@leonidstern/labit 0.6.0 → 0.6.2
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 +66 -0
- package/README.md +24 -125
- package/api/lab-comments.mjs +16 -2
- package/dist/chunk-DIR2O7SK.mjs +13 -0
- package/dist/chunk-LNYMIFDQ.mjs +49 -0
- package/dist/chunk-X4RYDWNI.mjs +52 -0
- package/dist/chunk-XZUZQFBJ.mjs +65 -0
- package/dist/commands-LAQNMF2X.mjs +240 -0
- package/dist/devserver-KCLPMBNL.mjs +56 -0
- package/dist/flags-PGKWZHJC.mjs +10 -0
- package/dist/local.mjs +1631 -0
- package/dist/mcp-4UPGXLZR.mjs +236 -0
- package/dist/proxy-FLFZV6EI.mjs +74 -0
- package/dist/settings-XLFKONNN.mjs +175 -0
- package/package.json +8 -6
- package/public/_lab/comments.js +30 -3592
- package/public/_lab/favicon.svg +1 -0
- package/public/_lab/lab.css +12 -0
- package/skills/labit/SKILL.md +7 -3
- package/skills/labit/zoom.md +29 -0
- package/lib/dev.mjs +0 -128
- package/lib/devserver.mjs +0 -58
- package/lib/mcp.mjs +0 -207
- package/lib/proxy.mjs +0 -73
- package/local.mjs +0 -1552
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,72 @@ 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
|
+
|
|
29
|
+
## 0.6.1 · 2026-11-16
|
|
30
|
+
|
|
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.
|
|
32
|
+
- The page list: newest first, each page with its open comments and when it last changed, a summary line under the folder's name, and a filter once there are more than 8 pages (`/` to focus it).
|
|
33
|
+
- A flat drag no longer draws a green hairline across the page. Marking an area by dragging sideways (or straight down) made a rectangle with no height, which read as a line through everything rather than as something being marked. The outline now keeps a least size of 12 px each way while you drag — the size the saved area was already grown to.
|
|
34
|
+
- The bar: hover, pressed and "its menu is open" (⋯) use the first grey step after white, not the second, which read as a dirty block on the white bar; menu rows the same. The mode switch's "off" pin (3, cursor) is the pin of 1 now (white, the pins' thin edge, bold letters) with the word in grey; it had a thicker, darker ring.
|
|
35
|
+
- Zoom in the widget: 3 zooms in, 3 again zooms out (the pointer moves to 4; on phones a tap on the switch steps comment → go → in → out). A zoom is placed at once like a go, its pin shows arrows in or out, Command-Z takes it back, and the page scrolls to the block when it lands.
|
|
36
|
+
- A `#id` in a message links to that block on the page.
|
|
37
|
+
- Zoom, the lab side (plain HTML pages): a comment with `zoom: in` or `zoom: out` asks the agent for one block, a deeper look or the bigger picture, not a change. The agent hands it over with `labit zoom <id> <file>`; the lab places it next to the section the comment is in (a deeper look after, a bigger picture above) and names it; the agent's reply closes the zoom. Rules for agents: `skills/labit/zoom.md`. The widget's keys come next.
|
|
38
|
+
- Phones: the mark on the chat button sits on the word's baseline, 6 px from it (it hung 3 px low and 9 px away), and every sheet's grab handle is a pill with round ends.
|
|
39
|
+
- The widget ships minified again, its stylesheet too: 218 → 138 KB, 58.2 → 43.9 KB gzipped, 50.2 → 39.3 KB brotli. Minifying was built on 15 Nov and lost when that work moved onto main (#41). `npm run build` runs `scripts/build-widget.mjs` (esbuild's API through npx, still no dependencies), which also minifies `styles.css` as it goes in. The readable source stays `src/`.
|
|
40
|
+
- A tap on the "talking to" pill no longer copies the agent's resume command: it only says who listens.
|
|
41
|
+
- The page says which model the agent runs on: "talking to Claude · Sonnet 5.5 (project)". The agent says it with `wait --model "Sonnet 5.5"` (or the MCP `wait` tool's `model`); without it, LAB_MODEL or ANTHROPIC_MODEL when set, an id like claude-sonnet-5-5 read as "Sonnet 5.5". The skill now asks agents to pass it.
|
|
42
|
+
- Go for guests: with go on and no name saved yet (a guest's first pin), the hold opens a small card that asks only your name, with "go" already in it; send and it's a go pin. It used to open the full comment box, and nothing sent until you typed a comment too. Once the name is saved, a go hold sends straight away as before. On phones a hold now pins after 0.4 s (was 0.5 s): at 0.5 s it raced iOS's own long press, which sometimes selected text instead.
|
|
43
|
+
- Your name is remembered for this computer, not for one lab. The browser keeps it per origin and every lab takes its own port, so naming yourself in one lab left you a stranger in the next. Now the lab keeps the name you give in `~/.config/labit/me.json` (`XDG_CONFIG_HOME` is honoured) and hands it to the widget, so the next lab starts out knowing you. Phones too: `labit invite [name]` bakes a name into the one-time link — the one you give, or yours — and the device that opens it starts out named.
|
|
44
|
+
- On a phone, a tap on the send arrow sends on the first try. The arrow keeps the cursor in the box by preventing the default on pointerdown, and a prevented pointerdown can swallow the click that follows — the tap then only moved focus, the box went back to its one line, and it took a second tap to send. A touch now sends from the touch itself, and the click that may follow it is ignored.
|
|
45
|
+
- A comment you sent no longer comes back in the box. The kept draft was let go after the send, and posting redraws the box, so the new one read the words straight back in. It is let go before the send now, and handed back only if the send fails.
|
|
46
|
+
- New in the ⋯ menu: **pin over controls**. The page's own links and buttons keep their clicks, so a demo still works while comments are on — with this on they do not, and a click there places a comment, as option-click always has. Remembered per browser.
|
|
47
|
+
- While you are writing a comment, the page's own pointer is back. The crosshair (and the drawn pin that follows the mouse) said a click would drop another comment, mid-sentence, which is never what you meant. It returns the moment the box is empty again.
|
|
48
|
+
- While there are words in a box that you have not sent, the dev server's reload waits. Behind a dev server the lab now puts a small holder at the top of every page: it keeps a reload message until the last box is empty again (sent or cleared), then hands it on, so the page is never more than one comment behind and you never lose your place mid-sentence.
|
|
49
|
+
- A comment you are part-way through writing survives the page reloading under you. A dev server rebuilding the page (or a crash, or a tab closed by mistake) used to take the words with it. Now what is typed is kept as you type — per page, per thread — and comes back with it: a reply reopens its thread, and an unsent new comment comes back with its pin, on the spot you put it. It is dropped the moment it is sent.
|
|
50
|
+
- labit has a mark (our pin as a head, two slabs as ears) and uses it: the bar's listening pill shows it instead of a dot (dark with a blink now and then while an agent listens, green with twitching ears while one works, grey and still when nobody listens; same pill size), and on phones it sits on the chat button. The lab's own screens (page list, not found, the one-time-link screen) open with it. A page with no tab icon of its own gets labit's in a local lab. The README carries it beside the name.
|
|
51
|
+
- A pin whose element is gone now waits beside the content (in the gutter left of what it sat in), not 10 px from the window's left edge. On a wide window with a centred column those pins were hundreds of px from the page and read as lost. Phones and full-width pages are unchanged.
|
|
52
|
+
- Computers: a click on the page's own controls is the page's, and the pin pointer steps aside over them: links and buttons as before, and now anything the page gives a hand pointer (a card, a demo you tap to play). Option-click still pins there.
|
|
53
|
+
- Pause motion (⋯ menu, P): everything that moves on the page stops where it is, so you can pin a moment of an animation; again to play on.
|
|
54
|
+
- Phones move more like native sheets (checked frame by frame in the iOS 27 simulator):
|
|
55
|
+
- Closing a sheet with the keyboard up takes the keyboard with it at once; the keyboard used to stay alone for 0.6 s after the sheet was gone.
|
|
56
|
+
- After you send, the sheet slides off with the keyboard; it used to ride the keyboard halfway down and vanish mid-screen.
|
|
57
|
+
- The dimmed page fades with the sheet's position, as it slides and while a finger drags it; it used to be gone while most of the sheet was still up.
|
|
58
|
+
- The first sheet after the page loads slides in; it used to show up already open.
|
|
59
|
+
- A new pin low on the page scrolls up above the sheet, so you see what you're commenting on.
|
|
60
|
+
- A pin's state change (Claude on it, done, a reply) eases in, and the ring fades in and out; they used to be cuts.
|
|
61
|
+
- Tapping "your name" no longer drops the sheet behind the keyboard, and Safari no longer offers "AutoFill Contact" there.
|
|
62
|
+
- The bar's buttons no longer stay grey after a tap.
|
|
63
|
+
- Pins keep their look but take a 44 pt tap: a finger near one opens it (they were 22 pt to hit).
|
|
64
|
+
- Sheets float as cards, as iOS 27's do: inset from the screen's edges, round at every corner, the page behind not dimmed. A tapped sheet grows out of what you tapped and shrinks back into it (after a send, into the new pin); a swipe still slides it down.
|
|
65
|
+
- The new comment card moves up with the keyboard instead of jumping there.
|
|
66
|
+
- From the motion lab (Leo's picks): after a send the card flies into the new pin, which pops in (B2), the keyboard waiting until it lands; the send arrow turns dark with a tiny pop when you start typing (A5); Claude's ring draws its arc in (C2).
|
|
67
|
+
|
|
68
|
+
- The widget is split into TypeScript modules in `src/widget/`: `composer` (the message box), `messages`, `list`, `chat`, `thread`, `sheets` (phone sheets, back gesture, keyboard fit) and `live` (live page updates), beside `anchoring` and `styles`. Its shared state is one object, so the parts can share it. Same behaviour; `src/comments.js` keeps setup, loading, drawing and the events (2,688 → 1,428 lines).
|
|
69
|
+
|
|
70
|
+
- The server is moving to TypeScript: all of `lib/` is TypeScript now (`dev`, `devserver`, `mcp`, `proxy`), and `local.mjs` hands its command line (`args`), agent detection (`agents`), the running-labs list (`labs`) and the commands that answer and exit (`commands`: preview, add, list, pages, wait, reply, resolve, invite) to their own files; it keeps the server. Node runs the `.ts` source directly while working on labit; npm gets a built copy, `dist/` (made by `npm run build:cli` before every pack), so the package stays plain JavaScript with no dependencies, now 109 kB instead of 120 kB.
|
|
71
|
+
- A phone on a `--wifi` lab now needs a one-time link (`labit invite`): one use, ten minutes, after which that browser keeps a signed cookie for a day. Being on the same wifi is no longer enough, so finding the port on a public network shows a gate and nothing else. The pages still travel unencrypted over the wifi.
|
|
72
|
+
|
|
7
73
|
## 0.6.0 · 2026-11-16
|
|
8
74
|
|
|
9
75
|
- New npm name: `@leonidstern/labit` (`npx @leonidstern/labit`; npm turned down the plain name `labit` as too close to `lab` and `lit`). The `labit` and `labfb` commands both work once installed. The GitHub repo is now leonidstern/labit (old links redirect).
|
package/README.md
CHANGED
|
@@ -1,154 +1,53 @@
|
|
|
1
|
-
|
|
1
|
+
<h1><picture><source media="(prefers-color-scheme: dark)" srcset="docs/labit-mark-dark.svg"><img src="docs/labit-mark-light.svg" alt="" width="34" height="34" align="top"></picture> labit</h1>
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@leonidstern/labit) [](https://github.com/leonidstern/labit/actions/workflows/test.yml) [](LICENSE)
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Pin comments on pages, and your agent reads them as plain text. Use it on a live domain where anyone with the link can comment, or on your own computer, where your agent (Claude, Codex, Cursor…) answers on the pins while it works.
|
|
8
|
-
|
|
9
|
-
**Small, no dependencies, runs in any folder.** labit uses only Node 22+ itself: no packages to install, about 120 kB on npm, 15 files. Run `npx @leonidstern/labit` in any project or folder: nothing goes into your project's dependencies or code, and it works with any stack, from plain HTML to Astro, Next or Vite.
|
|
5
|
+
**Review is the new build.** Pin comments on your pages. Your coding agent reads them, changes the code, and answers on the pin.
|
|
10
6
|
|
|
11
7
|

|
|
12
8
|
|
|
13
|
-
##
|
|
14
|
-
|
|
15
|
-
**Cloud lab**: pages on a domain, for people you share links with
|
|
16
|
-
- **No account:** anyone with the link clicks anywhere, types a name and comments.
|
|
17
|
-
- **One link for your agent:** "copy link" gives plain text with every open comment. Paste it into any agent and it goes to the file.
|
|
18
|
-
- **Knows what's under the pin:** the quoted words, the element, the image file and pixel, the code line, the video second; on a dev build, the component and the file and line that wrote it. No screenshots needed.
|
|
19
|
-
- **One domain, many repos:** the lab domain only proxies `/<name>/*` to each member's own repo and Vercel project.
|
|
20
|
-
- **Admin links per person:** let someone resolve and delete on their pages only. Nothing to set up per person.
|
|
21
|
-
|
|
22
|
-
**Local lab**: pages on your computer, for you and Claude
|
|
23
|
-
- **No deploy:** run `npx @leonidstern/labit@latest` in your project. It finds your running Astro, Next or Vite dev server and puts comments on top, or serves plain HTML files.
|
|
24
|
-
- **Your agent answers on the pin:** it hears each comment as you post it, edits the file, the page reloads, and the reply shows on the pin.
|
|
25
|
-
- **Shows who is listening:** the label says whether Claude is listening or working. Close the page and Claude waits quietly: your first comment when you're back wakes it, and it stops after an hour.
|
|
26
|
-
- **Phone too:** `--wifi` lets a phone at home join. Comments stay in `.lab/`, one store per project.
|
|
9
|
+
## Start
|
|
27
10
|
|
|
28
|
-
|
|
11
|
+
In your project:
|
|
29
12
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
Paste this into your agent. It is the whole setup.
|
|
33
|
-
|
|
34
|
-
```text
|
|
35
|
-
Set up labit (https://github.com/leonidstern/labit) for me on Vercel.
|
|
36
|
-
|
|
37
|
-
0. First check whether I already have a lab (a Vercel project with LAB_HOST set, or a site that loads /_lab/comments.js). If I do, stop and tell me: add sites to that one instead.
|
|
38
|
-
1. Fork the repo and import it into Vercel: framework preset "Other", no build command.
|
|
39
|
-
2. Add Upstash Redis from the Vercel Marketplace (free tier). It sets KV_REST_API_URL and KV_REST_API_TOKEN.
|
|
40
|
-
3. Set env vars: LAB_HOST=<lab domain, e.g. lab.example.com> and LAB_COMMENTS_ADMIN_TOKEN=<output of `openssl rand -hex 24`>. Tell me the token. Redeploy so the variables apply.
|
|
41
|
-
4. Add <lab domain> to the Vercel project and tell me the DNS record to create.
|
|
42
|
-
5. For each site that should get comments (slug = a short name, e.g. anna):
|
|
43
|
-
- serve it under the base path /<slug> (Astro `base`, Next `basePath`, Vite `base`) from its own Vercel project; every page answers 200, no redirects
|
|
44
|
-
- add two rewrites to labit's vercel.json:
|
|
45
|
-
{ "source": "/<slug>", "destination": "https://<their-project>.vercel.app/<slug>" },
|
|
46
|
-
{ "source": "/<slug>/:path*", "destination": "https://<their-project>.vercel.app/<slug>/:path*" }
|
|
47
|
-
- add this to the site's shared layout, before </body>:
|
|
48
|
-
<script src="https://<lab domain>/_lab/comments.js" defer></script>
|
|
49
|
-
- put pages at /<slug>/<project>/<secret>/<page>, where <secret> is 10 random characters per project; mark them noindex and link to them from nowhere
|
|
50
|
-
- deploy it with prebuilt deploys: add "ship": "npx --yes vercel build --prod --yes && npx --yes vercel deploy --prebuilt --prod --yes"
|
|
51
|
-
to its package.json scripts and "git": { "deploymentEnabled": false } to its vercel.json, so `npm run ship` builds on my computer
|
|
52
|
-
and is live in seconds, and a push only keeps the history (link it once: `npx vercel link`)
|
|
53
|
-
6. Once I confirm the DNS works: POST a test comment with curl to https://<lab domain>/_lab/api/comments
|
|
54
|
-
({"page":"/_lab/demo","name":"setup","text":"test"}, content-type application/json) and check that
|
|
55
|
-
https://<lab domain>/_lab/agent/_lab/demo shows it as text. Then delete it with header x-lab-admin: <token>.
|
|
13
|
+
```sh
|
|
14
|
+
npx @leonidstern/labit@latest
|
|
56
15
|
```
|
|
57
16
|
|
|
58
|
-
|
|
59
|
-
- **Read:** `https://<lab domain>/_lab/agent/<page path>` returns every open comment as plain text. Paste it into your agent.
|
|
60
|
-
- **Resolve or delete:** open any page once with `#lab-admin=<token>`.
|
|
61
|
-
- **Deploys:** each site ships with `npm run ship` (built on your computer, uploaded with `vercel deploy --prebuilt`, live in about 6 s for a small Astro site); pushes don't deploy. Ship what you commit.
|
|
62
|
-
- **Admins:** ask your agent "make a lab admin link for anna on /anna". With your token it gets a link that lets anna resolve and delete comments on `/anna` pages only. One browser can hold links for several labs. Nothing to set up per person (how: top of `api/lab-comments.mjs`).
|
|
17
|
+
It finds your running dev server (Astro, Next, Vite…) or serves plain HTML, and opens the page with comments on top. Click to comment, drag to mark an area. `M` hides the comments.
|
|
63
18
|
|
|
64
|
-
##
|
|
19
|
+
## Let your agent answer
|
|
65
20
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
```text
|
|
69
|
-
Start labit (https://github.com/leonidstern/labit) on this project and listen to my comments.
|
|
70
|
-
|
|
71
|
-
1. Run `npx @leonidstern/labit@latest` here in the background. It finds this project's dev server, or serves plain HTML files.
|
|
72
|
-
If it says the dev server isn't running, start it the way this project does, then run it again. Never stop other servers.
|
|
73
|
-
2. Run `npx @leonidstern/labit wait` in the background, with --name set to this project's name. It ends with my next comment.
|
|
74
|
-
3. For each comment, change what it asks, then answer on the pin: `npx @leonidstern/labit reply <id> "Done: …"`, with the id
|
|
75
|
-
that wait printed. Add --resolve when it's fully done; if you need something from me, ask in the reply instead.
|
|
76
|
-
4. Run wait again right away. Stop when wait says the page was closed.
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
Using it often? Install the plugin once, then just say **"start labit"** in any project. With the plugin, **"use lab"** also makes Claude show new pages in labit instead of an Artifact:
|
|
21
|
+
**Claude Code:** install the plugin once, then say **"start labit"** in any project.
|
|
80
22
|
|
|
81
23
|
```text
|
|
82
24
|
/plugin marketplace add leonidstern/labit
|
|
83
25
|
/plugin install labit@leonidstern
|
|
84
26
|
```
|
|
85
27
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
- **Dev server (Astro, Next, Vite…):** start it as usual. labit finds the one running from this project, even with other projects' servers running, and puts comments on top. `--proxy 4321` picks a port yourself.
|
|
89
|
-
- **Plain HTML files:** served as they are. Pages somewhere else: `npx @leonidstern/labit@latest dist`.
|
|
90
|
-
|
|
91
|
-
- **Comment:** press `m` (or hold Option) and click. Drag to mark an area.
|
|
92
|
-
- **One lab per project:** `npx @leonidstern/labit list` shows the labs running on your computer. Starting one in a folder that a running lab already serves opens that lab instead (`--new` starts a separate one anyway).
|
|
93
|
-
- **This project's pages:** `npx @leonidstern/labit pages` writes `.lab/lab-pages.md`, the project's lab pages as links with open comment counts (`--all` for every lab on your computer). `npx @leonidstern/labit add <url>` adds a cloud lab page to the project's list. Claude sends it to you, so in the desktop app it sits under Outputs.
|
|
94
|
-
- **Which model listens:** the session you start decides it. Start it with `claude --model sonnet`, or `/model` in a running session.
|
|
95
|
-
- **MCP (optional):** `npx @leonidstern/labit@latest mcp` is an MCP server with three tools, `comments`, `reply` and `wait`, for the lab in the folder the agent runs in (`comments` also reads a cloud lab page by its address). In Claude Code, once for all your projects: `claude mcp add -s user labit -- npx @leonidstern/labit@latest mcp`. The `wait` command stays the quickest way to hear a pin as it's posted.
|
|
96
|
-
- **Options:** `--wifi` lets a phone at home join. `npx @leonidstern/labit preview` opens it in the Claude desktop app's preview pane. `--help` has the rest.
|
|
97
|
-
- **Files:** comments stay in `.lab/` in the project. Delete it to start over. Add `.lab/` to `.gitignore`.
|
|
98
|
-
|
|
99
|
-
## Other agents
|
|
100
|
-
|
|
101
|
-
labit works with any agent that can use a terminal or MCP. Comments are plain text, the local loop is a few shell commands, and the skill is in the shared Agent Skills format.
|
|
102
|
-
|
|
103
|
-
- **The plugin (skill + MCP server):**
|
|
104
|
-
- Codex: `codex plugin marketplace add leonidstern/labit`, then `codex plugin add labit@leonidstern`.
|
|
105
|
-
- Cursor: add the repo as a plugin (Dashboard → Plugins & MCPs → Import from Repo), or copy it to `~/.cursor/plugins/local/labit`.
|
|
106
|
-
- Copilot CLI: `copilot plugin marketplace add leonidstern/labit` (it reads the Claude plugin files).
|
|
107
|
-
- Others with Agent Plugins: `plugin.json` and `mcp.json` at the repo root.
|
|
108
|
-
- **Just the skill:** `npx skills add leonidstern/labit` puts it where your agent reads skills (`.agents/skills/` for most). Then "start labit" works as in Claude. To point every session at it, add to your `AGENTS.md`:
|
|
109
|
-
```md
|
|
110
|
-
Pin comments on pages: labit. Say "start labit" to listen; see .agents/skills/labit/SKILL.md.
|
|
111
|
-
```
|
|
112
|
-
- **Cloud lab:** give the agent the `/_lab/agent/<page path>` link. It's plain text with every open comment.
|
|
113
|
-
- **Local lab:** paste the prompt from [Local lab](#local-lab), or use the skill. labit tells the agent apart by itself: the page says "talking to Codex", and replies are signed "Codex".
|
|
114
|
-
- **Agents that aren't woken when a background command ends** (Codex, Antigravity): run `wait --timeout 50` in the foreground, in a loop. The MCP `wait` returns after 50 seconds by default for the same reason (Codex and Cursor stop tool calls at 60).
|
|
115
|
-
|
|
116
|
-
| Agent | Known by | MCP | Back to the session |
|
|
117
|
-
|---|---|---|---|
|
|
118
|
-
| Claude Code | `CLAUDECODE` | `claude mcp add labit -- npx @leonidstern/labit@latest mcp` | link, or `claude --resume` |
|
|
119
|
-
| Codex | `CODEX_THREAD_ID` | `codex mcp add labit -- npx @leonidstern/labit@latest mcp` | `codex resume <id>` (tap the label to copy) |
|
|
120
|
-
| Cursor | `CURSOR_AGENT` | its MCP settings | |
|
|
121
|
-
| Amp | `AMP_CURRENT_THREAD_ID` | its MCP settings | thread link |
|
|
122
|
-
| opencode | `OPENCODE_CLIENT` | its MCP settings | |
|
|
123
|
-
| Antigravity | `ANTIGRAVITY_AGENT` | its MCP settings | |
|
|
124
|
-
| Copilot CLI | set `LAB_AGENT=copilot` | its MCP settings | |
|
|
125
|
-
|
|
126
|
-
- **Choose:** `LAB_AGENT=<name>` overrides who is listening (any name), and `LAB_AGENT_NAME` signs replies.
|
|
127
|
-
- **Codex's sandbox:** if `wait` or `reply` can't reach the lab, labit says so. Use the MCP tools, or allow it: `-c sandbox_workspace_write.network_access=true`.
|
|
28
|
+
**Any other agent:** tell it to run these in your project.
|
|
128
29
|
|
|
129
30
|
```sh
|
|
130
|
-
npx @leonidstern/labit
|
|
131
|
-
npx @leonidstern/labit reply <id> "Done: …"
|
|
31
|
+
npx @leonidstern/labit wait # ends with your next comment
|
|
32
|
+
npx @leonidstern/labit reply <id> "Done: …" # answers on the pin
|
|
132
33
|
```
|
|
133
34
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
## Updating
|
|
137
|
-
|
|
138
|
-
- **The command:** start labit with `npx @leonidstern/labit@latest` and npx fetches the newest version (plain `npx @leonidstern/labit` may reuse an older copy it keeps). When a newer one is out, labit says so as it starts; it checks npm at most once a day. `LABIT_NO_UPDATE_CHECK=1` turns that off.
|
|
139
|
-
- **The Claude Code plugin:** `claude plugin marketplace update leonidstern`, then `claude plugin update labit@leonidstern`.
|
|
140
|
-
- **The MCP server:** added with `@latest` (as above), it starts the newest version each time.
|
|
141
|
-
- **Your cloud lab:** sync your fork of labit with this repo on GitHub ("Sync fork") and redeploy; every site on the lab gets the new widget from the lab domain.
|
|
35
|
+
Or as an MCP server: `npx @leonidstern/labit@latest mcp`.
|
|
142
36
|
|
|
143
|
-
|
|
37
|
+
Everything merged to main, before it is released: `npx @leonidstern/labit@next`.
|
|
144
38
|
|
|
145
|
-
|
|
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.
|
|
146
40
|
|
|
147
|
-
|
|
148
|
-
- **Theme:** set `--lab-accent`, `--lab-bg`, `--lab-fg`, `--lab-radius` or `--lab-font` on `[data-lab-comments]`.
|
|
41
|
+
## Good to know
|
|
149
42
|
|
|
150
|
-
|
|
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.
|
|
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.
|
|
47
|
+
- Comments stay in `.lab/` in your project. Add it to `.gitignore`.
|
|
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.
|
|
49
|
+
- No dependencies, Node 22+. `--help` lists everything else.
|
|
151
50
|
|
|
152
|
-
|
|
51
|
+
Shared labs on a domain (comments from people you send a link to) come later.
|
|
153
52
|
|
|
154
53
|
MIT · made by [leonidstern](https://github.com/LeonidStern) · [OOZE](https://ooze.design)
|
package/api/lab-comments.mjs
CHANGED
|
@@ -160,6 +160,9 @@ function cleanAnchor(a) {
|
|
|
160
160
|
time: sec(a.time),
|
|
161
161
|
duration: sec(a.duration),
|
|
162
162
|
context: clean(a.context, MAX.context) || undefined, // older widget versions
|
|
163
|
+
// Zoom (lib/zoom.ts): the nearest element with an id around the spot, and on a zoom its direction.
|
|
164
|
+
block: /^[A-Za-z][\w:.-]{0,119}$/.test(a.block || '') ? a.block : undefined,
|
|
165
|
+
zoom: a.zoom === 'in' || a.zoom === 'out' ? a.zoom : undefined,
|
|
163
166
|
};
|
|
164
167
|
if (a.quote && typeof a.quote === 'object') {
|
|
165
168
|
const exact = clean(a.quote.exact, 300); // selected words can run long; a click quotes one word
|
|
@@ -287,6 +290,8 @@ function asText(path, comments, host) {
|
|
|
287
290
|
if (a.chosen) lines.push(`chosen option: ${a.chosen}`);
|
|
288
291
|
if (a.cssText) lines.push(`text added by CSS: ${a.cssText} (search the CSS for it)`);
|
|
289
292
|
if (a.section) lines.push(`section: "${a.section}"`);
|
|
293
|
+
if (a.block) lines.push(`block: ${a.block}`);
|
|
294
|
+
if (a.zoom) lines.push(a.zoom === 'out' ? 'zoom: out, the bigger picture (not a change request: write one block that shows the bigger picture this block sits in; see the zoom skill)' : 'zoom: in, dive deeper (not a change request: write one block that goes deeper into this block; see the zoom skill)');
|
|
290
295
|
if (a.zw) {
|
|
291
296
|
lines.push(`type: area comment, ${a.docW}×${a.docH} px on screen`);
|
|
292
297
|
lines.push(`area on element: ${pct(a.x)}–${pct(a.x + a.zw)} across, ${pct(a.y)}–${pct(a.y + a.zh)} down`);
|
|
@@ -298,7 +303,10 @@ function asText(path, comments, host) {
|
|
|
298
303
|
if (a.width) lines.push(`viewport: ${a.width}${a.height ? `×${a.height}` : 'px wide'}${a.dpr ? ` @${a.dpr}x` : ''}`);
|
|
299
304
|
if (a.build) lines.push(`build: ${a.build}`);
|
|
300
305
|
if (a.kind !== 'page') lines.push(`selector (at comment time): ${a.selector || 'body'}`);
|
|
301
|
-
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
|
+
}
|
|
302
310
|
});
|
|
303
311
|
return lines.join('\n') + '\n';
|
|
304
312
|
}
|
|
@@ -359,7 +367,9 @@ export async function POST(request) {
|
|
|
359
367
|
if (!current) return json({ error: 'not found' }, 404);
|
|
360
368
|
const thread = JSON.parse(current);
|
|
361
369
|
if (thread.parent || !body.anchor || typeof body.anchor !== 'object') return json({ error: 'bad move' }, 400);
|
|
362
|
-
const
|
|
370
|
+
const anchor = cleanAnchor(body.anchor);
|
|
371
|
+
if (thread.anchor?.zoom && !anchor.zoom) anchor.zoom = thread.anchor.zoom; // a moved zoom stays a zoom, whatever the widget sent
|
|
372
|
+
const comment = { ...thread, anchor, movedAt: new Date().toISOString() };
|
|
363
373
|
await run('HSET', key, id, JSON.stringify(comment));
|
|
364
374
|
return json({ comment });
|
|
365
375
|
}
|
|
@@ -422,6 +432,10 @@ export async function POST(request) {
|
|
|
422
432
|
createdAt: new Date().toISOString(),
|
|
423
433
|
resolved: false,
|
|
424
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) } : {}),
|
|
425
439
|
};
|
|
426
440
|
// The comment, and the reopened thread when someone (not an admin) answers a resolved one: one round trip.
|
|
427
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
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// lib/agents.ts
|
|
2
|
+
var AGENTS = {
|
|
3
|
+
amp: { name: "Amp", env: ["AMP_CURRENT_THREAD_ID"] },
|
|
4
|
+
codex: { name: "Codex", env: ["CODEX_THREAD_ID", "CODEX_SANDBOX", "CODEX_SANDBOX_NETWORK_DISABLED"] },
|
|
5
|
+
cursor: { name: "Cursor", env: ["CURSOR_AGENT"] },
|
|
6
|
+
antigravity: { name: "Antigravity", env: ["ANTIGRAVITY_AGENT"] },
|
|
7
|
+
gemini: { name: "Gemini", env: ["GEMINI_CLI"] },
|
|
8
|
+
opencode: { name: "opencode", env: ["OPENCODE_CLIENT", "OPENCODE"] },
|
|
9
|
+
copilot: { name: "Copilot", env: [] },
|
|
10
|
+
claude: { name: "Claude", env: ["CLAUDECODE", "CLAUDE_CODE_SESSION_ID"] }
|
|
11
|
+
};
|
|
12
|
+
var agentKind = (word = "") => {
|
|
13
|
+
const w = String(word).toLowerCase();
|
|
14
|
+
if (/\bagy\b/.test(w)) return "antigravity";
|
|
15
|
+
return Object.keys(AGENTS).find((k) => w.includes(k)) || "";
|
|
16
|
+
};
|
|
17
|
+
function agentNow(env = process.env) {
|
|
18
|
+
const own = (env.LAB_AGENT || "").trim().slice(0, 30);
|
|
19
|
+
if (own) return { kind: agentKind(own), name: AGENTS[agentKind(own)]?.name || own };
|
|
20
|
+
const kind = Object.keys(AGENTS).find((k) => AGENTS[k].env.some((v) => env[v])) || agentKind(env.AGENT) || agentKind(env.AI_AGENT);
|
|
21
|
+
return kind ? { kind, name: AGENTS[kind].name } : { kind: "", name: "Claude" };
|
|
22
|
+
}
|
|
23
|
+
var modelName = (m = "") => {
|
|
24
|
+
const w = String(m).trim().replace(/\[.*\]$/, "");
|
|
25
|
+
const id = /^(?:claude-)?(opus|sonnet|haiku|fable)-(\d+)(?:-(\d{1,2}))?(?:-\d{8})?$/i.exec(w);
|
|
26
|
+
if (id) return `${id[1][0].toUpperCase()}${id[1].slice(1).toLowerCase()} ${id[2]}${id[3] ? `.${id[3]}` : ""}`;
|
|
27
|
+
return /^(opus|sonnet|haiku|fable)$/i.test(w) ? w[0].toUpperCase() + w.slice(1).toLowerCase() : w.replace(/\s+/g, " ").slice(0, 30);
|
|
28
|
+
};
|
|
29
|
+
function mySession(asked, model) {
|
|
30
|
+
const agent = agentNow();
|
|
31
|
+
const env = process.env;
|
|
32
|
+
const remote = agent.kind === "claude" || !agent.kind ? env.CLAUDE_CODE_REMOTE_SESSION_ID || "" : "";
|
|
33
|
+
const id = { claude: env.CLAUDE_CODE_SESSION_ID, codex: env.CODEX_THREAD_ID, amp: env.AMP_CURRENT_THREAD_ID }[agent.kind || "claude"] || "";
|
|
34
|
+
const name = asked || env.LAB_SESSION_NAME || (id ? `session ${id.slice(0, 8)}` : agent.name);
|
|
35
|
+
const safe = /^[\w-]+$/.test(id);
|
|
36
|
+
return {
|
|
37
|
+
id,
|
|
38
|
+
name: name.replace(/\s+/g, " ").slice(0, 40),
|
|
39
|
+
agent: agent.name,
|
|
40
|
+
model: modelName(model || env.LAB_MODEL || env.ANTHROPIC_MODEL),
|
|
41
|
+
kind: agent.kind,
|
|
42
|
+
url: remote ? `https://claude.ai/code/${remote.replace(/^cse_/, "session_")}` : agent.kind === "amp" && safe ? `https://ampcode.com/threads/${id}` : "",
|
|
43
|
+
resume: !safe || remote ? "" : { claude: `claude --resume ${id}`, codex: `codex resume ${id}`, amp: `amp threads continue ${id}` }[agent.kind || "claude"] || ""
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export {
|
|
48
|
+
AGENTS,
|
|
49
|
+
agentKind,
|
|
50
|
+
agentNow,
|
|
51
|
+
mySession
|
|
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
|
+
};
|