anvil-engineering-workbench 1.0.8 → 1.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/CHANGELOG.md +37 -0
- package/README.md +23 -18
- package/dist/ai/claude-code-provider.js +55 -9
- package/dist/ai/claude-code-provider.js.map +1 -1
- package/dist/ai/provider.js +1 -1
- package/dist/ai/provider.js.map +1 -1
- package/dist/cli.js +837 -278
- package/dist/cli.js.map +1 -1
- package/dist/core/adr-engine.js +9 -11
- package/dist/core/adr-engine.js.map +1 -1
- package/dist/core/agent-config-release.js +29 -13
- package/dist/core/agent-config-release.js.map +1 -1
- package/dist/core/agent-config-versioning.js +32 -17
- package/dist/core/agent-config-versioning.js.map +1 -1
- package/dist/core/agent-evaluation-intelligence.js +30 -38
- package/dist/core/agent-evaluation-intelligence.js.map +1 -1
- package/dist/core/agent-evolution.js +109 -20
- package/dist/core/agent-evolution.js.map +1 -1
- package/dist/core/agent-experiment-studio.js +19 -11
- package/dist/core/agent-experiment-studio.js.map +1 -1
- package/dist/core/agent-optimization.js +69 -14
- package/dist/core/agent-optimization.js.map +1 -1
- package/dist/core/agent-registry.js +87 -15
- package/dist/core/agent-registry.js.map +1 -1
- package/dist/core/agent-security-audit.js +21 -21
- package/dist/core/agent-security-audit.js.map +1 -1
- package/dist/core/agent-workspace-context.js +37 -6
- package/dist/core/agent-workspace-context.js.map +1 -1
- package/dist/core/ai-code-review.js +60 -12
- package/dist/core/ai-code-review.js.map +1 -1
- package/dist/core/anthropic-provider.js.map +1 -1
- package/dist/core/architecture-map.js +87 -24
- package/dist/core/architecture-map.js.map +1 -1
- package/dist/core/benchmark-engine.js +89 -21
- package/dist/core/benchmark-engine.js.map +1 -1
- package/dist/core/benchmark-matrix.js +215 -41
- package/dist/core/benchmark-matrix.js.map +1 -1
- package/dist/core/benchmark-regression.js +124 -18
- package/dist/core/benchmark-regression.js.map +1 -1
- package/dist/core/change-intelligence.js +102 -43
- package/dist/core/change-intelligence.js.map +1 -1
- package/dist/core/code-intelligence.js +40 -13
- package/dist/core/code-intelligence.js.map +1 -1
- package/dist/core/code-review.js +145 -17
- package/dist/core/code-review.js.map +1 -1
- package/dist/core/code-search.js +79 -39
- package/dist/core/code-search.js.map +1 -1
- package/dist/core/container-sandbox.js +87 -23
- package/dist/core/container-sandbox.js.map +1 -1
- package/dist/core/dashboard-server.js +379 -93
- package/dist/core/dashboard-server.js.map +1 -1
- package/dist/core/dependency-graph.js +75 -13
- package/dist/core/dependency-graph.js.map +1 -1
- package/dist/core/dependency-impact.js +132 -33
- package/dist/core/dependency-impact.js.map +1 -1
- package/dist/core/dependency-intelligence.js +153 -56
- package/dist/core/dependency-intelligence.js.map +1 -1
- package/dist/core/doctor.js +3 -3
- package/dist/core/doctor.js.map +1 -1
- package/dist/core/engineering-risk.js +75 -40
- package/dist/core/engineering-risk.js.map +1 -1
- package/dist/core/env-compat.js.map +1 -1
- package/dist/core/evaluation-engine.js +188 -42
- package/dist/core/evaluation-engine.js.map +1 -1
- package/dist/core/execution-trace.js +83 -29
- package/dist/core/execution-trace.js.map +1 -1
- package/dist/core/experiment-history.js +70 -20
- package/dist/core/experiment-history.js.map +1 -1
- package/dist/core/experiment-manifest.js +92 -13
- package/dist/core/experiment-manifest.js.map +1 -1
- package/dist/core/gemini-provider.js.map +1 -1
- package/dist/core/git-intelligence.js +68 -16
- package/dist/core/git-intelligence.js.map +1 -1
- package/dist/core/hook-engine.js +7 -3
- package/dist/core/hook-engine.js.map +1 -1
- package/dist/core/hosted-agent-provider.js +48 -8
- package/dist/core/hosted-agent-provider.js.map +1 -1
- package/dist/core/intelligence-timeline.js +92 -43
- package/dist/core/intelligence-timeline.js.map +1 -1
- package/dist/core/mcp-setup.js +12 -12
- package/dist/core/mcp-setup.js.map +1 -1
- package/dist/core/model-router.js +153 -37
- package/dist/core/model-router.js.map +1 -1
- package/dist/core/openai-compatible-provider.js +41 -10
- package/dist/core/openai-compatible-provider.js.map +1 -1
- package/dist/core/orchestrator.js +28 -23
- package/dist/core/orchestrator.js.map +1 -1
- package/dist/core/patch-application.js +88 -24
- package/dist/core/patch-application.js.map +1 -1
- package/dist/core/patch-approval.js +43 -15
- package/dist/core/patch-approval.js.map +1 -1
- package/dist/core/patch-validation.js +93 -15
- package/dist/core/patch-validation.js.map +1 -1
- package/dist/core/permission-policy.js +8 -5
- package/dist/core/permission-policy.js.map +1 -1
- package/dist/core/policy-engine.d.ts +76 -0
- package/dist/core/policy-engine.js +352 -0
- package/dist/core/policy-engine.js.map +1 -0
- package/dist/core/project-cleaner.js +143 -129
- package/dist/core/project-cleaner.js.map +1 -1
- package/dist/core/project-health.js +183 -21
- package/dist/core/project-health.js.map +1 -1
- package/dist/core/project-init.js +32 -20
- package/dist/core/project-init.js.map +1 -1
- package/dist/core/project-inspector.js +81 -32
- package/dist/core/project-inspector.js.map +1 -1
- package/dist/core/project-memory.js +41 -18
- package/dist/core/project-memory.js.map +1 -1
- package/dist/core/provider-diagnostics.js +65 -12
- package/dist/core/provider-diagnostics.js.map +1 -1
- package/dist/core/quality-audit.js +167 -28
- package/dist/core/quality-audit.js.map +1 -1
- package/dist/core/regression-intelligence.js +88 -8
- package/dist/core/regression-intelligence.js.map +1 -1
- package/dist/core/remediation-planner.js +112 -40
- package/dist/core/remediation-planner.js.map +1 -1
- package/dist/core/review-history.js +39 -7
- package/dist/core/review-history.js.map +1 -1
- package/dist/core/run-history-output.js.map +1 -1
- package/dist/core/run-replay.js +12 -10
- package/dist/core/run-replay.js.map +1 -1
- package/dist/core/run-store.js +48 -21
- package/dist/core/run-store.js.map +1 -1
- package/dist/core/sandbox-cleanup-audit.js +1 -1
- package/dist/core/sandbox-cleanup-audit.js.map +1 -1
- package/dist/core/sandbox-compliance.js +53 -9
- package/dist/core/sandbox-compliance.js.map +1 -1
- package/dist/core/sandbox-lifecycle.js +1 -1
- package/dist/core/sandbox-lifecycle.js.map +1 -1
- package/dist/core/sandbox-policy.js +27 -3
- package/dist/core/sandbox-policy.js.map +1 -1
- package/dist/core/sandbox-runtime.js +9 -5
- package/dist/core/sandbox-runtime.js.map +1 -1
- package/dist/core/sandbox-security-profiles.js +31 -12
- package/dist/core/sandbox-security-profiles.js.map +1 -1
- package/dist/core/sarif-formatter.d.ts +10 -3
- package/dist/core/sarif-formatter.js +172 -57
- package/dist/core/sarif-formatter.js.map +1 -1
- package/dist/core/security-scanner.js +40 -32
- package/dist/core/security-scanner.js.map +1 -1
- package/dist/core/skill-registry.js +83 -21
- package/dist/core/skill-registry.js.map +1 -1
- package/dist/core/staged-verification.js +25 -10
- package/dist/core/staged-verification.js.map +1 -1
- package/dist/core/verification-history.js +12 -7
- package/dist/core/verification-history.js.map +1 -1
- package/dist/core/verification.js +50 -19
- package/dist/core/verification.js.map +1 -1
- package/dist/core/workflow-store.js +16 -4
- package/dist/core/workflow-store.js.map +1 -1
- package/dist/core/workspace-browser.js +57 -10
- package/dist/core/workspace-browser.js.map +1 -1
- package/dist/core/workspace-scan-policy.js +26 -4
- package/dist/core/workspace-scan-policy.js.map +1 -1
- package/dist/core/workspace-tool-broker.d.ts +1 -1
- package/dist/core/workspace-tool-broker.js +25 -4
- package/dist/core/workspace-tool-broker.js.map +1 -1
- package/dist/mcp/server.js +148 -55
- package/dist/mcp/server.js.map +1 -1
- package/dist/mcp/workspace-path.js +2 -2
- package/dist/mcp/workspace-path.js.map +1 -1
- package/package.json +8 -5
package/dist/cli.js
CHANGED
|
@@ -10,7 +10,7 @@ import { formatArchitectureMap, mapArchitecture } from "./core/architecture-map.
|
|
|
10
10
|
import { formatProjectReport, inspectProject } from "./core/project-inspector.js";
|
|
11
11
|
import { loadAgentRegistry } from "./core/agent-registry.js";
|
|
12
12
|
import { createReviewPlan } from "./core/review-planner.js";
|
|
13
|
-
import { saveRun, listRuns, loadRun, decideTaskApproval, recoverInterruptedRun, withRunExecutionLock } from "./core/run-store.js";
|
|
13
|
+
import { saveRun, listRuns, loadRun, decideTaskApproval, recoverInterruptedRun, withRunExecutionLock, } from "./core/run-store.js";
|
|
14
14
|
import { advanceRun } from "./core/orchestrator.js";
|
|
15
15
|
import { formatRunHistoryJson } from "./core/run-history-output.js";
|
|
16
16
|
import { OpenAICompatibleProvider } from "./core/openai-compatible-provider.js";
|
|
@@ -19,7 +19,7 @@ import { ClaudeCodeProvider } from "./ai/claude-code-provider.js";
|
|
|
19
19
|
import { startDashboard } from "./core/dashboard-server.js";
|
|
20
20
|
import { auditProject, formatQualityAudit } from "./core/quality-audit.js";
|
|
21
21
|
import { discoverChecks, formatVerificationResult, runVerification } from "./core/verification.js";
|
|
22
|
-
import { compareVerification, formatVerificationComparison, listVerifications, saveVerification } from "./core/verification-history.js";
|
|
22
|
+
import { compareVerification, formatVerificationComparison, listVerifications, saveVerification, } from "./core/verification-history.js";
|
|
23
23
|
import { formatProjectHealthMarkdown, generateProjectHealth } from "./core/project-health.js";
|
|
24
24
|
import { analyzeCodebase, formatCodebaseAnalysis } from "./core/code-intelligence.js";
|
|
25
25
|
import { analyzeGitChanges, formatGitIntelligence } from "./core/git-intelligence.js";
|
|
@@ -32,45 +32,46 @@ import { stageApprovedPatch, reviewStagedPatch } from "./core/patch-application.
|
|
|
32
32
|
import { verifyStagedPatch } from "./core/staged-verification.js";
|
|
33
33
|
import { formatSandboxRuntimeReport, parseSandboxRuntimeReport } from "./core/sandbox-runtime.js";
|
|
34
34
|
import { detectDockerRootless } from "./core/container-sandbox.js";
|
|
35
|
-
import { formatSandboxCleanupReport, parseManagedContainers, selectStoppedManagedContainers } from "./core/sandbox-lifecycle.js";
|
|
35
|
+
import { formatSandboxCleanupReport, parseManagedContainers, selectStoppedManagedContainers, } from "./core/sandbox-lifecycle.js";
|
|
36
36
|
import { getSandboxSecurityProfile, listSandboxSecurityProfiles } from "./core/sandbox-security-profiles.js";
|
|
37
37
|
import { createSandboxComplianceReport, formatSandboxComplianceReport } from "./core/sandbox-compliance.js";
|
|
38
38
|
import { formatSandboxPolicyValidation, loadSandboxPolicy } from "./core/sandbox-policy.js";
|
|
39
|
-
import { appendSandboxCleanupAudit, formatSandboxCleanupHistory, readSandboxCleanupAudit } from "./core/sandbox-cleanup-audit.js";
|
|
39
|
+
import { appendSandboxCleanupAudit, formatSandboxCleanupHistory, readSandboxCleanupAudit, } from "./core/sandbox-cleanup-audit.js";
|
|
40
40
|
import { formatRegressionReport, generateRegressionReport } from "./core/regression-intelligence.js";
|
|
41
41
|
import { searchWorkspace } from "./core/code-search.js";
|
|
42
42
|
import { buildAgentWorkspaceContext } from "./core/agent-workspace-context.js";
|
|
43
43
|
import { analyzeDependencyImpact, formatDependencyImpact } from "./core/dependency-impact.js";
|
|
44
44
|
import { analyzeEngineeringRisk, formatEngineeringRisk } from "./core/engineering-risk.js";
|
|
45
45
|
import { analyzeChangeIntelligence, formatChangeIntelligence } from "./core/change-intelligence.js";
|
|
46
|
-
import { captureIntelligenceSnapshot, compareLatestIntelligence, formatIntelligenceComparison } from "./core/intelligence-timeline.js";
|
|
46
|
+
import { captureIntelligenceSnapshot, compareLatestIntelligence, formatIntelligenceComparison, } from "./core/intelligence-timeline.js";
|
|
47
47
|
import { analyzeDependencies, formatDependencyIntelligence } from "./core/dependency-intelligence.js";
|
|
48
48
|
import { generateRemediationPlan, formatRemediationPlan } from "./core/remediation-planner.js";
|
|
49
|
-
import { addProjectMemory, buildProjectMemoryContext, listProjectMemory, removeProjectMemory } from "./core/project-memory.js";
|
|
49
|
+
import { addProjectMemory, buildProjectMemoryContext, listProjectMemory, removeProjectMemory, } from "./core/project-memory.js";
|
|
50
50
|
import { setupHarnessMcp, resolveMcpServerScript } from "./core/mcp-setup.js";
|
|
51
51
|
import { initAdrDirectory, listAdrs, createAdr, syncMemoryToAdrs } from "./core/adr-engine.js";
|
|
52
52
|
import { scanProjectSecurity, applySecurityFixes, formatSecurityReport } from "./core/security-scanner.js";
|
|
53
|
+
import { evaluateGate, generateBaselineJson } from "./core/policy-engine.js";
|
|
53
54
|
import { formatSkillContext, loadSkillRegistry, selectSkills } from "./core/skill-registry.js";
|
|
54
55
|
import { applyBeforeAgentHooks, loadHooks } from "./core/hook-engine.js";
|
|
55
56
|
import { assertSupportedAgentPolicy, loadPermissionPolicy } from "./core/permission-policy.js";
|
|
56
57
|
import { ModelRouter } from "./core/model-router.js";
|
|
57
58
|
import { loadExecutionTrace, saveExecutionTrace } from "./core/execution-trace.js";
|
|
58
59
|
import { createReplayRun } from "./core/run-replay.js";
|
|
59
|
-
import { evaluateRun, evaluateRunWithJudge, formatEvaluationReport, loadEvaluationSuites, saveEvaluationReport, loadEvaluationReport } from "./core/evaluation-engine.js";
|
|
60
|
-
import { createBenchmarkTrial, formatBenchmark, listBenchmarks, recordBenchmarkTrial } from "./core/benchmark-engine.js";
|
|
61
|
-
import { executeBenchmarkMatrix, formatBenchmarkMatrix, loadBenchmarkMatrix, listBenchmarkMatrices, saveBenchmarkMatrix } from "./core/benchmark-matrix.js";
|
|
60
|
+
import { evaluateRun, evaluateRunWithJudge, formatEvaluationReport, loadEvaluationSuites, saveEvaluationReport, loadEvaluationReport, } from "./core/evaluation-engine.js";
|
|
61
|
+
import { createBenchmarkTrial, formatBenchmark, listBenchmarks, recordBenchmarkTrial, } from "./core/benchmark-engine.js";
|
|
62
|
+
import { executeBenchmarkMatrix, formatBenchmarkMatrix, loadBenchmarkMatrix, listBenchmarkMatrices, saveBenchmarkMatrix, } from "./core/benchmark-matrix.js";
|
|
62
63
|
import { fingerprintAgentConfig } from "./core/benchmark-matrix.js";
|
|
63
64
|
import { loadAgentConfigVersion } from "./core/agent-config-versioning.js";
|
|
64
65
|
import { formatBenchmarkRegression, loadBenchmarkRegression } from "./core/benchmark-regression.js";
|
|
65
66
|
import { buildAgentOptimizationPlan, formatAgentOptimizationPlan } from "./core/agent-optimization.js";
|
|
66
67
|
import { auditAgentConfiguration, formatAgentSecurityReport } from "./core/agent-security-audit.js";
|
|
67
|
-
import { buildAgentEvaluationIntelligence, formatAgentEvaluationIntelligence } from "./core/agent-evaluation-intelligence.js";
|
|
68
|
+
import { buildAgentEvaluationIntelligence, formatAgentEvaluationIntelligence, } from "./core/agent-evaluation-intelligence.js";
|
|
68
69
|
import { assessAgentEvolution, formatAgentEvolutionAssessment } from "./core/agent-evolution.js";
|
|
69
|
-
import { createSkillExperimentMatrix, formatSkillExperimentMatrix, createModelComparisonMatrix, formatModelComparisonMatrix } from "./core/agent-experiment-studio.js";
|
|
70
|
+
import { createSkillExperimentMatrix, formatSkillExperimentMatrix, createModelComparisonMatrix, formatModelComparisonMatrix, } from "./core/agent-experiment-studio.js";
|
|
70
71
|
import { buildExperimentHistory, formatExperimentHistory } from "./core/experiment-history.js";
|
|
71
|
-
import { captureAgentConfigVersion, compareAgentConfigVersions, formatAgentConfigVersion, listAgentConfigVersions, materializeAgentConfigVersion } from "./core/agent-config-versioning.js";
|
|
72
|
-
import { decideAgentConfigRelease, formatAgentConfigRelease, listAgentConfigReleases, prepareAgentConfigRelease } from "./core/agent-config-release.js";
|
|
73
|
-
import { captureExperimentManifest, compareExperimentManifests, formatExperimentManifest, loadExperimentManifest, saveExperimentManifest } from "./core/experiment-manifest.js";
|
|
72
|
+
import { captureAgentConfigVersion, compareAgentConfigVersions, formatAgentConfigVersion, listAgentConfigVersions, materializeAgentConfigVersion, } from "./core/agent-config-versioning.js";
|
|
73
|
+
import { decideAgentConfigRelease, formatAgentConfigRelease, listAgentConfigReleases, prepareAgentConfigRelease, } from "./core/agent-config-release.js";
|
|
74
|
+
import { captureExperimentManifest, compareExperimentManifests, formatExperimentManifest, loadExperimentManifest, saveExperimentManifest, } from "./core/experiment-manifest.js";
|
|
74
75
|
function runSandboxProbe(args) {
|
|
75
76
|
return new Promise((resolve, reject) => {
|
|
76
77
|
const child = spawn("docker", args, { shell: false, windowsHide: true, stdio: ["ignore", "pipe", "pipe"] });
|
|
@@ -92,8 +93,8 @@ function runSandboxProbe(args) {
|
|
|
92
93
|
};
|
|
93
94
|
child.stdout.on("data", append);
|
|
94
95
|
child.stderr.on("data", append);
|
|
95
|
-
child.once("error", error => finish(error));
|
|
96
|
-
child.once("close", code => code === 0 ? finish() : finish(new Error("Docker probe exited with status " + code + ".")));
|
|
96
|
+
child.once("error", (error) => finish(error));
|
|
97
|
+
child.once("close", (code) => code === 0 ? finish() : finish(new Error("Docker probe exited with status " + code + ".")));
|
|
97
98
|
const timer = setTimeout(() => {
|
|
98
99
|
child.kill("SIGTERM");
|
|
99
100
|
finish(new Error("Docker probe timed out after 15 seconds."));
|
|
@@ -247,7 +248,7 @@ async function main(args) {
|
|
|
247
248
|
process.stdout.write(`anvil ${VERSION}\n`);
|
|
248
249
|
return;
|
|
249
250
|
case "init": {
|
|
250
|
-
const target = rest.find(arg => !arg.startsWith("--")) ?? ".";
|
|
251
|
+
const target = rest.find((arg) => !arg.startsWith("--")) ?? ".";
|
|
251
252
|
try {
|
|
252
253
|
const result = await initializeProject(path.resolve(target));
|
|
253
254
|
process.stdout.write(`ANVIL initialized in ${path.resolve(target)}\n`);
|
|
@@ -264,10 +265,13 @@ async function main(args) {
|
|
|
264
265
|
return;
|
|
265
266
|
}
|
|
266
267
|
case "evals": {
|
|
267
|
-
const target = path.resolve(rest.find(arg => !arg.startsWith("--")) ?? ".");
|
|
268
|
+
const target = path.resolve(rest.find((arg) => !arg.startsWith("--")) ?? ".");
|
|
268
269
|
try {
|
|
269
270
|
const suites = await loadEvaluationSuites(target);
|
|
270
|
-
process.stdout.write(suites.length
|
|
271
|
+
process.stdout.write(suites.length
|
|
272
|
+
? suites.map((suite) => suite.id + " " + suite.name + " · " + suite.cases.length + " cases").join("\n") +
|
|
273
|
+
"\n"
|
|
274
|
+
: "No evaluation suites. Add JSON suites under .forge/evals/.\n");
|
|
271
275
|
}
|
|
272
276
|
catch (error) {
|
|
273
277
|
process.stderr.write("Could not load evaluation suites: " + (error instanceof Error ? error.message : String(error)) + "\n");
|
|
@@ -277,10 +281,18 @@ async function main(args) {
|
|
|
277
281
|
}
|
|
278
282
|
case "agent-release": {
|
|
279
283
|
const action = rest[0] ?? "list";
|
|
280
|
-
const option = (name) => {
|
|
284
|
+
const option = (name) => {
|
|
285
|
+
const index = rest.indexOf(name);
|
|
286
|
+
return index >= 0 ? rest[index + 1] : undefined;
|
|
287
|
+
};
|
|
281
288
|
const pathIndex = rest.indexOf("--path");
|
|
282
|
-
const target = path.resolve(pathIndex >= 0 ? rest[pathIndex + 1] ?? "." : ".");
|
|
283
|
-
const args = rest
|
|
289
|
+
const target = path.resolve(pathIndex >= 0 ? (rest[pathIndex + 1] ?? ".") : ".");
|
|
290
|
+
const args = rest
|
|
291
|
+
.slice(1)
|
|
292
|
+
.filter((arg, index, all) => !arg.startsWith("--") &&
|
|
293
|
+
all[index - 1] !== "--path" &&
|
|
294
|
+
all[index - 1] !== "--reviewer" &&
|
|
295
|
+
all[index - 1] !== "--matrix");
|
|
284
296
|
try {
|
|
285
297
|
if (action === "prepare") {
|
|
286
298
|
const [candidateVersionId, baselineVersionId] = args;
|
|
@@ -288,18 +300,32 @@ async function main(args) {
|
|
|
288
300
|
if (!candidateVersionId || !baselineVersionId || !matrixId)
|
|
289
301
|
throw new Error("Usage: anvil agent-release prepare CANDIDATE_CONFIG_ID BASELINE_CONFIG_ID --matrix MATRIX_ID --path PROJECT");
|
|
290
302
|
const regression = await loadBenchmarkRegression(target, matrixId);
|
|
291
|
-
const release = await prepareAgentConfigRelease(target, {
|
|
303
|
+
const release = await prepareAgentConfigRelease(target, {
|
|
304
|
+
candidateVersionId,
|
|
305
|
+
baselineVersionId,
|
|
306
|
+
regression,
|
|
307
|
+
});
|
|
292
308
|
process.stdout.write(formatAgentConfigRelease(release) + "\nHuman approval is still required. No live files were changed.\n");
|
|
293
309
|
}
|
|
294
310
|
else if (action === "list") {
|
|
295
311
|
const items = await listAgentConfigReleases(target);
|
|
296
|
-
process.stdout.write(items.length
|
|
312
|
+
process.stdout.write(items.length
|
|
313
|
+
? items
|
|
314
|
+
.map((item) => item.id +
|
|
315
|
+
" " +
|
|
316
|
+
item.status.padEnd(17) +
|
|
317
|
+
" " +
|
|
318
|
+
item.candidateVersionId +
|
|
319
|
+
" " +
|
|
320
|
+
item.benchmarkStatus)
|
|
321
|
+
.join("\n") + "\n"
|
|
322
|
+
: "No agent configuration releases found.\n");
|
|
297
323
|
}
|
|
298
324
|
else if (action === "show") {
|
|
299
325
|
const id = args[0];
|
|
300
326
|
if (!id)
|
|
301
327
|
throw new Error("Usage: anvil agent-release show RELEASE_ID --path PROJECT");
|
|
302
|
-
const item = (await listAgentConfigReleases(target)).find(entry => entry.id === id);
|
|
328
|
+
const item = (await listAgentConfigReleases(target)).find((entry) => entry.id === id);
|
|
303
329
|
if (!item)
|
|
304
330
|
throw new Error("Release not found: " + id);
|
|
305
331
|
process.stdout.write(formatAgentConfigRelease(item) + "\n");
|
|
@@ -326,17 +352,39 @@ async function main(args) {
|
|
|
326
352
|
case "agent-config": {
|
|
327
353
|
const action = rest[0] ?? "list";
|
|
328
354
|
const pathIndex = rest.indexOf("--path");
|
|
329
|
-
const target = path.resolve(pathIndex >= 0 ? rest[pathIndex + 1] ?? "." : ".");
|
|
330
|
-
const ids = rest
|
|
331
|
-
|
|
355
|
+
const target = path.resolve(pathIndex >= 0 ? (rest[pathIndex + 1] ?? ".") : ".");
|
|
356
|
+
const ids = rest
|
|
357
|
+
.slice(1)
|
|
358
|
+
.filter((arg, index, all) => !arg.startsWith("--") &&
|
|
359
|
+
all[index - 1] !== "--path" &&
|
|
360
|
+
all[index - 1] !== "--note" &&
|
|
361
|
+
all[index - 1] !== "--reviewer");
|
|
362
|
+
const option = (name) => {
|
|
363
|
+
const index = rest.indexOf(name);
|
|
364
|
+
return index >= 0 ? rest[index + 1] : undefined;
|
|
365
|
+
};
|
|
332
366
|
try {
|
|
333
367
|
if (action === "snapshot") {
|
|
334
|
-
const version = await captureAgentConfigVersion(target, {
|
|
368
|
+
const version = await captureAgentConfigVersion(target, {
|
|
369
|
+
note: option("--note") ?? "",
|
|
370
|
+
createdBy: option("--author") ?? "local-user",
|
|
371
|
+
});
|
|
335
372
|
process.stdout.write(formatAgentConfigVersion(version) + "\n");
|
|
336
373
|
}
|
|
337
374
|
else if (action === "list") {
|
|
338
375
|
const versions = await listAgentConfigVersions(target);
|
|
339
|
-
process.stdout.write(versions.length
|
|
376
|
+
process.stdout.write(versions.length
|
|
377
|
+
? versions
|
|
378
|
+
.map((item) => item.id +
|
|
379
|
+
" " +
|
|
380
|
+
item.status.padEnd(9) +
|
|
381
|
+
" " +
|
|
382
|
+
item.createdAt +
|
|
383
|
+
" " +
|
|
384
|
+
item.files.length +
|
|
385
|
+
" files")
|
|
386
|
+
.join("\n") + "\n"
|
|
387
|
+
: "No agent configuration snapshots found. Run forge agent-config snapshot first.\n");
|
|
340
388
|
}
|
|
341
389
|
else if (action === "show") {
|
|
342
390
|
const id = ids[0];
|
|
@@ -347,9 +395,18 @@ async function main(args) {
|
|
|
347
395
|
else if (action === "diff") {
|
|
348
396
|
if (ids.length < 2)
|
|
349
397
|
throw new Error("Usage: anvil agent-config diff BEFORE_ID AFTER_ID --path PROJECT");
|
|
350
|
-
const [before, after] = await Promise.all([
|
|
398
|
+
const [before, after] = await Promise.all([
|
|
399
|
+
loadAgentConfigVersion(target, ids[0]),
|
|
400
|
+
loadAgentConfigVersion(target, ids[1]),
|
|
401
|
+
]);
|
|
351
402
|
const diff = compareAgentConfigVersions(before, after);
|
|
352
|
-
process.stdout.write([
|
|
403
|
+
process.stdout.write([
|
|
404
|
+
"Agent configuration diff",
|
|
405
|
+
"Added: " + (diff.added.join(", ") || "none"),
|
|
406
|
+
"Changed: " + (diff.changed.join(", ") || "none"),
|
|
407
|
+
"Removed: " + (diff.removed.join(", ") || "none"),
|
|
408
|
+
"Unchanged: " + diff.unchanged.length,
|
|
409
|
+
].join("\n") + "\n");
|
|
353
410
|
}
|
|
354
411
|
else if (action === "approve") {
|
|
355
412
|
throw new Error("Direct snapshot approval is disabled. Use forge agent-release prepare with a release-ready benchmark matrix, then forge agent-release approve RELEASE_ID --reviewer NAME.");
|
|
@@ -364,9 +421,12 @@ async function main(args) {
|
|
|
364
421
|
return;
|
|
365
422
|
}
|
|
366
423
|
case "experiment-history": {
|
|
367
|
-
const option = (name) => {
|
|
424
|
+
const option = (name) => {
|
|
425
|
+
const index = rest.indexOf(name);
|
|
426
|
+
return index >= 0 ? rest[index + 1] : undefined;
|
|
427
|
+
};
|
|
368
428
|
const pathIndex = rest.indexOf("--path");
|
|
369
|
-
const target = path.resolve(pathIndex >= 0 ? rest[pathIndex + 1] ?? "." : ".");
|
|
429
|
+
const target = path.resolve(pathIndex >= 0 ? (rest[pathIndex + 1] ?? ".") : ".");
|
|
370
430
|
const rawLimit = option("--limit");
|
|
371
431
|
const limit = rawLimit === undefined ? undefined : Number(rawLimit);
|
|
372
432
|
if (limit !== undefined && (!Number.isSafeInteger(limit) || limit < 1 || limit > 100)) {
|
|
@@ -378,7 +438,11 @@ async function main(args) {
|
|
|
378
438
|
const suiteId = option("--suite");
|
|
379
439
|
const candidateId = option("--candidate");
|
|
380
440
|
const reports = await listBenchmarkMatrices(target);
|
|
381
|
-
const history = buildExperimentHistory(reports, {
|
|
441
|
+
const history = buildExperimentHistory(reports, {
|
|
442
|
+
...(suiteId ? { suiteId } : {}),
|
|
443
|
+
...(candidateId ? { candidateId } : {}),
|
|
444
|
+
...(limit !== undefined ? { limit } : {}),
|
|
445
|
+
});
|
|
382
446
|
process.stdout.write(rest.includes("--json") ? JSON.stringify(history, null, 2) + "\n" : formatExperimentHistory(history) + "\n");
|
|
383
447
|
}
|
|
384
448
|
catch (error) {
|
|
@@ -389,7 +453,10 @@ async function main(args) {
|
|
|
389
453
|
}
|
|
390
454
|
case "experiment-studio": {
|
|
391
455
|
const action = rest[0] ?? "create";
|
|
392
|
-
const option = (name) => {
|
|
456
|
+
const option = (name) => {
|
|
457
|
+
const index = rest.indexOf(name);
|
|
458
|
+
return index >= 0 ? rest[index + 1] : undefined;
|
|
459
|
+
};
|
|
393
460
|
if (action !== "create" && action !== "compare") {
|
|
394
461
|
process.stderr.write("Usage: anvil experiment-studio compare --id ID --name NAME --candidates id:provider:model,id:provider:model [--config-versions id=cfg-id,id=cfg-id] [--repeats 2] [--path PROJECT]\n");
|
|
395
462
|
process.stderr.write(" or: forge experiment-studio create --id ID --name NAME --provider PROVIDER --model MODEL --skills skill-a,skill-b [--repeats 2] [--path PROJECT]\n");
|
|
@@ -402,20 +469,23 @@ async function main(args) {
|
|
|
402
469
|
const rawCandidates = option("--candidates");
|
|
403
470
|
const repeats = Number(option("--repeats") ?? "2");
|
|
404
471
|
const pathIndex = rest.indexOf("--path");
|
|
405
|
-
const target = path.resolve(pathIndex >= 0 ? rest[pathIndex + 1] ?? "." : ".");
|
|
472
|
+
const target = path.resolve(pathIndex >= 0 ? (rest[pathIndex + 1] ?? ".") : ".");
|
|
406
473
|
if (!id || !name || !rawCandidates) {
|
|
407
474
|
process.stderr.write("Usage: anvil experiment-studio compare --id ID --name NAME --candidates id:provider:model,id:provider:model [--repeats 2] [--path PROJECT]\n");
|
|
408
475
|
process.exitCode = 1;
|
|
409
476
|
return;
|
|
410
477
|
}
|
|
411
478
|
try {
|
|
412
|
-
const configVersions = new Map((option("--config-versions") ?? "")
|
|
479
|
+
const configVersions = new Map((option("--config-versions") ?? "")
|
|
480
|
+
.split(",")
|
|
481
|
+
.filter(Boolean)
|
|
482
|
+
.map((item) => {
|
|
413
483
|
const separator = item.indexOf("=");
|
|
414
484
|
if (separator < 1 || separator === item.length - 1)
|
|
415
485
|
throw new Error("Each config version must use candidate-id=cfg-xxxxxxxxxxxx format.");
|
|
416
486
|
return [item.slice(0, separator), item.slice(separator + 1)];
|
|
417
487
|
}));
|
|
418
|
-
const candidates = rawCandidates.split(",").map(item => {
|
|
488
|
+
const candidates = rawCandidates.split(",").map((item) => {
|
|
419
489
|
const [candidateId, candidateProvider, ...modelParts] = item.split(":");
|
|
420
490
|
const model = modelParts.join(":");
|
|
421
491
|
if (!candidateId || !candidateProvider || !model)
|
|
@@ -423,10 +493,15 @@ async function main(args) {
|
|
|
423
493
|
if (!["openai", "claude-code", "anthropic", "google", "ollama"].includes(candidateProvider))
|
|
424
494
|
throw new Error("Unsupported candidate provider: " + candidateProvider);
|
|
425
495
|
const configVersionId = configVersions.get(candidateId);
|
|
426
|
-
return {
|
|
496
|
+
return {
|
|
497
|
+
id: candidateId,
|
|
498
|
+
provider: candidateProvider,
|
|
499
|
+
model,
|
|
500
|
+
...(configVersionId ? { configVersionId } : {}),
|
|
501
|
+
};
|
|
427
502
|
});
|
|
428
503
|
for (const candidateId of configVersions.keys())
|
|
429
|
-
if (!candidates.some(candidate => candidate.id === candidateId))
|
|
504
|
+
if (!candidates.some((candidate) => candidate.id === candidateId))
|
|
430
505
|
throw new Error("Configuration snapshot references unknown candidate: " + candidateId);
|
|
431
506
|
for (const candidate of candidates)
|
|
432
507
|
if (candidate.configVersionId)
|
|
@@ -435,7 +510,11 @@ async function main(args) {
|
|
|
435
510
|
const destination = path.join(target, ".forge", "experiments", id + ".json");
|
|
436
511
|
const { mkdir, writeFile } = await import("node:fs/promises");
|
|
437
512
|
await mkdir(path.dirname(destination), { recursive: true, mode: 0o700 });
|
|
438
|
-
await writeFile(destination, JSON.stringify(matrix, null, 2) + "\n", {
|
|
513
|
+
await writeFile(destination, JSON.stringify(matrix, null, 2) + "\n", {
|
|
514
|
+
encoding: "utf8",
|
|
515
|
+
flag: "wx",
|
|
516
|
+
mode: 0o600,
|
|
517
|
+
});
|
|
439
518
|
process.stdout.write(formatModelComparisonMatrix(matrix) + "\nSaved: " + path.relative(target, destination) + "\n");
|
|
440
519
|
}
|
|
441
520
|
catch (error) {
|
|
@@ -449,7 +528,7 @@ async function main(args) {
|
|
|
449
528
|
const skills = option("--skills");
|
|
450
529
|
const repeats = Number(option("--repeats") ?? "2");
|
|
451
530
|
const pathIndex = rest.indexOf("--path");
|
|
452
|
-
const target = path.resolve(pathIndex >= 0 ? rest[pathIndex + 1] ?? "." : ".");
|
|
531
|
+
const target = path.resolve(pathIndex >= 0 ? (rest[pathIndex + 1] ?? ".") : ".");
|
|
453
532
|
if (!id || !name || !model || !skills) {
|
|
454
533
|
process.stderr.write("Usage: anvil experiment-studio create --id ID --name NAME --provider openai|claude-code --model MODEL --skills skill-a,skill-b [--repeats 2] [--path PROJECT]\n");
|
|
455
534
|
process.exitCode = 1;
|
|
@@ -461,16 +540,32 @@ async function main(args) {
|
|
|
461
540
|
return;
|
|
462
541
|
}
|
|
463
542
|
try {
|
|
464
|
-
const skillIds = skills
|
|
465
|
-
|
|
543
|
+
const skillIds = skills
|
|
544
|
+
.split(",")
|
|
545
|
+
.map((item) => item.trim())
|
|
546
|
+
.filter(Boolean);
|
|
547
|
+
const matrix = createSkillExperimentMatrix({
|
|
548
|
+
id,
|
|
549
|
+
name,
|
|
550
|
+
baselineCandidateId: "baseline",
|
|
551
|
+
treatmentCandidateId: "treatment",
|
|
552
|
+
provider: provider,
|
|
553
|
+
model,
|
|
554
|
+
repeats,
|
|
555
|
+
skillIds,
|
|
556
|
+
});
|
|
466
557
|
const registry = await loadSkillRegistry(target);
|
|
467
|
-
const unknown = skillIds.filter(skillId => !registry.some(skill => skill.id === skillId));
|
|
558
|
+
const unknown = skillIds.filter((skillId) => !registry.some((skill) => skill.id === skillId));
|
|
468
559
|
if (unknown.length)
|
|
469
560
|
throw new Error("Unknown workspace/built-in skill(s): " + unknown.join(", "));
|
|
470
561
|
const destination = path.join(target, ".forge", "experiments", id + ".json");
|
|
471
562
|
const { mkdir, writeFile } = await import("node:fs/promises");
|
|
472
563
|
await mkdir(path.dirname(destination), { recursive: true, mode: 0o700 });
|
|
473
|
-
await writeFile(destination, JSON.stringify(matrix, null, 2) + "\n", {
|
|
564
|
+
await writeFile(destination, JSON.stringify(matrix, null, 2) + "\n", {
|
|
565
|
+
encoding: "utf8",
|
|
566
|
+
flag: "wx",
|
|
567
|
+
mode: 0o600,
|
|
568
|
+
});
|
|
474
569
|
process.stdout.write(formatSkillExperimentMatrix(matrix) + "\nSaved: " + path.relative(target, destination) + "\n");
|
|
475
570
|
}
|
|
476
571
|
catch (error) {
|
|
@@ -482,7 +577,7 @@ async function main(args) {
|
|
|
482
577
|
case "agent-evolution": {
|
|
483
578
|
const matrixId = rest[0];
|
|
484
579
|
const pathIndex = rest.indexOf("--path");
|
|
485
|
-
const target = path.resolve(pathIndex >= 0 ? rest[pathIndex + 1] ?? "." : ".");
|
|
580
|
+
const target = path.resolve(pathIndex >= 0 ? (rest[pathIndex + 1] ?? ".") : ".");
|
|
486
581
|
if (!matrixId || matrixId.startsWith("--")) {
|
|
487
582
|
process.stderr.write("Usage: anvil agent-evolution MATRIX_ID --path PROJECT\n");
|
|
488
583
|
process.exitCode = 1;
|
|
@@ -490,7 +585,9 @@ async function main(args) {
|
|
|
490
585
|
}
|
|
491
586
|
try {
|
|
492
587
|
const history = await listBenchmarkMatrices(target);
|
|
493
|
-
const report = history
|
|
588
|
+
const report = history
|
|
589
|
+
.filter((item) => item.matrixId === matrixId)
|
|
590
|
+
.sort((a, b) => b.createdAt.localeCompare(a.createdAt))[0];
|
|
494
591
|
if (!report)
|
|
495
592
|
throw new Error("Benchmark matrix not found: " + matrixId);
|
|
496
593
|
const assessment = assessAgentEvolution(report);
|
|
@@ -528,7 +625,7 @@ async function main(args) {
|
|
|
528
625
|
return next && !next.startsWith("--") ? next : undefined;
|
|
529
626
|
};
|
|
530
627
|
const pathIndex = rest.indexOf("--path");
|
|
531
|
-
const target = path.resolve(pathIndex >= 0 ? rest[pathIndex + 1] ?? "." : ".");
|
|
628
|
+
const target = path.resolve(pathIndex >= 0 ? (rest[pathIndex + 1] ?? ".") : ".");
|
|
532
629
|
const rawLimit = option("--limit");
|
|
533
630
|
const limit = rawLimit === undefined ? undefined : Number(rawLimit);
|
|
534
631
|
if (limit !== undefined && (!Number.isSafeInteger(limit) || limit < 2 || limit > 50)) {
|
|
@@ -543,7 +640,7 @@ async function main(args) {
|
|
|
543
640
|
const report = buildAgentEvaluationIntelligence(history, {
|
|
544
641
|
...(suiteId ? { suiteId } : {}),
|
|
545
642
|
...(candidateId ? { candidateId } : {}),
|
|
546
|
-
...(limit !== undefined ? { limit } : {})
|
|
643
|
+
...(limit !== undefined ? { limit } : {}),
|
|
547
644
|
});
|
|
548
645
|
process.stdout.write(rest.includes("--json")
|
|
549
646
|
? JSON.stringify(report, null, 2) + "\n"
|
|
@@ -559,7 +656,7 @@ async function main(args) {
|
|
|
559
656
|
}
|
|
560
657
|
case "optimize-agents": {
|
|
561
658
|
const pathIndex = rest.indexOf("--path");
|
|
562
|
-
const target = path.resolve(pathIndex >= 0 ? rest[pathIndex + 1] ?? "." : ".");
|
|
659
|
+
const target = path.resolve(pathIndex >= 0 ? (rest[pathIndex + 1] ?? ".") : ".");
|
|
563
660
|
try {
|
|
564
661
|
const matrices = await listBenchmarkMatrices(target);
|
|
565
662
|
const plan = buildAgentOptimizationPlan(matrices);
|
|
@@ -575,7 +672,7 @@ async function main(args) {
|
|
|
575
672
|
}
|
|
576
673
|
case "benchmark-regression": {
|
|
577
674
|
const targetIndex = rest.indexOf("--path");
|
|
578
|
-
const target = path.resolve(targetIndex >= 0 ? rest[targetIndex + 1] ?? "." : ".");
|
|
675
|
+
const target = path.resolve(targetIndex >= 0 ? (rest[targetIndex + 1] ?? ".") : ".");
|
|
579
676
|
const matrixId = rest.find((arg, index) => !arg.startsWith("--") && index === 0);
|
|
580
677
|
try {
|
|
581
678
|
const report = await loadBenchmarkRegression(target, matrixId);
|
|
@@ -591,21 +688,26 @@ async function main(args) {
|
|
|
591
688
|
}
|
|
592
689
|
case "experiment": {
|
|
593
690
|
const action = rest[0] ?? "capture";
|
|
594
|
-
const option = (name) => {
|
|
691
|
+
const option = (name) => {
|
|
692
|
+
const index = rest.indexOf(name);
|
|
693
|
+
return index >= 0 ? rest[index + 1] : undefined;
|
|
694
|
+
};
|
|
595
695
|
const pathIndex = rest.indexOf("--path");
|
|
596
|
-
const target = path.resolve(pathIndex >= 0 ? rest[pathIndex + 1] ?? "." : ".");
|
|
696
|
+
const target = path.resolve(pathIndex >= 0 ? (rest[pathIndex + 1] ?? ".") : ".");
|
|
597
697
|
try {
|
|
598
698
|
if (action === "capture") {
|
|
599
699
|
const matrixFile = option("--matrix-file");
|
|
600
700
|
const suiteId = option("--suite");
|
|
601
701
|
const matrixId = option("--matrix-id");
|
|
602
702
|
const provider = option("--provider") ?? getAnvilEnv("ANVIL_AI_PROVIDER", "FORGE_AI_PROVIDER", "openai");
|
|
603
|
-
const model = option("--model") ??
|
|
703
|
+
const model = option("--model") ??
|
|
704
|
+
getAnvilEnv("ANVIL_AI_MODEL", "FORGE_AI_MODEL") ??
|
|
705
|
+
getAnvilEnv("ANVIL_MODEL", "FORGE_MODEL", "gpt-4.1");
|
|
604
706
|
if (!matrixFile || !suiteId || !matrixId)
|
|
605
707
|
throw new Error("Usage: anvil experiment capture --matrix-file CONFIG.json --matrix-id ID --suite SUITE_ID [--provider ID] [--model NAME] [--path PROJECT]");
|
|
606
708
|
const matrix = await loadBenchmarkMatrix(path.resolve(matrixFile));
|
|
607
709
|
const suites = await loadEvaluationSuites(target);
|
|
608
|
-
const suite = suites.find(item => item.id === suiteId);
|
|
710
|
+
const suite = suites.find((item) => item.id === suiteId);
|
|
609
711
|
if (!suite)
|
|
610
712
|
throw new Error("Evaluation suite not found: " + suiteId);
|
|
611
713
|
const fingerprints = [];
|
|
@@ -613,10 +715,24 @@ async function main(args) {
|
|
|
613
715
|
if (!candidate.configVersionId)
|
|
614
716
|
continue;
|
|
615
717
|
const snapshot = await loadAgentConfigVersion(target, candidate.configVersionId);
|
|
616
|
-
fingerprints.push({
|
|
718
|
+
fingerprints.push({
|
|
719
|
+
candidateId: candidate.id,
|
|
720
|
+
configVersionId: snapshot.id,
|
|
721
|
+
fingerprint: fingerprintAgentConfig(snapshot.files),
|
|
722
|
+
});
|
|
617
723
|
}
|
|
618
724
|
const baseUrl = getAnvilEnv("ANVIL_BASE_URL", "FORGE_BASE_URL");
|
|
619
|
-
const manifest = await captureExperimentManifest({
|
|
725
|
+
const manifest = await captureExperimentManifest({
|
|
726
|
+
projectPath: target,
|
|
727
|
+
matrixFile: path.resolve(matrixFile),
|
|
728
|
+
matrixId,
|
|
729
|
+
suiteId,
|
|
730
|
+
suite,
|
|
731
|
+
provider,
|
|
732
|
+
model,
|
|
733
|
+
...(baseUrl ? { baseUrl } : {}),
|
|
734
|
+
agentConfigFingerprints: fingerprints,
|
|
735
|
+
});
|
|
620
736
|
const saved = await saveExperimentManifest(target, manifest);
|
|
621
737
|
process.stdout.write(formatExperimentManifest(manifest) + "\nSaved: " + path.relative(target, saved) + "\n");
|
|
622
738
|
}
|
|
@@ -630,9 +746,18 @@ async function main(args) {
|
|
|
630
746
|
const ids = rest.slice(1).filter((arg, index, all) => !arg.startsWith("--") && all[index - 1] !== "--path");
|
|
631
747
|
if (ids.length !== 2)
|
|
632
748
|
throw new Error("Usage: anvil experiment compare EXPERIMENT_A EXPERIMENT_B --path PROJECT");
|
|
633
|
-
const [a, b] = await Promise.all([
|
|
749
|
+
const [a, b] = await Promise.all([
|
|
750
|
+
loadExperimentManifest(target, ids[0]),
|
|
751
|
+
loadExperimentManifest(target, ids[1]),
|
|
752
|
+
]);
|
|
634
753
|
const comparison = compareExperimentManifests(a, b);
|
|
635
|
-
process.stdout.write("Experiment reproducibility: " +
|
|
754
|
+
process.stdout.write("Experiment reproducibility: " +
|
|
755
|
+
(comparison.compatible ? "COMPATIBLE" : "NOT COMPARABLE") +
|
|
756
|
+
"\n" +
|
|
757
|
+
(comparison.differences.length
|
|
758
|
+
? comparison.differences.map((item) => " - " + item).join("\n")
|
|
759
|
+
: " Critical manifest fields match.") +
|
|
760
|
+
"\n");
|
|
636
761
|
if (!comparison.compatible)
|
|
637
762
|
process.exitCode = 2;
|
|
638
763
|
}
|
|
@@ -646,14 +771,19 @@ async function main(args) {
|
|
|
646
771
|
return;
|
|
647
772
|
}
|
|
648
773
|
case "benchmark-matrix": {
|
|
649
|
-
const configFile = rest.find(arg => !arg.startsWith("--"));
|
|
774
|
+
const configFile = rest.find((arg) => !arg.startsWith("--"));
|
|
650
775
|
const suiteIndex = rest.indexOf("--suite"), goalIndex = rest.indexOf("--goal"), pathIndex = rest.indexOf("--path");
|
|
651
|
-
const target = path.resolve(pathIndex >= 0 ? rest[pathIndex + 1] ?? "." : ".");
|
|
776
|
+
const target = path.resolve(pathIndex >= 0 ? (rest[pathIndex + 1] ?? ".") : ".");
|
|
652
777
|
const suiteId = suiteIndex >= 0 ? rest[suiteIndex + 1] : undefined;
|
|
653
778
|
const goalEnd = goalIndex >= 0 ? rest.findIndex((arg, index) => index > goalIndex && arg.startsWith("--")) : -1;
|
|
654
|
-
const goal = goalIndex >= 0
|
|
779
|
+
const goal = goalIndex >= 0
|
|
780
|
+
? rest
|
|
781
|
+
.slice(goalIndex + 1, goalEnd >= 0 ? goalEnd : rest.length)
|
|
782
|
+
.join(" ")
|
|
783
|
+
.trim()
|
|
784
|
+
: "";
|
|
655
785
|
if (!configFile || !suiteId || !goal) {
|
|
656
|
-
process.stderr.write(
|
|
786
|
+
process.stderr.write('Usage: anvil benchmark-matrix CONFIG.json --suite SUITE_ID --goal "engineering task" [--path PROJECT]\n');
|
|
657
787
|
process.exitCode = 1;
|
|
658
788
|
return;
|
|
659
789
|
}
|
|
@@ -667,7 +797,7 @@ async function main(args) {
|
|
|
667
797
|
configVersions.set(candidate.id, { id: snapshot.id, fingerprint: fingerprintAgentConfig(snapshot.files) });
|
|
668
798
|
}
|
|
669
799
|
const suites = await loadEvaluationSuites(target);
|
|
670
|
-
const suite = suites.find(item => item.id === suiteId);
|
|
800
|
+
const suite = suites.find((item) => item.id === suiteId);
|
|
671
801
|
if (!suite)
|
|
672
802
|
throw new Error("Evaluation suite not found: " + suiteId);
|
|
673
803
|
const apiKey = getAnvilEnv("ANVIL_API_KEY", "FORGE_API_KEY") ?? process.env.OPENAI_API_KEY ?? "";
|
|
@@ -675,43 +805,82 @@ async function main(args) {
|
|
|
675
805
|
const report = await executeBenchmarkMatrix(config, async (candidate, _repeat) => {
|
|
676
806
|
const createProvider = (selectedModel) => candidate.provider === "claude-code"
|
|
677
807
|
? new ClaudeCodeProvider({ cwd: target, model: selectedModel })
|
|
678
|
-
: createHostedAgentProvider({
|
|
808
|
+
: createHostedAgentProvider({
|
|
809
|
+
...process.env,
|
|
810
|
+
ANVIL_AI_PROVIDER: candidate.provider,
|
|
811
|
+
FORGE_AI_PROVIDER: candidate.provider,
|
|
812
|
+
...(apiKey ? { ANVIL_API_KEY: apiKey, FORGE_API_KEY: apiKey } : {}),
|
|
813
|
+
...(baseUrl ? { ANVIL_BASE_URL: baseUrl, FORGE_BASE_URL: baseUrl } : {}),
|
|
814
|
+
}, selectedModel);
|
|
679
815
|
const router = new ModelRouter({
|
|
680
|
-
fastModel: candidate.model,
|
|
816
|
+
fastModel: candidate.model,
|
|
817
|
+
balancedModel: candidate.model,
|
|
818
|
+
reasoningModel: candidate.model,
|
|
681
819
|
retryAttempts: Number(getAnvilEnv("ANVIL_MODEL_RETRY_ATTEMPTS", "FORGE_MODEL_RETRY_ATTEMPTS", "2")),
|
|
682
820
|
retryDelayMs: Number(getAnvilEnv("ANVIL_MODEL_RETRY_DELAY_MS", "FORGE_MODEL_RETRY_DELAY_MS", "500")),
|
|
683
|
-
...(getAnvilEnv("ANVIL_MAX_INPUT_TOKENS_PER_TASK", "FORGE_MAX_INPUT_TOKENS_PER_TASK")
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
...(getAnvilEnv("
|
|
821
|
+
...(getAnvilEnv("ANVIL_MAX_INPUT_TOKENS_PER_TASK", "FORGE_MAX_INPUT_TOKENS_PER_TASK")
|
|
822
|
+
? {
|
|
823
|
+
maxInputTokensPerTask: Number(getAnvilEnv("ANVIL_MAX_INPUT_TOKENS_PER_TASK", "FORGE_MAX_INPUT_TOKENS_PER_TASK")),
|
|
824
|
+
}
|
|
825
|
+
: {}),
|
|
826
|
+
...(getAnvilEnv("ANVIL_MAX_OUTPUT_TOKENS_PER_TASK", "FORGE_MAX_OUTPUT_TOKENS_PER_TASK")
|
|
827
|
+
? {
|
|
828
|
+
maxOutputTokensPerTask: Number(getAnvilEnv("ANVIL_MAX_OUTPUT_TOKENS_PER_TASK", "FORGE_MAX_OUTPUT_TOKENS_PER_TASK")),
|
|
829
|
+
}
|
|
830
|
+
: {}),
|
|
831
|
+
...(getAnvilEnv("ANVIL_MAX_ESTIMATED_TOKENS_PER_RUN", "FORGE_MAX_ESTIMATED_TOKENS_PER_RUN")
|
|
832
|
+
? {
|
|
833
|
+
maxEstimatedTokensPerRun: Number(getAnvilEnv("ANVIL_MAX_ESTIMATED_TOKENS_PER_RUN", "FORGE_MAX_ESTIMATED_TOKENS_PER_RUN")),
|
|
834
|
+
}
|
|
835
|
+
: {}),
|
|
836
|
+
...(getAnvilEnv("ANVIL_MAX_ESTIMATED_TOKENS_PER_AGENT", "FORGE_MAX_ESTIMATED_TOKENS_PER_AGENT")
|
|
837
|
+
? { maxEstimatedTokensPerAgent: readAgentTokenBudgets() }
|
|
838
|
+
: {}),
|
|
839
|
+
...(getAnvilEnv("ANVIL_MAX_TASK_DURATION_MS", "FORGE_MAX_TASK_DURATION_MS")
|
|
840
|
+
? { maxTaskDurationMs: Number(getAnvilEnv("ANVIL_MAX_TASK_DURATION_MS", "FORGE_MAX_TASK_DURATION_MS")) }
|
|
841
|
+
: {}),
|
|
842
|
+
...(getAnvilEnv("ANVIL_MAX_TASK_DURATION_MS_BY_AGENT", "FORGE_MAX_TASK_DURATION_MS_BY_AGENT")
|
|
843
|
+
? { maxTaskDurationMsByAgent: readAgentDurationBudgets() }
|
|
844
|
+
: {}),
|
|
689
845
|
createProvider,
|
|
690
846
|
});
|
|
691
847
|
const configWorkspace = await mkdtemp(path.join(os.tmpdir(), "forge-candidate-config-"));
|
|
692
848
|
try {
|
|
693
849
|
const snapshotId = candidate.configVersionId;
|
|
694
|
-
const snapshot = snapshotId
|
|
695
|
-
|
|
696
|
-
|
|
850
|
+
const snapshot = snapshotId
|
|
851
|
+
? await materializeAgentConfigVersion(target, snapshotId, configWorkspace)
|
|
852
|
+
: undefined;
|
|
853
|
+
if (snapshotId && !snapshot?.files.some((file) => file.path === "hooks.json")) {
|
|
854
|
+
throw new Error("Configuration snapshot " +
|
|
855
|
+
snapshotId +
|
|
856
|
+
" predates policy-hook isolation. Capture a new snapshot before benchmarking this candidate.");
|
|
697
857
|
}
|
|
698
858
|
const configRoot = snapshotId ? configWorkspace : target;
|
|
699
859
|
const run = createReviewPlan(goal);
|
|
700
860
|
const skillRegistry = await loadSkillRegistry(configRoot);
|
|
701
861
|
const agentRegistry = await loadAgentRegistry(configRoot);
|
|
702
862
|
const requestedSkillIds = candidate.skillIds;
|
|
703
|
-
const unknownSkills = (requestedSkillIds ?? []).filter(id => !skillRegistry.some(skill => skill.id === id));
|
|
863
|
+
const unknownSkills = (requestedSkillIds ?? []).filter((id) => !skillRegistry.some((skill) => skill.id === id));
|
|
704
864
|
if (unknownSkills.length)
|
|
705
865
|
throw new Error("Candidate " + candidate.id + " references unknown skill(s): " + unknownSkills.join(", "));
|
|
706
|
-
const selectedSkillsForTask = (task) => requestedSkillIds === undefined
|
|
707
|
-
|
|
866
|
+
const selectedSkillsForTask = (task) => requestedSkillIds === undefined
|
|
867
|
+
? selectSkills(skillRegistry, task.agent + " " + task.title + " " + task.prompt)
|
|
868
|
+
: skillRegistry.filter((skill) => requestedSkillIds.includes(skill.id));
|
|
869
|
+
const agentGuidanceForTask = (task) => agentRegistry.find((agent) => agent.id === task.agent)?.instructions ?? "";
|
|
708
870
|
const permissions = await loadPermissionPolicy(configRoot);
|
|
709
871
|
if (permissions.mode !== "proposal-only" || permissions.allowedTools.length > 0)
|
|
710
|
-
throw new Error("Benchmark candidate " +
|
|
872
|
+
throw new Error("Benchmark candidate " +
|
|
873
|
+
candidate.id +
|
|
874
|
+
" requests unsupported tool permissions. FORGE currently enforces proposal-only execution with no enabled tools.");
|
|
711
875
|
const hooks = await loadHooks(configRoot);
|
|
712
876
|
for (const record of run.tasks) {
|
|
713
877
|
const applied = applyBeforeAgentHooks(record.task, hooks);
|
|
714
|
-
record.task = {
|
|
878
|
+
record.task = {
|
|
879
|
+
...applied.task,
|
|
880
|
+
prompt: applied.context.length
|
|
881
|
+
? applied.task.prompt + "\n\nHook guidance:\n" + applied.context.join("\n")
|
|
882
|
+
: applied.task.prompt,
|
|
883
|
+
};
|
|
715
884
|
if (applied.blockedReason) {
|
|
716
885
|
record.status = "blocked";
|
|
717
886
|
record.error = "Blocked by policy hook: " + applied.blockedReason;
|
|
@@ -720,17 +889,49 @@ async function main(args) {
|
|
|
720
889
|
const memory = await buildProjectMemoryContext(target, goal);
|
|
721
890
|
const projectContext = memory.text;
|
|
722
891
|
const started = Date.now();
|
|
723
|
-
const completed = await advanceRun(run, router, new Set(), {
|
|
892
|
+
const completed = await advanceRun(run, router, new Set(), {
|
|
893
|
+
maxConcurrency: 4,
|
|
894
|
+
projectContext,
|
|
895
|
+
projectContextForTask: async (task) => [
|
|
896
|
+
agentGuidanceForTask(task),
|
|
897
|
+
formatSkillContext(selectedSkillsForTask(task)),
|
|
898
|
+
await buildAgentWorkspaceContext(target, task),
|
|
899
|
+
]
|
|
900
|
+
.filter(Boolean)
|
|
901
|
+
.join("\n\n"),
|
|
902
|
+
});
|
|
724
903
|
const durationMs = Date.now() - started;
|
|
725
904
|
await saveRun(target, completed);
|
|
726
905
|
await saveExecutionTrace(target, completed.id, router.traces);
|
|
727
906
|
const evaluation = evaluateRun(completed, suite);
|
|
728
907
|
await saveEvaluationReport(target, evaluation);
|
|
729
908
|
return {
|
|
730
|
-
runId: completed.id,
|
|
909
|
+
runId: completed.id,
|
|
910
|
+
score: evaluation.score,
|
|
911
|
+
passed: evaluation.passed,
|
|
731
912
|
durationMs,
|
|
732
913
|
estimatedTokens: router.traces.reduce((sum, item) => sum + item.inputTokensEstimate + item.outputTokensEstimate, 0),
|
|
733
|
-
agentScores: evaluation.cases
|
|
914
|
+
agentScores: evaluation.cases
|
|
915
|
+
.filter((item) => item.status === "scored")
|
|
916
|
+
.map((item) => {
|
|
917
|
+
const task = completed.tasks.find((record) => record.task.id === item.taskId)?.task;
|
|
918
|
+
const appliedSkills = task ? selectedSkillsForTask(task) : [];
|
|
919
|
+
return {
|
|
920
|
+
agent: item.agent,
|
|
921
|
+
caseId: item.caseId,
|
|
922
|
+
score: item.score,
|
|
923
|
+
passed: item.passed,
|
|
924
|
+
skillIds: appliedSkills.map((skill) => skill.id),
|
|
925
|
+
failedCriteria: item.criteria
|
|
926
|
+
.filter((criterion) => !criterion.passed)
|
|
927
|
+
.map((criterion) => ({
|
|
928
|
+
id: criterion.id,
|
|
929
|
+
failedChecks: criterion.checks
|
|
930
|
+
.filter((check) => !check.passed)
|
|
931
|
+
.map((check) => check.rule + ": " + check.detail),
|
|
932
|
+
})),
|
|
933
|
+
};
|
|
934
|
+
}),
|
|
734
935
|
};
|
|
735
936
|
}
|
|
736
937
|
finally {
|
|
@@ -740,19 +941,34 @@ async function main(args) {
|
|
|
740
941
|
report.suiteId = suite.id;
|
|
741
942
|
report.goal = goal;
|
|
742
943
|
if (configVersions.size)
|
|
743
|
-
report.candidateProvenance = [...configVersions.entries()].map(([candidateId, item]) => ({
|
|
944
|
+
report.candidateProvenance = [...configVersions.entries()].map(([candidateId, item]) => ({
|
|
945
|
+
candidateId,
|
|
946
|
+
configVersionId: item.id,
|
|
947
|
+
fingerprint: item.fingerprint,
|
|
948
|
+
}));
|
|
744
949
|
const experimentManifest = await captureExperimentManifest({
|
|
745
|
-
projectPath: target,
|
|
746
|
-
|
|
950
|
+
projectPath: target,
|
|
951
|
+
matrixFile: path.resolve(configFile),
|
|
952
|
+
matrixId: config.id,
|
|
953
|
+
suiteId: suite.id,
|
|
954
|
+
suite,
|
|
955
|
+
provider: "matrix",
|
|
956
|
+
model: "candidate-specific",
|
|
747
957
|
...(process.env.FORGE_BASE_URL ? { baseUrl: process.env.FORGE_BASE_URL } : {}),
|
|
748
|
-
agentConfigFingerprints: report.candidateProvenance ?? []
|
|
958
|
+
agentConfigFingerprints: report.candidateProvenance ?? [],
|
|
749
959
|
});
|
|
750
960
|
const manifestPath = await saveExperimentManifest(target, experimentManifest);
|
|
751
961
|
report.experimentManifest = { id: experimentManifest.id, fingerprint: experimentManifest.fingerprint };
|
|
752
962
|
const saved = await saveBenchmarkMatrix(target, report);
|
|
753
|
-
process.stdout.write("Experiment manifest: " +
|
|
963
|
+
process.stdout.write("Experiment manifest: " +
|
|
964
|
+
experimentManifest.id +
|
|
965
|
+
" · sha256:" +
|
|
966
|
+
experimentManifest.fingerprint +
|
|
967
|
+
"\nManifest saved: " +
|
|
968
|
+
path.relative(target, manifestPath) +
|
|
969
|
+
"\n");
|
|
754
970
|
process.stdout.write(formatBenchmarkMatrix(report) + "\nSaved: " + path.relative(target, saved) + "\n");
|
|
755
|
-
if (report.results.some(item => item.status === "failed") || report.results.some(item => !item.passed))
|
|
971
|
+
if (report.results.some((item) => item.status === "failed") || report.results.some((item) => !item.passed))
|
|
756
972
|
process.exitCode = 2;
|
|
757
973
|
}
|
|
758
974
|
catch (error) {
|
|
@@ -764,12 +980,14 @@ async function main(args) {
|
|
|
764
980
|
case "benchmark": {
|
|
765
981
|
const pathIndex = rest.indexOf("--path"), suiteIndex = rest.indexOf("--suite");
|
|
766
982
|
const runId = rest.find((arg, index) => !arg.startsWith("--") && rest[index - 1] !== "--path" && rest[index - 1] !== "--suite");
|
|
767
|
-
const target = path.resolve(pathIndex >= 0 ? rest[pathIndex + 1] ?? "." : ".");
|
|
983
|
+
const target = path.resolve(pathIndex >= 0 ? (rest[pathIndex + 1] ?? ".") : ".");
|
|
768
984
|
const suiteId = suiteIndex >= 0 ? rest[suiteIndex + 1] : undefined;
|
|
769
985
|
try {
|
|
770
986
|
if (!runId) {
|
|
771
987
|
const documents = await listBenchmarks(target);
|
|
772
|
-
process.stdout.write(documents.length
|
|
988
|
+
process.stdout.write(documents.length
|
|
989
|
+
? documents.map((document) => formatBenchmark(document)).join("\n\n") + "\n"
|
|
990
|
+
: "No benchmark history. Evaluate and record a run with: forge benchmark RUN_ID --path .\n");
|
|
773
991
|
return;
|
|
774
992
|
}
|
|
775
993
|
const report = await loadEvaluationReport(target, runId, suiteId);
|
|
@@ -784,9 +1002,9 @@ async function main(args) {
|
|
|
784
1002
|
return;
|
|
785
1003
|
}
|
|
786
1004
|
case "evaluate": {
|
|
787
|
-
const runId = rest.find(arg => !arg.startsWith("--"));
|
|
1005
|
+
const runId = rest.find((arg) => !arg.startsWith("--"));
|
|
788
1006
|
const pathIndex = rest.indexOf("--path"), suiteIndex = rest.indexOf("--suite");
|
|
789
|
-
const target = path.resolve(pathIndex >= 0 ? rest[pathIndex + 1] ?? "." : ".");
|
|
1007
|
+
const target = path.resolve(pathIndex >= 0 ? (rest[pathIndex + 1] ?? ".") : ".");
|
|
790
1008
|
const suiteId = suiteIndex >= 0 ? rest[suiteIndex + 1] : undefined;
|
|
791
1009
|
if (!runId) {
|
|
792
1010
|
process.stderr.write("Usage: anvil evaluate RUNID [--suite SUITE_ID] [--path PROJECT]\n");
|
|
@@ -795,20 +1013,27 @@ async function main(args) {
|
|
|
795
1013
|
}
|
|
796
1014
|
try {
|
|
797
1015
|
const suites = await loadEvaluationSuites(target);
|
|
798
|
-
const suite = suiteId ? suites.find(item => item.id === suiteId) : suites[0];
|
|
1016
|
+
const suite = suiteId ? suites.find((item) => item.id === suiteId) : suites[0];
|
|
799
1017
|
if (!suite)
|
|
800
|
-
throw new Error(suiteId
|
|
1018
|
+
throw new Error(suiteId
|
|
1019
|
+
? "Evaluation suite not found: " + suiteId
|
|
1020
|
+
: "No evaluation suite found. Add one under .forge/evals/.");
|
|
801
1021
|
const run = await loadRun(target, runId);
|
|
802
1022
|
const judgeEnabled = rest.includes("--judge");
|
|
803
1023
|
let report;
|
|
804
1024
|
if (judgeEnabled) {
|
|
805
1025
|
const providerChoice = getAnvilEnv("ANVIL_AI_PROVIDER", "FORGE_AI_PROVIDER", "openai");
|
|
806
|
-
const model = getAnvilEnv("ANVIL_EVAL_JUDGE_MODEL", "FORGE_EVAL_JUDGE_MODEL") ??
|
|
1026
|
+
const model = getAnvilEnv("ANVIL_EVAL_JUDGE_MODEL", "FORGE_EVAL_JUDGE_MODEL") ??
|
|
1027
|
+
getAnvilEnv("ANVIL_AI_MODEL", "FORGE_AI_MODEL") ??
|
|
1028
|
+
getAnvilEnv("ANVIL_MODEL", "FORGE_MODEL") ??
|
|
1029
|
+
(providerChoice === "claude-code" ? "sonnet" : "gpt-4.1");
|
|
807
1030
|
const apiKey = getAnvilEnv("ANVIL_API_KEY", "FORGE_API_KEY") ?? process.env.OPENAI_API_KEY ?? "";
|
|
808
1031
|
const baseUrl = getAnvilEnv("ANVIL_BASE_URL", "FORGE_BASE_URL", "https://api.openai.com/v1");
|
|
809
1032
|
if (providerChoice !== "claude-code" && !apiKey)
|
|
810
1033
|
throw new Error("Set ANVIL_API_KEY, FORGE_API_KEY, or OPENAI_API_KEY to use model-judged evaluation.");
|
|
811
|
-
const judgeProvider = providerChoice === "claude-code"
|
|
1034
|
+
const judgeProvider = providerChoice === "claude-code"
|
|
1035
|
+
? new ClaudeCodeProvider({ cwd: target, model })
|
|
1036
|
+
: new OpenAICompatibleProvider({ apiKey, model, baseUrl });
|
|
812
1037
|
report = await evaluateRunWithJudge(run, suite, judgeProvider);
|
|
813
1038
|
}
|
|
814
1039
|
else
|
|
@@ -816,7 +1041,12 @@ async function main(args) {
|
|
|
816
1041
|
const reportPath = await saveEvaluationReport(target, report);
|
|
817
1042
|
process.stdout.write(formatEvaluationReport(report) + "\n");
|
|
818
1043
|
if ("judgedCases" in report) {
|
|
819
|
-
process.stdout.write("Model judge: " +
|
|
1044
|
+
process.stdout.write("Model judge: " +
|
|
1045
|
+
report.judge.provider +
|
|
1046
|
+
(report.judge.model ? " / " + report.judge.model : "") +
|
|
1047
|
+
" · " +
|
|
1048
|
+
report.judge.evaluatedCases +
|
|
1049
|
+
" cases\n");
|
|
820
1050
|
for (const item of report.judgedCases)
|
|
821
1051
|
process.stdout.write(" " + item.caseId + " · " + item.result.score + "/100 · " + item.result.rationale + "\n");
|
|
822
1052
|
}
|
|
@@ -831,7 +1061,7 @@ async function main(args) {
|
|
|
831
1061
|
return;
|
|
832
1062
|
}
|
|
833
1063
|
case "agents": {
|
|
834
|
-
const target = rest.find(arg => !arg.startsWith("--")) ?? ".";
|
|
1064
|
+
const target = rest.find((arg) => !arg.startsWith("--")) ?? ".";
|
|
835
1065
|
try {
|
|
836
1066
|
const agents = await loadAgentRegistry(path.resolve(target));
|
|
837
1067
|
process.stdout.write("FORGE agent registry\n\n");
|
|
@@ -847,22 +1077,28 @@ async function main(args) {
|
|
|
847
1077
|
return;
|
|
848
1078
|
}
|
|
849
1079
|
case "skills": {
|
|
850
|
-
const option = (name) => {
|
|
851
|
-
|
|
1080
|
+
const option = (name) => {
|
|
1081
|
+
const index = rest.indexOf(name);
|
|
1082
|
+
return index >= 0 ? rest[index + 1] : undefined;
|
|
1083
|
+
};
|
|
1084
|
+
const target = path.resolve(rest.find((arg) => !arg.startsWith("--") && arg !== option("--show") && arg !== option("--match")) ?? ".");
|
|
852
1085
|
try {
|
|
853
1086
|
const skills = await loadSkillRegistry(target);
|
|
854
1087
|
const showId = option("--show");
|
|
855
1088
|
const matchGoal = option("--match");
|
|
856
1089
|
if (showId) {
|
|
857
|
-
const skill = skills.find(item => item.id === showId);
|
|
1090
|
+
const skill = skills.find((item) => item.id === showId);
|
|
858
1091
|
if (!skill)
|
|
859
1092
|
throw new Error("Skill not found: " + showId);
|
|
860
1093
|
process.stdout.write((rest.includes("--json") ? JSON.stringify(skill, null, 2) : formatSkillContext([skill])) + "\n");
|
|
861
1094
|
}
|
|
862
1095
|
else if (matchGoal !== undefined) {
|
|
863
1096
|
const selected = selectSkills(skills, matchGoal);
|
|
864
|
-
process.stdout.write(rest.includes("--json")
|
|
865
|
-
|
|
1097
|
+
process.stdout.write(rest.includes("--json")
|
|
1098
|
+
? JSON.stringify(selected, null, 2) + "\n"
|
|
1099
|
+
: selected.length
|
|
1100
|
+
? selected.map((skill) => skill.id + " " + skill.name + " — " + skill.description).join("\n") + "\n"
|
|
1101
|
+
: "No skills matched that goal.\n");
|
|
866
1102
|
}
|
|
867
1103
|
else if (rest.includes("--json")) {
|
|
868
1104
|
process.stdout.write(JSON.stringify(skills, null, 2) + "\n");
|
|
@@ -871,7 +1107,7 @@ async function main(args) {
|
|
|
871
1107
|
process.stdout.write("FORGE skill registry (" + skills.length + ")\n\n");
|
|
872
1108
|
for (const skill of skills)
|
|
873
1109
|
process.stdout.write(" " + skill.id.padEnd(24) + " " + skill.name + " [" + skill.source + "]\n " + skill.description + "\n");
|
|
874
|
-
process.stdout.write(
|
|
1110
|
+
process.stdout.write('\nUse --show ID to inspect instructions or --match "GOAL" to preview task selection.\n');
|
|
875
1111
|
}
|
|
876
1112
|
}
|
|
877
1113
|
catch (error) {
|
|
@@ -881,12 +1117,10 @@ async function main(args) {
|
|
|
881
1117
|
return;
|
|
882
1118
|
}
|
|
883
1119
|
case "agent-security": {
|
|
884
|
-
const target = path.resolve(rest.find(arg => !arg.startsWith("--")) ?? ".");
|
|
1120
|
+
const target = path.resolve(rest.find((arg) => !arg.startsWith("--")) ?? ".");
|
|
885
1121
|
try {
|
|
886
1122
|
const report = await auditAgentConfiguration(target);
|
|
887
|
-
process.stdout.write(rest.includes("--json")
|
|
888
|
-
? JSON.stringify(report, null, 2) + "\n"
|
|
889
|
-
: formatAgentSecurityReport(report) + "\n");
|
|
1123
|
+
process.stdout.write(rest.includes("--json") ? JSON.stringify(report, null, 2) + "\n" : formatAgentSecurityReport(report) + "\n");
|
|
890
1124
|
if (report.summary.critical > 0)
|
|
891
1125
|
process.exitCode = 2;
|
|
892
1126
|
}
|
|
@@ -899,7 +1133,7 @@ async function main(args) {
|
|
|
899
1133
|
case "hook":
|
|
900
1134
|
case "hooks": {
|
|
901
1135
|
if (rest[0] === "install" || rest.includes("--install")) {
|
|
902
|
-
const target = path.resolve(rest.find(arg => !arg.startsWith("--") && arg !== "install" && arg !== "pre-commit") ?? ".");
|
|
1136
|
+
const target = path.resolve(rest.find((arg) => !arg.startsWith("--") && arg !== "install" && arg !== "pre-commit") ?? ".");
|
|
903
1137
|
try {
|
|
904
1138
|
const { installPrecommitHook } = await import("./core/project-cleaner.js");
|
|
905
1139
|
const result = await installPrecommitHook(target);
|
|
@@ -913,10 +1147,13 @@ async function main(args) {
|
|
|
913
1147
|
}
|
|
914
1148
|
return;
|
|
915
1149
|
}
|
|
916
|
-
const target = path.resolve(rest.find(arg => !arg.startsWith("--")) ?? ".");
|
|
1150
|
+
const target = path.resolve(rest.find((arg) => !arg.startsWith("--")) ?? ".");
|
|
917
1151
|
try {
|
|
918
1152
|
const hooks = await loadHooks(target);
|
|
919
|
-
process.stdout.write(hooks.length
|
|
1153
|
+
process.stdout.write(hooks.length
|
|
1154
|
+
? hooks.map((hook) => hook.id + " [" + hook.event + "] " + hook.action + ": " + hook.message).join("\n") +
|
|
1155
|
+
"\n"
|
|
1156
|
+
: "No lifecycle hooks configured.\n");
|
|
920
1157
|
}
|
|
921
1158
|
catch (error) {
|
|
922
1159
|
process.stderr.write("Could not load hooks: " + (error instanceof Error ? error.message : String(error)) + "\n");
|
|
@@ -926,19 +1163,24 @@ async function main(args) {
|
|
|
926
1163
|
}
|
|
927
1164
|
case "memory": {
|
|
928
1165
|
const [action = "list", ...memoryArgs] = rest;
|
|
929
|
-
const option = (name) => {
|
|
1166
|
+
const option = (name) => {
|
|
1167
|
+
const index = memoryArgs.indexOf(name);
|
|
1168
|
+
return index >= 0 ? memoryArgs[index + 1] : undefined;
|
|
1169
|
+
};
|
|
930
1170
|
const skipValues = new Set();
|
|
931
1171
|
for (let i = 0; i < memoryArgs.length; i++) {
|
|
932
1172
|
if (memoryArgs[i]?.startsWith("--"))
|
|
933
1173
|
skipValues.add(i + 1);
|
|
934
1174
|
}
|
|
935
1175
|
const positional = memoryArgs.filter((arg, i) => !arg.startsWith("--") && !skipValues.has(i));
|
|
936
|
-
const targetPath = positional.find(arg => !arg.startsWith("mem-")) ?? ".";
|
|
1176
|
+
const targetPath = positional.find((arg) => !arg.startsWith("mem-")) ?? ".";
|
|
937
1177
|
const target = path.resolve(targetPath);
|
|
938
1178
|
try {
|
|
939
1179
|
if (action === "list") {
|
|
940
1180
|
const entries = await listProjectMemory(target);
|
|
941
|
-
process.stdout.write(entries.length
|
|
1181
|
+
process.stdout.write(entries.length
|
|
1182
|
+
? entries.map((entry) => `${entry.id} [${entry.kind}] ${entry.content}`).join("\n") + "\n"
|
|
1183
|
+
: "No project memory entries.\n");
|
|
942
1184
|
}
|
|
943
1185
|
else if (action === "add") {
|
|
944
1186
|
const kind = option("--kind");
|
|
@@ -951,7 +1193,7 @@ async function main(args) {
|
|
|
951
1193
|
process.stdout.write(`Saved ${entry.id} to project memory\n`);
|
|
952
1194
|
}
|
|
953
1195
|
else if (action === "remove") {
|
|
954
|
-
const id = memoryArgs.find(arg => arg.startsWith("mem-"));
|
|
1196
|
+
const id = memoryArgs.find((arg) => arg.startsWith("mem-"));
|
|
955
1197
|
if (!id)
|
|
956
1198
|
throw new Error("Usage: anvil memory remove [path] mem-ID");
|
|
957
1199
|
const removed = await removeProjectMemory(target, id);
|
|
@@ -974,7 +1216,10 @@ async function main(args) {
|
|
|
974
1216
|
}
|
|
975
1217
|
case "mcp": {
|
|
976
1218
|
const [subcommand = "info", ...mcpArgs] = rest;
|
|
977
|
-
const option = (name) => {
|
|
1219
|
+
const option = (name) => {
|
|
1220
|
+
const index = mcpArgs.indexOf(name);
|
|
1221
|
+
return index >= 0 ? mcpArgs[index + 1] : undefined;
|
|
1222
|
+
};
|
|
978
1223
|
const skipValues = new Set();
|
|
979
1224
|
for (let i = 0; i < mcpArgs.length; i++) {
|
|
980
1225
|
if (mcpArgs[i]?.startsWith("--"))
|
|
@@ -1028,7 +1273,10 @@ Subcommands:
|
|
|
1028
1273
|
return;
|
|
1029
1274
|
}
|
|
1030
1275
|
const [action = "list", ...adrArgs] = rest;
|
|
1031
|
-
const option = (name) => {
|
|
1276
|
+
const option = (name) => {
|
|
1277
|
+
const index = adrArgs.indexOf(name);
|
|
1278
|
+
return index >= 0 ? adrArgs[index + 1] : undefined;
|
|
1279
|
+
};
|
|
1032
1280
|
const skipValues = new Set();
|
|
1033
1281
|
for (let i = 0; i < adrArgs.length; i++) {
|
|
1034
1282
|
if (adrArgs[i]?.startsWith("--"))
|
|
@@ -1039,12 +1287,14 @@ Subcommands:
|
|
|
1039
1287
|
if (action === "init") {
|
|
1040
1288
|
const target = path.resolve(positional[0] ?? ".");
|
|
1041
1289
|
const res = await initAdrDirectory(target);
|
|
1042
|
-
process.stdout.write(res.created
|
|
1290
|
+
process.stdout.write(res.created
|
|
1291
|
+
? `Initialized Architecture Decision Records in ${res.path}\n`
|
|
1292
|
+
: `ADR directory already initialized in ${res.path}\n`);
|
|
1043
1293
|
}
|
|
1044
1294
|
else if (action === "new") {
|
|
1045
1295
|
const title = positional[0];
|
|
1046
1296
|
if (!title)
|
|
1047
|
-
throw new Error(
|
|
1297
|
+
throw new Error('Usage: anvil adr new "Title of decision" [path] [--status Proposed|Accepted]');
|
|
1048
1298
|
const target = path.resolve(positional[1] ?? ".");
|
|
1049
1299
|
const status = (option("--status") ?? "Accepted");
|
|
1050
1300
|
const context = option("--context");
|
|
@@ -1056,7 +1306,9 @@ Subcommands:
|
|
|
1056
1306
|
const target = path.resolve(positional[0] ?? ".");
|
|
1057
1307
|
const res = await syncMemoryToAdrs(target);
|
|
1058
1308
|
process.stdout.write(res.syncedCount > 0
|
|
1059
|
-
? `Synced ${res.syncedCount} decisions from project memory to docs/adr/:\n` +
|
|
1309
|
+
? `Synced ${res.syncedCount} decisions from project memory to docs/adr/:\n` +
|
|
1310
|
+
res.createdAdrs.map((a) => ` - [${a.id}] ${a.filename}`).join("\n") +
|
|
1311
|
+
"\n"
|
|
1060
1312
|
: `All project memory decisions are already synced to docs/adr/.\n`);
|
|
1061
1313
|
}
|
|
1062
1314
|
else if (action === "list") {
|
|
@@ -1097,14 +1349,16 @@ Options:
|
|
|
1097
1349
|
}
|
|
1098
1350
|
const isJson = rest.includes("--json");
|
|
1099
1351
|
const shouldFix = rest.includes("--fix");
|
|
1100
|
-
const positional = rest.filter(arg => !arg.startsWith("--"));
|
|
1352
|
+
const positional = rest.filter((arg) => !arg.startsWith("--"));
|
|
1101
1353
|
const target = path.resolve(positional[0] ?? ".");
|
|
1102
1354
|
try {
|
|
1103
1355
|
const report = await scanProjectSecurity(target);
|
|
1104
1356
|
if (shouldFix && report.findings.length > 0) {
|
|
1105
1357
|
const fixResult = await applySecurityFixes(target, report.findings);
|
|
1106
1358
|
if (fixResult.fixedCount > 0) {
|
|
1107
|
-
process.stdout.write(`Applied ${fixResult.fixedCount} security fix(es):\n` +
|
|
1359
|
+
process.stdout.write(`Applied ${fixResult.fixedCount} security fix(es):\n` +
|
|
1360
|
+
fixResult.details.map((d) => ` ✓ ${d}`).join("\n") +
|
|
1361
|
+
"\n\n");
|
|
1108
1362
|
}
|
|
1109
1363
|
}
|
|
1110
1364
|
if (isJson) {
|
|
@@ -1132,11 +1386,13 @@ and code quality rules against policies. Emits human-readable reports, machine-r
|
|
|
1132
1386
|
or OASIS SARIF v2.1.0 for PR comments and GitHub Security tab integration.
|
|
1133
1387
|
|
|
1134
1388
|
Options:
|
|
1135
|
-
--sarif PATH
|
|
1136
|
-
--policy PATH
|
|
1137
|
-
--
|
|
1138
|
-
--
|
|
1139
|
-
--
|
|
1389
|
+
--sarif PATH Export findings to an OASIS SARIF v2.1.0 report file
|
|
1390
|
+
--policy PATH Custom JSON policy file (defaults to .anvil/policy.json if present)
|
|
1391
|
+
--baseline PATH Baseline JSON file to suppress known existing findings
|
|
1392
|
+
--generate-baseline PATH Export current findings as a baseline JSON file
|
|
1393
|
+
--fail-on-warnings Fail gate (exit 1) on medium-severity warnings as well as critical/high errors
|
|
1394
|
+
--json Output full gate evaluation in machine-readable JSON format
|
|
1395
|
+
--help Show this help message
|
|
1140
1396
|
|
|
1141
1397
|
Exit codes:
|
|
1142
1398
|
0 Gate passed: all policy thresholds and security checks satisfied.
|
|
@@ -1155,13 +1411,35 @@ Exit codes:
|
|
|
1155
1411
|
const failOnWarnings = rest.includes("--fail-on-warnings");
|
|
1156
1412
|
const sarifPath = option("--sarif");
|
|
1157
1413
|
const policyPath = option("--policy");
|
|
1158
|
-
const
|
|
1414
|
+
const baselinePath = option("--baseline");
|
|
1415
|
+
const generateBaselinePath = option("--generate-baseline");
|
|
1416
|
+
const positional = rest.filter((arg) => !arg.startsWith("--") &&
|
|
1417
|
+
arg !== sarifPath &&
|
|
1418
|
+
arg !== policyPath &&
|
|
1419
|
+
arg !== baselinePath &&
|
|
1420
|
+
arg !== generateBaselinePath);
|
|
1159
1421
|
const target = path.resolve(positional[0] ?? ".");
|
|
1160
1422
|
try {
|
|
1161
|
-
const
|
|
1162
|
-
|
|
1423
|
+
const evaluation = await evaluateGate(target, {
|
|
1424
|
+
policyPath,
|
|
1425
|
+
baselinePath,
|
|
1426
|
+
failOnWarnings,
|
|
1427
|
+
});
|
|
1428
|
+
if (generateBaselinePath) {
|
|
1429
|
+
const outResolved = path.resolve(generateBaselinePath);
|
|
1430
|
+
await mkdir(path.dirname(outResolved), { recursive: true });
|
|
1431
|
+
await writeFile(outResolved, generateBaselineJson(evaluation.activeFindings), "utf8");
|
|
1432
|
+
if (!isJson) {
|
|
1433
|
+
process.stdout.write(`Generated baseline with ${evaluation.activeFindings.length} findings to ${path.relative(process.cwd(), outResolved)}\n`);
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1163
1436
|
if (sarifPath) {
|
|
1164
|
-
const sarifOutput = generateSarif({
|
|
1437
|
+
const sarifOutput = generateSarif({
|
|
1438
|
+
activeFindings: evaluation.activeFindings,
|
|
1439
|
+
suppressedFindings: evaluation.suppressedFindings,
|
|
1440
|
+
filterSuppressed: true,
|
|
1441
|
+
targetRoot: target,
|
|
1442
|
+
});
|
|
1165
1443
|
const outResolved = path.resolve(sarifPath);
|
|
1166
1444
|
await mkdir(path.dirname(outResolved), { recursive: true });
|
|
1167
1445
|
await writeFile(outResolved, sarifOutput, "utf8");
|
|
@@ -1169,42 +1447,46 @@ Exit codes:
|
|
|
1169
1447
|
process.stdout.write(`Exported SARIF report to ${path.relative(process.cwd(), outResolved)}\n`);
|
|
1170
1448
|
}
|
|
1171
1449
|
}
|
|
1172
|
-
const criticalCount = securityReport.summary.critical;
|
|
1173
|
-
const highCount = securityReport.summary.high + reviewReport.summary.high;
|
|
1174
|
-
const mediumCount = securityReport.summary.medium + reviewReport.summary.medium;
|
|
1175
|
-
const passed = criticalCount === 0 && highCount === 0 && (!failOnWarnings || mediumCount === 0);
|
|
1176
1450
|
if (isJson) {
|
|
1177
1451
|
process.stdout.write(JSON.stringify({
|
|
1178
|
-
gate: passed ? "PASSED" : "FAILED",
|
|
1452
|
+
gate: evaluation.passed ? "PASSED" : "FAILED",
|
|
1179
1453
|
target,
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
security: securityReport,
|
|
1187
|
-
review: reviewReport
|
|
1454
|
+
policySource: evaluation.policySource,
|
|
1455
|
+
baselineSource: evaluation.baselineSource,
|
|
1456
|
+
violations: evaluation.violations,
|
|
1457
|
+
summary: evaluation.summary,
|
|
1458
|
+
activeFindings: evaluation.activeFindings,
|
|
1459
|
+
suppressedFindings: evaluation.suppressedFindings,
|
|
1188
1460
|
}, null, 2) + "\n");
|
|
1189
1461
|
}
|
|
1190
1462
|
else {
|
|
1191
|
-
|
|
1463
|
+
const lines = [
|
|
1192
1464
|
`# ANVIL CI Quality & Security Gate`,
|
|
1193
1465
|
`Target: ${target}`,
|
|
1194
|
-
`Status: ${passed ? "PASSED" : "FAILED"}`,
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
`
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1466
|
+
`Status: ${evaluation.passed ? "PASSED" : "FAILED"}`,
|
|
1467
|
+
`Policy: ${evaluation.policySource}`,
|
|
1468
|
+
];
|
|
1469
|
+
if (evaluation.baselineSource) {
|
|
1470
|
+
lines.push(`Baseline: ${evaluation.baselineSource} (${evaluation.summary.suppressedByBaseline} findings suppressed)`);
|
|
1471
|
+
}
|
|
1472
|
+
lines.push(``, `Findings Summary:`, ` Critical: ${evaluation.summary.critical}`, ` High: ${evaluation.summary.high}`, ` Medium: ${evaluation.summary.medium}`, ` Low: ${evaluation.summary.low}`);
|
|
1473
|
+
if (evaluation.summary.suppressedByBaseline > 0) {
|
|
1474
|
+
lines.push(` Suppressed by baseline: ${evaluation.summary.suppressedByBaseline}`);
|
|
1475
|
+
}
|
|
1476
|
+
lines.push(``);
|
|
1477
|
+
if (evaluation.violations.length > 0) {
|
|
1478
|
+
lines.push(`Policy Violations:`);
|
|
1479
|
+
for (const v of evaluation.violations) {
|
|
1480
|
+
lines.push(` ✗ ${v}`);
|
|
1481
|
+
}
|
|
1482
|
+
lines.push(``);
|
|
1483
|
+
}
|
|
1484
|
+
lines.push(evaluation.passed
|
|
1485
|
+
? `✓ Gate passed: all policy thresholds satisfied.`
|
|
1486
|
+
: `✗ Gate failed: ${evaluation.violations.length} policy violations detected.`);
|
|
1487
|
+
process.stdout.write(lines.join("\n") + "\n");
|
|
1206
1488
|
}
|
|
1207
|
-
if (!passed) {
|
|
1489
|
+
if (!evaluation.passed) {
|
|
1208
1490
|
process.exitCode = 1;
|
|
1209
1491
|
}
|
|
1210
1492
|
}
|
|
@@ -1218,8 +1500,13 @@ Exit codes:
|
|
|
1218
1500
|
const goalIndex = rest.indexOf("--goal");
|
|
1219
1501
|
const pathIndex = rest.indexOf("--path");
|
|
1220
1502
|
const goalEnd = pathIndex >= 0 ? pathIndex : rest.length;
|
|
1221
|
-
const goal = goalIndex >= 0
|
|
1222
|
-
|
|
1503
|
+
const goal = goalIndex >= 0
|
|
1504
|
+
? rest
|
|
1505
|
+
.slice(goalIndex + 1, goalEnd)
|
|
1506
|
+
.join(" ")
|
|
1507
|
+
.trim()
|
|
1508
|
+
: "";
|
|
1509
|
+
const target = path.resolve(pathIndex >= 0 ? (rest[pathIndex + 1] ?? ".") : ".");
|
|
1223
1510
|
try {
|
|
1224
1511
|
const plan = createReviewPlan(goal);
|
|
1225
1512
|
const saved = await saveRun(target, plan);
|
|
@@ -1236,7 +1523,7 @@ Exit codes:
|
|
|
1236
1523
|
case "replay": {
|
|
1237
1524
|
const runId = rest[0] ?? "";
|
|
1238
1525
|
const pathIndex = rest.indexOf("--path");
|
|
1239
|
-
const target = path.resolve(pathIndex >= 0 ? rest[pathIndex + 1] ?? "." : ".");
|
|
1526
|
+
const target = path.resolve(pathIndex >= 0 ? (rest[pathIndex + 1] ?? ".") : ".");
|
|
1240
1527
|
try {
|
|
1241
1528
|
if (!runId)
|
|
1242
1529
|
throw new Error("Usage: anvil replay RUN_ID [--path PROJECT]");
|
|
@@ -1257,13 +1544,13 @@ Exit codes:
|
|
|
1257
1544
|
const runId = rest[0] ?? "";
|
|
1258
1545
|
const taskId = rest[1] ?? "";
|
|
1259
1546
|
const pathIndex = rest.indexOf("--path");
|
|
1260
|
-
const target = path.resolve(pathIndex >= 0 ? rest[pathIndex + 1] ?? "." : ".");
|
|
1547
|
+
const target = path.resolve(pathIndex >= 0 ? (rest[pathIndex + 1] ?? ".") : ".");
|
|
1261
1548
|
const reviewerIndex = rest.indexOf("--reviewer");
|
|
1262
1549
|
const reasonIndex = rest.indexOf("--reason");
|
|
1263
1550
|
try {
|
|
1264
1551
|
if (!runId || !taskId)
|
|
1265
1552
|
throw new Error("Usage: anvil approve RUN_ID TASK_ID [--reviewer NAME] [--reason TEXT] [--path PROJECT]");
|
|
1266
|
-
const updated = await decideTaskApproval(target, runId, taskId, "approved", reviewerIndex >= 0 ? rest[reviewerIndex + 1] ?? "local-user" : "local-user", reasonIndex >= 0 ? rest.slice(reasonIndex + 1, pathIndex >= 0 ? pathIndex : rest.length).join(" ") : undefined);
|
|
1553
|
+
const updated = await decideTaskApproval(target, runId, taskId, "approved", reviewerIndex >= 0 ? (rest[reviewerIndex + 1] ?? "local-user") : "local-user", reasonIndex >= 0 ? rest.slice(reasonIndex + 1, pathIndex >= 0 ? pathIndex : rest.length).join(" ") : undefined);
|
|
1267
1554
|
process.stdout.write("Approved " + taskId + " in " + runId + ". Resume explicitly with `forge resume " + runId + "`.\n");
|
|
1268
1555
|
process.stdout.write("Run status: " + updated.status + "\n");
|
|
1269
1556
|
}
|
|
@@ -1276,12 +1563,12 @@ Exit codes:
|
|
|
1276
1563
|
case "resume": {
|
|
1277
1564
|
const runId = rest[0] ?? "";
|
|
1278
1565
|
const pathIndex = rest.indexOf("--path");
|
|
1279
|
-
const target = path.resolve(pathIndex >= 0 ? rest[pathIndex + 1] ?? "." : ".");
|
|
1566
|
+
const target = path.resolve(pathIndex >= 0 ? (rest[pathIndex + 1] ?? ".") : ".");
|
|
1280
1567
|
try {
|
|
1281
1568
|
if (!runId)
|
|
1282
1569
|
throw new Error("Usage: anvil resume RUN_ID [--path PROJECT]");
|
|
1283
1570
|
const permissions = await loadPermissionPolicy(target);
|
|
1284
|
-
const providerChoice =
|
|
1571
|
+
const providerChoice = getAnvilEnv("ANVIL_AI_PROVIDER", "FORGE_AI_PROVIDER", "openai").toLowerCase();
|
|
1285
1572
|
assertSupportedAgentPolicy(permissions, providerChoice, "ANVIL resume");
|
|
1286
1573
|
await withRunExecutionLock(target, runId, async () => {
|
|
1287
1574
|
const savedRun = await loadRun(target, runId);
|
|
@@ -1295,7 +1582,9 @@ Exit codes:
|
|
|
1295
1582
|
throw new Error("Only pending or approval-cleared runs can be resumed. Use `anvil replay` only after reviewing failed tasks.");
|
|
1296
1583
|
const model = getAnvilEnv("ANVIL_AI_MODEL", "FORGE_AI_MODEL") ?? getAnvilEnv("ANVIL_MODEL", "FORGE_MODEL");
|
|
1297
1584
|
const baseModel = model ?? (providerChoice === "claude-code" ? "sonnet" : "gpt-4.1-mini");
|
|
1298
|
-
const createProvider = (selectedModel) => providerChoice === "claude-code"
|
|
1585
|
+
const createProvider = (selectedModel) => providerChoice === "claude-code"
|
|
1586
|
+
? new ClaudeCodeProvider({ cwd: target, model: selectedModel })
|
|
1587
|
+
: createHostedAgentProvider({ ...process.env, ANVIL_AI_PROVIDER: providerChoice, FORGE_AI_PROVIDER: providerChoice }, selectedModel, { workspacePath: target, permissionPolicy: permissions });
|
|
1299
1588
|
let priorTraceEntries = [];
|
|
1300
1589
|
try {
|
|
1301
1590
|
priorTraceEntries = (await loadExecutionTrace(target, runId)).entries;
|
|
@@ -1304,17 +1593,48 @@ Exit codes:
|
|
|
1304
1593
|
if (!(error && typeof error === "object" && "code" in error && error.code === "ENOENT"))
|
|
1305
1594
|
throw error;
|
|
1306
1595
|
}
|
|
1307
|
-
const traceAgentUsage = priorTraceEntries.reduce((usage, entry) => {
|
|
1596
|
+
const traceAgentUsage = priorTraceEntries.reduce((usage, entry) => {
|
|
1597
|
+
usage[entry.agent] = (usage[entry.agent] ?? 0) + entry.inputTokensEstimate + entry.outputTokensEstimate;
|
|
1598
|
+
return usage;
|
|
1599
|
+
}, {});
|
|
1308
1600
|
const traceRunUsage = priorTraceEntries.reduce((total, entry) => total + entry.inputTokensEstimate + entry.outputTokensEstimate, 0);
|
|
1309
1601
|
const priorAgentUsage = savedRun.tokenUsage?.estimatedTokensByAgent ?? traceAgentUsage;
|
|
1310
1602
|
const priorRunUsage = savedRun.tokenUsage?.estimatedTokensUsed ?? traceRunUsage;
|
|
1311
1603
|
const resumeFallback = getAnvilEnv("ANVIL_FALLBACK_MODEL", "FORGE_FALLBACK_MODEL");
|
|
1312
1604
|
const router = new ModelRouter({
|
|
1313
|
-
fastModel: getAnvilEnv("ANVIL_MODEL_FAST", "FORGE_MODEL_FAST") ?? baseModel,
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
...(
|
|
1317
|
-
|
|
1605
|
+
fastModel: getAnvilEnv("ANVIL_MODEL_FAST", "FORGE_MODEL_FAST") ?? baseModel,
|
|
1606
|
+
balancedModel: getAnvilEnv("ANVIL_MODEL_BALANCED", "FORGE_MODEL_BALANCED") ?? baseModel,
|
|
1607
|
+
reasoningModel: getAnvilEnv("ANVIL_MODEL_REASONING", "FORGE_MODEL_REASONING") ?? baseModel,
|
|
1608
|
+
...(resumeFallback ? { fallbackModel: resumeFallback } : {}),
|
|
1609
|
+
retryAttempts: Number(getAnvilEnv("ANVIL_MODEL_RETRY_ATTEMPTS", "FORGE_MODEL_RETRY_ATTEMPTS", "2")),
|
|
1610
|
+
retryDelayMs: Number(getAnvilEnv("ANVIL_MODEL_RETRY_DELAY_MS", "FORGE_MODEL_RETRY_DELAY_MS", "500")),
|
|
1611
|
+
...(getAnvilEnv("ANVIL_MAX_INPUT_TOKENS_PER_TASK", "FORGE_MAX_INPUT_TOKENS_PER_TASK")
|
|
1612
|
+
? {
|
|
1613
|
+
maxInputTokensPerTask: Number(getAnvilEnv("ANVIL_MAX_INPUT_TOKENS_PER_TASK", "FORGE_MAX_INPUT_TOKENS_PER_TASK")),
|
|
1614
|
+
}
|
|
1615
|
+
: {}),
|
|
1616
|
+
...(getAnvilEnv("ANVIL_MAX_OUTPUT_TOKENS_PER_TASK", "FORGE_MAX_OUTPUT_TOKENS_PER_TASK")
|
|
1617
|
+
? {
|
|
1618
|
+
maxOutputTokensPerTask: Number(getAnvilEnv("ANVIL_MAX_OUTPUT_TOKENS_PER_TASK", "FORGE_MAX_OUTPUT_TOKENS_PER_TASK")),
|
|
1619
|
+
}
|
|
1620
|
+
: {}),
|
|
1621
|
+
...(getAnvilEnv("ANVIL_MAX_ESTIMATED_TOKENS_PER_RUN", "FORGE_MAX_ESTIMATED_TOKENS_PER_RUN")
|
|
1622
|
+
? {
|
|
1623
|
+
maxEstimatedTokensPerRun: Number(getAnvilEnv("ANVIL_MAX_ESTIMATED_TOKENS_PER_RUN", "FORGE_MAX_ESTIMATED_TOKENS_PER_RUN")),
|
|
1624
|
+
}
|
|
1625
|
+
: {}),
|
|
1626
|
+
...(getAnvilEnv("ANVIL_MAX_ESTIMATED_TOKENS_PER_AGENT", "FORGE_MAX_ESTIMATED_TOKENS_PER_AGENT")
|
|
1627
|
+
? { maxEstimatedTokensPerAgent: readAgentTokenBudgets() }
|
|
1628
|
+
: {}),
|
|
1629
|
+
...(getAnvilEnv("ANVIL_MAX_TASK_DURATION_MS", "FORGE_MAX_TASK_DURATION_MS")
|
|
1630
|
+
? { maxTaskDurationMs: Number(getAnvilEnv("ANVIL_MAX_TASK_DURATION_MS", "FORGE_MAX_TASK_DURATION_MS")) }
|
|
1631
|
+
: {}),
|
|
1632
|
+
...(getAnvilEnv("ANVIL_MAX_TASK_DURATION_MS_BY_AGENT", "FORGE_MAX_TASK_DURATION_MS_BY_AGENT")
|
|
1633
|
+
? { maxTaskDurationMsByAgent: readAgentDurationBudgets() }
|
|
1634
|
+
: {}),
|
|
1635
|
+
initialEstimatedTokensUsed: priorRunUsage,
|
|
1636
|
+
initialEstimatedTokensByAgent: priorAgentUsage,
|
|
1637
|
+
createProvider,
|
|
1318
1638
|
});
|
|
1319
1639
|
const memory = await buildProjectMemoryContext(target, savedRun.goal);
|
|
1320
1640
|
// Re-check current workspace policy before resuming any task that has not completed.
|
|
@@ -1324,10 +1644,12 @@ Exit codes:
|
|
|
1324
1644
|
if (record.status !== "pending" && record.status !== "awaiting_approval")
|
|
1325
1645
|
continue;
|
|
1326
1646
|
const applied = applyBeforeAgentHooks(record.task, resumeHooks);
|
|
1327
|
-
const additions = applied.context.filter(message => !record.task.prompt.includes(message));
|
|
1647
|
+
const additions = applied.context.filter((message) => !record.task.prompt.includes(message));
|
|
1328
1648
|
record.task = {
|
|
1329
1649
|
...applied.task,
|
|
1330
|
-
prompt: additions.length
|
|
1650
|
+
prompt: additions.length
|
|
1651
|
+
? record.task.prompt + "\n\nHook guidance:\n" + additions.join("\n")
|
|
1652
|
+
: record.task.prompt,
|
|
1331
1653
|
};
|
|
1332
1654
|
if (applied.blockedReason) {
|
|
1333
1655
|
record.status = "blocked";
|
|
@@ -1335,7 +1657,17 @@ Exit codes:
|
|
|
1335
1657
|
}
|
|
1336
1658
|
}
|
|
1337
1659
|
const currentTokenUsage = () => {
|
|
1338
|
-
const usage = router.traces.reduce((total, entry) => {
|
|
1660
|
+
const usage = router.traces.reduce((total, entry) => {
|
|
1661
|
+
total.estimatedTokensUsed += entry.inputTokensEstimate + entry.outputTokensEstimate;
|
|
1662
|
+
total.estimatedTokensByAgent[entry.agent] =
|
|
1663
|
+
(total.estimatedTokensByAgent[entry.agent] ?? 0) +
|
|
1664
|
+
entry.inputTokensEstimate +
|
|
1665
|
+
entry.outputTokensEstimate;
|
|
1666
|
+
return total;
|
|
1667
|
+
}, {
|
|
1668
|
+
estimatedTokensUsed: priorRunUsage,
|
|
1669
|
+
estimatedTokensByAgent: { ...priorAgentUsage },
|
|
1670
|
+
});
|
|
1339
1671
|
return usage;
|
|
1340
1672
|
};
|
|
1341
1673
|
let persistedTraceEntries = 0;
|
|
@@ -1347,7 +1679,14 @@ Exit codes:
|
|
|
1347
1679
|
persistedTraceEntries = router.traces.length;
|
|
1348
1680
|
}
|
|
1349
1681
|
};
|
|
1350
|
-
const completed = await advanceRun(savedRun, router, new Set(), {
|
|
1682
|
+
const completed = await advanceRun(savedRun, router, new Set(), {
|
|
1683
|
+
maxConcurrency: 4,
|
|
1684
|
+
projectContext: memory.text,
|
|
1685
|
+
projectContextForTask: (task) => buildAgentWorkspaceContext(target, task),
|
|
1686
|
+
shouldCancel: async () => (await loadRun(target, runId)).status === "cancelled",
|
|
1687
|
+
onTaskSettled: persistRunSnapshot,
|
|
1688
|
+
onUpdate: persistRunSnapshot,
|
|
1689
|
+
});
|
|
1351
1690
|
const saved = await saveRun(target, { ...completed, tokenUsage: currentTokenUsage() });
|
|
1352
1691
|
const tracePath = await saveExecutionTrace(target, completed.id, router.traces.slice(persistedTraceEntries));
|
|
1353
1692
|
process.stdout.write("Resumed " + runId + ": " + completed.status + "\n");
|
|
@@ -1363,7 +1702,7 @@ Exit codes:
|
|
|
1363
1702
|
case "trace": {
|
|
1364
1703
|
const runId = rest[0];
|
|
1365
1704
|
const pathIndex = rest.indexOf("--path");
|
|
1366
|
-
const target = path.resolve(pathIndex >= 0 ? rest[pathIndex + 1] ?? "." : ".");
|
|
1705
|
+
const target = path.resolve(pathIndex >= 0 ? (rest[pathIndex + 1] ?? ".") : ".");
|
|
1367
1706
|
if (!runId) {
|
|
1368
1707
|
process.stderr.write("Usage: anvil trace RUNID [--path PROJECT]\n");
|
|
1369
1708
|
process.exitCode = 1;
|
|
@@ -1373,11 +1712,49 @@ Exit codes:
|
|
|
1373
1712
|
const trace = await loadExecutionTrace(target, runId);
|
|
1374
1713
|
process.stdout.write("FORGE execution trace: " + runId + "\n");
|
|
1375
1714
|
for (const entry of trace.entries)
|
|
1376
|
-
process.stdout.write(" " +
|
|
1377
|
-
|
|
1715
|
+
process.stdout.write(" " +
|
|
1716
|
+
entry.taskId +
|
|
1717
|
+
" [" +
|
|
1718
|
+
entry.tier +
|
|
1719
|
+
"] " +
|
|
1720
|
+
entry.model +
|
|
1721
|
+
" | " +
|
|
1722
|
+
entry.durationMs +
|
|
1723
|
+
" ms | " +
|
|
1724
|
+
entry.outcome +
|
|
1725
|
+
" | ~" +
|
|
1726
|
+
entry.inputTokensEstimate +
|
|
1727
|
+
"/" +
|
|
1728
|
+
entry.outputTokensEstimate +
|
|
1729
|
+
" tokens\n");
|
|
1730
|
+
process.stdout.write("Totals: " +
|
|
1731
|
+
trace.totals.tasks +
|
|
1732
|
+
" tasks, " +
|
|
1733
|
+
trace.totals.estimatedInputTokens +
|
|
1734
|
+
" input tokens, " +
|
|
1735
|
+
trace.totals.estimatedOutputTokens +
|
|
1736
|
+
" output tokens, " +
|
|
1737
|
+
trace.totals.fallbacks +
|
|
1738
|
+
" fallbacks, " +
|
|
1739
|
+
trace.totals.failures +
|
|
1740
|
+
" failures\n");
|
|
1378
1741
|
process.stdout.write("Provider health:\n");
|
|
1379
1742
|
for (const provider of trace.providers ?? [])
|
|
1380
|
-
process.stdout.write(" " +
|
|
1743
|
+
process.stdout.write(" " +
|
|
1744
|
+
provider.name +
|
|
1745
|
+
": " +
|
|
1746
|
+
provider.requests +
|
|
1747
|
+
" requests, " +
|
|
1748
|
+
provider.successes +
|
|
1749
|
+
" successes, " +
|
|
1750
|
+
provider.fallbacks +
|
|
1751
|
+
" fallbacks, " +
|
|
1752
|
+
provider.failures +
|
|
1753
|
+
" failures, " +
|
|
1754
|
+
provider.retries +
|
|
1755
|
+
" retries, " +
|
|
1756
|
+
provider.durationMs +
|
|
1757
|
+
" ms\n");
|
|
1381
1758
|
}
|
|
1382
1759
|
catch (error) {
|
|
1383
1760
|
process.stderr.write("Could not read execution trace: " + (error instanceof Error ? error.message : String(error)) + "\n");
|
|
@@ -1404,29 +1781,34 @@ Exit codes:
|
|
|
1404
1781
|
throw new Error("Usage: anvil runs [path] [--json] [--limit N] [--status STATUS]");
|
|
1405
1782
|
}
|
|
1406
1783
|
for (const option of ["--json", "--limit", "--status"]) {
|
|
1407
|
-
if (rest.filter(arg => arg === option).length > 1) {
|
|
1784
|
+
if (rest.filter((arg) => arg === option).length > 1) {
|
|
1408
1785
|
throw new Error(`${option} may only be specified once.`);
|
|
1409
1786
|
}
|
|
1410
1787
|
}
|
|
1411
1788
|
const allowedOptions = new Set(["--json", "--limit", "--status"]);
|
|
1412
|
-
const unknownOption = rest.find(arg => arg.startsWith("--") && !allowedOptions.has(arg));
|
|
1789
|
+
const unknownOption = rest.find((arg) => arg.startsWith("--") && !allowedOptions.has(arg));
|
|
1413
1790
|
if (unknownOption)
|
|
1414
1791
|
throw new Error(`Unknown option: ${unknownOption}.`);
|
|
1415
1792
|
if (limitIndex >= 0 && (!rawLimit || rawLimit.startsWith("--") || !Number.isSafeInteger(limit) || limit < 1)) {
|
|
1416
1793
|
throw new Error("--limit requires a positive safe integer.");
|
|
1417
1794
|
}
|
|
1418
1795
|
const validStatuses = ["pending", "awaiting_approval", "running", "completed", "failed", "cancelled"];
|
|
1419
|
-
if (statusIndex >= 0 &&
|
|
1796
|
+
if (statusIndex >= 0 &&
|
|
1797
|
+
(!rawStatus ||
|
|
1798
|
+
rawStatus.startsWith("--") ||
|
|
1799
|
+
!validStatuses.includes(rawStatus))) {
|
|
1420
1800
|
throw new Error(`--status requires one of: ${validStatuses.join(", ")}.`);
|
|
1421
1801
|
}
|
|
1422
1802
|
const allRuns = await listRuns(path.resolve(target));
|
|
1423
|
-
const filteredRuns = rawStatus ? allRuns.filter(run => run.status === rawStatus) : allRuns;
|
|
1803
|
+
const filteredRuns = rawStatus ? allRuns.filter((run) => run.status === rawStatus) : allRuns;
|
|
1424
1804
|
const runs = limit === undefined ? filteredRuns : filteredRuns.slice(0, limit);
|
|
1425
1805
|
if (rest.includes("--json")) {
|
|
1426
1806
|
process.stdout.write(formatRunHistoryJson(runs));
|
|
1427
1807
|
}
|
|
1428
1808
|
else {
|
|
1429
|
-
process.stdout.write(runs.length
|
|
1809
|
+
process.stdout.write(runs.length
|
|
1810
|
+
? runs.map((run) => `${run.id} ${run.status.padEnd(18)} ${run.goal}`).join("\n") + "\n"
|
|
1811
|
+
: "No saved FORGE runs.\n");
|
|
1430
1812
|
}
|
|
1431
1813
|
}
|
|
1432
1814
|
catch (error) {
|
|
@@ -1441,7 +1823,7 @@ Exit codes:
|
|
|
1441
1823
|
process.stdout.write("Usage: anvil show-run RUN_ID [--path PROJECT]\nDisplays one validated saved run record.\n");
|
|
1442
1824
|
return;
|
|
1443
1825
|
}
|
|
1444
|
-
const pathIndices = rest.flatMap((arg, index) => arg === "--path" ? [index] : []);
|
|
1826
|
+
const pathIndices = rest.flatMap((arg, index) => (arg === "--path" ? [index] : []));
|
|
1445
1827
|
const pathIndex = pathIndices[0] ?? -1;
|
|
1446
1828
|
const pathValue = pathIndex >= 0 ? rest[pathIndex + 1] : undefined;
|
|
1447
1829
|
const positional = rest.filter((arg, index) => !arg.startsWith("--") && !(pathIndex >= 0 && index === pathIndex + 1));
|
|
@@ -1449,8 +1831,8 @@ Exit codes:
|
|
|
1449
1831
|
try {
|
|
1450
1832
|
if (pathIndices.length > 1)
|
|
1451
1833
|
throw new Error("--path may only be specified once.");
|
|
1452
|
-
if (rest.some(arg => arg.startsWith("--") && arg !== "--path")) {
|
|
1453
|
-
throw new Error(`Unknown option: ${rest.find(arg => arg.startsWith("--") && arg !== "--path")}.`);
|
|
1834
|
+
if (rest.some((arg) => arg.startsWith("--") && arg !== "--path")) {
|
|
1835
|
+
throw new Error(`Unknown option: ${rest.find((arg) => arg.startsWith("--") && arg !== "--path")}.`);
|
|
1454
1836
|
}
|
|
1455
1837
|
if (pathIndex >= 0 && (!pathValue || pathValue.startsWith("--"))) {
|
|
1456
1838
|
throw new Error("--path requires a project directory.");
|
|
@@ -1472,12 +1854,17 @@ Exit codes:
|
|
|
1472
1854
|
const goalIndex = rest.indexOf("--goal");
|
|
1473
1855
|
const pathIndex = rest.indexOf("--path");
|
|
1474
1856
|
const goalEnd = pathIndex >= 0 ? pathIndex : rest.length;
|
|
1475
|
-
const goal = goalIndex >= 0
|
|
1476
|
-
|
|
1857
|
+
const goal = goalIndex >= 0
|
|
1858
|
+
? rest
|
|
1859
|
+
.slice(goalIndex + 1, goalEnd)
|
|
1860
|
+
.join(" ")
|
|
1861
|
+
.trim()
|
|
1862
|
+
: "";
|
|
1863
|
+
const target = path.resolve(pathIndex >= 0 ? (rest[pathIndex + 1] ?? ".") : ".");
|
|
1477
1864
|
try {
|
|
1478
1865
|
const permissions = await loadPermissionPolicy(target);
|
|
1479
1866
|
const model = getAnvilEnv("ANVIL_AI_MODEL", "FORGE_AI_MODEL") ?? getAnvilEnv("ANVIL_MODEL", "FORGE_MODEL");
|
|
1480
|
-
const providerChoice =
|
|
1867
|
+
const providerChoice = getAnvilEnv("ANVIL_AI_PROVIDER", "FORGE_AI_PROVIDER", "openai").toLowerCase();
|
|
1481
1868
|
assertSupportedAgentPolicy(permissions, providerChoice, "ANVIL run");
|
|
1482
1869
|
const baseModel = model ?? (providerChoice === "claude-code" ? "sonnet" : "gpt-4.1-mini");
|
|
1483
1870
|
const apiKey = getAnvilEnv("ANVIL_API_KEY", "FORGE_API_KEY") ?? process.env.OPENAI_API_KEY ?? "";
|
|
@@ -1499,12 +1886,30 @@ Exit codes:
|
|
|
1499
1886
|
retryAttempts: Number(getAnvilEnv("ANVIL_MODEL_RETRY_ATTEMPTS", "FORGE_MODEL_RETRY_ATTEMPTS", "2")),
|
|
1500
1887
|
retryDelayMs: Number(getAnvilEnv("ANVIL_MODEL_RETRY_DELAY_MS", "FORGE_MODEL_RETRY_DELAY_MS", "500")),
|
|
1501
1888
|
createProvider,
|
|
1502
|
-
...(getAnvilEnv("ANVIL_MAX_INPUT_TOKENS_PER_TASK", "FORGE_MAX_INPUT_TOKENS_PER_TASK")
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
...(getAnvilEnv("
|
|
1889
|
+
...(getAnvilEnv("ANVIL_MAX_INPUT_TOKENS_PER_TASK", "FORGE_MAX_INPUT_TOKENS_PER_TASK")
|
|
1890
|
+
? {
|
|
1891
|
+
maxInputTokensPerTask: Number(getAnvilEnv("ANVIL_MAX_INPUT_TOKENS_PER_TASK", "FORGE_MAX_INPUT_TOKENS_PER_TASK")),
|
|
1892
|
+
}
|
|
1893
|
+
: {}),
|
|
1894
|
+
...(getAnvilEnv("ANVIL_MAX_OUTPUT_TOKENS_PER_TASK", "FORGE_MAX_OUTPUT_TOKENS_PER_TASK")
|
|
1895
|
+
? {
|
|
1896
|
+
maxOutputTokensPerTask: Number(getAnvilEnv("ANVIL_MAX_OUTPUT_TOKENS_PER_TASK", "FORGE_MAX_OUTPUT_TOKENS_PER_TASK")),
|
|
1897
|
+
}
|
|
1898
|
+
: {}),
|
|
1899
|
+
...(getAnvilEnv("ANVIL_MAX_ESTIMATED_TOKENS_PER_RUN", "FORGE_MAX_ESTIMATED_TOKENS_PER_RUN")
|
|
1900
|
+
? {
|
|
1901
|
+
maxEstimatedTokensPerRun: Number(getAnvilEnv("ANVIL_MAX_ESTIMATED_TOKENS_PER_RUN", "FORGE_MAX_ESTIMATED_TOKENS_PER_RUN")),
|
|
1902
|
+
}
|
|
1903
|
+
: {}),
|
|
1904
|
+
...(getAnvilEnv("ANVIL_MAX_ESTIMATED_TOKENS_PER_AGENT", "FORGE_MAX_ESTIMATED_TOKENS_PER_AGENT")
|
|
1905
|
+
? { maxEstimatedTokensPerAgent: readAgentTokenBudgets() }
|
|
1906
|
+
: {}),
|
|
1907
|
+
...(getAnvilEnv("ANVIL_MAX_TASK_DURATION_MS", "FORGE_MAX_TASK_DURATION_MS")
|
|
1908
|
+
? { maxTaskDurationMs: Number(getAnvilEnv("ANVIL_MAX_TASK_DURATION_MS", "FORGE_MAX_TASK_DURATION_MS")) }
|
|
1909
|
+
: {}),
|
|
1910
|
+
...(getAnvilEnv("ANVIL_MAX_TASK_DURATION_MS_BY_AGENT", "FORGE_MAX_TASK_DURATION_MS_BY_AGENT")
|
|
1911
|
+
? { maxTaskDurationMsByAgent: readAgentDurationBudgets() }
|
|
1912
|
+
: {}),
|
|
1508
1913
|
});
|
|
1509
1914
|
const provider = router;
|
|
1510
1915
|
const plan = createReviewPlan(goal);
|
|
@@ -1513,7 +1918,12 @@ Exit codes:
|
|
|
1513
1918
|
const hooks = await loadHooks(target);
|
|
1514
1919
|
for (const record of plan.tasks) {
|
|
1515
1920
|
const applied = applyBeforeAgentHooks(record.task, hooks);
|
|
1516
|
-
record.task = {
|
|
1921
|
+
record.task = {
|
|
1922
|
+
...applied.task,
|
|
1923
|
+
prompt: applied.context.length
|
|
1924
|
+
? applied.task.prompt + "\n\nHook guidance:\n" + applied.context.join("\n")
|
|
1925
|
+
: applied.task.prompt,
|
|
1926
|
+
};
|
|
1517
1927
|
if (applied.blockedReason) {
|
|
1518
1928
|
record.status = "blocked";
|
|
1519
1929
|
record.error = "Blocked by policy hook: " + applied.blockedReason;
|
|
@@ -1521,16 +1931,25 @@ Exit codes:
|
|
|
1521
1931
|
}
|
|
1522
1932
|
process.stdout.write("Starting " + plan.id + " with provider " + provider.name + (model ? " (model " + model + ")" : "") + "\n");
|
|
1523
1933
|
if (skills.length)
|
|
1524
|
-
process.stdout.write("Selected skills: " + skills.map(skill => skill.id).join(", ") + "\n");
|
|
1934
|
+
process.stdout.write("Selected skills: " + skills.map((skill) => skill.id).join(", ") + "\n");
|
|
1525
1935
|
if (hooks.length)
|
|
1526
1936
|
process.stdout.write("Loaded policy hooks: " + hooks.length + "\n");
|
|
1527
1937
|
const memory = await buildProjectMemoryContext(target, goal);
|
|
1528
1938
|
const projectContext = [memory.text, skillContext].filter(Boolean).join("\n\n");
|
|
1529
|
-
const completed = await advanceRun(plan, provider, new Set(), {
|
|
1939
|
+
const completed = await advanceRun(plan, provider, new Set(), {
|
|
1940
|
+
maxConcurrency: 4,
|
|
1941
|
+
projectContext,
|
|
1942
|
+
projectContextForTask: (task) => buildAgentWorkspaceContext(target, task),
|
|
1943
|
+
});
|
|
1530
1944
|
const saved = await saveRun(target, completed);
|
|
1531
1945
|
const tracePath = await saveExecutionTrace(target, completed.id, router.traces);
|
|
1532
1946
|
process.stdout.write(`Run status: ${completed.status}\nSaved history: ${path.relative(target, saved)}\nExecution trace: ${path.relative(target, tracePath)}\n`);
|
|
1533
|
-
const totals = router.traces.reduce((sum, trace) => ({
|
|
1947
|
+
const totals = router.traces.reduce((sum, trace) => ({
|
|
1948
|
+
input: sum.input + trace.inputTokensEstimate,
|
|
1949
|
+
output: sum.output + trace.outputTokensEstimate,
|
|
1950
|
+
duration: sum.duration + trace.durationMs,
|
|
1951
|
+
fallback: sum.fallback + (trace.outcome === "fallback" ? 1 : 0),
|
|
1952
|
+
}), { input: 0, output: 0, duration: 0, fallback: 0 });
|
|
1534
1953
|
process.stdout.write(`Estimated tokens: ${totals.input} in / ${totals.output} out | Agent time: ${totals.duration} ms | Fallbacks: ${totals.fallback}\n`);
|
|
1535
1954
|
for (const task of completed.tasks)
|
|
1536
1955
|
process.stdout.write(` ${task.status.padEnd(18)} ${task.task.agent}: ${task.task.title}\n`);
|
|
@@ -1549,11 +1968,17 @@ Exit codes:
|
|
|
1549
1968
|
process.stdout.write("Usage: anvil deps [path] [--audit-report FILE] [--outdated-report FILE] [--json]\n");
|
|
1550
1969
|
return;
|
|
1551
1970
|
}
|
|
1552
|
-
const option = (name) => {
|
|
1971
|
+
const option = (name) => {
|
|
1972
|
+
const index = rest.indexOf(name);
|
|
1973
|
+
return index >= 0 ? rest[index + 1] : undefined;
|
|
1974
|
+
};
|
|
1553
1975
|
const target = path.resolve(rest.find((arg, index) => !arg.startsWith("--") && rest[index - 1] !== "--audit-report" && rest[index - 1] !== "--outdated-report") ?? ".");
|
|
1554
1976
|
try {
|
|
1555
1977
|
const auditReport = option("--audit-report"), outdatedReport = option("--outdated-report");
|
|
1556
|
-
const report = await analyzeDependencies(target, {
|
|
1978
|
+
const report = await analyzeDependencies(target, {
|
|
1979
|
+
...(auditReport ? { auditReport } : {}),
|
|
1980
|
+
...(outdatedReport ? { outdatedReport } : {}),
|
|
1981
|
+
});
|
|
1557
1982
|
process.stdout.write(rest.includes("--json") ? JSON.stringify(report, null, 2) + "\n" : formatDependencyIntelligence(report) + "\n");
|
|
1558
1983
|
}
|
|
1559
1984
|
catch (error) {
|
|
@@ -1563,7 +1988,7 @@ Exit codes:
|
|
|
1563
1988
|
return;
|
|
1564
1989
|
}
|
|
1565
1990
|
case "snapshot": {
|
|
1566
|
-
const target = path.resolve(rest.find(arg => !arg.startsWith("--")) ?? ".");
|
|
1991
|
+
const target = path.resolve(rest.find((arg) => !arg.startsWith("--")) ?? ".");
|
|
1567
1992
|
try {
|
|
1568
1993
|
const comparison = await captureIntelligenceSnapshot(target);
|
|
1569
1994
|
process.stdout.write(formatIntelligenceComparison(comparison) + "\n");
|
|
@@ -1575,10 +2000,12 @@ Exit codes:
|
|
|
1575
2000
|
return;
|
|
1576
2001
|
}
|
|
1577
2002
|
case "timeline": {
|
|
1578
|
-
const target = path.resolve(rest.find(arg => !arg.startsWith("--")) ?? ".");
|
|
2003
|
+
const target = path.resolve(rest.find((arg) => !arg.startsWith("--")) ?? ".");
|
|
1579
2004
|
try {
|
|
1580
2005
|
const comparison = await compareLatestIntelligence(target);
|
|
1581
|
-
process.stdout.write(comparison
|
|
2006
|
+
process.stdout.write(comparison
|
|
2007
|
+
? formatIntelligenceComparison(comparison) + "\n"
|
|
2008
|
+
: "No engineering snapshots found. Run forge snapshot . first.\n");
|
|
1582
2009
|
}
|
|
1583
2010
|
catch (error) {
|
|
1584
2011
|
process.stderr.write("FORGE timeline failed: " + (error instanceof Error ? error.message : String(error)) + "\n");
|
|
@@ -1588,8 +2015,10 @@ Exit codes:
|
|
|
1588
2015
|
}
|
|
1589
2016
|
case "change-risk": {
|
|
1590
2017
|
const pathIndex = rest.indexOf("--path"), baseIndex = rest.indexOf("--base");
|
|
1591
|
-
const target = path.resolve(pathIndex >= 0
|
|
1592
|
-
|
|
2018
|
+
const target = path.resolve(pathIndex >= 0
|
|
2019
|
+
? (rest[pathIndex + 1] ?? ".")
|
|
2020
|
+
: (rest.find((arg, index) => !arg.startsWith("--") && rest[index - 1] !== "--base") ?? "."));
|
|
2021
|
+
const base = baseIndex >= 0 ? (rest[baseIndex + 1] ?? "HEAD") : "HEAD";
|
|
1593
2022
|
const json = rest.includes("--json");
|
|
1594
2023
|
try {
|
|
1595
2024
|
const report = await analyzeChangeIntelligence(target, base);
|
|
@@ -1603,7 +2032,7 @@ Exit codes:
|
|
|
1603
2032
|
}
|
|
1604
2033
|
case "risk": {
|
|
1605
2034
|
const pathIndex = rest.indexOf("--path");
|
|
1606
|
-
const target = path.resolve(pathIndex >= 0 ? rest[pathIndex + 1] ?? "." : rest.find(arg => !arg.startsWith("--")) ?? ".");
|
|
2035
|
+
const target = path.resolve(pathIndex >= 0 ? (rest[pathIndex + 1] ?? ".") : (rest.find((arg) => !arg.startsWith("--")) ?? "."));
|
|
1607
2036
|
const json = rest.includes("--json");
|
|
1608
2037
|
try {
|
|
1609
2038
|
const report = await analyzeEngineeringRisk(target);
|
|
@@ -1617,8 +2046,10 @@ Exit codes:
|
|
|
1617
2046
|
}
|
|
1618
2047
|
case "impact": {
|
|
1619
2048
|
const pathIndex = rest.indexOf("--path"), baseIndex = rest.indexOf("--base");
|
|
1620
|
-
const target = path.resolve(pathIndex >= 0
|
|
1621
|
-
|
|
2049
|
+
const target = path.resolve(pathIndex >= 0
|
|
2050
|
+
? (rest[pathIndex + 1] ?? ".")
|
|
2051
|
+
: (rest.find((arg, index) => !arg.startsWith("--") && rest[index - 1] !== "--base") ?? "."));
|
|
2052
|
+
const base = baseIndex >= 0 ? (rest[baseIndex + 1] ?? "HEAD") : "HEAD";
|
|
1622
2053
|
const json = rest.includes("--json");
|
|
1623
2054
|
try {
|
|
1624
2055
|
const report = await analyzeDependencyImpact(target, base);
|
|
@@ -1637,8 +2068,11 @@ Exit codes:
|
|
|
1637
2068
|
optionValues.add(pathIndex + 1);
|
|
1638
2069
|
if (limitIndex >= 0)
|
|
1639
2070
|
optionValues.add(limitIndex + 1);
|
|
1640
|
-
const target = path.resolve(pathIndex >= 0 ? rest[pathIndex + 1] ?? "." : ".");
|
|
1641
|
-
const query = rest
|
|
2071
|
+
const target = path.resolve(pathIndex >= 0 ? (rest[pathIndex + 1] ?? ".") : ".");
|
|
2072
|
+
const query = rest
|
|
2073
|
+
.filter((arg, index) => !arg.startsWith("--") && !optionValues.has(index))
|
|
2074
|
+
.join(" ")
|
|
2075
|
+
.trim();
|
|
1642
2076
|
const limit = limitIndex >= 0 ? Number(rest[limitIndex + 1]) : 80;
|
|
1643
2077
|
try {
|
|
1644
2078
|
const report = await searchWorkspace(target, query, limit);
|
|
@@ -1651,7 +2085,7 @@ Exit codes:
|
|
|
1651
2085
|
return;
|
|
1652
2086
|
}
|
|
1653
2087
|
case "dashboard": {
|
|
1654
|
-
const target = path.resolve(rest.find(arg => !arg.startsWith("--")) ?? ".");
|
|
2088
|
+
const target = path.resolve(rest.find((arg) => !arg.startsWith("--")) ?? ".");
|
|
1655
2089
|
const portIndex = rest.indexOf("--port");
|
|
1656
2090
|
const portValue = portIndex >= 0 ? Number(rest[portIndex + 1]) : 4173;
|
|
1657
2091
|
if (!Number.isInteger(portValue) || portValue < 0 || portValue > 65535) {
|
|
@@ -1670,7 +2104,11 @@ Exit codes:
|
|
|
1670
2104
|
break;
|
|
1671
2105
|
}
|
|
1672
2106
|
catch (err) {
|
|
1673
|
-
if (err &&
|
|
2107
|
+
if (err &&
|
|
2108
|
+
typeof err === "object" &&
|
|
2109
|
+
"code" in err &&
|
|
2110
|
+
err.code === "EADDRINUSE" &&
|
|
2111
|
+
p < portValue + 9)
|
|
1674
2112
|
continue;
|
|
1675
2113
|
throw err;
|
|
1676
2114
|
}
|
|
@@ -1698,12 +2136,14 @@ Exit codes:
|
|
|
1698
2136
|
case "verify": {
|
|
1699
2137
|
const listOnly = rest.includes("--list");
|
|
1700
2138
|
const pathIndex = rest.indexOf("--path");
|
|
1701
|
-
const target = path.resolve(pathIndex >= 0 ? rest[pathIndex + 1] ?? "." : ".");
|
|
1702
|
-
const script = rest.find(arg => !arg.startsWith("--"));
|
|
2139
|
+
const target = path.resolve(pathIndex >= 0 ? (rest[pathIndex + 1] ?? ".") : ".");
|
|
2140
|
+
const script = rest.find((arg) => !arg.startsWith("--"));
|
|
1703
2141
|
try {
|
|
1704
2142
|
if (listOnly) {
|
|
1705
2143
|
const checks = await discoverChecks(target);
|
|
1706
|
-
process.stdout.write(checks.length
|
|
2144
|
+
process.stdout.write(checks.length
|
|
2145
|
+
? checks.map((check) => `${check.name.padEnd(20)} ${check.command}`).join("\n") + "\n"
|
|
2146
|
+
: "No selectable npm scripts found.\n");
|
|
1707
2147
|
return;
|
|
1708
2148
|
}
|
|
1709
2149
|
if (!script)
|
|
@@ -1730,12 +2170,22 @@ Exit codes:
|
|
|
1730
2170
|
for (const profile of profiles) {
|
|
1731
2171
|
process.stdout.write([
|
|
1732
2172
|
profile.name + " — " + profile.description,
|
|
1733
|
-
" network=" +
|
|
1734
|
-
|
|
1735
|
-
",
|
|
1736
|
-
|
|
1737
|
-
",
|
|
1738
|
-
|
|
2173
|
+
" network=" +
|
|
2174
|
+
profile.network +
|
|
2175
|
+
", readOnlyRoot=" +
|
|
2176
|
+
profile.readOnlyRoot +
|
|
2177
|
+
", dropAllCapabilities=" +
|
|
2178
|
+
profile.dropAllCapabilities +
|
|
2179
|
+
", noNewPrivileges=" +
|
|
2180
|
+
profile.noNewPrivileges,
|
|
2181
|
+
" memory=" +
|
|
2182
|
+
profile.maxMemory +
|
|
2183
|
+
", cpus=" +
|
|
2184
|
+
profile.maxCpus +
|
|
2185
|
+
", processes=" +
|
|
2186
|
+
profile.maxProcesses +
|
|
2187
|
+
", requireRootless=" +
|
|
2188
|
+
profile.requireRootless,
|
|
1739
2189
|
"",
|
|
1740
2190
|
].join("\n"));
|
|
1741
2191
|
}
|
|
@@ -1759,13 +2209,17 @@ Exit codes:
|
|
|
1759
2209
|
}
|
|
1760
2210
|
case "sandbox-cleanup": {
|
|
1761
2211
|
const apply = rest.includes("--apply");
|
|
1762
|
-
const unknown = rest.filter(arg => arg !== "--apply");
|
|
2212
|
+
const unknown = rest.filter((arg) => arg !== "--apply");
|
|
1763
2213
|
try {
|
|
1764
2214
|
if (unknown.length)
|
|
1765
2215
|
throw new Error("Usage: anvil sandbox-cleanup [--apply]. Cleanup is dry-run unless --apply is explicit.");
|
|
1766
2216
|
const output = await runSandboxProbe([
|
|
1767
|
-
"ps",
|
|
1768
|
-
"
|
|
2217
|
+
"ps",
|
|
2218
|
+
"-a",
|
|
2219
|
+
"--filter",
|
|
2220
|
+
"label=com.forge.managed=true",
|
|
2221
|
+
"--format",
|
|
2222
|
+
"{{.ID}}\\t{{.Status}}\\t{{.Names}}",
|
|
1769
2223
|
]);
|
|
1770
2224
|
const managed = parseManagedContainers(output);
|
|
1771
2225
|
const candidates = selectStoppedManagedContainers(managed);
|
|
@@ -1858,7 +2312,7 @@ Exit codes:
|
|
|
1858
2312
|
}
|
|
1859
2313
|
case "patch-verify": {
|
|
1860
2314
|
const pathIndex = rest.indexOf("--path");
|
|
1861
|
-
const target = path.resolve(pathIndex >= 0 ? rest[pathIndex + 1] ?? "." : ".");
|
|
2315
|
+
const target = path.resolve(pathIndex >= 0 ? (rest[pathIndex + 1] ?? ".") : ".");
|
|
1862
2316
|
const installDependencies = rest.includes("--install-dependencies");
|
|
1863
2317
|
const sandboxImageIndex = rest.indexOf("--sandbox-image");
|
|
1864
2318
|
const sandboxImage = sandboxImageIndex >= 0 ? rest[sandboxImageIndex + 1] : undefined;
|
|
@@ -1867,8 +2321,17 @@ Exit codes:
|
|
|
1867
2321
|
const securityProfile = profileIndex >= 0 ? rest[profileIndex + 1] : undefined;
|
|
1868
2322
|
const policyIndex = rest.indexOf("--policy");
|
|
1869
2323
|
const sandboxPolicyPath = policyIndex >= 0 ? rest[policyIndex + 1] : undefined;
|
|
1870
|
-
const argsWithoutPath = rest.filter((arg, index) => arg !== "--path" &&
|
|
1871
|
-
|
|
2324
|
+
const argsWithoutPath = rest.filter((arg, index) => arg !== "--path" &&
|
|
2325
|
+
!(pathIndex >= 0 && index === pathIndex + 1) &&
|
|
2326
|
+
arg !== "--install-dependencies" &&
|
|
2327
|
+
arg !== "--sandbox-image" &&
|
|
2328
|
+
!(sandboxImageIndex >= 0 && index === sandboxImageIndex + 1) &&
|
|
2329
|
+
arg !== "--require-rootless" &&
|
|
2330
|
+
arg !== "--profile" &&
|
|
2331
|
+
!(profileIndex >= 0 && index === profileIndex + 1) &&
|
|
2332
|
+
arg !== "--policy" &&
|
|
2333
|
+
!(policyIndex >= 0 && index === policyIndex + 1));
|
|
2334
|
+
const stageId = argsWithoutPath.find((arg) => !arg.startsWith("--"));
|
|
1872
2335
|
const script = argsWithoutPath.find((arg, index) => !arg.startsWith("--") && index > 0);
|
|
1873
2336
|
try {
|
|
1874
2337
|
if (!stageId || !script)
|
|
@@ -1891,21 +2354,51 @@ Exit codes:
|
|
|
1891
2354
|
installDependencies,
|
|
1892
2355
|
...(sandboxImage ? { sandboxImage } : {}),
|
|
1893
2356
|
...(requireRootless ? { requireRootless } : {}),
|
|
1894
|
-
...(securityProfile
|
|
2357
|
+
...(securityProfile
|
|
2358
|
+
? { securityProfile: securityProfile }
|
|
2359
|
+
: {}),
|
|
1895
2360
|
...(sandboxPolicyPath ? { sandboxPolicyPath } : {}),
|
|
1896
2361
|
});
|
|
1897
2362
|
process.stdout.write("# ANVIL Staged Patch Verification\n\n" +
|
|
1898
|
-
"- **Stage:** `" +
|
|
1899
|
-
|
|
1900
|
-
"
|
|
1901
|
-
"- **
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
"
|
|
1907
|
-
"
|
|
1908
|
-
|
|
2363
|
+
"- **Stage:** `" +
|
|
2364
|
+
result.stageId +
|
|
2365
|
+
"`\n" +
|
|
2366
|
+
"- **Patch file:** `" +
|
|
2367
|
+
result.file +
|
|
2368
|
+
"`\n" +
|
|
2369
|
+
"- **Staged SHA-256:** `" +
|
|
2370
|
+
result.stagedSha256 +
|
|
2371
|
+
"`\n" +
|
|
2372
|
+
"- **Snapshot files:** `" +
|
|
2373
|
+
result.snapshotFileCount +
|
|
2374
|
+
"`\n" +
|
|
2375
|
+
"- **Snapshot bytes:** `" +
|
|
2376
|
+
result.snapshotBytes +
|
|
2377
|
+
"`\n" +
|
|
2378
|
+
(result.dependencyInstall
|
|
2379
|
+
? "- **Dependencies:** **" +
|
|
2380
|
+
result.dependencyInstall.status.toUpperCase() +
|
|
2381
|
+
"** (`" +
|
|
2382
|
+
result.dependencyInstall.command +
|
|
2383
|
+
"`)\n"
|
|
2384
|
+
: "") +
|
|
2385
|
+
(sandboxImage
|
|
2386
|
+
? "- **Execution:** **CONTAINER** (`" + sandboxImage + "`)\n"
|
|
2387
|
+
: "- **Execution:** **LOCAL HOST**\n") +
|
|
2388
|
+
"- **Verification:** **" +
|
|
2389
|
+
result.verification.status.toUpperCase() +
|
|
2390
|
+
"**\n" +
|
|
2391
|
+
"- **Duration:** `" +
|
|
2392
|
+
result.verification.durationMs +
|
|
2393
|
+
" ms`\n\n" +
|
|
2394
|
+
"## Output\n\n```\n" +
|
|
2395
|
+
(result.verification.output || "(No output captured.)") +
|
|
2396
|
+
"\n```\n\n" +
|
|
2397
|
+
"Temporary workspace was removed after verification. " +
|
|
2398
|
+
(sandboxImage
|
|
2399
|
+
? "The container runtime and host kernel remain trusted."
|
|
2400
|
+
: "Project scripts ran on the local host; this is not an OS-level sandbox.") +
|
|
2401
|
+
"\n");
|
|
1909
2402
|
if (result.verification.status !== "passed")
|
|
1910
2403
|
process.exitCode = 1;
|
|
1911
2404
|
}
|
|
@@ -1918,14 +2411,16 @@ Exit codes:
|
|
|
1918
2411
|
}
|
|
1919
2412
|
case "verify-history": {
|
|
1920
2413
|
const targetIndex = rest.indexOf("--path");
|
|
1921
|
-
const target = path.resolve(targetIndex >= 0 ? rest[targetIndex + 1] ?? "." : ".");
|
|
2414
|
+
const target = path.resolve(targetIndex >= 0 ? (rest[targetIndex + 1] ?? ".") : ".");
|
|
1922
2415
|
try {
|
|
1923
2416
|
const history = await listVerifications(target);
|
|
1924
2417
|
if (!history.length) {
|
|
1925
2418
|
process.stdout.write("No saved verification runs.\n");
|
|
1926
2419
|
return;
|
|
1927
2420
|
}
|
|
1928
|
-
process.stdout.write(history
|
|
2421
|
+
process.stdout.write(history
|
|
2422
|
+
.map((item) => `${item.startedAt} ${item.status.padEnd(12)} ${item.script.padEnd(16)} ${item.durationMs} ms ${item.id}`)
|
|
2423
|
+
.join("\n") + "\n");
|
|
1929
2424
|
}
|
|
1930
2425
|
catch (error) {
|
|
1931
2426
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -1939,8 +2434,10 @@ Exit codes:
|
|
|
1939
2434
|
const all = rest.includes("--all");
|
|
1940
2435
|
const pathIndex = rest.indexOf("--path");
|
|
1941
2436
|
const baseIndex = rest.indexOf("--base");
|
|
1942
|
-
const target = path.resolve(pathIndex >= 0
|
|
1943
|
-
|
|
2437
|
+
const target = path.resolve(pathIndex >= 0
|
|
2438
|
+
? (rest[pathIndex + 1] ?? ".")
|
|
2439
|
+
: (rest.find((arg, index) => !arg.startsWith("--") && rest[index - 1] !== "--base" && rest[index - 1] !== "--path") ?? "."));
|
|
2440
|
+
const base = baseIndex >= 0 ? (rest[baseIndex + 1] ?? "HEAD") : "HEAD";
|
|
1944
2441
|
try {
|
|
1945
2442
|
const report = await reviewProject(target, { base, all });
|
|
1946
2443
|
let ai;
|
|
@@ -1948,11 +2445,21 @@ Exit codes:
|
|
|
1948
2445
|
const apiKey = getAnvilEnv("ANVIL_API_KEY", "FORGE_API_KEY") ?? process.env.OPENAI_API_KEY ?? "";
|
|
1949
2446
|
if (!apiKey)
|
|
1950
2447
|
throw new Error("Set ANVIL_API_KEY, FORGE_API_KEY, or OPENAI_API_KEY before using --ai.");
|
|
1951
|
-
const provider = new OpenAICompatibleProvider({
|
|
2448
|
+
const provider = new OpenAICompatibleProvider({
|
|
2449
|
+
apiKey,
|
|
2450
|
+
model: getAnvilEnv("ANVIL_MODEL", "FORGE_MODEL", "gpt-4.1-mini"),
|
|
2451
|
+
baseUrl: getAnvilEnv("ANVIL_BASE_URL", "FORGE_BASE_URL", "https://api.openai.com/v1"),
|
|
2452
|
+
});
|
|
1952
2453
|
ai = await generateAIReview(report, provider);
|
|
1953
2454
|
}
|
|
1954
2455
|
const saved = await saveReview(target, report, ai);
|
|
1955
|
-
process.stdout.write(json
|
|
2456
|
+
process.stdout.write(json
|
|
2457
|
+
? JSON.stringify({ ...saved, reviewId: saved.id }, null, 2) + "\n"
|
|
2458
|
+
: formatCodeReview(report) +
|
|
2459
|
+
(ai ? "\n\n" + formatAIReview(ai) : "") +
|
|
2460
|
+
"\n\nSaved review: " +
|
|
2461
|
+
saved.id +
|
|
2462
|
+
"\n");
|
|
1956
2463
|
}
|
|
1957
2464
|
catch (error) {
|
|
1958
2465
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -1965,7 +2472,11 @@ Exit codes:
|
|
|
1965
2472
|
const target = path.resolve(rest.find((arg, index) => !arg.startsWith("--") && rest[index - 1] !== "--path") ?? ".");
|
|
1966
2473
|
try {
|
|
1967
2474
|
const records = await listReviews(target);
|
|
1968
|
-
process.stdout.write(records.length
|
|
2475
|
+
process.stdout.write(records.length
|
|
2476
|
+
? records
|
|
2477
|
+
.map((r) => r.id + " " + r.createdAt + " " + r.report.findings.length + " static findings")
|
|
2478
|
+
.join("\n") + "\n"
|
|
2479
|
+
: "No saved reviews found.\n");
|
|
1969
2480
|
}
|
|
1970
2481
|
catch (error) {
|
|
1971
2482
|
process.stderr.write("ANVIL review history failed: " + (error instanceof Error ? error.message : String(error)) + "\n");
|
|
@@ -1974,9 +2485,9 @@ Exit codes:
|
|
|
1974
2485
|
return;
|
|
1975
2486
|
}
|
|
1976
2487
|
case "review-show": {
|
|
1977
|
-
const id = rest.find(arg => !arg.startsWith("--")) ?? "";
|
|
2488
|
+
const id = rest.find((arg) => !arg.startsWith("--")) ?? "";
|
|
1978
2489
|
const pathIndex = rest.indexOf("--path");
|
|
1979
|
-
const target = path.resolve(pathIndex >= 0 ? rest[pathIndex + 1] ?? "." : ".");
|
|
2490
|
+
const target = path.resolve(pathIndex >= 0 ? (rest[pathIndex + 1] ?? ".") : ".");
|
|
1980
2491
|
try {
|
|
1981
2492
|
const record = await loadReview(target, id);
|
|
1982
2493
|
process.stdout.write(formatReviewRecord(record) + "\n");
|
|
@@ -1990,13 +2501,21 @@ Exit codes:
|
|
|
1990
2501
|
case "review-compare": {
|
|
1991
2502
|
const ids = rest.filter((arg, index) => !arg.startsWith("--") && rest[index - 1] !== "--path");
|
|
1992
2503
|
const pathIndex = rest.indexOf("--path");
|
|
1993
|
-
const target = path.resolve(pathIndex >= 0 ? rest[pathIndex + 1] ?? "." : ".");
|
|
2504
|
+
const target = path.resolve(pathIndex >= 0 ? (rest[pathIndex + 1] ?? ".") : ".");
|
|
1994
2505
|
try {
|
|
1995
2506
|
if (ids.length < 2)
|
|
1996
2507
|
throw new Error("Usage: anvil review-compare REVIEW_ID_A REVIEW_ID_B --path PROJECT");
|
|
1997
2508
|
const [a, b] = await Promise.all([loadReview(target, ids[0]), loadReview(target, ids[1])]);
|
|
1998
2509
|
const diff = compareReviews(a, b);
|
|
1999
|
-
process.stdout.write([
|
|
2510
|
+
process.stdout.write([
|
|
2511
|
+
"Review comparison",
|
|
2512
|
+
"Added (" + diff.added.length + ")",
|
|
2513
|
+
...diff.added.map((x) => "+ " + x),
|
|
2514
|
+
"Resolved (" + diff.resolved.length + ")",
|
|
2515
|
+
...diff.resolved.map((x) => "- " + x),
|
|
2516
|
+
"Persistent (" + diff.persistent.length + ")",
|
|
2517
|
+
...diff.persistent.map((x) => "= " + x),
|
|
2518
|
+
].join("\n") + "\n");
|
|
2000
2519
|
}
|
|
2001
2520
|
catch (error) {
|
|
2002
2521
|
process.stderr.write("ANVIL review comparison failed: " + (error instanceof Error ? error.message : String(error)) + "\n");
|
|
@@ -2007,8 +2526,10 @@ Exit codes:
|
|
|
2007
2526
|
case "regression": {
|
|
2008
2527
|
const pathIndex = rest.indexOf("--path");
|
|
2009
2528
|
const baseIndex = rest.indexOf("--base");
|
|
2010
|
-
const target = path.resolve(pathIndex >= 0
|
|
2011
|
-
|
|
2529
|
+
const target = path.resolve(pathIndex >= 0
|
|
2530
|
+
? (rest[pathIndex + 1] ?? ".")
|
|
2531
|
+
: (rest.find((arg, index) => !arg.startsWith("--") && rest[index - 1] !== "--base") ?? "."));
|
|
2532
|
+
const base = baseIndex >= 0 ? (rest[baseIndex + 1] ?? "HEAD") : "HEAD";
|
|
2012
2533
|
const json = rest.includes("--json");
|
|
2013
2534
|
try {
|
|
2014
2535
|
const report = await generateRegressionReport(target, base);
|
|
@@ -2024,13 +2545,22 @@ Exit codes:
|
|
|
2024
2545
|
}
|
|
2025
2546
|
case "patch-review": {
|
|
2026
2547
|
const pathIndex = rest.indexOf("--path");
|
|
2027
|
-
const target = path.resolve(pathIndex >= 0 ? rest[pathIndex + 1] ?? "." : ".");
|
|
2548
|
+
const target = path.resolve(pathIndex >= 0 ? (rest[pathIndex + 1] ?? ".") : ".");
|
|
2028
2549
|
const stageId = rest.find((arg, index) => !arg.startsWith("--") && rest[index - 1] !== "--path") ?? "";
|
|
2029
2550
|
try {
|
|
2030
2551
|
if (!stageId)
|
|
2031
2552
|
throw new Error("Usage: anvil patch-review STAGE_ID --path PROJECT");
|
|
2032
2553
|
const review = await reviewStagedPatch(target, stageId);
|
|
2033
|
-
process.stdout.write([
|
|
2554
|
+
process.stdout.write([
|
|
2555
|
+
"# ANVIL Staged Patch Review",
|
|
2556
|
+
"- Stage: " + review.stageId,
|
|
2557
|
+
"- File: " + review.file,
|
|
2558
|
+
"- Source SHA-256: " + review.sourceSha256,
|
|
2559
|
+
"- Staged SHA-256: " + review.stagedSha256,
|
|
2560
|
+
"- Source unchanged: " + review.unchanged,
|
|
2561
|
+
"",
|
|
2562
|
+
review.diff,
|
|
2563
|
+
].join("\n") + "\n");
|
|
2034
2564
|
}
|
|
2035
2565
|
catch (error) {
|
|
2036
2566
|
process.stderr.write("ANVIL staged patch review failed: " + (error instanceof Error ? error.message : String(error)) + "\n");
|
|
@@ -2040,13 +2570,23 @@ Exit codes:
|
|
|
2040
2570
|
}
|
|
2041
2571
|
case "patch-stage": {
|
|
2042
2572
|
const pathIndex = rest.indexOf("--path");
|
|
2043
|
-
const target = path.resolve(pathIndex >= 0 ? rest[pathIndex + 1] ?? "." : ".");
|
|
2573
|
+
const target = path.resolve(pathIndex >= 0 ? (rest[pathIndex + 1] ?? ".") : ".");
|
|
2044
2574
|
const approvalId = rest.find((arg, index) => !arg.startsWith("--") && rest[index - 1] !== "--path") ?? "";
|
|
2045
2575
|
try {
|
|
2046
2576
|
if (!approvalId)
|
|
2047
2577
|
throw new Error("Usage: anvil patch-stage APPROVAL_ID --path PROJECT");
|
|
2048
2578
|
const staged = await stageApprovedPatch(target, approvalId);
|
|
2049
|
-
process.stdout.write([
|
|
2579
|
+
process.stdout.write([
|
|
2580
|
+
"# ANVIL Isolated Patch Stage",
|
|
2581
|
+
"- Stage: " + staged.id,
|
|
2582
|
+
"- Approval: " + staged.approvalId,
|
|
2583
|
+
"- File: " + staged.file,
|
|
2584
|
+
"- Staged copy: " + staged.stagedFile,
|
|
2585
|
+
"- SHA-256: " + staged.stagedSha256,
|
|
2586
|
+
"",
|
|
2587
|
+
"The original project file was not modified.",
|
|
2588
|
+
"No tests or commands were executed.",
|
|
2589
|
+
].join("\n") + "\n");
|
|
2050
2590
|
}
|
|
2051
2591
|
catch (error) {
|
|
2052
2592
|
process.stderr.write("ANVIL patch staging failed: " + (error instanceof Error ? error.message : String(error)) + "\n");
|
|
@@ -2058,18 +2598,31 @@ Exit codes:
|
|
|
2058
2598
|
const pathIndex = rest.indexOf("--path");
|
|
2059
2599
|
const reviewerIndex = rest.indexOf("--reviewer");
|
|
2060
2600
|
const reasonIndex = rest.indexOf("--reason");
|
|
2061
|
-
const target = path.resolve(pathIndex >= 0 ? rest[pathIndex + 1] ?? "." : ".");
|
|
2601
|
+
const target = path.resolve(pathIndex >= 0 ? (rest[pathIndex + 1] ?? ".") : ".");
|
|
2062
2602
|
const values = rest.filter((arg, index) => !arg.startsWith("--") && index !== pathIndex + 1 && index !== reviewerIndex + 1 && index !== reasonIndex + 1);
|
|
2063
2603
|
const reviewId = values[0] ?? "";
|
|
2064
2604
|
const suggestionNumber = Number(values[1]);
|
|
2065
|
-
const reviewer = reviewerIndex >= 0 ? rest[reviewerIndex + 1] ?? "" : "";
|
|
2605
|
+
const reviewer = reviewerIndex >= 0 ? (rest[reviewerIndex + 1] ?? "") : "";
|
|
2066
2606
|
const reason = reasonIndex >= 0 ? rest[reasonIndex + 1] : undefined;
|
|
2067
2607
|
try {
|
|
2068
2608
|
if (!reviewId || !Number.isInteger(suggestionNumber) || suggestionNumber < 1 || !reviewer.trim()) {
|
|
2069
2609
|
throw new Error("Usage: anvil patch-approve REVIEW_ID SUGGESTION_NUMBER --reviewer NAME [--reason TEXT] --path PROJECT");
|
|
2070
2610
|
}
|
|
2071
2611
|
const approval = await approveReviewPatch(target, reviewId, suggestionNumber, reviewer, reason);
|
|
2072
|
-
process.stdout.write([
|
|
2612
|
+
process.stdout.write([
|
|
2613
|
+
"# ANVIL Patch Approval",
|
|
2614
|
+
"- Approval ID: " + approval.id,
|
|
2615
|
+
"- Review: " + approval.reviewId,
|
|
2616
|
+
"- Suggestion: " + approval.suggestionNumber,
|
|
2617
|
+
"- File: " + approval.file,
|
|
2618
|
+
"- Reviewer: " + approval.reviewer,
|
|
2619
|
+
"- Approved: " + approval.approvedAt,
|
|
2620
|
+
"- Expires: " + approval.expiresAt,
|
|
2621
|
+
"- Patch SHA-256: " + approval.patchSha256,
|
|
2622
|
+
"- Source SHA-256: " + approval.sourceSha256,
|
|
2623
|
+
"",
|
|
2624
|
+
"No source files were modified.",
|
|
2625
|
+
].join("\n") + "\n");
|
|
2073
2626
|
}
|
|
2074
2627
|
catch (error) {
|
|
2075
2628
|
process.stderr.write("ANVIL patch approval failed: " + (error instanceof Error ? error.message : String(error)) + "\n");
|
|
@@ -2080,7 +2633,7 @@ Exit codes:
|
|
|
2080
2633
|
case "patch-approval-check": {
|
|
2081
2634
|
const id = rest.find((arg, index) => !arg.startsWith("--") && rest[index - 1] !== "--path") ?? "";
|
|
2082
2635
|
const pathIndex = rest.indexOf("--path");
|
|
2083
|
-
const target = path.resolve(pathIndex >= 0 ? rest[pathIndex + 1] ?? "." : ".");
|
|
2636
|
+
const target = path.resolve(pathIndex >= 0 ? (rest[pathIndex + 1] ?? ".") : ".");
|
|
2084
2637
|
try {
|
|
2085
2638
|
if (!id)
|
|
2086
2639
|
throw new Error("Usage: anvil patch-approval-check APPROVAL_ID --path PROJECT");
|
|
@@ -2098,7 +2651,7 @@ Exit codes:
|
|
|
2098
2651
|
case "patch-check": {
|
|
2099
2652
|
const id = rest.find((arg, index) => !arg.startsWith("--") && rest[index - 1] !== "--path") ?? "";
|
|
2100
2653
|
const pathIndex = rest.indexOf("--path");
|
|
2101
|
-
const target = path.resolve(pathIndex >= 0 ? rest[pathIndex + 1] ?? "." : ".");
|
|
2654
|
+
const target = path.resolve(pathIndex >= 0 ? (rest[pathIndex + 1] ?? ".") : ".");
|
|
2102
2655
|
const numberArg = rest.find((arg, index) => index > 0 && !arg.startsWith("--") && rest[index - 1] !== id && rest[index - 1] !== "--path");
|
|
2103
2656
|
try {
|
|
2104
2657
|
if (!id || !numberArg)
|
|
@@ -2119,8 +2672,8 @@ Exit codes:
|
|
|
2119
2672
|
const json = rest.includes("--json");
|
|
2120
2673
|
const pathIndex = rest.indexOf("--path");
|
|
2121
2674
|
const baseIndex = rest.indexOf("--base");
|
|
2122
|
-
const target = path.resolve(pathIndex >= 0 ? rest[pathIndex + 1] ?? "." : rest.find(arg => !arg.startsWith("--")) ?? ".");
|
|
2123
|
-
const base = baseIndex >= 0 ? rest[baseIndex + 1] ?? "HEAD" : "HEAD";
|
|
2675
|
+
const target = path.resolve(pathIndex >= 0 ? (rest[pathIndex + 1] ?? ".") : (rest.find((arg) => !arg.startsWith("--")) ?? "."));
|
|
2676
|
+
const base = baseIndex >= 0 ? (rest[baseIndex + 1] ?? "HEAD") : "HEAD";
|
|
2124
2677
|
try {
|
|
2125
2678
|
const report = await analyzeGitChanges(target, base);
|
|
2126
2679
|
process.stdout.write(json ? JSON.stringify(report, null, 2) + "\n" : formatGitIntelligence(report) + "\n");
|
|
@@ -2134,7 +2687,7 @@ Exit codes:
|
|
|
2134
2687
|
}
|
|
2135
2688
|
case "deep": {
|
|
2136
2689
|
const json = rest.includes("--json");
|
|
2137
|
-
const target = path.resolve(rest.find(arg => !arg.startsWith("--")) ?? ".");
|
|
2690
|
+
const target = path.resolve(rest.find((arg) => !arg.startsWith("--")) ?? ".");
|
|
2138
2691
|
try {
|
|
2139
2692
|
const report = await analyzeCodebase(target);
|
|
2140
2693
|
process.stdout.write(json ? JSON.stringify(report, null, 2) + "\n" : formatCodebaseAnalysis(report) + "\n");
|
|
@@ -2151,11 +2704,17 @@ Exit codes:
|
|
|
2151
2704
|
process.stdout.write("Usage: anvil remediate [path] [--audit-report FILE] [--outdated-report FILE] [--json]\n");
|
|
2152
2705
|
return;
|
|
2153
2706
|
}
|
|
2154
|
-
const option = (name) => {
|
|
2707
|
+
const option = (name) => {
|
|
2708
|
+
const index = rest.indexOf(name);
|
|
2709
|
+
return index >= 0 ? rest[index + 1] : undefined;
|
|
2710
|
+
};
|
|
2155
2711
|
const target = path.resolve(rest.find((arg, index) => !arg.startsWith("--") && rest[index - 1] !== "--audit-report" && rest[index - 1] !== "--outdated-report") ?? ".");
|
|
2156
2712
|
try {
|
|
2157
2713
|
const auditReport = option("--audit-report"), outdatedReport = option("--outdated-report");
|
|
2158
|
-
const plan = await generateRemediationPlan(target, {
|
|
2714
|
+
const plan = await generateRemediationPlan(target, {
|
|
2715
|
+
...(auditReport ? { auditReport } : {}),
|
|
2716
|
+
...(outdatedReport ? { outdatedReport } : {}),
|
|
2717
|
+
});
|
|
2159
2718
|
process.stdout.write(rest.includes("--json") ? JSON.stringify(plan, null, 2) + "\n" : formatRemediationPlan(plan) + "\n");
|
|
2160
2719
|
}
|
|
2161
2720
|
catch (error) {
|
|
@@ -2166,7 +2725,7 @@ Exit codes:
|
|
|
2166
2725
|
}
|
|
2167
2726
|
case "health": {
|
|
2168
2727
|
const json = rest.includes("--json");
|
|
2169
|
-
const target = path.resolve(rest.find(arg => !arg.startsWith("--")) ?? ".");
|
|
2728
|
+
const target = path.resolve(rest.find((arg) => !arg.startsWith("--")) ?? ".");
|
|
2170
2729
|
try {
|
|
2171
2730
|
const report = await generateProjectHealth(target);
|
|
2172
2731
|
process.stdout.write(json ? JSON.stringify(report, null, 2) + "\n" : formatProjectHealthMarkdown(report) + "\n");
|
|
@@ -2190,7 +2749,7 @@ Exit codes:
|
|
|
2190
2749
|
const fix = isFix || rest.includes("--fix");
|
|
2191
2750
|
const verify = rest.includes("--verify");
|
|
2192
2751
|
const checkOrphans = !rest.includes("--no-orphans");
|
|
2193
|
-
const target = rest.find(arg => !arg.startsWith("--")) ?? ".";
|
|
2752
|
+
const target = rest.find((arg) => !arg.startsWith("--")) ?? ".";
|
|
2194
2753
|
try {
|
|
2195
2754
|
const { cleanProject, formatCleanReport } = await import("./core/project-cleaner.js");
|
|
2196
2755
|
const report = await cleanProject(path.resolve(target), { apply, fix, checkOrphans, verify });
|
|
@@ -2209,7 +2768,7 @@ Exit codes:
|
|
|
2209
2768
|
return;
|
|
2210
2769
|
}
|
|
2211
2770
|
const json = rest.includes("--json");
|
|
2212
|
-
const target = rest.find(arg => !arg.startsWith("--")) ?? ".";
|
|
2771
|
+
const target = rest.find((arg) => !arg.startsWith("--")) ?? ".";
|
|
2213
2772
|
try {
|
|
2214
2773
|
const { undoLastClean, formatUndoReport } = await import("./core/project-cleaner.js");
|
|
2215
2774
|
const report = await undoLastClean(path.resolve(target));
|
|
@@ -2231,7 +2790,7 @@ Exit codes:
|
|
|
2231
2790
|
return;
|
|
2232
2791
|
}
|
|
2233
2792
|
const json = rest.includes("--json");
|
|
2234
|
-
const target = rest.find(arg => !arg.startsWith("--")) ?? ".";
|
|
2793
|
+
const target = rest.find((arg) => !arg.startsWith("--")) ?? ".";
|
|
2235
2794
|
try {
|
|
2236
2795
|
const report = await auditProject(path.resolve(target));
|
|
2237
2796
|
process.stdout.write(json ? `${JSON.stringify(report, null, 2)}\n` : `${formatQualityAudit(report)}\n`);
|
|
@@ -2250,7 +2809,7 @@ Exit codes:
|
|
|
2250
2809
|
return;
|
|
2251
2810
|
}
|
|
2252
2811
|
const json = rest.includes("--json");
|
|
2253
|
-
const target = rest.find(arg => !arg.startsWith("--")) ?? ".";
|
|
2812
|
+
const target = rest.find((arg) => !arg.startsWith("--")) ?? ".";
|
|
2254
2813
|
try {
|
|
2255
2814
|
if (command === "inspect") {
|
|
2256
2815
|
const report = await inspectProject(path.resolve(target));
|
|
@@ -2277,7 +2836,7 @@ Exit codes:
|
|
|
2277
2836
|
}
|
|
2278
2837
|
const json = rest.includes("--json");
|
|
2279
2838
|
const doFix = rest.includes("--fix");
|
|
2280
|
-
const target = rest.find(arg => !arg.startsWith("--"));
|
|
2839
|
+
const target = rest.find((arg) => !arg.startsWith("--"));
|
|
2281
2840
|
try {
|
|
2282
2841
|
const { runDoctorChecks, fixDoctorIssues, formatDoctorReport } = await import("./core/doctor.js");
|
|
2283
2842
|
if (doFix) {
|