@trim21/personal-pi-extensions 0.0.283 → 0.0.285
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/src/spawn-agent.ts +20 -17
package/package.json
CHANGED
package/src/spawn-agent.ts
CHANGED
|
@@ -13,9 +13,10 @@
|
|
|
13
13
|
* Progress is a rolling log: `tool: <name>` lines for tool calls and
|
|
14
14
|
* `text: <content>` lines for completed text blocks, keeping the last
|
|
15
15
|
* `MAX_PROGRESS_LINES` lines. Consecutive tool calls are merged into a
|
|
16
|
-
* single `tool:` line (`read x 2, glob`) and line content is
|
|
17
|
-
*
|
|
18
|
-
* text block does not flood the window; any text block starts a
|
|
16
|
+
* single `tool:` line (`read x 2, glob`) and over-long line content is
|
|
17
|
+
* folded to the first/last 7 chars joined by `…`, so a burst of tool calls
|
|
18
|
+
* or a long text block does not flood the window; any text block starts a
|
|
19
|
+
* new line.
|
|
19
20
|
*
|
|
20
21
|
* Security default: without an explicit `tools:` in the frontmatter, the
|
|
21
22
|
* subagent only gets read-only tools (read/grep/find/ls) — no bash/write/edit.
|
|
@@ -51,8 +52,8 @@ const MAX_OUTPUT_BYTES = 50 * 1024;
|
|
|
51
52
|
const DEFAULT_TOOLS = ["read", "grep", "find", "ls"];
|
|
52
53
|
/** Progress log keeps only the most recent lines (rolling window). */
|
|
53
54
|
const MAX_PROGRESS_LINES = 5;
|
|
54
|
-
/** Progress line content (without the `tool:` / `text:` prefix) is capped at
|
|
55
|
-
const MAX_PROGRESS_CHARS_PER_LINE =
|
|
55
|
+
/** Progress line content (without the `tool:` / `text:` prefix) is capped at 15 chars; longer text is folded to the first/last 7 chars joined by `…`. */
|
|
56
|
+
const MAX_PROGRESS_CHARS_PER_LINE = 15;
|
|
56
57
|
|
|
57
58
|
/**
|
|
58
59
|
* Tool → extension override map: when a subagent's frontmatter enables a
|
|
@@ -98,8 +99,6 @@ const spawnAgentSchema = Type.Object({
|
|
|
98
99
|
interface UsageStats {
|
|
99
100
|
input: number;
|
|
100
101
|
output: number;
|
|
101
|
-
cacheRead: number;
|
|
102
|
-
cacheWrite: number;
|
|
103
102
|
cost: number;
|
|
104
103
|
contextTokens: number;
|
|
105
104
|
turns: number;
|
|
@@ -131,6 +130,18 @@ function getFinalOutput(messages: AgentMessage[]): string {
|
|
|
131
130
|
return "";
|
|
132
131
|
}
|
|
133
132
|
|
|
133
|
+
/**
|
|
134
|
+
* Fold over-long progress line content: keep the first/last 7 chars joined by
|
|
135
|
+
* a single `…` ellipsis, so the folded line never exceeds
|
|
136
|
+
* `MAX_PROGRESS_CHARS_PER_LINE` chars (7 + 1 + 7 = 15). Shorter text is
|
|
137
|
+
* returned as-is.
|
|
138
|
+
*/
|
|
139
|
+
function foldProgressLine(text: string): string {
|
|
140
|
+
if (text.length <= MAX_PROGRESS_CHARS_PER_LINE) return text;
|
|
141
|
+
const keep = Math.floor((MAX_PROGRESS_CHARS_PER_LINE - 1) / 2);
|
|
142
|
+
return `${text.slice(0, keep)}…${text.slice(-keep)}`;
|
|
143
|
+
}
|
|
144
|
+
|
|
134
145
|
function formatTokens(count: number): string {
|
|
135
146
|
if (count < 1000) return count.toString();
|
|
136
147
|
if (count < 10_000) return `${(count / 1000).toFixed(1)}k`;
|
|
@@ -143,8 +154,6 @@ function formatUsageStats(usage: UsageStats, model?: string): string {
|
|
|
143
154
|
if (usage.turns) parts.push(`${usage.turns} turn${usage.turns > 1 ? "s" : ""}`);
|
|
144
155
|
if (usage.input) parts.push(`↑${formatTokens(usage.input)}`);
|
|
145
156
|
if (usage.output) parts.push(`↓${formatTokens(usage.output)}`);
|
|
146
|
-
if (usage.cacheRead) parts.push(`R${formatTokens(usage.cacheRead)}`);
|
|
147
|
-
if (usage.cacheWrite) parts.push(`W${formatTokens(usage.cacheWrite)}`);
|
|
148
157
|
if (usage.cost) parts.push(`$${usage.cost.toFixed(4)}`);
|
|
149
158
|
if (usage.contextTokens > 0) parts.push(`ctx:${formatTokens(usage.contextTokens)}`);
|
|
150
159
|
if (model) parts.push(model);
|
|
@@ -326,8 +335,6 @@ export async function runAgent(
|
|
|
326
335
|
usage: {
|
|
327
336
|
input: 0,
|
|
328
337
|
output: 0,
|
|
329
|
-
cacheRead: 0,
|
|
330
|
-
cacheWrite: 0,
|
|
331
338
|
cost: 0,
|
|
332
339
|
contextTokens: 0,
|
|
333
340
|
turns: 0,
|
|
@@ -379,7 +386,7 @@ export async function runAgent(
|
|
|
379
386
|
toolLine = { name, count: 1 };
|
|
380
387
|
}
|
|
381
388
|
const parts = [...toolLineSegments, toolSegment(toolLine.name, toolLine.count)].join(", ");
|
|
382
|
-
const line = `tool: ${parts
|
|
389
|
+
const line = `tool: ${foldProgressLine(parts)}`;
|
|
383
390
|
if (firstInBatch) {
|
|
384
391
|
logLines.push(line);
|
|
385
392
|
if (logLines.length > MAX_PROGRESS_LINES) {
|
|
@@ -462,7 +469,7 @@ export async function runAgent(
|
|
|
462
469
|
// `text:` log line. Deltas/thinking are intentionally not logged.
|
|
463
470
|
const delta = event.assistantMessageEvent;
|
|
464
471
|
if (delta.type === "text_end") {
|
|
465
|
-
pushLogLine(`text: ${delta.content
|
|
472
|
+
pushLogLine(`text: ${foldProgressLine(delta.content)}`);
|
|
466
473
|
emitUpdate();
|
|
467
474
|
}
|
|
468
475
|
|
|
@@ -479,8 +486,6 @@ export async function runAgent(
|
|
|
479
486
|
result.usage.turns++;
|
|
480
487
|
result.usage.input += msg.usage.input;
|
|
481
488
|
result.usage.output += msg.usage.output;
|
|
482
|
-
result.usage.cacheRead += msg.usage.cacheRead;
|
|
483
|
-
result.usage.cacheWrite += msg.usage.cacheWrite;
|
|
484
489
|
result.usage.cost += msg.usage.cost.total;
|
|
485
490
|
result.usage.contextTokens = msg.usage.totalTokens;
|
|
486
491
|
if (!result.model) result.model = msg.model;
|
|
@@ -635,8 +640,6 @@ export default function spawnAgent(pi: ExtensionAPI) {
|
|
|
635
640
|
usage: {
|
|
636
641
|
input: 0,
|
|
637
642
|
output: 0,
|
|
638
|
-
cacheRead: 0,
|
|
639
|
-
cacheWrite: 0,
|
|
640
643
|
cost: 0,
|
|
641
644
|
contextTokens: 0,
|
|
642
645
|
turns: 0,
|