Files
stack/packages/tasks/src/digest.mjs
T
jason.woltjeandClaude Opus 5.5 7e73c2cd13 feat(tasks): the Vikunja v2 adapter, broker task verbs and sync (row 38, S3, darkwing)
packages/tasks adds the Vikunja v2 client, the eight task verbs, the
board-plus-cursor poll with its 60 s window and the digest. The broker
gains the task verbs and boots trackers from the boot config (lead
decisions 66 to 68). Due dates are truncated to the second and recorded
as truncated (B1). A write that lands but whose final read fails counts
as landed, in update and in create (B2).

Candidate agents/darkwing/work/slice1-s3, build-r2.patch 71ce87e6,
manifest e10e30e3 (28 files). Filbert approved round 2 on #1520
(comment 26853). Darkwing's post-reset rerun: test-release 14/14,
test-task 98/98 (comment 26857).

Integration gate in a worktree on c4baf779 with the patch applied:
bus 67, business 60, control-board 124, discord 173, ledger 78,
mosaic 69, queue 148, seat 19, tasks 51 and webui 14, all with no
failures. Conversation is 149/3. The three cohort kill cases (K1, K3,
K10) fail the same on the unpatched base, and the patch doesn't touch
the package. Every scripts/test-*.sh is green. test-release 14/14 and
test-task 98/98 ran on the existing gate2 compose network, because the
host's Docker address pools are exhausted. No network was created or
pruned.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-09 07:40:48 -05:00

60 lines
2.5 KiB
JavaScript

import { canonicalJson, sha256 } from '../../business/src/util.mjs';
import { BusError } from '../../bus/src/broker.mjs';
// Vikunja writes this for an unset date.
export const NULL_DATE = '0001-01-01T00:00:00Z';
const positive = (x) => Number.isSafeInteger(x) && x > 0;
const ids = (list, where) => {
if (list !== null && list !== undefined && !Array.isArray(list)) throw new BusError('tracker-shape');
const out = (list ?? []).map((x) => x?.id);
if (out.some((x) => !positive(x))) throw new BusError('tracker-shape');
return out.sort((a, b) => a - b);
};
export const ref = (project, task) => `vikunja:${project}/${task}`;
export function parseRef(taskRef) {
const m = /^vikunja:([1-9][0-9]*)\/([1-9][0-9]*)$/.exec(taskRef ?? '');
if (!m) throw new BusError('invalid-request');
return { project: Number(m[1]), task: Number(m[2]) };
}
// Checks a task object from any v2 read and returns its updated time. Throws tracker-shape.
export function checkTask(task) {
if (
!task ||
typeof task !== 'object' ||
!positive(task.id) ||
!positive(task.project_id) ||
typeof task.title !== 'string' ||
typeof (task.description ?? '') !== 'string' ||
typeof task.done !== 'boolean' ||
!Number.isSafeInteger(task.priority) ||
typeof task.percent_done !== 'number' ||
typeof task.updated !== 'string' ||
!Number.isFinite(Date.parse(task.updated))
)
throw new BusError('tracker-shape');
return task.updated;
}
// The digest set from addendum B section 5. `bucket` comes from the board or a move, never the task.
export function taskFields(task, bucket) {
checkTask(task);
if (!positive(bucket)) throw new BusError('tracker-shape');
const due = task.due_date;
if (due !== undefined && due !== null && (typeof due !== 'string' || !Number.isFinite(Date.parse(due))))
throw new BusError('tracker-shape');
return {
project_id: task.project_id,
title: task.title,
description: task.description ?? '',
done: task.done,
// One text form, so an expected value written by S3 digests the same as the value read back.
due_date: !due || due === NULL_DATE ? null : new Date(due).toISOString(),
priority: task.priority,
percent_done: task.percent_done,
bucket,
labels: ids(task.labels),
assignees: ids(task.assignees),
};
}
export const digest = (fields) => sha256(canonicalJson(fields));
// A tombstone keeps only the reason, and the new project for a move.
export const tombstone = (gone, project = null) => (project === null ? { gone } : { gone, project });