@duetso/agent 0.1.150 → 0.1.152
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/dist/package.json +1 -1
- package/dist/src/cli/rpc.d.ts +3 -2
- package/dist/src/cli/rpc.d.ts.map +1 -1
- package/dist/src/cli/rpc.js +7 -1
- package/dist/src/cli/rpc.js.map +1 -1
- package/dist/src/memory/loader.d.ts.map +1 -1
- package/dist/src/memory/loader.js +1 -4
- package/dist/src/memory/loader.js.map +1 -1
- package/dist/src/memory/observational.d.ts +32 -11
- package/dist/src/memory/observational.d.ts.map +1 -1
- package/dist/src/memory/observational.js +36 -12
- package/dist/src/memory/observational.js.map +1 -1
- package/dist/src/memory/storage.d.ts.map +1 -1
- package/dist/src/memory/storage.js +1 -3
- package/dist/src/memory/storage.js.map +1 -1
- package/dist/src/session/session.d.ts +16 -1
- package/dist/src/session/session.d.ts.map +1 -1
- package/dist/src/session/session.js +18 -0
- package/dist/src/session/session.js.map +1 -1
- package/dist/src/tui/app.js +7 -7
- package/dist/src/tui/app.js.map +1 -1
- package/dist/src/tui/dino/index.d.ts +0 -4
- package/dist/src/tui/dino/index.d.ts.map +1 -1
- package/dist/src/tui/dino/index.js +9 -41
- package/dist/src/tui/dino/index.js.map +1 -1
- package/dist/src/tui/dino/visibility.d.ts +1 -1
- package/dist/src/tui/dino/visibility.d.ts.map +1 -1
- package/dist/src/tui/dino/visibility.js +10 -10
- package/dist/src/tui/dino/visibility.js.map +1 -1
- package/dist/src/tui/key-handlers.d.ts +1 -1
- package/dist/src/tui/layout.d.ts +5 -6
- package/dist/src/tui/layout.d.ts.map +1 -1
- package/dist/src/tui/layout.js.map +1 -1
- package/dist/src/tui/slash-commands.d.ts +8 -0
- package/dist/src/tui/slash-commands.d.ts.map +1 -1
- package/dist/src/tui/slash-commands.js +22 -0
- package/dist/src/tui/slash-commands.js.map +1 -1
- package/dist/src/turn-runner/state-compaction.d.ts +11 -0
- package/dist/src/turn-runner/state-compaction.d.ts.map +1 -1
- package/dist/src/turn-runner/state-compaction.js +11 -0
- package/dist/src/turn-runner/state-compaction.js.map +1 -1
- package/dist/src/turn-runner/turn-runner.d.ts +51 -4
- package/dist/src/turn-runner/turn-runner.d.ts.map +1 -1
- package/dist/src/turn-runner/turn-runner.js +177 -3
- package/dist/src/turn-runner/turn-runner.js.map +1 -1
- package/dist/src/turn-runner/wire-shaping.d.ts +5 -15
- package/dist/src/turn-runner/wire-shaping.d.ts.map +1 -1
- package/dist/src/turn-runner/wire-shaping.js +12 -5
- package/dist/src/turn-runner/wire-shaping.js.map +1 -1
- package/dist/src/types/config.d.ts +6 -4
- package/dist/src/types/config.d.ts.map +1 -1
- package/dist/src/types/memory.d.ts +6 -2
- package/dist/src/types/memory.d.ts.map +1 -1
- package/dist/src/types/protocol.d.ts +69 -1
- package/dist/src/types/protocol.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slash-commands.js","sourceRoot":"","sources":["../../../src/tui/slash-commands.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"slash-commands.js","sourceRoot":"","sources":["../../../src/tui/slash-commands.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAmGpC,0CAA0C;AAC1C,SAAS,MAAM,CAAC,OAAe,EAAE,IAAY;IAC3C,OAAO,OAAO,KAAK,IAAI,IAAI,EAAE,CAAC;AAChC,CAAC;AAED,iCAAiC;AACjC,SAAS,YAAY,CAAC,OAAe,EAAE,IAAY;IACjD,OAAO,OAAO,KAAK,IAAI,IAAI,EAAE,IAAI,OAAO,CAAC,UAAU,CAAC,IAAI,IAAI,GAAG,CAA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B;IACvE,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;QACjB,GAAG,CAAC,WAAW,CAAC,WAAW,EAAE,0CAA0C,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;QACxF,OAAO;IACT,CAAC;IACD,GAAG,CAAC,OAAO,EAAE,CAAC;IACd,GAAG,CAAC,WAAW,CACb,WAAW,EACX,2DAA2D,EAC3D,MAAM,CAAC,MAAM,CACd,CAAC;AACJ,CAAC;AAED,KAAK,UAAU,uBAAuB,CAAC,GAAW,EAAE,GAAwB;IAC1E,MAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;IAC/C,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,GAAG,CAAC,WAAW,CACb,SAAS,EACT,8DAA8D,EAC9D,MAAM,CAAC,MAAM,CACd,CAAC;QACF,OAAO;IACT,CAAC;IACD,MAAM,GAAG,CAAC,eAAe,EAAE,mBAAmB,CAAC,IAAI,CAAC,CAAC;AACvD,CAAC"}
|
|
@@ -26,6 +26,17 @@ export interface CompactionResult {
|
|
|
26
26
|
/** Serialized byte length after compaction, for caller logging/metrics. */
|
|
27
27
|
bytes: number;
|
|
28
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Fraction of the parent agent's effective context window that the on-demand
|
|
31
|
+
* `compact` command targets for the surviving wire-tail. 20% is an
|
|
32
|
+
* intentionally aggressive ceiling: it leaves the remaining 80% of the
|
|
33
|
+
* window for the system prompt, memory packs, the next user prompt, and
|
|
34
|
+
* the next assistant response, so a freshly compacted session has real
|
|
35
|
+
* headroom for the next turn instead of immediately bumping the
|
|
36
|
+
* auto-compaction ceiling again. The runner consumes this via the
|
|
37
|
+
* wire-shaping `WireGuardHorizon`; nothing on disk changes.
|
|
38
|
+
*/
|
|
39
|
+
export declare const COMPACT_MESSAGE_TOKENS_RATIO = 0.2;
|
|
29
40
|
/**
|
|
30
41
|
* Returns a new `TurnState` whose serialized size is at most `maxBytes`,
|
|
31
42
|
* evicting the oldest agent messages first. After each eviction, drops any
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state-compaction.d.ts","sourceRoot":"","sources":["../../../src/turn-runner/state-compaction.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEtD;;;;;;;;;GASG;AACH,eAAO,MAAM,uBAAuB,QAAoB,CAAC;AAEzD;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,IAAI,CAAC;AAEvC,MAAM,WAAW,0BAA0B;IACzC,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,SAAS,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,2EAA2E;IAC3E,KAAK,EAAE,MAAM,CAAC;CACf;
|
|
1
|
+
{"version":3,"file":"state-compaction.d.ts","sourceRoot":"","sources":["../../../src/turn-runner/state-compaction.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEtD;;;;;;;;;GASG;AACH,eAAO,MAAM,uBAAuB,QAAoB,CAAC;AAEzD;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,IAAI,CAAC;AAEvC,MAAM,WAAW,0BAA0B;IACzC,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,SAAS,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,2EAA2E;IAC3E,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,4BAA4B,MAAM,CAAC;AAahD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,SAAS,EAChB,OAAO,GAAE,0BAA+B,GACvC,gBAAgB,CA8BlB"}
|
|
@@ -15,6 +15,17 @@ export const DEFAULT_STATE_MAX_BYTES = 100 * 1024 * 1024;
|
|
|
15
15
|
* from a truncated transcript, but not from an empty one.
|
|
16
16
|
*/
|
|
17
17
|
export const MIN_RETAINED_MESSAGES = 1;
|
|
18
|
+
/**
|
|
19
|
+
* Fraction of the parent agent's effective context window that the on-demand
|
|
20
|
+
* `compact` command targets for the surviving wire-tail. 20% is an
|
|
21
|
+
* intentionally aggressive ceiling: it leaves the remaining 80% of the
|
|
22
|
+
* window for the system prompt, memory packs, the next user prompt, and
|
|
23
|
+
* the next assistant response, so a freshly compacted session has real
|
|
24
|
+
* headroom for the next turn instead of immediately bumping the
|
|
25
|
+
* auto-compaction ceiling again. The runner consumes this via the
|
|
26
|
+
* wire-shaping `WireGuardHorizon`; nothing on disk changes.
|
|
27
|
+
*/
|
|
28
|
+
export const COMPACT_MESSAGE_TOKENS_RATIO = 0.2;
|
|
18
29
|
/**
|
|
19
30
|
* Anthropic and OpenAI both reject conversations whose first message isn't
|
|
20
31
|
* `user`. Front-eviction can leave a `toolResult` (orphaned without its
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state-compaction.js","sourceRoot":"","sources":["../../../src/turn-runner/state-compaction.ts"],"names":[],"mappings":"AAGA;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,GAAG,IAAI,GAAG,IAAI,CAAC;AAEzD;;;;GAIG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC;AAcvC;;;;;GAKG;AACH,SAAS,aAAa,CAAC,OAAiC;IACtD,IAAI,CAAC,OAAO,IAAI,CAAC,CAAC,MAAM,IAAI,OAAO,CAAC;QAAE,OAAO,KAAK,CAAC;IACnD,OAAO,OAAO,CAAC,IAAI,KAAK,YAAY,IAAI,OAAO,CAAC,IAAI,KAAK,WAAW,CAAC;AACvE,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAA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EAAE,CAAC;QACvC,uEAAuE;QACvE,UAAU;QACV,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,MAAM,EAAE,CAAC;IACzD,CAAC;IAED,MAAM,OAAO,GAAmB,CAAC,GAAG,QAAQ,CAAC,CAAC;IAC9C,IAAI,OAAO,GAAc,KAAK,CAAC;IAC/B,IAAI,OAAO,GAAG,CAAC,CAAC;IAEhB,OAAO,UAAU,CAAC,MAAM,GAAG,QAAQ,IAAI,OAAO,CAAC,MAAM,GAAG,qBAAqB,EAAE,CAAC;QAC9E,OAAO,CAAC,KAAK,EAAE,CAAC;QAChB,OAAO,IAAI,CAAC,CAAC;QACb,OAAO,OAAO,CAAC,MAAM,GAAG,qBAAqB,IAAI,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAC3E,OAAO,CAAC,KAAK,EAAE,CAAC;YAChB,OAAO,IAAI,CAAC,CAAC;QACf,CAAC;QACD,OAAO,GAAG,EAAE,GAAG,OAAO,EAAE,KAAK,EAAE,EAAE,GAAG,OAAO,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,CAAC;QACzE,UAAU,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IACvC,CAAC;IAED,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,UAAU,CAAC,MAAM,EAAE,CAAC;AAC/D,CAAC"}
|
|
@@ -4,9 +4,8 @@ import type { Skill } from "@earendil-works/pi-coding-agent";
|
|
|
4
4
|
import type { SkillCollision } from "./skills.js";
|
|
5
5
|
import { MemoryContextCache } from "../memory/store.js";
|
|
6
6
|
import type { TurnRunnerConfig } from "../types/config.js";
|
|
7
|
-
import type { TurnAgentFile, TurnAnswerCommand, TurnContextWindowUsage, TurnEditFollowUpQueueCommand, TurnEvent, TurnEventOrigin, TurnInterruptCommand, TurnMode, TurnPromptCommand, TurnState, TurnTokenUsage, TurnStartCommand, TurnTerminalEvent, TurnCommand, TurnOptions } from "../types/protocol.js";
|
|
7
|
+
import type { TurnAgentFile, TurnAnswerCommand, TurnContextWindowUsage, WireGuardHorizon, TurnEditFollowUpQueueCommand, TurnEvent, TurnEventOrigin, TurnInterruptCommand, TurnMode, TurnPromptCommand, TurnState, TurnTokenUsage, TurnStartCommand, TurnTerminalEvent, TurnCommand, TurnOptions } from "../types/protocol.js";
|
|
8
8
|
import type { StateMachineAgentState } from "../types/state-machine.js";
|
|
9
|
-
import { type WireGuardHorizon } from "./wire-shaping.js";
|
|
10
9
|
import { type TurnRunnerControlResult } from "./tools.js";
|
|
11
10
|
import { SkillContext } from "./skill-context.js";
|
|
12
11
|
import { type StateAgentHandle } from "./state-machine-controller.js";
|
|
@@ -95,6 +94,15 @@ export declare class TurnRunner {
|
|
|
95
94
|
* transitions, but it emits one public terminal event for the whole chain.
|
|
96
95
|
*/
|
|
97
96
|
private activeTurnPromise?;
|
|
97
|
+
/**
|
|
98
|
+
* In-flight `compact()` promise, published while the drain + horizon
|
|
99
|
+
* advance is running so concurrent `turn()` calls can serialize behind
|
|
100
|
+
* it. Compact has no `activeTurnPromise` (it does not start a turn
|
|
101
|
+
* chain), so this is the only signal a fire-and-forget caller (e.g. the
|
|
102
|
+
* TUI `/compact` slash command followed immediately by a prompt) has
|
|
103
|
+
* that the wire-shaping horizon is mid-advance.
|
|
104
|
+
*/
|
|
105
|
+
private compactInFlight?;
|
|
98
106
|
/** Latest runner-owned state, hydrated by start() and advanced by terminal events. */
|
|
99
107
|
private state?;
|
|
100
108
|
/** True after `start()` has emitted the initial `turn_started` event. */
|
|
@@ -126,6 +134,45 @@ export declare class TurnRunner {
|
|
|
126
134
|
dispose(): Promise<void>;
|
|
127
135
|
subscribe(handler: TurnEventHandler): () => void;
|
|
128
136
|
editFollowUpQueue(command: TurnEditFollowUpQueueCommand): void;
|
|
137
|
+
/**
|
|
138
|
+
* Compact the runner's wire-visible message tail on demand by advancing
|
|
139
|
+
* the sticky `wireGuardHorizon` so the next request to the actor model
|
|
140
|
+
* dispatches a smaller prompt.
|
|
141
|
+
*
|
|
142
|
+
* Critical: this does **not** mutate `state.agent.messages` or the live
|
|
143
|
+
* parent agent's transcript. The durable transcript is the source of
|
|
144
|
+
* truth for resume, snapshotting, observer/reflector passes, and the
|
|
145
|
+
* TUI scrollback; destroying it would lose information the wire-shaping
|
|
146
|
+
* pipeline is specifically designed to preserve. Instead this reuses
|
|
147
|
+
* the same horizon-advance mechanism that
|
|
148
|
+
* `createObservationalContextTransform` runs every turn — it just
|
|
149
|
+
* forces it now, against a tighter token target than the automatic
|
|
150
|
+
* trigger uses.
|
|
151
|
+
*
|
|
152
|
+
* Target selection:
|
|
153
|
+
* - When the current wire-tail tokens exceed
|
|
154
|
+
* `COMPACT_MESSAGE_TOKENS_RATIO` (20%) of the parent agent's
|
|
155
|
+
* effective context window, the target is that 20% ceiling —
|
|
156
|
+
* leaving 80% headroom for system prompt, memory packs, the next
|
|
157
|
+
* user prompt, and the next assistant response.
|
|
158
|
+
* - When the wire-tail is already under 20%, the target halves the
|
|
159
|
+
* current wire-tail tokens instead. `compact` is user-initiated, so
|
|
160
|
+
* even an already-light session must produce visible relief.
|
|
161
|
+
*
|
|
162
|
+
* On a successful horizon advance the memory context pack is refreshed
|
|
163
|
+
* (same fire-and-forget call the transform's `onCompaction` handler
|
|
164
|
+
* uses) so the rendered prefix lines up with the new horizon and the
|
|
165
|
+
* next prompt-cache fault is paid once instead of twice.
|
|
166
|
+
*
|
|
167
|
+
* Rejected with a soft warning when a turn chain is in flight —
|
|
168
|
+
* mutating the horizon mid-stream would invalidate the request the
|
|
169
|
+
* parent (or a state agent) is already dispatching. `activeTurnPromise`
|
|
170
|
+
* is the single source of truth here, so poll/timer sleeps pass the
|
|
171
|
+
* gate cleanly: the chain has already resolved to the `sleep` terminal
|
|
172
|
+
* before compact is allowed to run.
|
|
173
|
+
*/
|
|
174
|
+
compact(): Promise<void>;
|
|
175
|
+
private runCompact;
|
|
129
176
|
/**
|
|
130
177
|
* Set up a session before any turn runs. Loads memory and skills, then
|
|
131
178
|
* emits `turn_started` with the initial state (a fresh state, or the
|
|
@@ -390,7 +437,7 @@ export declare class TurnRunner {
|
|
|
390
437
|
/**
|
|
391
438
|
* Estimate the per-segment occupancy of the parent agent's input before
|
|
392
439
|
* reconciliation with provider `totalTokens`. System prompt and memory
|
|
393
|
-
* packs use the same `ceil(chars/
|
|
440
|
+
* packs use the same `ceil(chars / CHARS_PER_TOKEN)` heuristic as the memory pipeline so
|
|
394
441
|
* compaction triggers stay on the same scale as `MEMORY_BUDGET_RATIOS`.
|
|
395
442
|
*
|
|
396
443
|
* The message tail uses {@link calculateWireTokens} over the
|
|
@@ -398,7 +445,7 @@ export declare class TurnRunner {
|
|
|
398
445
|
* messages already dropped by wire-shaping stop counting against the
|
|
399
446
|
* `messages` segment instead of inflating it from the runner's full
|
|
400
447
|
* retained transcript. Text and structured blocks (`toolCall`, thinking,
|
|
401
|
-
* etc.) use `ceil(chars/
|
|
448
|
+
* etc.) use `ceil(chars / CHARS_PER_TOKEN)`, and image blocks contribute a fixed
|
|
402
449
|
* per-image estimate rather than their base64 byte length.
|
|
403
450
|
*
|
|
404
451
|
* `emitParentAgentEvent` rescales all four segments with
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"turn-runner.d.ts","sourceRoot":"","sources":["../../../src/turn-runner/turn-runner.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,KAAK,UAAU,EACf,KAAK,YAAY,EACjB,KAAK,SAAS,EACf,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAGL,KAAK,YAAY,EACjB,KAAK,KAAK,EACX,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAgBlD,OAAO,EAAE,kBAAkB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CAAC,KAAK,CAAC,EAAE,cAAc,GAAG,KAAK,GAAG,IAAI;IAI3D,SAAS,CAAC,cAAc,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,eAAe,GAAG,IAAI;IAS3E,SAAS,CAAC,oBAAoB,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI;IAoBvD;;;;;;;;;OASG;IACH,SAAS,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,eAAe,GAAG,IAAI;IAYvD;;;;;;;;;;;;;;;;;OAiBG;IACH,SAAS,CAAC,0BAA0B;;;;;;IAgBpC;;;;;;;OAOG;IACH,SAAS,CAAC,sBAAsB,IAAI,MAAM;IAK1C;;;;;;OAMG;IACH,SAAS,CAAC,uBAAuB,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM;CAIhE"}
|
|
@@ -9,7 +9,7 @@ import { createEmbeddingClient } from "../memory/embedding.js";
|
|
|
9
9
|
import { loadStoredMemory } from "../memory/storage.js";
|
|
10
10
|
import { MemoryContextCache } from "../memory/store.js";
|
|
11
11
|
import { DEFAULT_CLI_MEMORY_MODEL, DEFAULT_CLI_MODEL, resolveModelName, } from "../model-resolution/resolver.js";
|
|
12
|
-
import { compactTurnState } from "./state-compaction.js";
|
|
12
|
+
import { COMPACT_MESSAGE_TOKENS_RATIO, compactTurnState, } from "./state-compaction.js";
|
|
13
13
|
import { agentEventToTurnEvents, agentMessageText } from "./agent-events.js";
|
|
14
14
|
import { createRecallMemorySystemPromptLayer, createSourceOfTruthSystemPromptLayer, createStateMachineSystemPromptLayer, } from "./prompts.js";
|
|
15
15
|
import { applyEvictionHorizon, calculateWireTokens, createInitialHorizon, findEvictionHorizon, } from "./wire-shaping.js";
|
|
@@ -127,6 +127,15 @@ export class TurnRunner {
|
|
|
127
127
|
* transitions, but it emits one public terminal event for the whole chain.
|
|
128
128
|
*/
|
|
129
129
|
activeTurnPromise;
|
|
130
|
+
/**
|
|
131
|
+
* In-flight `compact()` promise, published while the drain + horizon
|
|
132
|
+
* advance is running so concurrent `turn()` calls can serialize behind
|
|
133
|
+
* it. Compact has no `activeTurnPromise` (it does not start a turn
|
|
134
|
+
* chain), so this is the only signal a fire-and-forget caller (e.g. the
|
|
135
|
+
* TUI `/compact` slash command followed immediately by a prompt) has
|
|
136
|
+
* that the wire-shaping horizon is mid-advance.
|
|
137
|
+
*/
|
|
138
|
+
compactInFlight;
|
|
130
139
|
/** Latest runner-owned state, hydrated by start() and advanced by terminal events. */
|
|
131
140
|
state;
|
|
132
141
|
/** True after `start()` has emitted the initial `turn_started` event. */
|
|
@@ -179,6 +188,144 @@ export class TurnRunner {
|
|
|
179
188
|
this.requireStarted();
|
|
180
189
|
this.replaceFollowUpQueue(command.prompts);
|
|
181
190
|
}
|
|
191
|
+
/**
|
|
192
|
+
* Compact the runner's wire-visible message tail on demand by advancing
|
|
193
|
+
* the sticky `wireGuardHorizon` so the next request to the actor model
|
|
194
|
+
* dispatches a smaller prompt.
|
|
195
|
+
*
|
|
196
|
+
* Critical: this does **not** mutate `state.agent.messages` or the live
|
|
197
|
+
* parent agent's transcript. The durable transcript is the source of
|
|
198
|
+
* truth for resume, snapshotting, observer/reflector passes, and the
|
|
199
|
+
* TUI scrollback; destroying it would lose information the wire-shaping
|
|
200
|
+
* pipeline is specifically designed to preserve. Instead this reuses
|
|
201
|
+
* the same horizon-advance mechanism that
|
|
202
|
+
* `createObservationalContextTransform` runs every turn — it just
|
|
203
|
+
* forces it now, against a tighter token target than the automatic
|
|
204
|
+
* trigger uses.
|
|
205
|
+
*
|
|
206
|
+
* Target selection:
|
|
207
|
+
* - When the current wire-tail tokens exceed
|
|
208
|
+
* `COMPACT_MESSAGE_TOKENS_RATIO` (20%) of the parent agent's
|
|
209
|
+
* effective context window, the target is that 20% ceiling —
|
|
210
|
+
* leaving 80% headroom for system prompt, memory packs, the next
|
|
211
|
+
* user prompt, and the next assistant response.
|
|
212
|
+
* - When the wire-tail is already under 20%, the target halves the
|
|
213
|
+
* current wire-tail tokens instead. `compact` is user-initiated, so
|
|
214
|
+
* even an already-light session must produce visible relief.
|
|
215
|
+
*
|
|
216
|
+
* On a successful horizon advance the memory context pack is refreshed
|
|
217
|
+
* (same fire-and-forget call the transform's `onCompaction` handler
|
|
218
|
+
* uses) so the rendered prefix lines up with the new horizon and the
|
|
219
|
+
* next prompt-cache fault is paid once instead of twice.
|
|
220
|
+
*
|
|
221
|
+
* Rejected with a soft warning when a turn chain is in flight —
|
|
222
|
+
* mutating the horizon mid-stream would invalidate the request the
|
|
223
|
+
* parent (or a state agent) is already dispatching. `activeTurnPromise`
|
|
224
|
+
* is the single source of truth here, so poll/timer sleeps pass the
|
|
225
|
+
* gate cleanly: the chain has already resolved to the `sleep` terminal
|
|
226
|
+
* before compact is allowed to run.
|
|
227
|
+
*/
|
|
228
|
+
async compact() {
|
|
229
|
+
this.requireStarted();
|
|
230
|
+
// `activeTurnPromise` is the single source of truth for "a turn chain
|
|
231
|
+
// is in flight" — it covers the parent agent dispatching, a state
|
|
232
|
+
// agent dispatching while the parent is paused, and a poll/script
|
|
233
|
+
// command currently executing. Sleep terminals (poll/timer waits)
|
|
234
|
+
// have already resolved the chain and cleared this, so compact is
|
|
235
|
+
// free to run during those waits.
|
|
236
|
+
if (this.activeTurnPromise || this.compactInFlight) {
|
|
237
|
+
this.emit({
|
|
238
|
+
type: "system",
|
|
239
|
+
level: "warn",
|
|
240
|
+
message: this.compactInFlight
|
|
241
|
+
? "compact ignored: a compact pass is already in progress."
|
|
242
|
+
: "compact ignored: a turn chain is in flight; send compact between turns.",
|
|
243
|
+
});
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
// Publish the compact promise so concurrent `turn()` calls observe
|
|
247
|
+
// it and serialize behind us. Fire-and-forget callers (e.g. the TUI
|
|
248
|
+
// `/compact` slash command) would otherwise let a follow-up prompt
|
|
249
|
+
// dispatch with the pre-compact wire-tail and race the horizon
|
|
250
|
+
// mutation. The promise resolves to `void` after the inner body
|
|
251
|
+
// finishes, so `turn()` only needs to await, not inspect a result.
|
|
252
|
+
const inFlight = this.runCompact();
|
|
253
|
+
this.compactInFlight = inFlight;
|
|
254
|
+
try {
|
|
255
|
+
await inFlight;
|
|
256
|
+
}
|
|
257
|
+
finally {
|
|
258
|
+
if (this.compactInFlight === inFlight) {
|
|
259
|
+
this.compactInFlight = undefined;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
async runCompact() {
|
|
264
|
+
try {
|
|
265
|
+
const state = this.requireRunnerState();
|
|
266
|
+
// Drain: observe any unobserved tail before evicting it from the
|
|
267
|
+
// wire. `updateObservationalMemory` internally computes the
|
|
268
|
+
// unobserved tail via `getUnobservedMessageTail`, so this is
|
|
269
|
+
// idempotent when the observer already ran on those turns and
|
|
270
|
+
// does real work only when there's something new to capture.
|
|
271
|
+
// Wrapped because memory-model calls can fail; a failed drain
|
|
272
|
+
// should still let the user's compact request advance the horizon.
|
|
273
|
+
try {
|
|
274
|
+
await this.updateMemoryAfterAgentRun(state.agent.messages, state.options);
|
|
275
|
+
}
|
|
276
|
+
catch (error) {
|
|
277
|
+
this.emit({
|
|
278
|
+
type: "system",
|
|
279
|
+
level: "warn",
|
|
280
|
+
message: `compact: observation drain failed (${truncateForSystemMessage(error instanceof Error ? error.message : String(error))}); evicting anyway.`,
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
// Rebuild the rendered pack so the new observations from the
|
|
284
|
+
// drain (and anything else freshly written) are part of the
|
|
285
|
+
// prefix the next turn ships with the trimmed wire-tail.
|
|
286
|
+
await this.refreshMemoryContextPack();
|
|
287
|
+
const observable = stripObservationalContextMessages(state.agent.messages);
|
|
288
|
+
const previousHorizon = this.wireGuardHorizon.evictionHorizon;
|
|
289
|
+
const currentRetained = applyEvictionHorizon(observable, previousHorizon);
|
|
290
|
+
const beforeTokens = calculateWireTokens(currentRetained);
|
|
291
|
+
const contextWindow = this.effectiveContextWindow();
|
|
292
|
+
const ceiling = Math.max(1, Math.floor(contextWindow * COMPACT_MESSAGE_TOKENS_RATIO));
|
|
293
|
+
const overCeiling = beforeTokens > ceiling;
|
|
294
|
+
const target = overCeiling ? ceiling : Math.max(1, Math.floor(beforeTokens / 2));
|
|
295
|
+
const targetLabel = overCeiling
|
|
296
|
+
? `target ${target} = 20% of ${contextWindow}`
|
|
297
|
+
: `target ${target} = 50% of current ${beforeTokens}`;
|
|
298
|
+
const newHorizon = findEvictionHorizon(observable, previousHorizon, (candidate) => calculateWireTokens(candidate) <= target);
|
|
299
|
+
if (newHorizon === previousHorizon) {
|
|
300
|
+
this.emit({
|
|
301
|
+
type: "system",
|
|
302
|
+
level: "info",
|
|
303
|
+
message: `compact: nothing to evict (wire-tail ~${beforeTokens} tokens; ${targetLabel}).`,
|
|
304
|
+
});
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
this.wireGuardHorizon.evictionHorizon = newHorizon;
|
|
308
|
+
const retainedAfter = applyEvictionHorizon(observable, newHorizon);
|
|
309
|
+
const afterTokens = calculateWireTokens(retainedAfter);
|
|
310
|
+
const dropped = currentRetained.length - retainedAfter.length;
|
|
311
|
+
this.emit({
|
|
312
|
+
type: "system",
|
|
313
|
+
level: "info",
|
|
314
|
+
message: `compact: dropped ${dropped} older wire message(s); wire-tail ~${beforeTokens} → ~${afterTokens} tokens (${targetLabel}).`,
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
catch (error) {
|
|
318
|
+
// The drain and pack-refresh have their own try/catch; this outer
|
|
319
|
+
// catch guards against an unexpected throw in the horizon-advance
|
|
320
|
+
// path so `runCompact` always settles cleanly and `compactInFlight`
|
|
321
|
+
// resets via the caller's finally.
|
|
322
|
+
this.emit({
|
|
323
|
+
type: "system",
|
|
324
|
+
level: "warn",
|
|
325
|
+
message: `compact: failed (${truncateForSystemMessage(error instanceof Error ? error.message : String(error))}).`,
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
}
|
|
182
329
|
/**
|
|
183
330
|
* Set up a session before any turn runs. Loads memory and skills, then
|
|
184
331
|
* emits `turn_started` with the initial state (a fresh state, or the
|
|
@@ -200,6 +347,14 @@ export class TurnRunner {
|
|
|
200
347
|
}
|
|
201
348
|
: createInitialTurnState(mode, this.resolveTurnOptions(startOptions));
|
|
202
349
|
this.stateMachineController.hydrate(state.stateMachine);
|
|
350
|
+
// Hydrate the wire-shaping object in place. `this.wireGuardHorizon` is
|
|
351
|
+
// referenced by the observational context transform; replacing the
|
|
352
|
+
// reference would orphan the transform's view. `Object.assign` over
|
|
353
|
+
// the fresh default lets the persisted state contribute every field
|
|
354
|
+
// it carries without this code knowing the field list.
|
|
355
|
+
if (state.wireGuardHorizon) {
|
|
356
|
+
Object.assign(this.wireGuardHorizon, state.wireGuardHorizon);
|
|
357
|
+
}
|
|
203
358
|
this.setState(state);
|
|
204
359
|
this.initializeParentAgent();
|
|
205
360
|
this.started = true;
|
|
@@ -211,6 +366,15 @@ export class TurnRunner {
|
|
|
211
366
|
this.requireStarted();
|
|
212
367
|
await this.ensureMemoryLoaded();
|
|
213
368
|
await this.ensureSkillsLoaded();
|
|
369
|
+
// Serialize behind an in-flight compact. Compact advances the wire
|
|
370
|
+
// horizon and may write observations to the durable store; a turn
|
|
371
|
+
// started concurrently would dispatch the pre-compact wire-tail and
|
|
372
|
+
// race the horizon mutation. Awaiting here gives fire-and-forget
|
|
373
|
+
// callers (TUI `/compact` then a prompt) the same ordering RPC mode
|
|
374
|
+
// gets for free by awaiting `compact` between iterations.
|
|
375
|
+
if (this.compactInFlight) {
|
|
376
|
+
await this.compactInFlight;
|
|
377
|
+
}
|
|
214
378
|
if (this.activeTurnPromise) {
|
|
215
379
|
// turn() is the concurrency boundary: repeated calls extend or queue
|
|
216
380
|
// behind the active chain instead of creating a separate parent transcript.
|
|
@@ -813,6 +977,16 @@ export class TurnRunner {
|
|
|
813
977
|
todos: copyOptionalArray(state.todos ?? this.state?.todos),
|
|
814
978
|
followUpQueue: copyOptionalArray(state.followUpQueue ?? this.state?.followUpQueue),
|
|
815
979
|
queuedCommands: copyOptionalArray(state.queuedCommands ?? this.state?.queuedCommands),
|
|
980
|
+
// Carry wire-shaping state through every snapshot so persistence
|
|
981
|
+
// layers (state.json, terminal payloads, getState consumers) see
|
|
982
|
+
// the current value. Copy by spread so consumers can't mutate the
|
|
983
|
+
// runner's live object. Omit when nothing has moved off the
|
|
984
|
+
// fresh-runner default so untouched sessions stay schema-clean;
|
|
985
|
+
// `evictionHorizon` is the only field today, so it doubles as the
|
|
986
|
+
// dirty sentinel — revisit when more wire-shaping fields land.
|
|
987
|
+
...(this.wireGuardHorizon.evictionHorizon > 0
|
|
988
|
+
? { wireGuardHorizon: { ...this.wireGuardHorizon } }
|
|
989
|
+
: {}),
|
|
816
990
|
};
|
|
817
991
|
return this.applyAutoStateCompaction(snapshot);
|
|
818
992
|
}
|
|
@@ -1560,7 +1734,7 @@ export class TurnRunner {
|
|
|
1560
1734
|
/**
|
|
1561
1735
|
* Estimate the per-segment occupancy of the parent agent's input before
|
|
1562
1736
|
* reconciliation with provider `totalTokens`. System prompt and memory
|
|
1563
|
-
* packs use the same `ceil(chars/
|
|
1737
|
+
* packs use the same `ceil(chars / CHARS_PER_TOKEN)` heuristic as the memory pipeline so
|
|
1564
1738
|
* compaction triggers stay on the same scale as `MEMORY_BUDGET_RATIOS`.
|
|
1565
1739
|
*
|
|
1566
1740
|
* The message tail uses {@link calculateWireTokens} over the
|
|
@@ -1568,7 +1742,7 @@ export class TurnRunner {
|
|
|
1568
1742
|
* messages already dropped by wire-shaping stop counting against the
|
|
1569
1743
|
* `messages` segment instead of inflating it from the runner's full
|
|
1570
1744
|
* retained transcript. Text and structured blocks (`toolCall`, thinking,
|
|
1571
|
-
* etc.) use `ceil(chars/
|
|
1745
|
+
* etc.) use `ceil(chars / CHARS_PER_TOKEN)`, and image blocks contribute a fixed
|
|
1572
1746
|
* per-image estimate rather than their base64 byte length.
|
|
1573
1747
|
*
|
|
1574
1748
|
* `emitParentAgentEvent` rescales all four segments with
|