typeclaw 0.39.2 → 0.39.4

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 (102) hide show
  1. package/auth.schema.json +110 -0
  2. package/package.json +2 -2
  3. package/secrets.schema.json +110 -0
  4. package/src/agent/index.ts +39 -18
  5. package/src/agent/model-fallback.ts +13 -4
  6. package/src/agent/plugin-tools.ts +12 -12
  7. package/src/agent/provider-error.ts +36 -1
  8. package/src/agent/session-origin.ts +2 -0
  9. package/src/agent/subagents.ts +29 -2
  10. package/src/agent/throttle-circuit.ts +50 -0
  11. package/src/agent/todo/store.ts +21 -1
  12. package/src/agent/tools/channel-reply.ts +18 -5
  13. package/src/agent/tools/channel-send.ts +13 -2
  14. package/src/agent/turn-runner.ts +162 -0
  15. package/src/bundled-plugins/doc-render/render.ts +2 -2
  16. package/src/bundled-plugins/github-cli-auth/approve-idempotency.ts +40 -18
  17. package/src/bundled-plugins/memory/README.md +12 -12
  18. package/src/bundled-plugins/memory/append-tool.ts +58 -6
  19. package/src/bundled-plugins/memory/dreaming.ts +1 -1
  20. package/src/bundled-plugins/memory/fragment-parser.ts +10 -3
  21. package/src/bundled-plugins/memory/load-memory.ts +28 -2
  22. package/src/bundled-plugins/memory/memory-logger.ts +14 -2
  23. package/src/bundled-plugins/memory/search-tool.ts +50 -7
  24. package/src/bundled-plugins/memory/stream-events.ts +23 -0
  25. package/src/bundled-plugins/memory/vector/hybrid.ts +9 -2
  26. package/src/bundled-plugins/security/index.ts +24 -1
  27. package/src/bundled-plugins/security/policies/cron-promotion.ts +94 -62
  28. package/src/bundled-plugins/security/policies/plugin-addition.ts +2 -4
  29. package/src/bundled-plugins/security/policies/role-promotion.ts +2 -4
  30. package/src/channels/adapters/discord-author-resolver.ts +52 -0
  31. package/src/channels/adapters/discord-bot.ts +1 -1
  32. package/src/channels/adapters/discord-channel-resolver.ts +44 -0
  33. package/src/channels/adapters/discord-classify.ts +121 -0
  34. package/src/channels/adapters/discord-reactions.ts +138 -0
  35. package/src/channels/adapters/discord.ts +416 -0
  36. package/src/channels/adapters/github/outbound.ts +23 -4
  37. package/src/channels/adapters/kakaotalk.ts +8 -1
  38. package/src/channels/adapters/line.ts +1 -1
  39. package/src/channels/adapters/slack-author-resolver.ts +54 -0
  40. package/src/channels/adapters/slack-bot.ts +3 -1
  41. package/src/channels/adapters/slack-channel-resolver.ts +49 -0
  42. package/src/channels/adapters/slack-classify.ts +83 -0
  43. package/src/channels/adapters/slack-reactions.ts +126 -0
  44. package/src/channels/adapters/slack.ts +416 -0
  45. package/src/channels/adapters/telegram-bot.ts +2 -1
  46. package/src/channels/adapters/webex-bot.ts +31 -27
  47. package/src/channels/adapters/webex-prefetch-limiter.ts +120 -0
  48. package/src/channels/adapters/webex.ts +81 -31
  49. package/src/channels/github-review-turn-ledger.ts +32 -0
  50. package/src/channels/github-verdict-activity.ts +60 -0
  51. package/src/channels/index.ts +6 -0
  52. package/src/channels/manager.ts +168 -37
  53. package/src/channels/pr-verdict-activity-bridge.ts +43 -0
  54. package/src/channels/router.ts +295 -13
  55. package/src/channels/schema.ts +4 -0
  56. package/src/channels/types.ts +25 -2
  57. package/src/cli/builtins.ts +6 -31
  58. package/src/cli/channel.ts +170 -18
  59. package/src/cli/command-meta.ts +93 -0
  60. package/src/cli/help.ts +24 -0
  61. package/src/cli/index.ts +45 -10
  62. package/src/cli/init.ts +2 -0
  63. package/src/cli/update-check.ts +14 -0
  64. package/src/cli/update-notify.ts +91 -0
  65. package/src/cli/update-suppression.ts +19 -0
  66. package/src/config/channels-mutation.ts +3 -1
  67. package/src/config/config.ts +78 -1
  68. package/src/config/index.ts +1 -0
  69. package/src/container/start.ts +52 -8
  70. package/src/doctor/channel-checks.ts +57 -3
  71. package/src/hostd/daemon.ts +77 -31
  72. package/src/hostd/index.ts +11 -1
  73. package/src/hostd/paths.ts +4 -0
  74. package/src/hostd/protocol.ts +15 -2
  75. package/src/hostd/spawn.ts +53 -19
  76. package/src/init/cli-version.ts +1 -1
  77. package/src/init/discord-auth.ts +50 -0
  78. package/src/init/index.ts +94 -4
  79. package/src/init/reconcile-plugin-deps.ts +30 -5
  80. package/src/init/run-owner-claim.ts +2 -0
  81. package/src/init/slack-auth.ts +51 -0
  82. package/src/mcp/manager.ts +94 -7
  83. package/src/mcp/tools.ts +7 -4
  84. package/src/permissions/permissions.ts +12 -0
  85. package/src/permissions/resolve.ts +2 -0
  86. package/src/role-claim/match-rule.ts +2 -0
  87. package/src/run/codex-fetch-observer.ts +11 -6
  88. package/src/run/index.ts +74 -29
  89. package/src/secrets/discord-store.ts +96 -0
  90. package/src/secrets/oauth-xai.ts +2 -2
  91. package/src/secrets/schema.ts +34 -0
  92. package/src/secrets/slack-store.ts +96 -0
  93. package/src/server/command-runner.ts +21 -0
  94. package/src/server/index.ts +27 -2
  95. package/src/skills/typeclaw-channels/SKILL.md +1 -1
  96. package/src/skills/typeclaw-config/SKILL.md +1 -0
  97. package/src/skills/typeclaw-cron/SKILL.md +20 -4
  98. package/src/skills/typeclaw-permissions/SKILL.md +18 -6
  99. package/src/tui/format.ts +0 -19
  100. package/src/tui/index.ts +2 -8
  101. package/src/update/check.ts +192 -0
  102. package/typeclaw.schema.json +332 -0
