@eve/board 0.0.0 → 0.2.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.
Files changed (74) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +101 -0
  3. package/README.md +36 -2
  4. package/dist/extension/_manifest.json +6 -0
  5. package/dist/extension/channels/board.d.ts +2 -0
  6. package/dist/extension/channels/board.mjs +9 -0
  7. package/dist/extension/extension.d.ts +55 -0
  8. package/dist/extension/extension.mjs +70 -0
  9. package/dist/extension/instructions/boards.d.ts +2 -0
  10. package/dist/extension/instructions/boards.mjs +14 -0
  11. package/dist/extension/instructions.md +9 -0
  12. package/dist/extension/lib/authorize.d.ts +27 -0
  13. package/dist/extension/lib/authorize.mjs +7 -0
  14. package/dist/extension/lib/board-channel.d.ts +103 -0
  15. package/dist/extension/lib/board-channel.mjs +528 -0
  16. package/dist/extension/lib/boards.d.ts +28 -0
  17. package/dist/extension/lib/boards.mjs +103 -0
  18. package/dist/extension/lib/channel.d.ts +12 -0
  19. package/dist/extension/lib/channel.mjs +12 -0
  20. package/dist/extension/lib/client.d.ts +256 -0
  21. package/dist/extension/lib/client.mjs +363 -0
  22. package/dist/extension/lib/inbound.d.ts +21 -0
  23. package/dist/extension/lib/inbound.mjs +121 -0
  24. package/dist/extension/lib/route.d.ts +5 -0
  25. package/dist/extension/lib/route.mjs +23 -0
  26. package/dist/extension/lib/tools.d.ts +548 -0
  27. package/dist/extension/lib/tools.mjs +565 -0
  28. package/dist/extension/lib/watches.d.ts +95 -0
  29. package/dist/extension/lib/watches.mjs +330 -0
  30. package/dist/extension/skills/collaborate/SKILL.md +65 -0
  31. package/dist/extension/tools/actors.d.ts +10 -0
  32. package/dist/extension/tools/actors.mjs +10 -0
  33. package/dist/extension/tools/block_task.d.ts +3 -0
  34. package/dist/extension/tools/block_task.mjs +10 -0
  35. package/dist/extension/tools/cancel_schedule.d.ts +8 -0
  36. package/dist/extension/tools/cancel_schedule.mjs +10 -0
  37. package/dist/extension/tools/channels.d.ts +7 -0
  38. package/dist/extension/tools/channels.mjs +10 -0
  39. package/dist/extension/tools/complete_task.d.ts +3 -0
  40. package/dist/extension/tools/complete_task.mjs +10 -0
  41. package/dist/extension/tools/create_task.d.ts +28 -0
  42. package/dist/extension/tools/create_task.mjs +10 -0
  43. package/dist/extension/tools/fail_task.d.ts +3 -0
  44. package/dist/extension/tools/fail_task.mjs +10 -0
  45. package/dist/extension/tools/label.d.ts +11 -0
  46. package/dist/extension/tools/label.mjs +10 -0
  47. package/dist/extension/tools/no_reply.d.ts +1 -0
  48. package/dist/extension/tools/no_reply.mjs +7 -0
  49. package/dist/extension/tools/note.d.ts +26 -0
  50. package/dist/extension/tools/note.mjs +10 -0
  51. package/dist/extension/tools/post.d.ts +57 -0
  52. package/dist/extension/tools/post.mjs +10 -0
  53. package/dist/extension/tools/react.d.ts +19 -0
  54. package/dist/extension/tools/react.mjs +10 -0
  55. package/dist/extension/tools/read.d.ts +195 -0
  56. package/dist/extension/tools/read.mjs +10 -0
  57. package/dist/extension/tools/reply.d.ts +57 -0
  58. package/dist/extension/tools/reply.mjs +10 -0
  59. package/dist/extension/tools/schedule.d.ts +17 -0
  60. package/dist/extension/tools/schedule.mjs +10 -0
  61. package/dist/extension/tools/schedules.d.ts +9 -0
  62. package/dist/extension/tools/schedules.mjs +10 -0
  63. package/dist/extension/tools/unwatch.d.ts +9 -0
  64. package/dist/extension/tools/unwatch.mjs +10 -0
  65. package/dist/extension/tools/watch.d.ts +25 -0
  66. package/dist/extension/tools/watch.mjs +10 -0
  67. package/dist/extension/tools/watches.d.ts +20 -0
  68. package/dist/extension/tools/watches.mjs +10 -0
  69. package/dist/index.d.ts +4 -0
  70. package/dist/index.mjs +7 -0
  71. package/dist/tools/index.d.ts +21 -0
  72. package/dist/tools/index.mjs +26 -0
  73. package/package.json +65 -14
  74. package/index.js +0 -1
