audit-tools 0.36.0 → 0.36.2

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 (147) hide show
  1. package/dispatch/artifacts-dir.mjs +14 -0
  2. package/dispatch/merge-results.mjs +3 -5
  3. package/dispatch/validate-result.mjs +3 -5
  4. package/dist/audit/cli/cliHelpers.d.ts +18 -0
  5. package/dist/audit/cli/cliHelpers.d.ts.map +1 -0
  6. package/dist/audit/cli/cliHelpers.js +20 -0
  7. package/dist/audit/cli/cliHelpers.js.map +1 -0
  8. package/dist/audit/cli/conceptualDispatch.d.ts +11 -1
  9. package/dist/audit/cli/conceptualDispatch.d.ts.map +1 -1
  10. package/dist/audit/cli/conceptualDispatch.js +3 -1
  11. package/dist/audit/cli/conceptualDispatch.js.map +1 -1
  12. package/dist/audit/cli/dispatch/packetFilter.d.ts.map +1 -1
  13. package/dist/audit/cli/dispatch/packetFilter.js +2 -1
  14. package/dist/audit/cli/dispatch/packetFilter.js.map +1 -1
  15. package/dist/audit/cli/dispatch.d.ts.map +1 -1
  16. package/dist/audit/cli/dispatch.js +2 -1
  17. package/dist/audit/cli/dispatch.js.map +1 -1
  18. package/dist/audit/cli/mergeAndIngestCommand.d.ts.map +1 -1
  19. package/dist/audit/cli/mergeAndIngestCommand.js +24 -1
  20. package/dist/audit/cli/mergeAndIngestCommand.js.map +1 -1
  21. package/dist/audit/cli/nextStepHelpers.d.ts +22 -6
  22. package/dist/audit/cli/nextStepHelpers.d.ts.map +1 -1
  23. package/dist/audit/cli/nextStepHelpers.js +65 -26
  24. package/dist/audit/cli/nextStepHelpers.js.map +1 -1
  25. package/dist/audit/cli/quotaCommand.d.ts.map +1 -1
  26. package/dist/audit/cli/quotaCommand.js +3 -2
  27. package/dist/audit/cli/quotaCommand.js.map +1 -1
  28. package/dist/audit/cli/requeueCommand.d.ts.map +1 -1
  29. package/dist/audit/cli/requeueCommand.js +3 -2
  30. package/dist/audit/cli/requeueCommand.js.map +1 -1
  31. package/dist/audit/cli/resynthesizeCommand.d.ts.map +1 -1
  32. package/dist/audit/cli/resynthesizeCommand.js +3 -2
  33. package/dist/audit/cli/resynthesizeCommand.js.map +1 -1
  34. package/dist/audit/cli/sampleRunCommand.d.ts.map +1 -1
  35. package/dist/audit/cli/sampleRunCommand.js +2 -1
  36. package/dist/audit/cli/sampleRunCommand.js.map +1 -1
  37. package/dist/audit/cli/statusCommand.d.ts.map +1 -1
  38. package/dist/audit/cli/statusCommand.js +4 -3
  39. package/dist/audit/cli/statusCommand.js.map +1 -1
  40. package/dist/audit/cli/submitPacketCommand.d.ts.map +1 -1
  41. package/dist/audit/cli/submitPacketCommand.js +4 -3
  42. package/dist/audit/cli/submitPacketCommand.js.map +1 -1
  43. package/dist/audit/cli/synthesizeCommand.d.ts.map +1 -1
  44. package/dist/audit/cli/synthesizeCommand.js +3 -2
  45. package/dist/audit/cli/synthesizeCommand.js.map +1 -1
  46. package/dist/audit/cli/updateRuntimeValidationCommand.d.ts.map +1 -1
  47. package/dist/audit/cli/updateRuntimeValidationCommand.js +3 -2
  48. package/dist/audit/cli/updateRuntimeValidationCommand.js.map +1 -1
  49. package/dist/audit/decompose/findings.d.ts.map +1 -1
  50. package/dist/audit/decompose/findings.js +37 -55
  51. package/dist/audit/decompose/findings.js.map +1 -1
  52. package/dist/audit/io/artifacts.d.ts.map +1 -1
  53. package/dist/audit/io/artifacts.js +12 -2
  54. package/dist/audit/io/artifacts.js.map +1 -1
  55. package/dist/audit/orchestrator/designReviewPrompt.d.ts.map +1 -1
  56. package/dist/audit/orchestrator/designReviewPrompt.js +18 -21
  57. package/dist/audit/orchestrator/designReviewPrompt.js.map +1 -1
  58. package/dist/audit/orchestrator/intakeExecutors.d.ts.map +1 -1
  59. package/dist/audit/orchestrator/intakeExecutors.js +30 -23
  60. package/dist/audit/orchestrator/intakeExecutors.js.map +1 -1
  61. package/dist/audit/orchestrator/requeueCommand.d.ts +3 -0
  62. package/dist/audit/orchestrator/requeueCommand.d.ts.map +1 -1
  63. package/dist/audit/orchestrator/requeueCommand.js +1 -1
  64. package/dist/audit/orchestrator/requeueCommand.js.map +1 -1
  65. package/dist/audit/validation/artifacts.d.ts.map +1 -1
  66. package/dist/audit/validation/artifacts.js +12 -13
  67. package/dist/audit/validation/artifacts.js.map +1 -1
  68. package/dist/remediate/contractPipeline/changeClassification.d.ts.map +1 -1
  69. package/dist/remediate/contractPipeline/changeClassification.js +11 -6
  70. package/dist/remediate/contractPipeline/changeClassification.js.map +1 -1
  71. package/dist/remediate/phases/close.d.ts.map +1 -1
  72. package/dist/remediate/phases/close.js +9 -0
  73. package/dist/remediate/phases/close.js.map +1 -1
  74. package/dist/remediate/steps/contractPipelinePrompts.d.ts +2 -0
  75. package/dist/remediate/steps/contractPipelinePrompts.d.ts.map +1 -1
  76. package/dist/remediate/steps/contractPipelinePrompts.js +18 -4
  77. package/dist/remediate/steps/contractPipelinePrompts.js.map +1 -1
  78. package/dist/remediate/steps/dispatch/acceptNode.d.ts +19 -7
  79. package/dist/remediate/steps/dispatch/acceptNode.d.ts.map +1 -1
  80. package/dist/remediate/steps/dispatch/acceptNode.js +66 -16
  81. package/dist/remediate/steps/dispatch/acceptNode.js.map +1 -1
  82. package/dist/remediate/steps/dispatch/common.d.ts +11 -0
  83. package/dist/remediate/steps/dispatch/common.d.ts.map +1 -1
  84. package/dist/remediate/steps/dispatch/common.js +14 -0
  85. package/dist/remediate/steps/dispatch/common.js.map +1 -1
  86. package/dist/remediate/steps/dispatch/implementPrompt.js +2 -2
  87. package/dist/remediate/steps/dispatch/implementPrompt.js.map +1 -1
  88. package/dist/remediate/steps/dispatch/marshal.d.ts +3 -1
  89. package/dist/remediate/steps/dispatch/marshal.d.ts.map +1 -1
  90. package/dist/remediate/steps/dispatch/marshal.js +16 -4
  91. package/dist/remediate/steps/dispatch/marshal.js.map +1 -1
  92. package/dist/remediate/steps/dispatch/verifyCommands.d.ts +18 -5
  93. package/dist/remediate/steps/dispatch/verifyCommands.d.ts.map +1 -1
  94. package/dist/remediate/steps/dispatch/verifyCommands.js +47 -9
  95. package/dist/remediate/steps/dispatch/verifyCommands.js.map +1 -1
  96. package/dist/remediate/steps/dispatch/waveScheduling.d.ts +0 -5
  97. package/dist/remediate/steps/dispatch/waveScheduling.d.ts.map +1 -1
  98. package/dist/remediate/steps/dispatch/waveScheduling.js +0 -7
  99. package/dist/remediate/steps/dispatch/waveScheduling.js.map +1 -1
  100. package/dist/remediate/steps/dispatch/worktreeLifecycle.d.ts.map +1 -1
  101. package/dist/remediate/steps/dispatch/worktreeLifecycle.js +27 -1
  102. package/dist/remediate/steps/dispatch/worktreeLifecycle.js.map +1 -1
  103. package/dist/remediate/steps/dispatch.d.ts +3 -3
  104. package/dist/remediate/steps/dispatch.d.ts.map +1 -1
  105. package/dist/remediate/steps/dispatch.js +3 -3
  106. package/dist/remediate/steps/dispatch.js.map +1 -1
  107. package/dist/remediate/steps/gateCommands.d.ts +8 -6
  108. package/dist/remediate/steps/gateCommands.d.ts.map +1 -1
  109. package/dist/remediate/steps/gateCommands.js +18 -8
  110. package/dist/remediate/steps/gateCommands.js.map +1 -1
  111. package/dist/remediate/steps/nextStep.d.ts +13 -0
  112. package/dist/remediate/steps/nextStep.d.ts.map +1 -1
  113. package/dist/remediate/steps/nextStep.js +93 -22
  114. package/dist/remediate/steps/nextStep.js.map +1 -1
  115. package/dist/remediate/steps/rollingSession.d.ts.map +1 -1
  116. package/dist/remediate/steps/rollingSession.js +64 -8
  117. package/dist/remediate/steps/rollingSession.js.map +1 -1
  118. package/dist/shared/findings/dedupe.d.ts.map +1 -1
  119. package/dist/shared/findings/dedupe.js +45 -23
  120. package/dist/shared/findings/dedupe.js.map +1 -1
  121. package/dist/shared/friction/triage.js +1 -1
  122. package/dist/shared/friction/triage.js.map +1 -1
  123. package/dist/shared/index.d.ts +2 -2
  124. package/dist/shared/index.d.ts.map +1 -1
  125. package/dist/shared/index.js +2 -2
  126. package/dist/shared/index.js.map +1 -1
  127. package/dist/shared/io/frictionCapture.d.ts +20 -0
  128. package/dist/shared/io/frictionCapture.d.ts.map +1 -1
  129. package/dist/shared/io/frictionCapture.js +38 -0
  130. package/dist/shared/io/frictionCapture.js.map +1 -1
  131. package/dist/shared/io/json.d.ts +12 -0
  132. package/dist/shared/io/json.d.ts.map +1 -1
  133. package/dist/shared/io/json.js +19 -1
  134. package/dist/shared/io/json.js.map +1 -1
  135. package/dist/shared/io/nodeWorktreeGuard.js +1 -1
  136. package/dist/shared/io/nodeWorktreeGuard.js.map +1 -1
  137. package/dist/shared/providers/spawnLoggedCommand.js +1 -1
  138. package/dist/shared/providers/spawnLoggedCommand.js.map +1 -1
  139. package/dist/shared/quota/claudeOAuthQuotaSource.js +1 -1
  140. package/dist/shared/quota/claudeOAuthQuotaSource.js.map +1 -1
  141. package/dist/shared/quota/state.d.ts.map +1 -1
  142. package/dist/shared/quota/state.js +34 -15
  143. package/dist/shared/quota/state.js.map +1 -1
  144. package/dist/shared/types/auditorDescriptor.d.ts +2 -2
  145. package/package.json +1 -1
  146. package/wrapper/remediate-code-wrapper-install-hosts.mjs +5 -5
  147. package/wrapper/remediate-code-wrapper-io.mjs +2 -2
