typeclaw 0.45.1 → 0.46.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 (142) hide show
  1. package/README.md +1 -1
  2. package/package.json +2 -1
  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 +151 -39
  9. package/src/agent/network/response-body.ts +26 -0
  10. package/src/agent/network/safe-http.ts +198 -0
  11. package/src/agent/plugin-tools.ts +379 -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 +1050 -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 +143 -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 +27 -0
  30. package/src/agent/turn-runner.ts +86 -6
  31. package/src/bundled-plugins/backup/index.ts +2 -1
  32. package/src/bundled-plugins/backup/runner.ts +2 -1
  33. package/src/bundled-plugins/doc-render/render.ts +93 -12
  34. package/src/bundled-plugins/doc-render/skills/typeclaw-render-pdf/SKILL.md +13 -13
  35. package/src/bundled-plugins/github-cli-auth/effective-approval.ts +16 -6
  36. package/src/bundled-plugins/github-cli-auth/gh-command.ts +555 -15
  37. package/src/bundled-plugins/github-cli-auth/index.ts +131 -135
  38. package/src/bundled-plugins/github-cli-auth/review-checkout.ts +138 -0
  39. package/src/bundled-plugins/guard/policies/uncommitted-changes.ts +2 -1
  40. package/src/bundled-plugins/memory/README.md +23 -11
  41. package/src/bundled-plugins/memory/append-tool.ts +15 -8
  42. package/src/bundled-plugins/memory/citations.ts +22 -9
  43. package/src/bundled-plugins/memory/dreaming.ts +13 -8
  44. package/src/bundled-plugins/memory/find-entry-tool.ts +4 -0
  45. package/src/bundled-plugins/memory/index.ts +0 -4
  46. package/src/bundled-plugins/memory/load-memory.ts +8 -3
  47. package/src/bundled-plugins/memory/provenance-index.ts +717 -0
  48. package/src/bundled-plugins/memory/provenance-sanitize.ts +40 -0
  49. package/src/bundled-plugins/memory/references/store-reference-tool.ts +4 -0
  50. package/src/bundled-plugins/memory/search-tool.ts +163 -60
  51. package/src/bundled-plugins/memory/stream-events.ts +2 -0
  52. package/src/bundled-plugins/memory/vector/hybrid.ts +126 -13
  53. package/src/bundled-plugins/researcher/write-report.ts +6 -3
  54. package/src/bundled-plugins/reviewer/index.ts +2 -2
  55. package/src/bundled-plugins/reviewer/reviewer.ts +10 -3
  56. package/src/bundled-plugins/reviewer/skills/code-review.ts +19 -9
  57. package/src/bundled-plugins/scout/scout.ts +8 -0
  58. package/src/bundled-plugins/security/index.ts +4 -4
  59. package/src/bundled-plugins/security/policies/outbound-secret-scan.ts +1 -0
  60. package/src/bundled-plugins/security/policies/private-surface-read.ts +220 -29
  61. package/src/bundled-plugins/security/policies/secret-exfil-read.ts +1 -0
  62. package/src/bundled-plugins/security/policies/ssrf.ts +29 -9
  63. package/src/channels/adapters/discord-bot-channel-resolver.ts +26 -14
  64. package/src/channels/adapters/discord-bot-thread-room.ts +44 -12
  65. package/src/channels/adapters/discord-bot.ts +66 -6
  66. package/src/channels/adapters/discord-channel-resolver.ts +91 -23
  67. package/src/channels/adapters/discord-id.ts +4 -0
  68. package/src/channels/adapters/discord-resolver-cache.ts +41 -0
  69. package/src/channels/adapters/discord.ts +57 -7
  70. package/src/channels/adapters/github/auth-app.ts +41 -12
  71. package/src/channels/adapters/github/index.ts +23 -11
  72. package/src/channels/adapters/github/review-submitter.ts +302 -0
  73. package/src/channels/adapters/kakaotalk-channel-resolver.ts +5 -3
  74. package/src/channels/adapters/kakaotalk-fetch-attachment.ts +8 -4
  75. package/src/channels/adapters/kakaotalk-typing.ts +17 -15
  76. package/src/channels/adapters/slack-attachment-download.ts +71 -0
  77. package/src/channels/adapters/slack-bot.ts +19 -8
  78. package/src/channels/adapters/slack-classify.ts +21 -2
  79. package/src/channels/adapters/slack.ts +59 -7
  80. package/src/channels/adapters/telegram-bot.ts +18 -5
  81. package/src/channels/adapters/webex-bot.ts +8 -3
  82. package/src/channels/adapters/webex.ts +8 -3
  83. package/src/channels/fetch-attachment.ts +43 -0
  84. package/src/{bundled-plugins/github-cli-auth/approve-idempotency.ts → channels/github-review-verdict-coordinator.ts} +25 -1
  85. package/src/channels/github-token-bridge.ts +10 -3
  86. package/src/channels/manager.ts +9 -0
  87. package/src/channels/router.ts +248 -6
  88. package/src/channels/types.ts +28 -1
  89. package/src/cli/channel.ts +1 -1
  90. package/src/cli/init.ts +1 -1
  91. package/src/cli/model.ts +57 -7
  92. package/src/compose/stop.ts +17 -5
  93. package/src/config/config.ts +6 -6
  94. package/src/config/models-mutation.ts +13 -1
  95. package/src/config/providers.ts +176 -0
  96. package/src/container/start.ts +49 -10
  97. package/src/doctor/checks.ts +3 -1
  98. package/src/doctor/commit.ts +2 -1
  99. package/src/doctor/file-ownership.ts +52 -0
  100. package/src/dreams/git.ts +2 -1
  101. package/src/git/hookless.ts +5 -0
  102. package/src/git/reconcile-ignored.ts +18 -5
  103. package/src/git/secret-history.ts +371 -0
  104. package/src/git/system-commit.ts +12 -6
  105. package/src/init/dockerfile.ts +86 -5
  106. package/src/init/index.ts +17 -5
  107. package/src/init/models-dev.ts +4 -0
  108. package/src/init/validate-api-key.ts +2 -0
  109. package/src/mcp/tools.ts +16 -3
  110. package/src/permissions/builtins.ts +3 -1
  111. package/src/plugin/context.ts +2 -0
  112. package/src/plugin/index.ts +1 -0
  113. package/src/plugin/manager.ts +4 -0
  114. package/src/plugin/types.ts +21 -0
  115. package/src/run/index.ts +40 -0
  116. package/src/run/llm-fetch-observer.ts +41 -4
  117. package/src/sandbox/build.ts +37 -15
  118. package/src/sandbox/canonical-secrets.ts +18 -0
  119. package/src/sandbox/env-exposure.ts +80 -0
  120. package/src/sandbox/errors.ts +13 -6
  121. package/src/sandbox/hidden-paths.ts +102 -44
  122. package/src/sandbox/index.ts +22 -4
  123. package/src/sandbox/package-install.ts +3 -27
  124. package/src/sandbox/policy.ts +11 -25
  125. package/src/sandbox/privileged-runtime.ts +255 -0
  126. package/src/sandbox/session-tmp.ts +8 -2
  127. package/src/sandbox/writable-zones.ts +204 -140
  128. package/src/secrets/index.ts +8 -0
  129. package/src/secrets/refresh-provider-oauth.ts +128 -0
  130. package/src/server/command-runner.ts +48 -4
  131. package/src/server/index.ts +4 -0
  132. package/src/skills/typeclaw-channel-github/SKILL.md +49 -56
  133. package/src/skills/typeclaw-claude-code/SKILL.md +24 -60
  134. package/src/skills/typeclaw-claude-code/references/auth-flow.md +17 -158
  135. package/src/skills/typeclaw-codex-cli/SKILL.md +19 -49
  136. package/src/skills/typeclaw-codex-cli/references/auth-flow.md +17 -154
  137. package/src/skills/typeclaw-config/SKILL.md +5 -5
  138. package/src/skills/typeclaw-config/references/recommended-mounts.md +24 -24
  139. package/src/skills/typeclaw-github-contributing/SKILL.md +23 -26
  140. package/src/skills/typeclaw-memory/SKILL.md +9 -3
  141. package/src/skills/typeclaw-permissions/SKILL.md +19 -15
  142. package/typeclaw.schema.json +20 -0
