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.
@@ -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
+ }
@@ -0,0 +1,2 @@
1
+ import { work_context_update_stage_prompt } from "../src/tool-definitions.js";
2
+ export default work_context_update_stage_prompt;
@@ -0,0 +1,2 @@
1
+ import { work_context_update_stage_result } from "../src/tool-definitions.js";
2
+ export default work_context_update_stage_result;