minimal-agent 0.12.0 → 0.14.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 (472) hide show
  1. package/README.md +6 -5
  2. package/package.json +62 -5
  3. package/plugins/computer_use/.claude-plugin/plugin.json +1 -1
  4. package/plugins/cron-runner/src/commands.js +4 -4
  5. package/plugins/cron-runner/src/commands.ts +4 -4
  6. package/plugins/workflow-runner/.claude-plugin/plugin.json +2 -2
  7. package/plugins/workflow-runner/commands/workflow.md +57 -90
  8. package/plugins/workflow-runner/commands/workflows.md +4 -4
  9. package/plugins/workflow-runner/plugin.js +24 -13
  10. package/plugins/workflow-runner/plugin.ts +28 -13
  11. package/plugins/workflow-runner/src/discovery.js +160 -0
  12. package/plugins/workflow-runner/src/discovery.ts +194 -0
  13. package/plugins/workflow-runner/src/goalAnchor.js +53 -0
  14. package/plugins/workflow-runner/src/goalAnchor.ts +59 -0
  15. package/plugins/workflow-runner/src/index.js +204 -185
  16. package/plugins/workflow-runner/src/index.ts +249 -224
  17. package/plugins/workflow-runner/src/inputCoercion.js +40 -0
  18. package/plugins/workflow-runner/src/inputCoercion.ts +43 -0
  19. package/plugins/workflow-runner/src/journal.js +224 -0
  20. package/plugins/workflow-runner/src/journal.ts +274 -0
  21. package/plugins/workflow-runner/src/jsonSchema.js +132 -0
  22. package/plugins/workflow-runner/src/jsonSchema.ts +162 -0
  23. package/plugins/workflow-runner/src/moduleResolution.js +64 -0
  24. package/plugins/workflow-runner/src/moduleResolution.ts +71 -0
  25. package/plugins/workflow-runner/src/resourceInputs.js +220 -0
  26. package/plugins/workflow-runner/src/resourceInputs.ts +300 -0
  27. package/plugins/workflow-runner/src/runner.js +404 -467
  28. package/plugins/workflow-runner/src/runner.ts +491 -535
  29. package/plugins/workflow-runner/src/runtime/config.js +46 -0
  30. package/plugins/workflow-runner/src/runtime/config.ts +69 -0
  31. package/plugins/workflow-runner/src/runtime/context.js +1304 -0
  32. package/plugins/workflow-runner/src/runtime/context.ts +1786 -0
  33. package/plugins/workflow-runner/src/runtime/exec.js +34 -0
  34. package/plugins/workflow-runner/src/runtime/exec.ts +53 -0
  35. package/plugins/workflow-runner/src/runtime/flow.js +8 -0
  36. package/plugins/workflow-runner/src/runtime/flow.ts +12 -0
  37. package/plugins/workflow-runner/src/runtime/fs.js +27 -0
  38. package/plugins/workflow-runner/src/runtime/fs.ts +41 -0
  39. package/plugins/workflow-runner/src/runtime/model.js +6 -0
  40. package/plugins/workflow-runner/src/runtime/model.ts +8 -0
  41. package/plugins/workflow-runner/src/runtime/output.js +7 -0
  42. package/plugins/workflow-runner/src/runtime/output.ts +21 -0
  43. package/plugins/workflow-runner/src/runtime/scheduler.js +141 -0
  44. package/plugins/workflow-runner/src/runtime/scheduler.ts +166 -0
  45. package/plugins/workflow-runner/src/runtime/state.js +16 -0
  46. package/plugins/workflow-runner/src/runtime/state.ts +19 -0
  47. package/plugins/workflow-runner/src/runtime/tools.js +3 -0
  48. package/plugins/workflow-runner/src/runtime/tools.ts +6 -0
  49. package/plugins/workflow-runner/src/sandbox.js +141 -0
  50. package/plugins/workflow-runner/src/sandbox.ts +182 -0
  51. package/plugins/workflow-runner/src/scriptGuard.d.mts +38 -0
  52. package/plugins/workflow-runner/src/scriptGuard.mjs +449 -0
  53. package/plugins/workflow-runner/src/taskIdentity.js +172 -152
  54. package/plugins/workflow-runner/src/taskIdentity.ts +233 -200
  55. package/plugins/workflow-runner/src/toolRuntime.js +29 -8
  56. package/plugins/workflow-runner/src/toolRuntime.ts +36 -11
  57. package/plugins/workflow-runner/src/types.js +7 -105
  58. package/plugins/workflow-runner/src/types.ts +155 -520
  59. package/plugins/workflow-runner/src/util.js +47 -0
  60. package/plugins/workflow-runner/src/util.ts +51 -0
  61. package/plugins/workflow-runner/src/workflowContext.js +20 -0
  62. package/plugins/workflow-runner/src/workflowContext.ts +58 -0
  63. package/plugins/workflow-runner/src/workflowDependencies.js +36 -0
  64. package/plugins/workflow-runner/src/workflowDependencies.ts +59 -0
  65. package/plugins/workflow-runner/src/workflowFingerprint.js +118 -0
  66. package/plugins/workflow-runner/src/workflowFingerprint.ts +122 -0
  67. package/plugins/workflow-runner/src/workflowState.js +542 -469
  68. package/plugins/workflow-runner/src/workflowState.ts +639 -589
  69. package/plugins/workflow-runner/test/api.test.ts +223 -0
  70. package/plugins/workflow-runner/test/apiCapabilities.test.ts +614 -0
  71. package/plugins/workflow-runner/test/apiConcurrencyGate.test.ts +104 -0
  72. package/plugins/workflow-runner/test/apiEcho.test.ts +210 -0
  73. package/plugins/workflow-runner/test/apiReadText.test.ts +178 -0
  74. package/plugins/workflow-runner/test/apiResourceLedger.test.ts +184 -0
  75. package/plugins/workflow-runner/test/childWorkflow.test.ts +304 -0
  76. package/plugins/workflow-runner/test/discovery.test.ts +234 -0
  77. package/plugins/workflow-runner/test/goalAnchor.test.ts +106 -0
  78. package/plugins/workflow-runner/test/goalController.test.ts +317 -0
  79. package/plugins/workflow-runner/test/journalLanes.test.ts +198 -0
  80. package/plugins/workflow-runner/test/listResources.test.ts +106 -0
  81. package/plugins/workflow-runner/test/resourceInputs.test.ts +294 -0
  82. package/plugins/workflow-runner/test/sandbox.test.ts +126 -0
  83. package/plugins/workflow-runner/test/scheduler.test.ts +70 -0
  84. package/plugins/workflow-runner/test/scriptGuard.test.ts +276 -0
  85. package/plugins/workflow-runner/test/skillDocSync.test.ts +78 -0
  86. package/plugins/workflow-runner/test/taskIdentity.test.ts +288 -179
  87. package/plugins/workflow-runner/test/workflowFingerprint.test.ts +106 -0
  88. package/plugins/workflow-runner/test/workflowState.test.ts +429 -0
  89. package/skills/pptx/examples/assets/cover-bg.svg +23 -0
  90. package/skills/pptx/examples/assets/icon-spark.svg +5 -0
  91. package/skills/skill-creator/scripts/run_eval.py +3 -2
  92. package/skills/ui-design/SKILL.md +5 -2
  93. package/skills/ui-design/references/layout-composition.md +1 -1
  94. package/skills/workflow-creator/SKILL.md +344 -0
  95. package/skills/workflow-creator/assets/template/workflow.mjs +48 -0
  96. package/skills/workflow-creator/references/api.md +216 -0
  97. package/skills/workflow-creator/references/migration.md +103 -0
  98. package/skills/workflow-creator/references/patterns.md +779 -0
  99. package/skills/workflow-creator/scripts/list-resources.mjs +205 -0
  100. package/skills/workflow-creator/scripts/scaffold.mjs +148 -0
  101. package/skills/workflow-creator/scripts/validate.mjs +275 -0
  102. package/skills/workflow-creator/scripts/workflow-creator.test.mjs +82 -0
  103. package/src/advisor/advisorCoordinator.js +503 -0
  104. package/src/advisor/advisorCoordinator.ts +657 -0
  105. package/src/cli/configMenu.tsx +0 -1
  106. package/src/cli/print.js +44 -6
  107. package/src/cli/print.ts +73 -4
  108. package/src/cli/streamJson.js +5 -6
  109. package/src/cli/streamJson.ts +8 -4
  110. package/src/cli/wizards/advisorWizard.js +4 -2
  111. package/src/cli/wizards/advisorWizard.tsx +8 -2
  112. package/src/cli/wizards/contextAdvisorWizard.js +5 -4
  113. package/src/cli/wizards/contextAdvisorWizard.tsx +7 -6
  114. package/src/collaboration/taskFlow.js +115 -0
  115. package/src/collaboration/taskFlow.ts +169 -0
  116. package/src/config/configDefaults.js +41 -1
  117. package/src/config/configDefaults.ts +43 -1
  118. package/src/config/configDiagnostics.ts +2 -2
  119. package/src/config/configFile.js +40 -9
  120. package/src/config/configFile.ts +60 -11
  121. package/src/config/configService.js +443 -74
  122. package/src/config/configService.ts +723 -142
  123. package/src/config/numericLimits.js +22 -0
  124. package/src/config/numericLimits.ts +24 -0
  125. package/src/config.js +1 -0
  126. package/src/config.ts +3 -2
  127. package/src/context/budgetPlan.js +1 -1
  128. package/src/context/budgetPlan.ts +1 -1
  129. package/src/context/compact.js +7 -2
  130. package/src/context/compact.ts +9 -2
  131. package/src/context/microCompactLite.js +212 -13
  132. package/src/context/microCompactLite.ts +261 -12
  133. package/src/context/sessionRegistry.js +8 -1
  134. package/src/context/sessionRegistry.ts +18 -5
  135. package/src/context/toolResultArchive.js +72 -0
  136. package/src/context/toolResultArchive.ts +95 -0
  137. package/src/goal/errors.js +8 -0
  138. package/src/goal/errors.ts +18 -0
  139. package/src/goal/goalRuntime.js +344 -0
  140. package/src/goal/goalRuntime.ts +466 -0
  141. package/src/goal/goalStore.js +200 -0
  142. package/src/goal/goalStore.ts +219 -0
  143. package/src/goal/index.js +4 -0
  144. package/src/goal/index.ts +4 -0
  145. package/src/goal/statusMapping.js +71 -0
  146. package/src/goal/statusMapping.ts +95 -0
  147. package/src/goal/types.js +7 -0
  148. package/src/goal/types.ts +179 -0
  149. package/src/goal/workflowController.js +306 -0
  150. package/src/goal/workflowController.ts +360 -0
  151. package/src/harness/evidenceLedger.js +2 -0
  152. package/src/harness/evidenceLedger.ts +1 -0
  153. package/src/harness/stallGuard.js +9 -3
  154. package/src/harness/stallGuard.ts +7 -3
  155. package/src/images/imageResolver.js +161 -0
  156. package/src/images/imageResolver.ts +189 -0
  157. package/src/infra/verification.js +56 -20
  158. package/src/infra/verification.ts +87 -20
  159. package/src/llm/client.js +79 -21
  160. package/src/llm/client.ts +182 -35
  161. package/src/llm/gatewayClient.js +201 -0
  162. package/src/llm/gatewayClient.ts +299 -0
  163. package/src/llm/messageProvenance.js +46 -0
  164. package/src/llm/messageProvenance.ts +58 -0
  165. package/src/llm/modelProvider.js +1 -0
  166. package/src/llm/modelProvider.ts +22 -0
  167. package/src/llm/providers/anthropicFormat.js +108 -1
  168. package/src/llm/providers/anthropicFormat.ts +115 -4
  169. package/src/llm/providers/openaiFormat.js +9 -0
  170. package/src/llm/providers/openaiFormat.ts +12 -3
  171. package/src/loop.js +319 -54
  172. package/src/loop.ts +373 -57
  173. package/src/main.js +4 -1
  174. package/src/main.tsx +4 -1
  175. package/src/managedExecution/index.js +2 -0
  176. package/src/managedExecution/index.ts +2 -0
  177. package/src/managedExecution/registry.js +15 -0
  178. package/src/managedExecution/registry.ts +20 -0
  179. package/src/managedExecution/types.js +1 -0
  180. package/src/managedExecution/types.ts +86 -0
  181. package/src/modelRef.js +9 -0
  182. package/src/modelRef.ts +31 -0
  183. package/src/multimodal.js +14 -28
  184. package/src/multimodal.ts +17 -33
  185. package/src/net/lanDiscovery.js +65 -0
  186. package/src/net/lanDiscovery.ts +82 -0
  187. package/src/plugin-sdk.js +28 -3
  188. package/src/plugin-sdk.ts +39 -6
  189. package/src/plugins/pluginApi.ts +16 -1
  190. package/src/plugins/pluginLoader.js +4 -0
  191. package/src/plugins/pluginLoader.ts +6 -0
  192. package/src/plugins/pluginRunner.js +152 -9
  193. package/src/plugins/pluginRunner.ts +186 -8
  194. package/src/plugins/slashFallback.js +113 -0
  195. package/src/plugins/slashFallback.ts +137 -0
  196. package/src/prompts/policyRegistry.js +15 -8
  197. package/src/prompts/policyRegistry.ts +18 -8
  198. package/src/prompts/promptAssembly.js +103 -12
  199. package/src/prompts/promptAssembly.ts +114 -12
  200. package/src/prompts/skillList.js +21 -3
  201. package/src/prompts/skillList.ts +27 -2
  202. package/src/prompts/stableSystemPrompt.js +18 -0
  203. package/src/prompts/stableSystemPrompt.ts +33 -0
  204. package/src/runtime/agentRuntimeContext.js +8 -2
  205. package/src/runtime/agentRuntimeContext.ts +17 -4
  206. package/src/session/runAgentTurn.js +78 -12
  207. package/src/session/runAgentTurn.ts +105 -23
  208. package/src/session/runTurn.js +10 -9
  209. package/src/session/runTurn.ts +17 -8
  210. package/src/session/sessionState.ts +2 -0
  211. package/src/team/auth.js +186 -0
  212. package/src/team/auth.ts +298 -0
  213. package/src/team/cli.js +105 -0
  214. package/src/team/cli.ts +122 -0
  215. package/src/team/onlineToolContract.js +64 -0
  216. package/src/team/onlineToolContract.ts +109 -0
  217. package/src/team/toolPolicy.js +36 -0
  218. package/src/team/toolPolicy.ts +75 -0
  219. package/src/tools/advisor/advisor.js +148 -37
  220. package/src/tools/advisor/advisor.ts +161 -38
  221. package/src/tools/advisor/advisorDecision.js +71 -0
  222. package/src/tools/advisor/advisorDecision.ts +85 -0
  223. package/src/tools/agent/agent.js +18 -5
  224. package/src/tools/agent/agent.ts +21 -7
  225. package/src/tools/agent/agentControl.js +246 -0
  226. package/src/tools/agent/agentControl.ts +284 -0
  227. package/src/tools/agent/agentTaskService.js +40 -1
  228. package/src/tools/agent/agentTaskService.ts +44 -1
  229. package/src/tools/agent/agentTypes.js +14 -2
  230. package/src/tools/agent/agentTypes.ts +15 -2
  231. package/src/tools/applypatch/applyPatch.js +362 -0
  232. package/src/tools/applypatch/applyPatch.ts +428 -0
  233. package/src/tools/bash/bash.js +70 -18
  234. package/src/tools/bash/bash.ts +75 -20
  235. package/src/tools/capabilities.js +10 -5
  236. package/src/tools/capabilities.ts +10 -5
  237. package/src/tools/computeruse/computerIntent.js +32 -0
  238. package/src/tools/computeruse/computerIntent.ts +46 -0
  239. package/src/tools/computeruse/telemetryLog.js +12 -0
  240. package/src/tools/computeruse/telemetryLog.ts +16 -0
  241. package/src/tools/computeruse/vision/telemetry.js +1 -0
  242. package/src/tools/computeruse/vision/telemetry.ts +1 -0
  243. package/src/tools/effectiveToolSet.js +4 -0
  244. package/src/tools/effectiveToolSet.ts +4 -0
  245. package/src/tools/index.js +21 -2
  246. package/src/tools/index.ts +33 -2
  247. package/src/tools/powershell/powershell.js +18 -1
  248. package/src/tools/powershell/powershell.ts +18 -2
  249. package/src/tools/presentresult/presentresult.js +6 -15
  250. package/src/tools/presentresult/presentresult.ts +6 -15
  251. package/src/tools/read/read.js +69 -11
  252. package/src/tools/read/read.ts +70 -11
  253. package/src/tools/shared/fileUtils.js +1 -2
  254. package/src/tools/shared/fileUtils.ts +1 -2
  255. package/src/tools/shared/permanentDeleteGuard.js +34 -3
  256. package/src/tools/shared/permanentDeleteGuard.ts +43 -6
  257. package/src/tools/shared/toolOutputStore.js +23 -1
  258. package/src/tools/shared/toolOutputStore.ts +22 -1
  259. package/src/tools/skill/skill.js +9 -3
  260. package/src/tools/skill/skill.ts +8 -4
  261. package/src/tools/toolPromptGuides.js +117 -0
  262. package/src/tools/toolPromptGuides.ts +137 -0
  263. package/src/tools/webbrowser/agentBrowserPath.js +19 -9
  264. package/src/tools/webbrowser/agentBrowserPath.ts +70 -28
  265. package/src/tools/webbrowser/browser.js +27 -11
  266. package/src/tools/webbrowser/browser.ts +68 -24
  267. package/src/tools/webbrowser/browserAutomation.js +329 -0
  268. package/src/tools/webbrowser/browserAutomation.ts +467 -0
  269. package/src/tools/webbrowser/browserAxState.js +97 -0
  270. package/src/tools/webbrowser/browserAxState.ts +142 -0
  271. package/src/tools/webbrowser/browserBatch.js +1578 -0
  272. package/src/tools/webbrowser/browserBatch.ts +2382 -0
  273. package/src/tools/webbrowser/browserCdp.js +208 -0
  274. package/src/tools/webbrowser/browserCdp.ts +255 -0
  275. package/src/tools/webbrowser/browserConditions.js +24 -0
  276. package/src/tools/webbrowser/browserConditions.ts +45 -0
  277. package/src/tools/webbrowser/browserContent.js +281 -0
  278. package/src/tools/webbrowser/browserContent.ts +438 -0
  279. package/src/tools/webbrowser/browserControl.js +131 -30
  280. package/src/tools/webbrowser/browserControl.ts +210 -50
  281. package/src/tools/webbrowser/browserDaemon.js +22 -14
  282. package/src/tools/webbrowser/browserDaemon.ts +54 -21
  283. package/src/tools/webbrowser/browserFrames.js +47 -0
  284. package/src/tools/webbrowser/browserFrames.ts +54 -0
  285. package/src/tools/webbrowser/browserInteractionResolver.js +17 -0
  286. package/src/tools/webbrowser/browserInteractionResolver.ts +40 -0
  287. package/src/tools/webbrowser/browserLocator.js +140 -0
  288. package/src/tools/webbrowser/browserLocator.ts +194 -0
  289. package/src/tools/webbrowser/browserOutcome.js +10 -17
  290. package/src/tools/webbrowser/browserOutcome.ts +48 -31
  291. package/src/tools/webbrowser/browserRecovery.js +58 -0
  292. package/src/tools/webbrowser/browserRecovery.ts +83 -0
  293. package/src/tools/webbrowser/browserRunRegistry.js +35 -3
  294. package/src/tools/webbrowser/browserRunRegistry.ts +91 -15
  295. package/src/tools/webbrowser/browserService.js +28 -2
  296. package/src/tools/webbrowser/browserService.ts +49 -9
  297. package/src/tools/webbrowser/browserStream.js +132 -33
  298. package/src/tools/webbrowser/browserStream.ts +224 -50
  299. package/src/tools/webbrowser/browserTabs.js +48 -15
  300. package/src/tools/webbrowser/browserTabs.ts +178 -96
  301. package/src/tools/webbrowser/webbrowser.js +683 -144
  302. package/src/tools/webbrowser/webbrowser.ts +979 -236
  303. package/src/tools/webfetch/preapproved.js +0 -2
  304. package/src/tools/webfetch/preapproved.ts +0 -2
  305. package/src/tools/websearch/websearch.js +129 -8
  306. package/src/tools/websearch/websearch.ts +138 -6
  307. package/src/types.ts +450 -42
  308. package/src/ui/App.js +377 -58
  309. package/src/ui/App.tsx +576 -111
  310. package/src/ui/LiveArea.js +14 -8
  311. package/src/ui/LiveArea.tsx +14 -10
  312. package/src/ui/MessageList.js +63 -20
  313. package/src/ui/MessageList.tsx +101 -16
  314. package/src/ui/ModelPicker.js +7 -4
  315. package/src/ui/ModelPicker.tsx +55 -8
  316. package/src/ui/hooks/useChat.js +152 -163
  317. package/src/ui/hooks/useChat.ts +396 -334
  318. package/src/ui/loginCommand.js +56 -0
  319. package/src/ui/loginCommand.ts +63 -0
  320. package/src/ui/toolProgress.js +41 -0
  321. package/src/ui/toolProgress.ts +44 -0
  322. package/src/web/browserBridge.js +20 -2
  323. package/src/web/browserBridge.ts +20 -2
  324. package/src/web/protocol.ts +1897 -194
  325. package/workflows/adaptive-research/workflow.mjs +86 -0
  326. package/workflows/e2e-capabilities/workflow.mjs +102 -0
  327. package/workflows/e2e-llm/workflow.mjs +52 -0
  328. package/workflows/e2e-smoke/workflow.mjs +59 -0
  329. package/workflows/e2e-vision-schema/README.md +48 -0
  330. package/workflows/e2e-vision-schema/workflow.mjs +149 -0
  331. package/workflows/e2e-write-greet/workflow.mjs +37 -0
  332. package/workflows/file-census/README.md +14 -0
  333. package/workflows/file-census/scripts/.gitkeep +2 -0
  334. package/workflows/file-census/workflow.mjs +110 -0
  335. package/workflows/goal/README.md +166 -0
  336. package/workflows/goal/prompts/audit.md +57 -0
  337. package/workflows/goal/prompts/contract.md +56 -0
  338. package/workflows/goal/prompts/iterate.md +37 -0
  339. package/workflows/goal/workflow.mjs +501 -0
  340. package/workflows/illustrate/README.md +90 -0
  341. package/workflows/illustrate/assets/engines.json +20 -0
  342. package/workflows/illustrate/assets/extract-baidu.js +21 -0
  343. package/workflows/illustrate/assets/extract-bing.js +33 -0
  344. package/workflows/illustrate/assets/extract-google.js +31 -0
  345. package/workflows/illustrate/workflow.mjs +301 -0
  346. package/workflows/plan/workflow.mjs +389 -0
  347. package/workflows/question-crops/README.md +35 -0
  348. package/workflows/question-crops/prompts/inventory.md +23 -0
  349. package/workflows/question-crops/scripts/image-ops.mjs +305 -0
  350. package/workflows/question-crops/scripts/image-ops.test.mjs +95 -0
  351. package/workflows/question-crops/workflow.mjs +172 -0
  352. package/workflows/ralph-loop/workflow.mjs +162 -0
  353. package/workflows/research/DESIGN.md +449 -0
  354. package/workflows/research/README.md +74 -0
  355. package/workflows/research/prompts/s0-goal.md +43 -0
  356. package/workflows/research/prompts/s1-early-exit.md +22 -0
  357. package/workflows/research/prompts/s1-map.md +58 -0
  358. package/workflows/research/prompts/s2-options.md +53 -0
  359. package/workflows/research/prompts/s3-deep-dive.md +56 -0
  360. package/workflows/research/prompts/s4-verify.md +74 -0
  361. package/workflows/research/prompts/s5-synthesis.md +81 -0
  362. package/workflows/research/prompts/s5b-fill-gaps.md +32 -0
  363. package/workflows/research/prompts/s6-package.md +32 -0
  364. package/workflows/research/scripts/build-report.mjs +98 -0
  365. package/workflows/research/workflow.mjs +288 -0
  366. package/workflows/wechat-reading-shots/prompts/collect-params.md +16 -0
  367. package/workflows/wechat-reading-shots/prompts/evaluate.md +20 -0
  368. package/workflows/wechat-reading-shots/prompts/open-book.md +28 -0
  369. package/workflows/wechat-reading-shots/prompts/read-page.md +13 -0
  370. package/workflows/wechat-reading-shots/prompts/turn-batch.md +24 -0
  371. package/workflows/wechat-reading-shots/test/control-flow.test.ts +329 -0
  372. package/workflows/wechat-reading-shots/workflow.mjs +266 -0
  373. package/workflows/wrong-question-docx/README.md +55 -0
  374. package/workflows/wrong-question-docx/prompts/figure-qa.md +8 -0
  375. package/workflows/wrong-question-docx/prompts/transcribe.md +25 -0
  376. package/workflows/wrong-question-docx/scripts/workbook.mjs +857 -0
  377. package/workflows/wrong-question-docx/test/control-flow.test.ts +165 -0
  378. package/workflows/wrong-question-docx/test/workbook.test.mjs +303 -0
  379. package/workflows/wrong-question-docx/workflow.mjs +485 -0
  380. package/plugins/workflow-runner/src/agentCommon.js +0 -354
  381. package/plugins/workflow-runner/src/agentCommon.ts +0 -435
  382. package/plugins/workflow-runner/src/controlFlow/branch.js +0 -40
  383. package/plugins/workflow-runner/src/controlFlow/branch.ts +0 -46
  384. package/plugins/workflow-runner/src/controlFlow/loop.js +0 -211
  385. package/plugins/workflow-runner/src/controlFlow/loop.ts +0 -248
  386. package/plugins/workflow-runner/src/controlFlow/pause.js +0 -129
  387. package/plugins/workflow-runner/src/controlFlow/pause.ts +0 -141
  388. package/plugins/workflow-runner/src/controlFlow/signal.js +0 -21
  389. package/plugins/workflow-runner/src/controlFlow/signal.ts +0 -29
  390. package/plugins/workflow-runner/src/controlFlow/types.js +0 -18
  391. package/plugins/workflow-runner/src/controlFlow/types.ts +0 -63
  392. package/plugins/workflow-runner/src/dslManifest.js +0 -72
  393. package/plugins/workflow-runner/src/dslManifest.ts +0 -127
  394. package/plugins/workflow-runner/src/expressions.js +0 -618
  395. package/plugins/workflow-runner/src/expressions.ts +0 -622
  396. package/plugins/workflow-runner/src/loader.js +0 -573
  397. package/plugins/workflow-runner/src/loader.ts +0 -721
  398. package/plugins/workflow-runner/src/multimodal.js +0 -38
  399. package/plugins/workflow-runner/src/multimodal.ts +0 -64
  400. package/plugins/workflow-runner/src/recovery.js +0 -119
  401. package/plugins/workflow-runner/src/recovery.ts +0 -149
  402. package/plugins/workflow-runner/src/stepExecutors/agent.js +0 -173
  403. package/plugins/workflow-runner/src/stepExecutors/agent.ts +0 -234
  404. package/plugins/workflow-runner/src/stepExecutors/assert.js +0 -41
  405. package/plugins/workflow-runner/src/stepExecutors/assert.ts +0 -50
  406. package/plugins/workflow-runner/src/stepExecutors/echo.js +0 -31
  407. package/plugins/workflow-runner/src/stepExecutors/echo.ts +0 -38
  408. package/plugins/workflow-runner/src/stepExecutors/llm.js +0 -99
  409. package/plugins/workflow-runner/src/stepExecutors/llm.ts +0 -133
  410. package/plugins/workflow-runner/src/stepExecutors/set.js +0 -49
  411. package/plugins/workflow-runner/src/stepExecutors/set.ts +0 -56
  412. package/plugins/workflow-runner/src/stepExecutors/skill.js +0 -111
  413. package/plugins/workflow-runner/src/stepExecutors/skill.ts +0 -140
  414. package/plugins/workflow-runner/src/stepExecutors/tool.js +0 -208
  415. package/plugins/workflow-runner/src/stepExecutors/tool.ts +0 -256
  416. package/plugins/workflow-runner/src/stepExecutors/verify.js +0 -58
  417. package/plugins/workflow-runner/src/stepExecutors/verify.ts +0 -68
  418. package/plugins/workflow-runner/src/stepPipeline.js +0 -277
  419. package/plugins/workflow-runner/src/stepPipeline.ts +0 -366
  420. package/plugins/workflow-runner/test/agent.test.ts +0 -587
  421. package/plugins/workflow-runner/test/agentLlmError.test.ts +0 -373
  422. package/plugins/workflow-runner/test/bashBlacklist.sweep.test.ts +0 -65
  423. package/plugins/workflow-runner/test/captureMisbind.test.ts +0 -99
  424. package/plugins/workflow-runner/test/cli.e2e.test.ts +0 -147
  425. package/plugins/workflow-runner/test/context-files.test.ts +0 -320
  426. package/plugins/workflow-runner/test/e2e.test.ts +0 -370
  427. package/plugins/workflow-runner/test/engineRobustness.test.ts +0 -226
  428. package/plugins/workflow-runner/test/expressions.test.ts +0 -397
  429. package/plugins/workflow-runner/test/foundation.test.ts +0 -126
  430. package/plugins/workflow-runner/test/graceful.test.ts +0 -139
  431. package/plugins/workflow-runner/test/greedyInputs.load.test.ts +0 -47
  432. package/plugins/workflow-runner/test/hostCapability.test.ts +0 -108
  433. package/plugins/workflow-runner/test/illustrate.load.test.ts +0 -183
  434. package/plugins/workflow-runner/test/jsonPayload.test.ts +0 -83
  435. package/plugins/workflow-runner/test/loader.test.ts +0 -617
  436. package/plugins/workflow-runner/test/maxTurnsRetryDelay.test.ts +0 -33
  437. package/plugins/workflow-runner/test/multimodal.test.ts +0 -342
  438. package/plugins/workflow-runner/test/output-schema.test.ts +0 -213
  439. package/plugins/workflow-runner/test/parseWorkflowArgs.test.ts +0 -87
  440. package/plugins/workflow-runner/test/pluginRunner.isolation.test.ts +0 -269
  441. package/plugins/workflow-runner/test/ppt.load.test.ts +0 -1220
  442. package/plugins/workflow-runner/test/ralphLoop.e2e.test.ts +0 -220
  443. package/plugins/workflow-runner/test/recovery.test.ts +0 -265
  444. package/plugins/workflow-runner/test/runner.test.ts +0 -911
  445. package/plugins/workflow-runner/test/runnerPreflight.test.ts +0 -379
  446. package/plugins/workflow-runner/test/skillTurnDone.test.ts +0 -71
  447. package/plugins/workflow-runner/test/stateLifecycle.test.ts +0 -150
  448. package/plugins/workflow-runner/test/stepPipeline.test.ts +0 -114
  449. package/plugins/workflow-runner/test/taskArbitration.test.ts +0 -338
  450. package/plugins/workflow-runner/test/taskLifecycle.test.ts +0 -270
  451. package/plugins/workflow-runner/test/toolArtifactOverwrite.test.ts +0 -221
  452. package/plugins/workflow-runner/test/toolCapabilityBoundary.test.ts +0 -29
  453. package/plugins/workflow-runner/test/toolRuntimeIntegration.test.ts +0 -168
  454. package/plugins/workflow-runner/test/webppt.load.test.ts +0 -250
  455. package/plugins/workflow-runner/test/word.load.test.ts +0 -208
  456. package/plugins/workflow-runner/test/workflows.smoke.test.ts +0 -76
  457. package/plugins/workflow-runner/test/yamlGuardConditions.test.ts +0 -207
  458. package/src/advisorState.js +0 -22
  459. package/src/cli/configWizard.js +0 -293
  460. package/src/tools/toolProgressBridge.js +0 -48
  461. package/workflows/adaptive-research.yaml +0 -50
  462. package/workflows/book-review-short.yaml +0 -125
  463. package/workflows/e2e-write-greet.yaml +0 -31
  464. package/workflows/illustrate.yaml +0 -227
  465. package/workflows/plan.yaml +0 -470
  466. package/workflows/ppt.yaml +0 -1670
  467. package/workflows/ralph-loop.yaml +0 -199
  468. package/workflows/schema.json +0 -176
  469. package/workflows/webppt.yaml +0 -496
  470. package/workflows/wechat-reading-shots.yaml +0 -315
  471. package/workflows/word.yaml +0 -720
  472. package/workflows/youtube-shorts.yaml +0 -202