@@ -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,5 +1,5 @@
1
1
  import { randomBytes } from 'node:crypto'
2
- import { existsSync } from 'node:fs'
2
+ import { accessSync, constants as fsConstants, existsSync } from 'node:fs'
3
3
  import { cp, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises'
4
4
  import { tmpdir } from 'node:os'
5
5
  import { isAbsolute, join, relative, resolve } from 'node:path'
@@ -85,6 +85,9 @@ export type PlanStartOptions = {
85
85
  // Defaults to `process.platform`; tests inject it to exercise the native-
86
86
  // Windows dev-source mount branch without running on a Windows host.
87
87
  platform?: NodeJS.Platform
88
+ // POSIX identity whose ownership bind-mounted runtime writes must retain.
89
+ // Omitted when unavailable (native Windows and unusual JS hosts).
90
+ hostIdentity?: { uid: number; gid: number } | null
88
91
  }
89
92
 
90
93
  export type HostDaemonControl = {
@@ -168,6 +171,9 @@ export type StartOptions = {
168
171
  // Defaults to `process.platform`; tests inject it to exercise the
169
172
  // native-Windows dev-link reconcile path off a non-Windows runner.
170
173
  platform?: NodeJS.Platform
174
+ hostIdentity?: { uid: number; gid: number } | null
175
+ // Test seam for the host-stage writable-config preflight.
176
+ assertConfigWritable?: (cwd: string) => void
171
177
  }
172
178
 
173
179
  export type HostDaemonStatus =
@@ -219,6 +225,8 @@ export async function start({
219
225
  verifyRunning = createVerifyRunning({ exec }),
220
226
  runBunLink,
221
227
  platform = process.platform,
228
+ hostIdentity = currentHostIdentity(),
229
+ assertConfigWritable = assertAgentConfigWritable,
222
230
  }: StartOptions): Promise<StartResult> {
223
231
  try {
224
232
  const containerName = containerNameFromCwd(cwd)
@@ -234,6 +242,8 @@ export async function start({
234
242
  return await reportAlreadyRunning(exec, cwd, containerName)
235
243
  }
236
244
 
245
+ assertConfigWritable(cwd)
246
+
237
247
  // TypeClaw owns Dockerfile, .gitignore, and the bun-workspaces shape of
238
248
  // package.json. Refresh them from the current CLI templates on every fresh
239
249
  // start (not just --build) so version drift between the agent folder and
@@ -463,6 +473,7 @@ export async function start({
463
473
  publishHost,
464
474
  tuiToken,
465
475
  platform,
476
+ hostIdentity,
466
477
  })
467
478
 
468
479
  let built = false
@@ -598,6 +609,25 @@ function installedReachesTarget(installed: string, target: string): boolean {
598
609
  return true
599
610
  }
600
611
 
612
+ function currentHostIdentity(): { uid: number; gid: number } | null {
613
+ if (typeof process.getuid !== 'function' || typeof process.getgid !== 'function') return null
614
+ return { uid: process.getuid(), gid: process.getgid() }
615
+ }
616
+
617
+ function assertAgentConfigWritable(cwd: string): void {
618
+ const configPath = join(cwd, 'typeclaw.json')
619
+ if (!existsSync(configPath)) return
620
+ try {
621
+ accessSync(configPath, fsConstants.R_OK | fsConstants.W_OK)
622
+ } catch (error) {
623
+ const detail = error instanceof Error ? error.message : String(error)
624
+ throw new Error(
625
+ `typeclaw.json is not writable by the current host user: ${configPath}. ` +
626
+ `Inspect ownership with \`ls -ln "${configPath}"\` and run \`typeclaw doctor\` for repair guidance. ${detail}`,
627
+ )
628
+ }
629
+ }
630
+
601
631
  export async function planStart({
602
632
  cwd,
603
633
  hostPort,
@@ -607,6 +637,7 @@ export async function planStart({
607
637
  publishHost = '127.0.0.1',
608
638
  tuiToken = null,
609
639
  platform = process.platform,
640
+ hostIdentity = currentHostIdentity(),
610
641
  }: PlanStartOptions): Promise<StartPlan> {
611
642
  const containerName = containerNameFromCwd(cwd)
612
643
  const imageTag = imageTagFromCwd(cwd)
@@ -694,9 +725,9 @@ export async function planStart({
694
725
  }
695
726
 
696
727
  // sandbox.symlinks: the entrypoint shim creates `from -> /agent/<to>` at the
697
- // real container HOME for the UNSANDBOXED (trusted/owner) bash path. The
698
- // low-trust path is handled separately by the per-tool bwrap --symlink op
699
- // (src/sandbox/build.ts). Passed as base64-encoded JSON because `from`/`to`
728
+ // real container HOME for runtime-owned processes. Model-driven bash creates
729
+ // its corresponding link at the bwrap HOME via src/sandbox/build.ts. Passed
730
+ // as base64-encoded JSON because `from`/`to`
700
731
  // are arbitrary operator strings — base64 sidesteps every shell-metachar and
701
732
  // env-quoting hazard; the shim decodes + JSON-parses it with bun. Omitted when
702
733
  // empty so the common case adds no env clutter and the shim's loop never runs.
@@ -729,6 +760,14 @@ export async function planStart({
729
760
  runArgs.push('-e', `TZ=${hostTz}`)
730
761
  }
731
762
 
763
+ // Run the container entrypoint as root for iptables/bootstrap work, then
764
+ // re-exec the TypeClaw runtime under the invoking POSIX host identity. Docker
765
+ // Desktop/OrbStack propagate numeric ownership through the /agent bind mount,
766
+ // so this prevents container-created files from becoming root-owned on host.
767
+ if (platform !== 'win32' && hostIdentity !== null) {
768
+ runArgs.push('-e', `TYPECLAW_HOST_UID=${hostIdentity.uid}`, '-e', `TYPECLAW_HOST_GID=${hostIdentity.gid}`)
769
+ }
770
+
732
771
  // The agent's `restart` tool needs to identify itself to hostd. Inside the
733
772
  // container, cwd is `/agent` and basename(cwd) loses the host folder name,
734
773
  // so we cannot derive containerName from cwd at runtime. Inject it as an
@@ -969,13 +1008,13 @@ async function inspectContainer(exec: DockerExec, name: string): Promise<Inspect
969
1008
  // removal needs the user to act (`docker rm -f <name>` manually, or restart
970
1009
  // Docker) instead of looping forever.
971
1010
  //
972
- // A small bounded backoff (100/200/400ms) follows each cleanup before the
1011
+ // A bounded backoff (100/200/400/800/1200ms) follows each cleanup before the
973
1012
  // next `docker run`. waitForRemoval polls `docker inspect`, which can
974
1013
  // report the container gone BEFORE Docker's internal name-reservation
975
- // table has fully released the name. Without the backoff, the three
976
- // retries can all fire inside the same daemon drain window and exhaust
977
- // uselessly. The cumulative ~700ms is small next to the docker run RTT
978
- // itself and dwarfed by the user-visible cost of a failed start.
1014
+ // table has fully released the name. Without the backoff, the retries can
1015
+ // all fire inside the same daemon drain window and exhaust uselessly. The
1016
+ // cumulative ~2.7s is small next to the docker run RTT itself and dwarfed by
1017
+ // the user-visible cost of a failed start.
979
1018
  //
980
1019
  // Only the name-conflict path engages this destructive retry. Any other
981
1020
  // non-zero exit (port-allocated, image-not-found, permission-denied) is
@@ -999,7 +1038,7 @@ async function execRunWithConflictRetry(
999
1038
  return last
1000
1039
  }
1001
1040
 
1002
- const CONFLICT_RETRY_BACKOFFS_MS = [100, 200, 400] as const
1041
+ const CONFLICT_RETRY_BACKOFFS_MS = [100, 200, 400, 800, 1200] as const
1003
1042
 
1004
1043
  // Idempotent path for `start()`: the named container is already up. Reflect
1005
1044
  // the live container's identity (id) and host port in the result so callers
@@ -23,9 +23,10 @@ import { buildGitignore, GITIGNORE_FILE } from '@/init/gitignore'
23
23
  import { detectWsl, isWindows, isWindowsDriveMount, type WslInfo } from '@/shared'
24
24
 
25
25
  import { buildChannelChecks } from './channel-checks'
26
+ import { agentFileOwnership, type FileOwnershipDeps } from './file-ownership'
26
27
  import type { DoctorCheck } from './types'
27
28
 
28
- export function buildStaticChecks(opts: { dockerExec?: DockerExec } = {}): DoctorCheck[] {
29
+ export function buildStaticChecks(opts: { dockerExec?: DockerExec } & FileOwnershipDeps = {}): DoctorCheck[] {
29
30
  const dockerExec = opts.dockerExec ?? defaultDockerExec
30
31
 
31
32
  return [
@@ -36,6 +37,7 @@ export function buildStaticChecks(opts: { dockerExec?: DockerExec } = {}): Docto
36
37
  agentFolderGitignoreTemplate(),
37
38
  agentFolderNodeModules(),
38
39
  agentFolderGitRepo(),
40
+ agentFileOwnership(opts),
39
41
  configValid(),
40
42
  hostdHomeWritable(),
41
43
  wslDriveMount(),
@@ -1,3 +1,4 @@
1
+ import { hooklessGitArgs } from '@/git/hookless'
1
2
  import { resolveAgentGit } from '@/git/resolve-agent-git'
2
3
 
3
4
  import type { CommitOutcome, FixAttempt } from './types'
@@ -97,7 +98,7 @@ const defaultSpawnGit: SpawnGit = async (args, cwd) => {
97
98
  const bun = (globalThis as { Bun?: { spawn: typeof Bun.spawn } }).Bun
98
99
  if (!bun) return { exitCode: -1, stdout: '', stderr: 'bun runtime not available' }
99
100
  try {
100
- const proc = bun.spawn({ cmd: ['git', ...args], cwd, stdout: 'pipe', stderr: 'pipe' })
101
+ const proc = bun.spawn({ cmd: ['git', ...hooklessGitArgs(args)], cwd, stdout: 'pipe', stderr: 'pipe' })
101
102
  const exitCode = await proc.exited
102
103
  const stdout = await new Response(proc.stdout).text()
103
104
  const stderr = await new Response(proc.stderr).text()
@@ -0,0 +1,52 @@
1
+ import { existsSync, lstatSync, readdirSync } from 'node:fs'
2
+ import { join, relative } from 'node:path'
3
+
4
+ import type { DoctorCheck } from './types'
5
+
6
+ const MANAGED_PATHS = ['typeclaw.json', 'sessions', 'memory', '.typeclaw'] as const
7
+
8
+ export type FileOwnershipDeps = {
9
+ readonly platform?: NodeJS.Platform
10
+ readonly currentUid?: () => number
11
+ }
12
+
13
+ export function agentFileOwnership(deps: FileOwnershipDeps = {}): DoctorCheck {
14
+ const platform = deps.platform ?? process.platform
15
+ const currentUid = deps.currentUid ?? process.getuid
16
+
17
+ return {
18
+ name: 'agent-folder.file-ownership',
19
+ category: 'agent-folder',
20
+ description: 'agent-managed files are owned by the current host user',
21
+ applies: (ctx) => ctx.hasAgentFolder,
22
+ async run(ctx) {
23
+ if (platform === 'win32' || currentUid === undefined) {
24
+ return { status: 'ok', message: 'POSIX ownership does not apply on this host' }
25
+ }
26
+
27
+ const uid = currentUid()
28
+ const foreignPaths: string[] = []
29
+ for (const managedPath of MANAGED_PATHS) {
30
+ collectForeignPaths(join(ctx.cwd, managedPath), ctx.cwd, uid, foreignPaths)
31
+ }
32
+ if (foreignPaths.length === 0) return { status: 'ok', message: 'agent-managed files match the host user' }
33
+
34
+ return {
35
+ status: 'error',
36
+ message: `agent-managed files have a different owner: ${foreignPaths.join(', ')}`,
37
+ details: [
38
+ 'This usually means an older TypeClaw container wrote bind-mounted files as root.',
39
+ `Repair ownership from the agent folder: sudo chown -R "$(id -u):$(id -g)" ${MANAGED_PATHS.join(' ')}`,
40
+ ],
41
+ }
42
+ },
43
+ }
44
+ }
45
+
46
+ function collectForeignPaths(path: string, cwd: string, uid: number, foreignPaths: string[]): void {
47
+ if (!existsSync(path)) return
48
+ const stat = lstatSync(path)
49
+ if (stat.uid !== uid) foreignPaths.push(relative(cwd, path))
50
+ if (!stat.isDirectory()) return
51
+ for (const entry of readdirSync(path)) collectForeignPaths(join(path, entry), cwd, uid, foreignPaths)
52
+ }
package/src/dreams/git.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { hooklessGitArgs } from '@/git/hookless'
1
2
  import { resolveAgentGit } from '@/git/resolve-agent-git'
2
3
 
3
4
  export type GitResult = { exitCode: number; stdout: string; stderr: string }
@@ -87,7 +88,7 @@ const defaultSpawnGit: SpawnGit = async (args, cwd) => {
87
88
  const bun = (globalThis as { Bun?: { spawn: typeof Bun.spawn } }).Bun
88
89
  if (!bun) return { exitCode: -1, stdout: '', stderr: 'bun runtime not available' }
89
90
  try {
90
- const proc = bun.spawn({ cmd: ['git', ...args], cwd, stdout: 'pipe', stderr: 'pipe' })
91
+ const proc = bun.spawn({ cmd: ['git', ...hooklessGitArgs(args)], cwd, stdout: 'pipe', stderr: 'pipe' })
91
92
  const exitCode = await proc.exited
92
93
  const stdout = await new Response(proc.stdout).text()
93
94
  const stderr = await new Response(proc.stderr).text()
@@ -0,0 +1,5 @@
1
+ const HOOKLESS_GIT_CONFIG = ['-c', 'core.hooksPath=/dev/null'] as const
2
+
3
+ export function hooklessGitArgs(args: readonly string[]): string[] {
4
+ return [...HOOKLESS_GIT_CONFIG, ...args]
5
+ }
@@ -4,6 +4,7 @@ import { join } from 'node:path'
4
4
 
5
5
  import { SYSTEM_MANAGED_ROOTS, TRULY_IGNORED_PATTERNS } from '@/init/gitignore'
6
6
 
7
+ import { hooklessGitArgs } from './hookless'
7
8
  import { type AgentGit, resolveAgentGit } from './resolve-agent-git'
8
9
 
9
10
  export type UntrackResult = { untracked: string[] }
@@ -170,7 +171,7 @@ async function listTrackedIgnored(
170
171
  excludeFile: string,
171
172
  ): Promise<string[]> {
172
173
  const proc = bun.spawn({
173
- cmd: ['git', ...gitArgs, 'ls-files', '-z', '-c', '-i', '--exclude-from', excludeFile],
174
+ cmd: ['git', ...hooklessGitArgs([...gitArgs, 'ls-files', '-z', '-c', '-i', '--exclude-from', excludeFile])],
174
175
  cwd,
175
176
  stdout: 'pipe',
176
177
  stderr: 'pipe',
@@ -182,7 +183,7 @@ async function listTrackedIgnored(
182
183
 
183
184
  async function gitRmCached(bun: BunLike, cwd: string, gitArgs: readonly string[], files: string[]): Promise<string[]> {
184
185
  const proc = bun.spawn({
185
- cmd: ['git', ...gitArgs, 'rm', '--cached', '-q', '--', ...files],
186
+ cmd: ['git', ...hooklessGitArgs([...gitArgs, 'rm', '--cached', '-q', '--', ...files])],
186
187
  cwd,
187
188
  stdout: 'pipe',
188
189
  stderr: 'pipe',
@@ -200,7 +201,13 @@ async function run(
200
201
  args: readonly string[],
201
202
  env?: GitEnv,
202
203
  ): Promise<boolean> {
203
- const proc = bun.spawn({ cmd: ['git', ...gitArgs, ...args], cwd, env, stdout: 'pipe', stderr: 'pipe' })
204
+ const proc = bun.spawn({
205
+ cmd: ['git', ...hooklessGitArgs([...gitArgs, ...args])],
206
+ cwd,
207
+ env,
208
+ stdout: 'pipe',
209
+ stderr: 'pipe',
210
+ })
204
211
  return (await proc.exited) === 0
205
212
  }
206
213
 
@@ -211,7 +218,13 @@ async function capture(
211
218
  args: readonly string[],
212
219
  env?: GitEnv,
213
220
  ): Promise<string> {
214
- const proc = bun.spawn({ cmd: ['git', ...gitArgs, ...args], cwd, env, stdout: 'pipe', stderr: 'pipe' })
221
+ const proc = bun.spawn({
222
+ cmd: ['git', ...hooklessGitArgs([...gitArgs, ...args])],
223
+ cwd,
224
+ env,
225
+ stdout: 'pipe',
226
+ stderr: 'pipe',
227
+ })
215
228
  if ((await proc.exited) !== 0) return ''
216
229
  return await new Response(proc.stdout).text()
217
230
  }
@@ -226,7 +239,7 @@ async function forceRemove(
226
239
  env: GitEnv,
227
240
  ): Promise<boolean> {
228
241
  const proc = bun.spawn({
229
- cmd: ['git', ...gitArgs, 'update-index', '-z', '--force-remove', '--stdin'],
242
+ cmd: ['git', ...hooklessGitArgs([...gitArgs, 'update-index', '-z', '--force-remove', '--stdin'])],
230
243
  cwd,
231
244
  env,
232
245
  stdin: new TextEncoder().encode(files.join('\0')),