@zergai/ztc 0.18.0-beta.1 → 0.18.2-dev.202611110225

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.
Files changed (37) hide show
  1. package/bin/zmux-darwin-arm64 +0 -0
  2. package/bin/ztc-audio-darwin-arm64 +0 -0
  3. package/bin/ztc-capture-darwin-arm64 +0 -0
  4. package/bin/ztc-computer-darwin-arm64 +0 -0
  5. package/bin/ztc-llm-darwin-arm64 +0 -0
  6. package/bin/ztc-tts-darwin-arm64 +0 -0
  7. package/bin/ztc-tui-darwin-arm64 +0 -0
  8. package/bin/zterm-darwin-arm64 +1 -1
  9. package/dist/App.js +3 -1
  10. package/dist/agent/backends/index.js +14 -5
  11. package/dist/agent/backends/provider_ids.d.ts +13 -0
  12. package/dist/agent/backends/provider_ids.js +19 -0
  13. package/dist/agent/commands/config.d.ts +8 -3
  14. package/dist/agent/commands/config.js +72 -23
  15. package/dist/agent/commands/credential_status.js +23 -12
  16. package/dist/agent/commands/model.js +7 -2
  17. package/dist/agent/commands/models.js +4 -3
  18. package/dist/agent/commands/provider_choices.d.ts +62 -1
  19. package/dist/agent/commands/provider_choices.js +90 -6
  20. package/dist/agent/commands/reasoning_settings.d.ts +1 -1
  21. package/dist/agent/commands/reasoning_settings.js +5 -5
  22. package/dist/agent/commands/settings.js +4 -6
  23. package/dist/agent/factory.js +9 -5
  24. package/dist/app/agent_runner.js +8 -3
  25. package/dist/cli_ratatui.js +28 -11
  26. package/dist/config/defaults.d.ts +5 -2
  27. package/dist/config/defaults.js +8 -4
  28. package/dist/config.d.ts +17 -5
  29. package/dist/config.js +26 -9
  30. package/dist/headless.js +6 -2
  31. package/dist/headless_cli.js +21 -2
  32. package/dist/headless_cli_args.js +2 -10
  33. package/dist/onboarding/setup_agent_health.js +4 -0
  34. package/dist/utils/reasoning.d.ts +5 -0
  35. package/dist/utils/reasoning.js +7 -3
  36. package/dist/zlm-embed.mjs +86 -21
  37. package/package.json +9 -14
@@ -1,6 +1,5 @@
1
1
  import { resolveCodexEffort } from '../../config/defaults.js';
2
- import { getSupportedCodexReasoningEfforts } from '../../utils/models.js';
3
- import { formatReasoningEffort } from '../../utils/reasoning.js';
2
+ import { formatReasoningEffort, reasoningContractChoices } from '../../utils/reasoning.js';
4
3
  import { resolveRouterModel } from '../../utils/router_catalog.js';
5
4
  /** The active model's reasoning settings, as /effort, /thinking and the /model picker read them. */
