@leonidstern/labit 0.6.1 → 0.6.3-main.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/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +22 -0
- package/README.md +7 -1
- package/api/lab-comments.mjs +8 -1
- package/dist/chunk-DIR2O7SK.mjs +13 -0
- package/dist/chunk-LNYMIFDQ.mjs +49 -0
- package/dist/{chunk-T4IF6ZJQ.mjs → chunk-X4RYDWNI.mjs} +1 -55
- package/dist/chunk-XZUZQFBJ.mjs +65 -0
- package/dist/{commands-BPVIWBCF.mjs → commands-LAQNMF2X.mjs} +36 -51
- package/dist/flags-PGKWZHJC.mjs +10 -0
- package/dist/local.mjs +309 -165
- package/dist/{mcp-BKU67CST.mjs → mcp-4UPGXLZR.mjs} +65 -21
- package/dist/settings-XLFKONNN.mjs +175 -0
- package/package.json +3 -3
- package/public/_lab/comments.js +18 -18
- package/skills/labit/SKILL.md +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,28 @@ Versions follow [semver](https://semver.org). Before 1.0, a minor version can ch
|
|
|
4
4
|
|
|
5
5
|
## Unreleased
|
|
6
6
|
|
|
7
|
+
- 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.
|
|
8
|
+
|
|
9
|
+
## 0.6.2 · 2026-11-17
|
|
10
|
+
|
|
11
|
+
- 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.
|
|
12
|
+
- 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.
|
|
13
|
+
- 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
|
+
- 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
|
+
- 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 `/`.
|
|
16
|
+
- Phones: the quoted words of a comment are lit, not half the page. Safari painted that green over whole blocks of text that can't be selected, and with comments on the page was unselectable all the time; now only while a finger is down (the hold still never turns into a text selection).
|
|
17
|
+
- Phones: after a new comment is sent or dropped, the page glides back to where you were before the hold moved it up to keep the pin above the keyboard (once the card has landed in its pin; not if you scrolled yourself meanwhile).
|
|
18
|
+
- `test/phone/sim.mjs`: phone checks in the iOS simulator's Safari and the Chrome stand-in, real touches step by step against a recorder on the page (focus, keyboard, scroll, selection, pins and boxes, every frame). Not in CI.
|
|
19
|
+
- Things being tried arrive as flags: off unless somebody turns one on, tried in a real lab, then kept (the flag goes and it is simply labit) or dropped (the code goes with it). `flags` in `labit.json` or your own settings, switches under a **trying** heading in the ⋯ menu (this computer only), `labit settings` lists them, and a switch writes the project's `labit.json` so the agent sees the same thing. First two: `liveUrl` (a lab in front of a live page) and `agentPins` (a pin the agent left wears labit's own mark, the one the bar shows while an agent listens).
|
|
20
|
+
- A wait can no longer hold someone's turn open: `labit wait` (and `reply --wait`) sits for the full timeout only when the agent says it put the command in the background, with `--bg`. Without that it ends after a minute and says why. A wait left in an agent's foreground kept the person from saying anything to their agent until it ended, and the message they sent to reach them killed it; from inside the process a foreground run looks exactly like a background one, so `--bg` is the agent's word for it. At a terminal (a tty) nothing changes.
|
|
21
|
+
- The bar's counts (chat, new) are green when something is new, grey at 0.
|
|
22
|
+
- Settings: `labit.json` in the project (shared) and `~/.config/labit/settings.json` (yours) fill in what flags and variables leave out: port, proxy, folder, open, wifi (yours only), batchSeconds, stopListeningAfterMinutes, remindAfterMinutes, archiveAfterDays, updateCheck, name and model (yours only), shortcuts (every key on the page, shown in the bar) and zoom.skill (a project's own zoom skill). `labit settings` shows each value and where it came from. Your name moves from me.json to settings.json (me.json is still read). docs/settings.md.
|
|
23
|
+
- A lab's tabs share one live connection: the first tab holds it and passes every update to the others (Web Locks + BroadcastChannel; when it closes, the next tab takes over). Tabs in the background stay live, their title count and pins updating at once instead of every 20 s or so, and any number of tabs of one lab use one of the browser's 6 connections.
|
|
24
|
+
- Listening: the MCP server's `wait` is its own request to the lab, no longer a `labit wait` process it starts, so a cancel or the client going away ends it at once by design. A tab that drops its connection without saying bye (crashed, or frozen by a phone) stops counting as open after 90 s without checking in, not after half an hour (LAB_TAB_TTL, in seconds).
|
|
25
|
+
- MCP server, checked against the spec (2025-11-25, 2026-07-28) and the SDK's practice: when the client goes away (stdin closed, SIGTERM, SIGINT) a `wait` in flight stops with it, so the page no longer says an agent is listening for up to the wait's length; a `wait` refused for a bad argument no longer sends progress forever after its answer; a cancel for a request already answered is ignored (an id used again got no answer); roots are asked for after the client's `initialized`, not before; a batch gets an Invalid Request error instead of silence.
|
|
26
|
+
- `examples/claude-settings.json`: Claude Code settings to give people. labit's commands and MCP tools run without a prompt; `--wifi` and `invite` still ask. Checked with `claude -p` in a fresh folder.
|
|
27
|
+
- The last of the old name is gone: no `labfb` command (use `labit`), and `LABFB_HOME` / `LABFB_NO_UPDATE_CHECK` are no longer read (use `LABIT_HOME` / `LABIT_NO_UPDATE_CHECK`).
|
|
28
|
+
|
|
7
29
|
## 0.6.1 · 2026-11-16
|
|
8
30
|
|
|
9
31
|
- iPhones: a new comment no longer sometimes sits behind the keyboard's bar. When Safari (or Chrome) slid the page up for the keyboard instead of scrolling it, the widget counted that slide twice and saw no keyboard at all; it now measures the slide where WebKit measures boxes, from the screen's top.
|
package/README.md
CHANGED
|
@@ -34,10 +34,16 @@ npx @leonidstern/labit reply <id> "Done: …" # answers on the pin
|
|
|
34
34
|
|
|
35
35
|
Or as an MCP server: `npx @leonidstern/labit@latest mcp`.
|
|
36
36
|
|
|
37
|
+
Everything merged to main, before it is released: `npx @leonidstern/labit@next`.
|
|
38
|
+
|
|
39
|
+
**Fewer permission prompts (Claude Code):** copy [examples/claude-settings.json](examples/claude-settings.json) to `.claude/settings.json` in your project (or merge its `permissions` into yours). labit's commands and MCP tools then run without asking; `--wifi` and `invite`, which let another device in, still ask. Claude Code reads a project's allow rules only once you've opened the folder in it and trusted it.
|
|
40
|
+
|
|
37
41
|
## Good to know
|
|
38
42
|
|
|
39
43
|
- `--wifi` lets your phone comment too. Each device opens a one-time link from `npx @leonidstern/labit invite`, so being on the same wifi isn't enough. The pages still travel in the clear over the wifi.
|
|
40
|
-
-
|
|
44
|
+
- Agents learn how you like answers: reply as usual, and when you say an answer was too long or unclear, your message shows **rule?**. Tap it and the rule goes to `~/.config/labit/replies.md`, handed to every agent with your pins.
|
|
45
|
+
- You name yourself once. The name is kept for this computer in `~/.config/labit/settings.json`, so every later lab starts out knowing you — browsers keep it per port, labs don't. `labit invite [name]` carries a name to a phone the same way. `--page /path` makes the link open that page. Opening a used or old link again on a phone that's already in just takes you there, and a phone that keeps using the lab stays in.
|
|
46
|
+
- Settings (port, your dev server, keys, how long the lab waits…): `labit.json` in the project and `~/.config/labit/settings.json` for you. `labit settings` shows them all; [docs/settings.md](docs/settings.md) explains each.
|
|
41
47
|
- Comments stay in `.lab/` in your project. Add it to `.gitignore`.
|
|
42
48
|
- `3` is zoom, on plain HTML pages: a comment that asks your agent for a deeper look into what it's on (3 once) or the bigger picture around it (3 again). `1` comment, `2` go, `4` pointer.
|
|
43
49
|
- No dependencies, Node 22+. `--help` lists everything else.
|
package/api/lab-comments.mjs
CHANGED
|
@@ -303,7 +303,10 @@ function asText(path, comments, host) {
|
|
|
303
303
|
if (a.width) lines.push(`viewport: ${a.width}${a.height ? `×${a.height}` : 'px wide'}${a.dpr ? ` @${a.dpr}x` : ''}`);
|
|
304
304
|
if (a.build) lines.push(`build: ${a.build}`);
|
|
305
305
|
if (a.kind !== 'page') lines.push(`selector (at comment time): ${a.selector || 'body'}`);
|
|
306
|
-
for (const r of comments.filter((r) => r.parent === c.id))
|
|
306
|
+
for (const r of comments.filter((r) => r.parent === c.id)) {
|
|
307
|
+
const rule = r.rule ? ` (kept as rule: ${r.rule})` : r.suggest ? ` (offered as rule: ${r.suggest}${r.suggestDone === 'no' ? ', they said no' : ''})` : '';
|
|
308
|
+
lines.push(`reply: ${r.name}${r.from && r.from !== c.from ? ` (${r.from})` : ''} · ${stamp(r.createdAt)} · id ${r.id}: ${body(r.text)}${rule}`);
|
|
309
|
+
}
|
|
307
310
|
});
|
|
308
311
|
return lines.join('\n') + '\n';
|
|
309
312
|
}
|
|
@@ -429,6 +432,10 @@ export async function POST(request) {
|
|
|
429
432
|
createdAt: new Date().toISOString(),
|
|
430
433
|
resolved: false,
|
|
431
434
|
anchor: parent ? null : cleanAnchor(anchor),
|
|
435
|
+
// The message in the thread this one answers, when it isn't the first (shown as a quote).
|
|
436
|
+
...(parent && body.to ? { to: clean(body.to, 40) } : {}),
|
|
437
|
+
// A rule the agent offers on its own, from a reply about how it answered (labit reply --suggest-rule): kept with a tap.
|
|
438
|
+
...(parent && body.suggest && !limited ? { suggest: cleanText(body.suggest, 200) } : {}),
|
|
432
439
|
};
|
|
433
440
|
// The comment, and the reopened thread when someone (not an admin) answers a resolved one: one round trip.
|
|
434
441
|
if (thread?.resolved && limited) await run('HSET', key, comment.id, JSON.stringify(comment), parent, JSON.stringify({ ...thread, resolved: false, resolvedBy: undefined }));
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// lib/flags.ts
|
|
2
|
+
var FLAGS = {
|
|
3
|
+
liveUrl: { name: "a lab on a live URL", since: "0.6.2" },
|
|
4
|
+
agentPins: { name: "agent pins wear labit's mark", since: "0.6.2" }
|
|
5
|
+
};
|
|
6
|
+
var flagDefaults = () => Object.fromEntries(Object.keys(FLAGS).map((k) => [k, false]));
|
|
7
|
+
var flagsOn = (flags = {}) => Object.keys(FLAGS).filter((k) => flags[k]);
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
FLAGS,
|
|
11
|
+
flagDefaults,
|
|
12
|
+
flagsOn
|
|
13
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// lib/labcall.ts
|
|
2
|
+
import http from "node:http";
|
|
3
|
+
import fs from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
function findLab(from) {
|
|
6
|
+
for (let dir = path.resolve(from); ; dir = path.dirname(dir)) {
|
|
7
|
+
const file = path.join(dir, ".lab/server.json");
|
|
8
|
+
if (fs.existsSync(file)) return { dir, server: JSON.parse(fs.readFileSync(file, "utf8")) };
|
|
9
|
+
if (path.dirname(dir) === dir) return null;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
var labCall = (server, pathname, body, session, signal) => new Promise((resolve, reject) => {
|
|
13
|
+
const data = JSON.stringify(body);
|
|
14
|
+
const req = http.request(
|
|
15
|
+
{
|
|
16
|
+
host: "127.0.0.1",
|
|
17
|
+
port: server.port,
|
|
18
|
+
path: pathname,
|
|
19
|
+
method: "POST",
|
|
20
|
+
signal,
|
|
21
|
+
headers: {
|
|
22
|
+
host: `localhost:${server.port}`,
|
|
23
|
+
"content-type": "application/json",
|
|
24
|
+
"content-length": Buffer.byteLength(data),
|
|
25
|
+
"x-lab-admin": server.token,
|
|
26
|
+
"x-lab-agent": "1",
|
|
27
|
+
"x-lab-session": encodeURIComponent(JSON.stringify(session))
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
(res) => {
|
|
31
|
+
let text = "";
|
|
32
|
+
res.on("data", (c) => text += c);
|
|
33
|
+
res.on("end", () => resolve({ status: res.statusCode || 0, text }));
|
|
34
|
+
}
|
|
35
|
+
);
|
|
36
|
+
req.on("error", reject);
|
|
37
|
+
req.end(data);
|
|
38
|
+
});
|
|
39
|
+
var WAIT_SAID = {
|
|
40
|
+
204: "No new comments yet. Run wait again to keep listening.",
|
|
41
|
+
409: "Another session is listening now; this one stopped.",
|
|
42
|
+
410: "The page was closed, so this stopped listening. Wait again only when the person asks or opens the page."
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export {
|
|
46
|
+
findLab,
|
|
47
|
+
labCall,
|
|
48
|
+
WAIT_SAID
|
|
49
|
+
};
|
|
@@ -1,35 +1,3 @@
|
|
|
1
|
-
// lib/args.ts
|
|
2
|
-
function listenPages(opts, forWait = false) {
|
|
3
|
-
const raw = opts.pages || (forWait ? opts.page : "");
|
|
4
|
-
if (!raw) return null;
|
|
5
|
-
return String(raw).split(",").map((p) => "/" + p.trim().replace(/^\/+/, "").replace(/\.html?$/i, "")).filter((p) => p !== "/");
|
|
6
|
-
}
|
|
7
|
-
var SWITCHES = ["--wifi", "--no-open", "--resolve", "--wait", "--new", "--all", "--fast", "--no-fast"];
|
|
8
|
-
var WRITE_SHORT = "Write answers short: they're read in a small window, often on a phone. One point per line or two, a blank line between points, '- ' lines for lists.";
|
|
9
|
-
var VALUED = ["--port", "--name", "--page", "--pages", "--timeout", "--dir", "--proxy", "--model"];
|
|
10
|
-
function parseArgs(argv) {
|
|
11
|
-
const opts = {};
|
|
12
|
-
const pos = [];
|
|
13
|
-
const unknownFlags = [];
|
|
14
|
-
for (let i = 0; i < argv.length; i++) {
|
|
15
|
-
const a = argv[i];
|
|
16
|
-
if (a === "--") {
|
|
17
|
-
pos.push(...argv.slice(i + 1));
|
|
18
|
-
break;
|
|
19
|
-
}
|
|
20
|
-
if (a === "--help" || a === "-h") opts.help = true;
|
|
21
|
-
else if (a === "--version" || a === "-v") opts.version = true;
|
|
22
|
-
else if (SWITCHES.includes(a)) opts[a.slice(2)] = true;
|
|
23
|
-
else if (a.startsWith("--") && !VALUED.includes(a)) unknownFlags.push(a);
|
|
24
|
-
else if (VALUED.includes(a)) {
|
|
25
|
-
const v = argv[i + 1];
|
|
26
|
-
if (v === void 0 || v.startsWith("-")) opts[a.slice(2)] = true;
|
|
27
|
-
else opts[a.slice(2)] = argv[++i];
|
|
28
|
-
} else pos.push(a);
|
|
29
|
-
}
|
|
30
|
-
return { opts, pos, unknownFlags };
|
|
31
|
-
}
|
|
32
|
-
|
|
33
1
|
// lib/agents.ts
|
|
34
2
|
var AGENTS = {
|
|
35
3
|
amp: { name: "Amp", env: ["AMP_CURRENT_THREAD_ID"] },
|
|
@@ -76,31 +44,9 @@ function mySession(asked, model) {
|
|
|
76
44
|
};
|
|
77
45
|
}
|
|
78
46
|
|
|
79
|
-
// lib/labs.ts
|
|
80
|
-
import fs from "node:fs";
|
|
81
|
-
import os from "node:os";
|
|
82
|
-
import path from "node:path";
|
|
83
|
-
var REGISTRY = path.join(process.env.LABIT_HOME || process.env.LABFB_HOME || path.join(os.homedir(), ".labit"), "servers");
|
|
84
|
-
var runningLabs = () => (fs.existsSync(REGISTRY) ? fs.readdirSync(REGISTRY) : []).filter((n) => n.endsWith(".json")).flatMap((n) => {
|
|
85
|
-
const file = path.join(REGISTRY, n);
|
|
86
|
-
try {
|
|
87
|
-
const lab = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
88
|
-
process.kill(lab.pid, 0);
|
|
89
|
-
return [lab];
|
|
90
|
-
} catch {
|
|
91
|
-
fs.rmSync(file, { force: true });
|
|
92
|
-
return [];
|
|
93
|
-
}
|
|
94
|
-
}).sort((a, b) => a.root.localeCompare(b.root));
|
|
95
|
-
|
|
96
47
|
export {
|
|
97
|
-
listenPages,
|
|
98
|
-
WRITE_SHORT,
|
|
99
|
-
parseArgs,
|
|
100
48
|
AGENTS,
|
|
101
49
|
agentKind,
|
|
102
50
|
agentNow,
|
|
103
|
-
mySession
|
|
104
|
-
REGISTRY,
|
|
105
|
-
runningLabs
|
|
51
|
+
mySession
|
|
106
52
|
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
// lib/args.ts
|
|
2
|
+
function listenPages(opts, forWait = false) {
|
|
3
|
+
const raw = opts.pages || (forWait ? opts.page : "");
|
|
4
|
+
if (!raw) return null;
|
|
5
|
+
return String(raw).split(",").map((p) => "/" + p.trim().replace(/^\/+/, "").replace(/\.html?$/i, "")).filter((p) => p !== "/");
|
|
6
|
+
}
|
|
7
|
+
var SWITCHES = ["--wifi", "--no-open", "--resolve", "--wait", "--new", "--all", "--bg", "--fast", "--no-fast"];
|
|
8
|
+
var FOREGROUND_CAP = 60;
|
|
9
|
+
var WAIT_DEFAULT = 1500;
|
|
10
|
+
function waitSeconds(opts, isTTY = false) {
|
|
11
|
+
const asked = Number(opts.timeout) || WAIT_DEFAULT;
|
|
12
|
+
if (opts.bg || isTTY || process.env.LABIT_BACKGROUND === "1") return { seconds: asked, capped: false };
|
|
13
|
+
return { seconds: Math.min(asked, FOREGROUND_CAP), capped: asked > FOREGROUND_CAP };
|
|
14
|
+
}
|
|
15
|
+
var WRITE_SHORT = "Write answers short: they're read in a small window, often on a phone. One point per line or two, a blank line between points, '- ' lines for lists.";
|
|
16
|
+
var VALUED = ["--port", "--name", "--page", "--pages", "--timeout", "--dir", "--proxy", "--model", "--suggest-rule"];
|
|
17
|
+
function parseArgs(argv) {
|
|
18
|
+
const opts = {};
|
|
19
|
+
const pos = [];
|
|
20
|
+
const unknownFlags = [];
|
|
21
|
+
for (let i = 0; i < argv.length; i++) {
|
|
22
|
+
const a = argv[i];
|
|
23
|
+
if (a === "--") {
|
|
24
|
+
pos.push(...argv.slice(i + 1));
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
if (a === "--help" || a === "-h") opts.help = true;
|
|
28
|
+
else if (a === "--version" || a === "-v") opts.version = true;
|
|
29
|
+
else if (SWITCHES.includes(a)) opts[a.slice(2)] = true;
|
|
30
|
+
else if (a.startsWith("--") && !VALUED.includes(a)) unknownFlags.push(a);
|
|
31
|
+
else if (VALUED.includes(a)) {
|
|
32
|
+
const v = argv[i + 1];
|
|
33
|
+
if (v === void 0 || v.startsWith("-")) opts[a.slice(2)] = true;
|
|
34
|
+
else opts[a.slice(2)] = argv[++i];
|
|
35
|
+
} else pos.push(a);
|
|
36
|
+
}
|
|
37
|
+
return { opts, pos, unknownFlags };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// lib/labs.ts
|
|
41
|
+
import fs from "node:fs";
|
|
42
|
+
import os from "node:os";
|
|
43
|
+
import path from "node:path";
|
|
44
|
+
var REGISTRY = path.join(process.env.LABIT_HOME || path.join(os.homedir(), ".labit"), "servers");
|
|
45
|
+
var runningLabs = () => (fs.existsSync(REGISTRY) ? fs.readdirSync(REGISTRY) : []).filter((n) => n.endsWith(".json")).flatMap((n) => {
|
|
46
|
+
const file = path.join(REGISTRY, n);
|
|
47
|
+
try {
|
|
48
|
+
const lab = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
49
|
+
process.kill(lab.pid, 0);
|
|
50
|
+
return [lab];
|
|
51
|
+
} catch {
|
|
52
|
+
fs.rmSync(file, { force: true });
|
|
53
|
+
return [];
|
|
54
|
+
}
|
|
55
|
+
}).sort((a, b) => a.root.localeCompare(b.root));
|
|
56
|
+
|
|
57
|
+
export {
|
|
58
|
+
listenPages,
|
|
59
|
+
FOREGROUND_CAP,
|
|
60
|
+
waitSeconds,
|
|
61
|
+
WRITE_SHORT,
|
|
62
|
+
parseArgs,
|
|
63
|
+
REGISTRY,
|
|
64
|
+
runningLabs
|
|
65
|
+
};
|
|
@@ -1,11 +1,19 @@
|
|
|
1
1
|
import {
|
|
2
|
+
FOREGROUND_CAP,
|
|
2
3
|
listenPages,
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
} from "./chunk-
|
|
4
|
+
runningLabs,
|
|
5
|
+
waitSeconds
|
|
6
|
+
} from "./chunk-XZUZQFBJ.mjs";
|
|
7
|
+
import {
|
|
8
|
+
WAIT_SAID,
|
|
9
|
+
findLab,
|
|
10
|
+
labCall
|
|
11
|
+
} from "./chunk-LNYMIFDQ.mjs";
|
|
12
|
+
import {
|
|
13
|
+
mySession
|
|
14
|
+
} from "./chunk-X4RYDWNI.mjs";
|
|
6
15
|
|
|
7
16
|
// lib/commands.ts
|
|
8
|
-
import http from "node:http";
|
|
9
17
|
import fs from "node:fs";
|
|
10
18
|
import path from "node:path";
|
|
11
19
|
async function runCommand({ pos, opts, HERE, CMD, ME, die }) {
|
|
@@ -134,46 +142,16 @@ ${links.map((l) => `${l.title || l.url} ${l.url}`).join("\n")}`);
|
|
|
134
142
|
}
|
|
135
143
|
if (["wait", "reply", "resolve", "invite", "zoom"].includes(pos[0])) {
|
|
136
144
|
const [cmd, ref, ...words] = pos;
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
if (path.dirname(dir) === dir) die(`No lab server for this folder. Start one: run ${CMD} in the project.`);
|
|
140
|
-
dir = path.dirname(dir);
|
|
141
|
-
}
|
|
142
|
-
const server = JSON.parse(fs.readFileSync(path.join(dir, ".lab/server.json"), "utf8"));
|
|
145
|
+
const lab = findLab(opts.dir || ".") || die(`No lab server for this folder. Start one: run ${CMD} in the project.`);
|
|
146
|
+
const { dir, server } = lab;
|
|
143
147
|
const session = mySession(opts.name, opts.model);
|
|
144
|
-
const call = (pathname, body) =>
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
port: server.port,
|
|
150
|
-
path: pathname,
|
|
151
|
-
method: "POST",
|
|
152
|
-
headers: {
|
|
153
|
-
host: `localhost:${server.port}`,
|
|
154
|
-
"content-type": "application/json",
|
|
155
|
-
"content-length": Buffer.byteLength(data2),
|
|
156
|
-
"x-lab-admin": server.token,
|
|
157
|
-
"x-lab-agent": "1",
|
|
158
|
-
"x-lab-session": encodeURIComponent(JSON.stringify(session))
|
|
159
|
-
}
|
|
160
|
-
},
|
|
161
|
-
(res) => {
|
|
162
|
-
let text = "";
|
|
163
|
-
res.on("data", (c) => text += c);
|
|
164
|
-
res.on("end", () => resolve({ status: res.statusCode || 0, text }));
|
|
165
|
-
}
|
|
166
|
-
);
|
|
167
|
-
req.on(
|
|
168
|
-
"error",
|
|
169
|
-
() => die(
|
|
170
|
-
process.env.CODEX_SANDBOX_NETWORK_DISABLED ? `Codex's sandbox blocks this command from reaching the lab on this computer (port ${server.port}). Use labit's MCP server instead: codex mcp add labit -- npx @leonidstern/labit@latest mcp. Or let the sandbox reach it: -c sandbox_workspace_write.network_access=true` : `The lab server for ${dir} isn't running. Start it: ${CMD} ${dir === process.cwd() ? "" : dir}`.trim() + "."
|
|
171
|
-
)
|
|
172
|
-
);
|
|
173
|
-
req.end(data2);
|
|
174
|
-
});
|
|
148
|
+
const call = (pathname, body) => labCall(server, pathname, body, session).catch(
|
|
149
|
+
() => die(
|
|
150
|
+
process.env.CODEX_SANDBOX_NETWORK_DISABLED ? `Codex's sandbox blocks this command from reaching the lab on this computer (port ${server.port}). Use labit's MCP server instead: codex mcp add labit -- npx @leonidstern/labit@latest mcp. Or let the sandbox reach it: -c sandbox_workspace_write.network_access=true` : `The lab server for ${dir} isn't running. Start it: ${CMD} ${dir === process.cwd() ? "" : dir}`.trim() + "."
|
|
151
|
+
)
|
|
152
|
+
);
|
|
175
153
|
if (cmd === "invite") {
|
|
176
|
-
const out = await call("/_lab/invite", { name: [ref, ...words].filter(Boolean).join(" ") });
|
|
154
|
+
const out = await call("/_lab/invite", { name: [ref, ...words].filter(Boolean).join(" "), page: opts.page || "" });
|
|
177
155
|
if (out.status === 404) die("This lab is open to this computer only. Start it with --wifi to let a phone in.");
|
|
178
156
|
if (out.status >= 300) die(`Could not make a link: ${out.text}`);
|
|
179
157
|
const { links, name } = JSON.parse(out.text);
|
|
@@ -184,11 +162,14 @@ The device that opens it is ${name} in this lab.`);
|
|
|
184
162
|
process.exit(0);
|
|
185
163
|
}
|
|
186
164
|
if (cmd === "wait") {
|
|
187
|
-
const
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
165
|
+
const { seconds, capped } = waitSeconds(opts, process.stdout.isTTY === true);
|
|
166
|
+
const out = await call("/_lab/wait", { timeout: seconds, pages: listenPages(opts, true) });
|
|
167
|
+
console.log(WAIT_SAID[out.status] ?? out.text);
|
|
168
|
+
if (capped && out.status === 204)
|
|
169
|
+
console.log(
|
|
170
|
+
`
|
|
171
|
+
That wait was held to ${FOREGROUND_CAP} seconds. Run it in the background (your app's own way of doing that) and add --bg for the full wait: in the foreground this command holds your turn open, and the person cannot say anything to you until it ends.`
|
|
172
|
+
);
|
|
192
173
|
process.exit(out.status < 300 || out.status === 409 || out.status === 410 ? 0 : 1);
|
|
193
174
|
}
|
|
194
175
|
const data = {};
|
|
@@ -204,7 +185,7 @@ The device that opens it is ${name} in this lab.`);
|
|
|
204
185
|
}
|
|
205
186
|
const want = opts.page ? "/" + opts.page.replace(/^\/+/, "") : null;
|
|
206
187
|
let hit = null;
|
|
207
|
-
for (const [page, list] of Object.entries(data)) if (list[ref]) hit = { page, id: list[ref].parent || ref };
|
|
188
|
+
for (const [page, list] of Object.entries(data)) if (list[ref]) hit = { page, id: list[ref].parent || ref, to: list[ref].parent ? ref : "" };
|
|
208
189
|
if (!hit && /^\d+$/.test(ref || "")) {
|
|
209
190
|
const hits = Object.entries(data).filter(([page]) => !want || page === want).map(([page, list]) => {
|
|
210
191
|
const open = Object.values(list).filter((c) => !c.parent && !c.resolved).sort((a, b) => a.createdAt.localeCompare(b.createdAt));
|
|
@@ -235,7 +216,7 @@ The device that opens it is ${name} in this lab.`);
|
|
|
235
216
|
if (!words.length) die(`Reply text is missing: ${CMD} reply <id> "what you did"`);
|
|
236
217
|
const who = process.env.LAB_AGENT_NAME || session.agent;
|
|
237
218
|
const name = `${who}${session.name !== session.agent ? ` \xB7 ${session.name}` : ""}`;
|
|
238
|
-
const out = await call("/_lab/api/comments", { page: hit.page, parent: hit.id, name, text: words.join(" ") });
|
|
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"] } : {} });
|
|
239
220
|
if (out.status >= 300) die(`Could not reply: ${out.text}`);
|
|
240
221
|
}
|
|
241
222
|
if (cmd === "resolve" || opts.resolve) {
|
|
@@ -244,8 +225,12 @@ The device that opens it is ${name} in this lab.`);
|
|
|
244
225
|
}
|
|
245
226
|
console.log(`${cmd === "reply" ? opts.resolve ? "Replied and resolved" : "Replied" : "Resolved"} on ${hit.page}.`);
|
|
246
227
|
if (opts.wait) {
|
|
247
|
-
const
|
|
248
|
-
|
|
228
|
+
const { seconds, capped } = waitSeconds(opts, process.stdout.isTTY === true);
|
|
229
|
+
const out = await call("/_lab/wait", { timeout: seconds, pages: listenPages(opts) });
|
|
230
|
+
console.log(WAIT_SAID[out.status] ?? out.text);
|
|
231
|
+
if (capped && out.status === 204)
|
|
232
|
+
console.log(`
|
|
233
|
+
That wait was held to ${FOREGROUND_CAP} seconds: run the command in the background and add --bg for the full wait.`);
|
|
249
234
|
}
|
|
250
235
|
process.exit(0);
|
|
251
236
|
}
|