typeclaw 0.43.1 → 0.44.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 +1 -1
- package/auth.schema.json +92 -0
- package/package.json +2 -2
- package/secrets.schema.json +92 -0
- package/src/agent/index.ts +14 -2
- package/src/agent/multimodal/look-at.ts +27 -9
- package/src/agent/plugin-tools.ts +9 -4
- package/src/agent/session-origin.ts +1 -0
- package/src/agent/tools/channel-fetch-attachment.ts +45 -3
- package/src/agent/tools/channel-reply.ts +41 -18
- package/src/agent/tools/channel-send.ts +82 -13
- package/src/bundled-plugins/github-cli-auth/gh-review-detect.ts +101 -1
- package/src/bundled-plugins/github-cli-auth/review-recorder.ts +44 -3
- package/src/bundled-plugins/guard/policies/managed-config.ts +20 -4
- package/src/bundled-plugins/memory/README.md +9 -9
- package/src/bundled-plugins/memory/index.ts +40 -9
- package/src/channels/adapters/github/inbound.ts +20 -14
- package/src/channels/adapters/github/review-thread-resolver.ts +38 -4
- package/src/channels/adapters/teams-classify.ts +144 -0
- package/src/channels/adapters/teams-id-token.ts +112 -0
- package/src/channels/adapters/teams-key.ts +32 -0
- package/src/channels/adapters/teams.ts +519 -0
- package/src/channels/github-review-turn-ledger.ts +43 -0
- package/src/channels/index.ts +1 -1
- package/src/channels/manager.ts +54 -1
- package/src/channels/router.ts +302 -39
- package/src/channels/schema.ts +9 -0
- package/src/cli/channel.ts +92 -4
- package/src/cli/hostd.ts +41 -0
- package/src/cli/init.ts +58 -1
- package/src/config/channels-mutation.ts +9 -1
- package/src/cron/index.ts +16 -4
- package/src/cron/reloadable.ts +25 -7
- package/src/cron/scheduler.ts +4 -0
- package/src/cron/schema.ts +143 -35
- package/src/doctor/channel-checks.ts +27 -0
- package/src/hostd/daemon.ts +23 -3
- package/src/hostd/protocol.ts +2 -0
- package/src/hostd/teams-renewal-manager.ts +212 -0
- package/src/init/checkpoint.ts +1 -1
- package/src/init/index.ts +68 -1
- package/src/init/run-owner-claim.ts +1 -0
- package/src/init/teams-auth.ts +111 -0
- package/src/inspect/label.ts +4 -0
- package/src/permissions/match-rule.ts +11 -1
- package/src/permissions/resolve.ts +1 -0
- package/src/role-claim/match-rule.ts +2 -1
- package/src/run/index.ts +35 -8
- package/src/run/llm-fetch-observer.ts +27 -5
- package/src/sandbox/build.ts +12 -0
- package/src/sandbox/policy.ts +13 -0
- package/src/sandbox/writable-zones.ts +46 -10
- package/src/secrets/schema.ts +32 -0
- package/src/secrets/teams-renewal.ts +229 -0
- package/src/secrets/teams-store.ts +108 -0
- package/typeclaw.schema.json +163 -3
package/src/init/index.ts
CHANGED
|
@@ -89,6 +89,7 @@ export type InitStep =
|
|
|
89
89
|
| 'instagram-auth'
|
|
90
90
|
| 'kakaotalk-auth'
|
|
91
91
|
| 'webex-auth'
|
|
92
|
+
| 'teams-auth'
|
|
92
93
|
| 'github-webhooks'
|
|
93
94
|
| 'install'
|
|
94
95
|
| 'dockerfile'
|
|
@@ -97,6 +98,7 @@ export type InitStep =
|
|
|
97
98
|
|
|
98
99
|
export type KakaotalkAuthResult = { ok: true } | { ok: false; reason: string }
|
|
99
100
|
export type WebexAuthResult = { ok: true } | { ok: false; reason: string }
|
|
101
|
+
export type TeamsAuthResult = { ok: true } | { ok: false; reason: string }
|
|
100
102
|
export type SlackAuthResult = { ok: true } | { ok: false; reason: string }
|
|
101
103
|
export type DiscordAuthResult = { ok: true } | { ok: false; reason: string }
|
|
102
104
|
export type InstagramAuthResult = { ok: true } | { ok: false; reason: string }
|
|
@@ -137,6 +139,8 @@ export type InitStepEvent =
|
|
|
137
139
|
| { step: 'kakaotalk-auth'; phase: 'done'; result: KakaotalkAuthResult }
|
|
138
140
|
| { step: 'webex-auth'; phase: 'start' }
|
|
139
141
|
| { step: 'webex-auth'; phase: 'done'; result: WebexAuthResult }
|
|
142
|
+
| { step: 'teams-auth'; phase: 'start' }
|
|
143
|
+
| { step: 'teams-auth'; phase: 'done'; result: TeamsAuthResult }
|
|
140
144
|
| { step: 'discord-auth'; phase: 'start' }
|
|
141
145
|
| { step: 'discord-auth'; phase: 'done'; result: DiscordAuthResult }
|
|
142
146
|
| { step: 'instagram-auth'; phase: 'start' }
|
|
@@ -170,6 +174,7 @@ export type HatchRunner = (options: {
|
|
|
170
174
|
|
|
171
175
|
export type KakaotalkAuthRunner = (options: { cwd: string }) => Promise<KakaotalkAuthResult>
|
|
172
176
|
export type WebexAuthRunner = (options: { cwd: string }) => Promise<WebexAuthResult>
|
|
177
|
+
export type TeamsAuthRunner = (options: { cwd: string }) => Promise<TeamsAuthResult>
|
|
173
178
|
|
|
174
179
|
export type LineAuthResult = { ok: true } | { ok: false; reason: string }
|
|
175
180
|
export type LineAuthRunner = (options: { cwd: string }) => Promise<LineAuthResult>
|
|
@@ -228,11 +233,13 @@ export type InitOptions = {
|
|
|
228
233
|
withTelegram?: boolean
|
|
229
234
|
withWebex?: boolean
|
|
230
235
|
withWebexUser?: boolean
|
|
236
|
+
withTeams?: boolean
|
|
231
237
|
withInstagram?: boolean
|
|
232
238
|
withKakaotalk?: boolean
|
|
233
239
|
withGithub?: boolean
|
|
234
240
|
runKakaotalkAuth?: KakaotalkAuthRunner
|
|
235
241
|
runWebexAuth?: WebexAuthRunner
|
|
242
|
+
runTeamsAuth?: TeamsAuthRunner
|
|
236
243
|
runDiscordAuth?: DiscordAuthRunner
|
|
237
244
|
runInstagramAuth?: InstagramAuthRunner
|
|
238
245
|
// Structured GitHub credentials collected by the wizard. When omitted and
|
|
@@ -280,11 +287,13 @@ export async function runInit({
|
|
|
280
287
|
withTelegram,
|
|
281
288
|
withWebex,
|
|
282
289
|
withWebexUser = false,
|
|
290
|
+
withTeams = false,
|
|
283
291
|
withInstagram = false,
|
|
284
292
|
withKakaotalk = false,
|
|
285
293
|
withGithub = false,
|
|
286
294
|
runKakaotalkAuth,
|
|
287
295
|
runWebexAuth,
|
|
296
|
+
runTeamsAuth,
|
|
288
297
|
runDiscordAuth,
|
|
289
298
|
runInstagramAuth,
|
|
290
299
|
githubCredentials,
|
|
@@ -367,6 +376,7 @@ export async function runInit({
|
|
|
367
376
|
withTelegram: wantsTelegram,
|
|
368
377
|
withWebex: wantsWebex,
|
|
369
378
|
withWebexUser,
|
|
379
|
+
withTeams,
|
|
370
380
|
withInstagram,
|
|
371
381
|
withKakaotalk,
|
|
372
382
|
platform,
|
|
@@ -412,6 +422,15 @@ export async function runInit({
|
|
|
412
422
|
}
|
|
413
423
|
}
|
|
414
424
|
|
|
425
|
+
if (withTeams && runTeamsAuth !== undefined) {
|
|
426
|
+
emit({ step: 'teams-auth', phase: 'start' })
|
|
427
|
+
const result = await runTeamsAuth({ cwd })
|
|
428
|
+
emit({ step: 'teams-auth', phase: 'done', result })
|
|
429
|
+
if (!result.ok) {
|
|
430
|
+
throw new Error(`Teams authentication failed: ${result.reason}`)
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
|
|
415
434
|
if (withDiscordUser) {
|
|
416
435
|
emit({ step: 'discord-auth', phase: 'start' })
|
|
417
436
|
const runner = runDiscordAuth ?? defaultDiscordAuthRunner
|
|
@@ -482,6 +501,7 @@ export async function runInit({
|
|
|
482
501
|
if (wantsTelegram) configuredChannels.push('telegram-bot')
|
|
483
502
|
if (wantsWebex) configuredChannels.push('webex-bot')
|
|
484
503
|
if (withWebexUser) configuredChannels.push('webex')
|
|
504
|
+
if (withTeams) configuredChannels.push('teams')
|
|
485
505
|
if (withInstagram) configuredChannels.push('instagram')
|
|
486
506
|
if (withKakaotalk) configuredChannels.push('kakaotalk')
|
|
487
507
|
if (withGithub) configuredChannels.push('github')
|
|
@@ -653,6 +673,7 @@ export type ScaffoldOptions = {
|
|
|
653
673
|
withTelegram?: boolean
|
|
654
674
|
withWebex?: boolean
|
|
655
675
|
withWebexUser?: boolean
|
|
676
|
+
withTeams?: boolean
|
|
656
677
|
withInstagram?: boolean
|
|
657
678
|
withKakaotalk?: boolean
|
|
658
679
|
// Defaults to `process.platform`; controls the dev-mode typeclaw spec
|
|
@@ -692,6 +713,7 @@ export async function scaffold(root: string, options: ScaffoldOptions = {}): Pro
|
|
|
692
713
|
if (options.withTelegram) channels['telegram-bot'] = {}
|
|
693
714
|
if (options.withWebex) channels['webex-bot'] = {}
|
|
694
715
|
if (options.withWebexUser) channels.webex = {}
|
|
716
|
+
if (options.withTeams) channels.teams = {}
|
|
695
717
|
if (options.withInstagram) channels.instagram = {}
|
|
696
718
|
if (options.withKakaotalk) channels.kakaotalk = {}
|
|
697
719
|
if (Object.keys(channels).length > 0) config.channels = channels
|
|
@@ -1008,7 +1030,7 @@ export async function hasExistingOAuthCredentials(root: string, providerId: Know
|
|
|
1008
1030
|
// kakaotalk` anyway — better to re-auth now during init.
|
|
1009
1031
|
export async function hasExistingChannelSecrets(
|
|
1010
1032
|
root: string,
|
|
1011
|
-
channel: 'discord' | 'slack' | 'telegram' | 'webex' | 'instagram' | 'line' | 'kakaotalk' | 'github',
|
|
1033
|
+
channel: 'discord' | 'slack' | 'telegram' | 'webex' | 'teams' | 'instagram' | 'line' | 'kakaotalk' | 'github',
|
|
1012
1034
|
): Promise<boolean> {
|
|
1013
1035
|
const channels = new SecretsBackend(join(root, 'secrets.json')).tryReadChannelsSync()
|
|
1014
1036
|
if (channels === null) return false
|
|
@@ -1021,6 +1043,8 @@ export async function hasExistingChannelSecrets(
|
|
|
1021
1043
|
return hasSecretField(channels['telegram-bot'], 'token')
|
|
1022
1044
|
case 'webex':
|
|
1023
1045
|
return hasCurrentWebexAccount(channels.webex)
|
|
1046
|
+
case 'teams':
|
|
1047
|
+
return hasCurrentTeamsAccount(channels.teams)
|
|
1024
1048
|
case 'github':
|
|
1025
1049
|
// GitHub credentials alone are not enough to scaffold a working
|
|
1026
1050
|
// channel: typeclaw.json#channels.github also needs webhookUrl and
|
|
@@ -1105,6 +1129,33 @@ function hasCurrentWebexAccount(block: unknown): boolean {
|
|
|
1105
1129
|
return typeof token === 'string' && token.length > 0 && typeof email === 'string' && isObjectRecord(encryptedPassword)
|
|
1106
1130
|
}
|
|
1107
1131
|
|
|
1132
|
+
// A Teams block is only reusable when the current account can survive
|
|
1133
|
+
// unattended: the Skype access token lapses in ~60-90min, so silent renewal
|
|
1134
|
+
// needs the full AAD refresh trio (refresh token + client id + tenant id). An
|
|
1135
|
+
// access-token-only block (e.g. a hand-pasted token) would go stale with no way
|
|
1136
|
+
// to re-mint, so treat it as not-configured and let the wizard re-run the
|
|
1137
|
+
// device-code login rather than wiring a channel that dies within the hour.
|
|
1138
|
+
function hasCurrentTeamsAccount(block: unknown): boolean {
|
|
1139
|
+
if (!isObjectRecord(block)) return false
|
|
1140
|
+
const current = (block as { currentAccount?: unknown }).currentAccount
|
|
1141
|
+
if (typeof current !== 'string' || current.length === 0) return false
|
|
1142
|
+
const accounts = (block as { accounts?: unknown }).accounts
|
|
1143
|
+
if (!isObjectRecord(accounts)) return false
|
|
1144
|
+
const account = accounts[current]
|
|
1145
|
+
if (!isObjectRecord(account)) return false
|
|
1146
|
+
return (
|
|
1147
|
+
hasNonEmptyString(account, 'access_token') &&
|
|
1148
|
+
hasNonEmptyString(account, 'aad_refresh_token') &&
|
|
1149
|
+
hasNonEmptyString(account, 'aad_client_id') &&
|
|
1150
|
+
hasNonEmptyString(account, 'aad_tenant_id')
|
|
1151
|
+
)
|
|
1152
|
+
}
|
|
1153
|
+
|
|
1154
|
+
function hasNonEmptyString(record: Record<string, unknown>, key: string): boolean {
|
|
1155
|
+
const value = record[key]
|
|
1156
|
+
return typeof value === 'string' && value.length > 0
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1108
1159
|
function isObjectRecord(value: unknown): value is Record<string, unknown> {
|
|
1109
1160
|
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
1110
1161
|
}
|
|
@@ -1149,6 +1200,7 @@ export type ChannelKind =
|
|
|
1149
1200
|
| 'telegram-bot'
|
|
1150
1201
|
| 'webex'
|
|
1151
1202
|
| 'webex-bot'
|
|
1203
|
+
| 'teams'
|
|
1152
1204
|
| 'instagram'
|
|
1153
1205
|
| 'line'
|
|
1154
1206
|
| 'kakaotalk'
|
|
@@ -1166,6 +1218,7 @@ export const CHANNEL_KINDS: ReadonlyArray<ChannelKind> = [
|
|
|
1166
1218
|
'telegram-bot',
|
|
1167
1219
|
'webex',
|
|
1168
1220
|
'webex-bot',
|
|
1221
|
+
'teams',
|
|
1169
1222
|
'instagram',
|
|
1170
1223
|
'line',
|
|
1171
1224
|
'kakaotalk',
|
|
@@ -1194,6 +1247,8 @@ export type AddChannelStepEvent =
|
|
|
1194
1247
|
| { step: 'kakaotalk-auth'; phase: 'done'; result: KakaotalkAuthResult }
|
|
1195
1248
|
| { step: 'webex-auth'; phase: 'start' }
|
|
1196
1249
|
| { step: 'webex-auth'; phase: 'done'; result: WebexAuthResult }
|
|
1250
|
+
| { step: 'teams-auth'; phase: 'start' }
|
|
1251
|
+
| { step: 'teams-auth'; phase: 'done'; result: TeamsAuthResult }
|
|
1197
1252
|
| { step: 'discord-auth'; phase: 'start' }
|
|
1198
1253
|
| { step: 'discord-auth'; phase: 'done'; result: DiscordAuthResult }
|
|
1199
1254
|
| { step: 'slack-auth'; phase: 'start' }
|
|
@@ -1217,6 +1272,7 @@ export type AddChannelOptions = {
|
|
|
1217
1272
|
| { channel: 'telegram-bot'; telegramBotToken: string }
|
|
1218
1273
|
| { channel: 'webex-bot'; webexBotToken: string }
|
|
1219
1274
|
| { channel: 'webex'; runWebexAuth: WebexAuthRunner }
|
|
1275
|
+
| { channel: 'teams'; runTeamsAuth: TeamsAuthRunner }
|
|
1220
1276
|
| { channel: 'instagram'; runInstagramAuth: InstagramAuthRunner }
|
|
1221
1277
|
| { channel: 'line'; runLineAuth: LineAuthRunner }
|
|
1222
1278
|
| { channel: 'kakaotalk'; runKakaotalkAuth: KakaotalkAuthRunner }
|
|
@@ -1276,6 +1332,13 @@ export async function runAddChannel(options: AddChannelOptions): Promise<void> {
|
|
|
1276
1332
|
if (!result.ok) throw new Error(`Webex authentication failed: ${result.reason}`)
|
|
1277
1333
|
}
|
|
1278
1334
|
|
|
1335
|
+
if (options.channel === 'teams') {
|
|
1336
|
+
emit({ step: 'teams-auth', phase: 'start' })
|
|
1337
|
+
const result = await options.runTeamsAuth({ cwd: options.cwd })
|
|
1338
|
+
emit({ step: 'teams-auth', phase: 'done', result })
|
|
1339
|
+
if (!result.ok) throw new Error(`Teams authentication failed: ${result.reason}`)
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1279
1342
|
if (options.channel === 'discord') {
|
|
1280
1343
|
emit({ step: 'discord-auth', phase: 'start' })
|
|
1281
1344
|
const result = await options.runDiscordAuth({ cwd: options.cwd })
|
|
@@ -1371,6 +1434,10 @@ function channelSecretsFromOptions(options: AddChannelOptions): ChannelSecrets {
|
|
|
1371
1434
|
return { token: options.webexBotToken }
|
|
1372
1435
|
case 'webex':
|
|
1373
1436
|
return {}
|
|
1437
|
+
case 'teams':
|
|
1438
|
+
// Teams auth writes its structured account block directly to
|
|
1439
|
+
// secrets.json#channels.teams before config mutation.
|
|
1440
|
+
return {}
|
|
1374
1441
|
case 'instagram':
|
|
1375
1442
|
return {}
|
|
1376
1443
|
case 'line':
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { join } from 'node:path'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
loginWithDeviceCode as upstreamLoginWithDeviceCode,
|
|
5
|
+
TeamsCredentialManager,
|
|
6
|
+
type DeviceCodePrompt,
|
|
7
|
+
type DeviceLoginResult,
|
|
8
|
+
} from 'agent-messenger/teams'
|
|
9
|
+
|
|
10
|
+
import type { TeamsAccountRecord, TeamsAccountType } from '@/secrets/schema'
|
|
11
|
+
import { SecretsTeamsCredentialStore } from '@/secrets/teams-store'
|
|
12
|
+
|
|
13
|
+
export type TeamsBootstrapStatus = { ok: true } | { ok: false; reason: string }
|
|
14
|
+
|
|
15
|
+
export type LoginWithDeviceCodeFn = typeof upstreamLoginWithDeviceCode
|
|
16
|
+
|
|
17
|
+
export type TeamsDeviceCodeCallbacks = {
|
|
18
|
+
onCode: (prompt: DeviceCodePrompt) => void | Promise<void>
|
|
19
|
+
onPending?: () => void
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type TeamsLoginInput = {
|
|
23
|
+
agentDir: string
|
|
24
|
+
accountType: TeamsAccountType
|
|
25
|
+
callbacks: TeamsDeviceCodeCallbacks
|
|
26
|
+
loginWithDeviceCode?: LoginWithDeviceCodeFn
|
|
27
|
+
// The SDK persists the minted token in its own config dir; scope it to the
|
|
28
|
+
// agent folder so the login is self-contained and read-back is deterministic
|
|
29
|
+
// instead of leaking into the operator's global agent-messenger config.
|
|
30
|
+
credManager?: TeamsCredentialManager
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function teamsSecretsPath(agentDir: string): string {
|
|
34
|
+
return join(agentDir, 'secrets.json')
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export async function runTeamsBootstrap(input: TeamsLoginInput): Promise<TeamsBootstrapStatus> {
|
|
38
|
+
try {
|
|
39
|
+
const loginWithDeviceCode = input.loginWithDeviceCode ?? upstreamLoginWithDeviceCode
|
|
40
|
+
const credManager = input.credManager ?? new TeamsCredentialManager(teamsConfigDir(input.agentDir))
|
|
41
|
+
|
|
42
|
+
const result = await loginWithDeviceCode(
|
|
43
|
+
{
|
|
44
|
+
accountType: input.accountType,
|
|
45
|
+
onCode: input.callbacks.onCode,
|
|
46
|
+
...(input.callbacks.onPending !== undefined ? { onPending: input.callbacks.onPending } : {}),
|
|
47
|
+
},
|
|
48
|
+
credManager,
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
const record = await buildAccountRecord(result, credManager)
|
|
52
|
+
if (record === null) {
|
|
53
|
+
return { ok: false, reason: 'device-code login did not persist a usable Teams token' }
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const store = new SecretsTeamsCredentialStore({ mode: 'host', secretsPath: teamsSecretsPath(input.agentDir) })
|
|
57
|
+
await store.setAccount(record)
|
|
58
|
+
await store.setCurrentAccount(record.account_id)
|
|
59
|
+
|
|
60
|
+
return { ok: true }
|
|
61
|
+
} catch (err) {
|
|
62
|
+
return { ok: false, reason: err instanceof Error ? err.message : String(err) }
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// The SDK writes the minted token into its own credential manager keyed by
|
|
67
|
+
// account type; read it back and translate into typeclaw's TeamsAccountRecord
|
|
68
|
+
// shape for secrets.json. The AAD refresh trio is what lets the runtime adapter
|
|
69
|
+
// silently re-mint the ~60-90min skype token, so it must survive the hop.
|
|
70
|
+
async function buildAccountRecord(
|
|
71
|
+
result: DeviceLoginResult,
|
|
72
|
+
credManager: TeamsCredentialManager,
|
|
73
|
+
): Promise<TeamsAccountRecord | null> {
|
|
74
|
+
const config = await credManager.loadConfig()
|
|
75
|
+
const account = config?.accounts[result.accountType]
|
|
76
|
+
if (account === undefined || account.token === '') return null
|
|
77
|
+
|
|
78
|
+
const now = new Date().toISOString()
|
|
79
|
+
const accountId = accountIdFor(result)
|
|
80
|
+
return {
|
|
81
|
+
account_id: accountId,
|
|
82
|
+
access_token: account.token,
|
|
83
|
+
...(account.token_expires_at !== undefined ? { token_expires_at: account.token_expires_at } : {}),
|
|
84
|
+
account_type: result.accountType,
|
|
85
|
+
...(account.region !== undefined ? { region: account.region } : {}),
|
|
86
|
+
...(result.userName !== undefined ? { user_name: result.userName } : {}),
|
|
87
|
+
...(account.aad_refresh_token !== undefined ? { aad_refresh_token: account.aad_refresh_token } : {}),
|
|
88
|
+
...(account.aad_client_id !== undefined ? { aad_client_id: account.aad_client_id } : {}),
|
|
89
|
+
...(account.aad_tenant_id !== undefined ? { aad_tenant_id: account.aad_tenant_id } : {}),
|
|
90
|
+
created_at: now,
|
|
91
|
+
updated_at: now,
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// A stable per-account id for secrets.json. Teams has no cheap unique user id
|
|
96
|
+
// surfaced by the device-code result, so key on the display name when present
|
|
97
|
+
// and fall back to the account type, so a re-auth of the same account replaces
|
|
98
|
+
// its record rather than accumulating duplicates.
|
|
99
|
+
function accountIdFor(result: DeviceLoginResult): string {
|
|
100
|
+
const name = result.userName?.trim()
|
|
101
|
+
return name !== undefined && name !== '' ? name : result.accountType
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// The SDK caches the minted token in this dir; keep it under the already
|
|
105
|
+
// gitignored `.typeclaw/` local-scratch root so Teams tokens / AAD refresh
|
|
106
|
+
// tokens can never be staged into git by accident.
|
|
107
|
+
function teamsConfigDir(agentDir: string): string {
|
|
108
|
+
return join(agentDir, '.typeclaw', 'teams-auth')
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export type { DeviceCodePrompt, DeviceLoginResult }
|
package/src/inspect/label.ts
CHANGED
|
@@ -3,11 +3,15 @@ import { toRef } from '@/channels/adapters/webex-id-ref'
|
|
|
3
3
|
|
|
4
4
|
const ADAPTER_DISPLAY: Record<string, string> = {
|
|
5
5
|
'slack-bot': 'Slack',
|
|
6
|
+
slack: 'Slack',
|
|
6
7
|
'discord-bot': 'Discord',
|
|
8
|
+
discord: 'Discord',
|
|
7
9
|
github: 'GitHub',
|
|
8
10
|
'telegram-bot': 'Telegram',
|
|
9
11
|
webex: 'Webex',
|
|
10
12
|
'webex-bot': 'Webex',
|
|
13
|
+
teams: 'Teams',
|
|
14
|
+
instagram: 'Instagram',
|
|
11
15
|
line: 'LINE',
|
|
12
16
|
kakaotalk: 'KakaoTalk',
|
|
13
17
|
}
|
|
@@ -16,7 +16,17 @@
|
|
|
16
16
|
// error messages with typo suggestions; a single big regex would only ever
|
|
17
17
|
// say "didn't match".
|
|
18
18
|
|
|
19
|
-
export const PLATFORMS = [
|
|
19
|
+
export const PLATFORMS = [
|
|
20
|
+
'slack',
|
|
21
|
+
'discord',
|
|
22
|
+
'telegram',
|
|
23
|
+
'webex',
|
|
24
|
+
'teams',
|
|
25
|
+
'instagram',
|
|
26
|
+
'line',
|
|
27
|
+
'kakao',
|
|
28
|
+
'github',
|
|
29
|
+
] as const
|
|
20
30
|
export type Platform = (typeof PLATFORMS)[number]
|
|
21
31
|
|
|
22
32
|
const SUBAGENT_NAME = /^[a-z][a-z0-9-]*$/
|
|
@@ -27,7 +27,7 @@ export type PartialChannelOrigin = {
|
|
|
27
27
|
|
|
28
28
|
const ADAPTER_TO_PLATFORM: Record<
|
|
29
29
|
ChannelKey['adapter'],
|
|
30
|
-
'slack' | 'discord' | 'telegram' | 'webex' | 'kakao' | 'line' | 'github' | 'instagram'
|
|
30
|
+
'slack' | 'discord' | 'telegram' | 'webex' | 'teams' | 'kakao' | 'line' | 'github' | 'instagram'
|
|
31
31
|
> = {
|
|
32
32
|
slack: 'slack',
|
|
33
33
|
'slack-bot': 'slack',
|
|
@@ -38,6 +38,7 @@ const ADAPTER_TO_PLATFORM: Record<
|
|
|
38
38
|
'telegram-bot': 'telegram',
|
|
39
39
|
webex: 'webex',
|
|
40
40
|
'webex-bot': 'webex',
|
|
41
|
+
teams: 'teams',
|
|
41
42
|
line: 'line',
|
|
42
43
|
kakaotalk: 'kakao',
|
|
43
44
|
}
|
package/src/run/index.ts
CHANGED
|
@@ -34,6 +34,7 @@ import {
|
|
|
34
34
|
createPrVerdictActivityBridge,
|
|
35
35
|
createSubagentCompletionBridge,
|
|
36
36
|
setReviewObserver,
|
|
37
|
+
setReviewOutputObserver,
|
|
37
38
|
type ChannelManager,
|
|
38
39
|
type PrVerdictActivityBridge,
|
|
39
40
|
type SubagentCompletionBridge,
|
|
@@ -51,6 +52,7 @@ import {
|
|
|
51
52
|
createScheduler,
|
|
52
53
|
type LoadCronResult,
|
|
53
54
|
loadCron as loadCronDefault,
|
|
55
|
+
type ParseCronMode,
|
|
54
56
|
type Scheduler,
|
|
55
57
|
} from '@/cron'
|
|
56
58
|
import { CLI_VERSION } from '@/init/cli-version'
|
|
@@ -90,7 +92,10 @@ type BunServer = ReturnType<Server['start']>
|
|
|
90
92
|
|
|
91
93
|
export type TuiFactory = (options: TuiOptions) => { run: () => Promise<unknown> }
|
|
92
94
|
|
|
93
|
-
export type LoadCronFn = (
|
|
95
|
+
export type LoadCronFn = (
|
|
96
|
+
agentDir: string,
|
|
97
|
+
options?: { subagents?: SubagentRegistry; mode?: ParseCronMode },
|
|
98
|
+
) => Promise<LoadCronResult>
|
|
94
99
|
export type SchedulerFactory = (options: {
|
|
95
100
|
cwd: string
|
|
96
101
|
file: CronFile
|
|
@@ -783,6 +788,15 @@ async function startAgentRuntime(
|
|
|
783
788
|
})
|
|
784
789
|
registerBootCleanup(() => setReviewObserver(null))
|
|
785
790
|
|
|
791
|
+
// A landed review of ANY state (incl. COMMENT) marks the recording session so its
|
|
792
|
+
// empty-turn fallback is suppressed: the review IS the turn's output, but it goes
|
|
793
|
+
// through the GitHub API, not the channel send path. In-process router call — no
|
|
794
|
+
// stream fan-out, since this is the recording session's own bookkeeping.
|
|
795
|
+
setReviewOutputObserver((output) => {
|
|
796
|
+
channelManager.router.noteGithubReviewOutput(output)
|
|
797
|
+
})
|
|
798
|
+
registerBootCleanup(() => setReviewOutputObserver(null))
|
|
799
|
+
|
|
786
800
|
// Registered before channels so its cache clear lands before any channel
|
|
787
801
|
// session teardown observes it. secrets.json provider credentials are not
|
|
788
802
|
// part of the typeclaw.json config diff, so a rotated key takes effect on
|
|
@@ -1123,7 +1137,10 @@ function reloadRolesFromDisk(cwd: string): ReturnType<typeof getConfig>['roles']
|
|
|
1123
1137
|
return getConfig().roles
|
|
1124
1138
|
}
|
|
1125
1139
|
|
|
1126
|
-
|
|
1140
|
+
// Exported for the resilience regression test in `index.test.ts` (survives a
|
|
1141
|
+
// file-level cron.json failure by still scheduling plugin jobs). Not re-exported
|
|
1142
|
+
// from the package entry point, so this stays module-internal in practice.
|
|
1143
|
+
export async function startScheduler({
|
|
1127
1144
|
cwd,
|
|
1128
1145
|
loadCron,
|
|
1129
1146
|
createSchedulerFor,
|
|
@@ -1145,17 +1162,27 @@ async function startScheduler({
|
|
|
1145
1162
|
let result: LoadCronResult
|
|
1146
1163
|
const subagents = getSubagents?.()
|
|
1147
1164
|
try {
|
|
1148
|
-
result = await loadCron(cwd, subagents !== undefined ? { subagents } : {})
|
|
1165
|
+
result = await loadCron(cwd, { mode: 'boot', ...(subagents !== undefined ? { subagents } : {}) })
|
|
1149
1166
|
} catch (err) {
|
|
1150
|
-
|
|
1151
|
-
return null
|
|
1167
|
+
result = { ok: false, reason: err instanceof Error ? err.message : String(err) }
|
|
1152
1168
|
}
|
|
1169
|
+
|
|
1170
|
+
// A file-level cron.json failure (malformed JSON or top-level schema
|
|
1171
|
+
// violation) must not take the whole scheduler down: plugin-registered jobs
|
|
1172
|
+
// (e.g. memory dreaming) live outside cron.json and have to keep running.
|
|
1173
|
+
// Boot with an empty user file so the factory still merges internal jobs;
|
|
1174
|
+
// give up only when there is nothing to schedule at all.
|
|
1153
1175
|
if (!result.ok) {
|
|
1154
1176
|
console.error(`[cron] failed to load cron.json: ${result.reason}`)
|
|
1155
|
-
return null
|
|
1177
|
+
if (!hasInternalJobs) return null
|
|
1178
|
+
} else {
|
|
1179
|
+
for (const warning of result.warnings ?? []) {
|
|
1180
|
+
console.error(`[cron] skipped invalid job at boot: ${warning.reason}`)
|
|
1181
|
+
}
|
|
1156
1182
|
}
|
|
1157
|
-
|
|
1158
|
-
|
|
1183
|
+
|
|
1184
|
+
const file: CronFile = result.ok ? (result.file ?? { jobs: [] }) : { jobs: [] }
|
|
1185
|
+
if (result.ok && !result.file && !hasInternalJobs) return null
|
|
1159
1186
|
|
|
1160
1187
|
const onFire = (job: CronJob) => {
|
|
1161
1188
|
stream.publish({ target: { kind: 'cron', jobId: job.id }, payload: job })
|
|
@@ -3,6 +3,24 @@ export type LlmFetchObserverLogger = {
|
|
|
3
3
|
warn: (msg: string) => void
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
+
// Per-request timeout override, attached to a RequestInit under a Symbol key so
|
|
7
|
+
// it travels with a single fetch() without leaking a wire header to the provider
|
|
8
|
+
// and without widening the endpoint matcher. Used where one call on a SHARED
|
|
9
|
+
// endpoint URL needs a different deadline than its siblings — e.g. GLM vision and
|
|
10
|
+
// GLM text hit the identical /chat/completions URL, so a URL/header match cannot
|
|
11
|
+
// tell them apart, but the vision caller owns its fetch and can tag it directly.
|
|
12
|
+
export const LLM_FETCH_OBSERVER_TIMEOUTS = Symbol.for('typeclaw.llmFetchObserverTimeouts')
|
|
13
|
+
|
|
14
|
+
export type LlmFetchObserverTimeoutOverrides = {
|
|
15
|
+
ttfbMs?: number
|
|
16
|
+
idleMs?: number
|
|
17
|
+
overallMs?: number
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export type LlmFetchObservedRequestInit = RequestInit & {
|
|
21
|
+
[LLM_FETCH_OBSERVER_TIMEOUTS]?: LlmFetchObserverTimeoutOverrides
|
|
22
|
+
}
|
|
23
|
+
|
|
6
24
|
// A provider endpoint the observer should instrument. `match` is host-agnostic
|
|
7
25
|
// on purpose: base URLs are user-configured (ANTHROPIC_BASE_URL, OPENAI_BASE_URL,
|
|
8
26
|
// OpenRouter/LiteLLM/Fireworks/arbitrary proxies), so a host allowlist would be
|
|
@@ -442,12 +460,15 @@ export function installLlmFetchObserver(opts: LlmFetchObserverOptions = {}): ()
|
|
|
442
460
|
// "force this across all endpoints" (the test seam and any global override),
|
|
443
461
|
// so it must beat a per-endpoint tuned value. The master `timeoutsEnabled=off`
|
|
444
462
|
// switch forces every timer to 0 regardless.
|
|
445
|
-
const resolveTimeouts = (
|
|
463
|
+
const resolveTimeouts = (
|
|
464
|
+
endpoint: LlmFetchEndpoint,
|
|
465
|
+
perRequest: LlmFetchObserverTimeoutOverrides | undefined,
|
|
466
|
+
): ResolvedTimeouts => {
|
|
446
467
|
if (!timeoutsEnabled) return { ttfbMs: 0, idleMs: 0, overallMs: 0 }
|
|
447
468
|
return {
|
|
448
|
-
ttfbMs: opts.ttfbMs ?? endpoint.ttfbMs ?? envDefaults.ttfbMs,
|
|
449
|
-
idleMs: opts.idleMs ?? endpoint.idleMs ?? envDefaults.idleMs,
|
|
450
|
-
overallMs: opts.overallMs ?? endpoint.overallMs ?? envDefaults.overallMs,
|
|
469
|
+
ttfbMs: opts.ttfbMs ?? perRequest?.ttfbMs ?? endpoint.ttfbMs ?? envDefaults.ttfbMs,
|
|
470
|
+
idleMs: opts.idleMs ?? perRequest?.idleMs ?? endpoint.idleMs ?? envDefaults.idleMs,
|
|
471
|
+
overallMs: opts.overallMs ?? perRequest?.overallMs ?? endpoint.overallMs ?? envDefaults.overallMs,
|
|
451
472
|
}
|
|
452
473
|
}
|
|
453
474
|
|
|
@@ -459,7 +480,8 @@ export function installLlmFetchObserver(opts: LlmFetchObserverOptions = {}): ()
|
|
|
459
480
|
if (endpoint === null) {
|
|
460
481
|
return originalFetch(input, init)
|
|
461
482
|
}
|
|
462
|
-
const
|
|
483
|
+
const perRequest = (init as LlmFetchObservedRequestInit | undefined)?.[LLM_FETCH_OBSERVER_TIMEOUTS]
|
|
484
|
+
const timeouts = resolveTimeouts(endpoint, perRequest)
|
|
463
485
|
const provider = endpoint.label
|
|
464
486
|
const start = now()
|
|
465
487
|
|
package/src/sandbox/build.ts
CHANGED
|
@@ -171,6 +171,7 @@ function buildArgv(command: string, policy: SandboxPolicy): string[] {
|
|
|
171
171
|
appendMasks(argv, policy)
|
|
172
172
|
appendWritable(argv, policy)
|
|
173
173
|
appendProtected(argv, policy)
|
|
174
|
+
appendBlockedCreation(argv, policy)
|
|
174
175
|
appendSymlinks(argv, policy)
|
|
175
176
|
|
|
176
177
|
if (policy.cwd !== undefined) {
|
|
@@ -217,6 +218,17 @@ function appendProtected(argv: string[], policy: SandboxPolicy): void {
|
|
|
217
218
|
}
|
|
218
219
|
}
|
|
219
220
|
|
|
221
|
+
// Occupies each path with an empty read-only object so a writable-root install
|
|
222
|
+
// script cannot CREATE a real file there. /dev/null always exists (bwrap mounts
|
|
223
|
+
// --dev), so unlike --ro-bind-data this needs no manufactured placeholder on the
|
|
224
|
+
// host FS. Renders after appendProtected: both are RO carve-outs of the RW root,
|
|
225
|
+
// last-op-wins.
|
|
226
|
+
function appendBlockedCreation(argv: string[], policy: SandboxPolicy): void {
|
|
227
|
+
for (const file of policy.blockedCreation?.files ?? []) {
|
|
228
|
+
argv.push('--ro-bind', '/dev/null', file)
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
220
232
|
// Rendered after every bind (incl. the /tmp session bind in policy.mounts) so
|
|
221
233
|
// last-op-wins keeps the symlink: a `/tmp/.foo` dest emitted before the /tmp
|
|
222
234
|
// bind would be erased by it. `--dir` ensures the symlink's parent exists inside
|
package/src/sandbox/policy.ts
CHANGED
|
@@ -112,6 +112,18 @@ export type SandboxWritableRootPolicy = {
|
|
|
112
112
|
dir: string
|
|
113
113
|
}
|
|
114
114
|
|
|
115
|
+
// Paths whose CREATION must be blocked under a writable root, rendered as
|
|
116
|
+
// `--ro-bind /dev/null <path>`. Used by the package-install path for the
|
|
117
|
+
// semantically-guarded managed files (cron.json / typeclaw.json) when they are
|
|
118
|
+
// ABSENT: the RW root would otherwise let a postinstall lifecycle script create
|
|
119
|
+
// them, bypassing the write/edit-tool guards. Binding /dev/null occupies the
|
|
120
|
+
// path with an empty read-only object (blocking creation) WITHOUT manufacturing
|
|
121
|
+
// a real invalid file on the host FS. Renders after writableRoot, with the
|
|
122
|
+
// protected binds, so last-op-wins keeps the path occupied.
|
|
123
|
+
export type SandboxBlockedCreationPolicy = {
|
|
124
|
+
files?: string[]
|
|
125
|
+
}
|
|
126
|
+
|
|
115
127
|
export type SandboxPolicy = {
|
|
116
128
|
bwrapPath?: string
|
|
117
129
|
cwd?: string
|
|
@@ -128,6 +140,7 @@ export type SandboxPolicy = {
|
|
|
128
140
|
masks?: SandboxMaskPolicy
|
|
129
141
|
writable?: SandboxWritablePolicy
|
|
130
142
|
protected?: SandboxProtectedPolicy
|
|
143
|
+
blockedCreation?: SandboxBlockedCreationPolicy
|
|
131
144
|
symlinks?: SandboxSymlinkOp[]
|
|
132
145
|
network?: SandboxNetwork
|
|
133
146
|
env?: SandboxEnvPolicy
|