@trim21/personal-pi-extensions 0.1.646 → 0.1.647
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 -7
package/package.json
CHANGED
package/src/spawn-agent.ts
CHANGED
|
@@ -10,7 +10,11 @@
|
|
|
10
10
|
* pass to the tool. Execution
|
|
11
11
|
* is blocking: the tool awaits the subagent session until the turn settles and
|
|
12
12
|
* returns its final output to the parent model. Progress is streamed through
|
|
13
|
-
* `onUpdate`, the same channel the built-in bash tool uses for live output
|
|
13
|
+
* `onUpdate`, the same channel the built-in bash tool uses for live output, and
|
|
14
|
+
* is throttled like the bash tool: pushes are capped at one per
|
|
15
|
+
* `PROGRESS_UPDATE_THROTTLE_MS` so a burst of thinking deltas does not
|
|
16
|
+
* re-render the panel per chunk, and the trailing push still delivers the
|
|
17
|
+
* latest state at the end of the window.
|
|
14
18
|
* Progress is a rolling log: `tool: <name>` lines for tool calls and
|
|
15
19
|
* `text: <content>` lines for completed text blocks, keeping only the last few
|
|
16
20
|
* lines (`MAX_PROGRESS_LINES` in spawn-agent-progress.ts). Consecutive tool calls are merged into a
|
|
@@ -64,6 +68,7 @@ import {
|
|
|
64
68
|
SettingsManager,
|
|
65
69
|
truncateTail,
|
|
66
70
|
} from "@earendil-works/pi-coding-agent";
|
|
71
|
+
import { throttle } from "lodash-es";
|
|
67
72
|
import { Type } from "typebox";
|
|
68
73
|
|
|
69
74
|
import { type BwrapConfig, completeBwrapConfig } from "./bwrap/core.js";
|
|
@@ -87,6 +92,11 @@ import { createSubagentProgress, formatTokens } from "./spawn-agent-progress.js"
|
|
|
87
92
|
const MAX_OUTPUT_BYTES = 50 * 1024;
|
|
88
93
|
/** Read-only toolset used when an agent does not declare `tools`. */
|
|
89
94
|
const DEFAULT_TOOLS = ["read", "grep", "find", "ls"];
|
|
95
|
+
/**
|
|
96
|
+
* 进度推送的最小间隔(对齐 bash 工具的进度限流):逐 chunk 的 thinking 增量
|
|
97
|
+
* 会让面板每个 chunk 都重渲染一次。配合 trailing,窗口结束时的最新状态仍会送达。
|
|
98
|
+
*/
|
|
99
|
+
export const PROGRESS_UPDATE_THROTTLE_MS = 100;
|
|
90
100
|
/**
|
|
91
101
|
* 子代理未在 frontmatter 声明 `sandbox` 时 bash 使用的固定沙箱:文件系统只读 + 断网。
|
|
92
102
|
* 与主会话(跟随用户 sandbox.json)相反,子代理不继承用户配置——为交互会话放宽的
|
|
@@ -412,12 +422,16 @@ export async function runAgent(
|
|
|
412
422
|
|
|
413
423
|
const progress = createSubagentProgress({ name: result.agent });
|
|
414
424
|
|
|
415
|
-
const emitUpdate = (
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
425
|
+
const emitUpdate = throttle(
|
|
426
|
+
() => {
|
|
427
|
+
onUpdate?.({
|
|
428
|
+
content: [{ type: "text", text: progress.render(result.usage, result.model) }],
|
|
429
|
+
details: {},
|
|
430
|
+
});
|
|
431
|
+
},
|
|
432
|
+
PROGRESS_UPDATE_THROTTLE_MS,
|
|
433
|
+
{ trailing: true },
|
|
434
|
+
);
|
|
421
435
|
|
|
422
436
|
const handleEvent = (event: AgentSessionEvent) => {
|
|
423
437
|
switch (event.type) {
|