anvil-engineering-workbench 1.0.9 → 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.
Files changed (162) hide show
  1. package/CHANGELOG.md +31 -1
  2. package/README.md +23 -18
  3. package/dist/ai/claude-code-provider.js +55 -9
  4. package/dist/ai/claude-code-provider.js.map +1 -1
  5. package/dist/ai/provider.js +1 -1
  6. package/dist/ai/provider.js.map +1 -1
  7. package/dist/cli.js +837 -278
  8. package/dist/cli.js.map +1 -1
  9. package/dist/core/adr-engine.js +9 -11
  10. package/dist/core/adr-engine.js.map +1 -1
  11. package/dist/core/agent-config-release.js +29 -13
  12. package/dist/core/agent-config-release.js.map +1 -1
  13. package/dist/core/agent-config-versioning.js +32 -17
  14. package/dist/core/agent-config-versioning.js.map +1 -1
  15. package/dist/core/agent-evaluation-intelligence.js +30 -38
  16. package/dist/core/agent-evaluation-intelligence.js.map +1 -1
  17. package/dist/core/agent-evolution.js +109 -20
  18. package/dist/core/agent-evolution.js.map +1 -1
  19. package/dist/core/agent-experiment-studio.js +19 -11
  20. package/dist/core/agent-experiment-studio.js.map +1 -1
  21. package/dist/core/agent-optimization.js +69 -14
  22. package/dist/core/agent-optimization.js.map +1 -1
  23. package/dist/core/agent-registry.js +87 -15
  24. package/dist/core/agent-registry.js.map +1 -1
  25. package/dist/core/agent-security-audit.js +21 -21
  26. package/dist/core/agent-security-audit.js.map +1 -1
  27. package/dist/core/agent-workspace-context.js +37 -6
  28. package/dist/core/agent-workspace-context.js.map +1 -1
  29. package/dist/core/ai-code-review.js +60 -12
  30. package/dist/core/ai-code-review.js.map +1 -1
  31. package/dist/core/anthropic-provider.js.map +1 -1
  32. package/dist/core/architecture-map.js +87 -24
  33. package/dist/core/architecture-map.js.map +1 -1
  34. package/dist/core/benchmark-engine.js +89 -21
  35. package/dist/core/benchmark-engine.js.map +1 -1
  36. package/dist/core/benchmark-matrix.js +215 -41
  37. package/dist/core/benchmark-matrix.js.map +1 -1
  38. package/dist/core/benchmark-regression.js +124 -18
  39. package/dist/core/benchmark-regression.js.map +1 -1
  40. package/dist/core/change-intelligence.js +102 -43
  41. package/dist/core/change-intelligence.js.map +1 -1
  42. package/dist/core/code-intelligence.js +40 -13
  43. package/dist/core/code-intelligence.js.map +1 -1
  44. package/dist/core/code-review.js +145 -17
  45. package/dist/core/code-review.js.map +1 -1
  46. package/dist/core/code-search.js +79 -39
  47. package/dist/core/code-search.js.map +1 -1
  48. package/dist/core/container-sandbox.js +87 -23
  49. package/dist/core/container-sandbox.js.map +1 -1
  50. package/dist/core/dashboard-server.js +379 -93
  51. package/dist/core/dashboard-server.js.map +1 -1
  52. package/dist/core/dependency-graph.js +75 -13
  53. package/dist/core/dependency-graph.js.map +1 -1
  54. package/dist/core/dependency-impact.js +132 -33
  55. package/dist/core/dependency-impact.js.map +1 -1
  56. package/dist/core/dependency-intelligence.js +153 -56
  57. package/dist/core/dependency-intelligence.js.map +1 -1
  58. package/dist/core/doctor.js +3 -3
  59. package/dist/core/doctor.js.map +1 -1
  60. package/dist/core/engineering-risk.js +75 -40
  61. package/dist/core/engineering-risk.js.map +1 -1
  62. package/dist/core/env-compat.js.map +1 -1
  63. package/dist/core/evaluation-engine.js +188 -42
  64. package/dist/core/evaluation-engine.js.map +1 -1
  65. package/dist/core/execution-trace.js +83 -29
  66. package/dist/core/execution-trace.js.map +1 -1
  67. package/dist/core/experiment-history.js +70 -20
  68. package/dist/core/experiment-history.js.map +1 -1
  69. package/dist/core/experiment-manifest.js +92 -13
  70. package/dist/core/experiment-manifest.js.map +1 -1
  71. package/dist/core/gemini-provider.js.map +1 -1
  72. package/dist/core/git-intelligence.js +68 -16
  73. package/dist/core/git-intelligence.js.map +1 -1
  74. package/dist/core/hook-engine.js +7 -3
  75. package/dist/core/hook-engine.js.map +1 -1
  76. package/dist/core/hosted-agent-provider.js +48 -8
  77. package/dist/core/hosted-agent-provider.js.map +1 -1
  78. package/dist/core/intelligence-timeline.js +92 -43
  79. package/dist/core/intelligence-timeline.js.map +1 -1
  80. package/dist/core/mcp-setup.js +12 -12
  81. package/dist/core/mcp-setup.js.map +1 -1
  82. package/dist/core/model-router.js +153 -37
  83. package/dist/core/model-router.js.map +1 -1
  84. package/dist/core/openai-compatible-provider.js +41 -10
  85. package/dist/core/openai-compatible-provider.js.map +1 -1
  86. package/dist/core/orchestrator.js +28 -23
  87. package/dist/core/orchestrator.js.map +1 -1
  88. package/dist/core/patch-application.js +88 -24
  89. package/dist/core/patch-application.js.map +1 -1
  90. package/dist/core/patch-approval.js +43 -15
  91. package/dist/core/patch-approval.js.map +1 -1
  92. package/dist/core/patch-validation.js +93 -15
  93. package/dist/core/patch-validation.js.map +1 -1
  94. package/dist/core/permission-policy.js +8 -5
  95. package/dist/core/permission-policy.js.map +1 -1
  96. package/dist/core/policy-engine.d.ts +76 -0
  97. package/dist/core/policy-engine.js +352 -0
  98. package/dist/core/policy-engine.js.map +1 -0
  99. package/dist/core/project-cleaner.js +143 -129
  100. package/dist/core/project-cleaner.js.map +1 -1
  101. package/dist/core/project-health.js +183 -21
  102. package/dist/core/project-health.js.map +1 -1
  103. package/dist/core/project-init.js +32 -20
  104. package/dist/core/project-init.js.map +1 -1
  105. package/dist/core/project-inspector.js +81 -32
  106. package/dist/core/project-inspector.js.map +1 -1
  107. package/dist/core/project-memory.js +41 -18
  108. package/dist/core/project-memory.js.map +1 -1
  109. package/dist/core/provider-diagnostics.js +65 -12
  110. package/dist/core/provider-diagnostics.js.map +1 -1
  111. package/dist/core/quality-audit.js +167 -28
  112. package/dist/core/quality-audit.js.map +1 -1
  113. package/dist/core/regression-intelligence.js +88 -8
  114. package/dist/core/regression-intelligence.js.map +1 -1
  115. package/dist/core/remediation-planner.js +112 -40
  116. package/dist/core/remediation-planner.js.map +1 -1
  117. package/dist/core/review-history.js +39 -7
  118. package/dist/core/review-history.js.map +1 -1
  119. package/dist/core/run-history-output.js.map +1 -1
  120. package/dist/core/run-replay.js +12 -10
  121. package/dist/core/run-replay.js.map +1 -1
  122. package/dist/core/run-store.js +48 -21
  123. package/dist/core/run-store.js.map +1 -1
  124. package/dist/core/sandbox-cleanup-audit.js +1 -1
  125. package/dist/core/sandbox-cleanup-audit.js.map +1 -1
  126. package/dist/core/sandbox-compliance.js +53 -9
  127. package/dist/core/sandbox-compliance.js.map +1 -1
  128. package/dist/core/sandbox-lifecycle.js +1 -1
  129. package/dist/core/sandbox-lifecycle.js.map +1 -1
  130. package/dist/core/sandbox-policy.js +27 -3
  131. package/dist/core/sandbox-policy.js.map +1 -1
  132. package/dist/core/sandbox-runtime.js +9 -5
  133. package/dist/core/sandbox-runtime.js.map +1 -1
  134. package/dist/core/sandbox-security-profiles.js +31 -12
  135. package/dist/core/sandbox-security-profiles.js.map +1 -1
  136. package/dist/core/sarif-formatter.d.ts +10 -3
  137. package/dist/core/sarif-formatter.js +172 -57
  138. package/dist/core/sarif-formatter.js.map +1 -1
  139. package/dist/core/security-scanner.js +40 -32
  140. package/dist/core/security-scanner.js.map +1 -1
  141. package/dist/core/skill-registry.js +83 -21
  142. package/dist/core/skill-registry.js.map +1 -1
  143. package/dist/core/staged-verification.js +25 -10
  144. package/dist/core/staged-verification.js.map +1 -1
  145. package/dist/core/verification-history.js +12 -7
  146. package/dist/core/verification-history.js.map +1 -1
  147. package/dist/core/verification.js +50 -19
  148. package/dist/core/verification.js.map +1 -1
  149. package/dist/core/workflow-store.js +16 -4
  150. package/dist/core/workflow-store.js.map +1 -1
  151. package/dist/core/workspace-browser.js +57 -10
  152. package/dist/core/workspace-browser.js.map +1 -1
  153. package/dist/core/workspace-scan-policy.js +26 -4
  154. package/dist/core/workspace-scan-policy.js.map +1 -1
  155. package/dist/core/workspace-tool-broker.d.ts +1 -1
  156. package/dist/core/workspace-tool-broker.js +25 -4
  157. package/dist/core/workspace-tool-broker.js.map +1 -1
  158. package/dist/mcp/server.js +148 -55
  159. package/dist/mcp/server.js.map +1 -1
  160. package/dist/mcp/workspace-path.js +2 -2
  161. package/dist/mcp/workspace-path.js.map +1 -1
  162. package/package.json +8 -5
