@agentclientprotocol/claude-agent-acp 0.106.1-preview.8 → 0.107.0

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 (40) hide show
  1. package/dist/context-window.d.ts +11 -9
  2. package/dist/context-window.d.ts.map +1 -1
  3. package/dist/context-window.js +12 -13
  4. package/dist/managed-policy.d.ts +9 -0
  5. package/dist/managed-policy.d.ts.map +1 -1
  6. package/dist/managed-policy.js +25 -0
  7. package/dist/result-end.d.ts +13 -1
  8. package/dist/result-end.d.ts.map +1 -1
  9. package/dist/result-end.js +13 -0
  10. package/dist/session-model.d.ts +22 -16
  11. package/dist/session-model.d.ts.map +1 -1
  12. package/dist/session-model.js +66 -38
  13. package/dist/session-usage.d.ts +8 -17
  14. package/dist/session-usage.d.ts.map +1 -1
  15. package/dist/session-usage.js +8 -21
  16. package/dist/settings.d.ts +2 -0
  17. package/dist/settings.d.ts.map +1 -1
  18. package/dist/settings.js +12 -0
  19. package/dist/tool-calls/renderer.d.ts +5 -1
  20. package/dist/tool-calls/renderer.d.ts.map +1 -1
  21. package/dist/tool-calls/renderer.js +12 -7
  22. package/dist/tool-calls/retracted.d.ts +29 -0
  23. package/dist/tool-calls/retracted.d.ts.map +1 -0
  24. package/dist/tool-calls/retracted.js +66 -0
  25. package/dist/v1/acp-agent.d.ts +16 -13
  26. package/dist/v1/acp-agent.d.ts.map +1 -1
  27. package/dist/v1/acp-agent.js +54 -55
  28. package/dist/v2/outcome.d.ts +3 -1
  29. package/dist/v2/outcome.d.ts.map +1 -1
  30. package/dist/v2/outcome.js +5 -2
  31. package/dist/v2/reports.d.ts +2 -2
  32. package/dist/v2/reports.d.ts.map +1 -1
  33. package/dist/v2/reports.js +3 -6
  34. package/dist/v2/session.d.ts.map +1 -1
  35. package/dist/v2/session.js +3 -0
  36. package/dist/v2/setup.js +1 -1
  37. package/dist/v2/stream.d.ts +15 -1
  38. package/dist/v2/stream.d.ts.map +1 -1
  39. package/dist/v2/stream.js +35 -10
  40. package/package.json +1 -1
@@ -12,8 +12,8 @@ import type { ModelInfo, Query } from "@anthropic-ai/claude-agent-sdk";
12
12
  * Header/credential values can be secrets; the key only ever lives as an
13
13
  * in-memory Map key and is never logged or surfaced. Over-keying is the safe
14
14
  * side: a var change that didn't really change the backend costs one cache
15
- * miss (heuristic seed until the next result), while under-keying would serve
16
- * one backend's window for another's. */
15
+ * miss (the default window until Claude Code reports it), while under-keying
16
+ * would serve one backend's window for another's. */
17
17
  export declare function providerCacheKeyFor(env: Record<string, string | undefined>): string;
