@leonidstern/labit 0.6.2 → 0.6.3-edge.3.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 +15 -0
- package/README.md +1 -1
- package/api/_schema.mjs +29 -0
- package/api/lab-comments.mjs +26 -10
- package/dist/{chunk-XZUZQFBJ.mjs → chunk-AVPXXSFF.mjs} +7 -1
- package/dist/{chunk-LNYMIFDQ.mjs → chunk-QTMKKULT.mjs} +1 -1
- package/dist/{commands-LAQNMF2X.mjs → commands-L2RJ7R5W.mjs} +19 -5
- package/dist/local.mjs +173 -58
- package/dist/{mcp-4UPGXLZR.mjs → mcp-CNZISCIA.mjs} +8 -5
- package/package.json +1 -1
- package/public/_lab/comments.js +14 -14
- package/skills/labit/SKILL.md +1 -1
package/dist/local.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
WRITE_SHORT,
|
|
5
5
|
parseArgs,
|
|
6
6
|
runningLabs
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-AVPXXSFF.mjs";
|
|
8
8
|
import {
|
|
9
9
|
AGENTS,
|
|
10
10
|
agentKind,
|
|
@@ -288,13 +288,29 @@ function place(p) {
|
|
|
288
288
|
return { html, id };
|
|
289
289
|
}
|
|
290
290
|
|
|
291
|
+
// api/_schema.mjs
|
|
292
|
+
var VERSION = 1;
|
|
293
|
+
var intentFromText = (text) => /^done\b/i.test(String(text ?? "").trim()) ? "done" : /^on it\b/i.test(String(text ?? "").trim()) ? "working" : void 0;
|
|
294
|
+
function upgrade(record) {
|
|
295
|
+
if (!record || typeof record !== "object" || (Number(record.v) || 0) >= VERSION) return record;
|
|
296
|
+
const c = { ...record, v: VERSION };
|
|
297
|
+
if (c.parent) {
|
|
298
|
+
if (c.resolved === false) delete c.resolved;
|
|
299
|
+
if (c.session && !c.intent) {
|
|
300
|
+
const intent = intentFromText(c.text);
|
|
301
|
+
if (intent) c.intent = intent;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
return c;
|
|
305
|
+
}
|
|
306
|
+
|
|
291
307
|
// local.mjs
|
|
292
308
|
var SELF_DIR = path3.dirname(fileURLToPath(import.meta.url));
|
|
293
309
|
var REPO = path3.basename(SELF_DIR) === "dist" ? path3.dirname(SELF_DIR) : SELF_DIR;
|
|
294
310
|
var ME = fileURLToPath(import.meta.url);
|
|
295
311
|
var CMD = REPO.split(path3.sep).includes("node_modules") ? "npx @leonidstern/labit" : `node ${ME}`;
|
|
296
|
-
var
|
|
297
|
-
var HELP = `labit ${
|
|
312
|
+
var VERSION2 = JSON.parse(fs3.readFileSync(path3.join(REPO, "package.json"), "utf8")).version;
|
|
313
|
+
var HELP = `labit ${VERSION2}: comment on local pages, your agent (Claude, Codex, Cursor\u2026) answers on the pins.
|
|
298
314
|
Run it as npx @leonidstern/labit \u2026, or node local.mjs \u2026 from a clone.
|
|
299
315
|
|
|
300
316
|
labit [--proxy [port]] [--port 4400] [--wifi] [--no-open] [folder]
|
|
@@ -335,18 +351,19 @@ For the agent, from the project (any folder under it):
|
|
|
335
351
|
wait left in the foreground holds the person's turn open and they can't say anything to you until it ends.
|
|
336
352
|
An agent that isn't told when a background command ends runs it in the foreground: wait --timeout 50, in a loop.
|
|
337
353
|
The page then says it talks to this session. With the page closed it keeps waiting, and ends after an hour of no page.
|
|
338
|
-
labit reply <id> "what you did" [--resolve] [--wait] [--page /path]
|
|
339
|
-
Answer on the pin. Use the id that wait printed (the number on the card works too, but shifts after a delete). --
|
|
354
|
+
labit reply <id> "what you did" [--done | --on-it | --question] [--resolve] [--wait] [--page /path]
|
|
355
|
+
Answer on the pin. Use the id that wait printed (the number on the card works too, but shifts after a delete). --done says the ask is done (the
|
|
356
|
+
thread closes), --on-it that you're working on it, --question that you need the person; --resolve closes the thread; --wait listens again right after.
|
|
340
357
|
labit resolve <id> [--page /path]
|
|
341
358
|
labit zoom <id> <file>
|
|
342
359
|
Answer a zoom: <file> holds one element, the deeper look or the bigger picture. The lab places it on the page.
|
|
343
360
|
|
|
344
361
|
Files in .lab/ inside the folder: comments.md (every open comment as text), comments/ (the store, one file per
|
|
345
|
-
page), archive/ (done threads with nothing new in 30 days), server.json (port,
|
|
362
|
+
page), archive/ (done threads with nothing new in 30 days), server.json (port, keys, session; owner-only), seen.
|
|
346
363
|
Delete .lab to start over.`;
|
|
347
364
|
var { opts, pos, unknownFlags } = parseArgs(process.argv.slice(2));
|
|
348
365
|
if (opts.help || opts.version) {
|
|
349
|
-
console.log(opts.version ?
|
|
366
|
+
console.log(opts.version ? VERSION2 : HELP);
|
|
350
367
|
process.exit(0);
|
|
351
368
|
}
|
|
352
369
|
var die = (msg) => {
|
|
@@ -394,23 +411,40 @@ A flag or variable wins over labit.json, which wins over your file. See docs/set
|
|
|
394
411
|
process.exit(SETTINGS.problems.length ? 1 : 0);
|
|
395
412
|
}
|
|
396
413
|
if (["preview", "add", "remove", "list", "pages", "wait", "reply", "resolve", "invite", "zoom"].includes(pos[0])) {
|
|
397
|
-
const { runCommand } = await import("./commands-
|
|
414
|
+
const { runCommand } = await import("./commands-L2RJ7R5W.mjs");
|
|
398
415
|
await runCommand({ pos, opts, HERE, CMD, ME, die });
|
|
399
416
|
}
|
|
400
417
|
if (pos[0] === "mcp") {
|
|
401
|
-
const { runMcp } = await import("./mcp-
|
|
402
|
-
await runMcp({ HERE, ME, CMD, VERSION, WRITE_SHORT, AGENTS, agentKind, agentNow });
|
|
418
|
+
const { runMcp } = await import("./mcp-CNZISCIA.mjs");
|
|
419
|
+
await runMcp({ HERE, ME, CMD, VERSION: VERSION2, WRITE_SHORT, AGENTS, agentKind, agentNow });
|
|
403
420
|
}
|
|
404
421
|
if (pos[0] && !fs3.existsSync(pos[0])) die(`No folder ${pos[0]}. Run ${CMD} in your project, or name a folder (see --help)`);
|
|
405
422
|
var ROOT = fs3.realpathSync(path3.resolve(pos[0] || "."));
|
|
406
|
-
var
|
|
423
|
+
var answersHere = (port) => new Promise((done) => {
|
|
424
|
+
if (!Number.isInteger(port) || port <= 0) return done(false);
|
|
425
|
+
const req = http.get({ host: "127.0.0.1", port, path: "/_lab/pages", headers: { host: `localhost:${port}` }, timeout: 1500 }, (res) => {
|
|
426
|
+
let t = "";
|
|
427
|
+
res.on("data", (c) => t += c);
|
|
428
|
+
res.on("end", () => {
|
|
429
|
+
try {
|
|
430
|
+
done(JSON.parse(t).root === ROOT);
|
|
431
|
+
} catch {
|
|
432
|
+
done(false);
|
|
433
|
+
}
|
|
434
|
+
});
|
|
435
|
+
});
|
|
436
|
+
req.on("timeout", () => req.destroy());
|
|
437
|
+
req.on("error", () => done(false));
|
|
438
|
+
});
|
|
439
|
+
var runningServer = async () => {
|
|
407
440
|
try {
|
|
408
|
-
|
|
409
|
-
return
|
|
441
|
+
const running = JSON.parse(fs3.readFileSync(path3.join(ROOT, ".lab/server.json"), "utf8"));
|
|
442
|
+
return await answersHere(running.port) ? running : null;
|
|
410
443
|
} catch {
|
|
411
|
-
return
|
|
444
|
+
return null;
|
|
412
445
|
}
|
|
413
|
-
}
|
|
446
|
+
};
|
|
447
|
+
var alreadyRunning = Boolean(await runningServer());
|
|
414
448
|
if (!alreadyRunning && !opts.new && !["wait", "reply", "resolve", "zoom"].includes(pos[0])) {
|
|
415
449
|
const home = runningLabs().find((lab) => ROOT.startsWith(lab.root + path3.sep));
|
|
416
450
|
if (home) {
|
|
@@ -465,15 +499,73 @@ var ARCHIVE = path3.join(LAB, "archive");
|
|
|
465
499
|
var SERVER = path3.join(LAB, "server.json");
|
|
466
500
|
var SEEN = path3.join(LAB, "seen");
|
|
467
501
|
fs3.mkdirSync(LAB, { recursive: true });
|
|
468
|
-
|
|
469
|
-
const running = JSON.parse(fs3.readFileSync(SERVER, "utf8"));
|
|
470
|
-
process.kill(running.pid, 0);
|
|
502
|
+
var alreadyHere = (running) => {
|
|
471
503
|
if (process.env.PORT && !opts.port && Number(process.env.PORT) !== running.port)
|
|
472
504
|
die(`[lab] already running for this folder at http://localhost:${running.port}. Stop that one (Ctrl+C) to open it here.`);
|
|
473
505
|
console.log(`[lab] already running for this folder: http://localhost:${running.port}`);
|
|
474
506
|
process.exit(0);
|
|
475
|
-
}
|
|
507
|
+
};
|
|
508
|
+
{
|
|
509
|
+
const running = await runningServer();
|
|
510
|
+
if (running) alreadyHere(running);
|
|
476
511
|
}
|
|
512
|
+
var LOCK = path3.join(LAB, "lock");
|
|
513
|
+
var takeLock = () => {
|
|
514
|
+
try {
|
|
515
|
+
fs3.writeSync(fs3.openSync(LOCK, "wx", 384), JSON.stringify({ pid: process.pid, at: Date.now() }));
|
|
516
|
+
return true;
|
|
517
|
+
} catch (e) {
|
|
518
|
+
if (
|
|
519
|
+
/** @type {NodeJS.ErrnoException} */
|
|
520
|
+
e.code !== "EEXIST"
|
|
521
|
+
) throw e;
|
|
522
|
+
return false;
|
|
523
|
+
}
|
|
524
|
+
};
|
|
525
|
+
var readLock = () => {
|
|
526
|
+
try {
|
|
527
|
+
return JSON.parse(fs3.readFileSync(LOCK, "utf8"));
|
|
528
|
+
} catch {
|
|
529
|
+
return null;
|
|
530
|
+
}
|
|
531
|
+
};
|
|
532
|
+
var alive = (pid) => {
|
|
533
|
+
try {
|
|
534
|
+
process.kill(pid, 0);
|
|
535
|
+
return true;
|
|
536
|
+
} catch (e) {
|
|
537
|
+
return (
|
|
538
|
+
/** @type {NodeJS.ErrnoException} */
|
|
539
|
+
e.code === "EPERM"
|
|
540
|
+
);
|
|
541
|
+
}
|
|
542
|
+
};
|
|
543
|
+
for (let tries = 0; !takeLock(); tries++) {
|
|
544
|
+
const held = readLock();
|
|
545
|
+
if (held?.port && await answersHere(held.port)) alreadyHere(held);
|
|
546
|
+
const running = await runningServer();
|
|
547
|
+
if (running) alreadyHere(running);
|
|
548
|
+
const age = (() => {
|
|
549
|
+
try {
|
|
550
|
+
return Date.now() - fs3.statSync(LOCK).mtimeMs;
|
|
551
|
+
} catch {
|
|
552
|
+
return Infinity;
|
|
553
|
+
}
|
|
554
|
+
})();
|
|
555
|
+
const stale = !held ? age > 5e3 : !Number.isInteger(held.pid) || !alive(held.pid) || Date.now() - (Number(held.at) || 0) > 6e4 && tries >= 2;
|
|
556
|
+
if (stale && JSON.stringify(readLock()) === JSON.stringify(held)) {
|
|
557
|
+
fs3.rmSync(LOCK, { force: true });
|
|
558
|
+
if (takeLock()) break;
|
|
559
|
+
}
|
|
560
|
+
if (tries >= 40) die(`[lab] another lab is starting for this folder (pid ${held?.pid}) and hasn't answered. If it hangs, stop it, or delete ${LOCK}.`);
|
|
561
|
+
await new Promise((r) => setTimeout(r, 250));
|
|
562
|
+
}
|
|
563
|
+
process.on("exit", () => {
|
|
564
|
+
try {
|
|
565
|
+
if (JSON.parse(fs3.readFileSync(LOCK, "utf8")).pid === process.pid) fs3.rmSync(LOCK);
|
|
566
|
+
} catch {
|
|
567
|
+
}
|
|
568
|
+
});
|
|
477
569
|
var KEY = path3.join(LAB, "key");
|
|
478
570
|
var TOKEN = (() => {
|
|
479
571
|
try {
|
|
@@ -485,6 +577,7 @@ var TOKEN = (() => {
|
|
|
485
577
|
fs3.writeFileSync(KEY, k, { mode: 384 });
|
|
486
578
|
return k;
|
|
487
579
|
})();
|
|
580
|
+
var AGENT_KEY = randomBytes(16).toString("hex");
|
|
488
581
|
process.env.LAB_HOST = "localhost";
|
|
489
582
|
process.env.LAB_COMMENTS_ADMIN_TOKEN = TOKEN;
|
|
490
583
|
var writeAtomic = (file2, text, mode2) => {
|
|
@@ -498,7 +591,7 @@ var storeName = (page) => {
|
|
|
498
591
|
var savePage = (page, dir = STORE) => {
|
|
499
592
|
const h = db.get(`lab:comments:${page}`);
|
|
500
593
|
const file2 = path3.join(dir, storeName(page));
|
|
501
|
-
if (h?.size) writeAtomic(file2, `{"page":${JSON.stringify(page)},"comments":{${[...h].map(([id, v]) => `${JSON.stringify(id)}:${v}`).join(",")}}}`);
|
|
594
|
+
if (h?.size) writeAtomic(file2, `{"v":${VERSION},"page":${JSON.stringify(page)},"comments":{${[...h].map(([id, v]) => `${JSON.stringify(id)}:${v}`).join(",")}}}`);
|
|
502
595
|
else fs3.rmSync(file2, { force: true });
|
|
503
596
|
};
|
|
504
597
|
var putAside = (file2, what) => {
|
|
@@ -529,7 +622,7 @@ if (migrate) {
|
|
|
529
622
|
}
|
|
530
623
|
}
|
|
531
624
|
}
|
|
532
|
-
var db = new Map(Object.entries(saved).map(([page, h]) => [`lab:comments:${page}`, new Map(Object.entries(h).map(([id, c]) => [id, JSON.stringify(c)]))]));
|
|
625
|
+
var db = new Map(Object.entries(saved).map(([page, h]) => [`lab:comments:${page}`, new Map(Object.entries(h).map(([id, c]) => [id, JSON.stringify(upgrade(c))]))]));
|
|
533
626
|
saved = null;
|
|
534
627
|
if (migrate) {
|
|
535
628
|
const fresh = `${STORE}.new`;
|
|
@@ -553,7 +646,8 @@ function archiveOld(now = Date.now()) {
|
|
|
553
646
|
const h = db.get(`lab:comments:${page}`);
|
|
554
647
|
const all = [...h.values()].map((v) => JSON.parse(v));
|
|
555
648
|
const old = all.filter((c) => !c.parent && c.resolved).map((root) => [root, ...all.filter((c) => c.parent === root.id)]).filter((thread) => {
|
|
556
|
-
const
|
|
649
|
+
const dates = [...thread.map((c) => c.createdAt), ...thread[0].resolvedAt ? [thread[0].resolvedAt] : []];
|
|
650
|
+
const newest = Math.max(...dates.map((d) => Date.parse(d)));
|
|
557
651
|
return Number.isFinite(newest) && now - newest > ARCHIVE_DAYS * 864e5;
|
|
558
652
|
});
|
|
559
653
|
if (!old.length) continue;
|
|
@@ -566,7 +660,7 @@ function archiveOld(now = Date.now()) {
|
|
|
566
660
|
}
|
|
567
661
|
try {
|
|
568
662
|
fs3.mkdirSync(ARCHIVE, { recursive: true });
|
|
569
|
-
writeAtomic(file2, JSON.stringify({ page, comments: { ...kept, ...Object.fromEntries(old.flat().map((c) => [c.id, c])) } }));
|
|
663
|
+
writeAtomic(file2, JSON.stringify({ v: VERSION, page, comments: { ...kept, ...Object.fromEntries(old.flat().map((c) => [c.id, c])) } }));
|
|
570
664
|
} catch (e) {
|
|
571
665
|
console.error(`[lab] could not archive done threads on ${page}:`, e.message);
|
|
572
666
|
continue;
|
|
@@ -729,6 +823,7 @@ var forGuests = (c) => {
|
|
|
729
823
|
if (!c || typeof c !== "object") return c;
|
|
730
824
|
const rest = { ...c };
|
|
731
825
|
if (rest.session) rest.session = { name: rest.session.name, agent: rest.session.agent, kind: rest.session.kind };
|
|
826
|
+
delete rest.deliveredTo;
|
|
732
827
|
return rest;
|
|
733
828
|
};
|
|
734
829
|
function commentChangesSince(page, since) {
|
|
@@ -872,7 +967,11 @@ var redeem = (req, res, code, me = "", to = "") => {
|
|
|
872
967
|
if (NAME_OK(me)) cookies.push(`lab_me=${encodeURIComponent(me.trim())}; Path=/; Max-Age=2592000; SameSite=Lax`);
|
|
873
968
|
return res.writeHead(302, { location: landing(to), "set-cookie": cookies }).end();
|
|
874
969
|
};
|
|
875
|
-
var isAgent = (req) =>
|
|
970
|
+
var isAgent = (req) => {
|
|
971
|
+
const sent = Buffer.from(String(req.headers["x-lab-admin"] || ""));
|
|
972
|
+
const key = Buffer.from(AGENT_KEY);
|
|
973
|
+
return req.headers["x-lab-agent"] === "1" && sent.length === key.length && timingSafeEqual(sent, key);
|
|
974
|
+
};
|
|
876
975
|
var sessionFrom = (req) => {
|
|
877
976
|
try {
|
|
878
977
|
const s = JSON.parse(decodeURIComponent(req.headers["x-lab-session"] || ""));
|
|
@@ -911,22 +1010,32 @@ var register = () => {
|
|
|
911
1010
|
} catch {
|
|
912
1011
|
}
|
|
913
1012
|
};
|
|
914
|
-
var saveServer = () => writeAtomic(SERVER, JSON.stringify({ port: PORT, pid: process.pid, token: TOKEN, session }, null, 2), 384);
|
|
1013
|
+
var saveServer = () => writeAtomic(SERVER, JSON.stringify({ port: PORT, pid: process.pid, token: TOKEN, agent: AGENT_KEY, session }, null, 2), 384);
|
|
915
1014
|
var clients = /* @__PURE__ */ new Set();
|
|
916
1015
|
setInterval(() => {
|
|
917
1016
|
for (const c of clients) c.res.write("event: beat\ndata: 1\n\n");
|
|
918
1017
|
}, 15e3).unref();
|
|
919
1018
|
var READS = path3.join(LAB, "reads.json");
|
|
920
1019
|
var bare = (o) => Object.assign(/* @__PURE__ */ Object.create(null), o);
|
|
921
|
-
var
|
|
1020
|
+
var readSide = (file2, what) => {
|
|
1021
|
+
let text;
|
|
922
1022
|
try {
|
|
923
|
-
|
|
924
|
-
const out = /* @__PURE__ */ Object.create(null);
|
|
925
|
-
for (const [name, pagesOf] of Object.entries(raw)) if (pagesOf && typeof pagesOf === "object") out[name] = bare(pagesOf);
|
|
926
|
-
return out;
|
|
1023
|
+
text = fs3.readFileSync(file2, "utf8");
|
|
927
1024
|
} catch {
|
|
928
|
-
return
|
|
1025
|
+
return null;
|
|
929
1026
|
}
|
|
1027
|
+
try {
|
|
1028
|
+
const data = JSON.parse(text);
|
|
1029
|
+
if (data && typeof data === "object" && !Array.isArray(data)) return data;
|
|
1030
|
+
} catch {
|
|
1031
|
+
}
|
|
1032
|
+
putAside(file2, what);
|
|
1033
|
+
return null;
|
|
1034
|
+
};
|
|
1035
|
+
var reads = (() => {
|
|
1036
|
+
const out = /* @__PURE__ */ Object.create(null);
|
|
1037
|
+
for (const [name, pagesOf] of Object.entries(readSide(READS, "reads.json") || {})) if (pagesOf && typeof pagesOf === "object") out[name] = bare(pagesOf);
|
|
1038
|
+
return out;
|
|
930
1039
|
})();
|
|
931
1040
|
var readsBroadcast = 0;
|
|
932
1041
|
var readsRev = 0;
|
|
@@ -934,7 +1043,13 @@ var plainName = (n) => String(n || "").replace(/\s+/g, " ").trim().toLowerCase()
|
|
|
934
1043
|
var readsTimer;
|
|
935
1044
|
var saveReads = () => {
|
|
936
1045
|
clearTimeout(readsTimer);
|
|
937
|
-
readsTimer = setTimeout(() =>
|
|
1046
|
+
readsTimer = setTimeout(() => {
|
|
1047
|
+
try {
|
|
1048
|
+
writeAtomic(READS, JSON.stringify(reads));
|
|
1049
|
+
} catch (e) {
|
|
1050
|
+
console.error("[lab] could not save read marks:", e.message);
|
|
1051
|
+
}
|
|
1052
|
+
}, 300);
|
|
938
1053
|
};
|
|
939
1054
|
var state = (local) => JSON.stringify({ ...version, reads: readsRev, mode, session: session && (local ? session : { name: session.name, agent: session.agent, model: session.model }) });
|
|
940
1055
|
var broadcast = () => {
|
|
@@ -986,20 +1101,14 @@ var waiters = [];
|
|
|
986
1101
|
var CLAIM_MS = 18e5;
|
|
987
1102
|
var CLAIMS_FILE = path3.join(LAB, "claims.json");
|
|
988
1103
|
var claims = new Map(
|
|
989
|
-
(() =>
|
|
990
|
-
try {
|
|
991
|
-
return Object.entries(JSON.parse(fs3.readFileSync(CLAIMS_FILE, "utf8"))).filter(([p, at]) => typeof p === "string" && p.startsWith("/") && Number.isFinite(at) && Date.now() - at < CLAIM_MS);
|
|
992
|
-
} catch {
|
|
993
|
-
return [];
|
|
994
|
-
}
|
|
995
|
-
})()
|
|
1104
|
+
Object.entries(readSide(CLAIMS_FILE, "claims.json") || {}).filter(([p, at]) => typeof p === "string" && p.startsWith("/") && Number.isFinite(at) && Date.now() - at < CLAIM_MS)
|
|
996
1105
|
);
|
|
997
1106
|
var claim = (pages2) => {
|
|
998
1107
|
if (!pages2?.length) return;
|
|
999
1108
|
const now = Date.now();
|
|
1000
1109
|
for (const p of pages2) claims.set(p, now);
|
|
1001
1110
|
try {
|
|
1002
|
-
|
|
1111
|
+
writeAtomic(CLAIMS_FILE, JSON.stringify(Object.fromEntries([...claims].filter(([, at]) => now - at < CLAIM_MS))));
|
|
1003
1112
|
} catch {
|
|
1004
1113
|
}
|
|
1005
1114
|
};
|
|
@@ -1055,7 +1164,8 @@ var rulesOnce = () => {
|
|
|
1055
1164
|
rulesSent.set(who, rules);
|
|
1056
1165
|
return rules;
|
|
1057
1166
|
};
|
|
1058
|
-
|
|
1167
|
+
var whoOf = (s) => s?.id || s?.name || "";
|
|
1168
|
+
async function unseen(scope = pages(), who = "") {
|
|
1059
1169
|
const fresh = scope.flatMap((page) => commentsOf(page).filter((c) => !c.session && !(c.resolved && !c.parent) && stamp(c) > (c.deliveredAt || seen)).map((c) => ({ page, c })));
|
|
1060
1170
|
const now = Date.now();
|
|
1061
1171
|
const lastBy = (c, mine) => [c, ...commentsOf(c._page).filter((r) => r.parent === c.id)].filter((m) => Boolean(m.session) === mine).map((m) => m.createdAt).sort().pop() || "";
|
|
@@ -1066,7 +1176,7 @@ async function unseen(scope = pages()) {
|
|
|
1066
1176
|
const known = (f) => {
|
|
1067
1177
|
if (!f.c.parent) return false;
|
|
1068
1178
|
const root = commentsOf(f.page).find((c) => c.id === f.c.parent);
|
|
1069
|
-
return Boolean(root?.deliveredAt) && !fresh.some((g) => g.c.id === root.id);
|
|
1179
|
+
return Boolean(root?.deliveredAt) && (root.deliveredTo === void 0 || root.deliveredTo === who) && !fresh.some((g) => g.c.id === root.id);
|
|
1070
1180
|
};
|
|
1071
1181
|
const replies = fresh.filter(known);
|
|
1072
1182
|
const whole = fresh.filter((f) => !known(f));
|
|
@@ -1104,7 +1214,7 @@ ${f.c.parent || f.c.id}`));
|
|
|
1104
1214
|
|
|
1105
1215
|
${blocks.join("\n\n")}` : "") + `
|
|
1106
1216
|
|
|
1107
|
-
Answer each: ${CMD} reply <id> "what you did" [--resolve] (run in ${ROOT}); add --wait to the last one to listen again in the same command.` + (/\nzoom: (in|out)\b/.test(blocks.join("\n")) ? `
|
|
1217
|
+
Answer each: ${CMD} reply <id> "what you did" [--done | --on-it | --question] [--resolve] (run in ${ROOT}); add --wait to the last one to listen again in the same command.` + (/\nzoom: (in|out)\b/.test(blocks.join("\n")) ? `
|
|
1108
1218
|
A pin that says "zoom": read ${ZOOM_SKILL} first. Write one block to a file, then ${CMD} zoom <id> <file>, then reply.` : "") + (given.some((f) => f.c.parent) ? `
|
|
1109
1219
|
A reply about how you answered rather than the work (too long, unclear, didn't show or link it, the same misread twice): answer it and add --suggest-rule "<one short rule>"; they keep it with a tap. Not for the work itself or a one-off correction.` : "") + `
|
|
1110
1220
|
${WRITE_SHORT}` + rulesOnce();
|
|
@@ -1112,11 +1222,11 @@ ${WRITE_SHORT}` + rulesOnce();
|
|
|
1112
1222
|
const marks = given.map(({ page, c }) => [page, c.id, stamp(c)]);
|
|
1113
1223
|
return { text, marks, handed };
|
|
1114
1224
|
}
|
|
1115
|
-
function deliver(res, got) {
|
|
1225
|
+
function deliver(res, got, who = "") {
|
|
1116
1226
|
res.writeHead(200, { "content-type": "text/plain; charset=utf-8" }).end(got.text);
|
|
1117
|
-
for (const [page, id, at2] of got.marks) setComment(page, id, { deliveredAt: at2 });
|
|
1227
|
+
for (const [page, id, at2] of got.marks) setComment(page, id, { deliveredAt: at2, deliveredTo: who });
|
|
1118
1228
|
const at = (/* @__PURE__ */ new Date()).toISOString();
|
|
1119
|
-
for (const [page, id] of got.handed) setComment(page, id, { handedAt: at });
|
|
1229
|
+
for (const [page, id] of got.handed) setComment(page, id, { handedAt: at, deliveredTo: who });
|
|
1120
1230
|
for (const page of new Set([...got.marks, ...got.handed].map(([page2]) => page2))) persist(page).catch(() => {
|
|
1121
1231
|
});
|
|
1122
1232
|
setMode("working");
|
|
@@ -1132,12 +1242,12 @@ function wake() {
|
|
|
1132
1242
|
async function wakeNow() {
|
|
1133
1243
|
for (const w of Array.from(waiters)) {
|
|
1134
1244
|
if (!waiters.includes(w)) continue;
|
|
1135
|
-
const got = await unseen(scopeOf(w));
|
|
1245
|
+
const got = await unseen(scopeOf(w), w.who);
|
|
1136
1246
|
if (!got?.text || !waiters.includes(w)) continue;
|
|
1137
1247
|
waiters = waiters.filter((x) => x !== w);
|
|
1138
1248
|
waitEnded = Date.now();
|
|
1139
1249
|
clearTimeout(w.timer);
|
|
1140
|
-
deliver(w.res, got);
|
|
1250
|
+
deliver(w.res, got, w.who);
|
|
1141
1251
|
}
|
|
1142
1252
|
}
|
|
1143
1253
|
var setComment = (page, id, patch) => {
|
|
@@ -1361,10 +1471,10 @@ var handler = async (req, res) => {
|
|
|
1361
1471
|
old.res.writeHead(409).end("another session is listening now");
|
|
1362
1472
|
}
|
|
1363
1473
|
session = sessionFrom(req);
|
|
1364
|
-
const w = { res, pages: want, key };
|
|
1474
|
+
const w = { res, pages: want, key, who: whoOf(session) };
|
|
1365
1475
|
claim(want);
|
|
1366
|
-
const got = await unseen(scopeOf(w));
|
|
1367
|
-
if (got?.text) return deliver(res, got);
|
|
1476
|
+
const got = await unseen(scopeOf(w), w.who);
|
|
1477
|
+
if (got?.text) return deliver(res, got, w.who);
|
|
1368
1478
|
w.timer = setTimeout(() => {
|
|
1369
1479
|
if (!waiters.includes(w)) return;
|
|
1370
1480
|
waiters = waiters.filter((x) => x !== w);
|
|
@@ -1471,7 +1581,7 @@ var handler = async (req, res) => {
|
|
|
1471
1581
|
const kept = listing2 && cachedList(listPage, kind);
|
|
1472
1582
|
if (kept) return res.writeHead(kept.status, kept.headers).end(kept.out);
|
|
1473
1583
|
const fn = api[req.method] || (() => new Response("", { status: 405 }));
|
|
1474
|
-
const out = await callApi(fn, req, `http://localhost/api${url.search}`, { host: "localhost" });
|
|
1584
|
+
const out = await callApi(fn, req, `http://localhost/api${url.search}`, { host: "localhost", ...agent ? { "x-lab-admin": TOKEN } : {} });
|
|
1475
1585
|
const text = await out.text();
|
|
1476
1586
|
if (req.method === "POST" && out.ok) {
|
|
1477
1587
|
const { comment } = JSON.parse(text);
|
|
@@ -1479,25 +1589,28 @@ var handler = async (req, res) => {
|
|
|
1479
1589
|
const [key, h] = [...db].find(([k, m]) => k.startsWith("lab:comments:") && m.has(comment.id));
|
|
1480
1590
|
const stored = { ...JSON.parse(h.get(comment.id)), ...agent ? { session: sessionFrom(req) } : { from: isLoopback(req) ? "this computer" : "wifi guest" } };
|
|
1481
1591
|
if (!agent) delete stored.suggest;
|
|
1592
|
+
if (!agent) delete stored.intent;
|
|
1482
1593
|
h.set(comment.id, JSON.stringify(stored));
|
|
1483
1594
|
if (!agent && stored.parent && h.has(stored.parent)) {
|
|
1484
1595
|
const root = JSON.parse(h.get(stored.parent));
|
|
1485
|
-
if (root.resolved) h.set(stored.parent, JSON.stringify({ ...root, resolved: false, resolvedBy: void 0 }));
|
|
1596
|
+
if (root.resolved) h.set(stored.parent, JSON.stringify({ ...root, resolved: false, resolvedBy: void 0, resolvedAt: void 0 }));
|
|
1486
1597
|
}
|
|
1487
|
-
|
|
1598
|
+
const said = stored.intent || intentFromText(stored.text);
|
|
1599
|
+
if (agent && stored.parent && h.has(stored.parent) && said === "done") {
|
|
1488
1600
|
const root = JSON.parse(h.get(stored.parent));
|
|
1489
1601
|
const thread = [root, ...[...h.values()].map((v) => JSON.parse(v)).filter((x) => x.parent === root.id && x.id !== stored.id)].sort((x, y) => String(x.createdAt).localeCompare(String(y.createdAt)));
|
|
1490
1602
|
const lastAgent = thread.map((x) => Boolean(x.session)).lastIndexOf(true);
|
|
1491
1603
|
const asks = thread.slice(lastAgent + 1).filter((x) => !x.session);
|
|
1492
1604
|
const listy = (t) => String(t).split("\n").filter((l) => /^\s*(?:[-*•]|\d+[.)])\s+/.test(l)).length >= 2;
|
|
1493
1605
|
const oneThing = asks.length === 1 && !listy(asks[0].text);
|
|
1494
|
-
if (oneThing && !root.resolved && root.anchor?.kind !== "page")
|
|
1606
|
+
if ((stored.intent === "done" || oneThing) && !root.resolved && root.anchor?.kind !== "page")
|
|
1607
|
+
h.set(stored.parent, JSON.stringify({ ...root, resolved: true, resolvedBy: "agent", resolvedAt: stored.createdAt }));
|
|
1495
1608
|
}
|
|
1496
1609
|
if (agent && stored.parent && h.has(stored.parent)) {
|
|
1497
1610
|
const root = JSON.parse(h.get(stored.parent));
|
|
1498
1611
|
const more = [...h.values()].map((v) => JSON.parse(v)).some((x) => x.parent === root.id && x.id !== stored.id && !x.session);
|
|
1499
1612
|
const placed = root.anchor?.zoom && root.zoomed && !root.resolved && !more;
|
|
1500
|
-
if (placed) h.set(stored.parent, JSON.stringify({ ...root, resolved: true, resolvedBy: "agent" }));
|
|
1613
|
+
if (placed) h.set(stored.parent, JSON.stringify({ ...root, resolved: true, resolvedBy: "agent", resolvedAt: stored.createdAt }));
|
|
1501
1614
|
}
|
|
1502
1615
|
if (!agent) announce(key.slice("lab:comments:".length), stored);
|
|
1503
1616
|
}
|
|
@@ -1596,14 +1709,15 @@ async function newerVersion() {
|
|
|
1596
1709
|
}
|
|
1597
1710
|
}
|
|
1598
1711
|
const parts = (v) => String(v).split("-")[0].split(".").map(Number);
|
|
1599
|
-
const [a, b] = [parts(latest), parts(
|
|
1712
|
+
const [a, b] = [parts(latest), parts(VERSION2)];
|
|
1600
1713
|
for (let i = 0; i < 3; i++) if (a[i] !== b[i]) return a[i] > b[i] ? latest : null;
|
|
1601
1714
|
return null;
|
|
1602
1715
|
}
|
|
1603
1716
|
server.on("listening", async () => {
|
|
1604
|
-
newerVersion().then((v) => v && console.log(`[lab] labit ${v} is out (you have ${
|
|
1717
|
+
newerVersion().then((v) => v && console.log(`[lab] labit ${v} is out (you have ${VERSION2}): npx @leonidstern/labit@latest`));
|
|
1605
1718
|
origin = `http://localhost:${PORT}`;
|
|
1606
1719
|
saveServer();
|
|
1720
|
+
writeAtomic(LOCK, JSON.stringify({ pid: process.pid, at: Date.now(), port: PORT }), 384);
|
|
1607
1721
|
register();
|
|
1608
1722
|
await persist();
|
|
1609
1723
|
console.log(`[lab] ${origin} \xB7 ${PROXY ? `pages from the dev server at ${PROXY.origin}, comments in` : "pages from"} ${ROOT}`);
|
|
@@ -1628,4 +1742,5 @@ var bye = () => {
|
|
|
1628
1742
|
};
|
|
1629
1743
|
process.on("SIGINT", bye);
|
|
1630
1744
|
process.on("SIGTERM", bye);
|
|
1745
|
+
process.on("SIGHUP", bye);
|
|
1631
1746
|
server.listen(PORT, WIFI ? void 0 : "127.0.0.1");
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
WAIT_SAID,
|
|
3
3
|
findLab,
|
|
4
4
|
labCall
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-QTMKKULT.mjs";
|
|
6
6
|
import {
|
|
7
7
|
mySession
|
|
8
8
|
} from "./chunk-X4RYDWNI.mjs";
|
|
@@ -38,7 +38,7 @@ async function runMcp({ HERE, ME, CMD, VERSION, WRITE_SHORT, AGENTS, agentKind,
|
|
|
38
38
|
done({ ok: !err, text: (stdout || "") + (err && !stdout ? stderr || err.message : "") });
|
|
39
39
|
});
|
|
40
40
|
});
|
|
41
|
-
const forTools = (t) => t.replace(/^Answer each: .*$/m, "Answer each with the `reply` tool (id, text,
|
|
41
|
+
const forTools = (t) => t.replace(/^Answer each: .*$/m, "Answer each with the `reply` tool (id, text, intent: done when it is done, question when you need the person), then call `wait` again.");
|
|
42
42
|
const text = (t, isError = false) => ({ content: [{ type: "text", text: forTools(t).trim() || "(nothing)" }], ...isError ? { isError } : {} });
|
|
43
43
|
const tools = [
|
|
44
44
|
{
|
|
@@ -51,12 +51,13 @@ async function runMcp({ HERE, ME, CMD, VERSION, WRITE_SHORT, AGENTS, agentKind,
|
|
|
51
51
|
{
|
|
52
52
|
name: "reply",
|
|
53
53
|
title: "Answer on a pin",
|
|
54
|
-
description: `Answer on a pin in the local lab, by the id \`comments\` shows. resolve: true closes the thread. ${WRITE_SHORT}`,
|
|
54
|
+
description: `Answer on a pin in the local lab, by the id \`comments\` shows. intent says what the answer is: done (the thread closes), working (you're on it) or question (you need the person). resolve: true closes the thread. ${WRITE_SHORT}`,
|
|
55
55
|
inputSchema: {
|
|
56
56
|
type: "object",
|
|
57
57
|
properties: {
|
|
58
58
|
id: { type: "string", description: "The comment id" },
|
|
59
|
-
text: { type: "string", description: 'What you did, e.g. "
|
|
59
|
+
text: { type: "string", description: 'What you did, e.g. "The title is red"' },
|
|
60
|
+
intent: { type: "string", enum: ["done", "working", "question"], description: "done: the ask is done; working: you are on it; question: you need the person" },
|
|
60
61
|
resolve: { type: "boolean", description: "Close the thread" },
|
|
61
62
|
dir: { type: "string", description: "The project folder, if the server started somewhere else (default: the client's root or the folder it started in)" }
|
|
62
63
|
},
|
|
@@ -115,8 +116,10 @@ async function runMcp({ HERE, ME, CMD, VERSION, WRITE_SHORT, AGENTS, agentKind,
|
|
|
115
116
|
if (typeof a.id !== "string" || !a.id.trim()) return text("`id` is required: the comment id that `comments` shows.", true);
|
|
116
117
|
if (typeof a.text !== "string" || !a.text.trim()) return text("`text` is required: what you did.", true);
|
|
117
118
|
if (a.resolve !== void 0 && typeof a.resolve !== "boolean") return text("`resolve` must be true or false.", true);
|
|
119
|
+
const flag = { done: "--done", working: "--on-it", question: "--question" }[a.intent];
|
|
120
|
+
if (a.intent !== void 0 && !flag) return text("`intent` must be done, working or question.", true);
|
|
118
121
|
if (a.dir !== void 0 && typeof a.dir !== "string") return text("`dir` must be a folder path.", true);
|
|
119
|
-
const r = await run(["reply", a.id, a.text, ...a.resolve ? ["--resolve"] : []], 3e4, project(a));
|
|
122
|
+
const r = await run(["reply", a.id, a.text, ...flag ? [flag] : [], ...a.resolve ? ["--resolve"] : []], 3e4, project(a));
|
|
120
123
|
return text(r.text, !r.ok);
|
|
121
124
|
}
|
|
122
125
|
if (a.seconds !== void 0 && (typeof a.seconds !== "number" || !Number.isFinite(a.seconds))) return text("`seconds` must be a number.", true);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leonidstern/labit",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.3-edge.3.1",
|
|
4
4
|
"description": "Pin comments on pages, read by your agent as plain text. Local mode: comment on pages on your computer and Claude answers on the pins.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|