typeclaw 0.40.0 → 0.42.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 (61) hide show
  1. package/README.md +3 -2
  2. package/auth.schema.json +57 -0
  3. package/package.json +2 -2
  4. package/secrets.schema.json +57 -0
  5. package/src/agent/index.ts +10 -6
  6. package/src/agent/multimodal/look-at.ts +87 -0
  7. package/src/agent/session-origin.ts +1 -0
  8. package/src/agent/tools/channel-history-render.ts +21 -0
  9. package/src/agent/tools/channel-history.ts +2 -17
  10. package/src/agent/tools/channel-read.ts +206 -0
  11. package/src/bundled-plugins/agent-browser/skills/agent-browser/SKILL.md +26 -2
  12. package/src/bundled-plugins/github-cli-auth/index.ts +25 -6
  13. package/src/bundled-plugins/memory/index.ts +10 -11
  14. package/src/bundled-plugins/memory/vector/hybrid.ts +73 -6
  15. package/src/bundled-plugins/memory/vector/index-on-write.ts +25 -20
  16. package/src/bundled-plugins/memory/vector/passages.ts +2 -24
  17. package/src/bundled-plugins/memory/vector/reference-index-on-write.ts +28 -23
  18. package/src/bundled-plugins/memory/vector/store.ts +2 -0
  19. package/src/bundled-plugins/memory/vector/truncation.ts +28 -0
  20. package/src/bundled-plugins/planner/planner.ts +4 -2
  21. package/src/bundled-plugins/reviewer/reviewer.ts +9 -1
  22. package/src/bundled-plugins/tool-result-cap/README.md +10 -1
  23. package/src/bundled-plugins/tool-result-cap/cap-result.ts +8 -0
  24. package/src/channels/adapters/discord-bot.ts +112 -0
  25. package/src/channels/adapters/instagram-channel-resolver.ts +113 -0
  26. package/src/channels/adapters/instagram-classify.ts +69 -0
  27. package/src/channels/adapters/instagram-format.ts +8 -0
  28. package/src/channels/adapters/instagram.ts +346 -0
  29. package/src/channels/adapters/kakaotalk-classify.ts +31 -6
  30. package/src/channels/adapters/kakaotalk.ts +1 -1
  31. package/src/channels/adapters/slack-bot.ts +147 -0
  32. package/src/channels/manager.ts +60 -2
  33. package/src/channels/router.ts +64 -0
  34. package/src/channels/schema.ts +5 -0
  35. package/src/channels/types.ts +46 -0
  36. package/src/cli/channel.ts +76 -1
  37. package/src/cli/init.ts +1 -0
  38. package/src/cli/status.ts +37 -14
  39. package/src/config/channels-mutation.ts +2 -1
  40. package/src/doctor/channel-checks.ts +28 -0
  41. package/src/hostd/daemon.ts +59 -19
  42. package/src/hostd/kakao-renewal-manager.ts +35 -10
  43. package/src/hostd/protocol.ts +2 -0
  44. package/src/hostd/tailscale.ts +41 -5
  45. package/src/hostd/webex-renewal-manager.ts +13 -4
  46. package/src/init/index.ts +50 -1
  47. package/src/init/instagram-auth.ts +134 -0
  48. package/src/init/run-owner-claim.ts +1 -0
  49. package/src/permissions/match-rule.ts +1 -1
  50. package/src/permissions/resolve.ts +1 -0
  51. package/src/plugin/index.ts +1 -0
  52. package/src/plugin/manager.ts +14 -0
  53. package/src/plugin/registry.ts +12 -0
  54. package/src/plugin/types.ts +4 -0
  55. package/src/role-claim/match-rule.ts +2 -1
  56. package/src/run/index.ts +46 -20
  57. package/src/secrets/instagram-store.ts +112 -0
  58. package/src/secrets/schema.ts +18 -0
  59. package/src/skills/typeclaw-channel-instagram/SKILL.md +30 -0
  60. package/src/test-helpers/rm-temp-dir.ts +24 -0
  61. package/typeclaw.schema.json +161 -1
@@ -4,6 +4,7 @@ import { join } from 'node:path'
4
4
  import type { PermissionService } from '@/permissions'
5
5
  import type { GithubSecretsBlock } from '@/secrets'
6
6
  import { SecretsDiscordCredentialStore } from '@/secrets/discord-store'
7
+ import { SecretsInstagramCredentialStore } from '@/secrets/instagram-store'
7
8
  import { SecretsKakaoCredentialStore } from '@/secrets/kakao-store'
8
9
  import { SecretsLineCredentialStore } from '@/secrets/line-store'
9
10
  import { SecretsSlackCredentialStore } from '@/secrets/slack-store'
