@commonlyai/cli 0.1.353 → 0.1.355

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.353",
3
+ "version": "0.1.355",
4
4
  "license": "Apache-2.0",
5
5
  "description": "The Commonly CLI — connect agents, manage pods, iterate fast",
6
6
  "type": "module",
@@ -1126,8 +1126,9 @@ export const buildDefaultEnvironment = (adapterName) => {
1126
1126
  * (lib/unconfined-seat-guard.js `seatRunsUnconfined`) attaches only to a pod
1127
1127
  * confirmed private and invite-only; a pod whose visibility cannot be read
1128
1128
  * fails closed, and each turn checks again.
1129
- * dsh is private-only, so it requires a successful visibility read and rejects
1130
- * a public pod even without a sandbox declaration.
1129
+ * A dsh seat without public trust requires a successful visibility read and
1130
+ * rejects a public pod even without a sandbox declaration. A public-trust dsh
1131
+ * seat runs the public tool fence (adapters/dsh.js, F115) and attaches anywhere.
1131
1132
  */
1132
1133
  export const assertSandboxDeclaredForPublicPod = async ({
1133
1134
  client,
@@ -1139,7 +1140,7 @@ export const assertSandboxDeclaredForPublicPod = async ({
1139
1140
  }) => {
1140
1141
  if (!podId || !client) return;
1141
1142
 
1142
- if (adapterName === 'dsh') {
1143
+ if (adapterName === 'dsh' && effectiveSandboxTrust(environment?.sandbox?.trust) !== 'public') {
1143
1144
  let pod;
1144
1145
  try {
1145
1146
  pod = await client.get(`/api/pods/${podId}`);
@@ -1150,7 +1151,7 @@ export const assertSandboxDeclaredForPublicPod = async ({
1150
1151
  throw new Error('dsh requires confirmed private pod visibility before attach');
1151
1152
  }
1152
1153
  if (pod?.publicRead || pod?.communityListed) {
1153
- throw new Error('dsh supports private pods only; this pod is publicly readable');
1154
+ throw new Error('This pod is publicly readable. A dsh seat attaches to it only with "sandbox": { "trust": "public" }');
1154
1155
  }
1155
1156
  // dsh's confined shape stops here; an unconfined dsh runs as its owner and
1156
1157
  // meets the invite-only requirement below.
@@ -1427,7 +1428,9 @@ export const resolveAttachSandbox = ({
1427
1428
  // this they refused the only environment dsh accepts. The adapter's
1428
1429
  // check throws on every other shape, so this admits nothing it would refuse.
1429
1430
  if (typeof adapter?.confinesOwnSandbox === 'function' && adapter.confinesOwnSandbox(environment)) {
1430
- return { mode: environment.sandbox.mode, trust: environment.sandbox.trust };
1431
+ // A bare public dsh seat names no mode; its one shape is Seatbelt workspace,
1432
+ // so the Seatbelt check below runs at attach, not first at its spawn (F115).
1433
+ return { mode: environment.sandbox.mode || 'workspace', trust: environment.sandbox.trust };
1431
1434
  }
1432
1435
  const sandbox = normalizeSandboxTrust(environment?.sandbox);
1433
1436
  const trust = sandbox?.trust;
@@ -2360,6 +2363,11 @@ export const performRun = ({
2360
2363
  const scratchCwd = join(tmpdir(), 'commonly-agents', stateKey);
2361
2364
  const agentCwd = workspacePath || scratchCwd;
2362
2365
  if (!existsSync(agentCwd)) mkdirSync(agentCwd, { recursive: true });
2366
+ // A workspace seat still mounts its skills into the scratch folder (the
2367
+ // claude adapter's skillMountDir), and that mount's mkdir is not recursive:
2368
+ // on a machine that never ran this seat without a workspace, the first
2369
+ // turn failed ENOENT and opened the circuit.
2370
+ if (!existsSync(scratchCwd)) mkdirSync(scratchCwd, { recursive: true });
2363
2371
  // TASK-294: a pod can turn public after attach, so a workspace seat re-reads
2364
2372
  // its pods before every turn, and a turn it cannot confirm (a failed read
2365
2373
  // included) runs as a public seat in the scratch folder. The session is
@@ -0,0 +1,31 @@
1
+ /**
2
+ * F115: the dsh plugin a public seat's turn loads. The adapter copies this file
3
+ * into the turn's own folder and names it in the --patch; it is never read from
4
+ * anywhere a seat or a stranger can write.
5
+ *
6
+ * It refuses every tool call except a Commonly MCP tool that the adapter did not
7
+ * withhold. A tool a future dsh adds is refused too, without a code change.
8
+ * It also provides the service the Commonly MCP entry is gated on: if this file
9
+ * fails to load, the MCP never starts, so the turn has no tools at all rather
10
+ * than unguarded ones.
11
+ *
12
+ * Self-contained on purpose: it runs inside dsh and imports nothing.
13
+ * dsh.js holds the service name as DSH_PUBLIC_GUARD_SERVICE; a test holds them equal.
14
+ */
15
+ export const name = 'commonly-public-guard';
16
+ export const inject = ['tools'];
17
+
18
+ const PREFIX = 'mcp__commonly__';
19
+
20
+ export function apply(ctx, config) {
21
+ if (!Array.isArray(config?.withheld)) throw new Error('commonly-public-guard: config.withheld is required');
22
+ const withheld = new Set(config.withheld.map(String));
23
+ // The guard first: the service it provides is what lets the Commonly MCP start.
24
+ ctx.tools.guard((exec) => {
25
+ const tool = typeof exec?.name === 'string' ? exec.name : '';
26
+ const raw = tool.startsWith(PREFIX) ? tool.slice(PREFIX.length) : '';
27
+ if (raw && !withheld.has(raw)) return undefined;
28
+ return `${tool || 'This tool'} is not available on a public seat`;
29
+ });
30
+ ctx.provide('commonlyPublicGuard', Object.freeze({ withheld: [...withheld] }));
31
+ }
@@ -1,6 +1,10 @@
1
1
  import { observeSpawn } from '../runtime-observation.js';
2
2
  /**
3
- * DeepSeek Harness 0.2.1-rc.2, private seats only. Configuration is per spawn.
3
+ * DeepSeek Harness 0.2.1-rc.2. Configuration is per spawn.
4
+ *
5
+ * A public seat (F115) runs the confined shape below with dsh's own tools off,
6
+ * a guard plugin that refuses any call but a Commonly tool it may use, and the
7
+ * Commonly MCP gated on that guard; see DSH_PUBLIC_DISABLED_PLUGINS.
4
8
  *
5
9
  * A seat runs plain, or confined: `sandbox: { mode: 'workspace', network:
6
10
  * { policy: 'restricted' } }` runs dsh inside one Seatbelt profile that writes
@@ -33,6 +37,33 @@ import { writeCredentialFile } from '../credential-file.js';
33
37
  import { resolveProviderKeyFile, startProviderProxy } from '../provider-proxy.js';
34
38
  import { adapterFailure, spawnCredentials } from '../upstream-refusal.js';
35
39
  import { promptTokens } from '../session-recycle.js';
40
+ import { publicSeatWithheldTools } from '../public-withheld-tools.js';
41
+ import { PUBLIC_SEAT_MCP_ENV } from '../public-seat-mcp-flag.js';
42
+
43
+ /**
44
+ * F115: what a public seat's turn turns off. These are every headless-profile
45
+ * plugin that gives the model a tool of its own (shell, files, web, code,
46
+ * subagents, skills, jobs, workflows, goals, plan mode) or reads the working
47
+ * directory into the prompt. The guard plugin refuses anything that is still
48
+ * offered, so this list keeps the advertised set honest rather than being the
49
+ * only fence.
50
+ */
51
+ export const DSH_PUBLIC_DISABLED_PLUGINS = Object.freeze([
52
+ 'tool-bash', 'tool-pwsh', 'tool-jobs', 'tool-fs', 'tool-fs-search', 'tool-working-directory',
53
+ 'tool-skill', 'skill', 'skill-filesystem',
54
+ 'tool-subagent', 'tool-subagent-control', 'tool-subagent-list-agents', 'tool-subagent-fork',
55
+ 'subagent', 'subagent-spawn-in-process', 'subagent-fork-in-process',
56
+ 'tool-workflow', 'workflow-ptc', 'ptc-runtime', 'tool-todo', 'tool-goal',
57
+ 'tool-web', 'web', 'web-search-deepseek', 'web-deepseek-api', 'web-fetch-http',
58
+ 'mcp-resources', 'agent-instructions', 'plan-mode', 'goal', 'goal-round-driver', 'command-goal',
59
+ ]);
60
+ /** The service dsh-public-guard.mjs provides; the Commonly MCP entry is gated on it. */
61
+ export const DSH_PUBLIC_GUARD_SERVICE = 'commonlyPublicGuard';
62
+ /** A public turn's working directory, emptied before each turn, under the seat home. */
63
+ export const PUBLIC_TURN_DIR = 'public-turn';
64
+ const PUBLIC_GUARD_SOURCE = new URL('./dsh-public-guard.mjs', import.meta.url);
65
+ // The one thing a public seat's home keeps between turns (a symlink is not kept).
66
+ const PUBLIC_HOME_KEPT = 'sessions';
36
67
 
37
68
  export const TESTED_DSH_VERSIONS = Object.freeze(['0.2.1-rc.2']);
38
69
  const PROXY_KEY_ENV = 'COMMONLY_DSH_PROXY_KEY';
@@ -43,11 +74,14 @@ const SAFE_ENV = /^(?:PATH|LANG|LC_[A-Z_]+|TERM|USER|LOGNAME|NO_COLOR|CI|SSL_CER
43
74
  export const isConfinedDsh = (environment = {}) => {
44
75
  const sandbox = environment?.sandbox || {};
45
76
  refuseWorkspaceTrust(sandbox, 'dsh');
46
- if (effectiveSandboxTrust(sandbox.trust) === 'public') {
47
- throw new Error('dsh adapter: public-trust seats are not supported; nested Seatbelt fails closed');
48
- }
49
- if (sandbox.mode === undefined) return false;
50
- const { mode, network, ...rest } = sandbox;
77
+ // F115: public trust always runs the confined shape, with the public tool fence.
78
+ const isPublic = effectiveSandboxTrust(sandbox.trust) === 'public';
79
+ const { trust: _trust, ...publicShape } = sandbox;
80
+ const shape = isPublic ? publicShape : sandbox;
81
+ if (isPublic && Object.keys(shape).length === 0) return true;
82
+ // Only a private seat may run plain; a public one with any other key is refused below.
83
+ if (!isPublic && shape.mode === undefined) return false;
84
+ const { mode, network, ...rest } = shape;
51
85
  const networkKeys = Object.keys(network || {});
52
86
  if (mode === 'workspace' && network?.policy === 'restricted'
53
87
  && networkKeys.length === 1 && Object.keys(rest).length === 0) return true;
@@ -55,7 +89,11 @@ export const isConfinedDsh = (environment = {}) => {
55
89
  + "the one confined shape is { mode: 'workspace', network: { policy: 'restricted' } }");
56
90
  };
57
91
 
58
- export const assertPrivateDsh = (environment = {}) => { isConfinedDsh(environment); };
92
+ /** True for a public-trust seat (legacy `internal` included). */
93
+ export const isPublicDsh = (environment = {}) => effectiveSandboxTrust(environment?.sandbox?.trust) === 'public';
94
+
95
+ /** Throws on any sandbox this adapter cannot enforce. */
96
+ export const assertEnforceableDsh = (environment = {}) => { isConfinedDsh(environment); };
59
97
 
60
98
  /**
61
99
  * The macOS developer tools a confined writer needs for git, granted read-only.
@@ -131,7 +169,10 @@ export const assertServedModel = (check, credentials) => {
131
169
  /** A stable home per agent and Commonly instance, never the operator's ~/.dsh. */
132
170
  export const seatHome = (ctx) => {
133
171
  if (ctx._dshHome) return ctx._dshHome;
134
- const id = createHash('sha256').update(`${ctx.instanceUrl || ''}\0${ctx.agentName || ''}`).digest('hex').slice(0, 24);
172
+ // F115: a public seat never shares a home with a private turn of the same agent,
173
+ // which could plant a profile row or plugin there. A private seat's id is unchanged.
174
+ const trust = isPublicDsh(ctx.environment) ? '\0public' : '';
175
+ const id = createHash('sha256').update(`${ctx.instanceUrl || ''}\0${ctx.agentName || ''}${trust}`).digest('hex').slice(0, 24);
135
176
  return join(homedir(), '.commonly', 'dsh-homes', id);
136
177
  };
137
178
 
@@ -189,7 +230,10 @@ export const resolveCommonlyMcp = (declared, ctx) => {
189
230
  const values = { credentialFile: ctx.credentialFile, instanceUrl: ctx.instanceUrl };
190
231
  const env = Object.fromEntries(Object.entries(delivery.env)
191
232
  .map(([name, value]) => [name, substitute(value, values)]));
192
- if (Object.keys(env).some((name) => !['COMMONLY_API_URL', 'COMMONLY_TOKEN_FILE'].includes(name))
233
+ // A public seat's MCP always carries the public-seat flag, whatever was declared.
234
+ if (ctx.publicSeat) env[PUBLIC_SEAT_MCP_ENV] = '1';
235
+ const allowed = ['COMMONLY_API_URL', 'COMMONLY_TOKEN_FILE', ...(ctx.publicSeat ? [PUBLIC_SEAT_MCP_ENV] : [])];
236
+ if (Object.keys(env).some((name) => !allowed.includes(name))
193
237
  || env.COMMONLY_TOKEN_FILE !== ctx.credentialFile || env.COMMONLY_API_URL !== ctx.instanceUrl) {
194
238
  throw new Error('dsh adapter: Commonly MCP must use this spawn\'s credential file');
195
239
  }
@@ -206,7 +250,7 @@ export const resolveCommonlyMcp = (declared, ctx) => {
206
250
 
207
251
  /** JSON is valid YAML; a generated patch has no expression or quoting ambiguity. */
208
252
  export const buildPatch = ({
209
- proxyBaseURL, model, cwd, mcp, effort, deepseekOfficial = false, confined = false,
253
+ proxyBaseURL, model, cwd, mcp, effort, deepseekOfficial = false, confined = false, publicSeat = null,
210
254
  }) => ([
211
255
  { id: 'llm-pi-ai', config: { providers: {
212
256
  commonly: {
@@ -233,7 +277,13 @@ export const buildPatch = ({
233
277
  // Confined, the outer Seatbelt is the sandbox: dsh's own would nest a second
234
278
  // one, which macOS refuses, so it is off.
235
279
  { id: 'sandbox-policy', config: { mode: confined ? 'danger-full-access' : 'workspace-write', workspaceRoot: cwd } },
236
- { insert: [mcp] },
280
+ // F115: a public turn's native tools are off, the guard refuses whatever is
281
+ // left, and the Commonly MCP starts only once the guard's service exists.
282
+ ...(publicSeat ? [
283
+ ...DSH_PUBLIC_DISABLED_PLUGINS.map((id) => ({ id, disabled: true })),
284
+ { insert: [{ id: 'commonly-public-guard', name: publicSeat.guardPath, config: { withheld: [...publicSeat.withheld] } }] },
285
+ ] : []),
286
+ { insert: [publicSeat ? { ...mcp, inject: [DSH_PUBLIC_GUARD_SERVICE] } : mcp] },
237
287
  ]);
238
288
 
239
289
  export const assertPatchHasNoCredentials = (serialized, credentials) => {
@@ -350,7 +400,7 @@ export default {
350
400
  async validateEnvironment(environment, workspacePath) {
351
401
  const validation = validateEnvironmentSpec(environment);
352
402
  if (!validation.ok) throw new Error(validation.errors.join('; '));
353
- assertPrivateDsh(environment);
403
+ assertEnforceableDsh(environment);
354
404
  if (!environment?.provider || !environment?.model) {
355
405
  throw new Error('dsh requires environment.provider and environment.model');
356
406
  }
@@ -390,9 +440,25 @@ export default {
390
440
  throw new Error('dsh requires environment.provider and environment.model');
391
441
  }
392
442
  if (!ctx.runtimeToken || !ctx.instanceUrl) throw new Error('dsh requires a Commonly runtime token and instance URL');
443
+ const isPublic = confined && isPublicDsh(ctx.environment);
393
444
  const home = seatHome(ctx);
394
445
  await mkdir(home, { recursive: true, mode: 0o700 });
395
446
  await chmod(home, 0o700);
447
+ // F115: a public turn runs in an empty folder the adapter owns, so nothing a
448
+ // seat or a stranger put in the workspace (a .env dsh would load, say)
449
+ // reaches it. dsh also loads layers from its home: profiles/<name>/ (a user
450
+ // patch that may insert plugins, and their node_modules), cordis.patch.yml,
451
+ // .env, and HOME-relative module paths. So everything in a public home but
452
+ // its sessions is removed before each turn; dsh regenerates its stock profile.
453
+ let workspace = ctx.cwd;
454
+ if (isPublic) {
455
+ for (const entry of await readdir(home, { withFileTypes: true })) {
456
+ if (entry.name === PUBLIC_HOME_KEPT && entry.isDirectory()) continue;
457
+ await rm(join(home, entry.name), { recursive: true, force: true });
458
+ }
459
+ workspace = join(home, PUBLIC_TURN_DIR);
460
+ await mkdir(workspace, { mode: 0o700 });
461
+ }
396
462
  const binary = ctx._dshBinary || 'dsh';
397
463
  const sourceEnv = ctx.env || process.env;
398
464
  const version = readVersion(binary, childEnvironment(sourceEnv, home, ''));
@@ -419,9 +485,17 @@ export default {
419
485
  const mcpDirectories = [];
420
486
  if (confined) {
421
487
  relay = await startInstanceProxy({ instanceUrl: ctx.instanceUrl });
422
- egress = await (ctx._startEgressProxy || startEgressProxy)();
488
+ // A public turn has no tool that reaches the network, so it gets no egress at all.
489
+ if (!isPublic) egress = await (ctx._startEgressProxy || startEgressProxy)();
490
+ }
491
+ let publicSeat = null;
492
+ if (isPublic) {
493
+ const guardPath = join(tempDir, 'commonly-public-guard.mjs');
494
+ await writeFile(guardPath, await readFile(PUBLIC_GUARD_SOURCE), { mode: 0o600 });
495
+ publicSeat = { guardPath, withheld: publicSeatWithheldTools(ctx) };
423
496
  }
424
497
  const mcp = resolveCommonlyMcp(ctx.environment?.mcp, {
498
+ publicSeat: isPublic,
425
499
  credentialFile: credential.path,
426
500
  instanceUrl: confined ? relay.url : ctx.instanceUrl,
427
501
  ...(confined ? {
@@ -438,7 +512,7 @@ export default {
438
512
  });
439
513
  const patchData = buildPatch({
440
514
  proxyBaseURL: proxy.baseURL, model: seatModel,
441
- cwd: ctx.cwd, mcp, effort: ctx.environment.effort, confined,
515
+ cwd: workspace, mcp, effort: ctx.environment.effort, confined, publicSeat,
442
516
  deepseekOfficial: new URL(ctx.environment.provider.baseURL).hostname === 'api.deepseek.com',
443
517
  });
444
518
  const patch = JSON.stringify(patchData, null, 2);
@@ -450,7 +524,10 @@ export default {
450
524
  await chmod(patchPath, 0o600);
451
525
  const env = childEnvironment(sourceEnv, home, bearer);
452
526
  const resume = await sessionExists(home, ctx.sessionId);
453
- const fullPrompt = buildMemoryPreamble(prompt, ctx.memoryLongTerm, { freshSession: !resume });
527
+ // A public turn its owner didn't wake can't write memory, so the cue mustn't ask it to.
528
+ const fullPrompt = buildMemoryPreamble(prompt, ctx.memoryLongTerm, {
529
+ freshSession: !resume, ...(isPublic ? { memoryReadOnly: ctx.ownerWoken !== true } : {}),
530
+ });
454
531
  const args = ['--profile', 'headless', '--patch', patchPath, '--json',
455
532
  ...(resume ? ['--session-id', ctx.sessionId] : []), fullPrompt];
456
533
  const requested = Number(ctx.timeoutMs);
@@ -463,22 +540,29 @@ export default {
463
540
  const tempWork = join(home, 'tmp');
464
541
  await mkdir(tempWork, { recursive: true, mode: 0o700 });
465
542
  env.TMPDIR = tempWork;
466
- for (const name of ['HTTPS_PROXY', 'https_proxy', 'HTTP_PROXY', 'http_proxy']) env[name] = egress.url;
467
- env.NO_PROXY = '127.0.0.1,localhost';
468
- env.no_proxy = env.NO_PROXY;
543
+ if (egress) {
544
+ for (const name of ['HTTPS_PROXY', 'https_proxy', 'HTTP_PROXY', 'http_proxy']) env[name] = egress.url;
545
+ env.NO_PROXY = '127.0.0.1,localhost';
546
+ env.no_proxy = env.NO_PROXY;
547
+ }
469
548
  const developerDir = (ctx._developerToolsDir || developerToolsDir)({ env: sourceEnv });
470
549
  if (developerDir) {
471
550
  env.DEVELOPER_DIR = developerDir;
472
551
  env.PATH = systemToolsFirst(env.PATH);
473
552
  }
474
553
  [command, ...commandArgs] = (ctx._wrapArgvWithSeatbelt || wrapArgvWithSeatbelt)([process.execPath, entry, ...args], {
475
- workspacePath: ctx.cwd,
554
+ workspacePath: workspace,
476
555
  workspaceAccess: 'write',
556
+ // A public turn's folder is one the CLI made, so it is pinned: a link
557
+ // left there by an earlier turn's process is refused, not followed to a
558
+ // write grant on its target (as goose, opencode and claude pin theirs).
559
+ // A private seat's workspace is the operator's, and a link may be theirs.
560
+ pinWorkspace: isPublic,
477
561
  executablePath: process.execPath,
478
562
  statePath: home,
479
563
  mcpConfigDir: tempDir,
480
564
  network: 'loopback',
481
- loopbackNetworkPorts: [proxy.port, relay.port, egress.port],
565
+ loopbackNetworkPorts: [proxy.port, relay.port, ...(egress ? [egress.port] : [])],
482
566
  readOnlyDirectories: [packages, ...mcpDirectories, ...(developerDir ? [developerDir] : [])],
483
567
  });
484
568
  }
@@ -487,7 +571,7 @@ export default {
487
571
  let failure;
488
572
  try {
489
573
  result = await runDsh({
490
- binary: command, args: commandArgs, cwd: ctx.cwd, env, timeoutMs, credentials,
574
+ binary: command, args: commandArgs, cwd: workspace, env, timeoutMs, credentials,
491
575
  spawnImpl: ctx._spawnImpl, onSpawn: ctx.onSpawn, ownGroup: wantsOwnProcessGroup(ctx),
492
576
  controls: { model: passedModel || null, effort: passedProvider.reasoning || null },
493
577
  });
@@ -496,7 +580,7 @@ export default {
496
580
  }
497
581
  // A broken pin is the reason a turn failed, whatever dsh said about it.
498
582
  if (confined) {
499
- const { refusals } = egress.stats();
583
+ const refusals = egress ? egress.stats().refusals : [];
500
584
  // eslint-disable-next-line no-console
501
585
  if (refusals.length) console.warn(`[dsh] egress refused: ${refusals.map((r) => `${r.target} (${r.reason})`).join(', ')}`);
502
586
  assertServedModel(proxy.modelCheck(), credentials);