package/src/types.ts CHANGED
@@ -73,6 +73,19 @@ export interface ImageInputSpec {
73
73
  maxLongSidePixel?: number;
74
74
  }
75
75
 
76
+ /** Host-authorized file supplied for the current workflow invocation. */
77
+ export interface InvocationResource {
78
+ id: string;
79
+ origin: 'path' | 'attachment';
80
+ name: string;
81
+ mime: string;
82
+ size?: number;
83
+ sha256?: string;
84
+ localPath: string;
85
+ visionPath?: string;
86
+ kind: 'file' | 'directory';
87
+ }
88
+
76
89
  /**
77
90
  * 用户消息关联的附件展示元数据。
78
91
  *
@@ -105,6 +118,18 @@ export interface MessageBrowserReference {
105
118
  capturedAt: number;
106
119
  }
107
120
 
121
+ /** Local-only origin metadata used to keep one Session safe across private and group turns. */
122
+ export interface ConversationProvenance {
123
+ mode: 'private' | 'group';
124
+ visibility: 'owner-private' | 'group-public';
125
+ groupId?: string;
126
+ groupMessageId?: string;
127
+ senderId?: string;
128
+ senderName?: string;
129
+ taskId?: string;
130
+ grantId?: string;
131
+ }
132
+
108
133
  /**
109
134
  * 所有 Message variant 共享的可选字段。
110
135
  *
@@ -124,8 +149,7 @@ export type Message = (
124
149
  *
125
150
  * - saveContext(persistContext.ts)写盘前过滤掉 _ephemeral=true 的 system 消息
126
151
  * - MessageList 识别此标记走暗灰单行样式(其他 system 消息保持 hide)
127
- * - 其他场景(LLM 调用等)暂时不过滤;短消息无害,下个版本再做 runQuery 入参过滤
128
- * - 已知限制:本期 LLM 收到 ephemeral 消息(不影响功能,仅噪声)
152
+ * - provider 请求(包括本地与团队网关)会过滤掉这类消息
129
153
  */
