substrate-ai 0.2.8 → 0.2.9

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
@@ -2,7 +2,7 @@
2
2
  import { createLogger, deepMask } from "../logger-C6n1g8uP.js";
3
3
  import { AdapterRegistry, createEventBus } from "../event-bus-J-bw-pkp.js";
4
4
  import { CURRENT_CONFIG_FORMAT_VERSION, CURRENT_TASK_GRAPH_VERSION, PartialSubstrateConfigSchema, SUPPORTED_CONFIG_FORMAT_VERSIONS, SubstrateConfigSchema, defaultConfigMigrator } from "../version-manager-impl-BpVx2DkY.js";
5
- import { DatabaseWrapper, SUBSTRATE_OWNED_SETTINGS_KEYS, VALID_PHASES, buildPipelineStatusOutput, createContextCompiler, createDispatcher, createImplementationOrchestrator, createPackLoader, createPhaseOrchestrator, createStopAfterGate, findPackageRoot, formatOutput, formatPhaseCompletionSummary, formatPipelineStatusHuman, formatPipelineSummary, formatTokenTelemetry, getSubstrateDefaultSettings, parseDbTimestampAsUtc, registerRunCommand, resolveBmadMethodSrcPath, resolveBmadMethodVersion, resolveMainRepoRoot, runAnalysisPhase, runMigrations, runPlanningPhase, runSolutioningPhase, validateStopAfterFromConflict } from "../run-DbRH_r_-.js";
5
+ import { DatabaseWrapper, SUBSTRATE_OWNED_SETTINGS_KEYS, VALID_PHASES, buildPipelineStatusOutput, createContextCompiler, createDispatcher, createImplementationOrchestrator, createPackLoader, createPhaseOrchestrator, createStopAfterGate, findPackageRoot, formatOutput, formatPhaseCompletionSummary, formatPipelineStatusHuman, formatPipelineSummary, formatTokenTelemetry, getSubstrateDefaultSettings, parseDbTimestampAsUtc, registerRunCommand, resolveBmadMethodSrcPath, resolveBmadMethodVersion, resolveMainRepoRoot, runAnalysisPhase, runMigrations, runPlanningPhase, runSolutioningPhase, validateStopAfterFromConflict } from "../run-Bh7VhhyX.js";
6
6
  import { ConfigError, ConfigIncompatibleFormatError } from "../errors-BPqtzQ4U.js";
7
7
  import { addTokenUsage, createDecision, getDecisionsByPhaseForRun, getLatestRun, getPipelineRunById, getTokenUsageSummary, listRequirements, updatePipelineRun } from "../decisions-DNYByk0U.js";
8
8
  import { aggregateTokenUsageForRun, compareRunMetrics, getBaselineRunMetrics, getRunMetrics, getStoryMetricsForRun, incrementRunRestarts, listRunMetrics, tagRunAsBaseline } from "../metrics-BSg8VIHd.js";