@@ -3,16 +3,20 @@ import { join } from 'node:path'
3
3
 
4
4
  import type { PermissionService } from '@/permissions'
5
5
  import type { GithubSecretsBlock } from '@/secrets'
6
+ import { SecretsDiscordCredentialStore } from '@/secrets/discord-store'
6
7
  import { SecretsKakaoCredentialStore } from '@/secrets/kakao-store'
7
8
  import { SecretsLineCredentialStore } from '@/secrets/line-store'
9
+ import { SecretsSlackCredentialStore } from '@/secrets/slack-store'
8
10
  import { SecretsBackend } from '@/secrets/storage'
9
11
  import { SecretsWebexCredentialStore } from '@/secrets/webex-store'
10
12
  import type { Stream } from '@/stream'
11
13
 
14
+ import { createDiscordAdapter, type DiscordAdapter } from './adapters/discord'
12
15
  import { createDiscordBotAdapter, type DiscordBotAdapter } from './adapters/discord-bot'
13
16
  import { createGithubAdapter, type GithubAdapter } from './adapters/github'
14
17
  import { createKakaotalkAdapter, type KakaotalkAdapter } from './adapters/kakaotalk'
15
18
  import { createLineAdapter, type LineAdapter } from './adapters/line'
19
+ import { createSlackAdapter, type SlackAdapter } from './adapters/slack'
16
20
  import { createSlackBotAdapter, type SlackBotAdapter } from './adapters/slack-bot'
17
21
  import { createTelegramBotAdapter, type TelegramBotAdapter } from './adapters/telegram-bot'
18
22
  import { createWebexAdapter, type WebexAdapter } from './adapters/webex'
