substrate-ai 0.16.5 → 0.16.7

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/dist/cli/index.js CHANGED
@@ -4,7 +4,7 @@ import { createLogger } from "../logger-KeHncl-f.js";
4
4
  import { createEventBus } from "../helpers-CElYrONe.js";
5
5
  import { AdapterRegistry, BudgetConfigSchema, CURRENT_CONFIG_FORMAT_VERSION, CURRENT_TASK_GRAPH_VERSION, ConfigError, CostTrackerConfigSchema, DEFAULT_CONFIG, DoltClient, DoltNotInstalled, EXPERIMENT_RESULT, GlobalSettingsSchema, IngestionServer, MonitorDatabaseImpl, OPERATIONAL_FINDING, PartialGlobalSettingsSchema, PartialProviderConfigSchema, ProvidersSchema, RoutingRecommender, STORY_METRICS, TelemetryConfigSchema, addTokenUsage, aggregateTokenUsageForRun, checkDoltInstalled, compareRunMetrics, createAmendmentRun, createConfigSystem, createDecision, createDoltClient, createPipelineRun, getActiveDecisions, getAllCostEntriesFiltered, getBaselineRunMetrics, getDecisionsByCategory, getDecisionsByPhaseForRun, getLatestCompletedRun, getLatestRun, getPipelineRunById, getPlanningCostTotal, getRetryableEscalations, getRunMetrics, getSessionCostSummary, getSessionCostSummaryFiltered, getStoryMetricsForRun, getTokenUsageSummary, incrementRunRestarts, initSchema, initializeDolt, listRequirements, listRunMetrics, loadParentRunDecisions, supersedeDecision, tagRunAsBaseline, updatePipelineRun } from "../dist-CLvAwmT7.js";
6
6
  import "../adapter-registry-DXLMTmfD.js";
7
- import { AdapterTelemetryPersistence, AppError, DoltRepoMapMetaRepository, DoltSymbolRepository, ERR_REPO_MAP_STORAGE_WRITE, GitClient, GrammarLoader, RepoMapInjector, RepoMapModule, RepoMapQueryEngine, RepoMapStorage, SymbolParser, createContextCompiler, createDispatcher, createEventEmitter, createImplementationOrchestrator, createPackLoader, createPhaseOrchestrator, createStopAfterGate, createTelemetryAdvisor, formatPhaseCompletionSummary, getFactoryRunSummaries, getScenarioResultsForRun, getTwinRunsForRun, listGraphRuns, registerFactoryCommand, registerRunCommand, registerScenariosCommand, resolveStoryKeys, runAnalysisPhase, runPlanningPhase, runSolutioningPhase, validateStopAfterFromConflict } from "../run-3sUmDFaj.js";
7
+ import { AdapterTelemetryPersistence, AppError, DoltRepoMapMetaRepository, DoltSymbolRepository, ERR_REPO_MAP_STORAGE_WRITE, GitClient, GrammarLoader, RepoMapInjector, RepoMapModule, RepoMapQueryEngine, RepoMapStorage, SymbolParser, createContextCompiler, createDispatcher, createEventEmitter, createImplementationOrchestrator, createPackLoader, createPhaseOrchestrator, createStopAfterGate, createTelemetryAdvisor, formatPhaseCompletionSummary, getFactoryRunSummaries, getScenarioResultsForRun, getTwinRunsForRun, listGraphRuns, registerFactoryCommand, registerRunCommand, registerScenariosCommand, resolveStoryKeys, runAnalysisPhase, runPlanningPhase, runSolutioningPhase, validateStopAfterFromConflict } from "../run-BEWyyN-c.js";
8
8
  import "../errors-D1LU8CZ9.js";
9
9
  import "../routing-CcBOCuC9.js";
10
10
  import "../decisions-C0pz9Clx.js";
