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.
- package/CHANGELOG.md +72 -2
- package/DESIGN.md +26 -42
- package/README.md +286 -54
- package/SECURITY.md +3 -0
- package/TOWNMOUSE.md +1 -1
- package/bin/townmouse +2 -2
- package/docs/PACKAGING.md +104 -8
- package/docs/browser-workspace.md +62 -9
- package/docs/panes.md +199 -9
- package/native/TownmouseApp.swift +5 -5
- package/npm-shrinkwrap.json +1282 -0
- package/package.json +11 -7
- package/public/browser-picture.mjs +159 -0
- package/public/features/app-version.mjs +35 -0
- package/public/features/autosave.mjs +5 -1
- package/public/features/multi-window-sync.mjs +3 -1
- package/public/features/osc-bridge.mjs +8 -3
- package/public/features/session-manager.mjs +202 -100
- package/public/features/status-metrics.mjs +23 -0
- package/public/features/tab-reorder.mjs +8 -0
- package/public/features/window-title.mjs +10 -3
- package/public/index.html +617 -78
- package/public/input-guard.mjs +10 -2
- package/public/panes.css +189 -13
- package/public/panes.html +4 -1
- package/public/panes.mjs +667 -109
- package/public/workspace.css +198 -24
- package/public/workspace.mjs +346 -106
- package/scripts/install-service.sh +97 -63
- package/scripts/panes +134 -5
- package/scripts/retire-legacy-service.sh +76 -0
- package/scripts/{t1.sh → townmouse.sh} +60 -21
- package/scripts/uninstall-service.sh +31 -15
- package/src/agent-guide.js +72 -3
- package/src/attachments.js +2 -2
- package/src/browser-dom.js +5 -2
- package/src/browser-workspace.js +549 -62
- package/src/owner-page.js +43 -0
- package/src/request-boundary.js +1 -1
- package/src/server.js +588 -128
- package/src/workspace-panes.js +423 -91
|
@@ -1,51 +1,90 @@
|
|
|
1
1
|
#!/bin/bash
|
|
2
2
|
#
|
|
3
|
-
#
|
|
4
|
-
# be healthy, then opens the UI as a chrome-less app window (falls back to
|
|
5
|
-
# default browser). This is the volume-resident implementation; install-service.sh
|
|
6
|
-
# generates a self-contained `
|
|
7
|
-
# plus
|
|
3
|
+
# townmouse — open Townmouse. Ensures the always-on service is running, waits for
|
|
4
|
+
# it to be healthy, then opens the UI as a chrome-less app window (falls back to
|
|
5
|
+
# the default browser). This is the volume-resident implementation; install-service.sh
|
|
6
|
+
# generates a self-contained `townmouse` launcher on the internal disk that delegates
|
|
7
|
+
# here, plus /Applications/Townmouse.app. Run install once, then use `townmouse` or
|
|
8
|
+
# Spotlight.
|
|
9
|
+
#
|
|
10
|
+
# Townmouse keeps its own service name and port so it can sit beside TerminalOne,
|
|
11
|
+
# the engine it embeds: Townmouse is `com.floyd.townmouse` on 11002, TerminalOne is
|
|
12
|
+
# `com.floyd.terminalone` on 11001.
|
|
8
13
|
#
|
|
9
14
|
set -euo pipefail
|
|
10
15
|
|
|
11
16
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
|
|
12
|
-
PORT="${PORT:-
|
|
17
|
+
PORT="${PORT:-11002}"
|
|
13
18
|
APP_DIR="${TERMINALONE_APP_DIR:-$(cd "$SCRIPT_DIR/.." && pwd -P)}"
|
|
14
19
|
LOG_DIR="${TERMINALONE_LOG_DIR:-$HOME/Library/Logs/Townmouse}"
|
|
15
|
-
|
|
16
|
-
HEALTH_URL="${TERMINALONE_HEALTH_URL:-$URL/health}"
|
|
17
|
-
LABEL="com.floyd.terminalone"
|
|
20
|
+
LABEL="com.floyd.townmouse"
|
|
18
21
|
DOMAIN="gui/$(id -u)"
|
|
19
22
|
SERVE_ONLY=false
|
|
20
|
-
[ "${1:-}" = "--serve-only" ] && SERVE_ONLY=true
|
|
21
23
|
|
|
22
24
|
show_usage() {
|
|
23
25
|
cat <<'EOF'
|
|
24
|
-
Usage:
|
|
26
|
+
Usage: townmouse [--port <n>] [--no-open]
|
|
25
27
|
|
|
26
28
|
Open Townmouse, or ensure its service is healthy without opening a browser.
|
|
27
29
|
|
|
28
30
|
Options:
|
|
29
|
-
--
|
|
31
|
+
--port <n> Port for the local server (default 11002)
|
|
32
|
+
--no-open Start or verify the service, then exit
|
|
33
|
+
--serve-only Same as --no-open
|
|
34
|
+
-v, --version Show the installed version and exit
|
|
30
35
|
-h, --help Show this help and exit
|
|
31
36
|
EOF
|
|
32
37
|
}
|
|
33
38
|
|
|
34
|
-
case "${1:-}" in
|
|
35
|
-
help|-h|--help)
|
|
36
|
-
show_usage
|
|
37
|
-
exit 0
|
|
38
|
-
;;
|
|
39
|
-
esac
|
|
40
|
-
|
|
41
39
|
show_error() {
|
|
42
40
|
local msg="$1"
|
|
43
|
-
printf '
|
|
41
|
+
printf 'townmouse: %s\n' "$msg" >&2
|
|
44
42
|
if [ ! -t 2 ] && command -v osascript >/dev/null 2>&1; then
|
|
45
43
|
osascript -e "display dialog \"$msg\" with title \"Townmouse\" buttons {\"OK\"} default button \"OK\" with icon caution" >/dev/null 2>&1 || true
|
|
46
44
|
fi
|
|
47
45
|
}
|
|
48
46
|
|
|
47
|
+
while [ "$#" -gt 0 ]; do
|
|
48
|
+
case "$1" in
|
|
49
|
+
help|-h|--help)
|
|
50
|
+
show_usage
|
|
51
|
+
exit 0
|
|
52
|
+
;;
|
|
53
|
+
-v|--version)
|
|
54
|
+
sed -n 's/^ "version": "\([^"]*\)".*/\1/p' "$APP_DIR/package.json" | head -n 1
|
|
55
|
+
exit 0
|
|
56
|
+
;;
|
|
57
|
+
--serve-only|--no-open)
|
|
58
|
+
SERVE_ONLY=true
|
|
59
|
+
;;
|
|
60
|
+
--port)
|
|
61
|
+
[ "$#" -ge 2 ] || { show_error "--port needs a number"; exit 2; }
|
|
62
|
+
PORT="$2"
|
|
63
|
+
shift
|
|
64
|
+
;;
|
|
65
|
+
--port=*)
|
|
66
|
+
PORT="${1#--port=}"
|
|
67
|
+
;;
|
|
68
|
+
esac
|
|
69
|
+
shift
|
|
70
|
+
done
|
|
71
|
+
|
|
72
|
+
# The same range bin/townmouse accepts. Leading zeros are ignored.
|
|
73
|
+
port_is_valid() {
|
|
74
|
+
local value="$1" digits
|
|
75
|
+
case "$value" in ''|*[!0-9]*) return 1 ;; esac
|
|
76
|
+
digits="$(printf '%s' "$value" | sed 's/^0*//')"
|
|
77
|
+
digits="${digits:-0}"
|
|
78
|
+
[ "${#digits}" -le 5 ] && [ "$digits" -ge 1 ] && [ "$digits" -le 65535 ]
|
|
79
|
+
}
|
|
80
|
+
if ! port_is_valid "$PORT"; then
|
|
81
|
+
show_error "Invalid port. Use a number from 1 to 65535."
|
|
82
|
+
exit 2
|
|
83
|
+
fi
|
|
84
|
+
|
|
85
|
+
URL="${TERMINALONE_URL:-http://localhost:$PORT}"
|
|
86
|
+
HEALTH_URL="${TERMINALONE_HEALTH_URL:-$URL/health}"
|
|
87
|
+
|
|
49
88
|
wait_for_health() {
|
|
50
89
|
local tries="${1:-32}"
|
|
51
90
|
for _ in $(seq 1 "$tries"); do
|
|
@@ -78,7 +117,7 @@ if ! wait_for_health 1; then
|
|
|
78
117
|
fi
|
|
79
118
|
|
|
80
119
|
if ! "$APP_DIR/scripts/node-runtime.sh" doctor >/dev/null 2>&1; then
|
|
81
|
-
show_error "Townmouse runtime is not ready. Run:
|
|
120
|
+
show_error "Townmouse runtime is not ready. Run: townmouse repair"
|
|
82
121
|
exit 1
|
|
83
122
|
fi
|
|
84
123
|
|
|
@@ -2,13 +2,16 @@
|
|
|
2
2
|
#
|
|
3
3
|
# Townmouse — remove the always-on LaunchAgent. Full reversal of install-service.sh.
|
|
4
4
|
# Stops the running service and deletes the plist. Does not touch app code or ports
|
|
5
|
-
# beyond releasing
|
|
5
|
+
# beyond releasing 11002 when the process stops. TerminalOne is a separate product:
|
|
6
|
+
# its service, its `t1` launcher and TerminalOne.app are never removed here.
|
|
6
7
|
#
|
|
7
8
|
set -euo pipefail
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
|
|
11
|
+
LABEL="com.floyd.townmouse"
|
|
10
12
|
DOMAIN="gui/$(id -u)"
|
|
11
|
-
|
|
13
|
+
PLIST_DIR="${TERMINALONE_PLIST_DIR:-$HOME/Library/LaunchAgents}"
|
|
14
|
+
PLIST="$PLIST_DIR/$LABEL.plist"
|
|
12
15
|
|
|
13
16
|
launchctl bootout "$DOMAIN/$LABEL" 2>/dev/null || true
|
|
14
17
|
if [ -f "$PLIST" ]; then
|
|
@@ -18,21 +21,34 @@ else
|
|
|
18
21
|
echo "No plist found at $PLIST (nothing to remove)"
|
|
19
22
|
fi
|
|
20
23
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
bash "$SCRIPT_DIR/retire-legacy-service.sh"
|
|
25
|
+
|
|
26
|
+
if [ -n "${TERMINALONE_BIN_DIR:-}" ]; then
|
|
27
|
+
LAUNCHER_DIRS=("$TERMINALONE_BIN_DIR")
|
|
28
|
+
else
|
|
29
|
+
LAUNCHER_DIRS=(/usr/local/bin "$HOME/.local/bin" "$HOME/bin")
|
|
30
|
+
fi
|
|
31
|
+
# Remove only the `townmouse` launcher this installer wrote: a regular file
|
|
32
|
+
# whose text says so. A symlink of that name is npm's own command for the
|
|
33
|
+
# package, or someone else's; it is never removed here.
|
|
34
|
+
for dir in "${LAUNCHER_DIRS[@]}"; do
|
|
35
|
+
[ -n "$dir" ] || continue
|
|
36
|
+
launcher="$dir/townmouse"
|
|
37
|
+
if [ -f "$launcher" ] && [ ! -L "$launcher" ] && grep -q 'Townmouse launcher' "$launcher" 2>/dev/null; then
|
|
38
|
+
rm -f "$launcher" && echo "Removed $launcher"
|
|
30
39
|
fi
|
|
31
40
|
done
|
|
32
41
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
42
|
+
if [ -n "${TERMINALONE_APPLICATIONS_DIR:-}" ]; then
|
|
43
|
+
APP_DIRS=("$TERMINALONE_APPLICATIONS_DIR")
|
|
44
|
+
else
|
|
45
|
+
APP_DIRS=(/Applications "$HOME/Applications")
|
|
46
|
+
fi
|
|
47
|
+
# Remove the no-terminal app launcher Townmouse's installer built, and nothing else.
|
|
48
|
+
for dir in "${APP_DIRS[@]}"; do
|
|
49
|
+
[ -n "$dir" ] || continue
|
|
50
|
+
bundle="$dir/Townmouse.app"
|
|
51
|
+
if [ -d "$bundle" ]; then rm -rf "$bundle" && echo "Removed $bundle"; fi
|
|
36
52
|
done
|
|
37
53
|
|
|
38
54
|
# Remove the PATH line added to shell rc files by install-service.sh.
|
package/src/agent-guide.js
CHANGED
|
@@ -84,6 +84,13 @@ const TOOLS = [
|
|
|
84
84
|
purpose: 'Report your own status for a terminal pane. This is the agent-reported status, separate from whether the program is running.',
|
|
85
85
|
needs: 'pane id, state'
|
|
86
86
|
},
|
|
87
|
+
{
|
|
88
|
+
name: 'pane.request',
|
|
89
|
+
cli: 'panes pane request <pane-id> --level view|control [--message TEXT] [--timeout MS] [--no-wait]',
|
|
90
|
+
purpose: 'Ask the owner for access to one of the owner\'s panes. The ask appears on that pane, with your message, and the command waits for the answer. Use it when a refusal says the pane is Private or View only.',
|
|
91
|
+
needs: 'pane id, and the level you need',
|
|
92
|
+
returns: 'granted, declined, withdrawn, or still waiting when the timeout passes'
|
|
93
|
+
},
|
|
87
94
|
{
|
|
88
95
|
name: 'browser.observe',
|
|
89
96
|
cli: 'panes pane browser observe <pane-id> [--elements] [--max N]',
|
|
@@ -174,6 +181,38 @@ const TOOLS = [
|
|
|
174
181
|
cli: 'panes attach <file> [--pane <pane-id>] [--type MIME]',
|
|
175
182
|
purpose: 'Upload a file to the workspace and optionally insert its path into a terminal pane.',
|
|
176
183
|
needs: 'file path'
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
name: 'session.list',
|
|
187
|
+
cli: 'panes session list',
|
|
188
|
+
purpose: 'List the shells agents started, as they stand in the owner\'s terminal row: each one\'s id, name, folder, how many windows are viewing it, and whether the owner is viewing it. The owner\'s own shells are not listed; ownerStarted says how many there are, and max is the limit. A session is named by its name, its id, or the start of its id.',
|
|
189
|
+
needs: 'nothing',
|
|
190
|
+
returns: 'The agent-started sessions, ownerStarted, the limit, and which session the owner is viewing when it is one of them.'
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
name: 'session.create',
|
|
194
|
+
cli: 'panes session create [--name TEXT] [--cwd PATH] [--activate]',
|
|
195
|
+
purpose: 'Start a shell nobody is viewing yet. It is an agent\'s shell from the moment it starts, whatever the request says. It appears in the owner\'s row and does not change which shell the owner is looking at unless you pass --activate. At most ten shells run at once; a refused create says so, and says when none of them is one an agent may close.',
|
|
196
|
+
needs: 'optional name, folder; optional --activate',
|
|
197
|
+
returns: 'The new session.'
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
name: 'session.rename',
|
|
201
|
+
cli: 'panes session rename <session> --name TEXT',
|
|
202
|
+
purpose: 'Give a shell an agent started a name the owner can read. On a shell the owner started it is refused with OWNER_ONLY. Names are unique and at most 40 characters.',
|
|
203
|
+
needs: 'one of the agent-started sessions, new name'
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
name: 'session.activate',
|
|
207
|
+
cli: 'panes session activate <session>',
|
|
208
|
+
purpose: 'Ask the owner\'s open Townmouse windows to show a shell an agent started. This moves the owner\'s view; use it only when they asked to see it. On a shell the owner started it is refused with OWNER_ONLY.',
|
|
209
|
+
needs: 'one of the agent-started sessions'
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
name: 'session.close',
|
|
213
|
+
cli: 'panes session close <session>',
|
|
214
|
+
purpose: 'End a shell an agent started, and anything still running in it. It cannot be undone. A window that was viewing it moves to another shell and says so. On a shell the owner started it is refused with OWNER_ONLY.',
|
|
215
|
+
needs: 'one of the agent-started sessions'
|
|
177
216
|
}
|
|
178
217
|
];
|
|
179
218
|
|
|
@@ -181,23 +220,48 @@ const CAPABILITIES = [
|
|
|
181
220
|
{
|
|
182
221
|
id: 'workspace',
|
|
183
222
|
granted: true,
|
|
184
|
-
summary: '
|
|
223
|
+
summary: 'Use the workspace through the scoped pane token you already hold: create tabs, and open panes of your own. A pane an agent opened is every agent\'s to read and drive, including the Orchestrator pane.'
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
id: 'owner.panes',
|
|
227
|
+
granted: false,
|
|
228
|
+
summary: 'See, read or drive a pane the owner opened. Each is Private until the owner gives View only (read) or Allow control (read and drive); a Private pane appears in state as an empty shape. Every pane\'s state says what you have on it under agentAccess, and a refusal names the level and the pane.request command to ask for more.'
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
id: 'owner.surface',
|
|
232
|
+
granted: false,
|
|
233
|
+
summary: 'Close, resize, move or bring forward one of the owner\'s panes, or close a tab that holds one. These are the owner\'s whatever you were given on the pane.'
|
|
185
234
|
},
|
|
186
235
|
{
|
|
187
236
|
id: 'browser.control',
|
|
188
237
|
granted: true,
|
|
189
|
-
summary: 'Drive browser panes you create or that the owner has
|
|
238
|
+
summary: 'Drive browser panes you create or that the owner has given Allow control on.'
|
|
190
239
|
},
|
|
191
240
|
{
|
|
192
241
|
id: 'browser.sharing',
|
|
193
242
|
granted: false,
|
|
194
|
-
summary: 'Change a
|
|
243
|
+
summary: 'Change a pane\'s agent access, or answer an ask. Only the owner page can do this; an agent token is refused.'
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
id: 'page.passwords',
|
|
247
|
+
granted: false,
|
|
248
|
+
summary: 'Read a password field\'s value. A catalog, an action\'s result and its focused-element report all return null with redacted: true for one, and it cannot be waited on. Typing into the field still works.'
|
|
195
249
|
},
|
|
196
250
|
{
|
|
197
251
|
id: 'owner.page',
|
|
198
252
|
granted: false,
|
|
199
253
|
summary: 'Read or bootstrap the owner workspace token. An Authorization header is refused at the bootstrap routes.'
|
|
200
254
|
},
|
|
255
|
+
{
|
|
256
|
+
id: 'shell-sessions',
|
|
257
|
+
granted: true,
|
|
258
|
+
summary: 'Start shells in the owner\'s terminal row, and list, name, show and close the shells agents started. A shell keeps running, with or without a viewer, until it is closed or the app stops; at most ten run at once.'
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
id: 'owner.shells',
|
|
262
|
+
granted: false,
|
|
263
|
+
summary: 'Rename, show or close a shell the owner started, or see the owner\'s shells. session list holds the shells agents started and counts the rest as ownerStarted; a rename, show or close of one of the owner\'s is refused with OWNER_ONLY.'
|
|
264
|
+
},
|
|
201
265
|
{
|
|
202
266
|
id: 'workspace.limits',
|
|
203
267
|
granted: true,
|
|
@@ -225,6 +289,11 @@ function buildGuide(options = {}) {
|
|
|
225
289
|
lines.push('');
|
|
226
290
|
lines.push('## Ground rules');
|
|
227
291
|
lines.push('- Never activate or switch the owner\'s visible tab unless they asked you to.');
|
|
292
|
+
lines.push('- A pane the owner opened is the owner\'s. `panes state` says what you have on every pane (agentAccess); when it is not enough, ask with pane.request instead of working around it.');
|
|
293
|
+
lines.push('- To show the owner one of your own panes, report it with pane status and bring that pane forward with panes active.');
|
|
294
|
+
lines.push('- A password field takes your typing and never gives a value back. Do not look for one; wait on a selector or on page text.');
|
|
295
|
+
lines.push('- A shell you start keeps running after you stop looking. Close the shells you start when the owner is done with them.');
|
|
296
|
+
lines.push('- A shell the owner started is the owner\'s: an agent cannot rename, show or close it, whatever else it has been given.');
|
|
228
297
|
lines.push('- Prefer element refs from a fresh observation over coordinates.');
|
|
229
298
|
lines.push('- A coordinate is only valid for the observation it came from; a stale one is refused.');
|
|
230
299
|
lines.push('- Use a bounded wait instead of guessing that a page is ready after a pause.');
|
package/src/attachments.js
CHANGED
|
@@ -105,14 +105,14 @@ function installAttachments(app) {
|
|
|
105
105
|
const relative = `/attachments/${day}/${encodeURIComponent(stored)}`;
|
|
106
106
|
const forwardedHost = String(req.get('X-Forwarded-Host') || '').split(',')[0].trim();
|
|
107
107
|
const forwardedProto = String(req.get('X-Forwarded-Proto') || '').split(',')[0].trim();
|
|
108
|
-
const host = forwardedHost || req.get('host') || `127.0.0.1:${process.env.PORT ||
|
|
108
|
+
const host = forwardedHost || req.get('host') || `127.0.0.1:${process.env.PORT || 11002}`;
|
|
109
109
|
const protocol = forwardedProto === 'https' ? 'https' : req.protocol;
|
|
110
110
|
res.set('Cache-Control', 'no-store');
|
|
111
111
|
res.json({
|
|
112
112
|
name: original,
|
|
113
113
|
path: target,
|
|
114
114
|
url: `${protocol}://${host}${relative}`,
|
|
115
|
-
localUrl: `http://127.0.0.1:${process.env.PORT ||
|
|
115
|
+
localUrl: `http://127.0.0.1:${process.env.PORT || 11002}${relative}`,
|
|
116
116
|
relativeUrl: relative,
|
|
117
117
|
mime: String(req.get('Content-Type') || 'application/octet-stream'),
|
|
118
118
|
bytes: data.length
|
package/src/browser-dom.js
CHANGED
|
@@ -152,12 +152,15 @@ function pageCatalog(options) {
|
|
|
152
152
|
}
|
|
153
153
|
// A catalog is a read path: it is served to view-only grants. A password
|
|
154
154
|
// field's value must never leave the page through it; the image shows
|
|
155
|
-
// bullets and /content omits form values for the same reason.
|
|
155
|
+
// bullets and /content omits form values for the same reason. The input's
|
|
156
|
+
// type is reported so the server can hold the same line for every other
|
|
157
|
+
// path a control's value takes.
|
|
156
158
|
const isPassword = el.tagName === 'INPUT' && String(el.type || '').toLowerCase() === 'password';
|
|
157
159
|
const descriptor = {
|
|
158
160
|
ref,
|
|
159
161
|
role: roleFor(el),
|
|
160
162
|
tag: el.tagName.toLowerCase(),
|
|
163
|
+
type: el.tagName === 'INPUT' ? String(el.type || '').toLowerCase() : undefined,
|
|
161
164
|
name: labelFor(el),
|
|
162
165
|
box,
|
|
163
166
|
visible,
|
|
@@ -415,7 +418,7 @@ async function resolveRef(page, ref) {
|
|
|
415
418
|
return null;
|
|
416
419
|
}
|
|
417
420
|
|
|
418
|
-
// Cheap position read for
|
|
421
|
+
// Cheap position read for a picture taken for a viewer on request. The full layout
|
|
419
422
|
// signature is only needed when deciding whether a target is stale.
|
|
420
423
|
async function scrollPosition(page) {
|
|
421
424
|
try {
|