@@ -21,7 +21,7 @@ import { groundExtractedFindings } from "../phases/grounding.js";
21
21
  import { runTriagePhase } from "../phases/triage.js";
22
22
  import { runClosePhase } from "../phases/close.js";
23
23
  import { validateRemediationPlan } from "../validation/remediationState.js";
24
- import { mergeImplementResults, prepareImplementDispatch, readExtractedPlanIfPresent, buildConfirmedPools, executeNodeInWorktree, blockScopesFromPlan, targetedCommandsForBlock, } from "./dispatch.js";
24
+ import { mergeImplementResults, prepareImplementDispatch, readExtractedPlanIfPresent, buildConfirmedPools, executeNodeInWorktree, blockScopesFromPlan, targetedCommandsForBlock, readDispatchPlan, } from "./dispatch.js";
25
25
  import { makeProviderNodeDispatcher } from "./providerNodeDispatch.js";
26
26
  import { prepareHostRollingDispatch, nodeClaimRegistry, nodeSettledPoolsPath } from "./rollingSession.js";
27
27
  import { ClaimRegistry } from "../../shared/quota/claimRegistry.js";
@@ -156,6 +156,18 @@ export function detectStructuralRefusalPause(quota) {
156
156
  refusedIds,
157
157
  };
158
158
  }
