@commonlyai/cli 0.1.284 → 0.1.286

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.284",
3
+ "version": "0.1.286",
4
4
  "license": "Apache-2.0",
5
5
  "description": "The Commonly CLI — connect agents, manage pods, iterate fast",
6
6
  "type": "module",
@@ -873,7 +873,7 @@ const HELD_RETRY_MAX_FAILURES = 3;
873
873
  const PAST_CAP_MAX_CARRIES = 5;
874
874
 
875
875
  // Who gets a slot when a batch is past the cap. 'unknown' counts as a person:
876
- // the snapshot behind `trigger` holds 10 messages and a page holds up to 50, and
876
+ // only a row the snapshot and the kernel's stamp both can't place reads so, and
877
877
  // a wrong guess costs an ambient item one turn. Within a rank the older row
878
878
  // wins, and carried rows lead the page, so new arrivals can't overtake them.
879
879
  const capRank = (entry) => {
@@ -1760,7 +1760,7 @@ export const answersInChannel = (entry) => {
1760
1760
  // line offered silence on every turn. A turn that answers a person drops that
1761
1761
  // exit: NO_REPLY stays only as the way to end after a reply posted through a
1762
1762
  // tool, so the wrapper doesn't post a second one. It needs the sender known to
1763
- // be human, so an agent's @ and a message off the snapshot keep the old line. A
1763
+ // be human, so an agent's @ and a message nobody can place keep the old line. A
1764
1764
  // seat whose peer holds the claim keeps it too: the peer is answering them. So
1765
1765
  // do two chat.mention wakes where nobody typed the seat's name: an adjacent
1766
1766
  // reply and a new member's welcome, whose kernel frames offer NO_REPLY.
@@ -3817,14 +3817,11 @@ export const performRun = ({
3817
3817
  );
3818
3818
  if (!admission.allowed) {
3819
3819
  // An agent row refuses the page, and that shouldn't cost a row nobody
3820
- // can place: a person's message that scrolled off the snapshot reads
3821
- // `unknown`. It is carried, past-cap bound included, and alone in its
3822
- // next page it can't be refused, because only 'agent' ever is. A row
3823
- // stamped as an agent's is placed, so it stays refused, or it would walk
3824
- // past this brake. A legacy row has no stamp, and still carries.
3820
+ // can place: one past the snapshot with no stamp reads `unknown`. It is
3821
+ // carried, past-cap bound included, and alone in its next page it can't
3822
+ // be refused, because only 'agent' ever is.
3825
3823
  for (const entry of wakingEntries) {
3826
- if (entry.trigger === 'unknown' && entry.event.payload?.messageId
3827
- && entry.event.payload?.senderIsHuman !== false) entry.pastCap = true;
3824
+ if (entry.trigger === 'unknown' && entry.event.payload?.messageId) entry.pastCap = true;
3828
3825
  else entry.result = batchAdmissionResult(entry.event, admission);
3829
3826
  }
3830
3827
  carryPastCap();
@@ -604,7 +604,7 @@ Examples:
604
604
  // unaffected, and refusing to start would turn one missing key into a
605
605
  // whole-machine outage.
606
606
  for (const name of missingProviderKeys({ names: providerKeyEnvNames() })) {
607
- stampLog(`WARNING: ${name} is not set in this environment — a seat whose adapter needs it will fail to start. Export it and re-run: commonly daemon install (docs/agents/daemon-service-environment.md)`);
607
+ stampLog(`WARNING: ${name} is not set in this environment — a seat that relies on it will fail to start (one with its own provider.keyFile won't). Export it and re-run: commonly daemon install (docs/agents/daemon-service-environment.md)`);
608
608
  }
609
609
  // TASK-660: the daemon outlives many publishes, so say once at start-up
610
610
  // when it is stale. Not awaited: supervision never waits on the registry.
@@ -9,7 +9,7 @@ export default function commonlyShellEnvironment(pi) {
9
9
  const providerKey = process.env.COMMONLY_PI_PROVIDER_KEY_ENV;
10
10
  if (!providerKey) throw new Error('pi adapter: missing provider key environment name');
11
11
  const excluded = new Set([
12
- providerKey, 'COMMONLY_LITELLM_KEY', 'COMMONLY_PI_PROVIDER_KEY_ENV',
12
+ providerKey, 'COMMONLY_LITELLM_KEY', 'COMMONLY_PI_PROVIDER_KEY', 'COMMONLY_PI_PROVIDER_KEY_ENV',
13
13
  ].map((key) => key.toUpperCase()));
14
14
  const cleanEnv = (env) => {
15
15
  const clean = { ...env };
@@ -23,7 +23,8 @@
23
23
  * - Provider config is a per-seat models.json under
24
24
  * `~/.commonly/pi-homes/<hash>/agent`, pointed at by
25
25
  * PI_CODING_AGENT_DIR — never the operator's ~/.pi. The API key is an
26
- * env reference (`$COMMONLY_LITELLM_KEY`), so it never lands on disk.
26
+ * env reference (`$COMMONLY_LITELLM_KEY`, or `$COMMONLY_PI_PROVIDER_KEY`
27
+ * for a seat with its own provider.keyFile), so it never lands on disk.
27
28
  * - Commonly's tools reach pi through pi-commonly-mcp.mjs, an extension
28
29
  * that speaks MCP over stdio to every server in `environment.mcp` and
29
30
  * registers each tool. The token rides through the child env, never argv
@@ -47,9 +48,11 @@ import { resolveOnPath } from '../resolve-on-path.js';
47
48
  import { spawn as childSpawn, spawnSync } from 'child_process';
48
49
  import { createHash, randomUUID } from 'crypto';
49
50
  import { existsSync, readFileSync, realpathSync, rmSync } from 'fs';
50
- import { mkdir, readdir, writeFile } from 'fs/promises';
51
+ import { mkdir, readdir, readFile, writeFile } from 'fs/promises';
51
52
  import { homedir } from 'os';
52
- import { dirname, isAbsolute, join } from 'path';
53
+ import {
54
+ dirname, isAbsolute, join, relative, sep,
55
+ } from 'path';
53
56
  import { fileURLToPath } from 'url';
54
57
  import {
55
58
  adapterFailure,
@@ -57,14 +60,16 @@ import {
57
60
  spawnCredentials,
58
61
  } from '../upstream-refusal.js';
59
62
  import { buildMemoryPreamble } from '../memory-bridge.js';
60
- import { effectiveSandboxTrust, normalizeSandboxTrust, refuseWorkspaceTrust } from '../environment.js';
63
+ import {
64
+ effectiveSandboxTrust, normalizeSandboxTrust, refuseWorkspaceTrust, validateEnvironmentSpec,
65
+ } from '../environment.js';
61
66
  import { GRANT_BROKER_PUBLIC_ONLY_REFUSAL, isGrantBrokerUrl } from './pi-mcp-client.mjs';
62
67
  import { deliverSeatCredential, withholdRuntimeCredential } from '../mcp-credential-delivery.js';
63
68
  import { prepareMcpSpawn, publicMcpUnavailableError, selectedMcpVersionDir } from '../mcp-home.js';
64
69
  import { removeCredentialFile, writeCredentialFile } from '../credential-file.js';
65
70
  import { resolvePublicSandboxMode } from '../sandbox/mode.js';
66
71
  import { wrapArgvWithSeatbelt } from '../sandbox/seatbelt.js';
67
- import { startProviderProxy } from '../provider-proxy.js';
72
+ import { resolveProviderKeyFile, startProviderProxy } from '../provider-proxy.js';
68
73
  import { PUBLIC_SEAT_WITHHELD_TOOLS } from '../public-withheld-tools.js';
69
74
 
70
75
  const DEFAULT_TIMEOUT_MS = (() => {
@@ -84,6 +89,21 @@ export const DEFAULT_PROVIDER = Object.freeze({
84
89
  apiKeyEnv: 'COMMONLY_LITELLM_KEY',
85
90
  });
86
91
 
92
+ // What a seat with its own `provider.keyFile` calls its key inside pi. A private
93
+ // turn holds the key here, and pi-shell-env.mjs keeps it out of pi's shells. A
94
+ // public turn holds the proxy's token here. models.json holds only `$` + this.
95
+ const OWN_KEY_ENV = 'COMMONLY_PI_PROVIDER_KEY';
96
+
97
+ // The shared provider shape's `api` (environment.js PROVIDER_APIS) in pi's own
98
+ // words. Both measured on pi 0.84.1 against a local stub: `openai-completions`
99
+ // calls `<baseURL>/chat/completions` with a Bearer, `anthropic-messages` calls
100
+ // `<baseURL>/v1/messages` with x-api-key, so an Anthropic baseURL is the host,
101
+ // as it is for OpenCode and for the provider proxy.
102
+ const PI_PROVIDER_APIS = Object.freeze({
103
+ 'openai-chat': 'openai-completions',
104
+ 'anthropic-messages': 'anthropic-messages',
105
+ });
106
+
87
107
  // ADR-008 `effort` → pi `--thinking`. pi's ladder is off/minimal/low/medium/high/xhigh/max.
88
108
  const THINKING = { none: 'off', off: 'off', minimal: 'minimal', low: 'low', medium: 'medium', high: 'high', xhigh: 'xhigh', max: 'max' };
89
109
  export const thinkingFor = (effort) => (effort ? THINKING[String(effort).toLowerCase()] || null : null);
@@ -117,8 +137,10 @@ export const PUBLIC_EXCLUDED_TOOLS = Object.freeze([...PI_BUILTIN_TOOLS, ...PUBL
117
137
  const PUBLIC_SAFE_ENV = /^(?:PATH|LANG|LC_[A-Z_]+|TERM|USER|LOGNAME|NO_COLOR|CI|SSL_CERT_FILE|SSL_CERT_DIR)$/;
118
138
  const safeEnv = (env) => Object.fromEntries(Object.entries(env).filter(([name]) => PUBLIC_SAFE_ENV.test(name)));
119
139
 
120
- // The one provider API the loopback proxy carries for pi.
140
+ // The one provider API the loopback proxy carries for pi. The proxy's model pin
141
+ // checks chat completions only, and a public turn must not run unpinned.
121
142
  const PUBLIC_PROVIDER_API = 'openai-completions';
143
+ const publicApiRefusal = (api) => `pi adapter: a public seat reaches its provider through a loopback proxy that carries the ${PUBLIC_PROVIDER_API} API only, not ${api}`;
122
144
 
123
145
  // Same substitution contract as claude.js / codex.js: ${COMMONLY_*}
124
146
  // placeholders in the declared MCP env are the wrapper's per-(agent, pod)
@@ -298,9 +320,59 @@ export const resolveMcpServers = (mcpServers, ctx = {}) => {
298
320
  return carried;
299
321
  };
300
322
 
323
+ /**
324
+ * Two provider shapes reach this adapter. The shared one, `{ id, baseURL,
325
+ * keyFile, models, api }`, is what `--env` accepts and validateEnvironmentSpec
326
+ * checks. pi's own, `{ name, baseUrl, api, apiKeyEnv }`, is a token-file
327
+ * override older than that validation, and its `api` is pi's word for it. A key
328
+ * only the shared shape has decides; a block with keys from both is then judged
329
+ * as shared, and validation refuses it rather than reading half of each.
330
+ */
331
+ const SHARED_PROVIDER_KEYS = ['id', 'baseURL', 'keyFile', 'models'];
332
+ const isSharedProvider = (spec) => Boolean(spec) && SHARED_PROVIDER_KEYS.some((key) => spec[key] !== undefined);
333
+
334
+ /** The real key file of a shared provider, validated without reading it; null for any other seat. */
335
+ const sharedProviderKeyFile = async (environment, workspacePath) => {
336
+ if (!isSharedProvider(environment?.provider)) return null;
337
+ const validation = validateEnvironmentSpec(environment);
338
+ if (!validation.ok) throw new Error(validation.errors.join('; '));
339
+ return resolveProviderKeyFile(environment.provider, workspacePath, 'pi');
340
+ };
341
+
342
+ /**
343
+ * The proxy reads a public seat's key file from this process, so the file stays
344
+ * out of the jail, and nothing here admits it. The jail does admit these
345
+ * directories, and the seat home is a stable path a key file could be put in,
346
+ * so a key under one of them would be readable from inside.
347
+ */
348
+ const refuseKeyFileInJail = (keyFile, readableDirectories) => {
349
+ for (const directory of readableDirectories) {
350
+ const fromDirectory = relative(realpathSync(directory), keyFile);
351
+ if (fromDirectory !== '..' && !fromDirectory.startsWith(`..${sep}`) && !isAbsolute(fromDirectory)) {
352
+ throw new Error(`pi adapter: provider.keyFile ${keyFile} is inside the sandbox of a public seat; move it outside ${directory}`);
353
+ }
354
+ }
355
+ };
356
+
357
+ /** The private turn's key, read the way goose reads it, refused if empty. */
358
+ const readOwnKey = async (keyFile) => {
359
+ const key = (await readFile(keyFile, 'utf8')).trim();
360
+ if (!key) throw new Error('pi adapter: provider.keyFile must not be empty');
361
+ return key;
362
+ };
363
+
301
364
  /** The provider block for models.json: the env spec's `provider` over the LiteLLM default. */
302
365
  export const resolveProvider = (environment = {}) => {
303
366
  const spec = environment?.provider || {};
367
+ if (isSharedProvider(spec)) {
368
+ return {
369
+ name: spec.id,
370
+ baseUrl: spec.baseURL,
371
+ api: PI_PROVIDER_APIS[spec.api || 'openai-chat'],
372
+ apiKeyEnv: OWN_KEY_ENV,
373
+ reasoning: spec.models?.[environment.model]?.reasoning !== false,
374
+ };
375
+ }
304
376
  return {
305
377
  name: spec.name || DEFAULT_PROVIDER.name,
306
378
  baseUrl: spec.baseUrl || DEFAULT_PROVIDER.baseUrl,
@@ -320,7 +392,7 @@ export const buildModelsJson = (provider, model) => ({
320
392
  models: [{
321
393
  id: model,
322
394
  name: model,
323
- reasoning: true,
395
+ reasoning: provider.reasoning ?? true,
324
396
  input: ['text'],
325
397
  cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
326
398
  contextWindow: 128000,
@@ -607,12 +679,29 @@ export default {
607
679
  // into its login service and fail loudly at bind when it is absent, instead
608
680
  // of the seat dying at line ~406 with nothing naming the missing variable at
609
681
  // daemon level.
682
+ // A seat with its own provider.keyFile doesn't need it; spawn doesn't ask.
610
683
  providerKeyEnv: DEFAULT_PROVIDER.apiKeyEnv,
611
684
 
685
+ supportsProvider: true,
686
+ providerApis: Object.keys(PI_PROVIDER_APIS),
687
+
688
+ // The rule pi adds to the shared provider check. Its own shape names pi's
689
+ // api, which the shared list doesn't hold. A public seat can't take a wire
690
+ // the proxy doesn't pin. Anything else goes to the shared check (undefined).
691
+ providerVerdict(environment) {
692
+ const spec = environment?.provider;
693
+ if (!isSharedProvider(spec)) return null;
694
+ if (effectiveSandboxTrust(environment?.sandbox?.trust) !== 'public') return undefined;
695
+ const api = PI_PROVIDER_APIS[spec.api || 'openai-chat'];
696
+ return api && api !== PUBLIC_PROVIDER_API ? publicApiRefusal(api) : undefined;
697
+ },
698
+
612
699
  // Attach runs this before anything is published, so a public pi seat this
613
- // host cannot confine is refused there rather than at its first turn.
614
- async validateEnvironment(environment) {
700
+ // host cannot confine is refused there rather than at its first turn, and so
701
+ // is a provider block or key file that couldn't be used.
702
+ async validateEnvironment(environment, workspacePath) {
615
703
  assertSandboxSupported(environment);
704
+ return sharedProviderKeyFile(environment, workspacePath);
616
705
  },
617
706
 
618
707
  async detect() {
@@ -631,11 +720,15 @@ export default {
631
720
  assertSandboxSupported(ctx.environment, platform);
632
721
  const sandbox = normalizeSandboxTrust(ctx.environment?.sandbox);
633
722
  const isPublic = effectiveSandboxTrust(sandbox?.trust) === 'public';
723
+ const keyFile = await sharedProviderKeyFile(ctx.environment, ctx.cwd);
634
724
  const provider = resolveProvider(ctx.environment);
635
725
  const model = seatModel;
636
726
  const thinking = thinkingFor(ctx.environment?.effort);
637
727
  const baseEnv = ctx.env || process.env;
638
- if (!baseEnv[provider.apiKeyEnv]) {
728
+ // A public turn leaves the key file to the proxy, so this process holds the
729
+ // value only for a private pi, which is the one that is handed it.
730
+ const ownKey = keyFile && !isPublic ? await readOwnKey(keyFile) : null;
731
+ if (!keyFile && !baseEnv[provider.apiKeyEnv]) {
639
732
  throw new Error(`pi adapter: ${provider.apiKeyEnv} is not set — the seat's environment must carry the provider key (LiteLLM virtual key)`);
640
733
  }
641
734
 
@@ -646,7 +739,7 @@ export default {
646
739
  let nodePath = null;
647
740
  if (isPublic) {
648
741
  if (provider.api !== PUBLIC_PROVIDER_API) {
649
- throw new Error(`pi adapter: a public seat reaches its provider through a loopback proxy that carries the ${PUBLIC_PROVIDER_API} API only, not ${provider.api}`);
742
+ throw new Error(publicApiRefusal(provider.api));
650
743
  }
651
744
  if (!ctx.cwd || !isAbsolute(ctx.cwd)) {
652
745
  throw new Error('pi adapter: a public seat needs an absolute workspace path');
@@ -676,6 +769,7 @@ export default {
676
769
  // the token from the child copy below, and after that there is nothing left
677
770
  // to compare a refusal against.
678
771
  const credentials = spawnCredentials(ctx, [provider.apiKeyEnv]);
772
+ if (ownKey) credentials.push(ownKey);
679
773
 
680
774
  // Per-seat pi home: models.json holds the provider by env reference.
681
775
  const home = seatHome(ctx, { publicSeat: isPublic });
@@ -712,7 +806,7 @@ export default {
712
806
  if (isPublic) {
713
807
  proxy = await (ctx._startProviderProxy || startProviderProxy)({
714
808
  provider: { baseURL: provider.baseUrl },
715
- keyMaterial: baseEnv[provider.apiKeyEnv],
809
+ ...(keyFile ? { keyFile } : { keyMaterial: baseEnv[provider.apiKeyEnv] }),
716
810
  adapterLabel: 'pi',
717
811
  pinnedModel: model,
718
812
  });
@@ -734,6 +828,9 @@ export default {
734
828
  grantBrokers,
735
829
  });
736
830
  if (unavailableMcp.length) throw publicMcpUnavailableError(unavailableMcp);
831
+ if (keyFile && isPublic) {
832
+ refuseKeyFileInJail(keyFile, [home, packageRoot, EXTENSION_CODE_ROOT, ...mcpReadDirectories]);
833
+ }
737
834
  const childEnv = isPublic ? {
738
835
  // A scrubbed environment: nothing of the operator's crosses into the
739
836
  // jail, and the provider variable holds the proxy's token, not the key.
@@ -751,7 +848,10 @@ export default {
751
848
  // A variable NAME, never its value. The always-loaded extension uses
752
849
  // this to scrub custom provider keys as well as the default LiteLLM key.
753
850
  COMMONLY_PI_PROVIDER_KEY_ENV: provider.apiKeyEnv,
851
+ ...(ownKey ? { [provider.apiKeyEnv]: ownKey } : {}),
754
852
  };
853
+ // This seat brought its own key, so it has no use for ours.
854
+ if (ownKey) delete childEnv[DEFAULT_PROVIDER.apiKeyEnv];
755
855
  // `baseEnv` is normally the process environment, which carries the
756
856
  // bootstrap export. Nothing below this process needs the value: the bridge
757
857
  // is handed the servers, their resolved values included, over fd 3. It has
@@ -335,7 +335,7 @@ export const installDaemonService = async ({
335
335
  if (lingerUser) startsAtBoot = await ensureLinger({ username: lingerUser, existsFile, execCmd, warn });
336
336
  }
337
337
  for (const name of missing) {
338
- warn(`${name} is not set in this shell, so it is NOT in the service file. A seat whose adapter needs it will fail to start; export it and re-run: commonly daemon install (docs/agents/daemon-service-environment.md)`);
338
+ warn(`${name} is not set in this shell, so it is NOT in the service file. A seat that relies on it will fail to start (one with its own provider.keyFile won't); export it and re-run: commonly daemon install (docs/agents/daemon-service-environment.md)`);
339
339
  }
340
340
  log(`Installed ${target.kind} service (${target.file}). Logs: ${daemonLogPath(home)}`);
341
341
  return { ...target, startsAtBoot };
@@ -49,23 +49,21 @@ export const frameDecisionForkRule = (prompt) => `${DECISION_FORK_FRAME}\n\n${pr
49
49
  /**
50
50
  * Who authored the message that woke us — 'agent', 'human', or 'unknown'?
51
51
  *
52
- * Two signals, in order of reliability:
52
+ * Three signals, in order:
53
53
  * 1. payload.dmKind — the kernel stamps DM wakes 'agent-agent'/'user-agent'.
54
54
  * 2. The trigger message's isBot flag, looked up by payload.messageId in the
55
55
  * pre-spawn snapshot the run loop already fetches for echo suppression.
56
+ * 3. payload.senderIsHuman, for what no snapshot can name. A page holds more
57
+ * wakes than the snapshot holds messages, so without this a full page of
58
+ * agent wakes reads as all unknown and walks past the cascade cap. A post
59
+ * comment isn't a pod message at all (F225).
56
60
  *
57
61
  * 'unknown' is the fail-open verdict: it neither counts toward the cascade
58
- * cap nor resets it. In a live cascade the trigger message is seconds old and
59
- * always inside the snapshot window, so cascades classify reliably; a message
60
- * that has already scrolled out of the window is not cascade tempo.
62
+ * cap nor resets it. It's what's left when the kernel couldn't say either: an
63
+ * older server, or a sender it couldn't read.
61
64
  */
62
65
  export const classifyTrigger = (event, recentMessages) => {
63
66
  const p = event?.payload || {};
64
- // A post comment is not a pod message, so a snapshot can never name its
65
- // author (F225). The kernel stamps it; an older server leaves it 'unknown'.
66
- if (event?.type === 'thread.mention' && typeof p.senderIsHuman === 'boolean') {
67
- return p.senderIsHuman ? 'human' : 'agent';
68
- }
69
67
  // The third pricing branch (#1044, fable 55845). Kernel-found work is not
70
68
  // agent churn and must not price as it: counted as 'agent' it eats cascade
71
69
  // budget exactly when the board is busiest; counted as 'human' it CLEARS the
@@ -76,12 +74,12 @@ export const classifyTrigger = (event, recentMessages) => {
76
74
  if (p.triggerAuthor === 'kernel') return 'kernel';
77
75
  if (p.dmKind === 'agent-agent') return 'agent';
78
76
  if (p.dmKind === 'user-agent') return 'human';
79
- if (!p.messageId || !Array.isArray(recentMessages)) return 'unknown';
80
- const trigger = recentMessages.find(
81
- (m) => String(m._id || m.id) === String(p.messageId),
82
- );
83
- if (!trigger || typeof trigger.isBot !== 'boolean') return 'unknown';
84
- return trigger.isBot ? 'agent' : 'human';
77
+ const trigger = p.messageId && Array.isArray(recentMessages)
78
+ ? recentMessages.find((m) => String(m._id || m.id) === String(p.messageId))
79
+ : undefined;
80
+ if (typeof trigger?.isBot === 'boolean') return trigger.isBot ? 'agent' : 'human';
81
+ if (typeof p.senderIsHuman === 'boolean') return p.senderIsHuman ? 'human' : 'agent';
82
+ return 'unknown';
85
83
  };
86
84
 
87
85
  // Direct-address event types: the seat was NAMED (explicit @, implicit human
@@ -94,7 +92,7 @@ export const ADDRESSED_EVENT_TYPES = new Set(['chat.mention', 'thread.mention',
94
92
  /**
95
93
  * A person @-mentioned this seat in a pod (ADR-018 D9.2): the one wake that
96
94
  * carries unread message bodies. `trigger` is classifyTrigger's verdict, so an
97
- * agent's mention, a kernel wake and an author the snapshot can't name are all
95
+ * agent's mention, a kernel wake and an author nobody can name are all
98
96
  * out. A DM wake is not a mention, whichever type it rides, and neither is a
99
97
  * broadcast. Nor are three `chat.mention` wakes where nobody typed the seat's
100
98
  * name: a welcome, an adjacent reply and a reply to the seat's own message.
@@ -196,10 +196,14 @@ export const environmentForServer = (environment) => {
196
196
  export const PROVIDER_APIS = Object.freeze(['openai-chat', 'anthropic-messages']);
197
197
 
198
198
  // One provider check for config, attach, run and the daemon's adapter swap: the adapter must take a
199
- // provider block at all, and speak its `provider.api` (default openai-chat).
199
+ // provider block at all, and speak its `provider.api` (default openai-chat). An adapter's
200
+ // `providerVerdict(environment)` answers first when it returns a refusal or null (accepted);
201
+ // undefined leaves the seat to this check.
200
202
  export const providerRefusal = (environment, adapter) => {
201
203
  if (environment?.provider === undefined) return null;
202
204
  if (!adapter?.supportsProvider) return 'environment.provider requires a provider-capable adapter';
205
+ const verdict = adapter.providerVerdict?.(environment);
206
+ if (verdict !== undefined) return verdict;
203
207
  const api = environment.provider?.api || 'openai-chat';
204
208
  const apis = adapter.providerApis || ['openai-chat'];
205
209
  return apis.includes(api) ? null