townmouse 0.2.1 → 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 (41) hide show
  1. package/CHANGELOG.md +72 -2
  2. package/DESIGN.md +26 -42
  3. package/README.md +286 -54
  4. package/SECURITY.md +3 -0
  5. package/TOWNMOUSE.md +1 -1
  6. package/bin/townmouse +2 -2
  7. package/docs/PACKAGING.md +104 -8
  8. package/docs/browser-workspace.md +62 -9
  9. package/docs/panes.md +199 -9
  10. package/native/TownmouseApp.swift +5 -5
  11. package/npm-shrinkwrap.json +1282 -0
  12. package/package.json +11 -7
  13. package/public/browser-picture.mjs +159 -0
  14. package/public/features/app-version.mjs +35 -0
  15. package/public/features/autosave.mjs +5 -1
  16. package/public/features/multi-window-sync.mjs +3 -1
  17. package/public/features/osc-bridge.mjs +8 -3
  18. package/public/features/session-manager.mjs +202 -100
  19. package/public/features/status-metrics.mjs +23 -0
  20. package/public/features/tab-reorder.mjs +8 -0
  21. package/public/features/window-title.mjs +10 -3
  22. package/public/index.html +617 -78
  23. package/public/input-guard.mjs +10 -2
  24. package/public/panes.css +189 -13
  25. package/public/panes.html +4 -1
  26. package/public/panes.mjs +667 -109
  27. package/public/workspace.css +198 -24
  28. package/public/workspace.mjs +346 -106
  29. package/scripts/install-service.sh +97 -63
  30. package/scripts/panes +134 -5
  31. package/scripts/retire-legacy-service.sh +76 -0
  32. package/scripts/{t1.sh → townmouse.sh} +60 -21
  33. package/scripts/uninstall-service.sh +31 -15
  34. package/src/agent-guide.js +72 -3
  35. package/src/attachments.js +2 -2
  36. package/src/browser-dom.js +5 -2
  37. package/src/browser-workspace.js +549 -62
  38. package/src/owner-page.js +43 -0
  39. package/src/request-boundary.js +1 -1
  40. package/src/server.js +588 -128
  41. package/src/workspace-panes.js +423 -91
package/docs/PACKAGING.md CHANGED
@@ -78,14 +78,51 @@ The server refuses to start with that explanation rather than a stack trace when
78
78
  the engine cannot load. The container channel needs no such step; the image
79
79
  compiles node-pty during `npm ci`.
80
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
+
81
118
  The CLI surface is small on purpose:
82
119
 
83
120
  ```sh
84
121
  npm ci
85
122
  npm start
86
123
  npx townmouse
87
- townmouse --port 11001
88
- townmouse --port=11001 --no-open
124
+ townmouse --port 11002
125
+ townmouse --port=11002 --no-open
89
126
  townmouse --help
90
127
  townmouse --version
91
128
  npm pack
@@ -97,9 +134,9 @@ and neither should you.
97
134
 
98
135
  ### 2. Container (Linux home server)
99
136
 
100
- The `Dockerfile` uses `node:22-bookworm-slim`, installs Chromium, sets
137
+ The `Dockerfile` uses `node:22-alpine`, installs Chromium, sets
101
138
  `PUPPETEER_SKIP_DOWNLOAD=1` and `TERMINALONE_CHROME=/usr/bin/chromium`, runs as
102
- the `node` user, exposes `11001`, and declares volumes for both
139
+ the `node` user, exposes `11002`, and declares volumes for both
103
140
  `/home/node/.townmouse` (workspace, attachments, pane token) and
104
141
  `/home/node/.config/terminalone` (voice settings).
105
142
  It sets `HOST=0.0.0.0` for container port forwarding and
@@ -117,7 +154,7 @@ TOWNMOUSE_VERSION=$(node -p "require('./package.json').version") \
117
154
  --build-arg GIT_REVISION="$GIT_REVISION" \
118
155
  -t townmouse:"$TOWNMOUSE_VERSION" \
119
156
  -t townmouse:latest .
120
- docker run --rm -p 127.0.0.1:11001:11001 -v townmouse-home:/home/node/.townmouse -v townmouse-config:/home/node/.config/terminalone townmouse
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
121
158
  ```
