@copilotz/work 1.0.0-rc.34 → 1.0.0-rc.36

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.
@@ -9,14 +9,15 @@
9
9
  * who's in the space. Answers are short and name the board with its link.
10
10
  */
11
11
  import { namesFor } from "copilotz/plugins/access/contract";
12
- import { tool } from "copilotz/plugins/agents/contract";
12
+ import { tool, workIn, } from "copilotz/plugins/agents/contract";
13
13
  import { columnOf, fold, stageOf } from "../shared/columns.js";
14
14
  import { dueSaid, todayOf } from "../shared/dates.js";
15
15
  import { byOrder } from "../shared/order.js";
16
16
  import { assigneeSaid, everyone, peopleIn, shown, whoIs } from "../shared/people.js";
17
17
  import { cardNamed, named, onBoard } from "../shared/said.js";
18
18
  const inSpace = (_agent, thread) => !!thread.in;
19
- const NOWHERE = "This conversation isn't in a space, so there's no board here.";
19
+ /** Each tool works here, or in another space its work reaches. */
20
+ const ELSEWHERE = " In another space you can work in, give in (its id).";
20
21
  /** At most `most` characters of `text`, on one line. */
21
22
  const gist = (text, most = 160) => {
22
23
  const flat = (text ?? "").replace(/\s+/g, " ").trim();
@@ -109,12 +110,18 @@ function cardLine(card, people, today, done, names) {
109
110
  const listBoards = tool({
110
111
  offer: inSpace,
111
112
  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;
113
+ "many cards are in each column. Read one with read_board." + ELSEWHERE,
114
+ input: {
115
+ type: "object",
116
+ properties: {
117
+ in: { type: "string", description: "Another space, by its id (your context lists them)." },
118
+ },
119
+ },
120
+ run: async (input, ctx) => {
121
+ const where = await workIn(ctx, input.in, "read");
122
+ if (typeof where === "string")
123
+ return where;
124
+ const space = where.in;
118
125
  const boards = await boardsOf(ctx, space);
119
126
  if (!boards.length)
120
127
  return "No boards in this space yet. Make one with create_board.";
@@ -132,7 +139,7 @@ const listBoards = tool({
132
139
  const active = boards.filter((b) => !b.archived);
133
140
  const archived = boards.filter((b) => b.archived);
134
141
  return [
135
- `${active.length} board${active.length === 1 ? "" : "s"} in this space:`,
142
+ `${active.length} board${active.length === 1 ? "" : "s"} in ${space === ctx.in ? "this" : "that"} space:`,
136
143
  ...active.map(line),
137
144
  ...(archived.length ? ["Archived:", ...archived.map(line)] : []),
138
145
  ].join("\n");
@@ -142,15 +149,19 @@ const readBoard = tool({
142
149
  offer: inSpace,
143
150
  description: "Read a board in this space (by its name or id; without one, the space's " +
144
151
  "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.",
152
+ "due date and a line of its description. Read it before you change it." + ELSEWHERE,
146
153
  input: {
147
154
  type: "object",
148
- properties: { board: { type: "string", description: "Its name or id." } },
155
+ properties: {
156
+ in: { type: "string", description: "Another space, by its id (your context lists them)." },
157
+ board: { type: "string", description: "Its name or id." },
158
+ },
149
159
  },
150
- run: async ({ board: typed }, ctx) => {
151
- const space = ctx.in;
152
- if (!space)
153
- return NOWHERE;
160
+ run: async ({ board: typed, in: there }, ctx) => {
161
+ const where = await workIn(ctx, there, "read");
162
+ if (typeof where === "string")
163
+ return where;
164
+ const space = where.in;
154
165
  const board = await boardNamed(ctx, space, typed);
155
166
  if (typeof board === "string")
156
167
  return board;
@@ -187,10 +198,12 @@ const readBoard = tool({
187
198
  const createBoard = tool({
188
199
  offer: inSpace,
189
200
  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.",
201
+ "with Backlog, To do, Doing, Blocked, In review and Done, unless you name its columns." +
202
+ ELSEWHERE,
191
203
  input: {
192
204
  type: "object",
193
205
  properties: {
206
+ in: { type: "string", description: "Another space, by its id (your context lists them)." },
194
207
  name: { type: "string", minLength: 1, maxLength: 80 },
195
208
  description: { type: "string", description: "What it's for, in a line or two." },
196
209
  columns: {
@@ -201,10 +214,11 @@ const createBoard = tool({
201
214
  },
202
215
  required: ["name"],
203
216
  },
204
- run: async ({ name, description, columns }, ctx) => {
205
- const space = ctx.in;
206
- if (!space)
207
- return NOWHERE;
217
+ run: async ({ name, description, columns, in: there }, ctx) => {
218
+ const where = await workIn(ctx, there, "write");
219
+ if (typeof where === "string")
220
+ return where;
221
+ const space = where.in;
208
222
  try {
209
223
  const made = await ctx.call("board.create", {
210
224
  in: space,
@@ -224,10 +238,12 @@ const createCard = tool({
224
238
  offer: inSpace,
225
239
  description: "Add a card to a board in this space: one real outcome, with its owner " +
226
240
  "(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.",
241
+ "column. The board is the space's first unless you name one; the column, its first." +
242
+ ELSEWHERE,
228
243
  input: {
229
244
  type: "object",
230
245
  properties: {
246
+ in: { type: "string", description: "Another space, by its id (your context lists them)." },
231
247
  title: { type: "string", minLength: 1, maxLength: 300 },
232
248
  board: { type: "string", description: "The board's name or id." },
233
249
  column: { type: "string", description: "The column's name or id." },
@@ -250,9 +266,10 @@ const createCard = tool({
250
266
  required: ["title"],
251
267
  },
252
268
  run: async (input, ctx) => {
253
- const space = ctx.in;
254
- if (!space)
255
- return NOWHERE;
269
+ const where = await workIn(ctx, input.in, "write");
270
+ if (typeof where === "string")
271
+ return where;
272
+ const space = where.in;
256
273
  const board = await boardNamed(ctx, space, input.board);
257
274
  if (typeof board === "string")
258
275
  return board;
@@ -289,10 +306,11 @@ const updateCard = tool({
289
306
  offer: inSpace,
290
307
  description: "Change a card in this space (by its id from read_board, or its title): its " +
291
308
  "title, description, assignee, labels (the whole set) or due date. An empty value, or " +
292
- "null, clears one. Moving it is move_card.",
309
+ "null, clears one. Moving it is move_card." + ELSEWHERE,
293
310
  input: {
294
311
  type: "object",
295
312
  properties: {
313
+ in: { type: "string", description: "Another space, by its id (your context lists them)." },
296
314
  card: { type: "string", description: "Its id, or its title." },
297
315
  board: { type: "string", description: "The board's name or id, if the title is on several." },
298
316
  title: { type: "string", minLength: 1, maxLength: 300 },
@@ -307,9 +325,10 @@ const updateCard = tool({
307
325
  required: ["card"],
308
326
  },
309
327
  run: async (input, ctx) => {
310
- const space = ctx.in;
311
- if (!space)
312
- return NOWHERE;
328
+ const where = await workIn(ctx, input.in, "write");
329
+ if (typeof where === "string")
330
+ return where;
331
+ const space = where.in;
313
332
  const board = input.board ? await boardNamed(ctx, space, input.board) : undefined;
314
333
  if (typeof board === "string")
315
334
  return board;
@@ -362,10 +381,11 @@ const moveCard = tool({
362
381
  offer: inSpace,
363
382
  description: "Move a card in this space (by its id from read_board, or its title) to a " +
364
383
  "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.",
384
+ "the column's bottom unless you say top." + ELSEWHERE,
366
385
  input: {
367
386
  type: "object",
368
387
  properties: {
388
+ in: { type: "string", description: "Another space, by its id (your context lists them)." },
369
389
  card: { type: "string", description: "Its id, or its title." },
370
390
  column: { type: "string", description: "The column's name or id." },
371
391
  board: { type: "string", description: "The board's name or id, if the title is on several." },
@@ -374,9 +394,10 @@ const moveCard = tool({
374
394
  required: ["card", "column"],
375
395
  },
376
396
  run: async (input, ctx) => {
377
- const space = ctx.in;
378
- if (!space)
379
- return NOWHERE;
397
+ const where = await workIn(ctx, input.in, "write");
398
+ if (typeof where === "string")
399
+ return where;
400
+ const space = where.in;
380
401
  const board = input.board ? await boardNamed(ctx, space, input.board) : undefined;
381
402
  if (typeof board === "string")
382
403
  return board;
@@ -9,7 +9,7 @@
9
9
  * the document (`[Title](/document/<id>)`), so agents link it too.
10
10
  */
11
11
  import { namesFor } from "copilotz/plugins/access/contract";
12
- import { tool } from "copilotz/plugins/agents/contract";
12
+ import { tool, workIn, } from "copilotz/plugins/agents/contract";
13
13
  import { versionId } from "../collections/document-version.js";
14
14
  import { excerptOf, forOf, kb, keyOf, LIMIT, TITLE } from "../shared/text.js";
15
15
  import { agentNamer, nameOf, peopleOf } from "../shared/who.js";
@@ -67,10 +67,11 @@ function answer(w, made = false) {
67
67
  : `Saved ${link(w)} as version ${w.version}: +${w.added} −${w.removed} lines.`;
68
68
  }
69
69
  /** Changes a named document in one transaction (read, then written): `change` says how. */
70
- async function change(ctx, name, how, kind) {
71
- const space = ctx.in;
72
- if (!space)
73
- return "This conversation isn't in a space: there are no documents here.";
70
+ async function change(ctx, name, how, kind, there) {
71
+ const where = await workIn(ctx, there, "write");
72
+ if (typeof where === "string")
73
+ return where;
74
+ const space = where.in;
74
75
  try {
75
76
  return await ctx.transaction(async (tx) => {
76
77
  const doc = await named(tx.db, space, name);
@@ -86,16 +87,24 @@ async function change(ctx, name, how, kind) {
86
87
  return said(error);
87
88
  }
88
89
  }
90
+ /** Each tool works here, or in another space its work reaches. */
91
+ const ELSEWHERE = " In another space you can work in, give in (its id).";
89
92
  const listDocuments = tool({
90
93
  offer: inSpace,
91
94
  description: "List this space's documents, latest saved first: each one's title (a link to " +
92
95
  "it), version, size, who saved it last and when, and how it opens. Read one with " +
93
- "read_document before you change it.",
94
- input: { type: "object", properties: {} },
95
- run: async (_, ctx) => {
96
- const space = ctx.in;
97
- if (!space)
98
- return "This conversation isn't in a space: there are no documents here.";
96
+ "read_document before you change it." + ELSEWHERE,
97
+ input: {
98
+ type: "object",
99
+ properties: {
100
+ in: { type: "string", description: "Another space, by its id (your context lists them)." },
101
+ },
102
+ },
103
+ run: async ({ in: there }, ctx) => {
104
+ const where = await workIn(ctx, there);
105
+ if (typeof where === "string")
106
+ return where;
107
+ const space = where.in;
99
108
  const docs = await ctx.db.collection("document").find({ in: space }, {
100
109
  sort: { savedAt: -1 },
101
110
  });
@@ -116,19 +125,21 @@ const listDocuments = tool({
116
125
  const readDocument = tool({
117
126
  offer: inSpace,
118
127
  description: "Read a document of this space, by its title or id: its text (Markdown), with " +
119
- "its version and who saved it. With version, an older one, as it was then.",
128
+ "its version and who saved it. With version, an older one, as it was then." + ELSEWHERE,
120
129
  input: {
121
130
  type: "object",
122
131
  properties: {
123
132
  document: { type: "string", minLength: 1, description: "Its title or id." },
124
133
  version: { type: "integer", minimum: 1, description: "An older version (default: now)." },
134
+ in: { type: "string", description: "Another space, by its id (your context lists them)." },
125
135
  },
126
136
  required: ["document"],
127
137
  },
128
- run: async ({ document, version }, ctx) => {
129
- const space = ctx.in;
130
- if (!space)
131
- return "This conversation isn't in a space: there are no documents here.";
138
+ run: async ({ document, version, in: there }, ctx) => {
139
+ const where = await workIn(ctx, there);
140
+ if (typeof where === "string")
141
+ return where;
142
+ const space = where.in;
132
143
  const doc = await named(ctx.db, space, document);
133
144
  if (typeof doc === "string")
134
145
  return doc;
@@ -158,10 +169,11 @@ const writeDocument = tool({
158
169
  offer: inSpace,
159
170
  description: "Make a new document in this space (title and text), or, naming one with " +
160
171
  "document, replace its whole text (and title, if given). To change part of one, prefer " +
161
- "edit_document or append_document: they keep what others wrote. Markdown.",
172
+ "edit_document or append_document: they keep what others wrote. Markdown." + ELSEWHERE,
162
173
  input: {
163
174
  type: "object",
164
175
  properties: {
176
+ in: { type: "string", description: "Another space, by its id (your context lists them)." },
165
177
  title: { type: "string", maxLength: TITLE, description: "Its title." },
166
178
  text: { type: "string", maxLength: 4 * LIMIT, description: "Its whole text, in Markdown." },
167
179
  document: {
@@ -171,13 +183,14 @@ const writeDocument = tool({
171
183
  },
172
184
  required: ["text"],
173
185
  },
174
- run: async ({ title, text, document }, ctx) => {
186
+ run: async ({ title, text, document, in: there }, ctx) => {
175
187
  if (document) {
176
- return await change(ctx, document, () => ({ title: title?.trim() || undefined, text }), "write");
188
+ return await change(ctx, document, () => ({ title: title?.trim() || undefined, text }), "write", there);
177
189
  }
178
- const space = ctx.in;
179
- if (!space)
180
- return "This conversation isn't in a space: there's nowhere to write.";
190
+ const where = await workIn(ctx, there, "write");
191
+ if (typeof where === "string")
192
+ return where;
193
+ const space = where.in;
181
194
  const name = title?.trim();
182
195
  if (!name)
183
196
  return "A new document needs a title.";
@@ -202,35 +215,37 @@ const writeDocument = tool({
202
215
  const appendDocument = tool({
203
216
  offer: inSpace,
204
217
  description: "Add text to the end of a document of this space (by its title or id), after a " +
205
- "blank line. Markdown.",
218
+ "blank line. Markdown." + ELSEWHERE,
206
219
  input: {
207
220
  type: "object",
208
221
  properties: {
209
222
  document: { type: "string", minLength: 1, description: "Its title or id." },
210
223
  text: { type: "string", minLength: 1, maxLength: 4 * LIMIT },
224
+ in: { type: "string", description: "Another space, by its id (your context lists them)." },
211
225
  },
212
226
  required: ["document", "text"],
213
227
  },
214
- run: ({ document, text }, ctx) => change(ctx, document, (doc) => {
228
+ run: ({ document, text, in: there }, ctx) => change(ctx, document, (doc) => {
215
229
  const was = doc.text.replace(/\s+$/, "");
216
230
  return { text: was ? `${was}\n\n${text.replace(/^\n+/, "")}` : text };
217
- }, "append"),
231
+ }, "append", there),
218
232
  });
219
233
  const editDocument = tool({
220
234
  offer: inSpace,
221
235
  description: "Change part of a document of this space (by its title or id): replace text " +
222
236
  "that occurs exactly once in it (old, copied exactly, with enough around it to be " +
223
- "unique) with new text. Read it first.",
237
+ "unique) with new text. Read it first." + ELSEWHERE,
224
238
  input: {
225
239
  type: "object",
226
240
  properties: {
227
241
  document: { type: "string", minLength: 1, description: "Its title or id." },
228
242
  old: { type: "string", minLength: 1, description: "The text to replace, exactly." },
229
243
  new: { type: "string", description: "What goes in its place." },
244
+ in: { type: "string", description: "Another space, by its id (your context lists them)." },
230
245
  },
231
246
  required: ["document", "old", "new"],
232
247
  },
233
- run: ({ document, old, new: next }, ctx) => change(ctx, document, (doc) => {
248
+ run: ({ document, old, new: next, in: there }, ctx) => change(ctx, document, (doc) => {
234
249
  const at = doc.text.indexOf(old);
235
250
  if (at < 0) {
236
251
  return `The text to replace isn't in ${link(doc)}: read it again (read_document) and ` +
@@ -242,7 +257,7 @@ const editDocument = tool({
242
257
  `in ${link(doc)}: give more of what's around it.`;
243
258
  }
244
259
  return { text: doc.text.slice(0, at) + next + doc.text.slice(at + old.length) };
245
- }, "edit"),
260
+ }, "edit", there),
246
261
  });
247
262
  export const tools = {
248
263
  list_documents: listDocuments,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@copilotz/work",
3
- "version": "1.0.0-rc.34",
3
+ "version": "1.0.0-rc.36",
4
4
  "description": "Kanban boards and shared Markdown documents, in a space, for people and agents: a Copilotz plugin.",
5
5
  "keywords": [
6
6
  "copilotz",
@@ -52,7 +52,7 @@
52
52
  "dependencies": {},
53
53
  "peerDependencies": {
54
54
  "@types/react": "^19.3.0",
55
- "copilotz": "1.0.0-rc.34",
55
+ "copilotz": "1.0.0-rc.36",
56
56
  "react": "^19.3.1"
57
57
  },
58
58
  "peerDependenciesMeta": {