tabherd 0.0.0-stage → 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 (67) hide show
  1. package/CHANGELOG.md +166 -0
  2. package/LICENSE +674 -0
  3. package/README.md +540 -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 +44 -4
  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
package/lib/copilot.js ADDED
@@ -0,0 +1,359 @@
1
+ 'use strict';
2
+
3
+ // GitHub Copilot sessions, as cards like Claude's: the Copilot CLI's, and the
4
+ // agent sessions VS Code runs on the same Copilot runtime, which keep their
5
+ // state in the same place. Each session has a folder,
6
+ // $COPILOT_HOME/session-state/<id>/ (~/.copilot unless set), holding
7
+ // workspace.yaml (its folder, name and which client runs it), events.jsonl
8
+ // (everything it did) and, while a process has it open, inuse.<pid>.lock.
9
+ // Copilot also keeps open-sessions-state.json: each open session, and
10
+ // whether it's working.
11
+ //
12
+ // Approval requests are in events.jsonl, answered or not; a question for
13
+ // you is only seen as the ask_user tool it comes from.
14
+
15
+ const fs = require('fs');
16
+ const os = require('os');
17
+ const path = require('path');
18
+ const { Transcript, clip } = require('./transcript');
19
+
20
+ const COPILOT_HOME = process.env.COPILOT_HOME || path.join(os.homedir(), '.copilot');
21
+ const STATE_DIR = path.join(COPILOT_HOME, 'session-state');
22
+ const OPEN_FILE = path.join(COPILOT_HOME, 'open-sessions-state.json');
23
+ const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
24
+ // Session folders changed this recently are checked for a process too: VS
25
+ // Code's sessions may not be in the open list.
26
+ const RECENT_MS = 6 * 60 * 60 * 1000;
27
+ const RESCAN_MS = 10000;
28
+ const NO_SUBAGENTS = { running: [], finished: [], finishedTotal: 0 };
29
+
30
+ function isRunning(pid) {
31
+ try {
32
+ process.kill(pid, 0);
33
+ return true;
34
+ } catch (err) {
35
+ return err.code === 'EPERM';
36
+ }
37
+ }
38
+
39
+ // workspace.yaml is flat key: value lines.
40
+ function readWorkspace(dir) {
41
+ const out = {};
42
+ let text;
43
+ try {
44
+ text = fs.readFileSync(path.join(dir, 'workspace.yaml'), 'utf8');
45
+ } catch {
46
+ return null;
47
+ }
48
+ for (const line of text.split(/\r?\n/)) {
49
+ const m = line.match(/^([A-Za-z_]+):\s*(.*)$/);
50
+ if (!m) continue;
51
+ let v = m[2].trim();
52
+ if (/^(['"]).*\1$/.test(v)) v = v.slice(1, -1).replace(/\\(["\\])/g, '$1');
53
+ out[m[1]] = v === 'null' || v === '~' ? null : v;
54
+ }
55
+ return out;
56
+ }
57
+
58
+ // The process that has a session open, from its inuse.<pid>.lock, if it's
59
+ // still running. A lock left by a crash points at a process that's gone.
60
+ function owner(dir) {
61
+ let names;
62
+ try {
63
+ names = fs.readdirSync(dir);
64
+ } catch {
65
+ return null;
66
+ }
67
+ for (const n of names) {
68
+ const m = n.match(/^inuse\.(\d+)\.lock$/);
69
+ if (m && isRunning(Number(m[1]))) return Number(m[1]);
70
+ }
71
+ return null;
72
+ }
73
+
74
+ // ---- events.jsonl ----------------------------------------------------------------
75
+
76
+ // Read a few new bytes at a time, like a Claude transcript, into the same
77
+ // summary, plus the approvals still waiting and whether a turn is open.
78
+ class CopilotLog extends Transcript {
79
+ reset() {
80
+ super.reset();
81
+ Object.assign(this.s, { version: null, turnOpen: false, approvals: new Map(), asking: new Map() });
82
+ }
83
+
84
+ line(line) {
85
+ if (!line) return;
86
+ let e;
87
+ try {
88
+ e = JSON.parse(line);
89
+ } catch {
90
+ return;
91
+ }
92
+ const s = this.s;
93
+ const d = e.data || {};
94
+ if (e.timestamp) {
95
+ s.lastEventAt = e.timestamp;
96
+ s.startedAt = s.startedAt || e.timestamp;
97
+ }
98
+ switch (e.type) {
99
+ case 'session.start':
100
+ s.model = d.selectedModel || s.model;
101
+ s.version = d.copilotVersion || d.version || null;
102
+ s.cwd = s.cwd || d.context?.cwd || null;
103
+ if (d.context?.branch) s.gitBranch = d.context.branch;
104
+ break;
105
+ case 'session.context_changed':
106
+ if (d.context?.branch || d.branch) s.gitBranch = d.context?.branch || d.branch;
107
+ break;
108
+ case 'session.model_change':
109
+ s.model = d.newModel || s.model;
110
+ break;
111
+ case 'user.message':
112
+ // Messages Copilot adds itself, such as skill or system text, aren't prompts.
113
+ if (d.source && /^(system|skill|hook|subagent|compaction|summar)/i.test(d.source)) break;
114
+ if (typeof d.content === 'string' && d.content.trim()) {
115
+ this.noteTickets(d.content, 'prompt');
116
+ s.tools.clear();
117
+ s.lastPrompt = { text: clip(d.content), at: e.timestamp };
118
+ s.firstPrompt = s.firstPrompt || s.lastPrompt;
119
+ s.prompts++;
120
+ }
121
+ break;
122
+ case 'assistant.turn_start':
123
+ s.turnOpen = true;
124
+ break;
125
+ case 'assistant.turn_end':
126
+ s.turnOpen = false;
127
+ break;
128
+ case 'assistant.message':
129
+ if (typeof d.content === 'string' && d.content.trim()) {
130
+ s.lastReply = { text: clip(d.content), at: e.timestamp };
131
+ this.noteTickets(d.content, 'reply');
132
+ }
133
+ if (d.model) s.model = d.model;
134
+ break;
135
+ // Each model call: the model that answered, which in auto mode is the
136
+ // one Copilot chose, and its tokens.
137
+ case 'session.usage_record': {
138
+ const u = d.usage || {};
139
+ if (u.model) s.model = u.model;
140
+ if (u.modelDisplayName) s.modelName = u.modelDisplayName;
141
+ if (Number.isFinite(u.outputTokens)) s.outputTokens += u.outputTokens;
142
+ break;
143
+ }
144
+ case 'session.auto_mode_resolved':
145
+ if (d.chosenModel) s.model = d.chosenModel;
146
+ break;
147
+ case 'tool.execution_start':
148
+ if (!d.toolCallId) break;
149
+ s.tools.set(d.toolCallId, { name: d.toolTitle || d.toolName || 'Tool', detail: describe(d), at: e.timestamp });
150
+ if (d.toolName === 'ask_user') s.asking.set(d.toolCallId, d.arguments?.question || '');
151
+ break;
152
+ case 'tool.execution_complete':
153
+ s.tools.delete(d.toolCallId);
154
+ s.asking.delete(d.toolCallId);
155
+ break;
156
+ case 'permission.requested':
157
+ if (d.requestId) s.approvals.set(d.requestId, approvalText(d));
158
+ break;
159
+ case 'permission.completed':
160
+ s.approvals.delete(d.requestId);
161
+ break;
162
+ case 'abort':
163
+ s.turnOpen = false;
164
+ s.tools.clear();
165
+ s.approvals.clear();
166
+ s.asking.clear();
167
+ break;
168
+ case 'session.compaction_complete':
169
+ case 'session.compacted':
170
+ s.compactions++;
171
+ break;
172
+ }
173
+ }
174
+
175
+ summary() {
176
+ const s = this.s;
177
+ return {
178
+ ...super.summary(),
179
+ contextLimit: 0,
180
+ contextTokens: 0,
181
+ turnOpen: s.turnOpen,
182
+ approvals: [...s.approvals.values()],
183
+ asking: [...s.asking.values()],
184
+ };
185
+ }
186
+ }
187
+
188
+ function describe(d) {
189
+ const a = d.arguments && typeof d.arguments === 'object' ? d.arguments : {};
190
+ const text = d.shellToolInfo?.command || a.command || a.path || a.file_path || a.pattern || a.query || a.url || a.question || Object.values(a).find((v) => typeof v === 'string' && v.length < 200) || '';
191
+ const t = String(text).replace(/\s+/g, ' ').trim();
192
+ return t.length > 160 ? `${t.slice(0, 159)}…` : t;
193
+ }
194
+
195
+ // What an approval is for: the command to run, else the file or address, else
196
+ // what Copilot says it means to do.
197
+ function approvalText(d) {
198
+ const r = d.permissionRequest || d.promptRequest || {};
199
+ const text = r.kind === 'shell' && r.fullCommandText ? `run ${r.fullCommandText}` : r.path || r.url || r.intention || r.toolTitle || r.toolName || r.kind || 'an action';
200
+ return String(text).replace(/\s+/g, ' ').slice(0, 200);
201
+ }
202
+
203
+ // ---- sessions ------------------------------------------------------------------------
204
+
205
+ const logs = new Map();
206
+ let candidates = [];
207
+ let scannedAt = 0;
208
+
209
+ // Sessions that may be open: those in Copilot's open list, and those whose
210
+ // folder changed recently.
211
+ function findCandidates(now = Date.now()) {
212
+ if (now - scannedAt < RESCAN_MS) return candidates;
213
+ scannedAt = now;
214
+ const ids = new Set();
215
+ try {
216
+ for (const id of Object.keys(JSON.parse(fs.readFileSync(OPEN_FILE, 'utf8')) || {})) if (UUID.test(id)) ids.add(id);
217
+ } catch {}
218
+ let names = [];
219
+ try {
220
+ names = fs.readdirSync(STATE_DIR);
221
+ } catch {}
222
+ for (const n of names) {
223
+ if (!UUID.test(n) || ids.has(n)) continue;
224
+ try {
225
+ if (now - fs.statSync(path.join(STATE_DIR, n)).mtimeMs < RECENT_MS) ids.add(n);
226
+ } catch {}
227
+ }
228
+ candidates = [...ids];
229
+ return candidates;
230
+ }
231
+
232
+ function openState() {
233
+ try {
234
+ return JSON.parse(fs.readFileSync(OPEN_FILE, 'utf8')) || {};
235
+ } catch {
236
+ return {};
237
+ }
238
+ }
239
+
240
+ function readLog(id, used) {
241
+ const file = path.join(STATE_DIR, id, 'events.jsonl');
242
+ let log = logs.get(file);
243
+ if (!log) {
244
+ log = new CopilotLog(file);
245
+ logs.set(file, log);
246
+ }
247
+ used.add(file);
248
+ return log.update() ? log.summary() : null;
249
+ }
250
+
251
+ // A session's state, from its open-list flag and its log: waiting on an
252
+ // approval or an answer, working, or idle.
253
+ function stateOf(s, open) {
254
+ if (s?.approvals?.length) return { status: 'waiting', waitingFor: `Approval: ${s.approvals[0]}` };
255
+ if (s?.asking?.length) return { status: 'waiting', waitingFor: s.asking[0] ? `Question: ${s.asking[0]}` : 'Your answer' };
256
+ if (open?.working || s?.turnOpen || s?.tools?.length) return { status: 'busy', waitingFor: null };
257
+ return { status: 'idle', waitingFor: null };
258
+ }
259
+
260
+ const since = new Map();
261
+
262
+ // Copilot sessions as dashboard agents, and their processes, whose windows'
263
+ // titles the next snapshot needs.
264
+ function snapshot(now = Date.now()) {
265
+ const open = openState();
266
+ const used = new Set();
267
+ const agents = [];
268
+ for (const id of findCandidates(now)) {
269
+ const dir = path.join(STATE_DIR, id);
270
+ const pid = owner(dir);
271
+ if (!pid) continue;
272
+ const ws = readWorkspace(dir) || {};
273
+ const s = readLog(id, used);
274
+ const state = stateOf(s, open[id]);
275
+ const key = `${state.status}:${state.waitingFor}`;
276
+ const prev = since.get(id);
277
+ if (!prev || prev.key !== key) since.set(id, { key, at: now });
278
+ // VS Code's sessions run in its agent host, which has no console to type
279
+ // into and runs every VS Code session, so it isn't stopped from here.
280
+ const vscode = /vscode/i.test(ws.client_name || '');
281
+ agents.push({
282
+ ...(s || {}),
283
+ app: 'copilot',
284
+ id,
285
+ pid,
286
+ title: ws.name || ws.summary || null,
287
+ name: ws.name || ws.summary || path.basename(ws.cwd || '') || 'Copilot',
288
+ cwd: ws.cwd || s?.cwd || null,
289
+ kind: 'interactive',
290
+ entrypoint: vscode ? 'vscode' : 'cli',
291
+ version: s?.version || null,
292
+ status: state.status,
293
+ waitingFor: state.waitingFor,
294
+ statusSince: since.get(id).at,
295
+ startedAt: Date.parse(ws.created_at || '') || Date.parse(open[id]?.openedAt || '') || now,
296
+ terminalTitle: null,
297
+ subagents: NO_SUBAGENTS,
298
+ ...(vscode ? { actions: ['focus'] } : {}),
299
+ });
300
+ }
301
+ for (const file of logs.keys()) if (!used.has(file)) logs.delete(file);
302
+ const live = new Set(agents.map((a) => a.id));
303
+ for (const id of since.keys()) if (!live.has(id)) since.delete(id);
304
+ return { agents, windowPids: agents.map((a) => a.pid) };
305
+ }
306
+
307
+ // The command a new tab runs: Copilot, without its permission prompts if
308
+ // Settings says to skip them, starting a session with a given ID and name, or
309
+ // resuming one.
310
+ function command({ skipPermissions = false, resume = null, sessionId = null, name = null } = {}) {
311
+ const parts = ['copilot'];
312
+ if (skipPermissions) parts.push('--allow-all');
313
+ if (resume) parts.push(`--resume=${resume}`);
314
+ if (sessionId) parts.push(`--session-id=${sessionId}`);
315
+ if (name) parts.push('--name', name);
316
+ return parts.join(' ');
317
+ }
318
+
319
+ // ---- history ----------------------------------------------------------------------
320
+
321
+ // Session folders with a log changed since `floor`: [{ id, file, mtime, workspace }].
322
+ async function sessionFiles(floor) {
323
+ const found = [];
324
+ let names = [];
325
+ try {
326
+ names = await fs.promises.readdir(STATE_DIR);
327
+ } catch {
328
+ return found;
329
+ }
330
+ for (const id of names) {
331
+ if (!UUID.test(id)) continue;
332
+ const file = path.join(STATE_DIR, id, 'events.jsonl');
333
+ try {
334
+ const mtime = (await fs.promises.stat(file)).mtimeMs;
335
+ if (mtime >= floor) found.push({ id, file, mtime, workspace: readWorkspace(path.join(STATE_DIR, id)) || {} });
336
+ } catch {}
337
+ }
338
+ return found;
339
+ }
340
+
341
+ // Whether the Copilot CLI is on this computer: `copilot` on the PATH, or
342
+ // where winget or npm put it. VS Code makes ~/.copilot too, so that's no sign.
343
+ // Checked at most every half a minute.
344
+ let installedAt = 0;
345
+ let installedNow = false;
346
+ function installed() {
347
+ if (Date.now() - installedAt < 30000) return installedNow;
348
+ const names = process.platform === 'win32' ? ['copilot.exe', 'copilot.cmd'] : ['copilot'];
349
+ const dirs = [
350
+ ...(process.env.PATH || '').split(path.delimiter),
351
+ process.env.LOCALAPPDATA && path.join(process.env.LOCALAPPDATA, 'GitHubCopilotCLI'),
352
+ process.env.APPDATA && path.join(process.env.APPDATA, 'npm'),
353
+ ].filter(Boolean);
354
+ installedNow = dirs.some((dir) => names.some((n) => fs.existsSync(path.join(dir, n))));
355
+ installedAt = Date.now();
356
+ return installedNow;
357
+ }
358
+
359
+ module.exports = { snapshot, command, installed, sessionFiles, CopilotLog, stateOf, readWorkspace, COPILOT_HOME };