auditor-lambda 0.1.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.
- package/README.md +173 -0
- package/audit-code-wrapper-lib.mjs +905 -0
- package/audit-code.mjs +13 -0
- package/dist/adapters/coverageSummary.d.ts +8 -0
- package/dist/adapters/coverageSummary.js +13 -0
- package/dist/adapters/eslint.d.ts +13 -0
- package/dist/adapters/eslint.js +21 -0
- package/dist/adapters/normalizeExternal.d.ts +12 -0
- package/dist/adapters/normalizeExternal.js +19 -0
- package/dist/adapters/npmAudit.d.ts +15 -0
- package/dist/adapters/npmAudit.js +12 -0
- package/dist/adapters/semgrep.d.ts +22 -0
- package/dist/adapters/semgrep.js +14 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +724 -0
- package/dist/coverage.d.ts +11 -0
- package/dist/coverage.js +102 -0
- package/dist/extractors/bucketing.d.ts +7 -0
- package/dist/extractors/bucketing.js +72 -0
- package/dist/extractors/disposition.d.ts +4 -0
- package/dist/extractors/disposition.js +41 -0
- package/dist/extractors/fileInventory.d.ts +7 -0
- package/dist/extractors/fileInventory.js +44 -0
- package/dist/extractors/flows.d.ts +5 -0
- package/dist/extractors/flows.js +125 -0
- package/dist/extractors/fsIntake.d.ts +8 -0
- package/dist/extractors/fsIntake.js +66 -0
- package/dist/extractors/graph.d.ts +4 -0
- package/dist/extractors/graph.js +46 -0
- package/dist/extractors/ignore.d.ts +1 -0
- package/dist/extractors/ignore.js +17 -0
- package/dist/extractors/risk.d.ts +5 -0
- package/dist/extractors/risk.js +45 -0
- package/dist/extractors/surfaces.d.ts +4 -0
- package/dist/extractors/surfaces.js +40 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/io/artifacts.d.ts +38 -0
- package/dist/io/artifacts.js +100 -0
- package/dist/io/json.d.ts +8 -0
- package/dist/io/json.js +96 -0
- package/dist/io/runArtifacts.d.ts +14 -0
- package/dist/io/runArtifacts.js +37 -0
- package/dist/orchestrator/advance.d.ts +24 -0
- package/dist/orchestrator/advance.js +104 -0
- package/dist/orchestrator/artifactMetadata.d.ts +4 -0
- package/dist/orchestrator/artifactMetadata.js +111 -0
- package/dist/orchestrator/autoFixExecutor.d.ts +3 -0
- package/dist/orchestrator/autoFixExecutor.js +63 -0
- package/dist/orchestrator/chunking.d.ts +5 -0
- package/dist/orchestrator/chunking.js +13 -0
- package/dist/orchestrator/dependencyMap.d.ts +1 -0
- package/dist/orchestrator/dependencyMap.js +82 -0
- package/dist/orchestrator/executors.d.ts +6 -0
- package/dist/orchestrator/executors.js +52 -0
- package/dist/orchestrator/flowCoverage.d.ts +4 -0
- package/dist/orchestrator/flowCoverage.js +44 -0
- package/dist/orchestrator/flowPlanning.d.ts +3 -0
- package/dist/orchestrator/flowPlanning.js +42 -0
- package/dist/orchestrator/flowRequeue.d.ts +5 -0
- package/dist/orchestrator/flowRequeue.js +58 -0
- package/dist/orchestrator/internalExecutors.d.ts +16 -0
- package/dist/orchestrator/internalExecutors.js +212 -0
- package/dist/orchestrator/nextStep.d.ts +9 -0
- package/dist/orchestrator/nextStep.js +44 -0
- package/dist/orchestrator/planning.d.ts +4 -0
- package/dist/orchestrator/planning.js +62 -0
- package/dist/orchestrator/requeue.d.ts +3 -0
- package/dist/orchestrator/requeue.js +25 -0
- package/dist/orchestrator/requeueCommand.d.ts +10 -0
- package/dist/orchestrator/requeueCommand.js +27 -0
- package/dist/orchestrator/resultIngestion.d.ts +2 -0
- package/dist/orchestrator/resultIngestion.js +13 -0
- package/dist/orchestrator/runtimeValidation.d.ts +7 -0
- package/dist/orchestrator/runtimeValidation.js +103 -0
- package/dist/orchestrator/runtimeValidationUpdate.d.ts +2 -0
- package/dist/orchestrator/runtimeValidationUpdate.js +52 -0
- package/dist/orchestrator/staleness.d.ts +2 -0
- package/dist/orchestrator/staleness.js +83 -0
- package/dist/orchestrator/state.d.ts +3 -0
- package/dist/orchestrator/state.js +85 -0
- package/dist/orchestrator/syntaxResolutionExecutor.d.ts +3 -0
- package/dist/orchestrator/syntaxResolutionExecutor.js +99 -0
- package/dist/orchestrator/taskBuilder.d.ts +12 -0
- package/dist/orchestrator/taskBuilder.js +154 -0
- package/dist/orchestrator/unitBuilder.d.ts +3 -0
- package/dist/orchestrator/unitBuilder.js +145 -0
- package/dist/orchestrator.d.ts +6 -0
- package/dist/orchestrator.js +33 -0
- package/dist/prompts/renderWorkerPrompt.d.ts +2 -0
- package/dist/prompts/renderWorkerPrompt.js +19 -0
- package/dist/providers/claudeCodeProvider.d.ts +8 -0
- package/dist/providers/claudeCodeProvider.js +20 -0
- package/dist/providers/index.d.ts +7 -0
- package/dist/providers/index.js +77 -0
- package/dist/providers/localSubprocessProvider.d.ts +5 -0
- package/dist/providers/localSubprocessProvider.js +13 -0
- package/dist/providers/opencodeProvider.d.ts +8 -0
- package/dist/providers/opencodeProvider.js +15 -0
- package/dist/providers/spawnLoggedCommand.d.ts +2 -0
- package/dist/providers/spawnLoggedCommand.js +48 -0
- package/dist/providers/subprocessTemplateProvider.d.ts +8 -0
- package/dist/providers/subprocessTemplateProvider.js +41 -0
- package/dist/providers/types.d.ts +22 -0
- package/dist/providers/types.js +1 -0
- package/dist/providers/vscodeTaskProvider.d.ts +8 -0
- package/dist/providers/vscodeTaskProvider.js +14 -0
- package/dist/reporting/mergeFindings.d.ts +4 -0
- package/dist/reporting/mergeFindings.js +136 -0
- package/dist/reporting/rootCause.d.ts +11 -0
- package/dist/reporting/rootCause.js +69 -0
- package/dist/reporting/synthesis.d.ts +21 -0
- package/dist/reporting/synthesis.js +55 -0
- package/dist/supervisor/operatorHandoff.d.ts +37 -0
- package/dist/supervisor/operatorHandoff.js +144 -0
- package/dist/supervisor/runLedger.d.ts +3 -0
- package/dist/supervisor/runLedger.js +17 -0
- package/dist/supervisor/sessionConfig.d.ts +4 -0
- package/dist/supervisor/sessionConfig.js +26 -0
- package/dist/types/artifactMetadata.d.ts +8 -0
- package/dist/types/artifactMetadata.js +1 -0
- package/dist/types/auditState.d.ts +14 -0
- package/dist/types/auditState.js +1 -0
- package/dist/types/disposition.d.ts +9 -0
- package/dist/types/disposition.js +1 -0
- package/dist/types/externalAnalyzer.d.ts +16 -0
- package/dist/types/externalAnalyzer.js +1 -0
- package/dist/types/flowCoverage.d.ts +11 -0
- package/dist/types/flowCoverage.js +1 -0
- package/dist/types/flows.d.ts +11 -0
- package/dist/types/flows.js +1 -0
- package/dist/types/graph.d.ts +18 -0
- package/dist/types/graph.js +1 -0
- package/dist/types/risk.d.ts +9 -0
- package/dist/types/risk.js +1 -0
- package/dist/types/runLedger.d.ts +13 -0
- package/dist/types/runLedger.js +1 -0
- package/dist/types/runtimeValidation.d.ts +22 -0
- package/dist/types/runtimeValidation.js +1 -0
- package/dist/types/sessionConfig.d.ts +27 -0
- package/dist/types/sessionConfig.js +1 -0
- package/dist/types/surfaces.d.ts +11 -0
- package/dist/types/surfaces.js +1 -0
- package/dist/types/workerResult.d.ts +13 -0
- package/dist/types/workerResult.js +1 -0
- package/dist/types/workerSession.d.ts +13 -0
- package/dist/types/workerSession.js +1 -0
- package/dist/types.d.ts +104 -0
- package/dist/types.js +1 -0
- package/dist/validation/artifacts.d.ts +3 -0
- package/dist/validation/artifacts.js +191 -0
- package/dist/validation/basic.d.ts +5 -0
- package/dist/validation/basic.js +9 -0
- package/dist/validation/sessionConfig.d.ts +6 -0
- package/dist/validation/sessionConfig.js +139 -0
- package/docs/agent-integrations.md +237 -0
- package/docs/agent-roles.md +69 -0
- package/docs/architecture.md +90 -0
- package/docs/artifacts.md +69 -0
- package/docs/bootstrap-install.md +79 -0
- package/docs/contract.md +140 -0
- package/docs/github-copilot.md +50 -0
- package/docs/model-selection.md +86 -0
- package/docs/next-steps.md +161 -0
- package/docs/packaging.md +88 -0
- package/docs/pipeline.md +152 -0
- package/docs/product-direction.md +111 -0
- package/docs/production-launch-bar.md +83 -0
- package/docs/production-readiness.md +52 -0
- package/docs/repo-layout.md +30 -0
- package/docs/run-flow.md +49 -0
- package/docs/session-config.md +232 -0
- package/docs/supervisor.md +83 -0
- package/docs/usage.md +172 -0
- package/docs/windows-setup.md +146 -0
- package/package.json +56 -0
- package/schemas/audit-code-v1alpha1.schema.json +191 -0
- package/schemas/audit_result.schema.json +48 -0
- package/schemas/audit_state.schema.json +36 -0
- package/schemas/audit_task.schema.json +49 -0
- package/schemas/blind_spot_register.schema.json +40 -0
- package/schemas/coverage_matrix.schema.json +50 -0
- package/schemas/critical_flows.schema.json +38 -0
- package/schemas/external_analyzer_results.schema.json +31 -0
- package/schemas/file_disposition.schema.json +33 -0
- package/schemas/finding.schema.json +62 -0
- package/schemas/flow_coverage.schema.json +44 -0
- package/schemas/graph_bundle.schema.json +55 -0
- package/schemas/merged_findings.schema.json +14 -0
- package/schemas/repo_manifest.schema.json +37 -0
- package/schemas/risk_register.schema.json +30 -0
- package/schemas/root_cause_clusters.schema.json +31 -0
- package/schemas/runtime_validation_report.schema.json +34 -0
- package/schemas/runtime_validation_tasks.schema.json +36 -0
- package/schemas/surface_manifest.schema.json +32 -0
- package/schemas/synthesis_report.schema.json +61 -0
- package/schemas/unit_manifest.schema.json +36 -0
- package/skills/audit-code/SKILL.md +54 -0
- package/skills/audit-code/audit-code.prompt.md +66 -0
package/dist/cli.js
ADDED
|
@@ -0,0 +1,724 @@
|
|
|
1
|
+
import { mkdir } from "node:fs/promises";
|
|
2
|
+
import { createReadStream } from "node:fs";
|
|
3
|
+
import { resolve } from "node:path";
|
|
4
|
+
import { buildRepoManifest } from "./extractors/fileInventory.js";
|
|
5
|
+
import { buildFileDisposition } from "./extractors/disposition.js";
|
|
6
|
+
import { buildCriticalFlowManifest } from "./extractors/flows.js";
|
|
7
|
+
import { buildSurfaceManifest } from "./extractors/surfaces.js";
|
|
8
|
+
import { buildUnitManifest } from "./orchestrator/unitBuilder.js";
|
|
9
|
+
import { buildFlowCoverage } from "./orchestrator/flowCoverage.js";
|
|
10
|
+
import { buildRuntimeValidationTasks, buildPlaceholderRuntimeValidationReport, } from "./orchestrator/runtimeValidation.js";
|
|
11
|
+
import { initializeCoverageFromPlan } from "./orchestrator/planning.js";
|
|
12
|
+
import { loadArtifactBundle, writeCoreArtifacts, } from "./io/artifacts.js";
|
|
13
|
+
import { readJsonFile, writeJsonFile } from "./io/json.js";
|
|
14
|
+
import { validateArtifactBundle } from "./validation/artifacts.js";
|
|
15
|
+
import { validateConfiguredProviderEnvironment, validateSessionConfig, } from "./validation/sessionConfig.js";
|
|
16
|
+
import { buildSynthesisReport } from "./reporting/synthesis.js";
|
|
17
|
+
import { deriveAuditState } from "./orchestrator/state.js";
|
|
18
|
+
import { advanceAudit } from "./orchestrator/advance.js";
|
|
19
|
+
import { decideNextStep } from "./orchestrator/nextStep.js";
|
|
20
|
+
import { createFreshSessionProvider, resolveFreshSessionProviderName, } from "./providers/index.js";
|
|
21
|
+
import { appendRunLedgerEntry } from "./supervisor/runLedger.js";
|
|
22
|
+
import { buildAuditCodeHandoff, writeAuditCodeHandoffArtifacts, } from "./supervisor/operatorHandoff.js";
|
|
23
|
+
import { getSessionConfigPath, loadSessionConfig, readSessionConfigFile, } from "./supervisor/sessionConfig.js";
|
|
24
|
+
import { buildRunId, ensureSupervisorDirs, getRunPaths, writeWorkerTaskFiles, } from "./io/runArtifacts.js";
|
|
25
|
+
import { renderWorkerPrompt } from "./prompts/renderWorkerPrompt.js";
|
|
26
|
+
const ADVANCE_AUDIT_CONTRACT_VERSION = "audit-code/v1alpha1";
|
|
27
|
+
const WORKER_RESULT_CONTRACT_VERSION = "audit-code-worker-result/v1alpha1";
|
|
28
|
+
const sampleFiles = [
|
|
29
|
+
{ path: "src/api/auth.ts", size_bytes: 1240, hash: "abc123" },
|
|
30
|
+
{ path: "src/lib/session.ts", size_bytes: 980, hash: "def456" },
|
|
31
|
+
{ path: "infra/deploy.yml", size_bytes: 420, hash: "ghi789" },
|
|
32
|
+
{ path: "docs/notes.md", size_bytes: 300, hash: "doc111" },
|
|
33
|
+
];
|
|
34
|
+
function getFlag(argv, name, fallback) {
|
|
35
|
+
const index = argv.indexOf(name);
|
|
36
|
+
if (index >= 0 && argv[index + 1])
|
|
37
|
+
return argv[index + 1];
|
|
38
|
+
return fallback;
|
|
39
|
+
}
|
|
40
|
+
function hasFlag(argv, name) {
|
|
41
|
+
return argv.includes(name);
|
|
42
|
+
}
|
|
43
|
+
function getArtifactsDir(argv) {
|
|
44
|
+
return resolve(getFlag(argv, "--artifacts-dir", ".artifacts"));
|
|
45
|
+
}
|
|
46
|
+
function getRootDir(argv) {
|
|
47
|
+
return resolve(getFlag(argv, "--root", "."));
|
|
48
|
+
}
|
|
49
|
+
function getMaxRuns(argv) {
|
|
50
|
+
const raw = Number(getFlag(argv, "--max-runs", "25"));
|
|
51
|
+
return Number.isFinite(raw) && raw > 0 ? Math.floor(raw) : 25;
|
|
52
|
+
}
|
|
53
|
+
function getUiMode(argv, fallback = "headless") {
|
|
54
|
+
const raw = getFlag(argv, "--ui");
|
|
55
|
+
if (raw === "visible")
|
|
56
|
+
return "visible";
|
|
57
|
+
if (raw === "headless")
|
|
58
|
+
return "headless";
|
|
59
|
+
return fallback;
|
|
60
|
+
}
|
|
61
|
+
function buildEnvelope(params) {
|
|
62
|
+
return {
|
|
63
|
+
contract_version: ADVANCE_AUDIT_CONTRACT_VERSION,
|
|
64
|
+
audit_state: params.audit_state,
|
|
65
|
+
selected_obligation: params.selected_obligation,
|
|
66
|
+
selected_executor: params.selected_executor,
|
|
67
|
+
progress_made: params.progress_made,
|
|
68
|
+
artifacts_written: params.artifacts_written,
|
|
69
|
+
progress_summary: params.progress_summary,
|
|
70
|
+
next_likely_step: params.next_likely_step,
|
|
71
|
+
handoff: params.handoff,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
async function emitEnvelope(params) {
|
|
75
|
+
const handoff = buildAuditCodeHandoff({
|
|
76
|
+
root: params.root,
|
|
77
|
+
artifactsDir: params.artifactsDir,
|
|
78
|
+
state: params.audit_state,
|
|
79
|
+
bundle: params.bundle,
|
|
80
|
+
providerName: params.providerName,
|
|
81
|
+
progressSummary: params.progress_summary,
|
|
82
|
+
});
|
|
83
|
+
await writeAuditCodeHandoffArtifacts(handoff);
|
|
84
|
+
console.log(JSON.stringify(buildEnvelope({
|
|
85
|
+
audit_state: params.audit_state,
|
|
86
|
+
selected_obligation: params.selected_obligation,
|
|
87
|
+
selected_executor: params.selected_executor,
|
|
88
|
+
progress_made: params.progress_made,
|
|
89
|
+
artifacts_written: params.artifacts_written,
|
|
90
|
+
progress_summary: params.progress_summary,
|
|
91
|
+
next_likely_step: params.next_likely_step,
|
|
92
|
+
handoff,
|
|
93
|
+
}), null, 2));
|
|
94
|
+
}
|
|
95
|
+
function buildManualReviewBlocker(providerName) {
|
|
96
|
+
return providerName === "local-subprocess"
|
|
97
|
+
? "Automatic local-subprocess work is exhausted. Remaining audit tasks require explicit audit results or an interactive provider such as claude-code, opencode, or subprocess-template."
|
|
98
|
+
: "Automatic work is exhausted. Remaining audit tasks require explicit audit results or an interactive provider.";
|
|
99
|
+
}
|
|
100
|
+
function prefixValidationIssues(prefix, issues) {
|
|
101
|
+
return issues.map((issue) => ({
|
|
102
|
+
path: issue.path.length === 0
|
|
103
|
+
? prefix
|
|
104
|
+
: issue.path === prefix || issue.path.startsWith(`${prefix}.`)
|
|
105
|
+
? issue.path
|
|
106
|
+
: `${prefix}.${issue.path}`,
|
|
107
|
+
message: issue.message,
|
|
108
|
+
}));
|
|
109
|
+
}
|
|
110
|
+
function buildBlockedAuditState(params) {
|
|
111
|
+
return {
|
|
112
|
+
...params.state,
|
|
113
|
+
status: "blocked",
|
|
114
|
+
last_executor: params.executor ?? params.state.last_executor,
|
|
115
|
+
last_obligation: params.obligationId ?? params.state.last_obligation,
|
|
116
|
+
blockers: [...new Set([...(params.state.blockers ?? []), params.blocker])],
|
|
117
|
+
obligations: params.state.obligations.map((item) => item.id === params.obligationId
|
|
118
|
+
? {
|
|
119
|
+
...item,
|
|
120
|
+
state: "blocked",
|
|
121
|
+
reason: params.blocker,
|
|
122
|
+
}
|
|
123
|
+
: item),
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
async function countLines(path) {
|
|
127
|
+
return new Promise((resolve, reject) => {
|
|
128
|
+
let lines = 1;
|
|
129
|
+
let byteCount = 0;
|
|
130
|
+
const stream = createReadStream(path);
|
|
131
|
+
stream.on("data", (chunk) => {
|
|
132
|
+
const buffer = typeof chunk === "string" ? Buffer.from(chunk) : chunk;
|
|
133
|
+
byteCount += buffer.length;
|
|
134
|
+
for (let i = 0; i < buffer.length; ++i) {
|
|
135
|
+
if (buffer[i] === 10)
|
|
136
|
+
lines++;
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
stream.on("end", () => resolve(byteCount === 0 ? 0 : lines));
|
|
140
|
+
stream.on("error", reject);
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
async function buildLineIndex(root, repoManifest) {
|
|
144
|
+
const entries = [];
|
|
145
|
+
const batchSize = 25;
|
|
146
|
+
for (let i = 0; i < repoManifest.files.length; i += batchSize) {
|
|
147
|
+
const batch = repoManifest.files.slice(i, i + batchSize);
|
|
148
|
+
const results = await Promise.all(batch.map(async (file) => {
|
|
149
|
+
try {
|
|
150
|
+
return [
|
|
151
|
+
file.path,
|
|
152
|
+
await countLines(resolve(root, file.path)),
|
|
153
|
+
];
|
|
154
|
+
}
|
|
155
|
+
catch {
|
|
156
|
+
return [file.path, 0];
|
|
157
|
+
}
|
|
158
|
+
}));
|
|
159
|
+
entries.push(...results);
|
|
160
|
+
}
|
|
161
|
+
return Object.fromEntries(entries);
|
|
162
|
+
}
|
|
163
|
+
async function runAuditStep(options) {
|
|
164
|
+
const bundle = await loadArtifactBundle(options.artifactsDir);
|
|
165
|
+
const auditResults = options.auditResultsPath
|
|
166
|
+
? await readJsonFile(options.auditResultsPath)
|
|
167
|
+
: undefined;
|
|
168
|
+
const runtimeValidationUpdates = options.runtimeUpdatesPath
|
|
169
|
+
? await readJsonFile(options.runtimeUpdatesPath)
|
|
170
|
+
: undefined;
|
|
171
|
+
const externalAnalyzerResults = options.externalAnalyzerPath
|
|
172
|
+
? await readJsonFile(options.externalAnalyzerPath)
|
|
173
|
+
: undefined;
|
|
174
|
+
const lineIndex = bundle.repo_manifest
|
|
175
|
+
? await buildLineIndex(options.root, bundle.repo_manifest)
|
|
176
|
+
: undefined;
|
|
177
|
+
const result = await advanceAudit(bundle, {
|
|
178
|
+
root: options.root,
|
|
179
|
+
lineIndex,
|
|
180
|
+
auditResults,
|
|
181
|
+
runtimeValidationUpdates,
|
|
182
|
+
externalAnalyzerResults,
|
|
183
|
+
preferredExecutor: options.preferredExecutor,
|
|
184
|
+
});
|
|
185
|
+
await writeCoreArtifacts(options.artifactsDir, result.updated_bundle);
|
|
186
|
+
return result;
|
|
187
|
+
}
|
|
188
|
+
function isWorkerResult(value) {
|
|
189
|
+
return (typeof value === "object" &&
|
|
190
|
+
value !== null &&
|
|
191
|
+
value.contract_version ===
|
|
192
|
+
WORKER_RESULT_CONTRACT_VERSION);
|
|
193
|
+
}
|
|
194
|
+
export async function runSample() {
|
|
195
|
+
const repoManifest = buildRepoManifest("sample-repo", sampleFiles);
|
|
196
|
+
const disposition = buildFileDisposition(repoManifest);
|
|
197
|
+
const unitManifest = buildUnitManifest(repoManifest, disposition);
|
|
198
|
+
const surfaceManifest = buildSurfaceManifest(repoManifest, disposition);
|
|
199
|
+
const criticalFlows = buildCriticalFlowManifest(repoManifest, surfaceManifest, disposition);
|
|
200
|
+
const coverage = initializeCoverageFromPlan(repoManifest, unitManifest, disposition);
|
|
201
|
+
const sampleResults = [
|
|
202
|
+
{
|
|
203
|
+
task_id: "src-api:security:src/api/auth.ts:1-100",
|
|
204
|
+
unit_id: unitManifest.units[0]?.unit_id ?? "sample-unit",
|
|
205
|
+
pass_id: "pass:security",
|
|
206
|
+
lens: "security",
|
|
207
|
+
agent_role: "security-auditor",
|
|
208
|
+
reviewed_ranges: [{ path: "src/api/auth.ts", start: 1, end: 100 }],
|
|
209
|
+
findings: [],
|
|
210
|
+
notes: ["Sample result ingestion path."],
|
|
211
|
+
requires_followup: false,
|
|
212
|
+
},
|
|
213
|
+
];
|
|
214
|
+
const flowCoverage = buildFlowCoverage(criticalFlows, coverage);
|
|
215
|
+
const runtimeValidationTasks = buildRuntimeValidationTasks(unitManifest, criticalFlows, flowCoverage);
|
|
216
|
+
const runtimeValidationReport = buildPlaceholderRuntimeValidationReport(runtimeValidationTasks);
|
|
217
|
+
const synthesisReport = buildSynthesisReport(sampleResults, runtimeValidationReport);
|
|
218
|
+
const auditState = deriveAuditState({
|
|
219
|
+
repo_manifest: repoManifest,
|
|
220
|
+
file_disposition: disposition,
|
|
221
|
+
unit_manifest: unitManifest,
|
|
222
|
+
surface_manifest: surfaceManifest,
|
|
223
|
+
critical_flows: criticalFlows,
|
|
224
|
+
flow_coverage: flowCoverage,
|
|
225
|
+
coverage_matrix: coverage,
|
|
226
|
+
runtime_validation_tasks: runtimeValidationTasks,
|
|
227
|
+
runtime_validation_report: runtimeValidationReport,
|
|
228
|
+
audit_results: sampleResults,
|
|
229
|
+
synthesis_report: synthesisReport,
|
|
230
|
+
});
|
|
231
|
+
const artifactsDir = getArtifactsDir(process.argv);
|
|
232
|
+
await mkdir(artifactsDir, { recursive: true });
|
|
233
|
+
await writeCoreArtifacts(artifactsDir, {
|
|
234
|
+
repo_manifest: repoManifest,
|
|
235
|
+
file_disposition: disposition,
|
|
236
|
+
unit_manifest: unitManifest,
|
|
237
|
+
surface_manifest: surfaceManifest,
|
|
238
|
+
critical_flows: criticalFlows,
|
|
239
|
+
flow_coverage: flowCoverage,
|
|
240
|
+
coverage_matrix: coverage,
|
|
241
|
+
runtime_validation_tasks: runtimeValidationTasks,
|
|
242
|
+
runtime_validation_report: runtimeValidationReport,
|
|
243
|
+
audit_results: sampleResults,
|
|
244
|
+
synthesis_report: synthesisReport,
|
|
245
|
+
audit_state: auditState,
|
|
246
|
+
});
|
|
247
|
+
console.log(JSON.stringify({ audit_state: auditState, artifacts_dir: artifactsDir }, null, 2));
|
|
248
|
+
}
|
|
249
|
+
async function cmdAdvanceAudit(argv) {
|
|
250
|
+
const root = getRootDir(argv);
|
|
251
|
+
const artifactsDir = getArtifactsDir(argv);
|
|
252
|
+
const sessionConfig = await loadSessionConfig(artifactsDir);
|
|
253
|
+
const providerName = resolveFreshSessionProviderName(getFlag(argv, "--provider"), sessionConfig);
|
|
254
|
+
const externalAnalyzerPath = getFlag(argv, "--external-analyzer-results");
|
|
255
|
+
const result = await runAuditStep({
|
|
256
|
+
root,
|
|
257
|
+
artifactsDir,
|
|
258
|
+
preferredExecutor: getFlag(argv, "--preferred-executor") ??
|
|
259
|
+
(externalAnalyzerPath ? "external_analyzer_import_executor" : undefined),
|
|
260
|
+
auditResultsPath: getFlag(argv, "--results"),
|
|
261
|
+
runtimeUpdatesPath: getFlag(argv, "--updates"),
|
|
262
|
+
externalAnalyzerPath,
|
|
263
|
+
});
|
|
264
|
+
await emitEnvelope({
|
|
265
|
+
root,
|
|
266
|
+
artifactsDir,
|
|
267
|
+
bundle: result.updated_bundle,
|
|
268
|
+
audit_state: result.audit_state,
|
|
269
|
+
selected_obligation: result.selected_obligation,
|
|
270
|
+
selected_executor: result.selected_executor,
|
|
271
|
+
progress_made: result.progress_made,
|
|
272
|
+
artifacts_written: result.artifacts_written,
|
|
273
|
+
progress_summary: result.progress_summary,
|
|
274
|
+
next_likely_step: result.next_likely_step,
|
|
275
|
+
providerName,
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
async function cmdRunToCompletion(argv) {
|
|
279
|
+
const root = getRootDir(argv);
|
|
280
|
+
const artifactsDir = getArtifactsDir(argv);
|
|
281
|
+
const sessionConfig = await loadSessionConfig(artifactsDir);
|
|
282
|
+
const provider = createFreshSessionProvider(getFlag(argv, "--provider"), sessionConfig);
|
|
283
|
+
const uiMode = getUiMode(argv, sessionConfig.ui_mode ?? "headless");
|
|
284
|
+
const maxRuns = getMaxRuns(argv);
|
|
285
|
+
const timeoutMs = sessionConfig.timeout_ms ?? 30 * 60 * 1000;
|
|
286
|
+
const selfCliPath = resolve(process.argv[1] ?? "");
|
|
287
|
+
await mkdir(artifactsDir, { recursive: true });
|
|
288
|
+
await ensureSupervisorDirs(artifactsDir);
|
|
289
|
+
let pendingAuditResultsPath = getFlag(argv, "--results");
|
|
290
|
+
let pendingRuntimeUpdatesPath = getFlag(argv, "--updates");
|
|
291
|
+
let pendingExternalAnalyzerPath = getFlag(argv, "--external-analyzer-results");
|
|
292
|
+
let runCount = 0;
|
|
293
|
+
let anyProgress = false;
|
|
294
|
+
let lastResult = null;
|
|
295
|
+
const artifactsWritten = new Set();
|
|
296
|
+
while (runCount < maxRuns) {
|
|
297
|
+
const bundle = await loadArtifactBundle(artifactsDir);
|
|
298
|
+
const decision = decideNextStep(bundle);
|
|
299
|
+
let preferredExecutor = decision.selected_executor;
|
|
300
|
+
let obligationId = decision.selected_obligation;
|
|
301
|
+
let auditResultsPath;
|
|
302
|
+
let runtimeUpdatesPath;
|
|
303
|
+
let externalAnalyzerPath;
|
|
304
|
+
if (pendingExternalAnalyzerPath) {
|
|
305
|
+
preferredExecutor = "external_analyzer_import_executor";
|
|
306
|
+
obligationId = "external_analyzer_import";
|
|
307
|
+
externalAnalyzerPath = pendingExternalAnalyzerPath;
|
|
308
|
+
}
|
|
309
|
+
else if (pendingAuditResultsPath && bundle.coverage_matrix) {
|
|
310
|
+
preferredExecutor = "result_ingestion_executor";
|
|
311
|
+
obligationId = "audit_results_ingested";
|
|
312
|
+
auditResultsPath = pendingAuditResultsPath;
|
|
313
|
+
}
|
|
314
|
+
else if (pendingRuntimeUpdatesPath && bundle.runtime_validation_tasks) {
|
|
315
|
+
preferredExecutor = "runtime_validation_update_executor";
|
|
316
|
+
obligationId = "runtime_validation_current";
|
|
317
|
+
runtimeUpdatesPath = pendingRuntimeUpdatesPath;
|
|
318
|
+
}
|
|
319
|
+
if (preferredExecutor === "agent" && provider.name === "local-subprocess") {
|
|
320
|
+
const blocker = buildManualReviewBlocker(provider.name);
|
|
321
|
+
const blockedState = buildBlockedAuditState({
|
|
322
|
+
state: bundle.audit_state ?? decision.state,
|
|
323
|
+
obligationId,
|
|
324
|
+
executor: preferredExecutor,
|
|
325
|
+
blocker,
|
|
326
|
+
});
|
|
327
|
+
await writeCoreArtifacts(artifactsDir, {
|
|
328
|
+
...bundle,
|
|
329
|
+
audit_state: blockedState,
|
|
330
|
+
});
|
|
331
|
+
await emitEnvelope({
|
|
332
|
+
root,
|
|
333
|
+
artifactsDir,
|
|
334
|
+
bundle: {
|
|
335
|
+
...bundle,
|
|
336
|
+
audit_state: blockedState,
|
|
337
|
+
},
|
|
338
|
+
audit_state: blockedState,
|
|
339
|
+
selected_obligation: obligationId,
|
|
340
|
+
selected_executor: preferredExecutor,
|
|
341
|
+
progress_made: anyProgress,
|
|
342
|
+
artifacts_written: Array.from(new Set([...artifactsWritten, "audit_state.json"])),
|
|
343
|
+
progress_summary: blocker,
|
|
344
|
+
next_likely_step: null,
|
|
345
|
+
providerName: provider.name,
|
|
346
|
+
});
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
if (!preferredExecutor) {
|
|
350
|
+
const state = bundle.audit_state ?? decision.state;
|
|
351
|
+
await emitEnvelope({
|
|
352
|
+
root,
|
|
353
|
+
artifactsDir,
|
|
354
|
+
bundle,
|
|
355
|
+
audit_state: state,
|
|
356
|
+
selected_obligation: anyProgress
|
|
357
|
+
? (lastResult?.obligation_id ?? null)
|
|
358
|
+
: null,
|
|
359
|
+
selected_executor: anyProgress
|
|
360
|
+
? (lastResult?.selected_executor ?? null)
|
|
361
|
+
: null,
|
|
362
|
+
progress_made: anyProgress,
|
|
363
|
+
artifacts_written: Array.from(artifactsWritten),
|
|
364
|
+
progress_summary: anyProgress && state.status === "complete"
|
|
365
|
+
? `Completed audit in ${runCount} fresh worker runs.`
|
|
366
|
+
: decision.reason,
|
|
367
|
+
next_likely_step: state.status === "complete" ? null : decision.selected_obligation,
|
|
368
|
+
providerName: provider.name,
|
|
369
|
+
});
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
runCount += 1;
|
|
373
|
+
const runId = buildRunId(obligationId, runCount);
|
|
374
|
+
const paths = getRunPaths(artifactsDir, runId);
|
|
375
|
+
const task = {
|
|
376
|
+
contract_version: "audit-code-worker/v1alpha1",
|
|
377
|
+
run_id: runId,
|
|
378
|
+
repo_root: root,
|
|
379
|
+
artifacts_dir: artifactsDir,
|
|
380
|
+
obligation_id: obligationId,
|
|
381
|
+
preferred_executor: preferredExecutor,
|
|
382
|
+
result_path: paths.resultPath,
|
|
383
|
+
worker_command: [
|
|
384
|
+
process.execPath,
|
|
385
|
+
selfCliPath,
|
|
386
|
+
"worker-run",
|
|
387
|
+
"--task",
|
|
388
|
+
paths.taskPath,
|
|
389
|
+
],
|
|
390
|
+
audit_results_path: auditResultsPath,
|
|
391
|
+
runtime_updates_path: runtimeUpdatesPath,
|
|
392
|
+
external_analyzer_results_path: externalAnalyzerPath,
|
|
393
|
+
};
|
|
394
|
+
const prompt = renderWorkerPrompt(task);
|
|
395
|
+
await writeWorkerTaskFiles(task, prompt, paths, artifactsDir);
|
|
396
|
+
const startedAt = new Date().toISOString();
|
|
397
|
+
let workerResult;
|
|
398
|
+
try {
|
|
399
|
+
await provider.launch({
|
|
400
|
+
repoRoot: root,
|
|
401
|
+
runId,
|
|
402
|
+
obligationId,
|
|
403
|
+
promptPath: paths.promptPath,
|
|
404
|
+
taskPath: paths.taskPath,
|
|
405
|
+
resultPath: paths.resultPath,
|
|
406
|
+
stdoutPath: paths.stdoutPath,
|
|
407
|
+
stderrPath: paths.stderrPath,
|
|
408
|
+
uiMode,
|
|
409
|
+
timeoutMs,
|
|
410
|
+
});
|
|
411
|
+
const candidate = await readJsonFile(paths.resultPath);
|
|
412
|
+
workerResult = isWorkerResult(candidate)
|
|
413
|
+
? candidate
|
|
414
|
+
: {
|
|
415
|
+
contract_version: WORKER_RESULT_CONTRACT_VERSION,
|
|
416
|
+
run_id: runId,
|
|
417
|
+
obligation_id: obligationId,
|
|
418
|
+
status: "failed",
|
|
419
|
+
progress_made: false,
|
|
420
|
+
selected_executor: preferredExecutor,
|
|
421
|
+
artifacts_written: [],
|
|
422
|
+
summary: "Worker did not emit a valid worker result.",
|
|
423
|
+
next_likely_step: decision.selected_obligation,
|
|
424
|
+
errors: ["Invalid worker result contract."],
|
|
425
|
+
};
|
|
426
|
+
}
|
|
427
|
+
catch (error) {
|
|
428
|
+
workerResult = {
|
|
429
|
+
contract_version: WORKER_RESULT_CONTRACT_VERSION,
|
|
430
|
+
run_id: runId,
|
|
431
|
+
obligation_id: obligationId,
|
|
432
|
+
status: "failed",
|
|
433
|
+
progress_made: false,
|
|
434
|
+
selected_executor: preferredExecutor,
|
|
435
|
+
artifacts_written: [],
|
|
436
|
+
summary: `Worker launch failed for ${preferredExecutor}.`,
|
|
437
|
+
next_likely_step: decision.selected_obligation,
|
|
438
|
+
errors: [error instanceof Error ? error.message : String(error)],
|
|
439
|
+
};
|
|
440
|
+
await writeJsonFile(paths.resultPath, workerResult);
|
|
441
|
+
}
|
|
442
|
+
await appendRunLedgerEntry(artifactsDir, {
|
|
443
|
+
run_id: runId,
|
|
444
|
+
provider: provider.name,
|
|
445
|
+
obligation_id: obligationId,
|
|
446
|
+
selected_executor: workerResult.selected_executor,
|
|
447
|
+
status: workerResult.status,
|
|
448
|
+
started_at: startedAt,
|
|
449
|
+
ended_at: new Date().toISOString(),
|
|
450
|
+
result_path: paths.resultPath,
|
|
451
|
+
});
|
|
452
|
+
lastResult = workerResult;
|
|
453
|
+
if (workerResult.progress_made) {
|
|
454
|
+
anyProgress = true;
|
|
455
|
+
}
|
|
456
|
+
for (const artifact of workerResult.artifacts_written) {
|
|
457
|
+
artifactsWritten.add(artifact);
|
|
458
|
+
}
|
|
459
|
+
artifactsWritten.add("run-ledger.json");
|
|
460
|
+
if (externalAnalyzerPath)
|
|
461
|
+
pendingExternalAnalyzerPath = undefined;
|
|
462
|
+
if (auditResultsPath)
|
|
463
|
+
pendingAuditResultsPath = undefined;
|
|
464
|
+
if (runtimeUpdatesPath)
|
|
465
|
+
pendingRuntimeUpdatesPath = undefined;
|
|
466
|
+
if (workerResult.status === "failed" ||
|
|
467
|
+
workerResult.status === "blocked" ||
|
|
468
|
+
workerResult.status === "no_progress") {
|
|
469
|
+
const bundleAfter = await loadArtifactBundle(artifactsDir);
|
|
470
|
+
const state = bundleAfter.audit_state ?? deriveAuditState(bundleAfter);
|
|
471
|
+
await emitEnvelope({
|
|
472
|
+
root,
|
|
473
|
+
artifactsDir,
|
|
474
|
+
bundle: bundleAfter,
|
|
475
|
+
audit_state: state,
|
|
476
|
+
selected_obligation: workerResult.obligation_id,
|
|
477
|
+
selected_executor: workerResult.selected_executor,
|
|
478
|
+
progress_made: anyProgress,
|
|
479
|
+
artifacts_written: Array.from(artifactsWritten),
|
|
480
|
+
progress_summary: workerResult.summary,
|
|
481
|
+
next_likely_step: workerResult.next_likely_step,
|
|
482
|
+
providerName: provider.name,
|
|
483
|
+
});
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
const bundle = await loadArtifactBundle(artifactsDir);
|
|
488
|
+
const decision = decideNextStep(bundle);
|
|
489
|
+
const state = bundle.audit_state ?? decision.state;
|
|
490
|
+
await emitEnvelope({
|
|
491
|
+
root,
|
|
492
|
+
artifactsDir,
|
|
493
|
+
bundle,
|
|
494
|
+
audit_state: state,
|
|
495
|
+
selected_obligation: lastResult?.obligation_id ?? decision.selected_obligation,
|
|
496
|
+
selected_executor: lastResult?.selected_executor ?? decision.selected_executor,
|
|
497
|
+
progress_made: anyProgress,
|
|
498
|
+
artifacts_written: Array.from(artifactsWritten),
|
|
499
|
+
progress_summary: `Reached max run limit (${maxRuns}) before terminal state.`,
|
|
500
|
+
next_likely_step: state.status === "complete" ? null : decision.selected_obligation,
|
|
501
|
+
providerName: provider.name,
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
async function cmdWorkerRun(argv) {
|
|
505
|
+
const taskPath = getFlag(argv, "--task");
|
|
506
|
+
if (!taskPath) {
|
|
507
|
+
throw new Error("worker-run requires --task <path>");
|
|
508
|
+
}
|
|
509
|
+
const task = await readJsonFile(taskPath);
|
|
510
|
+
let workerResult;
|
|
511
|
+
try {
|
|
512
|
+
const result = await runAuditStep({
|
|
513
|
+
root: task.repo_root,
|
|
514
|
+
artifactsDir: task.artifacts_dir,
|
|
515
|
+
preferredExecutor: task.preferred_executor,
|
|
516
|
+
auditResultsPath: task.audit_results_path,
|
|
517
|
+
runtimeUpdatesPath: task.runtime_updates_path,
|
|
518
|
+
externalAnalyzerPath: task.external_analyzer_results_path,
|
|
519
|
+
});
|
|
520
|
+
workerResult = {
|
|
521
|
+
contract_version: WORKER_RESULT_CONTRACT_VERSION,
|
|
522
|
+
run_id: task.run_id,
|
|
523
|
+
obligation_id: task.obligation_id,
|
|
524
|
+
status: result.progress_made ? "completed" : "no_progress",
|
|
525
|
+
progress_made: result.progress_made,
|
|
526
|
+
selected_executor: result.selected_executor,
|
|
527
|
+
artifacts_written: result.artifacts_written,
|
|
528
|
+
summary: result.progress_summary,
|
|
529
|
+
next_likely_step: result.next_likely_step,
|
|
530
|
+
errors: [],
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
catch (error) {
|
|
534
|
+
workerResult = {
|
|
535
|
+
contract_version: WORKER_RESULT_CONTRACT_VERSION,
|
|
536
|
+
run_id: task.run_id,
|
|
537
|
+
obligation_id: task.obligation_id,
|
|
538
|
+
status: "failed",
|
|
539
|
+
progress_made: false,
|
|
540
|
+
selected_executor: task.preferred_executor,
|
|
541
|
+
artifacts_written: [],
|
|
542
|
+
summary: `Worker failed for executor ${task.preferred_executor}.`,
|
|
543
|
+
next_likely_step: task.obligation_id,
|
|
544
|
+
errors: [error instanceof Error ? error.message : String(error)],
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
await writeJsonFile(task.result_path, workerResult);
|
|
548
|
+
console.log(JSON.stringify(workerResult, null, 2));
|
|
549
|
+
if (workerResult.status === "failed") {
|
|
550
|
+
process.exitCode = 1;
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
async function cmdImportExternalAnalyzer(argv) {
|
|
554
|
+
const artifactsDir = getArtifactsDir(argv);
|
|
555
|
+
const sourcePath = getFlag(argv, "--external-analyzer-results", `${artifactsDir}/external_analyzer_results.json`);
|
|
556
|
+
const externalAnalyzerResults = await readJsonFile(sourcePath);
|
|
557
|
+
const result = await runAuditStep({
|
|
558
|
+
root: getRootDir(argv),
|
|
559
|
+
artifactsDir,
|
|
560
|
+
preferredExecutor: "external_analyzer_import_executor",
|
|
561
|
+
externalAnalyzerPath: sourcePath,
|
|
562
|
+
});
|
|
563
|
+
console.log(JSON.stringify({
|
|
564
|
+
artifacts_dir: artifactsDir,
|
|
565
|
+
tool: externalAnalyzerResults.tool,
|
|
566
|
+
imported_count: externalAnalyzerResults.results.length,
|
|
567
|
+
selected_executor: result.selected_executor,
|
|
568
|
+
}, null, 2));
|
|
569
|
+
}
|
|
570
|
+
async function cmdIntake(argv) {
|
|
571
|
+
const artifactsDir = getArtifactsDir(argv);
|
|
572
|
+
const result = await runAuditStep({
|
|
573
|
+
root: getRootDir(argv),
|
|
574
|
+
artifactsDir,
|
|
575
|
+
preferredExecutor: "intake_executor",
|
|
576
|
+
});
|
|
577
|
+
console.log(JSON.stringify({
|
|
578
|
+
artifacts_dir: artifactsDir,
|
|
579
|
+
selected_executor: result.selected_executor,
|
|
580
|
+
progress_summary: result.progress_summary,
|
|
581
|
+
}, null, 2));
|
|
582
|
+
}
|
|
583
|
+
async function cmdPlan(argv) {
|
|
584
|
+
const artifactsDir = getArtifactsDir(argv);
|
|
585
|
+
const result = await runAuditStep({ root: getRootDir(argv), artifactsDir });
|
|
586
|
+
console.log(JSON.stringify({
|
|
587
|
+
artifacts_dir: artifactsDir,
|
|
588
|
+
selected_executor: result.selected_executor,
|
|
589
|
+
progress_summary: result.progress_summary,
|
|
590
|
+
next_likely_step: result.next_likely_step,
|
|
591
|
+
}, null, 2));
|
|
592
|
+
}
|
|
593
|
+
async function cmdIngestResults(argv) {
|
|
594
|
+
const artifactsDir = getArtifactsDir(argv);
|
|
595
|
+
const result = await runAuditStep({
|
|
596
|
+
root: getRootDir(argv),
|
|
597
|
+
artifactsDir,
|
|
598
|
+
preferredExecutor: "result_ingestion_executor",
|
|
599
|
+
auditResultsPath: getFlag(argv, "--results"),
|
|
600
|
+
});
|
|
601
|
+
console.log(JSON.stringify({
|
|
602
|
+
artifacts_dir: artifactsDir,
|
|
603
|
+
selected_executor: result.selected_executor,
|
|
604
|
+
progress_summary: result.progress_summary,
|
|
605
|
+
}, null, 2));
|
|
606
|
+
}
|
|
607
|
+
async function cmdUpdateRuntimeValidation(argv) {
|
|
608
|
+
const artifactsDir = getArtifactsDir(argv);
|
|
609
|
+
const result = await runAuditStep({
|
|
610
|
+
root: getRootDir(argv),
|
|
611
|
+
artifactsDir,
|
|
612
|
+
preferredExecutor: "runtime_validation_update_executor",
|
|
613
|
+
runtimeUpdatesPath: getFlag(argv, "--updates"),
|
|
614
|
+
});
|
|
615
|
+
console.log(JSON.stringify({
|
|
616
|
+
artifacts_dir: artifactsDir,
|
|
617
|
+
selected_executor: result.selected_executor,
|
|
618
|
+
progress_summary: result.progress_summary,
|
|
619
|
+
}, null, 2));
|
|
620
|
+
}
|
|
621
|
+
async function cmdValidate(argv) {
|
|
622
|
+
const artifactsDir = getArtifactsDir(argv);
|
|
623
|
+
const bundle = await loadArtifactBundle(artifactsDir);
|
|
624
|
+
const sessionConfigPath = getSessionConfigPath(artifactsDir);
|
|
625
|
+
const rawSessionConfig = await readSessionConfigFile(artifactsDir);
|
|
626
|
+
const artifactIssues = validateArtifactBundle(bundle);
|
|
627
|
+
const sessionConfigIssues = rawSessionConfig === undefined
|
|
628
|
+
? []
|
|
629
|
+
: prefixValidationIssues("session_config", validateSessionConfig(rawSessionConfig));
|
|
630
|
+
const providerIssues = rawSessionConfig === undefined || sessionConfigIssues.length > 0
|
|
631
|
+
? []
|
|
632
|
+
: prefixValidationIssues("session_config", validateConfiguredProviderEnvironment(rawSessionConfig));
|
|
633
|
+
const issues = [
|
|
634
|
+
...artifactIssues,
|
|
635
|
+
...sessionConfigIssues,
|
|
636
|
+
...providerIssues,
|
|
637
|
+
];
|
|
638
|
+
const resolvedProvider = rawSessionConfig === undefined
|
|
639
|
+
? "local-subprocess"
|
|
640
|
+
: sessionConfigIssues.length > 0
|
|
641
|
+
? null
|
|
642
|
+
: resolveFreshSessionProviderName(undefined, rawSessionConfig);
|
|
643
|
+
console.log(JSON.stringify({
|
|
644
|
+
artifacts_dir: artifactsDir,
|
|
645
|
+
session_config_path: sessionConfigPath,
|
|
646
|
+
session_config_present: rawSessionConfig !== undefined,
|
|
647
|
+
resolved_provider: resolvedProvider,
|
|
648
|
+
artifact_issue_count: artifactIssues.length,
|
|
649
|
+
session_config_issue_count: sessionConfigIssues.length + providerIssues.length,
|
|
650
|
+
issue_count: issues.length,
|
|
651
|
+
issues,
|
|
652
|
+
}, null, 2));
|
|
653
|
+
process.exitCode = issues.length > 0 ? 1 : 0;
|
|
654
|
+
}
|
|
655
|
+
async function cmdRequeue(argv) {
|
|
656
|
+
const artifactsDir = getArtifactsDir(argv);
|
|
657
|
+
const bundle = await loadArtifactBundle(artifactsDir);
|
|
658
|
+
console.log(JSON.stringify({
|
|
659
|
+
artifacts_dir: artifactsDir,
|
|
660
|
+
task_count: bundle.requeue_tasks?.length ?? 0,
|
|
661
|
+
}, null, 2));
|
|
662
|
+
}
|
|
663
|
+
async function cmdSynthesize(argv) {
|
|
664
|
+
const artifactsDir = getArtifactsDir(argv);
|
|
665
|
+
const result = await runAuditStep({
|
|
666
|
+
root: getRootDir(argv),
|
|
667
|
+
artifactsDir,
|
|
668
|
+
preferredExecutor: "synthesis_executor",
|
|
669
|
+
});
|
|
670
|
+
console.log(JSON.stringify({
|
|
671
|
+
artifacts_dir: artifactsDir,
|
|
672
|
+
selected_executor: result.selected_executor,
|
|
673
|
+
progress_summary: result.progress_summary,
|
|
674
|
+
}, null, 2));
|
|
675
|
+
}
|
|
676
|
+
async function main(argv) {
|
|
677
|
+
const command = argv[2] ?? "sample-run";
|
|
678
|
+
switch (command) {
|
|
679
|
+
case "sample-run":
|
|
680
|
+
await runSample();
|
|
681
|
+
return;
|
|
682
|
+
case "advance-audit":
|
|
683
|
+
await cmdAdvanceAudit(argv);
|
|
684
|
+
return;
|
|
685
|
+
case "run-to-completion":
|
|
686
|
+
await cmdRunToCompletion(argv);
|
|
687
|
+
return;
|
|
688
|
+
case "worker-run":
|
|
689
|
+
await cmdWorkerRun(argv);
|
|
690
|
+
return;
|
|
691
|
+
case "import-external-analyzer":
|
|
692
|
+
await cmdImportExternalAnalyzer(argv);
|
|
693
|
+
return;
|
|
694
|
+
case "intake":
|
|
695
|
+
await cmdIntake(argv);
|
|
696
|
+
return;
|
|
697
|
+
case "plan":
|
|
698
|
+
await cmdPlan(argv);
|
|
699
|
+
return;
|
|
700
|
+
case "ingest-results":
|
|
701
|
+
await cmdIngestResults(argv);
|
|
702
|
+
return;
|
|
703
|
+
case "update-runtime-validation":
|
|
704
|
+
await cmdUpdateRuntimeValidation(argv);
|
|
705
|
+
return;
|
|
706
|
+
case "validate":
|
|
707
|
+
await cmdValidate(argv);
|
|
708
|
+
return;
|
|
709
|
+
case "requeue":
|
|
710
|
+
await cmdRequeue(argv);
|
|
711
|
+
return;
|
|
712
|
+
case "synthesize":
|
|
713
|
+
await cmdSynthesize(argv);
|
|
714
|
+
return;
|
|
715
|
+
default:
|
|
716
|
+
console.error(`Unknown command: ${command}`);
|
|
717
|
+
console.error("Available commands: sample-run, advance-audit, run-to-completion, worker-run, import-external-analyzer, intake, plan, ingest-results, update-runtime-validation, validate, requeue, synthesize");
|
|
718
|
+
process.exitCode = 1;
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
await main(process.argv).catch((error) => {
|
|
722
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
723
|
+
process.exitCode = 1;
|
|
724
|
+
});
|