acp-kernel 0.0.94 → 0.0.95-pr.454.305

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/DESIGN.md +158 -137
  2. package/PROVENANCE.md +44 -40
  3. package/README.md +45 -32
  4. package/dist/cache-report.d.ts.map +1 -1
  5. package/dist/ccr.d.ts.map +1 -1
  6. package/dist/{chunk-NUQZKPQS.js → chunk-TQ6I62XC.js} +13 -6
  7. package/dist/chunk-TQ6I62XC.js.map +1 -0
  8. package/dist/compress-tools.d.ts +282 -254
  9. package/dist/compress-tools.d.ts.map +1 -1
  10. package/dist/compression-rules.d.ts +9 -3
  11. package/dist/compression-rules.d.ts.map +1 -1
  12. package/dist/config.d.ts.map +1 -1
  13. package/dist/decompress.d.ts.map +1 -1
  14. package/dist/filter/apply.d.ts.map +1 -1
  15. package/dist/filter/index.d.ts +1 -1
  16. package/dist/filter/index.d.ts.map +1 -1
  17. package/dist/filter/types.d.ts.map +1 -1
  18. package/dist/handoff.d.ts.map +1 -1
  19. package/dist/hide-consumed.d.ts.map +1 -1
  20. package/dist/image-compress.d.ts.map +1 -1
  21. package/dist/index.d.ts +2 -0
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +370 -158
  24. package/dist/index.js.map +1 -1
  25. package/dist/message-kind.d.ts.map +1 -1
  26. package/dist/nudge-text.d.ts.map +1 -1
  27. package/dist/packs.d.ts +1 -1
  28. package/dist/packs.d.ts.map +1 -1
  29. package/dist/panel/cache.d.ts.map +1 -1
  30. package/dist/panel/index.js +29 -10
  31. package/dist/panel/index.js.map +1 -1
  32. package/dist/panel/panel.d.ts.map +1 -1
  33. package/dist/panel/topic.d.ts.map +1 -1
  34. package/dist/parse-compress-input.d.ts.map +1 -1
  35. package/dist/persist/index.d.ts +1 -1
  36. package/dist/persist/index.d.ts.map +1 -1
  37. package/dist/persist/index.js +49 -12
  38. package/dist/persist/index.js.map +1 -1
  39. package/dist/persist/state-merge.d.ts.map +1 -1
  40. package/dist/persist/store.d.ts.map +1 -1
  41. package/dist/protected.d.ts.map +1 -1
  42. package/dist/rebuild.d.ts.map +1 -1
  43. package/dist/recommend.d.ts.map +1 -1
  44. package/dist/render-refs.d.ts.map +1 -1
  45. package/dist/report.d.ts.map +1 -1
  46. package/dist/search/algorithms/bm25.d.ts.map +1 -1
  47. package/dist/search/algorithms/fuzzy.d.ts.map +1 -1
  48. package/dist/search/algorithms/hybrid.d.ts.map +1 -1
  49. package/dist/search/algorithms/semantic.d.ts.map +1 -1
  50. package/dist/search/algorithms/substring.d.ts.map +1 -1
  51. package/dist/search/doc-cache.d.ts.map +1 -1
  52. package/dist/search/index.d.ts +1 -1
  53. package/dist/search/index.d.ts.map +1 -1
  54. package/dist/search/registry.d.ts.map +1 -1
  55. package/dist/search/stemmer.d.ts.map +1 -1
  56. package/dist/search/tokenizer.d.ts.map +1 -1
  57. package/dist/search/types.d.ts.map +1 -1
  58. package/dist/search.d.ts +3 -3
  59. package/dist/search.d.ts.map +1 -1
  60. package/dist/segment.d.ts +33 -0
  61. package/dist/segment.d.ts.map +1 -0
  62. package/dist/surface-config.d.ts.map +1 -1
  63. package/dist/tool-pairs.d.ts.map +1 -1
  64. package/dist/truncate-tools.d.ts.map +1 -1
  65. package/dist/truncate.d.ts.map +1 -1
  66. package/dist/turn-integrity.d.ts.map +1 -1
  67. package/dist/wire/anthropic.d.ts.map +1 -1
  68. package/dist/wire/bili-message.d.ts.map +1 -1
  69. package/dist/wire/compress-detect.d.ts.map +1 -1
  70. package/dist/wire/demoted-thinking.d.ts.map +1 -1
  71. package/dist/wire/formats.d.ts.map +1 -1
  72. package/dist/wire/index.js +476 -129
  73. package/dist/wire/index.js.map +1 -1
  74. package/dist/wire/message-id.d.ts.map +1 -1
  75. package/dist/wire/mirror.d.ts.map +1 -1
  76. package/dist/wire/openai.d.ts.map +1 -1
  77. package/dist/wire/responses.d.ts.map +1 -1
  78. package/dist/wire/strip-images.d.ts.map +1 -1
  79. package/dist/wire/util.d.ts.map +1 -1
  80. package/package.json +66 -66
  81. package/dist/chunk-NUQZKPQS.js.map +0 -1
