opencode-work-context 0.5.1 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -322,16 +322,25 @@ disable this TUI loader; the package does not use an internal keymap fallback.
322
322
 
323
323
  The optional TUI loader tracks linked OpenCode sessions that need attention.
324
324
  Questions, permission requests, errors, and a background session becoming idle
325
- after observed work remain marked with `[ATTN]` until that native session is
326
- opened. Attention does not change workspace or stage lifecycle state.
325
+ after observed work remain marked until that native session is opened. Compact
326
+ markers retain both a symbol and a textual reason: `[✓ response complete]`,
327
+ `[? question]`, `[! permission]`, or `[x error]`. Aggregated markers append an
328
+ `xN` session count. Attention does not change workspace or stage lifecycle state.
329
+
330
+ The stages sidebar separately observes live `busy` and `retry` events for active
331
+ OpenCode sessions mapped to visible work-context stages. A braille loader appears
332
+ beside the lifecycle marker while any such session is working and stops on idle,
333
+ question, permission, or error events. This live state is never persisted or
334
+ inferred from stage status, historical sessions, or unread attention, so startup
335
+ and missed mappings fail closed without a stale loader.
327
336
 
328
337
  Every loaded TUI instance registers a short-lived user-level activity lease.
329
338
  Focus and keyboard activity select the active OpenCode instance independently
330
339
  of its project directory. When a session in project A needs attention while the
331
340
  user works in project B, A publishes a bounded event under
332
341
  `$XDG_RUNTIME_DIR/opencode-work-context/attention-v1` and active B displays a
333
- native `Work Context` toast. The persistent `[ATTN]` marker remains in project A;
334
- the toast does not import A's state or enable cross-server navigation.
342
+ native `Work Context` toast. The persistent reason-specific marker remains in
343
+ project A; the toast does not import A's state or enable cross-server navigation.
335
344
 
336
345
  The channel uses private directories, atomic immutable event files, strict
337
346
  schemas, ownership/type/size checks, short event expiry, stale-lease cleanup,
@@ -383,8 +392,8 @@ receives focus or keyboard activity.
383
392
  To verify cross-project delivery, install and load the TUI integration in two
384
393
  projects, start work in linked session A, then interact with OpenCode B before A
385
394
  finishes or asks a question. Expect a `Work Context` toast inside B, one system
386
- notification, and a persistent `[ATTN]` marker in A. Open A's affected native
387
- session to clear its marker. Set `notifications.desktop` to `false`, restart
395
+ notification, and a persistent reason-specific marker in A. Open A's affected
396
+ native session to clear its marker. Set `notifications.desktop` to `false`, restart
388
397
  OpenCode, and repeat to verify that the toast and marker remain without the
389
398
  system notification.
390
399
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "opencode-work-context",
3
3
  "type": "module",
4
- "version": "0.5.1",
4
+ "version": "0.6.0",
5
5
  "description": "Filesystem work-context core and OpenCode adapter",
6
6
  "license": "MIT",
