substrate-ai 0.9.0 → 0.11.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 (35) hide show
  1. package/dist/adapter-registry-DXLMTmfD.js +0 -0
  2. package/dist/adapter-registry-neBZrkr3.js +4 -0
  3. package/dist/cli/index.js +5594 -5951
  4. package/dist/decisions-C0pz9Clx.js +0 -0
  5. package/dist/{decisions-BDLp3tJB.js → decisions-DQZW0h9X.js} +2 -1
  6. package/dist/dist-eNB_v7Iy.js +10205 -0
  7. package/dist/errors-BvyMlvCX.js +74 -0
  8. package/dist/experimenter-Dos3NsCg.js +3 -0
  9. package/dist/health-BvYILeQQ.js +6 -0
  10. package/dist/{health-C-VRJruD.js → health-CiDi90gC.js} +57 -1850
  11. package/dist/{helpers-CpMs8VZX.js → helpers-DTp3VJ2-.js} +31 -121
  12. package/dist/index.d.ts +709 -266
  13. package/dist/index.js +5 -3
  14. package/dist/{logger-D2fS2ccL.js → logger-KeHncl-f.js} +2 -42
  15. package/dist/routing-CcBOCuC9.js +0 -0
  16. package/dist/{routing-CD8bIci_.js → routing-HaYsjEIS.js} +2 -2
  17. package/dist/{run-ClxNDHbr.js → run-CAUhTR7Y.js} +594 -4249
  18. package/dist/run-DPZOQOvB.js +9 -0
  19. package/dist/{upgrade-B1S61VXJ.js → upgrade-DFGrqjGI.js} +3 -3
  20. package/dist/{upgrade-BK0HrKA6.js → upgrade-DYdYuuJK.js} +3 -3
  21. package/dist/version-manager-impl-BmOWu8ml.js +0 -0
  22. package/dist/version-manager-impl-CKv6I1S0.js +4 -0
  23. package/package.json +5 -2
  24. package/dist/adapter-registry-D2zdMwVu.js +0 -840
  25. package/dist/adapter-registry-WAyFydN5.js +0 -4
  26. package/dist/config-migrator-CtGelIsG.js +0 -250
  27. package/dist/decisions-DhAA2HG2.js +0 -397
  28. package/dist/experimenter-D_N_7ZF3.js +0 -503
  29. package/dist/git-utils-DxPx6erV.js +0 -365
  30. package/dist/health-DMbNP9bw.js +0 -5
  31. package/dist/operational-BdcdmDqS.js +0 -374
  32. package/dist/routing-BVrxrM6v.js +0 -832
  33. package/dist/run-MAQ3Wuju.js +0 -10
  34. package/dist/version-manager-impl-BIxOe7gZ.js +0 -372
  35. package/dist/version-manager-impl-RrWs-CI6.js +0 -4
