@eve/board 0.1.0 → 0.2.1

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 (42) hide show
  1. package/dist/extension/_manifest.json +1 -1
  2. package/dist/extension/extension.d.ts +32 -4
  3. package/dist/extension/extension.mjs +73 -4
  4. package/dist/extension/instructions/boards.d.ts +2 -0
  5. package/dist/extension/instructions/boards.mjs +14 -0
  6. package/dist/extension/lib/authorize.d.ts +27 -0
  7. package/dist/extension/lib/authorize.mjs +7 -0
  8. package/dist/extension/lib/board-channel.d.ts +13 -1
  9. package/dist/extension/lib/board-channel.mjs +84 -34
  10. package/dist/extension/lib/boards.d.ts +28 -0
  11. package/dist/extension/lib/boards.mjs +103 -0
  12. package/dist/extension/lib/channel.d.ts +1 -0
  13. package/dist/extension/lib/client.d.ts +5 -1
  14. package/dist/extension/lib/client.mjs +25 -11
  15. package/dist/extension/lib/inbound.d.ts +9 -7
  16. package/dist/extension/lib/inbound.mjs +43 -15
  17. package/dist/extension/lib/route.d.ts +5 -0
  18. package/dist/extension/lib/route.mjs +23 -0
  19. package/dist/extension/lib/tools.d.ts +45 -1
  20. package/dist/extension/lib/tools.mjs +173 -65
  21. package/dist/extension/lib/watches.d.ts +11 -5
  22. package/dist/extension/lib/watches.mjs +62 -28
  23. package/dist/extension/skills/collaborate/SKILL.md +16 -5
  24. package/dist/extension/tools/actors.d.ts +1 -0
  25. package/dist/extension/tools/block_task.d.ts +1 -1
  26. package/dist/extension/tools/cancel_schedule.d.ts +1 -0
  27. package/dist/extension/tools/channels.d.ts +3 -1
  28. package/dist/extension/tools/complete_task.d.ts +1 -1
  29. package/dist/extension/tools/create_task.d.ts +1 -0
  30. package/dist/extension/tools/fail_task.d.ts +1 -1
  31. package/dist/extension/tools/label.d.ts +1 -0
  32. package/dist/extension/tools/note.d.ts +1 -0
  33. package/dist/extension/tools/post.d.ts +2 -0
  34. package/dist/extension/tools/react.d.ts +2 -0
  35. package/dist/extension/tools/read.d.ts +8 -0
  36. package/dist/extension/tools/reply.d.ts +2 -0
  37. package/dist/extension/tools/schedule.d.ts +1 -0
  38. package/dist/extension/tools/schedules.d.ts +1 -0
  39. package/dist/extension/tools/unwatch.d.ts +1 -0
  40. package/dist/extension/tools/watch.d.ts +7 -0
  41. package/dist/extension/tools/watches.d.ts +13 -0
  42. package/package.json +4 -4
@@ -4,27 +4,44 @@ import { createRequire as __eveCreateRequire } from "node:module";
4
4
  const __filename = __eveFileURLToPath(import.meta.url);
5
5
  __eveDirname(__filename);
6
6
  __eveCreateRequire(import.meta.url);
7
+ import { resolveBoards, selectBoard } from "./boards.mjs";
7
8
  import { BOARD_HOLD_KIND_PATTERN, BOARD_NAME_PATTERN, BOARD_TASK_NOTE_LIMIT, BOARD_TEXT_LIMIT, boardPostId } from "./client.mjs";
8
9
  import { boardClients, checkWatchScope, createWatch, listWatches, removeWatch, tailOf, watchIdOf } from "./watches.mjs";
9
10
  import { authorOf } from "./inbound.mjs";
10
11
  import { z } from "zod";
12
+ import { createLogger } from "eve/internal/channels";
11
13
  import { defineTool } from "eve/tools";
