feat(kernel): one-shot rewrite on acp-kernel (issue #42) - #274
Open
ranxianglei wants to merge 4 commits into
Open
feat(kernel): one-shot rewrite on acp-kernel (issue #42)#274ranxianglei wants to merge 4 commits into
ranxianglei wants to merge 4 commits into
Conversation
…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.
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 codepath.
index.tsnow imports exclusively fromlib/kernel/+ shared infra(
lib/config.ts,lib/logger.ts,lib/token-utils.ts,lib/auth.ts,lib/update.ts,lib/host-permissions.ts).messages.tsWithParts↔ kernelCoreMessageprojection + reconstruction (burns<acp>ref tags back onto originals)config.tsPluginConfig→ kernelConfigstate.tsplugin/acp-kernel/{sessionId}.jsonruntime.tscreateCoreRuntime— per-session lock,stateForsystem-prompt.tsCOMPRESS_PHILOSOPHY+ ruleshooks.tsmessages.transformis the core integration)tools.tscommands.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 typecheck— PASSnpm run build— PASS (single ESM bundle,dist/index.js175.53 KB)npm test— PASS (961 tests, 0 fail: 954 existing + 7 new smoke)dist/symbol audit: kernel inlined (processTurn/applyCompression/createCore/renderNudgeTextpresent); old engine fully tree-shaken (assignMessageRefs/createCompressRangeTool/runMajorGC/injectCompressNudges= 0); 0 externalrequire("acp-kernel").scripts/ci/check-pr.sh): all pass.Out of scope (follow-up PRs)
git rmthe orphaned old engine + redundant tests after live validation.scripts/dev-deploy.sh) and end-to-end smoke test the running plugin.Devlog:
devlog/2026-08-05_acp-kernel/{REQ,DESIGN,WORKLOG}.md(DESIGN's phasedplan is marked SUPERSEDED by this one-shot rewrite).