dsh-todo-float-ball 0.9.0 → 0.11.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/lib/client.js CHANGED
@@ -1,1115 +1,1656 @@
1
- window.__ModuleLoader__.load({
2
- id: "dsh-todo-float-ball",
3
- factory: function (require) {
4
- var module = { exports: {} };
5
- var exports = module.exports;
6
-
7
- // ============================================================
8
- // dsh-todo-float-ball — client half (browser). v0.3.0
9
- //
10
- // A persistent, draggable floating ball that mirrors todo_write lists.
11
- //
12
- // v0.3.0 — data layer rebuilt on the official `sessions` service:
13
- // * inject: ["sessions"] — the runtime's global session registry.
14
- // Its list snapshot carries, for EVERY session, the projection
15
- // values computed by the host (todos, title/plan/...), plus the
16
- // current session id and a subscribe() for changes.
17
- // * This gives us multi-session todo data and instant session-switch
18
- // detection with ZERO interception — no fetch/WS wrapping (desktop
19
- // renders go through the shell's __DSH_TRANSPORT__ Electron bridge,
20
- // which page-level taps can never see).
21
- // * Fallback: if ctx.sessions is unavailable, fall back to observing
22
- // the official todo panel DOM ([data-testid="todo-panel"]).
23
- //
24
- // Features: auto-follow active conversation; pin any conversation (📌)
25
- // for cross-session monitoring; pinned list persists in localStorage;
26
- // per-status colors; Shadow DOM isolation; draggable ball.
27
- // ============================================================
28
-
29
- var BALL_ID = "dsh-tfb-root";
30
- var POS_KEY = "dsh-todo-float-ball-pos";
31
- var PIN_KEY = "dsh-todo-float-ball-pinned";
32
- var CAPSULE_KEY = "dsh-todo-float-ball-capsule";
33
- var MAX_CONTENT = 80;
34
-
35
- // ---------- multi-session state ----------
36
- var bySession = {}; // sessionId -> { todos:[{content,status}], sig }
37
- var titles = {}; // sessionId -> display title
38
- var pinned = []; // [sessionId,...] (persisted)
39
- var currentSid = null; // active session (from sessions.list.current)
40
- var hasSessionsSvc = false;
41
- var currentSessions = null;
42
- var expanded = false;
43
- var capsule = false; // right-click: pill mode showing active task
44
- var openPin = {}; // pinned sessionId -> expanded? (UI state)
45
- var editing = { sid: null }; // inline rename editor state (one at a time)
46
- var ui = { root: null, ball: null, panel: null, list: null, summary: null, ctitle: null, pinBtn: null, pinSec: null };
47
-
48
- function normSid(sid) {
49
- return (typeof sid === "string" && sid) ? sid : "current";
50
- }
51
-
52
- // ---------- pinned persistence ----------
53
- function loadPinned() {
54
- try {
55
- var raw = localStorage.getItem(PIN_KEY);
56
- if (raw) {
57
- var arr = JSON.parse(raw);
58
- if (Array.isArray(arr)) pinned = arr.filter(function (x) { return typeof x === "string" && x; });
59
- }
60
- } catch (e) { pinned = []; }
61
- }
62
- function savePinned() {
63
- try { localStorage.setItem(PIN_KEY, JSON.stringify(pinned)); } catch (e) {}
64
- }
65
- function isPinned(sid) { return pinned.indexOf(sid) >= 0; }
66
- function pin(sid) {
67
- sid = normSid(sid);
68
- if (isPinned(sid)) return;
69
- pinned.push(sid);
70
- savePinned();
71
- render();
72
- }
73
- function unpin(sid) {
74
- var i = pinned.indexOf(sid);
75
- if (i >= 0) { pinned.splice(i, 1); savePinned(); render(); }
76
- }
77
-
78
- // ---------- helpers ----------
79
- function esc(s) {
80
- return String(s)
81
- .replace(/&/g, "&")
82
- .replace(/</g, "&lt;")
83
- .replace(/>/g, "&gt;")
84
- .replace(/"/g, "&quot;");
85
- }
86
-
87
- function countsOf(list) {
88
- var done = 0, active = 0;
89
- for (var i = 0; i < list.length; i++) {
90
- if (list[i].status === "completed") done++;
91
- else if (list[i].status === "in_progress") active++;
92
- }
93
- return { done: done, active: active, total: list.length };
94
- }
95
-
96
- function sessionTodos(sid) {
97
- var b = bySession[normSid(sid)];
98
- return b ? b.todos : null;
99
- }
100
- function sessionTitle(sid) {
101
- sid = normSid(sid);
102
- if (titles[sid]) return titles[sid];
103
- return sid === "current" ? "" : sid.slice(0, 10) + "…";
104
- }
105
-
106
- // ---------- rename (official API) ----------
107
- // Path (verified against dsh-client-runtime): the sessions facade exposes
108
- // .manager; SessionManager lazily builds resident Session records
109
- // (.sessions Map, .get(sessionId) is side-effect-safe); each Session has
110
- // .rename(title) → api.sessions.rename → host normalizes → title
111
- // projection updates → our sessions.list subscription re-renders.
112
- function renameSession(sid, title) {
113
- sid = normSid(sid);
114
- var clean = (typeof title === "string" ? title.trim() : "");
115
- if (!clean) return Promise.resolve(false);
116
- try {
117
- var mgr = currentSessions && currentSessions.manager;
118
- var session = mgr && mgr.sessions && typeof mgr.sessions.get === "function" ? mgr.sessions.get(sid) : null;
119
- if (session && typeof session.rename === "function") {
120
- return Promise.resolve(session.rename(clean)).then(function (result) {
121
- if (result && result.ok) {
122
- titles[sid] = (result.value && result.value.title) || clean;
123
- render();
124
- return true;
125
- }
126
- render();
127
- return false;
128
- }).catch(function () { render(); return false; });
129
- }
130
- } catch (e) {}
131
- return Promise.resolve(false);
132
- }
133
-
134
- function startRename(sid) {
135
- if (!hasSessionsSvc) return;
136
- sid = normSid(sid);
137
- if (editing.sid) return; // one editor at a time
138
- var isCurrent = sid === normSid(currentSid);
139
- var host = isCurrent ? ui.ctitle
140
- : (ui.pinSec ? ui.pinSec.querySelector('.tfb-pinrow[data-sid="' + sid + '"] .tfb-pinname') : null);
141
- if (!host) return;
142
- editing.sid = sid;
143
- var old = sessionTitle(sid);
144
- host.innerHTML = '<input class="tfb-rename" data-rename="1" value="' + esc(old) + '" placeholder="会话名称">';
145
- var input = host.querySelector("input");
146
- if (!input) { editing.sid = null; return; }
147
- input.focus();
148
- try { input.select(); } catch (e) {}
149
- var done = false;
150
- var commit = function () {
151
- if (done) return; done = true;
152
- var v = input.value;
153
- editing.sid = null;
154
- if (v && v.trim() && v.trim() !== old) renameSession(sid, v);
155
- else render();
156
- };
157
- var cancel = function () {
158
- if (done) return; done = true;
159
- editing.sid = null;
160
- render();
161
- };
162
- input.addEventListener("keydown", function (e) {
163
- if (e.key === "Enter") { e.preventDefault(); commit(); }
164
- else if (e.key === "Escape") { e.preventDefault(); cancel(); }
165
- });
166
- input.addEventListener("blur", commit);
167
- input.addEventListener("click", function (e) { e.stopPropagation(); });
168
- input.addEventListener("pointerdown", function (e) { e.stopPropagation(); });
169
- }
170
-
171
- function currentList() { return sessionTodos(currentSid) || []; }
172
-
173
- function summarize(list) {
174
- var c = countsOf(list);
175
- var head = c.done + "/" + c.total;
176
- var detail = "";
177
- if (c.active > 0) {
178
- var first = null;
179
- for (var i = 0; i < list.length; i++) {
180
- if (list[i].status === "in_progress") { first = list[i].content; break; }
181
- }
182
- if (first) detail = first.length > 30 ? first.slice(0, 30) + "…" : first;
183
- if (c.active > 1) detail += " (+" + (c.active - 1) + ")";
184
- }
185
- return { head: head, detail: detail, c: c };
186
- }
187
-
188
- function ballState() {
189
- var list = currentList();
190
- if (!list.length) return { cls: "tfb-idle", label: "✓" };
191
- var c = countsOf(list);
192
- if (c.done === c.total) return { cls: "tfb-done", label: "✓" };
193
- return { cls: c.active > 0 ? "tfb-active" : "tfb-pending", label: String(c.done) + "/" + String(c.total) };
194
- }
195
-
196
- // ---------- durable persistence (user requirement: cross-turn /
197
- // cross-refresh record survival) ----------
198
- // Every accepted snapshot is written to localStorage keyed by session.
199
- // On restore we take whichever side is "further along" (more completed
200
- // items, tie-break by total, then by recency) so nothing — a stale
201
- // snapshot poll, a page reload, a projection rebuild — can drag the
202
- // record BACKWARD. Completed items are history, not transients.
203
- var PERSIST_KEY = "dsh-todo-float-ball-persist-v1";
204
- var persistTimer = null;
205
- function loadPersisted() {
206
- var out = {};
207
- try {
208
- var raw = localStorage.getItem(PERSIST_KEY);
209
- if (raw) out = JSON.parse(raw) || {};
210
- } catch (e) { out = {}; }
211
- return out;
212
- }
213
- function persistSoon() {
214
- if (persistTimer) return;
215
- persistTimer = setTimeout(function () {
216
- persistTimer = null;
217
- try {
218
- var out = {};
219
- for (var sid in bySession) {
220
- var b = bySession[sid];
221
- if (b && b.todos && b.todos.length) {
222
- out[sid] = { todos: b.todos, sig: b.sig, at: b.at || 0 };
223
- }
224
- }
225
- localStorage.setItem(PERSIST_KEY, JSON.stringify(out));
226
- } catch (e) {}
227
- }, 400);
228
- }
229
- // progress score: completed count dominates, then total, then recency.
230
- // planKey: the sorted content set — identical set = same plan (progress
231
- // within one plan must never regress); different set = a new plan.
232
- function planKey(todos) {
233
- return todos.map(function (t) { return t.content; }).sort().join("\n");
234
- }
235
- function progressScore(todos, at) {
236
- var c = countsOf(todos);
237
- return c.done * 10000 + c.total * 100 + Math.min(99, Math.floor(((at || 0) / 60000) % 100));
238
- }
239
- function restorePersisted() {
240
- try {
241
- var saved = loadPersisted();
242
- for (var sid in saved) {
243
- var rec = saved[sid];
244
- if (!rec || !Array.isArray(rec.todos) || rec.todos.length === 0) continue;
245
- var norm = [];
246
- for (var i = 0; i < rec.todos.length; i++) {
247
- var it = rec.todos[i];
248
- if (it && typeof it.content === "string" && it.content.trim()) {
249
- norm.push({ content: it.content, status: it.status });
250
- }
251
- }
252
- if (!norm.length) continue;
253
- var mem = bySession[sid];
254
- if (mem && mem.todos && mem.todos.length) {
255
- // different plan: the live snapshot wins (it is what the host
256
- // currently holds); same plan: keep the further-along record
257
- if (planKey(mem.todos) !== planKey(norm)) continue;
258
- if (progressScore(norm, rec.at) <= progressScore(mem.todos, mem.at)) continue;
259
- }
260
- bySession[sid] = { todos: norm, sig: rec.sig || norm.map(function (t) { return t.status + "|" + t.content; }).join("\n"), stale: false, at: rec.at || 0 };
261
- }
262
- } catch (e) {}
263
- }
264
-
265
- // ---------- data ingestion ----------
266
- function setSessionTodos(sid, list) {
267
- sid = normSid(sid);
268
- if (!Array.isArray(list)) return;
269
- var norm = [];
270
- for (var i = 0; i < list.length; i++) {
271
- var it = list[i];
272
- if (!it || typeof it !== "object") continue;
273
- var st = it.status;
274
- if (st !== "pending" && st !== "in_progress" && st !== "completed") continue;
275
- var content = typeof it.content === "string" ? it.content : "";
276
- if (!content.trim()) continue;
277
- norm.push({ content: content, status: st });
278
- }
279
- if (norm.length === 0) {
280
- // STICKY: the host resets the todos projection to null at every
281
- // turn/start. Never wipe the last known list — only a real
282
- // todo_write snapshot (or a strictly-more-complete persisted one)
283
- // changes it. Per-session bucketing keeps this from bleeding
284
- // across conversations.
285
- var b0 = bySession[sid];
286
- if (b0) b0.stale = true;
287
- return;
288
- }
289
- var sig = norm.map(function (t) { return t.status + "|" + t.content; }).join("\n");
290
- var b = bySession[sid];
291
- if (b && b.sig === sig) { b.stale = false; return; }
292
- // MONOTONIC GUARD (plan-aware, v0.6.4): a todo_write is a whole-list
293
- // replacement — a NEW plan legitimately starts at 0 done, so the old
294
- // "fewer done = stale snapshot" check was rejecting freshly assigned
295
- // tasks (user bug: new plan never showed, ball stuck at "all done").
296
- // The guard now only applies WITHIN the same plan (identical content
297
- // set): same tasks but fewer completed = an older snapshot → reject.
298
- // Different content set = a new/edited plan → always accept.
299
- if (b && b.todos && b.todos.length && planKey(b.todos) === planKey(norm)) {
300
- var cMem = countsOf(b.todos);
301
- var cNew = countsOf(norm);
302
- if (cNew.done < cMem.done) {
303
- return; // same plan, progress regressed — stale snapshot, keep ours
304
- }
305
- }
306
- bySession[sid] = { todos: norm, sig: sig, stale: false, at: Date.now() };
307
- render();
308
- persistSoon();
309
- }
310
-
311
- // Primary channel: the official sessions service.
312
- // list snapshot shape (from dsh-client-runtime):
313
- // { ids:[...], byId:{ sid:{ id, displayTitle, running, projectionValues:{todos,title,...}, ... } },
314
- // current: sid|undefined, phase }
315
- function syncFromSessions() {
316
- try {
317
- var snap = currentSessions.list.getSnapshot();
318
- if (!snap || !snap.byId) return;
319
- for (var id in snap.byId) {
320
- var rec = snap.byId[id];
321
- if (!rec) continue;
322
- if (typeof rec.displayTitle === "string" && rec.displayTitle) titles[id] = rec.displayTitle;
323
- var pv = rec.projectionValues;
324
- if (pv && typeof pv === "object" && "todos" in pv) {
325
- setSessionTodos(id, pv.todos === null ? [] : pv.todos);
326
- }
327
- }
328
- if (snap.current) currentSid = snap.current;
329
- render();
330
- } catch (e) {}
331
- }
332
-
333
- // Fallback channel: observe the official todo panel DOM. Expanded panel
334
- // renders ul > li[data-status]; collapsed renders only header counts
335
- // (parsed into a skeleton — better than nothing when sessions service
336
- // is unavailable).
337
- function installPanelObserver() {
338
- var mo = new MutationObserver(function () {
339
- if (installPanelObserver._t) return;
340
- installPanelObserver._t = setTimeout(function () {
341
- installPanelObserver._t = 0;
342
- try { readOfficialPanel(); } catch (e) {}
343
- }, 200);
344
- });
345
- function start() {
346
- try {
347
- mo.observe(document.documentElement || document.body, { childList: true, subtree: true });
348
- readOfficialPanel();
349
- } catch (e) {}
350
- }
351
- if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", start);
352
- else start();
353
- }
354
-
355
- var ZH_NUM = { "零": 0, "一": 1, "二": 2, "两": 2, "三": 3, "四": 4, "五": 5, "六": 6, "七": 7, "八": 8, "九": 9, "十": 10 };
356
-
357
- function parseZhNum(s) {
358
- s = String(s).trim();
359
- if (/^\d+$/.test(s)) return parseInt(s, 10);
360
- if (ZH_NUM[s] !== undefined) return ZH_NUM[s];
361
- if (/^十$/.test(s)) return 10;
362
- var m = /^([一二两三四五六七八九])?十([一二三四五六七八九])?$/.exec(s);
363
- if (m) return (m[1] ? ZH_NUM[m[1]] : 1) * 10 + (m[2] ? ZH_NUM[m[2]] : 0);
364
- return NaN;
365
- }
366
-
367
- function readOfficialPanel() {
368
- var panel = document.querySelector('[data-testid="todo-panel"]');
369
- if (!panel) return;
370
- var items = panel.querySelectorAll("ul li[data-status]");
371
- if (items.length > 0) {
372
- var list = [];
373
- for (var i = 0; i < items.length; i++) {
374
- var li = items[i];
375
- var st = li.getAttribute("data-status");
376
- var contentEl = li.querySelector("span:last-child") || li.lastElementChild;
377
- var content = contentEl ? (contentEl.textContent || "").trim() : "";
378
- if (content) list.push({ content: content, status: st || "pending" });
379
- }
380
- if (list.length > 0) { setSessionTodos(currentSid, list); return; }
381
- }
382
- // collapsed: skeleton only if the current session has no real data
383
- var cur = bySession[normSid(currentSid)];
384
- var hasReal = cur && cur.todos && cur.todos.length > 0 && !cur.__skeleton;
385
- if (hasReal) return;
386
- var label = panel.querySelector('[class*="progress"]');
387
- if (!label) return;
388
- var text = (label.textContent || "").trim();
389
- if (!text) return;
390
- var segs = text.split("·");
391
- var done = NaN, active = NaN, pending = NaN;
392
- for (var k = 0; k < segs.length; k++) {
393
- var s = segs[k].trim();
394
- var n = parseZhNum(s.split(" ")[0]);
395
- if (isNaN(n)) continue;
396
- if (s.indexOf("完成") >= 0) done = n;
397
- else if (s.indexOf("进行") >= 0) active = n;
398
- else if (s.indexOf("待办") >= 0) pending = n;
399
- }
400
- if (isNaN(done) && isNaN(active) && isNaN(pending)) return;
401
- // only show the skeleton when we have nothing real, and mark it
402
- if (bySession[normSid(currentSid)] && !bySession[normSid(currentSid)].__skeleton) return;
403
- var skel = [];
404
- for (var d = 0; d < (isNaN(done) ? 0 : done); d++) skel.push({ content: "已完成任务", status: "completed" });
405
- for (var a = 0; a < (isNaN(active) ? 0 : active); a++) skel.push({ content: "进行中任务", status: "in_progress" });
406
- for (var p = 0; p < (isNaN(pending) ? 0 : pending); p++) skel.push({ content: "待办任务", status: "pending" });
407
- if (skel.length > 0) {
408
- setSessionTodos(currentSid, skel);
409
- var bb = bySession[normSid(currentSid)];
410
- if (bb) bb.__skeleton = true;
411
- render();
412
- }
413
- }
414
-
415
- // ---------- UI ----------
416
- // ---------- theme (dual skin, user requirement) ----------
417
- // "nebula" — skill-orb style clone (v0.6.2): nebula body + flowing
418
- // bands + rotating conic rim + breathing + glow text.
419
- // "graphite" — v0.5.1 dark-gem style: same glass family as
420
- // font-enhancer, teal accent + thin progress ring.
421
- // Persisted in localStorage; switched from the shared "悬浮球导航"
422
- // settings section (dsh-skill-browser provides the button).
423
- var THEME_KEY = "dsh-tfb-theme";
424
- var currentTheme = "nebula";
425
- function loadTheme() {
426
- try {
427
- var v = localStorage.getItem(THEME_KEY);
428
- if (v === "blue") currentTheme = "blue"; else if (v === "nebula") currentTheme = "nebula"; else if (v === "nebB") currentTheme = "nebB"; else if (v === "nebC") currentTheme = "nebC"; else if (v === "glass") currentTheme = "glass"; else currentTheme = "graphite";
429
- } catch (e) {}
430
- }
431
- function setTheme(t) {
432
- if (t !== "nebula" && t !== "graphite" && t !== "blue" && t !== "glass" && t !== "nebB" && t !== "nebC") return;
433
- currentTheme = t;
434
- try { localStorage.setItem(THEME_KEY, t); } catch (e) {}
435
- render();
436
- }
437
-
438
- function cssText() {
439
- var th = currentTheme;
440
- // Skeleton fields that all four skins share; shape differs per skin.
441
- var SIZE = "width:46px;height:46px;";
442
- // Per-skin ball rules (status variants + ring + band/rim).
443
- var ball = [];
444
- if (th === "nebula") {
445
- ball = [
446
- ".tfb-ball{position:fixed;right:18px;bottom:18px;z-index:2147483600;border-radius:50%;border:1px solid rgba(255,255,255,.28);cursor:grab;user-select:none;touch-action:none;pointer-events:auto;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:1px;color:#eafff7;font-size:13px;font-weight:800;line-height:1.1;background:radial-gradient(circle at 50% 60%, #2dd4a8 0%, #17a284 20%, #12876f 45%, #0a3a32 68%, #041715 100%);box-shadow:0 0 22px rgba(45,212,168,.5),0 0 4px rgba(120,255,214,.35),0 4px 18px rgba(0,0,0,.55),inset 0 1px 3px rgba(255,255,255,.4),inset 0 -8px 16px rgba(45,212,168,.16),inset 0 0 14px rgba(20,180,150,.25);text-shadow:0 0 6px rgba(120,255,214,.75),0 2px 4px rgba(0,40,30,.8);filter:drop-shadow(0 0 6px rgba(160,255,225,.85));animation:tfbBreathe 3.2s ease-in-out infinite;transition:transform .15s ease}" + SIZE.replace(";", ";"),
447
- ".tfb-orb-band{display:none}",
448
- ".tfb-orb-rim{position:absolute;inset:-1px;border-radius:50%;z-index:1;pointer-events:none;background:conic-gradient(from 200deg, rgba(255,255,255,.55), rgba(120,240,205,.35), rgba(10,200,170,.4), rgba(255,255,255,.15), rgba(45,212,168,.4), rgba(255,255,255,.55));-webkit-mask:radial-gradient(circle, transparent 63%, #000 66%, #000 72%, transparent 76%);mask:radial-gradient(circle, transparent 63%, #000 66%, #000 72%, transparent 76%);animation:tfbRimSpin 7s linear infinite;filter:blur(.5px)}",
449
- ".tfb-ball .tfb-ring{display:none}",
450
- ".tfb-ball .tfb-label{animation:tfbGlow 2.4s ease-in-out infinite}",
451
- ".tfb-ball.tfb-active{color:#fff3dc;background:radial-gradient(circle at 50% 60%, #ffaa33 0%, #e08410 20%, #b56708 45%, #4a2a06 70%, #170c02 100%);box-shadow:0 0 22px rgba(255,170,51,.55),0 0 4px rgba(255,210,120,.4),0 4px 18px rgba(0,0,0,.55),inset 0 1px 3px rgba(255,255,255,.4),inset 0 -8px 16px rgba(255,170,51,.16),inset 0 0 14px rgba(230,140,20,.25);text-shadow:0 0 4px rgba(255,255,255,.95),0 0 10px rgba(255,215,140,.95),0 0 20px rgba(255,160,40,.8),0 2px 4px rgba(60,30,0,.8);filter:drop-shadow(0 0 6px rgba(255,200,110,.9))}",
452
- ".tfb-ball.tfb-active .tfb-orb-rim{background:conic-gradient(from 200deg, rgba(255,255,255,.6), rgba(255,200,110,.4), rgba(255,150,30,.45), rgba(255,255,255,.15), rgba(255,190,80,.4), rgba(255,255,255,.6));animation-duration:2.6s}",
453
- ".tfb-ball.tfb-done{color:#eafff4;background:radial-gradient(circle at 50% 60%, #5dffa8 0%, #22c070 20%, #12875c 45%, #073c26 70%, #02150c 100%);box-shadow:0 0 26px rgba(93,255,168,.6),0 0 5px rgba(180,255,215,.45),0 4px 18px rgba(0,0,0,.55),inset 0 1px 3px rgba(255,255,255,.45),inset 0 -8px 16px rgba(93,255,168,.18),inset 0 0 14px rgba(40,200,120,.3);text-shadow:0 0 4px rgba(255,255,255,1),0 0 12px rgba(190,255,220,1),0 0 24px rgba(60,255,150,.85),0 2px 4px rgba(0,40,20,.8);filter:drop-shadow(0 0 8px rgba(140,255,195,.95))}",
454
- ".tfb-ball.tfb-pending{color:#e8f3ff;background:radial-gradient(circle at 50% 60%, #7fc4ff 0%, #4f92e0 20%, #2f6cb0 45%, #12305c 70%, #04101e 100%);box-shadow:0 0 22px rgba(127,196,255,.5),0 0 4px rgba(180,220,255,.35),0 4px 18px rgba(0,0,0,.55),inset 0 1px 3px rgba(255,255,255,.4),inset 0 -8px 16px rgba(127,196,255,.15),inset 0 0 14px rgba(70,140,220,.25);text-shadow:0 0 4px rgba(255,255,255,.95),0 0 10px rgba(190,225,255,.9),0 0 20px rgba(90,170,255,.75),0 2px 4px rgba(0,20,45,.8);filter:drop-shadow(0 0 6px rgba(170,215,255,.85))}"
455
- ];
456
- } else if (th === "blue") {
457
- ball = [
458
- ".tfb-ball{position:fixed;right:18px;bottom:18px;z-index:2147483600;border-radius:50%;border:1px solid rgba(255,255,255,.28);cursor:grab;user-select:none;touch-action:none;pointer-events:auto;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:1px;color:#a8c8ff;font-size:13px;font-weight:800;line-height:1.1;background:radial-gradient(circle at 30% 25%,rgba(255,255,255,.18),rgba(26,40,66,.96) 70%);box-shadow:0 4px 24px rgba(0,0,0,.6),inset 0 1px 0 rgba(255,255,255,.18),0 0 18px rgba(100,160,255,.5);transition:transform .15s ease}" + SIZE.replace(";", ";"),
459
- ".tfb-orb-band{display:none}",
460
- ".tfb-orb-rim{display:none}",
461
- ".tfb-ball .tfb-ring{position:absolute;inset:-1px;border-radius:50%;pointer-events:none;background:conic-gradient(var(--rc,#6aa8ff) calc(var(--pct,0)*1%),rgba(255,255,255,.08) 0);-webkit-mask:radial-gradient(farthest-side,transparent calc(100% - 5px),#000 calc(100% - 4px));mask:radial-gradient(farthest-side,transparent calc(100% - 5px),#000 calc(100% - 4px));transition:background .4s ease;filter:drop-shadow(0 0 6px rgba(100,160,255,.5))}",
462
- ".tfb-ball .tfb-label{text-shadow:0 0 10px currentColor,0 0 3px currentColor}",
463
- ".tfb-ball.tfb-active{color:#ffcf8a;box-shadow:0 4px 24px rgba(0,0,0,.6),inset 0 1px 0 rgba(255,255,255,.18),0 0 16px rgba(255,170,51,.5);animation:tfb-pulse 1.6s ease-in-out infinite}",
464
- ".tfb-ball.tfb-active .tfb-ring{--rc:#ffaa33;filter:drop-shadow(0 0 8px rgba(255,170,51,.6))}",
465
- ".tfb-ball.tfb-done{color:#a5ffd4;box-shadow:0 4px 24px rgba(0,0,0,.6),inset 0 1px 0 rgba(255,255,255,.18),0 0 18px rgba(93,255,168,.5)}",
466
- ".tfb-ball.tfb-done .tfb-ring{--rc:#5dffa8;filter:drop-shadow(0 0 10px rgba(93,255,168,.7))}",
467
- ".tfb-ball.tfb-pending{color:#bcd9ff;box-shadow:0 4px 24px rgba(0,0,0,.6),inset 0 1px 0 rgba(255,255,255,.18),0 0 14px rgba(127,196,255,.5)}",
468
- ".tfb-ball.tfb-pending .tfb-ring{--rc:#7fc4ff;filter:drop-shadow(0 0 8px rgba(127,196,255,.6))}"
469
- ];
470
- } else if (th === "nebB") {
471
- ball = [
472
- ".tfb-ball{position:fixed;right:18px;bottom:18px;z-index:2147483600;border-radius:50%;border:1px solid rgba(255,255,255,.28);cursor:grab;user-select:none;touch-action:none;pointer-events:auto;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:1px;color:#d9fff0;font-size:13px;font-weight:800;line-height:1.1;background:radial-gradient(circle at 50% 62%, rgba(210,255,244,.5) 0%, rgba(45,212,168,.75) 14%, rgba(18,160,130,.85) 30%, rgba(12,110,92,.95) 50%, rgba(6,40,34,1) 72%, rgba(2,16,14,1) 100%);box-shadow:0 0 20px rgba(45,212,168,.45),inset 0 2px 5px rgba(255,255,255,.45),inset 0 -10px 18px rgba(45,212,168,.25),inset 0 0 18px rgba(10,60,50,.5);text-shadow:0 0 6px rgba(120,255,214,.75),0 2px 4px rgba(0,40,30,.8);animation:tfbBreathe 3.2s ease-in-out infinite;transition:transform .15s ease}" + SIZE,
473
- ".tfb-orb-band{display:none}",
474
- ".tfb-orb-rim{position:absolute;inset:-1px;border-radius:50%;z-index:1;pointer-events:none;background:conic-gradient(from 200deg, rgba(255,255,255,.45), rgba(120,240,205,.3), rgba(10,200,170,.35), rgba(255,255,255,.12), rgba(45,212,168,.35), rgba(255,255,255,.45));-webkit-mask:radial-gradient(circle, transparent 63%, #000 66%, #000 72%, transparent 76%);mask:radial-gradient(circle, transparent 63%, #000 66%, #000 72%, transparent 76%);animation:tfbRimSpin 7s linear infinite;filter:blur(.5px)}",
475
- ".tfb-ball .tfb-ring{display:none}",
476
- ".tfb-ball .tfb-label{animation:tfbGlow 2.4s ease-in-out infinite}",
477
- ".tfb-ball.tfb-active{color:#ffd9a8;background:radial-gradient(circle at 50% 62%, rgba(255,240,210,.55) 0%, rgba(255,180,70,.8) 14%, rgba(220,130,25,.9) 30%, rgba(150,85,15,.95) 50%, rgba(60,32,6,1) 72%, rgba(24,12,2,1) 100%);box-shadow:0 0 20px rgba(255,170,51,.5),inset 0 2px 5px rgba(255,255,255,.5),inset 0 -10px 18px rgba(255,170,51,.28),inset 0 0 18px rgba(90,50,10,.5)}",
478
- ".tfb-ball.tfb-active .tfb-orb-rim{background:conic-gradient(from 200deg, rgba(255,255,255,.5), rgba(255,200,110,.35), rgba(255,150,30,.4), rgba(255,255,255,.12), rgba(255,190,80,.35), rgba(255,255,255,.5));animation-duration:2.6s}",
479
- ".tfb-ball.tfb-done{color:#d9fff0;background:radial-gradient(circle at 50% 62%, rgba(220,255,236,.5) 0%, rgba(93,255,168,.75) 14%, rgba(30,190,105,.85) 30%, rgba(15,130,75,.95) 50%, rgba(5,45,28,1) 72%, rgba(2,16,10,1) 100%);box-shadow:0 0 20px rgba(93,255,168,.5),inset 0 2px 5px rgba(255,255,255,.5),inset 0 -10px 18px rgba(93,255,168,.25),inset 0 0 18px rgba(8,60,38,.5)}",
480
- ".tfb-ball.tfb-pending{color:#dbeafe;background:radial-gradient(circle at 50% 62%, rgba(220,240,255,.5) 0%, rgba(127,196,255,.7) 14%, rgba(59,130,196,.85) 30%, rgba(35,90,150,.95) 50%, rgba(10,35,65,1) 72%, rgba(3,12,24,1) 100%);box-shadow:0 0 20px rgba(127,196,255,.45),inset 0 2px 5px rgba(255,255,255,.45),inset 0 -10px 18px rgba(127,196,255,.22),inset 0 0 18px rgba(15,45,85,.5)}"
481
- ];
482
- } else if (th === "nebC") {
483
- ball = [
484
- ".tfb-ball{position:fixed;right:18px;bottom:18px;z-index:2147483600;border-radius:50%;border:1px solid rgba(255,255,255,.28);cursor:grab;user-select:none;touch-action:none;pointer-events:auto;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:1px;color:#d9fff0;font-size:13px;font-weight:800;line-height:1.1;background:radial-gradient(circle at 50% 55%, #1a8a70 0%, #0f6b58 30%, #083f35 60%, #031511 100%);box-shadow:0 0 18px rgba(45,212,168,.35),inset 0 2px 6px rgba(255,255,255,.28),inset 0 -8px 14px rgba(0,0,0,.5);text-shadow:0 0 6px rgba(120,255,214,.75),0 2px 4px rgba(0,40,30,.8);animation:tfbBreathe 3.2s ease-in-out infinite;transition:transform .15s ease}" + SIZE,
485
- ".tfb-ball::before{content:\"\";position:absolute;inset:4px 6px 58% 6px;border-radius:50%;background:radial-gradient(ellipse at 50% 30%, rgba(140,255,225,.55) 0%, rgba(140,255,225,.12) 60%, transparent 80%);filter:blur(1px);z-index:1;pointer-events:none}",
486
- ".tfb-orb-band{display:none}",
487
- ".tfb-orb-rim{position:absolute;inset:-1px;border-radius:50%;z-index:1;pointer-events:none;background:conic-gradient(from 200deg, rgba(255,255,255,.45), rgba(120,240,205,.3), rgba(10,200,170,.35), rgba(255,255,255,.12), rgba(45,212,168,.35), rgba(255,255,255,.45));-webkit-mask:radial-gradient(circle, transparent 63%, #000 66%, #000 72%, transparent 76%);mask:radial-gradient(circle, transparent 63%, #000 66%, #000 72%, transparent 76%);animation:tfbRimSpin 7s linear infinite;filter:blur(.5px)}",
488
- ".tfb-ball .tfb-ring{display:none}",
489
- ".tfb-ball .tfb-label{animation:tfbGlow 2.4s ease-in-out infinite}",
490
- ".tfb-ball.tfb-active{color:#ffd9a8;background:radial-gradient(circle at 50% 55%, #d98a1a 0%, #a86410 30%, #5c3608 60%, #201003 100%);box-shadow:0 0 18px rgba(255,170,51,.4),inset 0 2px 6px rgba(255,255,255,.3),inset 0 -8px 14px rgba(0,0,0,.5)}",
491
- ".tfb-ball.tfb-active::before{background:radial-gradient(ellipse at 50% 30%, rgba(255,220,160,.55) 0%, rgba(255,220,160,.12) 60%, transparent 80%)}",
492
- ".tfb-ball.tfb-active .tfb-orb-rim{background:conic-gradient(from 200deg, rgba(255,255,255,.5), rgba(255,200,110,.35), rgba(255,150,30,.4), rgba(255,255,255,.12), rgba(255,190,80,.35), rgba(255,255,255,.5));animation-duration:2.6s}",
493
- ".tfb-ball.tfb-done{color:#d9fff0;background:radial-gradient(circle at 50% 55%, #17a06a 0%, #0f7a4e 30%, #084a30 60%, #03150c 100%);box-shadow:0 0 18px rgba(93,255,168,.4),inset 0 2px 6px rgba(255,255,255,.28),inset 0 -8px 14px rgba(0,0,0,.5)}",
494
- ".tfb-ball.tfb-done::before{background:radial-gradient(ellipse at 50% 30%, rgba(180,255,220,.55) 0%, rgba(180,255,220,.12) 60%, transparent 80%)}",
495
- ".tfb-ball.tfb-pending{color:#dbeafe;background:radial-gradient(circle at 50% 55%, #2a6cb0 0%, #1c5288 30%, #10315c 60%, #04101e 100%);box-shadow:0 0 18px rgba(127,196,255,.35),inset 0 2px 6px rgba(255,255,255,.28),inset 0 -8px 14px rgba(0,0,0,.5)}",
496
- ".tfb-ball.tfb-pending::before{background:radial-gradient(ellipse at 50% 30%, rgba(180,215,255,.55) 0%, rgba(180,215,255,.12) 60%, transparent 80%)}"
497
- ];
498
- } else if (th === "glass") {
499
- ball = [
500
- ".tfb-ball{position:fixed;right:18px;bottom:18px;z-index:2147483600;border-radius:50%;border:1px solid rgba(255,255,255,.4);cursor:grab;user-select:none;touch-action:none;pointer-events:auto;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:1px;color:#16324a;font-size:13px;font-weight:800;line-height:1.1;background:linear-gradient(145deg,rgba(190,225,245,.4) 0%,rgba(130,170,205,.28) 50%,rgba(85,115,150,.42) 100%);backdrop-filter:blur(4px);box-shadow:inset 0 1px 5px rgba(255,255,255,.55),inset 0 -8px 14px rgba(255,255,255,.1),0 4px 16px rgba(0,0,0,.35);transition:transform .15s ease}" + SIZE,
501
- ".tfb-orb-band{display:none}",
502
- ".tfb-orb-rim{display:none}",
503
- ".tfb-ball::before{content:\"\";position:absolute;inset:3px 3px 55% 3px;border-radius:50% 50% 40% 40%;background:linear-gradient(rgba(255,255,255,.55),rgba(255,255,255,.06));filter:blur(.5px);pointer-events:none}",
504
- ".tfb-ball .tfb-ring{position:absolute;inset:-1px;border-radius:50%;pointer-events:none;background:conic-gradient(var(--rc,#3b82c4) calc(var(--pct,0)*1%),rgba(255,255,255,.25) 0);-webkit-mask:radial-gradient(farthest-side,transparent calc(100% - 4px),#000 calc(100% - 3px));mask:radial-gradient(farthest-side,transparent calc(100% - 4px),#000 calc(100% - 3px));transition:background .4s ease;filter:drop-shadow(0 0 5px rgba(80,140,200,.5))}",
505
- ".tfb-ball .tfb-label,.tfb-ball .tfb-sub{text-shadow:0 1px 2px rgba(255,255,255,.6)}",
506
- ".tfb-ball.tfb-active{color:#7a4a08;box-shadow:inset 0 1px 5px rgba(255,255,255,.55),inset 0 -8px 14px rgba(255,190,120,.15),0 4px 16px rgba(0,0,0,.35),0 0 14px rgba(255,170,51,.35)}",
507
- ".tfb-ball.tfb-active .tfb-ring{--rc:#ffaa33;filter:drop-shadow(0 0 7px rgba(255,170,51,.6))}",
508
- ".tfb-ball.tfb-done{color:#14532d;box-shadow:inset 0 1px 5px rgba(255,255,255,.55),inset 0 -8px 14px rgba(160,255,200,.15),0 4px 16px rgba(0,0,0,.35),0 0 14px rgba(93,255,168,.35)}",
509
- ".tfb-ball.tfb-done .tfb-ring{--rc:#16a34a;filter:drop-shadow(0 0 7px rgba(22,163,74,.6))}",
510
- ".tfb-ball.tfb-pending{color:#1e3a5f;box-shadow:inset 0 1px 5px rgba(255,255,255,.55),inset 0 -8px 14px rgba(170,205,255,.15),0 4px 16px rgba(0,0,0,.35),0 0 12px rgba(100,160,255,.3)}",
511
- ".tfb-ball.tfb-pending .tfb-ring{--rc:#3b82c4;filter:drop-shadow(0 0 6px rgba(59,130,196,.55))}"
512
- ];
513
- } else { // graphite
514
- ball = [
515
- ".tfb-ball{position:fixed;right:18px;bottom:18px;z-index:2147483600;border-radius:50%;border:1px solid rgba(255,255,255,.28);cursor:grab;user-select:none;touch-action:none;pointer-events:auto;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:1px;color:#7defc4;font-size:13px;font-weight:800;line-height:1.1;background:radial-gradient(circle at 30% 25%,rgba(255,255,255,.15),rgba(40,44,54,.95) 70%);box-shadow:0 4px 24px rgba(0,0,0,.6),inset 0 1px 0 rgba(255,255,255,.15),0 0 14px rgba(45,212,168,.28);transition:transform .15s ease}" + SIZE.replace(";", ";"),
516
- ".tfb-orb-band{display:none}",
517
- ".tfb-orb-rim{display:none}",
518
- ".tfb-ball .tfb-ring{position:absolute;inset:-1px;border-radius:50%;pointer-events:none;background:conic-gradient(var(--rc,#2dd4a8) calc(var(--pct,0)*1%),rgba(255,255,255,.07) 0);-webkit-mask:radial-gradient(farthest-side,transparent calc(100% - 5px),#000 calc(100% - 4px));mask:radial-gradient(farthest-side,transparent calc(100% - 5px),#000 calc(100% - 4px));transition:background .4s ease}",
519
- ".tfb-ball .tfb-label{text-shadow:0 0 8px currentColor,0 0 2px currentColor}",
520
- ".tfb-ball.tfb-active{color:#ffcf8a;box-shadow:0 4px 24px rgba(0,0,0,.6),inset 0 1px 0 rgba(255,255,255,.15),0 0 16px rgba(255,170,51,.45);animation:tfb-pulse 1.6s ease-in-out infinite}",
521
- ".tfb-ball.tfb-active .tfb-ring{--rc:#ffaa33}",
522
- ".tfb-ball.tfb-done{color:#8dffc8;box-shadow:0 4px 24px rgba(0,0,0,.6),inset 0 1px 0 rgba(255,255,255,.15),0 0 16px rgba(93,255,168,.4)}",
523
- ".tfb-ball.tfb-done .tfb-ring{--rc:#5dffa8}",
524
- ".tfb-ball.tfb-pending{color:#a8c8ec;box-shadow:0 4px 24px rgba(0,0,0,.6),inset 0 1px 0 rgba(255,255,255,.15),0 0 12px rgba(127,196,255,.3)}",
525
- ".tfb-ball.tfb-pending .tfb-ring{--rc:#7fc4ff}"
526
- ];
527
- }
528
- return [
529
- ":host{all:initial}",
530
- ".tfb-root{position:static;pointer-events:none;font-family:'Segoe UI','Microsoft YaHei',system-ui,sans-serif}",
531
- ".tfb-ball:hover{transform:scale(1.08)}",
532
- ".tfb-ball:active{cursor:grabbing;transform:scale(.95)}"
533
- ].concat(ball, [
534
- "@keyframes tfbBandFlow{0%,100%{transform:translateY(-3px) scaleY(.94);opacity:.8}50%{transform:translateY(3px) scaleY(1.12);opacity:1}}",
535
- "@keyframes tfbRimSpin{0%{transform:rotate(0deg)}100%{transform:rotate(360deg)}}",
536
- "@keyframes tfbBreathe{0%,100%{transform:scale(.96);filter:brightness(.92)}50%{transform:scale(1.05);filter:brightness(1.12)}}",
537
- "@keyframes tfbGlow{0%,100%{text-shadow:0 0 4px rgba(255,255,255,.95),0 0 10px rgba(150,255,220,.9),0 0 20px rgba(30,220,180,.75)}50%{text-shadow:0 0 6px rgba(255,255,255,1),0 0 16px rgba(200,255,235,1),0 0 32px rgba(60,240,195,.95)}}",
538
- "@keyframes tfb-pulse{0%,100%{box-shadow:0 4px 24px rgba(0,0,0,.6),inset 0 1px 0 rgba(255,255,255,.15),0 0 16px rgba(255,170,51,.45),0 0 0 0 rgba(255,170,51,.5)}50%{box-shadow:0 4px 24px rgba(0,0,0,.6),inset 0 1px 0 rgba(255,255,255,.15),0 0 16px rgba(255,170,51,.55),0 0 0 10px rgba(255,170,51,0)}}",
539
- ".tfb-ball.tfb-active .tfb-label{animation:none;text-shadow:0 0 4px rgba(255,255,255,.95),0 0 10px rgba(255,215,140,.95),0 0 20px rgba(255,160,40,.8)}",
540
- ".tfb-ball.tfb-done .tfb-label{animation:none;text-shadow:0 0 6px rgba(255,255,255,1),0 0 14px rgba(190,255,220,1),0 0 28px rgba(60,255,150,.9)}",
541
- // capsule mode (right-click toggle): long pill, wider, text-first
542
- ".tfb-ball.tfb-capsule{width:auto;min-width:220px;max-width:min(520px,60vw);height:44px;border-radius:22px;flex-direction:row;gap:8px;padding:0 16px;font-size:12px;justify-content:flex-start}",
543
- ".tfb-ball.tfb-capsule .tfb-orb-band{inset:1px}",
544
- ".tfb-ball.tfb-capsule .tfb-orb-rim{display:none}",
545
- ".tfb-ball.tfb-capsule .tfb-ring{display:none}",
546
- ".tfb-ball.tfb-capsule .tfb-label{flex-shrink:0}",
547
- ".tfb-ball.tfb-capsule .tfb-sub{flex:1;min-width:0;max-width:none;font-size:12px;text-align:left;overflow:hidden;white-space:nowrap}",
548
- ".tfb-ball.tfb-capsule .tfb-capsule-text{display:inline-block;white-space:nowrap}",
549
- ".tfb-ball.tfb-capsule .tfb-capsule-text.tfb-marquee{animation:tfbMarquee 9s ease-in-out infinite alternate}",
550
- "@keyframes tfbMarquee{from{transform:translateX(0)}to{transform:translateX(var(--shift,-40px))}}",
551
- ".tfb-panel{position:fixed;z-index:2147483600;width:300px;max-width:calc(100vw - 24px);max-height:74vh;overflow-y:auto;overflow-x:hidden;pointer-events:auto;display:none;color:#e6e6e6;font-size:13px;line-height:1.5;border-radius:14px;padding:12px 14px 10px;background:rgba(16,18,22,.92);border:1px solid rgba(255,255,255,.08);box-shadow:0 20px 60px rgba(0,0,0,.7),inset 0 1px 0 rgba(255,255,255,.06);backdrop-filter:blur(24px)}",
552
- ".tfb-panel.tfb-open{display:block}",
553
- ".tfb-head{display:flex;align-items:center;gap:6px;margin-bottom:6px;padding-bottom:6px;border-bottom:1px solid rgba(45,212,168,.25)}",
554
- ".tfb-title{font-weight:700;font-size:13px;white-space:nowrap}",
555
- ".tfb-ctitle{flex:1;min-width:0;font-size:11px;color:#9aa3b2;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;cursor:text}",
556
- ".tfb-summary{font-size:11px;color:#9aa3b2;white-space:nowrap}",
557
- ".tfb-btn{border:0;background:transparent;color:#9aa3b2;font-size:13px;cursor:pointer;padding:2px 5px;border-radius:6px;flex-shrink:0}",
558
- ".tfb-btn:hover{color:#e6e6e6;background:rgba(255,255,255,.06)}",
559
- ".tfb-btn.tfb-on{color:#ffd27a}",
560
- ".tfb-list{list-style:none;margin:0;padding:0}",
561
- ".tfb-item{display:flex;align-items:flex-start;gap:8px;padding:5px 4px;border-radius:8px;word-break:break-word}",
562
- ".tfb-item:nth-child(odd){background:rgba(255,255,255,.03)}",
563
- ".tfb-ico{flex-shrink:0;width:16px;height:16px;border-radius:50%;display:inline-flex;align-items:center;justify-content:center;font-size:10px;margin-top:1px}",
564
- ".tfb-item[data-status='completed'] .tfb-ico{background:rgba(74,222,128,.18);color:#5dffa8;border:1px solid rgba(93,255,168,.4)}",
565
- ".tfb-item[data-status='in_progress'] .tfb-ico{background:rgba(255,170,51,.2);color:#ffaa33;border:1px solid rgba(255,170,51,.45)}",
566
- ".tfb-item[data-status='pending'] .tfb-ico{background:rgba(127,196,255,.14);color:#7fc4ff;border:1px dashed rgba(127,196,255,.5)}",
567
- ".tfb-item[data-status='in_progress']{background:rgba(255,170,51,.06)}",
568
- ".tfb-item[data-status='in_progress'] .tfb-txt{color:#ffcf8a;font-weight:600}",
569
- ".tfb-item[data-status='completed'] .tfb-txt{color:#7fae94;text-decoration:line-through}",
570
- ".tfb-item[data-status='pending'] .tfb-txt{color:#aebfd4}",
571
- ".tfb-txt{flex:1}",
572
- ".tfb-empty{color:#8b93a1;font-size:12px;text-align:center;padding:12px 0}",
573
- ".tfb-sep{margin:10px 0 6px;padding-top:8px;border-top:1px solid rgba(255,255,255,.07);display:flex;align-items:center;justify-content:space-between}",
574
- ".tfb-sep-label{font-size:11px;color:#9aa3b2;font-weight:600}",
575
- ".tfb-pinrow{display:flex;align-items:center;gap:6px;padding:6px 4px;border-radius:8px;cursor:pointer}",
576
- ".tfb-pinrow:hover{background:rgba(255,255,255,.05)}",
577
- ".tfb-pinname{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:12px}",
578
- ".tfb-pincount{font-size:11px;color:#9aa3b2;white-space:nowrap}",
579
- ".tfb-dot{width:8px;height:8px;border-radius:50%;flex-shrink:0}",
580
- ".tfb-dot-active{background:#fbbf24;box-shadow:0 0 6px rgba(251,191,36,.8);animation:tfb-dotpulse 1.4s ease-in-out infinite}",
581
- ".tfb-dot-done{background:#4ade80}",
582
- ".tfb-dot-none{background:#6b7280}",
583
- "@keyframes tfb-dotpulse{0%,100%{opacity:1}50%{opacity:.4}}",
584
- ".tfb-pinlist{list-style:none;margin:2px 0 4px;padding:0 0 0 10px;border-left:2px solid rgba(255,255,255,.08)}",
585
- ".tfb-hint{font-size:10px;color:#6b7280;padding:6px 0 0;display:flex;align-items:center;justify-content:center;gap:4px;flex-wrap:wrap}",
586
- ".tfb-theme-menu{display:none;margin:-2px 0 8px;padding:6px;border:1px solid rgba(45,212,168,.25);border-radius:10px;background:rgba(12,16,20,.96)}",
587
- ".tfb-theme-menu.tfb-open{display:block}",
588
- ".tfb-theme-row{display:flex;align-items:center;gap:8px;padding:6px 8px;border-radius:8px;cursor:pointer;font-size:12px;color:#cdd6e2}",
589
- ".tfb-theme-row:hover{background:rgba(255,255,255,.06)}",
590
- ".tfb-theme-row.tfb-cur{color:#ffd27a;font-weight:600}",
591
- ".tfb-theme-row .tfb-theme-check{flex-shrink:0;width:14px;text-align:center}",
592
- ".tfb-theme-row .tfb-theme-label{flex:1;min-width:0}",
593
- ".tfb-rename{flex:1;min-width:0;padding:3px 8px;border-radius:6px;border:1px solid rgba(255,210,122,.5);background:rgba(0,0,0,.4);color:#ffd27a;font:inherit;font-size:12px;outline:none}",
594
- ".tfb-rename:focus{border-color:#ffd27a}",
595
- ".tfb-ctitle[contenteditable='true']{outline:none;border-bottom:1px dashed #ffd27a;color:#ffd27a;cursor:text}"
596
- ]).join("\n");
597
- }
598
-
599
- function listHtml(list) {
600
- var html = "";
601
- for (var i = 0; i < list.length; i++) {
602
- var t = list[i];
603
- var ico = t.status === "completed" ? "✓" : t.status === "in_progress" ? "▶" : "○";
604
- var txt = t.content.length > MAX_CONTENT ? t.content.slice(0, MAX_CONTENT) + "…" : t.content;
605
- html += '<li class="tfb-item" data-status="' + t.status + '"><span class="tfb-ico">' + ico + '</span><span class="tfb-txt">' + esc(txt) + "</span></li>";
606
- }
607
- return html;
608
- }
609
-
610
- function pinDotClass(sid) {
611
- var list = sessionTodos(sid);
612
- if (!list || !list.length) return "tfb-dot-none";
613
- var c = countsOf(list);
614
- if (c.done === c.total) return "tfb-dot-done";
615
- if (c.active > 0) return "tfb-dot-active";
616
- return "tfb-dot-none";
617
- }
618
-
619
- function renderList() {
620
- if (!ui.list) return;
621
- var c = currentList().length ? countsOf(currentList()) : { done: 0, active: 0, total: 0 };
622
- if (ui.ctitle) {
623
- // while the rename editor is live, don't rebuild the title cell
624
- if (editing.sid === normSid(currentSid)) { /* keep editor */ }
625
- else {
626
- ui.ctitle.textContent = currentSid ? sessionTitle(currentSid) : "";
627
- ui.ctitle.title = currentSid ? "点击重命名此对话" : "";
628
- }
629
- }
630
- if (ui.summary) {
631
- var parts = [];
632
- if (c.done > 0) parts.push(c.done + " 完成");
633
- if (c.active > 0) parts.push(c.active + " 进行中");
634
- var pend = c.total - c.done - c.active;
635
- if (pend > 0) parts.push(pend + " 待办");
636
- ui.summary.textContent = parts.join(" · ");
637
- }
638
- if (ui.pinBtn) {
639
- var on = currentSid && isPinned(currentSid);
640
- ui.pinBtn.classList.toggle("tfb-on", !!on);
641
- ui.pinBtn.title = on ? "取消固定当前会话" : "固定当前会话(切换对话后仍监控)";
642
- ui.pinBtn.textContent = on ? "📍" : "📌";
643
- }
644
- var list = currentList();
645
- if (!list.length) {
646
- ui.list.innerHTML = '<li class="tfb-empty">当前会话暂无任务清单<br><span style="font-size:10px">AI 使用 todo_write 后自动显示;📌 可固定会话</span></li>';
647
- } else {
648
- ui.list.innerHTML = listHtml(list);
649
- // user requirement 4: when work remains, remind how to keep the AI
650
- // going (this plugin is a read-only monitor — continuous thinking
651
- // is driven by dsh-client-auto-continue, already installed here).
652
- var cc = countsOf(list);
653
- if (cc.done < cc.total) {
654
- var left = cc.total - cc.done;
655
- ui.list.innerHTML += '<li class="tfb-empty" style="padding:6px 0 2px;font-size:10px">⚠️ 还有 ' + left + ' 项未完成 — 装/启用 dsh-client-auto-continue 可让 AI 连续思考直到清单完成</li>';
656
- }
657
- }
658
- renderPinned();
659
- }
660
-
661
- function renderPinned() {
662
- if (!ui.pinSec) return;
663
- if (pinned.length === 0) { ui.pinSec.innerHTML = ""; return; }
664
- if (editing.sid) return; // a rename editor is live — don't rebuild under it
665
- var html = '<div class="tfb-sep"><span class="tfb-sep-label">📌 已固定 (' + pinned.length + ')</span></div>';
666
- for (var i = 0; i < pinned.length; i++) {
667
- var sid = pinned[i];
668
- var list = sessionTodos(sid);
669
- var c = list ? countsOf(list) : null;
670
- var tname = sessionTitle(sid);
671
- var open = !!openPin[sid];
672
- html += '<div class="tfb-pinrow" data-act="togglePin" data-sid="' + esc(sid) + '">';
673
- html += '<span class="tfb-dot ' + pinDotClass(sid) + '"></span>';
674
- html += '<span class="tfb-pinname" title="' + esc(tname) + '">' + esc(tname) + "</span>";
675
- html += '<span class="tfb-pincount">' + (c ? c.done + "/" + c.total : "…") + "</span>";
676
- html += '<button class="tfb-btn" data-act="renamePin" data-sid="' + esc(sid) + '" title="重命名">✏️</button>';
677
- html += '<button class="tfb-btn" data-act="unpin" data-sid="' + esc(sid) + '" title="取消固定">✖</button>';
678
- html += "</div>";
679
- if (open) {
680
- if (list && list.length) {
681
- html += '<ul class="tfb-pinlist">' + listHtml(list) + "</ul>";
682
- } else {
683
- html += '<ul class="tfb-pinlist"><li class="tfb-empty" style="padding:6px 0">暂无数据(该会话产生 todo_write 后自动出现)</li></ul>';
684
- }
685
- }
686
- }
687
- ui.pinSec.innerHTML = html;
688
- }
689
-
690
- var THEME_NAMES = { nebula: "🌌 星云·流光", nebB: "🌟 星云·宝石", nebC: "🌙 星云·顶弧", graphite: "💎 石墨版", blue: "🔵 蓝宝石版", glass: "🧊 玻璃版" };
691
-
692
- function renderThemeMenu() {
693
- if (!ui.themeMenu) return;
694
- var html = "";
695
- var order = ["nebula", "nebB", "nebC", "graphite", "blue", "glass"];
696
- for (var i = 0; i < order.length; i++) {
697
- var th = order[i];
698
- var cur = th === currentTheme;
699
- html += '<div class="tfb-theme-row' + (cur ? " tfb-cur" : "") + '" data-act="setTheme" data-sid="' + th + '">' +
700
- '<span class="tfb-theme-check">' + (cur ? "✓" : " ") + "</span>" +
701
- '<span class="tfb-theme-label">' + (THEME_NAMES[th] || th) + "</span>" +
702
- "</div>";
703
- }
704
- ui.themeMenu.innerHTML = html;
705
- }
706
-
707
- function renderBall() {
708
- if (!ui.ball) return;
709
- var st = ballState();
710
- ui.ball.className = "tfb-ball " + st.cls + (capsule ? " tfb-capsule" : "");
711
- var labelEl = ui.ball.querySelector(".tfb-label");
712
- if (labelEl) labelEl.textContent = st.label;
713
- // progress ring: --pct = done/total*100 (0 when no list; 100 when all
714
- // done). The conic-gradient ring visualizes completion at a glance.
715
- var pct = 0;
716
- var list = currentList();
717
- if (list.length) {
718
- var c0 = countsOf(list);
719
- pct = c0.total > 0 ? Math.round(c0.done / c0.total * 100) : 0;
720
- }
721
- try { ui.ball.style.setProperty("--pct", String(pct)); } catch (e) {}
722
- var sub = "";
723
- if (capsule) {
724
- // capsule mode: show the running task (or overall status) in full;
725
- // overflowing text scrolls back and forth (marquee)
726
- if (list.length) {
727
- var c1 = countsOf(list);
728
- if (c1.done === c1.total) sub = "✓ 全部完成 " + c1.done + "/" + c1.total;
729
- else {
730
- var running = "";
731
- for (var r = 0; r < list.length; r++) {
732
- if (list[r].status === "in_progress") { running = list[r].content; break; }
733
- }
734
- sub = running
735
- ? "▶ " + running
736
- : "待办 " + c1.done + "/" + c1.total;
737
- }
738
- } else if (pinned.length) {
739
- for (var i = 0; i < pinned.length; i++) {
740
- var pl = sessionTodos(pinned[i]);
741
- if (pl && countsOf(pl).active > 0) { sub = "📌 " + (sessionTitle(pinned[i]) || "固定会话") + " 进行中"; break; }
742
- }
743
- if (!sub) sub = "📋 暂无进行中任务";
744
- } else {
745
- sub = "📋 暂无任务";
746
- }
747
- }
748
- // ROUND-BALL MODE: show ONLY the progress (user requirement) — no
749
- // task content on the ball face, since it never fits. The label is
750
- // done/total (or ✓); the sub line stays empty.
751
- var subEl = ui.ball.querySelector(".tfb-sub");
752
- if (subEl) {
753
- if (capsule) {
754
- subEl.innerHTML = '<span class="tfb-capsule-text">' + esc(sub) + "</span>";
755
- var textEl = subEl.querySelector(".tfb-capsule-text");
756
- if (textEl) {
757
- // measure AFTER layout: if the text overflows the pill, set the
758
- // scroll distance so the marquee ping-pongs exactly the overflow
759
- requestAnimationFrame(function () {
760
- try {
761
- var over = textEl.scrollWidth - subEl.clientWidth;
762
- if (over > 8) {
763
- textEl.style.setProperty("--shift", "-" + (over + 6) + "px");
764
- textEl.classList.add("tfb-marquee");
765
- } else {
766
- textEl.classList.remove("tfb-marquee");
767
- }
768
- } catch (e2) {}
769
- });
770
- }
771
- } else {
772
- subEl.textContent = "";
773
- }
774
- }
775
- ui.ball.title = capsule
776
- ? "胶囊模式(右键切回圆球;左键仍可展开面板)"
777
- : (list.length
778
- ? "Todo 悬浮球 — 当前 " + summarize(list).head + "(" + pct + "% 完成;左键展开/折叠 · 右键胶囊 · 可拖动)"
779
- : "Todo 悬浮球 — 当前会话暂无任务(左键展开 · 右键胶囊 · 可拖动)");
780
- }
781
-
782
- function render() {
783
- renderBall();
784
- renderList();
785
- if (expanded && ui.panel) positionPanel();
786
- }
787
-
788
- function positionPanel() {
789
- if (!ui.panel || !ui.ball) return;
790
- var r = ui.ball.getBoundingClientRect();
791
- var pw = ui.panel.offsetWidth || 300;
792
- var ph = ui.panel.offsetHeight || 320;
793
- var left = r.left + r.width / 2 - pw / 2;
794
- left = Math.max(8, Math.min(window.innerWidth - pw - 8, left));
795
- var top = r.top - ph - 12;
796
- if (top < 8) top = r.bottom + 12;
797
- ui.panel.style.left = left + "px";
798
- ui.panel.style.top = top + "px";
799
- }
800
-
801
- function show() {
802
- try { applyThemeNow(); } catch (e) {}
803
- expanded = true;
804
- if (ui.panel) { ui.panel.classList.add("tfb-open"); positionPanel(); }
805
- }
806
- function hide() {
807
- try { applyThemeNow(); } catch (e) {}
808
- expanded = false;
809
- if (ui.panel) ui.panel.classList.remove("tfb-open");
810
- // 字体插件同款:收起面板时刷新整个插件界面(重载 UI,主题/结构即时生效)
811
- setTimeout(function () { try { refreshPlugin(); } catch (e) {} }, 120);
812
- }
813
- function refreshPlugin() {
814
- try {
815
- var h = document.getElementById(BALL_ID);
816
- if (h) h.remove();
817
- ui = { root: null, ball: null, panel: null, list: null, summary: null, ctitle: null, pinBtn: null, pinSec: null, themeMenu: null };
818
- expanded = false;
819
- buildUI();
820
- applyBallVisibility();
821
- } catch (e) {}
822
- }
823
-
824
- function buildUI() {
825
- if (document.getElementById(BALL_ID)) return;
826
- if (!document.body) return;
827
- try { fetch("/dsh-todo-float-ball/client-alive").catch(function () {}); } catch (e) {}
828
-
829
- var host = document.createElement("div");
830
- host.id = BALL_ID;
831
-
832
- var shadow = host.attachShadow({ mode: "open" });
833
- var style = document.createElement("style");
834
- style.textContent = cssText();
835
- shadow.appendChild(style);
836
-
837
- var root = document.createElement("div");
838
- root.className = "tfb-root";
839
- root.innerHTML =
840
- '<button class="tfb-ball tfb-idle" type="button">' +
841
- '<span class="tfb-orb-band"></span>' +
842
- '<span class="tfb-orb-rim"></span>' +
843
- '<span class="tfb-ring"></span>' +
844
- '<span class="tfb-label">✓</span><span class="tfb-sub"></span>' +
845
- "</button>" +
846
- '<div class="tfb-panel">' +
847
- '<div class="tfb-head">' +
848
- '<span class="tfb-title">📋</span>' +
849
- '<span class="tfb-ctitle"></span>' +
850
- '<span class="tfb-summary"></span>' +
851
- '<button class="tfb-btn" data-act="pin" type="button">📌</button>' +
852
- '<button class="tfb-btn" data-act="themeMenu" type="button" title="切换皮肤">🎨</button>' +
853
- '<button class="tfb-btn" data-act="close" type="button" title="折叠">✕</button>' +
854
- "</div>" +
855
- '<div class="tfb-theme-menu"></div>' +
856
- '<ul class="tfb-list"></ul>' +
857
- '<div class="tfb-pinsec"></div>' +
858
- '<div class="tfb-hint"><button class="tfb-btn" data-act="resetPos" type="button" title="一键归位右下角">🎯 归位</button> · 切换对话自动跟随 · 📌 固定 · 🎨 皮肤 · Esc 折叠</div>' +
859
- "</div>";
860
- shadow.appendChild(root);
861
-
862
- // Mount to <html>, not body — DSH gives body containers transform/filter
863
- // which break position:fixed children (font-enhancer verified fix).
864
- var mount = document.documentElement || document.body;
865
- if (!host.parentNode) mount.appendChild(host);
866
-
867
- ui.root = root;
868
- ui.ball = root.querySelector(".tfb-ball");
869
- ui.panel = root.querySelector(".tfb-panel");
870
- ui.list = root.querySelector(".tfb-list");
871
- ui.ctitle = root.querySelector(".tfb-ctitle");
872
- ui.summary = root.querySelector(".tfb-summary");
873
- ui.pinBtn = root.querySelector('[data-act="pin"]');
874
- ui.pinSec = root.querySelector(".tfb-pinsec");
875
- ui.themeMenu = root.querySelector(".tfb-theme-menu");
876
-
877
- // restore position (clamped inside viewport)
878
- var bw = ui.ball.offsetWidth || 56, bh = ui.ball.offsetHeight || 56;
879
- try {
880
- var raw = localStorage.getItem(POS_KEY);
881
- if (raw) {
882
- var pos = JSON.parse(raw);
883
- if (pos && typeof pos.x === "number" && typeof pos.y === "number" &&
884
- pos.x >= 0 && pos.y >= 0 &&
885
- pos.x <= window.innerWidth - bw && pos.y <= window.innerHeight - bh) {
886
- ui.ball.style.left = pos.x + "px";
887
- ui.ball.style.top = pos.y + "px";
888
- ui.ball.style.right = "auto";
889
- ui.ball.style.bottom = "auto";
890
- }
891
- }
892
- } catch (e) {}
893
-
894
- // drag + click-to-toggle (5px threshold separates the two)
895
- var drag = { active: false, moved: false, sx: 0, sy: 0, ox: 0, oy: 0 };
896
- ui.ball.addEventListener("pointerdown", function (e) {
897
- drag.active = true; drag.moved = false;
898
- drag.sx = e.clientX; drag.sy = e.clientY;
899
- var r = ui.ball.getBoundingClientRect();
900
- drag.ox = r.left; drag.oy = r.top;
901
- try { ui.ball.setPointerCapture(e.pointerId); } catch (err) {}
902
- e.preventDefault();
903
- });
904
- ui.ball.addEventListener("pointermove", function (e) {
905
- if (!drag.active) return;
906
- var dx = e.clientX - drag.sx, dy = e.clientY - drag.sy;
907
- if (!drag.moved && Math.abs(dx) + Math.abs(dy) < 5) return;
908
- drag.moved = true;
909
- var nx = Math.max(0, Math.min(window.innerWidth - (ui.ball.offsetWidth || bw), drag.ox + dx));
910
- var ny = Math.max(0, Math.min(window.innerHeight - (ui.ball.offsetHeight || bh), drag.oy + dy));
911
- ui.ball.style.left = nx + "px";
912
- ui.ball.style.top = ny + "px";
913
- ui.ball.style.right = "auto";
914
- ui.ball.style.bottom = "auto";
915
- try { localStorage.setItem(POS_KEY, JSON.stringify({ x: Math.round(nx), y: Math.round(ny) })); } catch (err) {}
916
- if (expanded) positionPanel();
917
- });
918
- function endDrag(e) {
919
- if (!drag.active) return;
920
- drag.active = false;
921
- try { ui.ball.releasePointerCapture(e.pointerId); } catch (err) {}
922
- if (!drag.moved) { if (expanded) hide(); else show(); }
923
- }
924
- ui.ball.addEventListener("pointerup", endDrag);
925
- ui.ball.addEventListener("pointercancel", endDrag);
926
-
927
- // RIGHT-CLICK: toggle capsule mode (long pill showing the running
928
- // task); persists in localStorage.
929
- ui.ball.addEventListener("contextmenu", function (e) {
930
- e.preventDefault();
931
- capsule = !capsule;
932
- try { localStorage.setItem(CAPSULE_KEY, capsule ? "1" : "0"); } catch (err) {}
933
- render();
934
- });
935
-
936
- // delegated actions inside the shadow root
937
- root.addEventListener("click", function (e) {
938
- var t = e.target && e.target.closest ? e.target.closest("[data-act]") : null;
939
- if (!t) {
940
- // clicking the title text (not while editing) starts a rename
941
- if (e.target === ui.ctitle && currentSid && hasSessionsSvc) startRename(currentSid);
942
- return;
943
- }
944
- var act = t.getAttribute("data-act");
945
- var sid = t.getAttribute("data-sid");
946
- if (act === "close") hide();
947
- else if (act === "pin") {
948
- if (!currentSid) return;
949
- if (isPinned(currentSid)) unpin(currentSid); else pin(currentSid);
950
- } else if (act === "resetPos") {
951
- try { localStorage.removeItem(POS_KEY); } catch (err) {}
952
- if (ui.ball) { ui.ball.style.left = "auto"; ui.ball.style.top = "auto"; ui.ball.style.right = "18px"; ui.ball.style.bottom = "18px"; }
953
- } else if (act === "themeMenu") {
954
- // toggle the skin picker inside the panel
955
- if (ui.themeMenu) ui.themeMenu.classList.toggle("tfb-open");
956
- renderThemeMenu();
957
- e.stopPropagation();
958
- } else if (act === "setTheme" && sid) {
959
- // pick a skin from the menu
960
- currentTheme = sid;
961
- try { localStorage.setItem(THEME_KEY, sid); } catch (err) {}
962
- try {
963
- var stEl = ui.root.querySelector("style");
964
- if (stEl) stEl.textContent = cssText();
965
- } catch (err) {}
966
- render();
967
- renderThemeMenu();
968
- e.stopPropagation();
969
- } else if (act === "togglePin" && sid) {
970
- openPin[sid] = !openPin[sid];
971
- render();
972
- } else if (act === "renamePin" && sid) {
973
- e.stopPropagation();
974
- startRename(sid);
975
- } else if (act === "unpin" && sid) {
976
- e.stopPropagation();
977
- unpin(sid);
978
- }
979
- });
980
-
981
- window.addEventListener("resize", function () { if (expanded) positionPanel(); });
982
- document.addEventListener("keydown", function (e) { if (e.key === "Escape" && expanded) hide(); });
983
-
984
- render();
985
- }
986
-
987
- // ---------- entry ----------
988
- var inject = ["sessions"];
989
- var currentSessions = null;
990
-
991
- // Skin buttons live in the sibling settings section (React-rendered);
992
- // React synthetic events / refs proved unreliable there, so the buttons
993
- // carry plain data attributes and we delegate at the DOCUMENT capture
994
- // phase — immune to any re-render, and capture fires before anything
995
- // can stopPropagation.
996
- function installThemeDelegation() {
997
- if (window.__dshtfbThemeDelegated) return;
998
- window.__dshtfbThemeDelegated = true;
999
- document.addEventListener("click", function (e) {
1000
- var t = e.target && e.target.closest ? e.target.closest("[data-tfb-theme]") : null;
1001
- if (!t) return;
1002
- var theme = t.getAttribute("data-tfb-theme");
1003
- if (theme !== "nebula" && theme !== "graphite" && theme !== "blue" && theme !== "glass" && theme !== "nebB" && theme !== "nebC") return;
1004
- try { localStorage.setItem(THEME_KEY, theme); } catch (err) {}
1005
- currentTheme = theme;
1006
- applyThemeNow();
1007
- }, true);
1008
- }
1009
-
1010
- // ---------- ball visibility (driven by the shared settings section) ----------
1011
- // The show/hide toggle lives in the shared "悬浮球导航" settings section
1012
- // provided by dsh-skill-browser (same pattern as the font ball). We only
1013
- // read the shared localStorage key and apply it defensively.
1014
- var BALL_VIS_KEY = "dsh-tfb-ball-visible";
1015
- function ballVisible() {
1016
- try { var v = localStorage.getItem(BALL_VIS_KEY); return v == null ? true : v === "1"; } catch (e) { return true; }
1017
- }
1018
- function applyBallVisibility() {
1019
- var b = document.querySelector("#" + BALL_ID);
1020
- if (!b) return;
1021
- var show = ballVisible();
1022
- // Uninstall-fallback (ecosystem safety): the show/hide toggle lives in
1023
- // the shared "悬浮球导航" section provided by dsh-skill-browser. If
1024
- // that plugin is GONE and the stored flag says hidden, the ball would
1025
- // be stuck invisible with no way back — in that case ignore the flag
1026
- // and show the ball again.
1027
- if (!show) {
1028
- var providerGone = !document.getElementById("dsh-skill-browser-ball") &&
1029
- !document.querySelector('[data-dsb-slot]');
1030
- if (providerGone) show = true;
1031
- }
1032
- b.style.setProperty("display", show ? "" : "none", "important");
1033
- }
1034
- function watchBallVisibility() {
1035
- // Long-lived, low-frequency: the shared settings section writes the
1036
- // theme/visibility keys and expects them picked up — so this watcher
1037
- // must NOT expire (the old 20-min cap made skin switching die after
1038
- // 20 minutes). The sibling plugin also calls window.__dshtfbApplyTheme
1039
- // directly for instant effect; the poll is just a safety net.
1040
- setInterval(function () {
1041
- try { applyBallVisibility(); } catch (e) {}
1042
- try {
1043
- var v = null;
1044
- try { v = localStorage.getItem(THEME_KEY); } catch (e2) {}
1045
- if ((v === "graphite" || v === "nebula" || v === "blue" || v === "glass" || v === "nebB" || v === "nebC") && v !== currentTheme) applyThemeNow();
1046
- } catch (e) {}
1047
- }, 2000);
1048
- }
1049
- // Immediate theme application — exposed as window.__dshtfbApplyTheme so
1050
- // the sibling settings section can invoke it synchronously on click.
1051
- function applyThemeNow() {
1052
- try {
1053
- var v = localStorage.getItem(THEME_KEY);
1054
- if (v === "blue") currentTheme = "blue"; else if (v === "nebula") currentTheme = "nebula"; else if (v === "nebB") currentTheme = "nebB"; else if (v === "nebC") currentTheme = "nebC"; else if (v === "glass") currentTheme = "glass"; else currentTheme = "graphite";
1055
- } catch (e) {}
1056
- try {
1057
- if (ui.root) {
1058
- var st = ui.root.querySelector("style");
1059
- if (st) st.textContent = cssText();
1060
- }
1061
- } catch (e) {}
1062
- render();
1063
- }
1064
-
1065
- function apply(ctx) {
1066
- loadPinned();
1067
- loadTheme();
1068
- try { capsule = localStorage.getItem(CAPSULE_KEY) === "1"; } catch (e) {}
1069
- restorePersisted();
1070
- // primary data channel: the official sessions service
1071
- try {
1072
- if (ctx && ctx.sessions && ctx.sessions.list && typeof ctx.sessions.list.getSnapshot === "function") {
1073
- currentSessions = ctx.sessions;
1074
- hasSessionsSvc = true;
1075
- try { ctx.sessions.list.subscribe(syncFromSessions); } catch (e) {}
1076
- syncFromSessions();
1077
- }
1078
- } catch (e) {}
1079
- // global hook: lets the shared settings section switch the theme
1080
- // synchronously on click (no polling delay).
1081
- try {
1082
- window.__dshtfbApplyTheme = applyThemeNow;
1083
- } catch (e) {}
1084
- // document-level delegation for the sibling skin buttons (React
1085
- // synthetic events / refs unreliable in that slot — plain
1086
- // data-attribute buttons + capture-phase listener always fire)
1087
- installThemeDelegation();
1088
- // UI
1089
- if (document.readyState === "loading") {
1090
- document.addEventListener("DOMContentLoaded", buildUI);
1091
- } else {
1092
- buildUI();
1093
- }
1094
- applyBallVisibility();
1095
- watchBallVisibility();
1096
- // fallback channel only when the sessions service is unavailable
1097
- if (!hasSessionsSvc) installPanelObserver();
1098
- // watchdog keeps the ball alive across shell rebuilds
1099
- var tries = 0;
1100
- var t = setInterval(function () {
1101
- tries++;
1102
- try {
1103
- if (!document.getElementById(BALL_ID)) buildUI();
1104
- else renderBall();
1105
- if (hasSessionsSvc) syncFromSessions();
1106
- } catch (e) {}
1107
- if (tries > 300) clearInterval(t);
1108
- }, 2000);
1109
- }
1110
-
1111
- exports.apply = apply;
1112
- exports.inject = inject;
1113
- return module.exports;
1114
- }
1115
- });
1
+ window.__ModuleLoader__.load({
2
+ id: "dsh-todo-float-ball",
3
+ factory: function (require) {
4
+ var module = { exports: {} };
5
+ var exports = module.exports;
6
+
7
+ // ============================================================
8
+ // dsh-todo-float-ball — client half (browser). v0.9.1
9
+ //
10
+ // A persistent, draggable floating ball that mirrors todo_write lists.
11
+ //
12
+ // v0.3.0 — data layer rebuilt on the official `sessions` service:
13
+ // * inject: ["sessions"] — the runtime's global session registry.
14
+ // Its list snapshot carries, for EVERY session, the projection
15
+ // values computed by the host (todos, title/plan/...), plus the
16
+ // current session id and a subscribe() for changes.
17
+ // * This gives us multi-session todo data and instant session-switch
18
+ // detection with ZERO interception — no fetch/WS wrapping (desktop
19
+ // renders go through the shell's __DSH_TRANSPORT__ Electron bridge,
20
+ // which page-level taps can never see).
21
+ // * Fallback: if ctx.sessions is unavailable, fall back to observing
22
+ // the official todo panel DOM ([data-testid="todo-panel"]).
23
+ //
24
+ // Features: auto-follow active conversation; pin any conversation (📌)
25
+ // for cross-session monitoring; pinned list persists in localStorage;
26
+ // per-status colors; Shadow DOM isolation; draggable ball.
27
+ //
28
+ // v0.9.1 — refresh reliability + install-and-go:
29
+ // * refresh fix 1: the plan-aware "progress regressed => stale snapshot"
30
+ // guard is GONE. todo_write rewrites the WHOLE list, so a fresh
31
+ // snapshot may legitimately carry fewer completed items; dropping it
32
+ // froze the ball on outdated data. Signature dedupe is all we need.
33
+ // * refresh fix 2: the 2s watcher also pulls the sessions snapshot, so
34
+ // a dead subscribe() callback can no longer strand the ball on old
35
+ // data (cheap: the DOM is only touched when something actually moved).
36
+ // * DEFAULTS + getCfg(): every switch has a code default, seeded into
37
+ // localStorage on first run — install it and it just works.
38
+ // ============================================================
39
+
40
+ var BALL_ID = "dsh-tfb-root";
41
+ var POS_KEY = "dsh-todo-float-ball-pos";
42
+ var PIN_KEY = "dsh-todo-float-ball-pinned";
43
+ var CAPSULE_KEY = "dsh-todo-float-ball-capsule";
44
+ var MAX_CONTENT = 80;
45
+ var MAX_ITEMS = 100; // Plan-A history merge soft cap (see setSessionTodos)
46
+
47
+ // ============================================================
48
+ // Install-and-go defaults (v0.9.1)
49
+ //
50
+ // User requirement: "install the plugin and it just works" — no
51
+ // configuration step. Every user-facing switch therefore carries its
52
+ // default IN CODE below, so a machine with empty localStorage (fresh
53
+ // install, new profile, cleared data, or an origin that changed with the
54
+ // port) behaves exactly like a configured one.
55
+ //
56
+ // getCfg(key, def) reads the stored value, falls back to the code default,
57
+ // and SEEDS the key on first run so the value stays visible/editable
58
+ // afterwards. Seeding only ever writes a key that is ABSENT — an existing
59
+ // user's stored choice is never overwritten.
60
+ // ============================================================
61
+ var DEFAULTS = {
62
+ ballVisible: true, // dsh-tfb-ball-visible: ball always shown
63
+ theme: "graphite", // dsh-tfb-theme: graphite skin
64
+ capsule: false // dsh-todo-float-ball-capsule: round ball, not pill
65
+ };
66
+ // Position default = bottom-right. The CSS already renders
67
+ // right:18px;bottom:18px, but we also SEED the key on first run (user
68
+ // requirement: the value must exist and stay editable). The seeded point
69
+ // mirrors the CSS box (46px ball, 18px margin) and is clamped into the
70
+ // viewport; the restore path re-clamps and silently falls back to the CSS
71
+ // default when the stored point no longer fits (smaller window, or the
72
+ // wider capsule pill), so a stale seed can never park the ball off-screen.
73
+ var POS_BALL_SIZE = 46;
74
+ var POS_MARGIN = 18;
75
+
76
+ function seedValue(def) {
77
+ if (def === true) return "1";
78
+ if (def === false) return "0";
79
+ return String(def);
80
+ }
81
+ // Pure read: the stored string, else the code default (never writes).
82
+ function peekCfg(key, def) {
83
+ var d = seedValue(def);
84
+ try {
85
+ var raw = localStorage.getItem(key);
86
+ return (raw === null || raw === undefined) ? d : raw;
87
+ } catch (e) { return d; }
88
+ }
89
+ // Read-with-seed: like peekCfg, but persists the default on first run.
90
+ // Always returns a STRING, so callers can compare against "1"/"0" safely.
91
+ function getCfg(key, def) {
92
+ var d = seedValue(def);
93
+ var raw = null;
94
+ try { raw = localStorage.getItem(key); } catch (e) { return d; }
95
+ if (raw !== null && raw !== undefined) return raw;
96
+ try { localStorage.setItem(key, d); } catch (e) {}
97
+ return d;
98
+ }
99
+ // Idempotent first-run seed, called once from apply().
100
+ function ensureDefaultCfg() {
101
+ getCfg(BALL_VIS_KEY, DEFAULTS.ballVisible);
102
+ getCfg(THEME_KEY, DEFAULTS.theme);
103
+ getCfg(CAPSULE_KEY, DEFAULTS.capsule);
104
+ seedDefaultPos();
105
+ }
106
+ // Bottom-right corner for the CURRENT viewport, clamped so the ball is
107
+ // always fully visible. Returns null when the document has no viewport yet
108
+ // (headless / pre-layout), in which case we simply leave the key absent and
109
+ // let the CSS default apply.
110
+ function defaultPos() {
111
+ try {
112
+ var w = window.innerWidth || 0, h = window.innerHeight || 0;
113
+ if (!w || !h) return null;
114
+ return {
115
+ x: Math.max(0, w - POS_BALL_SIZE - POS_MARGIN),
116
+ y: Math.max(0, h - POS_BALL_SIZE - POS_MARGIN)
117
+ };
118
+ } catch (e) { return null; }
119
+ }
120
+ // Seed POS_KEY only when absent (an existing drag position is preserved).
121
+ function seedDefaultPos() {
122
+ try {
123
+ var raw = localStorage.getItem(POS_KEY);
124
+ if (raw !== null && raw !== undefined && raw !== "") return;
125
+ var p = defaultPos();
126
+ if (!p) return;
127
+ localStorage.setItem(POS_KEY, JSON.stringify(p));
128
+ } catch (e) {}
129
+ }
130
+
131
+ // ---------- multi-session state ----------
132
+ var bySession = {}; // sessionId -> { todos:[{content,status}], sig }
133
+ var titles = {}; // sessionId -> display title
134
+ var pinned = []; // [sessionId,...] (persisted)
135
+ var currentSid = null; // active session (from sessions.list.current)
136
+ var hasSessionsSvc = false;
137
+ var currentSessions = null;
138
+ var expanded = false;
139
+ var capsule = false; // right-click: pill mode showing active task
140
+ var openPin = {}; // pinned sessionId -> expanded? (UI state)
141
+ // Plan-A9: fold open-state is PER-SESSION (sid-normalized maps). The
142
+ // current session and every pinned session fold/collapse independently;
143
+ // an absent key means collapsed (the default).
144
+ var historyOpen = {}; // sid -> completed-history fold open?
145
+ var historyOpenOpen = {}; // sid -> non-completed-history fold open?
146
+ var editing = { sid: null }; // inline rename editor state (one at a time)
147
+ // Plan-A2: contents the user hid with the row ✕. Display-only (the data
148
+ // source is untouched); per session so it never bleeds across chats.
149
+ var hiddenItems = {}; // sessionId -> { content:true, ... }
150
+ var HIDE_KEY = "dsh-todo-float-ball-hidden-v1";
151
+ var ui = { root: null, ball: null, panel: null, list: null, summary: null, ctitle: null, pinBtn: null, pinSec: null };
152
+
153
+ function normSid(sid) {
154
+ return (typeof sid === "string" && sid) ? sid : "current";
155
+ }
156
+
157
+ // ---------- pinned persistence ----------
158
+ function loadPinned() {
159
+ try {
160
+ var raw = localStorage.getItem(PIN_KEY);
161
+ if (raw) {
162
+ var arr = JSON.parse(raw);
163
+ if (Array.isArray(arr)) pinned = arr.filter(function (x) { return typeof x === "string" && x; });
164
+ }
165
+ } catch (e) { pinned = []; }
166
+ }
167
+ function savePinned() {
168
+ try { localStorage.setItem(PIN_KEY, JSON.stringify(pinned)); } catch (e) {}
169
+ }
170
+ function isPinned(sid) { return pinned.indexOf(sid) >= 0; }
171
+
172
+ // ---------- hidden-item set (Plan-A2) ----------
173
+ function loadHidden() {
174
+ try {
175
+ var raw = localStorage.getItem(HIDE_KEY);
176
+ if (raw) {
177
+ var obj = JSON.parse(raw);
178
+ if (obj && typeof obj === "object") hiddenItems = obj;
179
+ }
180
+ } catch (e) { hiddenItems = {}; }
181
+ }
182
+ function saveHidden() {
183
+ try { localStorage.setItem(HIDE_KEY, JSON.stringify(hiddenItems)); } catch (e) {}
184
+ }
185
+ function hiddenFor(sid) {
186
+ sid = normSid(sid);
187
+ if (!hiddenItems[sid] || typeof hiddenItems[sid] !== "object") hiddenItems[sid] = {};
188
+ return hiddenItems[sid];
189
+ }
190
+ // filter a list through the session's hidden set (display-only)
191
+ function visibleList(sid, list) {
192
+ var hid = hiddenFor(sid);
193
+ var keys = Object.keys(hid);
194
+ if (!keys.length || !Array.isArray(list)) return list;
195
+ var out = [];
196
+ for (var i = 0; i < list.length; i++) {
197
+ if (!hid[list[i].content]) out.push(list[i]);
198
+ }
199
+ return out;
200
+ }
201
+ function hideItem(sid, content) {
202
+ if (!content) return;
203
+ hiddenFor(sid)[content] = true;
204
+ saveHidden();
205
+ render();
206
+ }
207
+ function showItem(sid, content) {
208
+ var hid = hiddenFor(sid);
209
+ if (content in hid) { delete hid[content]; saveHidden(); render(); }
210
+ }
211
+ function pin(sid) {
212
+ sid = normSid(sid);
213
+ if (isPinned(sid)) return;
214
+ pinned.push(sid);
215
+ savePinned();
216
+ render();
217
+ }
218
+ function unpin(sid) {
219
+ var i = pinned.indexOf(sid);
220
+ if (i >= 0) { pinned.splice(i, 1); savePinned(); render(); }
221
+ }
222
+
223
+ // ---------- helpers ----------
224
+ function esc(s) {
225
+ return String(s)
226
+ .replace(/&/g, "&amp;")
227
+ .replace(/</g, "&lt;")
228
+ .replace(/>/g, "&gt;")
229
+ .replace(/"/g, "&quot;");
230
+ }
231
+
232
+ function countsOf(list) {
233
+ var done = 0, active = 0;
234
+ for (var i = 0; i < list.length; i++) {
235
+ if (list[i].status === "completed") done++;
236
+ else if (list[i].status === "in_progress") active++;
237
+ }
238
+ return { done: done, active: active, total: list.length };
239
+ }
240
+
241
+ function sessionTodos(sid) {
242
+ var b = bySession[normSid(sid)];
243
+ return b ? b.todos : null;
244
+ }
245
+ // Plan-A2.2: display variant of sessionTodos — filters the session's
246
+ // hidden rows out. Pinned panels and their header counts use this so
247
+ // a ✕ works identically in the current list and pinned lists.
248
+ function sessionTodosVisible(sid) {
249
+ return visibleList(normSid(sid), sessionTodos(sid));
250
+ }
251
+ function sessionTitle(sid) {
252
+ sid = normSid(sid);
253
+ if (titles[sid]) return titles[sid];
254
+ return sid === "current" ? "" : sid.slice(0, 10) + "…";
255
+ }
256
+
257
+ // ---------- rename (official API) ----------
258
+ // Path (verified against dsh-client-runtime): the sessions facade exposes
259
+ // .manager; SessionManager lazily builds resident Session records
260
+ // (.sessions Map, .get(sessionId) is side-effect-safe); each Session has
261
+ // .rename(title) → api.sessions.rename → host normalizes → title
262
+ // projection updates → our sessions.list subscription re-renders.
263
+ function renameSession(sid, title) {
264
+ sid = normSid(sid);
265
+ var clean = (typeof title === "string" ? title.trim() : "");
266
+ if (!clean) return Promise.resolve(false);
267
+ try {
268
+ var mgr = currentSessions && currentSessions.manager;
269
+ var session = mgr && mgr.sessions && typeof mgr.sessions.get === "function" ? mgr.sessions.get(sid) : null;
270
+ if (session && typeof session.rename === "function") {
271
+ return Promise.resolve(session.rename(clean)).then(function (result) {
272
+ if (result && result.ok) {
273
+ titles[sid] = (result.value && result.value.title) || clean;
274
+ render();
275
+ return true;
276
+ }
277
+ render();
278
+ return false;
279
+ }).catch(function () { render(); return false; });
280
+ }
281
+ } catch (e) {}
282
+ return Promise.resolve(false);
283
+ }
284
+
285
+ function startRename(sid) {
286
+ if (!hasSessionsSvc) return;
287
+ sid = normSid(sid);
288
+ if (editing.sid) return; // one editor at a time
289
+ var isCurrent = sid === normSid(currentSid);
290
+ var host = isCurrent ? ui.ctitle
291
+ : (ui.pinSec ? ui.pinSec.querySelector('.tfb-pinrow[data-sid="' + sid + '"] .tfb-pinname') : null);
292
+ if (!host) return;
293
+ editing.sid = sid;
294
+ var old = sessionTitle(sid);
295
+ host.innerHTML = '<input class="tfb-rename" data-rename="1" value="' + esc(old) + '" placeholder="会话名称">';
296
+ var input = host.querySelector("input");
297
+ if (!input) { editing.sid = null; return; }
298
+ input.focus();
299
+ try { input.select(); } catch (e) {}
300
+ var done = false;
301
+ var commit = function () {
302
+ if (done) return; done = true;
303
+ var v = input.value;
304
+ editing.sid = null;
305
+ if (v && v.trim() && v.trim() !== old) renameSession(sid, v);
306
+ else render();
307
+ };
308
+ var cancel = function () {
309
+ if (done) return; done = true;
310
+ editing.sid = null;
311
+ render();
312
+ };
313
+ input.addEventListener("keydown", function (e) {
314
+ if (e.key === "Enter") { e.preventDefault(); commit(); }
315
+ else if (e.key === "Escape") { e.preventDefault(); cancel(); }
316
+ });
317
+ input.addEventListener("blur", commit);
318
+ input.addEventListener("click", function (e) { e.stopPropagation(); });
319
+ input.addEventListener("pointerdown", function (e) { e.stopPropagation(); });
320
+ }
321
+
322
+ // Plan-A2: display list = stored list minus the user's hidden rows
323
+ // (panel list and summary read this).
324
+ function currentList() { return visibleList(currentSid, sessionTodos(currentSid)) || []; }
325
+ // Plan-A4 (user-approved): the ball face, progress ring, header summary
326
+ // and the "items left" hint report the CURRENT SNAPSHOT only — the AI's
327
+ // actual live plan. Accumulated history (the folds) stays out of every
328
+ // counter: it is an archive, not progress.
329
+ // Plan-A9: general-sid snapshot slice — the session's visible merged
330
+ // list cut at its snapLen (history folds live strictly after it). The
331
+ // ONE source of truth for every "snapshot only" counter (A4 rule),
332
+ // current session and pinned sessions alike.
333
+ function snapshotRowsOf(sid) {
334
+ var nsid = normSid(sid);
335
+ var raw = sessionTodos(nsid) || [];
336
+ var b = bySession[nsid];
337
+ var snapLen = (b && typeof b.snapLen === "number") ? Math.min(b.snapLen, raw.length) : raw.length;
338
+ return visibleList(nsid, raw.slice(0, snapLen));
339
+ }
340
+ function snapshotList() { return snapshotRowsOf(currentSid); }
341
+
342
+ function summarize(list) {
343
+ var c = countsOf(list);
344
+ var head = c.done + "/" + c.total;
345
+ var detail = "";
346
+ if (c.active > 0) {
347
+ var first = null;
348
+ for (var i = 0; i < list.length; i++) {
349
+ if (list[i].status === "in_progress") { first = list[i].content; break; }
350
+ }
351
+ if (first) detail = first.length > 30 ? first.slice(0, 30) + "…" : first;
352
+ if (c.active > 1) detail += " (+" + (c.active - 1) + ")";
353
+ }
354
+ return { head: head, detail: detail, c: c };
355
+ }
356
+
357
+ function ballState() {
358
+ var list = snapshotList(); // Plan-A4: current snapshot only
359
+ if (!list.length) return { cls: "tfb-idle", label: "✓" };
360
+ var c = countsOf(list);
361
+ if (c.done === c.total) return { cls: "tfb-done", label: "✓" };
362
+ return { cls: c.active > 0 ? "tfb-active" : "tfb-pending", label: String(c.done) + "/" + String(c.total) };
363
+ }
364
+
365
+ // ---------- durable persistence (user requirement: cross-turn /
366
+ // cross-refresh record survival) ----------
367
+ // Every accepted snapshot is written to localStorage keyed by session.
368
+ // On restore we take whichever side is "further along" (more completed
369
+ // items, tie-break by total, then by recency) so nothing — a stale
370
+ // snapshot poll, a page reload, a projection rebuild — can drag the
371
+ // record BACKWARD. Completed items are history, not transients.
372
+ var PERSIST_KEY = "dsh-todo-float-ball-persist-v1";
373
+ var persistTimer = null;
374
+ function loadPersisted() {
375
+ var out = {};
376
+ try {
377
+ var raw = localStorage.getItem(PERSIST_KEY);
378
+ if (raw) out = JSON.parse(raw) || {};
379
+ } catch (e) { out = {}; }
380
+ return out;
381
+ }
382
+ function persistSoon() {
383
+ if (persistTimer) return;
384
+ persistTimer = setTimeout(function () {
385
+ persistTimer = null;
386
+ try {
387
+ var out = {};
388
+ for (var sid in bySession) {
389
+ var b = bySession[sid];
390
+ if (b && b.todos && b.todos.length) {
391
+ out[sid] = { todos: b.todos, sig: b.sig, at: b.at || 0, snapLen: b.snapLen || 0 };
392
+ }
393
+ }
394
+ localStorage.setItem(PERSIST_KEY, JSON.stringify(out));
395
+ } catch (e) {}
396
+ }, 400);
397
+ }
398
+ // progress score: completed count dominates, then total, then recency.
399
+ // planKey: the sorted content set — identical set = same plan (progress
400
+ // within one plan must never regress); different set = a new plan.
401
+ function planKey(todos) {
402
+ return todos.map(function (t) { return t.content; }).sort().join("\n");
403
+ }
404
+ function progressScore(todos, at) {
405
+ var c = countsOf(todos);
406
+ return c.done * 10000 + c.total * 100 + Math.min(99, Math.floor(((at || 0) / 60000) % 100));
407
+ }
408
+ function restorePersisted() {
409
+ try {
410
+ var saved = loadPersisted();
411
+ for (var sid in saved) {
412
+ var rec = saved[sid];
413
+ if (!rec || !Array.isArray(rec.todos) || rec.todos.length === 0) continue;
414
+ var norm = [];
415
+ for (var i = 0; i < rec.todos.length; i++) {
416
+ var it = rec.todos[i];
417
+ if (it && typeof it.content === "string" && it.content.trim()) {
418
+ norm.push({ content: it.content, status: it.status });
419
+ }
420
+ }
421
+ if (!norm.length) continue;
422
+ var mem = bySession[sid];
423
+ if (mem && mem.todos && mem.todos.length) {
424
+ // different plan: the live snapshot wins (it is what the host
425
+ // currently holds); same plan: keep the further-along record
426
+ if (planKey(mem.todos) !== planKey(norm)) continue;
427
+ if (progressScore(norm, rec.at) <= progressScore(mem.todos, mem.at)) continue;
428
+ }
429
+ bySession[sid] = { todos: norm, sig: rec.sig || norm.map(function (t) { return t.status + "|" + t.content; }).join("\n"), stale: false, at: rec.at || 0, snapLen: rec.snapLen || norm.length };
430
+ }
431
+ } catch (e) {}
432
+ }
433
+
434
+ // ---------- data ingestion ----------
435
+ function setSessionTodos(sid, list) {
436
+ sid = normSid(sid);
437
+ if (!Array.isArray(list)) return false; // false = nothing changed
438
+ var norm = [];
439
+ for (var i = 0; i < list.length; i++) {
440
+ var it = list[i];
441
+ if (!it || typeof it !== "object") continue;
442
+ var st = it.status;
443
+ if (st !== "pending" && st !== "in_progress" && st !== "completed") continue;
444
+ var content = typeof it.content === "string" ? it.content : "";
445
+ if (!content.trim()) continue;
446
+ norm.push({ content: content, status: st });
447
+ }
448
+ if (norm.length === 0) {
449
+ // STICKY: the host resets the todos projection to null at every
450
+ // turn/start. Never wipe the last known list — only a real
451
+ // todo_write snapshot (or a strictly-more-complete persisted one)
452
+ // changes it. Per-session bucketing keeps this from bleeding
453
+ // across conversations.
454
+ var b0 = bySession[sid];
455
+ if (b0) b0.stale = true;
456
+ return false; // sticky: an empty payload never wipes the record
457
+ }
458
+ var sig = norm.map(function (t) { return t.status + "|" + t.content; }).join("\n");
459
+ var b = bySession[sid];
460
+ // Signature dedupe FIRST (v0.9.1 semantics, unchanged): an identical
461
+ // snapshot from the 2s safety-net poll or a re-subscribe must stay a
462
+ // cheap no-op — in particular it must NEVER undo the user's ✕ hides.
463
+ // Plan-A2 auto-resurface therefore runs only AFTER we know this is a
464
+ // genuinely NEW snapshot (a real todo_write): if the model explicitly
465
+ // lists a previously hidden item again, that row is live again and
466
+ // un-hides. The ✕ keeps silencing rows that merely sit in the merged
467
+ // history / unchanged snapshot.
468
+ if (b && b.sig === sig) { b.stale = false; return false; }
469
+ var hid0 = hiddenFor(sid);
470
+ for (var h0 in hid0) {
471
+ for (var ni0 = 0; ni0 < norm.length; ni0++) {
472
+ if (norm[ni0].content === h0) { delete hid0[h0]; break; }
473
+ }
474
+ }
475
+ saveHidden();
476
+ // NO progress-regression guard (removed in v0.9.1 on a user bug report).
477
+ // todo_write is a WHOLE-LIST replacement, so a fresh snapshot may
478
+ // legitimately carry FEWER completed items than the last one rendered:
479
+ // the list was re-organised, a status was re-adjusted, an item was
480
+ // re-opened, or a round rewrote the plan. The old plan-aware guard
481
+ // compared done-counts within an identical content set and silently
482
+ // dropped those snapshots as "stale", which is exactly why the ball kept
483
+ // showing outdated progress. A new snapshot now ALWAYS wins; the
484
+ // signature check above is the only dedupe (unchanged input costs
485
+ // nothing, so no redundant work).
486
+ // Plan-A history merge (2026-09-13, user approved): the snapshot is a
487
+ // whole-list replacement, so simply overwriting bySession[sid] made
488
+ // earlier tasks vanish whenever a new round rewrote the list. Merge
489
+ // instead: the fresh snapshot leads (its statuses win), and items that
490
+ // only exist in the previous record are appended in their last known
491
+ // state — history never disappears. A soft cap keeps the list bounded.
492
+ var merged = [];
493
+ var seen = {};
494
+ for (var mi = 0; mi < norm.length; mi++) {
495
+ seen[norm[mi].content] = true;
496
+ merged.push(norm[mi]);
497
+ }
498
+ // (auto-resurface now runs before the signature dedupe; see Plan-A2 note)
499
+ var prev = (b && b.todos) ? b.todos : [];
500
+ for (var pi = 0; pi < prev.length; pi++) {
501
+ if (!seen[prev[pi].content]) {
502
+ seen[prev[pi].content] = true;
503
+ merged.push(prev[pi]);
504
+ }
505
+ }
506
+ // soft cap: keep the ENTIRE snapshot (it leads) plus the most recent
507
+ // history entries that still fit — oldest history overflows first.
508
+ // (A snapshot larger than the cap itself is kept in full: it is what
509
+ // the host currently holds, truncating it would hide live tasks.)
510
+ if (merged.length > MAX_ITEMS && norm.length < MAX_ITEMS) {
511
+ var histQuota = MAX_ITEMS - norm.length;
512
+ merged = norm.concat(merged.slice(Math.max(norm.length, merged.length - histQuota)));
513
+ }
514
+ // Plan-A3 (user-approved option ③): remember where the fresh snapshot
515
+ // ends. Everything after snapLen is accumulated history — rendered
516
+ // collapsed (completed-only) by renderList; the snapshot itself stays
517
+ // fully visible.
518
+ bySession[sid] = { todos: merged, sig: sig, stale: false, at: Date.now(), snapLen: norm.length };
519
+ render();
520
+ persistSoon();
521
+ return true; // a new snapshot was accepted -> the caller must re-render
522
+ }
523
+
524
+ // Primary channel: the official sessions service.
525
+ // list snapshot shape (from dsh-client-runtime):
526
+ // { ids:[...], byId:{ sid:{ id, displayTitle, running, projectionValues:{todos,title,...}, ... } },
527
+ // current: sid|undefined, phase }
528
+ function syncFromSessions() {
529
+ try {
530
+ if (!currentSessions || !currentSessions.list || typeof currentSessions.list.getSnapshot !== "function") return;
531
+ var snap = currentSessions.list.getSnapshot();
532
+ if (!snap || !snap.byId) return;
533
+ var changed = false;
534
+ for (var id in snap.byId) {
535
+ var rec = snap.byId[id];
536
+ if (!rec) continue;
537
+ if (typeof rec.displayTitle === "string" && rec.displayTitle && titles[id] !== rec.displayTitle) {
538
+ titles[id] = rec.displayTitle;
539
+ changed = true;
540
+ }
541
+ var pv = rec.projectionValues;
542
+ if (pv && typeof pv === "object" && "todos" in pv) {
543
+ if (setSessionTodos(id, pv.todos === null ? [] : pv.todos)) changed = true;
544
+ }
545
+ }
546
+ if (snap.current && snap.current !== currentSid) {
547
+ currentSid = snap.current;
548
+ changed = true;
549
+ }
550
+ // Only touch the DOM when something actually moved. This is what lets
551
+ // the 2s safety-net poll be effectively free while nothing changes
552
+ // (the settings/theme skin switches still re-render via render()).
553
+ if (changed) render();
554
+ } catch (e) {}
555
+ }
556
+
557
+ // Fallback channel: observe the official todo panel DOM. Expanded panel
558
+ // renders ul > li[data-status]; collapsed renders only header counts
559
+ // (parsed into a skeleton — better than nothing when sessions service
560
+ // is unavailable).
561
+ function installPanelObserver() {
562
+ var mo = new MutationObserver(function () {
563
+ if (installPanelObserver._t) return;
564
+ installPanelObserver._t = setTimeout(function () {
565
+ installPanelObserver._t = 0;
566
+ try { readOfficialPanel(); } catch (e) {}
567
+ }, 200);
568
+ });
569
+ function start() {
570
+ try {
571
+ mo.observe(document.documentElement || document.body, { childList: true, subtree: true });
572
+ readOfficialPanel();
573
+ } catch (e) {}
574
+ }
575
+ if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", start);
576
+ else start();
577
+ }
578
+
579
+ var ZH_NUM = { "零": 0, "一": 1, "二": 2, "两": 2, "三": 3, "四": 4, "五": 5, "六": 6, "七": 7, "八": 8, "九": 9, "十": 10 };
580
+
581
+ function parseZhNum(s) {
582
+ s = String(s).trim();
583
+ if (/^\d+$/.test(s)) return parseInt(s, 10);
584
+ if (ZH_NUM[s] !== undefined) return ZH_NUM[s];
585
+ if (/^十$/.test(s)) return 10;
586
+ var m = /^([一二两三四五六七八九])?十([一二三四五六七八九])?$/.exec(s);
587
+ if (m) return (m[1] ? ZH_NUM[m[1]] : 1) * 10 + (m[2] ? ZH_NUM[m[2]] : 0);
588
+ return NaN;
589
+ }
590
+
591
+ function readOfficialPanel() {
592
+ var panel = document.querySelector('[data-testid="todo-panel"]');
593
+ if (!panel) return;
594
+ var items = panel.querySelectorAll("ul li[data-status]");
595
+ if (items.length > 0) {
596
+ var list = [];
597
+ for (var i = 0; i < items.length; i++) {
598
+ var li = items[i];
599
+ var st = li.getAttribute("data-status");
600
+ var contentEl = li.querySelector("span:last-child") || li.lastElementChild;
601
+ var content = contentEl ? (contentEl.textContent || "").trim() : "";
602
+ if (content) list.push({ content: content, status: st || "pending" });
603
+ }
604
+ if (list.length > 0) { setSessionTodos(currentSid, list); return; }
605
+ }
606
+ // collapsed: skeleton only if the current session has no real data
607
+ var cur = bySession[normSid(currentSid)];
608
+ var hasReal = cur && cur.todos && cur.todos.length > 0 && !cur.__skeleton;
609
+ if (hasReal) return;
610
+ var label = panel.querySelector('[class*="progress"]');
611
+ if (!label) return;
612
+ var text = (label.textContent || "").trim();
613
+ if (!text) return;
614
+ var segs = text.split("·");
615
+ var done = NaN, active = NaN, pending = NaN;
616
+ for (var k = 0; k < segs.length; k++) {
617
+ var s = segs[k].trim();
618
+ var n = parseZhNum(s.split(" ")[0]);
619
+ if (isNaN(n)) continue;
620
+ if (s.indexOf("完成") >= 0) done = n;
621
+ else if (s.indexOf("进行") >= 0) active = n;
622
+ else if (s.indexOf("待办") >= 0) pending = n;
623
+ }
624
+ if (isNaN(done) && isNaN(active) && isNaN(pending)) return;
625
+ // only show the skeleton when we have nothing real, and mark it
626
+ if (bySession[normSid(currentSid)] && !bySession[normSid(currentSid)].__skeleton) return;
627
+ var skel = [];
628
+ for (var d = 0; d < (isNaN(done) ? 0 : done); d++) skel.push({ content: "已完成任务", status: "completed" });
629
+ for (var a = 0; a < (isNaN(active) ? 0 : active); a++) skel.push({ content: "进行中任务", status: "in_progress" });
630
+ for (var p = 0; p < (isNaN(pending) ? 0 : pending); p++) skel.push({ content: "待办任务", status: "pending" });
631
+ if (skel.length > 0) {
632
+ setSessionTodos(currentSid, skel);
633
+ var bb = bySession[normSid(currentSid)];
634
+ if (bb) bb.__skeleton = true;
635
+ render();
636
+ }
637
+ }
638
+
639
+ // ---------- UI ----------
640
+ // ---------- theme (dual skin, user requirement) ----------
641
+ // "nebula" — skill-orb style clone (v0.6.2): nebula body + flowing
642
+ // bands + rotating conic rim + breathing + glow text.
643
+ // "graphite" — v0.5.1 dark-gem style: same glass family as
644
+ // font-enhancer, teal accent + thin progress ring.
645
+ // Persisted in localStorage; switched from the shared "悬浮球导航"
646
+ // settings section (dsh-skill-browser provides the button).
647
+ var THEME_KEY = "dsh-tfb-theme";
648
+ var currentTheme = DEFAULTS.theme;
649
+ // single source of truth for "is this a known skin?"
650
+ function isTheme(t) {
651
+ return t === "nebula" || t === "graphite" || t === "blue" || t === "glass" || t === "nebB" || t === "nebC";
652
+ }
653
+ function loadTheme() {
654
+ // stored value wins; absent => seeded default; unknown => default
655
+ var v = getCfg(THEME_KEY, DEFAULTS.theme);
656
+ currentTheme = isTheme(v) ? v : DEFAULTS.theme;
657
+ }
658
+ function setTheme(t) {
659
+ if (t !== "nebula" && t !== "graphite" && t !== "blue" && t !== "glass" && t !== "nebB" && t !== "nebC") return;
660
+ currentTheme = t;
661
+ try { localStorage.setItem(THEME_KEY, t); } catch (e) {}
662
+ render();
663
+ }
664
+
665
+ function cssText() {
666
+ var th = currentTheme;
667
+ // Skeleton fields that all four skins share; shape differs per skin.
668
+ var SIZE = "width:46px;height:46px;";
669
+ // Per-skin ball rules (status variants + ring + band/rim).
670
+ var ball = [];
671
+ if (th === "nebula") {
672
+ ball = [
673
+ ".tfb-ball{position:fixed;right:18px;bottom:18px;z-index:2147483600;border-radius:50%;border:1px solid rgba(255,255,255,.28);cursor:grab;user-select:none;touch-action:none;pointer-events:auto;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:1px;color:#eafff7;font-size:13px;font-weight:800;line-height:1.1;background:radial-gradient(circle at 50% 60%, #2dd4a8 0%, #17a284 20%, #12876f 45%, #0a3a32 68%, #041715 100%);box-shadow:0 0 22px rgba(45,212,168,.5),0 0 4px rgba(120,255,214,.35),0 4px 18px rgba(0,0,0,.55),inset 0 1px 3px rgba(255,255,255,.4),inset 0 -8px 16px rgba(45,212,168,.16),inset 0 0 14px rgba(20,180,150,.25);text-shadow:0 0 6px rgba(120,255,214,.75),0 2px 4px rgba(0,40,30,.8);filter:drop-shadow(0 0 6px rgba(160,255,225,.85));animation:tfbBreathe 3.2s ease-in-out infinite;transition:transform .15s ease}" + SIZE.replace(";", ";"),
674
+ ".tfb-orb-band{display:none}",
675
+ ".tfb-orb-rim{position:absolute;inset:-1px;border-radius:50%;z-index:1;pointer-events:none;background:conic-gradient(from 200deg, rgba(255,255,255,.55), rgba(120,240,205,.35), rgba(10,200,170,.4), rgba(255,255,255,.15), rgba(45,212,168,.4), rgba(255,255,255,.55));-webkit-mask:radial-gradient(circle, transparent 63%, #000 66%, #000 72%, transparent 76%);mask:radial-gradient(circle, transparent 63%, #000 66%, #000 72%, transparent 76%);animation:tfbRimSpin 7s linear infinite;filter:blur(.5px)}",
676
+ ".tfb-ball .tfb-ring{display:none}",
677
+ ".tfb-ball .tfb-label{animation:tfbGlow 2.4s ease-in-out infinite}",
678
+ ".tfb-ball.tfb-active{color:#fff3dc;background:radial-gradient(circle at 50% 60%, #ffaa33 0%, #e08410 20%, #b56708 45%, #4a2a06 70%, #170c02 100%);box-shadow:0 0 22px rgba(255,170,51,.55),0 0 4px rgba(255,210,120,.4),0 4px 18px rgba(0,0,0,.55),inset 0 1px 3px rgba(255,255,255,.4),inset 0 -8px 16px rgba(255,170,51,.16),inset 0 0 14px rgba(230,140,20,.25);text-shadow:0 0 4px rgba(255,255,255,.95),0 0 10px rgba(255,215,140,.95),0 0 20px rgba(255,160,40,.8),0 2px 4px rgba(60,30,0,.8);filter:drop-shadow(0 0 6px rgba(255,200,110,.9))}",
679
+ ".tfb-ball.tfb-active .tfb-orb-rim{background:conic-gradient(from 200deg, rgba(255,255,255,.6), rgba(255,200,110,.4), rgba(255,150,30,.45), rgba(255,255,255,.15), rgba(255,190,80,.4), rgba(255,255,255,.6));animation-duration:2.6s}",
680
+ ".tfb-ball.tfb-done{color:#eafff4;background:radial-gradient(circle at 50% 60%, #5dffa8 0%, #22c070 20%, #12875c 45%, #073c26 70%, #02150c 100%);box-shadow:0 0 26px rgba(93,255,168,.6),0 0 5px rgba(180,255,215,.45),0 4px 18px rgba(0,0,0,.55),inset 0 1px 3px rgba(255,255,255,.45),inset 0 -8px 16px rgba(93,255,168,.18),inset 0 0 14px rgba(40,200,120,.3);text-shadow:0 0 4px rgba(255,255,255,1),0 0 12px rgba(190,255,220,1),0 0 24px rgba(60,255,150,.85),0 2px 4px rgba(0,40,20,.8);filter:drop-shadow(0 0 8px rgba(140,255,195,.95))}",
681
+ ".tfb-ball.tfb-pending{color:#e8f3ff;background:radial-gradient(circle at 50% 60%, #7fc4ff 0%, #4f92e0 20%, #2f6cb0 45%, #12305c 70%, #04101e 100%);box-shadow:0 0 22px rgba(127,196,255,.5),0 0 4px rgba(180,220,255,.35),0 4px 18px rgba(0,0,0,.55),inset 0 1px 3px rgba(255,255,255,.4),inset 0 -8px 16px rgba(127,196,255,.15),inset 0 0 14px rgba(70,140,220,.25);text-shadow:0 0 4px rgba(255,255,255,.95),0 0 10px rgba(190,225,255,.9),0 0 20px rgba(90,170,255,.75),0 2px 4px rgba(0,20,45,.8);filter:drop-shadow(0 0 6px rgba(170,215,255,.85))}"
682
+ ];
683
+ } else if (th === "blue") {
684
+ ball = [
685
+ ".tfb-ball{position:fixed;right:18px;bottom:18px;z-index:2147483600;border-radius:50%;border:1px solid rgba(255,255,255,.28);cursor:grab;user-select:none;touch-action:none;pointer-events:auto;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:1px;color:#a8c8ff;font-size:13px;font-weight:800;line-height:1.1;background:radial-gradient(circle at 30% 25%,rgba(255,255,255,.18),rgba(26,40,66,.96) 70%);box-shadow:0 4px 24px rgba(0,0,0,.6),inset 0 1px 0 rgba(255,255,255,.18),0 0 18px rgba(100,160,255,.5);transition:transform .15s ease}" + SIZE.replace(";", ";"),
686
+ ".tfb-orb-band{display:none}",
687
+ ".tfb-orb-rim{display:none}",
688
+ ".tfb-ball .tfb-ring{position:absolute;inset:-1px;border-radius:50%;pointer-events:none;background:conic-gradient(var(--rc,#6aa8ff) calc(var(--pct,0)*1%),rgba(255,255,255,.08) 0);-webkit-mask:radial-gradient(farthest-side,transparent calc(100% - 5px),#000 calc(100% - 4px));mask:radial-gradient(farthest-side,transparent calc(100% - 5px),#000 calc(100% - 4px));transition:background .4s ease;filter:drop-shadow(0 0 6px rgba(100,160,255,.5))}",
689
+ ".tfb-ball .tfb-label{text-shadow:0 0 10px currentColor,0 0 3px currentColor}",
690
+ ".tfb-ball.tfb-active{color:#ffcf8a;box-shadow:0 4px 24px rgba(0,0,0,.6),inset 0 1px 0 rgba(255,255,255,.18),0 0 16px rgba(255,170,51,.5);animation:tfb-pulse 1.6s ease-in-out infinite}",
691
+ ".tfb-ball.tfb-active .tfb-ring{--rc:#ffaa33;filter:drop-shadow(0 0 8px rgba(255,170,51,.6))}",
692
+ ".tfb-ball.tfb-done{color:#a5ffd4;box-shadow:0 4px 24px rgba(0,0,0,.6),inset 0 1px 0 rgba(255,255,255,.18),0 0 18px rgba(93,255,168,.5)}",
693
+ ".tfb-ball.tfb-done .tfb-ring{--rc:#5dffa8;filter:drop-shadow(0 0 10px rgba(93,255,168,.7))}",
694
+ ".tfb-ball.tfb-pending{color:#bcd9ff;box-shadow:0 4px 24px rgba(0,0,0,.6),inset 0 1px 0 rgba(255,255,255,.18),0 0 14px rgba(127,196,255,.5)}",
695
+ ".tfb-ball.tfb-pending .tfb-ring{--rc:#7fc4ff;filter:drop-shadow(0 0 8px rgba(127,196,255,.6))}"
696
+ ];
697
+ } else if (th === "nebB") {
698
+ ball = [
699
+ ".tfb-ball{position:fixed;right:18px;bottom:18px;z-index:2147483600;border-radius:50%;border:1px solid rgba(255,255,255,.28);cursor:grab;user-select:none;touch-action:none;pointer-events:auto;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:1px;color:#d9fff0;font-size:13px;font-weight:800;line-height:1.1;background:radial-gradient(circle at 50% 62%, rgba(210,255,244,.5) 0%, rgba(45,212,168,.75) 14%, rgba(18,160,130,.85) 30%, rgba(12,110,92,.95) 50%, rgba(6,40,34,1) 72%, rgba(2,16,14,1) 100%);box-shadow:0 0 20px rgba(45,212,168,.45),inset 0 2px 5px rgba(255,255,255,.45),inset 0 -10px 18px rgba(45,212,168,.25),inset 0 0 18px rgba(10,60,50,.5);text-shadow:0 0 6px rgba(120,255,214,.75),0 2px 4px rgba(0,40,30,.8);animation:tfbBreathe 3.2s ease-in-out infinite;transition:transform .15s ease}" + SIZE,
700
+ ".tfb-orb-band{display:none}",
701
+ ".tfb-orb-rim{position:absolute;inset:-1px;border-radius:50%;z-index:1;pointer-events:none;background:conic-gradient(from 200deg, rgba(255,255,255,.45), rgba(120,240,205,.3), rgba(10,200,170,.35), rgba(255,255,255,.12), rgba(45,212,168,.35), rgba(255,255,255,.45));-webkit-mask:radial-gradient(circle, transparent 63%, #000 66%, #000 72%, transparent 76%);mask:radial-gradient(circle, transparent 63%, #000 66%, #000 72%, transparent 76%);animation:tfbRimSpin 7s linear infinite;filter:blur(.5px)}",
702
+ ".tfb-ball .tfb-ring{display:none}",
703
+ ".tfb-ball .tfb-label{animation:tfbGlow 2.4s ease-in-out infinite}",
704
+ ".tfb-ball.tfb-active{color:#ffd9a8;background:radial-gradient(circle at 50% 62%, rgba(255,240,210,.55) 0%, rgba(255,180,70,.8) 14%, rgba(220,130,25,.9) 30%, rgba(150,85,15,.95) 50%, rgba(60,32,6,1) 72%, rgba(24,12,2,1) 100%);box-shadow:0 0 20px rgba(255,170,51,.5),inset 0 2px 5px rgba(255,255,255,.5),inset 0 -10px 18px rgba(255,170,51,.28),inset 0 0 18px rgba(90,50,10,.5)}",
705
+ ".tfb-ball.tfb-active .tfb-orb-rim{background:conic-gradient(from 200deg, rgba(255,255,255,.5), rgba(255,200,110,.35), rgba(255,150,30,.4), rgba(255,255,255,.12), rgba(255,190,80,.35), rgba(255,255,255,.5));animation-duration:2.6s}",
706
+ ".tfb-ball.tfb-done{color:#d9fff0;background:radial-gradient(circle at 50% 62%, rgba(220,255,236,.5) 0%, rgba(93,255,168,.75) 14%, rgba(30,190,105,.85) 30%, rgba(15,130,75,.95) 50%, rgba(5,45,28,1) 72%, rgba(2,16,10,1) 100%);box-shadow:0 0 20px rgba(93,255,168,.5),inset 0 2px 5px rgba(255,255,255,.5),inset 0 -10px 18px rgba(93,255,168,.25),inset 0 0 18px rgba(8,60,38,.5)}",
707
+ ".tfb-ball.tfb-pending{color:#dbeafe;background:radial-gradient(circle at 50% 62%, rgba(220,240,255,.5) 0%, rgba(127,196,255,.7) 14%, rgba(59,130,196,.85) 30%, rgba(35,90,150,.95) 50%, rgba(10,35,65,1) 72%, rgba(3,12,24,1) 100%);box-shadow:0 0 20px rgba(127,196,255,.45),inset 0 2px 5px rgba(255,255,255,.45),inset 0 -10px 18px rgba(127,196,255,.22),inset 0 0 18px rgba(15,45,85,.5)}"
708
+ ];
709
+ } else if (th === "nebC") {
710
+ ball = [
711
+ ".tfb-ball{position:fixed;right:18px;bottom:18px;z-index:2147483600;border-radius:50%;border:1px solid rgba(255,255,255,.28);cursor:grab;user-select:none;touch-action:none;pointer-events:auto;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:1px;color:#d9fff0;font-size:13px;font-weight:800;line-height:1.1;background:radial-gradient(circle at 50% 55%, #1a8a70 0%, #0f6b58 30%, #083f35 60%, #031511 100%);box-shadow:0 0 18px rgba(45,212,168,.35),inset 0 2px 6px rgba(255,255,255,.28),inset 0 -8px 14px rgba(0,0,0,.5);text-shadow:0 0 6px rgba(120,255,214,.75),0 2px 4px rgba(0,40,30,.8);animation:tfbBreathe 3.2s ease-in-out infinite;transition:transform .15s ease}" + SIZE,
712
+ ".tfb-ball::before{content:\"\";position:absolute;inset:4px 6px 58% 6px;border-radius:50%;background:radial-gradient(ellipse at 50% 30%, rgba(140,255,225,.55) 0%, rgba(140,255,225,.12) 60%, transparent 80%);filter:blur(1px);z-index:1;pointer-events:none}",
713
+ ".tfb-orb-band{display:none}",
714
+ ".tfb-orb-rim{position:absolute;inset:-1px;border-radius:50%;z-index:1;pointer-events:none;background:conic-gradient(from 200deg, rgba(255,255,255,.45), rgba(120,240,205,.3), rgba(10,200,170,.35), rgba(255,255,255,.12), rgba(45,212,168,.35), rgba(255,255,255,.45));-webkit-mask:radial-gradient(circle, transparent 63%, #000 66%, #000 72%, transparent 76%);mask:radial-gradient(circle, transparent 63%, #000 66%, #000 72%, transparent 76%);animation:tfbRimSpin 7s linear infinite;filter:blur(.5px)}",
715
+ ".tfb-ball .tfb-ring{display:none}",
716
+ ".tfb-ball .tfb-label{animation:tfbGlow 2.4s ease-in-out infinite}",
717
+ ".tfb-ball.tfb-active{color:#ffd9a8;background:radial-gradient(circle at 50% 55%, #d98a1a 0%, #a86410 30%, #5c3608 60%, #201003 100%);box-shadow:0 0 18px rgba(255,170,51,.4),inset 0 2px 6px rgba(255,255,255,.3),inset 0 -8px 14px rgba(0,0,0,.5)}",
718
+ ".tfb-ball.tfb-active::before{background:radial-gradient(ellipse at 50% 30%, rgba(255,220,160,.55) 0%, rgba(255,220,160,.12) 60%, transparent 80%)}",
719
+ ".tfb-ball.tfb-active .tfb-orb-rim{background:conic-gradient(from 200deg, rgba(255,255,255,.5), rgba(255,200,110,.35), rgba(255,150,30,.4), rgba(255,255,255,.12), rgba(255,190,80,.35), rgba(255,255,255,.5));animation-duration:2.6s}",
720
+ ".tfb-ball.tfb-done{color:#d9fff0;background:radial-gradient(circle at 50% 55%, #17a06a 0%, #0f7a4e 30%, #084a30 60%, #03150c 100%);box-shadow:0 0 18px rgba(93,255,168,.4),inset 0 2px 6px rgba(255,255,255,.28),inset 0 -8px 14px rgba(0,0,0,.5)}",
721
+ ".tfb-ball.tfb-done::before{background:radial-gradient(ellipse at 50% 30%, rgba(180,255,220,.55) 0%, rgba(180,255,220,.12) 60%, transparent 80%)}",
722
+ ".tfb-ball.tfb-pending{color:#dbeafe;background:radial-gradient(circle at 50% 55%, #2a6cb0 0%, #1c5288 30%, #10315c 60%, #04101e 100%);box-shadow:0 0 18px rgba(127,196,255,.35),inset 0 2px 6px rgba(255,255,255,.28),inset 0 -8px 14px rgba(0,0,0,.5)}",
723
+ ".tfb-ball.tfb-pending::before{background:radial-gradient(ellipse at 50% 30%, rgba(180,215,255,.55) 0%, rgba(180,215,255,.12) 60%, transparent 80%)}"
724
+ ];
725
+ } else if (th === "glass") {
726
+ ball = [
727
+ ".tfb-ball{position:fixed;right:18px;bottom:18px;z-index:2147483600;border-radius:50%;border:1px solid rgba(255,255,255,.4);cursor:grab;user-select:none;touch-action:none;pointer-events:auto;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:1px;color:#16324a;font-size:13px;font-weight:800;line-height:1.1;background:linear-gradient(145deg,rgba(190,225,245,.4) 0%,rgba(130,170,205,.28) 50%,rgba(85,115,150,.42) 100%);backdrop-filter:blur(4px);box-shadow:inset 0 1px 5px rgba(255,255,255,.55),inset 0 -8px 14px rgba(255,255,255,.1),0 4px 16px rgba(0,0,0,.35);transition:transform .15s ease}" + SIZE,
728
+ ".tfb-orb-band{display:none}",
729
+ ".tfb-orb-rim{display:none}",
730
+ ".tfb-ball::before{content:\"\";position:absolute;inset:3px 3px 55% 3px;border-radius:50% 50% 40% 40%;background:linear-gradient(rgba(255,255,255,.55),rgba(255,255,255,.06));filter:blur(.5px);pointer-events:none}",
731
+ ".tfb-ball .tfb-ring{position:absolute;inset:-1px;border-radius:50%;pointer-events:none;background:conic-gradient(var(--rc,#3b82c4) calc(var(--pct,0)*1%),rgba(255,255,255,.25) 0);-webkit-mask:radial-gradient(farthest-side,transparent calc(100% - 4px),#000 calc(100% - 3px));mask:radial-gradient(farthest-side,transparent calc(100% - 4px),#000 calc(100% - 3px));transition:background .4s ease;filter:drop-shadow(0 0 5px rgba(80,140,200,.5))}",
732
+ ".tfb-ball .tfb-label,.tfb-ball .tfb-sub{text-shadow:0 1px 2px rgba(255,255,255,.6)}",
733
+ ".tfb-ball.tfb-active{color:#7a4a08;box-shadow:inset 0 1px 5px rgba(255,255,255,.55),inset 0 -8px 14px rgba(255,190,120,.15),0 4px 16px rgba(0,0,0,.35),0 0 14px rgba(255,170,51,.35)}",
734
+ ".tfb-ball.tfb-active .tfb-ring{--rc:#ffaa33;filter:drop-shadow(0 0 7px rgba(255,170,51,.6))}",
735
+ ".tfb-ball.tfb-done{color:#14532d;box-shadow:inset 0 1px 5px rgba(255,255,255,.55),inset 0 -8px 14px rgba(160,255,200,.15),0 4px 16px rgba(0,0,0,.35),0 0 14px rgba(93,255,168,.35)}",
736
+ ".tfb-ball.tfb-done .tfb-ring{--rc:#16a34a;filter:drop-shadow(0 0 7px rgba(22,163,74,.6))}",
737
+ ".tfb-ball.tfb-pending{color:#1e3a5f;box-shadow:inset 0 1px 5px rgba(255,255,255,.55),inset 0 -8px 14px rgba(170,205,255,.15),0 4px 16px rgba(0,0,0,.35),0 0 12px rgba(100,160,255,.3)}",
738
+ ".tfb-ball.tfb-pending .tfb-ring{--rc:#3b82c4;filter:drop-shadow(0 0 6px rgba(59,130,196,.55))}"
739
+ ];
740
+ } else { // graphite
741
+ ball = [
742
+ ".tfb-ball{position:fixed;right:18px;bottom:18px;z-index:2147483600;border-radius:50%;border:1px solid rgba(255,255,255,.28);cursor:grab;user-select:none;touch-action:none;pointer-events:auto;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:1px;color:#7defc4;font-size:13px;font-weight:800;line-height:1.1;background:radial-gradient(circle at 30% 25%,rgba(255,255,255,.15),rgba(40,44,54,.95) 70%);box-shadow:0 4px 24px rgba(0,0,0,.6),inset 0 1px 0 rgba(255,255,255,.15),0 0 14px rgba(45,212,168,.28);transition:transform .15s ease}" + SIZE.replace(";", ";"),
743
+ ".tfb-orb-band{display:none}",
744
+ ".tfb-orb-rim{display:none}",
745
+ ".tfb-ball .tfb-ring{position:absolute;inset:-1px;border-radius:50%;pointer-events:none;background:conic-gradient(var(--rc,#2dd4a8) calc(var(--pct,0)*1%),rgba(255,255,255,.07) 0);-webkit-mask:radial-gradient(farthest-side,transparent calc(100% - 5px),#000 calc(100% - 4px));mask:radial-gradient(farthest-side,transparent calc(100% - 5px),#000 calc(100% - 4px));transition:background .4s ease}",
746
+ ".tfb-ball .tfb-label{text-shadow:0 0 8px currentColor,0 0 2px currentColor}",
747
+ ".tfb-ball.tfb-active{color:#ffcf8a;box-shadow:0 4px 24px rgba(0,0,0,.6),inset 0 1px 0 rgba(255,255,255,.15),0 0 16px rgba(255,170,51,.45);animation:tfb-pulse 1.6s ease-in-out infinite}",
748
+ ".tfb-ball.tfb-active .tfb-ring{--rc:#ffaa33}",
749
+ ".tfb-ball.tfb-done{color:#8dffc8;box-shadow:0 4px 24px rgba(0,0,0,.6),inset 0 1px 0 rgba(255,255,255,.15),0 0 16px rgba(93,255,168,.4)}",
750
+ ".tfb-ball.tfb-done .tfb-ring{--rc:#5dffa8}",
751
+ ".tfb-ball.tfb-pending{color:#a8c8ec;box-shadow:0 4px 24px rgba(0,0,0,.6),inset 0 1px 0 rgba(255,255,255,.15),0 0 12px rgba(127,196,255,.3)}",
752
+ ".tfb-ball.tfb-pending .tfb-ring{--rc:#7fc4ff}"
753
+ ];
754
+ }
755
+ return [
756
+ ":host{all:initial}",
757
+ ".tfb-root{position:static;pointer-events:none;font-family:'Segoe UI','Microsoft YaHei',system-ui,sans-serif}",
758
+ ".tfb-ball:hover{transform:scale(1.08)}",
759
+ ".tfb-ball:active{cursor:grabbing;transform:scale(.95)}"
760
+ ].concat(ball, [
761
+ "@keyframes tfbBandFlow{0%,100%{transform:translateY(-3px) scaleY(.94);opacity:.8}50%{transform:translateY(3px) scaleY(1.12);opacity:1}}",
762
+ "@keyframes tfbRimSpin{0%{transform:rotate(0deg)}100%{transform:rotate(360deg)}}",
763
+ "@keyframes tfbBreathe{0%,100%{transform:scale(.96);filter:brightness(.92)}50%{transform:scale(1.05);filter:brightness(1.12)}}",
764
+ "@keyframes tfbGlow{0%,100%{text-shadow:0 0 4px rgba(255,255,255,.95),0 0 10px rgba(150,255,220,.9),0 0 20px rgba(30,220,180,.75)}50%{text-shadow:0 0 6px rgba(255,255,255,1),0 0 16px rgba(200,255,235,1),0 0 32px rgba(60,240,195,.95)}}",
765
+ "@keyframes tfb-pulse{0%,100%{box-shadow:0 4px 24px rgba(0,0,0,.6),inset 0 1px 0 rgba(255,255,255,.15),0 0 16px rgba(255,170,51,.45),0 0 0 0 rgba(255,170,51,.5)}50%{box-shadow:0 4px 24px rgba(0,0,0,.6),inset 0 1px 0 rgba(255,255,255,.15),0 0 16px rgba(255,170,51,.55),0 0 0 10px rgba(255,170,51,0)}}",
766
+ ".tfb-ball.tfb-active .tfb-label{animation:none;text-shadow:0 0 4px rgba(255,255,255,.95),0 0 10px rgba(255,215,140,.95),0 0 20px rgba(255,160,40,.8)}",
767
+ ".tfb-ball.tfb-done .tfb-label{animation:none;text-shadow:0 0 6px rgba(255,255,255,1),0 0 14px rgba(190,255,220,1),0 0 28px rgba(60,255,150,.9)}",
768
+ // capsule mode (right-click toggle): long pill, wider, text-first
769
+ ".tfb-ball.tfb-capsule{width:auto;min-width:220px;max-width:min(520px,60vw);height:44px;border-radius:22px;flex-direction:row;gap:8px;padding:0 16px;font-size:12px;justify-content:flex-start}",
770
+ ".tfb-ball.tfb-capsule .tfb-orb-band{inset:1px}",
771
+ ".tfb-ball.tfb-capsule .tfb-orb-rim{display:none}",
772
+ ".tfb-ball.tfb-capsule .tfb-ring{display:none}",
773
+ ".tfb-ball.tfb-capsule .tfb-label{flex-shrink:0}",
774
+ ".tfb-ball.tfb-capsule .tfb-sub{flex:1;min-width:0;max-width:none;font-size:12px;text-align:left;overflow:hidden;white-space:nowrap}",
775
+ ".tfb-ball.tfb-capsule .tfb-capsule-text{display:inline-block;white-space:nowrap}",
776
+ ".tfb-ball.tfb-capsule .tfb-capsule-text.tfb-marquee{animation:tfbMarquee 9s ease-in-out infinite alternate}",
777
+ "@keyframes tfbMarquee{from{transform:translateX(0)}to{transform:translateX(var(--shift,-40px))}}",
778
+ ".tfb-panel{position:fixed;z-index:2147483600;width:300px;max-width:calc(100vw - 24px);max-height:74vh;overflow-y:auto;overflow-x:hidden;pointer-events:auto;display:none;color:#e6e6e6;font-size:13px;line-height:1.5;border-radius:14px;padding:12px 14px 10px;background:rgba(16,18,22,.92);border:1px solid rgba(255,255,255,.08);box-shadow:0 20px 60px rgba(0,0,0,.7),inset 0 1px 0 rgba(255,255,255,.06);backdrop-filter:blur(24px)}",
779
+ ".tfb-panel.tfb-open{display:block}",
780
+ ".tfb-panel.tfb-open.tfb-hz{display:flex;flex-wrap:wrap;align-items:flex-start;width:auto;min-width:540px;max-width:min(92vw,800px)}",
781
+ ".tfb-panel.tfb-hz .tfb-head{flex:0 0 100%;width:100%}",
782
+ ".tfb-colcap{display:none;font-size:11px;font-weight:600;color:#8fd3c0;padding:2px 0 6px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}",
783
+ ".tfb-panel.tfb-hz .tfb-colcap{display:block}",
784
+ ".tfb-panel.tfb-hz .tfb-col-cur{flex:1 1 45%;min-width:250px;max-width:none;box-sizing:border-box;padding-right:10px;border-right:1px solid rgba(255,255,255,.10)}",
785
+ ".tfb-panel.tfb-hz .tfb-col-pin{flex:1 1 50%;min-width:260px;box-sizing:border-box;padding-left:10px}",
786
+ "",
787
+ ".tfb-head{display:flex;align-items:center;gap:6px;margin-bottom:6px;padding-bottom:6px;border-bottom:1px solid rgba(45,212,168,.25)}",
788
+ ".tfb-title{font-weight:700;font-size:13px;white-space:nowrap}",
789
+ ".tfb-ctitle{flex:1;min-width:0;font-size:11px;color:#9aa3b2;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;cursor:text}",
790
+ ".tfb-summary{font-size:11px;color:#9aa3b2;white-space:nowrap}",
791
+ ".tfb-btn{border:0;background:transparent;color:#9aa3b2;font-size:13px;cursor:pointer;padding:2px 5px;border-radius:6px;flex-shrink:0}",
792
+ ".tfb-btn:hover{color:#e6e6e6;background:rgba(255,255,255,.06)}",
793
+ ".tfb-btn.tfb-on{color:#ffd27a}",
794
+ ".tfb-list{list-style:none;margin:0;padding:0}",
795
+ ".tfb-item{display:flex;align-items:flex-start;gap:8px;padding:5px 4px;border-radius:8px;word-break:break-word}",
796
+ ".tfb-item:nth-child(odd){background:rgba(255,255,255,.03)}",
797
+ ".tfb-ico{flex-shrink:0;width:16px;height:16px;border-radius:50%;display:inline-flex;align-items:center;justify-content:center;font-size:10px;margin-top:1px}",
798
+ ".tfb-item[data-status='completed'] .tfb-ico{background:rgba(74,222,128,.18);color:#5dffa8;border:1px solid rgba(93,255,168,.4)}",
799
+ ".tfb-item[data-status='in_progress'] .tfb-ico{background:rgba(255,170,51,.2);color:#ffaa33;border:1px solid rgba(255,170,51,.45)}",
800
+ ".tfb-item[data-status='pending'] .tfb-ico{background:rgba(127,196,255,.14);color:#7fc4ff;border:1px dashed rgba(127,196,255,.5)}",
801
+ ".tfb-item[data-status='in_progress']{background:rgba(255,170,51,.06)}",
802
+ ".tfb-item[data-status='in_progress'] .tfb-txt{color:#ffcf8a;font-weight:600}",
803
+ ".tfb-item[data-status='completed'] .tfb-txt{color:#7fae94;text-decoration:line-through}",
804
+ ".tfb-item[data-status='pending'] .tfb-txt{color:#aebfd4}",
805
+ ".tfb-txt{flex:1}",
806
+ // Plan-A2: per-row hide button — invisible until hover/focus, never
807
+ // printed, keeps the row layout unchanged
808
+ ".tfb-x{flex-shrink:0;border:0;background:transparent;color:#6b7280;font-size:11px;line-height:1;cursor:pointer;padding:2px 4px;border-radius:5px;opacity:0;transition:opacity .12s ease}",
809
+ ".tfb-item:hover .tfb-x,.tfb-x:focus{opacity:1}",
810
+ ".tfb-x:hover{color:#ff8a8a;background:rgba(255,120,120,.12)}",
811
+ ".tfb-empty{color:#8b93a1;font-size:12px;text-align:center;padding:12px 0}",
812
+ // Plan-A3: history fold toggle row
813
+ ".tfb-histoggle{list-style:none;display:flex;align-items:center;justify-content:center;gap:4px;margin:6px 0 2px;padding:5px 4px;border-radius:8px;color:#9aa3b2;font-size:11px;cursor:pointer;background:rgba(255,255,255,.03)}",
814
+ ".tfb-histoggle:hover{color:#e6e6e6;background:rgba(255,255,255,.06)}",
815
+ ".tfb-sep{margin:10px 0 6px;padding-top:8px;border-top:1px solid rgba(255,255,255,.07);display:flex;align-items:center;justify-content:space-between}",
816
+ ".tfb-sep-label{font-size:11px;color:#9aa3b2;font-weight:600}",
817
+ ".tfb-pinrow{display:flex;align-items:center;gap:6px;padding:6px 4px;border-radius:8px;cursor:pointer}",
818
+ ".tfb-pinrow:hover{background:rgba(255,255,255,.05)}",
819
+ ".tfb-pinname{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:12px}",
820
+ ".tfb-pincount{font-size:11px;color:#9aa3b2;white-space:nowrap}",
821
+ ".tfb-dot{width:8px;height:8px;border-radius:50%;flex-shrink:0}",
822
+ ".tfb-dot-active{background:#fbbf24;box-shadow:0 0 6px rgba(251,191,36,.8);animation:tfb-dotpulse 1.4s ease-in-out infinite}",
823
+ ".tfb-dot-done{background:#4ade80}",
824
+ ".tfb-dot-none{background:#6b7280}",
825
+ "@keyframes tfb-dotpulse{0%,100%{opacity:1}50%{opacity:.4}}",
826
+ ".tfb-pinlist{list-style:none;margin:2px 0 4px;padding:0 0 0 10px;border-left:2px solid rgba(255,255,255,.08)}",
827
+ ".tfb-hint{font-size:10px;color:#6b7280;padding:6px 0 0;display:flex;align-items:center;justify-content:center;gap:4px;flex-wrap:wrap}",
828
+ ".tfb-theme-menu{display:none;margin:-2px 0 8px;padding:6px;border:1px solid rgba(45,212,168,.25);border-radius:10px;background:rgba(12,16,20,.96)}",
829
+ ".tfb-theme-menu.tfb-open{display:block}",
830
+ ".tfb-theme-row{display:flex;align-items:center;gap:8px;padding:6px 8px;border-radius:8px;cursor:pointer;font-size:12px;color:#cdd6e2}",
831
+ ".tfb-theme-row:hover{background:rgba(255,255,255,.06)}",
832
+ ".tfb-theme-row.tfb-cur{color:#ffd27a;font-weight:600}",
833
+ ".tfb-theme-row .tfb-theme-check{flex-shrink:0;width:14px;text-align:center}",
834
+ ".tfb-theme-row .tfb-theme-label{flex:1;min-width:0}",
835
+ ".tfb-rename{flex:1;min-width:0;padding:3px 8px;border-radius:6px;border:1px solid rgba(255,210,122,.5);background:rgba(0,0,0,.4);color:#ffd27a;font:inherit;font-size:12px;outline:none}",
836
+ ".tfb-rename:focus{border-color:#ffd27a}",
837
+ ".tfb-ctitle[contenteditable='true']{outline:none;border-bottom:1px dashed #ffd27a;color:#ffd27a;cursor:text}"
838
+ ]).join("\n");
839
+ }
840
+
841
+ function listHtml(list) {
842
+ var html = "";
843
+ for (var i = 0; i < list.length; i++) {
844
+ var t = list[i];
845
+ var ico = t.status === "completed" ? "✓" : t.status === "in_progress" ? "▶" : "○";
846
+ var txt = t.content.length > MAX_CONTENT ? t.content.slice(0, MAX_CONTENT) + "…" : t.content;
847
+ // Plan-A2: every row carries a small ✕ so the user can hide history
848
+ // rows they no longer want to see (only deletes from the DISPLAY —
849
+ // the underlying session log is never touched; a new snapshot that
850
+ // re-lists the item will show it again).
851
+ // Plan-A6: a 📋 copy button next to it — copies the FULL task text
852
+ // to the clipboard (handy for quoting a broken/odd task back).
853
+ html += '<li class="tfb-item" data-status="' + t.status + '">' +
854
+ '<span class="tfb-ico">' + ico + '</span>' +
855
+ '<span class="tfb-txt">' + esc(txt) + '</span>' +
856
+ '<button class="tfb-x" type="button" data-act="copyItem" data-copy="' + esc(t.content) + '" title="复制此条完整内容">📋</button>' +
857
+ '<button class="tfb-x" type="button" data-act="hideItem" data-idx="' + i + '" title="从悬浮球隐藏此条(不动数据源)">✕</button>' +
858
+ "</li>";
859
+ }
860
+ return html;
861
+ }
862
+
863
+ // Plan-A9: ONE body renderer shared by the current-session list and
864
+ // every pinned-session list — snapshot rows, the two history folds
865
+ // (per-sid open state), per-fold 🧹, the batch clear-all row and the
866
+ // ♻️ restore-all row. `sid` is the list's OWN session: fold state,
867
+ // hide scoping and every data-ownsid target key off it, so a pinned
868
+ // session's controls can never act on the current session (or vice
869
+ // versa). `list` is that session's RAW (unfiltered) merged list — the
870
+ // hidden filter is applied per part, after the snapshot/history split.
871
+ function historySectionHtml(sid, list) {
872
+ var osid = normSid(sid);
873
+ var raw = Array.isArray(list) ? list : [];
874
+ var b = bySession[osid];
875
+ var snapLen = (b && typeof b.snapLen === "number") ? Math.min(b.snapLen, raw.length) : raw.length;
876
+ // Plan-A9: split the RAW list FIRST, then drop hidden rows from each
877
+ // part — hiding a snapshot row must not drag a history row into the
878
+ // snapshot area (nor shrink the folds).
879
+ var snapRows = visibleList(osid, raw.slice(0, snapLen));
880
+ var histRows = visibleList(osid, raw.slice(snapLen));
881
+ var histDone = [];
882
+ var histOpen_ = []; // Plan-A3.1: non-completed history gets its own fold
883
+ for (var hi = 0; hi < histRows.length; hi++) {
884
+ if (histRows[hi].status === "completed") histDone.push(histRows[hi]);
885
+ else histOpen_.push(histRows[hi]);
886
+ }
887
+ // every action row carries data-ownsid so the dispatcher can scope
888
+ // toggle/🧹/♻️ to THIS session (continuation of Plan-A2.2)
889
+ var ownAttr = ' data-ownsid="' + esc(sid) + '"';
890
+ var html = listHtml(snapRows);
891
+ // Plan-A5: batch-clear affordance — one click hides every archive row
892
+ // (both folds), same ✕ semantics as single-row hides, snapshot rows
893
+ // and data layer untouched.
894
+ var anyHist = histDone.length + histOpen_.length;
895
+ if (histDone.length) {
896
+ html += '<li class="tfb-histoggle" data-act="toggleHistory"' + ownAttr + ' title="展开/收起历史任务">▾ 已完成历史 ' + histDone.length + ' 条(点击' + (historyOpen[osid] ? "收起" : "展开") + ')' +
897
+ '<button class="tfb-btn" data-act="clearHistory"' + ownAttr + ' type="button" title="一键隐藏本区全部条目(✕ 同款,仅显示层)">🧹</button></li>';
898
+ if (historyOpen[osid]) html += listHtml(histDone);
899
+ }
900
+ // Plan-A3.1: non-completed history in a SECOND fold (default closed)
901
+ if (histOpen_.length) {
902
+ html += '<li class="tfb-histoggle" data-act="toggleHistoryOpen"' + ownAttr + ' title="展开/收起被抛弃的历史任务">▸ 被抛弃的历史任务 ' + histOpen_.length + ' 条(点击' + (historyOpenOpen[osid] ? "收起" : "展开") + ')' +
903
+ '<button class="tfb-btn" data-act="clearHistoryOpen"' + ownAttr + ' type="button" title="一键隐藏本区全部条目(✕ 同款,仅显示层)">🧹</button></li>';
904
+ if (historyOpenOpen[osid]) html += listHtml(histOpen_);
905
+ }
906
+ if (anyHist) {
907
+ html += '<li class="tfb-histoggle" data-act="clearAll"' + ownAttr + ' title="一键隐藏两个历史区全部条目">🧹 一键清理全部历史(' + anyHist + ' 条)</li>';
908
+ }
909
+ // Plan-A7: restore affordance — one click un-hides EVERYTHING hidden
910
+ // in this session (single ✕ hides and batch clears alike). Only
911
+ // shown when at least one row is hidden, so it never adds noise.
912
+ var hidCount = 0;
913
+ var hidMap = hiddenFor(osid);
914
+ for (var hk in hidMap) { if (hidMap[hk]) hidCount++; }
915
+ if (hidCount > 0) {
916
+ html += '<li class="tfb-histoggle" data-act="restoreAll"' + ownAttr + ' title="取消本会话全部隐藏(✕/🧹 的反向操作)">♻️ 一键恢复全部隐藏的历史(' + hidCount + ' 条)</li>';
917
+ }
918
+ return html;
919
+ }
920
+
921
+ // Plan-A9: which session does a clicked action row belong to? Rows
922
+ // rendered by historySectionHtml carry data-ownsid directly; pinned
923
+ // rows are additionally covered by their <ul data-ownsid>; everything
924
+ // else targets the current session. The guards keep stub/DOM oddities
925
+ // from throwing.
926
+ function actionSid(t) {
927
+ var own = null;
928
+ try { own = t && t.getAttribute ? t.getAttribute("data-ownsid") : null; } catch (e) { own = null; }
929
+ if (own) return own;
930
+ // back-compat: the brief Plan-A8 pinned-fold rows carried data-sid
931
+ try { own = t && t.getAttribute ? t.getAttribute("data-sid") : null; } catch (e1) { own = null; }
932
+ if (own) return own;
933
+ try {
934
+ var li = t && t.closest ? t.closest(".tfb-item") : null;
935
+ var ul = li && li.closest ? li.closest(".tfb-pinlist") : null;
936
+ var own2 = ul && ul.getAttribute ? ul.getAttribute("data-ownsid") : null;
937
+ if (own2) return own2;
938
+ } catch (e2) {}
939
+ return currentSid;
940
+ }
941
+
942
+ // Plan-A9 back-compat: the pinned-fold action names emitted by the
943
+ // short-lived Plan-A8 attempt map onto the unified fold actions — ONE
944
+ // implementation and ONE per-sid fold-state map for both list kinds.
945
+ var ACT_ALIAS = {
946
+ toggleHistPinned: "toggleHistory",
947
+ toggleHistOpenPinned: "toggleHistoryOpen",
948
+ clearHistPinned: "clearHistory",
949
+ clearHistOpenPinned: "clearHistoryOpen"
950
+ };
951
+
952
+ function pinDotClass(sid) {
953
+ var list = sessionTodos(sid);
954
+ if (!list || !list.length) return "tfb-dot-none";
955
+ var c = countsOf(list);
956
+ if (c.done === c.total) return "tfb-dot-done";
957
+ if (c.active > 0) return "tfb-dot-active";
958
+ return "tfb-dot-none";
959
+ }
960
+
961
+ function renderList() {
962
+
963
+ if (!ui.list) return;
964
+
965
+ // Plan-A4: header summary reports the CURRENT SNAPSHOT only (history
966
+
967
+ // folds are an archive and stay out of every counter).
968
+
969
+ var c = snapshotList().length ? countsOf(snapshotList()) : { done: 0, active: 0, total: 0 };
970
+
971
+ if (ui.ctitle) {
972
+
973
+ // while the rename editor is live, don't rebuild the title cell
974
+
975
+ if (editing.sid === normSid(currentSid)) { /* keep editor */ }
976
+
977
+ else {
978
+
979
+ ui.ctitle.textContent = currentSid ? sessionTitle(currentSid) : ""; if (ui.capCur) ui.capCur.textContent = "▸ " + (ui.ctitle.textContent || "当前对话");
980
+
981
+ ui.ctitle.title = currentSid ? "点击重命名此对话" : "";
982
+
983
+ }
984
+
985
+ }
986
+
987
+ if (ui.summary) {
988
+
989
+ var parts = [];
990
+
991
+ if (c.done > 0) parts.push(c.done + " 完成");
992
+
993
+ if (c.active > 0) parts.push(c.active + " 进行中");
994
+
995
+ var pend = c.total - c.done - c.active;
996
+
997
+ if (pend > 0) parts.push(pend + " 待办");
998
+
999
+ ui.summary.textContent = parts.join(" · ");
1000
+
1001
+ }
1002
+
1003
+ if (ui.pinBtn) {
1004
+
1005
+ var on = currentSid && isPinned(currentSid);
1006
+
1007
+ ui.pinBtn.classList.toggle("tfb-on", !!on);
1008
+
1009
+ ui.pinBtn.title = on ? "取消固定当前会话" : "固定当前会话(切换对话后仍监控)";
1010
+
1011
+ ui.pinBtn.textContent = on ? "📍" : "📌";
1012
+
1013
+ }
1014
+
1015
+ var list = currentList();
1016
+
1017
+ if (!list.length) {
1018
+
1019
+ ui.list.innerHTML = '<li class="tfb-empty">当前会话暂无任务清单<br><span style="font-size:10px">AI 使用 todo_write 后自动显示;📌 可固定会话</span></li>';
1020
+
1021
+ } else {
1022
+
1023
+ // Plan-A9: the whole body (snapshot rows + the two history folds +
1024
+ // batch-clear + restore) comes from the ONE shared renderer, scoped
1025
+ // to the current session; renderPinned() reuses it per pinned sid.
1026
+ var html = historySectionHtml(currentSid, sessionTodos(currentSid));
1027
+
1028
+ ui.list.innerHTML = html;
1029
+
1030
+ // Plan-A4: counts from the CURRENT SNAPSHOT only. (User request
1031
+
1032
+ // 2026-09-13: the dsh-client-auto-continue recommendation line is
1033
+
1034
+ // removed — no third-party plugin advertising in this UI.)
1035
+
1036
+ var cc = countsOf(snapshotRowsOf(currentSid));
1037
+
1038
+ if (cc.done < cc.total) {
1039
+
1040
+ var left = cc.total - cc.done;
1041
+
1042
+ ui.list.innerHTML += '<li class="tfb-empty" style="padding:6px 0 2px;font-size:10px">⚠️ 还有 ' + left + ' 项未完成</li>';
1043
+
1044
+ }
1045
+
1046
+ }
1047
+
1048
+ renderPinned();
1049
+
1050
+ }
1051
+
1052
+
1053
+
1054
+ function renderPinned() {
1055
+ if (!ui.pinSec) return;
1056
+ if (pinned.length === 0) { ui.pinSec.innerHTML = ""; return; }
1057
+ if (editing.sid) return; // a rename editor is live — don't rebuild under it
1058
+ var html = '<div class="tfb-sep"><span class="tfb-sep-label">📌 已固定 (' + pinned.length + ')</span></div>';
1059
+ for (var i = 0; i < pinned.length; i++) {
1060
+ var sid = pinned[i];
1061
+ var list = sessionTodosVisible(sid);
1062
+ // Plan-A9: the header count reports the LATEST SNAPSHOT only (same
1063
+ // A4 rule as the current list — the history folds are an archive
1064
+ // and stay out of every counter).
1065
+ var c = list ? countsOf(snapshotRowsOf(sid)) : null;
1066
+ var tname = sessionTitle(sid);
1067
+ var open = !!openPin[sid];
1068
+ html += '<div class="tfb-pinrow" data-act="togglePin" data-sid="' + esc(sid) + '">';
1069
+ html += '<span class="tfb-dot ' + pinDotClass(sid) + '"></span>';
1070
+ html += '<span class="tfb-pinname" title="' + esc(tname) + '">' + esc(tname) + "</span>";
1071
+ html += '<span class="tfb-pincount">' + (c ? c.done + "/" + c.total : "…") + "</span>";
1072
+ html += '<button class="tfb-btn" data-act="renamePin" data-sid="' + esc(sid) + '" title="重命名">✏️</button>';
1073
+ html += '<button class="tfb-btn" data-act="unpin" data-sid="' + esc(sid) + '" title="取消固定">✖</button>';
1074
+ html += "</div>";
1075
+ if (open) {
1076
+ if (list && list.length) {
1077
+ // Plan-A9: pinned sessions render through the SAME shared body
1078
+ // renderer as the current list — snapshot/history split, the two
1079
+ // folds (open state kept per sid), per-fold 🧹, batch clear-all
1080
+ // and ♻️ restore-all, every action scoped to THIS sid.
1081
+ html += '<ul class="tfb-pinlist" data-ownsid="' + esc(sid) + '">' + historySectionHtml(sid, sessionTodos(sid)) + "</ul>";
1082
+ } else {
1083
+ html += '<ul class="tfb-pinlist"><li class="tfb-empty" style="padding:6px 0">暂无数据(该会话产生 todo_write 后自动出现)</li></ul>';
1084
+ }
1085
+ }
1086
+ }
1087
+ ui.pinSec.innerHTML = html;
1088
+ }
1089
+
1090
+ var THEME_NAMES = { nebula: "🌌 星云·流光", nebB: "🌟 星云·宝石", nebC: "🌙 星云·顶弧", graphite: "💎 石墨版", blue: "🔵 蓝宝石版", glass: "🧊 玻璃版" };
1091
+
1092
+ function renderThemeMenu() {
1093
+ if (!ui.themeMenu) return;
1094
+ var html = "";
1095
+ var order = ["nebula", "nebB", "nebC", "graphite", "blue", "glass"];
1096
+ for (var i = 0; i < order.length; i++) {
1097
+ var th = order[i];
1098
+ var cur = th === currentTheme;
1099
+ html += '<div class="tfb-theme-row' + (cur ? " tfb-cur" : "") + '" data-act="setTheme" data-sid="' + th + '">' +
1100
+ '<span class="tfb-theme-check">' + (cur ? "✓" : " ") + "</span>" +
1101
+ '<span class="tfb-theme-label">' + (THEME_NAMES[th] || th) + "</span>" +
1102
+ "</div>";
1103
+ }
1104
+ ui.themeMenu.innerHTML = html;
1105
+ }
1106
+
1107
+ function renderBall() {
1108
+ if (!ui.ball) return;
1109
+ var st = ballState();
1110
+ ui.ball.className = "tfb-ball " + st.cls + (capsule ? " tfb-capsule" : "");
1111
+ var labelEl = ui.ball.querySelector(".tfb-label");
1112
+ if (labelEl) labelEl.textContent = st.label;
1113
+ // progress ring: --pct = done/total*100 (0 when no list; 100 when all
1114
+ // done). The conic-gradient ring visualizes completion at a glance.
1115
+ // Plan-A4: ring/capsule numbers report the CURRENT SNAPSHOT only.
1116
+ var pct = 0;
1117
+ var list = snapshotList();
1118
+ if (list.length) {
1119
+ var c0 = countsOf(list);
1120
+ pct = c0.total > 0 ? Math.round(c0.done / c0.total * 100) : 0;
1121
+ }
1122
+ try { ui.ball.style.setProperty("--pct", String(pct)); } catch (e) {}
1123
+ var sub = "";
1124
+ if (capsule) {
1125
+ // capsule mode: show the running task (or overall status) in full;
1126
+ // overflowing text scrolls back and forth (marquee)
1127
+ if (list.length) {
1128
+ var c1 = countsOf(list);
1129
+ if (c1.done === c1.total) sub = "✓ 全部完成 " + c1.done + "/" + c1.total;
1130
+ else {
1131
+ var running = "";
1132
+ for (var r = 0; r < list.length; r++) {
1133
+ if (list[r].status === "in_progress") { running = list[r].content; break; }
1134
+ }
1135
+ sub = running
1136
+ ? "▶ " + running
1137
+ : "待办 " + c1.done + "/" + c1.total;
1138
+ }
1139
+ } else if (pinned.length) {
1140
+ for (var i = 0; i < pinned.length; i++) {
1141
+ var pl = sessionTodos(pinned[i]);
1142
+ if (pl && countsOf(pl).active > 0) { sub = "📌 " + (sessionTitle(pinned[i]) || "固定会话") + " 进行中"; break; }
1143
+ }
1144
+ if (!sub) sub = "📋 暂无进行中任务";
1145
+ } else {
1146
+ sub = "📋 暂无任务";
1147
+ }
1148
+ }
1149
+ // ROUND-BALL MODE: show ONLY the progress (user requirement) — no
1150
+ // task content on the ball face, since it never fits. The label is
1151
+ // done/total (or ✓); the sub line stays empty.
1152
+ var subEl = ui.ball.querySelector(".tfb-sub");
1153
+ if (subEl) {
1154
+ if (capsule) {
1155
+ subEl.innerHTML = '<span class="tfb-capsule-text">' + esc(sub) + "</span>";
1156
+ var textEl = subEl.querySelector(".tfb-capsule-text");
1157
+ if (textEl) {
1158
+ // measure AFTER layout: if the text overflows the pill, set the
1159
+ // scroll distance so the marquee ping-pongs exactly the overflow
1160
+ requestAnimationFrame(function () {
1161
+ try {
1162
+ var over = textEl.scrollWidth - subEl.clientWidth;
1163
+ if (over > 8) {
1164
+ textEl.style.setProperty("--shift", "-" + (over + 6) + "px");
1165
+ textEl.classList.add("tfb-marquee");
1166
+ } else {
1167
+ textEl.classList.remove("tfb-marquee");
1168
+ }
1169
+ } catch (e2) {}
1170
+ });
1171
+ }
1172
+ } else {
1173
+ subEl.textContent = "";
1174
+ }
1175
+ }
1176
+ ui.ball.title = capsule
1177
+ ? "胶囊模式(右键切回圆球;左键仍可展开面板)"
1178
+ : (list.length
1179
+ ? "Todo 悬浮球 — 当前最新任务 " + summarize(list).head + "(" + pct + "% 完成;历史折叠不计数;左键展开/折叠 · 右键胶囊 · 可拖动)"
1180
+ : "Todo 悬浮球 — 当前会话暂无任务(左键展开 · 右键胶囊 · 可拖动)");
1181
+ }
1182
+
1183
+ var layoutHz = false;
1184
+ try { layoutHz = localStorage.getItem("dsh-todo-float-ball-layout") === "1"; } catch (e) {}
1185
+
1186
+ function render() {
1187
+ renderBall();
1188
+ renderList();
1189
+ if (expanded && ui.panel) positionPanel();
1190
+ }
1191
+
1192
+ function positionPanel() {
1193
+ if (!ui.panel || !ui.ball) return;
1194
+ var r = ui.ball.getBoundingClientRect();
1195
+ var pw = ui.panel.offsetWidth || 300;
1196
+ var ph = ui.panel.offsetHeight || 320;
1197
+ var left = r.left + r.width / 2 - pw / 2;
1198
+ left = Math.max(8, Math.min(window.innerWidth - pw - 8, left));
1199
+ var top = r.top - ph - 12;
1200
+ if (top < 8) top = r.bottom + 12;
1201
+ ui.panel.style.left = left + "px";
1202
+ ui.panel.style.top = top + "px";
1203
+ }
1204
+
1205
+ function show() {
1206
+ try { applyThemeNow(); } catch (e) {}
1207
+ expanded = true;
1208
+ if (ui.panel) { ui.panel.classList.add("tfb-open"); positionPanel(); }
1209
+ }
1210
+ function hide() {
1211
+ try { applyThemeNow(); } catch (e) {}
1212
+ expanded = false;
1213
+ if (ui.panel) ui.panel.classList.remove("tfb-open");
1214
+ // 字体插件同款:收起面板时刷新整个插件界面(重载 UI,主题/结构即时生效)
1215
+ setTimeout(function () { try { refreshPlugin(); } catch (e) {} }, 120);
1216
+ }
1217
+ function refreshPlugin() {
1218
+ try {
1219
+ var h = document.getElementById(BALL_ID);
1220
+ if (h) h.remove();
1221
+ ui = { root: null, ball: null, panel: null, list: null, summary: null, ctitle: null, pinBtn: null, pinSec: null, themeMenu: null };
1222
+ expanded = false;
1223
+ buildUI();
1224
+ applyBallVisibility();
1225
+ } catch (e) {}
1226
+ }
1227
+
1228
+ function buildUI() {
1229
+ if (document.getElementById(BALL_ID)) return;
1230
+ if (!document.body) return;
1231
+ try { fetch("/dsh-todo-float-ball/client-alive").catch(function () {}); } catch (e) {}
1232
+
1233
+ var host = document.createElement("div");
1234
+ host.id = BALL_ID;
1235
+
1236
+ var shadow = host.attachShadow({ mode: "open" });
1237
+ var style = document.createElement("style");
1238
+ style.textContent = cssText();
1239
+ shadow.appendChild(style);
1240
+
1241
+ var root = document.createElement("div");
1242
+ root.className = "tfb-root";
1243
+ root.innerHTML =
1244
+ '<button class="tfb-ball tfb-idle" type="button">' +
1245
+ '<span class="tfb-orb-band"></span>' +
1246
+ '<span class="tfb-orb-rim"></span>' +
1247
+ '<span class="tfb-ring"></span>' +
1248
+ '<span class="tfb-label">✓</span><span class="tfb-sub"></span>' +
1249
+ "</button>" +
1250
+ '<div class="tfb-panel">' +
1251
+ '<div class="tfb-head">' +
1252
+ '<span class="tfb-title">📋</span>' +
1253
+ '<span class="tfb-ctitle"></span>' +
1254
+ '<button class="tfb-btn" data-act="toggleLayout" title="切换面板布局:上下/左右" type="button">⇄</button>' +
1255
+ '<span class="tfb-summary"></span>' +
1256
+ '<button class="tfb-btn" data-act="pin" type="button">📌</button>' +
1257
+ '<button class="tfb-btn" data-act="themeMenu" type="button" title="切换皮肤">🎨</button>' +
1258
+ '<button class="tfb-btn" data-act="close" type="button" title="折叠">✕</button>' +
1259
+ "</div>" +
1260
+ '<div class="tfb-theme-menu"></div>' +
1261
+ '<div class="tfb-col tfb-col-cur">' +
1262
+ '<div class="tfb-colcap" data-cap="cur"></div>' +
1263
+ '<ul class="tfb-list"></ul>' +
1264
+ "</div>" +
1265
+
1266
+ '<div class="tfb-col tfb-col-pin">' +
1267
+ '<div class="tfb-colcap" data-cap="pin">📌 固定会话</div>' +
1268
+ '<div class="tfb-pinsec"></div>' +
1269
+ "</div>" +
1270
+
1271
+ '<div class="tfb-hint"><button class="tfb-btn" data-act="resetPos" type="button" title="一键归位右下角">🎯 归位</button> · 切换对话自动跟随 · 📌 固定 · 🎨 皮肤 · Esc 折叠</div>' +
1272
+ "</div>";
1273
+ shadow.appendChild(root);
1274
+
1275
+ // Mount to <html>, not body — DSH gives body containers transform/filter
1276
+ // which break position:fixed children (font-enhancer verified fix).
1277
+ var mount = document.documentElement || document.body;
1278
+ if (!host.parentNode) mount.appendChild(host);
1279
+
1280
+ ui.root = root;
1281
+ ui.ball = root.querySelector(".tfb-ball");
1282
+ ui.panel = root.querySelector(".tfb-panel");
1283
+ ui.list = root.querySelector(".tfb-list");
1284
+ ui.ctitle = root.querySelector(".tfb-ctitle");
1285
+ ui.summary = root.querySelector(".tfb-summary");
1286
+ ui.pinBtn = root.querySelector('[data-act="pin"]');
1287
+ ui.pinSec = root.querySelector(".tfb-pinsec"); ui.capCur = root.querySelector('[data-cap="cur"]');
1288
+ ui.themeMenu = root.querySelector(".tfb-theme-menu");
1289
+
1290
+ // restore position (clamped inside viewport)
1291
+ var bw = ui.ball.offsetWidth || 56, bh = ui.ball.offsetHeight || 56;
1292
+ try {
1293
+ var raw = localStorage.getItem(POS_KEY);
1294
+ if (raw) {
1295
+ var pos = JSON.parse(raw);
1296
+ if (pos && typeof pos.x === "number" && typeof pos.y === "number" &&
1297
+ pos.x >= 0 && pos.y >= 0 &&
1298
+ pos.x <= window.innerWidth - bw && pos.y <= window.innerHeight - bh) {
1299
+ ui.ball.style.left = pos.x + "px";
1300
+ ui.ball.style.top = pos.y + "px";
1301
+ ui.ball.style.right = "auto";
1302
+ ui.ball.style.bottom = "auto";
1303
+ }
1304
+ }
1305
+ } catch (e) {}
1306
+
1307
+ // drag + click-to-toggle (5px threshold separates the two)
1308
+ var drag = { active: false, moved: false, sx: 0, sy: 0, ox: 0, oy: 0 };
1309
+ ui.ball.addEventListener("pointerdown", function (e) {
1310
+ drag.active = true; drag.moved = false;
1311
+ drag.sx = e.clientX; drag.sy = e.clientY;
1312
+ var r = ui.ball.getBoundingClientRect();
1313
+ drag.ox = r.left; drag.oy = r.top;
1314
+ try { ui.ball.setPointerCapture(e.pointerId); } catch (err) {}
1315
+ e.preventDefault();
1316
+ });
1317
+ ui.ball.addEventListener("pointermove", function (e) {
1318
+ if (!drag.active) return;
1319
+ var dx = e.clientX - drag.sx, dy = e.clientY - drag.sy;
1320
+ if (!drag.moved && Math.abs(dx) + Math.abs(dy) < 5) return;
1321
+ drag.moved = true;
1322
+ var nx = Math.max(0, Math.min(window.innerWidth - (ui.ball.offsetWidth || bw), drag.ox + dx));
1323
+ var ny = Math.max(0, Math.min(window.innerHeight - (ui.ball.offsetHeight || bh), drag.oy + dy));
1324
+ ui.ball.style.left = nx + "px";
1325
+ ui.ball.style.top = ny + "px";
1326
+ ui.ball.style.right = "auto";
1327
+ ui.ball.style.bottom = "auto";
1328
+ try { localStorage.setItem(POS_KEY, JSON.stringify({ x: Math.round(nx), y: Math.round(ny) })); } catch (err) {}
1329
+ if (expanded) positionPanel();
1330
+ });
1331
+ function endDrag(e) {
1332
+ if (!drag.active) return;
1333
+ drag.active = false;
1334
+ try { ui.ball.releasePointerCapture(e.pointerId); } catch (err) {}
1335
+ if (!drag.moved) { if (expanded) hide(); else show(); }
1336
+ }
1337
+ ui.ball.addEventListener("pointerup", endDrag);
1338
+ ui.ball.addEventListener("pointercancel", endDrag);
1339
+
1340
+ // RIGHT-CLICK: toggle capsule mode (long pill showing the running
1341
+ // task); persists in localStorage.
1342
+ ui.ball.addEventListener("contextmenu", function (e) {
1343
+ e.preventDefault();
1344
+ capsule = !capsule;
1345
+ try { localStorage.setItem(CAPSULE_KEY, capsule ? "1" : "0"); } catch (err) {}
1346
+ render();
1347
+ });
1348
+
1349
+ // delegated actions inside the shadow root
1350
+ root.addEventListener("click", function (e) {
1351
+ var t = e.target && e.target.closest ? e.target.closest("[data-act]") : null;
1352
+ if (!t) {
1353
+ // clicking the title text (not while editing) starts a rename
1354
+ if (e.target === ui.ctitle && currentSid && hasSessionsSvc) startRename(currentSid);
1355
+ return;
1356
+ }
1357
+ var act = t.getAttribute("data-act");
1358
+ var sid = t.getAttribute("data-sid");
1359
+ // Plan-A9 back-compat: normalize the legacy Plan-A8 fold action names
1360
+ // onto the unified ones before dispatch (see ACT_ALIAS).
1361
+ if (ACT_ALIAS[act]) act = ACT_ALIAS[act];
1362
+ if (act === "close") hide();
1363
+ else if (act === "pin") {
1364
+ if (!currentSid) return;
1365
+ if (isPinned(currentSid)) unpin(currentSid); else pin(currentSid);
1366
+ } else if (act === "resetPos") {
1367
+ try { localStorage.removeItem(POS_KEY); } catch (err) {}
1368
+ if (ui.ball) { ui.ball.style.left = "auto"; ui.ball.style.top = "auto"; ui.ball.style.right = "18px"; ui.ball.style.bottom = "18px"; }
1369
+ } else if (act === "toggleHistory") {
1370
+ // Plan-A9: expand/collapse the completed-history fold — PER-SID
1371
+ // (data-ownsid targets the row's own session; the current list
1372
+ // falls back to currentSid).
1373
+ var sidT1 = normSid(actionSid(t));
1374
+ historyOpen[sidT1] = !historyOpen[sidT1];
1375
+ render();
1376
+ } else if (act === "toggleHistoryOpen") {
1377
+ // Plan-A3.1/Plan-A9: non-completed fold, per-sid as well.
1378
+ var sidT2 = normSid(actionSid(t));
1379
+ historyOpenOpen[sidT2] = !historyOpenOpen[sidT2];
1380
+ render();
1381
+ } else if (act === "clearHistory" || act === "clearHistoryOpen" || act === "clearAll") {
1382
+ // Plan-A5: batch hide — mark every archive row of the targeted
1383
+ // fold(s) as hidden (same ✕ semantics: display-only, per-session).
1384
+ // Plan-A9: target = the row's own session, never the current one.
1385
+ var ns5 = normSid(actionSid(t));
1386
+ var b5 = bySession[ns5];
1387
+ var hid5 = hiddenFor(ns5);
1388
+ var snapLen5 = (b5 && typeof b5.snapLen === "number") ? Math.min(b5.snapLen, (b5.todos || []).length) : 0;
1389
+ var todos5 = (b5 && b5.todos) || [];
1390
+ var from = act === "clearHistory" ? snapLen5 : snapLen5; // both folds start after snapshot
1391
+ var to = act === "clearHistory" ? todos5.length : todos5.length;
1392
+ var changed5 = false;
1393
+ for (var ci = from; ci < to; ci++) {
1394
+ var it5 = todos5[ci];
1395
+ if (!it5 || !it5.content) continue;
1396
+ if (act === "clearHistory" && it5.status !== "completed") continue;
1397
+ if (act === "clearHistoryOpen" && it5.status === "completed") continue;
1398
+ if (!hid5[it5.content]) { hid5[it5.content] = true; changed5 = true; }
1399
+ }
1400
+ if (changed5) { saveHidden(); delete historyOpen[ns5]; delete historyOpenOpen[ns5]; }
1401
+ render();
1402
+ } else if (act === "restoreAll") {
1403
+ // Plan-A7: un-hide EVERYTHING hidden in this session — the inverse
1404
+ // of ✕ and 🧹 combined. Display-only, scoped to this session.
1405
+ // Plan-A9: session = the row's own sid (data-ownsid first).
1406
+ e.stopPropagation();
1407
+ var ns7 = normSid(actionSid(t));
1408
+ var hid7 = hiddenFor(ns7);
1409
+ var restored7 = false;
1410
+ for (var k7 in hid7) { delete hid7[k7]; restored7 = true; }
1411
+ if (restored7) { saveHidden(); historyOpen[ns7] = true; historyOpenOpen[ns7] = true; }
1412
+ render();
1413
+ } else if (act === "toggleLayout") {
1414
+ // Plan-A10: panel layout switch — stacked (up/down) <-> side-by-side (left/right).
1415
+ e.stopPropagation();
1416
+ layoutHz = !layoutHz;
1417
+ try { localStorage.setItem("dsh-todo-float-ball-layout", layoutHz ? "1" : "0"); } catch (err) {}
1418
+ if (ui.panel) ui.panel.classList.toggle("tfb-hz", !!layoutHz);
1419
+ if (expanded) positionPanel();
1420
+ render();
1421
+ } else if (act === "copyItem") {
1422
+ // Plan-A6: copy the row's full task text. The payload rides in the
1423
+ // data-copy attribute (the visible text may be truncated at
1424
+ // MAX_CONTENT). BUGFIX (user report: paste was empty): read
1425
+ // data-copy explicitly — the generic `sid` variable only carries
1426
+ // data-sid, which copy buttons don't have (it copied "").
1427
+ e.stopPropagation();
1428
+ var cpText = t.getAttribute("data-copy") || "";
1429
+ var copyOk = false;
1430
+ // execCommand path FIRST: it is synchronous, works inside the
1431
+ // Electron webview without clipboard-write permission, and its
1432
+ // success is actually observable. The async clipboard API in this
1433
+ // environment can reject silently (no await in a delegated
1434
+ // handler), which looked like success but pasted nothing.
1435
+ try {
1436
+ var ta = document.createElement("textarea");
1437
+ ta.value = cpText;
1438
+ ta.style.position = "fixed";
1439
+ ta.style.top = "0";
1440
+ ta.style.left = "0";
1441
+ ta.style.opacity = "0";
1442
+ document.body.appendChild(ta);
1443
+ ta.focus();
1444
+ ta.select();
1445
+ copyOk = document.execCommand("copy");
1446
+ document.body.removeChild(ta);
1447
+ } catch (err5) { copyOk = false; }
1448
+ if (!copyOk) {
1449
+ // fallback: async clipboard API (needs permission; may fail)
1450
+ try {
1451
+ if (navigator && navigator.clipboard && navigator.clipboard.writeText) {
1452
+ navigator.clipboard.writeText(cpText);
1453
+ copyOk = true;
1454
+ }
1455
+ } catch (err6) { copyOk = false; }
1456
+ }
1457
+ // visual ack reflects the real result: ✓ copied / ⚠ failed
1458
+ try {
1459
+ t.textContent = copyOk ? "✓" : "⚠";
1460
+ setTimeout(function () { try { t.textContent = "📋"; } catch (e7) {} }, 800);
1461
+ } catch (err7) {}
1462
+ } else if (act === "themeMenu") {
1463
+ // toggle the skin picker inside the panel
1464
+ if (ui.themeMenu) ui.themeMenu.classList.toggle("tfb-open");
1465
+ renderThemeMenu();
1466
+ e.stopPropagation();
1467
+ } else if (act === "setTheme" && sid) {
1468
+ // pick a skin from the menu
1469
+ currentTheme = sid;
1470
+ try { localStorage.setItem(THEME_KEY, sid); } catch (err) {}
1471
+ try {
1472
+ var stEl = ui.root.querySelector("style");
1473
+ if (stEl) stEl.textContent = cssText();
1474
+ } catch (err) {}
1475
+ render();
1476
+ renderThemeMenu();
1477
+ e.stopPropagation();
1478
+ } else if (act === "togglePin" && sid) {
1479
+ openPin[sid] = !openPin[sid];
1480
+ render();
1481
+ } else if (act === "renamePin" && sid) {
1482
+ e.stopPropagation();
1483
+ startRename(sid);
1484
+ } else if (act === "unpin" && sid) {
1485
+ e.stopPropagation();
1486
+ unpin(sid);
1487
+ } else if (act === "hideItem") {
1488
+ // Plan-A2: row ✕ — hide this item from the display (display-only;
1489
+ // the session log and the stored record are untouched).
1490
+ // Plan-A2.2: resolve the row's OWN session (a pinned list row
1491
+ // belongs to its pinned sid, not to the current one) — walk up to
1492
+ // the enclosing .tfb-pinlist's parent pinrow when present.
1493
+ e.stopPropagation(); var li = t.closest ? t.closest(".tfb-item") : null;
1494
+ var txtEl = li ? li.querySelector(".tfb-txt") : null;
1495
+ if (txtEl) {
1496
+ // Plan-A2.2: the row's own session. Pinned lists carry
1497
+ // data-ownsid on their <ul> (set in renderPinned); current-list
1498
+ // rows fall back to currentSid.
1499
+ var rowSid = currentSid;
1500
+ var pinUl = li.closest ? li.closest(".tfb-pinlist") : null;
1501
+ if (pinUl && pinUl.getAttribute) {
1502
+ var own = pinUl.getAttribute("data-ownsid");
1503
+ if (own) rowSid = own;
1504
+ }
1505
+ hideItem(rowSid, txtEl.textContent);
1506
+ }
1507
+ }
1508
+ });
1509
+
1510
+ window.addEventListener("resize", function () { if (expanded) positionPanel(); });
1511
+ document.addEventListener("keydown", function (e) { if (e.key === "Escape" && expanded) hide(); });
1512
+
1513
+ render();
1514
+ }
1515
+
1516
+ // ---------- entry ----------
1517
+ var inject = ["sessions"];
1518
+ var currentSessions = null;
1519
+
1520
+ // Skin buttons live in the sibling settings section (React-rendered);
1521
+ // React synthetic events / refs proved unreliable there, so the buttons
1522
+ // carry plain data attributes and we delegate at the DOCUMENT capture
1523
+ // phase — immune to any re-render, and capture fires before anything
1524
+ // can stopPropagation.
1525
+ function installThemeDelegation() {
1526
+ if (window.__dshtfbThemeDelegated) return;
1527
+ window.__dshtfbThemeDelegated = true;
1528
+ document.addEventListener("click", function (e) {
1529
+ var t = e.target && e.target.closest ? e.target.closest("[data-tfb-theme]") : null;
1530
+ if (!t) return;
1531
+ var theme = t.getAttribute("data-tfb-theme");
1532
+ if (theme !== "nebula" && theme !== "graphite" && theme !== "blue" && theme !== "glass" && theme !== "nebB" && theme !== "nebC") return;
1533
+ try { localStorage.setItem(THEME_KEY, theme); } catch (err) {}
1534
+ currentTheme = theme;
1535
+ applyThemeNow();
1536
+ }, true);
1537
+ }
1538
+
1539
+ // ---------- ball visibility (driven by the shared settings section) ----------
1540
+ // The show/hide toggle lives in the shared "悬浮球导航" settings section
1541
+ // provided by dsh-skill-browser (same pattern as the font ball). We only
1542
+ // read the shared localStorage key and apply it defensively.
1543
+ var BALL_VIS_KEY = "dsh-tfb-ball-visible";
1544
+ function ballVisible() {
1545
+ // default TRUE (always visible), seeded on first run so the shared
1546
+ // settings section can flip it and have the choice persist.
1547
+ return getCfg(BALL_VIS_KEY, DEFAULTS.ballVisible) === "1";
1548
+ }
1549
+ function applyBallVisibility() {
1550
+ var b = document.querySelector("#" + BALL_ID);
1551
+ if (!b) return;
1552
+ var show = ballVisible();
1553
+ // Uninstall-fallback (ecosystem safety): the show/hide toggle lives in
1554
+ // the shared "悬浮球导航" section provided by dsh-skill-browser. If
1555
+ // that plugin is GONE and the stored flag says hidden, the ball would
1556
+ // be stuck invisible with no way back — in that case ignore the flag
1557
+ // and show the ball again.
1558
+ if (!show) {
1559
+ var providerGone = !document.getElementById("dsh-skill-browser-ball") &&
1560
+ !document.querySelector('[data-dsb-slot]');
1561
+ if (providerGone) show = true;
1562
+ }
1563
+ b.style.setProperty("display", show ? "" : "none", "important");
1564
+ }
1565
+ function watchBallVisibility() {
1566
+ // Long-lived, low-frequency: the shared settings section writes the
1567
+ // theme/visibility keys and expects them picked up — so this watcher
1568
+ // must NOT expire (the old 20-min cap made skin switching die after
1569
+ // 20 minutes). The sibling plugin also calls window.__dshtfbApplyTheme
1570
+ // directly for instant effect; the poll is just a safety net.
1571
+ setInterval(function () {
1572
+ try { applyBallVisibility(); } catch (e) {}
1573
+ // 2s SAFETY NET (v0.9.1): if the sessions.list.subscribe() callback
1574
+ // ever stops firing (shell re-render, dropped projection frame, a
1575
+ // remount), the ball would otherwise sit on stale todos forever.
1576
+ // This pull is effectively free: syncFromSessions() funnels into
1577
+ // setSessionTodos(), whose signature check returns early on an
1578
+ // identical list, and it only re-renders when something moved.
1579
+ try { syncFromSessions(); } catch (e) {}
1580
+ try {
1581
+ var v = peekCfg(THEME_KEY, DEFAULTS.theme);
1582
+ if (isTheme(v) && v !== currentTheme) applyThemeNow();
1583
+ } catch (e) {}
1584
+ }, 2000);
1585
+ }
1586
+ // Immediate theme application — exposed as window.__dshtfbApplyTheme so
1587
+ // the sibling settings section can invoke it synchronously on click.
1588
+ function applyThemeNow() {
1589
+ var v = getCfg(THEME_KEY, DEFAULTS.theme);
1590
+ currentTheme = isTheme(v) ? v : DEFAULTS.theme;
1591
+ try {
1592
+ if (ui.root) {
1593
+ var st = ui.root.querySelector("style");
1594
+ if (st) st.textContent = cssText();
1595
+ }
1596
+ } catch (e) {}
1597
+ render();
1598
+ }
1599
+
1600
+ function apply(ctx) {
1601
+ // First-run seed: fill any ABSENT preference with its code default so a
1602
+ // fresh install is immediately usable and the values stay editable.
1603
+ // Existing stored values win — getCfg never overwrites.
1604
+ ensureDefaultCfg();
1605
+ loadPinned();
1606
+ loadHidden();
1607
+ loadTheme();
1608
+ try { capsule = getCfg(CAPSULE_KEY, DEFAULTS.capsule) === "1"; } catch (e) {}
1609
+ restorePersisted();
1610
+ if (ui.panel && layoutHz) ui.panel.classList.add("tfb-hz");
1611
+ // primary data channel: the official sessions service
1612
+ try {
1613
+ if (ctx && ctx.sessions && ctx.sessions.list && typeof ctx.sessions.list.getSnapshot === "function") {
1614
+ currentSessions = ctx.sessions;
1615
+ hasSessionsSvc = true;
1616
+ try { ctx.sessions.list.subscribe(syncFromSessions); } catch (e) {}
1617
+ syncFromSessions();
1618
+ }
1619
+ } catch (e) {}
1620
+ // global hook: lets the shared settings section switch the theme
1621
+ // synchronously on click (no polling delay).
1622
+ try {
1623
+ window.__dshtfbApplyTheme = applyThemeNow;
1624
+ } catch (e) {}
1625
+ // document-level delegation for the sibling skin buttons (React
1626
+ // synthetic events / refs unreliable in that slot — plain
1627
+ // data-attribute buttons + capture-phase listener always fire)
1628
+ installThemeDelegation();
1629
+ // UI
1630
+ if (document.readyState === "loading") {
1631
+ document.addEventListener("DOMContentLoaded", buildUI);
1632
+ } else {
1633
+ buildUI();
1634
+ }
1635
+ applyBallVisibility();
1636
+ watchBallVisibility();
1637
+ // fallback channel only when the sessions service is unavailable
1638
+ if (!hasSessionsSvc) installPanelObserver();
1639
+ // watchdog keeps the ball alive across shell rebuilds
1640
+ var tries = 0;
1641
+ var t = setInterval(function () {
1642
+ tries++;
1643
+ try {
1644
+ if (!document.getElementById(BALL_ID)) buildUI();
1645
+ else renderBall();
1646
+ if (hasSessionsSvc) syncFromSessions();
1647
+ } catch (e) {}
1648
+ if (tries > 300) clearInterval(t);
1649
+ }, 2000);
1650
+ }
1651
+
1652
+ exports.apply = apply;
1653
+ exports.inject = inject;
1654
+ return module.exports;
1655
+ }
1656
+ });