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,22 @@
1
+ // Split terminal input without cutting a UTF-16 surrogate pair in half.
2
+ // A split pair becomes U+FFFD in the PTY, which silently corrupts emoji and
3
+ // supplementary-plane characters in large pastes.
4
+ export function chunkInput(payload, size = 24000) {
5
+ const text = String(payload || '');
6
+ const limit = Math.max(2, Math.floor(Number(size) || 24000));
7
+ const chunks = [];
8
+ let offset = 0;
9
+ while (offset < text.length) {
10
+ let end = Math.min(offset + limit, text.length);
11
+ if (end < text.length) {
12
+ const last = text.charCodeAt(end - 1);
13
+ // High surrogate at the boundary: leave it for the next chunk so the
14
+ // low surrogate travels with it.
15
+ if (last >= 0xD800 && last <= 0xDBFF) end -= 1;
16
+ if (end <= offset) end = Math.min(offset + limit, text.length);
17
+ }
18
+ chunks.push(text.slice(offset, end));
19
+ offset = end;
20
+ }
21
+ return chunks;
22
+ }
@@ -0,0 +1,218 @@
1
+ /**
2
+ * InputGuard — eliminate iOS/iPadOS dictate-to-text and IME echo duplication
3
+ * while keeping normal typing perfectly crisp.
4
+ *
5
+ * v2 design (rolling buffer):
6
+ * - Single characters are sent immediately and APPEND to a rolling buffer of
7
+ * recently-sent text. (v1 reset the baseline on single chars — this was the
8
+ * dictation-doubling bug: a single-char event between the last partial and
9
+ * the compositionend finalization zeroed the baseline, so the full phrase
10
+ * was re-sent in its entirety.)
11
+ * - Multi-character strings are compared against the FULL rolling buffer, not
12
+ * just the last event. This catches all dictation patterns:
13
+ * • Cumulative partials ("a" → "ab" → "abc") — suffix delta sent.
14
+ * • Finalization re-fire of the complete phrase — suppressed (already in
15
+ * buffer).
16
+ * • Word-by-word partials followed by full-phrase finalization — the
17
+ * accumulated buffer contains the full phrase, so finalization is
18
+ * suppressed.
19
+ * - Known keyboard and paste events always pass through, regardless of size.
20
+ * Unclassified short bursts are preserved unless they repeat the last
21
+ * multi-character dictation partial. Length alone cannot identify dictation.
22
+ * - Control sequences reset the buffer and are sent immediately.
23
+ * - The rolling buffer is capped (default 256 chars) and entries expire after
24
+ * `bufferDedupeMs` (default 3000ms) so legitimate paste/type of previously
25
+ * sent text is not suppressed after a few seconds.
26
+ */
27
+ export class InputGuard {
28
+ constructor({ send, identicalDedupeMs = 500, bufferSize = 256, bufferDedupeMs = 3000 }) {
29
+ this._send = send;
30
+ this.identicalDedupeMs = identicalDedupeMs;
31
+ this._bufferSize = bufferSize;
32
+ this._bufferDedupeMs = bufferDedupeMs;
33
+ this._sentBuffer = '';
34
+ this._bufferTime = 0;
35
+ this._lastEvent = { data: '', time: 0 };
36
+ this._lastPartial = '';
37
+ this._now = () => (typeof performance !== 'undefined' ? performance.now() : Date.now());
38
+ }
39
+
40
+ onData(data, { source = 'unknown' } = {}) {
41
+ if (!data || data.length === 0) return;
42
+
43
+ const now = this._now();
44
+
45
+ const printable = [...data].every((c) => {
46
+ const code = c.codePointAt(0);
47
+ return code >= 0x20 && (code < 0x7f || code > 0x9f);
48
+ });
49
+
50
+ // Non-printable (control sequences, Enter, arrows, etc.) → send + reset.
51
+ if (!printable) {
52
+ this._sendRaw(data);
53
+ this._resetBuffer();
54
+ return;
55
+ }
56
+
57
+ // A real keyboard/paste event supplies new text, even if it looks like a
58
+ // previous phrase or a cumulative partial. Do not compare it with history.
59
+ if (source === 'keyboard' || source === 'paste') {
60
+ this.send(data);
61
+ return;
62
+ }
63
+
64
+ if (this._sentBuffer && now - this._bufferTime >= this._bufferDedupeMs) {
65
+ this._resetBuffer();
66
+ }
67
+
68
+ // Only unclassified/composition text needs the legacy echo protection.
69
+ if (data.length > 1 && data === this._lastEvent.data && now - this._lastEvent.time < this.identicalDedupeMs) {
70
+ return;
71
+ }
72
+ this._lastEvent = { data, time: now };
73
+
74
+ // Single character → always send immediately, APPEND to buffer (do NOT
75
+ // reset — this is the v1 bug fix).
76
+ if (data.length === 1) {
77
+ this._sendRaw(data);
78
+ this._appendBuffer(data);
79
+ this._bufferTime = now;
80
+ return;
81
+ }
82
+
83
+ // Multi-char: compare against the full rolling buffer so that dictation
84
+ // finalization (compositionend re-firing the complete phrase) is suppressed
85
+ // even when single chars or word-level partials were sent in between.
86
+
87
+ const bufferFresh = this._sentBuffer && now - this._bufferTime < this._bufferDedupeMs;
88
+
89
+ // Remember the last multi-character partial across intervening single
90
+ // characters, so "ls", " ", "ls" finalizes once just like longer phrases.
91
+ const repeatsPartial = data === this._lastPartial;
92
+ this._lastPartial = data;
93
+ const isTypingBurst = source !== 'composition' && data.length <= 3;
94
+
95
+ // Case 1: data is entirely contained in recent buffer → already sent.
96
+ if (bufferFresh && (!isTypingBurst || repeatsPartial) && this._sentBuffer.includes(data)) {
97
+ return;
98
+ }
99
+
100
+ // Case 2: buffer is a prefix of data → send only the suffix (cumulative
101
+ // partial extension: "hello" → "hello world").
102
+ if (bufferFresh && data.startsWith(this._sentBuffer)) {
103
+ const delta = data.slice(this._sentBuffer.length);
104
+ this._sendRaw(delta);
105
+ this._sentBuffer = data.slice(-this._bufferSize);
106
+ this._bufferTime = now;
107
+ return;
108
+ }
109
+
110
+ // Case 3: data overlaps the tail of the buffer → send only the new suffix
111
+ // (suffix revision: "hello world" → "world peace"). Typing bursts are
112
+ // exempt: subtracting an overlap would drop keys the user just pressed.
113
+ if (bufferFresh && !isTypingBurst) {
114
+ const overlap = this._longestTailOverlap(this._sentBuffer, data);
115
+ if (overlap > 0) {
116
+ const delta = data.slice(overlap);
117
+ if (delta.length === 0) return; // fully overlapped → already sent
118
+ this._sendRaw(delta);
119
+ this._appendBuffer(delta);
120
+ this._bufferTime = now;
121
+ return;
122
+ }
123
+ }
124
+
125
+ // Case 4: No overlap with recent history → send full data.
126
+ this._sendRaw(data);
127
+ this._appendBuffer(data);
128
+ this._bufferTime = now;
129
+ }
130
+
131
+ /** Raw send for deliberate key-bar input (Enter, arrows, etc.). Resets the
132
+ * buffer so the next dictation starts clean. */
133
+ send(data) {
134
+ this._sendRaw(data);
135
+ this._resetBuffer();
136
+ }
137
+
138
+ beginComposition() {
139
+ this._resetBuffer();
140
+ }
141
+
142
+ dispose() {
143
+ /* no timers to clear */
144
+ }
145
+
146
+ _appendBuffer(text) {
147
+ this._sentBuffer = (this._sentBuffer + text).slice(-this._bufferSize);
148
+ }
149
+
150
+ _resetBuffer() {
151
+ this._sentBuffer = '';
152
+ this._bufferTime = 0;
153
+ this._lastEvent = { data: '', time: 0 };
154
+ this._lastPartial = '';
155
+ }
156
+
157
+ /** Longest suffix of `buffer` that is also a prefix of `data`. */
158
+ _longestTailOverlap(buffer, data) {
159
+ const max = Math.min(buffer.length, data.length);
160
+ for (let len = max; len > 0; len -= 1) {
161
+ if (buffer.endsWith(data.slice(0, len))) {
162
+ return len;
163
+ }
164
+ }
165
+ return 0;
166
+ }
167
+
168
+ _sendRaw(data) {
169
+ if (data) this._send(data);
170
+ }
171
+ }
172
+
173
+ /** Preserve the browser's input source while xterm emits onData. Capture runs
174
+ * before xterm's listeners; eventPhase becomes zero when dispatch ends, so an
175
+ * asynchronous composition finalization never inherits a stale keyboard flag.
176
+ *
177
+ * `ignoreGenerated` is asked about each piece of input that has no key, paste
178
+ * or composition behind it. The terminal's answers to questions it was asked
179
+ * arrive that way. While a resumed shell's earlier output is being replayed,
180
+ * those questions were asked long ago, and an answer would be typed into a
181
+ * shell that is waiting for a command: the page passes a function that is true
182
+ * for the length of a replay. */
183
+ export function bindInputGuard(term, guard, { ignoreGenerated } = {}) {
184
+ let inputEvent = null;
185
+ let composing = false;
186
+ const capture = (event) => { inputEvent = event; };
187
+ const start = () => { composing = true; guard.beginComposition(); };
188
+ const end = () => { composing = false; };
189
+ const element = term.element;
190
+ for (const type of ['keydown', 'keypress', 'input', 'paste']) {
191
+ element.addEventListener(type, capture, true);
192
+ }
193
+ element.addEventListener('compositionstart', start, true);
194
+ element.addEventListener('compositionend', end, true);
195
+ const subscription = term.onData((data) => {
196
+ let source = 'unknown';
197
+ if (composing) source = 'composition';
198
+ if (inputEvent && inputEvent.eventPhase !== 0) {
199
+ if (composing || inputEvent.isComposing || inputEvent.keyCode === 229 || /composition|dictation/i.test(inputEvent.inputType || '')) {
200
+ source = 'composition';
201
+ } else {
202
+ source = inputEvent.type === 'paste' ? 'paste' : 'keyboard';
203
+ }
204
+ }
205
+ if (source === 'unknown' && ignoreGenerated && ignoreGenerated()) return;
206
+ guard.onData(data, { source });
207
+ });
208
+ return () => {
209
+ subscription.dispose();
210
+ for (const type of ['keydown', 'keypress', 'input', 'paste']) {
211
+ element.removeEventListener(type, capture, true);
212
+ }
213
+ element.removeEventListener('compositionstart', start, true);
214
+ element.removeEventListener('compositionend', end, true);
215
+ inputEvent = null;
216
+ guard.dispose();
217
+ };
218
+ }
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "Townmouse",
3
+ "short_name": "Townmouse",
4
+ "description": "Townmouse is a terminal and agent browser workspace. Its embedded TerminalOne engine supplies the PTY.",
5
+ "icons": [
6
+ {
7
+ "src": "icon-192.png",
8
+ "sizes": "192x192",
9
+ "type": "image/png",
10
+ "purpose": "any"
11
+ },
12
+ {
13
+ "src": "icon-512.png",
14
+ "sizes": "512x512",
15
+ "type": "image/png",
16
+ "purpose": "any"
17
+ },
18
+ {
19
+ "src": "icon-512-maskable.png",
20
+ "sizes": "512x512",
21
+ "type": "image/png",
22
+ "purpose": "maskable"
23
+ }
24
+ ],
25
+ "theme_color": "#eef1f5",
26
+ "background_color": "#eef1f5",
27
+ "start_url": "/",
28
+ "display": "standalone",
29
+ "orientation": "any",
30
+ "shortcuts": [
31
+ {
32
+ "name": "New tab",
33
+ "short_name": "New",
34
+ "description": "Open a new terminal session",
35
+ "url": "/?action=new-tab",
36
+ "icons": [
37
+ {
38
+ "src": "/icon-192.png",
39
+ "sizes": "192x192"
40
+ }
41
+ ]
42
+ },
43
+ {
44
+ "name": "Focus mode",
45
+ "short_name": "Focus",
46
+ "description": "Open in full-screen focus mode",
47
+ "url": "/?action=focus",
48
+ "icons": [
49
+ {
50
+ "src": "/icon-192.png",
51
+ "sizes": "192x192"
52
+ }
53
+ ]
54
+ }
55
+ ]
56
+ }