@@ -2833,7 +2833,7 @@ async function runSupervisorAction(options, deps = {}) {
2833
2833
  const expDb = expDbWrapper.db;
2834
2834
  const { runRunAction: runPipeline } = await import(
2835
2835
  /* @vite-ignore */
2836
- "../run-aGFwcIFG.js"
2836
+ "../run-p1rj6v-u.js"
2837
2837
  );
2838
2838
  const runStoryFn = async (opts) => {
2839
2839
  const exitCode = await runPipeline({
@@ -8,12 +8,12 @@ import { existsSync, mkdirSync, readFileSync } from "fs";
8
8
  import yaml from "js-yaml";
9
9
  import { createRequire } from "node:module";
10
10
  import { z } from "zod";
11
- import { spawn } from "node:child_process";
11
+ import { execSync, spawn } from "node:child_process";
12
12
  import { dirname as dirname$1, join as join$1, resolve as resolve$1 } from "node:path";
13
13
  import BetterSqlite3 from "better-sqlite3";
14
14
  import { fileURLToPath } from "node:url";
15
15
  import { existsSync as existsSync$1, readFileSync as readFileSync$1, readdirSync as readdirSync$1 } from "node:fs";
16
- import { freemem } from "node:os";
16
+ import { freemem, platform } from "node:os";
17
17
  import { randomUUID } from "node:crypto";
18
18
  import { readFile as readFile$1, stat as stat$1 } from "node:fs/promises";
19
19
 
@@ -2843,6 +2843,50 @@ const SHUTDOWN_MAX_WAIT_MS = 3e4;
2843
2843
  const CHARS_PER_TOKEN = 4;
2844
2844
  const MIN_FREE_MEMORY_BYTES = 512 * 1024 * 1024;
2845
2845
  const MEMORY_PRESSURE_POLL_MS = 1e4;
2846
+ /**
2847
+ * Get available system memory in bytes, accounting for platform differences.
2848
+ *
2849
+ * On macOS, the previous approach (free + inactive pages) dramatically
2850
+ * overestimates availability because inactive pages may be compressed,
2851
+ * swapped, or require I/O to reclaim. With heavy agent concurrency, this
2852
+ * leads to spawning too many processes and triggering real memory pressure.
2853
+ *
2854
+ * New approach:
2855
+ * 1. Check kern.memorystatus_vm_pressure_level — the kernel's own assessment.
2856
+ * Level >= 2 (warn/critical) means the system is already pressured.
2857
+ * 2. Use a conservative page calculation: free + purgeable + speculative.
2858
+ * These categories are truly reclaimable without I/O or decompression.
2859
+ * Inactive pages are excluded because they may require disk I/O,
2860
+ * decompression, or may already be backing the compressor.
2861
+ */
2862
+ function getAvailableMemory() {
2863
+ if (platform() === "darwin") {
2864
+ try {
2865
+ const pressureLevel = parseInt(execSync("sysctl -n kern.memorystatus_vm_pressure_level", {
2866
+ timeout: 1e3,
2867
+ encoding: "utf-8"
2868
+ }).trim(), 10);
2869
+ if (pressureLevel >= 2) {
2870
+ logger$12.warn({ pressureLevel }, "macOS kernel reports memory pressure");
2871
+ return 0;
2872
+ }
2873
+ } catch {}
2874
+ try {
2875
+ const vmstat = execSync("vm_stat", {
2876
+ timeout: 2e3,
2877
+ encoding: "utf-8"
2878
+ });
2879
+ const pageSize = parseInt(vmstat.match(/page size of (\d+)/)?.[1] ?? "4096", 10);
2880
+ const free = parseInt(vmstat.match(/Pages free:\s+(\d+)/)?.[1] ?? "0", 10);
2881
+ const purgeable = parseInt(vmstat.match(/Pages purgeable:\s+(\d+)/)?.[1] ?? "0", 10);
2882
+ const speculative = parseInt(vmstat.match(/Pages speculative:\s+(\d+)/)?.[1] ?? "0", 10);
2883
+ return (free + purgeable + speculative) * pageSize;
2884
+ } catch {
2885
+ return freemem();
2886
+ }
2887
+ }
2888
+ return freemem();
2889
+ }
2846
2890
  var MutableDispatchHandle = class {
2847
2891
  id;
2848
2892
  status;
@@ -3242,7 +3286,7 @@ var DispatcherImpl = class {
3242
3286
  if (idx !== -1) this._queue.splice(idx, 1);
3243
3287
  }
3244
3288
  _isMemoryPressured() {
3245
- const free = freemem();
3289
+ const free = getAvailableMemory();
3246
3290
  if (free < MIN_FREE_MEMORY_BYTES) {
3247
3291
  logger$12.warn({
3248
3292
  freeMB: Math.round(free / 1024 / 1024),
@@ -11058,4 +11102,4 @@ function registerRunCommand(program, _version = "0.0.0", projectRoot = process.c
11058
11102
 
11059
11103
  //#endregion
11060
11104
  export { DatabaseWrapper, SUBSTRATE_OWNED_SETTINGS_KEYS, VALID_PHASES, buildPipelineStatusOutput, createContextCompiler, createDispatcher, createImplementationOrchestrator, createPackLoader, createPhaseOrchestrator, createStopAfterGate, findPackageRoot, formatOutput, formatPhaseCompletionSummary, formatPipelineStatusHuman, formatPipelineSummary, formatTokenTelemetry, getSubstrateDefaultSettings, parseDbTimestampAsUtc, registerRunCommand, resolveBmadMethodSrcPath, resolveBmadMethodVersion, resolveMainRepoRoot, runAnalysisPhase, runMigrations, runPlanningPhase, runRunAction, runSolutioningPhase, validateStopAfterFromConflict };
11061
- //# sourceMappingURL=run-DbRH_r_-.js.map
11105
+ //# sourceMappingURL=run-Bh7VhhyX.js.map
@@ -1,6 +1,6 @@
1
1
  import "./logger-C6n1g8uP.js";
2
2
  import "./event-bus-J-bw-pkp.js";
3
- import { registerRunCommand, runRunAction } from "./run-DbRH_r_-.js";
3
+ import { registerRunCommand, runRunAction } from "./run-Bh7VhhyX.js";
4
4
  import "./decisions-DNYByk0U.js";
5
5
  import "./metrics-BSg8VIHd.js";
6
6
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "substrate-ai",
3
- "version": "0.2.8",
3
+ "version": "0.2.9",
4
4
  "description": "Substrate — multi-agent orchestration daemon for AI coding agents",
5
5
  "type": "module",
6
6
  "license": "MIT",