@leonidstern/labit 0.6.2 → 0.6.3-edge.4.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 CHANGED
@@ -4,12 +4,27 @@ Versions follow [semver](https://semver.org). Before 1.0, a minor version can ch
4
4
 
5
5
  ## Unreleased
6
6
 
7
+ - Pins find their spot again more reliably after the page changes: a twin search starts inside the pin's own section, a pin on words sits on those words, pins on text in the page body follow their quote, made-up ids and classes (React `:r3:`, Radix, CSS-module and Svelte hashes) no longer count as names, and a pin whose card is gone among look-alikes shows as moved instead of landing on the wrong one.
8
+ - Replies say what they are: `labit reply <id> "…" --done | --on-it | --question` (and `intent` on the MCP reply tool). The thread closes from `--done`, not from the words; a reply starting "Done" still works for older agents.
9
+ - Resolving records when (`resolvedAt`) and by whom: the agent's `labit resolve` now records `agent`, not `owner`. Done threads are archived a month after they were resolved, not after their last message. Replies no longer carry `resolved:false`.
10
+ - Comments carry a schema version (`v: 1`); older page files and hosted records are upgraded when they load.
11
+ - The agent has its own key, kept only in `.lab/server.json`: a script on a lab page holds the browser key and can no longer wait, zoom or answer as the agent. An older labit CLI can't act as the agent on this lab.
12
+ - The 500-per-page cap no longer blocks the owner or the agent, and done threads no longer count toward it.
13
+ - One lab per folder, for sure: `.lab/lock` is taken before the store loads, a lab counts as running only if it answers on its port, and closing the terminal (SIGHUP) cleans up.
14
+ - A session that takes over a page gets whole threads for pins another session was handed, not one-line "new replies".
15
+ - `reads.json`, `claims.json` and `links.json` are written whole; a damaged one is set aside (`*.broken-<time>`) instead of read as empty and written over.
16
+
7
17
  - Releases publish themselves: a version bump merged to main goes to npm as `latest` (tagged `vX.Y.Z`), and every merge to main goes out as `next` (0.6.3-main.41…). `npx @leonidstern/labit@latest` is the newest release; `@next` is main as it is now, for whoever wants each merge in their labs. From GitHub Actions with npm trusted publishing, no token.
18
+ - "Pin over controls": with it on, the pointer over the page's links, buttons and clickable cards is the pin, not their hand. The menu item shows how to do it once without the switch: (⌥ click).
8
19
 
9
20
  ## 0.6.2 · 2026-11-17
10
21
 
11
22
  - A go pin is a pin like any other: once it is done or resolved it wears the tick, where before it said "go" for ever and a finished one looked unfinished. Checked in both engines by the browser job.
23
+ - Option-click on a pin resolves its thread without opening it (again opens it again), for whoever may resolve it.
24
+
12
25
  - A done pin is a solid green ✓, full size, even when the page changed under it: faded and small is how a pin that lost its spot looks, and done pins looked lost.
26
+ - Phones: a sent comment's card slides down whole, like any sheet, and its new pin pops in with one green ring. It used to shrink and fly into the pin, which squeezed the card, and the pin was already there while it flew (its pop-in had been dropped by a later change).
27
+
13
28
  - Rules from how you reply: when a reply is about how the agent answered (too long, unclear, didn't show where), the agent offers a rule with its answer (`labit reply <id> "…" --suggest-rule "…"`) and your message shows **rule?** where its time was. One tap keeps it, ignoring it is a no, and undo on the answer takes it back. Rules live in `~/.config/labit/replies.md` (yours, every project, every agent; the same rule again counts again) and the 15 kept most go to each session once, and again when they change.
14
29
  - Threads: an answer to a later message in the thread quotes it, as the chat does; a plain "go" the agent resolves without a word shows one green ✓ on your message; an open thread stays at its newest message while it gets shorter (the keyboard) or an answer comes in, as the chat does, and goes to it when you tap the reply box.
15
30
  - Phone links: `labit invite --page /path` opens that page. A used or old link opened again on a device the lab already lets in takes you to its page instead of the gate, and a guest who keeps using the lab stays in (each page they open renews the day). Only a path of this lab is a landing; anything else lands on `/`.
package/README.md CHANGED
@@ -29,7 +29,7 @@ It finds your running dev server (Astro, Next, Vite…) or serves plain HTML, an
29
29
 
30
30
  ```sh
31
31
  npx @leonidstern/labit wait # ends with your next comment
32
- npx @leonidstern/labit reply <id> "Done: …" # answers on the pin
32
+ npx @leonidstern/labit reply <id> --done "…" # answers on the pin and closes it
33
33
  ```
34
34
 
35
35
  Or as an MCP server: `npx @leonidstern/labit@latest mcp`.
@@ -0,0 +1,29 @@
1
+ // The shape a comment is stored in, and how an older one is read. Used by the hosted API (api/lab-comments.mjs) as it
2
+ // reads Redis and by the local lab (local.mjs) as it loads .lab/comments/: one place, so both read old records alike.
3
+ // (The _ keeps Vercel from serving this file as an endpoint of its own.)
4
+ //
5
+ // v is the version a record was saved in; a record without one is 0. upgrade() brings any record up to VERSION, filling
6
+ // new fields from the old ones, so an old file means exactly what it meant before.
7
+ // 1 (17 Nov): agent replies say what they are with intent ('done' | 'working' | 'question'), read before from the
8
+ // text ("Done: …", "On it"); a thread says when it was resolved (resolvedAt); replies no longer carry resolved:false
9
+ // (only a thread can be resolved).
10
+ export const VERSION = 1;
11
+ export const INTENTS = ['done', 'working', 'question'];
12
+
13
+ // An agent reply's intent from its words, for records (and agents) that don't say it: the rule the lab and the widget
14
+ // went by before intent existed.
15
+ export const intentFromText = (text) => (/^done\b/i.test(String(text ?? '').trim()) ? 'done' : /^on it\b/i.test(String(text ?? '').trim()) ? 'working' : undefined);
16
+
17
+ export function upgrade(record) {
18
+ if (!record || typeof record !== 'object' || (Number(record.v) || 0) >= VERSION) return record;
19
+ const c = { ...record, v: VERSION };
20
+ if (c.parent) {
21
+ if (c.resolved === false) delete c.resolved;
22
+ // Only the local lab marks the agent's own replies (session); the hosted store can't tell them from people's.
23
+ if (c.session && !c.intent) {
24
+ const intent = intentFromText(c.text);
25
+ if (intent) c.intent = intent;
26
+ }
27
+ }
28
+ return c;
29
+ }
@@ -5,6 +5,7 @@
5
5
  // LAB_HOST (e.g. lab.example.com), LAB_COMMENTS_ADMIN_TOKEN for resolving and deleting (see adminFor()).
6
6
 
7
7
  import { createHmac, timingSafeEqual } from 'node:crypto';
8
+ import { INTENTS, upgrade, VERSION } from './_schema.mjs';
8
9
 
9
10
  const LAB_HOST = process.env.LAB_HOST || '';
10
11
  const MAX = { name: 60, text: 2000, path: 300, selector: 600, context: 400, perPage: 500 };
@@ -193,7 +194,7 @@ export async function GET(request) {
193
194
  const comments = values
194
195
  .map((v) => {
195
196
  try {
196
- return JSON.parse(v);
197
+ return upgrade(JSON.parse(v));
197
198
  } catch {
198
199
  return null;
199
200
  }
@@ -346,14 +347,18 @@ export async function POST(request) {
346
347
  const own = body.action !== 'delete' && edit && typeof body.edit === 'string' && sameKey(body.edit, edit);
347
348
  if (!admin && !own) return json({ error: 'forbidden' }, 403);
348
349
  if (body.action === 'delete') {
349
- const all = ((await run('HVALS', key)) || []).map((v) => JSON.parse(v));
350
+ const all = ((await run('HVALS', key)) || []).map((v) => upgrade(JSON.parse(v)));
350
351
  if (!all.some((c) => c.id === id)) return json({ error: 'not found' }, 404);
351
352
  await run('HDEL', key, id, ...all.filter((c) => c.parent === id).map((c) => c.id));
352
353
  return json({ ok: true });
353
354
  }
354
355
  const current = await run('HGET', key, id);
355
356
  if (!current) return json({ error: 'not found' }, 404);
356
- const comment = { ...JSON.parse(current), resolved: body.action === 'resolve', resolvedBy: body.action === 'resolve' ? admin?.name || 'author' : undefined };
357
+ // Who resolved it: the agent (an admin request the lab marks as the agent's, as labit resolve and --resolve are), an
358
+ // admin by name, or whoever started the thread. Reopening clears who and when.
359
+ const by = admin && request.headers.get('x-lab-agent') === '1' ? 'agent' : admin?.name || 'author';
360
+ const resolve = body.action === 'resolve';
361
+ const comment = { ...upgrade(JSON.parse(current)), resolved: resolve, resolvedBy: resolve ? by : undefined, resolvedAt: resolve ? new Date().toISOString() : undefined };
357
362
  await run('HSET', key, id, JSON.stringify(comment));
358
363
  return json({ comment });
359
364
  }
@@ -365,7 +370,7 @@ export async function POST(request) {
365
370
  if (!isAdmin(request, path) && !(edit && typeof body.edit === 'string' && sameKey(body.edit, edit))) return json({ error: 'forbidden' }, 403);
366
371
  const current = await run('HGET', key, id);
367
372
  if (!current) return json({ error: 'not found' }, 404);
368
- const thread = JSON.parse(current);
373
+ const thread = upgrade(JSON.parse(current));
369
374
  if (thread.parent || !body.anchor || typeof body.anchor !== 'object') return json({ error: 'bad move' }, 400);
370
375
  const anchor = cleanAnchor(body.anchor);
371
376
  if (thread.anchor?.zoom && !anchor.zoom) anchor.zoom = thread.anchor.zoom; // a moved zoom stays a zoom, whatever the widget sent
@@ -386,7 +391,7 @@ export async function POST(request) {
386
391
  const was = await run('GET', nonceKey);
387
392
  const earlier = was && (await run('HGET', key, was));
388
393
  if (earlier) {
389
- const c = JSON.parse(earlier);
394
+ const c = upgrade(JSON.parse(earlier));
390
395
  const edit = c.parent ? null : editKey(path, c.id);
391
396
  return json(edit ? { comment: c, edit } : { comment: c }, 200);
392
397
  }
@@ -406,7 +411,13 @@ export async function POST(request) {
406
411
  limited ? ['INCR', hourKey] : ['HLEN', key],
407
412
  limited && ['EXPIRE', hourKey, 3600],
408
413
  );
409
- if (count >= MAX.perPage) return json({ error: 'too many comments on this page' }, 429);
414
+ // A page full of open talk takes no more from people: open threads (and their replies) count, done ones don't, so a
415
+ // long-lived page doesn't fill up for good. Admins (the owner, the agent) are never refused: an answer always lands.
416
+ if (limited && count >= MAX.perPage) {
417
+ const all = ((await run('HVALS', key)) || []).map((v) => JSON.parse(v));
418
+ const done = new Set(all.filter((c) => !c.parent && c.resolved).map((c) => c.id));
419
+ if (all.filter((c) => !done.has(c.parent || c.id)).length >= MAX.perPage) return json({ error: 'too many comments on this page' }, 429);
420
+ }
410
421
  if (limited && used > (Number(process.env.LAB_COMMENTS_PER_HOUR) || 60)) return json({ error: 'too many comments, try again later' }, 429);
411
422
 
412
423
  // Replies attach to the thread (a reply to a reply goes to its thread). Someone answering a resolved thread
@@ -414,31 +425,36 @@ export async function POST(request) {
414
425
  let thread = null;
415
426
  if (parent) {
416
427
  if (!found) return json({ error: 'thread not found' }, 404);
417
- thread = JSON.parse(found);
428
+ thread = upgrade(JSON.parse(found));
418
429
  if (thread.parent) {
419
430
  parent = thread.parent;
420
431
  const root = await run('HGET', key, parent);
421
432
  if (!root) return json({ error: 'thread not found' }, 404);
422
- thread = JSON.parse(root);
433
+ thread = upgrade(JSON.parse(root));
423
434
  }
424
435
  }
425
436
 
426
437
  const anchor = body.anchor || {};
427
438
  const comment = {
439
+ v: VERSION,
428
440
  id: crypto.randomUUID().replace(/-/g, '').slice(0, 12),
429
441
  parent,
430
442
  name,
431
443
  text,
432
444
  createdAt: new Date().toISOString(),
433
- resolved: false,
445
+ // Only a thread is open or resolved; a reply has no such state.
446
+ ...(parent ? {} : { resolved: false }),
434
447
  anchor: parent ? null : cleanAnchor(anchor),
435
448
  // The message in the thread this one answers, when it isn't the first (shown as a quote).
436
449
  ...(parent && body.to ? { to: clean(body.to, 40) } : {}),
437
450
  // A rule the agent offers on its own, from a reply about how it answered (labit reply --suggest-rule): kept with a tap.
438
451
  ...(parent && body.suggest && !limited ? { suggest: cleanText(body.suggest, 200) } : {}),
452
+ // What the agent's answer is (labit reply --done / --on-it / --question): the thread's state is read from it, not
453
+ // from the words. Admins only, as the agent always is.
454
+ ...(parent && INTENTS.includes(body.intent) && !limited ? { intent: body.intent } : {}),
439
455
  };
440
456
  // The comment, and the reopened thread when someone (not an admin) answers a resolved one: one round trip.
441
- if (thread?.resolved && limited) await run('HSET', key, comment.id, JSON.stringify(comment), parent, JSON.stringify({ ...thread, resolved: false, resolvedBy: undefined }));
457
+ if (thread?.resolved && limited) await run('HSET', key, comment.id, JSON.stringify(comment), parent, JSON.stringify({ ...thread, resolved: false, resolvedBy: undefined, resolvedAt: undefined }));
442
458
  else await run('HSET', key, comment.id, JSON.stringify(comment));
443
459
  if (nonceKey) await run('SET', nonceKey, comment.id, 'EX', 900);
444
460
  const edit = parent ? null : editKey(path, comment.id);
@@ -4,7 +4,12 @@ function listenPages(opts, forWait = false) {
4
4
  if (!raw) return null;
5
5
  return String(raw).split(",").map((p) => "/" + p.trim().replace(/^\/+/, "").replace(/\.html?$/i, "")).filter((p) => p !== "/");
6
6
  }
7
- var SWITCHES = ["--wifi", "--no-open", "--resolve", "--wait", "--new", "--all", "--bg", "--fast", "--no-fast"];
7
+ var SWITCHES = ["--wifi", "--no-open", "--resolve", "--wait", "--new", "--all", "--bg", "--fast", "--no-fast", "--done", "--on-it", "--question"];
8
+ function replyIntent(opts) {
9
+ const given = ["done", "on-it", "question"].filter((f) => opts[f]);
10
+ if (given.length > 1) return new Error(`Give one of --done, --on-it, --question, not ${given.map((f) => `--${f}`).join(" and ")}.`);
11
+ return given[0] === "on-it" ? "working" : given[0];
12
+ }
8
13
  var FOREGROUND_CAP = 60;
9
14
  var WAIT_DEFAULT = 1500;
10
15
  function waitSeconds(opts, isTTY = false) {
@@ -56,6 +61,7 @@ var runningLabs = () => (fs.existsSync(REGISTRY) ? fs.readdirSync(REGISTRY) : []
56
61
 
57
62
  export {
58
63
  listenPages,
64
+ replyIntent,
59
65
  FOREGROUND_CAP,
60
66
  waitSeconds,
61
67
  WRITE_SHORT,
@@ -22,7 +22,7 @@ var labCall = (server, pathname, body, session, signal) => new Promise((resolve,
22
22
  host: `localhost:${server.port}`,
23
23
  "content-type": "application/json",
24
24
  "content-length": Buffer.byteLength(data),
25
- "x-lab-admin": server.token,
25
+ "x-lab-admin": server.agent || server.token,
26
26
  "x-lab-agent": "1",
27
27
  "x-lab-session": encodeURIComponent(JSON.stringify(session))
28
28
  }
@@ -1,14 +1,15 @@
1
1
  import {
2
2
  FOREGROUND_CAP,
3
3
  listenPages,
4
+ replyIntent,
4
5
  runningLabs,
5
6
  waitSeconds
6
- } from "./chunk-XZUZQFBJ.mjs";
7
+ } from "./chunk-AVPXXSFF.mjs";
7
8
  import {
8
9
  WAIT_SAID,
9
10
  findLab,
10
11
  labCall
11
- } from "./chunk-LNYMIFDQ.mjs";
12
+ } from "./chunk-QTMKKULT.mjs";
12
13
  import {
13
14
  mySession
14
15
  } from "./chunk-X4RYDWNI.mjs";
@@ -46,11 +47,21 @@ ${JSON.stringify(entry(), null, 2)}`);
46
47
  const forHere = (lab) => lab.root === HERE || lab.root.startsWith(HERE + path.sep) || HERE.startsWith(lab.root + path.sep);
47
48
  const LINKS = path.join(HERE, ".lab", "links.json");
48
49
  const savedLinks = () => {
50
+ let text;
49
51
  try {
50
- return JSON.parse(fs.readFileSync(LINKS, "utf8"));
52
+ text = fs.readFileSync(LINKS, "utf8");
51
53
  } catch {
52
54
  return [];
53
55
  }
56
+ try {
57
+ const list = JSON.parse(text);
58
+ if (Array.isArray(list)) return list;
59
+ } catch {
60
+ }
61
+ const aside = `${LINKS}.broken-${Date.now()}`;
62
+ fs.renameSync(LINKS, aside);
63
+ console.error(`[lab] .lab/links.json was damaged; moved it to ${path.basename(aside)}`);
64
+ return [];
54
65
  };
55
66
  const cloudOpen = async (url) => {
56
67
  try {
@@ -83,7 +94,8 @@ ${JSON.stringify(entry(), null, 2)}`);
83
94
  list.push({ url: key, title });
84
95
  }
85
96
  fs.mkdirSync(path.dirname(LINKS), { recursive: true });
86
- fs.writeFileSync(LINKS, JSON.stringify(list, null, 2) + "\n");
97
+ fs.writeFileSync(LINKS + ".tmp", JSON.stringify(list, null, 2) + "\n");
98
+ fs.renameSync(LINKS + ".tmp", LINKS);
87
99
  console.log(pos[0] === "add" ? `Saved ${key}${title ? ` (${title})` : ""}. It shows in \`${CMD} pages\` and \`${CMD} list\`.` : `Removed ${key}.`);
88
100
  process.exit(0);
89
101
  }
@@ -214,9 +226,11 @@ That wait was held to ${FOREGROUND_CAP} seconds. Run it in the background (your
214
226
  }
215
227
  if (cmd === "reply") {
216
228
  if (!words.length) die(`Reply text is missing: ${CMD} reply <id> "what you did"`);
229
+ const intent = replyIntent(opts);
230
+ if (intent instanceof Error) die(intent.message);
217
231
  const who = process.env.LAB_AGENT_NAME || session.agent;
218
232
  const name = `${who}${session.name !== session.agent ? ` \xB7 ${session.name}` : ""}`;
219
- const out = await call("/_lab/api/comments", { page: hit.page, parent: hit.id, ...hit.to ? { to: hit.to } : {}, name, text: words.join(" "), ...typeof opts["suggest-rule"] === "string" ? { suggest: opts["suggest-rule"] } : {} });
233
+ const out = await call("/_lab/api/comments", { page: hit.page, parent: hit.id, ...hit.to ? { to: hit.to } : {}, name, text: words.join(" "), ...typeof opts["suggest-rule"] === "string" ? { suggest: opts["suggest-rule"] } : {}, ...intent ? { intent } : {} });
220
234
  if (out.status >= 300) die(`Could not reply: ${out.text}`);
221
235
  }
222
236
  if (cmd === "resolve" || opts.resolve) {