6
5
  export function activeReasoning(ctx) {
@@ -11,14 +10,15 @@ export function activeReasoning(ctx) {
11
10
  ?? (config.authMode === 'zrouter' || provider === 'openai_compatible' ? 'chat_tools' : 'native_api');
12
11
  const catalog = ctx.config.getRoutedModelCatalog?.();
13
12
  const capabilities = catalog?.version === 1 ? resolveRouterModel(catalog, provider, model)?.capabilities : undefined;
13
+ const contract = ctx.config.getReasoningContract?.(provider, model)
14
+ ?? (catalog?.version === 1 ? capabilities?.reasoning ?? [] : surface);
14
15
  return {
15
16
  provider,
16
17
  model,
17
18
  /** Effort and thinking are checked against this: Router's catalog for a Router model, else the reviewed contract. */
18
- contract: ctx.config.getReasoningContract?.(provider, model)
19
- ?? (catalog?.version === 1 ? capabilities?.reasoning ?? [] : surface),
19
+ contract,
20
20
  /** The model's levels; undefined when nothing says which it takes. */
21
- supported: catalog?.version === 1 ? capabilities?.reasoning?.choices ?? [] : getSupportedCodexReasoningEfforts(model, provider, surface),
21
+ supported: reasoningContractChoices(provider, model, contract),
22
22
  /** The saved effort this model runs with, if any. */
23
23
  current: resolveCodexEffort(config, provider, model, capabilities ?? surface),
24
24
  status: () => {
@@ -1,6 +1,5 @@
1
1
  import { parseReasoningSelection } from '../../utils/reasoning.js';
2
2
  import { resolveRouterModel, routerModelForSwitch } from '../../utils/router_catalog.js';
3
- import { getSupportedCodexReasoningEfforts } from '../../utils/models.js';
4
3
  import { dictationChoiceNotice, dictationChoiceRefusal } from '../../utils/dictation.js';
5
4
  import { resolveExecutionSettings } from '../../config/execution.js';
6
5
  import { openAccountsManager } from './accounts.js';
@@ -22,6 +21,7 @@ import { subsCommand } from './subs.js';
22
21
  import { modelForProviderSwitch } from './provider_model_defaults.js';
23
22
  import { normalizeProviderId } from '../backends/provider_ids.js';
24
23
  import { applyRuntimeModelSelection, getEffectiveModel } from './runtime_model.js';
24
+ import { activeReasoning } from './reasoning_settings.js';
25
25
  import { isBuildableResolvedConfig, unbuildableSelectionMessage } from './config.js';
26
26
  import { hasRemovableKey, manageApiKey, promptForMissingDirectKey, removeApiKey, } from './direct_credential_prompt.js';
27
27
  import { offerKeyedProviderSwitch } from './provider_selection.js';
@@ -244,8 +244,6 @@ export async function buildSettingsCategories(ctx) {
244
244
  const routerSignedIn = routerCredentials !== null && Date.parse(routerCredentials.expiresAt) > Date.now();
245
245
  const provider = ctx.config.getProvider();
246
246
  const model = ctx.config.getModel?.() || config.model;
247
- const reasoningEfforts = getSupportedCodexReasoningEfforts(model, provider, ctx.config.getReasoningWireSurface?.(provider, model)
248
- ?? (config.authMode === 'zrouter' || provider === 'openai_compatible' ? 'chat_tools' : 'native_api'));
249
247
  const configScope = ctx.config.getConfigScope?.() || 'global';
250
248
  const authMode = ctx.config.getAuthMode?.() || config.authMode || 'auto';
251
249
  const zergProxyUrl = config.zergProxyUrl || '';
@@ -283,8 +281,8 @@ export async function buildSettingsCategories(ctx) {
283
281
  if (routerCatalog?.version === 1)
284
282
  modelOptions = routerCatalog.models.filter(row => row.owned_by === provider && row.capabilities?.chat)
285
283
  .map(row => ({ value: row.id, label: `${row.display_name || row.id}${row.capabilities?.tools === false ? ' (chat only)' : ''}${row.available === false ? ' (access unavailable)' : ''}` }));
286
- const reasoningChoices = routerCatalog?.version === 1 ? routerDescriptor?.capabilities?.reasoning?.choices ?? []
287
- : reasoningEfforts ?? CODEX_REASONING_EFFORTS;
284
+ // The model's levels on its route, as /effort checks them: a Router model's are its catalog row's.
285
+ const reasoningChoices = activeReasoning(ctx).supported ?? CODEX_REASONING_EFFORTS;
288
286
  const effortSupported = config.codexEffort === undefined || reasoningChoices.includes(config.codexEffort);
289
287
  const sections = [
290
288
  {
@@ -1964,7 +1962,7 @@ function holdUnbuildableSelection(ctx, categories, setting, { provider, model, a
1964
1962
  },
1965
1963
  });
1966
1964
  if (!asked)
1967
- throw new Error(unbuildableSelectionMessage(provider));
1965
+ throw new Error(unbuildableSelectionMessage(provider, llm, ctx.config));
1968
1966
  // The row keeps showing what is still selected until the key arrives.
1969
1967
  const row = categories.flatMap(category => category.settings).find(item => item.name === setting);
1970
1968
  if (row && setting === 'provider')
@@ -6,6 +6,7 @@ import { KIMI_CODE_AUTH_SENTINEL } from './backends/kimi_code_auth.js';
6
6
  import { CODEX_APP_SERVER_SENTINEL, isCodexAppServerProvider, isCodexLegacyProvider, isLocalSubscriptionProvider, normalizeProviderId } from './backends/provider_ids.js';
7
7
  import { accountBackendOptions, resolveActiveAccount, isAccountProvider, canonicalAccountProvider, sourceDir } from './backends/account_pool.js';
8
8
  import { assertProviderNotRetired } from '../config/retired_routes.js';
9
+ import { routerOnlyModelError } from './commands/provider_choices.js';
9
10
  import { getEmulationProfile, buildRuntimeContext } from '../emulation/catalog.js';
10
11
  import { getEmulationMappingAddendum, emulationUsesPaneTools } from '../emulation/mappings.js';
11
12
  import { buildEmulationCompatibilityTools, getEmulationToolMapping } from '../emulation/tool_adapters.js';
@@ -250,15 +251,18 @@ export function resolveAgentBackendFromConfig(options) {
250
251
  || (provider === 'openai_compatible' && Boolean(compatBaseUrl));
251
252
  const useProxy = llm.useProxy;
252
253
  const useDirectProvider = authMode === 'direct' ? directKeyAvailable : (!useProxy && directKeyAvailable);
254
+ // Modal is a new profile's default route, which waits for a ZergAI login as a
255
+ // missing key waits for a key.
253
256
  if (provider === 'modal' && !useProxy) {
254
257
  runtimeDiag('error', '[ztc] Modal requires Zerg Router authentication. Run ztc auth login and use authMode zrouter.');
255
258
  return null;
256
259
  }
257
- if (provider === 'openrouter' && !useProxy) { // no direct OpenRouter backend: say why, not "unknown provider"
258
- throw new Error(authMode === 'direct'
259
- ? `${effectiveModel} runs through Zerg Router, and routing is set to direct (local keys only). Set Routing to auto in /config, or choose another model with /model.`
260
- : `${effectiveModel} runs through Zerg Router, and ZTC isn't logged in to it. Log in with /auth login, or choose another model with /model.`);
261
- }
260
+ // Any other provider with no direct backend (OpenRouter, one Router adds)
261
+ // says why it can't run here and what to do, not "unknown provider", whatever
262
+ // key this machine has. Router's cached catalog can say Router serves it.
263
+ const routerOnly = routerOnlyModelError({ provider, model: effectiveModel, useProxy, authMode }, configStore);
264
+ if (routerOnly)
265
+ throw routerOnly;
262
266
  if (useProxy) {
263
267
  // Route selection is resolved before any provider-specific backend.
264
268
  apiKey = proxyToken;
@@ -11,6 +11,7 @@ import { createAgentFromConfig, resolveAgentBackendFromConfig } from '../agent/f
11
11
  import { configStore } from '../config.js';
12
12
  import { RouterConfigurationError } from '../router_auth.js';
13
13
  import { RouteAwaitingChoiceError } from '../config/retired_routes.js';
14
+ import { RouterOnlyModelError } from '../agent/commands/provider_choices.js';
14
15
  import { setBackgroundRegistry, getBackgroundRegistry, clearBackgroundRegistry } from '../agent/tools/index.js';
15
16
  import { BackgroundTaskRegistry } from '../agent/background_registry.js';
16
17
  import { InProcessWorkerExecutor, setWorkerExecutor, clearWorkerExecutor } from '../worker/index.js';
@@ -82,9 +83,13 @@ export function createAgentWithConfig(overrides = {}) {
82
83
  });
83
84
  }
84
85
  catch (error) {
85
- // A Router sign-in still to come, or a profile still waiting for a route
86
- // choice, leaves startup without an agent until there is a route.
87
- const unavailable = (error instanceof RouterConfigurationError && error.needsSignIn) || error instanceof RouteAwaitingChoiceError;
86
+ // A Router sign-in still to come, a model Zerg Router serves while the
87
+ // route isn't Router, or a profile still waiting for a route choice, leaves
88
+ // startup without an agent until there is a route. A provider nothing says
89
+ // Router serves is a configuration error, as an unknown provider was: a
90
+ // profile switch onto it fails and keeps the profile in use.
91
+ const unavailable = (error instanceof RouterConfigurationError && error.needsSignIn) || error instanceof RouteAwaitingChoiceError
92
+ || (error instanceof RouterOnlyModelError && error.served);
88
93
  if (!allowUnavailableRouterAuth || !unavailable)
89
94
  throw error;
90
95
  resolvedBackend = null;
@@ -39,7 +39,7 @@ import { createUsageSnapshot, recordUsageReceipt } from './usage_snapshot.js';
39
39
  import { withActiveProfileArg } from './config/profiles.js';
40
40
  import { DEFAULT_ROUTER_ORIGIN, RouterConfigurationError } from './router_auth.js';
41
41
  import { CODEX_REASONING_EFFORTS } from './config/types.js';
42
- import { getSupportedCodexReasoningEfforts, isCodexReasoningEffortSupported, unsupportedEffortMessage, } from './utils/models.js';
42
+ import { getSupportedCodexReasoningEfforts, unsupportedEffortMessage, } from './utils/models.js';
43
43
  import { getVersion } from './utils/version.js';
44
44
  import { isPersistableAssistantMessage } from './utils/assistant_message.js';
45
45
  import { claimObservationWarning, withHostClaimObservation } from './agent/claim_observation.js';
@@ -68,7 +68,7 @@ import { EvidenceLedger } from './agent/runtime/evidence.js';
68
68
  import { runtimePluginRegistry } from './plugin/runtime_registry.js';
69
69
  import { getMirrorCommandUsages, isRichSlashUsage } from './agent/commands/mirror_usages.js';
70
70
  import { createModeContext } from './agent/commands/mode_commands.js';
71
- import { isLocalSubscription, isRouterOnlyProvider, modelRouteStatus } from './agent/commands/provider_choices.js';
71
+ import { currentRouterOnlyModelError, isLocalSubscription, isRouterOnlyProvider, modelRouteStatus, RouterOnlyModelError, } from './agent/commands/provider_choices.js';
72
72
  import { isBuildableResolvedConfig } from './agent/commands/config.js';
73
73
  import { promptForMissingDirectKey } from './agent/commands/direct_credential_prompt.js';
74
74
  import { showConnectPrompt } from './agent/commands/connect.js';
@@ -2441,7 +2441,10 @@ export class RatatuiApp {
2441
2441
  if (!this.agent) {
2442
2442
  let notice = 'This profile has no usable provider yet. Configure one in /settings.';
2443
2443
  try {
2444
- configStore.resolveLLMBackendConfig({ cwd: this.shellCwd || process.cwd() });
2444
+ // A model only Zerg Router serves, off a Router route, names itself and the step that reaches it.
2445
+ const routerOnly = currentRouterOnlyModelError(configStore, configStore.resolveLLMBackendConfig({ cwd: this.shellCwd || process.cwd() }));
2446
+ if (routerOnly)
2447
+ notice = routerOnly.message;
2445
2448
  }
2446
2449
  catch (error) {
2447
2450
  if (error instanceof RouteAwaitingChoiceError)
@@ -5806,8 +5809,12 @@ export class RatatuiApp {
5806
5809
  return { ok: false, error };
5807
5810
  }
5808
5811
  const level = (effort ?? null);
5809
- if (level !== null && !isCodexReasoningEffortSupported(command.provider, command.model, level, configStore.getReasoningWireSurface(command.provider, command.model))) {
5810
- const supported = getSupportedCodexReasoningEfforts(command.model, command.provider, configStore.getReasoningWireSurface(command.provider, command.model)) ?? [];
5812
+ // The levels the pane's model takes on its route: a Zerg Router model's
5813
+ // are its catalog row's, whatever the main agent runs on.
5814
+ const supported = command.provider
5815
+ ? configStore.getReasoningChoices(command.provider, command.model)
5816
+ : getSupportedCodexReasoningEfforts(command.model, command.provider, configStore.getReasoningWireSurface(command.provider, command.model));
5817
+ if (level !== null && supported !== undefined && !supported.includes(level)) {
5811
5818
  const error = unsupportedEffortMessage(command.model, level, supported);
5812
5819
  this.publishPaneSystemMessage(command.pane_id, error);
5813
5820
  return { ok: false, error };
@@ -9002,7 +9009,9 @@ export class RatatuiApp {
9002
9009
  role: 'user',
9003
9010
  content: text,
9004
9011
  });
9005
- this.addErrorMessage(buildCredentialSetupMessage());
9012
+ // A model only Zerg Router serves names itself and the step that reaches it, with or without a key here.
9013
+ const routerOnly = sendRoute.route ? currentRouterOnlyModelError(configStore, sendRoute.route) : undefined;
9014
+ this.addErrorMessage(routerOnly ? routerOnly.message : buildCredentialSetupMessage());
9006
9015
  return;
9007
9016
  }
9008
9017
  // Resolve local overlap while the full input is still unadmitted, before
@@ -9099,7 +9108,8 @@ export class RatatuiApp {
9099
9108
  return { ready: false, awaitingChoice: error.notice };
9100
9109
  return { ready: configStore.hasApiKey() || configStore.isAuthenticated() };
9101
9110
  }
9102
- const platformFallback = route.provider !== 'modal' && route.authMode !== 'direct' && configStore.isAuthenticated();
9111
+ // A provider only Zerg Router serves (Modal among them) has no platform fallback: the factory refuses it off Router.
9112
+ const platformFallback = !isRouterOnlyProvider(route.provider) && route.authMode !== 'direct' && configStore.isAuthenticated();
9103
9113
  return { ready: isBuildableResolvedConfig(route) || platformFallback, route };
9104
9114
  }
9105
9115
  /**
@@ -11925,6 +11935,7 @@ export class RatatuiApp {
11925
11935
  }
11926
11936
  let rebuilt = null;
11927
11937
  let awaitingChoice = false;
11938
+ let routerOnly;
11928
11939
  try {
11929
11940
  rebuilt = this.createAgent();
11930
11941
  }
@@ -11932,6 +11943,8 @@ export class RatatuiApp {
11932
11943
  // A throwing configuration/backend constructor needs the same rollback
11933
11944
  // as a missing credential. Never leak a control envelope into chat.
11934
11945
  awaitingChoice = error instanceof RouteAwaitingChoiceError;
11946
+ if (error instanceof RouterOnlyModelError)
11947
+ routerOnly = error;
11935
11948
  }
11936
11949
  if (!rebuilt) {
11937
11950
  // Roll back the half-applied selection and keep the working agent live —
@@ -11949,13 +11962,17 @@ export class RatatuiApp {
11949
11962
  this.addSystemMessage(`⚠ ${ROUTE_AWAITS_A_CHOICE} Keeping the current model.`);
11950
11963
  return;
11951
11964
  }
11952
- const fix = isRouterOnlyProvider(who) ? 'log in with /auth login'
11965
+ // Routing set to direct keeps a provider only Zerg Router serves off Router whatever the login (Modal's
11966
+ // factory returns no agent rather than saying so).
11967
+ const fix = isRouterOnlyProvider(who) ? (configStore.getAuthMode() === 'direct' ? 'set Routing to auto in /config' : 'log in with /auth login')
11953
11968
  : isLocalSubscription(who) ? 'sign in through /accounts' : `add a key with /config key ${who}`;
11954
11969
  // A caller may have saved the choice first; rolling back cannot undo that.
11955
11970
  const kept = isOverseer ? this.overseerModelOverride?.provider ?? configStore.getProvider() : configStore.getProvider();
11956
- this.addSystemMessage(normalizeProviderId(kept) === normalizeProviderId(who)
11957
- ? `⚠ ${who} is selected but can't reach a model yet: ${fix}.`
11958
- : `⚠ ${who} isn't set up; ${fix} first. Keeping the current model.`);
11971
+ const selected = normalizeProviderId(kept) === normalizeProviderId(who);
11972
+ // A model only Zerg Router serves says why in its own words, as its turn would.
11973
+ this.addSystemMessage(routerOnly ? `⚠ ${routerOnly.message}${selected ? '' : ' Keeping the current model.'}`
11974
+ : selected ? `⚠ ${who} is selected but can't reach a model yet: ${fix}.`
11975
+ : `⚠ ${who} isn't set up; ${fix} first. Keeping the current model.`);
11959
11976
  debugLog(`[hot-swap] rebuild failed for ${who}; kept ${prevProvider}/${prevModel}`);
11960
11977
  return;
11961
11978
  }
@@ -1,5 +1,6 @@
1
1
  import type { ReasoningWireSurface } from '@zerg/model-contracts';
2
2
  import type { CodexReasoningEffort, ZTCConfig } from './types.js';
3
+ import { type ReasoningContract } from '../utils/reasoning.js';
3
4
  export declare const DEFAULT_OPENAI_MODEL = "gpt-5.4-nano";
4
5
  export declare const DEFAULT_CODEX_MODEL = "gpt-5.6-sol";
5
6
  export declare const DEFAULT_ANTHROPIC_MODEL = "claude-opus-5";
@@ -18,9 +19,11 @@ export declare function resolveCodexEffort(config: ZTCConfig, provider?: string,
18
19
  /**
19
20
  * The highest-priority saved effort when the active model rejects it, so the
20
21
  * UI can say the choice is not applied instead of silently falling back.
21
- * Undefined when the top choice is supported or nothing is saved.
22
+ * Undefined when the top choice is supported or nothing is saved. `contract`
23
+ * is the model's on its route (ConfigStore.getReasoningContract): a Router
24
+ * model's catalog row; without one, the reviewed tables decide.
22
25
  */
23
- export declare function unsupportedCodexEffort(config: ZTCConfig, provider?: string, model?: string): CodexReasoningEffort | undefined;
26
+ export declare function unsupportedCodexEffort(config: ZTCConfig, provider?: string, model?: string, contract?: ReasoningContract): CodexReasoningEffort | undefined;
24
27
  export declare function inferDefaultProvider(): string;
25
28
  export declare function getDefaultModelForProvider(provider: string): string;
26
29
  export declare function getDefaultApiKeyForProvider(provider: string): string | undefined;
@@ -2,6 +2,7 @@ import { CODEX_AUTH_SENTINEL, hasUsableCodexAuth } from '../agent/backends/codex
2
2
  import { KIMI_CODE_AUTH_SENTINEL, hasUsableKimiCodeAuth } from '../agent/backends/kimi_code_auth.js';
3
3
  import { CODEX_APP_SERVER_SENTINEL, CODEX_LEGACY_PROVIDER, isCodexAppServerProvider, isCodexLegacyProvider } from '../agent/backends/provider_ids.js';
4
4
  import { isCodexReasoningEffortSupported } from '../utils/models.js';
5
+ import { reasoningContractChoices } from '../utils/reasoning.js';
5
6
  import { DEEPSEEK_FLASH_MODEL, MODAL_DEEPSEEK_FLASH_MODEL } from '../utils/deepseek.js';
6
7
  import { FIREWORKS_FUNDED_MODEL } from '../utils/fireworks.js';
7
8
  import { newestClaudeModel } from './anthropic_models.js';
@@ -41,17 +42,20 @@ export function resolveCodexEffort(config, provider, model, contract = config.au
41
42
  /**
42
43
  * The highest-priority saved effort when the active model rejects it, so the
43
44
  * UI can say the choice is not applied instead of silently falling back.
44
- * Undefined when the top choice is supported or nothing is saved.
45
+ * Undefined when the top choice is supported or nothing is saved. `contract`
46
+ * is the model's on its route (ConfigStore.getReasoningContract): a Router
47
+ * model's catalog row; without one, the reviewed tables decide.
45
48
  */
46
- export function unsupportedCodexEffort(config, provider, model) {
49
+ export function unsupportedCodexEffort(config, provider, model, contract) {
47
50
  const chosen = [
48
51
  model ? config.codexEffortByModel?.[model] : undefined,
49
52
  provider ? config.codexEffortByProvider?.[provider] : undefined,
50
53
  config.codexEffort,
51
54
  ].find((candidate) => Boolean(candidate));
52
- if (!chosen || isCodexReasoningEffortSupported(provider, model, chosen))
55
+ if (!chosen)
53
56
  return undefined;
54
- return chosen;
57
+ const supported = reasoningContractChoices(provider, model, contract);
58
+ return supported === undefined || supported.includes(chosen) ? undefined : chosen;
55
59
  }
56
60
  /** Providers a standard key variable selects at first launch, in priority order. */
57
61
  const ENV_DEFAULT_PROVIDER_ORDER = ['anthropic', 'openai', 'gemini', 'kimi', 'fireworks', 'openai_compatible', 'inception', 'clarifai'];
package/dist/config.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { type ReasoningWireSurface } from '@zerg/model-contracts';
2
2
  import { type RouterCatalog, type RouterCatalogConnection } from './utils/router_catalog.js';
3
- import type { ReasoningContract } from './utils/reasoning.js';
3
+ import { type ReasoningContract } from './utils/reasoning.js';
4
4
  import { ZTCConfig, ZTCAuthCredentials, ApiEnvironment, ZTCAuthMode, ZTCConfigScope, CompactionTriggerMode, OpenAICompatibleSettings, ZTCPermissionProfile, IntentLayerSettings, ContextProgressBarSettings, CodexReasoningEffort, WorkflowSettings, Account, type NoticeLaunchStep, type TerminalInteractionSettings } from './config/types.js';
5
5
  import type { AuthContext, ResolvedLLMConfig } from './config/resolved.js';
6
6
  import { type RetiredRouteRequest } from './config/retired_routes.js';
@@ -431,9 +431,19 @@ export declare class ConfigStore {
431
431
  */
432
432
  getReasoningWireSurface(provider?: string, model?: string): ReasoningWireSurface;
433
433
  getCodexEffort(provider?: string, model?: string): CodexReasoningEffort | undefined;
434
- /** The active transport owns the model's choices, aliases and advertised default. */
434
+ /**
435
+ * The model's transport owns its choices, aliases and advertised default: on
436
+ * a Zerg Router route, the catalog row's; otherwise the reviewed contract of
437
+ * the wire surface (a missing or legacy catalog keeps that too).
438
+ */
435
439
  getReasoningContract(provider?: string, model?: string): ReasoningContract;
436
- /** Saved effort the active (or given) model rejects; undefined when it applies. */
440
+ /**
441
+ * The reasoning levels the active (or given) model takes on its route, from
442
+ * getReasoningContract: exactly a Router row's choices for a Router model.
443
+ * Undefined when nothing says which levels the model takes (any then).
444
+ */
445
+ getReasoningChoices(provider?: string, model?: string): readonly string[] | undefined;
446
+ /** Saved effort the active (or given) model rejects on its route; undefined when it applies. */
437
447
  getUnsupportedCodexEffort(provider?: string, model?: string): CodexReasoningEffort | undefined;
438
448
  /** Effort chosen by a startup `--effort` flag for this process (= none when unset). */
439
449
  getCodexEffortOverride(): CodexReasoningEffort | undefined;
@@ -517,8 +527,10 @@ export declare class ConfigStore {
517
527
  getChildAuthMode(): ZTCAuthMode;
518
528
  adoptRouterCatalog(catalog: RouterCatalog): Promise<void>;
519
529
  getRouterCatalog(): RouterCatalog | undefined;
520
- getResolvedAuthMode(): ZTCAuthMode;
521
- getRoutedModelCatalog(): RouterCatalog | undefined;
530
+ /** The route auto mode lands on for the active provider, or for `provider` (a pane's, say). */
531
+ getResolvedAuthMode(provider?: string): ZTCAuthMode;
532
+ /** Router's catalog when the active provider, or `provider`, runs through Zerg Router. */
533
+ getRoutedModelCatalog(provider?: string): RouterCatalog | undefined;
522
534
  getModelContextWindow(model?: string, provider?: string): number | null | undefined;
523
535
  /**
524
536
  * Resolve everything a backend factory needs into one struct. Folds in the
package/dist/config.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { modelContract } from '@zerg/model-contracts';
2
2
  import { isLocalSubscriptionProvider } from './agent/backends/provider_ids.js';
3
3
  import { resolveRouterModel, readRouterCatalog } from './utils/router_catalog.js';
4
+ import { reasoningContractChoices } from './utils/reasoning.js';
4
5
  import { dirname, join, resolve } from 'path';
5
6
  import { stat, readFile, readlink, writeFile, mkdir, rm, unlink, rename, realpath } from 'fs/promises';
6
7
  import { statSync } from 'fs';
@@ -1976,16 +1977,30 @@ export class ConfigStore {
1976
1977
  return resolveCodexEffort(this.get(), selectedProvider, selectedModel, capabilities
1977
1978
  ?? this.getReasoningWireSurface(selectedProvider, selectedModel));
1978
1979
  }
1979
- /** The active transport owns the model's choices, aliases and advertised default. */
1980
+ /**
1981
+ * The model's transport owns its choices, aliases and advertised default: on
1982
+ * a Zerg Router route, the catalog row's; otherwise the reviewed contract of
1983
+ * the wire surface (a missing or legacy catalog keeps that too).
1984
+ */
1980
1985
  getReasoningContract(provider = this.getProvider(), model = this.getModel()) {
1981
- const catalog = this.getRoutedModelCatalog();
1986
+ const catalog = this.getRoutedModelCatalog(provider);
1982
1987
  if (catalog?.version === 1)
1983
1988
  return resolveRouterModel(catalog, provider, model)?.capabilities?.reasoning ?? [];
1984
1989
  return this.getReasoningWireSurface(provider, model);
1985
1990
  }
1986
- /** Saved effort the active (or given) model rejects; undefined when it applies. */
1991
+ /**
1992
+ * The reasoning levels the active (or given) model takes on its route, from
1993
+ * getReasoningContract: exactly a Router row's choices for a Router model.
1994
+ * Undefined when nothing says which levels the model takes (any then).
1995
+ */
1996
+ getReasoningChoices(provider = this.getProvider(), model = this.getModel()) {
1997
+ return reasoningContractChoices(provider, model, this.getReasoningContract(provider, model));
1998
+ }
1999
+ /** Saved effort the active (or given) model rejects on its route; undefined when it applies. */
1987
2000
  getUnsupportedCodexEffort(provider, model) {
1988
- return unsupportedCodexEffort(this.get(), provider ?? this.getProvider(), model ?? this.getModel());
2001
+ const selectedProvider = provider ?? this.getProvider();
2002
+ const selectedModel = model ?? this.getModel();
2003
+ return unsupportedCodexEffort(this.get(), selectedProvider, selectedModel, this.getReasoningContract(selectedProvider, selectedModel));
1989
2004
  }
1990
2005
  /** Effort chosen by a startup `--effort` flag for this process (= none when unset). */
1991
2006
  getCodexEffortOverride() {
@@ -2254,22 +2269,24 @@ export class ConfigStore {
2254
2269
  const connection = this.getRouterCatalogConnection();
2255
2270
  return connection ? readRouterCatalog(connection) : undefined;
2256
2271
  }
2257
- getResolvedAuthMode() {
2272
+ /** The route auto mode lands on for the active provider, or for `provider` (a pane's, say). */
2273
+ getResolvedAuthMode(provider) {
2258
2274
  const mode = this.getAuthMode();
2259
2275
  if (mode !== 'auto')
2260
2276
  return mode;
2261
2277
  // Which route auto mode lands on, for catalogs and model names; nothing is sent here.
2262
2278
  try {
2263
- return this.resolveLLMBackendConfig({ asChosen: true }).useProxy ? 'zrouter' : 'direct';
2279
+ return this.resolveLLMBackendConfig({ provider, asChosen: true }).useProxy ? 'zrouter' : 'direct';
2264
2280
  }
2265
2281
  catch {
2266
2282
  return mode;
2267
2283
  }
2268
2284
  }
2269
- getRoutedModelCatalog() {
2270
- if (isLocalSubscriptionProvider(this.getProvider()))
2285
+ /** Router's catalog when the active provider, or `provider`, runs through Zerg Router. */
2286
+ getRoutedModelCatalog(provider = this.getProvider()) {
2287
+ if (isLocalSubscriptionProvider(provider))
2271
2288
  return undefined;
2272
- return this.getResolvedAuthMode() === 'zrouter' ? this.getRouterCatalog() : undefined;
2289
+ return this.getResolvedAuthMode(provider) === 'zrouter' ? this.getRouterCatalog() : undefined;
2273
2290
  }
2274
2291
  getModelContextWindow(model = this.getModel(), provider = this.getProvider()) {
2275
2292
  const catalog = this.getRoutedModelCatalog();
package/dist/headless.js CHANGED
@@ -29,6 +29,7 @@ import { configStore } from './config.js';
29
29
  import { isRetiredModel, isRetiredProvider, retiredProviderMessage, ROUTE_AWAITS_A_CHOICE, RouteAwaitingChoiceError } from './config/retired_routes.js';
30
30
  import { formatTaskHandoffContext, projectTaskHandoff } from './session_handoff_contract.js';
31
31
  import { RouterConfigurationError } from './router_auth.js';
32
+ import { currentRouterOnlyModelError, RouterOnlyModelError } from './agent/commands/provider_choices.js';
32
33
  import { routerRefusalOf } from './agent/backends/router_refusal.js';
33
34
  import { adoptRouterRefusalRecord } from './agent/backends/router_refusal_record.js';
34
35
  import { routerAccount, routerRefusalGate } from './agent/backends/router_gate.js';
@@ -1204,7 +1205,9 @@ export class HeadlessApp {
1204
1205
  type: 'error',
1205
1206
  timestamp: new Date().toISOString(),
1206
1207
  data: {
1207
- message: 'No API credentials configured. Run ztc auth login for Zerg Router, set a provider API key for direct mode, or provide ZTC_AUTH_TOKEN for platform routing.',
1208
+ // A model only Zerg Router serves needs no key here: it names itself and the step that reaches it.
1209
+ message: currentRouterOnlyModelError(configStore)?.message
1210
+ ?? 'No API credentials configured. Run ztc auth login for Zerg Router, set a provider API key for direct mode, or provide ZTC_AUTH_TOKEN for platform routing.',
1208
1211
  }
1209
1212
  });
1210
1213
  return false;
@@ -3887,8 +3890,9 @@ export async function runHeadless(options, initialPrompt) {
3887
3890
  }
3888
3891
  catch (error) {
3889
3892
  // A profile still waiting for a route choice has no route (see ConfigStore.routeAwaitingChoice), and says how to choose one.
3893
+ // A model only Zerg Router serves says how to reach it.
3890
3894
  const message = error instanceof RouterConfigurationError || error instanceof EnvironmentRecoveryError || error instanceof RouteAwaitingChoiceError
3891
- ? error.message : 'Headless initialization failed.';
3895
+ || error instanceof RouterOnlyModelError ? error.message : 'Headless initialization failed.';
3892
3896
  if (options.json) {
3893
3897
  process.stdout.write(`${JSON.stringify({
3894
3898
  type: 'error',
@@ -4,6 +4,7 @@ import { refuseRetiredRoute, retiredRouteRefusalFor, sayRetiredRouteNotices } fr
4
4
  import { getDefaultModelForProvider } from './config/defaults.js';
5
5
  import { CODEX_REASONING_EFFORTS } from './config/types.js';
6
6
  import { parseHeadlessCliArgs } from './headless_cli_args.js';
7
+ import { unsupportedEffortMessage } from './utils/models.js';
7
8
  import { getVersion } from './utils/version.js';
8
9
  const HELP = `ZTC Headless v${getVersion()}
9
10
 
@@ -79,11 +80,29 @@ async function main() {
79
80
  configStore.setCliOverride('model', model);
80
81
  if (authMode)
81
82
  configStore.setCliOverride('authMode', authMode);
82
- if (options.effort)
83
- configStore.setCliOverride('codexEffort', options.effort);
84
83
  const refusal = await retiredRouteRefusalFor(configStore);
85
84
  if (refusal)
86
85
  await refuseRetiredRoute(refusal, Boolean(options.json || options.jsonStream));
86
+ if (options.effort) {
87
+ // The levels the model takes on its route: a Zerg Router model's are its
88
+ // catalog row's, which the reviewed tables don't know. A fresh profile, or
89
+ // a new login, has no catalog cached yet, so ask Router first, as
90
+ // `ztc --effort` does; offline, the cached catalog or the tables decide.
91
+ try {
92
+ if (configStore.resolveLLMBackendConfig().useProxy) {
93
+ const { buildModelsController } = await import('./app/command_context.js');
94
+ await buildModelsController(configStore).catalog(AbortSignal.timeout(1000));
95
+ }
96
+ }
97
+ catch { /* Router unreachable or no route yet: check against what is known here. */ }
98
+ const supported = configStore.getReasoningChoices();
99
+ if (supported && !supported.includes(options.effort)) {
100
+ process.stderr.write(`${unsupportedEffortMessage(configStore.getModel(), options.effort, supported)}\n`);
101
+ process.exitCode = 2;
102
+ return;
103
+ }
104
+ configStore.setCliOverride('codexEffort', options.effort);
105
+ }
87
106
  sayRetiredRouteNotices(configStore);
88
107
  // The headless package is a standalone entry, so it must discover configured
89
108
  // MCP tools before the synchronous agent factory builds the allowed surface.
@@ -1,5 +1,4 @@
1
1
  import { CODEX_REASONING_EFFORTS, } from './config/types.js';
2
- import { getSupportedCodexReasoningEfforts, unsupportedEffortMessage, } from './utils/models.js';
3
2
  const AUTH_MODES = ['auto', 'direct', 'zrouter'];
4
3
  export function parseHeadlessCliArgs(args) {
5
4
  if (!args.includes('--headless')) {
@@ -81,15 +80,8 @@ export function parseHeadlessCliArgs(args) {
81
80
  if (valueError)
82
81
  return { ok: false, message: valueError };
83
82
  }
84
- if (options.effort) {
85
- const supported = getSupportedCodexReasoningEfforts(options.model, options.provider);
86
- if (supported && !supported.includes(options.effort)) {
87
- return {
88
- ok: false,
89
- message: unsupportedEffortMessage(options.model, options.effort, supported),
90
- };
91
- }
92
- }
83
+ // Which levels the model takes depends on its route (a Zerg Router model's
84
+ // are its catalog row's), so --effort is checked once config is loaded.
93
85
  return {
94
86
  ok: true,
95
87
  options,
@@ -2,6 +2,7 @@ import { randomUUID } from 'node:crypto';
2
2
  import { Agent } from '../agent/agent.js';
3
3
  import { resolveAgentBackendFromConfig } from '../agent/factory.js';
4
4
  import { ROUTE_AWAITS_A_CHOICE, RouteAwaitingChoiceError } from '../config/retired_routes.js';
5
+ import { RouterOnlyModelError } from '../agent/commands/provider_choices.js';
5
6
  import { runtimePluginRegistry } from '../plugin/runtime_registry.js';
6
7
  /** Check an isolated, tool-free turn without borrowing the active conversation. */
7
8
  export async function probeSetupAgent(options) {
@@ -67,6 +68,9 @@ export async function probeSetupAgent(options) {
67
68
  // A profile waiting for a route choice has none to check (see ConfigStore.routeAwaitingChoice).
68
69
  if (error instanceof RouteAwaitingChoiceError)
69
70
  return result('missing', ROUTE_AWAITS_A_CHOICE);
71
+ // A model only Zerg Router serves, off a Router route, needs a login (or routing set back to auto).
72
+ if (error instanceof RouterOnlyModelError)
73
+ return result('missing', error.message);
70
74
  // Provider errors and output can contain credential echoes. Fixed details
71
75
  // stay bounded and never copy those payloads into setup's visible report.
72
76
  return result('failed', 'Health check failed. Check provider credentials, model access and endpoint, then retry.');
@@ -4,6 +4,11 @@ export type ReasoningContract = ReasoningWireSurface | readonly string[] | {
4
4
  choices: readonly string[];
5
5
  default?: string;
6
6
  };
7
+ /**
8
+ * The levels a model's reasoning contract lists: a Router catalog row's choices, or the reviewed tables' for a wire
9
+ * surface. Undefined when nothing says which levels the model takes, so any level goes.
10
+ */
11
+ export declare function reasoningContractChoices(provider: string | undefined, model: string | undefined, contract?: ReasoningContract): readonly string[] | undefined;
7
12
  /** Suggestions and command validation share the same model contract. */
8
13
  export declare function reasoningCommandChoices(kind: 'effort' | 'thinking', provider: string, model: string, contract?: ReasoningContract): string[];
9
14
  /** One policy for slash commands and startup flags. null clears the model override. */
@@ -1,20 +1,24 @@
1
1
  import { CODEX_REASONING_EFFORTS } from '../config/types.js';
2
2
  import { getSupportedCodexReasoningEfforts, unsupportedEffortMessage } from './models.js';
3
- function reasoningChoices(provider, model, contract) {
3
+ /**
4
+ * The levels a model's reasoning contract lists: a Router catalog row's choices, or the reviewed tables' for a wire
5
+ * surface. Undefined when nothing says which levels the model takes, so any level goes.
6
+ */
7
+ export function reasoningContractChoices(provider, model, contract) {
4
8
  return contract === undefined || typeof contract === 'string'
5
9
  ? getSupportedCodexReasoningEfforts(model, provider, contract)
6
10
  : 'choices' in contract ? contract.choices : contract;
7
11
  }
8
12
  /** Suggestions and command validation share the same model contract. */
9
13
  export function reasoningCommandChoices(kind, provider, model, contract) {
10
- const choices = reasoningChoices(provider, model, contract);
14
+ const choices = reasoningContractChoices(provider, model, contract);
11
15
  if (kind === 'effort')
12
16
  return [...(choices ?? []), 'default'];
13
17
  return [choices?.some(value => value.toLowerCase() !== 'none') ? 'on' : '', choices?.some(value => value.toLowerCase() === 'none') ? 'off' : ''].filter(Boolean);
14
18
  }
15
19
  /** One policy for slash commands and startup flags. null clears the model override. */
16
20
  export function parseReasoningSelection(provider, model, current, selection, contract) {
17
- const supported = reasoningChoices(provider, model, contract);
21
+ const supported = reasoningContractChoices(provider, model, contract);
18
22
  const advertisedChoices = typeof contract === 'string' || contract === undefined ? undefined : supported;
19
23
  const canonical = (value) => supported?.find(choice => choice.toLowerCase() === value.toLowerCase()) ?? value;
20
24
  const effortInput = selection.effort?.toLowerCase();