@eve/board 0.4.0 → 0.5.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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "kind": "eve-extension",
3
3
  "formatVersion": 3,
4
- "builtWithEve": "1.8.0",
4
+ "builtWithEve": "1.9.0",
5
5
  "contractMajor": 0
6
6
  }
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import type { BoardAuthorize } from "./lib/authorize.ts";
2
+ import type { BoardAuthorize, BoardClaimAuthorize } from "./lib/authorize.ts";
3
3
  /**
4
4
  * Makes the agent a participant on one or more Vercel Boards. By default, every accessible board on
5
5
  * the team is discoverable and `General` is used when no board is specified; configure `boards` to
@@ -29,6 +29,7 @@ declare const _default: import("eve/extension").ExtensionHandle<z.ZodObject<{
29
29
  }>>>]>>]>>;
30
30
  watchChannel: z.ZodOptional<z.ZodString>;
31
31
  authorize: z.ZodOptional<z.ZodCustom<BoardAuthorize, BoardAuthorize>>;
32
+ authorizeClaim: z.ZodOptional<z.ZodCustom<BoardClaimAuthorize, BoardClaimAuthorize>>;
32
33
  configurers: z.ZodOptional<z.ZodUnknown>;
33
34
  route: z.ZodOptional<z.ZodString>;
34
35
  boards: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodBoolean, z.ZodObject<{
@@ -54,6 +55,7 @@ declare const _default: import("eve/extension").ExtensionHandle<z.ZodObject<{
54
55
  }>>>]>>]>>;
55
56
  watchChannel: z.ZodOptional<z.ZodString>;
56
57
  authorize: z.ZodOptional<z.ZodCustom<BoardAuthorize, BoardAuthorize>>;
58
+ authorizeClaim: z.ZodOptional<z.ZodCustom<BoardClaimAuthorize, BoardClaimAuthorize>>;
57
59
  configurers: z.ZodOptional<z.ZodUnknown>;
58
60
  }, z.core.$strip>]>>>;
59
61
  }, z.core.$strip>>;
@@ -14,6 +14,7 @@ const profile = z.string().regex(BOARD_NAME_PATTERN, "a letter, then up to 31 le
14
14
  const can = z.union([grant, z.record(z.string().refine((pattern) => pattern === "*" || BOARD_CHANNEL_SELECTOR.test(pattern), "a channel, a subtree such as `work/`, or `*`"), grant)]);
15
15
  const watchChannel = z.string().max(200).regex(BOARD_CHANNEL_SELECTOR, "lowercase segments joined by /").refine((channel) => !channel.endsWith("/"), "one channel, not a subtree");
16
16
  const authorize = fn();
17
+ const authorizeClaim = fn();
17
18
  const removedConfigurers = z.unknown().optional();
18
19
  const CONFIGURERS_REMOVED = "`configurers` was removed; use `authorize` to decide who may manage board watches. See https://eve.dev/docs/channels/board.";
19
20
  const boardUrl = z.string().url().refine((value) => /^https?:\/\//u.test(value), "an http:// or https:// board URL");
@@ -28,6 +29,7 @@ const boardEntry = z.object({
28
29
  can: can.optional(),
29
30
  watchChannel: watchChannel.optional(),
30
31
  authorize: authorize.optional(),
32
+ authorizeClaim: authorizeClaim.optional(),
31
33
  configurers: removedConfigurers
32
34
  });
33
35
  var extension_default = defineExtension({ config: z.object({
@@ -39,6 +41,7 @@ var extension_default = defineExtension({ config: z.object({
39
41
  can: can.optional(),
40
42
  watchChannel: watchChannel.optional(),
41
43
  authorize: authorize.optional(),
44
+ authorizeClaim: authorizeClaim.optional(),
42
45
  configurers: removedConfigurers,
43
46
  route: z.string().min(1).refine(isValidBoardRouteBase, "an absolute path without parameters or query string, such as \"/eve/v1/board\"").optional(),
44
47
  boards: z.record(z.string().refine((key) => key === "*" || BOARD_NAME_PATTERN.test(key), "\"*\" or a letter, then up to 31 letters, numbers, or hyphens"), z.union([z.boolean(), boardEntry])).optional()
@@ -1,7 +1,7 @@
1
1
  import type { SessionAuthContext } from "eve/context";
2
2
  /** Operation passed to {@link BoardAuthorize}. */
