Skip to content

feat: live stack-state injection via agent harness hook (#304) - #306

Draft
aarontrowbridge wants to merge 2 commits into
mainfrom
304-feat-live-stack-state-injection-via-agent-harness-hook
Draft

feat: live stack-state injection via agent harness hook (#304)#306
aarontrowbridge wants to merge 2 commits into
mainfrom
304-feat-live-stack-state-injection-via-agent-harness-hook

Conversation

@aarontrowbridge

@aarontrowbridge aarontrowbridge commented Aug 9, 2026

Copy link
Copy Markdown
Member

Implements #304.

Adds a second opencode plugin (amicode_context.ts) implementing experimental.chat.system.transform that reads live state on every prompt build and injects it as the final system[] entry.

Scope (expanded 2026-08-21): the original WIP moved solver mode + routing off the boot-time file splice. This update finishes the job — the fleet line and the user-memory sections (profile, recent problems, reference demos, mount stack, memory index) also move to the live hook. Motivation: the boot-time splices were the "Amicode forgets the fleet" bug class — a hand-maintained server bundle (the canonical launchd server's staging dir) or a stale re-prep served yesterday's memory index and yesterday's solver mode to every new session (observed: 10-entry index frozen at Aug 16 vs 18 live; cloud-HP solver instructions served after the user switched back to Piccolo).

Key changes:

  • opencode-plugin/stack_state.ts — standalone state readers + markdown builders (node-builtins only for Bun runtime): solver mode, routing, active problem, live runs (original WIP) + NEW lean fleet line (~/.amico/ops/fleet/fleet.json role, fleet-status.json devices/freshness with stale/unreadable degradation, on-demand pointers — absent fleet.json renders nothing) + NEW marker-only Armonia mount discovery (smol-toml-free port of mount_store semantics: kind ranks, duplicate-id skip, kind-rank ordering) and the five user-memory sections read live from the personal vault, section text byte-identical to the retired substrate/user_splice.ts builders. No mounts.toml manifest support (smol-toml unavailable in Bun; no manifest exists in practice — documented in-module).
  • opencode-plugin/amicode_context.ts — the plugin, single export, one hook (unchanged)
  • src/opencode_config.ts — solver/routing AND the user-memory/mount/memory-index splices removed from prepareOpencodeProject (the latter previously the only injector); buildOpencodeConfigContent accepts extraPluginPaths (original WIP)
  • src/extension.ts — boot + solver-switch register the context plugin; solver-switch projectDir asymmetry fixed (original WIP)
  • packages/extension/AGENTS.md — single broadened recovery pointer (template tail) covering solver mode, routing, fleet, and the vault files; replaces the WIP's programmatic append (was duplicated)
  • Deleted substrate/user_splice.ts + the now-dead vault_store index readers (KNOWLEDGE/DEMOS/MEMORY) — the plugin owns that text now, pinned golden in test/stack_state.test.ts (14 cases: fleet rendering + degradation, mount discovery incl. duplicate/marker-less skips, section text parity with the retired builders, caps 50/30/50, splice-parity section order, hermetic env-seam composition). solverModeSection/routingSection deliberately stay as the original WIP's parity oracles (test-only) — noted asymmetry, reviewer's call whether to fold them into stack_state pins too.
  • test/packaging.test.ts — pins amicode_context.ts + stack_state.ts as must-ship vsix assets.

Hook support verified against the deployed fork binary: experimental.chat.system.transform is typed (packages/plugin/src/index.ts:291), triggered (agent/agent.ts:381), and the frozen canonical server binary contains the hook string. Silent no-op remains the failure mode if a binary lacks it — which is why the recovery pointer exists.

Deployment sequencing (the canonical launchd server serves a hand-staged bundle):

  1. Merge + release a vsix carrying the plugin files (the server config's existing amicode_context.ts reference — dead since it was added — goes live the moment the newest installed vsix ships it).
  2. Restart the canonical server (it resolves __EXT__ to the newest vsix at boot).
  3. Strip the now-duplicated static sections (About this user / recent problems / reference demos / mount stack / memory index) from the staged ~/.amico/server/opencode-project-staging/opencode-project/AGENTS.md — until then they render twice (harmless, just noisy).

Verification: tsc --noEmit clean; full extension suite 1186 passed / 5 skipped / 100 files.

@aarontrowbridge aarontrowbridge linked an issue Aug 9, 2026 that may be closed by this pull request
@aarontrowbridge
aarontrowbridge force-pushed the 304-feat-live-stack-state-injection-via-agent-harness-hook branch from a91ada6 to a37166a Compare August 20, 2026 08:48
@coderabbitai

coderabbitai Bot commented Aug 20, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 53f1b6a9-7a3a-471e-892d-a1c01fe7d7e0

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Comment @coderabbitai help to get the list of available commands.

Adds a second opencode plugin (amicode_context.ts) implementing
experimental.chat.system.transform that reads solver mode, routing,
active problem, and live runs on every prompt build and injects them
as the final system[] entry.

- opencode-plugin/stack_state.ts — standalone state readers + builders
- opencode-plugin/amicode_context.ts — system.transform hook plugin
- src/opencode_config — removed solver/routing from file splice;
  buildOpencodeConfigContent accepts extraPluginPaths param
- src/extension.ts — registers context plugin in boot + solver-switch;
  fixes mkdtemp asymmetry in solver-switch re-prep
- AGENTS.md — one-line recovery pointer appended

Closes #304.
Extends the amicode_context plugin's system.transform injection so the
sections that went stale as boot-time file splices are read LIVE from
disk on every prompt build:

- stack_state.ts: lean fleet line (role from fleet.json, devices +
  freshness from fleet-status.json, on-demand pointers) — absent
  fleet.json renders nothing; marker-only Armonia mount discovery
  (smol-toml-free port of mount_store semantics: kind ranks, duplicate
  skip, kind-rank order) + the user-memory sections (profile, recent
  problems, reference demos, mount stack, memory index) read from the
  personal vault, section text byte-identical to the retired
  substrate/user_splice.ts builders (pinned golden in
  test/stack_state.test.ts, 14 cases incl. caps + splice-parity order)
- opencode_config.ts: the boot-time user-memory/mount/memory splices
  are REMOVED (they were the staleness bug: hand-maintained server
  bundles and re-prepped project dirs served yesterday's memory index);
  the template AGENTS.md carries the single broadened recovery pointer
  (replaces the programmatic append — was duplicated)
- user_splice.ts + vault_store's now-dead index readers deleted;
  solverModeSection/routingSection stay as the WIP's parity oracles
- packaging.test.ts pins amicode_context.ts + stack_state.ts as
  must-ship vsix assets (the server config's dead reference goes live
  the moment a vsix carries them)

Closes the 'Amicode forgets the fleet' class: a distiller write, a
solver switch, or a vault sync reaches the next message without a
re-prep or server restart.
@aarontrowbridge
aarontrowbridge force-pushed the 304-feat-live-stack-state-injection-via-agent-harness-hook branch from a37166a to 8d39f63 Compare August 21, 2026 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: live stack-state injection via agent harness hook

1 participant