@commonlyai/cli 0.1.347 → 0.1.348

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": "@commonlyai/cli",
3
- "version": "0.1.347",
3
+ "version": "0.1.348",
4
4
  "license": "Apache-2.0",
5
5
  "description": "The Commonly CLI — connect agents, manage pods, iterate fast",
6
6
  "type": "module",
@@ -13,7 +13,7 @@ import {
13
13
  chmodSync, closeSync, existsSync, mkdirSync, openSync, rmSync, watch,
14
14
  } from 'fs';
15
15
  import { createClient } from '../lib/api.js';
16
- import { getToken, resolveInstanceUrl } from '../lib/config.js';
16
+ import { getToken, resolveInstance, resolveInstanceUrl } from '../lib/config.js';
17
17
  import {
18
18
  clearDaemonStop, loadDaemonRecord, loadDaemonStop, removeDaemonRecord,
19
19
  saveDaemonRecord, saveDaemonStop,
@@ -63,6 +63,24 @@ import { CLI } from '../lib/cli-hint.js';
63
63
  // Set on the steps `daemon setup` runs, so a step can leave a line to setup.
64
64
  const SETUP_CHILD_ENV = 'COMMONLY_DAEMON_SETUP_STEP';
65
65
 
66
+ // F459: login and register take --instance, so the first-timer walk tried it
67
+ // on run too and got "unknown option". Run serves the one registration this
68
+ // computer has, so --instance only confirms it: the same instance runs, any
69
+ // other (or an unknown saved key) is refused with the register line instead of
70
+ // quietly serving the registered one.
71
+ const instanceKey = (url) => String(url || '').replace(/\/+$/, '').toLowerCase();
72
+ export const daemonRunInstanceRefusal = (record, instanceArg, resolve = resolveInstance) => {
73
+ if (!instanceArg) return null;
74
+ const wanted = resolve(instanceArg)?.url;
75
+ if (wanted && instanceKey(wanted) === instanceKey(record?.instanceUrl)) return null;
76
+ if (!wanted) {
77
+ return `This computer is registered with ${record?.instanceUrl}, and no saved instance is named ${instanceArg}. `
78
+ + `To use another instance, sign in to it first (${CLI} login --instance <url>), then ${CLI} daemon register --instance <url>`;
79
+ }
80
+ return `This computer is registered with ${record?.instanceUrl}, not ${instanceArg}. To run it for that instance instead: `
81
+ + `${CLI} daemon register --instance ${instanceArg}`;
82
+ };
83
+
66
84
  // launchd, systemd and Task Scheduler hold one Commonly daemon per computer
67
85
  // account. Install refuses to stop another HOME's; this flag takes it over.
68
86
  const REPLACE_FLAG = '--replace';
@@ -681,6 +699,7 @@ Examples:
681
699
  .option('--poll <ms>', 'Work-list poll interval in ms', String(DEFAULT_POLL_MS))
682
700
  .option('--heartbeat <ms>', 'Heartbeat interval in ms', String(DEFAULT_HEARTBEAT_MS))
683
701
  .option('--foreground', 'Keep the supervisor attached to this terminal (default for direct invocation)')
702
+ .option('--instance <url-or-key>', 'Confirm the instance this computer is registered with')
684
703
  .action(async (opts) => {
685
704
  let record;
686
705
  try {
@@ -691,6 +710,12 @@ Examples:
691
710
  return;
692
711
  }
693
712
  record = requireDaemonRecord();
713
+ const instanceRefusal = daemonRunInstanceRefusal(record, opts.instance);
714
+ if (instanceRefusal) {
715
+ console.error(instanceRefusal);
716
+ process.exitCode = 1;
717
+ return;
718
+ }
694
719
  const stopped = loadDaemonStop(record);
695
720
  if (stopped) {
696
721
  console.error(`Daemon stopped: this computer's key was revoked. Run: ${CLI} daemon register`);
@@ -371,6 +371,8 @@ export default {
371
371
  const home = await mkdtemp(join(tmpdir(), 'commonly-goose-home-'));
372
372
  let proxy;
373
373
  let credentialRelease = null;
374
+ let reply = null;
375
+ let cleanupFailure = null;
374
376
  try {
375
377
  const credential = writeCredentialFile(ctx.runtimeToken, {
376
378
  root: tempDir, agentName: ctx.agentName || 'agent',
@@ -490,12 +492,19 @@ export default {
490
492
  spawnImpl,
491
493
  }).catch((err) => { throw releaseFailure || err; });
492
494
  if (releaseFailure) throw releaseFailure;
493
- return { text, newSessionId: null };
495
+ reply = { text, newSessionId: null };
494
496
  } finally {
495
497
  credentialRelease?.stop();
496
498
  try { await proxy?.close(); } finally {
497
- await Promise.all([tempDir, home].map((path) => rm(path, { recursive: true, force: true })));
499
+ const removed = await Promise.allSettled([tempDir, home].map((path) => rm(path, { recursive: true, force: true })));
500
+ cleanupFailure = removed.find((outcome) => outcome.status === 'rejected')?.reason || null;
498
501
  }
499
502
  }
503
+ // Reached only when the turn worked. A cleanup failure is then the turn's
504
+ // error: on a private seat that rm is the one delete of the credential, so
505
+ // the turn must not report success over it. When another error ended the
506
+ // turn (a failed release, say), it propagates past this and is kept.
507
+ if (cleanupFailure) throw cleanupFailure;
508
+ return reply;
500
509
  },
501
510
  };
@@ -367,6 +367,8 @@ export default {
367
367
  const mcpPath = join(tempDir, 'mcp.json');
368
368
  let proxy;
369
369
  let credentialRelease = null;
370
+ let reply = null;
371
+ let cleanupFailure = null;
370
372
  try {
371
373
  const credential = writeCredentialFile(ctx.runtimeToken, {
372
374
  agentName: ctx.agentName || 'agent', root: tempDir,
@@ -502,12 +504,19 @@ export default {
502
504
  credentials: [...spawnCredentials(ctx, []), proxyWithBearer.bearer],
503
505
  }).catch((err) => { throw releaseFailure || err; });
504
506
  if (releaseFailure) throw releaseFailure;
505
- return { text: result.text, newSessionId: null };
507
+ reply = { text: result.text, newSessionId: null };
506
508
  } finally {
507
509
  credentialRelease?.stop();
508
510
  try { await proxy?.close(); } catch { /* best effort */ }
509
- await Promise.all([tempDir, home].map((path) => rm(path, { recursive: true, force: true })));
511
+ const removed = await Promise.allSettled([tempDir, home].map((path) => rm(path, { recursive: true, force: true })));
512
+ cleanupFailure = removed.find((outcome) => outcome.status === 'rejected')?.reason || null;
510
513
  }
514
+ // Reached only when the turn worked. A cleanup failure is then the turn's
515
+ // error: on a private seat that rm is the one delete of the credential, so
516
+ // the turn must not report success over it. When another error ended the
517
+ // turn (a failed release, say), it propagates past this and is kept.
518
+ if (cleanupFailure) throw cleanupFailure;
519
+ return reply;
511
520
  },
512
521
  };
513
522