7
7
  "author": {
@@ -15,6 +15,7 @@ const ACTIVE_ATTENTION_KEY = Symbol.for("opencode-work-context.attention");
15
15
  const activeControllers = new WeakMap();
16
16
  const PRIORITY = { idle: 1, question: 2, permission: 3, error: 4 };
17
17
  const REASON_TEXT = { idle: "response complete", question: "question", permission: "permission", error: "error" };
18
+ const REASON_MARKER = { idle: "✓", question: "?", permission: "!", error: "x" };
18
19
  const EVENT_TYPES = [
19
20
  "session.status",
20
21
  "session.idle",
@@ -29,7 +30,8 @@ const stableHash = (parts) => createHash("sha256").update(parts.map((part) => St
29
30
  const eventBody = (event) => event?.properties || event?.data || {};
30
31
  const eventSessionId = (event) => {
31
32
  const body = eventBody(event);
32
- return body.sessionID || body.sessionId || body.session_id || event?.sessionID || event?.sessionId || event?.session_id;
33
+ return body.sessionID || body.sessionId || body.session_id || body.info?.id || body.part?.sessionID
34
+ || event?.sessionID || event?.sessionId || event?.session_id;
33
35
  };
34
36
  const eventKey = (event, kind, cycle) => {
35
37
  const body = eventBody(event);
@@ -70,6 +72,9 @@ export const normalizeAttentionEvent = (event, cycle = 0) => {
70
72
  };
71
73
 
72
74
  export const attentionReasonText = (reason) => REASON_TEXT[reason] || "attention";
75
+ export const attentionIndicatorText = (attention) => attention
76
+ ? `[${REASON_MARKER[attention.reason] || "!"} ${attentionReasonText(attention.reason)}${attention.count > 1 ? ` x${attention.count}` : ""}]`
77
+ : "";
73
78
  export const globalAttentionToast = (event) => {
74
79
  const context = [event?.projectTitle, event?.workspaceTitle, event?.stageTitle].filter(Boolean).join(" / ");
75
80
  return {
@@ -280,6 +285,8 @@ const visibleSessionRecords = (snapshot, sessionId) => (snapshot?.workspaces ||
280
285
  .filter((session) => session.opencode_session_id === sessionId && visibleStages.has(session.stage))
281
286
  .map((session) => ({ workspace, session }));
282
287
  });
288
+ const activeVisibleSessionRecords = (snapshot, sessionId) => visibleSessionRecords(snapshot, sessionId)
289
+ .filter(({ session }) => session.state === "active");
283
290
  const notificationContexts = (snapshot, sessionId, reason) => {
284
291
  const contexts = [];
285
292
  const seen = new Set();
@@ -316,29 +323,85 @@ export const createAttentionTuiController = ({ api, projectRoot, read = readWork
316
323
  });
317
324
  let linked = new Set();
318
325
  let snapshot = null;
326
+ let activityMappingAvailable = false;
327
+ const activity = new Map();
328
+ const listeners = new Set();
319
329
  let disposed = false;
330
+ let refreshGeneration = 0;
331
+ let latestRefresh = Promise.resolve(false);
320
332
  let pending = Promise.resolve();
333
+ const notify = (change) => {
334
+ for (const listener of listeners) listener(change);
335
+ };
336
+ const unsubscribeEngine = engine.subscribe(notify);
337
+ const setActivity = (sessionId, status) => {
338
+ if (activity.get(sessionId) === status) return false;
339
+ activity.set(sessionId, status);
340
+ notify({ sessionId, activity: status });
341
+ return true;
342
+ };
343
+ const clearActivity = (sessionId) => {
344
+ if (!activity.delete(sessionId)) return false;
345
+ notify({ sessionId, activity: null });
346
+ return true;
347
+ };
348
+ const pruneActivity = () => {
349
+ for (const sessionId of activity.keys()) {
350
+ if (!activeVisibleSessionRecords(snapshot, sessionId).length) clearActivity(sessionId);
351
+ }
352
+ };
353
+ const clearAllActivity = () => {
354
+ for (const sessionId of [...activity.keys()]) clearActivity(sessionId);
355
+ };
321
356
  const acknowledgeObserved = (sessionId) => {
322
357
  const observedEventKey = engine.attentionFor(sessionId)?.eventKey;
323
358
  return observedEventKey ? engine.acknowledge(sessionId, observedEventKey) : false;
324
359
  };
325
- const refresh = async () => {
326
- try {
327
- const result = await read({ projectRoot, sessionId: currentSessionId(api) });
328
- if (result?.ok) {
329
- linked = linkedSessionIds(result);
330
- snapshot = result.data;
331
- const current = currentSessionId(api);
332
- if (isFocused() !== false && current && linked.has(current) && shouldAcknowledge(current) !== false) acknowledgeObserved(current);
360
+ const refresh = () => {
361
+ const generation = ++refreshGeneration;
362
+ const operation = (async () => {
363
+ try {
364
+ const result = await read({ projectRoot, sessionId: currentSessionId(api) });
365
+ if (disposed || generation !== refreshGeneration) return false;
366
+ if (result?.ok) {
367
+ linked = linkedSessionIds(result);
368
+ snapshot = result.data;
369
+ activityMappingAvailable = true;
370
+ pruneActivity();
371
+ const current = currentSessionId(api);
372
+ if (isFocused() !== false && current && linked.has(current) && shouldAcknowledge(current) !== false) acknowledgeObserved(current);
373
+ } else {
374
+ activityMappingAvailable = false;
375
+ clearAllActivity();
376
+ }
377
+ } catch {
378
+ if (disposed || generation !== refreshGeneration) return false;
379
+ activityMappingAvailable = false;
380
+ clearAllActivity();
333
381
  }
334
- } catch {}
335
- return linked;
382
+ return true;
383
+ })();
384
+ latestRefresh = operation;
385
+ return operation;
336
386
  };
337
387
  const process = async (event) => {
338
388
  if (disposed) return { changed: false, ignored: true };
339
389
  const sessionId = eventSessionId(event);
340
390
  if (!sessionId) return { changed: false, ignored: true };
341
- await refresh();
391
+ refresh();
392
+ while (!disposed) {
393
+ const observed = latestRefresh;
394
+ const ready = await observed;
395
+ if (ready && observed === latestRefresh) break;
396
+ }
397
+ if (disposed) return { changed: false, ignored: true };
398
+ const normalized = normalizeAttentionEvent(event);
399
+ if (normalized?.kind === "status" && ["busy", "retry"].includes(normalized.status)) {
400
+ if (activityMappingAvailable && activeVisibleSessionRecords(snapshot, sessionId).length) setActivity(sessionId, normalized.status);
401
+ else clearActivity(sessionId);
402
+ } else if (normalized) {
403
+ clearActivity(sessionId);
404
+ }
342
405
  if (!linked.has(sessionId)) return { changed: false, unlinked: true };
343
406
  const foreground = isFocused() !== false ? currentSessionId(api) : undefined;
344
407
  if (foreground === sessionId && shouldAcknowledge(sessionId) !== false) acknowledgeObserved(sessionId);
@@ -371,6 +434,14 @@ export const createAttentionTuiController = ({ api, projectRoot, read = readWork
371
434
  const mostImportant = items.reduce((best, item) => PRIORITY[item.reason] > PRIORITY[best.reason] ? item : best);
372
435
  return { count: items.length, reason: mostImportant.reason, items };
373
436
  };
437
+ const aggregateActivity = (matches) => {
438
+ if (!activityMappingAvailable) return null;
439
+ const items = [];
440
+ for (const [sessionId, status] of activity) {
441
+ if (activeVisibleSessionRecords(snapshot, sessionId).some(matches)) items.push({ sessionId, status });
442
+ }
443
+ return items.length ? { count: items.length, items } : null;
444
+ };
374
445
 
375
446
  return {
376
447
  refresh,
@@ -379,9 +450,23 @@ export const createAttentionTuiController = ({ api, projectRoot, read = readWork
379
450
  attentionFor: engine.attentionFor,
380
451
  attentionForStage: (workspace, stage) => aggregate((record) => record.workspace.id === workspace && record.session.stage === stage),
381
452
  attentionForWorkspace: (workspace) => aggregate((record) => record.workspace.id === workspace),
453
+ activityFor: (sessionId) => activity.get(sessionId) || null,
454
+ activityForStage: (workspace, stage) => aggregateActivity((record) => record.workspace.id === workspace && record.session.stage === stage),
455
+ activityForWorkspace: (workspace) => aggregateActivity((record) => record.workspace.id === workspace),
456
+ listActivity: () => [...activity].map(([sessionId, status]) => ({ sessionId, status })),
382
457
  list: engine.list,
383
- subscribe: engine.subscribe,
384
- dispose: () => { disposed = true; },
458
+ subscribe: (listener) => {
459
+ listeners.add(listener);
460
+ return () => listeners.delete(listener);
461
+ },
462
+ dispose: () => {
463
+ if (disposed) return;
464
+ disposed = true;
465
+ refreshGeneration += 1;
466
+ activity.clear();
467
+ listeners.clear();
468
+ unsubscribeEngine();
469
+ },
385
470
  };
386
471
  };
387
472
 
@@ -1,5 +1,5 @@
1
1
  import { readWorkContextSnapshot } from "../src/work-context-snapshot.js";
2
- import { acknowledgeNavigation, attentionForSession, attentionReasonText } from "./attention.js";
2
+ import { acknowledgeNavigation, attentionForSession, attentionIndicatorText, attentionReasonText } from "./attention.js";
3
3
 
4
4
  const SESSION_STATE_RANK = { active: 0, handed_off: 1, abandoned: 2, closed: 3 };
5
5
 
@@ -74,7 +74,7 @@ export const createSessionSwitcherFlow = (api, { read = readWorkContextSnapshot
74
74
  placeholder: "Search sessions",
75
75
  options: [
76
76
  ...available.map(({ workspace, session }) => ({
77
- title: `${attention(session.opencode_session_id) ? "[ATTN] " : ""}${workspace.id} ${session.stage || "-"}/${String(session.ordinal || 0).padStart(2, "0")} ${session.summary || "Work session"} · ${workspace.title}`,
77
+ title: `${attentionIndicatorText(attention(session.opencode_session_id))} ${workspace.id} ${session.stage || "-"}/${String(session.ordinal || 0).padStart(2, "0")} ${session.summary || "Work session"} · ${workspace.title}`.trim(),
78
78
  description: `${attention(session.opencode_session_id) ? `needs attention: ${attentionReasonText(attention(session.opencode_session_id).reason)} · ` : ""}${session.state || "unknown"} · ${session.session_id || "unknown"}`,
79
79
  footer: session.opencode_session_id,
80
80
  category: session.opencode_session_id === currentId ? "Current" : labels[session.state] || session.state || "Unknown",
@@ -1,7 +1,7 @@
1
1
  import { contextFor } from "../src/opencode-adapter.js";
2
2
  import { isDependencySatisfied } from "../src/stage-status.js";
3
3
  import { readTuiState, updateTuiState } from "./tui-state.js";
4
- import { acknowledgeNavigation, attentionForSession, attentionReasonText } from "./attention.js";
4
+ import { acknowledgeNavigation, attentionForSession, attentionIndicatorText, attentionReasonText } from "./attention.js";
5
5
 
6
6
  const TERMINAL_STATUSES = new Set(["completed", "cancelled", "archived"]);
7
7
  const SESSION_STATE_RANK = { active: 0, handed_off: 1, abandoned: 2, closed: 3 };
@@ -207,7 +207,7 @@ export const createStageSwitcherFlow = (api, { read = readStageSwitcherSnapshot,
207
207
  const available = (stage.sessions || []).filter((session) => session.opencode_session_id).length;
208
208
  const state = stage.blocked ? `blocked by ${stage.blockers.join(", ")}` : stage.status;
209
209
  return {
210
- title: `${stage.current ? ">" : " "} ${stage.attention ? "[ATTN] " : ""}${stage.id}. ${stage.title}`,
210
+ title: `${stage.current ? ">" : " "} ${attentionIndicatorText(stage.attention)} ${stage.id}. ${stage.title}`.replace(/ +/g, " "),
211
211
  description: `${stage.attention ? `needs attention: ${attentionReasonText(stage.attention.reason)} (${stage.attention.count}) · ` : ""}${state} · ${available ? `${available} session${available === 1 ? "" : "s"}` : TERMINAL_STATUSES.has(stage.status) || stage.blocked ? "no session available" : "new session"}`,
212
212
  category,
213
213
  disabled: (TERMINAL_STATUSES.has(stage.status) || stage.blocked) && !available,
@@ -5,12 +5,14 @@ import { contextFor, titleFor } from "../src/opencode-adapter.js";
5
5
  import { renderDependencyTree, renderStagesPanel } from "../src/stages-renderer.js";
6
6
  import { jsx } from "@opentui/solid/jsx-runtime";
7
7
  import { createSignal } from "solid-js";
8
- import { attentionReasonText } from "./attention.js";
8
+ import { attentionIndicatorText } from "./attention.js";
9
9
  import { createStageSwitcherFlow } from "./stage-switcher.js";
10
10
  import { readTuiState, updateTuiState } from "./tui-state.js";
11
11
 
12
12
  const DEBOUNCE_MS = 150;
13
13
  const POLL_MS = 1000;
14
+ const LOADER_MS = 80;
15
+ const LOADER_FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
14
16
  const PATH_TIMEOUT_MS = 5000;
15
17
  const PATH_POLL_MS = 25;
16
18
  const WORK_CONTEXT_PREFIX = "work" + "_" + "context_";
@@ -40,14 +42,15 @@ const candidateSummaryText = (workspace) => workspace.candidates && (workspace.c
40
42
  export { readStagesSnapshot, renderStagesPanel };
41
43
 
42
44
  const defaultRuntime = { jsx };
43
- const renderAttentionText = (value, runtime) => {
44
- const parts = value.split(/(\[ATTN[^\]]*\])/g);
45
- return parts.length === 1 ? value : parts.filter(Boolean).map((part) => part.startsWith("[ATTN")
46
- ? runtime.jsx("b", { children: part })
47
- : part);
45
+ const renderAttentionText = (value, indicator, runtime) => {
46
+ if (!indicator) return value;
47
+ const parts = value.split(indicator);
48
+ return parts.length === 1 ? value : parts.flatMap((part, index) => index
49
+ ? [runtime.jsx("b", { children: indicator }), part]
50
+ : [part]).filter(Boolean);
48
51
  };
49
52
 
50
- const renderStagesContent = (result, theme, runtime = defaultRuntime, attention, showDependencies = true, onStageSelect) => !result?.ok || !result.data?.workspace
53
+ const renderStagesContent = (result, theme, runtime = defaultRuntime, attention, showDependencies = true, onStageSelect, activityFrame = () => LOADER_FRAMES[0]) => !result?.ok || !result.data?.workspace
51
54
  ? [
52
55
  runtime.jsx("text", { children: runtime.jsx("b", { children: "Stages" }) }),
53
56
  ...renderStagesPanel(result).split("\n").slice(1).map((line) => runtime.jsx("text", { children: line })),
@@ -57,7 +60,7 @@ const renderStagesContent = (result, theme, runtime = defaultRuntime, attention,
57
60
  marginBottom: 1,
58
61
  flexDirection: "column",
59
62
  children: [
60
- runtime.jsx("text", { wrapMode: "word", children: runtime.jsx("b", { children: `${attention?.attentionForWorkspace?.(result.data.workspace.id) ? "[ATTN] " : ""}${result.data.workspace.title}` }) }),
63
+ runtime.jsx("text", { wrapMode: "word", children: runtime.jsx("b", { children: `${attentionIndicatorText(attention?.attentionForWorkspace?.(result.data.workspace.id))} ${result.data.workspace.title}`.trim() }) }),
61
64
  runtime.jsx("text", { fg: theme?.current?.textMuted, children: `Workflow · ${result.data.workspace.mode || "standard"}` }),
62
65
  candidateSummaryText(result.data.workspace) && runtime.jsx("text", { fg: theme?.current?.textMuted, children: candidateSummaryText(result.data.workspace) }),
63
66
  ],
@@ -71,11 +74,12 @@ const renderStagesContent = (result, theme, runtime = defaultRuntime, attention,
71
74
  }),
72
75
  ...result.data.stages.map((stage) => {
73
76
  const unread = attention?.attentionForStage?.(result.data.workspace.id, stage.id);
77
+ const working = attention?.activityForStage?.(result.data.workspace.id, stage.id);
74
78
  const metadata = showDependencies ? [
75
79
  stage.tracker_links?.length && `Tasks: ${stage.tracker_links.map(trackerLinkText).join(", ")}`,
76
80
  stage.depends_on?.length && `Deps: ${stage.depends_on.join(", ")}`,
77
81
  ].filter(Boolean).join(" · ") : "";
78
- const attentionText = unread ? `[ATTN: ${attentionReasonText(unread.reason)}${unread.count > 1 ? ` x${unread.count}` : ""}]` : "";
82
+ const attentionText = attentionIndicatorText(unread);
79
83
  const stageText = [
80
84
  `${stage.id}. ${stage.title}`,
81
85
  metadata,
@@ -88,17 +92,18 @@ const renderStagesContent = (result, theme, runtime = defaultRuntime, attention,
88
92
  return onStageSelect?.(stage);
89
93
  },
90
94
  children: [
95
+ working && runtime.jsx("text", { flexShrink: 0, marginRight: 1, fg: theme?.current?.warning, children: activityFrame() }),
91
96
  runtime.jsx("text", { flexShrink: 0, marginRight: 1, fg: stage.current || stage.id === result.data.currentStage ? theme?.current?.warning : theme?.current?.textMuted, children: statusMarker(stage.status) }),
92
- runtime.jsx("text", { flexGrow: 1, flexShrink: 1, wrapMode: "word", fg: stage.current || stage.id === result.data.currentStage ? theme?.current?.warning : theme?.current?.textMuted, children: renderAttentionText(stageText, runtime) }),
93
- ],
97
+ runtime.jsx("text", { flexGrow: 1, flexShrink: 1, wrapMode: "word", fg: stage.current || stage.id === result.data.currentStage ? theme?.current?.warning : theme?.current?.textMuted, children: renderAttentionText(stageText, attentionText, runtime) }),
98
+ ].filter(Boolean),
94
99
  });
95
100
  }),
96
101
  ];
97
102
 
98
- export const renderStagesElement = (result, theme, runtime = defaultRuntime, attention, showDependencies = true, onStageSelect) => {
103
+ export const renderStagesElement = (result, theme, runtime = defaultRuntime, attention, showDependencies = true, onStageSelect, activityFrame) => {
99
104
  return runtime.jsx("box", {
100
105
  flexDirection: "column",
101
- children: () => renderStagesContent(typeof result === "function" ? result() : result, theme, runtime, attention, typeof showDependencies === "function" ? showDependencies() : showDependencies, onStageSelect),
106
+ children: () => renderStagesContent(typeof result === "function" ? result() : result, theme, runtime, attention, typeof showDependencies === "function" ? showDependencies() : showDependencies, onStageSelect, activityFrame),
102
107
  });
103
108
  };
104
109
 
@@ -134,15 +139,40 @@ const disposeRegistration = (registration) => {
134
139
  else registration?.dispose?.();
135
140
  };
136
141
 
137
- export const createStagesTuiController = ({ projectRoot, read = readStagesSnapshot, debounceMs = DEBOUNCE_MS, pollMs = POLL_MS, createSignal: makeSignal = createSignal, attention } = {}) => {
142
+ export const createStagesTuiController = ({ projectRoot, read = readStagesSnapshot, debounceMs = DEBOUNCE_MS, pollMs = POLL_MS, loaderMs = LOADER_MS, loaderClock = globalThis, createSignal: makeSignal = createSignal, attention } = {}) => {
138
143
  const snapshots = new Map();
139
144
  const generations = new Map();
140
145
  const timers = new Map();
141
146
  const pollers = new Map();
142
147
  const [version, setVersion] = makeSignal(0);
143
148
  const [showDependencies, setShowDependencies] = makeSignal(readTuiState(projectRoot).sidebar_dependencies === true);
149
+ let loaderFrame = 0;
150
+ let loaderTimer;
151
+ let visibleSessionId;
144
152
  let disposed = false;
145
- const unsubscribeAttention = attention?.subscribe?.(() => setVersion((value) => value + 1));
153
+ const visibleActivity = () => {
154
+ const result = snapshots.get(visibleSessionId)?.result;
155
+ const workspace = result?.ok && result.data?.workspace;
156
+ return Boolean(workspace && result.data.stages.some((stage) => attention?.activityForStage?.(workspace.id, stage.id)));
157
+ };
158
+ const syncLoader = () => {
159
+ const working = visibleActivity();
160
+ if (working && !loaderTimer && loaderMs) {
161
+ loaderTimer = loaderClock.setInterval(() => {
162
+ loaderFrame = (loaderFrame + 1) % LOADER_FRAMES.length;
163
+ setVersion((value) => value + 1);
164
+ }, loaderMs);
165
+ } else if (!working && loaderTimer) {
166
+ loaderClock.clearInterval(loaderTimer);
167
+ loaderTimer = undefined;
168
+ loaderFrame = 0;
169
+ }
170
+ };
171
+ const unsubscribeAttention = attention?.subscribe?.(() => {
172
+ syncLoader();
173
+ setVersion((value) => value + 1);
174
+ });
175
+ syncLoader();
146
176
 
147
177
  const readSnapshot = async (sessionId) => {
148
178
  if (disposed || !sessionId) return;
@@ -150,6 +180,7 @@ export const createStagesTuiController = ({ projectRoot, read = readStagesSnapsh
150
180
  generations.set(sessionId, currentGeneration);
151
181
  const entry = snapshots.get(sessionId) || { result: null, successful: null };
152
182
  snapshots.set(sessionId, entry);
183
+ syncLoader();
153
184
  setVersion((value) => value + 1);
154
185
  try {
155
186
  const result = await read({ projectRoot, sessionId });
@@ -169,6 +200,7 @@ export const createStagesTuiController = ({ projectRoot, read = readStagesSnapsh
169
200
  : { ok: false, error: { code: error.code || "STORAGE_ERROR", message: error.message } };
170
201
  }
171
202
  snapshots.set(sessionId, entry);
203
+ syncLoader();
172
204
  setVersion((value) => value + 1);
173
205
  };
174
206
 
@@ -189,6 +221,8 @@ export const createStagesTuiController = ({ projectRoot, read = readStagesSnapsh
189
221
 
190
222
  const resultFor = (sessionId) => {
191
223
  version();
224
+ visibleSessionId = sessionId;
225
+ syncLoader();
192
226
  watch(sessionId);
193
227
  const entry = snapshots.get(sessionId);
194
228
  if (!entry) {
@@ -202,6 +236,10 @@ export const createStagesTuiController = ({ projectRoot, read = readStagesSnapsh
202
236
  load: readSnapshot,
203
237
  scheduleRefresh,
204
238
  resultFor,
239
+ activityFrame: () => {
240
+ version();
241
+ return LOADER_FRAMES[loaderFrame];
242
+ },
205
243
  showDependencies,
206
244
  toggleDependencies: () => {
207
245
  const visible = !showDependencies();
@@ -218,6 +256,8 @@ export const createStagesTuiController = ({ projectRoot, read = readStagesSnapsh
218
256
  for (const poller of pollers.values()) clearInterval(poller);
219
257
  pollers.clear();
220
258
  snapshots.clear();
259
+ if (loaderTimer) loaderClock.clearInterval(loaderTimer);
260
+ loaderTimer = undefined;
221
261
  unsubscribeAttention?.();
222
262
  },
223
263
  };
@@ -248,7 +288,7 @@ export const resolveProjectRoot = async (api, { timeoutMs = PATH_TIMEOUT_MS, pol
248
288
 
249
289
  const renderStagesSlot = (controller, theme, sessionId, runtime = defaultRuntime, attention, onStageSelect) => runtime.jsx("box", {
250
290
  flexDirection: "column",
251
- children: renderStagesElement(() => controller.resultFor(sessionId), theme, runtime, attention, controller.showDependencies, onStageSelect),
291
+ children: renderStagesElement(() => controller.resultFor(sessionId), theme, runtime, attention, controller.showDependencies, onStageSelect, controller.activityFrame),
252
292
  });
253
293
 
254
294
  const updateSessionTitle = async (api, projectRoot) => {
@@ -350,6 +390,7 @@ export const tui = async (api, options = {}) => {
350
390
  read: api.stagesSnapshotProvider || readStagesSnapshot,
351
391
  debounceMs: options.debounceMs,
352
392
  pollMs: options.pollMs,
393
+ loaderMs: options.loaderMs,
353
394
  createSignal: options.runtime?.createSignal,
354
395
  attention: api.workContextAttention,
355
396
  });
@@ -359,8 +400,10 @@ export const tui = async (api, options = {}) => {
359
400
  const unregisterDependencyTree = registerDependencyTree(api, controller, () => currentSessionId || ACTIVE_WORKSPACE_SESSION);
360
401
  await controller.load(initialSessionId);
361
402
  let storageWatcher;
403
+ const refreshAttention = () => { void api.workContextAttention?.refresh?.(); };
362
404
  try {
363
405
  storageWatcher = fs.watch(path.join(projectRoot, ".work-context"), { recursive: true }, () => {
406
+ refreshAttention();
364
407
  controller.scheduleRefresh(currentSessionId);
365
408
  });
366
409
  } catch {
@@ -379,10 +422,14 @@ export const tui = async (api, options = {}) => {
379
422
  },
380
423
  });
381
424
  const unsubscribe = api.event?.on?.("session.updated", (event) => {
425
+ refreshAttention();
382
426
  controller.scheduleRefresh(sessionIdFromEvent(event));
383
427
  });
384
428
  const unsubscribeTool = api.event?.on?.("message.part.updated", (event) => {
385
- if (isCompletedWorkContextTool(event)) controller.scheduleRefresh(sessionIdFromEvent(event));
429
+ if (isCompletedWorkContextTool(event)) {
430
+ refreshAttention();
431
+ controller.scheduleRefresh(sessionIdFromEvent(event));
432
+ }
386
433
  });
387
434
 
388
435
  let cleaned = false;
@@ -7,7 +7,7 @@ import { createSignal } from "solid-js";
7
7
  import { openStageSwitcher } from "./stage-switcher.js";
8
8
  import { openWorkspaceSwitcher } from "./workspace-switcher.js";
9
9
  import { openSessionSwitcher } from "./session-switcher.js";
10
- import { attentionForSession, attentionReasonText } from "./attention.js";
10
+ import { attentionForSession, attentionIndicatorText, attentionReasonText } from "./attention.js";
11
11
 
12
12
  const COMMAND_NAME = "work_context.open";
13
13
  const ACTIONS_COMMAND_NAME = "work_context.actions";
@@ -246,7 +246,7 @@ export const renderWorkContextModal = (controller, theme, runtime = { jsx }, { m
246
246
  return runtime.jsx("box", {
247
247
  id: `workspace-${workspace.id}`, flexDirection: "row", gap: 1, children: [
248
248
  line(runtime, index === selectedWorkspaceIndex ? ">" : " ", { flexShrink: 0, marginRight: 1, fg: index === selectedWorkspaceIndex ? theme?.current?.text : muted }),
249
- line(runtime, `${unread ? "[ATTN] " : ""}${workspace.id} ${workspace.title}`, { flexGrow: 1, flexShrink: 1, wrapMode: "word", fg: workspace.id === data?.currentWorkspace ? theme?.current?.warning : theme?.current?.text }),
249
+ line(runtime, `${attentionIndicatorText(unread)} ${workspace.id} ${workspace.title}`.trim(), { flexGrow: 1, flexShrink: 1, wrapMode: "word", fg: workspace.id === data?.currentWorkspace ? theme?.current?.warning : theme?.current?.text }),
250
250
  line(runtime, workspace.status, { flexShrink: 0, fg: muted }),
251
251
  ],
252
252
  });
@@ -256,7 +256,7 @@ export const renderWorkContextModal = (controller, theme, runtime = { jsx }, { m
256
256
  return runtime.jsx("box", {
257
257
  id: `stage-${item.id}`, flexDirection: "row", children: [
258
258
  line(runtime, index === selectedStageIndex ? ">" : " ", { flexShrink: 0, marginRight: 1, fg: index === selectedStageIndex ? theme?.current?.text : muted }),
259
- line(runtime, `${marker(item.status)} ${item.id}. ${item.title}${item.current ? " · current" : ""}${unread ? ` [ATTN: ${attentionReasonText(unread.reason)}${unread.count > 1 ? ` x${unread.count}` : ""}]` : ""}`, { flexGrow: 1, flexShrink: 1, wrapMode: "word", fg: item.current ? theme?.current?.warning : theme?.current?.text }),
259
+ line(runtime, `${marker(item.status)} ${item.id}. ${item.title}${item.current ? " · current" : ""}${unread ? ` ${attentionIndicatorText(unread)}` : ""}`, { flexGrow: 1, flexShrink: 1, wrapMode: "word", fg: item.current ? theme?.current?.warning : theme?.current?.text }),
260
260
  ],
261
261
  });
262
262
  }) : [];
@@ -291,7 +291,7 @@ export const renderWorkContextModal = (controller, theme, runtime = { jsx }, { m
291
291
  line(runtime, `Sessions ${(selected.sessions || []).length}`, { fg: muted }),
292
292
  ...(selected.sessions || []).map((session) => {
293
293
  const unread = controller.attention?.attentionFor?.(session.opencode_session_id);
294
- return line(runtime, `${unread ? `[ATTN: ${attentionReasonText(unread.reason)}] ` : ""}${session.state || "unknown"} ${session.session_id || "unknown"} stage ${session.stage || "-"}`, { wrapMode: "word", fg: muted });
294
+ return line(runtime, `${unread ? `${attentionIndicatorText(unread)} ` : ""}${session.state || "unknown"} ${session.session_id || "unknown"} stage ${session.stage || "-"}`, { wrapMode: "word", fg: muted });
295
295
  }),
296
296
  ] : []),
297
297
  ] }),
@@ -438,7 +438,7 @@ export const createWorkContextActionFlow = (api, { projectRoot, sessionId, read
438
438
  });
439
439
  const options = workspaces.flatMap((workspace) => {
440
440
  const unread = api.workContextAttention?.attentionForWorkspace?.(workspace.id);
441
- const category = `${unread ? "[ATTN] " : ""}${workspace.id} · ${workspace.title} · ${workspace.status}`;
441
+ const category = `${attentionIndicatorText(unread)} ${workspace.id} · ${workspace.title} · ${workspace.status}`.trim();
442
442
  return [
443
443
  { title: "Overview", description: workspace.status, footer: progress(workspace), category, value: { type: "workspace", workspace } },
444
444
  ...(workspace.stages || []).map((stage) => ({
@@ -474,7 +474,7 @@ export const createWorkContextActionFlow = (api, { projectRoot, sessionId, read
474
474
  showSelect("Stages", entries.map(({ workspace, stage }) => {
475
475
  const unread = api.workContextAttention?.attentionForStage?.(workspace.id, stage.id);
476
476
  return {
477
- title: `${marker(stage.status)} ${unread ? "[ATTN] " : ""}${workspace.id}/${stage.id} ${stage.title} · ${workspace.title}`,
477
+ title: `${marker(stage.status)} ${attentionIndicatorText(unread)} ${workspace.id}/${stage.id} ${stage.title} · ${workspace.title}`.replace(/ +/g, " "),
478
478
  description: unread ? `Needs attention: ${attentionReasonText(unread.reason)} (${unread.count}) · ${stage.description || stage.status}` : stage.description || stage.status,
479
479
  category: stage.current ? "Current" : labels[stage.status] || stage.status,
480
480
  value: { workspace, stage },
@@ -525,7 +525,7 @@ export const createWorkContextActionFlow = (api, { projectRoot, sessionId, read
525
525
  const current = session.opencode_session_id === sessionId || session.session_id === sessionId;
526
526
  const unread = attentionForSession(api, session.opencode_session_id);
527
527
  return {
528
- title: `${unread ? "[ATTN] " : ""}${workspace.id} ${sessionOrdinal(session)} ${session.summary || "Work session"} · ${workspace.title}`,
528
+ title: `${attentionIndicatorText(unread)} ${workspace.id} ${sessionOrdinal(session)} ${session.summary || "Work session"} · ${workspace.title}`.trim(),
529
529
  description: `${unread ? `needs attention: ${attentionReasonText(unread.reason)} · ` : ""}${session.state || "unknown"} · ${session.session_id}`,
530
530
  footer: session.updated_at || session.started_at,
531
531
  category: current ? "Current" : labels[session.state] || session.state || "Unknown",
@@ -1,5 +1,5 @@
1
1
  import { readWorkContextSnapshot } from "../src/work-context-snapshot.js";
2
- import { acknowledgeNavigation, attentionForSession, attentionReasonText } from "./attention.js";
2
+ import { acknowledgeNavigation, attentionForSession, attentionIndicatorText, attentionReasonText } from "./attention.js";
3
3
 
4
4
  const SESSION_STATE_RANK = { active: 0, handed_off: 1, abandoned: 2, closed: 3 };
5
5
  const WORKSPACE_STATUS_RANK = { in_progress: 0, planned: 1, completed: 2, cancelled: 3 };
@@ -69,7 +69,7 @@ export const createWorkspaceSwitcherFlow = (api, { read = readWorkContextSnapsho
69
69
  title: "Switch workspace",
70
70
  placeholder: "Search workspaces",
71
71
  options: workspaces.map((workspace) => ({
72
- title: `${workspace.attention ? "[ATTN] " : ""}${workspace.id} ${workspace.title}${workspace.id === data.currentWorkspace ? " · current" : ""}`,
72
+ title: `${attentionIndicatorText(workspace.attention)} ${workspace.id} ${workspace.title}${workspace.id === data.currentWorkspace ? " · current" : ""}`.trim(),
73
73
  description: workspace.selectedSession
74
74
  ? `${workspace.attention ? `needs attention: ${attentionReasonText(workspace.attention.reason)} (${workspace.attention.count}) · ` : ""}${workspace.status} · ${workspace.selectedSession.state || "unknown"} session`
75
75
  : `${workspace.status} · no OpenCode session available`,