@onesi/genesis-cli 0.2.4 → 0.2.5

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/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  `genesis`, the OneOS command line. It works against the Genesis API at `https://os.one.ml/api`.
4
4
 
5
5
  ```sh
6
- npx -y @onesi/genesis-cli@0.2.4 --help
6
+ npx -y @onesi/genesis-cli@0.2.5 --help
7
7
  ```
8
8
 
9
9
  ## First run
package/dist/fleets.js CHANGED
@@ -76,9 +76,11 @@ export function registerFleets(program, client, emit, keyInput = readFoundryKey)
76
76
  instances.command('start <instance_id>').description('Connect already admitted Henry compute').option('--idempotency-key <uuid>', 'canonical UUID4 to retain after an uncertain reply').action(async (id, options) => emit(await (await client()).fleets.instances.start(id, { idempotencyKey: options.idempotencyKey })));
77
77
  const connection = fleets.command('connection').description('Organization-owned Foundry connection');
78
78
  connection.command('get').action(async () => emit(await (await client()).fleets.connection.get()));
79
- connection.command('set').description('Read a Foundry key from stdin and encrypt it with Genesis KMS').action(async () => {
79
+ connection.command('set').description('Read a Foundry key from stdin and encrypt it with Genesis KMS')
80
+ .option('--model <id>', 'Foundry model for this organization\'s tasks (must be listed by Foundry for the key); default gpt-4.1-mini')
81
+ .action(async (options) => {
80
82
  const apiKey = await keyInput();
81
- emit(await (await client()).fleets.connection.set(apiKey));
83
+ emit(await (await client()).fleets.connection.set(apiKey, options.model !== undefined ? { model: options.model } : {}));
82
84
  });
83
85
  connection.command('delete').action(async () => emit(await (await client()).fleets.connection.delete()));
84
86
  const usage = fleets.command('usage').description('Usage observations derived from your tasks');
@@ -0,0 +1,8 @@
1
+ import type { Command } from 'commander';
2
+ import { type Genesis } from '@onesi/genesis';
3
+ /**
4
+ * Every `genesis hives` command with a <project_id>: the help says "Hives project id (prj_…)"; a Genesis pr_… id of
5
+ * the selected context resolves to its Hives binding, and where project_id is the last argument of a command that
6
+ * does not delete or end anything it may be omitted. The binding is read once per invocation, before the action.
7
+ */
8
+ export declare function registerHivesProjectDefault(hives: Command, client: () => Promise<Genesis>): void;
@@ -0,0 +1,31 @@
1
+ import { HIVES_PROJECT_ID_DEFAULT, HIVES_PROJECT_ID_DESCRIPTION, isGenesisProjectId } from '@onesi/genesis';
2
+ /** Commands that delete or end something keep an explicit project id: an omitted one never defaults. */
3
+ const EXPLICIT = /^(?:delete|remove|purge|uninstall|destroy|stop|cancel|rollback|detach)/;
4
+ const projectArgument = (command) => command.registeredArguments.findIndex((a) => a.name() === 'project_id');
5
+ /**
6
+ * Every `genesis hives` command with a <project_id>: the help says "Hives project id (prj_…)"; a Genesis pr_… id of
7
+ * the selected context resolves to its Hives binding, and where project_id is the last argument of a command that
8
+ * does not delete or end anything it may be omitted. The binding is read once per invocation, before the action.
9
+ */
10
+ export function registerHivesProjectDefault(hives, client) {
11
+ const visit = (command) => {
12
+ const at = projectArgument(command);
13
+ if (at >= 0 && command.parent?.name() !== 'context') {
14
+ const argument = command.registeredArguments[at];
15
+ const optional = at === command.registeredArguments.length - 1 && !argument.variadic && !EXPLICIT.test(command.name());
16
+ argument.description = optional ? `${HIVES_PROJECT_ID_DESCRIPTION}; ${HIVES_PROJECT_ID_DEFAULT}` : HIVES_PROJECT_ID_DESCRIPTION;
17
+ if (optional)
18
+ argument.required = false;
19
+ }
20
+ command.commands.forEach(visit);
21
+ };
22
+ hives.commands.forEach(visit);
23
+ hives.hook('preAction', async (_hooked, action) => {
24
+ const at = projectArgument(action);
25
+ if (at < 0 || action.parent?.name() === 'context')
26
+ return;
27
+ const value = action.processedArgs[at];
28
+ if (value === undefined || isGenesisProjectId(value))
29
+ action.processedArgs[at] = await (await client()).hives.resolveProject(value);
30
+ });
31
+ }
package/dist/index.js CHANGED
@@ -20,6 +20,7 @@ import { registerRunner } from './runner.js';
20
20
  import { createHivesNodeTransport } from './hives-node-transport.js';
21
21
  import { registerHivesOperations } from './hives-operations.js';
22
22
  import { registerHivesCoverage } from './hives-coverage.js';
23
+ import { registerHivesProjectDefault } from './hives-project.js';
23
24
  import { readFunctionFile, readFunctionJson, writeFunctionOutput } from './function-input.js';
24
25
  import { basename } from 'node:path';
25
26
  import { readWasmFile } from './wasm-input.js';
@@ -40,7 +41,7 @@ export function buildProgram(deps = {}) {
40
41
  const auth = { ...authConfig(env, f), sleep: deps.sleep };
41
42
  const program = new Command('genesis')
42
43
  .description('One CLI for every Genesis service.')
43
- .version('0.2.4')
44
+ .version('0.2.5')
44
45
  .option('--json', 'machine-readable JSON output')
45
46
  .option('--api-key <key>', 'use this API key (default: GENESIS_API_KEY, then your `genesis login`)')
46
47
  .option('--base-url <url>', 'gateway URL (default: GENESIS_BASE_URL or https://os.one.ml/api)')
@@ -56,7 +57,7 @@ export function buildProgram(deps = {}) {
56
57
  const opts = {
57
58
  apiKey: o.apiKey ?? env.GENESIS_API_KEY, token: env.GENESIS_TOKEN,
58
59
  baseUrl: o.baseUrl ?? env.GENESIS_BASE_URL, routing: o.direct || env.GENESIS_ROUTING === 'direct' ? 'direct' : 'gateway',
59
- fetch: f, userAgent: 'genesis-cli/0.2.4',
60
+ fetch: f, userAgent: 'genesis-cli/0.2.5',
60
61
  credentials: store ? savedLoginProvider(auth, store) : undefined,
61
62
  };
62
63
  return new Genesis(hivesTransport ? { ...opts, fetch: createHivesNodeTransport(opts, deps.signal) } : opts);
@@ -277,7 +278,7 @@ export function buildProgram(deps = {}) {
277
278
  if (!key)
278
279
  throw new Error('Give the enrollment key with --key-file, --key-stdin or GENESIS_ENROLLMENT_KEY; it is never accepted as an argument.');
279
280
  const body = await readFunctionJson(o.bodyFile, 16 * 1024);
280
- const result = await new Genesis({ baseUrl: g().baseUrl ?? env.GENESIS_BASE_URL, fetch: f, userAgent: 'genesis-cli/0.2.4' }).iam.agents.enroll(key, body);
281
+ const result = await new Genesis({ baseUrl: g().baseUrl ?? env.GENESIS_BASE_URL, fetch: f, userAgent: 'genesis-cli/0.2.5' }).iam.agents.enroll(key, body);
281
282
  emit(result, () => JSON.stringify(result, null, 2));
282
283
  });
283
284
  // ---- auth ------------------------------------------------------------
@@ -691,6 +692,8 @@ export function buildProgram(deps = {}) {
691
692
  });
692
693
  // Last: extends the hives groups defined above (flights, logs, env values, domain reads).
693
694
  registerHivesCoverage(hives, { client: hivesClient, emit, readRequest: deps.readHivesRequest });
695
+ // After every hives command exists: prj_… help, and pr_… or omitted project ids resolved from the selected context.
696
+ registerHivesProjectDefault(hives, hivesClient);
694
697
  // ---- relays ----------------------------------------------------------
695
698
  const relays = program.command('relays').description('Relays: DNS zones and records');
696
699
  registerRelaysEnrollment(relays, client, emit);
@@ -810,7 +813,7 @@ export function buildProgram(deps = {}) {
810
813
  const url = `${base.href.replace(/\/+$/, '')}/v1/status`;
811
814
  let response;
812
815
  try {
813
- response = await f(url, { method: 'GET', headers: { accept: 'application/json', 'user-agent': 'genesis-cli/0.2.4' }, signal: AbortSignal.timeout(15_000) });
816
+ response = await f(url, { method: 'GET', headers: { accept: 'application/json', 'user-agent': 'genesis-cli/0.2.5' }, signal: AbortSignal.timeout(15_000) });
814
817
  }
815
818
  catch (e) {
816
819
  throw new Error(`Gateway unreachable at ${safe(url)}: ${safe(e.message)}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onesi/genesis-cli",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/l1felabs/genesis-api.git",
@@ -33,7 +33,7 @@
33
33
  "dependencies": {
34
34
  "commander": "^14.0.0",
35
35
  "undici": "6.29.0",
36
- "@onesi/genesis": "0.2.4"
36
+ "@onesi/genesis": "0.2.5"
37
37
  },
38
38
  "optionalDependencies": {
39
39
  "@napi-rs/keyring": "^1.2.0"