@ornexus/neocortex 4.60.67 → 4.60.68

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 (230) hide show
  1. package/dist/release-source.json +1 -1
  2. package/dist/sbom.cdx.json +1194 -1194
  3. package/install.sh +1 -1
  4. package/package.json +2 -2
  5. package/packages/client/dist/adapters/adapter-registry.js +108 -1
  6. package/packages/client/dist/adapters/antigravity-adapter.js +77 -2
  7. package/packages/client/dist/adapters/claude-code-adapter.js +79 -3
  8. package/packages/client/dist/adapters/codex-adapter.js +80 -2
  9. package/packages/client/dist/adapters/cursor-adapter.js +115 -4
  10. package/packages/client/dist/adapters/gemini-adapter.js +71 -2
  11. package/packages/client/dist/adapters/grok-adapter.js +42 -2
  12. package/packages/client/dist/adapters/index.js +22 -1
  13. package/packages/client/dist/adapters/platform-detector.js +212 -1
  14. package/packages/client/dist/adapters/target-adapter.js +12 -0
  15. package/packages/client/dist/adapters/vscode-adapter.js +72 -2
  16. package/packages/client/dist/agent/refresh-stubs.js +417 -2
  17. package/packages/client/dist/agent/update-agent-yaml.js +102 -1
  18. package/packages/client/dist/agent/update-description.js +251 -1
  19. package/packages/client/dist/cache/crypto-utils.js +78 -1
  20. package/packages/client/dist/cache/encrypted-cache.js +108 -1
  21. package/packages/client/dist/cache/in-memory-asset-cache.js +73 -1
  22. package/packages/client/dist/cache/index.js +13 -1
  23. package/packages/client/dist/cache/protected-pi-boundary.js +44 -1
  24. package/packages/client/dist/checkpoint/checkpoint-client-reader.js +127 -2
  25. package/packages/client/dist/checkpoint/index.js +11 -1
  26. package/packages/client/dist/checkpoint/shared-checkpoint-types.js +32 -1
  27. package/packages/client/dist/cli.js +290 -3
  28. package/packages/client/dist/commands/activate.js +394 -8
  29. package/packages/client/dist/commands/architecture-answers.js +274 -7
  30. package/packages/client/dist/commands/architecture-memory-terminal.js +253 -4
  31. package/packages/client/dist/commands/architecture-non-ui-continuation.js +100 -1
  32. package/packages/client/dist/commands/architecture-root-binding.js +51 -1
  33. package/packages/client/dist/commands/cache-status.js +112 -2
  34. package/packages/client/dist/commands/config.js +88 -1
  35. package/packages/client/dist/commands/doctor.js +635 -2
  36. package/packages/client/dist/commands/invoke.js +7140 -142
  37. package/packages/client/dist/commands/legacy-epic-terminal.js +71 -1
  38. package/packages/client/dist/commands/legacy-story-branch.js +96 -1
  39. package/packages/client/dist/commands/legacy-story-pr.js +276 -1
  40. package/packages/client/dist/commands/mutation-qa-checkpoint.js +285 -5
  41. package/packages/client/dist/commands/mutation-qa-gate.js +54 -1
  42. package/packages/client/dist/commands/mutation-qa-git.js +41 -1
  43. package/packages/client/dist/commands/mutation-qa-policy.js +102 -1
  44. package/packages/client/dist/commands/mutation-qa-run.js +219 -3
  45. package/packages/client/dist/commands/mutation-qa-verdict.js +149 -1
  46. package/packages/client/dist/commands/mutation-qa.js +220 -1
  47. package/packages/client/dist/commands/native-agent.js +136 -2
  48. package/packages/client/dist/commands/planning-diagnosis.js +43 -1
  49. package/packages/client/dist/commands/planning-generation.js +53 -1
  50. package/packages/client/dist/commands/planning-memory.js +40 -1
  51. package/packages/client/dist/commands/planning-research.js +42 -1
  52. package/packages/client/dist/commands/private-session.js +75 -1
  53. package/packages/client/dist/commands/property-qa.js +139 -1
  54. package/packages/client/dist/commands/qa-control.js +16 -1
  55. package/packages/client/dist/commands/qa-scan-browser-launch.js +55 -1
  56. package/packages/client/dist/commands/qa-scan-browser-route.js +28 -1
  57. package/packages/client/dist/commands/qa-scan-capture.js +663 -5
  58. package/packages/client/dist/commands/qa-scan-discovery.js +376 -3
  59. package/packages/client/dist/commands/qa-scan-review.js +826 -5
  60. package/packages/client/dist/commands/qa-synthetic-backend-capture.js +266 -1
  61. package/packages/client/dist/commands/qa-synthetic-backend-review.js +297 -1
  62. package/packages/client/dist/commands/qa-synthetic-backend.js +340 -2
  63. package/packages/client/dist/commands/qa-synthetic-broker-port.js +85 -1
  64. package/packages/client/dist/commands/qa-synthetic-browser.js +39 -1
  65. package/packages/client/dist/commands/refactor-characterization.js +671 -21
  66. package/packages/client/dist/commands/refactor-commit.js +399 -13
  67. package/packages/client/dist/commands/refactor-control.js +142 -3
  68. package/packages/client/dist/commands/refactor-cpp-assertions.js +93 -3
  69. package/packages/client/dist/commands/refactor-review.js +283 -5
  70. package/packages/client/dist/commands/refactor-root.js +588 -7
  71. package/packages/client/dist/commands/refresh-memory.js +156 -3
  72. package/packages/client/dist/commands/shared-architecture-non-ui.js +24 -1
  73. package/packages/client/dist/commands/story-checkpoint.js +171 -1
  74. package/packages/client/dist/config/profile-directory.js +13 -1
  75. package/packages/client/dist/config/resolver-selection.js +278 -1
  76. package/packages/client/dist/config/secure-config.js +281 -12
  77. package/packages/client/dist/config.js +223 -2
  78. package/packages/client/dist/constants.js +25 -1
  79. package/packages/client/dist/context/context-collector.js +222 -2
  80. package/packages/client/dist/context/context-sanitizer.js +145 -1
  81. package/packages/client/dist/continuity/autonomous-governance.js +285 -1
  82. package/packages/client/dist/continuity/continuity-client-state-store.js +1587 -1
  83. package/packages/client/dist/continuity/invoke-hooks.js +129 -1
  84. package/packages/client/dist/continuity/migrations/001-initial-schema.js +12 -2
  85. package/packages/client/dist/continuity/migrations/002-processing-output-summary-indexes.js +12 -2
  86. package/packages/client/dist/continuity/migrations/003-headless-execution-attempts.js +12 -2
  87. package/packages/client/dist/continuity/migrations/004-outbox-delivery-state.js +12 -2
  88. package/packages/client/dist/continuity/migrations/005-bounded-headless-queue.js +12 -2
  89. package/packages/client/dist/continuity/migrations/006-native-agent-dispatches.js +10 -2
  90. package/packages/client/dist/continuity/native-agent-store.js +69 -1
  91. package/packages/client/dist/continuity/native-agent-types.js +90 -1
  92. package/packages/client/dist/continuity/outbox.js +117 -1
  93. package/packages/client/dist/continuity/runner-bootstrap-policy.js +172 -1
  94. package/packages/client/dist/continuity/sqlite-store.js +2536 -81
  95. package/packages/client/dist/effects/invoke-effect-gateways.js +62 -1
  96. package/packages/client/dist/errors/error-messages.js +228 -2
  97. package/packages/client/dist/errors/frontmatter-diagnostics.js +125 -1
  98. package/packages/client/dist/evidence/collector.js +347 -1
  99. package/packages/client/dist/evidence/index.js +1 -1
  100. package/packages/client/dist/evidence/types.js +2 -0
  101. package/packages/client/dist/fs/atomic-state-replace.js +152 -1
  102. package/packages/client/dist/generated/command-registry.generated.js +4076 -1
  103. package/packages/client/dist/generated/public-projections.generated.js +149 -1
  104. package/packages/client/dist/git/direct-yolo-c01-retry.js +138 -4
  105. package/packages/client/dist/git/direct-yolo-checkpoint.js +1234 -4
  106. package/packages/client/dist/git/git-lifecycle-step-ids.js +14 -1
  107. package/packages/client/dist/git/git-lifecycle-store.js +1938 -9
  108. package/packages/client/dist/git/legacy-story-branch-checkpoint.js +259 -9
  109. package/packages/client/dist/git/legacy-story-branch-setup.js +348 -4
  110. package/packages/client/dist/git/legacy-story-pr.js +3538 -70
  111. package/packages/client/dist/git/secure-filesystem-boundary.js +182 -5
  112. package/packages/client/dist/graph-retrieval/pre-command-hook.js +284 -1
  113. package/packages/client/dist/graph-retrieval/shared-graph-retrieval-contract.js +237 -1
  114. package/packages/client/dist/i18n/first-run.js +60 -2
  115. package/packages/client/dist/index.js +47 -1
  116. package/packages/client/dist/invocation/invoke-input.js +24 -1
  117. package/packages/client/dist/license/index.js +5 -1
  118. package/packages/client/dist/license/license-client.js +304 -1
  119. package/packages/client/dist/machine/fingerprint.js +163 -2
  120. package/packages/client/dist/machine/index.js +5 -1
  121. package/packages/client/dist/memory/project-memory-path-scope.js +62 -1
  122. package/packages/client/dist/memory/project-memory-writer.js +1007 -40
  123. package/packages/client/dist/memory/shared-project-memory-types.js +253 -2
  124. package/packages/client/dist/migrations/project-identity-capability.js +50 -1
  125. package/packages/client/dist/migrations/project-identity.js +493 -7
  126. package/packages/client/dist/migrations/state-json.js +344 -4
  127. package/packages/client/dist/policy/architecture-policy.js +184 -2
  128. package/packages/client/dist/policy/index.js +7 -1
  129. package/packages/client/dist/policy/shared-policy-types.js +38 -0
  130. package/packages/client/dist/policy/subagent-approval-policy.js +55 -1
  131. package/packages/client/dist/private-execution/clean-baseline.js +279 -2
  132. package/packages/client/dist/private-execution/codex-executor.js +574 -4
  133. package/packages/client/dist/private-execution/codex-host-runtime.js +137 -1
  134. package/packages/client/dist/private-execution/codex-lifecycle-guard.js +97 -1
  135. package/packages/client/dist/private-execution/codex-scoped-permissions.js +128 -1
  136. package/packages/client/dist/private-execution/delivery.js +410 -13
  137. package/packages/client/dist/private-execution/diagnosis-root-review.js +294 -2
  138. package/packages/client/dist/private-execution/frozen-handoff.js +19 -6
  139. package/packages/client/dist/private-execution/implementation-validation.js +106 -2
  140. package/packages/client/dist/private-execution/isolated-admission.js +1432 -23
  141. package/packages/client/dist/private-execution/isolated-session.js +725 -5
  142. package/packages/client/dist/private-execution/isolated-workspace.js +122 -1
  143. package/packages/client/dist/private-execution/pact-consumer-runtime.js +409 -3
  144. package/packages/client/dist/private-execution/pact-test-source.js +258 -1
  145. package/packages/client/dist/private-execution/pact-toolchain.js +290 -3
  146. package/packages/client/dist/private-execution/pact-write-set.js +172 -1
  147. package/packages/client/dist/private-execution/planning-diagnosis-checkpoint.js +406 -5
  148. package/packages/client/dist/private-execution/planning-generation-checkpoint.js +462 -5
  149. package/packages/client/dist/private-execution/planning-memory-checkpoint.js +139 -3
  150. package/packages/client/dist/private-execution/planning-research-checkpoint.js +325 -4
  151. package/packages/client/dist/private-execution/private-report-store.js +42 -1
  152. package/packages/client/dist/private-execution/property-test-candidate.js +103 -1
  153. package/packages/client/dist/private-execution/property-test-choices.js +147 -3
  154. package/packages/client/dist/private-execution/property-test-plan.js +271 -7
  155. package/packages/client/dist/private-execution/property-test-review.js +258 -4
  156. package/packages/client/dist/private-execution/property-test-runtime.js +372 -9
  157. package/packages/client/dist/private-execution/property-test-source.js +139 -1
  158. package/packages/client/dist/private-execution/root-checkpoint.js +80 -1
  159. package/packages/client/dist/private-execution/root-memory-git-evidence.js +135 -3
  160. package/packages/client/dist/private-execution/root-memory-recovery.js +93 -1
  161. package/packages/client/dist/private-execution/root-memory-request.js +29 -1
  162. package/packages/client/dist/private-execution/root-memory-scope.js +178 -1
  163. package/packages/client/dist/private-execution/root-memory-writer.js +102 -1
  164. package/packages/client/dist/private-execution/session-lease.js +63 -1
  165. package/packages/client/dist/private-execution/shared-private-admission-types.js +50 -1
  166. package/packages/client/dist/private-execution/shared-project-validation.js +66 -1
  167. package/packages/client/dist/private-execution/shared-root-memory-types.js +61 -1
  168. package/packages/client/dist/private-execution/ux-source-validation.js +372 -1
  169. package/packages/client/dist/private-execution/ux-write-set.js +191 -2
  170. package/packages/client/dist/resilience/circuit-breaker.js +170 -1
  171. package/packages/client/dist/resilience/degradation-manager.js +164 -1
  172. package/packages/client/dist/resilience/freshness-indicator.js +100 -1
  173. package/packages/client/dist/resilience/index.js +8 -1
  174. package/packages/client/dist/resilience/recovery-detector.js +74 -1
  175. package/packages/client/dist/resolvers/asset-resolver.js +13 -0
  176. package/packages/client/dist/resolvers/local-resolver.js +255 -8
  177. package/packages/client/dist/resolvers/remote-resolver.js +233 -1
  178. package/packages/client/dist/runner/binary.js +404 -1
  179. package/packages/client/dist/runner/cli.js +1571 -17
  180. package/packages/client/dist/runner/headless/adapters.js +49 -1
  181. package/packages/client/dist/runner/headless/claude-code-adapter.js +79 -1
  182. package/packages/client/dist/runner/headless/continuous-story-workspace.js +1628 -11
  183. package/packages/client/dist/runner/headless/epic-git-reconciliation-inventory.js +69 -1
  184. package/packages/client/dist/runner/headless/epic-merge-candidate-qa.js +110 -2
  185. package/packages/client/dist/runner/headless/epic-terminal-git-cli-adapter.js +1236 -8
  186. package/packages/client/dist/runner/headless/epic-terminal-git-runner.js +318 -2
  187. package/packages/client/dist/runner/headless/fake-adapter.js +62 -1
  188. package/packages/client/dist/runner/headless/managed-profile.js +132 -1
  189. package/packages/client/dist/runner/headless/opencode-adapter.js +145 -2
  190. package/packages/client/dist/runner/headless/prepared-story-bundle.js +43 -1
  191. package/packages/client/dist/runner/headless/resolver.js +231 -1
  192. package/packages/client/dist/runner/headless/run-yolo.js +885 -1
  193. package/packages/client/dist/runner/headless/run-yoloop.js +2574 -2
  194. package/packages/client/dist/runner/headless/types.js +574 -2
  195. package/packages/client/dist/runner/local-console.js +396 -13
  196. package/packages/client/dist/runner/portal-sync-worker.js +1487 -1
  197. package/packages/client/dist/runner/project-identity.js +106 -1
  198. package/packages/client/dist/runner/scheduler.js +995 -7
  199. package/packages/client/dist/runner-cli.js +18 -2
  200. package/packages/client/dist/state/invocation-shape.js +13 -1
  201. package/packages/client/dist/state/project-state-snapshot.js +1677 -1
  202. package/packages/client/dist/state/state-json-repair.js +785 -3
  203. package/packages/client/dist/state/structural-dag-projection.js +118 -1
  204. package/packages/client/dist/telemetry/index.js +5 -1
  205. package/packages/client/dist/telemetry/offline-queue.js +131 -1
  206. package/packages/client/dist/tier/index.js +5 -1
  207. package/packages/client/dist/tier/tier-aware-client.js +405 -1
  208. package/packages/client/dist/types/index.js +38 -1
  209. package/packages/client/dist/version.js +27 -1
  210. package/packages/client/dist/yolo/change-evidence-collector.js +126 -1
  211. package/packages/client/dist/yolo/invoke-envelope-capability.js +62 -1
  212. package/packages/client/dist/yolo/spec-envelope-collector.js +185 -5
  213. package/packages/client/dist/yoloop/discovery-hook.js +300 -2
  214. package/packages/client/dist/yoloop/index.js +8 -1
  215. package/packages/client/dist/yoloop/invoke-hooks.js +669 -12
  216. package/packages/client/dist/yoloop/shared-discover-epics.js +1007 -1
  217. package/packages/client/dist/yoloop/shared-yoloop-types.js +33 -1
  218. package/packages/client/dist/yoloop/target-normalization.js +180 -1
  219. package/packages/client/dist/yoloop/yoloop-client-state-store.js +1723 -1
  220. package/targets-stubs/antigravity/gemini.md +1 -1
  221. package/targets-stubs/antigravity/skill/SKILL.md +1 -1
  222. package/targets-stubs/claude-code/neocortex-root.agent.yaml +1 -1
  223. package/targets-stubs/claude-code/neocortex-root.md +2 -2
  224. package/targets-stubs/claude-code/neocortex.agent.yaml +1 -1
  225. package/targets-stubs/claude-code/neocortex.md +2 -2
  226. package/targets-stubs/codex/AGENTS.md +1 -1
  227. package/targets-stubs/cursor/agent.md +2 -2
  228. package/targets-stubs/gemini-cli/agent.md +2 -2
  229. package/targets-stubs/opencode/neocortex-root.md +1 -1
  230. package/targets-stubs/vscode/neocortex.agent.md +2 -2
