aegiscode 5.2.32 → 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/package.json +1 -1
- package/scripts/repro-toolcontext.ts +74 -0
package/package.json
CHANGED
|
@@ -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); });
|