pi-web-ui 0.99.0 → 0.101.0

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.
Files changed (109) hide show
  1. package/CHANGELOG.md +90 -1
  2. package/README.md +48 -45
  3. package/README.zh-CN.md +43 -40
  4. package/bin/pi-web-ui.mjs +172 -40
  5. package/dist/server/agent-formatters.js +191 -0
  6. package/dist/server/agent-service-daemon.js +1266 -0
  7. package/dist/server/agent-service.js +9851 -11892
  8. package/dist/server/approval-default-rules.js +158 -0
  9. package/dist/server/approval-rules.js +130 -184
  10. package/dist/server/ask-user-question-tool.js +94 -0
  11. package/dist/server/attachment-store.js +38 -1
  12. package/dist/server/attachments.js +55 -0
  13. package/dist/server/bash-tool.js +83 -0
  14. package/dist/server/bg-servers.js +82 -2
  15. package/dist/server/browser-page-tool.js +207 -0
  16. package/dist/server/claim-files-tool.js +4 -4
  17. package/dist/server/client-id-utils.js +51 -0
  18. package/dist/server/client-state.js +63 -1
  19. package/dist/server/compact-context-tool.js +10 -9
  20. package/dist/server/compaction-markers.js +34 -1
  21. package/dist/server/context-budget-runner.js +43 -0
  22. package/dist/server/conversation-read-tool.js +7 -8
  23. package/dist/server/conversation-touches.js +19 -0
  24. package/dist/server/dangling-tools.js +18 -5
  25. package/dist/server/delegate-mode.js +1 -0
  26. package/dist/server/delegate-task.js +10 -14
  27. package/dist/server/dispatch-domain-handlers.js +631 -0
  28. package/dist/server/dispatch-plugin-handlers.js +300 -0
  29. package/dist/server/dsh/dsh-agent-service.js +125 -13
  30. package/dist/server/edit-soft-tool.js +10 -12
  31. package/dist/server/eval-tool.js +4 -5
  32. package/dist/server/goal-evidence.js +180 -0
  33. package/dist/server/goal-service.js +49 -9
  34. package/dist/server/hashline-engine.js +199 -32
  35. package/dist/server/index.js +212 -944
  36. package/dist/server/left-panel-running.js +115 -0
  37. package/dist/server/load-tools-tool.js +100 -0
  38. package/dist/server/lsp-tool.js +50 -28
  39. package/dist/server/marker-service.js +53 -12
  40. package/dist/server/markers/builtins/action.js +108 -0
  41. package/dist/server/markers/index.js +4 -1
  42. package/dist/server/markers-list-tool.js +34 -0
  43. package/dist/server/market-service.js +277 -0
  44. package/dist/server/mcp-bridge.js +137 -30
  45. package/dist/server/mcp-hot-reload.js +84 -27
  46. package/dist/server/mcp-manager.js +215 -0
  47. package/dist/server/message-entry-resolver.js +32 -0
  48. package/dist/server/orphan-manager.js +44 -0
  49. package/dist/server/patch-remote-catalog.js +28 -10
  50. package/dist/server/patch-tool.js +9 -8
  51. package/dist/server/persona-chain.js +63 -0
  52. package/dist/server/plan-mode.js +9 -6
  53. package/dist/server/plan-update-tool.js +96 -0
  54. package/dist/server/plugin-api-catalog.js +30 -3
  55. package/dist/server/plugin-conversation-view.js +47 -0
  56. package/dist/server/plugin-facilities.js +13 -3
  57. package/dist/server/plugin-ui-slots.js +39 -0
  58. package/dist/server/plugins.js +183 -63
  59. package/dist/server/present-files-tool.js +10 -11
  60. package/dist/server/preset-fields.js +700 -0
  61. package/dist/server/preset-share.js +1179 -0
  62. package/dist/server/process-utils.js +30 -0
  63. package/dist/server/prompt-assembler.js +80 -0
  64. package/dist/server/prompt-composer.js +23 -9
  65. package/dist/server/protocol-version.js +1 -1
  66. package/dist/server/read-tool.js +8 -10
  67. package/dist/server/resolve-global-sdk.js +80 -18
  68. package/dist/server/schedule-agent-tool.js +147 -146
  69. package/dist/server/scm-commitmsg.js +74 -0
  70. package/dist/server/sdk-origin.js +125 -37
  71. package/dist/server/serialize.js +97 -7
  72. package/dist/server/session-branch.js +367 -0
  73. package/dist/server/session-parser.js +235 -0
  74. package/dist/server/session-search.js +158 -0
  75. package/dist/server/settings-service.js +115 -84
  76. package/dist/server/skill-content-filler.js +33 -0
  77. package/dist/server/skill-tool.js +3 -4
  78. package/dist/server/subagent-handoff.js +18 -0
  79. package/dist/server/subagent-helpers.js +88 -0
  80. package/dist/server/subagents.js +15 -22
  81. package/dist/server/terminals.js +171 -91
  82. package/dist/server/tool-approval.js +3 -1
  83. package/dist/server/tool-guards.js +527 -0
  84. package/dist/server/tool-host-factories.js +217 -0
  85. package/dist/server/tool-manager.js +84 -23
  86. package/dist/server/tool-prompt-overrides.js +158 -0
  87. package/dist/server/tool-prompts.js +42 -0
  88. package/dist/server/tool-signature.js +104 -0
  89. package/dist/server/wait-subscription-scan.js +46 -1
  90. package/dist/server/workspace-snapshot.js +60 -11
  91. package/extensions/webui.ts +90 -24
  92. package/package.json +5 -3
  93. package/plugin-sdk/README.md +25 -4
  94. package/plugin-sdk/import-check.mjs +210 -0
  95. package/plugin-sdk/index.d.ts +21 -1
  96. package/plugin-sdk/index.mjs +6 -0
  97. package/plugins/catalog.json +53 -2
  98. package/themes/aetheris.css +3 -1
  99. package/themes/translucent.css +8 -1
  100. package/themes/transparent.css +9 -1
  101. package/themes/zhupi-dark.css +1 -1
  102. package/themes/zhupi.css +1 -1
  103. package/web/dist/assets/{TerminalPanel-NerrJlTS.js → TerminalPanel-DD7I5_aC.js} +2 -2
  104. package/web/dist/assets/index-CpjA1YdT.css +1 -0
  105. package/web/dist/assets/index-nKn87VuM.js +678 -0
  106. package/web/dist/index.html +2 -2
  107. package/web/dist/sw.js +1 -1
  108. package/web/dist/assets/index-BdMaGCcs.css +0 -1
  109. package/web/dist/assets/index-ByCBN4Kt.js +0 -368