@@ -0,0 +1,565 @@
1
+ import { fileURLToPath as __eveFileURLToPath } from "node:url";
2
+ import { dirname as __eveDirname } from "node:path";
3
+ import { createRequire as __eveCreateRequire } from "node:module";
4
+ const __filename = __eveFileURLToPath(import.meta.url);
5
+ __eveDirname(__filename);
6
+ __eveCreateRequire(import.meta.url);
7
+ import { resolveBoards, selectBoard } from "./boards.mjs";
8
+ import { BOARD_HOLD_KIND_PATTERN, BOARD_NAME_PATTERN, BOARD_TASK_NOTE_LIMIT, BOARD_TEXT_LIMIT, boardPostId } from "./client.mjs";
9
+ import { boardClients, checkWatchScope, createWatch, listWatches, removeWatch, tailOf, watchIdOf } from "./watches.mjs";
10
+ import { authorOf } from "./inbound.mjs";
11
+ import { z } from "zod";
12
+ import { createLogger } from "eve/internal/channels";
13
+ import { defineTool } from "eve/tools";
14
+ import { always } from "eve/tools/approval";
15
+ const SHARED = "Board channels are shared with the team, and a channel may sync to Slack, GitHub, or Linear, so everything posted there can reach people outside the board.";
16
+ const messageId = z.string().min(1).describe("Any message ID in the thread, as the board gave it.");
17
+ const boardOption = z.string().min(1).optional().describe("Which configured board to use, by key. Defaults to this session's board; required outside a board session when more than one board is configured.");
18
+ function postId(ctx) {
19
+ return boardPostId(`${ctx.session.id}:${ctx.callId}`);
20
+ }
21
+ function boardMetadata(ctx) {
22
+ return ctx.channel.metadata;
23
+ }
24
+ function sessionBoard(ctx) {
25
+ return boardMetadata(ctx).board || void 0;
26
+ }
27
+ function currentThread(ctx) {
28
+ return boardMetadata(ctx).boardThread || void 0;
29
+ }
30
+ function targetBoard(settings, board, ctx) {
31
+ return selectBoard(resolveBoards(settings()), board, sessionBoard(ctx));
32
+ }
33
+ function clientFor(settings, board, ctx) {
34
+ const resolved = targetBoard(settings, board, ctx);
35
+ return {
36
+ board: resolved,
37
+ client: boardClients(resolved).model
38
+ };
39
+ }
40
+ function threadOrCurrent(id, ctx, targetKey) {
41
+ if (id !== void 0) return id;
42
+ const sessionKey = sessionBoard(ctx);
43
+ if (sessionKey !== void 0 && sessionKey !== targetKey) throw new Error(`Pass the thread's \`id\`: this session's thread is on board "${sessionKey}", not "${targetKey}".`);
44
+ const thread = currentThread(ctx);
45
+ if (thread === void 0) throw new Error("Pass the thread's `id`: this session didn't start from a board thread.");
46
+ return thread;
47
+ }
48
+ function holdsTask(ctx) {
49
+ return boardMetadata(ctx).boardTask != null;
50
+ }
51
+ function heldClaim(ctx) {
52
+ const task = boardMetadata(ctx).boardTask;
53
+ if (task == null) throw new Error("This session holds no board task: settle tools work only in a session that claimed one.");
54
+ if (Date.parse(task.until) <= Date.now()) throw new Error(`You no longer hold board task #${task.id}: its claim ran out. Stop working on it.`);
55
+ return task.id;
56
+ }
57
+ function settle(ctx, settled, details) {
58
+ return {
59
+ settled,
60
+ task: heldClaim(ctx),
61
+ ...details
62
+ };
63
+ }
64
+ const attach = z.array(z.string().min(1)).max(10).optional().describe("Files in the sandbox to attach, up to 4 MB each: absolute paths, or paths relative to the workspace root.");
65
+ const text = z.string().max(BOARD_TEXT_LIMIT).optional().describe("Markdown. May be left out when attaching files.");
66
+ async function uploadFiles(board, paths, getSandbox) {
67
+ if (paths === void 0 || paths.length === 0) return void 0;
68
+ const sandbox = await getSandbox();
69
+ const files = [];
70
+ for (const path of paths) {
71
+ const data = await sandbox.readBinaryFile({ path });
72
+ if (data === null) throw new Error(`There is no file at ${path} in the sandbox.`);
73
+ if (data.byteLength > 4194304) throw new Error(`${path} is over 4 MB, the most a board attachment can be.`);
74
+ const name = path.split("/").pop() || "file";
75
+ files.push({
76
+ data,
77
+ name
78
+ });
79
+ }
80
+ const ids = [];
81
+ for (const file of files) ids.push((await board.upload(file)).id);
82
+ return ids;
83
+ }
84
+ function written(message) {
85
+ return {
86
+ ...summarize(message),
87
+ ...message.unknownMentions !== void 0 && { warning: `${message.unknownMentions.map((handle) => `@${handle}`).join(", ")} matched no one on the board, so it stayed plain text and notified no one.` }
88
+ };
89
+ }
90
+ function summarizeThread(thread) {
91
+ return {
92
+ message: summarize(thread.message),
93
+ replies: thread.replies.map(summarize)
94
+ };
95
+ }
96
+ function summarize(message) {
97
+ return {
98
+ attachments: message.attachments.map((attachment) => attachment.name),
99
+ author: authorOf(message),
100
+ channel: message.channel,
101
+ createdAt: message.createdAt,
102
+ id: message.id,
103
+ labels: message.labels,
104
+ re: message.re,
105
+ text: message.deleted ? "(deleted)" : message.text,
106
+ ...message.task !== void 0 && { task: {
107
+ blocked: message.task.blocked,
108
+ holder: message.task.claim?.actor ?? null,
109
+ result: message.task.result,
110
+ state: message.task.state
111
+ } }
112
+ };
113
+ }
114
+ function requireContent(text, attach) {
115
+ if ((text === void 0 || text.trim() === "") && (attach === void 0 || attach.length === 0)) throw new Error("Pass text, files to attach, or both.");
116
+ }
117
+ function defineBoardChannelsTool(settings) {
118
+ return defineTool({
119
+ deferred: true,
120
+ description: "List the board's channels you can read.",
121
+ inputSchema: z.object({ board: boardOption }),
122
+ async execute({ board }, ctx) {
123
+ return { channels: await clientFor(settings, board, ctx).client.channels() };
124
+ }
125
+ });
126
+ }
127
+ function defineBoardReadTool(settings) {
128
+ return defineTool({
129
+ description: "Read the board. Pass `id` for a whole thread by any message in it, `link` for the thread a Slack or GitHub link points to, or `channel` for its threads, newest activity first. A channel read returns a `cursor`: pass it back as `after` to see only threads with activity since, or pass `older` as `before` to page back. The board has no search, so read the channel something would be in. Read a discussion before joining it. A task's state and holder show on its root.",
130
+ inputSchema: z.object({
131
+ board: boardOption,
132
+ id: messageId.optional(),
133
+ link: z.string().url().optional().describe("A link to a message on a platform the board syncs, such as a Slack permalink."),
134
+ channel: z.string().min(1).optional().describe("A channel path, or `prefix/` for a subtree."),
135
+ label: z.array(z.string().min(1)).optional().describe("`key` or `key=value` filters."),
136
+ text: z.string().min(1).optional().describe("With one `channel` (no `prefix/`, `label`, or `after`), keep threads whose first or latest message matches this text. Page older with `before`."),
137
+ mentions: z.string().min(1).optional().describe("With one `channel` (no `prefix/`, `label`, or `after`), keep threads whose first or latest message mentions `\"me\"`, a handle, or an actor ID."),
138
+ after: z.string().min(1).optional().describe("With `channel`, a `cursor` an earlier read returned; with `id`, a message ID, to read only the replies after it."),
139
+ before: z.string().min(1).optional().describe("With `channel`, the `older` an earlier read returned."),
140
+ limit: z.number().int().min(1).max(100).optional()
141
+ }),
142
+ async execute({ board: boardKey, id, link, after, ...query }, ctx) {
143
+ const board = clientFor(settings, boardKey, ctx).client;
144
+ if (id !== void 0) return summarizeThread(await board.thread(id, { after }));
145
+ if (link !== void 0) return summarizeThread(await board.linked(link));
146
+ if (query.channel === void 0) throw new Error("Pass `id`, `link`, or `channel`.");
147
+ const page = await board.threadsPage({
148
+ ...query,
149
+ after,
150
+ limit: query.limit ?? 20
151
+ });
152
+ return {
153
+ cursor: page.cursor,
154
+ older: page.older,
155
+ ...page.scanned !== void 0 && { scanned: page.scanned },
156
+ threads: page.threads.map((thread) => ({
157
+ last: thread.last === null ? null : summarize(thread.last),
158
+ message: summarize(thread.message),
159
+ replies: thread.replies
160
+ }))
161
+ };
162
+ }
163
+ });
164
+ }
165
+ function defineBoardPostTool(settings) {
166
+ return defineTool({
167
+ description: `Start a new board thread in a channel. Reply in an existing thread instead when one fits. ${SHARED}`,
168
+ inputSchema: z.object({
169
+ board: boardOption,
170
+ channel: z.string().min(1).describe("The channel path. The first post creates a channel."),
171
+ text,
172
+ attach,
173
+ labels: z.record(z.string(), z.string()).optional(),
174
+ noSync: z.boolean().optional().describe("Keep the thread on the board, out of synced platforms.")
175
+ }),
176
+ async execute({ board: boardKey, channel, text, attach, ...post }, ctx) {
177
+ requireContent(text, attach);
178
+ const board = clientFor(settings, boardKey, ctx).client;
179
+ const attachments = await uploadFiles(board, attach, ctx.getSandbox);
180
+ return written(await board.post(channel, {
181
+ ...post,
182
+ attachments,
183
+ id: postId(ctx),
184
+ text: text ?? ""
185
+ }));
186
+ }
187
+ });
188
+ }
189
+ function defineBoardReplyTool(settings) {
190
+ return defineTool({
191
+ description: `Post in a board thread right away, before your turn ends: progress while you work, a reply with files, or a reply in another thread. Defaults to this session's thread. In a session a board message started, your final message is posted there when your turn ends, so don't repeat it here. If a reply already says everything, such as files with a line about them, end your turn with \`no_reply\`. ${SHARED}`,
192
+ inputSchema: z.object({
193
+ board: boardOption,
194
+ id: messageId.optional(),
195
+ text,
196
+ attach,
197
+ after: z.string().min(1).optional().describe("The last message you read in the thread. In a busy thread, the reply posts only if nothing landed after it; otherwise it fails with `newer_message`, so read what's new and decide again."),
198
+ noSync: z.boolean().optional().describe("Keep the reply on the board, out of synced platforms.")
199
+ }),
200
+ async execute({ board: boardKey, id, text, attach, ...post }, ctx) {
201
+ requireContent(text, attach);
202
+ const { board: resolved, client: board } = clientFor(settings, boardKey, ctx);
203
+ const targetId = threadOrCurrent(id, ctx, resolved.key);
204
+ const attachments = await uploadFiles(board, attach, ctx.getSandbox);
205
+ return written(await board.reply(targetId, {
206
+ ...post,
207
+ attachments,
208
+ id: postId(ctx),
209
+ text: text ?? ""
210
+ }));
211
+ }
212
+ });
213
+ }
214
+ function defineBoardNoteTool(settings) {
215
+ return defineTool({
216
+ deferred: true,
217
+ description: "Keep a working note in a board thread: a reply that stays on the board and never reaches synced Slack, GitHub, or Linear threads. Use it for detail the team can read on the board, such as what you tried. Defaults to this session's thread.",
218
+ inputSchema: z.object({
219
+ board: boardOption,
220
+ id: messageId.optional(),
221
+ text: z.string().min(1).max(BOARD_TEXT_LIMIT)
222
+ }),
223
+ async execute({ board: boardKey, id, text }, ctx) {
224
+ const { board: resolved, client: board } = clientFor(settings, boardKey, ctx);
225
+ return written(await board.reply(threadOrCurrent(id, ctx, resolved.key), {
226
+ id: postId(ctx),
227
+ noSync: true,
228
+ text
229
+ }));
230
+ }
231
+ });
232
+ }
233
+ function defineBoardReactTool(settings) {
234
+ return defineTool({
235
+ description: "React to a board message with an emoji short name, such as `eyes` or `white_check_mark`.",
236
+ inputSchema: z.object({
237
+ board: boardOption,
238
+ id: z.string().min(1).describe("The message ID."),
239
+ emoji: z.string().min(1),
240
+ remove: z.boolean().optional()
241
+ }),
242
+ async execute({ board: boardKey, id, emoji, remove }, ctx) {
243
+ await clientFor(settings, boardKey, ctx).client.react(id, emoji, { remove });
244
+ return { ok: true };
245
+ }
246
+ });
247
+ }
248
+ function defineBoardLabelTool(settings) {
249
+ return defineTool({
250
+ deferred: true,
251
+ description: "Set or unset labels on a board message; labels on a thread's root apply to the whole thread. Use them to mark state others filter on, such as `status=done`. Labels under `board.` are the board's own.",
252
+ inputSchema: z.object({
253
+ board: boardOption,
254
+ id: z.string().min(1).describe("The message ID."),
255
+ set: z.record(z.string(), z.string()).optional(),
256
+ unset: z.array(z.string()).optional(),
257
+ if: z.record(z.string(), z.string().nullable()).optional().describe("Change only while the message has these labels now, such as `{ status: 'open' }`; `null` means the label must be unset. Use it when others may change the same labels.")
258
+ }),
259
+ async execute({ board: boardKey, id, set, unset, if: conditions }, ctx) {
260
+ await clientFor(settings, boardKey, ctx).client.label(id, {
261
+ if: conditions,
262
+ set,
263
+ unset
264
+ });
265
+ return { ok: true };
266
+ }
267
+ });
268
+ }
269
+ function defineBoardScheduleTool(settings) {
270
+ return defineTool({
271
+ deferred: true,
272
+ description: "Schedule a message in a board thread for later, as yourself: it wakes you there when it posts, so you can come back to something that takes time, such as a CI run. Write it for a reader who remembers nothing: what to check and what comes next. Defaults to this session's thread, and to staying off synced platforms. Pass `in` or `at` for once, or `every` with `times` or `until` for a repeat.",
273
+ inputSchema: z.object({
274
+ board: boardOption,
275
+ id: messageId.optional(),
276
+ text: z.string().min(1).max(BOARD_TEXT_LIMIT),
277
+ in: z.string().min(1).optional().describe("A duration from now, such as `5m` or `1d`."),
278
+ at: z.string().datetime().optional().describe("An ISO 8601 time."),
279
+ every: z.string().min(1).optional().describe("Repeat this often, at least `1m` apart."),
280
+ times: z.number().int().min(1).max(100).optional(),
281
+ until: z.string().datetime().optional(),
282
+ sync: z.boolean().optional().describe("Also post it to the thread's synced platforms, such as Slack.")
283
+ }),
284
+ async execute({ board: boardKey, id, sync, ...timing }, ctx) {
285
+ const { board: resolved, client: board } = clientFor(settings, boardKey, ctx);
286
+ const schedule = await board.schedule({ re: threadOrCurrent(id, ctx, resolved.key) }, {
287
+ ...timing,
288
+ noSync: sync !== true
289
+ });
290
+ return {
291
+ id: schedule.id,
292
+ next: schedule.next,
293
+ re: schedule.re
294
+ };
295
+ }
296
+ });
297
+ }
298
+ function defineBoardCancelScheduleTool(settings) {
299
+ return defineTool({
300
+ deferred: true,
301
+ description: "Cancel a scheduled board message by its ID, such as once what it checks on has happened.",
302
+ inputSchema: z.object({
303
+ board: boardOption,
304
+ id: z.string().min(1).describe("The schedule's ID.")
305
+ }),
306
+ async execute({ board: boardKey, id }, ctx) {
307
+ return await clientFor(settings, boardKey, ctx).client.cancelSchedule(id);
308
+ }
309
+ });
310
+ }
311
+ function defineBoardSchedulesTool(settings) {
312
+ return defineTool({
313
+ deferred: true,
314
+ description: "List pending scheduled board messages in a thread, by any message in it, or in a channel. Defaults to this session's thread, or outside one, to the messages you scheduled.",
315
+ inputSchema: z.object({
316
+ board: boardOption,
317
+ id: messageId.optional(),
318
+ channel: z.string().min(1).optional()
319
+ }),
320
+ async execute({ board: boardKey, id, channel }, ctx) {
321
+ const { board: resolved, client: board } = clientFor(settings, boardKey, ctx);
322
+ const sessionKey = sessionBoard(ctx);
323
+ const sameBoard = sessionKey === void 0 || sessionKey === resolved.key;
324
+ const re = id ?? (channel === void 0 && sameBoard ? currentThread(ctx) : void 0);
325
+ return { schedules: await board.schedules(re !== void 0 ? { re } : channel !== void 0 ? { channel } : { by: (await board.me()).actor }) };
326
+ }
327
+ });
328
+ }
329
+ function defineBoardActorsTool(settings) {
330
+ return defineTool({
331
+ deferred: true,
332
+ description: "List people and agents on the board with their handles, to mention them as `@handle`, or to name a task owner by `id`. Pass `search` to narrow by handle or name.",
333
+ inputSchema: z.object({
334
+ board: boardOption,
335
+ search: z.string().min(1).optional(),
336
+ limit: z.number().int().min(1).max(200).optional()
337
+ }),
338
+ async execute({ board: boardKey, search, limit }, ctx) {
339
+ const needle = search?.toLowerCase();
340
+ const actors = (await clientFor(settings, boardKey, ctx).client.actors()).filter((actor) => needle === void 0 || actor.handle.toLowerCase().includes(needle) || actor.name.toLowerCase().includes(needle));
341
+ return {
342
+ actors: actors.slice(0, limit ?? 50),
343
+ total: actors.length
344
+ };
345
+ }
346
+ });
347
+ }
348
+ function defineBoardCreateTaskTool(settings) {
349
+ return defineTool({
350
+ deferred: true,
351
+ description: `Create a task on the board's queue: a thread whose root is the brief for whoever claims it, any agent or person. Write the brief for a stranger: what to do, what's out of scope, and how to tell it's done. ${SHARED}`,
352
+ inputSchema: z.object({
353
+ board: boardOption,
354
+ channel: z.string().min(1).describe("The channel the queue is in."),
355
+ text: z.string().min(1).max(BOARD_TEXT_LIMIT).describe("The brief."),
356
+ labels: z.record(z.string(), z.string()).optional().describe("Labels that route it, such as `{ role: 'review' }`."),
357
+ needs: z.array(z.string().min(1)).optional().describe("Task IDs it waits for: it becomes ready when they complete."),
358
+ noSync: z.boolean().optional()
359
+ }),
360
+ async execute({ board: boardKey, channel, ...task }, ctx) {
361
+ return summarize(await clientFor(settings, boardKey, ctx).client.createTask(channel, {
362
+ ...task,
363
+ id: postId(ctx)
364
+ }));
365
+ }
366
+ });
367
+ }
368
+ function defineBoardCompleteTaskTool() {
369
+ return defineTool({
370
+ description: "Complete the board task you hold, with the result: what you did and the proof, such as a pull request link. Call it once the brief's check passes, as your last step.",
371
+ inputSchema: z.object({ result: z.string().min(1).max(BOARD_TASK_NOTE_LIMIT).optional() }),
372
+ async execute({ result }, ctx) {
373
+ return settle(ctx, "completed", { result });
374
+ }
375
+ });
376
+ }
377
+ function defineBoardFailTaskTool() {
378
+ return defineTool({
379
+ description: "Give up on the board task you hold, with why. Its owner can reopen it. Use it when the task can't be done as briefed.",
380
+ inputSchema: z.object({ reason: z.string().min(1).max(BOARD_TASK_NOTE_LIMIT) }),
381
+ async execute({ reason }, ctx) {
382
+ return settle(ctx, "failed", { reason });
383
+ }
384
+ });
385
+ }
386
+ function defineBoardBlockTaskTool() {
387
+ return defineTool({
388
+ description: "Hold the board task you hold for a person, with the one question they must answer: ask it in the thread with your recommendation first. Blocking ends your claim; once its owner answers and unblocks it, whoever claims it next reads the whole thread.",
389
+ inputSchema: z.object({
390
+ reason: z.string().min(1).max(BOARD_TASK_NOTE_LIMIT).describe("The question, in one line."),
391
+ kind: z.string().regex(BOARD_HOLD_KIND_PATTERN).optional().describe("What the hold is for, such as `needs_input` or `awaiting_approval`.")
392
+ }),
393
+ async execute({ reason, kind }, ctx) {
394
+ return settle(ctx, "blocked", {
395
+ kind,
396
+ reason
397
+ });
398
+ }
399
+ });
400
+ }
401
+ const log = createLogger("board.tools");
402
+ async function watchAuthorizationDenial(board, action, ctx, details = {}) {
403
+ const caller = ctx.session.auth?.current ?? null;
404
+ if (board.authorize !== void 0) try {
405
+ return await board.authorize({
406
+ action,
407
+ auth: caller,
408
+ board: board.key,
409
+ ...board.name !== void 0 && { boardName: board.name },
410
+ ...board.team !== void 0 && { team: board.team },
411
+ ...details.channel !== void 0 && { channel: details.channel },
412
+ ...details.claimChannel !== void 0 && { claimChannel: details.claimChannel },
413
+ ...details.watchId !== void 0 && { watchId: details.watchId }
414
+ }) === true ? void 0 : "You are not authorized to manage board watches on this agent.";
415
+ } catch (error) {
416
+ log.error("board watch authorization callback failed", {
417
+ action,
418
+ board: board.key,
419
+ error,
420
+ errorId: crypto.randomUUID()
421
+ });
422
+ return "You are not authorized to manage board watches on this agent.";
423
+ }
424
+ if (caller === null) return "Only a signed-in person may change this agent's board watches. Ask from a channel where you're signed in.";
425
+ if (caller.authenticator === "board-watcher") {
426
+ if (caller.attributes.actor_kind !== "person") return "Only a person on the team may change this agent's board watches, not a synced platform user or another agent.";
427
+ const callerBoard = typeof caller.attributes.board_key === "string" ? caller.attributes.board_key : void 0;
428
+ if (callerBoard !== void 0 && callerBoard !== board.key || callerBoard === void 0 && !board.shorthand) return "Board callers may only manage watches on their own board. Configure `authorize` to allow cross-board watch management.";
429
+ }
430
+ }
431
+ async function assertWatchAuthorized(board, action, ctx, details = {}) {
432
+ const denial = await watchAuthorizationDenial(board, action, ctx, details);
433
+ if (denial !== void 0) throw new Error(denial);
434
+ }
435
+ async function authorizingWatch(settings, board, action, ctx, details = {}) {
436
+ const resolved = targetBoard(settings, board, ctx);
437
+ await assertWatchAuthorized(resolved, action, ctx, details);
438
+ return {
439
+ config: resolved,
440
+ ...boardClients(resolved)
441
+ };
442
+ }
443
+ const queue = z.object({
444
+ channel: z.string().min(1).describe("The channel, or a subtree such as `work/`, to claim ready tasks from."),
445
+ label: z.record(z.string(), z.string()).optional().describe("Labels a task must have, such as `{ role: 'review' }`."),
446
+ from: z.array(z.string().min(1)).optional().describe("Owners whose tasks to take, by principal ID. Without them, only this deployment's own tasks.")
447
+ }).describe("Claim a ready task from this queue when the watch matches, and work the claimed task's thread. Leave it out to reply in the matching thread.");
448
+ function defineBoardWatchTool(settings) {
449
+ return defineTool({
450
+ approval: always(),
451
+ deferred: true,
452
+ description: "Watch the board: from now on, every message in the channel that matches the filters wakes you in its board thread with these instructions, across conversations, cold starts, and redeploys. Use it when someone asks you to watch a channel and act on what's posted there. Confirm conversational vs. task-claim (`claim`) mode, filters, and `claim.from` owners when unclear before calling; the caller approves the exact watch before it is created. Keep it as narrow as the request. Returns the watch's ID.",
453
+ inputSchema: z.object({
454
+ board: boardOption,
455
+ channel: z.string().min(1).max(200).describe("The channel to watch, such as `incidents`, or a subtree such as `work/`."),
456
+ label: z.array(z.string().min(1).max(200)).max(10).optional().describe("Labels a message must have: `key`, or `key=value`."),
457
+ by: z.string().min(1).max(200).optional().describe("Only messages by this handle, such as `@ada`."),
458
+ text: z.string().min(1).max(200).optional().describe("Only messages containing these words, ignoring case."),
459
+ instructions: z.string().min(1).max(BOARD_TEXT_LIMIT - 1e3).describe("What to do when it matches, written for a reader who remembers nothing of this conversation."),
460
+ claim: queue.optional()
461
+ }),
462
+ async execute({ board: boardKey, instructions, claim, ...filter }, ctx) {
463
+ const { config, deployment, watchChannel } = await authorizingWatch(settings, boardKey, "watch", ctx, {
464
+ channel: filter.channel,
465
+ ...claim !== void 0 && { claimChannel: claim.channel }
466
+ });
467
+ const action = claim === void 0 ? { type: "converse" } : {
468
+ queue: claim,
469
+ type: "claim"
470
+ };
471
+ checkWatchScope({
472
+ action,
473
+ can: config.can,
474
+ channel: filter.channel,
475
+ watchChannel
476
+ });
477
+ const watch = await createWatch({
478
+ action,
479
+ boardKey: config.key,
480
+ client: deployment,
481
+ id: watchIdOf(ctx.session.id, ctx.callId),
482
+ instructions,
483
+ routeBase: config.registrationRouteBase,
484
+ tail: tailOf(filter),
485
+ watchChannel
486
+ });
487
+ return config.shorthand ? {
488
+ action: watch.action,
489
+ id: watch.id,
490
+ tail: watch.tail
491
+ } : {
492
+ action: watch.action,
493
+ board: config.key,
494
+ id: watch.id,
495
+ tail: watch.tail
496
+ };
497
+ }
498
+ });
499
+ }
500
+ function defineBoardWatchesTool(settings) {
501
+ return defineTool({
502
+ deferred: true,
503
+ description: "List your board watches: each one's ID and what it matches, and with `details`, what it does. Defaults to this session's board inside a board session; outside one, omitting `board` when multiple boards are configured lists every authorized board's watches grouped by board.",
504
+ inputSchema: z.object({
505
+ board: boardOption,
506
+ details: z.boolean().optional().describe("Also read each watch's instructions and action.")
507
+ }),
508
+ async execute({ board: boardKey, details }, ctx) {
509
+ const set = resolveBoards(settings());
510
+ const sessionKey = sessionBoard(ctx);
511
+ if (boardKey !== void 0 || sessionKey !== void 0 || set.byKey.size === 1) {
512
+ const resolved = selectBoard(set, boardKey, sessionKey);
513
+ await assertWatchAuthorized(resolved, "watches", ctx);
514
+ const { deployment, watchChannel } = boardClients(resolved);
515
+ const watches = await listWatches({
516
+ client: deployment,
517
+ details: details === true,
518
+ watchChannel
519
+ });
520
+ return set.shorthand ? { watches } : {
521
+ board: resolved.key,
522
+ watches
523
+ };
524
+ }
525
+ const checked = await Promise.all([...set.byKey.values()].map(async (entry) => ({
526
+ denial: await watchAuthorizationDenial(entry, "watches", ctx),
527
+ entry
528
+ })));
529
+ const permitted = checked.filter((result) => result.denial === void 0).map((result) => result.entry);
530
+ if (permitted.length === 0) throw new Error(checked[0]?.denial ?? "You are not authorized to manage board watches on this agent.");
531
+ const entries = await Promise.all(permitted.map(async (entry) => {
532
+ const { deployment, watchChannel } = boardClients(entry);
533
+ const watches = await listWatches({
534
+ client: deployment,
535
+ details: details === true,
536
+ watchChannel
537
+ });
538
+ return [entry.key, watches];
539
+ }));
540
+ return { boards: Object.fromEntries(entries) };
541
+ }
542
+ });
543
+ }
544
+ function defineBoardUnwatchTool(settings) {
545
+ return defineTool({
546
+ approval: always(),
547
+ deferred: true,
548
+ description: "Stop a board watch by its ID: it no longer wakes you, and your other watches keep running.",
549
+ inputSchema: z.object({
550
+ board: boardOption,
551
+ id: z.string().regex(BOARD_NAME_PATTERN).describe("The watch's ID, such as `w-7k3p2q`.")
552
+ }),
553
+ async execute({ board: boardKey, id }, ctx) {
554
+ const { config, deployment, watchChannel } = await authorizingWatch(settings, boardKey, "unwatch", ctx, { watchId: id });
555
+ return await removeWatch({
556
+ boardKey: config.key,
557
+ client: deployment,
558
+ id,
559
+ routeBase: config.registrationRouteBase,
560
+ watchChannel
561
+ });
562
+ }
563
+ });
564
+ }
565
+ export { defineBoardActorsTool, defineBoardBlockTaskTool, defineBoardCancelScheduleTool, defineBoardChannelsTool, defineBoardCompleteTaskTool, defineBoardCreateTaskTool, defineBoardFailTaskTool, defineBoardLabelTool, defineBoardNoteTool, defineBoardPostTool, defineBoardReactTool, defineBoardReadTool, defineBoardReplyTool, defineBoardScheduleTool, defineBoardSchedulesTool, defineBoardUnwatchTool, defineBoardWatchTool, defineBoardWatchesTool, holdsTask };
@@ -0,0 +1,95 @@
1
+ import { DEFAULT_WATCH_CHANNEL } from "./boards.ts";
2
+ import { type BoardCan, type BoardClient, type BoardDiscovery, type BoardMessage, type BoardRegistration, type BoardRegistrationInput, type BoardSettings } from "./client.ts";
3
+ import { BOARD_WAKE_ROUTE, DEFAULT_BOARD_ROUTE_BASE, LEGACY_BOARD_WAKE_ROUTE } from "./route.ts";
4
+ export { BOARD_WAKE_ROUTE, DEFAULT_BOARD_ROUTE_BASE, DEFAULT_WATCH_CHANNEL, LEGACY_BOARD_WAKE_ROUTE, };
5
+ export declare const MAX_WATCHES = 64;
6
+ export interface BoardQueue {
7
+ readonly channel: string;
8
+ readonly label?: Readonly<Record<string, string>>;
9
+ readonly from?: readonly string[];
10
+ }
11
+ export type BoardWatchAction = {
12
+ readonly type: "converse";
13
+ } | {
14
+ readonly type: "claim";
15
+ readonly queue: BoardQueue;
16
+ };
17
+ export interface BoardWatch {
18
+ readonly id: string;
19
+ readonly tail: string;
20
+ readonly instructions?: string;
21
+ readonly action?: BoardWatchAction;
22
+ readonly problem?: string;
23
+ }
24
+ export interface BoardWatchRecord {
25
+ readonly id: string;
26
+ readonly instructions: string;
27
+ readonly action: BoardWatchAction;
28
+ readonly retired: boolean;
29
+ readonly message: BoardMessage;
30
+ }
31
+ export declare class BoardWatchConfigError extends Error {
32
+ readonly name = "BoardWatchConfigError";
33
+ }
34
+ export declare function watchIdOf(sessionId: string, callId: string): string;
35
+ export interface BoardWatchFilter {
36
+ readonly channel: string;
37
+ readonly label?: readonly string[];
38
+ readonly by?: string;
39
+ readonly text?: string;
40
+ }
41
+ export declare function tailOf({ channel, label, by, text }: BoardWatchFilter): string;
42
+ export declare function coversChannel(pattern: string, channel: string): boolean;
43
+ export declare function assertWatchId(id: string): void;
44
+ export type BoardClientConfig = Pick<BoardSettings, "can" | "name" | "profile" | "team" | "url" | "watchChannel">;
45
+ export declare function boardClients(settings: BoardClientConfig): {
46
+ deployment: BoardClient;
47
+ model: BoardClient;
48
+ watchChannel: string;
49
+ };
50
+ export declare function checkWatchScope(input: {
51
+ readonly channel: string;
52
+ readonly action: BoardWatchAction;
53
+ readonly can?: BoardCan;
54
+ readonly watchChannel: string;
55
+ }): void;
56
+ export declare function checkQueueScope(queue: BoardQueue, input: {
57
+ readonly can?: BoardCan;
58
+ readonly watchChannel: string;
59
+ }): void;
60
+ export declare function watchRecordText(id: string, action: BoardWatchAction, instructions: string): string;
61
+ export declare function findWatchRecord(input: {
62
+ readonly client: BoardClient;
63
+ readonly watchChannel: string;
64
+ readonly id: string;
65
+ readonly self: {
66
+ readonly actor: string;
67
+ };
68
+ }): Promise<BoardWatchRecord>;
69
+ export declare function registrationWhere(discovery: Pick<BoardDiscovery, "wake_by_path">, routeBase?: string): Omit<BoardRegistrationInput, "watch">;
70
+ export declare function heldRegistration(client: BoardClient): Promise<BoardRegistration | undefined>;
71
+ export declare function createWatch(input: {
72
+ readonly boardKey?: string;
73
+ readonly client: BoardClient;
74
+ readonly watchChannel: string;
75
+ readonly id: string;
76
+ readonly tail: string;
77
+ readonly instructions: string;
78
+ readonly action: BoardWatchAction;
79
+ readonly routeBase?: string;
80
+ }): Promise<BoardWatch>;
81
+ export declare function listWatches(input: {
82
+ readonly client: BoardClient;
83
+ readonly watchChannel: string;
84
+ readonly details: boolean;
85
+ }): Promise<BoardWatch[]>;
86
+ export declare function removeWatch(input: {
87
+ readonly boardKey?: string;
88
+ readonly client: BoardClient;
89
+ readonly watchChannel: string;
90
+ readonly id: string;
91
+ readonly routeBase?: string;
92
+ }): Promise<{
93
+ readonly id: string;
94
+ readonly removed: boolean;
95
+ }>;