typeclaw 0.45.1 → 0.46.1

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 (163) hide show
  1. package/README.md +1 -1
  2. package/package.json +3 -2
  3. package/src/agent/git-nudge.ts +2 -1
  4. package/src/agent/index.ts +44 -30
  5. package/src/agent/live-subagents.ts +18 -0
  6. package/src/agent/multimodal/index.ts +1 -1
  7. package/src/agent/multimodal/look-at.ts +78 -44
  8. package/src/agent/multimodal/looker.ts +161 -39
  9. package/src/agent/network/response-body.ts +26 -0
  10. package/src/agent/network/safe-http.ts +207 -0
  11. package/src/agent/plugin-tools.ts +377 -157
  12. package/src/agent/provider-error.ts +52 -1
  13. package/src/agent/restart/index.ts +61 -40
  14. package/src/agent/restart-handoff/index.ts +73 -4
  15. package/src/agent/reviewer-bash-policy.ts +42 -1
  16. package/src/agent/session-origin.ts +2 -0
  17. package/src/agent/subagent-drain.ts +117 -7
  18. package/src/agent/subagents.ts +49 -16
  19. package/src/agent/throttle-circuit.ts +25 -5
  20. package/src/agent/tool-error-remediation.ts +72 -0
  21. package/src/agent/tool-file-safety.ts +1310 -0
  22. package/src/agent/tools/channel-fetch-attachment.ts +10 -3
  23. package/src/agent/tools/ddg.ts +16 -2
  24. package/src/agent/tools/post-github-review.ts +199 -0
  25. package/src/agent/tools/spawn-subagent.ts +21 -18
  26. package/src/agent/tools/webfetch/fetch.ts +163 -183
  27. package/src/agent/tools/webfetch/tool.ts +2 -3
  28. package/src/agent/tools/websearch.ts +23 -2
  29. package/src/agent/tools-without-local-file-operands.ts +30 -0
  30. package/src/agent/turn-runner.ts +86 -6
  31. package/src/bundled-plugins/backup/README.md +23 -10
  32. package/src/bundled-plugins/backup/git-auth.ts +6 -4
  33. package/src/bundled-plugins/backup/index.ts +85 -44
  34. package/src/bundled-plugins/backup/runner.ts +85 -1
  35. package/src/bundled-plugins/doc-render/render.ts +93 -12
  36. package/src/bundled-plugins/doc-render/skills/typeclaw-render-pdf/SKILL.md +13 -13
  37. package/src/bundled-plugins/github-cli-auth/effective-approval.ts +16 -6
  38. package/src/bundled-plugins/github-cli-auth/gh-command.ts +555 -15
  39. package/src/bundled-plugins/github-cli-auth/git-askpass.ts +74 -26
  40. package/src/bundled-plugins/github-cli-auth/git-command.ts +224 -36
  41. package/src/bundled-plugins/github-cli-auth/graphql-auth-nudge.ts +9 -9
  42. package/src/bundled-plugins/github-cli-auth/index.ts +207 -132
  43. package/src/bundled-plugins/github-cli-auth/review-checkout.ts +138 -0
  44. package/src/bundled-plugins/github-cli-auth/token-class.ts +4 -6
  45. package/src/bundled-plugins/guard/policies/uncommitted-changes.ts +2 -1
  46. package/src/bundled-plugins/memory/README.md +32 -11
  47. package/src/bundled-plugins/memory/append-tool.ts +15 -8
  48. package/src/bundled-plugins/memory/citations.ts +22 -9
  49. package/src/bundled-plugins/memory/dreaming.ts +13 -8
  50. package/src/bundled-plugins/memory/find-entry-tool.ts +4 -0
  51. package/src/bundled-plugins/memory/index.ts +0 -4
  52. package/src/bundled-plugins/memory/load-memory.ts +8 -3
  53. package/src/bundled-plugins/memory/provenance-index.ts +717 -0
  54. package/src/bundled-plugins/memory/provenance-sanitize.ts +40 -0
  55. package/src/bundled-plugins/memory/references/store-reference-tool.ts +4 -0
  56. package/src/bundled-plugins/memory/search-tool.ts +163 -60
  57. package/src/bundled-plugins/memory/stream-events.ts +2 -0
  58. package/src/bundled-plugins/memory/vector/embed-threads.ts +36 -0
  59. package/src/bundled-plugins/memory/vector/embedder.ts +19 -1
  60. package/src/bundled-plugins/memory/vector/hybrid.ts +126 -13
  61. package/src/bundled-plugins/researcher/write-report.ts +8 -5
  62. package/src/bundled-plugins/reviewer/index.ts +2 -2
  63. package/src/bundled-plugins/reviewer/reviewer.ts +10 -3
  64. package/src/bundled-plugins/reviewer/skills/code-review.ts +19 -9
  65. package/src/bundled-plugins/scout/scout.ts +8 -0
  66. package/src/bundled-plugins/security/index.ts +4 -4
  67. package/src/bundled-plugins/security/policies/outbound-secret-scan.ts +1 -0
  68. package/src/bundled-plugins/security/policies/private-surface-read.ts +787 -36
  69. package/src/bundled-plugins/security/policies/secret-exfil-read.ts +1 -0
  70. package/src/bundled-plugins/security/policies/ssrf.ts +147 -42
  71. package/src/channels/adapters/discord-bot-channel-resolver.ts +26 -14
  72. package/src/channels/adapters/discord-bot-thread-room.ts +44 -12
  73. package/src/channels/adapters/discord-bot.ts +66 -6
  74. package/src/channels/adapters/discord-channel-resolver.ts +91 -23
  75. package/src/channels/adapters/discord-id.ts +4 -0
  76. package/src/channels/adapters/discord-resolver-cache.ts +41 -0
  77. package/src/channels/adapters/discord.ts +57 -7
  78. package/src/channels/adapters/github/auth-app.ts +41 -12
  79. package/src/channels/adapters/github/inbound.ts +11 -0
  80. package/src/channels/adapters/github/index.ts +71 -65
  81. package/src/channels/adapters/github/reconcile-cooldown-store.ts +178 -0
  82. package/src/channels/adapters/github/reconcile-open-prs.ts +31 -0
  83. package/src/channels/adapters/github/review-submitter.ts +302 -0
  84. package/src/channels/adapters/kakaotalk-channel-resolver.ts +5 -3
  85. package/src/channels/adapters/kakaotalk-fetch-attachment.ts +8 -4
  86. package/src/channels/adapters/kakaotalk-typing.ts +17 -15
  87. package/src/channels/adapters/slack-attachment-download.ts +71 -0
  88. package/src/channels/adapters/slack-bot-edit.ts +85 -20
  89. package/src/channels/adapters/slack-bot.ts +26 -10
  90. package/src/channels/adapters/slack-classify.ts +21 -2
  91. package/src/channels/adapters/slack-format.ts +245 -0
  92. package/src/channels/adapters/slack.ts +59 -7
  93. package/src/channels/adapters/telegram-bot.ts +18 -5
  94. package/src/channels/adapters/webex-bot.ts +8 -3
  95. package/src/channels/adapters/webex.ts +8 -3
  96. package/src/channels/fetch-attachment.ts +43 -0
  97. package/src/{bundled-plugins/github-cli-auth/approve-idempotency.ts → channels/github-review-verdict-coordinator.ts} +25 -1
  98. package/src/channels/github-token-bridge.ts +12 -6
  99. package/src/channels/manager.ts +9 -0
  100. package/src/channels/router.ts +248 -6
  101. package/src/channels/types.ts +28 -1
  102. package/src/cli/channel.ts +1 -1
  103. package/src/cli/init.ts +1 -1
  104. package/src/cli/model.ts +57 -7
  105. package/src/compose/stop.ts +17 -5
  106. package/src/config/config.ts +6 -6
  107. package/src/config/models-mutation.ts +13 -1
  108. package/src/config/providers.ts +176 -0
  109. package/src/container/docker-app.ts +42 -13
  110. package/src/container/start.ts +62 -10
  111. package/src/cron/bridge.ts +9 -2
  112. package/src/doctor/checks.ts +8 -3
  113. package/src/doctor/commit.ts +2 -1
  114. package/src/doctor/file-ownership.ts +52 -0
  115. package/src/dreams/git.ts +2 -1
  116. package/src/git/bound-gc-config.ts +82 -0
  117. package/src/git/hookless.ts +5 -0
  118. package/src/git/reconcile-ignored.ts +18 -5
  119. package/src/git/system-commit.ts +12 -6
  120. package/src/hostd/spawn.ts +133 -47
  121. package/src/init/dockerfile.ts +99 -5
  122. package/src/init/index.ts +17 -5
  123. package/src/init/models-dev.ts +4 -0
  124. package/src/init/validate-api-key.ts +2 -0
  125. package/src/inspect/replay.ts +21 -9
  126. package/src/inspect/session-list.ts +71 -33
  127. package/src/mcp/tools.ts +17 -3
  128. package/src/network/internal-destinations.ts +267 -0
  129. package/src/permissions/builtins.ts +3 -1
  130. package/src/plugin/context.ts +2 -0
  131. package/src/plugin/index.ts +1 -0
  132. package/src/plugin/manager.ts +4 -0
  133. package/src/plugin/types.ts +22 -0
  134. package/src/run/index.ts +40 -0
  135. package/src/run/llm-fetch-observer.ts +41 -4
  136. package/src/sandbox/build.ts +37 -15
  137. package/src/sandbox/canonical-secrets.ts +18 -0
  138. package/src/sandbox/env-exposure.ts +83 -0
  139. package/src/sandbox/errors.ts +13 -6
  140. package/src/sandbox/hidden-paths.ts +102 -44
  141. package/src/sandbox/index.ts +22 -4
  142. package/src/sandbox/package-install.ts +3 -27
  143. package/src/sandbox/policy.ts +16 -28
  144. package/src/sandbox/privileged-runtime.ts +256 -0
  145. package/src/sandbox/session-tmp.ts +8 -2
  146. package/src/sandbox/writable-zones.ts +204 -140
  147. package/src/secrets/index.ts +8 -0
  148. package/src/secrets/refresh-provider-oauth.ts +128 -0
  149. package/src/server/command-runner.ts +48 -4
  150. package/src/server/index.ts +4 -0
  151. package/src/skills/typeclaw-channel-github/SKILL.md +49 -56
  152. package/src/skills/typeclaw-claude-code/SKILL.md +24 -60
  153. package/src/skills/typeclaw-claude-code/references/auth-flow.md +17 -158
  154. package/src/skills/typeclaw-codex-cli/SKILL.md +19 -49
  155. package/src/skills/typeclaw-codex-cli/references/auth-flow.md +17 -154
  156. package/src/skills/typeclaw-config/SKILL.md +27 -11
  157. package/src/skills/typeclaw-config/references/recommended-mounts.md +24 -24
  158. package/src/skills/typeclaw-github-contributing/SKILL.md +23 -26
  159. package/src/skills/typeclaw-memory/SKILL.md +9 -3
  160. package/src/skills/typeclaw-permissions/SKILL.md +36 -19
  161. package/src/skills/typeclaw-plugins/SKILL.md +37 -0
  162. package/src/usage/scan.ts +11 -2
  163. package/typeclaw.schema.json +25 -0
