audit-tools 0.30.48 → 0.30.51

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 (263) hide show
  1. package/dist/audit/cli/advanceAuditCommand.d.ts.map +1 -1
  2. package/dist/audit/cli/advanceAuditCommand.js +8 -4
  3. package/dist/audit/cli/advanceAuditCommand.js.map +1 -1
  4. package/dist/audit/cli/args.d.ts +0 -10
  5. package/dist/audit/cli/args.d.ts.map +1 -1
  6. package/dist/audit/cli/args.js +9 -20
  7. package/dist/audit/cli/args.js.map +1 -1
  8. package/dist/audit/cli/envelope.d.ts +0 -1
  9. package/dist/audit/cli/envelope.d.ts.map +1 -1
  10. package/dist/audit/cli/envelope.js +0 -3
  11. package/dist/audit/cli/envelope.js.map +1 -1
  12. package/dist/audit/cli/mergeAndIngestCommand.d.ts.map +1 -1
  13. package/dist/audit/cli/mergeAndIngestCommand.js +6 -22
  14. package/dist/audit/cli/mergeAndIngestCommand.js.map +1 -1
  15. package/dist/audit/cli/nextStepCommand.d.ts +18 -14
  16. package/dist/audit/cli/nextStepCommand.d.ts.map +1 -1
  17. package/dist/audit/cli/nextStepCommand.js +23 -25
  18. package/dist/audit/cli/nextStepCommand.js.map +1 -1
  19. package/dist/audit/cli/validateResultCommand.d.ts.map +1 -1
  20. package/dist/audit/cli/validateResultCommand.js +19 -6
  21. package/dist/audit/cli/validateResultCommand.js.map +1 -1
  22. package/dist/audit/cli/workerResult.d.ts +0 -4
  23. package/dist/audit/cli/workerResult.d.ts.map +1 -1
  24. package/dist/audit/cli/workerResult.js +0 -22
  25. package/dist/audit/cli/workerResult.js.map +1 -1
  26. package/dist/audit/cli/workerRunCommand.d.ts.map +1 -1
  27. package/dist/audit/cli/workerRunCommand.js +6 -21
  28. package/dist/audit/cli/workerRunCommand.js.map +1 -1
  29. package/dist/audit/contracts/workerSchemas.d.ts +27 -3
  30. package/dist/audit/contracts/workerSchemas.d.ts.map +1 -1
  31. package/dist/audit/contracts/workerSchemas.js +5 -1
  32. package/dist/audit/contracts/workerSchemas.js.map +1 -1
  33. package/dist/audit/contracts/wrapperResponse.d.ts +0 -1
  34. package/dist/audit/contracts/wrapperResponse.d.ts.map +1 -1
  35. package/dist/audit/coverage.d.ts +1 -2
  36. package/dist/audit/coverage.d.ts.map +1 -1
  37. package/dist/audit/coverage.js +0 -7
  38. package/dist/audit/coverage.js.map +1 -1
  39. package/dist/audit/extractors/analyzers/acquisitionEngine.d.ts +0 -2
  40. package/dist/audit/extractors/analyzers/acquisitionEngine.d.ts.map +1 -1
  41. package/dist/audit/extractors/analyzers/acquisitionEngine.js +0 -6
  42. package/dist/audit/extractors/analyzers/acquisitionEngine.js.map +1 -1
  43. package/dist/audit/extractors/analyzers/html.d.ts +1 -0
  44. package/dist/audit/extractors/analyzers/html.d.ts.map +1 -1
  45. package/dist/audit/extractors/analyzers/html.js +5 -3
  46. package/dist/audit/extractors/analyzers/html.js.map +1 -1
  47. package/dist/audit/extractors/analyzers/registry.d.ts +1 -2
  48. package/dist/audit/extractors/analyzers/registry.d.ts.map +1 -1
  49. package/dist/audit/extractors/analyzers/registry.js +1 -4
  50. package/dist/audit/extractors/analyzers/registry.js.map +1 -1
  51. package/dist/audit/extractors/browserExtension.d.ts +0 -1
  52. package/dist/audit/extractors/browserExtension.d.ts.map +1 -1
  53. package/dist/audit/extractors/browserExtension.js +1 -20
  54. package/dist/audit/extractors/browserExtension.js.map +1 -1
  55. package/dist/audit/extractors/gitHistory.d.ts +1 -3
  56. package/dist/audit/extractors/gitHistory.d.ts.map +1 -1
  57. package/dist/audit/extractors/graphRoutes.d.ts.map +1 -1
  58. package/dist/audit/extractors/graphRoutes.js +4 -1
  59. package/dist/audit/extractors/graphRoutes.js.map +1 -1
  60. package/dist/audit/io/artifacts.d.ts +0 -1
  61. package/dist/audit/io/artifacts.d.ts.map +1 -1
  62. package/dist/audit/io/artifacts.js +0 -17
  63. package/dist/audit/io/artifacts.js.map +1 -1
  64. package/dist/audit/io/runArtifacts.d.ts +1 -4
  65. package/dist/audit/io/runArtifacts.d.ts.map +1 -1
  66. package/dist/audit/io/runArtifacts.js +0 -46
  67. package/dist/audit/io/runArtifacts.js.map +1 -1
  68. package/dist/audit/orchestrator/autoFixExecutor.d.ts +8 -0
  69. package/dist/audit/orchestrator/autoFixExecutor.d.ts.map +1 -1
  70. package/dist/audit/orchestrator/autoFixExecutor.js +68 -35
  71. package/dist/audit/orchestrator/autoFixExecutor.js.map +1 -1
  72. package/dist/audit/orchestrator/designReviewSnapshot.d.ts +0 -1
  73. package/dist/audit/orchestrator/designReviewSnapshot.d.ts.map +1 -1
  74. package/dist/audit/orchestrator/designReviewSnapshot.js +0 -25
  75. package/dist/audit/orchestrator/designReviewSnapshot.js.map +1 -1
  76. package/dist/audit/orchestrator/intentInterpreter.d.ts +0 -7
  77. package/dist/audit/orchestrator/intentInterpreter.d.ts.map +1 -1
  78. package/dist/audit/orchestrator/intentInterpreter.js +0 -9
  79. package/dist/audit/orchestrator/intentInterpreter.js.map +1 -1
  80. package/dist/audit/orchestrator/ledger.d.ts +0 -10
  81. package/dist/audit/orchestrator/ledger.d.ts.map +1 -1
  82. package/dist/audit/orchestrator/ledger.js +0 -19
  83. package/dist/audit/orchestrator/ledger.js.map +1 -1
  84. package/dist/audit/orchestrator/lensSelection.d.ts +0 -9
  85. package/dist/audit/orchestrator/lensSelection.d.ts.map +1 -1
  86. package/dist/audit/orchestrator/lensSelection.js +0 -29
  87. package/dist/audit/orchestrator/lensSelection.js.map +1 -1
  88. package/dist/audit/orchestrator/resultBaseline.d.ts +0 -44
  89. package/dist/audit/orchestrator/resultBaseline.d.ts.map +1 -1
  90. package/dist/audit/orchestrator/resultBaseline.js +0 -44
  91. package/dist/audit/orchestrator/resultBaseline.js.map +1 -1
  92. package/dist/audit/orchestrator/runtimeCommand.d.ts.map +1 -1
  93. package/dist/audit/orchestrator/runtimeCommand.js +7 -1
  94. package/dist/audit/orchestrator/runtimeCommand.js.map +1 -1
  95. package/dist/audit/orchestrator/selectiveDeepening/index.d.ts +0 -5
  96. package/dist/audit/orchestrator/selectiveDeepening/index.d.ts.map +1 -1
  97. package/dist/audit/orchestrator/selectiveDeepening/index.js +13 -14
  98. package/dist/audit/orchestrator/selectiveDeepening/index.js.map +1 -1
  99. package/dist/audit/orchestrator/selectiveDeepening.d.ts +1 -1
  100. package/dist/audit/orchestrator/selectiveDeepening.d.ts.map +1 -1
  101. package/dist/audit/orchestrator/selectiveDeepening.js +1 -1
  102. package/dist/audit/orchestrator/selectiveDeepening.js.map +1 -1
  103. package/dist/audit/orchestrator/taskBuilder.d.ts +0 -1
  104. package/dist/audit/orchestrator/taskBuilder.d.ts.map +1 -1
  105. package/dist/audit/orchestrator/taskBuilder.js +0 -73
  106. package/dist/audit/orchestrator/taskBuilder.js.map +1 -1
  107. package/dist/audit/quota/discoveredLimits.d.ts +12 -0
  108. package/dist/audit/quota/discoveredLimits.d.ts.map +1 -1
  109. package/dist/audit/quota/discoveredLimits.js +30 -25
  110. package/dist/audit/quota/discoveredLimits.js.map +1 -1
  111. package/dist/audit/supervisor/operatorHandoff.d.ts +0 -1
  112. package/dist/audit/supervisor/operatorHandoff.d.ts.map +1 -1
  113. package/dist/audit/supervisor/operatorHandoff.js +0 -1
  114. package/dist/audit/supervisor/operatorHandoff.js.map +1 -1
  115. package/dist/audit/supervisor/runLedger.d.ts +1 -2
  116. package/dist/audit/supervisor/runLedger.d.ts.map +1 -1
  117. package/dist/audit/supervisor/runLedger.js +1 -46
  118. package/dist/audit/supervisor/runLedger.js.map +1 -1
  119. package/dist/audit/types/analyzerCapability.d.ts +0 -1
  120. package/dist/audit/types/analyzerCapability.d.ts.map +1 -1
  121. package/dist/audit/types/analyzerCapability.js.map +1 -1
  122. package/dist/audit/types/designAssessment.d.ts +0 -4
  123. package/dist/audit/types/designAssessment.d.ts.map +1 -1
  124. package/dist/audit/types/designAssessment.js +1 -7
  125. package/dist/audit/types/designAssessment.js.map +1 -1
  126. package/dist/audit/types/externalAnalyzer.d.ts +0 -1
  127. package/dist/audit/types/externalAnalyzer.d.ts.map +1 -1
  128. package/dist/audit/types/externalAnalyzer.js.map +1 -1
  129. package/dist/audit/types/flowCoverage.d.ts +0 -1
  130. package/dist/audit/types/flowCoverage.d.ts.map +1 -1
  131. package/dist/audit/types/flowCoverage.js.map +1 -1
  132. package/dist/audit/types/reviewPlanning.d.ts +0 -1
  133. package/dist/audit/types/reviewPlanning.d.ts.map +1 -1
  134. package/dist/audit/types/reviewPlanning.js.map +1 -1
  135. package/dist/audit/types/runtimeValidation.d.ts +0 -5
  136. package/dist/audit/types/runtimeValidation.d.ts.map +1 -1
  137. package/dist/audit/types/runtimeValidation.js +0 -3
  138. package/dist/audit/types/runtimeValidation.js.map +1 -1
  139. package/dist/audit/types.d.ts +0 -6
  140. package/dist/audit/types.d.ts.map +1 -1
  141. package/dist/audit/types.js +0 -5
  142. package/dist/audit/types.js.map +1 -1
  143. package/dist/audit/validation/anchorGrounding.d.ts +1 -3
  144. package/dist/audit/validation/anchorGrounding.d.ts.map +1 -1
  145. package/dist/audit/validation/anchorGrounding.js.map +1 -1
  146. package/dist/audit/validation/auditResults.d.ts +16 -0
  147. package/dist/audit/validation/auditResults.d.ts.map +1 -1
  148. package/dist/audit/validation/auditResults.js +35 -1
  149. package/dist/audit/validation/auditResults.js.map +1 -1
  150. package/dist/remediate/contractPipeline/changeClassification.d.ts +0 -15
  151. package/dist/remediate/contractPipeline/changeClassification.d.ts.map +1 -1
  152. package/dist/remediate/contractPipeline/changeClassification.js +0 -24
  153. package/dist/remediate/contractPipeline/changeClassification.js.map +1 -1
  154. package/dist/remediate/contractPipeline/phaseCutArtifact.d.ts +0 -2
  155. package/dist/remediate/contractPipeline/phaseCutArtifact.d.ts.map +1 -1
  156. package/dist/remediate/contractPipeline/phaseCutArtifact.js +0 -4
  157. package/dist/remediate/contractPipeline/phaseCutArtifact.js.map +1 -1
  158. package/dist/remediate/dispatch/ownershipScheduler.d.ts +0 -20
  159. package/dist/remediate/dispatch/ownershipScheduler.d.ts.map +1 -1
  160. package/dist/remediate/dispatch/ownershipScheduler.js +0 -24
  161. package/dist/remediate/dispatch/ownershipScheduler.js.map +1 -1
  162. package/dist/remediate/intake.d.ts +0 -37
  163. package/dist/remediate/intake.d.ts.map +1 -1
  164. package/dist/remediate/intake.js +1 -89
  165. package/dist/remediate/intake.js.map +1 -1
  166. package/dist/remediate/phases/close.d.ts.map +1 -1
  167. package/dist/remediate/phases/close.js +16 -6
  168. package/dist/remediate/phases/close.js.map +1 -1
  169. package/dist/remediate/providers/index.d.ts +0 -32
  170. package/dist/remediate/providers/index.d.ts.map +1 -1
  171. package/dist/remediate/providers/index.js +1 -28
  172. package/dist/remediate/providers/index.js.map +1 -1
  173. package/dist/remediate/review/reviewGate.d.ts +0 -1
  174. package/dist/remediate/review/reviewGate.d.ts.map +1 -1
  175. package/dist/remediate/review/reviewGate.js +0 -1
  176. package/dist/remediate/review/reviewGate.js.map +1 -1
  177. package/dist/remediate/riskSignal.d.ts +0 -2
  178. package/dist/remediate/riskSignal.d.ts.map +1 -1
  179. package/dist/remediate/riskSignal.js +0 -4
  180. package/dist/remediate/riskSignal.js.map +1 -1
  181. package/dist/remediate/state/types.d.ts +0 -2
  182. package/dist/remediate/state/types.d.ts.map +1 -1
  183. package/dist/remediate/state/types.js.map +1 -1
  184. package/dist/remediate/steps/contractPipeline.d.ts +4 -1
  185. package/dist/remediate/steps/contractPipeline.d.ts.map +1 -1
  186. package/dist/remediate/steps/contractPipeline.js +63 -47
  187. package/dist/remediate/steps/contractPipeline.js.map +1 -1
  188. package/dist/remediate/steps/contractPipelinePrompts.d.ts +12 -3
  189. package/dist/remediate/steps/contractPipelinePrompts.d.ts.map +1 -1
  190. package/dist/remediate/steps/contractPipelinePrompts.js +29 -22
  191. package/dist/remediate/steps/contractPipelinePrompts.js.map +1 -1
  192. package/dist/remediate/steps/dispatch.d.ts +29 -16
  193. package/dist/remediate/steps/dispatch.d.ts.map +1 -1
  194. package/dist/remediate/steps/dispatch.js +193 -152
  195. package/dist/remediate/steps/dispatch.js.map +1 -1
  196. package/dist/remediate/steps/finalGate.d.ts +88 -0
  197. package/dist/remediate/steps/finalGate.d.ts.map +1 -0
  198. package/dist/remediate/steps/finalGate.js +171 -0
  199. package/dist/remediate/steps/finalGate.js.map +1 -0
  200. package/dist/remediate/steps/leanFastPath.d.ts +0 -8
  201. package/dist/remediate/steps/leanFastPath.d.ts.map +1 -1
  202. package/dist/remediate/steps/leanFastPath.js +12 -0
  203. package/dist/remediate/steps/leanFastPath.js.map +1 -1
  204. package/dist/remediate/steps/nextStep.d.ts +12 -82
  205. package/dist/remediate/steps/nextStep.d.ts.map +1 -1
  206. package/dist/remediate/steps/nextStep.js +71 -167
  207. package/dist/remediate/steps/nextStep.js.map +1 -1
  208. package/dist/remediate/steps/providerNodeDispatch.js +2 -2
  209. package/dist/remediate/steps/providerNodeDispatch.js.map +1 -1
  210. package/dist/remediate/steps/stepWriter.d.ts +0 -4
  211. package/dist/remediate/steps/stepWriter.d.ts.map +1 -1
  212. package/dist/remediate/steps/stepWriter.js +1 -11
  213. package/dist/remediate/steps/stepWriter.js.map +1 -1
  214. package/dist/remediate/types/workerSession.d.ts +0 -1
  215. package/dist/remediate/types/workerSession.d.ts.map +1 -1
  216. package/dist/remediate/types/workerSession.js +0 -8
  217. package/dist/remediate/types/workerSession.js.map +1 -1
  218. package/dist/remediate/validation/contractPipeline.d.ts +0 -1
  219. package/dist/remediate/validation/contractPipeline.d.ts.map +1 -1
  220. package/dist/remediate/validation/contractPipeline.js +18 -27
  221. package/dist/remediate/validation/contractPipeline.js.map +1 -1
  222. package/dist/shared/dispatch/rollingDispatch.d.ts +25 -0
  223. package/dist/shared/dispatch/rollingDispatch.d.ts.map +1 -1
  224. package/dist/shared/dispatch/rollingDispatch.js +6 -1
  225. package/dist/shared/dispatch/rollingDispatch.js.map +1 -1
  226. package/dist/shared/index.d.ts +1 -0
  227. package/dist/shared/index.d.ts.map +1 -1
  228. package/dist/shared/index.js +1 -0
  229. package/dist/shared/index.js.map +1 -1
  230. package/dist/shared/io/frictionCapture.d.ts +14 -1
  231. package/dist/shared/io/frictionCapture.d.ts.map +1 -1
  232. package/dist/shared/io/frictionCapture.js +28 -3
  233. package/dist/shared/io/frictionCapture.js.map +1 -1
  234. package/dist/shared/observability/runLog.d.ts +1 -1
  235. package/dist/shared/observability/runLog.d.ts.map +1 -1
  236. package/dist/shared/observability/runLog.js.map +1 -1
  237. package/dist/shared/providers/providerConfirmation.d.ts +16 -1
  238. package/dist/shared/providers/providerConfirmation.d.ts.map +1 -1
  239. package/dist/shared/providers/providerConfirmation.js +13 -13
  240. package/dist/shared/providers/providerConfirmation.js.map +1 -1
  241. package/dist/shared/providers/providerFactory.d.ts.map +1 -1
  242. package/dist/shared/providers/providerFactory.js +10 -14
  243. package/dist/shared/providers/providerFactory.js.map +1 -1
  244. package/dist/shared/providers/providerPathGuard.d.ts +21 -0
  245. package/dist/shared/providers/providerPathGuard.d.ts.map +1 -0
  246. package/dist/shared/providers/providerPathGuard.js +69 -0
  247. package/dist/shared/providers/providerPathGuard.js.map +1 -0
  248. package/dist/shared/providers/sharedProviderConfirmation.d.ts +14 -2
  249. package/dist/shared/providers/sharedProviderConfirmation.d.ts.map +1 -1
  250. package/dist/shared/providers/sharedProviderConfirmation.js +26 -5
  251. package/dist/shared/providers/sharedProviderConfirmation.js.map +1 -1
  252. package/dist/shared/quota/apiPool.d.ts +6 -1
  253. package/dist/shared/quota/apiPool.d.ts.map +1 -1
  254. package/dist/shared/quota/apiPool.js +13 -2
  255. package/dist/shared/quota/apiPool.js.map +1 -1
  256. package/dist/shared/quota/fileLock.d.ts +17 -2
  257. package/dist/shared/quota/fileLock.d.ts.map +1 -1
  258. package/dist/shared/quota/fileLock.js +21 -19
  259. package/dist/shared/quota/fileLock.js.map +1 -1
  260. package/dist/shared/types/providerConfirmation.d.ts +9 -0
  261. package/dist/shared/types/providerConfirmation.d.ts.map +1 -1
  262. package/package.json +4 -2
  263. package/scripts/audit/postinstall.mjs +22 -14
