opencode-work-context 0.4.8 → 0.4.10

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
@@ -283,8 +283,11 @@ On Linux notification servers that support actions, `Open session` routes the
283
283
  originating OpenCode process to the affected native session. If that process
284
284
  runs in tmux, its validated `TMUX_PANE` is selected with fixed `tmux` arguments.
285
285
  On X11, the loader records the active window with `xprop` and raises it with
286
- `wmctrl` when those optional tools are available. Each step is independent and
287
- best-effort: navigation can still succeed if pane or window activation fails.
286
+ `wmctrl` when those optional tools are available. Pane/window activation happens
287
+ before session navigation so a hidden TUI can process the route change. Attention
288
+ is acknowledged only after the destination route is verified; failed navigation
289
+ leaves it unread and shows an in-TUI warning. Each activation step is independent
290
+ and best-effort: navigation can still succeed if pane or window activation fails.
288
291
  Wayland focus restrictions and terminal tabs without a public activation API
289
292
  may require the user to foreground the terminal manually. Session and window
290
293
  identifiers never appear in notification text or configurable commands.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "opencode-work-context",
3
3
  "type": "module",
4
- "version": "0.4.8",
4
+ "version": "0.4.10",
5
5
  "description": "Filesystem work-context core and OpenCode adapter",
6
6
  "license": "MIT",