130
154
  _ephemeral?: true;
131
155
  }
@@ -168,6 +192,8 @@ export type Message = (
168
192
  tool_call_id: string;
169
193
  /** 本地展示元数据;发送 Provider 前会剥离。 */
170
194
  display_metadata?: ToolResultMetadata;
195
+ /** 本地压缩策略;发送 Provider 前会剥离。 */
196
+ tool_result_policy?: ToolResultPolicy;
171
197
  timestamp?: number;
172
198
  }
173
199
  ) & {
@@ -177,6 +203,8 @@ export type Message = (
177
203
  * - 不发给 LLM:client.ts 在发送给 LLM 序列化消息前自动剔除。
178
204
  */
179
205
  id?: string;
206
+ /** Persisted locally, rendered as a trusted label for the model, never sent as a raw provider field. */
207
+ provenance?: ConversationProvenance;
180
208
  };
181
209
 
182
210
  // ---------------- 2. 工具 (Tool) ----------------
@@ -213,7 +241,12 @@ export interface AgentResultMetadata {
213
241
  };
214
242
  }
215
243
 
216
- export type FileActivityKind = 'read' | 'created' | 'modified' | 'generated' | 'deleted';
244
+ export type FileActivityKind =
245
+ | 'read'
246
+ | 'created'
247
+ | 'modified'
248
+ | 'generated'
249
+ | 'deleted';
217
250
  export type FileVerification = 'passed' | 'failed' | 'not_run';
