Files
jason.woltje 8545057275 lead: commit sage's untracked evidence (100 files: prd-1-17 queue-135 queue-176 queue-199 queue-66 vikunja-setup window-repin-4429a104f)
Unclaimed files left in the canonical checkout. Inventory: canonical-cleanup-inventory.md (commit-as-evidence groups). detect-secrets scan clean on 2026-11-02: hits are sha256 pins, git object ids, test sentinels already in tracked tests and unit-file lines.
2026-11-02 15:05:15 -06:00

72 lines
5.6 KiB
JavaScript

// Sage, 2026-10-21: the T1 item 7 sessions row is numbered (row 264, #1769), so 463 closes (mos-1237).
// Comments on 466 (the row T3 depends on it) and 464 (rows 265-267 filed), then comments on 463 and marks it done.
// Sage's own key (bot user 13); the sync key reads back. A close sends the task as the v1 GET returned it with only
// done changed, and the read-back checks that title and description are the same. Rollback is marking it undone.
// Checks each task's title before anything is posted. Prints no secret.
// Usage: node post-w12-prd.mjs https://tasks.woltje.com SAGE_TOKEN_FILE SYNC_TOKEN_FILE OUT_JSON
import { readFileSync, writeFileSync, existsSync } from "node:fs";
const [ORIGIN, KEY, SYNC, OUT] = process.argv.slice(2);
if (!/^https:\/\/tasks\.woltje\.com$/.test(ORIGIN)) throw new Error("tasks.woltje.com only");
if (!OUT || existsSync(OUT)) throw new Error("OUT_JSON missing or exists; refusing");
const PROJECT = 19;
const PSIG = "Posted by Sage (T3 1ef1e4f8) with Sage's own key (bot user 13).";
const esc = (s) => s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
const ps = (xs) => xs.map((x) => `<p>${esc(x)}</p>`).join("") + `<p>${esc(PSIG)}</p>`;
const WIN = "agents/sage/work/window-repin-7247d80c7/";
const POSTS = [
{ id: 466, title: /^T1 item 7 N2: pin the Claude compaction count format/, close: false, body: [
"The sessions build row is queue row 264 (Gitea #1769). Its gate names this task as the dependency of acceptance test T3 (mos-1237). Sage is staffing owner; the seat is not named yet.",
] },
{ id: 464, title: /^Case 2: playground note for new universes/, close: false, body: [
"Build rows filed from the briefs that landed in aa772d731: row 265 C2-09b (#1770, Rocko, reviewer Dewey, after 219), row 266 C2-10c (#1771, Haiku high subagent under decision 129, reviewer Dewey, after 265 and 225), row 267 C2-15 (#1772, Morgana, reviewer Filbert, after 216, 224 and 217).",
"The C2-01c brief (dde2b44cf, Webby approved d2 in webby-0091) and PRD 1.14 (9bd665976, Della approved in della-0013) land next with Gosalyn's ruling 51fdfb7e2; the C2-01c row is filed after the brief is on refactor.",
] },
{ id: 463, title: /^MVP T1 item 7 design: several sessions per thread/, close: true, body: [
"Closing per mos-1237: the design landed on refactor as 3dcd3651e (docs/plans/2026-10-21_t1-sessions.md; Huey, Scrooge approved r3 in scrooge-0008), and its build row is queue row 264 (Gitea #1769). The row's gate names Vikunja 466 (N2) as the dependency of acceptance test T3. PRD 1.13 (REQ-SESS-1 to 3, Della della-0012) lands next; both requirements test files passed 3/3 run whole on the candidate 5f73b388c and verbs.test.mjs 31/31.",
] },
];
const key = readFileSync(KEY, "utf8").trim(), sync = readFileSync(SYNC, "utf8").trim();
async function api(method, path, body, auth) {
const r = await fetch(ORIGIN + path, { method, headers: { Authorization: `Bearer ${auth}`, "Content-Type": "application/json" }, body: body === undefined ? undefined : JSON.stringify(body), redirect: "error" });
const t = await r.text(); let json = null; try { json = JSON.parse(t); } catch {}
return { status: r.status, json };
}
const list = (j) => j?.items ?? (Array.isArray(j) ? j : []);
const rec = { at: new Date().toISOString(), comments: [], closes: [], problems: [] };
const save = () => {
const out = JSON.stringify(rec, null, 1) + "\n";
if (out.includes(key) || out.includes(sync)) throw new Error("secret in the record; not written");
writeFileSync(OUT, out);
};
const before = {};
for (const P of POSTS) {
const t = await api("GET", `/api/v2/tasks/${P.id}`, undefined, sync);
if (t.status !== 200 || t.json?.project_id !== PROJECT || !P.title.test(t.json?.title ?? "")) throw new Error(`task ${P.id}: ${t.status}, title check failed; nothing posted`);
if (P.close && t.json.done) throw new Error(`task ${P.id} is already done; nothing posted`);
before[P.id] = { title: t.json.title, description: t.json.description };
}
writeFileSync(OUT, "", { flag: "wx" });
for (const P of POSTS) {
const c = await api("PUT", `/api/v1/tasks/${P.id}/comments`, { comment: ps(P.body) }, key);
const e = { task: P.id, status: c.status, id: c.json?.id ?? null };
rec.comments.push(e);
if (c.status >= 300 || !Number.isSafeInteger(c.json?.id)) { rec.problems.push(`comment ${P.id}: ${c.status} ${c.json?.message ?? ""}`); save(); continue; }
const back = await api("GET", `/api/v2/tasks/${P.id}/comments?per_page=50`, undefined, sync);
const found = list(back.json).find((x) => x.id === c.json.id);
Object.assign(e, { readBack: back.status, found: Boolean(found) });
if (back.status !== 200 || !found) { rec.problems.push(`comment ${P.id} read-back: ${back.status}`); save(); continue; }
if (P.close) {
const full = await api("GET", `/api/v1/tasks/${P.id}`, undefined, key);
if (full.status !== 200 || full.json?.id !== P.id) { rec.problems.push(`v1 get ${P.id}: ${full.status}`); save(); continue; }
const u = await api("POST", `/api/v1/tasks/${P.id}`, { ...full.json, done: true }, key);
const b2 = await api("GET", `/api/v2/tasks/${P.id}`, undefined, sync);
const x = { task: P.id, status: u.status, readBack: b2.status, done: b2.json?.done, titleSame: b2.json?.title === before[P.id].title, descriptionSame: b2.json?.description === before[P.id].description, inverse: `mark undone: POST /api/v1/tasks/${P.id} done false (sage key)` };
rec.closes.push(x);
if (u.status >= 300 || b2.status !== 200 || b2.json?.done !== true || !x.titleSame || !x.descriptionSame) rec.problems.push(`close ${P.id}: update or read-back differs`);
}
save();
}
save();
process.stdout.write(JSON.stringify(rec, null, 1) + "\n");
if (rec.problems.length) process.exit(2);