opencode-work-context 0.4.10 → 0.4.11
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 +1 -1
- package/plugin/stage-switcher.js +26 -4
- package/plugin/stages-tui.js +12 -6
package/package.json
CHANGED
package/plugin/stage-switcher.js
CHANGED
|
@@ -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
|
-
|
|
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 = {}) => {
|
package/plugin/stages-tui.js
CHANGED
|
@@ -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;
|
|
@@ -30,7 +31,7 @@ export { readStagesSnapshot, renderStagesPanel };
|
|
|
30
31
|
|
|
31
32
|
const defaultRuntime = { jsx };
|
|
32
33
|
|
|
33
|
-
const renderStagesContent = (result, theme, runtime = defaultRuntime, attention, showDependencies = true) => !result?.ok || !result.data?.workspace
|
|
34
|
+
const renderStagesContent = (result, theme, runtime = defaultRuntime, attention, showDependencies = true, onStageSelect) => !result?.ok || !result.data?.workspace
|
|
34
35
|
? [
|
|
35
36
|
runtime.jsx("text", { children: runtime.jsx("b", { children: "Stages" }) }),
|
|
36
37
|
...renderStagesPanel(result).split("\n").slice(1).map((line) => runtime.jsx("text", { children: line })),
|
|
@@ -51,6 +52,10 @@ const renderStagesContent = (result, theme, runtime = defaultRuntime, attention,
|
|
|
51
52
|
const unread = attention?.attentionForStage?.(result.data.workspace.id, stage.id);
|
|
52
53
|
return runtime.jsx("box", {
|
|
53
54
|
flexDirection: "row",
|
|
55
|
+
onMouseDown: (event) => {
|
|
56
|
+
if (event?.button != null && event.button !== 0) return;
|
|
57
|
+
return onStageSelect?.(stage);
|
|
58
|
+
},
|
|
54
59
|
children: [
|
|
55
60
|
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
61
|
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}` : ""}]` : ""}` }),
|
|
@@ -59,10 +64,10 @@ const renderStagesContent = (result, theme, runtime = defaultRuntime, attention,
|
|
|
59
64
|
}),
|
|
60
65
|
];
|
|
61
66
|
|
|
62
|
-
export const renderStagesElement = (result, theme, runtime = defaultRuntime, attention, showDependencies = true) => {
|
|
67
|
+
export const renderStagesElement = (result, theme, runtime = defaultRuntime, attention, showDependencies = true, onStageSelect) => {
|
|
63
68
|
return runtime.jsx("box", {
|
|
64
69
|
flexDirection: "column",
|
|
65
|
-
|
|
70
|
+
children: () => renderStagesContent(typeof result === "function" ? result() : result, theme, runtime, attention, typeof showDependencies === "function" ? showDependencies() : showDependencies, onStageSelect),
|
|
66
71
|
});
|
|
67
72
|
};
|
|
68
73
|
|
|
@@ -210,9 +215,9 @@ export const resolveProjectRoot = async (api, { timeoutMs = PATH_TIMEOUT_MS, pol
|
|
|
210
215
|
return null;
|
|
211
216
|
};
|
|
212
217
|
|
|
213
|
-
const renderStagesSlot = (controller, theme, sessionId, runtime = defaultRuntime, attention) => runtime.jsx("box", {
|
|
218
|
+
const renderStagesSlot = (controller, theme, sessionId, runtime = defaultRuntime, attention, onStageSelect) => runtime.jsx("box", {
|
|
214
219
|
flexDirection: "column",
|
|
215
|
-
children: renderStagesElement(() => controller.resultFor(sessionId), theme, runtime, attention, controller.showDependencies),
|
|
220
|
+
children: renderStagesElement(() => controller.resultFor(sessionId), theme, runtime, attention, controller.showDependencies, onStageSelect),
|
|
216
221
|
});
|
|
217
222
|
|
|
218
223
|
const registerDependencyToggle = (api, controller) => {
|
|
@@ -299,6 +304,7 @@ export const tui = async (api, options = {}) => {
|
|
|
299
304
|
createSignal: options.runtime?.createSignal,
|
|
300
305
|
attention: api.workContextAttention,
|
|
301
306
|
});
|
|
307
|
+
const stageSwitcher = createStageSwitcherFlow(api);
|
|
302
308
|
const unregisterDependencyToggle = registerDependencyToggle(api, controller);
|
|
303
309
|
let currentSessionId = initialSessionId;
|
|
304
310
|
const unregisterDependencyTree = registerDependencyTree(api, controller, () => currentSessionId || ACTIVE_WORKSPACE_SESSION);
|
|
@@ -319,7 +325,7 @@ export const tui = async (api, options = {}) => {
|
|
|
319
325
|
sidebar_content: (slotContext = {}, slotState = {}) => {
|
|
320
326
|
const sessionId = sessionIdForSlot(api, initialSessionId, slotContext, slotState) || ACTIVE_WORKSPACE_SESSION;
|
|
321
327
|
currentSessionId = sessionId;
|
|
322
|
-
return renderStagesSlot(controller, api.theme, sessionId, options.runtime, api.workContextAttention);
|
|
328
|
+
return renderStagesSlot(controller, api.theme, sessionId, options.runtime, api.workContextAttention, (stage) => stageSwitcher.select(stage.id));
|
|
323
329
|
},
|
|
324
330
|
},
|
|
325
331
|
});
|