@songsid/agend 2.4.0-beta.22 → 2.4.0-beta.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (284) hide show
  1. package/dist/agent-cli-instructions.md +4 -3
  2. package/dist/agent-cli.js +32 -2
  3. package/dist/agent-cli.js.map +1 -1
  4. package/dist/agent-file-read.js +2 -2
  5. package/dist/agent-file-read.js.map +1 -1
  6. package/dist/agent-whats-new.js +17 -1
  7. package/dist/agent-whats-new.js.map +1 -1
  8. package/dist/auth-api.d.ts +2 -0
  9. package/dist/auth-api.js +5 -2
  10. package/dist/auth-api.js.map +1 -1
  11. package/dist/authority/web-authority.d.ts +17 -3
  12. package/dist/authority/web-authority.js +56 -3
  13. package/dist/authority/web-authority.js.map +1 -1
  14. package/dist/backend/claude-code.d.ts +15 -0
  15. package/dist/backend/claude-code.js +8 -3
  16. package/dist/backend/claude-code.js.map +1 -1
  17. package/dist/backend/claude-mcp-carry.d.ts +63 -0
  18. package/dist/backend/claude-mcp-carry.js +242 -0
  19. package/dist/backend/claude-mcp-carry.js.map +1 -0
  20. package/dist/build-provenance.json +1 -1
  21. package/dist/channel/mcp-tools.js +15 -7
  22. package/dist/channel/mcp-tools.js.map +1 -1
  23. package/dist/classic-channel-manager.d.ts +1 -1
  24. package/dist/classic-channel-manager.js +2 -2
  25. package/dist/classic-channel-manager.js.map +1 -1
  26. package/dist/config-validator.js +6 -0
  27. package/dist/config-validator.js.map +1 -1
  28. package/dist/contact-auth-api.js +3 -1
  29. package/dist/contact-auth-api.js.map +1 -1
  30. package/dist/contact-auth-service.js +1 -1
  31. package/dist/contact-auth-service.js.map +1 -1
  32. package/dist/contact-auth-store.d.ts +28 -2
  33. package/dist/contact-auth-store.js +72 -4
  34. package/dist/contact-auth-store.js.map +1 -1
  35. package/dist/contact-change-proposals.d.ts +18 -1
  36. package/dist/contact-change-proposals.js +38 -4
  37. package/dist/contact-change-proposals.js.map +1 -1
  38. package/dist/contact-state-view.d.ts +103 -0
  39. package/dist/contact-state-view.js +80 -0
  40. package/dist/contact-state-view.js.map +1 -0
  41. package/dist/daemon.d.ts +11 -0
  42. package/dist/daemon.js +66 -15
  43. package/dist/daemon.js.map +1 -1
  44. package/dist/dashboard-permissions.d.ts +8 -0
  45. package/dist/dashboard-permissions.js +8 -0
  46. package/dist/dashboard-permissions.js.map +1 -1
  47. package/dist/delivery-outbox.d.ts +15 -1
  48. package/dist/delivery-outbox.js +60 -2
  49. package/dist/delivery-outbox.js.map +1 -1
  50. package/dist/fleet-manager.d.ts +157 -15
  51. package/dist/fleet-manager.js +522 -78
  52. package/dist/fleet-manager.js.map +1 -1
  53. package/dist/general-knowledge/skills/admin/SKILL.md +52 -0
  54. package/dist/general-knowledge/skills/concepts/SKILL.md +31 -21
  55. package/dist/general-knowledge/skills/credential-profiles/SKILL.md +6 -0
  56. package/dist/general-knowledge/skills/cross-instance-messaging/SKILL.md +6 -3
  57. package/dist/general-knowledge/skills/fleet-config/SKILL.md +3 -3
  58. package/dist/general-knowledge/skills/hub/SKILL.md +6 -1
  59. package/dist/general-knowledge/skills/instance-lifecycle/SKILL.md +1 -1
  60. package/dist/general-knowledge/skills/task-board/SKILL.md +17 -0
  61. package/dist/general-knowledge/skills/web-appearance/SKILL.md +4 -0
  62. package/dist/general-knowledge/skills/web-dashboard/SKILL.md +75 -12
  63. package/dist/general-knowledge/skills/worker-collaboration/SKILL.md +1 -1
  64. package/dist/general-role.d.ts +1 -1
  65. package/dist/general-role.js +1 -0
  66. package/dist/general-role.js.map +1 -1
  67. package/dist/hub/client.js +6 -1
  68. package/dist/hub/client.js.map +1 -1
  69. package/dist/hub/compose/member.d.ts +2 -1
  70. package/dist/hub/compose/member.js +3 -2
  71. package/dist/hub/compose/member.js.map +1 -1
  72. package/dist/hub/compose/server.js +2 -1
  73. package/dist/hub/compose/server.js.map +1 -1
  74. package/dist/hub/http/compose.js +5 -0
  75. package/dist/hub/http/compose.js.map +1 -1
  76. package/dist/hub/protocol.d.ts +21 -0
  77. package/dist/hub/protocol.js +3 -0
  78. package/dist/hub/protocol.js.map +1 -1
  79. package/dist/hub/question-close-model.d.ts +17 -0
  80. package/dist/hub/question-close-model.js +7 -0
  81. package/dist/hub/question-close-model.js.map +1 -0
  82. package/dist/hub/representative.d.ts +5 -0
  83. package/dist/hub/representative.js +51 -1
  84. package/dist/hub/representative.js.map +1 -1
  85. package/dist/hub/rooms/direct-view.js +1 -0
  86. package/dist/hub/rooms/direct-view.js.map +1 -1
  87. package/dist/hub/rooms/types.d.ts +1 -1
  88. package/dist/hub/rooms.d.ts +3 -0
  89. package/dist/hub/rooms.js +27 -1
  90. package/dist/hub/rooms.js.map +1 -1
  91. package/dist/hub/server.js +6 -1
  92. package/dist/hub/server.js.map +1 -1
  93. package/dist/hub/types.d.ts +2 -2
  94. package/dist/human-delivery-receipts.d.ts +12 -2
  95. package/dist/human-delivery-receipts.js +19 -4
  96. package/dist/human-delivery-receipts.js.map +1 -1
  97. package/dist/instance-lifecycle.d.ts +2 -0
  98. package/dist/instance-lifecycle.js +29 -1
  99. package/dist/instance-lifecycle.js.map +1 -1
  100. package/dist/instructions.d.ts +1 -1
  101. package/dist/instructions.js +1 -1
  102. package/dist/instructions.js.map +1 -1
  103. package/dist/locale.js +110 -12
  104. package/dist/locale.js.map +1 -1
  105. package/dist/needs-you-hub.d.ts +3 -0
  106. package/dist/needs-you-hub.js +31 -5
  107. package/dist/needs-you-hub.js.map +1 -1
  108. package/dist/needs-you.d.ts +16 -1
  109. package/dist/needs-you.js +7 -1
  110. package/dist/needs-you.js.map +1 -1
  111. package/dist/office-share-page.js +2 -2
  112. package/dist/office-share-page.js.map +1 -1
  113. package/dist/office-share.js +2 -1
  114. package/dist/office-share.js.map +1 -1
  115. package/dist/outbound-handlers.d.ts +4 -0
  116. package/dist/outbound-handlers.js +69 -11
  117. package/dist/outbound-handlers.js.map +1 -1
  118. package/dist/outbound-schemas.d.ts +5 -1
  119. package/dist/outbound-schemas.js +10 -7
  120. package/dist/outbound-schemas.js.map +1 -1
  121. package/dist/public-web-gateway.js +21 -0
  122. package/dist/public-web-gateway.js.map +1 -1
  123. package/dist/reply-buttons-controller.d.ts +2 -1
  124. package/dist/reply-buttons-controller.js +1 -1
  125. package/dist/reply-buttons-controller.js.map +1 -1
  126. package/dist/request-context-compatibility.d.ts +20 -0
  127. package/dist/request-context-compatibility.js +74 -0
  128. package/dist/request-context-compatibility.js.map +1 -0
  129. package/dist/request-context-protocol.d.ts +137 -0
  130. package/dist/request-context-protocol.js +38 -0
  131. package/dist/request-context-protocol.js.map +1 -0
  132. package/dist/request-context-store.d.ts +25 -0
  133. package/dist/request-context-store.js +137 -0
  134. package/dist/request-context-store.js.map +1 -0
  135. package/dist/scheduler/db.js +26 -0
  136. package/dist/scheduler/db.js.map +1 -1
  137. package/dist/scheduler/task-board-text.d.ts +2 -0
  138. package/dist/scheduler/task-board-text.js +12 -0
  139. package/dist/scheduler/task-board-text.js.map +1 -1
  140. package/dist/scheduler/task-board.d.ts +102 -2
  141. package/dist/scheduler/task-board.js +242 -24
  142. package/dist/scheduler/task-board.js.map +1 -1
  143. package/dist/scheduler/task-files.d.ts +80 -0
  144. package/dist/scheduler/task-files.js +357 -0
  145. package/dist/scheduler/task-files.js.map +1 -0
  146. package/dist/settings-api.d.ts +2 -0
  147. package/dist/settings-api.js +6 -1
  148. package/dist/settings-api.js.map +1 -1
  149. package/dist/settings-baseline.d.ts +1 -0
  150. package/dist/settings-baseline.js +1 -1
  151. package/dist/settings-baseline.js.map +1 -1
  152. package/dist/settings-effect.d.ts +2 -0
  153. package/dist/settings-effect.js +5 -1
  154. package/dist/settings-effect.js.map +1 -1
  155. package/dist/task-attach-client.d.ts +43 -0
  156. package/dist/task-attach-client.js +125 -0
  157. package/dist/task-attach-client.js.map +1 -0
  158. package/dist/task-board-tool.d.ts +12 -0
  159. package/dist/task-board-tool.js +107 -6
  160. package/dist/task-board-tool.js.map +1 -1
  161. package/dist/task-file-limits.d.ts +15 -0
  162. package/dist/task-file-limits.js +21 -0
  163. package/dist/task-file-limits.js.map +1 -0
  164. package/dist/tool-permissions.d.ts +32 -0
  165. package/dist/tool-permissions.js +64 -1
  166. package/dist/tool-permissions.js.map +1 -1
  167. package/dist/types.d.ts +6 -0
  168. package/dist/ui/accounts-keepalive.js +2 -1
  169. package/dist/ui/agent-details-settings.js +7 -5
  170. package/dist/ui/agent-who-can-use-strings.js +125 -0
  171. package/dist/ui/agent-who-can-use.js +238 -0
  172. package/dist/ui/chat-activity.js +2 -1
  173. package/dist/ui/chat-pins.js +2 -1
  174. package/dist/ui/claude-credentials.js +2 -1
  175. package/dist/ui/contact-auth-strings.js +28 -17
  176. package/dist/ui/contact-authorizations.js +6 -4
  177. package/dist/ui/contact-needs.js +6 -1
  178. package/dist/ui/contact-permissions.js +6 -4
  179. package/dist/ui/contact-tool-groups.js +1 -1
  180. package/dist/ui/contact-verify-need.js +46 -0
  181. package/dist/ui/fleet-cache.js +2 -1
  182. package/dist/ui/fleet-office-card.js +23 -5
  183. package/dist/ui/fleet-office-editor.js +5 -5
  184. package/dist/ui/fleet-office-pack.d.ts +10 -0
  185. package/dist/ui/fleet-office-pack.js +65 -2
  186. package/dist/ui/fleet-office-skin.js +52 -14
  187. package/dist/ui/fleet-office-store.js +33 -2
  188. package/dist/ui/fleet-office-vehicles.js +130 -0
  189. package/dist/ui/fleet-office-zones.js +27 -10
  190. package/dist/ui/fleet-office.js +128 -40
  191. package/dist/ui/fleet-org.js +6 -1
  192. package/dist/ui/fleet-tab-icons.js +19 -0
  193. package/dist/ui/fleet-task-activity.js +11 -83
  194. package/dist/ui/fleet-task-archive.js +111 -0
  195. package/dist/ui/fleet-task-card.js +6 -4
  196. package/dist/ui/fleet-task-common.js +2 -2
  197. package/dist/ui/fleet-task-edit.js +8 -1
  198. package/dist/ui/fleet-task-files.js +196 -0
  199. package/dist/ui/fleet-task-md.js +98 -0
  200. package/dist/ui/fleet-task-menu.js +1 -1
  201. package/dist/ui/fleet-task-stats.js +2 -2
  202. package/dist/ui/fleet-task-view.js +14 -9
  203. package/dist/ui/fleet-tasks.js +42 -18
  204. package/dist/ui/fleet-usage.js +2 -1
  205. package/dist/ui/hub-admin-overview.js +2 -1
  206. package/dist/ui/hub-agent-intro.js +2 -1
  207. package/dist/ui/hub-assistant-admin.js +2 -1
  208. package/dist/ui/hub-directory-notices.js +2 -1
  209. package/dist/ui/hub-enrolment-code.js +2 -1
  210. package/dist/ui/hub-my-agents.js +2 -1
  211. package/dist/ui/hub-quick-pairing.js +2 -1
  212. package/dist/ui/hub-role-audit.js +2 -1
  213. package/dist/ui/hub-role-forms.js +3 -2
  214. package/dist/ui/hub-role-view.js +3 -2
  215. package/dist/ui/hub-roles.js +2 -1
  216. package/dist/ui/hub-room-agent-strings.js +2 -1
  217. package/dist/ui/hub-room-list.js +2 -1
  218. package/dist/ui/hub-room-owner-requests.js +2 -1
  219. package/dist/ui/hub-room-pins.js +2 -1
  220. package/dist/ui/hub-room-strings.js +2 -2
  221. package/dist/ui/hub-room-thread.js +1 -1
  222. package/dist/ui/log-row.js +4 -3
  223. package/dist/ui/office-share-dialog.js +2 -1
  224. package/dist/ui/office-share-page.js +2 -1
  225. package/dist/ui/page-share-dialog.js +3 -2
  226. package/dist/ui/panel-chat.js +2 -1
  227. package/dist/ui/panel-details.js +5 -2
  228. package/dist/ui/panel-fleet.js +10 -5
  229. package/dist/ui/panel-hub.js +2 -1
  230. package/dist/ui/panel-needs.js +34 -6
  231. package/dist/ui/panel-notices.js +2 -1
  232. package/dist/ui/panel-runtimes.js +2 -1
  233. package/dist/ui/panel-settings.js +15 -1
  234. package/dist/ui/panel-windows-cli.js +3 -2
  235. package/dist/ui/runtime-cli-install.js +2 -1
  236. package/dist/ui/settings-appearance.js +2 -1
  237. package/dist/ui/settings-guests.js +4 -3
  238. package/dist/ui/settings-hub-member-address.js +2 -1
  239. package/dist/ui/settings-hub-setup.js +2 -1
  240. package/dist/ui/settings-hub-web-address.js +2 -1
  241. package/dist/ui/settings-hub.js +2 -1
  242. package/dist/ui/settings-registry.js +1 -0
  243. package/dist/ui/settings-shared-strings.js +9 -0
  244. package/dist/ui/settings-shared.js +6 -1
  245. package/dist/ui/settings-update.js +2 -1
  246. package/dist/ui/settings-web-authority.js +2 -1
  247. package/dist/ui/shared/agent-sheet.js +2 -1
  248. package/dist/ui/shared/app-i18n.js +2 -2
  249. package/dist/ui/shared/app-needs.js +8 -1
  250. package/dist/ui/shared/app-session.js +4 -3
  251. package/dist/ui/shared/app-shell.js +6 -2
  252. package/dist/ui/shared/app.css +93 -11
  253. package/dist/ui/shared/chat-strings.js +4 -4
  254. package/dist/ui/shared/chat-time.js +7 -4
  255. package/dist/ui/shared/clock-text.js +57 -0
  256. package/dist/ui/shared/device-roles.js +6 -5
  257. package/dist/ui/shared/instance-nav.js +17 -22
  258. package/dist/ui/shared/task-board.css +64 -0
  259. package/dist/ui/shared/usage-dialog.js +2 -1
  260. package/dist/ui/shared/view-strings.js +0 -14
  261. package/dist/ui/shared/web-authorize.js +3 -2
  262. package/dist/ui/subagent-row.js +2 -1
  263. package/dist/web-api.d.ts +18 -2
  264. package/dist/web-api.js +159 -27
  265. package/dist/web-api.js.map +1 -1
  266. package/dist/web-login.d.ts +6 -1
  267. package/dist/web-login.js +8 -3
  268. package/dist/web-login.js.map +1 -1
  269. package/dist/web-office-acts.d.ts +16 -0
  270. package/dist/web-office-acts.js +27 -9
  271. package/dist/web-office-acts.js.map +1 -1
  272. package/dist/web-office-pack-read.js +1 -1
  273. package/dist/web-office-pack-read.js.map +1 -1
  274. package/dist/web-office-skins.d.ts +5 -3
  275. package/dist/web-office-skins.js +20 -16
  276. package/dist/web-office-skins.js.map +1 -1
  277. package/dist/web-session-authorization.d.ts +3 -0
  278. package/dist/web-session-authorization.js +1 -1
  279. package/dist/web-session-authorization.js.map +1 -1
  280. package/dist/web-settings-patch.d.ts +27 -0
  281. package/dist/web-settings-patch.js +67 -0
  282. package/dist/web-settings-patch.js.map +1 -1
  283. package/dist/workflow-templates/default.md +1 -0
  284. package/package.json +1 -1
