@mirnoorata/codexa 0.2.0

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 (364) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +634 -0
  3. package/dist/artifacts.d.ts +2 -0
  4. package/dist/artifacts.js +375 -0
  5. package/dist/artifacts.js.map +1 -0
  6. package/dist/autonomy.d.ts +17 -0
  7. package/dist/autonomy.js +124 -0
  8. package/dist/autonomy.js.map +1 -0
  9. package/dist/autoverify/policy.d.ts +5 -0
  10. package/dist/autoverify/policy.js +18 -0
  11. package/dist/autoverify/policy.js.map +1 -0
  12. package/dist/autoverify.d.ts +45 -0
  13. package/dist/autoverify.js +1041 -0
  14. package/dist/autoverify.js.map +1 -0
  15. package/dist/cache-lock.d.ts +16 -0
  16. package/dist/cache-lock.js +181 -0
  17. package/dist/cache-lock.js.map +1 -0
  18. package/dist/cli/hooks.d.ts +5 -0
  19. package/dist/cli/hooks.js +264 -0
  20. package/dist/cli/hooks.js.map +1 -0
  21. package/dist/cli.d.ts +2 -0
  22. package/dist/cli.js +1034 -0
  23. package/dist/cli.js.map +1 -0
  24. package/dist/codex-contract.d.ts +2 -0
  25. package/dist/codex-contract.js +78 -0
  26. package/dist/codex-contract.js.map +1 -0
  27. package/dist/command.d.ts +34 -0
  28. package/dist/command.js +162 -0
  29. package/dist/command.js.map +1 -0
  30. package/dist/doctor.d.ts +112 -0
  31. package/dist/doctor.js +518 -0
  32. package/dist/doctor.js.map +1 -0
  33. package/dist/eval/baseline.d.ts +7 -0
  34. package/dist/eval/baseline.js +146 -0
  35. package/dist/eval/baseline.js.map +1 -0
  36. package/dist/eval/historical.d.ts +4 -0
  37. package/dist/eval/historical.js +663 -0
  38. package/dist/eval/historical.js.map +1 -0
  39. package/dist/eval/render.d.ts +2 -0
  40. package/dist/eval/render.js +53 -0
  41. package/dist/eval/render.js.map +1 -0
  42. package/dist/eval/scoring.d.ts +21 -0
  43. package/dist/eval/scoring.js +618 -0
  44. package/dist/eval/scoring.js.map +1 -0
  45. package/dist/eval/synthetic.d.ts +36 -0
  46. package/dist/eval/synthetic.js +107 -0
  47. package/dist/eval/synthetic.js.map +1 -0
  48. package/dist/eval/types.d.ts +36 -0
  49. package/dist/eval/types.js +2 -0
  50. package/dist/eval/types.js.map +1 -0
  51. package/dist/eval.d.ts +140 -0
  52. package/dist/eval.js +551 -0
  53. package/dist/eval.js.map +1 -0
  54. package/dist/git.d.ts +17 -0
  55. package/dist/git.js +189 -0
  56. package/dist/git.js.map +1 -0
  57. package/dist/github-release.d.ts +47 -0
  58. package/dist/github-release.js +610 -0
  59. package/dist/github-release.js.map +1 -0
  60. package/dist/github-sync.d.ts +68 -0
  61. package/dist/github-sync.js +345 -0
  62. package/dist/github-sync.js.map +1 -0
  63. package/dist/graph.d.ts +10 -0
  64. package/dist/graph.js +665 -0
  65. package/dist/graph.js.map +1 -0
  66. package/dist/indexer/aliases.d.ts +2 -0
  67. package/dist/indexer/aliases.js +190 -0
  68. package/dist/indexer/aliases.js.map +1 -0
  69. package/dist/indexer/artifact-writing.d.ts +3 -0
  70. package/dist/indexer/artifact-writing.js +79 -0
  71. package/dist/indexer/artifact-writing.js.map +1 -0
  72. package/dist/indexer/discovery.d.ts +2 -0
  73. package/dist/indexer/discovery.js +5 -0
  74. package/dist/indexer/discovery.js.map +1 -0
  75. package/dist/indexer/external-facts.d.ts +6 -0
  76. package/dist/indexer/external-facts.js +45 -0
  77. package/dist/indexer/external-facts.js.map +1 -0
  78. package/dist/indexer/freshness.d.ts +8 -0
  79. package/dist/indexer/freshness.js +56 -0
  80. package/dist/indexer/freshness.js.map +1 -0
  81. package/dist/indexer/graph-stage.d.ts +2 -0
  82. package/dist/indexer/graph-stage.js +21 -0
  83. package/dist/indexer/graph-stage.js.map +1 -0
  84. package/dist/indexer/parsing.d.ts +30 -0
  85. package/dist/indexer/parsing.js +177 -0
  86. package/dist/indexer/parsing.js.map +1 -0
  87. package/dist/indexer/pipeline.d.ts +5 -0
  88. package/dist/indexer/pipeline.js +8 -0
  89. package/dist/indexer/pipeline.js.map +1 -0
  90. package/dist/indexer/ranking.d.ts +4 -0
  91. package/dist/indexer/ranking.js +134 -0
  92. package/dist/indexer/ranking.js.map +1 -0
  93. package/dist/indexer.d.ts +13 -0
  94. package/dist/indexer.js +395 -0
  95. package/dist/indexer.js.map +1 -0
  96. package/dist/init.d.ts +24 -0
  97. package/dist/init.js +566 -0
  98. package/dist/init.js.map +1 -0
  99. package/dist/language.d.ts +8 -0
  100. package/dist/language.js +123 -0
  101. package/dist/language.js.map +1 -0
  102. package/dist/live-index.d.ts +68 -0
  103. package/dist/live-index.js +215 -0
  104. package/dist/live-index.js.map +1 -0
  105. package/dist/lsp/assist.d.ts +44 -0
  106. package/dist/lsp/assist.js +331 -0
  107. package/dist/lsp/assist.js.map +1 -0
  108. package/dist/lsp/client.d.ts +59 -0
  109. package/dist/lsp/client.js +208 -0
  110. package/dist/lsp/client.js.map +1 -0
  111. package/dist/mcp/compaction.d.ts +15 -0
  112. package/dist/mcp/compaction.js +1249 -0
  113. package/dist/mcp/compaction.js.map +1 -0
  114. package/dist/mcp/envelope.d.ts +44 -0
  115. package/dist/mcp/envelope.js +425 -0
  116. package/dist/mcp/envelope.js.map +1 -0
  117. package/dist/mcp/prompts.d.ts +2 -0
  118. package/dist/mcp/prompts.js +109 -0
  119. package/dist/mcp/prompts.js.map +1 -0
  120. package/dist/mcp/resources.d.ts +2 -0
  121. package/dist/mcp/resources.js +132 -0
  122. package/dist/mcp/resources.js.map +1 -0
  123. package/dist/mcp/runtime.d.ts +15 -0
  124. package/dist/mcp/runtime.js +122 -0
  125. package/dist/mcp/runtime.js.map +1 -0
  126. package/dist/mcp/session-memory.d.ts +3 -0
  127. package/dist/mcp/session-memory.js +61 -0
  128. package/dist/mcp/session-memory.js.map +1 -0
  129. package/dist/mcp/tool-registry.d.ts +269 -0
  130. package/dist/mcp/tool-registry.js +284 -0
  131. package/dist/mcp/tool-registry.js.map +1 -0
  132. package/dist/mcp/tools.d.ts +53 -0
  133. package/dist/mcp/tools.js +372 -0
  134. package/dist/mcp/tools.js.map +1 -0
  135. package/dist/mcp-repo-root.d.ts +16 -0
  136. package/dist/mcp-repo-root.js +322 -0
  137. package/dist/mcp-repo-root.js.map +1 -0
  138. package/dist/mcp-tool-catalog.d.ts +2 -0
  139. package/dist/mcp-tool-catalog.js +2 -0
  140. package/dist/mcp-tool-catalog.js.map +1 -0
  141. package/dist/mcp.d.ts +11 -0
  142. package/dist/mcp.js +332 -0
  143. package/dist/mcp.js.map +1 -0
  144. package/dist/outcome-ranking.d.ts +5 -0
  145. package/dist/outcome-ranking.js +115 -0
  146. package/dist/outcome-ranking.js.map +1 -0
  147. package/dist/parser/context.d.ts +28 -0
  148. package/dist/parser/context.js +2 -0
  149. package/dist/parser/context.js.map +1 -0
  150. package/dist/parser/ecma.d.ts +5 -0
  151. package/dist/parser/ecma.js +388 -0
  152. package/dist/parser/ecma.js.map +1 -0
  153. package/dist/parser/facts.d.ts +12 -0
  154. package/dist/parser/facts.js +137 -0
  155. package/dist/parser/facts.js.map +1 -0
  156. package/dist/parser/json.d.ts +3 -0
  157. package/dist/parser/json.js +318 -0
  158. package/dist/parser/json.js.map +1 -0
  159. package/dist/parser/markdown.d.ts +3 -0
  160. package/dist/parser/markdown.js +180 -0
  161. package/dist/parser/markdown.js.map +1 -0
  162. package/dist/parser/nodes.d.ts +5 -0
  163. package/dist/parser/nodes.js +75 -0
  164. package/dist/parser/nodes.js.map +1 -0
  165. package/dist/parser/python.d.ts +2 -0
  166. package/dist/parser/python.js +307 -0
  167. package/dist/parser/python.js.map +1 -0
  168. package/dist/parser/references.d.ts +3 -0
  169. package/dist/parser/references.js +204 -0
  170. package/dist/parser/references.js.map +1 -0
  171. package/dist/parser/risks.d.ts +4 -0
  172. package/dist/parser/risks.js +62 -0
  173. package/dist/parser/risks.js.map +1 -0
  174. package/dist/parser/routes.d.ts +5 -0
  175. package/dist/parser/routes.js +97 -0
  176. package/dist/parser/routes.js.map +1 -0
  177. package/dist/parser/shallow.d.ts +3 -0
  178. package/dist/parser/shallow.js +545 -0
  179. package/dist/parser/shallow.js.map +1 -0
  180. package/dist/parser/source.d.ts +4 -0
  181. package/dist/parser/source.js +127 -0
  182. package/dist/parser/source.js.map +1 -0
  183. package/dist/parser.d.ts +2 -0
  184. package/dist/parser.js +2 -0
  185. package/dist/parser.js.map +1 -0
  186. package/dist/placeholder-signals.d.ts +15 -0
  187. package/dist/placeholder-signals.js +511 -0
  188. package/dist/placeholder-signals.js.map +1 -0
  189. package/dist/post-edit-outcomes.d.ts +167 -0
  190. package/dist/post-edit-outcomes.js +484 -0
  191. package/dist/post-edit-outcomes.js.map +1 -0
  192. package/dist/queries.d.ts +12 -0
  193. package/dist/queries.js +13 -0
  194. package/dist/queries.js.map +1 -0
  195. package/dist/query/change-plan.d.ts +48 -0
  196. package/dist/query/change-plan.js +858 -0
  197. package/dist/query/change-plan.js.map +1 -0
  198. package/dist/query/compact-data.d.ts +25 -0
  199. package/dist/query/compact-data.js +74 -0
  200. package/dist/query/compact-data.js.map +1 -0
  201. package/dist/query/context.d.ts +5 -0
  202. package/dist/query/context.js +1162 -0
  203. package/dist/query/context.js.map +1 -0
  204. package/dist/query/diff.d.ts +5 -0
  205. package/dist/query/diff.js +111 -0
  206. package/dist/query/diff.js.map +1 -0
  207. package/dist/query/edge-evidence.d.ts +3 -0
  208. package/dist/query/edge-evidence.js +36 -0
  209. package/dist/query/edge-evidence.js.map +1 -0
  210. package/dist/query/formatting.d.ts +14 -0
  211. package/dist/query/formatting.js +67 -0
  212. package/dist/query/formatting.js.map +1 -0
  213. package/dist/query/graph-traversal.d.ts +22 -0
  214. package/dist/query/graph-traversal.js +218 -0
  215. package/dist/query/graph-traversal.js.map +1 -0
  216. package/dist/query/graph.d.ts +14 -0
  217. package/dist/query/graph.js +102 -0
  218. package/dist/query/graph.js.map +1 -0
  219. package/dist/query/impact.d.ts +28 -0
  220. package/dist/query/impact.js +568 -0
  221. package/dist/query/impact.js.map +1 -0
  222. package/dist/query/inspection.d.ts +9 -0
  223. package/dist/query/inspection.js +290 -0
  224. package/dist/query/inspection.js.map +1 -0
  225. package/dist/query/next-tools.d.ts +3 -0
  226. package/dist/query/next-tools.js +25 -0
  227. package/dist/query/next-tools.js.map +1 -0
  228. package/dist/query/placeholders.d.ts +24 -0
  229. package/dist/query/placeholders.js +121 -0
  230. package/dist/query/placeholders.js.map +1 -0
  231. package/dist/query/post-edit/decision.d.ts +49 -0
  232. package/dist/query/post-edit/decision.js +130 -0
  233. package/dist/query/post-edit/decision.js.map +1 -0
  234. package/dist/query/post-edit/dirty-scope.d.ts +16 -0
  235. package/dist/query/post-edit/dirty-scope.js +21 -0
  236. package/dist/query/post-edit/dirty-scope.js.map +1 -0
  237. package/dist/query/post-edit/next-actions.d.ts +22 -0
  238. package/dist/query/post-edit/next-actions.js +44 -0
  239. package/dist/query/post-edit/next-actions.js.map +1 -0
  240. package/dist/query/post-edit/snapshot-contract.d.ts +8 -0
  241. package/dist/query/post-edit/snapshot-contract.js +111 -0
  242. package/dist/query/post-edit/snapshot-contract.js.map +1 -0
  243. package/dist/query/post-edit.d.ts +5 -0
  244. package/dist/query/post-edit.js +1108 -0
  245. package/dist/query/post-edit.js.map +1 -0
  246. package/dist/query/quality.d.ts +43 -0
  247. package/dist/query/quality.js +134 -0
  248. package/dist/query/quality.js.map +1 -0
  249. package/dist/query/raw-search.d.ts +23 -0
  250. package/dist/query/raw-search.js +147 -0
  251. package/dist/query/raw-search.js.map +1 -0
  252. package/dist/query/runtime.d.ts +11 -0
  253. package/dist/query/runtime.js +79 -0
  254. package/dist/query/runtime.js.map +1 -0
  255. package/dist/query/search.d.ts +25 -0
  256. package/dist/query/search.js +429 -0
  257. package/dist/query/search.js.map +1 -0
  258. package/dist/query/session-memory.d.ts +3 -0
  259. package/dist/query/session-memory.js +108 -0
  260. package/dist/query/session-memory.js.map +1 -0
  261. package/dist/query/session.d.ts +41 -0
  262. package/dist/query/session.js +90 -0
  263. package/dist/query/session.js.map +1 -0
  264. package/dist/query/targets.d.ts +25 -0
  265. package/dist/query/targets.js +97 -0
  266. package/dist/query/targets.js.map +1 -0
  267. package/dist/query/test-commands.d.ts +10 -0
  268. package/dist/query/test-commands.js +110 -0
  269. package/dist/query/test-commands.js.map +1 -0
  270. package/dist/query/test-plan.d.ts +6 -0
  271. package/dist/query/test-plan.js +104 -0
  272. package/dist/query/test-plan.js.map +1 -0
  273. package/dist/query/tests.d.ts +48 -0
  274. package/dist/query/tests.js +444 -0
  275. package/dist/query/tests.js.map +1 -0
  276. package/dist/query/verification/shell.d.ts +20 -0
  277. package/dist/query/verification/shell.js +164 -0
  278. package/dist/query/verification/shell.js.map +1 -0
  279. package/dist/query/verification.d.ts +47 -0
  280. package/dist/query/verification.js +1123 -0
  281. package/dist/query/verification.js.map +1 -0
  282. package/dist/query/workflow.d.ts +17 -0
  283. package/dist/query/workflow.js +252 -0
  284. package/dist/query/workflow.js.map +1 -0
  285. package/dist/query/workspace-guidance.d.ts +26 -0
  286. package/dist/query/workspace-guidance.js +214 -0
  287. package/dist/query/workspace-guidance.js.map +1 -0
  288. package/dist/query/worktree-state.d.ts +22 -0
  289. package/dist/query/worktree-state.js +32 -0
  290. package/dist/query/worktree-state.js.map +1 -0
  291. package/dist/query/worktree.d.ts +16 -0
  292. package/dist/query/worktree.js +194 -0
  293. package/dist/query/worktree.js.map +1 -0
  294. package/dist/query-data.d.ts +4 -0
  295. package/dist/query-data.js +112 -0
  296. package/dist/query-data.js.map +1 -0
  297. package/dist/repo-files.d.ts +24 -0
  298. package/dist/repo-files.js +105 -0
  299. package/dist/repo-files.js.map +1 -0
  300. package/dist/resolver.d.ts +9 -0
  301. package/dist/resolver.js +555 -0
  302. package/dist/resolver.js.map +1 -0
  303. package/dist/retrieval.d.ts +46 -0
  304. package/dist/retrieval.js +783 -0
  305. package/dist/retrieval.js.map +1 -0
  306. package/dist/risk-ingest.d.ts +16 -0
  307. package/dist/risk-ingest.js +458 -0
  308. package/dist/risk-ingest.js.map +1 -0
  309. package/dist/rules.d.ts +10 -0
  310. package/dist/rules.js +107 -0
  311. package/dist/rules.js.map +1 -0
  312. package/dist/semantic/python.d.ts +9 -0
  313. package/dist/semantic/python.js +817 -0
  314. package/dist/semantic/python.js.map +1 -0
  315. package/dist/semantic/typescript.d.ts +10 -0
  316. package/dist/semantic/typescript.js +714 -0
  317. package/dist/semantic/typescript.js.map +1 -0
  318. package/dist/semantic-retrieval.d.ts +53 -0
  319. package/dist/semantic-retrieval.js +673 -0
  320. package/dist/semantic-retrieval.js.map +1 -0
  321. package/dist/session-memory/derivation.d.ts +6 -0
  322. package/dist/session-memory/derivation.js +400 -0
  323. package/dist/session-memory/derivation.js.map +1 -0
  324. package/dist/session-memory/event-log.d.ts +23 -0
  325. package/dist/session-memory/event-log.js +126 -0
  326. package/dist/session-memory/event-log.js.map +1 -0
  327. package/dist/session-memory/formatting.d.ts +7 -0
  328. package/dist/session-memory/formatting.js +86 -0
  329. package/dist/session-memory/formatting.js.map +1 -0
  330. package/dist/session-memory/model.d.ts +94 -0
  331. package/dist/session-memory/model.js +17 -0
  332. package/dist/session-memory/model.js.map +1 -0
  333. package/dist/session-memory/runtime.d.ts +24 -0
  334. package/dist/session-memory/runtime.js +289 -0
  335. package/dist/session-memory/runtime.js.map +1 -0
  336. package/dist/session-memory/store.d.ts +27 -0
  337. package/dist/session-memory/store.js +447 -0
  338. package/dist/session-memory/store.js.map +1 -0
  339. package/dist/session-memory.d.ts +1 -0
  340. package/dist/session-memory.js +2 -0
  341. package/dist/session-memory.js.map +1 -0
  342. package/dist/static-analysis.d.ts +36 -0
  343. package/dist/static-analysis.js +505 -0
  344. package/dist/static-analysis.js.map +1 -0
  345. package/dist/symbol-report-ingest.d.ts +8 -0
  346. package/dist/symbol-report-ingest.js +504 -0
  347. package/dist/symbol-report-ingest.js.map +1 -0
  348. package/dist/task-snapshots.d.ts +41 -0
  349. package/dist/task-snapshots.js +430 -0
  350. package/dist/task-snapshots.js.map +1 -0
  351. package/dist/types.d.ts +848 -0
  352. package/dist/types.js +12 -0
  353. package/dist/types.js.map +1 -0
  354. package/dist/util.d.ts +11 -0
  355. package/dist/util.js +63 -0
  356. package/dist/util.js.map +1 -0
  357. package/dist/version.d.ts +1 -0
  358. package/dist/version.js +5 -0
  359. package/dist/version.js.map +1 -0
  360. package/package.json +81 -0
  361. package/plugins/codexa/.codex-plugin/plugin.json +38 -0
  362. package/plugins/codexa/.mcp.json +20 -0
  363. package/plugins/codexa/scripts/codexa-mcp.js +100 -0
  364. package/plugins/codexa/skills/codexa/SKILL.md +48 -0
