tabherd 0.0.1 → 0.6.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 (68) hide show
  1. package/CHANGELOG.md +166 -0
  2. package/LICENSE +674 -0
  3. package/README.md +538 -2
  4. package/launcher/npm.js +9 -0
  5. package/lib/agents.js +324 -0
  6. package/lib/codex-client.js +306 -0
  7. package/lib/codex-rollout.js +251 -0
  8. package/lib/codex.js +424 -0
  9. package/lib/comfy.js +479 -0
  10. package/lib/completed.js +55 -0
  11. package/lib/copilot.js +359 -0
  12. package/lib/cursor.js +516 -0
  13. package/lib/dismissed.js +30 -0
  14. package/lib/filters.js +120 -0
  15. package/lib/groups.js +144 -0
  16. package/lib/history.js +253 -0
  17. package/lib/llamacpp.js +159 -0
  18. package/lib/lmstudio.js +134 -0
  19. package/lib/localai.js +291 -0
  20. package/lib/memory.js +55 -0
  21. package/lib/ollama.js +124 -0
  22. package/lib/open-dashboard.js +39 -0
  23. package/lib/opencode.js +371 -0
  24. package/lib/repos.js +81 -0
  25. package/lib/saved.js +33 -0
  26. package/lib/secrets.js +196 -0
  27. package/lib/session-id.js +9 -0
  28. package/lib/settings.js +231 -0
  29. package/lib/store.js +44 -0
  30. package/lib/terminals/index.js +62 -0
  31. package/lib/terminals/kitty.js +126 -0
  32. package/lib/terminals/linux.js +310 -0
  33. package/lib/terminals/macos.js +468 -0
  34. package/lib/terminals/tmux.js +89 -0
  35. package/lib/terminals/unix-driver.js +172 -0
  36. package/lib/terminals/unix.js +204 -0
  37. package/lib/terminals/unsupported.js +22 -0
  38. package/lib/terminals/wezterm.js +103 -0
  39. package/lib/terminals/windows-close.ps1 +125 -0
  40. package/lib/terminals/windows-focus.ps1 +235 -0
  41. package/lib/terminals/windows-pick-folder.ps1 +57 -0
  42. package/lib/terminals/windows-titles.js +124 -0
  43. package/lib/terminals/windows-titles.ps1 +95 -0
  44. package/lib/terminals/windows.js +166 -0
  45. package/lib/ticket-refs.js +184 -0
  46. package/lib/tickets.js +437 -0
  47. package/lib/todos.js +166 -0
  48. package/lib/trackers.js +541 -0
  49. package/lib/transcript.js +314 -0
  50. package/lib/updates.js +186 -0
  51. package/package.json +35 -7
  52. package/public/app.js +4077 -0
  53. package/public/favicon.svg +1 -0
  54. package/public/icons/tabherd-128.png +0 -0
  55. package/public/icons/tabherd-16.png +0 -0
  56. package/public/icons/tabherd-20.png +0 -0
  57. package/public/icons/tabherd-24.png +0 -0
  58. package/public/icons/tabherd-256.png +0 -0
  59. package/public/icons/tabherd-32.png +0 -0
  60. package/public/icons/tabherd-40.png +0 -0
  61. package/public/icons/tabherd-48.png +0 -0
  62. package/public/icons/tabherd-512.png +0 -0
  63. package/public/icons/tabherd-64.png +0 -0
  64. package/public/index.html +655 -0
  65. package/public/lang/es.js +742 -0
  66. package/public/style.css +1443 -0
  67. package/server.js +814 -0
  68. package/placeholder.js +0 -3
