typeclaw 0.48.11 → 0.48.13

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 (94) hide show
  1. package/package.json +7 -4
  2. package/src/agent/attention-escalation.ts +8 -5
  3. package/src/agent/auth-reloadable.ts +2 -3
  4. package/src/agent/auth.ts +59 -79
  5. package/src/agent/compaction.ts +2 -2
  6. package/src/agent/index.ts +42 -16
  7. package/src/agent/llm-replay-sanitizer.ts +1 -1
  8. package/src/agent/model-overrides.ts +1 -1
  9. package/src/agent/multimodal/look-at.ts +3 -3
  10. package/src/agent/multimodal/read-redirect.ts +1 -1
  11. package/src/agent/plugin-tools.ts +26 -31
  12. package/src/agent/reload-tool.ts +1 -1
  13. package/src/agent/subagents.ts +1 -1
  14. package/src/agent/tool-error-remediation.ts +1 -1
  15. package/src/agent/tool-result-budget.ts +2 -2
  16. package/src/agent/tools/channel-disengage.ts +2 -2
  17. package/src/agent/tools/channel-edit.ts +2 -2
  18. package/src/agent/tools/channel-fetch-attachment.ts +2 -2
  19. package/src/agent/tools/channel-history.ts +2 -2
  20. package/src/agent/tools/channel-react.ts +2 -2
  21. package/src/agent/tools/channel-read.ts +2 -2
  22. package/src/agent/tools/channel-reply.ts +2 -2
  23. package/src/agent/tools/channel-send.ts +2 -2
  24. package/src/agent/tools/grant-role.ts +2 -2
  25. package/src/agent/tools/post-github-review.ts +2 -2
  26. package/src/agent/tools/restart.ts +2 -2
  27. package/src/agent/tools/skip-response.ts +2 -2
  28. package/src/agent/tools/spawn-subagent.ts +2 -2
  29. package/src/agent/tools/stream-snapshot.ts +2 -2
  30. package/src/agent/tools/subagent-cancel.ts +2 -2
  31. package/src/agent/tools/subagent-output.ts +2 -2
  32. package/src/agent/tools/todo/index.ts +2 -2
  33. package/src/agent/tools/webfetch/tool.ts +2 -2
  34. package/src/agent/tools/websearch.ts +2 -2
  35. package/src/bundled-plugins/github-cli-auth/gh-command.ts +7 -1
  36. package/src/bundled-plugins/github-cli-auth/index.ts +1 -1
  37. package/src/bundled-plugins/github-cli-auth/review-checkout.ts +9 -1
  38. package/src/bundled-plugins/memory/dreaming.ts +21 -6
  39. package/src/channels/adapters/kakaotalk-channel-resolver.ts +86 -16
  40. package/src/channels/adapters/kakaotalk.ts +7 -8
  41. package/src/channels/adapters/teams-classify.ts +21 -0
  42. package/src/channels/adapters/teams-edit.ts +2 -1
  43. package/src/channels/adapters/teams-format.ts +16 -0
  44. package/src/channels/adapters/teams.ts +12 -5
  45. package/src/channels/github-review-verdict-coordinator.ts +26 -3
  46. package/src/channels/router.ts +50 -25
  47. package/src/cli/compose.ts +3 -3
  48. package/src/cli/docker-preflight.ts +8 -4
  49. package/src/cli/model.ts +7 -5
  50. package/src/cli/oauth-callbacks.ts +38 -23
  51. package/src/cli/restart.ts +89 -23
  52. package/src/cli/start.ts +68 -16
  53. package/src/cli/status.ts +38 -6
  54. package/src/cli/stop.ts +5 -2
  55. package/src/compose/stop.ts +5 -4
  56. package/src/config/config.ts +62 -25
  57. package/src/config/providers.ts +272 -47
  58. package/src/container/build-cache.ts +807 -0
  59. package/src/container/compose-project.ts +4 -0
  60. package/src/container/docker-app.ts +74 -0
  61. package/src/container/log-archive.ts +33 -5
  62. package/src/container/memory-limit.ts +80 -0
  63. package/src/container/memory-oversubscription.ts +125 -0
  64. package/src/container/restart.ts +6 -1
  65. package/src/container/shared.ts +43 -16
  66. package/src/container/start.ts +280 -53
  67. package/src/container/stop.ts +19 -13
  68. package/src/container/verify-running.ts +12 -0
  69. package/src/cron/scheduler.ts +12 -4
  70. package/src/doctor/bounded-exec.ts +14 -0
  71. package/src/doctor/checks.ts +40 -15
  72. package/src/doctor/index.ts +14 -2
  73. package/src/doctor/plugin-bridge.ts +15 -3
  74. package/src/hostd/paths.ts +4 -0
  75. package/src/init/index.ts +4 -4
  76. package/src/init/oauth-login.ts +57 -17
  77. package/src/inspect/transcript-view.ts +6 -3
  78. package/src/run/channel-session-factory.ts +5 -4
  79. package/src/run/index.ts +27 -11
  80. package/src/run/resource-sample.ts +171 -0
  81. package/src/sandbox/index.ts +8 -1
  82. package/src/sandbox/session-tmp.ts +26 -1
  83. package/src/secrets/refresh-provider-oauth.ts +30 -76
  84. package/src/secrets/schema.ts +3 -4
  85. package/src/secrets/storage.ts +133 -234
  86. package/src/server/index.ts +1 -1
  87. package/src/sessions/index.ts +1 -1
  88. package/src/skills/typeclaw-config/SKILL.md +4 -4
  89. package/src/skills/typeclaw-plugins/SKILL.md +5 -5
  90. package/src/tui/index.ts +5 -3
  91. package/src/tui/theme.ts +1 -1
  92. package/typeclaw.schema.json +32 -1
  93. package/src/agent/adaptive-thinking-compat.ts +0 -79
  94. package/src/secrets/oauth-xai.ts +0 -348
