@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
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Copilotz Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,57 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @copilotz/work
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Kanban boards and shared Markdown documents, in a space, for people and agents: two plugins for
|
|
4
|
+
[Copilotz](https://github.com/copilotzhq/copilotz), beside its `chat` and `spaces`.
|
|
5
|
+
|
|
6
|
+
```sh
|
|
7
|
+
npm install @copilotz/work copilotz # Node 24+, Bun
|
|
8
|
+
deno add jsr:@copilotz/work jsr:@copilotz/copilotz
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
It goes with Copilotz at the same version (they're released together): `@copilotz/work@x.y.z` with
|
|
12
|
+
`copilotz@x.y.z`.
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import { createRuntime } from "copilotz";
|
|
16
|
+
import { models } from "copilotz/plugins/models";
|
|
17
|
+
import { chat } from "copilotz/plugins/agents";
|
|
18
|
+
import { access } from "copilotz/plugins/access";
|
|
19
|
+
import { boards, documents } from "@copilotz/work";
|
|
20
|
+
|
|
21
|
+
const runtime = await createRuntime({
|
|
22
|
+
store,
|
|
23
|
+
plugins: [models, chat, ...access, boards, documents, app],
|
|
24
|
+
});
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
// In the browser, beside the web shell's front ends:
|
|
29
|
+
import { boardsWeb, documentsWeb } from "@copilotz/work/web";
|
|
30
|
+
|
|
31
|
+
await web({ plugins: [webShell, chatWeb, spacesWeb, boardsWeb, documentsWeb], root });
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
| Import | What it has |
|
|
35
|
+
| ------------------------- | ------------------------------------------------------------------------------------ |
|
|
36
|
+
| `@copilotz/work` | `boards` (kanban), `documents` (shared Markdown with versions and merges) |
|
|
37
|
+
| `@copilotz/work/web` | `boardsWeb`, `documentsWeb`: a space's Board and Documents tabs, their pages |
|
|
38
|
+
| `@copilotz/work/contract` | their shapes (`Board`, `Card`, `Document`…) and addresses, for plugins built on them |
|
|
39
|
+
|
|
40
|
+
Both live in spaces (read where the space is read, changed where it's written), change only through
|
|
41
|
+
their Actions, and give agents tools wherever a conversation is in a space.
|
|
42
|
+
|
|
43
|
+
- **Boards** are kanban: columns in order (a new one starts with Backlog, To do, Doing, Blocked, In
|
|
44
|
+
review and Done), cards dragged within and across them, owners, labels and due dates. Its
|
|
45
|
+
collections are `board` and `card`; its tools, `list_boards`, `read_board`, `create_board`,
|
|
46
|
+
`create_card`, `update_card` and `move_card`. The app words the one line about agents on an empty
|
|
47
|
+
Board tab (`boardsText: { agentHint: "…" }`, a resource).
|
|
48
|
+
- **Documents** are Markdown where every save is a version (who, what, when), a save that started
|
|
49
|
+
from an old version is merged line by line or refused as a `conflict` for the person to settle, an
|
|
50
|
+
old version comes back as a new one, and who has one open is live. Its collections are `document`,
|
|
51
|
+
`documentVersion` and `documentPresence`; its tools, `list_documents`, `read_document`,
|
|
52
|
+
`write_document`, `append_document` and `edit_document`.
|
|
53
|
+
|
|
54
|
+
Through 1.0.0-rc.32 these were `copilotz/plugins/work` and `copilotz/plugins/work/web`. Their names
|
|
55
|
+
(collections, Actions, events, Views, resources) are the same, so an app's data stays as it is: only
|
|
56
|
+
its imports change. See
|
|
57
|
+
[design/plugins.md](https://github.com/copilotzhq/copilotz/blob/main/design/plugins.md).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const createBoardAction: import("copilotz").ActionDef;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `board.create`: a board in a space, by someone who may write there (the
|
|
3
|
+
* rules say), with the team's usual columns (Backlog, To do, Doing,
|
|
4
|
+
* Blocked, In review, Done) unless it's given its own.
|
|
5
|
+
*/
|
|
6
|
+
import { defineAction, people } from "copilotz";
|
|
7
|
+
import { columnsNamed, DEFAULT_COLUMNS, MOST_COLUMNS } from "../shared/columns.js";
|
|
8
|
+
import { invalid, said } from "../shared/errors.js";
|
|
9
|
+
import { COLUMN_NAME, DESCRIPTION, keyOf, NAME, newId } from "../shared/fields.js";
|
|
10
|
+
export const createBoardAction = defineAction({
|
|
11
|
+
description: "Makes a board in a space, with the usual columns unless given its own",
|
|
12
|
+
input: {
|
|
13
|
+
type: "object",
|
|
14
|
+
properties: {
|
|
15
|
+
in: { type: "string", minLength: 1 },
|
|
16
|
+
name: NAME,
|
|
17
|
+
description: DESCRIPTION,
|
|
18
|
+
/** Its columns' names, left to right. */
|
|
19
|
+
columns: { type: "array", minItems: 1, maxItems: MOST_COLUMNS, items: COLUMN_NAME },
|
|
20
|
+
},
|
|
21
|
+
required: ["in", "name"],
|
|
22
|
+
additionalProperties: false,
|
|
23
|
+
},
|
|
24
|
+
allow: people,
|
|
25
|
+
run: async (ctx, input) => {
|
|
26
|
+
const name = input.name.trim();
|
|
27
|
+
if (!name)
|
|
28
|
+
throw invalid("A board needs a name.");
|
|
29
|
+
const names = input.columns?.map((c) => c.trim()).filter(Boolean);
|
|
30
|
+
if (names && new Set(names.map((n) => n.toLowerCase())).size !== names.length) {
|
|
31
|
+
throw invalid("Each column needs a name of its own.");
|
|
32
|
+
}
|
|
33
|
+
const columns = names?.length ? columnsNamed(names) : DEFAULT_COLUMNS.map((c) => ({ ...c }));
|
|
34
|
+
const board = newId();
|
|
35
|
+
const description = input.description?.trim();
|
|
36
|
+
await ctx.db.collection("board").insertOne({
|
|
37
|
+
_id: board,
|
|
38
|
+
in: input.in,
|
|
39
|
+
name,
|
|
40
|
+
...(description ? { description } : {}),
|
|
41
|
+
columns,
|
|
42
|
+
by: keyOf(ctx.actor),
|
|
43
|
+
at: new Date().toISOString(),
|
|
44
|
+
}).catch(said("Only editors of a space add boards to it."));
|
|
45
|
+
return { board, name, columns };
|
|
46
|
+
},
|
|
47
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const createCardAction: import("copilotz").ActionDef;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `card.create`: a card on a board, by an editor of its space (the rules
|
|
3
|
+
* say): its title, and maybe its column (the first, unless given), where in
|
|
4
|
+
* it (the bottom, unless `at: "top"`), its description, assignee (someone in
|
|
5
|
+
* the space), labels and due date. The board is read in the same commit, so
|
|
6
|
+
* the card never lands in a column that was just removed.
|
|
7
|
+
*/
|
|
8
|
+
import { defineAction, people } from "copilotz";
|
|
9
|
+
import { invalid, notFound, said } from "../shared/errors.js";
|
|
10
|
+
import { ASSIGNEE, DESCRIPTION, DUE, dueOf, keyOf, LABELS, labelsOf, newId, POSITION, TITLE, } from "../shared/fields.js";
|
|
11
|
+
import { boardOf, inSpace } from "../shared/load.js";
|
|
12
|
+
import { STEP } from "../shared/order.js";
|
|
13
|
+
export const createCardAction = defineAction({
|
|
14
|
+
description: "Adds a card to a board: a title, and maybe its column, description, assignee, " +
|
|
15
|
+
"labels and due date",
|
|
16
|
+
input: {
|
|
17
|
+
type: "object",
|
|
18
|
+
properties: {
|
|
19
|
+
board: { type: "string", minLength: 1 },
|
|
20
|
+
title: TITLE,
|
|
21
|
+
/** Its column's id: the board's first column, unless given. */
|
|
22
|
+
column: { type: "string" },
|
|
23
|
+
at: POSITION,
|
|
24
|
+
description: DESCRIPTION,
|
|
25
|
+
assignee: ASSIGNEE,
|
|
26
|
+
labels: LABELS,
|
|
27
|
+
due: DUE,
|
|
28
|
+
},
|
|
29
|
+
required: ["board", "title"],
|
|
30
|
+
additionalProperties: false,
|
|
31
|
+
},
|
|
32
|
+
allow: people,
|
|
33
|
+
run: async (ctx, input) => {
|
|
34
|
+
const title = input.title.trim();
|
|
35
|
+
if (!title)
|
|
36
|
+
throw invalid("A card needs a title.");
|
|
37
|
+
const known = await boardOf(ctx, input.board);
|
|
38
|
+
if (input.assignee)
|
|
39
|
+
await inSpace(ctx, known.in, input.assignee);
|
|
40
|
+
const due = input.due ? dueOf(input.due) : undefined;
|
|
41
|
+
const labels = input.labels ? labelsOf(input.labels) : [];
|
|
42
|
+
const description = input.description?.trim();
|
|
43
|
+
const card = newId();
|
|
44
|
+
const at = new Date().toISOString();
|
|
45
|
+
const placed = await ctx.transaction(async (tx) => {
|
|
46
|
+
const board = await tx.db.collection("board").findOne({ _id: known._id });
|
|
47
|
+
if (!board)
|
|
48
|
+
throw notFound("That board was just deleted.");
|
|
49
|
+
const column = input.column
|
|
50
|
+
? board.columns.find((c) => c.id === input.column)
|
|
51
|
+
: board.columns[0];
|
|
52
|
+
if (!column) {
|
|
53
|
+
throw invalid(`“${board.name}” has no column “${input.column}”.`);
|
|
54
|
+
}
|
|
55
|
+
const top = input.at === "top";
|
|
56
|
+
const [end] = await tx.db.collection("card").find({ in: board.in, board: board._id, column: column.id }, { sort: { order: top ? 1 : -1 }, limit: 1 });
|
|
57
|
+
const order = end ? end.order + (top ? -STEP : STEP) : STEP;
|
|
58
|
+
await tx.db.collection("card").insertOne({
|
|
59
|
+
_id: card,
|
|
60
|
+
in: board.in,
|
|
61
|
+
board: board._id,
|
|
62
|
+
column: column.id,
|
|
63
|
+
order,
|
|
64
|
+
title,
|
|
65
|
+
...(description ? { description } : {}),
|
|
66
|
+
...(input.assignee ? { assignee: input.assignee } : {}),
|
|
67
|
+
...(labels.length ? { labels } : {}),
|
|
68
|
+
...(due ? { due } : {}),
|
|
69
|
+
by: keyOf(ctx.actor),
|
|
70
|
+
at,
|
|
71
|
+
});
|
|
72
|
+
return { column, order, board };
|
|
73
|
+
}).catch(said());
|
|
74
|
+
return {
|
|
75
|
+
card,
|
|
76
|
+
board: placed.board._id,
|
|
77
|
+
column: placed.column.id,
|
|
78
|
+
columnName: placed.column.name,
|
|
79
|
+
order: placed.order,
|
|
80
|
+
title,
|
|
81
|
+
};
|
|
82
|
+
},
|
|
83
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const deleteBoardAction: import("copilotz").ActionDef;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `board.delete`: removes a board and every card on it, by an editor of its
|
|
3
|
+
* space (the rules say), in one commit. Conversations that mention it keep
|
|
4
|
+
* what they said.
|
|
5
|
+
*/
|
|
6
|
+
import { defineAction, people } from "copilotz";
|
|
7
|
+
import { readOnly, said } from "../shared/errors.js";
|
|
8
|
+
import { boardOf } from "../shared/load.js";
|
|
9
|
+
export const deleteBoardAction = defineAction({
|
|
10
|
+
description: "Deletes a board, with its cards",
|
|
11
|
+
input: {
|
|
12
|
+
type: "object",
|
|
13
|
+
properties: { board: { type: "string", minLength: 1 } },
|
|
14
|
+
required: ["board"],
|
|
15
|
+
additionalProperties: false,
|
|
16
|
+
},
|
|
17
|
+
allow: people,
|
|
18
|
+
run: async (ctx, input) => {
|
|
19
|
+
const found = await boardOf(ctx, input.board);
|
|
20
|
+
await ctx.transaction(async (tx) => {
|
|
21
|
+
await tx.db.collection("card").deleteMany({ in: found.in, board: found._id }, {
|
|
22
|
+
writeConcern: { w: 0 },
|
|
23
|
+
});
|
|
24
|
+
const gone = await tx.db.collection("board").deleteOne({ _id: found._id });
|
|
25
|
+
if (!gone.deletedCount)
|
|
26
|
+
throw readOnly();
|
|
27
|
+
}).catch(said());
|
|
28
|
+
return { deleted: found._id, name: found.name };
|
|
29
|
+
},
|
|
30
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const deleteCardAction: import("copilotz").ActionDef;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `card.delete`: removes a card from its board, by an editor of its space
|
|
3
|
+
* (the rules say).
|
|
4
|
+
*/
|
|
5
|
+
import { defineAction, people } from "copilotz";
|
|
6
|
+
import { readOnly, said } from "../shared/errors.js";
|
|
7
|
+
import { cardOf } from "../shared/load.js";
|
|
8
|
+
export const deleteCardAction = defineAction({
|
|
9
|
+
description: "Deletes a card",
|
|
10
|
+
input: {
|
|
11
|
+
type: "object",
|
|
12
|
+
properties: { card: { type: "string", minLength: 1 } },
|
|
13
|
+
required: ["card"],
|
|
14
|
+
additionalProperties: false,
|
|
15
|
+
},
|
|
16
|
+
allow: people,
|
|
17
|
+
run: async (ctx, input) => {
|
|
18
|
+
const found = await cardOf(ctx, input.card);
|
|
19
|
+
const gone = await ctx.db.collection("card").deleteOne({ _id: found._id }).catch(said());
|
|
20
|
+
if (!gone.deletedCount)
|
|
21
|
+
throw readOnly();
|
|
22
|
+
return { deleted: found._id, board: found.board, title: found.title };
|
|
23
|
+
},
|
|
24
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const moveCardAction: import("copilotz").ActionDef;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `card.move`: moves a card, by an editor of its space (the rules say): to a
|
|
3
|
+
* column (its own, unless given) and a place there: just before or after
|
|
4
|
+
* another card (whose column it then joins), or at the top or bottom (the
|
|
5
|
+
* bottom, unless given). It takes the midpoint of its new neighbours'
|
|
6
|
+
* orders; when there's no room left between them, the column is numbered
|
|
7
|
+
* again. The board and the column are read in the same commit as the move.
|
|
8
|
+
*/
|
|
9
|
+
import { defineAction, people } from "copilotz";
|
|
10
|
+
import { invalid, notFound, readOnly, said } from "../shared/errors.js";
|
|
11
|
+
import { keyOf, POSITION } from "../shared/fields.js";
|
|
12
|
+
import { byOrder, indexOf, orderAt } from "../shared/order.js";
|
|
13
|
+
export const moveCardAction = defineAction({
|
|
14
|
+
description: "Moves a card: to a column, before or after another card, or to its top or bottom",
|
|
15
|
+
input: {
|
|
16
|
+
type: "object",
|
|
17
|
+
properties: {
|
|
18
|
+
card: { type: "string", minLength: 1 },
|
|
19
|
+
/** The column's id: the card's own, unless given (or another card's, with before or after). */
|
|
20
|
+
column: { type: "string" },
|
|
21
|
+
before: { type: "string" },
|
|
22
|
+
after: { type: "string" },
|
|
23
|
+
at: POSITION,
|
|
24
|
+
},
|
|
25
|
+
required: ["card"],
|
|
26
|
+
additionalProperties: false,
|
|
27
|
+
},
|
|
28
|
+
allow: people,
|
|
29
|
+
run: async (ctx, input) => {
|
|
30
|
+
const places = [input.before, input.after, input.at].filter((p) => p !== undefined);
|
|
31
|
+
if (places.length > 1) {
|
|
32
|
+
throw invalid("Say one place: before a card, after one, or top or bottom.");
|
|
33
|
+
}
|
|
34
|
+
if (input.before === input.card || input.after === input.card) {
|
|
35
|
+
throw invalid("A card can't go next to itself.");
|
|
36
|
+
}
|
|
37
|
+
const place = input.before !== undefined
|
|
38
|
+
? { before: input.before }
|
|
39
|
+
: input.after !== undefined
|
|
40
|
+
? { after: input.after }
|
|
41
|
+
: input.at
|
|
42
|
+
? { at: input.at }
|
|
43
|
+
: undefined;
|
|
44
|
+
const by = keyOf(ctx.actor);
|
|
45
|
+
const updated = new Date().toISOString();
|
|
46
|
+
return await ctx.transaction(async (tx) => {
|
|
47
|
+
const cards = tx.db.collection("card");
|
|
48
|
+
const card = await cards.findOne({ _id: input.card });
|
|
49
|
+
if (!card)
|
|
50
|
+
throw notFound("No such card here: it may have been deleted.");
|
|
51
|
+
const board = await tx.db.collection("board").findOne({ _id: card.board });
|
|
52
|
+
if (!board)
|
|
53
|
+
throw notFound("Its board was just deleted.");
|
|
54
|
+
const neighbour = place && !("at" in place)
|
|
55
|
+
? await cards.findOne({ _id: "before" in place ? place.before : place.after })
|
|
56
|
+
: undefined;
|
|
57
|
+
if (neighbour === null || (neighbour && neighbour.board !== board._id)) {
|
|
58
|
+
throw invalid("That card isn't on this board any more.");
|
|
59
|
+
}
|
|
60
|
+
const target = neighbour?.column ?? input.column ?? card.column;
|
|
61
|
+
if (input.column && neighbour && input.column !== neighbour.column) {
|
|
62
|
+
throw invalid("That card is in another column.");
|
|
63
|
+
}
|
|
64
|
+
const column = board.columns.find((c) => c.id === target);
|
|
65
|
+
if (!column)
|
|
66
|
+
throw invalid(`“${board.name}” has no column “${target}”.`);
|
|
67
|
+
const others = byOrder(await cards.find({ in: board.in, board: board._id, column: column.id })).filter((c) => c._id !== card._id);
|
|
68
|
+
const { order, renumbered } = orderAt(others, indexOf(others, place));
|
|
69
|
+
const moved = await cards.updateOne({ _id: card._id }, { $set: { column: column.id, order, updatedBy: by, updated } });
|
|
70
|
+
if (!moved.matchedCount)
|
|
71
|
+
throw readOnly();
|
|
72
|
+
for (const [id, fresh] of Object.entries(renumbered)) {
|
|
73
|
+
await cards.updateOne({ _id: id }, { $set: { order: fresh } }, { writeConcern: { w: 0 } });
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
card: card._id,
|
|
77
|
+
board: board._id,
|
|
78
|
+
column: column.id,
|
|
79
|
+
columnName: column.name,
|
|
80
|
+
from: card.column,
|
|
81
|
+
order,
|
|
82
|
+
};
|
|
83
|
+
}).catch(said());
|
|
84
|
+
},
|
|
85
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const updateBoardAction: import("copilotz").ActionDef;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `board.update`: changes a board, by an editor of its space (the rules
|
|
3
|
+
* say): its name, its description (`null` clears it), whether it's
|
|
4
|
+
* archived, and its columns: the whole list in its new order, each with the
|
|
5
|
+
* id it has (renamed, moved) or none (new). A column left out is removed
|
|
6
|
+
* when it's empty; one with cards only when `into` says which kept column
|
|
7
|
+
* they go to (at its bottom, in their order). All in one commit.
|
|
8
|
+
*/
|
|
9
|
+
import { defineAction, people } from "copilotz";
|
|
10
|
+
import { changeColumns, MOST_COLUMNS } from "../shared/columns.js";
|
|
11
|
+
import { invalid, readOnly, said } from "../shared/errors.js";
|
|
12
|
+
import { COLUMN_NAME, DESCRIPTION, keyOf, NAME } from "../shared/fields.js";
|
|
13
|
+
import { boardOf } from "../shared/load.js";
|
|
14
|
+
import { byOrder, STEP } from "../shared/order.js";
|
|
15
|
+
export const updateBoardAction = defineAction({
|
|
16
|
+
description: "Changes a board: its name, description, columns, or whether it's archived",
|
|
17
|
+
input: {
|
|
18
|
+
type: "object",
|
|
19
|
+
properties: {
|
|
20
|
+
board: { type: "string", minLength: 1 },
|
|
21
|
+
name: NAME,
|
|
22
|
+
description: { anyOf: [DESCRIPTION, { type: "null" }] },
|
|
23
|
+
archived: { type: "boolean" },
|
|
24
|
+
columns: {
|
|
25
|
+
type: "array",
|
|
26
|
+
minItems: 1,
|
|
27
|
+
maxItems: MOST_COLUMNS,
|
|
28
|
+
items: {
|
|
29
|
+
type: "object",
|
|
30
|
+
properties: { id: { type: "string" }, name: COLUMN_NAME },
|
|
31
|
+
required: ["name"],
|
|
32
|
+
additionalProperties: false,
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
/** Where a removed column's cards go: a column the board keeps. */
|
|
36
|
+
into: { type: "string" },
|
|
37
|
+
},
|
|
38
|
+
required: ["board"],
|
|
39
|
+
additionalProperties: false,
|
|
40
|
+
},
|
|
41
|
+
allow: people,
|
|
42
|
+
run: async (ctx, input) => {
|
|
43
|
+
const found = await boardOf(ctx, input.board);
|
|
44
|
+
const name = input.name?.trim();
|
|
45
|
+
if (input.name !== undefined && !name)
|
|
46
|
+
throw invalid("A board needs a name.");
|
|
47
|
+
const description = typeof input.description === "string"
|
|
48
|
+
? input.description.trim()
|
|
49
|
+
: input.description;
|
|
50
|
+
const change = input.columns ? changeColumns(found.columns, input.columns) : undefined;
|
|
51
|
+
const set = {
|
|
52
|
+
...(name ? { name } : {}),
|
|
53
|
+
...(description ? { description } : {}),
|
|
54
|
+
...(change ? { columns: change.columns } : {}),
|
|
55
|
+
...(input.archived ? { archived: found.archived ?? new Date().toISOString() } : {}),
|
|
56
|
+
updatedBy: keyOf(ctx.actor),
|
|
57
|
+
updated: new Date().toISOString(),
|
|
58
|
+
};
|
|
59
|
+
const unset = {
|
|
60
|
+
...(description === null || description === "" ? { description: "" } : {}),
|
|
61
|
+
...(input.archived === false ? { archived: "" } : {}),
|
|
62
|
+
};
|
|
63
|
+
const update = { $set: set, ...(Object.keys(unset).length ? { $unset: unset } : {}) };
|
|
64
|
+
const removed = change?.removed.map((c) => c.id) ?? [];
|
|
65
|
+
const into = input.into ? change?.columns.find((c) => c.id === input.into) : undefined;
|
|
66
|
+
if (input.into && !into) {
|
|
67
|
+
throw invalid("Cards can only go to a column the board keeps.");
|
|
68
|
+
}
|
|
69
|
+
const moved = await ctx.transaction(async (tx) => {
|
|
70
|
+
const changed = await tx.db.collection("board").updateOne({ _id: found._id }, update);
|
|
71
|
+
if (!changed.matchedCount)
|
|
72
|
+
throw readOnly();
|
|
73
|
+
// The removed columns' cards, read in the commit that removes them, so none is left behind.
|
|
74
|
+
const stranded = removed.length
|
|
75
|
+
? byOrder(await tx.db.collection("card").find({
|
|
76
|
+
in: found.in,
|
|
77
|
+
board: found._id,
|
|
78
|
+
column: { $in: removed },
|
|
79
|
+
}))
|
|
80
|
+
: [];
|
|
81
|
+
if (stranded.length && !into) {
|
|
82
|
+
const full = change.removed.filter((c) => stranded.some((s) => s.column === c.id));
|
|
83
|
+
const one = full.length === 1;
|
|
84
|
+
throw Object.assign(new Error(`${full.map((c) => `“${c.name}”`).join(", ")} still ${one ? "has" : "have"} ` +
|
|
85
|
+
`${stranded.length === 1 ? "a card" : "cards"}: move ${stranded.length === 1 ? "it" : "them"} first, or say which column ${stranded.length === 1 ? "it goes" : "they go"} to.`), { code: "not_empty", cards: stranded.length });
|
|
86
|
+
}
|
|
87
|
+
if (!stranded.length || !into)
|
|
88
|
+
return 0;
|
|
89
|
+
// At the bottom of where they go, in the order they had, column by column.
|
|
90
|
+
const last = await tx.db.collection("card").find({ in: found.in, board: found._id, column: into.id }, { sort: { order: -1 }, limit: 1 });
|
|
91
|
+
let order = (last[0]?.order ?? 0) + STEP;
|
|
92
|
+
const cards = tx.db.collection("card");
|
|
93
|
+
for (const column of change.removed) {
|
|
94
|
+
for (const card of stranded.filter((c) => c.column === column.id)) {
|
|
95
|
+
await cards.updateOne({ _id: card._id }, {
|
|
96
|
+
$set: { column: into.id, order, updatedBy: keyOf(ctx.actor), updated: set.updated },
|
|
97
|
+
}, { writeConcern: { w: 0 } });
|
|
98
|
+
order += STEP;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return stranded.length;
|
|
102
|
+
}).catch(said());
|
|
103
|
+
return {
|
|
104
|
+
board: found._id,
|
|
105
|
+
name: name ?? found.name,
|
|
106
|
+
columns: change?.columns ?? found.columns,
|
|
107
|
+
...(moved ? { moved } : {}),
|
|
108
|
+
};
|
|
109
|
+
},
|
|
110
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const updateCardAction: import("copilotz").ActionDef;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `card.update`: changes a card, by an editor of its space (the rules say):
|
|
3
|
+
* any of its title, description, assignee (someone in the space), labels and
|
|
4
|
+
* due date; `null` clears one. Moving it is `card.move`.
|
|
5
|
+
*/
|
|
6
|
+
import { defineAction, people } from "copilotz";
|
|
7
|
+
import { invalid, readOnly, said } from "../shared/errors.js";
|
|
8
|
+
import { ASSIGNEE, DESCRIPTION, DUE, dueOf, keyOf, LABELS, labelsOf, TITLE, } from "../shared/fields.js";
|
|
9
|
+
import { cardOf, inSpace } from "../shared/load.js";
|
|
10
|
+
const orNull = (schema) => ({ anyOf: [schema, { type: "null" }] });
|
|
11
|
+
export const updateCardAction = defineAction({
|
|
12
|
+
description: "Changes a card: its title, description, assignee, labels or due date (null clears)",
|
|
13
|
+
input: {
|
|
14
|
+
type: "object",
|
|
15
|
+
properties: {
|
|
16
|
+
card: { type: "string", minLength: 1 },
|
|
17
|
+
title: TITLE,
|
|
18
|
+
description: orNull(DESCRIPTION),
|
|
19
|
+
assignee: orNull(ASSIGNEE),
|
|
20
|
+
labels: orNull(LABELS),
|
|
21
|
+
due: orNull(DUE),
|
|
22
|
+
},
|
|
23
|
+
required: ["card"],
|
|
24
|
+
additionalProperties: false,
|
|
25
|
+
},
|
|
26
|
+
allow: people,
|
|
27
|
+
run: async (ctx, input) => {
|
|
28
|
+
const found = await cardOf(ctx, input.card);
|
|
29
|
+
const set = {};
|
|
30
|
+
const unset = {};
|
|
31
|
+
if (input.title !== undefined) {
|
|
32
|
+
const title = input.title.trim();
|
|
33
|
+
if (!title)
|
|
34
|
+
throw invalid("A card needs a title.");
|
|
35
|
+
set.title = title;
|
|
36
|
+
}
|
|
37
|
+
const description = typeof input.description === "string"
|
|
38
|
+
? input.description.trim()
|
|
39
|
+
: input.description;
|
|
40
|
+
if (description)
|
|
41
|
+
set.description = description;
|
|
42
|
+
else if (description !== undefined)
|
|
43
|
+
unset.description = "";
|
|
44
|
+
if (input.assignee) {
|
|
45
|
+
if (input.assignee !== found.assignee)
|
|
46
|
+
await inSpace(ctx, found.in, input.assignee);
|
|
47
|
+
set.assignee = input.assignee;
|
|
48
|
+
}
|
|
49
|
+
else if (input.assignee === null)
|
|
50
|
+
unset.assignee = "";
|
|
51
|
+
const labels = input.labels ? labelsOf(input.labels) : input.labels;
|
|
52
|
+
if (labels?.length)
|
|
53
|
+
set.labels = labels;
|
|
54
|
+
else if (labels !== undefined)
|
|
55
|
+
unset.labels = "";
|
|
56
|
+
if (input.due)
|
|
57
|
+
set.due = dueOf(input.due);
|
|
58
|
+
else if (input.due === null)
|
|
59
|
+
unset.due = "";
|
|
60
|
+
set.updatedBy = keyOf(ctx.actor);
|
|
61
|
+
set.updated = new Date().toISOString();
|
|
62
|
+
const changed = await ctx.db.collection("card").updateOne({ _id: found._id }, { $set: set, ...(Object.keys(unset).length ? { $unset: unset } : {}) }).catch(said());
|
|
63
|
+
if (!changed.matchedCount)
|
|
64
|
+
throw readOnly();
|
|
65
|
+
return { card: found._id, board: found.board };
|
|
66
|
+
},
|
|
67
|
+
});
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
export declare const board: {
|
|
2
|
+
schema: {
|
|
3
|
+
readonly type: "object";
|
|
4
|
+
readonly properties: {
|
|
5
|
+
readonly in: {
|
|
6
|
+
readonly type: "string";
|
|
7
|
+
};
|
|
8
|
+
readonly name: {
|
|
9
|
+
readonly type: "string";
|
|
10
|
+
};
|
|
11
|
+
readonly description: {
|
|
12
|
+
readonly type: "string";
|
|
13
|
+
};
|
|
14
|
+
readonly columns: {
|
|
15
|
+
readonly type: "array";
|
|
16
|
+
readonly items: {
|
|
17
|
+
readonly type: "object";
|
|
18
|
+
readonly properties: {
|
|
19
|
+
readonly id: {
|
|
20
|
+
readonly type: "string";
|
|
21
|
+
};
|
|
22
|
+
readonly name: {
|
|
23
|
+
readonly type: "string";
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
readonly required: readonly ["id", "name"];
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
readonly archived: {
|
|
30
|
+
readonly type: "string";
|
|
31
|
+
};
|
|
32
|
+
readonly by: {
|
|
33
|
+
readonly type: "string";
|
|
34
|
+
};
|
|
35
|
+
readonly at: {
|
|
36
|
+
readonly type: "string";
|
|
37
|
+
};
|
|
38
|
+
readonly updatedBy: {
|
|
39
|
+
readonly type: "string";
|
|
40
|
+
};
|
|
41
|
+
readonly updated: {
|
|
42
|
+
readonly type: "string";
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
readonly required: readonly ["in", "name", "columns", "at"];
|
|
46
|
+
};
|
|
47
|
+
events?: boolean;
|
|
48
|
+
records?: boolean;
|
|
49
|
+
durable?: false;
|
|
50
|
+
indexes?: string[][];
|
|
51
|
+
private?: string[];
|
|
52
|
+
queries?: Record<string, import("copilotz").QueryDef<{
|
|
53
|
+
[x: string]: unknown;
|
|
54
|
+
description?: string | undefined;
|
|
55
|
+
by?: string | undefined;
|
|
56
|
+
updatedBy?: string | undefined;
|
|
57
|
+
updated?: string | undefined;
|
|
58
|
+
archived?: string | undefined;
|
|
59
|
+
at: string;
|
|
60
|
+
name: string;
|
|
61
|
+
in: string;
|
|
62
|
+
columns: {
|
|
63
|
+
[x: string]: unknown;
|
|
64
|
+
id: string;
|
|
65
|
+
name: string;
|
|
66
|
+
}[];
|
|
67
|
+
} & {
|
|
68
|
+
_id: string;
|
|
69
|
+
}>> | undefined;
|
|
70
|
+
vectors?: string[];
|
|
71
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Boards: kanban boards in a space (`in`), each with its columns in order.
|
|
3
|
+
* Shared through the spaces plugin (`shared: { board: {} }`), so everyone
|
|
4
|
+
* there reads them and its editors change them; people change them with
|
|
5
|
+
* `board.*`, agents with their tools.
|
|
6
|
+
*/
|
|
7
|
+
import { defineCollection } from "copilotz";
|
|
8
|
+
export const board = defineCollection({
|
|
9
|
+
schema: {
|
|
10
|
+
type: "object",
|
|
11
|
+
properties: {
|
|
12
|
+
in: { type: "string" },
|
|
13
|
+
name: { type: "string" },
|
|
14
|
+
description: { type: "string" },
|
|
15
|
+
columns: {
|
|
16
|
+
type: "array",
|
|
17
|
+
items: {
|
|
18
|
+
type: "object",
|
|
19
|
+
properties: { id: { type: "string" }, name: { type: "string" } },
|
|
20
|
+
required: ["id", "name"],
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
archived: { type: "string" },
|
|
24
|
+
by: { type: "string" },
|
|
25
|
+
at: { type: "string" },
|
|
26
|
+
updatedBy: { type: "string" },
|
|
27
|
+
updated: { type: "string" },
|
|
28
|
+
},
|
|
29
|
+
required: ["in", "name", "columns", "at"],
|
|
30
|
+
},
|
|
31
|
+
indexes: [["in"]],
|
|
32
|
+
});
|