typeclaw 0.41.0 → 0.42.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 (91) hide show
  1. package/README.md +3 -2
  2. package/auth.schema.json +57 -0
  3. package/package.json +4 -4
  4. package/secrets.schema.json +57 -0
  5. package/src/agent/adaptive-thinking-compat.ts +79 -0
  6. package/src/agent/index.ts +89 -107
  7. package/src/agent/plugin-tools.ts +77 -130
  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 +1 -0
  11. package/src/agent/subagents.ts +2 -2
  12. package/src/agent/system-prompt.ts +19 -5
  13. package/src/agent/tool-result-budget.ts +1 -1
  14. package/src/agent/tools/channel-history-render.ts +21 -0
  15. package/src/agent/tools/channel-history.ts +2 -17
  16. package/src/agent/tools/channel-read.ts +206 -0
  17. package/src/agent/tools/stream-snapshot.ts +8 -3
  18. package/src/bundled-plugins/agent-browser/index.ts +18 -8
  19. package/src/bundled-plugins/agent-browser/skills/agent-browser/SKILL.md +26 -2
  20. package/src/bundled-plugins/github-cli-auth/index.ts +25 -6
  21. package/src/bundled-plugins/memory/README.md +4 -1
  22. package/src/bundled-plugins/memory/belief-sentence.ts +50 -0
  23. package/src/bundled-plugins/memory/dreaming.ts +13 -6
  24. package/src/bundled-plugins/memory/load-memory.ts +22 -2
  25. package/src/bundled-plugins/memory/memory-logger.ts +1 -1
  26. package/src/bundled-plugins/memory/vector/hybrid.ts +73 -6
  27. package/src/bundled-plugins/memory/vector/passages.ts +2 -24
  28. package/src/bundled-plugins/memory/vector/truncation.ts +28 -0
  29. package/src/bundled-plugins/tool-result-cap/README.md +10 -1
  30. package/src/bundled-plugins/tool-result-cap/cap-result.ts +8 -0
  31. package/src/capabilities/control-plane.ts +24 -0
  32. package/src/capabilities/index.ts +2 -0
  33. package/src/capabilities/runtime.ts +30 -0
  34. package/src/channels/adapters/discord-bot.ts +112 -0
  35. package/src/channels/adapters/instagram-channel-resolver.ts +113 -0
  36. package/src/channels/adapters/instagram-classify.ts +69 -0
  37. package/src/channels/adapters/instagram-format.ts +8 -0
  38. package/src/channels/adapters/instagram.ts +346 -0
  39. package/src/channels/adapters/slack-bot.ts +147 -0
  40. package/src/channels/manager.ts +96 -44
  41. package/src/channels/router.ts +75 -2
  42. package/src/channels/schema.ts +5 -0
  43. package/src/channels/types.ts +46 -0
  44. package/src/cli/channel.ts +121 -9
  45. package/src/cli/hostd.ts +4 -3
  46. package/src/cli/init.ts +1 -0
  47. package/src/cli/logs.ts +2 -2
  48. package/src/cli/restart.ts +5 -3
  49. package/src/cli/shell.ts +2 -2
  50. package/src/cli/start.ts +2 -2
  51. package/src/cli/status.ts +37 -14
  52. package/src/cli/stop.ts +2 -2
  53. package/src/compose/restart.ts +4 -3
  54. package/src/compose/start.ts +2 -2
  55. package/src/compose/stop.ts +2 -2
  56. package/src/config/channels-mutation.ts +2 -1
  57. package/src/config/config.ts +10 -1
  58. package/src/config/providers.ts +61 -9
  59. package/src/container/controller.ts +104 -0
  60. package/src/container/index.ts +9 -0
  61. package/src/doctor/channel-checks.ts +28 -0
  62. package/src/hostd/daemon.ts +11 -7
  63. package/src/hostd/protocol.ts +2 -0
  64. package/src/init/index.ts +51 -2
  65. package/src/init/instagram-auth.ts +289 -0
  66. package/src/init/run-owner-claim.ts +1 -0
  67. package/src/inspect/logs-item.ts +2 -2
  68. package/src/mcp/client.ts +1 -1
  69. package/src/permissions/match-rule.ts +1 -1
  70. package/src/permissions/resolve.ts +1 -0
  71. package/src/role-claim/match-rule.ts +2 -1
  72. package/src/run/index.ts +21 -9
  73. package/src/run/{codex-fetch-observer.ts → llm-fetch-observer.ts} +182 -82
  74. package/src/sandbox/availability.ts +2 -2
  75. package/src/sandbox/build.ts +1 -1
  76. package/src/sandbox/policy.ts +2 -2
  77. package/src/secrets/discord-store.ts +4 -13
  78. package/src/secrets/instagram-store.ts +103 -0
  79. package/src/secrets/kakao-store.ts +4 -13
  80. package/src/secrets/line-store.ts +4 -13
  81. package/src/secrets/schema.ts +18 -0
  82. package/src/secrets/secrets-provider.ts +86 -0
  83. package/src/secrets/slack-store.ts +4 -13
  84. package/src/secrets/webex-store.ts +4 -13
  85. package/src/server/index.ts +2 -2
  86. package/src/skills/typeclaw-channel-instagram/SKILL.md +30 -0
  87. package/src/skills/typeclaw-config/SKILL.md +5 -3
  88. package/src/skills/typeclaw-plugins/SKILL.md +1 -1
  89. package/src/stream/broker.ts +4 -3
  90. package/src/stream/types.ts +1 -0
  91. package/typeclaw.schema.json +175 -1