package/src/cli/stop.ts CHANGED
@@ -4,7 +4,7 @@ import { resolveController } from '@/container'
4
4
 
5
5
  import { preflightDocker, printDockerGuidance } from './docker-preflight'
6
6
  import { requireAgentDir } from './require-agent-dir'
7
- import { c, spinner } from './ui'
7
+ import { c, reportConfigWarnings, spinner } from './ui'
8
8
 
9
9
  export const stopCommand = defineCommand({
10
10
  meta: {
@@ -22,10 +22,12 @@ export const stopCommand = defineCommand({
22
22
 
23
23
  const s = spinner()
24
24
  s.start('Stopping container...')
25
- const result = await resolveController().stop({ cwd })
25
+ const warnings: string[] = []
26
+ const result = await resolveController().stop({ cwd, onWarning: (warning) => warnings.push(warning) })
26
27
 
27
28
  if (!result.ok) {
28
29
  s.error(result.reason)
30
+ reportConfigWarnings(warnings)
29
31
  process.exit(1)
30
32
  }
31
33
 
@@ -34,5 +36,6 @@ export const stopCommand = defineCommand({
34
36
  } else {
35
37
  s.stop(c.dim(`Container ${result.containerName} is not running.`))
36
38
  }
39
+ reportConfigWarnings(warnings)
37
40
  },
38
41
  })
@@ -45,11 +45,12 @@ export async function composeStop(
45
45
  }
46
46
 
47
47
  async function runOne(name: string, cwd: string, stop: Controller['stop']): Promise<AgentResult<StopSuccess>> {
48
+ const warnings: string[] = []
48
49
  try {
49
- const data = await stop({ cwd })
50
- if (!data.ok) return { name, ok: false, reason: data.reason }
51
- return { name, ok: true, data }
50
+ const data = await stop({ cwd, onWarning: (warning) => warnings.push(warning) })
51
+ if (!data.ok) return { name, ok: false, reason: data.reason, warnings }
52
+ return { name, ok: true, data, warnings }
52
53
  } catch (error) {
53
- return { name, ok: false, reason: error instanceof Error ? error.message : String(error) }
54
+ return { name, ok: false, reason: error instanceof Error ? error.message : String(error), warnings }
54
55
  }
55
56
  }
@@ -2,7 +2,8 @@ import { accessSync, constants as fsConstants, readFileSync, statSync, writeFile
2
2
  import { homedir } from 'node:os'
3
3
  import { isAbsolute, join, posix, resolve } from 'node:path'
4
4
 
5
- import type { KnownApi, Model } from '@mariozechner/pi-ai'
5
+ import type { KnownApi, Model } from '@earendil-works/pi-ai'
6
+ import { getBuiltinModel } from '@earendil-works/pi-ai/providers/all'
6
7
  import { z } from 'zod'
7
8
 
8
9
  import { channelsSchema, SEEDED_GITHUB_EVENT_ALLOWLISTS } from '@/channels/schema'
@@ -676,7 +677,7 @@ function asModelRef(value: string): ModelRef {
676
677
  // Mirrors pi-coding-agent's `ThinkingLevel`. Kept as a local enum (rather than
677
678
  // importing the SDK type) so the schema owns the canonical value list and zod
678
679
  // can validate `typeclaw.json` without a runtime SDK dependency.
679
- export const thinkingLevelSchema = z.enum(['off', 'minimal', 'low', 'medium', 'high', 'xhigh'])
680
+ export const thinkingLevelSchema = z.enum(['off', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max'])
680
681
  export type ThinkingLevel = z.infer<typeof thinkingLevelSchema>
681
682
 
682
683
  // Reject exact duplicates in a chain — retrying the same ref after the same
@@ -842,44 +843,80 @@ export function resolveModel(ref: KnownModelRef | ModelRef | string): Model<Know
842
843
  }
843
844
 
844
845
  const meta = getConfig().customModels[ref]
846
+ // `api`, `baseUrl`, and (by default) `compat` come from the provider template
847
+ // because they describe the PROVIDER's wire dialect, not the model. pi-ai
848
+ // infers compat from the baseUrl and only recognises first-party hosts, so a
849
+ // custom ref on a provider that pins compat (OpenGateway, Upstage) would
850
+ // otherwise fall back to OpenAI-native defaults and send `store`, the
851
+ // `developer` role, `strict` tool schemas and `max_completion_tokens` to an
852
+ // endpoint that never accepts them.
853
+ //
854
+ // The exception is a ref that pi-ai's catalog already knows, exactly or as
855
+ // its undated `-YYYYMMDD` base, on the same transport. The catalog describes
856
+ // the MODEL, so its name, capabilities, limits, and pricing are the defaults;
857
+ // `customModels` remains the explicit per-field override. pi 0.87 reads some
858
+ // behavior only from per-model metadata: e.g. Anthropic adaptive thinking is
859
+ // `compat.forceAdaptiveThinking` and is no longer inferred from the id.
860
+ // Anthropic's streamSimple gates adaptive thinking on the resolved model's
861
+ // `reasoning` capability, so a dated Sonnet 5 alias must inherit that too.
862
+ // That entry's compat and thinkingLevelMap are used, minus
863
+ // `allowedFallbackModels` (see the Fable 5 record). Without a catalog match
864
+ // `thinkingLevelMap` is deliberately not carried: it varies per model even
865
+ // within one provider, so copying the template's would be a guess.
866
+ const builtin = findBuiltinModel(providerId, modelId)
867
+ const catalogMetadata = builtin !== undefined && builtin.api === template.api ? builtin : undefined
868
+ let compat = template.compat
869
+ if (catalogMetadata !== undefined) {
870
+ const catalogCompat: Record<string, unknown> | undefined =
871
+ catalogMetadata.compat === undefined ? undefined : { ...catalogMetadata.compat }
872
+ if (catalogCompat !== undefined) delete catalogCompat.allowedFallbackModels
873
+ compat = catalogCompat as Model<KnownApi>['compat']
874
+ }
845
875
  return {
846
876
  id: modelId,
847
877
  provider: providerId,
848
878
  baseUrl: provider.baseUrl ?? template.baseUrl,
849
879
  api: template.api,
850
- // Carried from the template for the same reason `api` and `baseUrl` are:
851
- // it describes the PROVIDER's wire dialect, not the model. pi-ai infers
852
- // compat from the baseUrl and only recognises first-party hosts, so a
853
- // custom ref on a provider that pins compat (OpenGateway, Upstage) would
854
- // otherwise fall back to OpenAI-native defaults and send `store`, the
855
- // `developer` role, `strict` tool schemas and `max_completion_tokens` to
856
- // an endpoint that never accepts them. `thinkingLevelMap` is deliberately
857
- // NOT carried: it varies per model even within one provider, so copying
858
- // the template's would be a guess.
859
- ...(template.compat !== undefined ? { compat: template.compat } : {}),
860
- name: meta?.name ?? modelId,
861
- reasoning: meta?.reasoning ?? false,
862
- input: resolveCustomModelInput(meta?.input),
863
- contextWindow: meta?.contextWindow ?? template.contextWindow,
864
- maxTokens: meta?.maxTokens ?? template.maxTokens,
865
- cost: resolveCustomModelCost(meta?.cost),
880
+ ...(compat !== undefined ? { compat } : {}),
881
+ ...(catalogMetadata?.thinkingLevelMap !== undefined ? { thinkingLevelMap: catalogMetadata.thinkingLevelMap } : {}),
882
+ name: meta?.name ?? catalogMetadata?.name ?? modelId,
883
+ reasoning: meta?.reasoning ?? catalogMetadata?.reasoning ?? false,
884
+ input: resolveCustomModelInput(meta?.input, catalogMetadata?.input),
885
+ contextWindow: meta?.contextWindow ?? catalogMetadata?.contextWindow ?? template.contextWindow,
886
+ maxTokens: meta?.maxTokens ?? catalogMetadata?.maxTokens ?? template.maxTokens,
887
+ cost: resolveCustomModelCost(meta?.cost, catalogMetadata?.cost),
866
888
  }
867
889
  }
868
890
 
869
- function resolveCustomModelInput(input: readonly string[] | undefined): Model<KnownApi>['input'] {
870
- if (input === undefined) return ['text']
891
+ function findBuiltinModel(providerId: string, modelId: string): Model<KnownApi> | undefined {
892
+ const direct = getBuiltinModel(providerId as never, modelId as never) as Model<KnownApi> | undefined
893
+ if (direct !== undefined) return direct
894
+ const undatedId = modelId.replace(/-\d{8}$/, '')
895
+ return undatedId === modelId
896
+ ? undefined
897
+ : (getBuiltinModel(providerId as never, undatedId as never) as Model<KnownApi> | undefined)
898
+ }
899
+
900
+ function resolveCustomModelInput(
901
+ input: readonly string[] | undefined,
902
+ fallback: Model<KnownApi>['input'] | undefined,
903
+ ): Model<KnownApi>['input'] {
904
+ if (input === undefined) return fallback ?? ['text']
871
905
  const supported = input.filter(
872
906
  (value): value is Model<KnownApi>['input'][number] => value === 'text' || value === 'image',
873
907
  )
874
908
  return supported.length > 0 ? supported : ['text']
875
909
  }
876
910
 
877
- function resolveCustomModelCost(cost: CustomModelMeta['cost']): Model<KnownApi>['cost'] {
911
+ function resolveCustomModelCost(
912
+ cost: CustomModelMeta['cost'],
913
+ fallback: Model<KnownApi>['cost'] | undefined,
914
+ ): Model<KnownApi>['cost'] {
878
915
  return {
879
- input: cost?.input ?? 0,
880
- output: cost?.output ?? 0,
881
- cacheRead: cost?.cacheRead ?? 0,
882
- cacheWrite: cost?.cacheWrite ?? 0,
916
+ input: cost?.input ?? fallback?.input ?? 0,
917
+ output: cost?.output ?? fallback?.output ?? 0,
918
+ cacheRead: cost?.cacheRead ?? fallback?.cacheRead ?? 0,
919
+ cacheWrite: cost?.cacheWrite ?? fallback?.cacheWrite ?? 0,
883
920
  }
884
921
  }
885
922
 
@@ -1,5 +1,5 @@
1
- import type { ThinkingLevel } from '@mariozechner/pi-agent-core'
2
- import type { KnownApi, Model } from '@mariozechner/pi-ai'
1
+ import type { ThinkingLevel } from '@earendil-works/pi-agent-core'
2
+ import type { KnownApi, Model } from '@earendil-works/pi-ai'
3
3
 
4
4
  // Authentication mechanism a provider supports. `api-key` reads a static key
5
5
  // from .env (the original path); `oauth` runs a browser flow at init time and
@@ -29,16 +29,16 @@ type KnownProvider = {
29
29
  //
30
30
  // Adding a new model: append it to the matching provider's `models` map. Each
31
31
  // model object is the literal `Model<...>` that pi-ai consumes — keep it
32
- // faithful to https://github.com/mariozechner/pi-ai (the readme's "Custom
33
- // Models" section). `setRuntimeApiKey(provider, key)` keys off the `provider`
34
- // field, so it MUST match the outer provider id.
32
+ // faithful to pi-ai's "Custom Providers" README section
33
+ // (https://github.com/earendil-works/pi/tree/main/packages/ai#custom-providers).
34
+ // `setRuntimeApiKey(provider, key)` keys off the `provider` field, so it MUST
35
+ // match the outer provider id.
35
36
  //
36
37
  // Adding a new provider: add a top-level entry. Set `auth` to the supported
37
38
  // methods. For `api-key` providers, `apiKeyEnv` is the .env var typeclaw
38
39
  // writes at init and reads at boot (match the upstream provider's standard,
39
40
  // e.g. `OPENAI_API_KEY`). For `oauth` providers, `oauthProviderId` MUST match
40
- // a pi-ai OAuth provider id exactly, otherwise `authStorage.login()` will
41
- // throw "Unknown OAuth provider".
41
+ // a pi-ai OAuth provider id exactly, otherwise the provider login lookup fails.
42
42
  //
43
43
  // Granularity rule (split vs merge): a provider id is the runtime API surface,
44
44
  // not the brand. Different API call => different provider id; same API call =>
@@ -61,9 +61,14 @@ export const KNOWN_PROVIDERS = {
61
61
  auth: ['api-key'],
62
62
  apiKeyEnv: 'OPENAI_API_KEY',
63
63
  oauthProviderId: null,
64
- // Costs and context windows mirror models.dev as of 2026-05-10. When
65
- // refreshing, also rerun `scripts/generate-schema.ts` so typeclaw.schema.json
66
- // picks up new enum values.
64
+ // Costs and context windows mirror models.dev as of 2026-05-10; the GPT-6
65
+ // Sol/Luna records mirror OpenAI's model docs as of 2026-09-22.
66
+ // GPT-6 bills cache writes at 1.25x input; pi 0.87's Responses transport
67
+ // reads cache_write_tokens (openai-responses-shared.js), so that rate is
68
+ // applied. The >272K-input 2x/1.5x tier is not expressible in TypeClaw's
69
+ // flat cost shape, so these records use the standard rate. When
70
+ // refreshing, also rerun `scripts/generate-schema.ts` so
71
+ // typeclaw.schema.json picks up new enum values.
67
72
  models: {
68
73
  // Default. Cheapest tool-calling reasoning model in the family;
69
74
  // available on every paid OpenAI account tier.
@@ -115,6 +120,67 @@ export const KNOWN_PROVIDERS = {
115
120
  contextWindow: 1050000,
116
121
  maxTokens: 128000,
117
122
  },
123
+ // GPT-6 Sol and Luna use Responses because Chat Completions accepts tools
124
+ // only at effort `none`. The full map and compat are pi-ai 0.87.1's
125
+ // catalog values, preserving every documented effort through `max`.
126
+ 'gpt-6-sol': {
127
+ id: 'gpt-6-sol',
128
+ name: 'GPT-6 Sol',
129
+ api: 'openai-responses',
130
+ provider: 'openai',
131
+ baseUrl: 'https://api.openai.com/v1',
132
+ reasoning: true,
133
+ input: ['text', 'image'],
134
+ cost: { input: 2, output: 10, cacheRead: 0.2, cacheWrite: 2.5 },
135
+ contextWindow: 1050000,
136
+ maxTokens: 128000,
137
+ thinkingLevelMap: {
138
+ off: 'none',
139
+ minimal: null,
140
+ low: 'low',
141
+ medium: 'medium',
142
+ high: 'high',
143
+ xhigh: 'xhigh',
144
+ max: 'max',
145
+ },
146
+ compat: {
147
+ supportsStrictMode: true,
148
+ supportsOpenAIGrammarTools: true,
149
+ supportsAdditionalTools: true,
150
+ supportsToolSearch: true,
151
+ supportsMidConvoSystemMessages: true,
152
+ supportsExplicitPromptCacheMode: true,
153
+ },
154
+ },
155
+ 'gpt-6-luna': {
156
+ id: 'gpt-6-luna',
157
+ name: 'GPT-6 Luna',
158
+ api: 'openai-responses',
159
+ provider: 'openai',
160
+ baseUrl: 'https://api.openai.com/v1',
161
+ reasoning: true,
162
+ input: ['text', 'image'],
163
+ cost: { input: 0.1, output: 0.5, cacheRead: 0.01, cacheWrite: 0.125 },
164
+ contextWindow: 1050000,
165
+ maxTokens: 128000,
166
+ thinkingLevelMap: {
167
+ off: 'none',
168
+ minimal: null,
169
+ low: 'low',
170
+ medium: 'medium',
171
+ high: 'high',
172
+ xhigh: 'xhigh',
173
+ max: 'max',
174
+ },
175
+ compat: {
176
+ supportsStrictMode: true,
177
+ supportsOpenAIGrammarTools: true,
178
+ supportsAdditionalTools: true,
179
+ supportsToolSearch: true,
180
+ supportsMidConvoSystemMessages: true,
181
+ supportsExplicitPromptCacheMode: true,
182
+ },
183
+ },
118
184
  },
119
185
  },
120
186
  // ChatGPT Plus/Pro subscription via the OAuth Codex backend. No API key
@@ -177,6 +243,63 @@ export const KNOWN_PROVIDERS = {
177
243
  contextWindow: 272000,
178
244
  maxTokens: 128000,
179
245
  },
246
+ // GPT-6 Sol and Luna use the documented Codex backend limits. Their
247
+ // 0.87.1 maps preserve all valid efforts through `max`; Codex floors
248
+ // unsupported `minimal` at `low`.
249
+ 'gpt-6-sol': {
250
+ id: 'gpt-6-sol',
251
+ name: 'GPT-6 Sol',
252
+ api: 'openai-codex-responses',
253
+ provider: 'openai-codex',
254
+ baseUrl: 'https://chatgpt.com/backend-api',
255
+ reasoning: true,
256
+ input: ['text', 'image'],
257
+ cost: { input: 2, output: 10, cacheRead: 0.2, cacheWrite: 2.5 },
258
+ contextWindow: 272000,
259
+ maxTokens: 128000,
260
+ thinkingLevelMap: {
261
+ off: 'none',
262
+ minimal: 'low',
263
+ low: 'low',
264
+ medium: 'medium',
265
+ high: 'high',
266
+ xhigh: 'xhigh',
267
+ max: 'max',
268
+ },
269
+ compat: {
270
+ supportsOpenAIGrammarTools: true,
271
+ supportsAdditionalTools: true,
272
+ supportsToolSearch: true,
273
+ supportsMidConvoSystemMessages: true,
274
+ },
275
+ },
276
+ 'gpt-6-luna': {
277
+ id: 'gpt-6-luna',
278
+ name: 'GPT-6 Luna',
279
+ api: 'openai-codex-responses',
280
+ provider: 'openai-codex',
281
+ baseUrl: 'https://chatgpt.com/backend-api',
282
+ reasoning: true,
283
+ input: ['text', 'image'],
284
+ cost: { input: 0.1, output: 0.5, cacheRead: 0.01, cacheWrite: 0.125 },
285
+ contextWindow: 272000,
286
+ maxTokens: 128000,
287
+ thinkingLevelMap: {
288
+ off: 'none',
289
+ minimal: 'low',
290
+ low: 'low',
291
+ medium: 'medium',
292
+ high: 'high',
293
+ xhigh: 'xhigh',
294
+ max: 'max',
295
+ },
296
+ compat: {
297
+ supportsOpenAIGrammarTools: true,
298
+ supportsAdditionalTools: true,
299
+ supportsToolSearch: true,
300
+ supportsMidConvoSystemMessages: true,
301
+ },
302
+ },
180
303
  },
181
304
  },
182
305
  // Anthropic Claude — both the Anthropic Console API (ANTHROPIC_API_KEY)
@@ -215,7 +338,8 @@ export const KNOWN_PROVIDERS = {
215
338
  // not the recommended path. Claude Mythos 5 (Fable 5's classifier-free
216
339
  // sibling, limited availability via Project Glasswing) is intentionally
217
340
  // NOT listed — access is gated per-org and a registry entry would fail for
218
- // everyone else.
341
+ // everyone else. Opus 5.5 (Sep 22 2026) was added on its own; Claude Opus 5
342
+ // and Fable 5.1 are not registered yet.
219
343
  //
220
344
  // ID semantics differ across the lineup and matter for forward-compat:
221
345
  // - `claude-haiku-4-5` is a 4.5-generation CONVENIENCE ALIAS that
@@ -238,8 +362,8 @@ export const KNOWN_PROVIDERS = {
238
362
  // vs Opus 4.6, but total cost on identical workloads can rise meaningfully.
239
363
  // - 1M token context window (vs 200k on Haiku) and 128k max output (vs
240
364
  // 64k on Sonnet/Haiku). 1M context is at standard pricing — no surcharge.
241
- // - New `xhigh` effort level between `high` and `max` (pi-ai 0.67.x may
242
- // not surface this knob yet; check before relying on it).
365
+ // - `xhigh` effort level between `high` and `max`; each record's
366
+ // `thinkingLevelMap` declares whether the model exposes it.
243
367
  //
244
368
  // Pricing mirrors Anthropic's official table as of 2026-05; cacheWrite is
245
369
  // the 5m-TTL rate (1.25x input). 1h TTL is ~2x input (not modeled here —
@@ -264,6 +388,11 @@ export const KNOWN_PROVIDERS = {
264
388
  contextWindow: 200000,
265
389
  maxTokens: 64000,
266
390
  },
391
+ // pi-ai 0.73 inferred adaptive thinking from the 4.6/4.7 ids; 0.87 reads
392
+ // only `compat.forceAdaptiveThinking` (anthropic-messages.js). Without
393
+ // these catalog fields Sonnet 4.6 and Opus 4.7 fall back to budget
394
+ // thinking, which Anthropic deprecates on 4.6 and rejects with a 400 on
395
+ // 4.7+ (platform.claude.com/docs/en/build-with-claude/extended-thinking).
267
396
  'claude-sonnet-4-6': {
268
397
  id: 'claude-sonnet-4-6',
269
398
  name: 'Claude Sonnet 4.6',
@@ -275,6 +404,8 @@ export const KNOWN_PROVIDERS = {
275
404
  cost: { input: 3, output: 15, cacheRead: 0.3, cacheWrite: 3.75 },
276
405
  contextWindow: 1000000,
277
406
  maxTokens: 64000,
407
+ thinkingLevelMap: { max: 'max' },
408
+ compat: { forceAdaptiveThinking: true, supportsStrictTools: true },
278
409
  },
279
410
  // Sonnet 5 (Jul 1 2026) is the drop-in successor to Sonnet 4.6 with a
280
411
  // caveat set that affects consumers of this record:
@@ -282,17 +413,12 @@ export const KNOWN_PROVIDERS = {
282
413
  // Per-token price is unchanged, so equivalent requests cost more.
283
414
  // - Adaptive thinking only: manual extended thinking
284
415
  // (`thinking: {type: "enabled"}` with `budget_tokens`) returns a
285
- // 400. The pinned pi-ai 0.73.x DOES send that payload for this id
286
- // (its supportsAdaptiveThinking() only matches 4.6-generation ids,
287
- // and thinking defaults to "medium"), so registering this record
288
- // with `reasoning: true` depends on the rewrite shim in
289
- // src/agent/adaptive-thinking-compat.ts. Don't wire a
290
- // thinking-budget knob to this id.
416
+ // 400. `compat.forceAdaptiveThinking` makes pi-ai's Anthropic
417
+ // transport send adaptive thinking on every path, compaction included.
291
418
  // - Cost encodes the STANDARD rate (in effect Sep 1 2026+).
292
- // Introductory pricing ($2/$10, cacheRead 0.2, cacheWrite 2.5) runs
293
- // through Aug 31 2026, so `typeclaw usage` over-reports Sonnet 5
294
- // spend until then. Chosen so the record doesn't silently go stale
295
- // two months after landing.
419
+ // Introductory pricing ($2/$10, cacheRead 0.2, cacheWrite 2.5) ran
420
+ // through Aug 31 2026. It was chosen so the record doesn't silently
421
+ // go stale two months after landing.
296
422
  'claude-sonnet-5': {
297
423
  id: 'claude-sonnet-5',
298
424
  name: 'Claude Sonnet 5',
@@ -304,6 +430,8 @@ export const KNOWN_PROVIDERS = {
304
430
  cost: { input: 3, output: 15, cacheRead: 0.3, cacheWrite: 3.75 },
305
431
  contextWindow: 1000000,
306
432
  maxTokens: 128000,
433
+ thinkingLevelMap: { xhigh: 'xhigh', max: 'max' },
434
+ compat: { forceAdaptiveThinking: true, supportsStrictTools: true },
307
435
  },
308
436
  'claude-opus-4-7': {
309
437
  id: 'claude-opus-4-7',
@@ -316,7 +444,12 @@ export const KNOWN_PROVIDERS = {
316
444
  cost: { input: 5, output: 25, cacheRead: 0.5, cacheWrite: 6.25 },
317
445
  contextWindow: 1000000,
318
446
  maxTokens: 128000,
447
+ thinkingLevelMap: { xhigh: 'xhigh', max: 'max' },
448
+ compat: { forceAdaptiveThinking: true, supportsTemperature: false, supportsStrictTools: true },
319
449
  },
450
+ // Opus 4.8 was never in pi 0.73's adaptive id list, so it already got
451
+ // budget thinking (a 400 on 4.7+) before this migration. The catalog
452
+ // compat fixes it the same way.
320
453
  'claude-opus-4-8': {
321
454
  id: 'claude-opus-4-8',
322
455
  name: 'Claude Opus 4.8',
@@ -328,15 +461,62 @@ export const KNOWN_PROVIDERS = {
328
461
  cost: { input: 5, output: 25, cacheRead: 0.5, cacheWrite: 6.25 },
329
462
  contextWindow: 1000000,
330
463
  maxTokens: 128000,
464
+ thinkingLevelMap: { xhigh: 'xhigh', max: 'max' },
465
+ compat: {
466
+ supportsMidConvoSystemMessages: true,
467
+ supportsMidConvoToolChanges: true,
468
+ forceAdaptiveThinking: true,
469
+ supportsTemperature: false,
470
+ supportsStrictTools: true,
471
+ },
472
+ },
473
+ // Opus 5.5 (Sep 22 2026) keeps adaptive thinking permanently on: both
474
+ // manual and disabled thinking return 400, which `forceAdaptiveThinking`
475
+ // plus `off`/`minimal: null` rule out. `supportsMidConvoEffort` routes the
476
+ // thinking level through the mid-conversation output-config control and
477
+ // sends `thinking-binding-controls-2026-08-01` with `drop_block`. Without
478
+ // that, a replayed thinking block whose prefix changed (for example after
479
+ // compaction) returns 400 on accounts created on or after 2026-08-31.
480
+ // Forced tool use is unsupported; typeclaw never sets toolChoice.
481
+ 'claude-opus-5-5': {
482
+ id: 'claude-opus-5-5',
483
+ name: 'Claude Opus 5.5',
484
+ api: 'anthropic-messages',
485
+ provider: 'anthropic',
486
+ baseUrl: 'https://api.anthropic.com',
487
+ reasoning: true,
488
+ input: ['text', 'image'],
489
+ cost: { input: 4, output: 20, cacheRead: 0.2, cacheWrite: 5 },
490
+ contextWindow: 1000000,
491
+ maxTokens: 128000,
492
+ thinkingLevelMap: {
493
+ off: null,
494
+ minimal: null,
495
+ low: 'low',
496
+ medium: 'medium',
497
+ high: 'high',
498
+ xhigh: 'xhigh',
499
+ max: 'max',
500
+ },
501
+ compat: {
502
+ supportsMidConvoEffort: true,
503
+ supportsMidConvoSystemMessages: true,
504
+ supportsMidConvoToolChanges: true,
505
+ forceAdaptiveThinking: true,
506
+ supportsTemperature: false,
507
+ supportsStrictTools: true,
508
+ },
331
509
  },
332
510
  // Fable 5 (Jun 2026) is a NEW TIER above Opus — Anthropic's most
333
511
  // capable widely released model, aimed at long-horizon agentic work.
334
512
  // Ships the 5-generation tokenizer: ~1.3x token counts for the same
335
513
  // text vs pre-5 models, so equivalent requests cost more than the
336
514
  // per-token rates alone suggest. Adaptive thinking only, same as
337
- // Sonnet 5 above: `reasoning: true` here depends on the rewrite shim
338
- // in src/agent/adaptive-thinking-compat.ts (pinned pi-ai 0.73.x would
339
- // otherwise send budget-based `thinking`, a hard 400 on this id).
515
+ // Sonnet 5 above, via `compat.forceAdaptiveThinking`. Upstream's catalog
516
+ // also sets `allowedFallbackModels` (Anthropic server-side fallback to
517
+ // Opus 4.8 / Opus 5). That is deliberately NOT adopted: pi would send
518
+ // `fallbacks`, and a refused request would silently be served, and
519
+ // billed, by a different model than the one the operator configured.
340
520
  'claude-fable-5': {
341
521
  id: 'claude-fable-5',
342
522
  name: 'Claude Fable 5',
@@ -348,6 +528,13 @@ export const KNOWN_PROVIDERS = {
348
528
  cost: { input: 10, output: 50, cacheRead: 1, cacheWrite: 12.5 },
349
529
  contextWindow: 1000000,
350
530
  maxTokens: 128000,
531
+ thinkingLevelMap: { off: null, xhigh: 'xhigh', max: 'max' },
532
+ compat: {
533
+ supportsMidConvoSystemMessages: true,
534
+ supportsMidConvoToolChanges: true,
535
+ forceAdaptiveThinking: true,
536
+ supportsStrictTools: true,
537
+ },
351
538
  },
352
539
  },
353
540
  },
@@ -521,24 +708,23 @@ export const KNOWN_PROVIDERS = {
521
708
  },
522
709
  },
523
710
  },
524
- // xAI (Grok). The native developer API at api.x.ai/v1 is OpenAI-compatible
525
- // (Bearer auth + /chat/completions shape), so models go through pi-ai's
526
- // `openai-completions` adapter with a custom baseUrl — same trick as
527
- // Fireworks and Z.AI. This is a DUAL-AUTH provider like `anthropic`:
528
- // * api-key — XAI_API_KEY (the standard xAI env var), a plain Bearer token.
529
- // * oauth — Grok subscription login via xAI's OIDC server (auth.x.ai),
530
- // authorization-code + PKCE. pi-ai ships no built-in xAI OAuth provider,
531
- // so `oauthProviderId: 'xai'` resolves to the custom provider registered
532
- // in src/secrets/oauth-xai.ts (registered from createSecretsStoreForAgent
533
- // so both init-login and runtime-refresh see it). The dual-auth runtime
534
- // rule in src/agent/auth.ts applies: an OAuth credential on disk wins over
535
- // XAI_API_KEY in .env — remove it (`typeclaw provider remove xai`) to fall
536
- // back to the key.
711
+ // xAI (Grok) is a dual-auth provider: api-key requests use XAI_API_KEY and
712
+ // OAuth requests use the xAI OIDC credential. Grok 4.7 and 4.3 use
713
+ // `openai-responses` with pi-ai 0.87.1's catalog metadata, as upstream's
714
+ // built-in xAI provider does: Responses carries encrypted reasoning and the
715
+ // documented effort values. The grok-4.20 snapshots and grok-build-0.1 are
716
+ // not in that catalog, so they stay on `openai-completions`, where pi-ai
717
+ // sends no xAI reasoning_effort. That is their 0.73 wire behavior, unchanged.
718
+ // The built-in pi-ai xAI provider owns its device-code OAuth flow, including
719
+ // refresh. An OAuth credential on disk takes precedence over XAI_API_KEY in
720
+ // .env; remove it (`typeclaw provider remove xai`) to use the key instead.
537
721
  //
538
722
  // Costs and context windows mirror docs.x.ai/developers/models and the raw
539
723
  // /v1/models price fields as of 2026-06-08 (xAI quotes prices in cents per
540
- // 100M tokens; e.g. grok-4.3 prompt 12500 = $1.25/1M). grok-4.3 is the
541
- // flagship default; grok-build-0.1 is the coding-tuned model. The
724
+ // 100M tokens; e.g. grok-4.3 prompt 12500 = $1.25/1M); grok-4.7 mirrors
725
+ // docs.x.ai/developers/grok-4-7 and /pricing as of 2026-09-21. grok-4.7 is
726
+ // the flagship; grok-4.3 stays first as the template record for uncurated
727
+ // refs; grok-build-0.1 is the coding-tuned model. The
542
728
  // grok-4.20-0309 snapshots are pinned weights for reproducible runs.
543
729
  //
544
730
  // The earlier grok-4 / grok-4-fast / grok-code-fast-1 ids were RETIRED on
@@ -546,10 +732,10 @@ export const KNOWN_PROVIDERS = {
546
732
  // grok-4.3 / grok-build-0.1 rates, so they are intentionally NOT listed.
547
733
  //
548
734
  // cacheWrite is 0: xAI publishes no cache-write price (caching is implicit,
549
- // billed only at the cacheRead rate). Models 1-4 also carry a long-context
550
- // tier (2x rates above a 200k-token request); pi-ai's Model shape can't
551
- // express tiered pricing, so the standard rate is used and the breakpoint is
552
- // noted here. When refreshing, rerun `scripts/generate-schema.ts`.
735
+ // billed only at the cacheRead rate). Every model here also carries a
736
+ // long-context tier (2x rates above a 200k-token request); the flat cost
737
+ // shape can't express tiered pricing, so the standard rate is used and the
738
+ // breakpoint is noted here. When refreshing, rerun `scripts/generate-schema.ts`.
553
739
  xai: {
554
740
  id: 'xai',
555
741
  name: 'xAI (Grok)',
@@ -558,17 +744,56 @@ export const KNOWN_PROVIDERS = {
558
744
  apiKeyEnv: 'XAI_API_KEY',
559
745
  oauthProviderId: 'xai',
560
746
  models: {
747
+ // pi-ai 0.87.1's xAI catalog caps Grok 4.3 at 30K and maps its efforts;
748
+ // `minimal` is not an xAI effort, so it clamps to `low`. The current
749
+ // transport sends model.maxTokens by default, so keep that vendor-safe cap.
561
750
  'grok-4.3': {
562
751
  id: 'grok-4.3',
563
752
  name: 'Grok 4.3',
564
- api: 'openai-completions',
753
+ api: 'openai-responses',
565
754
  provider: 'xai',
566
755
  baseUrl: 'https://api.x.ai/v1',
567
756
  reasoning: true,
568
757
  input: ['text', 'image'],
569
758
  cost: { input: 1.25, output: 2.5, cacheRead: 0.2, cacheWrite: 0 },
570
759
  contextWindow: 1000000,
571
- maxTokens: 64000,
760
+ maxTokens: 30000,
761
+ thinkingLevelMap: {
762
+ off: 'none',
763
+ minimal: null,
764
+ low: 'low',
765
+ medium: 'medium',
766
+ high: 'high',
767
+ xhigh: null,
768
+ max: null,
769
+ },
770
+ compat: { supportsLongCacheRetention: false },
771
+ },
772
+ // Responses is required for Grok 4.7's encrypted reasoning and maps
773
+ // the documented low/medium/high/xhigh effort values on pi-ai 0.87.1.
774
+ 'grok-4.7': {
775
+ id: 'grok-4.7',
776
+ name: 'Grok 4.7',
777
+ api: 'openai-responses',
778
+ provider: 'xai',
779
+ baseUrl: 'https://api.x.ai/v1',
780
+ reasoning: true,
781
+ input: ['text', 'image'],
782
+ cost: { input: 2, output: 6, cacheRead: 0.5, cacheWrite: 0 },
783
+ // xAI documents no text-output ceiling. Use the 500K context window;
784
+ // pi-ai clamps it to remaining context before the Responses request.
785
+ contextWindow: 500000,
786
+ maxTokens: 500000,
787
+ thinkingLevelMap: {
788
+ off: null,
789
+ minimal: null,
790
+ low: 'low',
791
+ medium: 'medium',
792
+ high: 'high',
793
+ xhigh: 'xhigh',
794
+ max: null,
795
+ },
796
+ compat: { supportsLongCacheRetention: false },
572
797
  },
573
798
  'grok-4.20-0309-reasoning': {
574
799
  id: 'grok-4.20-0309-reasoning',