@trim21/personal-pi-extensions 0.0.281 → 0.0.284
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 +21 -4
package/package.json
CHANGED
package/src/spawn-agent.ts
CHANGED
|
@@ -13,8 +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`)
|
|
17
|
-
*
|
|
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.
|
|
18
20
|
*
|
|
19
21
|
* Security default: without an explicit `tools:` in the frontmatter, the
|
|
20
22
|
* subagent only gets read-only tools (read/grep/find/ls) — no bash/write/edit.
|
|
@@ -50,6 +52,8 @@ const MAX_OUTPUT_BYTES = 50 * 1024;
|
|
|
50
52
|
const DEFAULT_TOOLS = ["read", "grep", "find", "ls"];
|
|
51
53
|
/** Progress log keeps only the most recent lines (rolling window). */
|
|
52
54
|
const MAX_PROGRESS_LINES = 5;
|
|
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;
|
|
53
57
|
|
|
54
58
|
/**
|
|
55
59
|
* Tool → extension override map: when a subagent's frontmatter enables a
|
|
@@ -128,6 +132,18 @@ function getFinalOutput(messages: AgentMessage[]): string {
|
|
|
128
132
|
return "";
|
|
129
133
|
}
|
|
130
134
|
|
|
135
|
+
/**
|
|
136
|
+
* Fold over-long progress line content: keep the first/last 7 chars joined by
|
|
137
|
+
* a single `…` ellipsis, so the folded line never exceeds
|
|
138
|
+
* `MAX_PROGRESS_CHARS_PER_LINE` chars (7 + 1 + 7 = 15). Shorter text is
|
|
139
|
+
* returned as-is.
|
|
140
|
+
*/
|
|
141
|
+
function foldProgressLine(text: string): string {
|
|
142
|
+
if (text.length <= MAX_PROGRESS_CHARS_PER_LINE) return text;
|
|
143
|
+
const keep = Math.floor((MAX_PROGRESS_CHARS_PER_LINE - 1) / 2);
|
|
144
|
+
return `${text.slice(0, keep)}…${text.slice(-keep)}`;
|
|
145
|
+
}
|
|
146
|
+
|
|
131
147
|
function formatTokens(count: number): string {
|
|
132
148
|
if (count < 1000) return count.toString();
|
|
133
149
|
if (count < 10_000) return `${(count / 1000).toFixed(1)}k`;
|
|
@@ -375,7 +391,8 @@ export async function runAgent(
|
|
|
375
391
|
toolLineSegments.push(toolSegment(toolLine.name, toolLine.count));
|
|
376
392
|
toolLine = { name, count: 1 };
|
|
377
393
|
}
|
|
378
|
-
const
|
|
394
|
+
const parts = [...toolLineSegments, toolSegment(toolLine.name, toolLine.count)].join(", ");
|
|
395
|
+
const line = `tool: ${foldProgressLine(parts)}`;
|
|
379
396
|
if (firstInBatch) {
|
|
380
397
|
logLines.push(line);
|
|
381
398
|
if (logLines.length > MAX_PROGRESS_LINES) {
|
|
@@ -458,7 +475,7 @@ export async function runAgent(
|
|
|
458
475
|
// `text:` log line. Deltas/thinking are intentionally not logged.
|
|
459
476
|
const delta = event.assistantMessageEvent;
|
|
460
477
|
if (delta.type === "text_end") {
|
|
461
|
-
pushLogLine(`text: ${delta.content}`);
|
|
478
|
+
pushLogLine(`text: ${foldProgressLine(delta.content)}`);
|
|
462
479
|
emitUpdate();
|
|
463
480
|
}
|
|
464
481
|
|