@ai-agent-forge/agent-forge 0.86.7 → 0.87.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (665) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +8 -9
  3. package/dist/artifacts/artifact-store.d.ts.map +1 -1
  4. package/dist/artifacts/artifact-store.js +9 -5
  5. package/dist/artifacts/artifact-store.js.map +1 -1
  6. package/dist/bundle/.build-manifest.json +410 -371
  7. package/dist/bundle/chunks/{chunk-A7GUOX2H.js → chunk-6ZKDNZHA.js} +5 -1
  8. package/dist/bundle/chunks/chunk-BFC2BDVJ.js +13 -0
  9. package/dist/bundle/chunks/chunk-MOHOLL3F.js +1456 -0
  10. package/dist/bundle/chunks/image-resize-worker.js +12 -1
  11. package/dist/bundle/chunks/{virtual-modules-3IZ4MYSQ.js → virtual-modules-KZ5DRH7Q.js} +1 -1
  12. package/dist/bundle/cli.js +1 -1
  13. package/dist/bundle/client.js +1 -1
  14. package/dist/bundle/index.js +2 -2
  15. package/dist/bundle/rpc-entry.js +1 -1
  16. package/dist/cli/args.d.ts.map +1 -1
  17. package/dist/cli/args.js +231 -185
  18. package/dist/cli/args.js.map +1 -1
  19. package/dist/cli/auth-check.d.ts.map +1 -1
  20. package/dist/cli/auth-check.js +3 -2
  21. package/dist/cli/auth-check.js.map +1 -1
  22. package/dist/cli/auth-command.d.ts.map +1 -1
  23. package/dist/cli/auth-command.js +15 -9
  24. package/dist/cli/auth-command.js.map +1 -1
  25. package/dist/cli/credential-print.d.ts.map +1 -1
  26. package/dist/cli/credential-print.js +14 -7
  27. package/dist/cli/credential-print.js.map +1 -1
  28. package/dist/cli/experimental/command.d.ts.map +1 -1
  29. package/dist/cli/experimental/command.js +6 -5
  30. package/dist/cli/experimental/command.js.map +1 -1
  31. package/dist/cli/list-models.d.ts.map +1 -1
  32. package/dist/cli/list-models.js +9 -8
  33. package/dist/cli/list-models.js.map +1 -1
  34. package/dist/cli/plugin-manager-controller.d.ts.map +1 -1
  35. package/dist/cli/plugin-manager-controller.js +2 -1
  36. package/dist/cli/plugin-manager-controller.js.map +1 -1
  37. package/dist/cli/serve.d.ts.map +1 -1
  38. package/dist/cli/serve.js +8 -5
  39. package/dist/cli/serve.js.map +1 -1
  40. package/dist/client/remote-session.d.ts.map +1 -1
  41. package/dist/client/remote-session.js +16 -9
  42. package/dist/client/remote-session.js.map +1 -1
  43. package/dist/config.d.ts.map +1 -1
  44. package/dist/config.js +2 -1
  45. package/dist/config.js.map +1 -1
  46. package/dist/core/agent-capability-contract.d.ts +0 -7
  47. package/dist/core/agent-capability-contract.d.ts.map +1 -1
  48. package/dist/core/agent-capability-contract.js +72 -68
  49. package/dist/core/agent-capability-contract.js.map +1 -1
  50. package/dist/core/agent-session-bash.d.ts.map +1 -1
  51. package/dist/core/agent-session-bash.js +5 -4
  52. package/dist/core/agent-session-bash.js.map +1 -1
  53. package/dist/core/agent-session-compaction.d.ts.map +1 -1
  54. package/dist/core/agent-session-compaction.js +28 -22
  55. package/dist/core/agent-session-compaction.js.map +1 -1
  56. package/dist/core/agent-session-context.d.ts.map +1 -1
  57. package/dist/core/agent-session-context.js +18 -13
  58. package/dist/core/agent-session-context.js.map +1 -1
  59. package/dist/core/agent-session-model.d.ts.map +1 -1
  60. package/dist/core/agent-session-model.js +2 -1
  61. package/dist/core/agent-session-model.js.map +1 -1
  62. package/dist/core/agent-session-retry.d.ts.map +1 -1
  63. package/dist/core/agent-session-retry.js +3 -2
  64. package/dist/core/agent-session-retry.js.map +1 -1
  65. package/dist/core/agent-session-runtime.d.ts.map +1 -1
  66. package/dist/core/agent-session-runtime.js +7 -6
  67. package/dist/core/agent-session-runtime.js.map +1 -1
  68. package/dist/core/agent-session-services.d.ts +1 -1
  69. package/dist/core/agent-session-services.d.ts.map +1 -1
  70. package/dist/core/agent-session-services.js.map +1 -1
  71. package/dist/core/agent-session-tools.d.ts.map +1 -1
  72. package/dist/core/agent-session-tools.js +3 -2
  73. package/dist/core/agent-session-tools.js.map +1 -1
  74. package/dist/core/agent-session.d.ts +40 -2
  75. package/dist/core/agent-session.d.ts.map +1 -1
  76. package/dist/core/agent-session.js +142 -34
  77. package/dist/core/agent-session.js.map +1 -1
  78. package/dist/core/auth-guidance.d.ts.map +1 -1
  79. package/dist/core/auth-guidance.js +11 -5
  80. package/dist/core/auth-guidance.js.map +1 -1
  81. package/dist/core/auth-storage.d.ts.map +1 -1
  82. package/dist/core/auth-storage.js +9 -6
  83. package/dist/core/auth-storage.js.map +1 -1
  84. package/dist/core/compaction/compaction.d.ts.map +1 -1
  85. package/dist/core/compaction/compaction.js +2 -1
  86. package/dist/core/compaction/compaction.js.map +1 -1
  87. package/dist/core/embedded-sdk.d.ts.map +1 -1
  88. package/dist/core/embedded-sdk.js +10 -6
  89. package/dist/core/embedded-sdk.js.map +1 -1
  90. package/dist/core/export-html/index.d.ts.map +1 -1
  91. package/dist/core/export-html/index.js +9 -4
  92. package/dist/core/export-html/index.js.map +1 -1
  93. package/dist/core/extensions/agent-composition.d.ts.map +1 -1
  94. package/dist/core/extensions/agent-composition.js +26 -19
  95. package/dist/core/extensions/agent-composition.js.map +1 -1
  96. package/dist/core/extensions/bootstrap-agent-loop.d.ts.map +1 -1
  97. package/dist/core/extensions/bootstrap-agent-loop.js +3 -2
  98. package/dist/core/extensions/bootstrap-agent-loop.js.map +1 -1
  99. package/dist/core/extensions/bootstrap-lifecycle.d.ts.map +1 -1
  100. package/dist/core/extensions/bootstrap-lifecycle.js +20 -17
  101. package/dist/core/extensions/bootstrap-lifecycle.js.map +1 -1
  102. package/dist/core/extensions/bootstrap-overflow-policy.d.ts.map +1 -1
  103. package/dist/core/extensions/bootstrap-overflow-policy.js +2 -1
  104. package/dist/core/extensions/bootstrap-overflow-policy.js.map +1 -1
  105. package/dist/core/extensions/bootstrap-retry-policy.d.ts.map +1 -1
  106. package/dist/core/extensions/bootstrap-retry-policy.js +2 -1
  107. package/dist/core/extensions/bootstrap-retry-policy.js.map +1 -1
  108. package/dist/core/extensions/bootstrap-skills.d.ts.map +1 -1
  109. package/dist/core/extensions/bootstrap-skills.js +7 -6
  110. package/dist/core/extensions/bootstrap-skills.js.map +1 -1
  111. package/dist/core/extensions/bootstrap-tools.d.ts.map +1 -1
  112. package/dist/core/extensions/bootstrap-tools.js +2 -1
  113. package/dist/core/extensions/bootstrap-tools.js.map +1 -1
  114. package/dist/core/extensions/capability-plugin.d.ts.map +1 -1
  115. package/dist/core/extensions/capability-plugin.js +37 -13
  116. package/dist/core/extensions/capability-plugin.js.map +1 -1
  117. package/dist/core/extensions/capability-runtime-events.d.ts.map +1 -1
  118. package/dist/core/extensions/capability-runtime-events.js +17 -13
  119. package/dist/core/extensions/capability-runtime-events.js.map +1 -1
  120. package/dist/core/extensions/capability-runtime-guards.d.ts.map +1 -1
  121. package/dist/core/extensions/capability-runtime-guards.js +16 -15
  122. package/dist/core/extensions/capability-runtime-guards.js.map +1 -1
  123. package/dist/core/extensions/capability-runtime-manifest.d.ts.map +1 -1
  124. package/dist/core/extensions/capability-runtime-manifest.js +52 -30
  125. package/dist/core/extensions/capability-runtime-manifest.js.map +1 -1
  126. package/dist/core/extensions/capability-runtime-validation.d.ts.map +1 -1
  127. package/dist/core/extensions/capability-runtime-validation.js +66 -65
  128. package/dist/core/extensions/capability-runtime-validation.js.map +1 -1
  129. package/dist/core/extensions/capability-runtime.d.ts.map +1 -1
  130. package/dist/core/extensions/capability-runtime.js +147 -127
  131. package/dist/core/extensions/capability-runtime.js.map +1 -1
  132. package/dist/core/extensions/compaction-memory-failure-mode.d.ts.map +1 -1
  133. package/dist/core/extensions/compaction-memory-failure-mode.js +3 -2
  134. package/dist/core/extensions/compaction-memory-failure-mode.js.map +1 -1
  135. package/dist/core/extensions/context-strategy-binding.d.ts.map +1 -1
  136. package/dist/core/extensions/context-strategy-binding.js +7 -4
  137. package/dist/core/extensions/context-strategy-binding.js.map +1 -1
  138. package/dist/core/extensions/lifecycle-catalog.d.ts.map +1 -1
  139. package/dist/core/extensions/lifecycle-catalog.js +290 -279
  140. package/dist/core/extensions/lifecycle-catalog.js.map +1 -1
  141. package/dist/core/extensions/lifecycle-delivery-queue.d.ts.map +1 -1
  142. package/dist/core/extensions/lifecycle-delivery-queue.js +3 -2
  143. package/dist/core/extensions/lifecycle-delivery-queue.js.map +1 -1
  144. package/dist/core/facade/coding-agent-facade.d.ts +6 -0
  145. package/dist/core/facade/coding-agent-facade.d.ts.map +1 -1
  146. package/dist/core/facade/coding-agent-facade.js +2 -0
  147. package/dist/core/facade/coding-agent-facade.js.map +1 -1
  148. package/dist/core/http-dispatcher.d.ts.map +1 -1
  149. package/dist/core/http-dispatcher.js +2 -1
  150. package/dist/core/http-dispatcher.js.map +1 -1
  151. package/dist/core/i18n/index.d.ts +14 -0
  152. package/dist/core/i18n/index.d.ts.map +1 -0
  153. package/dist/core/i18n/index.js +67 -0
  154. package/dist/core/i18n/index.js.map +1 -0
  155. package/dist/core/i18n/locales/en/example.d.ts +7 -0
  156. package/dist/core/i18n/locales/en/example.d.ts.map +1 -0
  157. package/dist/core/i18n/locales/en/example.js +7 -0
  158. package/dist/core/i18n/locales/en/example.js.map +1 -0
  159. package/dist/core/i18n/locales/zh-cn/cli.d.ts +8 -0
  160. package/dist/core/i18n/locales/zh-cn/cli.d.ts.map +1 -0
  161. package/dist/core/i18n/locales/zh-cn/cli.js +227 -0
  162. package/dist/core/i18n/locales/zh-cn/cli.js.map +1 -0
  163. package/dist/core/i18n/locales/zh-cn/common.d.ts +6 -0
  164. package/dist/core/i18n/locales/zh-cn/common.d.ts.map +1 -0
  165. package/dist/core/i18n/locales/zh-cn/common.js +6 -0
  166. package/dist/core/i18n/locales/zh-cn/common.js.map +1 -0
  167. package/dist/core/i18n/locales/zh-cn/core-contract-core.d.ts +13 -0
  168. package/dist/core/i18n/locales/zh-cn/core-contract-core.d.ts.map +1 -0
  169. package/dist/core/i18n/locales/zh-cn/core-contract-core.js +173 -0
  170. package/dist/core/i18n/locales/zh-cn/core-contract-core.js.map +1 -0
  171. package/dist/core/i18n/locales/zh-cn/core-contract-extensions.d.ts +12 -0
  172. package/dist/core/i18n/locales/zh-cn/core-contract-extensions.d.ts.map +1 -0
  173. package/dist/core/i18n/locales/zh-cn/core-contract-extensions.js +582 -0
  174. package/dist/core/i18n/locales/zh-cn/core-contract-extensions.js.map +1 -0
  175. package/dist/core/i18n/locales/zh-cn/core-contract-final.d.ts +9 -0
  176. package/dist/core/i18n/locales/zh-cn/core-contract-final.d.ts.map +1 -0
  177. package/dist/core/i18n/locales/zh-cn/core-contract-final.js +55 -0
  178. package/dist/core/i18n/locales/zh-cn/core-contract-final.js.map +1 -0
  179. package/dist/core/i18n/locales/zh-cn/core-contract-plugins.d.ts +11 -0
  180. package/dist/core/i18n/locales/zh-cn/core-contract-plugins.d.ts.map +1 -0
  181. package/dist/core/i18n/locales/zh-cn/core-contract-plugins.js +455 -0
  182. package/dist/core/i18n/locales/zh-cn/core-contract-plugins.js.map +1 -0
  183. package/dist/core/i18n/locales/zh-cn/core-errors.d.ts +9 -0
  184. package/dist/core/i18n/locales/zh-cn/core-errors.d.ts.map +1 -0
  185. package/dist/core/i18n/locales/zh-cn/core-errors.js +191 -0
  186. package/dist/core/i18n/locales/zh-cn/core-errors.js.map +1 -0
  187. package/dist/core/i18n/locales/zh-cn/example.d.ts +7 -0
  188. package/dist/core/i18n/locales/zh-cn/example.d.ts.map +1 -0
  189. package/dist/core/i18n/locales/zh-cn/example.js +10 -0
  190. package/dist/core/i18n/locales/zh-cn/example.js.map +1 -0
  191. package/dist/core/i18n/locales/zh-cn/index.d.ts +2 -0
  192. package/dist/core/i18n/locales/zh-cn/index.d.ts.map +1 -0
  193. package/dist/core/i18n/locales/zh-cn/index.js +41 -0
  194. package/dist/core/i18n/locales/zh-cn/index.js.map +1 -0
  195. package/dist/core/i18n/locales/zh-cn/interactive-mode.d.ts +10 -0
  196. package/dist/core/i18n/locales/zh-cn/interactive-mode.d.ts.map +1 -0
  197. package/dist/core/i18n/locales/zh-cn/interactive-mode.js +265 -0
  198. package/dist/core/i18n/locales/zh-cn/interactive-mode.js.map +1 -0
  199. package/dist/core/i18n/locales/zh-cn/keybindings.d.ts +11 -0
  200. package/dist/core/i18n/locales/zh-cn/keybindings.d.ts.map +1 -0
  201. package/dist/core/i18n/locales/zh-cn/keybindings.js +67 -0
  202. package/dist/core/i18n/locales/zh-cn/keybindings.js.map +1 -0
  203. package/dist/core/i18n/locales/zh-cn/slash-commands.d.ts +7 -0
  204. package/dist/core/i18n/locales/zh-cn/slash-commands.d.ts.map +1 -0
  205. package/dist/core/i18n/locales/zh-cn/slash-commands.js +39 -0
  206. package/dist/core/i18n/locales/zh-cn/slash-commands.js.map +1 -0
  207. package/dist/core/i18n/locales/zh-cn/tui-builtin.d.ts +10 -0
  208. package/dist/core/i18n/locales/zh-cn/tui-builtin.d.ts.map +1 -0
  209. package/dist/core/i18n/locales/zh-cn/tui-builtin.js +15 -0
  210. package/dist/core/i18n/locales/zh-cn/tui-builtin.js.map +1 -0
  211. package/dist/core/i18n/locales/zh-cn/tui-components-misc.d.ts +13 -0
  212. package/dist/core/i18n/locales/zh-cn/tui-components-misc.d.ts.map +1 -0
  213. package/dist/core/i18n/locales/zh-cn/tui-components-misc.js +102 -0
  214. package/dist/core/i18n/locales/zh-cn/tui-components-misc.js.map +1 -0
  215. package/dist/core/i18n/locales/zh-cn/tui-components-selectors.d.ts +12 -0
  216. package/dist/core/i18n/locales/zh-cn/tui-components-selectors.d.ts.map +1 -0
  217. package/dist/core/i18n/locales/zh-cn/tui-components-selectors.js +288 -0
  218. package/dist/core/i18n/locales/zh-cn/tui-components-selectors.js.map +1 -0
  219. package/dist/core/i18n/locales/zh-cn/tui-interactive-misc.d.ts +9 -0
  220. package/dist/core/i18n/locales/zh-cn/tui-interactive-misc.d.ts.map +1 -0
  221. package/dist/core/i18n/locales/zh-cn/tui-interactive-misc.js +79 -0
  222. package/dist/core/i18n/locales/zh-cn/tui-interactive-misc.js.map +1 -0
  223. package/dist/core/i18n/locales/zh-cn/tui-self-owned.d.ts +8 -0
  224. package/dist/core/i18n/locales/zh-cn/tui-self-owned.d.ts.map +1 -0
  225. package/dist/core/i18n/locales/zh-cn/tui-self-owned.js +72 -0
  226. package/dist/core/i18n/locales/zh-cn/tui-self-owned.js.map +1 -0
  227. package/dist/core/keybindings.d.ts +15 -0
  228. package/dist/core/keybindings.d.ts.map +1 -1
  229. package/dist/core/keybindings.js +18 -0
  230. package/dist/core/keybindings.js.map +1 -1
  231. package/dist/core/logger.d.ts.map +1 -1
  232. package/dist/core/logger.js +5 -1
  233. package/dist/core/logger.js.map +1 -1
  234. package/dist/core/model-registry.d.ts.map +1 -1
  235. package/dist/core/model-registry.js +2 -1
  236. package/dist/core/model-registry.js.map +1 -1
  237. package/dist/core/model-runtime.d.ts.map +1 -1
  238. package/dist/core/model-runtime.js +8 -4
  239. package/dist/core/model-runtime.js.map +1 -1
  240. package/dist/core/package-install-host.d.ts.map +1 -1
  241. package/dist/core/package-install-host.js +4 -3
  242. package/dist/core/package-install-host.js.map +1 -1
  243. package/dist/core/package-manager.d.ts.map +1 -1
  244. package/dist/core/package-manager.js +15 -10
  245. package/dist/core/package-manager.js.map +1 -1
  246. package/dist/core/package-resource-collection.d.ts.map +1 -1
  247. package/dist/core/package-resource-collection.js +2 -1
  248. package/dist/core/package-resource-collection.js.map +1 -1
  249. package/dist/core/package-source.d.ts.map +1 -1
  250. package/dist/core/package-source.js +3 -2
  251. package/dist/core/package-source.js.map +1 -1
  252. package/dist/core/provider-composer.d.ts.map +1 -1
  253. package/dist/core/provider-composer.js +22 -13
  254. package/dist/core/provider-composer.js.map +1 -1
  255. package/dist/core/remote-catalog-provider.d.ts.map +1 -1
  256. package/dist/core/remote-catalog-provider.js +6 -2
  257. package/dist/core/remote-catalog-provider.js.map +1 -1
  258. package/dist/core/resolve-config-value.d.ts.map +1 -1
  259. package/dist/core/resolve-config-value.js +15 -5
  260. package/dist/core/resolve-config-value.js.map +1 -1
  261. package/dist/core/sdk.d.ts +19 -5
  262. package/dist/core/sdk.d.ts.map +1 -1
  263. package/dist/core/sdk.js +74 -54
  264. package/dist/core/sdk.js.map +1 -1
  265. package/dist/core/session-cwd.d.ts.map +1 -1
  266. package/dist/core/session-cwd.js +5 -2
  267. package/dist/core/session-cwd.js.map +1 -1
  268. package/dist/core/session-export.d.ts.map +1 -1
  269. package/dist/core/session-export.js +2 -1
  270. package/dist/core/session-export.js.map +1 -1
  271. package/dist/core/session-manager.d.ts.map +1 -1
  272. package/dist/core/session-manager.js +39 -29
  273. package/dist/core/session-manager.js.map +1 -1
  274. package/dist/core/session-storage.d.ts.map +1 -1
  275. package/dist/core/session-storage.js +3 -3
  276. package/dist/core/session-storage.js.map +1 -1
  277. package/dist/core/settings-manager.d.ts +11 -0
  278. package/dist/core/settings-manager.d.ts.map +1 -1
  279. package/dist/core/settings-manager.js +27 -5
  280. package/dist/core/settings-manager.js.map +1 -1
  281. package/dist/core/slash-commands.d.ts.map +1 -1
  282. package/dist/core/slash-commands.js +53 -32
  283. package/dist/core/slash-commands.js.map +1 -1
  284. package/dist/core/system-prompt.d.ts.map +1 -1
  285. package/dist/core/system-prompt.js +25 -2
  286. package/dist/core/system-prompt.js.map +1 -1
  287. package/dist/core/tools/bash.d.ts.map +1 -1
  288. package/dist/core/tools/bash.js +11 -7
  289. package/dist/core/tools/bash.js.map +1 -1
  290. package/dist/core/tools/edit-diff.d.ts.map +1 -1
  291. package/dist/core/tools/edit-diff.js +9 -4
  292. package/dist/core/tools/edit-diff.js.map +1 -1
  293. package/dist/core/tools/edit.d.ts.map +1 -1
  294. package/dist/core/tools/edit.js +4 -3
  295. package/dist/core/tools/edit.js.map +1 -1
  296. package/dist/core/tools/index.d.ts.map +1 -1
  297. package/dist/core/tools/index.js +3 -2
  298. package/dist/core/tools/index.js.map +1 -1
  299. package/dist/core/tools/output-accumulator.d.ts.map +1 -1
  300. package/dist/core/tools/output-accumulator.js +2 -1
  301. package/dist/core/tools/output-accumulator.js.map +1 -1
  302. package/dist/core/tools/read.d.ts.map +1 -1
  303. package/dist/core/tools/read.js +6 -2
  304. package/dist/core/tools/read.js.map +1 -1
  305. package/dist/core/tools/write.d.ts.map +1 -1
  306. package/dist/core/tools/write.js +2 -1
  307. package/dist/core/tools/write.js.map +1 -1
  308. package/dist/durable/durable-service.d.ts.map +1 -1
  309. package/dist/durable/durable-service.js +25 -18
  310. package/dist/durable/durable-service.js.map +1 -1
  311. package/dist/host/checkpoint-commit.d.ts.map +1 -1
  312. package/dist/host/checkpoint-commit.js +2 -1
  313. package/dist/host/checkpoint-commit.js.map +1 -1
  314. package/dist/host/manual-compaction.d.ts.map +1 -1
  315. package/dist/host/manual-compaction.js +2 -1
  316. package/dist/host/manual-compaction.js.map +1 -1
  317. package/dist/host/output-projection.d.ts +0 -13
  318. package/dist/host/output-projection.d.ts.map +1 -1
  319. package/dist/host/output-projection.js +16 -2
  320. package/dist/host/output-projection.js.map +1 -1
  321. package/dist/host/summary-retry.d.ts.map +1 -1
  322. package/dist/host/summary-retry.js +3 -2
  323. package/dist/host/summary-retry.js.map +1 -1
  324. package/dist/main.d.ts.map +1 -1
  325. package/dist/main.js +94 -58
  326. package/dist/main.js.map +1 -1
  327. package/dist/modes/interactive/components/agents-view.d.ts.map +1 -1
  328. package/dist/modes/interactive/components/agents-view.js +18 -15
  329. package/dist/modes/interactive/components/agents-view.js.map +1 -1
  330. package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
  331. package/dist/modes/interactive/components/assistant-message.js +6 -5
  332. package/dist/modes/interactive/components/assistant-message.js.map +1 -1
  333. package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
  334. package/dist/modes/interactive/components/bash-execution.js +12 -7
  335. package/dist/modes/interactive/components/bash-execution.js.map +1 -1
  336. package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -1
  337. package/dist/modes/interactive/components/bordered-loader.js +2 -1
  338. package/dist/modes/interactive/components/bordered-loader.js.map +1 -1
  339. package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -1
  340. package/dist/modes/interactive/components/branch-summary-message.js +6 -5
  341. package/dist/modes/interactive/components/branch-summary-message.js.map +1 -1
  342. package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -1
  343. package/dist/modes/interactive/components/compaction-summary-message.js +9 -5
  344. package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -1
  345. package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
  346. package/dist/modes/interactive/components/config-selector.js +18 -15
  347. package/dist/modes/interactive/components/config-selector.js.map +1 -1
  348. package/dist/modes/interactive/components/custom-entry.d.ts.map +1 -1
  349. package/dist/modes/interactive/components/custom-entry.js +2 -1
  350. package/dist/modes/interactive/components/custom-entry.js.map +1 -1
  351. package/dist/modes/interactive/components/dialog-editor.d.ts.map +1 -1
  352. package/dist/modes/interactive/components/dialog-editor.js +5 -4
  353. package/dist/modes/interactive/components/dialog-editor.js.map +1 -1
  354. package/dist/modes/interactive/components/dialog-input.d.ts.map +1 -1
  355. package/dist/modes/interactive/components/dialog-input.js +2 -1
  356. package/dist/modes/interactive/components/dialog-input.js.map +1 -1
  357. package/dist/modes/interactive/components/dialog-selector.d.ts.map +1 -1
  358. package/dist/modes/interactive/components/dialog-selector.js +4 -3
  359. package/dist/modes/interactive/components/dialog-selector.js.map +1 -1
  360. package/dist/modes/interactive/components/first-time-setup.d.ts.map +1 -1
  361. package/dist/modes/interactive/components/first-time-setup.js +11 -10
  362. package/dist/modes/interactive/components/first-time-setup.js.map +1 -1
  363. package/dist/modes/interactive/components/footer.d.ts.map +1 -1
  364. package/dist/modes/interactive/components/footer.js +7 -4
  365. package/dist/modes/interactive/components/footer.js.map +1 -1
  366. package/dist/modes/interactive/components/index.d.ts +1 -0
  367. package/dist/modes/interactive/components/index.d.ts.map +1 -1
  368. package/dist/modes/interactive/components/index.js +1 -0
  369. package/dist/modes/interactive/components/index.js.map +1 -1
  370. package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
  371. package/dist/modes/interactive/components/keybinding-hints.js +3 -2
  372. package/dist/modes/interactive/components/keybinding-hints.js.map +1 -1
  373. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
  374. package/dist/modes/interactive/components/login-dialog.js +12 -11
  375. package/dist/modes/interactive/components/login-dialog.js.map +1 -1
  376. package/dist/modes/interactive/components/mermaid.d.ts.map +1 -1
  377. package/dist/modes/interactive/components/mermaid.js +6 -2
  378. package/dist/modes/interactive/components/mermaid.js.map +1 -1
  379. package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
  380. package/dist/modes/interactive/components/model-selector.js +28 -16
  381. package/dist/modes/interactive/components/model-selector.js.map +1 -1
  382. package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
  383. package/dist/modes/interactive/components/oauth-selector.js +10 -9
  384. package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
  385. package/dist/modes/interactive/components/plugin-manager-entry.d.ts.map +1 -1
  386. package/dist/modes/interactive/components/plugin-manager-entry.js +22 -13
  387. package/dist/modes/interactive/components/plugin-manager-entry.js.map +1 -1
  388. package/dist/modes/interactive/components/plugin-selection-entry.d.ts.map +1 -1
  389. package/dist/modes/interactive/components/plugin-selection-entry.js +27 -12
  390. package/dist/modes/interactive/components/plugin-selection-entry.js.map +1 -1
  391. package/dist/modes/interactive/components/queue-manager-selector.d.ts +60 -0
  392. package/dist/modes/interactive/components/queue-manager-selector.d.ts.map +1 -0
  393. package/dist/modes/interactive/components/queue-manager-selector.js +166 -0
  394. package/dist/modes/interactive/components/queue-manager-selector.js.map +1 -0
  395. package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
  396. package/dist/modes/interactive/components/scoped-models-selector.js +16 -14
  397. package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
  398. package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
  399. package/dist/modes/interactive/components/session-selector.js +43 -31
  400. package/dist/modes/interactive/components/session-selector.js.map +1 -1
  401. package/dist/modes/interactive/components/settings-selector.d.ts +2 -0
  402. package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
  403. package/dist/modes/interactive/components/settings-selector.js +113 -96
  404. package/dist/modes/interactive/components/settings-selector.js.map +1 -1
  405. package/dist/modes/interactive/components/settings-submenu.d.ts.map +1 -1
  406. package/dist/modes/interactive/components/settings-submenu.js +5 -4
  407. package/dist/modes/interactive/components/settings-submenu.js.map +1 -1
  408. package/dist/modes/interactive/components/show-images-selector.d.ts.map +1 -1
  409. package/dist/modes/interactive/components/show-images-selector.js +3 -2
  410. package/dist/modes/interactive/components/show-images-selector.js.map +1 -1
  411. package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -1
  412. package/dist/modes/interactive/components/skill-invocation-message.js +4 -3
  413. package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -1
  414. package/dist/modes/interactive/components/status-indicator.d.ts.map +1 -1
  415. package/dist/modes/interactive/components/status-indicator.js +14 -5
  416. package/dist/modes/interactive/components/status-indicator.js.map +1 -1
  417. package/dist/modes/interactive/components/theme-selector.d.ts.map +1 -1
  418. package/dist/modes/interactive/components/theme-selector.js +2 -1
  419. package/dist/modes/interactive/components/theme-selector.js.map +1 -1
  420. package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
  421. package/dist/modes/interactive/components/thinking-selector.js +11 -4
  422. package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
  423. package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
  424. package/dist/modes/interactive/components/tool-execution.js +8 -3
  425. package/dist/modes/interactive/components/tool-execution.js.map +1 -1
  426. package/dist/modes/interactive/components/tree-list.d.ts.map +1 -1
  427. package/dist/modes/interactive/components/tree-list.js +7 -6
  428. package/dist/modes/interactive/components/tree-list.js.map +1 -1
  429. package/dist/modes/interactive/components/tree-render.d.ts.map +1 -1
  430. package/dist/modes/interactive/components/tree-render.js +28 -23
  431. package/dist/modes/interactive/components/tree-render.js.map +1 -1
  432. package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
  433. package/dist/modes/interactive/components/tree-selector.js +9 -7
  434. package/dist/modes/interactive/components/tree-selector.js.map +1 -1
  435. package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -1
  436. package/dist/modes/interactive/components/user-message-selector.js +5 -4
  437. package/dist/modes/interactive/components/user-message-selector.js.map +1 -1
  438. package/dist/modes/interactive/components/workflow-view.d.ts.map +1 -1
  439. package/dist/modes/interactive/components/workflow-view.js +36 -21
  440. package/dist/modes/interactive/components/workflow-view.js.map +1 -1
  441. package/dist/modes/interactive/external-editor.d.ts.map +1 -1
  442. package/dist/modes/interactive/external-editor.js +2 -1
  443. package/dist/modes/interactive/external-editor.js.map +1 -1
  444. package/dist/modes/interactive/interactive-auth.d.ts.map +1 -1
  445. package/dist/modes/interactive/interactive-auth.js +71 -40
  446. package/dist/modes/interactive/interactive-auth.js.map +1 -1
  447. package/dist/modes/interactive/interactive-commands.d.ts +1 -0
  448. package/dist/modes/interactive/interactive-commands.d.ts.map +1 -1
  449. package/dist/modes/interactive/interactive-commands.js +3 -0
  450. package/dist/modes/interactive/interactive-commands.js.map +1 -1
  451. package/dist/modes/interactive/interactive-dialog-ui.d.ts.map +1 -1
  452. package/dist/modes/interactive/interactive-dialog-ui.js +5 -5
  453. package/dist/modes/interactive/interactive-dialog-ui.js.map +1 -1
  454. package/dist/modes/interactive/interactive-format.d.ts.map +1 -1
  455. package/dist/modes/interactive/interactive-format.js +34 -18
  456. package/dist/modes/interactive/interactive-format.js.map +1 -1
  457. package/dist/modes/interactive/interactive-helpers.d.ts.map +1 -1
  458. package/dist/modes/interactive/interactive-helpers.js +7 -2
  459. package/dist/modes/interactive/interactive-helpers.js.map +1 -1
  460. package/dist/modes/interactive/interactive-mode.d.ts +4 -1
  461. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  462. package/dist/modes/interactive/interactive-mode.js +327 -243
  463. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  464. package/dist/modes/interactive/interactive-selectors.d.ts +9 -0
  465. package/dist/modes/interactive/interactive-selectors.d.ts.map +1 -1
  466. package/dist/modes/interactive/interactive-selectors.js +79 -25
  467. package/dist/modes/interactive/interactive-selectors.js.map +1 -1
  468. package/dist/modes/interactive/theme/theme-controller.d.ts.map +1 -1
  469. package/dist/modes/interactive/theme/theme-controller.js +5 -1
  470. package/dist/modes/interactive/theme/theme-controller.js.map +1 -1
  471. package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
  472. package/dist/modes/interactive/theme/theme.js +26 -23
  473. package/dist/modes/interactive/theme/theme.js.map +1 -1
  474. package/dist/modes/json-event.d.ts.map +1 -1
  475. package/dist/modes/json-event.js +3 -2
  476. package/dist/modes/json-event.js.map +1 -1
  477. package/dist/modes/print-mode.d.ts.map +1 -1
  478. package/dist/modes/print-mode.js +3 -2
  479. package/dist/modes/print-mode.js.map +1 -1
  480. package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
  481. package/dist/modes/rpc/rpc-client.js +3 -2
  482. package/dist/modes/rpc/rpc-client.js.map +1 -1
  483. package/dist/package-manager-cli.d.ts.map +1 -1
  484. package/dist/package-manager-cli.js +28 -13
  485. package/dist/package-manager-cli.js.map +1 -1
  486. package/dist/plugins/ecosystem/catalog.d.ts.map +1 -1
  487. package/dist/plugins/ecosystem/catalog.js +3 -2
  488. package/dist/plugins/ecosystem/catalog.js.map +1 -1
  489. package/dist/plugins/ecosystem/cli.d.ts.map +1 -1
  490. package/dist/plugins/ecosystem/cli.js +2 -1
  491. package/dist/plugins/ecosystem/cli.js.map +1 -1
  492. package/dist/plugins/ecosystem/default-plugin-market.d.ts.map +1 -1
  493. package/dist/plugins/ecosystem/default-plugin-market.js +3 -2
  494. package/dist/plugins/ecosystem/default-plugin-market.js.map +1 -1
  495. package/dist/plugins/ecosystem/distribution.d.ts.map +1 -1
  496. package/dist/plugins/ecosystem/distribution.js +2 -1
  497. package/dist/plugins/ecosystem/distribution.js.map +1 -1
  498. package/dist/plugins/ecosystem/installer.d.ts.map +1 -1
  499. package/dist/plugins/ecosystem/installer.js +3 -2
  500. package/dist/plugins/ecosystem/installer.js.map +1 -1
  501. package/dist/plugins/ecosystem/node-disk-registry-source.d.ts.map +1 -1
  502. package/dist/plugins/ecosystem/node-disk-registry-source.js +20 -17
  503. package/dist/plugins/ecosystem/node-disk-registry-source.js.map +1 -1
  504. package/dist/plugins/ecosystem/node-distribution-host.d.ts.map +1 -1
  505. package/dist/plugins/ecosystem/node-distribution-host.js +35 -34
  506. package/dist/plugins/ecosystem/node-distribution-host.js.map +1 -1
  507. package/dist/plugins/ecosystem/node-npm-registry-source.d.ts.map +1 -1
  508. package/dist/plugins/ecosystem/node-npm-registry-source.js +35 -34
  509. package/dist/plugins/ecosystem/node-npm-registry-source.js.map +1 -1
  510. package/dist/plugins/ecosystem/node-package-install-host.d.ts.map +1 -1
  511. package/dist/plugins/ecosystem/node-package-install-host.js +9 -8
  512. package/dist/plugins/ecosystem/node-package-install-host.js.map +1 -1
  513. package/dist/plugins/ecosystem/node-package-install-persistence.d.ts.map +1 -1
  514. package/dist/plugins/ecosystem/node-package-install-persistence.js +4 -3
  515. package/dist/plugins/ecosystem/node-package-install-persistence.js.map +1 -1
  516. package/dist/plugins/ecosystem/node-plugin-bootstrap.d.ts.map +1 -1
  517. package/dist/plugins/ecosystem/node-plugin-bootstrap.js +21 -5
  518. package/dist/plugins/ecosystem/node-plugin-bootstrap.js.map +1 -1
  519. package/dist/plugins/ecosystem/node-plugin-trust-root.d.ts.map +1 -1
  520. package/dist/plugins/ecosystem/node-plugin-trust-root.js +10 -9
  521. package/dist/plugins/ecosystem/node-plugin-trust-root.js.map +1 -1
  522. package/dist/plugins/ecosystem/node-registry-source.d.ts.map +1 -1
  523. package/dist/plugins/ecosystem/node-registry-source.js +31 -30
  524. package/dist/plugins/ecosystem/node-registry-source.js.map +1 -1
  525. package/dist/plugins/ecosystem/node-release-package-source.d.ts.map +1 -1
  526. package/dist/plugins/ecosystem/node-release-package-source.js +30 -29
  527. package/dist/plugins/ecosystem/node-release-package-source.js.map +1 -1
  528. package/dist/plugins/ecosystem/node-tar-writer.d.ts.map +1 -1
  529. package/dist/plugins/ecosystem/node-tar-writer.js +11 -10
  530. package/dist/plugins/ecosystem/node-tar-writer.js.map +1 -1
  531. package/dist/plugins/ecosystem/node-url-package-source.d.ts.map +1 -1
  532. package/dist/plugins/ecosystem/node-url-package-source.js +21 -20
  533. package/dist/plugins/ecosystem/node-url-package-source.js.map +1 -1
  534. package/dist/plugins/ecosystem/plugin-acquisition.d.ts.map +1 -1
  535. package/dist/plugins/ecosystem/plugin-acquisition.js +3 -2
  536. package/dist/plugins/ecosystem/plugin-acquisition.js.map +1 -1
  537. package/dist/plugins/ecosystem/registry-cli-adapter.d.ts.map +1 -1
  538. package/dist/plugins/ecosystem/registry-cli-adapter.js +2 -1
  539. package/dist/plugins/ecosystem/registry-cli-adapter.js.map +1 -1
  540. package/dist/plugins/ecosystem/registry.d.ts.map +1 -1
  541. package/dist/plugins/ecosystem/registry.js +35 -32
  542. package/dist/plugins/ecosystem/registry.js.map +1 -1
  543. package/dist/plugins/ecosystem/resolver.d.ts.map +1 -1
  544. package/dist/plugins/ecosystem/resolver.js +3 -2
  545. package/dist/plugins/ecosystem/resolver.js.map +1 -1
  546. package/dist/plugins/ecosystem/selection-store.d.ts.map +1 -1
  547. package/dist/plugins/ecosystem/selection-store.js +11 -10
  548. package/dist/plugins/ecosystem/selection-store.js.map +1 -1
  549. package/dist/plugins/ecosystem/selection.d.ts.map +1 -1
  550. package/dist/plugins/ecosystem/selection.js +8 -7
  551. package/dist/plugins/ecosystem/selection.js.map +1 -1
  552. package/dist/plugins/ecosystem/state.d.ts.map +1 -1
  553. package/dist/plugins/ecosystem/state.js +24 -23
  554. package/dist/plugins/ecosystem/state.js.map +1 -1
  555. package/dist/plugins/ecosystem/updates.d.ts.map +1 -1
  556. package/dist/plugins/ecosystem/updates.js +5 -4
  557. package/dist/plugins/ecosystem/updates.js.map +1 -1
  558. package/dist/plugins/mcp-http.d.ts +0 -17
  559. package/dist/plugins/mcp-http.d.ts.map +1 -1
  560. package/dist/plugins/mcp-http.js +30 -7
  561. package/dist/plugins/mcp-http.js.map +1 -1
  562. package/dist/plugins/plugin-supervisor.d.ts.map +1 -1
  563. package/dist/plugins/plugin-supervisor.js +19 -1
  564. package/dist/plugins/plugin-supervisor.js.map +1 -1
  565. package/dist/profile/first-roles.d.ts.map +1 -1
  566. package/dist/profile/first-roles.js +10 -1
  567. package/dist/profile/first-roles.js.map +1 -1
  568. package/dist/profile/goal-plugin.d.ts.map +1 -1
  569. package/dist/profile/goal-plugin.js +24 -5
  570. package/dist/profile/goal-plugin.js.map +1 -1
  571. package/dist/profile/identity.d.ts.map +1 -1
  572. package/dist/profile/identity.js +7 -6
  573. package/dist/profile/identity.js.map +1 -1
  574. package/dist/profile/lock.d.ts.map +1 -1
  575. package/dist/profile/lock.js +15 -1
  576. package/dist/profile/lock.js.map +1 -1
  577. package/dist/profile/plan-plugin.d.ts.map +1 -1
  578. package/dist/profile/plan-plugin.js +26 -13
  579. package/dist/profile/plan-plugin.js.map +1 -1
  580. package/dist/profile/plugin-profiles.d.ts.map +1 -1
  581. package/dist/profile/plugin-profiles.js +2 -1
  582. package/dist/profile/plugin-profiles.js.map +1 -1
  583. package/dist/profile/policy-manifest.d.ts.map +1 -1
  584. package/dist/profile/policy-manifest.js +5 -4
  585. package/dist/profile/policy-manifest.js.map +1 -1
  586. package/dist/profile/profile-registry.d.ts +0 -12
  587. package/dist/profile/profile-registry.d.ts.map +1 -1
  588. package/dist/profile/profile-registry.js +14 -1
  589. package/dist/profile/profile-registry.js.map +1 -1
  590. package/dist/profile/role-catalog.d.ts +0 -1
  591. package/dist/profile/role-catalog.d.ts.map +1 -1
  592. package/dist/profile/role-catalog.js +17 -15
  593. package/dist/profile/role-catalog.js.map +1 -1
  594. package/dist/profile/role-orchestrator.d.ts.map +1 -1
  595. package/dist/profile/role-orchestrator.js +8 -7
  596. package/dist/profile/role-orchestrator.js.map +1 -1
  597. package/dist/profile/role-runner.d.ts.map +1 -1
  598. package/dist/profile/role-runner.js +3 -2
  599. package/dist/profile/role-runner.js.map +1 -1
  600. package/dist/profile/root-facade.d.ts.map +1 -1
  601. package/dist/profile/root-facade.js +2 -1
  602. package/dist/profile/root-facade.js.map +1 -1
  603. package/dist/profile/skill-discovery-wiring.d.ts.map +1 -1
  604. package/dist/profile/skill-discovery-wiring.js +7 -2
  605. package/dist/profile/skill-discovery-wiring.js.map +1 -1
  606. package/dist/profile/state-store.d.ts.map +1 -1
  607. package/dist/profile/state-store.js +13 -9
  608. package/dist/profile/state-store.js.map +1 -1
  609. package/dist/profile/todo-plugin.d.ts.map +1 -1
  610. package/dist/profile/todo-plugin.js +9 -4
  611. package/dist/profile/todo-plugin.js.map +1 -1
  612. package/dist/profiles/builtin-suites.d.ts +13 -6
  613. package/dist/profiles/builtin-suites.d.ts.map +1 -1
  614. package/dist/profiles/builtin-suites.js +15 -6
  615. package/dist/profiles/builtin-suites.js.map +1 -1
  616. package/dist/profiles/suite-loader.d.ts +25 -1
  617. package/dist/profiles/suite-loader.d.ts.map +1 -1
  618. package/dist/profiles/suite-loader.js +34 -9
  619. package/dist/profiles/suite-loader.js.map +1 -1
  620. package/dist/remote/server-entry.d.ts.map +1 -1
  621. package/dist/remote/server-entry.js +3 -2
  622. package/dist/remote/server-entry.js.map +1 -1
  623. package/dist/remote/session-source.d.ts.map +1 -1
  624. package/dist/remote/session-source.js +8 -4
  625. package/dist/remote/session-source.js.map +1 -1
  626. package/dist/share/session-share.d.ts.map +1 -1
  627. package/dist/share/session-share.js +14 -2
  628. package/dist/share/session-share.js.map +1 -1
  629. package/dist/testing/plugin-testkit.d.ts.map +1 -1
  630. package/dist/testing/plugin-testkit.js +4 -3
  631. package/dist/testing/plugin-testkit.js.map +1 -1
  632. package/dist/testing/runtime-delivery-queue.d.ts.map +1 -1
  633. package/dist/testing/runtime-delivery-queue.js +2 -1
  634. package/dist/testing/runtime-delivery-queue.js.map +1 -1
  635. package/dist/testing/session-plugin-testkit.d.ts.map +1 -1
  636. package/dist/testing/session-plugin-testkit.js +10 -7
  637. package/dist/testing/session-plugin-testkit.js.map +1 -1
  638. package/dist/utils/ansi.d.ts.map +1 -1
  639. package/dist/utils/ansi.js +2 -1
  640. package/dist/utils/ansi.js.map +1 -1
  641. package/dist/utils/clipboard.d.ts.map +1 -1
  642. package/dist/utils/clipboard.js +7 -6
  643. package/dist/utils/clipboard.js.map +1 -1
  644. package/dist/utils/image-resize-worker.d.ts.map +1 -1
  645. package/dist/utils/image-resize-worker.js +3 -2
  646. package/dist/utils/image-resize-worker.js.map +1 -1
  647. package/dist/utils/shell.d.ts.map +1 -1
  648. package/dist/utils/shell.js +9 -8
  649. package/dist/utils/shell.js.map +1 -1
  650. package/dist/utils/tools-manager.d.ts.map +1 -1
  651. package/dist/utils/tools-manager.js +23 -13
  652. package/dist/utils/tools-manager.js.map +1 -1
  653. package/dist/utils/version-check.d.ts.map +1 -1
  654. package/dist/utils/version-check.js +5 -1
  655. package/dist/utils/version-check.js.map +1 -1
  656. package/docs/keybindings.md +3 -0
  657. package/docs/quickstart.md +1 -1
  658. package/docs/settings.md +1 -0
  659. package/docs/terminal-setup.md +2 -3
  660. package/docs/usage.md +6 -5
  661. package/examples/extensions/with-deps/package-lock.json +2 -2
  662. package/examples/extensions/with-deps/package.json +1 -1
  663. package/examples/extensions/with-deps/plugin.json +1 -1
  664. package/package.json +1 -1
  665. package/dist/bundle/chunks/chunk-EALJ5DDX.js +0 -1452
