opencode-work-context 0.1.10 → 0.1.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/README.md +137 -14
- package/bin/opencode-work-context.js +8 -2
- package/commands/wc.md +12 -3
- package/package.json +4 -2
- package/plugin/session-switcher.js +99 -0
- package/plugin/stage-switcher.js +217 -0
- package/plugin/stages-tui.js +12 -1
- package/plugin/tui.js +13 -0
- package/plugin/work-context-modal.js +577 -0
- package/plugin/workspace-switcher.js +87 -0
- package/src/core.js +68 -44
- package/src/identifiers.js +12 -0
- package/src/index.js +2 -0
- package/src/opencode-adapter.js +1 -1
- package/src/stages-renderer.js +2 -0
- package/src/title.js +3 -2
- package/src/tool-definitions.js +16 -27
- package/src/work-context-snapshot.js +81 -0
- package/tools/work_context_update_stage_prompt.js +2 -0
- package/tools/work_context_update_stage_result.js +2 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { WorkContext } from "./core.js";
|
|
2
|
+
|
|
3
|
+
const emptySnapshot = () => ({
|
|
4
|
+
schema: 1,
|
|
5
|
+
workspaces: [],
|
|
6
|
+
currentWorkspace: null,
|
|
7
|
+
currentStage: null,
|
|
8
|
+
generatedAt: new Date().toISOString(),
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
const errorResult = (error) => ({
|
|
12
|
+
ok: false,
|
|
13
|
+
error: {
|
|
14
|
+
code: error?.code || "STORAGE_ERROR",
|
|
15
|
+
message: error?.message || "Cannot read work-context storage",
|
|
16
|
+
details: error?.details || {},
|
|
17
|
+
},
|
|
18
|
+
data: emptySnapshot(),
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const sessionFor = (context, sessionId) => {
|
|
22
|
+
if (!sessionId) return null;
|
|
23
|
+
return context.sessionById(sessionId)
|
|
24
|
+
|| context.sessionByOpenCodeId(sessionId, null, null, null);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const readWorkspace = (context, record, currentSession) => {
|
|
28
|
+
const listed = context.listStages(record.workspace).data;
|
|
29
|
+
const sessions = listed.sessions;
|
|
30
|
+
const matchingSession = currentSession?.workspace === record.workspace
|
|
31
|
+
? currentSession
|
|
32
|
+
: sessions.find((session) => session.session_id === currentSession?.session_id);
|
|
33
|
+
const currentStage = matchingSession?.stage || null;
|
|
34
|
+
return {
|
|
35
|
+
id: record.workspace,
|
|
36
|
+
title: record.title,
|
|
37
|
+
status: record.status,
|
|
38
|
+
stages: listed.stages
|
|
39
|
+
.filter((stage) => stage.status !== "archived")
|
|
40
|
+
.sort((left, right) => Number(left.stage) - Number(right.stage))
|
|
41
|
+
.map((stage) => ({
|
|
42
|
+
id: stage.stage,
|
|
43
|
+
title: stage.title,
|
|
44
|
+
status: stage.status,
|
|
45
|
+
description: stage.description,
|
|
46
|
+
current: stage.stage === currentStage,
|
|
47
|
+
})),
|
|
48
|
+
currentStage,
|
|
49
|
+
sessions,
|
|
50
|
+
activeSession: sessions.find((session) => session.state === "active") || null,
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/** Read all canonical metadata without initializing or projecting storage. */
|
|
55
|
+
export function readWorkContextSnapshot({ projectRoot, sessionId } = {}) {
|
|
56
|
+
try {
|
|
57
|
+
const context = WorkContext.openExisting(projectRoot, { sessionId, actor: "OpenCode TUI" });
|
|
58
|
+
const currentSession = sessionFor(context, sessionId);
|
|
59
|
+
const workspaces = context.listWorkspaces().data
|
|
60
|
+
.sort((left, right) => left.workspace.localeCompare(right.workspace))
|
|
61
|
+
.map((record) => readWorkspace(context, record, currentSession));
|
|
62
|
+
const currentWorkspace = currentSession?.workspace
|
|
63
|
+
&& workspaces.some((workspace) => workspace.id === currentSession.workspace)
|
|
64
|
+
? currentSession.workspace
|
|
65
|
+
: null;
|
|
66
|
+
return {
|
|
67
|
+
ok: true,
|
|
68
|
+
data: {
|
|
69
|
+
schema: 1,
|
|
70
|
+
workspaces,
|
|
71
|
+
currentWorkspace,
|
|
72
|
+
currentStage: currentWorkspace
|
|
73
|
+
? workspaces.find((workspace) => workspace.id === currentWorkspace)?.currentStage || null
|
|
74
|
+
: null,
|
|
75
|
+
generatedAt: new Date().toISOString(),
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
} catch (error) {
|
|
79
|
+
return errorResult(error);
|
|
80
|
+
}
|
|
81
|
+
}
|