@mutagent/helix 0.1.0-alpha.14

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 (357) hide show
  1. package/.claude/skills/mutagent-helix/SKILL.md +113 -0
  2. package/.claude/skills/mutagent-helix/scripts/cli/codex-transcode.ts +143 -0
  3. package/.claude/skills/mutagent-helix/scripts/cli/doctor.ts +111 -0
  4. package/.claude/skills/mutagent-helix/scripts/cli/init.ts +382 -0
  5. package/.claude/skills/mutagent-helix/scripts/cli/run.sh +61 -0
  6. package/CLAUDE.md +193 -0
  7. package/LICENSE +201 -0
  8. package/NOTICE +22 -0
  9. package/README.md +209 -0
  10. package/assets/adl-loop.svg +162 -0
  11. package/assets/system-status.svg +422 -0
  12. package/bin/mutagent-cli.mjs +9950 -0
  13. package/bin/mutagent-helix.mjs +78 -0
  14. package/mutagent-agentspec/.claude/skills/mutagent-agentspec/CLAUDE.md +28 -0
  15. package/mutagent-agentspec/.claude/skills/mutagent-agentspec/SKILL.md +138 -0
  16. package/mutagent-agentspec/.claude/skills/mutagent-agentspec/assets/templates/agentspec.yaml.tpl +247 -0
  17. package/mutagent-agentspec/.claude/skills/mutagent-agentspec/references/frameworks/doc-pins.md +53 -0
  18. package/mutagent-agentspec/.claude/skills/mutagent-agentspec/references/principles.md +91 -0
  19. package/mutagent-agentspec/.claude/skills/mutagent-agentspec/references/requirements.yaml +295 -0
  20. package/mutagent-agentspec/.claude/skills/mutagent-agentspec/references/workflows/orchestrator-protocol.md +302 -0
  21. package/mutagent-agentspec/.claude/skills/mutagent-agentspec/scripts/cli/doctor.ts +116 -0
  22. package/mutagent-agentspec/.claude/skills/mutagent-agentspec/scripts/cli/init.ts +230 -0
  23. package/mutagent-agentspec/.claude/skills/mutagent-agentspec/scripts/cli/run.sh +60 -0
  24. package/mutagent-agentspec/.claude/skills/mutagent-agentspec/scripts/config/resolve-spec-dir.ts +199 -0
  25. package/mutagent-agentspec/.claude/skills/mutagent-agentspec/scripts/contract/agentspec.schema.ts +455 -0
  26. package/mutagent-agentspec/.claude/skills/mutagent-agentspec/scripts/setup/detect.ts +67 -0
  27. package/mutagent-agentspec/.claude/skills/mutagent-agentspec/scripts/validate/validate-spec.ts +93 -0
  28. package/mutagent-agentspec/LICENSE +201 -0
  29. package/mutagent-agentspec/NOTICE +19 -0
  30. package/mutagent-agentspec/README.md +44 -0
  31. package/mutagent-builder/.claude/skills/mutagent-builder/SKILL.md +100 -0
  32. package/mutagent-builder/.claude/skills/mutagent-builder/assets/agents/ai-architect.md +312 -0
  33. package/mutagent-builder/.claude/skills/mutagent-builder/assets/agents/ai-engineer.md +357 -0
  34. package/mutagent-builder/.claude/skills/mutagent-builder/assets/templates/build-report.md.tpl +39 -0
  35. package/mutagent-builder/.claude/skills/mutagent-builder/references/principles.md +31 -0
  36. package/mutagent-builder/.claude/skills/mutagent-builder/references/workflows/build-protocol.md +61 -0
  37. package/mutagent-builder/.claude/skills/mutagent-builder/references/workflows/improve-handoff.md +23 -0
  38. package/mutagent-builder/.claude/skills/mutagent-builder/scripts/cli/run.sh +60 -0
  39. package/mutagent-builder/.claude/skills/mutagent-builder/scripts/handoff/validate-build-input.ts +72 -0
  40. package/mutagent-builder/.claude/skills/mutagent-builder/scripts/sync-spec/check-sync-spec.ts +499 -0
  41. package/mutagent-builder/.claude/skills/mutagent-builder/scripts/verify/spec-impl-coverage.ts +182 -0
  42. package/mutagent-builder/CLAUDE.md +25 -0
  43. package/mutagent-builder/README.md +26 -0
  44. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/README.md +192 -0
  45. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/SKILL.md +352 -0
  46. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/assets/agents/ai-architect.md +256 -0
  47. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/assets/agents/ai-engineer.md +344 -0
  48. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/assets/agents/diagnostics-analyzer.md +576 -0
  49. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/assets/agents/discovery.md +425 -0
  50. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/assets/templates/audit.json.tpl +24 -0
  51. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/assets/templates/audit.md.tpl +49 -0
  52. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/assets/templates/config.yaml.tpl +100 -0
  53. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/assets/templates/pr-body.md.tpl +56 -0
  54. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/assets/templates/report.html.tpl +327 -0
  55. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/assets/templates/shared/README.md +27 -0
  56. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/assets/templates/shared/iter-N-handover.md.tpl +125 -0
  57. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/assets/templates/shared/self-diagnosis-contract.v0.1.0.yaml.tpl +234 -0
  58. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/assets/templates/shared/spec.yaml.tpl +152 -0
  59. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/assets/templates/shared/team.yaml.tpl +127 -0
  60. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/assets/templates/shared/wave-N-dashboard.html.tpl +1712 -0
  61. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/assets/wireframes/diagnostics/WF-2.1-nl-query.md +59 -0
  62. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/assets/wireframes/diagnostics/WF-2.2-tier0-progress.md +58 -0
  63. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/assets/wireframes/diagnostics/WF-2.3-analysis-progress.md +44 -0
  64. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/assets/wireframes/diagnostics/WF-2.4-html-report.md +61 -0
  65. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/assets/wireframes/diagnostics/WF-2.5-rca-detail.md +69 -0
  66. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/assets/wireframes/diagnostics/WF-2.6-stale-warning.md +53 -0
  67. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/assets/wireframes/onboarding/WF-1.1-welcome.md +60 -0
  68. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/assets/wireframes/onboarding/WF-1.2-source-platform-picker.md +41 -0
  69. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/assets/wireframes/onboarding/WF-1.3-source-auth.md +75 -0
  70. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/assets/wireframes/onboarding/WF-1.4-target-picker.md +48 -0
  71. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/assets/wireframes/onboarding/WF-1.5-ask-tool.md +43 -0
  72. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/assets/wireframes/onboarding/WF-1.6-config-review.md +57 -0
  73. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/assets/wireframes/onboarding/WF-1.7-filter-defaults.md +52 -0
  74. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/assets/wireframes/onboarding/WF-1.8-first-run.md +59 -0
  75. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/examples/sample-findings.json +92 -0
  76. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/examples/sample-meta.json +47 -0
  77. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/references/adapter-strategy.md +75 -0
  78. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/references/config-migration.md +84 -0
  79. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/references/config.md +159 -0
  80. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/references/filter-search-matrix.md +66 -0
  81. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/references/harness-knowledge.md +22 -0
  82. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/references/memory-format.md +78 -0
  83. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/references/onboarding-decisions.yaml +187 -0
  84. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/references/operation-inventory.md +59 -0
  85. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/references/overview.md +167 -0
  86. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/references/reference.md +119 -0
  87. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/references/script-index.md +101 -0
  88. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/references/source-adapter-contract.md +93 -0
  89. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/references/source-platforms/claude-code-transcripts.md +66 -0
  90. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/references/source-platforms/codex-transcripts.md +78 -0
  91. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/references/source-platforms/codex.md +145 -0
  92. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/references/source-platforms/install-paths.md +57 -0
  93. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/references/source-platforms/langfuse.md +178 -0
  94. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/references/source-platforms/local-jsonl.md +55 -0
  95. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/references/source-platforms/openobserve.md +102 -0
  96. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/references/source-platforms/otel.md +63 -0
  97. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/references/target-platforms/cloud-rest.md +84 -0
  98. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/references/target-platforms/local-claude.md +65 -0
  99. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/references/target-platforms/local-cloud-agent-sdk.md +92 -0
  100. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/references/target-platforms/local-codex.md +72 -0
  101. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/references/target-platforms/local-cursor.md +108 -0
  102. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/references/target-platforms/local-mastra.md +77 -0
  103. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/references/target-platforms/local-opencode.md +70 -0
  104. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/references/workflows/apply-pr-comment-format.md +82 -0
  105. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/references/workflows/diagnostics.md +35 -0
  106. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/references/workflows/handover-contract.md +247 -0
  107. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/references/workflows/onboarding.md +300 -0
  108. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/references/workflows/orchestrator-protocol.md +1861 -0
  109. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/references/workflows/rca.md +331 -0
  110. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/references/workflows/rendering-anatomy.md +314 -0
  111. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/references/workflows/schedule-prep.md +100 -0
  112. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/references/workflows/scope-model.md +128 -0
  113. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/references/workflows/verification-methodology.md +174 -0
  114. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/aggregate/sort-findings.ts +0 -0
  115. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/awareness/blind-spots.ts +167 -0
  116. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/awareness/llm-sample.ts +681 -0
  117. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/cli/doctor.ts +215 -0
  118. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/cli/init.ts +1013 -0
  119. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/cli/install-agents.ts +350 -0
  120. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/cli/run.sh +61 -0
  121. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/cli/shared-templates.ts +79 -0
  122. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/config/load.ts +392 -0
  123. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/config/resolve-credential.ts +120 -0
  124. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/config/schema.ts +641 -0
  125. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/config/validate.ts +134 -0
  126. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/context/build-diagnosis-context.ts +417 -0
  127. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/context/load-context.ts +105 -0
  128. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/contract/types.ts +166 -0
  129. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/enrich/build-render-input.ts +1964 -0
  130. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/enrich/corpus-severity.ts +172 -0
  131. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/enrich/dismissal-match.ts +270 -0
  132. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/enrich/rank-remedies.ts +75 -0
  133. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/hooks/install-hooks.sh +46 -0
  134. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/hooks/pre-push.sh +78 -0
  135. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/invocation/parse-brief.ts +188 -0
  136. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/library/match.ts +114 -0
  137. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/library/paths.ts +95 -0
  138. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/library/store.ts +535 -0
  139. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/library/types.ts +181 -0
  140. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/lint/template-inline-js.ts +267 -0
  141. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/memory/append.ts +188 -0
  142. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/memory/read.ts +218 -0
  143. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/normalize/platforms/entity-context.ts +686 -0
  144. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/normalize/read-unitf.ts +267 -0
  145. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/normalize/trace.ts +1078 -0
  146. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/normalize/unitf-adapter.ts +0 -0
  147. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/normalize/unitf-types.ts +213 -0
  148. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/report/persist-selections.ts +174 -0
  149. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/report/render.ts +3254 -0
  150. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/run/diagnose.ts +64 -0
  151. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/run/session.ts +167 -0
  152. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/sample/caps.ts +345 -0
  153. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/sample/deep-read-gate.ts +424 -0
  154. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/sample/representative.ts +584 -0
  155. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/scan/objection.ts +224 -0
  156. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/scan/trajectory.ts +489 -0
  157. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/self-diagnostics/dispatch.ts +135 -0
  158. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/self-diagnostics/probe.ts +170 -0
  159. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/setup/detect.ts +307 -0
  160. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/setup/ensure-cli.ts +315 -0
  161. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/setup/reconfigure.ts +77 -0
  162. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/setup/verify-agents.ts +207 -0
  163. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/slicer.ts +166 -0
  164. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/source/adapters/claude-code.ts +17 -0
  165. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/source/adapters/codex.ts +11 -0
  166. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/source/adapters/langfuse.ts +17 -0
  167. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/source/adapters/local-jsonl.ts +12 -0
  168. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/source/adapters/otel.ts +12 -0
  169. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/source/index.ts +54 -0
  170. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/source/registry.ts +45 -0
  171. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/source/types.ts +86 -0
  172. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/stale-detector.ts +74 -0
  173. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/test/render-playwright.cli.ts +477 -0
  174. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/tier0/claude-code.ts +133 -0
  175. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/tier0/langfuse.ts +143 -0
  176. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/tier0-scan.ts +423 -0
  177. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/validate/completeness-check.ts +436 -0
  178. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/validate/doc-refs.ts +190 -0
  179. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/validate/finalize-gate.ts +417 -0
  180. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/validate/findings-contract.ts +628 -0
  181. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/validate/render-js-syntax.ts +188 -0
  182. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/validate/report-checklist.yaml +217 -0
  183. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/validate/trace-shape.ts +262 -0
  184. package/mutagent-diagnostics/.claude/skills/mutagent-diagnostics/scripts/validate/wave6-checklist.ts +326 -0
  185. package/mutagent-diagnostics/CLAUDE.md +41 -0
  186. package/mutagent-diagnostics/LICENSE +201 -0
  187. package/mutagent-diagnostics/NOTICE +18 -0
  188. package/mutagent-diagnostics/README.md +343 -0
  189. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/SKILL.md +548 -0
  190. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/assets/agents/audit-executor.md +169 -0
  191. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/assets/agents/dataset-builder.md +160 -0
  192. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/assets/agents/discovery.md +425 -0
  193. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/assets/agents/evaluator.md +1108 -0
  194. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/assets/brand/theme.css +213 -0
  195. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/assets/brand/wordmark.html +9 -0
  196. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/lenses/context-flow-lens.md +85 -0
  197. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/lenses/data-lens.md +47 -0
  198. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/lenses/decision-lens.md +48 -0
  199. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/lenses/methodology-critic-lens.md +53 -0
  200. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/lenses/trajectory-lens.md +44 -0
  201. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/references/build-review-interface.md +83 -0
  202. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/references/edd-loop.md +134 -0
  203. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/references/error-analysis.md +113 -0
  204. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/references/eval-audit.md +154 -0
  205. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/references/eval-stage.md +168 -0
  206. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/references/generate-synthetic-data.md +81 -0
  207. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/references/grounded-adjudication.md +221 -0
  208. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/references/memory-format.md +65 -0
  209. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/references/methodology.md +201 -0
  210. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/references/operation-inventory.md +197 -0
  211. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/references/validate-evaluator.md +125 -0
  212. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/references/workflows/orchestrator-protocol.md +300 -0
  213. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/references/write-judge-prompt.md +123 -0
  214. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/schemas/behavior-tree.schema.yaml +73 -0
  215. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/schemas/dataset.schema.yaml +66 -0
  216. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/schemas/edd-change-request.schema.yaml +114 -0
  217. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/schemas/eval-matrix.schema.yaml +74 -0
  218. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/schemas/flow-graph.schema.yaml +69 -0
  219. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/schemas/flow-profile.schema.yaml +49 -0
  220. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/schemas/methodology-review.schema.yaml +40 -0
  221. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/schemas/scorecard.schema.yaml +85 -0
  222. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/agent-dispatch.ts +0 -0
  223. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/aggregate-discover.ts +543 -0
  224. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/artifact-paths.ts +115 -0
  225. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/assemble-scorecard.ts +172 -0
  226. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/build-dataset.ts +186 -0
  227. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/build-evals.ts +93 -0
  228. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/build-review-ui.ts +393 -0
  229. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/check-method-router.ts +170 -0
  230. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/cli/aggregate.ts +112 -0
  231. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/cli/audit-run.ts +182 -0
  232. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/cli/doctor.ts +211 -0
  233. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/cli/dogfood.ts +133 -0
  234. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/cli/init.ts +601 -0
  235. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/cli/methodology-review.ts +122 -0
  236. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/cli/prep.ts +295 -0
  237. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/cli/profile-subject.ts +165 -0
  238. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/cli/run.sh +56 -0
  239. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/cli/variance-check.ts +105 -0
  240. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/code-eval.ts +248 -0
  241. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/code-quality-verdict.ts +285 -0
  242. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/codegen-evals.ts +173 -0
  243. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/cold-start-project.ts +151 -0
  244. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/cold-start-sampler.ts +267 -0
  245. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/config/load.ts +343 -0
  246. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/config/schema.ts +380 -0
  247. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/contracts/agentspec-evals.ts +85 -0
  248. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/contracts/dataset.ts +149 -0
  249. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/contracts/eval-engine.ts +118 -0
  250. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/contracts/eval-matrix.ts +577 -0
  251. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/contracts/eval-types.ts +1074 -0
  252. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/contracts/flow-graph.ts +194 -0
  253. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/contracts/types.ts +303 -0
  254. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/contracts/validation.ts +193 -0
  255. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/derive-dataset.ts +152 -0
  256. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/determine-outcome.ts +219 -0
  257. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/diff-discriminate.ts +160 -0
  258. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/discover-criteria.ts +348 -0
  259. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/edd/change-request.ts +232 -0
  260. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/edd/edd-types.ts +210 -0
  261. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/edd/variance-gate.ts +186 -0
  262. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/emit-completeness.ts +111 -0
  263. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/eval-engine.ts +160 -0
  264. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/evaluate.ts +333 -0
  265. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/flow-graph.ts +230 -0
  266. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/judge-prompt-template.ts +253 -0
  267. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/judge-provider.ts +135 -0
  268. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/lint-grounding.ts +229 -0
  269. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/lint-uniformity.ts +168 -0
  270. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/living-suite.ts +109 -0
  271. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/load-bundle.ts +203 -0
  272. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/load-profile-vocab.ts +64 -0
  273. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/load-profile.ts +106 -0
  274. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/mask.ts +138 -0
  275. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/materialize-dataset.ts +113 -0
  276. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/matrix-judge.ts +750 -0
  277. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/memory/append.ts +215 -0
  278. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/memory/read.ts +168 -0
  279. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/persist-eval-criteria.ts +232 -0
  280. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/prep-tasks.ts +125 -0
  281. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/profile-subject.ts +310 -0
  282. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/publish-report.ts +131 -0
  283. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/read-unitf-traces.ts +81 -0
  284. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/render-build-cards.ts +195 -0
  285. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/render-discover-report.ts +1640 -0
  286. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/render-eval-report.ts +3838 -0
  287. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/render-report.ts +212 -0
  288. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/resolve-credential.ts +110 -0
  289. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/resolve-ref.ts +98 -0
  290. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/result-verify.ts +129 -0
  291. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/route-failures.ts +330 -0
  292. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/run-deterministic.ts +367 -0
  293. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/run-evaluate.ts +719 -0
  294. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/run-judge.ts +155 -0
  295. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/run-pipeline.ts +175 -0
  296. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/sample-traces.ts +210 -0
  297. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/self-audit.ts +387 -0
  298. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/source-map.ts +106 -0
  299. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/subject-profile.ts +134 -0
  300. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/substrate.ts +162 -0
  301. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/sync-eval-criteria.ts +244 -0
  302. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/ui-slots.ts +119 -0
  303. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/unitf-to-evaltrace.ts +284 -0
  304. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/validate-judge.ts +358 -0
  305. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/scripts/variance-compare.ts +177 -0
  306. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/subjects/mutagent-diagnostics/behavior-tree.yaml +140 -0
  307. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/subjects/mutagent-diagnostics/eval-matrix.yaml +1270 -0
  308. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/subjects/mutagent-diagnostics/methodology-review.yaml +105 -0
  309. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/workflows/audit.workflow.js +82 -0
  310. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/workflows/data-leak.workflow.js +236 -0
  311. package/mutagent-evaluator/.claude/skills/mutagent-evaluator/workflows/variance.workflow.js +163 -0
  312. package/mutagent-evaluator/CLAUDE.md +45 -0
  313. package/mutagent-evaluator/LICENSE +201 -0
  314. package/mutagent-evaluator/NOTICE +23 -0
  315. package/mutagent-evaluator/README.md +88 -0
  316. package/mutagent-optimize/.claude/skills/mutagent-optimize/SKILL.md +287 -0
  317. package/mutagent-optimize/.claude/skills/mutagent-optimize/scripts/contracts/amend-request.ts +503 -0
  318. package/mutagent-optimize/.claude/skills/mutagent-optimize/scripts/improve-loop-run.ts +304 -0
  319. package/mutagent-optimize/.claude/skills/mutagent-optimize/scripts/loop-state-cli.ts +300 -0
  320. package/mutagent-optimize/.claude/skills/mutagent-optimize/scripts/loop-state.ts +440 -0
  321. package/mutagent-optimize/CLAUDE.md +49 -0
  322. package/mutagent-optimize/README.md +26 -0
  323. package/mutagent-orchestrator/CLAUDE.md +102 -0
  324. package/mutagent-orchestrator/README.md +20 -0
  325. package/mutagent-orchestrator/assets/agents/discovery.md +425 -0
  326. package/mutagent-orchestrator/assets/agents/dogfood-monitor.md +266 -0
  327. package/mutagent-orchestrator/assets/agents/monitor.md +258 -0
  328. package/mutagent-orchestrator/orchestrator.md +782 -0
  329. package/mutagent-orchestrator/references/MONITORING.md +209 -0
  330. package/mutagent-orchestrator/references/config-fields.md +132 -0
  331. package/mutagent-orchestrator/references/config-migration.md +132 -0
  332. package/mutagent-orchestrator/references/index-registry.md +92 -0
  333. package/mutagent-orchestrator/routing.yaml +391 -0
  334. package/mutagent-orchestrator/scripts/config-schema.ts +1010 -0
  335. package/mutagent-orchestrator/scripts/dispatch.ts +439 -0
  336. package/mutagent-orchestrator/scripts/dogfood/extract-feedback.ts +203 -0
  337. package/mutagent-orchestrator/scripts/dogfood/reconstruct-trajectory.ts +327 -0
  338. package/mutagent-orchestrator/scripts/dogfood/render-dogfood-report.ts +347 -0
  339. package/mutagent-orchestrator/scripts/dogfood/resolve-subagents.ts +160 -0
  340. package/mutagent-orchestrator/scripts/dogfood/run-report.ts +264 -0
  341. package/mutagent-orchestrator/scripts/dogfood/slack-thread.ts +106 -0
  342. package/mutagent-orchestrator/scripts/dogfood/types.ts +257 -0
  343. package/mutagent-orchestrator/scripts/eval-routing.ts +753 -0
  344. package/mutagent-orchestrator/scripts/gate.ts +219 -0
  345. package/mutagent-orchestrator/scripts/handover-contract.ts +362 -0
  346. package/mutagent-orchestrator/scripts/index/build-index.ts +351 -0
  347. package/mutagent-orchestrator/scripts/index/render-index.ts +110 -0
  348. package/mutagent-orchestrator/scripts/monitor/slack-notify.ts +111 -0
  349. package/mutagent-orchestrator/scripts/monitor/triggers.ts +162 -0
  350. package/mutagent-orchestrator/scripts/onboarding-check.ts +369 -0
  351. package/mutagent-orchestrator/scripts/render-roster.ts +308 -0
  352. package/mutagent-orchestrator/scripts/resolve-credential.ts +185 -0
  353. package/mutagent-orchestrator/scripts/resolve-paths.ts +114 -0
  354. package/mutagent-orchestrator/scripts/slack/format.ts +63 -0
  355. package/mutagent-orchestrator/scripts/slack/post.ts +115 -0
  356. package/mutagent-orchestrator/scripts/sync-index.ts +311 -0
  357. package/package.json +64 -0
