auditor-lambda 0.3.40 → 0.5.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 (193) hide show
  1. package/audit-code-wrapper-lib.mjs +20 -2
  2. package/dist/cli/args.d.ts +59 -0
  3. package/dist/cli/args.js +244 -0
  4. package/dist/cli/dispatch.d.ts +80 -0
  5. package/dist/cli/dispatch.js +532 -0
  6. package/dist/cli/prompts.d.ts +37 -0
  7. package/dist/cli/prompts.js +225 -0
  8. package/dist/cli/steps.d.ts +29 -0
  9. package/dist/cli/steps.js +30 -0
  10. package/dist/cli/waveManifest.d.ts +40 -0
  11. package/dist/cli/waveManifest.js +41 -0
  12. package/dist/cli/workerResult.d.ts +18 -0
  13. package/dist/cli/workerResult.js +42 -0
  14. package/dist/cli.d.ts +2 -22
  15. package/dist/cli.js +442 -975
  16. package/dist/extractors/analyzers/css.d.ts +2 -0
  17. package/dist/extractors/analyzers/css.js +101 -0
  18. package/dist/extractors/analyzers/html.d.ts +2 -0
  19. package/dist/extractors/analyzers/html.js +92 -0
  20. package/dist/extractors/analyzers/merge.d.ts +14 -0
  21. package/dist/extractors/analyzers/merge.js +85 -0
  22. package/dist/extractors/analyzers/python.d.ts +2 -0
  23. package/dist/extractors/analyzers/python.js +104 -0
  24. package/dist/extractors/analyzers/registry.d.ts +33 -0
  25. package/dist/extractors/analyzers/registry.js +100 -0
  26. package/dist/extractors/analyzers/resourceUrl.d.ts +7 -0
  27. package/dist/extractors/analyzers/resourceUrl.js +25 -0
  28. package/dist/extractors/analyzers/sql.d.ts +2 -0
  29. package/dist/extractors/analyzers/sql.js +19 -0
  30. package/dist/extractors/analyzers/treeSitter.d.ts +34 -0
  31. package/dist/extractors/analyzers/treeSitter.js +111 -0
  32. package/dist/extractors/analyzers/types.d.ts +53 -0
  33. package/dist/extractors/analyzers/typescript.d.ts +2 -0
  34. package/dist/extractors/analyzers/typescript.js +257 -0
  35. package/dist/extractors/browserExtension.d.ts +1 -3
  36. package/dist/extractors/browserExtension.js +2 -2
  37. package/dist/extractors/designAssessment.d.ts +1 -3
  38. package/dist/extractors/disposition.d.ts +2 -1
  39. package/dist/extractors/disposition.js +11 -1
  40. package/dist/extractors/flows.d.ts +1 -3
  41. package/dist/extractors/flows.js +2 -2
  42. package/dist/extractors/graph.d.ts +2 -2
  43. package/dist/extractors/graph.js +171 -327
  44. package/dist/extractors/graphManifestEdges.d.ts +1 -1
  45. package/dist/extractors/graphPathUtils.d.ts +1 -1
  46. package/dist/extractors/graphPythonImports.d.ts +18 -0
  47. package/dist/extractors/graphPythonImports.js +362 -0
  48. package/dist/extractors/pathPatterns.d.ts +6 -0
  49. package/dist/extractors/pathPatterns.js +8 -0
  50. package/dist/extractors/risk.d.ts +1 -2
  51. package/dist/extractors/surfaces.d.ts +1 -3
  52. package/dist/extractors/surfaces.js +2 -2
  53. package/dist/io/artifacts.d.ts +12 -5
  54. package/dist/io/artifacts.js +13 -1
  55. package/dist/io/runArtifacts.js +1 -1
  56. package/dist/mcp/server.js +1 -1
  57. package/dist/orchestrator/advance.d.ts +21 -0
  58. package/dist/orchestrator/advance.js +69 -7
  59. package/dist/orchestrator/auditTaskUtils.d.ts +4 -0
  60. package/dist/orchestrator/auditTaskUtils.js +27 -0
  61. package/dist/orchestrator/dependencyMap.js +27 -0
  62. package/dist/orchestrator/edgeReasoning.d.ts +39 -0
  63. package/dist/orchestrator/edgeReasoning.js +125 -0
  64. package/dist/orchestrator/executors.js +11 -1
  65. package/dist/orchestrator/fileAnchors.d.ts +1 -1
  66. package/dist/orchestrator/fileIntegrity.d.ts +7 -0
  67. package/dist/orchestrator/fileIntegrity.js +41 -0
  68. package/dist/orchestrator/flowCoverage.d.ts +1 -1
  69. package/dist/orchestrator/flowPlanning.d.ts +1 -1
  70. package/dist/orchestrator/flowRequeue.d.ts +1 -1
  71. package/dist/orchestrator/graphEnrichmentExecutor.d.ts +29 -0
  72. package/dist/orchestrator/graphEnrichmentExecutor.js +196 -0
  73. package/dist/orchestrator/internalExecutors.d.ts +13 -2
  74. package/dist/orchestrator/internalExecutors.js +112 -16
  75. package/dist/orchestrator/localCommands.js +6 -25
  76. package/dist/orchestrator/nextStep.d.ts +2 -1
  77. package/dist/orchestrator/nextStep.js +3 -1
  78. package/dist/orchestrator/planning.d.ts +1 -1
  79. package/dist/orchestrator/requeueCommand.d.ts +1 -1
  80. package/dist/orchestrator/reviewPackets.d.ts +37 -4
  81. package/dist/orchestrator/reviewPackets.js +113 -158
  82. package/dist/orchestrator/runtimeValidation.d.ts +1 -1
  83. package/dist/orchestrator/runtimeValidation.js +4 -31
  84. package/dist/orchestrator/scope.d.ts +62 -0
  85. package/dist/orchestrator/scope.js +227 -0
  86. package/dist/orchestrator/state.js +2 -0
  87. package/dist/orchestrator/taskBuilder.d.ts +1 -1
  88. package/dist/orchestrator/taskBuilder.js +1 -12
  89. package/dist/orchestrator/unionFind.d.ts +7 -0
  90. package/dist/orchestrator/unionFind.js +32 -0
  91. package/dist/orchestrator/unitBuilder.d.ts +2 -2
  92. package/dist/orchestrator/unitBuilder.js +4 -18
  93. package/dist/prompts/renderWorkerPrompt.js +18 -1
  94. package/dist/providers/claudeCodeProvider.d.ts +4 -4
  95. package/dist/providers/claudeCodeProvider.js +9 -3
  96. package/dist/providers/constants.d.ts +1 -1
  97. package/dist/providers/constants.js +1 -1
  98. package/dist/providers/index.d.ts +1 -2
  99. package/dist/providers/index.js +5 -4
  100. package/dist/providers/localSubprocessProvider.d.ts +2 -2
  101. package/dist/providers/localSubprocessProvider.js +1 -1
  102. package/dist/providers/opencodeProvider.d.ts +4 -4
  103. package/dist/providers/opencodeProvider.js +7 -2
  104. package/dist/providers/spawnLoggedCommand.d.ts +3 -1
  105. package/dist/providers/spawnLoggedCommand.js +21 -0
  106. package/dist/providers/subprocessTemplateProvider.d.ts +4 -4
  107. package/dist/providers/subprocessTemplateProvider.js +8 -3
  108. package/dist/providers/vscodeTaskProvider.d.ts +3 -4
  109. package/dist/providers/vscodeTaskProvider.js +2 -2
  110. package/dist/quota/discoveredLimits.js +1 -1
  111. package/dist/quota/hostLimits.d.ts +1 -2
  112. package/dist/quota/hostLimits.js +4 -46
  113. package/dist/quota/index.d.ts +18 -15
  114. package/dist/quota/index.js +4 -9
  115. package/dist/quota/scheduler.d.ts +1 -3
  116. package/dist/quota/scheduler.js +1 -2
  117. package/dist/reporting/synthesis.d.ts +37 -3
  118. package/dist/reporting/synthesis.js +97 -16
  119. package/dist/reporting/synthesisNarrativePrompt.d.ts +7 -0
  120. package/dist/reporting/synthesisNarrativePrompt.js +60 -0
  121. package/dist/reporting/workBlocks.d.ts +2 -11
  122. package/dist/supervisor/operatorHandoff.js +1 -1
  123. package/dist/supervisor/runLedger.d.ts +1 -1
  124. package/dist/supervisor/runLedger.js +2 -2
  125. package/dist/supervisor/sessionConfig.d.ts +8 -1
  126. package/dist/supervisor/sessionConfig.js +22 -3
  127. package/dist/types/analyzerCapability.d.ts +16 -0
  128. package/dist/types/auditScope.d.ts +43 -0
  129. package/dist/types/auditScope.js +14 -0
  130. package/dist/types/reviewPlanning.d.ts +1 -1
  131. package/dist/types/synthesisNarrative.d.ts +7 -0
  132. package/dist/types/synthesisNarrative.js +5 -0
  133. package/dist/types/workerSession.d.ts +6 -0
  134. package/dist/types.d.ts +2 -19
  135. package/dist/validation/artifacts.d.ts +1 -1
  136. package/dist/validation/artifacts.js +10 -1
  137. package/dist/validation/auditResults.d.ts +1 -1
  138. package/dist/validation/auditResults.js +1 -1
  139. package/dist/validation/sessionConfig.d.ts +2 -3
  140. package/dist/validation/sessionConfig.js +25 -3
  141. package/package.json +7 -3
  142. package/schemas/analyzer_capability.schema.json +47 -0
  143. package/schemas/audit_findings.schema.json +141 -0
  144. package/schemas/finding.schema.json +2 -1
  145. package/schemas/graph_bundle.schema.json +5 -0
  146. package/schemas/scope.schema.json +46 -0
  147. package/scripts/postinstall.mjs +0 -1
  148. package/dist/io/json.d.ts +0 -10
  149. package/dist/io/json.js +0 -142
  150. package/dist/providers/types.d.ts +0 -33
  151. package/dist/quota/compositeQuotaSource.d.ts +0 -7
  152. package/dist/quota/compositeQuotaSource.js +0 -20
  153. package/dist/quota/errorParsers/claudeCodeErrorParser.d.ts +0 -6
  154. package/dist/quota/errorParsers/claudeCodeErrorParser.js +0 -39
  155. package/dist/quota/errorParsers/genericErrorParser.d.ts +0 -9
  156. package/dist/quota/errorParsers/genericErrorParser.js +0 -7
  157. package/dist/quota/errorParsers/index.d.ts +0 -5
  158. package/dist/quota/errorParsers/index.js +0 -12
  159. package/dist/quota/errorParsing.d.ts +0 -7
  160. package/dist/quota/errorParsing.js +0 -69
  161. package/dist/quota/fileLock.d.ts +0 -6
  162. package/dist/quota/fileLock.js +0 -64
  163. package/dist/quota/learnedQuotaSource.d.ts +0 -7
  164. package/dist/quota/learnedQuotaSource.js +0 -25
  165. package/dist/quota/limits.d.ts +0 -16
  166. package/dist/quota/limits.js +0 -77
  167. package/dist/quota/quotaSource.d.ts +0 -12
  168. package/dist/quota/slidingWindow.d.ts +0 -4
  169. package/dist/quota/slidingWindow.js +0 -28
  170. package/dist/quota/state.d.ts +0 -15
  171. package/dist/quota/state.js +0 -148
  172. package/dist/quota/types.d.ts +0 -67
  173. package/dist/quota/types.js +0 -1
  174. package/dist/reporting/rootCause.d.ts +0 -10
  175. package/dist/reporting/rootCause.js +0 -146
  176. package/dist/types/disposition.d.ts +0 -9
  177. package/dist/types/disposition.js +0 -1
  178. package/dist/types/flows.d.ts +0 -17
  179. package/dist/types/flows.js +0 -1
  180. package/dist/types/graph.d.ts +0 -22
  181. package/dist/types/graph.js +0 -1
  182. package/dist/types/risk.d.ts +0 -9
  183. package/dist/types/risk.js +0 -1
  184. package/dist/types/runLedger.d.ts +0 -17
  185. package/dist/types/runLedger.js +0 -6
  186. package/dist/types/sessionConfig.d.ts +0 -79
  187. package/dist/types/sessionConfig.js +0 -15
  188. package/dist/types/surfaces.d.ts +0 -15
  189. package/dist/types/surfaces.js +0 -1
  190. package/dist/validation/basic.d.ts +0 -13
  191. package/dist/validation/basic.js +0 -46
  192. /package/dist/{providers → extractors/analyzers}/types.js +0 -0
  193. /package/dist/{quota/quotaSource.js → types/analyzerCapability.js} +0 -0
