Skip to content

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

Merged
aarontrowbridge merged 2 commits into
mainfrom
304-feat-live-stack-state-injection-via-agent-harness-hook
Aug 22, 2026
Merged

feat: live stack-state injection via agent harness hook (#304)#306
aarontrowbridge merged 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.

Summary by CodeRabbit

  • New Features

    • Added live context injection for solver status, routing, fleet information, active work, profile data, and relevant memory.
    • Context updates automatically during startup and solver-mode restarts.
    • Added support for discovering and prioritizing available data sources.
  • Bug Fixes

    • Missing, malformed, or unavailable data is handled gracefully without interrupting prompt generation.
    • Prevented stale context from being embedded in persistent project instructions.
  • Tests

    • Expanded coverage for context composition, data discovery, ordering, limits, and graceful degradation.
    • Updated packaging and integration checks for the new context functionality.

@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

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 22e859f7-5049-4d1c-8401-dc55e00e9fa3

📥 Commits

Reviewing files that changed from the base of the PR and between 324a5ec and 8d39f63.

📒 Files selected for processing (12)
  • packages/extension/AGENTS.md
  • packages/extension/opencode-plugin/amicode_context.ts
  • packages/extension/opencode-plugin/stack_state.ts
  • packages/extension/src/extension.ts
  • packages/extension/src/opencode_config.ts
  • packages/extension/src/substrate/user_splice.ts
  • packages/extension/src/substrate/vault_store.ts
  • packages/extension/test/packaging.test.ts
  • packages/extension/test/scores/prep_integration.test.ts
  • packages/extension/test/stack_state.test.ts
  • packages/extension/test/substrate/user_splice.test.ts
  • packages/extension/test/substrate/vault_store.test.ts

📝 Walkthrough

Walkthrough

The extension now injects live solver, fleet, problem, routing, and personal-vault context into OpenCode prompts. Startup no longer splices this data into AGENTS.md. New stack-state readers, plugin wiring, packaging checks, and tests support the change.

Changes

Live context injection

Layer / File(s) Summary
Stack-state collection and rendering
packages/extension/opencode-plugin/stack_state.ts, packages/extension/test/stack_state.test.ts
The new builder reads operational state and vault data, discovers mounts, renders ordered markdown sections, applies content caps, and handles missing or malformed files.
OpenCode plugin wiring
packages/extension/opencode-plugin/amicode_context.ts, packages/extension/src/opencode_config.ts, packages/extension/src/extension.ts, packages/extension/AGENTS.md, packages/extension/test/packaging.test.ts
The plugin appends live context during system-prompt transformation. Initial and restart configurations register the plugin, and packaged assets include its runtime files.
Startup splice removal and migration coverage
packages/extension/src/substrate/vault_store.ts, packages/extension/src/opencode_config.ts, packages/extension/test/scores/prep_integration.test.ts
Startup writes only compiled AGENTS.md content. Obsolete user-memory readers and splice helpers are removed. Integration tests verify live injection and recovery-pointer behavior.

Estimated code review effort: 4 (Complex) | ~45 minutes

Suggested reviewers: rchari1

Sequence Diagram(s)

sequenceDiagram
  participant Extension
  participant OpenCode
  participant AmicodeContext
  participant LocalState
  participant PersonalVault
  Extension->>OpenCode: register Amico context plugin
  OpenCode->>AmicodeContext: transform system prompt
  AmicodeContext->>LocalState: read live solver and fleet state
  AmicodeContext->>PersonalVault: read profile, problems, demos, mounts, and memory
  AmicodeContext-->>OpenCode: append generated context
``

</details>

<!-- walkthrough_end -->
<!-- finishing_touch_checkbox_start -->

<details>
<summary>✨ Finishing Touches</summary>

<details>
<summary>📝 Generate docstrings</summary>

- [ ] <!-- {"checkboxId":"7962f53c-55bc-4827-bfbf-6a18da830691"} --> Create stacked PR
- [ ] <!-- {"checkboxId":"3e1879ae-f29b-4d0d-8e06-d12b7ba33d98"} --> Commit on current branch

</details>
<details>
<summary>🧪 Generate unit tests (beta)</summary>

- [ ] <!-- {"checkboxId": "f47ac10b-58cc-4372-a567-0e02b2c3d479", "radioGroupId": "utg-output-choice-group-unknown_comment_id"} -->   Create PR with unit tests
- [ ] <!-- {"checkboxId": "6ba7b810-9dad-11d1-80b4-00c04fd430c8", "radioGroupId": "utg-output-choice-group-unknown_comment_id"} -->   Commit unit tests in branch `304-feat-live-stack-state-injection-via-agent-harness-hook`

</details>

</details>

<!-- finishing_touch_checkbox_end -->
<!-- tips_start -->

---




<sub>Comment `@coderabbitai help` to get the list of available commands.</sub>

<!-- tips_end -->
Loading

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
@aarontrowbridge
aarontrowbridge marked this pull request as ready for review August 22, 2026 21:30
@aarontrowbridge
aarontrowbridge merged commit f0f5887 into main Aug 22, 2026
7 of 8 checks passed
@aarontrowbridge
aarontrowbridge deleted the 304-feat-live-stack-state-injection-via-agent-harness-hook branch August 22, 2026 21:30
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