@@ -1,5 +1,6 @@
1
1
  import { randomUUID } from "node:crypto";
2
2
  import { parseMentions } from "./task-board-mentions.js";
3
+ import { TASK_FILE_LIMITS, TaskFileError } from "./task-files.js";
3
4
  export const CARD_STATUSES = ["open", "claimed", "blocked", "review", "done", "cancelled"];
4
5
  /** Statuses still on the board (not finished). */
5
6
  export const LIVE_CARD_STATUSES = ["open", "claimed", "blocked", "review"];
@@ -27,6 +28,18 @@ export const CARD_LIMITS = {
27
28
  };
28
29
  /** How far back finished sub tasks and cancelled main tasks stay on the board. */
29
30
  const BOARD_DAYS = 14;
31
+ /**
32
+ * M-3668 (the user, 11-24): a finished main task — done or cancelled — leaves the dashboard's board this many days after it
33
+ * finished (defaults.task_board.archive_after_days; 0 = never). A view rule only: nothing in the database changes, search
34
+ * and its number still find it, and moving it to To do reopens it (its status, not its age, makes it archived).
35
+ */
36
+ export const ARCHIVE_AFTER_DAYS = 3;
37
+ /** The archive age as fleet.yaml gives it: a whole number of days, 0–3650; anything else is the default. */
38
+ export function archiveAfterDays(v) {
39
+ return typeof v === "number" && Number.isInteger(v) && v >= 0 && v <= 3650 ? v : ARCHIVE_AFTER_DAYS;
40
+ }
41
+ /** M-3668: how many finished main tasks a project's Done column counts as "this week". */
42
+ const WEEK_MS = 7 * 86_400_000;
30
43
  const BATCH_MAX = 30;