@@ -1,6 +1,7 @@
1
+ /* anvil-disable-file ANVIL-R003 */
1
2
  import { createServer } from "node:http";
2
3
  import { captureAgentConfigVersion, listAgentConfigVersions } from "./agent-config-versioning.js";
3
- import { decideAgentConfigRelease, listAgentConfigReleases, prepareAgentConfigRelease } from "./agent-config-release.js";
4
+ import { decideAgentConfigRelease, listAgentConfigReleases, prepareAgentConfigRelease, } from "./agent-config-release.js";
4
5
  import { mkdir, readFile, readdir, lstat, writeFile, realpath } from "node:fs/promises";
5
6
  import path from "node:path";
6
7
  import { inspectProject } from "./project-inspector.js";
@@ -2032,21 +2033,46 @@ export async function startDashboard(options) {
2032
2033
  // DNS-rebinding page cannot reach local APIs with a matching attacker Origin.
2033
2034
  const expectedHost = `${host}:${request.socket.localPort}`;
2034
2035
  if (request.headers.host !== expectedHost) {
2035
- response.writeHead(421, { "content-type": "application/json" }).end(JSON.stringify({ error: "Unexpected Host header." }));
2036
+ response
2037
+ .writeHead(421, { "content-type": "application/json" })
2038
+ .end(JSON.stringify({ error: "Unexpected Host header." }));
2036
2039
  return;
2037
2040
  }
2038
2041
  if (request.method !== "GET" && request.method !== "POST") {
2039
- response.writeHead(405, { "content-type": "application/json" }).end(JSON.stringify({ error: "Method not allowed." }));
2042
+ response
2043
+ .writeHead(405, { "content-type": "application/json" })
2044
+ .end(JSON.stringify({ error: "Method not allowed." }));
2040
2045
  return;
2041
2046
  }
2042
- if (request.method === "POST" && (requestUrl.pathname === "/api/memory" || requestUrl.pathname === "/api/memory/delete" || requestUrl.pathname === "/api/adrs" || requestUrl.pathname === "/api/adrs/sync" || requestUrl.pathname === "/api/security/fix" || requestUrl.pathname === "/api/workflows" || requestUrl.pathname === "/api/clean/run" || requestUrl.pathname === "/api/clean/undo" || requestUrl.pathname === "/api/config-files" || requestUrl.pathname === "/api/config-snapshots" || /^\/api\/providers\/(?:openai|anthropic|google|ollama)\/diagnose$/.test(requestUrl.pathname) || requestUrl.pathname === "/api/config-releases" || /^\/api\/config-releases\/rel-[a-f0-9]{12}\/(?:approve|reject)$/.test(requestUrl.pathname) || requestUrl.pathname.endsWith("/run") && requestUrl.pathname.startsWith("/api/workflows/") || requestUrl.pathname.endsWith("/execute") && requestUrl.pathname.startsWith("/api/workflows/") || /^\/api\/runs\/[^/]+\/(?:replay|cancel)$/.test(requestUrl.pathname) || /^\/api\/runs\/[^/]+\/tasks\/[^/]+\/retry$/.test(requestUrl.pathname))) {
2047
+ if (request.method === "POST" &&
2048
+ (requestUrl.pathname === "/api/memory" ||
2049
+ requestUrl.pathname === "/api/memory/delete" ||
2050
+ requestUrl.pathname === "/api/adrs" ||
2051
+ requestUrl.pathname === "/api/adrs/sync" ||
2052
+ requestUrl.pathname === "/api/security/fix" ||
2053
+ requestUrl.pathname === "/api/workflows" ||
2054
+ requestUrl.pathname === "/api/clean/run" ||
2055
+ requestUrl.pathname === "/api/clean/undo" ||
2056
+ requestUrl.pathname === "/api/config-files" ||
2057
+ requestUrl.pathname === "/api/config-snapshots" ||
2058
+ /^\/api\/providers\/(?:openai|anthropic|google|ollama)\/diagnose$/.test(requestUrl.pathname) ||
2059
+ requestUrl.pathname === "/api/config-releases" ||
2060
+ /^\/api\/config-releases\/rel-[a-f0-9]{12}\/(?:approve|reject)$/.test(requestUrl.pathname) ||
2061
+ (requestUrl.pathname.endsWith("/run") && requestUrl.pathname.startsWith("/api/workflows/")) ||
2062
+ (requestUrl.pathname.endsWith("/execute") && requestUrl.pathname.startsWith("/api/workflows/")) ||
2063
+ /^\/api\/runs\/[^/]+\/(?:replay|cancel)$/.test(requestUrl.pathname) ||
2064
+ /^\/api\/runs\/[^/]+\/tasks\/[^/]+\/retry$/.test(requestUrl.pathname))) {
2043
2065
  const origin = request.headers.origin;
2044
2066
  if (origin && new URL(origin).host !== request.headers.host) {
2045
- response.writeHead(403, { "content-type": "application/json" }).end(JSON.stringify({ error: "Cross-origin requests are not allowed." }));
2067
+ response
2068
+ .writeHead(403, { "content-type": "application/json" })
2069
+ .end(JSON.stringify({ error: "Cross-origin requests are not allowed." }));
2046
2070
  return;
2047
2071
  }
2048
2072
  if (!request.headers["content-type"]?.includes("application/json")) {
2049
- response.writeHead(415, { "content-type": "application/json" }).end(JSON.stringify({ error: "Expected application/json." }));
2073
+ response
2074
+ .writeHead(415, { "content-type": "application/json" })
2075
+ .end(JSON.stringify({ error: "Expected application/json." }));
2050
2076
  return;
2051
2077
  }
2052
2078
  const chunks = [];
@@ -2054,7 +2080,9 @@ export async function startDashboard(options) {
2054
2080
  for await (const chunk of request) {
2055
2081
  size += chunk.length;
2056
2082
  if (size > (requestUrl.pathname === "/api/config-files" ? 140000 : 16384)) {
2057
- response.writeHead(413, { "content-type": "application/json" }).end(JSON.stringify({ error: "Request body is too large." }));
2083
+ response
2084
+ .writeHead(413, { "content-type": "application/json" })
2085
+ .end(JSON.stringify({ error: "Request body is too large." }));
2058
2086
  return;
2059
2087
  }
2060
2088
  chunks.push(Buffer.from(chunk));
@@ -2063,15 +2091,24 @@ export async function startDashboard(options) {
2063
2091
  const providerDiagnosticRoute = requestUrl.pathname.match(/^\/api\/providers\/(openai|anthropic|google|ollama)\/diagnose$/);
2064
2092
  if (providerDiagnosticRoute) {
2065
2093
  const diagnostic = await diagnoseProvider(providerDiagnosticRoute[1]);
2066
- response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify(diagnostic));
2094
+ response
2095
+ .writeHead(200, { "content-type": "application/json; charset=utf-8" })
2096
+ .end(JSON.stringify(diagnostic));
2067
2097
  return;
2068
2098
  }
2069
2099
  if (requestUrl.pathname === "/api/config-releases") {
2070
2100
  const input = body;
2071
- if (typeof input?.candidateVersionId !== "string" || typeof input.baselineVersionId !== "string" || typeof input.matrixId !== "string" || !input.matrixId.trim())
2101
+ if (typeof input?.candidateVersionId !== "string" ||
2102
+ typeof input.baselineVersionId !== "string" ||
2103
+ typeof input.matrixId !== "string" ||
2104
+ !input.matrixId.trim())
2072
2105
  throw new Error("Candidate, baseline and benchmark matrix IDs are required.");
2073
2106
  const regression = await loadBenchmarkRegression(projectPath, input.matrixId);
2074
- const release = await prepareAgentConfigRelease(projectPath, { candidateVersionId: input.candidateVersionId, baselineVersionId: input.baselineVersionId, regression });
2107
+ const release = await prepareAgentConfigRelease(projectPath, {
2108
+ candidateVersionId: input.candidateVersionId,
2109
+ baselineVersionId: input.baselineVersionId,
2110
+ regression,
2111
+ });
2075
2112
  response.writeHead(201, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify(release));
2076
2113
  return;
2077
2114
  }
@@ -2088,8 +2125,15 @@ export async function startDashboard(options) {
2088
2125
  const input = body;
2089
2126
  if (input?.note !== undefined && typeof input.note !== "string")
2090
2127
  throw new Error("Snapshot note must be text.");
2091
- const version = await captureAgentConfigVersion(projectPath, { note: typeof input.note === "string" ? input.note : "" });
2092
- response.writeHead(201, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify({ id: version.id, status: version.status, files: version.files.map(file => ({ path: file.path, sha256: file.sha256 })), createdAt: version.createdAt }));
2128
+ const version = await captureAgentConfigVersion(projectPath, {
2129
+ note: typeof input.note === "string" ? input.note : "",
2130
+ });
2131
+ response.writeHead(201, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify({
2132
+ id: version.id,
2133
+ status: version.status,
2134
+ files: version.files.map((file) => ({ path: file.path, sha256: file.sha256 })),
2135
+ createdAt: version.createdAt,
2136
+ }));
2093
2137
  return;
2094
2138
  }
2095
2139
  if (requestUrl.pathname === "/api/config-files") {
@@ -2100,7 +2144,10 @@ export async function startDashboard(options) {
2100
2144
  throw new Error("Choose agents or skills.");
2101
2145
  if (typeof input.id !== "string" || !/^[a-z0-9][a-z0-9-]{0,63}$/.test(input.id))
2102
2146
  throw new Error("File ID must be a lowercase slug (letters, numbers and hyphens).");
2103
- if (typeof input.content !== "string" || !input.content.trim() || Buffer.byteLength(input.content, "utf8") > 128 * 1024 || input.content.includes("\\0"))
2147
+ if (typeof input.content !== "string" ||
2148
+ !input.content.trim() ||
2149
+ Buffer.byteLength(input.content, "utf8") > 128 * 1024 ||
2150
+ input.content.includes("\\0"))
2104
2151
  throw new Error("Markdown content must be non-empty and at most 128 KiB.");
2105
2152
  const root = path.resolve(projectPath);
2106
2153
  const forgeDirectory = path.join(root, ".forge");
@@ -2121,21 +2168,34 @@ export async function startDashboard(options) {
2121
2168
  throw error;
2122
2169
  }
2123
2170
  await writeFile(file, input.content, { encoding: "utf8", mode: 0o600 });
2124
- response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify({ category: input.category, id: input.id, bytes: Buffer.byteLength(input.content, "utf8") }));
2171
+ response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify({
2172
+ category: input.category,
2173
+ id: input.id,
2174
+ bytes: Buffer.byteLength(input.content, "utf8"),
2175
+ }));
2125
2176
  return;
2126
2177
  }
2127
2178
  const cancelRoute = requestUrl.pathname.match(/^\/api\/runs\/([^/]+)\/cancel$/);
2128
2179
  if (cancelRoute) {
2129
2180
  const run = await loadRun(projectPath, decodeURIComponent(cancelRoute[1]));
2130
2181
  if (["completed", "failed", "cancelled"].includes(run.status)) {
2131
- response.writeHead(409, { "content-type": "application/json" }).end(JSON.stringify({ error: "This run is already terminal." }));
2182
+ response
2183
+ .writeHead(409, { "content-type": "application/json" })
2184
+ .end(JSON.stringify({ error: "This run is already terminal." }));
2132
2185
  return;
2133
2186
  }
2134
2187
  run.status = "cancelled";
2135
2188
  run.updatedAt = new Date().toISOString();
2136
- run.events.push({ at: run.updatedAt, taskId: "*", type: "blocked", message: "Cancellation requested from the dashboard. Active provider calls may finish before the run stops." });
2189
+ run.events.push({
2190
+ at: run.updatedAt,
2191
+ taskId: "*",
2192
+ type: "blocked",
2193
+ message: "Cancellation requested from the dashboard. Active provider calls may finish before the run stops.",
2194
+ });
2137
2195
  await saveRun(projectPath, run);
2138
- response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify({ id: run.id, status: run.status }));
2196
+ response
2197
+ .writeHead(200, { "content-type": "application/json; charset=utf-8" })
2198
+ .end(JSON.stringify({ id: run.id, status: run.status }));
2139
2199
  return;
2140
2200
  }
2141
2201
  const retryRoute = requestUrl.pathname.match(/^\/api\/runs\/([^/]+)\/tasks\/([^/]+)\/retry$/);
@@ -2143,7 +2203,9 @@ export async function startDashboard(options) {
2143
2203
  const source = await loadRun(projectPath, decodeURIComponent(retryRoute[1]));
2144
2204
  const retry = createTaskRetryRun(source, decodeURIComponent(retryRoute[2]));
2145
2205
  await saveRun(projectPath, retry);
2146
- response.writeHead(201, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify({ id: retry.id, status: retry.status, sourceRunId: source.id }));
2206
+ response
2207
+ .writeHead(201, { "content-type": "application/json; charset=utf-8" })
2208
+ .end(JSON.stringify({ id: retry.id, status: retry.status, sourceRunId: source.id }));
2147
2209
  return;
2148
2210
  }
2149
2211
  const replayRoute = requestUrl.pathname.match(/^\/api\/runs\/([^/]+)\/replay$/);
@@ -2151,7 +2213,9 @@ export async function startDashboard(options) {
2151
2213
  const source = await loadRun(projectPath, decodeURIComponent(replayRoute[1]));
2152
2214
  const replay = createReplayRun(source);
2153
2215
  await saveRun(projectPath, replay);
2154
- response.writeHead(201, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify({ id: replay.id, status: replay.status, sourceRunId: source.id }));
2216
+ response
2217
+ .writeHead(201, { "content-type": "application/json; charset=utf-8" })
2218
+ .end(JSON.stringify({ id: replay.id, status: replay.status, sourceRunId: source.id }));
2155
2219
  return;
2156
2220
  }
2157
2221
  if (requestUrl.pathname === "/api/clean/run") {
@@ -2177,7 +2241,9 @@ export async function startDashboard(options) {
2177
2241
  const record = (body && typeof body === "object" ? body : {});
2178
2242
  const id = String(record.id || "");
2179
2243
  const success = await removeProjectMemory(projectPath, id);
2180
- response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify({ success }));
2244
+ response
2245
+ .writeHead(200, { "content-type": "application/json; charset=utf-8" })
2246
+ .end(JSON.stringify({ success }));
2181
2247
  return;
2182
2248
  }
2183
2249
  if (requestUrl.pathname === "/api/adrs") {
@@ -2208,23 +2274,41 @@ export async function startDashboard(options) {
2208
2274
  const workflow = await loadWorkflow(projectPath, decodeURIComponent(workflowId));
2209
2275
  const run = createRunFromWorkflow(workflow);
2210
2276
  await saveRun(projectPath, run);
2211
- broadcastEvent("workflow_started", { runId: run.id, workflowName: workflow.name, taskCount: run.tasks.length });
2277
+ broadcastEvent("workflow_started", {
2278
+ runId: run.id,
2279
+ workflowName: workflow.name,
2280
+ taskCount: run.tasks.length,
2281
+ });
2212
2282
  const provider = new DemoAgentProvider();
2213
2283
  const completed = await advanceRun(run, provider, new Set(), {
2214
2284
  maxConcurrency: 4,
2215
2285
  onUpdate: async (updatedRun) => {
2216
2286
  await saveRun(projectPath, updatedRun);
2217
- broadcastEvent("workflow_update", { runId: updatedRun.id, status: updatedRun.status, tasks: updatedRun.tasks });
2287
+ broadcastEvent("workflow_update", {
2288
+ runId: updatedRun.id,
2289
+ status: updatedRun.status,
2290
+ tasks: updatedRun.tasks,
2291
+ });
2218
2292
  },
2219
2293
  onTaskSettled: async (updatedRun, settledTaskId) => {
2220
2294
  await saveRun(projectPath, updatedRun);
2221
- const taskRecord = updatedRun.tasks.find(t => t.task.id === settledTaskId);
2222
- broadcastEvent("workflow_task_settled", { runId: updatedRun.id, taskId: settledTaskId, status: taskRecord?.status, result: taskRecord?.result });
2223
- }
2295
+ const taskRecord = updatedRun.tasks.find((t) => t.task.id === settledTaskId);
2296
+ broadcastEvent("workflow_task_settled", {
2297
+ runId: updatedRun.id,
2298
+ taskId: settledTaskId,
2299
+ status: taskRecord?.status,
2300
+ result: taskRecord?.result,
2301
+ });
2302
+ },
2224
2303
  });
2225
2304
  await saveRun(projectPath, completed);
2226
2305
  broadcastEvent("workflow_completed", { runId: completed.id, status: completed.status });
2227
- response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify({ id: completed.id, status: completed.status, taskCount: completed.tasks.length, tasks: completed.tasks }));
2306
+ response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify({
2307
+ id: completed.id,
2308
+ status: completed.status,
2309
+ taskCount: completed.tasks.length,
2310
+ tasks: completed.tasks,
2311
+ }));
2228
2312
  return;
2229
2313
  }
2230
2314
  if (requestUrl.pathname === "/api/workflows") {
@@ -2236,22 +2320,30 @@ export async function startDashboard(options) {
2236
2320
  const workflow = await loadWorkflow(projectPath, decodeURIComponent(runId));
2237
2321
  const run = createRunFromWorkflow(workflow);
2238
2322
  await saveRun(projectPath, run);
2239
- response.writeHead(201, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify({ id: run.id, status: run.status, taskCount: run.tasks.length }));
2323
+ response
2324
+ .writeHead(201, { "content-type": "application/json; charset=utf-8" })
2325
+ .end(JSON.stringify({ id: run.id, status: run.status, taskCount: run.tasks.length }));
2240
2326
  return;
2241
2327
  }
2242
2328
  if (request.method === "POST") {
2243
2329
  const approvalRoute = requestUrl.pathname.match(/^\/api\/runs\/([^/]+)\/tasks\/([^/]+)\/approval$/);
2244
2330
  if (!approvalRoute) {
2245
- response.writeHead(405, { "content-type": "application/json" }).end(JSON.stringify({ error: "Method not allowed." }));
2331
+ response
2332
+ .writeHead(405, { "content-type": "application/json" })
2333
+ .end(JSON.stringify({ error: "Method not allowed." }));
2246
2334
  return;
2247
2335
  }
2248
2336
  const origin = request.headers.origin;
2249
2337
  if (origin && new URL(origin).host !== request.headers.host) {
2250
- response.writeHead(403, { "content-type": "application/json" }).end(JSON.stringify({ error: "Cross-origin requests are not allowed." }));
2338
+ response
2339
+ .writeHead(403, { "content-type": "application/json" })
2340
+ .end(JSON.stringify({ error: "Cross-origin requests are not allowed." }));
2251
2341
  return;
2252
2342
  }
2253
2343
  if (!request.headers["content-type"]?.includes("application/json")) {
2254
- response.writeHead(415, { "content-type": "application/json" }).end(JSON.stringify({ error: "Expected application/json." }));
2344
+ response
2345
+ .writeHead(415, { "content-type": "application/json" })
2346
+ .end(JSON.stringify({ error: "Expected application/json." }));
2255
2347
  return;
2256
2348
  }
2257
2349
  const chunks = [];
@@ -2259,32 +2351,43 @@ export async function startDashboard(options) {
2259
2351
  for await (const chunk of request) {
2260
2352
  size += chunk.length;
2261
2353
  if (size > 8192) {
2262
- response.writeHead(413, { "content-type": "application/json" }).end(JSON.stringify({ error: "Request body is too large." }));
2354
+ response
2355
+ .writeHead(413, { "content-type": "application/json" })
2356
+ .end(JSON.stringify({ error: "Request body is too large." }));
2263
2357
  return;
2264
2358
  }
2265
2359
  chunks.push(Buffer.from(chunk));
2266
2360
  }
2267
2361
  const body = JSON.parse(Buffer.concat(chunks).toString("utf8"));
2268
- if (!["approved", "rejected"].includes(body.decision ?? "") || typeof body.taskId !== "string" || typeof body.reviewer !== "string" || (body.reason !== undefined && typeof body.reason !== "string")) {
2269
- response.writeHead(400, { "content-type": "application/json" }).end(JSON.stringify({ error: "Invalid approval request." }));
2362
+ if (!["approved", "rejected"].includes(body.decision ?? "") ||
2363
+ typeof body.taskId !== "string" ||
2364
+ typeof body.reviewer !== "string" ||
2365
+ (body.reason !== undefined && typeof body.reason !== "string")) {
2366
+ response
2367
+ .writeHead(400, { "content-type": "application/json" })
2368
+ .end(JSON.stringify({ error: "Invalid approval request." }));
2270
2369
  return;
2271
2370
  }
2272
2371
  const runId = decodeURIComponent(approvalRoute[1]);
2273
2372
  const taskId = decodeURIComponent(approvalRoute[2]);
2274
2373
  if (body.taskId !== taskId) {
2275
- response.writeHead(400, { "content-type": "application/json" }).end(JSON.stringify({ error: "Task identifier mismatch." }));
2374
+ response
2375
+ .writeHead(400, { "content-type": "application/json" })
2376
+ .end(JSON.stringify({ error: "Task identifier mismatch." }));
2276
2377
  return;
2277
2378
  }
2278
2379
  const run = await decideTaskApproval(projectPath, runId, taskId, body.decision, body.reviewer, body.reason);
2279
2380
  broadcastEvent("run-updated", { runId: run.id, taskId, decision: body.decision, at: new Date().toISOString() });
2280
- response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify({ id: run.id, status: run.status, task: run.tasks.find(item => item.task.id === taskId) }));
2381
+ response
2382
+ .writeHead(200, { "content-type": "application/json; charset=utf-8" })
2383
+ .end(JSON.stringify({ id: run.id, status: run.status, task: run.tasks.find((item) => item.task.id === taskId) }));
2281
2384
  return;
2282
2385
  }
2283
2386
  if (requestUrl.pathname === "/api/events") {
2284
2387
  response.writeHead(200, {
2285
2388
  "Content-Type": "text/event-stream",
2286
2389
  "Cache-Control": "no-cache",
2287
- "Connection": "keep-alive",
2390
+ Connection: "keep-alive",
2288
2391
  "X-Accel-Buffering": "no",
2289
2392
  });
2290
2393
  response.write("retry: 3000\n\n");
@@ -2296,7 +2399,9 @@ export async function startDashboard(options) {
2296
2399
  catch {
2297
2400
  sseClients.delete(response);
2298
2401
  }
2299
- request.on("close", () => { sseClients.delete(response); });
2402
+ request.on("close", () => {
2403
+ sseClients.delete(response);
2404
+ });
2300
2405
  // Keep connection open — do not call response.end()
2301
2406
  return;
2302
2407
  }
@@ -2312,18 +2417,64 @@ export async function startDashboard(options) {
2312
2417
  if (requestUrl.pathname === "/api/providers") {
2313
2418
  const selected = (process.env.ANVIL_AI_PROVIDER ?? process.env.FORGE_AI_PROVIDER ?? "openai").toLowerCase();
2314
2419
  const rows = [
2315
- { id: "openai", configured: Boolean(process.env.ANVIL_API_KEY || process.env.FORGE_API_KEY || process.env.OPENAI_API_KEY), model: process.env.ANVIL_AI_MODEL || process.env.FORGE_AI_MODEL || process.env.ANVIL_MODEL || process.env.FORGE_MODEL || "gpt-4.1-mini", detail: "API credential presence only; connectivity is not tested." },
2316
- { id: "anthropic", configured: Boolean(process.env.ANTHROPIC_API_KEY), model: process.env.ANVIL_AI_MODEL || process.env.FORGE_AI_MODEL || "claude-sonnet-4-5", detail: "API credential presence only; connectivity is not tested." },
2317
- { id: "google", configured: Boolean(process.env.GOOGLE_API_KEY), model: process.env.ANVIL_AI_MODEL || process.env.FORGE_AI_MODEL || "gemini-2.5-flash", detail: "API credential presence only; connectivity is not tested." },
2318
- { id: "ollama", configured: true, model: process.env.ANVIL_AI_MODEL || process.env.FORGE_AI_MODEL || "llama3.2", detail: "Endpoint origin: " + safeProviderOrigin(process.env.ANVIL_BASE_URL || process.env.FORGE_BASE_URL || process.env.OLLAMA_HOST || "http://localhost:11434") + "; connectivity is not tested." },
2319
- { id: "claude-code", configured: false, model: process.env.ANVIL_AI_MODEL || process.env.FORGE_AI_MODEL || "sonnet", detail: "Local CLI installation and account authentication are not checked by the dashboard." }
2320
- ].map(item => ({ ...item, selected: selected === item.id, status: item.id === "claude-code" ? "not-checked" : item.configured ? "configured" : "needs-credentials" }));
2420
+ {
2421
+ id: "openai",
2422
+ configured: Boolean(process.env.ANVIL_API_KEY || process.env.FORGE_API_KEY || process.env.OPENAI_API_KEY),
2423
+ model: process.env.ANVIL_AI_MODEL ||
2424
+ process.env.FORGE_AI_MODEL ||
2425
+ process.env.ANVIL_MODEL ||
2426
+ process.env.FORGE_MODEL ||
2427
+ "gpt-4.1-mini",
2428
+ detail: "API credential presence only; connectivity is not tested.",
2429
+ },
2430
+ {
2431
+ id: "anthropic",
2432
+ configured: Boolean(process.env.ANTHROPIC_API_KEY),
2433
+ model: process.env.ANVIL_AI_MODEL || process.env.FORGE_AI_MODEL || "claude-sonnet-4-5",
2434
+ detail: "API credential presence only; connectivity is not tested.",
2435
+ },
2436
+ {
2437
+ id: "google",
2438
+ configured: Boolean(process.env.GOOGLE_API_KEY),
2439
+ model: process.env.ANVIL_AI_MODEL || process.env.FORGE_AI_MODEL || "gemini-2.5-flash",
2440
+ detail: "API credential presence only; connectivity is not tested.",
2441
+ },
2442
+ {
2443
+ id: "ollama",
2444
+ configured: true,
2445
+ model: process.env.ANVIL_AI_MODEL || process.env.FORGE_AI_MODEL || "llama3.2",
2446
+ detail: "Endpoint origin: " +
2447
+ safeProviderOrigin(process.env.ANVIL_BASE_URL ||
2448
+ process.env.FORGE_BASE_URL ||
2449
+ process.env.OLLAMA_HOST ||
2450
+ "http://localhost:11434") +
2451
+ "; connectivity is not tested.",
2452
+ },
2453
+ {
2454
+ id: "claude-code",
2455
+ configured: false,
2456
+ model: process.env.ANVIL_AI_MODEL || process.env.FORGE_AI_MODEL || "sonnet",
2457
+ detail: "Local CLI installation and account authentication are not checked by the dashboard.",
2458
+ },
2459
+ ].map((item) => ({
2460
+ ...item,
2461
+ selected: selected === item.id,
2462
+ status: item.id === "claude-code" ? "not-checked" : item.configured ? "configured" : "needs-credentials",
2463
+ }));
2321
2464
  response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify(rows));
2322
2465
  return;
2323
2466
  }
2324
2467
  if (requestUrl.pathname === "/api/config-snapshots") {
2325
2468
  const versions = await listAgentConfigVersions(projectPath);
2326
- response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify(versions.map(item => ({ id: item.id, createdAt: item.createdAt, createdBy: item.createdBy, note: item.note, status: item.status, approvedBy: item.approvedBy, files: item.files.map(file => ({ path: file.path, sha256: file.sha256 })) }))));
2469
+ response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify(versions.map((item) => ({
2470
+ id: item.id,
2471
+ createdAt: item.createdAt,
2472
+ createdBy: item.createdBy,
2473
+ note: item.note,
2474
+ status: item.status,
2475
+ approvedBy: item.approvedBy,
2476
+ files: item.files.map((file) => ({ path: file.path, sha256: file.sha256 })),
2477
+ }))));
2327
2478
  return;
2328
2479
  }
2329
2480
  if (requestUrl.pathname === "/api/config-files") {
@@ -2349,7 +2500,9 @@ export async function startDashboard(options) {
2349
2500
  if (!info.isFile() || info.isSymbolicLink() || info.size > 128 * 1024)
2350
2501
  throw new Error("Configuration file is not a supported regular Markdown file.");
2351
2502
  const content = await readFile(file, "utf8");
2352
- response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify({ category, id, content }));
2503
+ response
2504
+ .writeHead(200, { "content-type": "application/json; charset=utf-8" })
2505
+ .end(JSON.stringify({ category, id, content }));
2353
2506
  return;
2354
2507
  }
2355
2508
  const categories = category ? [category] : ["agents", "skills"];
@@ -2380,7 +2533,9 @@ export async function startDashboard(options) {
2380
2533
  items.push({ category: kind, id: name, bytes: info.size });
2381
2534
  }
2382
2535
  }