package/DESIGN.md CHANGED
@@ -9,7 +9,7 @@ Framework-agnostic, model-driven context-compression engine. This document is th
9
9
  ACP-style compression is **not** like zip in one essential way: **the model writes the summaries; this library orchestrates everything around them.**
10
10
 
11
11
  - **zip**: computes the compressed output itself (`bytes → bytes`).
12
- - **acp-kernel**: the *summary text* is produced externally (by an LLM) and passed in as an argument. The core decides *when* to compress, *what range* to compress, tracks *state*, applies a compress *decision*, prunes ranges, and supports decompress/search. **It never calls a model.**
12
+ - **acp-kernel**: the _summary text_ is produced externally (by an LLM) and passed in as an argument. The core decides _when_ to compress, _what range_ to compress, tracks _state_, applies a compress _decision_, prunes ranges, and supports decompress/search. **It never calls a model.**
13
13
 
14
14
  This is precisely why the core can be a pure library: the one external dependency (the summarizer) is reduced to a string input.
15
15
 
@@ -48,60 +48,60 @@ Portable, host-agnostic. Adapters translate host-native messages into `CoreMessa
48
48
 
49
49
  ```ts
50
50
  type CoreMessage = {
51
- id: string;
52
- role: "user" | "assistant" | "system" | "tool";
53
- contentType: "text" | "tool-call" | "tool-result" | "reasoning";
54
- text?: string;
55
- toolName?: string; // for protected-tool filtering
56
- toolCallId?: string; // links tool-call ↔ tool-result
51
+ id: string;
52
+ role: "user" | "assistant" | "system" | "tool";
53
+ contentType: "text" | "tool-call" | "tool-result" | "reasoning";
54
+ text?: string;
55
+ toolName?: string; // for protected-tool filtering
56
+ toolCallId?: string; // links tool-call ↔ tool-result
57
57
  };
58
58
 
59
59
  type CompressionBlock = {
60
- blockId: string; // "b0", "b1", ...
61
- runId: string;
62
- tier: 1 | 2 | 3;
63
- topic?: string;
64
- summary: string; // produced by the model
65
- directMessageIds: string[];
66
- effectiveMessageIds: string[];
67
- directBlockIds: string[]; // nested blocks consumed
68
- createdAt: number;
69
- survivedCount: number;
70
- generation: "young" | "old";
71
- active: boolean;
60
+ blockId: string; // "b0", "b1", ...
61
+ runId: string;
62
+ tier: 1 | 2 | 3;
63
+ topic?: string;
64
+ summary: string; // produced by the model
65
+ directMessageIds: string[];
66
+ effectiveMessageIds: string[];
67
+ directBlockIds: string[]; // nested blocks consumed
68
+ createdAt: number;
69
+ survivedCount: number;
70
+ generation: "young" | "old";
71
+ active: boolean;
72
72
  };
73
73
 
74
74
  type CompressionState = {
75
- blocks: CompressionBlock[];
76
- messageRefs: { byRaw: Record<string, string>; byRef: Record<string, string> }; // raw ↔ mNNNNN
77
- nudge: {
78
- lastPerMessageNudgeTokens: number;
79
- lastNudgeShownTokens: number;
80
- baselineTokens: number;
81
- anchors: Record<string, unknown>;
82
- };
83
- stats: { tokensCompressed: number; compressionCount: number };
84
- nextBlockId: number;
85
- nextRunId: number;
75
+ blocks: CompressionBlock[];
76
+ messageRefs: { byRaw: Record<string, string>; byRef: Record<string, string> }; // raw ↔ mNNNNN
77
+ nudge: {
78
+ lastPerMessageNudgeTokens: number;
79
+ lastNudgeShownTokens: number;
80
+ baselineTokens: number;
81
+ anchors: Record<string, unknown>;
82
+ };
83
+ stats: { tokensCompressed: number; compressionCount: number };
84
+ nextBlockId: number;
85
+ nextRunId: number;
86
86
  };
87
87
 