@@ -14,6 +15,7 @@ import type { Stream } from '@/stream'
14
15
  import { createDiscordAdapter, type DiscordAdapter } from './adapters/discord'
15
16
  import { createDiscordBotAdapter, type DiscordBotAdapter } from './adapters/discord-bot'
16
17
  import { createGithubAdapter, type GithubAdapter } from './adapters/github'
18
+ import { createInstagramAdapter, type InstagramAdapter } from './adapters/instagram'
17
19
  import { createKakaotalkAdapter, type KakaotalkAdapter } from './adapters/kakaotalk'
18
20
  import { createLineAdapter, type LineAdapter } from './adapters/line'
19
21
  import { createSlackAdapter, type SlackAdapter } from './adapters/slack'
@@ -75,6 +77,7 @@ export type ChannelManagerOptions = {
75
77
  createDiscordAdapter?: typeof createDiscordBotAdapter
76
78
  createDiscordUserAdapter?: typeof createDiscordAdapter
77
79
  createGithubAdapter?: typeof createGithubAdapter
80
+ createInstagramAdapter?: typeof createInstagramAdapter
78
81
  createKakaotalkAdapter?: typeof createKakaotalkAdapter
79
82
  createLineAdapter?: typeof createLineAdapter
80
83
  createSlackAdapter?: typeof createSlackBotAdapter
@@ -145,6 +148,7 @@ type AnyAdapter =
145
148
  | DiscordAdapter
146
149
  | DiscordBotAdapter
147
150
  | GithubAdapter
151
+ | InstagramAdapter
148
152
  | LineAdapter
149
153
  | KakaotalkAdapter
150
154
  | SlackAdapter
@@ -188,6 +192,7 @@ export function createChannelManager(options: ChannelManagerOptions): ChannelMan
188
192
  const createDiscordBot = options.createDiscordAdapter ?? createDiscordBotAdapter
189
193
  const createDiscordUser = options.createDiscordUserAdapter ?? createDiscordAdapter
190
194
  const createGithub = options.createGithubAdapter ?? createGithubAdapter
195
+ const createInstagram = options.createInstagramAdapter ?? createInstagramAdapter
191
196
  const createKakaotalk = options.createKakaotalkAdapter ?? createKakaotalkAdapter
192
197
  const createLine = options.createLineAdapter ?? createLineAdapter
193
198
  const createSlackBot = options.createSlackAdapter ?? createSlackBotAdapter
@@ -219,6 +224,7 @@ export function createChannelManager(options: ChannelManagerOptions): ChannelMan
219
224
 
220
225
  const buildCredentialSignature = (name: AdapterId): { signature: string; missing: string[] } => {
221
226
  if (name === 'line') return buildLineSignature(options.agentDir)
227
+ if (name === 'instagram') return buildInstagramSignature(options.agentDir)
222
228
  if (name === 'kakaotalk') return buildKakaotalkSignature(options.agentDir)
223
229
  if (name === 'webex') return buildWebexSignature(options.agentDir)
224
230
  if (name === 'slack') return buildSlackSignature(options.agentDir)
@@ -271,6 +277,17 @@ export function createChannelManager(options: ChannelManagerOptions): ChannelMan
271
277
  credentialsStore,
272
278
  })
273
279
  }
