townmouse 0.0.0-stage → 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 (108) hide show
  1. package/CHANGELOG.md +196 -0
  2. package/DESIGN.md +153 -0
  3. package/LICENSE +661 -0
  4. package/README.md +600 -2
  5. package/SECURITY.md +60 -0
  6. package/TOWNMOUSE.md +91 -0
  7. package/assets/brand/mascot/README.md +23 -0
  8. package/assets/brand/mascot/townmouse-aristocrat.png +0 -0
  9. package/assets/brand/mascot/townmouse-icon.svg +1 -0
  10. package/assets/brand/mascot/townmouse-monocled.png +0 -0
  11. package/bin/townmouse +68 -0
  12. package/docs/PACKAGING.md +371 -0
  13. package/docs/browser-workspace.md +237 -0
  14. package/docs/panes.md +442 -0
  15. package/native/TownmouseApp.swift +108 -0
  16. package/npm-shrinkwrap.json +1282 -0
  17. package/package.json +93 -4
  18. package/public/apple-touch-icon.png +0 -0
  19. package/public/brand/floydslabs-credit.png +0 -0
  20. package/public/brand/floydslabs-credit.webp +0 -0
  21. package/public/brand/townmouse-aristocrat.webp +0 -0
  22. package/public/brand/townmouse-monocled.webp +0 -0
  23. package/public/browser-picture.mjs +159 -0
  24. package/public/clipboard-text.mjs +5 -0
  25. package/public/favicon-16x16.png +0 -0
  26. package/public/favicon-32x32.png +0 -0
  27. package/public/favicon.ico +0 -0
  28. package/public/favicon.svg +1 -0
  29. package/public/features/app-version.mjs +35 -0
  30. package/public/features/autosave.mjs +80 -0
  31. package/public/features/clipboard.mjs +69 -0
  32. package/public/features/command-palette.mjs +181 -0
  33. package/public/features/desktop-palette.mjs +19 -0
  34. package/public/features/export.mjs +37 -0
  35. package/public/features/file-drop.mjs +77 -0
  36. package/public/features/floating-palette.mjs +113 -0
  37. package/public/features/fontsize.mjs +72 -0
  38. package/public/features/haptic-keys.mjs +42 -0
  39. package/public/features/history-undo.mjs +102 -0
  40. package/public/features/keepalive.mjs +36 -0
  41. package/public/features/keybar-config.mjs +70 -0
  42. package/public/features/keyboard-shortcuts.mjs +74 -0
  43. package/public/features/links.mjs +139 -0
  44. package/public/features/multi-window-sync.mjs +76 -0
  45. package/public/features/osc-bridge.mjs +64 -0
  46. package/public/features/phone-landscape-focus.mjs +157 -0
  47. package/public/features/recent-commands.mjs +100 -0
  48. package/public/features/search.mjs +134 -0
  49. package/public/features/session-lock.mjs +96 -0
  50. package/public/features/session-manager.mjs +251 -0
  51. package/public/features/settings-sync.mjs +77 -0
  52. package/public/features/shortcut-help.mjs +85 -0
  53. package/public/features/smart-completions.mjs +101 -0
  54. package/public/features/smart-suggest.mjs +124 -0
  55. package/public/features/snippets.mjs +85 -0
  56. package/public/features/split-view.mjs +102 -0
  57. package/public/features/status-metrics.mjs +137 -0
  58. package/public/features/stylus-support.mjs +124 -0
  59. package/public/features/swipe-history.mjs +141 -0
  60. package/public/features/swipe-sessions.mjs +85 -0
  61. package/public/features/tab-reorder.mjs +70 -0
  62. package/public/features/theme-system.mjs +51 -0
  63. package/public/features/toast-status.mjs +118 -0
  64. package/public/features/two-finger-menu.mjs +87 -0
  65. package/public/features/voice-input.mjs +244 -0
  66. package/public/features/wake-fullscreen.mjs +67 -0
  67. package/public/features/window-title.mjs +47 -0
  68. package/public/features/zoom.mjs +80 -0
  69. package/public/icon-128.png +0 -0
  70. package/public/icon-180.png +0 -0
  71. package/public/icon-192.png +0 -0
  72. package/public/icon-48.png +0 -0
  73. package/public/icon-512-maskable.png +0 -0
  74. package/public/icon-512.png +0 -0
  75. package/public/icon.svg +1 -0
  76. package/public/index.html +2304 -0
  77. package/public/input-chunks.mjs +22 -0
  78. package/public/input-guard.mjs +218 -0
  79. package/public/manifest.json +56 -0
  80. package/public/panes.css +1433 -0
  81. package/public/panes.html +211 -0
  82. package/public/panes.mjs +3183 -0
  83. package/public/service-worker.js +67 -0
  84. package/public/workspace.css +1621 -0
  85. package/public/workspace.mjs +1715 -0
  86. package/scripts/install-service.sh +303 -0
  87. package/scripts/node-runtime.sh +138 -0
  88. package/scripts/panes +568 -0
  89. package/scripts/prepare-native.sh +35 -0
  90. package/scripts/retire-legacy-service.sh +76 -0
  91. package/scripts/run-hooks +69 -0
  92. package/scripts/townmouse.sh +152 -0
  93. package/scripts/uninstall-service.sh +65 -0
  94. package/src/agent-guide.js +329 -0
  95. package/src/attachments.js +128 -0
  96. package/src/browser-dom.js +548 -0
  97. package/src/browser-workspace.js +1733 -0
  98. package/src/chrome-resolve.js +80 -0
  99. package/src/owner-page.js +43 -0
  100. package/src/pty-permissions.js +99 -0
  101. package/src/regex-worker.js +13 -0
  102. package/src/replay-text.js +189 -0
  103. package/src/request-boundary.js +58 -0
  104. package/src/safe-regex.js +87 -0
  105. package/src/server.js +1582 -0
  106. package/src/shell-resolve.js +42 -0
  107. package/src/static-deps.js +61 -0
  108. package/src/workspace-panes.js +1431 -0