@@ -1,10 +0,0 @@
1
- import "./health-C-VRJruD.js";
2
- import "./logger-D2fS2ccL.js";
3
- import { registerRunCommand, runRunAction } from "./run-ClxNDHbr.js";
4
- import "./config-migrator-CtGelIsG.js";
5
- import "./helpers-CpMs8VZX.js";
6
- import "./routing-BVrxrM6v.js";
7
- import "./decisions-DhAA2HG2.js";
8
- import "./operational-BdcdmDqS.js";
9
-
10
- export { runRunAction };
@@ -1,372 +0,0 @@
1
- import { SUPPORTED_CONFIG_FORMAT_VERSIONS, SUPPORTED_TASK_GRAPH_VERSIONS, defaultConfigMigrator } from "./config-migrator-CtGelIsG.js";
2
- import { createRequire } from "module";
3
- import { fileURLToPath } from "url";
4
- import path, { dirname, resolve } from "path";
5
- import { mkdirSync, readFileSync, writeFileSync } from "fs";
6
- import os from "os";
7
- import * as semver$1 from "semver";
8
- import * as semver from "semver";
9
- import https from "https";
10
-
11
- //#region src/modules/version-manager/update-checker.ts
12
- /**
13
- * Thrown when an update check fails due to network error, timeout, or bad response.
14
- */
15
- var UpdateCheckError = class extends Error {
16
- name = "UpdateCheckError";
17
- constructor(message) {
18
- super(message);
19
- Object.setPrototypeOf(this, new.target.prototype);
20
- }
21
- };
22
- /**
23
- * Queries the npm registry to determine the latest published version of a package.
24
- */
25
- var UpdateChecker = class {
26
- timeoutMs;
27
- constructor(timeoutMs = 5e3) {
28
- this.timeoutMs = timeoutMs;
29
- }
30
- /**
31
- * Fetch the latest published version of a package from the npm registry.
32
- *
33
- * @param packageName - npm package name (e.g. 'substrate')
34
- * @returns The latest version string (semver)
35
- * @throws {UpdateCheckError} on timeout, network error, non-200 HTTP status, or parse failure
36
- */
37
- fetchLatestVersion(packageName) {
38
- return new Promise((resolve$1, reject) => {
39
- const url = `https://registry.npmjs.org/${packageName}/latest`;
40
- let settled = false;
41
- const safeReject = (err) => {
42
- if (!settled) {
43
- settled = true;
44
- clearTimeout(timer);
45
- reject(err);
46
- }
47
- };
48
- const safeResolve = (value) => {
49
- if (!settled) {
50
- settled = true;
51
- clearTimeout(timer);
52
- resolve$1(value);
53
- }
54
- };
55
- let req;
56
- const timer = setTimeout(() => {
57
- req.destroy();
58
- safeReject(new UpdateCheckError(`Update check timed out after ${this.timeoutMs}ms`));
59
- }, this.timeoutMs);
60
- const followRedirect = (location, hopsLeft) => {
61
- const redirectReq = https.get(location, (redirectRes) => {
62
- if (redirectRes.statusCode !== void 0 && redirectRes.statusCode >= 300 && redirectRes.statusCode < 400 && redirectRes.headers.location && hopsLeft > 0) {
63
- redirectRes.resume();
64
- followRedirect(redirectRes.headers.location, hopsLeft - 1);
65
- return;
66
- }
67
- if (redirectRes.statusCode !== 200) {
68
- redirectRes.resume();
69
- safeReject(new UpdateCheckError(`npm registry returned HTTP ${String(redirectRes.statusCode)} for ${packageName}`));
70
- return;
71
- }
72
- collectBody(redirectRes, safeResolve, safeReject);
73
- });
74
- redirectReq.on("error", (err) => {
75
- safeReject(new UpdateCheckError(`Update check network error: ${err.message}`));
76
- });
77
- redirectReq.setTimeout(this.timeoutMs, () => {
78
- redirectReq.destroy();
79
- safeReject(new UpdateCheckError(`Update check timed out after ${this.timeoutMs}ms`));
80
- });
81
- };
82
- req = https.get(url, (res) => {
83
- if (res.statusCode !== void 0 && res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
84
- res.resume();
85
- followRedirect(res.headers.location, 1);
86
- return;
87
- }
88
- if (res.statusCode !== 200) {
89
- res.resume();
90
- safeReject(new UpdateCheckError(`npm registry returned HTTP ${String(res.statusCode)} for ${packageName}`));
91
- return;
92
- }
93
- collectBody(res, safeResolve, safeReject);
94
- });
95
- req.on("error", (err) => {
96
- safeReject(new UpdateCheckError(`Update check network error: ${err.message}`));
97
- });
98
- });
99
- }
100
- /**
101
- * Determine whether upgrading from currentVersion to latestVersion is a breaking (major) change.
102
- *
103
- * @param currentVersion - The currently installed version (semver string)
104
- * @param latestVersion - The available latest version (semver string)
105
- * @returns true if the major version increases; false if either version is invalid
106
- */
107
- isBreaking(currentVersion, latestVersion) {
108
- if (!semver$1.valid(currentVersion) || !semver$1.valid(latestVersion)) return false;
109
- const currentMajor = semver$1.major(currentVersion);
110
- const latestMajor = semver$1.major(latestVersion);
111
- return latestMajor > currentMajor;
112
- }
113
- /**
114
- * Return a changelog URL for the given version.
115
- *
116
- * @param latestVersion - The version to link to
117
- * @returns A URL string pointing to the GitHub release page
118
- */
119
- getChangelog(latestVersion) {
120
- return `See https://github.com/johnplanow/substrate/releases/tag/v${latestVersion}`;
121
- }
122
- };
123
- function collectBody(res, resolve$1, reject) {
124
- const chunks = [];
125
- res.on("data", (chunk) => {
126
- chunks.push(chunk);
127
- });
128
- res.on("end", () => {
129
- try {
130
- const body = Buffer.concat(chunks).toString("utf-8");
131
- const data = JSON.parse(body);
132
- if (typeof data.version !== "string" || data.version.length === 0) {
133
- reject(new UpdateCheckError("npm registry response missing version field"));
134
- return;
135
- }
136
- resolve$1(data.version);
137
- } catch {
138
- reject(new UpdateCheckError("Failed to parse npm registry response"));
139
- }
140
- });
141
- res.on("error", (err) => {
142
- reject(new UpdateCheckError(`Response stream error: ${err.message}`));
143
- });
144
- }
145
-
146
- //#endregion
147
- //#region src/modules/version-manager/version-cache.ts
148
- /**
149
- * Manages reading and writing the version check result cache.
150
- *
151
- * Write errors are silently swallowed so that a read-only home directory
152
- * never breaks CLI execution.
153
- */
154
- var VersionCache = class {
155
- cachePath;
156
- ttlMs;
157
- constructor(cachePath = path.join(os.homedir(), ".substrate", "update-cache.json"), ttlMs = 24 * 60 * 60 * 1e3) {
158
- this.cachePath = cachePath;
159
- this.ttlMs = ttlMs;
160
- }
161
- /**
162
- * Read the cache file. Returns null if the file is missing, unreadable, or expired.
163
- */
164
- read() {
165
- try {
166
- const raw = readFileSync(this.cachePath, "utf-8");
167
- const entry = JSON.parse(raw);
168
- if (typeof entry.lastChecked !== "string" || typeof entry.latestVersion !== "string" || typeof entry.currentVersion !== "string") return null;
169
- if (this.isExpired(entry)) return null;
170
- return entry;
171
- } catch {
172
- return null;
173
- }
174
- }
175
- /**
176
- * Write a cache entry to disk. Creates the parent directory if needed.
177
- * Silently swallows any write errors.
178
- */
179
- write(entry) {
180
- try {
181
- mkdirSync(dirname(this.cachePath), { recursive: true });
182
- writeFileSync(this.cachePath, JSON.stringify(entry, null, 2), "utf-8");
183
- } catch {}
184
- }
185
- /**
186
- * Check whether a cache entry has expired according to the configured TTL.
187
- */
188
- isExpired(entry) {
189
- const age = Date.now() - new Date(entry.lastChecked).getTime();
190
- return age > this.ttlMs;
191
- }
192
- };
193
-
194
- //#endregion
195
- //#region src/modules/version-manager/version-manager-impl.ts
196
- /**
197
- * Concrete implementation of VersionManager.
198
- *
199
- * @param deps - Optional overrides for cache and updateChecker (for testing)
200
- */
201
- var VersionManagerImpl = class {
202
- cache;
203
- updateChecker;
204
- updateCheckEnabled;
205
- constructor(deps = {}) {
206
- this.cache = deps.cache ?? new VersionCache();
207
- this.updateChecker = deps.updateChecker ?? new UpdateChecker();
208
- this.updateCheckEnabled = deps.updateCheckEnabled !== false;
209
- }
210
- /**
211
- * Read the current package version from the bundled package.json.
212
- * Tries multiple relative paths because the bundler may place this chunk
213
- * at different depths (e.g. dist/version-manager-impl-xxx.js vs
214
- * src/modules/version-manager/version-manager-impl.ts).
215
- * Falls back to '0.0.0' if the file is unreadable.
216
- */
217
- getCurrentVersion() {
218
- try {
219
- const __dirname = dirname(fileURLToPath(import.meta.url));
220
- const candidates = [
221
- resolve(__dirname, "../package.json"),
222
- resolve(__dirname, "../../package.json"),
223
- resolve(__dirname, "../../../package.json")
224
- ];
225
- for (const candidate of candidates) try {
226
- const raw = readFileSync(candidate, "utf-8");
227
- const pkg = JSON.parse(raw);
228
- if (pkg.name === "substrate-ai" && typeof pkg.version === "string" && pkg.version.length > 0) return pkg.version;
229
- } catch {}
230
- return "0.0.0";
231
- } catch {
232
- return "0.0.0";
233
- }
234
- }
235
- /**
236
- * Check whether a newer version is available on npm.
237
- *
238
- * Respects:
239
- * 1. update_check config setting (AC5)
240
- * 2. SUBSTRATE_NO_UPDATE_CHECK env var
241
- * 3. Cache TTL (24h by default), unless forceRefresh is true
242
- *
243
- * Returns updateAvailable: false without a network call when checks are disabled
244
- * or the cache is fresh (and forceRefresh is not set).
245
- *
246
- * @param forceRefresh - When true, skips the cache and always makes a fresh network request.
247
- */
248
- async checkForUpdates(forceRefresh = false) {
249
- const currentVersion = this.getCurrentVersion();
250
- if (!this.updateCheckEnabled) return {
251
- currentVersion,
252
- latestVersion: currentVersion,
253
- updateAvailable: false,
254
- isBreaking: false,
255
- changelog: ""
256
- };
257
- if (process.env["SUBSTRATE_NO_UPDATE_CHECK"] === "1") return {
258
- currentVersion,
259
- latestVersion: currentVersion,
260
- updateAvailable: false,
261
- isBreaking: false,
262
- changelog: ""
263
- };
264
- if (!forceRefresh) {
265
- const cached = this.cache.read();
266
- if (cached !== null) {
267
- const updateAvailable = semver.gt(cached.latestVersion, currentVersion);
268
- return {
269
- currentVersion,
270
- latestVersion: cached.latestVersion,
271
- updateAvailable,
272
- isBreaking: this.updateChecker.isBreaking(currentVersion, cached.latestVersion),
273
- changelog: this.updateChecker.getChangelog(cached.latestVersion)
274
- };
275
- }
276
- }
277
- try {
278
- const latestVersion = await this.updateChecker.fetchLatestVersion("substrate-ai");
279
- const updateAvailable = semver.gt(latestVersion, currentVersion);
280
- this.cache.write({
281
- lastChecked: new Date().toISOString(),
282
- latestVersion,
283
- currentVersion
284
- });
285
- return {
286
- currentVersion,
287
- latestVersion,
288
- updateAvailable,
289
- isBreaking: this.updateChecker.isBreaking(currentVersion, latestVersion),
290
- changelog: this.updateChecker.getChangelog(latestVersion)
291
- };
292
- } catch {
293
- return {
294
- currentVersion,
295
- latestVersion: currentVersion,
296
- updateAvailable: false,
297
- isBreaking: false,
298
- changelog: ""
299
- };
300
- }
301
- }
302
- /**
303
- * Return an upgrade preview for the given target version.
304
- */
305
- getUpgradePreview(targetVersion) {
306
- const fromVersion = this.getCurrentVersion();
307
- const breaking = this.updateChecker.isBreaking(fromVersion, targetVersion);
308
- return {
309
- fromVersion,
310
- toVersion: targetVersion,
311
- breakingChanges: breaking ? [`Major version bump from v${fromVersion} to v${targetVersion}`] : [],
312
- migrationSteps: [this.updateChecker.getChangelog(targetVersion)],
313
- automaticMigrations: breaking ? ["Run defaultConfigMigrator.migrate() if config changed"] : [],
314
- manualStepsRequired: breaking ? ["Review breaking changes at the changelog URL above"] : []
315
- };
316
- }
317
- /**
318
- * Migrate the project configuration from one format version to another.
319
- * Delegates to the shared defaultConfigMigrator singleton.
320
- * Loads the actual config from the project config file so migration functions receive real data.
321
- */
322
- migrateConfiguration(fromVersion, toVersion) {
323
- let configObj = {};
324
- try {
325
- const _require = createRequire(import.meta.url);
326
- const fs = _require("fs");
327
- const path$1 = _require("path");
328
- const yaml = _require("js-yaml");
329
- const configPath = path$1.join(process.cwd(), ".substrate", "config.yaml");
330
- try {
331
- const raw = fs.readFileSync(configPath, "utf-8");
332
- configObj = yaml.load(raw) ?? {};
333
- } catch {
334
- configObj = {};
335
- }
336
- } catch {
337
- configObj = {};
338
- }
339
- const { result } = defaultConfigMigrator.migrate(configObj, fromVersion, toVersion);
340
- return result;
341
- }
342
- /**
343
- * Migrate a task graph file from one format version to another.
344
- * Delegates to the shared defaultConfigMigrator singleton.
345
- */
346
- migrateTaskGraphFormat(fromVersion, toVersion, filePath) {
347
- const { result } = defaultConfigMigrator.migrate({}, fromVersion, toVersion, filePath);
348
- return result;
349
- }
350
- /**
351
- * Check whether the given config format version is supported by this toolkit.
352
- */
353
- isConfigCompatible(configVersion) {
354
- return SUPPORTED_CONFIG_FORMAT_VERSIONS.includes(configVersion);
355
- }
356
- /**
357
- * Check whether the given task graph format version is supported by this toolkit.
358
- */
359
- isTaskGraphCompatible(graphVersion) {
360
- return SUPPORTED_TASK_GRAPH_VERSIONS.includes(graphVersion);
361
- }
362
- };
363
- /**
364
- * Create a new VersionManager instance with optional dependency overrides.
365
- */
366
- function createVersionManager(deps = {}) {
367
- return new VersionManagerImpl(deps);
368
- }
369
-
370
- //#endregion
371
- export { VersionManagerImpl, createVersionManager };
372
- //# sourceMappingURL=version-manager-impl-BIxOe7gZ.js.map
@@ -1,4 +0,0 @@
1
- import "./config-migrator-CtGelIsG.js";
2
- import { VersionManagerImpl, createVersionManager } from "./version-manager-impl-BIxOe7gZ.js";
3
-
4
- export { createVersionManager };