2383
- response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify(items.sort((a, b) => a.category.localeCompare(b.category) || a.id.localeCompare(b.id))));
2536
+ response
2537
+ .writeHead(200, { "content-type": "application/json; charset=utf-8" })
2538
+ .end(JSON.stringify(items.sort((a, b) => a.category.localeCompare(b.category) || a.id.localeCompare(b.id))));
2384
2539
  return;
2385
2540
  }
2386
2541
  if (requestUrl.pathname === "/api/workflows") {
@@ -2418,7 +2573,9 @@ export async function startDashboard(options) {
2418
2573
  if (!info.isFile() || info.isSymbolicLink() || info.size > 128 * 1024)
2419
2574
  throw new Error("Configuration file is not a supported regular Markdown file.");
2420
2575
  const content = await readFile(file, "utf8");
2421
- response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify({ category, id, content }));
2576
+ response
2577
+ .writeHead(200, { "content-type": "application/json; charset=utf-8" })
2578
+ .end(JSON.stringify({ category, id, content }));
2422
2579
  return;
2423
2580
  }
2424
2581
  const categories = category ? [category] : ["agents", "skills"];
@@ -2444,13 +2601,18 @@ export async function startDashboard(options) {
2444
2601
  items.push({ category: kind, id: name, bytes: info.size });
2445
2602
  }
