@element47/ag 4.4.3 → 4.5.1
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/cli/repl.d.ts.map +1 -1
- package/dist/cli/repl.js +210 -73
- package/dist/cli/repl.js.map +1 -1
- package/dist/cli.js +11 -1
- package/dist/cli.js.map +1 -1
- package/dist/core/__tests__/registry.test.js +9 -2
- package/dist/core/__tests__/registry.test.js.map +1 -1
- package/dist/core/agent.d.ts +11 -2
- package/dist/core/agent.d.ts.map +1 -1
- package/dist/core/agent.js +210 -68
- package/dist/core/agent.js.map +1 -1
- package/dist/core/context.d.ts.map +1 -1
- package/dist/core/context.js +17 -2
- package/dist/core/context.js.map +1 -1
- package/dist/core/types.d.ts +5 -1
- package/dist/core/types.d.ts.map +1 -1
- package/dist/memory/__tests__/memory.test.js +5 -3
- package/dist/memory/__tests__/memory.test.js.map +1 -1
- package/dist/memory/memory.d.ts.map +1 -1
- package/dist/memory/memory.js +25 -3
- package/dist/memory/memory.js.map +1 -1
- package/package.json +4 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.test.js","sourceRoot":"","sources":["../../../src/core/__tests__/registry.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC3E,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEjC,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,QAAQ,CAAC,C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AC,CAAC;IACxC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/core/agent.d.ts
CHANGED
|
@@ -30,10 +30,17 @@ export declare class Agent implements SkillHost {
|
|
|
30
30
|
private refreshCache;
|
|
31
31
|
private getProjectListing;
|
|
32
32
|
private get systemPrompt();
|
|
33
|
+
/** Build the JSON request body for chat completions, with prompt caching for supported models */
|
|
34
|
+
private buildRequestBody;
|
|
33
35
|
activateSkill(name: string): Promise<string>;
|
|
34
36
|
private compactConversation;
|
|
35
|
-
chat(content: string): Promise<string>;
|
|
36
|
-
chatStream(content: string): AsyncGenerator<StreamChunk>;
|
|
37
|
+
chat(content: string, signal?: AbortSignal): Promise<string>;
|
|
38
|
+
chatStream(content: string, signal?: AbortSignal): AsyncGenerator<StreamChunk>;
|
|
39
|
+
/** Return the char-size breakdown of every context component */
|
|
40
|
+
getContextBreakdown(): Array<{
|
|
41
|
+
label: string;
|
|
42
|
+
chars: number;
|
|
43
|
+
}>;
|
|
37
44
|
getTools(): Array<{
|
|
38
45
|
name: string;
|
|
39
46
|
description: string;
|
|
@@ -84,5 +91,7 @@ export declare class Agent implements SkillHost {
|
|
|
84
91
|
getContextDetails(): string;
|
|
85
92
|
getContextTracker(): ContextTracker;
|
|
86
93
|
getSystemPromptSize(): number;
|
|
94
|
+
/** Total estimated chars across all context components (system prompt + tools + messages) */
|
|
95
|
+
getTotalContextChars(): number;
|
|
87
96
|
}
|
|
88
97
|
//# sourceMappingURL=agent.d.ts.map
|
package/dist/core/agent.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../src/core/agent.ts"],"names":[],"mappings":"AAGA,OAAO,EAAW,IAAI,EAAE,WAAW,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAEtF,OAAO,EAA2P,KAAK,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAKhT,OAAO,EAAa,KAAK,SAA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AiB,IAAI,MAAM;IAC3B,iBAAiB,IAAI,cAAc;IACnC,mBAAmB,IAAI,MAAM;IAC7B,6FAA6F;IAC7F,oBAAoB,IAAI,MAAM;CAG/B"}
|
package/dist/core/agent.js
CHANGED
|
@@ -118,6 +118,16 @@ export function truncateToolResult(result) {
|
|
|
118
118
|
const omitted = lines.length - TRUNCATION_HEAD_LINES - TRUNCATION_TAIL_LINES;
|
|
119
119
|
return [...head, `\n... [${omitted} lines truncated] ...\n`, ...tail].join('\n');
|
|
120
120
|
}
|
|
121
|
+
/** Yield promise results as they resolve (like Promise.all but streaming) */
|
|
122
|
+
async function* raceAll(promises) {
|
|
123
|
+
const wrapped = promises.map((p, i) => p.then(v => ({ i, v })));
|
|
124
|
+
const settled = new Set();
|
|
125
|
+
while (settled.size < promises.length) {
|
|
126
|
+
const result = await Promise.race(wrapped.filter((_, idx) => !settled.has(idx)));
|
|
127
|
+
settled.add(result.i);
|
|
128
|
+
yield result.v;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
121
131
|
export class Agent {
|
|
122
132
|
apiKey;
|
|
123
133
|
model;
|
|
@@ -178,6 +188,7 @@ export class Agent {
|
|
|
178
188
|
- Be concise. Short responses, no filler, no trailing summaries of what you just did.
|
|
179
189
|
- When referencing code, include the file path and relevant context.
|
|
180
190
|
- Only use markdown formatting when it aids clarity.
|
|
191
|
+
- Always follow instructions in <global-memory> — these are persistent user preferences that override defaults.
|
|
181
192
|
|
|
182
193
|
# Verification
|
|
183
194
|
- After making changes, verify they work: run tests, check for syntax errors, or start the dev server as appropriate.
|
|
@@ -282,6 +293,24 @@ export class Agent {
|
|
|
282
293
|
}
|
|
283
294
|
return parts.join('\n\n');
|
|
284
295
|
}
|
|
296
|
+
/** Build the JSON request body for chat completions, with prompt caching for supported models */
|
|
297
|
+
buildRequestBody(stream) {
|
|
298
|
+
const body = {
|
|
299
|
+
model: this.model,
|
|
300
|
+
messages: [{ role: 'system', content: this.systemPrompt }, ...this.messages],
|
|
301
|
+
tools: Array.from(this.tools.values()).map(t => ({ type: t.type, function: t.function })),
|
|
302
|
+
tool_choice: 'auto',
|
|
303
|
+
};
|
|
304
|
+
if (stream) {
|
|
305
|
+
body.stream = true;
|
|
306
|
+
body.stream_options = { include_usage: true };
|
|
307
|
+
}
|
|
308
|
+
// Enable prompt caching for Anthropic models (top-level cache_control)
|
|
309
|
+
if (this.model.startsWith('anthropic/') || this.model.includes('claude')) {
|
|
310
|
+
body.cache_control = { type: 'ephemeral' };
|
|
311
|
+
}
|
|
312
|
+
return body;
|
|
313
|
+
}
|
|
285
314
|
async activateSkill(name) {
|
|
286
315
|
const skill = this.allSkills.find(s => s.name === name);
|
|
287
316
|
if (!skill)
|
|
@@ -368,7 +397,7 @@ export class Agent {
|
|
|
368
397
|
stopSpinner();
|
|
369
398
|
}
|
|
370
399
|
}
|
|
371
|
-
async chat(content) {
|
|
400
|
+
async chat(content, signal) {
|
|
372
401
|
const userMessage = { role: 'user', content };
|
|
373
402
|
this.messages.push(userMessage);
|
|
374
403
|
appendHistory(userMessage, this.cwd);
|
|
@@ -377,6 +406,10 @@ export class Agent {
|
|
|
377
406
|
this.messages = this.messages.slice(-MAX_MESSAGES);
|
|
378
407
|
}
|
|
379
408
|
for (let i = 0; i < this.maxIterations; i++) {
|
|
409
|
+
if (signal?.aborted) {
|
|
410
|
+
this.messages.push({ role: 'assistant', content: '[interrupted by user]' });
|
|
411
|
+
return '[interrupted by user]';
|
|
412
|
+
}
|
|
380
413
|
const iterLabel = this.maxIterations > 1 ? ` [${i + 1}/${this.maxIterations}]` : '';
|
|
381
414
|
const stopSpinner = startSpinner(`thinking${iterLabel}`);
|
|
382
415
|
let msg;
|
|
@@ -384,12 +417,8 @@ export class Agent {
|
|
|
384
417
|
const res = await fetch(`${this.baseURL}/chat/completions`, {
|
|
385
418
|
method: 'POST',
|
|
386
419
|
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${this.apiKey}` },
|
|
387
|
-
body: JSON.stringify(
|
|
388
|
-
|
|
389
|
-
messages: [{ role: 'system', content: this.systemPrompt }, ...this.messages],
|
|
390
|
-
tools: Array.from(this.tools.values()).map(t => ({ type: t.type, function: t.function })),
|
|
391
|
-
tool_choice: 'auto'
|
|
392
|
-
})
|
|
420
|
+
body: JSON.stringify(this.buildRequestBody(false)),
|
|
421
|
+
signal
|
|
393
422
|
});
|
|
394
423
|
if (!res.ok)
|
|
395
424
|
throw new Error(`API ${res.status}: ${await res.text()}`);
|
|
@@ -431,8 +460,8 @@ export class Agent {
|
|
|
431
460
|
}
|
|
432
461
|
}
|
|
433
462
|
this.messages.push(msg);
|
|
463
|
+
appendHistory(msg, this.cwd);
|
|
434
464
|
if (!msg.tool_calls?.length) {
|
|
435
|
-
appendHistory({ role: 'assistant', content: msg.content || '' }, this.cwd);
|
|
436
465
|
return msg.content || '';
|
|
437
466
|
}
|
|
438
467
|
// Execute tool calls in parallel
|
|
@@ -477,11 +506,12 @@ export class Agent {
|
|
|
477
506
|
const results = await Promise.all(toolPromises);
|
|
478
507
|
for (const { call, content } of results) {
|
|
479
508
|
this.messages.push({ role: 'tool', tool_call_id: call.id, content });
|
|
509
|
+
appendHistory({ role: 'tool', tool_call_id: call.id, content }, this.cwd);
|
|
480
510
|
}
|
|
481
511
|
}
|
|
482
512
|
return MAX_ITERATIONS_REACHED;
|
|
483
513
|
}
|
|
484
|
-
async *chatStream(content) {
|
|
514
|
+
async *chatStream(content, signal) {
|
|
485
515
|
const userMessage = { role: 'user', content };
|
|
486
516
|
this.messages.push(userMessage);
|
|
487
517
|
appendHistory(userMessage, this.cwd);
|
|
@@ -489,6 +519,12 @@ export class Agent {
|
|
|
489
519
|
this.messages = this.messages.slice(-MAX_MESSAGES);
|
|
490
520
|
}
|
|
491
521
|
for (let i = 0; i < this.maxIterations; i++) {
|
|
522
|
+
// ── Abort check: top of iteration ──
|
|
523
|
+
if (signal?.aborted) {
|
|
524
|
+
this.messages.push({ role: 'assistant', content: '[interrupted by user]' });
|
|
525
|
+
yield { type: 'interrupted' };
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
492
528
|
const iterLabel = this.maxIterations > 1 ? ` [${i + 1}/${this.maxIterations}]` : '';
|
|
493
529
|
yield { type: 'thinking', content: `thinking${iterLabel}` };
|
|
494
530
|
// Compact if needed
|
|
@@ -513,17 +549,24 @@ export class Agent {
|
|
|
513
549
|
this.compactionInProgress = false;
|
|
514
550
|
}
|
|
515
551
|
}
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
552
|
+
// ── API call with abort signal ──
|
|
553
|
+
let res;
|
|
554
|
+
try {
|
|
555
|
+
res = await fetch(`${this.baseURL}/chat/completions`, {
|
|
556
|
+
method: 'POST',
|
|
557
|
+
headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${this.apiKey}` },
|
|
558
|
+
body: JSON.stringify(this.buildRequestBody(true)),
|
|
559
|
+
signal
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
catch (e) {
|
|
563
|
+
if (e instanceof DOMException && e.name === 'AbortError') {
|
|
564
|
+
this.messages.push({ role: 'assistant', content: '[interrupted by user]' });
|
|
565
|
+
yield { type: 'interrupted' };
|
|
566
|
+
return;
|
|
567
|
+
}
|
|
568
|
+
throw e;
|
|
569
|
+
}
|
|
527
570
|
if (!res.ok)
|
|
528
571
|
throw new Error(`API ${res.status}: ${await res.text()}`);
|
|
529
572
|
if (!res.body)
|
|
@@ -532,62 +575,89 @@ export class Agent {
|
|
|
532
575
|
let assistantContent = '';
|
|
533
576
|
const toolCalls = new Map();
|
|
534
577
|
let usage = null;
|
|
578
|
+
let streamAborted = false;
|
|
535
579
|
const reader = res.body.getReader();
|
|
536
580
|
const decoder = new TextDecoder();
|
|
537
581
|
let buffer = '';
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
const lines = buffer.split('\n');
|
|
544
|
-
buffer = lines.pop() || '';
|
|
545
|
-
for (const line of lines) {
|
|
546
|
-
if (!line.startsWith('data: '))
|
|
547
|
-
continue;
|
|
548
|
-
const data = line.slice(6).trim();
|
|
549
|
-
if (data === '[DONE]')
|
|
550
|
-
continue;
|
|
551
|
-
let parsed;
|
|
552
|
-
try {
|
|
553
|
-
parsed = JSON.parse(data);
|
|
554
|
-
}
|
|
555
|
-
catch {
|
|
556
|
-
continue;
|
|
582
|
+
try {
|
|
583
|
+
while (true) {
|
|
584
|
+
if (signal?.aborted) {
|
|
585
|
+
streamAborted = true;
|
|
586
|
+
break;
|
|
557
587
|
}
|
|
558
|
-
const
|
|
559
|
-
if (
|
|
588
|
+
const { done, value } = await reader.read();
|
|
589
|
+
if (done)
|
|
590
|
+
break;
|
|
591
|
+
buffer += decoder.decode(value, { stream: true });
|
|
592
|
+
const lines = buffer.split('\n');
|
|
593
|
+
buffer = lines.pop() || '';
|
|
594
|
+
for (const line of lines) {
|
|
595
|
+
if (!line.startsWith('data: '))
|
|
596
|
+
continue;
|
|
597
|
+
const data = line.slice(6).trim();
|
|
598
|
+
if (data === '[DONE]')
|
|
599
|
+
continue;
|
|
600
|
+
let parsed;
|
|
601
|
+
try {
|
|
602
|
+
parsed = JSON.parse(data);
|
|
603
|
+
}
|
|
604
|
+
catch {
|
|
605
|
+
continue;
|
|
606
|
+
}
|
|
607
|
+
// Capture usage from any chunk that has it (may coexist with delta)
|
|
560
608
|
if (parsed.usage)
|
|
561
609
|
usage = parsed.usage;
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
// Tool calls (streamed incrementally)
|
|
570
|
-
if (delta.tool_calls) {
|
|
571
|
-
// Signal spinner on first tool_call delta so the user sees activity
|
|
572
|
-
if (toolCalls.size === 0) {
|
|
573
|
-
yield { type: 'thinking', content: 'running tools' };
|
|
610
|
+
const delta = parsed.choices?.[0]?.delta;
|
|
611
|
+
if (!delta)
|
|
612
|
+
continue;
|
|
613
|
+
// Text content
|
|
614
|
+
if (delta.content) {
|
|
615
|
+
assistantContent += delta.content;
|
|
616
|
+
yield { type: 'text', content: delta.content };
|
|
574
617
|
}
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
618
|
+
// Tool calls (streamed incrementally)
|
|
619
|
+
if (delta.tool_calls) {
|
|
620
|
+
for (const tc of delta.tool_calls) {
|
|
621
|
+
const idx = tc.index ?? 0;
|
|
622
|
+
if (!toolCalls.has(idx)) {
|
|
623
|
+
toolCalls.set(idx, { id: tc.id || '', name: tc.function?.name || '', arguments: '' });
|
|
624
|
+
}
|
|
625
|
+
const entry = toolCalls.get(idx);
|
|
626
|
+
if (tc.id)
|
|
627
|
+
entry.id = tc.id;
|
|
628
|
+
if (tc.function?.name) {
|
|
629
|
+
entry.name = tc.function.name;
|
|
630
|
+
// Show tool names as they arrive (replaces spinner in real-time)
|
|
631
|
+
const names = [...toolCalls.values()].map(t => t.name).filter(Boolean);
|
|
632
|
+
yield { type: 'thinking', content: `preparing ${names.join(', ')}` };
|
|
633
|
+
}
|
|
634
|
+
if (tc.function?.arguments)
|
|
635
|
+
entry.arguments += tc.function.arguments;
|
|
579
636
|
}
|
|
580
|
-
const entry = toolCalls.get(idx);
|
|
581
|
-
if (tc.id)
|
|
582
|
-
entry.id = tc.id;
|
|
583
|
-
if (tc.function?.name)
|
|
584
|
-
entry.name = tc.function.name;
|
|
585
|
-
if (tc.function?.arguments)
|
|
586
|
-
entry.arguments += tc.function.arguments;
|
|
587
637
|
}
|
|
588
638
|
}
|
|
589
639
|
}
|
|
590
640
|
}
|
|
641
|
+
catch (e) {
|
|
642
|
+
if (e instanceof DOMException && e.name === 'AbortError') {
|
|
643
|
+
streamAborted = true;
|
|
644
|
+
}
|
|
645
|
+
else {
|
|
646
|
+
throw e;
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
finally {
|
|
650
|
+
try {
|
|
651
|
+
reader.cancel();
|
|
652
|
+
}
|
|
653
|
+
catch { /* already closed */ }
|
|
654
|
+
}
|
|
655
|
+
// If aborted during streaming, discard partial message
|
|
656
|
+
if (streamAborted) {
|
|
657
|
+
this.messages.push({ role: 'assistant', content: '[interrupted by user]' });
|
|
658
|
+
yield { type: 'interrupted' };
|
|
659
|
+
return;
|
|
660
|
+
}
|
|
591
661
|
if (usage)
|
|
592
662
|
this.contextTracker.update(usage);
|
|
593
663
|
// Build assistant message
|
|
@@ -600,8 +670,8 @@ export class Agent {
|
|
|
600
670
|
}));
|
|
601
671
|
}
|
|
602
672
|
this.messages.push(msg);
|
|
673
|
+
appendHistory(msg, this.cwd);
|
|
603
674
|
if (!msg.tool_calls?.length) {
|
|
604
|
-
appendHistory({ role: 'assistant', content: assistantContent }, this.cwd);
|
|
605
675
|
yield { type: 'done', content: assistantContent };
|
|
606
676
|
return;
|
|
607
677
|
}
|
|
@@ -616,8 +686,10 @@ export class Agent {
|
|
|
616
686
|
const summary = args.command ?? args.action ?? call.function.name;
|
|
617
687
|
yield { type: 'tool_start', toolName: call.function.name, toolCallId: call.id, content: summary };
|
|
618
688
|
}
|
|
619
|
-
// Execute tool calls
|
|
689
|
+
// Execute tool calls — yield results as they complete (not Promise.all)
|
|
620
690
|
const execPromises = msg.tool_calls.map(async (call) => {
|
|
691
|
+
if (signal?.aborted)
|
|
692
|
+
return { call, content: '[cancelled by user]', isError: true };
|
|
621
693
|
const tool = this.tools.get(call.function.name);
|
|
622
694
|
if (!tool)
|
|
623
695
|
return { call, content: `Error: unknown tool "${call.function.name}"`, isError: true };
|
|
@@ -645,15 +717,81 @@ export class Agent {
|
|
|
645
717
|
return { call, content: `Tool error: ${error}`, isError: true };
|
|
646
718
|
}
|
|
647
719
|
});
|
|
648
|
-
|
|
649
|
-
|
|
720
|
+
// Yield results as they resolve (not waiting for all)
|
|
721
|
+
const completedCallIds = new Set();
|
|
722
|
+
for await (const r of raceAll(execPromises)) {
|
|
723
|
+
completedCallIds.add(r.call.id);
|
|
650
724
|
this.messages.push({ role: 'tool', tool_call_id: r.call.id, content: r.content });
|
|
725
|
+
appendHistory({ role: 'tool', tool_call_id: r.call.id, content: r.content }, this.cwd);
|
|
651
726
|
yield { type: 'tool_end', toolName: r.call.function.name, toolCallId: r.call.id, content: r.content, success: !r.isError };
|
|
727
|
+
// Check abort after each tool completes
|
|
728
|
+
if (signal?.aborted)
|
|
729
|
+
break;
|
|
730
|
+
}
|
|
731
|
+
// Fill placeholders for any tool calls that didn't complete (API requires all tool_call_ids)
|
|
732
|
+
if (signal?.aborted && msg.tool_calls) {
|
|
733
|
+
for (const call of msg.tool_calls) {
|
|
734
|
+
if (!completedCallIds.has(call.id)) {
|
|
735
|
+
const placeholder = { role: 'tool', tool_call_id: call.id, content: '[cancelled by user]' };
|
|
736
|
+
this.messages.push(placeholder);
|
|
737
|
+
appendHistory(placeholder, this.cwd);
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
this.messages.push({ role: 'assistant', content: '[interrupted by user]' });
|
|
741
|
+
yield { type: 'interrupted', content: `${completedCallIds.size} completed, ${msg.tool_calls.length - completedCallIds.size} cancelled` };
|
|
742
|
+
return;
|
|
652
743
|
}
|
|
653
744
|
}
|
|
654
745
|
yield { type: 'max_iterations' };
|
|
655
746
|
}
|
|
656
747
|
// ── Public API ─────────────────────────────────────────────────────────────
|
|
748
|
+
/** Return the char-size breakdown of every context component */
|
|
749
|
+
getContextBreakdown() {
|
|
750
|
+
const parts = [];
|
|
751
|
+
parts.push({ label: 'System prompt', chars: this.baseSystemPrompt.length });
|
|
752
|
+
parts.push({ label: 'Environment', chars: getEnvironmentContext(this.cwd).length });
|
|
753
|
+
const listing = this.getProjectListing();
|
|
754
|
+
if (listing)
|
|
755
|
+
parts.push({ label: 'Project files', chars: listing.length });
|
|
756
|
+
// cachedContext contains global memory + project memory + plan, but we want them separate
|
|
757
|
+
const globalMem = loadGlobalMemory(this.cwd);
|
|
758
|
+
const projectMem = loadProjectMemory(this.cwd);
|
|
759
|
+
const plan = loadPlan(this.cwd);
|
|
760
|
+
if (globalMem)
|
|
761
|
+
parts.push({ label: 'Global memory', chars: globalMem.length + '<global-memory>\n\n</global-memory>'.length });
|
|
762
|
+
if (projectMem)
|
|
763
|
+
parts.push({ label: 'Project memory', chars: projectMem.length + '<project-memory>\n\n</project-memory>'.length });
|
|
764
|
+
if (plan)
|
|
765
|
+
parts.push({ label: 'Plan', chars: plan.length + 50 /* tags + header */ });
|
|
766
|
+
if (this.cachedCatalog)
|
|
767
|
+
parts.push({ label: 'Skill catalog', chars: this.cachedCatalog.length });
|
|
768
|
+
if (this.cachedAlwaysOn)
|
|
769
|
+
parts.push({ label: 'Always-on skills', chars: this.cachedAlwaysOn.length });
|
|
770
|
+
if (this.activeSkillContent.length > 0) {
|
|
771
|
+
parts.push({ label: 'Active skills', chars: this.activeSkillContent.join('\n\n').length });
|
|
772
|
+
}
|
|
773
|
+
// Tool definitions (sent in every API call as the tools array)
|
|
774
|
+
const builtinChars = Array.from(this.tools.values())
|
|
775
|
+
.filter(t => this.builtinToolNames.has(t.function.name))
|
|
776
|
+
.reduce((sum, t) => sum + JSON.stringify({ type: t.type, function: t.function }).length, 0);
|
|
777
|
+
const customChars = Array.from(this.tools.values())
|
|
778
|
+
.filter(t => !this.builtinToolNames.has(t.function.name))
|
|
779
|
+
.reduce((sum, t) => sum + JSON.stringify({ type: t.type, function: t.function }).length, 0);
|
|
780
|
+
if (builtinChars > 0)
|
|
781
|
+
parts.push({ label: 'Tool definitions', chars: builtinChars });
|
|
782
|
+
if (customChars > 0)
|
|
783
|
+
parts.push({ label: 'Custom tools', chars: customChars });
|
|
784
|
+
// Messages (conversation history)
|
|
785
|
+
const msgChars = this.messages.reduce((sum, m) => {
|
|
786
|
+
let size = (m.content || '').length;
|
|
787
|
+
if (m.tool_calls)
|
|
788
|
+
size += JSON.stringify(m.tool_calls).length;
|
|
789
|
+
return sum + size;
|
|
790
|
+
}, 0);
|
|
791
|
+
if (msgChars > 0)
|
|
792
|
+
parts.push({ label: 'Messages', chars: msgChars });
|
|
793
|
+
return parts;
|
|
794
|
+
}
|
|
657
795
|
getTools() {
|
|
658
796
|
return Array.from(this.tools.values()).map(t => ({ name: t.function.name, description: t.function.description }));
|
|
659
797
|
}
|
|
@@ -708,5 +846,9 @@ export class Agent {
|
|
|
708
846
|
getContextDetails() { return this.contextTracker.formatDetailed(); }
|
|
709
847
|
getContextTracker() { return this.contextTracker; }
|
|
710
848
|
getSystemPromptSize() { return this.systemPrompt.length; }
|
|
849
|
+
/** Total estimated chars across all context components (system prompt + tools + messages) */
|
|
850
|
+
getTotalContextChars() {
|
|
851
|
+
return this.getContextBreakdown().reduce((sum, p) => sum + p.chars, 0);
|
|
852
|
+
}
|
|
711
853
|
}
|
|
712
854
|
//# sourceMappingURL=agent.js.map
|