typeclaw 0.37.7 → 0.38.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +2 -2
  2. package/auth.schema.json +109 -0
  3. package/package.json +2 -2
  4. package/secrets.schema.json +109 -0
  5. package/src/agent/session-origin.ts +16 -2
  6. package/src/bundled-plugins/memory/README.md +12 -1
  7. package/src/bundled-plugins/memory/index.ts +39 -2
  8. package/src/channels/adapters/kakaotalk.ts +1 -1
  9. package/src/channels/adapters/webex-bot-channel-resolver.ts +29 -0
  10. package/src/channels/adapters/webex-bot-classify.ts +98 -0
  11. package/src/channels/adapters/webex-bot-reference.ts +49 -0
  12. package/src/channels/adapters/webex-bot.ts +462 -0
  13. package/src/channels/adapters/webex-channel-resolver.ts +29 -0
  14. package/src/channels/adapters/webex-classify.ts +104 -0
  15. package/src/channels/adapters/webex-format.ts +53 -0
  16. package/src/channels/adapters/webex-id-ref.ts +32 -0
  17. package/src/channels/adapters/webex-reference.ts +49 -0
  18. package/src/channels/adapters/webex.ts +493 -0
  19. package/src/channels/manager.ts +75 -4
  20. package/src/channels/persistence.ts +67 -5
  21. package/src/channels/router.ts +9 -0
  22. package/src/channels/schema.ts +17 -1
  23. package/src/cli/channel.ts +155 -8
  24. package/src/cli/init.ts +129 -6
  25. package/src/config/channels-mutation.ts +11 -2
  26. package/src/doctor/channel-checks.ts +56 -1
  27. package/src/hostd/daemon.ts +7 -5
  28. package/src/hostd/protocol.ts +2 -2
  29. package/src/init/checkpoint.ts +1 -1
  30. package/src/init/index.ts +97 -17
  31. package/src/init/run-owner-claim.ts +2 -0
  32. package/src/init/webex-auth.ts +68 -0
  33. package/src/inspect/label.ts +13 -2
  34. package/src/inspect/render.ts +5 -3
  35. package/src/permissions/match-rule.ts +7 -3
  36. package/src/permissions/resolve.ts +44 -5
  37. package/src/role-claim/match-rule.ts +7 -2
  38. package/src/secrets/codex-auth-json.ts +52 -17
  39. package/src/secrets/defaults.ts +1 -0
  40. package/src/secrets/encryption.ts +5 -1
  41. package/src/secrets/export-codex-auth-file.ts +26 -3
  42. package/src/secrets/schema.ts +35 -0
  43. package/src/secrets/webex-store.ts +113 -0
  44. package/typeclaw.schema.json +321 -1
package/src/init/index.ts CHANGED
@@ -84,6 +84,7 @@ export type InitStep =
84
84
  | 'oauth-login'
85
85
  | 'scaffold'
86
86
  | 'kakaotalk-auth'
87
+ | 'webex-auth'
87
88
  | 'github-webhooks'
88
89
  | 'install'
89
90
  | 'dockerfile'
@@ -91,6 +92,7 @@ export type InitStep =
91
92
  | 'hatching'
92
93
 
93
94
  export type KakaotalkAuthResult = { ok: true } | { ok: false; reason: string }
95
+ export type WebexAuthResult = { ok: true } | { ok: false; reason: string }
94
96
 
95
97
  // Structured credential block for the GitHub channel adapter. Mirrors the
96
98
  // shape `runAddChannel({ channel: 'github', ... })` consumes so the wizard
@@ -126,6 +128,8 @@ export type InitStepEvent =
126
128
  | { step: 'scaffold'; phase: 'done' }
127
129
  | { step: 'kakaotalk-auth'; phase: 'start' }
128
130
  | { step: 'kakaotalk-auth'; phase: 'done'; result: KakaotalkAuthResult }
131
+ | { step: 'webex-auth'; phase: 'start' }
132
+ | { step: 'webex-auth'; phase: 'done'; result: WebexAuthResult }
129
133
  | { step: 'github-webhooks'; phase: 'start' }
130
134
  | { step: 'github-webhooks'; phase: 'done'; result: EagerGithubWebhookInstallResult }
131
135
  | { step: 'install'; phase: 'start' }
@@ -154,6 +158,7 @@ export type HatchRunner = (options: {
154
158
  }) => Promise<HatchingResult>
155
159
 
156
160
  export type KakaotalkAuthRunner = (options: { cwd: string }) => Promise<KakaotalkAuthResult>
161
+ export type WebexAuthRunner = (options: { cwd: string }) => Promise<WebexAuthResult>
157
162
 
158
163
  export type LineAuthResult = { ok: true } | { ok: false; reason: string }
159
164
  export type LineAuthRunner = (options: { cwd: string }) => Promise<LineAuthResult>