@@ -0,0 +1,1010 @@
1
+ import * as fs from "node:fs";
2
+ import * as path from "node:path";
3
+ import { type Static, Type } from "@sinclair/typebox";
4
+ import { TypeCompiler } from "@sinclair/typebox/compiler";
5
+ import { parse as parseYaml } from "yaml";
6
+
7
+ import { AdlStage } from "./handover-contract.ts";
8
+ import { resolveConfigPath } from "./resolve-paths.ts";
9
+
10
+ // ---------------------------------------------------------------------------
11
+ // C1-C3 — the MutagentConfig schema for the LOCAL `.mutagent/config.yaml` (v0.2.0).
12
+ //
13
+ // ONE config file drives the orchestrator + all skills. The v0.2.0 contract has
14
+ // THREE top-level blocks (the false `stages` (phase) vs skill (tool) axis is
15
+ // collapsed — every skill IS a stage, so the config is keyed by SKILL under a
16
+ // single `lifecycle` block):
17
+ //
18
+ // global — framework-wide SHARED resources (helix owns; TYPED): provider
19
+ // credential REFS · repo/workspace · default + judge models ·
20
+ // brand/theme · PROJECT-WIDE context links · the SOURCES catalog
21
+ // (where traces come from) · the TARGETS catalog (where fixes are
22
+ // applied). Sources/targets are bound BY ROLE, not by ref — a
23
+ // source-consumer (evaluate/diagnose) binds `global.sources`, a
24
+ // target-writer (build/diagnose-apply) binds `global.targets`.
25
+ // lifecycle — per-skill behavior, NESTED + keyed by SKILL NAME (agentspec ·
26
+ // builder · evaluator · diagnostics). The orchestrator TYPES only
27
+ // the gate-relevant fields (`spec_dir` / `context` / `apply` /
28
+ // `judge_runtime`); everything else is the skill's OPAQUE knobs
29
+ // (passthrough — each standalone skill validates its OWN section
30
+ // with its OWN schema, NEVER cross-imported).
31
+ // triggers — the FUTURE monitor, GLOBAL per stage. Ships DISABLED
32
+ // (enabled:false, empty rules). Absorbs the old diagnostics
33
+ // schedule / trigger_rules / heartbeat (now IN the trigger block).
34
+ //
35
+ // SHAPE vs COMPLETENESS — a deliberate split (unchanged from v0.1.0):
36
+ // - This SCHEMA enforces SHAPE only: closed objects at the levels the
37
+ // orchestrator owns, correct types, the frozen version, valid enum values.
38
+ // A present provider must carry both `name` and `credentials_ref`.
39
+ // - It does NOT enforce onboarding completeness. The sub-fields of `global`
40
+ // are OPTIONAL so a PARTIAL, mid-onboarding config still validates
41
+ // STRUCTURALLY. Whether a config is COMPLETE (has creds, a repo, models, a
42
+ // resolvable source/target for the invoked stage) is the job of
43
+ // scripts/onboarding-check.ts + scripts/gate.ts.
44
+ // - The per-skill `lifecycle.<skill>` sections are OPEN (additionalProperties:
45
+ // true) beyond the typed gate fields — the skill owns the rest.
46
+ // - Consequence (by design): a raw-secret-SHAPED `credentials_ref` still
47
+ // validates structurally — the schema cannot tell a leaked secret from an
48
+ // env-var ref. The no-raw-secret rule is a CONVENTION enforced by docs +
49
+ // review; fixtures use env-var NAMES only.
50
+ //
51
+ // Design invariants (mirror scripts/handover-contract.ts + scripts/sync-index.ts):
52
+ // - Pure functions + a thin CLI wrapper. No clock, no random, no network.
53
+ // - `loadConfig` reads an INJECTED path — never resolved here. Path resolution
54
+ // (the LOCAL install-dir `.mutagent/`, via resolve-paths.ts) happens only in
55
+ // the thin CLI, never in the pure core, so tests stay deterministic against
56
+ // committed fixtures.
57
+ //
58
+ // NOTE: the per-stage keys of `triggers` reuse the ROUTING `AdlStage` enum
59
+ // exported from handover-contract.ts (same package — allowed). That set
60
+ // (build|evaluate|diagnose|improve|audit) is the routed-ACTION classification;
61
+ // it intentionally differs from sync-index.ts's directory-CLASSIFICATION enum.
62
+ // Don't conflate.
63
+ // ---------------------------------------------------------------------------
64
+
65
+ /** The FROZEN config-contract version. Bump only via an explicit migration. */
66
+ export const CONFIG_VERSION = "0.2.0" as const;
67
+
68
+ /**
69
+ * The legacy version(s) whose configs must NOT be parsed at runtime — the loader
70
+ * detects them and emits `{ ok:false, legacy:true }` so the caller can route to
71
+ * `migration-required`. Hard-cut: no static migrate script, no old-shape parse.
72
+ */
73
+ export const LEGACY_CONFIG_VERSIONS = ["0.1.0"] as const;
74
+
75
+ // ── Categorical constants (no magic strings) ────────────────────────────────
76
+
77
+ /**
78
+ * Source platforms a `global.sources[]` entry can pull traces from. Closed enum →
79
+ * the config audit can detect an undeclared / typo'd platform. Mirrors the
80
+ * source platforms the diagnostics + evaluator skills support.
81
+ */
82
+ export const SourcePlatform = {
83
+ Langfuse: "langfuse",
84
+ Otel: "otel",
85
+ LocalJsonl: "local-jsonl",
86
+ ClaudeCode: "claude-code",
87
+ Codex: "codex",
88
+ } as const;
89
+ export type SourcePlatformValue =
90
+ (typeof SourcePlatform)[keyof typeof SourcePlatform];
91
+
92
+ /**
93
+ * Normalizer format hint for a source (how to parse the records). Consumed by the
94
+ * source-fetch/normalize path in `@mutagent/tools` (+ the evaluator/diagnostics
95
+ * fetch ports) to pick the per-platform record parser.
96
+ *
97
+ * `unitf` (F1) is the pass-through format: the records are ALREADY conformant
98
+ * UniTF jsonl (emitted by the code-run capture WRAP), so the fetch path SKIPS
99
+ * per-platform normalization and reads the jsonl directly. Pairs with
100
+ * `platform: local-jsonl` + `paths: […]`.
101
+ */
102
+ export const SourceFormat = {
103
+ LangfuseExport: "langfuse-export",
104
+ ClaudeCode: "claude-code",
105
+ Codex: "codex",
106
+ Raw: "raw",
107
+ /** Pre-normalized UniTF jsonl — read directly, skip per-platform normalize (F1). */
108
+ Unitf: "unitf",
109
+ } as const;
110
+ export type SourceFormatValue = (typeof SourceFormat)[keyof typeof SourceFormat];
111
+
112
+ /** Latency-unit override for a source (`auto` = infer from the record). */
113
+ export const LatencyUnit = {
114
+ Auto: "auto",
115
+ Ms: "ms",
116
+ S: "s",
117
+ } as const;
118
+ export type LatencyUnitValue = (typeof LatencyUnit)[keyof typeof LatencyUnit];
119
+
120
+ /**
121
+ * Target platforms a `global.targets[]` entry can write a fix TO. Closed enum.
122
+ * Local-agent markdown, local code-construct frameworks, a local SKILL directory,
123
+ * cloud REST, or a report-only sink (no target write).
124
+ */
125
+ export const TargetPlatform = {
126
+ LocalClaude: "local-claude",
127
+ LocalCodex: "local-codex",
128
+ LocalCursor: "local-cursor",
129
+ LocalOpencode: "local-opencode",
130
+ LocalMastra: "local-mastra",
131
+ LocalCloudAgentSdk: "local-cloud-agent-sdk",
132
+ // A local SKILL directory (SKILL.md + references + assets). A skill is NOT one
133
+ // .md-per-agent — its target root is the skill DIR; it applies via the SAME
134
+ // markdown worktree-PR path (no build), its skillspec is the .meta/prd.yaml (D2).
135
+ LocalSkill: "local-skill",
136
+ CloudRest: "cloud-rest",
137
+ ReportOnly: "report-only",
138
+ } as const;
139
+ export type TargetPlatformValue =
140
+ (typeof TargetPlatform)[keyof typeof TargetPlatform];
141
+
142
+ /**
143
+ * What KIND of subject a target writes to (D2 subject-kind axis). `agent` = a
144
+ * single .md / code-construct agent (the historical default). `skill` = a skill
145
+ * directory whose SSoT is its `.meta/prd.yaml` (the annexed skillspec) — routed
146
+ * to skill-builder's wave, applied via the markdown transport. `code` = a CODE
147
+ * subject: a spec-FIRST framework/harness implementation (mastra / cloud-agent-sdk
148
+ * / a `harness:<x>` target) whose realized source is the impl and whose SSoT is
149
+ * the `agentspec.yaml` (def→impl cascade) — the ⑤ IMPROVE loop treats "converged"
150
+ * for a `code` subject as BOTH the subject's own test suite green AND a code-quality
151
+ * evaluator verdict (Wave-2 W2I1). Applied via `apply.kind: code-pr` (full TDD in the
152
+ * worktree, not markdown). Optional on a target entry; absent ⇒ `agent` (back-compatible
153
+ * with pre-D2 configs). ADDITIVE — the value only widens the closed subject enum; it
154
+ * introduces no new required fields and no restructuring (a `code` target reuses the
155
+ * existing `code_refs` reserved link + `apply.kind: code-pr`).
156
+ */
157
+ export const TargetSubject = {
158
+ Agent: "agent",
159
+ Skill: "skill",
160
+ Code: "code",
161
+ } as const;
162
+ export type TargetSubjectValue =
163
+ (typeof TargetSubject)[keyof typeof TargetSubject];
164
+
165
+ /** Whether a target's writes go through local files (worktree) or a remote API. */
166
+ export const TargetMode = {
167
+ Local: "local",
168
+ Remote: "remote",
169
+ } as const;
170
+ export type TargetModeValue = (typeof TargetMode)[keyof typeof TargetMode];
171
+
172
+ /**
173
+ * HOW a fix is applied to a target (`report-only` ⇒ no target write).
174
+ *
175
+ * `apply.kind` BINDS to a `mutagent-cli apply` TARGET ADAPTER (DC-5), not a prose
176
+ * recipe (see `@mutagent/tools` src/apply/binding.ts `adapterIdForKind`):
177
+ * code-pr → worktree-PR adapter (git worktree → lint/typecheck → PR)
178
+ * markdown → worktree-PR adapter (NO build — .md agent AND skill dir path)
179
+ * cloud-deploy → REST adapter (non-destructive create-rev + activate) OR vendor-CLI
180
+ * report-only → report-only adapter (read + dryRun only; no write)
181
+ * The shared CLI is the transport; the skill layer gates BEFORE it (DC-1). Adding
182
+ * a new ApplyKind here requires a matching adapter branch in binding.ts.
183
+ */
184
+ export const ApplyKind = {
185
+ CodePr: "code-pr",
186
+ Markdown: "markdown",
187
+ CloudDeploy: "cloud-deploy",
188
+ ReportOnly: "report-only",
189
+ } as const;
190
+ export type ApplyKindValue = (typeof ApplyKind)[keyof typeof ApplyKind];
191
+
192
+ // ── Shared building-block schemas ────────────────────────────────────────────
193
+
194
+ /**
195
+ * A credential REFERENCE — an ENV-VAR NAME (string) or an object that also pins
196
+ * an explicit file to read first (`{ env, path? }`). NEVER a raw secret value
197
+ * (no-raw-secret contract; enforced by convention + review, not by the schema).
198
+ * Mirrors the `CredentialRef` type in scripts/resolve-credential.ts (same package).
199
+ */
200
+ export const CredentialRefSchema = Type.Union([
201
+ Type.String({ minLength: 1 }),
202
+ Type.Object(
203
+ {
204
+ // Env-var NAME to read the secret from. Consumer: resolve-credential.ts.
205
+ env: Type.String({ minLength: 1 }),
206
+ // Optional dotenv file to source FIRST before the process env. Consumer:
207
+ // resolve-credential.ts (explicit-file-then-env precedence).
208
+ path: Type.Optional(Type.String({ minLength: 1 })),
209
+ },
210
+ { additionalProperties: false },
211
+ ),
212
+ ]);
213
+ export type CredentialRefValue = Static<typeof CredentialRefSchema>;
214
+
215
+ /**
216
+ * A PROJECT-WIDE (or stage-specific) context link — a pointer to a supplementary
217
+ * doc with the WHAT / WHY / WHEN so a skill knows what it is, why it matters, and
218
+ * when to consult it. All four fields REQUIRED (a link with no rationale is noise).
219
+ */
220
+ export const ContextLinkSchema = Type.Object(
221
+ {
222
+ // Relative path to the supplementary doc. Consumer: the skills (evaluator /
223
+ // diagnostics) load it as stage context; the orchestrator passes it through.
224
+ path: Type.String({ minLength: 1 }),
225
+ // WHAT the doc is (one line). Consumer: the loading skill's context banner.
226
+ what: Type.String({ minLength: 1 }),
227
+ // WHY it matters. Consumer: the loading skill (relevance rationale).
228
+ why: Type.String({ minLength: 1 }),
229
+ // WHEN to consult it. Consumer: the loading skill (load-timing hint).
230
+ when: Type.String({ minLength: 1 }),
231
+ },
232
+ { additionalProperties: false },
233
+ );
234
+ export type ContextLink = Static<typeof ContextLinkSchema>;
235
+
236
+ // ── `global` — framework-wide shared resources (orchestrator-typed) ───────────
237
+
238
+ /**
239
+ * A provider credential REFERENCE — `credentials_ref` is an env-var NAME (or a
240
+ * `{env,path}` ref), never a raw secret value. A present provider must carry both.
241
+ */
242
+ export const ProviderSchema = Type.Object(
243
+ {
244
+ // Provider id (e.g. `anthropic` / `google`). Consumer: resolve-credential.ts +
245
+ // the in-house judge runtime (evaluator) provider wiring.
246
+ name: Type.String({ minLength: 1 }),
247
+ // Env-var NAME (or {env,path}) for the provider key — NEVER a raw secret.
248
+ // Consumer: onboarding-check.ts (provider floor) + resolve-credential.ts.
249
+ credentials_ref: CredentialRefSchema,
250
+ },
251
+ { additionalProperties: false },
252
+ );
253
+ export type Provider = Static<typeof ProviderSchema>;
254
+
255
+ /** Repo + workspace location. Relative `path` only (determinism: never absolute). */
256
+ export const WorkspaceSchema = Type.Object(
257
+ {
258
+ // The target repo slug. Consumer: onboarding-check.ts (target-writing floor
259
+ // requires it) + the build/diagnose-apply worktree setup.
260
+ repo: Type.Optional(Type.String({ minLength: 1 })),
261
+ // Relative workspace path (never absolute — determinism). Consumer:
262
+ // resolve-paths.ts (locates the install/init dir).
263
+ path: Type.Optional(Type.String({ minLength: 1 })),
264
+ },
265
+ { additionalProperties: false },
266
+ );
267
+ export type Workspace = Static<typeof WorkspaceSchema>;
268
+
269
+ /**
270
+ * The default model + the pinned judge model. `judge_model` (renamed from
271
+ * `pinned_judge` in v0.2.0) is the C-PIN pinned judge stamped on every scorecard;
272
+ * `agent-dispatch` judge_runtime ⇒ the host runtime's model (no provider key).
273
+ */
274
+ export const ModelsSchema = Type.Object(
275
+ {
276
+ // The default execution model + the JUDGE FALLBACK (used when `judge_model` is
277
+ // unset). Consumer: onboarding-check.ts (default-model floor for evaluate/build)
278
+ // + the evaluator run. ASYMMETRY: diagnostics IGNORES `models.default` — it runs
279
+ // host-runtime agent-dispatch, so a default model is not part of its floor.
280
+ default: Type.Optional(Type.String({ minLength: 1 })),
281
+ // The C-PIN pinned judge model stamped on every scorecard (renamed from
282
+ // `pinned_judge` in v0.2.0). Consumer: onboarding-check.ts (judge base floor for
283
+ // evaluate/audit) + the evaluator scorecard stamp.
284
+ judge_model: Type.Optional(Type.String({ minLength: 1 })),
285
+ },
286
+ { additionalProperties: false },
287
+ );
288
+ export type Models = Static<typeof ModelsSchema>;
289
+
290
+ /**
291
+ * Dashboard brand / theme styling. REPORT STYLING only — consumed by the styled
292
+ * HTML report renderers (evaluator + diagnostics report tabs) for the adapter-logo
293
+ * look-and-feel. Has NO effect on gating/onboarding (purely cosmetic).
294
+ */
295
+ export const BrandSchema = Type.Object(
296
+ {
297
+ // The theme name the report renderers key their palette/logo off. Consumer:
298
+ // the evaluator/diagnostics HTML report renderers (styling only).
299
+ theme: Type.Optional(Type.String({ minLength: 1 })),
300
+ },
301
+ { additionalProperties: false },
302
+ );
303
+ export type Brand = Static<typeof BrandSchema>;
304
+
305
+ /**
306
+ * One SOURCE catalog entry — where traces live. Bound BY ROLE (source-consumers
307
+ * evaluate/diagnose bind `global.sources`); a single entry auto-binds. When
308
+ * MULTIPLE exist, an entry marked `default: true` is auto-selected (the SELECTION
309
+ * contract); with no default, the operator picks at RUN time (needs-selection).
310
+ * `paths` (file sources) is mutually exclusive with `endpoint` (remote); the
311
+ * schema tolerates both, onboarding cares.
312
+ */
313
+ export const SourceSchema = Type.Object(
314
+ {
315
+ // The catalog key the operator names the source by. Consumer: onboarding-check.ts
316
+ // (resolveSourceByRole surfaces `entry.name`) + the run-time confirm/pick prompt.
317
+ name: Type.String({ minLength: 1 }),
318
+ // Which platform the traces live on. Consumer: the `@mutagent/tools` fetch path
319
+ // (+ evaluator/diagnostics fetch ports) picks the per-platform reader.
320
+ platform: Type.Union([
321
+ Type.Literal(SourcePlatform.Langfuse),
322
+ Type.Literal(SourcePlatform.Otel),
323
+ Type.Literal(SourcePlatform.LocalJsonl),
324
+ Type.Literal(SourcePlatform.ClaudeCode),
325
+ Type.Literal(SourcePlatform.Codex),
326
+ ]),
327
+ // SELECTION contract — a catalog entry marked `default: true` is auto-selected
328
+ // when multiple sources exist. Exactly one default ⇒ resolved-default; >1 default
329
+ // ⇒ multiple-defaults (config error); 0 defaults ⇒ needs-selection (pick at run).
330
+ // Consumer: onboarding-check.ts resolveByRole; the run-time confirm/pick prompt.
331
+ default: Type.Optional(Type.Boolean()),
332
+ // Remote-platform project/workspace slug (e.g. the Langfuse project). Consumer:
333
+ // the `@mutagent/tools` remote fetch path (scopes the query).
334
+ project: Type.Optional(Type.String({ minLength: 1 })),
335
+ // Remote-platform base URL (OTel/REST). Mutually exclusive with `paths` (file
336
+ // sources). Consumer: the `@mutagent/tools` remote fetch path.
337
+ endpoint: Type.Optional(Type.String({ minLength: 1 })),
338
+ // Env-var NAME (or {env,path}) for the platform read token. Consumer:
339
+ // resolve-credential.ts → the `@mutagent/tools` remote fetch path.
340
+ credential_ref: Type.Optional(CredentialRefSchema),
341
+ // File-source glob(s) (mutually exclusive with `endpoint`). Consumer: the
342
+ // `@mutagent/tools` local-jsonl / unitf reader.
343
+ paths: Type.Optional(Type.Array(Type.String({ minLength: 1 }))),
344
+ // How to PARSE the records (see SourceFormat). `unitf` ⇒ read jsonl direct, skip
345
+ // normalize (F1). Consumer: the `@mutagent/tools` normalize path.
346
+ format: Type.Optional(
347
+ Type.Union([
348
+ Type.Literal(SourceFormat.LangfuseExport),
349
+ Type.Literal(SourceFormat.ClaudeCode),
350
+ Type.Literal(SourceFormat.Codex),
351
+ Type.Literal(SourceFormat.Raw),
352
+ Type.Literal(SourceFormat.Unitf),
353
+ ]),
354
+ ),
355
+ // Which record field carries the agent name (for per-agent grouping). Consumer:
356
+ // the evaluator/diagnostics agent-variance grouping.
357
+ agent_field: Type.Optional(Type.String({ minLength: 1 })),
358
+ // Latency-unit override (`auto` = infer per record). Consumer: the
359
+ // `@mutagent/tools` normalize path (latency projection).
360
+ latency_unit: Type.Optional(
361
+ Type.Union([
362
+ Type.Literal(LatencyUnit.Auto),
363
+ Type.Literal(LatencyUnit.Ms),
364
+ Type.Literal(LatencyUnit.S),
365
+ ]),
366
+ ),
367
+ },
368
+ { additionalProperties: false },
369
+ );
370
+ export type Source = Static<typeof SourceSchema>;
371
+
372
+ /**
373
+ * A precise link to an Agent / Tooling definition file in a code target.
374
+ * RESERVED — consumed by Build/Improve (future): the realized-implementation link
375
+ * a *build/*improve run records so a fix targets the right file. Not read by any
376
+ * current orchestrator floor.
377
+ */
378
+ export const CodeRefSchema = Type.Object(
379
+ {
380
+ // RESERVED (Build/Improve, future) — path to the agent/tooling def file.
381
+ path: Type.String({ minLength: 1 }),
382
+ // RESERVED (Build/Improve, future) — why this file realizes the spec.
383
+ why: Type.String({ minLength: 1 }),
384
+ },
385
+ { additionalProperties: false },
386
+ );
387
+ export type CodeRef = Static<typeof CodeRefSchema>;
388
+
389
+ /** HOW a fix is applied for a target. `kind` gates the report-only branch. */
390
+ export const ApplySchema = Type.Object(
391
+ {
392
+ // HOW a fix is applied. `report-only` gates OUT the target/apply floor.
393
+ // Consumer: onboarding-check.ts diagnosticsIsReportOnly (compares
394
+ // lifecycle.diagnostics.apply, the string form) + the diagnose-apply worker.
395
+ kind: Type.Union([
396
+ Type.Literal(ApplyKind.CodePr),
397
+ Type.Literal(ApplyKind.Markdown),
398
+ Type.Literal(ApplyKind.CloudDeploy),
399
+ Type.Literal(ApplyKind.ReportOnly),
400
+ ]),
401
+ // RESERVED — consumed by Build/Improve (future): bump a version stamp on apply.
402
+ versioning: Type.Optional(Type.Boolean()),
403
+ // RESERVED — consumed by Build/Improve (future): open a PR vs write in place.
404
+ pr: Type.Optional(Type.Boolean()),
405
+ },
406
+ { additionalProperties: false },
407
+ );
408
+ export type Apply = Static<typeof ApplySchema>;
409
+
410
+ /**
411
+ * One TARGET catalog entry — where agent defs live + how a fix is applied. Bound
412
+ * BY ROLE (target-writers build/diagnose-apply bind `global.targets`); a single
413
+ * entry auto-binds. When MULTIPLE exist, an entry marked `default: true` is
414
+ * auto-selected (the SELECTION contract); with no default, the operator picks at
415
+ * RUN time (needs-selection).
416
+ */
417
+ export const TargetSchema = Type.Object(
418
+ {
419
+ // The catalog key the operator names the target by. Consumer: onboarding-check.ts
420
+ // (resolveTargetByRole surfaces `entry.name`) + the run-time confirm/pick prompt.
421
+ name: Type.String({ minLength: 1 }),
422
+ // Which platform a fix is written TO. Consumer: the diagnose-apply worker (+
423
+ // builder) picks the local-markdown / code-construct / cloud-REST writer.
424
+ platform: Type.Union([
425
+ Type.Literal(TargetPlatform.LocalClaude),
426
+ Type.Literal(TargetPlatform.LocalCodex),
427
+ Type.Literal(TargetPlatform.LocalCursor),
428
+ Type.Literal(TargetPlatform.LocalOpencode),
429
+ Type.Literal(TargetPlatform.LocalMastra),
430
+ Type.Literal(TargetPlatform.LocalCloudAgentSdk),
431
+ Type.Literal(TargetPlatform.LocalSkill),
432
+ Type.Literal(TargetPlatform.CloudRest),
433
+ Type.Literal(TargetPlatform.ReportOnly),
434
+ ]),
435
+ // What KIND of subject this target writes to — `agent` (default), `skill`
436
+ // (D2), or `code` (Wave-2 W2I1). A `skill` subject's root is the skill DIR;
437
+ // its SSoT is .meta/prd.yaml (the annexed skillspec); it applies via the
438
+ // markdown transport (no build). A `code` subject is a spec-FIRST
439
+ // framework/harness impl (def→impl cascade) applied via `apply.kind: code-pr`
440
+ // (full TDD in the worktree); the ⑤ IMPROVE loop's "converged" for it is BOTH
441
+ // test-green AND a code-quality evaluator verdict. Optional — absent ⇒ agent
442
+ // (back-compatible). Consumer: the apply on-ramp (skill amends route to
443
+ // skill-builder's wave; code amends route spec-first through ai-engineer) +
444
+ // onboarding-check.
445
+ subject: Type.Optional(
446
+ Type.Union([
447
+ Type.Literal(TargetSubject.Agent),
448
+ Type.Literal(TargetSubject.Skill),
449
+ Type.Literal(TargetSubject.Code),
450
+ ]),
451
+ ),
452
+ // SELECTION contract — a catalog entry marked `default: true` is auto-selected
453
+ // when multiple targets exist. Exactly one default ⇒ resolved-default; >1 default
454
+ // ⇒ multiple-defaults (config error); 0 defaults ⇒ needs-selection (pick at run).
455
+ // Consumer: onboarding-check.ts resolveByRole; the run-time confirm/pick prompt.
456
+ default: Type.Optional(Type.Boolean()),
457
+ // Whether writes go through local files (worktree) or a remote API. Consumer:
458
+ // the diagnose-apply worker (local-diff vs REST-PUT branch).
459
+ mode: Type.Union([
460
+ Type.Literal(TargetMode.Local),
461
+ Type.Literal(TargetMode.Remote),
462
+ ]),
463
+ // Local-target root dir the fix writes under (e.g. `.claude/agents`). Consumer:
464
+ // the diagnose-apply worker (local mode).
465
+ root: Type.Optional(Type.String({ minLength: 1 })),
466
+ // Remote-target REST base URL. Consumer: the diagnose-apply worker (remote mode).
467
+ rest_base_url: Type.Optional(Type.String({ minLength: 1 })),
468
+ // Remote git repo URL (worktree clone source). Consumer: the diagnose-apply
469
+ // worker (local-git-over-remote branch).
470
+ repo_url: Type.Optional(Type.String({ minLength: 1 })),
471
+ // RESERVED — consumed by Build/Improve (future): the realized-implementation
472
+ // links a *build/*improve run records. Not read by any current floor.
473
+ code_refs: Type.Optional(Type.Array(CodeRefSchema)),
474
+ // Env-var NAME (or {env,path}) for the target write token. Consumer:
475
+ // resolve-credential.ts → the diagnose-apply worker (remote mode).
476
+ credential_ref: Type.Optional(CredentialRefSchema),
477
+ // HOW the fix is applied (kind gates report-only). Consumer: onboarding-check.ts
478
+ // + the diagnose-apply worker. See ApplySchema.
479
+ apply: ApplySchema,
480
+ },
481
+ { additionalProperties: false },
482
+ );
483
+ export type Target = Static<typeof TargetSchema>;
484
+
485
+ /**
486
+ * The GLOBAL cross-cutting resources. Sub-fields are OPTIONAL on purpose — a
487
+ * partial, mid-onboarding config still validates structurally; completeness is
488
+ * the onboarding check's concern, not the schema's. Renamed from `shared` in v0.2.0.
489
+ */
490
+ export const GlobalSchema = Type.Object(
491
+ {
492
+ // Provider credential REFS. Consumer: onboarding-check.ts (provider floor) +
493
+ // resolve-credential.ts.
494
+ providers: Type.Optional(Type.Array(ProviderSchema)),
495
+ // Repo + workspace location. Consumer: onboarding-check.ts (target floor) +
496
+ // resolve-paths.ts.
497
+ workspace: Type.Optional(WorkspaceSchema),
498
+ // Default + pinned-judge models. Consumer: onboarding-check.ts (model floors) +
499
+ // the evaluator run/scorecard.
500
+ models: Type.Optional(ModelsSchema),
501
+ // Report styling (cosmetic). Consumer: the evaluator/diagnostics report renderers.
502
+ brand: Type.Optional(BrandSchema),
503
+ // PROJECT-WIDE context links. Consumer: the skills load them as stage context.
504
+ context: Type.Optional(Type.Array(ContextLinkSchema)),
505
+ // The SOURCES catalog (where traces come from). Consumer: onboarding-check.ts
506
+ // resolveSourceByRole + the evaluator/diagnostics fetch.
507
+ sources: Type.Optional(Type.Array(SourceSchema)),
508
+ // The TARGETS catalog (where fixes are applied). Consumer: onboarding-check.ts
509
+ // resolveTargetByRole + the builder/diagnose-apply worker.
510
+ targets: Type.Optional(Type.Array(TargetSchema)),
511
+ },
512
+ { additionalProperties: false },
513
+ );
514
+ export type Global = Static<typeof GlobalSchema>;
515
+
516
+ // ── `lifecycle` — per-skill config, keyed by SKILL NAME ───────────────────────
517
+ //
518
+ // The orchestrator TYPES only the gate-relevant fields per skill; the REST of
519
+ // each section is the skill's OPAQUE knobs. So each `lifecycle.<skill>` section
520
+ // is an OPEN object (additionalProperties:true) that pins the few fields the
521
+ // orchestrator reads and passes everything else through. Each standalone skill
522
+ // reads its OWN section + validates the rest with its OWN schema (never
523
+ // cross-imported — standalone + symbiosis invariant).
524
+
525
+ /** `lifecycle.agentspec` — the orchestrator reads `spec_dir` (where *spec writes). */
526
+ export const LifecycleAgentspecSchema = Type.Object(
527
+ {
528
+ // Where *spec writes the agentspec.yaml files. Consumer: the orchestrator +
529
+ // the agentspec skill (spec_dir root).
530
+ spec_dir: Type.Optional(Type.String({ minLength: 1 })),
531
+ },
532
+ { additionalProperties: true },
533
+ );
534
+ export type LifecycleAgentspec = Static<typeof LifecycleAgentspecSchema>;
535
+
536
+ /** `lifecycle.builder` — config-light (writes to a `global.target` by role). */
537
+ export const LifecycleBuilderSchema = Type.Object(
538
+ {},
539
+ { additionalProperties: true },
540
+ );
541
+ export type LifecycleBuilder = Static<typeof LifecycleBuilderSchema>;
542
+
543
+ /**
544
+ * `lifecycle.evaluator` — the orchestrator reads `context` (stage-specific links)
545
+ * + `judge_runtime` (renamed from `substrate`: how judges run —
546
+ * agent-dispatch|in-house|code-based|user-framework). The rest (subject, datasets,
547
+ * …) is the evaluator's opaque passthrough.
548
+ */
549
+ export const LifecycleEvaluatorSchema = Type.Object(
550
+ {
551
+ // Stage-specific context links for evaluate. Consumer: the evaluator (loaded on
552
+ // an evaluate run); the orchestrator passes them through.
553
+ context: Type.Optional(Type.Array(ContextLinkSchema)),
554
+ // HOW judges run (agent-dispatch|in-house|code-based|user-framework; renamed
555
+ // from `substrate`). Consumer: gate.ts / onboarding-check.ts (in-house ⇒ the
556
+ // provider floor) + the evaluator judge wiring.
557
+ judge_runtime: Type.Optional(Type.String({ minLength: 1 })),
558
+ },
559
+ { additionalProperties: true },
560
+ );
561
+ export type LifecycleEvaluator = Static<typeof LifecycleEvaluatorSchema>;
562
+
563
+ /**
564
+ * `lifecycle.diagnostics` — the orchestrator reads `apply` (the report-only gate:
565
+ * `report-only` ⇒ produce report, skip the target/apply gate) + `context`. The
566
+ * rest (ask_tool, self_diagnostics, run_tags, feedback_sources, agents,
567
+ * default_audience, …) is the diagnostics skill's opaque passthrough. NOTE:
568
+ * schedule/trigger_rules/heartbeat are NO LONGER here — they moved to top-level
569
+ * `triggers.<stage>` in v0.2.0.
570
+ */
571
+ export const LifecycleDiagnosticsSchema = Type.Object(
572
+ {
573
+ // The report-only gate: `report-only` ⇒ produce report, skip the target/apply
574
+ // floor. Consumer: onboarding-check.ts diagnosticsIsReportOnly (compares against
575
+ // ApplyKind.ReportOnly) + gate.ts (via the target floor).
576
+ apply: Type.Optional(Type.String({ minLength: 1 })),
577
+ // Stage-specific context links for diagnose. Consumer: the diagnostics skill;
578
+ // the orchestrator passes them through.
579
+ context: Type.Optional(Type.Array(ContextLinkSchema)),
580
+ },
581
+ { additionalProperties: true },
582
+ );
583
+ export type LifecycleDiagnostics = Static<typeof LifecycleDiagnosticsSchema>;
584
+
585
+ /**
586
+ * The `lifecycle` block — one OPTIONAL sub-section per skill, keyed by skill name.
587
+ * Closed at THIS level (only the four known skills), OPEN within each section.
588
+ */
589
+ export const LifecycleSchema = Type.Object(
590
+ {
591
+ // *spec section — the orchestrator reads `spec_dir`. Consumer: agentspec skill.
592
+ agentspec: Type.Optional(LifecycleAgentspecSchema),
593
+ // *build section — config-light (writes by role to a global.target). Consumer:
594
+ // builder skill (opaque passthrough).
595
+ builder: Type.Optional(LifecycleBuilderSchema),
596
+ // *evaluate section — orchestrator reads `context` + `judge_runtime`. Consumer:
597
+ // evaluator skill.
598
+ evaluator: Type.Optional(LifecycleEvaluatorSchema),
599
+ // *diagnose section — orchestrator reads `apply` (report-only gate) + `context`.
600
+ // Consumer: diagnostics skill.
601
+ diagnostics: Type.Optional(LifecycleDiagnosticsSchema),
602
+ },
603
+ { additionalProperties: false },
604
+ );
605
+ export type Lifecycle = Static<typeof LifecycleSchema>;
606
+
607
+ // ── `triggers` — the future monitor (global, per stage, DISABLED) ─────────────
608
+
609
+ /**
610
+ * One trigger rule (FUTURE monitor input). Closed → auditable. Minimal by
611
+ * design: the consuming always-on monitor is out-of-scope this iteration, so
612
+ * the shape is intentionally small (an event + an optional stage/command to run).
613
+ */
614
+ export const TriggerRuleSchema = Type.Object(
615
+ {
616
+ // The event that fires the rule. Consumer: RESERVED — the FUTURE always-on
617
+ // monitor (out-of-scope this iteration; ships disabled).
618
+ on: Type.String({ minLength: 1 }),
619
+ // The stage/command to run when it fires. Consumer: RESERVED — future monitor.
620
+ run: Type.Optional(Type.String({ minLength: 1 })),
621
+ },
622
+ { additionalProperties: false },
623
+ );
624
+ export type TriggerRule = Static<typeof TriggerRuleSchema>;
625
+
626
+ /**
627
+ * When the monitor wakes. v0.1 ships `on-demand`. Absorbed from the old
628
+ * diagnostics `schedule` (moved into the trigger block in v0.2.0).
629
+ */
630
+ export const TriggerScheduleSchema = Type.Object(
631
+ {
632
+ // When the monitor wakes (v0.1 ships `on-demand`). Consumer: RESERVED — future monitor.
633
+ mode: Type.String({ minLength: 1 }),
634
+ // Optional wake time (cron-ish). Consumer: RESERVED — future monitor.
635
+ at: Type.Optional(Type.String({ minLength: 1 })),
636
+ // Optional timezone for `at`. Consumer: RESERVED — future monitor.
637
+ timezone: Type.Optional(Type.String({ minLength: 1 })),
638
+ },
639
+ { additionalProperties: false },
640
+ );
641
+ export type TriggerSchedule = Static<typeof TriggerScheduleSchema>;
642
+
643
+ /**
644
+ * Notify + cost cap for the monitor. Absorbed from the old diagnostics
645
+ * `heartbeat` (moved into the trigger block in v0.2.0).
646
+ */
647
+ export const TriggerHeartbeatSchema = Type.Object(
648
+ {
649
+ // Notify when a scan matches nothing. Consumer: RESERVED — future monitor.
650
+ notify_on_zero_matches: Type.Optional(Type.Boolean()),
651
+ // Notify when a scan matches. Consumer: RESERVED — future monitor.
652
+ notify_on_matches: Type.Optional(Type.Boolean()),
653
+ // Per-day cost cap on auto-diagnoses. Consumer: RESERVED — future monitor.
654
+ max_diagnostics_per_day: Type.Optional(Type.Integer({ minimum: 0 })),
655
+ },
656
+ { additionalProperties: false },
657
+ );
658
+ export type TriggerHeartbeat = Static<typeof TriggerHeartbeatSchema>;
659
+
660
+ /**
661
+ * A per-stage trigger block. Ships DISABLED: `enabled` defaults false, `rules`
662
+ * defaults empty. `schedule` / `heartbeat` are OPTIONAL (moved in from the old
663
+ * diagnostics section). No auto-fire / no cron — the always-on monitor is future
664
+ * + out-of-scope (feedback_self_diagnostics_on_demand_only).
665
+ */
666
+ export const TriggerStageBlockSchema = Type.Object(
667
+ {
668
+ // Master on/off for this stage's monitor (ships false). Consumer: RESERVED —
669
+ // future monitor.
670
+ enabled: Type.Boolean({ default: false }),
671
+ // The trigger rules (ships empty). Consumer: RESERVED — future monitor.
672
+ rules: Type.Array(TriggerRuleSchema, { default: [] }),
673
+ // Optional wake schedule (moved in from the old diagnostics section). Consumer:
674
+ // RESERVED — future monitor.
675
+ schedule: Type.Optional(TriggerScheduleSchema),
676
+ // Optional notify + cost cap (moved in from the old diagnostics section).
677
+ // Consumer: RESERVED — future monitor.
678
+ heartbeat: Type.Optional(TriggerHeartbeatSchema),
679
+ },
680
+ { additionalProperties: false },
681
+ );
682
+ export type TriggerStageBlock = Static<typeof TriggerStageBlockSchema>;
683
+
684
+ /** Per-stage trigger blocks, keyed by routing AdlStage. Every stage optional. */
685
+ export const TriggersSchema = Type.Object(
686
+ {
687
+ // Per-stage trigger blocks (keyed by routing AdlStage). ALL RESERVED — the
688
+ // consuming always-on monitor is future + out-of-scope; every block ships
689
+ // disabled. Consumer: RESERVED — future monitor.
690
+ [AdlStage.Build]: Type.Optional(TriggerStageBlockSchema),
691
+ [AdlStage.Evaluate]: Type.Optional(TriggerStageBlockSchema),
692
+ [AdlStage.Diagnose]: Type.Optional(TriggerStageBlockSchema),
693
+ [AdlStage.Improve]: Type.Optional(TriggerStageBlockSchema),
694
+ [AdlStage.Audit]: Type.Optional(TriggerStageBlockSchema),
695
+ },
696
+ { additionalProperties: false },
697
+ );
698
+ export type Triggers = Static<typeof TriggersSchema>;
699
+
700
+ /**
701
+ * The full `.mutagent/config.yaml` contract (v0.2.0). Closed object — unknown
702
+ * extras (including the DROPPED legacy keys `shared` / `stages` / top-level
703
+ * `diagnostics` / `evaluator`) are rejected at THIS level, so a legacy config
704
+ * fails structural validation too (belt-and-braces with loadConfig's legacy
705
+ * detection).
706
+ */
707
+ /**
708
+ * `dogfood` — the hidden `*dogfood` observe surface's source binding.
709
+ *
710
+ * BUILD-PROJECT ≠ DOGFOOD-PROJECT (load-bearing). You DEVELOP Helix in one project
711
+ * (e.g. the mutagent monorepo) but USE it + collect feedback in ANOTHER (e.g. a
712
+ * hackathon / product repo). So `*dogfood` does NOT watch the current working dir's
713
+ * sessions — it watches the DOGFOOD TARGET's Claude-Code session dir, set here.
714
+ *
715
+ * dogfood:
716
+ * source_dir: "~/.claude/projects/-Users-you-path-to-DOGFOOD-project" # NOT the build project
717
+ * session_glob: "*.jsonl" # optional (default "*.jsonl")
718
+ * include_subagents: true # optional (default true) — also tail dispatched subagent JSONLs
719
+ *
720
+ * `source_dir` is the ABSOLUTE path to the dogfood project's `~/.claude/projects/<enc(path)>/`
721
+ * dir (Claude encodes the project cwd by replacing `/` with `-`). It is an ABSOLUTE
722
+ * path BY DESIGN (a documented exception to the relative-paths rule — it points at a
723
+ * SEPARATE project outside the workspace), so it is a plain String, never forced
724
+ * relative. `*dogfood` with no sessionId picks the latest `*.jsonl` by mtime WITHIN this dir.
725
+ */
726
+ /**
727
+ * `dogfood.slack` — the "meta Slack notifications" block (DOG-3). When
728
+ * `enabled`, `*dogfood` opens a LIVE Slack THREAD (root on start + threaded
729
+ * replies on stage-change · agent-dispatch · feedback · progress). Absent /
730
+ * disabled ⇒ NO Slack (HTML report only, never an error).
731
+ *
732
+ * Threading needs the Slack WEB API (`chat.postMessage` + `thread_ts`), so a
733
+ * BOT TOKEN is required — NOT an incoming webhook. `token_ref` is the NAME of the
734
+ * env var that holds the `xoxb-…` token (e.g. `SLACK_BOT_TOKEN`) — NEVER the raw
735
+ * secret (same discipline as `credentials_ref`). `channel` is a Slack channel id.
736
+ */
737
+ export const DogfoodSlackSchema = Type.Object(
738
+ {
739
+ enabled: Type.Boolean({ default: false }),
740
+ // A Slack channel id (e.g. "C0123ABC") the bot is a member of.
741
+ channel: Type.String({ minLength: 1 }),
742
+ // The ENV-VAR NAME holding the bot token (xoxb-…) — a reference, never a secret.
743
+ token_ref: Type.String({ minLength: 1 }),
744
+ },
745
+ { additionalProperties: false },
746
+ );
747
+ export type DogfoodSlack = Static<typeof DogfoodSlackSchema>;
748
+
749
+ export const DogfoodSchema = Type.Object(
750
+ {
751
+ // The DOGFOOD TARGET project's Claude-Code session dir (NOT the build project's).
752
+ // ABSOLUTE path by design (documented exception — a separate project's dir).
753
+ source_dir: Type.String({ minLength: 1 }),
754
+ session_glob: Type.Optional(Type.String({ minLength: 1 })), // default "*.jsonl"
755
+ include_subagents: Type.Optional(Type.Boolean()), // default true — tail dispatched subagent JSONLs too
756
+ // The forced re-render cadence in seconds (default 180 = 3 min); the watch
757
+ // loop also re-renders on drift. A plain positive integer.
758
+ cadence_seconds: Type.Optional(Type.Integer({ minimum: 1 })), // default 180
759
+ // Optional live-thread Slack sink (DOG-3). Absent ⇒ no Slack.
760
+ slack: Type.Optional(DogfoodSlackSchema),
761
+ },
762
+ { additionalProperties: false },
763
+ );
764
+ export type Dogfood = Static<typeof DogfoodSchema>;
765
+
766
+ /**
767
+ * `monitor.slack` — the EXTERNAL Monitor's notification sink (EXT-1). The OUTWARD
768
+ * monitor (`*monitor`) posts a discrete NOTIFICATION each time a `config.triggers`
769
+ * rule fires. Mirrors `dogfood.slack` in shape + discipline but is a SEPARATE
770
+ * block (a separate emitter, a separate voice — ADR-11/ADR-12): the dogfood block
771
+ * drives a live THREAD, this one drives one-shot notifications.
772
+ *
773
+ * Closed object (unknown keys rejected). `token_ref` is the NAME of the env var
774
+ * holding the `xoxb-…` bot token (e.g. `SLACK_BOT_TOKEN`) — NEVER the raw secret.
775
+ * `channel` is a Slack channel id. Absent / disabled ⇒ no Slack (never an error).
776
+ */
777
+ export const MonitorSlackSchema = Type.Object(
778
+ {
779
+ enabled: Type.Boolean({ default: false }),
780
+ // A Slack channel id (e.g. "C0123ABC") the bot is a member of.
781
+ channel: Type.String({ minLength: 1 }),
782
+ // The ENV-VAR NAME holding the bot token (xoxb-…) — a reference, never a secret.
783
+ token_ref: Type.String({ minLength: 1 }),
784
+ },
785
+ { additionalProperties: false },
786
+ );
787
+ export type MonitorSlack = Static<typeof MonitorSlackSchema>;
788
+
789
+ /**
790
+ * `monitor` — the EXTERNAL Monitor's config (EXT-1). Holds the OPTIONAL Slack
791
+ * notification sink. The CONDITION source stays `triggers` (the dormant per-stage
792
+ * rules) — `monitor` only adds the outward NOTIFICATION sink, keeping the trigger
793
+ * rules and the notification channel cleanly separated. Closed object.
794
+ */
795
+ export const MonitorSchema = Type.Object(
796
+ {
797
+ slack: Type.Optional(MonitorSlackSchema),
798
+ },
799
+ { additionalProperties: false },
800
+ );
801
+ export type Monitor = Static<typeof MonitorSchema>;
802
+
803
+ export const MutagentConfigSchema = Type.Object(
804
+ {
805
+ // The FROZEN contract version. Consumer: config-schema.ts (validateConfig literal
806
+ // check + detectLegacyConfig).
807
+ config_version: Type.Literal(CONFIG_VERSION),
808
+ // Framework-wide shared resources. Consumer: onboarding-check.ts + gate.ts +
809
+ // resolve-credential.ts + the skills.
810
+ global: Type.Optional(GlobalSchema),
811
+ // Per-skill behavior, keyed by skill name. Consumer: gate.ts / onboarding-check.ts
812
+ // (typed gate fields) + each standalone skill (its own section).
813
+ lifecycle: Type.Optional(LifecycleSchema),
814
+ // The future monitor (per-stage, disabled). Consumer: RESERVED — future monitor.
815
+ triggers: Type.Optional(TriggersSchema),
816
+ // Hidden *dogfood observe surface — watches a SEPARATE dogfood-target project's
817
+ // sessions (v2 surface, preserved). Consumer: scripts/dogfood/* (the *dogfood
818
+ // surface). Note: the old skill-owned passthrough keys (`diagnostics` /
819
+ // `evaluator`) are GONE in v0.2.0 — they moved under `lifecycle` (and now trip
820
+ // legacy detection as top-level keys).
821
+ dogfood: Type.Optional(DogfoodSchema),
822
+ // External Monitor (*monitor / EXT-1) — the OUTWARD notification sink. Its
823
+ // CONDITION source is the `triggers` block above; `monitor` only carries the
824
+ // Slack notification channel. Ships DISABLED (triggers.<stage>.enabled:false).
825
+ monitor: Type.Optional(MonitorSchema),
826
+ },
827
+ { additionalProperties: false },
828
+ );
829
+ export type MutagentConfig = Static<typeof MutagentConfigSchema>;
830
+
831
+ /**
832
+ * The canonical DISABLED trigger block — the shipped default. The schema allows
833
+ * `enabled:true` so a future monitor can opt in, but the shipped + onboarding
834
+ * default is OFF with no rules (on-demand-only).
835
+ */
836
+ export const DEFAULT_TRIGGER_BLOCK: TriggerStageBlock = {
837
+ enabled: false,
838
+ rules: [],
839
+ };
840
+
841
+ // ── Validation ──────────────────────────────────────────────────────────────
842
+
843
+ export interface ValidationResult {
844
+ ok: boolean;
845
+ /** Human-readable error strings (path: message), empty when ok. */
846
+ errors: string[];
847
+ }
848
+
849
+ // Compiled checker — compiled once at module load.
850
+ const MutagentConfigChecker = TypeCompiler.Compile(MutagentConfigSchema);
851
+
852
+ /**
853
+ * Validate an arbitrary value against the MutagentConfig contract.
854
+ *
855
+ * STRUCTURAL only — the compiled TypeBox checker. Catches missing / wrong-typed
856
+ * / out-of-enum / non-frozen-version fields AND undeclared extra fields at every
857
+ * orchestrator-owned level (additionalProperties:false). It deliberately does
858
+ * NOT judge onboarding COMPLETENESS (that is checkOnboardingComplete's job) — so
859
+ * a partial config and even a raw-secret-shaped credentials_ref pass here. Pure:
860
+ * no I/O, no clock. Never throws — a non-object input yields ok:false.
861
+ */
862
+ export function validateConfig(obj: unknown): ValidationResult {
863
+ const errors: string[] = [];
864
+ if (!MutagentConfigChecker.Check(obj)) {
865
+ for (const e of MutagentConfigChecker.Errors(obj)) {
866
+ errors.push(`${e.path === "" ? "/" : e.path}: ${e.message}`);
867
+ }
868
+ }
869
+ return { ok: errors.length === 0, errors };
870
+ }
871
+
872
+ // ── Legacy detection ──────────────────────────────────────────────────────────
873
+
874
+ /** The v0.1.0 top-level keys that must NOT appear in a v0.2.0 config. */
875
+ const LEGACY_TOP_LEVEL_KEYS = ["shared", "stages", "diagnostics", "evaluator"] as const;
876
+
877
+ /**
878
+ * Detect a legacy (pre-v0.2.0) config WITHOUT parsing its old shape. Two signals,
879
+ * either one fires:
880
+ * 1. `config_version` is absent or a known legacy version (not the frozen 0.2.0).
881
+ * 2. A legacy top-level key is present (`shared` / `stages` / a top-level
882
+ * `diagnostics` / `evaluator` skill section) OR any `*.observability` block
883
+ * survives (the old per-stage source binding).
884
+ *
885
+ * Returns the list of legacy markers found (empty ⇒ not legacy). Pure; tolerant
886
+ * of a non-object input (returns []). Callers route a non-empty result to
887
+ * `migration-required` (the migration DIRECTIVE, not a static script).
888
+ */
889
+ export function detectLegacyConfig(obj: unknown): string[] {
890
+ if (obj === null || typeof obj !== "object") return [];
891
+ const o = obj as Record<string, unknown>;
892
+ const markers: string[] = [];
893
+
894
+ const version = o.config_version;
895
+ if (version !== CONFIG_VERSION) {
896
+ if (typeof version === "string" && (LEGACY_CONFIG_VERSIONS as readonly string[]).includes(version)) {
897
+ markers.push(`config_version: "${version}" (legacy — expected "${CONFIG_VERSION}")`);
898
+ } else if (version === undefined) {
899
+ markers.push(`config_version: absent (expected "${CONFIG_VERSION}")`);
900
+ }
901
+ // A NON-legacy, non-current version (e.g. a future "0.3.0") is NOT a legacy
902
+ // marker — structural validation rejects it as a wrong literal instead.
903
+ }
904
+
905
+ for (const key of LEGACY_TOP_LEVEL_KEYS) {
906
+ if (key in o) markers.push(`legacy top-level key '${key}'`);
907
+ }
908
+
909
+ // Any `*.observability` block anywhere under a stages-like map = legacy source binding.
910
+ const stages = o.stages;
911
+ if (stages !== null && typeof stages === "object") {
912
+ for (const [stage, block] of Object.entries(stages as Record<string, unknown>)) {
913
+ if (block !== null && typeof block === "object" && "observability" in (block as Record<string, unknown>)) {
914
+ markers.push(`legacy '${stage}.observability' (source now binds by role via global.sources)`);
915
+ }
916
+ }
917
+ }
918
+
919
+ return markers;
920
+ }
921
+
922
+ // ── Loader ───────────────────────────────────────────────────────────────────
923
+
924
+ export type LoadConfigResult =
925
+ | { ok: true; config: MutagentConfig }
926
+ | { ok: false; legacy: true; errors: string[] }
927
+ | { ok: false; legacy?: false; errors: string[] };
928
+
929
+ /**
930
+ * Read + YAML-parse + validate a config file at an INJECTED path. Guarded
931
+ * parsing (mirrors sync-index.ts): a missing file, malformed YAML, a LEGACY
932
+ * config, or a config that fails structural validation returns { ok:false, … } —
933
+ * never throws.
934
+ *
935
+ * LEGACY DETECTION runs BEFORE structural validation: if the parsed object is a
936
+ * legacy (pre-v0.2.0) config — wrong `config_version` OR any legacy key
937
+ * (`shared` / `stages` / top-level `diagnostics`/`evaluator` / `*.observability`)
938
+ * — the loader returns `{ ok:false, legacy:true, errors:[…] }`. Callers route
939
+ * that to `migration-required` (the one-time migration DIRECTIVE). No old-shape
940
+ * parse ever happens at runtime (Fork B: hard-cut).
941
+ *
942
+ * The path is taken VERBATIM: no resolution, no env lookup. Callers that want the
943
+ * LOCAL `.mutagent/config.yaml` resolve it themselves via resolve-paths.ts (the
944
+ * thin CLI does this); the pure core stays deterministic against committed
945
+ * fixtures and never resolves a path on its own.
946
+ */
947
+ export function loadConfig(configPath: string): LoadConfigResult {
948
+ let raw: string;
949
+ try {
950
+ raw = fs.readFileSync(configPath, "utf-8");
951
+ } catch (err) {
952
+ return { ok: false, errors: [`cannot read ${configPath}: ${String(err)}`] };
953
+ }
954
+
955
+ let parsed: unknown;
956
+ try {
957
+ parsed = parseYaml(raw);
958
+ } catch (err) {
959
+ return { ok: false, errors: [`malformed YAML in ${configPath}: ${String(err)}`] };
960
+ }
961
+
962
+ // Legacy detection FIRST — never parse the old shape at runtime.
963
+ const legacyMarkers = detectLegacyConfig(parsed);
964
+ if (legacyMarkers.length > 0) {
965
+ return {
966
+ ok: false,
967
+ legacy: true,
968
+ errors: [
969
+ `legacy config detected in ${configPath} — migration required (see references/config-migration.md): ${legacyMarkers.join("; ")}`,
970
+ ],
971
+ };
972
+ }
973
+
974
+ const result = validateConfig(parsed);
975
+ if (!result.ok) return { ok: false, errors: result.errors };
976
+ return { ok: true, config: parsed as MutagentConfig };
977
+ }
978
+
979
+ // ---------------------------------------------------------------------------
980
+ // CLI — thin wrapper. Validates a config file. With no path arg it resolves the
981
+ // LOCAL config at the install/init dir (nearest ancestor with `.mutagent/`),
982
+ // NEVER `~/.mutagent`:
983
+ // bun run scripts/config-schema.ts [path] (defaults to <root>/.mutagent/config.yaml)
984
+ // Exit 0 = valid; exit 1 = invalid / legacy / unreadable (errors on stdout).
985
+ // ---------------------------------------------------------------------------
986
+
987
+ function runCli(argv: string[]): number {
988
+ const arg = argv.slice(2).find((a) => !a.startsWith("--"));
989
+ const target = arg ?? resolveConfigPath();
990
+
991
+ const result = loadConfig(path.resolve(target));
992
+ if (result.ok) {
993
+ console.info(`[config-schema] PASS — valid MutagentConfig v${CONFIG_VERSION} (${target}).`);
994
+ return 0;
995
+ }
996
+ for (const e of result.errors) console.info(e);
997
+ const label = "legacy" in result && result.legacy ? "MIGRATION REQUIRED" : "FAIL";
998
+ process.stderr.write(
999
+ `[config-schema] ${label} — ${result.errors.length} error(s) in ${target}.\n`,
1000
+ );
1001
+ return 1;
1002
+ }
1003
+
1004
+ const isMain =
1005
+ typeof import.meta !== "undefined" &&
1006
+ (import.meta as unknown as { main?: boolean }).main === true;
1007
+ if (isMain) {
1008
+ const argv = typeof Bun !== "undefined" ? Bun.argv : process.argv;
1009
+ process.exit(runCli(argv));
1010
+ }