@wrongstack/core 0.1.9 → 0.2.0
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/agent-bridge-DmBiCipY.d.ts +33 -0
- package/dist/compactor-DSl2FK7a.d.ts +17 -0
- package/dist/config-DXrqb41m.d.ts +193 -0
- package/dist/{provider-txgB0Oq9.d.ts → context-u0bryklF.d.ts} +540 -472
- package/dist/coordination/index.d.ts +892 -0
- package/dist/coordination/index.js +2869 -0
- package/dist/coordination/index.js.map +1 -0
- package/dist/defaults/index.d.ts +34 -2309
- package/dist/defaults/index.js +5610 -4608
- package/dist/defaults/index.js.map +1 -1
- package/dist/events-B6Q03pTu.d.ts +290 -0
- package/dist/execution/index.d.ts +260 -0
- package/dist/execution/index.js +1625 -0
- package/dist/execution/index.js.map +1 -0
- package/dist/index.d.ts +81 -11
- package/dist/index.js +7727 -6174
- package/dist/index.js.map +1 -1
- package/dist/infrastructure/index.d.ts +10 -0
- package/dist/infrastructure/index.js +575 -0
- package/dist/infrastructure/index.js.map +1 -0
- package/dist/input-reader-E-ffP2ee.d.ts +12 -0
- package/dist/kernel/index.d.ts +15 -4
- package/dist/kernel/index.js.map +1 -1
- package/dist/logger-BH6AE0W9.d.ts +24 -0
- package/dist/logger-BMQgxvdy.d.ts +12 -0
- package/dist/mcp-servers-BA1Ofmfj.d.ts +100 -0
- package/dist/memory-CEXuo7sz.d.ts +16 -0
- package/dist/mode-CV077NjV.d.ts +27 -0
- package/dist/models/index.d.ts +60 -0
- package/dist/models/index.js +621 -0
- package/dist/models/index.js.map +1 -0
- package/dist/models-registry-DqzwpBQy.d.ts +46 -0
- package/dist/models-registry-Y2xbog0E.d.ts +95 -0
- package/dist/multi-agent-BDfkxL5C.d.ts +351 -0
- package/dist/observability/index.d.ts +353 -0
- package/dist/observability/index.js +691 -0
- package/dist/observability/index.js.map +1 -0
- package/dist/observability-BhnVLBLS.d.ts +67 -0
- package/dist/path-resolver-CPRj4bFY.d.ts +10 -0
- package/dist/path-resolver-Crkt8wTQ.d.ts +54 -0
- package/dist/plugin-CoYYZKdn.d.ts +447 -0
- package/dist/renderer-0A2ZEtca.d.ts +158 -0
- package/dist/sdd/index.d.ts +206 -0
- package/dist/sdd/index.js +864 -0
- package/dist/sdd/index.js.map +1 -0
- package/dist/secret-scrubber-3TLUkiCV.d.ts +31 -0
- package/dist/secret-scrubber-CwYliRWd.d.ts +54 -0
- package/dist/secret-vault-DoISxaKO.d.ts +19 -0
- package/dist/security/index.d.ts +46 -0
- package/dist/security/index.js +536 -0
- package/dist/security/index.js.map +1 -0
- package/dist/selector-BRqzvugb.d.ts +51 -0
- package/dist/session-reader-C3x96CDR.d.ts +150 -0
- package/dist/skill-Bx8jxznf.d.ts +72 -0
- package/dist/storage/index.d.ts +540 -0
- package/dist/storage/index.js +1802 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/{system-prompt-vAB0F54-.d.ts → system-prompt-CG9jU5-5.d.ts} +9 -1
- package/dist/task-graph-BITvWt4t.d.ts +160 -0
- package/dist/tool-executor-CYdZdtno.d.ts +97 -0
- package/dist/types/index.d.ts +26 -4
- package/dist/types/index.js +1787 -4
- package/dist/types/index.js.map +1 -1
- package/dist/utils/index.d.ts +49 -2
- package/dist/utils/index.js +100 -2
- package/dist/utils/index.js.map +1 -1
- package/package.json +34 -2
- package/dist/mode-Pjt5vMS6.d.ts +0 -815
- package/dist/session-reader-9sOTgmeC.d.ts +0 -1087
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import { U as Usage, a0 as Context, y as ToolProgressEvent, u as Tool } from './context-u0bryklF.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* EventBus — observe-only typed event bus.
|
|
5
|
+
* Subscribers cannot modify or cancel. Subscriber exceptions are caught.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
interface EventMap {
|
|
9
|
+
'session.started': {
|
|
10
|
+
id: string;
|
|
11
|
+
};
|
|
12
|
+
'session.ended': {
|
|
13
|
+
id: string;
|
|
14
|
+
usage: Usage;
|
|
15
|
+
};
|
|
16
|
+
'session.damaged': {
|
|
17
|
+
sessionId: string;
|
|
18
|
+
detail: string;
|
|
19
|
+
};
|
|
20
|
+
'iteration.started': {
|
|
21
|
+
ctx: Context;
|
|
22
|
+
index: number;
|
|
23
|
+
};
|
|
24
|
+
'iteration.completed': {
|
|
25
|
+
ctx: Context;
|
|
26
|
+
index: number;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Fired when the agent hits its iteration limit. Listeners (CLI/TUI) can
|
|
30
|
+
* call `grant(extra)` to allow more iterations, or `deny()` to stop.
|
|
31
|
+
* If no listener responds within 30s the run ends with 'max_iterations'.
|
|
32
|
+
*/
|
|
33
|
+
'iteration.limit_reached': {
|
|
34
|
+
currentIterations: number;
|
|
35
|
+
currentLimit: number;
|
|
36
|
+
grant: (extraIterations: number) => void;
|
|
37
|
+
deny: () => void;
|
|
38
|
+
};
|
|
39
|
+
'provider.response': {
|
|
40
|
+
ctx: Context;
|
|
41
|
+
usage: Usage;
|
|
42
|
+
stopReason: string;
|
|
43
|
+
};
|
|
44
|
+
'provider.text_delta': {
|
|
45
|
+
ctx: Context;
|
|
46
|
+
text: string;
|
|
47
|
+
};
|
|
48
|
+
'provider.thinking_delta': {
|
|
49
|
+
ctx: Context;
|
|
50
|
+
text: string;
|
|
51
|
+
};
|
|
52
|
+
'provider.tool_use_start': {
|
|
53
|
+
ctx: Context;
|
|
54
|
+
id: string;
|
|
55
|
+
name: string;
|
|
56
|
+
};
|
|
57
|
+
'provider.tool_use_stop': {
|
|
58
|
+
ctx: Context;
|
|
59
|
+
id: string;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Fired before each retry of a failed provider call. `attempt` is 1-based
|
|
63
|
+
* (the first retry is attempt 1, etc.). `description` is the human-readable
|
|
64
|
+
* one-liner from `ProviderError.describe()` — render this in the CLI/TUI
|
|
65
|
+
* instead of grepping logger output for the raw JSON body.
|
|
66
|
+
*/
|
|
67
|
+
'provider.retry': {
|
|
68
|
+
providerId: string;
|
|
69
|
+
attempt: number;
|
|
70
|
+
delayMs: number;
|
|
71
|
+
status: number;
|
|
72
|
+
description: string;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Fired once when a provider call ultimately fails (retries exhausted, or
|
|
76
|
+
* non-retryable error). Same shape as `provider.retry` minus the delay.
|
|
77
|
+
*/
|
|
78
|
+
'provider.error': {
|
|
79
|
+
providerId: string;
|
|
80
|
+
status: number;
|
|
81
|
+
description: string;
|
|
82
|
+
retryable: boolean;
|
|
83
|
+
};
|
|
84
|
+
'tool.started': {
|
|
85
|
+
name: string;
|
|
86
|
+
id: string;
|
|
87
|
+
input?: unknown;
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Fired for each ToolProgressEvent yielded by `Tool.executeStream`. UIs
|
|
91
|
+
* subscribe to render incremental progress (streaming bash output, file
|
|
92
|
+
* tree counts, etc.) without the tool having to know about the UI.
|
|
93
|
+
*/
|
|
94
|
+
'tool.progress': {
|
|
95
|
+
name: string;
|
|
96
|
+
id: string;
|
|
97
|
+
event: ToolProgressEvent;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Fired when a tool call needs user confirmation and no confirmHandler
|
|
101
|
+
* is registered on the executor. The TUI renders a confirmation dialog
|
|
102
|
+
* from this event. Resolution is driven by calling the resolve function
|
|
103
|
+
* passed in the payload with a decision string ('yes' | 'no' | 'always' | 'deny').
|
|
104
|
+
*/
|
|
105
|
+
'tool.confirm_needed': {
|
|
106
|
+
tool: Tool;
|
|
107
|
+
input: unknown;
|
|
108
|
+
toolUseId: string;
|
|
109
|
+
suggestedPattern: string;
|
|
110
|
+
resolve: (decision: 'yes' | 'no' | 'always' | 'deny') => void;
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* `output` is a truncated preview of the tool's serialized result text
|
|
114
|
+
* (capped at ~400 chars by the emitter). UIs render this inline in the
|
|
115
|
+
* tool history line without re-fetching from the session log.
|
|
116
|
+
*/
|
|
117
|
+
'tool.executed': {
|
|
118
|
+
/**
|
|
119
|
+
* The tool_use id (e.g. "toolu_…") issued by the provider for this call.
|
|
120
|
+
* Pairs with `tool.started.id` so subscribers can correlate start/finish
|
|
121
|
+
* even when the model fires multiple tools in parallel with identical
|
|
122
|
+
* inputs. Optional only for legacy emit sites — new code should always
|
|
123
|
+
* set it.
|
|
124
|
+
*/
|
|
125
|
+
id?: string;
|
|
126
|
+
name: string;
|
|
127
|
+
durationMs: number;
|
|
128
|
+
ok: boolean;
|
|
129
|
+
input?: unknown;
|
|
130
|
+
output?: string;
|
|
131
|
+
/**
|
|
132
|
+
* Full UTF-8 byte length of the serialized tool result that the model
|
|
133
|
+
* actually sees (post-cap, post-scrub). The `output` preview is capped
|
|
134
|
+
* at ~400 chars for transport; this number lets UIs surface what the
|
|
135
|
+
* model is really paying tokens for. Optional only for legacy emit
|
|
136
|
+
* sites that may not yet populate it.
|
|
137
|
+
*/
|
|
138
|
+
outputBytes?: number;
|
|
139
|
+
/**
|
|
140
|
+
* Estimated token count for the full result body the model sees.
|
|
141
|
+
* Computed from `outputBytes` with the standard ~3.5 chars/token
|
|
142
|
+
* heuristic. Cheap to show in the TUI; not authoritative — the real
|
|
143
|
+
* provider count lives in `provider.response.usage`. */
|
|
144
|
+
outputTokens?: number;
|
|
145
|
+
/**
|
|
146
|
+
* For tools whose output has a clear "line" notion (file reads with
|
|
147
|
+
* numbered prefixes, grep hits, bash stdout), the agent counts the
|
|
148
|
+
* actual lines the model received and forwards it here. Undefined
|
|
149
|
+
* for tools without a meaningful line count. */
|
|
150
|
+
outputLines?: number;
|
|
151
|
+
};
|
|
152
|
+
'token.threshold': {
|
|
153
|
+
used: number;
|
|
154
|
+
limit: number;
|
|
155
|
+
};
|
|
156
|
+
'compaction.fired': {
|
|
157
|
+
before: number;
|
|
158
|
+
after: number;
|
|
159
|
+
};
|
|
160
|
+
/**
|
|
161
|
+
* Fired when the auto-compaction middleware's compactor.compact() call
|
|
162
|
+
* throws. Compaction is best-effort by design so we don't crash the agent
|
|
163
|
+
* loop, but a persistent failure (misconfigured summarizer model, network
|
|
164
|
+
* outage) means the next iteration may hit context overflow. Observability
|
|
165
|
+
* layers / dashboards subscribe to this to surface the silent regression.
|
|
166
|
+
*/
|
|
167
|
+
'compaction.failed': {
|
|
168
|
+
err: Error;
|
|
169
|
+
aggressive: boolean;
|
|
170
|
+
level: 'warn' | 'soft' | 'hard';
|
|
171
|
+
tokens: number;
|
|
172
|
+
maxContext: number;
|
|
173
|
+
load: number;
|
|
174
|
+
fatal: boolean;
|
|
175
|
+
};
|
|
176
|
+
/**
|
|
177
|
+
* Subagent lifecycle events. Emitted by `MultiAgentHost` so the TUI can
|
|
178
|
+
* surface what's happening in the fleet without needing director-mode
|
|
179
|
+
* (which renders the live FleetPanel). These complement the FleetBus
|
|
180
|
+
* (director-only) by giving the TUI a uniform feed for both `/spawn`
|
|
181
|
+
* and director-orchestrated work.
|
|
182
|
+
*/
|
|
183
|
+
'subagent.spawned': {
|
|
184
|
+
subagentId: string;
|
|
185
|
+
taskId: string;
|
|
186
|
+
name?: string;
|
|
187
|
+
provider?: string;
|
|
188
|
+
model?: string;
|
|
189
|
+
description?: string;
|
|
190
|
+
/**
|
|
191
|
+
* Absolute path to the per-subagent JSONL transcript on disk, when
|
|
192
|
+
* one was created. Undefined when the subagent shares the parent
|
|
193
|
+
* session writer (in-memory or single-file configurations).
|
|
194
|
+
* Surfaced so the TUI (FleetPanel) and `/fleet log` can show the
|
|
195
|
+
* user *where* to look without computing it from the run id.
|
|
196
|
+
*/
|
|
197
|
+
transcriptPath?: string;
|
|
198
|
+
};
|
|
199
|
+
'subagent.task_started': {
|
|
200
|
+
subagentId: string;
|
|
201
|
+
taskId: string;
|
|
202
|
+
description?: string;
|
|
203
|
+
};
|
|
204
|
+
/**
|
|
205
|
+
* Per-tool-call event re-emitted from a subagent's own EventBus
|
|
206
|
+
* onto the host EventBus, so the TUI / non-director surfaces can
|
|
207
|
+
* render "AGENT#1 ● bash 250ms" without having to subscribe to
|
|
208
|
+
* the director-only FleetBus. Fired AFTER the tool completes
|
|
209
|
+
* (paired with `tool.executed`). Includes the subagent id so
|
|
210
|
+
* multiple parallel subagents are distinguishable.
|
|
211
|
+
*/
|
|
212
|
+
'subagent.tool_executed': {
|
|
213
|
+
subagentId: string;
|
|
214
|
+
taskId?: string;
|
|
215
|
+
name: string;
|
|
216
|
+
durationMs: number;
|
|
217
|
+
ok: boolean;
|
|
218
|
+
input?: unknown;
|
|
219
|
+
outputBytes?: number;
|
|
220
|
+
};
|
|
221
|
+
'subagent.task_completed': {
|
|
222
|
+
subagentId: string;
|
|
223
|
+
taskId: string;
|
|
224
|
+
status: 'success' | 'failed' | 'timeout' | 'stopped';
|
|
225
|
+
iterations: number;
|
|
226
|
+
toolCalls: number;
|
|
227
|
+
durationMs: number;
|
|
228
|
+
/**
|
|
229
|
+
* Structured failure envelope when `status !== 'success'`. Carries
|
|
230
|
+
* `kind` (one of `SubagentErrorKind`), `message`, `retryable`, and
|
|
231
|
+
* optional `backoffMs`. UIs branch on `kind` to render the right
|
|
232
|
+
* chip (rate_limit vs auth vs tool_failed). The type is imported
|
|
233
|
+
* lazily as a structural object to avoid a coordination → kernel
|
|
234
|
+
* cycle in the dependency graph.
|
|
235
|
+
*/
|
|
236
|
+
error?: {
|
|
237
|
+
kind: string;
|
|
238
|
+
message: string;
|
|
239
|
+
retryable: boolean;
|
|
240
|
+
backoffMs?: number;
|
|
241
|
+
cause?: {
|
|
242
|
+
name: string;
|
|
243
|
+
message: string;
|
|
244
|
+
stack?: string;
|
|
245
|
+
};
|
|
246
|
+
};
|
|
247
|
+
};
|
|
248
|
+
'mcp.server.connected': {
|
|
249
|
+
name: string;
|
|
250
|
+
toolCount: number;
|
|
251
|
+
};
|
|
252
|
+
'mcp.server.reconnected': {
|
|
253
|
+
name: string;
|
|
254
|
+
toolCount: number;
|
|
255
|
+
};
|
|
256
|
+
'mcp.server.disconnected': {
|
|
257
|
+
name: string;
|
|
258
|
+
reason: string;
|
|
259
|
+
};
|
|
260
|
+
'token.cost_estimate_unavailable': {
|
|
261
|
+
model: string;
|
|
262
|
+
};
|
|
263
|
+
error: {
|
|
264
|
+
err: Error;
|
|
265
|
+
phase: string;
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
type EventName = keyof EventMap;
|
|
269
|
+
type Listener<E extends EventName> = (payload: EventMap[E]) => void;
|
|
270
|
+
interface EventLogger {
|
|
271
|
+
error(msg: string, ctx?: unknown): void;
|
|
272
|
+
}
|
|
273
|
+
declare class EventBus {
|
|
274
|
+
private readonly listeners;
|
|
275
|
+
private logger?;
|
|
276
|
+
setLogger(logger: EventLogger): void;
|
|
277
|
+
on<E extends EventName>(event: E, fn: Listener<E>): () => void;
|
|
278
|
+
off<E extends EventName>(event: E, fn: Listener<E>): void;
|
|
279
|
+
once<E extends EventName>(event: E, fn: Listener<E>): () => void;
|
|
280
|
+
emit<E extends EventName>(event: E, payload: EventMap[E]): void;
|
|
281
|
+
clear(): void;
|
|
282
|
+
/**
|
|
283
|
+
* V2-D: introspection helper. Pass an `event` to count handlers for a
|
|
284
|
+
* single key, or omit to get the total across every event. Used by the
|
|
285
|
+
* leak-detection smoke test to flag handler accumulation across runs.
|
|
286
|
+
*/
|
|
287
|
+
listenerCount(event?: EventName): number;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export { EventBus as E, type Listener as L, type EventName as a, type EventLogger as b, type EventMap as c };
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
export { C as CompactorOptions, D as DefaultErrorHandler, a as DefaultRetryPolicy, H as HybridCompactor, T as ToolExecutor } from '../tool-executor-CYdZdtno.js';
|
|
2
|
+
import { g as Provider, a0 as Context } from '../context-u0bryklF.js';
|
|
3
|
+
import { C as Compactor, a as CompactReport } from '../compactor-DSl2FK7a.js';
|
|
4
|
+
import { M as MessageSelector } from '../selector-BRqzvugb.js';
|
|
5
|
+
import { E as EventBus } from '../events-B6Q03pTu.js';
|
|
6
|
+
import { a as MiddlewareHandler } from '../renderer-0A2ZEtca.js';
|
|
7
|
+
import { A as Agent, R as RunResult } from '../plugin-CoYYZKdn.js';
|
|
8
|
+
import { D as DoneCondition } from '../multi-agent-BDfkxL5C.js';
|
|
9
|
+
import { a as SkillLoader, b as SkillManifest, S as SkillEntry } from '../skill-Bx8jxznf.js';
|
|
10
|
+
import { a as WstackPaths } from '../wstack-paths-BGu2INTm.js';
|
|
11
|
+
import '../models-registry-Y2xbog0E.js';
|
|
12
|
+
import '../observability-BhnVLBLS.js';
|
|
13
|
+
import '../secret-scrubber-3TLUkiCV.js';
|
|
14
|
+
import '../config-DXrqb41m.js';
|
|
15
|
+
import '../logger-BMQgxvdy.js';
|
|
16
|
+
|
|
17
|
+
interface SkillLoaderOptions {
|
|
18
|
+
paths: WstackPaths;
|
|
19
|
+
bundledDir?: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Discovery order (later layers shadow earlier ones at boot, but we walk
|
|
23
|
+
* highest priority first and skip names already seen):
|
|
24
|
+
* 1. Project-committed: <project>/.wrongstack/skills/
|
|
25
|
+
* 2. User-global: ~/.wrongstack/skills/
|
|
26
|
+
* 3. Bundled with build: packages/core/skills/
|
|
27
|
+
*/
|
|
28
|
+
declare class DefaultSkillLoader implements SkillLoader {
|
|
29
|
+
private readonly dirs;
|
|
30
|
+
private cache?;
|
|
31
|
+
constructor(opts: SkillLoaderOptions);
|
|
32
|
+
list(): Promise<SkillManifest[]>;
|
|
33
|
+
find(name: string): Promise<SkillManifest | undefined>;
|
|
34
|
+
manifestText(): Promise<string>;
|
|
35
|
+
listEntries(): Promise<SkillEntry[]>;
|
|
36
|
+
readBody(name: string): Promise<string>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Options for IntelligentCompactor.
|
|
41
|
+
*/
|
|
42
|
+
interface IntelligentCompactorOptions {
|
|
43
|
+
/** Provider to use for LLM-assisted summarization. Required. */
|
|
44
|
+
provider: Provider;
|
|
45
|
+
/** Fraction of maxContext that triggers a warning (default 0.6). */
|
|
46
|
+
warnThreshold?: number;
|
|
47
|
+
/** Fraction of maxContext that triggers soft compaction (default 0.75). */
|
|
48
|
+
softThreshold?: number;
|
|
49
|
+
/** Fraction of maxContext that triggers hard compaction (default 0.9). */
|
|
50
|
+
hardThreshold?: number;
|
|
51
|
+
/** Max context window in tokens (used only for threshold fraction math). */
|
|
52
|
+
maxContext?: number;
|
|
53
|
+
/** How many recent (user+assistant) pairs to always preserve (default 4). */
|
|
54
|
+
preserveK?: number;
|
|
55
|
+
/** Token threshold below which tool results are not elided (default 500). */
|
|
56
|
+
eliseThreshold?: number;
|
|
57
|
+
/** System prompt for the summarizer sub-LLM. */
|
|
58
|
+
summarizerPrompt?: string;
|
|
59
|
+
/**
|
|
60
|
+
* Model ID to use for summarization. When not set, the same model as the
|
|
61
|
+
* agent is used (which risks cascading failure on context overflow). Set to
|
|
62
|
+
* a fast/cheap model like `claude-3-5-haiku-20240620` for resilience.
|
|
63
|
+
*/
|
|
64
|
+
summarizerModel?: string;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* IntelligentCompactor uses an LLM to:
|
|
68
|
+
* - Analyze message importance and preserve critical context
|
|
69
|
+
* - Generate semantic summaries for old message ranges
|
|
70
|
+
* - Make intelligent decisions about what to compact
|
|
71
|
+
*
|
|
72
|
+
* It extends HybridCompactor's elision logic with LLM-assisted summarization.
|
|
73
|
+
*/
|
|
74
|
+
declare class IntelligentCompactor implements Compactor {
|
|
75
|
+
private readonly provider;
|
|
76
|
+
private readonly warnThreshold;
|
|
77
|
+
private readonly softThreshold;
|
|
78
|
+
private readonly hardThreshold;
|
|
79
|
+
private readonly maxContext;
|
|
80
|
+
private readonly preserveK;
|
|
81
|
+
private readonly eliseThreshold;
|
|
82
|
+
private readonly summarizerPrompt;
|
|
83
|
+
private readonly summarizerModel?;
|
|
84
|
+
constructor(opts: IntelligentCompactorOptions);
|
|
85
|
+
compact(ctx: Context, opts?: {
|
|
86
|
+
aggressive?: boolean;
|
|
87
|
+
}): Promise<CompactReport>;
|
|
88
|
+
private summarizeAncientTurns;
|
|
89
|
+
private findSafeBoundary;
|
|
90
|
+
private findExchangeStart;
|
|
91
|
+
private callSummarizer;
|
|
92
|
+
private messagesToText;
|
|
93
|
+
private lightweightCompact;
|
|
94
|
+
private eliseOldToolResults;
|
|
95
|
+
private hasTextContent;
|
|
96
|
+
private estimateTokens;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Options for SelectiveCompactor — the most configurable compactor.
|
|
101
|
+
*/
|
|
102
|
+
interface SelectiveCompactorOptions {
|
|
103
|
+
/** Provider for LLM calls (selector + summarizer). Required. */
|
|
104
|
+
provider: Provider;
|
|
105
|
+
/** Selector for LLM-driven importance analysis. */
|
|
106
|
+
selector?: MessageSelector;
|
|
107
|
+
/** Fraction of maxContext that triggers a warning (default 0.6). */
|
|
108
|
+
warnThreshold?: number;
|
|
109
|
+
/** Fraction of maxContext that triggers soft compaction (default 0.75). */
|
|
110
|
+
softThreshold?: number;
|
|
111
|
+
/** Fraction of maxContext that triggers hard compaction (default 0.9). */
|
|
112
|
+
hardThreshold?: number;
|
|
113
|
+
/** Max context window in tokens (used for threshold fraction math). */
|
|
114
|
+
maxContext?: number;
|
|
115
|
+
/** How many recent (user+assistant) pairs to always preserve (default 4). */
|
|
116
|
+
preserveK?: number;
|
|
117
|
+
/** Token threshold below which tool results are not elided (default 500). */
|
|
118
|
+
eliseThreshold?: number;
|
|
119
|
+
/** Model for selector LLM calls (default: same as provider default). */
|
|
120
|
+
selectorModel?: string;
|
|
121
|
+
/** Summarizer model for collapsed ranges (default: same as selectorModel). */
|
|
122
|
+
summarizerModel?: string;
|
|
123
|
+
/** Prompt for the summarizer sub-LLM. */
|
|
124
|
+
summarizerPrompt?: string;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* SelectiveCompactor uses an LLM-driven MessageSelector to make
|
|
128
|
+
* surgical decisions about which message ranges to keep vs collapse.
|
|
129
|
+
*
|
|
130
|
+
* Compared to HybridCompactor / IntelligentCompactor:
|
|
131
|
+
* - HybridCompactor: rule-based (preserveK + elision), no LLM calls
|
|
132
|
+
* - IntelligentCompactor: LLM summarization but no structured selection
|
|
133
|
+
* - SelectiveCompactor: full LLM-driven selection + optional summarization
|
|
134
|
+
*/
|
|
135
|
+
declare class SelectiveCompactor implements Compactor {
|
|
136
|
+
private readonly provider;
|
|
137
|
+
private readonly selector;
|
|
138
|
+
private readonly warnThreshold;
|
|
139
|
+
private readonly softThreshold;
|
|
140
|
+
private readonly hardThreshold;
|
|
141
|
+
private readonly maxContext;
|
|
142
|
+
private readonly preserveK;
|
|
143
|
+
private readonly eliseThreshold;
|
|
144
|
+
private readonly summarizerModel;
|
|
145
|
+
private readonly summarizerPrompt;
|
|
146
|
+
constructor(opts: SelectiveCompactorOptions);
|
|
147
|
+
compact(ctx: Context, opts?: {
|
|
148
|
+
aggressive?: boolean;
|
|
149
|
+
}): Promise<CompactReport>;
|
|
150
|
+
/**
|
|
151
|
+
* Run the LLM selector to decide what to keep vs collapse.
|
|
152
|
+
* Returns the token savings achieved.
|
|
153
|
+
*/
|
|
154
|
+
private runSelector;
|
|
155
|
+
/**
|
|
156
|
+
* Execute a SelectorResult plan: collapse/remove ranges and
|
|
157
|
+
* insert summaries where the selector provided them.
|
|
158
|
+
*/
|
|
159
|
+
private executePlan;
|
|
160
|
+
private summarizeRange;
|
|
161
|
+
private messagePreview;
|
|
162
|
+
/**
|
|
163
|
+
* Fallback when selector fails: aggressively trim from the oldest end
|
|
164
|
+
* until we hit targetBudget.
|
|
165
|
+
*/
|
|
166
|
+
private aggressiveRecencyTrim;
|
|
167
|
+
private computeTargetBudget;
|
|
168
|
+
private eliseOldToolResults;
|
|
169
|
+
private hasTextContent;
|
|
170
|
+
private estimateTokens;
|
|
171
|
+
private roughTokenEstimate;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
type CompactionFailureMode = 'throw' | 'throw_on_hard' | 'continue';
|
|
175
|
+
interface AutoCompactionOptions {
|
|
176
|
+
aggressiveOn?: 'hard' | 'soft' | 'warn';
|
|
177
|
+
events?: EventBus;
|
|
178
|
+
failureMode?: CompactionFailureMode;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Pipeline middleware that monitors context token load and automatically
|
|
182
|
+
* triggers compaction when the warn/soft/hard thresholds are crossed.
|
|
183
|
+
* Runs before the next agent iteration.
|
|
184
|
+
*/
|
|
185
|
+
declare class AutoCompactionMiddleware {
|
|
186
|
+
readonly name = "AutoCompaction";
|
|
187
|
+
private readonly compactor;
|
|
188
|
+
private readonly warnThreshold;
|
|
189
|
+
private readonly softThreshold;
|
|
190
|
+
private readonly hardThreshold;
|
|
191
|
+
private readonly maxContext;
|
|
192
|
+
private readonly estimator;
|
|
193
|
+
private readonly aggressiveOn;
|
|
194
|
+
private readonly events?;
|
|
195
|
+
private readonly failureMode;
|
|
196
|
+
/**
|
|
197
|
+
* @param compactor Compactor to use for compaction.
|
|
198
|
+
* @param maxContext Provider's max context window in tokens.
|
|
199
|
+
* @param estimator Token estimation function.
|
|
200
|
+
* @param thresholds Threshold fractions (0-1) of maxContext.
|
|
201
|
+
* @param opts Optional behavior. By default, failures at the
|
|
202
|
+
* hard threshold throw AGENT_CONTEXT_OVERFLOW so
|
|
203
|
+
* the agent does not continue into a likely
|
|
204
|
+
* provider context overflow. Warn/soft failures
|
|
205
|
+
* still emit compaction.failed and continue.
|
|
206
|
+
*/
|
|
207
|
+
constructor(compactor: Compactor, maxContext: number, estimator: (ctx: Context) => number, thresholds: {
|
|
208
|
+
warn: number;
|
|
209
|
+
soft: number;
|
|
210
|
+
hard: number;
|
|
211
|
+
}, optsOrAggressiveOn?: AutoCompactionOptions | 'hard' | 'soft' | 'warn', events?: EventBus);
|
|
212
|
+
handler(): MiddlewareHandler<Context>;
|
|
213
|
+
private compact;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
type AutonomousResult = RunResult & {
|
|
217
|
+
toolCalls: number;
|
|
218
|
+
reason?: string;
|
|
219
|
+
};
|
|
220
|
+
interface DoneCheckResult {
|
|
221
|
+
done: boolean;
|
|
222
|
+
reason?: string;
|
|
223
|
+
iterations: number;
|
|
224
|
+
toolCalls: number;
|
|
225
|
+
}
|
|
226
|
+
declare class DoneConditionChecker {
|
|
227
|
+
private readonly condition;
|
|
228
|
+
private readonly compiledRegex;
|
|
229
|
+
constructor(condition: DoneCondition);
|
|
230
|
+
check(state: {
|
|
231
|
+
iterations: number;
|
|
232
|
+
toolCalls: number;
|
|
233
|
+
lastOutput?: string;
|
|
234
|
+
}): DoneCheckResult;
|
|
235
|
+
}
|
|
236
|
+
interface AutonomousRunnerOptions {
|
|
237
|
+
agent: Agent;
|
|
238
|
+
context: Context;
|
|
239
|
+
doneCondition: DoneCondition;
|
|
240
|
+
iterationTimeoutMs?: number;
|
|
241
|
+
onIteration?: (state: {
|
|
242
|
+
iteration: number;
|
|
243
|
+
toolCalls: number;
|
|
244
|
+
}) => void;
|
|
245
|
+
onDone?: (result: AutonomousResult) => void;
|
|
246
|
+
}
|
|
247
|
+
declare class AutonomousRunner {
|
|
248
|
+
private readonly opts;
|
|
249
|
+
private iterations;
|
|
250
|
+
private toolCalls;
|
|
251
|
+
private lastOutput?;
|
|
252
|
+
private stopped;
|
|
253
|
+
private readonly doneChecker;
|
|
254
|
+
constructor(opts: AutonomousRunnerOptions);
|
|
255
|
+
run(): Promise<AutonomousResult>;
|
|
256
|
+
private runLoop;
|
|
257
|
+
stop(): void;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
export { AutoCompactionMiddleware, AutonomousRunner, type AutonomousRunnerOptions, DefaultSkillLoader, type DoneCheckResult, DoneConditionChecker, IntelligentCompactor, type IntelligentCompactorOptions, SelectiveCompactor, type SelectiveCompactorOptions, type SkillLoaderOptions };
|