typeclaw 0.43.0 → 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 +23 -4
- 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/system-prompt.ts +36 -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/discord-bot.ts +76 -3
- package/src/channels/adapters/discord.ts +15 -2
- 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 +63 -2
- package/src/channels/router.ts +664 -112
- package/src/channels/schema.ts +33 -0
- package/src/channels/types.ts +8 -5
- package/src/cli/channel.ts +131 -16
- 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/cron/index.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { join } from 'node:path'
|
|
|
4
4
|
|
|
5
5
|
import type { SubagentRegistry } from '@/agent/subagents'
|
|
6
6
|
|
|
7
|
-
import { type CronFile, parseCronFile } from './schema'
|
|
7
|
+
import { type CronFile, type CronParseWarning, type ParseCronMode, parseCronFile } from './schema'
|
|
8
8
|
|
|
9
9
|
export { type CountStore, createCountStore } from './count-state'
|
|
10
10
|
export { createCronReloadable } from './reloadable'
|
|
@@ -16,20 +16,29 @@ export {
|
|
|
16
16
|
cronJobSchema,
|
|
17
17
|
type CronFile,
|
|
18
18
|
type CronJob,
|
|
19
|
+
type CronParseWarning,
|
|
19
20
|
type ExecJob,
|
|
20
21
|
type HandlerJob,
|
|
21
22
|
parseCronJson,
|
|
23
|
+
type ParseCronMode,
|
|
22
24
|
type ParseCronResult,
|
|
23
25
|
type ParsedCronJob,
|
|
24
26
|
type PromptJob,
|
|
27
|
+
validateCronEdit,
|
|
25
28
|
} from './schema'
|
|
26
29
|
|
|
27
30
|
const CRON_FILE = 'cron.json'
|
|
28
31
|
|
|
29
|
-
export type LoadCronResult =
|
|
32
|
+
export type LoadCronResult =
|
|
33
|
+
| { ok: true; file: CronFile | null; warnings?: CronParseWarning[] }
|
|
34
|
+
| { ok: false; reason: string }
|
|
30
35
|
|
|
31
36
|
export type LoadCronOptions = {
|
|
32
37
|
subagents?: SubagentRegistry
|
|
38
|
+
// Defaults to strict `load` so inspection/security callers surface bad jobs
|
|
39
|
+
// as a whole-file error. Only the scheduler boot path passes `boot` to
|
|
40
|
+
// isolate individual bad jobs and keep the rest runnable.
|
|
41
|
+
mode?: ParseCronMode
|
|
33
42
|
}
|
|
34
43
|
|
|
35
44
|
export async function loadCron(agentDir: string, options: LoadCronOptions = {}): Promise<LoadCronResult> {
|
|
@@ -50,10 +59,13 @@ export async function loadCron(agentDir: string, options: LoadCronOptions = {}):
|
|
|
50
59
|
return { ok: false, reason: `cron.json is not valid JSON: ${errorMessage(err)}` }
|
|
51
60
|
}
|
|
52
61
|
|
|
53
|
-
const result = parseCronFile(parsed,
|
|
62
|
+
const result = parseCronFile(parsed, {
|
|
63
|
+
mode: options.mode ?? 'load',
|
|
64
|
+
...(options.subagents !== undefined ? { subagents: options.subagents } : {}),
|
|
65
|
+
})
|
|
54
66
|
if (!result.ok) return { ok: false, reason: result.reason }
|
|
55
67
|
|
|
56
|
-
return { ok: true, file: result.file }
|
|
68
|
+
return { ok: true, file: result.file, ...(result.warnings ? { warnings: result.warnings } : {}) }
|
|
57
69
|
}
|
|
58
70
|
|
|
59
71
|
function errorMessage(err: unknown): string {
|
package/src/cron/reloadable.ts
CHANGED
|
@@ -36,11 +36,34 @@ async function doReload({
|
|
|
36
36
|
getSubagents,
|
|
37
37
|
}: CreateCronReloadableOptions): Promise<ReloadResult> {
|
|
38
38
|
const subagents = getSubagents?.()
|
|
39
|
-
const loaded = await loadCron(cwd, subagents !== undefined ? { subagents } : {})
|
|
39
|
+
const loaded = await loadCron(cwd, { mode: 'boot', ...(subagents !== undefined ? { subagents } : {}) })
|
|
40
40
|
if (!loaded.ok) {
|
|
41
41
|
return { scope: 'cron', ok: false, reason: loaded.reason }
|
|
42
42
|
}
|
|
43
|
+
const warnings = loaded.warnings ?? []
|
|
44
|
+
for (const warning of warnings) {
|
|
45
|
+
console.error(`[cron] skipped invalid job on reload: ${warning.reason}`)
|
|
46
|
+
}
|
|
43
47
|
const userJobs = loaded.file?.jobs ?? []
|
|
48
|
+
|
|
49
|
+
// Wipe-guard: refuse a reload that would drop every user job *because they
|
|
50
|
+
// failed to parse* (not because the file was intentionally emptied) while a
|
|
51
|
+
// schedule is live, so a fat-fingered edit can't silently wipe running crons.
|
|
52
|
+
// A valid empty file has no warnings and passes through as intentional
|
|
53
|
+
// deletion. The live user-job baseline comes from the scheduler (single
|
|
54
|
+
// source of truth) minus the internal/plugin jobs, which are always present
|
|
55
|
+
// and must not count as "user jobs exist".
|
|
56
|
+
const internalIds = new Set((internalJobs?.() ?? []).map((job) => job.id))
|
|
57
|
+
const liveUserJobCount = scheduler.currentJobs().filter((job) => !internalIds.has(job.id)).length
|
|
58
|
+
if (warnings.length > 0 && userJobs.length === 0 && liveUserJobCount > 0) {
|
|
59
|
+
const reason = warnings.map((w) => w.reason).join('; ')
|
|
60
|
+
return {
|
|
61
|
+
scope: 'cron',
|
|
62
|
+
ok: false,
|
|
63
|
+
reason: `every configured user cron job is invalid; live schedule preserved: ${reason}`,
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
44
67
|
const nextJobs: CronJob[] = [...userJobs, ...(internalJobs?.() ?? [])]
|
|
45
68
|
|
|
46
69
|
let diff: JobDiff
|
|
@@ -51,12 +74,7 @@ async function doReload({
|
|
|
51
74
|
return { scope: 'cron', ok: false, reason: `apply failed (schedule unchanged): ${message}` }
|
|
52
75
|
}
|
|
53
76
|
|
|
54
|
-
return {
|
|
55
|
-
scope: 'cron',
|
|
56
|
-
ok: true,
|
|
57
|
-
summary: formatSummary(diff, nextJobs.length),
|
|
58
|
-
details: diff,
|
|
59
|
-
}
|
|
77
|
+
return { scope: 'cron', ok: true, summary: formatSummary(diff, nextJobs.length), details: diff }
|
|
60
78
|
}
|
|
61
79
|
|
|
62
80
|
function formatSummary(diff: JobDiff, total: number): string {
|
package/src/cron/scheduler.ts
CHANGED
|
@@ -43,6 +43,7 @@ export type Scheduler = {
|
|
|
43
43
|
start: () => void
|
|
44
44
|
stop: () => void
|
|
45
45
|
replaceJobs: (jobs: CronJob[]) => JobDiff
|
|
46
|
+
currentJobs: () => readonly CronJob[]
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
const realClock: SchedulerClock = {
|
|
@@ -188,6 +189,9 @@ export function createScheduler({
|
|
|
188
189
|
|
|
189
190
|
return result
|
|
190
191
|
},
|
|
192
|
+
currentJobs() {
|
|
193
|
+
return [...registry.values()]
|
|
194
|
+
},
|
|
191
195
|
}
|
|
192
196
|
}
|
|
193
197
|
|
package/src/cron/schema.ts
CHANGED
|
@@ -66,15 +66,28 @@ export type HandlerJob = z.infer<typeof baseJob> & {
|
|
|
66
66
|
export type CronJob = ParsedCronJob | HandlerJob
|
|
67
67
|
export type CronFile = z.infer<typeof cronFileSchema>
|
|
68
68
|
|
|
69
|
-
export type
|
|
69
|
+
export type CronParseWarning = { jobId?: string; index: number; reason: string }
|
|
70
70
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
//
|
|
76
|
-
//
|
|
77
|
-
|
|
71
|
+
export type ParseCronResult =
|
|
72
|
+
| { ok: true; file: CronFile; warnings?: CronParseWarning[] }
|
|
73
|
+
| { ok: false; reason: string }
|
|
74
|
+
|
|
75
|
+
// `edit` is the strict authoring path for an agent writing/editing cron.json: a
|
|
76
|
+
// past enabled `at`/`until` is rejected so a job scheduled in the past surfaces
|
|
77
|
+
// as an error instead of silently becoming a never-firing no-op, and any single
|
|
78
|
+
// bad job fails the whole file so the author sees it.
|
|
79
|
+
//
|
|
80
|
+
// `load` is the strict programmatic/security path (cron-promotion inspection,
|
|
81
|
+
// reload validation): it tolerates fired past `at`/`until` tombstones but still
|
|
82
|
+
// fails the whole file on any structurally bad job, so a security policy never
|
|
83
|
+
// reasons over a silently-filtered subset.
|
|
84
|
+
//
|
|
85
|
+
// `boot` is the runtime-survivability path used only by the scheduler on
|
|
86
|
+
// container boot/reload: it isolates bad individual jobs (skips them, emits a
|
|
87
|
+
// warning) and keeps the valid ones, so one malformed job can never brick every
|
|
88
|
+
// cron — including the plugin-registered dreaming job that isn't even in the
|
|
89
|
+
// file. It shares `load`'s tolerance for expired `at`/`until`.
|
|
90
|
+
export type ParseCronMode = 'edit' | 'load' | 'boot'
|
|
78
91
|
|
|
79
92
|
export type ParseCronOptions = {
|
|
80
93
|
// When provided, prompt jobs with a `subagent` field are validated against
|
|
@@ -106,6 +119,81 @@ export function parseCronJson(raw: string, options: ParseCronJsonOptions = {}):
|
|
|
106
119
|
})
|
|
107
120
|
}
|
|
108
121
|
|
|
122
|
+
// Authoring-delta validation for a cron.json edit. Strict `edit` mode fails the
|
|
123
|
+
// whole file on any enabled job with a past `at`/`until`, which lets a single
|
|
124
|
+
// stale pre-existing job (an expired `until` from weeks ago) brick EVERY edit —
|
|
125
|
+
// including the edit that would remove it, or an edit to a completely unrelated
|
|
126
|
+
// job. That is the trap: expired history holds the file hostage.
|
|
127
|
+
//
|
|
128
|
+
// This validator parses the proposed content in tolerant `load` mode (so it
|
|
129
|
+
// still catches structural errors and duplicate ids), then applies the strict
|
|
130
|
+
// `edit` timing check ONLY to jobs whose timing is newly-authored — a job that
|
|
131
|
+
// is new, or whose timing fields changed versus the on-disk baseline. A job
|
|
132
|
+
// carried over unchanged keeps its stale boundary tolerated, so removing it or
|
|
133
|
+
// editing a sibling is never blocked. Adding a new past job, or re-timing an
|
|
134
|
+
// existing one into the past, is still rejected exactly as before.
|
|
135
|
+
//
|
|
136
|
+
// `existingRaw` is the current on-disk cron.json (undefined on first-init). If
|
|
137
|
+
// it is missing or unparseable the baseline is empty, so every proposed job is
|
|
138
|
+
// treated as new and strict-checked — the safe direction (fail closed).
|
|
139
|
+
export function validateCronEdit(
|
|
140
|
+
proposedRaw: string,
|
|
141
|
+
existingRaw: string | undefined,
|
|
142
|
+
options: ParseCronOptions = {},
|
|
143
|
+
): ParseCronResult {
|
|
144
|
+
const now = options.now ?? Date.now()
|
|
145
|
+
const proposed = parseCronJson(proposedRaw, { ...options, mode: 'load' })
|
|
146
|
+
if (!proposed.ok) return proposed
|
|
147
|
+
|
|
148
|
+
const baselineTiming = existingRaw !== undefined ? timingSignaturesByJobId(existingRaw) : new Map<string, string>()
|
|
149
|
+
|
|
150
|
+
for (const job of proposed.file.jobs) {
|
|
151
|
+
const prior = baselineTiming.get(job.id)
|
|
152
|
+
const timingUnchanged = prior !== undefined && prior === timingSignature(job)
|
|
153
|
+
if (timingUnchanged) continue
|
|
154
|
+
const timingError = validateTiming(job, now, 'edit')
|
|
155
|
+
if (timingError !== null) return { ok: false, reason: `job ${job.id}: ${timingError}` }
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return proposed
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// The timing fields whose change re-arms the strict past-boundary check. A job
|
|
162
|
+
// is exempt from the stale-boundary rejection only when ALL of these match the
|
|
163
|
+
// baseline; touching any of them (including flipping `enabled` back on) counts
|
|
164
|
+
// as re-authoring the schedule and is strict-checked afresh.
|
|
165
|
+
function timingSignature(job: {
|
|
166
|
+
schedule?: string | undefined
|
|
167
|
+
at?: string | undefined
|
|
168
|
+
until?: string | undefined
|
|
169
|
+
count?: number | undefined
|
|
170
|
+
timezone?: string | undefined
|
|
171
|
+
enabled: boolean
|
|
172
|
+
}): string {
|
|
173
|
+
return JSON.stringify([
|
|
174
|
+
job.schedule ?? null,
|
|
175
|
+
job.at ?? null,
|
|
176
|
+
job.until ?? null,
|
|
177
|
+
job.count ?? null,
|
|
178
|
+
job.timezone ?? null,
|
|
179
|
+
job.enabled,
|
|
180
|
+
])
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function timingSignaturesByJobId(raw: string): Map<string, string> {
|
|
184
|
+
const signatures = new Map<string, string>()
|
|
185
|
+
let json: unknown
|
|
186
|
+
try {
|
|
187
|
+
json = JSON.parse(raw)
|
|
188
|
+
} catch {
|
|
189
|
+
return signatures
|
|
190
|
+
}
|
|
191
|
+
const parsed = cronFileSchema.safeParse(json)
|
|
192
|
+
if (!parsed.success) return signatures
|
|
193
|
+
for (const job of parsed.data.jobs) signatures.set(job.id, timingSignature(job))
|
|
194
|
+
return signatures
|
|
195
|
+
}
|
|
196
|
+
|
|
109
197
|
export function parseCronFile(raw: unknown, options: ParseCronOptions = {}): ParseCronResult {
|
|
110
198
|
const parsed = cronFileSchema.safeParse(raw)
|
|
111
199
|
if (!parsed.success) {
|
|
@@ -113,40 +201,56 @@ export function parseCronFile(raw: unknown, options: ParseCronOptions = {}): Par
|
|
|
113
201
|
}
|
|
114
202
|
|
|
115
203
|
const file = parsed.data
|
|
204
|
+
const mode = options.mode ?? 'load'
|
|
205
|
+
const now = options.now ?? Date.now()
|
|
206
|
+
|
|
207
|
+
const validJobs: ParsedCronJob[] = []
|
|
208
|
+
const warnings: CronParseWarning[] = []
|
|
116
209
|
const seen = new Set<string>()
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
210
|
+
|
|
211
|
+
for (const [index, job] of file.jobs.entries()) {
|
|
212
|
+
const duplicate = seen.has(job.id)
|
|
213
|
+
const reason = duplicate
|
|
214
|
+
? `duplicate job id: ${job.id}`
|
|
215
|
+
: validateJob(job, { now, mode, subagents: options.subagents })
|
|
216
|
+
|
|
217
|
+
if (reason !== null) {
|
|
218
|
+
const scoped = duplicate ? reason : `job ${job.id}: ${reason}`
|
|
219
|
+
if (mode !== 'boot') return { ok: false, reason: scoped }
|
|
220
|
+
warnings.push({ jobId: job.id, index, reason: scoped })
|
|
221
|
+
continue
|
|
120
222
|
}
|
|
223
|
+
|
|
121
224
|
seen.add(job.id)
|
|
225
|
+
validJobs.push(job)
|
|
226
|
+
}
|
|
122
227
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
228
|
+
if (mode !== 'boot') return { ok: true, file }
|
|
229
|
+
return { ok: true, file: { ...file, jobs: validJobs }, ...(warnings.length > 0 ? { warnings } : {}) }
|
|
230
|
+
}
|
|
127
231
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
232
|
+
function validateJob(
|
|
233
|
+
job: ParsedCronJob,
|
|
234
|
+
{ now, mode, subagents }: { now: number; mode: ParseCronMode; subagents?: SubagentRegistry },
|
|
235
|
+
): string | null {
|
|
236
|
+
const timingError = validateTiming(job, now, mode)
|
|
237
|
+
if (timingError !== null) return timingError
|
|
134
238
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
239
|
+
if (job.scheduledByRole === undefined) {
|
|
240
|
+
return `missing 'scheduledByRole'. Add "scheduledByRole": "owner" if you authored this entry manually.`
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
if (job.kind === 'prompt' && job.subagent !== undefined && subagents !== undefined) {
|
|
244
|
+
const subagent = subagents[job.subagent]
|
|
245
|
+
if (!subagent) return `unknown subagent "${job.subagent}"`
|
|
246
|
+
try {
|
|
247
|
+
validateSubagentPayload(job.subagent, subagent, job.payload)
|
|
248
|
+
} catch (err) {
|
|
249
|
+
return err instanceof Error ? err.message : String(err)
|
|
146
250
|
}
|
|
147
251
|
}
|
|
148
252
|
|
|
149
|
-
return
|
|
253
|
+
return null
|
|
150
254
|
}
|
|
151
255
|
|
|
152
256
|
type TimingJob = {
|
|
@@ -181,7 +285,11 @@ function validateTiming(job: TimingJob, now: number = Date.now(), mode: ParseCro
|
|
|
181
285
|
if (job.until !== undefined) {
|
|
182
286
|
until = parseInstant(job.until)
|
|
183
287
|
if (until === null) return `invalid "until": "${job.until}" is not an ISO datetime with an explicit zone/offset`
|
|
184
|
-
|
|
288
|
+
// Reject an expired boundary only on `edit`; `load`/`boot` tolerate an
|
|
289
|
+
// already-past `until` (the recurring counterpart of a fired one-shot `at`)
|
|
290
|
+
// so an expired job goes inert instead of bricking the whole file on reload.
|
|
291
|
+
// See ParseCronMode for the full rationale.
|
|
292
|
+
if (mode === 'edit' && job.enabled && until <= now) return `"until" is in the past: "${job.until}"`
|
|
185
293
|
}
|
|
186
294
|
|
|
187
295
|
let firstFire: number
|
|
@@ -199,7 +307,7 @@ function validateTiming(job: TimingJob, now: number = Date.now(), mode: ParseCro
|
|
|
199
307
|
return `invalid schedule "${job.schedule}": ${message}`
|
|
200
308
|
}
|
|
201
309
|
|
|
202
|
-
if (job.enabled && until !== null && firstFire > until) {
|
|
310
|
+
if (mode === 'edit' && job.enabled && until !== null && firstFire > until) {
|
|
203
311
|
return `schedule has no occurrence at or before "until" ("${job.until}")`
|
|
204
312
|
}
|
|
205
313
|
|
|
@@ -32,6 +32,7 @@ export function buildChannelChecks(): DoctorCheck[] {
|
|
|
32
32
|
discordUserCredentials(),
|
|
33
33
|
slackUserCredentials(),
|
|
34
34
|
webexUserCredentials(),
|
|
35
|
+
teamsCredentials(),
|
|
35
36
|
instagramCredentials(),
|
|
36
37
|
lineCredentials(),
|
|
37
38
|
kakaotalkCredentials(),
|
|
@@ -158,6 +159,32 @@ function webexUserCredentials(): DoctorCheck {
|
|
|
158
159
|
}
|
|
159
160
|
}
|
|
160
161
|
|
|
162
|
+
function teamsCredentials(): DoctorCheck {
|
|
163
|
+
return {
|
|
164
|
+
name: 'channel.teams.credentials',
|
|
165
|
+
category: 'channels',
|
|
166
|
+
description: 'teams adapter has a current account with an access token in secrets.json',
|
|
167
|
+
applies: (ctx) => ctx.hasAgentFolder,
|
|
168
|
+
async run(ctx) {
|
|
169
|
+
const channels = readDeclaredChannels(ctx)
|
|
170
|
+
if (channels === null) return configInvalidResult()
|
|
171
|
+
if (!isAdapterActive(channels, 'teams')) {
|
|
172
|
+
return { status: 'skipped', message: 'teams not configured' }
|
|
173
|
+
}
|
|
174
|
+
const block = readChannelsSecrets(ctx)?.teams
|
|
175
|
+
if (!hasCurrentAccountTokenField(block, 'access_token')) {
|
|
176
|
+
return {
|
|
177
|
+
status: 'warning',
|
|
178
|
+
message: 'teams has no current account access_token in secrets.json',
|
|
179
|
+
details: ['Adapter will start but fail authentication and stay disconnected.'],
|
|
180
|
+
fix: { description: 'Populate secrets.json#channels.teams manually with an access token to authenticate.' },
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return { status: 'ok', message: 'teams has a current account access_token' }
|
|
184
|
+
},
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
161
188
|
function instagramCredentials(): DoctorCheck {
|
|
162
189
|
return {
|
|
163
190
|
name: 'channel.instagram.credentials',
|
package/src/hostd/daemon.ts
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
lineChannelBlockSchema,
|
|
14
14
|
mcpCredentialSchema,
|
|
15
15
|
slackChannelBlockSchema,
|
|
16
|
+
teamsChannelBlockSchema,
|
|
16
17
|
webexChannelBlockSchema,
|
|
17
18
|
} from '@/secrets/schema'
|
|
18
19
|
import { SecretsBackend } from '@/secrets/storage'
|
|
@@ -35,6 +36,7 @@ import type {
|
|
|
35
36
|
} from './protocol'
|
|
36
37
|
import { buildSupervisor, type SupervisorLogEvent, type SupervisorRestart } from './supervisor'
|
|
37
38
|
import type { TailscaleServeEvent } from './tailscale'
|
|
39
|
+
import type { TeamsRenewalCallbacks, TeamsRenewalLogEvent } from './teams-renewal-manager'
|
|
38
40
|
import { UNVERSIONED_SENTINEL } from './version'
|
|
39
41
|
import type { WebexRenewalCallbacks, WebexRenewalLogEvent } from './webex-renewal-manager'
|
|
40
42
|
|
|
@@ -78,6 +80,10 @@ export type DaemonOptions = {
|
|
|
78
80
|
// ticks hourly because Webex password tokens live ~27h (see
|
|
79
81
|
// webex-renewal-manager.ts). Omit when the agent has no webex channel.
|
|
80
82
|
webexRenewal?: WebexRenewalCallbacks
|
|
83
|
+
// Teams credential renewal capability. Same lifecycle as webexRenewal but
|
|
84
|
+
// ticks every 5 minutes because Teams skype tokens live only 60-90 min (see
|
|
85
|
+
// teams-renewal-manager.ts). Omit when the agent has no teams channel.
|
|
86
|
+
teamsRenewal?: TeamsRenewalCallbacks
|
|
81
87
|
// Populated once the daemon is booted so direct callers of the restart
|
|
82
88
|
// (the renewal callbacks in cli/hostd.ts) get the in-process registration
|
|
83
89
|
// path instead of the socket self-RPC. Omit in tests that don't exercise it.
|
|
@@ -125,6 +131,7 @@ export type DaemonLogEvent =
|
|
|
125
131
|
| { kind: 'tailscale-serve-event'; event: TailscaleServeEvent }
|
|
126
132
|
| KakaoRenewalLogEvent
|
|
127
133
|
| WebexRenewalLogEvent
|
|
134
|
+
| TeamsRenewalLogEvent
|
|
128
135
|
|
|
129
136
|
export type Daemon = {
|
|
130
137
|
registered: () => string[]
|
|
@@ -396,6 +403,7 @@ export async function startDaemon(opts: DaemonOptions = {}): Promise<Daemon> {
|
|
|
396
403
|
await withCleanupTimeout(opts.portbroker.stop(containerName, 'fatal-auth'), cleanupStepTimeoutMs)
|
|
397
404
|
if (opts.kakaoRenewal) await withCleanupTimeout(opts.kakaoRenewal.stop(containerName), cleanupStepTimeoutMs)
|
|
398
405
|
if (opts.webexRenewal) await withCleanupTimeout(opts.webexRenewal.stop(containerName), cleanupStepTimeoutMs)
|
|
406
|
+
if (opts.teamsRenewal) await withCleanupTimeout(opts.teamsRenewal.stop(containerName), cleanupStepTimeoutMs)
|
|
399
407
|
await removeRegistrationFile(containerName)
|
|
400
408
|
log({ kind: 'registration-skipped', containerName, reason: `fatal broker auth: ${reason}` })
|
|
401
409
|
})
|
|
@@ -434,6 +442,9 @@ export async function startDaemon(opts: DaemonOptions = {}): Promise<Daemon> {
|
|
|
434
442
|
if (opts.webexRenewal) {
|
|
435
443
|
opts.webexRenewal.start({ containerName: payload.containerName, cwd: payload.cwd })
|
|
436
444
|
}
|
|
445
|
+
if (opts.teamsRenewal) {
|
|
446
|
+
opts.teamsRenewal.start({ containerName: payload.containerName, cwd: payload.cwd })
|
|
447
|
+
}
|
|
437
448
|
}
|
|
438
449
|
|
|
439
450
|
const registerContainer = async (req: RegisterPayload): Promise<RpcResponse> => {
|
|
@@ -465,6 +476,7 @@ export async function startDaemon(opts: DaemonOptions = {}): Promise<Daemon> {
|
|
|
465
476
|
await withCleanupTimeout(opts.portbroker.stop(req.containerName, 'deregistered'), cleanupStepTimeoutMs)
|
|
466
477
|
if (opts.kakaoRenewal) await withCleanupTimeout(opts.kakaoRenewal.stop(req.containerName), cleanupStepTimeoutMs)
|
|
467
478
|
if (opts.webexRenewal) await withCleanupTimeout(opts.webexRenewal.stop(req.containerName), cleanupStepTimeoutMs)
|
|
479
|
+
if (opts.teamsRenewal) await withCleanupTimeout(opts.teamsRenewal.stop(req.containerName), cleanupStepTimeoutMs)
|
|
468
480
|
await removeRegistrationFile(req.containerName)
|
|
469
481
|
if (hadCwd) log({ kind: 'deregister', containerName: req.containerName, reason: 'requested' })
|
|
470
482
|
return { ok: true }
|
|
@@ -536,6 +548,7 @@ export async function startDaemon(opts: DaemonOptions = {}): Promise<Daemon> {
|
|
|
536
548
|
| { instagram: unknown }
|
|
537
549
|
| { line: unknown }
|
|
538
550
|
| { webex: unknown }
|
|
551
|
+
| { teams: unknown }
|
|
539
552
|
| { slack: unknown }
|
|
540
553
|
mcp?: never
|
|
541
554
|
}
|
|
@@ -572,9 +585,11 @@ export async function startDaemon(opts: DaemonOptions = {}): Promise<Daemon> {
|
|
|
572
585
|
? { key: 'discord' as const, parsed: discordChannelBlockSchema.safeParse(channelsPatch.discord) }
|
|
573
586
|
: 'webex' in channelsPatch
|
|
574
587
|
? { key: 'webex' as const, parsed: webexChannelBlockSchema.safeParse(channelsPatch.webex) }
|
|
575
|
-
: '
|
|
576
|
-
? { key: '
|
|
577
|
-
:
|
|
588
|
+
: 'teams' in channelsPatch
|
|
589
|
+
? { key: 'teams' as const, parsed: teamsChannelBlockSchema.safeParse(channelsPatch.teams) }
|
|
590
|
+
: 'slack' in channelsPatch
|
|
591
|
+
? { key: 'slack' as const, parsed: slackChannelBlockSchema.safeParse(channelsPatch.slack) }
|
|
592
|
+
: { key: 'kakaotalk' as const, parsed: kakaoChannelBlockSchema.safeParse(channelsPatch.kakaotalk) }
|
|
578
593
|
if (!patch.parsed.success) {
|
|
579
594
|
return { ok: false, reason: patch.parsed.error.issues.map((issue) => issue.message).join('; ') }
|
|
580
595
|
}
|
|
@@ -815,6 +830,7 @@ export async function startDaemon(opts: DaemonOptions = {}): Promise<Daemon> {
|
|
|
815
830
|
if (opts.portbroker) await withCleanupTimeout(opts.portbroker.stop(name, 'deregistered'), cleanupStepTimeoutMs)
|
|
816
831
|
if (opts.kakaoRenewal) await withCleanupTimeout(opts.kakaoRenewal.stop(name), cleanupStepTimeoutMs)
|
|
817
832
|
if (opts.webexRenewal) await withCleanupTimeout(opts.webexRenewal.stop(name), cleanupStepTimeoutMs)
|
|
833
|
+
if (opts.teamsRenewal) await withCleanupTimeout(opts.teamsRenewal.stop(name), cleanupStepTimeoutMs)
|
|
818
834
|
await removeRegistrationFile(name)
|
|
819
835
|
if (hadCwd) log({ kind: 'deregister', containerName: name, reason: 'gone' })
|
|
820
836
|
return { ok: true }
|
|
@@ -858,6 +874,10 @@ export async function startDaemon(opts: DaemonOptions = {}): Promise<Daemon> {
|
|
|
858
874
|
const names = Array.from(cwds.keys())
|
|
859
875
|
await withCleanupTimeout(Promise.allSettled(names.map((n) => opts.webexRenewal!.stop(n))), cleanupStepTimeoutMs)
|
|
860
876
|
}
|
|
877
|
+
if (opts.teamsRenewal) {
|
|
878
|
+
const names = Array.from(cwds.keys())
|
|
879
|
+
await withCleanupTimeout(Promise.allSettled(names.map((n) => opts.teamsRenewal!.stop(n))), cleanupStepTimeoutMs)
|
|
880
|
+
}
|
|
861
881
|
cwds.clear()
|
|
862
882
|
restartTokens.clear()
|
|
863
883
|
if (!onWindows) {
|
package/src/hostd/protocol.ts
CHANGED
|
@@ -6,6 +6,7 @@ import type {
|
|
|
6
6
|
LineChannelBlock,
|
|
7
7
|
McpCredential,
|
|
8
8
|
SlackChannelBlock,
|
|
9
|
+
TeamsChannelBlock,
|
|
9
10
|
WebexChannelBlock,
|
|
10
11
|
} from '@/secrets/schema'
|
|
11
12
|
|
|
@@ -15,6 +16,7 @@ export type SecretsPatchChannels =
|
|
|
15
16
|
| { instagram: InstagramChannelBlock }
|
|
16
17
|
| { line: LineChannelBlock }
|
|
17
18
|
| { webex: WebexChannelBlock }
|
|
19
|
+
| { teams: TeamsChannelBlock }
|
|
18
20
|
| { slack: SlackChannelBlock }
|
|
19
21
|
|
|
20
22
|
export type SecretsPatchMcp = { server: string; credential: McpCredential }
|