pi-web-ui 0.118.0 → 0.120.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 (195) hide show
  1. package/CHANGELOG.md +143 -1
  2. package/bin/hub-upgrade.mjs +33 -15
  3. package/bin/lib/atomic-file.mjs +90 -0
  4. package/dist/server/agent-service-daemon.js +44 -10
  5. package/dist/server/agent-service.js +930 -166
  6. package/dist/server/approval-default-rules.js +4 -4
  7. package/dist/server/ask-user-question-tool.js +3 -40
  8. package/dist/server/atomic-file.js +130 -5
  9. package/dist/server/background-executors.js +235 -0
  10. package/dist/server/bash-timeout.js +47 -0
  11. package/dist/server/bash-tool.js +72 -5
  12. package/dist/server/bg-servers.js +19 -13
  13. package/dist/server/browser-page-tool.js +38 -29
  14. package/dist/server/browser-script-tool.js +119 -0
  15. package/dist/server/canvas/canvas-agent-tool.js +46 -35
  16. package/dist/server/canvas/canvas-dispatch.js +12 -1
  17. package/dist/server/claim-files-tool.js +6 -7
  18. package/dist/server/client-state.js +457 -41
  19. package/dist/server/communicate-tool.js +59 -77
  20. package/dist/server/compact-context-tool.js +4 -13
  21. package/dist/server/conversation-communication.js +23 -1
  22. package/dist/server/conversation-read-tool.js +14 -23
  23. package/dist/server/conversation-rows.js +17 -0
  24. package/dist/server/conversation-tool-names.js +2 -2
  25. package/dist/server/conversation-tool.js +23 -15
  26. package/dist/server/conversation-touches.js +1 -1
  27. package/dist/server/delegate-mode.js +0 -1
  28. package/dist/server/delegate-task.js +18 -39
  29. package/dist/server/device-center/approval-summary.js +0 -1
  30. package/dist/server/device-center/bot-execution.js +0 -1
  31. package/dist/server/device-center/group-router-runtime.js +2 -0
  32. package/dist/server/device-center/hub-upgrade.js +5 -10
  33. package/dist/server/device-center/task-progress.js +2 -2
  34. package/dist/server/dispatch-domain-handlers.js +97 -24
  35. package/dist/server/dispatch-plugin-handlers.js +10 -0
  36. package/dist/server/dsh/dsh-agent-service.js +21 -19
  37. package/dist/server/durable/durable-agent-service.js +1 -1
  38. package/dist/server/edit-tool.js +293 -0
  39. package/dist/server/engine-catalog.js +8 -2
  40. package/dist/server/engine-cli.js +29 -7
  41. package/dist/server/engine-probe.js +11 -6
  42. package/dist/server/eval-tool.js +5 -19
  43. package/dist/server/files-service.js +41 -19
  44. package/dist/server/fs-copy.js +93 -0
  45. package/dist/server/goal-review-gate.js +2 -3
  46. package/dist/server/index.js +92 -3
  47. package/dist/server/job-runner.js +345 -0
  48. package/dist/server/lsp-tool.js +10 -28
  49. package/dist/server/marker-service.js +42 -30
  50. package/dist/server/mcp-agent-tool.js +22 -47
  51. package/dist/server/model-session.js +16 -0
  52. package/dist/server/native-cli-session-hooks.js +3 -2
  53. package/dist/server/native-cli-session.js +27 -2
  54. package/dist/server/patch-tool.js +2 -8
  55. package/dist/server/phone-tool.js +167 -0
  56. package/dist/server/plan-mode.js +7 -4
  57. package/dist/server/plan-update-tool.js +5 -8
  58. package/dist/server/plugin-api-catalog.js +13 -1
  59. package/dist/server/plugin-bundled.js +35 -28
  60. package/dist/server/plugin-catalog.js +6 -0
  61. package/dist/server/plugin-delivery.js +358 -0
  62. package/dist/server/plugin-inbox.js +152 -0
  63. package/dist/server/plugin-installer.js +15 -0
  64. package/dist/server/plugin-ledger.js +183 -0
  65. package/dist/server/plugin-manifest-validate.js +19 -0
  66. package/dist/server/plugin-materialize.js +161 -0
  67. package/dist/server/plugin-paths.js +60 -0
  68. package/dist/server/plugin-removal.js +16 -3
  69. package/dist/server/plugin-schedule.js +8 -7
  70. package/dist/server/plugin-secrets.js +7 -3
  71. package/dist/server/plugin-updater.js +2 -4
  72. package/dist/server/plugins.js +205 -48
  73. package/dist/server/present-files-tool.js +7 -13
  74. package/dist/server/preset-fields.js +23 -12
  75. package/dist/server/preset-share.js +1 -1
  76. package/dist/server/process-utils.js +11 -0
  77. package/dist/server/project-scripts.js +38 -0
  78. package/dist/server/prompt-composer.js +40 -21
  79. package/dist/server/protocol-version.js +1 -1
  80. package/dist/server/question-params.js +98 -0
  81. package/dist/server/quick-ask-settings.js +0 -1
  82. package/dist/server/quick-ask.js +3 -0
  83. package/dist/server/read-tool.js +10 -17
  84. package/dist/server/remote-ssh-service.js +40 -1
  85. package/dist/server/sandbox-runtime-gate.js +1 -1
  86. package/dist/server/sandbox-service.js +0 -1
  87. package/dist/server/sandbox-tool.js +25 -34
  88. package/dist/server/schedule-agent-tool.js +9 -19
  89. package/dist/server/scm-commitmsg.js +2 -1
  90. package/dist/server/serialize.js +8 -0
  91. package/dist/server/session-list-index.js +246 -0
  92. package/dist/server/session-list-scan.js +5 -0
  93. package/dist/server/session-parser.js +16 -0
  94. package/dist/server/settings-service.js +49 -19
  95. package/dist/server/skill-tool.js +4 -6
  96. package/dist/server/subagent-budget.js +68 -0
  97. package/dist/server/subagent-evidence.js +297 -0
  98. package/dist/server/subagent-helpers.js +12 -0
  99. package/dist/server/subagent-ledger.js +401 -0
  100. package/dist/server/subagent-notify.js +6 -2
  101. package/dist/server/subagent-security-gate.js +2 -3
  102. package/dist/server/subagent-settle.js +71 -0
  103. package/dist/server/subagents.js +566 -211
  104. package/dist/server/tabs.js +8 -1
  105. package/dist/server/terminals.js +34 -28
  106. package/dist/server/tool-approval.js +15 -1
  107. package/dist/server/tool-guards.js +0 -91
  108. package/dist/server/tool-manager.js +127 -47
  109. package/dist/server/tool-overrides.js +8 -1
  110. package/dist/server/tool-prompt-overrides.js +3 -6
  111. package/dist/server/tool-prompts.js +60 -17
  112. package/dist/server/universal/driver-base.js +2 -0
  113. package/dist/server/universal/drivers/claude-code.js +210 -211
  114. package/dist/server/universal/drivers/codex.js +29 -24
  115. package/dist/server/universal/engine-mcp.js +107 -0
  116. package/dist/server/universal/universal-attachments.js +77 -1
  117. package/dist/server/universal/universal-service.js +1 -1
  118. package/dist/server/universal/universal-session.js +106 -69
  119. package/dist/server/vision-bridge.js +2 -0
  120. package/dist/server/workspace-handle.js +119 -17
  121. package/dist/server/workspace-queue.js +37 -0
  122. package/dist/server/worktree-tool.js +13 -20
  123. package/docs/README.md +40 -36
  124. package/docs/architecture-plugins.md +64 -35
  125. package/docs/device-center.md +1 -1
  126. package/package.json +16 -4
  127. package/plugin-sdk/index.d.ts +102 -0
  128. package/plugins/catalog.json +23 -51
  129. package/themes/bases/flow-base.css +8 -17
  130. package/themes/dark-teal.css +0 -3
  131. package/web/dist/.build-assets.json +1 -1
  132. package/web/dist/assets/BgTasksModal-BdOJ19Hj.js +1 -0
  133. package/web/dist/assets/BgTasksModal-SAH2XCkY.js +1 -0
  134. package/web/dist/assets/{CanvasStudio-CAWcs9tm.js → CanvasStudio-BB_Iq7pl.js} +3 -3
  135. package/web/dist/assets/CanvasStudio-DU6O3N4u.js +1579 -0
  136. package/web/dist/assets/DeviceCenter-By1zVTSY.js +3 -0
  137. package/web/dist/assets/DeviceCenter-Cnm0Tjrx.js +3 -0
  138. package/web/dist/assets/DeviceExecutionSettings-qJzbI0Cf.js +1 -0
  139. package/web/dist/assets/{DeviceGroups-C_fZMNeK.js → DeviceGroups-DPrQxW6B.js} +1 -1
  140. package/web/dist/assets/DeviceGroups-DoucyUjI.js +1 -0
  141. package/web/dist/assets/{Dropdown-CTgVLUbp.js → Dropdown-kj_NIj6e.js} +1 -1
  142. package/web/dist/assets/FilePreview-Bub8Y9uq.js +2 -0
  143. package/web/dist/assets/FilePreview-CC76Z6an.js +2 -0
  144. package/web/dist/assets/GlobalSearchModal-01nkgw4X.js +1 -0
  145. package/web/dist/assets/GlobalSearchModal-CiT6wBmR.js +1 -0
  146. package/web/dist/assets/GroupConversation-1-lsPO1f.js +61 -0
  147. package/web/dist/assets/GroupConversation-HeiyW_O_.js +61 -0
  148. package/web/dist/assets/{GroupWorkItems-BIvZtr10.js → GroupWorkItems-BYJv2XFj.js} +1 -1
  149. package/web/dist/assets/{HintTip-Da6qc566.js → HintTip-DFhoclDw.js} +1 -1
  150. package/web/dist/assets/ModelConfigModal-D2Ro-jUZ.js +2 -0
  151. package/web/dist/assets/ModelConfigModal-DPc9R1pq.js +2 -0
  152. package/web/dist/assets/{NativeCliPanel-CU1rZmyu.js → NativeCliPanel-B108d697.js} +3 -3
  153. package/web/dist/assets/NativeCliPanel-DupvGwQM.js +5 -0
  154. package/web/dist/assets/{PiSetupModal-DZKY5Wiw.js → PiSetupModal-D0HitBfd.js} +1 -1
  155. package/web/dist/assets/ProviderOAuthControls-BLKUEDde.js +1 -0
  156. package/web/dist/assets/SCMPanel-DDbWrUHR.js +2 -0
  157. package/web/dist/assets/SCMPanel-DluNcd2-.js +2 -0
  158. package/web/dist/assets/SettingsModal-Cy5lRC97.css +1 -0
  159. package/web/dist/assets/SettingsModal-DQu18366.js +33 -0
  160. package/web/dist/assets/SettingsModal-Dm_haPme.js +33 -0
  161. package/web/dist/assets/{TermXterm-Bt5WKAxP.js → TermXterm-SYc-MUk2.js} +2 -2
  162. package/web/dist/assets/TerminalPanel-CgA_lhVT.js +1 -0
  163. package/web/dist/assets/TerminalPanel-vdSIOPjD.js +1 -0
  164. package/web/dist/assets/TuiOverlayModal-Cy1jYYIw.js +1 -0
  165. package/web/dist/assets/TuiOverlayModal-kXY_4hV8.js +1 -0
  166. package/web/dist/assets/app-globals-CBEscsYP.js +129 -0
  167. package/web/dist/assets/{canvas-client-WkhM55mR.js → canvas-client-Clsypfs6.js} +1 -1
  168. package/web/dist/assets/{desktop-B8NZ3KW-.js → desktop-C6D9a8HZ.js} +1 -1
  169. package/web/dist/assets/index-BD29OL9L.js +404 -0
  170. package/web/dist/assets/index-BlCxbqqr.js +404 -0
  171. package/web/dist/assets/index-DB55rbKC.css +1 -0
  172. package/web/dist/assets/plugin-host-VWBcq-LQ.js +1 -0
  173. package/web/dist/assets/remote-ssh-client-C2eab5Kw.js +1 -0
  174. package/web/dist/assets/theme-CpQk_Agp.js +1 -0
  175. package/web/dist/index.html +10 -10
  176. package/web/dist/sw.js +1 -1
  177. package/dist/server/edit-soft-tool.js +0 -297
  178. package/web/dist/assets/BgTasksModal-D-x7kA63.js +0 -1
  179. package/web/dist/assets/DeviceCenter-Dc0whRcu.js +0 -3
  180. package/web/dist/assets/DeviceExecutionSettings-BoX7-0h7.js +0 -1
  181. package/web/dist/assets/FilePreview-C6W0PvaK.js +0 -2
  182. package/web/dist/assets/GlobalSearchModal-HR9LSspC.js +0 -1
  183. package/web/dist/assets/GroupConversation-C81YjF2C.js +0 -61
  184. package/web/dist/assets/ModelConfigModal-DhSyuIuV.js +0 -2
  185. package/web/dist/assets/ProviderOAuthControls-CIL85nA7.js +0 -1
  186. package/web/dist/assets/SCMPanel-CuEgzAlO.js +0 -2
  187. package/web/dist/assets/SettingsModal-Cdu5h29p.js +0 -33
  188. package/web/dist/assets/TerminalPanel-BCIBV8se.js +0 -1
  189. package/web/dist/assets/TuiOverlayModal-3NDd9T97.js +0 -1
  190. package/web/dist/assets/app-globals-CZjFtI4F.js +0 -129
  191. package/web/dist/assets/index-CQc3VrWa.css +0 -1
  192. package/web/dist/assets/index-D_AGu4Zv.js +0 -404
  193. package/web/dist/assets/plugin-host-uqZGpvCs.js +0 -1
  194. package/web/dist/assets/remote-ssh-client-Cdf-cTUe.js +0 -1
  195. package/web/dist/assets/theme-DGL7hLUs.js +0 -1