@@ -4359,7 +4359,7 @@ async function runSupervisorAction(options, deps = {}) {
4359
4359
  await initSchema(expAdapter);
4360
4360
  const { runRunAction: runPipeline } = await import(
4361
4361
  /* @vite-ignore */
4362
- "../run-CxN4St_1.js"
4362
+ "../run-BUMbrMA_.js"
4363
4363
  );
4364
4364
  const runStoryFn = async (opts) => {
4365
4365
  const exitCode = await runPipeline({
@@ -16648,20 +16648,63 @@ function createSdlcPhaseHandler(deps) {
16648
16648
  };
16649
16649
  const runId = context.getString("runId");
16650
16650
  const concept = phaseName === "analysis" ? context.getString("concept", "") : "";
16651
+ const PRE_IMPL_PHASES = [
16652
+ "analysis",
16653
+ "planning",
16654
+ "solutioning"
16655
+ ];
16656
+ const storyKey = context.getString("storyKey", "");
16657
+ if (storyKey && PRE_IMPL_PHASES.includes(phaseName)) return {
16658
+ status: "SUCCESS",
16659
+ notes: `Phase ${phaseName} skipped — explicit story dispatch (storyKey=${storyKey})`
16660
+ };
16651
16661
  const PHASE_ARTIFACT_TYPES = {
16652
- analysis: "product-brief",
16653
- planning: "prd",
16654
- solutioning: "stories"
16662
+ analysis: ["product-brief"],
16663
+ planning: ["prd"],
16664
+ solutioning: ["architecture", "stories"]
16655
16665
  };
16656
- const artifactType = PHASE_ARTIFACT_TYPES[phaseName];
16657
- if (artifactType !== void 0) try {
16666
+ const artifactTypes = PHASE_ARTIFACT_TYPES[phaseName];
16667
+ if (artifactTypes !== void 0) try {
16658
16668
  const db = deps.phaseDeps.db;
16659
16669
  if (db) {
16660
- const rows = await db.query("SELECT id FROM artifacts WHERE phase = ? AND type = ? LIMIT 1", [phaseName, artifactType]);
16661
- if (Array.isArray(rows) && rows.length > 0) return {
16662
- status: "SUCCESS",
16663
- notes: `Phase ${phaseName} already complete artifact '${artifactType}' exists, skipping dispatch`
16664
- };
16670
+ let allExist = true;
16671
+ for (const at of artifactTypes) {
16672
+ const rows = await db.query("SELECT id, path, content_hash, summary FROM artifacts WHERE phase = ? AND type = ? ORDER BY created_at DESC LIMIT 1", [phaseName, at]);
16673
+ if (!Array.isArray(rows) || rows.length === 0) {
16674
+ allExist = false;
16675
+ break;
16676
+ }
16677
+ }
16678
+ if (allExist) {
16679
+ const pipelineRunId = context.getString("pipelineRunId", "");
16680
+ if (pipelineRunId) for (const at of artifactTypes) {
16681
+ const existing = await db.query("SELECT id, path, content_hash, summary FROM artifacts WHERE phase = ? AND type = ? ORDER BY created_at DESC LIMIT 1", [phaseName, at]);
16682
+ const src = existing[0];
16683
+ if (src) {
16684
+ const alreadyRegistered = await db.query("SELECT id FROM artifacts WHERE pipeline_run_id = ? AND phase = ? AND type = ? LIMIT 1", [
16685
+ pipelineRunId,
16686
+ phaseName,
16687
+ at
16688
+ ]);
16689
+ if (!Array.isArray(alreadyRegistered) || alreadyRegistered.length === 0) {
16690
+ const newId = crypto.randomUUID();
16691
+ await db.query("INSERT INTO artifacts (id, pipeline_run_id, phase, type, path, content_hash, summary) VALUES (?, ?, ?, ?, ?, ?, ?)", [
16692
+ newId,
16693
+ pipelineRunId,
16694
+ phaseName,
16695
+ at,
16696
+ src.path,
16697
+ src.content_hash ?? null,
16698
+ src.summary ?? null
16699
+ ]);
16700
+ }
16701
+ }
16702
+ }
16703
+ return {
16704
+ status: "SUCCESS",
16705
+ notes: `Phase ${phaseName} already complete — artifact(s) exist, skipping dispatch`
16706
+ };
16707
+ }
16665
16708
  }
16666
16709
  } catch {}
16667
16710
  const params = phaseName === "analysis" ? {
@@ -17095,8 +17138,10 @@ function createGraphOrchestrator(config) {
17095
17138
  if (!config.graph?.nodes || !config.graph?.edges) throw new GraphOrchestratorInitError("Invalid graph: missing nodes or edges arrays");
17096
17139
  const gcPauseMs = config.gcPauseMs ?? 2e3;
17097
17140
  async function runStoryGraph(storyKey, summary) {
17141
+ const epicId = storyKey.split("-")[0] ?? "";
17098
17142
  const initialContext = {
17099
17143
  storyKey,
17144
+ epicId,
17100
17145
  projectRoot: config.projectRoot,
17101
17146
  methodologyPack: config.methodologyPack,
17102
17147
  ...config.pipelineRunId !== void 0 ? {
@@ -17126,6 +17171,7 @@ function createGraphOrchestrator(config) {
17126
17171
  });
17127
17172
  } catch (err) {
17128
17173
  const errMsg = err instanceof Error ? err.message : String(err);
17174
+ process.stderr.write(`[graph-orchestrator] Story ${storyKey} failed: ${errMsg}\n`);
17129
17175
  summary.stories[storyKey] = {
17130
17176
  outcome: escalated ? "ESCALATED" : "FAILED",
17131
17177
  error: errMsg
@@ -17142,7 +17188,12 @@ function createGraphOrchestrator(config) {
17142
17188
  summary.stories[storyKey] = { outcome: "ESCALATED" };
17143
17189
  summary.f++;
17144
17190
  } else {
17145
- summary.stories[storyKey] = { outcome: "FAILED" };
17191
+ const reason = result.failureReason ?? `status=${result.status}`;
17192
+ process.stderr.write(`[graph-orchestrator] Story ${storyKey} failed: ${reason}\n`);
17193
+ summary.stories[storyKey] = {
17194
+ outcome: "FAILED",
17195
+ error: reason
17196
+ };
17146
17197
  summary.f++;
17147
17198
  }
17148
17199
  }
@@ -22987,13 +23038,17 @@ function createGraphExecutor() {
22987
23038
  total_cost_usd: pipelineManager.getTotalCost(),
22988
23039
  node_count: graph.nodes.size
22989
23040
  });
22990
- } catch {}
23041
+ } catch (persistErr) {
23042
+ const msg = persistErr instanceof Error ? persistErr.message : String(persistErr);
23043
+ console.warn(`[executor] graph_runs upsert failed for run ${config.runId}: ${msg}`);
23044
+ }
22991
23045
  };
22992
23046
  let completedNodes = [];
22993
23047
  let nodeRetries = {};
22994
23048
  let context = new GraphContext(config.initialContext);
22995
23049
  let step = 0;
22996
23050
  const visitCount = new Map();
23051
+ const failRouteCount = new Map();
22997
23052
  let resumeCompletedSet = null;
22998
23053
  let firstResumedFidelity = "";
22999
23054
  let skipCycleCheck = false;
@@ -23021,7 +23076,7 @@ function createGraphExecutor() {
23021
23076
  executed_at: new Date().toISOString()
23022
23077
  }).catch((err) => {
23023
23078
  const msg = err instanceof Error ? err.message : String(err);
23024
- console.debug(`[executor] scenario:completed persistence failed for run ${config.runId}: ${msg}`);
23079
+ console.warn(`[executor] scenario_results persistence failed for run ${config.runId}: ${msg}`);
23025
23080
  });
23026
23081
  };
23027
23082
  config.eventBus.on("scenario:completed", scenarioHandler);
@@ -23035,7 +23090,10 @@ function createGraphExecutor() {
23035
23090
  started_at: runStartedAt,
23036
23091
  node_count: graph.nodes.size
23037
23092
  });
23038
- } catch {}
23093
+ } catch (persistErr) {
23094
+ const msg = persistErr instanceof Error ? persistErr.message : String(persistErr);
23095
+ console.warn(`[executor] graph_runs insert failed for run ${config.runId}: ${msg}`);
23096
+ }
23039
23097
  let currentNode;