@@ -2,7 +2,7 @@ import { existsSync } from "node:fs";
2
2
  import { mkdir, readFile, rename } from "node:fs/promises";
3
3
  import { dirname, join, resolve } from "node:path";
4
4
  import { StateStore } from "../state/store.js";
5
- import { readOptionalJsonFile, writeJsonFile, writeTextFile, buildAuditDeliverablePair, formatValidationIssues, isRecord, withFsRetry, RunLogger, DISPATCH_PROMPT_HANDOFF_NOTE, renderQuotaCoverageNudge, coerceJsonObjectArg, createRollingDispatcher, setQuotaStateDir, interpretFreeFormIntent, advance, decideFrictionTriage, buildFrictionTriageBlock, planHybridDispatch, readSettledPools, addSettledPool, sourceByPoolId, classifyProvider, selectDispatchDriver, renderDispatchDriverInstruction } from "audit-tools/shared";
5
+ import { readOptionalJsonFile, writeJsonFile, writeTextFile, buildAuditDeliverablePair, formatValidationIssues, isRecord, withFsRetry, RunLogger, DISPATCH_PROMPT_HANDOFF_NOTE, renderQuotaCoverageNudge, coerceJsonObjectArg, createRollingDispatcher, setQuotaStateDir, interpretFreeFormIntent, advance, decideFrictionTriage, buildFrictionTriageBlock, planHybridDispatch, readSettledPools, addSettledPool, sourceByPoolId, classifyProvider, selectDispatchDriver, renderDispatchDriverInstruction, HostSessionQuotaSource, buildProviderModelKey, captureStepBoundaryFriction, LENSES, SEVERITIES } from "audit-tools/shared";
6
6
  import { applyPlanPipeline, buildCoverageLedger } from "../phases/plan.js";
