opencode-work-context 0.4.9 → 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/package.json +1 -1
- package/plugin/stages-tui.js +88 -8
- package/src/stages-renderer.js +44 -1
- package/src/stages-snapshot.js +1 -0
- package/src/work-context-snapshot.js +1 -0
package/package.json
CHANGED
package/plugin/stages-tui.js
CHANGED
|
@@ -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
|
-
|
|
60
|
-
|
|
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
|
-
|
|
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);
|
package/src/stages-renderer.js
CHANGED
|
@@ -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");
|
package/src/stages-snapshot.js
CHANGED
|
@@ -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;
|