@@ -0,0 +1,225 @@
1
+ import { renderCommand } from "./args.js";
2
+ export function nextStepCommand(root, artifactsDir) {
3
+ return renderCommand([
4
+ "audit-code",
5
+ "next-step",
6
+ "--root",
7
+ root,
8
+ "--artifacts-dir",
9
+ artifactsDir,
10
+ ]);
11
+ }
12
+ export function mergeAndIngestCommand(artifactsDir, runId) {
13
+ return renderCommand([
14
+ "audit-code",
15
+ "merge-and-ingest",
16
+ "--artifacts-dir",
17
+ artifactsDir,
18
+ "--run-id",
19
+ runId,
20
+ ]);
21
+ }
22
+ export function renderDispatchReviewPrompt(params) {
23
+ const mergeCommand = mergeAndIngestCommand(params.artifactsDir, params.activeReviewRun.run_id);
24
+ const continueCommand = nextStepCommand(params.root, params.artifactsDir);
25
+ const modelLine = params.hostCanSelectSubagentModel
26
+ ? "When launching each subagent, map `entry.model_hint.tier` (`small`, `standard`, `deep`) to an available host model without asking the user for model names."
27
+ : "Ignore `entry.model_hint`; this host did not report per-subagent model selection.";
28
+ const toolsLine = params.hostCanRestrictSubagentTools
29
+ ? "Restrict review subagents to read/search plus the packet submit command named in their prompt. Do not give them source edit/write tools."
30
+ : "Do not ask the user about per-subagent tool restrictions; this host did not report a callable restriction facility.";
31
+ const dispatchDataLines = params.dispatchQuotaPath
32
+ ? [
33
+ "Read these generated files:",
34
+ "",
35
+ ` Dispatch plan: ${params.dispatchPlanPath}`,
36
+ ` Dispatch quota: ${params.dispatchQuotaPath}`,
37
+ "",
38
+ "Use the `wave_size` from the quota data. If `cooldown_until` is non-null, wait until that timestamp before starting the first wave.",
39
+ "",
40
+ "`host_concurrency_limit` records any detected hard host cap that contributed to `wave_size`.",
41
+ "",
42
+ "For each wave: use the `task` tool (or equivalent subagent dispatch) to launch up to `wave_size` subagents in parallel (one per entry), wait for all to finish, then start the next wave.",
43
+ ]
44
+ : [
45
+ "Read this generated dispatch plan:",
46
+ "",
47
+ ` ${params.dispatchPlanPath}`,
48
+ "",
49
+ "Launch one subagent for each entry in the plan.",
50
+ ];
51
+ return [
52
+ "# audit-code dispatch review",
53
+ "",
54
+ ...dispatchDataLines,
55
+ "",
56
+ "Pass each `entry.prompt_path` literally to its subagent; do not load packet prompt files into this orchestrator context.",
57
+ "",
58
+ "Subagent prompt shape:",
59
+ "",
60
+ ' Read and follow the audit instructions in: <entry.prompt_path>',
61
+ "",
62
+ modelLine,
63
+ toolsLine,
64
+ "",
65
+ "Each subagent must submit its packet through the submit command printed in its packet prompt and stop after successful submission.",
66
+ "",
67
+ "**File access pre-approval:** Each dispatch plan entry includes an `access` object with `read_paths` and `write_paths`. If your host supports per-subagent file access restrictions, pre-approve those paths before launching each subagent. Workers should not access files outside their declared paths.",
68
+ "",
69
+ "**After all waves complete:**",
70
+ "",
71
+ "Run exactly:",
72
+ "",
73
+ ` ${mergeCommand}`,
74
+ "",
75
+ "If merge-and-ingest fails, stop and report the exact command and error output. Do not manually merge results or edit audit state.",
76
+ "",
77
+ "If merge-and-ingest succeeds, run:",
78
+ "",
79
+ ` ${continueCommand}`,
80
+ "",
81
+ "Read and follow only the new step prompt path returned by that command.",
82
+ "",
83
+ ].join("\n");
84
+ }
85
+ export function renderSingleTaskFallbackStepPrompt(params) {
86
+ return [
87
+ "# audit-code single-task fallback step",
88
+ "",
89
+ "Use this step only because the host reported no callable subagent facility.",
90
+ "",
91
+ "Read and follow exactly this generated single-task prompt:",
92
+ "",
93
+ ` ${params.singleTaskPromptPath}`,
94
+ "",
95
+ "Complete exactly one AuditResult for the task named there, write the JSON array to the prompt's audit_results_path, run the exact worker_command from that prompt, then stop.",
96
+ "",
97
+ "Do not run dispatch commands, do not prepare packets, do not run next-step again in this turn, and do not read a report after the worker command.",
98
+ "",
99
+ "The only backend command allowed after writing the result is:",
100
+ "",
101
+ ` ${renderCommand(params.activeReviewRun.worker_command)}`,
102
+ "",
103
+ ].join("\n");
104
+ }
105
+ export function renderEdgeReasoningStepPrompt(params) {
106
+ return [
107
+ params.basePrompt,
108
+ "",
109
+ "## Results path",
110
+ "",
111
+ 'Write the JSON object ({"rewrites":[{"from":"...","to":"...","kind":"...","reason":"..."}]}) to:',
112
+ "",
113
+ ` ${params.resultsPath}`,
114
+ "",
115
+ `Cache key (edge-set content hash): ${params.contentHash}.`,
116
+ "If you already produced rewrites for this exact key, you may reuse them instead of regenerating.",
117
+ "",
118
+ `Then run: ${params.continueCommand}`,
119
+ "",
120
+ "Read and follow only the new step prompt returned by that command.",
121
+ "",
122
+ ].join("\n");
123
+ }
124
+ export function renderEdgeReasoningDispatchPrompt(params) {
125
+ return [
126
+ "# audit-code edge reasoning (subagent dispatch)",
127
+ "",
128
+ `The dependency graph has ${params.candidateCount} low-confidence edge(s) whose`,
129
+ "machine-generated `reason` text can be clarified. This is a single, bounded,",
130
+ "optional pass: it only rewrites the `reason` string of those edges — it never",
131
+ "adds, removes, re-targets, or re-weights an edge.",
132
+ "",
133
+ "Dispatch exactly ONE subagent (via the `task` tool or equivalent). Hand it this",
134
+ "prompt file path; do not load the file into this orchestrator context:",
135
+ "",
136
+ ` ${params.promptPath}`,
137
+ "",
138
+ "Subagent prompt shape:",
139
+ "",
140
+ " Read and follow the edge-reasoning instructions in: <prompt path above>",
141
+ "",
142
+ 'The subagent must write its JSON result ({"rewrites":[...]}) to:',
143
+ "",
144
+ ` ${params.resultsPath}`,
145
+ "",
146
+ `Cache key (edge-set content hash): ${params.contentHash}.`,
147
+ "If you hold a cached result for this exact key from a previous run, you may write",
148
+ "it to the results path directly instead of dispatching a subagent.",
149
+ "",
150
+ "**File access pre-approval:** if your host supports per-subagent file access",
151
+ `restrictions, allow the subagent to read ${params.promptPath} and write ${params.resultsPath}.`,
152
+ "",
153
+ "After the subagent writes the result, run exactly:",
154
+ "",
155
+ ` ${params.continueCommand}`,
156
+ "",
157
+ "Read and follow only the new step prompt returned by that command.",
158
+ "",
159
+ ].join("\n");
160
+ }
161
+ export function renderPresentReportPrompt(finalReportPath) {
162
+ return [
163
+ "# audit-code present report",
164
+ "",
165
+ "The deterministic audit is complete.",
166
+ "",
167
+ `Read the final audit report from: ${finalReportPath}`,
168
+ "",
169
+ "Present the completed audit with work blocks first.",
170
+ "",
171
+ "Do not run the orchestrator again for this completed audit.",
172
+ "",
173
+ ].join("\n");
174
+ }
175
+ export function renderAnalyzerInstallPrompt(params) {
176
+ const analyzerLines = params.unresolved.flatMap((entry) => [
177
+ `- **${entry.id}** — needs \`${entry.dependency ?? entry.id}\`; ${entry.supportedCount} in-scope file(s) would be analyzed.`,
178
+ ]);
179
+ const exampleObject = `{ ${params.unresolved
180
+ .map((entry) => `"${entry.id}": "ephemeral"`)
181
+ .join(", ")} }`;
182
+ return [
183
+ "# audit-code analyzer install",
184
+ "",
185
+ "The deterministic regex graph is built. These optional language analyzers can",
186
+ "produce a richer graph (real module resolution, inheritance, and a call graph),",
187
+ "but their compiler dependency is not installed in the audited repo:",
188
+ "",
189
+ ...analyzerLines,
190
+ "",
191
+ "Choose how to resolve each one and write a JSON object of `{ \"<analyzer-id>\": <setting> }`",
192
+ "to the decisions path below. Valid settings:",
193
+ "",
194
+ "- `ephemeral` — install into a shared, version-keyed cache (never touches this project); compile once, reuse across audits.",
195
+ "- `permanent` — same as `ephemeral` but a durable opt-in recorded in session config.",
196
+ "- `skip` — do not run this analyzer; keep the regex floor.",
197
+ "",
198
+ "Default if you are unsure or cannot install: choose `skip`. The audit proceeds either way.",
199
+ "",
200
+ "## Decisions path",
201
+ "",
202
+ "Write your choices to:",
203
+ "",
204
+ ` ${params.decisionsPath}`,
205
+ "",
206
+ `Example: ${exampleObject}`,
207
+ "",
208
+ `Then run: ${params.continueCommand}`,
209
+ "",
210
+ "Read and follow only the new step prompt returned by that command.",
211
+ "",
212
+ ].join("\n");
213
+ }
214
+ export function renderBlockedStepPrompt(reason) {
215
+ return [
216
+ "# audit-code blocked",
217
+ "",
218
+ "The audit cannot continue automatically from this step.",
219
+ "",
220
+ "Report this blocker verbatim and stop:",
221
+ "",
222
+ reason,
223
+ "",
224
+ ].join("\n");
225
+ }
@@ -0,0 +1,29 @@
1
+ import type { StepStatus } from "@audit-tools/shared";
2
+ import type { AccessDeclaration } from "../types/workerSession.js";
3
+ export declare const STEP_CONTRACT_VERSION = "audit-code-step/v1alpha1";
4
+ export type StepKind = "dispatch_review" | "single_task_fallback" | "design_review" | "analyzer_install" | "edge_reasoning" | "edge_reasoning_dispatch" | "synthesis_narrative" | "present_report" | "blocked";
5
+ export interface StepArtifact {
6
+ contract_version: typeof STEP_CONTRACT_VERSION;
7
+ step_kind: StepKind;
8
+ prompt_path: string;
9
+ status: StepStatus;
10
+ run_id: string | null;
11
+ allowed_commands: string[];
12
+ stop_condition: string;
13
+ repo_root: string;
14
+ artifacts_dir: string;
15
+ artifact_paths: Record<string, string | null>;
16
+ access?: AccessDeclaration;
17
+ }
18
+ export declare function writeCurrentStep(params: {
19
+ artifactsDir: string;
20
+ stepKind: StepKind;
21
+ status: StepStatus;
22
+ runId: string | null;
23
+ allowedCommands: string[];
24
+ stopCondition: string;
25
+ repoRoot: string;
26
+ artifactPaths: Record<string, string | null>;
27
+ prompt: string;
28
+ access?: AccessDeclaration;
29
+ }): Promise<StepArtifact>;
@@ -0,0 +1,30 @@
1
+ import { mkdir, writeFile } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ import { writeJsonFile } from "@audit-tools/shared";
4
+ export const STEP_CONTRACT_VERSION = "audit-code-step/v1alpha1";
5
+ export async function writeCurrentStep(params) {
6
+ const stepsDir = join(params.artifactsDir, "steps");
7
+ await mkdir(stepsDir, { recursive: true });
8
+ const promptPath = join(stepsDir, "current-prompt.md");
9
+ const stepPath = join(stepsDir, "current-step.json");
10
+ await writeFile(promptPath, params.prompt, "utf8");
11
+ const step = {
12
+ contract_version: STEP_CONTRACT_VERSION,
13
+ step_kind: params.stepKind,
14
+ prompt_path: promptPath,
15
+ status: params.status,
16
+ run_id: params.runId,
17
+ allowed_commands: params.allowedCommands,
18
+ stop_condition: params.stopCondition,
19
+ repo_root: params.repoRoot,
20
+ artifacts_dir: params.artifactsDir,
21
+ artifact_paths: {
22
+ current_step: stepPath,
23
+ current_prompt: promptPath,
24
+ ...params.artifactPaths,
25
+ },
26
+ ...(params.access ? { access: params.access } : {}),
27
+ };
28
+ await writeJsonFile(stepPath, step);
29
+ return step;
30
+ }
@@ -0,0 +1,40 @@
1
+ import type { AuditTask } from "../types.js";
2
+ declare const WAVE_MANIFEST_CONTRACT = "audit-code-wave/v1alpha1";
3
+ export interface WaveSlotEntry {
4
+ run_id: string;
5
+ task_path: string;
6
+ prompt_path: string;
7
+ result_path: string;
8
+ stdout_path: string;
9
+ stderr_path: string;
10
+ status_path: string;
11
+ audit_results_path: string;
12
+ pending_tasks_path: string;
13
+ task_ids: string[];
14
+ }
15
+ export interface WaveManifest {
16
+ contract_version: typeof WAVE_MANIFEST_CONTRACT;
17
+ obligation_id: string;
18
+ started_at: string;
19
+ pid: number;
20
+ slots: WaveSlotEntry[];
21
+ }
22
+ export declare function waveManifestPath(artifactsDir: string): string;
23
+ export declare function writeWaveManifest(artifactsDir: string, manifest: Omit<WaveManifest, "contract_version">): Promise<void>;
24
+ export declare function readWaveManifest(artifactsDir: string): Promise<WaveManifest | null>;
25
+ export declare function removeWaveManifest(artifactsDir: string): Promise<void>;
26
+ export declare function buildWaveSlotEntry(slot: {
27
+ runId: string;
28
+ paths: {
29
+ taskPath: string;
30
+ promptPath: string;
31
+ resultPath: string;
32
+ stdoutPath: string;
33
+ stderrPath: string;
34
+ statusPath: string;
35
+ };
36
+ auditResultsPath: string;
37
+ pendingTasksPath: string;
38
+ group: AuditTask[];
39
+ }): WaveSlotEntry;
40
+ export {};
@@ -0,0 +1,41 @@
1
+ import { rm } from "node:fs/promises";
2
+ import { join } from "node:path";
3
+ import { isFileMissingError, readJsonFile, writeJsonFile } from "@audit-tools/shared";
4
+ const WAVE_MANIFEST_FILENAME = "wave-manifest.json";
5
+ const WAVE_MANIFEST_CONTRACT = "audit-code-wave/v1alpha1";
6
+ export function waveManifestPath(artifactsDir) {
7
+ return join(artifactsDir, "dispatch", WAVE_MANIFEST_FILENAME);
8
+ }
9
+ export async function writeWaveManifest(artifactsDir, manifest) {
10
+ await writeJsonFile(waveManifestPath(artifactsDir), {
11
+ contract_version: WAVE_MANIFEST_CONTRACT,
12
+ ...manifest,
13
+ });
14
+ }
15
+ export async function readWaveManifest(artifactsDir) {
16
+ try {
17
+ return await readJsonFile(waveManifestPath(artifactsDir));
18
+ }
19
+ catch (error) {
20
+ if (isFileMissingError(error))
21
+ return null;
22
+ throw error;
23
+ }
24
+ }
25
+ export async function removeWaveManifest(artifactsDir) {
26
+ await rm(waveManifestPath(artifactsDir), { force: true });
27
+ }
28
+ export function buildWaveSlotEntry(slot) {
29
+ return {
30
+ run_id: slot.runId,
31
+ task_path: slot.paths.taskPath,
32
+ prompt_path: slot.paths.promptPath,
33
+ result_path: slot.paths.resultPath,
34
+ stdout_path: slot.paths.stdoutPath,
35
+ stderr_path: slot.paths.stderrPath,
36
+ status_path: slot.paths.statusPath,
37
+ audit_results_path: slot.auditResultsPath,
38
+ pending_tasks_path: slot.pendingTasksPath,
39
+ task_ids: slot.group.map((t) => t.task_id),
40
+ };
41
+ }
@@ -0,0 +1,18 @@
1
+ import type { WorkerResult } from "../types/workerResult.js";
2
+ import type { RunPaths } from "../io/runArtifacts.js";
3
+ export declare const WORKER_RESULT_CONTRACT_VERSION = "audit-code-worker-result/v1alpha1";
4
+ export declare function buildWorkerResult(params: {
5
+ runId: string;
6
+ obligationId: string | null;
7
+ status: WorkerResult["status"];
8
+ progressMade: boolean;
9
+ selectedExecutor: string | null;
10
+ artifactsWritten: string[];
11
+ summary: string;
12
+ nextLikelyStep: string | null;
13
+ errors: string[];
14
+ }): WorkerResult;
15
+ export declare function persistWorkerRunArtifacts(paths: RunPaths, workerResult: WorkerResult, executionMode: string): Promise<void>;
16
+ export declare function isWorkerResult(value: unknown): value is WorkerResult;
17
+ export declare function buildWorkerFailureBlocker(workerResult: WorkerResult): string;
18
+ export declare function formatAuditResultValidationError(issues: ReturnType<typeof import("../validation/auditResults.js").validateAuditResults>): string;
@@ -0,0 +1,42 @@
1
+ import { writeJsonFile } from "@audit-tools/shared";
2
+ import { formatAuditResultIssues } from "../validation/auditResults.js";
3
+ export const WORKER_RESULT_CONTRACT_VERSION = "audit-code-worker-result/v1alpha1";
4
+ export function buildWorkerResult(params) {
5
+ return {
6
+ contract_version: WORKER_RESULT_CONTRACT_VERSION,
7
+ run_id: params.runId,
8
+ obligation_id: params.obligationId,
9
+ status: params.status,
10
+ progress_made: params.progressMade,
11
+ selected_executor: params.selectedExecutor,
12
+ artifacts_written: params.artifactsWritten,
13
+ summary: params.summary,
14
+ next_likely_step: params.nextLikelyStep,
15
+ errors: params.errors,
16
+ };
17
+ }
18
+ export async function persistWorkerRunArtifacts(paths, workerResult, executionMode) {
19
+ await writeJsonFile(paths.resultPath, workerResult);
20
+ await writeJsonFile(paths.statusPath, {
21
+ run_id: workerResult.run_id,
22
+ status: workerResult.status,
23
+ execution_mode: executionMode,
24
+ result_path: paths.resultPath,
25
+ });
26
+ }
27
+ export function isWorkerResult(value) {
28
+ return (typeof value === "object" &&
29
+ value !== null &&
30
+ value.contract_version ===
31
+ WORKER_RESULT_CONTRACT_VERSION);
32
+ }
33
+ export function buildWorkerFailureBlocker(workerResult) {
34
+ const details = workerResult.errors.filter((error) => error.trim().length > 0);
35
+ return details.length > 0
36
+ ? `${workerResult.summary} ${details.join(" ")}`
37
+ : workerResult.summary;
38
+ }
39
+ export function formatAuditResultValidationError(issues) {
40
+ return (`audit-results validation failed with ${issues.length} error(s):\n` +
41
+ formatAuditResultIssues(issues));
42
+ }
package/dist/cli.d.ts CHANGED
@@ -1,24 +1,5 @@
1
- import type { SessionConfig } from "./types/sessionConfig.js";
2
- type UiMode = "visible" | "headless";
3
- declare function getFlag(argv: string[], name: string, fallback?: string): string | undefined;
4
- declare function hasFlag(argv: string[], name: string): boolean;
5
- export declare function resolveHostDispatchCapability(options: {
6
- explicit?: boolean;
7
- sessionConfig: SessionConfig;
8
- env?: NodeJS.ProcessEnv;
9
- }): boolean;
10
- declare function getArtifactsDir(argv: string[]): string;
11
- declare function getRootDir(argv: string[]): string;
12
- declare function warnIfNotGitRepo(root: string): void;
13
- declare function getBatchResultsDir(argv: string[]): string | undefined;
14
- declare function getMaxRuns(argv: string[]): number;
15
- declare function getAgentBatchSize(argv: string[], sessionConfig: SessionConfig): number;
16
- declare function getParallelWorkers(argv: string[], sessionConfig: SessionConfig): number;
17
- declare function getTimeoutMs(argv: string[], sessionConfig: SessionConfig): number;
18
- declare function chunkArray<T>(arr: T[], size: number): T[][];
19
- declare function getUiMode(argv: string[], fallback?: UiMode): UiMode;
20
- declare function countLines(path: string): Promise<number>;
21
- declare function looksLikeCliFlag(value: string | undefined): boolean;
1
+ export { resolveHostDispatchCapability, DIRECT_CLI_DEFAULTS, getFlag, hasFlag, getOptionalBooleanFlag, getArtifactsDir, getRootDir, getBatchResultsDir, getMaxRuns, getAgentBatchSize, getParallelWorkers, getTimeoutMs, chunkArray, getUiMode, looksLikeCliFlag, countLines, warnIfNotGitRepo, } from "./cli/args.js";
2
+ import { type UiMode, getFlag, hasFlag, getArtifactsDir, getRootDir, warnIfNotGitRepo, getBatchResultsDir, getMaxRuns, getAgentBatchSize, getParallelWorkers, getTimeoutMs, chunkArray, getUiMode, looksLikeCliFlag, countLines } from "./cli/args.js";
22
3
  export declare const cliTestUtils: {
23
4
  defaults: {
24
5
  rootDir: string;
@@ -46,4 +27,3 @@ export declare const cliTestUtils: {
46
27
  };
47
28
  export declare function runSample(argv?: string[]): Promise<void>;
48
29
  export declare function runCli(argv: string[]): Promise<void>;
49
- export {};