package/src/cli/model.ts CHANGED
@@ -15,6 +15,7 @@ import {
15
15
  } from '@/config/models-mutation'
16
16
  import {
17
17
  isKnownModelRef,
18
+ isModelRef,
18
19
  KNOWN_PROVIDERS,
19
20
  providerForModelRef,
20
21
  type KnownModelRef,
@@ -64,17 +65,19 @@ const setSub = defineCommand({
64
65
  },
65
66
  async run({ args }) {
66
67
  const cwd = ensureAgentDir()
67
- const profile = args.profile ?? (await pickProfileName())
68
- const picked = args.ref !== undefined ? await resolveExplicitRef(args.ref) : await pickModelRef(cwd)
68
+ // `model set <ref>` shorthand targets the `default` profile; a shorthand ref
69
+ // is resolved as an explicit ref (so its errors surface via resolvePickedRef's
70
+ // exit-1 path), and a bare/named-profile invocation falls back to the picker.
71
+ const shorthandRef = resolveShorthandRef(args.profile, args.ref)
72
+ const profile = shorthandRef !== undefined ? 'default' : (args.profile ?? (await pickProfileName()))
73
+ const picked = await resolvePickedRef(shorthandRef ?? args.ref, cwd)
69
74
 
70
75
  intro(`Setting model profile: ${profile} → ${picked.ref}`)
71
76
 
72
77
  // Gather every interactive/flag input BEFORE any write, so cancelling a
73
78
  // later prompt (e.g. the thinking-level select) aborts the whole command
74
- // without having already mutated typeclaw.json. Non-interactive (`--thinking`)
75
- // resolves the level from the flag; an interactive run (no flag, no explicit
76
- // ref) offers the prompt; explicit-ref scripted calls leave the level alone.
77
- const interactive = args.ref === undefined && args.thinking === undefined
79
+ // without having already mutated typeclaw.json.
80
+ const interactive = shouldPromptThinkingLevel(shorthandRef, args.ref, args.thinking)
78
81
  let thinking: { level: ThinkingLevel | undefined } | undefined
79
82
  if (args.thinking !== undefined) {
80
83
  const parsed = parseThinkingArg(args.thinking)
@@ -173,7 +176,7 @@ const addSub = defineCommand({
173
176
  },
174
177
  async run({ args }) {
175
178
  const cwd = ensureAgentDir()
176
- const picked = args.ref !== undefined ? await resolveExplicitRef(args.ref) : await pickModelRef(cwd)
179
+ const picked = await resolvePickedRef(args.ref, cwd)
177
180
 
178
181
  intro(`Adding model profile: ${args.profile} → ${picked.ref}`)
179
182
 
@@ -425,6 +428,30 @@ async function pickModelRef(cwd: string): Promise<PickedModelRef> {
425
428
  }
426
429
  }
427
430
 
431
+ // One-positional shorthand for `set`: `typeclaw model set <ref>` targets the
432
+ // `default` profile without repeating its name. It's shorthand ONLY when a
433
+ // single positional was given (no `<ref>` arg) and that positional parses as a
434
+ // model ref — so `model set fast` (a NAMED profile, not a ref) is NOT shorthand
435
+ // and still selects the `fast` profile interactively. Returns the ref when the
436
+ // invocation is shorthand, else undefined.
437
+ export function resolveShorthandRef(profile: string | undefined, ref: string | undefined): string | undefined {
438
+ return ref === undefined && profile !== undefined && isModelRef(profile) ? profile : undefined
439
+ }
440
+
441
+ // Whether `set` should OFFER the interactive thinking-level prompt. It should
442
+ // only when the ref itself was chosen interactively — i.e. no ref came from the
443
+ // command line (neither the explicit `<ref>` arg nor the shorthand) and no
444
+ // `--thinking` flag pinned the level. A named profile with no ref (e.g.
445
+ // `model set fast`) picks its ref interactively, so it MUST still prompt; keying
446
+ // this on `args.profile` instead of `shorthandRef` would wrongly suppress it.
447
+ export function shouldPromptThinkingLevel(
448
+ shorthandRef: string | undefined,
449
+ ref: string | undefined,
450
+ thinking: string | undefined,
451
+ ): boolean {
452
+ return shorthandRef === undefined && ref === undefined && thinking === undefined
453
+ }
454
+
428
455
  // Non-interactive `<ref>` path. Curated refs resolve from KNOWN_PROVIDERS, so
429
456
  // they need no metadata. Non-curated refs are looked up in the live catalog so
430
457
  // `customModels[ref]` carries the same metadata the interactive picker would
@@ -435,6 +462,14 @@ export async function resolveExplicitRef(
435
462
  loadCatalog: () => Promise<{ options: ModelOption[] }> = fetchModelOptions,
436
463
  ): Promise<PickedModelRef> {
437
464
  if (isKnownModelRef(ref)) return { ref }
465
+ // Intentionally NOT rejecting refs that miss our shipped registry — not even
466
+ // for a closed-set provider like openai-codex. The registry is a snapshot, not
467
+ // an authoritative catalog: OpenAI ships new Codex models (e.g. the gpt-5.6
468
+ // line) before we can update it, and a definite "this model doesn't exist" is
469
+ // only knowable from the backend's own 400, which the runtime path now
470
+ // classifies (see provider-error.ts). Blocking here would instead stop users
471
+ // from selecting a real, newly-shipped model. So an unknown closed-provider ref
472
+ // takes the same forward-compatible warning path as any other non-curated ref.
438
473
  const { options } = await loadCatalog()
439
474
  const option = options.find((candidate) => candidate.ref === ref)
440
475
  if (option === undefined) {
@@ -448,6 +483,21 @@ export async function resolveExplicitRef(
448
483
  return { ref, ...(meta !== undefined ? { meta } : {}) }
449
484
  }
450
485
 
486
+ // Resolve the model ref for `set`/`add`: an explicit `<ref>` arg is resolved
487
+ // (and enriched with catalog metadata) by `resolveExplicitRef`, while a bare
488
+ // invocation opens the interactive picker. Any resolution error surfaces via the
489
+ // standard CLI error line + non-zero exit instead of an unhandled-rejection
490
+ // stack trace. (Ref *shape*/support is validated downstream by set/addProfile.)
491
+ async function resolvePickedRef(ref: string | undefined, cwd: string): Promise<PickedModelRef> {
492
+ if (ref === undefined) return pickModelRef(cwd)
493
+ try {
494
+ return await resolveExplicitRef(ref)
495
+ } catch (e) {
496
+ console.error(errorLine(e instanceof Error ? e.message : String(e)))
497
+ process.exit(1)
498
+ }
499
+ }
500
+
451
501
  export type { PickedModelRef }
452
502
 
453
503
  async function listCredentialedModelOptions(refs: KnownModelRef[]): Promise<ModelOption[]> {
@@ -1,4 +1,4 @@
1
- import { resolveController, type StopResult } from '@/container'
1
+ import { type Controller, resolveController, type StopResult } from '@/container'
2
2
 
3
3
  import { discoverAgents, type AgentEntry } from './discover'
4
4
  import type { AgentResult } from './start'
@@ -14,17 +14,29 @@ export type ComposeStopOptions = {
14
14
  onProgress?: (event: ComposeStopEvent) => void
15
15
  }
16
16
 
17
+ // Injectable so tests drive orchestration without real Docker. Note the
18
+ // deliberate absence of the validateConfig guard that composeStart/Restart
19
+ // have: container identity derives from cwd, not a valid typeclaw.json, so a
20
+ // corrupted config must never block cleanup or a broken config strands a
21
+ // container that can only be removed by hand.
22
+ export type ComposeStopDeps = {
23
+ stop?: Controller['stop']
24
+ }
25
+
17
26
  export type ComposeStopResult = {
18
27
  agents: AgentEntry[]
19
28
  results: AgentResult<StopSuccess>[]
20
29
  }
21
30
 
22
- export async function composeStop({ rootCwd, onProgress }: ComposeStopOptions): Promise<ComposeStopResult> {
31
+ export async function composeStop(
32
+ { rootCwd, onProgress }: ComposeStopOptions,
33
+ { stop = (options) => resolveController().stop(options) }: ComposeStopDeps = {},
34
+ ): Promise<ComposeStopResult> {
23
35
  const agents = discoverAgents(rootCwd)
24
36
  const results = await Promise.all(
25
37
  agents.map(async (agent): Promise<AgentResult<StopSuccess>> => {
26
38
  onProgress?.({ kind: 'agent-start', name: agent.name })
27
- const result = await runOne(agent.name, agent.cwd)
39
+ const result = await runOne(agent.name, agent.cwd, stop)
28
40
  onProgress?.({ kind: 'agent-done', name: agent.name, result })
29
41
  return result
30
42
  }),
@@ -32,9 +44,9 @@ export async function composeStop({ rootCwd, onProgress }: ComposeStopOptions):
32
44
  return { agents, results }
33
45
  }
34
46
 
35
- async function runOne(name: string, cwd: string): Promise<AgentResult<StopSuccess>> {
47
+ async function runOne(name: string, cwd: string, stop: Controller['stop']): Promise<AgentResult<StopSuccess>> {
36
48
  try {
37
- const data = await resolveController().stop({ cwd })
49
+ const data = await stop({ cwd })
38
50
  if (!data.ok) return { name, ok: false, reason: data.reason }
39
51
  return { name, ok: true, data }
40
52
  } catch (error) {
@@ -415,12 +415,12 @@ export const relativeAgentPathSchema = z
415
415
  //
416
416
  // `from` is the symlink LOCATION and is fully configurable: an absolute container
417
417
  // path (e.g. `/root/.metabase-cli`) or a `~/`-prefixed path expanded against the
418
- // stage's HOME. Two stages create it: the entrypoint shim creates it at the real
419
- // container HOME (/root) for trusted/owner roles whose bash runs UNSANDBOXED, and
420
- // the per-tool bwrap sandbox emits a `--symlink` at the sandbox HOME (/tmp) for
421
- // low-trust roles — because `$HOME` differs between the two stages, a `~/` from
422
- // resolves to a different absolute path in each, which is exactly what each
423
- // consumer needs. The entrypoint refuses to clobber an existing non-symlink.
418
+ // stage's HOME. Two layers create it: the entrypoint shim creates it at the real
419
+ // container HOME (/root) for runtime-owned processes, and the per-tool bwrap
420
+ // sandbox emits a `--symlink` at the model-facing HOME (/tmp) for every role.
421
+ // Because `$HOME` differs between the two layers, a `~/` from resolves to the
422
+ // appropriate absolute path for each consumer. The entrypoint refuses to
423
+ // clobber an existing non-symlink.
424
424
  //
425
425
  // `from` SECURITY: it must not contain a null byte, must not be the root `/`, and
426
426
  // must not point INTO /agent (a self-referential loop). Kernel/virtual paths
@@ -307,7 +307,19 @@ function writeModels(
307
307
  try {
308
308
  writeFileSync(path, `${JSON.stringify(parsed, null, 2)}\n`)
309
309
  } catch (error) {
310
- return { ok: false, reason: `Failed to write ${CONFIG_FILE}: ${(error as Error).message}` }
310
+ const code = error instanceof Error && 'code' in error ? error.code : undefined
311
+ if (code === 'EACCES' || code === 'EPERM') {
312
+ return {
313
+ ok: false,
314
+ reason:
315
+ `${CONFIG_FILE} is not writable by the current user. ` +
316
+ `Inspect ownership with \`ls -ln "${path}"\`. If it is owned by another user and this agent folder belongs to you, repair it with \`sudo chown "$(id -u):$(id -g)" "${path}"\`.`,
317
+ }
318
+ }
319
+ return {
320
+ ok: false,
321
+ reason: `Failed to write ${CONFIG_FILE}: ${error instanceof Error ? error.message : String(error)}`,
322
+ }
311
323
  }
312
324
  // Final schema-pass for parity with every other host-side mutation that runs
313
325
  // through validateConfig. Mount checks etc. should never fail here because
@@ -400,6 +400,7 @@ export const KNOWN_PROVIDERS = {
400
400
  provider: 'zai',
401
401
  baseUrl: 'https://api.z.ai/api/paas/v4',
402
402
  reasoning: true,
403
+ thinkingLevelMap: { off: null, minimal: 'minimal', low: 'low', medium: 'medium', high: 'high', xhigh: 'high' },
403
404
  input: ['text'],
404
405
  cost: { input: 0.2, output: 1.1, cacheRead: 0, cacheWrite: 0 },
405
406
  contextWindow: 128000,
@@ -412,6 +413,7 @@ export const KNOWN_PROVIDERS = {
412
413
  provider: 'zai',
413
414
  baseUrl: 'https://api.z.ai/api/paas/v4',
414
415
  reasoning: true,
416
+ thinkingLevelMap: { off: null, minimal: 'minimal', low: 'low', medium: 'medium', high: 'high', xhigh: 'high' },
415
417
  input: ['text'],
416
418
  cost: { input: 0.6, output: 2.2, cacheRead: 0, cacheWrite: 0 },
417
419
  contextWindow: 200000,
@@ -424,6 +426,7 @@ export const KNOWN_PROVIDERS = {
424
426
  provider: 'zai',
425
427
  baseUrl: 'https://api.z.ai/api/paas/v4',
426
428
  reasoning: true,
429
+ thinkingLevelMap: { off: null, minimal: 'minimal', low: 'low', medium: 'medium', high: 'high', xhigh: 'high' },
427
430
  input: ['text'],
428
431
  cost: { input: 0.6, output: 2.2, cacheRead: 0, cacheWrite: 0 },
429
432
  contextWindow: 200000,
@@ -455,6 +458,7 @@ export const KNOWN_PROVIDERS = {
455
458
  provider: 'zai-coding',
456
459
  baseUrl: 'https://api.z.ai/api/coding/paas/v4',
457
460
  reasoning: true,
461
+ thinkingLevelMap: { off: null, minimal: 'minimal', low: 'low', medium: 'medium', high: 'high', xhigh: 'high' },
458
462
  input: ['text'],
459
463
  cost: { input: 0.2, output: 1.1, cacheRead: 0, cacheWrite: 0 },
460
464
  contextWindow: 128000,
@@ -467,6 +471,7 @@ export const KNOWN_PROVIDERS = {
467
471
  provider: 'zai-coding',
468
472
  baseUrl: 'https://api.z.ai/api/coding/paas/v4',
469
473
  reasoning: true,
474
+ thinkingLevelMap: { off: null, minimal: 'minimal', low: 'low', medium: 'medium', high: 'high', xhigh: 'high' },
470
475
  input: ['text'],
471
476
  cost: { input: 0.6, output: 2.2, cacheRead: 0, cacheWrite: 0 },
472
477
  contextWindow: 200000,
@@ -482,6 +487,7 @@ export const KNOWN_PROVIDERS = {
482
487
  provider: 'zai-coding',
483
488
  baseUrl: 'https://api.z.ai/api/coding/paas/v4',
484
489
  reasoning: true,
490
+ thinkingLevelMap: { off: null, minimal: 'minimal', low: 'low', medium: 'medium', high: 'high', xhigh: 'high' },
485
491
  input: ['text'],
486
492
  cost: { input: 1.0, output: 3.2, cacheRead: 0, cacheWrite: 0 },
487
493
  contextWindow: 200000,
@@ -494,6 +500,7 @@ export const KNOWN_PROVIDERS = {
494
500
  provider: 'zai-coding',
495
501
  baseUrl: 'https://api.z.ai/api/coding/paas/v4',
496
502
  reasoning: true,
503
+ thinkingLevelMap: { off: null, minimal: 'minimal', low: 'low', medium: 'medium', high: 'high', xhigh: 'high' },
497
504
  input: ['text'],
498
505
  cost: { input: 1.2, output: 4.0, cacheRead: 0, cacheWrite: 0 },
499
506
  contextWindow: 200000,
@@ -506,6 +513,7 @@ export const KNOWN_PROVIDERS = {
506
513
  provider: 'zai-coding',
507
514
  baseUrl: 'https://api.z.ai/api/coding/paas/v4',
508
515
  reasoning: true,
516
+ thinkingLevelMap: { off: null, minimal: 'minimal', low: 'low', medium: 'medium', high: 'high', xhigh: 'high' },
509
517
  input: ['text'],
510
518
  cost: { input: 1.4, output: 4.4, cacheRead: 0, cacheWrite: 0 },
511
519
  contextWindow: 200000,
@@ -653,6 +661,7 @@ export const KNOWN_PROVIDERS = {
653
661
  provider: 'minimax',
654
662
  baseUrl: 'https://api.minimax.io/v1',
655
663
  reasoning: true,
664
+ thinkingLevelMap: { off: null, minimal: 'minimal', low: 'low', medium: 'medium', high: 'high', xhigh: 'high' },
656
665
  input: ['text'],
657
666
  cost: { input: 0.3, output: 1.2, cacheRead: 0.06, cacheWrite: 0.375 },
658
667
  contextWindow: 204800,
@@ -665,6 +674,7 @@ export const KNOWN_PROVIDERS = {
665
674
  provider: 'minimax',
666
675
  baseUrl: 'https://api.minimax.io/v1',
667
676
  reasoning: true,
677
+ thinkingLevelMap: { off: null, minimal: 'minimal', low: 'low', medium: 'medium', high: 'high', xhigh: 'high' },
668
678
  input: ['text'],
669
679
  cost: { input: 0.3, output: 1.2, cacheRead: 0.03, cacheWrite: 0.375 },
670
680
  contextWindow: 204800,
@@ -677,6 +687,7 @@ export const KNOWN_PROVIDERS = {
677
687
  provider: 'minimax',
678
688
  baseUrl: 'https://api.minimax.io/v1',
679
689
  reasoning: true,
690
+ thinkingLevelMap: { off: null, minimal: 'minimal', low: 'low', medium: 'medium', high: 'high', xhigh: 'high' },
680
691
  input: ['text'],
681
692
  cost: { input: 0.3, output: 1.2, cacheRead: 0.03, cacheWrite: 0.375 },
682
693
  contextWindow: 204800,
@@ -689,6 +700,7 @@ export const KNOWN_PROVIDERS = {
689
700
  provider: 'minimax',
690
701
  baseUrl: 'https://api.minimax.io/v1',
691
702
  reasoning: true,
703
+ thinkingLevelMap: { off: null, minimal: 'minimal', low: 'low', medium: 'medium', high: 'high', xhigh: 'high' },
692
704
  input: ['text'],
693
705
  cost: { input: 0.3, output: 1.2, cacheRead: 0.03, cacheWrite: 0.375 },
694
706
  contextWindow: 204800,
@@ -734,6 +746,7 @@ export const KNOWN_PROVIDERS = {
734
746
  provider: 'deepseek',
735
747
  baseUrl: 'https://api.deepseek.com',
736
748
  reasoning: true,
749
+ thinkingLevelMap: { off: null, minimal: 'minimal', low: 'low', medium: 'medium', high: 'high', xhigh: 'high' },
737
750
  input: ['text'],
738
751
  cost: { input: 0.14, output: 0.28, cacheRead: 0.0028, cacheWrite: 0 },
739
752
  contextWindow: 1000000,
@@ -746,6 +759,7 @@ export const KNOWN_PROVIDERS = {
746
759
  provider: 'deepseek',
747
760
  baseUrl: 'https://api.deepseek.com',
748
761
  reasoning: true,
762
+ thinkingLevelMap: { off: null, minimal: 'minimal', low: 'low', medium: 'medium', high: 'high', xhigh: 'high' },
749
763
  input: ['text'],
750
764
  cost: { input: 0.435, output: 0.87, cacheRead: 0.003625, cacheWrite: 0 },
751
765
  contextWindow: 1000000,
@@ -753,6 +767,163 @@ export const KNOWN_PROVIDERS = {
753
767
  },
754
768
  },
755
769
  },
770
+ // Upstage (Solar) — console.upstage.ai pay-as-you-go API. OpenAI-compatible
771
+ // (Bearer auth + /chat/completions shape), so models go through pi-ai's
772
+ // `openai-completions` adapter with a custom baseUrl — same trick as
773
+ // Fireworks, Z.AI, MiniMax, DeepSeek, and Moonshot. api-key only; Upstage
774
+ // ships no OAuth flow. Keys are prefixed `up_`.
775
+ //
776
+ // baseUrl is `https://api.upstage.ai/v1` (the OpenAI-style `/v1` convention,
777
+ // like OpenAI/xAI/Moonshot — NOT the bare Anthropic/DeepSeek form). The SDK
778
+ // appends `/chat/completions`; `validate-api-key.ts` probes `${baseUrl}/models`.
779
+ // Some older third-party integrations (LangChain community, VoltAgent) point
780
+ // at the legacy `https://api.upstage.ai/v1/solar` path — that is deprecated;
781
+ // the console, the OpenAI-SDK example, and the agent docs all use bare `/v1`.
782
+ //
783
+ // Model lineup spans two families on the same Console API + key:
784
+ // * Closed chat models from the official agent API reference
785
+ // (console.upstage.ai/api/docs/for-agents) as of 2026-03-23:
786
+ // solar-pro3 (102B MoE / 12B active, 128K, flagship), solar-pro2
787
+ // (31B, 65K), solar-mini (10.7B, 32K, cheap/fast).
788
+ // * The open-weight Solar Open family: solar-open2 (Solar Open 2), a 102B
789
+ // MoE / 12B active model with a 128K context. It launched on the Console
790
+ // API for the Solar Agent Partner program (Stage 1, from 2026-07-17) —
791
+ // newer than the public docs snapshot above, so it is not yet in the
792
+ // public model-alias table; the model id is per Upstage's partner
793
+ // onboarding notice (docs: console.upstage.ai/api/chat).
794
+ // Every model here supports OpenAI-style function calling (required for agent
795
+ // use) and is text-only (Upstage's chat API exposes no image input). The
796
+ // `syn-pro` synthetic-data model is intentionally omitted: it does NOT
797
+ // support function calling and is useless as an agent model. Aliases (not the
798
+ // dated `-260323` suffixes) are used so they auto-forward to the latest
799
+ // versioned release.
800
+ //
801
+ // Costs are USD per 1M tokens from upstage.ai/pricing/api (VAT-exclusive).
802
+ // solar-pro3/pro2 publish an "Input(Cached)" cache-read rate ($0.015); no
803
+ // cache-write surcharge is published, so cacheWrite is 0. solar-mini
804
+ // publishes a single flat $0.15 rate with no cache line, so cacheRead and
805
+ // cacheWrite are both 0 (no published discount). solar-open2 has no published
806
+ // price yet (partner-program access, rate-limited rather than billed), so all
807
+ // four cost fields are 0 until Upstage publishes a Solar Open rate card.
808
+ //
809
+ // `compat` pins pi-ai's openai-completions adapter to Upstage's DOCUMENTED
810
+ // request surface. pi-ai only auto-detects compat for a known set of baseUrls
811
+ // (Cerebras, xAI, DeepSeek, …); api.upstage.ai is not among them, so without
812
+ // this it would default to OpenAI-native fields Upstage does not document and
813
+ // could reject. Per the Upstage Console API reference
814
+ // (console.upstage.ai/api/docs/for-agents): messages use system/user/assistant
815
+ // roles only (no `developer` role), output length is `max_tokens` (not
816
+ // `max_completion_tokens`), and `store` is not a documented field — so
817
+ // supportsDeveloperRole/supportsStore are false and maxTokensField is
818
+ // `max_tokens`. `stream_options.include_usage` and the `strict` field on tool
819
+ // definitions are both undocumented, so supportsUsageInStreaming and
820
+ // supportsStrictMode are false (both conservative — pi-ai defaults them to
821
+ // true, and Upstage only documents `strict` inside response_format.json_schema,
822
+ // never on tool defs). `reasoning_effort` IS documented for solar-pro3/pro2
823
+ // (and the solar-open2 chat template), so supportsReasoningEffort stays true
824
+ // there; solar-mini ignores it, so it is false and reasoning is off.
825
+ //
826
+ // Upstage documents reasoning_effort values minimal/low/medium/high only. pi
827
+ // adds an `xhigh` level that typeclaw's attention escalation can select
828
+ // (src/agent/attention-escalation.ts), and pi-ai passes the pi level straight
829
+ // through as reasoning_effort when no map is set — which would send the
830
+ // unsupported `xhigh`. `thinkingLevelMap` clamps xhigh -> high (and maps off ->
831
+ // null so nothing is sent) on the reasoning models so every emitted
832
+ // reasoning_effort is a value Upstage accepts. solar-mini needs no map (it
833
+ // never sends reasoning_effort).
834
+ upstage: {
835
+ id: 'upstage',
836
+ name: 'Upstage (Solar)',
837
+ baseUrl: 'https://api.upstage.ai/v1',
838
+ auth: ['api-key'],
839
+ apiKeyEnv: 'UPSTAGE_API_KEY',
840
+ oauthProviderId: null,
841
+ models: {
842
+ 'solar-open2': {
843
+ id: 'solar-open2',
844
+ name: 'Solar Open 2',
845
+ api: 'openai-completions',
846
+ provider: 'upstage',
847
+ baseUrl: 'https://api.upstage.ai/v1',
848
+ reasoning: true,
849
+ thinkingLevelMap: { off: null, minimal: 'minimal', low: 'low', medium: 'medium', high: 'high', xhigh: 'high' },
850
+ input: ['text'],
851
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
852
+ contextWindow: 128000,
853
+ maxTokens: 32000,
854
+ compat: {
855
+ supportsStore: false,
856
+ supportsDeveloperRole: false,
857
+ supportsReasoningEffort: true,
858
+ supportsUsageInStreaming: false,
859
+ supportsStrictMode: false,
860
+ maxTokensField: 'max_tokens',
861
+ },
862
+ },
863
+ 'solar-pro3': {
864
+ id: 'solar-pro3',
865
+ name: 'Solar Pro 3',
866
+ api: 'openai-completions',
867
+ provider: 'upstage',
868
+ baseUrl: 'https://api.upstage.ai/v1',
869
+ reasoning: true,
870
+ thinkingLevelMap: { off: null, minimal: 'minimal', low: 'low', medium: 'medium', high: 'high', xhigh: 'high' },
871
+ input: ['text'],
872
+ cost: { input: 0.15, output: 0.6, cacheRead: 0.015, cacheWrite: 0 },
873
+ contextWindow: 128000,
874
+ maxTokens: 32000,
875
+ compat: {
876
+ supportsStore: false,
877
+ supportsDeveloperRole: false,
878
+ supportsReasoningEffort: true,
879
+ supportsUsageInStreaming: false,
880
+ supportsStrictMode: false,
881
+ maxTokensField: 'max_tokens',
882
+ },
883
+ },
884
+ 'solar-pro2': {
885
+ id: 'solar-pro2',
886
+ name: 'Solar Pro 2',
887
+ api: 'openai-completions',
888
+ provider: 'upstage',
889
+ baseUrl: 'https://api.upstage.ai/v1',
890
+ reasoning: true,
891
+ thinkingLevelMap: { off: null, minimal: 'minimal', low: 'low', medium: 'medium', high: 'high', xhigh: 'high' },
892
+ input: ['text'],
893
+ cost: { input: 0.15, output: 0.6, cacheRead: 0.015, cacheWrite: 0 },
894
+ contextWindow: 65000,
895
+ maxTokens: 16000,
896
+ compat: {
897
+ supportsStore: false,
898
+ supportsDeveloperRole: false,
899
+ supportsReasoningEffort: true,
900
+ supportsUsageInStreaming: false,
901
+ supportsStrictMode: false,
902
+ maxTokensField: 'max_tokens',
903
+ },
904
+ },
905
+ 'solar-mini': {
906
+ id: 'solar-mini',
907
+ name: 'Solar Mini',
908
+ api: 'openai-completions',
909
+ provider: 'upstage',
910
+ baseUrl: 'https://api.upstage.ai/v1',
911
+ reasoning: false,
912
+ input: ['text'],
913
+ cost: { input: 0.15, output: 0.15, cacheRead: 0, cacheWrite: 0 },
914
+ contextWindow: 32000,
915
+ maxTokens: 8000,
916
+ compat: {
917
+ supportsStore: false,
918
+ supportsDeveloperRole: false,
919
+ supportsReasoningEffort: false,
920
+ supportsUsageInStreaming: false,
921
+ supportsStrictMode: false,
922
+ maxTokensField: 'max_tokens',
923
+ },
924
+ },
925
+ },
926
+ },
756
927
  // Moonshot AI (Kimi) — Open Platform pay-as-you-go API. The platform exposes
757
928
  // an OpenAI-compatible surface at api.moonshot.ai/v1 (Bearer auth +
758
929
  // /chat/completions shape), so models go through pi-ai's `openai-completions`
@@ -938,6 +1109,11 @@ export const KNOWN_PROVIDER_VENDORS = {
938
1109
  name: 'DeepSeek',
939
1110
  providers: ['deepseek'],
940
1111
  },
1112
+ upstage: {
1113
+ id: 'upstage',
1114
+ name: 'Upstage (Solar)',
1115
+ providers: ['upstage'],
1116
+ },
941
1117
  moonshot: {
942
1118
  id: 'moonshot',
943
1119
  name: 'Moonshot (Kimi)',
@@ -1,18 +1,22 @@
1
1
  import { existsSync } from 'node:fs'
2
2
 
3
- import { getBun } from './shared'
3
+ import { getBun, sanitizeDockerStderr } from './shared'
4
4
  import type { DockerAvailability } from './shared'
5
5
 
6
6
  // Detection + friendly guidance for "Docker is not reachable".
7
7
  //
8
8
  // `checkDockerAvailable` (in ./shared) already tells us WHETHER docker works and
9
9
  // discriminates `binary-missing` (no `docker` on PATH) from `daemon-down` (CLI
10
- // present, daemon refused the connection — the common "Docker Desktop / OrbStack
11
- // installed but not started" case on macOS). What it does NOT do is tell the
12
- // user WHICH runtime to nudge. This module fills that gap: it classifies the
13
- // likely runtime and renders a short, copy-pasteable instruction instead of
14
- // leaking the raw daemon error (which on OrbStack embeds a per-user socket path
15
- // under the user's home dir — noise the user can't act on).
10
+ // present, the selected Docker endpoint refused the connection). That covers the
11
+ // common "Docker Desktop / OrbStack installed but not started" case on macOS —
12
+ // but `docker info` failing proves only that the CONFIGURED ENDPOINT is
13
+ // unreachable, NOT that the runtime process is stopped: a running OrbStack whose
14
+ // CLI is pointed at a stale `desktop-linux` context (or an SSH session missing
15
+ // the interactive shell's DOCKER_HOST) produces the exact same connection error.
16
+ // So this module must not assert the app is "not started" — it nudges the likely
17
+ // runtime to start AND surfaces the context/endpoint recovery path plus the raw
18
+ // (sanitized) Docker error, so a user who knows the runtime is already up isn't
19
+ // sent into a dead-end "start it" loop.
16
20
  //
17
21
  // Classification priority (most → least authoritative):
18
22
  // 1. The configured socket: `DOCKER_HOST` or the socket path inside the raw
@@ -121,8 +125,8 @@ export function detectInstalledDockerApps(probes: DockerAppProbes = {}): DockerA
121
125
  // Docker Desktop's GUI launcher (`Docker Desktop.exe`) across the MSI, 32-bit,
122
126
  // and per-user install layouts confirmed by the Docker Desktop installer and
123
127
  // PowerShell's own probing scripts. Probing the exe (not just `docker` on PATH)
124
- // is what lets us say "Docker Desktop is installed but not started" when the
125
- // daemon is down — a stale PATH can hide the CLI even when Desktop is present.
128
+ // is what lets us name Docker Desktop as the runtime to nudge when the daemon is
129
+ // unreachable — a stale PATH can hide the CLI even when Desktop is present.
126
130
  function windowsDockerDesktopInstalled(env: NodeJS.ProcessEnv, exists: (path: string) => boolean): boolean {
127
131
  const programFiles = env.ProgramW6432 ?? env.ProgramFiles ?? 'C:\\Program Files'
128
132
  const programFilesX86 = env['ProgramFiles(x86)'] ?? 'C:\\Program Files (x86)'
@@ -231,23 +235,48 @@ export function renderDockerUnavailableGuidance(
231
235
  return { summary: 'Docker is not installed.', lines }
232
236
  }
233
237
 
234
- // daemon-down
238
+ // daemon-down: the configured Docker endpoint refused the connection. We can
239
+ // nudge the likely runtime to start, but must NOT claim it's stopped — the
240
+ // same error fires when the runtime is up and the CLI is on the wrong context.
235
241
  const lines: string[] = []
236
242
  let summary: string
237
243
  if (nudge !== null) {
238
- summary = `Docker is not running. ${dockerAppLabel(nudge)} is installed but not started.`
244
+ const label = dockerAppLabel(nudge)
245
+ summary = `Docker daemon is not reachable. Start ${label}, or check its connection if it's already running.`
239
246
  lines.push(...startInstructions(nudge, platform))
240
247
  } else if (installed.length > 1) {
241
248
  const names = installed.map(dockerAppLabel).join(', ')
242
- summary = 'Docker is not running.'
249
+ summary = `Docker daemon is not reachable. Start ${names}, or check your docker connection if it's already running.`
243
250
  lines.push(`Detected: ${names}. Start whichever one you use, then retry.`)
244
251
  } else {
245
- summary = 'Docker is installed but the daemon is not reachable.'
252
+ summary =
253
+ "Docker daemon is not reachable. Start your Docker runtime, or check your docker connection if it's already running."
246
254
  lines.push(...genericStartInstructions(platform))
247
255
  }
248
256
 
257
+ lines.push('', ...alreadyRunningRecovery(availability.detail))
258
+
249
259
  if (retryHint) {
250
260
  lines.push('', retryHint)
251
261
  }
252
262
  return { summary, lines }
253
263
  }
264
+
265
+ // The recovery path for the case the start-instructions can't fix: the runtime
266
+ // is already running but `docker info` still fails because the CLI is pointed at
267
+ // an unreachable endpoint (stale `docker context`, a leftover `DOCKER_HOST`, or
268
+ // a non-interactive/SSH shell missing the interactive env). We surface the
269
+ // configuration knobs to check plus the sanitized Docker error so the endpoint
270
+ // stays visible instead of being hidden as "noise".
271
+ function alreadyRunningRecovery(detail: string): string[] {
272
+ const lines = [
273
+ 'If it is already running, your docker CLI may be pointed at the wrong endpoint',
274
+ '(common over SSH or in non-interactive shells).',
275
+ 'Check `docker context ls`, `DOCKER_CONTEXT`, and `DOCKER_HOST`.',
276
+ ]
277
+ const reported = sanitizeDockerStderr(detail)
278
+ if (reported !== '') {
279
+ lines.push(`Docker reported: ${reported}`)
280
+ }
281
+ return lines
282
+ }