23040
23098
  if (config.checkpointPath) {
23041
23099
  const checkpoint = await checkpointManager.load(config.checkpointPath);
@@ -23248,6 +23306,7 @@ function createGraphExecutor() {
23248
23306
  controller.recordOutcome(nodeToDispatch.id, controllerStatus);
23249
23307
  }
23250
23308
  if (outcome.contextUpdates) for (const [key, value] of Object.entries(outcome.contextUpdates)) context.set(key, value);
23309
+ context.set("outcome", outcome.status.toLowerCase());
23251
23310
  const nodeCost = context.getNumber("factory.lastNodeCostUsd", 0);
23252
23311
  if (nodeCost > 0) pipelineManager.addCost(nodeCost);
23253
23312
  if (config.adapter) {
@@ -23264,7 +23323,10 @@ function createGraphExecutor() {
23264
23323
  cost_usd: nodeCost,
23265
23324
  ...outcome.failureReason !== void 0 ? { failure_reason: outcome.failureReason } : {}
23266
23325
  });
23267
- } catch {}
23326
+ } catch (persistErr) {
23327
+ const msg = persistErr instanceof Error ? persistErr.message : String(persistErr);
23328
+ console.warn(`[executor] graph_node_results insert failed for node ${currentNode.id}: ${msg}`);
23329
+ }
23268
23330
  }
23269
23331
  if (!skipCompletedPush) completedNodes.push(currentNode.id);
23270
23332
  skipCompletedPush = false;
@@ -23288,11 +23350,24 @@ function createGraphExecutor() {
23288
23350
  currentNode = retryNode;
23289
23351
  continue;
23290
23352
  }
