@vercel/board 0.57.0 → 0.58.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 (76) hide show
  1. package/README.md +1 -1
  2. package/dist/{access-CIj7v_Dr.mjs → access-D1AHzFSP.mjs} +1 -1
  3. package/dist/access.d.mts +2 -2
  4. package/dist/access.mjs +4 -4
  5. package/dist/{actors-DVDTqjm7.mjs → actors-CCth21rU.mjs} +2 -2
  6. package/dist/{auth-BDWGvFWl.mjs → auth-Cc5_pdi7.mjs} +2 -2
  7. package/dist/{auth-C0Mla9OU.d.mts → auth-DcWTzrHz.d.mts} +1 -1
  8. package/dist/{backend-BuqwQbb4.d.mts → backend-9H57DlQt.d.mts} +23 -5
  9. package/dist/backend-local.d.mts +1 -1
  10. package/dist/backend-local.mjs +1 -1
  11. package/dist/backend-postgres/blob-vercel.d.mts +1 -1
  12. package/dist/backend-postgres.d.mts +3 -3
  13. package/dist/backend-postgres.mjs +3 -3
  14. package/dist/{blob-DjS53D1A.d.mts → blob-CdLCZEPM.d.mts} +2 -2
  15. package/dist/{chat-provider-CpYdXEpI.d.mts → chat-provider-BiJ8G6KY.d.mts} +2 -2
  16. package/dist/cli-commands.d.mts +1 -1
  17. package/dist/cli-commands.mjs +1 -1
  18. package/dist/cli-embedded.d.mts +2 -2
  19. package/dist/cli-embedded.mjs +2 -2
  20. package/dist/cli.mjs +6 -6
  21. package/dist/{client-B0DGOt7P.d.mts → client-BUPyzzFt.d.mts} +13 -1
  22. package/dist/{commands-DLPIX7Jw.d.mts → commands-DryDbyWr.d.mts} +8 -3
  23. package/dist/{commands-7FY_8p92.mjs → commands-totPnoCC.mjs} +81 -23
  24. package/dist/{conformance-FiQ68adg.mjs → conformance-D9XutDay.mjs} +2 -2
  25. package/dist/conformance.d.mts +1 -1
  26. package/dist/conformance.mjs +1 -1
  27. package/dist/{engine-B_CjnE3G.mjs → engine-DVWbcEIB.mjs} +2 -2
  28. package/dist/{errors-BfMR39F0.mjs → errors-Ce_-E3_C.mjs} +210 -2
  29. package/dist/{errors-DBZtbfph.d.mts → errors-CwObkpSn.d.mts} +1 -1
  30. package/dist/{exports-BvJTIorX.d.mts → exports-Bh09j6Bd.d.mts} +5 -5
  31. package/dist/{exports-x-ioAfbp.mjs → exports-WtqjdQwb.mjs} +256 -57
  32. package/dist/{index-DuibwQf9.d.mts → index-mgNwCwJ4.d.mts} +2 -2
  33. package/dist/index.d.mts +7 -7
  34. package/dist/index.mjs +4 -4
  35. package/dist/index.node.d.mts +8 -8
  36. package/dist/index.node.mjs +4 -4
  37. package/dist/inspect/app.js +126 -146
  38. package/dist/inspect/engine.js +3 -3
  39. package/dist/inspect/sheet-presentation.js +1 -0
  40. package/dist/{inspect-BFnDSdsq.mjs → inspect-CtPZz0WG.mjs} +2 -2
  41. package/dist/inspect-wkA_8iyU.mjs +2 -0
  42. package/dist/inspect.d.mts +1 -1
  43. package/dist/inspect.mjs +1 -1
  44. package/dist/{local-Bt1-jA9A.mjs → local-B7Yp-B2z.mjs} +30 -8
  45. package/dist/{local-Gp8pqHSu.mjs → local-BPiDCkA4.mjs} +5 -5
  46. package/dist/{main-Du-mKQZn.mjs → main-BvkLqpUX.mjs} +223 -52
  47. package/dist/{memory-74hyK6eH.mjs → memory-BmsyKyHu.mjs} +1 -1
  48. package/dist/{middleware-bIABV895.mjs → middleware-DVBOEd8G.mjs} +2 -32
  49. package/dist/{provider-BNVyVKtH.d.mts → provider-BnK0Bif7.d.mts} +2 -2
  50. package/dist/{routes-CSnxZyyb.d.mts → routes-D5FtKOP_.d.mts} +87 -1
  51. package/dist/{serve-xOoxwq7T.mjs → serve-ChlJ955x.mjs} +6 -6
  52. package/dist/{server-BSexF7Bk.mjs → server-CRdVLqny.mjs} +25 -10
  53. package/dist/{serving-ByD4TOOU.mjs → serving-BVtrFzK4.mjs} +1 -1
  54. package/dist/{shell-0nWQEqh3.mjs → shell-hTUuAc6A.mjs} +11 -7
  55. package/dist/{sqlite-DtfrT_EP.mjs → sqlite-B9ZLSDUT.mjs} +1 -1
  56. package/dist/{sqlite-db-DSVlzQjv.mjs → sqlite-db-DawFxCk6.mjs} +20 -5
  57. package/dist/sync-chat-sdk.d.mts +2 -2
  58. package/dist/sync-github.d.mts +2 -2
  59. package/dist/sync-linear.d.mts +3 -3
  60. package/dist/sync-slack.d.mts +3 -3
  61. package/dist/sync.d.mts +2 -2
  62. package/dist/{task-batch-DgyfK9qx.mjs → task-batch-CnRhVsh6.mjs} +7 -4
  63. package/dist/{tokens-_1X8JNLT.mjs → tokens-XagdeYrv.mjs} +2 -2
  64. package/dist/{version-CZT5WmZs.mjs → version-rlZkE9nc.mjs} +1 -1
  65. package/docs/01-board/01-mounting.md +9 -0
  66. package/docs/01-board/05-reading.md +2 -1
  67. package/docs/01-board/09-access.md +8 -4
  68. package/docs/01-board/11-tasks.md +7 -2
  69. package/docs/01-board/12-postgres.md +3 -3
  70. package/docs/02-sync/01-overview.md +4 -0
  71. package/docs/02-sync/05-managed.md +117 -0
  72. package/docs/03-guides/02-inspector.md +1 -1
  73. package/docs/04-reference/01-cli.md +44 -2
  74. package/docs/04-reference/03-http.md +5 -0
  75. package/package.json +2 -2
  76. package/dist/inspect-BuNsu2z6.mjs +0 -2