7
7
  import { groundExtractedFindings } from "../phases/grounding.js";
8
8
  import { runTriagePhase } from "../phases/triage.js";
@@ -14,12 +14,11 @@ import { ownershipSubWaves } from "../dispatch/ownershipScheduler.js";
14
14
  import { prepareHostRollingDispatch, nodeClaimRegistry, nodeSettledPoolsPath } from "./rollingSession.js";
15
15
  import { writeCurrentStep } from "./stepWriter.js";
16
16
  import { dependencyVerifiedComplete } from "./stepUtils.js";
17
- import { isTerminalStatus, isVerifiedCompleteStatus, isSkipStatus, } from "../state/itemStatus.js";
17
+ import { isTerminalStatus, isVerifiedCompleteStatus, } from "../state/itemStatus.js";
18
18
  import { deduplicateCrossLensFindings, fixupBlocksAfterDedup, } from "../dedup/crossLensDedup.js";
19
19
  import { checkAffectedFileIntegrity } from "../utils/fileIntegrity.js";
20
20
  import { resolveIntakeStep } from "./intakeResolver.js";
21
- import { runCommand } from "../utils/commands.js";
22
- import { isAuditToolsMonorepo, toolOwnedFinalGateCommands, } from "./gateCommands.js";
21
+ import { runToolOwnedFinalGate, applyCoarseReblock, readFinalGateSidecar, writeFinalGateSidecar, } from "./finalGate.js";
23
22
  import { buildNextContractPipelineStep, shouldEnterContractPipeline, writePathASeedFromFindings, } from "./contractPipeline.js";
