opencode-work-context 0.4.10 → 0.4.12

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "opencode-work-context",
3
3
  "type": "module",
4
- "version": "0.4.10",
4
+ "version": "0.4.12",
5
5
  "description": "Filesystem work-context core and OpenCode adapter",
6
6
  "license": "MIT",
7
7
  "author": {
@@ -163,6 +163,30 @@ export const switchToStage = async (api, stage, options = {}) => {
163
163
 
164
164
  export const createStageSwitcherFlow = (api, { read = readStageSwitcherSnapshot, start = startStageSession } = {}) => {
165
165
  const toast = (message, variant = "warning") => api?.ui?.toast?.({ message, variant });
166
+ const select = async (stageId) => {
167
+ let result;
168
+ try { result = await read({ projectRoot: projectRoot(api), sessionId: currentSessionId(api) }); }
169
+ catch (error) { result = errorResult(error.code || "STORAGE_ERROR", error.message || "Cannot read work-context storage"); }
170
+ if (!result?.ok) {
171
+ toast(`${result?.error?.code || "STORAGE_ERROR"}: ${result?.error?.message || "Cannot read work-context storage"}`, "error");
172
+ return result;
173
+ }
174
+ const stage = result.data.stages.find((item) => item.id === stageId);
175
+ if (!stage) {
176
+ const missing = errorResult("NOT_FOUND", "The selected work-context stage no longer exists");
177
+ toast(`${missing.error.code}: ${missing.error.message}`, "error");
178
+ return missing;
179
+ }
180
+ const selected = {
181
+ ...stage,
182
+ attention: api.workContextAttention?.attentionForStage?.(result.data.workspace.id, stage.id),
183
+ selectedSession: selectStageSession(stage.sessions, (id) => attentionForSession(api, id)),
184
+ };
185
+ const switched = await switchToStage(api, selected, { workspace: result.data.workspace.id, currentStage: result.data.currentStage, start });
186
+ if (!switched.ok) toast(`${switched.error.code}: ${switched.error.message}`, "error");
187
+ else toast(switched.data.created ? "Stage session created" : "Stage session opened", "success");
188
+ return switched;
189
+ };
166
190
  const open = async () => {
167
191
  let result;
168
192
  try { result = await read({ projectRoot: projectRoot(api), sessionId: currentSessionId(api) }); }
@@ -201,14 +225,12 @@ export const createStageSwitcherFlow = (api, { read = readStageSwitcherSnapshot,
201
225
  ...ordinary.map((stage) => optionFor(stage, stage.status)),
202
226
  ],
203
227
  onSelect: (option) => void (async () => {
204
- const switched = await switchToStage(api, option.value, { workspace: workspace.id, currentStage: result.data.currentStage, start });
205
- if (!switched.ok) toast(`${switched.error.code}: ${switched.error.message}`, "error");
206
- else toast(switched.data.created ? "Stage session created" : "Stage session opened", "success");
228
+ await select(option.value.id);
207
229
  })(),
208
230
  }));
209
231
  return result;
210
232
  };
211
- return { open };
233
+ return { open, select };
212
234
  };
213
235
 