122
159
 
123
160
  The host port may differ from the container port; the request boundary accepts
@@ -126,7 +163,7 @@ host loopback. Mount project directories explicitly; the terminal starts in
126
163
  `/home/node`, not in your project. Health:
127
164
 
128
165
  ```sh
129
- curl http://127.0.0.1:11001/health
166
+ curl http://127.0.0.1:11002/health
130
167
  ```
131
168
 
132
169
  `GET /health` returns `status: "ok"` plus the live session count. If it does not
@@ -136,7 +173,7 @@ guessing.
136
173
  ### 3. macOS application wrapper
137
174
 
138
175
  `native/TownmouseApp.swift` is a WKWebView shell pointed at `TOWNMOUSE_URL`
139
- (default `http://127.0.0.1:11001`). It probes `/health`. If nothing answers, it
176
+ (default `http://127.0.0.1:11002`). It probes `/health`. If nothing answers, it
140
177
  tries a separately installed launcher and waits up to 12 seconds before showing
141
178
  a startup error.
142
179
 
@@ -146,6 +183,25 @@ backend. The installer scripts ship in the npm package, so this works from a
146
183
  global or local install; it is still a local convenience build, not a signed
147
184
  distribution.
148
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
+
149
205
  A distributable `.app` must bundle or launch the Node server or npm CLI, use a
150
206
  stable data directory, and be codesigned and notarized. Until that is done, there
151
207
  is no signed downloadable macOS release. The wrapper is a WebView with
@@ -180,6 +236,45 @@ CLI, and data directory is Townmouse.
180
236
  - Package version, Git tag, Docker tag, and release notes must agree. If they
181
237
  disagree, it is not a release; it is a rumor with a download link.
182
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
+
183
278
  ## Release gates
184
279
 
185
280
  1. `npm ci` from a clean checkout.
@@ -245,13 +340,14 @@ None of these are secrets. Shipping around them without saying so would be.
245
340
  ## Release checklist
246
341
 
247
342
  - [ ] Version and changelog updated.
343
+ - [ ] `npm run version:check` passes: the version agrees everywhere and both entries are written.
248
344
  - [ ] Clean `npm ci` and `npm test`.
249
345
  - [ ] `npm run test:package` green: the packed tarball installs and runs.
250
346
  - [ ] Pane UI/attachment/input evidence refreshed.
251
347
  - [ ] Codex review clean on the release commit.
252
348
  - [ ] `npm pack` inspected and checksummed.
253
349
  - [ ] Docker image built and smoke-tested.
254
- - [ ] Tag pushed; GitHub release notes; npm publish.
350
+ - [ ] Version bumped and changelog dated; merge to `main` runs `publish.yml` (npm publish, tag, GitHub release) once trusted publishing is configured.
255
351
  - [ ] Backup/rollback instructions included.
256
352
 
257
353
  If it is not checked, it is not shipped. That is the entire policy.
@@ -42,7 +42,8 @@ TOWNMOUSE_PANES_CLI=<repo>/scripts/panes
42
42
 
43
43
  So it can create tabs, add panes, open URLs, run commands, read output, and send
44
44
  input natively. No connection code is copied between the browser and the
45
- terminal. The pane limits are 24 tabs, four panes per tab, 24 terminal panes, and
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
46
47
  32 browser contexts. The full command list is in [panes.md](panes.md).
47
48
 
48
49
  ## Layouts
@@ -82,7 +83,9 @@ Closing a tab destroys its context.
82
83
  The supplied endpoint accepts a Bearer token in the `Authorization` header:
83
84
 