218
251
  export type ConversationFilePurpose = 'source' | 'deliverable' | 'support';
219
252
  export interface FilePatchSummary {
@@ -257,7 +290,11 @@ export interface DeliverableManifest {
257
290
  purpose: 'deliverable';
258
291
  }>;
259
292
  links?: Array<{ url: string; title?: string }>;
260
- browserEvidence?: Array<{ tabId: string; url: string; screenshotId?: string }>;
293
+ browserEvidence?: Array<{
294
+ tabId: string;
295
+ url: string;
296
+ screenshotId?: string;
297
+ }>;
261
298
  warnings: string[];
262
299
  }
263
300
 
@@ -277,8 +314,18 @@ export interface ResultManifestMetadata {
277
314
  manifest: DeliverableManifest;
278
315
  }
279
316
 
280
- export type ProcessCommandKind = 'test' | 'typecheck' | 'build' | 'check' | 'other';
281
- export type ProcessExecutionStatus = 'started' | 'running' | 'completed' | 'failed' | 'stopped';
317
+ export type ProcessCommandKind =
318
+ | 'test'
319
+ | 'typecheck'
320
+ | 'build'
321
+ | 'check'
322
+ | 'other';
323
+ export type ProcessExecutionStatus =
324
+ | 'started'
325
+ | 'running'
326
+ | 'completed'
327
+ | 'failed'
328
+ | 'stopped';
282
329
 