24
23
  import { evaluateFastPath, buildLeanExtractedPlan, distinctAffectedFiles, interpretLeanLightReviewVerdict, LEAN_LIGHT_REVIEW_SCHEMA_VERSION, } from "./leanFastPath.js";
25
24
  import { contractArtifactExists, contractPipelineDir, } from "../contractPipeline/artifactStore.js";
@@ -29,6 +28,26 @@ import { runFindingFilterPass } from "../findingFilter.js";
29
28
  import { intakePaths, isIntakeReady, readIntakeArtifacts, resolveManifestSources, } from "../intake.js";
30
29
  import { ensureIntakeRiskSignal, readIntakeRiskSignal, writeIntakeRiskSignal, escalateRiskSignal, } from "../riskSignal.js";
31
30
  import { ambiguityReviewPrompt, clarificationPrompt, collectIntakeClarificationsPrompt, collectStartingPointPrompt, loaderCommand, reviewApprovalPrompt, synthesizeIntakePrompt, triagePrompt, } from "./prompts.js";
31
+ // Single-sourced prose renders of the canonical lens / severity vocabularies
32
+ // (`audit-tools/shared` `LENSES` / `SEVERITIES`) for the intent-checkpoint
33
+ // prompt copy. Previously these 11-lens / 5-severity lists were hand-copied as
34
+ // backtick-quoted literals in three places in this file and would silently drift
35
+ // from the canonical enum (the very drift `types/lens.ts` exists to prevent).
36
+ const VALID_LENSES_PROSE = LENSES.map((lens) => `\`${lens}\``).join(", ");
37
+ const VALID_SEVERITIES_PROSE = SEVERITIES.map((sev) => `\`${sev}\``).join(", ");
38
+ /**
39
+ * The host's resolved provider identity for quota-key / driver-classification
40
+ * purposes: the configured `sessionConfig.provider`, defaulting to the
41
+ * conversation host (`claude-code`) when unset or `auto`. Single-sourced so the
42
+ * `?? "claude-code"` default and the `auto`-exclusion live in ONE place rather
43
+ * than being re-spelled (with an ad-hoc cast) at each dispatch call site.
44
+ */
45
+ function resolveHostProviderName(sessionConfig) {
46
+ const provider = sessionConfig?.provider;
47
+ if (provider === undefined || provider === "auto")
48
+ return "claude-code";
49
+ return provider;
50
+ }
32
51
  export function resolveHostDispatchCapability(options) {
33
52
  if (options.hostCanDispatchSubagents !== undefined) {
34
53
  return options.hostCanDispatchSubagents;
@@ -478,6 +497,7 @@ export async function driveRollingDispatch(levels, options) {
478
497
  estimatedTokens: estimateTokens(blockByPacketId.get(node.block_id)),
479
498
  complexity: 0.5,
480
499
  }));
