aegiscode 5.2.31 → 5.2.32
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/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); });
|