@trim21/personal-pi-extensions 0.0.280 → 0.0.283
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 +41 -5
package/package.json
CHANGED
package/src/spawn-agent.ts
CHANGED
|
@@ -12,7 +12,10 @@
|
|
|
12
12
|
* `onUpdate`, the same channel the built-in bash tool uses for live output.
|
|
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
|
-
* `MAX_PROGRESS_LINES` lines.
|
|
15
|
+
* `MAX_PROGRESS_LINES` lines. Consecutive tool calls are merged into a
|
|
16
|
+
* single `tool:` line (`read x 2, glob`) and line content is capped at
|
|
17
|
+
* `MAX_PROGRESS_CHARS_PER_LINE` characters, so a burst of tool calls or a long
|
|
18
|
+
* text block does not flood the window; any text block starts a new line.
|
|
16
19
|
*
|
|
17
20
|
* Security default: without an explicit `tools:` in the frontmatter, the
|
|
18
21
|
* subagent only gets read-only tools (read/grep/find/ls) — no bash/write/edit.
|
|
@@ -48,6 +51,8 @@ const MAX_OUTPUT_BYTES = 50 * 1024;
|
|
|
48
51
|
const DEFAULT_TOOLS = ["read", "grep", "find", "ls"];
|
|
49
52
|
/** Progress log keeps only the most recent lines (rolling window). */
|
|
50
53
|
const MAX_PROGRESS_LINES = 5;
|
|
54
|
+
/** Progress line content (without the `tool:` / `text:` prefix) is capped at 50 chars. */
|
|
55
|
+
const MAX_PROGRESS_CHARS_PER_LINE = 50;
|
|
51
56
|
|
|
52
57
|
/**
|
|
53
58
|
* Tool → extension override map: when a subagent's frontmatter enables a
|
|
@@ -345,12 +350,45 @@ export async function runAgent(
|
|
|
345
350
|
});
|
|
346
351
|
|
|
347
352
|
let logLines: string[] = [];
|
|
353
|
+
// 工具调用行合并:连续的 tool_execution_start 事件合并在同一 `tool:` 行
|
|
354
|
+
// (如 `tool: read x 2, glob`),相同工具名连续出现时计为 `name x N`,
|
|
355
|
+
// 不同名按调用顺序罗列;任何非工具行都会打断合并。
|
|
356
|
+
let toolLineSegments: string[] = [];
|
|
357
|
+
let toolLine: { name: string; count: number } | undefined;
|
|
358
|
+
|
|
359
|
+
const toolSegment = (name: string, count: number) => (count > 1 ? `${name} x ${count}` : name);
|
|
348
360
|
|
|
349
361
|
const pushLogLine = (line: string) => {
|
|
350
362
|
logLines.push(line);
|
|
351
363
|
if (logLines.length > MAX_PROGRESS_LINES) {
|
|
352
364
|
logLines = logLines.slice(-MAX_PROGRESS_LINES);
|
|
353
365
|
}
|
|
366
|
+
// 任何非工具行都会打断工具调用合并,下一批调用另起一行。
|
|
367
|
+
toolLine = undefined;
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
const appendToolLine = (name: string) => {
|
|
371
|
+
const firstInBatch = toolLine === undefined;
|
|
372
|
+
if (toolLine === undefined) {
|
|
373
|
+
toolLineSegments = [];
|
|
374
|
+
toolLine = { name, count: 1 };
|
|
375
|
+
} else if (toolLine.name === name) {
|
|
376
|
+
toolLine.count++;
|
|
377
|
+
} else {
|
|
378
|
+
toolLineSegments.push(toolSegment(toolLine.name, toolLine.count));
|
|
379
|
+
toolLine = { name, count: 1 };
|
|
380
|
+
}
|
|
381
|
+
const parts = [...toolLineSegments, toolSegment(toolLine.name, toolLine.count)].join(", ");
|
|
382
|
+
const line = `tool: ${parts.slice(0, MAX_PROGRESS_CHARS_PER_LINE)}`;
|
|
383
|
+
if (firstInBatch) {
|
|
384
|
+
logLines.push(line);
|
|
385
|
+
if (logLines.length > MAX_PROGRESS_LINES) {
|
|
386
|
+
logLines = logLines.slice(-MAX_PROGRESS_LINES);
|
|
387
|
+
}
|
|
388
|
+
} else {
|
|
389
|
+
logLines[logLines.length - 1] = line;
|
|
390
|
+
}
|
|
391
|
+
emitUpdate();
|
|
354
392
|
};
|
|
355
393
|
|
|
356
394
|
const emitUpdate = () => {
|
|
@@ -424,16 +462,14 @@ export async function runAgent(
|
|
|
424
462
|
// `text:` log line. Deltas/thinking are intentionally not logged.
|
|
425
463
|
const delta = event.assistantMessageEvent;
|
|
426
464
|
if (delta.type === "text_end") {
|
|
427
|
-
pushLogLine(`text: ${delta.content}`);
|
|
465
|
+
pushLogLine(`text: ${delta.content.slice(0, MAX_PROGRESS_CHARS_PER_LINE)}`);
|
|
428
466
|
emitUpdate();
|
|
429
467
|
}
|
|
430
468
|
|
|
431
469
|
break;
|
|
432
470
|
}
|
|
433
471
|
case "tool_execution_start": {
|
|
434
|
-
|
|
435
|
-
emitUpdate();
|
|
436
|
-
|
|
472
|
+
appendToolLine(event.toolName);
|
|
437
473
|
break;
|
|
438
474
|
}
|
|
439
475
|
case "message_end": {
|