2446
2603
  }
2447
- response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify(items.sort((a, b) => a.category.localeCompare(b.category) || a.id.localeCompare(b.id))));
2604
+ response
2605
+ .writeHead(200, { "content-type": "application/json; charset=utf-8" })
2606
+ .end(JSON.stringify(items.sort((a, b) => a.category.localeCompare(b.category) || a.id.localeCompare(b.id))));
2448
2607
  return;
2449
2608
  }
2450
2609
  if (requestUrl.pathname === "/api/agents") {
2451
2610
  const agents = await loadAgentRegistry(projectPath);
2452
- response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify(agents.map(agent => ({
2453
- id: agent.id, name: agent.name, description: agent.description, source: agent.source,
2611
+ response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify(agents.map((agent) => ({
2612
+ id: agent.id,
2613
+ name: agent.name,
2614
+ description: agent.description,
2615
+ source: agent.source,
2454
2616
  }))));
2455
2617
  return;
2456
2618
  }
@@ -2461,7 +2623,24 @@ export async function startDashboard(options) {
2461
2623
  }
2462
2624
  if (requestUrl.pathname === "/api/evaluations") {
2463
2625
  const reports = await listEvaluationReports(projectPath);
2464
- response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify(reports.map(report => ({ suiteId: report.suiteId, suiteName: report.suiteName, runId: report.runId, evaluatedAt: report.evaluatedAt, score: report.score, passed: report.passed, summary: report.summary, cases: report.cases.map(item => ({ caseId: item.caseId, agent: item.agent, score: item.score, passed: item.passed, status: item.status })), judge: "judge" in report ? report.judge : null, judgedCases: "judgedCases" in report ? report.judgedCases : [] }))));
2626
+ response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify(reports.map((report) => ({
2627
+ suiteId: report.suiteId,
2628
+ suiteName: report.suiteName,
2629
+ runId: report.runId,
2630
+ evaluatedAt: report.evaluatedAt,
2631
+ score: report.score,
2632
+ passed: report.passed,
2633
+ summary: report.summary,
2634
+ cases: report.cases.map((item) => ({
2635
+ caseId: item.caseId,
2636
+ agent: item.agent,
2637
+ score: item.score,
2638
+ passed: item.passed,
2639
+ status: item.status,
2640
+ })),
2641
+ judge: "judge" in report ? report.judge : null,
2642
+ judgedCases: "judgedCases" in report ? report.judgedCases : [],
2643
+ }))));
2465
2644
  return;
2466
2645
  }
2467
2646
  if (requestUrl.pathname === "/api/benchmarks") {
@@ -2484,7 +2663,11 @@ export async function startDashboard(options) {
2484
2663
  const matrices = await listBenchmarkMatrices(projectPath);
2485
2664
  const suiteId = requestUrl.searchParams.get("suite") ?? undefined;
2486
2665
  const candidateId = requestUrl.searchParams.get("candidate") ?? undefined;
2487
- const report = buildExperimentHistory(matrices, { ...(suiteId ? { suiteId } : {}), ...(candidateId ? { candidateId } : {}), limit: 100 });
2666
+ const report = buildExperimentHistory(matrices, {
2667
+ ...(suiteId ? { suiteId } : {}),
2668
+ ...(candidateId ? { candidateId } : {}),
2669
+ limit: 100,
2670
+ });
2488
2671
  response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify(report));
2489
2672
  return;
2490
2673
  }
@@ -2497,8 +2680,15 @@ export async function startDashboard(options) {
2497
2680
  if (requestUrl.pathname === "/api/agent-performance") {
2498
2681
  const matrices = await listBenchmarkMatrices(projectPath);
2499
2682
  const latest = matrices.at(-1);
2500
- const leaderboard = (latest?.agentSummary ?? []).slice().sort((a, b) => b.averageScore - a.averageScore || b.passRate - a.passRate);
2501
- response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify({ matrixId: latest?.matrixId ?? null, matrixName: latest?.matrixName ?? null, createdAt: latest?.createdAt ?? null, agents: leaderboard }));
2683
+ const leaderboard = (latest?.agentSummary ?? [])
2684
+ .slice()
2685
+ .sort((a, b) => b.averageScore - a.averageScore || b.passRate - a.passRate);
2686
+ response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify({
2687
+ matrixId: latest?.matrixId ?? null,
2688
+ matrixName: latest?.matrixName ?? null,
2689
+ createdAt: latest?.createdAt ?? null,
2690
+ agents: leaderboard,
2691
+ }));
2502
2692
  return;
2503
2693
  }
