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
@@ -1,32 +1,7 @@
1
- // Single source of truth for the top-level `typeclaw` subcommands that the
2
- // CLI dispatches via citty. Plugin commands MUST NOT shadow these names.
1
+ // Stable, dependency-free re-export of the top-level `typeclaw` subcommand names
2
+ // that the CLI dispatches via citty. Plugin commands MUST NOT shadow these names.
3
3
  // `src/cli/index.ts` consumes this for argv interception; `src/plugin/registry.ts`
4
- // consumes it to reject plugin commands that collide.
5
- export const BUILTIN_COMMAND_NAMES = [
6
- 'init',
7
- 'run',
8
- 'tui',
9
- 'start',
10
- 'stop',
11
- 'restart',
12
- 'status',
13
- 'reload',
14
- 'logs',
15
- 'inspect',
16
- 'dreams',
17
- 'shell',
18
- 'compose',
19
- 'channel',
20
- 'cron',
21
- 'tunnel',
22
- 'role',
23
- 'provider',
24
- 'model',
25
- 'mount',
26
- 'doctor',
27
- 'usage',
28
- 'update',
29
- '_hostd',
30
- ] as const
31
-
32
- export type BuiltinCommandName = (typeof BUILTIN_COMMAND_NAMES)[number]
4
+ // consumes it to reject plugin commands that collide. The names (and their help
5
+ // descriptions) are defined in `./command-meta`.
6
+ export { BUILTIN_COMMAND_NAMES } from './command-meta'
7
+ export type { BuiltinCommandName } from './command-meta'
@@ -2,6 +2,7 @@ import { randomBytes } from 'node:crypto'
2
2
 
3
3
  import { cancel, confirm, intro, isCancel, log, note, password, select, spinner, text } from '@clack/prompts'
4
4
  import { defineCommand } from 'citty'
5
+ import QRCode from 'qrcode'
5
6
 
6
7
  import { config } from '@/config'