@@ -1,17 +1,17 @@
1
- import { a as DIRECT_UPLOAD_BYTES_MAX, l as fileSize } from "./profile-header-O8wC8yk8.mjs";
1
+ import { a as DIRECT_UPLOAD_BYTES_MAX, f as typeOf, l as fileSize } from "./profile-header-O8wC8yk8.mjs";
2
2
  import { m as MESSAGE_TEXT_MAX, r as AttachmentId } from "./schemas-CUSTEFIy.mjs";
3
- import { f as BoardError } from "./errors-BfMR39F0.mjs";
3
+ import { f as BoardError } from "./errors-Ce_-E3_C.mjs";
4
4
  import { n as displayEmoji, r as normalizeEmoji } from "./emoji-CTLpvH-A.mjs";
5
- import { l as shownName } from "./middleware-bIABV895.mjs";
6
5
  import { d as parseSchemaId, r as findBlocks, t as block } from "./blocks-CVoBC7ur.mjs";
7
6
  import { n as isEmail, s as replaceMentions, t as extractMentions } from "./mentions-DBGmqkr2.mjs";
8
- import { t as VERSION } from "./version-CZT5WmZs.mjs";
9
- import { r as PERMISSIONS } from "./access-CIj7v_Dr.mjs";
10
- import { c as mentionValue, l as withMentions } from "./task-batch-DgyfK9qx.mjs";
11
- import { a as isBoardName, l as isApiMessageId, n as createTasksInChunks, s as apiThreadRoot, t as TasksInChunksError } from "./exports-x-ioAfbp.mjs";
12
- import { i as groups, n as filters$1, o as options, r as globalOptions, s as usage$1, t as commands } from "./commands-7FY_8p92.mjs";
13
- import { _ as vercelProjectFile, a as vercel, c as boardUrl, d as environmentProfile, f as handFetch, i as handTeam, l as configDir, m as handToken, n as credentialSource, o as http, p as handLogin, r as credentialed, t as board, u as connect } from "./server-BSexF7Bk.mjs";
14
- import { n as everyChannel, t as conformance } from "./conformance-FiQ68adg.mjs";
7
+ import { l as shownName } from "./middleware-DVBOEd8G.mjs";
8
+ import { t as VERSION } from "./version-rlZkE9nc.mjs";
9
+ import { r as PERMISSIONS } from "./access-D1AHzFSP.mjs";
10
+ import { c as mentionValue, l as withMentions } from "./task-batch-CnRhVsh6.mjs";
11
+ import { a as isBoardName, l as isApiMessageId, n as createTasksInChunks, s as apiThreadRoot, t as TasksInChunksError } from "./exports-WtqjdQwb.mjs";
12
+ import { i as groups, n as filters$1, o as options, r as globalOptions, s as usage$1, t as commands } from "./commands-totPnoCC.mjs";
13
+ import { a as handTeam, d as connect, f as environmentProfile, h as handToken, i as handProgram, l as boardUrl, m as handLogin, n as credentialSource, o as vercel, p as handFetch, r as credentialed, s as http, t as board, u as configDir, v as vercelProjectFile } from "./server-CRdVLqny.mjs";
14
+ import { n as everyChannel, t as conformance } from "./conformance-D9XutDay.mjs";
15
15
  import { n as displayText, t as byVercelBot } from "./bots-CqPYxkqK.mjs";
16
16
  import { spawn } from "node:child_process";
17
17
  import { createHash, randomUUID } from "node:crypto";