88
88
  type Config = {
89
- tiers: { enabled: boolean; tier2Trigger: number; tier3Trigger: number };
90
- nudge: {
91
- maxContextLimitPct: number; // e.g. 0.55 (currently advisory; threshold gate uses minContextLimitPct)
92
- minContextLimitPct: number; // e.g. 0.45 — nudge threshold gate
93
- frequency: number; // advisory (reserved for future turn-frequency gating)
94
- iterationThreshold: number; // advisory (reserved for future iteration gating)
95
- force: "soft" | "strong";
96
- };
97
- // young→old promotion after N survivals (drives the merge-blocks node).
98
- // NOTE: there is no GC — no age-based deactivation, no summary truncation.
99
- promotionThreshold: number;
100
- truncate: { threshold: number }; // emergency tool-output truncation node (LAST safety valve); 1.0 = 100%
101
- merge: { maxSummaryLength: number; minOldGenBlocks: number }; // batch-merge old-gen blocks into one summary
102
- protectedTools: string[];
103
- preserveRecentMessages: number;
104
- modelContextLimit: number;
89
+ tiers: { enabled: boolean; tier2Trigger: number; tier3Trigger: number };
90
+ nudge: {
91
+ maxContextLimitPct: number; // e.g. 0.55 (currently advisory; threshold gate uses minContextLimitPct)
92
+ minContextLimitPct: number; // e.g. 0.45 — nudge threshold gate
93
+ frequency: number; // advisory (reserved for future turn-frequency gating)
94
+ iterationThreshold: number; // advisory (reserved for future iteration gating)
95
+ force: "soft" | "strong";
96
+ };
97
+ // young→old promotion after N survivals (drives the merge-blocks node).
98
+ // NOTE: there is no GC — no age-based deactivation, no summary truncation.
99
+ promotionThreshold: number;
100
+ truncate: { threshold: number }; // emergency tool-output truncation node (LAST safety valve); 1.0 = 100%
101
+ merge: { maxSummaryLength: number; minOldGenBlocks: number }; // batch-merge old-gen blocks into one summary
102
+ protectedTools: string[];
103
+ preserveRecentMessages: number;
104
+ modelContextLimit: number;
105
105
  };
106
106
  ```
107
107
 
@@ -111,78 +111,99 @@ type Config = {
111
111
 
112
112
  ```ts