@@ -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,
@@ -32,6 +32,7 @@ export function buildChannelChecks(): DoctorCheck[] {
32
32
  discordUserCredentials(),
33
33
  slackUserCredentials(),
34
34
  webexUserCredentials(),
35
+ instagramCredentials(),
35
36
  lineCredentials(),
36
37
  kakaotalkCredentials(),
37
38
  githubCredentials(),
@@ -157,6 +158,33 @@ function webexUserCredentials(): DoctorCheck {
157
158
  }
158
159
  }
159
160
 
161
+ function instagramCredentials(): DoctorCheck {
162
+ return {
163
+ name: 'channel.instagram.credentials',
164
+ category: 'channels',
165
+ description: 'instagram adapter has at least one account in secrets.json',
166
+ applies: (ctx) => ctx.hasAgentFolder,
167
+ async run(ctx) {
168
+ const channels = readDeclaredChannels(ctx)
169
+ if (channels === null) return configInvalidResult()
170
+ if (!isAdapterActive(channels, 'instagram')) {
171
+ return { status: 'skipped', message: 'instagram not configured' }
172
+ }
173
+ const block = readChannelsSecrets(ctx)?.instagram
174
+ const accountCount = block?.accounts ? Object.keys(block.accounts).length : 0
175
+ if (accountCount === 0) {
176
+ return {
177
+ status: 'warning',
178
+ message: 'instagram has no accounts in secrets.json',
179
+ details: ['Adapter will start but fail authentication and stay disconnected.'],
180
+ fix: { description: 'Run `typeclaw channel add instagram` to log in an account.' },
181
+ }
182
+ }
183
+ return { status: 'ok', message: `instagram has ${accountCount} account(s)` }
184
+ },
185
+ }
186
+ }
187
+
160
188
  function lineCredentials(): DoctorCheck {
161
189
  return {
162
190
  name: 'channel.line.credentials',
@@ -8,6 +8,7 @@ import { defaultDockerExec, type DockerExec, type HostDaemonRegisterPayload } fr
8
8
  import type { PortForwardEvent } from '@/portbroker'
9
9
  import {
10
10
  discordChannelBlockSchema,
11
+ instagramChannelBlockSchema,
11
12
  kakaoChannelBlockSchema,
12
13
  lineChannelBlockSchema,
13
14
  slackChannelBlockSchema,
@@ -530,6 +531,7 @@ export async function startDaemon(opts: DaemonOptions = {}): Promise<Daemon> {
530
531
  channels:
531
532
  | { kakaotalk: unknown }
532
533
  | { discord: unknown }
534
+ | { instagram: unknown }
533
535
  | { line: unknown }
534
536
  | { webex: unknown }
535
537
  | { slack: unknown }
@@ -545,13 +547,15 @@ export async function startDaemon(opts: DaemonOptions = {}): Promise<Daemon> {
545
547
  const patch =
546
548
  'line' in channelsPatch
547
549
  ? { key: 'line' as const, parsed: lineChannelBlockSchema.safeParse(channelsPatch.line) }
548
- : 'discord' in channelsPatch
549
- ? { key: 'discord' as const, parsed: discordChannelBlockSchema.safeParse(channelsPatch.discord) }
550
- : 'webex' in channelsPatch
551
- ? { key: 'webex' as const, parsed: webexChannelBlockSchema.safeParse(channelsPatch.webex) }
552
- : 'slack' in channelsPatch
553
- ? { key: 'slack' as const, parsed: slackChannelBlockSchema.safeParse(channelsPatch.slack) }
554
- : { key: 'kakaotalk' as const, parsed: kakaoChannelBlockSchema.safeParse(channelsPatch.kakaotalk) }
550
+ : 'instagram' in channelsPatch
551
+ ? { key: 'instagram' as const, parsed: instagramChannelBlockSchema.safeParse(channelsPatch.instagram) }
552
+ : 'discord' in channelsPatch
553
+ ? { key: 'discord' as const, parsed: discordChannelBlockSchema.safeParse(channelsPatch.discord) }
554
+ : 'webex' in channelsPatch
555
+ ? { key: 'webex' as const, parsed: webexChannelBlockSchema.safeParse(channelsPatch.webex) }
556
+ : 'slack' in channelsPatch
557
+ ? { key: 'slack' as const, parsed: slackChannelBlockSchema.safeParse(channelsPatch.slack) }
558
+ : { key: 'kakaotalk' as const, parsed: kakaoChannelBlockSchema.safeParse(channelsPatch.kakaotalk) }
555
559
  if (!patch.parsed.success) {
556
560
  return { ok: false, reason: patch.parsed.error.issues.map((issue) => issue.message).join('; ') }
557
561
  }
@@ -1,6 +1,7 @@
1
1
  import type { PortForward } from '@/config'
2
2
  import type {
3
3
  DiscordChannelBlock,
4
+ InstagramChannelBlock,
4
5
  KakaoChannelBlock,
5
6
  LineChannelBlock,
6
7
  SlackChannelBlock,
@@ -28,6 +29,7 @@ export type Request =
28
29
  channels:
29
30
  | { kakaotalk: KakaoChannelBlock }
30
31
  | { discord: DiscordChannelBlock }
32
+ | { instagram: InstagramChannelBlock }
31
33
  | { line: LineChannelBlock }
32
34
  | { webex: WebexChannelBlock }
33
35
  | { slack: SlackChannelBlock }
package/src/init/index.ts CHANGED
@@ -86,6 +86,7 @@ export type InitStep =
86
86
  | 'scaffold'
87
87
  | 'slack-auth'
88
88
  | 'discord-auth'
89
+ | 'instagram-auth'
89
90
  | 'kakaotalk-auth'
90
91
  | 'webex-auth'
91
92
  | 'github-webhooks'
@@ -98,6 +99,7 @@ export type KakaotalkAuthResult = { ok: true } | { ok: false; reason: string }
98
99
  export type WebexAuthResult = { ok: true } | { ok: false; reason: string }
99
100
  export type SlackAuthResult = { ok: true } | { ok: false; reason: string }
100
101
  export type DiscordAuthResult = { ok: true } | { ok: false; reason: string }
102
+ export type InstagramAuthResult = { ok: true } | { ok: false; reason: string }
101
103
 
102
104
  // Structured credential block for the GitHub channel adapter. Mirrors the
103
105
  // shape `runAddChannel({ channel: 'github', ... })` consumes so the wizard
@@ -137,6 +139,8 @@ export type InitStepEvent =
137
139
  | { step: 'webex-auth'; phase: 'done'; result: WebexAuthResult }
138
140
  | { step: 'discord-auth'; phase: 'start' }
139
141
  | { step: 'discord-auth'; phase: 'done'; result: DiscordAuthResult }
142
+ | { step: 'instagram-auth'; phase: 'start' }
143
+ | { step: 'instagram-auth'; phase: 'done'; result: InstagramAuthResult }
140
144
  | { step: 'github-webhooks'; phase: 'start' }
141
145
  | { step: 'github-webhooks'; phase: 'done'; result: EagerGithubWebhookInstallResult }
142
146
  | { step: 'install'; phase: 'start' }
@@ -169,6 +173,7 @@ export type WebexAuthRunner = (options: { cwd: string }) => Promise<WebexAuthRes
169
173
 
170
174
  export type LineAuthResult = { ok: true } | { ok: false; reason: string }
171
175
  export type LineAuthRunner = (options: { cwd: string }) => Promise<LineAuthResult>
176
+ export type InstagramAuthRunner = (options: { cwd: string }) => Promise<InstagramAuthResult>
172
177
 
173
178
  // Discriminated by `kind` so the type system enforces "you can't pass an
174
179
  // API key to an OAuth provider, and you can't pass an OAuth runner to an
@@ -223,11 +228,13 @@ export type InitOptions = {
223
228
  withTelegram?: boolean
224
229
  withWebex?: boolean
225
230
  withWebexUser?: boolean
231
+ withInstagram?: boolean
226
232
  withKakaotalk?: boolean
227
233
  withGithub?: boolean
228
234
  runKakaotalkAuth?: KakaotalkAuthRunner
229
235
  runWebexAuth?: WebexAuthRunner
230
236
  runDiscordAuth?: DiscordAuthRunner
237
+ runInstagramAuth?: InstagramAuthRunner
231
238
  // Structured GitHub credentials collected by the wizard. When omitted and
232
239
  // `withGithub` is true, the existing secrets.json#channels.github block is
233
240
  // reused as-is (the wizard's "reuse existing credentials" path).
@@ -273,11 +280,13 @@ export async function runInit({
273
280
  withTelegram,
274
281
  withWebex,
275
282
  withWebexUser = false,
283
+ withInstagram = false,
276
284
  withKakaotalk = false,
277
285
  withGithub = false,
278
286
  runKakaotalkAuth,
279
287
  runWebexAuth,
280
288
  runDiscordAuth,
289
+ runInstagramAuth,
281
290
  githubCredentials,
282
291
  githubFetchImpl,
283
292
  onProgress,
@@ -358,12 +367,13 @@ export async function runInit({
358
367
  withTelegram: wantsTelegram,
359
368
  withWebex: wantsWebex,
360
369
  withWebexUser,
370
+ withInstagram,
361
371
  withKakaotalk,
362
372
  platform,
363
373
  })
364
374
  // Only write the LLM API key on the api-key path. OAuth providers persist
365
375
  // their credentials to secrets.json (via the OAuth login step above); writing
366
- // an empty FIREWORKS_API_KEY/OPENAI_API_KEY would just confuse users.
376
+ // an empty OPENAI_API_KEY would just confuse users.
367
377
  await writeSecrets(cwd, {
368
378
  model,
369
379
  apiKey: resolvedAuth.kind === 'api-key' ? resolvedAuth.apiKey : undefined,
@@ -412,6 +422,15 @@ export async function runInit({
412
422
  }
413
423
  }
414
424
 
425
+ if (withInstagram && runInstagramAuth !== undefined) {
426
+ emit({ step: 'instagram-auth', phase: 'start' })
427
+ const result = await runInstagramAuth({ cwd })
428
+ emit({ step: 'instagram-auth', phase: 'done', result })
429
+ if (!result.ok) {
430
+ throw new Error(`Instagram authentication failed: ${result.reason}`)
431
+ }
432
+ }
433
+
415
434
  // Write the structured github channel block alongside scaffold's bot-token
416
435
  // blocks. We do NOT delegate to runAddChannel because that's the `channel
417
436
  // add` semantics — strict no-overwrite, throws when secrets.json#channels
@@ -463,6 +482,7 @@ export async function runInit({
463
482
  if (wantsTelegram) configuredChannels.push('telegram-bot')
464
483
  if (wantsWebex) configuredChannels.push('webex-bot')
465
484
  if (withWebexUser) configuredChannels.push('webex')
485
+ if (withInstagram) configuredChannels.push('instagram')
466
486
  if (withKakaotalk) configuredChannels.push('kakaotalk')
467
487
  if (withGithub) configuredChannels.push('github')
468
488
 
@@ -633,6 +653,7 @@ export type ScaffoldOptions = {
633
653
  withTelegram?: boolean
634
654
  withWebex?: boolean
635
655
  withWebexUser?: boolean
656
+ withInstagram?: boolean
636
657
  withKakaotalk?: boolean
637
658
  // Defaults to `process.platform`; controls the dev-mode typeclaw spec
638
659
  // (`link:` on Windows, `file:` on POSIX). Tests inject it.
@@ -671,6 +692,7 @@ export async function scaffold(root: string, options: ScaffoldOptions = {}): Pro
671
692
  if (options.withTelegram) channels['telegram-bot'] = {}
672
693
  if (options.withWebex) channels['webex-bot'] = {}
673
694
  if (options.withWebexUser) channels.webex = {}
695
+ if (options.withInstagram) channels.instagram = {}
674
696
  if (options.withKakaotalk) channels.kakaotalk = {}
675
697
  if (Object.keys(channels).length > 0) config.channels = channels
676
698
  // No default `member` match is seeded. A fresh chat agent starts with every
@@ -986,7 +1008,7 @@ export async function hasExistingOAuthCredentials(root: string, providerId: Know
986
1008
  // kakaotalk` anyway — better to re-auth now during init.
987
1009
  export async function hasExistingChannelSecrets(
988
1010
  root: string,
989
- channel: 'discord' | 'slack' | 'telegram' | 'webex' | 'line' | 'kakaotalk' | 'github',
1011
+ channel: 'discord' | 'slack' | 'telegram' | 'webex' | 'instagram' | 'line' | 'kakaotalk' | 'github',
990
1012
  ): Promise<boolean> {
991
1013
  const channels = new SecretsBackend(join(root, 'secrets.json')).tryReadChannelsSync()
992
1014
  if (channels === null) return false
@@ -1008,6 +1030,18 @@ export async function hasExistingChannelSecrets(
1008
1030
  // surfaced as a hard error inside `runAddChannel` to prevent silent
1009
1031
  // overwrites.
1010
1032
  return false
1033
+ case 'instagram': {
1034
+ const block = channels.instagram
1035
+ if (!isObjectRecord(block)) return false
1036
+ const current = (block as { currentAccount?: unknown }).currentAccount
1037
+ if (typeof current !== 'string' || current.length === 0) return false
1038
+ const accounts = (block as { accounts?: unknown }).accounts
1039
+ if (!isObjectRecord(accounts)) return false
1040
+ const account = accounts[current]
1041
+ if (!isObjectRecord(account)) return false
1042
+ const username = (account as { username?: unknown }).username
1043
+ return typeof username === 'string' && username.length > 0
1044
+ }
1011
1045
  case 'line': {
1012
1046
  // A usable LINE block needs a current account whose record carries an
1013
1047
  // auth_token. Unlike KakaoTalk there are no renewal fields (email +
@@ -1115,6 +1149,7 @@ export type ChannelKind =
1115
1149
  | 'telegram-bot'
1116
1150
  | 'webex'
1117
1151
  | 'webex-bot'
1152
+ | 'instagram'
1118
1153
  | 'line'
1119
1154
  | 'kakaotalk'
1120
1155
  | 'github'
@@ -1131,6 +1166,7 @@ export const CHANNEL_KINDS: ReadonlyArray<ChannelKind> = [
1131
1166
  'telegram-bot',
1132
1167
  'webex',
1133
1168
  'webex-bot',
1169
+ 'instagram',
1134
1170
  'line',
1135
1171
  'kakaotalk',
1136
1172
  'github',
@@ -1138,6 +1174,7 @@ export const CHANNEL_KINDS: ReadonlyArray<ChannelKind> = [
1138
1174
 
1139
1175
  export type AddChannelStep =
1140
1176
  | 'line-auth'
1177
+ | 'instagram-auth'
1141
1178
  | 'kakaotalk-auth'
1142
1179
  | 'webex-auth'
1143
1180
  | 'discord-auth'
@@ -1151,6 +1188,8 @@ export type AddChannelStepEvent =
1151
1188
  | { step: 'config'; phase: 'done' }
1152
1189
  | { step: 'line-auth'; phase: 'start' }
1153
1190
  | { step: 'line-auth'; phase: 'done'; result: LineAuthResult }
1191
+ | { step: 'instagram-auth'; phase: 'start' }
1192
+ | { step: 'instagram-auth'; phase: 'done'; result: InstagramAuthResult }
1154
1193
  | { step: 'kakaotalk-auth'; phase: 'start' }
1155
1194
  | { step: 'kakaotalk-auth'; phase: 'done'; result: KakaotalkAuthResult }
1156
1195
  | { step: 'webex-auth'; phase: 'start' }
@@ -1178,6 +1217,7 @@ export type AddChannelOptions = {
1178
1217
  | { channel: 'telegram-bot'; telegramBotToken: string }
1179
1218
  | { channel: 'webex-bot'; webexBotToken: string }
1180
1219
  | { channel: 'webex'; runWebexAuth: WebexAuthRunner }
1220
+ | { channel: 'instagram'; runInstagramAuth: InstagramAuthRunner }
1181
1221
  | { channel: 'line'; runLineAuth: LineAuthRunner }
1182
1222
  | { channel: 'kakaotalk'; runKakaotalkAuth: KakaotalkAuthRunner }
1183
1223
  | {
@@ -1215,6 +1255,13 @@ export async function runAddChannel(options: AddChannelOptions): Promise<void> {
1215
1255
  if (!result.ok) throw new Error(`LINE authentication failed: ${result.reason}`)
1216
1256
  }
1217
1257
 
1258
+ if (options.channel === 'instagram') {
1259
+ emit({ step: 'instagram-auth', phase: 'start' })
1260
+ const result = await options.runInstagramAuth({ cwd: options.cwd })
1261
+ emit({ step: 'instagram-auth', phase: 'done', result })
1262
+ if (!result.ok) throw new Error(`Instagram authentication failed: ${result.reason}`)
1263
+ }
1264
+
1218
1265
  if (options.channel === 'kakaotalk') {
1219
1266
  emit({ step: 'kakaotalk-auth', phase: 'start' })
1220
1267
  const result = await options.runKakaotalkAuth({ cwd: options.cwd })
@@ -1324,6 +1371,8 @@ function channelSecretsFromOptions(options: AddChannelOptions): ChannelSecrets {
1324
1371
  return { token: options.webexBotToken }
1325
1372
  case 'webex':
1326
1373
  return {}
1374
+ case 'instagram':
1375
+ return {}
1327
1376
  case 'line':
1328
1377
  // LINE auth writes its structured account block directly to
1329
1378
  // secrets.json#channels.line before config mutation.