84
85
  - `GET /content`: current URL, title, and visible text.
85
- - `GET /snapshot`: current URL, title, and JPEG image in base64.
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.)
86
89
  - `POST /action` with JSON: `navigate` (url), `back`, `forward`, `reload`,
87
90
  `click` (x,y in the dimensions returned by `/snapshot`), `type` (text), `key`
88
91
  (Puppeteer key name), `scroll` (deltaY).
@@ -95,10 +98,59 @@ Choose **Agent** to create a separate context with control granted. Hide view
95
98
  keeps the browser running headless. Reopen Agent to observe the same context.
96
99
  Revoking access also works on the agent context.
97
100
 
98
- The viewer samples images once per second when open. This is remote interaction,
99
- not a native browser DOM exposed to the viewer's assistive technology. Agents can
100
- use `/content` for text. Keyboard Tab moves through the workspace interface; the
101
- Send field, Tab, and Enter buttons interact with page inputs.
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.
102
154
 
103
155
  Localhost means the terminal server host, not the phone or tablet. HTTP and HTTPS
104
156
  are supported; file URLs and embedded URL credentials are rejected.
@@ -132,9 +184,8 @@ agent guess from a picture alone, and it does not report success it cannot show.
132
184
  viewport so the owner's viewer scales the picture instead of rearranging the
133
185
  page. `mode: fit` restores the old behaviour.
134
186
 
135
- `docs/plans/townmouse-orchestrator-assessment-2026-11-20-implementation.md`
136
- maps each of these to the assessment item it answers, and
137
- `tests/agent-control.test.cjs` exercises them against a real browser.
187
+ The project's test suite exercises these against a real browser; the suite is
188
+ not part of the installed package.
138
189
 
139
190
  ## Runtime and trust
140
191
 
@@ -162,6 +213,8 @@ saved browser profiles and seamless session persistence are not implemented. No,
162
213
  then exercises terminal input, tabs, sharing, revocation, the agent browser,
163
214
  hidden-agent navigation, reduced motion, and the phone, tablet, and desktop
164
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".
165
218
 
166
219
  [DESIGN.md](../DESIGN.md) lists the five named motions and the device-specific
167
220
  structures.
package/docs/panes.md CHANGED
@@ -21,7 +21,8 @@ On first start, with no saved workspace, the pane surface seeds one tab with a
21
21
  terminal pane titled **Orchestrator**. That is a real PTY of its own — a second
22
22
  shell alongside the standard terminal view — created by the same server process,
23
23
  not a second application instance. It is intentional: the workspace opens with a
24
- place for the orchestrator to work. Keep it.
24
+ place for the orchestrator to work. Keep it. It is an agent's pane: an agent can
25
+ report and run from inside it from the first moment.
25
26
 
26
27
  The terminal panes are real PTYs from the embedded TerminalOne engine. The
27
28
  browser panes are real Chromium pages rendered by the server. Neither one is a
@@ -48,6 +49,16 @@ runaway agent runs out of room before it runs the machine out of memory.
48
49
  grid. Menu also has smaller/larger text, and a shortcut sheet.
49
50
  - Closing a pane or tab asks first. An answerable `alert`/`confirm`/`prompt`
50
51
  appears as a card; a forgotten dialog is dismissed after 30 seconds.
52
+ - **Agent access** is in the header of every pane you open: **Private**,
53
+ **View only**, or **Allow control**. These are the browser tab's three levels,
54
+ in the same words. Yours start Private. Change it there when you want an agent
55
+ to look at a pane or to drive it; setting it back to Private ends what an
56
+ agent was doing on that pane at once: its view of the output closes and a
57
+ command it was waiting on stops. An agent's ask appears under the header of
58
+ the pane it is about, with its reason, and is answered there: Not now, View
59
+ only, Allow control. An ask waits five minutes and then clears itself. A pane
60
+ an agent opened carries its "agent" mark instead and has no control; anything
61
+ typed into one of those is readable by agents.
51
62
  - Browser panes accept clicks, wheel scrolling, typing, Back, Forward, Reload,