283
330
  /** Structured process state shared by Bash, PowerShell, TaskOutput and the evidence ledger. */
284
331
  export interface ProcessExecutionMetadata {
@@ -291,10 +338,55 @@ export interface ProcessExecutionMetadata {
291
338
  exitCode?: number | null;
292
339
  }
293
340
 
341
+ export type AdvisorCheckpoint =
342
+ | 'pre-execution'
343
+ | 'stalled'
344
+ | 'high-risk'
345
+ | 'pre-delivery';
346
+
347
+ export interface AdvisorVersions {
348
+ taskVersion: number;
349
+ workVersion: number;
350
+ evidenceVersion: number;
351
+ }
352
+
353
+ export interface AdvisorCheckpointMetadata extends AdvisorVersions {
354
+ kind: 'advisor_checkpoint';
355
+ checkpoint: AdvisorCheckpoint;
356
+ checkpointKey: string;
357
+ status: 'required' | 'attempted-unavailable';
358
+ }
359
+
360
+ export interface AdvisorConsultationMetadata extends AdvisorVersions {
361
+ kind: 'advisor_consultation';
362
+ consultationId: string;
363
+ checkpoint: AdvisorCheckpoint;
364
+ checkpointKey: string;
365
+ status: 'completed' | 'failed';
366
+ }
367
+
368
+ export interface AdvisorDecisionMetadata extends AdvisorVersions {
369
+ kind: 'advisor_decision';
370
+ consultationId: string;
371
+ checkpoint: AdvisorCheckpoint;
372
+ checkpointKey: string;
373
+ decision: 'accept' | 'partial' | 'reject';
374
+ rationale: string;
375
+ acceptedPoints: string[];
376
+ rejectedPoints: string[];
377
+ verificationPlan: string[];
378
+ }
379
+
294
380
  /** Agent 子任务的结构化阶段进度;仅供宿主展示,不写入会话历史或发送给 LLM。 */
295
381
  export interface SubagentProgress {
296
382
  kind: 'subagent';
297
- phase: 'queued' | 'preparing' | 'analyzing' | 'using_tool' | 'drafting' | 'waiting_owner';
383
+ phase:
384
+ | 'queued'
385
+ | 'preparing'
386
+ | 'analyzing'
387
+ | 'using_tool'
388
+ | 'drafting'
389
+ | 'waiting_owner';
298
390
  queuePosition?: number;
299
391
  activeCount?: number;
300
392
  maxConcurrent?: number;
@@ -306,32 +398,73 @@ export interface SubagentProgress {
306
398
 
307
399
  export type ToolProgressDetail = SubagentProgress;
308
400
 
401
+ /** A browser download lives under the agent state root, not the workspace. */
402
+ export interface BrowserDownloadMetadata {
403
+ kind: 'browser_download';
404
+ downloads: Array<{
405
+ id: string;
406
+ url: string;
407
+ filename: string;
408
+ path: string;
409
+ state: 'start' | 'progress' | 'complete' | 'failed' | 'canceled';
410
+ mime?: string;
411
+ receivedBytes?: number;
412
+ totalBytes?: number;
413
+ error?: string;
414
+ }>;
415
+ /** Present when the batch requested `artifact.save_as`; the download is
416
+ * copied into the workspace and can be committed by the host as a normal
417
+ * conversation delivery. */
418
+ artifact?: DeliverableManifest;
419
+ }
420
+
309
421
  export type ToolResultMetadata =
310
422
  | AgentResultMetadata
311
423
  | FileActivityMetadata
312
424
  | FileDiscoveryMetadata
313
425
  | ResultManifestMetadata
314
- | ProcessExecutionMetadata;
426
+ | ProcessExecutionMetadata
427
+ | AdvisorCheckpointMetadata
428
+ | AdvisorConsultationMetadata
429
+ | AdvisorDecisionMetadata
430
+ | BrowserDownloadMetadata;
431
+
432
+ /**
433
+ * 本地工具结果压缩策略;只用于 history 决策和 UI 诊断,发送 provider 前剥离。
434
+ * highValue 优先级高于 reclaimable:高价值结果不会被 Path C 回收或中段截断。
435
+ */
436
+ export interface ToolResultPolicy {
437
+ reclaimable: boolean;
438
+ highValue: boolean;
439
+ archiveRef?: string;
440
+ originalChars?: number;
441
+ }
315
442
 
316
443
  export type ToolResult =
317
444
  | {
318
- ok: true;
319
- content: string;
320
- metadata?: ToolResultMetadata;
321
- recovery?: 'none' | 'retry' | 'change-input' | 'user-action';
322
- sensitivity?: 'public' | 'local' | 'sensitive';
323
- visionImages?: ImageInputSpec[];
324
- visionNote?: string;
325
- }
445
+ ok: true;
446
+ content: string;
447
+ metadata?: ToolResultMetadata;
448
+ /** 可选的本地上下文压缩策略;未提供时由工具名策略兜底。 */
449
+ policy?: ToolResultPolicy;
450
+ recovery?: 'none' | 'retry' | 'change-input' | 'user-action';
451
+ sensitivity?: 'public' | 'local' | 'sensitive';
452
+ visionImages?: ImageInputSpec[];
453
+ visionNote?: string;
454
+ }
326
455
  | {
327
- ok: false;
328
- error: string;
329
- metadata?: ToolResultMetadata;
330
- recovery?: 'none' | 'retry' | 'change-input' | 'user-action';
331
- sensitivity?: 'public' | 'local' | 'sensitive';
332
- visionImages?: ImageInputSpec[];
333
- visionNote?: string;
334
- };
456
+ ok: false;
457
+ error: string;
458
+ /** deferred 是宿主检查点暂缓,不是工具失败;失败统计与 stall guard 必须忽略。 */
459
+ disposition?: 'error' | 'deferred';
460
+ metadata?: ToolResultMetadata;
461
+ /** 可选的本地上下文压缩策略;未提供时由工具名策略兜底。 */
462
+ policy?: ToolResultPolicy;
463
+ recovery?: 'none' | 'retry' | 'change-input' | 'user-action';
464
+ sensitivity?: 'public' | 'local' | 'sensitive';
465
+ visionImages?: ImageInputSpec[];
466
+ visionNote?: string;
467
+ };
335
468
 
336
469
  // visionImages:工具想让(视觉)模型「亲眼看一下」的图像(如浏览器关键节点实况截图)。
337
470
  // 主循环在回填工具结果后,把它们组装成一条带图的 user 消息喂给模型自我核验(见 loop.ts)。
@@ -364,6 +497,8 @@ export interface ToolCallContext {
364
497
  advisorCalls?: { used: number; max: number };
365
498
  /** 区分主模型自动咨询与用户显式 /advisor ask。 */
366
499
  advisorInvocation?: 'agent' | 'manual';
500
+ /** Advisor 协调器运行时桥;只存在于主循环,不暴露给模型或持久化。 */
501
+ advisorRuntime?: AdvisorRuntimeBridge;
367
502
  /**
368
503
  * 主循环使用的 provider —— Agent 等「工具内部再起子查询」的派生工具用它
369
504
  * 跑嵌套 runQuery(子 agent 与主 agent 同一模型,不另配凭据)。
@@ -399,6 +534,8 @@ export interface ToolCallContext {
399
534
  cwd?: string;
400
535
  /** 本机记忆权限由宿主明确声明;不可信宿主必须为 denied。 */
401
536
  memoryAccess?: import('./runtime/agentRuntimeContext.js').MemoryAccessInput;
537
+ conversationMode?: import('./runtime/agentRuntimeContext.js').ConversationMode;
538
+ surface?: import('./runtime/agentRuntimeContext.js').AgentSurface;
402
539
  /**
403
540
  * Browser actions are scoped to the owning conversation/run by the host.
404
541
  * `supervised` 由宿主声明「存在可见浏览器 + 真人可接管/resume」(仅 Desktop 置 true):
@@ -459,6 +596,68 @@ export interface ToolCallContext {
459
596
  };
460
597
  }
461
598
 
599
+ export interface AdvisorContextPacket {
600
+ objective: string;
601
+ currentRequest: string;
602
+ checkpoint: AdvisorCheckpoint;
603
+ versions: AdvisorVersions;
604
+ changedFiles: string[];
605
+ evidence: string[];
606
+ previousAdvice?: string;
607
+ actionsAfterPreviousAdvice: string[];
608
+ openQuestions: string[];
609
+ }
610
+
611
+ export interface AdvisorRuntimeBridge {
612
+ /**
613
+ * 有值 = 存在一次已成功、但还没被 AdvisorDecision 结清的咨询——下一次
614
+ * Advisor 调用是对它的复核,而不是一次全新检查点的咨询。`advisor.ts`
615
+ * 用它判断复核调用是否该豁免配额(复核不该因为撞配额墙而被迫放弃、
616
+ * 反而把本该把关的检查点悄悄标记完成)。
617
+ */
618
+ readonly pendingConsultationId: string | undefined;
619
+ /** 同一检查点最多允许一次不占配额的证据冲突复核。 */
620
+ readonly canReconcileConsultation: boolean;
621
+ beginConsultation(): AdvisorConsultationMetadata;
622
+ finishConsultation(
623
+ metadata: AdvisorConsultationMetadata,
624
+ ok: boolean,
625
+ ): AdvisorConsultationMetadata;
626
+ recordDecision(input: {
627
+ consultationId: string;
628
+ decision: 'accept' | 'partial' | 'reject';
629
+ rationale: string;
630
+ acceptedPoints?: string[];
631
+ rejectedPoints?: string[];
632
+ verificationPlan?: string[];
633
+ }): ToolResult;
634
+ contextPacket(note?: string): AdvisorContextPacket;
635
+ }
636
+
637
+ export type ToolCategory =
638
+ | 'files'
639
+ | 'shell'
640
+ | 'web'
641
+ | 'desktop'
642
+ | 'agents'
643
+ | 'memory'
644
+ | 'media';
645
+
646
+ /**
647
+ * Compact, system-prompt-facing routing guidance.
648
+ *
649
+ * Tool descriptions identify the callable contract and parameter schemas
650
+ * describe fields. Selection boundaries live here so every active tool can
651
+ * be presented once in the system prompt without copying long descriptions.
652
+ */
653
+ export interface ToolPromptGuide {
654
+ category: ToolCategory;
655
+ useWhen: string;
656
+ method: string;
657
+ avoidWhen?: string;
658
+ priority?: 'preferred' | 'normal' | 'last-resort';
659
+ }
660
+
462
661
  export interface Tool<TInput = unknown> {
463
662
  /** 工具名,必须和 kakadeai 一致:'Read' / 'Edit' / 'Write' / 'Glob' / 'Grep' */
464
663
  name: string;
@@ -469,6 +668,13 @@ export interface Tool<TInput = unknown> {
469
668
  */
470
669
  description: string | (() => string);
471
670
 
671
+ /**
672
+ * Tool-selection guidance rendered into the system prompt. Built-in tools
673
+ * must provide it; optionality preserves compatibility with third-party
674
+ * plugins, whose first description sentence is used as a fallback.
675
+ */
676
+ promptGuide?: ToolPromptGuide;
677
+
472
678
  /** Zod schema:模型返回的 arguments JSON 会用它校验和解析 */
473
679
  inputSchema: z.ZodType<TInput>;
474
680
 
@@ -490,6 +696,10 @@ export interface Tool<TInput = unknown> {
490
696
  /** 输出超过这个字符数会被截断(防止把巨大文件灌进上下文) */
491
697
  maxResultSizeChars?: number;
492
698
 
699
+ /** Declarative host gates. Omitted means available in every mode/surface. */
700
+ availableInModes?: import('./runtime/agentRuntimeContext.js').ConversationMode[];
701
+ availableOnSurfaces?: import('./runtime/agentRuntimeContext.js').AgentSurface[];
702
+
493
703
  /** Synchronous host/runtime probe used before the tool is shown to the model. */
494
704
  resolveAvailability?(
495
705
  runtime: import('./runtime/agentRuntimeContext.js').AgentRuntimeContext,
@@ -518,7 +728,12 @@ export interface Tool<TInput = unknown> {
518
728
  gateRequest?(
519
729
  input: TInput | undefined,
520
730
  context: ToolCallContext,
521
- ): Partial<Pick<import('./toolGate.js').ToolGateRequest, 'isReadOnly' | 'runContext' | 'action'>>;
731
+ ): Partial<
732
+ Pick<
733
+ import('./toolGate.js').ToolGateRequest,
734
+ 'isReadOnly' | 'runContext' | 'action'
735
+ >
736
+ >;
522
737
 
523
738
  /**
524
739
  * 真正干活的函数。
@@ -550,16 +765,10 @@ export interface ToolAvailability {
550
765
  // MINIMAL_AGENT_PROVIDER - 友好名称(可选,默认 "env")
551
766
  // MINIMAL_AGENT_CONTEXT_WINDOW - 上下文窗口(可选,默认 128000)
552
767
 
553
- export interface Provider {
768
+ interface ProviderCommon {
554
769
  /** 友好名(仅展示用),如 "deepseek" */
555
770
  name: string;
556
771
 
557
- /** API 完整端点 URL,如 "https://api.deepseek.com/v1/chat/completions" */
558
- baseURL: string;
559
-
560
- /** API key(敏感信息,用户自己填) */
561
- apiKey: string;
562
-
563
772
  /** 模型 id,如 "deepseek-chat" */
564
773
  model: string;
565
774
 
@@ -603,7 +812,91 @@ export interface Provider {
603
812
  * 保守地不给可能非视觉的端点发图(免触发 400),并优雅降级(不截、不假装核验)。
604
813
  */
605
814
  supportsVision?: boolean;
815
+ /** Explicit provider declaration for reliable native JSON Schema output. */
816
+ supportsJsonSchema?: boolean;
606
817
  promptCache?: PromptCacheConfig;
818
+
819
+ /**
820
+ * 是否对 Anthropic 格式端点启用 cache_edits 式回收(对齐 kakadeai Cached MC)。
821
+ *
822
+ * **为什么默认关闭**:`cache_edits` content block(edits: [{type:'delete', cache_reference}])
823
+ * 不在 Anthropic 公开 Messages API 文档里(2023-06-01 版协议无此字段)——kakadeai 主项目
824
+ * 依赖其自建网关(Mycro)的服务端 KV 原地编辑能力。对着不支持的自定义/官方端点发送
825
+ * 未知 block 类型会 400。仅当 baseURL 指向支持该协议的网关时显式开启。
826
+ *
827
+ * 开启后(须同时 apiFormat === 'anthropic'):
828
+ * - reclaimOldToolResults 进入 cacheEdits 模式:**本地 history 不再被改写**,
829
+ * 回收决策只记入 pending 删除清单(CacheEditsState)。
830
+ * - anthropicFormat 请求组装时发送 cache_edits block,服务端在 KV 缓存内原地
831
+ * 删除这些 tool_result——模型实际看到的上下文变短,但前缀 hash 不变、
832
+ * 缓存命中完整保留(这是与 inline 占位符模式的本质区别)。
833
+ * - wire 上完整内容仍然发送(省的是服务端 KV 驻留与模型注意力窗口,不是请求体积)。
834
+ */
835
+ cacheEdits?: boolean;
836
+ }
837
+
838
+ /** Direct local provider descriptor. Vendor endpoint and key exist only here. */
839
+ export interface LocalProvider extends ProviderCommon {
840
+ source?: 'local';
841
+ /** API 完整端点 URL;仅本地 Provider 可拥有。 */
842
+ baseURL: string;
843
+ /** 本地模型 API key。 */
844
+ apiKey: string;
845
+ }
846
+
847
+ /** Runtime-only remote descriptor. It intentionally has no vendor endpoint or
848
+ * vendor credential fields; those exist only inside minimal-server. */
849
+ export interface GatewayProvider extends ProviderCommon {
850
+ source: 'gateway';
851
+ remoteModelId: string;
852
+ gatewayUrl: string;
853
+ gatewayToken: string;
854
+ /** Server-enforced upper bound for this remote model. */
855
+ gatewayMaxToolCategories?: string[];
856
+ /** Server-provided initial Session selection. */
857
+ gatewayDefaultToolCategories?: string[];
858
+ /** Server-declared provider capabilities used for local preflight UX. */
859
+ gatewayCapabilities?: {
860
+ vision: boolean;
861
+ tools: boolean;
862
+ structuredOutput: boolean;
863
+ };
864
+ /** Effective categories for the current turn; retained as the wire-facing
865
+ * compatibility field while callers migrate to the explicit fields. */
866
+ gatewayToolCategories?: string[];
867
+ }
868
+
869
+ export type Provider = LocalProvider | GatewayProvider;
870
+
871
+ /**
872
+ * cache_edits 式回收的运行时状态(Anthropic 格式 + provider.cacheEdits 开启时使用)。
873
+ *
874
+ * 放在 types.ts 而非 context/ 或 llm/ 的原因:context 层(microCompactLite,决策方)
875
+ * 与 llm 层(anthropicFormat,协议组装方)都要消费,放中立位置避免反向依赖。
876
+ *
877
+ * **下标稳定性契约**:pinned[].userMessageIndex 是 toAnthropicMessages() 翻译后数组
878
+ * 的下标。该契约依赖两个事实:history append-only(compact 时必须 resetCacheEdits),
879
+ * 且 toAnthropicMessages 是纯函数(同一份 history 翻译结果恒定)。旧消息的翻译后
880
+ * 下标因此跨轮稳定——cache_edits block 每轮必须重发在**原位置**,否则请求前缀
881
+ * 变化会破坏它本要保护的缓存(服务端无状态,指令须随每个请求重申)。
882
+ */
883
+ export interface CacheEditsState {
884
+ /** 已标记删除的 tool_call_id 集合(幂等:重复标记自动忽略) */
885
+ deletedToolIds: Set<string>;
886
+ /** 已 pin 的编辑批次:每轮请求在原 userMessageIndex 位置重发的删除指令 */
887
+ pinned: Array<{ userMessageIndex: number; toolUseIds: string[] }>;
888
+ /** 本轮新增、尚未随请求发送过的删除目标(发送即清空,发送后转入 pinned) */
889
+ pendingNew: string[];
890
+ /**
891
+ * 当前有效删除量(token 估算):服务端已删除、但本地 history 里仍完整存在的
892
+ * 工具结果内容的 token 总量。用于校正 autoCompact 的本地估算判据--cacheEdits
893
+ * 模式下 history 不瘦身,countMessagesTokens 会把这些已删内容重复计入,判据
894
+ * 虚高会导致压缩过早触发(压缩本身会重建整个前缀缓存,抵消 cacheEdits 的收益)。
895
+ *
896
+ * 生命周期:随每批删除累加;resetCacheEdits(compact/snip 后)清零--历史被
897
+ * 重写后旧账对应的已删内容可能已不在新历史里,继续减会过度校正。
898
+ */
899
+ activeDeletedTokens: number;
607
900
  }
608
901
 
609
902
  export type PromptCacheMode = 'auto' | 'session-key' | 'disabled';
@@ -694,6 +987,9 @@ export type LlmStreamEvent =
694
987
  /** 数组增量(reasoning_details) */
695
988
  items?: unknown[];
696
989
  }
990
+ /** Provider usage may arrive before the terminal event (not persisted in history). */
991
+ | { type: 'usage'; promptTokens?: number; outputTokens?: number }
992
+ // TurnResourceUsage 的定义在文件末尾附近(与 LoopEvent 同区),此处只是引用。
697
993
  /**
698
994
  * 流结束。
699
995
  *
@@ -716,6 +1012,17 @@ export type LlmStreamEvent =
716
1012
  type: 'done';
717
1013
  stopReason: 'stop' | 'tool_calls' | 'length' | 'unknown' | 'aborted';
718
1014
  promptTokens?: number;
1015
+ /**
1016
+ * 本轮**真实**输出 token 数(OpenAI `completion_tokens` / Anthropic `output_tokens`)。
1017
+ *
1018
+ * 与 promptTokens 同一条纪律:**provider 不报就是 undefined,绝不填 0**。
1019
+ * 填 0 会被上层预算刻度读成「这轮没花钱」,于是预算闸永远不触发 ——
1020
+ * 那比没有预算更危险,因为它看起来在工作。
1021
+ *
1022
+ * 用途:喂给回合级资源账本(`TurnResourceUsage`),再由 Goal 的轮次边界预算闸消费。
1023
+ * ⚠️ 它**不参与**自动压缩判定 —— 压缩只看 prompt 侧。
1024
+ */
1025
+ outputTokens?: number;
719
1026
  cachedPromptTokens?: number;
720
1027
  cacheMissTokens?: number;
721
1028
  cacheWriteTokens?: number;
@@ -780,6 +1087,35 @@ export interface ToolStatusState {
780
1087
  progressDetail?: ToolProgressDetail;
781
1088
  }
782
1089
 
1090
+ /**
1091
+ * 一个**用户回合**(不是一个 TAOR 迭代)累计消耗的资源。
1092
+ *
1093
+ * 语义边界,改之前先读:
1094
+ * - 「一回合」= 从用户输入到模型不再调工具为止,中间可能有几十次 LLM 请求。
1095
+ * - 它是**账本**不是闸门。loop 只负责记账,**绝不因为它中断进行中的工具循环** ——
1096
+ * 预算判定一律发生在「要不要开新一轮」的边界上(goal / ralph-loop 这类多轮工作流
1097
+ * 在循环开头调 `budget()`)。这条是产品决策:宁可超一点预算,也不能把 agent
1098
+ * 停在半成品状态。
1099
+ *
1100
+ * ⚠️ **消费前必须先看 `trustworthy`**。不是所有 provider 都回报 usage
1101
+ * (OpenAI 需要 `stream_options.include_usage`,部分兼容实现直接不发)。
1102
+ * 少报会让预算闸永远不触发 —— 那比没有预算更危险,因为它看起来在工作。
1103
+ * 所以这里如实区分「真的是 0」与「没人告诉我」:不报的调用不计入,
1104
+ * 由 `reportedCalls / totalCalls` 暴露这份账本的覆盖率。
1105
+ */
1106
+ export interface TurnResourceUsage {
1107
+ /** 累计输入 token(仅统计真实报告了 usage 的那些调用)。 */
1108
+ inputTokens: number;
1109
+ /** 累计输出 token(同上)。 */
1110
+ outputTokens: number;
1111
+ /** 本回合发出的 LLM 请求总数。 */
1112
+ totalCalls: number;
1113
+ /** 其中真实回报了 usage 的次数。 */
1114
+ reportedCalls: number;
1115
+ /** `totalCalls > 0 && reportedCalls === totalCalls` —— 只有全报了才算这份账可信。 */
1116
+ trustworthy: boolean;
1117
+ }
1118
+
783
1119
  export type LoopEvent =
784
1120
  /** 文本流(同 LlmStreamEvent.text_delta) */
785
1121
  | { type: 'text'; delta: string }
@@ -792,9 +1128,24 @@ export type LoopEvent =
792
1128
  * <Static> 直到整轮落定才一次性 commit「用户消息+reasoning+答案」,用户输入无法第一时间置顶。
793
1129
  * UI 收到此事件立即 bump,让 <Static> 马上把用户消息 commit 进 scrollback(符合 T-A-O-R 顺序)。
794
1130
  */
795
- | { type: 'user_message_committed'; message?: Extract<Message, { role: 'user' }> }
1131
+ | {
1132
+ type: 'user_message_committed';
1133
+ message?: Extract<Message, { role: 'user' }>;
1134
+ }
796
1135
  /** 一轮 assistant 消息已完整组装(含可能的 tool_calls) */
797
- | { type: 'assistant_message'; message: Extract<Message, { role: 'assistant' }> }
1136
+ | {
1137
+ type: 'assistant_message';
1138
+ message: Extract<Message, { role: 'assistant' }>;
1139
+ }
1140
+ /**
1141
+ * 模型已经流出了一份正文/思考草稿,但宿主确定它还不能成为本轮回答。
1142
+ * 消费方应清掉 live 草稿;该草稿不会写入会话 history。
1143
+ */
1144
+ | {
1145
+ type: 'assistant_draft_discarded';
1146
+ reason: 'formal_delivery' | 'advisor_checkpoint' | 'empty_response';
1147
+ textLength: number;
1148
+ }
798
1149
  /**
799
1150
  * 主循环在工具结果之后注入的「带外上下文消息」(当前用于浏览器关键节点实况截图回填)。
800
1151
  * 宿主收到后应把它当作一条消息追加进对话展示;模型也会在下一轮看到它(已 push 进 history)。
@@ -871,8 +1222,25 @@ export type LoopEvent =
871
1222
  /** 整轮交互结束(模型不再调工具) */
872
1223
  | {
873
1224
  type: 'turn_done';
874
- completionStatus?: 'completed' | 'delivery_incomplete' | 'delivery_unverified' | 'claims_unverified';
1225
+ completionStatus?:
1226
+ | 'completed'
1227
+ | 'delivery_incomplete'
1228
+ | 'delivery_unverified'
1229
+ | 'claims_unverified';
875
1230
  warning?: string;
1231
+ /** 本回合的资源账本。见 TurnResourceUsage —— 消费方务必先看 `trustworthy`。 */
1232
+ usage?: TurnResourceUsage;
1233
+ /**
1234
+ * 托管运行时(`meta.managedRuntime`,目前只有 goal)的生命周期状态。
1235
+ *
1236
+ * ⚠️ 它与 `completionStatus` 回答的**不是同一个问题**,别合并:
1237
+ * · completionStatus = 模型宣称的事做没做(交付判定)
1238
+ * · managedStatus = 这件事**有没有被人验收**(生命周期事实源)
1239
+ * `completionStatus:'completed'` + `managedStatus:'ready_for_acceptance'`
1240
+ * 是正常且重要的组合:机器自检通过,但还没有人点头。
1241
+ * 取值与映射见 `src/goal/statusMapping.ts`。
1242
+ */
1243
+ managedStatus?: string;
876
1244
  }
877
1245
  /**
878
1246
  * 中断事件
@@ -885,16 +1253,28 @@ export type LoopEvent =
885
1253
  *
886
1254
  * code(v2.x 新增,可选):让 `-p --output-format json` 把终结原因映射成稳定的
887
1255
  * stop_reason,也让 print.ts 区分"致命错误(退出)"与"非致命警告(继续)":
888
- * - 'llm_error' LLM 调用失败 → 终结,stop_reason='error'
889
- * - 'max_turns' 撞最大轮数上限 → 终结,stop_reason='max_turns'
890
- * - 'compact_failed' 自动压缩失败但 loop 想继续 → 非致命,print.ts 只 stderr 警告不退出
891
- * - 'aborted' 被中断(signal.aborted)
1256
+ * - 'llm_error' LLM 调用失败 → 终结,stop_reason='error'
1257
+ * - 'max_turns' 撞最大轮数上限 → 终结,stop_reason='max_turns'
1258
+ * - 'compact_failed' 自动压缩失败但 loop 想继续 → 非致命,print.ts 只 stderr 警告不退出
1259
+ * - 'aborted' 被中断(signal.aborted)
1260
+ * - 'stalled' StallGuard 判定原地打转(同一失败反复 / 整批调用无进展)
1261
+ * → 终结,stop_reason='stalled'
1262
+ * - 'context_overflow' 即使降级后仍超模型输入上限,主动不发这次请求
1263
+ * → 终结,stop_reason='error'
892
1264
  * 缺省(旧调用方 / 未分类错误)按致命、stop_reason='error' 处理。
1265
+ * ⚠️ 增删 code 时同步改 print.ts 的映射:那里只特判 max_turns / stalled,
1266
+ * 其余一律落 'error',新增的终结原因不特判就会被并进通用 error。
893
1267
  */
894
1268
  | {
895
1269
  type: 'error';
896
1270
  error: string;
897
- code?: 'llm_error' | 'max_turns' | 'compact_failed' | 'aborted' | 'stalled' | 'context_overflow';
1271
+ code?:
1272
+ | 'llm_error'
1273
+ | 'max_turns'
1274
+ | 'compact_failed'
1275
+ | 'aborted'
1276
+ | 'stalled'
1277
+ | 'context_overflow';
898
1278
  }
899
1279
  /**
900
1280
  * 非致命警告:需冒泡给用户但不终止执行。
@@ -923,6 +1303,23 @@ export type LoopEvent =
923
1303
  max?: number;
924
1304
  message?: string;
925
1305
  }
1306
+ | {
1307
+ type: 'workflow_progress';
1308
+ workflow: string;
1309
+ runId: string;
1310
+ rootRunId: string;
1311
+ parentRunId?: string;
1312
+ depth?: number;
1313
+ phase: string;
1314
+ status: 'start' | 'update' | 'complete' | 'warning';
1315
+ current?: number;
1316
+ total?: number;
1317
+ succeeded?: number;
1318
+ failed?: number;
1319
+ message?: string;
1320
+ queuedMs?: number;
1321
+ elapsedMs?: number;
1322
+ }
926
1323
  /**
927
1324
  * 思维链流式片段。
928
1325
  *
@@ -953,8 +1350,19 @@ export type LoopEvent =
953
1350
  * 让远程通道(webchat / 网关)收到问题、渲染选择、把答案经 stdin 的 `ask_answer` 回灌。
954
1351
  * requestId 用于关联问题与答案(一轮内可多次提问)。
955
1352
  */
956
- | { type: 'ask'; requestId: string; questions: AskQuestionSpec[]; source?: AskSource }
1353
+ | {
1354
+ type: 'ask';
1355
+ requestId: string;
1356
+ questions: AskQuestionSpec[];
1357
+ source?: AskSource;
1358
+ }
957
1359
  /** 问题在本回合所有者队列中的状态;不写入 Session 历史。 */
958
- | { type: 'ask_status'; source: AskSource; state: AskQueueState; queuePosition?: number; queuedCount?: number };
1360
+ | {
1361
+ type: 'ask_status';
1362
+ source: AskSource;
1363
+ state: AskQueueState;
1364
+ queuePosition?: number;
1365
+ queuedCount?: number;
1366
+ };
959
1367
  // 注:插件私有事件(如 workflow-runner 的 workflow_*)不再写在这里。
960
1368
  // 插件通过 PluginEvent 开放契约 yield 任意 type 字符串的事件,UI 静默忽略未识别项。