@commonlyai/cli 0.1.372 → 0.1.374

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.
@@ -21,6 +21,8 @@ const MAX_STDERR_CHARS = 4096;
21
21
  const MAX_LINE_CHARS = 1024 * 1024;
22
22
  // Keys the wrapper owns in the profile's .env. Every other line is the user's.
23
23
  const PROFILE_ENV_KEYS = ['OPENROUTER_API_KEY', 'OPENROUTER_BASE_URL'];
24
+ const HERMES_NO_PROVIDER = 'Hermes connects through OpenRouter only, so it can\'t use the provider block in this '
25
+ + 'environment file. Remove that block and set OPENROUTER_API_KEY where this agent runs.';
24
26
  const PLAIN_ENV_VALUE = /^[A-Za-z0-9_\-.:/+=@%~]+$/;
25
27
 
26
28
  const definedKey = (line) => {
@@ -214,17 +216,25 @@ export const createHermesAdapter = ({
214
216
  runtimeType: 'hermes',
215
217
  supportsProvider: false,
216
218
  providerKeyEnv: 'OPENROUTER_API_KEY',
219
+ // The CLI's shared provider check answers before validateEnvironment, so it
220
+ // reads this text for Hermes (F116).
221
+ noProviderRefusal: HERMES_NO_PROVIDER,
217
222
 
223
+ // F116: these refusals reach the person attaching their own agent, so each
224
+ // says what Hermes needs and what to do next, in words that person can act on.
218
225
  async validateEnvironment(environment) {
219
- if (environment?.provider !== undefined) {
220
- throw new Error('Hermes adapter does not consume environment.provider; supply OPENROUTER_API_KEY in the host environment');
221
- }
226
+ if (environment?.provider !== undefined) throw new Error(HERMES_NO_PROVIDER);
222
227
  if (environment?.mcp?.length) {
223
- throw new Error('Hermes adapter does not yet consume environment.mcp declarations');
228
+ throw new Error('Commonly can\'t give Hermes extra MCP servers yet, so this environment file can\'t '
229
+ + 'list any. Remove the mcp block to run Hermes.');
230
+ }
231
+ if (effectiveTrust(environment?.sandbox?.trust) === 'public') {
232
+ throw new Error('Commonly has no sandbox for Hermes yet, so Hermes can\'t run as a public seat. '
233
+ + 'Pick another harness for a public seat.');
224
234
  }
225
- if (effectiveTrust(environment?.sandbox?.trust) === 'public'
226
- || (environment?.sandbox?.mode && environment.sandbox.mode !== 'none')) {
227
- throw new Error('Hermes public or sandbox-declared seats are unsupported: no enforced confinement adapter exists');
235
+ if (environment?.sandbox?.mode && environment.sandbox.mode !== 'none') {
236
+ throw new Error(`This environment file asks for sandbox.mode=${environment.sandbox.mode}, and Commonly `
237
+ + 'has no sandbox for Hermes yet, so Hermes can\'t run under it.');
228
238
  }
229
239
  },
230
240
 
@@ -247,7 +257,8 @@ export const createHermesAdapter = ({
247
257
  throw new Error(`Hermes Agent ${SUPPORTED_HERMES_VERSION_RANGE} is not on PATH; install for your OS: https://hermes-agent.nousresearch.com/docs/getting-started/installation`);
248
258
  }
249
259
  if (!env.OPENROUTER_API_KEY) {
250
- throw new Error('Supply the operator OPENROUTER_API_KEY through Secret Manager before running Hermes');
260
+ throw new Error('Hermes connects through OpenRouter only. Set OPENROUTER_API_KEY where this agent runs, '
261
+ + 'then start it again.');
251
262
  }
252
263
  await syncProfileEnv(home, env);
253
264
  const cwd = ctx.cwd || process.cwd();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commonlyai/cli",
3
- "version": "0.1.372",
3
+ "version": "0.1.374",
4
4
  "license": "Apache-2.0",
5
5
  "description": "The Commonly CLI — connect agents, manage pods, iterate fast",
6
6
  "type": "module",
@@ -143,6 +143,7 @@ import {
143
143
  spawnRetryJitter,
144
144
  spawnRetryPolicy,
145
145
  } from '../lib/spawn-retry.js';
146
+ import { explainNarrowing, narrowingConfirmBody } from '../lib/install-narrowing.js';
146
147
  import {
147
148
  CONTENT_REFUSED_REASON,
148
149
  composeRefusalHandoff,
@@ -181,6 +182,10 @@ import { buildReplyReceipt } from '../lib/reply-receipt.js';
181
182
  import { savedRuntimeControls, withSavedRuntimeControls, effortRefusedByDevice } from '../lib/seat-runtime-controls.js';
182
183
  import { CLI } from '../lib/cli-hint.js';
183
184
 
185
+ // F167: shared by attach, init and register.
186
+ const NARROWING_FLAG_HELP = 'Install even when joining this pod would limit where the agent can write in its other pods '
187
+ + '(the install says which pods first)';
188
+
184
189
  const isPodFocusDiagnostic = (error) => (
185
190
  typeof error?.code === 'string'
186
191
  && (error.code.startsWith('pod_focus') || error.code.startsWith('FOCUS_FRAME_'))
@@ -1502,6 +1507,8 @@ export const performAttach = async ({
1502
1507
  wakeOnMessage = false,
1503
1508
  memoryFrom = null,
1504
1509
  memoryInstance = 'default',
1510
+ // F167: confirm the install route's narrowing warning (F164).
1511
+ confirmNarrowing = false,
1505
1512
  log = () => {},
1506
1513
  adapterRegistry = { getAdapter, listAdapterNames, listPublicAdapterNames },
1507
1514
  seatbelt: probeSeatbelt = detectSeatbelt,
@@ -1693,6 +1700,7 @@ export const performAttach = async ({
1693
1700
  ...(memoryFrom ? {
1694
1701
  resumeExisting: true, memoryFrom: { agentName: memoryFrom, instanceId: memoryInstance },
1695
1702
  } : {}),
1703
+ ...narrowingConfirmBody(confirmNarrowing),
1696
1704
  agentName,
1697
1705
  podId,
1698
1706
  displayName: displayName || agentName,
@@ -1710,7 +1718,7 @@ export const performAttach = async ({
1710
1718
  ...(wakeOnMessage ? { wakeOnMessage: { enabled: true } } : {}),
1711
1719
  },
1712
1720
  scopes: ['context:read', 'messages:write', 'memory:read', 'memory:write'],
1713
- });
1721
+ }).catch((error) => { throw explainNarrowing(error); });
1714
1722
 
1715
1723
  const installation = installResult.installation || installResult;
1716
1724
  const instanceId = installation.instanceId || 'default';
@@ -5239,6 +5247,7 @@ export const performInit = async ({
5239
5247
  podId,
5240
5248
  displayName,
5241
5249
  targetDir,
5250
+ confirmNarrowing = false,
5242
5251
  }) => {
5243
5252
  const recipe = SDK_SOURCES[language];
5244
5253
  if (!recipe) {
@@ -5267,12 +5276,21 @@ export const performInit = async ({
5267
5276
  // Self-serve install (ADR-006). No publish step; the backend synthesizes
5268
5277
  // an ephemeral registry row when no manifest exists for this name.
5269
5278
  const installResult = await client.post('/api/registry/install', {
5279
+ ...narrowingConfirmBody(confirmNarrowing),
5270
5280
  agentName,
5271
5281
  podId,
5272
5282
  displayName: displayName || agentName,
5273
5283
  version: '1.0.0',
5274
5284
  config: { runtime: { runtimeType: 'webhook', host: 'byo' } },
5275
5285
  scopes: ['context:read', 'messages:write', 'memory:read', 'memory:write'],
5286
+ }).catch((error) => {
5287
+ // The guard above proved neither file existed, so these two are this
5288
+ // attempt's own. Remove them, or the re-run a refusal advises (F167:
5289
+ // --confirm-narrowing) stops at that same guard before it installs.
5290
+ for (const written of [sdkOutPath, botOutPath]) {
5291
+ try { rmSync(written, { force: true }); } catch { /* the install error is the one to report */ }
5292
+ }
5293
+ throw explainNarrowing(error);
5276
5294
  });
5277
5295
  const installation = installResult.installation || installResult;
5278
5296
  const instanceId = installation.instanceId || 'default';
@@ -5450,6 +5468,7 @@ Docs:
5450
5468
  .requiredOption('--webhook <url>', 'Webhook URL (e.g. https://my-agent.example.com/cap)')
5451
5469
  .option('--secret <secret>', 'Webhook signing secret (HMAC-SHA256)')
5452
5470
  .option('--display <name>', 'Display name shown in the pod')
5471
+ .option('--confirm-narrowing', NARROWING_FLAG_HELP)
5453
5472
  .option('--instance <url>', 'Target Commonly instance')
5454
5473
  .action(async (opts) => {
5455
5474
  const instanceUrl = resolveInstanceUrl(opts.instance);
@@ -5473,6 +5492,7 @@ Docs:
5473
5492
  });
5474
5493
 
5475
5494
  const result = await client.post('/api/registry/install', {
5495
+ ...narrowingConfirmBody(opts.confirmNarrowing === true),
5476
5496
  agentName: opts.name,
5477
5497
  podId: opts.pod,
5478
5498
  displayName: opts.display || opts.name,
@@ -5486,7 +5506,7 @@ Docs:
5486
5506
  },
5487
5507
  },
5488
5508
  scopes: ['context:read', 'messages:write', 'memory:read'],
5489
- });
5509
+ }).catch((error) => { throw explainNarrowing(error); });
5490
5510
 
5491
5511
  const installation = result.installation || result;
5492
5512
  const instId = installation.instanceId || 'default';
@@ -5600,6 +5620,7 @@ Docs:
5600
5620
  .option('--import-memory [path]', 'Import local memory (CLAUDE.md / MEMORY.md / ~/.claude project memory, or a given file/dir) into the agent after attach')
5601
5621
  .option('--yes', 'Skip the import confirmation prompt')
5602
5622
  .option('--wake-on-message', `Wake this agent on every message in the pod, not only @mentions (ADR-018 ambient wake; default off). Change later with: ${CLI} agent wake <name> on|off`)
5623
+ .option('--confirm-narrowing', NARROWING_FLAG_HELP)
5603
5624
  .option('--instance <url>', 'Target Commonly instance')
5604
5625
  .action(async (adapterName, opts) => {
5605
5626
  const instanceUrl = resolveInstanceUrl(opts.instance);
@@ -5623,6 +5644,7 @@ Docs:
5623
5644
  wakeOnMessage: Boolean(opts.wakeOnMessage),
5624
5645
  memoryFrom: opts.memoryFrom,
5625
5646
  memoryInstance: opts.memoryInstance,
5647
+ confirmNarrowing: opts.confirmNarrowing === true,
5626
5648
  log: (line) => console.warn(`[attach] ${line}`),
5627
5649
  });
5628
5650
 
@@ -6174,6 +6196,7 @@ Docs:
6174
6196
  .requiredOption('--pod <podId>', 'Pod ID to install into')
6175
6197
  .option('--display <name>', 'Display name shown in the pod')
6176
6198
  .option('--dir <path>', 'Target directory (default: current dir)')
6199
+ .option('--confirm-narrowing', NARROWING_FLAG_HELP)
6177
6200
  .option('--instance <url>', 'Target Commonly instance')
6178
6201
  .action(async (opts) => {
6179
6202
  const instanceUrl = resolveInstanceUrl(opts.instance);
@@ -6190,6 +6213,7 @@ Docs:
6190
6213
  podId: opts.pod,
6191
6214
  displayName: opts.display,
6192
6215
  targetDir: pathResolve(opts.dir || process.cwd()),
6216
+ confirmNarrowing: opts.confirmNarrowing === true,
6193
6217
  });
6194
6218
 
6195
6219
  console.log(`✓ Written: ${result.files.bot}`);
@@ -200,10 +200,13 @@ export const PROVIDER_APIS = Object.freeze(['openai-chat', 'anthropic-messages',
200
200
  // One provider check for config, attach, run and the daemon's adapter swap: the adapter must take a
201
201
  // provider block at all, and speak its `provider.api` (default openai-chat). An adapter's
202
202
  // `providerVerdict(environment)` answers first when it returns a refusal or null (accepted);
203
- // undefined leaves the seat to this check.
203
+ // undefined leaves the seat to this check. An adapter that takes no provider block may name
204
+ // its own refusal (`noProviderRefusal`), so the person sees why in that harness's terms (F116).
204
205
  export const providerRefusal = (environment, adapter) => {
205
206
  if (environment?.provider === undefined) return null;
206
- if (!adapter?.supportsProvider) return 'environment.provider requires a provider-capable adapter';
207
+ if (!adapter?.supportsProvider) {
208
+ return adapter?.noProviderRefusal || 'environment.provider requires a provider-capable adapter';
209
+ }
207
210
  const verdict = adapter.providerVerdict?.(environment);
208
211
  if (verdict !== undefined) return verdict;
209
212
  const api = environment.provider?.api || 'openai-chat';
@@ -0,0 +1,33 @@
1
+ /**
2
+ * F167: the install route's narrowing confirmation (F164), from the CLI.
3
+ *
4
+ * Joining a pod can confine a seat's writes in its other pods (an
5
+ * outside-writable grant narrows it; backend agentRuntimeAuth). Before the
6
+ * install is written the route answers 409 with this code and a sentence naming
7
+ * what would change. The installer confirms by sending `confirmNarrowing: true`.
8
+ * The server's text ends with that API advice, so the CLI swaps it for its own
9
+ * flag.
10
+ */
11
+
12
+ // Mirrors backend services/outsiderGrantNarrowingPreview.ts NARROWING_CONFIRM_CODE.
13
+ export const NARROWING_CONFIRM_CODE = 'outsider_grant_narrowing_confirm_required';
14
+
15
+ const API_ADVICE = /\s*Send confirmNarrowing: true to install anyway\.\s*$/;
16
+ const CLI_ADVICE = 'Re-run with --confirm-narrowing to install anyway.';
17
+
18
+ /** The install body field for --confirm-narrowing: present only when set. */
19
+ export const narrowingConfirmBody = (confirm) => (confirm === true ? { confirmNarrowing: true } : {});
20
+
21
+ /**
22
+ * The same refusal, telling a CLI user the flag instead of the API field. Any
23
+ * other error is returned as it came.
24
+ */
25
+ export const explainNarrowing = (error) => {
26
+ if (error?.status !== 409 || error?.body?.code !== NARROWING_CONFIRM_CODE) return error;
27
+ const said = String(error.body.message || error.message || '').replace(API_ADVICE, '').trim();
28
+ const explained = new Error(said ? `${said} ${CLI_ADVICE}` : CLI_ADVICE);
29
+ explained.status = error.status;
30
+ explained.body = error.body;
31
+ explained.code = NARROWING_CONFIRM_CODE;
32
+ return explained;
33
+ };