500
+ const hostSession = options.hostSession;
481
501
  const dispatcher = createRollingDispatcher({
482
502
  confirmedPools: options.confirmedPools,
483
503
  sessionConfig: options.sessionConfig,
@@ -485,6 +505,15 @@ export async function driveRollingDispatch(levels, options) {
485
505
  const block = blockByPacketId.get(packet.payload.block_id);
486
506
  return options.dispatchNode(block, slot);
487
507
  },
508
+ // Host-session escalation: feed recordLimit (write) at the rate_limited
509
+ // observation point and read isEscalated (strand-not-requeue). The SAME
510
+ // instance sized the pools, so the bounded re-limit count is account-wide.
511
+ ...(hostSession
512
+ ? {
513
+ recordRateLimit: (packet, result) => hostSession.recordLimit(result.rateLimit?.channel ?? "error", result.rateLimit?.text ?? "", packet.id),
514
+ isPacketEscalated: (packetId) => hostSession.isEscalated(packetId),
515
+ }
516
+ : {}),
488
517
  });
489
518
  dispatcher.enqueue(packets);
490
519
  levelResults.push(...(await dispatcher.run()));
@@ -583,6 +612,30 @@ export async function driveRollingImplementDispatch(options) {
583
612
  const promptPathByBlock = new Map(plan.items
584
613
  .filter((i) => typeof i.block_id === "string")
585
614
  .map((i) => [i.block_id, i.prompt_path]));
615
+ // The RETAINED host-session source: threaded through pool sizing AND the
616
+ // dispatcher's escalation hooks so the bounded re-limit chain (recordLimit →
617
+ // escalate → strand → quota_escalation friction) is fed end-to-end. Its
618
+ // onEscalation routes to the single step-boundary friction chokepoint with this
619
+ // driver's artifactsDir/runId, so a bounded account-wall escalation surfaces as
620
+ // reviewable friction instead of only a stderr line.
621
+ const providerName = resolveHostProviderName(options.sessionConfig);
622
+ const hostSessionModelKey = buildProviderModelKey(providerName, options.sessionConfig
623
+ ?.block_quota?.host_model ??
624
+ options.waveOptions?.hostModelId ??
625
+ null);
626
+ const hostSession = new HostSessionQuotaSource({
627
+ providerModelKey: hostSessionModelKey,
628
+ onEscalation: (escalation) => {
629
+ void captureStepBoundaryFriction(artifactsDir, runId, {
630
+ eventType: "quota_escalation",
631
+ discriminator: escalation.packet_id,
632
+ note: escalation.reason,
633
+ severity: "high",
634
+ category: "trap",
635
+ area: "dispatch/quota",
636
+ }, "remediate-code");
637
+ },
638
+ });
586
639
  // Confirmed pools: quota-derived concurrency, never the raw host flag (INV-QD-11).
587
640
  const confirmedPools = await buildConfirmedPools({
588
641
  sessionConfig: options.sessionConfig,
@@ -591,6 +644,7 @@ export async function driveRollingImplementDispatch(options) {
591
644
  hostOutputTokens: options.waveOptions?.hostOutputTokens,
592
645
  hostModels: options.waveOptions?.hostModels,
593
646
  hostModelId: options.waveOptions?.hostModelId,
647
+ hostSession,
594
648
  });
595
649
  // The live per-node worker: the configured provider, launched with the node's
596
650
  // worktree-rooted prompt and cwd = its worktree. Tests inject `options.dispatchNode`
@@ -687,6 +741,7 @@ export async function driveRollingImplementDispatch(options) {
687
741
  rebuildSharedBetweenLevels: options.rebuildSharedBetweenLevels,
688
742
  quotaStateDir: artifactsDir,
689
743
  root,
744
+ hostSession,
690
745
  scopeForBlock: (block) => writePathsByBlock.get(block.block_id) ?? block.touched_files ?? [],
691
746
  });
692
747
  // Deterministic merge: same path the wave flow uses (tolerant remap, write-scope
@@ -784,161 +839,13 @@ export async function executeInProcessPartition(params) {
784
839
  // Tool-owned final completion gate (INV-RS-10) + coarse re-block (INV-RS-09)
785
840
  // ---------------------------------------------------------------------------
786
841
  //
787
- // INV-RS-10: the final completion gate is a TOOL-OWNED, NON-VACUOUS suite that
788
- // is INDEPENDENT of any `plan.test_command`. A run can only land green when this
789
- // suite passes; a vacuous/unset `plan.test_command` can never substitute for it.
790
- // The suite is executed through the env-scrubbing `runTracked` path
791
- // (`runCommand`), which strips CLAUDECODE / CLAUDE_CODE_* so the gate runs in a
792
- // clean environment regardless of the host session.
793
- //
794
- // Hard floor (always run, in order — single package, single-flight build — CE-001):
795
- // 1. npm run build (one tsc build for the whole package)
796
- // 2. npm run check (typecheck, no emit)
797
- // 3. BUILD-FREE unit suites at the repo root, each invoked directly so dist is
798
- // never rebuilt or raced:
799
- // - shared+audit: node --import tsx/esm --test tests/shared/*.test.mjs tests/audit/*.test.mjs
800
- // - remediate-code: npx vitest run
801
- //
802
- // CE-002: the hard floor is scoped to build + typecheck + unit. The
803
- // runtime/packaged-bin smoke surface (the `verify:release` smokes) is recorded
804
- // as a DECLARED RESIDUAL the floor does not gate, rather than run inline — the
805
- // packaged-bin smokes are the known Windows-flaky / EPERM surface and an in-loop
806
- // gate must converge deterministically, so they are surfaced for a separate
807
- // pass instead of being able to strand the run.
808
- // `FinalGateCommandSpec`, `isAuditToolsMonorepo`, and `toolOwnedFinalGateCommands`
809
- // are single-sourced in the leaf module `gateCommands.ts` (so `dispatch.ts` can
810
- // derive the same pinned merged-base check without an import cycle). Imported above
811
- // for local use here and re-exported to preserve this module's public surface +
812
- // test imports.
813
- export { isAuditToolsMonorepo, toolOwnedFinalGateCommands };
814
- /**
815
- * Run the tool-owned final gate (INV-RS-10). Each command runs through
816
- * `runCommand` → shared `runTracked`, which scrubs CLAUDECODE / CLAUDE_CODE_*.
817
- * The first failing command short-circuits the floor (a broken build makes the
818
- * later layers meaningless). A `runner` may be injected for tests. When the
819
- * audit-tools suite does not apply (non-monorepo target), the gate is
820
- * `scoped_out` (does not block) rather than vacuously passing.
821
- */
822
- export async function runToolOwnedFinalGate(root, opts = {}) {
823
- const runtime_residual = {
824
- surface: "runtime/packaged-bin smokes (verify:release)",
825
- commands: [
826
- "npm run smoke:packaged-audit-code",
827
- "npm run smoke:packaged-remediate-code",
828
- ],
829
- };
830
- const commands = toolOwnedFinalGateCommands(root);
831
- if (commands.length === 0) {
832
- // Audit-tools-specific suite does not apply here — declared scope, not a
833
- // vacuous pass (it never substitutes for a real gate on the audit-tools repo).
834
- return { passed: true, results: [], scoped_out: true, runtime_residual };
835
- }
836
- const runner = opts.runner ??
837
- ((argv, cwd, packageDir) => {
838
- const [command, ...args] = argv;
839
- // Package-scoped unit suites run with cwd at the package (no `npm -w`); the
840
- // monorepo-root build/check commands run at the repo root.
841
- const effectiveCwd = packageDir ? join(root, packageDir) : cwd;
842
- // runCommand → runTracked strips CLAUDECODE / CLAUDE_CODE_* (INV-RS-10).
843
- const result = runCommand(command, args, {
844
- cwd: effectiveCwd,
845
- stdio: ["ignore", "pipe", "pipe"],
846
- });
847
- return { status: result.status };
848
- });
849
- const results = [];
850
- let passed = true;
851
- for (const spec of commands) {
852
- const { status } = runner(spec.argv, root, spec.package_dir);
853
- const cmdPassed = status === 0;
854
- results.push({
855
- argv: spec.argv,
856
- layer: spec.layer,
857
- ...(spec.package_dir ? { package_dir: spec.package_dir } : {}),
858
- exit_code: status,
859
- passed: cmdPassed,
860
- });
861
- if (!cmdPassed) {
862
- passed = false;
863
- break; // short-circuit: later layers are meaningless on a broken floor
864
- }
865
- }
866
- return { passed, results, scoped_out: false, runtime_residual };
867
- }
868
- /**
869
- * The bound on coarse re-block iterations before the run converges to a terminal
870
- * `blocked` close (CE-003). Two re-block attempts give a flaky-but-recoverable
871
- * suite a chance to settle; the third unattributable red terminates
872
- * deterministically rather than livelocking.
873
- */
874
- export const COARSE_REBLOCK_BOUND = 2;
875
- const FINAL_GATE_STATE_FILENAME = "final-gate.json";
876
- async function readFinalGateSidecar(artifactsDir) {
877
- const sidecar = await readOptionalJsonFile(join(artifactsDir, FINAL_GATE_STATE_FILENAME));
878
- const n = sidecar?.coarse_reblock_count;
879
- return {
880
- count: typeof n === "number" && Number.isFinite(n) && n >= 0 ? n : 0,
881
- terminated: sidecar?.terminated === true,
882
- };
883
- }
884
- async function writeFinalGateSidecar(artifactsDir, count, terminated) {
885
- await writeJsonFile(join(artifactsDir, FINAL_GATE_STATE_FILENAME), {
886
- schema_version: "remediate-code-final-gate/v1alpha1",
887
- coarse_reblock_count: count,
888
- terminated,
889
- });
890
- }
891
- /**
892
- * Coarse re-block-ALL-non-terminal on an unattributable final-gate red
893
- * (INV-RS-09) with a bounded, monotonic auto-terminate (CE-003).
894
- *
895
- * The tool-owned gate is whole-repo, so a red is inherently unattributable to a
896
- * single node. Below the bound, EVERY non-skip item (including `resolved` ones —
897
- * a resolved item's own change may have caused the red) is re-opened to `pending`
898
- * and the run re-attempts the whole repo through the rolling scheduler
899
- * (`reattempt_all` → `implementing`). At or above the bound, the run STOPS
900
- * re-attempting and converges DETERMINISTICALLY: every non-skip item becomes
901
- * terminal `blocked` and the run advances to `closing`.
902
- *
903
- * CE-003 no-human-host guarantee: the loop is owned entirely by the gate + the
904
- * rolling scheduler — it NEVER routes through the human triage prompt
905
- * (`waiting_for_triage`) and is bounded by `bound`, so a permanently-red sibling
906
- * converges to a terminal `blocked` close deterministically: never livelocking,
907
- * never stranding on a human prompt, and never force-closed to green (a RED gate
908
- * always leaves `blocked` items, so close.ts's `!anyBlocked` guard keeps the run
909
- * out of the fully-green path). User SKIP dispositions (ignored /
910
- * deemed_inappropriate) are settled decisions and are left alone. Pure (the
911
- * counter is supplied / returned).
912
- */
913
- export function applyCoarseReblock(state, currentCount, gateSummary, bound = COARSE_REBLOCK_BOUND) {
914
- const now = new Date().toISOString();
915
- if (currentCount >= bound) {
916
- // Bounded auto-terminate: converge DETERMINISTICALLY to a terminal `blocked`
917
- // close for a no-human host — never livelock, never a triage prompt, never green.
918
- for (const it of Object.values(state.items ?? {})) {
919
- if (isSkipStatus(it.status))
920
- continue; // settled user decision — never overturn
921
- it.status = "blocked";
922
- it.started_at ??= now;
923
- it.completed_at = now;
924
- it.failure_reason =
925
- `Tool-owned final gate failed and the coarse re-block backstop reached its ` +
926
- `bound (${bound}); converging to a terminal blocked close (no-human host). ${gateSummary}`;
927
- }
928
- return { state, action: "terminal_blocked", next_count: currentCount };
929
- }
930
- // Below the bound: re-open every non-skip item to `pending` and re-attempt the
931
- // whole repo via the rolling scheduler (NOT the human triage prompt).
932
- for (const it of Object.values(state.items ?? {})) {
933
- if (isSkipStatus(it.status))
934
- continue;
935
- it.status = "pending";
936
- it.failure_context =
937
- `Re-attempted by the coarse final-gate backstop (unattributable whole-repo red). ${gateSummary}`;
938
- delete it.completed_at;
939
- }
940
- return { state, action: "reattempt_all", next_count: currentCount + 1 };
941
- }
842
+ // The gate runner, its bounded coarse-reblock backstop, and the sidecar counter
843
+ // I/O were extracted behaviour-preservingly into the sibling leaf module
844
+ // `finalGate.ts` (CP-NODE-1). They are imported below for local use in the
845
+ // completion handler and re-exported to preserve this module's public surface +
846
+ // existing test imports. See `finalGate.ts` for the INV-RS-10 / CE-001 / CE-002
847
+ // documentation.
848
+ export { isAuditToolsMonorepo, toolOwnedFinalGateCommands, runToolOwnedFinalGate, applyCoarseReblock, COARSE_REBLOCK_BOUND, } from "./finalGate.js";
942
849
  function resolvedOrTerminalItems(state) {
943
850
  return Object.values(state.items ?? {}).filter((item) => isTerminalStatus(item.status));
944
851
  }
@@ -1341,8 +1248,7 @@ async function buildImplementDispatchStep(ctx) {
1341
1248
  // S-BROKER-WIRING: pick the dispatch DRIVER (delegate the rolling loop to a
1342
1249
  // dedicated dispatcher subagent vs. drive it from the top host) off the
1343
1250
  // single classification + the live frontier/slot count — not host prose.
1344
- const hostProvider = sessionConfigImpl?.provider ??
1345
- "claude-code";
1251
+ const hostProvider = resolveHostProviderName(sessionConfigImpl);
1346
1252
  const driverSelection = selectDispatchDriver({
1347
1253
  classification: classifyProvider(hostProvider),
1348
1254
  eligibleItemCount: rolling.session.frontier.length,
@@ -2179,7 +2085,7 @@ Choose one explicitly and report the choice to the user:
2179
2085
  1. **Resume the existing run** — re-run WITHOUT \`--input\`: \`${loaderCommand("next-step")}\`
2180
2086
  2. **Start fresh from the new input** — first move aside or delete the existing
2181
2087
  \`${artifactsDir}\` directory (and the stale \`remediation-report.md\` /
2182
- \`remediation-report.json\` in \`.audit-tools/\`, which would otherwise be overwritten on completion),
2088
+ \`remediation-outcomes.json\` in \`.audit-tools/\`, which would otherwise be overwritten on completion),
2183
2089
  then re-run \`${loaderCommand("next-step --input <path>")}\`.
2184
2090
 
2185
2091
  Stop after presenting this choice. Do not advance the run until the user decides.
@@ -2984,10 +2890,8 @@ To confirm, write the final checkpoint to:
2984
2890
  \`\`\`
2985
2891
 
2986
2892
  Adjust \`filters\`, \`excluded_scope\`, \`must_not_touch\`, or \`free_form_intent\` to
2987
- narrow scope. Valid severities: \`critical\`, \`high\`, \`medium\`, \`low\`, \`info\`.
2988
- Valid lenses: \`correctness\`, \`architecture\`, \`maintainability\`, \`security\`,
2989
- \`reliability\`, \`performance\`, \`data_integrity\`, \`tests\`, \`operability\`,
2990
- \`config_deployment\`, \`observability\`.
2893
+ narrow scope. Valid severities: ${VALID_SEVERITIES_PROSE}.
2894
+ Valid lenses: ${VALID_LENSES_PROSE}.
2991
2895
 
2992
2896
  Once written with \`"confirmed_by": "host"\`, run:
2993
2897
 
@@ -3024,7 +2928,7 @@ Only \`scope_summary\` and \`intent_summary\` are required; add the optional fie
3024
2928
  }
3025
2929
  \`\`\`
3026
2930
 
3027
- - \`filters\` drop findings that don't match BEFORE planning, so only the work you want is remediated. Valid severities: \`critical\`, \`high\`, \`medium\`, \`low\`, \`info\`. Valid lenses: \`correctness\`, \`architecture\`, \`maintainability\`, \`security\`, \`reliability\`, \`performance\`, \`data_integrity\`, \`tests\`, \`operability\`, \`config_deployment\`, \`observability\`. Draw \`packages\`/\`themes\` from the findings in the audit report.
2931
+ - \`filters\` drop findings that don't match BEFORE planning, so only the work you want is remediated. Valid severities: ${VALID_SEVERITIES_PROSE}. Valid lenses: ${VALID_LENSES_PROSE}. Draw \`packages\`/\`themes\` from the findings in the audit report.
3028
2932
  - \`excluded_scope\` drops findings whose files match a path or directory prefix; \`must_not_touch\` globs are never written.
3029
2933
  - Skipped findings are listed in the final remediation report under "Skipped by Intent Checkpoint".
3030
2934
  - Leave the optional fields out to remediate everything in the report.