@copilotz/work 0.0.0-stage → 1.0.0-rc.34
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.
- package/LICENSE +21 -0
- package/README.md +56 -2
- package/boards/actions/create-board.d.ts +1 -0
- package/boards/actions/create-board.js +47 -0
- package/boards/actions/create-card.d.ts +1 -0
- package/boards/actions/create-card.js +83 -0
- package/boards/actions/delete-board.d.ts +1 -0
- package/boards/actions/delete-board.js +30 -0
- package/boards/actions/delete-card.d.ts +1 -0
- package/boards/actions/delete-card.js +24 -0
- package/boards/actions/move-card.d.ts +1 -0
- package/boards/actions/move-card.js +85 -0
- package/boards/actions/update-board.d.ts +1 -0
- package/boards/actions/update-board.js +110 -0
- package/boards/actions/update-card.d.ts +1 -0
- package/boards/actions/update-card.js +67 -0
- package/boards/collections/board.d.ts +71 -0
- package/boards/collections/board.js +32 -0
- package/boards/collections/card.d.ts +74 -0
- package/boards/collections/card.js +29 -0
- package/boards/contract.d.ts +67 -0
- package/boards/contract.js +20 -0
- package/boards/mod.d.ts +34 -0
- package/boards/mod.js +72 -0
- package/boards/resources/tools.d.ts +2 -0
- package/boards/resources/tools.js +414 -0
- package/boards/shared/columns.d.ts +39 -0
- package/boards/shared/columns.js +88 -0
- package/boards/shared/dates.d.ts +11 -0
- package/boards/shared/dates.js +22 -0
- package/boards/shared/errors.d.ts +24 -0
- package/boards/shared/errors.js +20 -0
- package/boards/shared/fields.d.ts +65 -0
- package/boards/shared/fields.js +44 -0
- package/boards/shared/load.d.ts +22 -0
- package/boards/shared/load.js +32 -0
- package/boards/shared/order.d.ts +30 -0
- package/boards/shared/order.js +47 -0
- package/boards/shared/people.d.ts +30 -0
- package/boards/shared/people.js +87 -0
- package/boards/shared/said.d.ts +28 -0
- package/boards/shared/said.js +30 -0
- package/boards/views/web/board-head.d.ts +62 -0
- package/boards/views/web/board-head.js +170 -0
- package/boards/views/web/board-page.d.ts +17 -0
- package/boards/views/web/board-page.js +97 -0
- package/boards/views/web/board-view.d.ts +40 -0
- package/boards/views/web/board-view.js +341 -0
- package/boards/views/web/boards-tab.d.ts +13 -0
- package/boards/views/web/boards-tab.js +109 -0
- package/boards/views/web/card-sheet.d.ts +47 -0
- package/boards/views/web/card-sheet.js +314 -0
- package/boards/views/web/card-tile.d.ts +29 -0
- package/boards/views/web/card-tile.js +20 -0
- package/boards/views/web/column.d.ts +38 -0
- package/boards/views/web/column.js +171 -0
- package/boards/views/web/drag.d.ts +36 -0
- package/boards/views/web/drag.js +276 -0
- package/boards/views/web/glyphs.d.ts +29 -0
- package/boards/views/web/glyphs.js +25 -0
- package/boards/views/web/load.d.ts +32 -0
- package/boards/views/web/load.js +33 -0
- package/boards/views/web/palette.d.ts +15 -0
- package/boards/views/web/palette.js +180 -0
- package/boards/views/web/pickers.d.ts +45 -0
- package/boards/views/web/pickers.js +83 -0
- package/boards/views/web/shown.d.ts +77 -0
- package/boards/views/web/shown.js +136 -0
- package/boards/views/web/step.d.ts +13 -0
- package/boards/views/web/step.js +41 -0
- package/boards/views/web/style.d.ts +10 -0
- package/boards/views/web/style.js +380 -0
- package/boards/views/web/toolbar.d.ts +21 -0
- package/boards/views/web/toolbar.js +39 -0
- package/boards/web.d.ts +26 -0
- package/boards/web.js +52 -0
- package/contract.d.ts +7 -0
- package/contract.js +7 -0
- package/documents/actions/create.d.ts +1 -0
- package/documents/actions/create.js +28 -0
- package/documents/actions/delete.d.ts +1 -0
- package/documents/actions/delete.js +32 -0
- package/documents/actions/presence.d.ts +1 -0
- package/documents/actions/presence.js +45 -0
- package/documents/actions/rename.d.ts +1 -0
- package/documents/actions/rename.js +33 -0
- package/documents/actions/restore.d.ts +1 -0
- package/documents/actions/restore.js +39 -0
- package/documents/actions/save.d.ts +1 -0
- package/documents/actions/save.js +78 -0
- package/documents/collections/document-presence.d.ts +79 -0
- package/documents/collections/document-presence.js +25 -0
- package/documents/collections/document-version.d.ts +166 -0
- package/documents/collections/document-version.js +60 -0
- package/documents/collections/document.d.ts +131 -0
- package/documents/collections/document.js +72 -0
- package/documents/contract.d.ts +17 -0
- package/documents/contract.js +1 -0
- package/documents/mod.d.ts +38 -0
- package/documents/mod.js +75 -0
- package/documents/resources/tools.d.ts +2 -0
- package/documents/resources/tools.js +253 -0
- package/documents/shared/diff.d.ts +37 -0
- package/documents/shared/diff.js +148 -0
- package/documents/shared/merge.d.ts +29 -0
- package/documents/shared/merge.js +120 -0
- package/documents/shared/presence.d.ts +7 -0
- package/documents/shared/presence.js +7 -0
- package/documents/shared/text.d.ts +36 -0
- package/documents/shared/text.js +67 -0
- package/documents/shared/who.d.ts +23 -0
- package/documents/shared/who.js +39 -0
- package/documents/shared/write.d.ts +54 -0
- package/documents/shared/write.js +123 -0
- package/documents/views/web/changes.d.ts +22 -0
- package/documents/views/web/changes.js +57 -0
- package/documents/views/web/conflict.d.ts +38 -0
- package/documents/views/web/conflict.js +96 -0
- package/documents/views/web/draft.d.ts +18 -0
- package/documents/views/web/draft.js +32 -0
- package/documents/views/web/editor.d.ts +57 -0
- package/documents/views/web/editor.js +268 -0
- package/documents/views/web/format.d.ts +56 -0
- package/documents/views/web/format.js +245 -0
- package/documents/views/web/history.d.ts +23 -0
- package/documents/views/web/history.js +118 -0
- package/documents/views/web/list.d.ts +37 -0
- package/documents/views/web/list.js +211 -0
- package/documents/views/web/page.d.ts +35 -0
- package/documents/views/web/page.js +416 -0
- package/documents/views/web/palette.d.ts +16 -0
- package/documents/views/web/palette.js +168 -0
- package/documents/views/web/people.d.ts +60 -0
- package/documents/views/web/people.js +63 -0
- package/documents/views/web/presence.d.ts +30 -0
- package/documents/views/web/presence.js +75 -0
- package/documents/views/web/step.d.ts +25 -0
- package/documents/views/web/step.js +81 -0
- package/documents/views/web/style.d.ts +7 -0
- package/documents/views/web/style.js +266 -0
- package/documents/web.d.ts +18 -0
- package/documents/web.js +46 -0
- package/mod.d.ts +18 -0
- package/mod.js +18 -0
- package/package.json +61 -4
- package/web.d.ts +13 -0
- package/web.js +13 -0
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Boards, for agents, wherever their conversation is in a space: that
|
|
3
|
+
* space's boards. `list_boards`, `read_board` (one by name or id, or the
|
|
4
|
+
* space's first: its columns and their cards, each with its id),
|
|
5
|
+
* `create_board`, `create_card`, `update_card` and `move_card`. They call
|
|
6
|
+
* the boards' Actions as the agent working for its person, so the rules
|
|
7
|
+
* keep them to that space and to what both may do there. People and agents
|
|
8
|
+
* are named as people say them (`me`, "North", an email), matched against
|
|
9
|
+
* who's in the space. Answers are short and name the board with its link.
|
|
10
|
+
*/
|
|
11
|
+
import { namesFor } from "copilotz/plugins/access/contract";
|
|
12
|
+
import { tool } from "copilotz/plugins/agents/contract";
|
|
13
|
+
import { columnOf, fold, stageOf } from "../shared/columns.js";
|
|
14
|
+
import { dueSaid, todayOf } from "../shared/dates.js";
|
|
15
|
+
import { byOrder } from "../shared/order.js";
|
|
16
|
+
import { assigneeSaid, everyone, peopleIn, shown, whoIs } from "../shared/people.js";
|
|
17
|
+
import { cardNamed, named, onBoard } from "../shared/said.js";
|
|
18
|
+
const inSpace = (_agent, thread) => !!thread.in;
|
|
19
|
+
const NOWHERE = "This conversation isn't in a space, so there's no board here.";
|
|
20
|
+
/** At most `most` characters of `text`, on one line. */
|
|
21
|
+
const gist = (text, most = 160) => {
|
|
22
|
+
const flat = (text ?? "").replace(/\s+/g, " ").trim();
|
|
23
|
+
return flat.length > most ? `${flat.slice(0, most - 1).trimEnd()}…` : flat;
|
|
24
|
+
};
|
|
25
|
+
/** The space's boards, oldest first. */
|
|
26
|
+
const boardsOf = async (ctx, space) => await ctx.db.collection("board").find({ in: space }, { sort: { at: 1 } });
|
|
27
|
+
/** The board `typed` names (its id or name), or the space's first in use; else why not. */
|
|
28
|
+
async function boardNamed(ctx, space, typed) {
|
|
29
|
+
const boards = await boardsOf(ctx, space);
|
|
30
|
+
const active = boards.filter((b) => !b.archived);
|
|
31
|
+
const asked = typed?.trim();
|
|
32
|
+
if (!asked) {
|
|
33
|
+
return active[0] ??
|
|
34
|
+
(boards.length
|
|
35
|
+
? `This space's boards are all archived: ${boards.map(named).join(", ")}.`
|
|
36
|
+
: "There's no board in this space yet: make one with create_board.");
|
|
37
|
+
}
|
|
38
|
+
const found = boards.find((b) => b._id === asked) ??
|
|
39
|
+
boards.find((b) => fold(b.name) === fold(asked)) ??
|
|
40
|
+
(() => {
|
|
41
|
+
const close = boards.filter((b) => fold(b.name).includes(fold(asked)));
|
|
42
|
+
return close.length === 1 ? close[0] : undefined;
|
|
43
|
+
})();
|
|
44
|
+
if (found)
|
|
45
|
+
return found;
|
|
46
|
+
return `No board “${asked}” in this space.` +
|
|
47
|
+
(boards.length ? ` Its boards: ${boards.map(named).join(", ")}.` : " It has none yet.");
|
|
48
|
+
}
|
|
49
|
+
/** The card `typed` names (its id, or its title) in the space, on `board` if given; else why not. */
|
|
50
|
+
async function cardFound(ctx, space, typed, board) {
|
|
51
|
+
const cards = ctx.db.collection("card");
|
|
52
|
+
const asked = typed.trim().replace(/^\[|\]$/g, "");
|
|
53
|
+
let card = await cards.findOne({ _id: asked, in: space });
|
|
54
|
+
if (!card) {
|
|
55
|
+
const all = await cards.find({ in: space, ...(board ? { board: board._id } : {}) });
|
|
56
|
+
const exact = all.filter((c) => fold(c.title) === fold(asked));
|
|
57
|
+
const close = exact.length ? exact : all.filter((c) => fold(c.title).includes(fold(asked)));
|
|
58
|
+
if (close.length > 1) {
|
|
59
|
+
return `Several cards match “${asked}”: ` +
|
|
60
|
+
close.slice(0, 6).map((c) => cardNamed(c)).join(", ") + ". Say which by its id.";
|
|
61
|
+
}
|
|
62
|
+
card = close[0] ?? null;
|
|
63
|
+
}
|
|
64
|
+
if (!card)
|
|
65
|
+
return `No card “${asked}” here. read_board lists the cards with their ids.`;
|
|
66
|
+
const its = board?._id === card.board
|
|
67
|
+
? board
|
|
68
|
+
: await ctx.db.collection("board").findOne({ _id: card.board });
|
|
69
|
+
return its ? { card, board: its } : "That card's board is gone.";
|
|
70
|
+
}
|
|
71
|
+
/** The column `typed` names on `board`, or why not. */
|
|
72
|
+
function columnNamed(board, typed) {
|
|
73
|
+
return columnOf(board.columns, typed) ??
|
|
74
|
+
`“${board.name}” has no column “${typed}”. Its columns: ${board.columns.map((c) => c.name).join(", ")}.`;
|
|
75
|
+
}
|
|
76
|
+
/** Who `typed` is in the space (`me`, a name, an email), or why not. */
|
|
77
|
+
function someoneNamed(typed, people, agent) {
|
|
78
|
+
const found = whoIs(typed, people, agent);
|
|
79
|
+
if ("found" in found)
|
|
80
|
+
return found.found;
|
|
81
|
+
if ("several" in found) {
|
|
82
|
+
return `“${typed}” could be ${found.several.map(shown).join(" or ")}: say which.`;
|
|
83
|
+
}
|
|
84
|
+
return `Nobody called “${typed}” is in this space. Here: ${everyone(people)}.`;
|
|
85
|
+
}
|
|
86
|
+
/** Whether a value asks to clear a field: null, or nothing. */
|
|
87
|
+
const clears = (value) => value === null || value === "" || (Array.isArray(value) && !value.length) ||
|
|
88
|
+
(typeof value === "string" && ["none", "nobody", "unassigned"].includes(fold(value)));
|
|
89
|
+
/** An Action's refusal, as an agent is told it. */
|
|
90
|
+
function refused(error) {
|
|
91
|
+
const { code, message } = error;
|
|
92
|
+
if (code === "forbidden") {
|
|
93
|
+
return "You can read this board, but you can't change it here: ask someone who manages " +
|
|
94
|
+
"the space to make you an editor.";
|
|
95
|
+
}
|
|
96
|
+
return message || String(error);
|
|
97
|
+
}
|
|
98
|
+
/** A card as `read_board` lists it: id, title, owner, labels, due, a line of what it says. */
|
|
99
|
+
function cardLine(card, people, today, done, names) {
|
|
100
|
+
const parts = [
|
|
101
|
+
`- [${card._id}] ${card.title}`,
|
|
102
|
+
assigneeSaid(card.assignee, people, names),
|
|
103
|
+
...(card.labels?.length ? [`labels: ${card.labels.join(", ")}`] : []),
|
|
104
|
+
...(card.due ? [dueSaid(card.due, today, done)] : []),
|
|
105
|
+
];
|
|
106
|
+
const about = gist(card.description);
|
|
107
|
+
return parts.join(" · ") + (about ? `\n ${about}` : "");
|
|
108
|
+
}
|
|
109
|
+
const listBoards = tool({
|
|
110
|
+
offer: inSpace,
|
|
111
|
+
description: "List the boards in this conversation's space: each one's name, link, and how " +
|
|
112
|
+
"many cards are in each column. Read one with read_board.",
|
|
113
|
+
input: { type: "object", properties: {} },
|
|
114
|
+
run: async (_, ctx) => {
|
|
115
|
+
const space = ctx.in;
|
|
116
|
+
if (!space)
|
|
117
|
+
return NOWHERE;
|
|
118
|
+
const boards = await boardsOf(ctx, space);
|
|
119
|
+
if (!boards.length)
|
|
120
|
+
return "No boards in this space yet. Make one with create_board.";
|
|
121
|
+
const cards = await ctx.db.collection("card").find({ in: space });
|
|
122
|
+
const line = (b) => {
|
|
123
|
+
const n = (column) => cards.filter((c) => c.board === b._id && c.column === column).length;
|
|
124
|
+
const total = b.columns.reduce((sum, c) => sum + n(c.id), 0);
|
|
125
|
+
const columns = b.columns.filter((c) => n(c.id)).map((c) => `${c.name} ${n(c.id)}`);
|
|
126
|
+
return `- ${named(b)}: ` +
|
|
127
|
+
(total
|
|
128
|
+
? `${total} card${total === 1 ? "" : "s"} (${columns.join(", ")})`
|
|
129
|
+
: "no cards yet") +
|
|
130
|
+
(b.description ? `. ${gist(b.description, 120)}` : "");
|
|
131
|
+
};
|
|
132
|
+
const active = boards.filter((b) => !b.archived);
|
|
133
|
+
const archived = boards.filter((b) => b.archived);
|
|
134
|
+
return [
|
|
135
|
+
`${active.length} board${active.length === 1 ? "" : "s"} in this space:`,
|
|
136
|
+
...active.map(line),
|
|
137
|
+
...(archived.length ? ["Archived:", ...archived.map(line)] : []),
|
|
138
|
+
].join("\n");
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
const readBoard = tool({
|
|
142
|
+
offer: inSpace,
|
|
143
|
+
description: "Read a board in this space (by its name or id; without one, the space's " +
|
|
144
|
+
"first): its columns in order, with their cards, each with its id, title, owner, labels, " +
|
|
145
|
+
"due date and a line of its description. Read it before you change it.",
|
|
146
|
+
input: {
|
|
147
|
+
type: "object",
|
|
148
|
+
properties: { board: { type: "string", description: "Its name or id." } },
|
|
149
|
+
},
|
|
150
|
+
run: async ({ board: typed }, ctx) => {
|
|
151
|
+
const space = ctx.in;
|
|
152
|
+
if (!space)
|
|
153
|
+
return NOWHERE;
|
|
154
|
+
const board = await boardNamed(ctx, space, typed);
|
|
155
|
+
if (typeof board === "string")
|
|
156
|
+
return board;
|
|
157
|
+
const [cards, people] = await Promise.all([
|
|
158
|
+
ctx.db.collection("card").find({ in: space, board: board._id }),
|
|
159
|
+
peopleIn(ctx, space),
|
|
160
|
+
]);
|
|
161
|
+
// Cards' owners since gone from the space: by their names still.
|
|
162
|
+
const gone = await namesFor(ctx, cards.flatMap((c) => c.assignee?.startsWith("person:") && !people.some((p) => p.key === c.assignee)
|
|
163
|
+
? [c.assignee]
|
|
164
|
+
: []));
|
|
165
|
+
const today = todayOf();
|
|
166
|
+
const sections = board.columns.map((column) => {
|
|
167
|
+
const here = byOrder(cards.filter((c) => c.column === column.id));
|
|
168
|
+
const done = stageOf(column) === "done";
|
|
169
|
+
return [
|
|
170
|
+
`## ${column.name} (${here.length})`,
|
|
171
|
+
...(here.length ? here.map((c) => cardLine(c, people, today, done, gone)) : ["(empty)"]),
|
|
172
|
+
].join("\n");
|
|
173
|
+
});
|
|
174
|
+
// Cards in a column the board no longer has (shouldn't happen): shown, not lost.
|
|
175
|
+
const lost = cards.filter((c) => !board.columns.some((col) => col.id === c.column));
|
|
176
|
+
return [
|
|
177
|
+
`Board ${named(board)}: ${board.columns.length} columns, ${cards.length} card${cards.length === 1 ? "" : "s"}${board.archived ? " (archived)" : ""}.`,
|
|
178
|
+
...(board.description ? [`About: ${gist(board.description, 600)}`] : []),
|
|
179
|
+
"",
|
|
180
|
+
...sections,
|
|
181
|
+
...(lost.length
|
|
182
|
+
? ["## (no column)", ...lost.map((c) => cardLine(c, people, today, false, gone))]
|
|
183
|
+
: []),
|
|
184
|
+
].join("\n");
|
|
185
|
+
},
|
|
186
|
+
});
|
|
187
|
+
const createBoard = tool({
|
|
188
|
+
offer: inSpace,
|
|
189
|
+
description: "Make a board in this space, for work that takes more than one step. It starts " +
|
|
190
|
+
"with Backlog, To do, Doing, Blocked, In review and Done, unless you name its columns.",
|
|
191
|
+
input: {
|
|
192
|
+
type: "object",
|
|
193
|
+
properties: {
|
|
194
|
+
name: { type: "string", minLength: 1, maxLength: 80 },
|
|
195
|
+
description: { type: "string", description: "What it's for, in a line or two." },
|
|
196
|
+
columns: {
|
|
197
|
+
type: "array",
|
|
198
|
+
items: { type: "string", minLength: 1, maxLength: 40 },
|
|
199
|
+
description: "Its columns' names, left to right (only if the usual ones don't fit).",
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
required: ["name"],
|
|
203
|
+
},
|
|
204
|
+
run: async ({ name, description, columns }, ctx) => {
|
|
205
|
+
const space = ctx.in;
|
|
206
|
+
if (!space)
|
|
207
|
+
return NOWHERE;
|
|
208
|
+
try {
|
|
209
|
+
const made = await ctx.call("board.create", {
|
|
210
|
+
in: space,
|
|
211
|
+
name,
|
|
212
|
+
...(description ? { description } : {}),
|
|
213
|
+
...(columns?.length ? { columns } : {}),
|
|
214
|
+
});
|
|
215
|
+
return `Made the board ${named({ _id: made.board, name: made.name })}, with columns ` +
|
|
216
|
+
`${made.columns.map((c) => c.name).join(", ")}. Add cards with create_card.`;
|
|
217
|
+
}
|
|
218
|
+
catch (error) {
|
|
219
|
+
return refused(error);
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
});
|
|
223
|
+
const createCard = tool({
|
|
224
|
+
offer: inSpace,
|
|
225
|
+
description: "Add a card to a board in this space: one real outcome, with its owner " +
|
|
226
|
+
"(assignee), what done looks like and any blocker in its description, and an honest " +
|
|
227
|
+
"column. The board is the space's first unless you name one; the column, its first.",
|
|
228
|
+
input: {
|
|
229
|
+
type: "object",
|
|
230
|
+
properties: {
|
|
231
|
+
title: { type: "string", minLength: 1, maxLength: 300 },
|
|
232
|
+
board: { type: "string", description: "The board's name or id." },
|
|
233
|
+
column: { type: "string", description: "The column's name or id." },
|
|
234
|
+
description: {
|
|
235
|
+
type: "string",
|
|
236
|
+
description: "Markdown: the outcome, how we'll know it's done, any blocker.",
|
|
237
|
+
},
|
|
238
|
+
assignee: {
|
|
239
|
+
type: "string",
|
|
240
|
+
description: "Who owns it: me (you), an agent's name, or a person's name or email.",
|
|
241
|
+
},
|
|
242
|
+
labels: { type: "array", items: { type: "string", minLength: 1, maxLength: 32 } },
|
|
243
|
+
due: { type: "string", description: "YYYY-MM-DD" },
|
|
244
|
+
at: {
|
|
245
|
+
type: "string",
|
|
246
|
+
enum: ["top", "bottom"],
|
|
247
|
+
description: "Where in the column (the bottom by default).",
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
required: ["title"],
|
|
251
|
+
},
|
|
252
|
+
run: async (input, ctx) => {
|
|
253
|
+
const space = ctx.in;
|
|
254
|
+
if (!space)
|
|
255
|
+
return NOWHERE;
|
|
256
|
+
const board = await boardNamed(ctx, space, input.board);
|
|
257
|
+
if (typeof board === "string")
|
|
258
|
+
return board;
|
|
259
|
+
const column = input.column ? columnNamed(board, input.column) : board.columns[0];
|
|
260
|
+
if (typeof column === "string")
|
|
261
|
+
return column;
|
|
262
|
+
let owner;
|
|
263
|
+
if (input.assignee && !clears(input.assignee)) {
|
|
264
|
+
const found = someoneNamed(input.assignee, await peopleIn(ctx, space), ctx.agent);
|
|
265
|
+
if (typeof found === "string")
|
|
266
|
+
return found;
|
|
267
|
+
owner = found;
|
|
268
|
+
}
|
|
269
|
+
try {
|
|
270
|
+
const made = await ctx.call("card.create", {
|
|
271
|
+
board: board._id,
|
|
272
|
+
title: input.title,
|
|
273
|
+
column: column.id,
|
|
274
|
+
...(input.at ? { at: input.at } : {}),
|
|
275
|
+
...(input.description ? { description: input.description } : {}),
|
|
276
|
+
...(owner ? { assignee: owner.key } : {}),
|
|
277
|
+
...(input.labels?.length ? { labels: input.labels } : {}),
|
|
278
|
+
...(input.due ? { due: input.due } : {}),
|
|
279
|
+
});
|
|
280
|
+
const card = { _id: made.card, title: made.title };
|
|
281
|
+
return onBoard(`Created ${cardNamed(card)} in ${column.name}${owner ? `, for ${shown(owner)}` : ""}`, board);
|
|
282
|
+
}
|
|
283
|
+
catch (error) {
|
|
284
|
+
return refused(error);
|
|
285
|
+
}
|
|
286
|
+
},
|
|
287
|
+
});
|
|
288
|
+
const updateCard = tool({
|
|
289
|
+
offer: inSpace,
|
|
290
|
+
description: "Change a card in this space (by its id from read_board, or its title): its " +
|
|
291
|
+
"title, description, assignee, labels (the whole set) or due date. An empty value, or " +
|
|
292
|
+
"null, clears one. Moving it is move_card.",
|
|
293
|
+
input: {
|
|
294
|
+
type: "object",
|
|
295
|
+
properties: {
|
|
296
|
+
card: { type: "string", description: "Its id, or its title." },
|
|
297
|
+
board: { type: "string", description: "The board's name or id, if the title is on several." },
|
|
298
|
+
title: { type: "string", minLength: 1, maxLength: 300 },
|
|
299
|
+
description: { type: ["string", "null"], description: "Markdown; replaces what it says." },
|
|
300
|
+
assignee: {
|
|
301
|
+
type: ["string", "null"],
|
|
302
|
+
description: "me, an agent's name, a person's name or email; empty to unassign.",
|
|
303
|
+
},
|
|
304
|
+
labels: { type: ["array", "null"], items: { type: "string", maxLength: 32 } },
|
|
305
|
+
due: { type: ["string", "null"], description: "YYYY-MM-DD; empty to clear." },
|
|
306
|
+
},
|
|
307
|
+
required: ["card"],
|
|
308
|
+
},
|
|
309
|
+
run: async (input, ctx) => {
|
|
310
|
+
const space = ctx.in;
|
|
311
|
+
if (!space)
|
|
312
|
+
return NOWHERE;
|
|
313
|
+
const board = input.board ? await boardNamed(ctx, space, input.board) : undefined;
|
|
314
|
+
if (typeof board === "string")
|
|
315
|
+
return board;
|
|
316
|
+
const found = await cardFound(ctx, space, input.card, board);
|
|
317
|
+
if (typeof found === "string")
|
|
318
|
+
return found;
|
|
319
|
+
const change = {};
|
|
320
|
+
const said = [];
|
|
321
|
+
if (input.title !== undefined && input.title.trim() !== found.card.title) {
|
|
322
|
+
change.title = input.title;
|
|
323
|
+
said.push(`titled “${input.title.trim()}”`);
|
|
324
|
+
}
|
|
325
|
+
if (input.description !== undefined) {
|
|
326
|
+
change.description = clears(input.description) ? null : input.description;
|
|
327
|
+
said.push(change.description === null ? "description cleared" : "description written");
|
|
328
|
+
}
|
|
329
|
+
if (input.assignee !== undefined) {
|
|
330
|
+
if (clears(input.assignee)) {
|
|
331
|
+
change.assignee = null;
|
|
332
|
+
said.push("unassigned");
|
|
333
|
+
}
|
|
334
|
+
else {
|
|
335
|
+
const owner = someoneNamed(input.assignee, await peopleIn(ctx, space), ctx.agent);
|
|
336
|
+
if (typeof owner === "string")
|
|
337
|
+
return owner;
|
|
338
|
+
change.assignee = owner.key;
|
|
339
|
+
said.push(`assigned to ${shown(owner)}`);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
if (input.labels !== undefined) {
|
|
343
|
+
change.labels = clears(input.labels) ? null : input.labels;
|
|
344
|
+
said.push(change.labels === null ? "labels cleared" : `labels ${input.labels.join(", ")}`);
|
|
345
|
+
}
|
|
346
|
+
if (input.due !== undefined) {
|
|
347
|
+
change.due = clears(input.due) ? null : input.due;
|
|
348
|
+
said.push(change.due === null ? "due date cleared" : `due ${input.due}`);
|
|
349
|
+
}
|
|
350
|
+
if (!said.length)
|
|
351
|
+
return `Nothing to change on ${cardNamed(found.card)}.`;
|
|
352
|
+
try {
|
|
353
|
+
await ctx.call("card.update", { card: found.card._id, ...change });
|
|
354
|
+
return onBoard(`Updated ${cardNamed({ ...found.card, title: input.title?.trim() || found.card.title })}: ${said.join(", ")}`, found.board);
|
|
355
|
+
}
|
|
356
|
+
catch (error) {
|
|
357
|
+
return refused(error);
|
|
358
|
+
}
|
|
359
|
+
},
|
|
360
|
+
});
|
|
361
|
+
const moveCard = tool({
|
|
362
|
+
offer: inSpace,
|
|
363
|
+
description: "Move a card in this space (by its id from read_board, or its title) to a " +
|
|
364
|
+
"column of its board, by the column's name or id: when its state changes, not later. At " +
|
|
365
|
+
"the column's bottom unless you say top.",
|
|
366
|
+
input: {
|
|
367
|
+
type: "object",
|
|
368
|
+
properties: {
|
|
369
|
+
card: { type: "string", description: "Its id, or its title." },
|
|
370
|
+
column: { type: "string", description: "The column's name or id." },
|
|
371
|
+
board: { type: "string", description: "The board's name or id, if the title is on several." },
|
|
372
|
+
at: { type: "string", enum: ["top", "bottom"] },
|
|
373
|
+
},
|
|
374
|
+
required: ["card", "column"],
|
|
375
|
+
},
|
|
376
|
+
run: async (input, ctx) => {
|
|
377
|
+
const space = ctx.in;
|
|
378
|
+
if (!space)
|
|
379
|
+
return NOWHERE;
|
|
380
|
+
const board = input.board ? await boardNamed(ctx, space, input.board) : undefined;
|
|
381
|
+
if (typeof board === "string")
|
|
382
|
+
return board;
|
|
383
|
+
const found = await cardFound(ctx, space, input.card, board);
|
|
384
|
+
if (typeof found === "string")
|
|
385
|
+
return found;
|
|
386
|
+
const column = columnNamed(found.board, input.column);
|
|
387
|
+
if (typeof column === "string")
|
|
388
|
+
return column;
|
|
389
|
+
const from = found.board.columns.find((c) => c.id === found.card.column);
|
|
390
|
+
try {
|
|
391
|
+
await ctx.call("card.move", {
|
|
392
|
+
card: found.card._id,
|
|
393
|
+
column: column.id,
|
|
394
|
+
at: input.at ?? "bottom",
|
|
395
|
+
});
|
|
396
|
+
const head = from?.id === column.id
|
|
397
|
+
? `Moved ${cardNamed(found.card)} to the ${input.at ?? "bottom"} of ${column.name}`
|
|
398
|
+
: `Moved ${cardNamed(found.card)} from ${from?.name ?? "nowhere"} to ${column.name}` +
|
|
399
|
+
(input.at === "top" ? " (at the top)" : "");
|
|
400
|
+
return onBoard(head, found.board);
|
|
401
|
+
}
|
|
402
|
+
catch (error) {
|
|
403
|
+
return refused(error);
|
|
404
|
+
}
|
|
405
|
+
},
|
|
406
|
+
});
|
|
407
|
+
export const tools = {
|
|
408
|
+
list_boards: listBoards,
|
|
409
|
+
read_board: readBoard,
|
|
410
|
+
create_board: createBoard,
|
|
411
|
+
create_card: createCard,
|
|
412
|
+
update_card: updateCard,
|
|
413
|
+
move_card: moveCard,
|
|
414
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A board's columns: the ones a new board starts with, the ids new ones
|
|
3
|
+
* take (from their names: `qa`, `qa-2`), finding one as people and agents
|
|
4
|
+
* name it ("in review", `review`), and the stage of work a column stands
|
|
5
|
+
* for, which its mark shows (Backlog's dashed ring, Done's check). Pure.
|
|
6
|
+
*/
|
|
7
|
+
import type { Column } from "../contract.js";
|
|
8
|
+
/** What a new board starts with: the team's usual flow. */
|
|
9
|
+
export declare const DEFAULT_COLUMNS: readonly Column[];
|
|
10
|
+
/** At most this many columns on a board. */
|
|
11
|
+
export declare const MOST_COLUMNS = 20;
|
|
12
|
+
/** Text as it's matched: any case, any accents, spaces and dashes alike. */
|
|
13
|
+
export declare const fold: (text: string) => string;
|
|
14
|
+
/** A new column's id, from its name, free among `taken`: `qa`, then `qa-2`. */
|
|
15
|
+
export declare function columnId(name: string, taken: Iterable<string>): string;
|
|
16
|
+
/** Columns from their names alone (a new board's own), each with an id. */
|
|
17
|
+
export declare function columnsNamed(names: string[]): Column[];
|
|
18
|
+
/** The column `named` is: by its id, or its name in any case. */
|
|
19
|
+
export declare const columnOf: (columns: readonly Column[], named: string) => Column | undefined;
|
|
20
|
+
/** A column's stage of work, as its mark shows it. */
|
|
21
|
+
export type Stage = "backlog" | "todo" | "doing" | "blocked" | "review" | "done";
|
|
22
|
+
/** What a column stands for, from its id or its name: Doing is under way, Done is done. */
|
|
23
|
+
export declare function stageOf(column: Column): Stage;
|
|
24
|
+
/** What changing a board's columns does: those it keeps, adds and removes. */
|
|
25
|
+
export type ColumnChange = {
|
|
26
|
+
columns: Column[];
|
|
27
|
+
added: Column[];
|
|
28
|
+
removed: Column[];
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* A board's columns as given (`[{ id?, name }]`, in their new order): known
|
|
32
|
+
* ids are kept (renamed, moved), the rest are new and get ids; those left
|
|
33
|
+
* out are removed. Throws, in words, on what can't be: no columns, too many,
|
|
34
|
+
* an empty name, or two with one name.
|
|
35
|
+
*/
|
|
36
|
+
export declare function changeColumns(was: readonly Column[], given: {
|
|
37
|
+
id?: string;
|
|
38
|
+
name: string;
|
|
39
|
+
}[]): ColumnChange;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { invalid } from "./errors.js";
|
|
2
|
+
/** What a new board starts with: the team's usual flow. */
|
|
3
|
+
export const DEFAULT_COLUMNS = [
|
|
4
|
+
{ id: "backlog", name: "Backlog" },
|
|
5
|
+
{ id: "todo", name: "To do" },
|
|
6
|
+
{ id: "doing", name: "Doing" },
|
|
7
|
+
{ id: "blocked", name: "Blocked" },
|
|
8
|
+
{ id: "review", name: "In review" },
|
|
9
|
+
{ id: "done", name: "Done" },
|
|
10
|
+
];
|
|
11
|
+
/** At most this many columns on a board. */
|
|
12
|
+
export const MOST_COLUMNS = 20;
|
|
13
|
+
/** Text as it's matched: any case, any accents, spaces and dashes alike. */
|
|
14
|
+
export const fold = (text) => text.normalize("NFD").replace(/[̀-ͯ]/g, "").toLowerCase().replace(/[\s_-]+/g, " ")
|
|
15
|
+
.trim();
|
|
16
|
+
/** A new column's id, from its name, free among `taken`: `qa`, then `qa-2`. */
|
|
17
|
+
export function columnId(name, taken) {
|
|
18
|
+
const used = new Set(taken);
|
|
19
|
+
const base = fold(name).replace(/[^a-z0-9 ]+/g, "").trim().replace(/ +/g, "-").slice(0, 24) ||
|
|
20
|
+
"column";
|
|
21
|
+
for (let n = 1;; n++) {
|
|
22
|
+
const id = n === 1 ? base : `${base}-${n}`;
|
|
23
|
+
if (!used.has(id))
|
|
24
|
+
return id;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/** Columns from their names alone (a new board's own), each with an id. */
|
|
28
|
+
export function columnsNamed(names) {
|
|
29
|
+
const columns = [];
|
|
30
|
+
for (const name of names) {
|
|
31
|
+
columns.push({ id: columnId(name, columns.map((c) => c.id)), name: name.trim() });
|
|
32
|
+
}
|
|
33
|
+
return columns;
|
|
34
|
+
}
|
|
35
|
+
/** The column `named` is: by its id, or its name in any case. */
|
|
36
|
+
export const columnOf = (columns, named) => columns.find((c) => c.id === named) ??
|
|
37
|
+
columns.find((c) => fold(c.name) === fold(named)) ??
|
|
38
|
+
columns.find((c) => fold(c.id) === fold(named));
|
|
39
|
+
/** What a column stands for, from its id or its name: Doing is under way, Done is done. */
|
|
40
|
+
export function stageOf(column) {
|
|
41
|
+
const said = `${fold(column.id)} ${fold(column.name)}`;
|
|
42
|
+
if (/\b(done|shipped|complete|completed|closed|finished|live)\b/.test(said))
|
|
43
|
+
return "done";
|
|
44
|
+
if (/\b(blocked|stuck|waiting|on hold|hold)\b/.test(said))
|
|
45
|
+
return "blocked";
|
|
46
|
+
if (/\b(review|reviewing|qa|testing|test|verify|approval)\b/.test(said))
|
|
47
|
+
return "review";
|
|
48
|
+
if (/\b(doing|progress|active|started|working|wip)\b/.test(said))
|
|
49
|
+
return "doing";
|
|
50
|
+
if (/\b(backlog|later|ideas?|someday|icebox|inbox)\b/.test(said))
|
|
51
|
+
return "backlog";
|
|
52
|
+
return "todo";
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* A board's columns as given (`[{ id?, name }]`, in their new order): known
|
|
56
|
+
* ids are kept (renamed, moved), the rest are new and get ids; those left
|
|
57
|
+
* out are removed. Throws, in words, on what can't be: no columns, too many,
|
|
58
|
+
* an empty name, or two with one name.
|
|
59
|
+
*/
|
|
60
|
+
export function changeColumns(was, given) {
|
|
61
|
+
if (!given.length)
|
|
62
|
+
throw invalid("A board needs at least one column.");
|
|
63
|
+
if (given.length > MOST_COLUMNS)
|
|
64
|
+
throw invalid(`A board has at most ${MOST_COLUMNS} columns.`);
|
|
65
|
+
const known = new Set(was.map((c) => c.id));
|
|
66
|
+
const columns = [];
|
|
67
|
+
const added = [];
|
|
68
|
+
for (const { id, name } of given) {
|
|
69
|
+
const trimmed = name.trim();
|
|
70
|
+
if (!trimmed)
|
|
71
|
+
throw invalid("Each column needs a name.");
|
|
72
|
+
if (columns.some((c) => fold(c.name) === fold(trimmed))) {
|
|
73
|
+
throw invalid(`There's already a column called “${trimmed}”.`);
|
|
74
|
+
}
|
|
75
|
+
if (id && known.has(id) && !columns.some((c) => c.id === id)) {
|
|
76
|
+
columns.push({ id, name: trimmed });
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const column = {
|
|
80
|
+
id: columnId(trimmed, [...known, ...columns.map((c) => c.id)]),
|
|
81
|
+
name: trimmed,
|
|
82
|
+
};
|
|
83
|
+
columns.push(column);
|
|
84
|
+
added.push(column);
|
|
85
|
+
}
|
|
86
|
+
const removed = was.filter((c) => !columns.some((kept) => kept.id === c.id));
|
|
87
|
+
return { columns, added, removed };
|
|
88
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Due dates (`YYYY-MM-DD`) against today: how many days away one is, and
|
|
3
|
+
* today as a day where the reader is (the browser's own zone; the server's
|
|
4
|
+
* clock for agents). Pure.
|
|
5
|
+
*/
|
|
6
|
+
/** Today, as `YYYY-MM-DD`, in the local zone. */
|
|
7
|
+
export declare const todayOf: (now?: Date) => string;
|
|
8
|
+
/** Days from `today` to `due`: 0 today, 1 tomorrow, -2 two days ago. */
|
|
9
|
+
export declare const daysUntil: (due: string, today: string) => number;
|
|
10
|
+
/** A due date as an agent reads it: "due 2026-11-02 (in 4 days)", "overdue since 2026-10-27". */
|
|
11
|
+
export declare function dueSaid(due: string, today: string, done?: boolean): string;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Due dates (`YYYY-MM-DD`) against today: how many days away one is, and
|
|
3
|
+
* today as a day where the reader is (the browser's own zone; the server's
|
|
4
|
+
* clock for agents). Pure.
|
|
5
|
+
*/
|
|
6
|
+
/** Today, as `YYYY-MM-DD`, in the local zone. */
|
|
7
|
+
export const todayOf = (now = new Date()) => `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, "0")}-${String(now.getDate()).padStart(2, "0")}`;
|
|
8
|
+
/** Days from `today` to `due`: 0 today, 1 tomorrow, -2 two days ago. */
|
|
9
|
+
export const daysUntil = (due, today) => Math.round((Date.parse(`${due}T00:00:00Z`) - Date.parse(`${today}T00:00:00Z`)) / 86_400_000);
|
|
10
|
+
/** A due date as an agent reads it: "due 2026-11-02 (in 4 days)", "overdue since 2026-10-27". */
|
|
11
|
+
export function dueSaid(due, today, done = false) {
|
|
12
|
+
const days = daysUntil(due, today);
|
|
13
|
+
if (done)
|
|
14
|
+
return `was due ${due}`;
|
|
15
|
+
if (days < 0)
|
|
16
|
+
return `overdue: was due ${due} (${-days} day${days === -1 ? "" : "s"} ago)`;
|
|
17
|
+
if (days === 0)
|
|
18
|
+
return `due today (${due})`;
|
|
19
|
+
if (days === 1)
|
|
20
|
+
return `due tomorrow (${due})`;
|
|
21
|
+
return `due ${due} (in ${days} days)`;
|
|
22
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What boards' Actions refuse with, in words: something asked that can't be
|
|
3
|
+
* (`invalid`), something that isn't there or isn't reached (`not_found`:
|
|
4
|
+
* the rules keep what someone can't read out of sight, so the two are one),
|
|
5
|
+
* and a change the rules turned down (`forbidden`: they may read it there,
|
|
6
|
+
* not change it).
|
|
7
|
+
*/
|
|
8
|
+
export declare const invalid: (message: string) => Error & {
|
|
9
|
+
code: string;
|
|
10
|
+
};
|
|
11
|
+
export declare const notFound: (message: string) => Error & {
|
|
12
|
+
code: string;
|
|
13
|
+
};
|
|
14
|
+
export declare const forbidden: (message: string) => Error & {
|
|
15
|
+
code: string;
|
|
16
|
+
};
|
|
17
|
+
/** A change to a board or its cards that the rules turned down. */
|
|
18
|
+
export declare const READ_ONLY = "You can read this board, but only its space's editors change it.";
|
|
19
|
+
/** A change the rules turned down, said in words. */
|
|
20
|
+
export declare const readOnly: (message?: string) => Error & {
|
|
21
|
+
code: string;
|
|
22
|
+
};
|
|
23
|
+
/** A refusal by the rules, said in words (`message`); anything else, as it was. */
|
|
24
|
+
export declare const said: (message?: string) => (error: unknown) => never;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What boards' Actions refuse with, in words: something asked that can't be
|
|
3
|
+
* (`invalid`), something that isn't there or isn't reached (`not_found`:
|
|
4
|
+
* the rules keep what someone can't read out of sight, so the two are one),
|
|
5
|
+
* and a change the rules turned down (`forbidden`: they may read it there,
|
|
6
|
+
* not change it).
|
|
7
|
+
*/
|
|
8
|
+
export const invalid = (message) => Object.assign(new Error(message), { code: "invalid" });
|
|
9
|
+
export const notFound = (message) => Object.assign(new Error(message), { code: "not_found" });
|
|
10
|
+
export const forbidden = (message) => Object.assign(new Error(message), { code: "forbidden" });
|
|
11
|
+
/** A change to a board or its cards that the rules turned down. */
|
|
12
|
+
export const READ_ONLY = "You can read this board, but only its space's editors change it.";
|
|
13
|
+
/** A change the rules turned down, said in words. */
|
|
14
|
+
export const readOnly = (message = READ_ONLY) => forbidden(message);
|
|
15
|
+
/** A refusal by the rules, said in words (`message`); anything else, as it was. */
|
|
16
|
+
export const said = (message = READ_ONLY) => (error) => {
|
|
17
|
+
if (error.code === "forbidden")
|
|
18
|
+
throw forbidden(message);
|
|
19
|
+
throw error;
|
|
20
|
+
};
|