52
63
  and an address. The browser is a real Chromium page rendered by the server,
53
64
  and its viewport reflows to the pane's actual size.
@@ -91,18 +102,73 @@ No code is copied between the browser and the terminal. Run the CLI directly:
91
102
  "$TOWNMOUSE_PANES_CLI" pane dialog <pane-id> --accept
92
103
  "$TOWNMOUSE_PANES_CLI" pane read <pane-id> --lines 120
93
104
  "$TOWNMOUSE_PANES_CLI" pane close <pane-id>
105
+ "$TOWNMOUSE_PANES_CLI" pane request <pane-id> --level control --message "why"
94
106
  "$TOWNMOUSE_PANES_CLI" attach ./screenshot.png --pane <pane-id>
95
107
  "$TOWNMOUSE_PANES_CLI" active --tab <tab-id> --pane <pane-id>
96
108
  ```
97
109
 
110
+ ### Whose pane is whose
111
+
112
+ The server decides whose pane or tab it is from the key that asks, and never
113
+ from a field in the request. A pane you open through the CLI or the API, with
114
+ the workspace token, is an agent's pane: every agent can read and drive it. So
115
+ is the seeded Orchestrator pane. A pane the owner opens from the page is the
116
+ owner's, and to you it is exactly what the owner has given:
117
+
118
+ | The owner gives | You can |
119
+ |---|---|
120
+ | **Private** (always at first) | See only that the pane exists and what you have on it. Its title, address, folder and output are not sent to you. |
121
+ | **View only** | Read it: the terminal's text and output stream, a job's result, the page's picture, controls and text, and waits. |
122
+ | **Allow control** | View only, and also type, press keys, run commands and jobs, report a status, open an address, act on the page, answer a page dialog and set the page's size. |
123
+
124
+ On the owner's pane, whatever you were given, you cannot close it, resize it,
125
+ move it, bring it forward, close a tab that holds it, or change what an agent
126
+ may do on it. Those stay the owner's.
127
+
128
+ Every pane in `panes state` carries `createdBy` (whose it is: `human` or
129
+ `agent`), `agentAccess` (what you have: `level` and `label`), and
130
+ `accessRequest` (an ask of yours that is waiting). A Private pane of the
131
+ owner's appears as an empty shape with `redacted: true`. A refusal is a 403
132
+ with a `code` (`PANE_PRIVATE`, `PANE_VIEW_ONLY` or `OWNER_ONLY`) and a message
133
+ that names the command to ask for more:
134
+
135
+ ```sh
136
+ "$TOWNMOUSE_PANES_CLI" pane request <pane-id> --level view|control [--message TEXT] [--timeout MS] [--no-wait]
137
+ "$TOWNMOUSE_PANES_CLI" pane request <pane-id> --cancel
138
+ ```
139
+
140
+ The ask is shown on that pane with your message. The command waits for the
141
+ answer, two minutes unless `--timeout` says otherwise: exit 0 when the owner
142
+ gives access, 3 while it is still waiting (run it again to keep waiting), 5
143
+ when the owner says Not now. `--no-wait` returns at once and prints the waiting
144
+ ask; `--cancel` withdraws it. One ask waits per pane; an unanswered ask clears
145
+ after five minutes; after Not now the pane cannot be asked about for five
146
+ minutes. Asking for a level the owner has already given is answered
147
+ `ALREADY_GRANTED`: there is nothing to ask for.
148
+
149
+ To show the owner one of your own panes, report it with `pane status` and bring
150
+ that pane forward with `panes active --tab <tab-id> --pane <pane-id>`.
151
+
152
+ The owner's key is never handed to you. It goes only to the owner's page,
153
+ opened in a browser, and only to that page's own request; a program making
154
+ ordinary requests is refused and told the steps above. These levels hold
155
+ against an agent's own key: the `panes` command, and the token in a pane's
156
+ environment. They do not hold against a program on the same Mac that presents
157
+ itself as the owner's page, by sending a browser's navigation details on
158
+ purpose. That is what the next stage, agents separated from the owner, is for.
159
+
160
+ No password field's value ever reaches you. A catalog, the result of a click or
161
+ of typing, and the report of the focused element all return `null` with
162
+ `redacted: true` for one, on the pane workspace and on the single-browser
163
+ workspace alike, and `pane browser wait --value` on a password field is refused.
164
+ Typing into the field works; only what comes back is withheld.
165
+
98
166
  ### Instruction sheet
99
167
 
100
168
  `panes guide` (or `GET /api/panes/guide`) prints the sheet an agent receives on
101
169
  connect: every tool, what it needs, what it returns, and — separately — which
102
170
  capabilities this connection has and has not been granted. It describes
103
- permissions; it does not enlarge them. See
104
- `docs/plans/townmouse-orchestrator-assessment-2026-11-20-implementation.md`
105
- for the full mapping of tools to assessment items.
171
+ permissions; it does not enlarge them.
106
172
 
107
173
  ### Pane ids default to the current pane
108
174
 
@@ -157,6 +223,14 @@ and open shadow roots. Each action returns a `status` (`completed`, `missing`,
157
223
  wait is bounded. In `fixed` sizing the owner's viewer scales the picture instead
158
224
  of rearranging the page.
159
225
 
226
+ None of this depends on whether anyone is looking at the pane. The owner's view
227
+ of a browser pane is pictured up to 30 times a second while the pane is on
228
+ screen and the page is changing, and not at all while it cannot be seen; that
229
+ is described under "Pictures" in
230
+ [browser-workspace.md](browser-workspace.md). An agent's `observe` is its own
231
+ capture: it does not start that stream, it is not made to wait behind it, and
232
+ an agent at work is never taken for a viewer.
233
+
160
234
  `pane create` defaults to `TOWNMOUSE_TAB_ID` when `--tab` is omitted. It also
161
235
  accepts `--cwd` and `--title`. `tab create` accepts `--activate` when the new
162
236
  tab should become active; without it, the CLI creates the tab without moving the
@@ -190,8 +264,61 @@ dragging a pane header or Alt+Shift+Arrow.
190
264
  The CLI reads `TOWNMOUSE_API` and `TOWNMOUSE_TOKEN` from the environment and
191
265
  falls back to `~/.townmouse/pane-token` when the token is absent. It sends the
192
266
  token in `X-Townmouse-Token`; the API also accepts `Authorization: Bearer