23291
- await persistExit("failed", outcome.failureReason ?? "FAIL");
23292
- return {
23293
- status: "FAIL",
23294
- ...outcome.failureReason !== void 0 && { failureReason: outcome.failureReason }
23295
- };
23353
+ const outgoing = graph.edges.filter((e) => e.fromNode === currentNode.id);
23354
+ const hasConditionalEdge = outgoing.some((e) => e.condition && e.condition.trim() !== "");
23355
+ if (!hasConditionalEdge) {
23356
+ await persistExit("failed", outcome.failureReason ?? "FAIL");
23357
+ return {
23358
+ status: "FAIL",
23359
+ ...outcome.failureReason !== void 0 && { failureReason: outcome.failureReason }
23360
+ };
23361
+ }
23362
+ const routeCount = (failRouteCount.get(currentNode.id) ?? 0) + 1;
23363
+ failRouteCount.set(currentNode.id, routeCount);
23364
+ if (routeCount > Math.max(graph.defaultMaxRetries || 0, 3)) {
23365
+ await persistExit("failed", outcome.failureReason ?? "FAIL");
23366
+ return {
23367
+ status: "FAIL",
23368
+ ...outcome.failureReason !== void 0 && { failureReason: outcome.failureReason }
23369
+ };
23370
+ }
23296
23371
  }
23297
23372
  const edge = selectEdge(currentNode, outcome, context, graph);
23298
23373
  if (!edge) {
@@ -29287,6 +29362,10 @@ function registerFactoryCommand(program, options) {
29287
29362
  type: "graph:completed",
29288
29363
  ...e
29289
29364
  }));
29365
+ eventBus.on("factory:config-reloaded", (e) => emit({
29366
+ type: "factory:config-reloaded",
29367
+ ...e
29368
+ }));
29290
29369
  }
29291
29370
  process.stdout.write(`Running graph pipeline from ${graphPath}\n`);
29292
29371
  const runId = randomUUID();
@@ -29326,6 +29405,11 @@ function registerFactoryCommand(program, options) {
29326
29405
  const oldThreshold = executorConfig.satisfactionThreshold;
29327
29406
  executorConfig.satisfactionThreshold = newThreshold;
29328
29407
  process.stderr.write(`[hot-reload] satisfaction_threshold changed: ${oldThreshold} → ${newThreshold}\n`);
29408
+ eventBus.emit("factory:config-reloaded", {
29409
+ key: "satisfaction_threshold",
29410
+ oldValue: oldThreshold,
29411
+ newValue: newThreshold
29412
+ });
29329
29413
  }
29330
29414
  } catch {}
29331
29415
  });
@@ -31023,4 +31107,4 @@ function registerRunCommand(program, _version = "0.0.0", projectRoot = process.c
31023
31107
 
31024
31108
  //#endregion
31025
31109
  export { AdapterTelemetryPersistence, AppError, DoltRepoMapMetaRepository, DoltSymbolRepository, ERR_REPO_MAP_STORAGE_WRITE, GitClient, GrammarLoader, RepoMapInjector, RepoMapModule, RepoMapQueryEngine, RepoMapStorage, SymbolParser, createContextCompiler, createDispatcher, createEventEmitter, createImplementationOrchestrator, createPackLoader, createPhaseOrchestrator, createStopAfterGate, createTelemetryAdvisor, formatPhaseCompletionSummary, getFactoryRunSummaries, getScenarioResultsForRun, getTwinRunsForRun, listGraphRuns, normalizeGraphSummaryToStatus, registerFactoryCommand, registerRunCommand, registerScenariosCommand, resolveStoryKeys, runAnalysisPhase, runPlanningPhase, runRunAction, runSolutioningPhase, validateStopAfterFromConflict };
31026
- //# sourceMappingURL=run-3sUmDFaj.js.map
31110
+ //# sourceMappingURL=run-BEWyyN-c.js.map
@@ -2,7 +2,7 @@ import "./health-DswaC1q5.js";
2
2
  import "./logger-KeHncl-f.js";
3
3
  import "./helpers-CElYrONe.js";
4
4
  import "./dist-CLvAwmT7.js";
5
- import { normalizeGraphSummaryToStatus, registerRunCommand, runRunAction } from "./run-3sUmDFaj.js";
5
+ import { normalizeGraphSummaryToStatus, registerRunCommand, runRunAction } from "./run-BEWyyN-c.js";
6
6
  import "./routing-CcBOCuC9.js";
7
7
  import "./decisions-C0pz9Clx.js";
8
8
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "substrate-ai",
3
- "version": "0.16.5",
3
+ "version": "0.16.7",
4
4
  "description": "Substrate — multi-agent orchestration daemon for AI coding agents",
5
5
  "type": "module",
6
6
  "license": "MIT",