@marver-design/marver 0.26.0 → 0.26.1
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 +54 -0
- package/README.md +2 -2
- package/dist/{anchor-check-Dg5xpNnU.mjs → anchor-check-l-ny3UzH.mjs} +1 -1
- package/dist/{audio-CmSRYFEs.mjs → audio-Dw1lfMdb.mjs} +14 -0
- package/dist/{bake-DtVlm0_F.mjs → bake-C-awKgLA.mjs} +1 -1
- package/dist/{build-C_gUgcdC.mjs → build-BDRiO_mP.mjs} +3 -3
- package/dist/{capture-CrqvU_jh.mjs → capture-vadKjuCo.mjs} +2 -1
- package/dist/cli.mjs +6 -6
- package/dist/{daemon-DZo6o3rU.mjs → daemon-DL6Fwq6D.mjs} +394 -270
- package/dist/{dev-_Nlsc6v9.mjs → dev-Bw_qYWWq.mjs} +24 -11
- package/dist/{marks-NQi0wZJ4.mjs → marks-DyWMv_Z1.mjs} +1 -1
- package/dist/perf-C75MZ73h.mjs +167 -0
- package/dist/perf-jam-BU3TVrZu.mjs +239 -0
- package/dist/{plugin-CTD0rydA.mjs → plugin-DkGmZs_r.mjs} +42 -22
- package/dist/{poster-ChjXGTS5.mjs → poster-BdtSKMDm.mjs} +2 -1
- package/dist/{publish-bakes-CEP_2NRc.mjs → publish-bakes-9RzRToXV.mjs} +2 -2
- package/dist/{queue-BuiCKSX1.mjs → queue-29ok5_eZ.mjs} +2 -2
- package/dist/{session-qZWKt_VA.mjs → session-BAaJsK5c.mjs} +1 -1
- package/dist/{shot-DqcxJibP.mjs → shot-DQeR_Pfn.mjs} +337 -19
- package/dist/shot-XQV7HC9A.mjs +139 -0
- package/dist/speech-worker.mjs +40 -5
- package/docs/jam-session.md +24 -7
- package/docs/live-jam.md +8 -0
- package/package.json +1 -1
- package/src/client/frame-host/inspect.js +8 -3
- package/src/client/frame-host/keys.js +6 -2
- package/src/client/shell/App.tsx +8 -4
- package/src/client/shell/JamSurface.tsx +9 -3
- package/src/client/shell/Play.tsx +11 -7
- package/src/client/shell/Toolbar.tsx +5 -4
- package/src/client/shell/canvas/FrameNode.tsx +3 -2
- package/src/client/shell/icons.tsx +2 -0
- package/src/client/shell/jam-capture.ts +77 -11
- package/src/client/shell/jam-keys.ts +47 -18
- package/src/client/shell/jam-lane.tsx +46 -5
- package/src/client/shell/jam-panel.tsx +63 -13
- package/src/client/shell/jam-state.ts +48 -6
- package/src/client/shell/jam-surface-parts.tsx +10 -6
- package/src/client/shell/store.ts +14 -5
- package/src/client/shell/styles.css +28 -8
- package/src/client/stage/main.tsx +2 -0
- package/templates/instructions/jam.md +5 -3
- package/dist/perf-D6VmmJ2q.mjs +0 -68
- package/dist/shot-CNbHoZ6H.mjs +0 -86
|
@@ -5,9 +5,10 @@ import { a as readLog, t as appendEvents } from "./comments-0BSbb04K.mjs";
|
|
|
5
5
|
import { n as localProfile } from "./profile-WU9qcbIo.mjs";
|
|
6
6
|
import { r as uncheckedAnchor } from "./anchor-5H1vnoLu.mjs";
|
|
7
7
|
import { i as record, t as has } from "./ledger-D54iROST.mjs";
|
|
8
|
-
import { _ as packetPath, a as checkRecord, c as firstPoint, d as picturePath, f as readCapture, g as goalText, h as buildPacket, n as captureFrames, o as continues, p as storeCapture, r as captureWords, t as CAPTURE_ID, v as parseAgentText, x as sharedFile, y as parseMembers } from "./capture-
|
|
9
|
-
import { a as recordFile, c as storeWrapup, i as readWrapup, n as buildWrapup, o as recordPathProblem, r as moreOf, t as SESSION_ID } from "./session-
|
|
10
|
-
import { act, addCapture, addWrapup, answeredSince, beginStep, captureComment, captureIntact, conflictStep, createQueue, ctxFor, endSession, endStep, fail, form, looksGood, moreWrapup, n as releaseLock, payloadKey, pending, prune, redelivering, sameComment, settle, startSession, stillOwned, t as acquireLock, textOf, undelivered, wrapupIntact, wrapupOf } from "./queue-
|
|
8
|
+
import { _ as packetPath, a as checkRecord, c as firstPoint, d as picturePath, f as readCapture, g as goalText, h as buildPacket, n as captureFrames, o as continues, p as storeCapture, r as captureWords, t as CAPTURE_ID, v as parseAgentText, x as sharedFile, y as parseMembers } from "./capture-vadKjuCo.mjs";
|
|
9
|
+
import { a as recordFile, c as storeWrapup, i as readWrapup, n as buildWrapup, o as recordPathProblem, r as moreOf, t as SESSION_ID } from "./session-BAaJsK5c.mjs";
|
|
10
|
+
import { act, addCapture, addWrapup, answeredSince, beginStep, captureComment, captureIntact, conflictStep, createQueue, ctxFor, endSession, endStep, fail, form, looksGood, moreWrapup, n as releaseLock, payloadKey, pending, prune, redelivering, sameComment, settle, startSession, stillOwned, t as acquireLock, textOf, undelivered, wrapupIntact, wrapupOf } from "./queue-29ok5_eZ.mjs";
|
|
11
|
+
import { t as logJam } from "./perf-jam-BU3TVrZu.mjs";
|
|
11
12
|
import { jamReservations, restoreHolds } from "./reserve-BURNQ2Y3.mjs";
|
|
12
13
|
import { jamLive } from "./live-Cgzsicwi.mjs";
|
|
13
14
|
import { lstatSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, rmSync, statSync, watch, writeFileSync } from "node:fs";
|
|
@@ -939,6 +940,28 @@ function createJam(root, cfg, adapter, log = () => {}, hooks = {}) {
|
|
|
939
940
|
* nothing when the agent has no namer, the capture has no words, or the call fails (its first words stay). */
|
|
940
941
|
const naming = /* @__PURE__ */ new Set();
|
|
941
942
|
let namerDir;
|
|
943
|
+
const queuedSince = /* @__PURE__ */ new Map();
|
|
944
|
+
const atBoot = /* @__PURE__ */ new Set();
|
|
945
|
+
let scanned = false;
|
|
946
|
+
const noteQueued = () => {
|
|
947
|
+
try {
|
|
948
|
+
const now = performance.now();
|
|
949
|
+
const queued = /* @__PURE__ */ new Set();
|
|
950
|
+
for (const c of q.j.cards) if (c.state === "queued") {
|
|
951
|
+
queued.add(c.id);
|
|
952
|
+
if (!queuedSince.has(c.id)) {
|
|
953
|
+
queuedSince.set(c.id, now);
|
|
954
|
+
if (!scanned) atBoot.add(c.id);
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
scanned = true;
|
|
958
|
+
for (const k of [...queuedSince.keys()]) if (!queued.has(k)) {
|
|
959
|
+
queuedSince.delete(k);
|
|
960
|
+
atBoot.delete(k);
|
|
961
|
+
}
|
|
962
|
+
} catch {}
|
|
963
|
+
};
|
|
964
|
+
const batchWaits = /* @__PURE__ */ new Map();
|
|
942
965
|
const nameCapture = (id) => {
|
|
943
966
|
const c0 = q.j.cards.find((x) => x.id === id);
|
|
944
967
|
if (!adapter.namerArgs || cfg.names === false || !c0 || c0.kind !== "capture" || c0.name || c0.autoName || naming.has(id)) return;
|
|
@@ -952,6 +975,18 @@ function createJam(root, cfg, adapter, log = () => {}, hooks = {}) {
|
|
|
952
975
|
let child;
|
|
953
976
|
namerDir ??= mkdtempSync(join(tmpdir(), "marver-namer-"));
|
|
954
977
|
const cwd = namerDir;
|
|
978
|
+
const t0 = performance.now();
|
|
979
|
+
let named = false;
|
|
980
|
+
const timed = (ok) => {
|
|
981
|
+
if (named) return;
|
|
982
|
+
named = true;
|
|
983
|
+
logJam(root, {
|
|
984
|
+
kind: "name",
|
|
985
|
+
capture: id,
|
|
986
|
+
ms: performance.now() - t0,
|
|
987
|
+
ok
|
|
988
|
+
});
|
|
989
|
+
};
|
|
955
990
|
try {
|
|
956
991
|
child = spawn(cmd, args, {
|
|
957
992
|
cwd,
|
|
@@ -981,12 +1016,17 @@ function createJam(root, cfg, adapter, log = () => {}, hooks = {}) {
|
|
|
981
1016
|
child.on("error", () => {
|
|
982
1017
|
clearTimeout(to);
|
|
983
1018
|
naming.delete(id);
|
|
1019
|
+
timed(false);
|
|
984
1020
|
});
|
|
985
1021
|
child.on("close", (code) => {
|
|
986
1022
|
clearTimeout(to);
|
|
987
1023
|
naming.delete(id);
|
|
988
|
-
if (stopped || code !== 0)
|
|
1024
|
+
if (stopped || code !== 0) {
|
|
1025
|
+
if (!stopped) timed(false);
|
|
1026
|
+
return;
|
|
1027
|
+
}
|
|
989
1028
|
const name = (out.split("\n").map((l) => l.trim()).find(Boolean) ?? "").replace(/^["'“”‘’`*#\s-]+|["'“”‘’`*.\s]+$/g, "").replace(/\s+/g, " ").slice(0, 60).trim();
|
|
1029
|
+
timed(!!name);
|
|
990
1030
|
if (!name) return;
|
|
991
1031
|
q.lock((j) => {
|
|
992
1032
|
const c = j.cards.find((x) => x.id === id);
|
|
@@ -1099,6 +1139,7 @@ function createJam(root, cfg, adapter, log = () => {}, hooks = {}) {
|
|
|
1099
1139
|
jamReservations.settling = !ready || delivering.size > 0;
|
|
1100
1140
|
};
|
|
1101
1141
|
const queueChanged = () => {
|
|
1142
|
+
noteQueued();
|
|
1102
1143
|
try {
|
|
1103
1144
|
hooks.queue?.();
|
|
1104
1145
|
} catch {}
|
|
@@ -1193,295 +1234,342 @@ function createJam(root, cfg, adapter, log = () => {}, hooks = {}) {
|
|
|
1193
1234
|
log(` jam: replied ${replies} of ${b.members.length}${b.model ? ` (${b.model})` : ""}${repinned ? ` · re-pinned ${repinned}` : ""}`);
|
|
1194
1235
|
};
|
|
1195
1236
|
const runBatch = async (b) => {
|
|
1196
|
-
const
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
const
|
|
1200
|
-
if (
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1237
|
+
const timing = { agentMs: [] };
|
|
1238
|
+
let timed = false;
|
|
1239
|
+
const members0 = [...b.members];
|
|
1240
|
+
const timeRun = (failure) => {
|
|
1241
|
+
if (timed) return;
|
|
1242
|
+
timed = true;
|
|
1243
|
+
const waits = batchWaits.get(b.batchId);
|
|
1244
|
+
batchWaits.delete(b.batchId);
|
|
1245
|
+
logJam(root, {
|
|
1246
|
+
kind: "run",
|
|
1247
|
+
batch: b.batchId,
|
|
1248
|
+
attempts: b.attempts,
|
|
1249
|
+
...timing,
|
|
1250
|
+
...failure ? { failure } : {},
|
|
1251
|
+
members: members0.map((m) => {
|
|
1252
|
+
const c = q.j.cards.find((x) => x.id === m.card);
|
|
1253
|
+
return {
|
|
1254
|
+
kind: c?.kind,
|
|
1255
|
+
waitMs: waits?.get(m.card),
|
|
1256
|
+
outcome: failure || !b.members.includes(m) ? "failed" : c?.state
|
|
1257
|
+
};
|
|
1258
|
+
})
|
|
1204
1259
|
});
|
|
1205
1260
|
};
|
|
1206
|
-
const unwatch = hooks.watchHolds?.(() => {
|
|
1207
|
-
crowded = true;
|
|
1208
|
-
markCrowded(b);
|
|
1209
|
-
}) ?? (() => {});
|
|
1210
|
-
for (const o of runningBatches.values()) if (o !== b) markCrowded(o);
|
|
1211
|
-
const bad = [];
|
|
1212
|
-
const logs = /* @__PURE__ */ new Map();
|
|
1213
|
-
const threadsOf = (board) => {
|
|
1214
|
-
let t = logs.get(board);
|
|
1215
|
-
if (!t) logs.set(board, t = replay(readLog(commentsDir, board)));
|
|
1216
|
-
return t;
|
|
1217
|
-
};
|
|
1218
|
-
const members = [];
|
|
1219
|
-
let disk = null;
|
|
1220
1261
|
try {
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1262
|
+
const myStart = ++batchStarts;
|
|
1263
|
+
const aloneAtStart = [...runningBatches.keys()].every((k) => k === b.batchId);
|
|
1264
|
+
let crowded = !!hooks.anyHold?.();
|
|
1265
|
+
const markCrowded = (x) => {
|
|
1266
|
+
if (x.crowded) return;
|
|
1267
|
+
q.lock(() => {
|
|
1268
|
+
x.crowded = true;
|
|
1269
|
+
q.persist();
|
|
1270
|
+
});
|
|
1271
|
+
};
|
|
1272
|
+
const unwatch = hooks.watchHolds?.(() => {
|
|
1273
|
+
crowded = true;
|
|
1274
|
+
markCrowded(b);
|
|
1275
|
+
}) ?? (() => {});
|
|
1276
|
+
for (const o of runningBatches.values()) if (o !== b) markCrowded(o);
|
|
1277
|
+
const bad = [];
|
|
1278
|
+
const logs = /* @__PURE__ */ new Map();
|
|
1279
|
+
const threadsOf = (board) => {
|
|
1280
|
+
let t = logs.get(board);
|
|
1281
|
+
if (!t) logs.set(board, t = replay(readLog(commentsDir, board)));
|
|
1282
|
+
return t;
|
|
1283
|
+
};
|
|
1284
|
+
const members = [];
|
|
1285
|
+
let disk = null;
|
|
1286
|
+
try {
|
|
1287
|
+
disk = JSON.parse(readFileSync(join(root, packetPath(b.batchId)), "utf8"));
|
|
1288
|
+
} catch {
|
|
1289
|
+
disk = null;
|
|
1231
1290
|
}
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
const
|
|
1235
|
-
if (!
|
|
1291
|
+
for (const m of b.members) {
|
|
1292
|
+
const c = q.j.cards.find((x) => x.id === m.card);
|
|
1293
|
+
const kept = m.brief ?? (c && c.kind !== "wrapup" ? disk?.members.find((x) => x.card === m.card && x.id === m.id)?.brief : void 0);
|
|
1294
|
+
if (!c || !kept) {
|
|
1236
1295
|
bad.push(m.card);
|
|
1237
1296
|
continue;
|
|
1238
1297
|
}
|
|
1239
|
-
brief =
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
};
|
|
1246
|
-
} else if (brief.wrapup) {
|
|
1247
|
-
const { wrapup: _w, ...rest } = brief;
|
|
1248
|
-
brief = rest;
|
|
1249
|
-
}
|
|
1250
|
-
const t = c.thread ? threadsOf(m.board).find((x) => x.id === c.thread) : void 0;
|
|
1251
|
-
members.push({
|
|
1252
|
-
id: m.id,
|
|
1253
|
-
card: c.id,
|
|
1254
|
-
kind: c.kind,
|
|
1255
|
-
board: m.board,
|
|
1256
|
-
...c.thread ? { thread: c.thread } : {},
|
|
1257
|
-
frames: c.frames,
|
|
1258
|
-
...t?.anchor !== void 0 ? { anchor: t.anchor } : {},
|
|
1259
|
-
brief
|
|
1260
|
-
});
|
|
1261
|
-
}
|
|
1262
|
-
if (bad.length) {
|
|
1263
|
-
await q.lock((j) => {
|
|
1264
|
-
for (const id of bad) {
|
|
1265
|
-
const c = j.cards.find((x) => x.id === id);
|
|
1266
|
-
if (c && c.state === "working") {
|
|
1267
|
-
c.state = "failed";
|
|
1268
|
-
c.note = c.kind === "wrapup" ? "the session record changed after it was written - write it again" : "interrupted - Retry";
|
|
1269
|
-
c.rev += 1;
|
|
1270
|
-
c.at = Date.now();
|
|
1298
|
+
let brief = kept;
|
|
1299
|
+
if (c.kind === "wrapup") {
|
|
1300
|
+
const w = readWrapup(root, wrapupOf(c));
|
|
1301
|
+
if (!w || !wrapupIntact(q.ctx(), c) || recordPathProblem(root, w.wrapup.file)) {
|
|
1302
|
+
bad.push(m.card);
|
|
1303
|
+
continue;
|
|
1271
1304
|
}
|
|
1305
|
+
brief = {
|
|
1306
|
+
...brief,
|
|
1307
|
+
wrapup: {
|
|
1308
|
+
content: w.wrapup,
|
|
1309
|
+
hash: w.hash
|
|
1310
|
+
}
|
|
1311
|
+
};
|
|
1312
|
+
} else if (brief.wrapup) {
|
|
1313
|
+
const { wrapup: _w, ...rest } = brief;
|
|
1314
|
+
brief = rest;
|
|
1272
1315
|
}
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1316
|
+
const t = c.thread ? threadsOf(m.board).find((x) => x.id === c.thread) : void 0;
|
|
1317
|
+
members.push({
|
|
1318
|
+
id: m.id,
|
|
1319
|
+
card: c.id,
|
|
1320
|
+
kind: c.kind,
|
|
1321
|
+
board: m.board,
|
|
1322
|
+
...c.thread ? { thread: c.thread } : {},
|
|
1323
|
+
frames: c.frames,
|
|
1324
|
+
...t?.anchor !== void 0 ? { anchor: t.anchor } : {},
|
|
1325
|
+
brief
|
|
1326
|
+
});
|
|
1327
|
+
}
|
|
1328
|
+
if (bad.length) {
|
|
1277
1329
|
await q.lock((j) => {
|
|
1278
|
-
const
|
|
1279
|
-
|
|
1330
|
+
for (const id of bad) {
|
|
1331
|
+
const c = j.cards.find((x) => x.id === id);
|
|
1332
|
+
if (c && c.state === "working") {
|
|
1333
|
+
c.state = "failed";
|
|
1334
|
+
c.note = c.kind === "wrapup" ? "the session record changed after it was written - write it again" : "interrupted - Retry";
|
|
1335
|
+
c.rev += 1;
|
|
1336
|
+
c.at = Date.now();
|
|
1337
|
+
}
|
|
1338
|
+
}
|
|
1280
1339
|
q.persist();
|
|
1281
1340
|
});
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
lit.add(f);
|
|
1341
|
+
b.members = b.members.filter((m) => !bad.includes(m.card));
|
|
1342
|
+
if (!b.members.length) {
|
|
1343
|
+
await q.lock((j) => {
|
|
1344
|
+
const x = j.batches.find((y) => y.batchId === b.batchId);
|
|
1345
|
+
if (x) x.state = "failed";
|
|
1346
|
+
q.persist();
|
|
1347
|
+
});
|
|
1348
|
+
queueChanged();
|
|
1349
|
+
timeRun("changed");
|
|
1350
|
+
return;
|
|
1351
|
+
}
|
|
1294
1352
|
}
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
lit
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
const one0 = b.members.length === 1 ? q.j.cards.find((c) => c.id === b.members[0].card) : void 0;
|
|
1311
|
-
const discover = async () => {
|
|
1312
|
-
if (one0?.kind !== "capture" || b.crowded || crowded || !aloneAtStart || batchStarts !== myStart || hooks.anyHold?.()) return;
|
|
1313
|
-
const found = newFrames(new Set(b.before ?? []), b).filter((f) => !(b.created ?? []).includes(f));
|
|
1314
|
-
if (!found.length) return;
|
|
1353
|
+
const packet = buildPacket(b.batchId, members, b.frames, b.exclusive ? [...new Set(cards0(b).flatMap((c) => c.exclusive ?? []))] : void 0);
|
|
1354
|
+
writeFileSync(join(root, packetPath(b.batchId)), JSON.stringify(packet, null, 1), { mode: 384 });
|
|
1355
|
+
const cards = () => b.members.map((m) => q.j.cards.find((c) => c.id === m.card)).filter((c) => !!c);
|
|
1356
|
+
const lit = /* @__PURE__ */ new Set();
|
|
1357
|
+
const light = (f) => {
|
|
1358
|
+
if (f && !lit.has(f)) {
|
|
1359
|
+
hooks.work?.(f, true);
|
|
1360
|
+
lit.add(f);
|
|
1361
|
+
}
|
|
1362
|
+
};
|
|
1363
|
+
const clearGlow = () => {
|
|
1364
|
+
for (const f of lit) hooks.work?.(f, false);
|
|
1365
|
+
lit.clear();
|
|
1366
|
+
};
|
|
1367
|
+
const startMtimes = sceneFrameMtimes(root);
|
|
1315
1368
|
await q.lock(() => {
|
|
1316
|
-
|
|
1317
|
-
b.
|
|
1369
|
+
const made = new Set(b.created ?? []);
|
|
1370
|
+
b.before = [.../* @__PURE__ */ new Set([...b.before ?? [], ...[...startMtimes.keys()].filter((f) => !made.has(f))])];
|
|
1318
1371
|
q.persist();
|
|
1319
1372
|
});
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
const sharedBefore = b.exclusive ? null : sharedMtimes(root);
|
|
1323
|
-
const touched = /* @__PURE__ */ new Set();
|
|
1324
|
-
for (const f of b.frames) light(f);
|
|
1325
|
-
const capturing = cards().some((c) => !!c.capture);
|
|
1326
|
-
const theme = (() => {
|
|
1327
|
-
const c = cards().find((x) => x.capture);
|
|
1328
|
-
return c && readCapture(root, c.capture)?.record.view.theme || "light";
|
|
1329
|
-
})();
|
|
1330
|
-
const sizes = Object.assign({}, ...cards().flatMap((c) => c.capture ? [readCapture(root, c.capture)?.record.sizes ?? {}] : []));
|
|
1331
|
-
const shoot = async (when) => {
|
|
1332
|
-
if (!capturing || !hooks.shoot) return;
|
|
1333
|
-
const shots = b.shots ?? b.frames.map((frame) => ({ frame }));
|
|
1334
|
-
for (const s of shots) {
|
|
1335
|
-
if (stopped) return;
|
|
1336
|
-
if (s.new) continue;
|
|
1337
|
-
const id = await hooks.shoot(s.frame, theme, { batch: b.batchId }, sizes[s.frame]).catch(() => null);
|
|
1338
|
-
if (id) s[when] = id;
|
|
1339
|
-
}
|
|
1340
|
-
if (when === "after") for (const s of shots) if (s.before && s.after && samePicture(s.before, s.after)) s.same = true;
|
|
1341
|
-
else delete s.same;
|
|
1342
|
-
await q.lock(() => {
|
|
1343
|
-
b.shots = shots;
|
|
1373
|
+
if (crowded || !aloneAtStart) await q.lock(() => {
|
|
1374
|
+
b.crowded = true;
|
|
1344
1375
|
q.persist();
|
|
1345
1376
|
});
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
for (const [id, mt] of sceneFrameMtimes(root)) if (startMtimes.get(id) !== mt) touched.add(id);
|
|
1352
|
-
for (const id of touched) light(id);
|
|
1353
|
-
for (const f of lit) hooks.work?.(f, true);
|
|
1354
|
-
};
|
|
1355
|
-
let early;
|
|
1356
|
-
let run = {
|
|
1357
|
-
reply: "",
|
|
1358
|
-
asks: false,
|
|
1359
|
-
ok: false,
|
|
1360
|
-
reanchors: []
|
|
1361
|
-
};
|
|
1362
|
-
try {
|
|
1363
|
-
while (!stopped && b.attempts < MAX_ATTEMPTS) {
|
|
1377
|
+
const one0 = b.members.length === 1 ? q.j.cards.find((c) => c.id === b.members[0].card) : void 0;
|
|
1378
|
+
const discover = async () => {
|
|
1379
|
+
if (one0?.kind !== "capture" || b.crowded || crowded || !aloneAtStart || batchStarts !== myStart || hooks.anyHold?.()) return;
|
|
1380
|
+
const found = newFrames(new Set(b.before ?? []), b).filter((f) => !(b.created ?? []).includes(f));
|
|
1381
|
+
if (!found.length) return;
|
|
1364
1382
|
await q.lock(() => {
|
|
1365
|
-
b.
|
|
1366
|
-
b.
|
|
1383
|
+
b.created = [...b.created ?? [], ...found];
|
|
1384
|
+
b.frames = [.../* @__PURE__ */ new Set([...b.frames, ...b.created])];
|
|
1367
1385
|
q.persist();
|
|
1368
1386
|
});
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1387
|
+
reserve();
|
|
1388
|
+
};
|
|
1389
|
+
const sharedBefore = b.exclusive ? null : sharedMtimes(root);
|
|
1390
|
+
const touched = /* @__PURE__ */ new Set();
|
|
1391
|
+
for (const f of b.frames) light(f);
|
|
1392
|
+
const capturing = cards().some((c) => !!c.capture);
|
|
1393
|
+
const theme = (() => {
|
|
1394
|
+
const c = cards().find((x) => x.capture);
|
|
1395
|
+
return c && readCapture(root, c.capture)?.record.view.theme || "light";
|
|
1396
|
+
})();
|
|
1397
|
+
const sizes = Object.assign({}, ...cards().flatMap((c) => c.capture ? [readCapture(root, c.capture)?.record.sizes ?? {}] : []));
|
|
1398
|
+
const shoot = async (when) => {
|
|
1399
|
+
if (!capturing || !hooks.shoot) return;
|
|
1400
|
+
const shots = b.shots ?? b.frames.map((frame) => ({ frame }));
|
|
1401
|
+
for (const s of shots) {
|
|
1402
|
+
if (stopped) return;
|
|
1403
|
+
if (s.new) continue;
|
|
1404
|
+
const id = await hooks.shoot(s.frame, theme, { batch: b.batchId }, sizes[s.frame]).catch(() => null);
|
|
1405
|
+
if (id) s[when] = id;
|
|
1380
1406
|
}
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1407
|
+
if (when === "after") for (const s of shots) if (s.before && s.after && samePicture(s.before, s.after)) s.same = true;
|
|
1408
|
+
else delete s.same;
|
|
1409
|
+
await q.lock(() => {
|
|
1410
|
+
b.shots = shots;
|
|
1411
|
+
q.persist();
|
|
1412
|
+
});
|
|
1413
|
+
};
|
|
1414
|
+
if (!b.shots?.some((s) => s.before)) {
|
|
1415
|
+
const t = performance.now();
|
|
1416
|
+
await shoot("before");
|
|
1417
|
+
if (capturing) timing.beforeMs = performance.now() - t;
|
|
1418
|
+
}
|
|
1419
|
+
const followWork = () => {
|
|
1420
|
+
if (hooks.anyHold?.()) crowded = true;
|
|
1421
|
+
discover();
|
|
1422
|
+
for (const [id, mt] of sceneFrameMtimes(root)) if (startMtimes.get(id) !== mt) touched.add(id);
|
|
1423
|
+
for (const id of touched) light(id);
|
|
1424
|
+
for (const f of lit) hooks.work?.(f, true);
|
|
1425
|
+
};
|
|
1426
|
+
let early;
|
|
1427
|
+
let run = {
|
|
1428
|
+
reply: "",
|
|
1429
|
+
asks: false,
|
|
1430
|
+
ok: false,
|
|
1431
|
+
reanchors: []
|
|
1432
|
+
};
|
|
1433
|
+
try {
|
|
1434
|
+
while (!stopped && b.attempts < MAX_ATTEMPTS) {
|
|
1435
|
+
await q.lock(() => {
|
|
1436
|
+
b.attempts += 1;
|
|
1437
|
+
b.leaseUntil = Date.now() + LEASE_MS;
|
|
1388
1438
|
q.persist();
|
|
1389
|
-
}
|
|
1390
|
-
|
|
1391
|
-
const
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1439
|
+
});
|
|
1440
|
+
for (const m of packet.members) if (m.kind === "wrapup") {
|
|
1441
|
+
const c = q.j.cards.find((x) => x.id === m.card);
|
|
1442
|
+
const w = c && readWrapup(root, wrapupOf(c));
|
|
1443
|
+
if (!c || !w || !wrapupIntact(q.ctx(), c) || recordPathProblem(root, w.wrapup.file)) throw new Error("the session record changed after it was written - write it again");
|
|
1444
|
+
m.brief = {
|
|
1445
|
+
...m.brief,
|
|
1446
|
+
wrapup: {
|
|
1447
|
+
content: w.wrapup,
|
|
1448
|
+
hash: w.hash
|
|
1449
|
+
}
|
|
1397
1450
|
};
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1451
|
+
}
|
|
1452
|
+
writeFileSync(join(root, packetPath(b.batchId)), JSON.stringify(packet, null, 1), { mode: 384 });
|
|
1453
|
+
const beat = setInterval(followWork, 2e3);
|
|
1454
|
+
beat.unref?.();
|
|
1455
|
+
const tAgent = performance.now();
|
|
1456
|
+
try {
|
|
1457
|
+
const one = b.members.length === 1 ? cards()[0] : void 0;
|
|
1458
|
+
run = await runAgent(goalText(packet, cfg.subagents && adapter.supportsSubagents), (pid) => {
|
|
1459
|
+
b.pgid = pid;
|
|
1460
|
+
q.persist();
|
|
1461
|
+
}, one?.thread ? (text, asks, model) => {
|
|
1462
|
+
if (stopped) return;
|
|
1463
|
+
const p = postReply(b, one, "m1", text, asks, model, "early");
|
|
1464
|
+
early = {
|
|
1465
|
+
body: text,
|
|
1466
|
+
asks,
|
|
1467
|
+
commentId: p.commentId,
|
|
1468
|
+
ts: p.ts
|
|
1469
|
+
};
|
|
1470
|
+
hooks.changed?.(one.board);
|
|
1471
|
+
} : void 0);
|
|
1472
|
+
} finally {
|
|
1473
|
+
clearInterval(beat);
|
|
1474
|
+
timing.agentMs.push(performance.now() - tAgent);
|
|
1475
|
+
}
|
|
1476
|
+
logRun(b.batchId, run.raw);
|
|
1477
|
+
if (run.ok) break;
|
|
1478
|
+
}
|
|
1479
|
+
if (stopped) return;
|
|
1480
|
+
if (!run.ok) {
|
|
1481
|
+
await discover();
|
|
1482
|
+
await q.lock((j) => {
|
|
1483
|
+
ownCreated(j, b);
|
|
1484
|
+
settled(fail(j, b, "the agent could not finish - its run log is in design/.local/jam-logs"));
|
|
1485
|
+
q.persist();
|
|
1486
|
+
});
|
|
1487
|
+
queueChanged();
|
|
1488
|
+
log(` jam: gave up on a batch of ${b.members.length} after ${b.attempts} attempts`);
|
|
1489
|
+
timeRun("agent");
|
|
1490
|
+
return;
|
|
1491
|
+
}
|
|
1492
|
+
if (!aloneAtStart || batchStarts !== myStart || crowded || hooks.anyHold?.()) {
|
|
1493
|
+
if (!b.crowded) await q.lock(() => {
|
|
1494
|
+
b.crowded = true;
|
|
1495
|
+
q.persist();
|
|
1496
|
+
});
|
|
1402
1497
|
}
|
|
1403
|
-
logRun(b.batchId, run.raw);
|
|
1404
|
-
if (run.ok) break;
|
|
1405
|
-
}
|
|
1406
|
-
if (stopped) return;
|
|
1407
|
-
if (!run.ok) {
|
|
1408
1498
|
await discover();
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
return;
|
|
1417
|
-
}
|
|
1418
|
-
if (!aloneAtStart || batchStarts !== myStart || crowded || hooks.anyHold?.()) {
|
|
1419
|
-
if (!b.crowded) await q.lock(() => {
|
|
1420
|
-
b.crowded = true;
|
|
1499
|
+
const tAfter = performance.now();
|
|
1500
|
+
await shoot("after");
|
|
1501
|
+
const one = b.members.length === 1 ? cards()[0] : void 0;
|
|
1502
|
+
const created = capturing && one?.kind === "capture" ? liveCreated(b) : [];
|
|
1503
|
+
let hosts = [];
|
|
1504
|
+
if (!created.length && b.shots?.some((x) => x.new)) await q.lock(() => {
|
|
1505
|
+
b.shots = (b.shots ?? []).filter((x) => !x.new);
|
|
1421
1506
|
q.persist();
|
|
1422
1507
|
});
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
if (
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1508
|
+
if (created.length && hooks.shoot) {
|
|
1509
|
+
const shots = (b.shots ?? []).filter((x) => !x.new);
|
|
1510
|
+
for (const f of created.slice(0, 3)) {
|
|
1511
|
+
if (stopped) return;
|
|
1512
|
+
if (shots.some((x) => x.frame === f)) continue;
|
|
1513
|
+
const id = await hooks.shoot(f, theme, { batch: b.batchId }, sizeOnBoard(f, one.board)).catch(() => null);
|
|
1514
|
+
shots.push({
|
|
1515
|
+
frame: f,
|
|
1516
|
+
...id ? { after: id } : {},
|
|
1517
|
+
new: true
|
|
1518
|
+
});
|
|
1519
|
+
}
|
|
1520
|
+
const own = shots.filter((x) => !x.new && one.frames.includes(x.frame));
|
|
1521
|
+
if (one.thread && own.every((x) => x.same)) hosts = [{
|
|
1522
|
+
member: b.members[0].id,
|
|
1523
|
+
frame: created[0]
|
|
1524
|
+
}];
|
|
1525
|
+
await q.lock(() => {
|
|
1526
|
+
b.shots = shots;
|
|
1527
|
+
q.persist();
|
|
1443
1528
|
});
|
|
1444
1529
|
}
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1530
|
+
if (capturing) timing.afterMs = performance.now() - tAfter;
|
|
1531
|
+
const split = parseMembers(run.said ?? run.reply, b.members.map((m) => m.id));
|
|
1532
|
+
const changedShared = sharedBefore ? [...sharedMtimes(root)].filter(([f, mt]) => sharedBefore.get(f) !== mt).map(([f]) => f) : [];
|
|
1533
|
+
const results = {};
|
|
1534
|
+
for (const [id, r0] of Object.entries(split)) {
|
|
1535
|
+
let r = r0;
|
|
1536
|
+
if ("shared" in r) {
|
|
1537
|
+
const files = r.shared.map(realShared).filter((f) => !!f);
|
|
1538
|
+
r = files.length ? { shared: files } : { missing: true };
|
|
1539
|
+
}
|
|
1540
|
+
results[id] = "body" in r ? {
|
|
1541
|
+
body: r.body,
|
|
1542
|
+
asks: r.asks,
|
|
1543
|
+
...run.model ? { model: run.model } : {},
|
|
1544
|
+
reanchors: [],
|
|
1545
|
+
...changedShared.length ? { alsoChanged: changedShared } : {}
|
|
1546
|
+
} : r;
|
|
1547
|
+
}
|
|
1450
1548
|
await q.lock(() => {
|
|
1451
|
-
b.
|
|
1549
|
+
b.results = results;
|
|
1550
|
+
if (run.reanchors.length) b.reanchors = run.reanchors;
|
|
1551
|
+
if (hosts.length) b.hosts = hosts;
|
|
1552
|
+
if (early) b.early = early;
|
|
1553
|
+
if (run.model) b.model = run.model;
|
|
1452
1554
|
q.persist();
|
|
1453
1555
|
});
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
r = files.length ? { shared: files } : { missing: true };
|
|
1556
|
+
if (changedShared.length) log(` jam: also changed ${changedShared.map((f) => relative("design", f)).join(", ")}`);
|
|
1557
|
+
const tDeliver = performance.now();
|
|
1558
|
+
try {
|
|
1559
|
+
await deliver(b);
|
|
1560
|
+
} catch (err) {
|
|
1561
|
+
timing.deliverMs = performance.now() - tDeliver;
|
|
1562
|
+
timeRun("delivery");
|
|
1563
|
+
throw err;
|
|
1463
1564
|
}
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
...changedShared.length ? { alsoChanged: changedShared } : {}
|
|
1470
|
-
} : r;
|
|
1565
|
+
timing.deliverMs = performance.now() - tDeliver;
|
|
1566
|
+
timeRun();
|
|
1567
|
+
} finally {
|
|
1568
|
+
unwatch();
|
|
1569
|
+
clearGlow();
|
|
1471
1570
|
}
|
|
1472
|
-
await q.lock(() => {
|
|
1473
|
-
b.results = results;
|
|
1474
|
-
if (run.reanchors.length) b.reanchors = run.reanchors;
|
|
1475
|
-
if (hosts.length) b.hosts = hosts;
|
|
1476
|
-
if (early) b.early = early;
|
|
1477
|
-
if (run.model) b.model = run.model;
|
|
1478
|
-
q.persist();
|
|
1479
|
-
});
|
|
1480
|
-
if (changedShared.length) log(` jam: also changed ${changedShared.map((f) => relative("design", f)).join(", ")}`);
|
|
1481
|
-
await deliver(b);
|
|
1482
1571
|
} finally {
|
|
1483
|
-
|
|
1484
|
-
clearGlow();
|
|
1572
|
+
if (!stopped) timeRun("other");
|
|
1485
1573
|
}
|
|
1486
1574
|
};
|
|
1487
1575
|
/** Write a card's pending comment (once - an event already there must say the same, or the step
|
|
@@ -1702,6 +1790,7 @@ function createJam(root, cfg, adapter, log = () => {}, hooks = {}) {
|
|
|
1702
1790
|
launch(b);
|
|
1703
1791
|
}
|
|
1704
1792
|
const started = await q.lock((j, ctx) => {
|
|
1793
|
+
noteQueued();
|
|
1705
1794
|
const frames = new Set([...runningBatches.values()].flatMap((b) => b.frames));
|
|
1706
1795
|
const { batches, exclusiveWaiting } = form(j, ctx, {
|
|
1707
1796
|
free: Math.max(1, cfg.concurrency) - runningBatches.size,
|
|
@@ -1713,6 +1802,11 @@ function createJam(root, cfg, adapter, log = () => {}, hooks = {}) {
|
|
|
1713
1802
|
prune(j);
|
|
1714
1803
|
q.persist();
|
|
1715
1804
|
for (const b of batches) runningBatches.set(b.batchId, b);
|
|
1805
|
+
const now = performance.now();
|
|
1806
|
+
for (const b of batches) batchWaits.set(b.batchId, new Map(b.members.flatMap((m) => {
|
|
1807
|
+
const t = queuedSince.get(m.card);
|
|
1808
|
+
return t !== void 0 && !atBoot.has(m.card) ? [[m.card, now - t]] : [];
|
|
1809
|
+
})));
|
|
1716
1810
|
reserve(exclusiveWaiting);
|
|
1717
1811
|
for (const c of j.cards) {
|
|
1718
1812
|
if (c.state !== "queued") continue;
|
|
@@ -1769,9 +1863,24 @@ function createJam(root, cfg, adapter, log = () => {}, hooks = {}) {
|
|
|
1769
1863
|
const t = setTimeout(() => {
|
|
1770
1864
|
timers.delete(t);
|
|
1771
1865
|
if (stopped) return;
|
|
1772
|
-
|
|
1866
|
+
const tDeliver = performance.now();
|
|
1867
|
+
deliver(b).then(() => {
|
|
1868
|
+
logJam(root, {
|
|
1869
|
+
kind: "run",
|
|
1870
|
+
batch: b.batchId,
|
|
1871
|
+
redelivered: true,
|
|
1872
|
+
deliverMs: performance.now() - tDeliver
|
|
1873
|
+
});
|
|
1874
|
+
settleDelivery(b);
|
|
1875
|
+
}, async (err) => {
|
|
1773
1876
|
log(` jam: posting failed again - ${err.message}`);
|
|
1774
1877
|
if (n < 5) return redeliver(b, n + 1);
|
|
1878
|
+
logJam(root, {
|
|
1879
|
+
kind: "run",
|
|
1880
|
+
batch: b.batchId,
|
|
1881
|
+
redelivered: true,
|
|
1882
|
+
failure: "delivery"
|
|
1883
|
+
});
|
|
1775
1884
|
await q.lock((j) => {
|
|
1776
1885
|
settled(undelivered(j, b, "its replies could not be posted - Retry posts them"));
|
|
1777
1886
|
q.persist();
|
|
@@ -1935,20 +2044,35 @@ function createJam(root, cfg, adapter, log = () => {}, hooks = {}) {
|
|
|
1935
2044
|
redelivering(j, b);
|
|
1936
2045
|
q.persist();
|
|
1937
2046
|
});
|
|
1938
|
-
for (let n = 1;; n++)
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
2047
|
+
for (let n = 1;; n++) {
|
|
2048
|
+
const tDeliver = performance.now();
|
|
2049
|
+
try {
|
|
2050
|
+
await deliver(b);
|
|
2051
|
+
logJam(root, {
|
|
2052
|
+
kind: "run",
|
|
2053
|
+
batch: b.batchId,
|
|
2054
|
+
redelivered: true,
|
|
2055
|
+
deliverMs: performance.now() - tDeliver
|
|
1947
2056
|
});
|
|
1948
2057
|
break;
|
|
2058
|
+
} catch (err) {
|
|
2059
|
+
if (n >= 4 || stopped) {
|
|
2060
|
+
log(` jam: could not post a recovered batch - ${err.message}; its cards fail, Retry posts them`);
|
|
2061
|
+
logJam(root, {
|
|
2062
|
+
kind: "run",
|
|
2063
|
+
batch: b.batchId,
|
|
2064
|
+
redelivered: true,
|
|
2065
|
+
failure: "delivery"
|
|
2066
|
+
});
|
|
2067
|
+
await q.lock((j) => {
|
|
2068
|
+
settled(undelivered(j, b, "its replies could not be posted - Retry posts them"));
|
|
2069
|
+
q.persist();
|
|
2070
|
+
});
|
|
2071
|
+
break;
|
|
2072
|
+
}
|
|
2073
|
+
await nap(500 * 2 ** n);
|
|
2074
|
+
if (stopped) return;
|
|
1949
2075
|
}
|
|
1950
|
-
await nap(500 * 2 ** n);
|
|
1951
|
-
if (stopped) return;
|
|
1952
2076
|
}
|
|
1953
2077
|
runningBatches.delete(b.batchId);
|
|
1954
2078
|
}
|
|
@@ -2033,7 +2157,7 @@ function createJam(root, cfg, adapter, log = () => {}, hooks = {}) {
|
|
|
2033
2157
|
return structuredClone(c);
|
|
2034
2158
|
});
|
|
2035
2159
|
queueChanged();
|
|
2036
|
-
if (cfg.capture === "at-once" && card.state === "draft") return confirm(card.id, card.rev, "queued");
|
|
2160
|
+
if (cfg.capture === "at-once" && card.state === "draft" && !rec.context.interrupted) return confirm(card.id, card.rev, "queued");
|
|
2037
2161
|
return {
|
|
2038
2162
|
ok: true,
|
|
2039
2163
|
card
|