@ai-agent-forge/agent-forge 0.88.0 → 0.88.2

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 (445) hide show
  1. package/CHANGELOG.md +73 -0
  2. package/bundled-plugins/agent-loop-policy/agent-forge.json +19 -0
  3. package/bundled-plugins/agent-loop-policy/dist/entry.d.ts +28 -0
  4. package/bundled-plugins/agent-loop-policy/dist/entry.d.ts.map +1 -0
  5. package/bundled-plugins/agent-loop-policy/dist/entry.js +69 -0
  6. package/bundled-plugins/agent-loop-policy/dist/entry.js.map +1 -0
  7. package/bundled-plugins/agent-loop-policy/dist/loop-guard.d.ts +199 -0
  8. package/bundled-plugins/agent-loop-policy/dist/loop-guard.d.ts.map +1 -0
  9. package/bundled-plugins/agent-loop-policy/dist/loop-guard.js +208 -0
  10. package/bundled-plugins/agent-loop-policy/dist/loop-guard.js.map +1 -0
  11. package/bundled-plugins/agent-loop-policy/dist/run-loop-strategy.d.ts +17 -0
  12. package/bundled-plugins/agent-loop-policy/dist/run-loop-strategy.d.ts.map +1 -0
  13. package/bundled-plugins/agent-loop-policy/dist/run-loop-strategy.js +18 -0
  14. package/bundled-plugins/agent-loop-policy/dist/run-loop-strategy.js.map +1 -0
  15. package/bundled-plugins/agent-loop-policy/plugin.json +7 -0
  16. package/bundled-plugins/coding-tools/agent-forge.json +19 -0
  17. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/bash.d.ts +5 -44
  18. package/bundled-plugins/coding-tools/dist/bash.d.ts.map +1 -0
  19. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/bash.js +15 -119
  20. package/bundled-plugins/coding-tools/dist/bash.js.map +1 -0
  21. package/bundled-plugins/coding-tools/dist/capability.d.ts +25 -0
  22. package/bundled-plugins/coding-tools/dist/capability.d.ts.map +1 -0
  23. package/bundled-plugins/coding-tools/dist/capability.js +98 -0
  24. package/bundled-plugins/coding-tools/dist/capability.js.map +1 -0
  25. package/bundled-plugins/coding-tools/dist/config.d.ts +8 -0
  26. package/bundled-plugins/coding-tools/dist/config.d.ts.map +1 -0
  27. package/bundled-plugins/coding-tools/dist/config.js +8 -0
  28. package/bundled-plugins/coding-tools/dist/config.js.map +1 -0
  29. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/edit.d.ts +3 -3
  30. package/bundled-plugins/coding-tools/dist/edit.d.ts.map +1 -0
  31. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/edit.js +12 -10
  32. package/bundled-plugins/coding-tools/dist/edit.js.map +1 -0
  33. package/bundled-plugins/coding-tools/dist/entry.d.ts +14 -0
  34. package/bundled-plugins/coding-tools/dist/entry.d.ts.map +1 -0
  35. package/bundled-plugins/coding-tools/dist/entry.js +23 -0
  36. package/bundled-plugins/coding-tools/dist/entry.js.map +1 -0
  37. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/find.d.ts +4 -4
  38. package/bundled-plugins/coding-tools/dist/find.d.ts.map +1 -0
  39. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/find.js +10 -8
  40. package/bundled-plugins/coding-tools/dist/find.js.map +1 -0
  41. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/grep.d.ts +3 -3
  42. package/bundled-plugins/coding-tools/dist/grep.d.ts.map +1 -0
  43. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/grep.js +10 -8
  44. package/bundled-plugins/coding-tools/dist/grep.js.map +1 -0
  45. package/bundled-plugins/coding-tools/dist/index.d.ts +17 -0
  46. package/bundled-plugins/coding-tools/dist/index.d.ts.map +1 -0
  47. package/bundled-plugins/coding-tools/dist/index.js +17 -0
  48. package/bundled-plugins/coding-tools/dist/index.js.map +1 -0
  49. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/ls.d.ts +3 -3
  50. package/bundled-plugins/coding-tools/dist/ls.d.ts.map +1 -0
  51. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/ls.js +8 -6
  52. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/ls.js.map +1 -1
  53. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/powershell.d.ts +2 -1
  54. package/bundled-plugins/coding-tools/dist/powershell.d.ts.map +1 -0
  55. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/powershell.js +6 -3
  56. package/bundled-plugins/coding-tools/dist/powershell.js.map +1 -0
  57. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/read.d.ts +3 -3
  58. package/bundled-plugins/coding-tools/dist/read.d.ts.map +1 -0
  59. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/read.js +15 -13
  60. package/bundled-plugins/coding-tools/dist/read.js.map +1 -0
  61. package/bundled-plugins/coding-tools/dist/types.d.ts +74 -0
  62. package/bundled-plugins/coding-tools/dist/types.d.ts.map +1 -0
  63. package/bundled-plugins/coding-tools/dist/types.js +28 -0
  64. package/bundled-plugins/coding-tools/dist/types.js.map +1 -0
  65. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/write.d.ts +2 -2
  66. package/bundled-plugins/coding-tools/dist/write.d.ts.map +1 -0
  67. package/{dist/core/tools → bundled-plugins/coding-tools/dist}/write.js +11 -9
  68. package/bundled-plugins/coding-tools/dist/write.js.map +1 -0
  69. package/bundled-plugins/coding-tools/plugin.json +10 -0
  70. package/bundled-plugins/compaction-policy/agent-forge.json +19 -0
  71. package/bundled-plugins/compaction-policy/dist/branch-summary-policy.d.ts +6 -0
  72. package/bundled-plugins/compaction-policy/dist/branch-summary-policy.d.ts.map +1 -0
  73. package/bundled-plugins/compaction-policy/dist/branch-summary-policy.js +19 -0
  74. package/bundled-plugins/compaction-policy/dist/branch-summary-policy.js.map +1 -0
  75. package/bundled-plugins/compaction-policy/dist/compaction-policy.d.ts +6 -0
  76. package/bundled-plugins/compaction-policy/dist/compaction-policy.d.ts.map +1 -0
  77. package/bundled-plugins/compaction-policy/dist/compaction-policy.js +38 -0
  78. package/bundled-plugins/compaction-policy/dist/compaction-policy.js.map +1 -0
  79. package/bundled-plugins/compaction-policy/dist/entry.d.ts +13 -0
  80. package/bundled-plugins/compaction-policy/dist/entry.d.ts.map +1 -0
  81. package/bundled-plugins/compaction-policy/dist/entry.js +23 -0
  82. package/bundled-plugins/compaction-policy/dist/entry.js.map +1 -0
  83. package/bundled-plugins/compaction-policy/plugin.json +10 -0
  84. package/bundled-plugins/mcp-http/dist/index.d.ts +8 -0
  85. package/bundled-plugins/mcp-http/dist/index.d.ts.map +1 -0
  86. package/bundled-plugins/mcp-http/dist/index.js +8 -0
  87. package/bundled-plugins/mcp-http/dist/index.js.map +1 -0
  88. package/bundled-plugins/mcp-http/dist/mcp-http.d.ts.map +1 -0
  89. package/{dist/plugins → bundled-plugins/mcp-http/dist}/mcp-http.js +1 -1
  90. package/bundled-plugins/mcp-http/dist/mcp-http.js.map +1 -0
  91. package/bundled-plugins/overflow-policy/agent-forge.json +19 -0
  92. package/bundled-plugins/overflow-policy/dist/entry.d.ts +16 -0
  93. package/bundled-plugins/overflow-policy/dist/entry.d.ts.map +1 -0
  94. package/bundled-plugins/overflow-policy/dist/entry.js +35 -0
  95. package/bundled-plugins/overflow-policy/dist/entry.js.map +1 -0
  96. package/bundled-plugins/overflow-policy/plugin.json +10 -0
  97. package/bundled-plugins/provider-failover/agent-forge.json +19 -0
  98. package/bundled-plugins/provider-failover/dist/entry.d.ts +8 -0
  99. package/bundled-plugins/provider-failover/dist/entry.d.ts.map +1 -0
  100. package/bundled-plugins/provider-failover/dist/entry.js +8 -0
  101. package/bundled-plugins/provider-failover/dist/entry.js.map +1 -0
  102. package/bundled-plugins/provider-failover/dist/provider-failover.d.ts +122 -0
  103. package/bundled-plugins/provider-failover/dist/provider-failover.d.ts.map +1 -0
  104. package/{dist/core/extensions → bundled-plugins/provider-failover/dist}/provider-failover.js +143 -56
  105. package/bundled-plugins/provider-failover/dist/provider-failover.js.map +1 -0
  106. package/bundled-plugins/provider-failover/plugin.json +7 -0
  107. package/bundled-plugins/retry-policy/agent-forge.json +19 -0
  108. package/bundled-plugins/retry-policy/dist/entry.d.ts +16 -0
  109. package/bundled-plugins/retry-policy/dist/entry.d.ts.map +1 -0
  110. package/bundled-plugins/retry-policy/dist/entry.js +34 -0
  111. package/bundled-plugins/retry-policy/dist/entry.js.map +1 -0
  112. package/bundled-plugins/retry-policy/plugin.json +10 -0
  113. package/dist/bundle/.build-manifest.json +109 -155
  114. package/dist/bundle/chunks/{anthropic-messages-ALDZBUKI.js → anthropic-messages-PLAKXR73.js} +1 -1
  115. package/dist/bundle/chunks/{azure-openai-responses-A2WJWZFB.js → azure-openai-responses-OUWQ2AZD.js} +1 -1
  116. package/dist/bundle/chunks/chunk-44I47ACN.js +13 -0
  117. package/dist/bundle/chunks/chunk-6F5JWGKE.js +4 -0
  118. package/dist/bundle/chunks/{chunk-CIX3FSBK.js → chunk-A3JYRWB6.js} +1 -1
  119. package/dist/bundle/chunks/{chunk-SQFG22WN.js → chunk-AC2FIS4G.js} +1 -1
  120. package/dist/bundle/chunks/chunk-HTC5K5SM.js +866 -0
  121. package/dist/bundle/chunks/{chunk-YJCQVXW5.js → chunk-HTEVUY7F.js} +1 -1
  122. package/dist/bundle/chunks/{chunk-Y7HXTASS.js → chunk-HV64ASMT.js} +1 -1
  123. package/dist/bundle/chunks/chunk-LSP24WNH.js +665 -0
  124. package/dist/bundle/chunks/{chunk-7ZY7IXZD.js → chunk-TRDNDS6A.js} +1 -1
  125. package/dist/bundle/chunks/{google-generative-ai-NIB4WONV.js → google-generative-ai-DLII6DAT.js} +1 -1
  126. package/dist/bundle/chunks/{google-vertex-DCPYUEUO.js → google-vertex-G7BZL7GM.js} +1 -1
  127. package/dist/bundle/chunks/image-resize-worker.js +4 -4
  128. package/dist/bundle/chunks/{mistral-conversations-OC6LA5XL.js → mistral-conversations-JXUK24ID.js} +1 -1
  129. package/dist/bundle/chunks/{openai-codex-responses-IO2X4Y7L.js → openai-codex-responses-5GSGFIPG.js} +1 -1
  130. package/dist/bundle/chunks/{openai-completions-XYQQHETU.js → openai-completions-EI2I6DTG.js} +1 -1
  131. package/dist/bundle/chunks/{openai-responses-DLIRN3CI.js → openai-responses-AUJQ3NWT.js} +1 -1
  132. package/dist/bundle/chunks/{pi-messages-E6RRYBO7.js → pi-messages-PWU2VJMR.js} +1 -1
  133. package/dist/bundle/chunks/virtual-modules-MRXD3RWG.js +5 -0
  134. package/dist/bundle/cli.js +1 -1
  135. package/dist/bundle/client.js +1 -1
  136. package/dist/bundle/index.js +3 -3
  137. package/dist/bundle/rpc-entry.js +1 -1
  138. package/dist/capabilities/builtin.d.ts +1 -1
  139. package/dist/capabilities/builtin.d.ts.map +1 -1
  140. package/dist/capabilities/builtin.js +5 -0
  141. package/dist/capabilities/builtin.js.map +1 -1
  142. package/dist/cli/plugin-command.d.ts.map +1 -1
  143. package/dist/cli/plugin-command.js +25 -3
  144. package/dist/cli/plugin-command.js.map +1 -1
  145. package/dist/config.d.ts +2 -3
  146. package/dist/config.d.ts.map +1 -1
  147. package/dist/config.js +2 -4
  148. package/dist/config.js.map +1 -1
  149. package/dist/core/agent-session-bash.d.ts +1 -1
  150. package/dist/core/agent-session-bash.d.ts.map +1 -1
  151. package/dist/core/agent-session-bash.js +1 -1
  152. package/dist/core/agent-session-bash.js.map +1 -1
  153. package/dist/core/agent-session-compaction.d.ts.map +1 -1
  154. package/dist/core/agent-session-compaction.js +14 -1
  155. package/dist/core/agent-session-compaction.js.map +1 -1
  156. package/dist/core/agent-session-internal.d.ts +3 -1
  157. package/dist/core/agent-session-internal.d.ts.map +1 -1
  158. package/dist/core/agent-session-internal.js.map +1 -1
  159. package/dist/core/agent-session-loop.d.ts +4 -3
  160. package/dist/core/agent-session-loop.d.ts.map +1 -1
  161. package/dist/core/agent-session-loop.js +9 -6
  162. package/dist/core/agent-session-loop.js.map +1 -1
  163. package/dist/core/agent-session-retry.d.ts +1 -1
  164. package/dist/core/agent-session-retry.d.ts.map +1 -1
  165. package/dist/core/agent-session-retry.js +32 -3
  166. package/dist/core/agent-session-retry.js.map +1 -1
  167. package/dist/core/agent-session-services.d.ts +2 -0
  168. package/dist/core/agent-session-services.d.ts.map +1 -1
  169. package/dist/core/agent-session-services.js +31 -9
  170. package/dist/core/agent-session-services.js.map +1 -1
  171. package/dist/core/agent-session-store.d.ts.map +1 -1
  172. package/dist/core/agent-session-store.js +6 -1
  173. package/dist/core/agent-session-store.js.map +1 -1
  174. package/dist/core/agent-session-tools.d.ts.map +1 -1
  175. package/dist/core/agent-session-tools.js +18 -1
  176. package/dist/core/agent-session-tools.js.map +1 -1
  177. package/dist/core/agent-session.d.ts +34 -11
  178. package/dist/core/agent-session.d.ts.map +1 -1
  179. package/dist/core/agent-session.js +114 -38
  180. package/dist/core/agent-session.js.map +1 -1
  181. package/dist/core/bash-executor.d.ts +1 -1
  182. package/dist/core/bash-executor.d.ts.map +1 -1
  183. package/dist/core/bash-executor.js.map +1 -1
  184. package/dist/core/extensions/bootstrap-agent-loop.d.ts +23 -151
  185. package/dist/core/extensions/bootstrap-agent-loop.d.ts.map +1 -1
  186. package/dist/core/extensions/bootstrap-agent-loop.js +28 -290
  187. package/dist/core/extensions/bootstrap-agent-loop.js.map +1 -1
  188. package/dist/core/extensions/capability-runtime-types.d.ts +5 -3
  189. package/dist/core/extensions/capability-runtime-types.d.ts.map +1 -1
  190. package/dist/core/extensions/capability-runtime-types.js.map +1 -1
  191. package/dist/core/extensions/capability-runtime.d.ts.map +1 -1
  192. package/dist/core/extensions/capability-runtime.js +42 -6
  193. package/dist/core/extensions/capability-runtime.js.map +1 -1
  194. package/dist/core/extensions/index.d.ts +12 -5
  195. package/dist/core/extensions/index.d.ts.map +1 -1
  196. package/dist/core/extensions/index.js +12 -5
  197. package/dist/core/extensions/index.js.map +1 -1
  198. package/dist/core/extensions/virtual-modules.d.ts.map +1 -1
  199. package/dist/core/extensions/virtual-modules.js +65 -0
  200. package/dist/core/extensions/virtual-modules.js.map +1 -1
  201. package/dist/core/facade/coding-agent-facade.d.ts +1 -1
  202. package/dist/core/facade/coding-agent-facade.d.ts.map +1 -1
  203. package/dist/core/facade/coding-agent-facade.js.map +1 -1
  204. package/dist/core/i18n/locales/zh-cn/cli.d.ts.map +1 -1
  205. package/dist/core/i18n/locales/zh-cn/cli.js +2 -0
  206. package/dist/core/i18n/locales/zh-cn/cli.js.map +1 -1
  207. package/dist/core/i18n/locales/zh-cn/core-contract-core.d.ts +1 -1
  208. package/dist/core/i18n/locales/zh-cn/core-contract-core.d.ts.map +1 -1
  209. package/dist/core/i18n/locales/zh-cn/core-contract-core.js +1 -1
  210. package/dist/core/i18n/locales/zh-cn/core-contract-core.js.map +1 -1
  211. package/dist/core/i18n/locales/zh-cn/core-contract-extensions.d.ts.map +1 -1
  212. package/dist/core/i18n/locales/zh-cn/core-contract-extensions.js +2 -4
  213. package/dist/core/i18n/locales/zh-cn/core-contract-extensions.js.map +1 -1
  214. package/dist/core/i18n/locales/zh-cn/core-errors.d.ts.map +1 -1
  215. package/dist/core/i18n/locales/zh-cn/core-errors.js +3 -1
  216. package/dist/core/i18n/locales/zh-cn/core-errors.js.map +1 -1
  217. package/dist/core/i18n/locales/zh-cn/index.d.ts.map +1 -1
  218. package/dist/core/i18n/locales/zh-cn/index.js +2 -0
  219. package/dist/core/i18n/locales/zh-cn/index.js.map +1 -1
  220. package/dist/core/i18n/locales/zh-cn/interactive-mode.d.ts.map +1 -1
  221. package/dist/core/i18n/locales/zh-cn/interactive-mode.js +5 -0
  222. package/dist/core/i18n/locales/zh-cn/interactive-mode.js.map +1 -1
  223. package/dist/core/i18n/locales/zh-cn/session-cleanup.d.ts +7 -0
  224. package/dist/core/i18n/locales/zh-cn/session-cleanup.d.ts.map +1 -0
  225. package/dist/core/i18n/locales/zh-cn/session-cleanup.js +15 -0
  226. package/dist/core/i18n/locales/zh-cn/session-cleanup.js.map +1 -0
  227. package/dist/core/i18n/locales/zh-cn/slash-commands.d.ts.map +1 -1
  228. package/dist/core/i18n/locales/zh-cn/slash-commands.js +1 -0
  229. package/dist/core/i18n/locales/zh-cn/slash-commands.js.map +1 -1
  230. package/dist/core/sdk.d.ts +10 -3
  231. package/dist/core/sdk.d.ts.map +1 -1
  232. package/dist/core/sdk.js +287 -78
  233. package/dist/core/sdk.js.map +1 -1
  234. package/dist/core/session-cleanup.d.ts +49 -0
  235. package/dist/core/session-cleanup.d.ts.map +1 -0
  236. package/dist/core/session-cleanup.js +159 -0
  237. package/dist/core/session-cleanup.js.map +1 -0
  238. package/dist/core/session-index.d.ts +75 -0
  239. package/dist/core/session-index.d.ts.map +1 -0
  240. package/dist/core/session-index.js +455 -0
  241. package/dist/core/session-index.js.map +1 -0
  242. package/dist/core/session-manager.d.ts +9 -0
  243. package/dist/core/session-manager.d.ts.map +1 -1
  244. package/dist/core/session-manager.js +202 -47
  245. package/dist/core/session-manager.js.map +1 -1
  246. package/dist/core/slash-commands.d.ts.map +1 -1
  247. package/dist/core/slash-commands.js +5 -0
  248. package/dist/core/slash-commands.js.map +1 -1
  249. package/dist/core/system-prompt.d.ts.map +1 -1
  250. package/dist/core/system-prompt.js +12 -1
  251. package/dist/core/system-prompt.js.map +1 -1
  252. package/dist/core/tools/bash-operations.d.ts +41 -0
  253. package/dist/core/tools/bash-operations.d.ts.map +1 -0
  254. package/dist/core/tools/bash-operations.js +113 -0
  255. package/dist/core/tools/bash-operations.js.map +1 -0
  256. package/dist/core/tools/capability-mount.d.ts +40 -0
  257. package/dist/core/tools/capability-mount.d.ts.map +1 -0
  258. package/dist/core/tools/capability-mount.js +112 -0
  259. package/dist/core/tools/capability-mount.js.map +1 -0
  260. package/dist/core/tools/index.d.ts +12 -36
  261. package/dist/core/tools/index.d.ts.map +1 -1
  262. package/dist/core/tools/index.js +1 -117
  263. package/dist/core/tools/index.js.map +1 -1
  264. package/dist/core/tools/readme-path.d.ts +3 -0
  265. package/dist/core/tools/readme-path.d.ts.map +1 -0
  266. package/dist/core/tools/readme-path.js +15 -0
  267. package/dist/core/tools/readme-path.js.map +1 -0
  268. package/dist/index.d.ts +3 -19
  269. package/dist/index.d.ts.map +1 -1
  270. package/dist/index.js +6 -39
  271. package/dist/index.js.map +1 -1
  272. package/dist/main.d.ts.map +1 -1
  273. package/dist/main.js +1 -0
  274. package/dist/main.js.map +1 -1
  275. package/dist/modes/interactive/components/assistant-message.d.ts +3 -0
  276. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  277. package/dist/modes/interactive/components/assistant-message.js +27 -5
  278. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  279. package/dist/modes/interactive/components/session-selector-search.d.ts.map +1 -1
  280. package/dist/modes/interactive/components/session-selector-search.js +5 -1
  281. package/dist/modes/interactive/components/session-selector-search.js.map +1 -1
  282. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  283. package/dist/modes/interactive/components/session-selector.js +9 -0
  284. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  285. package/dist/modes/interactive/components/tool-execution.d.ts +17 -1
  286. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  287. package/dist/modes/interactive/components/tool-execution.js +52 -25
  288. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  289. package/dist/modes/interactive/components/tool-run-group.d.ts +44 -0
  290. package/dist/modes/interactive/components/tool-run-group.d.ts.map +1 -0
  291. package/dist/modes/interactive/components/tool-run-group.js +121 -0
  292. package/dist/modes/interactive/components/tool-run-group.js.map +1 -0
  293. package/dist/modes/interactive/interactive-commands.d.ts +2 -0
  294. package/dist/modes/interactive/interactive-commands.d.ts.map +1 -1
  295. package/dist/modes/interactive/interactive-commands.js +7 -0
  296. package/dist/modes/interactive/interactive-commands.js.map +1 -1
  297. package/dist/modes/interactive/interactive-mode.d.ts +18 -0
  298. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  299. package/dist/modes/interactive/interactive-mode.js +85 -3
  300. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  301. package/dist/plugins/ecosystem/cli.d.ts.map +1 -1
  302. package/dist/plugins/ecosystem/cli.js +20 -5
  303. package/dist/plugins/ecosystem/cli.js.map +1 -1
  304. package/dist/plugins/ecosystem/node-npm-registry-source.d.ts +7 -2
  305. package/dist/plugins/ecosystem/node-npm-registry-source.d.ts.map +1 -1
  306. package/dist/plugins/ecosystem/node-npm-registry-source.js +64 -9
  307. package/dist/plugins/ecosystem/node-npm-registry-source.js.map +1 -1
  308. package/dist/plugins/ecosystem/node-plugin-acquisition-host.d.ts.map +1 -1
  309. package/dist/plugins/ecosystem/node-plugin-acquisition-host.js +6 -0
  310. package/dist/plugins/ecosystem/node-plugin-acquisition-host.js.map +1 -1
  311. package/dist/plugins/ecosystem/node-plugin-bootstrap.d.ts +7 -1
  312. package/dist/plugins/ecosystem/node-plugin-bootstrap.d.ts.map +1 -1
  313. package/dist/plugins/ecosystem/node-plugin-bootstrap.js +50 -3
  314. package/dist/plugins/ecosystem/node-plugin-bootstrap.js.map +1 -1
  315. package/dist/plugins/ecosystem/plugin-bootstrap.d.ts +28 -16
  316. package/dist/plugins/ecosystem/plugin-bootstrap.d.ts.map +1 -1
  317. package/dist/plugins/ecosystem/plugin-bootstrap.js +35 -33
  318. package/dist/plugins/ecosystem/plugin-bootstrap.js.map +1 -1
  319. package/dist/profile/plugin-profiles.d.ts +1 -1
  320. package/dist/profile/plugin-profiles.d.ts.map +1 -1
  321. package/dist/profile/plugin-profiles.js +18 -0
  322. package/dist/profile/plugin-profiles.js.map +1 -1
  323. package/dist/profiles/builtin-suites.d.ts +19 -5
  324. package/dist/profiles/builtin-suites.d.ts.map +1 -1
  325. package/dist/profiles/builtin-suites.js +26 -6
  326. package/dist/profiles/builtin-suites.js.map +1 -1
  327. package/docs/settings.md +354 -354
  328. package/docs/usage.md +292 -292
  329. package/examples/extensions/bash-spawn-hook/index.ts +7 -2
  330. package/examples/extensions/built-in-tool-renderer/index.ts +4 -2
  331. package/examples/extensions/minimal-mode/index.ts +2 -2
  332. package/examples/extensions/truncated-tool/index.ts +1 -1
  333. package/examples/extensions/with-deps/package-lock.json +2 -2
  334. package/examples/extensions/with-deps/package.json +1 -1
  335. package/examples/extensions/with-deps/plugin.json +1 -1
  336. package/package.json +3 -2
  337. package/dist/bundle/chunks/chunk-6ZKDNZHA.js +0 -145
  338. package/dist/bundle/chunks/chunk-HLJEVRWP.js +0 -13
  339. package/dist/bundle/chunks/chunk-YGHQME4V.js +0 -1456
  340. package/dist/bundle/chunks/virtual-modules-KZ5DRH7Q.js +0 -2
  341. package/dist/core/extensions/bootstrap-branch-summary-policy.d.ts +0 -7
  342. package/dist/core/extensions/bootstrap-branch-summary-policy.d.ts.map +0 -1
  343. package/dist/core/extensions/bootstrap-branch-summary-policy.js +0 -28
  344. package/dist/core/extensions/bootstrap-branch-summary-policy.js.map +0 -1
  345. package/dist/core/extensions/bootstrap-compaction-policy.d.ts +0 -7
  346. package/dist/core/extensions/bootstrap-compaction-policy.d.ts.map +0 -1
  347. package/dist/core/extensions/bootstrap-compaction-policy.js +0 -48
  348. package/dist/core/extensions/bootstrap-compaction-policy.js.map +0 -1
  349. package/dist/core/extensions/bootstrap-overflow-policy.d.ts +0 -7
  350. package/dist/core/extensions/bootstrap-overflow-policy.d.ts.map +0 -1
  351. package/dist/core/extensions/bootstrap-overflow-policy.js +0 -30
  352. package/dist/core/extensions/bootstrap-overflow-policy.js.map +0 -1
  353. package/dist/core/extensions/bootstrap-retry-policy.d.ts +0 -7
  354. package/dist/core/extensions/bootstrap-retry-policy.d.ts.map +0 -1
  355. package/dist/core/extensions/bootstrap-retry-policy.js +0 -29
  356. package/dist/core/extensions/bootstrap-retry-policy.js.map +0 -1
  357. package/dist/core/extensions/bootstrap-tools.d.ts +0 -20
  358. package/dist/core/extensions/bootstrap-tools.d.ts.map +0 -1
  359. package/dist/core/extensions/bootstrap-tools.js +0 -36
  360. package/dist/core/extensions/bootstrap-tools.js.map +0 -1
  361. package/dist/core/extensions/provider-failover.d.ts +0 -110
  362. package/dist/core/extensions/provider-failover.d.ts.map +0 -1
  363. package/dist/core/extensions/provider-failover.js.map +0 -1
  364. package/dist/core/tools/bash.d.ts.map +0 -1
  365. package/dist/core/tools/bash.js.map +0 -1
  366. package/dist/core/tools/edit.d.ts.map +0 -1
  367. package/dist/core/tools/edit.js.map +0 -1
  368. package/dist/core/tools/find.d.ts.map +0 -1
  369. package/dist/core/tools/find.js.map +0 -1
  370. package/dist/core/tools/grep.d.ts.map +0 -1
  371. package/dist/core/tools/grep.js.map +0 -1
  372. package/dist/core/tools/ls.d.ts.map +0 -1
  373. package/dist/core/tools/powershell.d.ts.map +0 -1
  374. package/dist/core/tools/powershell.js.map +0 -1
  375. package/dist/core/tools/read.d.ts.map +0 -1
  376. package/dist/core/tools/read.js.map +0 -1
  377. package/dist/core/tools/write.d.ts.map +0 -1
  378. package/dist/core/tools/write.js.map +0 -1
  379. package/dist/plugins/mcp-http.d.ts.map +0 -1
  380. package/dist/plugins/mcp-http.js.map +0 -1
  381. package/dist/profile/child-facade.d.ts +0 -44
  382. package/dist/profile/child-facade.d.ts.map +0 -1
  383. package/dist/profile/child-facade.js +0 -56
  384. package/dist/profile/child-facade.js.map +0 -1
  385. package/dist/profile/dependency-wiring.d.ts +0 -48
  386. package/dist/profile/dependency-wiring.d.ts.map +0 -1
  387. package/dist/profile/dependency-wiring.js +0 -56
  388. package/dist/profile/dependency-wiring.js.map +0 -1
  389. package/dist/profile/domain-recovery.d.ts +0 -60
  390. package/dist/profile/domain-recovery.d.ts.map +0 -1
  391. package/dist/profile/domain-recovery.js +0 -94
  392. package/dist/profile/domain-recovery.js.map +0 -1
  393. package/dist/profile/first-roles.d.ts +0 -30
  394. package/dist/profile/first-roles.d.ts.map +0 -1
  395. package/dist/profile/first-roles.js +0 -83
  396. package/dist/profile/first-roles.js.map +0 -1
  397. package/dist/profile/goal-plugin.d.ts +0 -38
  398. package/dist/profile/goal-plugin.d.ts.map +0 -1
  399. package/dist/profile/goal-plugin.js +0 -132
  400. package/dist/profile/goal-plugin.js.map +0 -1
  401. package/dist/profile/plan-plugin.d.ts +0 -44
  402. package/dist/profile/plan-plugin.d.ts.map +0 -1
  403. package/dist/profile/plan-plugin.js +0 -157
  404. package/dist/profile/plan-plugin.js.map +0 -1
  405. package/dist/profile/policy-manifest.d.ts +0 -53
  406. package/dist/profile/policy-manifest.d.ts.map +0 -1
  407. package/dist/profile/policy-manifest.js +0 -53
  408. package/dist/profile/policy-manifest.js.map +0 -1
  409. package/dist/profile/role-assembly.d.ts +0 -47
  410. package/dist/profile/role-assembly.d.ts.map +0 -1
  411. package/dist/profile/role-assembly.js +0 -31
  412. package/dist/profile/role-assembly.js.map +0 -1
  413. package/dist/profile/role-catalog.d.ts +0 -43
  414. package/dist/profile/role-catalog.d.ts.map +0 -1
  415. package/dist/profile/role-catalog.js +0 -132
  416. package/dist/profile/role-catalog.js.map +0 -1
  417. package/dist/profile/role-orchestrator.d.ts +0 -123
  418. package/dist/profile/role-orchestrator.d.ts.map +0 -1
  419. package/dist/profile/role-orchestrator.js +0 -195
  420. package/dist/profile/role-orchestrator.js.map +0 -1
  421. package/dist/profile/role-runner.d.ts +0 -99
  422. package/dist/profile/role-runner.d.ts.map +0 -1
  423. package/dist/profile/role-runner.js +0 -79
  424. package/dist/profile/role-runner.js.map +0 -1
  425. package/dist/profile/root-facade.d.ts +0 -36
  426. package/dist/profile/root-facade.d.ts.map +0 -1
  427. package/dist/profile/root-facade.js +0 -49
  428. package/dist/profile/root-facade.js.map +0 -1
  429. package/dist/profile/skill-discovery-wiring.d.ts +0 -58
  430. package/dist/profile/skill-discovery-wiring.d.ts.map +0 -1
  431. package/dist/profile/skill-discovery-wiring.js +0 -80
  432. package/dist/profile/skill-discovery-wiring.js.map +0 -1
  433. package/dist/profile/state-store.d.ts +0 -62
  434. package/dist/profile/state-store.d.ts.map +0 -1
  435. package/dist/profile/state-store.js +0 -144
  436. package/dist/profile/state-store.js.map +0 -1
  437. package/dist/profile/todo-plugin.d.ts +0 -37
  438. package/dist/profile/todo-plugin.d.ts.map +0 -1
  439. package/dist/profile/todo-plugin.js +0 -137
  440. package/dist/profile/todo-plugin.js.map +0 -1
  441. package/examples/extensions/mcp-stdio/index.d.ts +0 -64
  442. package/examples/extensions/mcp-stdio/index.d.ts.map +0 -1
  443. package/examples/extensions/mcp-stdio/index.js +0 -292
  444. package/examples/extensions/mcp-stdio/index.js.map +0 -1
  445. /package/{dist/plugins → bundled-plugins/mcp-http/dist}/mcp-http.d.ts +0 -0
