aegiscode 5.2.31 → 5.2.33
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/bin/cli.js +410 -410
- package/package.json +1 -1
- package/scripts/repro-tokencount.ts +45 -0
- package/scripts/repro-toolcontext.ts +74 -0
package/package.json
CHANGED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reproduce the interactive turn flow: ContextManager.addMessage for each
|
|
3
|
+
* user/assistant turn, then the post-turn recount from useCommandProcessor.
|
|
4
|
+
* Verify the stored token count tracks the actual conversation.
|
|
5
|
+
*/
|
|
6
|
+
import { ContextManager } from '../src/context/ContextManager.js';
|
|
7
|
+
import { TokenCounter } from '../src/context/TokenCounter.js';
|
|
8
|
+
|
|
9
|
+
async function main() {
|
|
10
|
+
const cm = new ContextManager({});
|
|
11
|
+
await cm.createSession();
|
|
12
|
+
|
|
13
|
+
// Simulate what useCommandProcessor does per turn, with realistic content
|
|
14
|
+
const turns = 8;
|
|
15
|
+
for (let i = 0; i < turns; i++) {
|
|
16
|
+
const userMsg = `Turn ${i}: please review the function at src/agent/Agent.ts, explain the auto-compact logic, and tell me whether the inter-turn truncation respects the reserved response budget. ${'Details: '.repeat(3)}${i}`;
|
|
17
|
+
const assistantMsg = `## Analysis (turn ${i})\n\nThe auto-compact path checks TokenCounter.estimateMessagesTokens first, then falls back to the exact BPE count when over threshold. The reserved response budget of 10k tokens is subtracted from maxTokens before truncation, so a long tool output cannot starve the final answer.\n\n| step | tokens |\n|------|--------|\n| pre-filter | ~${100 + i * 50} |\n| exact count | ${200 + i * 100} |\n\nThis is a moderately long assistant reply to simulate real conversation bulk across many turns. ${'words '.repeat(10)}end.`;
|
|
18
|
+
|
|
19
|
+
// 1. user message (ContextManager.addMessage)
|
|
20
|
+
await cm.addMessage('user', userMsg);
|
|
21
|
+
|
|
22
|
+
// 2. assistant message (ContextManager.addMessage)
|
|
23
|
+
await cm.addMessage('assistant', assistantMsg);
|
|
24
|
+
|
|
25
|
+
// 3. post-turn recount (useCommandProcessor lines 427-431)
|
|
26
|
+
const modelName = 'claude-sonnet-4-20250514';
|
|
27
|
+
const totalTokens = TokenCounter.countTokens(
|
|
28
|
+
cm.getMessages().map(m => ({ role: m.role as any, content: m.content })),
|
|
29
|
+
modelName
|
|
30
|
+
);
|
|
31
|
+
cm.updateTokenCount(totalTokens);
|
|
32
|
+
|
|
33
|
+
const stored = cm.getTokenCount();
|
|
34
|
+
const raw = cm.getContext()!.layers.conversation.messages.length;
|
|
35
|
+
console.log(`after turn ${i + 1}: store=${stored} tokens, msgs=${raw}`);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const final = cm.getTokenCount();
|
|
39
|
+
console.log('\n=== RESULT ===');
|
|
40
|
+
console.log('turns:', turns, '| final stored token count:', final);
|
|
41
|
+
console.log(final > 4000 ? 'PASS: /compact would proceed' : 'FAIL: /compact would refuse (stuck under 4000)');
|
|
42
|
+
await cm.cleanup();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
main().catch(e => { console.error(e); process.exit(1); });
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* End-to-end check for the "tool activity was never persisted" fix:
|
|
3
|
+
* 1. addToolActivity() records assistant(tool_calls) + tool results.
|
|
4
|
+
* 2. The stored token count reflects the tool content (→ /compact gate passes).
|
|
5
|
+
* 3. Persistence round-trips: reload from JSONL keeps messages, tool_calls,
|
|
6
|
+
* tool_call_id linkage, and an accurate recount.
|
|
7
|
+
*/
|
|
8
|
+
import { ContextManager } from '../src/context/ContextManager.js';
|
|
9
|
+
import { TokenCounter } from '../src/context/TokenCounter.js';
|
|
10
|
+
import * as fs from 'node:fs';
|
|
11
|
+
import * as path from 'node:path';
|
|
12
|
+
import { fileURLToPath } from 'node:url';
|
|
13
|
+
|
|
14
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
15
|
+
// Realistic tool output: actual source text (much denser than repeated chars)
|
|
16
|
+
const BIG_TOOL_OUTPUT = fs.readFileSync(path.join(__dirname, '..', 'src', 'agent', 'Agent.ts'), 'utf8')
|
|
17
|
+
.split('\n').slice(0, 300).join('\n');
|
|
18
|
+
|
|
19
|
+
async function main() {
|
|
20
|
+
const cm = new ContextManager({});
|
|
21
|
+
await cm.createSession();
|
|
22
|
+
const sessionId = cm.getCurrentSessionId()!;
|
|
23
|
+
|
|
24
|
+
// Turn 1: plain exchange (like repro-tokencount) — small.
|
|
25
|
+
await cm.addMessage('user', 'Turn 0: explain the auto-compact logic. Details: 0');
|
|
26
|
+
await cm.addMessage('assistant', '## Analysis (turn 0)\n\nThe auto-compact path checks TokenCounter first. ' + 'words '.repeat(20));
|
|
27
|
+
|
|
28
|
+
// Turn 2: tool-heavy turn — a Read returning a large file, plus a small tool.
|
|
29
|
+
await cm.addMessage('user', 'Turn 1: read src/agent/Agent.ts and summarize it. Details: 1');
|
|
30
|
+
await cm.addToolActivity(
|
|
31
|
+
[
|
|
32
|
+
{ id: 'call_read', type: 'function', function: { name: 'Read', arguments: JSON.stringify({ path: 'src/agent/Agent.ts', offset: 0, limit: 200 }) } },
|
|
33
|
+
{ id: 'call_bash', type: 'function', function: { name: 'Bash', arguments: JSON.stringify({ command: 'wc -l src/agent/Agent.ts' }) } },
|
|
34
|
+
],
|
|
35
|
+
[
|
|
36
|
+
{ id: 'call_read', name: 'Read', content: BIG_TOOL_OUTPUT },
|
|
37
|
+
{ id: 'call_bash', name: 'Bash', content: '986 lines' },
|
|
38
|
+
]
|
|
39
|
+
);
|
|
40
|
+
await cm.addMessage('assistant', '## Summary (turn 1)\n\nAgent.ts is 986 lines and its auto-compact path is straightforward.');
|
|
41
|
+
|
|
42
|
+
const stored = cm.getTokenCount();
|
|
43
|
+
const msgs = cm.getMessages();
|
|
44
|
+
console.log('stored token count:', stored);
|
|
45
|
+
console.log('stored messages:', msgs.length, '(roles: ' + msgs.map(m => m.role).join(',') + ')');
|
|
46
|
+
console.log('/compact gate (>=' + 4000 + '):', stored >= 4000 ? 'PASS' : 'FAIL');
|
|
47
|
+
|
|
48
|
+
// Verify message ordering / linkage for the API.
|
|
49
|
+
const asstIdx = msgs.findIndex(m => m.tool_calls && m.tool_calls.length > 0);
|
|
50
|
+
const toolIdx = msgs.findIndex(m => m.role === 'tool');
|
|
51
|
+
console.log('assistant(tool_calls) before tool results:', asstIdx !== -1 && toolIdx > asstIdx ? 'PASS' : 'FAIL');
|
|
52
|
+
const toolMsg = msgs[toolIdx];
|
|
53
|
+
console.log('tool message has tool_call_id + name:', toolMsg && toolMsg.tool_call_id === 'call_read' && toolMsg.name === 'Read' ? 'PASS' : 'FAIL');
|
|
54
|
+
|
|
55
|
+
await cm.flush();
|
|
56
|
+
await cm.cleanup();
|
|
57
|
+
|
|
58
|
+
// ── Reload from JSONL ──
|
|
59
|
+
const cm2 = new ContextManager({});
|
|
60
|
+
const ok = await cm2.loadSession(sessionId);
|
|
61
|
+
const msgs2 = cm2.getMessages();
|
|
62
|
+
const count2 = cm2.getTokenCount();
|
|
63
|
+
console.log('\nreload ok:', ok);
|
|
64
|
+
console.log('reloaded messages:', msgs2.length, '(roles: ' + msgs2.map(m => m.role).join(',') + ')');
|
|
65
|
+
console.log('reloaded tool_calls linkage:', (() => {
|
|
66
|
+
const a = msgs2.findIndex(m => m.tool_calls && m.tool_calls.length > 0);
|
|
67
|
+
const t = msgs2.findIndex(m => m.role === 'tool');
|
|
68
|
+
return a !== -1 && t > a && msgs2[t].tool_call_id === 'call_read' ? 'PASS' : 'FAIL';
|
|
69
|
+
})());
|
|
70
|
+
console.log('reloaded token count matches:', count2 === stored ? `PASS (${count2})` : `FAIL store=${stored} reload=${count2}`);
|
|
71
|
+
await cm2.cleanup();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
main().catch(e => { console.error(e); process.exit(1); });
|