@@ -54,8 +54,13 @@ export const SUITE_SCHEMA_VERSION = 1;
54
54
  * 5 receive the upgrade-proposal diagnostic and adopt via `--suite-reset`.
55
55
  */
56
56
  export const FACTORY_CONTENTS_VERSION = 6;
57
- /** Factory default suite used when no suite is configured anywhere (设计 §9). */
58
- export const DEFAULT_SUITE_ID = "assistant";
57
+ /**
58
+ * Factory default suite used when no suite is configured anywhere (设计 §9).
59
+ * 2026-10-02 user ruling: the product is a coding agent, so the factory
60
+ * default flipped from "assistant" to "coding"; assistant stays as the
61
+ * explicit-switch fallback suite.
62
+ */
63
+ export const DEFAULT_SUITE_ID = "coding";
59
64
  /** Suite ids become directory names: lowercase letters, digits, hyphens (设计 §9). */
60
65
  export const SUITE_ID_MAX_LENGTH = 64;
61
66
  /** The single unrestricted tool surface shared by both builtin suites (设计 §5/§6). */
@@ -97,7 +102,9 @@ export const BUILTIN_SUITE_CAPABILITIES = [
97
102
  * The strings are verbatim from the design spec: the assistant persona is the
98
103
  * companion style, the coding persona is the rigor-first style. Both are
99
104
  * session-nature declarations, so they ride every system prompt branch
100
- * (default and customPrompt).
105
+ * (default and customPrompt). The custom orientation is not in this table: its
106
+ * persona text comes from the suite workspace persona.md (设计 §6.3, resolved
107
+ * by suite-loader).
101
108
  */
102
109
  export const ORIENTATION_PROMPTS = {
103
110
  assistant: `You are the user's thoughtful companion — warm, patient, and helpful.
@@ -156,7 +163,7 @@ const codingSuite = {
156
163
  clonedFrom: null,
157
164
  factoryRevision: FACTORY_CONTENTS_VERSION,
158
165
  };
159
- /** The factory builtin pair: assistant (fallback default) and coding (尖刀). */
166
+ /** The factory builtin pair: coding (factory default 尖刀) and assistant (fallback). */
160
167
  export const BUILTIN_SUITES = [assistantSuite, codingSuite];
161
168
  export function getBuiltinSuite(id) {
162
169
  return BUILTIN_SUITES.find((suite) => suite.id === id);
@@ -294,9 +301,11 @@ export function validateSuiteJson(value, options = {}) {
294
301
  errors.push(`memory must be "assistant" or "code", found ${JSON.stringify(memoryValue)}`);
295
302
  }
296
303
  const orientationValue = record.orientation;
297
- const orientation = orientationValue === "assistant" || orientationValue === "coding" ? orientationValue : undefined;
304
+ const orientation = orientationValue === "assistant" || orientationValue === "coding" || orientationValue === "custom"
305
+ ? orientationValue
306
+ : undefined;
298
307
  if (orientationValue !== undefined && orientation === undefined) {
299
- errors.push(`orientation must be "assistant" or "coding", found ${JSON.stringify(orientationValue)}`);
308
+ errors.push(`orientation must be "assistant", "coding", or "custom", found ${JSON.stringify(orientationValue)}`);
300
309
  }
301
310
  const model = readOptionalString(record, "model", errors);
302
311
  const thinking = readOptionalString(record, "thinking", errors);
@@ -1 +1 @@
1
- {"version":3,"file":"builtin-suites.js","sourceRoot":"","sources":["../../src/profiles/builtin-suites.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC;AAEtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,CAAC;AAE1C,oFAA+E;AAC/E,MAAM,CAAC,MAAM,gBAAgB,GAAG,WAAW,CAAC;AAE5C,yFAAoF;AACpF,MAAM,CAAC,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAEtC,2FAAqF;AACrF,MAAM,CAAC,MAAM,mBAAmB,GAAsB;IACrD,MAAM;IACN,OAAO;IACP,MAAM;IACN,MAAM;IACN,IAAI;IACJ,MAAM;IACN,MAAM;IACN,YAAY;CACZ,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAsB;IAC5D,cAAc;IACd,cAAc;IACd,kBAAkB;IAClB,kBAAkB;IAClB,gBAAgB;IAChB,uBAAuB;IACvB,2BAA2B;CAC3B,CAAC;AAKF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAqC;IACpE,SAAS,EAAE;;;;;;+HAMmH;IAC9H,MAAM,EAAE;;;;;;;;sGAQ6F;CACrG,CAAC;AA4CF,MAAM,kBAAkB,GAAsB,EAAE,MAAM,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC;AAE9F;;;;GAIG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAsB,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC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ACvD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACvD,MAAM,CAAC,IAAI,CAAC,yDAAyD,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QAC9F,OAAO,IAAI,CAAC;IACb,CAAC;IACD,MAAM,MAAM,GAAG,KAAgC,CAAC;IAChD,IACC,OAAO,MAAM,CAAC,EAAE,KAAK,QAAQ;QAC7B,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC;QAC7B,OAAO,MAAM,CAAC,MAAM,KAAK,QAAQ;QACjC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC;QACjC,OAAO,MAAM,CAAC,EAAE,KAAK,QAAQ;QAC7B,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,CAAC,EAC/B,CAAC;QACF,MAAM,CAAC,IAAI,CACV,0FAA0F,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CACjH,CAAC;QACF,OAAO,IAAI,CAAC;IACb,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC;AAAA,CAC/D","sourcesContent":["/**\n * Builtin suite (方案) declarations and suite.json (schemaVersion 1)\n * serialization, parsing, and validation — 方案系统设计.md v2 §5/§6/§9, M1a.\n *\n * Suites are pure data plus default policy: both builtin suites share the same\n * unrestricted tool surface and differ only in orientation and memory strategy\n * (the orientation persona text is injected into the system prompt, M2).\n * Nothing here touches the packages/agent kernel; association resolution is\n * declaration-only until M1b.\n */\n\nexport const SUITE_SCHEMA_VERSION = 1;\n\n/**\n * Factory contents revision (M4): the revision of the factory builtin\n * declarations, independent of SUITE_SCHEMA_VERSION. Bump it (and update both\n * builtin declarations' `factoryRevision`) whenever the factory contents\n * change; the registry upgrade proposal then offers `--suite-reset` for\n * workspaces still on an older revision. Suite schema evolution keeps using\n * SUITE_SCHEMA_VERSION.\n *\n * Revision 2 (统一修复轮集成收口, 2026-09-08): assistant and coding now share\n * the same active 8-tool surface in full-control — the sdk `suiteToolOverride`\n * DEFAULT_SUITE_ID exemption was removed (方案设计 §5 + user decision). Existing\n * workspaces provisioned at revision 1 receive the upgrade-proposal diagnostic\n * and adopt via `--suite-reset`.\n *\n * Revision 3 (2026-09-18): `builtin.session-share` joins both builtin suites\n * (开发计划 §216: session-share productized from the example plugin into a\n * first-party default-distributed capability) once the agent-dir config\n * channel for embedded capabilities landed\n * (`<agentDir>/capabilities/<short-id>.json`, see capabilities/builtin.ts).\n * Existing workspaces provisioned at revision 2 receive the upgrade-proposal\n * diagnostic and adopt via `--suite-reset`.\n *\n * Revision 4 (2026-09-18): `builtin.subagent-delegate` joins both builtin\n * suites — the first-party subagent delegation tool (`subagent_run`) now ships\n * by default in shared mode (zero extra processes; pooled runner processes stay\n * opt-in through the capability config channel). Existing workspaces\n * provisioned at revision 3 receive the upgrade-proposal diagnostic and adopt\n * via `--suite-reset`.\n *\n * Revision 5 (2026-09-20): subagent role profiles land on disk only\n * (`<agentDir>/roles/<id>.json` — the factory seeds explore/reviewer and never\n * overwrites user edits) and both builtin suites associate them by default via\n * the new `suite.associations.roles` field, with skill/MCP-isomorphic\n * visibility: unassociated roles stay invisible, associated-but-missing files\n * surface as dangling diagnostics. Existing workspaces provisioned at\n * revision 4 receive the upgrade-proposal diagnostic and adopt via\n * `--suite-reset`.\n *\n * Revision 6 (D-077, 2026-10-02): `builtin.workflow` joins both builtin suites\n * — the workflow orchestration plugin enters the factory bootstrap manifest\n * (ninth package) and the suite capability declaration at goal/plan/todo-set\n * parity, keeping its plugin form. Existing workspaces provisioned at revision\n * 5 receive the upgrade-proposal diagnostic and adopt via `--suite-reset`.\n */\nexport const FACTORY_CONTENTS_VERSION = 6;\n\n/** Factory default suite used when no suite is configured anywhere (设计 §9). */\nexport const DEFAULT_SUITE_ID = \"assistant\";\n\n/** Suite ids become directory names: lowercase letters, digits, hyphens (设计 §9). */\nexport const SUITE_ID_MAX_LENGTH = 64;\n\n/** The single unrestricted tool surface shared by both builtin suites (设计 §5/§6). */\nexport const BUILTIN_SUITE_TOOLS: readonly string[] = [\n\t\"read\",\n\t\"write\",\n\t\"edit\",\n\t\"bash\",\n\t\"ls\",\n\t\"find\",\n\t\"grep\",\n\t\"powershell\",\n];\n\n/**\n * Builtin capability plugins associated with both suites. Declaration-only\n * data in M1a; the actual plugin wiring is delivered in M3. `builtin.memory`\n * joins in the 统一修复轮 A 路 (方案系统设计 §6.1: both suites share the same\n * memory tool surface; the strategy difference lives in the suiteId domain\n * isolation and the assistant preference card). `builtin.session-share` joins\n * in the session-share productization slice (开发计划 §216); its\n * target/gateway/viewerUrl are configured through the agent-dir config\n * channel (`<agentDir>/capabilities/builtin.session-share.json`), and the\n * unconfigured default answers `/share` with the explicit configuration\n * prompt — never an implicit Radius/Gist fallback. `builtin.workflow` joins\n * at goal/plan/todo-set parity (D-077, 2026-10-02: factory default install\n * plus this suite declaration, plugin form unchanged).\n */\nexport const BUILTIN_SUITE_CAPABILITIES: readonly string[] = [\n\t\"builtin.goal\",\n\t\"builtin.plan\",\n\t\"builtin.todo-set\",\n\t\"builtin.workflow\",\n\t\"builtin.memory\",\n\t\"builtin.session-share\",\n\t\"builtin.subagent-delegate\",\n];\n\nexport type SuiteMemoryStrategy = \"assistant\" | \"code\";\nexport type SuiteOrientation = \"assistant\" | \"coding\";\n\n/**\n * Orientation persona texts injected into the system prompt (设计 §6.2, M2).\n * The strings are verbatim from the design spec: the assistant persona is the\n * companion style, the coding persona is the rigor-first style. Both are\n * session-nature declarations, so they ride every system prompt branch\n * (default and customPrompt).\n */\nexport const ORIENTATION_PROMPTS: Record<SuiteOrientation, string> = {\n\tassistant: `You are the user's thoughtful companion — warm, patient, and helpful.\n- Understand the intent behind the question, including the unspoken parts; when something that matters is ambiguous, ask one short clarifying question instead of assuming.\n- Pay attention to detail: notice what the user might have missed and gently point it out.\n- Be proactive and divergent: after answering, offer next steps, related ideas, or creative alternatives — without being pushy.\n- Adapt tone to the user; stay natural and flexible, never robotic or formulaic.\n- When you can help by doing, act through tools autonomously (minimal interruption).\n- Structure longer answers clearly: short paragraphs, lists where they help, and a concrete \"what you can do next\" at the end.`,\n\tcoding: `You are an autonomous software engineering agent with a rigor-first mindset.\n- Never guess. Ground every claim in code you have read, commands you have run, or documented evidence; cite file paths and line numbers. If the evidence is insufficient, investigate, and report what is unverified — or \"unknown\" — instead of a plausible invention.\n- First principles: trace problems to the earliest reasonable root cause and fix that; do not patch symptoms.\n- No over-engineering: add no abstraction, options, or defensive handling for imagined future needs; generalise only when a second concrete case demands it.\n- Tests first: pin expected behavior with a failing or updated test before or alongside the fix, then run the smallest sufficient relevant checks; the work is not done until they pass.\n- Reproducible: prefer deterministic tests and mocks over ad-hoc verification, and report the exact commands and results so others can re-run them.\n- Docs as code: repository documentation is part of the change — keep design docs, READMEs, and changelogs consistent with the behavior they describe.\n- Self-review before finishing: re-check your changes for correctness, edge cases, regressions, and missing tests; prefer a second review pass over shipping the first draft.\n- Cautious: weigh side effects, compatibility, and failure modes; when in doubt, take the safer path.`,\n};\n\nexport interface SuiteAssociations {\n\treadonly skills: readonly string[];\n\treadonly mcp: readonly string[];\n\treadonly plugins: readonly string[];\n\t/**\n\t * 子代理角色关联(D-044 角色机制):关联的是 `<agentDir>/roles/<id>.json` 里的角色 id。\n\t * 角色定义只在磁盘上(工厂仅做种子落盘),方案只决定哪些角色对主代理可见——与\n\t * skill/MCP/插件同构,第一方与第三方角色没有区别。\n\t */\n\treadonly roles: readonly string[];\n}\n\nexport interface SuiteClonedFrom {\n\treadonly id: string;\n\treadonly digest: string;\n\treadonly at: number;\n}\n\n/** The serializable suite definition persisted as suite.json (设计 §5). */\nexport interface SuiteDefinition {\n\treadonly schemaVersion: number;\n\treadonly id: string;\n\treadonly name: string;\n\treadonly builtin: boolean;\n\treadonly tools: readonly string[];\n\treadonly capabilities: readonly string[];\n\treadonly associations: SuiteAssociations;\n\treadonly inheritSystemAgentsMd: boolean;\n\treadonly memory: SuiteMemoryStrategy;\n\treadonly orientation: SuiteOrientation;\n\treadonly model: string | null;\n\treadonly thinking: string | null;\n\treadonly clonedFrom: SuiteClonedFrom | null;\n\t/**\n\t * Factory contents revision this declaration was written at (M4). Builtin\n\t * declarations carry it; on-disk builtin suite.json may omit it (pre-M4\n\t * files parse as FACTORY_CONTENTS_VERSION). User suites are outside factory\n\t * upgrade governance: the key stays optional and may be absent.\n\t */\n\treadonly factoryRevision?: number;\n}\n\nconst EMPTY_ASSOCIATIONS: SuiteAssociations = { skills: [], mcp: [], plugins: [], roles: [] };\n\n/**\n * 默认方案关联的子代理角色(开箱即用):这两个 id 对应工厂种子落盘的两个普通角色文件\n * (`<agentDir>/roles/{explore,reviewer}.json`,用户可改可删)。工厂不在运行期回退到任何\n * 编译内的角色定义;删掉文件只会让该关联成为 dangling 诊断。\n */\nexport const DEFAULT_ROLE_ASSOCIATIONS: readonly string[] = [\"explore\", \"reviewer\"];\n\nconst assistantSuite: SuiteDefinition = {\n\tschemaVersion: SUITE_SCHEMA_VERSION,\n\tid: \"assistant\",\n\tname: \"Assistant\",\n\tbuiltin: true,\n\ttools: BUILTIN_SUITE_TOOLS,\n\tcapabilities: BUILTIN_SUITE_CAPABILITIES,\n\tassociations: { ...EMPTY_ASSOCIATIONS, roles: DEFAULT_ROLE_ASSOCIATIONS },\n\tinheritSystemAgentsMd: false,\n\tmemory: \"assistant\",\n\torientation: \"assistant\",\n\tmodel: null,\n\tthinking: null,\n\tclonedFrom: null,\n\tfactoryRevision: FACTORY_CONTENTS_VERSION,\n};\n\nconst codingSuite: SuiteDefinition = {\n\tschemaVersion: SUITE_SCHEMA_VERSION,\n\tid: \"coding\",\n\tname: \"Coding\",\n\tbuiltin: true,\n\ttools: BUILTIN_SUITE_TOOLS,\n\tcapabilities: BUILTIN_SUITE_CAPABILITIES,\n\tassociations: { ...EMPTY_ASSOCIATIONS, roles: DEFAULT_ROLE_ASSOCIATIONS },\n\tinheritSystemAgentsMd: false,\n\tmemory: \"code\",\n\torientation: \"coding\",\n\tmodel: null,\n\tthinking: null,\n\tclonedFrom: null,\n\tfactoryRevision: FACTORY_CONTENTS_VERSION,\n};\n\n/** The factory builtin pair: assistant (fallback default) and coding (尖刀). */\nexport const BUILTIN_SUITES: readonly SuiteDefinition[] = [assistantSuite, codingSuite];\n\nexport function getBuiltinSuite(id: string): SuiteDefinition | undefined {\n\treturn BUILTIN_SUITES.find((suite) => suite.id === id);\n}\n\nexport function isBuiltinSuiteId(id: string): boolean {\n\treturn BUILTIN_SUITES.some((suite) => suite.id === id);\n}\n\nconst WINDOWS_RESERVED_IDS = new Set([\n\t\"con\",\n\t\"prn\",\n\t\"aux\",\n\t\"nul\",\n\t\"com1\",\n\t\"com2\",\n\t\"com3\",\n\t\"com4\",\n\t\"com5\",\n\t\"com6\",\n\t\"com7\",\n\t\"com8\",\n\t\"com9\",\n\t\"lpt1\",\n\t\"lpt2\",\n\t\"lpt3\",\n\t\"lpt4\",\n\t\"lpt5\",\n\t\"lpt6\",\n\t\"lpt7\",\n\t\"lpt8\",\n\t\"lpt9\",\n\t\"conin$\",\n\t\"conout$\",\n]);\n\n/** Suite id rule (设计 §9): `a-z0-9-`, no leading/trailing hyphen, no Windows reserved names. */\nexport function isValidSuiteId(id: string): boolean {\n\tif (id.length === 0 || id.length > SUITE_ID_MAX_LENGTH) return false;\n\tif (!/^[a-z0-9-]+$/.test(id)) return false;\n\tif (id.startsWith(\"-\") || id.endsWith(\"-\")) return false;\n\tif (WINDOWS_RESERVED_IDS.has(id)) return false;\n\treturn true;\n}\n\n/** Serializes a suite to the canonical suite.json text (stable field order, trailing newline). */\nexport function serializeSuiteJson(suite: SuiteDefinition): string {\n\tconst ordered = {\n\t\tschemaVersion: suite.schemaVersion,\n\t\tid: suite.id,\n\t\tname: suite.name,\n\t\tbuiltin: suite.builtin,\n\t\ttools: [...suite.tools],\n\t\tcapabilities: [...suite.capabilities],\n\t\tassociations: {\n\t\t\tskills: [...suite.associations.skills],\n\t\t\tmcp: [...suite.associations.mcp],\n\t\t\tplugins: [...suite.associations.plugins],\n\t\t\troles: [...suite.associations.roles],\n\t\t},\n\t\tinheritSystemAgentsMd: suite.inheritSystemAgentsMd,\n\t\tmemory: suite.memory,\n\t\torientation: suite.orientation,\n\t\tmodel: suite.model,\n\t\tthinking: suite.thinking,\n\t\tclonedFrom: suite.clonedFrom\n\t\t\t? { id: suite.clonedFrom.id, digest: suite.clonedFrom.digest, at: suite.clonedFrom.at }\n\t\t\t: null,\n\t\tfactoryRevision: suite.factoryRevision,\n\t};\n\treturn `${JSON.stringify(ordered, null, 2)}\\n`;\n}\n\nexport interface SuiteJsonParseResult {\n\treadonly valid: boolean;\n\treadonly suite?: SuiteDefinition;\n\treadonly errors: readonly string[];\n}\n\n/**\n * Parses suite.json text. Never throws: an invalid result carries every\n * validation error so callers can apply the corruption policy (设计 §9) —\n * builtin suites fall back to factory content, user suites fail fast.\n */\nexport function parseSuiteJson(\n\traw: string,\n\toptions: { expectedBuiltin?: boolean; expectedId?: string },\n): SuiteJsonParseResult {\n\tlet value: unknown;\n\ttry {\n\t\tvalue = JSON.parse(raw);\n\t} catch (error) {\n\t\treturn {\n\t\t\tvalid: false,\n\t\t\terrors: [`invalid JSON: ${error instanceof Error ? error.message : String(error)}`],\n\t\t};\n\t}\n\treturn validateSuiteJson(value, options);\n}\n\nexport function validateSuiteJson(\n\tvalue: unknown,\n\toptions: { expectedBuiltin?: boolean; expectedId?: string } = {},\n): SuiteJsonParseResult {\n\tif (value === null || typeof value !== \"object\" || Array.isArray(value)) {\n\t\treturn { valid: false, errors: [\"suite.json must be a JSON object\"] };\n\t}\n\tconst record = value as Record<string, unknown>;\n\tconst errors: string[] = [];\n\n\tif (record.schemaVersion !== SUITE_SCHEMA_VERSION) {\n\t\terrors.push(`schemaVersion must be ${SUITE_SCHEMA_VERSION}, found ${JSON.stringify(record.schemaVersion)}`);\n\t}\n\n\t// Each field keeps a typed local: valid values land here, invalid ones only\n\t// contribute errors. The suite below is constructed exclusively when\n\t// `errors` is empty, so the fallbacks/coercions at that point are dead.\n\tconst idValue = record.id;\n\tconst id = typeof idValue === \"string\" && isValidSuiteId(idValue) ? idValue : undefined;\n\tif (id === undefined) {\n\t\terrors.push(\n\t\t\t`id must be a suite id (^[a-z0-9-]+$, no leading/trailing hyphen, Windows reserved names rejected), found ${JSON.stringify(idValue)}`,\n\t\t);\n\t} else if (options.expectedId !== undefined && id !== options.expectedId) {\n\t\terrors.push(`id \"${id}\" does not match the suite workspace directory id \"${options.expectedId}\"`);\n\t}\n\n\tconst nameValue = record.name;\n\tconst name = typeof nameValue === \"string\" && nameValue.trim().length > 0 ? nameValue : undefined;\n\tif (name === undefined) {\n\t\terrors.push(`name must be a non-empty string, found ${JSON.stringify(nameValue)}`);\n\t}\n\n\tconst builtinValue = record.builtin;\n\tconst builtin = typeof builtinValue === \"boolean\" ? builtinValue : undefined;\n\tif (builtin === undefined) {\n\t\terrors.push(`builtin must be a boolean, found ${JSON.stringify(builtinValue)}`);\n\t} else if (options.expectedBuiltin === true && builtin !== true) {\n\t\terrors.push(`builtin must be true for a builtin suite workspace, found ${builtin}`);\n\t}\n\n\tconst tools = readStringArray(record, \"tools\", errors);\n\tconst capabilities = readStringArray(record, \"capabilities\", errors);\n\tconst associations = readAssociations(record.associations, errors);\n\n\tconst inheritValue = record.inheritSystemAgentsMd;\n\tconst inheritSystemAgentsMd = typeof inheritValue === \"boolean\" ? inheritValue : undefined;\n\tif (inheritSystemAgentsMd === undefined) {\n\t\terrors.push(`inheritSystemAgentsMd must be a boolean, found ${JSON.stringify(inheritValue)}`);\n\t}\n\n\tconst memoryValue = record.memory;\n\tconst memory = memoryValue === \"assistant\" || memoryValue === \"code\" ? memoryValue : undefined;\n\tif (memory === undefined) {\n\t\terrors.push(`memory must be \"assistant\" or \"code\", found ${JSON.stringify(memoryValue)}`);\n\t}\n\n\tconst orientationValue = record.orientation;\n\tconst orientation = orientationValue === \"assistant\" || orientationValue === \"coding\" ? orientationValue : undefined;\n\tif (orientationValue !== undefined && orientation === undefined) {\n\t\terrors.push(`orientation must be \"assistant\" or \"coding\", found ${JSON.stringify(orientationValue)}`);\n\t}\n\n\tconst model = readOptionalString(record, \"model\", errors);\n\tconst thinking = readOptionalString(record, \"thinking\", errors);\n\tconst clonedFrom = readClonedFrom(record.clonedFrom, errors);\n\tconst factoryRevision = readFactoryRevision(record.factoryRevision, options.expectedBuiltin === true, errors);\n\n\tif (errors.length > 0) return { valid: false, errors };\n\n\treturn {\n\t\tvalid: true,\n\t\terrors: [],\n\t\tsuite: {\n\t\t\tschemaVersion: SUITE_SCHEMA_VERSION,\n\t\t\tid: id!,\n\t\t\tname: name!,\n\t\t\tbuiltin: builtin!,\n\t\t\ttools,\n\t\t\tcapabilities,\n\t\t\tassociations,\n\t\t\tinheritSystemAgentsMd: inheritSystemAgentsMd!,\n\t\t\tmemory: memory!,\n\t\t\torientation: orientation ?? \"assistant\",\n\t\t\tmodel,\n\t\t\tthinking,\n\t\t\tclonedFrom,\n\t\t\t...(factoryRevision === undefined ? {} : { factoryRevision }),\n\t\t},\n\t};\n}\n\nfunction readStringArray(record: Record<string, unknown>, key: string, errors: string[]): readonly string[] {\n\tconst value = record[key];\n\tif (!Array.isArray(value)) {\n\t\terrors.push(`${key} must be an array of strings, found ${JSON.stringify(value)}`);\n\t\treturn [];\n\t}\n\tconst entries: string[] = [];\n\tconst seen = new Set<string>();\n\tfor (const item of value) {\n\t\tif (typeof item !== \"string\" || item.trim().length === 0) {\n\t\t\terrors.push(`${key} entries must be non-empty strings, found ${JSON.stringify(item)}`);\n\t\t\tcontinue;\n\t\t}\n\t\tif (seen.has(item)) {\n\t\t\terrors.push(`${key} contains duplicate entry \"${item}\"`);\n\t\t\tcontinue;\n\t\t}\n\t\tseen.add(item);\n\t\tentries.push(item);\n\t}\n\treturn entries;\n}\n\nfunction readAssociations(value: unknown, errors: string[]): SuiteAssociations {\n\tif (value === undefined) return { skills: [], mcp: [], plugins: [], roles: [] };\n\tif (value === null || typeof value !== \"object\" || Array.isArray(value)) {\n\t\terrors.push(\n\t\t\t`associations must be an object with skills/mcp/plugins/roles arrays, found ${JSON.stringify(value)}`,\n\t\t);\n\t\treturn { skills: [], mcp: [], plugins: [], roles: [] };\n\t}\n\tconst record = value as Record<string, unknown>;\n\t// A key left out entirely means an empty list, consistent with a fully\n\t// absent `associations` object; a key that is present but malformed still\n\t// reports its errors. The removed legacy `extensions` kind is ignored on\n\t// read (it lost its loader with the old ExtensionAPI surface).\n\treturn {\n\t\tskills: record.skills === undefined ? [] : readStringArray(record, \"skills\", errors),\n\t\tmcp: record.mcp === undefined ? [] : readStringArray(record, \"mcp\", errors),\n\t\tplugins: record.plugins === undefined ? [] : readStringArray(record, \"plugins\", errors),\n\t\troles: record.roles === undefined ? [] : readStringArray(record, \"roles\", errors),\n\t};\n}\n\nfunction readOptionalString(record: Record<string, unknown>, key: string, errors: string[]): string | null {\n\tconst value = record[key];\n\tif (value === undefined || value === null) return null;\n\tif (typeof value !== \"string\" || value.trim().length === 0) {\n\t\terrors.push(`${key} must be a non-empty string or null, found ${JSON.stringify(value)}`);\n\t\treturn null;\n\t}\n\treturn value;\n}\n\n/**\n * Reads the optional `factoryRevision` key (M4). A missing key means\n * FACTORY_CONTENTS_VERSION for builtin workspaces (pre-M4 on-disk files stay\n * compatible) and stays absent for user suites (outside factory upgrade\n * governance). A present key must be a positive integer.\n */\nfunction readFactoryRevision(value: unknown, expectedBuiltin: boolean, errors: string[]): number | undefined {\n\tif (value === undefined) return expectedBuiltin ? FACTORY_CONTENTS_VERSION : undefined;\n\tif (typeof value !== \"number\" || !Number.isSafeInteger(value) || value <= 0) {\n\t\terrors.push(`factoryRevision must be a positive integer, found ${JSON.stringify(value)}`);\n\t\treturn undefined;\n\t}\n\treturn value;\n}\n\nfunction readClonedFrom(value: unknown, errors: string[]): SuiteClonedFrom | null {\n\tif (value === undefined || value === null) return null;\n\tif (typeof value !== \"object\" || Array.isArray(value)) {\n\t\terrors.push(`clonedFrom must be an object with id/digest/at, found ${JSON.stringify(value)}`);\n\t\treturn null;\n\t}\n\tconst record = value as Record<string, unknown>;\n\tif (\n\t\ttypeof record.id !== \"string\" ||\n\t\trecord.id.trim().length === 0 ||\n\t\ttypeof record.digest !== \"string\" ||\n\t\trecord.digest.trim().length === 0 ||\n\t\ttypeof record.at !== \"number\" ||\n\t\t!Number.isSafeInteger(record.at)\n\t) {\n\t\terrors.push(\n\t\t\t`clonedFrom must be an object with non-empty id/digest strings and an integer at, found ${JSON.stringify(value)}`,\n\t\t);\n\t\treturn null;\n\t}\n\treturn { id: record.id, digest: record.digest, at: record.at };\n}\n"]}
1
+ {"version":3,"file":"builtin-suites.js","sourceRoot":"","sources":["../../src/profiles/builtin-suites.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC;AAEtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,CAAC;AAE1C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,QAAQ,CAAC;AAEzC,yFAAoF;AACpF,MAAM,CAAC,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAEtC,2FAAqF;AACrF,MAAM,CAAC,MAAM,mBAAmB,GAAsB;IACrD,MAAM;IACN,OAAO;IACP,MAAM;IACN,MAAM;IACN,IAAI;IACJ,MAAM;IACN,MAAM;IACN,YAAY;CACZ,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAsB;IAC5D,cAAc;IACd,cAAc;IACd,kBAAkB;IAClB,kBAAkB;IAClB,gBAAgB;I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AC,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,EAAE,CAAC;AAAA,CAC/D","sourcesContent":["/**\n * Builtin suite (方案) declarations and suite.json (schemaVersion 1)\n * serialization, parsing, and validation — 方案系统设计.md v2 §5/§6/§9, M1a.\n *\n * Suites are pure data plus default policy: both builtin suites share the same\n * unrestricted tool surface and differ only in orientation and memory strategy\n * (the orientation persona text is injected into the system prompt, M2).\n * Nothing here touches the packages/agent kernel; association resolution is\n * declaration-only until M1b.\n */\n\nexport const SUITE_SCHEMA_VERSION = 1;\n\n/**\n * Factory contents revision (M4): the revision of the factory builtin\n * declarations, independent of SUITE_SCHEMA_VERSION. Bump it (and update both\n * builtin declarations' `factoryRevision`) whenever the factory contents\n * change; the registry upgrade proposal then offers `--suite-reset` for\n * workspaces still on an older revision. Suite schema evolution keeps using\n * SUITE_SCHEMA_VERSION.\n *\n * Revision 2 (统一修复轮集成收口, 2026-09-08): assistant and coding now share\n * the same active 8-tool surface in full-control — the sdk `suiteToolOverride`\n * DEFAULT_SUITE_ID exemption was removed (方案设计 §5 + user decision). Existing\n * workspaces provisioned at revision 1 receive the upgrade-proposal diagnostic\n * and adopt via `--suite-reset`.\n *\n * Revision 3 (2026-09-18): `builtin.session-share` joins both builtin suites\n * (开发计划 §216: session-share productized from the example plugin into a\n * first-party default-distributed capability) once the agent-dir config\n * channel for embedded capabilities landed\n * (`<agentDir>/capabilities/<short-id>.json`, see capabilities/builtin.ts).\n * Existing workspaces provisioned at revision 2 receive the upgrade-proposal\n * diagnostic and adopt via `--suite-reset`.\n *\n * Revision 4 (2026-09-18): `builtin.subagent-delegate` joins both builtin\n * suites — the first-party subagent delegation tool (`subagent_run`) now ships\n * by default in shared mode (zero extra processes; pooled runner processes stay\n * opt-in through the capability config channel). Existing workspaces\n * provisioned at revision 3 receive the upgrade-proposal diagnostic and adopt\n * via `--suite-reset`.\n *\n * Revision 5 (2026-09-20): subagent role profiles land on disk only\n * (`<agentDir>/roles/<id>.json` — the factory seeds explore/reviewer and never\n * overwrites user edits) and both builtin suites associate them by default via\n * the new `suite.associations.roles` field, with skill/MCP-isomorphic\n * visibility: unassociated roles stay invisible, associated-but-missing files\n * surface as dangling diagnostics. Existing workspaces provisioned at\n * revision 4 receive the upgrade-proposal diagnostic and adopt via\n * `--suite-reset`.\n *\n * Revision 6 (D-077, 2026-10-02): `builtin.workflow` joins both builtin suites\n * — the workflow orchestration plugin enters the factory bootstrap manifest\n * (ninth package) and the suite capability declaration at goal/plan/todo-set\n * parity, keeping its plugin form. Existing workspaces provisioned at revision\n * 5 receive the upgrade-proposal diagnostic and adopt via `--suite-reset`.\n */\nexport const FACTORY_CONTENTS_VERSION = 6;\n\n/**\n * Factory default suite used when no suite is configured anywhere (设计 §9).\n * 2026-10-02 user ruling: the product is a coding agent, so the factory\n * default flipped from \"assistant\" to \"coding\"; assistant stays as the\n * explicit-switch fallback suite.\n */\nexport const DEFAULT_SUITE_ID = \"coding\";\n\n/** Suite ids become directory names: lowercase letters, digits, hyphens (设计 §9). */\nexport const SUITE_ID_MAX_LENGTH = 64;\n\n/** The single unrestricted tool surface shared by both builtin suites (设计 §5/§6). */\nexport const BUILTIN_SUITE_TOOLS: readonly string[] = [\n\t\"read\",\n\t\"write\",\n\t\"edit\",\n\t\"bash\",\n\t\"ls\",\n\t\"find\",\n\t\"grep\",\n\t\"powershell\",\n];\n\n/**\n * Builtin capability plugins associated with both suites. Declaration-only\n * data in M1a; the actual plugin wiring is delivered in M3. `builtin.memory`\n * joins in the 统一修复轮 A 路 (方案系统设计 §6.1: both suites share the same\n * memory tool surface; the strategy difference lives in the suiteId domain\n * isolation and the assistant preference card). `builtin.session-share` joins\n * in the session-share productization slice (开发计划 §216); its\n * target/gateway/viewerUrl are configured through the agent-dir config\n * channel (`<agentDir>/capabilities/builtin.session-share.json`), and the\n * unconfigured default answers `/share` with the explicit configuration\n * prompt — never an implicit Radius/Gist fallback. `builtin.workflow` joins\n * at goal/plan/todo-set parity (D-077, 2026-10-02: factory default install\n * plus this suite declaration, plugin form unchanged).\n */\nexport const BUILTIN_SUITE_CAPABILITIES: readonly string[] = [\n\t\"builtin.goal\",\n\t\"builtin.plan\",\n\t\"builtin.todo-set\",\n\t\"builtin.workflow\",\n\t\"builtin.memory\",\n\t\"builtin.session-share\",\n\t\"builtin.subagent-delegate\",\n];\n\nexport type SuiteMemoryStrategy = \"assistant\" | \"code\";\nexport type SuiteOrientation = \"assistant\" | \"coding\" | \"custom\";\n\n/**\n * Orientation persona texts injected into the system prompt (设计 §6.2, M2).\n * The strings are verbatim from the design spec: the assistant persona is the\n * companion style, the coding persona is the rigor-first style. Both are\n * session-nature declarations, so they ride every system prompt branch\n * (default and customPrompt). The custom orientation is not in this table: its\n * persona text comes from the suite workspace persona.md (设计 §6.3, resolved\n * by suite-loader).\n */\nexport const ORIENTATION_PROMPTS: Record<\"assistant\" | \"coding\", string> = {\n\tassistant: `You are the user's thoughtful companion — warm, patient, and helpful.\n- Understand the intent behind the question, including the unspoken parts; when something that matters is ambiguous, ask one short clarifying question instead of assuming.\n- Pay attention to detail: notice what the user might have missed and gently point it out.\n- Be proactive and divergent: after answering, offer next steps, related ideas, or creative alternatives — without being pushy.\n- Adapt tone to the user; stay natural and flexible, never robotic or formulaic.\n- When you can help by doing, act through tools autonomously (minimal interruption).\n- Structure longer answers clearly: short paragraphs, lists where they help, and a concrete \"what you can do next\" at the end.`,\n\tcoding: `You are an autonomous software engineering agent with a rigor-first mindset.\n- Never guess. Ground every claim in code you have read, commands you have run, or documented evidence; cite file paths and line numbers. If the evidence is insufficient, investigate, and report what is unverified — or \"unknown\" — instead of a plausible invention.\n- First principles: trace problems to the earliest reasonable root cause and fix that; do not patch symptoms.\n- No over-engineering: add no abstraction, options, or defensive handling for imagined future needs; generalise only when a second concrete case demands it.\n- Tests first: pin expected behavior with a failing or updated test before or alongside the fix, then run the smallest sufficient relevant checks; the work is not done until they pass.\n- Reproducible: prefer deterministic tests and mocks over ad-hoc verification, and report the exact commands and results so others can re-run them.\n- Docs as code: repository documentation is part of the change — keep design docs, READMEs, and changelogs consistent with the behavior they describe.\n- Self-review before finishing: re-check your changes for correctness, edge cases, regressions, and missing tests; prefer a second review pass over shipping the first draft.\n- Cautious: weigh side effects, compatibility, and failure modes; when in doubt, take the safer path.`,\n};\n\nexport interface SuiteAssociations {\n\treadonly skills: readonly string[];\n\treadonly mcp: readonly string[];\n\treadonly plugins: readonly string[];\n\t/**\n\t * 子代理角色关联(D-044 角色机制):关联的是 `<agentDir>/roles/<id>.json` 里的角色 id。\n\t * 角色定义只在磁盘上(工厂仅做种子落盘),方案只决定哪些角色对主代理可见——与\n\t * skill/MCP/插件同构,第一方与第三方角色没有区别。\n\t */\n\treadonly roles: readonly string[];\n}\n\nexport interface SuiteClonedFrom {\n\treadonly id: string;\n\treadonly digest: string;\n\treadonly at: number;\n}\n\n/** The serializable suite definition persisted as suite.json (设计 §5). */\nexport interface SuiteDefinition {\n\treadonly schemaVersion: number;\n\treadonly id: string;\n\treadonly name: string;\n\treadonly builtin: boolean;\n\treadonly tools: readonly string[];\n\treadonly capabilities: readonly string[];\n\treadonly associations: SuiteAssociations;\n\treadonly inheritSystemAgentsMd: boolean;\n\treadonly memory: SuiteMemoryStrategy;\n\treadonly orientation: SuiteOrientation;\n\treadonly model: string | null;\n\treadonly thinking: string | null;\n\treadonly clonedFrom: SuiteClonedFrom | null;\n\t/**\n\t * Factory contents revision this declaration was written at (M4). Builtin\n\t * declarations carry it; on-disk builtin suite.json may omit it (pre-M4\n\t * files parse as FACTORY_CONTENTS_VERSION). User suites are outside factory\n\t * upgrade governance: the key stays optional and may be absent.\n\t */\n\treadonly factoryRevision?: number;\n}\n\nconst EMPTY_ASSOCIATIONS: SuiteAssociations = { skills: [], mcp: [], plugins: [], roles: [] };\n\n/**\n * 默认方案关联的子代理角色(开箱即用):这两个 id 对应工厂种子落盘的两个普通角色文件\n * (`<agentDir>/roles/{explore,reviewer}.json`,用户可改可删)。工厂不在运行期回退到任何\n * 编译内的角色定义;删掉文件只会让该关联成为 dangling 诊断。\n */\nexport const DEFAULT_ROLE_ASSOCIATIONS: readonly string[] = [\"explore\", \"reviewer\"];\n\nconst assistantSuite: SuiteDefinition = {\n\tschemaVersion: SUITE_SCHEMA_VERSION,\n\tid: \"assistant\",\n\tname: \"Assistant\",\n\tbuiltin: true,\n\ttools: BUILTIN_SUITE_TOOLS,\n\tcapabilities: BUILTIN_SUITE_CAPABILITIES,\n\tassociations: { ...EMPTY_ASSOCIATIONS, roles: DEFAULT_ROLE_ASSOCIATIONS },\n\tinheritSystemAgentsMd: false,\n\tmemory: \"assistant\",\n\torientation: \"assistant\",\n\tmodel: null,\n\tthinking: null,\n\tclonedFrom: null,\n\tfactoryRevision: FACTORY_CONTENTS_VERSION,\n};\n\nconst codingSuite: SuiteDefinition = {\n\tschemaVersion: SUITE_SCHEMA_VERSION,\n\tid: \"coding\",\n\tname: \"Coding\",\n\tbuiltin: true,\n\ttools: BUILTIN_SUITE_TOOLS,\n\tcapabilities: BUILTIN_SUITE_CAPABILITIES,\n\tassociations: { ...EMPTY_ASSOCIATIONS, roles: DEFAULT_ROLE_ASSOCIATIONS },\n\tinheritSystemAgentsMd: false,\n\tmemory: \"code\",\n\torientation: \"coding\",\n\tmodel: null,\n\tthinking: null,\n\tclonedFrom: null,\n\tfactoryRevision: FACTORY_CONTENTS_VERSION,\n};\n\n/** The factory builtin pair: coding (factory default 尖刀) and assistant (fallback). */\nexport const BUILTIN_SUITES: readonly SuiteDefinition[] = [assistantSuite, codingSuite];\n\nexport function getBuiltinSuite(id: string): SuiteDefinition | undefined {\n\treturn BUILTIN_SUITES.find((suite) => suite.id === id);\n}\n\nexport function isBuiltinSuiteId(id: string): boolean {\n\treturn BUILTIN_SUITES.some((suite) => suite.id === id);\n}\n\nconst WINDOWS_RESERVED_IDS = new Set([\n\t\"con\",\n\t\"prn\",\n\t\"aux\",\n\t\"nul\",\n\t\"com1\",\n\t\"com2\",\n\t\"com3\",\n\t\"com4\",\n\t\"com5\",\n\t\"com6\",\n\t\"com7\",\n\t\"com8\",\n\t\"com9\",\n\t\"lpt1\",\n\t\"lpt2\",\n\t\"lpt3\",\n\t\"lpt4\",\n\t\"lpt5\",\n\t\"lpt6\",\n\t\"lpt7\",\n\t\"lpt8\",\n\t\"lpt9\",\n\t\"conin$\",\n\t\"conout$\",\n]);\n\n/** Suite id rule (设计 §9): `a-z0-9-`, no leading/trailing hyphen, no Windows reserved names. */\nexport function isValidSuiteId(id: string): boolean {\n\tif (id.length === 0 || id.length > SUITE_ID_MAX_LENGTH) return false;\n\tif (!/^[a-z0-9-]+$/.test(id)) return false;\n\tif (id.startsWith(\"-\") || id.endsWith(\"-\")) return false;\n\tif (WINDOWS_RESERVED_IDS.has(id)) return false;\n\treturn true;\n}\n\n/** Serializes a suite to the canonical suite.json text (stable field order, trailing newline). */\nexport function serializeSuiteJson(suite: SuiteDefinition): string {\n\tconst ordered = {\n\t\tschemaVersion: suite.schemaVersion,\n\t\tid: suite.id,\n\t\tname: suite.name,\n\t\tbuiltin: suite.builtin,\n\t\ttools: [...suite.tools],\n\t\tcapabilities: [...suite.capabilities],\n\t\tassociations: {\n\t\t\tskills: [...suite.associations.skills],\n\t\t\tmcp: [...suite.associations.mcp],\n\t\t\tplugins: [...suite.associations.plugins],\n\t\t\troles: [...suite.associations.roles],\n\t\t},\n\t\tinheritSystemAgentsMd: suite.inheritSystemAgentsMd,\n\t\tmemory: suite.memory,\n\t\torientation: suite.orientation,\n\t\tmodel: suite.model,\n\t\tthinking: suite.thinking,\n\t\tclonedFrom: suite.clonedFrom\n\t\t\t? { id: suite.clonedFrom.id, digest: suite.clonedFrom.digest, at: suite.clonedFrom.at }\n\t\t\t: null,\n\t\tfactoryRevision: suite.factoryRevision,\n\t};\n\treturn `${JSON.stringify(ordered, null, 2)}\\n`;\n}\n\nexport interface SuiteJsonParseResult {\n\treadonly valid: boolean;\n\treadonly suite?: SuiteDefinition;\n\treadonly errors: readonly string[];\n}\n\n/**\n * Parses suite.json text. Never throws: an invalid result carries every\n * validation error so callers can apply the corruption policy (设计 §9) —\n * builtin suites fall back to factory content, user suites fail fast.\n */\nexport function parseSuiteJson(\n\traw: string,\n\toptions: { expectedBuiltin?: boolean; expectedId?: string },\n): SuiteJsonParseResult {\n\tlet value: unknown;\n\ttry {\n\t\tvalue = JSON.parse(raw);\n\t} catch (error) {\n\t\treturn {\n\t\t\tvalid: false,\n\t\t\terrors: [`invalid JSON: ${error instanceof Error ? error.message : String(error)}`],\n\t\t};\n\t}\n\treturn validateSuiteJson(value, options);\n}\n\nexport function validateSuiteJson(\n\tvalue: unknown,\n\toptions: { expectedBuiltin?: boolean; expectedId?: string } = {},\n): SuiteJsonParseResult {\n\tif (value === null || typeof value !== \"object\" || Array.isArray(value)) {\n\t\treturn { valid: false, errors: [\"suite.json must be a JSON object\"] };\n\t}\n\tconst record = value as Record<string, unknown>;\n\tconst errors: string[] = [];\n\n\tif (record.schemaVersion !== SUITE_SCHEMA_VERSION) {\n\t\terrors.push(`schemaVersion must be ${SUITE_SCHEMA_VERSION}, found ${JSON.stringify(record.schemaVersion)}`);\n\t}\n\n\t// Each field keeps a typed local: valid values land here, invalid ones only\n\t// contribute errors. The suite below is constructed exclusively when\n\t// `errors` is empty, so the fallbacks/coercions at that point are dead.\n\tconst idValue = record.id;\n\tconst id = typeof idValue === \"string\" && isValidSuiteId(idValue) ? idValue : undefined;\n\tif (id === undefined) {\n\t\terrors.push(\n\t\t\t`id must be a suite id (^[a-z0-9-]+$, no leading/trailing hyphen, Windows reserved names rejected), found ${JSON.stringify(idValue)}`,\n\t\t);\n\t} else if (options.expectedId !== undefined && id !== options.expectedId) {\n\t\terrors.push(`id \"${id}\" does not match the suite workspace directory id \"${options.expectedId}\"`);\n\t}\n\n\tconst nameValue = record.name;\n\tconst name = typeof nameValue === \"string\" && nameValue.trim().length > 0 ? nameValue : undefined;\n\tif (name === undefined) {\n\t\terrors.push(`name must be a non-empty string, found ${JSON.stringify(nameValue)}`);\n\t}\n\n\tconst builtinValue = record.builtin;\n\tconst builtin = typeof builtinValue === \"boolean\" ? builtinValue : undefined;\n\tif (builtin === undefined) {\n\t\terrors.push(`builtin must be a boolean, found ${JSON.stringify(builtinValue)}`);\n\t} else if (options.expectedBuiltin === true && builtin !== true) {\n\t\terrors.push(`builtin must be true for a builtin suite workspace, found ${builtin}`);\n\t}\n\n\tconst tools = readStringArray(record, \"tools\", errors);\n\tconst capabilities = readStringArray(record, \"capabilities\", errors);\n\tconst associations = readAssociations(record.associations, errors);\n\n\tconst inheritValue = record.inheritSystemAgentsMd;\n\tconst inheritSystemAgentsMd = typeof inheritValue === \"boolean\" ? inheritValue : undefined;\n\tif (inheritSystemAgentsMd === undefined) {\n\t\terrors.push(`inheritSystemAgentsMd must be a boolean, found ${JSON.stringify(inheritValue)}`);\n\t}\n\n\tconst memoryValue = record.memory;\n\tconst memory = memoryValue === \"assistant\" || memoryValue === \"code\" ? memoryValue : undefined;\n\tif (memory === undefined) {\n\t\terrors.push(`memory must be \"assistant\" or \"code\", found ${JSON.stringify(memoryValue)}`);\n\t}\n\n\tconst orientationValue = record.orientation;\n\tconst orientation =\n\t\torientationValue === \"assistant\" || orientationValue === \"coding\" || orientationValue === \"custom\"\n\t\t\t? orientationValue\n\t\t\t: undefined;\n\tif (orientationValue !== undefined && orientation === undefined) {\n\t\terrors.push(`orientation must be \"assistant\", \"coding\", or \"custom\", found ${JSON.stringify(orientationValue)}`);\n\t}\n\n\tconst model = readOptionalString(record, \"model\", errors);\n\tconst thinking = readOptionalString(record, \"thinking\", errors);\n\tconst clonedFrom = readClonedFrom(record.clonedFrom, errors);\n\tconst factoryRevision = readFactoryRevision(record.factoryRevision, options.expectedBuiltin === true, errors);\n\n\tif (errors.length > 0) return { valid: false, errors };\n\n\treturn {\n\t\tvalid: true,\n\t\terrors: [],\n\t\tsuite: {\n\t\t\tschemaVersion: SUITE_SCHEMA_VERSION,\n\t\t\tid: id!,\n\t\t\tname: name!,\n\t\t\tbuiltin: builtin!,\n\t\t\ttools,\n\t\t\tcapabilities,\n\t\t\tassociations,\n\t\t\tinheritSystemAgentsMd: inheritSystemAgentsMd!,\n\t\t\tmemory: memory!,\n\t\t\torientation: orientation ?? \"assistant\",\n\t\t\tmodel,\n\t\t\tthinking,\n\t\t\tclonedFrom,\n\t\t\t...(factoryRevision === undefined ? {} : { factoryRevision }),\n\t\t},\n\t};\n}\n\nfunction readStringArray(record: Record<string, unknown>, key: string, errors: string[]): readonly string[] {\n\tconst value = record[key];\n\tif (!Array.isArray(value)) {\n\t\terrors.push(`${key} must be an array of strings, found ${JSON.stringify(value)}`);\n\t\treturn [];\n\t}\n\tconst entries: string[] = [];\n\tconst seen = new Set<string>();\n\tfor (const item of value) {\n\t\tif (typeof item !== \"string\" || item.trim().length === 0) {\n\t\t\terrors.push(`${key} entries must be non-empty strings, found ${JSON.stringify(item)}`);\n\t\t\tcontinue;\n\t\t}\n\t\tif (seen.has(item)) {\n\t\t\terrors.push(`${key} contains duplicate entry \"${item}\"`);\n\t\t\tcontinue;\n\t\t}\n\t\tseen.add(item);\n\t\tentries.push(item);\n\t}\n\treturn entries;\n}\n\nfunction readAssociations(value: unknown, errors: string[]): SuiteAssociations {\n\tif (value === undefined) return { skills: [], mcp: [], plugins: [], roles: [] };\n\tif (value === null || typeof value !== \"object\" || Array.isArray(value)) {\n\t\terrors.push(\n\t\t\t`associations must be an object with skills/mcp/plugins/roles arrays, found ${JSON.stringify(value)}`,\n\t\t);\n\t\treturn { skills: [], mcp: [], plugins: [], roles: [] };\n\t}\n\tconst record = value as Record<string, unknown>;\n\t// A key left out entirely means an empty list, consistent with a fully\n\t// absent `associations` object; a key that is present but malformed still\n\t// reports its errors. The removed legacy `extensions` kind is ignored on\n\t// read (it lost its loader with the old ExtensionAPI surface).\n\treturn {\n\t\tskills: record.skills === undefined ? [] : readStringArray(record, \"skills\", errors),\n\t\tmcp: record.mcp === undefined ? [] : readStringArray(record, \"mcp\", errors),\n\t\tplugins: record.plugins === undefined ? [] : readStringArray(record, \"plugins\", errors),\n\t\troles: record.roles === undefined ? [] : readStringArray(record, \"roles\", errors),\n\t};\n}\n\nfunction readOptionalString(record: Record<string, unknown>, key: string, errors: string[]): string | null {\n\tconst value = record[key];\n\tif (value === undefined || value === null) return null;\n\tif (typeof value !== \"string\" || value.trim().length === 0) {\n\t\terrors.push(`${key} must be a non-empty string or null, found ${JSON.stringify(value)}`);\n\t\treturn null;\n\t}\n\treturn value;\n}\n\n/**\n * Reads the optional `factoryRevision` key (M4). A missing key means\n * FACTORY_CONTENTS_VERSION for builtin workspaces (pre-M4 on-disk files stay\n * compatible) and stays absent for user suites (outside factory upgrade\n * governance). A present key must be a positive integer.\n */\nfunction readFactoryRevision(value: unknown, expectedBuiltin: boolean, errors: string[]): number | undefined {\n\tif (value === undefined) return expectedBuiltin ? FACTORY_CONTENTS_VERSION : undefined;\n\tif (typeof value !== \"number\" || !Number.isSafeInteger(value) || value <= 0) {\n\t\terrors.push(`factoryRevision must be a positive integer, found ${JSON.stringify(value)}`);\n\t\treturn undefined;\n\t}\n\treturn value;\n}\n\nfunction readClonedFrom(value: unknown, errors: string[]): SuiteClonedFrom | null {\n\tif (value === undefined || value === null) return null;\n\tif (typeof value !== \"object\" || Array.isArray(value)) {\n\t\terrors.push(`clonedFrom must be an object with id/digest/at, found ${JSON.stringify(value)}`);\n\t\treturn null;\n\t}\n\tconst record = value as Record<string, unknown>;\n\tif (\n\t\ttypeof record.id !== \"string\" ||\n\t\trecord.id.trim().length === 0 ||\n\t\ttypeof record.digest !== \"string\" ||\n\t\trecord.digest.trim().length === 0 ||\n\t\ttypeof record.at !== \"number\" ||\n\t\t!Number.isSafeInteger(record.at)\n\t) {\n\t\terrors.push(\n\t\t\t`clonedFrom must be an object with non-empty id/digest strings and an integer at, found ${JSON.stringify(value)}`,\n\t\t);\n\t\treturn null;\n\t}\n\treturn { id: record.id, digest: record.digest, at: record.at };\n}\n"]}
@@ -1,3 +1,19 @@
1
+ /**
2
+ * Suite workspace location, lazy provisioning, and assembly (方案系统设计.md v2
3
+ * §4/§5/§8/§9/§11/§12, M1a).
4
+ *
5
+ * The loader is the assembler layer of the suite system: it resolves the
6
+ * active suite id (explicit > AGENT_FORGE_SUITE > project settings > global
7
+ * settings > "assistant"), provisions the builtin suite workspaces under
8
+ * `<agentDir>/suites/<id>/`, assembles the agents.md three-level chain
9
+ * (system -> suite -> project, 设计 §8), gates the global SYSTEM.md/
10
+ * APPEND_SYSTEM.md system prompt channel by inheritSystemAgentsMd (设计 §4:
11
+ * the project-level `<cwd>/.agent-forge/` layer always passes), and bridges
12
+ * the assembled suite onto the existing ProfileIdentityV1/ProfileLock
13
+ * mechanisms. The project level of the chain is delegated to the existing
14
+ * resource loader — the ancestor chain logic itself is never reimplemented
15
+ * here.
16
+ */
1
17
  import type { ResourceDiagnostic } from "../core/diagnostics.ts";
2
18
  import type { SettingsManager } from "../core/settings-manager.ts";
3
19
  import type { Skill } from "../core/skills.ts";
@@ -12,6 +28,7 @@ export { DEFAULT_SUITE_ID };
12
28
  export declare const SUITES_DIR_NAME = "suites";
13
29
  export declare const SUITE_MANIFEST_FILENAME = "suite.json";
14
30
  export declare const SUITE_AGENTS_MD_FILENAME = "agents.md";
31
+ export declare const SUITE_PERSONA_MD_FILENAME = "persona.md";
15
32
  export declare const SUITE_ENV_VAR = "AGENT_FORGE_SUITE";
16
33
  /** customType of the session custom entry recording the suite a session was created with (设计 §10.1). */
17
34
  export declare const SUITE_SESSION_ENTRY_TYPE = "suite";
@@ -50,7 +67,7 @@ export interface ResolveSuiteIdOptions {
50
67
  }
51
68
  /**
52
69
  * Resolves the active suite id: explicit > env AGENT_FORGE_SUITE > project
53
- * settings `suite` > global settings `suite` > "assistant" (设计 §9). The
70
+ * settings `suite` > global settings `suite` > "coding" (设计 §9). The
54
71
  * first configured value wins; an unknown or malformed value is a structured
55
72
  * error, never a silent fallback.
56
73
  */
@@ -60,6 +77,13 @@ export interface SuiteWorkspace {
60
77
  readonly suiteDir: string;
61
78
  readonly suiteJsonPath: string;
62
79
  readonly agentsMdPath: string;
80
+ /**
81
+ * The resolved orientation persona text (设计 §6.2/§6.3): the compiled
82
+ * ORIENTATION_PROMPTS text for assistant/coding, the workspace persona.md
83
+ * content for custom; a missing or unreadable file degrades to "" with a
84
+ * diagnostic.
85
+ */
86
+ readonly orientationPersona: string;
63
87
  readonly diagnostics: readonly string[];
64
88
  /** Persisted lock file path inside the workspace (M4). */
65
89
  readonly lockPath: string;
@@ -1 +1 @@
1
- {"version":3,"file":"suite-loader.d.ts","sourceRoot":"","sources":["../../src/profiles/suite-loader.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAEhE,OAAO,KAAK,EAAE,aAAa,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAEnF,OAAO,KAAK,EACX,gCAAgC,EAChC,wBAAwB,EACxB,gCAAgC,EAChC,MAAM,+BAA+B,CAAC;AAEvC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,KAAK,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAG/F,OAAO,EAEN,gBAAgB,EAQhB,KAAK,eAAe,EAEpB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,gBAAgB,EAAE,CAAC;AAE5B,eAAO,MAAM,eAAe,WAAW,CAAC;AACxC,eAAO,MAAM,uBAAuB,eAAe,CAAC;AACpD,eAAO,MAAM,wBAAwB,cAAc,CAAC;AACpD,eAAO,MAAM,aA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;IAC/C,QAAQ,CAAC,KAAK,EAAE,eAAe,CAAC;IAChC,QAAQ,CAAC,aAAa,CAAC,EAAE,gCAAgC,CAAC;IAC1D,QAAQ,CAAC,YAAY,CAAC,EAAE,aAAa,CAAC;IACtC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CAC5B,GAAG,sBAAsB,CA6BzB","sourcesContent":["/**\n * Suite workspace location, lazy provisioning, and assembly (方案系统设计.md v2\n * §4/§5/§8/§9/§11/§12, M1a).\n *\n * The loader is the assembler layer of the suite system: it resolves the\n * active suite id (explicit > AGENT_FORGE_SUITE > project settings > global\n * settings > \"assistant\"), provisions the builtin suite workspaces under\n * `<agentDir>/suites/<id>/`, assembles the agents.md three-level chain\n * (system -> suite -> project, 设计 §8), gates the global SYSTEM.md/\n * APPEND_SYSTEM.md system prompt channel by inheritSystemAgentsMd (设计 §4:\n * the project-level `<cwd>/.agent-forge/` layer always passes), and bridges\n * the assembled suite onto the existing ProfileIdentityV1/ProfileLock\n * mechanisms. The project level of the chain is delegated to the existing\n * resource loader — the ancestor chain logic itself is never reimplemented\n * here.\n */\nimport { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { join, resolve, sep } from \"node:path\";\nimport type { JsonValue } from \"@agent-forge/ai\";\nimport { CONFIG_DIR_NAME } from \"../config.ts\";\nimport type { ResourceDiagnostic } from \"../core/diagnostics.ts\";\nimport type { SettingsManager } from \"../core/settings-manager.ts\";\nimport type { Skill } from \"../core/skills.ts\";\nimport { loadSkills } from \"../core/skills.ts\";\nimport type { HostFactsV1 } from \"../plugins/ecosystem/types.ts\";\nimport type { ProfileIdentityV1 } from \"../profile/identity.ts\";\nimport { buildProfileIdentityV1, stableJsonDigest } from \"../profile/identity.ts\";\nimport type { ProfileLockV1, ProfileLockVerificationV1 } from \"../profile/lock.ts\";\nimport { createProfileLock, verifyProfileLock } from \"../profile/lock.ts\";\nimport type {\n\tBuiltinPluginManifestOverridesV1,\n\tBuiltinPluginProfileIdV1,\n\tBuiltinPluginProfileResolutionV1,\n} from \"../profile/plugin-profiles.ts\";\nimport { resolveBuiltinPluginProfileV1 } from \"../profile/plugin-profiles.ts\";\nimport type { VerifiedToolPluginV1 } from \"../profile/profile-assembly.ts\";\nimport type { RegistryProfileEntryV1, RegistrySourceV1 } from \"../profile/profile-registry.ts\";\nimport { createProfileRegistry } from \"../profile/profile-registry.ts\";\nimport { stripBom } from \"../utils/text.ts\";\nimport {\n\tBUILTIN_SUITES,\n\tDEFAULT_SUITE_ID,\n\tFACTORY_CONTENTS_VERSION,\n\tgetBuiltinSuite,\n\tisBuiltinSuiteId,\n\tisValidSuiteId,\n\tORIENTATION_PROMPTS,\n\tparseSuiteJson,\n\tSUITE_SCHEMA_VERSION,\n\ttype SuiteDefinition,\n\tserializeSuiteJson,\n} from \"./builtin-suites.ts\";\n\nexport { DEFAULT_SUITE_ID };\n\nexport const SUITES_DIR_NAME = \"suites\";\nexport const SUITE_MANIFEST_FILENAME = \"suite.json\";\nexport const SUITE_AGENTS_MD_FILENAME = \"agents.md\";\nexport const SUITE_ENV_VAR = \"AGENT_FORGE_SUITE\";\n/** customType of the session custom entry recording the suite a session was created with (设计 §10.1). */\nexport const SUITE_SESSION_ENTRY_TYPE = \"suite\";\n/** Persisted suite profile lock inside the suite workspace (M4, 设计 §12). */\nexport const SUITE_LOCK_FILENAME = \".profile-lock.json\";\n\nexport function getSuitesRootDir(agentDir: string): string {\n\treturn join(agentDir, SUITES_DIR_NAME);\n}\n\nexport function getSuiteWorkspaceDir(agentDir: string, suiteId: string): string {\n\treturn join(getSuitesRootDir(agentDir), suiteId);\n}\n\n/** The suite-local skill layer directory (统一修复轮 B): `<suiteDir>/skills`. */\nexport function getSuiteLocalSkillsDir(agentDir: string, suiteId: string): string {\n\treturn join(getSuiteWorkspaceDir(agentDir, suiteId), \"skills\");\n}\n\n/** The suite-local capability-plugin layer directory (统一修复轮 B): `<suiteDir>/plugins`. */\nexport function getSuiteLocalPluginsDir(agentDir: string, suiteId: string): string {\n\treturn join(getSuiteWorkspaceDir(agentDir, suiteId), \"plugins\");\n}\n\n/** Structured error for unknown suite ids; lists the available ids (设计 §9). */\nexport class SuiteResolutionError extends Error {\n\treadonly requestedId: string;\n\treadonly availableSuiteIds: readonly string[];\n\n\tconstructor(requestedId: string, availableSuiteIds: readonly string[]) {\n\t\tsuper(`Unknown suite \"${requestedId}\". Available suites: ${availableSuiteIds.join(\", \")}`);\n\t\tthis.name = \"SuiteResolutionError\";\n\t\tthis.requestedId = requestedId;\n\t\tthis.availableSuiteIds = Object.freeze([...availableSuiteIds]);\n\t}\n}\n\n/** Structured error for resuming a session under a suite it is not bound to. */\nexport class SuiteRebindError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"SuiteRebindError\";\n\t}\n}\n\n/**\n * Every suite id resolvable on this host: the builtin pair plus user\n * workspaces that already contain a suite.json.\n */\nexport function listSuiteIds(agentDir: string): string[] {\n\tconst ids = new Set(BUILTIN_SUITES.map((suite) => suite.id));\n\tconst rootDir = getSuitesRootDir(agentDir);\n\tif (existsSync(rootDir)) {\n\t\tfor (const entry of readdirSync(rootDir, { withFileTypes: true })) {\n\t\t\tif (!entry.isDirectory()) continue;\n\t\t\tif (!existsSync(join(rootDir, entry.name, SUITE_MANIFEST_FILENAME))) continue;\n\t\t\tids.add(entry.name);\n\t\t}\n\t}\n\treturn [...ids].sort();\n}\n\nexport interface ResolveSuiteIdOptions {\n\t/** Explicit suite id (SDK/CLI parameter); highest priority. */\n\texplicit?: string;\n\t/** Raw AGENT_FORGE_SUITE value; callers pass process.env[SUITE_ENV_VAR]. */\n\tenvSuite?: string;\n\t/** Settings source for the project/global `suite` keys. */\n\tsettings?: Pick<SettingsManager, \"getProjectSettings\" | \"getGlobalSettings\">;\n\t/** Agent dir used for workspace discovery and available-id listing. */\n\tagentDir: string;\n}\n\nfunction normalizeCandidate(value: unknown): string | undefined {\n\tif (typeof value !== \"string\") return undefined;\n\tconst trimmed = value.trim();\n\treturn trimmed.length > 0 ? trimmed : undefined;\n}\n\n/**\n * Resolves the active suite id: explicit > env AGENT_FORGE_SUITE > project\n * settings `suite` > global settings `suite` > \"assistant\" (设计 §9). The\n * first configured value wins; an unknown or malformed value is a structured\n * error, never a silent fallback.\n */\nexport function resolveSuiteId(options: ResolveSuiteIdOptions): string {\n\tconst candidate =\n\t\tnormalizeCandidate(options.explicit) ??\n\t\tnormalizeCandidate(options.envSuite) ??\n\t\t(options.settings === undefined ? undefined : normalizeCandidate(options.settings.getProjectSettings().suite)) ??\n\t\t(options.settings === undefined ? undefined : normalizeCandidate(options.settings.getGlobalSettings().suite));\n\tif (candidate === undefined) return DEFAULT_SUITE_ID;\n\tif (!isValidSuiteId(candidate)) throw new SuiteResolutionError(candidate, listSuiteIds(options.agentDir));\n\tif (!isBuiltinSuiteId(candidate)) {\n\t\tconst workspaceManifest = join(getSuiteWorkspaceDir(options.agentDir, candidate), SUITE_MANIFEST_FILENAME);\n\t\tif (!existsSync(workspaceManifest)) throw new SuiteResolutionError(candidate, listSuiteIds(options.agentDir));\n\t}\n\treturn candidate;\n}\n\nexport interface SuiteWorkspace {\n\treadonly suite: SuiteDefinition;\n\treadonly suiteDir: string;\n\treadonly suiteJsonPath: string;\n\treadonly agentsMdPath: string;\n\treadonly diagnostics: readonly string[];\n\t/** Persisted lock file path inside the workspace (M4). */\n\treadonly lockPath: string;\n\t/**\n\t * The suite profile lock (设计 §12): the persisted lock when one existed, a\n\t * fresh lock frozen over the current identity otherwise.\n\t */\n\treadonly lock: ProfileLockV1;\n\t/** Current resolved identity, including any selected optional domain Profile. */\n\treadonly identity: ProfileIdentityV1;\n\t/** Verify result against the persisted lock; absent when none existed. */\n\treadonly lockVerification?: ProfileLockVerificationV1;\n}\n\n/**\n * Serializes a ProfileLockV1 to the canonical `.profile-lock.json` text\n * (stable field order, trailing newline). Round-trips through\n * parseSuiteProfileLockFile.\n */\nexport function serializeSuiteProfileLockFile(lock: ProfileLockV1): string {\n\tconst ordered = {\n\t\tidentity: {\n\t\t\tprofileId: lock.identity.profileId,\n\t\t\tprofileVersion: lock.identity.profileVersion,\n\t\t\tmanifestDigest: lock.identity.manifestDigest,\n\t\t\tcapabilityVersions: lock.identity.capabilityVersions.map((ref) => ({ id: ref.id, version: ref.version })),\n\t\t},\n\t\tlockedAt: lock.lockedAt,\n\t\tlockedBy: lock.lockedBy,\n\t\tgeneration: lock.generation,\n\t};\n\treturn `${JSON.stringify(ordered, null, 2)}\\n`;\n}\n\n/**\n * Parses `.profile-lock.json` text back into a ProfileLockV1. Throws on any\n * structural mismatch so callers can apply their corruption policy.\n */\nexport function parseSuiteProfileLockFile(text: string): ProfileLockV1 {\n\tconst value: unknown = JSON.parse(text);\n\tif (value === null || typeof value !== \"object\" || Array.isArray(value)) {\n\t\tthrow new Error(\".profile-lock.json must be a JSON object\");\n\t}\n\tconst record = value as Record<string, unknown>;\n\tconst identityRecord = record.identity;\n\tif (identityRecord === null || typeof identityRecord !== \"object\" || Array.isArray(identityRecord)) {\n\t\tthrow new Error(\".profile-lock.json identity must be a JSON object\");\n\t}\n\tconst identity = identityRecord as Record<string, unknown>;\n\tif (\n\t\ttypeof identity.profileId !== \"string\" ||\n\t\ttypeof identity.profileVersion !== \"string\" ||\n\t\ttypeof identity.manifestDigest !== \"string\" ||\n\t\t!Array.isArray(identity.capabilityVersions)\n\t) {\n\t\tthrow new Error(\n\t\t\t\".profile-lock.json identity must carry profileId/profileVersion/manifestDigest/capabilityVersions\",\n\t\t);\n\t}\n\tconst capabilityVersions = identity.capabilityVersions.map((entry) => {\n\t\tif (entry === null || typeof entry !== \"object\" || Array.isArray(entry)) {\n\t\t\tthrow new Error(\".profile-lock.json identity.capabilityVersions entries must be objects\");\n\t\t}\n\t\tconst capability = entry as Record<string, unknown>;\n\t\tif (typeof capability.id !== \"string\" || typeof capability.version !== \"number\") {\n\t\t\tthrow new Error(\".profile-lock.json identity.capabilityVersions entries must carry id/version\");\n\t\t}\n\t\treturn { id: capability.id, version: capability.version };\n\t});\n\tif (\n\t\ttypeof record.lockedAt !== \"number\" ||\n\t\ttypeof record.lockedBy !== \"string\" ||\n\t\ttypeof record.generation !== \"number\"\n\t) {\n\t\tthrow new Error(\".profile-lock.json must carry lockedAt/lockedBy/generation\");\n\t}\n\treturn Object.freeze({\n\t\tidentity: Object.freeze({\n\t\t\tprofileId: identity.profileId,\n\t\t\tprofileVersion: identity.profileVersion,\n\t\t\tmanifestDigest: identity.manifestDigest,\n\t\t\tcapabilityVersions: Object.freeze(capabilityVersions.map((ref) => Object.freeze({ ...ref }))),\n\t\t}),\n\t\tlockedAt: record.lockedAt,\n\t\tlockedBy: record.lockedBy,\n\t\tgeneration: record.generation,\n\t});\n}\n\n/**\n * Locates and lazily provisions `<agentDir>/suites/<id>/`: the builtin pair\n * gets its factory suite.json plus an empty agents.md skeleton on first start\n * (设计 §5). Corruption policy (设计 §9): builtin suites fall back to factory\n * content with diagnostics; user suites fail fast with the file path.\n */\nexport function loadSuiteWorkspace(options: {\n\tagentDir: string;\n\tsuiteId: string;\n\tpluginProfile?: BuiltinPluginProfileResolutionV1;\n}): SuiteWorkspace {\n\tconst { agentDir, suiteId } = options;\n\tconst suiteDir = getSuiteWorkspaceDir(agentDir, suiteId);\n\tconst suiteJsonPath = join(suiteDir, SUITE_MANIFEST_FILENAME);\n\tconst agentsMdPath = join(suiteDir, SUITE_AGENTS_MD_FILENAME);\n\tconst diagnostics: string[] = [];\n\n\tlet suite: SuiteDefinition;\n\tif (!existsSync(suiteJsonPath)) {\n\t\tconst builtin = getBuiltinSuite(suiteId);\n\t\tif (builtin === undefined) throw new SuiteResolutionError(suiteId, listSuiteIds(agentDir));\n\t\tmkdirSync(suiteDir, { recursive: true });\n\t\twriteFileSync(suiteJsonPath, serializeSuiteJson(builtin), \"utf8\");\n\t\t// D-075 S4 第三批:首启不再预种角色文件——种子移到 subagent-delegate 插件\n\t\t// 注册期(entry 的幂等 seedFactoryRoleCatalog 补缺),插件安装并注册时\n\t\t// `<agentDir>/roles/{explore,reviewer}.json` 自然到位。\n\t\tsuite = builtin;\n\t} else {\n\t\tconst parsed = parseSuiteJson(readFileSync(suiteJsonPath, \"utf8\"), {\n\t\t\texpectedBuiltin: getBuiltinSuite(suiteId) !== undefined,\n\t\t\texpectedId: suiteId,\n\t\t});\n\t\tconst builtin = getBuiltinSuite(suiteId);\n\t\tif (parsed.valid && parsed.suite) {\n\t\t\tsuite = parsed.suite;\n\t\t} else if (builtin !== undefined) {\n\t\t\t// Builtin corruption policy (设计 §9): fall back to factory content\n\t\t\t// with diagnostics instead of locking the user out. The file on disk\n\t\t\t// is left untouched; recovery (reset) is an explicit M4 flow.\n\t\t\tsuite = builtin;\n\t\t\tdiagnostics.push(\n\t\t\t\t`suite.json at ${suiteJsonPath} is invalid; falling back to the factory content for builtin suite \"${suiteId}\". Errors: ${parsed.errors.join(\"; \")}`,\n\t\t\t);\n\t\t} else {\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid suite.json at ${suiteJsonPath}: ${parsed.errors.join(\"; \")}. Fix the file, or delete the suite workspace directory ${suiteDir} and recreate it.`,\n\t\t\t);\n\t\t}\n\t}\n\n\tif (!existsSync(agentsMdPath)) {\n\t\twriteFileSync(agentsMdPath, \"\", \"utf8\");\n\t}\n\n\t// Suite profile lock persistence (M4, 设计 §12): an existing lock file is\n\t// verified against the current identity (drift/migration recorded, never\n\t// blocking and never silently replaced); without one a fresh lock is frozen\n\t// and persisted. A lock file that cannot be parsed is recreated with a\n\t// diagnostic — it carries no openable identity, so nothing is silently\n\t// replaced.\n\tconst lockPath = join(suiteDir, SUITE_LOCK_FILENAME);\n\tlet previousLock: ProfileLockV1 | undefined;\n\tif (existsSync(lockPath)) {\n\t\ttry {\n\t\t\tpreviousLock = parseSuiteProfileLockFile(readFileSync(lockPath, \"utf8\"));\n\t\t} catch (error) {\n\t\t\tdiagnostics.push(\n\t\t\t\t`Profile lock at ${lockPath} is unreadable; recreating it over the current suite identity. Errors: ${\n\t\t\t\t\terror instanceof Error ? error.message : String(error)\n\t\t\t\t}`,\n\t\t\t);\n\t\t}\n\t}\n\tconst bridge = bridgeSuiteProfileLock({\n\t\tsuite,\n\t\t...(options.pluginProfile === undefined ? {} : { pluginProfile: options.pluginProfile }),\n\t\t...(previousLock === undefined ? {} : { previousLock }),\n\t\tlockedBy: \"suite-loader\",\n\t});\n\tdiagnostics.push(...bridge.diagnostics);\n\tif (previousLock === undefined) {\n\t\ttry {\n\t\t\twriteFileSync(lockPath, serializeSuiteProfileLockFile(bridge.lock), \"utf8\");\n\t\t} catch (error) {\n\t\t\tdiagnostics.push(\n\t\t\t\t`Failed to persist the suite profile lock at ${lockPath}: ${\n\t\t\t\t\terror instanceof Error ? error.message : String(error)\n\t\t\t\t}`,\n\t\t\t);\n\t\t}\n\t}\n\n\treturn {\n\t\tsuite,\n\t\tsuiteDir,\n\t\tsuiteJsonPath,\n\t\tagentsMdPath,\n\t\tdiagnostics: Object.freeze(diagnostics),\n\t\tlockPath,\n\t\tlock: bridge.lock,\n\t\tidentity: bridge.identity,\n\t\t...(bridge.verification === undefined ? {} : { lockVerification: bridge.verification }),\n\t};\n}\n\n// ---------------------------------------------------------------------------\n// agents.md three-level chain (设计 §8)\n// ---------------------------------------------------------------------------\n\nexport type SuiteAgentsMdSource = \"system\" | \"suite\" | \"project\";\n\nexport interface SuiteAgentsMdEntry {\n\treadonly source: SuiteAgentsMdSource;\n\treadonly path: string;\n\treadonly content: string;\n}\n\nexport interface SuiteAgentsMdAssembly {\n\treadonly chain: readonly SuiteAgentsMdEntry[];\n\treadonly diagnostics: readonly string[];\n}\n\nexport interface AssembleSuiteAgentsMdChainOptions {\n\treadonly suite: SuiteDefinition;\n\treadonly agentDir: string;\n\treadonly suiteJsonPath: string;\n\treadonly suiteAgentsMdPath: string;\n\t/**\n\t * Project-level context files exactly as produced by the existing resource\n\t * loader (`ResourceLoader.getAgentsFiles()`: agentDir global entry first,\n\t * then the AGENTS.md/CLAUDE.md ancestor chain). The ancestor chain logic is\n\t * delegated, never reimplemented; entries under agentDir are classified as\n\t * system-layer candidates.\n\t */\n\treadonly projectAgentsFiles: ReadonlyArray<{ path: string; content: string }>;\n}\n\nfunction readContextFile(path: string): string {\n\ttry {\n\t\treturn stripBom(readFileSync(path, \"utf8\"));\n\t} catch {\n\t\treturn \"\";\n\t}\n}\n\nfunction isUnderDir(path: string, dir: string): boolean {\n\tconst resolvedPath = resolve(path);\n\tconst resolvedDir = resolve(dir);\n\tconst prefix = resolvedDir.endsWith(sep) ? resolvedDir : `${resolvedDir}${sep}`;\n\treturn resolvedPath.startsWith(prefix);\n}\n\n/**\n * Assembles the agents.md three-level chain (设计 §8): system layer (the\n * agentDir context file the resource loader's agentsFiles already carries,\n * e.g. AGENTS.md, gated by inheritSystemAgentsMd) -> suite layer\n * (`suites/<id>/agents.md`) -> project layer (existing ancestor chain, passed\n * in unchanged). The global SYSTEM.md/APPEND_SYSTEM.md never ride the chain:\n * they keep their native system prompt channel and are gated there by\n * createSuiteSystemPromptGate, so both channels stay single-sourced. Every\n * entry carries its source label; missing layers are skipped. Diagnostics\n * record a blocked system layer (one-time migration hint) and the empty\n * association counts (设计 §11.3: 惰性 + 可观测).\n */\nexport function assembleSuiteAgentsMdChain(options: AssembleSuiteAgentsMdChainOptions): SuiteAgentsMdAssembly {\n\tconst { suite, agentDir, suiteJsonPath, suiteAgentsMdPath, projectAgentsFiles } = options;\n\tconst diagnostics: string[] = [];\n\n\t// System-layer candidates are the agentDir entries already present in the\n\t// loader's agentsFiles; they are never read from disk here again.\n\tconst systemCandidates = projectAgentsFiles\n\t\t.filter((entry) => isUnderDir(entry.path, agentDir))\n\t\t.map((entry) => ({ path: entry.path, content: entry.content }));\n\tconst projectEntries = projectAgentsFiles.filter((entry) => !isUnderDir(entry.path, agentDir));\n\n\tconst chain: SuiteAgentsMdEntry[] = [];\n\tif (suite.inheritSystemAgentsMd) {\n\t\tfor (const candidate of systemCandidates) {\n\t\t\tchain.push({ source: \"system\", path: candidate.path, content: candidate.content });\n\t\t}\n\t} else if (systemCandidates.length > 0) {\n\t\tdiagnostics.push(\n\t\t\t`Suite \"${suite.id}\" does not inherit the system agents.md layer (inheritSystemAgentsMd=false); system-layer file(s) kept out of the suite chain: ${systemCandidates\n\t\t\t\t.map((candidate) => candidate.path)\n\t\t\t\t.join(\n\t\t\t\t\t\", \",\n\t\t\t\t)}. Migrate them into ${suiteAgentsMdPath} or set \"inheritSystemAgentsMd\": true in ${suiteJsonPath}.`,\n\t\t);\n\t}\n\n\tchain.push({ source: \"suite\", path: suiteAgentsMdPath, content: readContextFile(suiteAgentsMdPath) });\n\tfor (const entry of projectEntries) {\n\t\tchain.push({ source: \"project\", path: entry.path, content: entry.content });\n\t}\n\n\t// Plugin associations are wired since M3 (the sdk filters the external\n\t// capability plugin pool by associations.plugins); mcp stays\n\t// declaration-only until M4.\n\tdiagnostics.push(\n\t\t`Suite \"${suite.id}\" mcp associations are declaration-only until M4; MCP association filtering is unwired.`,\n\t);\n\n\treturn { chain: Object.freeze(chain), diagnostics: Object.freeze(diagnostics) };\n}\n\n/**\n * Merges the assembled chain with the resource loader's own agentsFiles for\n * the contextFiles injection channel: chain entries are prepended unless they\n * are empty or already present in the base. Entries with empty content inject\n * nothing, so a fresh factory skeleton changes no prompt bytes. Base entries\n * under agentDir are dropped unconditionally (设计 §8): with\n * inheritSystemAgentsMd=false the switch blocks the system layer, with true\n * the chain already carries it at the head — keeping it in the base too would\n * duplicate it and pin it after the suite layer, breaking the\n * system -> suite -> project order.\n */\nexport function mergeSuiteAgentsFiles(\n\tchain: readonly SuiteAgentsMdEntry[],\n\tbase: ReadonlyArray<{ path: string; content: string }>,\n\toptions: { agentDir: string },\n): Array<{ path: string; content: string }> {\n\tconst retainedBase = base.filter((entry) => !isUnderDir(entry.path, options.agentDir));\n\tconst basePathSet = new Set(retainedBase.map((entry) => resolve(entry.path)));\n\tconst merged: Array<{ path: string; content: string }> = [];\n\tfor (const entry of chain) {\n\t\tif (entry.content.trim().length === 0) continue;\n\t\tif (basePathSet.has(resolve(entry.path))) continue;\n\t\tmerged.push({ path: entry.path, content: entry.content });\n\t}\n\tmerged.push(...retainedBase.map((entry) => ({ path: entry.path, content: entry.content })));\n\treturn merged;\n}\n\nexport interface SuiteSystemPromptGate {\n\t/** Gates the loader's main system prompt: the discovered file's content, or undefined. */\n\treadonly systemPromptOverride: (base: string | undefined) => string | undefined;\n\t/** Gates the loader's append system prompt: the discovered file's content array. */\n\treadonly appendSystemPromptOverride: (base: string[]) => string[];\n\t/** Blocked global system-layer files; filled as the overrides run, deduplicated. */\n\treadonly diagnostics: readonly string[];\n}\n\n/**\n * Gates the global SYSTEM.md/APPEND_SYSTEM.md system prompt channel by\n * inheritSystemAgentsMd (设计 §8: the switch governs the whole system layer,\n * not just the agents.md chain). The resource loader feeds both overrides with\n * the resolved content of exactly one discovered file — project-level\n * `<cwd>/.agent-forge/<name>` first, else global `<agentDir>/<name>` — with no\n * path attached, so project-level existence identifies the base origin:\n * present means the project layer, which per 设计 §4 is the third level and\n * always passes the switch; absent means a global source, which passes only\n * when the suite inherits the system layer. Blocked global files are recorded\n * in diagnostics with their paths (one-time migration hint, 设计 §11.3).\n */\nexport function createSuiteSystemPromptGate(\n\tsuite: SuiteDefinition,\n\toptions: { cwd: string; agentDir: string },\n): SuiteSystemPromptGate {\n\tconst diagnostics: string[] = [];\n\tconst passes = (filename: string): boolean => {\n\t\tconst projectPath = join(options.cwd, CONFIG_DIR_NAME, filename);\n\t\tif (existsSync(projectPath)) return true;\n\t\tif (suite.inheritSystemAgentsMd) return true;\n\t\tconst message =\n\t\t\t`Suite \"${suite.id}\" does not inherit the global system layer (inheritSystemAgentsMd=false); ` +\n\t\t\t`global file kept out of the model context: ${join(options.agentDir, filename)}. Move it to the ` +\n\t\t\t`project level (${projectPath}) or set \"inheritSystemAgentsMd\": true in the suite.json.`;\n\t\tif (!diagnostics.includes(message)) diagnostics.push(message);\n\t\treturn false;\n\t};\n\treturn {\n\t\tsystemPromptOverride: (base) => (base === undefined || passes(\"SYSTEM.md\") ? base : undefined),\n\t\tappendSystemPromptOverride: (base) => (base.length === 0 || passes(\"APPEND_SYSTEM.md\") ? base : []),\n\t\tdiagnostics,\n\t};\n}\n\n// ---------------------------------------------------------------------------\n// Association filtering (设计 §3/§4/§11.3, M1b)\n// ---------------------------------------------------------------------------\n\nexport type SuiteAssociationKind = \"skills\" | \"plugins\" | \"capabilities\";\n\nexport interface SuiteAssociationFilterResult<T> {\n\t/** Entries that pass the filter, in input order. */\n\treadonly kept: T[];\n\t/** Association names that matched no discovered entry (设计 §11.3 dangling). */\n\treadonly dangling: readonly string[];\n}\n\n/**\n * Single-sourced dangling-association diagnostic text (设计 §11.3): reported\n * through the suiteDiagnostics channel, never thrown.\n */\nexport function suiteDanglingAssociationDiagnostic(suiteId: string, kind: SuiteAssociationKind, name: string): string {\n\treturn `Suite \"${suiteId}\" dangling association \"${name}\" (${kind}): not found in the discovered registry; ignored.`;\n}\n\n/**\n * Filters the discovered skills down to the suite's skill associations (设计\n * §3: the filter lives in the assembler; discovery stays untouched). Project\n * scope (`<cwd>/.agent-forge/`) is the third layer (设计 §4) and always passes;\n * every other entry is kept only when its `Skill.name` exactly matches an\n * `associations.skills` entry. Association names that match no discovered\n * skill — including case mismatches — are reported as dangling.\n *\n * `options.localSkillsDir` is the suite-local skill layer (统一修复轮 B:\n * `<agentDir>/suites/<id>/skills`): its entries live inside the active suite\n * workspace, so suite activation is their association and they pass the filter\n * by path — the suite-local layer exemption — instead of requiring an\n * association entry.\n */\nexport function filterSuiteSkills(\n\tsuite: SuiteDefinition,\n\tskills: ReadonlyArray<Skill>,\n\toptions?: { localSkillsDir?: string },\n): SuiteAssociationFilterResult<Skill> {\n\tconst associated = new Set(suite.associations.skills);\n\tconst discovered = new Set(skills.map((skill) => skill.name));\n\tconst dangling = suite.associations.skills.filter((name) => !discovered.has(name));\n\tconst localSkillsDir = options?.localSkillsDir;\n\tconst kept = skills.filter(\n\t\t(skill) =>\n\t\t\tskill.sourceInfo.scope === \"project\" ||\n\t\t\t(localSkillsDir !== undefined && isUnderDir(skill.filePath, localSkillsDir)) ||\n\t\t\tassociated.has(skill.name),\n\t);\n\treturn { kept, dangling: Object.freeze(dangling) };\n}\n\n// ---------------------------------------------------------------------------\n// Capability plugin pool filtering (设计 §10.4, M3)\n// ---------------------------------------------------------------------------\n\n/** One external capability plugin manifest discovered below a plugin pool root. */\nexport interface SuiteCapabilityPluginCandidate {\n\t/** Exact manifest id (`PluginManifest.id`). */\n\treadonly manifestId: string;\n\t/** Resolved manifest path, as it will be reported in diagnostics. */\n\treadonly manifestPath: string;\n}\n\nexport interface SuiteCapabilityPluginDecision {\n\treadonly keep: boolean;\n\t/** Diagnostic for a filtered-out plugin; absent when the plugin passes. */\n\treadonly diagnostic?: string;\n}\n\n/**\n * Decides one external capability plugin manifest against the suite's\n * `associations.plugins` (方案设计 §10.4, M3 双键语义: associations.plugins\n * governs only the external capability plugin pool; suite.capabilities governs\n * the compiled builtin ids). The project-level pool\n * (`<cwd>/.agent-forge/plugins`) is the third layer (设计 §4) and always\n * passes; every other manifest is kept only when its id matches an\n * association exactly. Filtered plugins surface as diagnostics, never as\n * errors.\n */\nexport function decideSuiteCapabilityPlugin(\n\tsuite: SuiteDefinition,\n\tcandidate: SuiteCapabilityPluginCandidate,\n\toptions: { cwd: string },\n): SuiteCapabilityPluginDecision {\n\tif (isUnderDir(candidate.manifestPath, join(options.cwd, CONFIG_DIR_NAME, \"plugins\"))) return { keep: true };\n\tif (suite.associations.plugins.includes(candidate.manifestId)) return { keep: true };\n\treturn {\n\t\tkeep: false,\n\t\tdiagnostic: `Suite \"${suite.id}\" capability plugin \"${candidate.manifestId}\" at ${candidate.manifestPath} is not associated; not loaded.`,\n\t};\n}\n\n/**\n * Dangling `associations.plugins` entries: association ids that matched no\n * candidate capability plugin manifest (设计 §11.3), single-sourced through\n * the shared dangling diagnostic text. The caller decides what counts as a\n * candidate: the sdk assembler passes every manifest id it loads, so explicit\n * capabilityPluginPaths count toward satisfying an association even though\n * they bypass the keep filter; only manifests absent from the passed ids\n * surface as dangling.\n */\nexport function suiteDanglingPluginAssociations(\n\tsuite: SuiteDefinition,\n\tdiscoveredManifestIds: readonly string[],\n): readonly string[] {\n\tconst discovered = new Set(discoveredManifestIds);\n\treturn suite.associations.plugins\n\t\t.filter((id) => !discovered.has(id))\n\t\t.map((id) => suiteDanglingAssociationDiagnostic(suite.id, \"plugins\", id));\n}\n\n// ---------------------------------------------------------------------------\n// Shared suite loader assembly (设计 §3/§4/§8, M2)\n// ---------------------------------------------------------------------------\n\n/**\n * The DefaultResourceLoader override subset that wires a resolved suite into a\n * loader: the agents.md three-level chain, the skill/extension association\n * filters, and the inheritSystemAgentsMd gate on the global SYSTEM.md/\n * APPEND_SYSTEM.md prompt channel. Structurally compatible with the matching\n * DefaultResourceLoaderOptions fields.\n */\nexport interface SuiteLoaderOverrides {\n\tagentsFilesOverride: (base: { agentsFiles: Array<{ path: string; content: string }> }) => {\n\t\tagentsFiles: Array<{ path: string; content: string }>;\n\t};\n\tskillsOverride: (base: { skills: Skill[]; diagnostics: ResourceDiagnostic[] }) => {\n\t\tskills: Skill[];\n\t\tdiagnostics: ResourceDiagnostic[];\n\t};\n\tsystemPromptOverride: (base: string | undefined) => string | undefined;\n\tappendSystemPromptOverride: (base: string[]) => string[];\n}\n\nexport interface SuiteAssembly {\n\treadonly workspace: SuiteWorkspace;\n\t/** Optional domain plugin profile selected for this suite. */\n\treadonly pluginProfile?: BuiltinPluginProfileResolutionV1;\n\t/** Spread into DefaultResourceLoader options to wire the suite in. */\n\treadonly loaderOverrides: SuiteLoaderOverrides;\n\t/**\n\t * The suite-local skill layer directory (统一修复轮 B) when it exists on\n\t * disk; inject it into the loader's skill paths so suites/<id>/skills load\n\t * with the suite itself. Undefined when the directory is absent, so empty\n\t * and missing directories both contribute nothing.\n\t */\n\treadonly localSkillsDir?: string;\n\t/**\n\t * The suite-local capability-plugin layer directory (统一修复轮 B) when it\n\t * exists on disk; discover its manifests into the session's capability\n\t * plugin candidates. Undefined when the directory is absent.\n\t */\n\treadonly localPluginsDir?: string;\n\t/**\n\t * Snapshot of every suite assembly diagnostic collected so far — workspace\n\t * provisioning, agents.md chain, extension/skill filters, system prompt\n\t * gate, context budget — in the canonical suiteDiagnostics order. Overrides\n\t * that have not run yet contribute nothing (the budget line needs the\n\t * assembled agents.md chain).\n\t */\n\tcollectDiagnostics(): readonly string[];\n}\n\n/**\n * Single-sourced assembly-layer context budget estimate (统一修复轮 B): pure\n * chars/4 arithmetic over the assembled agents.md chain (per source layer),\n * the orientation persona text, plus the count of suite-local workspace\n * skills. Diagnostic-only: it never blocks, gates, or degrades anything.\n */\nexport function suiteContextBudgetDiagnostic(\n\tsuiteId: string,\n\tchain: ReadonlyArray<SuiteAgentsMdEntry>,\n\toptions: { personaChars: number; workspaceSkillCount: number },\n): string {\n\tconst layerChars: Record<SuiteAgentsMdSource, number> = { system: 0, suite: 0, project: 0 };\n\tfor (const entry of chain) {\n\t\tlayerChars[entry.source] += entry.content.length;\n\t}\n\tconst tokens = (chars: number): number => Math.round(chars / 4);\n\tconst system = tokens(layerChars.system);\n\tconst suiteLayer = tokens(layerChars.suite);\n\tconst project = tokens(layerChars.project);\n\treturn `Suite \"${suiteId}\" context budget: agents.md ~${system + suiteLayer + project} tok (system ${system}/suite ${suiteLayer}/project ${project}), persona ~${tokens(options.personaChars)} tok, workspace skills ${options.workspaceSkillCount}`;\n}\n\n/**\n * Plugin-profile diagnostics in the canonical suiteDiagnostics order.\n *\n * D-075 S2 soft degradation: a resolved Profile renders structured per-plugin\n * misses (e.g. `manifest_missing` for a package-distributed plugin without an\n * installed active version) as readable diagnostics, so the session keeps\n * starting without the missing plugin's tools and the miss stays visible.\n * Blocked resolutions already render every plugin diagnostic through\n * `resolution.diagnostics`; the per-plugin lines are additive for the\n * non-blocked branches only.\n */\nfunction pluginProfileDiagnosticsV1(profile: BuiltinPluginProfileResolutionV1): readonly string[] {\n\tif (profile.status === \"not_found\") return [`Plugin profile unavailable: ${profile.profileId}`];\n\tif (profile.status === \"host_facts_required\") return [`Plugin profile host facts required: ${profile.profileId}`];\n\tif (profile.status === \"invalid_selection\")\n\t\treturn [\n\t\t\t`Plugin profile invalid selection: ${profile.profileId} (unknown: ${profile.unknownPluginIds.join(\", \") || \"none\"}; duplicates: ${profile.duplicatePluginIds.join(\", \") || \"none\"})`,\n\t\t];\n\tconst pluginMisses =\n\t\tprofile.resolution.status === \"blocked\"\n\t\t\t? []\n\t\t\t: profile.resolution.plugins\n\t\t\t\t\t.filter((plugin) => plugin.status !== \"installed-ready\")\n\t\t\t\t\t.flatMap((plugin) =>\n\t\t\t\t\t\tplugin.diagnostics.map(\n\t\t\t\t\t\t\t(diagnostic) =>\n\t\t\t\t\t\t\t\t`Plugin profile plugin unavailable: ${plugin.pluginId} (${diagnostic.code}): ${diagnostic.message}`,\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\tif (profile.resolution.status === \"blocked\")\n\t\treturn profile.resolution.diagnostics.map((diagnostic) => `Plugin profile blocked: ${diagnostic.message}`);\n\tif (profile.assembly?.status === \"unverified\")\n\t\treturn [\n\t\t\t...profile.assembly.unverified.map(\n\t\t\t\t(plugin) => `Plugin profile unverified: ${plugin.pluginId}@${plugin.pluginVersion}`,\n\t\t\t),\n\t\t\t...pluginMisses,\n\t\t];\n\treturn pluginMisses;\n}\n\n/**\n * The single suite assembly used by both first-party entry paths (sdk.ts\n * self-built loader and agent-session-services `suiteAssembly`), so the two\n * cannot drift. Loads the suite workspace, builds the system prompt gate, and\n * returns the loader overrides plus a diagnostics collection channel.\n */\nexport function createSuiteAssembly(options: {\n\tcwd: string;\n\tagentDir: string;\n\tsuiteId: string;\n\tpluginProfileId?: BuiltinPluginProfileIdV1;\n\tselectedPluginIds?: readonly string[];\n\tdisabledPluginIds?: readonly string[];\n\tpluginHost?: HostFactsV1;\n\tverifiedPlugins?: readonly VerifiedToolPluginV1[];\n\t/** Explicit host-owned active installed manifests; never discovered implicitly. */\n\tmanifestOverrides?: BuiltinPluginManifestOverridesV1;\n\tpluginProfile?: BuiltinPluginProfileResolutionV1;\n}): SuiteAssembly {\n\tconst { cwd, agentDir, suiteId } = options;\n\tlet pluginProfile = options.pluginProfile;\n\tif (pluginProfile === undefined && options.pluginProfileId !== undefined) {\n\t\tpluginProfile =\n\t\t\toptions.pluginHost === undefined\n\t\t\t\t? ({ status: \"host_facts_required\", profileId: options.pluginProfileId } as const)\n\t\t\t\t: resolveBuiltinPluginProfileV1({\n\t\t\t\t\t\tprofileId: options.pluginProfileId,\n\t\t\t\t\t\tselectedPluginIds: options.selectedPluginIds,\n\t\t\t\t\t\tdisabledPluginIds: options.disabledPluginIds,\n\t\t\t\t\t\thost: options.pluginHost,\n\t\t\t\t\t\tverifiedPlugins: options.verifiedPlugins,\n\t\t\t\t\t\tmanifestOverrides: options.manifestOverrides,\n\t\t\t\t\t});\n\t}\n\tconst workspace = loadSuiteWorkspace({\n\t\tagentDir,\n\t\tsuiteId,\n\t\t...(pluginProfile === undefined ? {} : { pluginProfile }),\n\t});\n\tconst gate = createSuiteSystemPromptGate(workspace.suite, { cwd, agentDir });\n\t// Suite-local asset layer (统一修复轮 B): present directories only, so\n\t// missing and empty directories both contribute nothing.\n\tconst localSkillsDir = getSuiteLocalSkillsDir(agentDir, suiteId);\n\tconst localPluginsDir = getSuiteLocalPluginsDir(agentDir, suiteId);\n\tconst hasLocalSkillsDir = existsSync(localSkillsDir);\n\tconst hasLocalPluginsDir = existsSync(localPluginsDir);\n\tconst workspaceSkillCount = hasLocalSkillsDir\n\t\t? loadSkills({ cwd, agentDir, skillPaths: [localSkillsDir], includeDefaults: false }).skills.length\n\t\t: 0;\n\tlet chainDiagnostics: readonly string[] = [];\n\tlet skillDiagnostics: readonly string[] = [];\n\t// The assembled chain as far as the agentsFilesOverride has run; the budget\n\t// line is only honest once the real chain is known.\n\tlet assembledChain: readonly SuiteAgentsMdEntry[] | undefined;\n\t// Factory upgrade proposal (M4, 设计 §9 升级合并): an unbounded registry\n\t// resolve only proposes when the factory source wins, i.e. its revision is\n\t// strictly greater than the disk revision. Daily assembly keeps the disk\n\t// contents; adoption is an explicit --suite-reset.\n\tconst upgrade = detectSuiteFactoryUpgrade(workspace.suite);\n\tconst proposalDiagnostics = upgrade === undefined ? [] : [suiteFactoryUpgradeDiagnostic(suiteId, upgrade)];\n\tconst budgetDiagnostics = (): readonly string[] => {\n\t\tif (assembledChain === undefined) return [];\n\t\treturn [\n\t\t\tsuiteContextBudgetDiagnostic(suiteId, assembledChain, {\n\t\t\t\tpersonaChars: ORIENTATION_PROMPTS[workspace.suite.orientation].length,\n\t\t\t\tworkspaceSkillCount,\n\t\t\t}),\n\t\t];\n\t};\n\treturn {\n\t\tworkspace,\n\t\t...(pluginProfile === undefined ? {} : { pluginProfile }),\n\t\t...(hasLocalSkillsDir ? { localSkillsDir } : {}),\n\t\t...(hasLocalPluginsDir ? { localPluginsDir } : {}),\n\t\tloaderOverrides: {\n\t\t\tagentsFilesOverride: (base) => {\n\t\t\t\tconst assembly = assembleSuiteAgentsMdChain({\n\t\t\t\t\tsuite: workspace.suite,\n\t\t\t\t\tagentDir,\n\t\t\t\t\tsuiteJsonPath: workspace.suiteJsonPath,\n\t\t\t\t\tsuiteAgentsMdPath: workspace.agentsMdPath,\n\t\t\t\t\tprojectAgentsFiles: base.agentsFiles,\n\t\t\t\t});\n\t\t\t\tchainDiagnostics = assembly.diagnostics;\n\t\t\t\tassembledChain = assembly.chain;\n\t\t\t\treturn { agentsFiles: mergeSuiteAgentsFiles(assembly.chain, base.agentsFiles, { agentDir }) };\n\t\t\t},\n\t\t\tskillsOverride: (base) => {\n\t\t\t\tconst filtered = filterSuiteSkills(workspace.suite, base.skills, { localSkillsDir });\n\t\t\t\tskillDiagnostics = filtered.dangling.map((name) =>\n\t\t\t\t\tsuiteDanglingAssociationDiagnostic(suiteId, \"skills\", name),\n\t\t\t\t);\n\t\t\t\treturn { skills: filtered.kept, diagnostics: base.diagnostics };\n\t\t\t},\n\t\t\tsystemPromptOverride: gate.systemPromptOverride,\n\t\t\tappendSystemPromptOverride: gate.appendSystemPromptOverride,\n\t\t},\n\t\tcollectDiagnostics: () =>\n\t\t\tObject.freeze([\n\t\t\t\t...workspace.diagnostics,\n\t\t\t\t...(pluginProfile === undefined ? [] : pluginProfileDiagnosticsV1(pluginProfile)),\n\t\t\t\t...proposalDiagnostics,\n\t\t\t\t...chainDiagnostics,\n\t\t\t\t...skillDiagnostics,\n\t\t\t\t...budgetDiagnostics(),\n\t\t\t\t...gate.diagnostics,\n\t\t\t]),\n\t};\n}\n\n// ---------------------------------------------------------------------------\n// Session suite binding reader (设计 §10.1, 统一修复轮 B)\n// ---------------------------------------------------------------------------\n\n/**\n * Reads the suite binding recorded as session protocol data (设计 §10.1): the\n * suiteId of the latest `SUITE_SESSION_ENTRY_TYPE` custom entry. Undefined\n * when the session carries no binding — pre-suite sessions, entries without a\n * data payload, or payloads without a non-empty string suiteId.\n */\nexport function readSessionSuiteId(\n\tentries: ReadonlyArray<{ type: string; customType?: string; data?: unknown }>,\n): string | undefined {\n\treturn readSessionSuiteBinding(entries)?.suiteId;\n}\n\nexport interface SessionSuiteBindingV1 {\n\treadonly suiteId: string;\n\treadonly profileIdentity?: ProfileIdentityV1;\n}\n\nfunction sessionProfileIdentity(value: unknown): ProfileIdentityV1 | undefined {\n\tif (value === null || typeof value !== \"object\" || Array.isArray(value)) return undefined;\n\tconst record = value as Record<string, unknown>;\n\tif (\n\t\ttypeof record.profileId !== \"string\" ||\n\t\trecord.profileId.trim() === \"\" ||\n\t\ttypeof record.profileVersion !== \"string\" ||\n\t\trecord.profileVersion.trim() === \"\" ||\n\t\ttypeof record.manifestDigest !== \"string\" ||\n\t\trecord.manifestDigest.trim() === \"\" ||\n\t\t!Array.isArray(record.capabilityVersions)\n\t) {\n\t\treturn undefined;\n\t}\n\tconst capabilityVersions: { id: string; version: number }[] = [];\n\tfor (const entry of record.capabilityVersions) {\n\t\tif (entry === null || typeof entry !== \"object\" || Array.isArray(entry)) return undefined;\n\t\tconst capability = entry as Record<string, unknown>;\n\t\tif (\n\t\t\ttypeof capability.id !== \"string\" ||\n\t\t\tcapability.id.trim() === \"\" ||\n\t\t\ttypeof capability.version !== \"number\" ||\n\t\t\t!Number.isSafeInteger(capability.version) ||\n\t\t\tcapability.version < 1\n\t\t) {\n\t\t\treturn undefined;\n\t\t}\n\t\tcapabilityVersions.push({ id: capability.id, version: capability.version });\n\t}\n\treturn Object.freeze({\n\t\tprofileId: record.profileId,\n\t\tprofileVersion: record.profileVersion,\n\t\tmanifestDigest: record.manifestDigest,\n\t\tcapabilityVersions: Object.freeze(capabilityVersions) as readonly {\n\t\t\treadonly id: string;\n\t\t\treadonly version: number;\n\t\t}[],\n\t});\n}\n\n/** Reads the latest suite and optional Profile identity bound to a session. */\nexport function readSessionSuiteBinding(\n\tentries: ReadonlyArray<{ type: string; customType?: string; data?: unknown }>,\n): SessionSuiteBindingV1 | undefined {\n\tfor (let index = entries.length - 1; index >= 0; index--) {\n\t\tconst entry = entries[index];\n\t\tif (entry.type !== \"custom\" || entry.customType !== SUITE_SESSION_ENTRY_TYPE) continue;\n\t\tconst data = entry.data;\n\t\tif (data !== null && typeof data === \"object\" && !Array.isArray(data)) {\n\t\t\tconst suiteId = (data as { suiteId?: unknown }).suiteId;\n\t\t\tif (typeof suiteId === \"string\" && suiteId.length > 0) {\n\t\t\t\tconst profileIdentity = sessionProfileIdentity((data as { profileIdentity?: unknown }).profileIdentity);\n\t\t\t\treturn Object.freeze({\n\t\t\t\t\tsuiteId,\n\t\t\t\t\t...(profileIdentity === undefined ? {} : { profileIdentity }),\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t}\n\treturn undefined;\n}\n\n// ---------------------------------------------------------------------------\n// Suite -> ProfileIdentityV1 -> lock bridge (设计 §12)\n// ---------------------------------------------------------------------------\n\nfunction suiteToJsonValue(suite: SuiteDefinition): JsonValue {\n\treturn {\n\t\tschemaVersion: suite.schemaVersion,\n\t\tid: suite.id,\n\t\tname: suite.name,\n\t\tbuiltin: suite.builtin,\n\t\ttools: [...suite.tools],\n\t\tcapabilities: [...suite.capabilities],\n\t\tassociations: {\n\t\t\tskills: [...suite.associations.skills],\n\t\t\tmcp: [...suite.associations.mcp],\n\t\t\tplugins: [...suite.associations.plugins],\n\t\t},\n\t\tinheritSystemAgentsMd: suite.inheritSystemAgentsMd,\n\t\tmemory: suite.memory,\n\t\torientation: suite.orientation,\n\t\tmodel: suite.model,\n\t\tthinking: suite.thinking,\n\t\tclonedFrom: suite.clonedFrom\n\t\t\t? { id: suite.clonedFrom.id, digest: suite.clonedFrom.digest, at: suite.clonedFrom.at }\n\t\t\t: null,\n\t\t...(suite.factoryRevision === undefined ? {} : { factoryRevision: suite.factoryRevision }),\n\t};\n}\n\n/** The stable suite.json digest that rides as the suite profile manifest digest. */\nexport function suiteManifestDigest(suite: SuiteDefinition): string {\n\treturn stableJsonDigest(suiteToJsonValue(suite));\n}\n\n/**\n * Builds the ProfileIdentityV1 for an assembled suite. The identity is a pure\n * function of suite.json: the stable suite.json digest rides as the single\n * resolved \"manifest\", and the declared capabilities map to capability\n * references at version 1. No new identity/lock mechanism is introduced.\n */\nexport function buildSuiteProfileIdentity(\n\tsuite: SuiteDefinition,\n\tpluginProfile?: BuiltinPluginProfileResolutionV1,\n): ProfileIdentityV1 {\n\tconst fingerprint = suiteManifestDigest(suite);\n\tconst suiteCapabilityRefs = suite.capabilities.map((id) => ({ id, version: 1 }));\n\tconst pluginRefs =\n\t\tpluginProfile?.status === \"resolved\" && pluginProfile.resolution.status === \"ready\"\n\t\t\t? pluginProfile.resolution.resolvedManifest.plugins\n\t\t\t: [];\n\tconst capabilityRefs = [...suiteCapabilityRefs, ...pluginRefs.flatMap((plugin) => plugin.capabilityRefs)].sort(\n\t\t(left, right) => left.id.localeCompare(right.id) || left.version - right.version,\n\t);\n\treturn buildProfileIdentityV1({\n\t\tprofileId: suiteProfileId(suite.id),\n\t\tprofileVersion: `${SUITE_SCHEMA_VERSION}`,\n\t\tresolvedPlugins: [\n\t\t\t{\n\t\t\t\tpluginId: `${suite.id}/suite.json`,\n\t\t\t\tpluginVersion: fingerprint,\n\t\t\t\tcapabilityRefs: suiteCapabilityRefs,\n\t\t\t},\n\t\t\t...(pluginProfile?.status === \"resolved\" && pluginProfile.resolution.status === \"ready\"\n\t\t\t\t? [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tpluginId: `profile:${pluginProfile.profile.id}`,\n\t\t\t\t\t\t\tpluginVersion: pluginProfile.profile.version,\n\t\t\t\t\t\t\tcapabilityRefs: [],\n\t\t\t\t\t\t},\n\t\t\t\t\t\t...pluginRefs,\n\t\t\t\t\t]\n\t\t\t\t: []),\n\t\t],\n\t\tcapabilityVersions: capabilityRefs,\n\t});\n}\n\n// ---------------------------------------------------------------------------\n// ProfileRegistryV1 hookup: factory/disk sources and upgrade proposals (M4)\n// ---------------------------------------------------------------------------\n\n/** Registry profileId namespace for suites (设计 §12). */\nexport function suiteProfileId(suiteId: string): string {\n\treturn `suite:${suiteId}`;\n}\n\nexport const SUITE_FACTORY_REGISTRY_SOURCE_ID = \"suite-factory\";\nexport const SUITE_DISK_REGISTRY_SOURCE_ID = \"suite-disk\";\n/** Lower priority wins same-version ties: the disk contents beat the factory. */\nconst SUITE_FACTORY_REGISTRY_PRIORITY = 10;\nconst SUITE_DISK_REGISTRY_PRIORITY = 0;\n\n/** The effective on-disk revision: absent key means FACTORY_CONTENTS_VERSION. */\nfunction suiteDiskRevision(suite: SuiteDefinition): number {\n\treturn suite.factoryRevision ?? FACTORY_CONTENTS_VERSION;\n}\n\n/** Builds the registry entry of one suite definition (version = factoryRevision). */\nexport function buildSuiteRegistryEntry(suite: SuiteDefinition): RegistryProfileEntryV1 {\n\treturn {\n\t\tprofileId: suiteProfileId(suite.id),\n\t\tprofileVersion: String(suiteDiskRevision(suite)),\n\t\tmanifestDigest: suiteManifestDigest(suite),\n\t};\n}\n\n/** Factory source over the builtin declarations (priority 10). */\nexport function buildSuiteFactoryRegistrySource(): RegistrySourceV1 {\n\treturn {\n\t\tsourceId: SUITE_FACTORY_REGISTRY_SOURCE_ID,\n\t\tpriority: SUITE_FACTORY_REGISTRY_PRIORITY,\n\t\tprofiles: BUILTIN_SUITES.map(buildSuiteRegistryEntry),\n\t};\n}\n\n/** Disk source over workspace-effective definitions (priority 0; wins ties). */\nexport function buildSuiteDiskRegistrySource(suites: readonly SuiteDefinition[]): RegistrySourceV1 {\n\treturn {\n\t\tsourceId: SUITE_DISK_REGISTRY_SOURCE_ID,\n\t\tpriority: SUITE_DISK_REGISTRY_PRIORITY,\n\t\tprofiles: suites.map(buildSuiteRegistryEntry),\n\t};\n}\n\nexport interface SuiteFactoryUpgrade {\n\t/** Revision the factory builtin declaration carries. */\n\treadonly factoryRevision: number;\n\t/** Revision effective on disk. */\n\treadonly diskRevision: number;\n}\n\n/** Single-sourced upgrade-proposal diagnostic text (设计 §9 升级合并). */\nexport function suiteFactoryUpgradeDiagnostic(suiteId: string, upgrade: SuiteFactoryUpgrade): string {\n\treturn `Suite \"${suiteId}\": factory revision ${upgrade.factoryRevision} available (disk has ${upgrade.diskRevision}); run \"--suite-reset ${suiteId}\" to review and adopt.`;\n}\n\n/**\n * Detects a factory upgrade proposal for one disk-effective suite: an\n * unbounded registry resolve over the factory source (all builtins) plus a\n * disk source carrying exactly the effective definition. The factory source\n * wins only when its revision is strictly greater — same-version resolves\n * keep the disk contents (priority 0), so no proposal is emitted for\n * unchanged suites, and user suites (no factory entry) never resolve to the\n * factory. Pure function; the caller decides what to do with the proposal.\n */\nexport function detectSuiteFactoryUpgrade(diskSuite: SuiteDefinition): SuiteFactoryUpgrade | undefined {\n\tconst registry = createProfileRegistry();\n\tregistry.registerSource(buildSuiteFactoryRegistrySource());\n\tregistry.registerSource(buildSuiteDiskRegistrySource([diskSuite]));\n\tconst resolution = registry.resolve({ profileId: suiteProfileId(diskSuite.id) });\n\tif (resolution.status !== \"resolved\" || resolution.sourceId !== SUITE_FACTORY_REGISTRY_SOURCE_ID) {\n\t\treturn undefined;\n\t}\n\treturn {\n\t\tfactoryRevision: Number.parseInt(resolution.profileVersion, 10),\n\t\tdiskRevision: suiteDiskRevision(diskSuite),\n\t};\n}\n\nexport interface SuiteProfileLockBridge {\n\treadonly identity: ProfileIdentityV1;\n\t/**\n\t * The lock for this assembly. When a previous lock exists it is kept as-is\n\t * (a lock is never silently replaced); without one, a fresh lock freezes\n\t * the current identity.\n\t */\n\treadonly lock: ProfileLockV1;\n\treadonly verification?: ProfileLockVerificationV1;\n\t/** Drift/migration findings; recorded, never blocking in M1a (设计 §12). */\n\treadonly diagnostics: readonly string[];\n}\n\n/** Bridges an assembled suite onto the existing lock create/verify trio. */\nexport function bridgeSuiteProfileLock(options: {\n\treadonly suite: SuiteDefinition;\n\treadonly pluginProfile?: BuiltinPluginProfileResolutionV1;\n\treadonly previousLock?: ProfileLockV1;\n\treadonly lockedBy?: string;\n\treadonly now?: () => number;\n}): SuiteProfileLockBridge {\n\tconst identity = buildSuiteProfileIdentity(options.suite, options.pluginProfile);\n\tconst diagnostics: string[] = [];\n\tlet verification: ProfileLockVerificationV1 | undefined;\n\tif (options.previousLock !== undefined) {\n\t\tverification = verifyProfileLock(options.previousLock, identity);\n\t\tif (verification.status === \"drift\") {\n\t\t\t// 2026-10-01 dogfood finding: the bare drift reason left no recovery\n\t\t\t// path. Deleting the lock file and restarting rebuilds it from the\n\t\t\t// resolved manifest (loadSuiteWorkspace re-freezes a fresh lock).\n\t\t\tdiagnostics.push(\n\t\t\t\t`Suite \"${options.suite.id}\" profile lock drift: ${verification.reason}; to recover, delete <agentDir>/suites/${options.suite.id}/${SUITE_LOCK_FILENAME} and restart (the lock rebuilds from the resolved manifest)`,\n\t\t\t);\n\t\t} else if (verification.status === \"migration_required\") {\n\t\t\tdiagnostics.push(`Suite \"${options.suite.id}\" profile lock migration required: ${verification.reason}`);\n\t\t}\n\t}\n\tconst lock =\n\t\toptions.previousLock ??\n\t\tcreateProfileLock(identity, {\n\t\t\tlockedBy: options.lockedBy ?? \"suite-loader\",\n\t\t\t...(options.now === undefined ? {} : { now: options.now }),\n\t\t});\n\treturn {\n\t\tidentity,\n\t\tlock,\n\t\t...(verification === undefined ? {} : { verification }),\n\t\tdiagnostics: Object.freeze(diagnostics),\n\t};\n}\n"]}
1
+ {"version":3,"file":"suite-loader.d.ts","sourceRoot":"","sources":["../../src/profiles/suite-loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAMH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAEjE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AACnE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAEhE,OAAO,KAAK,EAAE,aAAa,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAEnF,OAAO,KAAK,EACX,gCAAgC,EAChC,wBAAwB,EACxB,gCAAgC,EAChC,MAAM,+BAA+B,CAAC;AAEvC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AAC3E,OAAO,KAAK,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAG/F,OAAO,EAEN,gBAAgB,EAQhB,KAAK,eAAe,EAEpB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,gBAAgB,EAAE,CAAC;AAE5B,eAAO,MAAM,eAAe,WAAW,CAAC;AACxC,eAAO,MAAM,uBAAuB,eAAe,CAAC;AACpD,eAAO,M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yBAAyB,CAAC;IAClD,+EAA0E;IAC1E,QAAQ,CAAC,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;CACxC;AAED,4EAA4E;AAC5E,wBAAgB,sBAAsB,CAAC,OAAO,EAAE;IAC/C,QAAQ,CAAC,KAAK,EAAE,eAAe,CAAC;IAChC,QAAQ,CAAC,aAAa,CAAC,EAAE,gCAAgC,CAAC;IAC1D,QAAQ,CAAC,YAAY,CAAC,EAAE,aAAa,CAAC;IACtC,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CAC5B,GAAG,sBAAsB,CA6BzB","sourcesContent":["/**\n * Suite workspace location, lazy provisioning, and assembly (方案系统设计.md v2\n * §4/§5/§8/§9/§11/§12, M1a).\n *\n * The loader is the assembler layer of the suite system: it resolves the\n * active suite id (explicit > AGENT_FORGE_SUITE > project settings > global\n * settings > \"assistant\"), provisions the builtin suite workspaces under\n * `<agentDir>/suites/<id>/`, assembles the agents.md three-level chain\n * (system -> suite -> project, 设计 §8), gates the global SYSTEM.md/\n * APPEND_SYSTEM.md system prompt channel by inheritSystemAgentsMd (设计 §4:\n * the project-level `<cwd>/.agent-forge/` layer always passes), and bridges\n * the assembled suite onto the existing ProfileIdentityV1/ProfileLock\n * mechanisms. The project level of the chain is delegated to the existing\n * resource loader — the ancestor chain logic itself is never reimplemented\n * here.\n */\n\nimport { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { join, resolve, sep } from \"node:path\";\nimport type { JsonValue } from \"@agent-forge/ai\";\nimport { CONFIG_DIR_NAME } from \"../config.ts\";\nimport type { ResourceDiagnostic } from \"../core/diagnostics.ts\";\nimport { t } from \"../core/i18n/index.ts\";\nimport type { SettingsManager } from \"../core/settings-manager.ts\";\nimport type { Skill } from \"../core/skills.ts\";\nimport { loadSkills } from \"../core/skills.ts\";\nimport type { HostFactsV1 } from \"../plugins/ecosystem/types.ts\";\nimport type { ProfileIdentityV1 } from \"../profile/identity.ts\";\nimport { buildProfileIdentityV1, stableJsonDigest } from \"../profile/identity.ts\";\nimport type { ProfileLockV1, ProfileLockVerificationV1 } from \"../profile/lock.ts\";\nimport { createProfileLock, verifyProfileLock } from \"../profile/lock.ts\";\nimport type {\n\tBuiltinPluginManifestOverridesV1,\n\tBuiltinPluginProfileIdV1,\n\tBuiltinPluginProfileResolutionV1,\n} from \"../profile/plugin-profiles.ts\";\nimport { resolveBuiltinPluginProfileV1 } from \"../profile/plugin-profiles.ts\";\nimport type { VerifiedToolPluginV1 } from \"../profile/profile-assembly.ts\";\nimport type { RegistryProfileEntryV1, RegistrySourceV1 } from \"../profile/profile-registry.ts\";\nimport { createProfileRegistry } from \"../profile/profile-registry.ts\";\nimport { stripBom } from \"../utils/text.ts\";\nimport {\n\tBUILTIN_SUITES,\n\tDEFAULT_SUITE_ID,\n\tFACTORY_CONTENTS_VERSION,\n\tgetBuiltinSuite,\n\tisBuiltinSuiteId,\n\tisValidSuiteId,\n\tORIENTATION_PROMPTS,\n\tparseSuiteJson,\n\tSUITE_SCHEMA_VERSION,\n\ttype SuiteDefinition,\n\tserializeSuiteJson,\n} from \"./builtin-suites.ts\";\n\nexport { DEFAULT_SUITE_ID };\n\nexport const SUITES_DIR_NAME = \"suites\";\nexport const SUITE_MANIFEST_FILENAME = \"suite.json\";\nexport const SUITE_AGENTS_MD_FILENAME = \"agents.md\";\nexport const SUITE_PERSONA_MD_FILENAME = \"persona.md\";\nexport const SUITE_ENV_VAR = \"AGENT_FORGE_SUITE\";\n/** customType of the session custom entry recording the suite a session was created with (设计 §10.1). */\nexport const SUITE_SESSION_ENTRY_TYPE = \"suite\";\n/** Persisted suite profile lock inside the suite workspace (M4, 设计 §12). */\nexport const SUITE_LOCK_FILENAME = \".profile-lock.json\";\n\nexport function getSuitesRootDir(agentDir: string): string {\n\treturn join(agentDir, SUITES_DIR_NAME);\n}\n\nexport function getSuiteWorkspaceDir(agentDir: string, suiteId: string): string {\n\treturn join(getSuitesRootDir(agentDir), suiteId);\n}\n\n/** The suite-local skill layer directory (统一修复轮 B): `<suiteDir>/skills`. */\nexport function getSuiteLocalSkillsDir(agentDir: string, suiteId: string): string {\n\treturn join(getSuiteWorkspaceDir(agentDir, suiteId), \"skills\");\n}\n\n/** The suite-local capability-plugin layer directory (统一修复轮 B): `<suiteDir>/plugins`. */\nexport function getSuiteLocalPluginsDir(agentDir: string, suiteId: string): string {\n\treturn join(getSuiteWorkspaceDir(agentDir, suiteId), \"plugins\");\n}\n\n/** Structured error for unknown suite ids; lists the available ids (设计 §9). */\nexport class SuiteResolutionError extends Error {\n\treadonly requestedId: string;\n\treadonly availableSuiteIds: readonly string[];\n\n\tconstructor(requestedId: string, availableSuiteIds: readonly string[]) {\n\t\tsuper(`Unknown suite \"${requestedId}\". Available suites: ${availableSuiteIds.join(\", \")}`);\n\t\tthis.name = \"SuiteResolutionError\";\n\t\tthis.requestedId = requestedId;\n\t\tthis.availableSuiteIds = Object.freeze([...availableSuiteIds]);\n\t}\n}\n\n/** Structured error for resuming a session under a suite it is not bound to. */\nexport class SuiteRebindError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"SuiteRebindError\";\n\t}\n}\n\n/**\n * Every suite id resolvable on this host: the builtin pair plus user\n * workspaces that already contain a suite.json.\n */\nexport function listSuiteIds(agentDir: string): string[] {\n\tconst ids = new Set(BUILTIN_SUITES.map((suite) => suite.id));\n\tconst rootDir = getSuitesRootDir(agentDir);\n\tif (existsSync(rootDir)) {\n\t\tfor (const entry of readdirSync(rootDir, { withFileTypes: true })) {\n\t\t\tif (!entry.isDirectory()) continue;\n\t\t\tif (!existsSync(join(rootDir, entry.name, SUITE_MANIFEST_FILENAME))) continue;\n\t\t\tids.add(entry.name);\n\t\t}\n\t}\n\treturn [...ids].sort();\n}\n\nexport interface ResolveSuiteIdOptions {\n\t/** Explicit suite id (SDK/CLI parameter); highest priority. */\n\texplicit?: string;\n\t/** Raw AGENT_FORGE_SUITE value; callers pass process.env[SUITE_ENV_VAR]. */\n\tenvSuite?: string;\n\t/** Settings source for the project/global `suite` keys. */\n\tsettings?: Pick<SettingsManager, \"getProjectSettings\" | \"getGlobalSettings\">;\n\t/** Agent dir used for workspace discovery and available-id listing. */\n\tagentDir: string;\n}\n\nfunction normalizeCandidate(value: unknown): string | undefined {\n\tif (typeof value !== \"string\") return undefined;\n\tconst trimmed = value.trim();\n\treturn trimmed.length > 0 ? trimmed : undefined;\n}\n\n/**\n * Resolves the active suite id: explicit > env AGENT_FORGE_SUITE > project\n * settings `suite` > global settings `suite` > \"coding\" (设计 §9). The\n * first configured value wins; an unknown or malformed value is a structured\n * error, never a silent fallback.\n */\nexport function resolveSuiteId(options: ResolveSuiteIdOptions): string {\n\tconst candidate =\n\t\tnormalizeCandidate(options.explicit) ??\n\t\tnormalizeCandidate(options.envSuite) ??\n\t\t(options.settings === undefined ? undefined : normalizeCandidate(options.settings.getProjectSettings().suite)) ??\n\t\t(options.settings === undefined ? undefined : normalizeCandidate(options.settings.getGlobalSettings().suite));\n\tif (candidate === undefined) return DEFAULT_SUITE_ID;\n\tif (!isValidSuiteId(candidate)) throw new SuiteResolutionError(candidate, listSuiteIds(options.agentDir));\n\tif (!isBuiltinSuiteId(candidate)) {\n\t\tconst workspaceManifest = join(getSuiteWorkspaceDir(options.agentDir, candidate), SUITE_MANIFEST_FILENAME);\n\t\tif (!existsSync(workspaceManifest)) throw new SuiteResolutionError(candidate, listSuiteIds(options.agentDir));\n\t}\n\treturn candidate;\n}\n\nexport interface SuiteWorkspace {\n\treadonly suite: SuiteDefinition;\n\treadonly suiteDir: string;\n\treadonly suiteJsonPath: string;\n\treadonly agentsMdPath: string;\n\t/**\n\t * The resolved orientation persona text (设计 §6.2/§6.3): the compiled\n\t * ORIENTATION_PROMPTS text for assistant/coding, the workspace persona.md\n\t * content for custom; a missing or unreadable file degrades to \"\" with a\n\t * diagnostic.\n\t */\n\treadonly orientationPersona: string;\n\treadonly diagnostics: readonly string[];\n\t/** Persisted lock file path inside the workspace (M4). */\n\treadonly lockPath: string;\n\t/**\n\t * The suite profile lock (设计 §12): the persisted lock when one existed, a\n\t * fresh lock frozen over the current identity otherwise.\n\t */\n\treadonly lock: ProfileLockV1;\n\t/** Current resolved identity, including any selected optional domain Profile. */\n\treadonly identity: ProfileIdentityV1;\n\t/** Verify result against the persisted lock; absent when none existed. */\n\treadonly lockVerification?: ProfileLockVerificationV1;\n}\n\n/**\n * Serializes a ProfileLockV1 to the canonical `.profile-lock.json` text\n * (stable field order, trailing newline). Round-trips through\n * parseSuiteProfileLockFile.\n */\nexport function serializeSuiteProfileLockFile(lock: ProfileLockV1): string {\n\tconst ordered = {\n\t\tidentity: {\n\t\t\tprofileId: lock.identity.profileId,\n\t\t\tprofileVersion: lock.identity.profileVersion,\n\t\t\tmanifestDigest: lock.identity.manifestDigest,\n\t\t\tcapabilityVersions: lock.identity.capabilityVersions.map((ref) => ({ id: ref.id, version: ref.version })),\n\t\t},\n\t\tlockedAt: lock.lockedAt,\n\t\tlockedBy: lock.lockedBy,\n\t\tgeneration: lock.generation,\n\t};\n\treturn `${JSON.stringify(ordered, null, 2)}\\n`;\n}\n\n/**\n * Parses `.profile-lock.json` text back into a ProfileLockV1. Throws on any\n * structural mismatch so callers can apply their corruption policy.\n */\nexport function parseSuiteProfileLockFile(text: string): ProfileLockV1 {\n\tconst value: unknown = JSON.parse(text);\n\tif (value === null || typeof value !== \"object\" || Array.isArray(value)) {\n\t\tthrow new Error(t(\".profile-lock.json must be a JSON object\"));\n\t}\n\tconst record = value as Record<string, unknown>;\n\tconst identityRecord = record.identity;\n\tif (identityRecord === null || typeof identityRecord !== \"object\" || Array.isArray(identityRecord)) {\n\t\tthrow new Error(t(\".profile-lock.json identity must be a JSON object\"));\n\t}\n\tconst identity = identityRecord as Record<string, unknown>;\n\tif (\n\t\ttypeof identity.profileId !== \"string\" ||\n\t\ttypeof identity.profileVersion !== \"string\" ||\n\t\ttypeof identity.manifestDigest !== \"string\" ||\n\t\t!Array.isArray(identity.capabilityVersions)\n\t) {\n\t\tthrow new Error(\n\t\t\tt(\".profile-lock.json identity must carry profileId/profileVersion/manifestDigest/capabilityVersions\"),\n\t\t);\n\t}\n\tconst capabilityVersions = identity.capabilityVersions.map((entry) => {\n\t\tif (entry === null || typeof entry !== \"object\" || Array.isArray(entry)) {\n\t\t\tthrow new Error(t(\".profile-lock.json identity.capabilityVersions entries must be objects\"));\n\t\t}\n\t\tconst capability = entry as Record<string, unknown>;\n\t\tif (typeof capability.id !== \"string\" || typeof capability.version !== \"number\") {\n\t\t\tthrow new Error(t(\".profile-lock.json identity.capabilityVersions entries must carry id/version\"));\n\t\t}\n\t\treturn { id: capability.id, version: capability.version };\n\t});\n\tif (\n\t\ttypeof record.lockedAt !== \"number\" ||\n\t\ttypeof record.lockedBy !== \"string\" ||\n\t\ttypeof record.generation !== \"number\"\n\t) {\n\t\tthrow new Error(t(\".profile-lock.json must carry lockedAt/lockedBy/generation\"));\n\t}\n\treturn Object.freeze({\n\t\tidentity: Object.freeze({\n\t\t\tprofileId: identity.profileId,\n\t\t\tprofileVersion: identity.profileVersion,\n\t\t\tmanifestDigest: identity.manifestDigest,\n\t\t\tcapabilityVersions: Object.freeze(capabilityVersions.map((ref) => Object.freeze({ ...ref }))),\n\t\t}),\n\t\tlockedAt: record.lockedAt,\n\t\tlockedBy: record.lockedBy,\n\t\tgeneration: record.generation,\n\t});\n}\n\n/**\n * Locates and lazily provisions `<agentDir>/suites/<id>/`: the builtin pair\n * gets its factory suite.json plus an empty agents.md skeleton on first start\n * (设计 §5). Corruption policy (设计 §9): builtin suites fall back to factory\n * content with diagnostics; user suites fail fast with the file path.\n */\nexport function loadSuiteWorkspace(options: {\n\tagentDir: string;\n\tsuiteId: string;\n\tpluginProfile?: BuiltinPluginProfileResolutionV1;\n}): SuiteWorkspace {\n\tconst { agentDir, suiteId } = options;\n\tconst suiteDir = getSuiteWorkspaceDir(agentDir, suiteId);\n\tconst suiteJsonPath = join(suiteDir, SUITE_MANIFEST_FILENAME);\n\tconst agentsMdPath = join(suiteDir, SUITE_AGENTS_MD_FILENAME);\n\tconst diagnostics: string[] = [];\n\n\tlet suite: SuiteDefinition;\n\tif (!existsSync(suiteJsonPath)) {\n\t\tconst builtin = getBuiltinSuite(suiteId);\n\t\tif (builtin === undefined) throw new SuiteResolutionError(suiteId, listSuiteIds(agentDir));\n\t\tmkdirSync(suiteDir, { recursive: true });\n\t\twriteFileSync(suiteJsonPath, serializeSuiteJson(builtin), \"utf8\");\n\t\t// D-075 S4 第三批:首启不再预种角色文件——种子移到 subagent-delegate 插件\n\t\t// 注册期(entry 的幂等 seedFactoryRoleCatalog 补缺),插件安装并注册时\n\t\t// `<agentDir>/roles/{explore,reviewer}.json` 自然到位。\n\t\tsuite = builtin;\n\t} else {\n\t\tconst parsed = parseSuiteJson(readFileSync(suiteJsonPath, \"utf8\"), {\n\t\t\texpectedBuiltin: getBuiltinSuite(suiteId) !== undefined,\n\t\t\texpectedId: suiteId,\n\t\t});\n\t\tconst builtin = getBuiltinSuite(suiteId);\n\t\tif (parsed.valid && parsed.suite) {\n\t\t\tsuite = parsed.suite;\n\t\t} else if (builtin !== undefined) {\n\t\t\t// Builtin corruption policy (设计 §9): fall back to factory content\n\t\t\t// with diagnostics instead of locking the user out. The file on disk\n\t\t\t// is left untouched; recovery (reset) is an explicit M4 flow.\n\t\t\tsuite = builtin;\n\t\t\tdiagnostics.push(\n\t\t\t\t`suite.json at ${suiteJsonPath} is invalid; falling back to the factory content for builtin suite \"${suiteId}\". Errors: ${parsed.errors.join(\"; \")}`,\n\t\t\t);\n\t\t} else {\n\t\t\tthrow new Error(\n\t\t\t\tt(\n\t\t\t\t\t\"Invalid suite.json at {path}: {errors}. Fix the file, or delete the suite workspace directory {dir} and recreate it.\",\n\t\t\t\t\t{ path: suiteJsonPath, errors: parsed.errors.join(\"; \"), dir: suiteDir },\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\t}\n\n\tif (!existsSync(agentsMdPath)) {\n\t\twriteFileSync(agentsMdPath, \"\", \"utf8\");\n\t}\n\n\t// Suite profile lock persistence (M4, 设计 §12): an existing lock file is\n\t// verified against the current identity (drift/migration recorded, never\n\t// blocking and never silently replaced); without one a fresh lock is frozen\n\t// and persisted. A lock file that cannot be parsed is recreated with a\n\t// diagnostic — it carries no openable identity, so nothing is silently\n\t// replaced.\n\tconst lockPath = join(suiteDir, SUITE_LOCK_FILENAME);\n\tlet previousLock: ProfileLockV1 | undefined;\n\tif (existsSync(lockPath)) {\n\t\ttry {\n\t\t\tpreviousLock = parseSuiteProfileLockFile(readFileSync(lockPath, \"utf8\"));\n\t\t} catch (error) {\n\t\t\tdiagnostics.push(\n\t\t\t\t`Profile lock at ${lockPath} is unreadable; recreating it over the current suite identity. Errors: ${\n\t\t\t\t\terror instanceof Error ? error.message : String(error)\n\t\t\t\t}`,\n\t\t\t);\n\t\t}\n\t}\n\tconst bridge = bridgeSuiteProfileLock({\n\t\tsuite,\n\t\t...(options.pluginProfile === undefined ? {} : { pluginProfile: options.pluginProfile }),\n\t\t...(previousLock === undefined ? {} : { previousLock }),\n\t\tlockedBy: \"suite-loader\",\n\t});\n\tdiagnostics.push(...bridge.diagnostics);\n\tif (previousLock === undefined) {\n\t\ttry {\n\t\t\twriteFileSync(lockPath, serializeSuiteProfileLockFile(bridge.lock), \"utf8\");\n\t\t} catch (error) {\n\t\t\tdiagnostics.push(\n\t\t\t\t`Failed to persist the suite profile lock at ${lockPath}: ${\n\t\t\t\t\terror instanceof Error ? error.message : String(error)\n\t\t\t\t}`,\n\t\t\t);\n\t\t}\n\t}\n\n\t// Orientation persona resolution (设计 §6.3): assistant/coding use the\n\t// compiled persona texts; custom reads the workspace persona.md verbatim\n\t// (BOM stripped, never trimmed), degrading to an empty persona with a\n\t// diagnostic instead of silently falling back to a builtin persona.\n\tconst personaPath = join(suiteDir, SUITE_PERSONA_MD_FILENAME);\n\tlet orientationPersona: string;\n\tif (suite.orientation !== \"custom\") {\n\t\torientationPersona = ORIENTATION_PROMPTS[suite.orientation];\n\t} else if (!existsSync(personaPath)) {\n\t\torientationPersona = \"\";\n\t\tdiagnostics.push(\n\t\t\t`Suite \"${suiteId}\" orientation is \"custom\" but ${personaPath} is missing; the orientation prompt stays empty until the file is created`,\n\t\t);\n\t} else {\n\t\ttry {\n\t\t\torientationPersona = stripBom(readFileSync(personaPath, \"utf8\"));\n\t\t} catch (error) {\n\t\t\torientationPersona = \"\";\n\t\t\tdiagnostics.push(\n\t\t\t\t`Persona file at ${personaPath} is unreadable; the orientation prompt stays empty. Errors: ${\n\t\t\t\t\terror instanceof Error ? error.message : String(error)\n\t\t\t\t}`,\n\t\t\t);\n\t\t}\n\t}\n\n\treturn {\n\t\tsuite,\n\t\tsuiteDir,\n\t\tsuiteJsonPath,\n\t\tagentsMdPath,\n\t\torientationPersona,\n\t\tdiagnostics: Object.freeze(diagnostics),\n\t\tlockPath,\n\t\tlock: bridge.lock,\n\t\tidentity: bridge.identity,\n\t\t...(bridge.verification === undefined ? {} : { lockVerification: bridge.verification }),\n\t};\n}\n\n// ---------------------------------------------------------------------------\n// agents.md three-level chain (设计 §8)\n// ---------------------------------------------------------------------------\n\nexport type SuiteAgentsMdSource = \"system\" | \"suite\" | \"project\";\n\nexport interface SuiteAgentsMdEntry {\n\treadonly source: SuiteAgentsMdSource;\n\treadonly path: string;\n\treadonly content: string;\n}\n\nexport interface SuiteAgentsMdAssembly {\n\treadonly chain: readonly SuiteAgentsMdEntry[];\n\treadonly diagnostics: readonly string[];\n}\n\nexport interface AssembleSuiteAgentsMdChainOptions {\n\treadonly suite: SuiteDefinition;\n\treadonly agentDir: string;\n\treadonly suiteJsonPath: string;\n\treadonly suiteAgentsMdPath: string;\n\t/**\n\t * Project-level context files exactly as produced by the existing resource\n\t * loader (`ResourceLoader.getAgentsFiles()`: agentDir global entry first,\n\t * then the AGENTS.md/CLAUDE.md ancestor chain). The ancestor chain logic is\n\t * delegated, never reimplemented; entries under agentDir are classified as\n\t * system-layer candidates.\n\t */\n\treadonly projectAgentsFiles: ReadonlyArray<{ path: string; content: string }>;\n}\n\nfunction readContextFile(path: string): string {\n\ttry {\n\t\treturn stripBom(readFileSync(path, \"utf8\"));\n\t} catch {\n\t\treturn \"\";\n\t}\n}\n\nfunction isUnderDir(path: string, dir: string): boolean {\n\tconst resolvedPath = resolve(path);\n\tconst resolvedDir = resolve(dir);\n\tconst prefix = resolvedDir.endsWith(sep) ? resolvedDir : `${resolvedDir}${sep}`;\n\treturn resolvedPath.startsWith(prefix);\n}\n\n/**\n * Assembles the agents.md three-level chain (设计 §8): system layer (the\n * agentDir context file the resource loader's agentsFiles already carries,\n * e.g. AGENTS.md, gated by inheritSystemAgentsMd) -> suite layer\n * (`suites/<id>/agents.md`) -> project layer (existing ancestor chain, passed\n * in unchanged). The global SYSTEM.md/APPEND_SYSTEM.md never ride the chain:\n * they keep their native system prompt channel and are gated there by\n * createSuiteSystemPromptGate, so both channels stay single-sourced. Every\n * entry carries its source label; missing layers are skipped. Diagnostics\n * record a blocked system layer (one-time migration hint) and the empty\n * association counts (设计 §11.3: 惰性 + 可观测).\n */\nexport function assembleSuiteAgentsMdChain(options: AssembleSuiteAgentsMdChainOptions): SuiteAgentsMdAssembly {\n\tconst { suite, agentDir, suiteJsonPath, suiteAgentsMdPath, projectAgentsFiles } = options;\n\tconst diagnostics: string[] = [];\n\n\t// System-layer candidates are the agentDir entries already present in the\n\t// loader's agentsFiles; they are never read from disk here again.\n\tconst systemCandidates = projectAgentsFiles\n\t\t.filter((entry) => isUnderDir(entry.path, agentDir))\n\t\t.map((entry) => ({ path: entry.path, content: entry.content }));\n\tconst projectEntries = projectAgentsFiles.filter((entry) => !isUnderDir(entry.path, agentDir));\n\n\tconst chain: SuiteAgentsMdEntry[] = [];\n\tif (suite.inheritSystemAgentsMd) {\n\t\tfor (const candidate of systemCandidates) {\n\t\t\tchain.push({ source: \"system\", path: candidate.path, content: candidate.content });\n\t\t}\n\t} else if (systemCandidates.length > 0) {\n\t\tdiagnostics.push(\n\t\t\t`Suite \"${suite.id}\" does not inherit the system agents.md layer (inheritSystemAgentsMd=false); system-layer file(s) kept out of the suite chain: ${systemCandidates\n\t\t\t\t.map((candidate) => candidate.path)\n\t\t\t\t.join(\n\t\t\t\t\t\", \",\n\t\t\t\t)}. Migrate them into ${suiteAgentsMdPath} or set \"inheritSystemAgentsMd\": true in ${suiteJsonPath}.`,\n\t\t);\n\t}\n\n\tchain.push({ source: \"suite\", path: suiteAgentsMdPath, content: readContextFile(suiteAgentsMdPath) });\n\tfor (const entry of projectEntries) {\n\t\tchain.push({ source: \"project\", path: entry.path, content: entry.content });\n\t}\n\n\t// Plugin associations are wired since M3 (the sdk filters the external\n\t// capability plugin pool by associations.plugins); mcp stays\n\t// declaration-only until M4.\n\tdiagnostics.push(\n\t\t`Suite \"${suite.id}\" mcp associations are declaration-only until M4; MCP association filtering is unwired.`,\n\t);\n\n\treturn { chain: Object.freeze(chain), diagnostics: Object.freeze(diagnostics) };\n}\n\n/**\n * Merges the assembled chain with the resource loader's own agentsFiles for\n * the contextFiles injection channel: chain entries are prepended unless they\n * are empty or already present in the base. Entries with empty content inject\n * nothing, so a fresh factory skeleton changes no prompt bytes. Base entries\n * under agentDir are dropped unconditionally (设计 §8): with\n * inheritSystemAgentsMd=false the switch blocks the system layer, with true\n * the chain already carries it at the head — keeping it in the base too would\n * duplicate it and pin it after the suite layer, breaking the\n * system -> suite -> project order.\n */\nexport function mergeSuiteAgentsFiles(\n\tchain: readonly SuiteAgentsMdEntry[],\n\tbase: ReadonlyArray<{ path: string; content: string }>,\n\toptions: { agentDir: string },\n): Array<{ path: string; content: string }> {\n\tconst retainedBase = base.filter((entry) => !isUnderDir(entry.path, options.agentDir));\n\tconst basePathSet = new Set(retainedBase.map((entry) => resolve(entry.path)));\n\tconst merged: Array<{ path: string; content: string }> = [];\n\tfor (const entry of chain) {\n\t\tif (entry.content.trim().length === 0) continue;\n\t\tif (basePathSet.has(resolve(entry.path))) continue;\n\t\tmerged.push({ path: entry.path, content: entry.content });\n\t}\n\tmerged.push(...retainedBase.map((entry) => ({ path: entry.path, content: entry.content })));\n\treturn merged;\n}\n\nexport interface SuiteSystemPromptGate {\n\t/** Gates the loader's main system prompt: the discovered file's content, or undefined. */\n\treadonly systemPromptOverride: (base: string | undefined) => string | undefined;\n\t/** Gates the loader's append system prompt: the discovered file's content array. */\n\treadonly appendSystemPromptOverride: (base: string[]) => string[];\n\t/** Blocked global system-layer files; filled as the overrides run, deduplicated. */\n\treadonly diagnostics: readonly string[];\n}\n\n/**\n * Gates the global SYSTEM.md/APPEND_SYSTEM.md system prompt channel by\n * inheritSystemAgentsMd (设计 §8: the switch governs the whole system layer,\n * not just the agents.md chain). The resource loader feeds both overrides with\n * the resolved content of exactly one discovered file — project-level\n * `<cwd>/.agent-forge/<name>` first, else global `<agentDir>/<name>` — with no\n * path attached, so project-level existence identifies the base origin:\n * present means the project layer, which per 设计 §4 is the third level and\n * always passes the switch; absent means a global source, which passes only\n * when the suite inherits the system layer. Blocked global files are recorded\n * in diagnostics with their paths (one-time migration hint, 设计 §11.3).\n */\nexport function createSuiteSystemPromptGate(\n\tsuite: SuiteDefinition,\n\toptions: { cwd: string; agentDir: string },\n): SuiteSystemPromptGate {\n\tconst diagnostics: string[] = [];\n\tconst passes = (filename: string): boolean => {\n\t\tconst projectPath = join(options.cwd, CONFIG_DIR_NAME, filename);\n\t\tif (existsSync(projectPath)) return true;\n\t\tif (suite.inheritSystemAgentsMd) return true;\n\t\tconst message =\n\t\t\t`Suite \"${suite.id}\" does not inherit the global system layer (inheritSystemAgentsMd=false); ` +\n\t\t\t`global file kept out of the model context: ${join(options.agentDir, filename)}. Move it to the ` +\n\t\t\t`project level (${projectPath}) or set \"inheritSystemAgentsMd\": true in the suite.json.`;\n\t\tif (!diagnostics.includes(message)) diagnostics.push(message);\n\t\treturn false;\n\t};\n\treturn {\n\t\tsystemPromptOverride: (base) => (base === undefined || passes(\"SYSTEM.md\") ? base : undefined),\n\t\tappendSystemPromptOverride: (base) => (base.length === 0 || passes(\"APPEND_SYSTEM.md\") ? base : []),\n\t\tdiagnostics,\n\t};\n}\n\n// ---------------------------------------------------------------------------\n// Association filtering (设计 §3/§4/§11.3, M1b)\n// ---------------------------------------------------------------------------\n\nexport type SuiteAssociationKind = \"skills\" | \"plugins\" | \"capabilities\";\n\nexport interface SuiteAssociationFilterResult<T> {\n\t/** Entries that pass the filter, in input order. */\n\treadonly kept: T[];\n\t/** Association names that matched no discovered entry (设计 §11.3 dangling). */\n\treadonly dangling: readonly string[];\n}\n\n/**\n * Single-sourced dangling-association diagnostic text (设计 §11.3): reported\n * through the suiteDiagnostics channel, never thrown.\n */\nexport function suiteDanglingAssociationDiagnostic(suiteId: string, kind: SuiteAssociationKind, name: string): string {\n\treturn `Suite \"${suiteId}\" dangling association \"${name}\" (${kind}): not found in the discovered registry; ignored.`;\n}\n\n/**\n * Filters the discovered skills down to the suite's skill associations (设计\n * §3: the filter lives in the assembler; discovery stays untouched). Project\n * scope (`<cwd>/.agent-forge/`) is the third layer (设计 §4) and always passes;\n * every other entry is kept only when its `Skill.name` exactly matches an\n * `associations.skills` entry. Association names that match no discovered\n * skill — including case mismatches — are reported as dangling.\n *\n * `options.localSkillsDir` is the suite-local skill layer (统一修复轮 B:\n * `<agentDir>/suites/<id>/skills`): its entries live inside the active suite\n * workspace, so suite activation is their association and they pass the filter\n * by path — the suite-local layer exemption — instead of requiring an\n * association entry.\n */\nexport function filterSuiteSkills(\n\tsuite: SuiteDefinition,\n\tskills: ReadonlyArray<Skill>,\n\toptions?: { localSkillsDir?: string },\n): SuiteAssociationFilterResult<Skill> {\n\tconst associated = new Set(suite.associations.skills);\n\tconst discovered = new Set(skills.map((skill) => skill.name));\n\tconst dangling = suite.associations.skills.filter((name) => !discovered.has(name));\n\tconst localSkillsDir = options?.localSkillsDir;\n\tconst kept = skills.filter(\n\t\t(skill) =>\n\t\t\tskill.sourceInfo.scope === \"project\" ||\n\t\t\t(localSkillsDir !== undefined && isUnderDir(skill.filePath, localSkillsDir)) ||\n\t\t\tassociated.has(skill.name),\n\t);\n\treturn { kept, dangling: Object.freeze(dangling) };\n}\n\n// ---------------------------------------------------------------------------\n// Capability plugin pool filtering (设计 §10.4, M3)\n// ---------------------------------------------------------------------------\n\n/** One external capability plugin manifest discovered below a plugin pool root. */\nexport interface SuiteCapabilityPluginCandidate {\n\t/** Exact manifest id (`PluginManifest.id`). */\n\treadonly manifestId: string;\n\t/** Resolved manifest path, as it will be reported in diagnostics. */\n\treadonly manifestPath: string;\n}\n\nexport interface SuiteCapabilityPluginDecision {\n\treadonly keep: boolean;\n\t/** Diagnostic for a filtered-out plugin; absent when the plugin passes. */\n\treadonly diagnostic?: string;\n}\n\n/**\n * Decides one external capability plugin manifest against the suite's\n * `associations.plugins` (方案设计 §10.4, M3 双键语义: associations.plugins\n * governs only the external capability plugin pool; suite.capabilities governs\n * the compiled builtin ids). The project-level pool\n * (`<cwd>/.agent-forge/plugins`) is the third layer (设计 §4) and always\n * passes; every other manifest is kept only when its id matches an\n * association exactly. Filtered plugins surface as diagnostics, never as\n * errors.\n */\nexport function decideSuiteCapabilityPlugin(\n\tsuite: SuiteDefinition,\n\tcandidate: SuiteCapabilityPluginCandidate,\n\toptions: { cwd: string },\n): SuiteCapabilityPluginDecision {\n\tif (isUnderDir(candidate.manifestPath, join(options.cwd, CONFIG_DIR_NAME, \"plugins\"))) return { keep: true };\n\tif (suite.associations.plugins.includes(candidate.manifestId)) return { keep: true };\n\treturn {\n\t\tkeep: false,\n\t\tdiagnostic: `Suite \"${suite.id}\" capability plugin \"${candidate.manifestId}\" at ${candidate.manifestPath} is not associated; not loaded.`,\n\t};\n}\n\n/**\n * Dangling `associations.plugins` entries: association ids that matched no\n * candidate capability plugin manifest (设计 §11.3), single-sourced through\n * the shared dangling diagnostic text. The caller decides what counts as a\n * candidate: the sdk assembler passes every manifest id it loads, so explicit\n * capabilityPluginPaths count toward satisfying an association even though\n * they bypass the keep filter; only manifests absent from the passed ids\n * surface as dangling.\n */\nexport function suiteDanglingPluginAssociations(\n\tsuite: SuiteDefinition,\n\tdiscoveredManifestIds: readonly string[],\n): readonly string[] {\n\tconst discovered = new Set(discoveredManifestIds);\n\treturn suite.associations.plugins\n\t\t.filter((id) => !discovered.has(id))\n\t\t.map((id) => suiteDanglingAssociationDiagnostic(suite.id, \"plugins\", id));\n}\n\n// ---------------------------------------------------------------------------\n// Shared suite loader assembly (设计 §3/§4/§8, M2)\n// ---------------------------------------------------------------------------\n\n/**\n * The DefaultResourceLoader override subset that wires a resolved suite into a\n * loader: the agents.md three-level chain, the skill/extension association\n * filters, and the inheritSystemAgentsMd gate on the global SYSTEM.md/\n * APPEND_SYSTEM.md prompt channel. Structurally compatible with the matching\n * DefaultResourceLoaderOptions fields.\n */\nexport interface SuiteLoaderOverrides {\n\tagentsFilesOverride: (base: { agentsFiles: Array<{ path: string; content: string }> }) => {\n\t\tagentsFiles: Array<{ path: string; content: string }>;\n\t};\n\tskillsOverride: (base: { skills: Skill[]; diagnostics: ResourceDiagnostic[] }) => {\n\t\tskills: Skill[];\n\t\tdiagnostics: ResourceDiagnostic[];\n\t};\n\tsystemPromptOverride: (base: string | undefined) => string | undefined;\n\tappendSystemPromptOverride: (base: string[]) => string[];\n}\n\nexport interface SuiteAssembly {\n\treadonly workspace: SuiteWorkspace;\n\t/** Optional domain plugin profile selected for this suite. */\n\treadonly pluginProfile?: BuiltinPluginProfileResolutionV1;\n\t/** Spread into DefaultResourceLoader options to wire the suite in. */\n\treadonly loaderOverrides: SuiteLoaderOverrides;\n\t/**\n\t * The suite-local skill layer directory (统一修复轮 B) when it exists on\n\t * disk; inject it into the loader's skill paths so suites/<id>/skills load\n\t * with the suite itself. Undefined when the directory is absent, so empty\n\t * and missing directories both contribute nothing.\n\t */\n\treadonly localSkillsDir?: string;\n\t/**\n\t * The suite-local capability-plugin layer directory (统一修复轮 B) when it\n\t * exists on disk; discover its manifests into the session's capability\n\t * plugin candidates. Undefined when the directory is absent.\n\t */\n\treadonly localPluginsDir?: string;\n\t/**\n\t * Snapshot of every suite assembly diagnostic collected so far — workspace\n\t * provisioning, agents.md chain, extension/skill filters, system prompt\n\t * gate, context budget — in the canonical suiteDiagnostics order. Overrides\n\t * that have not run yet contribute nothing (the budget line needs the\n\t * assembled agents.md chain).\n\t */\n\tcollectDiagnostics(): readonly string[];\n}\n\n/**\n * Single-sourced assembly-layer context budget estimate (统一修复轮 B): pure\n * chars/4 arithmetic over the assembled agents.md chain (per source layer),\n * the orientation persona text, plus the count of suite-local workspace\n * skills. Diagnostic-only: it never blocks, gates, or degrades anything.\n */\nexport function suiteContextBudgetDiagnostic(\n\tsuiteId: string,\n\tchain: ReadonlyArray<SuiteAgentsMdEntry>,\n\toptions: { personaChars: number; workspaceSkillCount: number },\n): string {\n\tconst layerChars: Record<SuiteAgentsMdSource, number> = { system: 0, suite: 0, project: 0 };\n\tfor (const entry of chain) {\n\t\tlayerChars[entry.source] += entry.content.length;\n\t}\n\tconst tokens = (chars: number): number => Math.round(chars / 4);\n\tconst system = tokens(layerChars.system);\n\tconst suiteLayer = tokens(layerChars.suite);\n\tconst project = tokens(layerChars.project);\n\treturn `Suite \"${suiteId}\" context budget: agents.md ~${system + suiteLayer + project} tok (system ${system}/suite ${suiteLayer}/project ${project}), persona ~${tokens(options.personaChars)} tok, workspace skills ${options.workspaceSkillCount}`;\n}\n\n/**\n * Plugin-profile diagnostics in the canonical suiteDiagnostics order.\n *\n * D-075 S2 soft degradation: a resolved Profile renders structured per-plugin\n * misses (e.g. `manifest_missing` for a package-distributed plugin without an\n * installed active version) as readable diagnostics, so the session keeps\n * starting without the missing plugin's tools and the miss stays visible.\n * Blocked resolutions already render every plugin diagnostic through\n * `resolution.diagnostics`; the per-plugin lines are additive for the\n * non-blocked branches only.\n */\nfunction pluginProfileDiagnosticsV1(profile: BuiltinPluginProfileResolutionV1): readonly string[] {\n\tif (profile.status === \"not_found\") return [`Plugin profile unavailable: ${profile.profileId}`];\n\tif (profile.status === \"host_facts_required\") return [`Plugin profile host facts required: ${profile.profileId}`];\n\tif (profile.status === \"invalid_selection\")\n\t\treturn [\n\t\t\t`Plugin profile invalid selection: ${profile.profileId} (unknown: ${profile.unknownPluginIds.join(\", \") || \"none\"}; duplicates: ${profile.duplicatePluginIds.join(\", \") || \"none\"})`,\n\t\t];\n\tconst pluginMisses =\n\t\tprofile.resolution.status === \"blocked\"\n\t\t\t? []\n\t\t\t: profile.resolution.plugins\n\t\t\t\t\t.filter((plugin) => plugin.status !== \"installed-ready\")\n\t\t\t\t\t.flatMap((plugin) =>\n\t\t\t\t\t\tplugin.diagnostics.map(\n\t\t\t\t\t\t\t(diagnostic) =>\n\t\t\t\t\t\t\t\t`Plugin profile plugin unavailable: ${plugin.pluginId} (${diagnostic.code}): ${diagnostic.message}`,\n\t\t\t\t\t\t),\n\t\t\t\t\t);\n\tif (profile.resolution.status === \"blocked\")\n\t\treturn profile.resolution.diagnostics.map((diagnostic) => `Plugin profile blocked: ${diagnostic.message}`);\n\tif (profile.assembly?.status === \"unverified\")\n\t\treturn [\n\t\t\t...profile.assembly.unverified.map(\n\t\t\t\t(plugin) => `Plugin profile unverified: ${plugin.pluginId}@${plugin.pluginVersion}`,\n\t\t\t),\n\t\t\t...pluginMisses,\n\t\t];\n\treturn pluginMisses;\n}\n\n/**\n * The single suite assembly used by both first-party entry paths (sdk.ts\n * self-built loader and agent-session-services `suiteAssembly`), so the two\n * cannot drift. Loads the suite workspace, builds the system prompt gate, and\n * returns the loader overrides plus a diagnostics collection channel.\n */\nexport function createSuiteAssembly(options: {\n\tcwd: string;\n\tagentDir: string;\n\tsuiteId: string;\n\tpluginProfileId?: BuiltinPluginProfileIdV1;\n\tselectedPluginIds?: readonly string[];\n\tdisabledPluginIds?: readonly string[];\n\tpluginHost?: HostFactsV1;\n\tverifiedPlugins?: readonly VerifiedToolPluginV1[];\n\t/** Explicit host-owned active installed manifests; never discovered implicitly. */\n\tmanifestOverrides?: BuiltinPluginManifestOverridesV1;\n\tpluginProfile?: BuiltinPluginProfileResolutionV1;\n}): SuiteAssembly {\n\tconst { cwd, agentDir, suiteId } = options;\n\tlet pluginProfile = options.pluginProfile;\n\tif (pluginProfile === undefined && options.pluginProfileId !== undefined) {\n\t\tpluginProfile =\n\t\t\toptions.pluginHost === undefined\n\t\t\t\t? ({ status: \"host_facts_required\", profileId: options.pluginProfileId } as const)\n\t\t\t\t: resolveBuiltinPluginProfileV1({\n\t\t\t\t\t\tprofileId: options.pluginProfileId,\n\t\t\t\t\t\tselectedPluginIds: options.selectedPluginIds,\n\t\t\t\t\t\tdisabledPluginIds: options.disabledPluginIds,\n\t\t\t\t\t\thost: options.pluginHost,\n\t\t\t\t\t\tverifiedPlugins: options.verifiedPlugins,\n\t\t\t\t\t\tmanifestOverrides: options.manifestOverrides,\n\t\t\t\t\t});\n\t}\n\tconst workspace = loadSuiteWorkspace({\n\t\tagentDir,\n\t\tsuiteId,\n\t\t...(pluginProfile === undefined ? {} : { pluginProfile }),\n\t});\n\tconst gate = createSuiteSystemPromptGate(workspace.suite, { cwd, agentDir });\n\t// Suite-local asset layer (统一修复轮 B): present directories only, so\n\t// missing and empty directories both contribute nothing.\n\tconst localSkillsDir = getSuiteLocalSkillsDir(agentDir, suiteId);\n\tconst localPluginsDir = getSuiteLocalPluginsDir(agentDir, suiteId);\n\tconst hasLocalSkillsDir = existsSync(localSkillsDir);\n\tconst hasLocalPluginsDir = existsSync(localPluginsDir);\n\tconst workspaceSkillCount = hasLocalSkillsDir\n\t\t? loadSkills({ cwd, agentDir, skillPaths: [localSkillsDir], includeDefaults: false }).skills.length\n\t\t: 0;\n\tlet chainDiagnostics: readonly string[] = [];\n\tlet skillDiagnostics: readonly string[] = [];\n\t// The assembled chain as far as the agentsFilesOverride has run; the budget\n\t// line is only honest once the real chain is known.\n\tlet assembledChain: readonly SuiteAgentsMdEntry[] | undefined;\n\t// Factory upgrade proposal (M4, 设计 §9 升级合并): an unbounded registry\n\t// resolve only proposes when the factory source wins, i.e. its revision is\n\t// strictly greater than the disk revision. Daily assembly keeps the disk\n\t// contents; adoption is an explicit --suite-reset.\n\tconst upgrade = detectSuiteFactoryUpgrade(workspace.suite);\n\tconst proposalDiagnostics = upgrade === undefined ? [] : [suiteFactoryUpgradeDiagnostic(suiteId, upgrade)];\n\tconst budgetDiagnostics = (): readonly string[] => {\n\t\tif (assembledChain === undefined) return [];\n\t\treturn [\n\t\t\tsuiteContextBudgetDiagnostic(suiteId, assembledChain, {\n\t\t\t\tpersonaChars: workspace.orientationPersona.length,\n\t\t\t\tworkspaceSkillCount,\n\t\t\t}),\n\t\t];\n\t};\n\treturn {\n\t\tworkspace,\n\t\t...(pluginProfile === undefined ? {} : { pluginProfile }),\n\t\t...(hasLocalSkillsDir ? { localSkillsDir } : {}),\n\t\t...(hasLocalPluginsDir ? { localPluginsDir } : {}),\n\t\tloaderOverrides: {\n\t\t\tagentsFilesOverride: (base) => {\n\t\t\t\tconst assembly = assembleSuiteAgentsMdChain({\n\t\t\t\t\tsuite: workspace.suite,\n\t\t\t\t\tagentDir,\n\t\t\t\t\tsuiteJsonPath: workspace.suiteJsonPath,\n\t\t\t\t\tsuiteAgentsMdPath: workspace.agentsMdPath,\n\t\t\t\t\tprojectAgentsFiles: base.agentsFiles,\n\t\t\t\t});\n\t\t\t\tchainDiagnostics = assembly.diagnostics;\n\t\t\t\tassembledChain = assembly.chain;\n\t\t\t\treturn { agentsFiles: mergeSuiteAgentsFiles(assembly.chain, base.agentsFiles, { agentDir }) };\n\t\t\t},\n\t\t\tskillsOverride: (base) => {\n\t\t\t\tconst filtered = filterSuiteSkills(workspace.suite, base.skills, { localSkillsDir });\n\t\t\t\tskillDiagnostics = filtered.dangling.map((name) =>\n\t\t\t\t\tsuiteDanglingAssociationDiagnostic(suiteId, \"skills\", name),\n\t\t\t\t);\n\t\t\t\treturn { skills: filtered.kept, diagnostics: base.diagnostics };\n\t\t\t},\n\t\t\tsystemPromptOverride: gate.systemPromptOverride,\n\t\t\tappendSystemPromptOverride: gate.appendSystemPromptOverride,\n\t\t},\n\t\tcollectDiagnostics: () =>\n\t\t\tObject.freeze([\n\t\t\t\t...workspace.diagnostics,\n\t\t\t\t...(pluginProfile === undefined ? [] : pluginProfileDiagnosticsV1(pluginProfile)),\n\t\t\t\t...proposalDiagnostics,\n\t\t\t\t...chainDiagnostics,\n\t\t\t\t...skillDiagnostics,\n\t\t\t\t...budgetDiagnostics(),\n\t\t\t\t...gate.diagnostics,\n\t\t\t]),\n\t};\n}\n\n// ---------------------------------------------------------------------------\n// Session suite binding reader (设计 §10.1, 统一修复轮 B)\n// ---------------------------------------------------------------------------\n\n/**\n * Reads the suite binding recorded as session protocol data (设计 §10.1): the\n * suiteId of the latest `SUITE_SESSION_ENTRY_TYPE` custom entry. Undefined\n * when the session carries no binding — pre-suite sessions, entries without a\n * data payload, or payloads without a non-empty string suiteId.\n */\nexport function readSessionSuiteId(\n\tentries: ReadonlyArray<{ type: string; customType?: string; data?: unknown }>,\n): string | undefined {\n\treturn readSessionSuiteBinding(entries)?.suiteId;\n}\n\nexport interface SessionSuiteBindingV1 {\n\treadonly suiteId: string;\n\treadonly profileIdentity?: ProfileIdentityV1;\n}\n\nfunction sessionProfileIdentity(value: unknown): ProfileIdentityV1 | undefined {\n\tif (value === null || typeof value !== \"object\" || Array.isArray(value)) return undefined;\n\tconst record = value as Record<string, unknown>;\n\tif (\n\t\ttypeof record.profileId !== \"string\" ||\n\t\trecord.profileId.trim() === \"\" ||\n\t\ttypeof record.profileVersion !== \"string\" ||\n\t\trecord.profileVersion.trim() === \"\" ||\n\t\ttypeof record.manifestDigest !== \"string\" ||\n\t\trecord.manifestDigest.trim() === \"\" ||\n\t\t!Array.isArray(record.capabilityVersions)\n\t) {\n\t\treturn undefined;\n\t}\n\tconst capabilityVersions: { id: string; version: number }[] = [];\n\tfor (const entry of record.capabilityVersions) {\n\t\tif (entry === null || typeof entry !== \"object\" || Array.isArray(entry)) return undefined;\n\t\tconst capability = entry as Record<string, unknown>;\n\t\tif (\n\t\t\ttypeof capability.id !== \"string\" ||\n\t\t\tcapability.id.trim() === \"\" ||\n\t\t\ttypeof capability.version !== \"number\" ||\n\t\t\t!Number.isSafeInteger(capability.version) ||\n\t\t\tcapability.version < 1\n\t\t) {\n\t\t\treturn undefined;\n\t\t}\n\t\tcapabilityVersions.push({ id: capability.id, version: capability.version });\n\t}\n\treturn Object.freeze({\n\t\tprofileId: record.profileId,\n\t\tprofileVersion: record.profileVersion,\n\t\tmanifestDigest: record.manifestDigest,\n\t\tcapabilityVersions: Object.freeze(capabilityVersions) as readonly {\n\t\t\treadonly id: string;\n\t\t\treadonly version: number;\n\t\t}[],\n\t});\n}\n\n/** Reads the latest suite and optional Profile identity bound to a session. */\nexport function readSessionSuiteBinding(\n\tentries: ReadonlyArray<{ type: string; customType?: string; data?: unknown }>,\n): SessionSuiteBindingV1 | undefined {\n\tfor (let index = entries.length - 1; index >= 0; index--) {\n\t\tconst entry = entries[index];\n\t\tif (entry.type !== \"custom\" || entry.customType !== SUITE_SESSION_ENTRY_TYPE) continue;\n\t\tconst data = entry.data;\n\t\tif (data !== null && typeof data === \"object\" && !Array.isArray(data)) {\n\t\t\tconst suiteId = (data as { suiteId?: unknown }).suiteId;\n\t\t\tif (typeof suiteId === \"string\" && suiteId.length > 0) {\n\t\t\t\tconst profileIdentity = sessionProfileIdentity((data as { profileIdentity?: unknown }).profileIdentity);\n\t\t\t\treturn Object.freeze({\n\t\t\t\t\tsuiteId,\n\t\t\t\t\t...(profileIdentity === undefined ? {} : { profileIdentity }),\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\treturn undefined;\n\t}\n\treturn undefined;\n}\n\n// ---------------------------------------------------------------------------\n// Suite -> ProfileIdentityV1 -> lock bridge (设计 §12)\n// ---------------------------------------------------------------------------\n\nfunction suiteToJsonValue(suite: SuiteDefinition): JsonValue {\n\treturn {\n\t\tschemaVersion: suite.schemaVersion,\n\t\tid: suite.id,\n\t\tname: suite.name,\n\t\tbuiltin: suite.builtin,\n\t\ttools: [...suite.tools],\n\t\tcapabilities: [...suite.capabilities],\n\t\tassociations: {\n\t\t\tskills: [...suite.associations.skills],\n\t\t\tmcp: [...suite.associations.mcp],\n\t\t\tplugins: [...suite.associations.plugins],\n\t\t},\n\t\tinheritSystemAgentsMd: suite.inheritSystemAgentsMd,\n\t\tmemory: suite.memory,\n\t\torientation: suite.orientation,\n\t\tmodel: suite.model,\n\t\tthinking: suite.thinking,\n\t\tclonedFrom: suite.clonedFrom\n\t\t\t? { id: suite.clonedFrom.id, digest: suite.clonedFrom.digest, at: suite.clonedFrom.at }\n\t\t\t: null,\n\t\t...(suite.factoryRevision === undefined ? {} : { factoryRevision: suite.factoryRevision }),\n\t};\n}\n\n/** The stable suite.json digest that rides as the suite profile manifest digest. */\nexport function suiteManifestDigest(suite: SuiteDefinition): string {\n\treturn stableJsonDigest(suiteToJsonValue(suite));\n}\n\n/**\n * Builds the ProfileIdentityV1 for an assembled suite. The identity is a pure\n * function of suite.json: the stable suite.json digest rides as the single\n * resolved \"manifest\", and the declared capabilities map to capability\n * references at version 1. No new identity/lock mechanism is introduced.\n */\nexport function buildSuiteProfileIdentity(\n\tsuite: SuiteDefinition,\n\tpluginProfile?: BuiltinPluginProfileResolutionV1,\n): ProfileIdentityV1 {\n\tconst fingerprint = suiteManifestDigest(suite);\n\tconst suiteCapabilityRefs = suite.capabilities.map((id) => ({ id, version: 1 }));\n\tconst pluginRefs =\n\t\tpluginProfile?.status === \"resolved\" && pluginProfile.resolution.status === \"ready\"\n\t\t\t? pluginProfile.resolution.resolvedManifest.plugins\n\t\t\t: [];\n\tconst capabilityRefs = [...suiteCapabilityRefs, ...pluginRefs.flatMap((plugin) => plugin.capabilityRefs)].sort(\n\t\t(left, right) => left.id.localeCompare(right.id) || left.version - right.version,\n\t);\n\treturn buildProfileIdentityV1({\n\t\tprofileId: suiteProfileId(suite.id),\n\t\tprofileVersion: `${SUITE_SCHEMA_VERSION}`,\n\t\tresolvedPlugins: [\n\t\t\t{\n\t\t\t\tpluginId: `${suite.id}/suite.json`,\n\t\t\t\tpluginVersion: fingerprint,\n\t\t\t\tcapabilityRefs: suiteCapabilityRefs,\n\t\t\t},\n\t\t\t...(pluginProfile?.status === \"resolved\" && pluginProfile.resolution.status === \"ready\"\n\t\t\t\t? [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tpluginId: `profile:${pluginProfile.profile.id}`,\n\t\t\t\t\t\t\tpluginVersion: pluginProfile.profile.version,\n\t\t\t\t\t\t\tcapabilityRefs: [],\n\t\t\t\t\t\t},\n\t\t\t\t\t\t...pluginRefs,\n\t\t\t\t\t]\n\t\t\t\t: []),\n\t\t],\n\t\tcapabilityVersions: capabilityRefs,\n\t});\n}\n\n// ---------------------------------------------------------------------------\n// ProfileRegistryV1 hookup: factory/disk sources and upgrade proposals (M4)\n// ---------------------------------------------------------------------------\n\n/** Registry profileId namespace for suites (设计 §12). */\nexport function suiteProfileId(suiteId: string): string {\n\treturn `suite:${suiteId}`;\n}\n\nexport const SUITE_FACTORY_REGISTRY_SOURCE_ID = \"suite-factory\";\nexport const SUITE_DISK_REGISTRY_SOURCE_ID = \"suite-disk\";\n/** Lower priority wins same-version ties: the disk contents beat the factory. */\nconst SUITE_FACTORY_REGISTRY_PRIORITY = 10;\nconst SUITE_DISK_REGISTRY_PRIORITY = 0;\n\n/** The effective on-disk revision: absent key means FACTORY_CONTENTS_VERSION. */\nfunction suiteDiskRevision(suite: SuiteDefinition): number {\n\treturn suite.factoryRevision ?? FACTORY_CONTENTS_VERSION;\n}\n\n/** Builds the registry entry of one suite definition (version = factoryRevision). */\nexport function buildSuiteRegistryEntry(suite: SuiteDefinition): RegistryProfileEntryV1 {\n\treturn {\n\t\tprofileId: suiteProfileId(suite.id),\n\t\tprofileVersion: String(suiteDiskRevision(suite)),\n\t\tmanifestDigest: suiteManifestDigest(suite),\n\t};\n}\n\n/** Factory source over the builtin declarations (priority 10). */\nexport function buildSuiteFactoryRegistrySource(): RegistrySourceV1 {\n\treturn {\n\t\tsourceId: SUITE_FACTORY_REGISTRY_SOURCE_ID,\n\t\tpriority: SUITE_FACTORY_REGISTRY_PRIORITY,\n\t\tprofiles: BUILTIN_SUITES.map(buildSuiteRegistryEntry),\n\t};\n}\n\n/** Disk source over workspace-effective definitions (priority 0; wins ties). */\nexport function buildSuiteDiskRegistrySource(suites: readonly SuiteDefinition[]): RegistrySourceV1 {\n\treturn {\n\t\tsourceId: SUITE_DISK_REGISTRY_SOURCE_ID,\n\t\tpriority: SUITE_DISK_REGISTRY_PRIORITY,\n\t\tprofiles: suites.map(buildSuiteRegistryEntry),\n\t};\n}\n\nexport interface SuiteFactoryUpgrade {\n\t/** Revision the factory builtin declaration carries. */\n\treadonly factoryRevision: number;\n\t/** Revision effective on disk. */\n\treadonly diskRevision: number;\n}\n\n/** Single-sourced upgrade-proposal diagnostic text (设计 §9 升级合并). */\nexport function suiteFactoryUpgradeDiagnostic(suiteId: string, upgrade: SuiteFactoryUpgrade): string {\n\treturn `Suite \"${suiteId}\": factory revision ${upgrade.factoryRevision} available (disk has ${upgrade.diskRevision}); run \"--suite-reset ${suiteId}\" to review and adopt.`;\n}\n\n/**\n * Detects a factory upgrade proposal for one disk-effective suite: an\n * unbounded registry resolve over the factory source (all builtins) plus a\n * disk source carrying exactly the effective definition. The factory source\n * wins only when its revision is strictly greater — same-version resolves\n * keep the disk contents (priority 0), so no proposal is emitted for\n * unchanged suites, and user suites (no factory entry) never resolve to the\n * factory. Pure function; the caller decides what to do with the proposal.\n */\nexport function detectSuiteFactoryUpgrade(diskSuite: SuiteDefinition): SuiteFactoryUpgrade | undefined {\n\tconst registry = createProfileRegistry();\n\tregistry.registerSource(buildSuiteFactoryRegistrySource());\n\tregistry.registerSource(buildSuiteDiskRegistrySource([diskSuite]));\n\tconst resolution = registry.resolve({ profileId: suiteProfileId(diskSuite.id) });\n\tif (resolution.status !== \"resolved\" || resolution.sourceId !== SUITE_FACTORY_REGISTRY_SOURCE_ID) {\n\t\treturn undefined;\n\t}\n\treturn {\n\t\tfactoryRevision: Number.parseInt(resolution.profileVersion, 10),\n\t\tdiskRevision: suiteDiskRevision(diskSuite),\n\t};\n}\n\nexport interface SuiteProfileLockBridge {\n\treadonly identity: ProfileIdentityV1;\n\t/**\n\t * The lock for this assembly. When a previous lock exists it is kept as-is\n\t * (a lock is never silently replaced); without one, a fresh lock freezes\n\t * the current identity.\n\t */\n\treadonly lock: ProfileLockV1;\n\treadonly verification?: ProfileLockVerificationV1;\n\t/** Drift/migration findings; recorded, never blocking in M1a (设计 §12). */\n\treadonly diagnostics: readonly string[];\n}\n\n/** Bridges an assembled suite onto the existing lock create/verify trio. */\nexport function bridgeSuiteProfileLock(options: {\n\treadonly suite: SuiteDefinition;\n\treadonly pluginProfile?: BuiltinPluginProfileResolutionV1;\n\treadonly previousLock?: ProfileLockV1;\n\treadonly lockedBy?: string;\n\treadonly now?: () => number;\n}): SuiteProfileLockBridge {\n\tconst identity = buildSuiteProfileIdentity(options.suite, options.pluginProfile);\n\tconst diagnostics: string[] = [];\n\tlet verification: ProfileLockVerificationV1 | undefined;\n\tif (options.previousLock !== undefined) {\n\t\tverification = verifyProfileLock(options.previousLock, identity);\n\t\tif (verification.status === \"drift\") {\n\t\t\t// 2026-10-01 dogfood finding: the bare drift reason left no recovery\n\t\t\t// path. Deleting the lock file and restarting rebuilds it from the\n\t\t\t// resolved manifest (loadSuiteWorkspace re-freezes a fresh lock).\n\t\t\tdiagnostics.push(\n\t\t\t\t`Suite \"${options.suite.id}\" profile lock drift: ${verification.reason}; to recover, delete <agentDir>/suites/${options.suite.id}/${SUITE_LOCK_FILENAME} and restart (the lock rebuilds from the resolved manifest)`,\n\t\t\t);\n\t\t} else if (verification.status === \"migration_required\") {\n\t\t\tdiagnostics.push(`Suite \"${options.suite.id}\" profile lock migration required: ${verification.reason}`);\n\t\t}\n\t}\n\tconst lock =\n\t\toptions.previousLock ??\n\t\tcreateProfileLock(identity, {\n\t\t\tlockedBy: options.lockedBy ?? \"suite-loader\",\n\t\t\t...(options.now === undefined ? {} : { now: options.now }),\n\t\t});\n\treturn {\n\t\tidentity,\n\t\tlock,\n\t\t...(verification === undefined ? {} : { verification }),\n\t\tdiagnostics: Object.freeze(diagnostics),\n\t};\n}\n"]}