@dsh-cc/compaction-micro 0.7.1 → 0.8.0-rc.1
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.i18n.yaml +2 -2
- package/README.md +6 -1
- package/README.zh.md +6 -1
- package/lib/config.d.ts.map +1 -1
- package/lib/config.js +5 -1
- package/lib/config.js.map +1 -1
- package/lib/index.d.ts +56 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +130 -16
- package/lib/index.js.map +1 -1
- package/lib/types.d.ts +7 -0
- package/lib/types.d.ts.map +1 -1
- package/package.json +5 -3
package/README.i18n.yaml
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
|
3
3
|
# after editing either side, bring the other along and re-record with:
|
|
4
4
|
# pnpm check:readme --write
|
|
5
|
-
README.md:
|
|
6
|
-
README.zh.md:
|
|
5
|
+
README.md: 22a6450008af5086e385bed863a66c67b117f023
|
|
6
|
+
README.zh.md: 29c736952e84095cecf3ca3051b4cafaa80b9b9b
|
package/README.md
CHANGED
|
@@ -29,8 +29,13 @@ Unrecognized keys fail at plugin construction. Resolved config is detached and d
|
|
|
29
29
|
| `retainResults` | no (default `10`) | Keep the most recent N tool results verbatim; older ones are eligible. |
|
|
30
30
|
| `auto` | no (default `false`) | Register an `agent/pre-step` hook that collapses stale results ahead of the turn's request. |
|
|
31
31
|
| `placeholderChars` | no (default `256`) | Maximum text code points in a generated placeholder (excluding a re-embedded spill locator). |
|
|
32
|
+
| `failureCap` | no (default `3`) | Consecutive auto pre-step pass failures tolerated per session before the pass pauses. |
|
|
32
33
|
|
|
33
|
-
All values are integers; `retainResults` and `
|
|
34
|
+
All values are integers; `retainResults`, `placeholderChars`, and `failureCap` are positive.
|
|
35
|
+
|
|
36
|
+
### Paused notice (auto pass)
|
|
37
|
+
|
|
38
|
+
After `failureCap` consecutive auto-pass failures for a session, the pass pauses for that session (later pre-steps skip it entirely; any later success resets the pause) and exactly one durable, model-visible notice is injected via `agent.inject` as a next-step user message from plugin source (`{ kind: 'plugin', plugin: 'compaction-micro' }`) — the model learns that auto-microcompact is paused and that `/compact` is the manual path.
|
|
34
39
|
|
|
35
40
|
## Usage
|
|
36
41
|
|
package/README.zh.md
CHANGED
|
@@ -29,8 +29,13 @@
|
|
|
29
29
|
| `retainResults` | 否(默认 `10`) | 原样保留最近的 N 个工具结果,更早的结果可被折叠。 |
|
|
30
30
|
| `auto` | 否(默认 `false`) | 注册一个 `agent/pre-step` 钩子,在回合请求之前折叠过期结果。 |
|
|
31
31
|
| `placeholderChars` | 否(默认 `256`) | 生成占位符的最大文本码点数(不包含重新嵌入的 spill locator)。 |
|
|
32
|
+
| `failureCap` | 否(默认 `3`) | 每个会话在自动 pre-step 连续失败达到该次数后暂停。 |
|
|
32
33
|
|
|
33
|
-
所有值都必须是整数;`retainResults` 与 `
|
|
34
|
+
所有值都必须是整数;`retainResults`、`placeholderChars` 与 `failureCap` 必须为正数。
|
|
35
|
+
|
|
36
|
+
### 暂停通知(自动 pass)
|
|
37
|
+
|
|
38
|
+
一个会话的自动 pass 连续失败达到 `failureCap` 次后,该 pass 对此会话暂停(后续 pre-step 完全跳过;之后的任何一次成功都会解除暂停),并通过 `agent.inject` 注入恰好一条持久的、模型可见的通知——它是一条来自插件来源(`{ kind: 'plugin', plugin: 'compaction-micro' }`)的 next-step 用户消息,让模型得知自动微压缩已暂停、`/compact` 是手动压缩路径。
|
|
34
39
|
|
|
35
40
|
## 用法
|
|
36
41
|
|
package/lib/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAEpE;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,4CAA4C,CAAA;AAE5E;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,qCAAqC,CAAA;AAUpE,wDAAwD;AACxD,eAAO,MAAM,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAEpE;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,4CAA4C,CAAA;AAE5E;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,qCAAqC,CAAA;AAUpE,wDAAwD;AACxD,eAAO,MAAM,QAAQ,EAAE,cAKrB,CAAA;AASF;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,SAAS;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,EAAE,GAAG,OAAO,CAMrG;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAMlE;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,MAAM,GAAE,kBAAuB,GAAG,cAAc,CAoB7E"}
|
package/lib/config.js
CHANGED
|
@@ -29,11 +29,13 @@ export const DEFAULTS = deepFreeze({
|
|
|
29
29
|
retainResults: 10,
|
|
30
30
|
auto: false,
|
|
31
31
|
placeholderChars: 256,
|
|
32
|
+
failureCap: 3,
|
|
32
33
|
});
|
|
33
34
|
const CONFIG_KEYS = new Set([
|
|
34
35
|
'retainResults',
|
|
35
36
|
'auto',
|
|
36
37
|
'placeholderChars',
|
|
38
|
+
'failureCap',
|
|
37
39
|
]);
|
|
38
40
|
/**
|
|
39
41
|
* Whether a content list already carries a microcompact placeholder as its
|
|
@@ -77,16 +79,18 @@ export function resolveConfig(config = {}) {
|
|
|
77
79
|
for (const key of Object.keys(config)) {
|
|
78
80
|
if (!CONFIG_KEYS.has(key)) {
|
|
79
81
|
throw new Error(`MicrocompactConfig: unknown key "${key}" `
|
|
80
|
-
+ '(allowed: retainResults, auto, placeholderChars)');
|
|
82
|
+
+ '(allowed: retainResults, auto, placeholderChars, failureCap)');
|
|
81
83
|
}
|
|
82
84
|
}
|
|
83
85
|
const resolved = {
|
|
84
86
|
retainResults: config.retainResults ?? DEFAULTS.retainResults,
|
|
85
87
|
auto: config.auto ?? DEFAULTS.auto,
|
|
86
88
|
placeholderChars: config.placeholderChars ?? DEFAULTS.placeholderChars,
|
|
89
|
+
failureCap: config.failureCap ?? DEFAULTS.failureCap,
|
|
87
90
|
};
|
|
88
91
|
assertPositiveInteger('retainResults', resolved.retainResults);
|
|
89
92
|
assertPositiveInteger('placeholderChars', resolved.placeholderChars);
|
|
93
|
+
assertPositiveInteger('failureCap', resolved.failureCap);
|
|
90
94
|
return deepFreeze(structuredClone(resolved));
|
|
91
95
|
}
|
|
92
96
|
function assertPositiveInteger(name, value) {
|
package/lib/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,8BAA8B,CAAA;AAGzD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,yCAAyC,CAAA;AAE5E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,kCAAkC,CAAA;AAEpE;;;;;GAKG;AACH,MAAM,qBAAqB,GAAG,6BAA6B,CAAA;AAE3D,wDAAwD;AACxD,MAAM,CAAC,MAAM,QAAQ,GAAmB,UAAU,CAAC;IACjD,aAAa,EAAE,EAAE;IACjB,IAAI,EAAE,KAAK;IACX,gBAAgB,EAAE,GAAG;
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,8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|
|
16
16
|
import z from '@deepseek-ai/schemastery';
|
|
17
|
+
import { ToolCallId } from '@deepseek-ai/dsh-llm';
|
|
18
|
+
import type { UserMessage } from '@deepseek-ai/dsh-llm';
|
|
17
19
|
import type { Session } from '@deepseek-ai/dsh-session';
|
|
20
|
+
import type { SummaryRow } from '@dsh-cc/tool-use-summary';
|
|
18
21
|
import type { MicrocompactConfig, MicrocompactResult, ResolvedConfig } from './types.ts';
|
|
19
22
|
export { DEFAULTS, MICROCOMPACT_MARKER, isMicrocompactPlaceholder, reuseSpillLocator, resolveConfig } from './config.ts';
|
|
20
23
|
export type { MicrocompactConfig, MicrocompactEntry, MicrocompactResult, ResolvedConfig, } from './types.ts';
|
|
@@ -23,6 +26,14 @@ declare module '@deepseek-ai/cordis' {
|
|
|
23
26
|
microcompactor: Microcompactor;
|
|
24
27
|
}
|
|
25
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Minimal agent surface the auto pass needs (structural: satisfied by the
|
|
31
|
+
* harness `Agent`, injectable by tests with a stub).
|
|
32
|
+
*/
|
|
33
|
+
interface AutoPassAgent {
|
|
34
|
+
readonly session: Session;
|
|
35
|
+
inject(message: UserMessage): void;
|
|
36
|
+
}
|
|
26
37
|
/**
|
|
27
38
|
* Model-free retention-window microcompaction service. Keeps the most recent
|
|
28
39
|
* {@link MicrocompactConfig.retainResults} tool results verbatim and replaces
|
|
@@ -38,6 +49,15 @@ export declare class Microcompactor extends Service {
|
|
|
38
49
|
static Config: z<MicrocompactConfig>;
|
|
39
50
|
/** Resolved and immutable policy. */
|
|
40
51
|
readonly config: ResolvedConfig;
|
|
52
|
+
/**
|
|
53
|
+
* Live `cc-tool-use-summary` settings reader (SINGLE SOURCE: the TUS
|
|
54
|
+
* package's settings.ts; `registerTusSettings` is idempotent per settings
|
|
55
|
+
* provider, so the producer plugin and this consumer share one
|
|
56
|
+
* registration). Only `upgradeMicroPlaceholders` is consulted here.
|
|
57
|
+
*/
|
|
58
|
+
private readonly readTusSettings;
|
|
59
|
+
/** Per-session auto-pass failure state, keyed by session id. */
|
|
60
|
+
private readonly failureState;
|
|
41
61
|
constructor(ctx: Context, config?: MicrocompactConfig);
|
|
42
62
|
/**
|
|
43
63
|
* Register an `agent/pre-step` hook that collapses stale tool results ahead
|
|
@@ -45,6 +65,26 @@ export declare class Microcompactor extends Service {
|
|
|
45
65
|
* window-reduced surface. Enabled only when `auto: true`.
|
|
46
66
|
*/
|
|
47
67
|
private _registerAutomaticMicrocompact;
|
|
68
|
+
/**
|
|
69
|
+
* One automatic pre-step pass: collapse stale tool results ahead of the
|
|
70
|
+
* turn's request, capped per session. After `failureCap` consecutive
|
|
71
|
+
* failures the pass pauses for the session and exactly one durable
|
|
72
|
+
* model-visible notice is injected via `agent.inject` (a next-step user
|
|
73
|
+
* message from plugin source, so the model learns auto-microcompact is
|
|
74
|
+
* paused and /compact is the manual path). Any later success resets the
|
|
75
|
+
* count, the pause, and the notice latch.
|
|
76
|
+
* @param agent - the agent whose session is compacted and which receives the pause notice.
|
|
77
|
+
* @param signal - the pre-step abort signal; an aborted signal skips the pass.
|
|
78
|
+
*/
|
|
79
|
+
autoMicrocompactPass(agent: AutoPassAgent, signal: AbortSignal): Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* Inject ONE durable model-visible pause notice as a next-step user message
|
|
82
|
+
* from plugin source. Defensive try/catch only: the harness does not
|
|
83
|
+
* restrict `inject` by agent level (`agent.ts:145-146` maps it to
|
|
84
|
+
* `send(input, 'next-step', false)`), so a failure here must not break the
|
|
85
|
+
* pause itself.
|
|
86
|
+
*/
|
|
87
|
+
private _injectPauseNotice;
|
|
48
88
|
/**
|
|
49
89
|
* Collapse every out-of-window tool result from one stable current-surface
|
|
50
90
|
* snapshot. The most recent `retainResults` tool results are kept verbatim;
|
|
@@ -52,12 +92,27 @@ export declare class Microcompactor extends Service {
|
|
|
52
92
|
* deterministic placeholder (reusing the original's spill locator when one is
|
|
53
93
|
* cited). Already-collapsed results are never re-decided, so a repeated pass
|
|
54
94
|
* over unchanged history emits a byte-identical prompt (freeze semantics).
|
|
95
|
+
*
|
|
96
|
+
* TUS upgrade (design doc §5.4 Consumer A): when a TUS summary row exists
|
|
97
|
+
* for a node's `callId` (and the `cc-tool-use-summary.upgradeMicroPlaceholders`
|
|
98
|
+
* gate is on), the placeholder carries the framed digest instead. Absent
|
|
99
|
+
* rows → the legacy placeholder bit-for-bit. Nodes whose body is already a
|
|
100
|
+
* context-crusher stub are never substituted (the stub's `context_retrieve`
|
|
101
|
+
* locator must survive). Pass `tus` explicitly when calling directly; the
|
|
102
|
+
* auto hook loads it from the TUS ledger.
|
|
55
103
|
* @param session - session whose current surface is rewritten.
|
|
104
|
+
* @param tus - TUS summaries for this session (callId → row), when available.
|
|
56
105
|
* @returns landed placeholder replacements and a stability flag.
|
|
57
106
|
* @throws when the session rejects a replacement; replacements committed
|
|
58
107
|
* earlier in the pass remain durable.
|
|
59
108
|
*/
|
|
60
|
-
microcompactSession(session: Session): MicrocompactResult;
|
|
109
|
+
microcompactSession(session: Session, tus?: ReadonlyMap<ToolCallId, SummaryRow>): MicrocompactResult;
|
|
110
|
+
/**
|
|
111
|
+
* Load the TUS ledger for one session (§5.3 pure reader). Empty/absent when
|
|
112
|
+
* the gate is off, the dshHomePath seam is missing, or the ledger has no
|
|
113
|
+
* rows — every failure degrades to `undefined` (legacy placeholders).
|
|
114
|
+
*/
|
|
115
|
+
private loadTusSummaries;
|
|
61
116
|
/** Deterministic placeholder body for one collapsed tool result. */
|
|
62
117
|
private placeholderContent;
|
|
63
118
|
}
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,CAAC,MAAM,0BAA0B,CAAA;
|
|
1
|
+
{"version":3,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AY,CAAkC;gBAEnD,GAAG,EAAE,OAAO,EAAE,MAAM,GAAE,kBAAuB;IAOzD;;;;OAIG;IACH,OAAO,CAAC,8BAA8B;IAetC;;;;;;;;;;OAUG;IACG,oBAAoB,CACxB,KAAK,EAAE,aAAa,EACpB,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC,IAAI,CAAC;IA8BhB;;;;;;OAMG;IACH,OAAO,CAAC,kBAAkB;IAc1B;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,mBAAmB,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,WAAW,CAAC,UAAU,EAAE,UAAU,CAAC,GAAG,kBAAkB;IAiEpG;;;;OAIG;YACW,gBAAgB;IAY9B,oEAAoE;IACpE,OAAO,CAAC,kBAAkB;CAS3B;AAiCD,eAAe,cAAc,CAAA"}
|
package/lib/index.js
CHANGED
|
@@ -14,11 +14,22 @@
|
|
|
14
14
|
*/
|
|
15
15
|
import { Service } from '@deepseek-ai/cordis';
|
|
16
16
|
import z from '@deepseek-ai/schemastery';
|
|
17
|
-
import { freezeMessage } from '@deepseek-ai/dsh-llm';
|
|
17
|
+
import { freezeMessage, ToolCallId, createUserMessage } from '@deepseek-ai/dsh-llm';
|
|
18
|
+
import { isCrusherStub, tusFramedSummary } from '@dsh-cc/tool-use-summary';
|
|
19
|
+
import { registerTusSettings, loadSummaries } from '@dsh-cc/tool-use-summary';
|
|
18
20
|
import { MICROCOMPACT_MARKER, isMicrocompactPlaceholder, resolveConfig, reuseSpillLocator, } from "./config.js";
|
|
19
21
|
export { DEFAULTS, MICROCOMPACT_MARKER, isMicrocompactPlaceholder, reuseSpillLocator, resolveConfig } from "./config.js";
|
|
20
22
|
const keepSchema = z.number().step(1).min(1);
|
|
21
23
|
const placeholderCharsSchema = z.number().step(1).min(1);
|
|
24
|
+
const failureCapSchema = z.number().step(1).min(1);
|
|
25
|
+
function dshHomeFn(ctx) {
|
|
26
|
+
try {
|
|
27
|
+
return ctx.dshHomePath;
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
22
33
|
/**
|
|
23
34
|
* Model-free retention-window microcompaction service. Keeps the most recent
|
|
24
35
|
* {@link MicrocompactConfig.retainResults} tool results verbatim and replaces
|
|
@@ -37,12 +48,23 @@ export class Microcompactor extends Service {
|
|
|
37
48
|
retainResults: keepSchema,
|
|
38
49
|
auto: z.boolean(),
|
|
39
50
|
placeholderChars: placeholderCharsSchema,
|
|
51
|
+
failureCap: failureCapSchema,
|
|
40
52
|
});
|
|
41
53
|
/** Resolved and immutable policy. */
|
|
42
54
|
config;
|
|
55
|
+
/**
|
|
56
|
+
* Live `cc-tool-use-summary` settings reader (SINGLE SOURCE: the TUS
|
|
57
|
+
* package's settings.ts; `registerTusSettings` is idempotent per settings
|
|
58
|
+
* provider, so the producer plugin and this consumer share one
|
|
59
|
+
* registration). Only `upgradeMicroPlaceholders` is consulted here.
|
|
60
|
+
*/
|
|
61
|
+
readTusSettings;
|
|
62
|
+
/** Per-session auto-pass failure state, keyed by session id. */
|
|
63
|
+
failureState = new Map();
|
|
43
64
|
constructor(ctx, config = {}) {
|
|
44
65
|
super(ctx, 'microcompactor');
|
|
45
66
|
this.config = resolveConfig(config);
|
|
67
|
+
this.readTusSettings = registerTusSettings(ctx);
|
|
46
68
|
if (this.config.auto)
|
|
47
69
|
this._registerAutomaticMicrocompact();
|
|
48
70
|
}
|
|
@@ -54,21 +76,75 @@ export class Microcompactor extends Service {
|
|
|
54
76
|
_registerAutomaticMicrocompact() {
|
|
55
77
|
const { ctx } = this;
|
|
56
78
|
ctx.on('agent/pre-step', async ({ agent, signal }, next) => {
|
|
57
|
-
|
|
58
|
-
try {
|
|
59
|
-
const result = this.microcompactSession(agent.session);
|
|
60
|
-
if (result.replaced.length > 0) {
|
|
61
|
-
ctx.logger.info(`microcompact: collapsed ${result.replaced.length} stale tool result(s) `
|
|
62
|
-
+ `(retain ${this.config.retainResults})`);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
catch (error) {
|
|
66
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
67
|
-
ctx.logger.warn(`microcompact failed: ${message}; continuing the turn`);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
79
|
+
await this.autoMicrocompactPass(agent, signal);
|
|
70
80
|
return next();
|
|
71
81
|
});
|
|
82
|
+
// Free the per-session failure state when the session goes away (no leak).
|
|
83
|
+
ctx.on('session/disposed', (session) => {
|
|
84
|
+
this.failureState.delete(String(session.header.id));
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* One automatic pre-step pass: collapse stale tool results ahead of the
|
|
89
|
+
* turn's request, capped per session. After `failureCap` consecutive
|
|
90
|
+
* failures the pass pauses for the session and exactly one durable
|
|
91
|
+
* model-visible notice is injected via `agent.inject` (a next-step user
|
|
92
|
+
* message from plugin source, so the model learns auto-microcompact is
|
|
93
|
+
* paused and /compact is the manual path). Any later success resets the
|
|
94
|
+
* count, the pause, and the notice latch.
|
|
95
|
+
* @param agent - the agent whose session is compacted and which receives the pause notice.
|
|
96
|
+
* @param signal - the pre-step abort signal; an aborted signal skips the pass.
|
|
97
|
+
*/
|
|
98
|
+
async autoMicrocompactPass(agent, signal) {
|
|
99
|
+
const { ctx } = this;
|
|
100
|
+
const sessionId = String(agent.session.header.id);
|
|
101
|
+
const state = this.failureState.get(sessionId);
|
|
102
|
+
if (state?.paused)
|
|
103
|
+
return;
|
|
104
|
+
if (signal.aborted)
|
|
105
|
+
return;
|
|
106
|
+
try {
|
|
107
|
+
const result = this.microcompactSession(agent.session, await this.loadTusSummaries(agent.session));
|
|
108
|
+
// Success (even with 0 replacements) resets attempts, pause, and latch.
|
|
109
|
+
this.failureState.set(sessionId, { count: 0, paused: false, noticed: false });
|
|
110
|
+
if (result.replaced.length > 0) {
|
|
111
|
+
ctx.logger.info(`microcompact: collapsed ${result.replaced.length} stale tool result(s) `
|
|
112
|
+
+ `(retain ${this.config.retainResults})`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
117
|
+
ctx.logger.warn(`microcompact failed: ${message}; continuing the turn`);
|
|
118
|
+
const entry = state ?? { count: 0, paused: false, noticed: false };
|
|
119
|
+
entry.count += 1;
|
|
120
|
+
this.failureState.set(sessionId, entry);
|
|
121
|
+
if (entry.count >= this.config.failureCap && !entry.noticed) {
|
|
122
|
+
entry.paused = true;
|
|
123
|
+
entry.noticed = true;
|
|
124
|
+
this._injectPauseNotice(agent, message);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Inject ONE durable model-visible pause notice as a next-step user message
|
|
130
|
+
* from plugin source. Defensive try/catch only: the harness does not
|
|
131
|
+
* restrict `inject` by agent level (`agent.ts:145-146` maps it to
|
|
132
|
+
* `send(input, 'next-step', false)`), so a failure here must not break the
|
|
133
|
+
* pause itself.
|
|
134
|
+
*/
|
|
135
|
+
_injectPauseNotice(agent, lastError) {
|
|
136
|
+
const text = `microcompact failed ${this.config.failureCap} consecutive time(s) (last: ${lastError}); `
|
|
137
|
+
+ 'auto-microcompact paused for this session — run /compact manually to compress context';
|
|
138
|
+
try {
|
|
139
|
+
agent.inject(createUserMessage({
|
|
140
|
+
content: [{ type: 'text', text }],
|
|
141
|
+
source: { kind: 'plugin', plugin: 'compaction-micro' },
|
|
142
|
+
}));
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
146
|
+
this.ctx.logger.warn(`microcompact: failed to inject pause notice: ${message}`);
|
|
147
|
+
}
|
|
72
148
|
}
|
|
73
149
|
/**
|
|
74
150
|
* Collapse every out-of-window tool result from one stable current-surface
|
|
@@ -77,12 +153,21 @@ export class Microcompactor extends Service {
|
|
|
77
153
|
* deterministic placeholder (reusing the original's spill locator when one is
|
|
78
154
|
* cited). Already-collapsed results are never re-decided, so a repeated pass
|
|
79
155
|
* over unchanged history emits a byte-identical prompt (freeze semantics).
|
|
156
|
+
*
|
|
157
|
+
* TUS upgrade (design doc §5.4 Consumer A): when a TUS summary row exists
|
|
158
|
+
* for a node's `callId` (and the `cc-tool-use-summary.upgradeMicroPlaceholders`
|
|
159
|
+
* gate is on), the placeholder carries the framed digest instead. Absent
|
|
160
|
+
* rows → the legacy placeholder bit-for-bit. Nodes whose body is already a
|
|
161
|
+
* context-crusher stub are never substituted (the stub's `context_retrieve`
|
|
162
|
+
* locator must survive). Pass `tus` explicitly when calling directly; the
|
|
163
|
+
* auto hook loads it from the TUS ledger.
|
|
80
164
|
* @param session - session whose current surface is rewritten.
|
|
165
|
+
* @param tus - TUS summaries for this session (callId → row), when available.
|
|
81
166
|
* @returns landed placeholder replacements and a stability flag.
|
|
82
167
|
* @throws when the session rejects a replacement; replacements committed
|
|
83
168
|
* earlier in the pass remain durable.
|
|
84
169
|
*/
|
|
85
|
-
microcompactSession(session) {
|
|
170
|
+
microcompactSession(session, tus) {
|
|
86
171
|
const candidates = snapshotCandidates(session);
|
|
87
172
|
const retainedFrom = Math.max(0, candidates.length - this.config.retainResults);
|
|
88
173
|
const replaced = [];
|
|
@@ -94,8 +179,18 @@ export class Microcompactor extends Service {
|
|
|
94
179
|
const blocks = resultBlock?.content ?? [];
|
|
95
180
|
if (isMicrocompactPlaceholder(blocks))
|
|
96
181
|
continue;
|
|
182
|
+
// §5.6: a crushed result's reversibility lives in its `context_retrieve`
|
|
183
|
+
// locator — a TUS substitution would destroy it, so skip.
|
|
184
|
+
if (isCrusherStub(plainText(blocks)))
|
|
185
|
+
continue;
|
|
97
186
|
const locatorLine = reuseSpillLocator(plainText(blocks));
|
|
98
|
-
const
|
|
187
|
+
const tusRow = tus?.get(message.source.callId);
|
|
188
|
+
const placeholder = tusRow !== undefined
|
|
189
|
+
&& this.readTusSettings().upgradeMicroPlaceholders
|
|
190
|
+
&& tusRow.status === 'ok'
|
|
191
|
+
&& typeof tusRow.summary === 'string'
|
|
192
|
+
? `${tusFramedSummary(tusRow)}${locatorLine === undefined ? '' : `\n${locatorLine}`}`
|
|
193
|
+
: this.placeholderContent(locatorLine);
|
|
99
194
|
// Preserve every non-content field of the original tool-result block (type,
|
|
100
195
|
// toolCallId, isError, plus future additions) so the surface rewrite honors
|
|
101
196
|
// the "may change only content" invariant.
|
|
@@ -135,6 +230,25 @@ export class Microcompactor extends Service {
|
|
|
135
230
|
}
|
|
136
231
|
return { replaced, stable: replaced.length === 0 };
|
|
137
232
|
}
|
|
233
|
+
/**
|
|
234
|
+
* Load the TUS ledger for one session (§5.3 pure reader). Empty/absent when
|
|
235
|
+
* the gate is off, the dshHomePath seam is missing, or the ledger has no
|
|
236
|
+
* rows — every failure degrades to `undefined` (legacy placeholders).
|
|
237
|
+
*/
|
|
238
|
+
async loadTusSummaries(session) {
|
|
239
|
+
try {
|
|
240
|
+
if (!this.readTusSettings().upgradeMicroPlaceholders)
|
|
241
|
+
return undefined;
|
|
242
|
+
const home = dshHomeFn(this.ctx);
|
|
243
|
+
if (home === undefined)
|
|
244
|
+
return undefined;
|
|
245
|
+
const rows = await loadSummaries(home(), String(session.header.id));
|
|
246
|
+
return rows.size === 0 ? undefined : new Map([...rows].map(([callId, row]) => [ToolCallId(callId), row]));
|
|
247
|
+
}
|
|
248
|
+
catch {
|
|
249
|
+
return undefined;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
138
252
|
/** Deterministic placeholder body for one collapsed tool result. */
|
|
139
253
|
placeholderContent(locatorLine) {
|
|
140
254
|
const markerText = `${MICROCOMPACT_MARKER} (tool result collapsed by microcompact; `
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAW,OAAO,EAAE,MAAM,qBAAqB,CAAA;AACt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AAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAC/B,IAAI,MAAM,CAAC,MAAM,IAAI,GAAG;QAAE,OAAO,IAAI,CAAA;IACrC,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;AACtC,CAAC;AAED,eAAe,cAAc,CAAA"}
|
package/lib/types.d.ts
CHANGED
|
@@ -15,12 +15,19 @@ export interface MicrocompactConfig {
|
|
|
15
15
|
auto?: boolean;
|
|
16
16
|
/** Maximum text code points in a generated placeholder (excluding a re-embedded spill locator). Defaults to `256`. */
|
|
17
17
|
placeholderChars?: number;
|
|
18
|
+
/**
|
|
19
|
+
* Consecutive auto pre-step pass failures tolerated before the pass pauses
|
|
20
|
+
* for the session and one durable model-visible notice is injected. Defaults
|
|
21
|
+
* to `3`.
|
|
22
|
+
*/
|
|
23
|
+
failureCap?: number;
|
|
18
24
|
}
|
|
19
25
|
/** Validated, detached, deeply immutable microcompact configuration. */
|
|
20
26
|
export interface ResolvedConfig {
|
|
21
27
|
readonly retainResults: number;
|
|
22
28
|
readonly auto: boolean;
|
|
23
29
|
readonly placeholderChars: number;
|
|
30
|
+
readonly failureCap: number;
|
|
24
31
|
}
|
|
25
32
|
/** One landed placeholder replacement during a microcompact pass. */
|
|
26
33
|
export interface MicrocompactEntry {
|
package/lib/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAEtD;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,sEAAsE;IACtE,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB;;;;OAIG;IACH,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,sHAAsH;IACtH,gBAAgB,CAAC,EAAE,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AAEtD;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,sEAAsE;IACtE,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB;;;;OAIG;IACH,IAAI,CAAC,EAAE,OAAO,CAAA;IACd,sHAAsH;IACtH,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB;AAED,wEAAwE;AACxE,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAA;IAC9B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;IACtB,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAA;IACjC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;CAC5B;AAED,qEAAqE;AACrE,MAAM,WAAW,iBAAiB;IAChC,yEAAyE;IACzE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAA;IAC5B,0DAA0D;IAC1D,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAA;IAC/B,4DAA4D;IAC5D,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAA;IAC3B,mFAAmF;IACnF,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAC/B;AAED,iEAAiE;AACjE,MAAM,WAAW,kBAAkB;IACjC,iEAAiE;IACjE,QAAQ,CAAC,QAAQ,EAAE,SAAS,iBAAiB,EAAE,CAAA;IAC/C;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAA;CACzB"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dsh-cc/compaction-micro",
|
|
3
3
|
"description": "Replay-safe model-free microcompaction of stale tool-result surface nodes",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.8.0-rc.1",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/dsh-cc/dsh-cc.git",
|
|
@@ -33,7 +33,8 @@
|
|
|
33
33
|
"@deepseek-ai/dsh-token-meter": ">=0.1.5-rc.1",
|
|
34
34
|
"@deepseek-ai/cordis": ">=0.1.5-rc.1",
|
|
35
35
|
"@deepseek-ai/schemastery": "^3.18.1",
|
|
36
|
-
"@deepseek-ai/dsh-util-values": ">=0.1.5-rc.1"
|
|
36
|
+
"@deepseek-ai/dsh-util-values": ">=0.1.5-rc.1",
|
|
37
|
+
"@dsh-cc/tool-use-summary": "^0.8.0-rc.1"
|
|
37
38
|
},
|
|
38
39
|
"devDependencies": {
|
|
39
40
|
"@deepseek-ai/cordis": "link:../../../../deepseek-harness/vendor/cordis",
|
|
@@ -47,7 +48,8 @@
|
|
|
47
48
|
"@deepseek-ai/dsh-session": "link:../../../../deepseek-harness/packages/core/session",
|
|
48
49
|
"@deepseek-ai/dsh-token-meter": "link:../../../../deepseek-harness/packages/llm/token-meter",
|
|
49
50
|
"@deepseek-ai/dsh-util-values": "link:../../../../deepseek-harness/packages/util/values",
|
|
50
|
-
"@deepseek-ai/schemastery": "link:../../../../deepseek-harness/vendor/schemastery"
|
|
51
|
+
"@deepseek-ai/schemastery": "link:../../../../deepseek-harness/vendor/schemastery",
|
|
52
|
+
"@dsh-cc/tool-use-summary": "^0.8.0-rc.1"
|
|
51
53
|
},
|
|
52
54
|
"publishConfig": {
|
|
53
55
|
"access": "public"
|