@gaia-ai/conductor 0.11.0 → 0.11.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gaia-ai/conductor",
3
- "version": "0.11.0",
3
+ "version": "0.11.1",
4
4
  "description": "GAIA conductor engine + CLI: registers, claims tickets via JSON:API, dispatches agents.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -28,7 +28,7 @@
28
28
  "directory": "gaia-cli/conductor"
29
29
  },
30
30
  "dependencies": {
31
- "@gaia-ai/core": "^0.11.0",
31
+ "@gaia-ai/core": "^0.11.1",
32
32
  "@dropsh/plugin-oauth2": "^0.6.1",
33
33
  "@dropsh/plugin-jsonapi-schema": "^0.6.1",
34
34
  "commander": "^12.1.0",
@@ -1,72 +0,0 @@
1
- /** The global install target on npm (the meta package). */
2
- export declare const GAIA_PACKAGE = "@gaia-ai/gaia";
3
- /** The npm registry endpoint for the latest published version. */
4
- export declare const REGISTRY_LATEST_URL = "https://registry.npmjs.org/@gaia-ai/gaia/latest";
5
- /**
6
- * The sentinel returned when the installed version cannot be resolved (the
7
- * package.json walk failed). Never a real published release, so callers treat
8
- * it as "unknown" and suppress the update notice rather than nagging.
9
- */
10
- export declare const UNKNOWN_VERSION = "0.0.0";
11
- /**
12
- * The currently installed CLI version. Walks up from this module to the nearest
13
- * @gaia-ai/conductor package.json so it resolves both from the compiled
14
- * dist/src/cli/version-check.js and from a vitest src run. Same release tag
15
- * across packages ⇒ == @gaia-ai/gaia. Memoized — the version cannot change
16
- * within a process, so the walk runs at most once (finding #6).
17
- */
18
- export declare function resolveCliVersion(): string;
19
- /**
20
- * Fetch the latest published version of @gaia-ai/gaia from the npm registry.
21
- * Bounded by an AbortController timeout; NEVER throws — any failure (network,
22
- * non-2xx, timeout, malformed JSON, missing field) resolves to null so the
23
- * caller can treat the check as best-effort (AC-4). fetchImpl is injectable so
24
- * tests run without network.
25
- */
26
- export declare function fetchLatestVersion(fetchImpl?: typeof fetch, timeoutMs?: number): Promise<string | null>;
27
- /**
28
- * A human-readable "update available" notice when `latest` is strictly newer
29
- * than `current`, else null (already current or ahead — AC-5). Pure.
30
- */
31
- export declare function updateNotice(current: string, latest: string): string | null;
32
- /** Spawns a command, inheriting stdio, resolving to its exit code. */
33
- export type SpawnUpdate = (cmd: string, args: string[]) => Promise<number>;
34
- /** Spawns a command, capturing stdout, resolving to its exit code + stdout. */
35
- export type SpawnCapture = (cmd: string, args: string[]) => Promise<{
36
- code: number;
37
- stdout: string;
38
- }>;
39
- /**
40
- * Upgrade the globally installed gaia CLI to the latest published version via
41
- * `npm install -g @gaia-ai/gaia@latest`. Reports the actual global version
42
- * before and after the install (queried from npm, not from a separate registry
43
- * fetch — finding #2), so the caller reports the real change: `before` is null
44
- * when gaia was not installed globally, and no "upgraded" claim is made unless
45
- * npm actually changed the on-disk version. On install failure `after` mirrors
46
- * `before` and the post-install query is skipped. spawnImpl/captureImpl are
47
- * injectable for tests.
48
- */
49
- export declare function runUpdate(spawnImpl?: SpawnUpdate, captureImpl?: SpawnCapture): Promise<{
50
- ok: boolean;
51
- before: string | null;
52
- after: string | null;
53
- }>;
54
- /**
55
- * Print the installed gaia version line (AC-2), synchronously, and return it.
56
- * Never blocks on the registry — the caller kicks off the newer-version check
57
- * separately (see fetchUpdateNotice) so start is not stalled waiting on npm.
58
- */
59
- export declare function printVersionLine(out?: (s: string) => void): string;
60
- /**
61
- * Best-effort "update available" notice for the given installed version
62
- * (AC-3/AC-5). Fetches the latest published version (fail-silent → null on any
63
- * error, AC-4) and compares. Returns the notice string or null. fetchImpl is
64
- * injectable for tests.
65
- */
66
- export declare function fetchUpdateNotice(current: string, fetchImpl?: typeof fetch): Promise<string | null>;
67
- /**
68
- * Print the installed gaia version (AC-2) and, best-effort, a newer-version
69
- * notice (AC-3/AC-5). The registry check is fail-silent (AC-4): an offline
70
- * registry prints only the version line. out/fetchImpl are injectable for tests.
71
- */
72
- export declare function printStartVersionBanner(out?: (s: string) => void, fetchImpl?: typeof fetch): Promise<void>;
@@ -1,186 +0,0 @@
1
- import { spawn } from 'node:child_process';
2
- import { readFileSync } from 'node:fs';
3
- import { dirname, join } from 'node:path';
4
- import { fileURLToPath } from 'node:url';
5
- import semver from 'semver';
6
- /** The global install target on npm (the meta package). */
7
- export const GAIA_PACKAGE = '@gaia-ai/gaia';
8
- /** The npm registry endpoint for the latest published version. */
9
- export const REGISTRY_LATEST_URL = 'https://registry.npmjs.org/@gaia-ai/gaia/latest';
10
- /**
11
- * The sentinel returned when the installed version cannot be resolved (the
12
- * package.json walk failed). Never a real published release, so callers treat
13
- * it as "unknown" and suppress the update notice rather than nagging.
14
- */
15
- export const UNKNOWN_VERSION = '0.0.0';
16
- let cachedCliVersion;
17
- /**
18
- * The currently installed CLI version. Walks up from this module to the nearest
19
- * @gaia-ai/conductor package.json so it resolves both from the compiled
20
- * dist/src/cli/version-check.js and from a vitest src run. Same release tag
21
- * across packages ⇒ == @gaia-ai/gaia. Memoized — the version cannot change
22
- * within a process, so the walk runs at most once (finding #6).
23
- */
24
- export function resolveCliVersion() {
25
- if (cachedCliVersion !== undefined)
26
- return cachedCliVersion;
27
- let dir = dirname(fileURLToPath(import.meta.url));
28
- for (let i = 0; i < 6; i++) {
29
- try {
30
- const pkg = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf8'));
31
- if (pkg.name === '@gaia-ai/conductor') {
32
- cachedCliVersion = pkg.version ?? UNKNOWN_VERSION;
33
- return cachedCliVersion;
34
- }
35
- }
36
- catch {
37
- // no package.json here — keep walking up
38
- }
39
- dir = dirname(dir);
40
- }
41
- cachedCliVersion = UNKNOWN_VERSION;
42
- return cachedCliVersion;
43
- }
44
- /**
45
- * Fetch the latest published version of @gaia-ai/gaia from the npm registry.
46
- * Bounded by an AbortController timeout; NEVER throws — any failure (network,
47
- * non-2xx, timeout, malformed JSON, missing field) resolves to null so the
48
- * caller can treat the check as best-effort (AC-4). fetchImpl is injectable so
49
- * tests run without network.
50
- */
51
- export async function fetchLatestVersion(fetchImpl = globalThis.fetch, timeoutMs = 1500) {
52
- const controller = new AbortController();
53
- const timer = setTimeout(() => controller.abort(), timeoutMs);
54
- try {
55
- const res = await fetchImpl(REGISTRY_LATEST_URL, {
56
- signal: controller.signal,
57
- headers: { accept: 'application/json' },
58
- });
59
- if (!res.ok)
60
- return null;
61
- const body = (await res.json());
62
- return typeof body.version === 'string' ? body.version : null;
63
- }
64
- catch {
65
- return null;
66
- }
67
- finally {
68
- clearTimeout(timer);
69
- }
70
- }
71
- /**
72
- * A human-readable "update available" notice when `latest` is strictly newer
73
- * than `current`, else null (already current or ahead — AC-5). Pure.
74
- */
75
- export function updateNotice(current, latest) {
76
- // Unknown installed version ⇒ suppress the notice (finding #5): otherwise a
77
- // failed package.json walk yields a perpetual bogus "0.0.0 → x.y.z" nag.
78
- if (current === UNKNOWN_VERSION)
79
- return null;
80
- if (!semver.valid(current) || !semver.valid(latest))
81
- return null;
82
- if (!semver.gt(latest, current))
83
- return null;
84
- // Two distinct steps, apt-style: first get the newer CODE, then migrate the
85
- // CONFIG. There is no `gaia update` command — the CLI is a global npm package,
86
- // so code is updated via npm; `gaia upgrade` then migrates the config shape.
87
- return (`A new gaia version is available: ${current} → ${latest}\n` +
88
- 'Run `npm install -g @gaia-ai/gaia@latest` to update the CLI, ' +
89
- 'then `gaia upgrade` to migrate your config.');
90
- }
91
- const defaultSpawn = (cmd, args) => new Promise((resolve) => {
92
- const child = spawn(cmd, args, { stdio: 'inherit', shell: false });
93
- child.on('error', () => resolve(1));
94
- child.on('close', (code) => resolve(code ?? 1));
95
- });
96
- const defaultCapture = (cmd, args) => new Promise((resolve) => {
97
- let stdout = '';
98
- const child = spawn(cmd, args, {
99
- stdio: ['ignore', 'pipe', 'ignore'],
100
- shell: false,
101
- });
102
- child.stdout?.on('data', (chunk) => {
103
- stdout += String(chunk);
104
- });
105
- child.on('error', () => resolve({ code: 1, stdout }));
106
- child.on('close', (code) => resolve({ code: code ?? 1, stdout }));
107
- });
108
- /**
109
- * The version of the globally installed @gaia-ai/gaia, read from
110
- * `npm ls -g @gaia-ai/gaia --json`, or null when it is not installed globally /
111
- * the output cannot be parsed. This reflects what npm actually has on disk —
112
- * independent of the (possibly dev-shim) CLI running this process.
113
- */
114
- async function queryGlobalVersion(captureImpl) {
115
- try {
116
- const { stdout } = await captureImpl('npm', [
117
- 'ls',
118
- '-g',
119
- GAIA_PACKAGE,
120
- '--json',
121
- '--depth',
122
- '0',
123
- ]);
124
- const parsed = JSON.parse(stdout);
125
- const v = parsed.dependencies?.[GAIA_PACKAGE]?.version;
126
- return typeof v === 'string' ? v : null;
127
- }
128
- catch {
129
- return null;
130
- }
131
- }
132
- /**
133
- * Upgrade the globally installed gaia CLI to the latest published version via
134
- * `npm install -g @gaia-ai/gaia@latest`. Reports the actual global version
135
- * before and after the install (queried from npm, not from a separate registry
136
- * fetch — finding #2), so the caller reports the real change: `before` is null
137
- * when gaia was not installed globally, and no "upgraded" claim is made unless
138
- * npm actually changed the on-disk version. On install failure `after` mirrors
139
- * `before` and the post-install query is skipped. spawnImpl/captureImpl are
140
- * injectable for tests.
141
- */
142
- export async function runUpdate(spawnImpl = defaultSpawn, captureImpl = defaultCapture) {
143
- const before = await queryGlobalVersion(captureImpl);
144
- const code = await spawnImpl('npm', [
145
- 'install',
146
- '-g',
147
- `${GAIA_PACKAGE}@latest`,
148
- ]);
149
- if (code !== 0)
150
- return { ok: false, before, after: before };
151
- const after = await queryGlobalVersion(captureImpl);
152
- return { ok: true, before, after };
153
- }
154
- /**
155
- * Print the installed gaia version line (AC-2), synchronously, and return it.
156
- * Never blocks on the registry — the caller kicks off the newer-version check
157
- * separately (see fetchUpdateNotice) so start is not stalled waiting on npm.
158
- */
159
- export function printVersionLine(out = console.log) {
160
- const current = resolveCliVersion();
161
- out(`gaia v${current}`);
162
- return current;
163
- }
164
- /**
165
- * Best-effort "update available" notice for the given installed version
166
- * (AC-3/AC-5). Fetches the latest published version (fail-silent → null on any
167
- * error, AC-4) and compares. Returns the notice string or null. fetchImpl is
168
- * injectable for tests.
169
- */
170
- export async function fetchUpdateNotice(current, fetchImpl = globalThis.fetch) {
171
- const latest = await fetchLatestVersion(fetchImpl);
172
- if (latest === null)
173
- return null;
174
- return updateNotice(current, latest);
175
- }
176
- /**
177
- * Print the installed gaia version (AC-2) and, best-effort, a newer-version
178
- * notice (AC-3/AC-5). The registry check is fail-silent (AC-4): an offline
179
- * registry prints only the version line. out/fetchImpl are injectable for tests.
180
- */
181
- export async function printStartVersionBanner(out = console.log, fetchImpl = globalThis.fetch) {
182
- const current = printVersionLine(out);
183
- const notice = await fetchUpdateNotice(current, fetchImpl);
184
- if (notice !== null)
185
- out(notice);
186
- }