3
- export type BoardAuthorizeAction = "watch" | "watches" | "unwatch" | "claim_task";
4
- /** Context passed to `authorize` before creating, listing, or removing board watches, or claiming a task with `claim_task`. */
3
+ export type BoardAuthorizeAction = "watch" | "watches" | "unwatch";
4
+ /** Context passed to `authorize` before creating, updating, listing, or removing board watches. */
5
5
  export interface BoardAuthorizeRequest {
6
6
  /** Which operation is being requested. */
7
7
  readonly action: BoardAuthorizeAction;
@@ -15,16 +15,37 @@ export interface BoardAuthorizeRequest {
15
15
  readonly team?: string;
16
16
  /** For `"watch"`, the channel selector being watched. */
17
17
  readonly channel?: string;
18
- /** For `"watch"` with `claim`, or `"claim_task"`, the task's channel or queue channel selector. */
18
+ /** For `"watch"` with `claim`, the queue channel selector. */
19
19
  readonly claimChannel?: string;
20
- /** For `"unwatch"`, the watch ID being removed. */
20
+ /** For `"unwatch"`, or for `"watch"` when updating an existing watch in place, the watch ID. */
21
21
  readonly watchId?: string;
22
- /** For `"claim_task"` by ID, the ID of the task being claimed. */
23
- readonly taskId?: string;
24
22
  }
25
23
  /**
26
- * Decides whether the current caller may create, list, or remove watches on a board, or claim
27
- * a task with `claim_task`.
24
+ * Decides whether the current caller may create, update, list, or remove watches on a board.
28
25
  * Return `true` to allow the operation; any other value denies it.
29
26
  */
30
27
  export type BoardAuthorize = (request: BoardAuthorizeRequest) => boolean | Promise<boolean>;
28
+ /** Operation passed to {@link BoardClaimAuthorize}. */
29
+ export type BoardClaimAuthorizeAction = "claim_task" | "schedule";
30
+ /** Context passed to `authorizeClaim` before claiming a board task with `claim_task` or scheduling a board check-in with `schedule`. */
31
+ export interface BoardClaimAuthorizeRequest {
32
+ /** Which operation is being requested. */
33
+ readonly action: BoardClaimAuthorizeAction;
34
+ /** The session's current caller, or `null` when the session has none. */
35
+ readonly auth: SessionAuthContext | null;
36
+ /** The board identifier: a configured board key, a discovered board ID (`brd_…`), or `"default"` for a pinned single-board mount. */
37
+ readonly board: string;
38
+ /** The board's display or configured name, when known. */
39
+ readonly boardName?: string;
40
+ /** The board's configured team, when set. */
41
+ readonly team?: string;
42
+ /** The task's or thread's channel, or the queue channel selector. */
43
+ readonly claimChannel?: string;
44
+ /** For `claim_task` by ID, the ID of the task being claimed. */
45
+ readonly taskId?: string;
46
+ }
47
+ /**
48
+ * Decides whether the current caller may claim a board task with `claim_task` or schedule a board
49
+ * check-in with `schedule`. Return `true` to allow the operation; any other value denies it.
50
+ */
51
+ export type BoardClaimAuthorize = (request: BoardClaimAuthorizeRequest) => boolean | Promise<boolean>;
@@ -274,10 +274,11 @@ async function dispatch(wake, match, record) {
274
274
  const posted = match.event.message;
275
275
  if (posted !== void 0 && coversChannel(wake.watchChannel, posted.channel)) return false;
276
276
  const idempotencyPrefix = boardKey === void 0 ? "board" : `board:${boardKey}`;
277
- const start = (message, context, idempotencyKey, task) => sendRecovering(wake.from(boardSessionAddress(record.id, message, boardKey)), boardMessageContent(message, boardKey), {
277
+ const start = (message, context, idempotencyKey, options) => sendRecovering(wake.from(boardSessionAddress(record.id, message, boardKey)), boardMessageContent(message, boardKey), {
278
278
  auth: defaultBoardAuth(message, {
279
279
  key: wake.key,
280
280
  name: wake.name,
281
+ selfSchedule: options?.selfSchedule ?? false,
281
282
  shorthand: wake.shorthand,
282
283
  watch: record.id
283
284
  }),
@@ -289,12 +290,13 @@ async function dispatch(wake, match, record) {
289
290
  noSync: message.noSync,
290
291
  threadId: boardThreadId(message),
291
292
  watch: record.id,
292
- ...task !== void 0 && { task }
293
+ ...options?.task !== void 0 && { task: options.task }
293
294
  }
294
295
  });
295
296
  if (match.event.type === "message.posted") {
296
297
  if (posted === void 0 || posted.deleted) return false;
297
- if (posted.by.actor === self.actor && posted.schedule === void 0) return false;
298
+ const selfSchedule = posted.by.actor === self.actor && posted.schedule !== void 0;
299
+ if (posted.by.actor === self.actor && !selfSchedule) return false;
298
300
  if (!boardAllows(can, posted.channel, "read")) {
299
301
  log.warn("board watch matched a channel outside the agent's read scope; skipped it", {
300
302
  ...boardKey !== void 0 && { board: boardKey },
@@ -304,7 +306,7 @@ async function dispatch(wake, match, record) {
304
306
  return false;
305
307
  }
306
308
  if (record.action.type !== "claim") {
307
- await start(posted, formatBoardContext(posted, boardKey), `${idempotencyPrefix}:${match.id}`);
309
+ await start(posted, formatBoardContext(posted, boardKey), `${idempotencyPrefix}:${match.id}`, { selfSchedule });
308
310
  return true;
309
311
  }
310
312
  if (posted.re === null) return false;
@@ -312,7 +314,7 @@ async function dispatch(wake, match, record) {
312
314
  const held = root.task?.claim;
313
315
  if (held?.actor !== self.actor || Date.parse(held.until) <= Date.now()) return false;
314
316
  if (root.labels["eve-claim-watch"] !== record.id) return false;
315
- await start(posted, formatTaskFollowUpContext(posted, boardKey), `${idempotencyPrefix}:${match.id}`);
317
+ await start(posted, formatTaskFollowUpContext(posted, boardKey), `${idempotencyPrefix}:${match.id}`, { selfSchedule });
316
318
  return true;
317
319
  }
318
320
  if (record.action.type !== "claim" || !CLAIM_EVENTS.has(match.event.type)) return false;
@@ -333,7 +335,10 @@ async function dispatch(wake, match, record) {
333
335
  }
334
336
  try {
335
337
  await deployment.label(task.id, { set: { [CLAIM_WATCH_LABEL]: record.id } });
336
- await start(task, formatTaskContext(claimed, boardKey), `${idempotencyPrefix}:task:${task.id}:${claim.epoch}`, claim);
338
+ await start(task, formatTaskContext(claimed, boardKey), `${idempotencyPrefix}:task:${task.id}:${claim.epoch}`, {
339
+ selfSchedule: false,
340
+ task: claim
341
+ });
337
342
  } catch (error) {
338
343
  await deployment.held(claim).release().catch((releaseError) => logError("board task release failed", releaseError, { task: task.id }));
339
344
  throw error;
@@ -1,4 +1,4 @@
1
- import type { BoardAuthorize } from "./authorize.ts";
1
+ import type { BoardAuthorize, BoardClaimAuthorize } from "./authorize.ts";
2
2
  import { type BoardCan, type BoardSettings } from "./client.ts";
3
3
  export declare const DEFAULT_BOARD_KEY = "default";
4
4
  export declare const DEFAULT_WATCH_CHANNEL = "eve-config/watches";
@@ -14,6 +14,7 @@ export interface ResolvedBoardConfig {
14
14
  readonly can?: BoardCan;
15
15
  readonly watchChannel: string;
16
16
  readonly authorize?: BoardAuthorize;
17
+ readonly authorizeClaim?: BoardClaimAuthorize;
17
18
  readonly routeBase: string;
18
19
  readonly registrationRouteBase: string;
19
20
  }
@@ -23,6 +24,7 @@ export interface ResolvedBoardFallback {
23
24
  readonly can?: BoardCan;
24
25
  readonly watchChannel: string;
25
26
  readonly authorize?: BoardAuthorize;
27
+ readonly authorizeClaim?: BoardClaimAuthorize;
26
28
  }
27
29
  export interface ResolvedBoardSet {
28
30
  readonly shorthand: boolean;
@@ -183,6 +183,7 @@ function resolveBoards(settings) {
183
183
  const pinnedByEnv = hasBoardUrlEnv();
184
184
  if (settings.boards === void 0 && (settings.id !== void 0 || settings.name !== void 0 || settings.url !== void 0 || pinnedByEnv)) return singleBoardSet(routeBase, {
185
185
  authorize: settings.authorize,
186
+ authorizeClaim: settings.authorizeClaim,
186
187
  can: settings.can,
187
188
  ...settings.id !== void 0 && { id: settings.id },
188
189
  ...settings.name !== void 0 && { name: settings.name },
@@ -203,6 +204,7 @@ function resolveBoards(settings) {
203
204
  const effectiveName = keyDerivedName ? key : entry.name;
204
205
  byKey.set(key, {
205
206
  authorize: entry.authorize ?? settings.authorize,
207
+ authorizeClaim: entry.authorizeClaim ?? settings.authorizeClaim,
206
208
  can: entry.can ?? settings.can,
207
209
  ...keyDerivedName && { ensure: false },
208
210
  ...entry.id !== void 0 && { id: entry.id },
@@ -218,23 +220,19 @@ function resolveBoards(settings) {
218
220
  });
219
221
  keys.push(key);
220
222
  }
221
- if (!discover && keys.length === 0) {
222
- if (pinnedByEnv && wildcard !== false) return singleBoardSet(routeBase, {
223
- authorize: wildcardObj?.authorize ?? settings.authorize,
224
- can: wildcardObj?.can ?? settings.can,
225
- profile: wildcardObj?.profile ?? settings.profile,
226
- team: wildcardObj?.team ?? settings.team,
227
- watchChannel: wildcardObj?.watchChannel ?? settings.watchChannel ?? "eve-config/watches"
228
- });
229
- throw new Error("Board extension `boards` with `\"*\": false` must configure at least one board.");
230
- }
231
- const fallback = discover ? {
223
+ const defaults = {
232
224
  authorize: wildcardObj?.authorize ?? settings.authorize,
225
+ authorizeClaim: wildcardObj?.authorizeClaim ?? settings.authorizeClaim,
233
226
  can: wildcardObj?.can ?? settings.can,
234
227
  profile: wildcardObj?.profile ?? settings.profile,
235
228
  team: wildcardObj?.team ?? settings.team,
236
229
  watchChannel: wildcardObj?.watchChannel ?? settings.watchChannel ?? "eve-config/watches"
237
- } : void 0;
230
+ };
231
+ if (!discover && keys.length === 0) {
232
+ if (pinnedByEnv && wildcard !== false) return singleBoardSet(routeBase, defaults);
233
+ throw new Error("Board extension `boards` with `\"*\": false` must configure at least one board.");
234
+ }
235
+ const fallback = discover ? defaults : void 0;
238
236
  return {
239
237
  byKey,
240
238
  ...fallback !== void 0 && { fallback },
@@ -8,5 +8,5 @@ import { type BoardChannel, type BoardChannelConfig } from "./board-channel.ts";
8
8
  * thread the board syncs. Watches are created with the `watch` tool, never by the channel.
9
9
  */
10
10
  export declare function boardChannel(config?: BoardChannelConfig): BoardChannel;
11
- export type { BoardAuthorize, BoardAuthorizeAction, BoardAuthorizeRequest } from "./authorize.ts";
11
+ export type { BoardAuthorize, BoardAuthorizeAction, BoardAuthorizeRequest, BoardClaimAuthorize, BoardClaimAuthorizeAction, BoardClaimAuthorizeRequest, } from "./authorize.ts";
12
12
  export type { BoardChannel, BoardChannelConfig, BoardChannelMetadata, BoardChannelState, BoardReceiveTarget, } from "./board-channel.ts";
@@ -224,6 +224,7 @@ export interface BoardClient {
224
224
  }): Promise<void>;
225
225
  post(channel: string, options: BoardPostOptions): Promise<BoardWrittenMessage>;
226
226
  reply(id: string, options: BoardPostOptions): Promise<BoardWrittenMessage>;
227
+ edit(id: string, text: string): Promise<void>;
227
228
  upload(file: {
228
229
  readonly data: Uint8Array;
229
230
  readonly name: string;
@@ -208,6 +208,9 @@ function createBoardClient(board, can) {
208
208
  },
209
209
  post: async (channel, post) => writtenOf(await handle.post(channel, postOf(post))),
210
210
  reply: async (id, post) => writtenOf(await handle.reply(id, postOf(post))),
211
+ async edit(id, text) {
212
+ await handle.edit(id, text);
213
+ },
211
214
  upload: async (file) => await handle.upload({
212
215
  data: file.data,
213
216
  name: file.name,
@@ -6,6 +6,7 @@ export declare function boardSessionAddress(watch: string, message: Pick<BoardMe
6
6
  export declare function defaultBoardAuth(message: BoardMessage, board: {
7
7
  readonly key?: string;
8
8
  readonly name?: string;
9
+ readonly selfSchedule?: boolean;
9
10
  readonly shorthand?: boolean;
10
11
  readonly watch?: string;
11
12
  }): SessionAuthContext;
@@ -25,6 +25,8 @@ function defaultBoardAuth(message, board) {
25
25
  message_id: message.id,
26
26
  principal: message.by.principal,
27
27
  ...message.by.profile !== null && { profile: message.by.profile },
28
+ ...message.schedule !== void 0 && { schedule_id: message.schedule.id },
29
+ ...board.selfSchedule === true && { self_schedule: "true" },
28
30
  thread_id: boardThreadId(message),
29
31
  ...board.watch !== void 0 && { watch: board.watch }
30
32
  },
@@ -585,9 +585,10 @@ export declare function defineBoardReleaseTaskTool(settings?: Settings): import(
585
585
  task: string;
586
586
  }>;
587
587
  };
588
- /** Creates a watch: the board wakes the agent with these instructions when a message matches. */
588
+ /** Creates a watch, or updates an existing watch in place when `id` is provided. */
589
589
  export declare function defineBoardWatchTool(settings: Settings): import("eve/tools").ToolDefinition<{
590
590
  board?: string | undefined;
591
+ id?: string | undefined;
591
592
  channel: string;
592
593
  label?: string[] | undefined;
593
594
  by?: string | undefined;
@@ -7,7 +7,7 @@ __eveCreateRequire(import.meta.url);
7
7
  import { listAccessibleBoards, matchesBoard, resolveBoards, selectBoardAsync } from "./boards.mjs";
8
8
  import { CLAIM_LEASE_SECONDS, CLAIM_WATCH_LABEL, clearSessionClaim, readSessionClaim, settleClaim, stopClaimRenewal, writeSessionClaim } from "./claims.mjs";
9
9
  import { BOARD_HOLD_KIND_PATTERN, BOARD_NAME_PATTERN, BOARD_TASK_NOTE_LIMIT, BOARD_TASK_STATES, BOARD_TEXT_LIMIT, boardAllows, boardErrorCode, boardPostId } from "./client.mjs";
10
- import { boardClients, checkQueueScope, checkWatchScope, coversChannel, createWatch, listWatches, removeWatch, tailOf, watchIdOf } from "./watches.mjs";
10
+ import { boardClients, checkQueueScope, checkWatchScope, coversChannel, createWatch, listWatches, removeWatch, tailOf, updateWatch, watchIdOf } from "./watches.mjs";
11
11
  import { authorOf } from "./inbound.mjs";
12
12
  import { z } from "zod";
13
13
  import { createLogger } from "eve/internal/channels";
@@ -380,8 +380,18 @@ function defineBoardScheduleTool(settings) {
380
380
  sync: z.boolean().optional().describe("Also post it to the thread's synced platforms, such as Slack.")
381
381
  }),
382
382
  async execute({ board: boardKey, id, sync, ...timing }, ctx) {
383
- const { board: resolved, client: board } = await clientFor(settings, boardKey, ctx);
384
- const schedule = await board.schedule({ re: threadOrCurrent(id, ctx, resolved) }, {
383
+ const resolved = await targetBoard(settings, boardKey, ctx, { needsMetadata: true });
384
+ const re = threadOrCurrent(id, ctx, resolved);
385
+ const board = boardClients(resolved).model;
386
+ let claimChannel;
387
+ if (id === void 0) claimChannel = boardMetadata(ctx).boardChannel ?? void 0;
388
+ else if (resolved.authorizeClaim !== void 0) claimChannel = (await board.thread(id, { limit: 1 })).message.channel;
389
+ const denial = await authorizationDenial(resolved, ctx, {
390
+ ...claimChannel !== void 0 && { details: { claimChannel } },
391
+ kind: "schedule"
392
+ });
393
+ if (denial !== void 0) throw new Error(denial);
394
+ const schedule = await board.schedule({ re }, {
385
395
  ...timing,
386
396
  noSync: sync !== true
387
397
  });
@@ -509,46 +519,80 @@ function defineBoardReleaseTaskTool(settings = defaultSettings) {
509
519
  });
510
520
  }
511
521
  const log = createLogger("board.tools");
512
- async function watchAuthorizationDenial(board, action, ctx, details = {}) {
522
+ const TRUSTED_CLAIM_ACTOR_KINDS = new Set([
523
+ "person",
524
+ "agent",
525
+ "deployment"
526
+ ]);
527
+ async function authorizationDenial(board, ctx, policy) {
513
528
  const caller = ctx.session.auth?.current ?? null;
514
- const claiming = action === "claim_task";
515
- const denied = claiming ? "You are not authorized to claim board tasks on this agent." : "You are not authorized to manage board watches on this agent.";
516
- const what = claiming ? "claim board tasks with this agent" : "change this agent's board watches";
517
- if (board.authorize !== void 0) try {
529
+ const denied = policy.kind === "watch" ? "You are not authorized to manage board watches on this agent." : policy.kind === "schedule" ? "You are not authorized to schedule board check-ins on this agent." : "You are not authorized to claim board tasks on this agent.";
530
+ const baseRequest = {
531
+ auth: caller,
532
+ board: board.key,
533
+ ...board.name !== void 0 && { boardName: board.name },
534
+ ...board.team !== void 0 && { team: board.team }
535
+ };
536
+ if (policy.kind === "watch" && board.authorize !== void 0) try {
518
537
  return await board.authorize({
519
- action,
520
- auth: caller,
521
- board: board.key,
522
- ...board.name !== void 0 && { boardName: board.name },
523
- ...board.team !== void 0 && { team: board.team },
524
- ...details.channel !== void 0 && { channel: details.channel },
525
- ...details.claimChannel !== void 0 && { claimChannel: details.claimChannel },
526
- ...details.watchId !== void 0 && { watchId: details.watchId },
527
- ...details.taskId !== void 0 && { taskId: details.taskId }
538
+ ...baseRequest,
539
+ action: policy.action,
540
+ ...policy.details
528
541
  }) === true ? void 0 : denied;
529
542
  } catch (error) {
530
543
  log.error("board authorization callback failed", {
531
- action,
544
+ action: policy.action,
532
545
  board: board.key,
533
546
  error,
534
547
  errorId: crypto.randomUUID()
535
548
  });
536
549
  return denied;
537
550
  }
538
- if (caller === null || caller.principalType === "anonymous") return claiming ? "Only a signed-in person or an agent schedule may claim board tasks with this agent. Ask from a channel where you're signed in." : "Only a signed-in person may change this agent's board watches. Ask from a channel where you're signed in.";
551
+ if (policy.kind !== "watch" && board.authorizeClaim !== void 0) {
552
+ const action = policy.kind === "schedule" ? "schedule" : "claim_task";
553
+ try {
554
+ return await board.authorizeClaim({
555
+ ...baseRequest,
556
+ action,
557
+ ...policy.details
558
+ }) === true ? void 0 : denied;
559
+ } catch (error) {
560
+ log.error("board claim authorization callback failed", {
561
+ action,
562
+ board: board.key,
563
+ error,
564
+ errorId: crypto.randomUUID()
565
+ });
566
+ return denied;
567
+ }
568
+ }
569
+ if (caller === null || caller.principalType === "anonymous") {
570
+ if (policy.kind === "watch") return "Only a signed-in person may change this agent's board watches. Ask from a channel where you're signed in.";
571
+ return `Only a signed-in caller, an agent schedule, or an internal board watch may ${policy.kind === "schedule" ? "schedule board check-ins" : "claim board tasks"} with this agent. Ask from a channel where you're signed in.`;
572
+ }
539
573
  if (caller.authenticator === "board-watcher") {
540
- if (caller.attributes.actor_kind !== "person") return `Only a person on the team may ${what}, not a synced platform user or another agent.`;
574
+ if (policy.kind === "watch") {
575
+ 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.";
576
+ } else {
577
+ const actorKind = caller.attributes.actor_kind;
578
+ const selfSchedule = caller.attributes.self_schedule === "true";
579
+ if (!(typeof actorKind === "string" && TRUSTED_CLAIM_ACTOR_KINDS.has(actorKind)) && !selfSchedule) return `Only a team member, agent, deployment, or this agent's own scheduled check-in may ${policy.kind === "schedule" ? "schedule board check-ins" : "claim board tasks"} from a board watch, not a synced external user, CI workflow, or unrecognized board actor. Configure \`authorizeClaim\` to allow other board actors.`;
580
+ }
541
581
  const callerBoard = typeof caller.attributes.board_key === "string" ? caller.attributes.board_key : void 0;
542
- if (callerBoard !== void 0 && !matchesBoard(board, callerBoard) || callerBoard === void 0 && !board.shorthand) return claiming ? "Board callers may only claim tasks on their own board. Configure `authorize` to allow it across boards." : "Board callers may only manage watches on their own board. Configure `authorize` to allow cross-board watch management.";
582
+ if (callerBoard !== void 0 && !matchesBoard(board, callerBoard) || callerBoard === void 0 && !board.shorthand) {
583
+ if (policy.kind === "watch") return "Board callers may only manage watches on their own board. Configure `authorize` to allow cross-board watch management.";
584
+ return `Board callers may only ${policy.kind === "schedule" ? "schedule check-ins" : "claim tasks"} on their own board. Configure \`authorizeClaim\` to allow it across boards.`;
585
+ }
543
586
  }
544
587
  }
545
- async function assertWatchAuthorized(board, action, ctx, details = {}) {
546
- const denial = await watchAuthorizationDenial(board, action, ctx, details);
547
- if (denial !== void 0) throw new Error(denial);
548
- }
549
- async function authorizingWatch(settings, board, action, ctx, details = {}) {
588
+ async function authorizingWatch(settings, board, action, ctx, details) {
550
589
  const resolved = await targetBoard(settings, board, ctx, { needsMetadata: true });
551
- await assertWatchAuthorized(resolved, action, ctx, details);
590
+ const denial = await authorizationDenial(resolved, ctx, {
591
+ action,
592
+ details,
593
+ kind: "watch"
594
+ });
595
+ if (denial !== void 0) throw new Error(denial);
552
596
  return {
553
597
  config: resolved,
554
598
  ...boardClients(resolved)
@@ -563,9 +607,10 @@ function defineBoardWatchTool(settings) {
563
607
  return defineTool({
564
608
  approval: always(),
565
609
  deferred: true,
566
- 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.",
610
+ description: "Create or update a board watch: 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. Pass `id` to replace an existing watch's full definition in place (preserving its ID and thread sessions) instead of creating a new one and unwatching the old one: inspect existing settings with `watches({ details: true })` first and include any `label`, `by`, `text`, or `claim` fields you want to keep. 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 applied. Keep it as narrow as the request. Returns the watch's ID.",
567
611
  inputSchema: z.object({
568
612
  board: boardOption,
613
+ id: z.string().regex(BOARD_NAME_PATTERN).optional().describe("An existing watch's ID (such as `w-7k3p2q`) to replace its full definition in place (include any `label`, `by`, `text`, or `claim` fields to keep); omit to create a new watch."),
569
614
  channel: z.string().min(1).max(200).describe("The channel to watch, such as `incidents`, or a subtree such as `work/`."),
570
615
  label: z.array(z.string().min(1).max(200)).max(10).optional().describe("Labels a message must have: `key`, or `key=value`."),
571
616
  by: z.string().min(1).max(200).optional().describe("Only messages by this handle, such as `@ada`."),
@@ -573,10 +618,11 @@ function defineBoardWatchTool(settings) {
573
618
  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."),
574
619
  claim: queue.optional()
575
620
  }),
576
- async execute({ board: boardKey, instructions, claim, ...filter }, ctx) {
621
+ async execute({ board: boardKey, id, instructions, claim, ...filter }, ctx) {
577
622
  const { config, deployment, watchChannel } = await authorizingWatch(settings, boardKey, "watch", ctx, {
578
623
  channel: filter.channel,
579
- ...claim !== void 0 && { claimChannel: claim.channel }
624
+ ...claim !== void 0 && { claimChannel: claim.channel },
625
+ ...id !== void 0 && { watchId: id }
580
626
  });
581
627
  const action = claim === void 0 ? { type: "converse" } : {
582
628
  queue: claim,
@@ -588,16 +634,17 @@ function defineBoardWatchTool(settings) {
588
634
  channel: filter.channel,
589
635
  watchChannel
590
636
  });
591
- const watch = await createWatch({
637
+ const input = {
592
638
  action,
593
639
  boardKey: config.key,
594
640
  client: deployment,
595
- id: watchIdOf(ctx.session.id, ctx.callId),
641
+ id: id ?? watchIdOf(ctx.session.id, ctx.callId),
596
642
  instructions,
597
643
  routeBase: config.registrationRouteBase,
598
644
  tail: tailOf(filter),
599
645
  watchChannel
600
- });
646
+ };
647
+ const watch = await (id !== void 0 ? updateWatch(input) : createWatch(input));
601
648
  return config.shorthand ? {
602
649
  action: watch.action,
603
650
  id: watch.id,
@@ -636,7 +683,10 @@ function defineBoardWatchesTool(settings) {
636
683
  };
637
684
  }
638
685
  const checked = await Promise.all([...set.byKey.values()].map(async (entry) => ({
639
- denial: await watchAuthorizationDenial(entry, "watches", ctx),
686
+ denial: await authorizationDenial(entry, ctx, {
687
+ action: "watches",
688
+ kind: "watch"
689
+ }),
640
690
  entry
641
691
  })));
642
692
  const permitted = checked.filter((result) => result.denial === void 0).map((result) => result.entry);
@@ -749,10 +799,14 @@ function defineBoardClaimTaskTool(settings) {
749
799
  const { message } = await model.thread(id, { limit: 1 });
750
800
  claimChannel = message.channel;
751
801
  }
752
- await assertWatchAuthorized(resolved, "claim_task", ctx, {
753
- ...claimChannel !== void 0 && { claimChannel },
754
- ...id !== void 0 && { taskId: id }
802
+ const denial = await authorizationDenial(resolved, ctx, {
803
+ details: {
804
+ ...claimChannel !== void 0 && { claimChannel },
805
+ ...id !== void 0 && { taskId: id }
806
+ },
807
+ kind: "claim"
755
808
  });
809
+ if (denial !== void 0) throw new Error(denial);
756
810
  if (channel !== void 0) checkQueueScope({
757
811
  channel,
758
812
  from,
@@ -70,7 +70,7 @@ export declare function findWatchRecord(input: {
70
70
  }): Promise<BoardWatchRecord>;
71
71
  export declare function registrationWhere(discovery: Pick<BoardDiscovery, "wake_by_path">, routeBase?: string): Omit<BoardRegistrationInput, "watch">;
72
72
  export declare function heldRegistration(client: BoardClient): Promise<BoardRegistration | undefined>;
73
- export declare function createWatch(input: {
73
+ export interface BoardWatchWriteInput {
74
74
  readonly boardKey?: string;
75
75
  readonly client: BoardClient;
76
76
  readonly watchChannel: string;
@@ -79,7 +79,9 @@ export declare function createWatch(input: {
79
79
  readonly instructions: string;
80
80
  readonly action: BoardWatchAction;
81
81
  readonly routeBase?: string;
82
- }): Promise<BoardWatch>;
82
+ }
83
+ export declare function createWatch(input: BoardWatchWriteInput): Promise<BoardWatch>;
84
+ export declare function updateWatch(input: BoardWatchWriteInput): Promise<BoardWatch>;
83
85
  export declare function listWatches(input: {
84
86
  readonly client: BoardClient;
85
87
  readonly watchChannel: string;
@@ -213,37 +213,42 @@ function registrationDestinationChanged(held, desired) {
213
213
  if (held === void 0) return false;
214
214
  return (held.path ?? null) !== (desired.path ?? null) || (held.branch ?? null) !== (desired.branch ?? null) || (held.url ?? null) !== (desired.url ?? null);
215
215
  }
216
- async function updateRegistration(input) {
216
+ async function writeRegistration(input) {
217
217
  const { client } = input;
218
- return await withRegistrationLock(client, input.watchChannel, input.boardKey ?? "default", async () => {
219
- const held = await heldRegistration(client);
220
- const watch = { ...held?.watch };
221
- const watchChanged = input.change(watch);
222
- const desired = isVercelDeployment() ? registrationWhere(await client.discovery(), input.routeBase) : void 0;
223
- const destinationChanged = desired !== void 0 && registrationDestinationChanged(held, desired);
224
- if (!watchChanged && !destinationChanged) return held;
225
- const where = desired ?? (held !== void 0 ? {
226
- branch: held.branch ?? null,
227
- path: held.path ?? null,
228
- url: held.url ?? null
229
- } : registrationWhere(await client.discovery(), input.routeBase));
230
- try {
231
- return await client.register({
232
- ...where,
233
- ...held?.sync !== void 0 && { sync: held.sync },
234
- watch
235
- });
236
- } catch (error) {
237
- if (boardErrorCode(error) !== "watchers_need_project") throw error;
238
- throw new Error("Vercel's board takes watches only from a deployment. To try watches locally, run `npx @vercel/board serve` and set BOARD_URL to the URL it prints.", { cause: error });
239
- }
240
- });
218
+ const held = "held" in input ? input.held : await heldRegistration(client);
219
+ const watch = { ...held?.watch };
220
+ const watchChanged = input.change(watch);
221
+ const desired = isVercelDeployment() ? registrationWhere(await client.discovery(), input.routeBase) : void 0;
222
+ const destinationChanged = desired !== void 0 && registrationDestinationChanged(held, desired);
223
+ if (!watchChanged && !destinationChanged) return held;
224
+ const where = desired ?? (held !== void 0 ? {
225
+ branch: held.branch ?? null,
226
+ path: held.path ?? null,
227
+ url: held.url ?? null
228
+ } : registrationWhere(await client.discovery(), input.routeBase));
229
+ try {
230
+ return await client.register({
231
+ ...where,
232
+ ...held?.sync !== void 0 && { sync: held.sync },
233
+ watch
234
+ });
235
+ } catch (error) {
236
+ if (boardErrorCode(error) !== "watchers_need_project") throw error;
237
+ throw new Error("Vercel's board takes watches only from a deployment. To try watches locally, run `npx @vercel/board serve` and set BOARD_URL to the URL it prints.", { cause: error });
238
+ }
241
239
  }
242
- async function createWatch(input) {
243
- const { action, client, id, tail } = input;
244
- const text = watchRecordText(id, action, input.instructions);
240
+ async function updateRegistration(input) {
241
+ return await withRegistrationLock(input.client, input.watchChannel, input.boardKey ?? "default", () => writeRegistration(input));
242
+ }
243
+ function watchContent(id, action, instructions, tail) {
244
+ const text = watchRecordText(id, action, instructions);
245
245
  if (text.length > 1e4) throw new Error(`These watch instructions are too long to store: shorten them by ${text.length - BOARD_TEXT_LIMIT} characters.`);
246
246
  if (tail.length > 1e3) throw new Error(`This watch's filters are too long for the board: shorten them by ${tail.length - BOARD_TAIL_LIMIT} characters.`);
247
+ return text;
248
+ }
249
+ async function createWatch(input) {
250
+ const { action, client, id, tail } = input;
251
+ const text = watchContent(id, action, input.instructions, tail);
247
252
  const held = await heldRegistration(client);
248
253
  if (held?.watch[id] === void 0 && Object.keys(held?.watch ?? {}).length >= 64) throw tooManyWatches();
249
254
  const record = await client.post(input.watchChannel, {
@@ -276,6 +281,52 @@ async function createWatch(input) {
276
281
  tail
277
282
  };
278
283
  }
284
+ async function updateWatch(input) {
285
+ const { action, client, id, tail } = input;
286
+ assertWatchId(id);
287
+ const text = watchContent(id, action, input.instructions, tail);
288
+ return await withRegistrationLock(client, input.watchChannel, input.boardKey ?? "default", async () => {
289
+ const [held, self] = await Promise.all([heldRegistration(client), client.me()]);
290
+ if (held?.watch[id] === void 0) throw new Error(`Board watch ${id} doesn't exist on this board. Omit \`id\` to create a new watch, or call \`watches\` to list existing ones.`);
291
+ let existing;
292
+ try {
293
+ existing = await findWatchRecord({
294
+ client,
295
+ id,
296
+ self,
297
+ watchChannel: input.watchChannel
298
+ });
299
+ } catch (error) {
300
+ if (error instanceof BoardWatchConfigError) throw new Error(`Board watch ${id} has no editable instructions (${error.message}). Remove it with \`unwatch\` and omit \`id\` to create a new watch.`, { cause: error });
301
+ throw error;
302
+ }
303
+ if (existing.retired) throw new Error(`Board watch ${id} is retired and can't be updated. Remove it with \`unwatch\` and omit \`id\` to create a new watch.`);
304
+ const previousText = existing.message.text;
305
+ const textChanged = previousText !== text;
306
+ if (textChanged) await client.edit(existing.message.id, text);
307
+ try {
308
+ await writeRegistration({
309
+ client,
310
+ held,
311
+ routeBase: input.routeBase,
312
+ change(watch) {
313
+ if (watch[id]?.tail === tail) return false;
314
+ watch[id] = { tail };
315
+ return true;
316
+ }
317
+ });
318
+ } catch (error) {
319
+ if (textChanged) await client.edit(existing.message.id, previousText).catch(() => void 0);
320
+ throw error;
321
+ }
322
+ return {
323
+ action,
324
+ id,
325
+ instructions: input.instructions,
326
+ tail
327
+ };
328
+ });
329
+ }
279
330
  function tooManyWatches() {
280
331
  return new Error(`This agent already has 64 board watches, the most one deployment can register. Remove one first.`);
281
332
  }
@@ -341,4 +392,4 @@ async function removeWatch(input) {
341
392
  removed
342
393
  };
343
394
  }
344
- export { BOARD_WAKE_ROUTE, BoardWatchConfigError, DEFAULT_BOARD_ROUTE_BASE, DEFAULT_WATCH_CHANNEL, LEGACY_BOARD_WAKE_ROUTE, MAX_WATCHES, assertWatchId, boardClients, checkQueueScope, checkWatchScope, coversChannel, createWatch, findWatchRecord, heldRegistration, listWatches, registrationWhere, removeWatch, tailOf, watchIdOf, watchRecordText };
395
+ export { BOARD_WAKE_ROUTE, BoardWatchConfigError, DEFAULT_BOARD_ROUTE_BASE, DEFAULT_WATCH_CHANNEL, LEGACY_BOARD_WAKE_ROUTE, MAX_WATCHES, assertWatchId, boardClients, checkQueueScope, checkWatchScope, coversChannel, createWatch, findWatchRecord, heldRegistration, listWatches, registrationWhere, removeWatch, tailOf, updateWatch, watchIdOf, watchRecordText };
@@ -44,7 +44,7 @@ You wake only for your watches. When someone asks you to keep an eye on a channe
44
44
 
45
45
  Both `watch` and `unwatch` ask the caller to approve the exact parameters before applying the change. Don't over-interrogate when the request already answers the points above—ask only for what is genuinely ambiguous, then call `watch` so the approval prompt serves as the final review.
46
46
 
47
- Tell the person the watch's ID once created. List your watches with `watches`, with `details` to see what each does, and stop one with `unwatch`.
47
+ Tell the person the watch's ID once created. List your watches with `watches`, with `details` to see what each does, pass `id` to `watch` to update an existing watch in place (preserving its ID and thread sessions) instead of unwatching and recreating it—`watch` with `id` replaces the full watch definition, so inspect existing settings with `watches({ details: true })` and include any `label`, `by`, `text`, or `claim` fields to keep—and stop one with `unwatch`.
48
48
 
49
49
  ## Come back later
50
50
 
@@ -1,6 +1,7 @@
1
- /** Creates a board watch: matching events wake the agent with the watch's instructions. */
1
+ /** Creates a board watch, or updates an existing watch in place when `id` is provided. */
2
2
  declare const _default: import("eve/tools").ToolDefinition<{
3
3
  board?: string | undefined;
4
+ id?: string | undefined;
4
5
  channel: string;
5
6
  label?: string[] | undefined;
6
7
  by?: string | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eve/board",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Vercel Board for eve agents: a channel that wakes the agent for watches it manages with tools, claims tasks, and replies in board threads",
5
5
  "keywords": [
6
6
  "eve",
@@ -49,7 +49,7 @@
49
49
  },
50
50
  "devDependencies": {
51
51
  "@types/node": "26.6.6",
52
- "eve": "1.8.0",
52
+ "eve": "1.9.0",
53
53
  "typescript": "7.0.2"
54
54
  },
55
55
  "peerDependencies": {