auditor-lambda 0.10.3 → 0.10.8
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/audit-code-wrapper-build.mjs +198 -0
- package/audit-code-wrapper-install-hosts.mjs +1140 -0
- package/audit-code-wrapper-io.mjs +155 -0
- package/audit-code-wrapper-legacy.mjs +125 -0
- package/audit-code-wrapper-lib.mjs +22 -1806
- package/audit-code-wrapper-opencode.mjs +255 -0
- package/dispatch/merge-results.mjs +5 -3
- package/dispatch/validate-result.mjs +2 -2
- package/dist/adapters/coverageSummary.js +6 -2
- package/dist/adapters/normalizeExternal.js +16 -1
- package/dist/adapters/npmAudit.js +20 -9
- package/dist/adapters/semgrep.js +26 -1
- package/dist/cli/advanceAuditCommand.d.ts +1 -0
- package/dist/cli/advanceAuditCommand.js +95 -0
- package/dist/cli/args.js +2 -3
- package/dist/cli/auditStep.js +2 -2
- package/dist/cli/cleanup.d.ts +11 -1
- package/dist/cli/cleanup.js +25 -5
- package/dist/cli/cleanupCommand.d.ts +1 -0
- package/dist/cli/cleanupCommand.js +24 -0
- package/dist/cli/dispatch.d.ts +55 -31
- package/dist/cli/dispatch.js +298 -241
- package/dist/cli/dispatchStatusCommand.d.ts +1 -0
- package/dist/cli/dispatchStatusCommand.js +68 -0
- package/dist/cli/explainTaskCommand.d.ts +1 -0
- package/dist/cli/explainTaskCommand.js +33 -0
- package/dist/cli/importExternalAnalyzerCommand.d.ts +1 -0
- package/dist/cli/importExternalAnalyzerCommand.js +20 -0
- package/dist/cli/ingestResultsCommand.d.ts +1 -0
- package/dist/cli/ingestResultsCommand.js +34 -0
- package/dist/cli/intakeCommand.d.ts +1 -0
- package/dist/cli/intakeCommand.js +17 -0
- package/dist/cli/lineIndex.js +19 -12
- package/dist/cli/nextStepCommand.d.ts +139 -0
- package/dist/cli/nextStepCommand.js +281 -234
- package/dist/cli/planCommand.d.ts +1 -0
- package/dist/cli/planCommand.js +16 -0
- package/dist/cli/prepareDispatchCommand.d.ts +1 -0
- package/dist/cli/prepareDispatchCommand.js +25 -0
- package/dist/cli/quotaCommand.d.ts +1 -0
- package/dist/cli/quotaCommand.js +56 -0
- package/dist/cli/requeueCommand.d.ts +1 -0
- package/dist/cli/requeueCommand.js +10 -0
- package/dist/cli/runToCompletion.js +451 -412
- package/dist/cli/sampleRunCommand.d.ts +1 -0
- package/dist/cli/sampleRunCommand.js +93 -0
- package/dist/cli/statusCommand.js +1 -1
- package/dist/cli/steps.js +4 -1
- package/dist/cli/submitPacketCommand.js +16 -15
- package/dist/cli/synthesizeCommand.d.ts +1 -0
- package/dist/cli/synthesizeCommand.js +15 -0
- package/dist/cli/updateRuntimeValidationCommand.d.ts +1 -0
- package/dist/cli/updateRuntimeValidationCommand.js +16 -0
- package/dist/cli/validateCommand.d.ts +1 -0
- package/dist/cli/validateCommand.js +41 -0
- package/dist/cli/validateResultCommand.d.ts +1 -0
- package/dist/cli/validateResultCommand.js +63 -0
- package/dist/cli/validateResultsCommand.d.ts +1 -0
- package/dist/cli/validateResultsCommand.js +31 -0
- package/dist/cli/workerRunCommand.d.ts +15 -1
- package/dist/cli/workerRunCommand.js +40 -4
- package/dist/cli.d.ts +3 -2
- package/dist/cli.js +21 -628
- package/dist/coverage.js +7 -3
- package/dist/extractors/analyzers/css.js +2 -2
- package/dist/extractors/analyzers/html.js +2 -2
- package/dist/extractors/analyzers/python.js +2 -2
- package/dist/extractors/analyzers/registry.js +17 -36
- package/dist/extractors/analyzers/treeSitter.d.ts +10 -1
- package/dist/extractors/analyzers/treeSitter.js +28 -6
- package/dist/extractors/analyzers/typescript.js +104 -85
- package/dist/extractors/browserExtension.js +4 -1
- package/dist/extractors/designAssessment.js +21 -21
- package/dist/extractors/fsIntake.js +35 -11
- package/dist/extractors/graph.js +17 -7
- package/dist/extractors/graphManifestEdges/cargo.d.ts +4 -0
- package/dist/extractors/graphManifestEdges/cargo.js +107 -0
- package/dist/extractors/graphManifestEdges/go.d.ts +5 -0
- package/dist/extractors/graphManifestEdges/go.js +151 -0
- package/dist/extractors/graphManifestEdges/index.d.ts +8 -0
- package/dist/extractors/graphManifestEdges/index.js +11 -0
- package/dist/extractors/graphManifestEdges/jsonc.d.ts +3 -0
- package/dist/extractors/graphManifestEdges/jsonc.js +97 -0
- package/dist/extractors/graphManifestEdges/maven.d.ts +3 -0
- package/dist/extractors/graphManifestEdges/maven.js +73 -0
- package/dist/extractors/graphManifestEdges/packageJson.d.ts +19 -0
- package/dist/extractors/graphManifestEdges/packageJson.js +204 -0
- package/dist/extractors/graphManifestEdges/pnpm.d.ts +2 -0
- package/dist/extractors/graphManifestEdges/pnpm.js +42 -0
- package/dist/extractors/graphManifestEdges/pyproject.d.ts +3 -0
- package/dist/extractors/graphManifestEdges/pyproject.js +83 -0
- package/dist/extractors/graphManifestEdges/toml.d.ts +4 -0
- package/dist/extractors/graphManifestEdges/toml.js +68 -0
- package/dist/extractors/graphManifestEdges/typescript.d.ts +3 -0
- package/dist/extractors/graphManifestEdges/typescript.js +56 -0
- package/dist/extractors/graphManifestEdges/workspace.d.ts +10 -0
- package/dist/extractors/graphManifestEdges/workspace.js +72 -0
- package/dist/extractors/graphManifestEdges/yaml.d.ts +3 -0
- package/dist/extractors/graphManifestEdges/yaml.js +59 -0
- package/dist/extractors/graphManifestEdges/yamlPaths.d.ts +4 -0
- package/dist/extractors/graphManifestEdges/yamlPaths.js +89 -0
- package/dist/extractors/graphPythonImports.js +4 -20
- package/dist/extractors/pathPatterns.js +3 -13
- package/dist/io/artifacts.d.ts +1 -2
- package/dist/io/artifacts.js +8 -4
- package/dist/io/runArtifacts.d.ts +8 -2
- package/dist/io/runArtifacts.js +103 -69
- package/dist/io/toolingManifest.js +2 -1
- package/dist/orchestrator/advance.js +36 -0
- package/dist/orchestrator/artifactFreshness.d.ts +1 -1
- package/dist/orchestrator/artifactFreshness.js +1 -1
- package/dist/orchestrator/artifactMetadata.js +5 -5
- package/dist/orchestrator/auditTaskUtils.d.ts +4 -0
- package/dist/orchestrator/auditTaskUtils.js +8 -12
- package/dist/orchestrator/autoFixExecutor.js +40 -26
- package/dist/orchestrator/dependencyMap.js +1 -1
- package/dist/orchestrator/executorResult.d.ts +33 -0
- package/dist/orchestrator/executors.d.ts +7 -0
- package/dist/orchestrator/executors.js +24 -0
- package/dist/orchestrator/fileAnchors.js +42 -29
- package/dist/orchestrator/fileIntegrity.js +6 -1
- package/dist/orchestrator/flowCoverage.js +1 -2
- package/dist/orchestrator/flowPlanning.js +8 -4
- package/dist/orchestrator/graphEnrichmentExecutor.js +67 -45
- package/dist/orchestrator/ingestionExecutors.js +9 -1
- package/dist/orchestrator/intakeExecutors.d.ts +0 -4
- package/dist/orchestrator/intakeExecutors.js +24 -14
- package/dist/orchestrator/localCommands.d.ts +1 -0
- package/dist/orchestrator/localCommands.js +10 -17
- package/dist/orchestrator/nextStep.js +3 -1
- package/dist/orchestrator/requeueCommand.js +4 -0
- package/dist/orchestrator/reviewPacketGraph.js +50 -18
- package/dist/orchestrator/reviewPackets.js +10 -8
- package/dist/orchestrator/runtimeCommand.js +35 -7
- package/dist/orchestrator/runtimeValidationUpdate.js +6 -0
- package/dist/orchestrator/selectiveDeepening/highRiskClean.js +3 -2
- package/dist/orchestrator/selectiveDeepening/lensVerification.js +44 -18
- package/dist/orchestrator/staleness.js +3 -3
- package/dist/orchestrator/state.js +1 -1
- package/dist/orchestrator/syntaxResolutionExecutor.js +17 -24
- package/dist/orchestrator/synthesisExecutors.js +1 -0
- package/dist/orchestrator/taskBuilder.js +5 -4
- package/dist/providers/claudeCodeProvider.js +5 -2
- package/dist/providers/opencodeProvider.js +4 -1
- package/dist/quota/discoveredLimits.js +3 -3
- package/dist/quota/headerExtraction.js +5 -2
- package/dist/quota/headerExtractors/claudeCodeHeaderExtractor.js +3 -0
- package/dist/quota/headerExtractors/index.js +3 -3
- package/dist/quota/index.d.ts +3 -1
- package/dist/quota/index.js +3 -0
- package/dist/reporting/findingRanks.d.ts +3 -0
- package/dist/reporting/findingRanks.js +24 -0
- package/dist/reporting/mergeFindings.js +1 -24
- package/dist/reporting/synthesis.d.ts +3 -1
- package/dist/reporting/synthesis.js +30 -6
- package/dist/reporting/synthesisNarrativePrompt.js +3 -0
- package/dist/reporting/workBlocks.js +1 -14
- package/dist/supervisor/operatorHandoff.js +2 -6
- package/dist/supervisor/runLedger.js +30 -41
- package/dist/types/activeDispatch.d.ts +31 -0
- package/dist/types/activeDispatch.js +2 -0
- package/dist/types.d.ts +21 -4
- package/dist/types.js +24 -16
- package/dist/validation/artifacts.js +3 -0
- package/dist/validation/auditResults.js +8 -2
- package/package.json +2 -2
- package/schemas/audit_findings.schema.json +5 -1
- package/schemas/audit_plan_metrics.schema.json +1 -1
- package/schemas/audit_result.schema.json +5 -6
- package/schemas/audit_task.schema.json +1 -4
- package/schemas/blind_spot_register.schema.json +1 -1
- package/schemas/coverage_matrix.schema.json +2 -8
- package/schemas/finding.schema.json +1 -16
- package/schemas/flow_coverage.schema.json +2 -8
- package/schemas/graph_bundle.schema.json +31 -0
- package/schemas/lens.schema.json +7 -0
- package/schemas/review_packets.schema.json +6 -17
- package/schemas/step_contract.schema.json +8 -2
- package/schemas/unit_manifest.schema.json +1 -4
- package/scripts/postinstall.mjs +4 -3
- package/skills/audit-code/audit-code.prompt.md +3 -4
- package/dist/extractors/graphManifestEdges.d.ts +0 -12
- package/dist/extractors/graphManifestEdges.js +0 -1135
package/dist/cli.js
CHANGED
|
@@ -1,47 +1,32 @@
|
|
|
1
|
-
import { mkdir, readFile, rm, } from "node:fs/promises";
|
|
2
1
|
import { homedir } from "node:os";
|
|
3
|
-
import { join, resolve
|
|
2
|
+
import { join, resolve } from "node:path";
|
|
4
3
|
import { fileURLToPath } from "node:url";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { buildCriticalFlowManifest } from "./extractors/flows.js";
|
|
8
|
-
import { buildSurfaceManifest } from "./extractors/surfaces.js";
|
|
9
|
-
import { buildUnitManifest } from "./orchestrator/unitBuilder.js";
|
|
10
|
-
import { buildFlowCoverage } from "./orchestrator/flowCoverage.js";
|
|
11
|
-
import { buildRuntimeValidationTasks, } from "./orchestrator/runtimeValidation.js";
|
|
12
|
-
import { initializeCoverageFromPlan } from "./orchestrator/planning.js";
|
|
13
|
-
import { loadArtifactBundle, writeCoreArtifacts, promoteFinalAuditReport, } from "./io/artifacts.js";
|
|
14
|
-
import { isFileMissingError, readJsonFile, prefixValidationIssues, DEFAULT_EMPIRICAL_HALF_LIFE_HOURS, } from "@audit-tools/shared";
|
|
15
|
-
import { buildQuotaSource } from "@audit-tools/shared/quota/compositeQuotaSource";
|
|
16
|
-
import { validateArtifactBundle } from "./validation/artifacts.js";
|
|
17
|
-
import { validateAuditResults, } from "./validation/auditResults.js";
|
|
18
|
-
import { validateConfiguredProviderEnvironment, validateSessionConfig, } from "./validation/sessionConfig.js";
|
|
19
|
-
import { buildAuditReportModel, renderAuditReportMarkdown, } from "./reporting/synthesis.js";
|
|
20
|
-
import { deriveAuditState } from "./orchestrator/state.js";
|
|
21
|
-
import { createFreshSessionProvider, resolveFreshSessionProviderName, } from "./providers/index.js";
|
|
22
|
-
import { getSessionConfigPath, loadSessionConfig, readSessionConfigFile, } from "./supervisor/sessionConfig.js";
|
|
23
|
-
import { clearDispatchFiles, ensureSupervisorDirs, } from "./io/runArtifacts.js";
|
|
24
|
-
import { scheduleWave, buildProviderModelKey, readQuotaState, resolveLimits, resolveHostActiveSubagentLimit, computeMaxSafeConcurrency, getQuotaStatePath, lookupDiscoveredLimits, setQuotaStateDir, } from "./quota/index.js";
|
|
25
|
-
import { DIRECT_CLI_DEFAULTS, getFlag, hasFlag, fromBase64Url, taskResultPath, getArtifactsDir, getRootDir, warnIfNotGitRepo, getBatchResultsDir, getMaxRuns, getAgentBatchSize, getParallelWorkers, getTimeoutMs, getExplicitProvider, getHostModel, getHostMaxActiveSubagents, resolveRunProviderName, chunkArray, getUiMode, looksLikeCliFlag, countLines, } from "./cli/args.js";
|
|
26
|
-
import { ACTIVE_DISPATCH_FILENAME, loadDispatchResultMap, prepareDispatchArtifacts, } from "./cli/dispatch.js";
|
|
27
|
-
import { buildLineIndex, } from "./cli/lineIndex.js";
|
|
28
|
-
import { emitEnvelope, } from "./cli/envelope.js";
|
|
29
|
-
import { persistConfigErrorHandoff } from "./cli/reviewRun.js";
|
|
30
|
-
import { runAuditStep, ingestBatchAuditResults, } from "./cli/auditStep.js";
|
|
31
|
-
import { packageRoot } from "./cli/paths.js";
|
|
4
|
+
import { setQuotaStateDir, } from "./quota/index.js";
|
|
5
|
+
import { DIRECT_CLI_DEFAULTS, getFlag, hasFlag, getArtifactsDir, getRootDir, getBatchResultsDir, getMaxRuns, getAgentBatchSize, getParallelWorkers, getTimeoutMs, chunkArray, getUiMode, looksLikeCliFlag, countLines, warnIfNotGitRepo, } from "./cli/args.js";
|
|
32
6
|
import { cmdNextStep } from "./cli/nextStepCommand.js";
|
|
33
7
|
import { cmdRunToCompletion } from "./cli/runToCompletion.js";
|
|
34
8
|
import { cmdWorkerRun } from "./cli/workerRunCommand.js";
|
|
35
9
|
import { cmdSubmitPacket } from "./cli/submitPacketCommand.js";
|
|
36
10
|
import { cmdMergeAndIngest } from "./cli/mergeAndIngestCommand.js";
|
|
37
11
|
import { cmdStatus } from "./cli/statusCommand.js";
|
|
38
|
-
import {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
12
|
+
import { runSample } from "./cli/sampleRunCommand.js";
|
|
13
|
+
import { cmdAdvanceAudit } from "./cli/advanceAuditCommand.js";
|
|
14
|
+
import { cmdPrepareDispatch } from "./cli/prepareDispatchCommand.js";
|
|
15
|
+
import { cmdValidateResult } from "./cli/validateResultCommand.js";
|
|
16
|
+
import { cmdImportExternalAnalyzer } from "./cli/importExternalAnalyzerCommand.js";
|
|
17
|
+
import { cmdIntake } from "./cli/intakeCommand.js";
|
|
18
|
+
import { cmdPlan } from "./cli/planCommand.js";
|
|
19
|
+
import { cmdIngestResults } from "./cli/ingestResultsCommand.js";
|
|
20
|
+
import { cmdExplainTask } from "./cli/explainTaskCommand.js";
|
|
21
|
+
import { cmdUpdateRuntimeValidation } from "./cli/updateRuntimeValidationCommand.js";
|
|
22
|
+
import { cmdValidate } from "./cli/validateCommand.js";
|
|
23
|
+
import { cmdValidateResults } from "./cli/validateResultsCommand.js";
|
|
24
|
+
import { cmdRequeue } from "./cli/requeueCommand.js";
|
|
25
|
+
import { cmdSynthesize } from "./cli/synthesizeCommand.js";
|
|
26
|
+
import { cmdCleanup } from "./cli/cleanupCommand.js";
|
|
27
|
+
import { cmdQuota } from "./cli/quotaCommand.js";
|
|
28
|
+
import { cmdDispatchStatus } from "./cli/dispatchStatusCommand.js";
|
|
29
|
+
export { runSample };
|
|
45
30
|
export const cliTestUtils = {
|
|
46
31
|
defaults: DIRECT_CLI_DEFAULTS,
|
|
47
32
|
getFlag,
|
|
@@ -59,598 +44,6 @@ export const cliTestUtils = {
|
|
|
59
44
|
countLines,
|
|
60
45
|
warnIfNotGitRepo,
|
|
61
46
|
};
|
|
62
|
-
export async function runSample(argv = process.argv) {
|
|
63
|
-
const repoManifest = buildRepoManifest("sample-repo", SAMPLE_REPO_FILES);
|
|
64
|
-
const disposition = buildFileDisposition(repoManifest);
|
|
65
|
-
const unitManifest = buildUnitManifest(repoManifest, disposition);
|
|
66
|
-
const surfaceManifest = buildSurfaceManifest(repoManifest, disposition);
|
|
67
|
-
const criticalFlows = buildCriticalFlowManifest(repoManifest, surfaceManifest, disposition);
|
|
68
|
-
const coverage = initializeCoverageFromPlan(repoManifest, unitManifest, disposition);
|
|
69
|
-
const sampleResults = [
|
|
70
|
-
{
|
|
71
|
-
task_id: "src-api:security:src/api/auth.ts:1-100",
|
|
72
|
-
unit_id: unitManifest.units[0]?.unit_id ?? "sample-unit",
|
|
73
|
-
pass_id: "pass:security",
|
|
74
|
-
lens: "security",
|
|
75
|
-
agent_role: "security-auditor",
|
|
76
|
-
file_coverage: [{ path: "src/api/auth.ts", total_lines: 100 }],
|
|
77
|
-
findings: [],
|
|
78
|
-
notes: ["Sample result ingestion path."],
|
|
79
|
-
requires_followup: false,
|
|
80
|
-
},
|
|
81
|
-
];
|
|
82
|
-
const flowCoverage = buildFlowCoverage(criticalFlows, coverage);
|
|
83
|
-
const runtimeValidationTasks = buildRuntimeValidationTasks({
|
|
84
|
-
unitManifest,
|
|
85
|
-
criticalFlows,
|
|
86
|
-
flowCoverage,
|
|
87
|
-
command: ["npm", "test"],
|
|
88
|
-
});
|
|
89
|
-
const runtimeValidationReport = {
|
|
90
|
-
results: runtimeValidationTasks.tasks.map((task) => ({
|
|
91
|
-
task_id: task.id,
|
|
92
|
-
status: "confirmed",
|
|
93
|
-
summary: "Sample runtime validation completed.",
|
|
94
|
-
evidence: [],
|
|
95
|
-
notes: [],
|
|
96
|
-
})),
|
|
97
|
-
};
|
|
98
|
-
const auditReport = renderAuditReportMarkdown(buildAuditReportModel({
|
|
99
|
-
results: sampleResults,
|
|
100
|
-
unitManifest,
|
|
101
|
-
criticalFlows,
|
|
102
|
-
coverageMatrix: coverage,
|
|
103
|
-
runtimeValidationReport,
|
|
104
|
-
}));
|
|
105
|
-
const auditState = deriveAuditState({
|
|
106
|
-
repo_manifest: repoManifest,
|
|
107
|
-
file_disposition: disposition,
|
|
108
|
-
unit_manifest: unitManifest,
|
|
109
|
-
surface_manifest: surfaceManifest,
|
|
110
|
-
critical_flows: criticalFlows,
|
|
111
|
-
flow_coverage: flowCoverage,
|
|
112
|
-
coverage_matrix: coverage,
|
|
113
|
-
runtime_validation_tasks: runtimeValidationTasks,
|
|
114
|
-
runtime_validation_report: runtimeValidationReport,
|
|
115
|
-
audit_results: sampleResults,
|
|
116
|
-
audit_report: auditReport,
|
|
117
|
-
});
|
|
118
|
-
const artifactsDir = getArtifactsDir(argv);
|
|
119
|
-
await mkdir(artifactsDir, { recursive: true });
|
|
120
|
-
await writeCoreArtifacts(artifactsDir, {
|
|
121
|
-
repo_manifest: repoManifest,
|
|
122
|
-
file_disposition: disposition,
|
|
123
|
-
unit_manifest: unitManifest,
|
|
124
|
-
surface_manifest: surfaceManifest,
|
|
125
|
-
critical_flows: criticalFlows,
|
|
126
|
-
flow_coverage: flowCoverage,
|
|
127
|
-
coverage_matrix: coverage,
|
|
128
|
-
runtime_validation_tasks: runtimeValidationTasks,
|
|
129
|
-
runtime_validation_report: runtimeValidationReport,
|
|
130
|
-
audit_results: sampleResults,
|
|
131
|
-
audit_report: auditReport,
|
|
132
|
-
audit_state: auditState,
|
|
133
|
-
});
|
|
134
|
-
console.log(JSON.stringify({ audit_state: auditState, artifacts_dir: artifactsDir }, null, 2));
|
|
135
|
-
}
|
|
136
|
-
async function cmdAdvanceAudit(argv) {
|
|
137
|
-
const root = getRootDir(argv);
|
|
138
|
-
warnIfNotGitRepo(root);
|
|
139
|
-
const artifactsDir = getArtifactsDir(argv);
|
|
140
|
-
await cleanupStaleArtifactsDir(artifactsDir);
|
|
141
|
-
await mkdir(artifactsDir, { recursive: true });
|
|
142
|
-
await ensureSupervisorDirs(artifactsDir);
|
|
143
|
-
let sessionConfig;
|
|
144
|
-
try {
|
|
145
|
-
sessionConfig = await loadSessionConfig(artifactsDir);
|
|
146
|
-
}
|
|
147
|
-
catch (error) {
|
|
148
|
-
await persistConfigErrorHandoff({
|
|
149
|
-
root,
|
|
150
|
-
artifactsDir,
|
|
151
|
-
progressSummary: error instanceof Error ? error.message : String(error),
|
|
152
|
-
});
|
|
153
|
-
throw error;
|
|
154
|
-
}
|
|
155
|
-
const providerName = resolveRunProviderName(argv, sessionConfig);
|
|
156
|
-
const batchResultsDir = getBatchResultsDir(argv);
|
|
157
|
-
if (batchResultsDir && getFlag(argv, "--results")) {
|
|
158
|
-
throw new Error("Use either --results <file> or --batch-results <dir>, not both.");
|
|
159
|
-
}
|
|
160
|
-
if (batchResultsDir) {
|
|
161
|
-
const result = await ingestBatchAuditResults({
|
|
162
|
-
root,
|
|
163
|
-
artifactsDir,
|
|
164
|
-
batchDir: batchResultsDir,
|
|
165
|
-
});
|
|
166
|
-
if (result.selected_executor !== "agent") {
|
|
167
|
-
await clearDispatchFiles(artifactsDir);
|
|
168
|
-
}
|
|
169
|
-
await emitEnvelope({
|
|
170
|
-
root,
|
|
171
|
-
artifactsDir,
|
|
172
|
-
bundle: result.bundle,
|
|
173
|
-
audit_state: result.audit_state,
|
|
174
|
-
selected_obligation: result.selected_obligation,
|
|
175
|
-
selected_executor: result.selected_executor,
|
|
176
|
-
progress_made: result.progress_made,
|
|
177
|
-
artifacts_written: result.artifacts_written,
|
|
178
|
-
progress_summary: result.progress_summary,
|
|
179
|
-
next_likely_step: result.next_likely_step,
|
|
180
|
-
providerName,
|
|
181
|
-
});
|
|
182
|
-
if (result.audit_state.status === "complete") {
|
|
183
|
-
await promoteFinalAuditReport({ artifactsDir, repoRoot: root });
|
|
184
|
-
}
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
const externalAnalyzerPath = getFlag(argv, "--external-analyzer-results");
|
|
188
|
-
const result = await runAuditStep({
|
|
189
|
-
root,
|
|
190
|
-
artifactsDir,
|
|
191
|
-
preferredExecutor: getFlag(argv, "--preferred-executor") ??
|
|
192
|
-
(externalAnalyzerPath ? "external_analyzer_import_executor" : undefined),
|
|
193
|
-
auditResultsPath: getFlag(argv, "--results"),
|
|
194
|
-
runtimeUpdatesPath: getFlag(argv, "--updates"),
|
|
195
|
-
externalAnalyzerPath,
|
|
196
|
-
analyzers: sessionConfig.analyzers,
|
|
197
|
-
graphLlmEdgeReasoning: sessionConfig.graph?.llm_edge_reasoning,
|
|
198
|
-
since: getFlag(argv, "--since"),
|
|
199
|
-
opentoken: sessionConfig.opentoken?.enabled,
|
|
200
|
-
runLog: sessionConfig.observability?.run_log,
|
|
201
|
-
});
|
|
202
|
-
if (result.selected_executor !== "agent") {
|
|
203
|
-
await clearDispatchFiles(artifactsDir);
|
|
204
|
-
}
|
|
205
|
-
await emitEnvelope({
|
|
206
|
-
root,
|
|
207
|
-
artifactsDir,
|
|
208
|
-
bundle: result.updated_bundle,
|
|
209
|
-
audit_state: result.audit_state,
|
|
210
|
-
selected_obligation: result.selected_obligation,
|
|
211
|
-
selected_executor: result.selected_executor,
|
|
212
|
-
progress_made: result.progress_made,
|
|
213
|
-
artifacts_written: result.artifacts_written,
|
|
214
|
-
progress_summary: result.progress_summary,
|
|
215
|
-
next_likely_step: result.next_likely_step,
|
|
216
|
-
providerName,
|
|
217
|
-
});
|
|
218
|
-
if (result.audit_state.status === "complete") {
|
|
219
|
-
await promoteFinalAuditReport({ artifactsDir, repoRoot: root });
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
async function cmdPrepareDispatch(argv) {
|
|
223
|
-
const runId = getFlag(argv, "--run-id");
|
|
224
|
-
if (!runId)
|
|
225
|
-
throw new Error("prepare-dispatch requires --run-id <run_id>");
|
|
226
|
-
const artifactsDir = getArtifactsDir(argv);
|
|
227
|
-
const sessionConfig = await loadSessionConfig(artifactsDir).catch(() => ({}));
|
|
228
|
-
const provider = createFreshSessionProvider(getExplicitProvider(argv), sessionConfig);
|
|
229
|
-
const hostModel = getHostModel(argv) ?? sessionConfig.block_quota?.host_model ?? null;
|
|
230
|
-
const result = await prepareDispatchArtifacts({
|
|
231
|
-
packageRoot,
|
|
232
|
-
runId,
|
|
233
|
-
artifactsDir,
|
|
234
|
-
root: getFlag(argv, "--root") ? getRootDir(argv) : undefined,
|
|
235
|
-
sessionConfig,
|
|
236
|
-
hostModel,
|
|
237
|
-
queryLimits: provider.queryLimits?.bind(provider),
|
|
238
|
-
hostActiveSubagentLimit: getHostMaxActiveSubagents(argv),
|
|
239
|
-
});
|
|
240
|
-
console.log(JSON.stringify(result, null, 2));
|
|
241
|
-
}
|
|
242
|
-
async function cmdValidateResult(argv) {
|
|
243
|
-
const rawRunId = getFlag(argv, "--run-id");
|
|
244
|
-
const runIdB64 = getFlag(argv, "--run-id-b64");
|
|
245
|
-
const rawTaskId = getFlag(argv, "--task-id");
|
|
246
|
-
const artifactsDirB64 = getFlag(argv, "--artifacts-dir-b64");
|
|
247
|
-
const runId = rawRunId ?? (runIdB64 ? fromBase64Url(runIdB64) : undefined);
|
|
248
|
-
const taskIdB64 = getFlag(argv, "--task-id-b64");
|
|
249
|
-
const taskId = rawTaskId ?? (taskIdB64 ? fromBase64Url(taskIdB64) : undefined);
|
|
250
|
-
const artifactsDir = artifactsDirB64
|
|
251
|
-
? resolve(fromBase64Url(artifactsDirB64))
|
|
252
|
-
: getArtifactsDir(argv);
|
|
253
|
-
if (!runId || !taskId) {
|
|
254
|
-
throw new Error("validate-result requires --run-id and --task-id (or --run-id-b64/--task-id-b64)");
|
|
255
|
-
}
|
|
256
|
-
const runDir = join(artifactsDir, "runs", runId);
|
|
257
|
-
const taskResultsDir = join(runDir, "task-results");
|
|
258
|
-
const resultMap = await loadDispatchResultMap(runDir);
|
|
259
|
-
const resultPath = resultMap?.entries.find((entry) => entry.task_id === taskId)?.result_path ??
|
|
260
|
-
taskResultPath(taskResultsDir, taskId);
|
|
261
|
-
const tasksPath = join(runDir, "pending-audit-tasks.json");
|
|
262
|
-
let raw;
|
|
263
|
-
try {
|
|
264
|
-
raw = await readFile(resultPath, "utf8");
|
|
265
|
-
}
|
|
266
|
-
catch {
|
|
267
|
-
console.error(`File not found: ${resultPath}`);
|
|
268
|
-
process.exitCode = 1;
|
|
269
|
-
return;
|
|
270
|
-
}
|
|
271
|
-
let obj;
|
|
272
|
-
try {
|
|
273
|
-
obj = JSON.parse(raw);
|
|
274
|
-
}
|
|
275
|
-
catch (e) {
|
|
276
|
-
console.error(`Invalid JSON: ${e.message}`);
|
|
277
|
-
process.exitCode = 1;
|
|
278
|
-
return;
|
|
279
|
-
}
|
|
280
|
-
let allTasks = [];
|
|
281
|
-
try {
|
|
282
|
-
allTasks = await readJsonFile(tasksPath);
|
|
283
|
-
}
|
|
284
|
-
catch { /* may not exist */ }
|
|
285
|
-
const matchingTasks = allTasks.filter(t => t.task_id === taskId);
|
|
286
|
-
const lineIndex = matchingTasks[0]?.file_line_counts ?? {};
|
|
287
|
-
const issues = validateAuditResults([obj], matchingTasks, { lineIndex });
|
|
288
|
-
const errors = issues.filter(i => i.severity === "error");
|
|
289
|
-
if (errors.length === 0) {
|
|
290
|
-
console.log(`✓ valid: ${taskId}`);
|
|
291
|
-
}
|
|
292
|
-
else {
|
|
293
|
-
console.error(`✗ invalid: ${taskId}`);
|
|
294
|
-
for (const e of errors)
|
|
295
|
-
console.error(` ${e.path}: ${e.message}`);
|
|
296
|
-
process.exitCode = 1;
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
async function cmdImportExternalAnalyzer(argv) {
|
|
300
|
-
const artifactsDir = getArtifactsDir(argv);
|
|
301
|
-
const sourcePath = getFlag(argv, "--external-analyzer-results", `${artifactsDir}/external_analyzer_results.json`);
|
|
302
|
-
const externalAnalyzerResults = await readJsonFile(sourcePath);
|
|
303
|
-
const result = await runAuditStep({
|
|
304
|
-
root: getRootDir(argv),
|
|
305
|
-
artifactsDir,
|
|
306
|
-
preferredExecutor: "external_analyzer_import_executor",
|
|
307
|
-
externalAnalyzerPath: sourcePath,
|
|
308
|
-
});
|
|
309
|
-
console.log(JSON.stringify({
|
|
310
|
-
artifacts_dir: artifactsDir,
|
|
311
|
-
tool: externalAnalyzerResults.tool,
|
|
312
|
-
imported_count: externalAnalyzerResults.results.length,
|
|
313
|
-
selected_executor: result.selected_executor,
|
|
314
|
-
}, null, 2));
|
|
315
|
-
}
|
|
316
|
-
async function cmdIntake(argv) {
|
|
317
|
-
const root = getRootDir(argv);
|
|
318
|
-
warnIfNotGitRepo(root);
|
|
319
|
-
const artifactsDir = getArtifactsDir(argv);
|
|
320
|
-
const result = await runAuditStep({
|
|
321
|
-
root,
|
|
322
|
-
artifactsDir,
|
|
323
|
-
preferredExecutor: "intake_executor",
|
|
324
|
-
});
|
|
325
|
-
console.log(JSON.stringify({
|
|
326
|
-
artifacts_dir: artifactsDir,
|
|
327
|
-
selected_executor: result.selected_executor,
|
|
328
|
-
progress_summary: result.progress_summary,
|
|
329
|
-
}, null, 2));
|
|
330
|
-
}
|
|
331
|
-
async function cmdPlan(argv) {
|
|
332
|
-
const artifactsDir = getArtifactsDir(argv);
|
|
333
|
-
const result = await runAuditStep({
|
|
334
|
-
root: getRootDir(argv),
|
|
335
|
-
artifactsDir,
|
|
336
|
-
since: getFlag(argv, "--since"),
|
|
337
|
-
});
|
|
338
|
-
console.log(JSON.stringify({
|
|
339
|
-
artifacts_dir: artifactsDir,
|
|
340
|
-
selected_executor: result.selected_executor,
|
|
341
|
-
progress_summary: result.progress_summary,
|
|
342
|
-
next_likely_step: result.next_likely_step,
|
|
343
|
-
}, null, 2));
|
|
344
|
-
}
|
|
345
|
-
async function cmdIngestResults(argv) {
|
|
346
|
-
const artifactsDir = getArtifactsDir(argv);
|
|
347
|
-
const batchResultsDir = getBatchResultsDir(argv);
|
|
348
|
-
if (batchResultsDir && getFlag(argv, "--results")) {
|
|
349
|
-
throw new Error("Use either --results <file> or --batch-results <dir>, not both.");
|
|
350
|
-
}
|
|
351
|
-
if (batchResultsDir) {
|
|
352
|
-
const result = await ingestBatchAuditResults({
|
|
353
|
-
root: getRootDir(argv),
|
|
354
|
-
artifactsDir,
|
|
355
|
-
batchDir: batchResultsDir,
|
|
356
|
-
});
|
|
357
|
-
console.log(JSON.stringify({
|
|
358
|
-
artifacts_dir: artifactsDir,
|
|
359
|
-
imported_files: result.batchFiles,
|
|
360
|
-
selected_executor: result.selected_executor,
|
|
361
|
-
progress_summary: result.progress_summary,
|
|
362
|
-
}, null, 2));
|
|
363
|
-
return;
|
|
364
|
-
}
|
|
365
|
-
const result = await runAuditStep({
|
|
366
|
-
root: getRootDir(argv),
|
|
367
|
-
artifactsDir,
|
|
368
|
-
preferredExecutor: "result_ingestion_executor",
|
|
369
|
-
auditResultsPath: getFlag(argv, "--results"),
|
|
370
|
-
});
|
|
371
|
-
console.log(JSON.stringify({
|
|
372
|
-
artifacts_dir: artifactsDir,
|
|
373
|
-
selected_executor: result.selected_executor,
|
|
374
|
-
progress_summary: result.progress_summary,
|
|
375
|
-
}, null, 2));
|
|
376
|
-
}
|
|
377
|
-
async function cmdExplainTask(argv) {
|
|
378
|
-
const artifactsDir = getArtifactsDir(argv);
|
|
379
|
-
const taskId = getFlag(argv, "--task-id") ?? argv[3];
|
|
380
|
-
if (!taskId) {
|
|
381
|
-
throw new Error("explain-task requires <task_id> or --task-id <task_id>");
|
|
382
|
-
}
|
|
383
|
-
const bundle = await loadArtifactBundle(artifactsDir);
|
|
384
|
-
const task = [...(bundle.audit_tasks ?? []), ...(bundle.requeue_tasks ?? [])].find((item) => item.task_id === taskId);
|
|
385
|
-
if (!task) {
|
|
386
|
-
throw new Error(`Unknown task_id '${taskId}'.`);
|
|
387
|
-
}
|
|
388
|
-
const coverageEntries = (bundle.coverage_matrix?.files ?? [])
|
|
389
|
-
.filter((file) => task.file_paths.includes(file.path))
|
|
390
|
-
.sort((a, b) => a.path.localeCompare(b.path));
|
|
391
|
-
const matchingResults = (bundle.audit_results ?? []).filter((result) => result.task_id === task.task_id);
|
|
392
|
-
console.log(JSON.stringify({
|
|
393
|
-
artifacts_dir: artifactsDir,
|
|
394
|
-
task_id: task.task_id,
|
|
395
|
-
task,
|
|
396
|
-
file_count: task.file_paths.length,
|
|
397
|
-
coverage_entries: coverageEntries,
|
|
398
|
-
pending_coverage: coverageEntries
|
|
399
|
-
.map((file) => ({
|
|
400
|
-
path: file.path,
|
|
401
|
-
missing_lenses: file.required_lenses.filter((lens) => !file.completed_lenses.includes(lens)),
|
|
402
|
-
}))
|
|
403
|
-
.filter((file) => file.missing_lenses.length > 0),
|
|
404
|
-
matching_result_count: matchingResults.length,
|
|
405
|
-
matching_finding_ids: matchingResults.flatMap((result) => result.findings.map((finding) => finding.id)),
|
|
406
|
-
}, null, 2));
|
|
407
|
-
}
|
|
408
|
-
async function cmdUpdateRuntimeValidation(argv) {
|
|
409
|
-
const artifactsDir = getArtifactsDir(argv);
|
|
410
|
-
const result = await runAuditStep({
|
|
411
|
-
root: getRootDir(argv),
|
|
412
|
-
artifactsDir,
|
|
413
|
-
preferredExecutor: "runtime_validation_update_executor",
|
|
414
|
-
runtimeUpdatesPath: getFlag(argv, "--updates"),
|
|
415
|
-
});
|
|
416
|
-
console.log(JSON.stringify({
|
|
417
|
-
artifacts_dir: artifactsDir,
|
|
418
|
-
selected_executor: result.selected_executor,
|
|
419
|
-
progress_summary: result.progress_summary,
|
|
420
|
-
}, null, 2));
|
|
421
|
-
}
|
|
422
|
-
async function cmdValidate(argv) {
|
|
423
|
-
const artifactsDir = getArtifactsDir(argv);
|
|
424
|
-
const bundle = await loadArtifactBundle(artifactsDir);
|
|
425
|
-
const sessionConfigPath = getSessionConfigPath(artifactsDir);
|
|
426
|
-
const rawSessionConfig = await readSessionConfigFile(artifactsDir);
|
|
427
|
-
const artifactIssues = validateArtifactBundle(bundle);
|
|
428
|
-
const sessionConfigIssues = rawSessionConfig === undefined
|
|
429
|
-
? []
|
|
430
|
-
: prefixValidationIssues("session_config", validateSessionConfig(rawSessionConfig));
|
|
431
|
-
const providerIssues = rawSessionConfig === undefined || sessionConfigIssues.length > 0
|
|
432
|
-
? []
|
|
433
|
-
: prefixValidationIssues("session_config", await validateConfiguredProviderEnvironment(rawSessionConfig));
|
|
434
|
-
const issues = [
|
|
435
|
-
...artifactIssues,
|
|
436
|
-
...sessionConfigIssues,
|
|
437
|
-
...providerIssues,
|
|
438
|
-
];
|
|
439
|
-
const resolvedProvider = rawSessionConfig === undefined
|
|
440
|
-
? "local-subprocess"
|
|
441
|
-
: sessionConfigIssues.length > 0
|
|
442
|
-
? null
|
|
443
|
-
: resolveFreshSessionProviderName(undefined, rawSessionConfig);
|
|
444
|
-
console.log(JSON.stringify({
|
|
445
|
-
artifacts_dir: artifactsDir,
|
|
446
|
-
session_config_path: sessionConfigPath,
|
|
447
|
-
session_config_present: rawSessionConfig !== undefined,
|
|
448
|
-
resolved_provider: resolvedProvider,
|
|
449
|
-
artifact_issue_count: artifactIssues.length,
|
|
450
|
-
session_config_issue_count: sessionConfigIssues.length + providerIssues.length,
|
|
451
|
-
issue_count: issues.length,
|
|
452
|
-
issues,
|
|
453
|
-
}, null, 2));
|
|
454
|
-
process.exitCode = issues.length > 0 ? 1 : 0;
|
|
455
|
-
}
|
|
456
|
-
async function cmdValidateResults(argv) {
|
|
457
|
-
const artifactsDir = getArtifactsDir(argv);
|
|
458
|
-
const resultsPath = getFlag(argv, "--results");
|
|
459
|
-
if (!resultsPath) {
|
|
460
|
-
throw new Error("validate-results requires --results <file>");
|
|
461
|
-
}
|
|
462
|
-
const bundle = await loadArtifactBundle(artifactsDir);
|
|
463
|
-
const lineIndex = bundle.repo_manifest
|
|
464
|
-
? await buildLineIndex(getRootDir(argv), bundle.repo_manifest)
|
|
465
|
-
: undefined;
|
|
466
|
-
const auditResults = await readJsonFile(resultsPath);
|
|
467
|
-
const issues = validateAuditResults(auditResults, bundle.audit_tasks ?? [], {
|
|
468
|
-
lineIndex,
|
|
469
|
-
});
|
|
470
|
-
const errors = issues.filter((issue) => issue.severity === "error");
|
|
471
|
-
const warnings = issues.filter((issue) => issue.severity === "warning");
|
|
472
|
-
console.log(JSON.stringify({
|
|
473
|
-
artifacts_dir: artifactsDir,
|
|
474
|
-
results_path: resolve(resultsPath),
|
|
475
|
-
warning_count: warnings.length,
|
|
476
|
-
error_count: errors.length,
|
|
477
|
-
issues,
|
|
478
|
-
}, null, 2));
|
|
479
|
-
process.exitCode = errors.length > 0 ? 1 : 0;
|
|
480
|
-
}
|
|
481
|
-
async function cmdRequeue(argv) {
|
|
482
|
-
const artifactsDir = getArtifactsDir(argv);
|
|
483
|
-
const bundle = await loadArtifactBundle(artifactsDir);
|
|
484
|
-
console.log(JSON.stringify({
|
|
485
|
-
artifacts_dir: artifactsDir,
|
|
486
|
-
task_count: bundle.requeue_tasks?.length ?? 0,
|
|
487
|
-
}, null, 2));
|
|
488
|
-
}
|
|
489
|
-
async function cmdSynthesize(argv) {
|
|
490
|
-
const artifactsDir = getArtifactsDir(argv);
|
|
491
|
-
const result = await runAuditStep({
|
|
492
|
-
root: getRootDir(argv),
|
|
493
|
-
artifactsDir,
|
|
494
|
-
preferredExecutor: "synthesis_executor",
|
|
495
|
-
});
|
|
496
|
-
console.log(JSON.stringify({
|
|
497
|
-
artifacts_dir: artifactsDir,
|
|
498
|
-
selected_executor: result.selected_executor,
|
|
499
|
-
progress_summary: result.progress_summary,
|
|
500
|
-
}, null, 2));
|
|
501
|
-
}
|
|
502
|
-
async function cmdCleanup(argv) {
|
|
503
|
-
const artifactsDir = getArtifactsDir(argv);
|
|
504
|
-
const dryRun = hasFlag(argv, "--dry-run");
|
|
505
|
-
const force = hasFlag(argv, "--force");
|
|
506
|
-
let status;
|
|
507
|
-
try {
|
|
508
|
-
const state = await readJsonFile(join(artifactsDir, "audit_state.json"));
|
|
509
|
-
status = state.status;
|
|
510
|
-
}
|
|
511
|
-
catch (error) {
|
|
512
|
-
if (!isFileMissingError(error)) {
|
|
513
|
-
throw error;
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
const resumable = status === "active" || status === "blocked";
|
|
517
|
-
const unknown = status === undefined;
|
|
518
|
-
if ((resumable || unknown) && !force) {
|
|
519
|
-
const reason = resumable
|
|
520
|
-
? `audit is ${status} and may be resumed`
|
|
521
|
-
: "no audit_state.json found; artifacts may be from a crashed audit";
|
|
522
|
-
console.log(JSON.stringify({
|
|
523
|
-
artifacts_dir: artifactsDir,
|
|
524
|
-
action: "skipped",
|
|
525
|
-
reason: `${reason} — use --force to delete anyway`,
|
|
526
|
-
dry_run: dryRun,
|
|
527
|
-
}, null, 2));
|
|
528
|
-
process.exitCode = 1;
|
|
529
|
-
return;
|
|
530
|
-
}
|
|
531
|
-
if (!dryRun) {
|
|
532
|
-
await rm(artifactsDir, { recursive: true, force: true });
|
|
533
|
-
}
|
|
534
|
-
console.log(JSON.stringify({
|
|
535
|
-
artifacts_dir: artifactsDir,
|
|
536
|
-
action: dryRun ? "dry-run" : "deleted",
|
|
537
|
-
status: status ?? "unknown",
|
|
538
|
-
dry_run: dryRun,
|
|
539
|
-
}, null, 2));
|
|
540
|
-
}
|
|
541
|
-
async function cmdQuota(argv) {
|
|
542
|
-
const artifactsDir = getArtifactsDir(argv);
|
|
543
|
-
const sessionConfig = await loadSessionConfig(artifactsDir).catch(() => ({}));
|
|
544
|
-
const explicitProvider = getExplicitProvider(argv);
|
|
545
|
-
const hostModel = getHostModel(argv);
|
|
546
|
-
const providerName = resolveFreshSessionProviderName(explicitProvider, sessionConfig);
|
|
547
|
-
const providerModelKey = buildProviderModelKey(providerName, hostModel);
|
|
548
|
-
const { limits, source, confidence } = resolveLimits({ providerName, sessionConfig, hostModel });
|
|
549
|
-
const quotaState = await readQuotaState().catch(() => ({ version: 2, entries: {} }));
|
|
550
|
-
const quotaStateEntry = quotaState.entries[providerModelKey] ?? null;
|
|
551
|
-
const halfLifeHours = sessionConfig.quota?.empirical_half_life_hours ??
|
|
552
|
-
DEFAULT_EMPIRICAL_HALF_LIFE_HOURS;
|
|
553
|
-
const hostConcurrencyLimit = resolveHostActiveSubagentLimit({
|
|
554
|
-
explicitLimit: getHostMaxActiveSubagents(argv),
|
|
555
|
-
sessionConfig,
|
|
556
|
-
});
|
|
557
|
-
const quotaSource = buildQuotaSource({ halfLifeHours });
|
|
558
|
-
const quotaSourceSnapshot = await quotaSource.queryCurrentUsage(providerModelKey).catch(() => null);
|
|
559
|
-
const queryDiscoveredLimits = await lookupDiscoveredLimits(providerModelKey).catch(() => null);
|
|
560
|
-
const waveSchedule = scheduleWave({
|
|
561
|
-
providerName,
|
|
562
|
-
sessionConfig,
|
|
563
|
-
hostModel,
|
|
564
|
-
requestedConcurrency: sessionConfig.parallel_workers ?? 1,
|
|
565
|
-
quotaStateEntry,
|
|
566
|
-
hostConcurrencyLimit,
|
|
567
|
-
quotaSourceSnapshot,
|
|
568
|
-
discoveredLimits: queryDiscoveredLimits,
|
|
569
|
-
});
|
|
570
|
-
console.log(JSON.stringify({
|
|
571
|
-
provider: providerName,
|
|
572
|
-
model: hostModel,
|
|
573
|
-
provider_model_key: providerModelKey,
|
|
574
|
-
resolved_limits: limits,
|
|
575
|
-
confidence,
|
|
576
|
-
source,
|
|
577
|
-
host_concurrency_limit: hostConcurrencyLimit,
|
|
578
|
-
learned_caps: quotaStateEntry
|
|
579
|
-
? {
|
|
580
|
-
max_safe_concurrency: computeMaxSafeConcurrency(quotaStateEntry, halfLifeHours),
|
|
581
|
-
cooldown_until: quotaStateEntry.cooldown_until,
|
|
582
|
-
last_429_at: quotaStateEntry.last_429_at,
|
|
583
|
-
}
|
|
584
|
-
: null,
|
|
585
|
-
quota_source_snapshot: quotaSourceSnapshot,
|
|
586
|
-
discovered_limits: queryDiscoveredLimits,
|
|
587
|
-
wave_schedule: waveSchedule,
|
|
588
|
-
quota_state_path: getQuotaStatePath(),
|
|
589
|
-
}, null, 2));
|
|
590
|
-
}
|
|
591
|
-
async function cmdDispatchStatus(argv) {
|
|
592
|
-
const artifactsDir = getArtifactsDir(argv);
|
|
593
|
-
const activeDispatchPath = join(artifactsDir, ACTIVE_DISPATCH_FILENAME);
|
|
594
|
-
let activeDispatch = null;
|
|
595
|
-
try {
|
|
596
|
-
activeDispatch = await readJsonFile(activeDispatchPath);
|
|
597
|
-
}
|
|
598
|
-
catch (e) {
|
|
599
|
-
if (!isFileMissingError(e))
|
|
600
|
-
throw e;
|
|
601
|
-
}
|
|
602
|
-
if (!activeDispatch) {
|
|
603
|
-
console.log(JSON.stringify({ status: "no_active_dispatch" }, null, 2));
|
|
604
|
-
return;
|
|
605
|
-
}
|
|
606
|
-
const runDir = join(artifactsDir, "runs", activeDispatch.run_id);
|
|
607
|
-
const resultMap = await loadDispatchResultMap(runDir);
|
|
608
|
-
if (!resultMap) {
|
|
609
|
-
console.log(JSON.stringify({
|
|
610
|
-
status: "missing_result_map",
|
|
611
|
-
run_id: activeDispatch.run_id,
|
|
612
|
-
}, null, 2));
|
|
613
|
-
return;
|
|
614
|
-
}
|
|
615
|
-
const packetIds = [...new Set(resultMap.entries.map((e) => e.packet_id))];
|
|
616
|
-
const packetStatus = [];
|
|
617
|
-
for (const pid of packetIds) {
|
|
618
|
-
if (pid === "__prior_dispatch__")
|
|
619
|
-
continue;
|
|
620
|
-
const entries = resultMap.entries.filter((e) => e.packet_id === pid);
|
|
621
|
-
let completed = 0;
|
|
622
|
-
const missing = [];
|
|
623
|
-
for (const entry of entries) {
|
|
624
|
-
try {
|
|
625
|
-
await readFile(entry.result_path, "utf8");
|
|
626
|
-
completed++;
|
|
627
|
-
}
|
|
628
|
-
catch {
|
|
629
|
-
missing.push(entry.task_id);
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
packetStatus.push({
|
|
633
|
-
packet_id: pid,
|
|
634
|
-
task_count: entries.length,
|
|
635
|
-
completed_count: completed,
|
|
636
|
-
missing_task_ids: missing,
|
|
637
|
-
});
|
|
638
|
-
}
|
|
639
|
-
const totalTasks = packetStatus.reduce((s, p) => s + p.task_count, 0);
|
|
640
|
-
const completedTasks = packetStatus.reduce((s, p) => s + p.completed_count, 0);
|
|
641
|
-
const completedPackets = packetStatus.filter((p) => p.missing_task_ids.length === 0).length;
|
|
642
|
-
console.log(JSON.stringify({
|
|
643
|
-
run_id: activeDispatch.run_id,
|
|
644
|
-
dispatch_status: activeDispatch.status,
|
|
645
|
-
created_at: activeDispatch.created_at,
|
|
646
|
-
total_packets: packetStatus.length,
|
|
647
|
-
completed_packets: completedPackets,
|
|
648
|
-
total_tasks: totalTasks,
|
|
649
|
-
completed_tasks: completedTasks,
|
|
650
|
-
missing_tasks: totalTasks - completedTasks,
|
|
651
|
-
packets: packetStatus,
|
|
652
|
-
}, null, 2));
|
|
653
|
-
}
|
|
654
47
|
async function main(argv) {
|
|
655
48
|
setQuotaStateDir(join(homedir(), ".audit-code"));
|
|
656
49
|
const command = argv[2] ?? "sample-run";
|