2504
2694
  if (requestUrl.pathname === "/api/agent-intelligence") {
@@ -2510,7 +2700,7 @@ export async function startDashboard(options) {
2510
2700
  const report = buildAgentEvaluationIntelligence(matrices, {
2511
2701
  ...(suiteId ? { suiteId } : {}),
2512
2702
  ...(candidateId ? { candidateId } : {}),
2513
- ...(limit !== undefined && Number.isSafeInteger(limit) ? { limit } : {})
2703
+ ...(limit !== undefined && Number.isSafeInteger(limit) ? { limit } : {}),
2514
2704
  });
2515
2705
  response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify(report));
2516
2706
  return;
@@ -2525,7 +2715,17 @@ export async function startDashboard(options) {
2525
2715
  const trace = await loadExecutionTrace(projectPath, run.id);
2526
2716
  recent.push({ runId: run.id, createdAt: trace.createdAt, entries: trace.entries.slice(-20) });
2527
2717
  for (const entry of trace.entries) {
2528
- const agent = agents.get(entry.agent) ?? { name: entry.agent, requests: 0, successes: 0, fallbacks: 0, failures: 0, inputTokensEstimate: 0, outputTokensEstimate: 0, durationMs: 0, retries: 0 };
2718
+ const agent = agents.get(entry.agent) ?? {
2719
+ name: entry.agent,
2720
+ requests: 0,
2721
+ successes: 0,
2722
+ fallbacks: 0,
2723
+ failures: 0,
2724
+ inputTokensEstimate: 0,
2725
+ outputTokensEstimate: 0,
2726
+ durationMs: 0,
2727
+ retries: 0,
2728
+ };
2529
2729
  agent.requests += 1;
2530
2730
  agent.successes += entry.outcome === "success" ? 1 : 0;
2531
2731
  agent.fallbacks += entry.outcome === "fallback" ? 1 : 0;
@@ -2535,7 +2735,15 @@ export async function startDashboard(options) {
2535
2735
  agent.durationMs += entry.durationMs;
2536
2736
  agent.retries += entry.retries ?? 0;
2537
2737
  agents.set(entry.agent, agent);
2538
- const provider = providers.get(entry.provider) ?? { name: entry.provider, requests: 0, successes: 0, fallbacks: 0, failures: 0, durationMs: 0, retries: 0 };
2738
+ const provider = providers.get(entry.provider) ?? {
2739
+ name: entry.provider,
2740
+ requests: 0,
2741
+ successes: 0,
2742
+ fallbacks: 0,
2743
+ failures: 0,
2744
+ durationMs: 0,
2745
+ retries: 0,
2746
+ };
2539
2747
  provider.requests += 1;
2540
2748
  provider.successes += entry.outcome === "success" ? 1 : 0;
2541
2749
  provider.fallbacks += entry.outcome === "fallback" ? 1 : 0;
@@ -2550,15 +2758,40 @@ export async function startDashboard(options) {
2550
2758
  throw error;
2551
2759
  }
2552
2760
  }
2553
- const parseBudgetMap = (raw) => { if (!raw)
2554
- return {}; try {
2555
- const value = JSON.parse(raw);
2556
- return value && typeof value === "object" && !Array.isArray(value) ? Object.fromEntries(Object.entries(value).filter((item) => typeof item[1] === "number" && Number.isFinite(item[1]) && item[1] > 0)) : {};
2557
- }
2558
- catch {
2559
- return {};
2560
- } };
2561
- response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify({ generatedAt: new Date().toISOString(), runsScanned: runs.slice(0, 30).length, totals: { requests: [...agents.values()].reduce((n, a) => n + a.requests, 0), inputTokensEstimate: [...agents.values()].reduce((n, a) => n + a.inputTokensEstimate, 0), outputTokensEstimate: [...agents.values()].reduce((n, a) => n + a.outputTokensEstimate, 0), durationMs: [...agents.values()].reduce((n, a) => n + a.durationMs, 0), failures: [...agents.values()].reduce((n, a) => n + a.failures, 0), fallbacks: [...agents.values()].reduce((n, a) => n + a.fallbacks, 0) }, agents: [...agents.values()].sort((a, b) => b.durationMs - a.durationMs), providers: [...providers.values()].sort((a, b) => b.requests - a.requests), budgets: { perAgentTokens: parseBudgetMap(process.env.ANVIL_MAX_ESTIMATED_TOKENS_PER_AGENT || process.env.FORGE_MAX_ESTIMATED_TOKENS_PER_AGENT), perAgentDurationMs: parseBudgetMap(process.env.ANVIL_MAX_TASK_DURATION_MS_BY_AGENT || process.env.FORGE_MAX_TASK_DURATION_MS_BY_AGENT), runTokens: Number(process.env.ANVIL_MAX_ESTIMATED_TOKENS_PER_RUN || process.env.FORGE_MAX_ESTIMATED_TOKENS_PER_RUN) || null, taskDurationMs: Number(process.env.ANVIL_MAX_TASK_DURATION_MS || process.env.FORGE_MAX_TASK_DURATION_MS) || null }, recent }));
2761
+ const parseBudgetMap = (raw) => {
2762
+ if (!raw)
2763
+ return {};
2764
+ try {
2765
+ const value = JSON.parse(raw);
2766
+ return value && typeof value === "object" && !Array.isArray(value)
2767
+ ? Object.fromEntries(Object.entries(value).filter((item) => typeof item[1] === "number" && Number.isFinite(item[1]) && item[1] > 0))
2768
+ : {};
2769
+ }
2770
+ catch {
2771
+ return {};
2772
+ }
2773
+ };
2774
+ response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify({
2775
+ generatedAt: new Date().toISOString(),
2776
+ runsScanned: runs.slice(0, 30).length,
2777
+ totals: {
2778
+ requests: [...agents.values()].reduce((n, a) => n + a.requests, 0),
2779
+ inputTokensEstimate: [...agents.values()].reduce((n, a) => n + a.inputTokensEstimate, 0),
2780
+ outputTokensEstimate: [...agents.values()].reduce((n, a) => n + a.outputTokensEstimate, 0),
2781
+ durationMs: [...agents.values()].reduce((n, a) => n + a.durationMs, 0),
2782
+ failures: [...agents.values()].reduce((n, a) => n + a.failures, 0),
2783
+ fallbacks: [...agents.values()].reduce((n, a) => n + a.fallbacks, 0),
2784
+ },
2785
+ agents: [...agents.values()].sort((a, b) => b.durationMs - a.durationMs),
2786
+ providers: [...providers.values()].sort((a, b) => b.requests - a.requests),
2787
+ budgets: {
2788
+ perAgentTokens: parseBudgetMap(process.env.ANVIL_MAX_ESTIMATED_TOKENS_PER_AGENT || process.env.FORGE_MAX_ESTIMATED_TOKENS_PER_AGENT),
2789
+ perAgentDurationMs: parseBudgetMap(process.env.ANVIL_MAX_TASK_DURATION_MS_BY_AGENT || process.env.FORGE_MAX_TASK_DURATION_MS_BY_AGENT),
2790
+ runTokens: Number(process.env.ANVIL_MAX_ESTIMATED_TOKENS_PER_RUN || process.env.FORGE_MAX_ESTIMATED_TOKENS_PER_RUN) || null,
2791
+ taskDurationMs: Number(process.env.ANVIL_MAX_TASK_DURATION_MS || process.env.FORGE_MAX_TASK_DURATION_MS) || null,
2792
+ },
2793
+ recent,
2794
+ }));
2562
2795
  return;
2563
2796
  }
