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,134 @@
1
+ /**
2
+ * Scrollback search — find text in the terminal buffer via the xterm
3
+ * SearchAddon. A fresh addon is attached on every (re)connect because the
4
+ * terminal is recreated. The search box is a small overlay toggled from the
5
+ * feature bar; Enter finds next, Shift+Enter finds previous, Esc closes.
6
+ *
7
+ * v2 adds case-sensitive and regex toggles so the global search behaves like
8
+ * a modern editor find panel.
9
+ */
10
+ import { SearchAddon } from '/node_modules/@xterm/addon-search/lib/addon-search.mjs';
11
+
12
+ export function init(T1) {
13
+ const tb = T1.ui.toolbar();
14
+ if (!tb) return;
15
+
16
+ let addon = null;
17
+ T1.onTermReady((term) => {
18
+ try { addon = new SearchAddon(); term.loadAddon(addon); }
19
+ catch (_) { addon = null; }
20
+ });
21
+
22
+ T1.ui.addStyle(`
23
+ .t1search-box {
24
+ position: absolute;
25
+ top: 8px; right: 8px;
26
+ z-index: 250;
27
+ display: none;
28
+ gap: 4px;
29
+ align-items: center;
30
+ padding: 6px;
31
+ background: var(--ui-elevated);
32
+ border: 1px solid var(--ui-border);
33
+ border-radius: 8px;
34
+ box-shadow: 0 4px 16px rgba(0,0,0,0.35);
35
+ }
36
+ .t1search-box.open { display: flex; }
37
+ .t1search-input {
38
+ background: var(--ui-bg);
39
+ border: 1px solid var(--ui-border);
40
+ border-radius: 6px;
41
+ color: var(--ui-fg);
42
+ font-family: inherit;
43
+ font-size: 13px;
44
+ padding: 4px 8px;
45
+ width: 180px;
46
+ outline: none;
47
+ }
48
+ .t1search-input:focus { border-color: var(--ui-accent); }
49
+ .t1search-toggle {
50
+ min-width: 28px;
51
+ padding: 0 6px;
52
+ }
53
+ .t1search-toggle.active { background: var(--ui-accent); color: var(--ui-on-accent, #14171b); }
54
+ `);
55
+
56
+ const state = { caseSensitive: false, regex: false };
57
+
58
+ const box = document.createElement('div');
59
+ box.className = 't1search-box';
60
+
61
+ const input = document.createElement('input');
62
+ input.type = 'text';
63
+ input.className = 't1search-input';
64
+ input.placeholder = 'Search scrollback';
65
+ input.setAttribute('aria-label', 'Search scrollback');
66
+ box.appendChild(input);
67
+
68
+ const searchOptions = () => ({
69
+ caseSensitive: state.caseSensitive,
70
+ regex: state.regex,
71
+ incremental: false,
72
+ decorate: true
73
+ });
74
+
75
+ const next = () => {
76
+ if (addon && input.value) {
77
+ try { addon.findNext(input.value, searchOptions()); }
78
+ catch (_) {
79
+ try { addon.findNext(input.value); } catch (_) {}
80
+ }
81
+ }
82
+ };
83
+ const prev = () => {
84
+ if (addon && input.value) {
85
+ try { addon.findPrevious(input.value, searchOptions()); }
86
+ catch (_) {
87
+ try { addon.findPrevious(input.value); } catch (_) {}
88
+ }
89
+ }
90
+ };
91
+
92
+ const makeToggle = (label, title, key) => {
93
+ const b = T1.ui.makeButton(label, title, () => {
94
+ state[key] = !state[key];
95
+ b.classList.toggle('active', state[key]);
96
+ if (input.value) next();
97
+ });
98
+ b.classList.add('t1search-toggle');
99
+ return b;
100
+ };
101
+
102
+ const caseToggle = makeToggle('Aa', 'Case sensitive', 'caseSensitive');
103
+ const regexToggle = makeToggle('.*', 'Regular expression', 'regex');
104
+
105
+ box.appendChild(caseToggle);
106
+ box.appendChild(regexToggle);
107
+ box.appendChild(T1.ui.makeButton('\u25c0', 'Previous match', prev));
108
+ box.appendChild(T1.ui.makeButton('\u25b6', 'Next match', next));
109
+ box.appendChild(T1.ui.makeButton('x', 'Close search', () => box.classList.remove('open')));
110
+
111
+ input.addEventListener('keydown', (e) => {
112
+ if (e.key === 'Enter') { e.preventDefault(); if (e.shiftKey) prev(); else next(); }
113
+ else if (e.key === 'Escape') { box.classList.remove('open'); }
114
+ });
115
+
116
+ const shell = T1.ui.appShell() || document.body;
117
+ // The overlay is absolutely positioned; ensure the shell is a containing block.
118
+ if (getComputedStyle(shell).position === 'static') shell.style.position = 'relative';
119
+ shell.appendChild(box);
120
+
121
+ const toggle = T1.ui.makeButton('Search', 'Search scrollback (Ctrl+Shift+F)', () => {
122
+ const open = box.classList.toggle('open');
123
+ if (open) setTimeout(() => input.focus(), 0);
124
+ });
125
+ tb.appendChild(toggle);
126
+
127
+ // Global keyboard shortcut is handled by keyboard-shortcuts.mjs via t1:action.
128
+ window.addEventListener('t1:action', (e) => {
129
+ if ((e.detail || {}).action === 'toggle-search') {
130
+ const open = box.classList.toggle('open');
131
+ if (open) setTimeout(() => input.focus(), 0);
132
+ }
133
+ });
134
+ }
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Biometric / PIN session lock.
3
+ *
4
+ * Optional per-session lock. Uses WebAuthn / Credential Management on desktop
5
+ * where available; falls back to a simple PIN modal on phone/tablet.
6
+ * Locks the terminal with a blur overlay until authenticated.
7
+ */
8
+ const LS_PIN = 'terminalone.sessionPin';
9
+ const LS_LOCKED = 'terminalone.sessionLocked';
10
+
11
+ export function init(T1) {
12
+ T1.ui.addStyle(`
13
+ .t1-lock-overlay {
14
+ position: fixed; inset: 0;
15
+ backdrop-filter: blur(12px);
16
+ background: rgba(0,0,0,0.55);
17
+ z-index: 600;
18
+ display: none; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
19
+ }
20
+ .t1-lock-overlay.active { display: flex; }
21
+ .t1-lock-overlay h3 { color: #fff; margin: 0; font-size: 16px; }
22
+ .t1-lock-overlay input {
23
+ width: 180px; padding: 10px; font-size: 16px; text-align: center;
24
+ border-radius: 6px; border: 1px solid var(--ui-border); background: var(--ui-bg); color: var(--ui-fg);
25
+ }
26
+ .t1-lock-overlay button {
27
+ padding: 8px 18px; border-radius: 6px; border: none;
28
+ background: var(--ui-accent); color: var(--ui-on-accent, #14171b); cursor: pointer; font-weight: 600;
29
+ }
30
+ .t1-lock-overlay .hint { color: #aaa; font-size: 12px; }
31
+ `);
32
+
33
+ const overlay = document.createElement('div');
34
+ overlay.className = 't1-lock-overlay';
35
+ overlay.setAttribute('role', 'dialog');
36
+ overlay.setAttribute('aria-modal', 'true');
37
+ overlay.setAttribute('aria-label', 'Unlock session');
38
+ overlay.innerHTML = `
39
+ <h3>Session locked</h3>
40
+ <input type="password" maxlength="8" inputmode="numeric" placeholder="PIN" aria-label="PIN" />
41
+ <button type="button">Unlock</button>
42
+ <span class="hint">Set a PIN in settings to protect this session.</span>
43
+ `;
44
+ document.body.appendChild(overlay);
45
+
46
+ const input = overlay.querySelector('input');
47
+ const btn = overlay.querySelector('button');
48
+
49
+ function setPin(pin) { T1.storage.set(LS_PIN, pin); }
50
+ function getPin() { return T1.storage.get(LS_PIN, ''); }
51
+ function lock() { T1.storage.set(LS_LOCKED, '1'); overlay.classList.add('active'); }
52
+ function unlock() {
53
+ const stored = getPin();
54
+ if (stored && input.value !== stored) {
55
+ T1.toast('Wrong PIN', 'error');
56
+ return;
57
+ }
58
+ T1.storage.del(LS_LOCKED);
59
+ overlay.classList.remove('active');
60
+ input.value = '';
61
+ T1.toast('Unlocked');
62
+ }
63
+
64
+ btn.addEventListener('click', unlock);
65
+ input.addEventListener('keydown', (e) => { if (e.key === 'Enter') unlock(); });
66
+
67
+ // NOTE: WebAuthn credential creation/verification is intentionally not
68
+ // wired here — it requires a secure context (HTTPS or localhost) plus a
69
+ // registered credential, neither of which a generic browser terminal can
70
+ // assume. This feature degrades to a local PIN. The PIN is stored in
71
+ // same-origin localStorage (cleartext) — acceptable threat model for a
72
+ // single-user local terminal; do NOT reuse this pattern for multi-user or
73
+ // remote-deployed apps.
74
+ function tryWebAuthn() { return Promise.resolve(false); }
75
+
76
+ // Auto-lock if previously locked.
77
+ if (T1.storage.get(LS_LOCKED, '0') === '1') lock();
78
+
79
+ // Toolbar button.
80
+ const lockBtn = T1.ui.makeButton('Lock', 'Lock this session', () => {
81
+ if (!getPin()) {
82
+ let pin = prompt('Create a 4-8 digit PIN');
83
+ if (!pin) return;
84
+ pin = pin.trim();
85
+ if (!/^\d{4,8}$/.test(pin)) {
86
+ T1.toast('PIN must be 4-8 digits', 'warn');
87
+ return;
88
+ }
89
+ setPin(pin);
90
+ }
91
+ lock();
92
+ });
93
+ T1.ui.toolbar().appendChild(lockBtn);
94
+
95
+ window.__terminalOneSessionLock = { lock, unlock, setPin, getPin, overlay, tryWebAuthn };
96
+ }
@@ -0,0 +1,251 @@
1
+ /**
2
+ * Session row: one chip per shell in the terminal header.
3
+ *
4
+ * The list of shells belongs to the server. public/index.html keeps a copy of
5
+ * it and announces changes as `t1:sessions-change`; this module only draws it.
6
+ *
7
+ * One button per live session, named as the server names it, with the current
8
+ * one marked; a close control on each; and the + that starts another.
9
+ * Activating a chip switches to that shell and can never start a new one.
10
+ * Closing asks first, in the app's own confirmation (workspace.mjs). The
11
+ * chips are plain buttons with a pressed state, so they are reachable by
12
+ * keyboard; Left and Right move between them.
13
+ *
14
+ * It keeps no list of its own. An earlier version remembered session names in
15
+ * localStorage, under two different keys per session, so the row showed chips
16
+ * for shells that had ended and lost the rest after five.
17
+ */
18
+
19
+ const ICONS = {
20
+ close: 'M6 6l12 12M18 6L6 18',
21
+ plus: 'M12 5v14M5 12h14'
22
+ };
23
+ const icon = (name) => '<svg viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round"><path d="' + ICONS[name] + '"/></svg>';
24
+
25
+ export function init(T1) {
26
+ const header = document.querySelector('.terminal-header');
27
+ if (!header) return;
28
+
29
+ T1.ui.addStyle(`
30
+ .t1session-tabs {
31
+ display: flex;
32
+ align-items: center;
33
+ gap: 6px;
34
+ margin-left: 4px;
35
+ flex: 0 1 auto;
36
+ min-width: 0;
37
+ }
38
+ .t1session-strip {
39
+ display: flex;
40
+ align-items: center;
41
+ gap: 4px;
42
+ flex: 0 1 auto;
43
+ min-width: 0;
44
+ overflow-x: auto;
45
+ overflow-y: hidden;
46
+ scrollbar-width: none;
47
+ scroll-behavior: smooth;
48
+ /* Keep the current chip clear of the fade when it is scrolled into view. */
49
+ scroll-padding-inline: 20px;
50
+ }
51
+ .t1session-strip::-webkit-scrollbar { display: none; }
52
+ .t1session-chip {
53
+ display: inline-flex;
54
+ align-items: center;
55
+ flex: 0 0 auto;
56
+ min-height: 44px;
57
+ border: 1px solid transparent;
58
+ border-radius: 4px;
59
+ color: var(--ui-muted);
60
+ transition: background-color 200ms, border-color 200ms, color 200ms;
61
+ }
62
+ .t1session-chip.active { color: var(--ui-fg); border-color: var(--ui-accent); }
63
+ .t1session-tab {
64
+ display: inline-flex;
65
+ align-items: center;
66
+ min-width: 0;
67
+ max-width: 180px;
68
+ padding: 3px 8px;
69
+ border: 0;
70
+ background: transparent;
71
+ color: inherit;
72
+ font: inherit;
73
+ font-size: 11px;
74
+ white-space: nowrap;
75
+ overflow: hidden;
76
+ text-overflow: ellipsis;
77
+ cursor: pointer;
78
+ }
79
+ .t1session-close {
80
+ display: inline-flex;
81
+ align-items: center;
82
+ justify-content: center;
83
+ flex: 0 0 auto;
84
+ width: 28px;
85
+ min-height: 44px;
86
+ padding: 0;
87
+ border: 0;
88
+ background: transparent;
89
+ color: var(--ui-muted);
90
+ cursor: pointer;
91
+ }
92
+ .t1session-close svg { width: 14px; height: 14px; }
93
+ .t1session-close:hover { color: var(--ui-fg); }
94
+ .t1session-new {
95
+ display: inline-flex;
96
+ align-items: center;
97
+ justify-content: center;
98
+ flex: 0 0 auto;
99
+ min-width: 44px;
100
+ min-height: 44px;
101
+ padding: 0;
102
+ line-height: 1;
103
+ }
104
+ .t1session-new svg { width: 18px; height: 18px; }
105
+ @media (pointer: coarse) {
106
+ .t1session-close { width: 44px; }
107
+ }
108
+ /* Where the row holds more chips than it can show, that edge fades, so a
109
+ chip cut at the edge reads as "more this way" rather than as a fault. */
110
+ .t1session-strip.more-left {
111
+ -webkit-mask-image: linear-gradient(to right, transparent, #000 20px);
112
+ mask-image: linear-gradient(to right, transparent, #000 20px);
113
+ }
114
+ .t1session-strip.more-right {
115
+ -webkit-mask-image: linear-gradient(to left, transparent, #000 20px);
116
+ mask-image: linear-gradient(to left, transparent, #000 20px);
117
+ }
118
+ .t1session-strip.more-left.more-right {
119
+ -webkit-mask-image: linear-gradient(to right, transparent, #000 20px), linear-gradient(to left, transparent, #000 20px);
120
+ mask-image: linear-gradient(to right, transparent, #000 20px), linear-gradient(to left, transparent, #000 20px);
121
+ -webkit-mask-composite: source-in;
122
+ mask-composite: intersect;
123
+ }
124
+ @media (prefers-reduced-motion: reduce) {
125
+ .t1session-strip { scroll-behavior: auto; }
126
+ .t1session-chip { transition: none; }
127
+ }
128
+ `);
129
+
130
+ const tabsEl = document.createElement('div');
131
+ tabsEl.className = 't1session-tabs';
132
+ tabsEl.id = 't1session-tabs';
133
+ const strip = document.createElement('div');
134
+ strip.className = 't1session-strip';
135
+ strip.setAttribute('role', 'group');
136
+ strip.setAttribute('aria-label', 'Shell sessions');
137
+ const plus = document.createElement('button');
138
+ plus.type = 'button';
139
+ plus.className = 't1session-new';
140
+ plus.id = 't1session-new';
141
+ plus.setAttribute('aria-label', 'New terminal session');
142
+ plus.title = 'New terminal session';
143
+ plus.innerHTML = icon('plus');
144
+ // At the session limit this opens the Sessions list instead of starting one.
145
+ plus.addEventListener('click', () => window.__terminalOne?.requestNewSession?.());
146
+ tabsEl.append(strip, plus);
147
+ // The row sits between the title and the session pill.
148
+ const title = header.querySelector('.terminal-title');
149
+ title?.parentNode?.insertBefore(tabsEl, title.nextSibling);
150
+
151
+ function makeChip(session) {
152
+ const chip = document.createElement('div');
153
+ chip.className = 't1session-chip';
154
+ chip.dataset.sessionId = session.id;
155
+ chip.setAttribute('role', 'presentation');
156
+ const tab = document.createElement('button');
157
+ tab.type = 'button';
158
+ tab.className = 't1session-tab';
159
+ tab.setAttribute('aria-pressed', 'false');
160
+ tab.addEventListener('click', () => window.__terminalOne?.switchSession?.(session.id));
161
+ const close = document.createElement('button');
162
+ close.type = 'button';
163
+ close.className = 't1session-close';
164
+ close.innerHTML = icon('close');
165
+ close.addEventListener('click', () => window.__terminalOne?.requestClose?.(session.id));
166
+ chip.append(tab, close);
167
+ return chip;
168
+ }
169
+
170
+ let signature = '';
171
+ function render() {
172
+ const api = window.__terminalOne;
173
+ if (!api) return;
174
+ const sessions = api.sessions?.() || [];
175
+ const currentId = api.sessionView?.().current?.id || '';
176
+ const next = sessions
177
+ .map((session) => `${session.id}\u0000${session.name}\u0000${session.id === currentId ? 1 : 0}`)
178
+ .join('\u0001');
179
+ if (next === signature) return;
180
+ signature = next;
181
+ const kept = new Map([...strip.querySelectorAll('.t1session-chip')].map((chip) => [chip.dataset.sessionId, chip]));
182
+ const hasCurrent = sessions.some((session) => session.id === currentId);
183
+ sessions.forEach((session, index) => {
184
+ let chip = kept.get(session.id);
185
+ if (!chip) {
186
+ chip = makeChip(session);
187
+ } else {
188
+ kept.delete(session.id);
189
+ }
190
+ const tab = chip.firstElementChild;
191
+ const close = chip.lastElementChild;
192
+ const current = session.id === currentId;
193
+ chip.classList.toggle('active', current);
194
+ tab.classList.toggle('active', current);
195
+ tab.setAttribute('aria-pressed', String(current));
196
+ // One stop in the Tab order: the current chip, else the first.
197
+ tab.tabIndex = current || (!hasCurrent && index === 0) ? 0 : -1;
198
+ tab.textContent = session.name;
199
+ // The tooltip says what a click does: nothing about a chip is left to
200
+ // the shape of the pointer alone.
201
+ const where = session.cwd ? ` · ${session.cwd}` : '';
202
+ tab.title = current ? `${session.name}${where} · current shell` : `Switch to ${session.name}${where}`;
203
+ close.setAttribute('aria-label', `Close ${session.name}`);
204
+ close.title = `Close ${session.name}`;
205
+ strip.append(chip);
206
+ });
207
+ for (const stale of kept.values()) stale.remove();
208
+ keepCurrentVisible();
209
+ showEdges();
210
+ }
211
+
212
+ // The person must always see which shell is current, including when the row
213
+ // gets narrower (a dock or a browser pane opens) without the list changing.
214
+ function keepCurrentVisible() {
215
+ const current = strip.querySelector('.t1session-chip.active');
216
+ if (current && strip.scrollWidth > strip.clientWidth + 1) {
217
+ current.scrollIntoView({ block: 'nearest', inline: 'nearest' });
218
+ }
219
+ }
220
+
221
+ // Fade the edges that hide chips (see the style above).
222
+ function showEdges() {
223
+ strip.classList.toggle('more-left', strip.scrollLeft > 1);
224
+ strip.classList.toggle('more-right', strip.scrollLeft + strip.clientWidth < strip.scrollWidth - 1);
225
+ }
226
+ const rowSettled = () => requestAnimationFrame(() => { keepCurrentVisible(); showEdges(); });
227
+ strip.addEventListener('scroll', showEdges, { passive: true });
228
+ if (typeof ResizeObserver === 'function') new ResizeObserver(rowSettled).observe(strip);
229
+ window.addEventListener('resize', rowSettled);
230
+ // A dock closing or opening can leave the row wide for a single layout and
231
+ // narrow again in the same frame, which resets its scroll place without any
232
+ // change of size for a resize observer to report. Watch the docks instead.
233
+ new MutationObserver(rowSettled)
234
+ .observe(document.body, { attributes: true, attributeFilter: ['open'], subtree: true });
235
+
236
+ strip.addEventListener('keydown', (event) => {
237
+ if (!['ArrowLeft', 'ArrowRight', 'Home', 'End'].includes(event.key)) return;
238
+ const tabs = [...strip.querySelectorAll('.t1session-tab')];
239
+ const at = tabs.indexOf(document.activeElement);
240
+ if (at < 0 || !tabs.length) return;
241
+ event.preventDefault();
242
+ const next = event.key === 'Home' ? 0
243
+ : event.key === 'End' ? tabs.length - 1
244
+ : (at + (event.key === 'ArrowRight' ? 1 : -1) + tabs.length) % tabs.length;
245
+ tabs[next].focus();
246
+ });
247
+
248
+ window.addEventListener('t1:sessions-change', render);
249
+ window.addEventListener('t1:session-ready', render);
250
+ render();
251
+ }
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Cross-device settings export/import cloud hook (local-first).
3
+ *
4
+ * Extends the settings import/export with a sync token / QR code for easy
5
+ * transfer. Settings are exported as JSON; import validates schema version.
6
+ */
7
+ const SCHEMA_VERSION = 2;
8
+ const LS_SYNC_TOKEN = 'terminalone.syncToken';
9
+
10
+ export function init(T1) {
11
+ T1.ui.addStyle(`
12
+ .t1-sync-token { font-family: ui-monospace, SFMono-Regular, monospace; font-size: 13px; word-break: break-all; }
13
+ .t1-qr-host { display: inline-block; padding: 6px; background: #fff; border-radius: 4px; }
14
+ `);
15
+
16
+ function collectSettings() {
17
+ return {
18
+ schemaVersion: SCHEMA_VERSION,
19
+ exportedAt: new Date().toISOString(),
20
+ theme: T1.storage.get('terminalone.theme', 'tokyo-night'),
21
+ style: T1.storage.get('terminalone.style', 'default'),
22
+ cursorStyle: T1.storage.get('terminalone.cursorStyle', 'block'),
23
+ cursorBlink: T1.storage.get('terminalone.cursorBlink', 'true') === 'true',
24
+ bell: T1.storage.get('terminalone.bell', 'false') === 'true',
25
+ scrollback: parseInt(T1.storage.get('terminalone.scrollback', '10000'), 10),
26
+ fontSize: parseInt(T1.storage.get('terminalone.fontSize', '14'), 10)
27
+ };
28
+ }
29
+
30
+ function validate(data) {
31
+ if (!data || typeof data !== 'object') return { ok: false, reason: 'not an object' };
32
+ if (typeof data.schemaVersion !== 'number') return { ok: false, reason: 'missing schemaVersion' };
33
+ if (data.schemaVersion > SCHEMA_VERSION) return { ok: false, reason: `schemaVersion ${data.schemaVersion} > supported ${SCHEMA_VERSION}` };
34
+ if (data.theme && typeof data.theme !== 'string') return { ok: false, reason: 'invalid theme' };
35
+ return { ok: true };
36
+ }
37
+
38
+ function importSettings(data) {
39
+ const v = validate(data);
40
+ if (!v.ok) throw new Error(v.reason);
41
+ if (data.theme) T1.storage.set('terminalone.theme', data.theme);
42
+ if (data.style) T1.storage.set('terminalone.style', data.style);
43
+ if (data.cursorStyle) T1.storage.set('terminalone.cursorStyle', data.cursorStyle);
44
+ if (typeof data.cursorBlink === 'boolean') T1.storage.set('terminalone.cursorBlink', String(data.cursorBlink));
45
+ if (typeof data.bell === 'boolean') T1.storage.set('terminalone.bell', String(data.bell));
46
+ if (data.scrollback) T1.storage.set('terminalone.scrollback', String(data.scrollback));
47
+ if (data.fontSize) T1.storage.set('terminalone.fontSize', String(data.fontSize));
48
+ return true;
49
+ }
50
+
51
+ function generateToken() {
52
+ const chars = 'ABCDEFGHJKMNPQRSTUVWXYZ23456789';
53
+ let token = '';
54
+ for (let i = 0; i < 12; i++) token += chars.charAt(Math.floor(Math.random() * chars.length));
55
+ T1.storage.set(LS_SYNC_TOKEN, token);
56
+ return token;
57
+ }
58
+
59
+ function getToken() { return T1.storage.get(LS_SYNC_TOKEN, '') || generateToken(); }
60
+
61
+ // Toolbar button: export with token.
62
+ const exportBtn = T1.ui.makeButton('Sync', 'Export settings with sync token', () => {
63
+ const payload = collectSettings();
64
+ payload.syncToken = getToken();
65
+ const blob = new Blob([JSON.stringify(payload, null, 2)], { type: 'application/json' });
66
+ const a = document.createElement('a');
67
+ a.href = URL.createObjectURL(blob);
68
+ a.download = `terminalone-sync-${payload.syncToken}.json`;
69
+ a.click();
70
+ URL.revokeObjectURL(a.href);
71
+ T1.toast(`Settings exported (token ${payload.syncToken})`);
72
+ });
73
+ T1.ui.toolbar().appendChild(exportBtn);
74
+
75
+ // Expose for tests.
76
+ window.__terminalOneSettingsSync = { collectSettings, importSettings, validate, generateToken, getToken, SCHEMA_VERSION };
77
+ }
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Keyboard shortcut helper overlay (tablet/desktop).
3
+ *
4
+ * Pressing ? or Cmd/Ctrl+? opens an overlay listing available shortcuts for
5
+ * the current device.
6
+ */
7
+ export function init(T1) {
8
+ T1.ui.addStyle(`
9
+ .t1-shortcut-overlay {
10
+ position: fixed; inset: 0;
11
+ background: rgba(0,0,0,0.5);
12
+ z-index: 400;
13
+ display: none; align-items: center; justify-content: center;
14
+ }
15
+ .t1-shortcut-overlay.open { display: flex; }
16
+ .t1-shortcut-panel {
17
+ background: var(--ui-elevated);
18
+ border: 1px solid var(--ui-border);
19
+ border-radius: 10px;
20
+ width: min(520px, 90vw);
21
+ max-height: 70vh;
22
+ overflow: hidden;
23
+ display: flex; flex-direction: column;
24
+ }
25
+ .t1-shortcut-panel header { padding: 14px 18px; border-bottom: 1px solid var(--ui-border); display: flex; justify-content: space-between; align-items: center; }
26
+ .t1-shortcut-panel h3 { margin: 0; font-size: 15px; color: var(--ui-fg); }
27
+ .t1-shortcut-panel .close { background: transparent; border: none; color: var(--ui-muted); font-size: 18px; }
28
+ .t1-shortcut-list { overflow-y: auto; padding: 10px 18px; }
29
+ .t1-shortcut-row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--ui-border); color: var(--ui-fg); font-size: 13px; }
30
+ .t1-shortcut-row kbd { background: var(--ui-bg); padding: 2px 6px; border-radius: 4px; border: 1px solid var(--ui-border); font-family: inherit; }
31
+ `);
32
+
33
+ const overlay = document.createElement('div');
34
+ overlay.className = 't1-shortcut-overlay';
35
+ overlay.setAttribute('role', 'dialog');
36
+ overlay.setAttribute('aria-label', 'Keyboard shortcuts');
37
+ overlay.innerHTML = `
38
+ <div class="t1-shortcut-panel">
39
+ <header><h3>Keyboard Shortcuts</h3><button type="button" class="close" aria-label="Close shortcuts">×</button></header>
40
+ <div class="t1-shortcut-list"></div>
41
+ </div>
42
+ `;
43
+ document.body.appendChild(overlay);
44
+
45
+ const list = overlay.querySelector('.t1-shortcut-list');
46
+ overlay.querySelector('.close').addEventListener('click', close);
47
+ overlay.addEventListener('click', (e) => { if (e.target === overlay) close(); });
48
+
49
+ const isMac = /Mac|iPod|iPhone|iPad/.test(navigator.platform || '');
50
+ const COMMON = [
51
+ { keys: isMac ? 'Cmd + Shift + P' : 'Ctrl + Shift + P', desc: 'Open command palette' },
52
+ { keys: isMac ? 'Cmd + Shift + F' : 'Ctrl + Shift + F', desc: 'Search scrollback' },
53
+ { keys: isMac ? 'Cmd + K' : 'Ctrl + Shift + K', desc: 'Clear screen' },
54
+ { keys: isMac ? 'Cmd + B' : 'Ctrl + Shift + B', desc: 'Toggle snippets' },
55
+ { keys: 'Cmd/Ctrl + = / -', desc: 'Increase / decrease font size' },
56
+ { keys: 'Ctrl + L', desc: 'Clear screen from the shell' },
57
+ { keys: 'Ctrl + Z / Ctrl + Y', desc: 'Recall previous / next command' }
58
+ ];
59
+ const TOUCH = [
60
+ { keys: 'Two-finger swipe', desc: 'Switch session tabs' },
61
+ { keys: 'Two-finger tap', desc: 'Open terminal context menu' }
62
+ ];
63
+
64
+ function open() {
65
+ const device = T1.device;
66
+ list.innerHTML = '';
67
+ const rows = [...COMMON, ...(device === 'desktop' ? [] : TOUCH)];
68
+ for (const { keys, desc } of rows) {
69
+ const row = document.createElement('div');
70
+ row.className = 't1-shortcut-row';
71
+ row.innerHTML = `<span>${desc}</span><kbd>${keys}</kbd>`;
72
+ list.appendChild(row);
73
+ }
74
+ overlay.classList.add('open');
75
+ }
76
+ function close() { overlay.classList.remove('open'); }
77
+
78
+ document.addEventListener('keydown', (e) => {
79
+ if (e.key === '?' && (e.ctrlKey || e.metaKey)) { e.preventDefault(); open(); }
80
+ else if (e.key === '?' && !e.ctrlKey && !e.metaKey && !e.altKey && !e.shiftKey) { e.preventDefault(); open(); }
81
+ else if (e.key === 'Escape') { close(); }
82
+ });
83
+
84
+ window.__terminalOneShortcutHelp = { open, close, overlay };
85
+ }