@@ -58,15 +58,17 @@ export function buildCompactionInstructions(focus, customSummary) {
58
58
  }
59
59
  export const CompactContextParams = Type.Object({
60
60
  focus: Type.String({
61
- description: "Compression focus and requirements for the current issue/task. State: 1) the active problem/goal; 2) context to PRESERVE (key decisions, code changes, conventions, user constraints); 3) what to REMOVE or condense (failed attempts, resolved debugging, off-topic history).",
61
+ description: "Compression focus for the current issue. State: 1) the active problem/goal; " +
62
+ "2) context to PRESERVE (decisions, code changes, conventions, constraints); " +
63
+ "3) what to REMOVE or condense (failed attempts, resolved debugging, off-topic history).",
62
64
  }),
63
65
  keepRecentTokens: Type.Optional(Type.Number({
64
66
  minimum: MIN_KEEP_RECENT_TOKENS,
65
67
  maximum: MAX_KEEP_RECENT_TOKENS,
66
- description: "Recent tokens to keep uncompacted (1000-100000). Smaller values (e.g. 3000-8000) compact more aggressively. Omit = auto-calculated from session size.",
68
+ description: "Recent tokens to keep uncompacted; smaller compacts more aggressively; omit = auto-calculated from session size.",
67
69
  })),
68
70
  summary: Type.Optional(Type.String({
69
- description: "Custom structured summary written by you; used as the core basis for the compaction entry if provided.",
71
+ description: "Optional structured summary; used as the basis for the compaction entry.",
70
72
  })),
71
73
  });
