acp-kernel 0.0.16 → 0.0.17
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.
- package/README.md +31 -0
- package/dist/compress.d.ts +14 -0
- package/dist/compress.d.ts.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +30 -16
- package/dist/index.js.map +1 -1
- package/dist/render-refs.d.ts +16 -1
- package/dist/render-refs.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -54,6 +54,37 @@ core.search("auth token", compressed); // relevance-ranked block search
|
|
|
54
54
|
core.status(compressed, tokenCount, config); // context-usage report
|
|
55
55
|
```
|
|
56
56
|
|
|
57
|
+
#### `renderTags` — host-side rendering strategy
|
|
58
|
+
|
|
59
|
+
`processTurn` always assigns a ref (e.g. `m00005`) to **every** mapped message,
|
|
60
|
+
including tool calls — that ref map is the anchor the model cites inside
|
|
61
|
+
`compress` calls. What varies is whether the `<acp>` tag is also **injected into
|
|
62
|
+
message text**. Pick the strategy that matches how your host consumes the
|
|
63
|
+
output:
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
import { processTurn, type RenderStrategy } from "acp-kernel";
|
|
67
|
+
|
|
68
|
+
type RenderStrategy = "all" | "text-only" | "none";
|
|
69
|
+
|
|
70
|
+
// default: every mapped message gets a visible <acp> tag.
|
|
71
|
+
// Use for in-process hosts (pai-acp / billion-context-pi) where the LLM
|
|
72
|
+
// reads the tag to identify compress ranges.
|
|
73
|
+
processTurn({ messages, state, config, tokenCount });
|
|
74
|
+
|
|
75
|
+
// proxy mode: tag user/assistant text, but leave tool-call args and tool
|
|
76
|
+
// results pristine (a <acp> tag inside {"command":"echo"} corrupts the JSON).
|
|
77
|
+
// Refs are still assigned to every message; only text rendering is selective.
|
|
78
|
+
processTurn({ messages, state, config, tokenCount, renderTags: "text-only" });
|
|
79
|
+
|
|
80
|
+
// host reads the ref map directly and never wants tags in the text.
|
|
81
|
+
// processTurn honors this by omitting the render-refs node entirely.
|
|
82
|
+
processTurn({ messages, state, config, tokenCount, renderTags: "none" });
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
`renderTags` is optional and defaults to `"all"`, so existing call sites keep
|
|
86
|
+
working unchanged.
|
|
87
|
+
|
|
57
88
|
### Standalone modules
|
|
58
89
|
|
|
59
90
|
| Module | Purpose |
|
package/dist/compress.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createInitialState } from "./state.js";
|
|
2
|
+
import type { RenderStrategy } from "./render-refs.js";
|
|
2
3
|
import { type PipelineNode } from "./pipeline.js";
|
|
3
4
|
import type { ApplyCompressionResult, CompressionBlock, CompressionState, Config, CoreMessage, ProcessTurnResult, StatusReport } from "./types.js";
|
|
4
5
|
export interface Ports {
|
|
@@ -17,6 +18,19 @@ export interface ProcessTurnInput {
|
|
|
17
18
|
state: CompressionState;
|
|
18
19
|
config: Config;
|
|
19
20
|
tokenCount: number;
|
|
21
|
+
/**
|
|
22
|
+
* Which messages get an <acp> ref tag injected into their text
|
|
23
|
+
* (the render-refs pipeline node). Refs are ALWAYS assigned regardless
|
|
24
|
+
* (assign-refs node runs unconditionally).
|
|
25
|
+
* - "all" (default): tag every mapped message — in-process hosts
|
|
26
|
+
* like pai-acp want tags for the LLM to reference compress ranges.
|
|
27
|
+
* - "text-only": tag only user/assistant text; leave tool-call args
|
|
28
|
+
* and tool-result content pristine — proxy hosts where structured
|
|
29
|
+
* content must not be polluted.
|
|
30
|
+
* - "none": leave all text untouched — hosts that read the ref map
|
|
31
|
+
* directly from result.state.messageRefs.
|
|
32
|
+
*/
|
|
33
|
+
renderTags?: RenderStrategy;
|
|
20
34
|
}
|
|
21
35
|
export interface ApplyCompressionInput {
|
|
22
36
|
ranges: {
|
package/dist/compress.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compress.d.ts","sourceRoot":"","sources":["../src/compress.ts"],"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ED,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE;QACN,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,EAAE,MAAM,CAAC;QACf,OAAO,EAAE,MAAM,CAAC;QAChB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,cAAc,CAAC,EAAE,MAAM,CAAC;QACxB,eAAe,CAAC,EAAE,MAAM,CAAC;KAC1B,EAAE,CAAC;IACJ,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,KAAK,EAAE,gBAAgB,CAAC;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,mBAAmB,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;CACnC;AAED,wBAAgB,UAAU,CAAC,KAAK,GAAE,KAAU,GAAG,eAAe,CAqO7D;AAmrBD,OAAO,EAAE,kBAAkB,EAAE,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -22,7 +22,8 @@ export { hideConsumedCompressCalls } from "./hide-consumed.js";
|
|
|
22
22
|
export type { HideConsumedResult } from "./hide-consumed.js";
|
|
23
23
|
export { rebuildCompressionState } from "./rebuild.js";
|
|
24
24
|
export type { RebuildResult, RebuildPorts } from "./rebuild.js";
|
|
25
|
-
export { renderVisibleRefs, renderRefsNode } from "./render-refs.js";
|
|
25
|
+
export { renderVisibleRefs, renderRefsNode, createRenderRefsNode } from "./render-refs.js";
|
|
26
|
+
export type { RenderStrategy } from "./render-refs.js";
|
|
26
27
|
export { searchBlocks, searchBlocksAsync, blockDocs, messageDocs } from "./search.js";
|
|
27
28
|
export type { SearchResult, SearchOptions, SearchAlgorithm, AsyncSearchAlgorithm, AnySearchAlgorithm, SearchDoc, SearchDocKind, ScoredBlock, MessageRole, RoleWeights, MessageInput } from "./search.js";
|
|
28
29
|
export { DEFAULT_ALGORITHM, DEFAULT_ROLE_WEIGHTS, registerSearchAlgorithm, getSearchAlgorithm, listSearchAlgorithms } from "./search.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|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,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACtF,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,eAAe,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,SAAS,EAAE,aAAa,EAAE,WAAW,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACzM,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACzI,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACtE,OAAO,EACL,WAAW,EACX,MAAM,EACN,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,MAAM,EACX,KAAK,WAAW,GACjB,MAAM,eAAe,CAAC;AACvB,cAAc,mBAAmB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -675,9 +675,13 @@ var TAG_CLOSE = LT + "/acp" + GT;
|
|
|
675
675
|
function acpTag(ref, tokens, type) {
|
|
676
676
|
return TAG_OPEN + 'tokens="' + formatTokens(tokens) + '" type="' + type + '"' + GT + ref + TAG_CLOSE;
|
|
677
677
|
}
|
|
678
|
-
function renderMessage(message, map, countTokens) {
|
|
678
|
+
function renderMessage(message, map, countTokens, strategy) {
|
|
679
679
|
const ref = refForRaw(map, message.id);
|
|
680
680
|
if (!ref || ref === BLOCKED_REF) return message;
|
|
681
|
+
if (strategy === "none") return message;
|
|
682
|
+
if (strategy === "text-only" && message.contentType !== "text") {
|
|
683
|
+
return message;
|
|
684
|
+
}
|
|
681
685
|
const ownTagRe = new RegExp(
|
|
682
686
|
"^" + escapeRegex(TAG_OPEN) + "[^>]*" + GT + escapeRegex(ref) + escapeRegex(TAG_CLOSE) + "\\n?"
|
|
683
687
|
);
|
|
@@ -688,21 +692,24 @@ function renderMessage(message, map, countTokens) {
|
|
|
688
692
|
if (!cleanText) return { ...message, text: prefix };
|
|
689
693
|
return { ...message, text: prefix + cleanText };
|
|
690
694
|
}
|
|
691
|
-
function renderVisibleRefs(messages, state, countTokens = (text) => Math.ceil(text.length / 4)) {
|
|
695
|
+
function renderVisibleRefs(messages, state, countTokens = (text) => Math.ceil(text.length / 4), strategy = "all") {
|
|
692
696
|
const map = state.messageRefs;
|
|
693
697
|
return messages.map(
|
|
694
|
-
(message) => renderMessage(message, map, countTokens)
|
|
698
|
+
(message) => renderMessage(message, map, countTokens, strategy)
|
|
695
699
|
);
|
|
696
700
|
}
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
}
|
|
701
|
+
function createRenderRefsNode(strategy) {
|
|
702
|
+
return {
|
|
703
|
+
name: "render-refs",
|
|
704
|
+
run(io, ctx) {
|
|
705
|
+
return {
|
|
706
|
+
...io,
|
|
707
|
+
messages: renderVisibleRefs(io.messages, io.state, ctx.countTokens, strategy)
|
|
708
|
+
};
|
|
709
|
+
}
|
|
710
|
+
};
|
|
711
|
+
}
|
|
712
|
+
var renderRefsNode = createRenderRefsNode("all");
|
|
706
713
|
|
|
707
714
|
// src/protected.ts
|
|
708
715
|
var ALWAYS_PROTECTED_TOOLS = ["compress"];
|
|
@@ -1086,7 +1093,9 @@ function createCore(ports = {}) {
|
|
|
1086
1093
|
state: input.state,
|
|
1087
1094
|
effects: {}
|
|
1088
1095
|
};
|
|
1089
|
-
const
|
|
1096
|
+
const strategy = input.renderTags ?? "all";
|
|
1097
|
+
const nodes = buildNodes(strategy);
|
|
1098
|
+
const result = runPipeline(nodes, initial, ctx);
|
|
1090
1099
|
return {
|
|
1091
1100
|
messages: result.messages,
|
|
1092
1101
|
state: result.state,
|
|
@@ -1116,7 +1125,10 @@ function createCore(ports = {}) {
|
|
|
1116
1125
|
};
|
|
1117
1126
|
}
|
|
1118
1127
|
function defaultNodes() {
|
|
1119
|
-
return
|
|
1128
|
+
return buildNodes("all");
|
|
1129
|
+
}
|
|
1130
|
+
function buildNodes(strategy) {
|
|
1131
|
+
const base = [
|
|
1120
1132
|
assignRefsNode,
|
|
1121
1133
|
syncBlocksNode,
|
|
1122
1134
|
pruneNode,
|
|
@@ -1124,9 +1136,10 @@ function createCore(ports = {}) {
|
|
|
1124
1136
|
hideCompressCallsNode,
|
|
1125
1137
|
recommendNode,
|
|
1126
1138
|
nudgeNode,
|
|
1127
|
-
emergencyTruncateNode
|
|
1128
|
-
renderRefsNode
|
|
1139
|
+
emergencyTruncateNode
|
|
1129
1140
|
];
|
|
1141
|
+
if (strategy === "none") return base;
|
|
1142
|
+
return [...base, createRenderRefsNode(strategy)];
|
|
1130
1143
|
}
|
|
1131
1144
|
return { processTurn, applyCompression, defaultNodes, decompress, search, status };
|
|
1132
1145
|
}
|
|
@@ -2649,6 +2662,7 @@ export {
|
|
|
2649
2662
|
createBpeTokenizer,
|
|
2650
2663
|
createCore,
|
|
2651
2664
|
createInitialState,
|
|
2665
|
+
createRenderRefsNode,
|
|
2652
2666
|
deactivateBlock,
|
|
2653
2667
|
defaultConfig,
|
|
2654
2668
|
defaultCountTokens,
|