typeclaw 0.38.0 → 0.39.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/auth.schema.json +109 -0
- package/package.json +2 -2
- package/secrets.schema.json +109 -0
- package/src/agent/attention-escalation.ts +4 -3
- package/src/agent/auth.ts +2 -2
- package/src/agent/index.ts +25 -2
- package/src/agent/restart/index.ts +17 -8
- package/src/agent/session-origin.ts +15 -2
- package/src/agent/subagents.ts +29 -1
- package/src/agent/system-prompt.ts +18 -5
- package/src/agent/tools/restart.ts +0 -3
- package/src/agent/tools/spawn-subagent.ts +7 -0
- package/src/bundled-plugins/memory/README.md +12 -1
- package/src/bundled-plugins/memory/index.ts +63 -8
- package/src/bundled-plugins/memory/memory-logger.ts +14 -10
- package/src/bundled-plugins/operator/operator.ts +1 -0
- package/src/channels/adapters/kakaotalk.ts +1 -1
- package/src/channels/adapters/webex-bot-classify.ts +20 -14
- package/src/channels/adapters/webex-bot-reference.ts +8 -6
- package/src/channels/adapters/webex-bot.ts +106 -39
- package/src/channels/adapters/webex-channel-resolver.ts +29 -0
- package/src/channels/adapters/webex-classify.ts +104 -0
- package/src/channels/adapters/webex-format.ts +53 -0
- package/src/channels/adapters/webex-id-ref.ts +32 -0
- package/src/channels/adapters/webex-reference.ts +49 -0
- package/src/channels/adapters/webex.ts +493 -0
- package/src/channels/manager.ts +63 -7
- package/src/channels/persistence.ts +67 -5
- package/src/channels/router.ts +8 -0
- package/src/channels/schema.ts +2 -0
- package/src/cli/channel.ts +118 -7
- package/src/cli/init.ts +70 -1
- package/src/cli/model.ts +143 -3
- package/src/config/channels-mutation.ts +2 -1
- package/src/config/config.ts +94 -31
- package/src/config/index.ts +3 -0
- package/src/config/models-mutation.ts +105 -15
- package/src/config/providers-mutation.ts +4 -4
- package/src/config/providers.ts +6 -14
- package/src/container/shared.ts +21 -0
- package/src/container/start.ts +25 -7
- package/src/doctor/channel-checks.ts +43 -0
- package/src/hostd/daemon.ts +7 -5
- package/src/hostd/index.ts +1 -11
- package/src/hostd/paths.ts +0 -16
- package/src/hostd/protocol.ts +2 -2
- package/src/init/checkpoint.ts +1 -1
- package/src/init/index.ts +60 -3
- package/src/init/run-owner-claim.ts +1 -0
- package/src/init/webex-auth.ts +68 -0
- package/src/inspect/label.ts +13 -2
- package/src/inspect/render.ts +5 -3
- package/src/permissions/resolve.ts +38 -1
- package/src/role-claim/match-rule.ts +5 -1
- package/src/run/index.ts +4 -1
- package/src/secrets/codex-auth-json.ts +52 -17
- package/src/secrets/encryption.ts +5 -1
- package/src/secrets/export-codex-auth-file.ts +26 -3
- package/src/secrets/schema.ts +35 -0
- package/src/secrets/webex-store.ts +113 -0
- package/src/skills/typeclaw-config/SKILL.md +18 -16
- package/typeclaw.schema.json +326 -0
package/src/container/shared.ts
CHANGED
|
@@ -108,6 +108,27 @@ export async function buildxAvailable(exec: DockerExec = defaultDockerExec): Pro
|
|
|
108
108
|
return (await exec(['buildx', 'version'])).exitCode === 0
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
+
export type BindMountSpec = { src: string; dst: string; readonly?: boolean }
|
|
112
|
+
|
|
113
|
+
// Emits `--mount type=bind,...` argv for a host->container bind mount, used in
|
|
114
|
+
// place of the legacy `-v src:dst[:ro]` form. The `-v` short form splits on
|
|
115
|
+
// `:`, which collides with a Windows drive letter (`C:\agent` parses as host
|
|
116
|
+
// `C` + path `\agent`); `--mount`'s `key=value` CSV has no such ambiguity and
|
|
117
|
+
// fails loud on an unknown/missing key instead of silently creating a phantom
|
|
118
|
+
// host dir. Src is resolved to an absolute path because `--mount` (unlike `-v`)
|
|
119
|
+
// rejects relative sources. A literal comma in a path would break the CSV;
|
|
120
|
+
// it's rejected here rather than silently mis-parsed (paths with commas are
|
|
121
|
+
// pathological and were never supported by the `-v` form either).
|
|
122
|
+
export function dockerBindMount({ src, dst, readonly }: BindMountSpec): [string, string] {
|
|
123
|
+
const absSrc = resolve(src)
|
|
124
|
+
if (absSrc.includes(',') || dst.includes(',')) {
|
|
125
|
+
throw new Error(`bind mount path contains a comma, which docker --mount cannot express: ${absSrc} -> ${dst}`)
|
|
126
|
+
}
|
|
127
|
+
const fields = [`type=bind`, `src=${absSrc}`, `dst=${dst}`]
|
|
128
|
+
if (readonly) fields.push('readonly')
|
|
129
|
+
return ['--mount', fields.join(',')]
|
|
130
|
+
}
|
|
131
|
+
|
|
111
132
|
export function containerNameFromCwd(cwd: string): string {
|
|
112
133
|
return sanitizeContainerName(basename(resolve(cwd)))
|
|
113
134
|
}
|
package/src/container/start.ts
CHANGED
|
@@ -26,6 +26,7 @@ import { buildGitignore, GITIGNORE_FILE } from '@/init/gitignore'
|
|
|
26
26
|
import { refreshPackageJson } from '@/init/packagejson'
|
|
27
27
|
import { reconcilePluginDeps } from '@/init/reconcile-plugin-deps'
|
|
28
28
|
import { runBunUpdate, type UpdateRunner } from '@/init/run-bun-install'
|
|
29
|
+
import { isWindows } from '@/shared'
|
|
29
30
|
import { hostLocaleIsCjk } from '@/shared/host-locale'
|
|
30
31
|
|
|
31
32
|
import { CONTAINER_PORT, TUI_TOKEN_LABEL, findFreePort, isPortAllocatedError, resolveTuiToken } from './port'
|
|
@@ -37,6 +38,7 @@ import {
|
|
|
37
38
|
defaultDockerExec,
|
|
38
39
|
type DockerExec,
|
|
39
40
|
type DockerExecResult,
|
|
41
|
+
dockerBindMount,
|
|
40
42
|
imageTagFromCwd,
|
|
41
43
|
isContainerNameConflict,
|
|
42
44
|
sanitizeDockerStderr,
|
|
@@ -656,18 +658,16 @@ export async function planStart({
|
|
|
656
658
|
runArgs.push('-e', `TYPECLAW_HOSTD_BROKER_TOKEN=${hostdControl.brokerToken}`)
|
|
657
659
|
}
|
|
658
660
|
|
|
659
|
-
runArgs.push('
|
|
661
|
+
runArgs.push(...dockerBindMount({ src: cwd, dst: '/agent' }))
|
|
660
662
|
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
if (devSourcePath && !devSourcePath.startsWith(cwd)) {
|
|
664
|
-
runArgs.push('-v', `${devSourcePath}:${devSourcePath}:ro`)
|
|
663
|
+
if (shouldMirrorDevSource(devSourcePath, cwd)) {
|
|
664
|
+
runArgs.push(...dockerBindMount({ src: devSourcePath, dst: devSourcePath, readonly: true }))
|
|
665
665
|
}
|
|
666
666
|
|
|
667
667
|
for (const mount of mounts) {
|
|
668
668
|
const hostPath = expandMountPath(mount.path, cwd)
|
|
669
669
|
const target = `${MOUNT_TARGET_PREFIX}/${mount.name}`
|
|
670
|
-
runArgs.push(
|
|
670
|
+
runArgs.push(...dockerBindMount({ src: hostPath, dst: target, readonly: mount.readOnly }))
|
|
671
671
|
}
|
|
672
672
|
|
|
673
673
|
// Shared model cache mount for embeddings. Gated on vector opt-in: a
|
|
@@ -676,7 +676,7 @@ export async function planStart({
|
|
|
676
676
|
// so mounting an empty cache would only invite a confusing local_files_only
|
|
677
677
|
// miss if something inside the container reached for the model anyway.
|
|
678
678
|
if (agentUsesVector(cwd)) {
|
|
679
|
-
runArgs.push(
|
|
679
|
+
runArgs.push(...dockerBindMount({ src: join(homeRoot(), 'models'), dst: '/opt/models', readonly: true }))
|
|
680
680
|
runArgs.push('-e', 'TYPECLAW_MODEL_CACHE=/opt/models')
|
|
681
681
|
}
|
|
682
682
|
|
|
@@ -915,6 +915,24 @@ async function detectDevSource(cwd: string): Promise<string | null> {
|
|
|
915
915
|
}
|
|
916
916
|
}
|
|
917
917
|
|
|
918
|
+
// Dev mode: node_modules/typeclaw is a symlink to an absolute host path outside
|
|
919
|
+
// /agent. The mirror mount bind-mounts that path at the SAME path inside the
|
|
920
|
+
// (Linux) container so the symlink resolves. That only works when the host path
|
|
921
|
+
// is itself a valid Linux container path — true on POSIX, false on native
|
|
922
|
+
// Windows where devSourcePath is `C:\...` (not an absolute Linux path, so it
|
|
923
|
+
// cannot be a container mount `dst`, and the in-container symlink would point at
|
|
924
|
+
// a Windows path regardless). Native-Windows dev-mode (file:/link: typeclaw dep)
|
|
925
|
+
// needs the deferred symlink/junction translation in #899; until then we skip
|
|
926
|
+
// the mirror mount rather than emit an invalid `dst`. End users install typeclaw
|
|
927
|
+
// from npm (a registry spec, not file:), so they never hit this path.
|
|
928
|
+
export function shouldMirrorDevSource(
|
|
929
|
+
devSourcePath: string | null,
|
|
930
|
+
cwd: string,
|
|
931
|
+
platform: NodeJS.Platform = process.platform,
|
|
932
|
+
): devSourcePath is string {
|
|
933
|
+
return devSourcePath !== null && !devSourcePath.startsWith(cwd) && !isWindows(platform)
|
|
934
|
+
}
|
|
935
|
+
|
|
918
936
|
// True when the agent's package.json declares typeclaw via `file:` or
|
|
919
937
|
// `link:` — i.e. a developer is iterating on the typeclaw source via a
|
|
920
938
|
// locally-linked checkout. `bun install` keys its file-dep cache on
|
|
@@ -29,6 +29,7 @@ export function buildChannelChecks(): DoctorCheck[] {
|
|
|
29
29
|
discordBotCredentials(),
|
|
30
30
|
telegramBotCredentials(),
|
|
31
31
|
webexBotCredentials(),
|
|
32
|
+
webexUserCredentials(),
|
|
32
33
|
lineCredentials(),
|
|
33
34
|
kakaotalkCredentials(),
|
|
34
35
|
githubCredentials(),
|
|
@@ -76,6 +77,32 @@ function webexBotCredentials(): DoctorCheck {
|
|
|
76
77
|
}
|
|
77
78
|
}
|
|
78
79
|
|
|
80
|
+
function webexUserCredentials(): DoctorCheck {
|
|
81
|
+
return {
|
|
82
|
+
name: 'channel.webex.credentials',
|
|
83
|
+
category: 'channels',
|
|
84
|
+
description: 'webex adapter has a current account with an access token in secrets.json',
|
|
85
|
+
applies: (ctx) => ctx.hasAgentFolder,
|
|
86
|
+
async run(ctx) {
|
|
87
|
+
const channels = readDeclaredChannels(ctx)
|
|
88
|
+
if (channels === null) return configInvalidResult()
|
|
89
|
+
if (!isAdapterActive(channels, 'webex')) {
|
|
90
|
+
return { status: 'skipped', message: 'webex not configured' }
|
|
91
|
+
}
|
|
92
|
+
const block = readChannelsSecrets(ctx)?.webex
|
|
93
|
+
if (!hasCurrentAccountToken(block)) {
|
|
94
|
+
return {
|
|
95
|
+
status: 'warning',
|
|
96
|
+
message: 'webex has no current account access_token in secrets.json',
|
|
97
|
+
details: ['Adapter will start but fail authentication and stay disconnected.'],
|
|
98
|
+
fix: { description: 'Run `typeclaw channel add webex` to log in an account.' },
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return { status: 'ok', message: 'webex has a current account access_token' }
|
|
102
|
+
},
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
79
106
|
function lineCredentials(): DoctorCheck {
|
|
80
107
|
return {
|
|
81
108
|
name: 'channel.line.credentials',
|
|
@@ -326,6 +353,22 @@ function isSecretShape(value: unknown): value is { value?: string; env?: string
|
|
|
326
353
|
return hasValue || hasEnv
|
|
327
354
|
}
|
|
328
355
|
|
|
356
|
+
function hasCurrentAccountToken(block: unknown): boolean {
|
|
357
|
+
if (!isObjectRecord(block)) return false
|
|
358
|
+
const current = (block as { currentAccount?: unknown }).currentAccount
|
|
359
|
+
if (typeof current !== 'string' || current.length === 0) return false
|
|
360
|
+
const accounts = (block as { accounts?: unknown }).accounts
|
|
361
|
+
if (!isObjectRecord(accounts)) return false
|
|
362
|
+
const account = accounts[current]
|
|
363
|
+
if (!isObjectRecord(account)) return false
|
|
364
|
+
const token = (account as { access_token?: unknown }).access_token
|
|
365
|
+
return typeof token === 'string' && token.length > 0
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
function isObjectRecord(value: unknown): value is Record<string, unknown> {
|
|
369
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
370
|
+
}
|
|
371
|
+
|
|
329
372
|
function readDeclaredChannels(ctx: CheckContext): ChannelsConfig | null {
|
|
330
373
|
const cfg = safeLoadConfig(ctx)
|
|
331
374
|
return cfg?.channels ?? null
|
package/src/hostd/daemon.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { join } from 'node:path'
|
|
|
6
6
|
import type { PortForward } from '@/config'
|
|
7
7
|
import { defaultDockerExec, type DockerExec } from '@/container'
|
|
8
8
|
import type { PortForwardEvent } from '@/portbroker'
|
|
9
|
-
import { kakaoChannelBlockSchema, lineChannelBlockSchema } from '@/secrets/schema'
|
|
9
|
+
import { kakaoChannelBlockSchema, lineChannelBlockSchema, webexChannelBlockSchema } from '@/secrets/schema'
|
|
10
10
|
import { SecretsBackend } from '@/secrets/storage'
|
|
11
11
|
import { isWindows } from '@/shared'
|
|
12
12
|
|
|
@@ -450,19 +450,21 @@ export async function startDaemon(opts: DaemonOptions = {}): Promise<Daemon> {
|
|
|
450
450
|
|
|
451
451
|
const handleSecretsPatch = async (req: {
|
|
452
452
|
containerName: string
|
|
453
|
-
patch: { channels: { kakaotalk: unknown } | { line: unknown } }
|
|
453
|
+
patch: { channels: { kakaotalk: unknown } | { line: unknown } | { webex: unknown } }
|
|
454
454
|
}): Promise<RpcResponse> =>
|
|
455
455
|
runSerially(req.containerName, async () => {
|
|
456
456
|
const cwd = cwds.get(req.containerName)
|
|
457
457
|
if (!cwd) return { ok: false, reason: `not registered: ${req.containerName}` }
|
|
458
458
|
const channelsPatch = req.patch?.channels
|
|
459
|
-
// Exactly one personal-account channel block per patch. KakaoTalk
|
|
460
|
-
//
|
|
459
|
+
// Exactly one personal-account channel block per patch. KakaoTalk, LINE,
|
|
460
|
+
// and Webex write their structured account block through this RPC; the
|
|
461
461
|
// key present in the patch selects which block to validate and merge.
|
|
462
462
|
const patch =
|
|
463
463
|
'line' in channelsPatch
|
|
464
464
|
? { key: 'line' as const, parsed: lineChannelBlockSchema.safeParse(channelsPatch.line) }
|
|
465
|
-
:
|
|
465
|
+
: 'webex' in channelsPatch
|
|
466
|
+
? { key: 'webex' as const, parsed: webexChannelBlockSchema.safeParse(channelsPatch.webex) }
|
|
467
|
+
: { key: 'kakaotalk' as const, parsed: kakaoChannelBlockSchema.safeParse(channelsPatch.kakaotalk) }
|
|
466
468
|
if (!patch.parsed.success) {
|
|
467
469
|
return { ok: false, reason: patch.parsed.error.issues.map((issue) => issue.message).join('; ') }
|
|
468
470
|
}
|
package/src/hostd/index.ts
CHANGED
|
@@ -1,16 +1,6 @@
|
|
|
1
1
|
export { isDaemonReachable, send } from './client'
|
|
2
2
|
export { startDaemon, type Daemon, type DaemonLogEvent, type DaemonOptions } from './daemon'
|
|
3
|
-
export {
|
|
4
|
-
containerSocketPath,
|
|
5
|
-
ensureDirs,
|
|
6
|
-
homeRoot,
|
|
7
|
-
lockfilePath,
|
|
8
|
-
logDir,
|
|
9
|
-
logfilePath,
|
|
10
|
-
pidfilePath,
|
|
11
|
-
runDir,
|
|
12
|
-
socketPath,
|
|
13
|
-
} from './paths'
|
|
3
|
+
export { ensureDirs, homeRoot, lockfilePath, logDir, logfilePath, pidfilePath, runDir, socketPath } from './paths'
|
|
14
4
|
export type {
|
|
15
5
|
ListResult,
|
|
16
6
|
Request,
|
package/src/hostd/paths.ts
CHANGED
|
@@ -5,11 +5,6 @@ import { join, resolve } from 'node:path'
|
|
|
5
5
|
|
|
6
6
|
import { isWindows } from '@/shared'
|
|
7
7
|
|
|
8
|
-
// Fixed in-container path where the host daemon's run dir is bind-mounted.
|
|
9
|
-
// The agent uses this to reach the host daemon (e.g. for the `restart` tool).
|
|
10
|
-
// Kept stable so the agent never has to discover the host's `~/.typeclaw`
|
|
11
|
-
// location at runtime.
|
|
12
|
-
const CONTAINER_HOST_RUN_DIR = '/run/typeclaw-host'
|
|
13
8
|
const SOCKET_FILE = 'hostd.sock'
|
|
14
9
|
const REGISTRATIONS_DIR = 'registrations'
|
|
15
10
|
const KEYS_DIR = 'keys'
|
|
@@ -90,17 +85,6 @@ export function registrationFilePath(containerName: string): string {
|
|
|
90
85
|
return join(registrationsDir(), `${containerName}.json`)
|
|
91
86
|
}
|
|
92
87
|
|
|
93
|
-
// In-container path to the same socket the host daemon listens on. The
|
|
94
|
-
// container-stage agent tool dials this path; the host bind-mounts the host
|
|
95
|
-
// run dir at CONTAINER_HOST_RUN_DIR so the socket is reachable.
|
|
96
|
-
export function containerSocketPath(): string {
|
|
97
|
-
return join(CONTAINER_HOST_RUN_DIR, SOCKET_FILE)
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export function containerHostRunDir(): string {
|
|
101
|
-
return CONTAINER_HOST_RUN_DIR
|
|
102
|
-
}
|
|
103
|
-
|
|
104
88
|
export async function ensureDirs(): Promise<void> {
|
|
105
89
|
await mkdir(runDir(), { recursive: true })
|
|
106
90
|
await mkdir(logDir(), { recursive: true })
|
package/src/hostd/protocol.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PortForward } from '@/config'
|
|
2
|
-
import type { KakaoChannelBlock, LineChannelBlock } from '@/secrets/schema'
|
|
2
|
+
import type { KakaoChannelBlock, LineChannelBlock, WebexChannelBlock } from '@/secrets/schema'
|
|
3
3
|
|
|
4
4
|
export type Request =
|
|
5
5
|
| {
|
|
@@ -18,7 +18,7 @@ export type Request =
|
|
|
18
18
|
| {
|
|
19
19
|
kind: 'secrets-patch'
|
|
20
20
|
containerName: string
|
|
21
|
-
patch: { channels: { kakaotalk: KakaoChannelBlock } | { line: LineChannelBlock } }
|
|
21
|
+
patch: { channels: { kakaotalk: KakaoChannelBlock } | { line: LineChannelBlock } | { webex: WebexChannelBlock } }
|
|
22
22
|
}
|
|
23
23
|
| { kind: 'http-info' }
|
|
24
24
|
| { kind: 'version' }
|
package/src/init/checkpoint.ts
CHANGED
|
@@ -21,7 +21,7 @@ export const INIT_CHECKPOINT_PATH = join('.typeclaw', 'init-progress.json')
|
|
|
21
21
|
|
|
22
22
|
export const WIZARD_CHECKPOINT_VERSION = 1
|
|
23
23
|
|
|
24
|
-
export type WizardChannelChoice = 'slack' | 'discord' | 'telegram' | 'kakaotalk' | 'github' | 'none'
|
|
24
|
+
export type WizardChannelChoice = 'slack' | 'discord' | 'telegram' | 'webex' | 'kakaotalk' | 'github' | 'none'
|
|
25
25
|
|
|
26
26
|
export type AuthMethod = 'api-key' | 'oauth'
|
|
27
27
|
|
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>
|
|
@@ -209,9 +214,11 @@ export type InitOptions = {
|
|
|
209
214
|
withSlack?: boolean
|
|
210
215
|
withTelegram?: boolean
|
|
211
216
|
withWebex?: boolean
|
|
217
|
+
withWebexUser?: boolean
|
|
212
218
|
withKakaotalk?: boolean
|
|
213
219
|
withGithub?: boolean
|
|
214
220
|
runKakaotalkAuth?: KakaotalkAuthRunner
|
|
221
|
+
runWebexAuth?: WebexAuthRunner
|
|
215
222
|
// Structured GitHub credentials collected by the wizard. When omitted and
|
|
216
223
|
// `withGithub` is true, the existing secrets.json#channels.github block is
|
|
217
224
|
// reused as-is (the wizard's "reuse existing credentials" path).
|
|
@@ -250,9 +257,11 @@ export async function runInit({
|
|
|
250
257
|
withSlack,
|
|
251
258
|
withTelegram,
|
|
252
259
|
withWebex,
|
|
260
|
+
withWebexUser = false,
|
|
253
261
|
withKakaotalk = false,
|
|
254
262
|
withGithub = false,
|
|
255
263
|
runKakaotalkAuth,
|
|
264
|
+
runWebexAuth,
|
|
256
265
|
githubCredentials,
|
|
257
266
|
githubFetchImpl,
|
|
258
267
|
onProgress,
|
|
@@ -329,6 +338,7 @@ export async function runInit({
|
|
|
329
338
|
withSlack: wantsSlack,
|
|
330
339
|
withTelegram: wantsTelegram,
|
|
331
340
|
withWebex: wantsWebex,
|
|
341
|
+
withWebexUser,
|
|
332
342
|
withKakaotalk,
|
|
333
343
|
})
|
|
334
344
|
// Only write the LLM API key on the api-key path. OAuth providers persist
|
|
@@ -363,6 +373,15 @@ export async function runInit({
|
|
|
363
373
|
}
|
|
364
374
|
}
|
|
365
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
|
+
|
|
366
385
|
// Write the structured github channel block alongside scaffold's bot-token
|
|
367
386
|
// blocks. We do NOT delegate to runAddChannel because that's the `channel
|
|
368
387
|
// add` semantics — strict no-overwrite, throws when secrets.json#channels
|
|
@@ -406,6 +425,7 @@ export async function runInit({
|
|
|
406
425
|
if (wantsSlack) configuredChannels.push('slack-bot')
|
|
407
426
|
if (wantsTelegram) configuredChannels.push('telegram-bot')
|
|
408
427
|
if (wantsWebex) configuredChannels.push('webex-bot')
|
|
428
|
+
if (withWebexUser) configuredChannels.push('webex')
|
|
409
429
|
if (withKakaotalk) configuredChannels.push('kakaotalk')
|
|
410
430
|
if (withGithub) configuredChannels.push('github')
|
|
411
431
|
|
|
@@ -560,6 +580,7 @@ export type ScaffoldOptions = {
|
|
|
560
580
|
withSlack?: boolean
|
|
561
581
|
withTelegram?: boolean
|
|
562
582
|
withWebex?: boolean
|
|
583
|
+
withWebexUser?: boolean
|
|
563
584
|
withKakaotalk?: boolean
|
|
564
585
|
}
|
|
565
586
|
|
|
@@ -593,6 +614,7 @@ export async function scaffold(root: string, options: ScaffoldOptions = {}): Pro
|
|
|
593
614
|
if (options.withSlack) channels['slack-bot'] = {}
|
|
594
615
|
if (options.withTelegram) channels['telegram-bot'] = {}
|
|
595
616
|
if (options.withWebex) channels['webex-bot'] = {}
|
|
617
|
+
if (options.withWebexUser) channels.webex = {}
|
|
596
618
|
if (options.withKakaotalk) channels.kakaotalk = {}
|
|
597
619
|
if (Object.keys(channels).length > 0) config.channels = channels
|
|
598
620
|
// No default `member` match is seeded. A fresh chat agent starts with every
|
|
@@ -936,7 +958,7 @@ export async function hasExistingChannelSecrets(
|
|
|
936
958
|
case 'telegram':
|
|
937
959
|
return hasSecretField(channels['telegram-bot'], 'token')
|
|
938
960
|
case 'webex':
|
|
939
|
-
return
|
|
961
|
+
return hasCurrentWebexAccount(channels.webex)
|
|
940
962
|
case 'github':
|
|
941
963
|
// GitHub credentials alone are not enough to scaffold a working
|
|
942
964
|
// channel: typeclaw.json#channels.github also needs webhookUrl and
|
|
@@ -995,6 +1017,20 @@ function hasSecretField(slot: unknown, field: string): boolean {
|
|
|
995
1017
|
return false
|
|
996
1018
|
}
|
|
997
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
|
+
|
|
998
1034
|
function isObjectRecord(value: unknown): value is Record<string, unknown> {
|
|
999
1035
|
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
1000
1036
|
}
|
|
@@ -1031,7 +1067,15 @@ function ignoreExists(error: NodeJS.ErrnoException): void {
|
|
|
1031
1067
|
// scaffold-test cases above demonstrates how easy it is to lose a single
|
|
1032
1068
|
// behavior under a mode flag.
|
|
1033
1069
|
|
|
1034
|
-
export type ChannelKind =
|
|
1070
|
+
export type ChannelKind =
|
|
1071
|
+
| 'discord-bot'
|
|
1072
|
+
| 'slack-bot'
|
|
1073
|
+
| 'telegram-bot'
|
|
1074
|
+
| 'webex'
|
|
1075
|
+
| 'webex-bot'
|
|
1076
|
+
| 'line'
|
|
1077
|
+
| 'kakaotalk'
|
|
1078
|
+
| 'github'
|
|
1035
1079
|
|
|
1036
1080
|
// Public adapter names match the typeclaw.json `channels.*` keys exactly.
|
|
1037
1081
|
// The CLI takes these as the optional positional arg, the picker shows
|
|
@@ -1041,13 +1085,14 @@ export const CHANNEL_KINDS: ReadonlyArray<ChannelKind> = [
|
|
|
1041
1085
|
'slack-bot',
|
|
1042
1086
|
'discord-bot',
|
|
1043
1087
|
'telegram-bot',
|
|
1088
|
+
'webex',
|
|
1044
1089
|
'webex-bot',
|
|
1045
1090
|
'line',
|
|
1046
1091
|
'kakaotalk',
|
|
1047
1092
|
'github',
|
|
1048
1093
|
]
|
|
1049
1094
|
|
|
1050
|
-
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'
|
|
1051
1096
|
|
|
1052
1097
|
export type AddChannelStepEvent =
|
|
1053
1098
|
| { step: 'config'; phase: 'start' }
|
|
@@ -1056,6 +1101,8 @@ export type AddChannelStepEvent =
|
|
|
1056
1101
|
| { step: 'line-auth'; phase: 'done'; result: LineAuthResult }
|
|
1057
1102
|
| { step: 'kakaotalk-auth'; phase: 'start' }
|
|
1058
1103
|
| { step: 'kakaotalk-auth'; phase: 'done'; result: KakaotalkAuthResult }
|
|
1104
|
+
| { step: 'webex-auth'; phase: 'start' }
|
|
1105
|
+
| { step: 'webex-auth'; phase: 'done'; result: WebexAuthResult }
|
|
1059
1106
|
| { step: 'secrets'; phase: 'start' }
|
|
1060
1107
|
| { step: 'secrets'; phase: 'done' }
|
|
1061
1108
|
| { step: 'github-webhooks'; phase: 'start' }
|
|
@@ -1072,6 +1119,7 @@ export type AddChannelOptions = {
|
|
|
1072
1119
|
| { channel: 'slack-bot'; slackBotToken: string; slackAppToken: string }
|
|
1073
1120
|
| { channel: 'telegram-bot'; telegramBotToken: string }
|
|
1074
1121
|
| { channel: 'webex-bot'; webexBotToken: string }
|
|
1122
|
+
| { channel: 'webex'; runWebexAuth: WebexAuthRunner }
|
|
1075
1123
|
| { channel: 'line'; runLineAuth: LineAuthRunner }
|
|
1076
1124
|
| { channel: 'kakaotalk'; runKakaotalkAuth: KakaotalkAuthRunner }
|
|
1077
1125
|
| {
|
|
@@ -1113,6 +1161,13 @@ export async function runAddChannel(options: AddChannelOptions): Promise<void> {
|
|
|
1113
1161
|
if (!result.ok) throw new Error(`KakaoTalk authentication failed: ${result.reason}`)
|
|
1114
1162
|
}
|
|
1115
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
|
+
|
|
1116
1171
|
emit({ step: 'config', phase: 'start' })
|
|
1117
1172
|
await mergeChannelIntoConfig(options.cwd, options)
|
|
1118
1173
|
emit({ step: 'config', phase: 'done' })
|
|
@@ -1187,6 +1242,8 @@ function channelSecretsFromOptions(options: AddChannelOptions): ChannelSecrets {
|
|
|
1187
1242
|
return { token: options.telegramBotToken }
|
|
1188
1243
|
case 'webex-bot':
|
|
1189
1244
|
return { token: options.webexBotToken }
|
|
1245
|
+
case 'webex':
|
|
1246
|
+
return {}
|
|
1190
1247
|
case 'line':
|
|
1191
1248
|
// LINE auth writes its structured account block directly to
|
|
1192
1249
|
// secrets.json#channels.line before config mutation.
|
|
@@ -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 }
|
package/src/inspect/label.ts
CHANGED
|
@@ -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 {
|
package/src/inspect/render.ts
CHANGED
|
@@ -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
|
|
124
|
-
const
|
|
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}`
|