tabglutton-gullet 0.4.0

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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +293 -0
  3. package/dist/gullet.js +2514 -0
  4. package/package.json +36 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Michael Simon
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,293 @@
1
+ # Gullet
2
+
3
+ The sidecar half of Tabglutton's agent bridge — the pipe tab content passes through on its
4
+ way to a coding agent. One side is an **MCP server over stdio**, spawned by whatever agent
5
+ harness you use; the other is a **WebSocket server on loopback** that browsers running
6
+ Tabglutton dial into.
7
+
8
+ Architecture, trust boundary, and phasing live in
9
+ [`docs/BRIDGE.md`](https://github.com/mlsimon734/tabglutton/blob/main/docs/BRIDGE.md).
10
+ This file is the setup guide.
11
+
12
+ ```
13
+ Claude Code ──MCP (stdio)──► Gullet ──WebSocket (automatic loopback port)──► browsers
14
+ ```
15
+
16
+ Zero dependencies: it runs on Bun's built-ins alone. Install Bun, then let your MCP client
17
+ launch the published package with `bunx tabglutton-gullet`; no checkout is required.
18
+
19
+ **Two names, one product.** "Gullet" is the internal name for this sidecar; everything a
20
+ user or an agent sees says **Tabglutton**. So the MCP server registers as `tabglutton`, the
21
+ tools appear under that namespace, and the token is `TABGLUTTON_TOKEN`. `GULLET_TOKEN` and
22
+ `GULLET_PORT` still work as aliases.
23
+
24
+ ## Setup
25
+
26
+ 1. **Turn the bridge on in the browser.** Tabglutton → Settings → _Agent bridge_ → enable,
27
+ then **Generate** a token and copy it. The bridge is off until you do this, and no
28
+ socket is opened while it is off.
29
+
30
+ 2. **Write the global token file.** The settings page renders a shell command with your
31
+ token filled in. _Copy setup command_ and run it once. It creates the directory privately
32
+ and writes the secret to `~/.config/tabglutton/token` with mode `0600` (under
33
+ `$XDG_CONFIG_HOME` instead when set). The token does not go into an MCP config.
34
+
35
+ 3. **Register Gullet with your agent.** Pick the shape your client accepts.
36
+
37
+ Claude Code, for every project:
38
+
39
+ ```sh
40
+ claude mcp add --scope user tabglutton -- bunx tabglutton-gullet
41
+ ```
42
+
43
+ Codex CLI and Codex desktop, in `~/.codex/config.toml`:
44
+
45
+ ```toml
46
+ [mcp_servers.tabglutton]
47
+ command = "bunx"
48
+ args = ["tabglutton-gullet"]
49
+ startup_timeout_sec = 30
50
+ tool_timeout_sec = 120
51
+ ```
52
+
53
+ Claude Desktop/Cowork and clients that accept the standard JSON shape:
54
+
55
+ ```json
56
+ {
57
+ "mcpServers": {
58
+ "tabglutton": { "command": "bunx", "args": ["tabglutton-gullet"] }
59
+ }
60
+ }
61
+ ```
62
+
63
+ `npx -y tabglutton-gullet` is also supported when a client already standardizes on
64
+ `npx`; the package still requires Bun because its executable uses Bun's runtime.
65
+
66
+ To run an unpublished checkout while developing, replace the command with:
67
+
68
+ ```sh
69
+ bun run /path/to/tabglutton/gullet/gullet.ts
70
+ ```
71
+
72
+ 4. **Start a session.** The agent spawns Gullet, which attaches to the background hub —
73
+ starting one on an approved port if none is running yet (see _The background hub_ below).
74
+ The browser is usually connected to it already; if it is not, its reconnect loop finds it
75
+ within a few seconds while its extension page is awake, worst case ~30 seconds when the
76
+ page had suspended. The toolbar badge shows a terracotta dot while the connection is live.
77
+ When the session ends its Gullet exits, and the hub stays listening for the next one.
78
+
79
+ There is no app to launch and no per-session step. Multiple browsers can be connected at
80
+ once — a Zen window and a Chrome profile, say — and each tool call picks one with the
81
+ `browser` argument.
82
+
83
+ ## Configuration
84
+
85
+ Gullet reads settings from `${XDG_CONFIG_HOME:-$HOME/.config}/tabglutton/config.json`.
86
+ The file is safe to keep in a dotfiles repository because Gullet rejects an inline
87
+ `"token"` key; it may contain only settings and a pointer to the secret.
88
+
89
+ ```jsonc
90
+ {
91
+ "port": "auto",
92
+ "tokenFile": "token",
93
+ }
94
+ ```
95
+
96
+ `tokenFile` defaults to `${XDG_CONFIG_HOME:-$HOME/.config}/tabglutton/token`. Relative
97
+ paths are resolved from the directory containing `config.json`. To read from a secret
98
+ manager instead, use `tokenCommand` in place of `tokenFile`:
99
+
100
+ ```jsonc
101
+ {
102
+ "port": "auto",
103
+ "tokenCommand": "op read op://Private/Tabglutton/token",
104
+ }
105
+ ```
106
+
107
+ The command runs through `sh` from the config directory and its trimmed stdout is the
108
+ token. Gullet bounds each attempt at five seconds. A timeout or nonzero exit is reported
109
+ to the MCP client with stderr attached while the process keeps retrying with backoff;
110
+ unlocking the secret manager heals the same MCP session.
111
+
112
+ Resolution is additive, so existing setups keep working. The first configured token wins:
113
+
114
+ ```text
115
+ --token -> TABGLUTTON_TOKEN / GULLET_TOKEN
116
+ -> tokenCommand -> tokenFile -> the default global token file
117
+ -> ./.env
118
+ ```
119
+
120
+ `./.env` is consulted **last**, and only when the global token file is not there at all. It
121
+ is the one source read out of a directory you did not choose — an MCP host sets this
122
+ process's working directory to whatever project your agent session started in, so a cloned
123
+ repository can ship a `.env` naming a token its author knows. Last means it can supply a
124
+ token nothing else had, and can never silently replace the one the setup command wrote.
125
+ It answers only when the global file is absent — a file that exists and is empty is a
126
+ half-finished setup, and reports itself as one rather than handing the realm to a `.env`.
127
+ (It previously outranked the global file; the move landed with the wire-protocol-3 release.)
128
+
129
+ Port selection uses `--port`, then `TABGLUTTON_PORT` / `GULLET_PORT`, then the global
130
+ config, then automatic discovery. A fixed number must match the browser's fixed-port
131
+ setting. Process arguments are visible to other local users, so `--token` is best kept for
132
+ temporary diagnosis; prefer the global file, a secret-manager command, or the environment.
133
+
134
+ Automatic mode uses the ordered candidate set shared with the extension: `4589`, `20317`,
135
+ `17483`, `27613`, and `24193`. It discovers an existing same-token hub before binding, so
136
+ multiple Claude Code and Codex sessions converge even if an earlier candidate later frees up.
137
+
138
+ Diagnostics go to **stderr**; stdout is the MCP transport and carries nothing else.
139
+
140
+ ### The background hub
141
+
142
+ The process your agent harness spawns does not talk to the browser itself. The first one to
143
+ find no hub running starts a small **detached hub** and attaches to it; every session after
144
+ that attaches to the same one. The point is the browser's side of it: with a hub always
145
+ listening, the browser holds a connection that already exists when your session starts,
146
+ instead of one that has to be discovered and dialled each time — which is where this bridge
147
+ has historically lost its first tool call.
148
+
149
+ It stays out of the way by design. It exits by itself after six hours with no session
150
+ attached, it stands aside when a newer Gullet arrives, it keeps your browser's background
151
+ page awake only while a session is actually attached, and it holds nothing beyond the same
152
+ loopback port, token, and origin check every other part of the bridge uses. Its log is
153
+ `${XDG_STATE_HOME:-$HOME/.local/state}/tabglutton/hub.log`, rewritten each time a hub
154
+ starts.
155
+
156
+ Pass `--no-detach` (or `"detach": false` in `config.json`) to serve the browser from the
157
+ session process instead, which is the older behaviour and the easier one to debug — the
158
+ hub's diagnostics then come out on that process's stderr with everything else.
159
+
160
+ ## Tools
161
+
162
+ | Tool | What it does |
163
+ | ------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
164
+ | `tabs_list` | Metadata for every open tab — id, title, url, `lastAccessed`, `discarded`, `pinned`, `active`, window, and `hidden` on Firefox/Zen. No page content, so it stays cheap across hundreds of tabs. |
165
+ | `tabs_load` | Reloads discarded tabs so they can be read, ≤20 per call, a few at a time. Off by default — see below. |
166
+ | `tab_read` | Extracts one loaded tab as clean markdown via Defuddle. |
167
+ | `tab_clip` | Files a tab exactly as the popup's Devour does — into Obsidian or as a markdown file, per your setting. Reports which, and who confirmed it. Optionally closes it after. |
168
+ | `tabs_close` | Closes tabs. Records the batch first and returns a `batchId`. |
169
+ | `undo_close` | Reopens a recorded batch. |
170
+
171
+ Deliberately absent: navigate, click, type, evaluate. The agent can read what you already
172
+ chose to open, file it, and clean up — it cannot act as you. Adding anything richer means
173
+ revisiting the prompt-injection posture in
174
+ [`docs/BRIDGE.md`](https://github.com/mlsimon734/tabglutton/blob/main/docs/BRIDGE.md)
175
+ first.
176
+
177
+ `tabs_load` is the one tool that acts on a page rather than observing it, so it has its own
178
+ switch — **Agent bridge → "Let agents load unloaded tabs"** in Tabglutton's settings — and
179
+ enabling the bridge does not enable it. Until it is on, the tool answers `not-enabled` with
180
+ that instruction, so an agent can tell you what to flip. Even on, all it does is reload a
181
+ tab you already opened; the URL never comes from the agent.
182
+
183
+ `tabs_list` with no `browser` argument fans out across every connected browser and tags
184
+ each tab with its origin. The tab-scoped tools refuse to guess between two browsers, since
185
+ tab ids only mean something within one.
186
+
187
+ ## Suggested workflow
188
+
189
+ Triage on metadata first. In a 300-tab backlog most tabs are discarded (unloaded), and
190
+ `tab_read` cannot reach those. Cutting on title, URL, and age before reading anything is
191
+ what makes triaging that many tabs affordable in tokens — and it also keeps the survivors
192
+ few enough to be worth waking.
193
+
194
+ Then wake the survivors in batches: one `tabs_load` per 20 tabs, not one per tab. Loads run
195
+ three at a time under a fixed budget per call, so a batch is bounded by the slowest few
196
+ pages rather than by their sum, and each tab comes back `ready`, `pending` (still loading,
197
+ or not reached — ask again), or `failed` (gone, or not an http(s) page). Read the `ready`
198
+ ones. With loading switched off, `tab_read` fails with `tab-discarded` instead and those
199
+ tabs are yours to open by hand.
200
+
201
+ ## Troubleshooting
202
+
203
+ **Several agent sessions at once.** Supported, and nothing needs configuring. Sessions
204
+ attach to the shared background hub described above and proxy through it, so every session
205
+ sees the same tabs. You may see more `tabglutton-gullet` processes than you have sessions —
206
+ some MCP clients spawn more than one, and one of them is the hub, which is meant to outlive
207
+ all of them.
208
+
209
+ **A Gullet process that will not go away.** That is the hub, and it is doing its job:
210
+ holding the browser's connection open between your sessions. It exits on its own after six
211
+ idle hours, retires when a newer Gullet attaches, and takes a `SIGTERM` if you want it gone
212
+ now. `--no-detach` keeps every future session's hub inside the session process instead.
213
+
214
+ **"No browser is connected."** The bridge is off in Tabglutton's settings, no token has
215
+ been generated, fixed-port settings do not match, or the browser has not re-dialled yet — a first
216
+ call waits up to 45s for the browser's backstop alarm (30s cadence, on Firefox too) to
217
+ fire and the dial to land, so this answer normally means configuration, not timing. The
218
+ settings page shows live connection status. A browser with no session attached deliberately
219
+ lets its background page suspend, so it is _usually_ but not always connected between
220
+ sessions; the wait covers that gap.
221
+
222
+ **Tool calls cancelled by the client.** A first call can legitimately hold for the 45s
223
+ connect wait, and a slow method holds for its own 45s request budget after that — ~90s
224
+ worst case for one tool call. Most MCP clients default to a 60s deadline (the MCP
225
+ TypeScript SDK and Codex both do); give your client at least 100s or a slow-but-healthy
226
+ call surfaces as a bare cancellation instead of an answer. Claude Code: `MCP_TOOL_TIMEOUT`
227
+ (milliseconds). Codex: `tool_timeout_sec` per server — this repo's `.codex/config.toml`
228
+ sets it to 120.
229
+
230
+ **The browser dials but nothing reaches Gullet.** If the extension's console shows a
231
+ WebSocket close code of **1015** and Gullet logs nothing at all, the extension CSP is
232
+ upgrading `ws://` to `wss://` and Gullet is being handed a TLS ClientHello. `manifest.json`
233
+ must declare `content_security_policy.extension_pages` explicitly — Firefox's MV3 default
234
+ includes `upgrade-insecure-requests`, which does this to loopback WebSockets as well.
235
+
236
+ **Discovery takes minutes instead of seconds.** If the extension only connects long after
237
+ Gullet started — or not at all — inspect the extension's background console via
238
+ `about:debugging#/runtime/this-firefox` → Tabglutton → _Inspect_ (its `[tabglutton]`
239
+ lines do not appear in the Browser Console). `bridge dial timed out after 120000ms`
240
+ repeating against a Gullet that answers `curl` instantly means the browser itself cannot
241
+ complete a loopback WebSocket: verified live in a ~1,050-tab Zen where dials sat two full
242
+ minutes without a SYN ever reaching the wire, while the Browser Console (Cmd-Shift-J)
243
+ showed Firefox's own Push service failing with
244
+ `PushServiceWebSocket … NS_ERROR_SOCKET_CREATE_FAILED`. The bridge is not misconfigured
245
+ and no setting fixes it — restart the browser.
246
+
247
+ **"Token mismatch."** `TABGLUTTON_TOKEN` and the token in Tabglutton's settings differ.
248
+ Regenerating the token in settings invalidates any sidecar still holding the old one.
249
+
250
+ **Every candidate is unavailable.** Gullet reports one summary and keeps retrying with
251
+ backoff. A same-token Gullet is joined automatically; markerless services, incompatible
252
+ versions, and different-token realms are skipped. Freeing any candidate heals the running
253
+ MCP session. If policy requires one known endpoint, select **Fixed port** in Tabglutton and
254
+ pass that number with `--port`.
255
+
256
+ **Nothing in the logs.** Gullet writes to stderr, which most agent harnesses hide. Run it
257
+ by hand to watch it:
258
+
259
+ ```sh
260
+ TABGLUTTON_TOKEN=<token> bunx tabglutton-gullet
261
+ ```
262
+
263
+ Then poke the selected socket directly (stderr prints the chosen port; `4589` is shown here):
264
+
265
+ ```sh
266
+ bunx wscat -c ws://127.0.0.1:4589 -H 'Origin: moz-extension://test'
267
+ ```
268
+
269
+ You should get a `challenge` frame back. Without the `Origin` header the upgrade is
270
+ refused with 403 — that check is what stops a hostile web page from opening the socket
271
+ from inside your browser.
272
+
273
+ ## Development
274
+
275
+ ```sh
276
+ bun run typecheck:gullet # from the repo root
277
+ bun test # protocol, config, selection, MCP, and a live-socket hub test
278
+ ```
279
+
280
+ The wire contract lives in
281
+ [`src/bridge-protocol.ts`](https://github.com/mlsimon734/tabglutton/blob/main/src/bridge-protocol.ts)
282
+ and is imported by both halves, so extension and sidecar are typechecked against one definition.
283
+
284
+ ### Releasing
285
+
286
+ The npm package is built by Bun and published by `.github/workflows/release.yml` when a
287
+ `v*` tag is pushed, using npm **trusted publishing** — a short-lived OIDC credential minted
288
+ for that one run, so no npm token exists in the repository. That job is switched off until
289
+ the repository variable `PUBLISH_GULLET_TO_NPM` is set to `true`, because a sidecar must
290
+ never reach npm ahead of the extension carrying the same `BRIDGE_PROTO`: there is no
291
+ downgrade path, and an early publish breaks the handshake for every installed user. The
292
+ order to turn it on, and the npm-side configuration it needs, are in
293
+ [`docs/STORE.md`](https://github.com/mlsimon734/tabglutton/blob/main/docs/STORE.md) §6.