@@ -199,6 +204,7 @@ export type InitOptions = {
199
204
  slackBotToken?: string
200
205
  slackAppToken?: string
201
206
  telegramBotToken?: string
207
+ webexBotToken?: string
202
208
  // When reusing existing channel credentials from a pre-init `secrets.json`,
203
209
  // the CLI passes `with<Adapter>: true` without a corresponding token so the
204
210
  // scaffolded `typeclaw.json` wires the adapter while `writeSecrets` leaves
@@ -207,9 +213,12 @@ export type InitOptions = {
207
213
  withDiscord?: boolean
208
214
  withSlack?: boolean
209
215
  withTelegram?: boolean
216
+ withWebex?: boolean
217
+ withWebexUser?: boolean
210
218
  withKakaotalk?: boolean
211
219
  withGithub?: boolean
212
220
  runKakaotalkAuth?: KakaotalkAuthRunner
221
+ runWebexAuth?: WebexAuthRunner
213
222
  // Structured GitHub credentials collected by the wizard. When omitted and
214
223
  // `withGithub` is true, the existing secrets.json#channels.github block is
215
224
  // reused as-is (the wizard's "reuse existing credentials" path).
@@ -243,12 +252,16 @@ export async function runInit({
243
252
  slackBotToken,
244
253
  slackAppToken,
245
254
  telegramBotToken,
255
+ webexBotToken,
246
256
  withDiscord,
247
257
  withSlack,
248
258
  withTelegram,
259
+ withWebex,
260
+ withWebexUser = false,
249
261
  withKakaotalk = false,
250
262
  withGithub = false,
251
263
  runKakaotalkAuth,
264
+ runWebexAuth,
252
265
  githubCredentials,
253
266
  githubFetchImpl,
254
267
  onProgress,
@@ -314,6 +327,7 @@ export async function runInit({
314
327
  const wantsDiscord = withDiscord ?? (discordBotToken !== undefined && discordBotToken !== '')
315
328
  const wantsSlack = withSlack ?? (slackBotToken !== undefined && slackBotToken !== '')
316
329
  const wantsTelegram = withTelegram ?? (telegramBotToken !== undefined && telegramBotToken !== '')
330
+ const wantsWebex = withWebex ?? (webexBotToken !== undefined && webexBotToken !== '')
317
331
  emit({ step: 'scaffold', phase: 'start' })
318
332
  await scaffold(cwd, {
319
333
  model,
@@ -323,6 +337,8 @@ export async function runInit({
323
337
  withDiscord: wantsDiscord,
324
338
  withSlack: wantsSlack,
325
339
  withTelegram: wantsTelegram,
340
+ withWebex: wantsWebex,
341
+ withWebexUser,
326
342
  withKakaotalk,
327
343
  })
328
344
  // Only write the LLM API key on the api-key path. OAuth providers persist
@@ -338,6 +354,7 @@ export async function runInit({
338
354
  slackBotToken,
339
355
  slackAppToken,
340
356
  telegramBotToken,
357
+ webexBotToken,
341
358
  })
342
359
  emit({ step: 'scaffold', phase: 'done' })
343
360
 
@@ -356,6 +373,15 @@ export async function runInit({
356
373
  }
357
374
  }
358
375
 
376
+ if (withWebexUser && runWebexAuth !== undefined) {
377
+ emit({ step: 'webex-auth', phase: 'start' })
378
+ const result = await runWebexAuth({ cwd })
379
+ emit({ step: 'webex-auth', phase: 'done', result })
380
+ if (!result.ok) {
381
+ throw new Error(`Webex authentication failed: ${result.reason}`)
382
+ }
383
+ }
384
+
359
385
  // Write the structured github channel block alongside scaffold's bot-token
360
386
  // blocks. We do NOT delegate to runAddChannel because that's the `channel
361
387
  // add` semantics — strict no-overwrite, throws when secrets.json#channels
@@ -398,6 +424,8 @@ export async function runInit({
398
424
  if (wantsDiscord) configuredChannels.push('discord-bot')
399
425
  if (wantsSlack) configuredChannels.push('slack-bot')
400
426
  if (wantsTelegram) configuredChannels.push('telegram-bot')
427
+ if (wantsWebex) configuredChannels.push('webex-bot')
428
+ if (withWebexUser) configuredChannels.push('webex')
401
429
  if (withKakaotalk) configuredChannels.push('kakaotalk')
402
430
  if (withGithub) configuredChannels.push('github')
403
431
 
@@ -551,6 +579,8 @@ export type ScaffoldOptions = {
551
579
  withDiscord?: boolean
552
580
  withSlack?: boolean
553
581
  withTelegram?: boolean
582
+ withWebex?: boolean
583
+ withWebexUser?: boolean
554
584
  withKakaotalk?: boolean
555
585
  }
556
586
 
@@ -583,6 +613,8 @@ export async function scaffold(root: string, options: ScaffoldOptions = {}): Pro
583
613
  if (options.withDiscord) channels['discord-bot'] = {}
584
614
  if (options.withSlack) channels['slack-bot'] = {}
585
615
  if (options.withTelegram) channels['telegram-bot'] = {}
616
+ if (options.withWebex) channels['webex-bot'] = {}
617
+ if (options.withWebexUser) channels.webex = {}
586
618
  if (options.withKakaotalk) channels.kakaotalk = {}
587
619
  if (Object.keys(channels).length > 0) config.channels = channels
588
620
  // No default `member` match is seeded. A fresh chat agent starts with every
@@ -796,6 +828,7 @@ export async function writeSecrets(
796
828
  slackBotToken,
797
829
  slackAppToken,
798
830
  telegramBotToken,
831
+ webexBotToken,
799
832
  }: {
800
833
  model?: ModelRef | string
801
834
  // Omitted on the OAuth path — credentials live in secrets.json via the OAuth runner.
@@ -806,6 +839,7 @@ export async function writeSecrets(
806
839
  slackBotToken?: string
807
840
  slackAppToken?: string
808
841
  telegramBotToken?: string
842
+ webexBotToken?: string
809
843
  },
810
844
  ): Promise<void> {
811
845
  const providerId = providerForModelRef(model)
@@ -839,6 +873,9 @@ export async function writeSecrets(
839
873
  if (telegramBotToken !== undefined && telegramBotToken !== '') {
840
874
  channelTokens['telegram-bot'] = { token: { value: telegramBotToken } }
841
875
  }
876
+ if (webexBotToken !== undefined && webexBotToken !== '') {
877
+ channelTokens['webex-bot'] = { token: { value: webexBotToken } }
878
+ }
842
879
  if (Object.keys(channelTokens).length === 0) return
843
880
 
844
881
  const backend = new SecretsBackend(join(root, 'secrets.json'))
@@ -865,18 +902,19 @@ export async function readExistingProviderApiKey(root: string, providerId: Known
865
902
  // browser login entirely instead of dragging them through a second OAuth
866
903
  // flow.
867
904
  //
868
- // Mirrors `readExistingProviderApiKey`'s contract — returns `false` when:
869
- // - The provider has no OAuth support (`oauthProviderId === null`)
870
- // - The file doesn't exist
871
- // - The slot exists but has the wrong shape (api-key instead of oauth, or
872
- // missing access_token)
873
- // - The token is empty / whitespace
905
+ // Mirrors `readExistingProviderApiKey`'s contract — returns `false` when the
906
+ // provider has no OAuth support, the file is missing, the slot is api-key
907
+ // shaped, or the access token is absent/blank.
908
+ //
909
+ // The token lives under `access` — pi-ai's secrets.json shape (`{ type:
910
+ // 'oauth', access, refresh, expires, accountId }`), the same field
911
+ // `export-codex-auth-file.ts` reads. NOT `access_token`: that key belongs to
912
+ // the unrelated `~/.codex/auth.json` export (`{ tokens: { access_token } }`).
913
+ // Reading `access_token` here silently returned false for every real
914
+ // credential, re-running the browser login on resume instead of reusing it.
874
915
  //
875
- // We do NOT validate the token's freshness here. A stale access_token still
876
- // counts as "exists" — pi-ai's secrets store handles refresh on first use,
877
- // and surfacing an "expired token" check at init-time would require a
878
- // network call we'd rather not run during a wizard. The runtime will fall
879
- // back to OAuth login on use if refresh fails; that's a separate UX path.
916
+ // Freshness is intentionally not checked: pi-ai refreshes on first use, and a
917
+ // network call mid-wizard isn't worth it.
880
918
  export async function hasExistingOAuthCredentials(root: string, providerId: KnownProviderId): Promise<boolean> {
881
919
  const provider = KNOWN_PROVIDERS[providerId]
882
920
  if (provider.oauthProviderId === null) return false
@@ -885,8 +923,8 @@ export async function hasExistingOAuthCredentials(root: string, providerId: Know
885
923
  const credential = providers[provider.oauthProviderId]
886
924
  if (credential === undefined) return false
887
925
  if (credential.type !== 'oauth') return false
888
- const accessToken = (credential as { access_token?: unknown }).access_token
889
- return typeof accessToken === 'string' && accessToken.trim().length > 0
926
+ const access = (credential as { access?: unknown }).access
927
+ return typeof access === 'string' && access.trim().length > 0
890
928
  }
891
929
 
892
930
  // Detects whether the requested channel already has usable credentials in
@@ -908,7 +946,7 @@ export async function hasExistingOAuthCredentials(root: string, providerId: Know
908
946
  // kakaotalk` anyway — better to re-auth now during init.
909
947
  export async function hasExistingChannelSecrets(
910
948
  root: string,
911
- channel: 'discord' | 'slack' | 'telegram' | 'line' | 'kakaotalk' | 'github',
949
+ channel: 'discord' | 'slack' | 'telegram' | 'webex' | 'line' | 'kakaotalk' | 'github',
912
950
  ): Promise<boolean> {
913
951
  const channels = new SecretsBackend(join(root, 'secrets.json')).tryReadChannelsSync()
914
952
  if (channels === null) return false
@@ -919,6 +957,8 @@ export async function hasExistingChannelSecrets(
919
957
  return hasSecretField(channels['slack-bot'], 'botToken') && hasSecretField(channels['slack-bot'], 'appToken')
920
958
  case 'telegram':
921
959
  return hasSecretField(channels['telegram-bot'], 'token')
960
+ case 'webex':
961
+ return hasCurrentWebexAccount(channels.webex)
922
962
  case 'github':
923
963
  // GitHub credentials alone are not enough to scaffold a working
924
964
  // channel: typeclaw.json#channels.github also needs webhookUrl and
@@ -977,6 +1017,20 @@ function hasSecretField(slot: unknown, field: string): boolean {
977
1017
  return false
978
1018
  }
979
1019
 
1020
+ function hasCurrentWebexAccount(block: unknown): boolean {
1021
+ if (!isObjectRecord(block)) return false
1022
+ const current = (block as { currentAccount?: unknown }).currentAccount
1023
+ if (typeof current !== 'string' || current.length === 0) return false
1024
+ const accounts = (block as { accounts?: unknown }).accounts
1025
+ if (!isObjectRecord(accounts)) return false
1026
+ const account = accounts[current]
1027
+ if (!isObjectRecord(account)) return false
1028
+ const token = (account as { access_token?: unknown }).access_token
1029
+ const email = (account as { email?: unknown }).email
1030
+ const encryptedPassword = (account as { encryptedPassword?: unknown }).encryptedPassword
1031
+ return typeof token === 'string' && token.length > 0 && typeof email === 'string' && isObjectRecord(encryptedPassword)
1032
+ }
1033
+
980
1034
  function isObjectRecord(value: unknown): value is Record<string, unknown> {
981
1035
  return typeof value === 'object' && value !== null && !Array.isArray(value)
982
1036
  }
@@ -1013,7 +1067,15 @@ function ignoreExists(error: NodeJS.ErrnoException): void {
1013
1067
  // scaffold-test cases above demonstrates how easy it is to lose a single
1014
1068
  // behavior under a mode flag.
1015
1069
 
1016
- export type ChannelKind = 'discord-bot' | 'slack-bot' | 'telegram-bot' | 'line' | 'kakaotalk' | 'github'
1070
+ export type ChannelKind =
1071
+ | 'discord-bot'
1072
+ | 'slack-bot'
1073
+ | 'telegram-bot'
1074
+ | 'webex'
1075
+ | 'webex-bot'
1076
+ | 'line'
1077
+ | 'kakaotalk'
1078
+ | 'github'
1017
1079
 
1018
1080
  // Public adapter names match the typeclaw.json `channels.*` keys exactly.
1019
1081
  // The CLI takes these as the optional positional arg, the picker shows
@@ -1023,12 +1085,14 @@ export const CHANNEL_KINDS: ReadonlyArray<ChannelKind> = [
1023
1085
  'slack-bot',
1024
1086
  'discord-bot',
1025
1087
  'telegram-bot',
1088
+ 'webex',
1089
+ 'webex-bot',
1026
1090
  'line',
1027
1091
  'kakaotalk',
1028
1092
  'github',
1029
1093
  ]
1030
1094
 
1031
- export type AddChannelStep = 'line-auth' | 'kakaotalk-auth' | 'config' | 'secrets' | 'github-webhooks'
1095
+ export type AddChannelStep = 'line-auth' | 'kakaotalk-auth' | 'webex-auth' | 'config' | 'secrets' | 'github-webhooks'
1032
1096
 
1033
1097
  export type AddChannelStepEvent =
1034
1098
  | { step: 'config'; phase: 'start' }
@@ -1037,6 +1101,8 @@ export type AddChannelStepEvent =
1037
1101
  | { step: 'line-auth'; phase: 'done'; result: LineAuthResult }
1038
1102
  | { step: 'kakaotalk-auth'; phase: 'start' }
1039
1103
  | { step: 'kakaotalk-auth'; phase: 'done'; result: KakaotalkAuthResult }
1104
+ | { step: 'webex-auth'; phase: 'start' }
1105
+ | { step: 'webex-auth'; phase: 'done'; result: WebexAuthResult }
1040
1106
  | { step: 'secrets'; phase: 'start' }
1041
1107
  | { step: 'secrets'; phase: 'done' }
1042
1108
  | { step: 'github-webhooks'; phase: 'start' }
@@ -1052,6 +1118,8 @@ export type AddChannelOptions = {
1052
1118
  | { channel: 'discord-bot'; discordBotToken: string }
1053
1119
  | { channel: 'slack-bot'; slackBotToken: string; slackAppToken: string }
1054
1120
  | { channel: 'telegram-bot'; telegramBotToken: string }
1121
+ | { channel: 'webex-bot'; webexBotToken: string }
1122
+ | { channel: 'webex'; runWebexAuth: WebexAuthRunner }
1055
1123
  | { channel: 'line'; runLineAuth: LineAuthRunner }
1056
1124
  | { channel: 'kakaotalk'; runKakaotalkAuth: KakaotalkAuthRunner }
1057
1125
  | {
@@ -1093,6 +1161,13 @@ export async function runAddChannel(options: AddChannelOptions): Promise<void> {
1093
1161
  if (!result.ok) throw new Error(`KakaoTalk authentication failed: ${result.reason}`)
1094
1162
  }
1095
1163
 
1164
+ if (options.channel === 'webex') {
1165
+ emit({ step: 'webex-auth', phase: 'start' })
1166
+ const result = await options.runWebexAuth({ cwd: options.cwd })
1167
+ emit({ step: 'webex-auth', phase: 'done', result })
1168
+ if (!result.ok) throw new Error(`Webex authentication failed: ${result.reason}`)
1169
+ }
1170
+
1096
1171
  emit({ step: 'config', phase: 'start' })
1097
1172
  await mergeChannelIntoConfig(options.cwd, options)
1098
1173
  emit({ step: 'config', phase: 'done' })
@@ -1165,6 +1240,10 @@ function channelSecretsFromOptions(options: AddChannelOptions): ChannelSecrets {
1165
1240
  return { botToken: options.slackBotToken, appToken: options.slackAppToken }
1166
1241
  case 'telegram-bot':
1167
1242
  return { token: options.telegramBotToken }
1243
+ case 'webex-bot':
1244
+ return { token: options.webexBotToken }
1245
+ case 'webex':
1246
+ return {}
1168
1247
  case 'line':
1169
1248
  // LINE auth writes its structured account block directly to
1170
1249
  // secrets.json#channels.line before config mutation.
@@ -1448,7 +1527,7 @@ async function appendChannelSecrets(cwd: string, channel: ChannelKind, tokens: C
1448
1527
 
1449
1528
  export type SetChannelTokensResult = { ok: true } | { ok: false; reason: string }
1450
1529
 
1451
- type BotTokenAdapter = 'discord-bot' | 'slack-bot' | 'telegram-bot'
1530
+ type BotTokenAdapter = 'discord-bot' | 'slack-bot' | 'telegram-bot' | 'webex-bot'
1452
1531
 
1453
1532
  // Required credential fields per adapter. Used post-merge to refuse a
1454
1533
  // rotation that would leave the adapter half-configured — e.g. rotating
@@ -1459,6 +1538,7 @@ const REQUIRED_CHANNEL_FIELDS: Record<BotTokenAdapter, readonly string[]> = {
1459
1538
  'discord-bot': ['token'],
1460
1539
  'slack-bot': ['botToken', 'appToken'],
1461
1540
  'telegram-bot': ['token'],
1541
+ 'webex-bot': ['token'],
1462
1542
  }
1463
1543
 
1464
1544
  // Preserve a user-authored `{ env: 'CUSTOM_NAME' }` rebinding when rotating
@@ -10,6 +10,8 @@ const CHANNEL_LABELS: Record<ChannelKind, string> = {
10
10
  'discord-bot': 'Discord',
11
11
  github: 'GitHub',
12
12
  'telegram-bot': 'Telegram',
13
+ webex: 'Webex (User)',
14
+ 'webex-bot': 'Webex',
13
15
  line: 'LINE',
14
16
  kakaotalk: 'KakaoTalk',
15
17
  }
@@ -0,0 +1,68 @@
1
+ import { join, resolve } from 'node:path'
2
+
3
+ import { loginWithPassword as upstreamLoginWithPassword, type PasswordLoginResult } from 'agent-messenger/webex'
4
+
5
+ import { containerNameFromCwd } from '@/container'
6
+ import { keysDir } from '@/hostd/paths'
7
+ import { encrypt } from '@/secrets/encryption'
8
+ import { createKeyStore, type KeyStore } from '@/secrets/keys'
9
+ import type { WebexAccountRecord } from '@/secrets/schema'
10
+ import { SecretsWebexCredentialStore } from '@/secrets/webex-store'
11
+
12
+ export type WebexBootstrapStatus = { ok: true } | { ok: false; reason: string }
13
+
14
+ export type LoginWithPasswordFn = typeof upstreamLoginWithPassword
15
+
16
+ export type WebexLoginInput = {
17
+ email: string
18
+ password: string
19
+ agentDir: string
20
+ idbrokerHost?: string
21
+ loginWithPassword?: LoginWithPasswordFn
22
+ keyStore?: KeyStore
23
+ containerName?: string
24
+ }
25
+
26
+ export function webexSecretsPath(agentDir: string): string {
27
+ return join(agentDir, 'secrets.json')
28
+ }
29
+
30
+ export async function runWebexBootstrap(input: WebexLoginInput): Promise<WebexBootstrapStatus> {
31
+ try {
32
+ const loginWithPassword = input.loginWithPassword ?? upstreamLoginWithPassword
33
+ const store = new SecretsWebexCredentialStore({ mode: 'host', secretsPath: webexSecretsPath(input.agentDir) })
34
+ const loginOptions = input.idbrokerHost !== undefined ? { idbrokerHost: input.idbrokerHost } : undefined
35
+ const result = await loginWithPassword(input.email, input.password, loginOptions)
36
+
37
+ const now = new Date().toISOString()
38
+ const accountId = result.userId || input.email
39
+ const containerName = input.containerName ?? containerNameFromCwd(resolve(input.agentDir))
40
+ const keyStore = input.keyStore ?? createKeyStore({ keysDir: keysDir() })
41
+ const key = await keyStore.ensure(containerName)
42
+ const encryptedPassword = encrypt(input.password, key, {
43
+ containerName,
44
+ accountId,
45
+ purpose: 'webex-password',
46
+ })
47
+ const account: WebexAccountRecord = {
48
+ account_id: accountId,
49
+ access_token: result.accessToken,
50
+ refresh_token: result.refreshToken,
51
+ expires_at: result.expiresAt,
52
+ device_url: result.deviceUrl,
53
+ user_id: result.userId,
54
+ created_at: now,
55
+ updated_at: now,
56
+ email: input.email,
57
+ encryptedPassword,
58
+ }
59
+ await store.setAccount(account)
60
+ await store.setCurrentAccount(accountId)
61
+
62
+ return { ok: true }
63
+ } catch (err) {
64
+ return { ok: false, reason: err instanceof Error ? err.message : String(err) }
65
+ }
66
+ }
67
+
68
+ export type { PasswordLoginResult }
@@ -1,15 +1,19 @@
1
1
  import type { MinimalSessionOrigin } from '@/agent/session-meta'
2
+ import { toRef } from '@/channels/adapters/webex-id-ref'
2
3
 
3
4
  const ADAPTER_DISPLAY: Record<string, string> = {
4
5
  'slack-bot': 'Slack',
5
6
  'discord-bot': 'Discord',
6
7
  github: 'GitHub',
7
8
  'telegram-bot': 'Telegram',
9
+ webex: 'Webex',
10
+ 'webex-bot': 'Webex',
8
11
  line: 'LINE',
9
12
  kakaotalk: 'KakaoTalk',
10
13
  }
11
14
 
12
15
  const SLACK_CHAT_PREFIX_ADAPTERS = new Set(['slack-bot', 'discord-bot'])
16
+ const WEBEX_ADAPTERS = new Set(['webex', 'webex-bot'])
13
17
 
14
18
  export function originLabel(origin: MinimalSessionOrigin): string {
15
19
  switch (origin.kind) {
@@ -39,12 +43,19 @@ function renderChat(origin: Extract<MinimalSessionOrigin, { kind: 'channel' }>):
39
43
  const prefix = SLACK_CHAT_PREFIX_ADAPTERS.has(origin.adapter) ? '#' : ''
40
44
  return `${prefix}${origin.chatName}`
41
45
  }
42
- return origin.chat
46
+ return readableId(origin.adapter, origin.chat)
43
47
  }
44
48
 
45
49
  function renderWorkspace(origin: Extract<MinimalSessionOrigin, { kind: 'channel' }>): string {
46
50
  if (origin.workspaceName !== undefined && origin.workspaceName !== '') return origin.workspaceName
47
- return origin.workspace
51
+ return readableId(origin.adapter, origin.workspace)
52
+ }
53
+
54
+ // Webex room/workspace/person ids are base64 `ciscospark://` blobs that read as
55
+ // gibberish. With no resolved title, decode to the trailing ref (a UUID) so the
56
+ // row is at least skimmable; non-Webex ids pass through.
57
+ export function readableId(adapter: string, id: string): string {
58
+ return WEBEX_ADAPTERS.has(adapter) ? toRef(id) : id
48
59
  }
49
60
 
50
61
  export function shortSessionId(sessionId: string): string {
@@ -1,6 +1,6 @@
1
1
  import { styleText } from 'node:util'
2
2
 
3
- import { originLabel } from './label'
3
+ import { originLabel, readableId } from './label'
4
4
  import type { InspectEvent } from './types'
5
5
 
6
6
  export type RenderOptions = {
@@ -120,8 +120,10 @@ function renderBody(event: InspectEvent, opts: RenderOptions): string {
120
120
  }
121
121
 
122
122
  function renderInboundBody(event: Extract<InspectEvent, { cat: 'inbound' }>, opts: RenderOptions): string {
123
- const coord = `${event.adapter}:${event.workspace}/${event.chat}${event.thread === null ? '' : `#${event.thread}`}`
124
- const who = event.authorName !== '' ? event.authorName : event.authorId
123
+ const workspace = readableId(event.adapter, event.workspace)
124
+ const chat = readableId(event.adapter, event.chat)
125
+ const coord = `${event.adapter}:${workspace}/${chat}${event.thread === null ? '' : `#${event.thread}`}`
126
+ const who = event.authorName !== '' ? event.authorName : readableId(event.adapter, event.authorId)
125
127
  const decisionTag = tint(opts, decisionColor(event.decision), `[${event.decision}]`)
126
128
  const text = truncate(singleLine(event.text), opts.maxTextLength ?? DEFAULT_MAX_TEXT)
127
129
  return `${decisionTag} ${tint(opts, 'dim', coord)} ${who}: ${text}`
@@ -16,7 +16,7 @@
16
16
  // error messages with typo suggestions; a single big regex would only ever
17
17
  // say "didn't match".
18
18
 
19
- export const PLATFORMS = ['slack', 'discord', 'telegram', 'line', 'kakao', 'github'] as const
19
+ export const PLATFORMS = ['slack', 'discord', 'telegram', 'webex', 'line', 'kakao', 'github'] as const
20
20
  export type Platform = (typeof PLATFORMS)[number]
21
21
 
22
22
  const SUBAGENT_NAME = /^[a-z][a-z0-9-]*$/
@@ -50,8 +50,12 @@ export type ParseMatchRuleResult = { ok: true; value: MatchRule } | { ok: false;
50
50
  // run and emit typo suggestions like `autor:` -> `author:`. If we tightened
51
51
  // this to `author:` only, the JSON schema would reject typos with a generic
52
52
  // "did not match pattern" error and the user would lose the actionable hint.
53
- export const MATCH_RULE_REGEX_SOURCE =
54
- '^(tui|cron|subagent(:[a-z][a-z0-9-]*)?|\\*|(slack|discord|telegram|line|kakao|github):[^\\s]+)(\\s+[a-zA-Z][a-zA-Z0-9_]*:[^\\s]+)*$'
53
+ //
54
+ // The platform alternation is derived from PLATFORMS so a newly added
55
+ // platform can never validate at the parser but be rejected by this schema
56
+ // regex (the bug that shipped when 'webex' was added to PLATFORMS but not
57
+ // here).
58
+ export const MATCH_RULE_REGEX_SOURCE = `^(tui|cron|subagent(:[a-z][a-z0-9-]*)?|\\*|(${PLATFORMS.join('|')}):[^\\s]+)(\\s+[a-zA-Z][a-zA-Z0-9_]*:[^\\s]+)*$`
55
59
 
56
60
  export function parseMatchRule(input: string): ParseMatchRuleResult {
57
61
  if (input !== input.trim() || input.length === 0) {
@@ -1,3 +1,4 @@
1
+ import { decodeWebexId } from '@/channels/adapters/webex-id-ref'
1
2
  import type { AdapterId } from '@/channels/schema'
2
3
 
3
4
  import type { MatchRule, Platform } from './match-rule'
@@ -7,6 +8,8 @@ const ADAPTER_TO_PLATFORM: Record<AdapterId, Platform> = {
7
8
  'discord-bot': 'discord',
8
9
  github: 'github',
9
10
  'telegram-bot': 'telegram',
11
+ webex: 'webex',
12
+ 'webex-bot': 'webex',
10
13
  line: 'line',
11
14
  kakaotalk: 'kakao',
12
15
  }
@@ -52,17 +55,52 @@ function matchesChannel(rule: Extract<MatchRule, { kind: 'channel' }>, origin: M
52
55
  if (rule.chat !== undefined && rule.chat !== origin.chat) return false
53
56
  }
54
57
 
55
- if (rule.author !== undefined && rule.author !== origin.lastInboundAuthorId) return false
58
+ if (rule.author !== undefined && !matchesAuthor(rule.platform, rule.author, origin.lastInboundAuthorId)) return false
56
59
  return true
57
60
  }
58
61
 
62
+ // Webex person ids are base64(`ciscospark://<cluster>/PEOPLE/<uuid-or-email>`),
63
+ // so a hand-authored or claim-generated rule may carry the raw base64 id, its
64
+ // decoded ref (UUID for modern accounts, email for legacy Hydra accounts), and
65
+ // the inbound may arrive as either. We compare on the decoded PERSON ref when
66
+ // BOTH sides decode to a PEOPLE id, and otherwise fall back to raw equality —
67
+ // so `author:<uuid>`, `author:<legacy-email>`, and the legacy `author:<base64>`
68
+ // all match the same human. A value that decodes to a non-PERSON type (e.g. a
69
+ // room id pasted into `author:`) never normalizes, so it can only ever raw-
70
+ // match — a room uuid can never satisfy an author rule.
71
+ function matchesAuthor(platform: Platform, ruleAuthor: string, inboundAuthorId: string | undefined): boolean {
72
+ if (inboundAuthorId === undefined) return false
73
+ if (ruleAuthor === inboundAuthorId) return true
74
+ if (platform !== 'webex') return false
75
+ // Both sides must resolve to a real PERSON ref. `webexPersonRef` returns null
76
+ // for any non-PEOPLE id, and null === null would otherwise let two different
77
+ // room/message ids satisfy an `author:` rule — so require both non-null.
78
+ const ruleRef = webexPersonRef(ruleAuthor)
79
+ const inboundRef = webexPersonRef(inboundAuthorId)
80
+ return ruleRef !== null && inboundRef !== null && ruleRef === inboundRef
81
+ }
82
+
83
+ // Returns the comparable person identity for a Webex `author:` value: the
84
+ // decoded trailing ref when the value is a base64 PEOPLE id, or the value
85
+ // itself when it is already a ref (bare uuid/email). Returns null for anything
86
+ // that decodes to a non-PERSON Webex id, so two different resource types can
87
+ // never be coerced into matching. Emails are lower-cased so case variation in
88
+ // a legacy-account ref does not silently deny a grant. Keep this for backward
89
+ // compatibility with pre-migration rules that still carry blob-form ids.
90
+ function webexPersonRef(value: string): string | null {
91
+ const decoded = decodeWebexId(value)
92
+ if (decoded === null) return value.includes('@') ? value.toLowerCase() : value
93
+ if (decoded.type !== 'PEOPLE') return null
94
+ return decoded.uuid.includes('@') ? decoded.uuid.toLowerCase() : decoded.uuid
95
+ }
96
+
59
97
  // DM and group buckets are inferred from the workspace/chat shape of the
60
- // inbound origin. Different adapters mark DMs differently — Slack uses an
61
- // `@dm` workspace marker today, Discord uses a `dm` workspace marker, and
98
+ // inbound origin. Different adapters mark DMs differently — Slack and Webex
99
+ // use an `@dm` workspace marker, Discord uses a `dm` workspace marker, and
62
100
  // KakaoTalk preserves group/open/dm explicitly in its workspace field. We
63
101
  // keep the heuristic narrow: a rule that says `slack:dm/*` matches only when
64
- // the origin's workspace is `@dm` (Slack) or `dm` (Discord). KakaoTalk uses
65
- // the workspace prefix itself.
102
+ // the origin's workspace is `@dm` (Slack/Webex) or `dm` (Discord). KakaoTalk
103
+ // uses the workspace prefix itself.
66
104
  function matchesBucket(
67
105
  bucket: 'dm' | 'group' | 'open' | 'square',
68
106
  origin: Extract<MatchableOrigin, { kind: 'channel' }>,
@@ -84,6 +122,7 @@ function matchesBucket(
84
122
  if (platform === 'slack') return origin.workspace === '@dm'
85
123
  if (platform === 'discord') return origin.workspace === 'dm' || origin.workspace === '@dm'
86
124
  if (platform === 'telegram') return origin.workspace === 'dm' || origin.workspace.startsWith('@')
125
+ if (platform === 'webex') return origin.workspace === '@dm'
87
126
  return false
88
127
  }
89
128
 
@@ -27,17 +27,22 @@ export type PartialChannelOrigin = {
27
27
 
28
28
  const ADAPTER_TO_PLATFORM: Record<
29
29
  ChannelKey['adapter'],
30
- 'slack' | 'discord' | 'telegram' | 'kakao' | 'line' | 'github'
30
+ 'slack' | 'discord' | 'telegram' | 'webex' | 'kakao' | 'line' | 'github'
31
31
  > = {
32
32
  'slack-bot': 'slack',
33
33
  'discord-bot': 'discord',
34
34
  github: 'github',
35
35
  'telegram-bot': 'telegram',
36
+ webex: 'webex',
37
+ 'webex-bot': 'webex',
36
38
  line: 'line',
37
39
  kakaotalk: 'kakao',
38
40
  }
39
41
 
40
42
  export function formatClaimMatchRule(origin: PartialChannelOrigin): string {
41
43
  const platform = ADAPTER_TO_PLATFORM[origin.adapter]
42
- return `${platform}:* author:${origin.authorId}`
44
+ // Webex authorIds are stored as decoded refs (UUID, or email for legacy
45
+ // accounts). The matcher still normalizes older blob-form rules/inbounds.
46
+ const author = origin.authorId
47
+ return `${platform}:* author:${author}`
43
48
  }