@@ -58,7 +58,7 @@ function principalsIn(tokens, prefixes, removal) {
58
58
  const prefix = prefixes.find((candidate) => KINDS.includes(name.slice(candidate.length)) && name.startsWith(candidate));
59
59
  if (prefix !== void 0) {
60
60
  const kind = name.slice(prefix.length);
61
- if (kind === "github" && !/^[^/\s]+\/[^/\s]+$/.test(value ?? "")) throw new GrantMisuse(`--${name} takes owner/repo, like acme/web: got ${value}.`);
61
+ if (kind === "github" && !/^([^/\s]+\/[^/\s]+|\d+)$/.test(value ?? "")) throw new GrantMisuse(`--${name} takes owner/repo or the repository's ID, like acme/web or 700001: got ${value}.`);
62
62
  started.push({
63
63
  prefix,
64
64
  kind,
@@ -587,6 +587,20 @@ const until = (iso, now) => {
587
587
  if (ms <= 0) return "due";
588
588
  return `in ${span(ms < 6e4 ? Math.ceil(ms / 1e3) * 1e3 : Math.ceil(ms / 6e4) * 6e4)}`;
589
589
  };
590
+ /**
591
+ * A sync the board runs itself: its ID, its channel, and what it syncs with, as the command that
592
+ * made it says it. One that isn't running says so last, and why.
593
+ */
594
+ function formatManagedSync(sync) {
595
+ const what = sync.slack ? `${sync.slack.app}:${sync.slack.name ? `#${sync.slack.name}` : sync.slack.channel}` : sync.source;
596
+ const held = sync.state === "active" ? [] : [sync.reason ? `${sync.state}: ${sync.reason}` : sync.state];
597
+ return [
598
+ sync.id,
599
+ sync.channel,
600
+ what,
601
+ ...held
602
+ ].join(" ");
603
+ }
590
604
  /** One schedule: what it sends, when, where, and how it stops. */
591
605
  function formatSchedule(schedule, options = {}) {
592
606
  const now = options.now ?? Date.now();
@@ -1791,23 +1805,34 @@ function labelPairs(values, wrong = "Labels look like key=value, and {value} isn
1791
1805
  return pairs;
1792
1806
  }
1793
1807
  /**
1794
- * A post or reply takes one text. What follows it was meant to be part of the message, or a label,
1808
+ * A post, reply, edit, or schedule takes one text. What follows it was meant to be part of the message, or a label,
1795
1809
  * and would be dropped without a word: say so, and how each is written.
1796
1810
  */
1797
1811
  function oneText(command, target, extra) {
1798
1812
  const [first] = extra;
1799
1813
  if (first === void 0) return;
1800
- if (/^[\w.-]+=/.test(first)) throw usage(`${first} looks like a label, and ${command} takes labels with --label.`, { next: [{
1801
- instruction: "Label it as you post it",
1802
- argv: [
1803
- ...cli(),
1804
- command,
1805
- target,
1806
- "<TEXT>",
1807
- "--label",
1808
- first
1809
- ]
1810
- }] });
1814
+ if (/^[\w.-]+=/.test(first)) {
1815
+ if (command === "edit") throw usage(`${first} looks like a label, and edit changes only the text.`, { next: [{
1816
+ instruction: "Label the message",
1817
+ argv: [
1818
+ ...cli(),
1819
+ "label",
1820
+ target,
1821
+ first
1822
+ ]
1823
+ }] });
1824
+ throw usage(`${first} looks like a label, and ${command} takes labels with --label.`, { next: [{
1825
+ instruction: "Label it as you post it",
1826
+ argv: [
1827
+ ...cli(),
1828
+ command,
1829
+ target,
1830
+ "<TEXT>",
1831
+ "--label",
1832
+ first
1833
+ ]
1834
+ }] });
1835
+ }
1811
1836
  if (flags.schema !== void 0 && first !== "-") throw usage(`With --schema, the text is ${flags.schema}'s JSON alone, and ${first.length > 40 ? `${first.slice(0, 40)}…` : first} is one too many. To say something with the data, leave out --schema and put the JSON in the text in a \`\`\`json#${flags.schema} fence.`);
1812
1837
  throw usage(first === "-" ? `${command} takes one text, and - (stdin) is a second. For a long message, pass - alone as the text: it has no title.` : `${command} takes one text, and ${first.length > 40 ? `${first.slice(0, 40)}…` : first} is one too many. Quote the whole message as one argument: it has no title.`);
1813
1838
  }
@@ -1885,12 +1910,25 @@ async function attachments(board) {
1885
1910
  });
1886
1911
  }
1887
1912
  const uploaded = [];
1888
- for (const { path, data } of files) uploaded.push(await board.upload({
1889
- data: new Uint8Array(data),
1890
- name: basename(path)
1891
- }));
1913
+ for (const { path, data } of files) try {
1914
+ uploaded.push(await board.upload({
1915
+ data: new Uint8Array(data),
1916
+ name: basename(path)
1917
+ }));
1918
+ } catch (error) {
1919
+ throw error instanceof BoardError && error.code === "attachment_type_mismatch" ? mismatched(path) : error;
1920
+ }
1892
1921
  return uploaded;
1893
1922
  }
1923
+ /** A file a board refused because its bytes aren't the type its name says. */
1924
+ function mismatched(path) {
1925
+ return new Failed({
1926
+ class: "usage",
1927
+ reason: "attachment_type_mismatch",
1928
+ message: `Can't attach ${path}. Its name says ${typeOf(basename(path))}, but its bytes aren't that type.`,
1929
+ next: [{ instruction: "Give it the extension of the format it holds, or save it as a real one, and attach it again" }]
1930
+ });
1931
+ }
1894
1932
  /**
1895
1933
  * Whether `value` is a schedule's own ID and not a message's: `s12` on a local board, `sch_…` on
1896
1934
  * Vercel's. A message's is a number or `msg_…`, so neither is ever one.
@@ -2121,7 +2159,10 @@ function doing() {
2121
2159
  case "label": return `${command} ${ref(a)}`;
2122
2160
  case "react": return `react to ${ref(a)}`;
2123
2161
  case "typing": return `show typing in ${ref(a)}`;
2124
- case "sync": return b === void 0 ? `list where ${ref(a)} is synced` : `sync ${ref(a)} with ${b}`;
2162
+ case "sync":
2163
+ if (a === "remove") return `remove sync ${b ?? ""}`.trimEnd();
2164
+ return b === void 0 ? `list where ${ref(a)} is synced` : `sync ${message ? ref(a) : a} with ${b}`;
2165
+ case "syncs": return a === void 0 ? "list syncs" : `list ${a}'s syncs`;
2125
2166
  case "schedule": return a === "cancel" ? `cancel schedule ${b}` : `schedule a message in ${message ? ref(a) : a ?? "a channel"}`;
2126
2167
  case "channels": return a === "create" ? `create ${b ?? "the channel"}` : "list channels";
2127
2168
  case "schedules":
@@ -2166,6 +2207,8 @@ function missing() {
2166
2207
  const [a, b] = args;
2167
2208
  if (a === void 0) return void 0;
2168
2209
  if (command === "read" && /^https?:\/\//i.test(a)) return "that link's message on this board";
2210
+ if (command === "sync" && a === "remove") return b === void 0 ? void 0 : `sync ${b}`;
2211
+ if (command === "sync" && b !== void 0 && !isMessageRef(a) && !partialApiId(a)) return void 0;
2169
2212
  if (ON_MESSAGE.has(command) || [
2170
2213
  "read",
2171
2214
  "post",
@@ -2345,6 +2388,7 @@ function failureOf(error) {
2345
2388
  if (status === 400) return theirs("usage", specific("invalid_arguments"), `Can't ${doing()}.`);
2346
2389
  if (status === 401) return theirs("auth", "login_required", "The board didn't accept your credentials.", loginRecoveries());
2347
2390
  if (status === 403 && code === "reauthentication_required") return theirs("auth", "login_required", "Your team needs you to log in again.", loginRecoveries());
2391
+ if (status === 403 && code === "invalid_token") return theirs("auth", "login_required", "The board didn't accept your credentials: they expired or were revoked.", loginRecoveries());
2348
2392
  if (status === 403) return theirs("permission", "permission_denied", `You can't ${doing()}.`, refusedRecoveries());
2349
2393
  if (status === 404) {
2350
2394
  const thing = missing();
@@ -2908,9 +2952,13 @@ async function run(command, args) {
2908
2952
  "re",
2909
2953
  "before"
2910
2954
  ].find((name) => flags[name] !== void 0);
2911
- if (across !== void 0) throw usage(`Can't use --${across} on one thread. It's read whole: --after and --label narrow its replies.`);
2955
+ if (across !== void 0) throw usage(`Can't use --${across} on one thread. It's read whole: --after, --limit, and --label narrow its replies.`);
2956
+ if (link && flags.limit !== void 0) throw usage("Can't use --limit with a link. Read the thread by its ID to page its replies.");
2912
2957
  const after = !link && flags.after !== void 0 ? flags.after.replace(/^#/, "") : void 0;
2913
- const thread = link ? await board.linked(target) : await board.thread(messageId(target), after !== void 0 && isMessageRef(after) ? { after: messageId(after) } : {}).catch((error) => {
2958
+ const thread = link ? await board.linked(target) : await board.thread(messageId(target), {
2959
+ ...after !== void 0 && isMessageRef(after) ? { after: messageId(after) } : {},
2960
+ ...flags.limit !== void 0 ? { limit: flags.limit } : {}
2961
+ }).catch((error) => {
2914
2962
  if (error instanceof BoardError && error.status === 400 && /isn't a message of this thread/.test(error.message)) throw usage(`--after ${flags.after} isn't a message of this thread. On one thread, it takes one of its messages.`);
2915
2963
  throw error;
2916
2964
  });
@@ -3088,6 +3136,7 @@ async function run(command, args) {
3088
3136
  }
3089
3137
  const [target, body] = args;
3090
3138
  if (!target) throw usage("Missing the channel or message to schedule a message in.", { reason: "missing_arguments" });
3139
+ oneText("schedule", target, args.slice(2));
3091
3140
  if (!flags.in && !flags.at && !flags.every) throw usage("Can't schedule a message without a time: pass --in 1d, --at <time>, or --every 30m.", { reason: "missing_arguments" });
3092
3141
  const times = flags.times === void 0 ? void 0 : Number(flags.times);
3093
3142
  if (times !== void 0 && !(Number.isInteger(times) && times > 0)) throw usage(`--times takes a count, and ${flags.times} isn't one.`);
@@ -3320,6 +3369,7 @@ async function run(command, args) {
3320
3369
  case "hook": return 0;
3321
3370
  case "edit": {
3322
3371
  const id = messageId(args[0]);
3372
+ oneText("edit", args[0], args.slice(2));
3323
3373
  const { mentions } = await client().edit(id, await content(args[1]), ifRevision());
3324
3374
  printDone(id, "edited", mentions);
3325
3375
  return 0;
@@ -3368,20 +3418,86 @@ async function run(command, args) {
3368
3418
  if (flags.json) result({ targets });
3369
3419
  return 0;
3370
3420
  }
3421
+ case "syncs": {
3422
+ const list = await client().syncs(args[0] !== void 0 ? { channel: args[0] } : {});
3423
+ if (flags.json) return result({ syncs: list }), 0;
3424
+ out(list.length ? list.map(formatManagedSync).join("\n") : "no syncs");
3425
+ return 0;
3426
+ }
3371
3427
  case "sync": {
3372
- const id = messageId(args[0]);
3373
- if (!args[1]) {
3374
- const { targets } = await client().sync(id);
3375
- if (flags.json) return result({ targets }), 0;
3376
- out(targets.length ? formatSynced(targets) : "not synced anywhere");
3377
- return 0;
3428
+ if (args[0] === "remove") {
3429
+ if (!args[1]) throw usage(`Missing the sync to remove: its ID, as \`${named()} syncs\` shows it.`, { reason: "missing_arguments" });
3430
+ const removed = await client().removeSync(args[1]);
3431
+ if (flags.json) return result({
3432
+ sync: removed,
3433
+ outcome: "removed"
3434
+ }), 0;
3435
+ return out(`removed ${formatManagedSync(removed)}`), 0;
3378
3436
  }
3379
- const synced = await client().sync(id, args[1]);
3380
- if (flags.json) result({
3381
- ...synced,
3382
- outcome: synced.attached ? "synced" : "unchanged"
3437
+ if (args[1] !== void 0) {
3438
+ const first = args[0];
3439
+ const mirrored = /^(slack\/[^\s/:]+):(.+)$/.exec(args[1]);
3440
+ if (isMessageRef(first) || partialApiId(first)) {
3441
+ if (mirrored) throw usage(`${args[1]} is what a board syncs a channel with, and ${ref(first)} is a message. A thread syncs to a target, such as slack:#incidents.`, { reason: "invalid_arguments" });
3442
+ const synced = await client().sync(messageId(first), args[1]);
3443
+ if (flags.json) result({
3444
+ ...synced,
3445
+ outcome: synced.attached ? "synced" : "unchanged"
3446
+ });
3447
+ else out(synced.attached ? `synced with ${synced.target}` : `already synced with ${synced.target}`);
3448
+ return 0;
3449
+ }
3450
+ const channel = first;
3451
+ if (!mirrored) throw usage(`${args[1]} isn't something a board syncs a channel with: slack/vercel:#channel. To sync a thread, name a message in it.`, { reason: "invalid_arguments" });
3452
+ const board = client();
3453
+ const made = await board.createSync({
3454
+ channel,
3455
+ source: "slack",
3456
+ slack: {
3457
+ app: mirrored[1],
3458
+ channel: mirrored[2],
3459
+ ...flags.workspace ? { workspace: flags.workspace } : {}
3460
+ }
3461
+ }).catch(async (error) => {
3462
+ if (!(error instanceof BoardError) || error.code !== "channel_not_found") throw error;
3463
+ const guess = closestChannel(channel, (await everyChannel(board)).map((c) => c.path));
3464
+ throw new Failed({
3465
+ class: "not_found",
3466
+ reason: "channel_not_found",
3467
+ message: `Couldn't find channel ${channel}.${guess ? ` Did you mean ${guess}?` : ""}`,
3468
+ details: ["A sync is of a channel that's there: none is made for it."],
3469
+ next: [{
3470
+ instruction: "Make the channel",
3471
+ argv: [
3472
+ ...cli(),
3473
+ "channels",
3474
+ "create",
3475
+ channel
3476
+ ]
3477
+ }]
3478
+ });
3479
+ });
3480
+ if (flags.json) return result({
3481
+ sync: made,
3482
+ outcome: made.state === "active" ? "synced" : made.state
3483
+ }), 0;
3484
+ return out(made.state === "active" ? `syncing ${formatManagedSync(made)}` : formatManagedSync(made)), 0;
3485
+ }
3486
+ if (args[0] !== void 0 && !isMessageRef(args[0]) && !partialApiId(args[0])) throw usage(`${args[0]} isn't a message: ${named()} sync <message> says where its thread is synced.`, {
3487
+ reason: "invalid_arguments",
3488
+ next: [{
3489
+ instruction: "List a channel's syncs",
3490
+ argv: [
3491
+ ...cli(),
3492
+ "syncs",
3493
+ args[0]
3494
+ ]
3495
+ }]
3383
3496
  });
3384
- else out(synced.attached ? `synced with ${synced.target}` : `already synced with ${synced.target}`);
3497
+ const id = messageId(args[0]);
3498
+ const { targets } = await client().sync(id);
3499
+ if (flags.json) return result({ targets }), 0;
3500
+ out(targets.length ? formatSynced(targets) : "not synced anywhere");
3385
3501
  return 0;
3386
3502
  }
3387
3503
  case "download": {
@@ -3596,12 +3712,18 @@ async function createPlan(target, text, path) {
3596
3712
  "needs",
3597
3713
  "for",
3598
3714
  "claim",
3599
- "lease",
3600
- "no-sync"
3715
+ "lease"
3601
3716
  ].find((name) => flags[name] !== void 0 && flags[name] !== false);
3602
- if (own !== void 0) throw usage(`--${own} is one task's: with --file, each task in the file has its own.`);
3717
+ if (own !== void 0) {
3718
+ const key = PLAN_KEY_OF_FLAG[own];
3719
+ if (key === void 0) throw usage(`--${own} is one task's: with --file, each task in the file has its own.`);
3720
+ throw usage(`--${own} is one task's: with --file, set ${key} on each task in the file.`);
3721
+ }
3603
3722
  const board = client();
3604
- const tasks = await planFrom(parsed, path, board);
3723
+ const tasks = (await planFrom(parsed, path, board)).map((task) => flags["no-sync"] && task.noSync === void 0 ? {
3724
+ ...task,
3725
+ noSync: true
3726
+ } : task);
3605
3727
  sentLength = Math.max(0, ...tasks.map((task) => typeof task.text === "string" ? task.text.length : 0));
3606
3728
  const key = flags["idempotency-key"] ?? crypto.randomUUID();
3607
3729
  let made;
@@ -3649,6 +3771,12 @@ const PLAN_KEYS = [
3649
3771
  "noSync",
3650
3772
  "attachments"
3651
3773
  ];
3774
+ /** The key of a plan's task that says what a task's own option does, as the error naming it shows it. */
3775
+ const PLAN_KEY_OF_FLAG = {
3776
+ label: "\"labels\": {…}",
3777
+ needs: "\"needs\": […]",
3778
+ for: "\"for\": \"…\""
3779
+ };
3652
3780
  /** The help page that says what a plan holds. */
3653
3781
  const planHelp = () => ({
3654
3782
  instruction: "See what a plan takes",
@@ -3877,6 +4005,21 @@ async function heldBy(board, claims, id) {
3877
4005
  next: [claim]
3878
4006
  });
3879
4007
  }
4008
+ /**
4009
+ * Task `id` as it is, when the claim of `epoch` settled it: completed, failed, or blocked, with no
4010
+ * claim since. Only that claim's holder gets a task there while `tasks run` keeps the claim
4011
+ * renewed, and `tasks run`'s command holds it too. Otherwise null: the claim was lost.
4012
+ */
4013
+ async function settledBy(board, id, epoch) {
4014
+ const { message } = await board.thread(id).catch(() => ({ message: null }));
4015
+ const task = message?.task;
4016
+ if (!task || task.epoch !== epoch || ![
4017
+ "completed",
4018
+ "failed",
4019
+ "blocked"
4020
+ ].includes(task.state)) return null;
4021
+ return message;
4022
+ }
3880
4023
  /** A write a claim makes. One the board answers `claim_lost` is over: the CLI forgets it, and the failure says how to claim again. */
3881
4024
  async function withClaim(claims, id, write) {
3882
4025
  try {
@@ -4034,6 +4177,9 @@ async function tasks(args) {
4034
4177
  reason: "channel_not_found",
4035
4178
  message: `Couldn't find channel ${verb}.${guess ? ` Did you mean ${guess}?` : ""}`,
4036
4179
  next: [{
4180
+ instruction: "List every channel's open tasks",
4181
+ argv: [...cli(), "tasks"]
4182
+ }, {
4037
4183
  instruction: "See its channels",
4038
4184
  argv: [...cli(), "channels"]
4039
4185
  }]
@@ -4053,6 +4199,7 @@ async function tasks(args) {
4053
4199
  const [target, body, extra] = rest;
4054
4200
  if (!target) throw usage("Missing a channel to start a task in, or a thread's ID to make one of.", { reason: "missing_arguments" });
4055
4201
  if (extra !== void 0) throw usage(`tasks create takes a channel and quoted text: ${extra} is one too many.`);
4202
+ if (flags.file !== void 0 && flags.attach?.length) throw usage("Can't use --attach with --file: a plan's tasks take their files as attachments, by ID.", { next: [planHelp()] });
4056
4203
  if (flags.file !== void 0) return createPlan(target, body, flags.file);
4057
4204
  const lease = seconds("lease");
4058
4205
  if (lease !== void 0 && !claimFlag()) throw usage("--lease is how long a claim holds the task: pass --claim too.");
@@ -4066,12 +4213,13 @@ async function tasks(args) {
4066
4213
  };
4067
4214
  let made;
4068
4215
  if (isMessageRef(target)) {
4069
- const own = body !== void 0 ? "text" : [
4216
+ const own = [...body !== void 0 ? ["text"] : [], ...[
4070
4217
  "label",
4218
+ "attach",
4071
4219
  "no-sync",
4072
4220
  "idempotency-key"
4073
- ].find((name) => flags[name] !== void 0 && flags[name] !== false);
4074
- if (own !== void 0) throw usage(`${ref(target)} becomes a task as it is: ${own === "text" ? "text" : `--${own}`} is for a new thread.`, { next: [{
4221
+ ].filter((name) => flags[name] !== void 0 && flags[name] !== false).map((name) => `--${name}`)];
4222
+ if (own.length > 0) throw usage(`${ref(target)} becomes a task as it is: ${own.length === 1 ? own[0] : `${own.slice(0, -1).join(", ")} and ${own.at(-1)}`} ${own.length === 1 ? "is" : "are"} for a new thread.`, { next: [{
4075
4223
  instruction: "Make it a task as it is",
4076
4224
  argv: [
4077
4225
  ...cli(),
@@ -4084,8 +4232,10 @@ async function tasks(args) {
4084
4232
  } else {
4085
4233
  const said = await text(body, { missing: "Missing the task's text: pass it, or - to read it from stdin. --file takes a plan of several." });
4086
4234
  sentLength = said.length;
4235
+ const files = await attachments(board);
4087
4236
  made = await board.tasks.create(target, {
4088
4237
  text: said,
4238
+ ...files.length ? { attachments: files } : {},
4089
4239
  ...flags.label?.length ? { labels: labelPairs(flags.label) } : {},
4090
4240
  ...flags["no-sync"] ? { noSync: true } : {},
4091
4241
  ...flags["idempotency-key"] ? { id: flags["idempotency-key"] } : {},
@@ -4152,6 +4302,7 @@ async function tasks(args) {
4152
4302
  const id = claim.task.id;
4153
4303
  runTask = id;
4154
4304
  const lease = seconds("lease");
4305
+ let settled = null;
4155
4306
  const ran = await runCommand(command, {
4156
4307
  env: {
4157
4308
  ...process.env,
@@ -4160,6 +4311,7 @@ async function tasks(args) {
4160
4311
  ...flags.json ? { stdout: "stderr" } : {},
4161
4312
  every: (Date.parse(claim.until) - Date.now()) / 3,
4162
4313
  async renew() {
4314
+ if (settled) return true;
4163
4315
  try {
4164
4316
  const renewed = await claim.renew(lease);
4165
4317
  await claims.put(id, {
@@ -4169,7 +4321,9 @@ async function tasks(args) {
4169
4321
  });
4170
4322
  return true;
4171
4323
  } catch (error) {
4172
- return !(error instanceof BoardError && error.code === "claim_lost");
4324
+ if (!(error instanceof BoardError && error.code === "claim_lost")) return true;
4325
+ settled = await settledBy(board, id, claim.epoch);
4326
+ return settled !== null;
4173
4327
  }
4174
4328
  }
4175
4329
  });
@@ -4200,13 +4354,28 @@ async function tasks(args) {
4200
4354
  });
4201
4355
  }
4202
4356
  if (ran.how === "interrupted") {
4203
- await withClaim(claims, id, () => claim.release());
4357
+ if (!settled) try {
4358
+ await withClaim(claims, id, () => claim.release());
4359
+ } catch (error) {
4360
+ if (!(error instanceof BoardError && error.code === "claim_lost") || !await settledBy(board, id, claim.epoch)) throw error;
4361
+ }
4362
+ await claims.drop(id);
4363
+ return ran.code;
4364
+ }
4365
+ const more = ran.code === 0 ? {} : { code: ran.code };
4366
+ if (!settled) try {
4367
+ const done = ran.code === 0 ? await withClaim(claims, id, () => claim.complete(flags.result)) : await withClaim(claims, id, () => claim.fail(ran.signal ? `killed by ${ran.signal}` : `exited ${ran.code}`));
4204
4368
  await claims.drop(id);
4369
+ printTask(done, ran.code === 0 ? "completed" : "failed", more);
4205
4370
  return ran.code;
4371
+ } catch (error) {
4372
+ if (!(error instanceof BoardError && error.code === "claim_lost")) throw error;
4373
+ settled = await settledBy(board, id, claim.epoch);
4374
+ if (!settled) throw error;
4206
4375
  }
4207
- const settled = ran.code === 0 ? await withClaim(claims, id, () => claim.complete(flags.result)) : await withClaim(claims, id, () => claim.fail(ran.signal ? `killed by ${ran.signal}` : `exited ${ran.code}`));
4376
+ const task = await settledBy(board, id, claim.epoch) ?? settled;
4208
4377
  await claims.drop(id);
4209
- printTask(settled, ran.code === 0 ? "completed" : "failed", ran.code === 0 ? {} : { code: ran.code });
4378
+ printTask(task, task.task.state, more);
4210
4379
  return ran.code;
4211
4380
  }
4212
4381
  const id = taskId(rest[0]);
@@ -4829,6 +4998,7 @@ async function main(argv, options) {
4829
4998
  handToken(options.token ?? null);
4830
4999
  handTeam(options.team ?? null);
4831
5000
  handFetch(options.fetch ?? null);
5001
+ handProgram("cli");
4832
5002
  try {
4833
5003
  return await runOnce(argv, options);
4834
5004
  } finally {
@@ -4836,6 +5006,7 @@ async function main(argv, options) {
4836
5006
  handToken(null);
4837
5007
  handTeam(null);
4838
5008
  handFetch(null);
5009
+ handProgram(null);
4839
5010
  }
4840
5011
  }
4841
5012
  async function runOnce(argv, options) {
@@ -1,6 +1,6 @@
1
1
  import { r as sqlTables } from "./sql-CvBbb5Ui.mjs";
2
2
  import { t as memory$1 } from "./store-memory-DOMraCLN.mjs";
3
- import { t as sqliteDb } from "./sqlite-db-DSVlzQjv.mjs";
3
+ import { t as sqliteDb } from "./sqlite-db-DawFxCk6.mjs";
4
4
  //#region src/store/memory.ts
5
5
  /**
6
6
  * A board that lives in memory, for tests: its log in A2's memory store, its
@@ -1,36 +1,6 @@
1
1
  import { _ as NewLabels, m as MESSAGE_TEXT_MAX } from "./schemas-CUSTEFIy.mjs";
2
- import { t as HttpError } from "./errors-BfMR39F0.mjs";
2
+ import { t as HttpError } from "./errors-Ce_-E3_C.mjs";
3
3
  import { z } from "zod";
4
- //#region src/client/ids.ts
5
- const hex = (bytes) => Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
6
- /** SHA-256 of `text`, in hex. */
7
- async function sha256(text) {
8
- return hex(new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode(text))));
9
- }
10
- /**
11
- * A UUIDv8 from `parts`, exactly as A2's `idempotentId` makes one: the IDs a board derives for the
12
- * writes its own code makes, which no request may post with.
13
- */
14
- async function derivedId(...parts) {
15
- const bytes = new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode(JSON.stringify(parts)))).slice(0, 16);
16
- bytes[6] = bytes[6] & 15 | 128;
17
- bytes[8] = bytes[8] & 63 | 128;
18
- const text = hex(bytes);
19
- return `${text.slice(0, 8)}-${text.slice(8, 12)}-${text.slice(12, 16)}-${text.slice(16, 20)}-${text.slice(20, 32)}`;
20
- }
21
- /** A derived ID's shape. */
22
- const DERIVED_ID = /^[0-9a-f]{8}-[0-9a-f]{4}-8[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/;
23
- /**
24
- * A post's ID, from one derived for it, under `principal`: a board takes a `key:<principal>:` ID
25
- * only from that principal, so no one else can post with it first.
26
- */
27
- const keyId = async (principal, derived) => `key:${principal}:${(await sha256(`board-key\u001f${derived}`)).slice(0, 32)}`;
28
- /**
29
- * Whether `id` is exactly the shape `keyId` makes for `principal`. A prefix check isn't enough:
30
- * a principal's ID can be the start of another's (`oidc:gitlab.com:acme` and `oidc:gitlab.com:acme:ci`).
31
- */
32
- const isKeyIdOf = (id, principal) => id.startsWith(`key:${principal}:`) && /^[0-9a-f]{32}$/.test(id.slice(`key:${principal}:`.length));
33
- //#endregion
34
4
  //#region src/contract/profiles.ts
35
5
  /**
36
6
  * What an actor's profile is, when it's a platform user a principal's sync speaks for: `slack:user:U0456`
@@ -176,4 +146,4 @@ async function runMiddleware(middleware, input, commit) {
176
146
  return committed.value;
177
147
  }
178
148
  //#endregion
179
- export { sha256 as _, waitUntil as a, platformProfile as c, userIdOf as d, viaText as f, keyId as g, isKeyIdOf as h, afterRetry as i, shownName as l, derivedId as m, MIDDLEWARE_ACTOR as n, actorParts as o, DERIVED_ID as p, runMiddleware as r, importedHandle as s, DroppedError as t, underPrincipal as u };
149
+ export { waitUntil as a, platformProfile as c, userIdOf as d, viaText as f, afterRetry as i, shownName as l, MIDDLEWARE_ACTOR as n, actorParts as o, runMiddleware as r, importedHandle as s, DroppedError as t, underPrincipal as u };
@@ -1,5 +1,5 @@
1
- import { Jn as ExternalEvent, Rt as SourceJoin, Vn as Actor, Vt as SourceRead, Xn as ExternalLink, Yn as ExternalFile, Zn as Link, qn as ExternalAuthor, u as BoardEventView, ut as MessageView } from "./routes-CSnxZyyb.mjs";
2
- import { t as BoardClient } from "./client-B0DGOt7P.mjs";
1
+ import { $n as ExternalAuthor, Wt as SourceJoin, er as ExternalEvent, gt as MessageView, nr as ExternalLink, qn as Actor, qt as SourceRead, rr as Link, tr as ExternalFile, u as BoardEventView } from "./routes-D5FtKOP_.mjs";
2
+ import { t as BoardClient } from "./client-BUPyzzFt.mjs";
3
3
  import { z } from "zod";
4
4
  //#region src/contract/bots.d.ts
5
5
  /**