193
- <token>`. The owner bootstrap route is separate: an agent token cannot bootstrap
194
- the owner workspace.
267
+ <token>`. The owner's page sends a key of its own in `X-Townmouse-Owner`
268
+ instead. The server reads who is asking from the key alone: the workspace token
269
+ is an agent, the page key is the owner, and anything else is a 403 with the code
270
+ `UNKNOWN_KEY`. `createdBy` in a request body is ignored; older clients still
271
+ send it, and a current server reaches the same answer from the key.
272
+
273
+ ### Shell sessions
274
+
275
+ The shells in the owner's terminal row (`/`, the terminal screen) answer under
276
+ `/api/sessions`, with the same token:
277
+
278
+ ```sh
279
+ "$TOWNMOUSE_PANES_CLI" session list
280
+ "$TOWNMOUSE_PANES_CLI" session create [--name TEXT] [--cwd PATH] [--activate]
281
+ "$TOWNMOUSE_PANES_CLI" session rename <session> --name TEXT
282
+ "$TOWNMOUSE_PANES_CLI" session activate <session>
283
+ "$TOWNMOUSE_PANES_CLI" session close <session>
284
+ ```
285
+
286
+ A shell belongs to whoever started it, as a pane does. These commands reach
287
+ the shells agents started. A `<session>` is its name, its full id, or the
288
+ first eight or more characters of its id, among the shells `session list`
289
+ shows you. A start of an id that matches more than one of them is refused,
290
+ and so is a name that is not among them: one of the owner's shells comes back
291
+ as not found.
292
+
293
+ `session list` returns the shells agents started, in the owner's row order:
294
+ its `id`, `name`, `command`, `cwd`, when it was started and last viewed, how
295
+ many windows are viewing it (`viewers`), and whether it is the one the owner
296
+ is viewing (`active`). Of the owner's own shells it says only how many there
297
+ are: `ownerStarted`, beside the limit (`max`). `activeSessionId` names the
298
+ shell the owner looked at last when that is one of yours; while the owner is
299
+ looking at one of their own it is null, and so is `activation`.
300
+
301
+ `session create` starts a shell nobody is viewing. The key that asks decides
302
+ whose it is: an agent's key makes it an agent's shell, and `createdBy` in the
303
+ request is ignored. It appears in the owner's row at once and does not change
304
+ which shell the owner is looking at, unless `--activate` is passed. `--cwd`
305
+ must be an existing directory; `--name` is at most 40 characters and no two
306
+ shells share one. `session rename` gives one of your shells a name the owner
307
+ can read. `session close` ends one of your shells and anything running in it;
308
+ a window that was viewing it moves to another shell and says so. It cannot be
309
+ undone. On a shell the owner started, renaming, showing and closing are the
310
+ owner's alone: an agent is refused with 403 `OWNER_ONLY` and the shell is left
311
+ as it was.
312
+
313
+ `session activate` is the one action that moves the owner's view: every open
314
+ Townmouse terminal window shows that shell, when it is one of yours. The
315
+ ground rule applies: use it when the owner asked to see that shell.
316
+
317
+ A shell keeps running after you stop looking at it, until it is closed or the
318
+ app stops, and at most ten run at once. When you hold a shell you may close, a
319
+ refused `create` says to close one first. When you hold none, it says that
320
+ every session is in use and how many of them the owner started. Close the
321
+ shells you start.
195
322
 
