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 @@ import type {
|
|
|
29
29
|
OutboundMessage,
|
|
30
30
|
ResolvedChannelNames,
|
|
31
31
|
SendResult,
|
|
32
|
+
TypingCallback,
|
|
33
|
+
TypingTarget,
|
|
32
34
|
} from '@/channels/types'
|
|
33
35
|
import type { WebexAccountRecord } from '@/secrets/schema'
|
|
34
36
|
|
|
@@ -112,6 +114,7 @@ export function createOutboundCallback(deps: {
|
|
|
112
114
|
|
|
113
115
|
try {
|
|
114
116
|
if (attachments.length > 0) {
|
|
117
|
+
const uploadedRefs: string[] = []
|
|
115
118
|
for (const [index, attachment] of attachments.entries()) {
|
|
116
119
|
const path = resolvePath ? resolvePath(attachment.path) : attachment.path
|
|
117
120
|
const file = await readFile(path)
|
|
@@ -121,14 +124,16 @@ export function createOutboundCallback(deps: {
|
|
|
121
124
|
...(carriesText ? { text } : {}),
|
|
122
125
|
...(parentId !== undefined ? { parentId } : {}),
|
|
123
126
|
})
|
|
127
|
+
uploadedRefs.push(sent.ref)
|
|
124
128
|
logger.info(`[webex] uploaded id=${sent.ref} filename=${file.filename} ${tag}`)
|
|
125
129
|
}
|
|
126
|
-
|
|
130
|
+
// First upload carries the text and is the thread parent, so it is the reply anchor.
|
|
131
|
+
return { ok: true, messageId: uploadedRefs[0], messageIds: uploadedRefs }
|
|
127
132
|
}
|
|
128
133
|
|
|
129
134
|
const sent = await client.sendMessage(msg.chat, text, parentId !== undefined ? { parentId } : undefined)
|
|
130
135
|
logger.info(`[webex] sent id=${sent.ref} ${tag}`)
|
|
131
|
-
return { ok: true }
|
|
136
|
+
return { ok: true, messageId: sent.ref, messageIds: [sent.ref] }
|
|
132
137
|
} catch (err) {
|
|
133
138
|
const message = describe(err)
|
|
134
139
|
logger.error(`[webex] outbound failed: ${message}`)
|
|
@@ -141,6 +146,47 @@ async function defaultReadFile(path: string): Promise<WebexOutboundFile> {
|
|
|
141
146
|
return { content: Bun.file(path), filename: path.split('/').pop() ?? 'attachment' }
|
|
142
147
|
}
|
|
143
148
|
|
|
149
|
+
// Webex's typing indicator does not auto-expire, so unlike Telegram both phases
|
|
150
|
+
// are load-bearing: 'tick' raises it (re-fired on each router heartbeat) and
|
|
151
|
+
// 'stop' explicitly clears it once the turn ends.
|
|
152
|
+
//
|
|
153
|
+
// The router fires ticks fire-and-forget (`void fireTyping(live, 'tick')`) and
|
|
154
|
+
// relies on adapters with explicit clears to order 'stop' after any in-flight
|
|
155
|
+
// 'tick' — see router.ts stopTypingHeartbeat ("The FIFO inside the slack adapter
|
|
156
|
+
// ensures this clear lands AFTER any in-flight 'tick'"). Without serialization a
|
|
157
|
+
// slow `setTyping(room, true)` could resolve AFTER the `setTyping(room, false)`
|
|
158
|
+
// clear and strand the persistent indicator on. So calls are chained through a
|
|
159
|
+
// per-room FIFO (mirroring createSlackTypingTracker) BEFORE awaiting any slow
|
|
160
|
+
// work, guaranteeing on-the-wire order matches enqueue order.
|
|
161
|
+
//
|
|
162
|
+
// A swallowed error never surfaces to the router — a dropped indicator is
|
|
163
|
+
// cosmetic and must not abort a send or teardown.
|
|
164
|
+
export function createTypingCallback(deps: {
|
|
165
|
+
client: Pick<WebexClient, 'setTyping'>
|
|
166
|
+
logger: WebexAdapterLogger
|
|
167
|
+
formatChannelTag?: (chat: string) => Promise<string>
|
|
168
|
+
}): TypingCallback {
|
|
169
|
+
const { client, logger, formatChannelTag } = deps
|
|
170
|
+
const queues = new Map<string, Promise<void>>()
|
|
171
|
+
return async (target: TypingTarget): Promise<void> => {
|
|
172
|
+
if (target.adapter !== 'webex') return
|
|
173
|
+
const typing = target.phase === 'tick'
|
|
174
|
+
const prev = queues.get(target.chat) ?? Promise.resolve()
|
|
175
|
+
const next = prev
|
|
176
|
+
.catch(() => {})
|
|
177
|
+
.then(() => client.setTyping(target.chat, typing))
|
|
178
|
+
.catch(async (err: unknown) => {
|
|
179
|
+
const tag = formatChannelTag ? await formatChannelTag(target.chat) : `room=${target.chat}`
|
|
180
|
+
logger.warn(`[webex] typing ${tag} phase=${target.phase} failed: ${describe(err)}`)
|
|
181
|
+
})
|
|
182
|
+
queues.set(target.chat, next)
|
|
183
|
+
void next.finally(() => {
|
|
184
|
+
if (queues.get(target.chat) === next) queues.delete(target.chat)
|
|
185
|
+
})
|
|
186
|
+
await next
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
144
190
|
// The Webex REST/internal client offers no AbortSignal, so a hung `listMessages`
|
|
145
191
|
// would otherwise block cold-start prefetch for the router's full 5s history
|
|
146
192
|
// ceiling before degrading. Racing it against a tighter internal deadline lets
|
|
@@ -305,6 +351,7 @@ export function createWebexAdapter(options: WebexAdapterOptions): WebexAdapter {
|
|
|
305
351
|
botPersonIdRef: () => botPerson?.ref ?? null,
|
|
306
352
|
})
|
|
307
353
|
const outboundCallback = createOutboundCallback({ client, logger, formatChannelTag })
|
|
354
|
+
const typingCallback = createTypingCallback({ client, logger, formatChannelTag })
|
|
308
355
|
const fetchAttachmentCallback = createFetchAttachmentCallback({ tokenRef: () => currentToken, logger, fetchImpl })
|
|
309
356
|
|
|
310
357
|
const handleMessage = async (event: WebexInboundMessage): Promise<void> => {
|
|
@@ -391,6 +438,8 @@ export function createWebexAdapter(options: WebexAdapterOptions): WebexAdapter {
|
|
|
391
438
|
})
|
|
392
439
|
|
|
393
440
|
options.router.registerOutbound('webex', outboundCallback)
|
|
441
|
+
options.router.registerTyping('webex', typingCallback)
|
|
442
|
+
options.router.setTypingCapability('webex', true)
|
|
394
443
|
options.router.registerChannelNameResolver('webex', channelResolver)
|
|
395
444
|
options.router.registerSelfIdentity('webex', selfIdentityResolver)
|
|
396
445
|
options.router.registerHistory('webex', historyCallback)
|
|
@@ -399,6 +448,8 @@ export function createWebexAdapter(options: WebexAdapterOptions): WebexAdapter {
|
|
|
399
448
|
|
|
400
449
|
const rollbackStart = (reason: string, cause: Error): never => {
|
|
401
450
|
options.router.unregisterOutbound('webex', outboundCallback)
|
|
451
|
+
options.router.unregisterTyping('webex', typingCallback)
|
|
452
|
+
options.router.setTypingCapability('webex', false)
|
|
402
453
|
options.router.unregisterChannelNameResolver('webex', channelResolver)
|
|
403
454
|
options.router.unregisterSelfIdentity('webex', selfIdentityResolver)
|
|
404
455
|
options.router.unregisterHistory('webex', historyCallback)
|
|
@@ -431,6 +482,8 @@ export function createWebexAdapter(options: WebexAdapterOptions): WebexAdapter {
|
|
|
431
482
|
if (!started) return
|
|
432
483
|
started = false
|
|
433
484
|
options.router.unregisterOutbound('webex', outboundCallback)
|
|
485
|
+
options.router.unregisterTyping('webex', typingCallback)
|
|
486
|
+
options.router.setTypingCapability('webex', false)
|
|
434
487
|
options.router.unregisterChannelNameResolver('webex', channelResolver)
|
|
435
488
|
options.router.unregisterSelfIdentity('webex', selfIdentityResolver)
|
|
436
489
|
options.router.unregisterHistory('webex', historyCallback)
|
|
@@ -8,12 +8,35 @@
|
|
|
8
8
|
|
|
9
9
|
export type ReviewVerdict = 'APPROVE' | 'REQUEST_CHANGES'
|
|
10
10
|
|
|
11
|
+
export type ReviewObserver = (args: {
|
|
12
|
+
sessionId: string
|
|
13
|
+
workspace: string
|
|
14
|
+
prNumber: number
|
|
15
|
+
verdict: ReviewVerdict
|
|
16
|
+
}) => void
|
|
17
|
+
|
|
11
18
|
type PrKey = string
|
|
12
19
|
type ThreadKey = string
|
|
13
20
|
|
|
14
21
|
const reviewsByPr = new Map<PrKey, Set<ReviewVerdict>>()
|
|
15
22
|
const resolvedThreads = new Set<ThreadKey>()
|
|
16
23
|
|
|
24
|
+
// A single process-wide observer notified AFTER a verdict is recorded, so the
|
|
25
|
+
// run-side wiring can fan a landed verdict out over the broadcast bus to sibling
|
|
26
|
+
// PR sessions (see github-verdict-activity.ts) WITHOUT giving the github-cli-auth
|
|
27
|
+
// plugin stream access. Registered once at boot from run/index.ts. The ledger
|
|
28
|
+
// stays the single seam where "a formal verdict happened" is known across the
|
|
29
|
+
// plugin/channels boundary, which is why it owns this hook.
|
|
30
|
+
let reviewObserver: ReviewObserver | null = null
|
|
31
|
+
|
|
32
|
+
export function setReviewObserver(observer: ReviewObserver | null): void {
|
|
33
|
+
reviewObserver = observer
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function __resetReviewObserverForTest(): void {
|
|
37
|
+
reviewObserver = null
|
|
38
|
+
}
|
|
39
|
+
|
|
17
40
|
function prKey(sessionId: string, workspace: string, prNumber: number): PrKey {
|
|
18
41
|
return `${sessionId}::${workspace}::${prNumber}`
|
|
19
42
|
}
|
|
@@ -41,6 +64,15 @@ export function recordReview(args: {
|
|
|
41
64
|
const set = reviewsByPr.get(key) ?? new Set<ReviewVerdict>()
|
|
42
65
|
set.add(args.verdict)
|
|
43
66
|
reviewsByPr.set(key, set)
|
|
67
|
+
// Notify AFTER the record lands and never let an observer failure corrupt the
|
|
68
|
+
// ledger write — the false-receipt guard depends on this record being durable.
|
|
69
|
+
if (reviewObserver !== null) {
|
|
70
|
+
try {
|
|
71
|
+
reviewObserver(args)
|
|
72
|
+
} catch {
|
|
73
|
+
// swallow: a broken broadcast must not break verdict bookkeeping
|
|
74
|
+
}
|
|
75
|
+
}
|
|
44
76
|
}
|
|
45
77
|
|
|
46
78
|
export function hasReview(args: {
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { ReviewVerdict } from './github-review-turn-ledger'
|
|
2
|
+
|
|
3
|
+
// A formal review verdict (APPROVE / REQUEST_CHANGES) that LANDED on a PR, fanned
|
|
4
|
+
// out over the broadcast bus so the OTHER live sessions reviewing the same PR
|
|
5
|
+
// stand down from posting their own redundant verdict. The duplicate-review
|
|
6
|
+
// incident was driven by per-thread session fan-out: N sessions for one PR each
|
|
7
|
+
// independently submitted a verdict, blind to the others. The hard idempotency
|
|
8
|
+
// lease + cooldown catch overlapping/near-simultaneous submits; this advisory
|
|
9
|
+
// signal covers the SEQUENTIAL case — a sibling that wakes after another already
|
|
10
|
+
// landed the verdict and would otherwise re-derive and re-submit it.
|
|
11
|
+
//
|
|
12
|
+
// Routing is by { workspace, prNumber } only (the PR is the unit), with sessionId
|
|
13
|
+
// carried so the publisher excludes itself. No channel key — the publish seam is
|
|
14
|
+
// the turn-ledger's recordReview(), which has no channel coordinate, and Oracle's
|
|
15
|
+
// review favored not expanding plugin coupling just to mirror subagent.completed.
|
|
16
|
+
|
|
17
|
+
export type PrVerdictActivityPayload = {
|
|
18
|
+
workspace: string
|
|
19
|
+
prNumber: number
|
|
20
|
+
verdict: ReviewVerdict
|
|
21
|
+
sessionId: string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function parsePrVerdictActivityPayload(payload: unknown): PrVerdictActivityPayload | null {
|
|
25
|
+
if (payload === null || typeof payload !== 'object') return null
|
|
26
|
+
const p = payload as {
|
|
27
|
+
kind?: unknown
|
|
28
|
+
workspace?: unknown
|
|
29
|
+
prNumber?: unknown
|
|
30
|
+
verdict?: unknown
|
|
31
|
+
sessionId?: unknown
|
|
32
|
+
}
|
|
33
|
+
if (p.kind !== 'pr.verdict-activity') return null
|
|
34
|
+
if (typeof p.workspace !== 'string' || p.workspace === '') return null
|
|
35
|
+
if (typeof p.prNumber !== 'number' || !Number.isInteger(p.prNumber)) return null
|
|
36
|
+
if (typeof p.sessionId !== 'string' || p.sessionId === '') return null
|
|
37
|
+
const verdict = parseVerdict(p.verdict)
|
|
38
|
+
if (verdict === null) return null
|
|
39
|
+
return { workspace: p.workspace, prNumber: p.prNumber, verdict, sessionId: p.sessionId }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function parseVerdict(value: unknown): ReviewVerdict | null {
|
|
43
|
+
return value === 'APPROVE' || value === 'REQUEST_CHANGES' ? value : null
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Advisory and deliberately soft (per the design review): it must not suppress a
|
|
47
|
+
// genuine flipped verdict or a re-review after new commits/evidence, so it forbids
|
|
48
|
+
// only a REDUNDANT same-intent verdict and explicitly preserves inline-thread
|
|
49
|
+
// replies. The hard guards remain the correctness boundary; this only trims wasted
|
|
50
|
+
// sibling work before they fire.
|
|
51
|
+
export function renderPrVerdictStandDownReminder(args: { prNumber: number; verdict: ReviewVerdict }): string {
|
|
52
|
+
return (
|
|
53
|
+
`<system-reminder>\n` +
|
|
54
|
+
`Another session in this agent has already posted a formal ${args.verdict} review for PR #${args.prNumber}. ` +
|
|
55
|
+
`Do not submit your own ${args.verdict} (or any redundant verdict) for this PR this turn unless new ` +
|
|
56
|
+
`information genuinely invalidates that result (e.g. new commits, or a different verdict warranted by ` +
|
|
57
|
+
`fresh evidence). You may still reply to inline review comments / threads as normal.\n` +
|
|
58
|
+
`</system-reminder>`
|
|
59
|
+
)
|
|
60
|
+
}
|
package/src/channels/index.ts
CHANGED
|
@@ -15,6 +15,12 @@ export {
|
|
|
15
15
|
type CreateSessionForChannel,
|
|
16
16
|
} from './router'
|
|
17
17
|
export { createChannelsReloadable } from './reloadable'
|
|
18
|
+
export {
|
|
19
|
+
createPrVerdictActivityBridge,
|
|
20
|
+
type PrVerdictActivityBridge,
|
|
21
|
+
type PrVerdictActivityBridgeOptions,
|
|
22
|
+
} from './pr-verdict-activity-bridge'
|
|
23
|
+
export { setReviewObserver } from './github-review-turn-ledger'
|
|
18
24
|
export {
|
|
19
25
|
createSubagentCompletionBridge,
|
|
20
26
|
type SubagentCompletionBridge,
|
package/src/channels/manager.ts
CHANGED
|
@@ -3,16 +3,20 @@ import { join } from 'node:path'
|
|
|
3
3
|
|
|
4
4
|
import type { PermissionService } from '@/permissions'
|
|
5
5
|
import type { GithubSecretsBlock } from '@/secrets'
|
|
6
|
+
import { SecretsDiscordCredentialStore } from '@/secrets/discord-store'
|
|
6
7
|
import { SecretsKakaoCredentialStore } from '@/secrets/kakao-store'
|
|
7
8
|
import { SecretsLineCredentialStore } from '@/secrets/line-store'
|
|
9
|
+
import { SecretsSlackCredentialStore } from '@/secrets/slack-store'
|
|
8
10
|
import { SecretsBackend } from '@/secrets/storage'
|
|
9
11
|
import { SecretsWebexCredentialStore } from '@/secrets/webex-store'
|
|
10
12
|
import type { Stream } from '@/stream'
|
|
11
13
|
|
|
14
|
+
import { createDiscordAdapter, type DiscordAdapter } from './adapters/discord'
|
|
12
15
|
import { createDiscordBotAdapter, type DiscordBotAdapter } from './adapters/discord-bot'
|
|
13
16
|
import { createGithubAdapter, type GithubAdapter } from './adapters/github'
|
|
14
17
|
import { createKakaotalkAdapter, type KakaotalkAdapter } from './adapters/kakaotalk'
|
|
15
18
|
import { createLineAdapter, type LineAdapter } from './adapters/line'
|
|
19
|
+
import { createSlackAdapter, type SlackAdapter } from './adapters/slack'
|
|
16
20
|
import { createSlackBotAdapter, type SlackBotAdapter } from './adapters/slack-bot'
|
|
17
21
|
import { createTelegramBotAdapter, type TelegramBotAdapter } from './adapters/telegram-bot'
|
|
18
22
|
import { createWebexAdapter, type WebexAdapter } from './adapters/webex'
|
|
@@ -69,10 +73,12 @@ export type ChannelManagerOptions = {
|
|
|
69
73
|
createSessionForChannel?: CreateSessionForChannel
|
|
70
74
|
// Test seams: let fake adapters replace the real adapter wiring per id.
|
|
71
75
|
createDiscordAdapter?: typeof createDiscordBotAdapter
|
|
76
|
+
createDiscordUserAdapter?: typeof createDiscordAdapter
|
|
72
77
|
createGithubAdapter?: typeof createGithubAdapter
|
|
73
78
|
createKakaotalkAdapter?: typeof createKakaotalkAdapter
|
|
74
79
|
createLineAdapter?: typeof createLineAdapter
|
|
75
80
|
createSlackAdapter?: typeof createSlackBotAdapter
|
|
81
|
+
createSlackUserAdapter?: typeof createSlackAdapter
|
|
76
82
|
createTelegramAdapter?: typeof createTelegramBotAdapter
|
|
77
83
|
createWebexAdapter?: typeof createWebexAdapter
|
|
78
84
|
createWebexBotAdapter?: typeof createWebexBotAdapter
|
|
@@ -109,6 +115,11 @@ export type ChannelManagerOptions = {
|
|
|
109
115
|
// unregistered. See CreateChannelRouterOptions.onReload/onRestart.
|
|
110
116
|
onReload?: () => Promise<string>
|
|
111
117
|
onRestart?: (ctx?: RestartCommandContext) => Promise<string>
|
|
118
|
+
// Forwarded to the router so idle GC and stale-rollover can pin a channel
|
|
119
|
+
// session whose background subagent is still running (the next inbound would
|
|
120
|
+
// otherwise spawn a duplicate child). Production wiring (src/run/index.ts)
|
|
121
|
+
// supplies it from the LiveSubagentRegistry; tests omit it.
|
|
122
|
+
newestRunningChildSubagentStartedAt?: (sessionId: string) => number | null
|
|
112
123
|
// Persistent messenger SDKs usually reconnect themselves, but a host sleep/offline
|
|
113
124
|
// cycle can leave a socket half-dead forever. The manager watches live adapters
|
|
114
125
|
// and restarts one that stays disconnected past this grace period. Test seams are
|
|
@@ -131,10 +142,12 @@ export type ChannelManager = {
|
|
|
131
142
|
}
|
|
132
143
|
|
|
133
144
|
type AnyAdapter =
|
|
145
|
+
| DiscordAdapter
|
|
134
146
|
| DiscordBotAdapter
|
|
135
147
|
| GithubAdapter
|
|
136
148
|
| LineAdapter
|
|
137
149
|
| KakaotalkAdapter
|
|
150
|
+
| SlackAdapter
|
|
138
151
|
| SlackBotAdapter
|
|
139
152
|
| TelegramBotAdapter
|
|
140
153
|
| WebexAdapter
|
|
@@ -168,12 +181,17 @@ export function createChannelManager(options: ChannelManagerOptions): ChannelMan
|
|
|
168
181
|
...(options.stream ? { stream: options.stream } : {}),
|
|
169
182
|
...(options.onReload ? { onReload: options.onReload } : {}),
|
|
170
183
|
...(options.onRestart ? { onRestart: options.onRestart } : {}),
|
|
184
|
+
...(options.newestRunningChildSubagentStartedAt
|
|
185
|
+
? { newestRunningChildSubagentStartedAt: options.newestRunningChildSubagentStartedAt }
|
|
186
|
+
: {}),
|
|
171
187
|
})
|
|
172
|
-
const
|
|
188
|
+
const createDiscordBot = options.createDiscordAdapter ?? createDiscordBotAdapter
|
|
189
|
+
const createDiscordUser = options.createDiscordUserAdapter ?? createDiscordAdapter
|
|
173
190
|
const createGithub = options.createGithubAdapter ?? createGithubAdapter
|
|
174
191
|
const createKakaotalk = options.createKakaotalkAdapter ?? createKakaotalkAdapter
|
|
175
192
|
const createLine = options.createLineAdapter ?? createLineAdapter
|
|
176
|
-
const
|
|
193
|
+
const createSlackBot = options.createSlackAdapter ?? createSlackBotAdapter
|
|
194
|
+
const createSlackUser = options.createSlackUserAdapter ?? createSlackAdapter
|
|
177
195
|
const createTelegramAdapter = options.createTelegramAdapter ?? createTelegramBotAdapter
|
|
178
196
|
const createWebex = options.createWebexAdapter ?? createWebexAdapter
|
|
179
197
|
const createWebexBot = options.createWebexBotAdapter ?? createWebexBotAdapter
|
|
@@ -203,6 +221,8 @@ export function createChannelManager(options: ChannelManagerOptions): ChannelMan
|
|
|
203
221
|
if (name === 'line') return buildLineSignature(options.agentDir)
|
|
204
222
|
if (name === 'kakaotalk') return buildKakaotalkSignature(options.agentDir)
|
|
205
223
|
if (name === 'webex') return buildWebexSignature(options.agentDir)
|
|
224
|
+
if (name === 'slack') return buildSlackSignature(options.agentDir)
|
|
225
|
+
if (name === 'discord') return buildDiscordSignature(options.agentDir)
|
|
206
226
|
if (name === 'github') return buildGithubSignature(options.agentDir)
|
|
207
227
|
const requiredEnvs = TOKEN_ENV[name]
|
|
208
228
|
const parts: string[] = []
|
|
@@ -219,7 +239,7 @@ export function createChannelManager(options: ChannelManagerOptions): ChannelMan
|
|
|
219
239
|
if (name === 'discord-bot') {
|
|
220
240
|
const token = env.DISCORD_BOT_TOKEN
|
|
221
241
|
if (token === undefined || token.trim() === '') return null
|
|
222
|
-
return
|
|
242
|
+
return createDiscordBot({
|
|
223
243
|
router,
|
|
224
244
|
configRef: () => options.channelsConfigRef()[name] ?? cfg,
|
|
225
245
|
token,
|
|
@@ -231,7 +251,7 @@ export function createChannelManager(options: ChannelManagerOptions): ChannelMan
|
|
|
231
251
|
const appToken = env.SLACK_APP_TOKEN
|
|
232
252
|
if (token === undefined || token.trim() === '') return null
|
|
233
253
|
if (appToken === undefined || appToken.trim() === '') return null
|
|
234
|
-
return
|
|
254
|
+
return createSlackBot({
|
|
235
255
|
router,
|
|
236
256
|
configRef: () => options.channelsConfigRef()[name] ?? cfg,
|
|
237
257
|
token,
|
|
@@ -258,6 +278,24 @@ export function createChannelManager(options: ChannelManagerOptions): ChannelMan
|
|
|
258
278
|
credentialsStore: createContainerKakaoCredentialStore(options.agentDir, env),
|
|
259
279
|
})
|
|
260
280
|
}
|
|
281
|
+
if (name === 'slack') {
|
|
282
|
+
return createSlackUser({
|
|
283
|
+
router,
|
|
284
|
+
configRef: () => options.channelsConfigRef()[name] ?? cfg,
|
|
285
|
+
logger,
|
|
286
|
+
selfAliasesRef: () => router.getSelfAliases(),
|
|
287
|
+
credentialsStore: createContainerSlackCredentialStore(options.agentDir, env),
|
|
288
|
+
})
|
|
289
|
+
}
|
|
290
|
+
if (name === 'discord') {
|
|
291
|
+
return createDiscordUser({
|
|
292
|
+
router,
|
|
293
|
+
configRef: () => options.channelsConfigRef()[name] ?? cfg,
|
|
294
|
+
logger,
|
|
295
|
+
selfAliasesRef: () => router.getSelfAliases(),
|
|
296
|
+
credentialsStore: createContainerDiscordCredentialStore(options.agentDir, env),
|
|
297
|
+
})
|
|
298
|
+
}
|
|
261
299
|
if (name === 'webex') {
|
|
262
300
|
return createWebex({
|
|
263
301
|
router,
|
|
@@ -474,7 +512,9 @@ export function createChannelManager(options: ChannelManagerOptions): ChannelMan
|
|
|
474
512
|
stopped.push(name)
|
|
475
513
|
} else if (signature !== current.credentialSignature) {
|
|
476
514
|
const reason =
|
|
477
|
-
name === 'kakaotalk' || name === 'line' || name === 'webex'
|
|
515
|
+
name === 'kakaotalk' || name === 'line' || name === 'webex' || name === 'slack' || name === 'discord'
|
|
516
|
+
? 'credential rotation'
|
|
517
|
+
: 'token rotation'
|
|
478
518
|
restartRequired.push(`${name} (${reason})`)
|
|
479
519
|
}
|
|
480
520
|
}
|
|
@@ -488,13 +528,79 @@ export function createChannelManager(options: ChannelManagerOptions): ChannelMan
|
|
|
488
528
|
// Token-based adapters only. Personal-account credentials live in
|
|
489
529
|
// secrets.json#channels.<adapter>, not in env, so they go through
|
|
490
530
|
// structured-block signatures instead.
|
|
491
|
-
const TOKEN_ENV: Record<
|
|
531
|
+
const TOKEN_ENV: Record<
|
|
532
|
+
Exclude<AdapterId, 'kakaotalk' | 'line' | 'github' | 'webex' | 'slack' | 'discord'>,
|
|
533
|
+
readonly string[]
|
|
534
|
+
> = {
|
|
492
535
|
'discord-bot': ['DISCORD_BOT_TOKEN'],
|
|
493
536
|
'slack-bot': ['SLACK_BOT_TOKEN', 'SLACK_APP_TOKEN'],
|
|
494
537
|
'telegram-bot': ['TELEGRAM_BOT_TOKEN'],
|
|
495
538
|
'webex-bot': ['WEBEX_BOT_TOKEN'],
|
|
496
539
|
}
|
|
497
540
|
|
|
541
|
+
function createContainerDiscordCredentialStore(
|
|
542
|
+
agentDir: string,
|
|
543
|
+
env: NodeJS.ProcessEnv,
|
|
544
|
+
): SecretsDiscordCredentialStore {
|
|
545
|
+
const hostdUrl = env.TYPECLAW_HOSTD_URL
|
|
546
|
+
const restartToken = env.TYPECLAW_HOSTD_TOKEN
|
|
547
|
+
const containerName = env.TYPECLAW_CONTAINER_NAME
|
|
548
|
+
if (!hostdUrl || !restartToken || !containerName) {
|
|
549
|
+
throw new Error('Discord credentials require TYPECLAW_HOSTD_URL, TYPECLAW_HOSTD_TOKEN, and TYPECLAW_CONTAINER_NAME')
|
|
550
|
+
}
|
|
551
|
+
return new SecretsDiscordCredentialStore({
|
|
552
|
+
mode: 'container',
|
|
553
|
+
secretsPath: join(agentDir, 'secrets.json'),
|
|
554
|
+
hostdUrl,
|
|
555
|
+
restartToken,
|
|
556
|
+
containerName,
|
|
557
|
+
})
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
function buildDiscordSignature(agentDir: string): { signature: string; missing: string[] } {
|
|
561
|
+
const path = join(agentDir, 'secrets.json')
|
|
562
|
+
try {
|
|
563
|
+
const block = new SecretsBackend(path).tryReadChannelsSync()?.discord
|
|
564
|
+
if (!isDiscordCredentialBlock(block)) {
|
|
565
|
+
return { signature: '', missing: ['secrets.json#channels.discord'] }
|
|
566
|
+
}
|
|
567
|
+
const digest = createHash('sha256').update(JSON.stringify(block)).digest('hex')
|
|
568
|
+
return { signature: `secrets.json#channels.discord@sha256:${digest}`, missing: [] }
|
|
569
|
+
} catch (err) {
|
|
570
|
+
return { signature: '', missing: [`secrets.json#channels.discord (${describe(err)})`] }
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
function createContainerSlackCredentialStore(agentDir: string, env: NodeJS.ProcessEnv): SecretsSlackCredentialStore {
|
|
575
|
+
const hostdUrl = env.TYPECLAW_HOSTD_URL
|
|
576
|
+
const restartToken = env.TYPECLAW_HOSTD_TOKEN
|
|
577
|
+
const containerName = env.TYPECLAW_CONTAINER_NAME
|
|
578
|
+
if (!hostdUrl || !restartToken || !containerName) {
|
|
579
|
+
throw new Error('Slack credentials require TYPECLAW_HOSTD_URL, TYPECLAW_HOSTD_TOKEN, and TYPECLAW_CONTAINER_NAME')
|
|
580
|
+
}
|
|
581
|
+
return new SecretsSlackCredentialStore({
|
|
582
|
+
mode: 'container',
|
|
583
|
+
secretsPath: join(agentDir, 'secrets.json'),
|
|
584
|
+
hostdUrl,
|
|
585
|
+
restartToken,
|
|
586
|
+
containerName,
|
|
587
|
+
})
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
function buildSlackSignature(agentDir: string): { signature: string; missing: string[] } {
|
|
591
|
+
const path = join(agentDir, 'secrets.json')
|
|
592
|
+
try {
|
|
593
|
+
const block = new SecretsBackend(path).tryReadChannelsSync()?.slack
|
|
594
|
+
if (!isSlackCredentialBlock(block)) {
|
|
595
|
+
return { signature: '', missing: ['secrets.json#channels.slack'] }
|
|
596
|
+
}
|
|
597
|
+
const digest = createHash('sha256').update(JSON.stringify(block)).digest('hex')
|
|
598
|
+
return { signature: `secrets.json#channels.slack@sha256:${digest}`, missing: [] }
|
|
599
|
+
} catch (err) {
|
|
600
|
+
return { signature: '', missing: [`secrets.json#channels.slack (${describe(err)})`] }
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
|
|
498
604
|
function createContainerWebexCredentialStore(agentDir: string, env: NodeJS.ProcessEnv): SecretsWebexCredentialStore {
|
|
499
605
|
const hostdUrl = env.TYPECLAW_HOSTD_URL
|
|
500
606
|
const restartToken = env.TYPECLAW_HOSTD_TOKEN
|
|
@@ -631,6 +737,24 @@ function isLineCredentialBlock(value: unknown): value is { accounts: Record<stri
|
|
|
631
737
|
)
|
|
632
738
|
}
|
|
633
739
|
|
|
740
|
+
function isSlackCredentialBlock(value: unknown): value is { accounts: Record<string, unknown> } {
|
|
741
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) return false
|
|
742
|
+
if (!('accounts' in value)) return false
|
|
743
|
+
const accounts = value.accounts
|
|
744
|
+
return (
|
|
745
|
+
typeof accounts === 'object' && accounts !== null && !Array.isArray(accounts) && Object.keys(accounts).length > 0
|
|
746
|
+
)
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
function isDiscordCredentialBlock(value: unknown): value is { accounts: Record<string, unknown> } {
|
|
750
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) return false
|
|
751
|
+
if (!('accounts' in value)) return false
|
|
752
|
+
const accounts = value.accounts
|
|
753
|
+
return (
|
|
754
|
+
typeof accounts === 'object' && accounts !== null && !Array.isArray(accounts) && Object.keys(accounts).length > 0
|
|
755
|
+
)
|
|
756
|
+
}
|
|
757
|
+
|
|
634
758
|
function isWebexCredentialBlock(value: unknown): value is { accounts: Record<string, unknown> } {
|
|
635
759
|
if (typeof value !== 'object' || value === null || Array.isArray(value)) return false
|
|
636
760
|
if (!('accounts' in value)) return false
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Stream } from '@/stream'
|
|
2
|
+
|
|
3
|
+
import { parsePrVerdictActivityPayload } from './github-verdict-activity'
|
|
4
|
+
import type { ChannelRouter } from './router'
|
|
5
|
+
|
|
6
|
+
export type PrVerdictActivityBridgeLogger = {
|
|
7
|
+
info: (msg: string) => void
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type PrVerdictActivityBridgeOptions = {
|
|
11
|
+
stream: Stream
|
|
12
|
+
router: Pick<ChannelRouter, 'injectPrVerdictActivity'>
|
|
13
|
+
logger?: PrVerdictActivityBridgeLogger
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type PrVerdictActivityBridge = {
|
|
17
|
+
stop: () => void
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const consoleLogger: PrVerdictActivityBridgeLogger = {
|
|
21
|
+
info: (msg) => console.log(msg),
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Bridges `pr.verdict-activity` broadcasts on the in-process Stream into a router
|
|
25
|
+
// call so the OTHER live sessions reviewing the same PR get a stand-down reminder
|
|
26
|
+
// once one of them lands a formal verdict. Mirrors the subagent-completion bridge:
|
|
27
|
+
// one broadcast subscriber, self-filtering payload parse, single router call. The
|
|
28
|
+
// verdict reaches the bus via the turn-ledger review observer (src/run/index.ts),
|
|
29
|
+
// because plugins have no direct stream access.
|
|
30
|
+
export function createPrVerdictActivityBridge(options: PrVerdictActivityBridgeOptions): PrVerdictActivityBridge {
|
|
31
|
+
const logger = options.logger ?? consoleLogger
|
|
32
|
+
const unsubscribe = options.stream.subscribe({ target: { kind: 'broadcast' } }, (msg) => {
|
|
33
|
+
const parsed = parsePrVerdictActivityPayload(msg.payload)
|
|
34
|
+
if (parsed === null) return
|
|
35
|
+
const result = options.router.injectPrVerdictActivity(parsed)
|
|
36
|
+
if (result.count > 0) {
|
|
37
|
+
logger.info(
|
|
38
|
+
`[channels] pr-verdict stand-down fanned out to ${result.count} sibling session(s) for ${parsed.workspace}#${parsed.prNumber} verdict=${parsed.verdict}`,
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
return { stop: unsubscribe }
|
|
43
|
+
}
|