7
8
  import {
@@ -25,14 +26,18 @@ import {
25
26
  setGithubSecrets,
26
27
  type AddChannelStepEvent,
27
28
  type ChannelKind,
29
+ type DiscordAuthResult,
28
30
  type GithubCredentialPatch,
29
31
  type GithubTunnelProvider,
30
32
  type KakaotalkAuthResult,
31
33
  type LineAuthResult,
34
+ type SlackAuthResult,
32
35
  type WebexAuthResult,
33
36
  } from '@/init'
37
+ import { runDiscordBootstrap } from '@/init/discord-auth'
34
38
  import { runKakaotalkBootstrap } from '@/init/kakaotalk-auth'
35
39
  import { runLineBootstrap } from '@/init/line-auth'
40
+ import { runSlackBootstrap } from '@/init/slack-auth'
36
41
  import { runWebexBootstrap } from '@/init/webex-auth'
37
42
  import { SecretsKakaoCredentialStore } from '@/secrets/kakao-store'
38
43
  import { SecretsWebexCredentialStore } from '@/secrets/webex-store'
@@ -43,6 +48,8 @@ import { c, done, errorLine, printDiscordInviteHint, printSlackAppManifestSetup,
43
48
 
44
49
  const CHANNEL_LABELS: Record<ChannelKind, string> = {
45
50
  'slack-bot': 'Slack',
51
+ slack: 'Slack (User)',
52
+ discord: 'Discord (User)',
46
53
  'discord-bot': 'Discord',
47
54
  'telegram-bot': 'Telegram',
48
55
  webex: 'Webex (User)',
@@ -612,16 +619,18 @@ async function pickChannel(configured: Set<ChannelKind>): Promise<ChannelKind> {
612
619
  process.exit(0)
613
620
  }
614
621
 
615
- type PickerValue = Exclude<ChannelKind, 'webex' | 'webex-bot'> | 'webex-family'
616
- const webexModes = available.filter((kind): kind is 'webex' | 'webex-bot' => kind === 'webex' || kind === 'webex-bot')
622
+ type FamilyValue = 'webex-family' | 'slack-family' | 'discord-family'
623
+ type FlatKind = Exclude<ChannelKind, 'webex' | 'webex-bot' | 'slack' | 'slack-bot' | 'discord' | 'discord-bot'>
624
+ type PickerValue = FlatKind | FamilyValue
617
625
  const options: Array<{ value: PickerValue; label: string }> = []
618
626
  for (const kind of available) {
619
- if (kind === 'webex' || kind === 'webex-bot') {
620
- if (!options.some((option) => option.value === 'webex-family'))
621
- options.push({ value: 'webex-family', label: 'Webex' })
627
+ const family = FAMILY_OF[kind]
628
+ if (family !== undefined) {
629
+ if (!options.some((option) => option.value === family.value))
630
+ options.push({ value: family.value, label: family.label })
622
631
  continue
623
632
  }
624
- options.push({ value: kind, label: CHANNEL_LABELS[kind] })
633
+ options.push({ value: kind as FlatKind, label: CHANNEL_LABELS[kind] })
625
634
  }
626
635
 
627
636
  const selected = await select<PickerValue>({
@@ -633,20 +642,87 @@ async function pickChannel(configured: Set<ChannelKind>): Promise<ChannelKind> {
633
642
  cancel('Aborted.')
634
643
  process.exit(0)
635
644
  }
636
- if (selected !== 'webex-family') return selected
637
- if (webexModes.length === 1) return webexModes[0]!
638
- const allWebexOptions: Array<{ value: 'webex' | 'webex-bot'; label: string }> = [
639
- {
640
- value: 'webex',
641
- label: 'User (ID/PW) — receives all messages, no @mention needed (recommended)',
642
- },
643
- { value: 'webex-bot', label: 'Bot (Token) — only sees @mentions in group spaces' },
644
- ]
645
- const webexOptions = allWebexOptions.filter((option) => webexModes.includes(option.value))
645
+ if (selected === 'webex-family') return pickWebexMode(available)
646
+ if (selected === 'slack-family') return pickSlackMode(available)
647
+ if (selected === 'discord-family') return pickDiscordMode(available)
648
+ return selected
649
+ }
650
+
651
+ const FAMILY_OF: Partial<Record<ChannelKind, { value: FamilyValue; label: string }>> = {
652
+ webex: { value: 'webex-family', label: 'Webex' },
653
+ 'webex-bot': { value: 'webex-family', label: 'Webex' },
654
+ slack: { value: 'slack-family', label: 'Slack' },
655
+ 'slack-bot': { value: 'slack-family', label: 'Slack' },
656
+ discord: { value: 'discord-family', label: 'Discord' },
657
+ 'discord-bot': { value: 'discord-family', label: 'Discord' },
658
+ }
659
+
660
+ type FamilyValue = 'webex-family' | 'slack-family' | 'discord-family'
661
+
662
+ type FamilyMode<K extends ChannelKind> = { value: K; label: string }
663
+
664
+ export const WEBEX_MODES: ReadonlyArray<FamilyMode<'webex' | 'webex-bot'>> = [
665
+ { value: 'webex', label: 'User (ID/PW) — receives all messages, no @mention needed (recommended)' },
666
+ { value: 'webex-bot', label: 'Bot (Token) — only sees @mentions in group spaces' },
667
+ ]
668
+
669
+ export const SLACK_MODES: ReadonlyArray<FamilyMode<'slack' | 'slack-bot'>> = [
670
+ { value: 'slack-bot', label: 'Bot (Token) — posts as a Slack app/bot user (recommended)' },
671
+ { value: 'slack', label: 'User (QR) — posts as your own Slack account; unofficial session, may need re-auth' },
672
+ ]
673
+
674
+ export const DISCORD_MODES: ReadonlyArray<FamilyMode<'discord' | 'discord-bot'>> = [
675
+ { value: 'discord-bot', label: 'Bot (Token) — posts as a Discord app/bot user (recommended)' },
676
+ { value: 'discord', label: 'User (QR) — posts as your own Discord account; unofficial session, may need re-auth' },
677
+ ]
678
+
679
+ // Keep the displayed order (recommended/User first), dropping already-configured
680
+ // modes. The caller defaults the selection to options[0], so this order — NOT
681
+ // CHANNEL_KINDS order — decides which mode is preselected.
682
+ export function familyModeOptions<K extends ChannelKind>(
683
+ modes: ReadonlyArray<FamilyMode<K>>,
684
+ available: ReadonlyArray<ChannelKind>,
685
+ ): Array<FamilyMode<K>> {
686
+ return modes.filter((mode) => available.includes(mode.value))
687
+ }
688
+
689
+ async function pickWebexMode(available: ReadonlyArray<ChannelKind>): Promise<'webex' | 'webex-bot'> {
690
+ const options = familyModeOptions(WEBEX_MODES, available)
691
+ if (options.length === 1) return options[0]!.value
646
692
  const mode = await select<'webex' | 'webex-bot'>({
647
693
  message: 'Which Webex mode?',
648
- options: webexOptions,
649
- initialValue: webexModes[0],
694
+ options: options.map((o) => ({ value: o.value, label: o.label })),
695
+ initialValue: options[0]?.value,
696
+ })
697
+ if (isCancel(mode)) {
698
+ cancel('Aborted.')
699
+ process.exit(0)
700
+ }
701
+ return mode
702
+ }
703
+
704
+ async function pickSlackMode(available: ReadonlyArray<ChannelKind>): Promise<'slack' | 'slack-bot'> {
705
+ const options = familyModeOptions(SLACK_MODES, available)
706
+ if (options.length === 1) return options[0]!.value
707
+ const mode = await select<'slack' | 'slack-bot'>({
708
+ message: 'Which Slack mode?',
709
+ options: options.map((o) => ({ value: o.value, label: o.label })),
710
+ initialValue: options[0]?.value,
711
+ })
712
+ if (isCancel(mode)) {
713
+ cancel('Aborted.')
714
+ process.exit(0)
715
+ }
716
+ return mode
717
+ }
718
+
719
+ async function pickDiscordMode(available: ReadonlyArray<ChannelKind>): Promise<'discord' | 'discord-bot'> {
720
+ const options = familyModeOptions(DISCORD_MODES, available)
721
+ if (options.length === 1) return options[0]!.value
722
+ const mode = await select<'discord' | 'discord-bot'>({
723
+ message: 'Which Discord mode?',
724
+ options: options.map((o) => ({ value: o.value, label: o.label })),
725
+ initialValue: options[0]?.value,
650
726
  })
651
727
  if (isCancel(mode)) {
652
728
  cancel('Aborted.')
@@ -852,7 +928,13 @@ async function runSetGithub(cwd: string): Promise<void> {
852
928
  }
853
929
 
854
930
  type CollectedCredentials =
931
+ | { channel: 'discord'; runDiscordAuth: (options: { cwd: string }) => Promise<DiscordAuthResult> }
855
932
  | { channel: 'discord-bot'; discordBotToken: string }
933
+ | {
934
+ channel: 'slack'
935
+ slackQrDataUrl: string
936
+ runSlackAuth: (options: { cwd: string; qrDataUrl: string }) => Promise<SlackAuthResult>
937
+ }
856
938
  | { channel: 'slack-bot'; slackBotToken: string; slackAppToken: string }
857
939
  | { channel: 'telegram-bot'; telegramBotToken: string }
858
940
  | { channel: 'webex'; runWebexAuth: (options: { cwd: string }) => Promise<WebexAuthResult> }
@@ -875,12 +957,22 @@ async function collectCredentials(
875
957
  lineSpinnerHolder?: LineAuthSpinnerHolder,
876
958
  ): Promise<CollectedCredentials> {
877
959
  switch (channel) {
960
+ case 'discord':
961
+ return { channel, runDiscordAuth: ({ cwd: agentDir }) => runDiscordQrAuth(agentDir) }
878
962
  case 'discord-bot':
879
963
  return { channel, discordBotToken: await promptDiscordToken() }
880
964
  case 'slack-bot': {
881
965
  const slack = await promptSlackTokens()
882
966
  return { channel, slackBotToken: slack.bot, slackAppToken: slack.app }
883
967
  }
968
+ case 'slack': {
969
+ const qrDataUrl = await promptSlackQrDataUrl()
970
+ return {
971
+ channel,
972
+ slackQrDataUrl: qrDataUrl,
973
+ runSlackAuth: ({ cwd: agentDir, qrDataUrl }) => runSlackBootstrap({ qrDataUrl, agentDir }),
974
+ }
975
+ }
884
976
  case 'telegram-bot':
885
977
  return { channel, telegramBotToken: await promptTelegramToken() }
886
978
  case 'webex': {
@@ -920,6 +1012,20 @@ async function collectCredentials(
920
1012
  }
921
1013
  }
922
1014
 
1015
+ async function runDiscordQrAuth(agentDir: string): Promise<DiscordAuthResult> {
1016
+ return await runDiscordBootstrap({ agentDir, onQrUrl: renderDiscordQrToTerminal })
1017
+ }
1018
+
1019
+ async function renderDiscordQrToTerminal(url: string): Promise<void> {
1020
+ const qr = await QRCode.toString(url, { type: 'terminal', small: true })
1021
+ note(
1022
+ [`Open Discord mobile app → Settings → scan QR.`, '', qr, '', 'Approve the login on your phone to continue.'].join(
1023
+ '\n',
1024
+ ),
1025
+ 'Discord QR login',
1026
+ )
1027
+ }
1028
+
923
1029
  async function promptGithubCredentials(cwd: string): Promise<{
924
1030
  webhookSecret: string
925
1031
  tunnelProvider: GithubTunnelProvider
@@ -1241,6 +1347,34 @@ async function promptSlackTokens(): Promise<{ bot: string; app: string }> {
1241
1347
  return { bot, app }
1242
1348
  }
1243
1349
 
1350
+ async function promptSlackQrDataUrl(): Promise<string> {
1351
+ note(
1352
+ [
1353
+ 'Slack user mode signs in as your own account — messages are sent and',
1354
+ 'received as this Slack user, not a bot.',
1355
+ '',
1356
+ 'Copy the QR image data URL from the Slack desktop app:',
1357
+ '',
1358
+ '1. Click your name (top-left) → "Sign in on mobile".',
1359
+ '2. Right-click the QR code → "Copy Image Address".',
1360
+ '3. Paste it below (a long data:image/png;base64,... string).',
1361
+ '',
1362
+ 'Generate a fresh QR each time — the sign-in link expires quickly.',
1363
+ ].join('\n'),
1364
+ 'Sign in to Slack (user account)',
1365
+ )
1366
+ const qrDataUrl = await text({
1367
+ message: 'Slack QR data URL (data:image/png;base64,...)',
1368
+ validate: (value) =>
1369
+ value && value.startsWith('data:image/') ? undefined : 'QR data URL must start with "data:image/"',
1370
+ })
1371
+ if (isCancel(qrDataUrl)) {
1372
+ cancel('Aborted.')
1373
+ process.exit(0)
1374
+ }
1375
+ return qrDataUrl
1376
+ }
1377
+
1244
1378
  async function promptSlackBotToken(): Promise<string> {
1245
1379
  const botToken = await password({
1246
1380
  message: 'Slack bot token (xoxb-...)',
@@ -1557,6 +1691,12 @@ function reportProgress(
1557
1691
  case 'webex-auth':
1558
1692
  s.stop(reportWebexAuth(event.result))
1559
1693
  break
1694
+ case 'discord-auth':
1695
+ s.stop(reportDiscordAuth(event.result))
1696
+ break
1697
+ case 'slack-auth':
1698
+ s.stop(reportSlackAuth(event.result))
1699
+ break
1560
1700
  case 'config':
1561
1701
  s.stop('Updated typeclaw.json.')
1562
1702
  break
@@ -1574,6 +1714,8 @@ const START_MESSAGES: Record<AddChannelStepEvent['step'], string> = {
1574
1714
  'line-auth': 'Logging in to LINE...',
1575
1715
  'kakaotalk-auth': 'Logging in to KakaoTalk...',
1576
1716
  'webex-auth': 'Logging in to Webex...',
1717
+ 'discord-auth': 'Logging in to Discord...',
1718
+ 'slack-auth': 'Logging in to Slack...',
1577
1719
  config: 'Updating typeclaw.json...',
1578
1720
  secrets: 'Saving credentials to secrets.json...',
1579
1721
  'github-webhooks': 'Installing GitHub repository webhooks...',
@@ -1584,6 +1726,16 @@ function reportKakaotalkAuth(result: KakaotalkAuthResult): string {
1584
1726
  return `KakaoTalk login failed: ${result.reason}`
1585
1727
  }
1586
1728
 
1729
+ function reportSlackAuth(result: SlackAuthResult): string {
1730
+ if (result.ok) return 'Slack credentials saved to secrets.json.'
1731
+ return `Slack login failed: ${result.reason}`
1732
+ }
1733
+
1734
+ function reportDiscordAuth(result: DiscordAuthResult): string {
1735
+ if (result.ok) return 'Discord credentials saved to secrets.json.'
1736
+ return `Discord login failed: ${result.reason}`
1737
+ }
1738
+
1587
1739
  function reportWebexAuth(result: WebexAuthResult): string {
1588
1740
  if (result.ok) return 'Webex credentials saved to secrets.json.'
1589
1741
  return `Webex login failed: ${result.reason}`
@@ -0,0 +1,93 @@
1
+ // MUST stay free of command-module imports. `src/cli/index.ts` hand-renders the
2
+ // top-level help table from this data so a bare `typeclaw`/`--help` does not make
3
+ // citty resolve all 25 lazy `subCommands` thunks (each pulling the full
4
+ // config/docker/agent-messenger graph) just to read their descriptions — the
5
+ // resolve-all-for-help path was why a bare invocation was slower than a real
6
+ // subcommand. Each command module keeps its own literal `meta.description` (what
7
+ // citty prints for `typeclaw <cmd> --help`); the descriptions here are a separate
8
+ // copy, and `command-meta.test.ts` asserts the two stay byte-identical so the
9
+ // top-level table and per-command help cannot drift.
10
+
11
+ export type BuiltinCommandName =
12
+ | 'init'
13
+ | 'run'
14
+ | 'tui'
15
+ | 'start'
16
+ | 'stop'
17
+ | 'restart'
18
+ | 'status'
19
+ | 'reload'
20
+ | 'logs'
21
+ | 'inspect'
22
+ | 'dreams'
23
+ | 'shell'
24
+ | 'compose'
25
+ | 'channel'
26
+ | 'cron'
27
+ | 'tunnel'
28
+ | 'role'
29
+ | 'provider'
30
+ | 'model'
31
+ | 'mount'
32
+ | 'doctor'
33
+ | 'usage'
34
+ | 'update'
35
+ | '_hostd'
36
+ | '_update-check'
37
+
38
+ export type BuiltinCommandMeta = {
39
+ name: BuiltinCommandName
40
+ description: string
41
+ hidden?: boolean
42
+ }
43
+
44
+ export const BUILTIN_COMMANDS: readonly BuiltinCommandMeta[] = [
45
+ { name: 'init', description: 'initialize a new typeclaw agent in the current directory' },
46
+ { name: 'run', description: 'run the agent in the foreground (container stage)' },
47
+ { name: 'tui', description: 'open the live agent session in the read+write viewer (host stage)' },
48
+ { name: 'start', description: 'launch the agent container in the background (host stage)' },
49
+ { name: 'stop', description: 'stop the agent container (host stage)' },
50
+ { name: 'restart', description: 'stop and relaunch the agent container (host stage)' },
51
+ { name: 'status', description: 'show the agent container and host daemon status (host stage)' },
52
+ { name: 'reload', description: "reload the running agent's reloadable subsystems (cron, ...)" },
53
+ { name: 'logs', description: 'show the agent container logs (host stage)' },
54
+ {
55
+ name: 'inspect',
56
+ description: 'session viewer: pick a session, the live TUI, or container logs to observe (host stage)',
57
+ },
58
+ {
59
+ name: 'dreams',
60
+ description: "browse the dreaming subagent's memory-consolidation journal from git history (host stage)",
61
+ },
62
+ { name: 'shell', description: 'open an interactive shell in the agent container (host stage)' },
63
+ { name: 'compose', description: 'orchestrate every typeclaw agent in immediate subdirectories of cwd' },
64
+ { name: 'channel', description: 'manage channel adapters wired into the agent' },
65
+ {
66
+ name: 'cron',
67
+ description: 'inspect cron jobs registered in the running agent (user-authored + plugin-contributed)',
68
+ },
69
+ { name: 'tunnel', description: 'manage public tunnels for channels and manual upstreams' },
70
+ { name: 'role', description: 'manage role memberships on this agent' },
71
+ { name: 'provider', description: 'manage LLM provider credentials in secrets.json' },
72
+ { name: 'model', description: 'manage model profiles in typeclaw.json (models.default, models.fast, …)' },
73
+ { name: 'mount', description: 'manage host files and directories mounted into the agent container' },
74
+ { name: 'doctor', description: 'diagnose the host, agent folder, and plugins; surface remediation steps' },
75
+ { name: 'usage', description: 'report LLM token usage and cost for this agent folder' },
76
+ { name: 'update', description: 'update the installed typeclaw CLI (auto-detects global vs local)' },
77
+ { name: '_hostd', description: 'internal: host-side typeclaw daemon (do not invoke directly)', hidden: true },
78
+ {
79
+ name: '_update-check',
80
+ description: 'internal: refresh the typeclaw version cache (do not invoke directly)',
81
+ hidden: true,
82
+ },
83
+ ]
84
+
85
+ export const BUILTIN_COMMAND_NAMES: readonly BuiltinCommandName[] = BUILTIN_COMMANDS.map((c) => c.name)
86
+
87
+ const DESCRIPTION_BY_NAME: ReadonlyMap<string, string> = new Map(BUILTIN_COMMANDS.map((c) => [c.name, c.description]))
88
+
89
+ export function getBuiltinCommandDescription(name: BuiltinCommandName): string {
90
+ const description = DESCRIPTION_BY_NAME.get(name)
91
+ if (description === undefined) throw new Error(`unknown builtin command: ${name}`)
92
+ return description
93
+ }
@@ -0,0 +1,24 @@
1
+ import { type CommandDef, renderUsage } from 'citty'
2
+
3
+ import { CLI_VERSION } from '../init/cli-version'
4
+ import { BUILTIN_COMMANDS } from './command-meta'
5
+
6
+ // Reuses citty's own renderUsage for byte-identical output, but feeds it static
7
+ // `{ meta }` subcommands instead of the lazy import-thunks the real `main` uses.
8
+ // renderUsage only reads each subcommand's `meta` (name/description/hidden), so
9
+ // these stand-ins render the same table WITHOUT importing the 25 command modules
10
+ // — the resolve-all-for-help path was the startup-cost regression this fixes.
11
+ function buildHelpCommand(): CommandDef {
12
+ const subCommands: Record<string, CommandDef> = {}
13
+ for (const { name, description, hidden } of BUILTIN_COMMANDS) {
14
+ subCommands[name] = { meta: { name, description, ...(hidden === true ? { hidden: true } : {}) } }
15
+ }
16
+ return {
17
+ meta: { name: 'typeclaw', version: CLI_VERSION, description: 'TypeClaw agent runtime' },
18
+ subCommands,
19
+ }
20
+ }
21
+
22
+ export async function renderTopLevelUsage(): Promise<string> {
23
+ return renderUsage(buildHelpCommand())
24
+ }
package/src/cli/index.ts CHANGED
@@ -39,6 +39,7 @@ const main = defineCommand({
39
39
  usage: () => import('./usage').then((m) => m.usageCommand),
40
40
  update: () => import('./update').then((m) => m.updateCommand),
41
41
  _hostd: () => import('./hostd').then((m) => m.hostdCommand),
42
+ '_update-check': () => import('./update-check').then((m) => m.updateCheckCommand),
42
43
  },
43
44
  })
44
45
 
@@ -74,23 +75,57 @@ function runHostStartupMigrationsOnce(commandName: string | undefined): void {
74
75
  }
75
76
  }
76
77
 
78
+ // Plugin commands are discovered from the agent folder; outside one, discovery
79
+ // yields nothing and no section prints. Shared by the --help and no-command
80
+ // paths so both keep showing plugin commands above the builtin usage table.
81
+ async function printPluginCommandsSection(): Promise<void> {
82
+ const { renderPluginCommandsSection } = await import('./plugin-command-help')
83
+ const { discoverCommands } = await import('./plugin-commands')
84
+ const discovery = await discoverCommands({ cwd: process.cwd() })
85
+ const section = renderPluginCommandsSection(discovery.commands)
86
+ if (section !== null) process.stdout.write(`${section}\n\n`)
87
+ }
88
+
77
89
  async function runWithPluginDispatch(): Promise<void> {
78
90
  const argv = process.argv.slice(2)
79
91
  const first = argv[0]
80
92
 
81
93
  runHostStartupMigrationsOnce(first)
82
94
 
95
+ // Disk-only read + detached background refresh; fail-open and never blocks the
96
+ // command. The suppression check is dependency-free and runs FIRST so a bare
97
+ // flag or plugin command never imports update-notify (which eagerly loads
98
+ // @/config). See src/cli/update-suppression.ts and src/cli/update-notify.ts.
99
+ const { shouldConsiderUpdateNotice } = await import('./update-suppression')
100
+ if (shouldConsiderUpdateNotice(first)) {
101
+ const { maybeNotifyUpdate } = await import('./update-notify')
102
+ await maybeNotifyUpdate(first)
103
+ }
104
+
105
+ // Top-level help and the no-command case are hand-rendered from the static
106
+ // command-meta table (see ./help) instead of `runMain(main)`. Routing them
107
+ // through citty would resolve every lazy `subCommands` thunk just to read the
108
+ // descriptions for the usage table, importing all 25 command modules (and
109
+ // their config/docker/agent-messenger graphs) — which made a bare `typeclaw`
110
+ // slower than running a real subcommand. Per-command help (`typeclaw x --help`)
111
+ // still goes through citty below, importing only that one command.
83
112
  if (first === '--help' || first === '-h') {
84
- // citty calls process.exit() after rendering help, so anything we print
85
- // AFTER `runMain(main)` is never reached. Print the plugin commands
86
- // section first; citty's own help follows and the user reads top-down.
87
- const { renderPluginCommandsSection } = await import('./plugin-command-help')
88
- const { discoverCommands } = await import('./plugin-commands')
89
- const discovery = await discoverCommands({ cwd: process.cwd() })
90
- const section = renderPluginCommandsSection(discovery.commands)
91
- if (section !== null) process.stdout.write(`${section}\n\n`)
92
- await runMain(main)
93
- return
113
+ await printPluginCommandsSection()
114
+ const { renderTopLevelUsage } = await import('./help')
115
+ process.stdout.write(`${await renderTopLevelUsage()}\n\n`)
116
+ process.exit(0)
117
+ }
118
+
119
+ if (first === undefined) {
120
+ // No plugin discovery here: bare `typeclaw` must stay a pure
121
+ // E_NO_COMMAND report and never load plugin/config code (discoverCommands
122
+ // can rewrite typeclaw.json via loadConfigSync). Plugin commands surface
123
+ // only on explicit top-level help and plugin-command dispatch. Mirror
124
+ // citty's E_NO_COMMAND: usage to stdout, the message to stderr, exit 1.
125
+ const { renderTopLevelUsage } = await import('./help')
126
+ process.stdout.write(`${await renderTopLevelUsage()}\n\n`)
127
+ process.stderr.write('No command specified.\n')
128
+ process.exit(1)
94
129
  }
95
130
 
96
131
  if (
package/src/cli/init.ts CHANGED
@@ -2043,6 +2043,8 @@ const START_MESSAGES: Record<Exclude<InitStep, 'hatching'>, string> = {
2043
2043
  preflight: 'Checking Docker...',
2044
2044
  'oauth-login': 'Waiting for browser login...',
2045
2045
  scaffold: 'Laying the egg...',
2046
+ 'slack-auth': 'Logging in to Slack...',
2047
+ 'discord-auth': 'Logging in to Discord...',
2046
2048
  'kakaotalk-auth': 'Logging in to KakaoTalk...',
2047
2049
  'webex-auth': 'Logging in to Webex...',
2048
2050
  'github-webhooks': 'Installing GitHub repository webhooks...',
@@ -0,0 +1,14 @@
1
+ import { defineCommand } from 'citty'
2
+
3
+ import { runBackgroundCheck } from '@/update/check'
4
+
5
+ export const updateCheckCommand = defineCommand({
6
+ meta: {
7
+ name: '_update-check',
8
+ description: 'internal: refresh the typeclaw version cache (do not invoke directly)',
9
+ hidden: true,
10
+ },
11
+ async run() {
12
+ await runBackgroundCheck()
13
+ },
14
+ })
@@ -0,0 +1,91 @@
1
+ import { CLI_VERSION, isInstalledCli } from '@/init/cli-version'
2
+ import {
3
+ isCacheFresh,
4
+ readVersionCache,
5
+ renderUpdateNotice,
6
+ resolveSkipReason,
7
+ type VersionCache,
8
+ } from '@/update/check'
9
+
10
+ import { shouldConsiderUpdateNotice, UPDATE_CHECK_COMMAND } from './update-suppression'
11
+
12
+ export { shouldConsiderUpdateNotice }
13
+
14
+ export type UpdateAction = { notice: string | null; refresh: boolean }
15
+
16
+ // Pure decision, kept config-free (takes `configEnabled` as a param) so it is
17
+ // unit-testable without spawning or loading config. Two invariants the reviews
18
+ // pinned: a skipped check suppresses BOTH the notice and the refresh; and a
19
+ // FRESH cache (success or failure-only) suppresses the refresh so the parent
20
+ // stops forking a check child on every invocation while the throttle holds.
21
+ export function decideUpdateAction(opts: {
22
+ current: string
23
+ isInstalled: boolean
24
+ configEnabled: boolean
25
+ env: Record<string, string | undefined>
26
+ cache: VersionCache | null
27
+ now: number
28
+ }): UpdateAction {
29
+ const skip = resolveSkipReason({
30
+ current: opts.current,
31
+ isInstalled: opts.isInstalled,
32
+ configEnabled: opts.configEnabled,
33
+ env: opts.env,
34
+ })
35
+ if (skip !== null) return { notice: null, refresh: false }
36
+ return {
37
+ notice: renderUpdateNotice({ current: opts.current, cache: opts.cache }),
38
+ refresh: !isCacheFresh(opts.cache, opts.now),
39
+ }
40
+ }
41
+
42
+ // The host-stage entry hook. Fail-open: a thrown error here must never disrupt
43
+ // the command the user actually ran, so the whole body is best-effort. Order is
44
+ // load-bearing: the dependency-free skip (env / dev / non-release) runs BEFORE
45
+ // @/config is ever imported, so a suppressed command (CI / opt-out) never pays
46
+ // the eager config load that would emit malformed-typeclaw.json warnings.
47
+ export async function maybeNotifyUpdate(commandName: string | undefined): Promise<void> {
48
+ try {
49
+ if (!shouldConsiderUpdateNotice(commandName)) return
50
+
51
+ const { resolveDependencyFreeSkip } = await import('@/update/check')
52
+ if (resolveDependencyFreeSkip({ current: CLI_VERSION, isInstalled: isInstalledCli(), env: process.env }) !== null) {
53
+ return
54
+ }
55
+
56
+ const { config } = await import('@/config')
57
+ const cache = await readVersionCache()
58
+ const action = decideUpdateAction({
59
+ current: CLI_VERSION,
60
+ isInstalled: isInstalledCli(),
61
+ configEnabled: config.updateCheck.enabled,
62
+ env: process.env,
63
+ cache,
64
+ now: Date.now(),
65
+ })
66
+
67
+ if (action.notice !== null) process.stderr.write(`${action.notice}\n`)
68
+ if (action.refresh) spawnBackgroundRefresh()
69
+ } catch {}
70
+ }
71
+
72
+ // Detached `typeclaw _update-check` child: fully unref'd so the parent process
73
+ // exits immediately regardless of the network call's fate (the user's hard rule
74
+ // — the command is 10000x more important than the check). stdio is ignored so
75
+ // the child can't write into the parent's terminal.
76
+ function spawnBackgroundRefresh(): void {
77
+ const bun = (globalThis as { Bun?: { spawn: typeof Bun.spawn } }).Bun
78
+ if (!bun) return
79
+ const cliEntry = process.argv[1]
80
+ if (cliEntry === undefined) return
81
+ try {
82
+ const proc = bun.spawn({
83
+ cmd: [process.execPath, cliEntry, UPDATE_CHECK_COMMAND],
84
+ stdin: 'ignore',
85
+ stdout: 'ignore',
86
+ stderr: 'ignore',
87
+ env: { ...process.env },
88
+ })
89
+ proc.unref()
90
+ } catch {}
91
+ }
@@ -0,0 +1,19 @@
1
+ import { BUILTIN_COMMAND_NAMES } from './builtins'
2
+
3
+ export const UPDATE_CHECK_COMMAND = '_update-check'
4
+
5
+ // Commands for which an update nudge would be noise or out of place: the
6
+ // container stage (`run`), the hidden internals, and `update` itself (the user
7
+ // is already updating). Bare flags are filtered separately by the `-` prefix.
8
+ const SUPPRESSED_COMMANDS = new Set(['run', 'update', '_hostd', UPDATE_CHECK_COMMAND])
9
+
10
+ // Dependency-free on purpose: index.ts calls this BEFORE importing the rest of
11
+ // the update-notify path so a suppressed command (bare flag, plugin command,
12
+ // `run`) never pays the eager `@/config` load that module triggers. Keep this
13
+ // file's imports limited to the builtin-name list.
14
+ export function shouldConsiderUpdateNotice(commandName: string | undefined): boolean {
15
+ if (commandName === undefined) return false
16
+ if (commandName.startsWith('-')) return false
17
+ if (SUPPRESSED_COMMANDS.has(commandName)) return false
18
+ return BUILTIN_COMMAND_NAMES.includes(commandName as (typeof BUILTIN_COMMAND_NAMES)[number])
19
+ }