typeclaw 0.39.2 → 0.39.3
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/auth.schema.json +110 -0
- package/package.json +2 -2
- package/secrets.schema.json +110 -0
- package/src/agent/index.ts +44 -19
- package/src/agent/plugin-tools.ts +12 -12
- package/src/agent/session-origin.ts +2 -0
- package/src/agent/todo/store.ts +21 -1
- package/src/agent/tools/channel-reply.ts +18 -5
- package/src/agent/tools/channel-send.ts +13 -2
- package/src/bundled-plugins/doc-render/render.ts +2 -2
- package/src/bundled-plugins/github-cli-auth/approve-idempotency.ts +40 -18
- package/src/channels/adapters/discord-author-resolver.ts +52 -0
- package/src/channels/adapters/discord-bot.ts +1 -1
- package/src/channels/adapters/discord-channel-resolver.ts +44 -0
- package/src/channels/adapters/discord-classify.ts +121 -0
- package/src/channels/adapters/discord-reactions.ts +138 -0
- package/src/channels/adapters/discord.ts +416 -0
- package/src/channels/adapters/github/outbound.ts +23 -4
- package/src/channels/adapters/kakaotalk.ts +8 -1
- package/src/channels/adapters/line.ts +1 -1
- package/src/channels/adapters/slack-author-resolver.ts +54 -0
- package/src/channels/adapters/slack-bot.ts +3 -1
- package/src/channels/adapters/slack-channel-resolver.ts +49 -0
- package/src/channels/adapters/slack-classify.ts +83 -0
- package/src/channels/adapters/slack-reactions.ts +126 -0
- package/src/channels/adapters/slack.ts +416 -0
- package/src/channels/adapters/telegram-bot.ts +2 -1
- package/src/channels/adapters/webex-bot.ts +5 -2
- package/src/channels/adapters/webex.ts +55 -2
- package/src/channels/github-review-turn-ledger.ts +32 -0
- package/src/channels/github-verdict-activity.ts +60 -0
- package/src/channels/index.ts +6 -0
- package/src/channels/manager.ts +130 -6
- package/src/channels/pr-verdict-activity-bridge.ts +43 -0
- package/src/channels/router.ts +161 -9
- package/src/channels/schema.ts +4 -0
- package/src/channels/types.ts +17 -1
- package/src/cli/builtins.ts +1 -0
- package/src/cli/channel.ts +170 -18
- package/src/cli/index.ts +11 -0
- package/src/cli/init.ts +2 -0
- package/src/cli/update-check.ts +14 -0
- package/src/cli/update-notify.ts +91 -0
- package/src/cli/update-suppression.ts +19 -0
- package/src/config/channels-mutation.ts +3 -1
- package/src/config/config.ts +51 -0
- package/src/config/index.ts +1 -0
- package/src/container/start.ts +30 -6
- package/src/doctor/channel-checks.ts +57 -3
- package/src/hostd/daemon.ts +22 -5
- package/src/hostd/index.ts +11 -1
- package/src/hostd/paths.ts +4 -0
- package/src/hostd/protocol.ts +15 -2
- package/src/init/cli-version.ts +1 -1
- package/src/init/discord-auth.ts +50 -0
- package/src/init/index.ts +94 -4
- package/src/init/reconcile-plugin-deps.ts +30 -5
- package/src/init/run-owner-claim.ts +2 -0
- package/src/init/slack-auth.ts +51 -0
- package/src/mcp/manager.ts +94 -7
- package/src/mcp/tools.ts +7 -4
- package/src/permissions/resolve.ts +2 -0
- package/src/role-claim/match-rule.ts +2 -0
- package/src/run/index.ts +74 -29
- package/src/secrets/discord-store.ts +96 -0
- package/src/secrets/schema.ts +34 -0
- package/src/secrets/slack-store.ts +96 -0
- package/src/server/command-runner.ts +21 -0
- package/src/skills/typeclaw-cron/SKILL.md +13 -2
- package/src/tui/format.ts +0 -19
- package/src/tui/index.ts +2 -8
- package/src/update/check.ts +192 -0
- package/typeclaw.schema.json +332 -0
|
@@ -29,6 +29,8 @@ export function buildChannelChecks(): DoctorCheck[] {
|
|
|
29
29
|
discordBotCredentials(),
|
|
30
30
|
telegramBotCredentials(),
|
|
31
31
|
webexBotCredentials(),
|
|
32
|
+
discordUserCredentials(),
|
|
33
|
+
slackUserCredentials(),
|
|
32
34
|
webexUserCredentials(),
|
|
33
35
|
lineCredentials(),
|
|
34
36
|
kakaotalkCredentials(),
|
|
@@ -47,6 +49,32 @@ function slackBotCredentials(): DoctorCheck {
|
|
|
47
49
|
}
|
|
48
50
|
}
|
|
49
51
|
|
|
52
|
+
function slackUserCredentials(): DoctorCheck {
|
|
53
|
+
return {
|
|
54
|
+
name: 'channel.slack.credentials',
|
|
55
|
+
category: 'channels',
|
|
56
|
+
description: 'slack adapter has a current account with a token in secrets.json',
|
|
57
|
+
applies: (ctx) => ctx.hasAgentFolder,
|
|
58
|
+
async run(ctx) {
|
|
59
|
+
const channels = readDeclaredChannels(ctx)
|
|
60
|
+
if (channels === null) return configInvalidResult()
|
|
61
|
+
if (!isAdapterActive(channels, 'slack')) {
|
|
62
|
+
return { status: 'skipped', message: 'slack not configured' }
|
|
63
|
+
}
|
|
64
|
+
const block = readChannelsSecrets(ctx)?.slack
|
|
65
|
+
if (!hasCurrentAccountTokenField(block, 'token')) {
|
|
66
|
+
return {
|
|
67
|
+
status: 'warning',
|
|
68
|
+
message: 'slack has no current account token in secrets.json',
|
|
69
|
+
details: ['Adapter will start but fail authentication and stay disconnected.'],
|
|
70
|
+
fix: { description: 'Run `typeclaw channel add slack` to log in an account.' },
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return { status: 'ok', message: 'slack has a current account token' }
|
|
74
|
+
},
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
50
78
|
function discordBotCredentials(): DoctorCheck {
|
|
51
79
|
return {
|
|
52
80
|
name: 'channel.discord-bot.credentials',
|
|
@@ -57,6 +85,32 @@ function discordBotCredentials(): DoctorCheck {
|
|
|
57
85
|
}
|
|
58
86
|
}
|
|
59
87
|
|
|
88
|
+
function discordUserCredentials(): DoctorCheck {
|
|
89
|
+
return {
|
|
90
|
+
name: 'channel.discord.credentials',
|
|
91
|
+
category: 'channels',
|
|
92
|
+
description: 'discord adapter has a current account with a token in secrets.json',
|
|
93
|
+
applies: (ctx) => ctx.hasAgentFolder,
|
|
94
|
+
async run(ctx) {
|
|
95
|
+
const channels = readDeclaredChannels(ctx)
|
|
96
|
+
if (channels === null) return configInvalidResult()
|
|
97
|
+
if (!isAdapterActive(channels, 'discord')) {
|
|
98
|
+
return { status: 'skipped', message: 'discord not configured' }
|
|
99
|
+
}
|
|
100
|
+
const block = readChannelsSecrets(ctx)?.discord
|
|
101
|
+
if (!hasCurrentAccountTokenField(block, 'token')) {
|
|
102
|
+
return {
|
|
103
|
+
status: 'warning',
|
|
104
|
+
message: 'discord has no current account token in secrets.json',
|
|
105
|
+
details: ['Adapter will start but fail authentication and stay disconnected.'],
|
|
106
|
+
fix: { description: 'Run `typeclaw channel add discord` to log in an account.' },
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return { status: 'ok', message: 'discord has a current account token' }
|
|
110
|
+
},
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
60
114
|
function telegramBotCredentials(): DoctorCheck {
|
|
61
115
|
return {
|
|
62
116
|
name: 'channel.telegram-bot.credentials',
|
|
@@ -90,7 +144,7 @@ function webexUserCredentials(): DoctorCheck {
|
|
|
90
144
|
return { status: 'skipped', message: 'webex not configured' }
|
|
91
145
|
}
|
|
92
146
|
const block = readChannelsSecrets(ctx)?.webex
|
|
93
|
-
if (!
|
|
147
|
+
if (!hasCurrentAccountTokenField(block, 'access_token')) {
|
|
94
148
|
return {
|
|
95
149
|
status: 'warning',
|
|
96
150
|
message: 'webex has no current account access_token in secrets.json',
|
|
@@ -353,7 +407,7 @@ function isSecretShape(value: unknown): value is { value?: string; env?: string
|
|
|
353
407
|
return hasValue || hasEnv
|
|
354
408
|
}
|
|
355
409
|
|
|
356
|
-
function
|
|
410
|
+
function hasCurrentAccountTokenField(block: unknown, field: string): boolean {
|
|
357
411
|
if (!isObjectRecord(block)) return false
|
|
358
412
|
const current = (block as { currentAccount?: unknown }).currentAccount
|
|
359
413
|
if (typeof current !== 'string' || current.length === 0) return false
|
|
@@ -361,7 +415,7 @@ function hasCurrentAccountToken(block: unknown): boolean {
|
|
|
361
415
|
if (!isObjectRecord(accounts)) return false
|
|
362
416
|
const account = accounts[current]
|
|
363
417
|
if (!isObjectRecord(account)) return false
|
|
364
|
-
const token =
|
|
418
|
+
const token = account[field]
|
|
365
419
|
return typeof token === 'string' && token.length > 0
|
|
366
420
|
}
|
|
367
421
|
|
package/src/hostd/daemon.ts
CHANGED
|
@@ -6,7 +6,13 @@ 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 {
|
|
9
|
+
import {
|
|
10
|
+
discordChannelBlockSchema,
|
|
11
|
+
kakaoChannelBlockSchema,
|
|
12
|
+
lineChannelBlockSchema,
|
|
13
|
+
slackChannelBlockSchema,
|
|
14
|
+
webexChannelBlockSchema,
|
|
15
|
+
} from '@/secrets/schema'
|
|
10
16
|
import { SecretsBackend } from '@/secrets/storage'
|
|
11
17
|
import { isWindows } from '@/shared'
|
|
12
18
|
|
|
@@ -461,7 +467,14 @@ export async function startDaemon(opts: DaemonOptions = {}): Promise<Daemon> {
|
|
|
461
467
|
|
|
462
468
|
const handleSecretsPatch = async (req: {
|
|
463
469
|
containerName: string
|
|
464
|
-
patch: {
|
|
470
|
+
patch: {
|
|
471
|
+
channels:
|
|
472
|
+
| { kakaotalk: unknown }
|
|
473
|
+
| { discord: unknown }
|
|
474
|
+
| { line: unknown }
|
|
475
|
+
| { webex: unknown }
|
|
476
|
+
| { slack: unknown }
|
|
477
|
+
}
|
|
465
478
|
}): Promise<RpcResponse> =>
|
|
466
479
|
runSerially(req.containerName, async () => {
|
|
467
480
|
const cwd = cwds.get(req.containerName)
|
|
@@ -473,9 +486,13 @@ export async function startDaemon(opts: DaemonOptions = {}): Promise<Daemon> {
|
|
|
473
486
|
const patch =
|
|
474
487
|
'line' in channelsPatch
|
|
475
488
|
? { key: 'line' as const, parsed: lineChannelBlockSchema.safeParse(channelsPatch.line) }
|
|
476
|
-
: '
|
|
477
|
-
? { key: '
|
|
478
|
-
:
|
|
489
|
+
: 'discord' in channelsPatch
|
|
490
|
+
? { key: 'discord' as const, parsed: discordChannelBlockSchema.safeParse(channelsPatch.discord) }
|
|
491
|
+
: 'webex' in channelsPatch
|
|
492
|
+
? { key: 'webex' as const, parsed: webexChannelBlockSchema.safeParse(channelsPatch.webex) }
|
|
493
|
+
: 'slack' in channelsPatch
|
|
494
|
+
? { key: 'slack' as const, parsed: slackChannelBlockSchema.safeParse(channelsPatch.slack) }
|
|
495
|
+
: { key: 'kakaotalk' as const, parsed: kakaoChannelBlockSchema.safeParse(channelsPatch.kakaotalk) }
|
|
479
496
|
if (!patch.parsed.success) {
|
|
480
497
|
return { ok: false, reason: patch.parsed.error.issues.map((issue) => issue.message).join('; ') }
|
|
481
498
|
}
|
package/src/hostd/index.ts
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
export { isDaemonReachable, send } from './client'
|
|
2
2
|
export { startDaemon, type Daemon, type DaemonLogEvent, type DaemonOptions } from './daemon'
|
|
3
|
-
export {
|
|
3
|
+
export {
|
|
4
|
+
ensureDirs,
|
|
5
|
+
homeRoot,
|
|
6
|
+
lockfilePath,
|
|
7
|
+
logDir,
|
|
8
|
+
logfilePath,
|
|
9
|
+
pidfilePath,
|
|
10
|
+
runDir,
|
|
11
|
+
socketPath,
|
|
12
|
+
versionCachePath,
|
|
13
|
+
} from './paths'
|
|
4
14
|
export type {
|
|
5
15
|
ListResult,
|
|
6
16
|
Request,
|
package/src/hostd/paths.ts
CHANGED
|
@@ -75,6 +75,10 @@ export function modelsDir(): string {
|
|
|
75
75
|
return join(homeRoot(), 'models')
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
+
export function versionCachePath(): string {
|
|
79
|
+
return join(homeRoot(), 'version-cache.json')
|
|
80
|
+
}
|
|
81
|
+
|
|
78
82
|
// Throws on any name that could traverse out of registrationsDir() or
|
|
79
83
|
// confuse the filesystem. Caller's responsibility to handle the error;
|
|
80
84
|
// don't catch-and-ignore — an invalid name is a protocol violation.
|
package/src/hostd/protocol.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import type { PortForward } from '@/config'
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
DiscordChannelBlock,
|
|
4
|
+
KakaoChannelBlock,
|
|
5
|
+
LineChannelBlock,
|
|
6
|
+
SlackChannelBlock,
|
|
7
|
+
WebexChannelBlock,
|
|
8
|
+
} from '@/secrets/schema'
|
|
3
9
|
|
|
4
10
|
export type Request =
|
|
5
11
|
| {
|
|
@@ -18,7 +24,14 @@ export type Request =
|
|
|
18
24
|
| {
|
|
19
25
|
kind: 'secrets-patch'
|
|
20
26
|
containerName: string
|
|
21
|
-
patch: {
|
|
27
|
+
patch: {
|
|
28
|
+
channels:
|
|
29
|
+
| { kakaotalk: KakaoChannelBlock }
|
|
30
|
+
| { discord: DiscordChannelBlock }
|
|
31
|
+
| { line: LineChannelBlock }
|
|
32
|
+
| { webex: WebexChannelBlock }
|
|
33
|
+
| { slack: SlackChannelBlock }
|
|
34
|
+
}
|
|
22
35
|
}
|
|
23
36
|
| { kind: 'http-info' }
|
|
24
37
|
| { kind: 'version' }
|
package/src/init/cli-version.ts
CHANGED
|
@@ -23,7 +23,7 @@ export const CLI_VERSION = cliPkg.version
|
|
|
23
23
|
|
|
24
24
|
const NODE_MODULES_SEGMENT = `${join('/', 'node_modules', '/')}`
|
|
25
25
|
|
|
26
|
-
function isInstalledCli(): boolean {
|
|
26
|
+
export function isInstalledCli(): boolean {
|
|
27
27
|
return CLI_PACKAGE_JSON_PATH.includes(NODE_MODULES_SEGMENT)
|
|
28
28
|
}
|
|
29
29
|
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto'
|
|
2
|
+
import { join } from 'node:path'
|
|
3
|
+
|
|
4
|
+
import { loginWithRemoteAuth as upstreamLoginWithRemoteAuth, type RemoteAuthSession } from 'agent-messenger/discord'
|
|
5
|
+
|
|
6
|
+
import { SecretsDiscordCredentialStore } from '@/secrets/discord-store'
|
|
7
|
+
import type { DiscordAccountRecord } from '@/secrets/schema'
|
|
8
|
+
|
|
9
|
+
export type DiscordBootstrapStatus = { ok: true } | { ok: false; reason: string }
|
|
10
|
+
|
|
11
|
+
export type LoginWithRemoteAuthFn = typeof upstreamLoginWithRemoteAuth
|
|
12
|
+
|
|
13
|
+
export type DiscordLoginInput = {
|
|
14
|
+
agentDir: string
|
|
15
|
+
onQrUrl?: (url: string) => void | Promise<void>
|
|
16
|
+
loginWithRemoteAuth?: LoginWithRemoteAuthFn
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function discordSecretsPath(agentDir: string): string {
|
|
20
|
+
return join(agentDir, 'secrets.json')
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export async function runDiscordBootstrap(input: DiscordLoginInput): Promise<DiscordBootstrapStatus> {
|
|
24
|
+
try {
|
|
25
|
+
const loginWithRemoteAuth = input.loginWithRemoteAuth ?? upstreamLoginWithRemoteAuth
|
|
26
|
+
const store = new SecretsDiscordCredentialStore({ mode: 'host', secretsPath: discordSecretsPath(input.agentDir) })
|
|
27
|
+
const result = await loginWithRemoteAuth({ onQrUrl: input.onQrUrl })
|
|
28
|
+
const now = new Date().toISOString()
|
|
29
|
+
const accountId = discordAccountId(result)
|
|
30
|
+
const account: DiscordAccountRecord = {
|
|
31
|
+
account_id: accountId,
|
|
32
|
+
token: result.token,
|
|
33
|
+
...(result.user?.username !== undefined ? { username: result.user.username } : {}),
|
|
34
|
+
created_at: now,
|
|
35
|
+
updated_at: now,
|
|
36
|
+
}
|
|
37
|
+
await store.setAccount(account)
|
|
38
|
+
await store.setCurrentAccount(accountId)
|
|
39
|
+
return { ok: true }
|
|
40
|
+
} catch (err) {
|
|
41
|
+
return { ok: false, reason: err instanceof Error ? err.message : String(err) }
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function discordAccountId(result: RemoteAuthSession): string {
|
|
46
|
+
if (result.user?.id !== undefined && result.user.id !== '') return result.user.id
|
|
47
|
+
return createHash('sha256').update(result.token).digest('hex').slice(0, 16)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export type { RemoteAuthSession }
|
package/src/init/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { existsSync, readdirSync } from 'node:fs'
|
|
2
2
|
import { mkdir, readFile, writeFile } from 'node:fs/promises'
|
|
3
|
-
import { basename, join
|
|
3
|
+
import { basename, join } from 'node:path'
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
6
|
config,
|
|
@@ -84,6 +84,8 @@ export type InitStep =
|
|
|
84
84
|
| 'preflight'
|
|
85
85
|
| 'oauth-login'
|
|
86
86
|
| 'scaffold'
|
|
87
|
+
| 'slack-auth'
|
|
88
|
+
| 'discord-auth'
|
|
87
89
|
| 'kakaotalk-auth'
|
|
88
90
|
| 'webex-auth'
|
|
89
91
|
| 'github-webhooks'
|
|
@@ -94,6 +96,8 @@ export type InitStep =
|
|
|
94
96
|
|
|
95
97
|
export type KakaotalkAuthResult = { ok: true } | { ok: false; reason: string }
|
|
96
98
|
export type WebexAuthResult = { ok: true } | { ok: false; reason: string }
|
|
99
|
+
export type SlackAuthResult = { ok: true } | { ok: false; reason: string }
|
|
100
|
+
export type DiscordAuthResult = { ok: true } | { ok: false; reason: string }
|
|
97
101
|
|
|
98
102
|
// Structured credential block for the GitHub channel adapter. Mirrors the
|
|
99
103
|
// shape `runAddChannel({ channel: 'github', ... })` consumes so the wizard
|
|
@@ -131,6 +135,8 @@ export type InitStepEvent =
|
|
|
131
135
|
| { step: 'kakaotalk-auth'; phase: 'done'; result: KakaotalkAuthResult }
|
|
132
136
|
| { step: 'webex-auth'; phase: 'start' }
|
|
133
137
|
| { step: 'webex-auth'; phase: 'done'; result: WebexAuthResult }
|
|
138
|
+
| { step: 'discord-auth'; phase: 'start' }
|
|
139
|
+
| { step: 'discord-auth'; phase: 'done'; result: DiscordAuthResult }
|
|
134
140
|
| { step: 'github-webhooks'; phase: 'start' }
|
|
135
141
|
| { step: 'github-webhooks'; phase: 'done'; result: EagerGithubWebhookInstallResult }
|
|
136
142
|
| { step: 'install'; phase: 'start' }
|
|
@@ -212,6 +218,7 @@ export type InitOptions = {
|
|
|
212
218
|
// the existing slot in `secrets.json#channels` untouched. Defaults below
|
|
213
219
|
// mirror the legacy derivation (`<token> !== undefined && !== ''`).
|
|
214
220
|
withDiscord?: boolean
|
|
221
|
+
withDiscordUser?: boolean
|
|
215
222
|
withSlack?: boolean
|
|
216
223
|
withTelegram?: boolean
|
|
217
224
|
withWebex?: boolean
|
|
@@ -220,6 +227,7 @@ export type InitOptions = {
|
|
|
220
227
|
withGithub?: boolean
|
|
221
228
|
runKakaotalkAuth?: KakaotalkAuthRunner
|
|
222
229
|
runWebexAuth?: WebexAuthRunner
|
|
230
|
+
runDiscordAuth?: DiscordAuthRunner
|
|
223
231
|
// Structured GitHub credentials collected by the wizard. When omitted and
|
|
224
232
|
// `withGithub` is true, the existing secrets.json#channels.github block is
|
|
225
233
|
// reused as-is (the wizard's "reuse existing credentials" path).
|
|
@@ -260,6 +268,7 @@ export async function runInit({
|
|
|
260
268
|
telegramBotToken,
|
|
261
269
|
webexBotToken,
|
|
262
270
|
withDiscord,
|
|
271
|
+
withDiscordUser = false,
|
|
263
272
|
withSlack,
|
|
264
273
|
withTelegram,
|
|
265
274
|
withWebex,
|
|
@@ -268,6 +277,7 @@ export async function runInit({
|
|
|
268
277
|
withGithub = false,
|
|
269
278
|
runKakaotalkAuth,
|
|
270
279
|
runWebexAuth,
|
|
280
|
+
runDiscordAuth,
|
|
271
281
|
githubCredentials,
|
|
272
282
|
githubFetchImpl,
|
|
273
283
|
onProgress,
|
|
@@ -343,6 +353,7 @@ export async function runInit({
|
|
|
343
353
|
...(visionModel !== undefined ? { visionModel } : {}),
|
|
344
354
|
...(visionModelMeta !== undefined ? { visionModelMeta } : {}),
|
|
345
355
|
withDiscord: wantsDiscord,
|
|
356
|
+
withDiscordUser,
|
|
346
357
|
withSlack: wantsSlack,
|
|
347
358
|
withTelegram: wantsTelegram,
|
|
348
359
|
withWebex: wantsWebex,
|
|
@@ -391,6 +402,16 @@ export async function runInit({
|
|
|
391
402
|
}
|
|
392
403
|
}
|
|
393
404
|
|
|
405
|
+
if (withDiscordUser) {
|
|
406
|
+
emit({ step: 'discord-auth', phase: 'start' })
|
|
407
|
+
const runner = runDiscordAuth ?? defaultDiscordAuthRunner
|
|
408
|
+
const result = await runner({ cwd })
|
|
409
|
+
emit({ step: 'discord-auth', phase: 'done', result })
|
|
410
|
+
if (!result.ok) {
|
|
411
|
+
throw new Error(`Discord authentication failed: ${result.reason}`)
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
|
|
394
415
|
// Write the structured github channel block alongside scaffold's bot-token
|
|
395
416
|
// blocks. We do NOT delegate to runAddChannel because that's the `channel
|
|
396
417
|
// add` semantics — strict no-overwrite, throws when secrets.json#channels
|
|
@@ -437,6 +458,7 @@ export async function runInit({
|
|
|
437
458
|
|
|
438
459
|
const configuredChannels: ChannelKind[] = []
|
|
439
460
|
if (wantsDiscord) configuredChannels.push('discord-bot')
|
|
461
|
+
if (withDiscordUser) configuredChannels.push('discord')
|
|
440
462
|
if (wantsSlack) configuredChannels.push('slack-bot')
|
|
441
463
|
if (wantsTelegram) configuredChannels.push('telegram-bot')
|
|
442
464
|
if (wantsWebex) configuredChannels.push('webex-bot')
|
|
@@ -606,6 +628,7 @@ export type ScaffoldOptions = {
|
|
|
606
628
|
visionModel?: ModelRef | string
|
|
607
629
|
visionModelMeta?: CustomModelMeta
|
|
608
630
|
withDiscord?: boolean
|
|
631
|
+
withDiscordUser?: boolean
|
|
609
632
|
withSlack?: boolean
|
|
610
633
|
withTelegram?: boolean
|
|
611
634
|
withWebex?: boolean
|
|
@@ -643,6 +666,7 @@ export async function scaffold(root: string, options: ScaffoldOptions = {}): Pro
|
|
|
643
666
|
if (Object.keys(customModels).length > 0) config.customModels = customModels
|
|
644
667
|
const channels: Record<string, Record<string, never>> = {}
|
|
645
668
|
if (options.withDiscord) channels['discord-bot'] = {}
|
|
669
|
+
if (options.withDiscordUser) channels.discord = {}
|
|
646
670
|
if (options.withSlack) channels['slack-bot'] = {}
|
|
647
671
|
if (options.withTelegram) channels['telegram-bot'] = {}
|
|
648
672
|
if (options.withWebex) channels['webex-bot'] = {}
|
|
@@ -728,13 +752,21 @@ export async function writeDockerAssets(root: string): Promise<DockerAssetsResul
|
|
|
728
752
|
try {
|
|
729
753
|
const pkg = await readPackageJson(root)
|
|
730
754
|
const typeclawSpec = pkg.dependencies?.typeclaw ?? ''
|
|
731
|
-
|
|
755
|
+
// Both `file:` (POSIX dev) and `link:` (native-Windows dev, see
|
|
756
|
+
// resolveTypeclawSpec) are locally-linked checkouts that must inline the
|
|
757
|
+
// heavy stack on the slim base, since the matching GHCR base tag for an
|
|
758
|
+
// unreleased dev build does not exist. Mirrors hasLocallyLinkedTypeclawDep.
|
|
759
|
+
const devMode = typeclawSpec.startsWith('file:') || typeclawSpec.startsWith('link:')
|
|
732
760
|
|
|
733
761
|
const typeclawConfig = await readTypeclawConfig(root)
|
|
734
762
|
await writeFile(
|
|
735
763
|
join(root, DOCKERFILE),
|
|
736
764
|
buildDockerfile(typeclawConfig.docker.file, {
|
|
737
|
-
|
|
765
|
+
// A local-spec dev install must inline the heavy stack: its unreleased
|
|
766
|
+
// version has no published `typeclaw-base` tag, so resolving a base
|
|
767
|
+
// image version would pin a nonexistent `FROM ghcr.io/...:<version>`.
|
|
768
|
+
// `null` selects the inline `oven/bun:1-slim` path in buildDockerfile.
|
|
769
|
+
baseImageVersion: devMode ? null : resolveBaseImageVersion(root),
|
|
738
770
|
cjkFontsAuto: hostLocaleIsCjk(),
|
|
739
771
|
}),
|
|
740
772
|
{ flag: 'wx' },
|
|
@@ -1076,7 +1108,9 @@ function ignoreExists(error: NodeJS.ErrnoException): void {
|
|
|
1076
1108
|
// behavior under a mode flag.
|
|
1077
1109
|
|
|
1078
1110
|
export type ChannelKind =
|
|
1111
|
+
| 'discord'
|
|
1079
1112
|
| 'discord-bot'
|
|
1113
|
+
| 'slack'
|
|
1080
1114
|
| 'slack-bot'
|
|
1081
1115
|
| 'telegram-bot'
|
|
1082
1116
|
| 'webex'
|
|
@@ -1091,6 +1125,8 @@ export type ChannelKind =
|
|
|
1091
1125
|
// when reading typeclaw.json.
|
|
1092
1126
|
export const CHANNEL_KINDS: ReadonlyArray<ChannelKind> = [
|
|
1093
1127
|
'slack-bot',
|
|
1128
|
+
'slack',
|
|
1129
|
+
'discord',
|
|
1094
1130
|
'discord-bot',
|
|
1095
1131
|
'telegram-bot',
|
|
1096
1132
|
'webex',
|
|
@@ -1100,7 +1136,15 @@ export const CHANNEL_KINDS: ReadonlyArray<ChannelKind> = [
|
|
|
1100
1136
|
'github',
|
|
1101
1137
|
]
|
|
1102
1138
|
|
|
1103
|
-
export type AddChannelStep =
|
|
1139
|
+
export type AddChannelStep =
|
|
1140
|
+
| 'line-auth'
|
|
1141
|
+
| 'kakaotalk-auth'
|
|
1142
|
+
| 'webex-auth'
|
|
1143
|
+
| 'discord-auth'
|
|
1144
|
+
| 'slack-auth'
|
|
1145
|
+
| 'config'
|
|
1146
|
+
| 'secrets'
|
|
1147
|
+
| 'github-webhooks'
|
|
1104
1148
|
|
|
1105
1149
|
export type AddChannelStepEvent =
|
|
1106
1150
|
| { step: 'config'; phase: 'start' }
|
|
@@ -1111,6 +1155,10 @@ export type AddChannelStepEvent =
|
|
|
1111
1155
|
| { step: 'kakaotalk-auth'; phase: 'done'; result: KakaotalkAuthResult }
|
|
1112
1156
|
| { step: 'webex-auth'; phase: 'start' }
|
|
1113
1157
|
| { step: 'webex-auth'; phase: 'done'; result: WebexAuthResult }
|
|
1158
|
+
| { step: 'discord-auth'; phase: 'start' }
|
|
1159
|
+
| { step: 'discord-auth'; phase: 'done'; result: DiscordAuthResult }
|
|
1160
|
+
| { step: 'slack-auth'; phase: 'start' }
|
|
1161
|
+
| { step: 'slack-auth'; phase: 'done'; result: SlackAuthResult }
|
|
1114
1162
|
| { step: 'secrets'; phase: 'start' }
|
|
1115
1163
|
| { step: 'secrets'; phase: 'done' }
|
|
1116
1164
|
| { step: 'github-webhooks'; phase: 'start' }
|
|
@@ -1124,6 +1172,8 @@ export type AddChannelOptions = {
|
|
|
1124
1172
|
onProgress?: (event: AddChannelStepEvent) => void
|
|
1125
1173
|
} & (
|
|
1126
1174
|
| { channel: 'discord-bot'; discordBotToken: string }
|
|
1175
|
+
| { channel: 'discord'; runDiscordAuth: DiscordAuthRunner }
|
|
1176
|
+
| { channel: 'slack'; slackQrDataUrl: string; runSlackAuth?: SlackAuthRunner }
|
|
1127
1177
|
| { channel: 'slack-bot'; slackBotToken: string; slackAppToken: string }
|
|
1128
1178
|
| { channel: 'telegram-bot'; telegramBotToken: string }
|
|
1129
1179
|
| { channel: 'webex-bot'; webexBotToken: string }
|
|
@@ -1144,6 +1194,9 @@ export type AddChannelOptions = {
|
|
|
1144
1194
|
}
|
|
1145
1195
|
)
|
|
1146
1196
|
|
|
1197
|
+
export type SlackAuthRunner = (options: { cwd: string; qrDataUrl: string }) => Promise<SlackAuthResult>
|
|
1198
|
+
export type DiscordAuthRunner = (options: { cwd: string }) => Promise<DiscordAuthResult>
|
|
1199
|
+
|
|
1147
1200
|
export async function runAddChannel(options: AddChannelOptions): Promise<void> {
|
|
1148
1201
|
const emit = options.onProgress ?? (() => {})
|
|
1149
1202
|
|
|
@@ -1176,6 +1229,21 @@ export async function runAddChannel(options: AddChannelOptions): Promise<void> {
|
|
|
1176
1229
|
if (!result.ok) throw new Error(`Webex authentication failed: ${result.reason}`)
|
|
1177
1230
|
}
|
|
1178
1231
|
|
|
1232
|
+
if (options.channel === 'discord') {
|
|
1233
|
+
emit({ step: 'discord-auth', phase: 'start' })
|
|
1234
|
+
const result = await options.runDiscordAuth({ cwd: options.cwd })
|
|
1235
|
+
emit({ step: 'discord-auth', phase: 'done', result })
|
|
1236
|
+
if (!result.ok) throw new Error(`Discord authentication failed: ${result.reason}`)
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1239
|
+
if (options.channel === 'slack') {
|
|
1240
|
+
emit({ step: 'slack-auth', phase: 'start' })
|
|
1241
|
+
const runner = options.runSlackAuth ?? defaultSlackAuthRunner
|
|
1242
|
+
const result = await runner({ cwd: options.cwd, qrDataUrl: options.slackQrDataUrl })
|
|
1243
|
+
emit({ step: 'slack-auth', phase: 'done', result })
|
|
1244
|
+
if (!result.ok) throw new Error(`Slack authentication failed: ${result.reason}`)
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1179
1247
|
emit({ step: 'config', phase: 'start' })
|
|
1180
1248
|
await mergeChannelIntoConfig(options.cwd, options)
|
|
1181
1249
|
emit({ step: 'config', phase: 'done' })
|
|
@@ -1244,8 +1312,12 @@ function channelSecretsFromOptions(options: AddChannelOptions): ChannelSecrets {
|
|
|
1244
1312
|
switch (options.channel) {
|
|
1245
1313
|
case 'discord-bot':
|
|
1246
1314
|
return { token: options.discordBotToken }
|
|
1315
|
+
case 'discord':
|
|
1316
|
+
return {}
|
|
1247
1317
|
case 'slack-bot':
|
|
1248
1318
|
return { botToken: options.slackBotToken, appToken: options.slackAppToken }
|
|
1319
|
+
case 'slack':
|
|
1320
|
+
return {}
|
|
1249
1321
|
case 'telegram-bot':
|
|
1250
1322
|
return { token: options.telegramBotToken }
|
|
1251
1323
|
case 'webex-bot':
|
|
@@ -1266,6 +1338,24 @@ function channelSecretsFromOptions(options: AddChannelOptions): ChannelSecrets {
|
|
|
1266
1338
|
}
|
|
1267
1339
|
}
|
|
1268
1340
|
|
|
1341
|
+
async function defaultSlackAuthRunner(options: { cwd: string; qrDataUrl: string }): Promise<SlackAuthResult> {
|
|
1342
|
+
const { runSlackBootstrap } = await import('./slack-auth')
|
|
1343
|
+
return await runSlackBootstrap({ agentDir: options.cwd, qrDataUrl: options.qrDataUrl })
|
|
1344
|
+
}
|
|
1345
|
+
|
|
1346
|
+
async function defaultDiscordAuthRunner(options: { cwd: string }): Promise<DiscordAuthResult> {
|
|
1347
|
+
const [{ runDiscordBootstrap }, QRCode] = await Promise.all([import('./discord-auth'), import('qrcode')])
|
|
1348
|
+
return await runDiscordBootstrap({
|
|
1349
|
+
agentDir: options.cwd,
|
|
1350
|
+
onQrUrl: async (url) => {
|
|
1351
|
+
const qr = await QRCode.default.toString(url, { type: 'terminal', small: true })
|
|
1352
|
+
console.log(
|
|
1353
|
+
['Open Discord mobile app → Settings → scan QR.', '', qr, '', 'Approve the login on your phone.'].join('\n'),
|
|
1354
|
+
)
|
|
1355
|
+
},
|
|
1356
|
+
})
|
|
1357
|
+
}
|
|
1358
|
+
|
|
1269
1359
|
type ChannelSecrets = Record<string, string>
|
|
1270
1360
|
|
|
1271
1361
|
// Returns the set of channel keys already present in typeclaw.json. Used by
|
|
@@ -104,34 +104,59 @@ type PackageJsonShape = {
|
|
|
104
104
|
// re-resolve `latest` on every start and silently rewrite package.json when the
|
|
105
105
|
// registry moves — bypassing the pluginAddition security gate, which only fires
|
|
106
106
|
// on a guarded config write.
|
|
107
|
+
//
|
|
108
|
+
// Registry resolution for genuinely-new bare names runs CONCURRENTLY: each
|
|
109
|
+
// `resolveLatest` spawns a `bun pm view` subprocess (a serial pass paid the
|
|
110
|
+
// per-call network round-trip once per new plugin on the cold-start critical
|
|
111
|
+
// path). A hard resolver failure (network/auth, NOT a 404) still rejects the
|
|
112
|
+
// whole pass via Promise.all, preserving the "network errors block start"
|
|
113
|
+
// contract. The `skipped` list is sorted so its order is independent of which
|
|
114
|
+
// concurrent probe settled first.
|
|
115
|
+
//
|
|
116
|
+
// Last-entry-wins is positional, matching the prior serial loop: for a name
|
|
117
|
+
// listed more than once, the LAST entry decides. An explicit/pinned version
|
|
118
|
+
// applied during the loop must therefore survive even if an EARLIER bare entry
|
|
119
|
+
// for the same name resolved from the registry afterward — so the post-await
|
|
120
|
+
// assignment is skipped for any name whose last occurrence was not the bare one.
|
|
107
121
|
async function resolveDesiredManaged(
|
|
108
122
|
plugins: readonly string[],
|
|
109
123
|
previousManaged: Record<string, string>,
|
|
110
124
|
resolveLatest: ResolveLatestVersion,
|
|
111
125
|
): Promise<{ desired: Record<string, string>; skipped: string[] }> {
|
|
112
126
|
const desired: Record<string, string> = {}
|
|
113
|
-
const
|
|
127
|
+
const bareIsLastFor = new Set<string>()
|
|
128
|
+
const toResolve: string[] = []
|
|
114
129
|
for (const entry of plugins) {
|
|
115
130
|
if (isLocalEntry(entry)) continue
|
|
116
131
|
const { name, versionSpec } = splitPluginEntrySpec(entry)
|
|
117
132
|
if (name.length === 0) continue
|
|
118
133
|
if (versionSpec !== undefined) {
|
|
119
134
|
desired[name] = versionSpec
|
|
135
|
+
bareIsLastFor.delete(name)
|
|
120
136
|
continue
|
|
121
137
|
}
|
|
122
138
|
const pinned = previousManaged[name]
|
|
123
139
|
if (pinned !== undefined) {
|
|
124
140
|
desired[name] = pinned
|
|
141
|
+
bareIsLastFor.delete(name)
|
|
125
142
|
continue
|
|
126
143
|
}
|
|
127
|
-
|
|
128
|
-
if (
|
|
144
|
+
bareIsLastFor.add(name)
|
|
145
|
+
if (!toResolve.includes(name)) toResolve.push(name)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const resolved = await Promise.all(toResolve.map(async (name) => ({ name, version: await resolveLatest(name) })))
|
|
149
|
+
const skipped: string[] = []
|
|
150
|
+
for (const { name, version } of resolved) {
|
|
151
|
+
if (!bareIsLastFor.has(name)) continue
|
|
152
|
+
if (version === null) {
|
|
129
153
|
skipped.push(name)
|
|
130
154
|
continue
|
|
131
155
|
}
|
|
132
|
-
desired[name] =
|
|
156
|
+
desired[name] = version
|
|
133
157
|
}
|
|
134
|
-
|
|
158
|
+
|
|
159
|
+
return { desired: sortKeys(desired), skipped: skipped.sort() }
|
|
135
160
|
}
|
|
136
161
|
|
|
137
162
|
function isLocalEntry(entry: string): boolean {
|
|
@@ -6,7 +6,9 @@ import { runClaimSession } from '@/role-claim'
|
|
|
6
6
|
import type { ChannelKind } from './index'
|
|
7
7
|
|
|
8
8
|
const CHANNEL_LABELS: Record<ChannelKind, string> = {
|
|
9
|
+
slack: 'Slack (User)',
|
|
9
10
|
'slack-bot': 'Slack',
|
|
11
|
+
discord: 'Discord (User)',
|
|
10
12
|
'discord-bot': 'Discord',
|
|
11
13
|
github: 'GitHub',
|
|
12
14
|
'telegram-bot': 'Telegram',
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { join } from 'node:path'
|
|
2
|
+
|
|
3
|
+
import { loginWithQr as upstreamLoginWithQr, type QrSession } from 'agent-messenger/slack'
|
|
4
|
+
|
|
5
|
+
import type { SlackAccountRecord } from '@/secrets/schema'
|
|
6
|
+
import { SecretsSlackCredentialStore } from '@/secrets/slack-store'
|
|
7
|
+
|
|
8
|
+
export type SlackBootstrapStatus = { ok: true } | { ok: false; reason: string }
|
|
9
|
+
|
|
10
|
+
export type LoginWithQrFn = typeof upstreamLoginWithQr
|
|
11
|
+
|
|
12
|
+
export type SlackLoginInput = {
|
|
13
|
+
qrDataUrl: string
|
|
14
|
+
agentDir: string
|
|
15
|
+
loginWithQr?: LoginWithQrFn
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function slackSecretsPath(agentDir: string): string {
|
|
19
|
+
return join(agentDir, 'secrets.json')
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export async function runSlackBootstrap(input: SlackLoginInput): Promise<SlackBootstrapStatus> {
|
|
23
|
+
try {
|
|
24
|
+
const loginWithQr = input.loginWithQr ?? upstreamLoginWithQr
|
|
25
|
+
const store = new SecretsSlackCredentialStore({ mode: 'host', secretsPath: slackSecretsPath(input.agentDir) })
|
|
26
|
+
const result = await loginWithQr(input.qrDataUrl)
|
|
27
|
+
const now = new Date().toISOString()
|
|
28
|
+
const accountId = workspaceId(result)
|
|
29
|
+
const account: SlackAccountRecord = {
|
|
30
|
+
account_id: accountId,
|
|
31
|
+
token: result.token,
|
|
32
|
+
cookie: result.cookie,
|
|
33
|
+
workspace_id: accountId,
|
|
34
|
+
workspace_name: result.workspace,
|
|
35
|
+
created_at: now,
|
|
36
|
+
updated_at: now,
|
|
37
|
+
}
|
|
38
|
+
await store.setAccount(account)
|
|
39
|
+
await store.setCurrentAccount(accountId)
|
|
40
|
+
return { ok: true }
|
|
41
|
+
} catch (err) {
|
|
42
|
+
return { ok: false, reason: err instanceof Error ? err.message : String(err) }
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function workspaceId(result: QrSession): string {
|
|
47
|
+
const record = result as QrSession & { workspace_id?: unknown }
|
|
48
|
+
return typeof record.workspace_id === 'string' && record.workspace_id !== '' ? record.workspace_id : result.workspace
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export type { QrSession }
|