typeclaw 0.42.0 → 0.43.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 (89) hide show
  1. package/auth.schema.json +16 -0
  2. package/package.json +3 -3
  3. package/secrets.schema.json +16 -0
  4. package/src/agent/adaptive-thinking-compat.ts +79 -0
  5. package/src/agent/index.ts +79 -101
  6. package/src/agent/live-subagents.ts +4 -4
  7. package/src/agent/plugin-tools.ts +85 -132
  8. package/src/agent/provider-error.ts +37 -0
  9. package/src/agent/reload-tool.ts +1 -1
  10. package/src/agent/session-origin.ts +6 -3
  11. package/src/agent/subagents.ts +2 -2
  12. package/src/agent/system-prompt.ts +24 -8
  13. package/src/agent/tool-result-budget.ts +1 -1
  14. package/src/agent/tools/channel-react.ts +5 -4
  15. package/src/agent/tools/spawn-subagent.ts +80 -24
  16. package/src/agent/tools/stream-snapshot.ts +8 -3
  17. package/src/bundled-plugins/agent-browser/index.ts +18 -8
  18. package/src/bundled-plugins/memory/README.md +4 -1
  19. package/src/bundled-plugins/memory/belief-sentence.ts +50 -0
  20. package/src/bundled-plugins/memory/dreaming.ts +13 -6
  21. package/src/bundled-plugins/memory/load-memory.ts +22 -2
  22. package/src/bundled-plugins/memory/memory-logger.ts +1 -1
  23. package/src/bundled-plugins/planner/planner.ts +1 -1
  24. package/src/bundled-plugins/researcher/researcher.ts +2 -2
  25. package/src/bundled-plugins/reviewer/reviewer.ts +1 -1
  26. package/src/capabilities/control-plane.ts +24 -0
  27. package/src/capabilities/index.ts +2 -0
  28. package/src/capabilities/runtime.ts +30 -0
  29. package/src/channels/adapters/discord-bot-thread-room.ts +73 -0
  30. package/src/channels/adapters/discord-bot.ts +9 -1
  31. package/src/channels/adapters/slack-bot-classify.ts +1 -0
  32. package/src/channels/adapters/slack-classify.ts +1 -0
  33. package/src/channels/engagement.ts +33 -0
  34. package/src/channels/manager.ts +41 -47
  35. package/src/channels/router.ts +150 -21
  36. package/src/channels/types.ts +10 -0
  37. package/src/cli/channel.ts +49 -12
  38. package/src/cli/command-meta.ts +2 -0
  39. package/src/cli/hostd.ts +4 -3
  40. package/src/cli/index.ts +1 -0
  41. package/src/cli/logs.ts +2 -2
  42. package/src/cli/mcp.ts +233 -0
  43. package/src/cli/restart.ts +5 -3
  44. package/src/cli/shell.ts +2 -2
  45. package/src/cli/start.ts +2 -2
  46. package/src/cli/status.ts +2 -2
  47. package/src/cli/stop.ts +2 -2
  48. package/src/compose/restart.ts +4 -3
  49. package/src/compose/start.ts +2 -2
  50. package/src/compose/stop.ts +2 -2
  51. package/src/config/config.ts +10 -1
  52. package/src/config/providers.ts +61 -9
  53. package/src/container/controller.ts +104 -0
  54. package/src/container/index.ts +9 -0
  55. package/src/hostd/daemon.ts +28 -9
  56. package/src/hostd/protocol.ts +12 -9
  57. package/src/init/index.ts +1 -1
  58. package/src/init/instagram-auth.ts +189 -34
  59. package/src/inspect/logs-item.ts +2 -2
  60. package/src/mcp/client.ts +16 -6
  61. package/src/mcp/index.ts +12 -0
  62. package/src/mcp/manager.ts +9 -4
  63. package/src/mcp/oauth.ts +212 -0
  64. package/src/run/index.ts +36 -11
  65. package/src/run/{codex-fetch-observer.ts → llm-fetch-observer.ts} +182 -82
  66. package/src/sandbox/availability.ts +2 -2
  67. package/src/sandbox/build.ts +1 -1
  68. package/src/sandbox/hidden-paths.ts +59 -0
  69. package/src/sandbox/index.ts +1 -1
  70. package/src/sandbox/policy.ts +2 -2
  71. package/src/secrets/discord-store.ts +4 -13
  72. package/src/secrets/index.ts +1 -1
  73. package/src/secrets/instagram-store.ts +4 -13
  74. package/src/secrets/kakao-store.ts +4 -13
  75. package/src/secrets/line-store.ts +4 -13
  76. package/src/secrets/schema.ts +13 -0
  77. package/src/secrets/secrets-provider.ts +86 -0
  78. package/src/secrets/slack-store.ts +4 -13
  79. package/src/secrets/storage.ts +108 -1
  80. package/src/secrets/webex-store.ts +4 -13
  81. package/src/server/index.ts +2 -2
  82. package/src/skills/typeclaw-channel-github/SKILL.md +2 -2
  83. package/src/skills/typeclaw-channel-instagram/SKILL.md +1 -1
  84. package/src/skills/typeclaw-config/SKILL.md +5 -3
  85. package/src/skills/typeclaw-plugins/SKILL.md +1 -1
  86. package/src/skills/typeclaw-troubleshooting/SKILL.md +1 -1
  87. package/src/stream/broker.ts +4 -3
  88. package/src/stream/types.ts +1 -0
  89. package/typeclaw.schema.json +14 -0