18
18
  /** Compose the `contextWindowCache` key from a session's provider key and a
19
19
  * model id. `\0`-joined so the model segment can't collide with a provider
@@ -35,13 +35,15 @@ export declare function cacheResultContextWindow(providerCacheKey: string, model
35
35
  /** The context window to report *right now* for a model, with NO IPC on the
36
36
  * critical path: the cached authoritative value if we've learned it (from a
37
37
  * prior turn's `result.modelUsage`, this or any session on the same backend),
38
- * else the text heuristic over the model row's identity strings, else the
39
- * default. Derives the cache key itself — `modelInfo?.resolvedModel ?? modelId`,
40
- * the same rule at every seed site — so read keys can't drift from the write
41
- * site's spelling. `authoritative` reports whether the value came from the
42
- * cache: an authoritative window can legitimately equal
43
- * DEFAULT_CONTEXT_WINDOW, so the value alone can't tell the caller. */
44
- export declare function immediateContextWindow(providerCacheKey: string, modelId: string, modelInfo?: Pick<ModelInfo, "resolvedModel" | "displayName" | "description">): {
38
+ * else DEFAULT_CONTEXT_WINDOW. The model's names do not give the window:
39
+ * Claude Code 2.1.323 reports 1M for `sonnet`, and 200K for it under
40
+ * `CLAUDE_CODE_DISABLE_1M_CONTEXT=1`. Derives the cache key itself —
41
+ * `modelInfo?.resolvedModel ?? modelId`, the same rule at every seed site — so
42
+ * read keys can't drift from the write site's spelling. `authoritative`
43
+ * reports whether the value came from the cache: an authoritative window can
44
+ * legitimately equal DEFAULT_CONTEXT_WINDOW, so the value alone can't tell the
45
+ * caller. */
46
+ export declare function immediateContextWindow(providerCacheKey: string, modelId: string, modelInfo?: Pick<ModelInfo, "resolvedModel">): {
45
47
  size: number;
46
48
  authoritative: boolean;
47
49
  };
@@ -1 +1 @@
1
- {"version":3,"file":"context-window.d.ts","sourceRoot":"","sources":["../src/context-window.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AAkDvE;;;;;;;;0CAQ0C;AAC1C,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,GAAG,MAAM,CAEnF;AAED;;eAEe;AACf,wBAAgB,qBAAqB,CAAC,gBAAgB,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAEvF;AAQD;;;;;;;;;;;gFAWgF;AAChF,wBAAgB,wBAAwB,CACtC,gBAAgB,EAAE,MAAM,EACxB,aAAa,EAAE,MAAM,EACrB,cAAc,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACzC,MAAM,EAAE,MAAM,GACb,IAAI,CAKN;AAED;;;;;;;;wEAQwE;AACxE,wBAAgB,sBAAsB,CACpC,gBAAgB,EAAE,MAAM,EACxB,OAAO,EAAE,MAAM,EACf,SAAS,CAAC,EAAE,IAAI,CAAC,SAAS,EAAE,eAAe,GAAG,aAAa,GAAG,aAAa,CAAC,GAC3E;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,OAAO,CAAA;CAAE,CAe1C;AAED;;;+BAG+B;AAC/B,wBAAgB,uBAAuB,IAAI,IAAI,CAE9C;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,iBAAiB,CACrC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,iBAAiB,CAAC,GACpC,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAG7B"}
1
+ {"version":3,"file":"context-window.d.ts","sourceRoot":"","sources":["../src/context-window.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AAkDvE;;;;;;;;sDAQsD;AACtD,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,GAAG,MAAM,CAEnF;AAED;;eAEe;AACf,wBAAgB,qBAAqB,CAAC,gBAAgB,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAEvF;AAQD;;;;;;;;;;;gFAWgF;AAChF,wBAAgB,wBAAwB,CACtC,gBAAgB,EAAE,MAAM,EACxB,aAAa,EAAE,MAAM,EACrB,cAAc,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EACzC,MAAM,EAAE,MAAM,GACb,IAAI,CAKN;AAED;;;;;;;;;;cAUc;AACd,wBAAgB,sBAAsB,CACpC,gBAAgB,EAAE,MAAM,EACxB,OAAO,EAAE,MAAM,EACf,SAAS,CAAC,EAAE,IAAI,CAAC,SAAS,EAAE,eAAe,CAAC,GAC3C;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,OAAO,CAAA;CAAE,CAM1C;AAED;;;+BAG+B;AAC/B,wBAAgB,uBAAuB,IAAI,IAAI,CAE9C;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,iBAAiB,CACrC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,iBAAiB,CAAC,GACpC,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAG7B"}
@@ -1,4 +1,4 @@
1
- import { DEFAULT_CONTEXT_WINDOW, inferContextWindowFromModel } from "./session-usage.js";
1
+ import { DEFAULT_CONTEXT_WINDOW } from "./session-usage.js";
2
2
  /** Cross-session cache of authoritative context windows, keyed by
3
3
  * `${providerCacheKey}\0${modelId}` (see {@link contextWindowCacheKey}).
4
4
  * The window is a property of (model id, backend): the same resolved model id
@@ -51,8 +51,8 @@ const PROVIDER_ROUTING_ENV_VARS = [
51
51
  * Header/credential values can be secrets; the key only ever lives as an
52
52
  * in-memory Map key and is never logged or surfaced. Over-keying is the safe
53
53
  * side: a var change that didn't really change the backend costs one cache
54
- * miss (heuristic seed until the next result), while under-keying would serve
55
- * one backend's window for another's. */
54
+ * miss (the default window until Claude Code reports it), while under-keying
55
+ * would serve one backend's window for another's. */
56
56
  export function providerCacheKeyFor(env) {
57
57
  return PROVIDER_ROUTING_ENV_VARS.map((name) => env[name] ?? "").join("\0");
58
58
  }
@@ -88,20 +88,19 @@ export function cacheResultContextWindow(providerCacheKey, modelUsageKey, assist
88
88
  /** The context window to report *right now* for a model, with NO IPC on the
89
89
  * critical path: the cached authoritative value if we've learned it (from a
90
90
  * prior turn's `result.modelUsage`, this or any session on the same backend),
91
- * else the text heuristic over the model row's identity strings, else the
92
- * default. Derives the cache key itself — `modelInfo?.resolvedModel ?? modelId`,
93
- * the same rule at every seed site — so read keys can't drift from the write
94
- * site's spelling. `authoritative` reports whether the value came from the
95
- * cache: an authoritative window can legitimately equal
96
- * DEFAULT_CONTEXT_WINDOW, so the value alone can't tell the caller. */
91
+ * else DEFAULT_CONTEXT_WINDOW. The model's names do not give the window:
92
+ * Claude Code 2.1.323 reports 1M for `sonnet`, and 200K for it under
93
+ * `CLAUDE_CODE_DISABLE_1M_CONTEXT=1`. Derives the cache key itself —
94
+ * `modelInfo?.resolvedModel ?? modelId`, the same rule at every seed site — so
95
+ * read keys can't drift from the write site's spelling. `authoritative`
96
+ * reports whether the value came from the cache: an authoritative window can
97
+ * legitimately equal DEFAULT_CONTEXT_WINDOW, so the value alone can't tell the
98
+ * caller. */
97
99
  export function immediateContextWindow(providerCacheKey, modelId, modelInfo) {
98
100
  const cached = contextWindowCache.get(contextWindowCacheKey(providerCacheKey, modelInfo?.resolvedModel ?? modelId));
99
101
  if (cached !== undefined)
100
102
  return { size: cached, authoritative: true };
101
- return {
102
- size: inferContextWindowFromModel(modelId, modelInfo?.resolvedModel, modelInfo?.displayName, modelInfo?.description) ?? DEFAULT_CONTEXT_WINDOW,
103
- authoritative: false,
104
- };
103
+ return { size: DEFAULT_CONTEXT_WINDOW, authoritative: false };
105
104
  }
106
105
  /** Forgets the learned windows, as a logout asks: 1M-context entitlement is
107
106
  * gated per org/tier, and an OAuth re-login is invisible to the env-derived
@@ -1,4 +1,13 @@
1
1
  import { resolveSettings } from "@anthropic-ai/claude-agent-sdk";
2
+ /**
3
+ * The machine policy sources that may be there and did not load
4
+ * (`machinePolicy.didNotLoad`, SDK 0.3.323), named for a log line: "the macOS
5
+ * MDM profile, the managed-settings file". The resolved settings show such a
6
+ * source as absent, so the adapter applies nothing from it, and Claude Code
7
+ * reads the policy itself. Undefined when every source loaded, and when the
8
+ * SDK does not report it.
9
+ */
10
+ export declare function unloadedPolicySources(resolved: Pick<Awaited<ReturnType<typeof resolveSettings>>, "machinePolicy">): string | undefined;
2
11
  /**
3
12
  * Applies the managed-policy tier's env vars to `process.env` before any SDK
4
13
  * call, so the SDK subprocess inherits them. Going through `resolveSettings`
@@ -1 +1 @@
1
- {"version":3,"file":"managed-policy.d.ts","sourceRoot":"","sources":["../src/managed-policy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAEjE;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,GAAE,OAAO,eAAiC,EACjD,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAe,GACpD,OAAO,CAAC,IAAI,CAAC,CAYf"}
1
+ {"version":3,"file":"managed-policy.d.ts","sourceRoot":"","sources":["../src/managed-policy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AASjE;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC,EAAE,eAAe,CAAC,GAC3E,MAAM,GAAG,SAAS,CAIpB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,GAAE,OAAO,eAAiC,EACjD,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAe,GACpD,OAAO,CAAC,IAAI,CAAC,CAmBf"}
@@ -1,4 +1,24 @@
1
1
  import { resolveSettings } from "@anthropic-ai/claude-agent-sdk";
2
+ /** The machine policy sources that `machinePolicy.didNotLoad` names. */
3
+ const POLICY_SOURCES = {
4
+ profile: "the macOS MDM profile",
5
+ registry: "the Windows registry policy",
6
+ file: "the managed-settings file",
7
+ };
8
+ /**
9
+ * The machine policy sources that may be there and did not load
10
+ * (`machinePolicy.didNotLoad`, SDK 0.3.323), named for a log line: "the macOS
11
+ * MDM profile, the managed-settings file". The resolved settings show such a
12
+ * source as absent, so the adapter applies nothing from it, and Claude Code
13
+ * reads the policy itself. Undefined when every source loaded, and when the
14
+ * SDK does not report it.
15
+ */
16
+ export function unloadedPolicySources(resolved) {
17
+ const unloaded = resolved.machinePolicy?.didNotLoad;
18
+ if (!unloaded || unloaded.length === 0)
19
+ return undefined;
20
+ return unloaded.map((kind) => POLICY_SOURCES[kind] ?? kind).join(", ");
21
+ }
2
22
  /**
3
23
  * Applies the managed-policy tier's env vars to `process.env` before any SDK
4
24
  * call, so the SDK subprocess inherits them. Going through `resolveSettings`
@@ -25,6 +45,11 @@ export async function applyManagedPolicyEnv(resolve = resolveSettings, env = pro
25
45
  console.error("Failed to resolve managed policy settings:", error);
26
46
  return;
27
47
  }
48
+ const unloaded = unloadedPolicySources(policy);
49
+ if (unloaded) {
50
+ console.error(`Managed settings did not load from ${unloaded}: its env vars are not applied. ` +
51
+ "Restart the agent to read it again.");
52
+ }
28
53
  for (const [key, value] of Object.entries(policy.effective.env ?? {})) {
29
54
  env[key] = value;
30
55
  }
@@ -5,7 +5,19 @@
5
5
  * `v1/acp-agent.ts` and `v2/`). Each core adds its own side effects, such as v1's
6
6
  * session failure category.
7
7
  */
8
- import type { SDKMessage, SDKMessageOrigin, SDKResultMessage } from "@anthropic-ai/claude-agent-sdk";
8
+ import type { SDKMessage, SDKMessageOrigin, SDKRateLimitInfo, SDKResultMessage } from "@anthropic-ai/claude-agent-sdk";
9
+ /**
10
+ * The `data` of the error that fails a turn, for clients to dispatch on
11
+ * without matching its text: the assistant message's `errorKind`, and for a
12
+ * `rate_limit` failure the turn's latest `rate_limit_event` info as
13
+ * `rateLimit`, whose `resetsAt` says when the account can run again. A turn
14
+ * refused before its first usage sends no `usage_update` to carry that info.
15
+ * `undefined` without an error kind.
16
+ */
17
+ export declare function turnErrorData<K extends string>(errorKind: K | undefined, rateLimit: SDKRateLimitInfo | undefined): {
18
+ errorKind: K;
19
+ rateLimit?: SDKRateLimitInfo;
20
+ } | undefined;
9
21
  export type ResultEnd = {
10
22
  stopReason: "refusal" | "max_tokens" | "end_turn" | "max_turn_requests";
11
23
  }
@@ -1 +1 @@
1
- {"version":3,"file":"result-end.d.ts","sourceRoot":"","sources":["../src/result-end.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EACV,UAAU,EACV,gBAAgB,EAChB,gBAAgB,EACjB,MAAM,gCAAgC,CAAC;AAExC,MAAM,MAAM,SAAS,GACjB;IAAE,UAAU,EAAE,SAAS,GAAG,YAAY,GAAG,UAAU,GAAG,mBAAmB,CAAA;CAAE;AAC7E;;;GAGG;GACD;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,OAAO,CAAA;CAAE,CAAC;AAE9C;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEzD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,MAAM,EAAE,gBAAgB,GAAG,SAAS,CAmB7D;AAMD;;;;;;;;;;;;;;;;;;;;;kDAqBkD;AAClD,eAAO,MAAM,yBAAyB,EAAE,WAAW,CAAC,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"}
@@ -1,3 +1,16 @@
1
+ /**
2
+ * The `data` of the error that fails a turn, for clients to dispatch on
3
+ * without matching its text: the assistant message's `errorKind`, and for a
4
+ * `rate_limit` failure the turn's latest `rate_limit_event` info as
5
+ * `rateLimit`, whose `resetsAt` says when the account can run again. A turn
6
+ * refused before its first usage sends no `usage_update` to carry that info.
7
+ * `undefined` without an error kind.
8
+ */
9
+ export function turnErrorData(errorKind, rateLimit) {
10
+ if (!errorKind)
11
+ return undefined;
12
+ return errorKind === "rate_limit" && rateLimit ? { errorKind, rateLimit } : { errorKind };
13
+ }
1
14
  /**
2
15
  * True when CLI error text tells the user to sign in with `/login`. The CLI
3
16
  * words this several ways — "Not logged in · Please run /login", "Not logged
@@ -1,5 +1,5 @@
1
1
  import type { SessionConfigOption } from "@agentclientprotocol/sdk/unstable";
2
- import type { ModelInfo, Query, Settings } from "@anthropic-ai/claude-agent-sdk";
2
+ import { type ModelInfo, type Query, type Settings } from "@anthropic-ai/claude-agent-sdk";
3
3
  export declare const MODEL_CONFIG_ID = "model";
4
4
  export type SessionModelState = {
5
5
  availableModels: Array<{
@@ -52,15 +52,20 @@ export declare function buildModelConfigOption(models: SessionModelState, modelI
52
52
  */
53
53
  export declare function aliasResumedModelRow(models: ModelInfo[], resumedModel: string | undefined): ModelInfo[];
54
54
  /**
55
- * Whether managed `deniedModels` blocks a model id, following the CLI's rules
56
- * closely enough for the picker: a family alias blocks the whole family, and a
57
- * model id blocks that version in every spelling plus the later minor versions
58
- * it prefixes (`claude-opus-5` also blocks `claude-opus-5-5`). Entries share
59
- * `normalizeModelId`, so `claude-opus-4.5` or `anthropic/claude-opus-4.5` also
60
- * blocks `claude-opus-4-5`, which the CLI may still allow. The CLI stays the
61
- * enforcer; this only keeps the picker from offering a refused row.
55
+ * Which of `ids` a managed `deniedModels` list blocks, by the CLI's own entry
56
+ * rules: the SDK's `matchDeniedModels`, asked about each of the
57
+ * {@link deniedModelSpellings} of an id.
58
+ * - A family alias (`opus`) blocks the family.
59
+ * - A model id blocks that version in every spelling, and the later minor
60
+ * versions when it names none (`claude-opus-5` also blocks `claude-opus-5-5`).
61
+ * - Any other entry (`claude-opus-4.5`, `my-model`) blocks only that name,
62
+ * alone or as the last path segment (`gateway/my-model`).
63
+ * - `default`, `best` and `opusplan` block nothing.
64
+ *
65
+ * The CLI stays the enforcer; this only keeps the picker from offering a row
66
+ * that `setModel` would refuse.
62
67
  */
63
- export declare function isDeniedModel(modelId: string, deniedModels: readonly string[]): boolean;
68
+ export declare function deniedModelIds(ids: readonly string[], deniedModels: readonly string[]): Promise<Set<string>>;
64
69
  /**
65
70
  * Restrict the SDK's model list to the user's `availableModels` allowlist
66
71
  * (already merged-and-deduped across settings sources by `SettingsManager`).
@@ -76,10 +81,11 @@ export declare function isDeniedModel(modelId: string, deniedModels: readonly st
76
81
  * - `undefined` is handled by the caller (no allowlist applied).
77
82
  * - The Default option is unaffected by `availableModels` — it always remains
78
83
  * available, even when the allowlist is `[]`.
79
- * - Managed `deniedModels` wins over the allowlist, so a denied entry is
80
- * dropped even though the CLI would otherwise leave it unmatched.
84
+ * - Managed `deniedModels` wins over the allowlist: an entry is dropped when
85
+ * the list blocks its name, its `modelOverrides` target, or the model of the
86
+ * row it resolves to (see {@link deniedModelIds}).
81
87
  */
82
- export declare function applyAvailableModelsAllowlist(sdkModels: ModelInfo[], allowlist: string[], settingsModelOverrides?: Record<string, string>, deniedModels?: readonly string[]): ModelInfo[];
88
+ export declare function applyAvailableModelsAllowlist(sdkModels: ModelInfo[], allowlist: string[], settingsModelOverrides?: Record<string, string>, deniedModels?: readonly string[]): Promise<ModelInfo[]>;
83
89
  /**
84
90
  * Keep the SDK models the `providers/set` gateway listed (`listGatewayModels`,
85
91
  * `listBedrockModels`). A row matches when its `resolvedModel` (or
@@ -119,10 +125,10 @@ export declare function narrowToGatewayModels(models: ModelInfo[], listedModelId
119
125
  * capability flag (current and future); the identity fields are overridden
120
126
  * because the fuzzy-matched sibling's resolvedModel/displayName/description
121
127
  * can describe a different context lane and would poison later resolvedModel
122
- * matching (a model switch that the adapter did not make) and context-window
123
- * inference if they traveled under this id. `allowlistedModelInfo` is the
124
- * allowlisted entry alone, the only one whose identity strings are a
125
- * trustworthy window signal.
128
+ * matching (a model switch that the adapter did not make) and the lookup of
129
+ * the learned context window (`immediateContextWindow`) if they traveled under
130
+ * this id. `allowlistedModelInfo` is the allowlisted entry alone, the only one
131
+ * whose `resolvedModel` that lookup may use.
126
132
  */
127
133
  export declare function withCurrentModelInfo(allowedModels: ModelInfo[], sdkModels: ModelInfo[], currentModelId: string): {
128
134
  allowlistedModelInfo: ModelInfo | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"session-model.d.ts","sourceRoot":"","sources":["../src/session-model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAIjF,eAAO,MAAM,eAAe,UAAU,CAAC;AAEvC,MAAM,MAAM,iBAAiB,GAAG;IAC9B,eAAe,EAAE,KAAK,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAChF,cAAc,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,KAAK,WAAW,GAAG;IACjB,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IAClC,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;CACrC,CAAC;AACF,KAAK,mBAAmB,GAAG;IAAE,WAAW,IAAI,QAAQ,CAAA;CAAE,CAAC;AAmHvD;;;;;;;;;;;GAWG;AACH,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,UAAU,EAAE,MAAM,GA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,CAAC,EAAE,MAAM,GACpB,SAAS,EAAE,CAiBb;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,oBAAoB,CAClC,aAAa,EAAE,SAAS,EAAE,EAC1B,SAAS,EAAE,SAAS,EAAE,EACtB,cAAc,EAAE,MAAM,GACrB;IACD,oBAAoB,EAAE,SAAS,GAAG,SAAS,CAAC;IAC5C,gBAAgB,EAAE,SAAS,GAAG,SAAS,CAAC;IACxC,UAAU,EAAE,SAAS,EAAE,CAAC;CACzB,CAqBA;AAWD,wBAAsB,kBAAkB,CACtC,KAAK,EAAE,KAAK,EACZ,MAAM,EAAE,SAAS,EAAE,EACnB,SAAS,EAAE,SAAS,EAAE,EACtB,eAAe,EAAE,mBAAmB,EACpC,MAAM,EAAE,WAAW,EACnB,gBAAgB,EAAE,OAAO,EACzB,SAAS,EAAE,MAAM,EACjB,gBAAgB,CAAC,EAAE,MAAM,EACzB,iBAAiB,UAAQ,GACxB,OAAO,CAAC,iBAAiB,CAAC,CA4J5B;AAED,gFAAgF;AAChF,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,SAAS,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAQ3F;AAaD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,aAAa,CAC3B,aAAa,EAAE,SAAS,mBAAmB,EAAE,EAC7C,UAAU,EAAE,SAAS,EAAE,EACvB,KAAK,EAAE,MAAM,GACZ;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAW7C"}
@@ -1,3 +1,5 @@
1
+ // matchDeniedModels is marked @alpha in the SDK; API may shift in a future release.
2
+ import { matchDeniedModels, } from "@anthropic-ai/claude-agent-sdk";
1
3
  import { AIR_RECOMMENDED_CONFIG_VALUE_CAPABILITY, withAirMeta } from "./air-extension.js";
2
4
  import { bedrockRegionPrefix } from "./gateway-models.js";
3
5
  export const MODEL_CONFIG_ID = "model";
@@ -85,7 +87,7 @@ function containsWords(haystack, needle) {
85
87
  return false;
86
88
  }
87
89
  /** `id` without the gateway spellings that `normalizeModelId` keeps for
88
- * `deniedModels` and gateway listings: path segments before `claude-`
90
+ * gateway listings: path segments before `claude-`
89
91
  * (`vertex_ai/`, `openrouter/anthropic/`, `publishers/anthropic/models/`)
90
92
  * and the Anthropic API's `-latest` suffix (`claude-3-5-haiku-latest`). */
91
93
  function withoutGatewaySpelling(id) {
@@ -308,8 +310,8 @@ export function aliasResumedModelRow(models, resumedModel) {
308
310
  }
309
311
  /** A model id without the spellings that name the same model: provider
310
312
  * prefixes, dates, version suffixes, `:variant` suffixes, dotted versions,
311
- * `-fast` and context hints. `deniedModels` and gateway listings both match on
312
- * it. OpenRouter lists `anthropic/claude-opus-5.5:batch[1m]`, which normalizes
313
+ * `-fast` and context hints. Gateway listings match on it. OpenRouter lists
314
+ * `anthropic/claude-opus-5.5:batch[1m]`, which normalizes
313
315
  * to `claude-opus-5-5`; `anthropic/openai/gpt-5` keeps its `openai/` prefix and
314
316
  * matches no Claude id. */
315
317
  function normalizeModelId(value) {
@@ -331,27 +333,49 @@ function normalizeModelId(value) {
331
333
  .replace(/-fast$/, "")
332
334
  .replace(/-\d{8}$/, ""));
333
335
  }
336
+ /** A path that no model id starts with. Nothing enforces that no
337
+ * `deniedModels` entry names it (see {@link deniedModelSpellings}). */
338
+ const VERSION_SPELLING_PATH = "version-of/";
334
339
  /**
335
- * Whether managed `deniedModels` blocks a model id, following the CLI's rules
336
- * closely enough for the picker: a family alias blocks the whole family, and a
337
- * model id blocks that version in every spelling plus the later minor versions
338
- * it prefixes (`claude-opus-5` also blocks `claude-opus-5-5`). Entries share
339
- * `normalizeModelId`, so `claude-opus-4.5` or `anthropic/claude-opus-4.5` also
340
- * blocks `claude-opus-4-5`, which the CLI may still allow. The CLI stays the
341
- * enforcer; this only keeps the picker from offering a refused row.
340
+ * The spellings of `id` to ask the SDK's `matchDeniedModels` about. That
341
+ * function compares an id with the entries alone. The CLI blocks more
342
+ * (`setModel` against CLI 2.1.323):
343
+ * - a last path segment that an exact-name entry names: `my-model` blocks
344
+ * `gateway/my-model`;
345
+ * - a version behind a `:variant` suffix or written with a dot:
346
+ * `claude-opus-5-5` blocks `claude-opus-5-5:free` and
347
+ * `anthropic/claude-opus-5.5`.
348
+ *
349
+ * An exact-name entry does not block a `:variant`: `my-model` leaves
350
+ * `my-model:free` allowed. So the version spelling goes behind a path, which
351
+ * the SDK ignores for a versioned id and which keeps the spelling from
352
+ * equalling an exact name.
342
353
  */
343
- export function isDeniedModel(modelId, deniedModels) {
344
- const id = normalizeModelId(modelId);
345
- if (!id)
346
- return false;
347
- return deniedModels.some((entry) => {
348
- const denied = normalizeModelId(entry);
349
- if (!denied)
350
- return false;
351
- if (MODEL_FAMILY_ALIASES.has(denied))
352
- return id === denied || id.includes(`-${denied}`);
353
- return id === denied || id.startsWith(`${denied}-`);
354
- });
354
+ function deniedModelSpellings(id) {
355
+ const lastSegment = id.slice(id.lastIndexOf("/") + 1);
356
+ const version = lastSegment.replace(/:.*$/, "").replace(/(?<=\d)\.(?=\d)/g, "-");
357
+ return [id, lastSegment, `${VERSION_SPELLING_PATH}${version}`];
358
+ }
359
+ /**
360
+ * Which of `ids` a managed `deniedModels` list blocks, by the CLI's own entry
361
+ * rules: the SDK's `matchDeniedModels`, asked about each of the
362
+ * {@link deniedModelSpellings} of an id.
363
+ * - A family alias (`opus`) blocks the family.
364
+ * - A model id blocks that version in every spelling, and the later minor
365
+ * versions when it names none (`claude-opus-5` also blocks `claude-opus-5-5`).
366
+ * - Any other entry (`claude-opus-4.5`, `my-model`) blocks only that name,
367
+ * alone or as the last path segment (`gateway/my-model`).
368
+ * - `default`, `best` and `opusplan` block nothing.
369
+ *
370
+ * The CLI stays the enforcer; this only keeps the picker from offering a row
371
+ * that `setModel` would refuse.
372
+ */
373
+ export async function deniedModelIds(ids, deniedModels) {
374
+ if (ids.length === 0 || deniedModels.length === 0)
375
+ return new Set();
376
+ const asked = ids.flatMap((id) => deniedModelSpellings(id).map((spelling) => ({ id, spelling })));
377
+ const { denied } = await matchDeniedModels(asked.map(({ spelling }) => spelling), deniedModels);
378
+ return new Set(asked.filter((_, index) => denied[index]).map(({ id }) => id));
355
379
  }
356
380
  /**
357
381
  * Restrict the SDK's model list to the user's `availableModels` allowlist
@@ -368,10 +392,11 @@ export function isDeniedModel(modelId, deniedModels) {
368
392
  * - `undefined` is handled by the caller (no allowlist applied).
369
393
  * - The Default option is unaffected by `availableModels` — it always remains
370
394
  * available, even when the allowlist is `[]`.
371
- * - Managed `deniedModels` wins over the allowlist, so a denied entry is
372
- * dropped even though the CLI would otherwise leave it unmatched.
395
+ * - Managed `deniedModels` wins over the allowlist: an entry is dropped when
396
+ * the list blocks its name, its `modelOverrides` target, or the model of the
397
+ * row it resolves to (see {@link deniedModelIds}).
373
398
  */
374
- export function applyAvailableModelsAllowlist(sdkModels, allowlist, settingsModelOverrides, deniedModels = []) {
399
+ export async function applyAvailableModelsAllowlist(sdkModels, allowlist, settingsModelOverrides, deniedModels = []) {
375
400
  // Default is always preserved per the docs. Synthesize one if the SDK
376
401
  // didn't surface it so downstream code (e.g. `getAvailableModels` picking
377
402
  // `models[0]` as a fallback) still has something to work with.
@@ -390,18 +415,21 @@ export function applyAvailableModelsAllowlist(sdkModels, allowlist, settingsMode
390
415
  // opaque provider IDs) often won't textually resemble anything in
391
416
  // `sdkModelsWithoutDefault`. Only the entry's surfaced `value` becomes the
392
417
  // override target, so it's what `setModel` ends up passing to the API.
393
- for (const entry of allowlist) {
418
+ const entries = allowlist.flatMap((entry) => {
394
419
  const trimmed = entry.trim();
395
- if (!trimmed || seen.has(trimmed))
396
- continue;
397
- const overridden = settingsModelOverrides?.[trimmed];
398
- const effective = overridden ?? trimmed;
399
- if (seen.has(effective))
400
- continue;
420
+ if (!trimmed)
421
+ return [];
422
+ const effective = settingsModelOverrides?.[trimmed] ?? trimmed;
401
423
  const sdkMatch = resolveModelPreference(sdkModelsWithoutDefault, trimmed);
402
- if ([trimmed, effective, sdkMatch?.resolvedModel].some((id) => id != null && isDeniedModel(id, deniedModels))) {
424
+ const ids = [trimmed, effective, ...(sdkMatch?.resolvedModel ? [sdkMatch.resolvedModel] : [])];
425
+ return [{ trimmed, effective, sdkMatch, ids }];
426
+ });
427
+ const denied = await deniedModelIds(entries.flatMap(({ ids }) => ids), deniedModels);
428
+ for (const { trimmed, effective, sdkMatch, ids } of entries) {
429
+ if (seen.has(trimmed) || seen.has(effective))
430
+ continue;
431
+ if (ids.some((id) => denied.has(id)))
403
432
  continue;
404
- }
405
433
  if (sdkMatch) {
406
434
  result.push({ ...sdkMatch, value: effective });
407
435
  }
@@ -485,10 +513,10 @@ export function narrowToGatewayModels(models, listedModelIds, regionPrefix) {
485
513
  * capability flag (current and future); the identity fields are overridden
486
514
  * because the fuzzy-matched sibling's resolvedModel/displayName/description
487
515
  * can describe a different context lane and would poison later resolvedModel
488
- * matching (a model switch that the adapter did not make) and context-window
489
- * inference if they traveled under this id. `allowlistedModelInfo` is the
490
- * allowlisted entry alone, the only one whose identity strings are a
491
- * trustworthy window signal.
516
+ * matching (a model switch that the adapter did not make) and the lookup of
517
+ * the learned context window (`immediateContextWindow`) if they traveled under
518
+ * this id. `allowlistedModelInfo` is the allowlisted entry alone, the only one
519
+ * whose `resolvedModel` that lookup may use.
492
520
  */
493
521
  export function withCurrentModelInfo(allowedModels, sdkModels, currentModelId) {
494
522
  const allowlistedModelInfo = allowedModels.find((m) => m.value === currentModelId);
@@ -25,7 +25,14 @@ export declare const ZERO_USAGE: Readonly<{
25
25
  cache_read_input_tokens: 0;
26
26
  cache_creation_input_tokens: 0;
27
27
  }>;
28
- export declare const DEFAULT_CONTEXT_WINDOW = 200000;
28
+ /**
29
+ * The context window reported for a model until Claude Code says what it is
30
+ * (see `context-window.ts`): 1M, the window Claude Code itself assumes for a
31
+ * model id it does not know (since 2.1.323). Claude Code reports 200K for an
32
+ * older model such as `claude-sonnet-4-5`, and for every model under
33
+ * `CLAUDE_CODE_DISABLE_1M_CONTEXT=1`.
34
+ */
35
+ export declare const DEFAULT_CONTEXT_WINDOW = 1000000;
29
36
  /** `_meta.quota` for work that spent `usage` in its main agent loop and
30
37
  * `modelUsage` by model (see `turnQuotaMeta` in `v1/acp-agent.ts`). */
31
38
  export declare function quotaMeta(usage: AccumulatedUsage, modelUsage: ModelTokenTally | undefined): {
@@ -102,22 +109,6 @@ export declare function snapshotFromUsage(usage: {
102
109
  cache_read_input_tokens?: number | null;
103
110
  cache_creation_input_tokens?: number | null;
104
111
  }): UsageSnapshot;
105
- /** Best-effort first guess of a model's context window, used to seed the
106
- * window synchronously (via `immediateContextWindow`) until a `result` message
107
- * arrives with the authoritative `modelUsage` value.
108
- *
109
- * Anthropic 1M-context variants encode "1m" as a distinct token in the SDK
110
- * model ID (e.g., "claude-opus-4-6-1m"), which `\b1m\b` catches without also
111
- * matching things like "10m" or embedded substrings. Semantic aliases like
112
- * `default` carry no such token in the ID, but their `resolvedModel` and the
113
- * SDK's human-facing `displayName`/`description` can (e.g.
114
- * "claude-opus-4-8[1m]", "Opus 4.7 (1M context)"), so callers pass those too.
115
- * This text scan can't catch every model — some resolve to extended-context
116
- * models with no "1m" anywhere (e.g. `sonnet` → claude-sonnet-5, natively
117
- * ~1M). Such a miss falls back to the default window, is refined by the
118
- * background `getContextUsage` (`refreshContextWindowInBackground`), and is
119
- * corrected by `result.modelUsage` (and cached) within one turn. */
120
- export declare function inferContextWindowFromModel(...texts: Array<string | undefined>): number | null;
121
112
  export declare function getMatchingModelUsage(modelUsage: Record<string, ModelUsage>, currentModel: string): {
122
113
  key: string;
123
114
  usage: ModelUsage;
@@ -1 +1 @@
1
- {"version":3,"file":"session-usage.d.ts","sourceRoot":"","sources":["../src/session-usage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAEjE,MAAM,MAAM,gBAAgB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AAM,GAAG,IAAI,CAAC;IAC7B,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,uBAAuB,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxC,2BAA2B,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7C,GAAG,aAAa,CAOhB;AAUD,wBAAgB,qBAAqB,CACnC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,EACtC,YAAY,EAAE,MAAM;;;cAsBrB"}
@@ -4,7 +4,14 @@ export const ZERO_USAGE = Object.freeze({
4
4
  cache_read_input_tokens: 0,
5
5
  cache_creation_input_tokens: 0,
6
6
  });
7
- export const DEFAULT_CONTEXT_WINDOW = 200000;
7
+ /**
8
+ * The context window reported for a model until Claude Code says what it is
9
+ * (see `context-window.ts`): 1M, the window Claude Code itself assumes for a
10
+ * model id it does not know (since 2.1.323). Claude Code reports 200K for an
11
+ * older model such as `claude-sonnet-4-5`, and for every model under
12
+ * `CLAUDE_CODE_DISABLE_1M_CONTEXT=1`.
13
+ */
14
+ export const DEFAULT_CONTEXT_WINDOW = 1_000_000;
8
15
  /** `_meta.quota` for work that spent `usage` in its main agent loop and
9
16
  * `modelUsage` by model (see `turnQuotaMeta` in `v1/acp-agent.ts`). */
10
17
  export function quotaMeta(usage, modelUsage) {
@@ -154,26 +161,6 @@ function commonPrefixLength(a, b) {
154
161
  }
155
162
  return i;
156
163
  }
157
- /** Best-effort first guess of a model's context window, used to seed the
158
- * window synchronously (via `immediateContextWindow`) until a `result` message
159
- * arrives with the authoritative `modelUsage` value.
160
- *
161
- * Anthropic 1M-context variants encode "1m" as a distinct token in the SDK
162
- * model ID (e.g., "claude-opus-4-6-1m"), which `\b1m\b` catches without also
163
- * matching things like "10m" or embedded substrings. Semantic aliases like
164
- * `default` carry no such token in the ID, but their `resolvedModel` and the
165
- * SDK's human-facing `displayName`/`description` can (e.g.
166
- * "claude-opus-4-8[1m]", "Opus 4.7 (1M context)"), so callers pass those too.
167
- * This text scan can't catch every model — some resolve to extended-context
168
- * models with no "1m" anywhere (e.g. `sonnet` → claude-sonnet-5, natively
169
- * ~1M). Such a miss falls back to the default window, is refined by the
170
- * background `getContextUsage` (`refreshContextWindowInBackground`), and is
171
- * corrected by `result.modelUsage` (and cached) within one turn. */
172
- export function inferContextWindowFromModel(...texts) {
173
- if (texts.some((text) => text != null && /\b1m\b/i.test(text)))
174
- return 1_000_000;
175
- return null;
176
- }
177
164
  export function getMatchingModelUsage(modelUsage, currentModel) {
178
165
  let bestKey = null;
179
166
  let bestLen = 0;
@@ -29,6 +29,8 @@ export declare class SettingsManager {
29
29
  private managedModelSettings;
30
30
  private managedApiKeyHelper?;
31
31
  private managedCompactionSettings;
32
+ /** The policy sources last logged as not loaded (see {@link unloadedPolicySources}). */
33
+ private unloadedPolicy?;
32
34
  private watchers;
33
35
  private onChange?;
34
36
  private logger;
@@ -1 +1 @@
1
- {"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../src/settings.ts"],"names":[],"mappings":"AAIA,OAAO,EAGL,KAAK,QAAQ,EACd,MAAM,gCAAgC,CAAC;AA0BxC,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,MAAM,CAAC,EAAE;QAAE,GAAG,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;QAAC,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAA;KAAE,CAAC;CAC7E;AAED,KAAK,sBAAsB,GAAG,IAAI,CAAC,QAAQ,EAAE,iBAAiB,GAAG,gBAAgB,CAAC,CAAC;AAEnF,wFAAwF;AACxF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;C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O,CAAC,EAAE,sBAAsB;IAMzD;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAmBjC;;;OAGG;IACH,OAAO,CAAC,eAAe;IASvB;;;OAGG;YACW,eAAe;IAoD7B;;OAEG;IACH,OAAO,CAAC,aAAa;IAyBrB;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAqB5B;;OAEG;IACH,WAAW,IAAI,QAAQ;IAIvB;;;OAGG;IACH,eAAe,CAAC,gBAAgB,CAAC,EAAE,QAAQ,GAAG,MAAM,GAAG,SAAS;IAMhE,uEAAuE;IACvE,yBAAyB,CAAC,QAAQ,CAAC,EAAE,QAAQ,GAAG,sBAAsB;IAmBtE;;;;;OAKG;IACH,qBAAqB,CAAC,gBAAgB,CAAC,EAAE,QAAQ,GAAG,kBAAkB;IAmBtE;;;OAGG;IACH,sBAAsB,IAAI,MAAM,EAAE;IAIlC;;OAEG;IACH,MAAM,IAAI,MAAM;IAIhB;;OAEG;IACG,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAUxC;;OAEG;IACH,OAAO,IAAI,IAAI;CAehB"}
package/dist/settings.js CHANGED
@@ -3,6 +3,7 @@ import * as path from "node:path";
3
3
  // resolveSettings and filterEscalatingDefaultMode are marked @alpha in the
4
4
  // SDK; API may shift in a future release.
5
5
  import { filterEscalatingDefaultMode, resolveSettings, } from "@anthropic-ai/claude-agent-sdk";
6
+ import { unloadedPolicySources } from "./managed-policy.js";
6
7
  import { claudeConfigDir } from "./paths.js";
7
8
  /**
8
9
  * Permission rule format examples:
@@ -41,6 +42,8 @@ export class SettingsManager {
41
42
  managedModelSettings = {};
42
43
  managedApiKeyHelper;
43
44
  managedCompactionSettings = {};
45
+ /** The policy sources last logged as not loaded (see {@link unloadedPolicySources}). */
46
+ unloadedPolicy;
44
47
  watchers = [];
45
48
  onChange;
46
49
  logger;
@@ -92,6 +95,15 @@ export class SettingsManager {
92
95
  async loadAllSettings() {
93
96
  try {
94
97
  const resolved = await resolveSettings({ cwd: this.cwd });
98
+ // Once per change: a reload after each settings file edit would repeat it.
99
+ const unloaded = unloadedPolicySources(resolved);
100
+ if (unloaded !== this.unloadedPolicy) {
101
+ this.unloadedPolicy = unloaded;
102
+ if (unloaded) {
103
+ this.logger.error(`Managed settings did not load from ${unloaded}: the session's settings ` +
104
+ "and model list do not reflect it. Claude Code reads the policy itself.");
105
+ }
106
+ }
95
107
  this.effective = filterEscalatingDefaultMode(resolved);
96
108
  // The CLI reads `deniedModels` from managed settings only.
97
109
  this.managedDeniedModels = resolved.sources
@@ -265,12 +265,16 @@ export declare class AcpToolCallRenderer {
265
265
  * client `failed`, since v1 has no `cancelled`. If Claude Code ran it but
266
266
  * returned no result, it failed, unless a `session/cancel` ended the turn
267
267
  * (`cancelled`): the cancel stopped the run, so a v2 client gets `cancelled`
268
- * for it too. The report does not end the call's terminal: see {@link terminalExit}.
268
+ * for it too. The same goes for a call that Claude Code stopped when it took
269
+ * back the message that made it (`retracted`, see `RetractedToolCalls`),
270
+ * which closes when that is known, before the turn ends. The report does not
271
+ * end the call's terminal: see {@link terminalExit}.
269
272
  */
270
273
  unfinished(call: {
271
274
  toolCallId: string;
272
275
  ran: boolean;
273
276
  cancelled?: boolean;
277
+ retracted?: boolean;
274
278
  }): ToolCallUpdate;
275
279
  /**
276
280
  * The `_meta` that ends the display terminal of a command whose tool call gets no result, to