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.
- package/CHANGELOG.md +166 -0
- package/LICENSE +674 -0
- package/README.md +540 -2
- package/launcher/npm.js +9 -0
- package/lib/agents.js +324 -0
- package/lib/codex-client.js +306 -0
- package/lib/codex-rollout.js +251 -0
- package/lib/codex.js +424 -0
- package/lib/comfy.js +479 -0
- package/lib/completed.js +55 -0
- package/lib/copilot.js +359 -0
- package/lib/cursor.js +516 -0
- package/lib/dismissed.js +30 -0
- package/lib/filters.js +120 -0
- package/lib/groups.js +144 -0
- package/lib/history.js +253 -0
- package/lib/llamacpp.js +159 -0
- package/lib/lmstudio.js +134 -0
- package/lib/localai.js +291 -0
- package/lib/memory.js +55 -0
- package/lib/ollama.js +124 -0
- package/lib/open-dashboard.js +39 -0
- package/lib/opencode.js +371 -0
- package/lib/repos.js +81 -0
- package/lib/saved.js +33 -0
- package/lib/secrets.js +196 -0
- package/lib/session-id.js +9 -0
- package/lib/settings.js +231 -0
- package/lib/store.js +44 -0
- package/lib/terminals/index.js +62 -0
- package/lib/terminals/kitty.js +126 -0
- package/lib/terminals/linux.js +310 -0
- package/lib/terminals/macos.js +468 -0
- package/lib/terminals/tmux.js +89 -0
- package/lib/terminals/unix-driver.js +172 -0
- package/lib/terminals/unix.js +204 -0
- package/lib/terminals/unsupported.js +22 -0
- package/lib/terminals/wezterm.js +103 -0
- package/lib/terminals/windows-close.ps1 +125 -0
- package/lib/terminals/windows-focus.ps1 +235 -0
- package/lib/terminals/windows-pick-folder.ps1 +57 -0
- package/lib/terminals/windows-titles.js +124 -0
- package/lib/terminals/windows-titles.ps1 +95 -0
- package/lib/terminals/windows.js +166 -0
- package/lib/ticket-refs.js +184 -0
- package/lib/tickets.js +437 -0
- package/lib/todos.js +166 -0
- package/lib/trackers.js +541 -0
- package/lib/transcript.js +314 -0
- package/lib/updates.js +186 -0
- package/package.json +44 -4
- package/public/app.js +4077 -0
- package/public/favicon.svg +1 -0
- package/public/icons/tabherd-128.png +0 -0
- package/public/icons/tabherd-16.png +0 -0
- package/public/icons/tabherd-20.png +0 -0
- package/public/icons/tabherd-24.png +0 -0
- package/public/icons/tabherd-256.png +0 -0
- package/public/icons/tabherd-32.png +0 -0
- package/public/icons/tabherd-40.png +0 -0
- package/public/icons/tabherd-48.png +0 -0
- package/public/icons/tabherd-512.png +0 -0
- package/public/icons/tabherd-64.png +0 -0
- package/public/index.html +655 -0
- package/public/lang/es.js +742 -0
- package/public/style.css +1443 -0
- package/server.js +814 -0
package/public/app.js
ADDED
|
@@ -0,0 +1,4077 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
let token = document.querySelector('meta[name="agents-token"]').content;
|
|
4
|
+
|
|
5
|
+
// Settings this browser saved before the project was renamed Tabherd, under
|
|
6
|
+
// its old name, move to the new one.
|
|
7
|
+
try {
|
|
8
|
+
for (const key of Object.keys(localStorage)) {
|
|
9
|
+
if (!key.startsWith('claude-agents:')) continue;
|
|
10
|
+
const renamed = `tabherd:${key.slice('claude-agents:'.length)}`;
|
|
11
|
+
if (localStorage.getItem(renamed) === null) localStorage.setItem(renamed, localStorage.getItem(key));
|
|
12
|
+
localStorage.removeItem(key);
|
|
13
|
+
}
|
|
14
|
+
} catch {}
|
|
15
|
+
|
|
16
|
+
// Whether this browser has used the dashboard before, from the settings it
|
|
17
|
+
// keeps, read before this visit keeps any. A first visit gets the tour.
|
|
18
|
+
let firstVisit = false;
|
|
19
|
+
try {
|
|
20
|
+
firstVisit = !Object.keys(localStorage).some((key) => key.startsWith('tabherd:'));
|
|
21
|
+
} catch {}
|
|
22
|
+
|
|
23
|
+
// ---- language ----------------------------------------------------------------
|
|
24
|
+
|
|
25
|
+
// The page's words are written in English, and tr() gives each in the language
|
|
26
|
+
// chosen in Settings → Appearance, from that language's table in public/lang,
|
|
27
|
+
// or the English where the table has none. {name} in a text is filled from
|
|
28
|
+
// vars. trn() picks the form for a count: a table gives one text for each of
|
|
29
|
+
// the English forms, or, for a language with more forms than English, its
|
|
30
|
+
// own forms (Intl.PluralRules' one, few, many, other) under the English plural.
|
|
31
|
+
const LANGUAGES = { en: 'English', es: 'Español' };
|
|
32
|
+
const LANGUAGE_KEY = 'tabherd:language';
|
|
33
|
+
// Automatic follows the browser's languages, the first one there's a table for.
|
|
34
|
+
const browserLanguage =
|
|
35
|
+
(navigator.languages || [navigator.language]).map((l) => String(l).toLowerCase().split('-')[0]).find((l) => l in LANGUAGES) || 'en';
|
|
36
|
+
let languageChoice = 'auto';
|
|
37
|
+
try {
|
|
38
|
+
languageChoice = localStorage.getItem(LANGUAGE_KEY) || 'auto';
|
|
39
|
+
} catch {}
|
|
40
|
+
const lang = languageChoice in LANGUAGES ? languageChoice : browserLanguage;
|
|
41
|
+
// Each table is a script in public/lang, loaded before this one.
|
|
42
|
+
const phrases = (lang !== 'en' && window.TABHERD_LANGUAGES?.[lang]) || {};
|
|
43
|
+
const plurals = new Intl.PluralRules(lang);
|
|
44
|
+
const fillIn = (text, vars) => (vars ? text.replace(/\{(\w+)\}/g, (m, k) => (k in vars ? String(vars[k]) : m)) : text);
|
|
45
|
+
const tr = (text, vars) => fillIn(typeof phrases[text] === 'string' ? phrases[text] : text, vars);
|
|
46
|
+
function trn(n, one, other, vars) {
|
|
47
|
+
const forms = phrases[other];
|
|
48
|
+
if (forms && typeof forms === 'object') return fillIn(forms[plurals.select(n)] ?? forms.other, { n, ...vars });
|
|
49
|
+
return tr(n === 1 ? one : other, { n, ...vars });
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// The page's own text, translated once as it loads. An element marked
|
|
53
|
+
// data-i18n is translated whole, markup and all, where the words on either
|
|
54
|
+
// side of a <b> or <code> need to move together; elsewhere each piece of text
|
|
55
|
+
// is, leaving out code. So are titles, labels and placeholders.
|
|
56
|
+
function translatePage() {
|
|
57
|
+
if (lang === 'en') return;
|
|
58
|
+
document.documentElement.lang = lang;
|
|
59
|
+
for (const node of document.querySelectorAll('[data-i18n]')) node.innerHTML = tr(node.innerHTML.replace(/\s+/g, ' ').trim());
|
|
60
|
+
const skip = (n) => n.parentElement.closest('[data-i18n], code, pre, script, style') || !n.nodeValue.trim();
|
|
61
|
+
const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT, { acceptNode: (n) => (skip(n) ? NodeFilter.FILTER_REJECT : NodeFilter.FILTER_ACCEPT) });
|
|
62
|
+
for (let n = walker.nextNode(); n; n = walker.nextNode()) {
|
|
63
|
+
const text = n.nodeValue.trim();
|
|
64
|
+
n.nodeValue = n.nodeValue.replace(text, () => tr(text.replace(/\s+/g, ' ')));
|
|
65
|
+
}
|
|
66
|
+
for (const attr of ['title', 'aria-label', 'placeholder', 'data-title', 'alt']) {
|
|
67
|
+
for (const node of document.querySelectorAll(`[${attr}]`)) node.setAttribute(attr, tr(node.getAttribute(attr)));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
translatePage();
|
|
71
|
+
|
|
72
|
+
const STATUS = {
|
|
73
|
+
waiting: { label: tr('Needs you'), group: 'needs', rank: 0 },
|
|
74
|
+
busy: { label: tr('Working'), group: 'working', rank: 1 },
|
|
75
|
+
shell: { label: tr('Shell running'), group: 'working', rank: 2, hint: tr('At the prompt while a background shell task runs') },
|
|
76
|
+
// A ComfyUI job or a download waiting its turn.
|
|
77
|
+
queued: { label: tr('Queued'), group: 'working', rank: 3, hint: tr('Waiting for the ones before it') },
|
|
78
|
+
idle: { label: tr('Idle'), group: 'idle', rank: 4 },
|
|
79
|
+
unknown: { label: tr('Starting'), group: 'idle', rank: 5 },
|
|
80
|
+
// A model loaded in LocalAI: not anyone's turn, so in no filter but All.
|
|
81
|
+
loaded: { label: tr('Loaded'), group: 'resource', rank: 6 },
|
|
82
|
+
};
|
|
83
|
+
// The statuses a filter can pick: status groups, with Shell running apart
|
|
84
|
+
// from the rest of Working.
|
|
85
|
+
const FILTER_STATUSES = { needs: tr('Needs you'), working: tr('Working'), shell: tr('Shell running'), idle: tr('Idle') };
|
|
86
|
+
const filterStatus = (x) => (x.status === 'shell' ? 'shell' : status(x).group);
|
|
87
|
+
// The ticket statuses a filter can pick: the dashboard's groups for them, or none.
|
|
88
|
+
const FILTER_TICKETS = { todo: tr('To do'), progress: tr('In progress'), done: tr('Done'), closed: tr('Cancelled'), none: tr('No ticket') };
|
|
89
|
+
// A card's tickets' status: its least finished ticket's, so a card is done
|
|
90
|
+
// only once all its tickets are. Cancelled counts as finished, without being done.
|
|
91
|
+
const ticketStatus = (x) => {
|
|
92
|
+
const cats = (x.tickets || []).map((t) => t.category);
|
|
93
|
+
return cats.length ? ['todo', 'progress', 'done', 'closed'].find((c) => cats.includes(c)) || 'progress' : 'none';
|
|
94
|
+
};
|
|
95
|
+
const MAX_FILTERS = 12;
|
|
96
|
+
const PERMISSION_MODES = {
|
|
97
|
+
bypassPermissions: tr('bypass'),
|
|
98
|
+
acceptEdits: tr('accept edits'),
|
|
99
|
+
plan: tr('plan mode'),
|
|
100
|
+
auto: tr('auto'),
|
|
101
|
+
dontAsk: tr("don't ask"),
|
|
102
|
+
'never-ask': tr('never asks'),
|
|
103
|
+
};
|
|
104
|
+
// Which app each session is, on its card and in the history.
|
|
105
|
+
const APPS = { claude: 'Claude', codex: 'Codex', copilot: 'Copilot', opencode: 'OpenCode', cursor: 'Cursor', comfy: 'Comfy', localai: 'LocalAI', ollama: 'Ollama', lmstudio: 'LM Studio', llamacpp: 'llama.cpp' };
|
|
106
|
+
// Cards for things other than sessions: ComfyUI's jobs, LocalAI's models,
|
|
107
|
+
// downloads and chats, and the other model servers' loaded models.
|
|
108
|
+
const isItem = (a) => ['comfy', 'localai', 'ollama', 'lmstudio', 'llamacpp'].includes(a.app);
|
|
109
|
+
const APP_HINTS = {
|
|
110
|
+
claude: tr('A Claude Code session'),
|
|
111
|
+
codex: tr('A Codex session'),
|
|
112
|
+
copilot: tr('A GitHub Copilot session'),
|
|
113
|
+
opencode: tr('An OpenCode session'),
|
|
114
|
+
cursor: tr('A Cursor CLI session'),
|
|
115
|
+
comfy: tr('A ComfyUI job'),
|
|
116
|
+
localai: tr('From LocalAI'),
|
|
117
|
+
ollama: tr('From Ollama'),
|
|
118
|
+
lmstudio: tr('From LM Studio'),
|
|
119
|
+
llamacpp: tr("From llama.cpp's server"),
|
|
120
|
+
};
|
|
121
|
+
const appTag = (x) => el('span', { class: `app app-${x.app || 'claude'}`, title: APP_HINTS[x.app] || APP_HINTS.claude }, APPS[x.app] || APPS.claude);
|
|
122
|
+
// The colours a group can have, as the server knows them. Each is set for
|
|
123
|
+
// light and dark in the stylesheet, as .g-<name>.
|
|
124
|
+
const GROUP_COLORS = {
|
|
125
|
+
rose: tr('Rose'),
|
|
126
|
+
orange: tr('Orange'),
|
|
127
|
+
olive: tr('Olive'),
|
|
128
|
+
teal: tr('Teal'),
|
|
129
|
+
indigo: tr('Indigo'),
|
|
130
|
+
plum: tr('Plum'),
|
|
131
|
+
brown: tr('Brown'),
|
|
132
|
+
slate: tr('Slate'),
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const $ = (id) => document.getElementById(id);
|
|
136
|
+
const list = $('list');
|
|
137
|
+
const cards = new Map();
|
|
138
|
+
const subsOpen = new Map();
|
|
139
|
+
const expanded = new Set();
|
|
140
|
+
let filter = 'all';
|
|
141
|
+
let snap = null;
|
|
142
|
+
let clockSkew = 0;
|
|
143
|
+
|
|
144
|
+
// ---- helpers ---------------------------------------------------------------
|
|
145
|
+
|
|
146
|
+
function el(tag, props, ...children) {
|
|
147
|
+
const node = document.createElement(tag);
|
|
148
|
+
for (const [k, v] of Object.entries(props || {})) {
|
|
149
|
+
if (v === null || v === undefined || v === false) continue;
|
|
150
|
+
if (k === 'class') node.className = v;
|
|
151
|
+
else if (k === 'text') node.textContent = v;
|
|
152
|
+
else if (k.startsWith('on')) node.addEventListener(k.slice(2), v);
|
|
153
|
+
else node.setAttribute(k, v === true ? '' : v);
|
|
154
|
+
}
|
|
155
|
+
for (const c of children.flat()) if (c !== null && c !== undefined && c !== false) node.append(c);
|
|
156
|
+
return node;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Enter in a text box would otherwise submit the Settings form, which closes it.
|
|
160
|
+
const noSubmit = (then) => (e) => {
|
|
161
|
+
if (e.key !== 'Enter') return;
|
|
162
|
+
e.preventDefault();
|
|
163
|
+
then?.(e.currentTarget);
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
const now = () => Date.now() + clockSkew;
|
|
167
|
+
const ms = (t) => (typeof t === 'number' ? t : t ? Date.parse(t) : NaN);
|
|
168
|
+
|
|
169
|
+
// Seconds, minutes, hours and days, short.
|
|
170
|
+
const UNITS = { s: tr('{n}s'), m: tr('{n}m'), h: tr('{n}h'), d: tr('{n}d') };
|
|
171
|
+
const unit = (u, n) => fillIn(UNITS[u], { n });
|
|
172
|
+
|
|
173
|
+
function dur(delta) {
|
|
174
|
+
const s = Math.max(0, Math.floor(delta / 1000));
|
|
175
|
+
if (s < 60) return unit('s', s);
|
|
176
|
+
const m = Math.floor(s / 60);
|
|
177
|
+
if (m < 60) return unit('m', m);
|
|
178
|
+
const h = Math.floor(m / 60);
|
|
179
|
+
if (h < 24) return `${unit('h', h)} ${unit('m', m % 60)}`;
|
|
180
|
+
return `${unit('d', Math.floor(h / 24))} ${unit('h', h % 24)}`;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
// How long since then, kept up to date by tick(), as "5m ago" with ago.
|
|
184
|
+
const sinceText = (at, ago) => (ago ? tr('{time} ago', { time: dur(now() - at) }) : dur(now() - at));
|
|
185
|
+
|
|
186
|
+
function since(t, ago = false) {
|
|
187
|
+
const at = ms(t);
|
|
188
|
+
if (!Number.isFinite(at)) return null;
|
|
189
|
+
return el('span', { class: 'since', 'data-since': at, 'data-ago': ago, title: new Date(at).toLocaleString(lang) }, sinceText(at, ago));
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function tick() {
|
|
193
|
+
for (const node of document.querySelectorAll('[data-since]')) {
|
|
194
|
+
node.textContent = sinceText(Number(node.dataset.since), 'ago' in node.dataset);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function tokens(n) {
|
|
199
|
+
if (!n) return '0';
|
|
200
|
+
if (n < 1000) return String(n);
|
|
201
|
+
if (n < 1e6) return `${n < 1e4 ? (n / 1e3).toFixed(1).replace(/\.0$/, '') : Math.round(n / 1e3)}k`;
|
|
202
|
+
return `${(n / 1e6).toFixed(2).replace(/\.?0+$/, '')}M`;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function modelLabel(a) {
|
|
206
|
+
if (a.modelName) return a.modelName.replace(/ \((1M) context\)$/, ' · $1');
|
|
207
|
+
const m = (a.model || '').match(/^claude-([a-z]+)-(\d+)-(\d+)/);
|
|
208
|
+
return m ? `${m[1][0].toUpperCase()}${m[1].slice(1)} ${m[2]}.${m[3]}` : a.model;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function shortPath(p) {
|
|
212
|
+
if (!p) return '';
|
|
213
|
+
const home = snap?.home || repoData?.home;
|
|
214
|
+
return home && p.toLowerCase().startsWith(home.toLowerCase()) ? `~${p.slice(home.length)}` : p;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const status = (a) => STATUS[a.status] || STATUS.unknown;
|
|
218
|
+
// What the terminal tab shows, falling back to Claude's own names.
|
|
219
|
+
const displayName = (a) => a.terminalTitle || a.title || a.name;
|
|
220
|
+
const RESUME = {
|
|
221
|
+
codex: (id) => `codex resume ${id}`,
|
|
222
|
+
copilot: (id) => `copilot --resume=${id}`,
|
|
223
|
+
opencode: (id) => `opencode --session ${id}`,
|
|
224
|
+
cursor: (id) => `cursor-agent --resume ${id}`,
|
|
225
|
+
claude: (id) => `claude --resume ${id}`,
|
|
226
|
+
};
|
|
227
|
+
const resumeCommand = (a) => `cd "${a.cwd}"; ${(RESUME[a.app] || RESUME.claude)(a.id)}`;
|
|
228
|
+
// A Copilot session inside VS Code can only be gone to: VS Code runs it.
|
|
229
|
+
const inVsCode = (a) => a.app === 'copilot' && a.entrypoint === 'vscode';
|
|
230
|
+
|
|
231
|
+
function toast(message, isError) {
|
|
232
|
+
const t = $('toast');
|
|
233
|
+
t.textContent = message;
|
|
234
|
+
t.className = `toast show${isError ? ' error' : ''}`;
|
|
235
|
+
// A popover shows above dialogs opened before it, so it's opened again for
|
|
236
|
+
// each message, in front of whichever dialog is open now.
|
|
237
|
+
if (t.showPopover) {
|
|
238
|
+
if (t.matches(':popover-open')) t.hidePopover();
|
|
239
|
+
t.showPopover();
|
|
240
|
+
}
|
|
241
|
+
clearTimeout(toast.timer);
|
|
242
|
+
toast.timer = setTimeout(() => (t.className = 'toast'), isError ? 5000 : 2200);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
async function copy(text) {
|
|
246
|
+
try {
|
|
247
|
+
await navigator.clipboard.writeText(text);
|
|
248
|
+
} catch {
|
|
249
|
+
const area = el('textarea', { readonly: true });
|
|
250
|
+
area.value = text;
|
|
251
|
+
document.body.append(area);
|
|
252
|
+
area.select();
|
|
253
|
+
document.execCommand('copy');
|
|
254
|
+
area.remove();
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// Each server run has its own token. A page left open while the server
|
|
259
|
+
// restarted gets the new one and tries again; the server did nothing with the
|
|
260
|
+
// refused request.
|
|
261
|
+
async function api(url, body) {
|
|
262
|
+
const request = () =>
|
|
263
|
+
fetch(url, {
|
|
264
|
+
method: 'POST',
|
|
265
|
+
headers: { 'X-Agents-Token': token, 'Content-Type': 'application/json' },
|
|
266
|
+
body: JSON.stringify(body || {}),
|
|
267
|
+
});
|
|
268
|
+
let res = await request();
|
|
269
|
+
if (res.status === 403 && (await renewToken())) res = await request();
|
|
270
|
+
const data = await res.json().catch(() => ({}));
|
|
271
|
+
// The server's messages are English; the fixed ones are in the tables too.
|
|
272
|
+
if (!res.ok || !data.ok) throw new Error(data.error ? tr(data.error) : tr('Request failed ({status})', { status: res.status }));
|
|
273
|
+
return data;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// Reads the token from a fresh copy of the page. True if it changed.
|
|
277
|
+
async function renewToken() {
|
|
278
|
+
try {
|
|
279
|
+
const html = await (await fetch('/', { cache: 'no-store' })).text();
|
|
280
|
+
const fresh = new DOMParser().parseFromString(html, 'text/html').querySelector('meta[name="agents-token"]')?.content;
|
|
281
|
+
if (!fresh || fresh === token) return false;
|
|
282
|
+
token = fresh;
|
|
283
|
+
return true;
|
|
284
|
+
} catch {
|
|
285
|
+
return false;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const post = (agent, action) => api(`/api/agents/${encodeURIComponent(agent.id)}/${action}`);
|
|
290
|
+
|
|
291
|
+
// The server says whether this computer has a terminal it can drive. A Codex
|
|
292
|
+
// session's window is known once its tab's title names it.
|
|
293
|
+
// A background run, with `claude -p`, has no window.
|
|
294
|
+
// Other apps' cards say which buttons they have.
|
|
295
|
+
const canFocus = (a) =>
|
|
296
|
+
Boolean(snap?.terminals) && !a.background && Boolean(a.pid) && (a.actions ? a.actions.includes('focus') : !a.kind || a.kind === 'interactive');
|
|
297
|
+
// Codex and OpenCode take Catch up's prompt through their own services, so
|
|
298
|
+
// they don't need the window; Claude's is typed into the window.
|
|
299
|
+
const canCatchUp = (a) => !inVsCode(a) && (a.app === 'codex' || a.app === 'opencode' ? !a.kind || a.kind === 'interactive' : canFocus(a));
|
|
300
|
+
// The app a to-do starts: its own choice, or the one Settings names.
|
|
301
|
+
const todoApp = (t) => t.app || snap?.newSessionApp || 'claude';
|
|
302
|
+
|
|
303
|
+
async function goToWindow(a, button) {
|
|
304
|
+
if (button) button.disabled = true;
|
|
305
|
+
try {
|
|
306
|
+
const r = await post(a, 'focus');
|
|
307
|
+
if (r.terminal && !r.tab) toast(tr("Opened {window}, but couldn't tell which tab is {name}", { window: r.window, name: displayName(a) }), true);
|
|
308
|
+
else if (!r.raised)
|
|
309
|
+
toast(
|
|
310
|
+
r.terminal
|
|
311
|
+
? tr('Found the tab, but Windows kept it in the background. Check the taskbar.')
|
|
312
|
+
: tr('Found {window}, but Windows kept it in the background. Check the taskbar.', { window: r.window }),
|
|
313
|
+
true,
|
|
314
|
+
);
|
|
315
|
+
else toast(r.terminal ? tr('Switched to {name}', { name: displayName(a) }) : tr('Opened {window}', { window: r.window }));
|
|
316
|
+
} catch (err) {
|
|
317
|
+
toast(err.message, true);
|
|
318
|
+
} finally {
|
|
319
|
+
if (button) button.disabled = false;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
async function catchUp(a, button) {
|
|
324
|
+
button.disabled = true;
|
|
325
|
+
try {
|
|
326
|
+
const r = await post(a, 'catch-up');
|
|
327
|
+
// A Codex session's window may not be known, which isn't worth a mention.
|
|
328
|
+
const where = r.raised || (a.app === 'codex' && !a.pid) ? '' : ` ${tr('Its window stayed in the background.')}`;
|
|
329
|
+
const name = displayName(a);
|
|
330
|
+
const asked =
|
|
331
|
+
a.status !== 'busy'
|
|
332
|
+
? tr('Asked {name} to catch you up.', { name })
|
|
333
|
+
: a.app === 'codex'
|
|
334
|
+
? tr('Queued for {name}. It will answer after its current turn.', { name })
|
|
335
|
+
: tr('Queued for {name}. It will answer after its current step.', { name });
|
|
336
|
+
toast(asked + where);
|
|
337
|
+
refresh();
|
|
338
|
+
} catch (err) {
|
|
339
|
+
toast(err.message, true);
|
|
340
|
+
} finally {
|
|
341
|
+
button.disabled = false;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// ---- groups ------------------------------------------------------------------
|
|
346
|
+
|
|
347
|
+
// The server says which group each session and to-do is in, and whether it
|
|
348
|
+
// was put there by hand (`placed`) or is there by its folder.
|
|
349
|
+
const groupDef = (id) => (id && (snap?.groups || []).find((g) => g.id === id)) || null;
|
|
350
|
+
|
|
351
|
+
// The group button on a card. Without a group it reads "No group" and only
|
|
352
|
+
// shows while the card is pointed at or focused.
|
|
353
|
+
function groupChip(x, cwd) {
|
|
354
|
+
const g = groupDef(x.group);
|
|
355
|
+
const title = g
|
|
356
|
+
? x.placed
|
|
357
|
+
? tr('In {group}, put there by hand. Click to change.', { group: g.name })
|
|
358
|
+
: tr('In {group}, by its folder. Click to change.', { group: g.name })
|
|
359
|
+
: x.placed
|
|
360
|
+
? tr('In no group, put there by hand. Click to choose one.')
|
|
361
|
+
: tr('In no group. Click to choose one.');
|
|
362
|
+
return el(
|
|
363
|
+
'button',
|
|
364
|
+
{
|
|
365
|
+
type: 'button',
|
|
366
|
+
class: g ? `group-chip g-${g.color}` : 'group-chip none',
|
|
367
|
+
title,
|
|
368
|
+
'aria-haspopup': 'menu',
|
|
369
|
+
onclick: (e) => openGroupMenu(x, cwd, e.currentTarget),
|
|
370
|
+
},
|
|
371
|
+
el('span', { class: 'dot' }),
|
|
372
|
+
g ? g.name : tr('No group'),
|
|
373
|
+
);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
// The group's name in its colour, where it can't be changed, as in History.
|
|
377
|
+
function groupTag(x) {
|
|
378
|
+
const g = groupDef(x.group);
|
|
379
|
+
return g ? el('span', { class: `group-chip static g-${g.color}`, title: tr('In {group}', { group: g.name }) }, el('span', { class: 'dot' }), g.name) : null;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
async function placeIn(x, group) {
|
|
383
|
+
try {
|
|
384
|
+
await api('/api/groups/place', { id: x.id, group });
|
|
385
|
+
const g = groupDef(group);
|
|
386
|
+
toast(group === 'auto' ? tr('Following its folder again') : g ? tr('Moved to {group}', { group: g.name }) : tr('Moved out of its group'));
|
|
387
|
+
} catch (err) {
|
|
388
|
+
toast(err.message, true);
|
|
389
|
+
}
|
|
390
|
+
refresh();
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
// The next colour no group has yet, so new groups look different.
|
|
394
|
+
function freeColor(groups) {
|
|
395
|
+
const used = new Set(groups.map((g) => g.color));
|
|
396
|
+
return Object.keys(GROUP_COLORS).find((c) => !used.has(c)) || Object.keys(GROUP_COLORS)[groups.length % 8];
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
const baseName = (p) => (p || '').split(/[\\/]/).filter(Boolean).pop() || p || '';
|
|
400
|
+
|
|
401
|
+
// The menu under a card's group button: each group, No group, Follow its
|
|
402
|
+
// folder again (once moved by hand), a new group for the card's folder, and
|
|
403
|
+
// the group settings.
|
|
404
|
+
function openGroupMenu(x, cwd, button) {
|
|
405
|
+
const menu = $('group-menu');
|
|
406
|
+
const groups = snap?.groups || [];
|
|
407
|
+
const close = () => menu.hidePopover();
|
|
408
|
+
const item = (label, checked, onclick, extra = {}) =>
|
|
409
|
+
el('button', { type: 'button', class: 'menu-item', role: checked === null ? 'menuitem' : 'menuitemradio', 'aria-checked': checked === null ? null : String(checked), onclick, ...extra }, label);
|
|
410
|
+
const choose = (group) => () => {
|
|
411
|
+
close();
|
|
412
|
+
placeIn(x, group);
|
|
413
|
+
};
|
|
414
|
+
const name = el('input', { type: 'text', value: baseName(cwd), maxlength: '40', 'aria-label': tr('New group name'), autocomplete: 'off', spellcheck: 'false' });
|
|
415
|
+
const create = async (e) => {
|
|
416
|
+
e.preventDefault();
|
|
417
|
+
const g = { id: crypto.randomUUID(), name: name.value.trim(), color: freeColor(groups), folders: [cwd] };
|
|
418
|
+
if (!g.name) return name.focus();
|
|
419
|
+
try {
|
|
420
|
+
await api('/api/groups', { groups: [...groups, g] });
|
|
421
|
+
// Moved by hand before, it now follows its folder into the new group.
|
|
422
|
+
if (x.placed) await api('/api/groups/place', { id: x.id, group: 'auto' });
|
|
423
|
+
close();
|
|
424
|
+
toast(tr('Made {group} for {folder}', { group: g.name, folder: shortPath(cwd) }));
|
|
425
|
+
} catch (err) {
|
|
426
|
+
toast(err.message, true);
|
|
427
|
+
}
|
|
428
|
+
refresh();
|
|
429
|
+
};
|
|
430
|
+
const items = [
|
|
431
|
+
...groups.map((g) => item([el('span', { class: `dot g-${g.color}` }), g.name], x.group === g.id, choose(g.id))),
|
|
432
|
+
item([el('span', { class: 'dot none' }), tr('No group')], !x.group, choose(null)),
|
|
433
|
+
x.placed ? item(tr('Follow its folder again'), null, choose('auto'), { title: tr('Go back to the group its folder is in') }) : null,
|
|
434
|
+
el('hr'),
|
|
435
|
+
cwd
|
|
436
|
+
? el(
|
|
437
|
+
'form',
|
|
438
|
+
{ class: 'menu-new', onsubmit: create },
|
|
439
|
+
el('label', { text: tr('New group for {folder}', { folder: shortPath(cwd) }) }),
|
|
440
|
+
el('div', { class: 'menu-new-row' }, name, el('button', { type: 'submit', class: 'btn btn-primary' }, tr('Make'))),
|
|
441
|
+
)
|
|
442
|
+
: null,
|
|
443
|
+
item(tr('Edit groups…'), null, () => {
|
|
444
|
+
close();
|
|
445
|
+
openSettings('groups-setting');
|
|
446
|
+
}),
|
|
447
|
+
];
|
|
448
|
+
menu.replaceChildren(...items.filter(Boolean));
|
|
449
|
+
showMenu(menu, button);
|
|
450
|
+
menu.querySelector('[aria-checked="true"]')?.focus();
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
// Opens a menu under the button that opened it, kept on screen.
|
|
454
|
+
function showMenu(menu, button) {
|
|
455
|
+
menu.showPopover();
|
|
456
|
+
const r = button.getBoundingClientRect();
|
|
457
|
+
const w = menu.offsetWidth;
|
|
458
|
+
const h = menu.offsetHeight;
|
|
459
|
+
menu.style.left = `${Math.max(8, Math.min(r.left, innerWidth - w - 8))}px`;
|
|
460
|
+
menu.style.top = `${r.bottom + 4 + h > innerHeight - 8 ? Math.max(8, r.top - h - 4) : r.bottom + 4}px`;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
// The address boxes under Settings → Other apps, and the settings they set.
|
|
464
|
+
const APP_ADDRESSES = [
|
|
465
|
+
['comfy-url', 'comfyUrl'],
|
|
466
|
+
['localai-url', 'localaiUrl'],
|
|
467
|
+
['ollama-url', 'ollamaUrl'],
|
|
468
|
+
['lmstudio-url', 'lmstudioUrl'],
|
|
469
|
+
['llamacpp-url', 'llamacppUrl'],
|
|
470
|
+
];
|
|
471
|
+
|
|
472
|
+
// Codex or the Copilot CLI is installed, so there's an app to choose.
|
|
473
|
+
const otherAppsInstalled = () => Boolean(snap?.codexInstalled || snap?.copilotInstalled);
|
|
474
|
+
|
|
475
|
+
// Only the apps that are installed are offered in a Claude, Codex or Copilot choice.
|
|
476
|
+
function showInstalledChoices(name) {
|
|
477
|
+
for (const r of document.querySelectorAll(`input[name="${name}"]`)) {
|
|
478
|
+
r.closest('label').hidden = (r.value === 'codex' && !snap?.codexInstalled) || (r.value === 'copilot' && !snap?.copilotInstalled);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
// ---- save and close, resume ----------------------------------------------------
|
|
483
|
+
|
|
484
|
+
// The sessions Save and close takes: Claude's, Codex's, OpenCode's and
|
|
485
|
+
// Cursor's in a terminal.
|
|
486
|
+
const closable = (a) =>
|
|
487
|
+
(a.app === 'claude' && !a.background && (!a.kind || a.kind === 'interactive') && (!a.entrypoint || a.entrypoint === 'cli')) ||
|
|
488
|
+
a.app === 'codex' ||
|
|
489
|
+
a.app === 'opencode' ||
|
|
490
|
+
a.app === 'cursor' ||
|
|
491
|
+
(a.app === 'copilot' && a.entrypoint === 'cli');
|
|
492
|
+
const isWorking = (a) => a.status === 'busy' || a.status === 'shell';
|
|
493
|
+
|
|
494
|
+
function openSessionsMenu(button) {
|
|
495
|
+
const menu = $('sessions-menu');
|
|
496
|
+
const open = (snap?.agents || []).filter(closable);
|
|
497
|
+
const last = snap?.saved;
|
|
498
|
+
const item = (label, onclick, disabled) => el('button', { type: 'button', class: 'menu-item', role: 'menuitem', disabled: disabled || null, onclick }, label);
|
|
499
|
+
menu.replaceChildren(
|
|
500
|
+
item(open.length ? tr('Save and close all ({n})', { n: open.length }) : tr('No sessions to close'), () => (menu.hidePopover(), confirmSaveClose()), !open.length),
|
|
501
|
+
last?.count
|
|
502
|
+
? item(
|
|
503
|
+
[
|
|
504
|
+
el('span', { text: tr('Resume last session') }),
|
|
505
|
+
el('span', { class: 'menu-meta', text: tr('{n} · saved {time} ago', { n: last.count, time: dur(now() - last.savedAt) }) }),
|
|
506
|
+
],
|
|
507
|
+
() => (menu.hidePopover(), resumeLast()),
|
|
508
|
+
)
|
|
509
|
+
: item(tr('No saved session to resume'), null, true),
|
|
510
|
+
snap?.closing?.length
|
|
511
|
+
? el('p', { class: 'menu-note', text: trn(snap.closing.length, '{n} will close when its turn ends', '{n} will close when their turns end') })
|
|
512
|
+
: null,
|
|
513
|
+
);
|
|
514
|
+
showMenu(menu, button);
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
function confirmSaveClose() {
|
|
518
|
+
const open = (snap?.agents || []).filter(closable);
|
|
519
|
+
const busy = open.filter(isWorking);
|
|
520
|
+
const left = (snap?.agents || []).filter((a) => !closable(a) && !isItem(a) && !a.background);
|
|
521
|
+
$('save-close-title').textContent = trn(open.length, 'Save and close {n} session?', 'Save and close {n} sessions?');
|
|
522
|
+
$('save-close-list').replaceChildren(
|
|
523
|
+
...open.map((a) => el('li', {}, el('span', { class: 'save-close-name', text: displayName(a) }), el('span', { class: `badge s-${a.status}` }, el('span', { class: 'dot' }), status(a).label))),
|
|
524
|
+
);
|
|
525
|
+
$('save-close-busy').hidden = !busy.length;
|
|
526
|
+
$('save-close-busy-text').textContent = trn(busy.length, '{n} is still working:', '{n} are still working:');
|
|
527
|
+
$('save-close-left').hidden = !left.length;
|
|
528
|
+
$('save-close-left').textContent = left.length ? trn(left.length, '{n} in VS Code or another app stays open.', '{n} in VS Code or another app stay open.') : '';
|
|
529
|
+
const dialog = $('save-close');
|
|
530
|
+
dialog.returnValue = '';
|
|
531
|
+
dialog.onclose = async () => {
|
|
532
|
+
if (dialog.returnValue !== 'save') return;
|
|
533
|
+
const wait = busy.length > 0 && document.querySelector('input[name="save-close-busy"]:checked')?.value === 'wait';
|
|
534
|
+
try {
|
|
535
|
+
const r = await api('/api/sessions/save-close', { wait });
|
|
536
|
+
const parts = [tr('Saved {saved}, closed {closed}', { saved: r.saved, closed: r.closed })];
|
|
537
|
+
if (r.waiting) parts.push(tr('{n} closing when done', { n: r.waiting }));
|
|
538
|
+
if (r.failed.length) parts.push(tr("couldn't close {list}", { list: r.failed.map((f) => `${f.name} (${tr(f.error)})`).join(', ') }));
|
|
539
|
+
toast(parts.join('. '), r.failed.length > 0);
|
|
540
|
+
} catch (err) {
|
|
541
|
+
toast(err.message, true);
|
|
542
|
+
}
|
|
543
|
+
refresh();
|
|
544
|
+
};
|
|
545
|
+
dialog.showModal();
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
async function resumeLast() {
|
|
549
|
+
try {
|
|
550
|
+
const r = await api('/api/sessions/resume-last');
|
|
551
|
+
const skipped = r.skipped.length ? `. ${tr('Skipped {list}', { list: r.skipped.map((s) => `${s.name || tr('one')} (${tr(s.why)})`).join(', ') })}` : '';
|
|
552
|
+
toast(trn(r.opened, 'Opening {n} session', 'Opening {n} sessions') + skipped, r.skipped.length > 0 && !r.opened);
|
|
553
|
+
} catch (err) {
|
|
554
|
+
toast(err.message, true);
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
async function keepOpen(a) {
|
|
559
|
+
try {
|
|
560
|
+
await api('/api/sessions/keep-open', { id: a.id });
|
|
561
|
+
toast(tr('{name} stays open', { name: displayName(a) }));
|
|
562
|
+
} catch (err) {
|
|
563
|
+
toast(err.message, true);
|
|
564
|
+
}
|
|
565
|
+
refresh();
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
$('sessions-button').addEventListener('click', (e) => openSessionsMenu(e.currentTarget));
|
|
569
|
+
|
|
570
|
+
// ---- card ------------------------------------------------------------------
|
|
571
|
+
|
|
572
|
+
// Text cut to two lines that a click expands. `id` remembers it across updates.
|
|
573
|
+
function expandable(id, text) {
|
|
574
|
+
return el('p', {
|
|
575
|
+
class: 'text',
|
|
576
|
+
text,
|
|
577
|
+
tabindex: '0',
|
|
578
|
+
title: tr('Click to expand'),
|
|
579
|
+
onclick: (e) => {
|
|
580
|
+
const box = e.currentTarget.parentElement;
|
|
581
|
+
box.classList.toggle('expanded');
|
|
582
|
+
if (box.classList.contains('expanded')) expanded.add(id);
|
|
583
|
+
else expanded.delete(id);
|
|
584
|
+
},
|
|
585
|
+
onkeydown: (e) => (e.key === 'Enter' || e.key === ' ') && (e.preventDefault(), e.currentTarget.click()),
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
function message(a, key, label, m, cls) {
|
|
590
|
+
const id = `${a.id}:${key}`;
|
|
591
|
+
return el(
|
|
592
|
+
'div',
|
|
593
|
+
{ class: `msg ${cls || ''}${expanded.has(id) ? ' expanded' : ''}` },
|
|
594
|
+
el('span', { class: 'label' }, m.at ? [`${label} · `, since(m.at, true)] : label),
|
|
595
|
+
expandable(id, m.text),
|
|
596
|
+
);
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
// On a session started from a to-do: the to-do, and a way to copy it into Claude.
|
|
600
|
+
function todoNote(a) {
|
|
601
|
+
const t = a.todo;
|
|
602
|
+
if (!t) return null;
|
|
603
|
+
const id = `${a.id}:todo`;
|
|
604
|
+
return el(
|
|
605
|
+
'div',
|
|
606
|
+
{ class: `msg todo-text todo-msg${expanded.has(id) ? ' expanded' : ''}` },
|
|
607
|
+
el(
|
|
608
|
+
'div',
|
|
609
|
+
{ class: 'todo-msg-head' },
|
|
610
|
+
el('span', { class: 'label', text: tr('To-do') }),
|
|
611
|
+
el('b', { class: 'todo-msg-title', text: t.title, title: t.title }),
|
|
612
|
+
el('button', { type: 'button', class: 'link-btn', title: tr('Copy the title and notes, to paste into Claude'), onclick: () => copyTodo(t) }, tr('Copy')),
|
|
613
|
+
),
|
|
614
|
+
t.notes ? expandable(id, t.notes) : null,
|
|
615
|
+
);
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
function nowBlock(a) {
|
|
619
|
+
const rows = [];
|
|
620
|
+
if (a.status === 'waiting') {
|
|
621
|
+
rows.push(el('div', { class: 'now-row' }, el('span', { class: 'what', text: tr('Waiting on you') }), el('span', { class: 'detail', text: tr(a.waitingFor || '') })));
|
|
622
|
+
}
|
|
623
|
+
for (const t of a.tools || []) {
|
|
624
|
+
rows.push(el('div', { class: 'now-row' }, el('span', { class: 'what', text: t.name }), el('span', { class: 'detail', text: t.detail, title: t.detail }), since(t.at)));
|
|
625
|
+
}
|
|
626
|
+
const runningSubs = a.subagents?.running.length || 0;
|
|
627
|
+
if (a.status === 'busy' && !a.tools?.length) {
|
|
628
|
+
const what = runningSubs ? tr('Waiting on subagents') : tr('Thinking');
|
|
629
|
+
const detail = runningSubs ? tr('{n} running', { n: runningSubs }) : '';
|
|
630
|
+
rows.push(el('div', { class: 'now-row' }, el('span', { class: 'what', text: what }), el('span', { class: 'detail', text: detail }), since(a.lastEventAt)));
|
|
631
|
+
}
|
|
632
|
+
if (a.status === 'shell' && !a.tools?.length) {
|
|
633
|
+
rows.push(
|
|
634
|
+
el('div', { class: 'now-row' }, el('span', { class: 'what', text: tr('Background shell') }), el('span', { class: 'detail', text: tr('running while the session waits at the prompt') })),
|
|
635
|
+
);
|
|
636
|
+
}
|
|
637
|
+
if (a.detail) rows.push(el('div', { class: 'now-row' }, el('span', { class: 'detail', text: a.detail })));
|
|
638
|
+
return rows.length ? el('div', { class: `now${a.status === 'waiting' ? ' waiting' : ''}` }, rows) : null;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
function activity(a) {
|
|
642
|
+
const promptAt = ms(a.lastPrompt?.at) || 0;
|
|
643
|
+
const parts = [todoNote(a), nowBlock(a)];
|
|
644
|
+
const replyFresh = a.lastReply && ms(a.lastReply.at) >= promptAt;
|
|
645
|
+
const recapFresh = a.recap && ms(a.recap.at) >= Math.max(promptAt, replyFresh ? ms(a.lastReply.at) : 0);
|
|
646
|
+
if (recapFresh && a.status !== 'busy') parts.push(message(a, 'recap', tr('Recap'), a.recap));
|
|
647
|
+
else if (replyFresh) parts.push(message(a, 'reply', a.status === 'busy' ? tr('Latest update') : tr('Last reply'), a.lastReply));
|
|
648
|
+
if (a.lastPrompt) parts.push(message(a, 'prompt', tr('Last prompt'), a.lastPrompt, 'prompt'));
|
|
649
|
+
return el('div', { class: 'activity' }, parts);
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
function stats(a) {
|
|
653
|
+
const items = [];
|
|
654
|
+
if (a.model) items.push(el('span', { class: 'model', text: modelLabel(a), title: a.model }));
|
|
655
|
+
if (a.contextTokens) {
|
|
656
|
+
const pct = Math.min(100, (a.contextTokens / a.contextLimit) * 100);
|
|
657
|
+
const fill = el('i');
|
|
658
|
+
fill.style.width = `${pct.toFixed(1)}%`;
|
|
659
|
+
items.push(
|
|
660
|
+
el(
|
|
661
|
+
'span',
|
|
662
|
+
{ class: 'ctx', title: tr('Context: {used} of {limit} tokens', { used: a.contextTokens.toLocaleString(lang), limit: a.contextLimit.toLocaleString(lang) }) },
|
|
663
|
+
el('span', { class: `bar${pct > 85 ? ' high' : pct > 60 ? ' mid' : ''}` }, fill),
|
|
664
|
+
tr('{used} / {limit} context', { used: tokens(a.contextTokens), limit: tokens(a.contextLimit) }),
|
|
665
|
+
),
|
|
666
|
+
);
|
|
667
|
+
}
|
|
668
|
+
if (a.outputTokens) items.push(el('span', { title: tr('Output tokens generated this session'), text: tr('{n} out', { n: tokens(a.outputTokens) }) }));
|
|
669
|
+
if (a.prompts) items.push(el('span', { text: trn(a.prompts, '{n} prompt', '{n} prompts') }));
|
|
670
|
+
if (a.compactions) items.push(el('span', { text: trn(a.compactions, '{n} compaction', '{n} compactions') }));
|
|
671
|
+
return items.length ? el('div', { class: 'stats' }, items) : null;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
function subagents(a) {
|
|
675
|
+
const s = a.subagents;
|
|
676
|
+
if (!s || (!s.running.length && !s.finishedTotal)) return null;
|
|
677
|
+
const open = subsOpen.has(a.id) ? subsOpen.get(a.id) : s.running.length > 0;
|
|
678
|
+
const summary = [tr('Subagents · {n} running', { n: s.running.length })];
|
|
679
|
+
if (s.finishedTotal) summary.push(` · ${tr('{n} finished', { n: s.finishedTotal })}`);
|
|
680
|
+
const rows = [
|
|
681
|
+
...s.running.map((sub) => {
|
|
682
|
+
const tool = sub.tools[sub.tools.length - 1];
|
|
683
|
+
return el(
|
|
684
|
+
'li',
|
|
685
|
+
{ class: 'sub running' },
|
|
686
|
+
el('span', { class: 'dot' }),
|
|
687
|
+
el('span', { class: 'type', text: sub.type }),
|
|
688
|
+
el('span', { class: 'desc', text: sub.description, title: sub.description }),
|
|
689
|
+
since(sub.startedAt),
|
|
690
|
+
el('span', { class: 'tool', text: tool ? `${tool.name} · ${tool.detail}` : sub.lastReply?.text || tr('Thinking…') }),
|
|
691
|
+
);
|
|
692
|
+
}),
|
|
693
|
+
...s.finished.map((sub) =>
|
|
694
|
+
el(
|
|
695
|
+
'li',
|
|
696
|
+
{ class: `sub ${sub.status}`, title: sub.status === 'done' ? tr('Finished') : tr('Ended without finishing') },
|
|
697
|
+
el('span', { class: 'dot' }),
|
|
698
|
+
el('span', { class: 'type', text: sub.type }),
|
|
699
|
+
el('span', { class: 'desc', text: sub.description, title: sub.description }),
|
|
700
|
+
since(sub.updatedAt, true),
|
|
701
|
+
),
|
|
702
|
+
),
|
|
703
|
+
];
|
|
704
|
+
const more = s.finishedTotal - s.finished.length;
|
|
705
|
+
return el(
|
|
706
|
+
'details',
|
|
707
|
+
{
|
|
708
|
+
class: 'subs',
|
|
709
|
+
open,
|
|
710
|
+
ontoggle: (e) => subsOpen.set(a.id, e.currentTarget.open),
|
|
711
|
+
},
|
|
712
|
+
el('summary', {}, summary.join('')),
|
|
713
|
+
el('ul', {}, rows),
|
|
714
|
+
more > 0 ? el('p', { class: 'more', text: tr('and {n} more finished', { n: more }) }) : null,
|
|
715
|
+
);
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
function actions(a) {
|
|
719
|
+
const btn = (label, onclick, cls = '', props = {}) => el('button', { type: 'button', class: `btn ${cls}`, onclick, ...props }, label);
|
|
720
|
+
const waiting = a.status === 'waiting';
|
|
721
|
+
return el(
|
|
722
|
+
'div',
|
|
723
|
+
{ class: 'actions' },
|
|
724
|
+
canFocus(a) ? btn(tr('Go to window'), (e) => goToWindow(a, e.currentTarget), 'btn-primary') : null,
|
|
725
|
+
canCatchUp(a)
|
|
726
|
+
? btn(tr('Catch up'), (e) => catchUp(a, e.currentTarget), 'btn-accent', {
|
|
727
|
+
disabled: waiting,
|
|
728
|
+
title: waiting
|
|
729
|
+
? tr('Waiting on a prompt or dialog. Answer it with Go to window first.')
|
|
730
|
+
: tr('Go to the window and ask where things stand'),
|
|
731
|
+
})
|
|
732
|
+
: null,
|
|
733
|
+
btn(tr('Open folder'), async (e) => {
|
|
734
|
+
const b = e.currentTarget;
|
|
735
|
+
b.disabled = true;
|
|
736
|
+
try {
|
|
737
|
+
await post(a, 'open-folder');
|
|
738
|
+
toast(tr('Opened {folder}', { folder: shortPath(a.cwd) }));
|
|
739
|
+
} catch (err) {
|
|
740
|
+
toast(err.message, true);
|
|
741
|
+
} finally {
|
|
742
|
+
b.disabled = false;
|
|
743
|
+
}
|
|
744
|
+
}),
|
|
745
|
+
btn(tr('Copy resume command'), async () => {
|
|
746
|
+
await copy(resumeCommand(a));
|
|
747
|
+
toast(tr('Resume command copied'));
|
|
748
|
+
}),
|
|
749
|
+
// The two that end the session, together at the end, wrapping together.
|
|
750
|
+
inVsCode(a)
|
|
751
|
+
? null
|
|
752
|
+
: el(
|
|
753
|
+
'span',
|
|
754
|
+
{ class: 'actions-end' },
|
|
755
|
+
closable(a) && !snap?.closing?.includes(a.id)
|
|
756
|
+
? btn(armedLabel(`complete:${a.id}`, tr('Complete')), (e) => completeSession(a, e.currentTarget), armedClass(`complete:${a.id}`), {
|
|
757
|
+
'data-armed': `complete:${a.id}`,
|
|
758
|
+
title: tr('Mark it complete and close it. A working session finishes its turn first.'),
|
|
759
|
+
})
|
|
760
|
+
: null,
|
|
761
|
+
btn(tr('Stop…'), () => confirmStop(a), 'btn-stop'),
|
|
762
|
+
),
|
|
763
|
+
);
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
// Buttons that ask for a second click: Complete, and a job's, model's or
|
|
767
|
+
// download's Stop, Cancel and Unload. The first click is kept for three
|
|
768
|
+
// seconds by what the button does, as `key`, not by the button, since a card
|
|
769
|
+
// is drawn again whenever what it shows changes, which can be every update.
|
|
770
|
+
// A button that may be armed is drawn with armedLabel, armedClass and
|
|
771
|
+
// data-armed set to its key.
|
|
772
|
+
const armed = new Map();
|
|
773
|
+
const isArmed = (key) => (armed.get(key) || 0) > Date.now();
|
|
774
|
+
const armedLabel = (key, label) => (isArmed(key) ? tr('{label}?', { label }) : label);
|
|
775
|
+
const armedClass = (key) => (isArmed(key) ? 'btn-danger' : '');
|
|
776
|
+
|
|
777
|
+
// True on the second click. The first arms the button, and any copy of it
|
|
778
|
+
// drawn in the next three seconds, and says so on it.
|
|
779
|
+
function secondClick(key, button, label) {
|
|
780
|
+
if (isArmed(key)) {
|
|
781
|
+
armed.delete(key);
|
|
782
|
+
return true;
|
|
783
|
+
}
|
|
784
|
+
const until = Date.now() + 3000;
|
|
785
|
+
armed.set(key, until);
|
|
786
|
+
button.classList.add('btn-danger');
|
|
787
|
+
button.textContent = tr('{label}?', { label });
|
|
788
|
+
setTimeout(() => {
|
|
789
|
+
if (armed.get(key) !== until) return;
|
|
790
|
+
armed.delete(key);
|
|
791
|
+
for (const shown of document.querySelectorAll(`[data-armed="${CSS.escape(key)}"]`)) {
|
|
792
|
+
shown.classList.remove('btn-danger');
|
|
793
|
+
shown.textContent = label;
|
|
794
|
+
}
|
|
795
|
+
}, 3000);
|
|
796
|
+
return false;
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
// Complete asks for a second click, like Unload, then closes the session,
|
|
800
|
+
// once its turn ends if it's working. History keeps it, marked complete. A
|
|
801
|
+
// session with tickets opens a dialog instead, to update them first.
|
|
802
|
+
async function completeSession(a, button) {
|
|
803
|
+
if (a.tickets?.length) {
|
|
804
|
+
openCompleteDialog(a);
|
|
805
|
+
return;
|
|
806
|
+
}
|
|
807
|
+
if (!secondClick(`complete:${a.id}`, button, tr('Complete'))) return;
|
|
808
|
+
button.disabled = true;
|
|
809
|
+
if (!(await completeNow(a))) button.disabled = false;
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
async function completeNow(a) {
|
|
813
|
+
try {
|
|
814
|
+
const r = await post(a, 'complete');
|
|
815
|
+
toast(r.waiting ? tr('{name} will close when its turn ends', { name: displayName(a) }) : tr('Completed {name}', { name: displayName(a) }));
|
|
816
|
+
return true;
|
|
817
|
+
} catch (err) {
|
|
818
|
+
toast(err.message, true);
|
|
819
|
+
return false;
|
|
820
|
+
} finally {
|
|
821
|
+
refresh();
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
// ---- completing a session with tickets -----------------------------------------
|
|
826
|
+
|
|
827
|
+
// Each tracker's ticks in the Complete dialog, kept in this browser.
|
|
828
|
+
const TICKS_KEY = 'tabherd:ticket-ticks';
|
|
829
|
+
function savedTicks() {
|
|
830
|
+
try {
|
|
831
|
+
return JSON.parse(localStorage.getItem(TICKS_KEY)) || {};
|
|
832
|
+
} catch {
|
|
833
|
+
return {};
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
function keepTicks(rows) {
|
|
837
|
+
const all = savedTicks();
|
|
838
|
+
for (const r of rows) all[r.t.tracker] = { comment: r.comment.checked, move: r.move.checked, publicReply: Boolean(r.pub?.checked) };
|
|
839
|
+
try {
|
|
840
|
+
localStorage.setItem(TICKS_KEY, JSON.stringify(all));
|
|
841
|
+
} catch {}
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
// The comment a ticket is offered: the session that did the work, what it
|
|
845
|
+
// said last, and its pull requests. It goes to the ticket as written, so
|
|
846
|
+
// it's in English, and can be changed before it's posted.
|
|
847
|
+
const APP_NAMES = { claude: 'Claude Code', codex: 'Codex', copilot: 'GitHub Copilot', opencode: 'OpenCode', cursor: 'Cursor CLI' };
|
|
848
|
+
function doneComment(a) {
|
|
849
|
+
const said = (a.recap?.text || a.lastReply?.text || '').trim();
|
|
850
|
+
const parts = [`Done in a ${APP_NAMES[a.app] || 'coding'} session (${displayName(a)})${said ? `: ${said}` : '.'}`];
|
|
851
|
+
if (a.prs?.length) parts.push(`Pull requests: ${a.prs.map((p) => p.url).join(', ')}`);
|
|
852
|
+
return parts.join('\n\n');
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
let completing = null;
|
|
856
|
+
|
|
857
|
+
// What a ticket's row says about moving it to done.
|
|
858
|
+
function showMoves(row, options) {
|
|
859
|
+
const moves = options?.moves || [];
|
|
860
|
+
row.moveTo.replaceChildren(...moves.map((m) => el('option', { value: m.id, text: m.name })));
|
|
861
|
+
row.moveTo.hidden = moves.length < 2;
|
|
862
|
+
row.move.disabled = !moves.length || row.done.includes('move');
|
|
863
|
+
if (!moves.length) row.move.checked = false;
|
|
864
|
+
const t = row.t;
|
|
865
|
+
let note = '';
|
|
866
|
+
if (options?.error) note = tr("Can't move it: {problem}", { problem: tr(options.error) });
|
|
867
|
+
else if (t.pullRequest) note = tr("A pull request isn't moved from here.");
|
|
868
|
+
else if (t.category === 'done' || t.category === 'closed') note = tr('Already {status}.', { status: t.status });
|
|
869
|
+
else if (!moves.length) note = tr('Its status has no way to done.');
|
|
870
|
+
else if (t.type === 'zendesk') note = tr('To Solved, which emails the requester.');
|
|
871
|
+
else if (t.type === 'github') note = tr('Closes it as completed.');
|
|
872
|
+
else if (moves.length === 1) note = tr('To {status}', { status: moves[0].name });
|
|
873
|
+
row.moveNote.textContent = note;
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
async function openCompleteDialog(a) {
|
|
877
|
+
const ticks = savedTicks();
|
|
878
|
+
const rows = a.tickets.map((t) => {
|
|
879
|
+
const saved = ticks[t.tracker] || {};
|
|
880
|
+
const check = (label, checked) => {
|
|
881
|
+
const box = el('input', { type: 'checkbox' });
|
|
882
|
+
box.checked = Boolean(checked);
|
|
883
|
+
return [box, el('label', { class: 'check' }, box, label)];
|
|
884
|
+
};
|
|
885
|
+
const [comment, commentLabel] = check(tr('Comment'), saved.comment);
|
|
886
|
+
const text = el('textarea', { rows: 4, maxlength: 20000, 'aria-label': tr('Comment') });
|
|
887
|
+
text.value = doneComment(a);
|
|
888
|
+
text.disabled = !comment.checked;
|
|
889
|
+
comment.addEventListener('change', () => (text.disabled = !comment.checked));
|
|
890
|
+
// Zendesk comments are internal notes unless they're a public reply.
|
|
891
|
+
const [pub, pubLabel] = t.type === 'zendesk' ? check(tr('Public reply'), saved.publicReply) : [null, null];
|
|
892
|
+
const [move, moveLabel] = check(tr('Move to done'), saved.move);
|
|
893
|
+
move.disabled = true;
|
|
894
|
+
const moveTo = el('select', { hidden: true, 'aria-label': tr('Move to') });
|
|
895
|
+
const moveNote = el('span', { class: 'complete-note', text: tr('Checking how it can be moved…') });
|
|
896
|
+
const problem = el('p', { class: 'complete-problem', hidden: true });
|
|
897
|
+
const block = el(
|
|
898
|
+
'div',
|
|
899
|
+
{ class: 'complete-ticket' },
|
|
900
|
+
el('div', { class: 'complete-title' }, ticketChip(t), el('span', { class: 'complete-note', text: t.title })),
|
|
901
|
+
el('div', { class: 'checks' }, commentLabel, pubLabel),
|
|
902
|
+
el('div', { class: 'field' }, text),
|
|
903
|
+
pub ? el('p', { class: 'settings-help', text: tr("Without Public reply, it's an internal note. A public reply emails the requester.") }) : null,
|
|
904
|
+
el('div', { class: 'checks' }, moveLabel, moveTo, moveNote),
|
|
905
|
+
problem,
|
|
906
|
+
);
|
|
907
|
+
return { t, comment, text, pub, move, moveTo, moveNote, problem, block, done: [] };
|
|
908
|
+
});
|
|
909
|
+
completing = { a, rows };
|
|
910
|
+
$('complete-name').textContent = displayName(a);
|
|
911
|
+
$('complete-tickets').replaceChildren(...rows.map((r) => r.block));
|
|
912
|
+
$('complete-anyway').hidden = true;
|
|
913
|
+
$('complete-save').disabled = false;
|
|
914
|
+
$('complete-dialog').showModal();
|
|
915
|
+
try {
|
|
916
|
+
const r = await api('/api/tickets/done-options', { id: a.id });
|
|
917
|
+
for (const row of rows) showMoves(row, r.tickets.find((x) => x.chip === row.t.id));
|
|
918
|
+
} catch (err) {
|
|
919
|
+
for (const row of rows) showMoves(row, { moves: [], error: err.message });
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
// Posts what's ticked to the tickets, then completes the session. If any
|
|
924
|
+
// fails, the dialog stays, saying why, with Complete anyway. What was posted
|
|
925
|
+
// isn't posted again.
|
|
926
|
+
$('complete-form').addEventListener('submit', async (e) => {
|
|
927
|
+
e.preventDefault();
|
|
928
|
+
const { a, rows } = completing;
|
|
929
|
+
const save = $('complete-save');
|
|
930
|
+
save.disabled = true;
|
|
931
|
+
try {
|
|
932
|
+
keepTicks(rows);
|
|
933
|
+
const writes = rows
|
|
934
|
+
.map((r) => ({
|
|
935
|
+
chip: r.t.id,
|
|
936
|
+
comment: r.comment.checked && !r.done.includes('comment') ? r.text.value : null,
|
|
937
|
+
publicReply: Boolean(r.pub?.checked),
|
|
938
|
+
move: r.move.checked && !r.move.disabled && !r.done.includes('move') ? r.moveTo.value || null : null,
|
|
939
|
+
}))
|
|
940
|
+
.filter((w) => w.comment || w.move);
|
|
941
|
+
let failed = false;
|
|
942
|
+
if (writes.length) {
|
|
943
|
+
const res = await api('/api/tickets/write', { id: a.id, writes });
|
|
944
|
+
for (const result of res.results) {
|
|
945
|
+
const row = rows.find((r) => r.t.id === result.chip);
|
|
946
|
+
if (!row) continue;
|
|
947
|
+
row.done.push(...result.done);
|
|
948
|
+
if (row.done.includes('comment')) row.comment.disabled = row.text.disabled = true;
|
|
949
|
+
if (row.done.includes('move')) row.move.disabled = true;
|
|
950
|
+
row.problem.hidden = result.ok;
|
|
951
|
+
if (!result.ok) {
|
|
952
|
+
failed = true;
|
|
953
|
+
row.problem.textContent = result.done.includes('comment') ? tr('The comment was posted, but: {problem}', { problem: tr(result.error) }) : tr(result.error);
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
if (failed) {
|
|
958
|
+
$('complete-anyway').hidden = false;
|
|
959
|
+
toast(tr("Some tickets weren't updated. Try again, or complete it anyway."), true);
|
|
960
|
+
return;
|
|
961
|
+
}
|
|
962
|
+
$('complete-dialog').close();
|
|
963
|
+
await completeNow(a);
|
|
964
|
+
} catch (err) {
|
|
965
|
+
toast(err.message, true);
|
|
966
|
+
} finally {
|
|
967
|
+
save.disabled = false;
|
|
968
|
+
}
|
|
969
|
+
});
|
|
970
|
+
$('complete-anyway').addEventListener('click', async () => {
|
|
971
|
+
$('complete-dialog').close();
|
|
972
|
+
await completeNow(completing.a);
|
|
973
|
+
});
|
|
974
|
+
for (const id of ['complete-cancel', 'complete-close']) $(id).addEventListener('click', () => $('complete-dialog').close());
|
|
975
|
+
|
|
976
|
+
// A card for a ComfyUI job, or a LocalAI model, download or chat. The server
|
|
977
|
+
// gives what it shows, `facts` as label and value pairs, and which buttons it
|
|
978
|
+
// has, as `actions`.
|
|
979
|
+
function itemCard(a) {
|
|
980
|
+
const st = status(a);
|
|
981
|
+
const can = (action) => (a.actions || []).includes(action);
|
|
982
|
+
const btn = (label, onclick, cls = '', props = {}) => el('button', { type: 'button', class: `btn ${cls}`, onclick, ...props }, label);
|
|
983
|
+
// Stop, Cancel and Unload, which ask for a second click.
|
|
984
|
+
const twice = (action, label) => {
|
|
985
|
+
const key = `${action}:${a.id}`;
|
|
986
|
+
return btn(armedLabel(key, label), (e) => itemAction(a, action, label, e.currentTarget), `btn-stop ${armedClass(key)}`, { 'data-armed': key });
|
|
987
|
+
};
|
|
988
|
+
const proc = [a.pid && !isItem(a) ? `PID ${a.pid}` : null, a.memBytes ? `${Math.round(a.memBytes / 1048576)} MB` : null].filter(Boolean);
|
|
989
|
+
const pct = a.progress ? Math.max(0, Math.min(100, (a.progress.value / (a.progress.max || 100)) * 100)) : null;
|
|
990
|
+
const fill = el('i');
|
|
991
|
+
if (pct !== null) fill.style.width = `${pct.toFixed(1)}%`;
|
|
992
|
+
return el(
|
|
993
|
+
'article',
|
|
994
|
+
{ class: `card item s-${a.status}`, 'data-id': a.id },
|
|
995
|
+
el(
|
|
996
|
+
'div',
|
|
997
|
+
{ class: 'card-head' },
|
|
998
|
+
el('span', { class: `badge s-${a.status}`, title: st.hint }, el('span', { class: 'dot' }), a.statusLabel ? tr(a.statusLabel) : st.label),
|
|
999
|
+
since(a.statusSince),
|
|
1000
|
+
el('span', { class: 'spacer' }),
|
|
1001
|
+
appTag(a),
|
|
1002
|
+
proc.length ? el('span', { class: 'proc', text: proc.join(' · ') }) : null,
|
|
1003
|
+
),
|
|
1004
|
+
el(
|
|
1005
|
+
'h2',
|
|
1006
|
+
{ class: 'name' },
|
|
1007
|
+
canFocus(a) ? el('button', { type: 'button', class: 'name-link', title: tr('Go to its window'), onclick: (e) => goToWindow(a, e.currentTarget) }, tr(a.name)) : tr(a.name),
|
|
1008
|
+
),
|
|
1009
|
+
a.host || a.where ? el('div', { class: 'where' }, el('span', { class: 'path', text: [a.host, a.where].filter(Boolean).join(' · ') })) : null,
|
|
1010
|
+
el(
|
|
1011
|
+
'div',
|
|
1012
|
+
{ class: 'card-body' },
|
|
1013
|
+
a.status === 'waiting' && a.waitingFor
|
|
1014
|
+
? el('div', { class: 'now waiting' }, el('div', { class: 'now-row' }, el('span', { class: 'detail', text: tr(a.waitingFor), title: tr(a.waitingFor) })))
|
|
1015
|
+
: null,
|
|
1016
|
+
pct !== null
|
|
1017
|
+
? el('div', { class: 'progress', title: `${Math.round(pct)}%` }, el('span', { class: 'bar' }, fill), el('span', { text: `${Math.round(pct)}%` }))
|
|
1018
|
+
: null,
|
|
1019
|
+
a.preview ? el('img', { class: 'preview', src: a.preview, alt: tr('Output of {name}', { name: tr(a.name) }), loading: 'lazy' }) : null,
|
|
1020
|
+
a.facts?.length ? el('dl', { class: 'facts' }, a.facts.flatMap(([k, v]) => [el('dt', { text: tr(k) }), el('dd', { text: tr(v), title: tr(v) })])) : null,
|
|
1021
|
+
a.lastReply ? message(a, 'reply', tr('Last reply'), a.lastReply) : null,
|
|
1022
|
+
),
|
|
1023
|
+
el(
|
|
1024
|
+
'div',
|
|
1025
|
+
{ class: 'actions' },
|
|
1026
|
+
canFocus(a) ? btn(tr('Go to window'), (e) => goToWindow(a, e.currentTarget), 'btn-primary') : null,
|
|
1027
|
+
can('open') && a.url
|
|
1028
|
+
? el('a', { class: 'btn btn-primary', href: a.url, target: '_blank', rel: 'noopener noreferrer' }, a.openLabel ? tr(a.openLabel) : tr('Open in {app}', { app: APPS[a.app] }))
|
|
1029
|
+
: null,
|
|
1030
|
+
can('stop') ? twice('stop', tr('Stop')) : null,
|
|
1031
|
+
can('cancel') ? twice('cancel', tr('Cancel')) : null,
|
|
1032
|
+
can('unload') ? twice('unload', tr('Unload')) : null,
|
|
1033
|
+
can('dismiss') ? btn(tr('Clear'), (e) => clearItem(a, e.currentTarget), '', { title: tr('Take this off the dashboard') }) : null,
|
|
1034
|
+
),
|
|
1035
|
+
);
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
const ITEM_DONE = { stop: tr('Stopped {name}'), cancel: tr('Cancelled {name}'), unload: tr('Unloaded {name}') };
|
|
1039
|
+
|
|
1040
|
+
// A failed job, chat or download, off the dashboard. No second click: it has
|
|
1041
|
+
// already ended.
|
|
1042
|
+
async function clearItem(a, button) {
|
|
1043
|
+
button.disabled = true;
|
|
1044
|
+
try {
|
|
1045
|
+
await post(a, 'dismiss');
|
|
1046
|
+
} catch (err) {
|
|
1047
|
+
toast(err.message, true);
|
|
1048
|
+
button.disabled = false;
|
|
1049
|
+
}
|
|
1050
|
+
refresh();
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
// Stop, Cancel and Unload ask for a second click, like a to-do's Delete.
|
|
1054
|
+
async function itemAction(a, action, label, button) {
|
|
1055
|
+
if (!secondClick(`${action}:${a.id}`, button, label)) return;
|
|
1056
|
+
button.disabled = true;
|
|
1057
|
+
try {
|
|
1058
|
+
if (a.leavesWhenDone) stoppedHere.add(a.id);
|
|
1059
|
+
const result = await post(a, action);
|
|
1060
|
+
// ComfyUI's Unload frees all its models, and says so.
|
|
1061
|
+
toast(result?.done ? tr(result.done) : fillIn(ITEM_DONE[action], { name: tr(a.name) }));
|
|
1062
|
+
} catch (err) {
|
|
1063
|
+
toast(err.message, true);
|
|
1064
|
+
} finally {
|
|
1065
|
+
button.disabled = false;
|
|
1066
|
+
}
|
|
1067
|
+
refresh();
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
function card(a) {
|
|
1071
|
+
if (isItem(a)) return itemCard(a);
|
|
1072
|
+
const st = status(a);
|
|
1073
|
+
const tags = [];
|
|
1074
|
+
if (a.gitBranch) tags.push(el('span', { class: 'tag branch', title: tr('Git branch'), text: `⎇ ${a.gitBranch}` }));
|
|
1075
|
+
if (a.kind && a.kind !== 'interactive') tags.push(el('span', { class: 'tag', text: a.kind }));
|
|
1076
|
+
if (snap?.closing?.includes(a.id)) {
|
|
1077
|
+
tags.push(
|
|
1078
|
+
a.completedAt
|
|
1079
|
+
? el(
|
|
1080
|
+
'button',
|
|
1081
|
+
{ type: 'button', class: 'tag closing', title: tr('Marked complete: it closes when this turn ends. Click to keep it open.'), onclick: () => keepOpen(a) },
|
|
1082
|
+
`${tr('Completes when done')} ✕`,
|
|
1083
|
+
)
|
|
1084
|
+
: el(
|
|
1085
|
+
'button',
|
|
1086
|
+
{ type: 'button', class: 'tag closing', title: tr('Save and close will close it when this turn ends. Click to keep it open.'), onclick: () => keepOpen(a) },
|
|
1087
|
+
`${tr('Closes when done')} ✕`,
|
|
1088
|
+
),
|
|
1089
|
+
);
|
|
1090
|
+
}
|
|
1091
|
+
if (a.background) {
|
|
1092
|
+
tags.push(el('span', { class: 'tag background', title: tr('Running in the background ({how}), with no window', { how: a.entrypoint }), text: tr('Background') }));
|
|
1093
|
+
}
|
|
1094
|
+
else if (a.entrypoint && a.entrypoint !== 'cli') tags.push(el('span', { class: 'tag', text: a.entrypoint }));
|
|
1095
|
+
const perm = PERMISSION_MODES[a.permissionMode];
|
|
1096
|
+
if (perm) tags.push(el('span', { class: 'tag', title: tr('Permission mode: {mode}', { mode: a.permissionMode }), text: perm }));
|
|
1097
|
+
if (a.version) tags.push(el('span', { text: `v${a.version}` }));
|
|
1098
|
+
|
|
1099
|
+
const heading = displayName(a);
|
|
1100
|
+
const subtitle = a.title && a.title.toLowerCase() !== heading.toLowerCase() ? a.title : null;
|
|
1101
|
+
// Claude's session name, when the heading is the tab's title; Codex and Copilot head their cards with their session's name.
|
|
1102
|
+
const proc = a.app === 'claude' ? [a.name] : [];
|
|
1103
|
+
if (a.pid) proc.push(`PID ${a.pid}`);
|
|
1104
|
+
if (a.memBytes) proc.push(`${Math.round(a.memBytes / 1048576)} MB`);
|
|
1105
|
+
|
|
1106
|
+
const g = groupDef(a.group);
|
|
1107
|
+
return el(
|
|
1108
|
+
'article',
|
|
1109
|
+
{ class: `card s-${a.status}${g ? ` grouped g-${g.color}` : ''}`, 'data-id': a.id },
|
|
1110
|
+
el(
|
|
1111
|
+
'div',
|
|
1112
|
+
{ class: 'card-head' },
|
|
1113
|
+
el('span', { class: `badge s-${a.status}`, title: st.hint }, el('span', { class: 'dot' }), st.label),
|
|
1114
|
+
since(a.statusSince),
|
|
1115
|
+
el('span', { class: 'spacer' }),
|
|
1116
|
+
groupChip(a, a.cwd),
|
|
1117
|
+
appTag(a),
|
|
1118
|
+
el('span', { class: 'proc', title: tr('Session {id}\nStarted {time}', { id: a.id, time: new Date(a.startedAt).toLocaleString(lang) }), text: proc.join(' · ') }),
|
|
1119
|
+
),
|
|
1120
|
+
el(
|
|
1121
|
+
'h2',
|
|
1122
|
+
{ class: 'name' },
|
|
1123
|
+
canFocus(a)
|
|
1124
|
+
? el('button', { type: 'button', class: 'name-link', title: tr('Go to this session’s window'), onclick: (e) => goToWindow(a, e.currentTarget) }, heading)
|
|
1125
|
+
: heading,
|
|
1126
|
+
),
|
|
1127
|
+
subtitle ? el('p', { class: 'title', text: subtitle }) : null,
|
|
1128
|
+
el('div', { class: 'where' }, el('span', { class: 'path', title: a.cwd, text: shortPath(a.cwd) }), tags),
|
|
1129
|
+
ticketRow(a.tickets, { add: () => openTicketDialog(a), remove: (t) => removeTicket(a, t) }),
|
|
1130
|
+
// The part that scrolls when every card is the same size.
|
|
1131
|
+
el(
|
|
1132
|
+
'div',
|
|
1133
|
+
{ class: 'card-body' },
|
|
1134
|
+
activity(a),
|
|
1135
|
+
stats(a),
|
|
1136
|
+
subagents(a),
|
|
1137
|
+
a.prs?.length
|
|
1138
|
+
? el(
|
|
1139
|
+
'div',
|
|
1140
|
+
{ class: 'prs' },
|
|
1141
|
+
a.prs.map((pr) => el('a', { href: pr.url, target: '_blank', rel: 'noopener noreferrer', text: `${pr.repo || 'PR'}#${pr.number}` })),
|
|
1142
|
+
)
|
|
1143
|
+
: null,
|
|
1144
|
+
),
|
|
1145
|
+
actions(a),
|
|
1146
|
+
);
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
// ---- tickets -------------------------------------------------------------------
|
|
1150
|
+
|
|
1151
|
+
// A ticket's key as its chip shows it: a GitHub issue by its repository's
|
|
1152
|
+
// name and number, without its owner.
|
|
1153
|
+
const ticketKey = (t) => (t.type === 'github' ? t.key.replace(/^[^/]+\//, '') : t.key);
|
|
1154
|
+
|
|
1155
|
+
// A ticket's chip: its key and status, with a dot in its status group's
|
|
1156
|
+
// colour, opening the ticket. Its title, assignee and tracker show on hover.
|
|
1157
|
+
function ticketChip(t, remove) {
|
|
1158
|
+
const tip = [t.title, t.assignee ? tr('Assigned to {name}', { name: t.assignee }) : null, t.trackerName].filter(Boolean).join('\n');
|
|
1159
|
+
const label = [el('span', { class: 'ticket-dot' }), `${ticketKey(t)} · ${t.status}`];
|
|
1160
|
+
return el(
|
|
1161
|
+
'span',
|
|
1162
|
+
{ class: `ticket t-${t.category}` },
|
|
1163
|
+
t.url ? el('a', { href: t.url, target: '_blank', rel: 'noopener noreferrer', title: tip }, label) : el('span', { title: tip }, label),
|
|
1164
|
+
remove ? el('button', { type: 'button', class: 'ticket-x', title: tr('Take {key} off this card', { key: ticketKey(t) }), 'aria-label': tr('Take {key} off this card', { key: ticketKey(t) }), onclick: () => remove(t) }, '✕') : null,
|
|
1165
|
+
);
|
|
1166
|
+
}
|
|
1167
|
+
|
|
1168
|
+
// A card's tickets, under its folder, then + Ticket to link one by hand,
|
|
1169
|
+
// once there's a tracker in Settings → Tickets.
|
|
1170
|
+
function ticketRow(list, { add, remove } = {}) {
|
|
1171
|
+
const adding = Boolean(add && snap?.trackerCount);
|
|
1172
|
+
if (!list?.length && !adding) return null;
|
|
1173
|
+
return el(
|
|
1174
|
+
'div',
|
|
1175
|
+
{ class: 'tickets' },
|
|
1176
|
+
(list || []).map((t) => ticketChip(t, remove)),
|
|
1177
|
+
adding ? el('button', { type: 'button', class: 'ticket ticket-add', title: tr('Link a ticket to this session'), onclick: add }, tr('+ Ticket')) : null,
|
|
1178
|
+
);
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
let ticketFor = null;
|
|
1182
|
+
|
|
1183
|
+
function openTicketDialog(a) {
|
|
1184
|
+
ticketFor = a;
|
|
1185
|
+
$('ticket-name').textContent = displayName(a);
|
|
1186
|
+
$('ticket-text').value = '';
|
|
1187
|
+
$('ticket-dialog').showModal();
|
|
1188
|
+
$('ticket-text').focus();
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
$('ticket-form').addEventListener('submit', async (e) => {
|
|
1192
|
+
e.preventDefault();
|
|
1193
|
+
const a = ticketFor;
|
|
1194
|
+
const button = $('ticket-save');
|
|
1195
|
+
button.disabled = true;
|
|
1196
|
+
try {
|
|
1197
|
+
const r = await api('/api/tickets/add', { id: a.id, text: $('ticket-text').value });
|
|
1198
|
+
const said = [];
|
|
1199
|
+
if (r.linked.length) said.push(tr('Linked {keys}.', { keys: r.linked.join(', ') }));
|
|
1200
|
+
if (r.unsure.length) said.push(tr("{keys}: its tracker didn't answer, so it's linked once it does.", { keys: r.unsure.join(', ') }));
|
|
1201
|
+
if (r.notFound.length) said.push(tr('{keys}: not found in your trackers.', { keys: r.notFound.join(', ') }));
|
|
1202
|
+
toast(said.join(' '), !r.linked.length && !r.unsure.length);
|
|
1203
|
+
if (r.linked.length || r.unsure.length) $('ticket-dialog').close();
|
|
1204
|
+
refresh();
|
|
1205
|
+
} catch (err) {
|
|
1206
|
+
toast(err.message, true);
|
|
1207
|
+
} finally {
|
|
1208
|
+
button.disabled = false;
|
|
1209
|
+
}
|
|
1210
|
+
});
|
|
1211
|
+
for (const id of ['ticket-cancel', 'ticket-close']) $(id).addEventListener('click', () => $('ticket-dialog').close());
|
|
1212
|
+
|
|
1213
|
+
// Takes a ticket off a session's card. It stays off, unless it's linked
|
|
1214
|
+
// again with + Ticket.
|
|
1215
|
+
async function removeTicket(a, t) {
|
|
1216
|
+
try {
|
|
1217
|
+
await api('/api/tickets/remove', { id: a.id, chip: t.id });
|
|
1218
|
+
toast(tr('{key} taken off. Link it again with + Ticket.', { key: ticketKey(t) }));
|
|
1219
|
+
refresh();
|
|
1220
|
+
} catch (err) {
|
|
1221
|
+
toast(err.message, true);
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
// A to-do's tickets as its Tickets field shows them: one from a link, as
|
|
1226
|
+
// that link again.
|
|
1227
|
+
function refText(r) {
|
|
1228
|
+
const host = r.hint?.startsWith('host:') ? r.hint.slice(5) : null;
|
|
1229
|
+
if (host) return r.key.startsWith('#') ? `https://${host}/agent/tickets/${r.key.slice(1)}` : `https://${host}/browse/${r.key}`;
|
|
1230
|
+
return r.hint ? `${r.hint} ${r.key}` : r.key;
|
|
1231
|
+
}
|
|
1232
|
+
const refsText = (list) => (list || []).map(refText).join(', ');
|
|
1233
|
+
|
|
1234
|
+
// ---- to-dos --------------------------------------------------------------------
|
|
1235
|
+
|
|
1236
|
+
// A to-do has its own card until its session starts, then it's on the
|
|
1237
|
+
// session's card. Card IDs get this prefix so they can't meet a session's.
|
|
1238
|
+
const TODO_PREFIX = 'todo:';
|
|
1239
|
+
let editingTodo = null;
|
|
1240
|
+
|
|
1241
|
+
const todoText = (t) => (t.notes ? `${t.title}\n\n${t.notes}` : t.title);
|
|
1242
|
+
|
|
1243
|
+
async function copyTodo(t) {
|
|
1244
|
+
await copy(todoText(t));
|
|
1245
|
+
toast(tr('To-do copied'));
|
|
1246
|
+
}
|
|
1247
|
+
|
|
1248
|
+
function editTodo(t) {
|
|
1249
|
+
editingTodo = t;
|
|
1250
|
+
$('todo-dialog-title').textContent = t ? tr('Edit to-do') : tr('New to-do');
|
|
1251
|
+
$('todo-save').textContent = t ? tr('Save') : tr('Add to-do');
|
|
1252
|
+
$('todo-title').value = t?.title || '';
|
|
1253
|
+
// A new one can be filled in from a ticket.
|
|
1254
|
+
$('todo-title').placeholder = !t && snap?.trackerCount ? tr('Or paste a ticket link or key') : '';
|
|
1255
|
+
ticketLookup++;
|
|
1256
|
+
todoTicketNote('');
|
|
1257
|
+
$('todo-notes').value = t?.notes || '';
|
|
1258
|
+
// Which app it starts in, once Codex is installed too.
|
|
1259
|
+
$('todo-app-field').hidden = !otherAppsInstalled();
|
|
1260
|
+
$('todo-app').querySelector('option[value="codex"]').hidden = !snap?.codexInstalled;
|
|
1261
|
+
$('todo-app').querySelector('option[value="copilot"]').hidden = !snap?.copilotInstalled;
|
|
1262
|
+
$('todo-app-default').textContent = tr('As in Settings ({app})', { app: APPS[snap?.newSessionApp] || APPS.claude });
|
|
1263
|
+
$('todo-app').value = t?.app || '';
|
|
1264
|
+
// Its tickets, once there's a tracker to look them up in.
|
|
1265
|
+
$('todo-tickets-field').hidden = !snap?.trackerCount && !t?.ticketRefs?.length;
|
|
1266
|
+
$('todo-tickets').value = refsText(t?.ticketRefs);
|
|
1267
|
+
$('todo-dialog').showModal();
|
|
1268
|
+
$('todo-title').focus();
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
// A to-do with no folder starts in the one Settings names, where Claude or
|
|
1272
|
+
// Codex can make a new project.
|
|
1273
|
+
async function startTodo(t, button) {
|
|
1274
|
+
if (button) button.disabled = true;
|
|
1275
|
+
try {
|
|
1276
|
+
await api(`/api/todos/${t.id}/start`);
|
|
1277
|
+
toast(tr('Starting {app} in {folder}', { app: APPS[todoApp(t)], folder: shortPath(t.cwd || snap?.todoStartsIn || '') }));
|
|
1278
|
+
} catch (err) {
|
|
1279
|
+
toast(err.message, true);
|
|
1280
|
+
} finally {
|
|
1281
|
+
if (button) button.disabled = false;
|
|
1282
|
+
}
|
|
1283
|
+
refresh();
|
|
1284
|
+
}
|
|
1285
|
+
|
|
1286
|
+
// From the repo menu or the folder picker, as Settings says. With
|
|
1287
|
+
// `start`, Claude starts there once it's chosen.
|
|
1288
|
+
async function chooseTodoFolder(t, start, button) {
|
|
1289
|
+
if (serverSettings?.todoFolderSource !== 'picker') {
|
|
1290
|
+
openRepoPicker(t, start);
|
|
1291
|
+
return;
|
|
1292
|
+
}
|
|
1293
|
+
const label = button.textContent;
|
|
1294
|
+
button.disabled = true;
|
|
1295
|
+
button.textContent = tr('Choosing…');
|
|
1296
|
+
try {
|
|
1297
|
+
const r = await api(`/api/todos/${t.id}/folder`, { pick: true });
|
|
1298
|
+
if (r.cancelled) return;
|
|
1299
|
+
if (start) await startTodo({ ...t, cwd: r.cwd });
|
|
1300
|
+
else refresh();
|
|
1301
|
+
} catch (err) {
|
|
1302
|
+
toast(err.message, true);
|
|
1303
|
+
} finally {
|
|
1304
|
+
button.disabled = false;
|
|
1305
|
+
button.textContent = label;
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
// Asks for a second click, so one stray click can't lose the notes.
|
|
1310
|
+
async function deleteTodo(t, button) {
|
|
1311
|
+
if (!button.classList.contains('btn-danger')) {
|
|
1312
|
+
button.classList.add('btn-danger');
|
|
1313
|
+
button.textContent = tr('{label}?', { label: tr('Delete') });
|
|
1314
|
+
setTimeout(() => {
|
|
1315
|
+
button.classList.remove('btn-danger');
|
|
1316
|
+
button.textContent = tr('Delete');
|
|
1317
|
+
}, 3000);
|
|
1318
|
+
return;
|
|
1319
|
+
}
|
|
1320
|
+
button.disabled = true;
|
|
1321
|
+
try {
|
|
1322
|
+
await api(`/api/todos/${t.id}/delete`);
|
|
1323
|
+
refresh();
|
|
1324
|
+
} catch (err) {
|
|
1325
|
+
toast(err.message, true);
|
|
1326
|
+
button.disabled = false;
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1329
|
+
|
|
1330
|
+
function todoCard(t) {
|
|
1331
|
+
const btn = (label, onclick, cls = '', props = {}) => el('button', { type: 'button', class: `btn ${cls}`, onclick, ...props }, label);
|
|
1332
|
+
const drivable = Boolean(snap?.terminals);
|
|
1333
|
+
const startsIn = shortPath(t.cwd || snap?.todoStartsIn || '');
|
|
1334
|
+
// Started, but no session with its ID has turned up.
|
|
1335
|
+
const stalled = t.startedAt && !t.starting;
|
|
1336
|
+
const g = groupDef(t.group);
|
|
1337
|
+
return el(
|
|
1338
|
+
'article',
|
|
1339
|
+
{ class: `card todo-card${g ? ` grouped g-${g.color}` : ''}`, 'data-id': TODO_PREFIX + t.id },
|
|
1340
|
+
el(
|
|
1341
|
+
'div',
|
|
1342
|
+
{ class: 'card-head' },
|
|
1343
|
+
el('span', { class: `badge s-todo${t.starting ? ' starting' : ''}` }, el('span', { class: 'dot' }), t.starting ? tr('Starting') : tr('To-do')),
|
|
1344
|
+
since(t.starting ? t.startedAt : t.createdAt),
|
|
1345
|
+
el('span', { class: 'spacer' }),
|
|
1346
|
+
groupChip(t, t.cwd || snap?.todoStartsIn),
|
|
1347
|
+
// The app it will start, once there's a choice.
|
|
1348
|
+
otherAppsInstalled() ? appTag({ app: todoApp(t) }) : null,
|
|
1349
|
+
),
|
|
1350
|
+
el('h2', { class: 'name', text: t.title }),
|
|
1351
|
+
el(
|
|
1352
|
+
'div',
|
|
1353
|
+
{ class: 'where' },
|
|
1354
|
+
t.cwd
|
|
1355
|
+
? el('span', { class: 'path', title: t.cwd, text: shortPath(t.cwd) })
|
|
1356
|
+
: el('span', { class: 'no-folder', title: tr('No folder chosen: it starts here, where Claude can make a new project'), text: tr('Starts in {folder}', { folder: startsIn }) }),
|
|
1357
|
+
),
|
|
1358
|
+
ticketRow(t.tickets),
|
|
1359
|
+
el(
|
|
1360
|
+
'div',
|
|
1361
|
+
{ class: 'card-body' },
|
|
1362
|
+
el(
|
|
1363
|
+
'div',
|
|
1364
|
+
{ class: 'activity' },
|
|
1365
|
+
t.starting
|
|
1366
|
+
? el(
|
|
1367
|
+
'div',
|
|
1368
|
+
{ class: 'now' },
|
|
1369
|
+
el('div', { class: 'now-row' }, el('span', { class: 'what', text: tr('Opening {app}', { app: APPS[todoApp(t)] }) }), el('span', { class: 'detail', text: tr('in a new terminal tab') })),
|
|
1370
|
+
)
|
|
1371
|
+
: null,
|
|
1372
|
+
stalled
|
|
1373
|
+
? el(
|
|
1374
|
+
'div',
|
|
1375
|
+
{ class: 'now waiting' },
|
|
1376
|
+
el('div', { class: 'now-row' }, el('span', { class: 'what', text: tr('No session yet') }), el('span', { class: 'detail', text: tr('Check its terminal tab, or start it again') })),
|
|
1377
|
+
)
|
|
1378
|
+
: null,
|
|
1379
|
+
t.notes ? message({ id: TODO_PREFIX + t.id }, 'notes', tr('Notes'), { text: t.notes }, 'todo-text') : null,
|
|
1380
|
+
),
|
|
1381
|
+
),
|
|
1382
|
+
el(
|
|
1383
|
+
'div',
|
|
1384
|
+
{ class: 'actions' },
|
|
1385
|
+
drivable
|
|
1386
|
+
? btn(stalled ? tr('Start again') : tr('Start'), (e) => startTodo(t, e.currentTarget), 'btn-primary', {
|
|
1387
|
+
disabled: t.starting,
|
|
1388
|
+
title: tr('Open a terminal tab in {folder} running {app}', { folder: startsIn, app: APPS[todoApp(t)] }),
|
|
1389
|
+
})
|
|
1390
|
+
: null,
|
|
1391
|
+
drivable ? btn(t.cwd ? tr('Change folder') : tr('Choose folder'), (e) => chooseTodoFolder(t, false, e.currentTarget), '', { disabled: t.starting }) : null,
|
|
1392
|
+
btn(tr('Copy'), () => copyTodo(t), '', { title: tr('Copy the title and notes, to paste into Claude') }),
|
|
1393
|
+
btn(tr('Edit'), () => editTodo(t)),
|
|
1394
|
+
btn(tr('Delete'), (e) => deleteTodo(t, e.currentTarget), 'btn-stop'),
|
|
1395
|
+
),
|
|
1396
|
+
);
|
|
1397
|
+
}
|
|
1398
|
+
|
|
1399
|
+
$('todo-new').addEventListener('click', () => editTodo(null));
|
|
1400
|
+
$('todo-form').addEventListener('submit', async (e) => {
|
|
1401
|
+
e.preventDefault();
|
|
1402
|
+
const save = $('todo-save');
|
|
1403
|
+
save.disabled = true;
|
|
1404
|
+
try {
|
|
1405
|
+
const body = { title: $('todo-title').value, notes: $('todo-notes').value, app: $('todo-app').value || null, tickets: $('todo-tickets').value };
|
|
1406
|
+
await api(editingTodo ? `/api/todos/${editingTodo.id}` : '/api/todos', body);
|
|
1407
|
+
$('todo-dialog').close();
|
|
1408
|
+
refresh();
|
|
1409
|
+
} catch (err) {
|
|
1410
|
+
toast(err.message, true);
|
|
1411
|
+
} finally {
|
|
1412
|
+
save.disabled = false;
|
|
1413
|
+
}
|
|
1414
|
+
});
|
|
1415
|
+
// Ctrl+Enter saves from the notes, where Enter is a new line.
|
|
1416
|
+
$('todo-notes').addEventListener('keydown', (e) => {
|
|
1417
|
+
if (e.key === 'Enter' && (e.ctrlKey || e.metaKey)) {
|
|
1418
|
+
e.preventDefault();
|
|
1419
|
+
$('todo-form').requestSubmit();
|
|
1420
|
+
}
|
|
1421
|
+
});
|
|
1422
|
+
for (const id of ['todo-cancel', 'todo-close']) $(id).addEventListener('click', () => $('todo-dialog').close());
|
|
1423
|
+
|
|
1424
|
+
// A ticket's link or key pasted as a new to-do's title fills the to-do in
|
|
1425
|
+
// from the ticket: its title, its description as the notes if they're empty,
|
|
1426
|
+
// and the ticket in Tickets. Only what looks like one is looked up.
|
|
1427
|
+
const LOOKS_LIKE_TICKET = /^(?:https?:\/\/\S*(?:\/browse\/|selectedIssue=|linear\.app\/\S*\/issue\/|github\.com\/\S*\/issues\/|\/agent\/tickets\/)\S*|[A-Za-z][A-Za-z0-9_]*-\d+|[\w.-]+\/[\w.-]+#\d+)$/;
|
|
1428
|
+
// Each lookup's number, so one answered after the title changed, or the
|
|
1429
|
+
// dialog was opened again, is ignored.
|
|
1430
|
+
let ticketLookup = 0;
|
|
1431
|
+
|
|
1432
|
+
// The line under Title: the lookup, what it filled in from, or what went wrong.
|
|
1433
|
+
function todoTicketNote(text, problem = false) {
|
|
1434
|
+
const note = $('todo-from-ticket');
|
|
1435
|
+
note.textContent = text;
|
|
1436
|
+
note.classList.toggle('problem', problem);
|
|
1437
|
+
note.hidden = !text;
|
|
1438
|
+
}
|
|
1439
|
+
|
|
1440
|
+
async function fillTodoFromTicket(pasted) {
|
|
1441
|
+
const asked = ++ticketLookup;
|
|
1442
|
+
todoTicketNote(tr('Looking up the ticket…'));
|
|
1443
|
+
let r;
|
|
1444
|
+
try {
|
|
1445
|
+
r = await api('/api/tickets/describe', { text: pasted });
|
|
1446
|
+
} catch (err) {
|
|
1447
|
+
r = { error: err.message };
|
|
1448
|
+
}
|
|
1449
|
+
// The dialog was opened again, or something else pasted, in the meantime.
|
|
1450
|
+
if (asked !== ticketLookup) return;
|
|
1451
|
+
// Typed over: what was typed stays.
|
|
1452
|
+
if ($('todo-title').value.trim() !== pasted) return todoTicketNote('');
|
|
1453
|
+
if (r.error) return todoTicketNote(r.error, true);
|
|
1454
|
+
if (!r.ticket) return todoTicketNote('');
|
|
1455
|
+
$('todo-title').value = r.ticket.title;
|
|
1456
|
+
if (!$('todo-notes').value.trim()) $('todo-notes').value = r.ticket.description;
|
|
1457
|
+
const field = $('todo-tickets');
|
|
1458
|
+
if (!field.value.includes(pasted)) field.value = field.value.trim() ? `${field.value.trim()}, ${pasted}` : pasted;
|
|
1459
|
+
$('todo-tickets-field').hidden = false;
|
|
1460
|
+
todoTicketNote(tr('Filled in from {key}, in {tracker}.', { key: r.ticket.key, tracker: r.ticket.trackerName }));
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
$('todo-title').addEventListener('input', (e) => {
|
|
1464
|
+
const pasted = $('todo-title').value.trim();
|
|
1465
|
+
if (e.inputType === 'insertFromPaste' && !editingTodo && snap?.trackerCount && LOOKS_LIKE_TICKET.test(pasted)) fillTodoFromTicket(pasted);
|
|
1466
|
+
});
|
|
1467
|
+
|
|
1468
|
+
// ---- page ------------------------------------------------------------------
|
|
1469
|
+
|
|
1470
|
+
// ---- memory and models ----------------------------------------------------------
|
|
1471
|
+
|
|
1472
|
+
// In binary gigabytes, as Task Manager and nvidia-smi count memory.
|
|
1473
|
+
// With the language's decimal point.
|
|
1474
|
+
const oneDecimal = new Intl.NumberFormat(lang, { minimumFractionDigits: 1, maximumFractionDigits: 1 });
|
|
1475
|
+
const gb = (n) => (n >= 2 ** 30 ? `${oneDecimal.format(n / 2 ** 30)} GB` : `${Math.round(n / 2 ** 20)} MB`);
|
|
1476
|
+
|
|
1477
|
+
// A bar for memory in use, of what there is: amber past three quarters, red
|
|
1478
|
+
// past nine tenths.
|
|
1479
|
+
function memoryBar(label, used, total, extra) {
|
|
1480
|
+
const pct = total ? Math.min(100, (used / total) * 100) : 0;
|
|
1481
|
+
const fill = el('i');
|
|
1482
|
+
fill.style.width = `${pct.toFixed(1)}%`;
|
|
1483
|
+
const figure = tr('{used} of {total}', { used: gb(used), total: gb(total) }) + (extra ? ` · ${extra}` : '');
|
|
1484
|
+
return el(
|
|
1485
|
+
'div',
|
|
1486
|
+
{ class: 'mem-row', title: tr('{label}: {figure}, {pct}% used', { label, figure, pct: Math.round(pct) }) },
|
|
1487
|
+
el('span', { class: 'mem-label', text: label }),
|
|
1488
|
+
el('span', { class: `bar${pct > 90 ? ' high' : pct > 75 ? ' mid' : ''}` }, fill),
|
|
1489
|
+
el('span', { class: 'mem-figure', text: figure }),
|
|
1490
|
+
);
|
|
1491
|
+
}
|
|
1492
|
+
|
|
1493
|
+
// What a model takes in memory, for its line on the card. Where all an app
|
|
1494
|
+
// gives is the model's size, it's about what it takes. Where some or all of
|
|
1495
|
+
// it isn't in graphics memory, as Ollama says, how much of it is.
|
|
1496
|
+
function modelMemory(mem) {
|
|
1497
|
+
if (!mem) return el('span', { class: 'mem-model-size' });
|
|
1498
|
+
const size = gb(mem.used);
|
|
1499
|
+
if (mem.about) return el('span', { class: 'mem-model-size', text: `≈ ${size}`, title: tr("{size}, the model's size: about what it takes in memory", { size }) });
|
|
1500
|
+
const known = Number.isFinite(mem.graphics);
|
|
1501
|
+
const split = known && mem.graphics < mem.used;
|
|
1502
|
+
const share = !split ? null : mem.graphics > 0 ? tr('{pct}% GPU', { pct: Math.floor((mem.graphics / mem.used) * 100) }) : tr('CPU only');
|
|
1503
|
+
return el('span', {
|
|
1504
|
+
class: 'mem-model-size',
|
|
1505
|
+
text: [size, share].filter(Boolean).join(' · '),
|
|
1506
|
+
title: !known
|
|
1507
|
+
? tr('{size} in memory', { size })
|
|
1508
|
+
: !split
|
|
1509
|
+
? tr('{size} in graphics memory', { size })
|
|
1510
|
+
: mem.graphics > 0
|
|
1511
|
+
? tr('{size} in memory, {graphics} of it in graphics memory', { size, graphics: gb(mem.graphics) })
|
|
1512
|
+
: tr('{size} in memory, none of it in graphics memory', { size }),
|
|
1513
|
+
});
|
|
1514
|
+
}
|
|
1515
|
+
|
|
1516
|
+
// What a model's line leaves out of its facts, as its memory says it.
|
|
1517
|
+
const MEMORY_FACTS = new Set(['Size', 'Graphics memory', 'Memory']);
|
|
1518
|
+
|
|
1519
|
+
// The list of models can be closed to its count and what they take
|
|
1520
|
+
// together. Open unless closed, kept in this browser.
|
|
1521
|
+
const MODELS_OPEN_KEY = 'tabherd:memory-models';
|
|
1522
|
+
let modelsOpen = true;
|
|
1523
|
+
try {
|
|
1524
|
+
modelsOpen = localStorage.getItem(MODELS_OPEN_KEY) !== 'closed';
|
|
1525
|
+
} catch {}
|
|
1526
|
+
|
|
1527
|
+
// The card at the top: the computer's RAM and each graphics card's memory,
|
|
1528
|
+
// used against what there is, and the models loaded in ComfyUI, LocalAI,
|
|
1529
|
+
// Ollama, LM Studio and llama.cpp, each with what it takes and Unload.
|
|
1530
|
+
function memoryCard({ memory, models }) {
|
|
1531
|
+
const rows = [memoryBar('RAM', memory.ram.used, memory.ram.total)];
|
|
1532
|
+
for (const g of memory.gpus || []) rows.push(memoryBar(g.name, g.used, g.total, Number.isFinite(g.busy) ? tr('{pct}% busy', { pct: g.busy }) : null));
|
|
1533
|
+
const modelRows = models.map((m) =>
|
|
1534
|
+
el(
|
|
1535
|
+
'li',
|
|
1536
|
+
{ class: 'mem-model' },
|
|
1537
|
+
appTag(m),
|
|
1538
|
+
el('span', { class: 'mem-model-name', text: m.name, title: [m.name, m.where].filter(Boolean).join(' · ') }),
|
|
1539
|
+
el('span', {
|
|
1540
|
+
class: 'mem-model-facts',
|
|
1541
|
+
text: (m.facts || [])
|
|
1542
|
+
.filter(([k]) => !(m.memory && MEMORY_FACTS.has(k)))
|
|
1543
|
+
.map(([k, v]) => `${tr(k)} ${tr(v)}`)
|
|
1544
|
+
.join(' · '),
|
|
1545
|
+
}),
|
|
1546
|
+
modelMemory(m.memory),
|
|
1547
|
+
(m.actions || []).includes('unload')
|
|
1548
|
+
? el(
|
|
1549
|
+
'button',
|
|
1550
|
+
{
|
|
1551
|
+
type: 'button',
|
|
1552
|
+
class: `btn btn-stop ${armedClass(`unload:${m.id}`)}`,
|
|
1553
|
+
'data-armed': `unload:${m.id}`,
|
|
1554
|
+
title: m.app === 'comfy' ? tr("Unloads all of {name}'s models: ComfyUI can't unload one alone", { name: m.host }) : null,
|
|
1555
|
+
onclick: (e) => itemAction(m, 'unload', tr('Unload'), e.currentTarget),
|
|
1556
|
+
},
|
|
1557
|
+
armedLabel(`unload:${m.id}`, tr('Unload')),
|
|
1558
|
+
)
|
|
1559
|
+
: null,
|
|
1560
|
+
),
|
|
1561
|
+
);
|
|
1562
|
+
// Together, about what they take if any one's figure is about, or missing.
|
|
1563
|
+
const total = models.reduce((sum, m) => sum + (m.memory?.used || 0), 0);
|
|
1564
|
+
const about = models.some((m) => !m.memory || m.memory.about);
|
|
1565
|
+
const summary = [trn(models.length, '{n} model loaded', '{n} models loaded'), total ? `${about ? '≈ ' : ''}${gb(total)}` : null];
|
|
1566
|
+
return el(
|
|
1567
|
+
'article',
|
|
1568
|
+
{ class: 'card memory-card', 'data-id': 'memory' },
|
|
1569
|
+
el('div', { class: 'card-head' }, el('h2', { class: 'mem-title', text: tr('Memory and models') })),
|
|
1570
|
+
el('div', { class: 'mem-bars' }, rows),
|
|
1571
|
+
modelRows.length
|
|
1572
|
+
? el(
|
|
1573
|
+
'details',
|
|
1574
|
+
{
|
|
1575
|
+
class: 'mem-models-box',
|
|
1576
|
+
open: modelsOpen,
|
|
1577
|
+
ontoggle: (e) => {
|
|
1578
|
+
modelsOpen = e.currentTarget.open;
|
|
1579
|
+
try {
|
|
1580
|
+
localStorage.setItem(MODELS_OPEN_KEY, modelsOpen ? 'open' : 'closed');
|
|
1581
|
+
} catch {}
|
|
1582
|
+
},
|
|
1583
|
+
},
|
|
1584
|
+
el('summary', {}, el('span', { class: 'chev' }), summary.filter(Boolean).join(' · ')),
|
|
1585
|
+
el('ul', { class: 'mem-models' }, modelRows),
|
|
1586
|
+
)
|
|
1587
|
+
: el('p', { class: 'mem-none', text: tr('No models loaded in ComfyUI, LocalAI, Ollama, LM Studio or llama.cpp.') }),
|
|
1588
|
+
);
|
|
1589
|
+
}
|
|
1590
|
+
|
|
1591
|
+
// The card can be turned off in Settings → Appearance, kept in this browser.
|
|
1592
|
+
// Loaded models are on it, or in the grid, each with a card of its own, when
|
|
1593
|
+
// it's off.
|
|
1594
|
+
const MEMORY_CARD_KEY = 'tabherd:memory-card';
|
|
1595
|
+
let memoryCardOn = true;
|
|
1596
|
+
try {
|
|
1597
|
+
memoryCardOn = localStorage.getItem(MEMORY_CARD_KEY) !== 'off';
|
|
1598
|
+
} catch {}
|
|
1599
|
+
const onMemoryCard = (a) => memoryCardOn && a.kind === 'model';
|
|
1600
|
+
$('memory-card').checked = memoryCardOn;
|
|
1601
|
+
$('memory-card').addEventListener('change', (e) => {
|
|
1602
|
+
memoryCardOn = e.currentTarget.checked;
|
|
1603
|
+
try {
|
|
1604
|
+
localStorage.setItem(MEMORY_CARD_KEY, memoryCardOn ? 'on' : 'off');
|
|
1605
|
+
} catch {}
|
|
1606
|
+
$('memory-float').disabled = !memoryCardOn;
|
|
1607
|
+
render();
|
|
1608
|
+
});
|
|
1609
|
+
|
|
1610
|
+
// It can also stay in view, under the header, while the cards scroll. Off
|
|
1611
|
+
// unless chosen, kept in this browser.
|
|
1612
|
+
const MEMORY_FLOAT_KEY = 'tabherd:memory-float';
|
|
1613
|
+
let memoryFloat = false;
|
|
1614
|
+
try {
|
|
1615
|
+
memoryFloat = localStorage.getItem(MEMORY_FLOAT_KEY) === 'on';
|
|
1616
|
+
} catch {}
|
|
1617
|
+
list.classList.toggle('memory-float', memoryFloat);
|
|
1618
|
+
$('memory-float').checked = memoryFloat;
|
|
1619
|
+
$('memory-float').disabled = !memoryCardOn;
|
|
1620
|
+
$('memory-float').addEventListener('change', (e) => {
|
|
1621
|
+
memoryFloat = e.currentTarget.checked;
|
|
1622
|
+
try {
|
|
1623
|
+
localStorage.setItem(MEMORY_FLOAT_KEY, memoryFloat ? 'on' : 'off');
|
|
1624
|
+
} catch {}
|
|
1625
|
+
list.classList.toggle('memory-float', memoryFloat);
|
|
1626
|
+
});
|
|
1627
|
+
// The header wraps onto more lines in a narrow window, so the card stops
|
|
1628
|
+
// wherever its bottom is.
|
|
1629
|
+
new ResizeObserver(([entry]) => document.documentElement.style.setProperty('--top-height', `${entry.target.offsetHeight}px`)).observe(
|
|
1630
|
+
document.querySelector('.top'),
|
|
1631
|
+
);
|
|
1632
|
+
|
|
1633
|
+
// A group's heading, when the cards are in sections by group. It closes the
|
|
1634
|
+
// section, hiding its cards, and opens it again. A closed one says how many
|
|
1635
|
+
// of its sessions need you.
|
|
1636
|
+
function sectionHead(s) {
|
|
1637
|
+
return el(
|
|
1638
|
+
'h2',
|
|
1639
|
+
{ class: `section-head${s.color ? ` g-${s.color}` : ' none'}` },
|
|
1640
|
+
el(
|
|
1641
|
+
'button',
|
|
1642
|
+
{ type: 'button', class: 'section-toggle', 'data-section': s.key, 'aria-expanded': String(!s.closed), onclick: () => toggleSection(s.key) },
|
|
1643
|
+
el('span', { class: 'chev' }),
|
|
1644
|
+
el('span', { class: 'dot' }),
|
|
1645
|
+
s.name,
|
|
1646
|
+
el('b', { text: String(s.count) }),
|
|
1647
|
+
),
|
|
1648
|
+
s.waiting ? el('span', { class: 'badge s-waiting' }, el('span', { class: 'dot' }), trn(s.waiting, '{n} needs you', '{n} need you')) : null,
|
|
1649
|
+
);
|
|
1650
|
+
}
|
|
1651
|
+
|
|
1652
|
+
// The sections closed, by group, or "none" for the one of cards in no group.
|
|
1653
|
+
// Kept in this browser, like Sections by group.
|
|
1654
|
+
const CLOSED_SECTIONS_KEY = 'tabherd:closed-sections';
|
|
1655
|
+
let closedSections = new Set();
|
|
1656
|
+
try {
|
|
1657
|
+
closedSections = new Set(JSON.parse(localStorage.getItem(CLOSED_SECTIONS_KEY) || '[]'));
|
|
1658
|
+
} catch {}
|
|
1659
|
+
|
|
1660
|
+
function toggleSection(key) {
|
|
1661
|
+
if (!closedSections.delete(key)) closedSections.add(key);
|
|
1662
|
+
try {
|
|
1663
|
+
localStorage.setItem(CLOSED_SECTIONS_KEY, JSON.stringify([...closedSections]));
|
|
1664
|
+
} catch {}
|
|
1665
|
+
render();
|
|
1666
|
+
// The heading is made again, so the keyboard stays on it.
|
|
1667
|
+
list.querySelector(`.section-toggle[data-section="${CSS.escape(key)}"]`)?.focus();
|
|
1668
|
+
}
|
|
1669
|
+
|
|
1670
|
+
// The app and group chosen in the header narrow everything, the filters'
|
|
1671
|
+
// counts included. To-dos start Claude, so they count as Claude's.
|
|
1672
|
+
const inView = (x) =>
|
|
1673
|
+
(appFilter === 'all' || (x.app || 'claude') === appFilter) && (groupFilter === 'all' || (groupFilter === 'none' ? !x.group : x.group === groupFilter));
|
|
1674
|
+
|
|
1675
|
+
function render() {
|
|
1676
|
+
if (!snap) return;
|
|
1677
|
+
renderViewFilters();
|
|
1678
|
+
const models = snap.agents.filter((a) => onMemoryCard(a) && inView(a));
|
|
1679
|
+
const agents = snap.agents
|
|
1680
|
+
.filter((a) => !onMemoryCard(a) && inView(a))
|
|
1681
|
+
.sort((x, y) => status(x).rank - status(y).rank || x.startedAt - y.startedAt);
|
|
1682
|
+
const todos = (snap.todos || []).filter(inView).sort((x, y) => x.createdAt - y.createdAt);
|
|
1683
|
+
renderFilterTabs(agents, todos);
|
|
1684
|
+
// The tab's title counts every session that needs you, whatever's shown.
|
|
1685
|
+
const needsYou = snap.agents.filter((a) => a.status === 'waiting').length;
|
|
1686
|
+
document.title = needsYou ? `(${needsYou}) Tabherd` : 'Tabherd';
|
|
1687
|
+
$('host').textContent = snap.host;
|
|
1688
|
+
$('version').textContent = snap.version ? `v${snap.version}` : '';
|
|
1689
|
+
|
|
1690
|
+
// To-do cards come first, under All and the filters that ask for them.
|
|
1691
|
+
const f = filterDef(filter);
|
|
1692
|
+
let shown = [
|
|
1693
|
+
...todos.filter((t) => matchesFilter(f, t, true)).map((t) => [TODO_PREFIX + t.id, t, todoCard]),
|
|
1694
|
+
...agents.filter((a) => matchesFilter(f, a, false)).map((a) => [a.id, a, card]),
|
|
1695
|
+
];
|
|
1696
|
+
// In sections: each group's cards under its heading, in the groups' order,
|
|
1697
|
+
// then those in no group. A closed section is its heading alone.
|
|
1698
|
+
if (sectionsOn && snap.groups?.length) {
|
|
1699
|
+
const items = shown;
|
|
1700
|
+
shown = [];
|
|
1701
|
+
for (const id of [...snap.groups.map((g) => g.id), null]) {
|
|
1702
|
+
const inGroup = items.filter(([, d]) => (d.group || null) === id);
|
|
1703
|
+
if (!inGroup.length) continue;
|
|
1704
|
+
const g = groupDef(id);
|
|
1705
|
+
const key = id || 'none';
|
|
1706
|
+
const closed = closedSections.has(key);
|
|
1707
|
+
const waiting = closed ? inGroup.filter(([, d]) => d.status === 'waiting').length : 0;
|
|
1708
|
+
shown.push([`section:${id}`, { key, name: g ? g.name : tr('No group'), color: g?.color || null, count: inGroup.length, closed, waiting }, sectionHead]);
|
|
1709
|
+
if (!closed) shown.push(...inGroup);
|
|
1710
|
+
}
|
|
1711
|
+
}
|
|
1712
|
+
// The memory card comes first, whatever the filter.
|
|
1713
|
+
if (memoryCardOn && snap.memory) shown.unshift(['memory', { memory: snap.memory, models }, memoryCard]);
|
|
1714
|
+
const seen = new Set();
|
|
1715
|
+
shown.forEach(([id, data, make], i) => {
|
|
1716
|
+
seen.add(id);
|
|
1717
|
+
// A group's name or colour can change without the card changing.
|
|
1718
|
+
const key = JSON.stringify(data) + subsOpen.get(id) + JSON.stringify(groupDef(data.group));
|
|
1719
|
+
let entry = cards.get(id);
|
|
1720
|
+
if (!entry || entry.key !== key) {
|
|
1721
|
+
const node = make(data);
|
|
1722
|
+
if (entry) {
|
|
1723
|
+
// Keep the card where it was scrolled to, so updates don't jump it.
|
|
1724
|
+
const scrolled = entry.node.querySelector('.card-body')?.scrollTop;
|
|
1725
|
+
entry.node.replaceWith(node);
|
|
1726
|
+
const body = node.querySelector('.card-body');
|
|
1727
|
+
if (body && scrolled) body.scrollTop = scrolled;
|
|
1728
|
+
}
|
|
1729
|
+
entry = { key, node };
|
|
1730
|
+
cards.set(id, entry);
|
|
1731
|
+
}
|
|
1732
|
+
if (list.children[i] !== entry.node) list.insertBefore(entry.node, list.children[i] || null);
|
|
1733
|
+
});
|
|
1734
|
+
for (const [id, entry] of cards) {
|
|
1735
|
+
if (!seen.has(id)) {
|
|
1736
|
+
entry.node.remove();
|
|
1737
|
+
cards.delete(id);
|
|
1738
|
+
}
|
|
1739
|
+
}
|
|
1740
|
+
const nothing = !snap.agents.length && !snap.todos?.length;
|
|
1741
|
+
$('empty').hidden = !nothing && shown.length > 0;
|
|
1742
|
+
$('empty').querySelector('.empty-title').textContent = nothing ? tr('No Claude Code or Codex sessions are running.') : tr('No sessions match this filter.');
|
|
1743
|
+
}
|
|
1744
|
+
|
|
1745
|
+
// The app and group filters in the header. Each shows once there's a choice:
|
|
1746
|
+
// the app filter once a Codex session is running, the group filter once
|
|
1747
|
+
// there are groups. Kept in this browser.
|
|
1748
|
+
const VIEW_KEY = 'tabherd:view';
|
|
1749
|
+
let appFilter = 'all';
|
|
1750
|
+
let groupFilter = 'all';
|
|
1751
|
+
try {
|
|
1752
|
+
const saved = JSON.parse(localStorage.getItem(VIEW_KEY) || '{}');
|
|
1753
|
+
if (['all', ...Object.keys(APPS)].includes(saved.app)) appFilter = saved.app;
|
|
1754
|
+
if (typeof saved.group === 'string') groupFilter = saved.group;
|
|
1755
|
+
if (typeof saved.filter === 'string') filter = saved.filter;
|
|
1756
|
+
} catch {}
|
|
1757
|
+
|
|
1758
|
+
function saveView() {
|
|
1759
|
+
try {
|
|
1760
|
+
localStorage.setItem(VIEW_KEY, JSON.stringify({ app: appFilter, group: groupFilter, filter }));
|
|
1761
|
+
} catch {}
|
|
1762
|
+
}
|
|
1763
|
+
|
|
1764
|
+
function renderViewFilters() {
|
|
1765
|
+
const groups = snap?.groups || [];
|
|
1766
|
+
if (!['all', 'none'].includes(groupFilter) && !groups.some((g) => g.id === groupFilter)) groupFilter = 'all';
|
|
1767
|
+
const app = $('app-filter');
|
|
1768
|
+
// Claude, and each other app with something on the dashboard.
|
|
1769
|
+
const apps = ['claude', ...Object.keys(APPS).filter((k) => k !== 'claude' && (k === appFilter || snap.agents.some((a) => a.app === k)))];
|
|
1770
|
+
app.hidden = appFilter === 'all' && apps.length < 2;
|
|
1771
|
+
const appOptions = [['all', tr('All apps')], ...apps.map((k) => [k, APPS[k]])];
|
|
1772
|
+
if (app.dataset.signature !== JSON.stringify(appOptions)) {
|
|
1773
|
+
app.replaceChildren(...appOptions.map(([value, text]) => el('option', { value, text })));
|
|
1774
|
+
app.dataset.signature = JSON.stringify(appOptions);
|
|
1775
|
+
}
|
|
1776
|
+
app.value = appFilter;
|
|
1777
|
+
const select = $('group-filter');
|
|
1778
|
+
select.hidden = !groups.length && groupFilter === 'all';
|
|
1779
|
+
const options = [['all', tr('All groups')], ...groups.map((g) => [g.id, g.name]), ['none', tr('No group')]];
|
|
1780
|
+
const signature = JSON.stringify(options);
|
|
1781
|
+
if (select.dataset.signature !== signature) {
|
|
1782
|
+
select.replaceChildren(...options.map(([value, text]) => el('option', { value, text })));
|
|
1783
|
+
select.dataset.signature = signature;
|
|
1784
|
+
}
|
|
1785
|
+
select.value = groupFilter;
|
|
1786
|
+
const g = groupDef(groupFilter);
|
|
1787
|
+
select.className = `view-select${g ? ` chosen g-${g.color}` : ''}`;
|
|
1788
|
+
}
|
|
1789
|
+
|
|
1790
|
+
$('app-filter').addEventListener('change', (e) => {
|
|
1791
|
+
appFilter = e.currentTarget.value;
|
|
1792
|
+
saveView();
|
|
1793
|
+
render();
|
|
1794
|
+
});
|
|
1795
|
+
$('group-filter').addEventListener('change', (e) => {
|
|
1796
|
+
groupFilter = e.currentTarget.value;
|
|
1797
|
+
saveView();
|
|
1798
|
+
render();
|
|
1799
|
+
});
|
|
1800
|
+
|
|
1801
|
+
// ---- filters -------------------------------------------------------------------
|
|
1802
|
+
|
|
1803
|
+
// The tabs across the top: All, then the filters kept on the server, in their
|
|
1804
|
+
// order, then the filters' menu. Each can pick statuses, apps, groups and
|
|
1805
|
+
// words; a list left empty matches any.
|
|
1806
|
+
const filterDef = (id) => (snap?.filters || []).find((f) => f.id === id) || null;
|
|
1807
|
+
|
|
1808
|
+
// Whether a card shows under a filter, or under All (null). To-do cards have
|
|
1809
|
+
// no status, so they show under the filters that ask for them.
|
|
1810
|
+
function matchesFilter(f, x, isTodo) {
|
|
1811
|
+
if (!f) return true;
|
|
1812
|
+
if (isTodo ? !f.todos : f.statuses.length && !f.statuses.includes(filterStatus(x))) return false;
|
|
1813
|
+
if (f.apps.length && !f.apps.includes(x.app || 'claude')) return false;
|
|
1814
|
+
if (f.groups.length && !f.groups.includes(x.group || 'none')) return false;
|
|
1815
|
+
if (f.tickets.length && !f.tickets.includes(ticketStatus(x))) return false;
|
|
1816
|
+
if (f.text) {
|
|
1817
|
+
const words = [x.name, x.title, x.cwd, x.where].filter(Boolean).join(' ').toLowerCase();
|
|
1818
|
+
if (!f.text.toLowerCase().split(' ').every((w) => words.includes(w))) return false;
|
|
1819
|
+
}
|
|
1820
|
+
return true;
|
|
1821
|
+
}
|
|
1822
|
+
|
|
1823
|
+
// What a filter shows, in words, like "Needs you or Idle, and to-dos".
|
|
1824
|
+
const anyOf = new Intl.ListFormat(lang, { type: 'disjunction' });
|
|
1825
|
+
|
|
1826
|
+
function describeFilter(f) {
|
|
1827
|
+
const or = (ids, name) => anyOf.format(ids.map(name).filter(Boolean));
|
|
1828
|
+
return [
|
|
1829
|
+
f.statuses.length ? or(f.statuses, (s) => FILTER_STATUSES[s]) : tr('Any status'),
|
|
1830
|
+
f.apps.length ? or(f.apps, (a) => APPS[a]) : null,
|
|
1831
|
+
f.groups.length ? tr('in {groups}', { groups: or(f.groups, (g) => (g === 'none' ? tr('no group') : groupDef(g)?.name)) }) : null,
|
|
1832
|
+
f.tickets.length ? tr('ticket: {statuses}', { statuses: or(f.tickets, (s) => FILTER_TICKETS[s]) }) : null,
|
|
1833
|
+
f.text ? `“${f.text}”` : null,
|
|
1834
|
+
f.todos ? tr('and to-dos') : null,
|
|
1835
|
+
]
|
|
1836
|
+
.filter(Boolean)
|
|
1837
|
+
.join(', ');
|
|
1838
|
+
}
|
|
1839
|
+
|
|
1840
|
+
function chooseFilter(id) {
|
|
1841
|
+
filter = id;
|
|
1842
|
+
saveView();
|
|
1843
|
+
render();
|
|
1844
|
+
}
|
|
1845
|
+
|
|
1846
|
+
// Each tab with how many cards it shows, amber when one of them needs you.
|
|
1847
|
+
function renderFilterTabs(agents, todos) {
|
|
1848
|
+
// A filter that picks tickets' statuses waits for a tracker to read them from.
|
|
1849
|
+
const filters = (snap.filters || []).filter((f) => !f.tickets.length || snap.trackerCount);
|
|
1850
|
+
if (filter !== 'all' && !filters.some((f) => f.id === filter)) filter = 'all';
|
|
1851
|
+
const nav = $('filters');
|
|
1852
|
+
const tabs = [{ id: 'all', name: tr('All') }, ...filters];
|
|
1853
|
+
const signature = JSON.stringify([tabs, snap.groups]);
|
|
1854
|
+
if (nav.dataset.signature !== signature) {
|
|
1855
|
+
nav.replaceChildren(
|
|
1856
|
+
...tabs.map((f) =>
|
|
1857
|
+
el(
|
|
1858
|
+
'button',
|
|
1859
|
+
{
|
|
1860
|
+
type: 'button',
|
|
1861
|
+
'data-filter': f.id,
|
|
1862
|
+
title: f.id === 'all' ? tr('Everything') : describeFilter(f),
|
|
1863
|
+
onclick: () => chooseFilter(f.id),
|
|
1864
|
+
},
|
|
1865
|
+
`${tr(f.name)} `,
|
|
1866
|
+
el('b', { text: '0' }),
|
|
1867
|
+
),
|
|
1868
|
+
),
|
|
1869
|
+
el(
|
|
1870
|
+
'button',
|
|
1871
|
+
{
|
|
1872
|
+
type: 'button',
|
|
1873
|
+
class: 'filter-menu-button',
|
|
1874
|
+
title: tr('New filter, or change the filters'),
|
|
1875
|
+
'aria-label': tr('Filter options'),
|
|
1876
|
+
'aria-haspopup': 'menu',
|
|
1877
|
+
onclick: (e) => openFilterMenu(e.currentTarget),
|
|
1878
|
+
},
|
|
1879
|
+
'⋯',
|
|
1880
|
+
),
|
|
1881
|
+
);
|
|
1882
|
+
nav.dataset.signature = signature;
|
|
1883
|
+
}
|
|
1884
|
+
for (const b of nav.querySelectorAll('[data-filter]')) {
|
|
1885
|
+
const f = filterDef(b.dataset.filter);
|
|
1886
|
+
const matched = agents.filter((a) => matchesFilter(f, a, false));
|
|
1887
|
+
b.querySelector('b').textContent = matched.length + todos.filter((t) => matchesFilter(f, t, true)).length;
|
|
1888
|
+
b.setAttribute('aria-pressed', String(b.dataset.filter === filter));
|
|
1889
|
+
b.classList.toggle('has', !!f && matched.some((a) => a.status === 'waiting'));
|
|
1890
|
+
}
|
|
1891
|
+
}
|
|
1892
|
+
|
|
1893
|
+
// The menu at the end of the tabs: a new filter, the one shown, or all of
|
|
1894
|
+
// them in Settings.
|
|
1895
|
+
function openFilterMenu(button) {
|
|
1896
|
+
const menu = $('filter-menu');
|
|
1897
|
+
const shown = filterDef(filter);
|
|
1898
|
+
const full = (snap?.filters || []).length >= MAX_FILTERS;
|
|
1899
|
+
const item = (label, onclick, disabled) =>
|
|
1900
|
+
el('button', { type: 'button', class: 'menu-item', role: 'menuitem', disabled: disabled || null, onclick: () => (menu.hidePopover(), onclick()) }, label);
|
|
1901
|
+
// All isn't a filter of its own, so with it shown there's none to change.
|
|
1902
|
+
const items = [
|
|
1903
|
+
item(full ? tr('New filter (up to {n})', { n: MAX_FILTERS }) : tr('New filter…'), () => editFilter(null), full),
|
|
1904
|
+
shown ? item(tr('Edit “{name}”…', { name: tr(shown.name) }), () => editFilter(shown)) : null,
|
|
1905
|
+
el('hr'),
|
|
1906
|
+
item(tr('Edit filters…'), () => openSettings('filters-setting')),
|
|
1907
|
+
];
|
|
1908
|
+
menu.replaceChildren(...items.filter(Boolean));
|
|
1909
|
+
showMenu(menu, button);
|
|
1910
|
+
}
|
|
1911
|
+
|
|
1912
|
+
// Every filter at once, one save at a time, in order; `null` puts the usual
|
|
1913
|
+
// ones back. Resolves to the filters as saved.
|
|
1914
|
+
let filtersSaving = Promise.resolve();
|
|
1915
|
+
|
|
1916
|
+
function saveFilters(next) {
|
|
1917
|
+
const run = filtersSaving.then(async () => {
|
|
1918
|
+
const saved = (await api('/api/filters', next ? { filters: next } : { reset: true })).filters;
|
|
1919
|
+
if (snap) snap = { ...snap, filters: saved };
|
|
1920
|
+
render();
|
|
1921
|
+
renderFilterSettings();
|
|
1922
|
+
return saved;
|
|
1923
|
+
});
|
|
1924
|
+
filtersSaving = run.catch(() => {});
|
|
1925
|
+
return run;
|
|
1926
|
+
}
|
|
1927
|
+
|
|
1928
|
+
// Asks for a second click, like a group's Delete.
|
|
1929
|
+
function askTwice(button, then) {
|
|
1930
|
+
if (button.classList.contains('btn-danger')) return then();
|
|
1931
|
+
const label = button.textContent;
|
|
1932
|
+
button.classList.add('btn-danger');
|
|
1933
|
+
button.textContent = tr('{label}?', { label });
|
|
1934
|
+
setTimeout(() => {
|
|
1935
|
+
button.classList.remove('btn-danger');
|
|
1936
|
+
button.textContent = label;
|
|
1937
|
+
}, 3000);
|
|
1938
|
+
}
|
|
1939
|
+
|
|
1940
|
+
let editingFilter = null;
|
|
1941
|
+
|
|
1942
|
+
// A tick box for each choice.
|
|
1943
|
+
function filterChecks(box, options, chosen) {
|
|
1944
|
+
box.replaceChildren(
|
|
1945
|
+
...options.map(([value, text, color]) =>
|
|
1946
|
+
el('label', { class: `check${color ? ` g-${color}` : ''}` }, el('input', { type: 'checkbox', value, checked: chosen.includes(value) }), color ? el('span', { class: 'dot' }) : null, text),
|
|
1947
|
+
),
|
|
1948
|
+
);
|
|
1949
|
+
}
|
|
1950
|
+
|
|
1951
|
+
function filterFromForm() {
|
|
1952
|
+
const ticked = (id) => [...$(id).querySelectorAll('input:checked')].map((i) => i.value);
|
|
1953
|
+
const name = $('filter-name').value;
|
|
1954
|
+
return {
|
|
1955
|
+
...(editingFilter || {}),
|
|
1956
|
+
// One of the usual filters, shown in another language, keeps its name.
|
|
1957
|
+
name: editingFilter && name === tr(editingFilter.name) ? editingFilter.name : name,
|
|
1958
|
+
statuses: ticked('filter-statuses'),
|
|
1959
|
+
apps: ticked('filter-apps'),
|
|
1960
|
+
groups: ticked('filter-groups'),
|
|
1961
|
+
tickets: ticked('filter-tickets'),
|
|
1962
|
+
text: $('filter-text').value.replace(/\s+/g, ' ').trim(),
|
|
1963
|
+
todos: $('filter-todos').checked,
|
|
1964
|
+
};
|
|
1965
|
+
}
|
|
1966
|
+
|
|
1967
|
+
// How many cards it would show now, as it's changed.
|
|
1968
|
+
function showFilterCount() {
|
|
1969
|
+
if (!snap) return;
|
|
1970
|
+
const f = filterFromForm();
|
|
1971
|
+
const n =
|
|
1972
|
+
snap.agents.filter((a) => !onMemoryCard(a) && inView(a) && matchesFilter(f, a, false)).length +
|
|
1973
|
+
(snap.todos || []).filter((t) => inView(t) && matchesFilter(f, t, true)).length;
|
|
1974
|
+
$('filter-count').textContent = trn(n, 'Shows {n} card now.', 'Shows {n} cards now.');
|
|
1975
|
+
}
|
|
1976
|
+
|
|
1977
|
+
// Opens the editor, for a new filter if `f` is null.
|
|
1978
|
+
function editFilter(f) {
|
|
1979
|
+
editingFilter = f;
|
|
1980
|
+
$('filter-dialog-title').textContent = f ? tr('Edit filter') : tr('New filter');
|
|
1981
|
+
$('filter-save').textContent = f ? tr('Save') : tr('Add filter');
|
|
1982
|
+
$('filter-delete').hidden = !f;
|
|
1983
|
+
$('filter-name').value = f ? tr(f.name) : '';
|
|
1984
|
+
filterChecks($('filter-statuses'), Object.entries(FILTER_STATUSES), f?.statuses || []);
|
|
1985
|
+
// Every app, so a filter can be made before an app has anything running.
|
|
1986
|
+
filterChecks($('filter-apps'), Object.entries(APPS), f?.apps || []);
|
|
1987
|
+
const groups = snap?.groups || [];
|
|
1988
|
+
$('filter-groups-field').hidden = !groups.length;
|
|
1989
|
+
filterChecks($('filter-groups'), [...groups.map((g) => [g.id, g.name, g.color]), ['none', tr('No group')]], f?.groups || []);
|
|
1990
|
+
// Tickets' statuses, once there's a tracker to read them from.
|
|
1991
|
+
$('filter-tickets-field').hidden = !snap?.trackerCount && !f?.tickets.length;
|
|
1992
|
+
filterChecks($('filter-tickets'), Object.entries(FILTER_TICKETS), f?.tickets || []);
|
|
1993
|
+
$('filter-text').value = f?.text || '';
|
|
1994
|
+
$('filter-todos').checked = !!f?.todos;
|
|
1995
|
+
showFilterCount();
|
|
1996
|
+
$('filter-dialog').showModal();
|
|
1997
|
+
$('filter-name').focus();
|
|
1998
|
+
}
|
|
1999
|
+
|
|
2000
|
+
$('filter-form').addEventListener('input', showFilterCount);
|
|
2001
|
+
$('filter-form').addEventListener('submit', async (e) => {
|
|
2002
|
+
e.preventDefault();
|
|
2003
|
+
const f = filterFromForm();
|
|
2004
|
+
const filters = snap?.filters || [];
|
|
2005
|
+
const next = editingFilter ? filters.map((x) => (x.id === editingFilter.id ? f : x)) : [...filters, f];
|
|
2006
|
+
const save = $('filter-save');
|
|
2007
|
+
save.disabled = true;
|
|
2008
|
+
try {
|
|
2009
|
+
const saved = await saveFilters(next);
|
|
2010
|
+
$('filter-dialog').close();
|
|
2011
|
+
// A new filter is shown as soon as it's made.
|
|
2012
|
+
if (!editingFilter) chooseFilter(saved[saved.length - 1].id);
|
|
2013
|
+
} catch (err) {
|
|
2014
|
+
toast(err.message, true);
|
|
2015
|
+
} finally {
|
|
2016
|
+
save.disabled = false;
|
|
2017
|
+
}
|
|
2018
|
+
});
|
|
2019
|
+
$('filter-delete').addEventListener('click', (e) =>
|
|
2020
|
+
askTwice(e.currentTarget, async () => {
|
|
2021
|
+
try {
|
|
2022
|
+
await saveFilters((snap?.filters || []).filter((x) => x.id !== editingFilter.id));
|
|
2023
|
+
$('filter-dialog').close();
|
|
2024
|
+
} catch (err) {
|
|
2025
|
+
toast(err.message, true);
|
|
2026
|
+
}
|
|
2027
|
+
}),
|
|
2028
|
+
);
|
|
2029
|
+
for (const id of ['filter-cancel', 'filter-close']) $(id).addEventListener('click', () => $('filter-dialog').close());
|
|
2030
|
+
|
|
2031
|
+
// The list in Settings: each filter with what it shows, to move, change or delete.
|
|
2032
|
+
function renderFilterSettings(focusKey) {
|
|
2033
|
+
const filters = snap?.filters || [];
|
|
2034
|
+
const box = $('filter-list');
|
|
2035
|
+
const focused = focusKey || (box.contains(document.activeElement) ? document.activeElement.dataset.focus : null);
|
|
2036
|
+
const move = (i, by, key) => {
|
|
2037
|
+
const next = [...filters];
|
|
2038
|
+
[next[i], next[i + by]] = [next[i + by], next[i]];
|
|
2039
|
+
saveFilters(next)
|
|
2040
|
+
.then(() => box.querySelector(`[data-focus="${CSS.escape(key)}"]:not(:disabled)`)?.focus())
|
|
2041
|
+
.catch((err) => toast(err.message, true));
|
|
2042
|
+
};
|
|
2043
|
+
box.replaceChildren(
|
|
2044
|
+
...filters.map((f, i) =>
|
|
2045
|
+
el(
|
|
2046
|
+
'li',
|
|
2047
|
+
{ class: 'filter-row' },
|
|
2048
|
+
el('div', { class: 'filter-row-text' }, el('b', { text: tr(f.name) }), el('span', { text: describeFilter(f) })),
|
|
2049
|
+
el(
|
|
2050
|
+
'button',
|
|
2051
|
+
{ type: 'button', class: 'icon-btn', title: tr('Move up'), 'aria-label': tr('Move {name} up', { name: tr(f.name) }), 'data-focus': `up:${f.id}`, disabled: i === 0, onclick: () => move(i, -1, `up:${f.id}`) },
|
|
2052
|
+
'↑',
|
|
2053
|
+
),
|
|
2054
|
+
el(
|
|
2055
|
+
'button',
|
|
2056
|
+
{
|
|
2057
|
+
type: 'button',
|
|
2058
|
+
class: 'icon-btn',
|
|
2059
|
+
title: tr('Move down'),
|
|
2060
|
+
'aria-label': tr('Move {name} down', { name: tr(f.name) }),
|
|
2061
|
+
'data-focus': `down:${f.id}`,
|
|
2062
|
+
disabled: i === filters.length - 1,
|
|
2063
|
+
onclick: () => move(i, 1, `down:${f.id}`),
|
|
2064
|
+
},
|
|
2065
|
+
'↓',
|
|
2066
|
+
),
|
|
2067
|
+
el('button', { type: 'button', class: 'btn', onclick: () => editFilter(f) }, tr('Edit')),
|
|
2068
|
+
el(
|
|
2069
|
+
'button',
|
|
2070
|
+
{
|
|
2071
|
+
type: 'button',
|
|
2072
|
+
class: 'btn btn-stop',
|
|
2073
|
+
onclick: (e) => askTwice(e.currentTarget, () => saveFilters(filters.filter((x) => x.id !== f.id)).catch((err) => toast(err.message, true))),
|
|
2074
|
+
},
|
|
2075
|
+
tr('Delete'),
|
|
2076
|
+
),
|
|
2077
|
+
),
|
|
2078
|
+
),
|
|
2079
|
+
);
|
|
2080
|
+
if (!filters.length) box.append(el('li', { class: 'filter-none', text: tr('Only All, for now.') }));
|
|
2081
|
+
$('filter-add').disabled = filters.length >= MAX_FILTERS;
|
|
2082
|
+
if (focused) box.querySelector(`[data-focus="${CSS.escape(focused)}"]:not(:disabled)`)?.focus();
|
|
2083
|
+
}
|
|
2084
|
+
|
|
2085
|
+
$('filter-add').addEventListener('click', () => editFilter(null));
|
|
2086
|
+
$('filter-reset').addEventListener('click', (e) => askTwice(e.currentTarget, () => saveFilters(null).catch((err) => toast(err.message, true))));
|
|
2087
|
+
|
|
2088
|
+
// ---- updates and dings ---------------------------------------------------------
|
|
2089
|
+
|
|
2090
|
+
const SOUND_KEY = 'tabherd:sound';
|
|
2091
|
+
const DING_GAP_MS = 2000;
|
|
2092
|
+
let soundOn = true;
|
|
2093
|
+
try {
|
|
2094
|
+
soundOn = localStorage.getItem(SOUND_KEY) !== 'off';
|
|
2095
|
+
} catch {}
|
|
2096
|
+
let audio = null;
|
|
2097
|
+
let lastDingAt = 0;
|
|
2098
|
+
// The agents in the last update, to see what changed.
|
|
2099
|
+
let lastAgents = null;
|
|
2100
|
+
// Background runs stopped from here, which haven't finished on their own.
|
|
2101
|
+
const stoppedHere = new Set();
|
|
2102
|
+
|
|
2103
|
+
function audioContext() {
|
|
2104
|
+
if (!audio) {
|
|
2105
|
+
try {
|
|
2106
|
+
audio = new AudioContext();
|
|
2107
|
+
audio.addEventListener('statechange', updateSoundButton);
|
|
2108
|
+
} catch {
|
|
2109
|
+
return null;
|
|
2110
|
+
}
|
|
2111
|
+
}
|
|
2112
|
+
return audio;
|
|
2113
|
+
}
|
|
2114
|
+
|
|
2115
|
+
function tone(ctx, freq, start, length, peak) {
|
|
2116
|
+
const osc = ctx.createOscillator();
|
|
2117
|
+
const gain = ctx.createGain();
|
|
2118
|
+
osc.frequency.value = freq;
|
|
2119
|
+
gain.gain.setValueAtTime(0.0001, start);
|
|
2120
|
+
gain.gain.exponentialRampToValueAtTime(peak, start + 0.012);
|
|
2121
|
+
gain.gain.exponentialRampToValueAtTime(0.0001, start + length);
|
|
2122
|
+
osc.connect(gain).connect(ctx.destination);
|
|
2123
|
+
osc.start(start);
|
|
2124
|
+
osc.stop(start + length + 0.05);
|
|
2125
|
+
}
|
|
2126
|
+
|
|
2127
|
+
const SOUNDS = {
|
|
2128
|
+
// Two rising notes: your turn.
|
|
2129
|
+
needs: (ctx, t) => {
|
|
2130
|
+
tone(ctx, 784, t, 0.35, 0.22);
|
|
2131
|
+
tone(ctx, 1175, t + 0.16, 0.55, 0.22);
|
|
2132
|
+
},
|
|
2133
|
+
// One soft bell: something finished.
|
|
2134
|
+
done: (ctx, t) => {
|
|
2135
|
+
tone(ctx, 1047, t, 0.9, 0.16);
|
|
2136
|
+
tone(ctx, 2890, t, 0.25, 0.025);
|
|
2137
|
+
},
|
|
2138
|
+
};
|
|
2139
|
+
|
|
2140
|
+
function ding(kind) {
|
|
2141
|
+
const ctx = audioContext();
|
|
2142
|
+
if (!soundOn || !ctx || ctx.state !== 'running') return;
|
|
2143
|
+
SOUNDS[kind](ctx, ctx.currentTime + 0.02);
|
|
2144
|
+
}
|
|
2145
|
+
|
|
2146
|
+
function updateSoundButton() {
|
|
2147
|
+
const blocked = soundOn && audio?.state !== 'running';
|
|
2148
|
+
const button = $('sound');
|
|
2149
|
+
button.classList.toggle('off', !soundOn);
|
|
2150
|
+
button.classList.toggle('blocked', blocked);
|
|
2151
|
+
button.setAttribute('aria-pressed', String(soundOn));
|
|
2152
|
+
$('sound-label').textContent = blocked ? tr('Click to enable sound') : '';
|
|
2153
|
+
button.title = !soundOn
|
|
2154
|
+
? tr('Sound is off. Click to ding when an agent needs you or finishes.')
|
|
2155
|
+
: blocked
|
|
2156
|
+
? tr('The browser blocks sound until you click the page')
|
|
2157
|
+
: tr('Dings when an agent needs you or finishes. Click to mute.');
|
|
2158
|
+
}
|
|
2159
|
+
|
|
2160
|
+
// Browsers only let a page play sound after it has been clicked or typed in.
|
|
2161
|
+
function unlockAudio() {
|
|
2162
|
+
const ctx = audioContext();
|
|
2163
|
+
if (ctx?.state === 'suspended') ctx.resume().catch(() => {});
|
|
2164
|
+
}
|
|
2165
|
+
|
|
2166
|
+
// Waiting on you, or done with a turn: Working to Idle, or to waiting at the
|
|
2167
|
+
// prompt beside a background shell.
|
|
2168
|
+
function notableChanges(agents) {
|
|
2169
|
+
const needs = [];
|
|
2170
|
+
const done = [];
|
|
2171
|
+
if (lastAgents) {
|
|
2172
|
+
for (const a of agents) {
|
|
2173
|
+
const before = lastAgents.get(a.id)?.status;
|
|
2174
|
+
if (before === undefined || before === a.status) continue;
|
|
2175
|
+
if (a.status === 'waiting') needs.push(a);
|
|
2176
|
+
else if (before === 'busy' && (a.status === 'idle' || a.status === 'shell')) done.push(a);
|
|
2177
|
+
}
|
|
2178
|
+
// A background run doesn't wait at a prompt when it's done: it exits.
|
|
2179
|
+
const running = new Set(agents.map((a) => a.id));
|
|
2180
|
+
for (const [id, a] of lastAgents) {
|
|
2181
|
+
// So do downloads, and anything else that leaves once it's done.
|
|
2182
|
+
// How it ended, and its output, if the server knows: a ComfyUI job.
|
|
2183
|
+
if ((a.background || a.leavesWhenDone) && !running.has(id) && !stoppedHere.delete(id)) {
|
|
2184
|
+
done.push({ ...a, finished: snap?.finished?.find((f) => f.id === id) || null });
|
|
2185
|
+
}
|
|
2186
|
+
}
|
|
2187
|
+
}
|
|
2188
|
+
lastAgents = new Map(agents.map((a) => [a.id, a]));
|
|
2189
|
+
return { needs, done };
|
|
2190
|
+
}
|
|
2191
|
+
|
|
2192
|
+
function announce({ needs, done }) {
|
|
2193
|
+
if (!needs.length && !done.length) return;
|
|
2194
|
+
for (const a of [...needs, ...done]) {
|
|
2195
|
+
const node = cards.get(a.id)?.node;
|
|
2196
|
+
if (!node) continue;
|
|
2197
|
+
node.classList.remove('flash');
|
|
2198
|
+
void node.offsetWidth;
|
|
2199
|
+
node.classList.add('flash');
|
|
2200
|
+
}
|
|
2201
|
+
const [one] = needs.length ? needs : done;
|
|
2202
|
+
const name = displayName(one);
|
|
2203
|
+
if (needs.length > 1) toast(tr('{n} agents need you', { n: needs.length }));
|
|
2204
|
+
else if (needs.length) toast(one.waitingFor ? tr('{name} needs you: {what}', { name, what: tr(one.waitingFor) }) : tr('{name} needs you', { name }));
|
|
2205
|
+
else toast(done.length > 1 ? tr('{n} agents finished', { n: done.length }) : tr('{name} finished', { name }));
|
|
2206
|
+
if (Date.now() - lastDingAt < DING_GAP_MS) return;
|
|
2207
|
+
lastDingAt = Date.now();
|
|
2208
|
+
ding(needs.length ? 'needs' : 'done');
|
|
2209
|
+
}
|
|
2210
|
+
|
|
2211
|
+
// ---- notification list --------------------------------------------------------
|
|
2212
|
+
|
|
2213
|
+
// Each "needs you" or "finished" also goes in a list, so it can still be seen
|
|
2214
|
+
// after its toast fades. The setting under Notifications keeps it in this
|
|
2215
|
+
// browser across reloads.
|
|
2216
|
+
const NOTES_KEY = 'tabherd:notifications';
|
|
2217
|
+
const KEEP_NOTES_KEY = 'tabherd:keep-notifications';
|
|
2218
|
+
let keepNotes = true;
|
|
2219
|
+
let notes = [];
|
|
2220
|
+
let notesKey = null;
|
|
2221
|
+
try {
|
|
2222
|
+
keepNotes = localStorage.getItem(KEEP_NOTES_KEY) !== 'off';
|
|
2223
|
+
const saved = keepNotes && JSON.parse(localStorage.getItem(NOTES_KEY) || '[]');
|
|
2224
|
+
if (Array.isArray(saved)) notes = saved;
|
|
2225
|
+
} catch {}
|
|
2226
|
+
|
|
2227
|
+
function saveNotes() {
|
|
2228
|
+
try {
|
|
2229
|
+
if (keepNotes) localStorage.setItem(NOTES_KEY, JSON.stringify(notes));
|
|
2230
|
+
else localStorage.removeItem(NOTES_KEY);
|
|
2231
|
+
} catch {}
|
|
2232
|
+
}
|
|
2233
|
+
|
|
2234
|
+
// An agent that's working again has been dealt with, and so has a question
|
|
2235
|
+
// it's no longer waiting on. Each agent keeps only its latest entry.
|
|
2236
|
+
function updateNotes(agents, { needs, done }) {
|
|
2237
|
+
const live = new Map(agents.map((a) => [a.id, a]));
|
|
2238
|
+
const before = notes.length;
|
|
2239
|
+
notes = notes.filter((n) => {
|
|
2240
|
+
const a = live.get(n.id);
|
|
2241
|
+
return !a || (a.status !== 'busy' && (n.kind !== 'needs' || a.status === 'waiting'));
|
|
2242
|
+
});
|
|
2243
|
+
const added = [
|
|
2244
|
+
...needs.map((a) => ({ id: a.id, kind: 'needs', name: displayName(a), detail: a.waitingFor || '', at: snap.now })),
|
|
2245
|
+
...done.map((a) => ({
|
|
2246
|
+
id: a.id,
|
|
2247
|
+
kind: 'done',
|
|
2248
|
+
name: displayName(a),
|
|
2249
|
+
detail: '',
|
|
2250
|
+
background: Boolean(a.background),
|
|
2251
|
+
// Gone once it's done, so its leaving isn't a session closing.
|
|
2252
|
+
gone: Boolean(a.background || a.leavesWhenDone),
|
|
2253
|
+
label: a.finished?.label || null,
|
|
2254
|
+
preview: a.finished?.preview || null,
|
|
2255
|
+
at: snap.now,
|
|
2256
|
+
})),
|
|
2257
|
+
];
|
|
2258
|
+
if (added.length) notes = [...added, ...notes.filter((n) => !added.some((x) => x.id === n.id))];
|
|
2259
|
+
if (added.length || notes.length !== before) saveNotes();
|
|
2260
|
+
renderNotes();
|
|
2261
|
+
}
|
|
2262
|
+
|
|
2263
|
+
function clearNotes(note) {
|
|
2264
|
+
notes = note ? notes.filter((n) => n !== note) : [];
|
|
2265
|
+
saveNotes();
|
|
2266
|
+
renderNotes();
|
|
2267
|
+
}
|
|
2268
|
+
|
|
2269
|
+
function renderNotes() {
|
|
2270
|
+
const live = new Map((snap?.agents || []).map((a) => [a.id, a]));
|
|
2271
|
+
const rows = notes.map((n) => {
|
|
2272
|
+
const a = live.get(n.id);
|
|
2273
|
+
return { n, a, name: a ? displayName(a) : n.name, focus: Boolean(a && canFocus(a)) };
|
|
2274
|
+
});
|
|
2275
|
+
// A finished background run is picked up again from the history.
|
|
2276
|
+
const resumable = (n) => n.background && Boolean(snap?.terminals);
|
|
2277
|
+
// Rebuilt only when something shown changes, so an open list doesn't flicker.
|
|
2278
|
+
const key = JSON.stringify(rows.map((r) => [r.n.id, r.n.kind, r.n.at, r.name, Boolean(r.a), r.focus, resumable(r.n), r.n.preview]));
|
|
2279
|
+
if (key === notesKey) return;
|
|
2280
|
+
notesKey = key;
|
|
2281
|
+
$('notes-list').replaceChildren(
|
|
2282
|
+
...rows.map(({ n, a, name, focus }) => {
|
|
2283
|
+
const what = [
|
|
2284
|
+
n.kind === 'update'
|
|
2285
|
+
? tr('A new version is out')
|
|
2286
|
+
: n.kind === 'needs'
|
|
2287
|
+
? n.detail
|
|
2288
|
+
? tr('Needs you: {what}', { what: tr(n.detail) })
|
|
2289
|
+
: tr('Needs you')
|
|
2290
|
+
: n.label
|
|
2291
|
+
? tr(n.label)
|
|
2292
|
+
: n.background
|
|
2293
|
+
? tr('Finished in the background')
|
|
2294
|
+
: tr('Finished'),
|
|
2295
|
+
];
|
|
2296
|
+
if (!a && !n.gone && !n.background && n.kind !== 'update') what.push(tr('session closed'));
|
|
2297
|
+
return el(
|
|
2298
|
+
'li',
|
|
2299
|
+
{ class: `note k-${n.kind}` },
|
|
2300
|
+
el('span', { class: 'dot' }),
|
|
2301
|
+
el(
|
|
2302
|
+
'span',
|
|
2303
|
+
{ class: 'note-text' },
|
|
2304
|
+
n.kind === 'update'
|
|
2305
|
+
? el('button', { type: 'button', class: 'name-link note-name', title: tr("See what's new, and how to update"), onclick: () => openUpdate() }, name)
|
|
2306
|
+
: focus
|
|
2307
|
+
? el('button', { type: 'button', class: 'name-link note-name', title: tr('Go to this session’s window'), onclick: (e) => goToWindow(a, e.currentTarget) }, name)
|
|
2308
|
+
: !a && resumable(n)
|
|
2309
|
+
? el(
|
|
2310
|
+
'button',
|
|
2311
|
+
{ type: 'button', class: 'name-link note-name', title: tr('Open a terminal tab in its folder and continue the conversation'), onclick: (e) => resumeNote(n, e.currentTarget) },
|
|
2312
|
+
name,
|
|
2313
|
+
)
|
|
2314
|
+
: el('span', { class: 'note-name', text: name }),
|
|
2315
|
+
el('span', { class: 'note-what', text: what.join(' · '), title: what.join(' · ') }),
|
|
2316
|
+
n.preview ? el('img', { class: 'note-preview', src: n.preview, alt: tr('Output of {name}', { name }), loading: 'lazy' }) : null,
|
|
2317
|
+
),
|
|
2318
|
+
since(n.at, true),
|
|
2319
|
+
el('button', { type: 'button', class: 'icon-btn note-clear', title: tr('Clear'), 'aria-label': tr('Clear {name}', { name }), onclick: () => clearNotes(n) }, '✕'),
|
|
2320
|
+
);
|
|
2321
|
+
}),
|
|
2322
|
+
);
|
|
2323
|
+
$('notes-empty').hidden = notes.length > 0;
|
|
2324
|
+
$('notes-clear').hidden = !notes.length;
|
|
2325
|
+
$('n-notes').textContent = notes.length || '';
|
|
2326
|
+
const needCount = notes.filter((n) => n.kind === 'needs').length;
|
|
2327
|
+
$('notes-button').classList.toggle('has-needs', needCount > 0);
|
|
2328
|
+
$('notes-button').title = notes.length
|
|
2329
|
+
? trn(notes.length, '{n} notification', '{n} notifications') + (needCount ? `, ${tr('{n} needing you', { n: needCount })}` : '')
|
|
2330
|
+
: tr('Notifications');
|
|
2331
|
+
}
|
|
2332
|
+
|
|
2333
|
+
$('notes-clear').addEventListener('click', () => clearNotes());
|
|
2334
|
+
|
|
2335
|
+
// Resumes a finished background run from its notification, as History does.
|
|
2336
|
+
async function resumeNote(n, button) {
|
|
2337
|
+
button.disabled = true;
|
|
2338
|
+
try {
|
|
2339
|
+
await api(`/api/history/${n.id}/resume`);
|
|
2340
|
+
toast(tr('Resuming {name}', { name: n.name }));
|
|
2341
|
+
clearNotes(n);
|
|
2342
|
+
} catch (err) {
|
|
2343
|
+
toast(err.message, true);
|
|
2344
|
+
} finally {
|
|
2345
|
+
button.disabled = false;
|
|
2346
|
+
}
|
|
2347
|
+
}
|
|
2348
|
+
|
|
2349
|
+
// ---- update alerts -------------------------------------------------------------
|
|
2350
|
+
|
|
2351
|
+
// When a newer Tabherd is out, the header has an Update to button and the
|
|
2352
|
+
// notification list says so, once. Not now hides the button until the next
|
|
2353
|
+
// version, in this browser. The server only checks once Settings says yes,
|
|
2354
|
+
// which a bar above the cards asks once, after any first-run tour.
|
|
2355
|
+
const UPDATE_DISMISSED_KEY = 'tabherd:update-dismissed';
|
|
2356
|
+
const UPDATE_NOTED_KEY = 'tabherd:update-noted';
|
|
2357
|
+
let updateDismissed = null;
|
|
2358
|
+
let updateNoted = null;
|
|
2359
|
+
try {
|
|
2360
|
+
updateDismissed = localStorage.getItem(UPDATE_DISMISSED_KEY);
|
|
2361
|
+
updateNoted = localStorage.getItem(UPDATE_NOTED_KEY);
|
|
2362
|
+
} catch {}
|
|
2363
|
+
|
|
2364
|
+
// How to update, for each way the server can tell Tabherd was installed. A
|
|
2365
|
+
// command can depend on the new version.
|
|
2366
|
+
const HOW_TO_UPDATE = {
|
|
2367
|
+
git: { text: tr('This copy runs from a clone of the repository. Pull the new version, then start the server again:'), command: 'git pull' },
|
|
2368
|
+
homebrew: { text: tr('Installed with Homebrew:'), command: 'brew upgrade tabherd' },
|
|
2369
|
+
npm: { text: tr('Installed with npm. Stop the server with Ctrl+C in its terminal, then install the new version and start it again:'), command: (v) => `npm install -g tabherd@${v}` },
|
|
2370
|
+
npx: { text: tr('Run with npx. Stop the server with Ctrl+C in its terminal, then start the new version:'), command: (v) => `npx tabherd@${v}` },
|
|
2371
|
+
winget: { text: tr('Installed with winget:'), command: 'winget upgrade tleeadams.Tabherd' },
|
|
2372
|
+
'windows-installer': { text: tr('Download the new installer from the release and run it. It installs over this version.') },
|
|
2373
|
+
'windows-zip': { text: tr("Download the new zip from the release, and put its folder in place of this one's.") },
|
|
2374
|
+
'mac-app': { text: tr('Download the new disk image from the release, and drag Tabherd to Applications, replacing this version.') },
|
|
2375
|
+
'linux-package': { text: tr('Download the new .deb or .rpm from the release, and install it as you did this one.') },
|
|
2376
|
+
appimage: { text: tr('Download the new AppImage from the release, and use it in place of this one.') },
|
|
2377
|
+
archive: { text: tr("Download the new archive for your system from the release, and unpack it in place of this one's folder.") },
|
|
2378
|
+
};
|
|
2379
|
+
|
|
2380
|
+
function showUpdates() {
|
|
2381
|
+
const u = snap.updates;
|
|
2382
|
+
if (!u) return;
|
|
2383
|
+
const latest = u.latest;
|
|
2384
|
+
$('update-button').hidden = !latest || updateDismissed === latest.version;
|
|
2385
|
+
if (latest) $('update-label').textContent = tr('Update to {version}', { version: latest.version });
|
|
2386
|
+
// Asked once for every browser, as the server keeps the answer, but not
|
|
2387
|
+
// over the first-run tour.
|
|
2388
|
+
$('update-ask').hidden = u.check !== null || tourOn || tourPending;
|
|
2389
|
+
if (latest && updateNoted !== latest.version) {
|
|
2390
|
+
updateNoted = latest.version;
|
|
2391
|
+
try {
|
|
2392
|
+
localStorage.setItem(UPDATE_NOTED_KEY, updateNoted);
|
|
2393
|
+
} catch {}
|
|
2394
|
+
notes = [{ id: `update:${latest.version}`, kind: 'update', name: `Tabherd ${latest.version}`, detail: '', at: snap.now }, ...notes.filter((n) => n.kind !== 'update')];
|
|
2395
|
+
saveNotes();
|
|
2396
|
+
renderNotes();
|
|
2397
|
+
}
|
|
2398
|
+
if ($('settings').open) renderUpdateSetting();
|
|
2399
|
+
}
|
|
2400
|
+
|
|
2401
|
+
// Settings → Help: whether to check, and what the last check found.
|
|
2402
|
+
function renderUpdateSetting() {
|
|
2403
|
+
const u = snap?.updates;
|
|
2404
|
+
$('update-check').checked = u?.check === true;
|
|
2405
|
+
// A prerelease always hears of the next one, so the choice is made.
|
|
2406
|
+
$('update-prereleases').checked = Boolean(u?.prereleases);
|
|
2407
|
+
$('update-prereleases').disabled = Boolean(u?.onPrerelease);
|
|
2408
|
+
$('update-prereleases-note').hidden = !u?.onPrerelease;
|
|
2409
|
+
if (!u) return;
|
|
2410
|
+
const said = [tr('This is Tabherd {version}.', { version: u.version })];
|
|
2411
|
+
if (u.latest) said.push(tr('{version} is out.', { version: u.latest.version }));
|
|
2412
|
+
else if (u.checkedAt) said.push(tr('It’s the latest: checked {time}.', { time: sinceText(u.checkedAt, true) }));
|
|
2413
|
+
if (u.error) said.push(tr("The last check didn't reach GitHub: {error}", { error: u.error }));
|
|
2414
|
+
$('update-status').textContent = said.join(' ');
|
|
2415
|
+
}
|
|
2416
|
+
|
|
2417
|
+
// A release's notes, from GitHub's Markdown, as plain paragraphs and lists:
|
|
2418
|
+
// links, bold and code show as their text. The line every release starts
|
|
2419
|
+
// with, saying what Tabherd is, and the link to the signing policy are left out.
|
|
2420
|
+
function releaseNotes(markdown) {
|
|
2421
|
+
const plain = (s) =>
|
|
2422
|
+
s
|
|
2423
|
+
.replace(/\[([^\]]*)\]\([^)]*\)/g, '$1')
|
|
2424
|
+
.replace(/\*\*|`/g, '')
|
|
2425
|
+
.replace(/(^|\W)\*([^*]+)\*/g, '$1$2')
|
|
2426
|
+
.trim();
|
|
2427
|
+
const blocks = [];
|
|
2428
|
+
let items = null;
|
|
2429
|
+
for (const line of String(markdown || '').split(/\r?\n/)) {
|
|
2430
|
+
const text = line.trim();
|
|
2431
|
+
const item = /^[-*]\s+(.*)$/.exec(text);
|
|
2432
|
+
if (!text || text.startsWith('**Tabherd** is a dashboard') || text.startsWith('[Code signing policy]')) items = null;
|
|
2433
|
+
else if (item) {
|
|
2434
|
+
if (!items) blocks.push((items = el('ul')));
|
|
2435
|
+
items.append(el('li', { text: plain(item[1]) }));
|
|
2436
|
+
} else {
|
|
2437
|
+
items = null;
|
|
2438
|
+
blocks.push(el('p', { text: plain(text) }));
|
|
2439
|
+
}
|
|
2440
|
+
}
|
|
2441
|
+
return blocks;
|
|
2442
|
+
}
|
|
2443
|
+
|
|
2444
|
+
// What's new in the newer version, and how to update this copy.
|
|
2445
|
+
async function openUpdate() {
|
|
2446
|
+
let info = null;
|
|
2447
|
+
try {
|
|
2448
|
+
const res = await fetch('/api/updates', { cache: 'no-store' });
|
|
2449
|
+
if (res.ok) info = await res.json();
|
|
2450
|
+
} catch {}
|
|
2451
|
+
const latest = info?.latest;
|
|
2452
|
+
if (!latest) return toast(tr("There's no newer version."));
|
|
2453
|
+
const dialog = $('update-dialog');
|
|
2454
|
+
$('update-title').textContent = tr('Tabherd {version} is out', { version: latest.version });
|
|
2455
|
+
$('update-current').textContent = [
|
|
2456
|
+
tr('You have {version}.', { version: info.version }),
|
|
2457
|
+
latest.prerelease ? tr('This one is a prerelease, to try before a release has it.') : '',
|
|
2458
|
+
]
|
|
2459
|
+
.filter(Boolean)
|
|
2460
|
+
.join(' ');
|
|
2461
|
+
$('update-notes').replaceChildren(...releaseNotes(latest.notes));
|
|
2462
|
+
const how = HOW_TO_UPDATE[info.install] || HOW_TO_UPDATE.archive;
|
|
2463
|
+
const command = typeof how.command === 'function' ? how.command(latest.version) : how.command;
|
|
2464
|
+
$('update-how').textContent = how.text;
|
|
2465
|
+
$('update-command').hidden = !command;
|
|
2466
|
+
$('update-command-text').textContent = command || '';
|
|
2467
|
+
$('update-release').href = latest.url;
|
|
2468
|
+
dialog.dataset.version = latest.version;
|
|
2469
|
+
dialog.returnValue = '';
|
|
2470
|
+
dialog.showModal();
|
|
2471
|
+
}
|
|
2472
|
+
|
|
2473
|
+
async function answerUpdateCheck(yes) {
|
|
2474
|
+
if (!(await saveServerSetting({ updateCheck: yes }))) return;
|
|
2475
|
+
$('update-ask').hidden = true;
|
|
2476
|
+
toast(yes ? tr('Tabherd will tell you when a new version is out.') : tr("It won't check. Settings → Help can turn it on."));
|
|
2477
|
+
refresh();
|
|
2478
|
+
}
|
|
2479
|
+
|
|
2480
|
+
$('update-button').addEventListener('click', () => openUpdate());
|
|
2481
|
+
$('update-ask-yes').addEventListener('click', () => answerUpdateCheck(true));
|
|
2482
|
+
$('update-ask-no').addEventListener('click', () => answerUpdateCheck(false));
|
|
2483
|
+
$('update-copy').addEventListener('click', async () => {
|
|
2484
|
+
await copy($('update-command-text').textContent);
|
|
2485
|
+
toast(tr('Command copied'));
|
|
2486
|
+
});
|
|
2487
|
+
$('update-dialog').addEventListener('close', (e) => {
|
|
2488
|
+
const dialog = e.currentTarget;
|
|
2489
|
+
if (dialog.returnValue !== 'later') return;
|
|
2490
|
+
updateDismissed = dialog.dataset.version;
|
|
2491
|
+
try {
|
|
2492
|
+
localStorage.setItem(UPDATE_DISMISSED_KEY, updateDismissed);
|
|
2493
|
+
} catch {}
|
|
2494
|
+
$('update-button').hidden = true;
|
|
2495
|
+
});
|
|
2496
|
+
$('update-check').addEventListener('change', (e) => saveServerSetting({ updateCheck: e.currentTarget.checked }).then(() => refresh()));
|
|
2497
|
+
$('update-prereleases').addEventListener('change', (e) => saveServerSetting({ updatePrereleases: e.currentTarget.checked }).then(() => refresh()));
|
|
2498
|
+
// Check now asks whatever the setting is, as it's asked for.
|
|
2499
|
+
$('update-now').addEventListener('click', async (e) => {
|
|
2500
|
+
const button = e.currentTarget;
|
|
2501
|
+
button.disabled = true;
|
|
2502
|
+
try {
|
|
2503
|
+
const u = await api('/api/updates/check');
|
|
2504
|
+
toast(u.latest ? tr('Tabherd {version} is out', { version: u.latest.version }) : tr('You have the latest version.'));
|
|
2505
|
+
await refresh();
|
|
2506
|
+
} catch (err) {
|
|
2507
|
+
toast(err.message, true);
|
|
2508
|
+
} finally {
|
|
2509
|
+
button.disabled = false;
|
|
2510
|
+
}
|
|
2511
|
+
});
|
|
2512
|
+
|
|
2513
|
+
function apply(next) {
|
|
2514
|
+
snap = next;
|
|
2515
|
+
clockSkew = snap.now - Date.now();
|
|
2516
|
+
$('conn').className = 'conn live';
|
|
2517
|
+
$('updated').textContent = tr('Live · {time}', { time: new Date(snap.now).toLocaleTimeString(lang) });
|
|
2518
|
+
list.classList.remove('stale');
|
|
2519
|
+
const changes = notableChanges(snap.agents);
|
|
2520
|
+
// The cards hold still while the tour runs; dings and notifications don't.
|
|
2521
|
+
if (!tourOn) render();
|
|
2522
|
+
announce(changes);
|
|
2523
|
+
updateNotes(snap.agents, changes);
|
|
2524
|
+
showUpdates();
|
|
2525
|
+
if (tourPending) startTourWhenSettled();
|
|
2526
|
+
}
|
|
2527
|
+
|
|
2528
|
+
function disconnected() {
|
|
2529
|
+
$('conn').className = 'conn down';
|
|
2530
|
+
$('updated').textContent = tr('Disconnected. Is the server running?');
|
|
2531
|
+
list.classList.add('stale');
|
|
2532
|
+
}
|
|
2533
|
+
|
|
2534
|
+
// A one-off update, so an action's effect shows without waiting for a push.
|
|
2535
|
+
async function refresh() {
|
|
2536
|
+
try {
|
|
2537
|
+
const res = await fetch('/api/agents', { cache: 'no-store' });
|
|
2538
|
+
if (res.ok) apply(await res.json());
|
|
2539
|
+
} catch {}
|
|
2540
|
+
}
|
|
2541
|
+
|
|
2542
|
+
function connect() {
|
|
2543
|
+
const source = new EventSource('/api/stream');
|
|
2544
|
+
source.onmessage = (e) => apply(JSON.parse(e.data));
|
|
2545
|
+
// EventSource reconnects by itself.
|
|
2546
|
+
source.onerror = disconnected;
|
|
2547
|
+
}
|
|
2548
|
+
|
|
2549
|
+
function confirmStop(a) {
|
|
2550
|
+
const dialog = $('confirm');
|
|
2551
|
+
$('confirm-name').textContent = displayName(a);
|
|
2552
|
+
// Codex and OpenCode run the session in a background service: Stop
|
|
2553
|
+
// interrupts its turn there, then ends the app in its window, if that's known.
|
|
2554
|
+
$('confirm-what').textContent =
|
|
2555
|
+
a.app !== 'codex' && a.app !== 'opencode'
|
|
2556
|
+
? tr("This force-ends PID {pid} along with its shells and MCP servers. Anything the current turn hasn't saved is lost.", { pid: a.pid })
|
|
2557
|
+
: a.pid
|
|
2558
|
+
? a.app === 'codex'
|
|
2559
|
+
? tr("This interrupts its current turn and ends Codex in its window, PID {pid}. What the turn hasn't finished is lost.", { pid: a.pid })
|
|
2560
|
+
: tr("This interrupts its current turn and ends OpenCode in its window, PID {pid}. What the turn hasn't finished is lost.", { pid: a.pid })
|
|
2561
|
+
: tr("This interrupts its current turn. What the turn hasn't finished is lost. Its window isn't known, so close that yourself.");
|
|
2562
|
+
$('confirm-resume').textContent = resumeCommand(a);
|
|
2563
|
+
dialog.returnValue = '';
|
|
2564
|
+
dialog.onclose = async () => {
|
|
2565
|
+
if (dialog.returnValue !== 'stop') return;
|
|
2566
|
+
try {
|
|
2567
|
+
if (a.background) stoppedHere.add(a.id);
|
|
2568
|
+
const r = await post(a, 'stop');
|
|
2569
|
+
toast(r.windowLeft ? tr('Interrupted {name}. Close its window to end it.', { name: displayName(a) }) : tr('Stopped {name}', { name: displayName(a) }));
|
|
2570
|
+
} catch (err) {
|
|
2571
|
+
toast(err.message, true);
|
|
2572
|
+
}
|
|
2573
|
+
refresh();
|
|
2574
|
+
};
|
|
2575
|
+
dialog.showModal();
|
|
2576
|
+
}
|
|
2577
|
+
|
|
2578
|
+
// ---- repo menu ---------------------------------------------------------------
|
|
2579
|
+
|
|
2580
|
+
const OPEN_FOLDERS_KEY = 'tabherd:open-folders';
|
|
2581
|
+
let repoData = null;
|
|
2582
|
+
let openFolders = new Set();
|
|
2583
|
+
try {
|
|
2584
|
+
openFolders = new Set(JSON.parse(localStorage.getItem(OPEN_FOLDERS_KEY) || '[]'));
|
|
2585
|
+
} catch {}
|
|
2586
|
+
|
|
2587
|
+
function saveOpenFolders() {
|
|
2588
|
+
try {
|
|
2589
|
+
localStorage.setItem(OPEN_FOLDERS_KEY, JSON.stringify([...openFolders]));
|
|
2590
|
+
} catch {}
|
|
2591
|
+
}
|
|
2592
|
+
|
|
2593
|
+
function filterTerms() {
|
|
2594
|
+
return $('repos-filter').value.toLowerCase().split(/\s+/).filter(Boolean);
|
|
2595
|
+
}
|
|
2596
|
+
|
|
2597
|
+
// How many running sessions have their folder in this repo.
|
|
2598
|
+
function sessionsIn(repoPath) {
|
|
2599
|
+
const dir = `${repoData.root}\\${repoPath.replace(/\//g, '\\')}`.toLowerCase();
|
|
2600
|
+
return (snap?.agents || []).filter((a) => {
|
|
2601
|
+
const cwd = (a.cwd || '').toLowerCase();
|
|
2602
|
+
return cwd === dir || cwd.startsWith(`${dir}\\`);
|
|
2603
|
+
}).length;
|
|
2604
|
+
}
|
|
2605
|
+
|
|
2606
|
+
// Every word must be in the repo's path and at least one in its own name, so
|
|
2607
|
+
// "acme" finds the acme repos rather than everything under the Acme folder,
|
|
2608
|
+
// while "api auth" still finds Api-Repos/_wt/auth.
|
|
2609
|
+
function repoMatches(node, terms) {
|
|
2610
|
+
const p = node.path.toLowerCase();
|
|
2611
|
+
const name = node.name.toLowerCase();
|
|
2612
|
+
return terms.every((t) => p.includes(t)) && terms.some((t) => name.includes(t));
|
|
2613
|
+
}
|
|
2614
|
+
|
|
2615
|
+
// A dot in the colour of the group that has this folder or repo among its
|
|
2616
|
+
// folders, if one does.
|
|
2617
|
+
function folderGroupDot(node) {
|
|
2618
|
+
if (!repoData) return null;
|
|
2619
|
+
const sep = repoSep();
|
|
2620
|
+
const full = `${repoData.root}${sep}${node.path.split('/').join(sep)}`.toLowerCase();
|
|
2621
|
+
const g = (snap?.groups || []).find((x) => x.folders.some((f) => f.toLowerCase() === full));
|
|
2622
|
+
return g ? el('span', { class: `group-dot g-${g.color}`, title: tr('Group: {group}', { group: g.name }) }) : null;
|
|
2623
|
+
}
|
|
2624
|
+
|
|
2625
|
+
function repoItem(node, terms) {
|
|
2626
|
+
if (terms.length && !repoMatches(node, terms)) return null;
|
|
2627
|
+
const live = sessionsIn(node.path);
|
|
2628
|
+
return el(
|
|
2629
|
+
'li',
|
|
2630
|
+
{},
|
|
2631
|
+
el(
|
|
2632
|
+
'button',
|
|
2633
|
+
{
|
|
2634
|
+
type: 'button',
|
|
2635
|
+
class: 'repo',
|
|
2636
|
+
'data-path': node.path,
|
|
2637
|
+
title: repoPick ? tr('Use {folder}', { folder: node.path }) : tr('Open {app} in {folder}', { app: APPS[repoData.app] || APPS.claude, folder: node.path }),
|
|
2638
|
+
onclick: (e) => (repoPick ? pickRepo(node, e.currentTarget) : openRepo(node, e.currentTarget)),
|
|
2639
|
+
},
|
|
2640
|
+
el('span', { class: 'repo-name', text: node.name }),
|
|
2641
|
+
folderGroupDot(node),
|
|
2642
|
+
live
|
|
2643
|
+
? el('span', { class: 'repo-live', title: trn(live, '{n} session running here', '{n} sessions running here') }, el('span', { class: 'dot' }), String(live))
|
|
2644
|
+
: null,
|
|
2645
|
+
),
|
|
2646
|
+
);
|
|
2647
|
+
}
|
|
2648
|
+
|
|
2649
|
+
function folderItem(node, terms) {
|
|
2650
|
+
const list = treeList(node.children, terms);
|
|
2651
|
+
if (!list) return null;
|
|
2652
|
+
return el(
|
|
2653
|
+
'li',
|
|
2654
|
+
{},
|
|
2655
|
+
el(
|
|
2656
|
+
'details',
|
|
2657
|
+
{
|
|
2658
|
+
'data-path': node.path,
|
|
2659
|
+
// While filtering, every folder with a match is open.
|
|
2660
|
+
open: terms.length > 0 || openFolders.has(node.path),
|
|
2661
|
+
ontoggle: (e) => {
|
|
2662
|
+
if (filterTerms().length) return;
|
|
2663
|
+
if (e.currentTarget.open) openFolders.add(node.path);
|
|
2664
|
+
else openFolders.delete(node.path);
|
|
2665
|
+
saveOpenFolders();
|
|
2666
|
+
},
|
|
2667
|
+
},
|
|
2668
|
+
el(
|
|
2669
|
+
'summary',
|
|
2670
|
+
{},
|
|
2671
|
+
el('span', { class: 'chev' }),
|
|
2672
|
+
el('span', { class: 'folder-name', text: node.name }),
|
|
2673
|
+
folderGroupDot(node),
|
|
2674
|
+
el('span', { class: 'folder-count', text: String(list.querySelectorAll('.repo').length) }),
|
|
2675
|
+
),
|
|
2676
|
+
list,
|
|
2677
|
+
),
|
|
2678
|
+
);
|
|
2679
|
+
}
|
|
2680
|
+
|
|
2681
|
+
function treeList(nodes, terms) {
|
|
2682
|
+
const items = nodes.map((n) => (n.repo ? repoItem(n, terms) : folderItem(n, terms))).filter(Boolean);
|
|
2683
|
+
return items.length ? el('ul', {}, items) : null;
|
|
2684
|
+
}
|
|
2685
|
+
|
|
2686
|
+
function renderRepos() {
|
|
2687
|
+
if (!repoData) return;
|
|
2688
|
+
const terms = filterTerms();
|
|
2689
|
+
const list = treeList(repoData.tree, terms);
|
|
2690
|
+
$('repos-tree').replaceChildren(list || el('p', { class: 'tree-empty', text: terms.length ? tr('No repos match.') : tr('No git repos found.') }));
|
|
2691
|
+
}
|
|
2692
|
+
|
|
2693
|
+
async function loadRepos(refresh) {
|
|
2694
|
+
try {
|
|
2695
|
+
const res = await fetch(`/api/repos${refresh ? '?refresh=1' : ''}`, { cache: 'no-store' });
|
|
2696
|
+
if (!res.ok) throw new Error(tr("Couldn't list repos (HTTP {status})", { status: res.status }));
|
|
2697
|
+
repoData = await res.json();
|
|
2698
|
+
const excluded = repoData.excluded ? ` · ${tr('{n} hidden', { n: repoData.excluded })}` : '';
|
|
2699
|
+
$('repos-root').textContent = `${shortPath(repoData.root)} · ${trn(repoData.count, '{n} repo', '{n} repos')}${excluded}`;
|
|
2700
|
+
$('repos-root').title = excluded ? tr('Change what is hidden in Settings') : '';
|
|
2701
|
+
$('repos-command').textContent = repoData.command;
|
|
2702
|
+
// Claude or Codex, once Codex is installed; it's the setting in Settings.
|
|
2703
|
+
$('repos-app').hidden = !otherAppsInstalled();
|
|
2704
|
+
showInstalledChoices('repos-app');
|
|
2705
|
+
for (const r of document.querySelectorAll('input[name="repos-app"]')) r.checked = r.value === repoData.app;
|
|
2706
|
+
renderRepos();
|
|
2707
|
+
renderExcluded();
|
|
2708
|
+
renderServerSettings();
|
|
2709
|
+
renderFolderSuggestions();
|
|
2710
|
+
} catch (err) {
|
|
2711
|
+
toast(err.message, true);
|
|
2712
|
+
}
|
|
2713
|
+
}
|
|
2714
|
+
|
|
2715
|
+
async function openRepo(node, button) {
|
|
2716
|
+
button.disabled = true;
|
|
2717
|
+
try {
|
|
2718
|
+
await api('/api/repos/open', { path: node.path });
|
|
2719
|
+
$('repos').close();
|
|
2720
|
+
toast(tr('Opening {app} in {folder}', { app: APPS[repoData.app] || APPS.claude, folder: node.name }));
|
|
2721
|
+
} catch (err) {
|
|
2722
|
+
toast(err.message, true);
|
|
2723
|
+
} finally {
|
|
2724
|
+
button.disabled = false;
|
|
2725
|
+
}
|
|
2726
|
+
}
|
|
2727
|
+
|
|
2728
|
+
// The menu also chooses a to-do's folder. While it does, clicking a repo
|
|
2729
|
+
// picks it rather than opening Claude there.
|
|
2730
|
+
let repoPick = null;
|
|
2731
|
+
|
|
2732
|
+
function openRepoPicker(todo, start) {
|
|
2733
|
+
repoPick = { todo, start };
|
|
2734
|
+
$('repos-title').textContent = tr('Choose a folder');
|
|
2735
|
+
$('repos-foot').hidden = true;
|
|
2736
|
+
$('repos-pick-foot').hidden = false;
|
|
2737
|
+
$('repos-pick-foot').textContent = start ? tr('Click a repo to start “{title}” there.', { title: todo.title }) : tr('Click a repo to use it for “{title}”.', { title: todo.title });
|
|
2738
|
+
$('repos-filter').value = '';
|
|
2739
|
+
$('repos').showModal();
|
|
2740
|
+
$('repos-filter').focus();
|
|
2741
|
+
renderRepos();
|
|
2742
|
+
loadRepos(false).then(showStartFolder);
|
|
2743
|
+
}
|
|
2744
|
+
|
|
2745
|
+
// Opens the folder Settings says to start in, and scrolls to it.
|
|
2746
|
+
function showStartFolder() {
|
|
2747
|
+
const start = serverSettings?.todoStartFolder;
|
|
2748
|
+
if (!repoPick || !start || !repoData) return;
|
|
2749
|
+
const norm = (p) => p.replace(/[\\/]+/g, '/').replace(/\/$/, '').toLowerCase();
|
|
2750
|
+
const root = norm(repoData.root);
|
|
2751
|
+
if (!norm(start).startsWith(`${root}/`)) return;
|
|
2752
|
+
const rel = norm(start).slice(root.length + 1);
|
|
2753
|
+
const node = repoNodes(repoData.tree).find((n) => n.path.toLowerCase() === rel);
|
|
2754
|
+
if (!node) return;
|
|
2755
|
+
const parts = node.path.split('/');
|
|
2756
|
+
for (let i = 1; i <= parts.length; i++) openFolders.add(parts.slice(0, i).join('/'));
|
|
2757
|
+
saveOpenFolders();
|
|
2758
|
+
renderRepos();
|
|
2759
|
+
$('repos-tree').querySelector(`[data-path="${CSS.escape(node.path)}"]`)?.scrollIntoView({ block: 'start' });
|
|
2760
|
+
}
|
|
2761
|
+
|
|
2762
|
+
async function pickRepo(node, button) {
|
|
2763
|
+
const { todo, start } = repoPick;
|
|
2764
|
+
button.disabled = true;
|
|
2765
|
+
try {
|
|
2766
|
+
const r = await api(`/api/todos/${todo.id}/folder`, { repo: node.path });
|
|
2767
|
+
$('repos').close();
|
|
2768
|
+
if (start) await startTodo({ ...todo, cwd: r.cwd });
|
|
2769
|
+
else refresh();
|
|
2770
|
+
} catch (err) {
|
|
2771
|
+
toast(err.message, true);
|
|
2772
|
+
} finally {
|
|
2773
|
+
button.disabled = false;
|
|
2774
|
+
}
|
|
2775
|
+
}
|
|
2776
|
+
|
|
2777
|
+
$('repos').addEventListener('close', () => {
|
|
2778
|
+
if (!repoPick) return;
|
|
2779
|
+
repoPick = null;
|
|
2780
|
+
$('repos-title').textContent = tr('Repositories');
|
|
2781
|
+
$('repos-foot').hidden = false;
|
|
2782
|
+
$('repos-pick-foot').hidden = true;
|
|
2783
|
+
});
|
|
2784
|
+
|
|
2785
|
+
$('menu-button').addEventListener('click', () => {
|
|
2786
|
+
$('repos').showModal();
|
|
2787
|
+
$('repos-filter').focus();
|
|
2788
|
+
loadRepos(false);
|
|
2789
|
+
});
|
|
2790
|
+
$('repos-close').addEventListener('click', () => $('repos').close());
|
|
2791
|
+
$('repos-refresh').addEventListener('click', () => loadRepos(true));
|
|
2792
|
+
$('repos-filter').addEventListener('input', renderRepos);
|
|
2793
|
+
$('repos-filter').addEventListener('keydown', (e) => {
|
|
2794
|
+
// Enter opens the repo when the filter leaves exactly one.
|
|
2795
|
+
const matches = $('repos-tree').querySelectorAll('.repo');
|
|
2796
|
+
if (e.key === 'Enter' && filterTerms().length && matches.length === 1) matches[0].click();
|
|
2797
|
+
});
|
|
2798
|
+
// A click on the backdrop lands on the dialog itself.
|
|
2799
|
+
$('repos').addEventListener('click', (e) => e.target === e.currentTarget && e.currentTarget.close());
|
|
2800
|
+
// #repos opens the menu; #repos/<filter> also fills in the filter.
|
|
2801
|
+
const repoLink = location.hash.match(/^#repos(?:\/(.*))?$/);
|
|
2802
|
+
if (repoLink) {
|
|
2803
|
+
$('repos-filter').value = decodeURIComponent(repoLink[1] || '');
|
|
2804
|
+
$('menu-button').click();
|
|
2805
|
+
}
|
|
2806
|
+
|
|
2807
|
+
// ---- history -------------------------------------------------------------------
|
|
2808
|
+
|
|
2809
|
+
// Closed sessions, newest first, as the server recorded them or read them back
|
|
2810
|
+
// from their transcripts.
|
|
2811
|
+
let historyData = null;
|
|
2812
|
+
|
|
2813
|
+
// A session read back from its transcript has no terminal title or session
|
|
2814
|
+
// name, so it falls back to its title or first prompt.
|
|
2815
|
+
const pastName = (s) => s.terminalTitle || s.title || s.firstPrompt?.text || s.name || shortPath(s.cwd);
|
|
2816
|
+
|
|
2817
|
+
function dayLabel(t) {
|
|
2818
|
+
const d = new Date(t);
|
|
2819
|
+
const midnight = (x) => new Date(x.getFullYear(), x.getMonth(), x.getDate()).getTime();
|
|
2820
|
+
const days = Math.round((midnight(new Date(now())) - midnight(d)) / 86400000);
|
|
2821
|
+
if (days === 0) return tr('Today');
|
|
2822
|
+
if (days === 1) return tr('Yesterday');
|
|
2823
|
+
return d.toLocaleDateString(lang, { weekday: 'long', month: 'short', day: 'numeric' });
|
|
2824
|
+
}
|
|
2825
|
+
|
|
2826
|
+
async function resumePast(s, button) {
|
|
2827
|
+
button.disabled = true;
|
|
2828
|
+
try {
|
|
2829
|
+
await api(`/api/history/${s.id}/resume`);
|
|
2830
|
+
$('history').close();
|
|
2831
|
+
toast(tr('Resuming {name}', { name: pastName(s) }));
|
|
2832
|
+
} catch (err) {
|
|
2833
|
+
toast(err.message, true);
|
|
2834
|
+
} finally {
|
|
2835
|
+
button.disabled = false;
|
|
2836
|
+
}
|
|
2837
|
+
}
|
|
2838
|
+
|
|
2839
|
+
function pastItem(s) {
|
|
2840
|
+
const name = pastName(s);
|
|
2841
|
+
const subtitle = s.title && s.title !== name ? s.title : null;
|
|
2842
|
+
const meta = [];
|
|
2843
|
+
if (s.prompts) meta.push(trn(s.prompts, '{n} prompt', '{n} prompts'));
|
|
2844
|
+
if (s.model) meta.push(modelLabel(s));
|
|
2845
|
+
return el(
|
|
2846
|
+
'li',
|
|
2847
|
+
{ class: 'past' },
|
|
2848
|
+
el(
|
|
2849
|
+
'div',
|
|
2850
|
+
{ class: 'past-head' },
|
|
2851
|
+
el('span', { class: 'past-name', text: name, title: name }),
|
|
2852
|
+
s.completedAt ? el('span', { class: 'tag complete', title: tr('Marked complete: {when}', { when: new Date(s.completedAt).toLocaleString(lang) }), text: `✓ ${tr('Completed')}` }) : null,
|
|
2853
|
+
groupTag(s),
|
|
2854
|
+
appTag(s),
|
|
2855
|
+
since(s.closedAt, true),
|
|
2856
|
+
),
|
|
2857
|
+
subtitle ? el('p', { class: 'past-title', text: subtitle, title: subtitle }) : null,
|
|
2858
|
+
s.todo ? el('p', { class: 'past-title', title: todoText(s.todo) }, el('b', {}, `${tr('To-do')} · `), s.todo.title) : null,
|
|
2859
|
+
el(
|
|
2860
|
+
'div',
|
|
2861
|
+
{ class: 'where' },
|
|
2862
|
+
el('span', { class: 'path', text: shortPath(s.cwd), title: s.cwd }),
|
|
2863
|
+
s.gitBranch ? el('span', { class: 'tag branch', title: tr('Git branch'), text: `⎇ ${s.gitBranch}` }) : null,
|
|
2864
|
+
s.background ? el('span', { class: 'tag background', title: tr('Ran in the background, with claude -p'), text: tr('Background') }) : null,
|
|
2865
|
+
),
|
|
2866
|
+
ticketRow(s.tickets),
|
|
2867
|
+
s.lastPrompt ? el('p', { class: 'past-prompt', title: s.lastPrompt.text }, el('b', {}, `${tr('Last prompt')} · `), s.lastPrompt.text) : null,
|
|
2868
|
+
el(
|
|
2869
|
+
'div',
|
|
2870
|
+
{ class: 'past-actions' },
|
|
2871
|
+
snap?.terminals
|
|
2872
|
+
? el(
|
|
2873
|
+
'button',
|
|
2874
|
+
{ type: 'button', class: 'btn btn-primary', title: tr('Open a terminal tab in its folder and continue the conversation'), onclick: (e) => resumePast(s, e.currentTarget) },
|
|
2875
|
+
tr('Resume'),
|
|
2876
|
+
)
|
|
2877
|
+
: null,
|
|
2878
|
+
el(
|
|
2879
|
+
'button',
|
|
2880
|
+
{
|
|
2881
|
+
type: 'button',
|
|
2882
|
+
class: 'btn',
|
|
2883
|
+
onclick: async () => {
|
|
2884
|
+
await copy(resumeCommand(s));
|
|
2885
|
+
toast(tr('Resume command copied'));
|
|
2886
|
+
},
|
|
2887
|
+
},
|
|
2888
|
+
tr('Copy resume command'),
|
|
2889
|
+
),
|
|
2890
|
+
meta.length ? el('span', { class: 'past-meta', text: meta.join(' · ') }) : null,
|
|
2891
|
+
),
|
|
2892
|
+
);
|
|
2893
|
+
}
|
|
2894
|
+
|
|
2895
|
+
// Every word must appear somewhere in the session's names, folder, branch,
|
|
2896
|
+
// prompts or tickets.
|
|
2897
|
+
function renderHistory() {
|
|
2898
|
+
if (!historyData) return;
|
|
2899
|
+
const terms = $('history-filter').value.toLowerCase().split(/\s+/).filter(Boolean);
|
|
2900
|
+
const background = $('history-background').checked;
|
|
2901
|
+
const complete = $('history-complete').checked;
|
|
2902
|
+
const shown = historyData.filter((s) => {
|
|
2903
|
+
if (s.background && !background) return false;
|
|
2904
|
+
if (s.completedAt && !complete) return false;
|
|
2905
|
+
const tickets = (s.tickets || []).flatMap((t) => [t.key, t.title]);
|
|
2906
|
+
const text = [pastName(s), s.title, s.name, s.cwd, s.gitBranch, s.firstPrompt?.text, s.lastPrompt?.text, s.todo?.title, s.todo?.notes, ...tickets]
|
|
2907
|
+
.join(' ')
|
|
2908
|
+
.toLowerCase();
|
|
2909
|
+
return terms.every((t) => text.includes(t));
|
|
2910
|
+
});
|
|
2911
|
+
const n = historyData.length;
|
|
2912
|
+
const done = historyData.filter((s) => s.completedAt).length;
|
|
2913
|
+
$('history-sub').textContent = [
|
|
2914
|
+
trn(n, '{n} closed session', '{n} closed sessions'),
|
|
2915
|
+
done ? tr('Complete: {n}', { n: done }) : null,
|
|
2916
|
+
shown.length < n ? tr('{n} shown', { n: shown.length }) : null,
|
|
2917
|
+
]
|
|
2918
|
+
.filter(Boolean)
|
|
2919
|
+
.join(' · ');
|
|
2920
|
+
// The switches for background runs and complete sessions only show once there are some.
|
|
2921
|
+
$('history-background-label').hidden = !historyData.some((s) => s.background);
|
|
2922
|
+
$('history-complete-label').hidden = !done;
|
|
2923
|
+
const days = [];
|
|
2924
|
+
for (const s of shown) {
|
|
2925
|
+
const day = dayLabel(s.closedAt);
|
|
2926
|
+
if (days.at(-1)?.day !== day) days.push({ day, sessions: [] });
|
|
2927
|
+
days.at(-1).sessions.push(s);
|
|
2928
|
+
}
|
|
2929
|
+
$('history-list').replaceChildren(
|
|
2930
|
+
...(days.length
|
|
2931
|
+
? days.flatMap((d) => [el('h3', { class: 'history-day', text: d.day }), el('ul', {}, d.sessions.map(pastItem))])
|
|
2932
|
+
: [el('p', { class: 'tree-empty', text: n ? tr('No closed sessions match.') : tr('No sessions have closed in the last 30 days.') })]),
|
|
2933
|
+
);
|
|
2934
|
+
}
|
|
2935
|
+
|
|
2936
|
+
async function loadHistory() {
|
|
2937
|
+
try {
|
|
2938
|
+
const res = await fetch('/api/history', { cache: 'no-store' });
|
|
2939
|
+
if (!res.ok) throw new Error(tr("Couldn't load the history (HTTP {status})", { status: res.status }));
|
|
2940
|
+
historyData = (await res.json()).sessions;
|
|
2941
|
+
renderHistory();
|
|
2942
|
+
} catch (err) {
|
|
2943
|
+
$('history-sub').textContent = err.message;
|
|
2944
|
+
}
|
|
2945
|
+
}
|
|
2946
|
+
|
|
2947
|
+
$('history-button').addEventListener('click', () => {
|
|
2948
|
+
$('history').showModal();
|
|
2949
|
+
$('history-filter').focus();
|
|
2950
|
+
loadHistory();
|
|
2951
|
+
});
|
|
2952
|
+
$('history-close').addEventListener('click', () => $('history').close());
|
|
2953
|
+
$('history-filter').addEventListener('input', renderHistory);
|
|
2954
|
+
// Whether History lists background runs, such as `claude -p` reviews. Kept in this browser.
|
|
2955
|
+
const HISTORY_BACKGROUND_KEY = 'tabherd:history-background';
|
|
2956
|
+
try {
|
|
2957
|
+
$('history-background').checked = localStorage.getItem(HISTORY_BACKGROUND_KEY) !== 'off';
|
|
2958
|
+
} catch {}
|
|
2959
|
+
$('history-background').addEventListener('change', (e) => {
|
|
2960
|
+
try {
|
|
2961
|
+
localStorage.setItem(HISTORY_BACKGROUND_KEY, e.currentTarget.checked ? 'on' : 'off');
|
|
2962
|
+
} catch {}
|
|
2963
|
+
renderHistory();
|
|
2964
|
+
});
|
|
2965
|
+
// Whether History lists sessions marked complete. Kept in this browser.
|
|
2966
|
+
const HISTORY_COMPLETE_KEY = 'tabherd:history-complete';
|
|
2967
|
+
try {
|
|
2968
|
+
$('history-complete').checked = localStorage.getItem(HISTORY_COMPLETE_KEY) !== 'off';
|
|
2969
|
+
} catch {}
|
|
2970
|
+
$('history-complete').addEventListener('change', (e) => {
|
|
2971
|
+
try {
|
|
2972
|
+
localStorage.setItem(HISTORY_COMPLETE_KEY, e.currentTarget.checked ? 'on' : 'off');
|
|
2973
|
+
} catch {}
|
|
2974
|
+
renderHistory();
|
|
2975
|
+
});
|
|
2976
|
+
$('history').addEventListener('click', (e) => e.target === e.currentTarget && e.currentTarget.close());
|
|
2977
|
+
|
|
2978
|
+
// ---- settings ----------------------------------------------------------------
|
|
2979
|
+
|
|
2980
|
+
// A group of radio buttons saved in this browser as tabherd:<name>. The
|
|
2981
|
+
// first value is the default. `apply` runs now and on every change.
|
|
2982
|
+
function radioSetting(name, values, apply) {
|
|
2983
|
+
const key = `tabherd:${name}`;
|
|
2984
|
+
const radios = document.querySelectorAll(`input[name="${name}"]`);
|
|
2985
|
+
let value = values[0];
|
|
2986
|
+
try {
|
|
2987
|
+
const saved = localStorage.getItem(key);
|
|
2988
|
+
if (values.includes(saved)) value = saved;
|
|
2989
|
+
} catch {}
|
|
2990
|
+
const update = () => {
|
|
2991
|
+
for (const r of radios) r.checked = r.value === value;
|
|
2992
|
+
apply(value);
|
|
2993
|
+
};
|
|
2994
|
+
for (const r of radios) {
|
|
2995
|
+
r.addEventListener('change', () => {
|
|
2996
|
+
value = r.value;
|
|
2997
|
+
try {
|
|
2998
|
+
localStorage.setItem(key, value);
|
|
2999
|
+
} catch {}
|
|
3000
|
+
update();
|
|
3001
|
+
});
|
|
3002
|
+
}
|
|
3003
|
+
update();
|
|
3004
|
+
}
|
|
3005
|
+
|
|
3006
|
+
// System follows the system's light or dark mode; Light and Dark override it.
|
|
3007
|
+
radioSetting('theme', ['system', 'light', 'dark'], (theme) => {
|
|
3008
|
+
if (theme === 'system') delete document.documentElement.dataset.theme;
|
|
3009
|
+
else document.documentElement.dataset.theme = theme;
|
|
3010
|
+
});
|
|
3011
|
+
|
|
3012
|
+
// The page's language, from those there's a table for. Automatic follows the
|
|
3013
|
+
// browser's. Changing it reloads the page, which is translated as it loads,
|
|
3014
|
+
// and opens Settings again.
|
|
3015
|
+
const languageSelect = $('language');
|
|
3016
|
+
languageSelect.replaceChildren(
|
|
3017
|
+
el('option', { value: 'auto', text: tr('Automatic ({language})', { language: LANGUAGES[browserLanguage] }) }),
|
|
3018
|
+
...Object.entries(LANGUAGES).map(([value, text]) => el('option', { value, text, lang: value })),
|
|
3019
|
+
);
|
|
3020
|
+
languageSelect.value = languageChoice in LANGUAGES ? languageChoice : 'auto';
|
|
3021
|
+
languageSelect.addEventListener('change', (e) => {
|
|
3022
|
+
try {
|
|
3023
|
+
localStorage.setItem(LANGUAGE_KEY, e.currentTarget.value);
|
|
3024
|
+
sessionStorage.setItem(LANGUAGE_KEY, 'changed');
|
|
3025
|
+
} catch {}
|
|
3026
|
+
location.reload();
|
|
3027
|
+
});
|
|
3028
|
+
|
|
3029
|
+
// Fit lets each card grow to its content; the others make every card the same size.
|
|
3030
|
+
radioSetting('card-size', ['fit', 'small', 'medium', 'large'], (size) => {
|
|
3031
|
+
list.dataset.size = size;
|
|
3032
|
+
list.classList.toggle('uniform', size !== 'fit');
|
|
3033
|
+
});
|
|
3034
|
+
|
|
3035
|
+
// In the desktop app, the window can stay on top of other windows, from
|
|
3036
|
+
// Settings or the pin in the header, and on Windows its background can be
|
|
3037
|
+
// see-through. The app gives the page tabherdApp to say so. Both are kept in
|
|
3038
|
+
// this browser, the app's own, and put back as the page loads.
|
|
3039
|
+
const desktopApp = window.tabherdApp || null;
|
|
3040
|
+
const ON_TOP_KEY = 'tabherd:on-top';
|
|
3041
|
+
const SEE_THROUGH_KEY = 'tabherd:see-through';
|
|
3042
|
+
let onTop = false;
|
|
3043
|
+
let seeThrough = 0;
|
|
3044
|
+
try {
|
|
3045
|
+
onTop = localStorage.getItem(ON_TOP_KEY) === 'on';
|
|
3046
|
+
seeThrough = Math.max(0, Math.min(80, Number(localStorage.getItem(SEE_THROUGH_KEY)) || 0));
|
|
3047
|
+
} catch {}
|
|
3048
|
+
|
|
3049
|
+
async function keepOnTop(on) {
|
|
3050
|
+
try {
|
|
3051
|
+
await desktopApp.setOnTop(on);
|
|
3052
|
+
onTop = on;
|
|
3053
|
+
try {
|
|
3054
|
+
localStorage.setItem(ON_TOP_KEY, on ? 'on' : 'off');
|
|
3055
|
+
} catch {}
|
|
3056
|
+
} catch (err) {
|
|
3057
|
+
toast(tr("Couldn't change that: {error}", { error: err }), true);
|
|
3058
|
+
}
|
|
3059
|
+
$('on-top').checked = onTop;
|
|
3060
|
+
$('pin-button').setAttribute('aria-pressed', String(onTop));
|
|
3061
|
+
$('pin-button').title = onTop ? tr('On top of other windows: click to stop') : tr('Keep this window on top of other windows');
|
|
3062
|
+
}
|
|
3063
|
+
|
|
3064
|
+
// A percentage of the background that lets what's behind show through; 0 is off.
|
|
3065
|
+
function showSeeThrough() {
|
|
3066
|
+
document.documentElement.classList.toggle('see-through', seeThrough > 0);
|
|
3067
|
+
document.documentElement.style.setProperty('--see-through', `${seeThrough}%`);
|
|
3068
|
+
$('see-through').value = String(seeThrough);
|
|
3069
|
+
$('see-through-value').textContent = seeThrough ? `${seeThrough}%` : tr('Off');
|
|
3070
|
+
}
|
|
3071
|
+
|
|
3072
|
+
if (desktopApp) {
|
|
3073
|
+
$('window-setting').hidden = false;
|
|
3074
|
+
$('pin-button').hidden = false;
|
|
3075
|
+
$('pin-button').addEventListener('click', () => keepOnTop(!onTop));
|
|
3076
|
+
$('on-top').addEventListener('change', (e) => keepOnTop(e.currentTarget.checked));
|
|
3077
|
+
keepOnTop(onTop);
|
|
3078
|
+
if (desktopApp.seeThrough) {
|
|
3079
|
+
$('see-through-setting').hidden = false;
|
|
3080
|
+
$('see-through').addEventListener('input', (e) => {
|
|
3081
|
+
seeThrough = Number(e.currentTarget.value);
|
|
3082
|
+
try {
|
|
3083
|
+
localStorage.setItem(SEE_THROUGH_KEY, String(seeThrough));
|
|
3084
|
+
} catch {}
|
|
3085
|
+
showSeeThrough();
|
|
3086
|
+
});
|
|
3087
|
+
showSeeThrough();
|
|
3088
|
+
}
|
|
3089
|
+
}
|
|
3090
|
+
|
|
3091
|
+
// In the desktop app the header stands in for the window's title bar. On
|
|
3092
|
+
// Windows and Linux it has the window's buttons; on macOS it leaves room for
|
|
3093
|
+
// the system's, in its top left corner. The cards scroll below it, rather
|
|
3094
|
+
// than the whole page, so the scroll bar doesn't run up beside the buttons.
|
|
3095
|
+
const cardScroller = () => (desktopApp?.titleBar ? document.querySelector('main') : document.scrollingElement);
|
|
3096
|
+
if (desktopApp?.titleBar) {
|
|
3097
|
+
document.documentElement.dataset.titleBar = desktopApp.titleBar;
|
|
3098
|
+
if (desktopApp.titleBar === 'buttons') {
|
|
3099
|
+
$('window-buttons').hidden = false;
|
|
3100
|
+
$('window-minimize').addEventListener('click', () => desktopApp.minimize());
|
|
3101
|
+
$('window-maximize').addEventListener('click', () => desktopApp.toggleMaximize());
|
|
3102
|
+
$('window-close').addEventListener('click', () => desktopApp.close());
|
|
3103
|
+
// Maximize turns into Restore while the window is maximized.
|
|
3104
|
+
const showMaximized = async () => {
|
|
3105
|
+
const maximized = await desktopApp.isMaximized().catch(() => false);
|
|
3106
|
+
const label = maximized ? tr('Restore') : tr('Maximize');
|
|
3107
|
+
$('window-maximize').classList.toggle('maximized', maximized);
|
|
3108
|
+
$('window-maximize').title = label;
|
|
3109
|
+
$('window-maximize').setAttribute('aria-label', label);
|
|
3110
|
+
};
|
|
3111
|
+
addEventListener('resize', showMaximized);
|
|
3112
|
+
showMaximized();
|
|
3113
|
+
}
|
|
3114
|
+
}
|
|
3115
|
+
|
|
3116
|
+
// Folders and repos left out of the repo menu. The server keeps these, for
|
|
3117
|
+
// every browser, as paths under the repos folder with forward slashes.
|
|
3118
|
+
let serverSettings = null;
|
|
3119
|
+
// The terminals this computer offers for new sessions: [{ id, name, available }].
|
|
3120
|
+
let terminalChoices = [];
|
|
3121
|
+
|
|
3122
|
+
const repoSep = () => (repoData?.root.includes('\\') ? '\\' : '/');
|
|
3123
|
+
const showRepoPath = (p) => p.replace(/\//g, repoSep());
|
|
3124
|
+
|
|
3125
|
+
// Every folder and repo in a tree.
|
|
3126
|
+
function repoNodes(nodes, out = []) {
|
|
3127
|
+
for (const n of nodes) {
|
|
3128
|
+
out.push(n);
|
|
3129
|
+
if (n.children) repoNodes(n.children, out);
|
|
3130
|
+
}
|
|
3131
|
+
return out;
|
|
3132
|
+
}
|
|
3133
|
+
|
|
3134
|
+
// Folders opened in this tree. Until the first render, every folder above a
|
|
3135
|
+
// hidden one opens, so what's hidden is in view.
|
|
3136
|
+
let excludedOpen = null;
|
|
3137
|
+
|
|
3138
|
+
const excludedSet = () => new Set((serverSettings?.excludedFolders || []).map((p) => p.toLowerCase()));
|
|
3139
|
+
const excludedFilter = () => $('excluded-filter').value.toLowerCase().split(/\s+/).filter(Boolean);
|
|
3140
|
+
|
|
3141
|
+
// How many repos are in this folder, and how many of them are hidden.
|
|
3142
|
+
function repoTally(node, excluded, hidden = false) {
|
|
3143
|
+
hidden ||= excluded.has(node.path.toLowerCase());
|
|
3144
|
+
if (node.repo) return { total: 1, hidden: hidden ? 1 : 0 };
|
|
3145
|
+
const tally = { total: 0, hidden: 0 };
|
|
3146
|
+
for (const c of node.children) {
|
|
3147
|
+
const t = repoTally(c, excluded, hidden);
|
|
3148
|
+
tally.total += t.total;
|
|
3149
|
+
tally.hidden += t.hidden;
|
|
3150
|
+
}
|
|
3151
|
+
return tally;
|
|
3152
|
+
}
|
|
3153
|
+
|
|
3154
|
+
function setExcluded(node, show) {
|
|
3155
|
+
const list = (serverSettings?.excludedFolders || []).filter((p) => p.toLowerCase() !== node.path.toLowerCase());
|
|
3156
|
+
saveExcluded(show ? list : [...list, node.path]);
|
|
3157
|
+
}
|
|
3158
|
+
|
|
3159
|
+
// A tick box for one folder or repo. Inside a hidden folder it's unticked and
|
|
3160
|
+
// disabled, though the folder or repo keeps its own setting for when the
|
|
3161
|
+
// folder is shown again.
|
|
3162
|
+
function excludedBox(node, excluded, hiddenBy) {
|
|
3163
|
+
const label = showRepoPath(node.path);
|
|
3164
|
+
return el('input', {
|
|
3165
|
+
type: 'checkbox',
|
|
3166
|
+
'data-path': node.path,
|
|
3167
|
+
checked: !hiddenBy && !excluded.has(node.path.toLowerCase()),
|
|
3168
|
+
disabled: !!hiddenBy,
|
|
3169
|
+
title: hiddenBy ? tr('Hidden along with {folder}', { folder: showRepoPath(hiddenBy) }) : null,
|
|
3170
|
+
'aria-label': tr('Show {folder} in the repo menu', { folder: label }),
|
|
3171
|
+
onchange: (e) => setExcluded(node, e.currentTarget.checked),
|
|
3172
|
+
});
|
|
3173
|
+
}
|
|
3174
|
+
|
|
3175
|
+
// Filtering works like the menu's. A folder that matches by itself lists
|
|
3176
|
+
// everything inside it.
|
|
3177
|
+
function excludedItem(node, terms, excluded, hiddenBy) {
|
|
3178
|
+
const matches = terms.length > 0 && repoMatches(node, terms);
|
|
3179
|
+
if (node.repo) {
|
|
3180
|
+
if (terms.length && !matches) return null;
|
|
3181
|
+
return el(
|
|
3182
|
+
'li',
|
|
3183
|
+
{},
|
|
3184
|
+
el('label', { class: 'excluded-repo' }, excludedBox(node, excluded, hiddenBy), el('span', { class: 'repo-name', text: node.name })),
|
|
3185
|
+
);
|
|
3186
|
+
}
|
|
3187
|
+
const off = hiddenBy || (excluded.has(node.path.toLowerCase()) ? node.path : null);
|
|
3188
|
+
const list = excludedList(node.children, matches ? [] : terms, excluded, off);
|
|
3189
|
+
if (!list) return null;
|
|
3190
|
+
const { total, hidden } = repoTally(node, excluded);
|
|
3191
|
+
const count = !hidden ? String(total) : hidden === total ? tr('{n} hidden', { n: total }) : tr('{hidden} of {total} hidden', { hidden, total });
|
|
3192
|
+
// The filter opens folders with matches inside; those aren't remembered.
|
|
3193
|
+
const auto = terms.length > 0 && !matches;
|
|
3194
|
+
return el(
|
|
3195
|
+
'li',
|
|
3196
|
+
{},
|
|
3197
|
+
el(
|
|
3198
|
+
'details',
|
|
3199
|
+
{
|
|
3200
|
+
open: auto || excludedOpen.has(node.path),
|
|
3201
|
+
ontoggle: (e) => {
|
|
3202
|
+
if (auto) return;
|
|
3203
|
+
if (e.currentTarget.open) excludedOpen.add(node.path);
|
|
3204
|
+
else excludedOpen.delete(node.path);
|
|
3205
|
+
},
|
|
3206
|
+
},
|
|
3207
|
+
el(
|
|
3208
|
+
'summary',
|
|
3209
|
+
{},
|
|
3210
|
+
el('span', { class: 'chev' }),
|
|
3211
|
+
excludedBox(node, excluded, hiddenBy),
|
|
3212
|
+
el('span', { class: 'folder-name', text: node.name }),
|
|
3213
|
+
el('span', { class: `folder-count${hidden && hidden < total ? ' some' : ''}`, text: count }),
|
|
3214
|
+
),
|
|
3215
|
+
list,
|
|
3216
|
+
),
|
|
3217
|
+
);
|
|
3218
|
+
}
|
|
3219
|
+
|
|
3220
|
+
function excludedList(nodes, terms, excluded, hiddenBy) {
|
|
3221
|
+
const items = nodes.map((n) => excludedItem(n, terms, excluded, hiddenBy)).filter(Boolean);
|
|
3222
|
+
return items.length ? el('ul', {}, items) : null;
|
|
3223
|
+
}
|
|
3224
|
+
|
|
3225
|
+
function renderExcluded() {
|
|
3226
|
+
const tree = $('excluded-tree');
|
|
3227
|
+
if (!repoData?.all || !serverSettings) {
|
|
3228
|
+
tree.replaceChildren(el('p', { class: 'tree-empty', text: tr('Loading…') }));
|
|
3229
|
+
return;
|
|
3230
|
+
}
|
|
3231
|
+
const excluded = excludedSet();
|
|
3232
|
+
if (!excludedOpen) {
|
|
3233
|
+
// Hidden paths match in any case; the tree needs each folder's path as found.
|
|
3234
|
+
const byLower = new Map(repoNodes(repoData.all).map((n) => [n.path.toLowerCase(), n.path]));
|
|
3235
|
+
excludedOpen = new Set();
|
|
3236
|
+
for (const p of excluded) {
|
|
3237
|
+
const parts = p.split('/');
|
|
3238
|
+
for (let i = 1; i < parts.length; i++) {
|
|
3239
|
+
const found = byLower.get(parts.slice(0, i).join('/'));
|
|
3240
|
+
if (found) excludedOpen.add(found);
|
|
3241
|
+
}
|
|
3242
|
+
}
|
|
3243
|
+
}
|
|
3244
|
+
// Rebuilding the tree would lose focus from the box just clicked.
|
|
3245
|
+
const focused = tree.contains(document.activeElement) ? document.activeElement.dataset.path : null;
|
|
3246
|
+
const terms = excludedFilter();
|
|
3247
|
+
tree.replaceChildren(
|
|
3248
|
+
excludedList(repoData.all, terms, excluded, null) ||
|
|
3249
|
+
el('p', { class: 'tree-empty', text: terms.length ? tr('No folders or repos match.') : tr('No git repos found.') }),
|
|
3250
|
+
);
|
|
3251
|
+
if (focused) tree.querySelector(`input[data-path="${CSS.escape(focused)}"]`)?.focus();
|
|
3252
|
+
|
|
3253
|
+
// Hidden paths that the scan no longer finds can still be removed.
|
|
3254
|
+
const found = new Set(repoNodes(repoData.all).map((n) => n.path.toLowerCase()));
|
|
3255
|
+
const missing = (serverSettings.excludedFolders || []).filter((p) => !found.has(p.toLowerCase()));
|
|
3256
|
+
$('excluded-missing').hidden = !missing.length;
|
|
3257
|
+
$('excluded-list').replaceChildren(
|
|
3258
|
+
...missing.map((p) =>
|
|
3259
|
+
el(
|
|
3260
|
+
'li',
|
|
3261
|
+
{},
|
|
3262
|
+
el('span', { class: 'excluded-path', text: showRepoPath(p), title: showRepoPath(p) }),
|
|
3263
|
+
el(
|
|
3264
|
+
'button',
|
|
3265
|
+
{
|
|
3266
|
+
type: 'button',
|
|
3267
|
+
class: 'icon-btn',
|
|
3268
|
+
title: tr('Stop hiding it'),
|
|
3269
|
+
'aria-label': tr('Stop hiding {folder}', { folder: showRepoPath(p) }),
|
|
3270
|
+
onclick: () => setExcluded({ path: p }, true),
|
|
3271
|
+
},
|
|
3272
|
+
'✕',
|
|
3273
|
+
),
|
|
3274
|
+
),
|
|
3275
|
+
),
|
|
3276
|
+
);
|
|
3277
|
+
}
|
|
3278
|
+
|
|
3279
|
+
async function loadServerSettings() {
|
|
3280
|
+
try {
|
|
3281
|
+
const res = await fetch('/api/settings', { cache: 'no-store' });
|
|
3282
|
+
if (!res.ok) throw new Error(tr("Couldn't load settings (HTTP {status})", { status: res.status }));
|
|
3283
|
+
const data = await res.json();
|
|
3284
|
+
serverSettings = data.settings;
|
|
3285
|
+
terminalChoices = data.terminals || [];
|
|
3286
|
+
renderExcluded();
|
|
3287
|
+
renderServerSettings();
|
|
3288
|
+
} catch (err) {
|
|
3289
|
+
toast(err.message, true);
|
|
3290
|
+
}
|
|
3291
|
+
}
|
|
3292
|
+
|
|
3293
|
+
// Shown only where there's a choice to make. A terminal that isn't found here
|
|
3294
|
+
// stays listed, so a choice made before it was removed still shows.
|
|
3295
|
+
function renderTerminalChoice() {
|
|
3296
|
+
const select = $('terminal-choice');
|
|
3297
|
+
$('terminal-setting').hidden = terminalChoices.length < 2;
|
|
3298
|
+
const current = serverSettings?.terminal || 'auto';
|
|
3299
|
+
select.replaceChildren(
|
|
3300
|
+
el('option', { value: 'auto', text: tr('Automatic') }),
|
|
3301
|
+
...terminalChoices.map((t) =>
|
|
3302
|
+
el('option', { value: t.id, text: t.available ? t.name : tr('{name} (not found)', { name: t.name }), disabled: !t.available && t.id !== current }),
|
|
3303
|
+
),
|
|
3304
|
+
);
|
|
3305
|
+
select.value = current;
|
|
3306
|
+
}
|
|
3307
|
+
|
|
3308
|
+
// The settings kept on the server, other than the repo menu's. The to-do
|
|
3309
|
+
// folder box isn't changed under someone typing in it.
|
|
3310
|
+
function renderServerSettings() {
|
|
3311
|
+
for (const [id, key] of APP_ADDRESSES) {
|
|
3312
|
+
if (document.activeElement !== $(id)) $(id).value = serverSettings?.[key] || '';
|
|
3313
|
+
}
|
|
3314
|
+
$('lmstudio-key').placeholder = serverSettings?.lmstudioKeySet ? tr('Set. Type a new one to change it') : tr('None');
|
|
3315
|
+
const key = $('localai-key');
|
|
3316
|
+
key.placeholder = serverSettings?.localaiKeySet ? tr('Set. Type a new one to change it') : tr('None');
|
|
3317
|
+
$('app-setting').hidden = !otherAppsInstalled();
|
|
3318
|
+
showInstalledChoices('new-app');
|
|
3319
|
+
const app = serverSettings?.newSessionApp || 'claude';
|
|
3320
|
+
for (const r of document.querySelectorAll('input[name="new-app"]')) r.checked = r.value === app;
|
|
3321
|
+
$('skip-permissions').checked = Boolean(serverSettings?.skipPermissions);
|
|
3322
|
+
const source = serverSettings?.todoFolderSource || 'repos';
|
|
3323
|
+
for (const r of document.querySelectorAll('input[name="todo-source"]')) r.checked = r.value === source;
|
|
3324
|
+
const input = $('todo-start');
|
|
3325
|
+
if (repoData) input.placeholder = shortPath(repoData.root);
|
|
3326
|
+
if (document.activeElement !== input) input.value = shortPath(serverSettings?.todoStartFolder || '');
|
|
3327
|
+
renderTerminalChoice();
|
|
3328
|
+
}
|
|
3329
|
+
|
|
3330
|
+
async function saveServerSetting(changes) {
|
|
3331
|
+
try {
|
|
3332
|
+
serverSettings = (await api('/api/settings', changes)).settings;
|
|
3333
|
+
if ('todoStartFolder' in changes) $('todo-start').value = shortPath(serverSettings.todoStartFolder);
|
|
3334
|
+
renderServerSettings();
|
|
3335
|
+
return true;
|
|
3336
|
+
} catch (err) {
|
|
3337
|
+
toast(err.message, true);
|
|
3338
|
+
renderServerSettings();
|
|
3339
|
+
return false;
|
|
3340
|
+
}
|
|
3341
|
+
}
|
|
3342
|
+
|
|
3343
|
+
$('skip-permissions').addEventListener('change', (e) => saveServerSetting({ skipPermissions: e.currentTarget.checked }));
|
|
3344
|
+
for (const [id, key] of APP_ADDRESSES) {
|
|
3345
|
+
$(id).addEventListener('change', (e) => saveServerSetting({ [key]: e.currentTarget.value }));
|
|
3346
|
+
$(id).addEventListener('keydown', noSubmit((input) => input.blur()));
|
|
3347
|
+
}
|
|
3348
|
+
$('lmstudio-key').addEventListener('change', async (e) => {
|
|
3349
|
+
const input = e.currentTarget;
|
|
3350
|
+
if (await saveServerSetting({ lmstudioKey: input.value })) input.value = '';
|
|
3351
|
+
});
|
|
3352
|
+
$('lmstudio-key').addEventListener('keydown', noSubmit((input) => input.blur()));
|
|
3353
|
+
// The key box is left empty; what's typed replaces the key, and it's cleared
|
|
3354
|
+
// once saved, so the key is never shown.
|
|
3355
|
+
$('localai-key').addEventListener('change', async (e) => {
|
|
3356
|
+
const input = e.currentTarget;
|
|
3357
|
+
if (await saveServerSetting({ localaiKey: input.value })) input.value = '';
|
|
3358
|
+
});
|
|
3359
|
+
$('localai-key').addEventListener('keydown', noSubmit((input) => input.blur()));
|
|
3360
|
+
for (const r of document.querySelectorAll('input[name="new-app"]')) {
|
|
3361
|
+
r.addEventListener('change', () => saveServerSetting({ newSessionApp: r.value }).then(() => refresh()));
|
|
3362
|
+
}
|
|
3363
|
+
// The repo menu's own Claude or Codex choice is the same setting.
|
|
3364
|
+
for (const r of document.querySelectorAll('input[name="repos-app"]')) {
|
|
3365
|
+
r.addEventListener('change', async () => {
|
|
3366
|
+
if (await saveServerSetting({ newSessionApp: r.value })) await loadRepos(false);
|
|
3367
|
+
refresh();
|
|
3368
|
+
});
|
|
3369
|
+
}
|
|
3370
|
+
$('terminal-choice').addEventListener('change', (e) => saveServerSetting({ terminal: e.currentTarget.value }));
|
|
3371
|
+
for (const r of document.querySelectorAll('input[name="todo-source"]')) {
|
|
3372
|
+
r.addEventListener('change', () => saveServerSetting({ todoFolderSource: r.value }));
|
|
3373
|
+
}
|
|
3374
|
+
$('todo-start').addEventListener('change', (e) => saveServerSetting({ todoStartFolder: e.currentTarget.value }));
|
|
3375
|
+
$('todo-start').addEventListener('keydown', (e) => {
|
|
3376
|
+
if (e.key !== 'Enter') return;
|
|
3377
|
+
// Enter would otherwise submit the dialog's form, which closes it.
|
|
3378
|
+
e.preventDefault();
|
|
3379
|
+
saveServerSetting({ todoStartFolder: e.currentTarget.value });
|
|
3380
|
+
});
|
|
3381
|
+
|
|
3382
|
+
// The tree changes at once and the saves go out one at a time, in order. Only
|
|
3383
|
+
// the latest save's reply is shown, so quick clicks don't flicker back.
|
|
3384
|
+
let excludedSaving = Promise.resolve();
|
|
3385
|
+
let excludedSaves = 0;
|
|
3386
|
+
|
|
3387
|
+
function saveExcluded(list) {
|
|
3388
|
+
const n = ++excludedSaves;
|
|
3389
|
+
serverSettings = { ...serverSettings, excludedFolders: list };
|
|
3390
|
+
renderExcluded();
|
|
3391
|
+
excludedSaving = excludedSaving.then(async () => {
|
|
3392
|
+
try {
|
|
3393
|
+
const saved = (await api('/api/settings', { excludedFolders: list })).settings;
|
|
3394
|
+
if (n === excludedSaves) serverSettings = saved;
|
|
3395
|
+
} catch (err) {
|
|
3396
|
+
toast(err.message, true);
|
|
3397
|
+
if (n === excludedSaves) await loadServerSettings();
|
|
3398
|
+
}
|
|
3399
|
+
if (n === excludedSaves) await loadRepos(false);
|
|
3400
|
+
});
|
|
3401
|
+
}
|
|
3402
|
+
|
|
3403
|
+
$('excluded-filter').addEventListener('input', renderExcluded);
|
|
3404
|
+
$('excluded-filter').addEventListener('keydown', (e) => {
|
|
3405
|
+
// Enter would otherwise submit the dialog's form, which closes it.
|
|
3406
|
+
if (e.key === 'Enter') e.preventDefault();
|
|
3407
|
+
});
|
|
3408
|
+
|
|
3409
|
+
// ---- group settings ------------------------------------------------------------
|
|
3410
|
+
|
|
3411
|
+
// Sections by group is kept in this browser, like the card size.
|
|
3412
|
+
const SECTIONS_KEY = 'tabherd:group-sections';
|
|
3413
|
+
let sectionsOn = false;
|
|
3414
|
+
try {
|
|
3415
|
+
sectionsOn = localStorage.getItem(SECTIONS_KEY) === 'on';
|
|
3416
|
+
} catch {}
|
|
3417
|
+
$('group-sections').checked = sectionsOn;
|
|
3418
|
+
$('group-sections').addEventListener('change', (e) => {
|
|
3419
|
+
sectionsOn = e.currentTarget.checked;
|
|
3420
|
+
try {
|
|
3421
|
+
localStorage.setItem(SECTIONS_KEY, sectionsOn ? 'on' : 'off');
|
|
3422
|
+
} catch {}
|
|
3423
|
+
render();
|
|
3424
|
+
});
|
|
3425
|
+
|
|
3426
|
+
// The groups as edited here. Every change saves the whole list, one save at a
|
|
3427
|
+
// time, in order; only the latest save's reply is shown.
|
|
3428
|
+
let groupsDraft = null;
|
|
3429
|
+
let groupsSaving = Promise.resolve();
|
|
3430
|
+
let groupSaves = 0;
|
|
3431
|
+
|
|
3432
|
+
const editedGroups = () => groupsDraft || snap?.groups || [];
|
|
3433
|
+
|
|
3434
|
+
function saveGroups(next, focusKey) {
|
|
3435
|
+
const n = ++groupSaves;
|
|
3436
|
+
groupsDraft = next;
|
|
3437
|
+
renderGroupEditor(focusKey);
|
|
3438
|
+
groupsSaving = groupsSaving.then(async () => {
|
|
3439
|
+
try {
|
|
3440
|
+
const saved = (await api('/api/groups', { groups: next })).groups;
|
|
3441
|
+
if (n === groupSaves) {
|
|
3442
|
+
groupsDraft = saved;
|
|
3443
|
+
if (snap) snap = { ...snap, groups: saved };
|
|
3444
|
+
}
|
|
3445
|
+
} catch (err) {
|
|
3446
|
+
toast(err.message, true);
|
|
3447
|
+
if (n === groupSaves) groupsDraft = null;
|
|
3448
|
+
}
|
|
3449
|
+
if (n === groupSaves) {
|
|
3450
|
+
renderGroupEditor();
|
|
3451
|
+
refresh();
|
|
3452
|
+
}
|
|
3453
|
+
});
|
|
3454
|
+
}
|
|
3455
|
+
|
|
3456
|
+
const changeGroup = (g, changes, focusKey) => saveGroups(editedGroups().map((x) => (x.id === g.id ? { ...x, ...changes } : x)), focusKey);
|
|
3457
|
+
|
|
3458
|
+
function addGroupFolder(g, input) {
|
|
3459
|
+
const folder = input.value.trim();
|
|
3460
|
+
if (!folder) return;
|
|
3461
|
+
changeGroup(g, { folders: [...g.folders, folder] }, `add:${g.id}`);
|
|
3462
|
+
}
|
|
3463
|
+
|
|
3464
|
+
// Asks for a second click, like a to-do's Delete.
|
|
3465
|
+
function deleteGroup(g, button) {
|
|
3466
|
+
if (!button.classList.contains('btn-danger')) {
|
|
3467
|
+
button.classList.add('btn-danger');
|
|
3468
|
+
button.textContent = tr('{label}?', { label: tr('Delete') });
|
|
3469
|
+
setTimeout(() => {
|
|
3470
|
+
button.classList.remove('btn-danger');
|
|
3471
|
+
button.textContent = tr('Delete');
|
|
3472
|
+
}, 3000);
|
|
3473
|
+
return;
|
|
3474
|
+
}
|
|
3475
|
+
saveGroups(editedGroups().filter((x) => x.id !== g.id));
|
|
3476
|
+
}
|
|
3477
|
+
|
|
3478
|
+
function groupRow(g) {
|
|
3479
|
+
return el(
|
|
3480
|
+
'div',
|
|
3481
|
+
{ class: `group-row g-${g.color}` },
|
|
3482
|
+
el(
|
|
3483
|
+
'div',
|
|
3484
|
+
{ class: 'group-row-head' },
|
|
3485
|
+
el('span', { class: 'dot' }),
|
|
3486
|
+
el('input', {
|
|
3487
|
+
type: 'text',
|
|
3488
|
+
class: 'group-name',
|
|
3489
|
+
value: g.name,
|
|
3490
|
+
maxlength: '40',
|
|
3491
|
+
'aria-label': tr('Group name'),
|
|
3492
|
+
'data-focus': `name:${g.id}`,
|
|
3493
|
+
onchange: (e) => {
|
|
3494
|
+
const name = e.currentTarget.value.trim();
|
|
3495
|
+
if (name) changeGroup(g, { name });
|
|
3496
|
+
else {
|
|
3497
|
+
e.currentTarget.value = g.name;
|
|
3498
|
+
toast(tr('A group needs a name.'), true);
|
|
3499
|
+
}
|
|
3500
|
+
},
|
|
3501
|
+
onkeydown: noSubmit((input) => input.blur()),
|
|
3502
|
+
}),
|
|
3503
|
+
el('button', { type: 'button', class: 'btn btn-stop', onclick: (e) => deleteGroup(g, e.currentTarget) }, tr('Delete')),
|
|
3504
|
+
),
|
|
3505
|
+
el(
|
|
3506
|
+
'div',
|
|
3507
|
+
{ class: 'swatches', role: 'radiogroup', 'aria-label': tr("{group}'s colour", { group: g.name }) },
|
|
3508
|
+
Object.entries(GROUP_COLORS).map(([color, label]) =>
|
|
3509
|
+
el('button', {
|
|
3510
|
+
type: 'button',
|
|
3511
|
+
role: 'radio',
|
|
3512
|
+
class: `swatch g-${color}`,
|
|
3513
|
+
'aria-checked': String(g.color === color),
|
|
3514
|
+
'aria-label': label,
|
|
3515
|
+
title: label,
|
|
3516
|
+
'data-focus': `color:${g.id}:${color}`,
|
|
3517
|
+
onclick: () => changeGroup(g, { color }, `color:${g.id}:${color}`),
|
|
3518
|
+
}),
|
|
3519
|
+
),
|
|
3520
|
+
),
|
|
3521
|
+
g.folders.length
|
|
3522
|
+
? el(
|
|
3523
|
+
'ul',
|
|
3524
|
+
{ class: 'excluded group-folders' },
|
|
3525
|
+
g.folders.map((f) =>
|
|
3526
|
+
el(
|
|
3527
|
+
'li',
|
|
3528
|
+
{},
|
|
3529
|
+
el('span', { class: 'excluded-path', text: shortPath(f), title: f }),
|
|
3530
|
+
el(
|
|
3531
|
+
'button',
|
|
3532
|
+
{ type: 'button', class: 'icon-btn', title: tr('Remove'), 'aria-label': tr('Remove {folder}', { folder: shortPath(f) }), onclick: () => changeGroup(g, { folders: g.folders.filter((x) => x !== f) }) },
|
|
3533
|
+
'✕',
|
|
3534
|
+
),
|
|
3535
|
+
),
|
|
3536
|
+
),
|
|
3537
|
+
)
|
|
3538
|
+
: el('p', { class: 'settings-help', text: tr('No folders yet, so only sessions moved here by hand are in it.') }),
|
|
3539
|
+
el(
|
|
3540
|
+
'div',
|
|
3541
|
+
{ class: 'group-add-folder' },
|
|
3542
|
+
el('input', {
|
|
3543
|
+
type: 'text',
|
|
3544
|
+
list: 'group-folders',
|
|
3545
|
+
placeholder: tr('Add a folder: a full path, or pick a repo'),
|
|
3546
|
+
'aria-label': tr('Add a folder to {group}', { group: g.name }),
|
|
3547
|
+
autocomplete: 'off',
|
|
3548
|
+
spellcheck: 'false',
|
|
3549
|
+
'data-focus': `add:${g.id}`,
|
|
3550
|
+
onkeydown: noSubmit((input) => addGroupFolder(g, input)),
|
|
3551
|
+
}),
|
|
3552
|
+
el('button', { type: 'button', class: 'btn', onclick: (e) => addGroupFolder(g, e.currentTarget.previousElementSibling) }, tr('Add')),
|
|
3553
|
+
),
|
|
3554
|
+
);
|
|
3555
|
+
}
|
|
3556
|
+
|
|
3557
|
+
// Rebuilt after each change, with focus put back where it was, or on `focusKey`.
|
|
3558
|
+
function renderGroupEditor(focusKey) {
|
|
3559
|
+
const box = $('group-editor');
|
|
3560
|
+
const focused = focusKey || (box.contains(document.activeElement) ? document.activeElement.dataset.focus : null);
|
|
3561
|
+
const groups = editedGroups();
|
|
3562
|
+
box.replaceChildren(...groups.map(groupRow));
|
|
3563
|
+
if (focused) box.querySelector(`[data-focus="${CSS.escape(focused)}"]`)?.focus();
|
|
3564
|
+
}
|
|
3565
|
+
|
|
3566
|
+
// The repo menu's folders and repos, as suggestions for a group's folders.
|
|
3567
|
+
function renderFolderSuggestions() {
|
|
3568
|
+
if (!repoData?.all) return;
|
|
3569
|
+
const sep = repoSep();
|
|
3570
|
+
const paths = repoNodes(repoData.all).map((n) => shortPath(`${repoData.root}${sep}${n.path.split('/').join(sep)}`));
|
|
3571
|
+
$('group-folders').replaceChildren(...paths.map((value) => el('option', { value })));
|
|
3572
|
+
}
|
|
3573
|
+
|
|
3574
|
+
$('group-add').addEventListener('click', () => {
|
|
3575
|
+
const groups = editedGroups();
|
|
3576
|
+
const g = { id: crypto.randomUUID(), name: tr('Group {n}', { n: groups.length + 1 }), color: freeColor(groups), folders: [] };
|
|
3577
|
+
saveGroups([...groups, g], `name:${g.id}`);
|
|
3578
|
+
$('group-editor').querySelector(`[data-focus="name:${g.id}"]`)?.select();
|
|
3579
|
+
});
|
|
3580
|
+
|
|
3581
|
+
$('keep-notes').checked = keepNotes;
|
|
3582
|
+
$('keep-notes').addEventListener('change', (e) => {
|
|
3583
|
+
keepNotes = e.currentTarget.checked;
|
|
3584
|
+
try {
|
|
3585
|
+
localStorage.setItem(KEEP_NOTES_KEY, keepNotes ? 'on' : 'off');
|
|
3586
|
+
} catch {}
|
|
3587
|
+
saveNotes();
|
|
3588
|
+
});
|
|
3589
|
+
|
|
3590
|
+
// Settings shows one section at a time, picked from the list down its left
|
|
3591
|
+
// side. It opens at the last one used, kept in this browser.
|
|
3592
|
+
const SETTINGS_SECTION_KEY = 'tabherd:settings-section';
|
|
3593
|
+
|
|
3594
|
+
function showSettingsSection(id, focus) {
|
|
3595
|
+
const sections = [...document.querySelectorAll('.settings-section')];
|
|
3596
|
+
const shown = sections.find((s) => s.id === id) || sections[0];
|
|
3597
|
+
for (const s of sections) s.hidden = s !== shown;
|
|
3598
|
+
for (const b of $('settings-nav').children) {
|
|
3599
|
+
const on = b.dataset.section === shown.id;
|
|
3600
|
+
b.setAttribute('aria-selected', String(on));
|
|
3601
|
+
b.tabIndex = on ? 0 : -1;
|
|
3602
|
+
if (on && focus) b.focus();
|
|
3603
|
+
}
|
|
3604
|
+
$('settings').querySelector('.settings-panels').scrollTop = 0;
|
|
3605
|
+
try {
|
|
3606
|
+
localStorage.setItem(SETTINGS_SECTION_KEY, shown.id);
|
|
3607
|
+
} catch {}
|
|
3608
|
+
}
|
|
3609
|
+
|
|
3610
|
+
$('settings-nav').replaceChildren(
|
|
3611
|
+
...[...document.querySelectorAll('.settings-section')].map((s) =>
|
|
3612
|
+
el('button', { type: 'button', role: 'tab', 'data-section': s.id, 'aria-controls': s.id, onclick: () => showSettingsSection(s.id) }, s.dataset.title),
|
|
3613
|
+
),
|
|
3614
|
+
);
|
|
3615
|
+
// Up and down arrows move through the list, as in other tab lists.
|
|
3616
|
+
$('settings-nav').addEventListener('keydown', (e) => {
|
|
3617
|
+
if (!['ArrowDown', 'ArrowUp', 'ArrowLeft', 'ArrowRight'].includes(e.key)) return;
|
|
3618
|
+
e.preventDefault();
|
|
3619
|
+
const tabs = [...$('settings-nav').children];
|
|
3620
|
+
const i = tabs.indexOf(document.activeElement);
|
|
3621
|
+
const next = tabs[(i + (e.key === 'ArrowDown' || e.key === 'ArrowRight' ? 1 : tabs.length - 1)) % tabs.length];
|
|
3622
|
+
showSettingsSection(next.dataset.section, true);
|
|
3623
|
+
});
|
|
3624
|
+
|
|
3625
|
+
// Opens Settings, at the section holding `elementId` if given.
|
|
3626
|
+
// ---- Settings → Tickets ------------------------------------------------------
|
|
3627
|
+
|
|
3628
|
+
// The ticket trackers, without their tokens, and how secrets are kept on this
|
|
3629
|
+
// computer. Loaded each time Settings opens.
|
|
3630
|
+
let trackerData = null;
|
|
3631
|
+
// What each tracker's last Test said, by its ID.
|
|
3632
|
+
const trackerTests = new Map();
|
|
3633
|
+
let editingTracker = null;
|
|
3634
|
+
|
|
3635
|
+
const TRACKER_TYPES = { jira: 'Jira', linear: 'Linear', github: 'GitHub Issues', zendesk: 'Zendesk' };
|
|
3636
|
+
// What each type needs, and where its token comes from.
|
|
3637
|
+
const TRACKER_HELP = {
|
|
3638
|
+
jira: tr(
|
|
3639
|
+
"Address: your Jira site. Token: an API token from id.atlassian.com → Security → API tokens, for the email you sign in with. Leave the email empty for a Jira Data Center personal access token. Key prefixes are your projects' keys, to look up only those here; leave them empty to try any key.",
|
|
3640
|
+
),
|
|
3641
|
+
linear: tr("Token: a personal API key, from Linear → Settings → Security & access. Key prefixes are your teams' keys; leave them empty to try any key."),
|
|
3642
|
+
github: tr("Uses gh's own sign-in, so no token is kept here. If Test says so, run gh auth login."),
|
|
3643
|
+
zendesk: tr(
|
|
3644
|
+
'Address: your Zendesk, such as https://example.zendesk.com. An API token is made in Admin Center → Apps and integrations → Zendesk API. Zendesk is replacing API tokens with OAuth access tokens, which work here too. A key prefix, such as ZD, finds ZD-1234 in branch names.',
|
|
3645
|
+
),
|
|
3646
|
+
};
|
|
3647
|
+
const TRACKER_ADDRESSES = { jira: 'https://example.atlassian.net', zendesk: 'https://example.zendesk.com' };
|
|
3648
|
+
const SECRETS_KEPT = {
|
|
3649
|
+
dpapi: tr('Tokens and trackers are saved encrypted, with a key Windows keeps for your user.'),
|
|
3650
|
+
keychain: tr('Tokens and trackers are saved encrypted, with a key kept in your login Keychain.'),
|
|
3651
|
+
'secret-service': tr('Tokens and trackers are saved encrypted, with a key kept in your keyring.'),
|
|
3652
|
+
file: tr('Tokens and trackers are saved encrypted, with a key in ~/.tabherd/secret.key that only you can read. A keyring, such as GNOME Keyring or KWallet, would keep it safer.'),
|
|
3653
|
+
};
|
|
3654
|
+
|
|
3655
|
+
async function loadTrackers() {
|
|
3656
|
+
try {
|
|
3657
|
+
trackerData = await api('/api/tickets/trackers/list');
|
|
3658
|
+
renderTrackers();
|
|
3659
|
+
} catch (err) {
|
|
3660
|
+
$('tracker-protection').textContent = err.message;
|
|
3661
|
+
}
|
|
3662
|
+
}
|
|
3663
|
+
|
|
3664
|
+
function renderTrackers() {
|
|
3665
|
+
if (!trackerData) return;
|
|
3666
|
+
$('tracker-list').replaceChildren(
|
|
3667
|
+
...trackerData.trackers.map((t) => {
|
|
3668
|
+
const tested = trackerTests.get(t.id);
|
|
3669
|
+
const about = [TRACKER_TYPES[t.type], t.url.replace(/^https?:\/\//, ''), t.prefixes.join(', ')].filter(Boolean).join(' · ');
|
|
3670
|
+
let note = null;
|
|
3671
|
+
if (tested?.pending) note = el('span', { text: tr('Testing…') });
|
|
3672
|
+
else if (tested) note = el('span', { class: tested.ok ? 'tracker-ok' : 'tracker-error', text: tested.ok ? tr('Connected as {name}', { name: tested.as }) : tested.error });
|
|
3673
|
+
else if (t.type !== 'github' && !t.tokenSet) note = el('span', { class: 'tracker-error', text: tr('No token yet') });
|
|
3674
|
+
// Its tickets keep their last known status until it answers again.
|
|
3675
|
+
else if (trackerData.problems?.[t.id]) note = el('span', { class: 'tracker-error', text: tr('Looking up tickets: {problem}', { problem: tr(trackerData.problems[t.id].error) }) });
|
|
3676
|
+
return el(
|
|
3677
|
+
'li',
|
|
3678
|
+
{ class: 'filter-row tracker-row' },
|
|
3679
|
+
el('div', { class: 'filter-row-text' }, el('b', { text: t.name }), el('span', { text: about, title: about }), note),
|
|
3680
|
+
el('button', { type: 'button', class: 'btn', disabled: Boolean(tested?.pending), onclick: () => testTracker(t.id) }, tr('Test')),
|
|
3681
|
+
el('button', { type: 'button', class: 'btn', onclick: () => openTrackerDialog(t) }, tr('Edit')),
|
|
3682
|
+
el('button', { type: 'button', class: `btn btn-stop ${armedClass(`tracker:${t.id}`)}`, 'data-armed': `tracker:${t.id}`, onclick: (e) => removeTracker(t, e.currentTarget) }, armedLabel(`tracker:${t.id}`, tr('Remove'))),
|
|
3683
|
+
);
|
|
3684
|
+
}),
|
|
3685
|
+
);
|
|
3686
|
+
const s = trackerData.secrets;
|
|
3687
|
+
const notes = [s.state === 'failed' ? tr("Secrets can't be saved on this computer: {problem}", { problem: tr(s.problem) }) : SECRETS_KEPT[s.protection] || tr('Tokens and trackers are saved encrypted.')];
|
|
3688
|
+
if (s.unreadable?.length) notes.push(tr('Some were encrypted by another user or on another computer, so they count as unset here. Enter them again.'));
|
|
3689
|
+
$('tracker-protection').textContent = notes.join(' ');
|
|
3690
|
+
}
|
|
3691
|
+
|
|
3692
|
+
async function testTracker(id) {
|
|
3693
|
+
trackerTests.set(id, { pending: true });
|
|
3694
|
+
renderTrackers();
|
|
3695
|
+
try {
|
|
3696
|
+
const r = await api('/api/tickets/trackers/test', { id });
|
|
3697
|
+
trackerTests.set(id, { ok: true, as: r.as });
|
|
3698
|
+
} catch (err) {
|
|
3699
|
+
trackerTests.set(id, { ok: false, error: err.message });
|
|
3700
|
+
}
|
|
3701
|
+
renderTrackers();
|
|
3702
|
+
}
|
|
3703
|
+
|
|
3704
|
+
async function removeTracker(t, button) {
|
|
3705
|
+
if (!secondClick(`tracker:${t.id}`, button, tr('Remove'))) return;
|
|
3706
|
+
try {
|
|
3707
|
+
trackerData = await api('/api/tickets/trackers/remove', { id: t.id });
|
|
3708
|
+
trackerTests.delete(t.id);
|
|
3709
|
+
renderTrackers();
|
|
3710
|
+
} catch (err) {
|
|
3711
|
+
toast(err.message, true);
|
|
3712
|
+
}
|
|
3713
|
+
}
|
|
3714
|
+
|
|
3715
|
+
function openTrackerDialog(t = null) {
|
|
3716
|
+
editingTracker = t;
|
|
3717
|
+
$('tracker-dialog-title').textContent = t ? tr('Edit tracker') : tr('New tracker');
|
|
3718
|
+
$('tracker-save').textContent = t ? tr('Save') : tr('Add tracker');
|
|
3719
|
+
// A tracker's type is fixed once it's made.
|
|
3720
|
+
$('tracker-type').value = t?.type || 'jira';
|
|
3721
|
+
$('tracker-type').disabled = Boolean(t);
|
|
3722
|
+
$('tracker-name').value = t?.name || '';
|
|
3723
|
+
$('tracker-url').value = t?.url || '';
|
|
3724
|
+
$('tracker-email').value = t?.email || '';
|
|
3725
|
+
$('tracker-auth').value = t?.auth || 'token';
|
|
3726
|
+
$('tracker-token').value = '';
|
|
3727
|
+
$('tracker-prefixes').value = (t?.prefixes || []).join(', ');
|
|
3728
|
+
showTrackerFields();
|
|
3729
|
+
$('tracker-dialog').showModal();
|
|
3730
|
+
$('tracker-name').focus();
|
|
3731
|
+
}
|
|
3732
|
+
|
|
3733
|
+
// Only the fields the chosen type uses.
|
|
3734
|
+
function showTrackerFields() {
|
|
3735
|
+
const type = $('tracker-type').value;
|
|
3736
|
+
const signsIn = type === 'jira' || type === 'zendesk';
|
|
3737
|
+
$('tracker-url-field').hidden = !signsIn;
|
|
3738
|
+
$('tracker-url').placeholder = TRACKER_ADDRESSES[type] || '';
|
|
3739
|
+
$('tracker-auth-field').hidden = type !== 'zendesk';
|
|
3740
|
+
$('tracker-email-field').hidden = !(type === 'jira' || (type === 'zendesk' && $('tracker-auth').value === 'token'));
|
|
3741
|
+
$('tracker-token-field').hidden = type === 'github';
|
|
3742
|
+
$('tracker-token').placeholder = editingTracker?.tokenSet ? tr('Set. Type a new one to change it') : '';
|
|
3743
|
+
$('tracker-prefixes-field').hidden = type === 'github';
|
|
3744
|
+
$('tracker-help').textContent = TRACKER_HELP[type];
|
|
3745
|
+
}
|
|
3746
|
+
$('tracker-type').addEventListener('change', showTrackerFields);
|
|
3747
|
+
$('tracker-auth').addEventListener('change', showTrackerFields);
|
|
3748
|
+
$('tracker-add').addEventListener('click', () => openTrackerDialog());
|
|
3749
|
+
for (const id of ['tracker-cancel', 'tracker-close']) $(id).addEventListener('click', () => $('tracker-dialog').close());
|
|
3750
|
+
|
|
3751
|
+
$('tracker-form').addEventListener('submit', async (e) => {
|
|
3752
|
+
e.preventDefault();
|
|
3753
|
+
const token = $('tracker-token').value.trim();
|
|
3754
|
+
const tracker = {
|
|
3755
|
+
id: editingTracker?.id,
|
|
3756
|
+
type: $('tracker-type').value,
|
|
3757
|
+
name: $('tracker-name').value,
|
|
3758
|
+
url: $('tracker-url').value,
|
|
3759
|
+
email: $('tracker-email').value,
|
|
3760
|
+
auth: $('tracker-auth').value,
|
|
3761
|
+
prefixes: $('tracker-prefixes').value.split(/[\s,]+/).filter(Boolean),
|
|
3762
|
+
// Left empty while editing, the saved token is kept.
|
|
3763
|
+
...(token || !editingTracker ? { token } : {}),
|
|
3764
|
+
};
|
|
3765
|
+
const button = $('tracker-save');
|
|
3766
|
+
button.disabled = true;
|
|
3767
|
+
try {
|
|
3768
|
+
trackerData = await api('/api/tickets/trackers/save', { tracker });
|
|
3769
|
+
$('tracker-dialog').close();
|
|
3770
|
+
// A new or changed sign-in is tried straight away.
|
|
3771
|
+
testTracker(trackerData.id);
|
|
3772
|
+
} catch (err) {
|
|
3773
|
+
toast(err.message, true);
|
|
3774
|
+
} finally {
|
|
3775
|
+
button.disabled = false;
|
|
3776
|
+
}
|
|
3777
|
+
});
|
|
3778
|
+
|
|
3779
|
+
function openSettings(elementId) {
|
|
3780
|
+
$('settings').showModal();
|
|
3781
|
+
groupsDraft = null;
|
|
3782
|
+
renderGroupEditor();
|
|
3783
|
+
renderFilterSettings();
|
|
3784
|
+
loadTrackers();
|
|
3785
|
+
let section = elementId ? $(elementId)?.closest('.settings-section')?.id : null;
|
|
3786
|
+
if (!section) {
|
|
3787
|
+
try {
|
|
3788
|
+
section = localStorage.getItem(SETTINGS_SECTION_KEY);
|
|
3789
|
+
} catch {}
|
|
3790
|
+
}
|
|
3791
|
+
showSettingsSection(section, true);
|
|
3792
|
+
renderUpdateSetting();
|
|
3793
|
+
loadServerSettings();
|
|
3794
|
+
loadRepos(false);
|
|
3795
|
+
}
|
|
3796
|
+
|
|
3797
|
+
// ---- first-run tour ----------------------------------------------------------
|
|
3798
|
+
|
|
3799
|
+
// A short look around the dashboard, on a browser's first visit and from
|
|
3800
|
+
// Settings → Help. While it runs the page is frozen: the cards don't update,
|
|
3801
|
+
// nothing scrolls, and only the tour can be clicked, so nothing moves under
|
|
3802
|
+
// it. A first visit's tour waits until every session is on the page, so none
|
|
3803
|
+
// look lost.
|
|
3804
|
+
const TOUR_KEY = 'tabherd:tour';
|
|
3805
|
+
let tourOn = false;
|
|
3806
|
+
let tourPending = firstVisit;
|
|
3807
|
+
let tourSteps = [];
|
|
3808
|
+
let tourAt = 0;
|
|
3809
|
+
let tourCard = null;
|
|
3810
|
+
let tourSample = null;
|
|
3811
|
+
|
|
3812
|
+
const sessionCount = () => (snap?.agents || []).filter((a) => !isItem(a) && a.kind !== 'model').length;
|
|
3813
|
+
const tourAll = (selector) => () => [...document.querySelectorAll(selector)];
|
|
3814
|
+
|
|
3815
|
+
const TOUR_STEPS = [
|
|
3816
|
+
{
|
|
3817
|
+
title: tr('Welcome to Tabherd'),
|
|
3818
|
+
text: () => {
|
|
3819
|
+
const n = sessionCount();
|
|
3820
|
+
const yours = n ? ` ${trn(n, 'The one running now is on the page.', 'The {n} running now are on the page.')}` : '';
|
|
3821
|
+
return `${tr('Every Claude Code, Codex and Copilot session on this computer gets a card here, and a ding when it needs you.')}${yours} ${tr(
|
|
3822
|
+
'This is a quick look around: nothing on the page changes while it runs, and your sessions carry on as usual.',
|
|
3823
|
+
)}`;
|
|
3824
|
+
},
|
|
3825
|
+
},
|
|
3826
|
+
{
|
|
3827
|
+
target: () => [tourCard],
|
|
3828
|
+
title: tr('A card for each session'),
|
|
3829
|
+
text: () =>
|
|
3830
|
+
tr(
|
|
3831
|
+
"Its status, Needs you, Working or Idle, and for how long; what it's doing; its last prompt and reply; and its model and tokens. Go to window brings up its terminal tab, and Catch up asks it where things stand.",
|
|
3832
|
+
) + (tourSample ? ` ${tr('This one is only an example, and goes when the tour ends.')}` : ''),
|
|
3833
|
+
},
|
|
3834
|
+
{
|
|
3835
|
+
target: tourAll('#list .memory-card'),
|
|
3836
|
+
title: tr('Memory and models'),
|
|
3837
|
+
text: tr(
|
|
3838
|
+
'Memory in use, on the computer and each graphics card, and the models loaded in ComfyUI, LocalAI, Ollama, LM Studio or llama.cpp, with Unload where it can. Settings → Appearance turns it off.',
|
|
3839
|
+
),
|
|
3840
|
+
},
|
|
3841
|
+
{
|
|
3842
|
+
target: tourAll('#filters'),
|
|
3843
|
+
title: tr('Filters'),
|
|
3844
|
+
text: tr('All, then filters of your own. Each tab counts its cards, in amber when one needs you. The ⋯ at the end makes a new filter or changes the one shown.'),
|
|
3845
|
+
},
|
|
3846
|
+
{
|
|
3847
|
+
target: tourAll('.view-filters > :not([hidden])'),
|
|
3848
|
+
title: tr('Apps and groups'),
|
|
3849
|
+
text: tr("Show only one app's sessions, or one group's. The counts on the tabs follow them."),
|
|
3850
|
+
},
|
|
3851
|
+
{
|
|
3852
|
+
target: tourAll('#menu-button'),
|
|
3853
|
+
title: tr('Your repos'),
|
|
3854
|
+
text: tr('Every repo in your repos folder. Pick one to start a session in it, in a new terminal tab.'),
|
|
3855
|
+
},
|
|
3856
|
+
{
|
|
3857
|
+
target: tourAll('#todo-new'),
|
|
3858
|
+
title: tr('To-dos'),
|
|
3859
|
+
text: tr("Note a task to start later. Its card's Start opens a session for it in its folder, named after it."),
|
|
3860
|
+
},
|
|
3861
|
+
{
|
|
3862
|
+
target: tourAll('#sessions-button, #history-button'),
|
|
3863
|
+
title: tr('Save and close, and History'),
|
|
3864
|
+
text: tr('Save and close every session at once, then resume them all later. History lists the sessions closed in the last 30 days, each with Resume.'),
|
|
3865
|
+
},
|
|
3866
|
+
{
|
|
3867
|
+
target: tourAll('#notes-button, #sound'),
|
|
3868
|
+
title: tr('Notifications and sound'),
|
|
3869
|
+
text: tr(
|
|
3870
|
+
"A ding when a session needs you or finishes, and a list of what happened while you were away. Browsers only play sound once you've clicked the page, so the bell may ask for a click.",
|
|
3871
|
+
),
|
|
3872
|
+
},
|
|
3873
|
+
{
|
|
3874
|
+
target: tourAll('#settings-button'),
|
|
3875
|
+
title: tr('Settings'),
|
|
3876
|
+
text: tr('Theme, card size, groups, filters, the app and terminal new sessions open in, and more. This tour is in Settings → Help whenever you want it again.'),
|
|
3877
|
+
},
|
|
3878
|
+
];
|
|
3879
|
+
|
|
3880
|
+
// The first session card on the page, or else an example one, put in for the
|
|
3881
|
+
// tour and taken out after.
|
|
3882
|
+
function tourSessionCard() {
|
|
3883
|
+
const sessions = new Set((snap?.agents || []).filter((a) => !isItem(a) && a.kind !== 'model').map((a) => a.id));
|
|
3884
|
+
const shown = [...list.children].find((n) => sessions.has(n.dataset.id));
|
|
3885
|
+
if (shown) return shown;
|
|
3886
|
+
const t = now();
|
|
3887
|
+
const sep = snap?.platform === 'win32' ? '\\' : '/';
|
|
3888
|
+
tourSample = card({
|
|
3889
|
+
app: 'claude',
|
|
3890
|
+
id: 'tour-example',
|
|
3891
|
+
pid: 18244,
|
|
3892
|
+
name: 'my-app',
|
|
3893
|
+
title: tr('Add a sign-up page'),
|
|
3894
|
+
cwd: [snap?.home || '', 'projects', 'my-app'].join(sep),
|
|
3895
|
+
gitBranch: 'main',
|
|
3896
|
+
status: 'busy',
|
|
3897
|
+
statusSince: t - 95e3,
|
|
3898
|
+
startedAt: t - 42 * 60e3,
|
|
3899
|
+
tools: [{ name: 'Bash', detail: 'npm test', at: t - 8e3 }],
|
|
3900
|
+
lastReply: { text: tr('The form and its checks are in. Running the tests now.'), at: t - 20e3 },
|
|
3901
|
+
lastPrompt: { text: tr('Add a sign-up page with email and password, and tests for it.'), at: t - 6 * 60e3 },
|
|
3902
|
+
model: 'claude-sonnet-5-5',
|
|
3903
|
+
contextTokens: 61000,
|
|
3904
|
+
contextLimit: 200000,
|
|
3905
|
+
outputTokens: 18400,
|
|
3906
|
+
prompts: 3,
|
|
3907
|
+
});
|
|
3908
|
+
tourSample.classList.add('tour-sample');
|
|
3909
|
+
tourSample.removeAttribute('data-id');
|
|
3910
|
+
// After the memory card, if it's there.
|
|
3911
|
+
const memory = list.querySelector('.memory-card');
|
|
3912
|
+
if (memory) memory.after(tourSample);
|
|
3913
|
+
else list.prepend(tourSample);
|
|
3914
|
+
$('empty').hidden = true;
|
|
3915
|
+
return tourSample;
|
|
3916
|
+
}
|
|
3917
|
+
|
|
3918
|
+
// What a step points at, as one box on screen, or null if it's not showing.
|
|
3919
|
+
function tourRect(step) {
|
|
3920
|
+
if (!step.target) return null;
|
|
3921
|
+
const rects = step
|
|
3922
|
+
.target()
|
|
3923
|
+
.filter(Boolean)
|
|
3924
|
+
.map((n) => n.getBoundingClientRect())
|
|
3925
|
+
.filter((r) => r.width && r.height);
|
|
3926
|
+
if (!rects.length) return null;
|
|
3927
|
+
const left = Math.max(0, Math.min(...rects.map((r) => r.left)));
|
|
3928
|
+
const top = Math.max(0, Math.min(...rects.map((r) => r.top)));
|
|
3929
|
+
const right = Math.min(innerWidth, Math.max(...rects.map((r) => r.right)));
|
|
3930
|
+
const bottom = Math.min(innerHeight, Math.max(...rects.map((r) => r.bottom)));
|
|
3931
|
+
return right > left && bottom > top ? { left, top, right, bottom, width: right - left, height: bottom - top } : null;
|
|
3932
|
+
}
|
|
3933
|
+
|
|
3934
|
+
// Lights up what the step is about, with the panel beside it where there's
|
|
3935
|
+
// room: below, above, to the right or left, else at the bottom of the screen.
|
|
3936
|
+
function placeTour() {
|
|
3937
|
+
const r = tourRect(tourSteps[tourAt]);
|
|
3938
|
+
const spot = $('tour-spot');
|
|
3939
|
+
const panel = $('tour-panel');
|
|
3940
|
+
const pad = 6;
|
|
3941
|
+
const gap = 12;
|
|
3942
|
+
const edge = 12;
|
|
3943
|
+
const pw = panel.offsetWidth;
|
|
3944
|
+
const ph = panel.offsetHeight;
|
|
3945
|
+
const x = (v) => Math.max(edge, Math.min(innerWidth - pw - edge, v));
|
|
3946
|
+
const y = (v) => Math.max(edge, Math.min(innerHeight - ph - edge, v));
|
|
3947
|
+
$('tour').classList.toggle('no-spot', !r);
|
|
3948
|
+
let left = (innerWidth - pw) / 2;
|
|
3949
|
+
let top = (innerHeight - ph) / 2;
|
|
3950
|
+
if (r) {
|
|
3951
|
+
Object.assign(spot.style, { left: `${r.left - pad}px`, top: `${r.top - pad}px`, width: `${r.width + pad * 2}px`, height: `${r.height + pad * 2}px` });
|
|
3952
|
+
const middle = r.left + r.width / 2 - pw / 2;
|
|
3953
|
+
if (r.bottom + pad + gap + ph <= innerHeight - edge) [left, top] = [x(middle), r.bottom + pad + gap];
|
|
3954
|
+
else if (r.top - pad - gap - ph >= edge) [left, top] = [x(middle), r.top - pad - gap - ph];
|
|
3955
|
+
else if (r.right + pad + gap + pw <= innerWidth - edge) [left, top] = [r.right + pad + gap, y(r.top)];
|
|
3956
|
+
else if (r.left - pad - gap - pw >= edge) [left, top] = [r.left - pad - gap - pw, y(r.top)];
|
|
3957
|
+
else [left, top] = [x((innerWidth - pw) / 2), innerHeight - ph - edge];
|
|
3958
|
+
}
|
|
3959
|
+
panel.style.left = `${left}px`;
|
|
3960
|
+
panel.style.top = `${top}px`;
|
|
3961
|
+
}
|
|
3962
|
+
|
|
3963
|
+
function showTourStep(i) {
|
|
3964
|
+
tourAt = i;
|
|
3965
|
+
const step = tourSteps[i];
|
|
3966
|
+
const last = i === tourSteps.length - 1;
|
|
3967
|
+
$('tour-step').textContent = tr('{n} of {total}', { n: i + 1, total: tourSteps.length });
|
|
3968
|
+
$('tour-title').textContent = step.title;
|
|
3969
|
+
$('tour-text').textContent = typeof step.text === 'function' ? step.text() : step.text;
|
|
3970
|
+
$('tour-back').hidden = i === 0;
|
|
3971
|
+
$('tour-next').textContent = i === 0 ? tr('Show me around') : last ? tr('Done') : tr('Next');
|
|
3972
|
+
$('tour-skip').hidden = last;
|
|
3973
|
+
// A card it points at is brought into view below the header, which stays put.
|
|
3974
|
+
const first = step.target?.().find(Boolean);
|
|
3975
|
+
if (first && !first.closest('.top')) {
|
|
3976
|
+
const r = first.getBoundingClientRect();
|
|
3977
|
+
const below = document.querySelector('.top').getBoundingClientRect().bottom + 12;
|
|
3978
|
+
if (r.top < below || r.top > innerHeight / 2) cardScroller().scrollBy(0, r.top - below);
|
|
3979
|
+
}
|
|
3980
|
+
placeTour();
|
|
3981
|
+
$('tour-next').focus();
|
|
3982
|
+
}
|
|
3983
|
+
|
|
3984
|
+
function startTour() {
|
|
3985
|
+
if (tourOn || !snap) return;
|
|
3986
|
+
tourPending = false;
|
|
3987
|
+
// Brought up to date, then frozen.
|
|
3988
|
+
render();
|
|
3989
|
+
tourOn = true;
|
|
3990
|
+
// The update question waits, so the cards don't move under the tour.
|
|
3991
|
+
$('update-ask').hidden = true;
|
|
3992
|
+
cardScroller().scrollTo(0, 0);
|
|
3993
|
+
tourCard = tourSessionCard();
|
|
3994
|
+
tourSteps = TOUR_STEPS.filter((s) => !s.target || tourRect(s));
|
|
3995
|
+
$('tour').showModal();
|
|
3996
|
+
showTourStep(0);
|
|
3997
|
+
try {
|
|
3998
|
+
localStorage.setItem(TOUR_KEY, 'seen');
|
|
3999
|
+
} catch {}
|
|
4000
|
+
}
|
|
4001
|
+
|
|
4002
|
+
// A first visit's tour starts once the sessions have all arrived: Codex's are
|
|
4003
|
+
// known, and the same cards came in two updates running. It waits for any
|
|
4004
|
+
// dialog that's open to close.
|
|
4005
|
+
let tourIds = null;
|
|
4006
|
+
let tourWaitFrom = 0;
|
|
4007
|
+
|
|
4008
|
+
function startTourWhenSettled() {
|
|
4009
|
+
const ids = [...snap.agents.map((a) => a.id), ...(snap.todos || []).map((t) => t.id)].sort().join();
|
|
4010
|
+
const steady = ids === tourIds && snap.settled !== false;
|
|
4011
|
+
tourIds = ids;
|
|
4012
|
+
tourWaitFrom ||= Date.now();
|
|
4013
|
+
if ((steady || Date.now() - tourWaitFrom > 15000) && !document.querySelector('dialog[open]')) startTour();
|
|
4014
|
+
}
|
|
4015
|
+
|
|
4016
|
+
$('tour-next').addEventListener('click', () => (tourAt === tourSteps.length - 1 ? $('tour').close() : showTourStep(tourAt + 1)));
|
|
4017
|
+
$('tour-back').addEventListener('click', () => tourAt > 0 && showTourStep(tourAt - 1));
|
|
4018
|
+
$('tour-skip').addEventListener('click', () => $('tour').close());
|
|
4019
|
+
// Esc closes it too, as it does any dialog. The arrow keys move through it,
|
|
4020
|
+
// and nothing else scrolls the page under it.
|
|
4021
|
+
$('tour').addEventListener('keydown', (e) => {
|
|
4022
|
+
if (e.key === 'ArrowRight' && tourAt < tourSteps.length - 1) showTourStep(tourAt + 1);
|
|
4023
|
+
else if (e.key === 'ArrowLeft' && tourAt > 0) showTourStep(tourAt - 1);
|
|
4024
|
+
else if (!['ArrowUp', 'ArrowDown', 'PageUp', 'PageDown', 'Home', 'End'].includes(e.key)) return;
|
|
4025
|
+
e.preventDefault();
|
|
4026
|
+
});
|
|
4027
|
+
for (const type of ['wheel', 'touchmove']) $('tour').addEventListener(type, (e) => e.preventDefault(), { passive: false });
|
|
4028
|
+
addEventListener('resize', () => tourOn && placeTour());
|
|
4029
|
+
$('tour').addEventListener('close', () => {
|
|
4030
|
+
tourOn = false;
|
|
4031
|
+
tourSample?.remove();
|
|
4032
|
+
tourSample = null;
|
|
4033
|
+
tourCard = null;
|
|
4034
|
+
render();
|
|
4035
|
+
});
|
|
4036
|
+
$('tour-again').addEventListener('click', () => {
|
|
4037
|
+
$('settings').close();
|
|
4038
|
+
startTour();
|
|
4039
|
+
});
|
|
4040
|
+
|
|
4041
|
+
// ---- start ---------------------------------------------------------------------
|
|
4042
|
+
|
|
4043
|
+
$('settings-button').addEventListener('click', () => openSettings());
|
|
4044
|
+
$('settings').addEventListener('click', (e) => e.target === e.currentTarget && e.currentTarget.close());
|
|
4045
|
+
renderNotes();
|
|
4046
|
+
// Starting a to-do needs the folder setting before Settings is ever opened.
|
|
4047
|
+
loadServerSettings();
|
|
4048
|
+
// Back from choosing a language, Settings opens again where it was.
|
|
4049
|
+
try {
|
|
4050
|
+
if (sessionStorage.getItem(LANGUAGE_KEY)) {
|
|
4051
|
+
sessionStorage.removeItem(LANGUAGE_KEY);
|
|
4052
|
+
openSettings('language');
|
|
4053
|
+
}
|
|
4054
|
+
} catch {}
|
|
4055
|
+
|
|
4056
|
+
$('sound').addEventListener('click', () => {
|
|
4057
|
+
const ctx = audioContext();
|
|
4058
|
+
// While sound is blocked, the first click only unblocks it.
|
|
4059
|
+
if (!(soundOn && ctx && ctx.state !== 'running')) {
|
|
4060
|
+
soundOn = !soundOn;
|
|
4061
|
+
try {
|
|
4062
|
+
localStorage.setItem(SOUND_KEY, soundOn ? 'on' : 'off');
|
|
4063
|
+
} catch {}
|
|
4064
|
+
}
|
|
4065
|
+
const preview = () => {
|
|
4066
|
+
updateSoundButton();
|
|
4067
|
+
ding('done');
|
|
4068
|
+
};
|
|
4069
|
+
if (ctx && ctx.state !== 'running') ctx.resume().then(preview, preview);
|
|
4070
|
+
else preview();
|
|
4071
|
+
});
|
|
4072
|
+
document.addEventListener('pointerdown', unlockAudio, true);
|
|
4073
|
+
document.addEventListener('keydown', unlockAudio, true);
|
|
4074
|
+
audioContext();
|
|
4075
|
+
updateSoundButton();
|
|
4076
|
+
setInterval(tick, 1000);
|
|
4077
|
+
connect();
|