214
236
  export const openStageSwitcher = (api, options = {}) => {
@@ -5,6 +5,7 @@ import { renderDependencyTree, renderStagesPanel } from "../src/stages-renderer.
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 { createStageSwitcherFlow } from "./stage-switcher.js";
8
9
  import { readTuiState, updateTuiState } from "./tui-state.js";
9
10
 
10
11
  const DEBOUNCE_MS = 150;
@@ -29,8 +30,14 @@ const statusMarker = (status) => ({
29
30
  export { readStagesSnapshot, renderStagesPanel };
30
31
 
31
32
  const defaultRuntime = { jsx };
33
+ const renderAttentionText = (value, runtime) => {
34
+ const parts = value.split(/(\[ATTN[^\]]*\])/g);
35
+ return parts.length === 1 ? value : parts.filter(Boolean).map((part) => part.startsWith("[ATTN")
36
+ ? runtime.jsx("b", { children: part })
37
+ : part);
38
+ };
32
39
 
33
- const renderStagesContent = (result, theme, runtime = defaultRuntime, attention, showDependencies = true) => !result?.ok || !result.data?.workspace
40
+ const renderStagesContent = (result, theme, runtime = defaultRuntime, attention, showDependencies = true, onStageSelect) => !result?.ok || !result.data?.workspace
34
41
  ? [
35
42
  runtime.jsx("text", { children: runtime.jsx("b", { children: "Stages" }) }),
36
43
  ...renderStagesPanel(result).split("\n").slice(1).map((line) => runtime.jsx("text", { children: line })),
@@ -49,20 +56,25 @@ const renderStagesContent = (result, theme, runtime = defaultRuntime, attention,
49
56
  }),
50
57
  ...result.data.stages.map((stage) => {
51
58
  const unread = attention?.attentionForStage?.(result.data.workspace.id, stage.id);
59
+ const stageText = `${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
60
  return runtime.jsx("box", {
53
61
  flexDirection: "row",
62
+ onMouseDown: (event) => {
63
+ if (event?.button != null && event.button !== 0) return;
64
+ return onStageSelect?.(stage);
65
+ },
54
66
  children: [
55
67
  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) }),
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}` : ""}]` : ""}` }),
68
+ 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) }),
57
69
  ],
58
70
  });
59
71
  }),
60
72
  ];
61
73
 
62
- export const renderStagesElement = (result, theme, runtime = defaultRuntime, attention, showDependencies = true) => {
74
+ export const renderStagesElement = (result, theme, runtime = defaultRuntime, attention, showDependencies = true, onStageSelect) => {
63
75
  return runtime.jsx("box", {
64
76
  flexDirection: "column",
65
- children: () => renderStagesContent(typeof result === "function" ? result() : result, theme, runtime, attention, typeof showDependencies === "function" ? showDependencies() : showDependencies),
77
+ children: () => renderStagesContent(typeof result === "function" ? result() : result, theme, runtime, attention, typeof showDependencies === "function" ? showDependencies() : showDependencies, onStageSelect),
66
78
  });
67
79
  };
68
80
 
@@ -210,9 +222,9 @@ export const resolveProjectRoot = async (api, { timeoutMs = PATH_TIMEOUT_MS, pol
210
222
  return null;
211
223
  };
212
224
 
213
- const renderStagesSlot = (controller, theme, sessionId, runtime = defaultRuntime, attention) => runtime.jsx("box", {
225
+ const renderStagesSlot = (controller, theme, sessionId, runtime = defaultRuntime, attention, onStageSelect) => runtime.jsx("box", {
214
226
  flexDirection: "column",
215
- children: renderStagesElement(() => controller.resultFor(sessionId), theme, runtime, attention, controller.showDependencies),
227
+ children: renderStagesElement(() => controller.resultFor(sessionId), theme, runtime, attention, controller.showDependencies, onStageSelect),
216
228
  });
217
229
 
218
230
  const registerDependencyToggle = (api, controller) => {
@@ -299,6 +311,7 @@ export const tui = async (api, options = {}) => {
299
311
  createSignal: options.runtime?.createSignal,
300
312
  attention: api.workContextAttention,
301
313
  });
314
+ const stageSwitcher = createStageSwitcherFlow(api);
302
315
  const unregisterDependencyToggle = registerDependencyToggle(api, controller);
303
316
  let currentSessionId = initialSessionId;
304
317
  const unregisterDependencyTree = registerDependencyTree(api, controller, () => currentSessionId || ACTIVE_WORKSPACE_SESSION);
@@ -319,7 +332,7 @@ export const tui = async (api, options = {}) => {
319
332
  sidebar_content: (slotContext = {}, slotState = {}) => {
320
333
  const sessionId = sessionIdForSlot(api, initialSessionId, slotContext, slotState) || ACTIVE_WORKSPACE_SESSION;
321
334
  currentSessionId = sessionId;
322
- return renderStagesSlot(controller, api.theme, sessionId, options.runtime, api.workContextAttention);
335
+ return renderStagesSlot(controller, api.theme, sessionId, options.runtime, api.workContextAttention, (stage) => stageSwitcher.select(stage.id));
323
336
  },
324
337
  },
325
338
  });