package/src/cli/mcp.ts ADDED
@@ -0,0 +1,233 @@
1
+ import { spawn } from 'node:child_process'
2
+ import { join } from 'node:path'
3
+
4
+ import { isCancel, log, note, text } from '@clack/prompts'
5
+ import { UnauthorizedError } from '@modelcontextprotocol/sdk/client/auth.js'
6
+ import { Client } from '@modelcontextprotocol/sdk/client/index.js'
7
+ import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js'
8
+ import { defineCommand } from 'citty'
9
+
10
+ import { loadConfigSync } from '@/config'
11
+ import { findAgentDir, isInitialized } from '@/init'
12
+ import { createFileMcpOAuthStore, TypeClawMcpOAuthProvider, listMcpCredentials } from '@/mcp'
13
+ import { SecretsBackend } from '@/secrets'
14
+
15
+ import { c, done, errorLine } from './ui'
16
+
17
+ const DEFAULT_CALLBACK_PORT = 1456
18
+
19
+ const authSub = defineCommand({
20
+ meta: {
21
+ name: 'auth',
22
+ description: 'authenticate an HTTP MCP server with OAuth',
23
+ },
24
+ args: {
25
+ server: { type: 'positional', description: 'MCP server name from typeclaw.json', required: true },
26
+ },
27
+ async run({ args }) {
28
+ const cwd = ensureAgentDir()
29
+ const result = await runMcpAuthFlow(cwd, args.server)
30
+ if (!result.ok) {
31
+ console.error(errorLine(result.reason))
32
+ process.exit(1)
33
+ }
34
+ },
35
+ })
36
+
37
+ const listSub = defineCommand({
38
+ meta: {
39
+ name: 'list',
40
+ description: 'show configured MCP servers and OAuth credential state',
41
+ },
42
+ run() {
43
+ const cwd = ensureAgentDir()
44
+ const config = loadConfigSync(cwd)
45
+ const credentials = listMcpCredentials(join(cwd, 'secrets.json'))
46
+ if (config.mcpServers.length === 0) {
47
+ console.log(c.dim('No MCP servers configured in typeclaw.json.'))
48
+ return
49
+ }
50
+ const nameWidth = Math.max(4, ...config.mcpServers.map((server) => server.name.length))
51
+ const typeWidth = 5
52
+ console.log(c.dim(`${'NAME'.padEnd(nameWidth)} ${'TYPE'.padEnd(typeWidth)} OAUTH`))
53
+ for (const server of config.mcpServers) {
54
+ const type = server.url === undefined ? 'stdio' : 'http'
55
+ const oauth = credentials[server.name] === undefined ? 'not configured' : 'configured'
56
+ console.log(`${server.name.padEnd(nameWidth)} ${type.padEnd(typeWidth)} ${oauth}`)
57
+ }
58
+ },
59
+ })
60
+
61
+ const logoutSub = defineCommand({
62
+ meta: {
63
+ name: 'logout',
64
+ description: 'remove OAuth credentials for an MCP server',
65
+ },
66
+ args: {
67
+ server: { type: 'positional', description: 'MCP server name from typeclaw.json', required: true },
68
+ },
69
+ run({ args }) {
70
+ const cwd = ensureAgentDir()
71
+ const removed = new SecretsBackend(join(cwd, 'secrets.json')).removeMcpCredentialSync(args.server)
72
+ if (!removed) log.info(`No OAuth credentials found for MCP server "${args.server}".`)
73
+ done({
74
+ title: c.green(`Removed OAuth credentials for MCP server "${args.server}".`),
75
+ hints: [{ label: 'Apply the secrets.json change:', command: 'typeclaw reload' }],
76
+ })
77
+ },
78
+ })
79
+
80
+ export const mcpCommand = defineCommand({
81
+ meta: {
82
+ name: 'mcp',
83
+ description: 'manage MCP server OAuth credentials',
84
+ },
85
+ subCommands: {
86
+ auth: authSub,
87
+ list: listSub,
88
+ logout: logoutSub,
89
+ },
90
+ })
91
+
92
+ export type McpAuthFlowResult = { ok: true } | { ok: false; reason: string }
93
+
94
+ export async function runMcpAuthFlow(cwd: string, serverName: string): Promise<McpAuthFlowResult> {
95
+ const config = loadConfigSync(cwd)
96
+ const server = config.mcpServers.find((candidate) => candidate.name === serverName)
97
+ if (server === undefined) return { ok: false, reason: `MCP server "${serverName}" is not configured.` }
98
+ if (server.url === undefined)
99
+ return { ok: false, reason: `MCP server "${serverName}" is stdio-only; OAuth is HTTP-only.` }
100
+
101
+ const redirectUrl = `http://localhost:${DEFAULT_CALLBACK_PORT}/callback`
102
+ let authorizationUrl: URL | undefined
103
+ const provider = new TypeClawMcpOAuthProvider(serverName, createFileMcpOAuthStore(join(cwd, 'secrets.json')), {
104
+ mode: 'host',
105
+ redirectUrl,
106
+ clientName: 'typeclaw',
107
+ onRedirect: (url) => {
108
+ authorizationUrl = url
109
+ },
110
+ })
111
+ const callback = createCallbackServer(DEFAULT_CALLBACK_PORT)
112
+ try {
113
+ const transport = new StreamableHTTPClientTransport(new URL(server.url), { authProvider: provider })
114
+ const client = new Client({ name: 'typeclaw', version: '0.17.0' }, { capabilities: {} })
115
+ try {
116
+ await client.connect(transport)
117
+ await client.close()
118
+ done({ title: c.green(`MCP server "${serverName}" is already authenticated.`), hints: [] })
119
+ return { ok: true }
120
+ } catch (cause) {
121
+ await client.close().catch(() => undefined)
122
+ if (!(cause instanceof UnauthorizedError)) throw cause
123
+ }
124
+ if (authorizationUrl === undefined)
125
+ return { ok: false, reason: 'OAuth server did not provide an authorization URL.' }
126
+ renderAuthorizationUrl(serverName, authorizationUrl)
127
+ openBrowserBestEffort(authorizationUrl)
128
+ const expectedState = await provider.state()
129
+ const codeResult = await Promise.race([callback.code, promptForCodeOrUrl()])
130
+ if (expectedState !== undefined && codeResult.state !== undefined && codeResult.state !== expectedState) {
131
+ return { ok: false, reason: 'OAuth callback state did not match the authorization request.' }
132
+ }
133
+ await transport.finishAuth(codeResult.code)
134
+ await verifyMcpAuth(server.url, provider)
135
+ done({
136
+ title: c.green(`Authenticated MCP server "${serverName}".`),
137
+ hints: [{ label: 'Apply the secrets.json change:', command: 'typeclaw reload' }],
138
+ })
139
+ return { ok: true }
140
+ } catch (cause) {
141
+ return { ok: false, reason: cause instanceof Error ? cause.message : String(cause) }
142
+ } finally {
143
+ callback.stop()
144
+ }
145
+ }
146
+
147
+ function ensureAgentDir(): string {
148
+ const cwd = findAgentDir(process.cwd()) ?? process.cwd()
149
+ if (!isInitialized(cwd)) {
150
+ console.error(errorLine('TypeClaw config file not found. Run `typeclaw init` first, or cd into an agent folder.'))
151
+ process.exit(1)
152
+ }
153
+ return cwd
154
+ }
155
+
156
+ function createCallbackServer(port: number): { code: Promise<{ code: string; state?: string }>; stop(): void } {
157
+ let resolveCode!: (value: { code: string; state?: string }) => void
158
+ const code = new Promise<{ code: string; state?: string }>((resolve) => {
159
+ resolveCode = resolve
160
+ })
161
+ const server = Bun.serve({
162
+ hostname: '127.0.0.1',
163
+ port,
164
+ fetch(req) {
165
+ const url = new URL(req.url)
166
+ if (url.pathname !== '/callback') return new Response('Not found', { status: 404 })
167
+ const parsed = parseCodeInput(url)
168
+ if (parsed === null) return new Response('Missing OAuth code', { status: 400 })
169
+ resolveCode(parsed)
170
+ return new Response('TypeClaw MCP OAuth complete. You can close this tab.')
171
+ },
172
+ })
173
+ return { code, stop: () => server.stop(true) }
174
+ }
175
+
176
+ function renderAuthorizationUrl(serverName: string, url: URL): void {
177
+ note(
178
+ [
179
+ `Open this URL in your browser to authenticate MCP server "${serverName}".`,
180
+ '',
181
+ 'If the browser cannot reach localhost after sign-in, copy the full redirect URL or code and paste it below.',
182
+ ].join('\n'),
183
+ 'MCP OAuth',
184
+ )
185
+ console.log(url.toString())
186
+ console.log('')
187
+ }
188
+
189
+ function openBrowserBestEffort(url: URL): void {
190
+ const command = process.platform === 'darwin' ? 'open' : process.platform === 'win32' ? 'cmd' : 'xdg-open'
191
+ const args = process.platform === 'win32' ? ['/c', 'start', '', url.toString()] : [url.toString()]
192
+ const child = spawn(command, args, { stdio: 'ignore', detached: true })
193
+ child.on('error', () => undefined)
194
+ child.unref()
195
+ }
196
+
197
+ async function promptForCodeOrUrl(): Promise<{ code: string; state?: string }> {
198
+ const value = await text({
199
+ message: 'After signing in, paste the code or full redirect URL:',
200
+ placeholder: 'code, or http://localhost:1456/callback?code=...&state=...',
201
+ })
202
+ if (isCancel(value)) throw new Error('OAuth login cancelled by user')
203
+ const parsed = parseCodeInput(value)
204
+ if (parsed === null) throw new Error('OAuth callback did not include a code')
205
+ return parsed
206
+ }
207
+
208
+ function parseCodeInput(input: string | URL): { code: string; state?: string } | null {
209
+ if (input instanceof URL) {
210
+ const code = input.searchParams.get('code')
211
+ if (code === null || code.trim() === '') return null
212
+ const state = input.searchParams.get('state') ?? undefined
213
+ return { code, ...(state === undefined ? {} : { state }) }
214
+ }
215
+ const trimmed = input.trim()
216
+ if (trimmed === '') return null
217
+ try {
218
+ return parseCodeInput(new URL(trimmed))
219
+ } catch {
220
+ return { code: trimmed }
221
+ }
222
+ }
223
+
224
+ async function verifyMcpAuth(url: string, authProvider: TypeClawMcpOAuthProvider): Promise<void> {
225
+ const client = new Client({ name: 'typeclaw', version: '0.17.0' }, { capabilities: {} })
226
+ try {
227
+ const transport = new StreamableHTTPClientTransport(new URL(url), { authProvider })
228
+ await client.connect(transport)
229
+ await client.listTools()
230
+ } finally {
231
+ await client.close().catch(() => undefined)
232
+ }
233
+ }
@@ -2,7 +2,7 @@ import { confirm, isCancel } from '@clack/prompts'
2
2
  import { defineCommand } from 'citty'
