@rpamis/comet 0.3.9 → 0.4.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (623) hide show
  1. package/README.md +371 -222
  2. package/assets/manifest.json +33 -12
  3. package/assets/skills/comet/SKILL.md +87 -102
  4. package/assets/skills/comet/reference/auto-transition.md +1 -1
  5. package/assets/skills/comet/reference/comet-yaml-fields.md +11 -4
  6. package/assets/skills/comet/reference/context-recovery.md +12 -2
  7. package/assets/skills/comet/reference/debug-gate.md +17 -1
  8. package/assets/skills/comet/reference/decision-point.md +13 -2
  9. package/assets/skills/comet/reference/intent-frame.md +74 -0
  10. package/assets/skills/comet/reference/scripts.md +69 -0
  11. package/assets/skills/comet/reference/subagent-dispatch.md +79 -23
  12. package/assets/skills/comet/rules/comet-phase-guard.en.md +18 -10
  13. package/assets/skills/comet/rules/comet-phase-guard.md +17 -10
  14. package/assets/skills/comet/runtime/classic/checks.yaml +6 -0
  15. package/assets/skills/comet/runtime/classic/guardrails.yaml +13 -0
  16. package/assets/skills/comet/runtime/classic/skill.yaml +122 -0
  17. package/assets/skills/comet/scripts/comet-archive.mjs +3 -0
  18. package/assets/skills/comet/scripts/comet-env.mjs +15 -0
  19. package/assets/skills/comet/scripts/comet-guard.mjs +3 -0
  20. package/assets/skills/comet/scripts/comet-handoff.mjs +3 -0
  21. package/assets/skills/comet/scripts/comet-hook-guard.mjs +3 -0
  22. package/assets/skills/comet/scripts/comet-intent.mjs +3 -0
  23. package/assets/skills/comet/scripts/comet-runtime.mjs +12941 -0
  24. package/assets/skills/comet/scripts/comet-state.mjs +3 -0
  25. package/assets/skills/comet/scripts/comet-yaml-validate.mjs +3 -0
  26. package/assets/skills/comet-any/SKILL.md +118 -0
  27. package/assets/skills/comet-any/reference/authored-zone-example.md +100 -0
  28. package/assets/skills/comet-any/reference/authoring-protocol.json +91 -0
  29. package/assets/skills/comet-any/reference/authoring-subagents.md +102 -0
  30. package/assets/skills/comet-any/reference/bundle-authoring.md +166 -0
  31. package/assets/skills/comet-any/reference/eval-provider.md +83 -0
  32. package/assets/skills/comet-any/reference/subagents/pause-points-author.md +75 -0
  33. package/assets/skills/comet-any/reference/subagents/reference-author.md +77 -0
  34. package/assets/skills/comet-any/reference/subagents/script-author.md +81 -0
  35. package/assets/skills/comet-any/reference/subagents/skill-core-author.md +129 -0
  36. package/assets/skills/comet-any/reference/subagents/skill-reviewer.md +124 -0
  37. package/assets/skills/comet-any/reference/subagents/workflow-entry-author.md +100 -0
  38. package/assets/skills/comet-archive/SKILL.md +25 -15
  39. package/assets/skills/comet-build/SKILL.md +51 -40
  40. package/assets/skills/comet-design/SKILL.md +14 -18
  41. package/assets/skills/comet-hotfix/SKILL.md +33 -43
  42. package/assets/skills/comet-open/SKILL.md +10 -20
  43. package/assets/skills/comet-tweak/SKILL.md +71 -65
  44. package/assets/skills/comet-verify/SKILL.md +31 -35
  45. package/assets/skills-zh/comet/SKILL.md +87 -101
  46. package/assets/skills-zh/comet/reference/auto-transition.md +3 -3
  47. package/assets/skills-zh/comet/reference/comet-yaml-fields.md +8 -4
  48. package/assets/skills-zh/comet/reference/context-recovery.md +11 -1
  49. package/assets/skills-zh/comet/reference/debug-gate.md +17 -1
  50. package/assets/skills-zh/comet/reference/decision-point.md +13 -2
  51. package/assets/skills-zh/comet/reference/intent-frame.md +74 -0
  52. package/assets/skills-zh/comet/reference/scripts.md +69 -0
  53. package/assets/skills-zh/comet/reference/subagent-dispatch.md +67 -18
  54. package/assets/skills-zh/comet/runtime/classic/checks.yaml +6 -0
  55. package/assets/skills-zh/comet/runtime/classic/guardrails.yaml +13 -0
  56. package/assets/skills-zh/comet/runtime/classic/skill.yaml +122 -0
  57. package/assets/skills-zh/comet-any/SKILL.md +118 -0
  58. package/assets/skills-zh/comet-any/reference/authored-zone-example.md +100 -0
  59. package/assets/skills-zh/comet-any/reference/authoring-protocol.json +91 -0
  60. package/assets/skills-zh/comet-any/reference/authoring-subagents.md +107 -0
  61. package/assets/skills-zh/comet-any/reference/bundle-authoring.md +166 -0
  62. package/assets/skills-zh/comet-any/reference/eval-provider.md +66 -0
  63. package/assets/skills-zh/comet-any/reference/subagents/pause-points-author.md +79 -0
  64. package/assets/skills-zh/comet-any/reference/subagents/reference-author.md +81 -0
  65. package/assets/skills-zh/comet-any/reference/subagents/script-author.md +84 -0
  66. package/assets/skills-zh/comet-any/reference/subagents/skill-core-author.md +129 -0
  67. package/assets/skills-zh/comet-any/reference/subagents/skill-reviewer.md +124 -0
  68. package/assets/skills-zh/comet-any/reference/subagents/workflow-entry-author.md +98 -0
  69. package/assets/skills-zh/comet-archive/SKILL.md +25 -15
  70. package/assets/skills-zh/comet-build/SKILL.md +41 -43
  71. package/assets/skills-zh/comet-design/SKILL.md +14 -18
  72. package/assets/skills-zh/comet-hotfix/SKILL.md +37 -47
  73. package/assets/skills-zh/comet-open/SKILL.md +12 -22
  74. package/assets/skills-zh/comet-tweak/SKILL.md +70 -63
  75. package/assets/skills-zh/comet-verify/SKILL.md +28 -30
  76. package/bin/comet.js +1 -1
  77. package/dist/{cli → app/cli}/index.d.ts.map +1 -1
  78. package/dist/app/cli/index.js +430 -0
  79. package/dist/app/cli/index.js.map +1 -0
  80. package/dist/app/commands/bundle.d.ts +51 -0
  81. package/dist/app/commands/bundle.d.ts.map +1 -0
  82. package/dist/app/commands/bundle.js +387 -0
  83. package/dist/app/commands/bundle.js.map +1 -0
  84. package/dist/app/commands/creator.d.ts +14 -0
  85. package/dist/app/commands/creator.d.ts.map +1 -0
  86. package/dist/app/commands/creator.js +82 -0
  87. package/dist/app/commands/creator.js.map +1 -0
  88. package/dist/app/commands/dashboard.d.ts +16 -0
  89. package/dist/app/commands/dashboard.d.ts.map +1 -0
  90. package/dist/app/commands/dashboard.js +53 -0
  91. package/dist/app/commands/dashboard.js.map +1 -0
  92. package/dist/{commands → app/commands}/doctor.d.ts +1 -1
  93. package/dist/app/commands/doctor.d.ts.map +1 -0
  94. package/dist/{commands → app/commands}/doctor.js +110 -60
  95. package/dist/app/commands/doctor.js.map +1 -0
  96. package/dist/app/commands/eval.d.ts +17 -0
  97. package/dist/app/commands/eval.d.ts.map +1 -0
  98. package/dist/app/commands/eval.js +169 -0
  99. package/dist/app/commands/eval.js.map +1 -0
  100. package/dist/app/commands/i18n.d.ts +4 -0
  101. package/dist/app/commands/i18n.d.ts.map +1 -0
  102. package/dist/{commands → app/commands}/i18n.js +22 -2
  103. package/dist/app/commands/i18n.js.map +1 -0
  104. package/dist/{commands → app/commands}/init.d.ts +3 -1
  105. package/dist/app/commands/init.d.ts.map +1 -0
  106. package/dist/{commands → app/commands}/init.js +82 -32
  107. package/dist/app/commands/init.js.map +1 -0
  108. package/dist/app/commands/platform-select-prompt.d.ts +38 -0
  109. package/dist/app/commands/platform-select-prompt.d.ts.map +1 -0
  110. package/dist/app/commands/platform-select-prompt.js +141 -0
  111. package/dist/app/commands/platform-select-prompt.js.map +1 -0
  112. package/dist/app/commands/publish.d.ts +7 -0
  113. package/dist/app/commands/publish.d.ts.map +1 -0
  114. package/dist/app/commands/publish.js +14 -0
  115. package/dist/app/commands/publish.js.map +1 -0
  116. package/dist/app/commands/skill.d.ts +23 -0
  117. package/dist/app/commands/skill.d.ts.map +1 -0
  118. package/dist/app/commands/skill.js +208 -0
  119. package/dist/app/commands/skill.js.map +1 -0
  120. package/dist/app/commands/status.d.ts.map +1 -0
  121. package/dist/app/commands/status.js +159 -0
  122. package/dist/app/commands/status.js.map +1 -0
  123. package/dist/{commands → app/commands}/uninstall.d.ts +1 -1
  124. package/dist/app/commands/uninstall.d.ts.map +1 -0
  125. package/dist/{commands → app/commands}/uninstall.js +3 -3
  126. package/dist/app/commands/uninstall.js.map +1 -0
  127. package/dist/{commands → app/commands}/update.d.ts +4 -3
  128. package/dist/app/commands/update.d.ts.map +1 -0
  129. package/dist/{commands → app/commands}/update.js +43 -15
  130. package/dist/app/commands/update.js.map +1 -0
  131. package/dist/config/repository-layout.json +98 -0
  132. package/dist/domains/bundle/authoring.d.ts +82 -0
  133. package/dist/domains/bundle/authoring.d.ts.map +1 -0
  134. package/dist/domains/bundle/authoring.js +185 -0
  135. package/dist/domains/bundle/authoring.js.map +1 -0
  136. package/dist/domains/bundle/bundle-platform.d.ts +39 -0
  137. package/dist/domains/bundle/bundle-platform.d.ts.map +1 -0
  138. package/dist/domains/bundle/bundle-platform.js +287 -0
  139. package/dist/domains/bundle/bundle-platform.js.map +1 -0
  140. package/dist/domains/bundle/candidates.d.ts +29 -0
  141. package/dist/domains/bundle/candidates.d.ts.map +1 -0
  142. package/dist/domains/bundle/candidates.js +37 -0
  143. package/dist/domains/bundle/candidates.js.map +1 -0
  144. package/dist/domains/bundle/compatibility-benchmark.d.ts +12 -0
  145. package/dist/domains/bundle/compatibility-benchmark.d.ts.map +1 -0
  146. package/dist/domains/bundle/compatibility-benchmark.js +224 -0
  147. package/dist/domains/bundle/compatibility-benchmark.js.map +1 -0
  148. package/dist/domains/bundle/compiler.d.ts +5 -0
  149. package/dist/domains/bundle/compiler.d.ts.map +1 -0
  150. package/dist/domains/bundle/compiler.js +106 -0
  151. package/dist/domains/bundle/compiler.js.map +1 -0
  152. package/dist/domains/bundle/distribute.d.ts +33 -0
  153. package/dist/domains/bundle/distribute.d.ts.map +1 -0
  154. package/dist/domains/bundle/distribute.js +166 -0
  155. package/dist/domains/bundle/distribute.js.map +1 -0
  156. package/dist/domains/bundle/draft.d.ts +19 -0
  157. package/dist/domains/bundle/draft.d.ts.map +1 -0
  158. package/dist/domains/bundle/draft.js +82 -0
  159. package/dist/domains/bundle/draft.js.map +1 -0
  160. package/dist/domains/bundle/eval.d.ts +36 -0
  161. package/dist/domains/bundle/eval.d.ts.map +1 -0
  162. package/dist/domains/bundle/eval.js +501 -0
  163. package/dist/domains/bundle/eval.js.map +1 -0
  164. package/dist/domains/bundle/factory-compose.d.ts +12 -0
  165. package/dist/domains/bundle/factory-compose.d.ts.map +1 -0
  166. package/dist/domains/bundle/factory-compose.js +309 -0
  167. package/dist/domains/bundle/factory-compose.js.map +1 -0
  168. package/dist/domains/bundle/factory-guide.d.ts +37 -0
  169. package/dist/domains/bundle/factory-guide.d.ts.map +1 -0
  170. package/dist/domains/bundle/factory-guide.js +96 -0
  171. package/dist/domains/bundle/factory-guide.js.map +1 -0
  172. package/dist/domains/bundle/factory-plan.d.ts +48 -0
  173. package/dist/domains/bundle/factory-plan.d.ts.map +1 -0
  174. package/dist/domains/bundle/factory-plan.js +172 -0
  175. package/dist/domains/bundle/factory-plan.js.map +1 -0
  176. package/dist/domains/bundle/factory-proposal.d.ts +31 -0
  177. package/dist/domains/bundle/factory-proposal.d.ts.map +1 -0
  178. package/dist/domains/bundle/factory-proposal.js +225 -0
  179. package/dist/domains/bundle/factory-proposal.js.map +1 -0
  180. package/dist/domains/bundle/factory-resolve.d.ts +11 -0
  181. package/dist/domains/bundle/factory-resolve.d.ts.map +1 -0
  182. package/dist/domains/bundle/factory-resolve.js +121 -0
  183. package/dist/domains/bundle/factory-resolve.js.map +1 -0
  184. package/dist/domains/bundle/factory.d.ts +17 -0
  185. package/dist/domains/bundle/factory.d.ts.map +1 -0
  186. package/dist/domains/bundle/factory.js +511 -0
  187. package/dist/domains/bundle/factory.js.map +1 -0
  188. package/dist/domains/bundle/hash.d.ts +3 -0
  189. package/dist/domains/bundle/hash.d.ts.map +1 -0
  190. package/dist/domains/bundle/hash.js +72 -0
  191. package/dist/domains/bundle/hash.js.map +1 -0
  192. package/dist/domains/bundle/load.d.ts +4 -0
  193. package/dist/domains/bundle/load.d.ts.map +1 -0
  194. package/dist/domains/bundle/load.js +355 -0
  195. package/dist/domains/bundle/load.js.map +1 -0
  196. package/dist/domains/bundle/next-action.d.ts +37 -0
  197. package/dist/domains/bundle/next-action.d.ts.map +1 -0
  198. package/dist/domains/bundle/next-action.js +185 -0
  199. package/dist/domains/bundle/next-action.js.map +1 -0
  200. package/dist/domains/bundle/platform.d.ts +21 -0
  201. package/dist/domains/bundle/platform.d.ts.map +1 -0
  202. package/dist/domains/bundle/platform.js +170 -0
  203. package/dist/domains/bundle/platform.js.map +1 -0
  204. package/dist/domains/bundle/preferences.d.ts +11 -0
  205. package/dist/domains/bundle/preferences.d.ts.map +1 -0
  206. package/dist/domains/bundle/preferences.js +17 -0
  207. package/dist/domains/bundle/preferences.js.map +1 -0
  208. package/dist/domains/bundle/publish.d.ts +14 -0
  209. package/dist/domains/bundle/publish.d.ts.map +1 -0
  210. package/dist/domains/bundle/publish.js +159 -0
  211. package/dist/domains/bundle/publish.js.map +1 -0
  212. package/dist/domains/bundle/readiness-user-summary.d.ts +25 -0
  213. package/dist/domains/bundle/readiness-user-summary.d.ts.map +1 -0
  214. package/dist/domains/bundle/readiness-user-summary.js +186 -0
  215. package/dist/domains/bundle/readiness-user-summary.js.map +1 -0
  216. package/dist/domains/bundle/review-summary.d.ts +36 -0
  217. package/dist/domains/bundle/review-summary.d.ts.map +1 -0
  218. package/dist/domains/bundle/review-summary.js +348 -0
  219. package/dist/domains/bundle/review-summary.js.map +1 -0
  220. package/dist/domains/bundle/state.d.ts +7 -0
  221. package/dist/domains/bundle/state.d.ts.map +1 -0
  222. package/dist/domains/bundle/state.js +132 -0
  223. package/dist/domains/bundle/state.js.map +1 -0
  224. package/dist/domains/bundle/types.d.ts +347 -0
  225. package/dist/domains/bundle/types.d.ts.map +1 -0
  226. package/dist/domains/bundle/types.js.map +1 -0
  227. package/dist/domains/bundle/user-facing.d.ts +48 -0
  228. package/dist/domains/bundle/user-facing.d.ts.map +1 -0
  229. package/dist/domains/bundle/user-facing.js +73 -0
  230. package/dist/domains/bundle/user-facing.js.map +1 -0
  231. package/dist/domains/bundle/validate.d.ts +5 -0
  232. package/dist/domains/bundle/validate.d.ts.map +1 -0
  233. package/dist/domains/bundle/validate.js +292 -0
  234. package/dist/domains/bundle/validate.js.map +1 -0
  235. package/dist/domains/comet-classic/classic-archive-entry.d.ts +2 -0
  236. package/dist/domains/comet-classic/classic-archive-entry.d.ts.map +1 -0
  237. package/dist/domains/comet-classic/classic-archive-entry.js +4 -0
  238. package/dist/domains/comet-classic/classic-archive-entry.js.map +1 -0
  239. package/dist/domains/comet-classic/classic-archive.d.ts +3 -0
  240. package/dist/domains/comet-classic/classic-archive.d.ts.map +1 -0
  241. package/dist/domains/comet-classic/classic-archive.js +392 -0
  242. package/dist/domains/comet-classic/classic-archive.js.map +1 -0
  243. package/dist/domains/comet-classic/classic-cli.d.ts +15 -0
  244. package/dist/domains/comet-classic/classic-cli.d.ts.map +1 -0
  245. package/dist/domains/comet-classic/classic-cli.js +94 -0
  246. package/dist/domains/comet-classic/classic-cli.js.map +1 -0
  247. package/dist/domains/comet-classic/classic-diagnostics.d.ts +16 -0
  248. package/dist/domains/comet-classic/classic-diagnostics.d.ts.map +1 -0
  249. package/dist/domains/comet-classic/classic-diagnostics.js +57 -0
  250. package/dist/domains/comet-classic/classic-diagnostics.js.map +1 -0
  251. package/dist/domains/comet-classic/classic-evidence.d.ts +10 -0
  252. package/dist/domains/comet-classic/classic-evidence.d.ts.map +1 -0
  253. package/dist/domains/comet-classic/classic-evidence.js +114 -0
  254. package/dist/domains/comet-classic/classic-evidence.js.map +1 -0
  255. package/dist/domains/comet-classic/classic-guard-entry.d.ts +2 -0
  256. package/dist/domains/comet-classic/classic-guard-entry.d.ts.map +1 -0
  257. package/dist/domains/comet-classic/classic-guard-entry.js +4 -0
  258. package/dist/domains/comet-classic/classic-guard-entry.js.map +1 -0
  259. package/dist/domains/comet-classic/classic-guard.d.ts +3 -0
  260. package/dist/domains/comet-classic/classic-guard.d.ts.map +1 -0
  261. package/dist/domains/comet-classic/classic-guard.js +833 -0
  262. package/dist/domains/comet-classic/classic-guard.js.map +1 -0
  263. package/dist/domains/comet-classic/classic-handoff-entry.d.ts +2 -0
  264. package/dist/domains/comet-classic/classic-handoff-entry.d.ts.map +1 -0
  265. package/dist/domains/comet-classic/classic-handoff-entry.js +4 -0
  266. package/dist/domains/comet-classic/classic-handoff-entry.js.map +1 -0
  267. package/dist/domains/comet-classic/classic-handoff.d.ts +3 -0
  268. package/dist/domains/comet-classic/classic-handoff.d.ts.map +1 -0
  269. package/dist/domains/comet-classic/classic-handoff.js +478 -0
  270. package/dist/domains/comet-classic/classic-handoff.js.map +1 -0
  271. package/dist/domains/comet-classic/classic-hook-guard-entry.d.ts +2 -0
  272. package/dist/domains/comet-classic/classic-hook-guard-entry.d.ts.map +1 -0
  273. package/dist/domains/comet-classic/classic-hook-guard-entry.js +4 -0
  274. package/dist/domains/comet-classic/classic-hook-guard-entry.js.map +1 -0
  275. package/dist/domains/comet-classic/classic-hook-guard.d.ts +3 -0
  276. package/dist/domains/comet-classic/classic-hook-guard.d.ts.map +1 -0
  277. package/dist/domains/comet-classic/classic-hook-guard.js +382 -0
  278. package/dist/domains/comet-classic/classic-hook-guard.js.map +1 -0
  279. package/dist/domains/comet-classic/classic-intent-command.d.ts +3 -0
  280. package/dist/domains/comet-classic/classic-intent-command.d.ts.map +1 -0
  281. package/dist/domains/comet-classic/classic-intent-command.js +40 -0
  282. package/dist/domains/comet-classic/classic-intent-command.js.map +1 -0
  283. package/dist/domains/comet-classic/classic-intent-entry.d.ts +2 -0
  284. package/dist/domains/comet-classic/classic-intent-entry.d.ts.map +1 -0
  285. package/dist/domains/comet-classic/classic-intent-entry.js +4 -0
  286. package/dist/domains/comet-classic/classic-intent-entry.js.map +1 -0
  287. package/dist/domains/comet-classic/classic-intent.d.ts +79 -0
  288. package/dist/domains/comet-classic/classic-intent.d.ts.map +1 -0
  289. package/dist/domains/comet-classic/classic-intent.js +307 -0
  290. package/dist/domains/comet-classic/classic-intent.js.map +1 -0
  291. package/dist/domains/comet-classic/classic-migrate.d.ts +18 -0
  292. package/dist/domains/comet-classic/classic-migrate.d.ts.map +1 -0
  293. package/dist/domains/comet-classic/classic-migrate.js +184 -0
  294. package/dist/domains/comet-classic/classic-migrate.js.map +1 -0
  295. package/dist/domains/comet-classic/classic-paths.d.ts +8 -0
  296. package/dist/domains/comet-classic/classic-paths.d.ts.map +1 -0
  297. package/dist/domains/comet-classic/classic-paths.js +61 -0
  298. package/dist/domains/comet-classic/classic-paths.js.map +1 -0
  299. package/dist/domains/comet-classic/classic-resolver.d.ts +10 -0
  300. package/dist/domains/comet-classic/classic-resolver.d.ts.map +1 -0
  301. package/dist/domains/comet-classic/classic-resolver.js +89 -0
  302. package/dist/domains/comet-classic/classic-resolver.js.map +1 -0
  303. package/dist/domains/comet-classic/classic-runtime-evals.d.ts +9 -0
  304. package/dist/domains/comet-classic/classic-runtime-evals.d.ts.map +1 -0
  305. package/dist/domains/comet-classic/classic-runtime-evals.js +45 -0
  306. package/dist/domains/comet-classic/classic-runtime-evals.js.map +1 -0
  307. package/dist/domains/comet-classic/classic-runtime-run.d.ts +7 -0
  308. package/dist/domains/comet-classic/classic-runtime-run.d.ts.map +1 -0
  309. package/dist/domains/comet-classic/classic-runtime-run.js +105 -0
  310. package/dist/domains/comet-classic/classic-runtime-run.js.map +1 -0
  311. package/dist/domains/comet-classic/classic-script-entry.d.ts +3 -0
  312. package/dist/domains/comet-classic/classic-script-entry.d.ts.map +1 -0
  313. package/dist/domains/comet-classic/classic-script-entry.js +31 -0
  314. package/dist/domains/comet-classic/classic-script-entry.js.map +1 -0
  315. package/dist/domains/comet-classic/classic-state-command.d.ts +3 -0
  316. package/dist/domains/comet-classic/classic-state-command.d.ts.map +1 -0
  317. package/dist/domains/comet-classic/classic-state-command.js +984 -0
  318. package/dist/domains/comet-classic/classic-state-command.js.map +1 -0
  319. package/dist/domains/comet-classic/classic-state-entry.d.ts +2 -0
  320. package/dist/domains/comet-classic/classic-state-entry.d.ts.map +1 -0
  321. package/dist/domains/comet-classic/classic-state-entry.js +4 -0
  322. package/dist/domains/comet-classic/classic-state-entry.js.map +1 -0
  323. package/dist/domains/comet-classic/classic-state-events.d.ts +18 -0
  324. package/dist/domains/comet-classic/classic-state-events.d.ts.map +1 -0
  325. package/dist/domains/comet-classic/classic-state-events.js +15 -0
  326. package/dist/domains/comet-classic/classic-state-events.js.map +1 -0
  327. package/dist/domains/comet-classic/classic-state.d.ts +69 -0
  328. package/dist/domains/comet-classic/classic-state.d.ts.map +1 -0
  329. package/dist/domains/comet-classic/classic-state.js +238 -0
  330. package/dist/domains/comet-classic/classic-state.js.map +1 -0
  331. package/dist/domains/comet-classic/classic-store.d.ts +7 -0
  332. package/dist/domains/comet-classic/classic-store.d.ts.map +1 -0
  333. package/dist/domains/comet-classic/classic-store.js +127 -0
  334. package/dist/domains/comet-classic/classic-store.js.map +1 -0
  335. package/dist/domains/comet-classic/classic-transitions.d.ts +24 -0
  336. package/dist/domains/comet-classic/classic-transitions.d.ts.map +1 -0
  337. package/dist/domains/comet-classic/classic-transitions.js +124 -0
  338. package/dist/domains/comet-classic/classic-transitions.js.map +1 -0
  339. package/dist/domains/comet-classic/classic-validate-command.d.ts +3 -0
  340. package/dist/domains/comet-classic/classic-validate-command.d.ts.map +1 -0
  341. package/dist/domains/comet-classic/classic-validate-command.js +154 -0
  342. package/dist/domains/comet-classic/classic-validate-command.js.map +1 -0
  343. package/dist/domains/comet-classic/classic-validate-entry.d.ts +2 -0
  344. package/dist/domains/comet-classic/classic-validate-entry.d.ts.map +1 -0
  345. package/dist/domains/comet-classic/classic-validate-entry.js +4 -0
  346. package/dist/domains/comet-classic/classic-validate-entry.js.map +1 -0
  347. package/dist/domains/comet-classic/index.d.ts +20 -0
  348. package/dist/domains/comet-classic/index.d.ts.map +1 -0
  349. package/dist/domains/comet-classic/index.js +20 -0
  350. package/dist/domains/comet-classic/index.js.map +1 -0
  351. package/dist/domains/dashboard/collector.d.ts +12 -0
  352. package/dist/domains/dashboard/collector.d.ts.map +1 -0
  353. package/dist/domains/dashboard/collector.js +475 -0
  354. package/dist/domains/dashboard/collector.js.map +1 -0
  355. package/dist/domains/dashboard/git.d.ts +8 -0
  356. package/dist/domains/dashboard/git.d.ts.map +1 -0
  357. package/dist/domains/dashboard/git.js +69 -0
  358. package/dist/domains/dashboard/git.js.map +1 -0
  359. package/dist/domains/dashboard/next-action.d.ts +17 -0
  360. package/dist/domains/dashboard/next-action.d.ts.map +1 -0
  361. package/dist/domains/dashboard/next-action.js +83 -0
  362. package/dist/domains/dashboard/next-action.js.map +1 -0
  363. package/dist/domains/dashboard/open-browser.d.ts +9 -0
  364. package/dist/domains/dashboard/open-browser.d.ts.map +1 -0
  365. package/dist/domains/dashboard/open-browser.js +40 -0
  366. package/dist/domains/dashboard/open-browser.js.map +1 -0
  367. package/dist/domains/dashboard/risk.d.ts +24 -0
  368. package/dist/domains/dashboard/risk.d.ts.map +1 -0
  369. package/dist/domains/dashboard/risk.js +97 -0
  370. package/dist/domains/dashboard/risk.js.map +1 -0
  371. package/dist/domains/dashboard/server.d.ts +21 -0
  372. package/dist/domains/dashboard/server.d.ts.map +1 -0
  373. package/dist/domains/dashboard/server.js +149 -0
  374. package/dist/domains/dashboard/server.js.map +1 -0
  375. package/dist/domains/dashboard/task-parser.d.ts +13 -0
  376. package/dist/domains/dashboard/task-parser.d.ts.map +1 -0
  377. package/dist/domains/dashboard/task-parser.js +82 -0
  378. package/dist/domains/dashboard/task-parser.js.map +1 -0
  379. package/dist/domains/dashboard/types.d.ts +122 -0
  380. package/dist/domains/dashboard/types.d.ts.map +1 -0
  381. package/dist/domains/dashboard/types.js +10 -0
  382. package/dist/domains/dashboard/types.js.map +1 -0
  383. package/dist/domains/dashboard/verify-parser.d.ts +18 -0
  384. package/dist/domains/dashboard/verify-parser.d.ts.map +1 -0
  385. package/dist/domains/dashboard/verify-parser.js +94 -0
  386. package/dist/domains/dashboard/verify-parser.js.map +1 -0
  387. package/dist/domains/dashboard/web/assets/demo-DQyfozbi.js +1 -0
  388. package/dist/domains/dashboard/web/assets/index-BcO3_QlT.css +1 -0
  389. package/dist/domains/dashboard/web/assets/index-CjU3VXVu.js +22 -0
  390. package/dist/domains/dashboard/web/favicon.png +0 -0
  391. package/dist/domains/dashboard/web/index.html +16 -0
  392. package/dist/domains/dashboard/yaml.d.ts +13 -0
  393. package/dist/domains/dashboard/yaml.d.ts.map +1 -0
  394. package/dist/domains/dashboard/yaml.js +61 -0
  395. package/dist/domains/dashboard/yaml.js.map +1 -0
  396. package/dist/domains/engine/evals.d.ts +4 -0
  397. package/dist/domains/engine/evals.d.ts.map +1 -0
  398. package/dist/domains/engine/evals.js +25 -0
  399. package/dist/domains/engine/evals.js.map +1 -0
  400. package/dist/domains/engine/guardrails.d.ts +10 -0
  401. package/dist/domains/engine/guardrails.d.ts.map +1 -0
  402. package/dist/domains/engine/guardrails.js +25 -0
  403. package/dist/domains/engine/guardrails.js.map +1 -0
  404. package/dist/domains/engine/loop.d.ts +15 -0
  405. package/dist/domains/engine/loop.d.ts.map +1 -0
  406. package/dist/domains/engine/loop.js +126 -0
  407. package/dist/domains/engine/loop.js.map +1 -0
  408. package/dist/domains/engine/manual-run.d.ts +30 -0
  409. package/dist/domains/engine/manual-run.d.ts.map +1 -0
  410. package/dist/domains/engine/manual-run.js +184 -0
  411. package/dist/domains/engine/manual-run.js.map +1 -0
  412. package/dist/domains/engine/resolver.d.ts +20 -0
  413. package/dist/domains/engine/resolver.d.ts.map +1 -0
  414. package/dist/domains/engine/resolver.js +36 -0
  415. package/dist/domains/engine/resolver.js.map +1 -0
  416. package/dist/domains/engine/run-store.d.ts +13 -0
  417. package/dist/domains/engine/run-store.d.ts.map +1 -0
  418. package/dist/domains/engine/run-store.js +100 -0
  419. package/dist/domains/engine/run-store.js.map +1 -0
  420. package/dist/domains/engine/runtime-types.d.ts +11 -0
  421. package/dist/domains/engine/runtime-types.d.ts.map +1 -0
  422. package/dist/domains/engine/runtime-types.js +2 -0
  423. package/dist/domains/engine/runtime-types.js.map +1 -0
  424. package/dist/domains/engine/standalone-run.d.ts +13 -0
  425. package/dist/domains/engine/standalone-run.d.ts.map +1 -0
  426. package/dist/domains/engine/standalone-run.js +27 -0
  427. package/dist/domains/engine/standalone-run.js.map +1 -0
  428. package/dist/domains/engine/state.d.ts +10 -0
  429. package/dist/domains/engine/state.d.ts.map +1 -0
  430. package/dist/domains/engine/state.js +160 -0
  431. package/dist/domains/engine/state.js.map +1 -0
  432. package/dist/domains/engine/types.d.ts +51 -0
  433. package/dist/domains/engine/types.d.ts.map +1 -0
  434. package/dist/domains/engine/types.js +2 -0
  435. package/dist/domains/engine/types.js.map +1 -0
  436. package/dist/domains/eval/index.d.ts +7 -0
  437. package/dist/domains/eval/index.d.ts.map +1 -0
  438. package/dist/domains/eval/index.js +11 -0
  439. package/dist/domains/eval/index.js.map +1 -0
  440. package/dist/domains/eval/repository-benchmarks.d.ts +6 -0
  441. package/dist/domains/eval/repository-benchmarks.d.ts.map +1 -0
  442. package/dist/domains/eval/repository-benchmarks.js +10 -0
  443. package/dist/domains/eval/repository-benchmarks.js.map +1 -0
  444. package/dist/domains/factory/artifacts.d.ts +53 -0
  445. package/dist/domains/factory/artifacts.d.ts.map +1 -0
  446. package/dist/domains/factory/artifacts.js +8 -0
  447. package/dist/domains/factory/artifacts.js.map +1 -0
  448. package/dist/domains/factory/package.d.ts +7 -0
  449. package/dist/domains/factory/package.d.ts.map +1 -0
  450. package/dist/domains/factory/package.js +1511 -0
  451. package/dist/domains/factory/package.js.map +1 -0
  452. package/dist/domains/factory/types.d.ts +127 -0
  453. package/dist/domains/factory/types.d.ts.map +1 -0
  454. package/dist/domains/factory/types.js +2 -0
  455. package/dist/domains/factory/types.js.map +1 -0
  456. package/dist/{core → domains/integrations}/codegraph.d.ts +1 -1
  457. package/dist/domains/integrations/codegraph.d.ts.map +1 -0
  458. package/dist/{core → domains/integrations}/codegraph.js +1 -1
  459. package/dist/domains/integrations/codegraph.js.map +1 -0
  460. package/dist/domains/integrations/openspec.d.ts +18 -0
  461. package/dist/domains/integrations/openspec.d.ts.map +1 -0
  462. package/dist/{core → domains/integrations}/openspec.js +102 -25
  463. package/dist/domains/integrations/openspec.js.map +1 -0
  464. package/dist/{core → domains/integrations}/superpowers.d.ts +10 -2
  465. package/dist/domains/integrations/superpowers.d.ts.map +1 -0
  466. package/dist/{core → domains/integrations}/superpowers.js +59 -13
  467. package/dist/domains/integrations/superpowers.js.map +1 -0
  468. package/dist/domains/skill/discovery.d.ts +17 -0
  469. package/dist/domains/skill/discovery.d.ts.map +1 -0
  470. package/dist/domains/skill/discovery.js +80 -0
  471. package/dist/domains/skill/discovery.js.map +1 -0
  472. package/dist/domains/skill/find.d.ts +41 -0
  473. package/dist/domains/skill/find.d.ts.map +1 -0
  474. package/dist/domains/skill/find.js +251 -0
  475. package/dist/domains/skill/find.js.map +1 -0
  476. package/dist/domains/skill/install.d.ts +11 -0
  477. package/dist/domains/skill/install.d.ts.map +1 -0
  478. package/dist/domains/skill/install.js +82 -0
  479. package/dist/domains/skill/install.js.map +1 -0
  480. package/dist/domains/skill/inventory.d.ts +19 -0
  481. package/dist/domains/skill/inventory.d.ts.map +1 -0
  482. package/dist/domains/skill/inventory.js +64 -0
  483. package/dist/domains/skill/inventory.js.map +1 -0
  484. package/dist/domains/skill/languages.d.ts +19 -0
  485. package/dist/domains/skill/languages.d.ts.map +1 -0
  486. package/dist/domains/skill/languages.js +21 -0
  487. package/dist/domains/skill/languages.js.map +1 -0
  488. package/dist/domains/skill/load.d.ts +5 -0
  489. package/dist/domains/skill/load.d.ts.map +1 -0
  490. package/dist/domains/skill/load.js +313 -0
  491. package/dist/domains/skill/load.js.map +1 -0
  492. package/dist/domains/skill/platform-install.d.ts +79 -0
  493. package/dist/domains/skill/platform-install.d.ts.map +1 -0
  494. package/dist/{core/skills.js → domains/skill/platform-install.js} +311 -54
  495. package/dist/domains/skill/platform-install.js.map +1 -0
  496. package/dist/domains/skill/preferences.d.ts +42 -0
  497. package/dist/domains/skill/preferences.d.ts.map +1 -0
  498. package/dist/domains/skill/preferences.js +118 -0
  499. package/dist/domains/skill/preferences.js.map +1 -0
  500. package/dist/domains/skill/snapshot.d.ts +8 -0
  501. package/dist/domains/skill/snapshot.d.ts.map +1 -0
  502. package/dist/domains/skill/snapshot.js +184 -0
  503. package/dist/domains/skill/snapshot.js.map +1 -0
  504. package/dist/domains/skill/types.d.ts +85 -0
  505. package/dist/domains/skill/types.d.ts.map +1 -0
  506. package/dist/domains/skill/types.js +2 -0
  507. package/dist/{core → domains/skill}/types.js.map +1 -1
  508. package/dist/{core → domains/skill}/uninstall.d.ts +2 -18
  509. package/dist/domains/skill/uninstall.d.ts.map +1 -0
  510. package/dist/{core → domains/skill}/uninstall.js +15 -66
  511. package/dist/domains/skill/uninstall.js.map +1 -0
  512. package/dist/domains/skill/validate.d.ts +3 -0
  513. package/dist/domains/skill/validate.d.ts.map +1 -0
  514. package/dist/domains/skill/validate.js +81 -0
  515. package/dist/domains/skill/validate.js.map +1 -0
  516. package/dist/domains/workflow-contract/builtins.d.ts +8 -0
  517. package/dist/domains/workflow-contract/builtins.d.ts.map +1 -0
  518. package/dist/domains/workflow-contract/builtins.js +229 -0
  519. package/dist/domains/workflow-contract/builtins.js.map +1 -0
  520. package/dist/domains/workflow-contract/hash.d.ts +3 -0
  521. package/dist/domains/workflow-contract/hash.d.ts.map +1 -0
  522. package/dist/domains/workflow-contract/hash.js +16 -0
  523. package/dist/domains/workflow-contract/hash.js.map +1 -0
  524. package/dist/domains/workflow-contract/index.d.ts +6 -0
  525. package/dist/domains/workflow-contract/index.d.ts.map +1 -0
  526. package/dist/domains/workflow-contract/index.js +5 -0
  527. package/dist/domains/workflow-contract/index.js.map +1 -0
  528. package/dist/domains/workflow-contract/normalize.d.ts +3 -0
  529. package/dist/domains/workflow-contract/normalize.d.ts.map +1 -0
  530. package/dist/domains/workflow-contract/normalize.js +146 -0
  531. package/dist/domains/workflow-contract/normalize.js.map +1 -0
  532. package/dist/domains/workflow-contract/types.d.ts +128 -0
  533. package/dist/domains/workflow-contract/types.d.ts.map +1 -0
  534. package/dist/domains/workflow-contract/types.js +2 -0
  535. package/dist/domains/workflow-contract/types.js.map +1 -0
  536. package/dist/domains/workflow-contract/validation.d.ts +3 -0
  537. package/dist/domains/workflow-contract/validation.d.ts.map +1 -0
  538. package/dist/domains/workflow-contract/validation.js +180 -0
  539. package/dist/domains/workflow-contract/validation.js.map +1 -0
  540. package/dist/platform/fs/file-system.d.ts.map +1 -0
  541. package/dist/platform/fs/file-system.js.map +1 -0
  542. package/dist/platform/install/detect.d.ts.map +1 -0
  543. package/dist/{core → platform/install}/detect.js +4 -3
  544. package/dist/platform/install/detect.js.map +1 -0
  545. package/dist/platform/install/platforms.d.ts.map +1 -0
  546. package/dist/{core → platform/install}/platforms.js +41 -0
  547. package/dist/platform/install/platforms.js.map +1 -0
  548. package/dist/platform/install/types.d.ts +3 -0
  549. package/dist/platform/install/types.d.ts.map +1 -0
  550. package/dist/platform/install/types.js +2 -0
  551. package/dist/platform/install/types.js.map +1 -0
  552. package/dist/platform/paths/repository-layout.d.ts +22 -0
  553. package/dist/platform/paths/repository-layout.d.ts.map +1 -0
  554. package/dist/platform/paths/repository-layout.js +11 -0
  555. package/dist/platform/paths/repository-layout.js.map +1 -0
  556. package/dist/platform/process/command-error.d.ts.map +1 -0
  557. package/dist/platform/process/command-error.js.map +1 -0
  558. package/dist/platform/process/shell-quote.d.ts +22 -0
  559. package/dist/platform/process/shell-quote.d.ts.map +1 -0
  560. package/dist/platform/process/shell-quote.js +34 -0
  561. package/dist/platform/process/shell-quote.js.map +1 -0
  562. package/dist/platform/version/version.d.ts.map +1 -0
  563. package/dist/{core → platform/version}/version.js +16 -3
  564. package/dist/platform/version/version.js.map +1 -0
  565. package/package.json +41 -15
  566. package/assets/skills/comet/scripts/comet-archive.sh +0 -311
  567. package/assets/skills/comet/scripts/comet-env.sh +0 -110
  568. package/assets/skills/comet/scripts/comet-guard.sh +0 -778
  569. package/assets/skills/comet/scripts/comet-handoff.sh +0 -390
  570. package/assets/skills/comet/scripts/comet-hook-guard.sh +0 -336
  571. package/assets/skills/comet/scripts/comet-state.sh +0 -1338
  572. package/assets/skills/comet/scripts/comet-yaml-validate.sh +0 -225
  573. package/dist/cli/index.js +0 -84
  574. package/dist/cli/index.js.map +0 -1
  575. package/dist/commands/doctor.d.ts.map +0 -1
  576. package/dist/commands/doctor.js.map +0 -1
  577. package/dist/commands/i18n.d.ts +0 -4
  578. package/dist/commands/i18n.d.ts.map +0 -1
  579. package/dist/commands/i18n.js.map +0 -1
  580. package/dist/commands/init.d.ts.map +0 -1
  581. package/dist/commands/init.js.map +0 -1
  582. package/dist/commands/status.d.ts.map +0 -1
  583. package/dist/commands/status.js +0 -108
  584. package/dist/commands/status.js.map +0 -1
  585. package/dist/commands/uninstall.d.ts.map +0 -1
  586. package/dist/commands/uninstall.js.map +0 -1
  587. package/dist/commands/update.d.ts.map +0 -1
  588. package/dist/commands/update.js.map +0 -1
  589. package/dist/core/codegraph.d.ts.map +0 -1
  590. package/dist/core/codegraph.js.map +0 -1
  591. package/dist/core/command-error.d.ts.map +0 -1
  592. package/dist/core/command-error.js.map +0 -1
  593. package/dist/core/detect.d.ts.map +0 -1
  594. package/dist/core/detect.js.map +0 -1
  595. package/dist/core/openspec.d.ts +0 -11
  596. package/dist/core/openspec.d.ts.map +0 -1
  597. package/dist/core/openspec.js.map +0 -1
  598. package/dist/core/platforms.d.ts.map +0 -1
  599. package/dist/core/platforms.js.map +0 -1
  600. package/dist/core/skills.d.ts +0 -58
  601. package/dist/core/skills.d.ts.map +0 -1
  602. package/dist/core/skills.js.map +0 -1
  603. package/dist/core/superpowers.d.ts.map +0 -1
  604. package/dist/core/superpowers.js.map +0 -1
  605. package/dist/core/types.d.ts +0 -2
  606. package/dist/core/types.d.ts.map +0 -1
  607. package/dist/core/uninstall.d.ts.map +0 -1
  608. package/dist/core/uninstall.js.map +0 -1
  609. package/dist/core/version.d.ts.map +0 -1
  610. package/dist/core/version.js.map +0 -1
  611. package/dist/utils/file-system.d.ts.map +0 -1
  612. package/dist/utils/file-system.js.map +0 -1
  613. /package/dist/{cli → app/cli}/index.d.ts +0 -0
  614. /package/dist/{commands → app/commands}/status.d.ts +0 -0
  615. /package/dist/{core → domains/bundle}/types.js +0 -0
  616. /package/dist/{utils → platform/fs}/file-system.d.ts +0 -0
  617. /package/dist/{utils → platform/fs}/file-system.js +0 -0
  618. /package/dist/{core → platform/install}/detect.d.ts +0 -0
  619. /package/dist/{core → platform/install}/platforms.d.ts +0 -0
  620. /package/dist/{core → platform/process}/command-error.d.ts +0 -0
  621. /package/dist/{core → platform/process}/command-error.js +0 -0
  622. /package/dist/{core → platform/version}/version.d.ts +0 -0
  623. /package/scripts/{postinstall.js → install/postinstall.js} +0 -0