@@ -1,132 +0,0 @@
1
- /**
2
- * Goal plugin (2.3b) — Goal schema, evidence, and recovery on top of the 2.3a
3
- * transition store.
4
- *
5
- * Status graph: null → draft → active → achieved, and draft/active → archived.
6
- * `achieve` requires at least one evidence reference. The plugin holds NO
7
- * shadow state: every read derives status, revision, title, and evidence from
8
- * the transition history, so recovery is exactly a store replay.
9
- */
10
- import { t } from "../core/i18n/index.js";
11
- export function createGoalPlugin(options) {
12
- const transitions = options.transitions;
13
- const goalHistory = (goalId, owner) => transitions.history(goalId).filter((record) => record.domain === "goal" && record.owner === owner);
14
- const current = (goalId, owner) => {
15
- const state = transitions.currentStatus("goal", goalId);
16
- if (state === undefined || goalHistory(goalId, owner).length === 0)
17
- return undefined;
18
- return { status: state.status, revision: state.revision };
19
- };
20
- const titleOf = (goalId, owner) => {
21
- for (const record of goalHistory(goalId, owner)) {
22
- if (record.fromStatus !== null)
23
- continue;
24
- const payload = record.payload;
25
- if (payload !== null && typeof payload === "object" && !Array.isArray(payload)) {
26
- const title = payload.title;
27
- if (typeof title === "string")
28
- return title;
29
- }
30
- }
31
- return goalId;
32
- };
33
- const goalGet = (goalId, owner) => {
34
- const state = current(goalId, owner);
35
- if (!state)
36
- return undefined;
37
- const history = goalHistory(goalId, owner);
38
- const lastEvidence = [...history].reverse().find((record) => record.evidence.length > 0)?.evidence ?? [];
39
- return {
40
- goalId,
41
- owner,
42
- title: titleOf(goalId, owner),
43
- status: state.status,
44
- evidence: lastEvidence,
45
- revision: state.revision,
46
- };
47
- };
48
- /** A retried transition with an already-applied operationId returns the existing state instead of conflicting. */
49
- const replayedGoal = (goalId, owner, toStatus, operationId) => {
50
- if (!operationId)
51
- return undefined;
52
- const applied = goalHistory(goalId, owner).some((record) => record.toStatus === toStatus && record.operationId === operationId);
53
- return applied ? goalGet(goalId, owner) : undefined;
54
- };
55
- const transitionGoal = (goalId, owner, fromStatus, toStatus, goalOptions) => {
56
- transitions.transition({
57
- domain: "goal",
58
- entityId: goalId,
59
- owner,
60
- fromStatus,
61
- toStatus,
62
- operationId: goalOptions.operationId ?? `${toStatus}:${goalId}`,
63
- evidence: goalOptions.evidence,
64
- payload: goalOptions.payload,
65
- });
66
- const state = transitions.currentStatus("goal", goalId);
67
- return {
68
- goalId,
69
- owner,
70
- title: titleOf(goalId, owner),
71
- status: state?.status,
72
- evidence: goalOptions.evidence ?? [],
73
- // v8 ignore next -- transition 刚写入 currentStatus,必可读到 revision
74
- revision: state?.revision ?? 0,
75
- };
76
- };
77
- return {
78
- createGoal({ goalId, owner, title }) {
79
- if (title.trim().length === 0)
80
- throw new Error(t("Goal title must be a non-empty string"));
81
- return transitionGoal(goalId, owner, null, "draft", {
82
- payload: { title },
83
- operationId: `create:${goalId}`,
84
- });
85
- },
86
- activate(goalId, owner, activateOptions) {
87
- const replayed = replayedGoal(goalId, owner, "active", activateOptions?.operationId);
88
- if (replayed)
89
- return replayed;
90
- const existing = current(goalId, owner);
91
- if (existing?.status !== "draft") {
92
- throw new Error(t("Goal {goalId} must be in draft status to activate (current: {status})", {
93
- goalId,
94
- status: existing?.status ?? "missing",
95
- }));
96
- }
97
- return transitionGoal(goalId, owner, "draft", "active", { operationId: activateOptions?.operationId });
98
- },
99
- achieve(goalId, owner, evidence, achieveOptions) {
100
- const replayed = replayedGoal(goalId, owner, "achieved", achieveOptions?.operationId);
101
- if (replayed)
102
- return replayed;
103
- const existing = current(goalId, owner);
104
- if (existing?.status !== "active") {
105
- throw new Error(t("Goal {goalId} must be active to achieve (current: {status})", {
106
- goalId,
107
- status: existing?.status ?? "missing",
108
- }));
109
- }
110
- if (evidence.length === 0)
111
- throw new Error(t("Achieving a goal requires at least one evidence reference"));
112
- return transitionGoal(goalId, owner, "active", "achieved", {
113
- evidence,
114
- operationId: achieveOptions?.operationId,
115
- });
116
- },
117
- archive(goalId, owner) {
118
- const existing = current(goalId, owner);
119
- if (!existing || existing.status === "achieved" || existing.status === "archived") {
120
- throw new Error(t("Goal {goalId} cannot be archived from status {status}", {
121
- goalId,
122
- status: existing?.status ?? "missing",
123
- }));
124
- }
125
- return transitionGoal(goalId, owner, existing.status, "archived", {});
126
- },
127
- get(goalId, owner) {
128
- return goalGet(goalId, owner);
129
- },
130
- };
131
- }
132
- //# sourceMappingURL=goal-plugin.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"goal-plugin.js","sourceRoot":"","sources":["../../src/profile/goal-plugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,uBAAuB,CAAC;AA2B1C,MAAM,UAAU,gBAAgB,CAAC,OAAoD,EAAgB;IACpG,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IAExC,MAAM,WAAW,GAAG,CAAC,MAAc,EAAE,KAAa,EAAE,EAAE,CACrD,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,KAAK,MAAM,IAAI,MAAM,CAAC,KAAK,KAAK,KAAK,CAAC,CAAC;IAEpG,MAAM,OAAO,GAAG,CAAC,MAAc,EAAE,KAAa,EAA0D,EAAE,CAAC;QAC1G,MAAM,KAAK,GAAG,WAAW,CAAC,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QACxD,IAAI,KAAK,KAAK,SAAS,IAAI,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,SAAS,CAAC;QACrF,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,MAAsB,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,CA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,EAAE,KAAK,CAAC,CAAC;YACxC,IAAI,QAAQ,EAAE,MAAM,KAAK,QAAQ,EAAE,CAAC;gBACnC,MAAM,IAAI,KAAK,CACd,CAAC,CAAC,6DAA6D,EAAE;oBAChE,MAAM;oBACN,MAAM,EAAE,QAAQ,EAAE,MAAM,IAAI,SAAS;iBACrC,CAAC,CACF,CAAC;YACH,CAAC;YACD,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC;gBAAE,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,2DAA2D,CAAC,CAAC,CAAC;YAC3G,OAAO,cAAc,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,UAAU,EAAE;gBAC1D,QAAQ;gBACR,WAAW,EAAE,cAAc,EAAE,WAAW;aACxC,CAAC,CAAC;QAAA,CACH;QACD,OAAO,CAAC,MAAM,EAAE,KAAK,EAAE;YACtB,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;YACxC,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,MAAM,KAAK,UAAU,IAAI,QAAQ,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;gBACnF,MAAM,IAAI,KAAK,CACd,CAAC,CAAC,uDAAuD,EAAE;oBAC1D,MAAM;oBACN,MAAM,EAAE,QAAQ,EAAE,MAAM,IAAI,SAAS;iBACrC,CAAC,CACF,CAAC;YACH,CAAC;YACD,OAAO,cAAc,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,CAAC,MAAM,EAAE,UAAU,EAAE,EAAE,CAAC,CAAC;QAAA,CACtE;QACD,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE;YAClB,OAAO,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAAA,CAC9B;KACD,CAAC;AAAA,CACF","sourcesContent":["/**\n * Goal plugin (2.3b) — Goal schema, evidence, and recovery on top of the 2.3a\n * transition store.\n *\n * Status graph: null → draft → active → achieved, and draft/active → archived.\n * `achieve` requires at least one evidence reference. The plugin holds NO\n * shadow state: every read derives status, revision, title, and evidence from\n * the transition history, so recovery is exactly a store replay.\n */\n\nimport { t } from \"../core/i18n/index.ts\";\nimport type { TransitionEvidenceRefV1, TransitionStoreV1 } from \"./state-store.ts\";\n\nexport type GoalStatusV1 = \"draft\" | \"active\" | \"achieved\" | \"archived\";\n\nexport interface GoalV1 {\n\treadonly goalId: string;\n\treadonly owner: string;\n\treadonly title: string;\n\treadonly status: GoalStatusV1;\n\treadonly evidence: readonly TransitionEvidenceRefV1[];\n\treadonly revision: number;\n}\n\nexport interface GoalPluginV1 {\n\tcreateGoal(input: { readonly goalId: string; readonly owner: string; readonly title: string }): GoalV1;\n\tactivate(goalId: string, owner: string, options?: { readonly operationId?: string }): GoalV1;\n\tachieve(\n\t\tgoalId: string,\n\t\towner: string,\n\t\tevidence: readonly TransitionEvidenceRefV1[],\n\t\toptions?: { readonly operationId?: string },\n\t): GoalV1;\n\tarchive(goalId: string, owner: string): GoalV1;\n\tget(goalId: string, owner: string): GoalV1 | undefined;\n}\n\nexport function createGoalPlugin(options: { readonly transitions: TransitionStoreV1 }): GoalPluginV1 {\n\tconst transitions = options.transitions;\n\n\tconst goalHistory = (goalId: string, owner: string) =>\n\t\ttransitions.history(goalId).filter((record) => record.domain === \"goal\" && record.owner === owner);\n\n\tconst current = (goalId: string, owner: string): { status: GoalStatusV1; revision: number } | undefined => {\n\t\tconst state = transitions.currentStatus(\"goal\", goalId);\n\t\tif (state === undefined || goalHistory(goalId, owner).length === 0) return undefined;\n\t\treturn { status: state.status as GoalStatusV1, revision: state.revision };\n\t};\n\n\tconst titleOf = (goalId: string, owner: string): string => {\n\t\tfor (const record of goalHistory(goalId, owner)) {\n\t\t\tif (record.fromStatus !== null) continue;\n\t\t\tconst payload = record.payload;\n\t\t\tif (payload !== null && typeof payload === \"object\" && !Array.isArray(payload)) {\n\t\t\t\tconst title = (payload as Record<string, unknown>).title;\n\t\t\t\tif (typeof title === \"string\") return title;\n\t\t\t}\n\t\t}\n\t\treturn goalId;\n\t};\n\n\tconst goalGet = (goalId: string, owner: string): GoalV1 | undefined => {\n\t\tconst state = current(goalId, owner);\n\t\tif (!state) return undefined;\n\t\tconst history = goalHistory(goalId, owner);\n\t\tconst lastEvidence = [...history].reverse().find((record) => record.evidence.length > 0)?.evidence ?? [];\n\t\treturn {\n\t\t\tgoalId,\n\t\t\towner,\n\t\t\ttitle: titleOf(goalId, owner),\n\t\t\tstatus: state.status,\n\t\t\tevidence: lastEvidence,\n\t\t\trevision: state.revision,\n\t\t};\n\t};\n\n\t/** A retried transition with an already-applied operationId returns the existing state instead of conflicting. */\n\tconst replayedGoal = (\n\t\tgoalId: string,\n\t\towner: string,\n\t\ttoStatus: GoalStatusV1,\n\t\toperationId?: string,\n\t): GoalV1 | undefined => {\n\t\tif (!operationId) return undefined;\n\t\tconst applied = goalHistory(goalId, owner).some(\n\t\t\t(record) => record.toStatus === toStatus && record.operationId === operationId,\n\t\t);\n\t\treturn applied ? goalGet(goalId, owner) : undefined;\n\t};\n\n\tconst transitionGoal = (\n\t\tgoalId: string,\n\t\towner: string,\n\t\tfromStatus: GoalStatusV1 | null,\n\t\ttoStatus: GoalStatusV1,\n\t\tgoalOptions: {\n\t\t\treadonly evidence?: readonly TransitionEvidenceRefV1[];\n\t\t\treadonly payload?: { readonly title: string };\n\t\t\treadonly operationId?: string;\n\t\t},\n\t): GoalV1 => {\n\t\ttransitions.transition({\n\t\t\tdomain: \"goal\",\n\t\t\tentityId: goalId,\n\t\t\towner,\n\t\t\tfromStatus,\n\t\t\ttoStatus,\n\t\t\toperationId: goalOptions.operationId ?? `${toStatus}:${goalId}`,\n\t\t\tevidence: goalOptions.evidence,\n\t\t\tpayload: goalOptions.payload,\n\t\t});\n\t\tconst state = transitions.currentStatus(\"goal\", goalId);\n\t\treturn {\n\t\t\tgoalId,\n\t\t\towner,\n\t\t\ttitle: titleOf(goalId, owner),\n\t\t\tstatus: state?.status as GoalStatusV1,\n\t\t\tevidence: goalOptions.evidence ?? [],\n\t\t\t// v8 ignore next -- transition 刚写入 currentStatus,必可读到 revision\n\t\t\trevision: state?.revision ?? 0,\n\t\t};\n\t};\n\n\treturn {\n\t\tcreateGoal({ goalId, owner, title }) {\n\t\t\tif (title.trim().length === 0) throw new Error(t(\"Goal title must be a non-empty string\"));\n\t\t\treturn transitionGoal(goalId, owner, null, \"draft\", {\n\t\t\t\tpayload: { title },\n\t\t\t\toperationId: `create:${goalId}`,\n\t\t\t});\n\t\t},\n\t\tactivate(goalId, owner, activateOptions) {\n\t\t\tconst replayed = replayedGoal(goalId, owner, \"active\", activateOptions?.operationId);\n\t\t\tif (replayed) return replayed;\n\t\t\tconst existing = current(goalId, owner);\n\t\t\tif (existing?.status !== \"draft\") {\n\t\t\t\tthrow new Error(\n\t\t\t\t\tt(\"Goal {goalId} must be in draft status to activate (current: {status})\", {\n\t\t\t\t\t\tgoalId,\n\t\t\t\t\t\tstatus: existing?.status ?? \"missing\",\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn transitionGoal(goalId, owner, \"draft\", \"active\", { operationId: activateOptions?.operationId });\n\t\t},\n\t\tachieve(goalId, owner, evidence, achieveOptions) {\n\t\t\tconst replayed = replayedGoal(goalId, owner, \"achieved\", achieveOptions?.operationId);\n\t\t\tif (replayed) return replayed;\n\t\t\tconst existing = current(goalId, owner);\n\t\t\tif (existing?.status !== \"active\") {\n\t\t\t\tthrow new Error(\n\t\t\t\t\tt(\"Goal {goalId} must be active to achieve (current: {status})\", {\n\t\t\t\t\t\tgoalId,\n\t\t\t\t\t\tstatus: existing?.status ?? \"missing\",\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (evidence.length === 0) throw new Error(t(\"Achieving a goal requires at least one evidence reference\"));\n\t\t\treturn transitionGoal(goalId, owner, \"active\", \"achieved\", {\n\t\t\t\tevidence,\n\t\t\t\toperationId: achieveOptions?.operationId,\n\t\t\t});\n\t\t},\n\t\tarchive(goalId, owner) {\n\t\t\tconst existing = current(goalId, owner);\n\t\t\tif (!existing || existing.status === \"achieved\" || existing.status === \"archived\") {\n\t\t\t\tthrow new Error(\n\t\t\t\t\tt(\"Goal {goalId} cannot be archived from status {status}\", {\n\t\t\t\t\t\tgoalId,\n\t\t\t\t\t\tstatus: existing?.status ?? \"missing\",\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn transitionGoal(goalId, owner, existing.status, \"archived\", {});\n\t\t},\n\t\tget(goalId, owner) {\n\t\t\treturn goalGet(goalId, owner);\n\t\t},\n\t};\n}\n"]}
@@ -1,44 +0,0 @@
1
- import type { TransitionEvidenceRefV1, TransitionStoreV1 } from "./state-store.ts";
2
- export type PlanStatusV1 = "draft" | "active" | "completed" | "discarded";
3
- export interface PlanStepV1 {
4
- readonly stepId: string;
5
- readonly title: string;
6
- }
7
- export interface PlanV1 {
8
- readonly planId: string;
9
- readonly owner: string;
10
- readonly title: string;
11
- readonly branch: string;
12
- readonly steps: readonly PlanStepV1[];
13
- readonly status: PlanStatusV1;
14
- /** The latest revision explicitly linked while active (undefined before the first link). */
15
- readonly revision?: number;
16
- readonly evidence: readonly TransitionEvidenceRefV1[];
17
- readonly revisionNo: number;
18
- }
19
- export interface PlanPluginV1 {
20
- createPlan(input: {
21
- readonly planId: string;
22
- readonly owner: string;
23
- readonly title: string;
24
- readonly branch: string;
25
- readonly steps: readonly PlanStepV1[];
26
- }): PlanV1;
27
- activate(planId: string, owner: string, options?: {
28
- readonly operationId?: string;
29
- }): PlanV1;
30
- /** Records plan progress against a concrete revision of the bound branch. */
31
- linkRevision(planId: string, owner: string, revision: number, options?: {
32
- readonly operationId?: string;
33
- }): PlanV1;
34
- complete(planId: string, owner: string, evidence: readonly TransitionEvidenceRefV1[], options?: {
35
- readonly atRevision?: number;
36
- readonly operationId?: string;
37
- }): PlanV1;
38
- discard(planId: string, owner: string): PlanV1;
39
- get(planId: string, owner: string): PlanV1 | undefined;
40
- }
41
- export declare function createPlanPlugin(options: {
42
- readonly transitions: TransitionStoreV1;
43
- }): PlanPluginV1;
44
- //# sourceMappingURL=plan-plugin.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"plan-plugin.d.ts","sourceRoot":"","sources":["../../src/profile/plan-plugin.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAEnF,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,QAAQ,GAAG,WAAW,GAAG,WAAW,CAAC;AAE1E,MAAM,WAAW,UAAU;IAC1B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,MAAM;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,SAAS,UAAU,EAAE,CAAC;IACtC,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,4FAA4F;IAC5F,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,SAAS,uBAAuB,EAAE,CAAC;IACtD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,WAAW,YAAY;IAC5B,UAAU,CAAC,KAAK,EAAE;QACjB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;QACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QACvB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;QACxB,QAAQ,CAAC,KAAK,EAAE,SAAS,UAAU,EAAE,CAAC;KACtC,GAAG,MAAM,CAAC;IACX,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM,CAAC;IAC7F,6EAA6E;IAC7E,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM,CAAC;IACnH,QAAQ,CACP,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,SAAS,uBAAuB,EAAE,EAC5C,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,GACvE,MAAM,CAAC;IACV,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/C,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;CACvD;AAiBD,wBAAgB,gBAAgB,CAAC,OAAO,EAAE;IAAE,QAAQ,CAAC,WAAW,EAAE,iBAAiB,CAAA;CAAE,GAAG,YAAY,CAyKnG","sourcesContent":["/**\n * Plan plugin (2.3c) — Plan semantics bound to a branch/revision over the\n * 2.3a transition store.\n *\n * Status graph: null → draft → active → completed, and draft/active →\n * discarded. A plan is created with its step list and bound to a code branch;\n * while active, `linkRevision` records plan progress against concrete\n * revisions, and `complete` requires evidence plus the final revision. The\n * plugin holds NO shadow state: status, revision, steps, branch, and the\n * latest linked revision are all derived from the transition history, so\n * recovery is exactly a store replay.\n */\nimport type { JsonValue } from \"@agent-forge/ai\";\nimport { t } from \"../core/i18n/index.ts\";\nimport type { TransitionEvidenceRefV1, TransitionStoreV1 } from \"./state-store.ts\";\n\nexport type PlanStatusV1 = \"draft\" | \"active\" | \"completed\" | \"discarded\";\n\nexport interface PlanStepV1 {\n\treadonly stepId: string;\n\treadonly title: string;\n}\n\nexport interface PlanV1 {\n\treadonly planId: string;\n\treadonly owner: string;\n\treadonly title: string;\n\treadonly branch: string;\n\treadonly steps: readonly PlanStepV1[];\n\treadonly status: PlanStatusV1;\n\t/** The latest revision explicitly linked while active (undefined before the first link). */\n\treadonly revision?: number;\n\treadonly evidence: readonly TransitionEvidenceRefV1[];\n\treadonly revisionNo: number;\n}\n\nexport interface PlanPluginV1 {\n\tcreatePlan(input: {\n\t\treadonly planId: string;\n\t\treadonly owner: string;\n\t\treadonly title: string;\n\t\treadonly branch: string;\n\t\treadonly steps: readonly PlanStepV1[];\n\t}): PlanV1;\n\tactivate(planId: string, owner: string, options?: { readonly operationId?: string }): PlanV1;\n\t/** Records plan progress against a concrete revision of the bound branch. */\n\tlinkRevision(planId: string, owner: string, revision: number, options?: { readonly operationId?: string }): PlanV1;\n\tcomplete(\n\t\tplanId: string,\n\t\towner: string,\n\t\tevidence: readonly TransitionEvidenceRefV1[],\n\t\toptions?: { readonly atRevision?: number; readonly operationId?: string },\n\t): PlanV1;\n\tdiscard(planId: string, owner: string): PlanV1;\n\tget(planId: string, owner: string): PlanV1 | undefined;\n}\n\ninterface PlanPayloadV1 {\n\treadonly title: string;\n\treadonly branch: string;\n\treadonly steps: readonly PlanStepV1[];\n\treadonly linkedRevision?: number;\n}\n\nfunction planPayloadOf(record: { readonly payload?: unknown }): Partial<PlanPayloadV1> | undefined {\n\tconst payload = record.payload;\n\tif (payload !== null && typeof payload === \"object\" && !Array.isArray(payload)) {\n\t\treturn payload as Partial<PlanPayloadV1>;\n\t}\n\treturn undefined;\n}\n\nexport function createPlanPlugin(options: { readonly transitions: TransitionStoreV1 }): PlanPluginV1 {\n\tconst transitions = options.transitions;\n\n\tconst planHistory = (planId: string, owner: string) =>\n\t\ttransitions.history(planId).filter((record) => record.domain === \"plan\" && record.owner === owner);\n\n\tconst current = (planId: string, owner: string): { status: PlanStatusV1; revisionNo: number } | undefined => {\n\t\tconst state = transitions.currentStatus(\"plan\", planId);\n\t\tif (state === undefined || planHistory(planId, owner).length === 0) return undefined;\n\t\treturn { status: state.status as PlanStatusV1, revisionNo: state.revision };\n\t};\n\n\tconst planGet = (planId: string, owner: string): PlanV1 | undefined => {\n\t\tconst state = current(planId, owner);\n\t\tif (!state) return undefined;\n\t\tconst history = planHistory(planId, owner);\n\t\t// v8 ignore next -- 因果校验保证每条 plan 历史都以 fromStatus=null 的创建记录开始\n\t\tconst createPayload = planPayloadOf(history.find((record) => record.fromStatus === null) ?? {});\n\t\tconst lastLinked = [...history]\n\t\t\t.reverse()\n\t\t\t.map((record) => planPayloadOf(record)?.linkedRevision)\n\t\t\t.find((revision): revision is number => typeof revision === \"number\");\n\t\tconst lastEvidence = [...history].reverse().find((record) => record.evidence.length > 0)?.evidence ?? [];\n\t\treturn {\n\t\t\tplanId,\n\t\t\towner,\n\t\t\ttitle: createPayload?.title ?? planId,\n\t\t\tbranch: createPayload?.branch ?? \"\",\n\t\t\tsteps: createPayload?.steps ?? [],\n\t\t\tstatus: state.status,\n\t\t\t...(lastLinked === undefined ? {} : { revision: lastLinked }),\n\t\t\tevidence: lastEvidence,\n\t\t\trevisionNo: state.revisionNo,\n\t\t};\n\t};\n\n\t/** A retried transition with an already-applied operationId returns the existing state instead of conflicting. */\n\tconst replayedPlan = (\n\t\tplanId: string,\n\t\towner: string,\n\t\ttoStatus: PlanStatusV1,\n\t\toperationId?: string,\n\t): PlanV1 | undefined => {\n\t\tif (!operationId) return undefined;\n\t\tconst applied = planHistory(planId, owner).some(\n\t\t\t(record) => record.toStatus === toStatus && record.operationId === operationId,\n\t\t);\n\t\treturn applied ? planGet(planId, owner) : undefined;\n\t};\n\n\tconst transitionPlan = (\n\t\tplanId: string,\n\t\towner: string,\n\t\tfromStatus: PlanStatusV1 | null,\n\t\ttoStatus: PlanStatusV1,\n\t\tplanOptions: {\n\t\t\treadonly evidence?: readonly TransitionEvidenceRefV1[];\n\t\t\treadonly payload?: PlanPayloadV1;\n\t\t\treadonly operationId?: string;\n\t\t},\n\t): PlanV1 => {\n\t\ttransitions.transition({\n\t\t\tdomain: \"plan\",\n\t\t\tentityId: planId,\n\t\t\towner,\n\t\t\tfromStatus,\n\t\t\ttoStatus,\n\t\t\toperationId: planOptions.operationId ?? `${toStatus}:${planId}`,\n\t\t\tevidence: planOptions.evidence,\n\t\t\tpayload: planOptions.payload as JsonValue | undefined,\n\t\t});\n\t\treturn planGet(planId, owner)!;\n\t};\n\n\treturn {\n\t\tcreatePlan({ planId, owner, title, branch, steps }) {\n\t\t\tif (title.trim().length === 0) throw new Error(t(\"Plan title must be a non-empty string\"));\n\t\t\tif (branch.trim().length === 0) throw new Error(t(\"Plan branch must be a non-empty string\"));\n\t\t\tif (steps.length === 0) throw new Error(t(\"Plan requires at least one step\"));\n\t\t\tconst stepIds = new Set<string>();\n\t\t\tfor (const step of steps) {\n\t\t\t\tif (typeof step.stepId !== \"string\" || step.stepId.trim().length === 0) {\n\t\t\t\t\tthrow new Error(t(\"Plan stepId must be a non-empty string\"));\n\t\t\t\t}\n\t\t\t\tif (typeof step.title !== \"string\" || step.title.trim().length === 0) {\n\t\t\t\t\tthrow new Error(t(\"Plan step title must be a non-empty string\"));\n\t\t\t\t}\n\t\t\t\tif (stepIds.has(step.stepId))\n\t\t\t\t\tthrow new Error(t(\"Duplicate plan stepId: {stepId}\", { stepId: step.stepId }));\n\t\t\t\tstepIds.add(step.stepId);\n\t\t\t}\n\t\t\treturn transitionPlan(planId, owner, null, \"draft\", {\n\t\t\t\tpayload: { title, branch, steps: [...steps] },\n\t\t\t\toperationId: `create:${planId}`,\n\t\t\t});\n\t\t},\n\t\tactivate(planId, owner, activateOptions) {\n\t\t\tconst replayed = replayedPlan(planId, owner, \"active\", activateOptions?.operationId);\n\t\t\tif (replayed) return replayed;\n\t\t\tconst plan = planGet(planId, owner);\n\t\t\tif (plan?.status !== \"draft\") {\n\t\t\t\tthrow new Error(\n\t\t\t\t\tt(\"Plan {planId} must be in draft status to activate (current: {status})\", {\n\t\t\t\t\t\tplanId,\n\t\t\t\t\t\tstatus: plan?.status ?? \"missing\",\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn transitionPlan(planId, owner, \"draft\", \"active\", { operationId: activateOptions?.operationId });\n\t\t},\n\t\tlinkRevision(planId, owner, revision, linkOptions) {\n\t\t\tconst replayed = replayedPlan(planId, owner, \"active\", linkOptions?.operationId);\n\t\t\tif (replayed) return replayed;\n\t\t\tconst plan = planGet(planId, owner);\n\t\t\tif (plan?.status !== \"active\") {\n\t\t\t\tthrow new Error(\n\t\t\t\t\tt(\"Plan {planId} must be active to link a revision (current: {status})\", {\n\t\t\t\t\t\tplanId,\n\t\t\t\t\t\tstatus: plan?.status ?? \"missing\",\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (!Number.isSafeInteger(revision) || revision < 1) {\n\t\t\t\tthrow new Error(t(\"Plan revision must be a positive safe integer, got {revision}\", { revision }));\n\t\t\t}\n\t\t\treturn transitionPlan(planId, owner, \"active\", \"active\", {\n\t\t\t\tpayload: { title: plan.title, branch: plan.branch, steps: plan.steps, linkedRevision: revision },\n\t\t\t\toperationId: linkOptions?.operationId ?? `link:${planId}:${revision}`,\n\t\t\t});\n\t\t},\n\t\tcomplete(planId, owner, evidence, completeOptions) {\n\t\t\tconst replayed = replayedPlan(planId, owner, \"completed\", completeOptions?.operationId);\n\t\t\tif (replayed) return replayed;\n\t\t\tconst plan = planGet(planId, owner);\n\t\t\tif (plan?.status !== \"active\") {\n\t\t\t\tthrow new Error(\n\t\t\t\t\tt(\"Plan {planId} must be active to complete (current: {status})\", {\n\t\t\t\t\t\tplanId,\n\t\t\t\t\t\tstatus: plan?.status ?? \"missing\",\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (evidence.length === 0) throw new Error(t(\"Completing a plan requires at least one evidence reference\"));\n\t\t\tconst target = completeOptions?.atRevision ?? plan.revision;\n\t\t\tif (typeof target !== \"number\") {\n\t\t\t\tthrow new Error(t(\"Plan {planId} requires atRevision or a linked revision to complete\", { planId }));\n\t\t\t}\n\t\t\treturn transitionPlan(planId, owner, \"active\", \"completed\", {\n\t\t\t\tevidence,\n\t\t\t\tpayload: { title: plan.title, branch: plan.branch, steps: plan.steps, linkedRevision: target },\n\t\t\t\toperationId: completeOptions?.operationId,\n\t\t\t});\n\t\t},\n\t\tdiscard(planId, owner) {\n\t\t\tconst plan = planGet(planId, owner);\n\t\t\tif (!plan || plan.status === \"completed\" || plan.status === \"discarded\") {\n\t\t\t\tthrow new Error(\n\t\t\t\t\tt(\"Plan {planId} cannot be discarded from status {status}\", {\n\t\t\t\t\t\tplanId,\n\t\t\t\t\t\tstatus: plan?.status ?? \"missing\",\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn transitionPlan(planId, owner, plan.status, \"discarded\", {});\n\t\t},\n\t\tget(planId, owner) {\n\t\t\treturn planGet(planId, owner);\n\t\t},\n\t};\n}\n"]}
@@ -1,157 +0,0 @@
1
- import { t } from "../core/i18n/index.js";
2
- function planPayloadOf(record) {
3
- const payload = record.payload;
4
- if (payload !== null && typeof payload === "object" && !Array.isArray(payload)) {
5
- return payload;
6
- }
7
- return undefined;
8
- }
9
- export function createPlanPlugin(options) {
10
- const transitions = options.transitions;
11
- const planHistory = (planId, owner) => transitions.history(planId).filter((record) => record.domain === "plan" && record.owner === owner);
12
- const current = (planId, owner) => {
13
- const state = transitions.currentStatus("plan", planId);
14
- if (state === undefined || planHistory(planId, owner).length === 0)
15
- return undefined;
16
- return { status: state.status, revisionNo: state.revision };
17
- };
18
- const planGet = (planId, owner) => {
19
- const state = current(planId, owner);
20
- if (!state)
21
- return undefined;
22
- const history = planHistory(planId, owner);
23
- // v8 ignore next -- 因果校验保证每条 plan 历史都以 fromStatus=null 的创建记录开始
24
- const createPayload = planPayloadOf(history.find((record) => record.fromStatus === null) ?? {});
25
- const lastLinked = [...history]
26
- .reverse()
27
- .map((record) => planPayloadOf(record)?.linkedRevision)
28
- .find((revision) => typeof revision === "number");
29
- const lastEvidence = [...history].reverse().find((record) => record.evidence.length > 0)?.evidence ?? [];
30
- return {
31
- planId,
32
- owner,
33
- title: createPayload?.title ?? planId,
34
- branch: createPayload?.branch ?? "",
35
- steps: createPayload?.steps ?? [],
36
- status: state.status,
37
- ...(lastLinked === undefined ? {} : { revision: lastLinked }),
38
- evidence: lastEvidence,
39
- revisionNo: state.revisionNo,
40
- };
41
- };
42
- /** A retried transition with an already-applied operationId returns the existing state instead of conflicting. */
43
- const replayedPlan = (planId, owner, toStatus, operationId) => {
44
- if (!operationId)
45
- return undefined;
46
- const applied = planHistory(planId, owner).some((record) => record.toStatus === toStatus && record.operationId === operationId);
47
- return applied ? planGet(planId, owner) : undefined;
48
- };
49
- const transitionPlan = (planId, owner, fromStatus, toStatus, planOptions) => {
50
- transitions.transition({
51
- domain: "plan",
52
- entityId: planId,
53
- owner,
54
- fromStatus,
55
- toStatus,
56
- operationId: planOptions.operationId ?? `${toStatus}:${planId}`,
57
- evidence: planOptions.evidence,
58
- payload: planOptions.payload,
59
- });
60
- return planGet(planId, owner);
61
- };
62
- return {
63
- createPlan({ planId, owner, title, branch, steps }) {
64
- if (title.trim().length === 0)
65
- throw new Error(t("Plan title must be a non-empty string"));
66
- if (branch.trim().length === 0)
67
- throw new Error(t("Plan branch must be a non-empty string"));
68
- if (steps.length === 0)
69
- throw new Error(t("Plan requires at least one step"));
70
- const stepIds = new Set();
71
- for (const step of steps) {
72
- if (typeof step.stepId !== "string" || step.stepId.trim().length === 0) {
73
- throw new Error(t("Plan stepId must be a non-empty string"));
74
- }
75
- if (typeof step.title !== "string" || step.title.trim().length === 0) {
76
- throw new Error(t("Plan step title must be a non-empty string"));
77
- }
78
- if (stepIds.has(step.stepId))
79
- throw new Error(t("Duplicate plan stepId: {stepId}", { stepId: step.stepId }));
80
- stepIds.add(step.stepId);
81
- }
82
- return transitionPlan(planId, owner, null, "draft", {
83
- payload: { title, branch, steps: [...steps] },
84
- operationId: `create:${planId}`,
85
- });
86
- },
87
- activate(planId, owner, activateOptions) {
88
- const replayed = replayedPlan(planId, owner, "active", activateOptions?.operationId);
89
- if (replayed)
90
- return replayed;
91
- const plan = planGet(planId, owner);
92
- if (plan?.status !== "draft") {
93
- throw new Error(t("Plan {planId} must be in draft status to activate (current: {status})", {
94
- planId,
95
- status: plan?.status ?? "missing",
96
- }));
97
- }
98
- return transitionPlan(planId, owner, "draft", "active", { operationId: activateOptions?.operationId });
99
- },
100
- linkRevision(planId, owner, revision, linkOptions) {
101
- const replayed = replayedPlan(planId, owner, "active", linkOptions?.operationId);
102
- if (replayed)
103
- return replayed;
104
- const plan = planGet(planId, owner);
105
- if (plan?.status !== "active") {
106
- throw new Error(t("Plan {planId} must be active to link a revision (current: {status})", {
107
- planId,
108
- status: plan?.status ?? "missing",
109
- }));
110
- }
111
- if (!Number.isSafeInteger(revision) || revision < 1) {
112
- throw new Error(t("Plan revision must be a positive safe integer, got {revision}", { revision }));
113
- }
114
- return transitionPlan(planId, owner, "active", "active", {
115
- payload: { title: plan.title, branch: plan.branch, steps: plan.steps, linkedRevision: revision },
116
- operationId: linkOptions?.operationId ?? `link:${planId}:${revision}`,
117
- });
118
- },
119
- complete(planId, owner, evidence, completeOptions) {
120
- const replayed = replayedPlan(planId, owner, "completed", completeOptions?.operationId);
121
- if (replayed)
122
- return replayed;
123
- const plan = planGet(planId, owner);
124
- if (plan?.status !== "active") {
125
- throw new Error(t("Plan {planId} must be active to complete (current: {status})", {
126
- planId,
127
- status: plan?.status ?? "missing",
128
- }));
129
- }
130
- if (evidence.length === 0)
131
- throw new Error(t("Completing a plan requires at least one evidence reference"));
132
- const target = completeOptions?.atRevision ?? plan.revision;
133
- if (typeof target !== "number") {
134
- throw new Error(t("Plan {planId} requires atRevision or a linked revision to complete", { planId }));
135
- }
136
- return transitionPlan(planId, owner, "active", "completed", {
137
- evidence,
138
- payload: { title: plan.title, branch: plan.branch, steps: plan.steps, linkedRevision: target },
139
- operationId: completeOptions?.operationId,
140
- });
141
- },
142
- discard(planId, owner) {
143
- const plan = planGet(planId, owner);
144
- if (!plan || plan.status === "completed" || plan.status === "discarded") {
145
- throw new Error(t("Plan {planId} cannot be discarded from status {status}", {
146
- planId,
147
- status: plan?.status ?? "missing",
148
- }));
149
- }
150
- return transitionPlan(planId, owner, plan.status, "discarded", {});
151
- },
152
- get(planId, owner) {
153
- return planGet(planId, owner);
154
- },
155
- };
156
- }
157
- //# sourceMappingURL=plan-plugin.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"plan-plugin.js","sourceRoot":"","sources":["../../src/profile/plan-plugin.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,CAAC,EAAE,MAAM,uBAAuB,CAAC;AAmD1C,SAAS,aAAa,CAAC,MAAsC,EAAsC;IAClG,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;IAC/B,IAAI,OAAO,KAAK,IAAI,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;QAChF,OAAO,OAAiC,CAAC;IAC1C,CAAC;IACD,OAAO,SAAS,CAAC;AAAA,CACjB;AAED,MAAM,UAAU,gBAAgB,CAAC,OAAoD,EAAgB;IACpG,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IAExC,MAAM,WAAW,GAAG,CAAC,MAAc,EAAE,KAAa,EAAE,EAAE,CACrD,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,KAAK,MAAM,IAAI,MAAM,CAAC,KAAK,KAAK,KAAK,CAAC,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AClB,OAAO,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAAA,CAC9B;KACD,CAAC;AAAA,CACF","sourcesContent":["/**\n * Plan plugin (2.3c) — Plan semantics bound to a branch/revision over the\n * 2.3a transition store.\n *\n * Status graph: null → draft → active → completed, and draft/active →\n * discarded. A plan is created with its step list and bound to a code branch;\n * while active, `linkRevision` records plan progress against concrete\n * revisions, and `complete` requires evidence plus the final revision. The\n * plugin holds NO shadow state: status, revision, steps, branch, and the\n * latest linked revision are all derived from the transition history, so\n * recovery is exactly a store replay.\n */\nimport type { JsonValue } from \"@agent-forge/ai\";\nimport { t } from \"../core/i18n/index.ts\";\nimport type { TransitionEvidenceRefV1, TransitionStoreV1 } from \"./state-store.ts\";\n\nexport type PlanStatusV1 = \"draft\" | \"active\" | \"completed\" | \"discarded\";\n\nexport interface PlanStepV1 {\n\treadonly stepId: string;\n\treadonly title: string;\n}\n\nexport interface PlanV1 {\n\treadonly planId: string;\n\treadonly owner: string;\n\treadonly title: string;\n\treadonly branch: string;\n\treadonly steps: readonly PlanStepV1[];\n\treadonly status: PlanStatusV1;\n\t/** The latest revision explicitly linked while active (undefined before the first link). */\n\treadonly revision?: number;\n\treadonly evidence: readonly TransitionEvidenceRefV1[];\n\treadonly revisionNo: number;\n}\n\nexport interface PlanPluginV1 {\n\tcreatePlan(input: {\n\t\treadonly planId: string;\n\t\treadonly owner: string;\n\t\treadonly title: string;\n\t\treadonly branch: string;\n\t\treadonly steps: readonly PlanStepV1[];\n\t}): PlanV1;\n\tactivate(planId: string, owner: string, options?: { readonly operationId?: string }): PlanV1;\n\t/** Records plan progress against a concrete revision of the bound branch. */\n\tlinkRevision(planId: string, owner: string, revision: number, options?: { readonly operationId?: string }): PlanV1;\n\tcomplete(\n\t\tplanId: string,\n\t\towner: string,\n\t\tevidence: readonly TransitionEvidenceRefV1[],\n\t\toptions?: { readonly atRevision?: number; readonly operationId?: string },\n\t): PlanV1;\n\tdiscard(planId: string, owner: string): PlanV1;\n\tget(planId: string, owner: string): PlanV1 | undefined;\n}\n\ninterface PlanPayloadV1 {\n\treadonly title: string;\n\treadonly branch: string;\n\treadonly steps: readonly PlanStepV1[];\n\treadonly linkedRevision?: number;\n}\n\nfunction planPayloadOf(record: { readonly payload?: unknown }): Partial<PlanPayloadV1> | undefined {\n\tconst payload = record.payload;\n\tif (payload !== null && typeof payload === \"object\" && !Array.isArray(payload)) {\n\t\treturn payload as Partial<PlanPayloadV1>;\n\t}\n\treturn undefined;\n}\n\nexport function createPlanPlugin(options: { readonly transitions: TransitionStoreV1 }): PlanPluginV1 {\n\tconst transitions = options.transitions;\n\n\tconst planHistory = (planId: string, owner: string) =>\n\t\ttransitions.history(planId).filter((record) => record.domain === \"plan\" && record.owner === owner);\n\n\tconst current = (planId: string, owner: string): { status: PlanStatusV1; revisionNo: number } | undefined => {\n\t\tconst state = transitions.currentStatus(\"plan\", planId);\n\t\tif (state === undefined || planHistory(planId, owner).length === 0) return undefined;\n\t\treturn { status: state.status as PlanStatusV1, revisionNo: state.revision };\n\t};\n\n\tconst planGet = (planId: string, owner: string): PlanV1 | undefined => {\n\t\tconst state = current(planId, owner);\n\t\tif (!state) return undefined;\n\t\tconst history = planHistory(planId, owner);\n\t\t// v8 ignore next -- 因果校验保证每条 plan 历史都以 fromStatus=null 的创建记录开始\n\t\tconst createPayload = planPayloadOf(history.find((record) => record.fromStatus === null) ?? {});\n\t\tconst lastLinked = [...history]\n\t\t\t.reverse()\n\t\t\t.map((record) => planPayloadOf(record)?.linkedRevision)\n\t\t\t.find((revision): revision is number => typeof revision === \"number\");\n\t\tconst lastEvidence = [...history].reverse().find((record) => record.evidence.length > 0)?.evidence ?? [];\n\t\treturn {\n\t\t\tplanId,\n\t\t\towner,\n\t\t\ttitle: createPayload?.title ?? planId,\n\t\t\tbranch: createPayload?.branch ?? \"\",\n\t\t\tsteps: createPayload?.steps ?? [],\n\t\t\tstatus: state.status,\n\t\t\t...(lastLinked === undefined ? {} : { revision: lastLinked }),\n\t\t\tevidence: lastEvidence,\n\t\t\trevisionNo: state.revisionNo,\n\t\t};\n\t};\n\n\t/** A retried transition with an already-applied operationId returns the existing state instead of conflicting. */\n\tconst replayedPlan = (\n\t\tplanId: string,\n\t\towner: string,\n\t\ttoStatus: PlanStatusV1,\n\t\toperationId?: string,\n\t): PlanV1 | undefined => {\n\t\tif (!operationId) return undefined;\n\t\tconst applied = planHistory(planId, owner).some(\n\t\t\t(record) => record.toStatus === toStatus && record.operationId === operationId,\n\t\t);\n\t\treturn applied ? planGet(planId, owner) : undefined;\n\t};\n\n\tconst transitionPlan = (\n\t\tplanId: string,\n\t\towner: string,\n\t\tfromStatus: PlanStatusV1 | null,\n\t\ttoStatus: PlanStatusV1,\n\t\tplanOptions: {\n\t\t\treadonly evidence?: readonly TransitionEvidenceRefV1[];\n\t\t\treadonly payload?: PlanPayloadV1;\n\t\t\treadonly operationId?: string;\n\t\t},\n\t): PlanV1 => {\n\t\ttransitions.transition({\n\t\t\tdomain: \"plan\",\n\t\t\tentityId: planId,\n\t\t\towner,\n\t\t\tfromStatus,\n\t\t\ttoStatus,\n\t\t\toperationId: planOptions.operationId ?? `${toStatus}:${planId}`,\n\t\t\tevidence: planOptions.evidence,\n\t\t\tpayload: planOptions.payload as JsonValue | undefined,\n\t\t});\n\t\treturn planGet(planId, owner)!;\n\t};\n\n\treturn {\n\t\tcreatePlan({ planId, owner, title, branch, steps }) {\n\t\t\tif (title.trim().length === 0) throw new Error(t(\"Plan title must be a non-empty string\"));\n\t\t\tif (branch.trim().length === 0) throw new Error(t(\"Plan branch must be a non-empty string\"));\n\t\t\tif (steps.length === 0) throw new Error(t(\"Plan requires at least one step\"));\n\t\t\tconst stepIds = new Set<string>();\n\t\t\tfor (const step of steps) {\n\t\t\t\tif (typeof step.stepId !== \"string\" || step.stepId.trim().length === 0) {\n\t\t\t\t\tthrow new Error(t(\"Plan stepId must be a non-empty string\"));\n\t\t\t\t}\n\t\t\t\tif (typeof step.title !== \"string\" || step.title.trim().length === 0) {\n\t\t\t\t\tthrow new Error(t(\"Plan step title must be a non-empty string\"));\n\t\t\t\t}\n\t\t\t\tif (stepIds.has(step.stepId))\n\t\t\t\t\tthrow new Error(t(\"Duplicate plan stepId: {stepId}\", { stepId: step.stepId }));\n\t\t\t\tstepIds.add(step.stepId);\n\t\t\t}\n\t\t\treturn transitionPlan(planId, owner, null, \"draft\", {\n\t\t\t\tpayload: { title, branch, steps: [...steps] },\n\t\t\t\toperationId: `create:${planId}`,\n\t\t\t});\n\t\t},\n\t\tactivate(planId, owner, activateOptions) {\n\t\t\tconst replayed = replayedPlan(planId, owner, \"active\", activateOptions?.operationId);\n\t\t\tif (replayed) return replayed;\n\t\t\tconst plan = planGet(planId, owner);\n\t\t\tif (plan?.status !== \"draft\") {\n\t\t\t\tthrow new Error(\n\t\t\t\t\tt(\"Plan {planId} must be in draft status to activate (current: {status})\", {\n\t\t\t\t\t\tplanId,\n\t\t\t\t\t\tstatus: plan?.status ?? \"missing\",\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn transitionPlan(planId, owner, \"draft\", \"active\", { operationId: activateOptions?.operationId });\n\t\t},\n\t\tlinkRevision(planId, owner, revision, linkOptions) {\n\t\t\tconst replayed = replayedPlan(planId, owner, \"active\", linkOptions?.operationId);\n\t\t\tif (replayed) return replayed;\n\t\t\tconst plan = planGet(planId, owner);\n\t\t\tif (plan?.status !== \"active\") {\n\t\t\t\tthrow new Error(\n\t\t\t\t\tt(\"Plan {planId} must be active to link a revision (current: {status})\", {\n\t\t\t\t\t\tplanId,\n\t\t\t\t\t\tstatus: plan?.status ?? \"missing\",\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (!Number.isSafeInteger(revision) || revision < 1) {\n\t\t\t\tthrow new Error(t(\"Plan revision must be a positive safe integer, got {revision}\", { revision }));\n\t\t\t}\n\t\t\treturn transitionPlan(planId, owner, \"active\", \"active\", {\n\t\t\t\tpayload: { title: plan.title, branch: plan.branch, steps: plan.steps, linkedRevision: revision },\n\t\t\t\toperationId: linkOptions?.operationId ?? `link:${planId}:${revision}`,\n\t\t\t});\n\t\t},\n\t\tcomplete(planId, owner, evidence, completeOptions) {\n\t\t\tconst replayed = replayedPlan(planId, owner, \"completed\", completeOptions?.operationId);\n\t\t\tif (replayed) return replayed;\n\t\t\tconst plan = planGet(planId, owner);\n\t\t\tif (plan?.status !== \"active\") {\n\t\t\t\tthrow new Error(\n\t\t\t\t\tt(\"Plan {planId} must be active to complete (current: {status})\", {\n\t\t\t\t\t\tplanId,\n\t\t\t\t\t\tstatus: plan?.status ?? \"missing\",\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (evidence.length === 0) throw new Error(t(\"Completing a plan requires at least one evidence reference\"));\n\t\t\tconst target = completeOptions?.atRevision ?? plan.revision;\n\t\t\tif (typeof target !== \"number\") {\n\t\t\t\tthrow new Error(t(\"Plan {planId} requires atRevision or a linked revision to complete\", { planId }));\n\t\t\t}\n\t\t\treturn transitionPlan(planId, owner, \"active\", \"completed\", {\n\t\t\t\tevidence,\n\t\t\t\tpayload: { title: plan.title, branch: plan.branch, steps: plan.steps, linkedRevision: target },\n\t\t\t\toperationId: completeOptions?.operationId,\n\t\t\t});\n\t\t},\n\t\tdiscard(planId, owner) {\n\t\t\tconst plan = planGet(planId, owner);\n\t\t\tif (!plan || plan.status === \"completed\" || plan.status === \"discarded\") {\n\t\t\t\tthrow new Error(\n\t\t\t\t\tt(\"Plan {planId} cannot be discarded from status {status}\", {\n\t\t\t\t\t\tplanId,\n\t\t\t\t\t\tstatus: plan?.status ?? \"missing\",\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn transitionPlan(planId, owner, plan.status, \"discarded\", {});\n\t\t},\n\t\tget(planId, owner) {\n\t\t\treturn planGet(planId, owner);\n\t\t},\n\t};\n}\n"]}
@@ -1,53 +0,0 @@
1
- /**
2
- * Default policy manifest (2.7e) — an explicit, declarative manifest of the
3
- * confirmation / permission / dangerous-operation policies a profile wants,
4
- * with an external selection path.
5
- *
6
- * The manifest is PURE DECLARATION: the kernel ships no policy enforcement —
7
- * an enforcement plugin (or none at all) attaches externally. Every entry
8
- * states its `enabled` flag explicitly; selecting an external policy
9
- * replaces or nulls (disables) a declaration and produces a NEW frozen
10
- * manifest plus a change record — the previous manifest stays untouched.
11
- * Digests reuse the key-order-stable serialization so declarations are
12
- * replayable.
13
- */
14
- import type { JsonValue } from "@agent-forge/ai";
15
- export type PolicyKindV1 = "confirmation" | "permission" | "dangerous_operation";
16
- export interface PolicyDeclarationV1 {
17
- readonly policyKind: PolicyKindV1;
18
- readonly policyId: string;
19
- readonly description: string;
20
- /** Stated explicitly — a policy the profile does not want is `false`. */
21
- readonly enabled: boolean;
22
- readonly defaults?: JsonValue;
23
- }
24
- export interface PolicyManifestV1 {
25
- readonly manifestVersion: 1;
26
- readonly profileId: string;
27
- readonly declarations: readonly PolicyDeclarationV1[];
28
- readonly manifestDigest: string;
29
- }
30
- export interface PolicyChangeRecordV1 {
31
- readonly policyKind: PolicyKindV1;
32
- readonly policyId: string;
33
- readonly action: "disabled" | "external_selected";
34
- readonly reason: string;
35
- }
36
- export interface PolicyManifestBuilderV1 {
37
- buildManifest(input: {
38
- readonly profileId: string;
39
- readonly declarations: readonly PolicyDeclarationV1[];
40
- }): PolicyManifestV1;
41
- /** The external selection path: swap in an external declaration or disable one (null). */
42
- selectExternalPolicy(manifest: PolicyManifestV1, input: {
43
- readonly policyKind: PolicyKindV1;
44
- readonly policyId: string;
45
- readonly external: PolicyDeclarationV1 | null;
46
- readonly reason: string;
47
- }): {
48
- readonly manifest: PolicyManifestV1;
49
- readonly change: PolicyChangeRecordV1;
50
- };
51
- }
52
- export declare function createPolicyManifestBuilder(): PolicyManifestBuilderV1;
53
- //# sourceMappingURL=policy-manifest.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"policy-manifest.d.ts","sourceRoot":"","sources":["../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,EAAE,MAAM,CAAC;QAC1B,QAAQ,CAAC,QAAQ,EAAE,mBAAmB,GAAG,IAAI,CAAC;QAC9C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;KACxB,GACC;QAAE,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC;QAAC,QAAQ,CAAC,MAAM,EAAE,oBAAoB,CAAA;KAAE,CAAC;CAClF;AAgBD,wBAAgB,2BAA2B,IAAI,uBAAuB,CA6CrE","sourcesContent":["/**\n * Default policy manifest (2.7e) — an explicit, declarative manifest of the\n * confirmation / permission / dangerous-operation policies a profile wants,\n * with an external selection path.\n *\n * The manifest is PURE DECLARATION: the kernel ships no policy enforcement —\n * an enforcement plugin (or none at all) attaches externally. Every entry\n * states its `enabled` flag explicitly; selecting an external policy\n * replaces or nulls (disables) a declaration and produces a NEW frozen\n * manifest plus a change record — the previous manifest stays untouched.\n * Digests reuse the key-order-stable serialization so declarations are\n * replayable.\n */\nimport type { JsonValue } from \"@agent-forge/ai\";\nimport { t } from \"../core/i18n/index.ts\";\nimport { stableJsonDigest } from \"./identity.ts\";\n\nexport type PolicyKindV1 = \"confirmation\" | \"permission\" | \"dangerous_operation\";\n\nexport interface PolicyDeclarationV1 {\n\treadonly policyKind: PolicyKindV1;\n\treadonly policyId: string;\n\treadonly description: string;\n\t/** Stated explicitly — a policy the profile does not want is `false`. */\n\treadonly enabled: boolean;\n\treadonly defaults?: JsonValue;\n}\n\nexport interface PolicyManifestV1 {\n\treadonly manifestVersion: 1;\n\treadonly profileId: string;\n\treadonly declarations: readonly PolicyDeclarationV1[];\n\treadonly manifestDigest: string;\n}\n\nexport interface PolicyChangeRecordV1 {\n\treadonly policyKind: PolicyKindV1;\n\treadonly policyId: string;\n\treadonly action: \"disabled\" | \"external_selected\";\n\treadonly reason: string;\n}\n\nexport interface PolicyManifestBuilderV1 {\n\tbuildManifest(input: {\n\t\treadonly profileId: string;\n\t\treadonly declarations: readonly PolicyDeclarationV1[];\n\t}): PolicyManifestV1;\n\t/** The external selection path: swap in an external declaration or disable one (null). */\n\tselectExternalPolicy(\n\t\tmanifest: PolicyManifestV1,\n\t\tinput: {\n\t\t\treadonly policyKind: PolicyKindV1;\n\t\t\treadonly policyId: string;\n\t\t\treadonly external: PolicyDeclarationV1 | null;\n\t\t\treadonly reason: string;\n\t\t},\n\t): { readonly manifest: PolicyManifestV1; readonly change: PolicyChangeRecordV1 };\n}\n\nfunction assertDeclaration(value: PolicyDeclarationV1): void {\n\tif (![\"confirmation\", \"permission\", \"dangerous_operation\"].includes(value.policyKind)) {\n\t\tthrow new Error(\n\t\t\tt(\"Policy manifest policyKind is invalid: {policyKind}\", { policyKind: String(value.policyKind) }),\n\t\t);\n\t}\n\tif (typeof value.policyId !== \"string\" || value.policyId.trim().length === 0) {\n\t\tthrow new Error(t(\"Policy manifest policyId must be a non-empty string\"));\n\t}\n\tif (typeof value.enabled !== \"boolean\") {\n\t\tthrow new Error(t(\"Policy manifest {policyId}: enabled must be stated explicitly\", { policyId: value.policyId }));\n\t}\n}\n\nexport function createPolicyManifestBuilder(): PolicyManifestBuilderV1 {\n\tconst buildManifest = (input: {\n\t\treadonly profileId: string;\n\t\treadonly declarations: readonly PolicyDeclarationV1[];\n\t}): PolicyManifestV1 => {\n\t\tif (input.profileId.trim().length === 0)\n\t\t\tthrow new Error(t(\"Policy manifest profileId must be a non-empty string\"));\n\t\tfor (const declaration of input.declarations) assertDeclaration(declaration);\n\t\tconst declarations = Object.freeze(input.declarations.map((declaration) => Object.freeze({ ...declaration })));\n\t\treturn Object.freeze({\n\t\t\tmanifestVersion: 1 as const,\n\t\t\tprofileId: input.profileId,\n\t\t\tdeclarations,\n\t\t\tmanifestDigest: stableJsonDigest(declarations as unknown as JsonValue),\n\t\t});\n\t};\n\n\treturn {\n\t\tbuildManifest,\n\t\tselectExternalPolicy(manifest, input) {\n\t\t\tassertDeclaration(\n\t\t\t\tinput.external ?? {\n\t\t\t\t\tpolicyKind: input.policyKind,\n\t\t\t\t\tpolicyId: input.policyId,\n\t\t\t\t\tdescription: \"\",\n\t\t\t\t\tenabled: false,\n\t\t\t\t},\n\t\t\t);\n\t\t\tconst kept = manifest.declarations.filter(\n\t\t\t\t(declaration) => !(declaration.policyKind === input.policyKind && declaration.policyId === input.policyId),\n\t\t\t);\n\t\t\tconst existed = kept.length !== manifest.declarations.length;\n\t\t\tconst declarations = input.external === null ? kept : [...kept, input.external];\n\t\t\tconst next = buildManifest({ profileId: manifest.profileId, declarations });\n\t\t\treturn {\n\t\t\t\tmanifest: next,\n\t\t\t\tchange: {\n\t\t\t\t\tpolicyKind: input.policyKind,\n\t\t\t\t\tpolicyId: input.policyId,\n\t\t\t\t\taction: input.external === null ? \"disabled\" : existed ? \"external_selected\" : \"external_selected\",\n\t\t\t\t\treason: input.reason,\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t};\n}\n"]}
@@ -1,53 +0,0 @@
1
- import { t } from "../core/i18n/index.js";
2
- import { stableJsonDigest } from "./identity.js";
3
- function assertDeclaration(value) {
4
- if (!["confirmation", "permission", "dangerous_operation"].includes(value.policyKind)) {
5
- throw new Error(t("Policy manifest policyKind is invalid: {policyKind}", { policyKind: String(value.policyKind) }));
6
- }
7
- if (typeof value.policyId !== "string" || value.policyId.trim().length === 0) {
8
- throw new Error(t("Policy manifest policyId must be a non-empty string"));
9
- }
10
- if (typeof value.enabled !== "boolean") {
11
- throw new Error(t("Policy manifest {policyId}: enabled must be stated explicitly", { policyId: value.policyId }));
12
- }
13
- }
14
- export function createPolicyManifestBuilder() {
15
- const buildManifest = (input) => {
16
- if (input.profileId.trim().length === 0)
17
- throw new Error(t("Policy manifest profileId must be a non-empty string"));
18
- for (const declaration of input.declarations)
19
- assertDeclaration(declaration);
20
- const declarations = Object.freeze(input.declarations.map((declaration) => Object.freeze({ ...declaration })));
21
- return Object.freeze({
22
- manifestVersion: 1,
23
- profileId: input.profileId,
24
- declarations,
25
- manifestDigest: stableJsonDigest(declarations),
26
- });
27
- };
28
- return {
29
- buildManifest,
30
- selectExternalPolicy(manifest, input) {
31
- assertDeclaration(input.external ?? {
32
- policyKind: input.policyKind,
33
- policyId: input.policyId,
34
- description: "",
35
- enabled: false,
36
- });
37
- const kept = manifest.declarations.filter((declaration) => !(declaration.policyKind === input.policyKind && declaration.policyId === input.policyId));
38
- const existed = kept.length !== manifest.declarations.length;
39
- const declarations = input.external === null ? kept : [...kept, input.external];
40
- const next = buildManifest({ profileId: manifest.profileId, declarations });
41
- return {
42
- manifest: next,
43
- change: {
44
- policyKind: input.policyKind,
45
- policyId: input.policyId,
46
- action: input.external === null ? "disabled" : existed ? "external_selected" : "external_selected",
47
- reason: input.reason,
48
- },
49
- };
50
- },
51
- };
52
- }
53
- //# sourceMappingURL=policy-manifest.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"policy-manifest.js","sourceRoot":"","sources":["../../src/profile/policy-manifest.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,CAAC,EAAE,MAAM,uBAAuB,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AA4CjD,SAAS,iBAAiB,CAAC,KAA0B,EAAQ;IAC5D,IAAI,CAAC,CAAC,cAAc,EAAE,YAAY,EAAE,qBAAqB,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC;QACvF,MAAM,IAAI,KAAK,CACd,CAAC,CAAC,qDAAqD,EAAE,EAAE,UAAU,EAAE,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC,CAClG,CAAC;IACH,CAAC;IACD,IAAI,OAAO,KAAK,CAAC,QAAQ,KAAK,QAAQ,IAAI,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC9E,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,qDAAqD,CAAC,CAAC,CAAC;IAC3E,CAAC;IACD,IAAI,OAAO,KAAK,CAAC,OAAO,KAAK,SA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KAAK,KAAK,CAAC,UAAU,IAAI,WAAW,CAAC,QAAQ,KAAK,KAAK,CAAC,QAAQ,CAAC,CAC1G,CAAC;YACF,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,KAAK,QAAQ,CAAC,YAAY,CAAC,MAAM,CAAC;YAC7D,MAAM,YAAY,GAAG,KAAK,CAAC,QAAQ,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;YAChF,MAAM,IAAI,GAAG,aAAa,CAAC,EAAE,SAAS,EAAE,QAAQ,CAAC,SAAS,EAAE,YAAY,EAAE,CAAC,CAAC;YAC5E,OAAO;gBACN,QAAQ,EAAE,IAAI;gBACd,MAAM,EAAE;oBACP,UAAU,EAAE,KAAK,CAAC,UAAU;oBAC5B,QAAQ,EAAE,KAAK,CAAC,QAAQ;oBACxB,MAAM,EAAE,KAAK,CAAC,QAAQ,KAAK,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,mBAAmB;oBAClG,MAAM,EAAE,KAAK,CAAC,MAAM;iBACpB;aACD,CAAC;QAAA,CACF;KACD,CAAC;AAAA,CACF","sourcesContent":["/**\n * Default policy manifest (2.7e) — an explicit, declarative manifest of the\n * confirmation / permission / dangerous-operation policies a profile wants,\n * with an external selection path.\n *\n * The manifest is PURE DECLARATION: the kernel ships no policy enforcement —\n * an enforcement plugin (or none at all) attaches externally. Every entry\n * states its `enabled` flag explicitly; selecting an external policy\n * replaces or nulls (disables) a declaration and produces a NEW frozen\n * manifest plus a change record — the previous manifest stays untouched.\n * Digests reuse the key-order-stable serialization so declarations are\n * replayable.\n */\nimport type { JsonValue } from \"@agent-forge/ai\";\nimport { t } from \"../core/i18n/index.ts\";\nimport { stableJsonDigest } from \"./identity.ts\";\n\nexport type PolicyKindV1 = \"confirmation\" | \"permission\" | \"dangerous_operation\";\n\nexport interface PolicyDeclarationV1 {\n\treadonly policyKind: PolicyKindV1;\n\treadonly policyId: string;\n\treadonly description: string;\n\t/** Stated explicitly — a policy the profile does not want is `false`. */\n\treadonly enabled: boolean;\n\treadonly defaults?: JsonValue;\n}\n\nexport interface PolicyManifestV1 {\n\treadonly manifestVersion: 1;\n\treadonly profileId: string;\n\treadonly declarations: readonly PolicyDeclarationV1[];\n\treadonly manifestDigest: string;\n}\n\nexport interface PolicyChangeRecordV1 {\n\treadonly policyKind: PolicyKindV1;\n\treadonly policyId: string;\n\treadonly action: \"disabled\" | \"external_selected\";\n\treadonly reason: string;\n}\n\nexport interface PolicyManifestBuilderV1 {\n\tbuildManifest(input: {\n\t\treadonly profileId: string;\n\t\treadonly declarations: readonly PolicyDeclarationV1[];\n\t}): PolicyManifestV1;\n\t/** The external selection path: swap in an external declaration or disable one (null). */\n\tselectExternalPolicy(\n\t\tmanifest: PolicyManifestV1,\n\t\tinput: {\n\t\t\treadonly policyKind: PolicyKindV1;\n\t\t\treadonly policyId: string;\n\t\t\treadonly external: PolicyDeclarationV1 | null;\n\t\t\treadonly reason: string;\n\t\t},\n\t): { readonly manifest: PolicyManifestV1; readonly change: PolicyChangeRecordV1 };\n}\n\nfunction assertDeclaration(value: PolicyDeclarationV1): void {\n\tif (![\"confirmation\", \"permission\", \"dangerous_operation\"].includes(value.policyKind)) {\n\t\tthrow new Error(\n\t\t\tt(\"Policy manifest policyKind is invalid: {policyKind}\", { policyKind: String(value.policyKind) }),\n\t\t);\n\t}\n\tif (typeof value.policyId !== \"string\" || value.policyId.trim().length === 0) {\n\t\tthrow new Error(t(\"Policy manifest policyId must be a non-empty string\"));\n\t}\n\tif (typeof value.enabled !== \"boolean\") {\n\t\tthrow new Error(t(\"Policy manifest {policyId}: enabled must be stated explicitly\", { policyId: value.policyId }));\n\t}\n}\n\nexport function createPolicyManifestBuilder(): PolicyManifestBuilderV1 {\n\tconst buildManifest = (input: {\n\t\treadonly profileId: string;\n\t\treadonly declarations: readonly PolicyDeclarationV1[];\n\t}): PolicyManifestV1 => {\n\t\tif (input.profileId.trim().length === 0)\n\t\t\tthrow new Error(t(\"Policy manifest profileId must be a non-empty string\"));\n\t\tfor (const declaration of input.declarations) assertDeclaration(declaration);\n\t\tconst declarations = Object.freeze(input.declarations.map((declaration) => Object.freeze({ ...declaration })));\n\t\treturn Object.freeze({\n\t\t\tmanifestVersion: 1 as const,\n\t\t\tprofileId: input.profileId,\n\t\t\tdeclarations,\n\t\t\tmanifestDigest: stableJsonDigest(declarations as unknown as JsonValue),\n\t\t});\n\t};\n\n\treturn {\n\t\tbuildManifest,\n\t\tselectExternalPolicy(manifest, input) {\n\t\t\tassertDeclaration(\n\t\t\t\tinput.external ?? {\n\t\t\t\t\tpolicyKind: input.policyKind,\n\t\t\t\t\tpolicyId: input.policyId,\n\t\t\t\t\tdescription: \"\",\n\t\t\t\t\tenabled: false,\n\t\t\t\t},\n\t\t\t);\n\t\t\tconst kept = manifest.declarations.filter(\n\t\t\t\t(declaration) => !(declaration.policyKind === input.policyKind && declaration.policyId === input.policyId),\n\t\t\t);\n\t\t\tconst existed = kept.length !== manifest.declarations.length;\n\t\t\tconst declarations = input.external === null ? kept : [...kept, input.external];\n\t\t\tconst next = buildManifest({ profileId: manifest.profileId, declarations });\n\t\t\treturn {\n\t\t\t\tmanifest: next,\n\t\t\t\tchange: {\n\t\t\t\t\tpolicyKind: input.policyKind,\n\t\t\t\t\tpolicyId: input.policyId,\n\t\t\t\t\taction: input.external === null ? \"disabled\" : existed ? \"external_selected\" : \"external_selected\",\n\t\t\t\t\treason: input.reason,\n\t\t\t\t},\n\t\t\t};\n\t\t},\n\t};\n}\n"]}
@@ -1,47 +0,0 @@
1
- /**
2
- * Role assembly (2.2d) — builds a `RoleCatalogV1` plus a role-runner binding
3
- * from registered role metadata, evaluates every role's REQUIRED capability
4
- * dependencies against the available capability registry (2.5a structured
5
- * `missing` diagnostics), and exposes the sorted roleId summary consumed by
6
- * the code profile package assembly (2.7c). The same input always assembles
7
- * identically; duplicate roleIds fail explicitly through the catalog.
8
- */
9
- import type { AvailableCapabilityV1 } from "./dependency-wiring.ts";
10
- import { type RoleCatalogV1, type RoleMetadataV1 } from "./role-catalog.ts";
11
- import { type RoleMissingCapabilityV1, type RoleRunCallbackV1, type RoleRunnerV1 } from "./role-runner.ts";
12
- /** One registered role: catalog metadata plus an optional per-role run binding. */
13
- export interface RegisteredRoleMetaV1 {
14
- readonly metadata: RoleMetadataV1;
15
- /**
16
- * Optional per-role run override. Run-binding precedence: per-role override
17
- * → deterministic first-batch callback → explicit failure for roles
18
- * without any first-batch callback.
19
- */
20
- readonly run?: RoleRunCallbackV1;
21
- }
22
- /** Aggregated required-dependency diagnostics across all assembled roles. */
23
- export interface RoleAssemblyDiagnosticsV1 {
24
- readonly status: "satisfied" | "missing";
25
- readonly missing: readonly RoleMissingCapabilityV1[];
26
- }
27
- /** Assembled role mount: catalog + runner binding + identity summary + diagnostics. */
28
- export interface RoleAssemblyV1 {
29
- readonly catalog: RoleCatalogV1;
30
- readonly runner: RoleRunnerV1;
31
- /** Sorted registered roleId summary (package identity/diagnostics surface). */
32
- readonly roleIds: readonly string[];
33
- readonly capabilityDiagnostics: RoleAssemblyDiagnosticsV1;
34
- }
35
- /** Data-only role mount summary carried by a ready code profile package. */
36
- export interface MountedRoleSummaryV1 {
37
- readonly roleIds: readonly string[];
38
- readonly capabilityDiagnostics: RoleAssemblyDiagnosticsV1;
39
- }
40
- /** Assembles registered role metadata into a catalog + runner binding object. */
41
- export declare function assembleRoles(input: {
42
- readonly roles: readonly RegisteredRoleMetaV1[];
43
- readonly availableCapabilities: readonly AvailableCapabilityV1[];
44
- /** Owner stamped onto produced child definitions (see `createRoleRunner`). */
45
- readonly owner?: string;
46
- }): RoleAssemblyV1;
47
- //# sourceMappingURL=role-assembly.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"role-assembly.d.ts","sourceRoot":"","sources":["../../src/profile/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AAC;CACxB,GAAG,cAAc,CA4BjB","sourcesContent":["/**\n * Role assembly (2.2d) — builds a `RoleCatalogV1` plus a role-runner binding\n * from registered role metadata, evaluates every role's REQUIRED capability\n * dependencies against the available capability registry (2.5a structured\n * `missing` diagnostics), and exposes the sorted roleId summary consumed by\n * the code profile package assembly (2.7c). The same input always assembles\n * identically; duplicate roleIds fail explicitly through the catalog.\n */\nimport type { AvailableCapabilityV1 } from \"./dependency-wiring.ts\";\nimport { createRoleCatalog, type RoleCatalogV1, type RoleMetadataV1 } from \"./role-catalog.ts\";\nimport {\n\tcreateRoleRunner,\n\ttype RoleMissingCapabilityV1,\n\ttype RoleRunCallbackV1,\n\ttype RoleRunnerV1,\n\ttype RoleRunResolverV1,\n\trunFirstBatchRole,\n} from \"./role-runner.ts\";\n\n/** One registered role: catalog metadata plus an optional per-role run binding. */\nexport interface RegisteredRoleMetaV1 {\n\treadonly metadata: RoleMetadataV1;\n\t/**\n\t * Optional per-role run override. Run-binding precedence: per-role override\n\t * → deterministic first-batch callback → explicit failure for roles\n\t * without any first-batch callback.\n\t */\n\treadonly run?: RoleRunCallbackV1;\n}\n\n/** Aggregated required-dependency diagnostics across all assembled roles. */\nexport interface RoleAssemblyDiagnosticsV1 {\n\treadonly status: \"satisfied\" | \"missing\";\n\treadonly missing: readonly RoleMissingCapabilityV1[];\n}\n\n/** Assembled role mount: catalog + runner binding + identity summary + diagnostics. */\nexport interface RoleAssemblyV1 {\n\treadonly catalog: RoleCatalogV1;\n\treadonly runner: RoleRunnerV1;\n\t/** Sorted registered roleId summary (package identity/diagnostics surface). */\n\treadonly roleIds: readonly string[];\n\treadonly capabilityDiagnostics: RoleAssemblyDiagnosticsV1;\n}\n\n/** Data-only role mount summary carried by a ready code profile package. */\nexport interface MountedRoleSummaryV1 {\n\treadonly roleIds: readonly string[];\n\treadonly capabilityDiagnostics: RoleAssemblyDiagnosticsV1;\n}\n\n/** Assembles registered role metadata into a catalog + runner binding object. */\nexport function assembleRoles(input: {\n\treadonly roles: readonly RegisteredRoleMetaV1[];\n\treadonly availableCapabilities: readonly AvailableCapabilityV1[];\n\t/** Owner stamped onto produced child definitions (see `createRoleRunner`). */\n\treadonly owner?: string;\n}): RoleAssemblyV1 {\n\tconst catalog = createRoleCatalog(input.roles.map((role) => role.metadata));\n\tconst overrides = new Map<string, RoleRunCallbackV1>(\n\t\tinput.roles.flatMap((role) => (role.run ? [[role.metadata.roleId, role.run] as const] : [])),\n\t);\n\tconst runner = createRoleRunner({\n\t\tcatalog,\n\t\t...(input.owner === undefined ? {} : { owner: input.owner }),\n\t\t...(overrides.size > 0\n\t\t\t? {\n\t\t\t\t\trun: ((roleId, runInput, context) => {\n\t\t\t\t\t\tconst override = overrides.get(roleId);\n\t\t\t\t\t\treturn override ? override(runInput, context) : runFirstBatchRole(roleId, runInput, context);\n\t\t\t\t\t}) satisfies RoleRunResolverV1,\n\t\t\t\t}\n\t\t\t: {}),\n\t});\n\tconst roleIds = catalog.list().map((role) => role.roleId);\n\tconst missing = roleIds.flatMap((roleId) => runner.checkCapabilities(roleId, input.availableCapabilities).missing);\n\treturn Object.freeze({\n\t\tcatalog,\n\t\trunner,\n\t\troleIds: Object.freeze([...roleIds]),\n\t\tcapabilityDiagnostics: Object.freeze({\n\t\t\tstatus: missing.length > 0 ? \"missing\" : \"satisfied\",\n\t\t\tmissing: Object.freeze(missing),\n\t\t}),\n\t});\n}\n"]}