72
74
  export function makeCompactContextTool(host, lang) {
@@ -74,13 +76,12 @@ export function makeCompactContextTool(host, lang) {
74
76
  return defineTool({
75
77
  name: COMPACT_CONTEXT_TOOL_NAME,
76
78
  label: "Compact conversation context based on current issue",
77
- description: "Compress/compact the conversation context around the current task: specify what to preserve (key decisions, code structure, active requirements) and what to drop or heavily summarize (unrelated exploration, verbose outputs, resolved debugging). " +
78
- "Optionally control how many recent tokens stay untouched. Compaction executes when the current turn settles, refreshing context for subsequent turns.",
79
- promptSnippet: "proactively compact conversation context focusing on the current issue",
79
+ description: "Compress the conversation context around the current task. Compaction executes when the current turn settles, " +
80
+ "so the refreshed context applies from the next turn on.",
81
+ promptSnippet: "compact a long or noisy conversation context",
80
82
  promptGuidelines: [
81
- "Use compact_context when the conversation has grown long, or after extensive debugging/exploration, to focus context strictly on the current problem.",
82
- "Clearly specify in 'focus' what to keep (decisions, specs, active changes) and what to drop (failed attempts, voluminous command outputs).",
83
- "After calling compact_context, conclude your current turn with a brief wrap-up and next steps; the system executes compaction right after this turn finishes.",
83
+ "Use it when the conversation has grown long or after extensive exploration, to refocus context on the current problem.",
84
+ "After calling it, wrap up your turn with a brief summary and next steps.",
84
85
  ],
85
86
  parameters: CompactContextParams,
86
87
  execute: async (_id, p) => {
@@ -19,6 +19,7 @@
19
19
  */
20
20
  import { randomUUID } from "node:crypto";
21
21
  import { existsSync, readFileSync, writeFileSync } from "node:fs";
22
+ import { reorderEntriesForMainBranch } from "./session-branch.js";
22
23
  export const COMPACTION_PENDING_TYPE = "pi-web-ui/compaction-pending";
23
24
  export const COMPACTION_DONE_TYPE = "pi-web-ui/compaction-done";
24
25
  /** 0.90.x 写死的 id——repair 用来识别存量坏标记。 */
@@ -240,7 +241,39 @@ export function repairSessionTranscript(raw) {
240
241
  }
241
242
  }
242
243
  }
243
- const anyChange = result.removedPending > 0 || result.renamedIds > 0 || result.rewiredParents > 0 || result.cyclesBroken > 0;
244
+ // 第 4 步:分支拓扑归置(issue #567)。
245
+ // 当物理文件尾部是由于旧节点上追加的 custom/metadata 导致的侧枝(导致主对话分支
246
+ // 被 SDK 的 SessionManager 读成旧历史)时,按拓扑顺序重排,确保包含完整对话的
247
+ // 主分支叶子位于物理文件的末行,同时保留全部 custom 条目及其 parentId。
248
+ const liveEntries = slots.filter((s) => !s.removed && s.entry !== null).map((s) => s.entry);
249
+ if (liveEntries.length > 1) {
250
+ const reorderResult = reorderEntriesForMainBranch(liveEntries);
251
+ if (reorderResult.changed) {
252
+ result.reorderedBranches = true;
253
+ result.reorderedReason = reorderResult.reason;
254
+ const slotByEntry = new Map();
255
+ for (const s of slots) {
256
+ if (!s.removed && s.entry)
257
+ slotByEntry.set(s.entry, s);
258
+ }
259
+ const reorderedSlots = [];
260
+ for (const e of reorderResult.entries) {
261
+ const s = slotByEntry.get(e);
262
+ if (s) {
263
+ s.dirty = true;
264
+ reorderedSlots.push(s);
265
+ }
266
+ }
267
+ const prefixSlots = slots.filter((s) => !s.removed && s.entry === null);
268
+ slots.length = 0;
269
+ slots.push(...prefixSlots, ...reorderedSlots);
270
+ }
271
+ }
272
+ const anyChange = result.removedPending > 0 ||
273
+ result.renamedIds > 0 ||
274
+ result.rewiredParents > 0 ||
275
+ result.cyclesBroken > 0 ||
276
+ Boolean(result.reorderedBranches);
244
277
  if (!anyChange)
245
278
  return result;
246
279
  result.changed = true;
@@ -0,0 +1,43 @@
1
+ /**
2
+ * context-budget-runner — 多级分层上下文预算裁剪执行器。
3
+ *
4
+ * 当上下文达到预警水位(例如 70%)时,自动执行第一级(远期工具输出裁剪)和
5
+ * 第二级(已完成步骤折叠),推迟触发全量 LLM 压缩,保留近期关键代码的细节。
6
+ *
7
+ * 从 agent-service.ts 抽出为独立模块。
8
+ */
9
+ import { contextWindowOf, modelKeyOf } from "./agent-formatters.js";
10
+ import { effectiveSoftCap, softCapToReserve, DEFAULT_COMPACTION_RESERVE_TOKENS } from "./soft-cap.js";
11
+ import { pruneContextHierarchically } from "./context-budget.js";
12
+ /**
13
+ * 对指定对话执行分层上下文预算裁剪评估与就地修剪。
14
+ */
15
+ export function executeContextBudgetPruning(conv, settings) {
16
+ if (!conv?.session)
17
+ return { pruned: false, tokensSaved: 0 };
18
+ try {
19
+ const contextWindow = contextWindowOf(conv.session);
20
+ if (!contextWindow || contextWindow <= 0)
21
+ return { pruned: false, tokensSaved: 0 };
22
+ const modelId = modelKeyOf(conv.session);
23
+ const cap = effectiveSoftCap(settings.softCapTokens ?? 0, settings.softCapByModel, modelId);
24
+ const reserve = softCapToReserve(contextWindow, cap) ?? DEFAULT_COMPACTION_RESERVE_TOKENS;
25
+ const messages = conv.session.agent.state.messages;
26
+ if (!messages || messages.length === 0)
27
+ return { pruned: false, tokensSaved: 0 };
28
+ const result = pruneContextHierarchically(messages, {
29
+ contextWindow,
30
+ reserveTokens: reserve,
31
+ softCap: cap > 0 ? cap : null,
32
+ });
33
+ if (result.tier1.trimmedCount > 0 || result.tier2.foldedCount > 0) {
34
+ conv.session.agent.state.messages = result.messages;
35
+ const tokensSaved = result.tokensBefore - result.tokensAfter;
36
+ return { pruned: true, tokensSaved };
37
+ }
38
+ return { pruned: false, tokensSaved: 0 };
39
+ }
40
+ catch {
41
+ return { pruned: false, tokensSaved: 0 };
42
+ }
43
+ }
@@ -369,15 +369,14 @@ export function makeConversationReadTool(host, lang, extras) {
369
369
  return defineTool({
370
370
  name: CONVERSATION_READ_TOOL_NAME,
371
371
  label: "Read another conversation",
372
- description: "Read ANOTHER conversation: a running conversation of this client (incl. subagents — id from action=list) or a persisted history session (file path). " +
373
- "Use when the user references another chat. list: running + history sessions (query filter, limit). " +
374
- "read: one transcript — view=chat (default, user/assistant text) or full (incl. tool calls); last=N latest; query searches within (±1 context); messages capped ~600 chars. " +
375
- "files: files it created/modified. status: last tool call, last assistant text, pending question. " +
372
+ description: "Read ANOTHER conversation: a running conversation of this client (incl. subagents — id from action=list) " +
373
+ "or a persisted history session (file path). Use it whenever the user references another chat. " +
376
374
  "Only listed sessions are readable; other tabs' live runs appear in history once persisted.",
377
- promptSnippet: "read another conversation: list/find chats, read transcript (chat view / tail / search), touched files, status summary",
375
+ promptSnippet: "inspect another conversation the user mentions (list/read/files/status)",
378
376
  parameters: Type.Object({
379
377
  action: Type.Optional(Type.String({
380
- description: 'list = show running conversations + history sessions; read = fetch one transcript. Default "list".',
378
+ description: 'Default "list": running conversations + history sessions; read = one transcript (≤600 chars/msg); ' +
379
+ "files = files it created/modified; status = last tool call, last assistant text, pending question.",
381
380
  })),
382
381
  scope: Type.Optional(Type.String({
383
382
  description: 'list only: "current" = this project, "all" = every project. Default "all".',
@@ -391,14 +390,14 @@ export function makeConversationReadTool(host, lang, extras) {
391
390
  view: Type.Optional(Type.String({
392
391
  description: 'read only: "chat" = only user/assistant text (default, cheap); "full" = incl. tool calls/results.',
393
392
  })),
394
- last: Type.Optional(Type.Number({ description: "read only: take the latest N messages (1-200) instead of guessing offset." })),
393
+ last: Type.Optional(Type.Number({ description: "read only: take the latest N messages instead of guessing offset." })),
395
394
  id: Type.Optional(Type.String({ description: 'read only: running conversation id (e.g. "c3"), from action=list.' })),
396
395
  path: Type.Optional(Type.String({ description: "read only: history session file path, from action=list." })),
397
396
  offset: Type.Optional(Type.Number({ description: "read only: first message index (0-based). Default 0." })),
398
397
  limit: Type.Optional(Type.Number({
399
398
  description: "list: max entries per section (history defaults to 15, running uncapped up to 50). read/files: max messages/entries (1-200, default 50).",
400
399
  })),
401
- maxChars: Type.Optional(Type.Number({ description: "read only: max characters (1000-60000). Default 20000." })),
400
+ maxChars: Type.Optional(Type.Number({ description: "read only: max characters. Default 20000." })),
402
401
  }),
403
402
  execute: async (_id, p, _signal, _onUpdate, ctx) => {
404
403
  const action = (p.action ?? "list").trim().toLowerCase();
@@ -97,6 +97,16 @@ export function normalizeTouchPath(p) {
97
97
  s = s.slice(2);
98
98
  return s;
99
99
  }
100
+ /** patch 补丁文本 → 目标路径集合(段头 [path#TAG]/[path] + MV 目标)。 */
101
+ export function patchWriteTargets(patchText) {
102
+ const out = [];
103
+ for (const m of patchText.matchAll(/^\s*\[([^#\]\r\n]+)(?:#[0-9A-Fa-f]{4})?\]\s*$/gm)) {
104
+ out.push(m[1].trim());
105
+ }
106
+ for (const m of patchText.matchAll(/^\s*MV\s+(\S+)/gim))
107
+ out.push(m[1]);
108
+ return out;
109
+ }
100
110
  // ---------------------------------------------------------------------------
101
111
  // bash 命令解析(高置信度写入迹象,见文件头规则)
102
112
  // ---------------------------------------------------------------------------
@@ -280,6 +290,15 @@ export function extractTouches(messages, opts) {
280
290
  const ts = typeof m.timestamp === "number" && Number.isFinite(m.timestamp) ? m.timestamp : 0;
281
291
  for (const call of toolCallsOf(m)) {
282
292
  const name = call.name;
293
+ if (name === "patch") {
294
+ // patch 的目标路径在补丁文本里(无 args.path),按段头/MV 提取
295
+ const args = call.args;
296
+ if (args && typeof args.patch === "string") {
297
+ for (const p of patchWriteTargets(args.patch))
298
+ bump(p, ts);
299
+ }
300
+ continue;
301
+ }
283
302
  if (WRITE_TOOL_NAMES.has(name)) {
284
303
  const p = pathOfWriteArgs(call.args);
285
304
  if (p)
@@ -21,12 +21,25 @@
21
21
  * - findDanglingToolCalls:纯函数,消息/条目数组里找「有调用、无后继结果」的 toolCall;
22
22
  * - tailAssistantToolCallIds:沿当前分支回溯,定位尾部会上线的 assistant 的 toolCallId 集合;
23
23
  * - healDanglingToolCallFile:落盘版,仅针对当前分支尾部生效的悬空调用追加合成 toolResult;
24
- * - 合成结果文案:DANGLING_TOOL_RESULT_TEXT(中英各一,toolResult content 只带一条文本)。
24
+ * - 合成结果文案:danglingToolResultText(cause)(按成因归因,中英各一,toolResult content 只带一条文本)。
25
25
  */
26
26
  import { appendFileSync, existsSync, readFileSync } from "node:fs";
27
27
  import { randomUUID } from "node:crypto";
28
- export const DANGLING_TOOL_RESULT_TEXT = "(系统:上一次运行被强制终止(工具执行超时/模型流卡死),该工具调用没有返回结果。为避免对话记录损坏,已自动填入一条合成结果。请根据需要重新执行该工具或继续对话。)";
29
- export const DANGLING_TOOL_RESULT_TEXT_EN = "(System: the previous run was force-terminated (tool timeout / hung model stream) and this tool call never returned. A synthetic result was inserted automatically to keep the transcript valid. Re-run the tool or continue as needed.)";
28
+ const DANGLING_TEXT = {
29
+ generic: {
30
+ zh: "(系统:上一次运行未正常结束(可能是工具执行超时、模型流卡死或服务中断),该工具调用没有返回结果。为避免对话记录损坏,已自动填入一条合成结果。该命令可能已部分或全部执行,若需重跑请先确认是否会产生重复副作用。)",
31
+ en: "(System: the previous run did not finish cleanly (possibly a tool timeout, a hung model stream, or a service interruption) and this tool call never returned. A synthetic result was inserted automatically to keep the transcript valid. The command may have partly or fully run; confirm before re-running anything with side effects.)",
32
+ },
33
+ restart: {
34
+ zh: "(系统:上一次运行因服务重启被中断,该工具调用没有返回结果——它可能已经执行过。为避免对话记录损坏,已自动填入一条合成结果。重跑前请先确认是否会产生重复副作用(如删除、部署、推送)。)",
35
+ en: "(System: the previous run was interrupted by a service restart and this tool call never returned — it may already have executed. A synthetic result was inserted automatically to keep the transcript valid. Confirm before re-running anything with side effects such as deletes, deploys or pushes.)",
36
+ },
37
+ };
38
+ /** 合成 toolResult 的文本(中英各一,content 只带一条文本)。 */
39
+ export function danglingToolResultText(cause = "generic") {
40
+ const t = DANGLING_TEXT[cause];
41
+ return `${t.zh}\n${t.en}`;
42
+ }
30
43
  function toolCallsOfMessage(msg) {
31
44
  if (typeof msg !== "object" || msg === null)
32
45
  return [];
@@ -164,7 +177,7 @@ export function tailAssistantToolCallIds(entries, lastId) {
164
177
  * parentId 链式接在当前尾行之后。append-only——历史字节不动,无需备份。
165
178
  * 返回追加条数(0 = 健康,无需处理;-1 = 文件不可读/不可写)。
166
179
  */
167
- export function healDanglingToolCallFile(filePath) {
180
+ export function healDanglingToolCallFile(filePath, cause = "generic") {
168
181
  let raw;
169
182
  try {
170
183
  raw = readFileSync(filePath, "utf8");
@@ -210,7 +223,7 @@ export function healDanglingToolCallFile(filePath) {
210
223
  role: "toolResult",
211
224
  toolCallId: d.toolCallId,
212
225
  toolName: d.toolName,
213
- content: [{ type: "text", text: `${DANGLING_TOOL_RESULT_TEXT}\n${DANGLING_TOOL_RESULT_TEXT_EN}` }],
226
+ content: [{ type: "text", text: danglingToolResultText(cause) }],
214
227
  isError: true,
215
228
  timestamp: Date.now(),
216
229
  },
@@ -49,6 +49,7 @@ const BLOCKED_TOOLS = new Set([
49
49
  "git",
50
50
  // 代码求值(eval 沙箱可写真实文件系统 —— 主对话只审阅不施工,#436)
51
51
  "eval",
52
+ "codemode",
52
53
  "format",
53
54
  "prettier",
54
55
  "lint_fix",
@@ -101,14 +101,14 @@ export function buildDelegationPrompt(input, lang = "en") {
101
101
  }
102
102
  const delegateSchema = Type.Object({
103
103
  agent: Type.String({
104
- description: "Specialist template to delegate to (e.g. oracle, metis, momus, explore, librarian, sisyphus-junior, multimodal-looker, review). " +
105
- "Must be an enabled template — use subagent (action='templates') to see descriptions and pick the domain match.",
104
+ description: "Specialist template to delegate to (e.g. oracle, explore, review, librarian). " +
105
+ "Must be enabled — use subagent (action='templates') to list them and pick the domain match.",
106
106
  }),
107
107
  task: Type.String({
108
- description: "Atomic, specific goal: ONE action per delegation (minimum 20 chars). Vague tasks are rejected.",
108
+ description: "Atomic, specific goal: ONE action per delegation. Vague tasks are rejected.",
109
109
  }),
110
110
  expected_outcome: Type.String({
111
- description: "Concrete deliverables with done criteria: what does success look like (minimum 10 chars).",
111
+ description: "Concrete deliverables with done criteria.",
112
112
  }),
113
113
  required_tools: Type.String({
114
114
  description: "Explicit tool whitelist for the subagent (prevents tool sprawl).",
@@ -127,9 +127,8 @@ const delegateSchema = Type.Object({
127
127
  "omit = template model → panel default → follow the main conversation model.",
128
128
  })),
129
129
  persist: Type.Optional(Type.Boolean({
130
- description: "Optional: persist this conversation to disk as a regular session (saved in history, resumable). " +
131
- "Default false (lightweight in-memory subagent). " +
132
- "Use true for tasks that need long-term retention.",
130
+ description: "Persist as a regular session saved in history (default false = lightweight in-memory subagent); " +
131
+ "use for tasks needing long-term retention.",
133
132
  })),
134
133
  });
135
134
  /** 结构化派单工具:校验六段 → 拼装标准 prompt → 走 host.spawnSubagent 真子代理。 */
@@ -142,14 +141,11 @@ export function makeDelegateTaskTool(host, lang) {
142
141
  return defineTool({
143
142
  name: DELEGATE_TOOL_NAME,
144
143
  label: "Delegate task",
145
- description: "Delegate ONE well-defined task to a specialist subagent template via a structured six-section brief (TASK / EXPECTED OUTCOME / REQUIRED TOOLS / MUST DO / MUST NOT DO / CONTEXT). " +
146
- "The brief is validated server-side — missing or vague sections are rejected, so fill every section concretely. " +
147
- "Prefer over subagent (action='spawn') when the work fits a specialist template. Spawns a real subagent conversation; " +
148
- "collect with subagent (action='wait_all' / 'get_result'), redirect with subagent (action='steer'), stop with subagent (action='stop'). " +
149
- "For follow-ups continue the SAME subagent session instead of delegating again.",
150
- promptSnippet: "Delegate a well-defined task to a specialist template with a validated six-section brief",
144
+ description: "Delegate ONE well-defined task to a specialist template via a six-section brief (TASK / EXPECTED OUTCOME / REQUIRED TOOLS / MUST DO / MUST NOT DO / CONTEXT). " +
145
+ "Vague sections are rejected server-side — fill every one concretely. Prefer it over subagent (action='spawn'). Spawns a real subagent conversation; " +
146
+ "follow up with subagent (action='wait_all' | 'get_result' | 'steer' | 'stop'), continuing the SAME session rather than delegating again.",
147
+ promptSnippet: "hand a well-scoped task to a specialist template",
151
148
  promptGuidelines: [
152
- "Prefer delegate_task over subagent (action='spawn') when the work matches a specialist template's domain",
153
149
  "Before delegating, declare which template you chose and WHY its description matches the task",
154
150
  "After delegation ALWAYS verify the result: " +
155
151
  "does it work, does it follow codebase patterns, did it respect MUST DO / MUST NOT DO",