7
7
  "author": {
@@ -2,6 +2,10 @@ import { spawn as nodeSpawn } from "node:child_process";
2
2
 
3
3
  const WINDOW_ID = /^0x[0-9a-f]+$/i;
4
4
  const MAX_OUTPUT = 128;
5
+ const routeSessionId = (api) => api?.route?.current?.name === "session"
6
+ ? api.route.current.params?.sessionID || api.route.current.params?.sessionId || api.route.current.params?.session_id || null
7
+ : null;
8
+ const wait = (delayMs) => new Promise((resolve) => setTimeout(resolve, delayMs));
5
9
 
6
10
  const run = ({ executable, args, spawn, timeoutMs, capture = false, children }) => new Promise((resolve) => {
7
11
  let child;
@@ -69,6 +73,8 @@ export const createAttentionActivator = ({
69
73
  timeoutMs = 1000,
70
74
  captureThrottleMs = 1000,
71
75
  navigationTimeoutMs = 2000,
76
+ routeVerificationMs = 500,
77
+ activationDelayMs = 50,
72
78
  now = () => Date.now(),
73
79
  } = {}) => {
74
80
  const paneId = env.TMUX && /^%\d+$/.test(env.TMUX_PANE || "") ? env.TMUX_PANE : null;
@@ -122,22 +128,40 @@ export const createAttentionActivator = ({
122
128
  }
123
129
  };
124
130
 
131
+ const verifyRoute = async (sessionId) => {
132
+ if (!("current" in (api?.route || {})) || disposed) return false;
133
+ const deadline = Date.now() + routeVerificationMs;
134
+ do {
135
+ if (!disposed && routeSessionId(api) === sessionId) return true;
136
+ if (routeVerificationMs <= 0) break;
137
+ await wait(Math.min(25, Math.max(1, deadline - Date.now())));
138
+ } while (!disposed && Date.now() < deadline);
139
+ return !disposed && routeSessionId(api) === sessionId;
140
+ };
141
+
125
142
  const activate = async (sessionId) => {
126
- if (disposed || typeof sessionId !== "string" || !sessionId || sessionId.length > 256) return false;
127
- let activated = await navigate(sessionId);
128
- if (disposed) return activated;
143
+ if (disposed || typeof sessionId !== "string" || !sessionId || sessionId.length > 256) {
144
+ return { ok: false, activated: false, navigated: false, verified: false };
145
+ }
146
+ let activated = false;
129
147
  if (paneId) {
130
148
  const selectedWindow = await run({ executable: "tmux", args: ["select-window", "-t", paneId], spawn, timeoutMs, children });
131
- if (disposed) return activated;
149
+ if (disposed) return { ok: false, activated, navigated: false, verified: false };
132
150
  const selectedPane = await run({ executable: "tmux", args: ["select-pane", "-t", paneId], spawn, timeoutMs, children });
133
- activated = selectedWindow.ok && selectedPane.ok || activated;
151
+ activated = selectedWindow.ok && selectedPane.ok;
134
152
  }
135
- if (disposed) return activated;
153
+ if (disposed) return { ok: false, activated, navigated: false, verified: false };
136
154
  if (windowId && canCaptureWindow) {
137
155
  const raised = await run({ executable: "wmctrl", args: ["-ia", windowId], spawn, timeoutMs, children });
138
156
  activated = raised.ok || activated;
139
157
  }
140
- return activated;
158
+ if (disposed) return { ok: false, activated, navigated: false, verified: false };
159
+ if (activated && activationDelayMs > 0) await wait(activationDelayMs);
160
+ if (disposed) return { ok: false, activated, navigated: false, verified: false };
161
+ const navigated = await navigate(sessionId);
162
+ if (disposed) return { ok: false, activated, navigated, verified: false };
163
+ const verified = navigated && await verifyRoute(sessionId);
164
+ return { ok: verified, activated, navigated, verified };
141
165
  };
142
166
 
143
167
  return {
@@ -86,6 +86,49 @@ export const acknowledgeNavigation = (api, sessionId, observedEventKey) => {
86
86
  if (!sessionId || !observedEventKey) return false;
87
87
  return api?.workContextAttention?.acknowledge?.(sessionId, observedEventKey) === true;
88
88
  };
89
+ export const createPendingNavigationTracker = () => {
90
+ const counts = new Map();
91
+ let total = 0;
92
+ return {
93
+ set(sessionId, pending) {
94
+ if (!sessionId) return;
95
+ const current = counts.get(sessionId) || 0;
96
+ if (pending) {
97
+ counts.set(sessionId, current + 1);
98
+ total += 1;
99
+ } else if (current > 0) {
100
+ if (current === 1) counts.delete(sessionId);
101
+ else counts.set(sessionId, current - 1);
102
+ total -= 1;
103
+ }
104
+ },
105
+ hasAny: () => total > 0,
106
+ has: (sessionId) => (counts.get(sessionId) || 0) > 0,
107
+ };
108
+ };
109
+ export const openAttentionDestination = async ({ api, activator, controller, sessionId, eventKey, setNavigationPending } = {}) => {
110
+ try { setNavigationPending?.(sessionId, true); } catch {}
111
+ try {
112
+ let result;
113
+ try { result = await activator?.activate?.(sessionId); } catch { result = null; }
114
+ const opened = result?.ok === true && result?.verified === true;
115
+ if (opened) {
116
+ controller?.acknowledge?.(sessionId, eventKey);
117
+ return true;
118
+ }
119
+ try {
120
+ api?.ui?.toast?.({
121
+ title: "Work Context",
122
+ message: "The target session could not be opened. Attention remains unread.",
123
+ variant: "warning",
124
+ duration: 5000,
125
+ });
126
+ } catch {}
127
+ return false;
128
+ } finally {
129
+ try { setNavigationPending?.(sessionId, false); } catch {}
130
+ }
131
+ };
89
132
 
90
133
  const validAttention = (value) => value
91
134
  && typeof value === "object"
@@ -260,7 +303,7 @@ export const desktopNotificationsEnabled = (projectRoot) => {
260
303
  try { return loadConfig(projectRoot).notifications?.desktop !== false; } catch { return false; }
261
304
  };
262
305
 
263
- export const createAttentionTuiController = ({ api, projectRoot, read = readWorkContextSnapshot, onAttention, isFocused = () => true, now } = {}) => {
306
+ export const createAttentionTuiController = ({ api, projectRoot, read = readWorkContextSnapshot, onAttention, isFocused = () => true, shouldAcknowledge = () => true, now } = {}) => {
264
307
  const persisted = readTuiState(projectRoot).attention;
265
308
  const engine = createAttentionEngine({
266
309
  persisted,
@@ -271,6 +314,10 @@ export const createAttentionTuiController = ({ api, projectRoot, read = readWork
271
314
  let snapshot = null;
272
315
  let disposed = false;
273
316
  let pending = Promise.resolve();
317
+ const acknowledgeObserved = (sessionId) => {
318
+ const observedEventKey = engine.attentionFor(sessionId)?.eventKey;
319
+ return observedEventKey ? engine.acknowledge(sessionId, observedEventKey) : false;
320
+ };
274
321
  const refresh = async () => {
275
322
  try {
276
323
  const result = await read({ projectRoot, sessionId: currentSessionId(api) });
@@ -278,7 +325,7 @@ export const createAttentionTuiController = ({ api, projectRoot, read = readWork
278
325
  linked = linkedSessionIds(result);
279
326
  snapshot = result.data;
280
327
  const current = currentSessionId(api);
281
- if (isFocused() !== false && current && linked.has(current)) engine.acknowledge(current);
328
+ if (isFocused() !== false && current && linked.has(current) && shouldAcknowledge(current) !== false) acknowledgeObserved(current);
282
329
  }
283
330
  } catch {}
284
331
  return linked;
@@ -290,7 +337,7 @@ export const createAttentionTuiController = ({ api, projectRoot, read = readWork
290
337
  await refresh();
291
338
  if (!linked.has(sessionId)) return { changed: false, unlinked: true };
292
339
  const foreground = isFocused() !== false ? currentSessionId(api) : undefined;
293
- if (foreground === sessionId) engine.acknowledge(sessionId);
340
+ if (foreground === sessionId && shouldAcknowledge(sessionId) !== false) acknowledgeObserved(sessionId);
294
341
  const result = engine.apply(event, { foreground });
295
342
  if (result.changed) onAttention?.({
296
343
  sessionId,
@@ -306,7 +353,7 @@ export const createAttentionTuiController = ({ api, projectRoot, read = readWork
306
353
  pending = result.catch(() => {});
307
354
  return result;
308
355
  };
309
- const acknowledge = (sessionId, observedEventKey) => engine.acknowledge(sessionId, observedEventKey);
356
+ const acknowledge = (sessionId, observedEventKey) => disposed ? false : engine.acknowledge(sessionId, observedEventKey);
310
357
  const aggregate = (matches) => {
311
358
  const bySession = new Map();
312
359
  const current = currentSessionId(api);
@@ -346,6 +393,8 @@ export const tui = async (api, options = {}) => {
346
393
  const activator = options.attentionActivator
347
394
  || (typeof api.route?.navigate === "function" ? createAttentionActivator({ api, ...options.activatorOptions }) : null);
348
395
  let controller;
396
+ const notificationNavigations = createPendingNavigationTracker();
397
+ const setNavigationPending = (sessionId, pending) => notificationNavigations.set(sessionId, pending);
349
398
  const globalChannel = options.globalAttentionChannel === false
350
399
  ? null
351
400
  : options.globalAttentionChannel || (typeof api.ui?.toast === "function" ? createGlobalAttentionChannel(options.globalAttentionOptions) : null);
@@ -361,7 +410,8 @@ export const tui = async (api, options = {}) => {
361
410
  globalChannel?.activity?.();
362
411
  void activator?.capture?.();
363
412
  const sessionId = currentSessionId(api);
364
- if (sessionId) controller?.acknowledge(sessionId);
413
+ const observedEventKey = sessionId && !notificationNavigations.hasAny() ? controller?.attentionFor(sessionId)?.eventKey : null;
414
+ if (observedEventKey) controller?.acknowledge(sessionId, observedEventKey);
365
415
  },
366
416
  onBlur: () => {
367
417
  globalChannel?.deactivate?.();
@@ -375,6 +425,7 @@ export const tui = async (api, options = {}) => {
375
425
  isFocused: options.isTuiFocused || (globalDelivery
376
426
  ? () => globalChannel.hasActiveInstance() ? globalChannel.isActive() && focus.isFocused() : focus.isFocused()
377
427
  : () => focus.isFocused()),
428
+ shouldAcknowledge: () => !notificationNavigations.hasAny(),
378
429
  onAttention: (change) => {
379
430
  try { options.onAttention?.(change); } catch {}
380
431
  const context = change.contexts?.[0];
@@ -386,7 +437,14 @@ export const tui = async (api, options = {}) => {
386
437
  workspaceTitle: context.workspaceTitle,
387
438
  stageTitle: context.stageTitle,
388
439
  });
389
- const onOpen = activator?.available ? () => activator.activate(change.sessionId) : undefined;
440
+ const onOpen = activator?.available ? () => openAttentionDestination({
441
+ api,
442
+ activator,
443
+ controller,
444
+ sessionId: change.sessionId,
445
+ eventKey: change.attention.eventKey,
446
+ setNavigationPending,
447
+ }) : undefined;
390
448
  void Promise.resolve(desktopNotifier.notify(context, { onOpen })).catch(() => {});
391
449
  },
392
450
  now: options.now,
@@ -396,7 +454,8 @@ export const tui = async (api, options = {}) => {
396
454
  registrations.push(api.event.on("tui.session.select", (event) => {
397
455
  queueMicrotask(() => {
398
456
  const sessionId = currentSessionId(api);
399
- if (sessionId) controller.acknowledge(sessionId);
457
+ const observedEventKey = sessionId && !notificationNavigations.hasAny() ? controller.attentionFor(sessionId)?.eventKey : null;
458
+ if (observedEventKey) controller.acknowledge(sessionId, observedEventKey);
400
459
  });
401
460
  }));
402
461
  let cleaned = false;
@@ -1,10 +1,11 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
3
  import { readStagesSnapshot } from "../src/stages-snapshot.js";
4
- import { renderStagesPanel } from "../src/stages-renderer.js";
4
+ import { renderDependencyTree, renderStagesPanel } from "../src/stages-renderer.js";
5
5
  import { jsx } from "@opentui/solid/jsx-runtime";
6
6
  import { createSignal } from "solid-js";
7
7
  import { attentionReasonText } from "./attention.js";
8
+ import { readTuiState, updateTuiState } from "./tui-state.js";
8
9
 
9
10
  const DEBOUNCE_MS = 150;
10
11
  const POLL_MS = 1000;
@@ -13,6 +14,10 @@ const PATH_POLL_MS = 25;
13
14
  const WORK_CONTEXT_PREFIX = "work" + "_" + "context_";
14
15
  const activeTuiInstances = new WeakMap();
15
16
  const ACTIVE_TUI_KEY = Symbol.for("opencode-work-context.stages-tui");
17
+ const DEPENDENCIES_COMMAND = "work_context.toggle_dependencies";
18
+ const DEPENDENCIES_SHORTCUT = "<leader>d";
19
+ const TREE_COMMAND = "work_context.show_dependency_tree";
20
+ const TREE_SHORTCUT = "<leader>t";
16
21
  const statusMarker = (status) => ({
17
22
  planned: "[ ]",
18
23
  in_progress: "[•]",
@@ -25,7 +30,7 @@ export { readStagesSnapshot, renderStagesPanel };
25
30
 
26
31
  const defaultRuntime = { jsx };
27
32
 
28
- const renderStagesContent = (result, theme, runtime = defaultRuntime, attention) => !result?.ok || !result.data?.workspace
33
+ const renderStagesContent = (result, theme, runtime = defaultRuntime, attention, showDependencies = true) => !result?.ok || !result.data?.workspace
29
34
  ? [
30
35
  runtime.jsx("text", { children: runtime.jsx("b", { children: "Stages" }) }),
31
36
  ...renderStagesPanel(result).split("\n").slice(1).map((line) => runtime.jsx("text", { children: line })),
@@ -48,16 +53,16 @@ const renderStagesContent = (result, theme, runtime = defaultRuntime, attention)
48
53
  flexDirection: "row",
49
54
  children: [
50
55
  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) }),
51
- runtime.jsx("text", { flexGrow: 1, flexShrink: 1, wrapMode: "word", fg: stage.current || stage.id === result.data.currentStage ? theme?.current?.warning : theme?.current?.textMuted, children: `${stage.id}. ${stage.title}${unread ? ` [ATTN: ${attentionReasonText(unread.reason)}${unread.count > 1 ? ` x${unread.count}` : ""}]` : ""}` }),
56
+ runtime.jsx("text", { flexGrow: 1, flexShrink: 1, wrapMode: "word", fg: stage.current || stage.id === result.data.currentStage ? theme?.current?.warning : theme?.current?.textMuted, children: `${stage.id}. ${stage.title}${showDependencies && stage.depends_on?.length ? `\nDeps: ${stage.depends_on.join(", ")}` : ""}${unread ? ` [ATTN: ${attentionReasonText(unread.reason)}${unread.count > 1 ? ` x${unread.count}` : ""}]` : ""}` }),
52
57
  ],
53
58
  });
54
59
  }),
55
60
  ];
56
61
 
57
- export const renderStagesElement = (result, theme, runtime = defaultRuntime, attention) => {
62
+ export const renderStagesElement = (result, theme, runtime = defaultRuntime, attention, showDependencies = true) => {
58
63
  return runtime.jsx("box", {
59
- flexDirection: "column",
60
- children: () => renderStagesContent(typeof result === "function" ? result() : result, theme, runtime, attention),
64
+ flexDirection: "column",
65
+ children: () => renderStagesContent(typeof result === "function" ? result() : result, theme, runtime, attention, typeof showDependencies === "function" ? showDependencies() : showDependencies),
61
66
  });
62
67
  };
63
68
 
@@ -99,6 +104,7 @@ export const createStagesTuiController = ({ projectRoot, read = readStagesSnapsh
99
104
  const timers = new Map();
100
105
  const pollers = new Map();
101
106
  const [version, setVersion] = makeSignal(0);
107
+ const [showDependencies, setShowDependencies] = makeSignal(readTuiState(projectRoot).sidebar_dependencies === true);
102
108
  let disposed = false;
103
109
  const unsubscribeAttention = attention?.subscribe?.(() => setVersion((value) => value + 1));
104
110
 
@@ -160,6 +166,13 @@ export const createStagesTuiController = ({ projectRoot, read = readStagesSnapsh
160
166
  load: readSnapshot,
161
167
  scheduleRefresh,
162
168
  resultFor,
169
+ showDependencies,
170
+ toggleDependencies: () => {
171
+ const visible = !showDependencies();
172
+ setShowDependencies(visible);
173
+ updateTuiState(projectRoot, (state) => ({ ...state, sidebar_dependencies: visible }));
174
+ return visible;
175
+ },
163
176
  dispose: () => {
164
177
  if (disposed) return;
165
178
  disposed = true;
@@ -199,9 +212,72 @@ export const resolveProjectRoot = async (api, { timeoutMs = PATH_TIMEOUT_MS, pol
199
212
 
200
213
  const renderStagesSlot = (controller, theme, sessionId, runtime = defaultRuntime, attention) => runtime.jsx("box", {
201
214
  flexDirection: "column",
202
- children: renderStagesElement(() => controller.resultFor(sessionId), theme, runtime, attention),
215
+ children: renderStagesElement(() => controller.resultFor(sessionId), theme, runtime, attention, controller.showDependencies),
203
216
  });
204
217
 
218
+ const registerDependencyToggle = (api, controller) => {
219
+ if (typeof api?.keymap?.registerLayer !== "function") return () => {};
220
+ const command = {
221
+ name: DEPENDENCIES_COMMAND,
222
+ title: "Toggle sidebar dependencies",
223
+ desc: "Show or hide dependency IDs in the stages sidebar",
224
+ category: "Work Context",
225
+ namespace: "palette",
226
+ run: () => controller.toggleDependencies(),
227
+ };
228
+ return api.keymap.registerLayer({
229
+ commands: [command],
230
+ bindings: [{ key: DEPENDENCIES_SHORTCUT, cmd: DEPENDENCIES_COMMAND, desc: command.title }],
231
+ });
232
+ };
233
+
234
+ export const dependencyTreeOptions = (stages, width = 80) => {
235
+ const narrow = width < 50;
236
+ const tree = renderDependencyTree(stages, {
237
+ compact: narrow,
238
+ maxTitleLength: narrow ? Math.max(12, width - 18) : undefined,
239
+ });
240
+ return [
241
+ { title: "Close", value: "close", category: "Dependency tree" },
242
+ ...tree.split("\n").map((line) => ({ title: line, value: line, category: "Dependency tree" })),
243
+ ];
244
+ };
245
+
246
+ export const openDependencyTreeDialog = (api, result) => {
247
+ if (typeof api?.ui?.DialogSelect !== "function" || typeof api?.ui?.dialog?.replace !== "function") return false;
248
+ if (!result?.ok || !result.data?.workspace) {
249
+ api.ui?.toast?.({ message: "No work-context stages are available", variant: "warning" });
250
+ return false;
251
+ }
252
+ const width = api.renderer?.width || 80;
253
+ api.ui.dialog.setSize?.(width < 50 ? "small" : "large");
254
+ api.ui.dialog.replace(() => api.ui.DialogSelect({
255
+ title: `Dependency tree · ${result.data.workspace.title}`,
256
+ placeholder: "Dependency tree",
257
+ options: dependencyTreeOptions(result.data.stages, width),
258
+ onSelect: (option) => {
259
+ if (option.value === "close") api.ui.dialog.clear?.();
260
+ },
261
+ }));
262
+ return true;
263
+ };
264
+
265
+ const registerDependencyTree = (api, controller, sessionId) => {
266
+ if (typeof api?.keymap?.registerLayer !== "function") return () => {};
267
+ const command = {
268
+ name: TREE_COMMAND,
269
+ title: "Show dependency tree",
270
+ desc: "Open the full work-context dependency tree",
271
+ category: "Work Context",
272
+ namespace: "palette",
273
+ run: () => openDependencyTreeDialog(api, controller.resultFor(sessionId())),
274
+ };
275
+ return api.keymap.registerLayer({
276
+ commands: [command],
277
+ bindings: [{ key: TREE_SHORTCUT, cmd: TREE_COMMAND, desc: command.title }],
278
+ });
279
+ };
280
+
205
281
  const ACTIVE_WORKSPACE_SESSION = "__active_" + "work" + "_context_workspace__";
206
282
 
207
283
  // Optional TUI entry point. It is deliberately not imported by the server plugin.
@@ -223,8 +299,10 @@ export const tui = async (api, options = {}) => {
223
299
  createSignal: options.runtime?.createSignal,
224
300
  attention: api.workContextAttention,
225
301
  });
226
- await controller.load(initialSessionId);
302
+ const unregisterDependencyToggle = registerDependencyToggle(api, controller);
227
303
  let currentSessionId = initialSessionId;
304
+ const unregisterDependencyTree = registerDependencyTree(api, controller, () => currentSessionId || ACTIVE_WORKSPACE_SESSION);
305
+ await controller.load(initialSessionId);
228
306
  let storageWatcher;
229
307
  try {
230
308
  storageWatcher = fs.watch(path.join(projectRoot, ".work-context"), { recursive: true }, () => {
@@ -263,6 +341,8 @@ export const tui = async (api, options = {}) => {
263
341
  disposeRegistration(unsubscribe);
264
342
  disposeRegistration(unsubscribeTool);
265
343
  disposeRegistration(unregisterSlot);
344
+ disposeRegistration(unregisterDependencyToggle);
345
+ disposeRegistration(unregisterDependencyTree);
266
346
  };
267
347
  api[ACTIVE_TUI_KEY] = cleanup;
268
348
  activeTuiInstances.set(api, cleanup);
@@ -6,6 +6,49 @@ const statusMarker = (status) => ({
6
6
  archived: "[-]",
7
7
  }[status] || "[?]");
8
8
 
9
+ const compareStageIds = (left, right) => Number(left.id) - Number(right.id);
10
+
11
+ /**
12
+ * Render normalized stages as a dependency-to-dependent forest. A stage may
13
+ * appear more than once when multiple dependency paths reach the same join.
14
+ */
15
+ export function renderDependencyTree(stages, { compact = false, maxTitleLength } = {}) {
16
+ const sortedStages = [...stages].sort(compareStageIds);
17
+ const byId = new Map(sortedStages.map((stage) => [stage.id, stage]));
18
+ const dependents = new Map(sortedStages.map((stage) => [stage.id, []]));
19
+
20
+ for (const stage of sortedStages) {
21
+ for (const dependency of stage.depends_on || []) {
22
+ dependents.get(dependency)?.push(stage);
23
+ }
24
+ }
25
+ for (const children of dependents.values()) children.sort(compareStageIds);
26
+
27
+ const roots = sortedStages.filter((stage) => !(stage.depends_on || []).some((dependency) => byId.has(dependency)));
28
+ const lines = [];
29
+ const branchCharacters = compact
30
+ ? { tee: "+- ", last: "\\- ", vertical: "| ", space: " " }
31
+ : { tee: "├─ ", last: "└─ ", vertical: "│ ", space: " " };
32
+ const stageTitle = (title) => maxTitleLength && title.length > maxTitleLength
33
+ ? `${title.slice(0, Math.max(1, maxTitleLength - 3))}...`
34
+ : title;
35
+ const render = (stage, prefix, branch, ancestors) => {
36
+ const cycle = ancestors.has(stage.id);
37
+ lines.push(`${prefix}${branch}${statusMarker(stage.status)} ${stage.id}. ${stageTitle(stage.title)}${cycle ? " [cycle]" : ""}`);
38
+ if (cycle) return;
39
+
40
+ const children = dependents.get(stage.id) || [];
41
+ const nextAncestors = new Set(ancestors).add(stage.id);
42
+ children.forEach((child, index) => {
43
+ const last = index === children.length - 1;
44
+ render(child, `${prefix}${branch ? (branch === branchCharacters.last ? branchCharacters.space : branchCharacters.vertical) : ""}`, last ? branchCharacters.last : branchCharacters.tee, nextAncestors);
45
+ });
46
+ };
47
+
48
+ for (const root of roots.length ? roots : sortedStages.slice(0, 1)) render(root, "", "", new Set());
49
+ return lines.join("\n");
50
+ }
51
+
9
52
  export function renderStagesPanel(result) {
10
53
  if (!result?.ok) return `work-context stages\n! unavailable: ${result?.error?.code || "STORAGE_ERROR"}`;
11
54
  const snapshot = result.data;
@@ -17,7 +60,7 @@ export function renderStagesPanel(result) {
17
60
  `Stages · ${snapshot.workspace.status}`,
18
61
  ];
19
62
  for (const stage of snapshot.stages) {
20
- lines.push(`${statusMarker(stage.status)} ${stage.id}. ${stage.title}`);
63
+ lines.push(`${statusMarker(stage.status)} ${stage.id}. ${stage.title}${stage.depends_on?.length ? `\nDeps: ${stage.depends_on.join(", ")}` : ""}`);
21
64
  }
22
65
  if (result.stale) lines.push(`! stale: ${result.error?.code || "STORAGE_ERROR"}`);
23
66
  return lines.join("\n");
@@ -42,6 +42,7 @@ export function readStagesSnapshot({ projectRoot, sessionId }) {
42
42
  title: stage.title,
43
43
  status: stage.status,
44
44
  description: stage.description,
45
+ depends_on: stage.depends_on,
45
46
  current: stage.stage === session.stage,
46
47
  }));
47
48
  const currentStage = stages.some((stage) => stage.current) ? session.stage : null;
@@ -43,6 +43,7 @@ const readWorkspace = (context, record, currentSession) => {
43
43
  title: stage.title,
44
44
  status: stage.status,
45
45
  description: stage.description,
46
+ depends_on: stage.depends_on,
46
47
  current: stage.stage === currentStage,
47
48
  })),
48
49
  currentStage,