196
323
  ## Wire facts
197
324
 
@@ -213,6 +340,13 @@ the owner workspace.
213
340
  - Resize is `POST /api/panes/panes/<pane-id>/resize`. Terminal columns are
214
341
  clamped to 20-400 and rows to 5-200. Browser panes set a viewport clamped to
215
342
  320-1920 by 240-1200.
343
+ - A browser pane's picture is `GET /api/panes/panes/<pane-id>/browser/snapshot`.
344
+ Without query parameters a picture is taken for the caller there and then
345
+ (an agent's `observe` takes its own, separately). The owner's page sends
346
+ `watch=1&since=<seq>&wait=<ms>` while the pane is on screen (the request waits
347
+ up to `wait` ms for the next picture; the answer carries `changed` and `seq`,
348
+ and a picture only when there is a new one) and `watch=0` while the pane
349
+ cannot be seen (title, address and page prompt only, no picture).
216
350
  - `POST /api/panes/panes/<pane-id>/start` spawns a deferred terminal at the
217
351
  measured cols/rows; the UI creates terminals with `start:false` so the first
218
352
  prompt is laid out at the visible width.
@@ -226,9 +360,65 @@ the owner workspace.
226
360
  - State includes an `epoch` minted per server boot and `restored`. After a
227
361
  restart the client keeps tabs, pane kinds, titles, cwd, and browser URLs but
228
362
  warns that terminal scrollback and running jobs are gone.
229
- - Owner bootstrap (`GET /api/panes/bootstrap`) requires the HttpOnly owner
230
- cookie minted on page navigation. A pane token receives 403 there; the token
231
- is accepted by the pane API and by attachment uploads.
363
+ - Owner bootstrap (`GET /api/panes/bootstrap`) answers only the owner's page.
364
+ It takes the HttpOnly owner cookie, which is minted only when an owner page
365
+ is reached by a navigation (`Sec-Fetch-Mode: navigate`, which a browser sets
366
+ and a plain HTTP client does not), and requires the mark of the page's own
367
+ request (`Sec-Fetch-Site: same-origin`; an absent value is refused). Anything
368
+ else is a 403 with a code: `OWNER_PAGE_REQUIRED`, `NOT_FROM_OWNER_PAGE` or
369
+ `AGENT_TOKEN`, each with a message that names what an agent does instead. A
370
+ pane token receives 403 there; the token is accepted by the pane API, by
371
+ attachment uploads and by the shell-session API. The single-browser workspace's bootstrap
372
+ (`GET /api/browser/bootstrap`) is guarded the same way. The bootstrap hands
373
+ the page its key (`ownerKey`), which lives for one server run and is never
374
+ written to disk. When the server restarts the page's key stops working; the
375
+ page sees `UNKNOWN_KEY`, renews its key through the cookie, and reloads once
376
+ if the cookie has gone too.
377
+ - Every state answer is numbered (`seq`). The page ignores an answer older
378
+ than the one it has, so a change the person just made cannot flash back.
379
+ - Grants are held in memory. A saved workspace records whose pane is whose, so
380
+ an agent's pane is still the agent's after a restart, while one of the
381
+ owner's comes back Private.
382
+ - Shell sessions: `GET /api/sessions` returns `{ epoch, sessions, activeSessionId,
383
+ max, activation }` to the owner. An agent gets the same shape holding only
384
+ the shells agents started, plus `ownerStarted`, the count of the owner's.
385
+ `POST /api/sessions` takes `{ name?, cwd?, activate? }` and answers 200 with
386
+ the session, 409 `SESSION_LIMIT` at the cap or `NAME_IN_USE` for a name in
387
+ use, 400 for a name or folder that cannot be used. Who started it is read
388
+ from the key; `createdBy` in the body is ignored.
389
+ `PATCH /api/sessions/<id>` takes `{ name }`. `POST /api/sessions/<id>/activate`
390
+ answers `{ activated, windows }`. `DELETE /api/sessions/<id>` answers
391
+ `{ closed, ...state }`. For an agent, those three on a shell the owner
392
+ started are 403 `OWNER_ONLY`. An unknown session is 404 `SESSION_NOT_FOUND`. `epoch` is minted per app
393
+ run; a different one means the app was restarted. The owner's page drives the
394
+ same actions over its own WebSocket and is sent the list on every change, so
395
+ the row, the list and this API are one list. `GET /health` counts the same
396
+ shells in `sessions`.
397
+
398
+ ### What an agent may call on one of the owner's panes
399
+
400
+ Every route under `/api/panes` is open to the owner. For an agent:
401
+
402
+ | Route | Private | View only | Allow control |
403
+ |---|---|---|---|
404
+ | `GET /state`, `GET /guide` | Yes (the owner's Private panes as empty shapes) | Yes | Yes |
405
+ | `POST /tabs`, `POST /tabs/:id/panes` (opening a pane of the agent's own) | Yes | Yes | Yes |
406
+ | `GET /panes/:id/text`, `/read`, `/stream`, `/wait`, `/jobs/:jobId` | 403 `PANE_PRIVATE` | Yes | Yes |
407
+ | `GET /panes/:id/browser/snapshot`, `/observe`, `/elements`, `/content`; `POST /panes/:id/browser/wait` | 403 `PANE_PRIVATE` | Yes | Yes |
408
+ | `POST /panes/:id/input`, `/keys`, `/command`, `/jobs`, `/status`, `/start`, `/url` | 403 `PANE_PRIVATE` | 403 `PANE_VIEW_ONLY` | Yes |
409
+ | `POST /panes/:id/browser/action`, `/reopen`, `/dialog`, `/sizing`; `DELETE /panes/:id/jobs/:jobId` | 403 `PANE_PRIVATE` | 403 `PANE_VIEW_ONLY` | Yes |
410
+ | `POST /panes/:id/resize`, `DELETE /panes/:id` | 403 `OWNER_ONLY` | 403 `OWNER_ONLY` | 403 `OWNER_ONLY` |
411
+ | `POST /tabs/:id/reorder` moving it; `POST /active` bringing it, or a tab of only the owner's panes, forward; `DELETE /tabs/:id` for a tab holding one | 403 `OWNER_ONLY` | 403 `OWNER_ONLY` | 403 `OWNER_ONLY` |
412
+ | `POST /panes/:id/permission` | 403 `OWNER_ONLY` | 403 `OWNER_ONLY` | 403 `OWNER_ONLY` |
413
+ | `POST /panes/:id/request-access` | Asks | Asks, for what is missing | 409 `ALREADY_GRANTED` |
414
+ | `DELETE /panes/:id/request-access` | Withdraws the agent's ask | Withdraws the agent's ask | Withdraws the agent's ask |
415
+
416
+ On a pane an agent opened, every route above answers the agent. Each check is
417
+ made before the work and again after it, and a level lowered while a stream,
418
+ a wait or a queued action is in flight ends it. On the owner's pane the owner
419
+ sets the level with `POST /api/panes/panes/<id>/permission` (`private`,
420
+ `view` or `control`), and answers or dismisses an ask by setting a level or
421
+ with `DELETE /api/panes/panes/<id>/request-access`.
232
422
 
233
423
  The workspace limits are real. The token is real. The panes are real. The old
234
424
  way copied a connection string between the browser and the terminal; this one
@@ -7,7 +7,7 @@ import WebKit
7
7
  final class TownmouseApp: NSObject, NSApplicationDelegate {
8
8
  private var window: NSWindow!
9
9
  private var webView: WKWebView!
10
- private let serviceURL = URL(string: ProcessInfo.processInfo.environment["TOWNMOUSE_URL"] ?? ProcessInfo.processInfo.environment["TERMINALONE_URL"] ?? "http://127.0.0.1:11001")!
10
+ private let serviceURL = URL(string: ProcessInfo.processInfo.environment["TOWNMOUSE_URL"] ?? ProcessInfo.processInfo.environment["TERMINALONE_URL"] ?? "http://127.0.0.1:11002")!
11
11
 
12
12
  static func main() {
13
13
  let app = NSApplication.shared
@@ -83,9 +83,9 @@ final class TownmouseApp: NSObject, NSApplicationDelegate {
83
83
  candidates.append(path)
84
84
  }
85
85
  candidates += [
86
- NSString(string: "~/.local/bin/t1").expandingTildeInPath,
87
- "/usr/local/bin/t1",
88
- NSString(string: "~/bin/t1").expandingTildeInPath,
86
+ NSString(string: "~/.local/bin/townmouse").expandingTildeInPath,
87
+ "/usr/local/bin/townmouse",
88
+ NSString(string: "~/bin/townmouse").expandingTildeInPath,
89
89
  ]
90
90
  guard let launcher = candidates.first(where: { FileManager.default.isExecutableFile(atPath: $0) }) else { return }
91
91
  let process = Process()
@@ -99,7 +99,7 @@ final class TownmouseApp: NSObject, NSApplicationDelegate {
99
99
  private func presentStartupError() {
100
100
  let alert = NSAlert()
101
101
  alert.messageText = "Townmouse could not start"
102
- alert.informativeText = "Run ‘t1 doctor’ in a terminal for the exact cause and repair command."
102
+ alert.informativeText = "Run ‘townmouse doctor’ in a terminal for the exact cause and repair command."
103
103
  alert.alertStyle = .critical
104
104
  alert.addButton(withTitle: "OK")
105
105
  alert.runModal()