@@ -69,10 +73,12 @@ export type ChannelManagerOptions = {
69
73
  createSessionForChannel?: CreateSessionForChannel
70
74
  // Test seams: let fake adapters replace the real adapter wiring per id.
71
75
  createDiscordAdapter?: typeof createDiscordBotAdapter
76
+ createDiscordUserAdapter?: typeof createDiscordAdapter
72
77
  createGithubAdapter?: typeof createGithubAdapter
73
78
  createKakaotalkAdapter?: typeof createKakaotalkAdapter
74
79
  createLineAdapter?: typeof createLineAdapter
75
80
  createSlackAdapter?: typeof createSlackBotAdapter
81
+ createSlackUserAdapter?: typeof createSlackAdapter
76
82
  createTelegramAdapter?: typeof createTelegramBotAdapter
77
83
  createWebexAdapter?: typeof createWebexAdapter
78
84
  createWebexBotAdapter?: typeof createWebexBotAdapter
@@ -109,6 +115,11 @@ export type ChannelManagerOptions = {
109
115
  // unregistered. See CreateChannelRouterOptions.onReload/onRestart.
110
116
  onReload?: () => Promise<string>
111
117
  onRestart?: (ctx?: RestartCommandContext) => Promise<string>
118
+ // Forwarded to the router so idle GC and stale-rollover can pin a channel
119
+ // session whose background subagent is still running (the next inbound would
120
+ // otherwise spawn a duplicate child). Production wiring (src/run/index.ts)
121
+ // supplies it from the LiveSubagentRegistry; tests omit it.
122
+ newestRunningChildSubagentStartedAt?: (sessionId: string) => number | null
112
123
  // Persistent messenger SDKs usually reconnect themselves, but a host sleep/offline
113
124
  // cycle can leave a socket half-dead forever. The manager watches live adapters
114
125
  // and restarts one that stays disconnected past this grace period. Test seams are
@@ -131,10 +142,12 @@ export type ChannelManager = {
131
142
  }
132
143
 
133
144
  type AnyAdapter =
145
+ | DiscordAdapter
134
146
  | DiscordBotAdapter
135
147
  | GithubAdapter
136
148
  | LineAdapter
137
149
  | KakaotalkAdapter
150
+ | SlackAdapter
138
151
  | SlackBotAdapter
139
152
  | TelegramBotAdapter
140
153
  | WebexAdapter
@@ -168,12 +181,17 @@ export function createChannelManager(options: ChannelManagerOptions): ChannelMan
168
181
  ...(options.stream ? { stream: options.stream } : {}),
169
182
  ...(options.onReload ? { onReload: options.onReload } : {}),
170
183
  ...(options.onRestart ? { onRestart: options.onRestart } : {}),
184
+ ...(options.newestRunningChildSubagentStartedAt
185
+ ? { newestRunningChildSubagentStartedAt: options.newestRunningChildSubagentStartedAt }
186
+ : {}),
171
187
  })
172
- const createDiscordAdapter = options.createDiscordAdapter ?? createDiscordBotAdapter
188
+ const createDiscordBot = options.createDiscordAdapter ?? createDiscordBotAdapter
189
+ const createDiscordUser = options.createDiscordUserAdapter ?? createDiscordAdapter
173
190
  const createGithub = options.createGithubAdapter ?? createGithubAdapter
174
191
  const createKakaotalk = options.createKakaotalkAdapter ?? createKakaotalkAdapter
175
192
  const createLine = options.createLineAdapter ?? createLineAdapter
176
- const createSlackAdapter = options.createSlackAdapter ?? createSlackBotAdapter
193
+ const createSlackBot = options.createSlackAdapter ?? createSlackBotAdapter
194
+ const createSlackUser = options.createSlackUserAdapter ?? createSlackAdapter
177
195
  const createTelegramAdapter = options.createTelegramAdapter ?? createTelegramBotAdapter
178
196
  const createWebex = options.createWebexAdapter ?? createWebexAdapter
179
197
  const createWebexBot = options.createWebexBotAdapter ?? createWebexBotAdapter
@@ -203,6 +221,8 @@ export function createChannelManager(options: ChannelManagerOptions): ChannelMan
203
221
  if (name === 'line') return buildLineSignature(options.agentDir)
204
222
  if (name === 'kakaotalk') return buildKakaotalkSignature(options.agentDir)
