@marver-design/marver 0.30.1 → 0.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +58 -0
- package/README.md +11 -7
- package/dist/{anchor-check-Bv4o-R2T.mjs → anchor-check-B92s9tVv.mjs} +1 -1
- package/dist/{board-tree-BXR8dw4b.mjs → board-tree-DGj0HhEE.mjs} +6 -2
- package/dist/{boards-EH2onUXM.mjs → boards-Cim1GTKc.mjs} +32 -2
- package/dist/{boards-BeWtjGUM.mjs → boards-OlAhZ87x.mjs} +7 -7
- package/dist/{build-zWGXSzly.mjs → build-BNssmbqd.mjs} +14 -17
- package/dist/{capture-DEtM4qm5.mjs → capture-HaS-1or8.mjs} +1 -1
- package/dist/cli.mjs +38 -20
- package/dist/{collab-BEAcXrBb.mjs → collab-D2NcrOB8.mjs} +53 -14
- package/dist/comment-actions-Bxf9Ld4g.mjs +351 -0
- package/dist/{comments-XNhMmSSu.mjs → comments-BakJQwaf.mjs} +85 -10
- package/dist/config-B0YcFtqS.mjs +510 -0
- package/dist/{context-BUnFiyA3.mjs → context-Cj2TcC0H.mjs} +3 -3
- package/dist/{daemon-CChgWJNq.mjs → daemon-MxoEQajX.mjs} +222 -23
- package/dist/deep-link-DYtuT740.mjs +163 -0
- package/dist/{dev-DOgIITpT.mjs → dev-BBZe_brH.mjs} +23 -16
- package/dist/devices-uJZ2inMq.mjs +155 -0
- package/dist/{events-CLH4ijKP.mjs → events-Dieo1482.mjs} +49 -4
- package/dist/{init-CYlFaRzG.mjs → init-BgusplYn.mjs} +40 -10
- package/dist/{jam-Cj5gBvwD.mjs → jam-CkuLL8A8.mjs} +1 -1
- package/dist/{link-BFFRgrMt.mjs → link-Cmt9Xy4X.mjs} +54 -7
- package/dist/{logo-CXY-1yrn.mjs → logo-C9s7-Cy9.mjs} +89 -66
- package/dist/{ls-NqmePKOf.mjs → ls-DGVIW-Io.mjs} +1 -1
- package/dist/{manifest-DPZ3WNg_.mjs → manifest-CK8Qh4Nq.mjs} +255 -13
- package/dist/{marks-BnNANic9.mjs → marks-C8oX8kbE.mjs} +3 -3
- package/dist/{marks-DBp3h1Mc.mjs → marks-Dt-5JXCp.mjs} +18 -5
- package/dist/{marver-id-gate-vBLb_Icb.mjs → marver-id-gate-BAeuMeaU.mjs} +11 -7
- package/dist/md-B9_13Q0R.mjs +105 -0
- package/dist/notes-CRAX4wgk.mjs +148 -0
- package/dist/own-C8Mq0Hnf.mjs +128 -0
- package/dist/pdf-0m721FFn.mjs +117 -0
- package/dist/pdf-CZENT6t3.mjs +2299 -0
- package/dist/{perf-BCxAo0IS.mjs → perf-BB0XNt1M.mjs} +1 -1
- package/dist/{perf-6MOTHxay.mjs → perf-CIMijND6.mjs} +5 -5
- package/dist/{plugin-CFWBcAba.mjs → plugin-CL8_wL7a.mjs} +460 -83
- package/dist/{poster-DPPpQiva.mjs → poster-B7uSjlEP.mjs} +1 -1
- package/dist/{profile-B1FKOM1e.mjs → profile-cdmSer1k.mjs} +1 -1
- package/dist/{publish-bakes-_Zx8crP3.mjs → publish-bakes-BjgDNeyS.mjs} +3 -3
- package/dist/{queue-DeSQm24g.mjs → queue-BLLfdlDw.mjs} +156 -11
- package/dist/{recover-mDUVsnPd.mjs → recover-ByuFQOF9.mjs} +2 -2
- package/dist/{serve-DQv3Ti6X.mjs → serve-kcF6-H8V.mjs} +4 -4
- package/dist/{session-VDJfXEEm.mjs → session-DBF-nQvq.mjs} +29 -3
- package/dist/{share-Bu_kuOKL.mjs → share-CS2mg27O.mjs} +1 -1
- package/dist/{shot-d4h_hJi9.mjs → shot-BqwkdtKn.mjs} +4 -4
- package/dist/{shot-DBWN8hPP.mjs → shot-D2TQGo2V.mjs} +1 -1
- package/dist/show-B1u3DiJw.mjs +101 -0
- package/dist/{sizes-wjXDev3b.mjs → sizes-BckcL4Zz.mjs} +1 -1
- package/dist/{slots-Dn4Onb0V.mjs → slots-BOcfIqxy.mjs} +15 -3
- package/dist/{summary-Y8MY1Wuc.mjs → summary-cPmRDGpX.mjs} +1 -1
- package/dist/{sync-CMozOwZ0.mjs → sync-BNWwh8OF.mjs} +205 -7
- package/dist/{work-BYWD_1Zf.mjs → work-DRdzXPvg.mjs} +3 -3
- package/dist/{work-DJxH7cCX.mjs → work-Nv-n2_Un.mjs} +1 -1
- package/docs/app.md +49 -0
- package/docs/boards-and-folders.md +37 -6
- package/docs/jam-session.md +5 -0
- package/docs/live-jam.md +9 -0
- package/docs/pdf.md +108 -0
- package/docs/publish.md +9 -9
- package/docs/sharing.md +11 -0
- package/docs/slides.md +9 -0
- package/package.json +3 -1
- package/src/client/content/index.tsx +4 -2
- package/src/client/frame-host/main.tsx +3 -0
- package/src/client/shell/App.tsx +71 -24
- package/src/client/shell/BoardList.tsx +16 -7
- package/src/client/shell/Comments.tsx +77 -16
- package/src/client/shell/Play.tsx +24 -22
- package/src/client/shell/Toolbar.tsx +4 -3
- package/src/client/shell/app-bridge.ts +32 -5
- package/src/client/shell/canvas/Canvas.tsx +30 -8
- package/src/client/shell/canvas/FrameNode.tsx +3 -1
- package/src/client/shell/canvas/ctl.ts +16 -0
- package/src/client/shell/commands.ts +20 -0
- package/src/client/shell/comments-store.ts +81 -2
- package/src/client/shell/devices.tsx +42 -0
- package/src/client/shell/goto.ts +56 -9
- package/src/client/shell/icons.tsx +11 -4
- package/src/client/shell/jam-lines.ts +5 -3
- package/src/client/shell/jam-panel.tsx +17 -5
- package/src/client/shell/marks-ui.tsx +54 -0
- package/src/client/shell/notes.ts +21 -0
- package/src/client/shell/pdf-export.tsx +154 -0
- package/src/client/shell/pdf-notes.ts +20 -0
- package/src/client/shell/show.ts +250 -0
- package/src/client/shell/store.ts +23 -38
- package/src/client/shell/styles.css +43 -0
- package/src/shared/app-api.ts +49 -4
- package/src/shared/auto-place.ts +32 -0
- package/src/shared/board-tree.ts +3 -0
- package/src/shared/board-types.ts +6 -2
- package/src/shared/deep-link.ts +212 -0
- package/src/shared/devices.ts +89 -0
- package/src/shared/events.ts +48 -5
- package/src/shared/export-plan.ts +98 -0
- package/templates/AGENTS-embedded.md +76 -12
- package/templates/AGENTS-studio.md +76 -12
- package/templates/instructions/boards.md +6 -5
- package/templates/instructions/configure.md +32 -2
- package/templates/instructions/iterate.md +8 -0
- package/templates/instructions/jam.md +9 -0
- package/templates/instructions/publish.md +14 -4
- package/templates/instructions/review.md +4 -0
- package/templates/instructions/slides.md +67 -1
- package/templates/instructions/welcome.md +9 -5
- package/templates/playbooks/publish-canvas/PLAYBOOK.md +1 -1
- package/dist/config-BezZTiov.mjs +0 -182
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { t as ALL_SCENES } from "./board-tree-
|
|
1
|
+
import { t as ALL_SCENES } from "./board-tree-DGj0HhEE.mjs";
|
|
2
|
+
import { n as deletedMessages, o as withoutDeletedWords } from "./events-Dieo1482.mjs";
|
|
2
3
|
import { a as readLog, i as listBoards, r as legacyExposure, t as appendEvents } from "./comments-0BSbb04K.mjs";
|
|
3
4
|
import { A as reconfirmGrant, C as commentAllowed, D as operativeMode, E as loadShare, F as setBlocked, I as setGeneralMode, L as shareState, M as resolveAccess, N as resolveRequest, O as provisionVerdict, P as rosterEtag, S as ceilingsFromRights, T as loadRequests, _ as sessionUser, a as claimInvite, b as updateProfile, c as issueDeviceSession, d as opaqueId, f as ownerName, g as sessionIsOperator, h as revokeUser, j as removeGrant, k as putRequest, l as loadStore, m as publicUser, o as createInvite, s as inviteInfo, u as normEmail, v as signIn, w as entryAllowed, y as signOut, z as upsertGrant } from "./auth-Dix8wrXV.mjs";
|
|
4
|
-
import { canvasIdentity, deriveThreads, loadSeen, markSeen, signCanvasJws, unreadCount, verifyCanvasJws } from "./summary-
|
|
5
|
+
import { canvasIdentity, deriveThreads, loadSeen, markSeen, signCanvasJws, unreadCount, verifyCanvasJws } from "./summary-cPmRDGpX.mjs";
|
|
5
6
|
import { t as secureSuffix } from "./secure-cookie-_K1Hsx8H.mjs";
|
|
6
7
|
import { readFileSync } from "node:fs";
|
|
7
8
|
import { join } from "node:path";
|
|
@@ -161,7 +162,8 @@ const EVENT_TYPES = /* @__PURE__ */ new Set([
|
|
|
161
162
|
"reopen",
|
|
162
163
|
"react",
|
|
163
164
|
"profile",
|
|
164
|
-
"reanchor"
|
|
165
|
+
"reanchor",
|
|
166
|
+
"delete"
|
|
165
167
|
]);
|
|
166
168
|
const ID_RE = /^[\w-]{8,64}$/;
|
|
167
169
|
const MAX_BODY_TEXT = 1e4;
|
|
@@ -215,7 +217,9 @@ function validateEvents(incoming, log, u, board, opts = {}) {
|
|
|
215
217
|
const creates = /* @__PURE__ */ new Map();
|
|
216
218
|
const comments = /* @__PURE__ */ new Set();
|
|
217
219
|
const authors = /* @__PURE__ */ new Map();
|
|
220
|
+
const deleted = /* @__PURE__ */ new Set();
|
|
218
221
|
for (const ev of log) {
|
|
222
|
+
if (ev.type === "delete" && ev.commentId) deleted.add(ev.commentId);
|
|
219
223
|
if (ev.type === "create" && ev.commentId && !creates.has(ev.commentId)) creates.set(ev.commentId, ev);
|
|
220
224
|
if ((ev.type === "create" || ev.type === "reply") && ev.commentId) {
|
|
221
225
|
comments.add(ev.commentId);
|
|
@@ -239,13 +243,15 @@ function validateEvents(incoming, log, u, board, opts = {}) {
|
|
|
239
243
|
"reply",
|
|
240
244
|
"edit"
|
|
241
245
|
].includes(ev.type))) return "asks is a flag on a comment";
|
|
242
|
-
if (
|
|
246
|
+
if (ev.op !== void 0 && (typeof ev.op !== "string" || !ID_RE.test(ev.op) || ev.type !== "resolve" && ev.type !== "reopen")) return "op is a resolve-all's id on a resolve or reopen";
|
|
247
|
+
if ((ev.type === "create" || ev.type === "reply" || ev.type === "react" || ev.type === "edit" || ev.type === "reanchor" || ev.type === "profile" || ev.type === "delete") && ev.author?.email?.toLowerCase() !== me) return "event author must be the signed-in account";
|
|
243
248
|
if (typeof ev.commentId !== "string" || !ID_RE.test(ev.commentId)) {
|
|
244
249
|
if (ev.type !== "profile") return "event needs a commentId";
|
|
245
250
|
}
|
|
246
251
|
switch (ev.type) {
|
|
247
252
|
case "create":
|
|
248
253
|
if (creates.has(ev.commentId)) return "a thread with that id already exists";
|
|
254
|
+
if (comments.has(ev.commentId)) return "a comment with that id already exists";
|
|
249
255
|
creates.set(ev.commentId, ev);
|
|
250
256
|
comments.add(ev.commentId);
|
|
251
257
|
if (ev.author?.email) authors.set(ev.commentId, ev.author.email.toLowerCase());
|
|
@@ -260,6 +266,15 @@ function validateEvents(incoming, log, u, board, opts = {}) {
|
|
|
260
266
|
const owner = authors.get(ev.commentId);
|
|
261
267
|
if (!owner) return "cannot edit a comment that does not exist";
|
|
262
268
|
if (owner !== me) return "only the author can edit a comment";
|
|
269
|
+
if (deleted.has(ev.commentId)) return "that comment was deleted";
|
|
270
|
+
break;
|
|
271
|
+
}
|
|
272
|
+
case "delete": {
|
|
273
|
+
const owner = authors.get(ev.commentId);
|
|
274
|
+
if (!owner) return "cannot delete a comment that does not exist";
|
|
275
|
+
if (owner !== me) return "only the author can delete a comment";
|
|
276
|
+
if (ev.body !== void 0 || ev.mentions !== void 0) return "a delete carries no words";
|
|
277
|
+
deleted.add(ev.commentId);
|
|
263
278
|
break;
|
|
264
279
|
}
|
|
265
280
|
case "resolve":
|
|
@@ -278,6 +293,12 @@ function validateEvents(incoming, log, u, board, opts = {}) {
|
|
|
278
293
|
}
|
|
279
294
|
return null;
|
|
280
295
|
}
|
|
296
|
+
/** What of a push may be mailed (spec 31 C.4, Codex r8): never a message deleted by then - an offline create and its
|
|
297
|
+
* delete arriving together mail nothing. */
|
|
298
|
+
function mailable(fresh, log) {
|
|
299
|
+
const gone = deletedMessages([...log, ...fresh]);
|
|
300
|
+
return fresh.filter((e) => !((e.type === "create" || e.type === "reply" || e.type === "edit") && e.commentId && gone.has(e.commentId)));
|
|
301
|
+
}
|
|
281
302
|
function collabHandler(dataDir, distDir) {
|
|
282
303
|
let rights = {};
|
|
283
304
|
let meta = {};
|
|
@@ -313,15 +334,29 @@ function collabHandler(dataDir, distDir) {
|
|
|
313
334
|
let seq = 0;
|
|
314
335
|
const ring = [];
|
|
315
336
|
const clients = /* @__PURE__ */ new Map();
|
|
316
|
-
const
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
337
|
+
const frameOf = (s, board, ev) => `id: ${bootEpoch}-${s}\nevent: comment\ndata: ${JSON.stringify({
|
|
338
|
+
board,
|
|
339
|
+
ev
|
|
340
|
+
})}\n\n`;
|
|
341
|
+
/** `gone` (spec 31 C.4): the board's deleted messages - their words never go out, and a frame the replay ring still
|
|
342
|
+
* holds for one is made again without them, so a reconnect cannot read what was deleted since */
|
|
343
|
+
const broadcast = (board, events, gone = /* @__PURE__ */ new Set()) => {
|
|
344
|
+
if (gone.size && events.some((e) => e.type === "delete")) for (const r of ring) {
|
|
345
|
+
if (r.board !== board) continue;
|
|
346
|
+
const ev = withoutDeletedWords(r.ev, gone);
|
|
347
|
+
if (ev !== r.ev) {
|
|
348
|
+
r.ev = ev;
|
|
349
|
+
r.data = frameOf(r.seq, board, ev);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
for (const raw of events) {
|
|
353
|
+
const ev = withoutDeletedWords(raw, gone);
|
|
354
|
+
const frame = frameOf(++seq, board, ev);
|
|
322
355
|
ring.push({
|
|
323
356
|
seq,
|
|
324
|
-
data: frame
|
|
357
|
+
data: frame,
|
|
358
|
+
board,
|
|
359
|
+
ev
|
|
325
360
|
});
|
|
326
361
|
if (ring.length > 500) ring.shift();
|
|
327
362
|
for (const res of clients.keys()) res.write(frame);
|
|
@@ -809,6 +844,7 @@ function collabHandler(dataDir, distDir) {
|
|
|
809
844
|
return res.end(), true;
|
|
810
845
|
}
|
|
811
846
|
if (req.method === "GET") {
|
|
847
|
+
if (path === "capabilities") return json(res, 200, { delete: true }), true;
|
|
812
848
|
if (path === "me") {
|
|
813
849
|
const u = currentUser(req);
|
|
814
850
|
if (!u) return json(res, 401, { error: "signed out" }), true;
|
|
@@ -848,7 +884,9 @@ function collabHandler(dataDir, distDir) {
|
|
|
848
884
|
const exposed = legacyExposure(events, rights, shows);
|
|
849
885
|
events = events.filter((e) => exposed(e).length);
|
|
850
886
|
}
|
|
851
|
-
return json(res, 200, { events
|
|
887
|
+
if (rawTransport(req)) return json(res, 200, { events }), true;
|
|
888
|
+
const gone = deletedMessages(events);
|
|
889
|
+
return json(res, 200, { events: events.map((e) => project(withoutDeletedWords(e, gone))) }), true;
|
|
852
890
|
}
|
|
853
891
|
if (path === "invite-info") {
|
|
854
892
|
if (limited(`ip:${ip}`)) return json(res, 429, { error: "too many attempts - wait a minute" }), true;
|
|
@@ -987,8 +1025,9 @@ function collabHandler(dataDir, distDir) {
|
|
|
987
1025
|
const st = threads.get(m[1]);
|
|
988
1026
|
threads.set(m[1], deriveThreads([...st?.events ?? [], ...fresh]));
|
|
989
1027
|
}
|
|
990
|
-
broadcast(m[1], fresh.map(project));
|
|
991
|
-
|
|
1028
|
+
broadcast(m[1], fresh.map(project), deletedMessages([...log, ...fresh]));
|
|
1029
|
+
const mail = mailable(fresh, log);
|
|
1030
|
+
if (mail.length) notifyCommentActivity(notifyCtx, m[1], mail, legacy ? [...log, ...fresh] : threads.get(m[1])?.events ?? [], (email) => legacy ? Object.keys(rights).some((b) => mailAllowed(b, email)) : mailAllowed(m[1], email));
|
|
992
1031
|
return json(res, 200, { accepted: fresh.length }), true;
|
|
993
1032
|
}
|
|
994
1033
|
return false;
|
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
import { h as readRegistry, l as listBoardFiles, o as checkBoardsDir, r as boardFields } from "./boards-Cim1GTKc.mjs";
|
|
2
|
+
import { a as buildTree, f as isBoardName, l as framesOn, o as flatten } from "./board-tree-DGj0HhEE.mjs";
|
|
3
|
+
import { s as scanFrames } from "./manifest-CK8Qh4Nq.mjs";
|
|
4
|
+
import { a as replay } from "./events-Dieo1482.mjs";
|
|
5
|
+
import { a as readLog, i as listBoards, t as appendEvents } from "./comments-0BSbb04K.mjs";
|
|
6
|
+
import { ctxFor, liveThreads, n as readRaw } from "./queue-BLLfdlDw.mjs";
|
|
7
|
+
import { mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
import { createHash } from "node:crypto";
|
|
10
|
+
//#region src/server/comment-actions.ts
|
|
11
|
+
/**
|
|
12
|
+
* Resolve all comments, and its Undo (spec 31 B.1-B.5) - one core for the dev server's routes and the CLI.
|
|
13
|
+
*
|
|
14
|
+
* Scope is what you see, never a log: a board = the open threads on frames that board shows; a folder = the union
|
|
15
|
+
* over its boards, sub-folders included; a scene = the threads on that scene's frames; the canvas = every open
|
|
16
|
+
* thread. Each resolve is written to its thread's own log, so it is the same as resolving each by hand - Jam's
|
|
17
|
+
* `asks`, `review` and `failed` items on it complete when the queue ingests it - except live work: a thread whose
|
|
18
|
+
* Jam card is queued or working (or whose tag is written and not yet queued) is skipped and counted. The check and
|
|
19
|
+
* the appends run in one synchronous step: nothing is awaited between them, so no ingest slips a card in.
|
|
20
|
+
*
|
|
21
|
+
* Every operation has a client id (`op`): a retry returns the same receipt. The receipt names, per thread, its log,
|
|
22
|
+
* its resolve event and that event's time (after everything the thread held, whatever clock wrote it); Undo reopens a
|
|
23
|
+
* thread only while that resolve is still its latest event of any kind, and says how many changed since. Jam items a resolve completed stay completed - Undo reopens conversations only.
|
|
24
|
+
*
|
|
25
|
+
* Receipts live in `design/.local/comment-ops/` (never synced). Event ids are derived from the op, so a crash
|
|
26
|
+
* between the appends and the receipt is retried onto the same ids (appendEvents keeps one of each).
|
|
27
|
+
*/
|
|
28
|
+
const OP_RE = /^[\w-]{8,64}$/;
|
|
29
|
+
const SCENE_RE = /^[A-Za-z0-9_][\w.-]*$/;
|
|
30
|
+
/** Exactly one scope, every name on its grammar - else what is wrong. An empty or malformed one is refused,
|
|
31
|
+
* never read as the whole canvas. */
|
|
32
|
+
function parseScope(raw) {
|
|
33
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return "expected a scope: {board} | {folder} | {scene} | {canvas: true}";
|
|
34
|
+
if (Object.keys(raw).length !== 1) return "name exactly one scope: board, folder, scene or canvas";
|
|
35
|
+
const o = raw;
|
|
36
|
+
if ("board" in o) return isBoardName(o.board) ? { board: o.board } : "invalid board name";
|
|
37
|
+
if ("folder" in o) return isBoardName(o.folder) ? { folder: o.folder } : "invalid folder name";
|
|
38
|
+
if ("scene" in o) return typeof o.scene === "string" && o.scene.length <= 120 && (o.scene === "" || SCENE_RE.test(o.scene)) ? { scene: o.scene } : "invalid scene name";
|
|
39
|
+
if ("canvas" in o) return o.canvas === true ? { canvas: true } : "canvas scope is {canvas: true}";
|
|
40
|
+
return "unknown scope - board, folder, scene or canvas";
|
|
41
|
+
}
|
|
42
|
+
const scopeLabel = (s) => "board" in s ? `board ${s.board}` : "folder" in s ? `folder ${s.folder}` : "scene" in s ? s.scene ? `scene ${s.scene}` : "the root scene" : "the canvas";
|
|
43
|
+
/** The frames a scope covers (null = the whole canvas), or why it names nothing. */
|
|
44
|
+
function scopeFrames(root, scope) {
|
|
45
|
+
if ("canvas" in scope) return { frames: null };
|
|
46
|
+
const manifest = scanFrames(root).frames;
|
|
47
|
+
const live = manifest.map((f) => f.id);
|
|
48
|
+
if ("scene" in scope) {
|
|
49
|
+
const ids = manifest.filter((f) => f.scene === scope.scene).map((f) => f.id);
|
|
50
|
+
return ids.length ? { frames: new Set(ids) } : { error: scope.scene ? `no scene "${scope.scene}"` : "no frames in the root scene" };
|
|
51
|
+
}
|
|
52
|
+
const dir = join(root, "design", "boards");
|
|
53
|
+
const files = checkBoardsDir(root, dir) ? [] : listBoardFiles(dir).boards;
|
|
54
|
+
const framesOf = (names) => new Set(names.flatMap((n) => framesOn(files.find((b) => b.name === n)?.json, live)));
|
|
55
|
+
if ("board" in scope) {
|
|
56
|
+
const b = files.find((x) => x.name === scope.board);
|
|
57
|
+
return b ? { frames: framesOf([b.name]) } : { error: `no board "${scope.board}"` };
|
|
58
|
+
}
|
|
59
|
+
const reg = readRegistry(dir);
|
|
60
|
+
const tree = buildTree(files.map((b) => ({
|
|
61
|
+
name: b.name,
|
|
62
|
+
...boardFields(b.json, isBoardName)
|
|
63
|
+
})), reg.state === "ok" ? reg.folders : []);
|
|
64
|
+
const find = (items) => {
|
|
65
|
+
for (const it of items) {
|
|
66
|
+
if (it.kind !== "folder") continue;
|
|
67
|
+
if (it.name === scope.folder) return it;
|
|
68
|
+
const inner = find(it.items);
|
|
69
|
+
if (inner) return inner;
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
const f = find(tree);
|
|
73
|
+
return f && f.kind === "folder" ? { frames: framesOf(flatten(f.items)) } : { error: `no folder "${scope.folder}"` };
|
|
74
|
+
}
|
|
75
|
+
/** The threads Jam is at work on (`board\tthread`): the running daemon's journal in memory when it has one, else
|
|
76
|
+
* the journal on disk - queued work that would run at the next start is work too. */
|
|
77
|
+
function jamBusy(root, live) {
|
|
78
|
+
if (live) return live();
|
|
79
|
+
const raw = readRaw(root);
|
|
80
|
+
return raw.v2 ? liveThreads(raw.v2, ctxFor(root)) : /* @__PURE__ */ new Set();
|
|
81
|
+
}
|
|
82
|
+
const opsDir = (root) => join(root, "design", ".local", "comment-ops");
|
|
83
|
+
const receiptFile = (root, op, undo = false) => join(opsDir(root), `${op}${undo ? ".undo" : ""}.json`);
|
|
84
|
+
const readJson = (f) => {
|
|
85
|
+
try {
|
|
86
|
+
return JSON.parse(readFileSync(f, "utf8"));
|
|
87
|
+
} catch {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
function save(file, v) {
|
|
92
|
+
mkdirSync(join(file, ".."), { recursive: true });
|
|
93
|
+
const tmp = `${file}.${process.pid}.tmp`;
|
|
94
|
+
writeFileSync(tmp, JSON.stringify(v, null, 1) + "\n", { mode: 384 });
|
|
95
|
+
renameSync(tmp, file);
|
|
96
|
+
}
|
|
97
|
+
const idFor = (kind, op, board, thread) => `${kind}-${createHash("sha256").update(`${op}\0${board}\0${thread}`).digest("hex").slice(0, 32)}`;
|
|
98
|
+
const readReceipt = (root, op) => OP_RE.test(op) ? readJson(receiptFile(root, op)) : null;
|
|
99
|
+
/** Every event of a thread in one log - its messages, and whatever names it or one of its replies (an edit, a reaction,
|
|
100
|
+
* a resolve, a delete) - in replay's order. */
|
|
101
|
+
function threadEvents(events, thread) {
|
|
102
|
+
const ids = /* @__PURE__ */ new Set([thread, ...events.filter((e) => e.type === "reply" && e.parentId === thread && e.commentId).map((e) => e.commentId)]);
|
|
103
|
+
return events.filter((e) => e.type === "reply" ? e.parentId === thread : !!e.commentId && ids.has(e.commentId)).sort((a, b) => a.ts - b.ts || (a.id < b.id ? -1 : 1));
|
|
104
|
+
}
|
|
105
|
+
/** A time after everything the thread holds - what this clock says, or later when another clock ran ahead (replay
|
|
106
|
+
* orders by time: the write must come last to take effect). */
|
|
107
|
+
const after = (events, thread, now) => Math.max(now, (threadEvents(events, thread).at(-1)?.ts ?? 0) + 1);
|
|
108
|
+
/** The open threads a scope covers, each with its own log - shown threads only (a deleted one is not). */
|
|
109
|
+
function threadsIn(root, frames) {
|
|
110
|
+
const dir = join(root, "design", "comments");
|
|
111
|
+
const out = [];
|
|
112
|
+
for (const board of listBoards(dir)) for (const t of replay(readLog(dir, board))) {
|
|
113
|
+
if (t.resolved) continue;
|
|
114
|
+
if (frames && (!t.frame || !frames.has(t.frame))) continue;
|
|
115
|
+
out.push({
|
|
116
|
+
board,
|
|
117
|
+
thread: t.id,
|
|
118
|
+
...t.frame ? { frame: t.frame } : {},
|
|
119
|
+
...t.board && t.board !== board ? { stamp: t.board } : {}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
return out;
|
|
123
|
+
}
|
|
124
|
+
/** Append each log's events; a log that throws is reported with its threads, the others still land. */
|
|
125
|
+
function appendAll(dir, byBoard) {
|
|
126
|
+
const failed = [];
|
|
127
|
+
for (const [board, events] of byBoard) try {
|
|
128
|
+
appendEvents(dir, board, events);
|
|
129
|
+
} catch (err) {
|
|
130
|
+
failed.push({
|
|
131
|
+
board,
|
|
132
|
+
threads: events.map((e) => e.commentId),
|
|
133
|
+
error: err.message
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
return failed;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Resolve every open thread in `scope` but the ones Jam is at work on. SYNCHRONOUS from the Jam check to the last
|
|
140
|
+
* append - keep it that way. A retry of an op returns its receipt (a pending one is finished first).
|
|
141
|
+
*/
|
|
142
|
+
function resolveAll(root, op, scope, o = {}) {
|
|
143
|
+
if (!OP_RE.test(op)) return {
|
|
144
|
+
error: "op must be an 8-64 char token",
|
|
145
|
+
status: 400
|
|
146
|
+
};
|
|
147
|
+
const dir = join(root, "design", "comments");
|
|
148
|
+
const file = receiptFile(root, op);
|
|
149
|
+
const had = o.dryRun ? null : readJson(file);
|
|
150
|
+
if (had && JSON.stringify(had.scope) !== JSON.stringify(scope)) return {
|
|
151
|
+
error: "that op was used for another scope",
|
|
152
|
+
status: 409
|
|
153
|
+
};
|
|
154
|
+
if (had?.state === "done") return had;
|
|
155
|
+
const at = o.now ?? Date.now();
|
|
156
|
+
const busy = jamBusy(root, o.busy);
|
|
157
|
+
const skipped = [];
|
|
158
|
+
let plan;
|
|
159
|
+
if (had) {
|
|
160
|
+
plan = had.resolved.filter((r) => !busy.has(`${r.board}\t${r.thread}`));
|
|
161
|
+
for (const r of had.resolved) if (busy.has(`${r.board}\t${r.thread}`)) skipped.push({
|
|
162
|
+
board: r.board,
|
|
163
|
+
thread: r.thread,
|
|
164
|
+
why: "working"
|
|
165
|
+
});
|
|
166
|
+
skipped.push(...had.skipped.filter((x) => !skipped.some((y) => y.board === x.board && y.thread === x.thread)));
|
|
167
|
+
} else {
|
|
168
|
+
const where = scopeFrames(root, scope);
|
|
169
|
+
if ("error" in where) return {
|
|
170
|
+
error: where.error,
|
|
171
|
+
status: 404
|
|
172
|
+
};
|
|
173
|
+
plan = [];
|
|
174
|
+
const logs = /* @__PURE__ */ new Map();
|
|
175
|
+
const logOf = (b) => {
|
|
176
|
+
let l = logs.get(b);
|
|
177
|
+
if (!l) logs.set(b, l = readLog(dir, b));
|
|
178
|
+
return l;
|
|
179
|
+
};
|
|
180
|
+
for (const t of threadsIn(root, where.frames)) {
|
|
181
|
+
if (busy.has(`${t.board}\t${t.thread}`)) {
|
|
182
|
+
skipped.push({
|
|
183
|
+
board: t.board,
|
|
184
|
+
thread: t.thread,
|
|
185
|
+
why: "working"
|
|
186
|
+
});
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
plan.push({
|
|
190
|
+
board: t.board,
|
|
191
|
+
thread: t.thread,
|
|
192
|
+
event: idFor("ra", op, t.board, t.thread),
|
|
193
|
+
...t.stamp ? { stamp: t.stamp } : {},
|
|
194
|
+
ts: after(logOf(t.board), t.thread, at),
|
|
195
|
+
known: threadEvents(logOf(t.board), t.thread).length
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
const receipt = {
|
|
200
|
+
op,
|
|
201
|
+
scope,
|
|
202
|
+
at: had?.at ?? at,
|
|
203
|
+
state: "pending",
|
|
204
|
+
resolved: plan,
|
|
205
|
+
skipped,
|
|
206
|
+
failed: []
|
|
207
|
+
};
|
|
208
|
+
if (o.dryRun) return {
|
|
209
|
+
...receipt,
|
|
210
|
+
state: "done"
|
|
211
|
+
};
|
|
212
|
+
save(file, receipt);
|
|
213
|
+
const byBoard = /* @__PURE__ */ new Map();
|
|
214
|
+
for (const r of plan) {
|
|
215
|
+
const ev = {
|
|
216
|
+
id: r.event,
|
|
217
|
+
ts: r.ts ?? receipt.at,
|
|
218
|
+
type: "resolve",
|
|
219
|
+
commentId: r.thread,
|
|
220
|
+
board: r.stamp ?? r.board,
|
|
221
|
+
op
|
|
222
|
+
};
|
|
223
|
+
byBoard.set(r.board, [...byBoard.get(r.board) ?? [], ev]);
|
|
224
|
+
}
|
|
225
|
+
const unwritten = appendAll(dir, byBoard);
|
|
226
|
+
const missed = new Set(unwritten.flatMap((f) => f.threads.map((t) => `${f.board}\t${t}`)));
|
|
227
|
+
receipt.failed = [...unwritten, ...verify(dir, plan.filter((r) => !missed.has(`${r.board}\t${r.thread}`)), true)];
|
|
228
|
+
const lost = new Set(receipt.failed.flatMap((f) => f.threads.map((t) => `${f.board}\t${t}`)));
|
|
229
|
+
receipt.resolved = plan.filter((r) => !lost.has(`${r.board}\t${r.thread}`));
|
|
230
|
+
receipt.state = "done";
|
|
231
|
+
save(file, receipt);
|
|
232
|
+
return receipt;
|
|
233
|
+
}
|
|
234
|
+
/** What the logs say now, per planned thread: a write that took is counted, one that did not is reported. */
|
|
235
|
+
function verify(dir, plan, resolved) {
|
|
236
|
+
const out = /* @__PURE__ */ new Map();
|
|
237
|
+
for (const board of new Set(plan.map((r) => r.board))) {
|
|
238
|
+
const state = new Map(replay(readLog(dir, board)).map((t) => [t.id, t.resolved]));
|
|
239
|
+
for (const r of plan.filter((x) => x.board === board)) if (state.has(r.thread) && state.get(r.thread) !== resolved) out.set(board, [...out.get(board) ?? [], r.thread]);
|
|
240
|
+
}
|
|
241
|
+
return [...out].map(([board, threads]) => ({
|
|
242
|
+
board,
|
|
243
|
+
threads,
|
|
244
|
+
error: `a later event keeps ${threads.length === 1 ? "it" : "them"} ${resolved ? "open" : "resolved"}`
|
|
245
|
+
}));
|
|
246
|
+
}
|
|
247
|
+
/** Undo an op: reopen each thread whose latest resolve or reopen is still the op's resolve. A retry returns the
|
|
248
|
+
* same answer. */
|
|
249
|
+
function undoResolveAll(root, op, o = {}) {
|
|
250
|
+
if (!OP_RE.test(op)) return {
|
|
251
|
+
error: "op must be an 8-64 char token",
|
|
252
|
+
status: 400
|
|
253
|
+
};
|
|
254
|
+
const done = readReceipt(root, op);
|
|
255
|
+
if (!done || done.state !== "done") return {
|
|
256
|
+
error: "no such resolve-all to undo",
|
|
257
|
+
status: 404
|
|
258
|
+
};
|
|
259
|
+
const file = receiptFile(root, op, true);
|
|
260
|
+
const had = readJson(file);
|
|
261
|
+
if (had?.state === "done") return had;
|
|
262
|
+
const dir = join(root, "design", "comments");
|
|
263
|
+
const at = o.now ?? Date.now();
|
|
264
|
+
const logs = /* @__PURE__ */ new Map();
|
|
265
|
+
const logOf = (b) => {
|
|
266
|
+
let l = logs.get(b);
|
|
267
|
+
if (!l) logs.set(b, l = readLog(dir, b));
|
|
268
|
+
return l;
|
|
269
|
+
};
|
|
270
|
+
let reopened = [], changed = [];
|
|
271
|
+
/** Nothing happened in the thread since the op resolved it: its latest event is that resolve, and no event arrived
|
|
272
|
+
* since the plan however its clock ordered it (a slower clock sorts before the resolve - Codex r3). */
|
|
273
|
+
const untouched = (r, events) => {
|
|
274
|
+
const evs = threadEvents(events, r.thread);
|
|
275
|
+
if (evs.at(-1)?.id !== r.event) return false;
|
|
276
|
+
const reopen = idFor("ru", op, r.board, r.thread);
|
|
277
|
+
return r.known === void 0 || evs.filter((e) => e.id !== r.event && e.id !== reopen).length <= r.known;
|
|
278
|
+
};
|
|
279
|
+
if (had) {
|
|
280
|
+
changed = [...had.changed];
|
|
281
|
+
for (const r of had.reopened) {
|
|
282
|
+
const events = logOf(r.board);
|
|
283
|
+
if (events.some((e) => e.id === r.event)) {
|
|
284
|
+
reopened.push(r);
|
|
285
|
+
continue;
|
|
286
|
+
}
|
|
287
|
+
const planned = done.resolved.find((x) => x.board === r.board && x.thread === r.thread);
|
|
288
|
+
if (planned && untouched(planned, events)) reopened.push(r);
|
|
289
|
+
else changed.push({
|
|
290
|
+
board: r.board,
|
|
291
|
+
thread: r.thread
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
} else for (const r of done.resolved) {
|
|
295
|
+
const events = logOf(r.board);
|
|
296
|
+
if (replay(events).some((t) => t.id === r.thread) && untouched(r, events)) reopened.push({
|
|
297
|
+
board: r.board,
|
|
298
|
+
thread: r.thread,
|
|
299
|
+
event: idFor("ru", op, r.board, r.thread),
|
|
300
|
+
...r.stamp ? { stamp: r.stamp } : {},
|
|
301
|
+
ts: after(events, r.thread, at)
|
|
302
|
+
});
|
|
303
|
+
else changed.push({
|
|
304
|
+
board: r.board,
|
|
305
|
+
thread: r.thread
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
const receipt = {
|
|
309
|
+
op,
|
|
310
|
+
at: had?.at ?? at,
|
|
311
|
+
state: "pending",
|
|
312
|
+
reopened,
|
|
313
|
+
changed,
|
|
314
|
+
failed: []
|
|
315
|
+
};
|
|
316
|
+
save(file, receipt);
|
|
317
|
+
const byBoard = /* @__PURE__ */ new Map();
|
|
318
|
+
for (const r of reopened) byBoard.set(r.board, [...byBoard.get(r.board) ?? [], {
|
|
319
|
+
id: r.event,
|
|
320
|
+
ts: r.ts ?? receipt.at,
|
|
321
|
+
type: "reopen",
|
|
322
|
+
commentId: r.thread,
|
|
323
|
+
board: r.stamp ?? r.board,
|
|
324
|
+
op
|
|
325
|
+
}]);
|
|
326
|
+
const unwritten = appendAll(dir, byBoard);
|
|
327
|
+
const missed = new Set(unwritten.flatMap((f) => f.threads.map((t) => `${f.board}\t${t}`)));
|
|
328
|
+
receipt.failed = [...unwritten, ...verify(dir, reopened.filter((r) => !missed.has(`${r.board}\t${r.thread}`)), false)];
|
|
329
|
+
const lost = new Set(receipt.failed.flatMap((f) => f.threads.map((t) => `${f.board}\t${t}`)));
|
|
330
|
+
receipt.reopened = reopened.filter((r) => !lost.has(`${r.board}\t${r.thread}`));
|
|
331
|
+
receipt.state = "done";
|
|
332
|
+
save(file, receipt);
|
|
333
|
+
return receipt;
|
|
334
|
+
}
|
|
335
|
+
/** The words a person reads: "Resolved 31 conversations · 2 left open: work in progress". */
|
|
336
|
+
function resolveSummary(r) {
|
|
337
|
+
const n = r.resolved.length;
|
|
338
|
+
const parts = [n ? `Resolved ${n} conversation${n === 1 ? "" : "s"}` : "Nothing to resolve"];
|
|
339
|
+
if (r.skipped.length) parts.push(`${r.skipped.length} left open: work in progress`);
|
|
340
|
+
if (r.failed.length) parts.push(`${r.failed.reduce((k, f) => k + f.threads.length, 0)} not resolved: ${r.failed.map((f) => `${f.board} (${f.error})`).join(", ")}`);
|
|
341
|
+
return parts.join(" · ");
|
|
342
|
+
}
|
|
343
|
+
function undoSummary(u) {
|
|
344
|
+
const n = u.reopened.length;
|
|
345
|
+
const parts = [`Reopened ${n}${n ? " (finished Jam items stay finished)" : ""}`];
|
|
346
|
+
if (u.changed.length) parts.push(`${u.changed.length} changed since - left as is`);
|
|
347
|
+
if (u.failed.length) parts.push(`${u.failed.reduce((k, f) => k + f.threads.length, 0)} could not be reopened: ${u.failed.map((f) => `${f.board} (${f.error})`).join(", ")}`);
|
|
348
|
+
return parts.join(" · ");
|
|
349
|
+
}
|
|
350
|
+
//#endregion
|
|
351
|
+
export { OP_RE, parseScope, resolveAll, resolveSummary, scopeLabel, undoResolveAll, undoSummary };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { r as NAME } from "./cli.mjs";
|
|
2
|
-
import { i as readDevInfo } from "./work-
|
|
3
|
-
import {
|
|
2
|
+
import { i as readDevInfo } from "./work-Nv-n2_Un.mjs";
|
|
3
|
+
import { a as replay } from "./events-Dieo1482.mjs";
|
|
4
4
|
import { a as readLog, i as listBoards, t as appendEvents } from "./comments-0BSbb04K.mjs";
|
|
5
|
-
import { a as syncOnce, i as loadCollab, n as connectClaim, r as connectToken, t as connect } from "./sync-
|
|
6
|
-
import { n as localProfile } from "./profile-
|
|
5
|
+
import { a as syncOnce, i as loadCollab, n as connectClaim, r as connectToken, t as connect } from "./sync-BNWwh8OF.mjs";
|
|
6
|
+
import { n as localProfile } from "./profile-cdmSer1k.mjs";
|
|
7
7
|
import { a as runningAgent } from "./agent-BsieQGTD.mjs";
|
|
8
8
|
import { n as readTarget, r as uncheckedAnchor } from "./anchor-5H1vnoLu.mjs";
|
|
9
9
|
import { join } from "node:path";
|
|
@@ -29,6 +29,8 @@ import { createInterface } from "node:readline";
|
|
|
29
29
|
* --ask when the reply asks the human something
|
|
30
30
|
* move <thread> re-pin a thread on another element (--on / --at) - its author's only
|
|
31
31
|
* resolve <thread> mark addressed (--addressed-in <frame> records WHICH variant)
|
|
32
|
+
* resolve --all every open thread in one scope (--board | --folder | --scene | --canvas; --dry-run counts) -
|
|
33
|
+
* never what Jam is at work on; --undo <op> reopens what it resolved. Only on the human's yes.
|
|
32
34
|
* invite <email> mint a single-use invite link (owner only, needs connect first)
|
|
33
35
|
* revoke <email> revoke an account and its sessions (owner only)
|
|
34
36
|
*/
|
|
@@ -94,7 +96,9 @@ async function commentsCommand(root, action, value, opts) {
|
|
|
94
96
|
const collab = loadCollab(root);
|
|
95
97
|
if (!collab) throw new Error(`not connected - run \`${NAME} comments connect <url>\` first`);
|
|
96
98
|
const out = await syncOnce(root, collab);
|
|
97
|
-
|
|
99
|
+
const { readHeld, heldWords } = await import("./sync-BNWwh8OF.mjs").then((n) => n.o);
|
|
100
|
+
const held = readHeld(root);
|
|
101
|
+
for (const [b, n] of Object.entries(out)) console.log(` ${b}: pulled ${n.pulled}, pushed ${n.pushed}${held[b]?.length ? ` - ${heldWords(held[b]).join("; ")}` : ""}`);
|
|
98
102
|
if (!Object.keys(out).length) console.log(" nothing to sync");
|
|
99
103
|
return;
|
|
100
104
|
}
|
|
@@ -105,7 +109,7 @@ async function commentsCommand(root, action, value, opts) {
|
|
|
105
109
|
if (!threads.length) return void console.log(` no ${opts.open ? "open " : ""}comments`);
|
|
106
110
|
for (const t of threads) {
|
|
107
111
|
const anchor = t.frame ? ` on ${t.frame}` : "";
|
|
108
|
-
console.log(` ${t.resolved ? "✓" : "○"} ${t.id}${anchor} - ${t.agent ? "Marver" : t.author?.name ?? "?"}: ${t.body ?? ""}${t.replies.length ? ` (+${t.replies.length})` : ""}${t.addressedIn ? ` → ${t.addressedIn}` : ""}`);
|
|
112
|
+
console.log(` ${t.resolved ? "✓" : "○"} ${t.id}${anchor} - ${t.deleted ? "(comment deleted)" : `${t.agent ? "Marver" : t.author?.name ?? "?"}: ${t.body ?? ""}`}${t.replies.length ? ` (+${t.replies.length})` : ""}${t.addressedIn ? ` → ${t.addressedIn}` : ""}`);
|
|
109
113
|
}
|
|
110
114
|
return;
|
|
111
115
|
}
|
|
@@ -132,7 +136,7 @@ async function commentsCommand(root, action, value, opts) {
|
|
|
132
136
|
case "new": {
|
|
133
137
|
if (opts.thread !== void 0) return addToThread(root, String(opts.thread), value, opts);
|
|
134
138
|
if (!value || !opts.body) throw new Error("usage: comments new <scene/frame> --body \"...\" --on \"<words it shows>\" | --at \"<selector or data-testid>\" [--nth <n>] [--fyi] [--board <board>]");
|
|
135
|
-
const { resolveLink, devOrigin } = await import("./link-
|
|
139
|
+
const { resolveLink, devOrigin, linkFor } = await import("./link-Cmt9Xy4X.mjs");
|
|
136
140
|
const r = resolveLink(root, [value], opts.board);
|
|
137
141
|
if (r.exact.length !== 1) throw new Error(`"${value}" is a folder of frames - pin a note on one frame: comments new <scene/frame>`);
|
|
138
142
|
if (!r.board) throw new Error(`a note needs a board to live on - ${r.hints.join("\n")}`);
|
|
@@ -157,7 +161,7 @@ async function commentsCommand(root, action, value, opts) {
|
|
|
157
161
|
asks: !opts.fyi
|
|
158
162
|
}]);
|
|
159
163
|
const origin = await devOrigin(root);
|
|
160
|
-
console.log(` pinned a note on ${frame} (board ${r.board})${origin ? `: ${origin
|
|
164
|
+
console.log(` pinned a note on ${frame} (board ${r.board})${origin ? `: ${linkFor(root, origin, `#/b/${r.board}?c=${threadId}`)}` : ""}`);
|
|
161
165
|
for (const t of open.filter((t) => holders.includes(t.id))) {
|
|
162
166
|
const next = ownerThread(root, t) ? `comments new --thread ${t.id} --body "..."` : `comments reply ${t.id} --body "..."`;
|
|
163
167
|
console.log(` that element already holds thread ${t.id} (${t.agent ? "Marver" : t.author?.name ?? "someone"}: "${(t.body ?? "").slice(0, 60)}") - a follow-up on it is \`${NAME} ${next}\``);
|
|
@@ -188,7 +192,9 @@ async function commentsCommand(root, action, value, opts) {
|
|
|
188
192
|
return;
|
|
189
193
|
}
|
|
190
194
|
case "resolve": {
|
|
191
|
-
if (
|
|
195
|
+
if (opts.undo !== void 0) return resolveUndo(root, String(opts.undo));
|
|
196
|
+
if (opts.all) return resolveAllCli(root, value, opts);
|
|
197
|
+
if (!value) throw new Error("usage: comments resolve <thread-id> [--addressed-in <frame>] | --all (--board b | --folder f | --scene s | --canvas) [--dry-run]");
|
|
192
198
|
const t = allThreads(root).find((t) => t.id === value);
|
|
193
199
|
if (!t) throw new Error(`no thread ${value} in design/comments/`);
|
|
194
200
|
appendEvents(join(root, "design", "comments"), t.board, [{
|
|
@@ -223,9 +229,78 @@ async function commentsCommand(root, action, value, opts) {
|
|
|
223
229
|
await ownerApi(root, "revoke", { email: value });
|
|
224
230
|
console.log(` revoked ${value} - their sessions are dead`);
|
|
225
231
|
return;
|
|
226
|
-
default: throw new Error(`unknown action "${action}" - connect | sync | list | new | reply | move | resolve | invite | revoke`);
|
|
232
|
+
default: throw new Error(`unknown action "${action}" - connect | sync | list | new | reply | move | resolve (--all) | invite | revoke`);
|
|
227
233
|
}
|
|
228
234
|
}
|
|
235
|
+
/** `comments resolve --all` (spec 31 B.5): every open thread in one scope - through the running \`dev\` (its Jam queue in
|
|
236
|
+
* memory is the one checked, in the same step as the writes), else here, against the journal on disk. Never decided by
|
|
237
|
+
* an agent alone: the guide says to ask, with the counts \`--dry-run\` prints. */
|
|
238
|
+
const resolveAllCli = async (root, value, opts) => {
|
|
239
|
+
if (value) throw new Error(`resolve --all takes no thread id - name a scope: --board, --folder, --scene or --canvas`);
|
|
240
|
+
const ca = await import("./comment-actions-Bxf9Ld4g.mjs");
|
|
241
|
+
const named = [
|
|
242
|
+
opts.board !== void 0 && { board: String(opts.board) },
|
|
243
|
+
opts.folder !== void 0 && { folder: String(opts.folder) },
|
|
244
|
+
opts.scene !== void 0 && { scene: String(opts.scene) },
|
|
245
|
+
opts.canvas && { canvas: true }
|
|
246
|
+
].filter(Boolean);
|
|
247
|
+
if (named.length !== 1) throw new Error("resolve --all needs exactly one scope: --board <b> | --folder <f> | --scene <s> | --canvas");
|
|
248
|
+
const scope = ca.parseScope(named[0]);
|
|
249
|
+
if (typeof scope === "string") throw new Error(scope);
|
|
250
|
+
const op = randomUUID();
|
|
251
|
+
const dryRun = !!opts.dryRun;
|
|
252
|
+
const r = readDevInfo(root) ? await viaDev(root, "resolve-all", {
|
|
253
|
+
op,
|
|
254
|
+
scope,
|
|
255
|
+
dryRun
|
|
256
|
+
}) : ca.resolveAll(root, op, scope, { dryRun });
|
|
257
|
+
if ("error" in r) throw new Error(r.error);
|
|
258
|
+
if (dryRun) {
|
|
259
|
+
const per = /* @__PURE__ */ new Map();
|
|
260
|
+
for (const t of r.resolved) per.set(t.board, (per.get(t.board) ?? 0) + 1);
|
|
261
|
+
console.log(` ${ca.scopeLabel(scope)}: ${r.resolved.length} open conversation${r.resolved.length === 1 ? "" : "s"} would be resolved${r.skipped.length ? `, ${r.skipped.length} left open (work in progress)` : ""}`);
|
|
262
|
+
for (const [b, n] of per) console.log(` ${b}: ${n}`);
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
console.log(` ${ca.resolveSummary(r)} (${ca.scopeLabel(scope)})`);
|
|
266
|
+
if (r.resolved.length) console.log(` undo: ${NAME} comments resolve --undo ${op}`);
|
|
267
|
+
if (r.resolved.length) await pushIfConnected(root);
|
|
268
|
+
if (r.failed.length) process.exitCode = 1;
|
|
269
|
+
};
|
|
270
|
+
/** A comment action through the running \`dev\` - tried twice with the same op (a retry returns the same receipt); a
|
|
271
|
+
* \`dev\` that cannot answer is said, never worked around. */
|
|
272
|
+
const viaDev = async (root, action, body) => {
|
|
273
|
+
const info = readDevInfo(root);
|
|
274
|
+
let last = "";
|
|
275
|
+
for (let i = 0; i < 2; i++) try {
|
|
276
|
+
const res = await fetch(`http://localhost:${info.port}/__mv/api/comment-actions/${action}`, {
|
|
277
|
+
method: "POST",
|
|
278
|
+
headers: {
|
|
279
|
+
"x-mv-work": info.token,
|
|
280
|
+
"content-type": "application/json"
|
|
281
|
+
},
|
|
282
|
+
body: JSON.stringify(body),
|
|
283
|
+
signal: AbortSignal.timeout(3e4)
|
|
284
|
+
});
|
|
285
|
+
const data = await res.json().catch(() => null);
|
|
286
|
+
if (res.ok || res.status === 207) return data;
|
|
287
|
+
if (/unknown endpoint/.test(data?.error ?? "")) throw new Error(`the running \`${NAME} dev\` is older than 0.31 and cannot resolve all - restart it, then run this again`);
|
|
288
|
+
if (res.status < 500) return { error: data?.error ?? `dev answered ${res.status}` };
|
|
289
|
+
last = data?.error ?? `dev answered ${res.status}`;
|
|
290
|
+
} catch (err) {
|
|
291
|
+
if (err.message.includes("older than 0.31")) throw err;
|
|
292
|
+
last = err.message;
|
|
293
|
+
}
|
|
294
|
+
throw new Error(`\`${NAME} dev\` is running but did not answer (${last}) - run it again (what it already did stays done)`);
|
|
295
|
+
};
|
|
296
|
+
const resolveUndo = async (root, op) => {
|
|
297
|
+
const ca = await import("./comment-actions-Bxf9Ld4g.mjs");
|
|
298
|
+
const u = readDevInfo(root) ? await viaDev(root, "undo", { op }) : ca.undoResolveAll(root, op);
|
|
299
|
+
if ("error" in u) throw new Error(u.error);
|
|
300
|
+
console.log(` ${ca.undoSummary(u)}`);
|
|
301
|
+
if (u.reopened.length) await pushIfConnected(root);
|
|
302
|
+
if (u.failed.length) process.exitCode = 1;
|
|
303
|
+
};
|
|
229
304
|
/** `comments new --thread <id>`: one thread per topic - a follow-up joins the open thread, as
|
|
230
305
|
* Marver, and asks unless --fyi. A collaborator's thread is answered with `comments reply`, which
|
|
231
306
|
* keeps its voice and sync rules. */
|