@copilotz/work 0.0.0-stage → 1.0.0-rc.35

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 (147) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +56 -2
  3. package/boards/actions/create-board.d.ts +1 -0
  4. package/boards/actions/create-board.js +47 -0
  5. package/boards/actions/create-card.d.ts +1 -0
  6. package/boards/actions/create-card.js +83 -0
  7. package/boards/actions/delete-board.d.ts +1 -0
  8. package/boards/actions/delete-board.js +30 -0
  9. package/boards/actions/delete-card.d.ts +1 -0
  10. package/boards/actions/delete-card.js +24 -0
  11. package/boards/actions/move-card.d.ts +1 -0
  12. package/boards/actions/move-card.js +85 -0
  13. package/boards/actions/update-board.d.ts +1 -0
  14. package/boards/actions/update-board.js +110 -0
  15. package/boards/actions/update-card.d.ts +1 -0
  16. package/boards/actions/update-card.js +67 -0
  17. package/boards/collections/board.d.ts +71 -0
  18. package/boards/collections/board.js +32 -0
  19. package/boards/collections/card.d.ts +74 -0
  20. package/boards/collections/card.js +29 -0
  21. package/boards/contract.d.ts +67 -0
  22. package/boards/contract.js +20 -0
  23. package/boards/mod.d.ts +34 -0
  24. package/boards/mod.js +72 -0
  25. package/boards/resources/tools.d.ts +2 -0
  26. package/boards/resources/tools.js +414 -0
  27. package/boards/shared/columns.d.ts +39 -0
  28. package/boards/shared/columns.js +88 -0
  29. package/boards/shared/dates.d.ts +11 -0
  30. package/boards/shared/dates.js +22 -0
  31. package/boards/shared/errors.d.ts +24 -0
  32. package/boards/shared/errors.js +20 -0
  33. package/boards/shared/fields.d.ts +65 -0
  34. package/boards/shared/fields.js +44 -0
  35. package/boards/shared/load.d.ts +22 -0
  36. package/boards/shared/load.js +32 -0
  37. package/boards/shared/order.d.ts +30 -0
  38. package/boards/shared/order.js +47 -0
  39. package/boards/shared/people.d.ts +30 -0
  40. package/boards/shared/people.js +87 -0
  41. package/boards/shared/said.d.ts +28 -0
  42. package/boards/shared/said.js +30 -0
  43. package/boards/views/web/board-head.d.ts +62 -0
  44. package/boards/views/web/board-head.js +170 -0
  45. package/boards/views/web/board-page.d.ts +17 -0
  46. package/boards/views/web/board-page.js +97 -0
  47. package/boards/views/web/board-view.d.ts +40 -0
  48. package/boards/views/web/board-view.js +341 -0
  49. package/boards/views/web/boards-tab.d.ts +13 -0
  50. package/boards/views/web/boards-tab.js +109 -0
  51. package/boards/views/web/card-sheet.d.ts +47 -0
  52. package/boards/views/web/card-sheet.js +314 -0
  53. package/boards/views/web/card-tile.d.ts +29 -0
  54. package/boards/views/web/card-tile.js +20 -0
  55. package/boards/views/web/column.d.ts +38 -0
  56. package/boards/views/web/column.js +171 -0
  57. package/boards/views/web/drag.d.ts +36 -0
  58. package/boards/views/web/drag.js +276 -0
  59. package/boards/views/web/glyphs.d.ts +29 -0
  60. package/boards/views/web/glyphs.js +25 -0
  61. package/boards/views/web/load.d.ts +32 -0
  62. package/boards/views/web/load.js +33 -0
  63. package/boards/views/web/palette.d.ts +15 -0
  64. package/boards/views/web/palette.js +180 -0
  65. package/boards/views/web/pickers.d.ts +45 -0
  66. package/boards/views/web/pickers.js +83 -0
  67. package/boards/views/web/shown.d.ts +77 -0
  68. package/boards/views/web/shown.js +136 -0
  69. package/boards/views/web/step.d.ts +13 -0
  70. package/boards/views/web/step.js +41 -0
  71. package/boards/views/web/style.d.ts +10 -0
  72. package/boards/views/web/style.js +380 -0
  73. package/boards/views/web/toolbar.d.ts +21 -0
  74. package/boards/views/web/toolbar.js +39 -0
  75. package/boards/web.d.ts +26 -0
  76. package/boards/web.js +52 -0
  77. package/contract.d.ts +7 -0
  78. package/contract.js +7 -0
  79. package/documents/actions/create.d.ts +1 -0
  80. package/documents/actions/create.js +28 -0
  81. package/documents/actions/delete.d.ts +1 -0
  82. package/documents/actions/delete.js +32 -0
  83. package/documents/actions/presence.d.ts +1 -0
  84. package/documents/actions/presence.js +45 -0
  85. package/documents/actions/rename.d.ts +1 -0
  86. package/documents/actions/rename.js +33 -0
  87. package/documents/actions/restore.d.ts +1 -0
  88. package/documents/actions/restore.js +39 -0
  89. package/documents/actions/save.d.ts +1 -0
  90. package/documents/actions/save.js +78 -0
  91. package/documents/collections/document-presence.d.ts +79 -0
  92. package/documents/collections/document-presence.js +25 -0
  93. package/documents/collections/document-version.d.ts +166 -0
  94. package/documents/collections/document-version.js +60 -0
  95. package/documents/collections/document.d.ts +131 -0
  96. package/documents/collections/document.js +72 -0
  97. package/documents/contract.d.ts +17 -0
  98. package/documents/contract.js +1 -0
  99. package/documents/mod.d.ts +38 -0
  100. package/documents/mod.js +75 -0
  101. package/documents/resources/tools.d.ts +2 -0
  102. package/documents/resources/tools.js +253 -0
  103. package/documents/shared/diff.d.ts +37 -0
  104. package/documents/shared/diff.js +148 -0
  105. package/documents/shared/merge.d.ts +29 -0
  106. package/documents/shared/merge.js +120 -0
  107. package/documents/shared/presence.d.ts +7 -0
  108. package/documents/shared/presence.js +7 -0
  109. package/documents/shared/text.d.ts +36 -0
  110. package/documents/shared/text.js +67 -0
  111. package/documents/shared/who.d.ts +23 -0
  112. package/documents/shared/who.js +39 -0
  113. package/documents/shared/write.d.ts +54 -0
  114. package/documents/shared/write.js +123 -0
  115. package/documents/views/web/changes.d.ts +22 -0
  116. package/documents/views/web/changes.js +57 -0
  117. package/documents/views/web/conflict.d.ts +38 -0
  118. package/documents/views/web/conflict.js +96 -0
  119. package/documents/views/web/draft.d.ts +18 -0
  120. package/documents/views/web/draft.js +32 -0
  121. package/documents/views/web/editor.d.ts +57 -0
  122. package/documents/views/web/editor.js +268 -0
  123. package/documents/views/web/format.d.ts +56 -0
  124. package/documents/views/web/format.js +245 -0
  125. package/documents/views/web/history.d.ts +23 -0
  126. package/documents/views/web/history.js +118 -0
  127. package/documents/views/web/list.d.ts +37 -0
  128. package/documents/views/web/list.js +211 -0
  129. package/documents/views/web/page.d.ts +35 -0
  130. package/documents/views/web/page.js +416 -0
  131. package/documents/views/web/palette.d.ts +16 -0
  132. package/documents/views/web/palette.js +168 -0
  133. package/documents/views/web/people.d.ts +60 -0
  134. package/documents/views/web/people.js +63 -0
  135. package/documents/views/web/presence.d.ts +30 -0
  136. package/documents/views/web/presence.js +75 -0
  137. package/documents/views/web/step.d.ts +25 -0
  138. package/documents/views/web/step.js +81 -0
  139. package/documents/views/web/style.d.ts +7 -0
  140. package/documents/views/web/style.js +266 -0
  141. package/documents/web.d.ts +18 -0
  142. package/documents/web.js +46 -0
  143. package/mod.d.ts +18 -0
  144. package/mod.js +18 -0
  145. package/package.json +61 -4
  146. package/web.d.ts +13 -0
  147. package/web.js +13 -0
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Boards' and cards' fields as the Actions take them (JSON Schema), and
3
+ * what's kept of what's given: names and titles trimmed, labels trimmed and
4
+ * once each, due dates real days. Who did something, as documents say it
5
+ * (`person:ana`, `agent:north`), and new documents' ids: short, so agents
6
+ * and links carry them easily.
7
+ */
8
+ import type { Actor } from "copilotz";
9
+ export declare const LIMITS: {
10
+ name: number;
11
+ description: number;
12
+ title: number;
13
+ labels: number;
14
+ label: number;
15
+ column: number;
16
+ };
17
+ export declare const NAME: {
18
+ readonly type: "string";
19
+ readonly minLength: 1;
20
+ readonly maxLength: number;
21
+ };
22
+ export declare const TITLE: {
23
+ readonly type: "string";
24
+ readonly minLength: 1;
25
+ readonly maxLength: number;
26
+ };
27
+ export declare const DESCRIPTION: {
28
+ readonly type: "string";
29
+ readonly maxLength: number;
30
+ };
31
+ export declare const COLUMN_NAME: {
32
+ readonly type: "string";
33
+ readonly minLength: 1;
34
+ readonly maxLength: number;
35
+ };
36
+ /** Who a card is for: a person (`person:<id>`) or an agent (`agent:<name>`). */
37
+ export declare const ASSIGNEE: {
38
+ readonly type: "string";
39
+ readonly pattern: "^(person|agent):.+$";
40
+ readonly maxLength: 200;
41
+ };
42
+ export declare const LABELS: {
43
+ readonly type: "array";
44
+ readonly maxItems: number;
45
+ readonly items: {
46
+ readonly type: "string";
47
+ readonly minLength: 1;
48
+ readonly maxLength: number;
49
+ };
50
+ };
51
+ export declare const DUE: {
52
+ readonly type: "string";
53
+ readonly pattern: "^\\d{4}-\\d{2}-\\d{2}$";
54
+ };
55
+ export declare const POSITION: {
56
+ readonly enum: readonly ["top", "bottom"];
57
+ };
58
+ /** Labels as kept: trimmed, without empty ones, once each (in any case), in the order given. */
59
+ export declare function labelsOf(given: string[]): string[];
60
+ /** A due date, checked to be a real day (`2026-02-30` isn't). */
61
+ export declare function dueOf(given: string): string;
62
+ /** Who an actor is, as a document records it: `person:ana`, `agent:north`. */
63
+ export declare const keyOf: (actor?: Actor) => string;
64
+ /** A new board's or card's id: twelve hex digits. */
65
+ export declare const newId: () => string;
@@ -0,0 +1,44 @@
1
+ import { invalid } from "./errors.js";
2
+ export const LIMITS = {
3
+ name: 80,
4
+ description: 20_000,
5
+ title: 300,
6
+ labels: 12,
7
+ label: 32,
8
+ column: 40,
9
+ };
10
+ export const NAME = { type: "string", minLength: 1, maxLength: LIMITS.name };
11
+ export const TITLE = { type: "string", minLength: 1, maxLength: LIMITS.title };
12
+ export const DESCRIPTION = { type: "string", maxLength: LIMITS.description };
13
+ export const COLUMN_NAME = { type: "string", minLength: 1, maxLength: LIMITS.column };
14
+ /** Who a card is for: a person (`person:<id>`) or an agent (`agent:<name>`). */
15
+ export const ASSIGNEE = { type: "string", pattern: "^(person|agent):.+$", maxLength: 200 };
16
+ export const LABELS = {
17
+ type: "array",
18
+ maxItems: LIMITS.labels,
19
+ items: { type: "string", minLength: 1, maxLength: LIMITS.label },
20
+ };
21
+ export const DUE = { type: "string", pattern: "^\\d{4}-\\d{2}-\\d{2}$" };
22
+ export const POSITION = { enum: ["top", "bottom"] };
23
+ /** Labels as kept: trimmed, without empty ones, once each (in any case), in the order given. */
24
+ export function labelsOf(given) {
25
+ const kept = [];
26
+ for (const raw of given) {
27
+ const label = raw.trim().replace(/\s+/g, " ");
28
+ if (label && !kept.some((k) => k.toLowerCase() === label.toLowerCase()))
29
+ kept.push(label);
30
+ }
31
+ return kept;
32
+ }
33
+ /** A due date, checked to be a real day (`2026-02-30` isn't). */
34
+ export function dueOf(given) {
35
+ const day = new Date(`${given}T00:00:00Z`);
36
+ if (Number.isNaN(day.getTime()) || day.toISOString().slice(0, 10) !== given) {
37
+ throw invalid(`“${given}” isn't a day: give it as YYYY-MM-DD.`);
38
+ }
39
+ return given;
40
+ }
41
+ /** Who an actor is, as a document records it: `person:ana`, `agent:north`. */
42
+ export const keyOf = (actor) => actor ? `${actor.kind}:${actor.id}` : "system";
43
+ /** A new board's or card's id: twelve hex digits. */
44
+ export const newId = () => crypto.randomUUID().replace(/-/g, "").slice(0, 12);
@@ -0,0 +1,22 @@
1
+ /**
2
+ * What boards' Actions read first, as whoever calls them: a board, a card,
3
+ * and whether someone is in a space (a card's assignee has to be). What the
4
+ * caller doesn't reach, the rules keep out of sight, so it reads as missing.
5
+ */
6
+ import { namesFor } from "copilotz/plugins/access/contract";
7
+ import type { Board, Card } from "../contract.js";
8
+ type Reads = {
9
+ db: {
10
+ collection<T>(name: string): {
11
+ findOne(filter: Record<string, unknown>): Promise<T | null>;
12
+ };
13
+ };
14
+ };
15
+ export declare function boardOf(ctx: Reads, id: string): Promise<Board>;
16
+ export declare function cardOf(ctx: Reads, id: string): Promise<Card>;
17
+ /**
18
+ * Throws unless `who` (`person:ana`, `agent:north`) is a member of `space`:
19
+ * cards go to those there. Who isn't, it names (a person by their name).
20
+ */
21
+ export declare function inSpace(ctx: Reads & Parameters<typeof namesFor>[0], space: string, who: string): Promise<void>;
22
+ export {};
@@ -0,0 +1,32 @@
1
+ /**
2
+ * What boards' Actions read first, as whoever calls them: a board, a card,
3
+ * and whether someone is in a space (a card's assignee has to be). What the
4
+ * caller doesn't reach, the rules keep out of sight, so it reads as missing.
5
+ */
6
+ import { nameOf, namesFor } from "copilotz/plugins/access/contract";
7
+ import { invalid, notFound } from "./errors.js";
8
+ export async function boardOf(ctx, id) {
9
+ const found = await ctx.db.collection("board").findOne({ _id: id });
10
+ if (!found) {
11
+ throw notFound("No such board here: it may have been deleted, or it's in a space you're not in.");
12
+ }
13
+ return found;
14
+ }
15
+ export async function cardOf(ctx, id) {
16
+ const found = await ctx.db.collection("card").findOne({ _id: id });
17
+ if (!found)
18
+ throw notFound("No such card here: it may have been deleted or moved away.");
19
+ return found;
20
+ }
21
+ /**
22
+ * Throws unless `who` (`person:ana`, `agent:north`) is a member of `space`:
23
+ * cards go to those there. Who isn't, it names (a person by their name).
24
+ */
25
+ export async function inSpace(ctx, space, who) {
26
+ const found = await ctx.db.collection("member").findOne({ space, member: who });
27
+ if (!found) {
28
+ if (who.startsWith("agent:"))
29
+ throw invalid(`The agent ${nameOf(who)} isn't in this space.`);
30
+ throw invalid(`${nameOf(who, await namesFor(ctx, [who]))} isn't in this space.`);
31
+ }
32
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Where cards sit in a column: each has an `order`, lowest first. A card
3
+ * placed between two others takes the midpoint of theirs, so a move writes
4
+ * one card; at the top or bottom, a step past the end. When a gap runs out
5
+ * (midpoints stop fitting between two doubles), the column is numbered again
6
+ * from the top, a step apart. Pure, so the browser places a card the way
7
+ * the server will while a move is on its way.
8
+ */
9
+ import type { Card, Place } from "../contract.js";
10
+ /** The distance between cards numbered afresh, and past the ends. */
11
+ export declare const STEP = 1024;
12
+ type Placed = Pick<Card, "_id" | "order"> & {
13
+ at?: string;
14
+ };
15
+ /** A column's cards in the order they show: by order, then as they were made. */
16
+ export declare const byOrder: <C extends Placed>(cards: C[]) => C[];
17
+ /** The order between two neighbours' (`above` and `below`, either missing at an end), if one fits. */
18
+ export declare function between(above?: number, below?: number): number | undefined;
19
+ /** Where `place` puts a card among the others of its column (in their order, without it). */
20
+ export declare function indexOf(others: Pick<Card, "_id">[], place?: Place): number;
21
+ /**
22
+ * A card's order at `index` among `others` (in their order, without it), and
23
+ * the others' new orders when there was no room and the column was numbered
24
+ * again (`renumbered`: only those that change).
25
+ */
26
+ export declare function orderAt(others: Placed[], index: number): {
27
+ order: number;
28
+ renumbered: Record<string, number>;
29
+ };
30
+ export {};
@@ -0,0 +1,47 @@
1
+ /** The distance between cards numbered afresh, and past the ends. */
2
+ export const STEP = 1024;
3
+ /** The narrowest gap a midpoint still goes in. */
4
+ const NARROWEST = 1e-6;
5
+ /** A column's cards in the order they show: by order, then as they were made. */
6
+ export const byOrder = (cards) => [...cards].sort((a, b) => a.order - b.order || (a.at ?? "").localeCompare(b.at ?? "") || a._id.localeCompare(b._id));
7
+ /** The order between two neighbours' (`above` and `below`, either missing at an end), if one fits. */
8
+ export function between(above, below) {
9
+ if (above === undefined && below === undefined)
10
+ return STEP;
11
+ if (above === undefined)
12
+ return below - STEP;
13
+ if (below === undefined)
14
+ return above + STEP;
15
+ const mid = above + (below - above) / 2;
16
+ return below - above > NARROWEST && mid > above && mid < below ? mid : undefined;
17
+ }
18
+ /** Where `place` puts a card among the others of its column (in their order, without it). */
19
+ export function indexOf(others, place) {
20
+ if (!place || ("at" in place && place.at === "bottom"))
21
+ return others.length;
22
+ if ("at" in place)
23
+ return 0;
24
+ const id = "before" in place ? place.before : place.after;
25
+ const found = others.findIndex((c) => c._id === id);
26
+ if (found < 0)
27
+ return others.length;
28
+ return "before" in place ? found : found + 1;
29
+ }
30
+ /**
31
+ * A card's order at `index` among `others` (in their order, without it), and
32
+ * the others' new orders when there was no room and the column was numbered
33
+ * again (`renumbered`: only those that change).
34
+ */
35
+ export function orderAt(others, index) {
36
+ const at = Math.max(0, Math.min(index, others.length));
37
+ const order = between(others[at - 1]?.order, others[at]?.order);
38
+ if (order !== undefined && Number.isFinite(order))
39
+ return { order, renumbered: {} };
40
+ const renumbered = {};
41
+ others.forEach((card, i) => {
42
+ const fresh = (i < at ? i + 1 : i + 2) * STEP;
43
+ if (card.order !== fresh)
44
+ renumbered[card._id] = fresh;
45
+ });
46
+ return { order: (at + 1) * STEP, renumbered };
47
+ }
@@ -0,0 +1,30 @@
1
+ import type { ToolContext } from "copilotz/plugins/agents/contract";
2
+ /** Someone in a space: the key a card holds, how they're named, and what else matches them. */
3
+ export type Someone = {
4
+ key: string;
5
+ kind: "person" | "agent";
6
+ name: string;
7
+ also: string[];
8
+ };
9
+ /**
10
+ * The space's people and agents. Their emails are read as the system (only
11
+ * theirs); their names are their profiles'.
12
+ */
13
+ export declare function peopleIn(ctx: ToolContext, space: string): Promise<Someone[]>;
14
+ /** Whom `typed` names among `people`: `me` is `agent`; none, or several, say so. */
15
+ export declare function whoIs(typed: string, people: Someone[], agent: string): {
16
+ found: Someone;
17
+ } | {
18
+ none: true;
19
+ } | {
20
+ several: Someone[];
21
+ };
22
+ /** How someone shows in an answer: an agent by name, a person by name and email. */
23
+ export declare function shown(someone: Someone): string;
24
+ /** Everyone in the space, as an answer lists them when a name matches nobody. */
25
+ export declare const everyone: (people: Someone[]) => string;
26
+ /**
27
+ * How a card's assignee shows: by name when they're in the space; else
28
+ * (someone since gone) by `names`, their profiles' names.
29
+ */
30
+ export declare function assigneeSaid(key: string | undefined, people: Someone[], names?: Record<string, string>): string;
@@ -0,0 +1,87 @@
1
+ /**
2
+ * Who's in a space, as boards' tools name them: its people (by the name
3
+ * their profile shows, by the email they signed in with) and its agents (by the name they're
4
+ * shown as, "North", or the one they're called by, `north`), each with the
5
+ * key a card's assignee holds (`person:<id>`, `agent:<name>`). A name typed
6
+ * is matched against them: `me` is the agent asking.
7
+ */
8
+ import { nameOf, namesFor } from "copilotz/plugins/access/contract";
9
+ import { fold } from "./columns.js";
10
+ /**
11
+ * The space's people and agents. Their emails are read as the system (only
12
+ * theirs); their names are their profiles'.
13
+ */
14
+ export async function peopleIn(ctx, space) {
15
+ const members = await ctx.db.collection("member").find({ space });
16
+ const ids = (kind) => members.filter((m) => m.member.startsWith(`${kind}:`)).map((m) => m.member.slice(kind.length + 1));
17
+ const agents = ids("agent");
18
+ const persons = ids("person");
19
+ const [team, people, names] = await Promise.all([
20
+ agents.length
21
+ ? ctx.db.collection("thread").query("agents", { in: space, names: agents })
22
+ : { agents: {} },
23
+ persons.length
24
+ ? ctx.as().db.collection("person").find({ _id: { $in: persons } })
25
+ : [],
26
+ namesFor(ctx, persons),
27
+ ]);
28
+ return [
29
+ ...persons.map((id) => {
30
+ const p = people.find((x) => x._id === id);
31
+ return {
32
+ key: `person:${id}`,
33
+ kind: "person",
34
+ name: names[id] || p?.name || p?.email || nameOf(id),
35
+ also: [
36
+ id,
37
+ ...(p?.email ? [p.email, p.email.split("@")[0]] : []),
38
+ ...(p?.name ? [p.name] : []),
39
+ ...(names[id] ? [names[id]] : []),
40
+ ],
41
+ };
42
+ }),
43
+ ...agents.map((id) => ({
44
+ key: `agent:${id}`,
45
+ kind: "agent",
46
+ name: team.agents[id]?.name || id,
47
+ also: [id, `@${id}`, ...(team.agents[id]?.name ? [team.agents[id].name] : [])],
48
+ })),
49
+ ];
50
+ }
51
+ /** Whom `typed` names among `people`: `me` is `agent`; none, or several, say so. */
52
+ export function whoIs(typed, people, agent) {
53
+ const said = fold(typed.replace(/^@/, ""));
54
+ if (said === "me" || said === "myself") {
55
+ const self = people.find((p) => p.key === `agent:${agent}`);
56
+ return self ? { found: self } : { none: true };
57
+ }
58
+ const exact = people.filter((p) => fold(p.key) === said || [p.name, ...p.also].some((n) => fold(n.replace(/^@/, "")) === said));
59
+ if (exact.length === 1)
60
+ return { found: exact[0] };
61
+ if (exact.length > 1)
62
+ return { several: exact };
63
+ const first = people.filter((p) => [p.name, ...p.also].some((n) => fold(n).split(/[\s.@]+/).includes(said)));
64
+ if (first.length === 1)
65
+ return { found: first[0] };
66
+ return first.length ? { several: first } : { none: true };
67
+ }
68
+ /** How someone shows in an answer: an agent by name, a person by name and email. */
69
+ export function shown(someone) {
70
+ if (someone.kind === "agent")
71
+ return someone.name;
72
+ // An email, not an id that holds one (`email:ana@…`).
73
+ const email = someone.also.find((a) => a.includes("@") && !a.includes(":"));
74
+ return email && email !== someone.name ? `${someone.name} (${email})` : someone.name;
75
+ }
76
+ /** Everyone in the space, as an answer lists them when a name matches nobody. */
77
+ export const everyone = (people) => people.length ? people.map(shown).join(", ") : "nobody yet";
78
+ /**
79
+ * How a card's assignee shows: by name when they're in the space; else
80
+ * (someone since gone) by `names`, their profiles' names.
81
+ */
82
+ export function assigneeSaid(key, people, names = {}) {
83
+ if (!key)
84
+ return "unassigned";
85
+ const someone = people.find((p) => p.key === key);
86
+ return someone ? shown(someone) : nameOf(key, names);
87
+ }
@@ -0,0 +1,28 @@
1
+ /** A board as answers name it: in quotes, with its link. */
2
+ export declare const named: (board: {
3
+ _id: string;
4
+ name: string;
5
+ }) => string;
6
+ /** What happened to a card, then where: `<head> — on “Board” (/board/<id>).` */
7
+ export declare const onBoard: (head: string, board: {
8
+ _id: string;
9
+ name: string;
10
+ }) => string;
11
+ /** A card as answers name it: in quotes, with its id. */
12
+ export declare const cardNamed: (card: {
13
+ _id: string;
14
+ title: string;
15
+ }) => string;
16
+ /** An answer, read back: whether it did something, what, and the boards and card it names. */
17
+ export type Heard = {
18
+ /** Whether it names a board: answers that failed don't. */
19
+ ok: boolean;
20
+ /** Its first line, without the board's link and the card's id: what happened. */
21
+ head: string;
22
+ boards: {
23
+ name: string;
24
+ id: string;
25
+ }[];
26
+ card?: string;
27
+ };
28
+ export declare function heard(output: string | undefined): Heard;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * How boards' tools answer, and how those answers read back. An answer's
3
+ * first line says what happened ("Moved “Ship pricing page” [c1] from To do
4
+ * to Doing") and names the board with its link (“Launch plan”
5
+ * (/board/<id>)), so an agent links it when it tells people; a card's id is
6
+ * in brackets, for the next call. A conversation shows each call by its
7
+ * tool's View (views/web/step.tsx), which reads the same answer back:
8
+ * what happened, the boards it names, the card. Pure.
9
+ */
10
+ import { boardPath } from "../contract.js";
11
+ /** A board as answers name it: in quotes, with its link. */
12
+ export const named = (board) => `“${board.name}” (${boardPath(board._id)})`;
13
+ /** What happened to a card, then where: `<head> — on “Board” (/board/<id>).` */
14
+ export const onBoard = (head, board) => `${head} — on ${named(board)}.`;
15
+ /** A card as answers name it: in quotes, with its id. */
16
+ export const cardNamed = (card) => `“${card.title}” [${card._id}]`;
17
+ const BOARD = /“([^”\n]*)” \(\/board\/([A-Za-z0-9_-]+)\)/g;
18
+ export function heard(output) {
19
+ const text = (output ?? "").trim();
20
+ const first = text.split("\n")[0] ?? "";
21
+ const boards = [...text.matchAll(BOARD)].map((m) => ({ name: m[1], id: m[2] }))
22
+ .filter((b, i, all) => all.findIndex((o) => o.id === b.id) === i);
23
+ const card = /\[([A-Za-z0-9_-]+)\]/.exec(first)?.[1];
24
+ const head = first
25
+ .replace(/ — on “[^”\n]*” \(\/board\/[A-Za-z0-9_-]+\)\.?$/, "")
26
+ .replace(/ \[[A-Za-z0-9_-]+\]/g, "")
27
+ .replace(/\.$/, "")
28
+ .trim();
29
+ return { ok: boards.length > 0, head, boards, ...(card ? { card } : {}) };
30
+ }
@@ -0,0 +1,62 @@
1
+ /**
2
+ * A board's head, as its page and a space's tab show it: its name, renamed
3
+ * in place by editors; its description, written in place; its menu (rename,
4
+ * describe, add a column, archive or restore, delete, after a question that
5
+ * says its cards go too). And a new board, named in a small form.
6
+ */
7
+ import { type ReactNode } from "react";
8
+ import { type MenuItem } from "copilotz/web";
9
+ import type { Board } from "../../contract.js";
10
+ import { boardsTab } from "../../contract.js";
11
+ type Call = <R = unknown>(action: string, input?: unknown) => Promise<R>;
12
+ /** A board's name: a button that turns into a field, for editors. */
13
+ export declare function BoardName({ board, can, renaming, onRenaming, call }: {
14
+ board: Board;
15
+ can: boolean;
16
+ renaming: boolean;
17
+ onRenaming(on: boolean): void;
18
+ call: Call;
19
+ }): ReactNode;
20
+ /** What a board is for: a line or two, written in place by editors. */
21
+ export declare function BoardAbout({ board, can, writing, onWriting, call }: {
22
+ board: Board;
23
+ can: boolean;
24
+ writing: boolean;
25
+ onWriting(on: boolean): void;
26
+ call: Call;
27
+ }): ReactNode;
28
+ /** A board's menu: what an editor does with it, and opening its page from elsewhere. */
29
+ export declare function boardMenu({ board, can, inline, onRename, onDescribe, onAddColumn, onDelete, onNewBoard, call }: {
30
+ board: Board;
31
+ can: boolean;
32
+ /** Shown in a space's tab or a side panel: it offers the board's page. */
33
+ inline?: {
34
+ space: string;
35
+ };
36
+ onRename(): void;
37
+ onDescribe(): void;
38
+ onAddColumn(): void;
39
+ onDelete(): void;
40
+ onNewBoard?(): void;
41
+ call: Call;
42
+ }): (MenuItem | "separator")[];
43
+ /** Deleting a board, once its editor has read that its cards go too. */
44
+ export declare function DeleteBoard({ board, cards, onClose, call, after }: {
45
+ board: Board;
46
+ cards: number;
47
+ onClose(): void;
48
+ call: Call;
49
+ /** Where to go once it's gone. */
50
+ after?: string;
51
+ }): ReactNode;
52
+ /** A new board in a space: its name, and what it's for; then it opens. */
53
+ export declare function NewBoard({ space, where, onClose, call, open }: {
54
+ space: string;
55
+ /** The space's name, as it's shown. */
56
+ where: string;
57
+ onClose(): void;
58
+ call: Call;
59
+ /** Whether it goes to the board once made (else it shows where it is). */
60
+ open?: boolean;
61
+ }): ReactNode;
62
+ export { boardsTab };
@@ -0,0 +1,170 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * A board's head, as its page and a space's tab show it: its name, renamed
4
+ * in place by editors; its description, written in place; its menu (rename,
5
+ * describe, add a column, archive or restore, delete, after a question that
6
+ * says its cards go too). And a new board, named in a small form.
7
+ */
8
+ import { useEffect, useRef, useState } from "react";
9
+ import { Button, go, IconButton, InlineEdit, Input, Kbd, message, Textarea, } from "copilotz/web";
10
+ import { boardPath, boardsTab } from "../../contract.js";
11
+ import { MOD, Sheet } from "./card-sheet.js";
12
+ import { Glyph } from "./glyphs.js";
13
+ /** A board's name: a button that turns into a field, for editors. */
14
+ export function BoardName({ board, can, renaming, onRenaming, call }) {
15
+ if (renaming) {
16
+ return (_jsx(InlineEdit, { label: "The board's name", value: board.name, maxLength: 80, save: (name) => call("board.update", { board: board._id, name }), done: () => onRenaming(false) }));
17
+ }
18
+ if (!can)
19
+ return _jsx(_Fragment, { children: board.name });
20
+ return (_jsx("button", { type: "button", className: "board-name", title: "Rename", onClick: () => onRenaming(true), children: board.name }));
21
+ }
22
+ /** What a board is for: a line or two, written in place by editors. */
23
+ export function BoardAbout({ board, can, writing, onWriting, call }) {
24
+ const [text, setText] = useState(board.description ?? "");
25
+ const [busy, setBusy] = useState(false);
26
+ const [error, setError] = useState();
27
+ const field = useRef(null);
28
+ useEffect(() => {
29
+ if (writing) {
30
+ setText(board.description ?? "");
31
+ requestAnimationFrame(() => field.current?.focus());
32
+ }
33
+ }, [writing]);
34
+ if (writing) {
35
+ const save = async () => {
36
+ setBusy(true);
37
+ setError(undefined);
38
+ try {
39
+ await call("board.update", { board: board._id, description: text.trim() || null });
40
+ onWriting(false);
41
+ }
42
+ catch (e) {
43
+ setError(message(e));
44
+ }
45
+ finally {
46
+ setBusy(false);
47
+ }
48
+ };
49
+ return (_jsxs("span", { className: "board-about-edit", children: [_jsx(Textarea, { ref: field, autoGrow: true, rows: 2, maxLength: 2000, "aria-label": "What the board is for", placeholder: "What this board is for, and what done looks like", value: text, onChange: (event) => setText(event.target.value), onKeyDown: (event) => {
50
+ if (event.key === "Enter" && (event.metaKey || event.ctrlKey)) {
51
+ event.preventDefault();
52
+ void save();
53
+ }
54
+ else if (event.key === "Escape") {
55
+ event.preventDefault();
56
+ onWriting(false);
57
+ }
58
+ } }), error ? _jsx("span", { role: "alert", className: "board-error", children: error }) : null, _jsxs("span", { className: "board-about-edit-end", children: [_jsxs("span", { className: "board-quick-hint board-grow", children: [_jsx(Kbd, { children: MOD }), _jsx(Kbd, { children: "Enter" }), " saves"] }), _jsx(Button, { size: "sm", variant: "ghost", onClick: () => onWriting(false), children: "Cancel" }), _jsx(Button, { size: "sm", variant: "primary", loading: busy, onClick: () => void save(), children: "Save" })] })] }));
59
+ }
60
+ if (!board.description && !can)
61
+ return null;
62
+ if (!can)
63
+ return _jsx("span", { className: "board-about", children: board.description });
64
+ return (_jsx("button", { type: "button", className: "board-about", "data-empty": !board.description || undefined, onClick: () => onWriting(true), children: board.description || "Add a description: what this board is for" }));
65
+ }
66
+ /** A board's menu: what an editor does with it, and opening its page from elsewhere. */
67
+ export function boardMenu({ board, can, inline, onRename, onDescribe, onAddColumn, onDelete, onNewBoard, call }) {
68
+ return [
69
+ ...(inline
70
+ ? [{
71
+ label: "Open its page",
72
+ icon: "external",
73
+ href: boardPath(board._id, inline.space),
74
+ }]
75
+ : []),
76
+ ...(can
77
+ ? [
78
+ { label: "Rename", icon: "pencil", onSelect: onRename },
79
+ {
80
+ label: board.description ? "Edit the description" : "Add a description",
81
+ icon: "note",
82
+ onSelect: onDescribe,
83
+ },
84
+ { label: "Add a column", icon: "plus", onSelect: onAddColumn },
85
+ ...(onNewBoard
86
+ ? [{ label: "New board…", icon: "plus", onSelect: onNewBoard }]
87
+ : []),
88
+ "separator",
89
+ board.archived
90
+ ? {
91
+ label: "Restore",
92
+ icon: "restore",
93
+ onSelect: () => void call("board.update", { board: board._id, archived: false }),
94
+ }
95
+ : {
96
+ label: "Archive",
97
+ icon: "archive",
98
+ onSelect: () => void call("board.update", { board: board._id, archived: true }),
99
+ },
100
+ {
101
+ label: "Delete board…",
102
+ icon: "trash",
103
+ tone: "destructive",
104
+ onSelect: onDelete,
105
+ },
106
+ ]
107
+ : []),
108
+ ];
109
+ }
110
+ /** Deleting a board, once its editor has read that its cards go too. */
111
+ export function DeleteBoard({ board, cards, onClose, call, after }) {
112
+ const [busy, setBusy] = useState(false);
113
+ const [error, setError] = useState();
114
+ return (_jsx(Sheet, { open: true, onClose: onClose, label: `Delete ${board.name}`, children: _jsxs("div", { className: "card-sheet", children: [_jsxs("header", { className: "card-sheet-head", children: [_jsxs("span", { className: "card-sheet-where", children: [_jsx(Glyph, { name: "board", size: 15 }), "Delete \u201C", board.name, "\u201D?"] }), _jsx("span", { className: "card-sheet-head-end", children: _jsx(IconButton, { icon: "close", label: "Close", size: "sm", onClick: onClose }) })] }), _jsxs("div", { className: "card-sheet-body", children: [_jsxs("p", { className: "card-sheet-say", children: [cards
115
+ ? `Its ${cards} card${cards === 1 ? "" : "s"} go with it, for everyone in the space.`
116
+ : "It has no cards.", " ", "It can't be brought back. Conversations that mention it keep what they said."] }), error ? _jsx("p", { role: "alert", className: "card-sheet-error", children: error }) : null] }), _jsx("footer", { className: "card-sheet-foot", children: _jsxs("span", { className: "card-sheet-end", children: [_jsx(Button, { variant: "ghost", onClick: onClose, children: "Keep it" }), _jsx(Button, { variant: "destructive", icon: "trash", loading: busy, onClick: async () => {
117
+ setBusy(true);
118
+ setError(undefined);
119
+ try {
120
+ await call("board.delete", { board: board._id });
121
+ onClose();
122
+ if (after)
123
+ go(after);
124
+ }
125
+ catch (e) {
126
+ setError(message(e));
127
+ setBusy(false);
128
+ }
129
+ }, children: "Delete board" })] }) })] }) }));
130
+ }
131
+ /** A new board in a space: its name, and what it's for; then it opens. */
132
+ export function NewBoard({ space, where, onClose, call, open = true }) {
133
+ const [name, setName] = useState("");
134
+ const [about, setAbout] = useState("");
135
+ const [busy, setBusy] = useState(false);
136
+ const [error, setError] = useState();
137
+ const named = useRef(null);
138
+ // Past the sheet's own first focus (its close button): the name.
139
+ useEffect(() => void requestAnimationFrame(() => named.current?.focus()), []);
140
+ const make = async () => {
141
+ if (!name.trim() || busy)
142
+ return;
143
+ setBusy(true);
144
+ setError(undefined);
145
+ try {
146
+ const { board } = await call("board.create", {
147
+ in: space,
148
+ name: name.trim(),
149
+ ...(about.trim() ? { description: about.trim() } : {}),
150
+ });
151
+ onClose();
152
+ if (open)
153
+ go(boardPath(board, space));
154
+ }
155
+ catch (e) {
156
+ setError(message(e));
157
+ setBusy(false);
158
+ }
159
+ };
160
+ return (_jsx(Sheet, { open: true, onClose: onClose, label: `New board in ${where}`, children: _jsxs("form", { className: "card-sheet", onSubmit: (event) => {
161
+ event.preventDefault();
162
+ void make();
163
+ }, children: [_jsxs("header", { className: "card-sheet-head", children: [_jsxs("span", { className: "card-sheet-where", children: [_jsx(Glyph, { name: "board", size: 15 }), "New board in ", where] }), _jsx("span", { className: "card-sheet-head-end", children: _jsx(IconButton, { icon: "close", label: "Close", size: "sm", onClick: onClose }) })] }), _jsxs("div", { className: "card-sheet-body", children: [_jsx(Input, { ref: named, maxLength: 80, placeholder: "Launch plan", "aria-label": "The board's name", value: name, onChange: (event) => setName(event.target.value) }), _jsx(Textarea, { autoGrow: true, rows: 2, maxLength: 2000, placeholder: "What it's for, and what done looks like (optional)", "aria-label": "What the board is for", value: about, onChange: (event) => setAbout(event.target.value), onKeyDown: (event) => {
164
+ if (event.key === "Enter" && (event.metaKey || event.ctrlKey)) {
165
+ event.preventDefault();
166
+ void make();
167
+ }
168
+ } }), _jsx("p", { className: "board-quick-hint card-sheet-say", children: "It starts with Backlog, To do, Doing, Blocked, In review and Done; change them anytime." }), error ? _jsx("p", { role: "alert", className: "card-sheet-error", children: error }) : null] }), _jsx("footer", { className: "card-sheet-foot", children: _jsxs("span", { className: "card-sheet-end", children: [_jsx(Button, { variant: "ghost", onClick: onClose, children: "Cancel" }), _jsx(Button, { type: "submit", variant: "primary", loading: busy, disabled: !name.trim(), children: "Make the board" })] }) })] }) }));
169
+ }
170
+ export { boardsTab };