113
113
  interface CompressionCore {
114
- // Per-turn node pipeline (replaces the message-transform hook's algorithm part).
115
- // Runs every turn (canonical order): assign-refs → sync-blocks → merge-blocks →
116
- // prune → ccr-store → filter → hide-compress-calls → nudge-inject →
117
- // emergency-truncate → render-refs. Survives/promotes blocks via advanceSurvival
118
- // (no age-based deactivation). Returns transformed messages + updated state +
119
- // nudge decision + the (possibly grown) content store.
120
- processTurn(input: {
121
- messages: CoreMessage[];
122
- state: CompressionState;
123
- config: Config;
124
- tokenCount: number;
125
- /** Per-session CCR content store from the previous turn (optional; an
126
- * empty store is created when omitted). */
127
- contentStore?: MessageContentStore;
128
- }): {
129
- messages: CoreMessage[];
130
- state: CompressionState;
131
- nudge?: NudgeDecision;
132
- /** Always present; pass back as input.contentStore next turn. */
133
- contentStore: MessageContentStore;
114
+ // Per-turn node pipeline (replaces the message-transform hook's algorithm part).
115
+ // Runs every turn (canonical order): assign-refs → sync-blocks → merge-blocks →
116
+ // prune → ccr-store → filter → hide-compress-calls → nudge-inject →
117
+ // emergency-truncate → render-refs. Survives/promotes blocks via advanceSurvival
118
+ // (no age-based deactivation). Returns transformed messages + updated state +
119
+ // nudge decision + the (possibly grown) content store.
120
+ processTurn(input: {
121
+ messages: CoreMessage[];
122
+ state: CompressionState;
123
+ config: Config;
124
+ tokenCount: number;
125
+ /** Per-session CCR content store from the previous turn (optional; an
126
+ * empty store is created when omitted). */
127
+ contentStore?: MessageContentStore;
128
+ }): {
129
+ messages: CoreMessage[];
130
+ state: CompressionState;
131
+ nudge?: NudgeDecision;
132
+ /** Always present; pass back as input.contentStore next turn. */
133
+ contentStore: MessageContentStore;
134
+ };
135
+
136
+ // When the model calls acp_retrieve. Pure lookup over the host-provided store
137
+ // plus an ephemeral injection message (id prefix acp_retrieved_*) that consumes
138
+ // no ref and never enters fold space. Hallucinated refs → not-found ack.
139
+ retrieve(store: MessageContentStore, ref: string): ApplyRetrieveResult;
140
+
141
+ // When the model calls compress. `ranges[].summary` is model-produced text.
142
+ // Allocates block(s), deactivates consumed blocks, updates indices, resets the
143
+ // nudge growth baseline on success (§5.7 feedback-loop fix).
144
+ applyCompression(input: {
145
+ ranges: {
146
+ startRef: string;
147
+ endRef: string;
148
+ summary: string;
149
+ topic?: string;
150
+ }[];
151
+ messages: CoreMessage[];
152
+ state: CompressionState;
153
+ config: Config;
154
+ }): {
155
+ state: CompressionState;
156
+ result: {
157
+ blocksCreated: number;
158
+ tokensCompressed: number;
159
+ errors: string[];
134
160
  };
135
-
136
- // When the model calls acp_retrieve. Pure lookup over the host-provided store
137
- // plus an ephemeral injection message (id prefix acp_retrieved_*) that consumes
138
- // no ref and never enters fold space. Hallucinated refs → not-found ack.
139
- retrieve(store: MessageContentStore, ref: string): ApplyRetrieveResult;
140
-
141
- // When the model calls compress. `ranges[].summary` is model-produced text.
142
- // Allocates block(s), deactivates consumed blocks, updates indices, resets the
143
- // nudge growth baseline on success (§5.7 feedback-loop fix).
144
- applyCompression(input: {
145
- ranges: { startRef: string; endRef: string; summary: string; topic?: string }[];
146
- messages: CoreMessage[];
147
- state: CompressionState;
148
- config: Config;
149
- }): {
150
- state: CompressionState;
151
- result: { blocksCreated: number; tokensCompressed: number; errors: string[] };
152
- };
153
-
154
- resolveBoundaries(input: {
155
- startRef: string;
156
- endRef: string;
157
- messages: CoreMessage[];
158
- state: CompressionState;
159
- }): { startIndex: number; endIndex: number; protectedGaps: number[] };
160
- // protectedGaps is reserved (currently always []); protected-tool hard-exclusion
161
- // is intentionally NOT implemented in the core — see README "Known limitation".
162
-
163
- decompress(blockId: string, state: CompressionState): CompressionBlock | undefined;
164
-
165
- search(query: string, state: CompressionState): CompressionBlock[];
166
-
167
- status(state: CompressionState, tokenCount: number, config: Config): StatusReport;
168
-
169
- // No gc(): age-based deactivation was removed (it caused memory-loss upstream).
170
- // Block promotion (young→old) still happens via advanceSurvival in sync-blocks,
171
- // and old-gen blocks are batch-merged by the merge-blocks node — not dropped.
161
+ };
162
+
163
+ resolveBoundaries(input: {
164
+ startRef: string;
165
+ endRef: string;
166
+ messages: CoreMessage[];
167
+ state: CompressionState;
168
+ }): { startIndex: number; endIndex: number; protectedGaps: number[] };
169
+ // protectedGaps is reserved (currently always []); protected-tool hard-exclusion
170
+ // is intentionally NOT implemented in the core — see README "Known limitation".
171
+
172
+ decompress(
173
+ blockId: string,
174
+ state: CompressionState,
175
+ ): CompressionBlock | undefined;
176
+
177
+ search(query: string, state: CompressionState): CompressionBlock[];
178
+
179
+ status(
180
+ state: CompressionState,
181
+ tokenCount: number,
182
+ config: Config,
183
+ ): StatusReport;
184
+
185
+ // No gc(): age-based deactivation was removed (it caused memory-loss upstream).
186
+ // Block promotion (young→old) still happens via advanceSurvival in sync-blocks,
187
+ // and old-gen blocks are batch-merged by the merge-blocks node — not dropped.
172
188
  }
173
189
 
174
190
  type CompressCall = {
175
- mode: "range" | "message";
176
- ranges: { startRef: string; endRef: string; summary: string; topic?: string }[];
191
+ mode: "range" | "message";
192
+ ranges: {
193
+ startRef: string;
194
+ endRef: string;
195
+ summary: string;
196
+ topic?: string;
197
+ }[];
177
198
  };
178
199
 
179
200
  type NudgeDecision = {
180
- shouldInject: boolean;
181
- reason: string;
182
- compressibleRanges: { startRef: string; endRef: string; tokens: number }[];
183
- contextUsage: number; // 0..1
184
- tier: 1 | 2 | 3 | null; // multi-tier trigger, if any
185
- breakdown: Record<string, number>;
201
+ shouldInject: boolean;
202
+ reason: string;
203
+ compressibleRanges: { startRef: string; endRef: string; tokens: number }[];
204
+ contextUsage: number; // 0..1
205
+ tier: 1 | 2 | 3 | null; // multi-tier trigger, if any
206
+ breakdown: Record<string, number>;
186
207
  };
187
208
  ```
188
209
 
@@ -194,9 +215,9 @@ The core needs two capabilities from the host, both injected (the core never imp
194
215
 
195
216
  ```ts
196
217
  interface Ports {
197
- countTokens(text: string): number; // default impl ships in core
198
- // messages are PASSED IN to each call (never fetched) → no MessageStore port
199
- // state persistence is the host's job (state is plain data) → no storage port
218
+ countTokens(text: string): number; // default impl ships in core
219
+ // messages are PASSED IN to each call (never fetched) → no MessageStore port
220
+ // state persistence is the host's job (state is plain data) → no storage port
200
221
  }
201
222
  ```
202
223
 
@@ -206,32 +227,32 @@ A default `countTokens` ships with the core (word-level + unicode CJK tokenizer,
206
227
 
207
228
  ## 6. Concept Mapping (nothing is lost)
208
229
 
209
- | ACP concept | Destination in acp-kernel |
210
- |---|---|
211
- | message-id ↔ ref mapping | **core** `processTurn` (pure) |
212
- | prune (range → summary block) | **core** `processTurn` (pure) |
213
- | boundary resolution / search | **core** `resolveBoundaries` (pure) |
214
- | block allocation / state mutation / tiers | **core** `applyCompression` (pure) |
215
- | compress **argument parsing** (lenient: fences, trailing commas, truncated-array salvage; field-name variants) | **core** `parseCompressArgs` (pure; diagnostics are data — adapters emit them) |
216
- | young→old promotion / batch merge | **core** `sync-blocks` node (`advanceSurvival`) + `merge-blocks` node (pure) |
217
- | emergency truncation (context near full) | **core** `emergency-truncate` node — the LAST safety valve; no age-based GC |
218
- | protected-tools filtering logic | **core** (pure: message + config → bool) |
219
- | `inject` **decision** (shouldNudge / growth / threshold) | **core** `decideNudge` (pure) |
220
- | `inject` **text rendering** (nudge → message string) | **adapter** (host message format) |
221
- | prompts (system / nudge text templates) | rules as **structured data** in core; text rendering in **adapter** |
222
- | compress/decompress/search/status **tool registration** | **adapter** (calls core pure fns) |
223
- | `/acp` commands | **adapter** |
224
- | opencode hooks | **OpenCode adapter** |
225
- | output-steering **decisions** (turn classification / verbosity level / effort clamp, #355) | **core** `decideOutputSteering` (pure; operates on a structural summary — role + block kinds, no content) |
226
- | output-steering **landing** (wire field write-back, system-prompt carrier selection, numeric budget floors) | **adapter** |
227
- | config three-layer merge | **adapter** (core only consumes its own `Config`) |
228
- | logger / auth / persistence / update | **adapter** (core does zero I/O) |
230
+ | ACP concept | Destination in acp-kernel |
231
+ | -------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- |
232
+ | message-id ↔ ref mapping | **core** `processTurn` (pure) |
233
+ | prune (range → summary block) | **core** `processTurn` (pure) |
234
+ | boundary resolution / search | **core** `resolveBoundaries` (pure) |
235
+ | block allocation / state mutation / tiers | **core** `applyCompression` (pure) |
236
+ | compress **argument parsing** (lenient: fences, trailing commas, truncated-array salvage; field-name variants) | **core** `parseCompressArgs` (pure; diagnostics are data — adapters emit them) |
237
+ | young→old promotion / batch merge | **core** `sync-blocks` node (`advanceSurvival`) + `merge-blocks` node (pure) |
238
+ | emergency truncation (context near full) | **core** `emergency-truncate` node — the LAST safety valve; no age-based GC |
239
+ | protected-tools filtering logic | **core** (pure: message + config → bool) |
240
+ | `inject` **decision** (shouldNudge / growth / threshold) | **core** `decideNudge` (pure) |
241
+ | `inject` **text rendering** (nudge → message string) | **adapter** (host message format) |
242
+ | prompts (system / nudge text templates) | rules as **structured data** in core; text rendering in **adapter** |
243
+ | compress/decompress/search/status **tool registration** | **adapter** (calls core pure fns) |
244
+ | `/acp` commands | **adapter** |
245
+ | opencode hooks | **OpenCode adapter** |
246
+ | output-steering **decisions** (turn classification / verbosity level / effort clamp, #355) | **core** `decideOutputSteering` (pure; operates on a structural summary — role + block kinds, no content) |
247
+ | output-steering **landing** (wire field write-back, system-prompt carrier selection, numeric budget floors) | **adapter** |
248
+ | config three-layer merge | **adapter** (core only consumes its own `Config`) |
249
+ | logger / auth / persistence / update | **adapter** (core does zero I/O) |
229
250
 
230
251
  ---
231
252
 
232
253
  ## 7. Why the algorithm, but not the DCP-derived code, comes here
233
254
 
234
- Copyright protects *expression*, not ideas, methods, or algorithms (17 USC §102(b)). The compression *methods* (3-tier, growth cadence, protected filtering) are the author's. This core reimplements them in **fresh expression** — it is not a copy or refactor of DCP-derived files. See [PROVENANCE.md](./PROVENANCE.md) for the per-module origin classification (original-bring / DCP-derived-reimplement / adapter-only).
255
+ Copyright protects _expression_, not ideas, methods, or algorithms (17 USC §102(b)). The compression _methods_ (3-tier, growth cadence, protected filtering) are the author's. This core reimplements them in **fresh expression** — it is not a copy or refactor of DCP-derived files. See [PROVENANCE.md](./PROVENANCE.md) for the per-module origin classification (original-bring / DCP-derived-reimplement / adapter-only).
235
256
 
236
257
  ---
237
258
 
@@ -241,10 +262,10 @@ Copyright protects *expression*, not ideas, methods, or algorithms (17 USC §102
241
262
 
242
263
  ### 8.1 First-user-message pin
243
264
 
244
- The session's **first user message survives prune unconditionally** — even when it is covered by an active block. In `rebuildMessages` (`src/prune.ts`) the pin check runs *before* the covered-by-active-block check, so after compressing a range that includes the first user message, the rebuilt wire contains **both** the rendered summary **and** the first user message verbatim; all other covered messages drop as usual. Only the *first* user message is pinned — later covered user messages are pruned normally.
265
+ The session's **first user message survives prune unconditionally** — even when it is covered by an active block. In `rebuildMessages` (`src/prune.ts`) the pin check runs _before_ the covered-by-active-block check, so after compressing a range that includes the first user message, the rebuilt wire contains **both** the rendered summary **and** the first user message verbatim; all other covered messages drop as usual. Only the _first_ user message is pinned — later covered user messages are pruned normally.
245
266
 
246
267
  - **Why:** strict providers reject conversations with no user message (e.g., Anthropic requires the conversation to start from the user role). Pinning guarantees the rebuilt wire retains at least one user message whenever the input had one. Deliberate since prune's first implementation (v0.0.2) — the ordering of the two checks is part of the contract, not incidental. Regression-tested by `tests/state-prune.test.ts` ("prune preserves first user message even when covered") and `tests/orphan-fixes.test.ts` ("prune: first user message pruned when covered (no duplication)").
247
268
  - **Consequences for consumers:**
248
269
  - Consumers cannot assert byte-level disappearance of the first user message after compression; post-compress wire assertions must expect the rendered summary **plus** the pinned message verbatim.
249
270
  - Token-size and prefix-cache stability estimates must account for the pinned message staying verbatim (it is often the task description and can be long).
250
- - Boundary resolution compensates: `blockVisibleInRange` (`src/boundaries.ts`) treats a block as present in a range via its rendered summary **or** its earliest surviving raw — required precisely because the summary anchors *before* the pinned raw.
271
+ - Boundary resolution compensates: `blockVisibleInRange` (`src/boundaries.ts`) treats a block as present in a range via its rendered summary **or** its earliest surviving raw — required precisely because the summary anchors _before_ the pinned raw.
package/PROVENANCE.md CHANGED
@@ -2,17 +2,17 @@
2
2
 
3
3
  This document classifies **every** source file in `opencode-acp/lib/` (the donor) into one of three buckets, to determine what can be carried into the MIT `acp-kernel` and what must be reimplemented in fresh expression.
4
4
 
5
- **Method**: exact path comparison of `opencode-acp` (the ACP fork, 82 `lib/*.ts` files) against the upstream DCP repository (66 `lib/*.ts` files). A file that has **no DCP equivalent** is original work (bucket A). A file with a **DCP equivalent at the same path** is a DCP derivative — its *expression* is AGPL-bound regardless of how much it was later changed (derivation is judged by whether a file was created by transforming the original, not by % changed; per copyright law expression is protected, not ideas/methods/algorithms).
5
+ **Method**: exact path comparison of `opencode-acp` (the ACP fork, 82 `lib/*.ts` files) against the upstream DCP repository (66 `lib/*.ts` files). A file that has **no DCP equivalent** is original work (bucket A). A file with a **DCP equivalent at the same path** is a DCP derivative — its _expression_ is AGPL-bound regardless of how much it was later changed (derivation is judged by whether a file was created by transforming the original, not by % changed; per copyright law expression is protected, not ideas/methods/algorithms).
6
6
 
7
7
  ---
8
8
 
9
9
  ## Legend
10
10
 
11
- | Bucket | Meaning | Action in acp-kernel |
12
- |---|---|---|
13
- | **A** | No DCP equivalent → original work of ranxianglei | **Bring verbatim** (the author's own code, MIT-safe). License header rewritten to MIT. |
14
- | **B** | DCP-derived file (same path exists upstream) → derivative expression is AGPL | **Reimplement in fresh expression** using the author's algorithm; do NOT copy/refactor the file's code. |
15
- | **N/A** | Adapter-only (framework-specific: opencode hooks, I/O, auth, commands, UI) | **Excluded** from the pure core. Stays in host adapters. Origin irrelevant. |
11
+ | Bucket | Meaning | Action in acp-kernel |
12
+ | ------- | ---------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
13
+ | **A** | No DCP equivalent → original work of ranxianglei | **Bring verbatim** (the author's own code, MIT-safe). License header rewritten to MIT. |
14
+ | **B** | DCP-derived file (same path exists upstream) → derivative expression is AGPL | **Reimplement in fresh expression** using the author's algorithm; do NOT copy/refactor the file's code. |
15
+ | **N/A** | Adapter-only (framework-specific: opencode hooks, I/O, auth, commands, UI) | **Excluded** from the pure core. Stays in host adapters. Origin irrelevant. |
16
16
 
17
17
  ---
18
18
 
@@ -21,26 +21,28 @@ This document classifies **every** source file in `opencode-acp/lib/` (the donor
21
21
  Quality gate intentionally omitted from acp-kernel (may be added later if needed).
22
22
 
23
23
  ### `compress/`
24
- | File | Notes |
25
- |---|---|
26
- | `compress/decompress.ts` | ACP-original (v1.11+); DCP has no decompress |
27
- | `compress/decompress-logic.ts` | ACP-original |
28
- | `compress/hide-consumed.ts` | ACP-original (v1.14+) |
29
- | `compress/hide-failed.ts` | ACP-original |
30
- | `compress/keep-markers.ts` | ACP-original (v1.12+) |
31
- | `compress/parts.ts` | ACP-original |
32
- | `compress/recap.ts` | ACP-original (v1.12.1) |
33
- | `compress/status.ts` | ACP-original (v1.11+) |
24
+
25
+ | File | Notes |
26
+ | ------------------------------ | -------------------------------------------- |
27
+ | `compress/decompress.ts` | ACP-original (v1.11+); DCP has no decompress |
28
+ | `compress/decompress-logic.ts` | ACP-original |
29
+ | `compress/hide-consumed.ts` | ACP-original (v1.14+) |
30
+ | `compress/hide-failed.ts` | ACP-original |
31
+ | `compress/keep-markers.ts` | ACP-original (v1.12+) |
32
+ | `compress/parts.ts` | ACP-original |
33
+ | `compress/recap.ts` | ACP-original (v1.12.1) |
34
+ | `compress/status.ts` | ACP-original (v1.11+) |
34
35
 
35
36
  ### other
36
- | File | Notes |
37
- |---|---|
38
- | `config-validation.ts` | ACP-extracted for testability; no DCP equivalent |
39
- | `gc/merge.ts` | ACP-original (DCP has no `gc/` dir) |
40
- | `messages/truncate-tools.ts` | ACP-original (v1.14.5, replaced DCP's `gc/truncate.ts`) |
41
- | `messages/filter/*` (9 files) | ACP-original filtering subsystem |
37
+
38
+ | File | Notes |
39
+ | ------------------------------------ | --------------------------------------------------------------- |
40
+ | `config-validation.ts` | ACP-extracted for testability; no DCP equivalent |
41
+ | `gc/merge.ts` | ACP-original (DCP has no `gc/` dir) |
42
+ | `messages/truncate-tools.ts` | ACP-original (v1.14.5, replaced DCP's `gc/truncate.ts`) |
43
+ | `messages/filter/*` (9 files) | ACP-original filtering subsystem |
42
44
  | `messages/inject/policy/*` (3 files) | ACP-original (v1.13.1) — inject **policy** logic, not rendering |
43
- | `state/rebuild.ts` | ACP-original (v1.11+) |
45
+ | `state/rebuild.ts` | ACP-original (v1.11+) |
44
46
 
45
47
  ---
46
48
 
@@ -49,22 +51,25 @@ Quality gate intentionally omitted from acp-kernel (may be added later if needed
49
51
  Only the **algorithmic** subset is reimplemented into the pure core; the rest are adapter-only (persistence, config-merge, prompts-rendering) and excluded from the core. Listed by what they become.
50
52
 
51
53
  ### Reimplemented into acp-kernel (fresh expression, ~9 substantial files)
52
- | DCP-derived file | Becomes | What to reimplement |
53
- |---|---|---|
54
- | `compress/range.ts` | `core/applyCompression` (range mode) | block allocation, nested-block handling, boundary resolution |
55
- | `compress/search.ts` | `core/resolveBoundaries` | ref→index mapping, reversed-boundary swap, protected-gap detection |
56
- | `compress/state.ts` | `core/state` (mutation) | block id/run allocation, deactivation, byMessageId index |
57
- | `compress/pipeline.ts` | `core/processTurn` prep/finalize | permission (host-side), fetch (host-side), state wrap |
58
- | `messages/prune.ts` | `core/prune` | replace compressed ranges with summary blocks |
59
- | `messages/sync.ts` | `core/sync` | deactivate orphaned blocks when messages deleted |
60
- | `message-ids.ts` | `core/refs` | raw↔mNNNNN bidirectional map |
61
- | `messages/inject/inject.ts` + `inject/utils.ts` | `core/decideNudge` | **decision only** — shouldNudge, growth baseline, threshold, compressible ranges |
62
- | `config.ts` (core subset) | `core/Config` defaults | defaults + validation (use A-class `config-validation.ts`) |
54
+
55
+ | DCP-derived file | Becomes | What to reimplement |
56
+ | ----------------------------------------------- | ------------------------------------ | -------------------------------------------------------------------------------- |
57
+ | `compress/range.ts` | `core/applyCompression` (range mode) | block allocation, nested-block handling, boundary resolution |
58
+ | `compress/search.ts` | `core/resolveBoundaries` | ref→index mapping, reversed-boundary swap, protected-gap detection |
59
+ | `compress/state.ts` | `core/state` (mutation) | block id/run allocation, deactivation, byMessageId index |
60
+ | `compress/pipeline.ts` | `core/processTurn` prep/finalize | permission (host-side), fetch (host-side), state wrap |
61
+ | `messages/prune.ts` | `core/prune` | replace compressed ranges with summary blocks |
62
+ | `messages/sync.ts` | `core/sync` | deactivate orphaned blocks when messages deleted |
63
+ | `message-ids.ts` | `core/refs` | raw↔mNNNNN bidirectional map |
64
+ | `messages/inject/inject.ts` + `inject/utils.ts` | `core/decideNudge` | **decision only** — shouldNudge, growth baseline, threshold, compressible ranges |
65
+ | `config.ts` (core subset) | `core/Config` defaults | defaults + validation (use A-class `config-validation.ts`) |
63
66
 
64
67
  ### Supporting types/barrels (trivial, write fresh)
68
+
65
69
  `compress/{index,types,timing,range-utils}.ts`, `messages/{index,priority,query,reasoning-strip,shape,utils}.ts`, `state/{index,types,utils}.ts`, `token-utils.ts` (wrap `cc-alg` tokenizer), `protected-patterns.ts`, `compress/protected-content.ts`.
66
70
 
67
71
  ### Excluded from core (adapter-only despite B lineage)
72
+
68
73
  `state/persistence.ts` (filesystem I/O), `prompts/*` (text rendering → adapter), `compress-permission.ts` (permission = host concern).
69
74
 
70
75
  ---
@@ -79,14 +84,13 @@ All framework-specific; irrelevant to the pure core. Stay in the OpenCode adapte
79
84
 
80
85
  ## Summary
81
86
 
82
- | Bucket | Files | Disposition |
83
- |---|---|---|
84
- | **B** DCP-derived | 40 | ~9 substantial algorithms reimplemented fresh + ~12 types/barrels rewritten fresh; rest excluded (adapter) |
85
- | **N/A** adapter | 12 | excluded from core |
86
-
87
+ | Bucket | Files | Disposition |
88
+ | ----------------- | ----- | ---------------------------------------------------------------------------------------------------------- |
89
+ | **B** DCP-derived | 40 | ~9 substantial algorithms reimplemented fresh + ~12 types/barrels rewritten fresh; rest excluded (adapter) |
90
+ | **N/A** adapter | 12 | excluded from core |
87
91
 
88
92
  ---
89
93
 
90
94
  ## Compliance note
91
95
 
92
- This audit exists to ensure acp-kernel is **genuinely MIT**, not "MIT-labeled but AGPL-tainted." The rule applied throughout: an idea/algorithm is free regardless of source; a *file's code expression* is bound to the license of the file it descends from. A-class files descend from no DCP file. B-class files' code is NOT carried — the algorithms are reimplemented in new expression. Should any contributor question a classification, the comparison data above (and the upstream DCP tree) allow independent verification.
96
+ This audit exists to ensure acp-kernel is **genuinely MIT**, not "MIT-labeled but AGPL-tainted." The rule applied throughout: an idea/algorithm is free regardless of source; a _file's code expression_ is bound to the license of the file it descends from. A-class files descend from no DCP file. B-class files' code is NOT carried — the algorithms are reimplemented in new expression. Should any contributor question a classification, the comparison data above (and the upstream DCP tree) allow independent verification.