@@ -0,0 +1,297 @@
1
+ /**
2
+ * 子代理完成证据单源:子代理自述「做完了」不够,必须给出可核对的证据,
3
+ * 而且证据要拿它自己的转录来对账(不是再问一遍模型)。
4
+ *
5
+ * 三层职责:
6
+ * · `normalizeEvidenceInput`:把模型传的 evidence 归一化并限量(不可信输入)。
7
+ * · `collectTranscriptFacts`:从子代理转录里抽「真的改过哪些文件、真的跑过哪些命令」。
8
+ * · `verifyEvidence`:对账,产出裁决 + 硬矛盾(驳回)/ 软疑点(降级为 partial)。
9
+ *
10
+ * 只做**可证伪**的判断:声称跑过的命令在转录里找不到 → 驳回;声称没改文件但转录有编辑 →
11
+ * 驳回;声称改过的文件找不到写入调用 → 只记疑点(bash 里 sed/mv 也会改文件,不能一票否决)。
12
+ */
13
+ import { SUBAGENT_WRITE_TOOL_NAMES } from "./subagent-security-gate.js";
14
+ export const EVIDENCE_LIMITS = {
15
+ files: 50,
16
+ commands: 20,
17
+ fieldChars: 400,
18
+ issueListed: 5,
19
+ warningListed: 4,
20
+ };
21
+ const SHELL_TOOL_NAMES = new Set(["bash", "powershell", "shell", "sh", "run_command", "exec_command"]);
22
+ const PATH_KEYS = ["path", "file_path", "filePath", "file", "target", "dest", "destination"];
23
+ const PATH_LIST_KEYS = ["paths", "files"];
24
+ function isRecord(value) {
25
+ return typeof value === "object" && value !== null;
26
+ }
27
+ function oneLine(value, max = EVIDENCE_LIMITS.fieldChars) {
28
+ const s = value.replace(/\s+/g, " ").trim();
29
+ return s.length > max ? `${s.slice(0, max)}…` : s;
30
+ }
31
+ export function normalizeCommandText(command) {
32
+ return command.replace(/\s+/g, " ").trim();
33
+ }
34
+ export function normalizeEvidencePath(path) {
35
+ const s = path.replace(/\\/g, "/").trim().replace(/^\.\//, "");
36
+ return s.length > 1 ? s.replace(/\/+$/, "") : s;
37
+ }
38
+ function normalizeList(raw, limit, normalize) {
39
+ if (!Array.isArray(raw))
40
+ return [];
41
+ const out = [];
42
+ const seen = new Set();
43
+ for (const item of raw) {
44
+ if (typeof item !== "string")
45
+ continue;
46
+ const value = normalize(oneLine(item));
47
+ if (!value || seen.has(value))
48
+ continue;
49
+ seen.add(value);
50
+ out.push(value);
51
+ if (out.length >= limit)
52
+ break;
53
+ }
54
+ return out;
55
+ }
56
+ /** 归一化模型传入的 evidence;不做对账,只保证形状与上限。 */
57
+ export function normalizeEvidenceInput(raw) {
58
+ if (raw === undefined || raw === null)
59
+ return { ok: true, value: {} };
60
+ if (!isRecord(raw))
61
+ return { ok: false, error: "not_object" };
62
+ const files = normalizeList(raw.files, EVIDENCE_LIMITS.files, normalizeEvidencePath);
63
+ const commands = normalizeList(raw.commands, EVIDENCE_LIMITS.commands, normalizeCommandText);
64
+ const none = raw.none === true;
65
+ const blocked = typeof raw.blocked === "string" ? oneLine(raw.blocked) : undefined;
66
+ if (Array.isArray(raw.files) && files.length === 0)
67
+ return { ok: false, error: "invalid_fields" };
68
+ if (Array.isArray(raw.commands) && commands.length === 0)
69
+ return { ok: false, error: "invalid_fields" };
70
+ if (!files.length && !commands.length && !none && !blocked)
71
+ return { ok: false, error: "empty" };
72
+ return { ok: true, value: { files, commands, none, blocked } };
73
+ }
74
+ function argsOf(block) {
75
+ const raw = block.args ?? block.arguments;
76
+ if (isRecord(raw))
77
+ return raw;
78
+ if (typeof raw === "string" && raw.trim()) {
79
+ try {
80
+ const parsed = JSON.parse(raw);
81
+ return isRecord(parsed) ? parsed : undefined;
82
+ }
83
+ catch {
84
+ return undefined;
85
+ }
86
+ }
87
+ return undefined;
88
+ }
89
+ function pathsOf(args) {
90
+ const out = [];
91
+ for (const key of PATH_KEYS) {
92
+ const value = args[key];
93
+ if (typeof value === "string" && value.trim())
94
+ out.push(value);
95
+ }
96
+ for (const key of PATH_LIST_KEYS) {
97
+ const value = args[key];
98
+ if (!Array.isArray(value))
99
+ continue;
100
+ for (const item of value)
101
+ if (typeof item === "string" && item.trim())
102
+ out.push(item);
103
+ }
104
+ return out;
105
+ }
106
+ function commandOf(args) {
107
+ const value = typeof args.command === "string" ? args.command : typeof args.cmd === "string" ? args.cmd : "";
108
+ return normalizeCommandText(value);
109
+ }
110
+ /**
111
+ * 从转录里抽事实。只认三种载体:assistant 的 `toolCall` 块、`bashExecution` 记录、
112
+ * `toolResult`(用于把失败标记贴回对应命令)。
113
+ */
114
+ export function collectTranscriptFacts(messages, opts = {}) {
115
+ const writeTools = opts.writeTools ?? SUBAGENT_WRITE_TOOL_NAMES;
116
+ const edited = new Set();
117
+ const commands = [];
118
+ const byCallId = new Map();
119
+ for (const message of messages) {
120
+ if (!isRecord(message))
121
+ continue;
122
+ if (message.role === "assistant" && Array.isArray(message.content)) {
123
+ for (const block of message.content) {
124
+ if (!isRecord(block) || block.type !== "toolCall")
125
+ continue;
126
+ const name = typeof block.name === "string" ? block.name : "";
127
+ const callId = typeof block.toolCallId === "string" ? block.toolCallId : typeof block.id === "string" ? block.id : "";
128
+ const args = argsOf(block);
129
+ if (!args)
130
+ continue;
131
+ if (writeTools.has(name)) {
132
+ for (const path of pathsOf(args))
133
+ edited.add(normalizeEvidencePath(path));
134
+ }
135
+ if (SHELL_TOOL_NAMES.has(name)) {
136
+ const command = commandOf(args);
137
+ if (!command)
138
+ continue;
139
+ commands.push({ command, failed: false });
140
+ if (callId)
141
+ byCallId.set(callId, { command });
142
+ }
143
+ }
144
+ continue;
145
+ }
146
+ if (message.role === "bashExecution") {
147
+ const command = normalizeCommandText(typeof message.command === "string" ? message.command : "");
148
+ if (!command)
149
+ continue;
150
+ const exitCode = typeof message.exitCode === "number" ? message.exitCode : undefined;
151
+ commands.push({ command, failed: exitCode !== undefined && exitCode !== 0 });
152
+ continue;
153
+ }
154
+ if (message.role === "toolResult" && message.isError === true) {
155
+ const callId = typeof message.toolCallId === "string" ? message.toolCallId : "";
156
+ const command = callId ? byCallId.get(callId)?.command : undefined;
157
+ if (!command)
158
+ continue;
159
+ const hit = commands.find((entry) => entry.command === command && !entry.failed);
160
+ if (hit)
161
+ hit.failed = true;
162
+ }
163
+ }
164
+ return { editedFiles: [...edited], commands };
165
+ }
166
+ function samePath(a, b) {
167
+ const x = normalizeEvidencePath(a).toLowerCase();
168
+ const y = normalizeEvidencePath(b).toLowerCase();
169
+ if (!x || !y)
170
+ return false;
171
+ if (x === y)
172
+ return true;
173
+ return x.endsWith(`/${y}`) || y.endsWith(`/${x}`);
174
+ }
175
+ function commandMatches(claimed, executed) {
176
+ const a = normalizeCommandText(claimed);
177
+ const b = normalizeCommandText(executed);
178
+ if (!a || !b)
179
+ return false;
180
+ return a === b || b.includes(a);
181
+ }
182
+ function listFor(items, limit) {
183
+ if (items.length <= limit)
184
+ return items.join("; ");
185
+ return `${items.slice(0, limit).join("; ")} (+${items.length - limit})`;
186
+ }
187
+ /** 对账:返回带裁决与问题清单的证据记录。 */
188
+ export function verifyEvidence(input, facts, opts = {}) {
189
+ const files = input.files ?? [];
190
+ const commands = input.commands ?? [];
191
+ const none = input.none === true;
192
+ const blocked = input.blocked?.trim() || undefined;
193
+ const issues = [];
194
+ const warnings = [];
195
+ let matchedFiles = 0;
196
+ for (const file of files) {
197
+ if (facts.editedFiles.some((edited) => samePath(file, edited)))
198
+ matchedFiles++;
199
+ else
200
+ warnings.push(`declared file not seen in this run's edits: ${file}`);
201
+ }
202
+ if (none && facts.editedFiles.length > 0) {
203
+ issues.push(`declared no file changes, but ${facts.editedFiles.length} file(s) were edited: ${listFor(facts.editedFiles, EVIDENCE_LIMITS.issueListed)}`);
204
+ }
205
+ let matchedCommands = 0;
206
+ for (const claimed of commands) {
207
+ const hit = facts.commands.find((entry) => commandMatches(claimed, entry.command));
208
+ if (!hit) {
209
+ issues.push(`declared command was never run in this session: ${claimed}`);
210
+ continue;
211
+ }
212
+ if (hit.failed) {
213
+ issues.push(`declared command failed in this session: ${claimed}`);
214
+ continue;
215
+ }
216
+ matchedCommands++;
217
+ }
218
+ if (!none && files.length > 0 && facts.editedFiles.length > 0) {
219
+ const undeclared = facts.editedFiles.filter((edited) => !files.some((file) => samePath(file, edited)));
220
+ if (undeclared.length > 0) {
221
+ warnings.push(`${undeclared.length} file(s) were edited but not declared: ${listFor(undeclared, EVIDENCE_LIMITS.warningListed)}`);
222
+ }
223
+ }
224
+ let verdict;
225
+ if (blocked)
226
+ verdict = "blocked";
227
+ else if (issues.length > 0)
228
+ verdict = "unverified";
229
+ else if (warnings.length > 0)
230
+ verdict = "partial";
231
+ else if (none || files.length > 0 || commands.length > 0)
232
+ verdict = "pass";
233
+ else
234
+ verdict = "unverified";
235
+ return {
236
+ files,
237
+ commands,
238
+ none,
239
+ blocked,
240
+ verdict,
241
+ issues: issues.slice(0, EVIDENCE_LIMITS.issueListed),
242
+ warnings: warnings.slice(0, EVIDENCE_LIMITS.warningListed),
243
+ matchedFiles,
244
+ matchedCommands,
245
+ reportedAt: opts.now ?? Date.now(),
246
+ };
247
+ }
248
+ export function evidenceVerdictLabel(verdict, lang) {
249
+ if (lang === "zh") {
250
+ switch (verdict) {
251
+ case "pass":
252
+ return "证据已核对";
253
+ case "partial":
254
+ return "部分证据未核对";
255
+ case "blocked":
256
+ return "自述受阻";
257
+ default:
258
+ return "未提供证据";
259
+ }
260
+ }
261
+ switch (verdict) {
262
+ case "pass":
263
+ return "evidence verified";
264
+ case "partial":
265
+ return "partially verified";
266
+ case "blocked":
267
+ return "reported blocked";
268
+ default:
269
+ return "no evidence";
270
+ }
271
+ }
272
+ /** 一行人话证据摘要:`证据已核对(2 文件、1 命令)` / `verified (2 files, 1 command)`。 */
273
+ export function formatEvidenceSummary(evidence, lang) {
274
+ const zh = lang === "zh";
275
+ const label = evidenceVerdictLabel(evidence.verdict, lang);
276
+ const parts = [];
277
+ if (evidence.files.length > 0) {
278
+ parts.push(zh
279
+ ? `${evidence.matchedFiles}/${evidence.files.length} 文件`
280
+ : `${evidence.matchedFiles}/${evidence.files.length} files`);
281
+ }
282
+ if (evidence.commands.length > 0) {
283
+ parts.push(zh
284
+ ? `${evidence.matchedCommands}/${evidence.commands.length} 命令`
285
+ : `${evidence.matchedCommands}/${evidence.commands.length} commands`);
286
+ }
287
+ if (evidence.none)
288
+ parts.push(zh ? "声明无文件改动" : "declared no changes");
289
+ if (evidence.blocked)
290
+ parts.push(zh ? `受阻原因:${evidence.blocked}` : `blocked: ${evidence.blocked}`);
291
+ const head = parts.length > 0 ? `${label}${zh ? "(" : " ("}${parts.join(zh ? "、" : ", ")}${zh ? ")" : ")"}` : label;
292
+ const issuePart = evidence.issues.length > 0 ? `${zh ? ";矛盾:" : "; issues: "}${evidence.issues.join(zh ? ";" : "; ")}` : "";
293
+ const warnPart = evidence.warnings.length > 0
294
+ ? `${zh ? ";疑点:" : "; warnings: "}${evidence.warnings.join(zh ? ";" : "; ")}`
295
+ : "";
296
+ return `${head}${issuePart}${warnPart}`;
297
+ }
@@ -81,6 +81,16 @@ export function toSubagentSnapshot(conv) {
81
81
  const isPersisted = !conv.isSubagent || (typeof sm?.isPersisted === "function" && sm.isPersisted());
82
82
  const m = conv.session.model;
83
83
  const modelKey = m ? `${m.provider}/${m.id}` : (conv.subagentTemplate?.model ?? undefined);
84
+ let usage;
85
+ try {
86
+ const tokens = conv.session.getSessionStats()?.tokens;
87
+ if (tokens && Number.isFinite(tokens.input) && Number.isFinite(tokens.output)) {
88
+ usage = { input: tokens.input, output: tokens.output, total: tokens.input + tokens.output };
89
+ }
90
+ }
91
+ catch {
92
+ usage = undefined;
93
+ }
84
94
  return {
85
95
  convId: conv.id,
86
96
  executionId: conversationIdentity(conv),
@@ -101,6 +111,8 @@ export function toSubagentSnapshot(conv) {
101
111
  output: conv.session.getLastAssistantText() ?? "",
102
112
  parentId: conversationParent(conv)?.id,
103
113
  persisted: isPersisted,
114
+ evidence: conv.subagentEvidence,
115
+ usage,
104
116
  handoffTo: conv.peerHandoffTo ? [...conv.peerHandoffTo] : undefined,
105
117
  handoffFrom: conv.peerHandoffFrom ? [...conv.peerHandoffFrom] : undefined,
106
118
  worktree: conv.subagentWorktree