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,310 @@
1
+ 'use strict';
2
+
3
+ // Linux. Each terminal app is a backend (see unix-driver.js); sessions inside
4
+ // tmux are handled by tmux whatever terminal shows it.
5
+
6
+ const fs = require('fs');
7
+ const os = require('os');
8
+ const path = require('path');
9
+ const unix = require('./unix');
10
+ const tmux = require('./tmux');
11
+ const kitty = require('./kitty');
12
+ const wezterm = require('./wezterm');
13
+ const { create } = require('./unix-driver');
14
+
15
+ const has = (cmd) => Boolean(unix.which(cmd));
16
+ const inChain = (ctx, ...names) => ctx.chain.some((p) => names.includes(p.name));
17
+
18
+ const desktop = () => String(process.env.XDG_CURRENT_DESKTOP || '').toUpperCase();
19
+ const wayland = () => Boolean(process.env.WAYLAND_DISPLAY) || process.env.XDG_SESSION_TYPE === 'wayland';
20
+
21
+ // busctl, on the user's session bus, with its JSON output parsed.
22
+ async function busctl(args) {
23
+ if (!has('busctl')) return { ok: false, error: 'busctl was not found.' };
24
+ const out = await unix.run('busctl', ['--user', '--json=short', ...args]);
25
+ if (!out.ok) return { ok: false, error: out.stderr.trim() };
26
+ try {
27
+ return { ok: true, data: out.stdout.trim() ? JSON.parse(out.stdout).data : null };
28
+ } catch {
29
+ return { ok: true, data: null };
30
+ }
31
+ }
32
+
33
+ // On KDE, KWin runs a small script that activates the window, which works on
34
+ // Wayland too: KWin's own scripts aren't held back by focus-stealing rules.
35
+ async function raiseOnKde(pid, title) {
36
+ const script = path.join(os.tmpdir(), `tabherd-raise-${process.pid}.js`);
37
+ const match = title ? ` && w.caption.indexOf(${JSON.stringify(title)}) >= 0` : '';
38
+ fs.writeFileSync(
39
+ script,
40
+ `for (const w of workspace.windowList()) if (w.pid === ${Number(pid)} && w.normalWindow${match}) { workspace.activeWindow = w; break; }\n`,
41
+ );
42
+ const name = 'tabherd-raise';
43
+ await busctl(['call', 'org.kde.KWin', '/Scripting', 'org.kde.kwin.Scripting', 'unloadScript', 's', name]);
44
+ const loaded = await busctl(['call', 'org.kde.KWin', '/Scripting', 'org.kde.kwin.Scripting', 'loadScript', 'ss', script, name]);
45
+ const id = loaded.data?.[0];
46
+ if (!loaded.ok || !(id >= 0)) return false;
47
+ const ran = await busctl(['call', 'org.kde.KWin', `/Scripting/Script${id}`, 'org.kde.kwin.Script', 'run']);
48
+ return ran.ok;
49
+ }
50
+
51
+ // Brings a terminal's window forward: through KWin on KDE, and with xdotool on
52
+ // X11, picking the window with that title when the terminal has several.
53
+ // GNOME on Wayland doesn't let one app do this for another; it shows that the
54
+ // window is ready instead.
55
+ async function raiseWindow(pid, title, windowId) {
56
+ if (!pid) return false;
57
+ if (desktop().includes('KDE') && has('busctl')) return raiseOnKde(pid, title);
58
+ if (!process.env.DISPLAY || !has('xdotool')) return false;
59
+ if (windowId) return (await unix.run('xdotool', ['windowactivate', String(windowId)])).ok;
60
+ const out = await unix.run('xdotool', ['search', '--onlyvisible', '--pid', String(pid)]);
61
+ const ids = out.stdout.split('\n').filter(Boolean);
62
+ if (!ids.length) return false;
63
+ let target = ids[0];
64
+ if (title) {
65
+ for (const id of ids) {
66
+ const name = await unix.run('xdotool', ['getwindowname', id]);
67
+ if (name.stdout.trim().includes(title)) target = id;
68
+ }
69
+ }
70
+ return (await unix.run('xdotool', ['windowactivate', target])).ok;
71
+ }
72
+
73
+ // The terminal's own process, among the session's ancestors. Linux shortens
74
+ // process names to 15 characters, so gnome-terminal-server is "gnome-terminal-".
75
+ const guiPid = (ctx, ...names) => ctx?.chain?.find((p) => names.includes(p.name))?.pid;
76
+
77
+ // The environment a session in an existing window has, so a new tab can join
78
+ // that window, from the first shell found under that terminal's process.
79
+ function siblingEnvironment(table, terminalNames, key) {
80
+ for (const p of table.values()) {
81
+ const parent = table.get(p.ppid);
82
+ if (!parent || !terminalNames.includes(parent.name)) continue;
83
+ const env = unix.environment(p.pid);
84
+ if (env?.[key]) return env;
85
+ }
86
+ return null;
87
+ }
88
+
89
+ // GNOME Terminal. Its search provider, which GNOME's shell uses to find tabs,
90
+ // is what can switch to a tab and read tab titles; each session's environment
91
+ // names its tab. Nothing outside it can type into a tab.
92
+ const GNOME_SERVER = ['gnome-terminal-', 'gnome-terminal-server'];
93
+ const SEARCH_PROVIDER = ['/org/gnome/Terminal/SearchProvider', 'org.gnome.Shell.SearchProvider2'];
94
+ const gnomeTab = (ctx) => {
95
+ const screen = ctx.env?.GNOME_TERMINAL_SCREEN;
96
+ return screen ? { service: ctx.env.GNOME_TERMINAL_SERVICE || 'org.gnome.Terminal', uuid: path.basename(screen).replace(/_/g, '-') } : null;
97
+ };
98
+
99
+ const gnomeTerminal = {
100
+ id: 'gnome-terminal',
101
+ processNames: GNOME_SERVER,
102
+ name: 'GNOME Terminal',
103
+ available: () => has('gnome-terminal'),
104
+ hosts: (ctx) => Boolean(ctx.env?.GNOME_TERMINAL_SCREEN) || inChain(ctx, ...GNOME_SERVER),
105
+ // A tab joins an existing window when gnome-terminal is told one of its
106
+ // tabs; otherwise it opens a window.
107
+ async open(dir, command) {
108
+ const env = { ...process.env };
109
+ delete env.GNOME_TERMINAL_SCREEN;
110
+ delete env.GNOME_TERMINAL_SERVICE;
111
+ const sibling = siblingEnvironment(await unix.processTable(), GNOME_SERVER, 'GNOME_TERMINAL_SCREEN');
112
+ if (sibling) Object.assign(env, { GNOME_TERMINAL_SCREEN: sibling.GNOME_TERMINAL_SCREEN, GNOME_TERMINAL_SERVICE: sibling.GNOME_TERMINAL_SERVICE });
113
+ const out = await unix.run('gnome-terminal', ['--tab', `--working-directory=${dir}`, '--', ...unix.shellArgs(dir, command)], { env });
114
+ return out.ok ? { ok: true } : { ok: false, error: `GNOME Terminal didn't open a tab: ${out.stderr.trim()}` };
115
+ },
116
+ async focus(ctx) {
117
+ const tab = gnomeTab(ctx);
118
+ if (!tab) return { ok: false, error: "GNOME Terminal didn't say which tab this session is in." };
119
+ const out = await busctl(['call', tab.service, ...SEARCH_PROVIDER, 'ActivateResult', 'sasu', tab.uuid, '0', '0']);
120
+ if (!out.ok) return { ok: false, error: `GNOME Terminal couldn't go to it: ${out.error}` };
121
+ // The window now shows the tab's title, which picks it out on X11.
122
+ const meta = await busctl(['call', tab.service, ...SEARCH_PROVIDER, 'GetResultMetas', 'as', '1', tab.uuid]);
123
+ const raised = await raiseWindow(guiPid(ctx, ...GNOME_SERVER), meta.data?.[0]?.[0]?.name?.data);
124
+ return { ok: true, tab: true, raised };
125
+ },
126
+ async titles(ctxs) {
127
+ const map = new Map();
128
+ const tabs = ctxs.map((ctx) => ({ ctx, tab: gnomeTab(ctx) })).filter((t) => t.tab);
129
+ if (!tabs.length) return map;
130
+ const out = await busctl(['call', tabs[0].tab.service, ...SEARCH_PROVIDER, 'GetResultMetas', 'as', String(tabs.length), ...tabs.map((t) => t.tab.uuid)]);
131
+ for (const meta of out.data?.[0] || []) {
132
+ const t = tabs.find((x) => x.tab.uuid === meta.id?.data);
133
+ if (t && meta.name?.data) map.set(t.ctx.tty, meta.name.data);
134
+ }
135
+ return map;
136
+ },
137
+ };
138
+
139
+ // Ptyxis, Ubuntu's terminal from 25.10. It can open a tab; showing a given tab
140
+ // needs the tab's ID in the session's environment, which Ptyxis adds after 50.
141
+ const ptyxis = {
142
+ id: 'ptyxis',
143
+ processNames: ['ptyxis', 'ptyxis-agent'],
144
+ name: 'Ptyxis',
145
+ available: () => has('ptyxis'),
146
+ hosts: (ctx) => Boolean(ctx.env?.PTYXIS_VERSION) || inChain(ctx, 'ptyxis', 'ptyxis-agent'),
147
+ async open(dir, command) {
148
+ const out = await unix.run('ptyxis', ['--tab', '-d', dir, '--', ...unix.shellArgs(dir, command)]);
149
+ return out.ok ? { ok: true } : { ok: false, error: `Ptyxis didn't open a tab: ${out.stderr.trim()}` };
150
+ },
151
+ async focus(ctx) {
152
+ const uuid = ctx.env?.PTYXIS_TAB;
153
+ if (!uuid) {
154
+ const raised = await raiseWindow(guiPid(ctx, 'ptyxis'));
155
+ return raised ? { ok: true, tab: false } : { ok: false, error: 'This version of Ptyxis can\'t be asked to show a given tab.' };
156
+ }
157
+ const out = await busctl(['call', 'org.gnome.Ptyxis', '/org/gnome/Ptyxis', 'org.gtk.Actions', 'Activate', 'sava{sv}', 'focus-tab-by-uuid', '1', 's', uuid, '0']);
158
+ return out.ok ? { ok: true, tab: true } : { ok: false, error: `Ptyxis couldn't go to it: ${out.error}` };
159
+ },
160
+ };
161
+
162
+ // Konsole, through its D-Bus interface; each session's environment names its
163
+ // service, window and session. From Konsole 25.12, typing into a tab is off
164
+ // until the user turns on a setting.
165
+ const KONSOLE_LOCKED =
166
+ 'Konsole blocks typing into its tabs. Turn on Configure Konsole › General › "Enable the security sensitive parts of the DBus API", then restart Konsole.';
167
+ // Konsole's version as a number, 2508 for 25.08.
168
+ let konsoleVersion = null;
169
+ async function konsoleRelease() {
170
+ if (konsoleVersion === null) {
171
+ const m = (await unix.run('konsole', ['--version'])).stdout.match(/(\d+)\.(\d+)/);
172
+ konsoleVersion = m ? Number(m[1]) * 100 + Number(m[2]) : 0;
173
+ }
174
+ return konsoleVersion;
175
+ }
176
+
177
+ const konsoleIds = (ctx) => {
178
+ const env = ctx.env || {};
179
+ if (!env.KONSOLE_DBUS_SERVICE || !env.KONSOLE_DBUS_SESSION) return null;
180
+ return { service: env.KONSOLE_DBUS_SERVICE, session: env.KONSOLE_DBUS_SESSION, window: env.KONSOLE_DBUS_WINDOW, windowId: env.WINDOWID };
181
+ };
182
+
183
+ const konsole = {
184
+ id: 'konsole',
185
+ processNames: ['konsole'],
186
+ name: 'Konsole',
187
+ available: () => has('konsole'),
188
+ hosts: (ctx) => Boolean(ctx.env?.KONSOLE_DBUS_SESSION) || inChain(ctx, 'konsole'),
189
+ // In a running Konsole, a new tab in its window: from 25.08 by loading a
190
+ // one-tab layout, which types the command into the tab's shell and isn't
191
+ // blocked as typing is from 25.12; before 25.08, a new tab and then the
192
+ // command. Otherwise, a new window.
193
+ async open(dir, command) {
194
+ const sibling = siblingEnvironment(await unix.processTable(), ['konsole'], 'KONSOLE_DBUS_SERVICE');
195
+ if (sibling?.KONSOLE_DBUS_WINDOW) {
196
+ const at = [sibling.KONSOLE_DBUS_SERVICE, sibling.KONSOLE_DBUS_WINDOW, 'org.kde.konsole.Window'];
197
+ if ((await konsoleRelease()) >= 2508) {
198
+ const layout = path.join(os.tmpdir(), `tabherd-konsole-${process.pid}.json`);
199
+ fs.writeFileSync(layout, JSON.stringify({ Orientation: 'Horizontal', Widgets: [{ SessionRestoreId: 0, WorkingDirectory: dir, Command: command }] }));
200
+ const loaded = await busctl(['call', ...at, 'loadLayout', 's', layout]);
201
+ fs.rmSync(layout, { force: true });
202
+ if (loaded.ok) return { ok: true };
203
+ } else {
204
+ const created = await busctl(['call', ...at, 'newSession', 'ss', '', dir]);
205
+ const id = created.data?.[0];
206
+ if (created.ok && Number.isInteger(id)) {
207
+ const ran = await busctl(['call', sibling.KONSOLE_DBUS_SERVICE, `/Sessions/${id}`, 'org.kde.konsole.Session', 'runCommand', 's', command]);
208
+ if (ran.ok) return { ok: true };
209
+ }
210
+ }
211
+ }
212
+ return unix.detached('konsole', ['--new-tab', '--workdir', dir, '-e', ...unix.shellArgs(dir, command)]);
213
+ },
214
+ async focus(ctx) {
215
+ const ids = konsoleIds(ctx);
216
+ if (!ids) return { ok: false, error: "Konsole didn't say which tab this session is in." };
217
+ const session = Number(path.basename(ids.session));
218
+ const out = await busctl(['call', ids.service, ids.window || '/Windows/1', 'org.kde.konsole.Window', 'setCurrentSession', 'i', String(session)]);
219
+ if (!out.ok) return { ok: false, error: `Konsole couldn't go to it: ${out.error}` };
220
+ const title = (await busctl(['call', ids.service, ids.session, 'org.kde.konsole.Session', 'title', 'i', '1'])).data?.[0];
221
+ const raised = await raiseWindow(guiPid(ctx, 'konsole'), title, wayland() ? null : ids.windowId);
222
+ return { ok: true, tab: true, raised };
223
+ },
224
+ async type(ctx, text) {
225
+ const ids = konsoleIds(ctx);
226
+ if (!ids) return "Konsole didn't say which tab this session is in";
227
+ const send = (s) => busctl(['call', ids.service, ids.session, 'org.kde.konsole.Session', 'sendText', 's', s]);
228
+ let out = await send(`\u001b[200~${text}\u001b[201~`);
229
+ if (!out.ok) return /AccessDenied|disabled/i.test(out.error) ? KONSOLE_LOCKED : `Konsole couldn't type into it: ${out.error}`;
230
+ await unix.pause(300);
231
+ out = await send('\r');
232
+ return out.ok ? null : `Konsole couldn't press Enter: ${out.error}`;
233
+ },
234
+ // No titles: Konsole's tabs are named by its own format, the folder and the
235
+ // program, and the title a program sets isn't available over D-Bus.
236
+ };
237
+
238
+ // Ghostty on Linux can open tabs and windows, and from 1.4 show a given tab,
239
+ // through its D-Bus service. It can't be typed into or have its titles read
240
+ // from outside; sessions run inside tmux get those.
241
+ const ghostty = {
242
+ id: 'ghostty',
243
+ processNames: ['ghostty'],
244
+ name: 'Ghostty',
245
+ available: () => has('ghostty'),
246
+ hosts: (ctx) => inChain(ctx, 'ghostty'),
247
+ async open(dir, command) {
248
+ const args = [`--working-directory=${dir}`, '-e', ...unix.shellArgs(dir, command)];
249
+ for (const action of ['+new-tab', '+new-window']) {
250
+ if ((await unix.run('ghostty', [action, ...args])).ok) return { ok: true };
251
+ }
252
+ return unix.detached('ghostty', args);
253
+ },
254
+ async focus(ctx) {
255
+ const surface = ctx.env?.GHOSTTY_SURFACE_ID;
256
+ if (!surface || !has('gdbus')) {
257
+ const raised = await raiseWindow(guiPid(ctx, 'ghostty'));
258
+ return raised ? { ok: true, tab: false } : { ok: false, error: 'Ghostty can only be asked to show a tab from version 1.4.' };
259
+ }
260
+ const out = await unix.run('gdbus', [
261
+ 'call', '--session', '--dest', 'com.mitchellh.ghostty', '--object-path', '/com/mitchellh/ghostty',
262
+ '--method', 'org.gtk.Actions.Activate', 'present-surface', `[<uint64 ${BigInt(surface).toString()}>]`, '{}',
263
+ ]);
264
+ return out.ok ? { ok: true, tab: true } : { ok: false, error: `Ghostty couldn't go to it: ${out.stderr.trim()}` };
265
+ },
266
+ };
267
+
268
+ const backends = [
269
+ gnomeTerminal,
270
+ ptyxis,
271
+ konsole,
272
+ kitty.backend(),
273
+ wezterm.backend({ raise: (ctx) => raiseWindow(guiPid(ctx, 'wezterm-gui'), ctx.title) }),
274
+ ghostty,
275
+ {
276
+ id: 'tmux',
277
+ name: 'tmux',
278
+ available: () => tmux.available(),
279
+ hosts: () => false,
280
+ open: tmux.open,
281
+ },
282
+ ];
283
+
284
+ // The terminal Automatic picks: the desktop's own, else the first one found.
285
+ async function defaultTerminal(list) {
286
+ const desktop = String(process.env.XDG_CURRENT_DESKTOP || '').toUpperCase();
287
+ const prefer = desktop.includes('KDE') ? ['konsole'] : desktop.includes('GNOME') ? ['ptyxis', 'gnome-terminal'] : [];
288
+ const order = [...prefer, 'gnome-terminal', 'ptyxis', 'konsole', 'kitty', 'wezterm', 'ghostty', 'tmux'];
289
+ return order.find((id) => list.find((b) => b.id === id && b.open && b.available())) || null;
290
+ }
291
+
292
+ // zenity on GNOME and most desktops, kdialog on KDE. Both exit 1 when cancelled.
293
+ async function pickFolder(start, title) {
294
+ const kde = String(process.env.XDG_CURRENT_DESKTOP || '').toUpperCase().includes('KDE');
295
+ const tools = kde ? ['kdialog', 'zenity'] : ['zenity', 'kdialog'];
296
+ const tool = tools.find(has);
297
+ if (!tool) return { ok: false, error: 'No folder picker was found. Install zenity, or choose the folder from the repo menu.' };
298
+ const args =
299
+ tool === 'zenity'
300
+ ? ['--file-selection', '--directory', `--title=${title}`, ...(start ? [`--filename=${path.join(start, '/')}`] : [])]
301
+ : ['--getexistingdirectory', start || '.', '--title', title];
302
+ const out = await unix.run(tool, args, { timeout: 30 * 60 * 1000 });
303
+ if (out.code === 1) return { ok: true, cancelled: true };
304
+ const picked = out.stdout.trim();
305
+ return out.ok && picked ? { ok: true, path: picked } : { ok: false, error: out.stderr.trim() || `${tool} didn't return a folder.` };
306
+ }
307
+
308
+ const openFolder = (dir) => unix.detached('xdg-open', [dir]);
309
+
310
+ module.exports = create({ name: 'linux', backends, openFolder, pickFolder, defaultTerminal });