@nexrall/code-core 1.4.66 → 1.4.68
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/agentRegistry.d.ts +27 -0
- package/dist/agent/agentRegistry.d.ts.map +1 -1
- package/dist/agent/agentRegistry.js +45 -0
- package/dist/agent/agentTypes.d.ts +6 -2
- package/dist/agent/agentTypes.d.ts.map +1 -1
- package/dist/agent/agentTypes.js +13 -4
- package/dist/agent/askOnce.d.ts +12 -0
- package/dist/agent/askOnce.d.ts.map +1 -0
- package/dist/agent/askOnce.js +41 -0
- package/dist/agent/compaction.d.ts +244 -0
- package/dist/agent/compaction.d.ts.map +1 -0
- package/dist/agent/compaction.js +976 -0
- package/dist/agent/fileLocks.d.ts +34 -0
- package/dist/agent/fileLocks.d.ts.map +1 -0
- package/dist/agent/fileLocks.js +114 -0
- package/dist/agent/hooks.d.ts +331 -0
- package/dist/agent/hooks.d.ts.map +1 -0
- package/dist/agent/hooks.js +1239 -0
- package/dist/agent/iterationPolicy.d.ts +121 -0
- package/dist/agent/iterationPolicy.d.ts.map +1 -0
- package/dist/agent/iterationPolicy.js +297 -0
- package/dist/agent/lifecycleHost.d.ts +55 -0
- package/dist/agent/lifecycleHost.d.ts.map +1 -0
- package/dist/agent/lifecycleHost.js +294 -0
- package/dist/agent/loop.d.ts +39 -491
- package/dist/agent/loop.d.ts.map +1 -1
- package/dist/agent/loop.js +538 -3069
- package/dist/agent/planMode.d.ts.map +1 -1
- package/dist/agent/planMode.js +1 -0
- package/dist/agent/sharedTasks.d.ts +7 -0
- package/dist/agent/sharedTasks.d.ts.map +1 -1
- package/dist/agent/sharedTasks.js +16 -0
- package/dist/agent/subAgentBudget.d.ts +65 -0
- package/dist/agent/subAgentBudget.d.ts.map +1 -0
- package/dist/agent/subAgentBudget.js +269 -0
- package/dist/agent/subTask.d.ts +15 -0
- package/dist/agent/subTask.d.ts.map +1 -0
- package/dist/agent/subTask.js +730 -0
- package/dist/agent/subTaskSupport.d.ts +167 -0
- package/dist/agent/subTaskSupport.d.ts.map +1 -0
- package/dist/agent/subTaskSupport.js +425 -0
- package/dist/agent/toolDescriptions.d.ts +3 -0
- package/dist/agent/toolDescriptions.d.ts.map +1 -0
- package/dist/agent/toolDescriptions.js +116 -0
- package/dist/api/client.d.ts +41 -0
- package/dist/api/client.d.ts.map +1 -1
- package/dist/api/client.js +173 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/mcp/client.d.ts +104 -0
- package/dist/mcp/client.d.ts.map +1 -1
- package/dist/mcp/client.js +136 -2
- package/dist/mcp/httpClient.d.ts +17 -1
- package/dist/mcp/httpClient.d.ts.map +1 -1
- package/dist/mcp/httpClient.js +120 -19
- package/dist/mcp/manager.d.ts +77 -2
- package/dist/mcp/manager.d.ts.map +1 -1
- package/dist/mcp/manager.js +275 -9
- package/dist/mcp/server.d.ts +39 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/mcp/server.js +189 -0
- package/dist/mcp/sseClient.d.ts +7 -1
- package/dist/mcp/sseClient.d.ts.map +1 -1
- package/dist/mcp/sseClient.js +45 -1
- package/dist/mcp/stats.d.ts +41 -0
- package/dist/mcp/stats.d.ts.map +1 -0
- package/dist/mcp/stats.js +108 -0
- package/dist/permissions/destructive.d.ts +2 -0
- package/dist/permissions/destructive.d.ts.map +1 -1
- package/dist/permissions/destructive.js +6 -2
- package/dist/permissions/destructiveTokens.d.ts +5 -0
- package/dist/permissions/destructiveTokens.d.ts.map +1 -1
- package/dist/permissions/destructiveTokens.js +9 -3
- package/dist/permissions/modePolicy.d.ts.map +1 -1
- package/dist/permissions/modePolicy.js +5 -2
- package/dist/permissions/rules.d.ts +4 -1
- package/dist/permissions/rules.d.ts.map +1 -1
- package/dist/permissions/rules.js +29 -0
- package/dist/plugins/data.d.ts +23 -0
- package/dist/plugins/data.d.ts.map +1 -0
- package/dist/plugins/data.js +141 -0
- package/dist/plugins/index.d.ts +14 -2
- package/dist/plugins/index.d.ts.map +1 -1
- package/dist/plugins/index.js +45 -4
- package/dist/plugins/installer.d.ts +83 -0
- package/dist/plugins/installer.d.ts.map +1 -1
- package/dist/plugins/installer.js +207 -1
- package/dist/types.d.ts +45 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -72,6 +72,33 @@ export declare function claimAgentForResume(id: string): boolean;
|
|
|
72
72
|
export declare function releaseAgentForResume(id: string): void;
|
|
73
73
|
/** Newest first — the order a "which agents can I resume?" list wants. */
|
|
74
74
|
export declare function listAgents(): StoredAgent[];
|
|
75
|
+
/**
|
|
76
|
+
* One persisted sub-agent transcript, summarised: what ran, when, and how big it is.
|
|
77
|
+
* Deliberately WITHOUT the messages — see listPersistedAgents.
|
|
78
|
+
*/
|
|
79
|
+
export interface PersistedAgentSummary {
|
|
80
|
+
id: string;
|
|
81
|
+
agentName: string | null;
|
|
82
|
+
description: string;
|
|
83
|
+
createdAt: number;
|
|
84
|
+
updatedAt: number;
|
|
85
|
+
/** Message count, so a listing can show how much context the transcript holds. */
|
|
86
|
+
messages: number;
|
|
87
|
+
bytes: number;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Summarise the transcripts written by enableAgentTranscriptPersistence().
|
|
91
|
+
*
|
|
92
|
+
* This is a READ-ONLY listing for a DIFFERENT process than the one that wrote them (the
|
|
93
|
+
* `nex agents` shell command): every session that enabled persistence writes here, so the
|
|
94
|
+
* view does not need any session to be awake. Message bodies are deliberately not returned
|
|
95
|
+
* — a row needs a description and an age, and loading every transcript would pull
|
|
96
|
+
* megabytes into memory for a table.
|
|
97
|
+
*
|
|
98
|
+
* Malformed or half-written files are SKIPPED, never thrown over: one bad file (a crash
|
|
99
|
+
* mid-write, a format from an older version) must not blank the whole view.
|
|
100
|
+
*/
|
|
101
|
+
export declare function listPersistedAgents(dir?: string): PersistedAgentSummary[];
|
|
75
102
|
/** Test seam. Not exported through index.ts's public surface by intent. */
|
|
76
103
|
export declare function _resetAgentRegistry(): void;
|
|
77
104
|
export declare const _limits: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agentRegistry.d.ts","sourceRoot":"","sources":["../../src/agent/agentRegistry.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AA8CxC,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX;;;;;;OAMG;IACH,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB;;;;;;;;;;;;;;OAcG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB,2EAA2E;IAC3E,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,iFAAiF;IACjF,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB;;;;;;;;;OASG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ,mFAAmF;IACnF,KAAK,EAAE,MAAM,CAAC;IACd;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAsDD,wBAAgB,gCAAgC,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAInE;AAED,wBAAgB,iCAAiC,IAAI,IAAI,CAAwB;AAoCjF,yEAAyE;AACzE,wBAAgB,aAAa,CAC3B,SAAS,EAAE,MAAM,GAAG,IAAI,EACxB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,OAAO,EAAE,EACnB,UAAU,SAAS,EACnB,UAAU,CAAC,EAAE,MAAM,GAClB,MAAM,CAoBR;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAG1F;AAED,gEAAgE;AAChE,wBAAgB,WAAW,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,OA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6 +43,7 @@ exports.getAgent = getAgent;
|
|
|
43
43
|
exports.claimAgentForResume = claimAgentForResume;
|
|
44
44
|
exports.releaseAgentForResume = releaseAgentForResume;
|
|
45
45
|
exports.listAgents = listAgents;
|
|
46
|
+
exports.listPersistedAgents = listPersistedAgents;
|
|
46
47
|
exports._resetAgentRegistry = _resetAgentRegistry;
|
|
47
48
|
const node_crypto_1 = require("node:crypto");
|
|
48
49
|
const fs = __importStar(require("node:fs"));
|
|
@@ -279,6 +280,50 @@ function releaseAgentForResume(id) { _inUse.delete(id); }
|
|
|
279
280
|
function listAgents() {
|
|
280
281
|
return [..._agents.values()].sort((a, b) => b.seq - a.seq);
|
|
281
282
|
}
|
|
283
|
+
/**
|
|
284
|
+
* Summarise the transcripts written by enableAgentTranscriptPersistence().
|
|
285
|
+
*
|
|
286
|
+
* This is a READ-ONLY listing for a DIFFERENT process than the one that wrote them (the
|
|
287
|
+
* `nex agents` shell command): every session that enabled persistence writes here, so the
|
|
288
|
+
* view does not need any session to be awake. Message bodies are deliberately not returned
|
|
289
|
+
* — a row needs a description and an age, and loading every transcript would pull
|
|
290
|
+
* megabytes into memory for a table.
|
|
291
|
+
*
|
|
292
|
+
* Malformed or half-written files are SKIPPED, never thrown over: one bad file (a crash
|
|
293
|
+
* mid-write, a format from an older version) must not blank the whole view.
|
|
294
|
+
*/
|
|
295
|
+
function listPersistedAgents(dir) {
|
|
296
|
+
const root = dir ?? process.env.NEXRALL_AGENT_TRANSCRIPTS_DIR ?? path.join(os.homedir(), '.nexrall', 'agent-transcripts');
|
|
297
|
+
let names;
|
|
298
|
+
try {
|
|
299
|
+
names = fs.readdirSync(root).filter((f) => f.endsWith('.json'));
|
|
300
|
+
}
|
|
301
|
+
catch {
|
|
302
|
+
return [];
|
|
303
|
+
}
|
|
304
|
+
const out = [];
|
|
305
|
+
for (const name of names) {
|
|
306
|
+
try {
|
|
307
|
+
const a = JSON.parse(fs.readFileSync(path.join(root, name), 'utf-8'));
|
|
308
|
+
// The same id shape persistedPath() writes — anything else is not ours to show.
|
|
309
|
+
if (!a || typeof a.id !== 'string' || !/^agent_\d+_[0-9a-f]{8}$/.test(a.id))
|
|
310
|
+
continue;
|
|
311
|
+
if (!Array.isArray(a.messages))
|
|
312
|
+
continue;
|
|
313
|
+
out.push({
|
|
314
|
+
id: a.id,
|
|
315
|
+
agentName: typeof a.agentName === 'string' ? a.agentName : null,
|
|
316
|
+
description: typeof a.description === 'string' ? a.description : '',
|
|
317
|
+
createdAt: typeof a.createdAt === 'number' ? a.createdAt : 0,
|
|
318
|
+
updatedAt: typeof a.updatedAt === 'number' ? a.updatedAt : 0,
|
|
319
|
+
messages: a.messages.length,
|
|
320
|
+
bytes: typeof a.bytes === 'number' ? a.bytes : 0,
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
catch { /* one unreadable transcript must not blank the list */ }
|
|
324
|
+
}
|
|
325
|
+
return out.sort((x, y) => y.updatedAt - x.updatedAt);
|
|
326
|
+
}
|
|
282
327
|
/** Test seam. Not exported through index.ts's public surface by intent. */
|
|
283
328
|
function _resetAgentRegistry() {
|
|
284
329
|
_agents.clear();
|
|
@@ -82,8 +82,12 @@ export interface AgentType {
|
|
|
82
82
|
hooks?: AgentHooks;
|
|
83
83
|
}
|
|
84
84
|
export interface AgentHookDef {
|
|
85
|
-
type: 'command';
|
|
86
|
-
command
|
|
85
|
+
type: 'command' | 'http';
|
|
86
|
+
command?: string;
|
|
87
|
+
/** `type:"http"`: POST the hook payload here. */
|
|
88
|
+
url?: string;
|
|
89
|
+
headers?: Record<string, string>;
|
|
90
|
+
allowedEnvVars?: string[];
|
|
87
91
|
timeout_ms?: number;
|
|
88
92
|
}
|
|
89
93
|
export interface AgentHookEntry {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agentTypes.d.ts","sourceRoot":"","sources":["../../src/agent/agentTypes.ts"],"names":[],"mappings":"AAoCA,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC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tB;IAAE,KAAK,EAAE,SAAS,EAAE,CAAC;IAAC,QAAQ,EAAE,YAAY,EAAE,CAAA;CAAE,CAuBlD;AAED,yFAAyF;AACzF,wBAAgB,cAAc,IAAI,MAAM,EAAE,CAEzC;AAED,2FAA2F;AAC3F,wBAAgB,aAAa,IAAI,SAAS,EAAE,CAE3C;AACD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,EAAE,GAAG,MAAM,CAY1D;AASD,wBAAgB,aAAa,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,CAIjG"}
|
package/dist/agent/agentTypes.js
CHANGED
|
@@ -588,12 +588,21 @@ function parseAgentHooks(raw) {
|
|
|
588
588
|
throw new Error(`${where}: expected a list of hooks`);
|
|
589
589
|
return list.map((h, i) => {
|
|
590
590
|
const o = h;
|
|
591
|
-
if (!o || o.type !== 'command' || typeof o.command !== 'string' || !o.command.trim()) {
|
|
592
|
-
throw new Error(`${where}[${i}]: each hook needs type: command and a command`);
|
|
593
|
-
}
|
|
594
591
|
const ms = typeof o.timeout_ms === 'number' ? o.timeout_ms
|
|
595
592
|
: typeof o.timeout === 'number' ? o.timeout * 1000 : undefined;
|
|
596
|
-
|
|
593
|
+
const timeout = ms && ms > 0 ? { timeout_ms: ms } : {};
|
|
594
|
+
if (o && o.type === 'http' && typeof o.url === 'string' && o.url.trim()) {
|
|
595
|
+
if (!/^https?:\/\//i.test(o.url.trim()))
|
|
596
|
+
throw new Error(`${where}[${i}]: http hooks need an http(s) url`);
|
|
597
|
+
const headers = o.headers && typeof o.headers === 'object' && !Array.isArray(o.headers)
|
|
598
|
+
? o.headers : undefined;
|
|
599
|
+
const allowed = Array.isArray(o.allowedEnvVars) ? o.allowedEnvVars.filter((v) => typeof v === 'string') : undefined;
|
|
600
|
+
return { type: 'http', url: o.url.trim(), ...(headers ? { headers } : {}), ...(allowed ? { allowedEnvVars: allowed } : {}), ...timeout };
|
|
601
|
+
}
|
|
602
|
+
if (!o || o.type !== 'command' || typeof o.command !== 'string' || !o.command.trim()) {
|
|
603
|
+
throw new Error(`${where}[${i}]: each hook needs type: command and a command, or type: http and a url`);
|
|
604
|
+
}
|
|
605
|
+
return { type: 'command', command: o.command, ...timeout };
|
|
597
606
|
});
|
|
598
607
|
};
|
|
599
608
|
const entries = (list, ev) => {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { EnvContext } from '../types';
|
|
2
|
+
export interface AskOnceOptions {
|
|
3
|
+
model: string;
|
|
4
|
+
cwd: string;
|
|
5
|
+
env?: EnvContext;
|
|
6
|
+
timeoutMs?: number;
|
|
7
|
+
abortSignal?: {
|
|
8
|
+
aborted: boolean;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export declare function askModelOnce(prompt: string, opts: AskOnceOptions): Promise<string | null>;
|
|
12
|
+
//# sourceMappingURL=askOnce.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"askOnce.d.ts","sourceRoot":"","sources":["../../src/agent/askOnce.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAgB,UAAU,EAAW,MAAM,UAAU,CAAC;AAKlE,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,CAAC,EAAE,UAAU,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;CACpC;AAED,wBAAsB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAwB/F"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// A single tool-less model call: send one prompt, get the text back. Used by small
|
|
3
|
+
// judges (e.g. the CLI's /goal) that need an answer, not an agent loop. It never
|
|
4
|
+
// runs tools, never throws on a model/network failure (returns null) and never
|
|
5
|
+
// outlives its timeout, so a judge can never hang or crash the turn that asked.
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.askModelOnce = askModelOnce;
|
|
8
|
+
const client_1 = require("../api/client");
|
|
9
|
+
/** The same marker prompt hooks use: matches no tool, so the backend sends none. */
|
|
10
|
+
const NO_TOOLS_MARKER = '\u0000hook-no-tools';
|
|
11
|
+
async function askModelOnce(prompt, opts) {
|
|
12
|
+
const ctl = { aborted: false };
|
|
13
|
+
const timer = setTimeout(() => { ctl.aborted = true; }, Math.max(1000, opts.timeoutMs ?? 45000));
|
|
14
|
+
const poll = opts.abortSignal
|
|
15
|
+
? setInterval(() => { if (opts.abortSignal?.aborted)
|
|
16
|
+
ctl.aborted = true; }, 100)
|
|
17
|
+
: undefined;
|
|
18
|
+
try {
|
|
19
|
+
if (opts.abortSignal?.aborted)
|
|
20
|
+
return null;
|
|
21
|
+
const messages = [{ role: 'user', content: [{ type: 'text', text: prompt }] }];
|
|
22
|
+
const msg = await (0, client_1.streamChat)(messages, {
|
|
23
|
+
model: opts.model,
|
|
24
|
+
env: opts.env ?? { cwd: opts.cwd },
|
|
25
|
+
abortSignal: ctl,
|
|
26
|
+
toolAllowlist: [NO_TOOLS_MARKER],
|
|
27
|
+
}, () => { });
|
|
28
|
+
const blocks = Array.isArray(msg.content) ? msg.content : [];
|
|
29
|
+
const text = blocks.filter((b) => b.type === 'text' && typeof b.text === 'string').map((b) => b.text).join('\n');
|
|
30
|
+
return ctl.aborted ? null : text;
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
finally {
|
|
36
|
+
clearTimeout(timer);
|
|
37
|
+
if (poll)
|
|
38
|
+
clearInterval(poll);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=askOnce.js.map
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import type { Message, AgentLoopOptions, EnvContext } from '../types';
|
|
2
|
+
import { streamChat } from '../api/client';
|
|
3
|
+
import { type MemoryScope } from './memory';
|
|
4
|
+
export declare const MODEL_CONTEXT_TOKENS: Record<string, number>;
|
|
5
|
+
/**
|
|
6
|
+
* Context window (tokens) for a model alias or real model id.
|
|
7
|
+
*
|
|
8
|
+
* Checks the LIVE catalogue (GET /api/code/models, modelCatalogue.ts) first —
|
|
9
|
+
* populated once per process by whichever client fetched it (CLI at session
|
|
10
|
+
* start, VS Code via _postModelCatalogue, desktop via its main-process
|
|
11
|
+
* fetch) — falling back to this hard-coded table when no live data exists yet
|
|
12
|
+
* (offline, older backend, or the catalogue simply hasn't been fetched by
|
|
13
|
+
* this call site). This is what lets a model added to the backend registry
|
|
14
|
+
* (services/providers/modelRegistry.js) get the CORRECT context window here
|
|
15
|
+
* even before this table is updated by hand for a new nexrall-code release —
|
|
16
|
+
* exactly the class of bug GPT-5.6's 922K-vs-1.05M mismatch was (see
|
|
17
|
+
* modelRegistry.js's own comment on that row).
|
|
18
|
+
*
|
|
19
|
+
* The static-table fallback is deliberately the SMALLEST window in the table
|
|
20
|
+
* rather than the largest. An unknown model is most likely a newly added one
|
|
21
|
+
* this client build predates, and guessing high is the failure that cannot be
|
|
22
|
+
* recovered from: the turn hits a provider 400 with no chance to compact.
|
|
23
|
+
* Guessing low only costs an earlier, lossy compaction — annoying, not broken.
|
|
24
|
+
*/
|
|
25
|
+
export declare function contextWindowFor(model?: string): number;
|
|
26
|
+
/** Token counts at which auto-prune and auto-compact (summarise) fire for a model window. */
|
|
27
|
+
export declare function compactionLimits(contextWindow: number, settingsRaw?: Record<string, unknown>): {
|
|
28
|
+
prune: number;
|
|
29
|
+
compact: number;
|
|
30
|
+
};
|
|
31
|
+
/** Auto-prune / auto-compact thresholds as fractions of the context window — for UI display (e.g. `/context`). */
|
|
32
|
+
export declare function compactionThresholds(contextWindow?: number, settingsRaw?: Record<string, unknown>): {
|
|
33
|
+
prune: number;
|
|
34
|
+
compact: number;
|
|
35
|
+
};
|
|
36
|
+
export declare const PRUNE_MIN_RECLAIM_BYTES: number;
|
|
37
|
+
export declare const _lastApiCallEndedAt: Map<string, number>;
|
|
38
|
+
export declare function pruneReclaimFloor(lastCallEndedAt: number | undefined, now?: number): number;
|
|
39
|
+
export declare const COMPACT_KEEP_MIN = 6;
|
|
40
|
+
/**
|
|
41
|
+
* Bytes a compaction must reclaim to count as productive.
|
|
42
|
+
*
|
|
43
|
+
* Deliberately much smaller than PRUNE_MIN_RECLAIM_BYTES: a prune declines when the
|
|
44
|
+
* gain isn't worth busting the prompt cache, whereas by the time we are summarising
|
|
45
|
+
* we are already committed to rewriting the prefix — the only question is whether the
|
|
46
|
+
* summariser is making ANY headway. 32 KB is small enough that a genuinely useful
|
|
47
|
+
* compaction always clears it, large enough that shuffling a few bytes doesn't.
|
|
48
|
+
*/
|
|
49
|
+
export declare const COMPACT_MIN_RECLAIM_BYTES: number;
|
|
50
|
+
/**
|
|
51
|
+
* Consecutive non-productive compaction attempts before auto-compaction is switched
|
|
52
|
+
* off for the rest of the run.
|
|
53
|
+
*
|
|
54
|
+
* 3 rather than 1 because the failure is often transient — a summariser stream that
|
|
55
|
+
* blipped will usually succeed on the next turn, and giving up instantly would lose
|
|
56
|
+
* the safety net for a whole long session over one network hiccup. 3 also bounds the
|
|
57
|
+
* wasted spend: at most three summariser calls, not hundreds.
|
|
58
|
+
*/
|
|
59
|
+
export declare const COMPACT_MAX_FAILURES = 3;
|
|
60
|
+
export declare const MAX_BODY_BYTES: number;
|
|
61
|
+
/** Approximate serialised request-body size (bytes) for the messages array. */
|
|
62
|
+
export declare function estimateBodyBytes(messages: Message[]): number;
|
|
63
|
+
export declare function resolveAutoCompact(fromOptions: boolean | undefined, rawSettings: Record<string, unknown>): boolean;
|
|
64
|
+
/** Opt-out for the one-shot verification nudge (GAP D). Defaults to on. */
|
|
65
|
+
export declare function resolveVerificationNudge(rawSettings: Record<string, unknown>): boolean;
|
|
66
|
+
/** Tools that mutate the filesystem — used by the verification nudge (GAP D). */
|
|
67
|
+
export declare const WRITE_TOOL_NAMES: Set<string>;
|
|
68
|
+
/**
|
|
69
|
+
* May an agent restricted to `testFilesOnly` perform this tool call?
|
|
70
|
+
*
|
|
71
|
+
* A tool allowlist is all-or-nothing per tool: granting `edit_file` grants it for
|
|
72
|
+
* every path in the repo. A user-defined test-writer agent needs write access to produce
|
|
73
|
+
* tests, but must NOT be able to "fix" production source so a failing test goes
|
|
74
|
+
* green — the single most common way a test-writing agent destroys the signal it
|
|
75
|
+
* was asked to create. Its prompt says so; this makes it a refusal rather than a
|
|
76
|
+
* request.
|
|
77
|
+
*
|
|
78
|
+
* Pure + exported so the rules are testable directly, without running a real
|
|
79
|
+
* sub-agent.
|
|
80
|
+
*
|
|
81
|
+
* KNOWN LIMIT, stated rather than hidden: this gates the file TOOLS, not `bash`.
|
|
82
|
+
* A determined model could still write source via `bash: echo ... > src/x.ts`.
|
|
83
|
+
* Closing that means parsing shell redirection, which is not reliably doable — so
|
|
84
|
+
* this is a strong guardrail against the realistic failure mode, not a sandbox.
|
|
85
|
+
* Real isolation is the sandbox config (tools/sandbox.ts), a separate mechanism.
|
|
86
|
+
*/
|
|
87
|
+
export declare function allowsTestOnlyWrite(tool: string, input: Record<string, unknown> | undefined): boolean;
|
|
88
|
+
/** Heuristic: does a bash command look like it's running tests/build/lint/typecheck? (GAP D) */
|
|
89
|
+
export declare const VERIFY_CMD_RE: RegExp;
|
|
90
|
+
/**
|
|
91
|
+
* Find the latest index ≤ maxIdx where history can be cut safely.
|
|
92
|
+
*
|
|
93
|
+
* A safe cut point is a **turn boundary**: an assistant message (which always
|
|
94
|
+
* begins a fresh turn after a user message). Cutting there guarantees that
|
|
95
|
+
* `messages[cut..]` starts with an assistant whose `tool_use` blocks are all
|
|
96
|
+
* answered by `tool_result`s that remain in the kept slice — so we never orphan
|
|
97
|
+
* a tool_result (which the API rejects). We deliberately allow cutting across
|
|
98
|
+
* tool_result-bearing user messages: the OLD implementation only cut at a
|
|
99
|
+
* *non*-tool_result user message, which never exists inside a single long
|
|
100
|
+
* agentic run (every user turn is a tool_result), so compaction was a no-op
|
|
101
|
+
* exactly when a long task needs it most.
|
|
102
|
+
*/
|
|
103
|
+
export declare function findSafeCutIndex(messages: Message[], maxIdx: number): number;
|
|
104
|
+
/**
|
|
105
|
+
* Render messages to a plain-text transcript for the summariser (tool noise
|
|
106
|
+
* truncated per-block AND the whole transcript hard-capped). When the transcript
|
|
107
|
+
* would exceed MAX_TRANSCRIPT_CHARS we keep the HEAD (original task + early
|
|
108
|
+
* decisions) and the TAIL (most-recent, highest-signal context) and drop the
|
|
109
|
+
* middle — a middle-out elision that preserves both "what we set out to do" and
|
|
110
|
+
* "where we are now", which is what the continuation summary needs most.
|
|
111
|
+
*/
|
|
112
|
+
/**
|
|
113
|
+
* Appends the backend-announced runtime-context block to the user message it was
|
|
114
|
+
* attached to. No-op if that message is not a user turn or already ends with the
|
|
115
|
+
* identical block. Exported for tests.
|
|
116
|
+
*/
|
|
117
|
+
export declare function persistRuntimeContext(messages: Message[], idx: number, text: string): boolean;
|
|
118
|
+
export declare function transcriptOf(messages: Message[]): string;
|
|
119
|
+
export interface ProgressLedger {
|
|
120
|
+
filesTouched: Map<string, {
|
|
121
|
+
tool: string;
|
|
122
|
+
edits: number;
|
|
123
|
+
}>;
|
|
124
|
+
/**
|
|
125
|
+
* DISTINCT paths ever touched, including any since evicted from `filesTouched`.
|
|
126
|
+
*
|
|
127
|
+
* The Map is bounded (see ledgerRecord), so `filesTouched.size` is a window, not a
|
|
128
|
+
* total. The preamble states "FILES CHANGED THIS SESSION (N)" as a fact the model
|
|
129
|
+
* reasons about, so N must not silently shrink when eviction kicks in on a very long
|
|
130
|
+
* run — that would tell the model less work happened than actually did.
|
|
131
|
+
*/
|
|
132
|
+
filesTouchedTotal: number;
|
|
133
|
+
verifications: Array<{
|
|
134
|
+
cmd: string;
|
|
135
|
+
ok: boolean;
|
|
136
|
+
epoch: number;
|
|
137
|
+
}>;
|
|
138
|
+
/** Test-integrity findings (reward-hacking signals) that must survive compaction. */
|
|
139
|
+
testIntegrity: Array<{
|
|
140
|
+
path: string;
|
|
141
|
+
reason: string;
|
|
142
|
+
}>;
|
|
143
|
+
/**
|
|
144
|
+
* TOTAL test-integrity findings ever recorded, including ones since trimmed.
|
|
145
|
+
*
|
|
146
|
+
* `testIntegrity` is a bounded window (older entries are spliced off once it grows
|
|
147
|
+
* past 2×LEDGER_MAX_NOTES), so its `.length` STOPS being a running total after the
|
|
148
|
+
* first trim. The one-shot nudge compares "how many findings exist" against "how
|
|
149
|
+
* many I've already surfaced", and comparing against a window that shrinks meant the
|
|
150
|
+
* count could never move ahead again — silently disabling the reward-hacking warning
|
|
151
|
+
* for the remainder of a long session, i.e. exactly when it matters most.
|
|
152
|
+
*
|
|
153
|
+
* This counter only ever increases, so it is a safe basis for that comparison.
|
|
154
|
+
*/
|
|
155
|
+
testIntegrityTotal: number;
|
|
156
|
+
/**
|
|
157
|
+
* Monotonic mutation epoch: incremented on every successful source write. Two
|
|
158
|
+
* verification runs sharing an epoch had NO edit between them, so a PASS↔FAIL
|
|
159
|
+
* flip across that boundary proves the test is flaky (see detectFlaky).
|
|
160
|
+
*/
|
|
161
|
+
epoch: number;
|
|
162
|
+
}
|
|
163
|
+
export declare function createLedger(): ProgressLedger;
|
|
164
|
+
/** Record one tool call's effect on the ledger (deterministic, no model call). */
|
|
165
|
+
export declare function ledgerRecord(ledger: ProgressLedger, toolName: string, input: Record<string, unknown> | undefined, ok: boolean, output?: string, exitCode?: number): void;
|
|
166
|
+
/** Render the ledger as a compact, verbatim block for the compaction preamble. */
|
|
167
|
+
export declare function ledgerSummary(ledger: ProgressLedger): string;
|
|
168
|
+
export declare const PRUNE_KEEP_RECENT = 8;
|
|
169
|
+
/**
|
|
170
|
+
* Lossy-but-structure-preserving prune: shrink OLD, large tool_result blocks in
|
|
171
|
+
* place, keeping the last PRUNE_KEEP_RECENT messages untouched. This is tried
|
|
172
|
+
* BEFORE summarisation because it:
|
|
173
|
+
* • keeps every turn and every tool_use/tool_result pair (API stays valid),
|
|
174
|
+
* • never makes an extra model call (summarisation does — cost + latency),
|
|
175
|
+
* • degrades gracefully on repeat (summarise-of-summarise loses the most on
|
|
176
|
+
* long runs; pruning just trims already-consumed output further).
|
|
177
|
+
*
|
|
178
|
+
* IMPORTANT: pruned state is encoded in the content string (PRUNE_MARKER_TAIL
|
|
179
|
+
* suffix), NOT as an extra property on the block — a stray field on a content
|
|
180
|
+
* block is rejected by the Anthropic API as an unknown key (400). This keeps the
|
|
181
|
+
* serialised body schema-clean while remaining idempotent across repeat calls.
|
|
182
|
+
*
|
|
183
|
+
* Returns the number of bytes reclaimed (0 if nothing was prunable).
|
|
184
|
+
*
|
|
185
|
+
* `minReclaimBytes` (default 0): if the TOTAL prunable amount is below this, the
|
|
186
|
+
* function makes NO changes and returns 0. This is a cache-safety gate — pruning
|
|
187
|
+
* even one old block changes the request prefix and invalidates the message-level
|
|
188
|
+
* prompt cache, so a tiny prune would bust the cache (re-write at 1.25×) for
|
|
189
|
+
* almost no size win. Measuring first, then applying only if worthwhile, keeps
|
|
190
|
+
* the "don't bust cache for a trivial gain" contract truly atomic (the old code
|
|
191
|
+
* mutated first and let the caller decide, which had already invalidated the
|
|
192
|
+
* cache by the time the caller declined).
|
|
193
|
+
*/
|
|
194
|
+
export declare function pruneOldToolResults(messages: Message[], minReclaimBytes?: number): number;
|
|
195
|
+
/**
|
|
196
|
+
* The summariser's own model call failed — as opposed to running fine but not
|
|
197
|
+
* shrinking anything.
|
|
198
|
+
*
|
|
199
|
+
* These two outcomes used to be one `return false`, and collapsing them was a
|
|
200
|
+
* real bug: the in-loop circuit breaker disables auto-compaction permanently
|
|
201
|
+
* after COMPACT_MAX_FAILURES, on the sound theory that a compaction which cannot
|
|
202
|
+
* reclaim bytes will never start. But a summariser that THREW says nothing about
|
|
203
|
+
* whether compaction would help — only that the network/provider was unavailable
|
|
204
|
+
* for a moment. Feeding those into the same counter meant three transient blips
|
|
205
|
+
* (a 529 burst, a brief outage, a rate-limit spike) permanently switched off the
|
|
206
|
+
* one mechanism keeping the context under control, and the run then died at the
|
|
207
|
+
* context wall minutes later with its own recovery already disabled.
|
|
208
|
+
*/
|
|
209
|
+
export declare class CompactionUnavailableError extends Error {
|
|
210
|
+
constructor();
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Summarises the WHOLE conversation by appending the instruction to its final user
|
|
214
|
+
* message and sending it with the conversation's own request options — Claude Code's
|
|
215
|
+
* approach. The prefix is byte-identical to the previous request, so the history is a
|
|
216
|
+
* cache READ (0.10×) instead of a fresh uncached transcript of up to 600K chars.
|
|
217
|
+
* Returns '' when it cannot be used (last turn is not the user's) or yields no text.
|
|
218
|
+
*/
|
|
219
|
+
export type CachedSummarizer = (instruction: string) => Promise<string>;
|
|
220
|
+
export declare function makeCachedSummarizer(messages: Message[], requestOptions: () => Parameters<typeof streamChat>[1], abortSignal?: {
|
|
221
|
+
aborted: boolean;
|
|
222
|
+
}): CachedSummarizer;
|
|
223
|
+
export declare function autoCompactMessages(messages: Message[], options: AgentLoopOptions, ledger?: ProgressLedger, summarizeCached?: CachedSummarizer): Promise<boolean>;
|
|
224
|
+
export declare function maybeCompactMemory(scope: MemoryScope, options: AgentLoopOptions): Promise<void>;
|
|
225
|
+
/** Rough token estimate for a resumed transcript — no API round-trip needed. */
|
|
226
|
+
export declare function estimateTokensRough(messages: Message[]): number;
|
|
227
|
+
/**
|
|
228
|
+
* Proactively compact `messages` in place if resuming this session would blow
|
|
229
|
+
* past the auto-compact threshold on the very first turn. Returns true if any
|
|
230
|
+
* compaction happened (so the caller can surface a one-line notice to the
|
|
231
|
+
* user). Safe to call on any message array, including empty/small ones (no-op).
|
|
232
|
+
*
|
|
233
|
+
* `model` picks the right context window (mirrors runAgentLoop's own lookup);
|
|
234
|
+
* `onNotice` is optional — pass it to show the same "auto-compacted" message
|
|
235
|
+
* the in-loop path shows, so the behaviour is visually consistent.
|
|
236
|
+
*/
|
|
237
|
+
export declare function compactMessagesForResume(messages: Message[], opts: {
|
|
238
|
+
model?: string;
|
|
239
|
+
workDir: string;
|
|
240
|
+
clientType?: string;
|
|
241
|
+
env?: EnvContext;
|
|
242
|
+
onNotice?: (text: string) => void;
|
|
243
|
+
}): Promise<boolean>;
|
|
244
|
+
//# sourceMappingURL=compaction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compaction.d.ts","sourceRoot":"","sources":["../../src/agent/compaction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAgB,gBAAgB,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAIpF,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAyB,KAAK,WAAW,EAAE,MAAM,UAAU,CAAC;AAmCnE,eAAO,MAAM,oBAAoB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CA0CvD,CAAC;AAEF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAGvD;AAmDD,6FAA6F;AAC7F,wBAAgB,gBAAgB,CAC9B,aAAa,EAAE,MAAM,EACrB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACpC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CASpC;AAED,kHAAkH;AAClH,wBAAgB,oBAAoB,CAClC,aAAa,SAAY,EACzB,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACpC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAGpC;AAMD,eAAO,MAAM,uBAAuB,QAAa,CAAC;AAUlD,eAAO,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