@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,719 @@
1
+ /**
2
+ * scripts/run-evaluate.ts — P5: the real-engine `*evaluate` END-TO-END runner.
3
+ * ---------------------------------------------------------------------------
4
+ * The HEADLINE path, WIRED (not re-implemented). It COMPOSES the existing,
5
+ * C-PIN-certified engine into the full spine the dogfood (M6) bypassed when it
6
+ * hand-rolled judge packets:
7
+ *
8
+ * PREP prepMatrixPackets : buildMatrixPacket → writeMatrixPacket (one
9
+ * DATA packet per trajectory; NO hand-rolled packets)
10
+ * DISPATCH [parent session] : fan out #mode-judge-trajectory leaves — each
11
+ * scores the WHOLE matrix for ONE trajectory, writes a verdict file.
12
+ * Sub-agents cannot dispatch sub-agents, so the PARENT runs this;
13
+ * the runner is split PREP | AGGREGATE around it.
14
+ * AGGREGATE aggregateEvaluate : FAIL-LOUD readiness gate (missingMatrixVerdicts
15
+ * → THROW; never roll up a partial) → readMatrixVerdictFiles →
16
+ * aggregateMatrixScorecard → GATE + variance → EV-051 route failures.
17
+ *
18
+ * C-PIN: `maskedScorecard` is the byte-identity artifact — two runs on the same
19
+ * verdict files produce a BYTE-IDENTICAL masked scorecard. JUDGE-ONLY (EV-051):
20
+ * failing criteria are ROUTED to a diagnostics HandoverBundle — NEVER fixed here.
21
+ *
22
+ * COMPOSE-ONLY: this module calls matrix-judge.ts / evaluate.ts / route-failures.ts
23
+ * / mask.ts unchanged. It re-implements nothing — the engine is C-PIN-certified.
24
+ * PURE except for the fs the composed fns already do (read/write packet+verdict
25
+ * files); no clock/random/network (handover provenance is INJECTED, not read).
26
+ */
27
+ import { existsSync, mkdirSync, writeFileSync } from "node:fs";
28
+ import { join } from "node:path";
29
+ import {
30
+ aggregateMatrixScorecard,
31
+ assessTraceFidelity,
32
+ buildMatrixPacket,
33
+ consolidateByLocus,
34
+ estimateMatrixPacketTokens,
35
+ matrixVerdictFileName,
36
+ packetFileName,
37
+ planAdaptivePackets,
38
+ readMatrixVerdictFiles,
39
+ synthesizeIncompleteVerdictFile,
40
+ tier0PrePass,
41
+ writeMatrixPacket,
42
+ writeMatrixVerdictFile,
43
+ type AdaptiveKOptions,
44
+ type LocusCluster,
45
+ type PacketGroup,
46
+ type Tier0Result,
47
+ type TraceFidelity,
48
+ } from "./matrix-judge.ts";
49
+ import { parseMatrixVerdictFile, type MatrixVerdictFile, type SubjectProfile } from "./contracts/eval-matrix.ts";
50
+ import { assessEmitCompleteness, type EmitCompleteness } from "./emit-completeness.ts";
51
+ import type { VerifierSignal } from "./result-verify.ts";
52
+ import { reportDir } from "./artifact-paths.ts";
53
+ import {
54
+ buildEvalReportInput,
55
+ fromMatrixCriteria,
56
+ renderEvalReport,
57
+ } from "./render-eval-report.ts";
58
+ import { maskedCanonicalJson } from "./mask.ts";
59
+ import {
60
+ calibrationItems,
61
+ routeFailures,
62
+ type ArtifactRef,
63
+ type CalibrationItem,
64
+ type FailureRef,
65
+ type HandoverBundle,
66
+ type SubjectKindValue,
67
+ } from "./route-failures.ts";
68
+ import { packetsDir, verdictsDir } from "./artifact-paths.ts";
69
+ import {
70
+ CriterionFlag,
71
+ type CriterionVerdict,
72
+ type GroundingReadiness,
73
+ type IndependentVerifyRecord,
74
+ } from "./contracts/eval-types.ts";
75
+ import type { MatrixCriterion } from "./contracts/eval-matrix.ts";
76
+ import type { Scorecard } from "./evaluate.ts";
77
+ import type { EvalTrace } from "./contracts/eval-types.ts";
78
+
79
+ /** The pinned envelope every packet carries (C-PIN; model-intent-sacred). */
80
+ export interface PinnedEnvelope {
81
+ model: string;
82
+ temperature: 0;
83
+ }
84
+
85
+ export interface EvaluateRunInput {
86
+ subject: { kind: SubjectKindValue; name: string; path: string };
87
+ /** the agent sessions under evaluation (one packet each). */
88
+ trajectories: EvalTrace[];
89
+ /** the WHOLE eval matrix every trajectory is scored against. */
90
+ criteria: MatrixCriterion[];
91
+ /**
92
+ * §9.4.4 M1 — the SUBJECT PROFILE (identity·purpose·tools·skill·scope) carried
93
+ * into EVERY judge packet so the judge knows who the agent is before it judges.
94
+ * GIVEN (code access) or RECONSTRUCTED from the trace batch (`buildSubjectProfile`).
95
+ * ABSENT ⇒ byte-stable legacy packets (the judge reconstructs at reason-time).
96
+ */
97
+ subjectProfile?: SubjectProfile;
98
+ pin: PinnedEnvelope;
99
+ /** where PREP writes packet files. */
100
+ packetDir: string;
101
+ /** where the dispatched #mode-judge-trajectory leaves wrote verdict files. */
102
+ verdictDir: string;
103
+ gatingSeverities?: string[];
104
+ /**
105
+ * T3 — the dispatched independent-verifier signals (criterionId → VerifierSignal)
106
+ * + the situation, applied DOWNGRADE-ONLY to gating fails. ABSENT ⇒ self-verify
107
+ * only (byte-stable). The parent PREPs the 2nd-judge tasks (`prepIndependentVerifyTasks`),
108
+ * dispatches the REFUTE leaves, collects their signals, and passes them here.
109
+ */
110
+ independentVerify?: { situation: EvalTrace[]; signals: Record<string, VerifierSignal> };
111
+ /** INJECTED provenance for the EV-051 handover — never a self-read clock. */
112
+ producedBy: string;
113
+ producedAt: string;
114
+ /** the artifacts that cross the diagnose boundary (e.g. the scorecard ref). */
115
+ artifacts?: ArtifactRef[];
116
+ /**
117
+ * Code-eval STDOUT opt-out (the CLI `--quiet-code-eval`). DEFAULT (absent/false)
118
+ * ⇒ every code-decided per-criterion verdict is streamed to stdout as JSONL
119
+ * BEFORE it folds into the scorecard (never-blind guarantee). `true` ⇒ suppress
120
+ * the stdout log ONLY — the scorecard + masked artifact are byte-identical either
121
+ * way (the log is a separate stream, not part of C-PIN).
122
+ */
123
+ quietCodeEval?: boolean;
124
+ }
125
+
126
+ // ── T1 tier-0 plan ────────────────────────────────────────────────────────────
127
+
128
+ /** One trajectory's tier-0 plan: the trace, its deterministic code verdicts, the
129
+ * residual judge rows still needing dispatch, and its EXAMINE fidelity gate. */
130
+ export interface Tier0PlanEntry extends Tier0Result {
131
+ trace: EvalTrace;
132
+ /** §9.4.2 node 1 — the deterministic fidelity gate. `complete:false` ⇒ INCOMPLETE
133
+ * (no residual rows are dispatched; a synthesized INCOMPLETE verdict is emitted). */
134
+ fidelity: TraceFidelity;
135
+ }
136
+
137
+ /**
138
+ * Run the tier-0 deterministic pre-pass over every trajectory (PURE — `tier0PrePass`
139
+ * is a pure function of (criteria, trace)). The plan is the SINGLE source of truth
140
+ * for PREP (which residual rows to dispatch), AGGREGATE (which code verdicts to fold),
141
+ * and the #3 fidelity gate (which trajectories are INCOMPLETE). Default (no
142
+ * `checkMethod`, no truncation): every row is residual, zero code verdicts →
143
+ * byte-identical to the legacy path.
144
+ *
145
+ * #3 EXAMINE fidelity gate (§9.4.2 node 1): a trace flagged INCOMPLETE by
146
+ * `assessTraceFidelity` (truncated / structurally-empty) SHORT-CIRCUITS — it gets
147
+ * ZERO residual criteria (never dispatched the full criteria walk) and ZERO code
148
+ * verdicts; PREP emits a synthesized INCOMPLETE verdict for it instead.
149
+ */
150
+ export function tier0Plan(input: EvaluateRunInput): Tier0PlanEntry[] {
151
+ return input.trajectories.map((trace) => {
152
+ const fidelity = assessTraceFidelity(trace);
153
+ if (!fidelity.complete) {
154
+ // node-1 short-circuit: never walk a truncated trace per-criterion.
155
+ return { trace, fidelity, codeVerdicts: [], residualCriteria: [] };
156
+ }
157
+ return { trace, fidelity, ...tier0PrePass(input.criteria, trace) };
158
+ });
159
+ }
160
+
161
+ // ── CODE-EVAL STDOUT (never-blind guarantee) ──────────────────────────────────
162
+ //
163
+ // tier-0 `codeVerdicts` are the deterministic per-criterion code decisions. TODAY
164
+ // they fold SILENTLY into `aggregateMatrixScorecard` — a code/dataset run with no
165
+ // dispatched judge emits ZERO visible per-row output, so a code-only run is BLIND.
166
+ // We stream each code verdict as ONE JSONL line to STDOUT before the fold, so the
167
+ // runner always shows the per-criterion code decisions.
168
+ //
169
+ // C-PIN SAFETY: this is a SEPARATE stdout stream — it NEVER enters the masked
170
+ // scorecard artifact (`maskedScorecard`/`maskedCanonicalJson`). The byte-identity
171
+ // artifact is untouched; only the human-facing stdout gains the per-row log.
172
+
173
+ /** One per-criterion code-eval STDOUT record (a stable JSONL projection of a
174
+ * tier-0 `MatrixVerdict`, tagged with its trajectory). PURE data — no clock. */
175
+ export interface CodeEvalLogRecord {
176
+ kind: "code-eval";
177
+ trajectoryId: string;
178
+ criterionId: string;
179
+ result: string;
180
+ confidence: number;
181
+ critique: string;
182
+ }
183
+
184
+ /**
185
+ * The per-criterion code-eval JSONL lines for a run — PURE (a projection of the
186
+ * tier-0 plan's `codeVerdicts`). One line per (trajectory × code-decided criterion),
187
+ * in deterministic plan order (criteria order preserved by `tier0PrePass`). EMPTY
188
+ * when no row is code-decided (an all-judge run → byte-identical to legacy stdout).
189
+ * Exposed for testing WITHOUT touching the console.
190
+ */
191
+ export function codeEvalStdoutLines(input: EvaluateRunInput): string[] {
192
+ const lines: string[] = [];
193
+ for (const entry of tier0Plan(input)) {
194
+ for (const v of entry.codeVerdicts) {
195
+ const rec: CodeEvalLogRecord = {
196
+ kind: "code-eval",
197
+ trajectoryId: entry.trace.id,
198
+ criterionId: v.criterionId,
199
+ result: v.result,
200
+ confidence: v.confidence,
201
+ critique: v.critique,
202
+ };
203
+ lines.push(JSON.stringify(rec));
204
+ }
205
+ }
206
+ return lines;
207
+ }
208
+
209
+ /**
210
+ * Emit the per-criterion code-eval JSONL to STDOUT (never-blind guarantee) — one
211
+ * line per code-decided row, BEFORE they fold into the scorecard. ALWAYS-ON by
212
+ * default; pass `quiet:true` (the CLI `--quiet-code-eval` opt-out) to suppress.
213
+ * The ONLY side effect is a `process.stdout.write` (a raw data stream, NOT a
214
+ * logger); it writes NOTHING to the masked scorecard (C-PIN byte-identity
215
+ * preserved). Returns the number of lines emitted.
216
+ */
217
+ export function emitCodeEvalStdout(input: EvaluateRunInput, quiet = false): number {
218
+ if (quiet) return 0;
219
+ const lines = codeEvalStdoutLines(input);
220
+ if (lines.length > 0) process.stdout.write(lines.join("\n") + "\n");
221
+ return lines.length;
222
+ }
223
+
224
+ /** The trajectory ids that still need a dispatched judge verdict (COMPLETE trace ∧
225
+ * residual rows > 0). Fully code-decided AND truncated (INCOMPLETE) trajectories are
226
+ * excluded — they get no packet dispatched. */
227
+ export function judgeTrajectoryIds(input: EvaluateRunInput): string[] {
228
+ return tier0Plan(input)
229
+ .filter((e) => e.fidelity.complete && e.residualCriteria.length > 0)
230
+ .map((e) => e.trace.id);
231
+ }
232
+
233
+ /** The trajectory ids the #3 fidelity gate flagged INCOMPLETE (truncated / empty).
234
+ * Each gets a synthesized INCOMPLETE verdict at PREP — never a dispatched judge. */
235
+ export function incompleteTrajectoryIds(input: EvaluateRunInput): string[] {
236
+ return tier0Plan(input)
237
+ .filter((e) => !e.fidelity.complete)
238
+ .map((e) => e.trace.id);
239
+ }
240
+
241
+ /**
242
+ * T5 — the adaptive-K dispatch PLAN (the overload guard) over the tier-0 residual
243
+ * judge trajectories. DEFAULT (maxK=1) ⇒ one singleton group per trajectory (the
244
+ * headline 1:1 path). With maxK>1 + a token budget, same-cohort trajectories that
245
+ * FIT are batched (1:K); a trajectory that alone exceeds the budget is an
246
+ * `overBudget` singleton (never batched). The estimate uses the RESIDUAL criteria
247
+ * (post tier-0). PURE — the plan is computed, never mutated. NOTE: the actual
248
+ * dispatch packet stays single-trajectory (the `MatrixPacket` contract); this plan
249
+ * is the budget/isolation guard that decides WHEN batching is even safe.
250
+ */
251
+ export function adaptivePacketPlan(input: EvaluateRunInput, opts: AdaptiveKOptions = {}): PacketGroup[] {
252
+ const items = tier0Plan(input)
253
+ .filter((e) => e.residualCriteria.length > 0)
254
+ .map((e) => ({
255
+ trajectoryId: e.trace.id,
256
+ estTokens: estimateMatrixPacketTokens(e.residualCriteria, e.trace),
257
+ }));
258
+ return planAdaptivePackets(items, opts);
259
+ }
260
+
261
+ // ── PREP ────────────────────────────────────────────────────────────────────
262
+
263
+ /**
264
+ * PREP: build + write one MatrixPacket per trajectory via `buildMatrixPacket`
265
+ * (which asserts the packet shape). NO hand-rolled packets. T1: the packet carries
266
+ * ONLY the tier-0 RESIDUAL judge rows; a fully code-decided trajectory is skipped
267
+ * (no packet, no dispatch). Returns the trajectory ids that were PREPped (the
268
+ * dispatch keys). PURE except the packet-file writes.
269
+ *
270
+ * #3 EXAMINE fidelity gate (§9.4.2 node 1): a trajectory flagged INCOMPLETE is NEVER
271
+ * dispatched the full criteria walk — PREP writes a synthesized INCOMPLETE verdict
272
+ * file for it directly into `verdictDir` (deterministic, no judge tokens) and skips
273
+ * the packet. The returned ids are the DISPATCH keys only (complete + residual > 0).
274
+ */
275
+ export function prepMatrixPackets(input: EvaluateRunInput): string[] {
276
+ const ids: string[] = [];
277
+ for (const entry of tier0Plan(input)) {
278
+ if (!entry.fidelity.complete) {
279
+ // #3 short-circuit: emit the synthesized INCOMPLETE verdict (no dispatch).
280
+ writeMatrixVerdictFile(
281
+ input.verdictDir,
282
+ synthesizeIncompleteVerdictFile(entry.trace, input.criteria, input.pin, entry.fidelity),
283
+ );
284
+ continue;
285
+ }
286
+ if (entry.residualCriteria.length === 0) continue; // fully code-decided
287
+ // §9.4.4 M1 — carry the subject profile into every packet (ABSENT ⇒ byte-stable).
288
+ const packet = buildMatrixPacket(
289
+ input.subject.name,
290
+ entry.trace,
291
+ entry.residualCriteria,
292
+ input.pin,
293
+ input.subjectProfile,
294
+ );
295
+ ids.push(writeMatrixPacket(input.packetDir, packet));
296
+ }
297
+ return ids;
298
+ }
299
+
300
+ /** Test/verify helper: do all PREPped packet files exist on disk? PURE fs read. */
301
+ export function parseMatrixPacketsExist(packetDir: string, trajectoryIds: string[]): boolean {
302
+ return trajectoryIds.every((id) => existsSync(join(packetDir, packetFileName(id))));
303
+ }
304
+
305
+ // ── Readiness gate (fail-loud) ──────────────────────────────────────────────
306
+
307
+ /**
308
+ * Which trajectory verdict files are still MISSING from `verdictDir`. An empty
309
+ * array means every dispatched #mode-judge-trajectory leaf has a collected
310
+ * verdict → safe to roll up. The matrix-path analogue of `missingVerdictKeys`.
311
+ * PURE fs read.
312
+ */
313
+ export function missingMatrixVerdicts(verdictDir: string, trajectoryIds: string[]): string[] {
314
+ return trajectoryIds.filter((id) => !existsSync(join(verdictDir, matrixVerdictFileName(id))));
315
+ }
316
+
317
+ // ── AGGREGATE ───────────────────────────────────────────────────────────────
318
+
319
+ export interface EvaluateRunResult {
320
+ scorecard: Scorecard;
321
+ /** the folded per-criterion verdict (for the report's ✓/✗ table). */
322
+ verdicts: CriterionVerdict[];
323
+ /** the EV-051 diagnostics handover for failing criteria; null when none failed. */
324
+ handover: HandoverBundle | null;
325
+ /** GA — indeterminate CRIT/HIGH criteria routed to the CALIBRATION loop (not
326
+ * diagnostics): re-ground / operator-ratify / re-scope by blockedBy.kind. */
327
+ calibration: CalibrationItem[];
328
+ /** T4 — failing criteria CONSOLIDATED by shared root locus (1 finding, N symptoms). */
329
+ lociClusters: LocusCluster[];
330
+ trajectoryIds: string[];
331
+ /** #3 — trajectory ids the EXAMINE fidelity gate flagged INCOMPLETE (truncated /
332
+ * empty): never dispatched the full criteria walk; a synthesized INCOMPLETE
333
+ * verdict was emitted instead. Visible + auditable. */
334
+ incompleteTrajectories: string[];
335
+ /** #6 (T3) — the AUDITABLE independent-verify ledger (one record per gating fail
336
+ * that went through the 2nd-judge refutation; upheld or downgraded). EMPTY when
337
+ * no independent-verify pass ran. */
338
+ independentVerify: IndependentVerifyRecord[];
339
+ /** UI-12-A — GA-1 grounding-capture readiness over the final folded verdicts.
340
+ * `warning` is set (and logged loudly) on the silent-capture regression (decided
341
+ * verdicts present, zero carry refs). ADVISORY — never gates the run. */
342
+ groundingReadiness: GroundingReadiness;
343
+ /** WS-1 — judge EMIT-CONTRACT completeness over the dispatched verdicts (how many
344
+ * complete-fidelity verdicts carry M2+M3+agentSteps+judgeSteps). `warning` is set
345
+ * + logged loudly when a required walk field is wholly dropped. ADVISORY — feeds
346
+ * the §5 Self-Eval Emit-Completeness panel; never gates the run. */
347
+ emitCompleteness: EmitCompleteness;
348
+ }
349
+
350
+ /**
351
+ * AGGREGATE: the fail-loud readiness gate → read the dispatched verdict files →
352
+ * `aggregateMatrixScorecard` (GATE + variance, C-PIN PURE) → EV-051 route failing
353
+ * criteria to a diagnostics HandoverBundle. THROWS if any trajectory verdict is
354
+ * missing (never rolls up a partial scorecard). JUDGE-ONLY: no remedy is emitted.
355
+ */
356
+ export function aggregateEvaluate(input: EvaluateRunInput): EvaluateRunResult {
357
+ // T1 — the tier-0 plan decides which trajectories need a dispatched judge verdict
358
+ // (residual rows > 0) vs are fully code-decided (no verdict file expected).
359
+ const plan = tier0Plan(input);
360
+ const dispatchedIds = plan.filter((e) => e.residualCriteria.length > 0).map((e) => e.trace.id);
361
+
362
+ // (2) FAIL-LOUD readiness gate — every DISPATCHED verdict must be collected (a
363
+ // fully code-decided trajectory is excluded; it never produced a packet/verdict).
364
+ const missing = missingMatrixVerdicts(input.verdictDir, dispatchedIds);
365
+ if (missing.length > 0) {
366
+ throw new Error(
367
+ `aggregateEvaluate: ${missing.length} trajectory verdict file(s) MISSING ` +
368
+ `(${missing.join(", ")}). FAIL-LOUD readiness gate — never roll up a partial ` +
369
+ "scorecard. PREP packets → dispatch #mode-judge-trajectory → collect ALL verdict " +
370
+ "files before AGGREGATE.",
371
+ );
372
+ }
373
+
374
+ // CODE-EVAL STDOUT (never-blind): stream each deterministic per-criterion code
375
+ // verdict as JSONL to stdout BEFORE it folds into the scorecard below. Separate
376
+ // stream — does NOT touch the masked scorecard (C-PIN byte-identity preserved).
377
+ emitCodeEvalStdout(input, input.quietCodeEval === true);
378
+
379
+ const verdictFilesRaw = readMatrixVerdictFiles(input.verdictDir, dispatchedIds);
380
+ // T1 — the tier-0 code verdicts folded into the SAME per-criterion aggregation.
381
+ const codeVerdictsByTrajectory = plan
382
+ .filter((e) => e.codeVerdicts.length > 0)
383
+ .map((e) => ({ trajectoryId: e.trace.id, verdicts: e.codeVerdicts }));
384
+ const { scorecard, verdicts, independentVerify, groundingReadiness } = aggregateMatrixScorecard({
385
+ criteria: input.criteria,
386
+ verdictFilesRaw,
387
+ ...(codeVerdictsByTrajectory.length > 0 ? { codeVerdictsByTrajectory } : {}),
388
+ ...(input.independentVerify !== undefined ? { independentVerify: input.independentVerify } : {}),
389
+ ...(input.gatingSeverities !== undefined ? { gatingSeverities: input.gatingSeverities } : {}),
390
+ });
391
+ const trajectoryIds = input.trajectories.map((t) => t.id);
392
+
393
+ // (4b) UI-12-A — LOUD readiness assert: surface the GA-1 silent-capture regression
394
+ // prominently (a logged assertion) without hard-failing the run. The judge SHOULD
395
+ // emit refs[]{obs,path,value} per decided verdict; a 0-grounded batch is a defect.
396
+ if (groundingReadiness.warning !== undefined) {
397
+ console.warn(`[readiness-assert] ${groundingReadiness.warning}`);
398
+ } else if (groundingReadiness.decidedCount > 0) {
399
+ console.info(
400
+ `[readiness-assert] GA-1 grounding OK: ${groundingReadiness.groundedCount}/` +
401
+ `${groundingReadiness.decidedCount} decided verdicts grounded ` +
402
+ `(${groundingReadiness.groundedPctOfDecided}%).`,
403
+ );
404
+ }
405
+
406
+ // (4c) WS-1 — judge EMIT-CONTRACT completeness: loudly surface a dropped §9.4 walk
407
+ // (M2/M3/agentSteps/judgeSteps) so the Trajectory + Self-Eval tabs are HONEST about
408
+ // coverage. Advisory — never gates the run; computed over the COMPLETE-fidelity
409
+ // dispatched verdicts (INCOMPLETE traces legitimately skip the walk).
410
+ const emitCompleteness = assessEmitCompleteness(verdictFilesRaw.map(parseVerdictFileForReport));
411
+ if (emitCompleteness.warning !== undefined) {
412
+ console.warn(`[emit-contract] ${emitCompleteness.warning}`);
413
+ } else if (emitCompleteness.eligible > 0) {
414
+ console.info(
415
+ `[emit-contract] judge-walk completeness: ${emitCompleteness.completeEmits}/` +
416
+ `${emitCompleteness.eligible} complete-fidelity verdicts carry M2+M3+agentSteps+judgeSteps ` +
417
+ `(${emitCompleteness.completePct}%).`,
418
+ );
419
+ }
420
+
421
+ // (5) EV-051 — route failing criteria to a diagnostics handover (NEVER fix).
422
+ const verdictById = new Map(verdicts.map((v) => [v.criterionId, v]));
423
+ const failures: FailureRef[] = scorecard.gate.failedCriteria.map((fc) => {
424
+ const v = verdictById.get(fc.criterionId);
425
+ const ref: FailureRef = {
426
+ criterionId: fc.criterionId,
427
+ severity: fc.severity,
428
+ // eval-matrix failures are behavioral eval-worthy judgments (infra fixables
429
+ // are flagged upstream at *discover-evals); routed for root-cause, never fixed here.
430
+ flag: CriterionFlag.EvalWorthy,
431
+ traceId: v?.traceId ?? "(suite)",
432
+ result: v?.result ?? "fail",
433
+ critique: v?.critique ?? "(no critique)",
434
+ };
435
+ // GA — NO silent drop: carry the indeterminate's blockedBy for calibration routing.
436
+ if (v?.blockedBy !== undefined) ref.blockedBy = v.blockedBy;
437
+ return ref;
438
+ });
439
+ // GA — only true FAILs become a diagnostics handover; indeterminates route to
440
+ // the calibration loop (partitioned inside routeFailures / calibrationItems).
441
+ const diagnoseFailures = failures.filter((f) => f.result === "fail");
442
+ const handover =
443
+ diagnoseFailures.length > 0
444
+ ? routeFailures({
445
+ subject: input.subject,
446
+ failures: diagnoseFailures,
447
+ artifacts: input.artifacts ?? [],
448
+ producedBy: input.producedBy,
449
+ producedAt: input.producedAt,
450
+ })
451
+ : null;
452
+ const calibration = calibrationItems(failures);
453
+
454
+ // T4 — consolidate the failing criteria by their shared root locus (read off the
455
+ // dispatched judge walks). A fully-code-decided run has no walks ⇒ each fail is
456
+ // its own `unlocalized:<id>` cluster (never falsely merged).
457
+ const failingVerdicts = verdicts.filter((v) => v.result === "fail");
458
+ const lociClusters =
459
+ failingVerdicts.length > 0
460
+ ? consolidateByLocus(failingVerdicts, readRunVerdictFiles(input))
461
+ : [];
462
+
463
+ return {
464
+ scorecard,
465
+ verdicts,
466
+ handover,
467
+ calibration,
468
+ lociClusters,
469
+ trajectoryIds,
470
+ incompleteTrajectories: incompleteTrajectoryIds(input),
471
+ independentVerify,
472
+ groundingReadiness,
473
+ emitCompleteness,
474
+ };
475
+ }
476
+
477
+ /** The C-PIN byte-identity artifact: the masked canonical scorecard. */
478
+ export function maskedScorecard(scorecard: Scorecard): string {
479
+ return maskedCanonicalJson(scorecard);
480
+ }
481
+
482
+ // ── REPORT (D-2/D-3) — render the 5-tab HTML eval-report from the run ─────────
483
+
484
+ /**
485
+ * WS-1 — parse a verdict file for the REPORT path WITHOUT dropping the rich §9.4
486
+ * judge-walk additive fields. The strict `parseMatrixVerdictFile` rejects two
487
+ * tolerant real-judge shapes that ride on EXACTLY the walk-bearing files:
488
+ * • `context.exitStates` emitted as a STRUCTURED object (e.g. `{steps: 7}`) where
489
+ * the schema allows only `string | string[]`, and
490
+ * • `subjectProfile` emitted WITHOUT `tools` (the schema marks it required).
491
+ * On a strict-parse failure this coerces those two known shapes and re-validates; if
492
+ * it STILL fails it falls back to the raw parsed object so the report binds the rich
493
+ * judge reasoning rather than crashing/silently dropping the trajectory. The data
494
+ * leak this closes: the rich verdict files (which carry the judge_steps walk + per-
495
+ * criterion critique) were precisely the ones strict-parse threw on, so the §2
496
+ * "How the Judge Reasoned" view rendered with the rich traces MISSING. JUDGE-ONLY,
497
+ * read-only: no verdict content is altered beyond the two structural coercions.
498
+ */
499
+ function parseVerdictFileForReport(raw: string): MatrixVerdictFile {
500
+ try {
501
+ return parseMatrixVerdictFile(raw);
502
+ } catch {
503
+ const obj = JSON.parse(raw) as Record<string, unknown>;
504
+ const ctx = obj.context as { exitStates?: unknown } | undefined;
505
+ if (ctx && ctx.exitStates !== null && typeof ctx.exitStates === "object" && !Array.isArray(ctx.exitStates)) {
506
+ ctx.exitStates = Object.entries(ctx.exitStates as Record<string, unknown>)
507
+ .map(([k, v]) => `${k}: ${v}`)
508
+ .join(", ");
509
+ }
510
+ const sp = obj.subjectProfile as { tools?: unknown } | undefined;
511
+ if (sp && sp.tools === undefined) sp.tools = [];
512
+ try {
513
+ return parseMatrixVerdictFile(JSON.stringify(obj));
514
+ } catch {
515
+ // last resort — NEVER drop a rich verdict from the report over residual schema
516
+ // drift; the renderer reads the additive fields defensively.
517
+ return obj as unknown as MatrixVerdictFile;
518
+ }
519
+ }
520
+ }
521
+
522
+ /**
523
+ * Read + parse the per-trajectory Judge-Agent verdict files for the run (the rich
524
+ * §9.4 judge-walk fields, when emitted, ride along — `MatrixVerdictFile` carries
525
+ * them as OPTIONAL additive fields). PURE fs read. THROWS via `readMatrixVerdictFiles`
526
+ * if a verdict file is missing (the same fail-loud contract AGGREGATE uses).
527
+ *
528
+ * WS-1 — uses the TOLERANT `parseVerdictFileForReport` so the walk-bearing verdict
529
+ * files (object `exitStates` / no `subjectProfile.tools`) reach the renderer instead
530
+ * of being rejected by the strict schema (the rich-data-not-bound report leak).
531
+ */
532
+ export function readRunVerdictFiles(input: EvaluateRunInput): MatrixVerdictFile[] {
533
+ // T1 — the DISPATCHED trajectories (residual judge rows > 0) have a judge verdict
534
+ // file; a fully code-decided trajectory produced none and is skipped. #3 — the
535
+ // INCOMPLETE (truncated) trajectories carry a synthesized INCOMPLETE verdict file
536
+ // emitted at PREP, included here so the report shows them (they fold nothing).
537
+ const ids = [...judgeTrajectoryIds(input), ...incompleteTrajectoryIds(input)];
538
+ return readMatrixVerdictFiles(input.verdictDir, ids).map(parseVerdictFileForReport);
539
+ }
540
+
541
+ /**
542
+ * REPORT — build the rich `EvalReportInput` from the REAL run outputs (the folded
543
+ * scorecard + per-criterion verdicts + the per-trajectory Judge-Agent verdict
544
+ * files + the matrix criteria + the EV-051 handover) and render the 5-tab HTML
545
+ * eval-report into `<reportDir>/evaluation-report.html`. This is the wiring D-2/D-3 had been
546
+ * MISSING: `*evaluate` produced a scorecard but emitted no report. The report
547
+ * consumes the §9.4 judge-walk fields when present (side-by-side) and degrades to
548
+ * the per-trajectory scorecard otherwise. Returns the written report path.
549
+ *
550
+ * Deterministic: the only non-deterministic input is `producedAt` (injected,
551
+ * masked for byte-identity). PURE except the report-file write.
552
+ */
553
+ export function writeRunReport(
554
+ input: EvaluateRunInput,
555
+ result: EvaluateRunResult,
556
+ runId: string,
557
+ cwd?: string,
558
+ // PRD R-4 — render audience (resolved by the caller: explicit flag → config.default_audience →
559
+ // "client"). Omitted ⇒ the renderer defaults to "client" (leak-safe). "internal" shows §5.
560
+ audience?: "client" | "internal",
561
+ ): string {
562
+ const matrixVerdictFiles = readRunVerdictFiles(input);
563
+ const reportInput = buildEvalReportInput({
564
+ subject: { name: input.subject.name, source: input.subject.kind },
565
+ scorecard: result.scorecard,
566
+ verdicts: result.verdicts,
567
+ criteria: fromMatrixCriteria(input.criteria),
568
+ matrixVerdictFiles,
569
+ handover: result.handover,
570
+ generatedAt: input.producedAt,
571
+ // Gap A — pass the run's INGESTED traces so the report can source each
572
+ // trajectory's RAW triggering INPUT (`EvalTrace.input.prompt`) by trace id.
573
+ // The input is ground-truth in the trace (NOT a judge-emit field), so this
574
+ // surfaces the initial input that fired the subject agent without any
575
+ // judge-protocol change. ABSENT-tolerant (a row with no input renders "—").
576
+ traces: input.trajectories,
577
+ // §9.4.4 M1/R2 — carry the subject profile into the report (internal calibration).
578
+ ...(input.subjectProfile !== undefined ? { subjectProfile: input.subjectProfile } : {}),
579
+ // Overview provenance meta-strip — the run config (C-PIN: pinned judge model + temp 0).
580
+ // The JUDGE substrate defaults to agent-dispatch (host runtime); the SOURCE is the
581
+ // subject kind. The judge model is DISTINCT from any target model under eval.
582
+ runConfig: {
583
+ runId,
584
+ date: input.producedAt,
585
+ source: input.subject.kind,
586
+ judgeSubstrate: "agent-dispatch",
587
+ judgeModel: input.pin.model,
588
+ temperature: input.pin.temperature,
589
+ cPin: true,
590
+ },
591
+ });
592
+ if (audience) reportInput.audience = audience; // else renderEvalReport defaults to "client"
593
+ const dir = reportDir(runId, cwd);
594
+ mkdirSync(dir, { recursive: true });
595
+ const outPath = join(dir, "evaluation-report.html");
596
+ writeFileSync(outPath, renderEvalReport(reportInput));
597
+ return outPath;
598
+ }
599
+
600
+ /**
601
+ * #6 (T3) — persist the AUDITABLE independent-verify ledger as an on-disk artifact
602
+ * (`<reportDir>/independent-verify.json`) so the second-judge refutation result is
603
+ * inspectable outside the HTML report. Each record carries `{criterionId, upheld,
604
+ * reason, byDifferentJudge:true, reviewerId?, leapKind?}`. Returns the written path
605
+ * (or null when no independent-verify pass ran). PURE except the file write.
606
+ */
607
+ export function writeIndependentVerifyLedger(
608
+ result: EvaluateRunResult,
609
+ runId: string,
610
+ cwd?: string,
611
+ ): string | null {
612
+ if (result.independentVerify.length === 0) return null;
613
+ const dir = reportDir(runId, cwd);
614
+ mkdirSync(dir, { recursive: true });
615
+ const outPath = join(dir, "independent-verify.json");
616
+ writeFileSync(
617
+ outPath,
618
+ JSON.stringify(
619
+ {
620
+ byDifferentJudge: true,
621
+ records: result.independentVerify,
622
+ downgraded: result.independentVerify.filter((r) => !r.upheld).map((r) => r.criterionId),
623
+ upheld: result.independentVerify.filter((r) => r.upheld).map((r) => r.criterionId),
624
+ },
625
+ null,
626
+ 2,
627
+ ),
628
+ );
629
+ return outPath;
630
+ }
631
+
632
+ /**
633
+ * P8 (EV-REQ-058) — fill MISSING `packetDir`/`verdictDir` from the localized
634
+ * artifact resolver (`.mutagent/evaluator/runs/<runId>/{packets,verdicts}`). The
635
+ * CLI default-wiring: a bare run lands under the namespaced dot-root (no
636
+ * ad-hoc/scattered output paths). ADDITIVE — an explicitly-provided dir WINS;
637
+ * the PURE core functions still take explicit dirs (this only fills the defaults).
638
+ * PURE (runId + cwd passed in).
639
+ */
640
+ export function withResolvedDirs(
641
+ input: Omit<EvaluateRunInput, "packetDir" | "verdictDir"> & { packetDir?: string; verdictDir?: string },
642
+ runId: string,
643
+ cwd?: string,
644
+ ): EvaluateRunInput {
645
+ return {
646
+ ...input,
647
+ packetDir: input.packetDir ?? packetsDir(runId, cwd),
648
+ verdictDir: input.verdictDir ?? verdictsDir(runId, cwd),
649
+ };
650
+ }
651
+
652
+ // ── CLI entrypoint (the parent drives PREP, dispatches, then AGGREGATE) ──────
653
+ //
654
+ // prep: bun scripts/run-evaluate.ts prep <input.json>
655
+ // aggregate: bun scripts/run-evaluate.ts aggregate <input.json>
656
+ // `input.json` = an EvaluateRunInput. PREP writes packets; after the parent
657
+ // dispatches #mode-judge-trajectory and collects verdict files, AGGREGATE prints
658
+ // the GATE + variance summary + whether an EV-051 handover was emitted (secret-free).
659
+
660
+ declare const Bun: { argv: string[] } | undefined;
661
+
662
+ async function main(): Promise<void> {
663
+ const argv = typeof Bun !== "undefined" ? Bun.argv.slice(2) : process.argv.slice(2);
664
+ const positional = argv.filter((a) => !a.startsWith("--"));
665
+ const [mode, inputPath, runIdArg] = positional;
666
+ // Code-eval stdout is ALWAYS-ON; `--quiet-code-eval` opts out of the JSONL log.
667
+ const quietCodeEval = argv.includes("--quiet-code-eval");
668
+ if ((mode !== "prep" && mode !== "aggregate") || !inputPath) {
669
+ console.error("usage: run-evaluate.ts <prep|aggregate> <input.json> [runId] [--quiet-code-eval]");
670
+ process.exit(2);
671
+ return;
672
+ }
673
+ const { readFileSync } = await import("node:fs");
674
+ const parsed = JSON.parse(readFileSync(inputPath, "utf8")) as Omit<EvaluateRunInput, "packetDir" | "verdictDir"> & {
675
+ packetDir?: string;
676
+ verdictDir?: string;
677
+ };
678
+ // P8: a bare run (no packetDir/verdictDir in the input) DEFAULTS under the
679
+ // localized dot-root `.mutagent/evaluator/runs/<runId>/{packets,verdicts}`.
680
+ const runId = runIdArg ?? parsed.subject.name;
681
+ const input = { ...withResolvedDirs(parsed, runId), quietCodeEval };
682
+
683
+ if (mode === "prep") {
684
+ const ids = prepMatrixPackets(input);
685
+ console.info(JSON.stringify({ prepped: ids.length, packetDir: input.packetDir, trajectoryIds: ids }, null, 2));
686
+ process.exit(0);
687
+ return;
688
+ }
689
+ const out = aggregateEvaluate(input);
690
+ // REPORT (D-2/D-3): render the 5-tab HTML eval-report from the run. The
691
+ // orchestrator fires the cross-platform auto-open command post-render.
692
+ const reportPath = writeRunReport(input, out, runId);
693
+ // #6 (T3): persist the auditable independent-verify ledger artifact (if any).
694
+ const ivLedgerPath = writeIndependentVerifyLedger(out, runId);
695
+ console.info(
696
+ JSON.stringify(
697
+ {
698
+ trajectories: out.trajectoryIds.length,
699
+ gate: { passed: out.scorecard.gate.passed, total: out.scorecard.gate.total, passCount: out.scorecard.gate.passCount, gatedBy: out.scorecard.gate.gatedBy },
700
+ varianceCriteria: Object.keys(out.scorecard.variance).length,
701
+ handoverEmitted: out.handover !== null,
702
+ routedFailures: out.handover?.acceptance.criteria.length ?? 0,
703
+ incompleteTrajectories: out.incompleteTrajectories,
704
+ independentVerify: { records: out.independentVerify.length, ledger: ivLedgerPath },
705
+ report: reportPath,
706
+ },
707
+ null,
708
+ 2,
709
+ ),
710
+ );
711
+ process.exit(0);
712
+ }
713
+
714
+ const isMain =
715
+ typeof import.meta !== "undefined" &&
716
+ (import.meta as unknown as { main?: boolean }).main === true;
717
+ if (isMain) {
718
+ void main();
719
+ }