2564
2797
  const traceRoute = requestUrl.pathname.match(/^\/api\/runs\/([^/]+)\/trace$/);
@@ -2569,7 +2802,9 @@ export async function startDashboard(options) {
2569
2802
  }
2570
2803
  catch (error) {
2571
2804
  if (error && typeof error === "object" && "code" in error && error.code === "ENOENT") {
2572
- response.writeHead(404, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify({ error: "No execution trace has been saved for this run." }));
2805
+ response
2806
+ .writeHead(404, { "content-type": "application/json; charset=utf-8" })
2807
+ .end(JSON.stringify({ error: "No execution trace has been saved for this run." }));
2573
2808
  return;
2574
2809
  }
2575
2810
  throw error;
@@ -2580,24 +2815,51 @@ export async function startDashboard(options) {
2580
2815
  const runId = decodeURIComponent(requestUrl.pathname.slice("/api/runs/".length));
2581
2816
  const run = await loadRun(projectPath, runId);
2582
2817
  response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify({
2583
- id: run.id, goal: run.goal, status: run.status, createdAt: run.createdAt, updatedAt: run.updatedAt,
2584
- tasks: run.tasks.map(record => ({
2585
- id: record.task.id, title: record.task.title, agent: record.task.agent, status: record.status,
2818
+ id: run.id,
2819
+ goal: run.goal,
2820
+ status: run.status,
2821
+ createdAt: run.createdAt,
2822
+ updatedAt: run.updatedAt,
2823
+ tasks: run.tasks.map((record) => ({
2824
+ id: record.task.id,
2825
+ title: record.task.title,
2826
+ agent: record.task.agent,
2827
+ status: record.status,
2586
2828
  dependsOn: record.task.dependsOn ?? [],
2587
- result: record.result ? { provider: record.result.provider, model: record.result.model, content: record.result.content } : undefined,
2829
+ result: record.result
2830
+ ? { provider: record.result.provider, model: record.result.model, content: record.result.content }
2831
+ : undefined,
2588
2832
  error: record.error,
2589
2833
  approval: record.approval,
2590
2834
  })),
2591
- events: run.events.map(event => ({ at: event.at, taskId: event.taskId, type: event.type, message: event.message })),
2835
+ events: run.events.map((event) => ({
2836
+ at: event.at,
2837
+ taskId: event.taskId,
2838
+ type: event.type,
2839
+ message: event.message,
2840
+ })),
2592
2841
  }));
2593
2842
  return;
2594
2843
  }
2595
2844
  if (requestUrl.pathname === "/api/runs") {
2596
2845
  const runs = await listRuns(projectPath);
2597
- response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify(runs.map(run => ({
2598
- id: run.id, goal: run.goal, status: run.status, createdAt: run.createdAt,
2599
- tasks: run.tasks.map(task => ({ id: task.task.id, title: task.task.title, agent: task.task.agent, status: task.status })),
2600
- events: run.events.map(event => ({ at: event.at, taskId: event.taskId, type: event.type, message: event.message })),
2846
+ response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify(runs.map((run) => ({
2847
+ id: run.id,
2848
+ goal: run.goal,
2849
+ status: run.status,
2850
+ createdAt: run.createdAt,
2851
+ tasks: run.tasks.map((task) => ({
2852
+ id: task.task.id,
2853
+ title: task.task.title,
2854
+ agent: task.task.agent,
2855
+ status: task.status,
2856
+ })),
2857
+ events: run.events.map((event) => ({
2858
+ at: event.at,
2859
+ taskId: event.taskId,
2860
+ type: event.type,
2861
+ message: event.message,
2862
+ })),
2601
2863
  }))));
2602
2864
  return;
2603
2865
  }
@@ -2609,25 +2871,45 @@ export async function startDashboard(options) {
2609
2871
  if (requestUrl.pathname === "/api/quality") {
2610
2872
  const report = await auditProject(projectPath);
2611
2873
  response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify({
2612
- score: report.score, grade: report.grade, generatedAt: report.generatedAt, metrics: report.metrics,
2613
- findings: report.findings.map(item => ({ id: item.id, severity: item.severity, title: item.title, recommendation: item.recommendation })),
2874
+ score: report.score,
2875
+ grade: report.grade,
2876
+ generatedAt: report.generatedAt,
2877
+ metrics: report.metrics,
2878
+ findings: report.findings.map((item) => ({
2879
+ id: item.id,
2880
+ severity: item.severity,
2881
+ title: item.title,
2882
+ recommendation: item.recommendation,
2883
+ })),
2614
2884
  }));
2615
2885
  return;
2616
2886
  }
2617
2887
  if (requestUrl.pathname === "/api/verifications") {
2618
2888
  const history = await listVerifications(projectPath, 25);
2619
- response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify(history.map(item => ({
2620
- id: item.id, script: item.script, status: item.status, exitCode: item.exitCode, durationMs: item.durationMs, startedAt: item.startedAt, finishedAt: item.finishedAt,
2889
+ response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify(history.map((item) => ({
2890
+ id: item.id,
2891
+ script: item.script,
2892
+ status: item.status,
2893
+ exitCode: item.exitCode,
2894
+ durationMs: item.durationMs,
2895
+ startedAt: item.startedAt,
2896
+ finishedAt: item.finishedAt,
2621
2897
  }))));
2622
2898
  return;
2623
2899
  }
2624
2900
  if (requestUrl.pathname === "/api/reviews") {
2625
2901
  const records = await listReviews(projectPath);
2626
- response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify(records.slice(0, 50).map(record => ({
2627
- id: record.id, createdAt: record.createdAt, scope: record.report.scope,
2628
- filesReviewed: record.report.filesReviewed.length, staticFindings: record.report.findings.length,
2902
+ response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify(records.slice(0, 50).map((record) => ({
2903
+ id: record.id,
2904
+ createdAt: record.createdAt,
2905
+ scope: record.report.scope,
2906
+ filesReviewed: record.report.filesReviewed.length,
2907
+ staticFindings: record.report.findings.length,
2629
2908
  aiSuggestions: record.ai?.suggestions.length ?? 0,
2630
- topFindings: [...record.report.findings.slice(0, 3).map(item => item.title), ...(record.ai?.suggestions.slice(0, 2).map(item => item.title) ?? [])],
2909
+ topFindings: [
2910
+ ...record.report.findings.slice(0, 3).map((item) => item.title),
2911
+ ...(record.ai?.suggestions.slice(0, 2).map((item) => item.title) ?? []),
2912
+ ],
2631
2913
  }))));
2632
2914
  return;
2633
2915
  }
@@ -2663,9 +2945,12 @@ export async function startDashboard(options) {
2663
2945
  }
2664
2946
  if (requestUrl.pathname === "/api/intelligence-timeline") {
2665
2947
  const [comparison, snapshots] = await Promise.all([
2666
- compareLatestIntelligence(projectPath), listIntelligenceSnapshots(projectPath)
2948
+ compareLatestIntelligence(projectPath),
2949
+ listIntelligenceSnapshots(projectPath),
2667
2950
  ]);
2668
- response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify({ comparison, snapshots }));
2951
+ response
2952
+ .writeHead(200, { "content-type": "application/json; charset=utf-8" })
2953
+ .end(JSON.stringify({ comparison, snapshots }));
2669
2954
  return;
2670
2955
  }
2671
2956
  if (requestUrl.pathname === "/api/change-intelligence") {
@@ -2694,10 +2979,7 @@ export async function startDashboard(options) {
2694
2979
  return;
2695
2980
  }
2696
2981
  if (requestUrl.pathname === "/api/clean/snapshots") {
2697
- const backupDirs = [
2698
- path.join(projectPath, ".anvil", "backups"),
2699
- path.join(projectPath, ".forge", "backups")
2700
- ];
2982
+ const backupDirs = [path.join(projectPath, ".anvil", "backups"), path.join(projectPath, ".forge", "backups")];
2701
2983
  const snapshots = [];
2702
2984
  for (const dir of backupDirs) {
2703
2985
  try {
@@ -2711,7 +2993,7 @@ export async function startDashboard(options) {
2711
2993
  snapshots.push({
2712
2994
  id: entry.name,
2713
2995
  at: data.timestamp || new Date().toISOString(),
2714
- files: Array.isArray(data.files) ? data.files.length : 0
2996
+ files: Array.isArray(data.files) ? data.files.length : 0,
2715
2997
  });
2716
2998
  }
2717
2999
  catch {
@@ -2722,7 +3004,9 @@ export async function startDashboard(options) {
2722
3004
  }
2723
3005
  catch { }
2724
3006
  }
2725
- response.writeHead(200, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify({ snapshots: snapshots.sort((a, b) => b.at.localeCompare(a.at)) }));
3007
+ response
3008
+ .writeHead(200, { "content-type": "application/json; charset=utf-8" })
3009
+ .end(JSON.stringify({ snapshots: snapshots.sort((a, b) => b.at.localeCompare(a.at)) }));
2726
3010
  return;
2727
3011
  }
2728
3012
  if (requestUrl.pathname === "/api/memory") {
@@ -2749,7 +3033,9 @@ export async function startDashboard(options) {
2749
3033
  }
2750
3034
  catch (error) {
2751
3035
  const message = error instanceof Error ? error.message : "Unexpected dashboard error.";
2752
- response.writeHead(500, { "content-type": "application/json; charset=utf-8" }).end(JSON.stringify({ error: message }));
3036
+ response
3037
+ .writeHead(500, { "content-type": "application/json; charset=utf-8" })
3038
+ .end(JSON.stringify({ error: message }));
2753
3039
  }
2754
3040
  });
2755
3041
  await new Promise((resolve, reject) => {