@gaia-ai/gaia 0.5.4 → 0.6.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.
- package/bin/gaia +4 -1
- package/dist/src/host.d.ts +31 -0
- package/dist/src/host.js +218 -0
- package/dist/src/upgrade.d.ts +3 -0
- package/dist/src/upgrade.js +24 -0
- package/package.json +16 -11
package/bin/gaia
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
// GAIA-201: the `gaia` entrypoint lives in the meta package now (AC-1). It runs
|
|
3
|
+
// the plugin host, which dynamically mounts the ui/conductor/dropsh command
|
|
4
|
+
// plugins — conductor is no longer the CLI owner.
|
|
5
|
+
import('../dist/src/host.js').then((m) => m.main(process.argv));
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type CommandDescriptor } from '@gaia-ai/core';
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
/** The built-in command registry. `$GAIA_COMMANDS` (JSON array of descriptors)
|
|
4
|
+
* overrides it wholesale. */
|
|
5
|
+
export declare const DEFAULT_COMMANDS: CommandDescriptor[];
|
|
6
|
+
/** Resolve the registry: `$GAIA_COMMANDS` override else the built-in set. */
|
|
7
|
+
export declare function resolveCommands(): CommandDescriptor[];
|
|
8
|
+
/** The installed CLI version (the meta package version). */
|
|
9
|
+
export declare function resolveCliVersion(): string;
|
|
10
|
+
/** Host bases for ESLint-style sibling resolution: the meta install → cwd. */
|
|
11
|
+
export declare function hostBases(): string[];
|
|
12
|
+
/**
|
|
13
|
+
* Value-aware argv pre-scan: find the first positional token that names a
|
|
14
|
+
* registered command. Skips the host's value-taking global (`--conductor <v>`)
|
|
15
|
+
* and maps `help <name>` → `<name>`. Returns undefined for `--help`, an unknown
|
|
16
|
+
* first positional, or a bare invocation.
|
|
17
|
+
*/
|
|
18
|
+
export declare function scanTarget(argv: string[], names: string[]): string | undefined;
|
|
19
|
+
/** Build the top-level host program, mounting only the target command (the rest
|
|
20
|
+
* are describe-only stubs). */
|
|
21
|
+
export declare function buildHostProgram(argv: string[], opts?: {
|
|
22
|
+
forceTarget?: string;
|
|
23
|
+
bases?: string[];
|
|
24
|
+
}): Promise<Command>;
|
|
25
|
+
/** Parse argv against the host program, mapping commander's clean exits. */
|
|
26
|
+
export declare function runHost(argv: string[], opts?: {
|
|
27
|
+
forceTarget?: string;
|
|
28
|
+
bases?: string[];
|
|
29
|
+
}): Promise<void>;
|
|
30
|
+
/** The `gaia` entrypoint: drop node + script path, run the host. */
|
|
31
|
+
export declare function main(argv: string[]): Promise<void>;
|
package/dist/src/host.js
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
4
|
+
import { commands as conductorCommands } from '@gaia-ai/conductor/preset';
|
|
5
|
+
import { resolveModuleEslintStyle, } from '@gaia-ai/core';
|
|
6
|
+
import { commands as dropshCommands } from '@gaia-ai/plugin-dropsh/preset';
|
|
7
|
+
import { commands as uiCommands } from '@gaia-ai/ui/preset';
|
|
8
|
+
import { Command } from 'commander';
|
|
9
|
+
import { registerUpgrade } from './upgrade.js';
|
|
10
|
+
// GAIA-201: the `gaia` plugin HOST. The meta package `@gaia-ai/gaia` owns the
|
|
11
|
+
// CLI entrypoint (AC-1); ui / conductor / dropsh are declared, ESLint-style
|
|
12
|
+
// resolved, LAZILY mounted command plugins (AC-2). The host discovers + mounts;
|
|
13
|
+
// it hard-wires nothing. Only the invoked subcommand's module is imported —
|
|
14
|
+
// `gaia --help` lists all three via describe-only stubs and imports none;
|
|
15
|
+
// `gaia conductor …` imports only the conductor module.
|
|
16
|
+
//
|
|
17
|
+
// GAIA-215: the registry is DERIVED from the command surface — the three command
|
|
18
|
+
// addons' preset `commands` accumulators — rather than a hand-written list.
|
|
19
|
+
// Those presets are LIGHT (they import no runtime, only return descriptors), so
|
|
20
|
+
// composing them at boot keeps `gaia --help` import-light. `$GAIA_COMMANDS`
|
|
21
|
+
// still overrides the whole registry.
|
|
22
|
+
/** Compose the built-in command registry from the command addons' presets. The
|
|
23
|
+
* accumulators are synchronous descriptor builders (light presets), threaded in
|
|
24
|
+
* the conductor → ui → dropsh order. */
|
|
25
|
+
function composeCommandSurface() {
|
|
26
|
+
const accumulators = [conductorCommands, uiCommands, dropshCommands];
|
|
27
|
+
let acc = [];
|
|
28
|
+
for (const fn of accumulators) {
|
|
29
|
+
if (typeof fn === 'function')
|
|
30
|
+
acc = fn(acc, undefined);
|
|
31
|
+
}
|
|
32
|
+
return acc;
|
|
33
|
+
}
|
|
34
|
+
/** The built-in command registry. `$GAIA_COMMANDS` (JSON array of descriptors)
|
|
35
|
+
* overrides it wholesale. */
|
|
36
|
+
export const DEFAULT_COMMANDS = composeCommandSurface();
|
|
37
|
+
/** Resolve the registry: `$GAIA_COMMANDS` override else the built-in set. */
|
|
38
|
+
export function resolveCommands() {
|
|
39
|
+
const override = process.env.GAIA_COMMANDS;
|
|
40
|
+
if (override && override.trim() !== '') {
|
|
41
|
+
const parsed = JSON.parse(override);
|
|
42
|
+
if (!Array.isArray(parsed)) {
|
|
43
|
+
throw new Error('$GAIA_COMMANDS must be a JSON array of command descriptors');
|
|
44
|
+
}
|
|
45
|
+
return parsed;
|
|
46
|
+
}
|
|
47
|
+
return DEFAULT_COMMANDS;
|
|
48
|
+
}
|
|
49
|
+
/** The meta package root (holds package.json), for version + resolveBases. */
|
|
50
|
+
function metaPackageRoot() {
|
|
51
|
+
let dir = dirname(fileURLToPath(import.meta.url));
|
|
52
|
+
for (;;) {
|
|
53
|
+
try {
|
|
54
|
+
readFileSync(join(dir, 'package.json'), 'utf8');
|
|
55
|
+
return dir;
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
const parent = dirname(dir);
|
|
59
|
+
if (parent === dir)
|
|
60
|
+
return dir;
|
|
61
|
+
dir = parent;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/** The installed CLI version (the meta package version). */
|
|
66
|
+
export function resolveCliVersion() {
|
|
67
|
+
try {
|
|
68
|
+
const pkg = JSON.parse(readFileSync(join(metaPackageRoot(), 'package.json'), 'utf8'));
|
|
69
|
+
return pkg.version ?? '0.0.0';
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return '0.0.0';
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/** Host bases for ESLint-style sibling resolution: the meta install → cwd. */
|
|
76
|
+
export function hostBases() {
|
|
77
|
+
return [import.meta.url, pathToFileURL(`${process.cwd()}/`).href];
|
|
78
|
+
}
|
|
79
|
+
/** Load a command descriptor's `GaiaCommandPlugin` (default export, or the named
|
|
80
|
+
* `export`), resolving the module over the host bases. */
|
|
81
|
+
async function loadCommandPlugin(entry, bases) {
|
|
82
|
+
const resolved = resolveModuleEslintStyle(entry.plugin, bases);
|
|
83
|
+
if (resolved === undefined) {
|
|
84
|
+
throw new Error(`gaia: cannot resolve command plugin '${entry.plugin}' (command '${entry.name}')`);
|
|
85
|
+
}
|
|
86
|
+
const mod = (await import(pathToFileURL(resolved).href));
|
|
87
|
+
const factory = entry.export ? mod[entry.export] : mod.default;
|
|
88
|
+
if (factory === undefined || factory === null) {
|
|
89
|
+
throw new Error(`gaia: command plugin '${entry.plugin}' has no ${entry.export ?? 'default'} export`);
|
|
90
|
+
}
|
|
91
|
+
return factory;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Value-aware argv pre-scan: find the first positional token that names a
|
|
95
|
+
* registered command. Skips the host's value-taking global (`--conductor <v>`)
|
|
96
|
+
* and maps `help <name>` → `<name>`. Returns undefined for `--help`, an unknown
|
|
97
|
+
* first positional, or a bare invocation.
|
|
98
|
+
*/
|
|
99
|
+
export function scanTarget(argv, names) {
|
|
100
|
+
for (let i = 0; i < argv.length; i++) {
|
|
101
|
+
const a = argv[i];
|
|
102
|
+
if (a === '--conductor') {
|
|
103
|
+
i++; // skip its value
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if (a === 'help') {
|
|
107
|
+
const next = argv[i + 1];
|
|
108
|
+
return next !== undefined && names.includes(next) ? next : undefined;
|
|
109
|
+
}
|
|
110
|
+
if (a.startsWith('-'))
|
|
111
|
+
continue; // any other flag
|
|
112
|
+
return names.includes(a) ? a : undefined;
|
|
113
|
+
}
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
/** Add a describe-only stub for a not-loaded command so `--help` stays complete.
|
|
117
|
+
* If it is ever dispatched (a mis-scan), its action self-loads the real plugin
|
|
118
|
+
* and re-runs the host forcing that target. */
|
|
119
|
+
function addStub(program, entry, bases, argv) {
|
|
120
|
+
program
|
|
121
|
+
.command(entry.name)
|
|
122
|
+
.description(pluginDescribe(entry))
|
|
123
|
+
.allowUnknownOption(true)
|
|
124
|
+
.allowExcessArguments(true)
|
|
125
|
+
.helpOption(false)
|
|
126
|
+
.action(async () => {
|
|
127
|
+
await runHost(argv, { forceTarget: entry.name, bases });
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
/** Best-effort describe text for a stub without importing the plugin. GAIA-215:
|
|
131
|
+
* the descriptor now carries its own `describe` (from the addon's preset); this
|
|
132
|
+
* falls back only for a `$GAIA_COMMANDS` entry that omits it. */
|
|
133
|
+
function pluginDescribe(entry) {
|
|
134
|
+
if (typeof entry.describe === 'string' && entry.describe.trim() !== '') {
|
|
135
|
+
return entry.describe;
|
|
136
|
+
}
|
|
137
|
+
switch (entry.name) {
|
|
138
|
+
case 'conductor':
|
|
139
|
+
return 'node-agent lifecycle + local registry';
|
|
140
|
+
case 'ui':
|
|
141
|
+
return 'interactive terminal UI: project dashboard, ticket list, ticket detail';
|
|
142
|
+
case 'dropsh':
|
|
143
|
+
return 'JSON:API shell (dropsh) bound to the GAIA connection config';
|
|
144
|
+
default:
|
|
145
|
+
return `${entry.name} command`;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
/** Build the top-level host program, mounting only the target command (the rest
|
|
149
|
+
* are describe-only stubs). */
|
|
150
|
+
export async function buildHostProgram(argv, opts = {}) {
|
|
151
|
+
const bases = opts.bases ?? hostBases();
|
|
152
|
+
const host = { resolveBases: bases };
|
|
153
|
+
const commands = resolveCommands();
|
|
154
|
+
const names = commands.map((c) => c.name);
|
|
155
|
+
const program = new Command();
|
|
156
|
+
// exitOverride so commander surfaces help/version/unknown-command as thrown
|
|
157
|
+
// CommanderErrors (mapped in runHost) instead of calling process.exit —
|
|
158
|
+
// otherwise an unknown command would kill the host process directly.
|
|
159
|
+
program.exitOverride();
|
|
160
|
+
program
|
|
161
|
+
.name('gaia')
|
|
162
|
+
.description('GAIA conductor + client CLI')
|
|
163
|
+
.option('--conductor <name>', 'select a conductor by stem (conductor→conductor.config.js, else <name>.conductor.config.js; env $GAIA_CONDUCTOR)');
|
|
164
|
+
// The global --conductor flag threads into $GAIA_CONDUCTOR (flag wins over env)
|
|
165
|
+
// so every command selects the named engine config without per-command wiring.
|
|
166
|
+
program.hook('preAction', () => {
|
|
167
|
+
const name = program.opts().conductor;
|
|
168
|
+
if (typeof name === 'string' && name !== '') {
|
|
169
|
+
process.env.GAIA_CONDUCTOR = name;
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
const cliVersion = resolveCliVersion();
|
|
173
|
+
program.version(cliVersion); // -V, --version
|
|
174
|
+
program
|
|
175
|
+
.command('version')
|
|
176
|
+
.description('output the gaia CLI version')
|
|
177
|
+
.action(() => {
|
|
178
|
+
console.log(cliVersion);
|
|
179
|
+
});
|
|
180
|
+
registerUpgrade(program);
|
|
181
|
+
const target = opts.forceTarget ?? scanTarget(argv, names);
|
|
182
|
+
for (const entry of commands) {
|
|
183
|
+
if (entry.name === target) {
|
|
184
|
+
const plugin = await loadCommandPlugin(entry, bases);
|
|
185
|
+
await plugin.register(program, host);
|
|
186
|
+
}
|
|
187
|
+
else {
|
|
188
|
+
addStub(program, entry, bases, argv);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return program;
|
|
192
|
+
}
|
|
193
|
+
/** Parse argv against the host program, mapping commander's clean exits. */
|
|
194
|
+
export async function runHost(argv, opts = {}) {
|
|
195
|
+
const program = await buildHostProgram(argv, opts);
|
|
196
|
+
try {
|
|
197
|
+
await program.parseAsync(argv, { from: 'user' });
|
|
198
|
+
}
|
|
199
|
+
catch (err) {
|
|
200
|
+
const e = err;
|
|
201
|
+
if (e.code === 'commander.helpDisplayed' ||
|
|
202
|
+
e.code === 'commander.version') {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
if (typeof e.code === 'string' && e.code.startsWith('commander.')) {
|
|
206
|
+
if (!process.exitCode)
|
|
207
|
+
process.exitCode = 1;
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
process.stderr.write(`${e.message ?? String(err)}\n`);
|
|
211
|
+
if (!process.exitCode)
|
|
212
|
+
process.exitCode = 1;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
/** The `gaia` entrypoint: drop node + script path, run the host. */
|
|
216
|
+
export async function main(argv) {
|
|
217
|
+
await runHost(argv.slice(2));
|
|
218
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { runUpgrade } from '@gaia-ai/conductor';
|
|
2
|
+
// GAIA-216: the `gaia upgrade` migration/seed routine was hoisted DOWN into the
|
|
3
|
+
// engine (`@gaia-ai/conductor`) so `conductor init` can call it intra-package
|
|
4
|
+
// without a host→engine→host cycle. The host keeps only the thin CLI
|
|
5
|
+
// registration below; the behaviour/output contract is unchanged. See
|
|
6
|
+
// `conductor/engine/src/cli/upgrade.ts` for `runUpgrade` + `UpgradeReport`.
|
|
7
|
+
/** Register `gaia upgrade` on the host program. */
|
|
8
|
+
export function registerUpgrade(program) {
|
|
9
|
+
program
|
|
10
|
+
.command('upgrade')
|
|
11
|
+
.description('migrate this install to the split config model (gaia.config.js connection + conductor.config.js engine; ~/.gaia/machine.config.js)')
|
|
12
|
+
.option('--dry-run', 'print the migration plan without writing anything', false)
|
|
13
|
+
.action((opts) => {
|
|
14
|
+
const report = runUpgrade({ dryRun: opts.dryRun });
|
|
15
|
+
for (const line of report.actions)
|
|
16
|
+
console.log(line);
|
|
17
|
+
if (report.alreadyCurrent)
|
|
18
|
+
console.log('gaia upgrade: already current');
|
|
19
|
+
else if (opts.dryRun)
|
|
20
|
+
console.log('gaia upgrade: dry run (no changes written)');
|
|
21
|
+
else
|
|
22
|
+
console.log('gaia upgrade: done');
|
|
23
|
+
});
|
|
24
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gaia-ai/gaia",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "GAIA meta package:
|
|
3
|
+
"version": "0.6.0",
|
|
4
|
+
"description": "GAIA meta package: the `gaia` plugin-host CLI + all runtime plugins. Global install target.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"engines": {
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"gaia": "./bin/gaia"
|
|
12
12
|
},
|
|
13
13
|
"exports": {
|
|
14
|
+
"./host": "./dist/src/host.js",
|
|
14
15
|
"./plugins": "./dist/src/plugins-barrel.js",
|
|
15
16
|
"./package.json": "./package.json"
|
|
16
17
|
},
|
|
@@ -26,7 +27,7 @@
|
|
|
26
27
|
"repository": {
|
|
27
28
|
"type": "git",
|
|
28
29
|
"url": "git+https://git.key-tec.de/keytec/gaia.git",
|
|
29
|
-
"directory": "conductor/
|
|
30
|
+
"directory": "conductor/host"
|
|
30
31
|
},
|
|
31
32
|
"keywords": [
|
|
32
33
|
"gaia",
|
|
@@ -37,13 +38,17 @@
|
|
|
37
38
|
"jsonapi"
|
|
38
39
|
],
|
|
39
40
|
"dependencies": {
|
|
40
|
-
"@gaia-ai/conductor": "^0.
|
|
41
|
-
"@gaia-ai/core": "^0.
|
|
42
|
-
"@gaia-ai/plugin-claude": "^0.
|
|
43
|
-
"@gaia-ai/plugin-codex": "^0.
|
|
44
|
-
"@gaia-ai/plugin-
|
|
45
|
-
"@gaia-ai/plugin-
|
|
46
|
-
"@gaia-ai/plugin-
|
|
47
|
-
"@gaia-ai/plugin-
|
|
41
|
+
"@gaia-ai/conductor": "^0.6.0",
|
|
42
|
+
"@gaia-ai/core": "^0.6.0",
|
|
43
|
+
"@gaia-ai/plugin-claude": "^0.6.0",
|
|
44
|
+
"@gaia-ai/plugin-codex": "^0.6.0",
|
|
45
|
+
"@gaia-ai/plugin-dropsh": "^0.6.0",
|
|
46
|
+
"@gaia-ai/plugin-essentials": "^0.6.0",
|
|
47
|
+
"@gaia-ai/plugin-gaia-ui": "^0.6.0",
|
|
48
|
+
"@gaia-ai/plugin-herdr": "^0.6.0",
|
|
49
|
+
"@gaia-ai/plugin-kimi": "^0.6.0",
|
|
50
|
+
"@gaia-ai/plugin-opencode": "^0.6.0",
|
|
51
|
+
"@gaia-ai/ui": "^0.6.0",
|
|
52
|
+
"commander": "^12.1.0"
|
|
48
53
|
}
|
|
49
54
|
}
|