@@ -0,0 +1,167 @@
1
+ import type { AutoVerifyReportRunner } from "./autoverify.js";
2
+ import type { Confidence, FreshnessInfo, TaskSnapshotRequiredCheck, TestRecommendation, VerificationCommandEnvelope, VerificationCommandReport, VerificationCoverage, VerificationLedgerEntry, VerificationLedgerStatus, VerificationProvenance, VerificationWaiver, SessionMemoryPointer } from "./types.js";
3
+ type OutcomeCommandReport = VerificationCommandReport & {
4
+ runner?: AutoVerifyReportRunner;
5
+ };
6
+ export type PostEditVerdict = "continue" | "run_tests" | "inspect" | "replan";
7
+ export type PostEditInspectMode = "none" | "advisory" | "blocking";
8
+ export type PostEditCompletionAuthority = "complete" | "tests_required" | "advisory_inspect" | "blocking_inspect" | "replan_required";
9
+ export type CodexaHookName = "session-start" | "pre-edit" | "post-edit";
10
+ export type CodexaHookEventStatus = "ok" | "skipped" | "failed";
11
+ export interface PostEditOutcomeInput {
12
+ repoRoot: string;
13
+ task: string;
14
+ taskId?: string;
15
+ snapshotPath?: string;
16
+ verdict: PostEditVerdict;
17
+ inspectMode: PostEditInspectMode;
18
+ inspectReasons: string[];
19
+ completionAuthority: PostEditCompletionAuthority;
20
+ freshness: FreshnessInfo;
21
+ changedFiles: string[];
22
+ plannedEditTargets: string[];
23
+ reviewTargets: string[];
24
+ unplannedEditedFiles: string[];
25
+ unindexedEditedFiles: string[];
26
+ modifiedSymbols: string[];
27
+ modifiedPublicSymbols: string[];
28
+ affectedWorkflows: string[];
29
+ workflowChecks: PostEditCheckResult[];
30
+ dependencyChecks: PostEditCheckResult[];
31
+ driftReasons: string[];
32
+ tests: TestRecommendation[];
33
+ degradedSnapshotTests?: TestRecommendation[];
34
+ testsNotRun: TestRecommendation[];
35
+ missedLikelyTests: TestRecommendation[];
36
+ ranTests: string[];
37
+ ranCommands: string[];
38
+ ranCommandReports: OutcomeCommandReport[];
39
+ commandEnvelopes: VerificationCommandEnvelope[];
40
+ waivedChecks: string[];
41
+ waivers: VerificationWaiver[];
42
+ verificationCoverage: VerificationCoverage[];
43
+ verificationLedger: VerificationLedgerEntry[];
44
+ verificationProvenance?: VerificationProvenance;
45
+ sessionMemory?: SessionMemoryPointer;
46
+ riskDeltas: PostEditRiskDelta[];
47
+ quality?: {
48
+ level?: unknown;
49
+ counts?: unknown;
50
+ };
51
+ confidence?: {
52
+ authoritative: number;
53
+ derived: number;
54
+ heuristic: number;
55
+ fallback: number;
56
+ };
57
+ }
58
+ export interface PostEditCheckResult extends TaskSnapshotRequiredCheck {
59
+ status: Extract<VerificationLedgerStatus, "covered" | "missing" | "not_applicable">;
60
+ }
61
+ export interface PostEditRiskDelta {
62
+ path: string;
63
+ beforeRisk: number;
64
+ afterRisk: number;
65
+ delta: number;
66
+ }
67
+ export interface PostEditHookSummary {
68
+ verdict: PostEditVerdict;
69
+ changedFiles: number;
70
+ unplannedEditedFiles: number;
71
+ modifiedSymbols: number;
72
+ missedLikelyTests: number;
73
+ riskIncreases: number;
74
+ requiredChecksMissing: number;
75
+ nextAction: string;
76
+ }
77
+ export interface PostEditOutcome {
78
+ schemaVersion: 1;
79
+ outcomeId: string;
80
+ createdAt: string;
81
+ repoRoot: string;
82
+ task: string;
83
+ taskId?: string;
84
+ snapshotPath?: string;
85
+ verdict: PostEditVerdict;
86
+ inspectMode: PostEditInspectMode;
87
+ inspectReasons: string[];
88
+ completionAuthority: PostEditCompletionAuthority;
89
+ headCommit: string | null;
90
+ indexSnapshotId: string;
91
+ changedFiles: string[];
92
+ plannedEditTargets: string[];
93
+ reviewTargets: string[];
94
+ unplannedEditedFiles: string[];
95
+ unindexedEditedFiles: string[];
96
+ modifiedSymbols: string[];
97
+ modifiedPublicSymbols: string[];
98
+ affectedWorkflows: string[];
99
+ workflowChecks: PostEditCheckResult[];
100
+ dependencyChecks: PostEditCheckResult[];
101
+ driftReasons: string[];
102
+ recommendedTests: Array<Pick<TestRecommendation, "path" | "reason" | "rank" | "evidenceTier" | "command" | "commandSource" | "commandConfidence" | "provenance">>;
103
+ degradedSnapshotTests: Array<Pick<TestRecommendation, "path" | "reason" | "rank" | "evidenceTier" | "command" | "commandSource" | "commandConfidence" | "provenance">>;
104
+ testsNotRun: Array<Pick<TestRecommendation, "path" | "reason" | "rank" | "evidenceTier" | "command" | "commandSource" | "commandConfidence" | "provenance">>;
105
+ missedLikelyTests: Array<Pick<TestRecommendation, "path" | "reason" | "rank" | "evidenceTier" | "command" | "commandSource" | "commandConfidence" | "provenance">>;
106
+ ranTests: string[];
107
+ ranCommands: string[];
108
+ ranCommandReports: OutcomeCommandReport[];
109
+ commandEnvelopes: VerificationCommandEnvelope[];
110
+ waivedChecks: string[];
111
+ waivers: VerificationWaiver[];
112
+ verificationCoverage: VerificationCoverage[];
113
+ verificationLedger: VerificationLedgerEntry[];
114
+ verificationProvenance: VerificationProvenance;
115
+ sessionMemory?: SessionMemoryPointer;
116
+ riskDeltas: PostEditRiskDelta[];
117
+ hookSummary: PostEditHookSummary;
118
+ qualityLevel?: string;
119
+ confidence?: Record<Confidence | "fallback", number>;
120
+ calibrationLabels: string[];
121
+ }
122
+ export interface PostEditHookReviewState {
123
+ schemaVersion: 1;
124
+ signature: string;
125
+ createdAt: string;
126
+ outcomeId?: string;
127
+ taskId?: string;
128
+ verdict?: PostEditVerdict;
129
+ autoVerifyStatus?: "off" | "covered" | "skipped" | "failed" | "non_covering";
130
+ }
131
+ export interface CodexaHookEventInput {
132
+ hook: CodexaHookName;
133
+ status: CodexaHookEventStatus;
134
+ durationMs: number;
135
+ reason?: string;
136
+ taskId?: string;
137
+ verdict?: PostEditVerdict;
138
+ outcomeId?: string;
139
+ signature?: string;
140
+ error?: string;
141
+ }
142
+ export interface CodexaHookEvent extends CodexaHookEventInput {
143
+ schemaVersion: 1;
144
+ createdAt: string;
145
+ repoRoot: ".";
146
+ }
147
+ export declare function buildPostEditOutcome(input: PostEditOutcomeInput, createdAt?: string): PostEditOutcome;
148
+ export declare function savePostEditOutcome(input: PostEditOutcomeInput): Promise<{
149
+ outcome: PostEditOutcome;
150
+ path: string;
151
+ relativePath: string;
152
+ }>;
153
+ export declare function postEditHookReviewSignature(input: {
154
+ freshness: FreshnessInfo;
155
+ taskId?: string;
156
+ autoVerifyMode?: string;
157
+ }): string;
158
+ export declare function loadPostEditHookReviewState(repoRoot: string): Promise<PostEditHookReviewState | null>;
159
+ export declare function savePostEditHookReviewState(repoRoot: string, input: {
160
+ signature: string;
161
+ outcome?: PostEditOutcome;
162
+ autoVerifyStatus?: PostEditHookReviewState["autoVerifyStatus"];
163
+ }): Promise<void>;
164
+ export declare function recordCodexaHookEvent(repoRoot: string, input: CodexaHookEventInput): Promise<void>;
165
+ export declare function loadLatestCodexaHookEvent(repoRoot: string): Promise<CodexaHookEvent | null>;
166
+ export declare function codexaHookEventsRelativePath(): string;
167
+ export {};
@@ -0,0 +1,484 @@
1
+ import { createHash } from "node:crypto";
2
+ import { promises as fs } from "node:fs";
3
+ import path from "node:path";
4
+ import { CURRENT_VERIFICATION_PROVENANCE } from "./types.js";
5
+ import { stableId } from "./util.js";
6
+ const OUTCOME_DIR = ".codex/cache/codexa-outcomes";
7
+ const LATEST_FILE = "latest.json";
8
+ const LATEST_HOOK_REVIEW_FILE = "latest-hook-review.json";
9
+ const HOOK_EVENT_DIR = ".codex/cache/codexa-hooks";
10
+ const HOOK_EVENTS_FILE = "events.ndjson";
11
+ const LATEST_HOOK_EVENT_FILE = "latest.json";
12
+ const MAX_HOOK_EVENTS_BYTES = 512 * 1024;
13
+ const MAX_HOOK_EVENT_LINES = 200;
14
+ export function buildPostEditOutcome(input, createdAt = new Date().toISOString()) {
15
+ const repoRoot = path.resolve(input.repoRoot);
16
+ const outcomeId = stableOutcomeId(repoRoot, input, createdAt);
17
+ return {
18
+ schemaVersion: 1,
19
+ outcomeId,
20
+ createdAt,
21
+ repoRoot: ".",
22
+ task: input.task,
23
+ taskId: input.taskId,
24
+ snapshotPath: input.snapshotPath,
25
+ verdict: input.verdict,
26
+ inspectMode: input.inspectMode,
27
+ inspectReasons: input.inspectReasons,
28
+ completionAuthority: input.completionAuthority,
29
+ headCommit: input.freshness.headCommit,
30
+ indexSnapshotId: input.freshness.snapshotId,
31
+ changedFiles: input.changedFiles,
32
+ plannedEditTargets: input.plannedEditTargets,
33
+ reviewTargets: input.reviewTargets,
34
+ unplannedEditedFiles: input.unplannedEditedFiles,
35
+ unindexedEditedFiles: input.unindexedEditedFiles,
36
+ modifiedSymbols: input.modifiedSymbols,
37
+ modifiedPublicSymbols: input.modifiedPublicSymbols,
38
+ affectedWorkflows: input.affectedWorkflows,
39
+ workflowChecks: input.workflowChecks,
40
+ dependencyChecks: input.dependencyChecks,
41
+ driftReasons: input.driftReasons,
42
+ recommendedTests: compactTests(input.tests, repoRoot),
43
+ degradedSnapshotTests: compactTests(input.degradedSnapshotTests ?? [], repoRoot),
44
+ testsNotRun: compactTests(input.testsNotRun, repoRoot),
45
+ missedLikelyTests: compactTests(input.missedLikelyTests, repoRoot),
46
+ ranTests: input.ranTests.map((test) => sanitizeText(test, repoRoot) ?? ""),
47
+ ranCommands: input.ranCommands.map((command) => sanitizeText(command, repoRoot) ?? ""),
48
+ ranCommandReports: compactCommandReports(input.ranCommandReports, repoRoot),
49
+ commandEnvelopes: compactCommandEnvelopes(input.commandEnvelopes, repoRoot),
50
+ waivedChecks: input.waivedChecks.map((check) => sanitizeText(check, repoRoot) ?? ""),
51
+ waivers: compactWaivers(input.waivers, repoRoot),
52
+ verificationCoverage: compactCoverage(input.verificationCoverage, repoRoot),
53
+ verificationLedger: compactLedger(input.verificationLedger, repoRoot),
54
+ verificationProvenance: input.verificationProvenance ?? CURRENT_VERIFICATION_PROVENANCE,
55
+ sessionMemory: input.sessionMemory,
56
+ riskDeltas: input.riskDeltas,
57
+ hookSummary: hookSummary(input),
58
+ qualityLevel: typeof input.quality?.level === "string" ? input.quality.level : undefined,
59
+ confidence: input.confidence,
60
+ calibrationLabels: calibrationLabels(input)
61
+ };
62
+ }
63
+ export async function savePostEditOutcome(input) {
64
+ const repoRoot = path.resolve(input.repoRoot);
65
+ const createdAt = new Date().toISOString();
66
+ const outcome = buildPostEditOutcome(input, createdAt);
67
+ const dir = path.join(repoRoot, OUTCOME_DIR);
68
+ await fs.mkdir(dir, { recursive: true });
69
+ const outcomePath = path.join(dir, `${outcome.outcomeId}.json`);
70
+ await atomicJsonWrite(outcomePath, outcome);
71
+ await atomicJsonWrite(path.join(dir, LATEST_FILE), {
72
+ schemaVersion: 1,
73
+ outcomeId: outcome.outcomeId,
74
+ path: path.basename(outcomePath),
75
+ createdAt,
76
+ verdict: outcome.verdict,
77
+ taskId: outcome.taskId
78
+ });
79
+ return { outcome, path: outcomePath, relativePath: path.posix.join(OUTCOME_DIR, `${outcome.outcomeId}.json`) };
80
+ }
81
+ export function postEditHookReviewSignature(input) {
82
+ return createHash("sha1")
83
+ .update(JSON.stringify({
84
+ taskId: input.taskId ?? null,
85
+ autoVerifyMode: input.autoVerifyMode ?? "autoverify:off",
86
+ snapshotId: input.freshness.snapshotId,
87
+ indexedAt: input.freshness.indexedAt,
88
+ headCommit: input.freshness.headCommit,
89
+ dirtyFiles: input.freshness.dirtyFiles,
90
+ dirtyFileHashes: input.freshness.dirtyFileHashes
91
+ }))
92
+ .digest("hex");
93
+ }
94
+ export async function loadPostEditHookReviewState(repoRoot) {
95
+ try {
96
+ const parsed = JSON.parse(await fs.readFile(path.join(path.resolve(repoRoot), OUTCOME_DIR, LATEST_HOOK_REVIEW_FILE), "utf8"));
97
+ if (parsed.schemaVersion === 1 && typeof parsed.signature === "string" && typeof parsed.createdAt === "string") {
98
+ return {
99
+ schemaVersion: 1,
100
+ signature: parsed.signature,
101
+ createdAt: parsed.createdAt,
102
+ outcomeId: typeof parsed.outcomeId === "string" ? parsed.outcomeId : undefined,
103
+ taskId: typeof parsed.taskId === "string" ? parsed.taskId : undefined,
104
+ verdict: isPostEditVerdict(parsed.verdict) ? parsed.verdict : undefined,
105
+ autoVerifyStatus: isAutoVerifyStatus(parsed.autoVerifyStatus) ? parsed.autoVerifyStatus : undefined
106
+ };
107
+ }
108
+ }
109
+ catch {
110
+ return null;
111
+ }
112
+ return null;
113
+ }
114
+ export async function savePostEditHookReviewState(repoRoot, input) {
115
+ const repo = path.resolve(repoRoot);
116
+ const dir = path.join(repo, OUTCOME_DIR);
117
+ await fs.mkdir(dir, { recursive: true });
118
+ await atomicJsonWrite(path.join(dir, LATEST_HOOK_REVIEW_FILE), {
119
+ schemaVersion: 1,
120
+ signature: input.signature,
121
+ createdAt: new Date().toISOString(),
122
+ outcomeId: input.outcome?.outcomeId,
123
+ taskId: input.outcome?.taskId,
124
+ verdict: input.outcome?.verdict,
125
+ autoVerifyStatus: input.autoVerifyStatus
126
+ });
127
+ }
128
+ export async function recordCodexaHookEvent(repoRoot, input) {
129
+ const repo = path.resolve(repoRoot);
130
+ const codexDir = path.join(repo, ".codex");
131
+ if (!(await pathExists(codexDir))) {
132
+ return;
133
+ }
134
+ const dir = path.join(repo, HOOK_EVENT_DIR);
135
+ await fs.mkdir(dir, { recursive: true });
136
+ const event = compactHookEvent(repo, input);
137
+ const eventsPath = path.join(dir, HOOK_EVENTS_FILE);
138
+ await trimHookEventsIfNeeded(eventsPath);
139
+ await fs.appendFile(eventsPath, `${JSON.stringify(event)}\n`, "utf8");
140
+ await atomicJsonWrite(path.join(dir, LATEST_HOOK_EVENT_FILE), event);
141
+ }
142
+ export async function loadLatestCodexaHookEvent(repoRoot) {
143
+ try {
144
+ const parsed = JSON.parse(await fs.readFile(path.join(path.resolve(repoRoot), HOOK_EVENT_DIR, LATEST_HOOK_EVENT_FILE), "utf8"));
145
+ if (parsed.schemaVersion === 1 &&
146
+ parsed.repoRoot === "." &&
147
+ isHookName(parsed.hook) &&
148
+ isHookEventStatus(parsed.status) &&
149
+ typeof parsed.createdAt === "string" &&
150
+ typeof parsed.durationMs === "number") {
151
+ return {
152
+ schemaVersion: 1,
153
+ createdAt: parsed.createdAt,
154
+ repoRoot: ".",
155
+ hook: parsed.hook,
156
+ status: parsed.status,
157
+ durationMs: parsed.durationMs,
158
+ reason: typeof parsed.reason === "string" ? parsed.reason : undefined,
159
+ taskId: typeof parsed.taskId === "string" ? parsed.taskId : undefined,
160
+ verdict: isPostEditVerdict(parsed.verdict) ? parsed.verdict : undefined,
161
+ outcomeId: typeof parsed.outcomeId === "string" ? parsed.outcomeId : undefined,
162
+ signature: typeof parsed.signature === "string" ? parsed.signature : undefined,
163
+ error: typeof parsed.error === "string" ? parsed.error : undefined
164
+ };
165
+ }
166
+ }
167
+ catch {
168
+ return null;
169
+ }
170
+ return null;
171
+ }
172
+ export function codexaHookEventsRelativePath() {
173
+ return path.posix.join(HOOK_EVENT_DIR, HOOK_EVENTS_FILE);
174
+ }
175
+ function stableOutcomeId(repoRoot, input, createdAt) {
176
+ const task = (input.taskId ?? input.task).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 40) || "post-edit";
177
+ const suffix = stableId("post-edit-outcome", repoRoot, input.taskId, input.task, input.verdict, input.changedFiles.join("\n"), createdAt);
178
+ return `${task}-${createdAt.replace(/[-:TZ.]/g, "").slice(0, 14)}-${suffix}`.slice(0, 120);
179
+ }
180
+ function isPostEditVerdict(value) {
181
+ return value === "continue" || value === "run_tests" || value === "inspect" || value === "replan";
182
+ }
183
+ function isHookName(value) {
184
+ return value === "session-start" || value === "pre-edit" || value === "post-edit";
185
+ }
186
+ function isHookEventStatus(value) {
187
+ return value === "ok" || value === "skipped" || value === "failed";
188
+ }
189
+ function isAutoVerifyStatus(value) {
190
+ return value === "off" || value === "covered" || value === "skipped" || value === "failed" || value === "non_covering";
191
+ }
192
+ function compactHookEvent(repoRoot, input) {
193
+ return {
194
+ schemaVersion: 1,
195
+ createdAt: new Date().toISOString(),
196
+ repoRoot: ".",
197
+ hook: input.hook,
198
+ status: input.status,
199
+ durationMs: Math.max(0, Math.round(input.durationMs)),
200
+ reason: sanitizeText(input.reason, repoRoot),
201
+ taskId: sanitizeText(input.taskId, repoRoot),
202
+ verdict: input.verdict,
203
+ outcomeId: sanitizeText(input.outcomeId, repoRoot),
204
+ signature: sanitizeText(input.signature, repoRoot),
205
+ error: sanitizeText(input.error, repoRoot)
206
+ };
207
+ }
208
+ async function trimHookEventsIfNeeded(eventsPath) {
209
+ try {
210
+ const stat = await fs.stat(eventsPath);
211
+ if (stat.size < MAX_HOOK_EVENTS_BYTES) {
212
+ return;
213
+ }
214
+ const text = await fs.readFile(eventsPath, "utf8");
215
+ const lines = text.split(/\r?\n/u).filter(Boolean).slice(-MAX_HOOK_EVENT_LINES);
216
+ await fs.writeFile(eventsPath, `${lines.join("\n")}\n`, "utf8");
217
+ }
218
+ catch {
219
+ return;
220
+ }
221
+ }
222
+ async function pathExists(filePath) {
223
+ try {
224
+ await fs.access(filePath);
225
+ return true;
226
+ }
227
+ catch {
228
+ return false;
229
+ }
230
+ }
231
+ function compactTests(tests, repoRoot) {
232
+ return tests.map((test) => ({
233
+ path: test.path,
234
+ reason: test.reason,
235
+ rank: test.rank,
236
+ evidenceTier: test.evidenceTier,
237
+ command: test.command?.replaceAll(repoRoot, "<repo>"),
238
+ commandSource: test.commandSource,
239
+ commandConfidence: test.commandConfidence,
240
+ provenance: test.provenance
241
+ }));
242
+ }
243
+ function compactCoverage(coverage, repoRoot) {
244
+ return coverage.map((entry) => ({
245
+ ...entry,
246
+ command: sanitizeText(entry.command, repoRoot) ?? "",
247
+ source: sanitizeText(entry.source, repoRoot) ?? entry.source,
248
+ scope: sanitizePathField(entry.scope, repoRoot),
249
+ targetPath: sanitizePathField(entry.targetPath, repoRoot),
250
+ details: entry.details.map((detail) => sanitizeText(detail, repoRoot) ?? "").filter(Boolean),
251
+ outputSummary: sanitizeText(entry.outputSummary, repoRoot),
252
+ commandEnvelope: entry.commandEnvelope ? compactCommandEnvelopes([entry.commandEnvelope], repoRoot)[0] : undefined
253
+ }));
254
+ }
255
+ function compactCommandReports(reports, repoRoot) {
256
+ return reports.map((report) => ({
257
+ ...report,
258
+ command: sanitizeText(report.command, repoRoot) ?? "",
259
+ cwd: sanitizePathField(report.cwd, repoRoot),
260
+ packageManager: sanitizeText(report.packageManager, repoRoot),
261
+ workspace: sanitizeText(report.workspace, repoRoot),
262
+ packageRoot: sanitizePathField(report.packageRoot, repoRoot),
263
+ packageName: sanitizeText(report.packageName, repoRoot),
264
+ scriptName: sanitizeText(report.scriptName, repoRoot),
265
+ stdoutSummary: sanitizeText(report.stdoutSummary, repoRoot),
266
+ stderrSummary: sanitizeText(report.stderrSummary, repoRoot),
267
+ outputSummary: sanitizeText(report.outputSummary, repoRoot),
268
+ args: sanitizeArgs(report.args, repoRoot),
269
+ runner: compactRunner(report.runner, repoRoot)
270
+ }));
271
+ }
272
+ function compactRunner(runner, repoRoot) {
273
+ if (!runner) {
274
+ return undefined;
275
+ }
276
+ return {
277
+ ...runner,
278
+ cwdRealpath: sanitizePathField(runner.cwdRealpath, repoRoot) ?? runner.cwdRealpath,
279
+ targetRealpaths: runner.targetRealpaths.map((target) => sanitizePathField(target, repoRoot) ?? target),
280
+ allowedBy: runner.allowedBy.map((reason) => sanitizeText(reason, repoRoot) ?? reason),
281
+ skippedReason: sanitizeText(runner.skippedReason, repoRoot)
282
+ };
283
+ }
284
+ function compactCommandEnvelopes(envelopes, repoRoot) {
285
+ return envelopes.map((envelope) => ({
286
+ ...envelope,
287
+ command: sanitizeText(envelope.command, repoRoot) ?? "",
288
+ cwd: sanitizePathField(envelope.cwd, repoRoot),
289
+ packageManager: sanitizeText(envelope.packageManager, repoRoot),
290
+ workspace: sanitizeText(envelope.workspace, repoRoot),
291
+ packageRoot: sanitizePathField(envelope.packageRoot, repoRoot),
292
+ packageName: sanitizeText(envelope.packageName, repoRoot),
293
+ scriptName: sanitizeText(envelope.scriptName, repoRoot),
294
+ stdoutSummary: sanitizeText(envelope.stdoutSummary, repoRoot),
295
+ stderrSummary: sanitizeText(envelope.stderrSummary, repoRoot),
296
+ outputSummary: sanitizeText(envelope.outputSummary, repoRoot),
297
+ args: sanitizeArgs(envelope.args, repoRoot) ?? []
298
+ }));
299
+ }
300
+ function compactWaivers(waivers, repoRoot) {
301
+ return waivers.map((waiver) => ({
302
+ kind: waiver.kind,
303
+ target: sanitizeText(waiver.target, repoRoot) ?? "",
304
+ reason: sanitizeText(waiver.reason, repoRoot) ?? ""
305
+ }));
306
+ }
307
+ function compactLedger(ledger, repoRoot) {
308
+ return ledger.map((entry) => ({
309
+ ...entry,
310
+ command: sanitizeText(entry.command, repoRoot),
311
+ evidence: entry.evidence.map((item) => sanitizeText(item, repoRoot) ?? "").filter(Boolean)
312
+ }));
313
+ }
314
+ function clampSummary(value) {
315
+ const clean = value?.replace(/\s+/gu, " ").trim();
316
+ if (!clean) {
317
+ return undefined;
318
+ }
319
+ return clean.length > 500 ? `${clean.slice(0, 497)}...` : clean;
320
+ }
321
+ function sanitizeText(value, repoRoot) {
322
+ return clampSummary(redactSecretText(value)
323
+ ?.replaceAll(repoRoot, "<repo>")
324
+ .replace(/__outside_repo__:[^\s;|)]+/gu, "__outside_repo__:<outside-repo>")
325
+ .replace(/(^|[\s([,{])\/[^\s;|)\]'",]+/gu, "$1<abs-path>")
326
+ .replace(/(^|[\s([,{])(?:\.\.?\/)[^\s;|)\]'",]+/gu, "$1<rel-path>"));
327
+ }
328
+ function sanitizeArgs(args, repoRoot) {
329
+ if (!args) {
330
+ return undefined;
331
+ }
332
+ let redactNext = false;
333
+ return args.map((arg) => {
334
+ if (redactNext) {
335
+ redactNext = false;
336
+ return "<redacted>";
337
+ }
338
+ if (isSecretFlag(arg) && !arg.includes("=")) {
339
+ redactNext = true;
340
+ return sanitizeText(arg, repoRoot) ?? "";
341
+ }
342
+ return sanitizeText(redactSecretArg(arg), repoRoot) ?? "";
343
+ });
344
+ }
345
+ function redactSecretText(value) {
346
+ return value
347
+ ?.replace(/(^|[\s([,{])((?:--?[a-z0-9-]*(?:token|secret|password|passwd|pwd|api[-_]?key|access[-_]?key|auth|credential|cookie)[a-z0-9-]*)(?:=|\s+))([^\s;|)\]'",]+)/giu, "$1$2<redacted>")
348
+ .replace(/(\b[A-Z_]*(?:TOKEN|SECRET|PASSWORD|PASSWD|PWD|API_?KEY|ACCESS_?KEY|AUTH|CREDENTIAL|COOKIE)[A-Z0-9_]*=)([^\s;|)\]'",]+)/gu, "$1<redacted>")
349
+ .replace(/\b(Bearer)\s+[A-Za-z0-9._~+/-]+=*/giu, "$1 <redacted>");
350
+ }
351
+ function redactSecretArg(value) {
352
+ if (/^Bearer\s+/iu.test(value)) {
353
+ return "Bearer <redacted>";
354
+ }
355
+ if (isSecretFlag(value) && value.includes("=")) {
356
+ return value.replace(/=.*/u, "=<redacted>");
357
+ }
358
+ if (/^(?:[A-Z_]*(?:TOKEN|SECRET|PASSWORD|PASSWD|PWD|API_?KEY|ACCESS_?KEY|AUTH|CREDENTIAL|COOKIE)[A-Z0-9_]*)=/iu.test(value)) {
359
+ return value.replace(/=.*/u, "=<redacted>");
360
+ }
361
+ return value;
362
+ }
363
+ function isSecretFlag(value) {
364
+ return /^--?[a-z0-9-]*(?:token|secret|password|passwd|pwd|api-?key|access-?key|auth|credential|cookie)[a-z0-9-]*(?:=.*)?$/iu.test(value);
365
+ }
366
+ function sanitizePathField(value, repoRoot) {
367
+ if (!value) {
368
+ return undefined;
369
+ }
370
+ if (value.startsWith("__outside_repo__:")) {
371
+ return "__outside_repo__:<outside-repo>";
372
+ }
373
+ if (value === "." || value === "./") {
374
+ return ".";
375
+ }
376
+ if (value === ".." || value.startsWith("../")) {
377
+ return "<outside-repo>";
378
+ }
379
+ if (value.startsWith("./")) {
380
+ const relative = value.replace(/\\/gu, "/").replace(/^\.\//u, "").replace(/\/+/gu, "/");
381
+ return relative === "." ? "." : `<repo>/${relative}`;
382
+ }
383
+ if (path.isAbsolute(value)) {
384
+ const relative = path.relative(repoRoot, value);
385
+ if (relative === "") {
386
+ return "<repo>";
387
+ }
388
+ return !relative.startsWith("..") && !path.isAbsolute(relative) ? `<repo>/${relative.split(path.sep).join("/")}` : "<outside-repo>";
389
+ }
390
+ return sanitizeText(value, repoRoot);
391
+ }
392
+ function hookSummary(input) {
393
+ const missingChecks = [...input.workflowChecks, ...input.dependencyChecks].filter((check) => check.status === "missing").length;
394
+ const riskIncreases = input.riskDeltas.filter((delta) => delta.delta > 0).length;
395
+ const nextAction = input.verdict === "replan"
396
+ ? "replan before continuing"
397
+ : input.verdict === "inspect"
398
+ ? "inspect drift before completion"
399
+ : input.verdict === "run_tests"
400
+ ? "run or account for targeted tests"
401
+ : "continue with normal diff review";
402
+ return {
403
+ verdict: input.verdict,
404
+ changedFiles: input.changedFiles.length,
405
+ unplannedEditedFiles: input.unplannedEditedFiles.length,
406
+ modifiedSymbols: input.modifiedSymbols.length,
407
+ missedLikelyTests: input.missedLikelyTests.length,
408
+ riskIncreases,
409
+ requiredChecksMissing: missingChecks,
410
+ nextAction
411
+ };
412
+ }
413
+ function calibrationLabels(input) {
414
+ const labels = [];
415
+ if (input.unplannedEditedFiles.length > 0) {
416
+ labels.push("unplanned-edits");
417
+ }
418
+ const commandEvidenceCount = input.ranCommands.length + input.ranCommandReports.length;
419
+ const commandCoveredTests = commandEvidenceCount > 0 &&
420
+ input.verificationLedger.some((entry) => entry.kind === "test" && entry.status === "covered" && entry.coverageKinds.some((kind) => kind === "javascript-tests" || kind === "python-tests" || kind === "targeted-test"));
421
+ const unresolvedCommandCoverage = commandEvidenceCount > 0 && input.verificationCoverage.some((entry) => entry.kind === "unknown");
422
+ const failedCommandCoverage = input.verificationCoverage.some((entry) => entry.kind === "unknown" && entry.exitCode !== undefined && entry.exitCode !== 0);
423
+ if (input.testsNotRun.length > 0) {
424
+ labels.push("missing-recommended-tests");
425
+ labels.push(failedCommandCoverage ? "failed-verification-command" : unresolvedCommandCoverage ? "unresolved-verification-command" : "real-missed-tests");
426
+ }
427
+ else if (commandCoveredTests && input.ranTests.length === 0 && commandEvidenceCount > 0) {
428
+ labels.push("aggregate-command-coverage");
429
+ labels.push("false-missing-test-warning-avoided");
430
+ }
431
+ if (input.verificationLedger.some((entry) => entry.status === "waived")) {
432
+ labels.push("verification-waiver");
433
+ }
434
+ if (input.verificationLedger.some((entry) => entry.status === "waived" && entry.kind === "test")) {
435
+ labels.push("waived-behavior-test");
436
+ }
437
+ if (input.verificationLedger.some((entry) => entry.status === "waived" && entry.kind === "workflow")) {
438
+ labels.push("workflow-checks-waived");
439
+ }
440
+ if (input.verificationLedger.some((entry) => entry.status === "waived" && entry.kind === "dependency")) {
441
+ labels.push("dependency-checks-waived");
442
+ }
443
+ if (input.verificationLedger.some((entry) => entry.status === "waived" && entry.kind !== "test")) {
444
+ labels.push("waived-required-check");
445
+ }
446
+ if (input.verificationLedger.some((entry) => entry.status === "not_applicable")) {
447
+ labels.push("recommended-check-not-applicable");
448
+ }
449
+ if (input.unindexedEditedFiles.length > 0) {
450
+ labels.push("unindexed-edits");
451
+ }
452
+ if (input.modifiedPublicSymbols.length > 0) {
453
+ labels.push("modified-public-symbols");
454
+ }
455
+ if (input.workflowChecks.some((check) => check.status === "missing")) {
456
+ labels.push("workflow-checks-missing");
457
+ }
458
+ if (input.dependencyChecks.some((check) => check.status === "missing")) {
459
+ labels.push("dependency-checks-missing");
460
+ }
461
+ if (input.riskDeltas.some((delta) => delta.delta > 0)) {
462
+ labels.push("risk-increase");
463
+ }
464
+ if (input.quality?.level === "low") {
465
+ labels.push("low-context-quality");
466
+ }
467
+ if ((input.confidence?.heuristic ?? 0) > (input.confidence?.authoritative ?? 0) + (input.confidence?.derived ?? 0)) {
468
+ labels.push("heuristic-heavy");
469
+ }
470
+ if (input.verdict === "replan") {
471
+ labels.push("requires-replan");
472
+ }
473
+ else if (input.verdict === "inspect") {
474
+ labels.push("requires-inspection");
475
+ labels.push(input.inspectMode === "blocking" ? "blocking-inspection" : "advisory-inspection");
476
+ }
477
+ return [...new Set(labels)].sort();
478
+ }
479
+ async function atomicJsonWrite(filePath, value) {
480
+ const tmp = `${filePath}.${process.pid}.${Date.now()}.tmp`;
481
+ await fs.writeFile(tmp, `${JSON.stringify(value, null, 2)}\n`, "utf8");
482
+ await fs.rename(tmp, filePath);
483
+ }
484
+ //# sourceMappingURL=post-edit-outcomes.js.map