@@ -0,0 +1,371 @@
1
+ # Packaging and Release
2
+
3
+ ## Or: How To Ship A Workspace Without Asking A Subscription Committee For Permission
4
+
5
+ ---
6
+
7
+ - **DOCUMENT CLASSIFICATION:** Technical / Moderate Chaos
8
+ - **DATE RECORDED:** 2026-11-15 — Late Enough To Be Useful
9
+ - **LOCATION:** The Garage, Brown County, Indiana
10
+ - **BEVERAGE:** Coffee that tastes like motor oil (fresh pot)
11
+ - **CURRENT STATE:** Gates assembled; signed release still pending
12
+
13
+ ---
14
+
15
+ Townmouse is a local, self-hosted terminal and agent browser workspace. The
16
+ release unit is the server plus its static frontend, not a hosted SaaS. There is
17
+ no per-seat meter, no subscription treadmill, and no boardroom waiting to approve
18
+ a keyboard shortcut. You install it. You run it. You own the machine it runs on.
19
+
20
+ TerminalOne is the embedded terminal engine and remains its own product.
21
+ Townmouse owns the workspace, the browser surfaces, the sharing grants, the pane
22
+ workspace, and the release artifacts. The npm package, CLI, Docker image, data
23
+ directory, and macOS wrapper all carry the Townmouse name.
24
+
25
+ This document is the working plan until the first signed release. Everything
26
+ below is a gate, not a vibe.
27
+
28
+ ## License
29
+
30
+ **AGPL-3.0-only.** The complete license is in `LICENSE`. If a person or company
31
+ runs Townmouse, or a modified version of it, as a network service, they must
32
+ offer the complete corresponding source to the people using that service.
33
+ Distributing the software or a derivative also requires the source. TerminalOne's
34
+ license and copyright notices remain with the portions it supplies.
35
+
36
+ That is not a suggestion, and it is not the kind of thing that gets waived
37
+ because a launch post would look better without it.
38
+
39
+ ## Release channels
40
+
41
+ ### 1. npm (primary, macOS/Linux)
42
+
43
+ - Package name: `townmouse`.
44
+ - `bin`: `townmouse` starts `src/server.js`, prints the URL, and opens a browser
45
+ unless `--no-open` is passed.
46
+ - Runtime: Node 22.x preferred and declared as `>=22 <27`, npm, and a
47
+ Chromium/Chrome binary for browser panes. `scripts/node-runtime.sh` prefers 22
48
+ and falls back to any installed major where node-pty loads, because node-pty
49
+ is built on Node-API.
50
+ - `postinstall` runs `scripts/prepare-native.sh`, which marks node-pty's macOS
51
+ spawn helpers executable. **It is not enough on its own:** npm 12 skips
52
+ dependency install scripts by default (`allow-scripts = [""]`), so the server
53
+ also repairs the helper mode at startup (`src/pty-permissions.js`). An install
54
+ with scripts ignored is the tested case.
55
+ - Browser panes resolve an engine in this order: `TERMINALONE_CHROME`,
56
+ Puppeteer's downloaded build, then a system Chrome/Chromium/Edge/Brave.
57
+ `GET /health` reports `browser.engine`, so an install without a browser says
58
+ so instead of failing at the first pane.
59
+ - `npm run doctor` checks the Node version and native modules; `npm run repair`
60
+ rebuilds node-pty if they do not match.
61
+ - `npm pack` is the release artifact; `npm publish` publishes it under a semver
62
+ tag.
63
+ - `npx townmouse` is the no-install smoke path.
64
+
65
+ **Linux and npm 12.** npm 12 does not run dependency install scripts by default
66
+ (`allow-scripts = [""]`). node-pty ships prebuilds only for macOS and Windows,
67
+ so a Linux install that skipped scripts has no terminal engine. Build it
68
+ explicitly:
69
+
70
+ ```sh
71
+ npm install --allow-scripts=node-pty townmouse
72
+ # or, in an existing install:
73
+ npm rebuild node-pty # needs python3, make, and g++
74
+ npm run doctor # native_modules=ok
75
+ ```
76
+
77
+ The server refuses to start with that explanation rather than a stack trace when
78
+ the engine cannot load. The container channel needs no such step; the image
79
+ compiles node-pty during `npm ci`.
80
+
81
+ **Release automation — trusted publishing, not tokens.** Merging a version
82
+ bump to `main` triggers `.github/workflows/publish.yml`. If that version is not
83
+ yet on npm, the workflow runs the suite and package gate, publishes with npm
84
+ **Trusted Publishing** (GitHub's OIDC token stands in for a stored npm token),
85
+ tags the commit, and creates the GitHub release with the tarball and checksum
86
+ attached. A merge whose version is already published skips after one registry
87
+ read, so ordinary main updates do not re-release. Do not create an automation
88
+ token for CI; npm warns against that use, and a long-lived publish token is a
89
+ standing liability.
90
+
91
+ One-time bootstrap, because a trusted publisher is configured on an existing
92
+ package:
93
+
94
+ 1. Publish the first version interactively (`npm login --auth-type=web`, then
95
+ `npm publish --access public`, completing the second factor).
96
+ 2. On npmjs.com, open the package → Settings. Under **Trusted Publisher**,
97
+ choose **Add Trusted Publisher connection for GitHub Actions**: organization
98
+ or user `CaptainPhantasy`, repository `townmouse`, workflow filename
99
+ `publish.yml`, environment name blank.
100
+ 3. From then on, merging a version bump to `main` publishes and releases
101
+ automatically with provenance. Raise the version with
102
+ `npm run version:bump <version>` and write the two entries it starts
103
+ ("Versioning" below), then
104
+ merge; nothing else is needed.
105
+
106
+ **Interim route while npm refuses the sign-in.** On 2026-11-28 npm refused
107
+ this repository's Trusted Publisher sign-in with
108
+ `OIDC token exchange error - package not found`, before and after the
109
+ connection in step 2 was added. The repository was created after 2026-07-15 and
110
+ uses GitHub's newer subject claim; npm/cli issue 9969 reports the same refusal
111
+ for such repositories. Until npm accepts it, store a token as the repository
112
+ secret `NPM_TOKEN` for a release: a granular access token for this package only,
113
+ read and write, with bypass two-factor enabled and the shortest expiry offered.
114
+ The workflow still tries the sign-in first and falls back to the token; with no
115
+ secret stored it uses the sign-in alone. Delete the secret and revoke the token
116
+ after the release. This does not change the rule above: no long-lived token.
117
+
118
+ The CLI surface is small on purpose:
119
+
120
+ ```sh
121
+ npm ci
122
+ npm start
123
+ npx townmouse
124
+ townmouse --port 11002
125
+ townmouse --port=11002 --no-open
126
+ townmouse --help
127
+ townmouse --version
128
+ npm pack
129
+ npm publish
130
+ ```
131
+
132
+ The server binds to `127.0.0.1`. The CLI does not turn off the loopback listener,
133
+ and neither should you.
134
+
135
+ ### 2. Container (Linux home server)
136
+
137
+ The `Dockerfile` uses `node:22-alpine`, installs Chromium, sets
138
+ `PUPPETEER_SKIP_DOWNLOAD=1` and `TERMINALONE_CHROME=/usr/bin/chromium`, runs as
139
+ the `node` user, exposes `11002`, and declares volumes for both
140
+ `/home/node/.townmouse` (workspace, attachments, pane token) and
141
+ `/home/node/.config/terminalone` (voice settings).
142
+ It sets `HOST=0.0.0.0` for container port forwarding and
143
+ `TOWNMOUSE_CHROMIUM_NO_SANDBOX=1` because the container has no Chromium sandbox
144
+ setup; both are container-only choices. The host run keeps loopback binding and
145
+ the Chromium sandbox.
146
+
147
+ Build and run:
148
+
149
+ ```sh
150
+ TOWNMOUSE_VERSION=$(node -p "require('./package.json').version") \
151
+ GIT_REVISION=$(git rev-parse HEAD) \
152
+ docker build \
153
+ --build-arg TOWNMOUSE_VERSION="$TOWNMOUSE_VERSION" \
154
+ --build-arg GIT_REVISION="$GIT_REVISION" \
155
+ -t townmouse:"$TOWNMOUSE_VERSION" \
156
+ -t townmouse:latest .
157
+ docker run --rm -p 127.0.0.1:11002:11002 -v townmouse-home:/home/node/.townmouse -v townmouse-config:/home/node/.config/terminalone townmouse
158
+ ```
159
+
160
+ The host port may differ from the container port; the request boundary accepts
161
+ loopback hostnames on any port and still enforces same-origin. Publish only to
162
+ host loopback. Mount project directories explicitly; the terminal starts in
163
+ `/home/node`, not in your project. Health:
164
+
165
+ ```sh
166
+ curl http://127.0.0.1:11002/health
167
+ ```
168
+
169
+ `GET /health` returns `status: "ok"` plus the live session count. If it does not
170
+ answer, the container is not ready, and staring at the logs is cheaper than
171
+ guessing.
172
+
173
+ ### 3. macOS application wrapper
174
+
175
+ `native/TownmouseApp.swift` is a WKWebView shell pointed at `TOWNMOUSE_URL`
176
+ (default `http://127.0.0.1:11002`). It probes `/health`. If nothing answers, it
177
+ tries a separately installed launcher and waits up to 12 seconds before showing
178
+ a startup error.
179
+
180
+ `scripts/install-service.sh` builds a local `Townmouse.app`, installs a launcher,
181
+ and writes the launcher path into the bundle so the wrapper can start the
182
+ backend. The installer scripts ship in the npm package, so this works from a
183
+ global or local install; it is still a local convenience build, not a signed
184
+ distribution.
185
+
186
+ **Service identity.** Townmouse's service is its own: launchd label
187
+ `com.floyd.townmouse`, port `11002`, launcher `townmouse`, bundle identifier
188
+ `com.floyd.townmouse`. TerminalOne, the engine Townmouse embeds, keeps
189
+ `com.floyd.terminalone`, port `11001` and the `t1` launcher, so the two products
190
+ can be installed side by side; nothing Townmouse's installer writes takes
191
+ TerminalOne's name, port or launcher. After `install-service.sh`, the `townmouse`
192
+ launcher on the internal disk comes first on `PATH` and is service-aware: it
193
+ starts the service when it is not healthy, then opens the workspace. It accepts
194
+ `--port <n>`, `--no-open` (or `--serve-only`), `--version` and `--help`.
195
+ `scripts/uninstall-service.sh` removes the service, the launcher and the app. It never removes a `townmouse` command the installer did not write, such as the one npm creates for the package, and the installer never overwrites one. The launcher and the icon always use port 11002: `PORT` set while running `install-service.sh` changes the service's port only, so leave the service on 11002.
196
+
197
+ **Upgrading from 0.2.x.** Those versions installed the service as
198
+ `com.floyd.terminalone` on port 11001 and wrote their launcher as `t1`, so on a
199
+ Mac with TerminalOne, `t1` and TerminalOne.app opened Townmouse. The 0.3.0
200
+ installer and uninstaller stop and remove that service, and remove the `t1`
201
+ launcher 0.2.x wrote, when they find them; a TerminalOne service or launcher is
202
+ never touched. If 0.2.x displaced TerminalOne, run TerminalOne's own
203
+ `scripts/install-service.sh` afterwards to restore it.
204
+
205
+ A distributable `.app` must bundle or launch the Node server or npm CLI, use a
206
+ stable data directory, and be codesigned and notarized. Until that is done, there
207
+ is no signed downloadable macOS release. The wrapper is a WebView with
208
+ ambitions, and it knows it.
209
+
210
+ ### 4. Phone/tablet PWA over the tailnet
211
+
212
+ - The app is installable from the browser. The shell and workspace load from the
213
+ local server; live PTYs and browser pages still need that server.
214
+ - Publish with `tailscale serve` on a claimed port, bound to loopback. Never
215
+ expose an owner tool with Funnel without explicit approval.
216
+ - An HTTPS proxy must require authentication before it forwards any request,
217
+ including WebSocket upgrades. It must preserve the public `Host` header and
218
+ the browser `Origin`. `TERMINALONE_TRUSTED_ORIGINS` only allows an address; it
219
+ does not add authentication.
220
+
221
+ ```sh
222
+ TERMINALONE_TRUSTED_ORIGINS=https://townmouse.example.com npm start
223
+ ```
224
+
225
+ The `TERMINALONE_` prefix on that variable and on `TERMINALONE_CHROME` is a
226
+ compatibility name the runtime still reads. Renaming an environment variable is
227
+ a breaking change, not a rebranding exercise. The product name in the UI, package,
228
+ CLI, and data directory is Townmouse.
229
+
230
+ ## Versioning
231
+
232
+ - Semantic versioning: `MAJOR.MINOR.PATCH`.
233
+ - Feature work lands on `feat/*`; releases are tagged from `main`.
234
+ - `CHANGELOG.md` gets a dated section for every release. The punch list is not a
235
+ changelog.
236
+ - Package version, Git tag, Docker tag, and release notes must agree. If they
237
+ disagree, it is not a release; it is a rumor with a download link.
238
+
239
+ **Patch, minor or breaking, below 1.0.**
240
+
241
+ - **Patch** (`0.3.0` to `0.3.1`): a fix. Something a user relies on is repaired
242
+ and nothing changes for them. A dependency or security update is a patch, and
243
+ so is a correction to a document inside the package.
244
+ - **Minor** (`0.3.0` to `0.4.0`): anything new, and anything a user must do
245
+ differently after upgrading: a new capability, command or setting, a changed
246
+ default, a renamed setting, a removed command. Below 1.0 a breaking change is
247
+ a minor; say so in the changelog and tell the user what to change, as the
248
+ 0.3.0 entry does for its port.
249
+ - **Major** (`1.0.0`): the first stable release, and after it a breaking change.
250
+
251
+ **Where the version is written.** By hand, in five files: `package.json`;
252
+ `package-lock.json` and `npm-shrinkwrap.json` (the top of each and its root
253
+ package entry); the sentence "Townmouse is version …" and the newest heading of
254
+ `CHANGELOG.md`; and in `docs/RELEASE_NOTES.md` the newest heading, the line
255
+ "Product version: …" and the `Product:` line of the box at the end. The app
256
+ reports the `package.json` version (`townmouse --version`, `GET /health`), and
257
+ the release workflow tags `main` as `v<version>`.
258
+
259
+ **No bump, no release.** `scripts/check-version.mjs` is the one check. It runs
260
+ on every pull request to `main`, against the newest `v*` tag there, and in the
261
+ release workflow. It fails when the five files disagree or when the changelog
262
+ and the release notes lack the entry. It refuses a change to **what ships**
263
+ unless the version is higher than the tag's. What ships is every file
264
+ `npm pack` lists, compared by content, plus the `Dockerfile` and
265
+ `.dockerignore`; a change only to tests, workflows or documents outside the
266
+ package (the release notes among them) needs no bump. A merge to `main` that
267
+ breaks the rule fails the release workflow instead of being skipped unnoticed.
268
+
269
+ ```sh
270
+ npm run version:bump 0.3.1 # writes the new version into every place and starts the two entries
271
+ npm run version:check # passes once every place agrees and both entries are written
272
+ ```
273
+
274
+ `version:bump` dates the entries with today's date unless told otherwise
275
+ (`npm run version:bump 0.3.1 -- --date 2026-12-01`). The entries it starts are
276
+ placeholders, and the check refuses them until they are written.
277
+
278
+ ## Release gates
279
+
280
+ 1. `npm ci` from a clean checkout.
281
+ 2. `npm test` green, including `test:panes`, `test:agent-control` (36 journeys),
282
+ and the security suite.
283
+ 3. Four-pane UI acceptance: 2 terminals + 2 browsers, no console errors.
284
+ 4. Attachment test: image upload once, path in PTY, URL serves 200.
285
+ 5. Input test: a burst of keystrokes produces one ordered input POST.
286
+ 6. Codex code and security review has no unresolved findings on the release
287
+ commit.
288
+ 7. `npm pack --dry-run` contains `bin/`, `src/`, `public/panes.*`,
289
+ `scripts/panes`, `LICENSE`, and no secrets or local evidence.
290
+ 8. `npm run test:package` green: the packed tarball installs into a clean
291
+ project with `--ignore-scripts`, starts, serves its engine assets, creates
292
+ `~/.townmouse` with safe modes, spawns a PTY, runs a tracked command, and
293
+ opens a browser pane. This is the gate that catches a dev tree that is not
294
+ the application.
295
+ 9. Docker image builds and answers `/health` on loopback, including when the
296
+ published host port differs from the container port.
297
+
298
+ A release that skips a gate is a branch with a nicer tag. The cats are not
299
+ impressed, and Bella has already walked across the checklist.
300
+
301
+ ## Data and backup
302
+
303
+ - `~/.townmouse/pane-token` — workspace API token, mode 600. The server creates
304
+ it on first run if it is missing.
305
+ - `~/.townmouse/attachments/<YYYYMMDD>/` — dropped files, directories mode 700
306
+ and files mode 600, with a 25 MB per-upload limit.
307
+ - Project files live wherever the member mounted them; never inside the package
308
+ directory.
309
+ - Back up `~/.townmouse` before upgrades. Docker uses the `townmouse-home`
310
+ volume for the same data.
311
+
312
+ ```sh
313
+ cp -a ~/.townmouse ~/.townmouse.backup-$(date +%Y%m%d)
314
+ ```
315
+
316
+ ## Upgrade and rollback
317
+
318
+ - npm: publish under a new version; roll back with
319
+ `npm install -g townmouse@<previous>`.
320
+ - Docker: keep immutable tags (`townmouse:<version>`) and a moving `latest`; roll
321
+ back by running the previous tag.
322
+ - Keep the previous release artifact and its checksums. Data is compatible within
323
+ a minor version; any breaking data change needs a migration note.
324
+
325
+ A rollback path you have not tested is a hope with a shell prompt.
326
+
327
+ ## Known gaps before a public release
328
+
329
+ - The macOS wrapper does not bundle the server yet; it can only start a
330
+ separately installed launcher.
331
+ - Browser panes do not yet bridge native file pickers or downloads.
332
+ - PWA offline coverage is the shell only; live PTYs and browser pages require the
333
+ server.
334
+ - No Windows-signed installer.
335
+ - The pane workspace and the legacy single-browser workspace still coexist; the
336
+ legacy Copy-connection UI is compatibility-only.
337
+
338
+ None of these are secrets. Shipping around them without saying so would be.
339
+
340
+ ## Release checklist
341
+
342
+ - [ ] Version and changelog updated.
343
+ - [ ] `npm run version:check` passes: the version agrees everywhere and both entries are written.
344
+ - [ ] Clean `npm ci` and `npm test`.
345
+ - [ ] `npm run test:package` green: the packed tarball installs and runs.
346
+ - [ ] Pane UI/attachment/input evidence refreshed.
347
+ - [ ] Codex review clean on the release commit.
348
+ - [ ] `npm pack` inspected and checksummed.
349
+ - [ ] Docker image built and smoke-tested.
350
+ - [ ] Version bumped and changelog dated; merge to `main` runs `publish.yml` (npm publish, tag, GitHub release) once trusted publishing is configured.
351
+ - [ ] Backup/rollback instructions included.
352
+
353
+ If it is not checked, it is not shipped. That is the entire policy.
354
+
355
+ ```text
356
+ ┌──────────────────────────────────────────────────────────┐
357
+ │ DOCUMENT METADATA │
358
+ ├──────────────────────────────────────────────────────────┤
359
+ │ Classification: Technical / Release │
360
+ │ Cat Supervision: Bella, asleep on the checklist │
361
+ │ Bowser Status: Monitoring routers, not releases │
362
+ │ "I Don't Suck": PASS │
363
+ │ Corporate Feelings: HURT (intended) │
364
+ └──────────────────────────────────────────────────────────┘
365
+ ```
366
+
367
+ **DOCUMENT ENDS**
368
+
369
+ *— Build/Release, Floyd's Labs*
370
+ *The Garage — Brown County, Indiana*
371
+ *"A release is a promise you can install from a clean checkout."*
@@ -0,0 +1,237 @@
1
+ # Browser Workspace
2
+
3
+ ## Or: The Browser Is Real, The Iframe Is Not
4
+
5
+ ---
6
+
7
+ - **DOCUMENT CLASSIFICATION:** Technical / Moderate Chaos
8
+ - **DATE RECORDED:** 2026-11-15 — Late Enough To Be Useful
9
+ - **LOCATION:** The Garage, Brown County, Indiana
10
+ - **BEVERAGE:** Coffee that tastes like motor oil (fresh pot)
11
+ - **CURRENT STATE:** One Chromium engine, several opinions
12
+
13
+ ---
14
+
15
+ Open **Browser** or the **+** in the tab strip to create an isolated Chromium
16
+ page on the terminal host. Enter a web address, search phrase, or localhost URL.
17
+ Navigation, clicking, typing, and scrolling happen in that real page,
18
+ independent of iframe policies. The iframe was a compromise. This is not that.
19
+
20
+ Each tab has its own cookie context. These are workspace browser tabs, not an
21
+ attachment to an existing Safari or Chrome profile. Browser audio, file
22
+ upload/download dialogs, extensions, and password-manager integration are not
23
+ provided by the image-based viewer.
24
+
25
+ ## Pane workspace
26
+
27
+ Open `/panes.html` (or **Panes** in the sidebar) for the split workspace. Each
28
+ workspace tab holds up to four panes in a 2x2 grid; a pane is either a real PTY
29
+ terminal or a real browser page. The browser panes are rendered by the same
30
+ headless-browser backend as the single browser tab, and the terminal panes are
31
+ independent PTY sessions powered by the embedded TerminalOne engine.
32
+
33
+ An agent running in a terminal pane receives:
34
+
35
+ ```text
36
+ TOWNMOUSE_API=http://127.0.0.1:<port>/api/panes
37
+ TOWNMOUSE_TOKEN=<workspace token>
38
+ TOWNMOUSE_TAB_ID=<this tab>
39
+ TOWNMOUSE_PANE_ID=<this pane>
40
+ TOWNMOUSE_PANES_CLI=<repo>/scripts/panes
41
+ ```
42
+
43
+ So it can create tabs, add panes, open URLs, run commands, read output, and send
44
+ input natively. No connection code is copied between the browser and the
45
+ terminal. A pane the owner opened is Private to it until the owner gives View
46
+ only or Allow control; see "Whose pane is whose" in [panes.md](panes.md). The pane limits are 24 tabs, four panes per tab, 24 terminal panes, and
47
+ 32 browser contexts. The full command list is in [panes.md](panes.md).
48
+
49
+ ## Layouts
50
+
51
+ - **Desktop:** persistent sidebar, browser tabs in the sidebar, terminal and
52
+ browser split horizontally when a browser is open. The separator is draggable
53
+ left and right; the terminal keeps at least 320px and the browser at least
54
+ 420px.
55
+ - **Tablet:** labeled rail, browser tabs in a strip above the address bar,
56
+ terminal and browser stacked vertically when a browser is open. The separator
57
+ is draggable up and down between a 25% and 75% browser share.
58
+ - **Phone:** bottom navigation with Terminal, Browser, Agent, and Tools. One task
59
+ surface is visible at a time. The key bar collapses to one row; the chevron
60
+ reveals the remaining keys. Browser tabs and sharing controls live in the
61
+ browser surface. The browser and terminal chrome is tightly padded, and after
62
+ seven seconds without a touch it collapses to the content; the bottom
63
+ navigation stays and the next touch wakes the chrome.
64
+
65
+ Three layouts, not one layout stretched until it apologizes.
66
+
67
+ ## Sharing
68
+
69
+ Human tabs start Private. Select **Share** to open the sharing row at every
70
+ width; it starts closed so the page keeps the space. A **Collapse** control
71
+ removes every bar above the page and remembers the choice, leaving a slim strip
72
+ that names the page and brings the controls back. The mascot stays in the
73
+ navigation rail and no longer appears in the working area.
74
+
75
+ This is the **compatibility** path. For agent work, open `/panes.html`; the
76
+ orchestrator receives `TOWNMOUSE_API` and `scripts/panes` directly, with no
77
+ connection code to copy. If you are using the legacy single-browser flow, select
78
+ View only or Allow control, then Copy connection, and paste the connection JSON
79
+ into your terminal agent. Changing permission rotates the token; choosing Private immediately
80
+ rejects subsequent token requests. Commands already executing can finish.
81
+ Closing a tab destroys its context.
82
+
83
+ The supplied endpoint accepts a Bearer token in the `Authorization` header:
84
+
85
+ - `GET /content`: current URL, title, and visible text.
86
+ - `GET /snapshot`: current URL, title, and JPEG image in base64. A picture is
87
+ taken for the caller there and then. (The owner's own page adds `watch`,
88
+ `since` and `wait` to this; see "Pictures" below.)
89
+ - `POST /action` with JSON: `navigate` (url), `back`, `forward`, `reload`,
90
+ `click` (x,y in the dimensions returned by `/snapshot`), `type` (text), `key`
91
+ (Puppeteer key name), `scroll` (deltaY).
92
+
93
+ View tokens cannot invoke actions or change grants. Never paste the token into a
94
+ visited web page. A token is a key, and web pages are full of people who would
95
+ love a copy of your keys.
96
+
97
+ Choose **Agent** to create a separate context with control granted. Hide view
98
+ keeps the browser running headless. Reopen Agent to observe the same context.
99
+ Revoking access also works on the agent context.
100
+
101
+ ## Pictures
102
+
103
+ How often the viewer is shown a new picture depends on whether a person can see
104
+ it. The viewer used to ask for one a second, for ever, whether or not anyone was
105
+ looking, and a click's picture arrived about a quarter of a second later.
106
+
107
+ - **Seen.** While the Browser view, or a browser pane, is on screen, a new
108
+ picture arrives as the page changes: up to 30 a second for one view, and 48 a
109
+ second across every view and pane together. The picture that follows a click,
110
+ a key or a scroll is sent as soon as the page has drawn it. On the machine
111
+ this was measured on, the server has it 5 to 20 ms after the action has
112
+ returned; before, the viewer waited 120 to 220 ms on purpose and then a
113
+ 65 to 85 ms capture.
114
+ - **Not seen.** With the view hidden, the browser tab in the background, the
115
+ window minimized, a pane scrolled out of the window, or a pane in a workspace
116
+ tab that is not the active one, nothing is asked for. A pane that is on the
117
+ active tab but out of view still reports its title, address and any page
118
+ prompt every three seconds, and no picture is taken for that. Coming back
119
+ into view brings a current picture at once.
120
+ - **Still.** A page that is not changing sends no picture at all, seen or not.
121
+
122
+ This is remote interaction, not a native browser DOM exposed to the viewer's
123
+ assistive technology. Agents can use `/content` for text. Keyboard Tab moves
124
+ through the workspace interface; the Send field, Tab, and Enter buttons
125
+ interact with page inputs.
126
+
127
+ How it works, for anyone changing it. The page keeps one request waiting on the
128
+ server for the next picture (up to half a second), so a change is delivered as
129
+ it happens and a still page costs one small request per wait. While such a
130
+ request has arrived in the last second and a half, the server has Chrome push a
131
+ picture each time the page repaints (`Page.startScreencast`); when none has,
132
+ the stream is stopped, whether or not the viewer said goodbye. Chrome sends its
133
+ next picture only once the last one is acknowledged (measured: about 1.05
134
+ pictures for each acknowledgement once running), and the server holds each
135
+ acknowledgement to one pane period and one all-panes period, which is what
136
+ keeps both ceilings. A pushed picture can have been taken at any moment,
137
+ including while the viewport changes, so it is accepted only if its own pixel
138
+ size is the viewport's; a picture taken on request still runs inside the
139
+ session queue, where it never meets a resize. The viewer's request is
140
+ `GET /snapshot?watch=1&since=<seq>&wait=<ms>` while seen (the answer carries
141
+ `changed`, `seq`, and the picture only when it is new) and `?watch=0` while not.
142
+ Without `watch` nothing changes for an agent: a picture is taken for it there
143
+ and then. An agent's `observe` is its own capture; it neither starts the stream
144
+ nor waits behind a viewer's pictures, and an agent at work is never taken for a
145
+ viewer. At most four viewer requests wait at the same time (the same share of a
146
+ browser's six connections per site that terminal streams allow); a fifth is
147
+ answered at once, or takes a picture if it has none yet, and asks again shortly.
148
+
149
+ `tests/browser-picture-rate.test.cjs` (in `npm test`) checks all of this against
150
+ the running app: pictures a second while seen against while the tab is hidden,
151
+ scrolled out of view, in another workspace tab or with the view hidden; nothing
152
+ sent for a still page; the two ceilings; and an agent's observation with and
153
+ without a viewer.
154
+
155
+ Localhost means the terminal server host, not the phone or tablet. HTTP and HTTPS
156
+ are supported; file URLs and embedded URL credentials are rejected.
157
+
158
+ ## Agent control
159
+
160
+ The agent surface describes what it sees and what it did. It does not make an
161
+ agent guess from a picture alone, and it does not report success it cannot show.
162
+
163
+ - **Observations.** `GET /api/browser/:id/observe` returns a screenshot plus a
164
+ label: observation id, capture time, viewport size, scroll offset, address,
165
+ title, and a revision counter. `?elements=1` adds the controls.
166
+ - **Controls by identity.** `GET /api/browser/:id/elements` catalogs controls
167
+ across every frame (including cross-origin iframes) and open shadow roots with
168
+ role, accessible name, value, state, box, and a stable `ref` (`e12`). The ref
169
+ is a DOM marker, not an index, so it survives unrelated re-renders.
170
+ - **Actions.** `POST /api/browser/:id/action` accepts `click`, `hover`, `drag`,
171
+ `type`, `key`, `scroll`, `select`, `navigate`, `back`, `forward`, and `reload`,
172
+ by `ref` or by coordinate. Key combinations such as `Alt+M` are supported;
173
+ `type` with `replace: true` clears the field first.
174
+ - **Results.** Every action returns `status`: `completed`, `missing`,
175
+ `wrong-kind`, `failed`, `stale`, or `unconfirmed`, plus the focused control and
176
+ its value where useful. A coordinate cites the observation it came from; if
177
+ the page's geometry moved, the action is refused with `409` and an instruction
178
+ to look again.
179
+ - **Waiting.** `POST /api/browser/:id/wait` waits for an address, title, text,
180
+ selector, or field value, always bounded by a timeout.
181
+ - **Scrolling.** `scroll` with a ref or selector scrolls that element's own
182
+ scroll box; without one it scrolls the page deliberately.
183
+ - **Sizing.** `POST /api/browser/:id/sizing` with `mode: fixed` locks the page
184
+ viewport so the owner's viewer scales the picture instead of rearranging the
185
+ page. `mode: fit` restores the old behaviour.
186
+
187
+ The project's test suite exercises these against a real browser; the suite is
188
+ not part of the installed package.
189
+
190
+ ## Runtime and trust
191
+
192
+ Puppeteer is a production dependency; `npm ci` downloads its compatible
193
+ Chromium. `TERMINALONE_CHROME` can select an operator-installed compatible
194
+ binary. The name is a compatibility holdover; the binary it points at is just
195
+ Chromium. Use the pinned runtime by default.
196
+
197
+ The existing loopback listener and request-origin checks protect workspace
198
+ routes. User control keys stay in page memory and are never embedded in page
199
+ URLs. API responses use no-store. At most 32 browser contexts can remain open.
200
+
201
+ Grants protect cooperative API clients, not hostile processes that already have
202
+ unrestricted access to the host shell or the browser owner's application. The
203
+ local server has the user's existing authority. Keep remote access behind the
204
+ existing authenticated proxy in [PACKAGING.md](PACKAGING.md).
205
+
206
+ Browser sessions and grants are in memory. Restarting the server closes them;
207
+ saved browser profiles and seamless session persistence are not implemented. No,
208
+ "seamless" is not a feature we are hiding. It does not exist.
209
+
210
+ ## Validation
211
+
212
+ `npm run test:workspace` starts the workspace and its own local preview site,
213
+ then exercises terminal input, tabs, sharing, revocation, the agent browser,
214
+ hidden-agent navigation, reduced motion, and the phone, tablet, and desktop
215
+ layouts. It captures evidence at 393×852, 820×1180, 1440×900, and 1920×1080.
216
+ `tests/browser-picture-rate.test.cjs` covers the picture rate described under
217
+ "Pictures".
218
+
219
+ [DESIGN.md](../DESIGN.md) lists the five named motions and the device-specific
220
+ structures.
221
+
222
+ ```text
223
+ ┌──────────────────────────────────────────────────────────┐
224
+ │ DOCUMENT METADATA │
225
+ ├──────────────────────────────────────────────────────────┤
226
+ │ Classification: Technical / Browser Workspace │
227
+ │ Cat Supervision: Bella, asleep on the tab strip │
228
+ │ "I Don't Suck": PASS │
229
+ │ Corporate Feelings: HURT (intended) │
230
+ └──────────────────────────────────────────────────────────┘
231
+ ```
232
+
233
+ **DOCUMENT ENDS**
234
+
235
+ *— Workspace, Floyd's Labs*
236
+ *The Garage — Brown County, Indiana*
237
+ *"A browser tab should be a browser, not a JPEG with a dream."*