205
223
  if (name === 'webex') return buildWebexSignature(options.agentDir)
224
+ if (name === 'slack') return buildSlackSignature(options.agentDir)
225
+ if (name === 'discord') return buildDiscordSignature(options.agentDir)
206
226
  if (name === 'github') return buildGithubSignature(options.agentDir)
207
227
  const requiredEnvs = TOKEN_ENV[name]
208
228
  const parts: string[] = []
@@ -219,7 +239,7 @@ export function createChannelManager(options: ChannelManagerOptions): ChannelMan
219
239
  if (name === 'discord-bot') {
220
240
  const token = env.DISCORD_BOT_TOKEN
221
241
  if (token === undefined || token.trim() === '') return null
222
- return createDiscordAdapter({
242
+ return createDiscordBot({
223
243
  router,
224
244
  configRef: () => options.channelsConfigRef()[name] ?? cfg,
225
245
  token,
@@ -231,7 +251,7 @@ export function createChannelManager(options: ChannelManagerOptions): ChannelMan
231
251
  const appToken = env.SLACK_APP_TOKEN
232
252
  if (token === undefined || token.trim() === '') return null
233
253
  if (appToken === undefined || appToken.trim() === '') return null
234
- return createSlackAdapter({
254
+ return createSlackBot({
235
255
  router,
236
256
  configRef: () => options.channelsConfigRef()[name] ?? cfg,
237
257
  token,
@@ -241,30 +261,58 @@ export function createChannelManager(options: ChannelManagerOptions): ChannelMan
241
261
  })
242
262
  }
243
263
  if (name === 'line') {
264
+ const credentialsStore = createContainerLineCredentialStore(options.agentDir, env)
265
+ if (credentialsStore === null) return null
244
266
  return createLine({
245
267
  router,
246
268
  configRef: () => options.channelsConfigRef()[name] ?? cfg,
247
269
  logger,
248
270
  selfAliasesRef: () => router.getSelfAliases(),
249
- credentialsStore: createContainerLineCredentialStore(options.agentDir, env),
271
+ credentialsStore,
250
272
  })
251
273
  }
252
274
  if (name === 'kakaotalk') {
275
+ const credentialsStore = createContainerKakaoCredentialStore(options.agentDir, env)
276
+ if (credentialsStore === null) return null
253
277
  return createKakaotalk({
254
278
  router,
255
279
  configRef: () => options.channelsConfigRef()[name] ?? cfg,
256
280
  logger,
257
281
  selfAliasesRef: () => router.getSelfAliases(),
258
- credentialsStore: createContainerKakaoCredentialStore(options.agentDir, env),
282
+ credentialsStore,
283
+ })
284
+ }
285
+ if (name === 'slack') {
286
+ const credentialsStore = createContainerSlackCredentialStore(options.agentDir, env)
287
+ if (credentialsStore === null) return null
288
+ return createSlackUser({
289
+ router,
290
+ configRef: () => options.channelsConfigRef()[name] ?? cfg,
291
+ logger,
292
+ selfAliasesRef: () => router.getSelfAliases(),
293
+ credentialsStore,
294
+ })
295
+ }
296
+ if (name === 'discord') {
297
+ const credentialsStore = createContainerDiscordCredentialStore(options.agentDir, env)
298
+ if (credentialsStore === null) return null
299
+ return createDiscordUser({
300
+ router,
301
+ configRef: () => options.channelsConfigRef()[name] ?? cfg,
302
+ logger,
303
+ selfAliasesRef: () => router.getSelfAliases(),
304
+ credentialsStore,
259
305
  })
260
306
  }
261
307
  if (name === 'webex') {
308
+ const credentialsStore = createContainerWebexCredentialStore(options.agentDir, env)
309
+ if (credentialsStore === null) return null
262
310
  return createWebex({
263
311
  router,
264
312
  configRef: () => options.channelsConfigRef()[name] ?? cfg,
265
313
  logger,
266
314
  selfAliasesRef: () => router.getSelfAliases(),
267
- credentialsStore: createContainerWebexCredentialStore(options.agentDir, env),
315
+ credentialsStore,
268
316
  })
269
317
  }
270
318
  if (name === 'github') {
@@ -474,7 +522,9 @@ export function createChannelManager(options: ChannelManagerOptions): ChannelMan
474
522
  stopped.push(name)
475
523
  } else if (signature !== current.credentialSignature) {
476
524
  const reason =
477
- name === 'kakaotalk' || name === 'line' || name === 'webex' ? 'credential rotation' : 'token rotation'
525
+ name === 'kakaotalk' || name === 'line' || name === 'webex' || name === 'slack' || name === 'discord'
526
+ ? 'credential rotation'
527
+ : 'token rotation'
478
528
  restartRequired.push(`${name} (${reason})`)
479
529
  }
480
530
  }
@@ -488,26 +538,97 @@ export function createChannelManager(options: ChannelManagerOptions): ChannelMan
488
538
  // Token-based adapters only. Personal-account credentials live in
489
539
  // secrets.json#channels.<adapter>, not in env, so they go through
490
540
  // structured-block signatures instead.
491
- const TOKEN_ENV: Record<Exclude<AdapterId, 'kakaotalk' | 'line' | 'github' | 'webex'>, readonly string[]> = {
541
+ const TOKEN_ENV: Record<
542
+ Exclude<AdapterId, 'kakaotalk' | 'line' | 'github' | 'webex' | 'slack' | 'discord'>,
543
+ readonly string[]
544
+ > = {
492
545
  'discord-bot': ['DISCORD_BOT_TOKEN'],
493
546
  'slack-bot': ['SLACK_BOT_TOKEN', 'SLACK_APP_TOKEN'],
494
547
  'telegram-bot': ['TELEGRAM_BOT_TOKEN'],
495
548
  'webex-bot': ['WEBEX_BOT_TOKEN'],
496
549
  }
497
550
 
498
- function createContainerWebexCredentialStore(agentDir: string, env: NodeJS.ProcessEnv): SecretsWebexCredentialStore {
551
+ // Personal-account adapters (line/kakaotalk/slack/discord/webex) need the hostd
552
+ // triple the host CLI injects at `docker run` time, gated on a successful daemon
553
+ // registration (src/container/start.ts). If the daemon wasn't reachable at
554
+ // launch (e.g. a lost first-boot spawn race) the triple is absent; null lets
555
+ // buildAdapter skip the adapter instead of throwing and crashing the whole
556
+ // channel manager. startAdapter's signature pre-check only reads secrets.json,
557
+ // so this is the only place the missing triple is caught.
558
+ type HostdContainerCredentials = { hostdUrl: string; restartToken: string; containerName: string }
559
+
560
+ function resolveHostdContainerCredentials(env: NodeJS.ProcessEnv): HostdContainerCredentials | null {
499
561
  const hostdUrl = env.TYPECLAW_HOSTD_URL
500
562
  const restartToken = env.TYPECLAW_HOSTD_TOKEN
501
563
  const containerName = env.TYPECLAW_CONTAINER_NAME
502
- if (!hostdUrl || !restartToken || !containerName) {
503
- throw new Error('Webex credentials require TYPECLAW_HOSTD_URL, TYPECLAW_HOSTD_TOKEN, and TYPECLAW_CONTAINER_NAME')
564
+ if (!hostdUrl || !restartToken || !containerName) return null
565
+ return { hostdUrl, restartToken, containerName }
566
+ }
567
+
568
+ function createContainerDiscordCredentialStore(
569
+ agentDir: string,
570
+ env: NodeJS.ProcessEnv,
571
+ ): SecretsDiscordCredentialStore | null {
572
+ const creds = resolveHostdContainerCredentials(env)
573
+ if (creds === null) return null
574
+ return new SecretsDiscordCredentialStore({
575
+ mode: 'container',
576
+ secretsPath: join(agentDir, 'secrets.json'),
577
+ ...creds,
578
+ })
579
+ }
580
+
581
+ function buildDiscordSignature(agentDir: string): { signature: string; missing: string[] } {
582
+ const path = join(agentDir, 'secrets.json')
583
+ try {
584
+ const block = new SecretsBackend(path).tryReadChannelsSync()?.discord
585
+ if (!isDiscordCredentialBlock(block)) {
586
+ return { signature: '', missing: ['secrets.json#channels.discord'] }
587
+ }
588
+ const digest = createHash('sha256').update(JSON.stringify(block)).digest('hex')
589
+ return { signature: `secrets.json#channels.discord@sha256:${digest}`, missing: [] }
590
+ } catch (err) {
591
+ return { signature: '', missing: [`secrets.json#channels.discord (${describe(err)})`] }
504
592
  }
593
+ }
594
+
595
+ function createContainerSlackCredentialStore(
596
+ agentDir: string,
597
+ env: NodeJS.ProcessEnv,
598
+ ): SecretsSlackCredentialStore | null {
599
+ const creds = resolveHostdContainerCredentials(env)
600
+ if (creds === null) return null
601
+ return new SecretsSlackCredentialStore({
602
+ mode: 'container',
603
+ secretsPath: join(agentDir, 'secrets.json'),
604
+ ...creds,
605
+ })
606
+ }
607
+
608
+ function buildSlackSignature(agentDir: string): { signature: string; missing: string[] } {
609
+ const path = join(agentDir, 'secrets.json')
610
+ try {
611
+ const block = new SecretsBackend(path).tryReadChannelsSync()?.slack
612
+ if (!isSlackCredentialBlock(block)) {
613
+ return { signature: '', missing: ['secrets.json#channels.slack'] }
614
+ }
615
+ const digest = createHash('sha256').update(JSON.stringify(block)).digest('hex')
616
+ return { signature: `secrets.json#channels.slack@sha256:${digest}`, missing: [] }
617
+ } catch (err) {
618
+ return { signature: '', missing: [`secrets.json#channels.slack (${describe(err)})`] }
619
+ }
620
+ }
621
+
622
+ function createContainerWebexCredentialStore(
623
+ agentDir: string,
624
+ env: NodeJS.ProcessEnv,
625
+ ): SecretsWebexCredentialStore | null {
626
+ const creds = resolveHostdContainerCredentials(env)
627
+ if (creds === null) return null
505
628
  return new SecretsWebexCredentialStore({
506
629
  mode: 'container',
507
630
  secretsPath: join(agentDir, 'secrets.json'),
508
- hostdUrl,
509
- restartToken,
510
- containerName,
631
+ ...creds,
511
632
  })
512
633
  }
513
634
 
@@ -525,21 +646,16 @@ function buildWebexSignature(agentDir: string): { signature: string; missing: st
525
646
  }
526
647
  }
527
648
 
528
- function createContainerKakaoCredentialStore(agentDir: string, env: NodeJS.ProcessEnv): SecretsKakaoCredentialStore {
529
- const hostdUrl = env.TYPECLAW_HOSTD_URL
530
- const restartToken = env.TYPECLAW_HOSTD_TOKEN
531
- const containerName = env.TYPECLAW_CONTAINER_NAME
532
- if (!hostdUrl || !restartToken || !containerName) {
533
- throw new Error(
534
- 'KakaoTalk credentials require TYPECLAW_HOSTD_URL, TYPECLAW_HOSTD_TOKEN, and TYPECLAW_CONTAINER_NAME',
535
- )
536
- }
649
+ function createContainerKakaoCredentialStore(
650
+ agentDir: string,
651
+ env: NodeJS.ProcessEnv,
652
+ ): SecretsKakaoCredentialStore | null {
653
+ const creds = resolveHostdContainerCredentials(env)
654
+ if (creds === null) return null
537
655
  return new SecretsKakaoCredentialStore({
538
656
  mode: 'container',
539
657
  secretsPath: join(agentDir, 'secrets.json'),
540
- hostdUrl,
541
- restartToken,
542
- containerName,
658
+ ...creds,
543
659
  })
544
660
  }
545
661
 
@@ -557,19 +673,16 @@ function buildKakaotalkSignature(agentDir: string): { signature: string; missing
557
673
  }
558
674
  }
559
675
 
560
- function createContainerLineCredentialStore(agentDir: string, env: NodeJS.ProcessEnv): SecretsLineCredentialStore {
561
- const hostdUrl = env.TYPECLAW_HOSTD_URL
562
- const restartToken = env.TYPECLAW_HOSTD_TOKEN
563
- const containerName = env.TYPECLAW_CONTAINER_NAME
564
- if (!hostdUrl || !restartToken || !containerName) {
565
- throw new Error('LINE credentials require TYPECLAW_HOSTD_URL, TYPECLAW_HOSTD_TOKEN, and TYPECLAW_CONTAINER_NAME')
566
- }
676
+ function createContainerLineCredentialStore(
677
+ agentDir: string,
678
+ env: NodeJS.ProcessEnv,
679
+ ): SecretsLineCredentialStore | null {
680
+ const creds = resolveHostdContainerCredentials(env)
681
+ if (creds === null) return null
567
682
  return new SecretsLineCredentialStore({
568
683
  mode: 'container',
569
684
  secretsPath: join(agentDir, 'secrets.json'),
570
- hostdUrl,
571
- restartToken,
572
- containerName,
685
+ ...creds,
573
686
  })
574
687
  }
575
688
 
@@ -631,6 +744,24 @@ function isLineCredentialBlock(value: unknown): value is { accounts: Record<stri
631
744
  )
632
745
  }
633
746
 
747
+ function isSlackCredentialBlock(value: unknown): value is { accounts: Record<string, unknown> } {
748
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) return false
749
+ if (!('accounts' in value)) return false
750
+ const accounts = value.accounts
751
+ return (
752
+ typeof accounts === 'object' && accounts !== null && !Array.isArray(accounts) && Object.keys(accounts).length > 0
753
+ )
754
+ }
755
+
756
+ function isDiscordCredentialBlock(value: unknown): value is { accounts: Record<string, unknown> } {
757
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) return false
758
+ if (!('accounts' in value)) return false
759
+ const accounts = value.accounts
760
+ return (
761
+ typeof accounts === 'object' && accounts !== null && !Array.isArray(accounts) && Object.keys(accounts).length > 0
762
+ )
763
+ }
764
+
634
765
  function isWebexCredentialBlock(value: unknown): value is { accounts: Record<string, unknown> } {
635
766
  if (typeof value !== 'object' || value === null || Array.isArray(value)) return false
636
767
  if (!('accounts' in value)) return false
@@ -0,0 +1,43 @@
1
+ import type { Stream } from '@/stream'
2
+
3
+ import { parsePrVerdictActivityPayload } from './github-verdict-activity'
4
+ import type { ChannelRouter } from './router'
5
+
6
+ export type PrVerdictActivityBridgeLogger = {
7
+ info: (msg: string) => void
8
+ }
9
+
10
+ export type PrVerdictActivityBridgeOptions = {
11
+ stream: Stream
12
+ router: Pick<ChannelRouter, 'injectPrVerdictActivity'>
13
+ logger?: PrVerdictActivityBridgeLogger
14
+ }
15
+
16
+ export type PrVerdictActivityBridge = {
17
+ stop: () => void
18
+ }
19
+
20
+ const consoleLogger: PrVerdictActivityBridgeLogger = {
21
+ info: (msg) => console.log(msg),
22
+ }
23
+
24
+ // Bridges `pr.verdict-activity` broadcasts on the in-process Stream into a router
25
+ // call so the OTHER live sessions reviewing the same PR get a stand-down reminder
26
+ // once one of them lands a formal verdict. Mirrors the subagent-completion bridge:
27
+ // one broadcast subscriber, self-filtering payload parse, single router call. The
28
+ // verdict reaches the bus via the turn-ledger review observer (src/run/index.ts),
29
+ // because plugins have no direct stream access.
30
+ export function createPrVerdictActivityBridge(options: PrVerdictActivityBridgeOptions): PrVerdictActivityBridge {
31
+ const logger = options.logger ?? consoleLogger
32
+ const unsubscribe = options.stream.subscribe({ target: { kind: 'broadcast' } }, (msg) => {
33
+ const parsed = parsePrVerdictActivityPayload(msg.payload)
34
+ if (parsed === null) return
35
+ const result = options.router.injectPrVerdictActivity(parsed)
36
+ if (result.count > 0) {
37
+ logger.info(
38
+ `[channels] pr-verdict stand-down fanned out to ${result.count} sibling session(s) for ${parsed.workspace}#${parsed.prNumber} verdict=${parsed.verdict}`,
39
+ )
40
+ }
41
+ })
42
+ return { stop: unsubscribe }
43
+ }