3
3
 
4
4
  import { config, validateConfig } from '@/config'
5
- import { start, stop } from '@/container'
5
+ import { resolveController } from '@/container'
6
6
  import { findAgentDir, isInitialized } from '@/init'
7
7
 
8
8
  import { preflightDocker, printDockerGuidance } from './docker-preflight'
@@ -70,9 +70,11 @@ export const restartCommand = defineCommand({
70
70
  process.exit(1)
71
71
  }
72
72
 
73
+ const controller = resolveController()
74
+
73
75
  const stopSpin = spinner()
74
76
  stopSpin.start('Stopping container...')
75
- const stopped = await stop({ cwd })
77
+ const stopped = await controller.stop({ cwd })
76
78
  if (!stopped.ok) {
77
79
  stopSpin.error(stopped.reason)
78
80
  process.exit(1)
@@ -81,7 +83,7 @@ export const restartCommand = defineCommand({
81
83
 
82
84
  const startSpin = spinner()
83
85
  startSpin.start('Starting container...')
84
- const started = await start({
86
+ const started = await controller.start({
85
87
  cwd,
86
88
  preferredHostPort: Number(args.port),
87
89
  forceBuild: args.build,
package/src/cli/shell.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { defineCommand } from 'citty'
2
2
 
3
- import { shell } from '@/container'
3
+ import { resolveController } from '@/container'
4
4
 
5
5
  import { preflightDocker, printDockerGuidance } from './docker-preflight'
6
6
  import { requireAgentDir } from './require-agent-dir'
@@ -29,7 +29,7 @@ export const shellCommand = defineCommand({
29
29
 
30
30
  console.log(c.cyan(`Attaching ${args.shell} inside the container...`))
31
31
 
32
- const result = await shell({ cwd, shell: args.shell })
32
+ const result = await resolveController().shell({ cwd, shell: args.shell })
33
33
  if (!result.ok) {
34
34
  console.error(errorLine(result.reason))
35
35
  process.exit(1)
package/src/cli/start.ts CHANGED
@@ -2,7 +2,7 @@ import { confirm, isCancel } from '@clack/prompts'
2
2
  import { defineCommand } from 'citty'
3
3
 
4
4
  import { config, validateConfig } from '@/config'
5
- import { start } from '@/container'
5
+ import { resolveController } from '@/container'
6
6
  import { findAgentDir, isInitialized } from '@/init'
7
7
 
8
8
  import { preflightDocker, printDockerGuidance } from './docker-preflight'
@@ -72,7 +72,7 @@ export const startCommand = defineCommand({
72
72
 
73
73
  const s = spinner()
74
74
  s.start('Starting container...')
75
- const result = await start({
75
+ const result = await resolveController().start({
76
76
  cwd,
77
77
  preferredHostPort: Number(args.port),
78
78
  forceBuild: args.build,
package/src/cli/status.ts CHANGED
@@ -2,7 +2,7 @@ import { styleText } from 'node:util'
2
2
 
3
3
  import { defineCommand } from 'citty'
4
4
 
5
- import { status as containerStatus, type ContainerStatus, type DockerExec } from '@/container'
5
+ import { type ContainerStatus, type DockerExec, resolveController } from '@/container'
6
6
  import { isDaemonReachable, send } from '@/hostd'
7
7
  import type { StatusResult } from '@/hostd'
8
8
  import { findAgentDir } from '@/init'
@@ -52,7 +52,7 @@ export async function runStatus(deps: RunStatusDeps = {}): Promise<void> {
52
52
  return
53
53
  }
54
54
 
55
- const container = await containerStatus({ cwd, exec: deps.exec })
55
+ const container = await resolveController().status({ cwd, exec: deps.exec })
56
56
  const hostd = await (deps.fetchHostd ?? fetchHostdStatus)(container.containerName)
57
57
 
58
58
  const useColor = Boolean(process.stdout.isTTY) && process.env.NO_COLOR === undefined
package/src/cli/stop.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { defineCommand } from 'citty'
2
2
 
3
- import { stop } from '@/container'
3
+ import { resolveController } from '@/container'
4
4
 
5
5
  import { preflightDocker, printDockerGuidance } from './docker-preflight'
6
6
  import { requireAgentDir } from './require-agent-dir'
@@ -22,7 +22,7 @@ export const stopCommand = defineCommand({
22
22
 
23
23
  const s = spinner()
24
24
  s.start('Stopping container...')
25
- const result = await stop({ cwd })
25
+ const result = await resolveController().stop({ cwd })
26
26
 
27
27
  if (!result.ok) {
28
28
  s.error(result.reason)
@@ -1,5 +1,5 @@
1
1
  import { validateConfig } from '@/config'
2
- import { start, stop } from '@/container'
2
+ import { resolveController } from '@/container'
3
3
 
4
4
  import { discoverAgents, type AgentEntry } from './discover'
5
5
  import type { AgentResult, StartSuccess } from './start'
@@ -57,10 +57,11 @@ async function runOne(
57
57
  const validated = validateConfig(cwd)
58
58
  if (!validated.ok) return { name, ok: false, reason: validated.reason }
59
59
  try {
60
- const stopped = await stop({ cwd })
60
+ const controller = resolveController()
61
+ const stopped = await controller.stop({ cwd })
61
62
  if (!stopped.ok) return { name, ok: false, reason: stopped.reason }
62
63
  onStopped()
63
- const started = await start({ cwd, preferredHostPort, forceBuild, cliEntry })
64
+ const started = await controller.start({ cwd, preferredHostPort, forceBuild, cliEntry })
64
65
  if (!started.ok) return { name, ok: false, reason: started.reason }
65
66
  return { name, ok: true, data: { stop: stopped, start: started }, warnings: validated.warnings }
66
67
  } catch (error) {
@@ -1,5 +1,5 @@
1
1
  import { validateConfig } from '@/config'
2
- import { start, type StartResult } from '@/container'
2
+ import { resolveController, type StartResult } from '@/container'
3
3
 
4
4
  import { discoverAgents, type AgentEntry } from './discover'
5
5
 
@@ -55,7 +55,7 @@ async function runOne(
55
55
  const validated = validateConfig(cwd)
56
56
  if (!validated.ok) return { name, ok: false, reason: validated.reason }
57
57
  try {
58
- const data = await start({ cwd, preferredHostPort, forceBuild, cliEntry })
58
+ const data = await resolveController().start({ cwd, preferredHostPort, forceBuild, cliEntry })
59
59
  if (!data.ok) return { name, ok: false, reason: data.reason }
60
60
  return { name, ok: true, data, warnings: validated.warnings }
61
61
  } catch (error) {
@@ -1,4 +1,4 @@
1
- import { stop, type StopResult } from '@/container'
1
+ import { resolveController, type StopResult } from '@/container'
2
2
 
3
3
  import { discoverAgents, type AgentEntry } from './discover'
4
4
  import type { AgentResult } from './start'
@@ -34,7 +34,7 @@ export async function composeStop({ rootCwd, onProgress }: ComposeStopOptions):
34
34
 
35
35
  async function runOne(name: string, cwd: string): Promise<AgentResult<StopSuccess>> {
36
36
  try {
37
- const data = await stop({ cwd })
37
+ const data = await resolveController().stop({ cwd })
38
38
  if (!data.ok) return { name, ok: false, reason: data.reason }
39
39
  return { name, ok: true, data }
40
40
  } catch (error) {
@@ -373,7 +373,7 @@ export type NetworkConfig = z.infer<typeof networkSchema>
373
373
  // the default 'proc-bind' strategy `--ro-bind`s the container's already-real
374
374
  // procfs into the sandbox with NO CAP_SYS_ADMIN, giving the runner's child a
375
375
  // working /proc/self/{fd,maps} so it stops aborting with Bun's "NotDir". The
376
- // agent runtime's /proc/N/environ (FIREWORKS_API_KEY) stays unreadable because
376
+ // agent runtime's /proc/N/environ (OPENAI_API_KEY) stays unreadable because
377
377
  // bwrap's --unshare-user puts the sandbox in a child user namespace the kernel
378
378
  // won't let read a parent-userns process's environ — verified at runtime by a
379
379
  // probe before the strategy is selected (src/sandbox/availability.ts). Avoiding
@@ -786,6 +786,14 @@ export const configSchema = z
786
786
  git: gitSchema,
787
787
  roles: rolesConfigSchema.optional(),
788
788
  tunnels: tunnelsArraySchema,
789
+ // When `true` (default), the system prompt tells the agent it runs on
790
+ // TypeClaw and stamps the runtime version. Set `false` to strip every
791
+ // TypeClaw-identifying clue from the system prompt: the base prompt's
792
+ // opening lines are phrased generically ("a general-purpose AI agent"
793
+ // instead of "…running inside TypeClaw") and the `## Runtime` version
794
+ // block is omitted entirely. Read fresh per session via `getConfig()`, so
795
+ // it applies on reload without a restart.
796
+ branding: z.boolean().default(true),
789
797
  })
790
798
  .catchall(z.unknown())
791
799
 
@@ -1012,6 +1020,7 @@ export const FIELD_EFFECTS: Record<string, FieldEffect> = {
1012
1020
  // the corresponding projections of the whole `roles` block.
1013
1021
  'roles.match': 'applied',
1014
1022
  'roles.permissions': 'restart-required',
1023
+ branding: 'applied',
1015
1024
  }
1016
1025
 
1017
1026
  // Stable JSON for value comparison. Fields are small JSON-shaped objects, so
@@ -120,9 +120,8 @@ export const KNOWN_PROVIDERS = {
120
120
  // ChatGPT Plus/Pro subscription via the OAuth Codex backend. No API key
121
121
  // path here on purpose — the Codex backend is OAuth-only upstream.
122
122
  //
123
- // pi-ai 0.73.1's `openai-codex` bucket carries gpt-5.5 (and 5.4) against
124
- // chatgpt.com/backend-api. We pin pi-coding-agent ^0.67.3 today, which
125
- // ships pi-ai 0.67.3 and lacks those entries — but we hand pi-ai a
123
+ // pi-ai's `openai-codex` bucket carries gpt-5.5 (and 5.4) against
124
+ // chatgpt.com/backend-api. We don't rely on that catalog: we hand pi-ai a
126
125
  // freshly-constructed `Model<>` literal via resolveModel(), bypassing its
127
126
  // built-in catalog entirely (same trick we use for kimi-k2p6-turbo). So
128
127
  // these ids work end-to-end as long as the Codex backend itself accepts
@@ -205,14 +204,18 @@ export const KNOWN_PROVIDERS = {
205
204
  // anthropic`) before relying on the env-var path. Same rule applies to any
206
205
  // future dual-auth provider — keep the surprise in mind when expanding.
207
206
  //
208
- // Model lineup is the current GA tier as of 2026-05-29: Opus 4.8 (top,
209
- // released May 2026), Opus 4.7 (prior top, Apr 16 2026), Sonnet 4.6 (mid,
210
- // Feb 5 2026), Haiku 4.5 (fast, Oct 1 2025). Anthropic's own model overview
211
- // lists the latest Opus/Sonnet/Haiku as the current recommended set and
212
- // flags earlier Opus/Sonnet variants with
207
+ // Model lineup is the current GA tier as of 2026-07-02: Fable 5 (top,
208
+ // released Jun 2026 — a tier above Opus), Sonnet 5 (mid, Jul 1 2026),
209
+ // Opus 4.8 (May 2026), Opus 4.7 (Apr 16 2026), Sonnet 4.6 (Feb 5 2026),
210
+ // Haiku 4.5 (fast, Oct 1 2025). Anthropic's own model overview lists the
211
+ // latest Fable/Opus/Sonnet/Haiku as the current recommended set and flags
212
+ // earlier Opus/Sonnet variants with
213
213
  // "Consider migrating to current models." Opus 4 / Sonnet 4 are deprecated
214
214
  // (retirement: Jun 15 2026); the 4.5/4.6 alternates remain Active but are
215
- // not the recommended path.
215
+ // not the recommended path. Claude Mythos 5 (Fable 5's classifier-free
216
+ // sibling, limited availability via Project Glasswing) is intentionally
217
+ // NOT listed — access is gated per-org and a registry entry would fail for
218
+ // everyone else.
216
219
  //
217
220
  // ID semantics differ across the lineup and matter for forward-compat:
218
221
  // - `claude-haiku-4-5` is a 4.5-generation CONVENIENCE ALIAS that
@@ -273,6 +276,35 @@ export const KNOWN_PROVIDERS = {
273
276
  contextWindow: 1000000,
274
277
  maxTokens: 64000,
275
278
  },
279
+ // Sonnet 5 (Jul 1 2026) is the drop-in successor to Sonnet 4.6 with a
280
+ // caveat set that affects consumers of this record:
281
+ // - New tokenizer: ~30% more tokens for the same text vs Sonnet 4.6.
282
+ // Per-token price is unchanged, so equivalent requests cost more.
283
+ // - Adaptive thinking only: manual extended thinking
284
+ // (`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.
291
+ // - 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.
296
+ 'claude-sonnet-5': {
297
+ id: 'claude-sonnet-5',
298
+ name: 'Claude Sonnet 5',
299
+ api: 'anthropic-messages',
300
+ provider: 'anthropic',
301
+ baseUrl: 'https://api.anthropic.com',
302
+ reasoning: true,
303
+ input: ['text', 'image'],
304
+ cost: { input: 3, output: 15, cacheRead: 0.3, cacheWrite: 3.75 },
305
+ contextWindow: 1000000,
306
+ maxTokens: 128000,
307
+ },
276
308
  'claude-opus-4-7': {
277
309
  id: 'claude-opus-4-7',
278
310
  name: 'Claude Opus 4.7',
@@ -297,6 +329,26 @@ export const KNOWN_PROVIDERS = {
297
329
  contextWindow: 1000000,
298
330
  maxTokens: 128000,
299
331
  },
332
+ // Fable 5 (Jun 2026) is a NEW TIER above Opus — Anthropic's most
333
+ // capable widely released model, aimed at long-horizon agentic work.
334
+ // Ships the 5-generation tokenizer: ~1.3x token counts for the same
335
+ // text vs pre-5 models, so equivalent requests cost more than the
336
+ // 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).
340
+ 'claude-fable-5': {
341
+ id: 'claude-fable-5',
342
+ name: 'Claude Fable 5',
343
+ api: 'anthropic-messages',
344
+ provider: 'anthropic',
345
+ baseUrl: 'https://api.anthropic.com',
346
+ reasoning: true,
347
+ input: ['text', 'image'],
348
+ cost: { input: 10, output: 50, cacheRead: 1, cacheWrite: 12.5 },
349
+ contextWindow: 1000000,
350
+ maxTokens: 128000,
351
+ },
300
352
  },
301
353
  },
302
354
  fireworks: {
@@ -0,0 +1,104 @@
1
+ import { logs, type LogsOptions, type LogsResult } from './logs'
2
+ import { containerNameFromCwd, imageTagFromCwd } from './shared'
3
+ import { shell, type ShellResult } from './shell'
4
+ import { start, type StartOptions, type StartResult } from './start'
5
+ import { status, type ContainerStatus, type StatusOptions } from './status'
6
+ import { stop, type StopOptions, type StopResult } from './stop'
7
+
8
+ // The controller role: the external actuator that acts ON a container's
9
+ // lifecycle (start/stop/status/logs/shell). Distinct from the host role
10
+ // (RuntimeSecretsProvider), which the container reaches INTO for durable state.
11
+ //
12
+ // In the `host` profile typeclaw owns this loop (LocalDockerController shells
13
+ // out to Docker). In a `managed` profile a platform (ECS/K8s/…) owns it, so
14
+ // typeclaw carries no controller — NoopController makes that absence explicit
15
+ // and fail-loud instead of silently shelling out to a Docker that isn't there.
16
+ export interface Controller {
17
+ start(options: StartOptions): Promise<StartResult>
18
+ stop(options: StopOptions): Promise<StopResult>
19
+ status(options: StatusOptions): Promise<ContainerStatus>
20
+ logs(options: LogsOptions): Promise<LogsResult>
21
+ shell(options: { cwd: string; shell?: string }): Promise<ShellResult>
22
+ }
23
+
24
+ // Thin adapter over the existing lifecycle functions — no behavior change, it
25
+ // just names the actuation surface as an interface so a managed profile can
26
+ // substitute a no-op controller. Factory (not class) to match the repo's
27
+ // functional DI convention.
28
+ export function createLocalDockerController(): Controller {
29
+ return {
30
+ start: (options) => start(options),
31
+ stop: (options) => stop(options),
32
+ status: (options) => status(options),
33
+ logs: (options) => logs(options),
34
+ shell: (options) => shell(options),
35
+ }
36
+ }
37
+
38
+ export const CONTROLLER_UNSUPPORTED_REASON =
39
+ 'container lifecycle is managed by the platform; typeclaw has no controller in this profile'
40
+
41
+ // The `managed`-profile controller: the platform owns start/stop/restart, so
42
+ // every lifecycle verb is a fail-loud no-op rather than a Docker shell-out.
43
+ // status() reports `missing` because typeclaw cannot introspect a container it
44
+ // does not orchestrate.
45
+ export function createNoopController(): Controller {
46
+ return {
47
+ async start({ cwd }) {
48
+ return { ok: false, reason: unsupported('start', cwd) }
49
+ },
50
+ async stop({ cwd }) {
51
+ return { ok: false, reason: unsupported('stop', cwd) }
52
+ },
53
+ async status({ cwd }) {
54
+ return { kind: 'missing', containerName: containerNameFromCwd(cwd), imageTag: imageTagFromCwd(cwd) }
55
+ },
56
+ async logs({ cwd }) {
57
+ return { ok: false, reason: unsupported('logs', cwd) }
58
+ },
59
+ async shell({ cwd }) {
60
+ return { ok: false, reason: unsupported('shell', cwd) }
61
+ },
62
+ }
63
+ }
64
+
65
+ function unsupported(verb: string, cwd: string): string {
66
+ return `${verb} unsupported for ${cwd}: ${CONTROLLER_UNSUPPORTED_REASON}`
67
+ }
68
+
69
+ // Which side owns the container control loop. `host` = typeclaw orchestrates
70
+ // via local Docker (the only reachable value today). `managed` = an external
71
+ // platform (ECS/K8s/…) owns it. The distinction is a deployer concern, not an
72
+ // agent-runtime one; see docs/internals for the host/controller split.
73
+ export type DeploymentProfile = 'host' | 'managed'
74
+
75
+ // Single source of truth for the deployment profile. There is no `managed`
76
+ // runtime yet, so this always resolves to `host`. When a managed platform
77
+ // lands, the trigger (a platform-injected env var, or a config field) is wired
78
+ // HERE — one place, not per call site.
79
+ export function resolveDeploymentProfile(): DeploymentProfile {
80
+ return 'host'
81
+ }
82
+
83
+ // The controller-axis resolver: maps the deployment profile to its actuator.
84
+ // Callers construct their Controller through this instead of `new
85
+ // LocalDockerController()` directly. `profile` is injectable for tests;
86
+ // production omits it and gets `resolveDeploymentProfile()`.
87
+ //
88
+ // SCOPE (do not overclaim): this centralizes only the *direct controller
89
+ // construction* — the lifecycle CALLS that previously did `new
90
+ // LocalDockerController()`. It is NOT yet the single deployment boundary. Two
91
+ // host-Docker escape hatches still sit outside it, to be routed when the
92
+ // managed controller is actually built:
93
+ // 1. Docker preflight (`preflightDocker()`) runs BEFORE the resolver in
94
+ // start/stop/logs/shell/restart and compose, so a managed profile would
95
+ // exit on the host-only check before reaching a managed controller.
96
+ // Fix: resolve profile first, move availability checks inside the host
97
+ // controller path.
98
+ // 2. Fleet/status/init paths still use host primitives directly
99
+ // (`resolveDockerBinary` in compose/logs, `inspectContainer` in
100
+ // compose/status, `start`/`stop` deps in init) — probes not on the
101
+ // Controller surface. Route or narrow when managed lands.
102
+ export function resolveController(profile: DeploymentProfile = resolveDeploymentProfile()): Controller {
103
+ return profile === 'managed' ? createNoopController() : createLocalDockerController()
104
+ }
@@ -1,3 +1,12 @@
1
+ export {
2
+ CONTROLLER_UNSUPPORTED_REASON,
3
+ type Controller,
4
+ createLocalDockerController,
5
+ createNoopController,
6
+ type DeploymentProfile,
7
+ resolveController,
8
+ resolveDeploymentProfile,
9
+ } from './controller'
1
10
  export {
2
11
  classifyConfiguredRuntime,
3
12
  detectInstalledDockerApps,