@songsid/agend 2.4.0-beta.23 → 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.
- package/dist/agent-cli-instructions.md +4 -3
- package/dist/agent-cli.js +32 -2
- package/dist/agent-cli.js.map +1 -1
- package/dist/agent-file-read.js +2 -2
- package/dist/agent-file-read.js.map +1 -1
- package/dist/agent-whats-new.js +11 -1
- package/dist/agent-whats-new.js.map +1 -1
- package/dist/backend/claude-code.d.ts +15 -0
- package/dist/backend/claude-code.js +8 -3
- package/dist/backend/claude-code.js.map +1 -1
- package/dist/backend/claude-mcp-carry.d.ts +63 -0
- package/dist/backend/claude-mcp-carry.js +242 -0
- package/dist/backend/claude-mcp-carry.js.map +1 -0
- package/dist/build-provenance.json +1 -1
- package/dist/channel/mcp-tools.js +7 -6
- package/dist/channel/mcp-tools.js.map +1 -1
- package/dist/config-validator.js +6 -0
- package/dist/config-validator.js.map +1 -1
- package/dist/daemon.d.ts +11 -0
- package/dist/daemon.js +66 -15
- package/dist/daemon.js.map +1 -1
- package/dist/dashboard-permissions.d.ts +8 -0
- package/dist/dashboard-permissions.js +8 -0
- package/dist/dashboard-permissions.js.map +1 -1
- package/dist/delivery-outbox.d.ts +15 -1
- package/dist/delivery-outbox.js +60 -2
- package/dist/delivery-outbox.js.map +1 -1
- package/dist/fleet-manager.d.ts +14 -0
- package/dist/fleet-manager.js +67 -0
- package/dist/fleet-manager.js.map +1 -1
- package/dist/general-knowledge/skills/concepts/SKILL.md +22 -9
- package/dist/general-knowledge/skills/credential-profiles/SKILL.md +6 -0
- package/dist/general-knowledge/skills/fleet-config/SKILL.md +3 -3
- package/dist/general-knowledge/skills/instance-lifecycle/SKILL.md +1 -1
- package/dist/general-knowledge/skills/task-board/SKILL.md +17 -0
- package/dist/general-knowledge/skills/web-appearance/SKILL.md +4 -0
- package/dist/general-knowledge/skills/web-dashboard/SKILL.md +21 -3
- package/dist/hub/group-policy/resources.d.ts +1 -1
- package/dist/instance-lifecycle.d.ts +2 -0
- package/dist/instance-lifecycle.js +29 -1
- package/dist/instance-lifecycle.js.map +1 -1
- package/dist/locale.js +10 -0
- package/dist/locale.js.map +1 -1
- package/dist/needs-you-hub.d.ts +3 -0
- package/dist/needs-you-hub.js +31 -5
- package/dist/needs-you-hub.js.map +1 -1
- package/dist/needs-you.d.ts +14 -1
- package/dist/needs-you.js +5 -0
- package/dist/needs-you.js.map +1 -1
- package/dist/office-share-page.js +1 -1
- package/dist/office-share-page.js.map +1 -1
- package/dist/office-share.js +2 -1
- package/dist/office-share.js.map +1 -1
- package/dist/outbound-handlers.js +29 -6
- package/dist/outbound-handlers.js.map +1 -1
- package/dist/outbound-schemas.d.ts +3 -0
- package/dist/outbound-schemas.js +7 -5
- package/dist/outbound-schemas.js.map +1 -1
- package/dist/public-web-gateway.js +3 -0
- package/dist/public-web-gateway.js.map +1 -1
- package/dist/request-context-compatibility.d.ts +20 -0
- package/dist/request-context-compatibility.js +74 -0
- package/dist/request-context-compatibility.js.map +1 -0
- package/dist/request-context-protocol.d.ts +137 -0
- package/dist/request-context-protocol.js +38 -0
- package/dist/request-context-protocol.js.map +1 -0
- package/dist/request-context-store.d.ts +25 -0
- package/dist/request-context-store.js +137 -0
- package/dist/request-context-store.js.map +1 -0
- package/dist/scheduler/db.js +26 -0
- package/dist/scheduler/db.js.map +1 -1
- package/dist/scheduler/task-board-text.d.ts +2 -0
- package/dist/scheduler/task-board-text.js +12 -0
- package/dist/scheduler/task-board-text.js.map +1 -1
- package/dist/scheduler/task-board.d.ts +102 -2
- package/dist/scheduler/task-board.js +242 -24
- package/dist/scheduler/task-board.js.map +1 -1
- package/dist/scheduler/task-files.d.ts +80 -0
- package/dist/scheduler/task-files.js +357 -0
- package/dist/scheduler/task-files.js.map +1 -0
- package/dist/settings-api.d.ts +2 -0
- package/dist/settings-api.js +6 -1
- package/dist/settings-api.js.map +1 -1
- package/dist/settings-baseline.d.ts +1 -0
- package/dist/settings-baseline.js +1 -1
- package/dist/settings-baseline.js.map +1 -1
- package/dist/settings-effect.d.ts +2 -0
- package/dist/settings-effect.js +5 -1
- package/dist/settings-effect.js.map +1 -1
- package/dist/task-attach-client.d.ts +43 -0
- package/dist/task-attach-client.js +125 -0
- package/dist/task-attach-client.js.map +1 -0
- package/dist/task-board-tool.d.ts +12 -0
- package/dist/task-board-tool.js +107 -6
- package/dist/task-board-tool.js.map +1 -1
- package/dist/task-file-limits.d.ts +15 -0
- package/dist/task-file-limits.js +21 -0
- package/dist/task-file-limits.js.map +1 -0
- package/dist/tool-permissions.d.ts +32 -0
- package/dist/tool-permissions.js +63 -0
- package/dist/tool-permissions.js.map +1 -1
- package/dist/types.d.ts +6 -0
- package/dist/ui/agent-details-settings.js +7 -5
- package/dist/ui/agent-who-can-use-strings.js +125 -0
- package/dist/ui/agent-who-can-use.js +238 -0
- package/dist/ui/fleet-office-card.js +23 -5
- package/dist/ui/fleet-office-editor.js +5 -5
- package/dist/ui/fleet-office-pack.d.ts +10 -0
- package/dist/ui/fleet-office-pack.js +65 -2
- package/dist/ui/fleet-office-skin.js +42 -8
- package/dist/ui/fleet-office-store.js +33 -2
- package/dist/ui/fleet-office-vehicles.js +130 -0
- package/dist/ui/fleet-office-zones.js +5 -1
- package/dist/ui/fleet-office.js +112 -31
- package/dist/ui/fleet-task-activity.js +9 -82
- package/dist/ui/fleet-task-archive.js +111 -0
- package/dist/ui/fleet-task-card.js +6 -4
- package/dist/ui/fleet-task-common.js +2 -2
- package/dist/ui/fleet-task-edit.js +8 -1
- package/dist/ui/fleet-task-files.js +196 -0
- package/dist/ui/fleet-task-md.js +98 -0
- package/dist/ui/fleet-task-menu.js +1 -1
- package/dist/ui/fleet-task-stats.js +2 -2
- package/dist/ui/fleet-task-view.js +12 -8
- package/dist/ui/fleet-tasks.js +42 -18
- package/dist/ui/panel-details.js +3 -1
- package/dist/ui/panel-needs.js +3 -3
- package/dist/ui/panel-settings.js +15 -1
- package/dist/ui/settings-registry.js +1 -0
- package/dist/ui/settings-shared-strings.js +9 -0
- package/dist/ui/settings-shared.js +6 -1
- package/dist/ui/shared/app-i18n.js +2 -2
- package/dist/ui/shared/app-needs.js +8 -1
- package/dist/ui/shared/app.css +55 -3
- package/dist/ui/shared/chat-strings.js +4 -4
- package/dist/ui/shared/task-board.css +64 -0
- package/dist/web-api.d.ts +3 -0
- package/dist/web-api.js +97 -14
- package/dist/web-api.js.map +1 -1
- package/dist/web-office-acts.d.ts +16 -0
- package/dist/web-office-acts.js +27 -9
- package/dist/web-office-acts.js.map +1 -1
- package/dist/web-office-pack-read.js +1 -1
- package/dist/web-office-pack-read.js.map +1 -1
- package/dist/web-office-skins.d.ts +5 -3
- package/dist/web-office-skins.js +20 -16
- package/dist/web-office-skins.js.map +1 -1
- package/dist/web-settings-patch.d.ts +27 -0
- package/dist/web-settings-patch.js +67 -0
- package/dist/web-settings-patch.js.map +1 -1
- package/dist/workflow-templates/default.md +1 -0
- package/package.json +1 -1
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
* card to another project, or reopens a finished card; an instance moves its own cards along.
|
|
14
14
|
*/
|
|
15
15
|
import type Database from "better-sqlite3";
|
|
16
|
+
import { type TaskFileStore } from "./task-files.js";
|
|
16
17
|
export declare const CARD_STATUSES: readonly ["open", "claimed", "blocked", "review", "done", "cancelled"];
|
|
17
18
|
export type CardStatus = (typeof CARD_STATUSES)[number];
|
|
18
19
|
/** Statuses still on the board (not finished). */
|
|
@@ -47,6 +48,14 @@ export declare const CARD_LIMITS: {
|
|
|
47
48
|
readonly projectDescription: 300;
|
|
48
49
|
readonly assignee: 128;
|
|
49
50
|
};
|
|
51
|
+
/**
|
|
52
|
+
* M-3668 (the user, 11-24): a finished main task — done or cancelled — leaves the dashboard's board this many days after it
|
|
53
|
+
* finished (defaults.task_board.archive_after_days; 0 = never). A view rule only: nothing in the database changes, search
|
|
54
|
+
* and its number still find it, and moving it to To do reopens it (its status, not its age, makes it archived).
|
|
55
|
+
*/
|
|
56
|
+
export declare const ARCHIVE_AFTER_DAYS = 3;
|
|
57
|
+
/** The archive age as fleet.yaml gives it: a whole number of days, 0–3650; anything else is the default. */
|
|
58
|
+
export declare function archiveAfterDays(v: unknown): number;
|
|
50
59
|
/**
|
|
51
60
|
* The loop guard for comments that wake (docs/design/task-board.md, "Comments and mentions"): instances (and scripts,
|
|
52
61
|
* held to the same rules) can wake each other with a comment or an `@` mention, and a reply wakes its writer again.
|
|
@@ -196,6 +205,13 @@ export interface ProjectStats {
|
|
|
196
205
|
waiting: number;
|
|
197
206
|
blocked: number;
|
|
198
207
|
lastActivity: string | null;
|
|
208
|
+
/**
|
|
209
|
+
* M-3668: finished main tasks archived (left out of the numbers above), main tasks done in the last 7 days, and how many
|
|
210
|
+
* of those are archived already (the Done column shows the rest: "45 done this week · 8 archived").
|
|
211
|
+
*/
|
|
212
|
+
archived: number;
|
|
213
|
+
doneWeek: number;
|
|
214
|
+
archivedWeek: number;
|
|
199
215
|
}
|
|
200
216
|
/** A card as the dashboard draws it: references by card number. */
|
|
201
217
|
export interface CardView {
|
|
@@ -235,6 +251,8 @@ export interface CardView {
|
|
|
235
251
|
progress: Progress | null;
|
|
236
252
|
unmetDeps: string[];
|
|
237
253
|
commentCount: number;
|
|
254
|
+
/** Files on the card (its attachments). */
|
|
255
|
+
attachmentCount: number;
|
|
238
256
|
/** Comments by others its assignee has not acted on yet. */
|
|
239
257
|
newCommentCount: number;
|
|
240
258
|
lastComment: {
|
|
@@ -253,6 +271,23 @@ export interface Entry {
|
|
|
253
271
|
text: string;
|
|
254
272
|
at: string;
|
|
255
273
|
}
|
|
274
|
+
/**
|
|
275
|
+
* A file on a card: linked to the comment its writer left with it (`entryId`), kept under the card in
|
|
276
|
+
* `task-files/` (task-files.ts) and served only as a download (GET /ui/tasks/files/<id>). `kind` is what the bytes are
|
|
277
|
+
* (a picture, or anything else); `name` is a label — never a path.
|
|
278
|
+
*/
|
|
279
|
+
export interface Attachment {
|
|
280
|
+
id: string;
|
|
281
|
+
cardId: string;
|
|
282
|
+
entryId: number | null;
|
|
283
|
+
name: string;
|
|
284
|
+
mime: string;
|
|
285
|
+
kind: "photo" | "document";
|
|
286
|
+
size: number;
|
|
287
|
+
author: string;
|
|
288
|
+
authorKind: Actor["kind"];
|
|
289
|
+
at: string;
|
|
290
|
+
}
|
|
256
291
|
export type CardEventType = "created" | "updated" | "moved" | "assigned" | "commented" | "logged" | "reordered";
|
|
257
292
|
export interface CardEvent {
|
|
258
293
|
id: number;
|
|
@@ -352,6 +387,8 @@ export interface CardDetail {
|
|
|
352
387
|
comments: Entry[];
|
|
353
388
|
logs: Entry[];
|
|
354
389
|
history: CardEvent[];
|
|
390
|
+
/** The files on this card, oldest first; each hangs under the comment `entryId` names. */
|
|
391
|
+
attachments: Attachment[];
|
|
355
392
|
/** The instances that watch this card (its own list: a sub task's main task's watchers follow it too). */
|
|
356
393
|
watchers: string[];
|
|
357
394
|
/** A sub task's: the watchers of its main task, which follow it too (read-only here; empty for any other card). */
|
|
@@ -412,12 +449,16 @@ export interface CardPatch {
|
|
|
412
449
|
projectId?: number | null;
|
|
413
450
|
log?: string;
|
|
414
451
|
comment?: string;
|
|
452
|
+
/** Files the writer staged (TaskFileStore): linked to the comment this write leaves — a line naming them when it has no words. */
|
|
453
|
+
attach?: string[];
|
|
415
454
|
}
|
|
416
455
|
export interface MoveOptions {
|
|
417
456
|
reason?: string;
|
|
418
457
|
result?: string;
|
|
419
458
|
comment?: string;
|
|
420
459
|
version?: number;
|
|
460
|
+
/** As CardPatch.attach: the files that go with the move's comment. */
|
|
461
|
+
attach?: string[];
|
|
421
462
|
}
|
|
422
463
|
export interface MutationResult {
|
|
423
464
|
card: Card;
|
|
@@ -517,7 +558,14 @@ export declare class TaskBoard {
|
|
|
517
558
|
/** The notes of the last write, until a caller of the `task` tool's old actions takes them (takeNotes). */
|
|
518
559
|
private lastNotes;
|
|
519
560
|
private codes;
|
|
561
|
+
/** Where files on cards live (task-files.ts); none: this process cannot take attachments (a bare board in a test, the CLI). */
|
|
562
|
+
private fileStore;
|
|
563
|
+
/** What undoes this write's file moves, when the write fails after them. */
|
|
564
|
+
private undo;
|
|
520
565
|
constructor(db: Database.Database, now?: () => Date);
|
|
566
|
+
/** The store for files on cards (the fleet's scheduler sets it); null takes attachments away. */
|
|
567
|
+
setFiles(store: TaskFileStore | null): void;
|
|
568
|
+
files(): TaskFileStore | null;
|
|
521
569
|
/** Called with what each committed write changed. Returns an unsubscribe function. */
|
|
522
570
|
onChange(listener: (change: BoardChange) => void): () => void;
|
|
523
571
|
/**
|
|
@@ -576,14 +624,48 @@ export declare class TaskBoard {
|
|
|
576
624
|
* tasks — or every done main task with `allDone` (the Done column's "All"). Older finished work stays in the
|
|
577
625
|
* database and in the projects' numbers (projectStats), not in every board read.
|
|
578
626
|
*/
|
|
579
|
-
boardCards(days?: number, allDone?: boolean): Card[];
|
|
627
|
+
boardCards(days?: number, allDone?: boolean, archiveDays?: number): Card[];
|
|
628
|
+
/**
|
|
629
|
+
* #4428 review: ` AND …` leaving out the cards that name one of `names` (assigned to, created by or handed out by one:
|
|
630
|
+
* the public link's hiding, web-api boardHiding), with its values; empty when none.
|
|
631
|
+
*/
|
|
632
|
+
private unseen;
|
|
633
|
+
/**
|
|
634
|
+
* #4428 review: what time alone changes in a board read and its numbers — how many finished cards have passed each
|
|
635
|
+
* of its lines (archived, out of this week's count, out of the recent window) — with the archive age. A card passes a
|
|
636
|
+
* line without a write (the revision stays), so a page's "same revision" read is answered `unchanged` only when this
|
|
637
|
+
* matches too. One counting pass, no rows. `leaveOut`: as projectStats (the public link's hidden instances' cards never
|
|
638
|
+
* move it).
|
|
639
|
+
*/
|
|
640
|
+
boardEpoch(archiveDays?: number, days?: number, leaveOut?: readonly string[]): string;
|
|
580
641
|
/**
|
|
581
642
|
* Each project's numbers (by id; "none" for No project) over all its cards, finished ones included: main tasks,
|
|
582
643
|
* work units (a main task's sub tasks, or one unit for a main task without them; a done main task counts all its
|
|
583
644
|
* units done), cards waiting for the person and blocked, and the last change. One pass over the table. #2080: waiting
|
|
584
645
|
* counts only the cards in review the person confirms (waitsForPerson, `gone` as for Needs you), never an agent's.
|
|
646
|
+
* #4428 review: `leaveOut` names (the public link's hidden instances) — their cards, and a hidden main task's sub tasks,
|
|
647
|
+
* count nowhere, as the board read leaves them out.
|
|
585
648
|
*/
|
|
586
|
-
projectStats(gone?: GoneDispatcher): Record<string, ProjectStats>;
|
|
649
|
+
projectStats(gone?: GoneDispatcher, archiveDays?: number, leaveOut?: readonly string[]): Record<string, ProjectStats>;
|
|
650
|
+
/** M-3668: whether the dashboard has archived this card (a sub task goes with its main task). */
|
|
651
|
+
isArchived(card: Card, archiveDays: number): boolean;
|
|
652
|
+
/**
|
|
653
|
+
* M-3668: a project's archived main tasks (`project` null: No project), the most recently finished first, a page at a
|
|
654
|
+
* time (`before`: the last one's cursor), and who they were assigned to (the list's filter, `assignee`).
|
|
655
|
+
* `leaveOut`: names whose cards the reader may not see (assigned to, created by or handed out by one) — left out
|
|
656
|
+
* before the page, its cursor, the total and the assignees are worked out, so none of them tells of such a card.
|
|
657
|
+
*/
|
|
658
|
+
archiveList(project: number | null, archiveDays: number, opts?: {
|
|
659
|
+
before?: string | null;
|
|
660
|
+
limit?: number;
|
|
661
|
+
assignee?: string | null;
|
|
662
|
+
leaveOut?: readonly string[];
|
|
663
|
+
}): {
|
|
664
|
+
cards: Card[];
|
|
665
|
+
next: string | null;
|
|
666
|
+
total: number;
|
|
667
|
+
assignees: string[];
|
|
668
|
+
};
|
|
587
669
|
view(card: Card, scope?: ReadScope, gone?: GoneDispatcher): CardView;
|
|
588
670
|
/** ` AND <column> NOT IN (…)` for a scope's left-out authors, with its values (empty when none). */
|
|
589
671
|
private notBy;
|
|
@@ -915,6 +997,24 @@ export declare class TaskBoard {
|
|
|
915
997
|
private assertNoCycle;
|
|
916
998
|
private checkVersion;
|
|
917
999
|
private assign;
|
|
1000
|
+
/**
|
|
1001
|
+
* A comment written, with the files that came with it: its entry, the files linked to it, and the
|
|
1002
|
+
* "commented" event. A write that brings files and no words leaves a line naming them (`📎 name, name`), which an
|
|
1003
|
+
* older release shows as the comment it is. False when there is nothing to write (no words, no files).
|
|
1004
|
+
*/
|
|
1005
|
+
private writeComment;
|
|
1006
|
+
/** The files `actor` staged, checked against this card's limits (nothing is moved yet). */
|
|
1007
|
+
private stagedFiles;
|
|
1008
|
+
/** The staged files, now the card's: a row each, hung under `entryId`, and the file moved under the card. */
|
|
1009
|
+
private linkFiles;
|
|
1010
|
+
/** The files on a card, oldest first; a scope leaves out the ones its left-out authors wrote. */
|
|
1011
|
+
attachments(uuid: string, scope?: ReadScope): Attachment[];
|
|
1012
|
+
/** One file by its id, with the card it is on; undefined when there is none. */
|
|
1013
|
+
attachment(id: string): {
|
|
1014
|
+
file: Attachment;
|
|
1015
|
+
card: Card;
|
|
1016
|
+
} | undefined;
|
|
1017
|
+
private toAttachment;
|
|
918
1018
|
/**
|
|
919
1019
|
* Any write by the assignee counts as having seen the comments so far, so the unseen ones go in its reply first;
|
|
920
1020
|
* otherwise a comment posted mid-task would be acknowledged without being read.
|
|
@@ -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
|
|
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
|
-
|
|
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.
|
|
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
|
-
|
|
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 ? {
|
|
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
|
/**
|