@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,143 @@
1
+ /**
2
+ * scripts/tier0/langfuse.ts
3
+ * R-SELF-11-a: Per-platform Tier 0 module for langfuse source.
4
+ *
5
+ * Langfuse traces carry explicit score + feedback + latency signals
6
+ * as first-class fields — this module produces a Tier 0 report tuned
7
+ * to Langfuse's signal density.
8
+ *
9
+ * Invoked by tier0-scan.ts when `sourcePlatform === "langfuse"`.
10
+ * Type A — Pure Script (deterministic pattern matching, no LLM calls)
11
+ */
12
+
13
+ import type { TraceMetadata } from "../normalize/trace.ts";
14
+ // I-020/PR-033 drift fix (SL-5): reuse the generic scanner's IQR fence rather than
15
+ // reimplementing it, so Langfuse-source runs honor thresholdMode identically to the
16
+ // generic path. `iqrUpperFence` is a runtime value import; tier0-scan.ts only DYNAMICALLY
17
+ // imports this module (via dispatchPlatformTier0), so there is no eval-time import cycle.
18
+ import { iqrUpperFence } from "../tier0-scan.ts";
19
+ import type { Tier0Report, PatternMatch, Tier0ScanConfig } from "../tier0-scan.ts";
20
+
21
+ const HIGH_LATENCY_MS = 10_000; // absolute gate; also the <4-sample fallback in relative mode
22
+ const LOW_SCORE_RAW_MAX = 0.4;
23
+ const MAX_ESTIMATED_SLOTS = 5;
24
+
25
+ // I-020: default to "relative" — identical to the generic scanner's DEFAULT_TIER0_CONFIG.
26
+ // Before this fix runLangfuseTier0 IGNORED the config entirely and hardcoded the absolute
27
+ // HIGH_LATENCY_MS gate, so a `thresholdMode:"relative"` request silently used the absolute
28
+ // threshold on Langfuse-source runs (PR-033 drift found by SimuLatte SL-5).
29
+ const DEFAULT_LANGFUSE_TIER0_CONFIG: Tier0ScanConfig = { thresholdMode: "relative" };
30
+
31
+ export function runLangfuseTier0(
32
+ traces: TraceMetadata[],
33
+ config: Tier0ScanConfig = DEFAULT_LANGFUSE_TIER0_CONFIG
34
+ ): Tier0Report {
35
+ const withError = traces.filter((t) => t.hasError);
36
+ const withFeedback = traces.filter((t) => t.hasFeedback);
37
+ const withLowScore = traces.filter((t) => {
38
+ if (t.normalizedScore !== undefined) return t.normalizedScore <= LOW_SCORE_RAW_MAX;
39
+ return typeof t.rawScore === "number" && t.rawScore < 3;
40
+ });
41
+
42
+ // I-020/PR-033: high-latency threshold follows thresholdMode, mirroring the generic
43
+ // runTier0Scan semantics EXACTLY — "relative" derives a per-batch Tukey IQR upper fence
44
+ // (Q3 + 1.5·IQR), falling back to the absolute constant when <4 latency samples exist;
45
+ // "absolute" uses the fixed HIGH_LATENCY_MS constant.
46
+ let highLatencyThreshold: number;
47
+ if (config.thresholdMode === "relative") {
48
+ const latencySamples = traces
49
+ .filter((t) => t.latencyMs !== undefined)
50
+ .map((t) => t.latencyMs as number);
51
+ highLatencyThreshold = iqrUpperFence(latencySamples) ?? HIGH_LATENCY_MS;
52
+ } else {
53
+ highLatencyThreshold = HIGH_LATENCY_MS;
54
+ }
55
+
56
+ const withHighLatency = traces.filter(
57
+ (t) => t.latencyMs !== undefined && t.latencyMs > highLatencyThreshold
58
+ );
59
+
60
+ // Langfuse-specific: check API exhaustion (v0.3 apiErrors — may be populated
61
+ // if the Langfuse normalizer captures SDK retry events)
62
+ const withApiExhaustion = traces.filter(
63
+ (t) =>
64
+ Array.isArray(t.apiErrors) &&
65
+ t.apiErrors.some((e) => e.retryAttempt >= e.maxRetries)
66
+ );
67
+ const hasApiExhaustion = withApiExhaustion.length > 0;
68
+
69
+ const hasPrimarySignal =
70
+ withFeedback.length > 0 || withLowScore.length > 0 || hasApiExhaustion;
71
+
72
+ const patterns: PatternMatch[] = [];
73
+
74
+ // P-001: error spike (>20% error rate)
75
+ const errorRate = withError.length / Math.max(traces.length, 1);
76
+ if (errorRate > 0.2) {
77
+ patterns.push({
78
+ patternId: "P-001",
79
+ name: "error-spike",
80
+ matchCount: withError.length,
81
+ traceIds: withError.map((t) => t.traceId),
82
+ });
83
+ }
84
+
85
+ // P-002: latency spike (>10% high latency)
86
+ const latencyRate = withHighLatency.length / Math.max(traces.length, 1);
87
+ if (latencyRate > 0.1) {
88
+ patterns.push({
89
+ patternId: "P-002",
90
+ name: "latency-spike",
91
+ matchCount: withHighLatency.length,
92
+ traceIds: withHighLatency.map((t) => t.traceId),
93
+ });
94
+ }
95
+
96
+ // P-003: feedback cluster (>5% feedback bearing)
97
+ const feedbackRate = withFeedback.length / Math.max(traces.length, 1);
98
+ if (feedbackRate > 0.05) {
99
+ patterns.push({
100
+ patternId: "P-003",
101
+ name: "feedback-cluster",
102
+ matchCount: withFeedback.length,
103
+ traceIds: withFeedback.map((t) => t.traceId),
104
+ });
105
+ }
106
+
107
+ // LF-001: score concentration in low tier (>30% below threshold — strong signal density)
108
+ const lowScoreRate = withLowScore.length / Math.max(traces.length, 1);
109
+ if (lowScoreRate > 0.3 && withLowScore.length > 2) {
110
+ patterns.push({
111
+ patternId: "LF-001",
112
+ name: "low-score-concentration",
113
+ matchCount: withLowScore.length,
114
+ traceIds: withLowScore.map((t) => t.traceId),
115
+ });
116
+ }
117
+
118
+ // NOTE: a former LF-002 "low-tagging-rate" pattern (>80% untagged) was REMOVED
119
+ // (W12-05 / PR-051 propose). Empty `tags[]` is Langfuse dashboard hygiene, NOT
120
+ // agent behavior — it is not a failure WHAT and must never surface as a signal,
121
+ // census row, or finding. The Tier-0 census admits only mechanical signals that
122
+ // map to a user-visible failure (loop / latency / cost / error / feedback / score);
123
+ // observability hygiene is out of scope by construction.
124
+ // See references/principles.md PR-049 step-2 + feedback_signal_discipline_evidence_first.
125
+
126
+ const slots = Math.min(
127
+ Math.max(1, patterns.length + (hasPrimarySignal ? 1 : 0)),
128
+ MAX_ESTIMATED_SLOTS
129
+ );
130
+
131
+ return {
132
+ totalTraces: traces.length,
133
+ withError: withError.length,
134
+ withFeedback: withFeedback.length,
135
+ withLowScore: withLowScore.length,
136
+ withHighLatency: withHighLatency.length,
137
+ hasApiExhaustion,
138
+ hasPrimarySignal,
139
+ recommendedSlicing: hasPrimarySignal ? "dynamic-cluster" : "window-based",
140
+ estimatedSlots: slots,
141
+ patterns,
142
+ };
143
+ }
@@ -0,0 +1,423 @@
1
+ /**
2
+ * scripts/tier0-scan.ts
3
+ * Tier 0 static pattern scan — runs BEFORE any LLM call (PR-001)
4
+ * Type A — Pure Script (deterministic pattern matching + counts)
5
+ *
6
+ * Reads a JSON array of TraceMetadata, computes signal counts, emits a structured
7
+ * route-guess that tells the orchestrator whether to use dynamic-cluster or window-based slicing.
8
+ *
9
+ * R-SELF-11-a: When all traces share a single sourcePlatform, dispatches to the
10
+ * per-platform Tier 0 module for richer signal extraction. Falls back to generic
11
+ * path for mixed-platform or unknown batches.
12
+ *
13
+ * I-020: Relative threshold mode (PR-033). Anomaly detection uses per-session
14
+ * p95/IQR comparisons instead of hardcoded numeric thresholds. Default: "relative".
15
+ *
16
+ * Usage: bun scripts/tier0-scan.ts <traces-metadata.json>
17
+ */
18
+
19
+ import { readFileSync } from "fs";
20
+ import type { TraceMetadata, SourcePlatform } from "./normalize/trace.ts";
21
+ import { ensureBuiltinSourceAdapters, tryGetSourceAdapter } from "./source/index.ts";
22
+
23
+ /**
24
+ * I-020: Scan configuration for anomaly threshold mode (PR-033).
25
+ */
26
+ export interface Tier0ScanConfig {
27
+ /**
28
+ * Threshold mode for latency anomaly detection.
29
+ * "relative" (default): IQR-based per-session outlier detection — no hardcoded ms values.
30
+ * A trace is "high latency" if its latencyMs is above Q3 + 1.5 * IQR of the batch.
31
+ * Falls back to absolute when fewer than 4 latency samples are available.
32
+ * "absolute" (legacy): fixed HIGH_LATENCY_MS = 10_000 ms threshold (backward-compat).
33
+ */
34
+ thresholdMode: "absolute" | "relative";
35
+ }
36
+
37
+ const DEFAULT_TIER0_CONFIG: Tier0ScanConfig = {
38
+ thresholdMode: "relative",
39
+ };
40
+
41
+ export interface Tier0Report {
42
+ totalTraces: number;
43
+ withError: number;
44
+ withFeedback: number;
45
+ withLowScore: number;
46
+ withHighLatency: number;
47
+ /**
48
+ * R-SELF-06-b: true when ANY trace has retryAttempt === maxRetries
49
+ * (provider exhausted all retries — a primary failure signal regardless of score).
50
+ */
51
+ hasApiExhaustion: boolean;
52
+ /**
53
+ * I-012: true when ANY trace has skill workflow deviations detected
54
+ * (TraceMetadata.skillBehaviorDeviationCount > 0).
55
+ * Covers: skipped signal census, omitted assumption enumeration, bypassed scope construct.
56
+ * Optional for backward-compat with platform-specific tier0 modules (claude-code, langfuse).
57
+ */
58
+ hasSkillBehaviorDeviation?: boolean;
59
+ /** Whether score/feedback signal is present (determines slicing strategy) */
60
+ hasPrimarySignal: boolean;
61
+ /** Recommended slicing: dynamic-cluster (scored) or window-based (naive) */
62
+ recommendedSlicing: "dynamic-cluster" | "window-based";
63
+ /** Estimated number of analyzer slots needed (capped at 5) */
64
+ estimatedSlots: number;
65
+ /** Known failure patterns matched */
66
+ patterns: PatternMatch[];
67
+ /**
68
+ * I-012: Typed Axis-1 signals — includes skill-behavior-deviation and future signal types.
69
+ * Separate from `patterns` (which are structural patterns P-001/P-002/P-003).
70
+ * Each entry has a `type` field for jq-queryable enumeration.
71
+ * Optional for backward-compat with platform-specific tier0 modules (claude-code, langfuse).
72
+ */
73
+ signals?: SignalMatch[];
74
+ /**
75
+ * I-020: Scan configuration applied for this report.
76
+ * Present when using runTier0Scan or runTier0ScanPlatformAware directly.
77
+ * Optional to avoid breaking per-platform modules (claude-code, langfuse) that return
78
+ * Tier0Report without config — runTier0ScanPlatformAware merges config in after dispatch.
79
+ */
80
+ config?: Tier0ScanConfig;
81
+ /**
82
+ * Wave-6 R2.3: class-memory library matches, MATCHED FIRST (before generic
83
+ * heuristics). Each entry carries the 3× prior weight. Present only when the scan
84
+ * was run via runTier0ScanWithLibrary against an entity with library priors.
85
+ * Optional (backward-compat — absent on every pre-R2.3 path).
86
+ */
87
+ libraryMatches?: LibraryMatchSummary[];
88
+ }
89
+
90
+ /**
91
+ * Wave-6 R2.3: a single library-prior match surfaced in a Tier-0 report.
92
+ * Mirrors scripts/library/match.ts LibraryMatch (kept structural here so
93
+ * tier0-scan.ts does not hard-depend on the library on the generic path).
94
+ */
95
+ export interface LibraryMatchSummary {
96
+ patternId: string;
97
+ signal: string;
98
+ matchCount: number;
99
+ traceIds: string[];
100
+ /** 3× prior weight (library priors outrank fresh Tier-0 signals). */
101
+ weight: number;
102
+ }
103
+
104
+
105
+ /**
106
+ * I-012: Typed signal match — one entry per detected signal category.
107
+ * Used to surface skill workflow deviations and other Axis-1 signals.
108
+ */
109
+ export interface SignalMatch {
110
+ /** Signal category type (e.g. "skill-behavior-deviation") */
111
+ type: string;
112
+ /** Number of traces where this signal was detected */
113
+ matchCount: number;
114
+ /** Trace IDs that exhibited this signal */
115
+ traceIds: string[];
116
+ }
117
+
118
+ export interface PatternMatch {
119
+ patternId: string;
120
+ name: string;
121
+ matchCount: number;
122
+ traceIds: string[];
123
+ }
124
+
125
+ const HIGH_LATENCY_MS = 10_000; // used only when thresholdMode === "absolute"
126
+ const LOW_SCORE_RAW_MAX = 0.4; // used when normalizedScore present
127
+
128
+ // ── I-020: Per-session relative threshold helpers (PR-033) ────────────────────
129
+
130
+ /**
131
+ * Compute the p95 (95th percentile) of a numeric array using linear interpolation.
132
+ * Returns null for empty arrays.
133
+ */
134
+ export function computeP95(values: number[]): number | null {
135
+ if (values.length === 0) return null;
136
+ const sorted = [...values].sort((a, b) => a - b);
137
+ const idx = 0.95 * (sorted.length - 1);
138
+ const lower = Math.floor(idx);
139
+ const upper = Math.ceil(idx);
140
+ if (lower === upper) return sorted[lower];
141
+ return sorted[lower] + (idx - lower) * (sorted[upper] - sorted[lower]);
142
+ }
143
+
144
+ /**
145
+ * Compute the Tukey IQR upper fence (Q3 + 1.5 × IQR) for outlier detection.
146
+ * A value above this fence is considered an anomaly relative to the batch.
147
+ *
148
+ * Uses linear interpolation for Q1/Q3 (same as computeP95).
149
+ * Returns null when fewer than 4 values are available (insufficient for IQR).
150
+ * Falls back to HIGH_LATENCY_MS (absolute) in the caller when null.
151
+ */
152
+ export function iqrUpperFence(values: number[]): number | null {
153
+ if (values.length < 4) return null;
154
+ const sorted = [...values].sort((a, b) => a - b);
155
+ const n = sorted.length - 1;
156
+ const q1Idx = 0.25 * n;
157
+ const q3Idx = 0.75 * n;
158
+ const q1 =
159
+ sorted[Math.floor(q1Idx)] +
160
+ (q1Idx - Math.floor(q1Idx)) * (sorted[Math.ceil(q1Idx)] - sorted[Math.floor(q1Idx)]);
161
+ const q3 =
162
+ sorted[Math.floor(q3Idx)] +
163
+ (q3Idx - Math.floor(q3Idx)) * (sorted[Math.ceil(q3Idx)] - sorted[Math.floor(q3Idx)]);
164
+ const iqr = q3 - q1;
165
+ return q3 + 1.5 * iqr;
166
+ }
167
+
168
+ /**
169
+ * R-SELF-11-a: Detect the dominant platform in a batch of traces.
170
+ * Returns the platform if ALL traces share the same sourcePlatform, else null.
171
+ */
172
+ function detectSinglePlatform(traces: TraceMetadata[]): SourcePlatform | null {
173
+ if (traces.length === 0) return null;
174
+ const first = traces[0].sourcePlatform;
175
+ if (!first) return null;
176
+ return traces.every((t) => t.sourcePlatform === first) ? first : null;
177
+ }
178
+
179
+ /**
180
+ * R-SELF-11-a: Dispatch to per-platform Tier 0 module when batch is homogeneous.
181
+ * Falls back to generic path for mixed-platform or unknown-platform batches.
182
+ *
183
+ * Item #7: resolution is now REGISTRY-driven (scripts/source) instead of a
184
+ * hard-coded `if (platform === …)` switch — a new source registers declaratively
185
+ * and its optional `tier0Scan` is picked up here with ZERO edits to this file.
186
+ * Behavior is byte-identical to the prior switch:
187
+ * - langfuse → runLangfuseTier0(traces, config) (config-honoring, I-020/PR-033)
188
+ * - claude-code→ runClaudeCodeTier0(traces)
189
+ * - otel / local-jsonl / codex / unknown → null (adapter has no tier0Scan) → generic scan
190
+ * Any adapter/module load or scan failure falls through to the generic path.
191
+ */
192
+ async function dispatchPlatformTier0(
193
+ traces: TraceMetadata[],
194
+ platform: SourcePlatform,
195
+ config: Tier0ScanConfig = DEFAULT_TIER0_CONFIG
196
+ ): Promise<Tier0Report | null> {
197
+ ensureBuiltinSourceAdapters();
198
+ const adapter = tryGetSourceAdapter(platform);
199
+ // No adapter, or an adapter WITHOUT a bespoke scanner (otel/local-jsonl/codex),
200
+ // takes the generic path — exactly as the pre-registry fallback did.
201
+ if (!adapter || !adapter.tier0Scan) return null;
202
+ try {
203
+ return await adapter.tier0Scan(traces, config);
204
+ } catch {
205
+ // Module load / scan failure — fall through to generic path
206
+ return null;
207
+ }
208
+ }
209
+
210
+ /**
211
+ * Generic (platform-agnostic) Tier 0 scan.
212
+ * Used as the fallback when platform dispatch is unavailable or not applicable.
213
+ * Also exported for use by per-platform modules that want to extend the base result.
214
+ *
215
+ * @param traces Batch of TraceMetadata to scan.
216
+ * @param config I-020: Scan configuration. Defaults to { thresholdMode: "relative" }.
217
+ */
218
+ export function runTier0Scan(traces: TraceMetadata[], config: Tier0ScanConfig = DEFAULT_TIER0_CONFIG): Tier0Report {
219
+ const withError = traces.filter((t) => t.hasError);
220
+ const withFeedback = traces.filter((t) => t.hasFeedback);
221
+ // R-SELF-04-a: treat null rawScore correctly — only count traces where
222
+ // rawScore is an actual number below threshold, not null/undefined.
223
+ const withLowScore = traces.filter((t) => {
224
+ if (t.normalizedScore !== undefined) {
225
+ return t.normalizedScore <= LOW_SCORE_RAW_MAX;
226
+ }
227
+ // rawScore must be a non-null number strictly below 3
228
+ return typeof t.rawScore === "number" && t.rawScore < 3;
229
+ });
230
+
231
+ // I-020: High-latency detection — relative (IQR) or absolute (hardcoded ms).
232
+ // In "relative" mode, the threshold is derived per-session from the batch's own
233
+ // latency distribution using the Tukey IQR upper fence (Q3 + 1.5 × IQR).
234
+ // This means no hardcoded ms values drive the anomaly gate (PR-033).
235
+ let highLatencyThreshold: number;
236
+ if (config.thresholdMode === "relative") {
237
+ const latencySamples = traces
238
+ .filter((t) => t.latencyMs !== undefined)
239
+ .map((t) => t.latencyMs as number);
240
+ // iqrUpperFence returns null when <4 samples — fall back to absolute threshold.
241
+ highLatencyThreshold = iqrUpperFence(latencySamples) ?? HIGH_LATENCY_MS;
242
+ } else {
243
+ highLatencyThreshold = HIGH_LATENCY_MS;
244
+ }
245
+
246
+ const withHighLatency = traces.filter(
247
+ (t) => t.latencyMs !== undefined && t.latencyMs > highLatencyThreshold
248
+ );
249
+
250
+ // R-SELF-06-b: API exhaustion = retryAttempt reached maxRetries on any trace
251
+ const hasApiExhaustion = traces.some(
252
+ (t) =>
253
+ Array.isArray(t.apiErrors) &&
254
+ t.apiErrors.some((e) => e.retryAttempt >= e.maxRetries)
255
+ );
256
+
257
+ // I-012: skill-behavior-deviation — skill deviated from documented workflow
258
+ // (e.g., skipped signal census, omitted assumption enumeration, bypassed scope construct)
259
+ const withSkillDeviation = traces.filter(
260
+ (t) => typeof t.skillBehaviorDeviationCount === "number" && t.skillBehaviorDeviationCount > 0
261
+ );
262
+ const hasSkillBehaviorDeviation = withSkillDeviation.length > 0;
263
+
264
+ const hasPrimarySignal = withFeedback.length > 0 || withLowScore.length > 0 || hasApiExhaustion;
265
+
266
+ // Pattern: error spike (>20% error rate)
267
+ const patterns: PatternMatch[] = [];
268
+ const errorRate = withError.length / Math.max(traces.length, 1);
269
+ if (errorRate > 0.2) {
270
+ patterns.push({
271
+ patternId: "P-001",
272
+ name: "error-spike",
273
+ matchCount: withError.length,
274
+ traceIds: withError.map((t) => t.traceId),
275
+ });
276
+ }
277
+
278
+ // Pattern: latency spike (>10% high latency)
279
+ const latencyRate = withHighLatency.length / Math.max(traces.length, 1);
280
+ if (latencyRate > 0.1) {
281
+ patterns.push({
282
+ patternId: "P-002",
283
+ name: "latency-spike",
284
+ matchCount: withHighLatency.length,
285
+ traceIds: withHighLatency.map((t) => t.traceId),
286
+ });
287
+ }
288
+
289
+ // Pattern: feedback cluster (>5% feedback bearing)
290
+ const feedbackRate = withFeedback.length / Math.max(traces.length, 1);
291
+ if (feedbackRate > 0.05) {
292
+ patterns.push({
293
+ patternId: "P-003",
294
+ name: "feedback-cluster",
295
+ matchCount: withFeedback.length,
296
+ traceIds: withFeedback.map((t) => t.traceId),
297
+ });
298
+ }
299
+
300
+ // I-012: Build Axis-1 signals array (typed signal categories, separate from patterns)
301
+ const signals: SignalMatch[] = [];
302
+ if (hasSkillBehaviorDeviation) {
303
+ signals.push({
304
+ type: "skill-behavior-deviation",
305
+ matchCount: withSkillDeviation.length,
306
+ traceIds: withSkillDeviation.map((t) => t.traceId),
307
+ });
308
+ }
309
+
310
+ // Estimate slots: one slot per distinct signal cluster, capped at 5 (PR-005)
311
+ const slots = Math.min(
312
+ Math.max(1, patterns.length + (hasPrimarySignal ? 1 : 0)),
313
+ 5
314
+ );
315
+
316
+ return {
317
+ totalTraces: traces.length,
318
+ withError: withError.length,
319
+ withFeedback: withFeedback.length,
320
+ withLowScore: withLowScore.length,
321
+ withHighLatency: withHighLatency.length,
322
+ hasApiExhaustion,
323
+ hasSkillBehaviorDeviation,
324
+ hasPrimarySignal,
325
+ recommendedSlicing: hasPrimarySignal ? "dynamic-cluster" : "window-based",
326
+ estimatedSlots: slots,
327
+ patterns,
328
+ signals,
329
+ // I-020: record the config used so callers / jq queries can inspect thresholdMode
330
+ config,
331
+ };
332
+ }
333
+
334
+ /**
335
+ * R-SELF-11-a: Platform-aware entry point.
336
+ * Detects dominant sourcePlatform and dispatches to the appropriate per-platform
337
+ * module. Falls back to generic runTier0Scan for mixed or unknown batches.
338
+ *
339
+ * I-020: config is merged into the result regardless of path so that
340
+ * `.config.thresholdMode` is always present in CLI output (PR-033 audit surface).
341
+ *
342
+ * This is the preferred entrypoint for the orchestrator. The synchronous
343
+ * runTier0Scan export is kept for testing and for per-platform modules that
344
+ * call it internally.
345
+ */
346
+ export async function runTier0ScanPlatformAware(
347
+ traces: TraceMetadata[],
348
+ config: Tier0ScanConfig = DEFAULT_TIER0_CONFIG
349
+ ): Promise<Tier0Report> {
350
+ const platform = detectSinglePlatform(traces);
351
+ if (platform) {
352
+ // I-020/PR-033: thread config INTO the per-platform module (not just merged into the
353
+ // result afterward) so the platform scanner actually COMPUTES with the requested
354
+ // thresholdMode — the langfuse module previously ignored it and hardcoded absolute.
355
+ const result = await dispatchPlatformTier0(traces, platform, config);
356
+ // Merge config into platform-specific result so .config.thresholdMode is always present
357
+ if (result) return { ...result, config };
358
+ }
359
+ // Generic fallback
360
+ return runTier0Scan(traces, config);
361
+ }
362
+
363
+ /**
364
+ * Wave-6 R2.3 / PRD-MP-07 (PR-037): library-FIRST Tier-0 entry point.
365
+ * Takes PRE-COMPUTED library matches (the caller runs scripts/library/match.ts
366
+ * FIRST, before this scan) and attaches them to the report's `libraryMatches`
367
+ * so the promoted patterns are surfaced ahead of the generic heuristics.
368
+ * The generic scan is unchanged — library matches are ADDITIVE prior signals
369
+ * carrying the 3× weight.
370
+ *
371
+ * PRD-MP-07 ENFORCEMENT: This function is now the PREFERRED entry point for
372
+ * the orchestrator at Step 4 (Tier-0). The orchestrator MUST:
373
+ * 1. Call matchLibraryPatterns() from scripts/library/match.ts FIRST.
374
+ * 2. Call this function with the resulting matches (empty array = no-op).
375
+ * 3. When matches.length > 0: skip Step 3.5 awareness mini-sample (buildPriorSignalsRef
376
+ * provides the ref to pass to shouldFireAwareness({ priorSignalsRef })).
377
+ * 4. Record the skip in runMeta.exemptions: [{ stepId: 'awareness-sample',
378
+ * reason: 'library-priors:' + ref, declaredBy: 'orchestrator' }].
379
+ *
380
+ * Library writes are approved-only — never auto-promoted without operator gate.
381
+ * Keeping the matcher OUT of this function keeps it dependency-light (pure wrapper).
382
+ *
383
+ * When there are no library matches, this behaves identically to
384
+ * runTier0ScanPlatformAware.
385
+ */
386
+ export async function runTier0ScanWithLibrary(
387
+ traces: TraceMetadata[],
388
+ libraryMatches: LibraryMatchSummary[],
389
+ config: Tier0ScanConfig = DEFAULT_TIER0_CONFIG
390
+ ): Promise<Tier0Report> {
391
+ const base = await runTier0ScanPlatformAware(traces, config);
392
+ if (libraryMatches.length === 0) return base;
393
+ // LIBRARY FIRST: promoted patterns are surfaced ahead of generic heuristics.
394
+ // PRD-MP-07: hasPrimarySignal is re-evaluated to include library hits.
395
+ const hasPrimarySignalWithLib = base.hasPrimarySignal || libraryMatches.length > 0;
396
+ return {
397
+ ...base,
398
+ libraryMatches,
399
+ hasPrimarySignal: hasPrimarySignalWithLib,
400
+ recommendedSlicing: hasPrimarySignalWithLib ? "dynamic-cluster" : base.recommendedSlicing,
401
+ };
402
+ }
403
+
404
+ // CLI entrypoint
405
+ if (import.meta.main) {
406
+ const inputPath = process.argv[2];
407
+ if (!inputPath) {
408
+ process.stderr.write("Usage: bun scripts/tier0-scan.ts <traces-metadata.json>\n");
409
+ process.exit(1);
410
+ }
411
+
412
+ try {
413
+ const raw = readFileSync(inputPath, "utf8");
414
+ const traces: TraceMetadata[] = JSON.parse(raw);
415
+ // R-SELF-11-a: use platform-aware entry for CLI execution
416
+ const report = await runTier0ScanPlatformAware(traces);
417
+ process.stdout.write(JSON.stringify(report, null, 2) + "\n");
418
+ process.exit(0);
419
+ } catch (err) {
420
+ process.stderr.write(`Error: ${err}\n`);
421
+ process.exit(1);
422
+ }
423
+ }