14
+ import { always } from "eve/tools/approval";
12
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.";
13
16
  const messageId = z.string().min(1).describe("Any message ID in the thread, as the board gave it.");
14
- function client(settings) {
15
- return boardClients(settings()).model;
16
- }
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.");
17
18
  function postId(ctx) {
18
19
  return boardPostId(`${ctx.session.id}:${ctx.callId}`);
19
20
  }
20
21
  function boardMetadata(ctx) {
21
22
  return ctx.channel.metadata;
22
23
  }
24
+ function sessionBoard(ctx) {
25
+ return boardMetadata(ctx).board || void 0;
26
+ }
23
27
  function currentThread(ctx) {
24
28
  return boardMetadata(ctx).boardThread || void 0;
25
29
  }
26
- function threadOrCurrent(id, ctx) {
27
- const thread = id ?? currentThread(ctx);
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);
28
45
  if (thread === void 0) throw new Error("Pass the thread's `id`: this session didn't start from a board thread.");
29
46
  return thread;
30
47
  }
@@ -101,9 +118,9 @@ function defineBoardChannelsTool(settings) {
101
118
  return defineTool({
102
119
  deferred: true,
103
120
  description: "List the board's channels you can read.",
104
- inputSchema: z.object({}),
105
- async execute() {
106
- return { channels: await client(settings).channels() };
121
+ inputSchema: z.object({ board: boardOption }),
122
+ async execute({ board }, ctx) {
123
+ return { channels: await clientFor(settings, board, ctx).client.channels() };
107
124
  }
108
125
  });
109
126
  }
@@ -111,16 +128,19 @@ function defineBoardReadTool(settings) {
111
128
  return defineTool({
112
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.",
113
130
  inputSchema: z.object({
131
+ board: boardOption,
114
132
  id: messageId.optional(),
115
133
  link: z.string().url().optional().describe("A link to a message on a platform the board syncs, such as a Slack permalink."),
116
134
  channel: z.string().min(1).optional().describe("A channel path, or `prefix/` for a subtree."),
117
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."),
118
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."),
119
139
  before: z.string().min(1).optional().describe("With `channel`, the `older` an earlier read returned."),
120
140
  limit: z.number().int().min(1).max(100).optional()
121
141
  }),
122
- async execute({ id, link, after, ...query }) {
123
- const board = client(settings);
142
+ async execute({ board: boardKey, id, link, after, ...query }, ctx) {
143
+ const board = clientFor(settings, boardKey, ctx).client;
124
144
  if (id !== void 0) return summarizeThread(await board.thread(id, { after }));
125
145
  if (link !== void 0) return summarizeThread(await board.linked(link));
126
146
  if (query.channel === void 0) throw new Error("Pass `id`, `link`, or `channel`.");
@@ -132,6 +152,7 @@ function defineBoardReadTool(settings) {
132
152
  return {
133
153
  cursor: page.cursor,
134
154
  older: page.older,
155
+ ...page.scanned !== void 0 && { scanned: page.scanned },
135
156
  threads: page.threads.map((thread) => ({
136
157
  last: thread.last === null ? null : summarize(thread.last),
137
158
  message: summarize(thread.message),
@@ -145,15 +166,16 @@ function defineBoardPostTool(settings) {
145
166
  return defineTool({
146
167
  description: `Start a new board thread in a channel. Reply in an existing thread instead when one fits. ${SHARED}`,
147
168
  inputSchema: z.object({
169
+ board: boardOption,
148
170
  channel: z.string().min(1).describe("The channel path. The first post creates a channel."),
149
171
  text,
150
172
  attach,
151
173
  labels: z.record(z.string(), z.string()).optional(),
152
174
  noSync: z.boolean().optional().describe("Keep the thread on the board, out of synced platforms.")
153
175
  }),
154
- async execute({ channel, text, attach, ...post }, ctx) {
176
+ async execute({ board: boardKey, channel, text, attach, ...post }, ctx) {
155
177
  requireContent(text, attach);
156
- const board = client(settings);
178
+ const board = clientFor(settings, boardKey, ctx).client;
157
179
  const attachments = await uploadFiles(board, attach, ctx.getSandbox);
158
180
  return written(await board.post(channel, {
159
181
  ...post,
@@ -168,17 +190,19 @@ function defineBoardReplyTool(settings) {
168
190
  return defineTool({
169
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}`,
170
192
  inputSchema: z.object({
193
+ board: boardOption,
171
194
  id: messageId.optional(),
172
195
  text,
173
196
  attach,
174
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."),
175
198
  noSync: z.boolean().optional().describe("Keep the reply on the board, out of synced platforms.")
176
199
  }),
177
- async execute({ id, text, attach, ...post }, ctx) {
200
+ async execute({ board: boardKey, id, text, attach, ...post }, ctx) {
178
201
  requireContent(text, attach);
179
- const board = client(settings);
202
+ const { board: resolved, client: board } = clientFor(settings, boardKey, ctx);
203
+ const targetId = threadOrCurrent(id, ctx, resolved.key);
180
204
  const attachments = await uploadFiles(board, attach, ctx.getSandbox);
181
- return written(await board.reply(threadOrCurrent(id, ctx), {
205
+ return written(await board.reply(targetId, {
182
206
  ...post,
183
207
  attachments,
184
208
  id: postId(ctx),
@@ -192,11 +216,13 @@ function defineBoardNoteTool(settings) {
192
216
  deferred: true,
193
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.",
194
218
  inputSchema: z.object({
219
+ board: boardOption,
195
220
  id: messageId.optional(),
196
221
  text: z.string().min(1).max(BOARD_TEXT_LIMIT)
197
222
  }),
198
- async execute({ id, text }, ctx) {
199
- return written(await client(settings).reply(threadOrCurrent(id, ctx), {
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), {
200
226
  id: postId(ctx),
201
227
  noSync: true,
202
228
  text
@@ -208,12 +234,13 @@ function defineBoardReactTool(settings) {
208
234
  return defineTool({
209
235
  description: "React to a board message with an emoji short name, such as `eyes` or `white_check_mark`.",
210
236
  inputSchema: z.object({
237
+ board: boardOption,
211
238
  id: z.string().min(1).describe("The message ID."),
212
239
  emoji: z.string().min(1),
213
240
  remove: z.boolean().optional()
214
241
  }),
215
- async execute({ id, emoji, remove }) {
216
- await client(settings).react(id, emoji, { remove });
242
+ async execute({ board: boardKey, id, emoji, remove }, ctx) {
243
+ await clientFor(settings, boardKey, ctx).client.react(id, emoji, { remove });
217
244
  return { ok: true };
218
245
  }
219
246
  });
@@ -223,13 +250,14 @@ function defineBoardLabelTool(settings) {
223
250
  deferred: true,
224
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.",
225
252
  inputSchema: z.object({
253
+ board: boardOption,
226
254
  id: z.string().min(1).describe("The message ID."),
227
255
  set: z.record(z.string(), z.string()).optional(),
228
256
  unset: z.array(z.string()).optional(),
229
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.")
230
258
  }),
231
- async execute({ id, set, unset, if: conditions }) {
232
- await client(settings).label(id, {
259
+ async execute({ board: boardKey, id, set, unset, if: conditions }, ctx) {
260
+ await clientFor(settings, boardKey, ctx).client.label(id, {
233
261
  if: conditions,
234
262
  set,
235
263
  unset
@@ -243,6 +271,7 @@ function defineBoardScheduleTool(settings) {
243
271
  deferred: true,
244
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.",
245
273
  inputSchema: z.object({
274
+ board: boardOption,
246
275
  id: messageId.optional(),
247
276
  text: z.string().min(1).max(BOARD_TEXT_LIMIT),
248
277
  in: z.string().min(1).optional().describe("A duration from now, such as `5m` or `1d`."),
@@ -252,8 +281,9 @@ function defineBoardScheduleTool(settings) {
252
281
  until: z.string().datetime().optional(),
253
282
  sync: z.boolean().optional().describe("Also post it to the thread's synced platforms, such as Slack.")
254
283
  }),
255
- async execute({ id, sync, ...timing }, ctx) {
256
- const schedule = await client(settings).schedule({ re: threadOrCurrent(id, ctx) }, {
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) }, {
257
287
  ...timing,
258
288
  noSync: sync !== true
259
289
  });
@@ -269,9 +299,12 @@ function defineBoardCancelScheduleTool(settings) {
269
299
  return defineTool({
270
300
  deferred: true,
271
301
  description: "Cancel a scheduled board message by its ID, such as once what it checks on has happened.",
272
- inputSchema: z.object({ id: z.string().min(1).describe("The schedule's ID.") }),
273
- async execute({ id }) {
274
- return await client(settings).cancelSchedule(id);
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);
275
308
  }
276
309
  });
277
310
  }
@@ -280,12 +313,15 @@ function defineBoardSchedulesTool(settings) {
280
313
  deferred: true,
281
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.",
282
315
  inputSchema: z.object({
316
+ board: boardOption,
283
317
  id: messageId.optional(),
284
318
  channel: z.string().min(1).optional()
285
319
  }),
286
- async execute({ id, channel }, ctx) {
287
- const board = client(settings);
288
- const re = id ?? (channel === void 0 ? currentThread(ctx) : void 0);
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);
289
325
  return { schedules: await board.schedules(re !== void 0 ? { re } : channel !== void 0 ? { channel } : { by: (await board.me()).actor }) };
290
326
  }
291
327
  });
@@ -295,12 +331,13 @@ function defineBoardActorsTool(settings) {
295
331
  deferred: true,
296
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.",
297
333
  inputSchema: z.object({
334
+ board: boardOption,
298
335
  search: z.string().min(1).optional(),
299
336
  limit: z.number().int().min(1).max(200).optional()
300
337
  }),
301
- async execute({ search, limit }) {
338
+ async execute({ board: boardKey, search, limit }, ctx) {
302
339
  const needle = search?.toLowerCase();
303
- const actors = (await client(settings).actors()).filter((actor) => needle === void 0 || actor.handle.toLowerCase().includes(needle) || actor.name.toLowerCase().includes(needle));
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));
304
341
  return {
305
342
  actors: actors.slice(0, limit ?? 50),
306
343
  total: actors.length
@@ -313,14 +350,15 @@ function defineBoardCreateTaskTool(settings) {
313
350
  deferred: true,
314
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}`,
315
352
  inputSchema: z.object({
353
+ board: boardOption,
316
354
  channel: z.string().min(1).describe("The channel the queue is in."),
317
355
  text: z.string().min(1).max(BOARD_TEXT_LIMIT).describe("The brief."),
318
356
  labels: z.record(z.string(), z.string()).optional().describe("Labels that route it, such as `{ role: 'review' }`."),
319
357
  needs: z.array(z.string().min(1)).optional().describe("Task IDs it waits for: it becomes ready when they complete."),
320
358
  noSync: z.boolean().optional()
321
359
  }),
322
- async execute({ channel, ...task }, ctx) {
323
- return summarize(await client(settings).createTask(channel, {
360
+ async execute({ board: boardKey, channel, ...task }, ctx) {
361
+ return summarize(await clientFor(settings, boardKey, ctx).client.createTask(channel, {
324
362
  ...task,
325
363
  id: postId(ctx)
326
364
  }));
@@ -360,24 +398,47 @@ function defineBoardBlockTaskTool() {
360
398
  }
361
399
  });
362
400
  }
363
- function configuring(settings, ctx) {
364
- assertConfigurer(settings, ctx);
365
- const config = settings();
366
- return {
367
- config,
368
- ...boardClients(config)
369
- };
370
- }
371
- function assertConfigurer(settings, ctx) {
401
+ const log = createLogger("board.tools");
402
+ async function watchAuthorizationDenial(board, action, ctx, details = {}) {
372
403
  const caller = ctx.session.auth?.current ?? null;
373
- const allowed = settings().configurers;
374
- if (allowed !== void 0) {
375
- const ids = [caller?.principalId, caller?.attributes.principal];
376
- if (caller !== null && ids.some((id) => typeof id === "string" && allowed.includes(id))) return;
377
- throw new Error("Only the people this agent's `configurers` names may change its board watches. Ask one of them.");
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.";
378
423
  }
379
- if (caller === null) throw new Error("Only a signed-in person may change this agent's board watches. Ask from a channel where you're signed in.");
380
- if (caller.authenticator === "board-watcher" && caller.attributes.actor_kind !== "person") throw new Error("Only a person on the team may change this agent's board watches, not a synced platform user or another agent.");
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
+ };
381
442
  }
382
443
  const queue = z.object({
383
444
  channel: z.string().min(1).describe("The channel, or a subtree such as `work/`, to claim ready tasks from."),
@@ -386,9 +447,11 @@ const queue = z.object({
386
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.");
387
448
  function defineBoardWatchTool(settings) {
388
449
  return defineTool({
450
+ approval: always(),
389
451
  deferred: true,
390
- 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. Keep it as narrow as the request. Returns the watch's ID.",
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.",
391
453
  inputSchema: z.object({
454
+ board: boardOption,
392
455
  channel: z.string().min(1).max(200).describe("The channel to watch, such as `incidents`, or a subtree such as `work/`."),
393
456
  label: z.array(z.string().min(1).max(200)).max(10).optional().describe("Labels a message must have: `key`, or `key=value`."),
394
457
  by: z.string().min(1).max(200).optional().describe("Only messages by this handle, such as `@ada`."),
@@ -396,8 +459,11 @@ function defineBoardWatchTool(settings) {
396
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."),
397
460
  claim: queue.optional()
398
461
  }),
399
- async execute({ instructions, claim, ...filter }, ctx) {
400
- const { config, deployment, watchChannel } = configuring(settings, ctx);
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
+ });
401
467
  const action = claim === void 0 ? { type: "converse" } : {
402
468
  queue: claim,
403
469
  type: "claim"
@@ -410,14 +476,21 @@ function defineBoardWatchTool(settings) {
410
476
  });
411
477
  const watch = await createWatch({
412
478
  action,
479
+ boardKey: config.key,
413
480
  client: deployment,
414
481
  id: watchIdOf(ctx.session.id, ctx.callId),
415
482
  instructions,
483
+ routeBase: config.registrationRouteBase,
416
484
  tail: tailOf(filter),
417
485
  watchChannel
418
486
  });
419
- return {
487
+ return config.shorthand ? {
488
+ action: watch.action,
489
+ id: watch.id,
490
+ tail: watch.tail
491
+ } : {
420
492
  action: watch.action,
493
+ board: config.key,
421
494
  id: watch.id,
422
495
  tail: watch.tail
423
496
  };
@@ -427,28 +500,63 @@ function defineBoardWatchTool(settings) {
427
500
  function defineBoardWatchesTool(settings) {
428
501
  return defineTool({
429
502
  deferred: true,
430
- description: "List your board watches: each one's ID and what it matches, and with `details`, what it does.",
431
- inputSchema: z.object({ details: z.boolean().optional().describe("Also read each watch's instructions and action.") }),
432
- async execute({ details }, ctx) {
433
- const { deployment, watchChannel } = configuring(settings, ctx);
434
- return { watches: await listWatches({
435
- client: deployment,
436
- details: details === true,
437
- watchChannel
438
- }) };
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) };
439
541
  }
440
542
  });
441
543
  }
442
544
  function defineBoardUnwatchTool(settings) {
443
545
  return defineTool({
546
+ approval: always(),
444
547
  deferred: true,
445
548
  description: "Stop a board watch by its ID: it no longer wakes you, and your other watches keep running.",
446
- inputSchema: z.object({ id: z.string().regex(BOARD_NAME_PATTERN).describe("The watch's ID, such as `w-7k3p2q`.") }),
447
- async execute({ id }, ctx) {
448
- const { deployment, watchChannel } = configuring(settings, ctx);
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 });
449
555
  return await removeWatch({
556
+ boardKey: config.key,
450
557
  client: deployment,
451
558
  id,
559
+ routeBase: config.registrationRouteBase,
452
560
  watchChannel
453
561
  });
454
562
  }
@@ -1,7 +1,8 @@
1
+ import { DEFAULT_WATCH_CHANNEL } from "./boards.ts";
1
2
  import { type BoardCan, type BoardClient, type BoardDiscovery, type BoardMessage, type BoardRegistration, type BoardRegistrationInput, type BoardSettings } from "./client.ts";
2
- export declare const DEFAULT_WATCH_CHANNEL = "eve-config/watches";
3
- export declare const BOARD_WAKE_ROUTE = "/board/wake";
4
- export declare const MAX_WATCHES = 32;
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;
5
6
  export interface BoardQueue {
6
7
  readonly channel: string;
7
8
  readonly label?: Readonly<Record<string, string>>;
@@ -40,7 +41,8 @@ export interface BoardWatchFilter {
40
41
  export declare function tailOf({ channel, label, by, text }: BoardWatchFilter): string;
41
42
  export declare function coversChannel(pattern: string, channel: string): boolean;
42
43
  export declare function assertWatchId(id: string): void;
43
- export declare function boardClients(settings: BoardSettings): {
44
+ export type BoardClientConfig = Pick<BoardSettings, "can" | "name" | "profile" | "team" | "url" | "watchChannel">;
45
+ export declare function boardClients(settings: BoardClientConfig): {
44
46
  deployment: BoardClient;
45
47
  model: BoardClient;
46
48
  watchChannel: string;
@@ -64,15 +66,17 @@ export declare function findWatchRecord(input: {
64
66
  readonly actor: string;
65
67
  };
66
68
  }): Promise<BoardWatchRecord>;
67
- export declare function registrationWhere(discovery: Pick<BoardDiscovery, "wake_by_path">): Omit<BoardRegistrationInput, "watch">;
69
+ export declare function registrationWhere(discovery: Pick<BoardDiscovery, "wake_by_path">, routeBase?: string): Omit<BoardRegistrationInput, "watch">;
68
70
  export declare function heldRegistration(client: BoardClient): Promise<BoardRegistration | undefined>;
69
71
  export declare function createWatch(input: {
72
+ readonly boardKey?: string;
70
73
  readonly client: BoardClient;
71
74
  readonly watchChannel: string;
72
75
  readonly id: string;
73
76
  readonly tail: string;
74
77
  readonly instructions: string;
75
78
  readonly action: BoardWatchAction;
79
+ readonly routeBase?: string;
76
80
  }): Promise<BoardWatch>;
77
81
  export declare function listWatches(input: {
78
82
  readonly client: BoardClient;
@@ -80,9 +84,11 @@ export declare function listWatches(input: {
80
84
  readonly details: boolean;
81
85
  }): Promise<BoardWatch[]>;
82
86
  export declare function removeWatch(input: {
87
+ readonly boardKey?: string;
83
88
  readonly client: BoardClient;
84
89
  readonly watchChannel: string;
85
90
  readonly id: string;
91
+ readonly routeBase?: string;
86
92
  }): Promise<{
87
93
  readonly id: string;
88
94
  readonly removed: boolean;