@@ -0,0 +1,231 @@
1
+ 'use strict';
2
+
3
+ const fs = require('fs');
4
+ const os = require('os');
5
+ const path = require('path');
6
+ const store = require('./store');
7
+ const secrets = require('./secrets');
8
+ const trackers = require('./trackers');
9
+
10
+ // Settings shared by every browser, unlike the ones the page keeps in its own
11
+ // storage. Each key has a check that returns the cleaned value, or undefined
12
+ // if the value isn't valid. The secret ones are encrypted in the file.
13
+ const DEFAULTS = {
14
+ skipPermissions: false,
15
+ excludedFolders: [],
16
+ todoFolderSource: 'repos',
17
+ todoStartFolder: '',
18
+ terminal: 'auto',
19
+ newSessionApp: 'claude',
20
+ comfyUrl: '',
21
+ localaiUrl: '',
22
+ localaiKey: '',
23
+ ollamaUrl: '',
24
+ lmstudioUrl: '',
25
+ lmstudioKey: '',
26
+ llamacppUrl: '',
27
+ // Whether the server checks GitHub for a newer Tabherd: null until the
28
+ // dashboard has asked, as nothing is sent anywhere unless someone says so.
29
+ updateCheck: null,
30
+ // Whether betas and other prereleases count as newer versions too.
31
+ updatePrereleases: false,
32
+ // Ticket trackers, with their sign-ins. Set through Settings → Tickets'
33
+ // own routes, never with the rest.
34
+ trackers: [],
35
+ };
36
+ // Kept encrypted in settings.json (see secrets.js): the keys and tokens, and
37
+ // the trackers whole, with their addresses and emails.
38
+ const SECRET = ['localaiKey', 'lmstudioKey', 'trackers'];
39
+ const isSet = (value) => (Array.isArray(value) ? value.length > 0 : Boolean(value));
40
+ // The terminals new sessions can open in, on any platform. The terminal
41
+ // drivers say which of them this computer has.
42
+ const TERMINALS = ['auto', 'windows-terminal', 'terminal', 'iterm2', 'ghostty', 'kitty', 'wezterm', 'gnome-terminal', 'ptyxis', 'konsole', 'tmux'];
43
+ const MAX_FOLDERS = 100;
44
+ const ERRORS = {
45
+ todoStartFolder: "That isn't a folder on this computer. Give its full path, or leave it empty.",
46
+ comfyUrl: 'Give an address such as http://127.0.0.1:8188, or leave it empty.',
47
+ localaiUrl: 'Give an address such as http://127.0.0.1:8080, or leave it empty.',
48
+ ollamaUrl: 'Give an address such as http://127.0.0.1:11434, or leave it empty.',
49
+ lmstudioUrl: 'Give an address such as http://127.0.0.1:1234, or leave it empty.',
50
+ llamacppUrl: 'Give an address such as http://127.0.0.1:8080, or leave it empty.',
51
+ };
52
+
53
+ // A folder under the repos folder, as the repo menu names it:
54
+ // "work/acme". Either slash is accepted.
55
+ function folderPath(p) {
56
+ if (typeof p !== 'string' || p.length > 260) return null;
57
+ const parts = p.split(/[\\/]+/).map((s) => s.trim()).filter(Boolean);
58
+ if (!parts.length || parts.some((s) => s === '.' || s === '..' || /[<>:"|?*]/.test(s))) return null;
59
+ return parts.join('/');
60
+ }
61
+
62
+ // An http or https address, without a login in it, or empty.
63
+ function webAddress(value) {
64
+ if (typeof value !== 'string' || value.length > 500) return undefined;
65
+ const v = value.trim().replace(/\/+$/, '');
66
+ if (!v) return '';
67
+ try {
68
+ const u = new URL(v);
69
+ return (u.protocol === 'http:' || u.protocol === 'https:') && !u.username && !u.password ? v : undefined;
70
+ } catch {
71
+ return undefined;
72
+ }
73
+ }
74
+
75
+ // A key or token: one line, trimmed.
76
+ function oneLine(value) {
77
+ return typeof value === 'string' && value.length <= 500 && !/[\r\n]/.test(value) ? value.trim() : undefined;
78
+ }
79
+
80
+ const CHECKS = {
81
+ // Sessions the dashboard opens run with Claude's
82
+ // --dangerously-skip-permissions, or Codex's
83
+ // --dangerously-bypass-approvals-and-sandbox. Off unless chosen.
84
+ skipPermissions(value) {
85
+ return typeof value === 'boolean' ? value : undefined;
86
+ },
87
+ // The app the repo menu, and to-dos that don't name one, start sessions in.
88
+ newSessionApp(value) {
89
+ return ['claude', 'codex', 'copilot'].includes(value) ? value : undefined;
90
+ },
91
+ // Where a ComfyUI that Comfy Desktop didn't start answers. Empty means
92
+ // http://127.0.0.1:8188. Comfy Desktop's are found by themselves.
93
+ comfyUrl: webAddress,
94
+ // Where LocalAI answers. Empty means http://127.0.0.1:8080.
95
+ localaiUrl: webAddress,
96
+ // LocalAI's API key, if it has one set. Never sent back to the page.
97
+ localaiKey: oneLine,
98
+ // Where Ollama answers. Empty means OLLAMA_HOST, or http://127.0.0.1:11434.
99
+ ollamaUrl: webAddress,
100
+ // Where LM Studio's server answers. Empty means the port it last used, or
101
+ // http://127.0.0.1:1234.
102
+ lmstudioUrl: webAddress,
103
+ // LM Studio's API token, if it requires one. Never sent back to the page.
104
+ lmstudioKey: oneLine,
105
+ // Where llama.cpp's server answers. Empty means LLAMA_ARG_HOST and
106
+ // LLAMA_ARG_PORT, or http://127.0.0.1:8080.
107
+ llamacppUrl: webAddress,
108
+ // Yes or no to checking for a newer Tabherd. Once answered, it isn't asked again.
109
+ updateCheck(value) {
110
+ return typeof value === 'boolean' ? value : undefined;
111
+ },
112
+ updatePrereleases(value) {
113
+ return typeof value === 'boolean' ? value : undefined;
114
+ },
115
+ trackers: trackers.cleanList,
116
+ // Left out of the repo menu, with everything inside them.
117
+ excludedFolders(list) {
118
+ if (!Array.isArray(list) || list.length > MAX_FOLDERS) return undefined;
119
+ const paths = list.map(folderPath);
120
+ if (paths.includes(null)) return undefined;
121
+ const seen = new Set();
122
+ return paths.filter((p) => {
123
+ const key = p.toLowerCase();
124
+ if (seen.has(key)) return false;
125
+ seen.add(key);
126
+ return true;
127
+ });
128
+ },
129
+ // The terminal that sessions the dashboard opens run in. Automatic picks
130
+ // one this computer has.
131
+ terminal(value) {
132
+ return TERMINALS.includes(value) ? value : undefined;
133
+ },
134
+ // Where a to-do's folder is chosen from: the repo menu, or Windows' folder picker.
135
+ todoFolderSource(value) {
136
+ return value === 'repos' || value === 'picker' ? value : undefined;
137
+ },
138
+ // The folder that choice starts at, as a full path. Empty means the repos
139
+ // folder, and ~ the home folder.
140
+ todoStartFolder(value) {
141
+ if (typeof value !== 'string' || value.length > 1000) return undefined;
142
+ const p = value.trim().replace(/^~(?=$|[\\/])/, os.homedir());
143
+ if (!p) return '';
144
+ if (!path.isAbsolute(p)) return undefined;
145
+ try {
146
+ return fs.statSync(p).isDirectory() ? path.resolve(p) : undefined;
147
+ } catch {
148
+ return undefined;
149
+ }
150
+ },
151
+ };
152
+
153
+ // Secrets that are saved but couldn't be decrypted this run, as saved, so
154
+ // saving other settings doesn't lose them. Setting one replaces it.
155
+ let unreadable = {};
156
+
157
+ // A hand-edited file can hold anything; keep only what passes the checks.
158
+ // Secrets saved before they were encrypted are noted, to be encrypted now.
159
+ function load() {
160
+ const saved = store.read('settings', {});
161
+ const settings = { ...DEFAULTS };
162
+ let plain = false;
163
+ unreadable = {};
164
+ for (const [key, check] of Object.entries(CHECKS)) {
165
+ if (!saved || typeof saved !== 'object' || !Object.hasOwn(saved, key)) continue;
166
+ let raw = saved[key];
167
+ if (SECRET.includes(key)) {
168
+ if (secrets.isEncrypted(raw)) {
169
+ const value = secrets.decrypt(raw);
170
+ if (value === undefined) {
171
+ unreadable[key] = raw;
172
+ continue;
173
+ }
174
+ raw = value;
175
+ } else if (isSet(raw)) plain = true;
176
+ }
177
+ const value = check(raw);
178
+ if (value !== undefined) settings[key] = value;
179
+ }
180
+ return { settings, plain };
181
+ }
182
+
183
+ // The settings as written: secrets encrypted, or as they were if they
184
+ // couldn't be read. Throws if they can't be encrypted, so none is written plain.
185
+ function forDisk(s) {
186
+ const out = { ...s };
187
+ for (const key of SECRET) {
188
+ if (Object.hasOwn(unreadable, key)) out[key] = unreadable[key];
189
+ else if (isSet(s[key])) out[key] = secrets.encrypt(s[key]);
190
+ }
191
+ return out;
192
+ }
193
+
194
+ const loaded = load();
195
+ let current = loaded.settings;
196
+ if (loaded.plain) {
197
+ try {
198
+ store.write('settings', forDisk(current));
199
+ } catch {
200
+ // Left as it was until a key can be made; Settings → Tickets says why.
201
+ }
202
+ }
203
+
204
+ const get = () => current;
205
+
206
+ // Changes only the keys given, all or none. Trackers are changed only by the
207
+ // server's own routes for them (`internal`), which keep their tokens.
208
+ function update(changes, { internal = false } = {}) {
209
+ const next = { ...current };
210
+ for (const [key, value] of Object.entries(changes || {})) {
211
+ const clean = Object.hasOwn(CHECKS, key) && (internal || key !== 'trackers') ? CHECKS[key](value) : undefined;
212
+ if (clean === undefined) return { ok: false, error: (Object.hasOwn(ERRORS, key) && ERRORS[key]) || `Not a valid value for ${key}.` };
213
+ next[key] = clean;
214
+ }
215
+ const replaced = Object.keys(changes || {}).filter((key) => Object.hasOwn(unreadable, key));
216
+ const kept = { ...unreadable };
217
+ for (const key of replaced) delete unreadable[key];
218
+ try {
219
+ store.write('settings', forDisk(next));
220
+ } catch (err) {
221
+ unreadable = kept;
222
+ return { ok: false, error: `Couldn't save settings: ${err.message}` };
223
+ }
224
+ current = next;
225
+ return { ok: true, settings: current };
226
+ }
227
+
228
+ // Secrets saved but not readable here, for Settings to say so.
229
+ const unreadableKeys = () => Object.keys(unreadable);
230
+
231
+ module.exports = { get, update, unreadableKeys };
package/lib/store.js ADDED
@@ -0,0 +1,44 @@
1
+ 'use strict';
2
+
3
+ const fs = require('fs');
4
+ const os = require('os');
5
+ const path = require('path');
6
+
7
+ // What the server keeps between runs, one JSON file per kind, in ~/.tabherd
8
+ // (or TABHERD_DATA_DIR). Before the project was renamed Tabherd, the folder
9
+ // was ~/.claude-agents; it's moved on the first run after the rename. If it
10
+ // can't be moved, it's used where it is.
11
+ function dataDir(home = os.homedir(), env = process.env) {
12
+ if (env.TABHERD_DATA_DIR) return env.TABHERD_DATA_DIR;
13
+ const dir = path.join(home, '.tabherd');
14
+ const old = path.join(home, '.claude-agents');
15
+ if (fs.existsSync(dir) || !fs.existsSync(old)) return dir;
16
+ try {
17
+ fs.renameSync(old, dir);
18
+ return dir;
19
+ } catch {
20
+ return old;
21
+ }
22
+ }
23
+
24
+ const DATA_DIR = dataDir();
25
+
26
+ function read(name, fallback) {
27
+ try {
28
+ return JSON.parse(fs.readFileSync(path.join(DATA_DIR, `${name}.json`), 'utf8'));
29
+ } catch {
30
+ return fallback;
31
+ }
32
+ }
33
+
34
+ // Written beside the old file and renamed over it, so a crash mid-write can't
35
+ // leave half a file.
36
+ function write(name, data) {
37
+ fs.mkdirSync(DATA_DIR, { recursive: true });
38
+ const file = path.join(DATA_DIR, `${name}.json`);
39
+ const temp = `${file}.${process.pid}.tmp`;
40
+ fs.writeFileSync(temp, `${JSON.stringify(data, null, 2)}\n`);
41
+ fs.renameSync(temp, file);
42
+ }
43
+
44
+ module.exports = { DATA_DIR, dataDir, read, write };
@@ -0,0 +1,62 @@
1
+ 'use strict';
2
+
3
+ // Everything that drives terminals and windows, one driver per operating
4
+ // system, each with the same functions:
5
+ //
6
+ // terminals() the terminals Settings offers, and which are available
7
+ // quote(text) text quoted as one argument for the shell commands run in
8
+ // open(dir, command, o) opens a tab running `command` in `dir`, in o.terminal
9
+ // focus(pid, o) goes to the session's tab; with o.send, also types
10
+ // that prompt into it and presses Enter
11
+ // pickFolder(start, t) shows a folder picker: { ok, path } or { ok, cancelled }
12
+ // stop(pid) ends the session and the processes it started
13
+ // close(pid) ends the session, and its terminal tab with it
14
+ // openFolder(dir) shows the folder in the file manager
15
+ // refreshTitles(pids) starts reading the sessions' tab titles, in the background
16
+ // titleFor(pid) the title last read for that session's tab
17
+
18
+ const DRIVERS = { win32: './windows', darwin: './macos', linux: './linux' };
19
+ const driver = require(DRIVERS[process.platform] || './unsupported');
20
+
21
+ // The variables a Claude Code session gives the programs it runs. A server
22
+ // started from inside a session has them, and the terminals it opens pass
23
+ // them on, so the sessions it starts would run as that one's children:
24
+ // unattended, without colour, unseen by the dashboard, and holding that
25
+ // session's messaging pipe and token. CLAUDE_CONFIG_DIR is the user's own
26
+ // setting, so it stays. Done once, as this module loads, for everything
27
+ // that opens terminals.
28
+ //
29
+ // Codex gives the commands it runs its session's IDs and sandbox, and turns
30
+ // off colour and paging for them, which would carry into the tabs too. The
31
+ // settings people set themselves, such as CODEX_HOME, stay.
32
+ const CODEX_SESSION_VARS = /^CODEX_(THREAD_ID|SESSION_ID|TOOL_CALL_ID|VERSION|PERMISSION_PROFILE|SANDBOX\w*|CI|APPLY_PATCH_\w+|NETWORK_PROXY_\w+)$/;
33
+ const CODEX_PLAIN_OUTPUT = { NO_COLOR: '1', TERM: 'dumb', PAGER: 'cat', GIT_PAGER: 'cat', GH_PAGER: 'cat' };
34
+ // The Copilot CLI's own, for its session, hooks and supervisor. COPILOT_HOME
35
+ // and a GitHub token someone set themselves stay.
36
+ const COPILOT_SESSION_VARS = /^COPILOT_(CLI|AGENT_SESSION_ID|PROJECT_DIR|HOOK_\w+|TRACEPARENT|PLUGIN_ROOT|LOADER_PID|SUPERVISED|RESTART_SUPERVISOR\w*|CONNECTION_TOKEN|DETACHED_\w+)$/;
37
+
38
+ function forgetParentSession(env = process.env) {
39
+ const insideCodex = 'CODEX_THREAD_ID' in env;
40
+ for (const key of Object.keys(env)) {
41
+ if (/^CLAUDE(CODE$|_)/.test(key) && key !== 'CLAUDE_CONFIG_DIR') delete env[key];
42
+ else if (CODEX_SESSION_VARS.test(key) || COPILOT_SESSION_VARS.test(key)) delete env[key];
43
+ else if (insideCodex && CODEX_PLAIN_OUTPUT[key] === env[key]) delete env[key];
44
+ }
45
+ return env;
46
+ }
47
+ forgetParentSession();
48
+
49
+ // One picker at a time: a second one would open behind the first.
50
+ let picking = false;
51
+
52
+ async function pickFolder(start, title) {
53
+ if (picking) return { ok: false, error: 'A folder picker is already open. It may be behind another window.' };
54
+ picking = true;
55
+ try {
56
+ return await driver.pickFolder(start, title);
57
+ } finally {
58
+ picking = false;
59
+ }
60
+ }
61
+
62
+ module.exports = { ...driver, pickFolder, forgetParentSession };
@@ -0,0 +1,126 @@
1
+ 'use strict';
2
+
3
+ // kitty, on macOS and Linux, driven through its remote control. That's off
4
+ // until kitty.conf has these two lines, and kitty is restarted:
5
+ //
6
+ // allow_remote_control socket-only
7
+ // listen_on unix:/tmp/kitty
8
+ //
9
+ // kitty then listens on /tmp/kitty-<its PID>. Its panes have no terminal
10
+ // device to go by, so a session's pane is the one whose shell is among the
11
+ // session's ancestors.
12
+
13
+ const fs = require('fs');
14
+ const os = require('os');
15
+ const path = require('path');
16
+ const unix = require('./unix');
17
+
18
+ // kitty's installer puts it in ~/Applications; Homebrew in /Applications.
19
+ const MAC_APPS = ['/Applications', path.join(os.homedir(), 'Applications')].map((dir) => path.join(dir, 'kitty.app', 'Contents', 'MacOS'));
20
+ const SETUP =
21
+ "kitty isn't listening for remote control. Add \"allow_remote_control socket-only\" and \"listen_on unix:/tmp/kitty\" to kitty.conf, then quit kitty completely and open it again.";
22
+
23
+ const findBin = (name) => unix.which(name) || MAC_APPS.map((dir) => path.join(dir, name)).find((file) => fs.existsSync(file)) || null;
24
+ const kitten = () => findBin('kitten') || findBin('kitty');
25
+
26
+ // The unix sockets a process has open, for a listen_on set to another path.
27
+ async function openSockets(pid) {
28
+ const out = await unix.run('lsof', ['-a', '-p', String(pid), '-U', '-Fn']);
29
+ return out.stdout
30
+ .split('\n')
31
+ .filter((line) => line.startsWith('n/'))
32
+ .map((line) => line.slice(1))
33
+ .filter(unix.isSocket);
34
+ }
35
+
36
+ // The sockets of running kittys, the session's own first: the one in its
37
+ // environment (Linux), /tmp/kitty-<PID> as listen_on unix:/tmp/kitty makes,
38
+ // or whatever socket the kitty process has open.
39
+ async function sockets(table, ctx) {
40
+ const found = [];
41
+ if (ctx?.env?.KITTY_LISTEN_ON) found.push(ctx.env.KITTY_LISTEN_ON);
42
+ const own = ctx?.chain.find((p) => p.name === 'kitty');
43
+ const pids = [...new Set([...(own ? [own.pid] : []), ...[...table.values()].filter((p) => p.name === 'kitty').map((p) => p.pid)])];
44
+ for (const pid of pids) {
45
+ if (unix.isSocket(`/tmp/kitty-${pid}`)) found.push(`unix:/tmp/kitty-${pid}`);
46
+ else for (const file of await openSockets(pid)) found.push(`unix:${file}`);
47
+ }
48
+ if (unix.isSocket('/tmp/kitty')) found.push('unix:/tmp/kitty');
49
+ return [...new Set(found)];
50
+ }
51
+
52
+ const remote = (to, args, input) => unix.run(kitten(), ['@', '--to', to, ...args], { input });
53
+
54
+ // The kitty socket and window running the session, or what stopped that.
55
+ async function locate(ctx) {
56
+ const chain = new Set(ctx.chain.map((p) => p.pid));
57
+ const list = await sockets(ctx.table || (await unix.processTable()), ctx);
58
+ if (!list.length) return { error: SETUP };
59
+ let refused = null;
60
+ for (const to of list) {
61
+ const out = await remote(to, ['ls']);
62
+ if (!out.ok) {
63
+ refused = refused || out.stderr.trim();
64
+ continue;
65
+ }
66
+ let windows = [];
67
+ try {
68
+ windows = JSON.parse(out.stdout).flatMap((osWindow) => osWindow.tabs.flatMap((tab) => tab.windows));
69
+ } catch {}
70
+ const found = windows.find((w) => chain.has(w.pid) || (w.foreground_processes || []).some((p) => p.pid === ctx.pid));
71
+ if (found) return { to, window: found };
72
+ }
73
+ if (refused) return { error: `kitty didn't answer on its remote-control socket: ${refused}` };
74
+ return { error: "kitty is listening, but didn't list this session's window." };
75
+ }
76
+
77
+ function backend({ raise } = {}) {
78
+ return {
79
+ id: 'kitty',
80
+ name: 'kitty',
81
+ processNames: ['kitty'],
82
+ available: () => Boolean(kitten()),
83
+ hosts: (ctx) => ctx.chain.some((p) => p.name === 'kitty'),
84
+ async open(dir, command) {
85
+ const to = (await sockets(await unix.processTable()))[0];
86
+ if (to) {
87
+ const out = await remote(to, ['launch', '--type=tab', `--cwd=${dir}`, ...unix.shellArgs(dir, command)]);
88
+ if (out.ok) return { ok: true };
89
+ }
90
+ // Without remote control, a new kitty window.
91
+ const kitty = findBin('kitty');
92
+ if (!kitty) return { ok: false, error: "kitty wasn't found." };
93
+ return unix.detached(kitty, ['--directory', dir, ...unix.shellArgs(dir, command)]);
94
+ },
95
+ async focus(ctx) {
96
+ const at = await locate(ctx);
97
+ if (at.error) return { ok: false, error: at.error };
98
+ const out = await remote(at.to, ['focus-window', '--match', `id:${at.window.id}`]);
99
+ if (!out.ok) return { ok: false, error: `kitty couldn't go to it: ${out.stderr.trim()}` };
100
+ if (raise) await raise(ctx);
101
+ return { ok: true, tab: true };
102
+ },
103
+ // Pasted, marked as a paste if the session asked for that, then Enter.
104
+ async type(ctx, text) {
105
+ const at = await locate(ctx);
106
+ if (at.error) return at.error;
107
+ const match = ['--match', `id:${at.window.id}`];
108
+ let out = await remote(at.to, ['send-text', ...match, '--bracketed-paste=auto', '--stdin'], text);
109
+ if (!out.ok) out = await remote(at.to, ['send-text', ...match, '--stdin'], text);
110
+ if (!out.ok) return `kitty couldn't type into it: ${out.stderr.trim()}`;
111
+ await unix.pause(300);
112
+ out = await remote(at.to, ['send-key', ...match, 'enter']);
113
+ return out.ok ? null : `kitty couldn't press Enter: ${out.stderr.trim()}`;
114
+ },
115
+ async titles(ctxs) {
116
+ const map = new Map();
117
+ for (const ctx of ctxs) {
118
+ const at = await locate(ctx);
119
+ if (at.window?.title) map.set(ctx.tty, at.window.title);
120
+ }
121
+ return map;
122
+ },
123
+ };
124
+ }
125
+
126
+ module.exports = { backend };