opencode-work-context 0.2.1 → 0.4.1
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 +44 -0
- package/commands/wc.md +6 -0
- package/package.json +1 -1
- package/plugin/attention.js +364 -0
- package/plugin/notifier.js +83 -0
- package/plugin/session-switcher.js +14 -7
- package/plugin/stage-switcher.js +27 -26
- package/plugin/stages-tui.js +22 -15
- package/plugin/tui-state.js +31 -0
- package/plugin/tui.js +2 -0
- package/plugin/work-context-modal.js +74 -31
- package/plugin/workspace-switcher.js +16 -7
- package/src/core.js +65 -12
- package/src/storage.js +25 -5
- package/src/tool-definitions.js +3 -1
- package/tools/work_context_reopen_workspace.js +3 -0
- package/tools/work_context_restore_stage.js +3 -0
package/plugin/stage-switcher.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
1
|
import { contextFor } from "../src/opencode-adapter.js";
|
|
4
|
-
import { atomicWrite } from "../src/storage.js";
|
|
5
2
|
import { isDependencySatisfied } from "../src/stage-status.js";
|
|
3
|
+
import { readTuiState, updateTuiState } from "./tui-state.js";
|
|
4
|
+
import { acknowledgeNavigation, attentionForSession, attentionReasonText } from "./attention.js";
|
|
6
5
|
|
|
7
6
|
const TERMINAL_STATUSES = new Set(["completed", "cancelled", "archived"]);
|
|
8
7
|
const SESSION_STATE_RANK = { active: 0, handed_off: 1, abandoned: 2, closed: 3 };
|
|
9
8
|
const RECENT_STAGE_LIMIT = 5;
|
|
10
|
-
const RECENT_STATE_FILE = path.join(".work-context", "local", "tui-state.json");
|
|
11
9
|
const recentStagesByApi = new WeakMap();
|
|
12
10
|
|
|
13
11
|
const errorResult = (code, message, details = {}) => ({ ok: false, error: { code, message, details } });
|
|
@@ -15,24 +13,16 @@ const currentSessionId = (api) => api?.route?.current?.params?.sessionID || api?
|
|
|
15
13
|
const projectRoot = (api) => api?.state?.path?.worktree || api?.state?.path?.directory;
|
|
16
14
|
|
|
17
15
|
const readRecentState = (root) => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return Object.fromEntries(Object.entries(state.recent_stages).map(([workspace, stages]) => [
|
|
25
|
-
workspace,
|
|
26
|
-
Array.isArray(stages) ? stages.filter((stage) => /^\d{2}$/.test(stage)).slice(0, RECENT_STAGE_LIMIT) : [],
|
|
27
|
-
]));
|
|
28
|
-
} catch { return {}; }
|
|
16
|
+
const recent = readTuiState(root).recent_stages;
|
|
17
|
+
if (!recent || typeof recent !== "object" || Array.isArray(recent)) return {};
|
|
18
|
+
return Object.fromEntries(Object.entries(recent).map(([workspace, stages]) => [
|
|
19
|
+
workspace,
|
|
20
|
+
Array.isArray(stages) ? stages.filter((stage) => /^\d{2}$/.test(stage)).slice(0, RECENT_STAGE_LIMIT) : [],
|
|
21
|
+
]));
|
|
29
22
|
};
|
|
30
23
|
|
|
31
24
|
const persistRecentState = (root, store) => {
|
|
32
|
-
|
|
33
|
-
try {
|
|
34
|
-
atomicWrite(path.join(root, RECENT_STATE_FILE), `${JSON.stringify({ schema: 1, recent_stages: Object.fromEntries(store) }, null, 2)}\n`);
|
|
35
|
-
} catch {}
|
|
25
|
+
updateTuiState(root, (state) => ({ ...state, recent_stages: Object.fromEntries(store) }));
|
|
36
26
|
};
|
|
37
27
|
|
|
38
28
|
const recentStageStore = (api) => {
|
|
@@ -55,9 +45,10 @@ export const rememberRecentStage = (api, workspace, stage) => {
|
|
|
55
45
|
|
|
56
46
|
export const recentStageIds = (api, workspace) => [...(recentStageStore(api).get(workspace) || [])];
|
|
57
47
|
|
|
58
|
-
export const selectStageSession = (sessions = []) => sessions
|
|
48
|
+
export const selectStageSession = (sessions = [], attention) => sessions
|
|
59
49
|
.filter((session) => session.opencode_session_id)
|
|
60
|
-
.sort((left, right) => (
|
|
50
|
+
.sort((left, right) => Number(Boolean(attention?.(right.opencode_session_id))) - Number(Boolean(attention?.(left.opencode_session_id)))
|
|
51
|
+
|| (SESSION_STATE_RANK[left.state] ?? 9) - (SESSION_STATE_RANK[right.state] ?? 9)
|
|
61
52
|
|| String(right.updated_at || right.started_at || "").localeCompare(String(left.updated_at || left.started_at || ""))
|
|
62
53
|
|| Number(right.ordinal || 0) - Number(left.ordinal || 0))[0] || null;
|
|
63
54
|
|
|
@@ -100,8 +91,10 @@ export const readStageSwitcherSnapshot = ({ projectRoot: root, sessionId } = {})
|
|
|
100
91
|
const navigateToSession = (api, sessionID) => {
|
|
101
92
|
if (typeof api?.route?.navigate !== "function") return errorResult("SESSION_SWITCH_UNAVAILABLE", "This OpenCode host cannot switch sessions from a TUI plugin");
|
|
102
93
|
try {
|
|
94
|
+
const observed = attentionForSession(api, sessionID)?.eventKey;
|
|
103
95
|
api.ui?.dialog?.clear?.();
|
|
104
96
|
api.route.navigate("session", { sessionID });
|
|
97
|
+
acknowledgeNavigation(api, sessionID, observed);
|
|
105
98
|
return { ok: true, data: { opencode_session_id: sessionID, created: false } };
|
|
106
99
|
} catch (error) {
|
|
107
100
|
return errorResult(error.code || "SESSION_SWITCH_ERROR", error.message || "OpenCode could not open the selected session");
|
|
@@ -176,16 +169,22 @@ export const createStageSwitcherFlow = (api, { read = readStageSwitcherSnapshot,
|
|
|
176
169
|
catch (error) { result = errorResult(error.code || "STORAGE_ERROR", error.message || "Cannot read work-context storage"); }
|
|
177
170
|
if (!result?.ok) { toast(`${result?.error?.code || "STORAGE_ERROR"}: ${result?.error?.message || "Cannot read work-context storage"}`, "error"); return result; }
|
|
178
171
|
const { workspace, stages } = result.data;
|
|
172
|
+
const sessionAttention = (id) => attentionForSession(api, id);
|
|
173
|
+
const stageAttention = (id) => api.workContextAttention?.attentionForStage?.(workspace.id, id);
|
|
174
|
+
const decorated = stages.map((stage) => ({ ...stage, attention: stageAttention(stage.id), selectedSession: selectStageSession(stage.sessions, sessionAttention) }));
|
|
179
175
|
rememberRecentStage(api, workspace.id, result.data.currentStage);
|
|
180
176
|
const recent = recentStageIds(api, workspace.id)
|
|
181
|
-
.map((id) =>
|
|
177
|
+
.map((id) => decorated.find((stage) => stage.id === id))
|
|
182
178
|
.filter((stage) => stage && !stage.current);
|
|
179
|
+
const current = decorated.filter((stage) => stage.current);
|
|
180
|
+
const needsAttention = decorated.filter((stage) => !stage.current && stage.attention);
|
|
181
|
+
const ordinary = decorated.filter((stage) => !stage.current && !stage.attention);
|
|
183
182
|
const optionFor = (stage, category) => {
|
|
184
183
|
const available = (stage.sessions || []).filter((session) => session.opencode_session_id).length;
|
|
185
184
|
const state = stage.blocked ? `blocked by ${stage.blockers.join(", ")}` : stage.status;
|
|
186
185
|
return {
|
|
187
|
-
title: `${stage.current ? ">" : " "} ${stage.id}. ${stage.title}`,
|
|
188
|
-
description: `${state} · ${available ? `${available} session${available === 1 ? "" : "s"}` : TERMINAL_STATUSES.has(stage.status) || stage.blocked ? "no session available" : "new session"}`,
|
|
186
|
+
title: `${stage.current ? ">" : " "} ${stage.attention ? "[ATTN] " : ""}${stage.id}. ${stage.title}`,
|
|
187
|
+
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"}`,
|
|
189
188
|
category,
|
|
190
189
|
disabled: (TERMINAL_STATUSES.has(stage.status) || stage.blocked) && !available,
|
|
191
190
|
value: stage,
|
|
@@ -196,8 +195,10 @@ export const createStageSwitcherFlow = (api, { read = readStageSwitcherSnapshot,
|
|
|
196
195
|
title: `Switch stage · ${workspace.id} ${workspace.title}`,
|
|
197
196
|
placeholder: "Search stages",
|
|
198
197
|
options: [
|
|
199
|
-
...
|
|
200
|
-
...
|
|
198
|
+
...current.map((stage) => optionFor(stage, "Current")),
|
|
199
|
+
...needsAttention.map((stage) => optionFor(stage, "Needs attention")),
|
|
200
|
+
...recent.filter((stage) => !stage.attention).map((stage) => optionFor(stage, "Recent")),
|
|
201
|
+
...ordinary.map((stage) => optionFor(stage, stage.status)),
|
|
201
202
|
],
|
|
202
203
|
onSelect: (option) => void (async () => {
|
|
203
204
|
const switched = await switchToStage(api, option.value, { workspace: workspace.id, currentStage: result.data.currentStage, start });
|
package/plugin/stages-tui.js
CHANGED
|
@@ -4,6 +4,7 @@ import { readStagesSnapshot } from "../src/stages-snapshot.js";
|
|
|
4
4
|
import { renderStagesPanel } from "../src/stages-renderer.js";
|
|
5
5
|
import { jsx } from "@opentui/solid/jsx-runtime";
|
|
6
6
|
import { createSignal } from "solid-js";
|
|
7
|
+
import { attentionReasonText } from "./attention.js";
|
|
7
8
|
|
|
8
9
|
const DEBOUNCE_MS = 150;
|
|
9
10
|
const POLL_MS = 1000;
|
|
@@ -24,7 +25,7 @@ export { readStagesSnapshot, renderStagesPanel };
|
|
|
24
25
|
|
|
25
26
|
const defaultRuntime = { jsx };
|
|
26
27
|
|
|
27
|
-
const renderStagesContent = (result, theme, runtime = defaultRuntime) => !result?.ok || !result.data?.workspace
|
|
28
|
+
const renderStagesContent = (result, theme, runtime = defaultRuntime, attention) => !result?.ok || !result.data?.workspace
|
|
28
29
|
? [
|
|
29
30
|
runtime.jsx("text", { children: runtime.jsx("b", { children: "Stages" }) }),
|
|
30
31
|
...renderStagesPanel(result).split("\n").slice(1).map((line) => runtime.jsx("text", { children: line })),
|
|
@@ -32,7 +33,7 @@ const renderStagesContent = (result, theme, runtime = defaultRuntime) => !result
|
|
|
32
33
|
: [
|
|
33
34
|
runtime.jsx("box", {
|
|
34
35
|
marginBottom: 1,
|
|
35
|
-
children: runtime.jsx("text", { wrapMode: "word", children: runtime.jsx("b", { children: result.data.workspace.title }) }),
|
|
36
|
+
children: runtime.jsx("text", { wrapMode: "word", children: runtime.jsx("b", { children: `${attention?.attentionForWorkspace?.(result.data.workspace.id) ? "[ATTN] " : ""}${result.data.workspace.title}` }) }),
|
|
36
37
|
}),
|
|
37
38
|
runtime.jsx("box", {
|
|
38
39
|
flexDirection: "row",
|
|
@@ -41,19 +42,22 @@ const renderStagesContent = (result, theme, runtime = defaultRuntime) => !result
|
|
|
41
42
|
runtime.jsx("text", { fg: theme?.current?.textMuted, children: ` · ${result.data.workspace.status}` }),
|
|
42
43
|
],
|
|
43
44
|
}),
|
|
44
|
-
...result.data.stages.map((stage) =>
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
...result.data.stages.map((stage) => {
|
|
46
|
+
const unread = attention?.attentionForStage?.(result.data.workspace.id, stage.id);
|
|
47
|
+
return runtime.jsx("box", {
|
|
48
|
+
flexDirection: "row",
|
|
49
|
+
children: [
|
|
50
|
+
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}` : ""}]` : ""}` }),
|
|
52
|
+
],
|
|
53
|
+
});
|
|
54
|
+
}),
|
|
51
55
|
];
|
|
52
56
|
|
|
53
|
-
export const renderStagesElement = (result, theme, runtime = defaultRuntime) => {
|
|
57
|
+
export const renderStagesElement = (result, theme, runtime = defaultRuntime, attention) => {
|
|
54
58
|
return runtime.jsx("box", {
|
|
55
59
|
flexDirection: "column",
|
|
56
|
-
children: () => renderStagesContent(typeof result === "function" ? result() : result, theme, runtime),
|
|
60
|
+
children: () => renderStagesContent(typeof result === "function" ? result() : result, theme, runtime, attention),
|
|
57
61
|
});
|
|
58
62
|
};
|
|
59
63
|
|
|
@@ -89,13 +93,14 @@ const disposeRegistration = (registration) => {
|
|
|
89
93
|
else registration?.dispose?.();
|
|
90
94
|
};
|
|
91
95
|
|
|
92
|
-
export const createStagesTuiController = ({ projectRoot, read = readStagesSnapshot, debounceMs = DEBOUNCE_MS, pollMs = POLL_MS, createSignal: makeSignal = createSignal } = {}) => {
|
|
96
|
+
export const createStagesTuiController = ({ projectRoot, read = readStagesSnapshot, debounceMs = DEBOUNCE_MS, pollMs = POLL_MS, createSignal: makeSignal = createSignal, attention } = {}) => {
|
|
93
97
|
const snapshots = new Map();
|
|
94
98
|
const generations = new Map();
|
|
95
99
|
const timers = new Map();
|
|
96
100
|
const pollers = new Map();
|
|
97
101
|
const [version, setVersion] = makeSignal(0);
|
|
98
102
|
let disposed = false;
|
|
103
|
+
const unsubscribeAttention = attention?.subscribe?.(() => setVersion((value) => value + 1));
|
|
99
104
|
|
|
100
105
|
const readSnapshot = async (sessionId) => {
|
|
101
106
|
if (disposed || !sessionId) return;
|
|
@@ -164,6 +169,7 @@ export const createStagesTuiController = ({ projectRoot, read = readStagesSnapsh
|
|
|
164
169
|
for (const poller of pollers.values()) clearInterval(poller);
|
|
165
170
|
pollers.clear();
|
|
166
171
|
snapshots.clear();
|
|
172
|
+
unsubscribeAttention?.();
|
|
167
173
|
},
|
|
168
174
|
};
|
|
169
175
|
};
|
|
@@ -191,9 +197,9 @@ export const resolveProjectRoot = async (api, { timeoutMs = PATH_TIMEOUT_MS, pol
|
|
|
191
197
|
return null;
|
|
192
198
|
};
|
|
193
199
|
|
|
194
|
-
const renderStagesSlot = (controller, theme, sessionId, runtime = defaultRuntime) => runtime.jsx("box", {
|
|
200
|
+
const renderStagesSlot = (controller, theme, sessionId, runtime = defaultRuntime, attention) => runtime.jsx("box", {
|
|
195
201
|
flexDirection: "column",
|
|
196
|
-
children: renderStagesElement(() => controller.resultFor(sessionId), theme, runtime),
|
|
202
|
+
children: renderStagesElement(() => controller.resultFor(sessionId), theme, runtime, attention),
|
|
197
203
|
});
|
|
198
204
|
|
|
199
205
|
const ACTIVE_WORKSPACE_SESSION = "__active_" + "work" + "_context_workspace__";
|
|
@@ -215,6 +221,7 @@ export const tui = async (api, options = {}) => {
|
|
|
215
221
|
debounceMs: options.debounceMs,
|
|
216
222
|
pollMs: options.pollMs,
|
|
217
223
|
createSignal: options.runtime?.createSignal,
|
|
224
|
+
attention: api.workContextAttention,
|
|
218
225
|
});
|
|
219
226
|
await controller.load(initialSessionId);
|
|
220
227
|
let currentSessionId = initialSessionId;
|
|
@@ -234,7 +241,7 @@ export const tui = async (api, options = {}) => {
|
|
|
234
241
|
sidebar_content: (slotContext = {}, slotState = {}) => {
|
|
235
242
|
const sessionId = sessionIdForSlot(api, initialSessionId, slotContext, slotState) || ACTIVE_WORKSPACE_SESSION;
|
|
236
243
|
currentSessionId = sessionId;
|
|
237
|
-
return renderStagesSlot(controller, api.theme, sessionId, options.runtime);
|
|
244
|
+
return renderStagesSlot(controller, api.theme, sessionId, options.runtime, api.workContextAttention);
|
|
238
245
|
},
|
|
239
246
|
},
|
|
240
247
|
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { atomicWrite } from "../src/storage.js";
|
|
4
|
+
|
|
5
|
+
export const TUI_STATE_FILE = path.join(".work-context", "local", "tui-state.json");
|
|
6
|
+
|
|
7
|
+
export const readTuiState = (root) => {
|
|
8
|
+
if (!root) return { schema: 1 };
|
|
9
|
+
try {
|
|
10
|
+
const file = path.join(root, TUI_STATE_FILE);
|
|
11
|
+
if (!fs.lstatSync(file).isFile()) return { schema: 1 };
|
|
12
|
+
const value = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
13
|
+
return value && value.schema === 1 && typeof value === "object" && !Array.isArray(value)
|
|
14
|
+
? value
|
|
15
|
+
: { schema: 1 };
|
|
16
|
+
} catch {
|
|
17
|
+
return { schema: 1 };
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const updateTuiState = (root, update) => {
|
|
22
|
+
if (!root) return false;
|
|
23
|
+
try {
|
|
24
|
+
const current = readTuiState(root);
|
|
25
|
+
const next = update(current);
|
|
26
|
+
atomicWrite(path.join(root, TUI_STATE_FILE), `${JSON.stringify({ ...next, schema: 1 }, null, 2)}\n`);
|
|
27
|
+
return true;
|
|
28
|
+
} catch {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
};
|
package/plugin/tui.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import stages from "./stages-tui.js";
|
|
2
2
|
import modal from "./work-context-modal.js";
|
|
3
|
+
import attention from "./attention.js";
|
|
3
4
|
|
|
4
5
|
// Keep the sidebar and modal adapters composed under one optional TUI entry.
|
|
5
6
|
// The server plugin remains a separate runtime contract.
|
|
6
7
|
export const tui = async (api, options = {}) => {
|
|
8
|
+
await attention.tui(api, options);
|
|
7
9
|
await stages.tui(api, options);
|
|
8
10
|
await modal.tui(api, options);
|
|
9
11
|
};
|
|
@@ -7,6 +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
11
|
|
|
11
12
|
const COMMAND_NAME = "work_context.open";
|
|
12
13
|
const ACTIONS_COMMAND_NAME = "work_context.actions";
|
|
@@ -32,6 +33,7 @@ export const WORK_CONTEXT_ACTIONS = [
|
|
|
32
33
|
{ value: "workspace.list", title: "Inspect workspace", description: "List one workspace and its stages", category: "Workspace" },
|
|
33
34
|
{ value: "workspace.rename", title: "Rename workspace", description: "Change a workspace title", category: "Workspace" },
|
|
34
35
|
{ value: "workspace.finish", title: "Finish workspace", description: "Complete a workspace", category: "Workspace" },
|
|
36
|
+
{ value: "workspace.reopen", title: "Reopen workspace", description: "Reopen a completed workspace with a reason", category: "Workspace" },
|
|
35
37
|
{ value: "stage.add", title: "Add stage", description: "Create a planned stage with an optional prompt", category: "Stage" },
|
|
36
38
|
{ value: "resume", title: "Resume stage", description: "Start or continue work on a stage", category: "Stage" },
|
|
37
39
|
{ value: "stage.rename", title: "Rename stage", description: "Change a stage title", category: "Stage" },
|
|
@@ -40,6 +42,7 @@ export const WORK_CONTEXT_ACTIONS = [
|
|
|
40
42
|
{ value: "stage.update-result", title: "Update stage result", description: "Replace an existing completion result", category: "Stage" },
|
|
41
43
|
{ value: "stage.archive", title: "Archive stage", description: "Archive a non-active stage", category: "Stage" },
|
|
42
44
|
{ value: "stage.reopen", title: "Reopen stage", description: "Reopen a completed stage with a reason", category: "Stage" },
|
|
45
|
+
{ value: "stage.restore", title: "Restore stage", description: "Restore an archived stage with a reason", category: "Stage" },
|
|
43
46
|
{ value: "stage.handoff", title: "Hand off stage", description: "Close this session and preserve continuation", category: "Stage" },
|
|
44
47
|
{ value: "stage.abandon", title: "Abandon stage session", description: "Close this session and keep the stage resumable", category: "Stage" },
|
|
45
48
|
{ value: "stage.finish", title: "Finish stage", description: "Complete a stage and review knowledge", category: "Stage" },
|
|
@@ -113,6 +116,7 @@ export const createWorkContextModalController = ({
|
|
|
113
116
|
createSignal: makeSignal = createSignal,
|
|
114
117
|
onClose = () => {},
|
|
115
118
|
onCommand = () => {},
|
|
119
|
+
attention,
|
|
116
120
|
} = {}) => {
|
|
117
121
|
const [version, setVersion] = makeSignal(0);
|
|
118
122
|
const [query, setQuery] = makeSignal("");
|
|
@@ -125,6 +129,7 @@ export const createWorkContextModalController = ({
|
|
|
125
129
|
let poller;
|
|
126
130
|
let disposed = false;
|
|
127
131
|
let onSelectionChange = () => {};
|
|
132
|
+
const unsubscribeAttention = attention?.subscribe?.(() => setVersion((value) => value + 1));
|
|
128
133
|
|
|
129
134
|
const refresh = async () => {
|
|
130
135
|
if (disposed) return;
|
|
@@ -147,7 +152,17 @@ export const createWorkContextModalController = ({
|
|
|
147
152
|
timer = setTimeout(() => { timer = undefined; void refresh(); }, debounceMs);
|
|
148
153
|
};
|
|
149
154
|
const snapshot = () => { version(); return result; };
|
|
150
|
-
const workspaces = () =>
|
|
155
|
+
const workspaces = () => {
|
|
156
|
+
const data = snapshot()?.data || {};
|
|
157
|
+
return filterWorkspaces(data.workspaces || [], query())
|
|
158
|
+
.map((workspace) => ({
|
|
159
|
+
...workspace,
|
|
160
|
+
stages: [...(workspace.stages || [])].sort((left, right) => Number(Boolean(right.current)) - Number(Boolean(left.current))
|
|
161
|
+
|| Number(Boolean(attention?.attentionForStage?.(workspace.id, right.id))) - Number(Boolean(attention?.attentionForStage?.(workspace.id, left.id)))),
|
|
162
|
+
}))
|
|
163
|
+
.sort((left, right) => Number(right.id === data.currentWorkspace) - Number(left.id === data.currentWorkspace)
|
|
164
|
+
|| Number(Boolean(attention?.attentionForWorkspace?.(right.id))) - Number(Boolean(attention?.attentionForWorkspace?.(left.id))));
|
|
165
|
+
};
|
|
151
166
|
const selectedWorkspace = () => workspaces()[Math.min(workspaceIndex(), Math.max(0, workspaces().length - 1))] || null;
|
|
152
167
|
const selectedStage = () => selectedWorkspace()?.stages?.[Math.min(stageIndex(), Math.max(0, (selectedWorkspace()?.stages || []).length - 1))] || null;
|
|
153
168
|
const [preparedCommand, setPreparedCommand] = makeSignal(null);
|
|
@@ -198,9 +213,9 @@ export const createWorkContextModalController = ({
|
|
|
198
213
|
void refresh();
|
|
199
214
|
if (pollMs) poller = setInterval(scheduleRefresh, pollMs);
|
|
200
215
|
return {
|
|
201
|
-
snapshot, query, setQuery, workspaces, selectedWorkspace, selectedStage, details, preparedCommand, prepareCommand, insertCommand, handleKey, scheduleRefresh,
|
|
216
|
+
snapshot, query, setQuery, workspaces, selectedWorkspace, selectedStage, details, preparedCommand, prepareCommand, insertCommand, handleKey, scheduleRefresh, attention,
|
|
202
217
|
onSelectionChange: (handler) => { onSelectionChange = typeof handler === "function" ? handler : () => {}; },
|
|
203
|
-
dispose: () => { disposed = true; clearTimeout(timer); clearInterval(poller); },
|
|
218
|
+
dispose: () => { disposed = true; clearTimeout(timer); clearInterval(poller); unsubscribeAttention?.(); },
|
|
204
219
|
};
|
|
205
220
|
};
|
|
206
221
|
|
|
@@ -226,19 +241,25 @@ export const renderWorkContextModal = (controller, theme, runtime = { jsx }, { m
|
|
|
226
241
|
const muted = theme?.current?.textMuted;
|
|
227
242
|
const selectedWorkspaceIndex = selected ? workspaces.indexOf(selected) : -1;
|
|
228
243
|
const selectedStageIndex = stage && selected ? (selected.stages || []).indexOf(stage) : -1;
|
|
229
|
-
const workspaceItems = workspaces.map((workspace, index) =>
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
244
|
+
const workspaceItems = workspaces.map((workspace, index) => {
|
|
245
|
+
const unread = controller.attention?.attentionForWorkspace?.(workspace.id);
|
|
246
|
+
return runtime.jsx("box", {
|
|
247
|
+
id: `workspace-${workspace.id}`, flexDirection: "row", gap: 1, children: [
|
|
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 }),
|
|
250
|
+
line(runtime, workspace.status, { flexShrink: 0, fg: muted }),
|
|
251
|
+
],
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
const stageItems = selected ? (selected.stages || []).map((item, index) => {
|
|
255
|
+
const unread = controller.attention?.attentionForStage?.(selected.id, item.id);
|
|
256
|
+
return runtime.jsx("box", {
|
|
257
|
+
id: `stage-${item.id}`, flexDirection: "row", children: [
|
|
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 }),
|
|
260
|
+
],
|
|
261
|
+
});
|
|
262
|
+
}) : [];
|
|
242
263
|
const children = [runtime.jsx("box", {
|
|
243
264
|
flexDirection: "row", justifyContent: "space-between", paddingLeft: 2, paddingRight: 2,
|
|
244
265
|
children: [
|
|
@@ -268,7 +289,10 @@ export const renderWorkContextModal = (controller, theme, runtime = { jsx }, { m
|
|
|
268
289
|
line(runtime, "Details", { marginTop: 1, fg: muted }),
|
|
269
290
|
line(runtime, stage.description || "No description.", { wrapMode: "word", fg: theme?.current?.text }),
|
|
270
291
|
line(runtime, `Sessions ${(selected.sessions || []).length}`, { fg: muted }),
|
|
271
|
-
...(selected.sessions || []).map((session) =>
|
|
292
|
+
...(selected.sessions || []).map((session) => {
|
|
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 });
|
|
295
|
+
}),
|
|
272
296
|
] : []),
|
|
273
297
|
] }),
|
|
274
298
|
],
|
|
@@ -295,6 +319,9 @@ export const buildWorkContextActionCommand = (action, { workspace, stage, value,
|
|
|
295
319
|
if (!normalizedWorkspace) return { ok: false, error: { code: "INVALID_ARGUMENT", message: "Invalid workspace ID" } };
|
|
296
320
|
if (action === "workspace.list") return { ok: true, command: `/wc workspace list ${normalizedWorkspace}` };
|
|
297
321
|
if (action === "workspace.finish") return { ok: true, command: `/wc workspace finish ${normalizedWorkspace}` };
|
|
322
|
+
if (action === "workspace.reopen") return value?.trim()
|
|
323
|
+
? { ok: true, command: `/wc workspace reopen ${normalizedWorkspace} ${quoteWorkContextArgument(value.trim())}` }
|
|
324
|
+
: { ok: false, error: { code: "INVALID_ARGUMENT", message: "Reason is required" } };
|
|
298
325
|
if (action === "workspace.rename") return value?.trim()
|
|
299
326
|
? { ok: true, command: `/wc workspace rename ${normalizedWorkspace} ${quoteWorkContextArgument(value.trim())}` }
|
|
300
327
|
: { ok: false, error: { code: "INVALID_ARGUMENT", message: "Title is required" } };
|
|
@@ -306,7 +333,7 @@ export const buildWorkContextActionCommand = (action, { workspace, stage, value,
|
|
|
306
333
|
if (!normalizedStage) return { ok: false, error: { code: "INVALID_ARGUMENT", message: "Invalid stage ID" } };
|
|
307
334
|
const commandName = action.replace(".", " ");
|
|
308
335
|
if (["resume", "stage.archive", "stage.handoff", "stage.abandon", "stage.finish"].includes(action)) return { ok: true, command: `/wc ${commandName} ${normalizedWorkspace} ${normalizedStage}` };
|
|
309
|
-
const inputCommands = { "stage.rename": "title", "stage.update": "description", "stage.update-prompt": "prompt", "stage.update-result": "result", "stage.reopen": "reason" };
|
|
336
|
+
const inputCommands = { "stage.rename": "title", "stage.update": "description", "stage.update-prompt": "prompt", "stage.update-result": "result", "stage.reopen": "reason", "stage.restore": "reason" };
|
|
310
337
|
if (Object.hasOwn(inputCommands, action)) return value?.trim()
|
|
311
338
|
? { ok: true, command: `/wc ${commandName} ${normalizedWorkspace} ${normalizedStage} ${quoteWorkContextArgument(value.trim())}` }
|
|
312
339
|
: { ok: false, error: { code: "INVALID_ARGUMENT", message: `${inputCommands[action][0].toUpperCase()}${inputCommands[action].slice(1)} is required` } };
|
|
@@ -339,7 +366,7 @@ export const createWorkContextActionFlow = (api, { projectRoot, sessionId, read
|
|
|
339
366
|
else if (action === "stage.update") requireValue("Update stage description", "Description", action, context);
|
|
340
367
|
else if (action === "stage.update-prompt") requireValue("Update stage prompt", "Detailed prompt", action, context);
|
|
341
368
|
else if (action === "stage.update-result") requireValue("Update stage result", "Completion result", action, context);
|
|
342
|
-
else if (action === "stage.reopen") requireValue("Reopen stage", "Reason for reopening", action, context);
|
|
369
|
+
else if (action === "stage.reopen" || action === "stage.restore") requireValue(action === "stage.restore" ? "Restore stage" : "Reopen stage", action === "stage.restore" ? "Reason for restoring" : "Reason for reopening", action, context);
|
|
343
370
|
else void insert(buildWorkContextActionCommand(action, context));
|
|
344
371
|
};
|
|
345
372
|
const selectStage = (action, workspace, stages) => showSelect("Select stage", stages.map((stage) => ({
|
|
@@ -367,6 +394,7 @@ export const createWorkContextActionFlow = (api, { projectRoot, sessionId, read
|
|
|
367
394
|
})), (option) => {
|
|
368
395
|
const workspace = option.value;
|
|
369
396
|
if (action === "workspace.list" || action === "workspace.finish") void insert(buildWorkContextActionCommand(action, { workspace: workspace.id }));
|
|
397
|
+
else if (action === "workspace.reopen") requireValue("Reopen workspace", "Reason for reopening", action, { workspace: workspace.id });
|
|
370
398
|
else if (action === "workspace.rename") requireValue("Rename workspace", "New title", action, { workspace: workspace.id });
|
|
371
399
|
else if (action === "stage.add") addStage(workspace.id);
|
|
372
400
|
else if (!workspace.stages?.length) toast("No stages found");
|
|
@@ -381,16 +409,17 @@ export const createWorkContextActionFlow = (api, { projectRoot, sessionId, read
|
|
|
381
409
|
};
|
|
382
410
|
const showWorkspaceActions = (workspace) => showSelect(`${workspace.id} ${workspace.title}`, [
|
|
383
411
|
{ title: "Back to workspaces", value: "back", category: "Navigation" },
|
|
384
|
-
...WORK_CONTEXT_ACTIONS.filter((action) => ["workspace.list", "stage.add", "workspace.rename", "workspace.finish"].includes(action.value)),
|
|
412
|
+
...WORK_CONTEXT_ACTIONS.filter((action) => ["workspace.list", "stage.add", "workspace.rename", "workspace.finish", "workspace.reopen"].includes(action.value)),
|
|
385
413
|
], (option) => {
|
|
386
414
|
if (option.value === "back") { void browseWorkspaces(); return; }
|
|
387
415
|
if (option.value === "workspace.list" || option.value === "workspace.finish") void insert(buildWorkContextActionCommand(option.value, { workspace: workspace.id }));
|
|
416
|
+
else if (option.value === "workspace.reopen") requireValue("Reopen workspace", "Reason for reopening", option.value, { workspace: workspace.id });
|
|
388
417
|
else if (option.value === "workspace.rename") requireValue("Rename workspace", "New title", option.value, { workspace: workspace.id });
|
|
389
418
|
else if (option.value === "stage.add") addStage(workspace.id);
|
|
390
419
|
});
|
|
391
420
|
const showStageActions = (workspace, stage, { backTitle = "Back to workspaces", onBack = () => void browseWorkspaces() } = {}) => showSelect(`${workspace.id}/${stage.id} ${stage.title}`, [
|
|
392
421
|
{ title: backTitle, value: "back", category: "Navigation" },
|
|
393
|
-
...WORK_CONTEXT_ACTIONS.filter((action) => ["resume", "stage.rename", "stage.update", "stage.update-prompt", "stage.update-result", "stage.archive", "stage.reopen", "stage.handoff", "stage.abandon", "stage.finish"].includes(action.value)),
|
|
422
|
+
...WORK_CONTEXT_ACTIONS.filter((action) => ["resume", "stage.rename", "stage.update", "stage.update-prompt", "stage.update-result", "stage.archive", "stage.reopen", "stage.restore", "stage.handoff", "stage.abandon", "stage.finish"].includes(action.value)),
|
|
394
423
|
], (option) => {
|
|
395
424
|
if (option.value === "back") { onBack(); return; }
|
|
396
425
|
runStageAction(option.value, workspace.id, stage.id);
|
|
@@ -402,10 +431,14 @@ export const createWorkContextActionFlow = (api, { projectRoot, sessionId, read
|
|
|
402
431
|
const workspaces = [...loaded.workspaces].sort((left, right) => {
|
|
403
432
|
if (left.id === loaded.currentWorkspace) return -1;
|
|
404
433
|
if (right.id === loaded.currentWorkspace) return 1;
|
|
434
|
+
const leftAttention = api.workContextAttention?.attentionForWorkspace?.(left.id);
|
|
435
|
+
const rightAttention = api.workContextAttention?.attentionForWorkspace?.(right.id);
|
|
436
|
+
if (Boolean(leftAttention) !== Boolean(rightAttention)) return leftAttention ? -1 : 1;
|
|
405
437
|
return (rank[left.status] ?? 9) - (rank[right.status] ?? 9) || left.id.localeCompare(right.id);
|
|
406
438
|
});
|
|
407
439
|
const options = workspaces.flatMap((workspace) => {
|
|
408
|
-
const
|
|
440
|
+
const unread = api.workContextAttention?.attentionForWorkspace?.(workspace.id);
|
|
441
|
+
const category = `${unread ? "[ATTN] " : ""}${workspace.id} · ${workspace.title} · ${workspace.status}`;
|
|
409
442
|
return [
|
|
410
443
|
{ title: "Overview", description: workspace.status, footer: progress(workspace), category, value: { type: "workspace", workspace } },
|
|
411
444
|
...(workspace.stages || []).map((stage) => ({
|
|
@@ -430,17 +463,23 @@ export const createWorkContextActionFlow = (api, { projectRoot, sessionId, read
|
|
|
430
463
|
entries.sort((left, right) => {
|
|
431
464
|
if (left.stage.current) return -1;
|
|
432
465
|
if (right.stage.current) return 1;
|
|
466
|
+
const leftAttention = api.workContextAttention?.attentionForStage?.(left.workspace.id, left.stage.id);
|
|
467
|
+
const rightAttention = api.workContextAttention?.attentionForStage?.(right.workspace.id, right.stage.id);
|
|
468
|
+
if (Boolean(leftAttention) !== Boolean(rightAttention)) return leftAttention ? -1 : 1;
|
|
433
469
|
return (rank[left.stage.status] ?? 9) - (rank[right.stage.status] ?? 9)
|
|
434
470
|
|| left.workspace.id.localeCompare(right.workspace.id)
|
|
435
471
|
|| Number(left.stage.id) - Number(right.stage.id);
|
|
436
472
|
});
|
|
437
473
|
const labels = { in_progress: "In progress", planned: "Planned", completed: "Completed", cancelled: "Cancelled" };
|
|
438
|
-
showSelect("Stages", entries.map(({ workspace, stage }) =>
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
474
|
+
showSelect("Stages", entries.map(({ workspace, stage }) => {
|
|
475
|
+
const unread = api.workContextAttention?.attentionForStage?.(workspace.id, stage.id);
|
|
476
|
+
return {
|
|
477
|
+
title: `${marker(stage.status)} ${unread ? "[ATTN] " : ""}${workspace.id}/${stage.id} ${stage.title} · ${workspace.title}`,
|
|
478
|
+
description: unread ? `Needs attention: ${attentionReasonText(unread.reason)} (${unread.count}) · ${stage.description || stage.status}` : stage.description || stage.status,
|
|
479
|
+
category: stage.current ? "Current" : labels[stage.status] || stage.status,
|
|
480
|
+
value: { workspace, stage },
|
|
481
|
+
};
|
|
482
|
+
}), (option) => showStageActions(option.value.workspace, option.value.stage, { backTitle: "Back to stages", onBack: () => void browseStages() }));
|
|
444
483
|
};
|
|
445
484
|
const sessionOrdinal = (session) => String(session.ordinal).includes("/")
|
|
446
485
|
? String(session.ordinal)
|
|
@@ -475,15 +514,19 @@ export const createWorkContextActionFlow = (api, { projectRoot, sessionId, read
|
|
|
475
514
|
const rightCurrent = right.session.opencode_session_id === sessionId || right.session.session_id === sessionId;
|
|
476
515
|
if (leftCurrent) return -1;
|
|
477
516
|
if (rightCurrent) return 1;
|
|
517
|
+
const leftAttention = attentionForSession(api, left.session.opencode_session_id);
|
|
518
|
+
const rightAttention = attentionForSession(api, right.session.opencode_session_id);
|
|
519
|
+
if (Boolean(leftAttention) !== Boolean(rightAttention)) return leftAttention ? -1 : 1;
|
|
478
520
|
return (rank[left.session.state] ?? 9) - (rank[right.session.state] ?? 9)
|
|
479
521
|
|| String(right.session.updated_at || "").localeCompare(String(left.session.updated_at || ""));
|
|
480
522
|
});
|
|
481
523
|
const labels = { active: "Active", handed_off: "Handed off", abandoned: "Abandoned", closed: "Closed" };
|
|
482
524
|
showSelect("Sessions", entries.map(({ workspace, session }) => {
|
|
483
525
|
const current = session.opencode_session_id === sessionId || session.session_id === sessionId;
|
|
526
|
+
const unread = attentionForSession(api, session.opencode_session_id);
|
|
484
527
|
return {
|
|
485
|
-
title: `${workspace.id} ${sessionOrdinal(session)} ${session.summary || "Work session"} · ${workspace.title}`,
|
|
486
|
-
description: `${session.state || "unknown"} · ${session.session_id}`,
|
|
528
|
+
title: `${unread ? "[ATTN] " : ""}${workspace.id} ${sessionOrdinal(session)} ${session.summary || "Work session"} · ${workspace.title}`,
|
|
529
|
+
description: `${unread ? `needs attention: ${attentionReasonText(unread.reason)} · ` : ""}${session.state || "unknown"} · ${session.session_id}`,
|
|
487
530
|
footer: session.updated_at || session.started_at,
|
|
488
531
|
category: current ? "Current" : labels[session.state] || session.state || "Unknown",
|
|
489
532
|
value: { workspace, session },
|
|
@@ -534,7 +577,7 @@ export const openCompatibilityDialog = (api, runtime = {}, options = {}) => {
|
|
|
534
577
|
watcher?.close();
|
|
535
578
|
closeDialog(api);
|
|
536
579
|
};
|
|
537
|
-
const controller = createWorkContextModalController({ projectRoot, sessionId, read: options.read || readWorkContextSnapshot, createSignal: runtime.createSignal, onClose: close, onCommand: (command) => insertPromptCommand(api, command) });
|
|
580
|
+
const controller = createWorkContextModalController({ projectRoot, sessionId, read: options.read || readWorkContextSnapshot, createSignal: runtime.createSignal, attention: api.workContextAttention, onClose: close, onCommand: (command) => insertPromptCommand(api, command) });
|
|
538
581
|
try { watcher = projectRoot && fs.watch(path.join(projectRoot, ".work-context"), { recursive: true }, () => controller.scheduleRefresh?.()); } catch {}
|
|
539
582
|
const maxListHeight = Math.max(8, Math.floor((api.renderer?.height || 60) / 2) - 6);
|
|
540
583
|
const render = () => renderWorkContextModal(controller, api.theme, runtime, { maxListHeight });
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { readWorkContextSnapshot } from "../src/work-context-snapshot.js";
|
|
2
|
+
import { acknowledgeNavigation, attentionForSession, attentionReasonText } from "./attention.js";
|
|
2
3
|
|
|
3
4
|
const SESSION_STATE_RANK = { active: 0, handed_off: 1, abandoned: 2, closed: 3 };
|
|
4
5
|
const WORKSPACE_STATUS_RANK = { in_progress: 0, planned: 1, completed: 2, cancelled: 3 };
|
|
@@ -8,15 +9,19 @@ const currentSessionId = (api) => api?.route?.current?.params?.sessionID || api?
|
|
|
8
9
|
const projectRoot = (api) => api?.state?.path?.worktree || api?.state?.path?.directory;
|
|
9
10
|
|
|
10
11
|
/** Select the best existing OpenCode session without changing work-context state. */
|
|
11
|
-
export const selectWorkspaceSession = (sessions = []) => sessions
|
|
12
|
+
export const selectWorkspaceSession = (sessions = [], attention) => sessions
|
|
12
13
|
.filter((session) => session.opencode_session_id)
|
|
13
|
-
.sort((left, right) => (
|
|
14
|
+
.sort((left, right) => Number(Boolean(attention?.(right.opencode_session_id))) - Number(Boolean(attention?.(left.opencode_session_id)))
|
|
15
|
+
|| (SESSION_STATE_RANK[left.state] ?? 9) - (SESSION_STATE_RANK[right.state] ?? 9)
|
|
14
16
|
|| String(right.updated_at || right.started_at || "").localeCompare(String(left.updated_at || left.started_at || ""))
|
|
15
17
|
|| Number(right.ordinal || 0) - Number(left.ordinal || 0))[0] || null;
|
|
16
18
|
|
|
17
|
-
export const sortWorkspaceSwitcherEntries = (workspaces = [], currentWorkspace = null) => [...workspaces].sort((left, right) => {
|
|
19
|
+
export const sortWorkspaceSwitcherEntries = (workspaces = [], currentWorkspace = null, attention) => [...workspaces].sort((left, right) => {
|
|
18
20
|
if (left.id === currentWorkspace) return -1;
|
|
19
21
|
if (right.id === currentWorkspace) return 1;
|
|
22
|
+
const leftAttention = Boolean(attention?.(left.id));
|
|
23
|
+
const rightAttention = Boolean(attention?.(right.id));
|
|
24
|
+
if (leftAttention !== rightAttention) return leftAttention ? -1 : 1;
|
|
20
25
|
return (WORKSPACE_STATUS_RANK[left.status] ?? 9) - (WORKSPACE_STATUS_RANK[right.status] ?? 9)
|
|
21
26
|
|| left.id.localeCompare(right.id);
|
|
22
27
|
});
|
|
@@ -24,8 +29,10 @@ export const sortWorkspaceSwitcherEntries = (workspaces = [], currentWorkspace =
|
|
|
24
29
|
const navigateToSession = (api, sessionID) => {
|
|
25
30
|
if (typeof api?.route?.navigate !== "function") return errorResult("SESSION_SWITCH_UNAVAILABLE", "This OpenCode host cannot switch sessions from a TUI plugin");
|
|
26
31
|
try {
|
|
32
|
+
const observed = attentionForSession(api, sessionID)?.eventKey;
|
|
27
33
|
api.ui?.dialog?.clear?.();
|
|
28
34
|
api.route.navigate("session", { sessionID });
|
|
35
|
+
acknowledgeNavigation(api, sessionID, observed);
|
|
29
36
|
return { ok: true, data: { opencode_session_id: sessionID, created: false } };
|
|
30
37
|
} catch (error) {
|
|
31
38
|
return errorResult(error.code || "SESSION_SWITCH_ERROR", error.message || "OpenCode could not open the selected session");
|
|
@@ -49,8 +56,10 @@ export const createWorkspaceSwitcherFlow = (api, { read = readWorkContextSnapsho
|
|
|
49
56
|
return result;
|
|
50
57
|
}
|
|
51
58
|
const data = result.data || {};
|
|
52
|
-
const
|
|
53
|
-
|
|
59
|
+
const workspaceAttention = (id) => api.workContextAttention?.attentionForWorkspace?.(id);
|
|
60
|
+
const sessionAttention = (id) => attentionForSession(api, id);
|
|
61
|
+
const workspaces = sortWorkspaceSwitcherEntries(data.workspaces || [], data.currentWorkspace, workspaceAttention)
|
|
62
|
+
.map((workspace) => ({ ...workspace, attention: workspaceAttention(workspace.id), selectedSession: selectWorkspaceSession(workspace.sessions, sessionAttention) }));
|
|
54
63
|
if (!workspaces.length) {
|
|
55
64
|
toast("No workspaces found");
|
|
56
65
|
return result;
|
|
@@ -60,9 +69,9 @@ export const createWorkspaceSwitcherFlow = (api, { read = readWorkContextSnapsho
|
|
|
60
69
|
title: "Switch workspace",
|
|
61
70
|
placeholder: "Search workspaces",
|
|
62
71
|
options: workspaces.map((workspace) => ({
|
|
63
|
-
title: `${workspace.id} ${workspace.title}${workspace.id === data.currentWorkspace ? " · current" : ""}`,
|
|
72
|
+
title: `${workspace.attention ? "[ATTN] " : ""}${workspace.id} ${workspace.title}${workspace.id === data.currentWorkspace ? " · current" : ""}`,
|
|
64
73
|
description: workspace.selectedSession
|
|
65
|
-
? `${workspace.status} · ${workspace.selectedSession.state || "unknown"} session`
|
|
74
|
+
? `${workspace.attention ? `needs attention: ${attentionReasonText(workspace.attention.reason)} (${workspace.attention.count}) · ` : ""}${workspace.status} · ${workspace.selectedSession.state || "unknown"} session`
|
|
66
75
|
: `${workspace.status} · no OpenCode session available`,
|
|
67
76
|
category: workspace.id === data.currentWorkspace ? "Current" : workspace.status,
|
|
68
77
|
disabled: !workspace.selectedSession,
|