@netnodeag/kraftwerk 0.98.0 → 0.99.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -574,9 +574,16 @@ task goes to an agent or to yourself (`human:<handle>`, the person
574
574
  Cloud boards are multiplayer. They live in kraftwerk cloud, belong to the
575
575
  workspace's `id:`, and everyone on the workspace sees and edits them, from
576
576
  their own machine or the cloud's web app (`/w/<ws id>`). A task goes to
577
- anyone on the workspace or to an agent. They show in the boards page
578
- under the local ones, with a cloud mark, and never sync with them. This
579
- machine reaches them through `/api/remote-boards/…`:
577
+ anyone on the workspace or to an agent. They never sync with local boards.
578
+
579
+ Here they are boards like any other, with a cloud mark: on Home, in the
580
+ boards page, on a task's page beside its chat. Pick "kraftwerk cloud" when
581
+ you make a board. A cloud board's slug starts with `@`, so the same API
582
+ (`/api/boards/@launch/tasks/3`) and the same commands
583
+ (`kraftwerk tasks show 3 --board @launch`) work on it. A cloud task has no
584
+ folder and no files; a cloud board has no default agent, rules or project
585
+ links. `/api/remote-boards/…` speaks the cloud's own shapes. Calls go to
586
+ the cloud as the caller:
580
587
 
581
588
  - A signed-in browser (`users: cloud`) acts as its person.
582
589
  - Everything else on the machine acts as the account that claimed it.
@@ -6,6 +6,8 @@ import { taskSessions } from "../core/board-wake.js";
6
6
  import { initContext as prepare } from "./routines.js";
7
7
  import { fmtAgo } from "./workspaces.js";
8
8
  import { actorFor } from "../core/person.js";
9
+ import { resolveWorkspace, workspaceSlug } from "../config.js";
10
+ import { findDaemon } from "../core/daemon.js";
9
11
  /**
10
12
  * `kraftwerk boards` and `kraftwerk tasks` — the boards (columns of tasks)
11
13
  * of a project or of the workspace, and the tasks on them. The same module
@@ -31,7 +33,9 @@ import { actorFor } from "../core/person.js";
31
33
  * kraftwerk tasks remove <n>
32
34
  *
33
35
  * --board defaults to the project's `tasks` board (or the only board); the
34
- * number alone names a task.
36
+ * number alone names a task. A cloud board (`--board @launch`, kept in
37
+ * kraftwerk cloud, server/cloud-boards.ts) is reached through the running
38
+ * daemon, which asks the cloud for this machine; the same commands work.
35
39
  */
36
40
  const die = (msg) => {
37
41
  console.error(chalk.red(msg));
@@ -65,6 +69,26 @@ async function whereOf(w, create = false) {
65
69
  die(`no board ${project ? `in project ${project}` : "in the workspace"} yet — \`kraftwerk boards create "<title>"${project ? ` --project ${project}` : ""}\` makes one`);
66
70
  return die(`several boards here (${view.boards.map((b) => b.board).join(", ")}) — say which with --board`);
67
71
  }
72
+ /** A cloud board: `@<slug>`. */
73
+ const isCloud = (w) => !!w.board?.trim().startsWith("@");
74
+ /** The boards API of this workspace on the running daemon — the way to a cloud board. */
75
+ async function cloudApi(method, route, body) {
76
+ const ws = await resolveWorkspace(process.cwd());
77
+ const daemon = await findDaemon();
78
+ if (!daemon)
79
+ die("cloud boards go through the daemon, and it is not running — `kraftwerk daemon start`");
80
+ const r = await fetch(`http://127.0.0.1:${daemon.port}/w/${encodeURIComponent(workspaceSlug(ws))}${route}`, {
81
+ method,
82
+ headers: body !== undefined ? { "content-type": "application/json" } : {},
83
+ body: body !== undefined ? JSON.stringify(body) : undefined,
84
+ signal: AbortSignal.timeout(20_000),
85
+ }).catch((err) => die(`the daemon did not answer: ${err.message}`));
86
+ const data = (await r.json().catch(() => ({})));
87
+ if (!r.ok)
88
+ die(data.error ?? `${r.status} from the daemon`);
89
+ return data;
90
+ }
91
+ const cloudTask = (w, task, rest = "") => `/api/boards/${encodeURIComponent(w.board.trim())}/tasks/${encodeURIComponent(task)}${rest}`;
68
92
  const flags = (ref) => (ref.project ? `--project ${ref.project} --board ${ref.board}` : `--board ${ref.board}`);
69
93
  function taskRow(t) {
70
94
  return [
@@ -83,7 +107,7 @@ function printBoard(b) {
83
107
  console.log(chalk.red(`board.md: ${b.configError}`));
84
108
  if (b.notes.trim())
85
109
  console.log(b.notes.trim());
86
- console.log(chalk.dim(b.path));
110
+ console.log(chalk.dim(b.cloud ? "a cloud board (kraftwerk cloud), shared with everyone on the workspace" : b.path));
87
111
  for (const c of b.columns) {
88
112
  const items = b.items.filter((t) => t.status === c.slug);
89
113
  console.log(`\n${chalk.bold(c.label)} ${chalk.dim(`(${items.length}${c.limit ? `/${c.limit}` : ""}${c.review ? ", review" : c.done ? ", done" : ""})`)}`);
@@ -102,7 +126,7 @@ function printTask(t) {
102
126
  console.log(`${t.status}${t.assignee ? ` · ${t.assignee}` : " · unassigned"}${t.due ? ` · due ${t.due}` : ""}${t.tags.length ? ` · ${t.tags.join(", ")}` : ""}${t.stale ? chalk.yellow(" · stale") : ""}`);
103
127
  if (t.refs.length)
104
128
  console.log(chalk.dim(`refs: ${t.refs.join(", ")}`));
105
- console.log(chalk.dim(`folder: ${t.path}`));
129
+ console.log(chalk.dim(t.cloud ? "on a cloud board (kraftwerk cloud) — no folder" : `folder: ${t.path}`));
106
130
  const sessions = t.sessions ?? [];
107
131
  if (sessions.length)
108
132
  console.log(chalk.dim(`sessions: ${sessions.map((s) => `${s.emoji ? `${s.emoji} ` : ""}${s.name ?? s.agent} ${s.id}${s.busy ? " (working)" : ""}`).join(", ")}`));
@@ -110,9 +134,11 @@ function printTask(t) {
110
134
  console.log(chalk.red(`task.md: ${t.configError}`));
111
135
  if (t.notes.trim())
112
136
  console.log(`\n${t.notes.trim()}`);
113
- console.log(`\n${chalk.bold("files")}${t.fileList.length ? "" : chalk.dim(" (none)")}`);
114
- for (const f of t.fileList)
115
- console.log(` ${f}`);
137
+ if (!t.cloud) {
138
+ console.log(`\n${chalk.bold("files")}${t.fileList.length ? "" : chalk.dim(" (none)")}`);
139
+ for (const f of t.fileList)
140
+ console.log(` ${f}`);
141
+ }
116
142
  if (t.log.trim())
117
143
  console.log(`\n${chalk.bold("log")}\n${t.log.trim()}`);
118
144
  }
@@ -161,7 +187,7 @@ export function registerBoardCommands(program) {
161
187
  .action(async (board, opts) => {
162
188
  await prepare();
163
189
  try {
164
- const b = await getBoard({ ...(opts.project ? { project: opts.project } : {}), board });
190
+ const b = board.startsWith("@") ? await cloudApi("GET", `/api/boards/${encodeURIComponent(board)}`) : await getBoard({ ...(opts.project ? { project: opts.project } : {}), board });
165
191
  if (!b)
166
192
  die(`no board "${board}"`);
167
193
  if (opts.json)
@@ -258,8 +284,8 @@ export function registerBoardCommands(program) {
258
284
  .action(async (opts) => {
259
285
  await prepare();
260
286
  try {
261
- const ref = await whereOf(opts);
262
- const b = await getBoard(ref);
287
+ const ref = isCloud(opts) ? { board: opts.board.trim() } : await whereOf(opts);
288
+ const b = isCloud(opts) ? await cloudApi("GET", `/api/boards/${encodeURIComponent(ref.board)}`) : await getBoard(ref);
263
289
  if (!b)
264
290
  die(`no board "${ref.board}"`);
265
291
  const me = opts.mine ? agentOf(opts.as) || die("--mine needs --as <agent> outside an agent session") : undefined;
@@ -289,6 +315,14 @@ export function registerBoardCommands(program) {
289
315
  .action(async (task, opts) => {
290
316
  await prepare();
291
317
  try {
318
+ if (isCloud(opts)) {
319
+ const t = await cloudApi("GET", cloudTask(opts, task));
320
+ if (opts.json)
321
+ console.log(JSON.stringify(t, null, 2));
322
+ else
323
+ printTask(t);
324
+ return;
325
+ }
292
326
  const found = await getTask(await whereOf(opts), task);
293
327
  if (!found)
294
328
  die(`no task "${task}"`);
@@ -318,8 +352,7 @@ export function registerBoardCommands(program) {
318
352
  .action(async (title, opts) => {
319
353
  await prepare();
320
354
  try {
321
- const ref = await whereOf(opts, true);
322
- const t = await createTask(ref, {
355
+ const input = {
323
356
  title,
324
357
  status: opts.status,
325
358
  assignee: opts.assign,
@@ -329,11 +362,14 @@ export function registerBoardCommands(program) {
329
362
  notes: opts.file ? await readFile(opts.file, "utf8") : opts.notes,
330
363
  actor: actorOf(opts.actor),
331
364
  message: opts.message,
332
- });
365
+ };
366
+ const t = isCloud(opts)
367
+ ? await cloudApi("POST", `/api/boards/${encodeURIComponent(opts.board.trim())}/tasks`, { ...input, tags: input.tags?.split(",").map((x) => x.trim()).filter(Boolean), refs: undefined })
368
+ : await createTask(await whereOf(opts, true), input);
333
369
  if (opts.json)
334
370
  console.log(JSON.stringify(t, null, 2));
335
371
  else
336
- console.log(`${chalk.green("✔")} ${chalk.cyan(String(t.number))} ${t.title} ${chalk.dim(`(${t.status}${t.assignee ? `, ${t.assignee}` : ""}) → ${t.path}`)}`);
372
+ console.log(`${chalk.green("✔")} ${chalk.cyan(String(t.number))} ${t.title} ${chalk.dim(`(${t.status}${t.assignee ? `, ${t.assignee}` : ""}) → ${t.path || t.ref}`)}`);
337
373
  }
338
374
  catch (err) {
339
375
  die(err.message);
@@ -361,7 +397,9 @@ export function registerBoardCommands(program) {
361
397
  };
362
398
  if (Object.keys(input).length === 0)
363
399
  die("nothing to set — pass --title, --due, --tags, --refs or --notes-file");
364
- const t = await saveTask(await whereOf(opts), task, input, { actor: actorOf(opts.actor) });
400
+ const t = isCloud(opts)
401
+ ? await cloudApi("PUT", cloudTask(opts, task), { ...input, ...(typeof input.tags === "string" ? { tags: input.tags.split(",").map((x) => x.trim()).filter(Boolean) } : {}), refs: undefined, actor: actorOf(opts.actor) })
402
+ : await saveTask(await whereOf(opts), task, input, { actor: actorOf(opts.actor) });
365
403
  if (opts.json)
366
404
  console.log(JSON.stringify(t, null, 2));
367
405
  else
@@ -381,7 +419,9 @@ export function registerBoardCommands(program) {
381
419
  .action(async (task, column, opts) => {
382
420
  await prepare();
383
421
  try {
384
- const t = await moveTask(await whereOf(opts), task, column, { message: opts.message, actor: actorOf(opts.actor) });
422
+ const t = isCloud(opts)
423
+ ? await cloudApi("POST", cloudTask(opts, task, "/move"), { status: column, message: opts.message, actor: actorOf(opts.actor) })
424
+ : await moveTask(await whereOf(opts), task, column, { message: opts.message, actor: actorOf(opts.actor) });
385
425
  if (opts.json)
386
426
  console.log(JSON.stringify(t, null, 2));
387
427
  else
@@ -405,7 +445,9 @@ export function registerBoardCommands(program) {
405
445
  if (!to)
406
446
  die('say who: `tasks assign <n> <agent>` or `--to human`');
407
447
  try {
408
- const t = await assignTask(await whereOf(opts), task, to === "human" ? null : to, { message: opts.message, actor: actorOf(opts.actor) });
448
+ const t = isCloud(opts)
449
+ ? await cloudApi("POST", cloudTask(opts, task, "/assign"), { to: to === "human" ? null : to, message: opts.message, actor: actorOf(opts.actor) })
450
+ : await assignTask(await whereOf(opts), task, to === "human" ? null : to, { message: opts.message, actor: actorOf(opts.actor) });
409
451
  if (opts.json)
410
452
  console.log(JSON.stringify(t, null, 2));
411
453
  else
@@ -425,9 +467,10 @@ export function registerBoardCommands(program) {
425
467
  .action(async (task, entry, opts) => {
426
468
  await prepare();
427
469
  try {
428
- const ref = await whereOf(opts);
470
+ const cloudBoard = isCloud(opts);
471
+ const ref = cloudBoard ? { board: opts.board.trim() } : await whereOf(opts);
429
472
  if (opts.tail !== undefined) {
430
- const t = await getTask(ref, task);
473
+ const t = cloudBoard ? await cloudApi("GET", cloudTask(opts, task)) : await getTask(ref, task);
431
474
  if (!t)
432
475
  die(`no task "${task}"`);
433
476
  const n = Number(opts.tail) || 5;
@@ -439,7 +482,7 @@ export function registerBoardCommands(program) {
439
482
  return;
440
483
  }
441
484
  const text = opts.file ? await readFile(opts.file, "utf8") : entry ?? "";
442
- const t = await appendTaskLog(ref, task, text, actorOf(opts.actor));
485
+ const t = cloudBoard ? await cloudApi("POST", cloudTask(opts, task, "/log"), { entry: text, actor: actorOf(opts.actor) }) : await appendTaskLog(ref, task, text, actorOf(opts.actor));
443
486
  console.log(`${chalk.green("✔")} logged on ${chalk.cyan(String(t.number))} ${chalk.dim(`(${await actorFor(actorOf(opts.actor))})`)}`);
444
487
  }
445
488
  catch (err) {
@@ -457,7 +500,9 @@ export function registerBoardCommands(program) {
457
500
  if (!agent)
458
501
  die("who picks? pass --as <agent> (inside an agent session KRAFTWERK_AGENT is set)");
459
502
  try {
460
- const t = await pickTask(await whereOf(opts), agent, { column: opts.column, actor: process.env.KRAFTWERK_ACTOR || agent });
503
+ const t = isCloud(opts)
504
+ ? (await cloudApi("POST", `/api/boards/${encodeURIComponent(opts.board.trim())}/pick`, { agent, ...(opts.column ? { column: opts.column } : {}) })).task
505
+ : await pickTask(await whereOf(opts), agent, { column: opts.column, actor: process.env.KRAFTWERK_ACTOR || agent });
461
506
  if (!t) {
462
507
  if (opts.json)
463
508
  console.log("null");
@@ -482,6 +527,10 @@ export function registerBoardCommands(program) {
482
527
  .action(async (task, opts) => {
483
528
  await prepare();
484
529
  try {
530
+ if (isCloud(opts)) {
531
+ await cloudApi("DELETE", cloudTask(opts, task));
532
+ return void console.log(`${chalk.green("✔")} deleted task ${chalk.cyan(task)} from the cloud board`);
533
+ }
485
534
  await deleteTask(await whereOf(opts), task);
486
535
  console.log(`${chalk.green("✔")} moved task ${chalk.cyan(task)} to the trash`);
487
536
  }
@@ -71,6 +71,8 @@ export interface BoardSummary extends BoardDef {
71
71
  tasks: number;
72
72
  /** Tasks in a review column. */
73
73
  review: number;
74
+ /** A cloud board (server/cloud-boards.ts): kept in kraftwerk cloud, `board` is "@<slug>", no folder. */
75
+ cloud?: true;
74
76
  }
75
77
  export interface BoardDetail extends BoardSummary {
76
78
  /** The body of board.md: what the board is for, the rules agents follow. */
@@ -108,6 +110,8 @@ export interface TaskSummary extends TaskDef {
108
110
  lastLog?: string;
109
111
  /** In a work column with an assignee and nothing logged for staleAfter. */
110
112
  stale?: boolean;
113
+ /** On a cloud board: no folder, no files. */
114
+ cloud?: true;
111
115
  }
112
116
  export interface TaskDetail extends TaskSummary {
113
117
  /** The body of task.md. */
@@ -1,4 +1,5 @@
1
1
  import * as z from "zod";
2
+ import * as cloud from "../cloud-boards.js";
2
3
  /**
3
4
  * Boards and tasks over the API. A board is addressed by its slug and, for
4
5
  * a project's board, `?project=<slug>`; a task by its folder name or its
@@ -6,7 +7,7 @@ import * as z from "zod";
6
7
  * on the task and may wake the assignee (core/board-wake.ts).
7
8
  */
8
9
  export declare const boardErrors: (message: string) => number;
9
- export declare const boardRoutes: (import("./router.js").Route<"boards.create", import("./router.js").Reply<import("../../core/boards.js").BoardDetail>, "/api/boards", z.ZodObject<{
10
+ export declare const boardRoutes: (import("./router.js").Route<"boards.create", import("./router.js").Reply<import("../../core/boards.js").BoardSummary & cloud.CloudMark>, "/api/boards", z.ZodObject<{
10
11
  title: z.ZodString;
11
12
  slug: z.ZodOptional<z.ZodString>;
12
13
  project: z.ZodOptional<z.ZodString>;
@@ -19,11 +20,21 @@ export declare const boardRoutes: (import("./router.js").Route<"boards.create",
19
20
  }, z.core.$strip>]>>>;
20
21
  agent: z.ZodOptional<z.ZodString>;
21
22
  notes: z.ZodOptional<z.ZodString>;
23
+ cloud: z.ZodOptional<z.ZodBoolean>;
22
24
  }, z.core.$strip>> | import("./router.js").Route<"boards.delete", {
23
25
  ok: boolean;
24
26
  }, "/api/boards/:board", undefined> | import("./router.js").Route<"boards.ensure", import("../../core/boards.js").BoardDetail, "/api/boards/default", z.ZodObject<{
25
27
  project: z.ZodOptional<z.ZodString>;
26
- }, z.core.$strip>> | import("./router.js").Route<"boards.get", import("../../core/boards.js").BoardDetail, "/api/boards/:board", undefined> | import("./router.js").Route<"boards.list", import("../../core/boards.js").BoardsView, "/api/boards", undefined> | import("./router.js").Route<"boards.save", import("../../core/boards.js").BoardDetail, "/api/boards/:board", z.ZodObject<{
28
+ }, z.core.$strip>> | import("./router.js").Route<"boards.get", import("../../core/boards.js").BoardDetail, "/api/boards/:board", undefined> | import("./router.js").Route<"boards.list", import("../../core/boards.js").BoardsView | {
29
+ enabled: boolean;
30
+ root?: string;
31
+ error?: string;
32
+ boards: import("../../core/boards.js").BoardSummary[];
33
+ cloud: {
34
+ offline?: boolean | undefined;
35
+ error?: string | undefined;
36
+ };
37
+ }, "/api/boards", undefined> | import("./router.js").Route<"boards.save", import("../../core/boards.js").BoardSummary & cloud.CloudMark, "/api/boards/:board", z.ZodObject<{
27
38
  title: z.ZodOptional<z.ZodString>;
28
39
  columns: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
29
40
  slug: z.ZodString;
@@ -72,6 +83,7 @@ export declare const boardRoutes: (import("./router.js").Route<"boards.create",
72
83
  files: number;
73
84
  lastLog?: string;
74
85
  stale?: boolean;
86
+ cloud?: true;
75
87
  notes: string;
76
88
  log: string;
77
89
  fileList: string[];
@@ -90,7 +102,7 @@ export declare const boardRoutes: (import("./router.js").Route<"boards.create",
90
102
  message: z.ZodOptional<z.ZodString>;
91
103
  actor: z.ZodOptional<z.ZodString>;
92
104
  }, z.core.$strip>> | import("./router.js").Route<"tasks.pick", {
93
- task: import("../../core/boards.js").TaskDetail | null;
105
+ task: (import("../../core/boards.js").TaskDetail & cloud.CloudMark) | null;
94
106
  }, "/api/boards/:board/pick", z.ZodObject<{
95
107
  agent: z.ZodString;
96
108
  column: z.ZodOptional<z.ZodString>;
@@ -2,6 +2,7 @@ import * as z from "zod";
2
2
  import { appendTaskLog, assignTask, createBoard, createTask, deleteBoard, deleteTask, ensureDefaultBoard, getBoard, getTask, listAllBoards, listAllTasks, listBoards, moveTask, openBoards, pickTask, saveBoard, saveTask, } from "../../core/boards.js";
3
3
  import { taskSessions } from "../../core/board-wake.js";
4
4
  import { fail, reply, route, statusByMessage } from "./router.js";
5
+ import * as cloud from "../cloud-boards.js";
5
6
  /**
6
7
  * Boards and tasks over the API. A board is addressed by its slug and, for
7
8
  * a project's board, `?project=<slug>`; a task by its folder name or its
@@ -35,17 +36,26 @@ const refOf = (c) => {
35
36
  const project = c.query.get("project");
36
37
  return { ...(project ? { project } : {}), board: c.params.board };
37
38
  };
39
+ /** A cloud board (`@<slug>`, server/cloud-boards.ts) — only ever at the workspace level. */
40
+ const onCloud = (c) => cloud.isCloudBoard(c.params.board) && !c.query.get("project");
38
41
  const requireOn = async () => {
39
42
  if ((await openBoards()).off)
40
43
  fail(409, "boards are off");
41
44
  };
42
45
  export const boardRoutes = [
43
46
  route({ name: "boards.list", method: "GET", path: "/api/boards", summary: "the boards: a project's with ?project=, every board with ?all=1, else the workspace's" }, async (c) => {
44
- if (c.query.get("all") === "1") {
45
- const opened = await openBoards();
46
- return { enabled: !opened.off && !!opened.root, ...(opened.root ? { root: opened.root } : {}), boards: await listAllBoards(), ...(opened.error ? { error: opened.error } : {}) };
47
- }
48
- return listBoards(c.query.get("project") ?? undefined);
47
+ // The workspace's cloud boards follow its local ones (none in a project's list); how the cloud is doing rides along.
48
+ const project = c.query.get("project") ?? undefined;
49
+ const all = c.query.get("all") === "1";
50
+ const [local, remote] = await Promise.all([
51
+ all
52
+ ? openBoards().then(async (opened) => ({ enabled: !opened.off && !!opened.root, ...(opened.root ? { root: opened.root } : {}), boards: await listAllBoards(), ...(opened.error ? { error: opened.error } : {}) }))
53
+ : listBoards(project),
54
+ project && !all ? null : cloud.listCloudBoards(c.trust),
55
+ ]);
56
+ if (!remote)
57
+ return local;
58
+ return { ...local, boards: [...local.boards, ...remote.boards], cloud: { ...(remote.offline ? { offline: true } : {}), ...(remote.error ? { error: remote.error } : {}) } };
49
59
  }),
50
60
  route({
51
61
  name: "boards.create",
@@ -53,23 +63,35 @@ export const boardRoutes = [
53
63
  path: "/api/boards",
54
64
  summary: "create a board {title, slug?, project?, columns?, agent?, notes?}",
55
65
  errors: boardErrors,
56
- body: z.object({ title: z.string(), slug: z.string().optional(), project: z.string().optional(), columns: Columns.optional(), agent: z.string().optional(), notes: z.string().optional() }),
66
+ body: z.object({ title: z.string(), slug: z.string().optional(), project: z.string().optional(), columns: Columns.optional(), agent: z.string().optional(), notes: z.string().optional(), cloud: z.boolean().optional() }),
57
67
  }, async (c) => {
68
+ const { cloud: inCloud, ...input } = await c.body();
69
+ // In kraftwerk cloud: shared with everyone on the workspace, at the workspace level.
70
+ if (inCloud)
71
+ return reply(201, await cloud.createCloudBoard(c.trust, input));
58
72
  await requireOn();
59
- return reply(201, await createBoard(await c.body()));
73
+ return reply(201, await createBoard(input));
60
74
  }),
61
75
  route({ name: "boards.get", method: "GET", path: "/api/boards/:board", summary: "columns, rules, counts and every task (?project=)", errors: boardErrors }, async (c) => {
76
+ if (onCloud(c))
77
+ return cloud.getCloudBoard(c.trust, c.params.board);
62
78
  await requireOn();
63
79
  const ref = refOf(c);
64
80
  return (await getBoard(ref)) ?? fail(404, `no board "${ref.board}"`);
65
81
  }),
66
82
  route({ name: "boards.save", method: "PUT", path: "/api/boards/:board", summary: "save title, columns, default agent, stale_after, rules", errors: boardErrors, body: BoardFields }, async (c) => {
83
+ if (onCloud(c))
84
+ return cloud.saveCloudBoard(c.trust, c.params.board, await c.body());
67
85
  await requireOn();
68
86
  return saveBoard(refOf(c), (await c.body()));
69
87
  }),
70
88
  route({ name: "boards.delete", method: "DELETE", path: "/api/boards/:board", summary: "move the board, tasks and all, to the trash", errors: boardErrors }, async (c) => {
71
- await requireOn();
72
- await deleteBoard(refOf(c));
89
+ if (onCloud(c))
90
+ await cloud.deleteCloudBoard(c.trust, c.params.board);
91
+ else {
92
+ await requireOn();
93
+ await deleteBoard(refOf(c));
94
+ }
73
95
  return { ok: true };
74
96
  }),
75
97
  route({
@@ -92,20 +114,29 @@ export const boardRoutes = [
92
114
  errors: boardErrors,
93
115
  body: TaskFields.extend({ title: z.string() }),
94
116
  }, async (c) => {
117
+ if (onCloud(c))
118
+ return reply(201, await cloud.createCloudTask(c.trust, c.params.board, await c.body()));
95
119
  await requireOn();
96
120
  return reply(201, await createTask(refOf(c), (await c.body())));
97
121
  }),
98
- route({ name: "tasks.list", method: "GET", path: "/api/tasks", summary: "every task of every board, the workspace's and the projects', each with its board and column" }, async () => {
99
- return { tasks: (await openBoards()).off ? [] : await listAllTasks() };
122
+ route({ name: "tasks.list", method: "GET", path: "/api/tasks", summary: "every task of every board, the workspace's, the projects' and the cloud's, each with its board and column" }, async (c) => {
123
+ const [local, remote] = await Promise.all([openBoards().then(async (o) => (o.off ? [] : await listAllTasks())), cloud.listCloudTasks(c.trust)]);
124
+ return { tasks: [...local, ...remote] };
100
125
  }),
101
126
  route({ name: "tasks.get", method: "GET", path: "/api/boards/:board/tasks/:task", summary: "the task: fields, markdown, files, log and the sessions that worked on it (:task = folder name or number)", errors: boardErrors }, async (c) => {
127
+ if (onCloud(c)) {
128
+ const t = await cloud.getCloudTask(c.trust, c.params.board, c.params.task);
129
+ return { ...t, sessions: await taskSessions(t.ref) };
130
+ }
102
131
  await requireOn();
103
132
  const task = (await getTask(refOf(c), c.params.task)) ?? fail(404, `no task "${c.params.task}"`);
104
133
  return { ...task, sessions: await taskSessions(task.ref) };
105
134
  }),
106
135
  route({ name: "tasks.save", method: "PUT", path: "/api/boards/:board/tasks/:task", summary: "save fields and markdown; a status or assignee change is logged (message?) and wakes an agent assigned in a work column (unless wake: false)", errors: boardErrors, body: TaskFields.extend({ wake: z.boolean().optional() }) }, async (c) => {
107
- await requireOn();
108
136
  const { actor, message, wake, ...fields } = await c.body();
137
+ if (onCloud(c))
138
+ return cloud.saveCloudTask(c.trust, c.params.board, c.params.task, { ...fields, actor, message });
139
+ await requireOn();
109
140
  return saveTask(refOf(c), c.params.task, fields, { actor, message, quiet: wake === false });
110
141
  }),
111
142
  route({
@@ -116,8 +147,10 @@ export const boardRoutes = [
116
147
  errors: boardErrors,
117
148
  body: z.object({ status: z.string(), before: z.string().optional(), order: z.number().optional(), message: z.string().optional(), actor: z.string().optional() }),
118
149
  }, async (c) => {
119
- await requireOn();
120
150
  const { status, ...opts } = await c.body();
151
+ if (onCloud(c))
152
+ return cloud.moveCloudTask(c.trust, c.params.board, c.params.task, status, opts);
153
+ await requireOn();
121
154
  return moveTask(refOf(c), c.params.task, status, opts);
122
155
  }),
123
156
  route({
@@ -128,8 +161,10 @@ export const boardRoutes = [
128
161
  errors: boardErrors,
129
162
  body: z.object({ to: z.string().nullable(), message: z.string().optional(), actor: z.string().optional() }),
130
163
  }, async (c) => {
131
- await requireOn();
132
164
  const { to, ...opts } = await c.body();
165
+ if (onCloud(c))
166
+ return cloud.assignCloudTask(c.trust, c.params.board, c.params.task, to, opts);
167
+ await requireOn();
133
168
  return assignTask(refOf(c), c.params.task, to, opts);
134
169
  }),
135
170
  route({
@@ -140,8 +175,10 @@ export const boardRoutes = [
140
175
  errors: boardErrors,
141
176
  body: z.object({ entry: z.string(), actor: z.string().optional() }),
142
177
  }, async (c) => {
143
- await requireOn();
144
178
  const { entry, actor } = await c.body();
179
+ if (onCloud(c))
180
+ return cloud.logCloudTask(c.trust, c.params.board, c.params.task, entry, actor);
181
+ await requireOn();
145
182
  return appendTaskLog(refOf(c), c.params.task, entry, actor);
146
183
  }),
147
184
  route({
@@ -152,13 +189,19 @@ export const boardRoutes = [
152
189
  errors: boardErrors,
153
190
  body: z.object({ agent: z.string(), column: z.string().optional() }),
154
191
  }, async (c) => {
155
- await requireOn();
156
192
  const { agent, column } = await c.body();
193
+ if (onCloud(c))
194
+ return { task: await cloud.pickCloudTask(c.trust, c.params.board, agent, column) };
195
+ await requireOn();
157
196
  return { task: await pickTask(refOf(c), agent, { column }) };
158
197
  }),
159
198
  route({ name: "tasks.delete", method: "DELETE", path: "/api/boards/:board/tasks/:task", summary: "move the task folder to the trash", errors: boardErrors }, async (c) => {
160
- await requireOn();
161
- await deleteTask(refOf(c), c.params.task);
199
+ if (onCloud(c))
200
+ await cloud.deleteCloudTask(c.trust, c.params.board, c.params.task);
201
+ else {
202
+ await requireOn();
203
+ await deleteTask(refOf(c), c.params.task);
204
+ }
162
205
  return { ok: true };
163
206
  }),
164
207
  ];
@@ -107,7 +107,7 @@ export declare const routes: (Route<"agents.addJournal", {
107
107
  content: string;
108
108
  }, "/api/agents/:slug/skills/:name", undefined> | Route<"agents.skills", {
109
109
  skills: import("../../core/skills.js").SkillInfo[];
110
- }, "/api/agents/:slug/skills", undefined> | Route<"agents.status", Record<string, import("../../core/agent-status.js").AgentStatus>, "/api/agent-status", undefined> | Route<"attention.list", import("../../core/attention.js").AttentionView, "/api/attention", undefined> | Route<"boards.create", import("./router.js").Reply<import("../../core/boards.js").BoardDetail>, "/api/boards", z.ZodObject<{
110
+ }, "/api/agents/:slug/skills", undefined> | Route<"agents.status", Record<string, import("../../core/agent-status.js").AgentStatus>, "/api/agent-status", undefined> | Route<"attention.list", import("../../core/attention.js").AttentionView, "/api/attention", undefined> | Route<"boards.create", import("./router.js").Reply<import("../../core/boards.js").BoardSummary & import("../cloud-boards.js").CloudMark>, "/api/boards", z.ZodObject<{
111
111
  title: z.ZodString;
112
112
  slug: z.ZodOptional<z.ZodString>;
113
113
  project: z.ZodOptional<z.ZodString>;
@@ -120,11 +120,21 @@ export declare const routes: (Route<"agents.addJournal", {
120
120
  }, z.core.$strip>]>>>;
121
121
  agent: z.ZodOptional<z.ZodString>;
122
122
  notes: z.ZodOptional<z.ZodString>;
123
+ cloud: z.ZodOptional<z.ZodBoolean>;
123
124
  }, z.core.$strip>> | Route<"boards.delete", {
124
125
  ok: boolean;
125
126
  }, "/api/boards/:board", undefined> | Route<"boards.ensure", import("../../core/boards.js").BoardDetail, "/api/boards/default", z.ZodObject<{
126
127
  project: z.ZodOptional<z.ZodString>;
127
- }, z.core.$strip>> | Route<"boards.get", import("../../core/boards.js").BoardDetail, "/api/boards/:board", undefined> | Route<"boards.list", import("../../core/boards.js").BoardsView, "/api/boards", undefined> | Route<"boards.save", import("../../core/boards.js").BoardDetail, "/api/boards/:board", z.ZodObject<{
128
+ }, z.core.$strip>> | Route<"boards.get", import("../../core/boards.js").BoardDetail, "/api/boards/:board", undefined> | Route<"boards.list", import("../../core/boards.js").BoardsView | {
129
+ enabled: boolean;
130
+ root?: string;
131
+ error?: string;
132
+ boards: import("../../core/boards.js").BoardSummary[];
133
+ cloud: {
134
+ offline?: boolean | undefined;
135
+ error?: string | undefined;
136
+ };
137
+ }, "/api/boards", undefined> | Route<"boards.save", import("../../core/boards.js").BoardSummary & import("../cloud-boards.js").CloudMark, "/api/boards/:board", z.ZodObject<{
128
138
  title: z.ZodOptional<z.ZodString>;
129
139
  columns: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodObject<{
130
140
  slug: z.ZodString;
@@ -959,6 +969,7 @@ export declare const routes: (Route<"agents.addJournal", {
959
969
  files: number;
960
970
  lastLog?: string;
961
971
  stale?: boolean;
972
+ cloud?: true;
962
973
  notes: string;
963
974
  log: string;
964
975
  fileList: string[];
@@ -977,7 +988,7 @@ export declare const routes: (Route<"agents.addJournal", {
977
988
  message: z.ZodOptional<z.ZodString>;
978
989
  actor: z.ZodOptional<z.ZodString>;
979
990
  }, z.core.$strip>> | Route<"tasks.pick", {
980
- task: import("../../core/boards.js").TaskDetail | null;
991
+ task: (import("../../core/boards.js").TaskDetail & import("../cloud-boards.js").CloudMark) | null;
981
992
  }, "/api/boards/:board/pick", z.ZodObject<{
982
993
  agent: z.ZodString;
983
994
  column: z.ZodOptional<z.ZodString>;
@@ -0,0 +1,79 @@
1
+ import type { RemotePerson } from "./api/remote-boards.js";
2
+ import type { BoardDetail, BoardSummary, ListedTask, TaskDetail } from "../core/boards.js";
3
+ import type { Trust } from "./trust.js";
4
+ /**
5
+ * Cloud boards in the shape of local boards. The boards API (api/boards.ts)
6
+ * serves a cloud board wherever it serves a local one, so every view —
7
+ * home, the boards page, a board, a task beside its chat, the context
8
+ * column — shows and edits it the same way. A cloud board's slug is its
9
+ * cloud slug behind "@" (`@launch-plan`), which no local board can have
10
+ * (SLUG_RE); a task is addressed by its number; refs read `@launch-plan/3`.
11
+ *
12
+ * What a cloud board has not: files in a task folder, a default agent,
13
+ * rules (board.md's body), links to projects, waking an assigned agent.
14
+ * Its "done" and "review" columns are the columns with those slugs.
15
+ */
16
+ export declare const CLOUD_PREFIX = "@";
17
+ export declare const isCloudBoard: (board: string | undefined) => boolean;
18
+ export interface CloudMark {
19
+ /** Kept in kraftwerk cloud, shared with everyone on the workspace. */
20
+ cloud?: true;
21
+ }
22
+ export interface CloudList {
23
+ boards: (BoardSummary & CloudMark)[];
24
+ /** Why there are none to show: offline (the cloud off or not answering), or not set up for this workspace. */
25
+ error?: string;
26
+ offline?: boolean;
27
+ /** This workspace in the cloud's web app. */
28
+ url?: string | null;
29
+ }
30
+ /** The cloud boards beside the local ones; never throws — offline is reported, not raised. */
31
+ export declare function listCloudBoards(trust: Trust): Promise<CloudList>;
32
+ /** Every task of every cloud board, as tasks.list lists them; [] while offline. */
33
+ export declare function listCloudTasks(trust: Trust, boards?: CloudList): Promise<ListedTask[]>;
34
+ export declare function getCloudBoard(trust: Trust, board: string): Promise<BoardDetail & CloudMark & {
35
+ people: RemotePerson[];
36
+ actor: string;
37
+ }>;
38
+ export declare function getCloudTask(trust: Trust, board: string, t: string): Promise<TaskDetail & CloudMark>;
39
+ export declare function createCloudBoard(trust: Trust, input: {
40
+ title: string;
41
+ slug?: string;
42
+ columns?: unknown;
43
+ }): Promise<BoardSummary & CloudMark>;
44
+ export declare function saveCloudBoard(trust: Trust, board: string, input: {
45
+ title?: string;
46
+ columns?: unknown;
47
+ }): Promise<BoardSummary & CloudMark>;
48
+ export declare function deleteCloudBoard(trust: Trust, board: string): Promise<void>;
49
+ export interface CloudTaskInput {
50
+ title?: string;
51
+ status?: string;
52
+ order?: number;
53
+ assignee?: string | null;
54
+ due?: string | null;
55
+ tags?: unknown;
56
+ notes?: string;
57
+ actor?: string;
58
+ message?: string;
59
+ }
60
+ export declare function createCloudTask(trust: Trust, board: string, input: CloudTaskInput & {
61
+ title: string;
62
+ }): Promise<TaskDetail & CloudMark>;
63
+ export declare function saveCloudTask(trust: Trust, board: string, t: string, input: CloudTaskInput): Promise<TaskDetail & CloudMark>;
64
+ /** Into a column, above `before` (a task's number or slug) or at `order`; at the end otherwise. */
65
+ export declare function moveCloudTask(trust: Trust, board: string, t: string, status: string, opts: {
66
+ before?: string;
67
+ order?: number;
68
+ message?: string;
69
+ actor?: string;
70
+ }): Promise<TaskDetail & CloudMark>;
71
+ /** Give the task to an agent or a person; null or "human" hands it back to the review column, as on a local board. */
72
+ export declare function assignCloudTask(trust: Trust, board: string, t: string, to: string | null, opts: {
73
+ message?: string;
74
+ actor?: string;
75
+ }): Promise<TaskDetail & CloudMark>;
76
+ export declare function logCloudTask(trust: Trust, board: string, t: string, entry: string, actor?: string): Promise<TaskDetail & CloudMark>;
77
+ export declare function deleteCloudTask(trust: Trust, board: string, t: string): Promise<void>;
78
+ /** An agent takes the next unassigned task of the pick column (todo, else the second), as on a local board. */
79
+ export declare function pickCloudTask(trust: Trust, board: string, agent: string, column?: string): Promise<(TaskDetail & CloudMark) | null>;