@trim21/personal-pi-extensions 0.0.280 → 0.0.281
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 +36 -4
package/package.json
CHANGED
package/src/spawn-agent.ts
CHANGED
|
@@ -12,7 +12,9 @@
|
|
|
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`), so a burst of tool calls does
|
|
17
|
+
* not flood the window; any text block starts a new line.
|
|
16
18
|
*
|
|
17
19
|
* Security default: without an explicit `tools:` in the frontmatter, the
|
|
18
20
|
* subagent only gets read-only tools (read/grep/find/ls) — no bash/write/edit.
|
|
@@ -345,12 +347,44 @@ export async function runAgent(
|
|
|
345
347
|
});
|
|
346
348
|
|
|
347
349
|
let logLines: string[] = [];
|
|
350
|
+
// 工具调用行合并:连续的 tool_execution_start 事件合并在同一 `tool:` 行
|
|
351
|
+
// (如 `tool: read x 2, glob`),相同工具名连续出现时计为 `name x N`,
|
|
352
|
+
// 不同名按调用顺序罗列;任何非工具行都会打断合并。
|
|
353
|
+
let toolLineSegments: string[] = [];
|
|
354
|
+
let toolLine: { name: string; count: number } | undefined;
|
|
355
|
+
|
|
356
|
+
const toolSegment = (name: string, count: number) => (count > 1 ? `${name} x ${count}` : name);
|
|
348
357
|
|
|
349
358
|
const pushLogLine = (line: string) => {
|
|
350
359
|
logLines.push(line);
|
|
351
360
|
if (logLines.length > MAX_PROGRESS_LINES) {
|
|
352
361
|
logLines = logLines.slice(-MAX_PROGRESS_LINES);
|
|
353
362
|
}
|
|
363
|
+
// 任何非工具行都会打断工具调用合并,下一批调用另起一行。
|
|
364
|
+
toolLine = undefined;
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
const appendToolLine = (name: string) => {
|
|
368
|
+
const firstInBatch = toolLine === undefined;
|
|
369
|
+
if (toolLine === undefined) {
|
|
370
|
+
toolLineSegments = [];
|
|
371
|
+
toolLine = { name, count: 1 };
|
|
372
|
+
} else if (toolLine.name === name) {
|
|
373
|
+
toolLine.count++;
|
|
374
|
+
} else {
|
|
375
|
+
toolLineSegments.push(toolSegment(toolLine.name, toolLine.count));
|
|
376
|
+
toolLine = { name, count: 1 };
|
|
377
|
+
}
|
|
378
|
+
const line = `tool: ${[...toolLineSegments, toolSegment(toolLine.name, toolLine.count)].join(", ")}`;
|
|
379
|
+
if (firstInBatch) {
|
|
380
|
+
logLines.push(line);
|
|
381
|
+
if (logLines.length > MAX_PROGRESS_LINES) {
|
|
382
|
+
logLines = logLines.slice(-MAX_PROGRESS_LINES);
|
|
383
|
+
}
|
|
384
|
+
} else {
|
|
385
|
+
logLines[logLines.length - 1] = line;
|
|
386
|
+
}
|
|
387
|
+
emitUpdate();
|
|
354
388
|
};
|
|
355
389
|
|
|
356
390
|
const emitUpdate = () => {
|
|
@@ -431,9 +465,7 @@ export async function runAgent(
|
|
|
431
465
|
break;
|
|
432
466
|
}
|
|
433
467
|
case "tool_execution_start": {
|
|
434
|
-
|
|
435
|
-
emitUpdate();
|
|
436
|
-
|
|
468
|
+
appendToolLine(event.toolName);
|
|
437
469
|
break;
|
|
438
470
|
}
|
|
439
471
|
case "message_end": {
|