280
+ if (name === 'instagram') {
281
+ const credentialsStore = createContainerInstagramCredentialStore(options.agentDir, env)
282
+ if (credentialsStore === null) return null
283
+ return createInstagram({
284
+ router,
285
+ configRef: () => options.channelsConfigRef()[name] ?? cfg,
286
+ logger,
287
+ selfAliasesRef: () => router.getSelfAliases(),
288
+ credentialsStore,
289
+ })
290
+ }
274
291
  if (name === 'kakaotalk') {
275
292
  const credentialsStore = createContainerKakaoCredentialStore(options.agentDir, env)
276
293
  if (credentialsStore === null) return null
@@ -522,7 +539,12 @@ export function createChannelManager(options: ChannelManagerOptions): ChannelMan
522
539
  stopped.push(name)
523
540
  } else if (signature !== current.credentialSignature) {
524
541
  const reason =
525
- name === 'kakaotalk' || name === 'line' || name === 'webex' || name === 'slack' || name === 'discord'
542
+ name === 'kakaotalk' ||
543
+ name === 'line' ||
544
+ name === 'instagram' ||
545
+ name === 'webex' ||
546
+ name === 'slack' ||
547
+ name === 'discord'
526
548
  ? 'credential rotation'
527
549
  : 'token rotation'
528
550
  restartRequired.push(`${name} (${reason})`)
@@ -539,7 +561,7 @@ export function createChannelManager(options: ChannelManagerOptions): ChannelMan
539
561
  // secrets.json#channels.<adapter>, not in env, so they go through
540
562
  // structured-block signatures instead.
541
563
  const TOKEN_ENV: Record<
542
- Exclude<AdapterId, 'kakaotalk' | 'line' | 'github' | 'webex' | 'slack' | 'discord'>,
564
+ Exclude<AdapterId, 'kakaotalk' | 'line' | 'instagram' | 'github' | 'webex' | 'slack' | 'discord'>,
543
565
  readonly string[]
544
566
  > = {
545
567
  'discord-bot': ['DISCORD_BOT_TOKEN'],
@@ -700,6 +722,33 @@ function buildLineSignature(agentDir: string): { signature: string; missing: str
700
722
  }
701
723
  }
702
724
 
725
+ function createContainerInstagramCredentialStore(
726
+ agentDir: string,
727
+ env: NodeJS.ProcessEnv,
728
+ ): SecretsInstagramCredentialStore | null {
729
+ const creds = resolveHostdContainerCredentials(env)
730
+ if (creds === null) return null
731
+ return new SecretsInstagramCredentialStore({
732
+ mode: 'container',
733
+ secretsPath: join(agentDir, 'secrets.json'),
734
+ ...creds,
735
+ })
736
+ }
737
+
738
+ function buildInstagramSignature(agentDir: string): { signature: string; missing: string[] } {
739
+ const path = join(agentDir, 'secrets.json')
740
+ try {
741
+ const block = new SecretsBackend(path).tryReadChannelsSync()?.instagram
742
+ if (!isInstagramCredentialBlock(block)) {
743
+ return { signature: '', missing: ['secrets.json#channels.instagram'] }
744
+ }
745
+ const digest = createHash('sha256').update(JSON.stringify(block)).digest('hex')
746
+ return { signature: `secrets.json#channels.instagram@sha256:${digest}`, missing: [] }
747
+ } catch (err) {
748
+ return { signature: '', missing: [`secrets.json#channels.instagram (${describe(err)})`] }
749
+ }
750
+ }
751
+
703
752
  function buildGithubSignature(agentDir: string): { signature: string; missing: string[] } {
704
753
  const block = readGithubSecrets(agentDir)
705
754
  if (block === null) return { signature: '', missing: ['secrets.json#channels.github'] }
@@ -744,6 +793,15 @@ function isLineCredentialBlock(value: unknown): value is { accounts: Record<stri
744
793
  )
745
794
  }
746
795
 
796
+ function isInstagramCredentialBlock(value: unknown): value is { accounts: Record<string, unknown> } {
797
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) return false
798
+ if (!('accounts' in value)) return false
799
+ const accounts = value.accounts
800
+ return (
801
+ typeof accounts === 'object' && accounts !== null && !Array.isArray(accounts) && Object.keys(accounts).length > 0
802
+ )
803
+ }
804
+
747
805
  function isSlackCredentialBlock(value: unknown): value is { accounts: Record<string, unknown> } {
748
806
  if (typeof value !== 'object' || value === null || Array.isArray(value)) return false
749
807
  if (!('accounts' in value)) return false
@@ -74,10 +74,16 @@ import type {
74
74
  FetchAttachmentResult,
75
75
  FetchHistoryArgs,
76
76
  FetchHistoryResult,
77
+ GetMessageArgs,
78
+ GetMessageResult,
77
79
  HistoryCallback,
78
80
  InboundAttachment,
79
81
  InboundMessage,
80
82
  InboundReferenceContext,
83
+ ListCallback,
84
+ ListChannelsArgs,
85
+ ListChannelsResult,
86
+ MessageGetCallback,
81
87
  RemoveReactionCallback,
82
88
  RemoveReactionRequest,
83
89
  OutboundCallback,
@@ -1049,6 +1055,16 @@ export type ChannelRouter = {
1049
1055
  registerHistory: (adapter: ChannelKey['adapter'], cb: HistoryCallback) => void
1050
1056
  unregisterHistory: (adapter: ChannelKey['adapter'], cb: HistoryCallback) => void
1051
1057
  fetchHistory: (adapter: ChannelKey['adapter'], args: FetchHistoryArgs) => Promise<FetchHistoryResult>
1058
+ // Single-message-get and channel-list are opt-in per adapter and last-write-
1059
+ // wins (one bot account per adapter). When unregistered, `getMessage` /
1060
+ // `listChannels` answer `code: 'not-supported'`, matching `fetchHistory`'s
1061
+ // 'history-not-supported' fallback.
1062
+ registerMessageGet: (adapter: ChannelKey['adapter'], cb: MessageGetCallback) => void
1063
+ unregisterMessageGet: (adapter: ChannelKey['adapter'], cb: MessageGetCallback) => void
1064
+ getMessage: (adapter: ChannelKey['adapter'], args: GetMessageArgs) => Promise<GetMessageResult>
1065
+ registerList: (adapter: ChannelKey['adapter'], cb: ListCallback) => void
1066
+ unregisterList: (adapter: ChannelKey['adapter'], cb: ListCallback) => void
1067
+ listChannels: (adapter: ChannelKey['adapter'], args: ListChannelsArgs) => Promise<ListChannelsResult>
1052
1068
  registerFetchAttachment: (adapter: ChannelKey['adapter'], cb: FetchAttachmentCallback) => void
1053
1069
  unregisterFetchAttachment: (adapter: ChannelKey['adapter'], cb: FetchAttachmentCallback) => void
1054
1070
  fetchAttachment: (adapter: ChannelKey['adapter'], args: FetchAttachmentArgs) => Promise<FetchAttachmentResult>
@@ -1385,6 +1401,8 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
1385
1401
  const selfIdentityResolvers = new Map<ChannelKey['adapter'], ChannelSelfIdentityResolver>()
1386
1402
  const membershipCaches = new Map<ChannelKey['adapter'], MembershipCache>()
1387
1403
  const historyCallbacks = new Map<ChannelKey['adapter'], Set<HistoryCallback>>()
1404
+ const messageGetCallbacks = new Map<ChannelKey['adapter'], MessageGetCallback>()
1405
+ const listCallbacks = new Map<ChannelKey['adapter'], ListCallback>()
1388
1406
  const fetchAttachmentCallbacks = new Map<ChannelKey['adapter'], Set<FetchAttachmentCallback>>()
1389
1407
  const reviewThreadResolvers = new Map<ChannelKey['adapter'], ReviewThreadResolver>()
1390
1408
  const reviewStateResolvers = new Map<ChannelKey['adapter'], ReviewStateResolver>()
@@ -3374,6 +3392,44 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
3374
3392
  return lastError
3375
3393
  }
3376
3394
 
3395
+ const registerMessageGet = (adapter: ChannelKey['adapter'], cb: MessageGetCallback): void => {
3396
+ messageGetCallbacks.set(adapter, cb)
3397
+ }
3398
+
3399
+ const unregisterMessageGet = (adapter: ChannelKey['adapter'], cb: MessageGetCallback): void => {
3400
+ if (messageGetCallbacks.get(adapter) === cb) messageGetCallbacks.delete(adapter)
3401
+ }
3402
+
3403
+ const getMessage = async (adapter: ChannelKey['adapter'], args: GetMessageArgs): Promise<GetMessageResult> => {
3404
+ const cb = messageGetCallbacks.get(adapter)
3405
+ if (cb === undefined) return { ok: false, error: 'message-get-not-supported', code: 'not-supported' }
3406
+ try {
3407
+ return await raceWithTimeout(cb(args), fetchHistoryTimeoutMs, `[channels] ${adapter} message get`)
3408
+ } catch (err) {
3409
+ logger.warn(`[channels] message get threw for ${adapter}: ${describe(err)}`)
3410
+ return { ok: false, error: 'message-get-not-supported', code: 'not-supported' }
3411
+ }
3412
+ }
3413
+
3414
+ const registerList = (adapter: ChannelKey['adapter'], cb: ListCallback): void => {
3415
+ listCallbacks.set(adapter, cb)
3416
+ }
3417
+
3418
+ const unregisterList = (adapter: ChannelKey['adapter'], cb: ListCallback): void => {
3419
+ if (listCallbacks.get(adapter) === cb) listCallbacks.delete(adapter)
3420
+ }
3421
+
3422
+ const listChannels = async (adapter: ChannelKey['adapter'], args: ListChannelsArgs): Promise<ListChannelsResult> => {
3423
+ const cb = listCallbacks.get(adapter)
3424
+ if (cb === undefined) return { ok: false, error: 'list-not-supported', code: 'not-supported' }
3425
+ try {
3426
+ return await raceWithTimeout(cb(args), fetchHistoryTimeoutMs, `[channels] ${adapter} list channels`)
3427
+ } catch (err) {
3428
+ logger.warn(`[channels] list channels threw for ${adapter}: ${describe(err)}`)
3429
+ return { ok: false, error: 'list-not-supported', code: 'not-supported' }
3430
+ }
3431
+ }
3432
+
3377
3433
  const registerFetchAttachment = (adapter: ChannelKey['adapter'], cb: FetchAttachmentCallback): void => {
3378
3434
  let set = fetchAttachmentCallbacks.get(adapter)
3379
3435
  if (!set) {
@@ -4798,6 +4854,12 @@ export function createChannelRouter(options: CreateChannelRouterOptions): Channe
4798
4854
  registerHistory,
4799
4855
  unregisterHistory,
4800
4856
  fetchHistory,
4857
+ registerMessageGet,
4858
+ unregisterMessageGet,
4859
+ getMessage,
4860
+ registerList,
4861
+ unregisterList,
4862
+ listChannels,
4801
4863
  registerFetchAttachment,
4802
4864
  unregisterFetchAttachment,
4803
4865
  fetchAttachment,
@@ -5158,6 +5220,7 @@ export function formatAuthorAttribution(adapter: AdapterId, authorId: string, au
5158
5220
  case 'telegram-bot':
5159
5221
  case 'webex':
5160
5222
  case 'webex-bot':
5223
+ case 'instagram':
5161
5224
  case 'line':
5162
5225
  case 'kakaotalk':
5163
5226
  return hasDisplayName ? `${displayName} <${id}>` : id
@@ -5190,6 +5253,7 @@ function formatAuthorReference(adapter: AdapterId, authorId: string, authorName:
5190
5253
  case 'telegram-bot':
5191
5254
  case 'webex':
5192
5255
  case 'webex-bot':
5256
+ case 'instagram':
5193
5257
  case 'line':
5194
5258
  case 'kakaotalk':
5195
5259
  return displayName
@@ -4,6 +4,7 @@ export const ADAPTER_IDS = [
4
4
  'discord',
5
5
  'discord-bot',
6
6
  'github',
7
+ 'instagram',
7
8
  'line',
8
9
  'kakaotalk',
9
10
  'slack',
@@ -266,6 +267,10 @@ export const channelsSchema = z
266
267
  discord: adapterSchema.optional(),
267
268
  'discord-bot': adapterSchema.optional(),
268
269
  github: githubChannelSchema.optional(),
270
+ // Instagram is a personal-account channel: plain-text sends only,
271
+ // alias-only engagement in groups, and DM/group buckets backed by
272
+ // secrets.json#channels.instagram credentials rather than env vars.
273
+ instagram: adapterSchema.optional(),
269
274
  // LINE is a personal-account channel like KakaoTalk: plain-text only,
270
275
  // alias-only engagement (no native @-mention), credentials in
271
276
  // secrets.json#channels.line (not env). Unlike KakaoTalk it has no
@@ -358,6 +358,52 @@ export type FetchHistoryResult =
358
358
  // 'history-not-supported' for those.
359
359
  export type HistoryCallback = (args: FetchHistoryArgs) => Promise<FetchHistoryResult>
360
360
 
361
+ // Fetch a single message by its platform id from an arbitrary chat. Backs the
362
+ // `channel_read` tool's `mode: "message"`. `thread` narrows the lookup on
363
+ // platforms where a message id is only addressable within a thread (Slack
364
+ // thread replies); pass null for channel-root lookups. Reuses
365
+ // `ChannelHistoryMessage` as the result shape — a single message is just a
366
+ // one-element history with the same author/ts/isBot fields.
367
+ export type GetMessageArgs = {
368
+ chat: string
369
+ thread: string | null
370
+ messageId: string
371
+ }
372
+
373
+ export type GetMessageResult =
374
+ | { ok: true; message: ChannelHistoryMessage }
375
+ // `code: 'not-found'` is an expected miss (deleted/wrong id) the tool surfaces
376
+ // as a soft error; `code: 'not-supported'` means no adapter callback is
377
+ // registered, mirroring `fetchHistory`'s 'history-not-supported' contract.
378
+ | { ok: false; error: string; code?: 'not-found' | 'not-supported' }
379
+
380
+ export type MessageGetCallback = (args: GetMessageArgs) => Promise<GetMessageResult>
381
+
382
+ // One channel/chat the bot account can see, returned by `ListCallback`. `chat`
383
+ // is the id the agent passes back to `channel_read`/`channel_send`; `name` is a
384
+ // human label for the agent to recognize. `isMember` is best-effort — omitted
385
+ // when the adapter can't cheaply determine membership.
386
+ export type ChannelListEntry = {
387
+ chat: string
388
+ name: string
389
+ kind: 'channel' | 'dm' | 'group' | 'thread'
390
+ isMember?: boolean
391
+ }
392
+
393
+ export type ListChannelsArgs = {
394
+ workspace: string
395
+ limit: number
396
+ cursor?: string
397
+ }
398
+
399
+ export type ListChannelsResult =
400
+ | { ok: true; entries: ChannelListEntry[]; nextCursor?: string }
401
+ | { ok: false; error: string; code?: 'not-supported' }
402
+
403
+ // Backs the `channel_read` tool's `mode: "list"`. Opt-in per adapter like
404
+ // history; the router answers 'list-not-supported' when none is registered.
405
+ export type ListCallback = (args: ListChannelsArgs) => Promise<ListChannelsResult>
406
+
361
407
  export type FetchAttachmentArgs = {
362
408
  ref: string
363
409
  filename?: string
@@ -30,12 +30,14 @@ import {
30
30
  type DiscordAuthResult,
31
31
  type GithubCredentialPatch,
32
32
  type GithubTunnelProvider,
33
+ type InstagramAuthResult,
33
34
  type KakaotalkAuthResult,
34
35
  type LineAuthResult,
35
36
  type SlackAuthResult,
36
37
  type WebexAuthResult,
37
38
  } from '@/init'
38
39
  import { runDiscordBootstrap } from '@/init/discord-auth'
40
+ import { runInstagramBootstrap } from '@/init/instagram-auth'
39
41
  import { runKakaotalkBootstrap } from '@/init/kakaotalk-auth'
40
42
  import { runLineBootstrap } from '@/init/line-auth'
41
43
  import { runSlackBootstrap } from '@/init/slack-auth'
@@ -55,6 +57,7 @@ const CHANNEL_LABELS: Record<ChannelKind, string> = {
55
57
  'telegram-bot': 'Telegram',
56
58
  webex: 'Webex (User)',
57
59
  'webex-bot': 'Webex',
60
+ instagram: 'Instagram',
58
61
  line: 'LINE',
59
62
  kakaotalk: 'KakaoTalk',
60
63
  github: 'GitHub',
@@ -160,6 +163,15 @@ const setSub = defineCommand({
160
163
  process.exit(1)
161
164
  }
162
165
 
166
+ if (args.adapter === 'instagram') {
167
+ console.error(
168
+ errorLine(
169
+ 'Instagram uses a username/password auth flow. Use `typeclaw channel reauth instagram` to rotate its credentials.',
170
+ ),
171
+ )
172
+ process.exit(1)
173
+ }
174
+
163
175
  const adapter =
164
176
  args.adapter === undefined
165
177
  ? await pickSettableAdapter(configured)
@@ -171,7 +183,7 @@ const setSub = defineCommand({
171
183
  },
172
184
  })
173
185
 
174
- const REAUTHABLE_ADAPTERS = ['line', 'kakaotalk', 'webex'] as const
186
+ const REAUTHABLE_ADAPTERS = ['line', 'instagram', 'kakaotalk', 'webex'] as const
175
187
  type ReauthableAdapter = (typeof REAUTHABLE_ADAPTERS)[number]
176
188
 
177
189
  const reauthSub = defineCommand({
@@ -441,6 +453,9 @@ async function runReauth(cwd: string, adapter: ReauthableAdapter): Promise<void>
441
453
  case 'line':
442
454
  await runLineReauth(cwd)
443
455
  return
456
+ case 'instagram':
457
+ await runInstagramReauth(cwd)
458
+ return
444
459
  case 'kakaotalk':
445
460
  await runKakaotalkReauth(cwd)
446
461
  return
@@ -450,6 +465,20 @@ async function runReauth(cwd: string, adapter: ReauthableAdapter): Promise<void>
450
465
  }
451
466
  }
452
467
 
468
+ async function runInstagramReauth(cwd: string): Promise<void> {
469
+ const creds = await promptInstagramCredentials()
470
+ const s = spinner()
471
+ s.start('Logging in to Instagram...')
472
+ const result = await runInstagramBootstrap({ username: creds.username, password: creds.password, agentDir: cwd })
473
+ if (!result.ok) {
474
+ s.stop(`Instagram login failed: ${result.reason}`)
475
+ process.exit(1)
476
+ }
477
+ s.stop('Instagram credentials refreshed in secrets.json.')
478
+
479
+ await maybePromptReauthRefresh(cwd, 'instagram')
480
+ }
481
+
453
482
  async function runLineReauth(cwd: string): Promise<void> {
454
483
  const holder: LineAuthSpinnerHolder = { current: null }
455
484
  const login = await promptLineLogin(holderSpinnerControl(holder))
@@ -940,6 +969,7 @@ type CollectedCredentials =
940
969
  | { channel: 'telegram-bot'; telegramBotToken: string }
941
970
  | { channel: 'webex'; runWebexAuth: (options: { cwd: string }) => Promise<WebexAuthResult> }
942
971
  | { channel: 'webex-bot'; webexBotToken: string }
972
+ | { channel: 'instagram'; runInstagramAuth: (options: { cwd: string }) => Promise<InstagramAuthResult> }
943
973
  | { channel: 'line'; runLineAuth: (options: { cwd: string }) => Promise<LineAuthResult> }
944
974
  | { channel: 'kakaotalk'; runKakaotalkAuth: (options: { cwd: string }) => Promise<KakaotalkAuthResult> }
945
975
  | {
@@ -986,6 +1016,14 @@ async function collectCredentials(
986
1016
  }
987
1017
  case 'webex-bot':
988
1018
  return { channel, webexBotToken: await promptWebexToken() }
1019
+ case 'instagram': {
1020
+ const creds = await promptInstagramCredentials()
1021
+ return {
1022
+ channel,
1023
+ runInstagramAuth: ({ cwd: agentDir }) =>
1024
+ runInstagramBootstrap({ username: creds.username, password: creds.password, agentDir }),
1025
+ }
1026
+ }
989
1027
  case 'line': {
990
1028
  const login = await promptLineLogin(lineSpinnerHolder ? holderSpinnerControl(lineSpinnerHolder) : undefined)
991
1029
  return {
@@ -1515,6 +1553,34 @@ async function promptWebexCredentials(
1515
1553
  return { email, password: pwd }
1516
1554
  }
1517
1555
 
1556
+ async function promptInstagramCredentials(): Promise<{ username: string; password: string }> {
1557
+ note(
1558
+ [
1559
+ 'Instagram authentication uses a personal account.',
1560
+ 'Messages will be sent and received under this account.',
1561
+ '2FA/checkpointed accounts are not supported; use a dedicated account without those challenges.',
1562
+ ].join('\n'),
1563
+ 'About to log in to Instagram',
1564
+ )
1565
+ const username = await text({
1566
+ message: 'Instagram username',
1567
+ validate: (value) => (value && value.length > 0 ? undefined : 'Username is required'),
1568
+ })
1569
+ if (isCancel(username)) {
1570
+ cancel('Aborted.')
1571
+ process.exit(0)
1572
+ }
1573
+ const pwd = await password({
1574
+ message: 'Instagram password',
1575
+ validate: (value) => (value && value.length > 0 ? undefined : 'Password is required'),
1576
+ })
1577
+ if (isCancel(pwd)) {
1578
+ cancel('Aborted.')
1579
+ process.exit(0)
1580
+ }
1581
+ return { username, password: pwd }
1582
+ }
1583
+
1518
1584
  type LinePromptResult =
1519
1585
  | { method: 'qr'; callbacks: { onQRUrl: (url: string) => Promise<void>; onPincode: (pin: string) => void } }
1520
1586
  | {
@@ -1681,6 +1747,9 @@ function reportProgress(
1681
1747
  if (lineSpinnerHolder) lineSpinnerHolder.current = null
1682
1748
  s.stop(reportLineAuth(event.result))
1683
1749
  break
1750
+ case 'instagram-auth':
1751
+ s.stop(reportInstagramAuth(event.result))
1752
+ break
1684
1753
  case 'kakaotalk-auth':
1685
1754
  s.stop(reportKakaotalkAuth(event.result))
1686
1755
  break
@@ -1708,6 +1777,7 @@ function reportProgress(
1708
1777
 
1709
1778
  const START_MESSAGES: Record<AddChannelStepEvent['step'], string> = {
1710
1779
  'line-auth': 'Logging in to LINE...',
1780
+ 'instagram-auth': 'Logging in to Instagram...',
1711
1781
  'kakaotalk-auth': 'Logging in to KakaoTalk...',
1712
1782
  'webex-auth': 'Logging in to Webex...',
1713
1783
  'discord-auth': 'Logging in to Discord...',
@@ -1742,6 +1812,11 @@ function reportLineAuth(result: LineAuthResult): string {
1742
1812
  return `LINE login failed: ${result.reason}`
1743
1813
  }
1744
1814
 
1815
+ function reportInstagramAuth(result: InstagramAuthResult): string {
1816
+ if (result.ok) return 'Instagram credentials saved to secrets.json.'
1817
+ return `Instagram login failed: ${result.reason}`
1818
+ }
1819
+
1745
1820
  async function maybePromptRestart(
1746
1821
  cwd: string,
1747
1822
  channel: ChannelKind,
package/src/cli/init.ts CHANGED
@@ -2047,6 +2047,7 @@ const START_MESSAGES: Record<Exclude<InitStep, 'hatching'>, string> = {
2047
2047
  scaffold: 'Laying the egg...',
2048
2048
  'slack-auth': 'Logging in to Slack...',
2049
2049
  'discord-auth': 'Logging in to Discord...',
2050
+ 'instagram-auth': 'Logging in to Instagram...',
2050
2051
  'kakaotalk-auth': 'Logging in to KakaoTalk...',
2051
2052
  'webex-auth': 'Logging in to Webex...',
2052
2053
  'github-webhooks': 'Installing GitHub repository webhooks...',
package/src/cli/status.ts CHANGED
@@ -2,12 +2,12 @@ import { styleText } from 'node:util'
2
2
 
3
3
  import { defineCommand } from 'citty'
4
4
 
5
- import { status as containerStatus, type ContainerStatus } from '@/container'
5
+ import { status as containerStatus, type ContainerStatus, type DockerExec } from '@/container'
6
6
  import { isDaemonReachable, send } from '@/hostd'
7
7
  import type { StatusResult } from '@/hostd'
8
8
  import { findAgentDir } from '@/init'
9
9
 
10
- import { preflightDocker, printDockerGuidance } from './docker-preflight'
10
+ import { type DockerPreflightResult, preflightDocker, printDockerGuidance } from './docker-preflight'
11
11
 
12
12
  export type HostdStatus =
13
13
  | { kind: 'unreachable' }
@@ -26,21 +26,44 @@ export const statusCommand = defineCommand({
26
26
  description: 'show the agent container and host daemon status (host stage)',
27
27
  },
28
28
  async run() {
29
- const cwd = findAgentDir(process.cwd()) ?? process.cwd()
29
+ await runStatus()
30
+ },
31
+ })
30
32
 
31
- const preflight = await preflightDocker()
32
- if (!preflight.ok) {
33
- printDockerGuidance(preflight)
34
- process.exit(1)
35
- }
33
+ // Injectable seam so the render/flow can be exercised without spawning the real
34
+ // Docker CLI. The broken-config path otherwise pays a ~70s Docker Desktop
35
+ // cold-start on the first `docker info` of a Windows CI run; injecting the
36
+ // preflight + exec keeps the test on the pure flow it actually cares about.
37
+ export type RunStatusDeps = {
38
+ cwd?: string
39
+ preflight?: () => Promise<DockerPreflightResult>
40
+ exec?: DockerExec
41
+ fetchHostd?: (containerName: string) => Promise<HostdStatus>
42
+ write?: (text: string) => void
43
+ onDockerUnavailable?: (failure: Extract<DockerPreflightResult, { ok: false }>) => void
44
+ }
36
45
 
37
- const container = await containerStatus({ cwd })
38
- const hostd = await fetchHostdStatus(container.containerName)
46
+ export async function runStatus(deps: RunStatusDeps = {}): Promise<void> {
47
+ const cwd = deps.cwd ?? findAgentDir(process.cwd()) ?? process.cwd()
39
48
 
40
- const useColor = Boolean(process.stdout.isTTY) && process.env.NO_COLOR === undefined
41
- process.stdout.write(`${formatStatus({ cwd, container, hostd }, { useColor })}\n`)
42
- },
43
- })
49
+ const preflight = await (deps.preflight ?? preflightDocker)()
50
+ if (!preflight.ok) {
51
+ ;(deps.onDockerUnavailable ?? defaultOnDockerUnavailable)(preflight)
52
+ return
53
+ }
54
+
55
+ const container = await containerStatus({ cwd, exec: deps.exec })
56
+ const hostd = await (deps.fetchHostd ?? fetchHostdStatus)(container.containerName)
57
+
58
+ const useColor = Boolean(process.stdout.isTTY) && process.env.NO_COLOR === undefined
59
+ const write = deps.write ?? ((text: string) => process.stdout.write(text))
60
+ write(`${formatStatus({ cwd, container, hostd }, { useColor })}\n`)
61
+ }
62
+
63
+ function defaultOnDockerUnavailable(failure: Extract<DockerPreflightResult, { ok: false }>): never {
64
+ printDockerGuidance(failure)
65
+ process.exit(1)
66
+ }
44
67
 
45
68
  async function fetchHostdStatus(containerName: string): Promise<HostdStatus> {
46
69
  if (!(await isDaemonReachable())) return { kind: 'unreachable' }
@@ -15,6 +15,7 @@ export const CHANNEL_KINDS = [
15
15
  'telegram-bot',
16
16
  'webex',
17
17
  'webex-bot',
18
+ 'instagram',
18
19
  'line',
19
20
  'kakaotalk',
20
21
  'github',
@@ -189,7 +190,7 @@ function buildDetail(kind: ChannelKind, channelConfig: unknown, secretsBlock: un
189
190
  const repos = isObjectRecord(channelConfig) && Array.isArray(channelConfig.repos) ? channelConfig.repos.length : 0
190
191
  return { detail: `${repos} repo${repos === 1 ? '' : 's'}` }
191
192
  }
192
- if (kind === 'line' || kind === 'kakaotalk' || kind === 'webex' || kind === 'discord') {
193
+ if (kind === 'line' || kind === 'instagram' || kind === 'kakaotalk' || kind === 'webex' || kind === 'discord') {
193
194
  if (!isObjectRecord(secretsBlock)) return {}
194
195
  const accounts = isObjectRecord(secretsBlock.accounts) ? Object.keys(secretsBlock.accounts).length : 0
195
196
  const current = typeof secretsBlock.currentAccount === 'string' ? secretsBlock.currentAccount : undefined
@@ -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',