Skip to content

feat(kernel): one-shot rewrite on acp-kernel (issue #42) - #274

Open
ranxianglei wants to merge 4 commits into
masterfrom
2026-08-05_acp-kernel
Open

feat(kernel): one-shot rewrite on acp-kernel (issue #42)#274
ranxianglei wants to merge 4 commits into
masterfrom
2026-08-05_acp-kernel

Conversation

@ranxianglei

@ranxianglei ranxianglei commented Aug 4, 2026

Copy link
Copy Markdown
Owner

Closes dog/opencode-acp#42 (Gitea).

What

One-shot fresh rewrite that replaces opencode-acp's in-tree compression engine
with the external acp-kernel library, per @Dog's directive on issue #42:
一步到位即可 — direct rewrite on the kernel, align basic functionality through
tuning, no phased switchover (which would introduce its own bugs).

How

New kernel-backed adapter under lib/kernel/ becomes the only active code
path. index.ts now imports exclusively from lib/kernel/ + shared infra
(lib/config.ts, lib/logger.ts, lib/token-utils.ts, lib/auth.ts,
lib/update.ts, lib/host-permissions.ts).

Module Role
messages.ts OpenCode WithParts ↔ kernel CoreMessage projection + reconstruction (burns <acp> ref tags back onto originals)
config.ts PluginConfig → kernel Config
state.ts atomic persistence to plugin/acp-kernel/{sessionId}.json
runtime.ts createCoreRuntime — per-session lock, stateFor
system-prompt.ts COMPRESS_PHILOSOPHY + rules
hooks.ts 5 SDK hook handlers (messages.transform is the core integration)
tools.ts compress / decompress / search_context / acp_status
commands.ts /acp + /dcp (back-compat)

The old in-tree engine (lib/hooks.ts, lib/compress/, lib/messages/,
lib/state/ engine, lib/gc/, lib/prompts/, lib/commands/, lib/ui/)
is left on disk as dead code — unreferenced and tree-shaken out of dist/.
Removing it (git rm) is a follow-up once the kernel path is validated.

Verification

  • npm run typecheckPASS
  • npm run buildPASS (single ESM bundle, dist/index.js 175.53 KB)
  • npm testPASS (961 tests, 0 fail: 954 existing + 7 new smoke)
  • dist/ symbol audit: kernel inlined (processTurn/applyCompression/createCore/renderNudgeText present); old engine fully tree-shaken (assignMessageRefs/createCompressRangeTool/runMajorGC/injectCompressNudges = 0); 0 external require("acp-kernel").
  • Local CI check (scripts/ci/check-pr.sh): all pass.

Out of scope (follow-up PRs)

  • git rm the orphaned old engine + redundant tests after live validation.
  • Deploy (scripts/dev-deploy.sh) and end-to-end smoke test the running plugin.
  • Tune nudge cadence / protected-tools / notification UX to match old behaviour.

Devlog: devlog/2026-08-05_acp-kernel/{REQ,DESIGN,WORKLOG}.md (DESIGN's phased
plan is marked SUPERSEDED by this one-shot rewrite).

…undation)

Issue #42 — replace the in-tree compression engine with the external
acp-kernel library. This is Phase 1 (foundation only): additive, nothing
rewired, old engine untouched.

- package.json: add acp-kernel@0.0.16 (devDep, inline-bundled)
- tsup.config.ts: noExternal acp-kernel (self-contained tarball)
- NOTICE: acp-kernel MIT attribution
- lib/kernel/{messages,config,state,runtime,index}.ts: host adapter
  (OpenCode WithParts <-> CoreMessage, PluginConfig -> kernel Config,
  kernel CompressionState persistence under plugin/acp-kernel/, legacy
  state detector, per-session runtime with async lock)
- devlog/2026-08-05_acp-kernel/{REQ,DESIGN,WORKLOG}.md

Verification: typecheck PASS, build PASS, 942 tests PASS (0 behavior change).
Phasing + state-shape migration documented in devlog DESIGN.md.
Fresh kernel-backed adapter under lib/kernel/ replacing the in-tree engine
as the active code path, per @Dog's one-shot directive on issue #42.

New modules:
- lib/kernel/messages.ts   WithParts <-> CoreMessage projection + reconstruct
- lib/kernel/config.ts     PluginConfig -> kernel Config
- lib/kernel/state.ts      atomic persistence (plugin/acp-kernel/{id}.json)
- lib/kernel/runtime.ts    createCoreRuntime (per-session lock, stateFor)
- lib/kernel/system-prompt.ts  COMPRESS_PHILOSOPHY + rules
- lib/kernel/hooks.ts      5 SDK hook handlers (messages.transform = core)
- lib/kernel/tools.ts      compress/decompress/search_context/acp_status
- lib/kernel/commands.ts   /acp + /dcp (back-compat)
- lib/kernel/index.ts      barrel

Rewired:
- index.ts                 imports ONLY lib/kernel + shared infra
- lib/token-utils.ts       SessionState -> import type (stops dist leak)
- package.json/tsup/NOTICE acp-kernel@0.0.16 inlined

Old engine (lib/compress,lib/messages,lib/state engine,lib/gc,lib/hooks.ts,
lib/prompts,lib/commands,lib/ui) left on disk as dead code, unreferenced and
tree-shaken from dist. git rm is a follow-up.

tests/kernel-smoke.test.ts: 7 new tests (projection -> processTurn ->
applyCompression -> reconstruct round-trip).

Verification: typecheck PASS, build PASS (dist/index.js 175.53 KB),
npm test 961 pass 0 fail (954 + 7), dist audit confirms kernel inlined
and old engine fully tree-shaken.
@ranxianglei ranxianglei changed the title feat(kernel): add acp-kernel engine + lib/kernel/ adapter (Phase 1) feat(kernel): one-shot rewrite on acp-kernel (issue #42) Aug 4, 2026
Adds scripts/test-profile.sh (seed/refresh an isolated opencode profile that
swaps the ACP plugin to this kernel build) and scripts/opencode-test.sh (the
XDG-redirect launcher installed to ~/.local/bin/opencode-test).

Isolates config/data/cache/state/DB under ~/.opencode-test/ so the stable
opencode-acp@latest install is never touched. Verified end-to-end: kernel
plugin loads, a headless run replies, and kernel CompressionState is written
to storage/plugin/acp-kernel/{sessionId}.json.
Add /acp version (and a banner line on every /acp output) so users can confirm
the kernel-based build is active:

  opencode-acp v1.14.12 (engine: acp-kernel v0.0.16)

Injects ACP_VERSION, ACP_ENGINE="acp-kernel", and KERNEL_VERSION at build time
via tsup define. KERNEL_VERSION is resolved by walking up from
import.meta.resolve("acp-kernel") to its package.json (its exports map does not
expose ./package.json, so require.resolve fails).
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.

1 participant