159
+ /**
160
+ * Read the admission record backing the zero-frontier structural-refusal
161
+ * discriminator. `quotaPath` is null for an ATTENDED host (hostOwnedDispatch —
162
+ * the host owns provider selection/pacing, so NO admission record exists); a
163
+ * null path is the no-signal case, never a crash: no record ⇒ no structural
164
+ * refusal ⇒ the caller folds the empty frontier straight to merge. (v0.36.1
165
+ * zero-frontier crash, accept/reverify cluster defect 5: the call site asserted
166
+ * `quotaPath!` and the read threw on the attended-host null.)
167
+ */
168
+ export async function structuralRefusalForZeroFrontier(quotaPath) {
169
+ return detectStructuralRefusalPause(quotaPath ? await readOptionalJsonFile(quotaPath) : undefined);
170
+ }
159
171
  function randomRunId(prefix = "RUN") {
160
172
  return `${prefix}-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
161
173
  }
@@ -782,36 +794,70 @@ export async function driveRollingImplementDispatch(options) {
782
794
  // or double-merge it; the run-level `mergeImplementResults` reconciles from the
783
795
  // peer's accept outcome.
784
796
  if (!claimTokens.has(block.block_id)) {
785
- const claim = await registry.claim(block.block_id, "in-process");
786
- if (!claim.acquired) {
787
- nodeOutcomes.push({ block_id: block.block_id, outcome: "success", verify_passed: false, merged: false, pool_id: slot.poolId });
797
+ try {
798
+ const claim = await registry.claim(block.block_id, "in-process");
799
+ if (!claim.acquired) {
800
+ nodeOutcomes.push({ block_id: block.block_id, outcome: "success", verify_passed: false, merged: false, pool_id: slot.poolId });
801
+ return {
802
+ packet: { id: block.block_id, payload: { block_id: block.block_id }, estimatedTokens: 0, complexity: 0.5 },
803
+ outcome: "success",
804
+ };
805
+ }
806
+ claimTokens.set(block.block_id, claim.ownerToken);
807
+ }
808
+ catch (err) {
809
+ // Claim acquisition failed — return error outcome without rejecting, per
810
+ // contract. Release is skipped since we never acquired the claim.
811
+ nodeOutcomes.push({ block_id: block.block_id, outcome: "error", verify_passed: false, merged: false, pool_id: slot.poolId });
788
812
  return {
789
813
  packet: { id: block.block_id, payload: { block_id: block.block_id }, estimatedTokens: 0, complexity: 0.5 },
790
- outcome: "success",
814
+ outcome: "error",
815
+ error: err,
791
816
  };
792
817
  }
793
- claimTokens.set(block.block_id, claim.ownerToken);
794
818
  }
795
819
  // The shared per-node worktree lifecycle (reset → create → link node_modules →
796
820
  // seed → dispatch → commit/verify/write-scope/merge → record), identical to the
797
821
  // A-8 hybrid executor and behaviourally to the host-subagent driver's
798
822
  // `accept-node` callback. `touched_files` is the block's authoritative declared
799
823
  // write set (the source the dispatch plan's write scope is derived from).
800
- const { result, accept } = await executeNodeInWorktree({
801
- block,
802
- slot,
803
- root,
804
- artifactsDir,
805
- runId,
806
- resultPath,
807
- seedPaths: block.touched_files,
808
- allBlockScopes,
809
- additionalVerifyCommands: targetedCommandsForBlock(state, block.block_id),
810
- dispatchNode,
811
- // Merge-time ownership gate (OD3 layer 2, D-66/67 slice-1): the SAME lease
812
- // this driver just claimed (or re-claimed on a rate_limited re-queue) above.
813
- ownership: { registry, nodeId: block.block_id, ownerToken: claimTokens.get(block.block_id) },
814
- });
824
+ let result;
825
+ let accept;
826
+ try {
827
+ ({ result, accept } = await executeNodeInWorktree({
828
+ block,
829
+ slot,
830
+ root,
831
+ artifactsDir,
832
+ runId,
833
+ resultPath,
834
+ seedPaths: block.touched_files,
835
+ allBlockScopes,
836
+ additionalVerifyCommands: targetedCommandsForBlock(state, block.block_id),
837
+ dispatchNode,
838
+ // Merge-time ownership gate (OD3 layer 2, D-66/67 slice-1): the SAME lease
839
+ // this driver just claimed (or re-claimed on a rate_limited re-queue) above.
840
+ ownership: { registry, nodeId: block.block_id, ownerToken: claimTokens.get(block.block_id) },
841
+ }));
842
+ }
843
+ catch (err) {
844
+ // Worker execution failed — return error outcome without rejecting, per
845
+ // contract. Release the claim since we must free it on exception to prevent
846
+ // blocking peer drivers.
847
+ try {
848
+ await releaseNodeClaim(registry, claimTokens, block.block_id);
849
+ }
850
+ catch (releaseErr) {
851
+ // Log release failure but don't escalate — node outcome already records the
852
+ // execution error as the primary failure mode.
853
+ }
854
+ nodeOutcomes.push({ block_id: block.block_id, outcome: "error", verify_passed: false, merged: false, pool_id: slot.poolId });
855
+ return {
856
+ packet: { id: block.block_id, payload: { block_id: block.block_id }, estimatedTokens: 0, complexity: 0.5 },
857
+ outcome: "error",
858
+ error: err,
859
+ };
860
+ }
815
861
  nodeOutcomes.push({
816
862
  block_id: block.block_id,
817
863
  outcome: accept.outcome,
@@ -1553,7 +1599,7 @@ async function buildImplementDispatchStep(ctx) {
1553
1599
  // stay PENDING, and the quota_paused step renders the fit-mismatch cause
1554
1600
  // ("free a larger pool or split the node"), never "wait for a reset".
1555
1601
  if (rolling.session.frontier.length === 0) {
1556
- const structuralRefusal = detectStructuralRefusalPause(await readOptionalJsonFile(rolling.quotaPath));
1602
+ const structuralRefusal = await structuralRefusalForZeroFrontier(rolling.quotaPath);
1557
1603
  if (structuralRefusal.pause) {
1558
1604
  if (rolling.quotaPath) {
1559
1605
  await reconcileAdmissionLeasesFromQuotaFile(rolling.quotaPath);
@@ -2813,6 +2859,31 @@ async function applyPlanClarificationResolution(root, artifactsDir, state, store
2813
2859
  if (existsSync(resolutionPath)) {
2814
2860
  await withFsRetry(() => rename(resolutionPath, `${resolutionPath}.consumed-${Date.now()}`));
2815
2861
  }
2862
+ // Accept/reverify cluster defect 6: the worker's needs_clarification result
2863
+ // survives at the block's CONSTANT result_path, so the very next merge
2864
+ // (often within this same drain) re-reads it, flips the just-answered item
2865
+ // back to needs_clarification, and re-asks the operator. Archive each
2866
+ // clarified finding's block result at consume time — an ABSENT result file
2867
+ // is the benign "worker hasn't run yet → re-dispatch from scratch" branch,
2868
+ // exactly the state the answer re-opens the item into. (reject_finding /
2869
+ // defer close their items terminally, so the stale file cannot re-open them
2870
+ // — only `clarified` needs the retire.)
2871
+ const clarifiedIds = new Set(resolutions
2872
+ .filter((r) => r.action !== "reject_finding" && r.action !== "defer")
2873
+ .map((r) => r.finding_id));
2874
+ if (clarifiedIds.size > 0) {
2875
+ const owningBlockIds = new Set((state.plan.blocks ?? [])
2876
+ .filter((b) => b.items.some((id) => clarifiedIds.has(id)))
2877
+ .map((b) => b.block_id));
2878
+ const dispatchPlan = await readDispatchPlan(artifactsDir, stateRunId(state), "implement").catch(() => null);
2879
+ for (const planItem of dispatchPlan?.items ?? []) {
2880
+ if (typeof planItem.block_id === "string" &&
2881
+ owningBlockIds.has(planItem.block_id) &&
2882
+ existsSync(planItem.result_path)) {
2883
+ await withFsRetry(() => rename(planItem.result_path, `${planItem.result_path}.consumed-${Date.now()}`));
2884
+ }
2885
+ }
2886
+ }
2816
2887
  const remainingPending = state.plan.findings.some((f) => state.items?.[f.id]?.status === "pending");
2817
2888
  // Undecided-remainder guard, mirroring triage's still-blocked guard: a
2818
2889
  // resolution covering only SOME of the paused items must not fall through to