@@ -1,5 +1,285 @@
1
- import{createHash as b,randomUUID as J}from"node:crypto";import{closeSync as S,fsyncSync as w,lstatSync as h,mkdirSync as D,openSync as k,readFileSync as x,realpathSync as A,linkSync as I,unlinkSync as j,writeFileSync as P}from"node:fs";import{isAbsolute as F,join as y,resolve as q}from"node:path";import{mutationQaGit as g}from"./mutation-qa-git.js";import{planMutationQa as v}from"./mutation-qa.js";import{runMutationQa as H}from"./mutation-qa-run.js";function E(n,o){const e=q(n),r=g(e,["rev-parse","--show-toplevel"]).toString("utf8").trim(),t=g(e,["rev-parse","--git-common-dir"]).toString("utf8").trim(),a=F(t)?q(t):q(e,t);if(A(e)!==e||r!==e||A(a)!==a||h(a).isSymbolicLink()||h(a).uid!==process.getuid?.())throw new Error("mutation-qa-checkpoint-store-invalid");const i=y(a,"neocortex-mutation-qa");let c=!1;if(o&&!h(i,{throwIfNoEntry:!1}))try{D(i,{mode:448}),c=!0}catch(s){if(s.code!=="EEXIST")throw s}const d=h(i,{throwIfNoEntry:!1});if(d&&(!d.isDirectory()||d.isSymbolicLink()||d.uid!==process.getuid?.()||(d.mode&63)!==0))throw new Error("mutation-qa-checkpoint-store-invalid");if(c){const s=k(a,"r");try{w(s)}finally{S(s)}}return{root:e,directory:i}}function O(n){const o=h(n);if(!o.isFile()||o.isSymbolicLink()||o.uid!==process.getuid?.()||(o.mode&63)!==0||o.size<1||o.size>4096)throw new Error("mutation-qa-checkpoint-record-invalid");const e=x(n,"utf8");let r;try{r=JSON.parse(e)}catch{throw new Error("mutation-qa-checkpoint-record-invalid")}if(!r||typeof r!="object"||Array.isArray(r))throw new Error("mutation-qa-checkpoint-record-invalid");const t=r,{checksumSha256:a,...i}=t,c=b("sha256").update(`mutation-qa-checkpoint-v1\0${JSON.stringify(i)}`).digest("hex");if(Object.keys(t).sort().join(",")!==["schemaVersion","kind","planSha256","headSha","baseSha","reportSha256","verdict","mutationScore","checkpointAccepted","qaPassed","localOnly","checksumSha256"].sort().join(",")||t.schemaVersion!==1||t.kind!=="mutation-qa-checkpoint"||typeof t.planSha256!="string"||!/^[a-f0-9]{64}$/.test(t.planSha256)||typeof t.headSha!="string"||!/^[a-f0-9]{40,64}$/.test(t.headSha)||typeof t.baseSha!="string"||!/^[a-f0-9]{40,64}$/.test(t.baseSha)||typeof t.reportSha256!="string"||!/^[a-f0-9]{64}$/.test(t.reportSha256)||!["passed","warned","failed"].includes(String(t.verdict))||typeof t.mutationScore!="number"||!Number.isFinite(t.mutationScore)||t.mutationScore<0||t.mutationScore>100||t.checkpointAccepted!==!0||t.qaPassed!==(t.verdict==="passed")||t.localOnly!==!0||a!==c||e!==`${JSON.stringify(t)}
2
- `)throw new Error("mutation-qa-checkpoint-record-invalid");return t}function Q(n){const o=h(n);if(!o.isFile()||o.isSymbolicLink()||o.uid!==process.getuid?.()||(o.mode&63)!==0||o.size<1||o.size>4096)throw new Error("mutation-qa-debt-record-invalid");const e=x(n,"utf8");let r;try{r=JSON.parse(e)}catch{throw new Error("mutation-qa-debt-record-invalid")}if(!r||typeof r!="object"||Array.isArray(r))throw new Error("mutation-qa-debt-record-invalid");const t=r,{checksumSha256:a,...i}=t,c=b("sha256").update(`mutation-qa-debt-v1\0${JSON.stringify(i)}`).digest("hex");if(Object.keys(t).sort().join(",")!==["schemaVersion","kind","planSha256","headSha","status","reasonCode","runOutcome","owner","severity","publicSafe","localOnly","checksumSha256"].sort().join(",")||t.schemaVersion!==1||t.kind!=="mutation-qa-follow-up-debt"||typeof t.planSha256!="string"||!/^[a-f0-9]{64}$/.test(t.planSha256)||typeof t.headSha!="string"||!/^[a-f0-9]{40,64}$/.test(t.headSha)||!["warned","unobserved"].includes(String(t.status))||t.reasonCode!==(t.status==="warned"?"mutation-qa-warned":"mutation-qa-observation-missing")||!["not-run","skipped-no-files","skipped-stryker-missing","skipped-dependencies-unavailable","skipped-host-isolation-unavailable","skipped-stryker-error","verified"].includes(String(t.runOutcome))||t.owner!=="root-qa"||t.severity!==(t.status==="warned"?"P2":"P3")||t.publicSafe!==!0||t.localOnly!==!0||a!==c||e!==`${JSON.stringify(t)}
3
- `)throw new Error("mutation-qa-debt-record-invalid");return t}function B(n,o,e,r,t,a){const i=v(n,o);if(i.planSha256!==e)throw new Error("mutation-qa-debt-plan-drift");const c=V(n,o,e);if(r==="warned"&&(t!=="verified"||c?.verdict!=="warned"))throw new Error("mutation-qa-debt-run-invalid");if(r==="unobserved"&&(i.outcome!=="ready"||c||!["skipped-stryker-missing","skipped-dependencies-unavailable","skipped-stryker-error"].includes(t)))throw new Error("mutation-qa-debt-run-invalid");const{root:d,directory:s}=E(a??n,!0);if(a&&g(d,["rev-parse","--verify","HEAD"]).toString("utf8").trim()!==i.baseSha)throw new Error("mutation-qa-debt-root-drift");const l={schemaVersion:1,kind:"mutation-qa-follow-up-debt",planSha256:e,headSha:i.headSha,status:r,reasonCode:r==="warned"?"mutation-qa-warned":"mutation-qa-observation-missing",runOutcome:t,owner:"root-qa",severity:r==="warned"?"P2":"P3",publicSafe:!0,localOnly:!0},f=Object.freeze({...l,checksumSha256:b("sha256").update(`mutation-qa-debt-v1\0${JSON.stringify(l)}`).digest("hex")}),p=y(s,`debt-${e}.json`);if(h(p,{throwIfNoEntry:!1})){const m=Q(p);if(JSON.stringify(m)!==JSON.stringify(f))throw new Error("mutation-qa-debt-conflict");return m}const u=y(s,`debt-${J()}.tmp`);try{const m=k(u,"wx",384);try{P(m,`${JSON.stringify(f)}
4
- `),w(m)}finally{S(m)}if(v(n,o).planSha256!==e||a&&g(d,["rev-parse","--verify","HEAD"]).toString("utf8").trim()!==i.baseSha)throw new Error("mutation-qa-debt-plan-drift");try{I(u,p)}catch($){if($.code!=="EEXIST")throw $;const z=Q(p);if(JSON.stringify(z)!==JSON.stringify(f))throw new Error("mutation-qa-debt-conflict")}const N=k(s,"r");try{w(N)}finally{S(N)}}finally{h(u,{throwIfNoEntry:!1})&&j(u)}return f}function M(n,o,e){if(e.outcome!=="verified"||!e.verdict||e.verdict.planSha256!==e.planSha256||e.verdict.checkpointAccepted!==!1)throw new Error("mutation-qa-checkpoint-verdict-unavailable");const r=v(n,o);if(r.outcome!=="ready"||r.planSha256!==e.planSha256||r.headSha!==e.headSha)throw new Error("mutation-qa-checkpoint-plan-drift");const{root:t,directory:a}=E(n,!0),i={schemaVersion:1,kind:"mutation-qa-checkpoint",planSha256:r.planSha256,headSha:r.headSha,baseSha:r.baseSha,reportSha256:e.verdict.reportSha256,verdict:e.verdict.outcome,mutationScore:e.verdict.mutationScore,checkpointAccepted:!0,qaPassed:e.verdict.outcome==="passed",localOnly:!0},c=Object.freeze({...i,checksumSha256:b("sha256").update(`mutation-qa-checkpoint-v1\0${JSON.stringify(i)}`).digest("hex")}),d=y(a,`${r.planSha256}.json`);if(h(d,{throwIfNoEntry:!1})){const l=O(d);if(JSON.stringify(l)!==JSON.stringify(c))throw new Error("mutation-qa-checkpoint-conflict");return l}const s=y(a,`checkpoint-${J()}.tmp`);try{const l=k(s,"wx",384);try{P(l,`${JSON.stringify(c)}
5
- `),w(l)}finally{S(l)}if(v(t,o).planSha256!==r.planSha256)throw new Error("mutation-qa-checkpoint-plan-drift");try{I(s,d)}catch(p){if(p.code!=="EEXIST")throw p;const u=O(d);if(JSON.stringify(u)!==JSON.stringify(c))throw new Error("mutation-qa-checkpoint-conflict")}const f=k(a,"r");try{w(f)}finally{S(f)}}finally{h(s,{throwIfNoEntry:!1})&&j(s)}return c}function K(n,o,e){const r=H(n,o,e);return r.outcome==="verified"?{result:r,checkpoint:M(n,o,r)}:{result:r}}function V(n,o,e){if(!/^[a-f0-9]{64}$/.test(e))throw new Error("mutation-qa-plan-digest-invalid");const r=v(n,o);if(r.planSha256!==e)throw new Error("mutation-qa-checkpoint-plan-drift");const{directory:t}=E(n,!1),a=y(t,`${e}.json`);if(!h(a,{throwIfNoEntry:!1}))return;const i=O(a);if(i.planSha256!==e||i.headSha!==r.headSha||i.baseSha!==r.baseSha)throw new Error("mutation-qa-checkpoint-plan-drift");return i}export{V as readMutationQaCheckpoint,B as recordMutationQaFollowUpDebt,K as runAndRecordMutationQa};
1
+ /** Root-owned, private observation of one physically executed mutation QA plan. */
2
+ import { createHash, randomUUID } from 'node:crypto';
3
+ import { closeSync, fsyncSync, lstatSync, mkdirSync, openSync, readFileSync, realpathSync, linkSync, unlinkSync, writeFileSync } from 'node:fs';
4
+ import { isAbsolute, join, resolve } from 'node:path';
5
+ import { mutationQaGit } from './mutation-qa-git.js';
6
+ import { planMutationQa } from './mutation-qa.js';
7
+ import { runMutationQa } from './mutation-qa-run.js';
8
+ function context(projectRoot, create) {
9
+ const root = resolve(projectRoot);
10
+ const top = mutationQaGit(root, ['rev-parse', '--show-toplevel']).toString('utf8').trim();
11
+ const raw = mutationQaGit(root, ['rev-parse', '--git-common-dir']).toString('utf8').trim();
12
+ const common = isAbsolute(raw) ? resolve(raw) : resolve(root, raw);
13
+ if (realpathSync(root) !== root || top !== root || realpathSync(common) !== common
14
+ || lstatSync(common).isSymbolicLink() || lstatSync(common).uid !== process.getuid?.()) {
15
+ throw new Error('mutation-qa-checkpoint-store-invalid');
16
+ }
17
+ const directory = join(common, 'neocortex-mutation-qa');
18
+ let created = false;
19
+ if (create && !lstatSync(directory, { throwIfNoEntry: false })) {
20
+ try {
21
+ mkdirSync(directory, { mode: 0o700 });
22
+ created = true;
23
+ }
24
+ catch (error) {
25
+ if (error.code !== 'EEXIST')
26
+ throw error;
27
+ }
28
+ }
29
+ const stat = lstatSync(directory, { throwIfNoEntry: false });
30
+ if (stat) {
31
+ if (!stat.isDirectory() || stat.isSymbolicLink() || stat.uid !== process.getuid?.()
32
+ || (stat.mode & 0o077) !== 0)
33
+ throw new Error('mutation-qa-checkpoint-store-invalid');
34
+ }
35
+ if (created) {
36
+ const commonHandle = openSync(common, 'r');
37
+ try {
38
+ fsyncSync(commonHandle);
39
+ }
40
+ finally {
41
+ closeSync(commonHandle);
42
+ }
43
+ }
44
+ return { root, directory };
45
+ }
46
+ function checkedRecord(path) {
47
+ const stat = lstatSync(path);
48
+ if (!stat.isFile() || stat.isSymbolicLink() || stat.uid !== process.getuid?.()
49
+ || (stat.mode & 0o077) !== 0 || stat.size < 1 || stat.size > 4096) {
50
+ throw new Error('mutation-qa-checkpoint-record-invalid');
51
+ }
52
+ const raw = readFileSync(path, 'utf8');
53
+ let parsed;
54
+ try {
55
+ parsed = JSON.parse(raw);
56
+ }
57
+ catch {
58
+ throw new Error('mutation-qa-checkpoint-record-invalid');
59
+ }
60
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
61
+ throw new Error('mutation-qa-checkpoint-record-invalid');
62
+ }
63
+ const record = parsed;
64
+ const { checksumSha256, ...payload } = record;
65
+ const expected = createHash('sha256').update(`mutation-qa-checkpoint-v1\0${JSON.stringify(payload)}`)
66
+ .digest('hex');
67
+ if (Object.keys(record).sort().join(',') !== [
68
+ 'schemaVersion', 'kind', 'planSha256', 'headSha', 'baseSha', 'reportSha256',
69
+ 'verdict', 'mutationScore', 'checkpointAccepted', 'qaPassed', 'localOnly', 'checksumSha256',
70
+ ].sort().join(',') || record.schemaVersion !== 1 || record.kind !== 'mutation-qa-checkpoint'
71
+ || typeof record.planSha256 !== 'string' || !/^[a-f0-9]{64}$/.test(record.planSha256)
72
+ || typeof record.headSha !== 'string' || !/^[a-f0-9]{40,64}$/.test(record.headSha)
73
+ || typeof record.baseSha !== 'string' || !/^[a-f0-9]{40,64}$/.test(record.baseSha)
74
+ || typeof record.reportSha256 !== 'string' || !/^[a-f0-9]{64}$/.test(record.reportSha256)
75
+ || !['passed', 'warned', 'failed'].includes(String(record.verdict))
76
+ || typeof record.mutationScore !== 'number' || !Number.isFinite(record.mutationScore)
77
+ || record.mutationScore < 0 || record.mutationScore > 100
78
+ || record.checkpointAccepted !== true || record.qaPassed !== (record.verdict === 'passed')
79
+ || record.localOnly !== true || checksumSha256 !== expected
80
+ || raw !== `${JSON.stringify(record)}\n`) {
81
+ throw new Error('mutation-qa-checkpoint-record-invalid');
82
+ }
83
+ return record;
84
+ }
85
+ function checkedDebt(path) {
86
+ const stat = lstatSync(path);
87
+ if (!stat.isFile() || stat.isSymbolicLink() || stat.uid !== process.getuid?.()
88
+ || (stat.mode & 0o077) !== 0 || stat.size < 1 || stat.size > 4096) {
89
+ throw new Error('mutation-qa-debt-record-invalid');
90
+ }
91
+ const raw = readFileSync(path, 'utf8');
92
+ let parsed;
93
+ try {
94
+ parsed = JSON.parse(raw);
95
+ }
96
+ catch {
97
+ throw new Error('mutation-qa-debt-record-invalid');
98
+ }
99
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
100
+ throw new Error('mutation-qa-debt-record-invalid');
101
+ }
102
+ const record = parsed;
103
+ const { checksumSha256, ...payload } = record;
104
+ const expected = createHash('sha256').update(`mutation-qa-debt-v1\0${JSON.stringify(payload)}`).digest('hex');
105
+ if (Object.keys(record).sort().join(',') !== [
106
+ 'schemaVersion', 'kind', 'planSha256', 'headSha', 'status', 'reasonCode',
107
+ 'runOutcome', 'owner', 'severity', 'publicSafe', 'localOnly', 'checksumSha256',
108
+ ].sort().join(',') || record.schemaVersion !== 1 || record.kind !== 'mutation-qa-follow-up-debt'
109
+ || typeof record.planSha256 !== 'string' || !/^[a-f0-9]{64}$/.test(record.planSha256)
110
+ || typeof record.headSha !== 'string' || !/^[a-f0-9]{40,64}$/.test(record.headSha)
111
+ || !['warned', 'unobserved'].includes(String(record.status))
112
+ || record.reasonCode !== (record.status === 'warned'
113
+ ? 'mutation-qa-warned' : 'mutation-qa-observation-missing')
114
+ || !['not-run', 'skipped-no-files', 'skipped-stryker-missing',
115
+ 'skipped-dependencies-unavailable', 'skipped-host-isolation-unavailable',
116
+ 'skipped-stryker-error', 'verified'].includes(String(record.runOutcome))
117
+ || record.owner !== 'root-qa'
118
+ || record.severity !== (record.status === 'warned' ? 'P2' : 'P3')
119
+ || record.publicSafe !== true || record.localOnly !== true
120
+ || checksumSha256 !== expected || raw !== `${JSON.stringify(record)}\n`) {
121
+ throw new Error('mutation-qa-debt-record-invalid');
122
+ }
123
+ return record;
124
+ }
125
+ /** Persist optional-QA debt separately from the verdict before allowing root continuation. */
126
+ export function recordMutationQaFollowUpDebt(projectRoot, baseRef, planSha256, status, runOutcome, durableRoot) {
127
+ const plan = planMutationQa(projectRoot, baseRef);
128
+ if (plan.planSha256 !== planSha256)
129
+ throw new Error('mutation-qa-debt-plan-drift');
130
+ const checkpoint = readMutationQaCheckpoint(projectRoot, baseRef, planSha256);
131
+ if (status === 'warned' && (runOutcome !== 'verified' || checkpoint?.verdict !== 'warned')) {
132
+ throw new Error('mutation-qa-debt-run-invalid');
133
+ }
134
+ if (status === 'unobserved' && (plan.outcome !== 'ready' || checkpoint
135
+ || !['skipped-stryker-missing', 'skipped-dependencies-unavailable',
136
+ 'skipped-stryker-error'].includes(runOutcome))) {
137
+ throw new Error('mutation-qa-debt-run-invalid');
138
+ }
139
+ const { root, directory } = context(durableRoot ?? projectRoot, true);
140
+ if (durableRoot && mutationQaGit(root, ['rev-parse', '--verify', 'HEAD'])
141
+ .toString('utf8').trim() !== plan.baseSha) {
142
+ throw new Error('mutation-qa-debt-root-drift');
143
+ }
144
+ const payload = { schemaVersion: 1, kind: 'mutation-qa-follow-up-debt',
145
+ planSha256, headSha: plan.headSha, status,
146
+ reasonCode: status === 'warned' ? 'mutation-qa-warned'
147
+ : 'mutation-qa-observation-missing',
148
+ runOutcome, owner: 'root-qa',
149
+ severity: status === 'warned' ? 'P2' : 'P3',
150
+ publicSafe: true, localOnly: true };
151
+ const record = Object.freeze({ ...payload, checksumSha256: createHash('sha256')
152
+ .update(`mutation-qa-debt-v1\0${JSON.stringify(payload)}`).digest('hex') });
153
+ const target = join(directory, `debt-${planSha256}.json`);
154
+ if (lstatSync(target, { throwIfNoEntry: false })) {
155
+ const previous = checkedDebt(target);
156
+ if (JSON.stringify(previous) !== JSON.stringify(record))
157
+ throw new Error('mutation-qa-debt-conflict');
158
+ return previous;
159
+ }
160
+ const temporary = join(directory, `debt-${randomUUID()}.tmp`);
161
+ try {
162
+ const handle = openSync(temporary, 'wx', 0o600);
163
+ try {
164
+ writeFileSync(handle, `${JSON.stringify(record)}\n`);
165
+ fsyncSync(handle);
166
+ }
167
+ finally {
168
+ closeSync(handle);
169
+ }
170
+ if (planMutationQa(projectRoot, baseRef).planSha256 !== planSha256
171
+ || (durableRoot && mutationQaGit(root, ['rev-parse', '--verify', 'HEAD'])
172
+ .toString('utf8').trim() !== plan.baseSha)) {
173
+ throw new Error('mutation-qa-debt-plan-drift');
174
+ }
175
+ try {
176
+ linkSync(temporary, target);
177
+ }
178
+ catch (error) {
179
+ if (error.code !== 'EEXIST')
180
+ throw error;
181
+ const previous = checkedDebt(target);
182
+ if (JSON.stringify(previous) !== JSON.stringify(record))
183
+ throw new Error('mutation-qa-debt-conflict');
184
+ }
185
+ const directoryHandle = openSync(directory, 'r');
186
+ try {
187
+ fsyncSync(directoryHandle);
188
+ }
189
+ finally {
190
+ closeSync(directoryHandle);
191
+ }
192
+ }
193
+ finally {
194
+ if (lstatSync(temporary, { throwIfNoEntry: false }))
195
+ unlinkSync(temporary);
196
+ }
197
+ return record;
198
+ }
199
+ function recordMutationQaCheckpoint(projectRoot, baseRef, run) {
200
+ if (run.outcome !== 'verified' || !run.verdict
201
+ || run.verdict.planSha256 !== run.planSha256 || run.verdict.checkpointAccepted !== false) {
202
+ throw new Error('mutation-qa-checkpoint-verdict-unavailable');
203
+ }
204
+ const plan = planMutationQa(projectRoot, baseRef);
205
+ if (plan.outcome !== 'ready' || plan.planSha256 !== run.planSha256
206
+ || plan.headSha !== run.headSha)
207
+ throw new Error('mutation-qa-checkpoint-plan-drift');
208
+ const { root, directory } = context(projectRoot, true);
209
+ const payload = { schemaVersion: 1, kind: 'mutation-qa-checkpoint',
210
+ planSha256: plan.planSha256, headSha: plan.headSha, baseSha: plan.baseSha,
211
+ reportSha256: run.verdict.reportSha256, verdict: run.verdict.outcome,
212
+ mutationScore: run.verdict.mutationScore, checkpointAccepted: true,
213
+ qaPassed: run.verdict.outcome === 'passed', localOnly: true };
214
+ const record = Object.freeze({ ...payload, checksumSha256: createHash('sha256')
215
+ .update(`mutation-qa-checkpoint-v1\0${JSON.stringify(payload)}`).digest('hex') });
216
+ const target = join(directory, `${plan.planSha256}.json`);
217
+ if (lstatSync(target, { throwIfNoEntry: false })) {
218
+ const previous = checkedRecord(target);
219
+ if (JSON.stringify(previous) !== JSON.stringify(record)) {
220
+ throw new Error('mutation-qa-checkpoint-conflict');
221
+ }
222
+ return previous;
223
+ }
224
+ const temporary = join(directory, `checkpoint-${randomUUID()}.tmp`);
225
+ try {
226
+ const handle = openSync(temporary, 'wx', 0o600);
227
+ try {
228
+ writeFileSync(handle, `${JSON.stringify(record)}\n`);
229
+ fsyncSync(handle);
230
+ }
231
+ finally {
232
+ closeSync(handle);
233
+ }
234
+ if (planMutationQa(root, baseRef).planSha256 !== plan.planSha256) {
235
+ throw new Error('mutation-qa-checkpoint-plan-drift');
236
+ }
237
+ try {
238
+ linkSync(temporary, target);
239
+ }
240
+ catch (error) {
241
+ if (error.code !== 'EEXIST')
242
+ throw error;
243
+ const previous = checkedRecord(target);
244
+ if (JSON.stringify(previous) !== JSON.stringify(record)) {
245
+ throw new Error('mutation-qa-checkpoint-conflict');
246
+ }
247
+ }
248
+ const directoryHandle = openSync(directory, 'r');
249
+ try {
250
+ fsyncSync(directoryHandle);
251
+ }
252
+ finally {
253
+ closeSync(directoryHandle);
254
+ }
255
+ }
256
+ finally {
257
+ if (lstatSync(temporary, { throwIfNoEntry: false }))
258
+ unlinkSync(temporary);
259
+ }
260
+ return record;
261
+ }
262
+ /** An authorized root run is the only producer; skips never create a checkpoint. */
263
+ export function runAndRecordMutationQa(projectRoot, baseRef, planSha256) {
264
+ const result = runMutationQa(projectRoot, baseRef, planSha256);
265
+ return result.outcome === 'verified'
266
+ ? { result, checkpoint: recordMutationQaCheckpoint(projectRoot, baseRef, result) }
267
+ : { result };
268
+ }
269
+ /** Revalidate the exact physical plan before projecting a private checkpoint. */
270
+ export function readMutationQaCheckpoint(projectRoot, baseRef, planSha256) {
271
+ if (!/^[a-f0-9]{64}$/.test(planSha256))
272
+ throw new Error('mutation-qa-plan-digest-invalid');
273
+ const plan = planMutationQa(projectRoot, baseRef);
274
+ if (plan.planSha256 !== planSha256)
275
+ throw new Error('mutation-qa-checkpoint-plan-drift');
276
+ const { directory } = context(projectRoot, false);
277
+ const target = join(directory, `${planSha256}.json`);
278
+ if (!lstatSync(target, { throwIfNoEntry: false }))
279
+ return undefined;
280
+ const record = checkedRecord(target);
281
+ if (record.planSha256 !== planSha256 || record.headSha !== plan.headSha
282
+ || record.baseSha !== plan.baseSha)
283
+ throw new Error('mutation-qa-checkpoint-plan-drift');
284
+ return record;
285
+ }
@@ -1 +1,54 @@
1
- import{readMutationQaCheckpoint as l,recordMutationQaFollowUpDebt as s,runAndRecordMutationQa as c}from"./mutation-qa-checkpoint.js";import{planMutationQa as u}from"./mutation-qa.js";function d(n,t,o){const i=u(n,t);if(i.planSha256!==o)throw new Error("mutation-qa-gate-plan-drift");const e=l(n,t,o);if(u(n,t).planSha256!==i.planSha256)throw new Error("mutation-qa-gate-plan-drift");const a=e?.verdict??(i.outcome==="skipped-no-files"?"not-applicable":"unobserved"),r=a==="passed"?"mutation-qa-passed":a==="warned"?"mutation-qa-warned":a==="failed"?"mutation-qa-failed":a==="not-applicable"?"mutation-qa-no-eligible-files":"mutation-qa-observation-missing";return Object.freeze({schemaVersion:1,kind:"mutation-qa-gate-decision",planSha256:i.planSha256,headSha:i.headSha,status:a,reasonCode:r,checkpointAccepted:e!==void 0,qaPassed:a==="passed",blocksLocalQa:a==="failed",followUpDebtRequired:a==="warned"||a==="unobserved",safeToContinueLocalQa:a==="passed"||a==="not-applicable",publicSafe:!0,localOnly:!0})}function f(n,t,o){const i=u(n,t);if(i.planSha256!==o)throw new Error("mutation-qa-plan-drift");const e=i.outcome==="ready"?c(n,t,o):void 0;if(e?.result.outcome==="skipped-host-isolation-unavailable")throw new Error("mutation-qa-host-isolation-unavailable");const a=d(n,t,o),r=a.followUpDebtRequired?s(n,t,o,a.status,e?.result.outcome??"not-run"):void 0;if(u(n,t).planSha256!==o)throw new Error("mutation-qa-root-execution-drift");return Object.freeze({schemaVersion:1,kind:"mutation-qa-root-execution",planSha256:o,headSha:i.headSha,runOutcome:e?.result.outcome??"not-run",decision:a,...e?.checkpoint?{checkpoint:e.checkpoint}:{},...r?{followUpDebt:r}:{},continuationAuthorized:a.safeToContinueLocalQa||!!r&&!a.blocksLocalQa,publicSafe:!0,localOnly:!0})}export{d as classifyMutationQaGate,f as executeMutationQaPlan};
1
+ /** Root-only classification of a physically bound mutation observation. */
2
+ import { readMutationQaCheckpoint, recordMutationQaFollowUpDebt, runAndRecordMutationQa } from './mutation-qa-checkpoint.js';
3
+ import { planMutationQa } from './mutation-qa.js';
4
+ /** A skip is never a passing verdict; the caller must persist required debt separately. */
5
+ export function classifyMutationQaGate(projectRoot, baseRef, expectedPlanSha256) {
6
+ const plan = planMutationQa(projectRoot, baseRef);
7
+ if (plan.planSha256 !== expectedPlanSha256)
8
+ throw new Error('mutation-qa-gate-plan-drift');
9
+ const checkpoint = readMutationQaCheckpoint(projectRoot, baseRef, expectedPlanSha256);
10
+ if (planMutationQa(projectRoot, baseRef).planSha256 !== plan.planSha256) {
11
+ throw new Error('mutation-qa-gate-plan-drift');
12
+ }
13
+ const status = checkpoint?.verdict ?? (plan.outcome === 'skipped-no-files'
14
+ ? 'not-applicable' : 'unobserved');
15
+ const reasonCode = status === 'passed' ? 'mutation-qa-passed'
16
+ : status === 'warned' ? 'mutation-qa-warned'
17
+ : status === 'failed' ? 'mutation-qa-failed'
18
+ : status === 'not-applicable' ? 'mutation-qa-no-eligible-files'
19
+ : 'mutation-qa-observation-missing';
20
+ return Object.freeze({ schemaVersion: 1, kind: 'mutation-qa-gate-decision',
21
+ planSha256: plan.planSha256, headSha: plan.headSha, status, reasonCode,
22
+ checkpointAccepted: checkpoint !== undefined, qaPassed: status === 'passed',
23
+ blocksLocalQa: status === 'failed',
24
+ followUpDebtRequired: status === 'warned' || status === 'unobserved',
25
+ safeToContinueLocalQa: status === 'passed' || status === 'not-applicable',
26
+ publicSafe: true, localOnly: true });
27
+ }
28
+ /** One root transaction from a reviewed physical plan to verdict or durable debt. */
29
+ export function executeMutationQaPlan(projectRoot, baseRef, expectedPlanSha256) {
30
+ const plan = planMutationQa(projectRoot, baseRef);
31
+ if (plan.planSha256 !== expectedPlanSha256)
32
+ throw new Error('mutation-qa-plan-drift');
33
+ const run = plan.outcome === 'ready'
34
+ ? runAndRecordMutationQa(projectRoot, baseRef, expectedPlanSha256)
35
+ : undefined;
36
+ if (run?.result.outcome === 'skipped-host-isolation-unavailable') {
37
+ throw new Error('mutation-qa-host-isolation-unavailable');
38
+ }
39
+ const decision = classifyMutationQaGate(projectRoot, baseRef, expectedPlanSha256);
40
+ const followUpDebt = decision.followUpDebtRequired
41
+ ? recordMutationQaFollowUpDebt(projectRoot, baseRef, expectedPlanSha256, decision.status, run?.result.outcome ?? 'not-run')
42
+ : undefined;
43
+ if (planMutationQa(projectRoot, baseRef).planSha256 !== expectedPlanSha256) {
44
+ throw new Error('mutation-qa-root-execution-drift');
45
+ }
46
+ return Object.freeze({ schemaVersion: 1, kind: 'mutation-qa-root-execution',
47
+ planSha256: expectedPlanSha256, headSha: plan.headSha,
48
+ runOutcome: run?.result.outcome ?? 'not-run', decision,
49
+ ...(run?.checkpoint ? { checkpoint: run.checkpoint } : {}),
50
+ ...(followUpDebt ? { followUpDebt } : {}),
51
+ continuationAuthorized: decision.safeToContinueLocalQa
52
+ || (!!followUpDebt && !decision.blocksLocalQa),
53
+ publicSafe: true, localOnly: true });
54
+ }
@@ -1 +1,41 @@
1
- import{execFileSync as r}from"node:child_process";import{existsSync as i,lstatSync as n,realpathSync as s}from"node:fs";import{isAbsolute as c,join as u}from"node:path";function l(){for(const t of(process.env.PATH??"").split(":")){if(!c(t))continue;const e=u(t,"git");if(i(e)){try{const o=s(e);if((o.startsWith("/usr/")||o.startsWith("/home/linuxbrew/.linuxbrew/"))&&n(o).isFile())return o}catch{}break}}throw new Error("mutation-qa-git-untrusted")}function G(t,e){return r(l(),["-c","core.fsmonitor=false","-c","core.hooksPath=/dev/null","-c","protocol.ext.allow=never",...e],{cwd:t,env:{PATH:"/usr/bin:/bin",GIT_CONFIG_NOSYSTEM:"1",GIT_CONFIG_GLOBAL:"/dev/null",GIT_CONFIG_SYSTEM:"/dev/null",GIT_TERMINAL_PROMPT:"0",GIT_OPTIONAL_LOCKS:"0",GIT_LFS_SKIP_SMUDGE:"1"},stdio:["ignore","pipe","pipe"],timeout:15e3,maxBuffer:8*1024*1024})}export{G as mutationQaGit};
1
+ /** Closed host Git boundary for root-owned mutation QA planning and clone setup. */
2
+ import { execFileSync } from 'node:child_process';
3
+ import { existsSync, lstatSync, realpathSync } from 'node:fs';
4
+ import { isAbsolute, join } from 'node:path';
5
+ function trustedGit() {
6
+ for (const directory of (process.env.PATH ?? '').split(':')) {
7
+ if (!isAbsolute(directory))
8
+ continue;
9
+ const candidate = join(directory, 'git');
10
+ if (!existsSync(candidate))
11
+ continue;
12
+ try {
13
+ const resolved = realpathSync(candidate);
14
+ if ((resolved.startsWith('/usr/') || resolved.startsWith('/home/linuxbrew/.linuxbrew/'))
15
+ && lstatSync(resolved).isFile())
16
+ return resolved;
17
+ }
18
+ catch { /* The first matching Git on PATH is untrusted. */ }
19
+ break;
20
+ }
21
+ throw new Error('mutation-qa-git-untrusted');
22
+ }
23
+ /** Exclude ambient Git configuration and executable shadowing; disable local hook/fsmonitor execution. */
24
+ export function mutationQaGit(root, args) {
25
+ return execFileSync(trustedGit(), [
26
+ '-c', 'core.fsmonitor=false', '-c', 'core.hooksPath=/dev/null',
27
+ '-c', 'protocol.ext.allow=never', ...args,
28
+ ], {
29
+ cwd: root,
30
+ env: {
31
+ PATH: '/usr/bin:/bin',
32
+ GIT_CONFIG_NOSYSTEM: '1',
33
+ GIT_CONFIG_GLOBAL: '/dev/null',
34
+ GIT_CONFIG_SYSTEM: '/dev/null',
35
+ GIT_TERMINAL_PROMPT: '0',
36
+ GIT_OPTIONAL_LOCKS: '0',
37
+ GIT_LFS_SKIP_SMUDGE: '1',
38
+ },
39
+ stdio: ['ignore', 'pipe', 'pipe'], timeout: 15_000, maxBuffer: 8 * 1024 * 1024,
40
+ });
41
+ }
@@ -1 +1,102 @@
1
- import{createHash as m}from"node:crypto";import{lstatSync as y,readFileSync as b,realpathSync as w}from"node:fs";import{join as x}from"node:path";const g=Object.freeze({schema_version:1,default_threshold:75,block_threshold:50,exclude_paths:["**/*.test.ts","**/*.spec.ts","**/__tests__/**","**/migrations/**","**/*.d.ts"],per_area_threshold:{domain:90,infrastructure:60}}),h=16*1024;function c(e){return typeof e=="number"&&Number.isFinite(e)&&e>=0&&e<=100}function d(e){if(e.length===0||e.length>240||e.startsWith("/")||e.includes("..")||e.includes("//")||!/^[A-Za-z0-9_./*?-]+$/.test(e))throw new Error("mutation-qa-policy-pattern-invalid");let t="^";for(let o=0;o<e.length;o++){const s=e[o];s==="*"?e[o+1]==="*"?e[o+2]==="/"?(t+="(?:.*/)?",o+=2):(t+=".*",o++):t+="[^/]*":s==="?"?t+="[^/]":s==="/"?t+="/":t+=s.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}return new RegExp(`${t}$`)}function O(e,t){return e.excludePaths.some(o=>d(o).test(t))}function A(e){const t=x(e,".neocortex","mutation-policy.json");let o="default",s=Buffer.from(JSON.stringify(g));const n=y(t,{throwIfNoEntry:!1});if(n){if(w(t)!==t)throw new Error("mutation-qa-policy-path-unsafe");if(!n.isFile()||n.size===0||n.size>h)throw new Error("mutation-qa-policy-size-invalid");if(s=b(t),s.byteLength===0||s.byteLength>h)throw new Error("mutation-qa-policy-size-invalid");o="project"}let a;try{a=JSON.parse(s.toString("utf8").replace(/^\uFEFF/,""))}catch{throw new Error("mutation-qa-policy-invalid")}if(!a||typeof a!="object"||Array.isArray(a))throw new Error("mutation-qa-policy-invalid");const r=a,f=new Set(["$schema","_comment","schema_version","default_threshold","block_threshold","exclude_paths","per_area_threshold"]);if(Object.keys(r).some(i=>!f.has(i))||r.schema_version!==1||!c(r.default_threshold)||!c(r.block_threshold)||r.block_threshold>r.default_threshold||!Array.isArray(r.exclude_paths)||r.exclude_paths.length>32||r.exclude_paths.some(i=>typeof i!="string"))throw new Error("mutation-qa-policy-invalid");const u=r.exclude_paths.map(i=>(d(i),i)),l=r.per_area_threshold??{};if(!l||typeof l!="object"||Array.isArray(l)||Object.keys(l).length>32||Object.entries(l).some(([i,_])=>!/^[a-z][a-z0-9-]{0,63}$/.test(i)||!c(_)))throw new Error("mutation-qa-policy-invalid");const p=Object.freeze({...l});return Object.freeze({schemaVersion:1,source:o,sha256:m("sha256").update(s).digest("hex"),thresholds:Object.freeze({defaultThreshold:r.default_threshold,blockThreshold:r.block_threshold,perAreaThreshold:p}),excludePaths:Object.freeze(u)})}export{A as loadMutationQaPolicy,O as policyExcludesPath};
1
+ /** Closed local mutation policy projection; never falls back from malformed project policy. */
2
+ import { createHash } from 'node:crypto';
3
+ import { lstatSync, readFileSync, realpathSync } from 'node:fs';
4
+ import { join } from 'node:path';
5
+ const DEFAULT_FIELDS = Object.freeze({ schema_version: 1, default_threshold: 75,
6
+ block_threshold: 50,
7
+ exclude_paths: ['**/*.test.ts', '**/*.spec.ts', '**/__tests__/**', '**/migrations/**', '**/*.d.ts'],
8
+ per_area_threshold: { domain: 90, infrastructure: 60 } });
9
+ const MAX_POLICY_BYTES = 16 * 1024;
10
+ function validScore(value) {
11
+ return typeof value === 'number' && Number.isFinite(value) && value >= 0 && value <= 100;
12
+ }
13
+ function globRegex(pattern) {
14
+ if (pattern.length === 0 || pattern.length > 240 || pattern.startsWith('/')
15
+ || pattern.includes('..') || pattern.includes('//')
16
+ || !/^[A-Za-z0-9_./*?-]+$/.test(pattern)) {
17
+ throw new Error('mutation-qa-policy-pattern-invalid');
18
+ }
19
+ let expression = '^';
20
+ for (let index = 0; index < pattern.length; index++) {
21
+ const current = pattern[index];
22
+ if (current === '*') {
23
+ if (pattern[index + 1] === '*') {
24
+ if (pattern[index + 2] === '/') {
25
+ expression += '(?:.*/)?';
26
+ index += 2;
27
+ }
28
+ else {
29
+ expression += '.*';
30
+ index++;
31
+ }
32
+ }
33
+ else
34
+ expression += '[^/]*';
35
+ }
36
+ else if (current === '?')
37
+ expression += '[^/]';
38
+ else if (current === '/')
39
+ expression += '/';
40
+ else
41
+ expression += current.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
42
+ }
43
+ return new RegExp(`${expression}$`);
44
+ }
45
+ export function policyExcludesPath(policy, path) {
46
+ return policy.excludePaths.some((pattern) => globRegex(pattern).test(path));
47
+ }
48
+ /** Accept a bounded subset of the published policy schema, failing closed on unknown semantics. */
49
+ export function loadMutationQaPolicy(projectRoot) {
50
+ const path = join(projectRoot, '.neocortex', 'mutation-policy.json');
51
+ let source = 'default';
52
+ let raw = Buffer.from(JSON.stringify(DEFAULT_FIELDS));
53
+ const stat = lstatSync(path, { throwIfNoEntry: false });
54
+ if (stat) {
55
+ if (realpathSync(path) !== path)
56
+ throw new Error('mutation-qa-policy-path-unsafe');
57
+ if (!stat.isFile() || stat.size === 0 || stat.size > MAX_POLICY_BYTES) {
58
+ throw new Error('mutation-qa-policy-size-invalid');
59
+ }
60
+ raw = readFileSync(path);
61
+ if (raw.byteLength === 0 || raw.byteLength > MAX_POLICY_BYTES) {
62
+ throw new Error('mutation-qa-policy-size-invalid');
63
+ }
64
+ source = 'project';
65
+ }
66
+ let parsed;
67
+ try {
68
+ parsed = JSON.parse(raw.toString('utf8').replace(/^\uFEFF/, ''));
69
+ }
70
+ catch {
71
+ throw new Error('mutation-qa-policy-invalid');
72
+ }
73
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
74
+ throw new Error('mutation-qa-policy-invalid');
75
+ }
76
+ const policy = parsed;
77
+ const allowed = new Set(['$schema', '_comment', 'schema_version', 'default_threshold',
78
+ 'block_threshold', 'exclude_paths', 'per_area_threshold']);
79
+ if (Object.keys(policy).some((key) => !allowed.has(key)) || policy.schema_version !== 1
80
+ || !validScore(policy.default_threshold) || !validScore(policy.block_threshold)
81
+ || policy.block_threshold > policy.default_threshold
82
+ || !Array.isArray(policy.exclude_paths) || policy.exclude_paths.length > 32
83
+ || policy.exclude_paths.some((entry) => typeof entry !== 'string')) {
84
+ throw new Error('mutation-qa-policy-invalid');
85
+ }
86
+ const exclusions = policy.exclude_paths.map((entry) => {
87
+ globRegex(entry);
88
+ return entry;
89
+ });
90
+ const areas = policy.per_area_threshold ?? {};
91
+ if (!areas || typeof areas !== 'object' || Array.isArray(areas)
92
+ || Object.keys(areas).length > 32
93
+ || Object.entries(areas).some(([key, value]) => !/^[a-z][a-z0-9-]{0,63}$/.test(key)
94
+ || !validScore(value)))
95
+ throw new Error('mutation-qa-policy-invalid');
96
+ const perAreaThreshold = Object.freeze({ ...areas });
97
+ return Object.freeze({ schemaVersion: 1, source,
98
+ sha256: createHash('sha256').update(raw).digest('hex'),
99
+ thresholds: Object.freeze({ defaultThreshold: policy.default_threshold,
100
+ blockThreshold: policy.block_threshold, perAreaThreshold }),
101
+ excludePaths: Object.freeze(exclusions), });
102
+ }