@@ -0,0 +1,1511 @@
1
+ import { promises as fs } from 'fs';
2
+ import path from 'path';
3
+ import { stringify } from 'yaml';
4
+ import { workflowProtocolHash, } from './artifacts.js';
5
+ function factoryEntryDescription(plan) {
6
+ return plan.description || `Use when running the generated ${plan.name} workflow.`;
7
+ }
8
+ function runtimeEvals() {
9
+ return {
10
+ runtime: [
11
+ {
12
+ id: 'completed',
13
+ scope: 'completion',
14
+ type: 'state_equals',
15
+ field: 'status',
16
+ equals: 'completed',
17
+ },
18
+ ],
19
+ };
20
+ }
21
+ function artifact(path, kind, content, executable = false) {
22
+ return { path, kind, content, ...(executable ? { executable } : {}) };
23
+ }
24
+ function jsonArtifact(artifactPath, value, kind = 'reference') {
25
+ return artifact(artifactPath, kind, `${JSON.stringify(value, null, 2)}\n`);
26
+ }
27
+ function claudeAgentDefinition(options) {
28
+ return `---
29
+ name: ${options.name}
30
+ description: ${options.description}
31
+ tools: ${options.tools}
32
+ model: inherit
33
+ ---
34
+
35
+ # ${options.title}
36
+
37
+ ${options.body}
38
+ `;
39
+ }
40
+ function portableScriptAuthorBrief() {
41
+ return `# Script Author Brief
42
+
43
+ Author the script contract for one comet-any authoring lane. This is a portable role brief for platforms that do not support Claude Code custom agents.
44
+
45
+ - Read the assigned workflow protocol and lane instructions.
46
+ - Write only the assigned report path.
47
+ - Do not publish, install, or run destructive commands.
48
+ `;
49
+ }
50
+ function slug(value) {
51
+ return value
52
+ .toLowerCase()
53
+ .replace(/[^a-z0-9._-]+/gu, '-')
54
+ .replace(/^-+|-+$/gu, '');
55
+ }
56
+ function generatedNodeSkillName(workflowName, nodeId) {
57
+ const base = slug(workflowName) || 'workflow';
58
+ const suffix = slug(nodeId) || 'node';
59
+ return `${base}-${suffix}`;
60
+ }
61
+ function workflowContractRoute(protocol) {
62
+ return protocol.nodes.filter((node) => !node.disabled);
63
+ }
64
+ function workflowContractInternalSkillNames(protocol) {
65
+ return workflowContractRoute(protocol).map((node) => generatedNodeSkillName(protocol.name, node.id));
66
+ }
67
+ function nodeAuthoringMode(protocol, _node) {
68
+ return protocol.kind === 'comet-five-phase-overlay' ? 'delegates' : 'substance';
69
+ }
70
+ const AUTHORING_PENDING_MARKER = '<!-- AUTHORING PENDING -->';
71
+ function entryDecisionCoreBody(plan) {
72
+ const draft = plan.contentDrafts?.['SKILL.md'];
73
+ if (draft !== undefined)
74
+ return draft;
75
+ return `${AUTHORING_PENDING_MARKER}\n**Not yet authored.** The Decision Core for this entry — how to detect the current Node, when to pause for the user, and the red flags — must be authored by the workflow-entry lane. Until then, rely on \`workflow-state.mjs next\` for routing and treat the rest of this file as scaffold only.`;
76
+ }
77
+ function nodeGuidanceBody(plan, protocol, node) {
78
+ const nodeSkillPath = `../${generatedNodeSkillName(protocol.name, node.id)}/SKILL.md`;
79
+ const draft = plan.contentDrafts?.[nodeSkillPath];
80
+ if (draft !== undefined)
81
+ return draft;
82
+ if (nodeAuthoringMode(protocol, node) === 'delegates') {
83
+ return `This Node delegates to \`${node.implementation.skill}\`. Load that Skill, apply the Required Skill Calls below, and record the Output Schema evidence before running the Exit Check. Do not duplicate the delegate Skill's body here.`;
84
+ }
85
+ return `${AUTHORING_PENDING_MARKER}\n**Not yet authored.** This substance Node requires its decision content (prerequisites, step-by-step guidance, completion reasoning, red flags) from the skill-core lane. The control-plane sections below are scaffold only; they do not describe *how* to do this Node.`;
86
+ }
87
+ export function computeUnauthoredSubstanceNodes(plan) {
88
+ const protocol = plan.workflowProtocol;
89
+ if (!protocol)
90
+ return [];
91
+ return workflowContractRoute(protocol)
92
+ .filter((node) => nodeAuthoringMode(protocol, node) === 'substance')
93
+ .filter((node) => plan.contentDrafts?.[`../${generatedNodeSkillName(protocol.name, node.id)}/SKILL.md`] ===
94
+ undefined)
95
+ .map((node) => generatedNodeSkillName(protocol.name, node.id));
96
+ }
97
+ export function wrapperClassification(plan) {
98
+ const protocol = plan.workflowProtocol;
99
+ if (!protocol)
100
+ return 'scaffold-blocked';
101
+ if (plan.contentDrafts?.['SKILL.md'] === undefined)
102
+ return 'scaffold-blocked';
103
+ if (computeUnauthoredSubstanceNodes(plan).length > 0)
104
+ return 'scaffold-blocked';
105
+ if (protocol.kind === 'workflow-kernel')
106
+ return 'kernel-authored';
107
+ const hasAdvisoryAugmentation = workflowContractRoute(protocol).some((node) => node.augmentations.some((binding) => binding.enforcement === 'advisory'));
108
+ if (hasAdvisoryAugmentation)
109
+ return 'delegate-advisory';
110
+ return 'delegate-complete';
111
+ }
112
+ function workflowContractEntryMarkdown(plan, protocol, decisionCoreBody) {
113
+ const nodeLines = workflowContractRoute(protocol)
114
+ .map((node, index) => {
115
+ const required = node.requiredSkillCalls.length === 0
116
+ ? ''
117
+ : ` Required Skills: ${node.requiredSkillCalls.map((binding) => `\`${binding.skill}\``).join(', ')}.`;
118
+ const augmentations = node.augmentations.length === 0
119
+ ? ''
120
+ : ` Augmentations: ${node.augmentations.map((binding) => `\`${binding.skill}\` (${binding.enforcement})`).join(', ')}.`;
121
+ const schemas = node.outputSchemas.length === 0
122
+ ? ''
123
+ : ` Output Schemas: ${node.outputSchemas.map((schema) => `\`${schema}\``).join(', ')}.`;
124
+ return `${index + 1}. \`${generatedNodeSkillName(protocol.name, node.id)}\` - ${node.label} (${node.kind}). Responsibility: ${node.responsibility}${required}${augmentations}${schemas}`;
125
+ })
126
+ .join('\n');
127
+ const bindings = workflowContractRoute(protocol)
128
+ .map((node) => `- \`${node.id}\`: implementation \`${node.implementation.skill}\` (${node.implementation.operation}); required calls ${node.requiredSkillCalls.map((binding) => `\`${binding.skill}\``).join(', ') || 'none'}; augmentations ${node.augmentations
129
+ .map((binding) => `\`${binding.skill}\` (${binding.enforcement})`)
130
+ .join(', ') || 'none'}.`)
131
+ .join('\n');
132
+ const guardrails = workflowContractRoute(protocol)
133
+ .flatMap((node) => node.guardrails.map((guardrail) => `- \`${node.id}.${guardrail.id}\`: ${guardrail.label} (${guardrail.validation}).`))
134
+ .join('\n');
135
+ const startupProtocol = protocol.kind === 'comet-five-phase-overlay'
136
+ ? `1. Run \`node ${plan.name}/scripts/workflow-state.mjs status\` to read the active Comet change state.
137
+ 2. If there is no active Comet change, use \`/comet-open\` or the original \`/comet\` entry to create or resume one.
138
+ 3. Run \`node ${plan.name}/scripts/workflow-state.mjs next\` and load **only** the returned Skill. Do not load multiple Skills at once.`
139
+ : `1. Run \`node ${plan.name}/scripts/workflow-state.mjs status\` to read current state.
140
+ 2. If the workflow is not started, confirm scope with the user, then run \`node ${plan.name}/scripts/workflow-state.mjs init\`.
141
+ 3. Run \`node ${plan.name}/scripts/workflow-state.mjs next\` and load **only** the returned Skill. Do not load multiple Skills at once.`;
142
+ return `---
143
+ name: ${plan.name}
144
+ description: ${factoryEntryDescription(plan)}
145
+ ---
146
+
147
+ # ${protocol.name}
148
+
149
+ ## Decision Core
150
+
151
+ ${decisionCoreBody}
152
+
153
+ ## Workflow Nodes
154
+
155
+ ${nodeLines}
156
+
157
+ ## Skill Bindings
158
+
159
+ ${bindings || '- No Skill bindings.'}
160
+
161
+ ## Guardrails And Evidence
162
+
163
+ ${guardrails || '- No explicit guardrails.'}
164
+
165
+ ## Runtime And Recovery
166
+
167
+ ### Startup Protocol
168
+
169
+ ${startupProtocol}
170
+
171
+ ### Resume Rules (every context resume)
172
+
173
+ - **Re-detect from scratch**: on every context resume, re-run the Startup Protocol. Do not trust conversation history for current-Node detection — context compaction may have discarded critical state.
174
+ - **Trust files over state**: if the script says a Node is DONE but its expected artifacts or evidence are missing, treat the Node as incomplete and re-enter it. File evidence is the source of truth.
175
+ - **Drift handling**: if the user's request belongs to a different Node than the one returned by \`next\`, pause and confirm which Node to enter. Do not silently follow the script if the user's intent conflicts.
176
+
177
+ ### Node Boundary Rules
178
+
179
+ - Before leaving a Node, run \`node ${plan.name}/scripts/workflow-guard.mjs exit <node> --apply\` to advance state and record evidence.
180
+ - If the guard fails, do not proceed — present the guard output and ask the user how to fix it.
181
+ - If the user wants to redo a completed Node, reset its completion state and re-enter rather than creating a parallel path.
182
+
183
+ The route, Output Schemas, required Skill calls, and recovery state are defined by \`reference/workflow-protocol.json\`.
184
+ `;
185
+ }
186
+ function bindingCheckId(kind, node, skill) {
187
+ return `${kind}:${node.id}.${skill}`;
188
+ }
189
+ function requiredSkillCallMarkdown(node) {
190
+ if (node.requiredSkillCalls.length === 0)
191
+ return '- This Node has no extra required Skill calls.';
192
+ return node.requiredSkillCalls
193
+ .map((binding) => {
194
+ const check = bindingCheckId('required-skill', node, binding.skill);
195
+ const reason = binding.reason ? ` Reason: ${binding.reason}` : '';
196
+ if (binding.scope === 'handoff') {
197
+ return `- When delegating this Node, the handoff prompt must require loading \`${binding.skill}\` and returning evidence with completed check \`${check}\`.${reason}`;
198
+ }
199
+ return `- Load \`${binding.skill}\` during this Node and record completed check \`${check}\`.${reason}`;
200
+ })
201
+ .join('\n');
202
+ }
203
+ function augmentationMarkdown(node) {
204
+ if (node.augmentations.length === 0)
205
+ return '- This Node has no declared augmentations.';
206
+ return node.augmentations
207
+ .map((binding) => {
208
+ const check = bindingCheckId('augmentation', node, binding.skill);
209
+ const reason = binding.reason ? ` Reason: ${binding.reason}` : '';
210
+ return `- \`${binding.skill}\` (${binding.scope}, ${binding.enforcement}): record completed check \`${check}\`.${reason}`;
211
+ })
212
+ .join('\n');
213
+ }
214
+ function outputSchemaMarkdown(protocol, node) {
215
+ if (node.outputSchemas.length === 0)
216
+ return '- This Node has no declared Output Schema.';
217
+ return node.outputSchemas
218
+ .map((schemaId) => {
219
+ const schema = protocol.outputSchemas.find((item) => item.id === schemaId);
220
+ if (!schema)
221
+ return `- \`${schemaId}\` (missing schema definition)`;
222
+ const evidence = schema.evidence
223
+ .filter((item) => item.required)
224
+ .map((item) => `\`${item.id}\``)
225
+ .join(', ');
226
+ const artifacts = schema.artifacts
227
+ .filter((item) => item.required)
228
+ .map((item) => `\`${item.id}\` at ${item.paths.map((schemaPath) => `\`${schemaPath}\``).join(' or ')}`)
229
+ .join('; ');
230
+ return `- \`${schema.id}\`: ${schema.description} Required evidence: ${evidence || 'none'}. Required artifacts: ${artifacts || 'none'}.`;
231
+ })
232
+ .join('\n');
233
+ }
234
+ function workflowContractNodeMarkdown(plan, protocol, node, guidanceBody) {
235
+ const skillName = generatedNodeSkillName(protocol.name, node.id);
236
+ const next = workflowContractRoute(protocol)[workflowContractRoute(protocol).findIndex((item) => item.id === node.id) + 1];
237
+ const schemaLines = outputSchemaMarkdown(protocol, node);
238
+ const guardrailLines = node.guardrails.length === 0
239
+ ? '- This Node has no explicit guardrails.'
240
+ : node.guardrails
241
+ .map((guardrail) => `- \`${guardrail.id}\`: ${guardrail.label} (${guardrail.validation}).`)
242
+ .join('\n');
243
+ return `---
244
+ name: ${skillName}
245
+ description: Run the ${node.label} Node for ${protocol.name}.
246
+ ---
247
+
248
+ # ${node.label}
249
+
250
+ ## Node Goal
251
+
252
+ Complete the \`${node.id}\` Node for \`${protocol.name}\`.
253
+
254
+ Responsibility: ${node.responsibility}
255
+
256
+ ## Guidance
257
+
258
+ ${guidanceBody}
259
+
260
+ ## Entry Check
261
+
262
+ \`\`\`bash
263
+ node ${plan.name}/scripts/workflow-guard.mjs entry ${node.id}
264
+ \`\`\`
265
+
266
+ ## Skill Implementation
267
+
268
+ Load \`${node.implementation.skill}\` for this Node. Operation: \`${node.implementation.operation}\`.
269
+
270
+ ## Required Skill Calls
271
+
272
+ ${requiredSkillCallMarkdown(node)}
273
+
274
+ ## Augmentations
275
+
276
+ ${augmentationMarkdown(node)}
277
+
278
+ ## Output Schemas
279
+
280
+ ${schemaLines}
281
+
282
+ ## Evidence Record
283
+
284
+ \`\`\`bash
285
+ node ${plan.name}/scripts/workflow-state.mjs record ${node.id} '{"summary":"record the real Node result","completedChecks":[]}'
286
+ \`\`\`
287
+
288
+ ## Guardrails
289
+
290
+ ${guardrailLines}
291
+
292
+ ## Exit Check
293
+
294
+ \`\`\`bash
295
+ node ${plan.name}/scripts/workflow-guard.mjs exit ${node.id} --apply
296
+ \`\`\`
297
+
298
+ ${next ? `If the script prints \`SKILL: ${generatedNodeSkillName(protocol.name, next.id)}\`, load that Skill next.` : 'If the script prints `NEXT: done`, summarize the workflow evidence and stop.'}
299
+
300
+ ## Recovery
301
+
302
+ Read \`reference/workflow-protocol.json\` and the configured workflow state. Resume the first Node that is not listed in \`${protocol.state.completedNodesField}\`.
303
+ `;
304
+ }
305
+ function workflowContractPlanScript() {
306
+ return `#!/usr/bin/env node
307
+ import './workflow-state.mjs';
308
+ `;
309
+ }
310
+ function workflowContractCheckScript(requiredFiles) {
311
+ return `#!/usr/bin/env node
312
+ import { promises as fs } from 'fs';
313
+ import path from 'path';
314
+ import { fileURLToPath } from 'url';
315
+
316
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
317
+ const packageRoot = path.resolve(__dirname, '..');
318
+ const required = ${JSON.stringify(requiredFiles, null, 2)};
319
+
320
+ async function main() {
321
+ const missing = [];
322
+ for (const relative of required) {
323
+ try {
324
+ const stats = await fs.stat(path.join(packageRoot, relative));
325
+ if (!stats.isFile()) missing.push(relative);
326
+ } catch {
327
+ missing.push(relative);
328
+ }
329
+ }
330
+ if (missing.length > 0) {
331
+ console.error('Missing required workflow contract files: ' + missing.join(', '));
332
+ process.exit(1);
333
+ }
334
+ const protocol = JSON.parse(await fs.readFile(path.join(packageRoot, 'reference', 'workflow-protocol.json'), 'utf8'));
335
+ if (protocol.schemaVersion !== 1 || !Array.isArray(protocol.nodes)) {
336
+ throw new Error('workflow-protocol.json must use the current schema with nodes');
337
+ }
338
+ console.log('workflow-contract-ok');
339
+ }
340
+
341
+ main().catch((error) => {
342
+ console.error(error.message);
343
+ process.exit(1);
344
+ });
345
+ `;
346
+ }
347
+ function workflowContractOverlayHelperScript() {
348
+ return `
349
+ function isCometOverlay(protocol) {
350
+ return protocol.kind === 'comet-five-phase-overlay';
351
+ }
352
+
353
+ function parseSimpleYaml(raw) {
354
+ const state = {};
355
+ for (const line of String(raw).split(/\\r?\\n/u)) {
356
+ const trimmed = line.trim();
357
+ if (!trimmed || trimmed.startsWith('#')) continue;
358
+ const match = /^([^:#][^:]*):\\s*(.*)$/u.exec(line);
359
+ if (!match) continue;
360
+ const key = match[1].trim();
361
+ let value = match[2].trim();
362
+ const commentIndex = value.indexOf(' #');
363
+ if (commentIndex >= 0) value = value.slice(0, commentIndex).trim();
364
+ if (value === 'true') state[key] = true;
365
+ else if (value === 'false') state[key] = false;
366
+ else if (value === 'null') state[key] = null;
367
+ else if (
368
+ (value.startsWith('"') && value.endsWith('"')) ||
369
+ (value.startsWith("'") && value.endsWith("'"))
370
+ ) {
371
+ state[key] = value.slice(1, -1);
372
+ } else {
373
+ state[key] = value;
374
+ }
375
+ }
376
+ return state;
377
+ }
378
+
379
+ async function activeCometChanges() {
380
+ const changesRoot = path.join(runRoot, 'openspec', 'changes');
381
+ let entries;
382
+ try {
383
+ entries = await fs.readdir(changesRoot, { withFileTypes: true });
384
+ } catch (error) {
385
+ if (error && typeof error === 'object' && error.code === 'ENOENT') return [];
386
+ throw error;
387
+ }
388
+ const changes = [];
389
+ for (const entry of entries) {
390
+ if (!entry.isDirectory()) continue;
391
+ const statePath = path.join(changesRoot, entry.name, '.comet.yaml');
392
+ let state;
393
+ try {
394
+ state = parseSimpleYaml(await fs.readFile(statePath, 'utf8'));
395
+ } catch (error) {
396
+ if (error && typeof error === 'object' && error.code === 'ENOENT') continue;
397
+ throw error;
398
+ }
399
+ const archived = state.archived === true || String(state.archived ?? '').toLowerCase() === 'true';
400
+ if (!archived) changes.push({ name: entry.name, statePath, state });
401
+ }
402
+ return changes.sort((left, right) => left.name.localeCompare(right.name));
403
+ }
404
+
405
+ async function resolveCometOverlayChange() {
406
+ const changes = await activeCometChanges();
407
+ if (changes.length === 0) {
408
+ throw new Error('No active Comet change; use /comet-open or the original /comet entry to create one.');
409
+ }
410
+ if (changes.length > 1) {
411
+ throw new Error(
412
+ 'Multiple active Comet changes: ' +
413
+ changes.map((change) => change.name).join(', ') +
414
+ '. Ask the user which change to resume.',
415
+ );
416
+ }
417
+ return changes[0];
418
+ }
419
+
420
+ function hasOverlayEvidence(evidence, nodeId) {
421
+ const value = evidence && typeof evidence === 'object' ? evidence[nodeId] : null;
422
+ return !!(value && typeof value === 'object' && !Array.isArray(value));
423
+ }
424
+
425
+ function hasGeneratedPlan(state) {
426
+ if (!Object.prototype.hasOwnProperty.call(state, 'plan')) return false;
427
+ const value = state.plan;
428
+ if (value === null || value === undefined) return false;
429
+ if (typeof value === 'string') {
430
+ const normalized = value.trim().toLowerCase();
431
+ return normalized !== '' && normalized !== 'null';
432
+ }
433
+ return true;
434
+ }
435
+
436
+ function overlayBuildExecutionNode(state) {
437
+ if (
438
+ state.build_mode === 'subagent-driven-development' &&
439
+ state.subagent_dispatch === 'confirmed'
440
+ ) {
441
+ return 'subagent-execute';
442
+ }
443
+ return 'execute';
444
+ }
445
+
446
+ function overlayNodeFromState(state, evidence = {}) {
447
+ const phase = String(state.phase ?? '').trim();
448
+ if (phase === 'open') return 'open';
449
+ if (phase === 'design') return 'design';
450
+ if (phase === 'build') {
451
+ if (state.build_pause === 'plan-ready' || !hasGeneratedPlan(state)) {
452
+ return 'plan';
453
+ }
454
+ const executionNode = overlayBuildExecutionNode(state);
455
+ if (!hasOverlayEvidence(evidence, executionNode)) return executionNode;
456
+ if (String(state.review_mode ?? 'off') !== 'off') return 'review';
457
+ return executionNode;
458
+ }
459
+ if (phase === 'verify') return 'verify';
460
+ if (phase === 'archive') return 'archive';
461
+ return null;
462
+ }
463
+
464
+ function evidencePathFor(protocol, change) {
465
+ const changeName = typeof change === 'string' ? change : change.name;
466
+ return path.join(runRoot, '.comet', 'workflow-evidence', changeName, protocol.name + '.json');
467
+ }
468
+
469
+ async function readOverlayEvidence(protocol, change) {
470
+ try {
471
+ const parsed = JSON.parse(await fs.readFile(evidencePathFor(protocol, change), 'utf8'));
472
+ return parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : {};
473
+ } catch (error) {
474
+ if (error && typeof error === 'object' && error.code === 'ENOENT') return {};
475
+ throw error;
476
+ }
477
+ }
478
+
479
+ async function writeOverlayEvidence(protocol, change, value) {
480
+ const file = evidencePathFor(protocol, change);
481
+ await fs.mkdir(path.dirname(file), { recursive: true });
482
+ await fs.writeFile(file, JSON.stringify(value, null, 2) + '\\n', 'utf8');
483
+ }
484
+ `;
485
+ }
486
+ function workflowContractHookGuardScript() {
487
+ return `#!/usr/bin/env node
488
+ import { promises as fs } from 'fs';
489
+ import path from 'path';
490
+ import { fileURLToPath } from 'url';
491
+
492
+ const event = process.argv[2] ?? 'before_tool';
493
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
494
+ const packageRoot = path.resolve(__dirname, '..');
495
+ const runRoot = process.env.COMET_RUN_ROOT ? path.resolve(process.env.COMET_RUN_ROOT) : process.cwd();
496
+ const protocolPath = path.join(packageRoot, 'reference', 'workflow-protocol.json');
497
+ ${workflowContractOverlayHelperScript()}
498
+
499
+ function statePath(protocol) {
500
+ const preferred = String(protocol.state?.statePath ?? '');
501
+ if (preferred.includes('*')) {
502
+ throw new Error('workflow-run statePath cannot contain wildcards');
503
+ }
504
+ const relative = preferred;
505
+ return path.join(runRoot, ...relative.split('/').filter(Boolean));
506
+ }
507
+
508
+ async function readJson(file) {
509
+ return JSON.parse(await fs.readFile(file, 'utf8'));
510
+ }
511
+
512
+ function route(protocol) {
513
+ return (protocol.nodes ?? []).filter((node) => !node.disabled);
514
+ }
515
+
516
+ function completedSet(state) {
517
+ return new Set(Array.isArray(state.completedNodes) ? state.completedNodes : []);
518
+ }
519
+
520
+ function nextNode(protocol, state) {
521
+ const completed = completedSet(state);
522
+ return route(protocol).find((node) => !completed.has(node.id)) ?? null;
523
+ }
524
+
525
+ async function main() {
526
+ const protocol = await readJson(protocolPath);
527
+ if (protocol.schemaVersion !== 1 || !Array.isArray(protocol.nodes)) {
528
+ throw new Error('workflow-protocol.json must use the current schema with nodes');
529
+ }
530
+ const nodes = route(protocol);
531
+ if (nodes.length === 0) {
532
+ throw new Error('workflow protocol has no enabled nodes');
533
+ }
534
+ if (isCometOverlay(protocol)) {
535
+ const change = await resolveCometOverlayChange();
536
+ const evidence = await readOverlayEvidence(protocol, change);
537
+ const current = overlayNodeFromState(change.state, evidence);
538
+ if (!current || !nodes.some((node) => node.id === current)) {
539
+ throw new Error('active Comet change has no valid workflow Node');
540
+ }
541
+ console.log('workflow-hook-guard-ok');
542
+ console.log('EVENT: ' + event);
543
+ console.log('NODE: ' + current);
544
+ return;
545
+ }
546
+ let state;
547
+ try {
548
+ state = await readJson(statePath(protocol));
549
+ } catch (error) {
550
+ if (error && typeof error === 'object' && error.code === 'ENOENT') {
551
+ throw new Error('workflow state is missing; run workflow-state.mjs init first');
552
+ }
553
+ throw error;
554
+ }
555
+ if (state.workflow !== protocol.name) {
556
+ throw new Error('workflow state does not match this workflow protocol');
557
+ }
558
+ if (state.status !== 'running') {
559
+ throw new Error('workflow is not running; current status is ' + String(state.status));
560
+ }
561
+ const current = state.currentNode ?? nextNode(protocol, state)?.id ?? null;
562
+ if (!current || !nodes.some((node) => node.id === current)) {
563
+ throw new Error('workflow state has no valid current Node');
564
+ }
565
+ console.log('workflow-hook-guard-ok');
566
+ console.log('EVENT: ' + event);
567
+ console.log('NODE: ' + current);
568
+ }
569
+
570
+ main().catch((error) => {
571
+ console.error(error.message);
572
+ process.exit(1);
573
+ });
574
+ `;
575
+ }
576
+ function workflowContractStateScript() {
577
+ return `#!/usr/bin/env node
578
+ import { promises as fs } from 'fs';
579
+ import path from 'path';
580
+ import { fileURLToPath } from 'url';
581
+
582
+ const command = process.argv[2] ?? 'status';
583
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
584
+ const packageRoot = path.resolve(__dirname, '..');
585
+ const runRoot = process.env.COMET_RUN_ROOT ? path.resolve(process.env.COMET_RUN_ROOT) : process.cwd();
586
+ const protocolPath = path.join(packageRoot, 'reference', 'workflow-protocol.json');
587
+ ${workflowContractOverlayHelperScript()}
588
+
589
+ function slug(value) {
590
+ return String(value).toLowerCase().replace(/[^a-z0-9._-]+/gu, '-').replace(/^-+|-+$/gu, '');
591
+ }
592
+
593
+ function generatedNodeSkillName(protocol, nodeId) {
594
+ return (slug(protocol.name) || 'workflow') + '-' + (slug(nodeId) || 'node');
595
+ }
596
+
597
+ function statePath(protocol) {
598
+ const preferred = String(protocol.state?.statePath ?? '');
599
+ if (preferred.includes('*')) {
600
+ throw new Error('workflow-run statePath cannot contain wildcards');
601
+ }
602
+ const relative = preferred;
603
+ return path.join(runRoot, ...relative.split('/').filter(Boolean));
604
+ }
605
+
606
+ async function readJson(file) {
607
+ return JSON.parse(await fs.readFile(file, 'utf8'));
608
+ }
609
+
610
+ async function writeJson(file, value) {
611
+ await fs.mkdir(path.dirname(file), { recursive: true });
612
+ await fs.writeFile(file, JSON.stringify(value, null, 2) + '\\n', 'utf8');
613
+ }
614
+
615
+ function route(protocol) {
616
+ return (protocol.nodes ?? []).filter((node) => !node.disabled);
617
+ }
618
+
619
+ function completedSet(state) {
620
+ return new Set(Array.isArray(state.completedNodes) ? state.completedNodes : []);
621
+ }
622
+
623
+ function nextNode(protocol, state) {
624
+ const completed = completedSet(state);
625
+ return route(protocol).find((node) => !completed.has(node.id)) ?? null;
626
+ }
627
+
628
+ function printNext(protocol, node) {
629
+ if (!node) {
630
+ console.log('NEXT: done');
631
+ return;
632
+ }
633
+ console.log('NEXT: auto');
634
+ console.log('NODE: ' + node.id);
635
+ console.log('SKILL: ' + generatedNodeSkillName(protocol, node.id));
636
+ }
637
+
638
+ function parseEvidence(raw) {
639
+ if (!raw || raw.trim().length === 0) return {};
640
+ try {
641
+ const parsed = JSON.parse(raw);
642
+ return parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : { value: parsed };
643
+ } catch {
644
+ return { summary: raw };
645
+ }
646
+ }
647
+
648
+ async function readState(protocol) {
649
+ try {
650
+ return await readJson(statePath(protocol));
651
+ } catch (error) {
652
+ if (error && typeof error === 'object' && error.code === 'ENOENT') {
653
+ throw new Error('Missing workflow state. Run workflow-state.mjs init first.');
654
+ }
655
+ throw error;
656
+ }
657
+ }
658
+
659
+ async function main() {
660
+ const protocol = await readJson(protocolPath);
661
+ if (protocol.schemaVersion !== 1 || !Array.isArray(protocol.nodes)) {
662
+ throw new Error('workflow-protocol.json must use the current schema with nodes');
663
+ }
664
+ if (isCometOverlay(protocol)) {
665
+ if (command === 'init') {
666
+ throw new Error(
667
+ 'Comet overlay state is created by /comet-open; use the original /comet entry to start a change.',
668
+ );
669
+ }
670
+ if (command === 'status') {
671
+ try {
672
+ const change = await resolveCometOverlayChange();
673
+ const evidence = await readOverlayEvidence(protocol, change);
674
+ const currentNode = overlayNodeFromState(change.state, evidence);
675
+ console.log(
676
+ JSON.stringify(
677
+ {
678
+ status: 'running',
679
+ change: change.name,
680
+ statePath: change.statePath,
681
+ currentNode,
682
+ phase: change.state.phase ?? null,
683
+ },
684
+ null,
685
+ 2,
686
+ ),
687
+ );
688
+ } catch (error) {
689
+ console.log(
690
+ JSON.stringify(
691
+ { status: 'blocked', reason: error instanceof Error ? error.message : String(error) },
692
+ null,
693
+ 2,
694
+ ),
695
+ );
696
+ }
697
+ return;
698
+ }
699
+ if (command === 'next') {
700
+ const change = await resolveCometOverlayChange();
701
+ const evidence = await readOverlayEvidence(protocol, change);
702
+ const nodeId = overlayNodeFromState(change.state, evidence);
703
+ printNext(protocol, route(protocol).find((node) => node.id === nodeId) ?? null);
704
+ return;
705
+ }
706
+ if (command === 'record') {
707
+ const nodeId = process.argv[3];
708
+ if (!nodeId) throw new Error('record requires a Node id.');
709
+ const node = route(protocol).find((item) => item.id === nodeId || generatedNodeSkillName(protocol, item.id) === nodeId);
710
+ if (!node) throw new Error('Unknown workflow Node: ' + nodeId);
711
+ const change = await resolveCometOverlayChange();
712
+ const evidence = await readOverlayEvidence(protocol, change);
713
+ evidence[node.id] = { ...parseEvidence(process.argv.slice(4).join(' ')), recordedAt: new Date().toISOString() };
714
+ await writeOverlayEvidence(protocol, change, evidence);
715
+ console.log('EVIDENCE: ' + node.id);
716
+ printNext(protocol, route(protocol).find((item) => item.id === overlayNodeFromState(change.state, evidence)) ?? null);
717
+ return;
718
+ }
719
+ throw new Error('Unknown command: ' + command);
720
+ }
721
+ const file = statePath(protocol);
722
+ if (command === 'init') {
723
+ const node = nextNode(protocol, { completedNodes: [] });
724
+ await writeJson(file, {
725
+ schemaVersion: 1,
726
+ workflow: protocol.name,
727
+ status: node ? 'running' : 'completed',
728
+ currentNode: node?.id ?? null,
729
+ completedNodes: [],
730
+ evidence: {},
731
+ history: [],
732
+ });
733
+ printNext(protocol, node);
734
+ return;
735
+ }
736
+ if (command === 'status') {
737
+ try {
738
+ console.log(JSON.stringify(await readJson(file), null, 2));
739
+ } catch (error) {
740
+ if (error && typeof error === 'object' && error.code === 'ENOENT') {
741
+ console.log(JSON.stringify({ status: 'not-started' }, null, 2));
742
+ return;
743
+ }
744
+ throw error;
745
+ }
746
+ return;
747
+ }
748
+ if (command === 'next') {
749
+ printNext(protocol, nextNode(protocol, await readState(protocol)));
750
+ return;
751
+ }
752
+ if (command === 'record') {
753
+ const nodeId = process.argv[3];
754
+ if (!nodeId) throw new Error('record requires a Node id.');
755
+ const node = route(protocol).find((item) => item.id === nodeId || generatedNodeSkillName(protocol, item.id) === nodeId);
756
+ if (!node) throw new Error('Unknown workflow Node: ' + nodeId);
757
+ const state = await readState(protocol);
758
+ state.evidence = state.evidence && typeof state.evidence === 'object' ? state.evidence : {};
759
+ state.history = Array.isArray(state.history) ? state.history : [];
760
+ state.evidence[node.id] = { ...parseEvidence(process.argv.slice(4).join(' ')), recordedAt: new Date().toISOString() };
761
+ state.history.push({ event: 'evidence-recorded', node: node.id, at: new Date().toISOString() });
762
+ await writeJson(file, state);
763
+ console.log('EVIDENCE: ' + node.id);
764
+ printNext(protocol, nextNode(protocol, state));
765
+ return;
766
+ }
767
+ throw new Error('Unknown command: ' + command);
768
+ }
769
+
770
+ main().catch((error) => {
771
+ console.error(error.message);
772
+ process.exit(1);
773
+ });
774
+ `;
775
+ }
776
+ function workflowContractGuardScript() {
777
+ return `#!/usr/bin/env node
778
+ import { promises as fs } from 'fs';
779
+ import path from 'path';
780
+ import { fileURLToPath } from 'url';
781
+
782
+ const command = process.argv[2] ?? 'verify';
783
+ const nodeId = process.argv[3] ?? null;
784
+ const apply = process.argv.includes('--apply');
785
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
786
+ const packageRoot = path.resolve(__dirname, '..');
787
+ const runRoot = process.env.COMET_RUN_ROOT ? path.resolve(process.env.COMET_RUN_ROOT) : process.cwd();
788
+ const protocolPath = path.join(packageRoot, 'reference', 'workflow-protocol.json');
789
+ ${workflowContractOverlayHelperScript()}
790
+
791
+ function slug(value) {
792
+ return String(value).toLowerCase().replace(/[^a-z0-9._-]+/gu, '-').replace(/^-+|-+$/gu, '');
793
+ }
794
+
795
+ function generatedNodeSkillName(protocol, id) {
796
+ return (slug(protocol.name) || 'workflow') + '-' + (slug(id) || 'node');
797
+ }
798
+
799
+ function statePath(protocol) {
800
+ const preferred = String(protocol.state?.statePath ?? '');
801
+ if (preferred.includes('*')) {
802
+ throw new Error('workflow-run statePath cannot contain wildcards');
803
+ }
804
+ const relative = preferred;
805
+ return path.join(runRoot, ...relative.split('/').filter(Boolean));
806
+ }
807
+
808
+ async function readJson(file) {
809
+ return JSON.parse(await fs.readFile(file, 'utf8'));
810
+ }
811
+
812
+ async function writeJson(file, value) {
813
+ await fs.mkdir(path.dirname(file), { recursive: true });
814
+ await fs.writeFile(file, JSON.stringify(value, null, 2) + '\\n', 'utf8');
815
+ }
816
+
817
+ function route(protocol) {
818
+ return protocol.nodes.filter((node) => !node.disabled);
819
+ }
820
+
821
+ function findNode(protocol, id) {
822
+ return route(protocol).find((node) => node.id === id || generatedNodeSkillName(protocol, node.id) === id) ?? null;
823
+ }
824
+
825
+ function completedSet(state) {
826
+ return new Set(Array.isArray(state.completedNodes) ? state.completedNodes : []);
827
+ }
828
+
829
+ function nextNode(protocol, state) {
830
+ const completed = completedSet(state);
831
+ return route(protocol).find((node) => !completed.has(node.id)) ?? null;
832
+ }
833
+
834
+ function printNext(protocol, node) {
835
+ if (!node) {
836
+ console.log('NEXT: done');
837
+ return;
838
+ }
839
+ console.log('NEXT: auto');
840
+ console.log('NODE: ' + node.id);
841
+ console.log('SKILL: ' + generatedNodeSkillName(protocol, node.id));
842
+ }
843
+
844
+ function evidenceFor(state, id) {
845
+ const value = state.evidence && typeof state.evidence === 'object' ? state.evidence[id] : null;
846
+ return value && typeof value === 'object' && !Array.isArray(value) ? value : null;
847
+ }
848
+
849
+ function missingRequiredSkillChecks(node, evidence) {
850
+ const values = Array.isArray(evidence?.completedChecks) ? evidence.completedChecks : [];
851
+ return (node.requiredSkillCalls ?? [])
852
+ .map((binding) => 'required-skill:' + node.id + '.' + binding.skill)
853
+ .filter((check) => !values.includes(check));
854
+ }
855
+
856
+ function missingAugmentationChecks(node, evidence) {
857
+ const values = Array.isArray(evidence?.completedChecks) ? evidence.completedChecks : [];
858
+ return (node.augmentations ?? [])
859
+ .filter((binding) => binding.enforcement && binding.enforcement !== 'advisory')
860
+ .map((binding) => 'augmentation:' + node.id + '.' + binding.skill)
861
+ .filter((check) => !values.includes(check));
862
+ }
863
+
864
+ function hasEvidenceField(evidence, id) {
865
+ if (Object.prototype.hasOwnProperty.call(evidence, id)) return true;
866
+ const schemaEvidence = evidence.schemaEvidence;
867
+ return !!(
868
+ schemaEvidence &&
869
+ typeof schemaEvidence === 'object' &&
870
+ !Array.isArray(schemaEvidence) &&
871
+ Object.prototype.hasOwnProperty.call(schemaEvidence, id)
872
+ );
873
+ }
874
+
875
+ function schemaMap(protocol) {
876
+ return new Map((protocol.outputSchemas ?? []).map((schema) => [schema.id, schema]));
877
+ }
878
+
879
+ function missingRequiredSchemaEvidence(protocol, node, evidence) {
880
+ const schemas = schemaMap(protocol);
881
+ const missing = [];
882
+ for (const schemaId of node.outputSchemas ?? []) {
883
+ const schema = schemas.get(schemaId);
884
+ for (const field of schema?.evidence ?? []) {
885
+ if (field.required && !hasEvidenceField(evidence, field.id)) {
886
+ missing.push(schemaId + '.' + field.id);
887
+ }
888
+ }
889
+ }
890
+ return missing;
891
+ }
892
+
893
+ function escapeRegExp(value) {
894
+ return String(value).replace(/[|\\\\{}()[\\]^$+?.]/gu, '\\\\$&');
895
+ }
896
+
897
+ function patternToRegExp(pattern) {
898
+ return new RegExp('^' + String(pattern).split('*').map(escapeRegExp).join('.*') + '$', 'u');
899
+ }
900
+
901
+ async function pathPatternExists(root, relativePattern) {
902
+ const parts = String(relativePattern).split('/').filter(Boolean);
903
+ async function walk(current, index) {
904
+ if (index >= parts.length) {
905
+ try {
906
+ await fs.stat(current);
907
+ return true;
908
+ } catch {
909
+ return false;
910
+ }
911
+ }
912
+ const part = parts[index];
913
+ if (!part.includes('*')) {
914
+ return walk(path.join(current, part), index + 1);
915
+ }
916
+ let entries;
917
+ try {
918
+ entries = await fs.readdir(current, { withFileTypes: true });
919
+ } catch {
920
+ return false;
921
+ }
922
+ const matcher = patternToRegExp(part);
923
+ for (const entry of entries) {
924
+ if (matcher.test(entry.name) && (await walk(path.join(current, entry.name), index + 1))) {
925
+ return true;
926
+ }
927
+ }
928
+ return false;
929
+ }
930
+ return walk(root, 0);
931
+ }
932
+
933
+ async function missingRequiredArtifacts(protocol, node) {
934
+ const schemas = schemaMap(protocol);
935
+ const missing = [];
936
+ for (const schemaId of node.outputSchemas ?? []) {
937
+ const schema = schemas.get(schemaId);
938
+ for (const artifact of schema?.artifacts ?? []) {
939
+ if (!artifact.required) continue;
940
+ const exists = (
941
+ await Promise.all(
942
+ (artifact.paths ?? []).map((artifactPath) => pathPatternExists(runRoot, artifactPath)),
943
+ )
944
+ ).some(Boolean);
945
+ if (!exists) missing.push(schemaId + '.' + artifact.id);
946
+ }
947
+ }
948
+ return missing;
949
+ }
950
+
951
+ async function main() {
952
+ const protocol = await readJson(protocolPath);
953
+ if (protocol.schemaVersion !== 1 || !Array.isArray(protocol.nodes)) {
954
+ throw new Error('workflow-protocol.json must use the current schema with nodes');
955
+ }
956
+ if (command === 'verify') {
957
+ console.log('workflow-guard-ok');
958
+ return;
959
+ }
960
+ if (command !== 'entry' && command !== 'exit') throw new Error('Unknown command: ' + command);
961
+ if (!nodeId) throw new Error(command + ' requires a Node id.');
962
+ const node = findNode(protocol, nodeId);
963
+ if (!node) throw new Error('Unknown workflow Node: ' + nodeId);
964
+ if (isCometOverlay(protocol)) {
965
+ const change = await resolveCometOverlayChange();
966
+ const overlayEvidence = await readOverlayEvidence(protocol, change);
967
+ const current = overlayNodeFromState(change.state, overlayEvidence);
968
+ if (command === 'entry') {
969
+ if (current !== node.id) {
970
+ console.error('BLOCKED: current Node is ' + String(current) + ', cannot enter ' + node.id + '.');
971
+ process.exit(1);
972
+ }
973
+ console.log('ENTRY OK: ' + node.id);
974
+ return;
975
+ }
976
+ const evidenceState = { evidence: overlayEvidence };
977
+ const evidence = evidenceFor(evidenceState, node.id);
978
+ if (!evidence) {
979
+ console.error('BLOCKED: missing evidence for Node ' + node.id + '.');
980
+ process.exit(1);
981
+ }
982
+ const missingSchemaEvidence = missingRequiredSchemaEvidence(protocol, node, evidence);
983
+ if (missingSchemaEvidence.length > 0) {
984
+ console.error('BLOCKED: missing Output Schema evidence: ' + missingSchemaEvidence.join(', '));
985
+ process.exit(1);
986
+ }
987
+ const missingArtifacts = await missingRequiredArtifacts(protocol, node);
988
+ if (missingArtifacts.length > 0) {
989
+ console.error('BLOCKED: missing Output Schema artifacts: ' + missingArtifacts.join(', '));
990
+ process.exit(1);
991
+ }
992
+ const missingRequired = missingRequiredSkillChecks(node, evidence);
993
+ if (missingRequired.length > 0) {
994
+ console.error('BLOCKED: missing required Skill evidence: ' + missingRequired.join(', '));
995
+ process.exit(1);
996
+ }
997
+ const missingAugmentations = missingAugmentationChecks(node, evidence);
998
+ if (missingAugmentations.length > 0) {
999
+ console.error('BLOCKED: missing augmentation evidence: ' + missingAugmentations.join(', '));
1000
+ process.exit(1);
1001
+ }
1002
+ console.log('ALL CHECKS PASSED');
1003
+ if (apply) {
1004
+ console.log('COMET STATE: unchanged; phase progression remains owned by the original Comet runtime.');
1005
+ return;
1006
+ }
1007
+ console.log('APPLY: rerun with --apply to update workflow state');
1008
+ return;
1009
+ }
1010
+ const file = statePath(protocol);
1011
+ const state = await readJson(file);
1012
+ state.completedNodes = Array.isArray(state.completedNodes) ? state.completedNodes : [];
1013
+ state.evidence = state.evidence && typeof state.evidence === 'object' ? state.evidence : {};
1014
+ if (command === 'entry') {
1015
+ const current = state.currentNode ?? nextNode(protocol, state)?.id ?? null;
1016
+ if (current !== node.id && !state.completedNodes.includes(node.id)) {
1017
+ console.error('BLOCKED: current Node is ' + String(current) + ', cannot enter ' + node.id + '.');
1018
+ process.exit(1);
1019
+ }
1020
+ console.log('ENTRY OK: ' + node.id);
1021
+ return;
1022
+ }
1023
+ const evidence = evidenceFor(state, node.id);
1024
+ if (!evidence) {
1025
+ console.error('BLOCKED: missing evidence for Node ' + node.id + '.');
1026
+ process.exit(1);
1027
+ }
1028
+ const missingSchemaEvidence = missingRequiredSchemaEvidence(protocol, node, evidence);
1029
+ if (missingSchemaEvidence.length > 0) {
1030
+ console.error('BLOCKED: missing Output Schema evidence: ' + missingSchemaEvidence.join(', '));
1031
+ process.exit(1);
1032
+ }
1033
+ const missingArtifacts = await missingRequiredArtifacts(protocol, node);
1034
+ if (missingArtifacts.length > 0) {
1035
+ console.error('BLOCKED: missing Output Schema artifacts: ' + missingArtifacts.join(', '));
1036
+ process.exit(1);
1037
+ }
1038
+ const missingRequired = missingRequiredSkillChecks(node, evidence);
1039
+ if (missingRequired.length > 0) {
1040
+ console.error('BLOCKED: missing required Skill evidence: ' + missingRequired.join(', '));
1041
+ process.exit(1);
1042
+ }
1043
+ const missingAugmentations = missingAugmentationChecks(node, evidence);
1044
+ if (missingAugmentations.length > 0) {
1045
+ console.error('BLOCKED: missing augmentation evidence: ' + missingAugmentations.join(', '));
1046
+ process.exit(1);
1047
+ }
1048
+ if (apply) {
1049
+ const completed = completedSet(state);
1050
+ completed.add(node.id);
1051
+ state.completedNodes = route(protocol).filter((item) => completed.has(item.id)).map((item) => item.id);
1052
+ const next = nextNode(protocol, state);
1053
+ state.currentNode = next?.id ?? null;
1054
+ state.status = next ? 'running' : 'completed';
1055
+ state.history = Array.isArray(state.history) ? state.history : [];
1056
+ state.history.push({ event: 'exit-applied', node: node.id, at: new Date().toISOString() });
1057
+ await writeJson(file, state);
1058
+ console.log('ALL CHECKS PASSED');
1059
+ printNext(protocol, next);
1060
+ return;
1061
+ }
1062
+ console.log('ALL CHECKS PASSED');
1063
+ console.log('APPLY: rerun with --apply to update workflow state');
1064
+ }
1065
+
1066
+ main().catch((error) => {
1067
+ console.error(error.message);
1068
+ process.exit(1);
1069
+ });
1070
+ `;
1071
+ }
1072
+ function workflowContractHandoffScript() {
1073
+ return `#!/usr/bin/env node
1074
+ import { promises as fs } from 'fs';
1075
+ import path from 'path';
1076
+ import { fileURLToPath } from 'url';
1077
+
1078
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
1079
+ const packageRoot = path.resolve(__dirname, '..');
1080
+
1081
+ async function main() {
1082
+ const protocol = JSON.parse(await fs.readFile(path.join(packageRoot, 'reference', 'workflow-protocol.json'), 'utf8'));
1083
+ console.log(JSON.stringify({
1084
+ workflow: protocol.name,
1085
+ nodes: protocol.nodes.map((node) => ({
1086
+ id: node.id,
1087
+ label: node.label,
1088
+ requiredSkillCalls: node.requiredSkillCalls ?? [],
1089
+ augmentations: node.augmentations ?? [],
1090
+ outputSchemas: node.outputSchemas ?? [],
1091
+ })),
1092
+ }, null, 2));
1093
+ }
1094
+
1095
+ main().catch((error) => {
1096
+ console.error(error.message);
1097
+ process.exit(1);
1098
+ });
1099
+ `;
1100
+ }
1101
+ function uniqueStrings(values) {
1102
+ return Array.from(new Set(values));
1103
+ }
1104
+ function sortedUniqueRecords(records) {
1105
+ const byKey = new Map();
1106
+ for (const record of records) {
1107
+ const key = JSON.stringify(Object.fromEntries(Object.entries(record).sort(([left], [right]) => left.localeCompare(right))));
1108
+ byKey.set(key, record);
1109
+ }
1110
+ return [...byKey.entries()]
1111
+ .sort(([left], [right]) => left.localeCompare(right))
1112
+ .map(([, record]) => record);
1113
+ }
1114
+ function workflowContractSkillDefinition(plan, protocol) {
1115
+ const route = workflowContractRoute(protocol);
1116
+ const steps = route.map((node, index) => ({
1117
+ id: `node-${index + 1}-${slug(node.id)}`,
1118
+ action: { type: 'invoke_skill', ref: generatedNodeSkillName(protocol.name, node.id) },
1119
+ ...(route[index + 1] ? { next: `node-${index + 2}-${slug(route[index + 1].id)}` } : {}),
1120
+ }));
1121
+ return {
1122
+ apiVersion: 'comet/v1alpha1',
1123
+ kind: 'Skill',
1124
+ metadata: {
1125
+ name: plan.name,
1126
+ version: plan.version,
1127
+ description: factoryEntryDescription(plan),
1128
+ },
1129
+ goal: {
1130
+ statement: protocol.goal,
1131
+ inputs: [],
1132
+ outputs: [{ name: 'result', description: 'Generated workflow result' }],
1133
+ success: ['The generated workflow completes according to its workflow protocol'],
1134
+ },
1135
+ orchestration: {
1136
+ mode: plan.engineMode === 'adaptive' ? 'adaptive' : 'deterministic',
1137
+ entry: steps[0]?.id ?? 'complete',
1138
+ steps: steps.length > 0 ? steps : [{ id: 'complete', action: { type: 'checkpoint' } }],
1139
+ },
1140
+ skills: route.map((node) => ({ id: generatedNodeSkillName(protocol.name, node.id) })),
1141
+ agents: [],
1142
+ tools: [],
1143
+ };
1144
+ }
1145
+ function workflowContractEvalManifest(plan, protocol) {
1146
+ const activeNodes = workflowContractRoute(protocol);
1147
+ const route = activeNodes.map((node) => generatedNodeSkillName(protocol.name, node.id));
1148
+ const isOverlay = protocol.kind === 'comet-five-phase-overlay';
1149
+ const recommendedTasks = isOverlay
1150
+ ? [
1151
+ 'authoring-skill-smoke',
1152
+ 'workflow-route-conformance',
1153
+ 'workflow-overlay-contract',
1154
+ 'comet-full-workflow',
1155
+ 'comet-fix-median',
1156
+ 'comet-refactor-counter',
1157
+ 'comet-api-cache-ttl',
1158
+ ]
1159
+ : ['generic-skill-smoke', 'authoring-skill-smoke', 'workflow-route-conformance'];
1160
+ const activeOutputSchemas = uniqueStrings(activeNodes.flatMap((node) => node.outputSchemas));
1161
+ const activeOutputSchemaSet = new Set(activeOutputSchemas);
1162
+ const evalRequiredOutputSchemas = protocol.evals[0]?.requiredOutputSchemas ?? [];
1163
+ const activeEvalRequiredOutputSchemas = evalRequiredOutputSchemas.filter((schemaId) => activeOutputSchemaSet.has(schemaId));
1164
+ const requiredOutputSchemas = uniqueStrings(evalRequiredOutputSchemas.length > 0 ? activeEvalRequiredOutputSchemas : activeOutputSchemas);
1165
+ const schemasById = new Map(protocol.outputSchemas.map((schema) => [schema.id, schema]));
1166
+ const expectedEvidence = sortedUniqueRecords(activeNodes.flatMap((node) => [
1167
+ ...node.requiredSkillCalls.map((binding) => ({
1168
+ node: node.id,
1169
+ check: `required-skill:${node.id}.${binding.skill}`,
1170
+ enforcement: binding.enforcement,
1171
+ })),
1172
+ ...node.augmentations.map((binding) => ({
1173
+ node: node.id,
1174
+ check: `augmentation:${node.id}.${binding.skill}`,
1175
+ enforcement: binding.enforcement,
1176
+ })),
1177
+ ...node.outputSchemas.flatMap((schemaId) => (schemasById.get(schemaId)?.evidence ?? [])
1178
+ .filter((field) => field.required)
1179
+ .map((field) => ({
1180
+ node: node.id,
1181
+ check: `output-schema:${node.id}.${schemaId}.${field.id}`,
1182
+ schema: schemaId,
1183
+ evidence: field.id,
1184
+ }))),
1185
+ ]));
1186
+ const expectedArtifacts = activeNodes.flatMap((node) => node.outputSchemas.flatMap((schemaId) => {
1187
+ const schema = protocol.outputSchemas.find((item) => item.id === schemaId);
1188
+ return (schema?.artifacts ?? [])
1189
+ .filter((item) => item.required)
1190
+ .map((item) => ({
1191
+ node: node.id,
1192
+ schema: schemaId,
1193
+ artifact: item.id,
1194
+ paths: item.paths,
1195
+ }));
1196
+ }));
1197
+ return {
1198
+ apiVersion: 'comet.eval/v1alpha1',
1199
+ kind: 'SkillEvalManifest',
1200
+ metadata: {
1201
+ name: plan.name,
1202
+ description: factoryEntryDescription(plan),
1203
+ draftHash: '<current-bundle-hash>',
1204
+ },
1205
+ skill: { name: plan.name, source: '..', profile: 'authoring-skill' },
1206
+ evaluation: {
1207
+ recommendedTasks,
1208
+ baselineTreatments: isOverlay ? ['CONTROL', 'COMET_FULL_040_BETA'] : ['CONTROL'],
1209
+ qualityGates: {
1210
+ minWeightedScore: 0.8,
1211
+ minPassAt1: 0.6,
1212
+ maxInstabilityGap: 0.4,
1213
+ },
1214
+ requiredOutputSchemas,
1215
+ expectedEvidence,
1216
+ requiredSkills: [plan.name, ...route],
1217
+ generatedNodeSkills: route,
1218
+ expectedArtifacts,
1219
+ routeConformance: {
1220
+ task: 'workflow-route-conformance',
1221
+ expectedNodeOrder: (protocol.evals[0]?.expectedNodeOrder ?? activeNodes.map((node) => node.id)).filter((nodeId) => activeNodes.some((node) => node.id === nodeId)),
1222
+ },
1223
+ },
1224
+ interaction: { mode: 'none', maxTurns: 8 },
1225
+ };
1226
+ }
1227
+ function workflowContractCompositionReport(plan, protocol) {
1228
+ const callChain = plan.callChain.length === 0
1229
+ ? '- None'
1230
+ : plan.callChain.map((item) => `- ${item.skill}`).join('\n');
1231
+ const compositionSteps = !plan.composition || plan.composition.steps.length === 0
1232
+ ? '- None'
1233
+ : plan.composition.steps
1234
+ .map((step) => `- ${step.id}: ${step.skill} (${step.source})`)
1235
+ .join('\n');
1236
+ const resolved = !plan.resolvedSkills || plan.resolvedSkills.length === 0
1237
+ ? '- None'
1238
+ : plan.resolvedSkills.map((skill) => `- ${skill.query}: ${skill.status}`).join('\n');
1239
+ const preferenceMode = plan.preference?.mode ?? 'not configured';
1240
+ const preferenceHash = plan.preference?.sourceHash ?? 'none';
1241
+ return `# Composition Report
1242
+
1243
+ ## Workflow Contract
1244
+
1245
+ - Kind: ${protocol.kind}
1246
+ - Nodes: ${protocol.nodes.length}
1247
+ - Required Skill Calls: ${protocol.nodes.reduce((count, node) => count + node.requiredSkillCalls.length, 0)}
1248
+ - Output Schemas: ${protocol.outputSchemas.map((schema) => schema.id).join(', ')}
1249
+ - Wrapper classification: ${wrapperClassification(plan)}
1250
+
1251
+ ## Source Skills
1252
+
1253
+ ${callChain}
1254
+
1255
+ ## Composition Steps
1256
+
1257
+ ${compositionSteps}
1258
+
1259
+ ## Resolved Skills
1260
+
1261
+ ${resolved}
1262
+
1263
+ ## Preferences
1264
+
1265
+ - Preference mode: ${preferenceMode}
1266
+ - Preference hash: ${preferenceHash}
1267
+ `;
1268
+ }
1269
+ function renderSkillReviewMarkdown(plan) {
1270
+ const draft = plan.contentDrafts?.['reference/skill-review.md'];
1271
+ if (draft)
1272
+ return draft;
1273
+ const review = plan.authoringReview;
1274
+ if (review) {
1275
+ const findings = review.findings.length === 0
1276
+ ? '- None.'
1277
+ : review.findings
1278
+ .map((finding) => `- [${finding.severity}]${finding.path ? ` ${finding.path}` : ''}: ${finding.problem}${finding.fix ? ` -> ${finding.fix}` : ''}`)
1279
+ .join('\n');
1280
+ return `# Skill Review\n\nEvidence source: ${review.evidenceSource}.\nPassed: ${review.passed ? 'yes' : 'no'}.\nVoters: ${review.voters ?? 'n/a'}.\nLenses: ${(review.lenses ?? []).join(', ') || 'n/a'}.\nRounds: ${review.rounds ?? 'n/a'}.\nReviewed at: ${review.reviewedAt}.\n\n## Findings\n\n${findings}\n`;
1281
+ }
1282
+ return '# Skill Review\n\nEvidence source: deterministic-check-only.\n\nNo LLM authoring review has been recorded for this Bundle yet. This file is an honest placeholder, not a review approval. Run the `/comet-any` skill-review lane and record its verdict via `comet creator authoring-record <name> --lane skill-review --file <review.json>` to replace this with a real multi-vote review summary.\n';
1283
+ }
1284
+ function authoringLanesReview(plan) {
1285
+ const review = plan.authoringReview;
1286
+ if (review) {
1287
+ return {
1288
+ passed: review.passed,
1289
+ evidenceSource: review.evidenceSource,
1290
+ voters: review.voters ?? null,
1291
+ lenses: review.lenses ?? [],
1292
+ rounds: review.rounds ?? null,
1293
+ blockingFindings: review.findings
1294
+ .filter((finding) => finding.severity === 'critical' || finding.severity === 'important')
1295
+ .map((finding) => finding.problem),
1296
+ warnings: review.findings
1297
+ .filter((finding) => finding.severity === 'minor')
1298
+ .map((finding) => finding.problem),
1299
+ };
1300
+ }
1301
+ return {
1302
+ passed: null,
1303
+ evidenceSource: 'deterministic-check-only',
1304
+ voters: null,
1305
+ lenses: [],
1306
+ rounds: null,
1307
+ blockingFindings: [],
1308
+ warnings: ['No LLM authoring review recorded for this Bundle'],
1309
+ };
1310
+ }
1311
+ function workflowContractArtifacts(plan) {
1312
+ const protocol = plan.workflowProtocol;
1313
+ if (!protocol)
1314
+ throw new Error('workflowProtocol is required for workflow contract package generation');
1315
+ const protocolHash = workflowProtocolHash(protocol);
1316
+ const nodeSkills = workflowContractInternalSkillNames(protocol);
1317
+ const requiredFiles = [
1318
+ 'SKILL.md',
1319
+ ...nodeSkills.map((name) => `../${name}/SKILL.md`),
1320
+ 'reference/resolved-skills.json',
1321
+ 'reference/workflow-protocol.json',
1322
+ 'reference/decision-points.md',
1323
+ 'reference/recovery.md',
1324
+ 'reference/authoring-lanes.json',
1325
+ 'reference/skill-review.md',
1326
+ 'reference/composition-report.md',
1327
+ 'reference/subagents/script-author.md',
1328
+ 'agents/claude/comet-any-script-author.md',
1329
+ 'scripts/comet-plan.mjs',
1330
+ 'scripts/comet-check.mjs',
1331
+ 'scripts/comet-hook-guard.mjs',
1332
+ 'scripts/workflow-state.mjs',
1333
+ 'scripts/workflow-guard.mjs',
1334
+ 'scripts/workflow-handoff.mjs',
1335
+ ...(plan.engineMode === 'none'
1336
+ ? []
1337
+ : ['comet/skill.yaml', 'comet/guardrails.yaml', 'comet/checks.yaml', 'comet/eval.yaml']),
1338
+ ];
1339
+ const artifacts = [
1340
+ artifact('SKILL.md', 'skill', workflowContractEntryMarkdown(plan, protocol, entryDecisionCoreBody(plan))),
1341
+ ...workflowContractRoute(protocol).map((node) => artifact(`../${generatedNodeSkillName(protocol.name, node.id)}/SKILL.md`, 'skill', workflowContractNodeMarkdown(plan, protocol, node, nodeGuidanceBody(plan, protocol, node)))),
1342
+ artifact('scripts/comet-plan.mjs', 'script', workflowContractPlanScript(), true),
1343
+ artifact('scripts/comet-check.mjs', 'script', workflowContractCheckScript(requiredFiles), true),
1344
+ artifact('scripts/comet-hook-guard.mjs', 'script', workflowContractHookGuardScript(), true),
1345
+ artifact('scripts/workflow-state.mjs', 'script', workflowContractStateScript(), true),
1346
+ artifact('scripts/workflow-guard.mjs', 'script', workflowContractGuardScript(), true),
1347
+ artifact('scripts/workflow-handoff.mjs', 'script', workflowContractHandoffScript(), true),
1348
+ jsonArtifact('reference/resolved-skills.json', {
1349
+ schemaVersion: 1,
1350
+ resolvedSkills: plan.resolvedSkills ?? [],
1351
+ workflow: {
1352
+ kind: protocol.kind,
1353
+ nodes: protocol.nodes.map((node) => ({
1354
+ id: node.id,
1355
+ label: node.label,
1356
+ implementation: node.implementation,
1357
+ requiredSkillCalls: node.requiredSkillCalls,
1358
+ outputSchemas: node.outputSchemas,
1359
+ })),
1360
+ },
1361
+ preference: plan.preference ?? null,
1362
+ }),
1363
+ jsonArtifact('reference/workflow-protocol.json', protocol),
1364
+ artifact('reference/decision-points.md', 'reference', plan.contentDrafts?.['reference/decision-points.md'] ??
1365
+ `# Workflow Decision Points\n\n${workflowContractRoute(protocol)
1366
+ .map((node) => `- \`${node.id}\`: confirm Output Schemas ${node.outputSchemas.join(', ') || 'none'}.`)
1367
+ .join('\n')}\n`),
1368
+ artifact('reference/recovery.md', 'reference', plan.contentDrafts?.['reference/recovery.md'] ??
1369
+ `# Workflow Recovery\n\n- State model: \`${protocol.state.kind}\`\n- State path: \`${protocol.state.statePath}\`\n- Resume by reading the first incomplete Workflow Node.\n`),
1370
+ artifact('reference/composition-report.md', 'reference', workflowContractCompositionReport(plan, protocol)),
1371
+ artifact('reference/skill-review.md', 'reference', renderSkillReviewMarkdown(plan)),
1372
+ artifact('reference/subagents/script-author.md', 'reference', portableScriptAuthorBrief()),
1373
+ artifact('agents/claude/comet-any-script-author.md', 'agent', claudeAgentDefinition({
1374
+ name: 'comet-any-script-author',
1375
+ description: 'Use when authoring workflow script contracts for a confirmed comet-any bundle draft.',
1376
+ tools: 'Read, Write, Glob, Grep',
1377
+ title: 'Script Author Agent',
1378
+ body: 'Author the script contract for one comet-any authoring lane. Read the portable brief, write only the assigned report path, and do not publish, install, or run destructive commands.',
1379
+ })),
1380
+ jsonArtifact('reference/authoring-lanes.json', {
1381
+ schemaVersion: 1,
1382
+ protocolHash,
1383
+ lanes: [
1384
+ 'workflow-entry',
1385
+ 'skill-core',
1386
+ 'script-contract',
1387
+ 'platform-agent',
1388
+ 'reference',
1389
+ 'eval',
1390
+ 'skill-review',
1391
+ ],
1392
+ review: authoringLanesReview(plan),
1393
+ }),
1394
+ ...(plan.engineMode === 'none'
1395
+ ? []
1396
+ : [
1397
+ artifact('comet/skill.yaml', 'engine', stringify(workflowContractSkillDefinition(plan, protocol))),
1398
+ artifact('comet/guardrails.yaml', 'engine', stringify({
1399
+ allowedSkills: [plan.name, ...nodeSkills],
1400
+ allowedAgents: [],
1401
+ allowedTools: [],
1402
+ maxIterations: Math.max(nodeSkills.length + 2, 5),
1403
+ maxRetriesPerAction: 2,
1404
+ confirmationRequiredFor: [],
1405
+ })),
1406
+ artifact('comet/checks.yaml', 'engine', stringify(runtimeEvals())),
1407
+ artifact('comet/eval.yaml', 'engine', stringify(workflowContractEvalManifest(plan, protocol))),
1408
+ ]),
1409
+ ];
1410
+ const proposals = [
1411
+ {
1412
+ lane: 'workflow-entry',
1413
+ protocolHash,
1414
+ artifacts: artifacts.filter((item) => item.path === 'SKILL.md'),
1415
+ claims: workflowEntryClaims(),
1416
+ },
1417
+ {
1418
+ lane: 'skill-core',
1419
+ protocolHash,
1420
+ artifacts: artifacts.filter((item) => item.kind === 'skill' && item.path !== 'SKILL.md'),
1421
+ claims: nodeSkills.map((name) => claim('node-skill', `node-skill:${name}`, [`../${name}/SKILL.md`], `Workflow Node Skill ${name}.`, name)),
1422
+ },
1423
+ ];
1424
+ return {
1425
+ workflow: protocol,
1426
+ protocolHash,
1427
+ proposals,
1428
+ artifacts,
1429
+ review: { passed: true, blockingFindings: [], warnings: [] },
1430
+ };
1431
+ }
1432
+ function claim(kind, id, paths, summary, nodeSkill) {
1433
+ return {
1434
+ kind,
1435
+ id,
1436
+ paths,
1437
+ summary,
1438
+ ...(nodeSkill ? { nodeSkill } : {}),
1439
+ };
1440
+ }
1441
+ function workflowEntryClaims() {
1442
+ return [
1443
+ claim('workflow-entry', 'workflow-entry', ['SKILL.md'], 'Entry Skill routes the generated workflow.'),
1444
+ ];
1445
+ }
1446
+ function artifactTarget(packageRoot, artifactPath) {
1447
+ const skillsRoot = path.dirname(packageRoot);
1448
+ const target = path.resolve(packageRoot, artifactPath);
1449
+ const relative = path.relative(skillsRoot, target);
1450
+ if (relative.startsWith('..') || path.isAbsolute(relative)) {
1451
+ throw new Error(`Generated artifact escapes skills root: ${artifactPath}`);
1452
+ }
1453
+ return target;
1454
+ }
1455
+ export async function draftFactorySkillArtifacts(plan) {
1456
+ if (!plan.workflowProtocol) {
1457
+ throw new Error('workflowProtocol is required for workflow contract package generation');
1458
+ }
1459
+ return workflowContractArtifacts(plan);
1460
+ }
1461
+ async function writeFactoryArtifacts(packageRoot, artifacts) {
1462
+ for (const item of artifacts) {
1463
+ const target = artifactTarget(packageRoot, item.path);
1464
+ await fs.mkdir(path.dirname(target), { recursive: true });
1465
+ await fs.writeFile(target, item.content, 'utf8');
1466
+ }
1467
+ }
1468
+ export async function generateFactorySkillPackage(plan) {
1469
+ const packageRoot = path.resolve(plan.root, 'skills', plan.name);
1470
+ const cometRoot = path.join(packageRoot, 'comet');
1471
+ const referenceRoot = path.join(packageRoot, 'reference');
1472
+ if (!plan.workflowProtocol) {
1473
+ throw new Error('workflowProtocol is required for workflow contract package generation');
1474
+ }
1475
+ const internalSkillIds = workflowContractInternalSkillNames(plan.workflowProtocol);
1476
+ const draft = await draftFactorySkillArtifacts(plan);
1477
+ const compositionReportPath = path.join(referenceRoot, 'composition-report.md');
1478
+ if (!draft.review.passed) {
1479
+ const findings = draft.review.blockingFindings
1480
+ .map((finding) => `${finding.code}${finding.path ? ` (${finding.path})` : ''}: ${finding.message}`)
1481
+ .join('\n');
1482
+ throw new Error(`Generated Skill package failed authoring review:\n${findings}`);
1483
+ }
1484
+ await fs.mkdir(packageRoot, { recursive: true });
1485
+ await writeFactoryArtifacts(packageRoot, draft.artifacts);
1486
+ return {
1487
+ packageRoot,
1488
+ skillPath: path.join(packageRoot, 'SKILL.md'),
1489
+ internalSkills: internalSkillIds,
1490
+ unauthoredSubstanceNodes: computeUnauthoredSubstanceNodes(plan),
1491
+ wrapperClassification: wrapperClassification(plan),
1492
+ enginePath: plan.engineMode === 'none' ? null : cometRoot,
1493
+ evalManifestPath: plan.engineMode === 'none' ? null : path.join(cometRoot, 'eval.yaml'),
1494
+ controlPlane: {
1495
+ checksPath: plan.engineMode === 'none' ? null : path.join(cometRoot, 'checks.yaml'),
1496
+ evalManifestPath: plan.engineMode === 'none' ? null : path.join(cometRoot, 'eval.yaml'),
1497
+ compositionReportPath,
1498
+ scripts: draft.artifacts
1499
+ .filter((item) => item.kind === 'script')
1500
+ .map((item) => artifactTarget(packageRoot, item.path)),
1501
+ },
1502
+ platformAgents: [
1503
+ {
1504
+ id: 'comet-any-script-author',
1505
+ platform: 'claude',
1506
+ path: path.join(packageRoot, 'agents', 'claude', 'comet-any-script-author.md'),
1507
+ },
1508
+ ],
1509
+ };
1510
+ }
1511
+ //# sourceMappingURL=package.js.map