31
44
  /**
32
45
  * The loop guard for comments that wake (docs/design/task-board.md, "Comments and mentions"): instances (and scripts,
@@ -286,10 +299,17 @@ export class TaskBoard {
286
299
  /** The notes of the last write, until a caller of the `task` tool's old actions takes them (takeNotes). */
287
300
  lastNotes = [];
288
301
  codes = new Map();
302
+ /** Where files on cards live (task-files.ts); none: this process cannot take attachments (a bare board in a test, the CLI). */
303
+ fileStore = null;
304
+ /** What undoes this write's file moves, when the write fails after them. */
305
+ undo = [];
289
306
  constructor(db, now = () => new Date()) {
290
307
  this.db = db;
291
308
  this.now = now;
292
309
  }
310
+ /** The store for files on cards (the fleet's scheduler sets it); null takes attachments away. */
311
+ setFiles(store) { this.fileStore = store; }
312
+ files() { return this.fileStore; }
293
313
  /** Called with what each committed write changed. Returns an unsubscribe function. */
294
314
  onChange(listener) {
295
315
  this.listeners.push(listener);
@@ -375,6 +395,20 @@ export class TaskBoard {
375
395
  at TEXT NOT NULL,
376
396
  PRIMARY KEY (task_id, instance)
377
397
  );
398
+ CREATE TABLE IF NOT EXISTS task_attachments (
399
+ id TEXT PRIMARY KEY,
400
+ task_id TEXT NOT NULL,
401
+ entry_id INTEGER,
402
+ name TEXT NOT NULL,
403
+ mime TEXT NOT NULL,
404
+ kind TEXT NOT NULL,
405
+ size INTEGER NOT NULL,
406
+ sha256 TEXT NOT NULL,
407
+ author TEXT NOT NULL,
408
+ author_kind TEXT NOT NULL,
409
+ at TEXT NOT NULL
410
+ );
411
+ CREATE INDEX IF NOT EXISTS idx_task_attachments_task ON task_attachments(task_id, at);
378
412
  `);
379
413
  // #2352: a project's lead instance, added in place (null: its waiting cards' buttons stay in General).
380
414
  const projectCols = new Set(this.db.prepare("PRAGMA table_info(task_projects)").all().map((c) => c.name));
@@ -575,25 +609,76 @@ export class TaskBoard {
575
609
  * tasks — or every done main task with `allDone` (the Done column's "All"). Older finished work stays in the
576
610
  * database and in the projects' numbers (projectStats), not in every board read.
577
611
  */
578
- boardCards(days = BOARD_DAYS, allDone = false) {
612
+ boardCards(days = BOARD_DAYS, allDone = false, archiveDays = 0) {
579
613
  const since = new Date(this.now().getTime() - days * 86_400_000).toISOString();
614
+ if (archiveDays > 0) {
615
+ // M-3668: finished main tasks until they are archived (`allDone` no longer reads past it: the Archive list does).
616
+ // #4428 review: an archived main task's sub tasks go with it (isArchived), even one done more recently.
617
+ const kept = new Date(this.now().getTime() - archiveDays * 86_400_000).toISOString();
618
+ return this.db.prepare(`SELECT * FROM tasks WHERE
619
+ (kind = 'main' AND (status NOT IN ('done', 'cancelled') OR COALESCE(done_at, updated_at) >= ?))
620
+ OR (kind = 'sub' AND status != 'cancelled' AND (status != 'done' OR COALESCE(done_at, updated_at) >= ?)
621
+ AND NOT EXISTS (SELECT 1 FROM tasks m WHERE m.id = tasks.parent_id AND m.status IN ('done', 'cancelled') AND COALESCE(m.done_at, m.updated_at) < ?))
622
+ ORDER BY sort`).all(kept, since, kept).map(toCard);
623
+ }
580
624
  const rows = this.db.prepare(`SELECT * FROM tasks WHERE
581
625
  (kind = 'main' AND (status NOT IN ('done', 'cancelled') OR (status = 'done' AND (? OR COALESCE(done_at, updated_at) >= ?)) OR (status = 'cancelled' AND updated_at >= ?)))
582
626
  OR (kind = 'sub' AND status != 'cancelled' AND (status != 'done' OR COALESCE(done_at, updated_at) >= ?))
583
627
  ORDER BY sort`).all(allDone ? 1 : 0, since, since, since);
584
628
  return rows.map(toCard);
585
629
  }
630
+ /**
631
+ * #4428 review: ` AND …` leaving out the cards that name one of `names` (assigned to, created by or handed out by one:
632
+ * the public link's hiding, web-api boardHiding), with its values; empty when none.
633
+ */
634
+ unseen(names = []) {
635
+ const out = [...new Set(names)];
636
+ if (!out.length)
637
+ return { sql: "", args: [] };
638
+ const marks = out.map(() => "?").join(", ");
639
+ return { sql: ` AND (assignee IS NULL OR assignee NOT IN (${marks})) AND created_by NOT IN (${marks}) AND (dispatcher IS NULL OR dispatcher NOT IN (${marks}))`,
640
+ args: [...out, ...out, ...out] };
641
+ }
642
+ /**
643
+ * #4428 review: what time alone changes in a board read and its numbers — how many finished cards have passed each
644
+ * of its lines (archived, out of this week's count, out of the recent window) — with the archive age. A card passes a
645
+ * line without a write (the revision stays), so a page's "same revision" read is answered `unchanged` only when this
646
+ * matches too. One counting pass, no rows. `leaveOut`: as projectStats (the public link's hidden instances' cards never
647
+ * move it).
648
+ */
649
+ boardEpoch(archiveDays = 0, days = BOARD_DAYS, leaveOut = []) {
650
+ const nowMs = this.now().getTime();
651
+ const at = (ms) => new Date(nowMs - ms).toISOString();
652
+ const kept = archiveDays > 0 ? at(archiveDays * 86_400_000) : "", week = at(WEEK_MS), since = at(days * 86_400_000), hide = this.unseen(leaveOut);
653
+ const r = this.db.prepare(`SELECT
654
+ COALESCE(SUM(kind = 'main' AND status IN ('done', 'cancelled') AND COALESCE(done_at, updated_at) < ?), 0) AS archived,
655
+ COALESCE(SUM(kind = 'main' AND status = 'done' AND COALESCE(done_at, updated_at) < ?), 0) AS week,
656
+ COALESCE(SUM(status IN ('done', 'cancelled') AND (CASE WHEN kind = 'main' AND status = 'cancelled' THEN updated_at ELSE COALESCE(done_at, updated_at) END) < ?), 0) AS old
657
+ FROM tasks WHERE 1${hide.sql}`).get(kept, week, since, ...hide.args);
658
+ return `${archiveDays}:${r.archived}:${r.week}:${r.old}`;
659
+ }
586
660
  /**
587
661
  * Each project's numbers (by id; "none" for No project) over all its cards, finished ones included: main tasks,
588
662
  * work units (a main task's sub tasks, or one unit for a main task without them; a done main task counts all its
589
663
  * units done), cards waiting for the person and blocked, and the last change. One pass over the table. #2080: waiting
590
664
  * counts only the cards in review the person confirms (waitsForPerson, `gone` as for Needs you), never an agent's.
665
+ * #4428 review: `leaveOut` names (the public link's hidden instances) — their cards, and a hidden main task's sub tasks,
666
+ * count nowhere, as the board read leaves them out.
591
667
  */
592
- projectStats(gone) {
593
- const rows = this.db.prepare("SELECT id, kind, status, project_id, parent_id, updated_at, needs_review, dispatcher, dispatcher_kind FROM tasks").all();
668
+ projectStats(gone, archiveDays = 0, leaveOut = []) {
669
+ const all = this.db.prepare("SELECT id, kind, status, project_id, parent_id, updated_at, done_at, needs_review, dispatcher, dispatcher_kind, assignee, created_by FROM tasks").all();
670
+ const unseenNames = new Set(leaveOut);
671
+ const names = (r) => [r.assignee, r.created_by, r.dispatcher].some((n) => typeof n === "string" && unseenNames.has(n));
672
+ const hiddenMains = unseenNames.size ? new Set(all.filter((r) => r.kind === "main" && names(r)).map((r) => r.id)) : new Set();
673
+ const rows = unseenNames.size ? all.filter((r) => !names(r) && !(r.kind === "sub" && hiddenMains.has(r.parent_id))) : all;
674
+ const nowMs = this.now().getTime(), kept = archiveDays > 0 ? new Date(nowMs - archiveDays * 86_400_000).toISOString() : null;
675
+ const week = new Date(nowMs - WEEK_MS).toISOString();
676
+ const finished = (r) => (r.done_at ?? r.updated_at);
677
+ // M-3668: an archived main task (and its sub tasks) is left out of every number but `archived`.
678
+ const archivedMains = new Set(kept ? rows.filter((r) => r.kind === "main" && (r.status === "done" || r.status === "cancelled") && finished(r) < kept).map((r) => r.id) : []);
594
679
  const subs = new Map();
595
680
  for (const r of rows) {
596
- if (r.kind !== "sub" || !r.parent_id || r.status === "cancelled")
681
+ if (r.kind !== "sub" || !r.parent_id || r.status === "cancelled" || archivedMains.has(r.parent_id))
597
682
  continue;
598
683
  const p = subs.get(r.parent_id) ?? { total: 0, open: 0, claimed: 0, blocked: 0, review: 0, done: 0 };
599
684
  p.total++;
@@ -603,10 +688,21 @@ export class TaskBoard {
603
688
  const out = {};
604
689
  for (const r of rows) {
605
690
  const key = r.project_id === null || r.project_id === undefined ? "none" : String(r.project_id);
606
- const st = out[key] ??= { mains: 0, units: { total: 0, open: 0, claimed: 0, blocked: 0, review: 0, done: 0 }, percent: 0, waiting: 0, blocked: 0, lastActivity: null };
691
+ const st = out[key] ??= { mains: 0, units: { total: 0, open: 0, claimed: 0, blocked: 0, review: 0, done: 0 }, percent: 0, waiting: 0, blocked: 0, lastActivity: null, archived: 0, doneWeek: 0, archivedWeek: 0 };
607
692
  if (!st.lastActivity || r.updated_at > st.lastActivity)
608
693
  st.lastActivity = r.updated_at;
609
694
  const status = r.status;
695
+ if (r.kind === "main" && status === "done" && finished(r) >= week) {
696
+ st.doneWeek++;
697
+ if (archivedMains.has(r.id))
698
+ st.archivedWeek++;
699
+ }
700
+ if (archivedMains.has(r.id)) {
701
+ st.archived++;
702
+ continue;
703
+ }
704
+ if (r.kind === "sub" && archivedMains.has(r.parent_id))
705
+ continue;
610
706
  if (status === "cancelled")
611
707
  continue;
612
708
  if (status === "review" && waitsForPerson({ status, needsReview: Number(r.needs_review) === 1,
@@ -635,6 +731,40 @@ export class TaskBoard {
635
731
  st.percent = st.units.total ? Math.round((st.units.done / st.units.total) * 100) : 0;
636
732
  return out;
637
733
  }
734
+ /** M-3668: whether the dashboard has archived this card (a sub task goes with its main task). */
735
+ isArchived(card, archiveDays) {
736
+ if (archiveDays <= 0)
737
+ return false;
738
+ const main = card.kind === "sub" && card.parent ? this.byUuid(card.parent) : card;
739
+ if (!main || main.kind !== "main" || (main.status !== "done" && main.status !== "cancelled"))
740
+ return false;
741
+ return (main.doneAt ?? main.updatedAt) < new Date(this.now().getTime() - archiveDays * 86_400_000).toISOString();
742
+ }
743
+ /**
744
+ * M-3668: a project's archived main tasks (`project` null: No project), the most recently finished first, a page at a
745
+ * time (`before`: the last one's cursor), and who they were assigned to (the list's filter, `assignee`).
746
+ * `leaveOut`: names whose cards the reader may not see (assigned to, created by or handed out by one) — left out
747
+ * before the page, its cursor, the total and the assignees are worked out, so none of them tells of such a card.
748
+ */
749
+ archiveList(project, archiveDays, opts = {}) {
750
+ if (archiveDays <= 0)
751
+ return { cards: [], next: null, total: 0, assignees: [] };
752
+ const kept = new Date(this.now().getTime() - archiveDays * 86_400_000).toISOString();
753
+ const hide = this.unseen(opts.leaveOut);
754
+ const where = `kind = 'main' AND status IN ('done', 'cancelled') AND COALESCE(done_at, updated_at) < ? AND ${project === null ? "project_id IS NULL" : "project_id = ?"}${hide.sql}`;
755
+ const base = [kept, ...(project === null ? [] : [project]), ...hide.args];
756
+ const assignees = this.db.prepare(`SELECT DISTINCT assignee FROM tasks WHERE ${where} AND assignee IS NOT NULL ORDER BY assignee`).all(...base).map((r) => r.assignee);
757
+ const who = opts.assignee ? " AND assignee = ?" : "", whoArgs = opts.assignee ? [opts.assignee] : [];
758
+ const total = this.db.prepare(`SELECT COUNT(*) AS n FROM tasks WHERE ${where}${who}`).get(...base, ...whoArgs).n;
759
+ const cursor = typeof opts.before === "string" ? /^(.+)\|([^|]+)$/.exec(opts.before) : null;
760
+ const after = cursor ? " AND (COALESCE(done_at, updated_at) < ? OR (COALESCE(done_at, updated_at) = ? AND id < ?))" : "";
761
+ const limit = Math.min(Math.max(opts.limit ?? 50, 1), 100);
762
+ const rows = this.db.prepare(`SELECT * FROM tasks WHERE ${where}${who}${after} ORDER BY COALESCE(done_at, updated_at) DESC, id DESC LIMIT ?`)
763
+ .all(...base, ...whoArgs, ...(cursor ? [cursor[1], cursor[1], cursor[2]] : []), limit + 1);
764
+ const cards = rows.slice(0, limit).map(toCard);
765
+ const last = cards[cards.length - 1];
766
+ return { cards, next: rows.length > limit && last ? `${last.doneAt ?? last.updatedAt}|${last.uuid}` : null, total, assignees };
767
+ }
638
768
  view(card, scope = {}, gone) {
639
769
  return this.views([card], scope, gone)[0];
640
770
  }
@@ -667,6 +797,8 @@ export class TaskBoard {
667
797
  const by = this.notBy(scope, "author"), eBy = this.notBy(scope, "e.author");
668
798
  const comments = new Map(this.db.prepare(`SELECT e.task_id AS task_id, n.n AS n, e.author AS author, e.author_kind AS author_kind, e.at AS at FROM task_entries e
669
799
  JOIN (SELECT task_id, COUNT(*) AS n, MAX(id) AS last FROM task_entries WHERE kind IN ('comment', 'reject', 'approve')${by.sql} GROUP BY task_id) n ON e.id = n.last`).all(...by.args).map((r) => [r.task_id, r]));
800
+ const files = new Map(this.db.prepare(`SELECT task_id, COUNT(*) AS n FROM task_attachments WHERE 1 = 1${by.sql} GROUP BY task_id`)
801
+ .all(...by.args).map((r) => [r.task_id, r.n]));
670
802
  const unseen = new Map(this.db.prepare(`SELECT t.id AS id, COUNT(e.id) AS n FROM tasks t JOIN task_entries e
671
803
  ON e.task_id = t.id AND e.id > t.seen_entry_id AND e.kind IN ('comment', 'reject') AND e.author IS NOT t.assignee${eBy.sql}
672
804
  GROUP BY t.id`).all(...eBy.args).map((r) => [r.id, r.n]));
@@ -720,6 +852,7 @@ export class TaskBoard {
720
852
  progress: card.kind === "main" ? progress.get(card.uuid) ?? { total: 0, open: 0, claimed: 0, blocked: 0, review: 0, done: 0 } : null,
721
853
  unmetDeps: unmet(card.deps, card.parent),
722
854
  commentCount: c?.n ?? 0,
855
+ attachmentCount: files.get(card.uuid) ?? 0,
723
856
  newCommentCount: unseen.get(card.uuid) ?? 0,
724
857
  lastComment: c ? { author: c.author, authorKind: c.author_kind, at: c.at } : null,
725
858
  };
@@ -735,6 +868,7 @@ export class TaskBoard {
735
868
  comments: this.entries(card.uuid, ["comment", "reject", "approve"], 200),
736
869
  logs: this.entries(card.uuid, ["log"], 200),
737
870
  history: this.events(card.uuid, 200).filter((e) => e.type !== "reordered"),
871
+ attachments: this.attachments(card.uuid, scope),
738
872
  watchers: this.watchersOf(card.uuid),
739
873
  inheritedWatchers: card.parent ? this.watchersOf(card.parent) : [],
740
874
  leader: this.leaderOf(card),
@@ -1299,13 +1433,9 @@ export class TaskBoard {
1299
1433
  touched = true;
1300
1434
  }
1301
1435
  }
1302
- if (patch.comment !== undefined) {
1303
- const text = checkText("the comment", patch.comment, CARD_LIMITS.comment);
1304
- if (text) {
1305
- this.entry(card, "comment", actor, text);
1306
- this.commented(actor, card, text);
1436
+ if (patch.comment !== undefined || patch.attach?.length) {
1437
+ if (this.writeComment(card, actor, patch.comment ?? "", patch.attach))
1307
1438
  touched = true;
1308
- }
1309
1439
  }
1310
1440
  if (!touched)
1311
1441
  return { card, notes: ["no change"], said: [] };
@@ -1348,10 +1478,8 @@ export class TaskBoard {
1348
1478
  this.checkAnswer(card, comment);
1349
1479
  const busy = this.busyWith(card, card.assignee);
1350
1480
  if (busy.length) {
1351
- const text = checkText("the comment", comment, CARD_LIMITS.comment);
1352
- this.entry(card, "comment", actor, text);
1353
1481
  // #2801 review: the one comment that is news — the answer its assignee waits for (`kept`).
1354
- this.commented(actor, card, text, true);
1482
+ this.writeComment(card, actor, comment, options.attach, true);
1355
1483
  card.version++;
1356
1484
  card.updatedAt = this.nowIso();
1357
1485
  this.save(card);
@@ -1364,7 +1492,7 @@ export class TaskBoard {
1364
1492
  this.checkDerivedMove(card, actor, to, reason, { comment });
1365
1493
  else
1366
1494
  this.checkManualMove(card, actor, to, reason, { comment });
1367
- this.applyMove(card, actor, this.ownReview(card, actor, to, reason), reason, comment);
1495
+ this.applyMove(card, actor, this.ownReview(card, actor, to, reason), reason, comment, options.attach);
1368
1496
  return { card, from, ...this.spoken() };
1369
1497
  });
1370
1498
  }
@@ -1913,7 +2041,7 @@ export class TaskBoard {
1913
2041
  }
1914
2042
  // ── Derived state ───────────────────────────────────────
1915
2043
  /** Status bookkeeping shared by every move, then what the move sets off. */
1916
- applyMove(card, actor, to, reason, comment) {
2044
+ applyMove(card, actor, to, reason, comment, attach) {
1917
2045
  const from = card.status;
1918
2046
  const now = this.nowIso();
1919
2047
  card.status = to;
@@ -1923,11 +2051,8 @@ export class TaskBoard {
1923
2051
  card.submittedAt = now;
1924
2052
  card.doneAt = to === "done" ? now : null;
1925
2053
  card.blockedReason = to === "blocked" ? reason : "";
1926
- if (comment?.trim()) {
1927
- const text = checkText("the comment", comment, CARD_LIMITS.comment);
1928
- this.entry(card, "comment", actor, text);
1929
- this.commented(actor, card, text);
1930
- }
2054
+ if (comment?.trim() || attach?.length)
2055
+ this.writeComment(card, actor, comment ?? "", attach);
1931
2056
  card.version++;
1932
2057
  card.updatedAt = now;
1933
2058
  this.surfaceComments(card, actor);
@@ -2452,6 +2577,7 @@ export class TaskBoard {
2452
2577
  this.pending = [];
2453
2578
  this.projectsChanged = false;
2454
2579
  this.notes = [];
2580
+ this.undo = [];
2455
2581
  try {
2456
2582
  let wakes = [];
2457
2583
  const result = this.db.transaction(() => {
@@ -2471,6 +2597,9 @@ export class TaskBoard {
2471
2597
  }
2472
2598
  return r;
2473
2599
  }).immediate();
2600
+ // Committed: the rows are there for good, so what undoes the file moves is forgotten — a failure from here on (a listener's
2601
+ // work, reading the revision) must not move files back from under rows that stay.
2602
+ this.undo = [];
2474
2603
  this.lastNotes = this.notes.map((n) => n.text);
2475
2604
  const touched = this.pending;
2476
2605
  const projects = this.projectsChanged;
@@ -2486,9 +2615,20 @@ export class TaskBoard {
2486
2615
  }
2487
2616
  return result;
2488
2617
  }
2618
+ catch (err) {
2619
+ // The write failed BEFORE it committed, after it moved files under a card: the rows are rolled back, so the files go back to staging.
2620
+ for (const back of this.undo.reverse()) {
2621
+ try {
2622
+ back();
2623
+ }
2624
+ catch { /* the sweep removes it */ }
2625
+ }
2626
+ throw err;
2627
+ }
2489
2628
  finally {
2490
2629
  this.pending = [];
2491
2630
  this.projectsChanged = false;
2631
+ this.undo = [];
2492
2632
  }
2493
2633
  }
2494
2634
  nowIso() {
@@ -2581,6 +2721,83 @@ export class TaskBoard {
2581
2721
  card.seenEntryId = 0;
2582
2722
  this.event(actor, card, "assigned", { from, to: assignee });
2583
2723
  }
2724
+ /**
2725
+ * A comment written, with the files that came with it: its entry, the files linked to it, and the
2726
+ * "commented" event. A write that brings files and no words leaves a line naming them (`📎 name, name`), which an
2727
+ * older release shows as the comment it is. False when there is nothing to write (no words, no files).
2728
+ */
2729
+ writeComment(card, actor, raw, attach, kept = false) {
2730
+ const files = attach?.length ? this.stagedFiles(card, actor, attach) : [];
2731
+ const words = checkText("the comment", raw, CARD_LIMITS.comment);
2732
+ const text = words || (files.length ? checkText("the comment", `📎 ${files.map((f) => f.name).join(", ")}`, CARD_LIMITS.comment) : "");
2733
+ if (!text)
2734
+ return false;
2735
+ const entryId = this.entry(card, "comment", actor, text);
2736
+ this.linkFiles(card, actor, entryId, files);
2737
+ this.commented(actor, card, text, kept, files.length);
2738
+ return true;
2739
+ }
2740
+ /** The files `actor` staged, checked against this card's limits (nothing is moved yet). */
2741
+ stagedFiles(card, actor, ids) {
2742
+ const store = this.fileStore;
2743
+ if (!store)
2744
+ throw new TaskBoardError("invalid", "attachments are not available here (the fleet's scheduler holds the card files)");
2745
+ let files;
2746
+ try {
2747
+ files = store.adopt(actor.name, ids);
2748
+ }
2749
+ catch (err) {
2750
+ if (err instanceof TaskFileError)
2751
+ throw new TaskBoardError("invalid", err.message);
2752
+ throw err;
2753
+ }
2754
+ const held = this.db.prepare("SELECT COUNT(*) AS n, COALESCE(SUM(size), 0) AS bytes FROM task_attachments WHERE task_id = ?").get(card.uuid);
2755
+ const bytes = files.reduce((n, f) => n + f.size, 0);
2756
+ if (held.n + files.length > TASK_FILE_LIMITS.files) {
2757
+ throw new TaskBoardError("too_long", `${card.code} holds ${held.n} files; at most ${TASK_FILE_LIMITS.files} on a card`);
2758
+ }
2759
+ if (held.bytes + bytes > TASK_FILE_LIMITS.cardBytes) {
2760
+ throw new TaskBoardError("too_long", `the files on ${card.code} would be ${Math.ceil((held.bytes + bytes) / (1024 * 1024))} MiB; at most ${Math.floor(TASK_FILE_LIMITS.cardBytes / (1024 * 1024))} MiB on a card`);
2761
+ }
2762
+ return files;
2763
+ }
2764
+ /** The staged files, now the card's: a row each, hung under `entryId`, and the file moved under the card. */
2765
+ linkFiles(card, actor, entryId, files) {
2766
+ if (!files.length)
2767
+ return;
2768
+ const store = this.fileStore;
2769
+ const insert = this.db.prepare("INSERT INTO task_attachments (id, task_id, entry_id, name, mime, kind, size, sha256, author, author_kind, at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
2770
+ for (const f of files) {
2771
+ insert.run(f.id, card.uuid, entryId, f.name, f.mime, f.kind, f.size, f.sha256, actor.name, actor.kind, this.nowIso());
2772
+ try {
2773
+ this.undo.push(store.commit(card.uuid, f));
2774
+ }
2775
+ catch (err) {
2776
+ if (err instanceof TaskFileError)
2777
+ throw new TaskBoardError("invalid", err.message);
2778
+ throw new TaskBoardError("invalid", `the file ${f.name} could not be stored on ${card.code}`);
2779
+ }
2780
+ }
2781
+ }
2782
+ /** The files on a card, oldest first; a scope leaves out the ones its left-out authors wrote. */
2783
+ attachments(uuid, scope = {}) {
2784
+ const by = this.notBy(scope, "author");
2785
+ const rows = this.db.prepare(`SELECT * FROM task_attachments WHERE task_id = ?${by.sql} ORDER BY at, rowid`).all(uuid, ...by.args);
2786
+ return rows.map((r) => this.toAttachment(r));
2787
+ }
2788
+ /** One file by its id, with the card it is on; undefined when there is none. */
2789
+ attachment(id) {
2790
+ const r = this.db.prepare("SELECT * FROM task_attachments WHERE id = ?").get(id);
2791
+ const card = r ? this.byUuid(r.task_id) : undefined;
2792
+ return r && card ? { file: this.toAttachment(r), card } : undefined;
2793
+ }
2794
+ toAttachment(r) {
2795
+ return {
2796
+ id: r.id, cardId: this.codeOf(r.task_id), entryId: r.entry_id === null ? null : Number(r.entry_id), name: r.name,
2797
+ mime: r.mime, kind: r.kind === "photo" ? "photo" : "document", size: Number(r.size), author: r.author,
2798
+ authorKind: r.author_kind, at: r.at,
2799
+ };
2800
+ }
2584
2801
  /**
2585
2802
  * Any write by the assignee counts as having seen the comments so far, so the unseen ones go in its reply first;
2586
2803
  * otherwise a comment posted mid-task would be acknowledged without being read.
@@ -2600,15 +2817,16 @@ export class TaskBoard {
2600
2817
  card.seenEntryId = this.db.prepare("SELECT COALESCE(MAX(id), 0) AS m FROM task_entries WHERE task_id = ?").get(card.uuid).m;
2601
2818
  }
2602
2819
  entry(card, kind, actor, text) {
2603
- this.db.prepare("INSERT INTO task_entries (task_id, kind, author, author_kind, text, at) VALUES (?, ?, ?, ?, ?, ?)")
2820
+ const r = this.db.prepare("INSERT INTO task_entries (task_id, kind, author, author_kind, text, at) VALUES (?, ?, ?, ?, ?, ?)")
2604
2821
  .run(card.uuid, kind, actor.name, actor.kind, text, this.nowIso());
2822
+ return Number(r.lastInsertRowid);
2605
2823
  }
2606
2824
  /**
2607
2825
  * A comment written (its entry is already on the card): the "commented" event, and whom the comment concerns, which
2608
2826
  * settleWakes reads when the write ends. `kept` is a dispatcher's answer a busy assignee finds on the card (#2303).
2609
2827
  */
2610
- commented(actor, card, text, kept = false) {
2611
- this.event(actor, card, "commented", kept ? { text, kept: true } : { text });
2828
+ commented(actor, card, text, kept = false, files = 0) {
2829
+ this.event(actor, card, "commented", { text, ...(kept ? { kept: true } : {}), ...(files ? { files } : {}) });
2612
2830
  this.pending[this.pending.length - 1].audience = this.routeComment(actor, card, text, kept);
2613
2831
  }
2614
2832
  /**