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,87 @@
|
|
|
1
|
+
import { readWorkContextSnapshot } from "../src/work-context-snapshot.js";
|
|
2
|
+
|
|
3
|
+
const SESSION_STATE_RANK = { active: 0, handed_off: 1, abandoned: 2, closed: 3 };
|
|
4
|
+
const WORKSPACE_STATUS_RANK = { in_progress: 0, planned: 1, completed: 2, cancelled: 3 };
|
|
5
|
+
|
|
6
|
+
const errorResult = (code, message, details = {}) => ({ ok: false, error: { code, message, details } });
|
|
7
|
+
const currentSessionId = (api) => api?.route?.current?.params?.sessionID || api?.route?.current?.params?.sessionId;
|
|
8
|
+
const projectRoot = (api) => api?.state?.path?.worktree || api?.state?.path?.directory;
|
|
9
|
+
|
|
10
|
+
/** Select the best existing OpenCode session without changing work-context state. */
|
|
11
|
+
export const selectWorkspaceSession = (sessions = []) => sessions
|
|
12
|
+
.filter((session) => session.opencode_session_id)
|
|
13
|
+
.sort((left, right) => (SESSION_STATE_RANK[left.state] ?? 9) - (SESSION_STATE_RANK[right.state] ?? 9)
|
|
14
|
+
|| String(right.updated_at || right.started_at || "").localeCompare(String(left.updated_at || left.started_at || ""))
|
|
15
|
+
|| Number(right.ordinal || 0) - Number(left.ordinal || 0))[0] || null;
|
|
16
|
+
|
|
17
|
+
export const sortWorkspaceSwitcherEntries = (workspaces = [], currentWorkspace = null) => [...workspaces].sort((left, right) => {
|
|
18
|
+
if (left.id === currentWorkspace) return -1;
|
|
19
|
+
if (right.id === currentWorkspace) return 1;
|
|
20
|
+
return (WORKSPACE_STATUS_RANK[left.status] ?? 9) - (WORKSPACE_STATUS_RANK[right.status] ?? 9)
|
|
21
|
+
|| left.id.localeCompare(right.id);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const navigateToSession = (api, sessionID) => {
|
|
25
|
+
if (typeof api?.route?.navigate !== "function") return errorResult("SESSION_SWITCH_UNAVAILABLE", "This OpenCode host cannot switch sessions from a TUI plugin");
|
|
26
|
+
try {
|
|
27
|
+
api.ui?.dialog?.clear?.();
|
|
28
|
+
api.route.navigate("session", { sessionID });
|
|
29
|
+
return { ok: true, data: { opencode_session_id: sessionID, created: false } };
|
|
30
|
+
} catch (error) {
|
|
31
|
+
return errorResult(error.code || "SESSION_SWITCH_ERROR", error.message || "OpenCode could not open the selected session");
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const switchToWorkspace = (api, workspace) => {
|
|
36
|
+
const session = workspace.selectedSession || selectWorkspaceSession(workspace.sessions);
|
|
37
|
+
if (!session) return errorResult("WORKSPACE_SESSION_UNAVAILABLE", "This workspace has no OpenCode-backed session to open", { workspace: workspace.id });
|
|
38
|
+
return navigateToSession(api, session.opencode_session_id);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const createWorkspaceSwitcherFlow = (api, { read = readWorkContextSnapshot } = {}) => {
|
|
42
|
+
const toast = (message, variant = "warning") => api?.ui?.toast?.({ message, variant });
|
|
43
|
+
const open = async () => {
|
|
44
|
+
let result;
|
|
45
|
+
try { result = await read({ projectRoot: projectRoot(api), sessionId: currentSessionId(api) }); }
|
|
46
|
+
catch (error) { result = errorResult(error.code || "STORAGE_ERROR", error.message || "Cannot read work-context storage"); }
|
|
47
|
+
if (!result?.ok) {
|
|
48
|
+
toast(`${result?.error?.code || "STORAGE_ERROR"}: ${result?.error?.message || "Cannot read work-context storage"}`, "error");
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
const data = result.data || {};
|
|
52
|
+
const workspaces = sortWorkspaceSwitcherEntries(data.workspaces || [], data.currentWorkspace)
|
|
53
|
+
.map((workspace) => ({ ...workspace, selectedSession: selectWorkspaceSession(workspace.sessions) }));
|
|
54
|
+
if (!workspaces.length) {
|
|
55
|
+
toast("No workspaces found");
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
api.ui.dialog.setSize?.("medium");
|
|
59
|
+
api.ui.dialog.replace(() => api.ui.DialogSelect({
|
|
60
|
+
title: "Switch workspace",
|
|
61
|
+
placeholder: "Search workspaces",
|
|
62
|
+
options: workspaces.map((workspace) => ({
|
|
63
|
+
title: `${workspace.id} ${workspace.title}${workspace.id === data.currentWorkspace ? " · current" : ""}`,
|
|
64
|
+
description: workspace.selectedSession
|
|
65
|
+
? `${workspace.status} · ${workspace.selectedSession.state || "unknown"} session`
|
|
66
|
+
: `${workspace.status} · no OpenCode session available`,
|
|
67
|
+
footer: workspace.selectedSession?.opencode_session_id,
|
|
68
|
+
category: workspace.id === data.currentWorkspace ? "Current" : workspace.status,
|
|
69
|
+
disabled: !workspace.selectedSession,
|
|
70
|
+
value: workspace,
|
|
71
|
+
})),
|
|
72
|
+
onSelect: (option) => {
|
|
73
|
+
const switched = switchToWorkspace(api, option.value);
|
|
74
|
+
if (!switched.ok) toast(`${switched.error.code}: ${switched.error.message}`, "error");
|
|
75
|
+
else toast("Workspace session opened", "success");
|
|
76
|
+
},
|
|
77
|
+
}));
|
|
78
|
+
return result;
|
|
79
|
+
};
|
|
80
|
+
return { open };
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export const openWorkspaceSwitcher = (api, options = {}) => {
|
|
84
|
+
if (typeof api?.ui?.DialogSelect !== "function" || typeof api?.ui?.dialog?.replace !== "function") return false;
|
|
85
|
+
void createWorkspaceSwitcherFlow(api, options).open();
|
|
86
|
+
return true;
|
|
87
|
+
};
|
package/src/core.js
CHANGED
|
@@ -6,19 +6,18 @@ import { ERROR_CODES, fail } from "./errors.js";
|
|
|
6
6
|
import { event, reduceSessions, activeSession, assertActive } from "./sessions.js";
|
|
7
7
|
import { generateProjections, renderSessions } from "./projections.js";
|
|
8
8
|
import { nextKnowledgeId, parseKnowledge, renderKnowledge, validateKnowledgeInput, validateKnowledgeRecords } from "./knowledge.js";
|
|
9
|
+
import { normalizeStageId, normalizeWorkspaceId } from "./identifiers.js";
|
|
9
10
|
|
|
10
|
-
const id = (value, digits) => {
|
|
11
|
-
const normalized = String(value);
|
|
12
|
-
if (!new RegExp(`^\\d{${digits}}$`).test(normalized)) fail(ERROR_CODES.INVALID_ARGUMENT, `Expected ${digits}-digit identifier`);
|
|
13
|
-
return normalized;
|
|
14
|
-
};
|
|
15
|
-
const stageId = (value) => id(String(value).padStart(2, "0"), 2);
|
|
16
11
|
const actor = (options) => options.actor || "OpenCode";
|
|
12
|
+
const activeKnowledge = (records) => records
|
|
13
|
+
.filter((record) => record.status === "active")
|
|
14
|
+
.map(({ id: knowledgeId, title, kind, text, sources }) => ({ id: knowledgeId, title, kind, text, sources }));
|
|
17
15
|
const body = (title, goal = "", prompt = "") => `# ${title}\n\n${goal ? `## Goal\n\n${goal}\n` : ""}${prompt ? `\n## Prompt\n\n${prompt}\n` : ""}`;
|
|
18
16
|
const stageBody = (record, title, goal, prompt = record.data.prompt || "") => {
|
|
19
17
|
const result = record.body.match(/\n## Result[\s\S]*$/)?.[0] || "";
|
|
20
18
|
return `${body(title, goal, prompt).trimEnd()}${result}`;
|
|
21
19
|
};
|
|
20
|
+
const stageResult = (record) => record.body.match(/\n## Result\s*\n([\s\S]*)$/)?.[1]?.trim() ?? null;
|
|
22
21
|
const assertNoSymlinkPath = (file) => { let current = path.parse(file).root; for (const part of file.slice(current.length).split(path.sep).filter(Boolean)) { current = path.join(current, part); try { if (fs.lstatSync(current).isSymbolicLink()) fail(ERROR_CODES.STORAGE_ERROR, `Symlink path component is not supported: ${current}`); } catch (error) { if (error.code !== "ENOENT") throw error; break; } } };
|
|
23
22
|
|
|
24
23
|
function parseIssue(url) {
|
|
@@ -92,7 +91,7 @@ export class WorkContext {
|
|
|
92
91
|
|
|
93
92
|
listStages(workspace) {
|
|
94
93
|
this.storage.assertNoSymlinks();
|
|
95
|
-
|
|
94
|
+
workspace = normalizeWorkspaceId(workspace);
|
|
96
95
|
const dir = path.join(this.storage.workspaceDir(workspace), "stages");
|
|
97
96
|
if (!fs.existsSync(dir)) fail(ERROR_CODES.NOT_FOUND, "Workspace not found");
|
|
98
97
|
const stages = fs.readdirSync(dir).filter((file) => /^\d{2}\.md$/.test(file)).map((file) => {
|
|
@@ -117,7 +116,7 @@ export class WorkContext {
|
|
|
117
116
|
}
|
|
118
117
|
|
|
119
118
|
finishWorkspace(workspace) {
|
|
120
|
-
|
|
119
|
+
workspace = normalizeWorkspaceId(workspace);
|
|
121
120
|
return this.transact(`workspace-${workspace}`, () => {
|
|
122
121
|
const record = this.storage.readWorkspace(workspace);
|
|
123
122
|
const stages = this.listStages(workspace).data.stages;
|
|
@@ -159,14 +158,13 @@ export class WorkContext {
|
|
|
159
158
|
if (!title?.trim()) fail(ERROR_CODES.INVALID_ARGUMENT, "Title is required");
|
|
160
159
|
const requestedWorkspace = options.workspace;
|
|
161
160
|
return this.transact("workspace-create", () => {
|
|
162
|
-
const workspace = requestedWorkspace
|
|
163
|
-
id(workspace, 6);
|
|
161
|
+
const workspace = requestedWorkspace === undefined ? this.nextWorkspace() : normalizeWorkspaceId(requestedWorkspace);
|
|
164
162
|
const now = new Date().toISOString();
|
|
165
163
|
if (fs.existsSync(this.storage.workspaceDir(workspace))) fail(ERROR_CODES.CONFLICT, "Workspace already exists");
|
|
166
164
|
fs.mkdirSync(path.join(this.storage.workspaceDir(workspace), "stages"), { recursive: true });
|
|
167
165
|
this.storage.writeMarkdown(this.storage.workspaceFile(workspace), { schema: 1, workspace, title: title.trim(), status: "in_progress", created_at: now, updated_at: now, tracker_links: [] }, body(title));
|
|
168
166
|
const planningGoal = "Clarify the work goal and constraints";
|
|
169
|
-
const planningPrompt = "Diagnose and plan the task without functional changes. Discuss possible solutions, record constraints, and decompose the work into the following stages. For each new implementation stage, write a separate detailed prompt with context, concrete actions, constraints, completion criteria, and the expected result. Ask clarifying questions only when genuinely blocked.";
|
|
167
|
+
const planningPrompt = "Diagnose and plan the task without functional changes. Discuss possible solutions, record durable workspace-wide facts, decisions, constraints, important files, and risks through explicit knowledge operations, and decompose the work into the following stages. For each new implementation stage, write a separate detailed prompt with local context, concrete actions, constraints, completion criteria, and the expected result; do not duplicate shared knowledge that every stage receives in resume.context.workspace_knowledge. Ask clarifying questions only when genuinely blocked.";
|
|
170
168
|
this.storage.writeMarkdown(this.storage.stageFile(workspace, "01"), { schema: 1, workspace, stage: "01", title: "Planning", status: "in_progress", goal: planningGoal, prompt: planningPrompt, depends_on: [], owner: actor(this.options), created_at: now, updated_at: now, tracker_links: [] }, body("Planning", planningGoal, planningPrompt));
|
|
171
169
|
const sessionId = options.sessionId || randomUUID();
|
|
172
170
|
if (this.storage.readEvents().some((item) => item.session_id === sessionId)) fail(ERROR_CODES.CONFLICT, "Session ID already exists");
|
|
@@ -188,6 +186,7 @@ export class WorkContext {
|
|
|
188
186
|
essence: planningGoal,
|
|
189
187
|
previous: "The previous session did not save a result; the stopping point needs to be clarified.",
|
|
190
188
|
now: planningPrompt,
|
|
189
|
+
workspace_knowledge: [],
|
|
191
190
|
},
|
|
192
191
|
next_action: "start_work",
|
|
193
192
|
instruction: planningPrompt,
|
|
@@ -197,7 +196,7 @@ export class WorkContext {
|
|
|
197
196
|
}
|
|
198
197
|
|
|
199
198
|
renameWorkspace(workspace, title) {
|
|
200
|
-
|
|
199
|
+
workspace = normalizeWorkspaceId(workspace);
|
|
201
200
|
if (!title?.trim()) fail(ERROR_CODES.INVALID_ARGUMENT, "Title is required");
|
|
202
201
|
return this.transact(`workspace-${workspace}`, () => {
|
|
203
202
|
const record = this.storage.readWorkspace(workspace);
|
|
@@ -217,8 +216,8 @@ export class WorkContext {
|
|
|
217
216
|
}
|
|
218
217
|
|
|
219
218
|
startSession(workspace, stage, options = {}) {
|
|
220
|
-
|
|
221
|
-
stage =
|
|
219
|
+
workspace = normalizeWorkspaceId(workspace);
|
|
220
|
+
stage = normalizeStageId(stage);
|
|
222
221
|
const sessionId = options.sessionId || randomUUID();
|
|
223
222
|
return this.transact(`stage-${workspace}-${stage}`, () => {
|
|
224
223
|
const stageRecord = this.storage.readStage(workspace, stage);
|
|
@@ -246,6 +245,7 @@ export class WorkContext {
|
|
|
246
245
|
const previousSession = previous.at(-1) || null;
|
|
247
246
|
const firstResume = previous.length === 0;
|
|
248
247
|
const hasPrompt = Boolean(stageRecord.data.prompt?.trim());
|
|
248
|
+
const workspaceKnowledge = activeKnowledge(this.listKnowledge(workspace).data);
|
|
249
249
|
return this.result({
|
|
250
250
|
workspace,
|
|
251
251
|
stage,
|
|
@@ -264,6 +264,7 @@ export class WorkContext {
|
|
|
264
264
|
essence: stageRecord.data.goal || stageRecord.data.title,
|
|
265
265
|
previous: previousSession?.summary || "The previous session did not save a result; the stopping point needs to be clarified.",
|
|
266
266
|
now: hasPrompt ? stageRecord.data.prompt : "First clarify the task and work plan with the user.",
|
|
267
|
+
workspace_knowledge: workspaceKnowledge,
|
|
267
268
|
},
|
|
268
269
|
next_action: hasPrompt ? (firstResume ? "start_work" : "await_confirmation") : "ask_questions",
|
|
269
270
|
instruction: hasPrompt
|
|
@@ -278,10 +279,11 @@ export class WorkContext {
|
|
|
278
279
|
}
|
|
279
280
|
|
|
280
281
|
addStage(workspace, title, options = {}) {
|
|
281
|
-
|
|
282
|
+
workspace = normalizeWorkspaceId(workspace);
|
|
282
283
|
if (!title?.trim()) fail(ERROR_CODES.INVALID_ARGUMENT, "Title is required");
|
|
283
|
-
|
|
284
|
-
|
|
284
|
+
if (!Array.isArray(options.dependsOn || [])) fail(ERROR_CODES.INVALID_ARGUMENT, "dependsOn must contain unique stage IDs");
|
|
285
|
+
const dependsOn = (options.dependsOn || []).map(normalizeStageId);
|
|
286
|
+
if (new Set(dependsOn).size !== dependsOn.length) fail(ERROR_CODES.INVALID_ARGUMENT, "dependsOn must contain unique stage IDs");
|
|
285
287
|
return this.transact(`workspace-${workspace}`, () => {
|
|
286
288
|
const stages = this.listStages(workspace).data.stages;
|
|
287
289
|
if (stages.length >= 99) fail(ERROR_CODES.INVALID_STATE, "A workspace cannot contain more than 99 stages");
|
|
@@ -293,13 +295,13 @@ export class WorkContext {
|
|
|
293
295
|
const metadata = { schema: 1, workspace, stage, title: title.trim(), status: "planned", goal: options.goal || title.trim(), ...(prompt ? { prompt } : {}), depends_on: dependsOn, owner: options.owner || actor(this.options), created_at: now, updated_at: now, tracker_links: [] };
|
|
294
296
|
this.storage.writeMarkdown(this.storage.stageFile(workspace, stage), metadata, body(title, options.goal || title, prompt));
|
|
295
297
|
generateProjections(this.storage);
|
|
296
|
-
return this.result({ workspace, stage }, [stage]);
|
|
298
|
+
return this.result({ workspace, stage, status: "planned", session_started: false, resume_required: true }, [stage]);
|
|
297
299
|
});
|
|
298
300
|
}
|
|
299
301
|
|
|
300
302
|
renameStage(workspace, stage, title) {
|
|
301
|
-
|
|
302
|
-
stage =
|
|
303
|
+
workspace = normalizeWorkspaceId(workspace);
|
|
304
|
+
stage = normalizeStageId(stage);
|
|
303
305
|
if (!title?.trim()) fail(ERROR_CODES.INVALID_ARGUMENT, "Title is required");
|
|
304
306
|
return this.transact(`stage-${workspace}-${stage}`, () => {
|
|
305
307
|
const record = this.storage.readStage(workspace, stage);
|
|
@@ -314,8 +316,8 @@ export class WorkContext {
|
|
|
314
316
|
}
|
|
315
317
|
|
|
316
318
|
updateStage(workspace, stage, description) {
|
|
317
|
-
|
|
318
|
-
stage =
|
|
319
|
+
workspace = normalizeWorkspaceId(workspace);
|
|
320
|
+
stage = normalizeStageId(stage);
|
|
319
321
|
if (!description?.trim()) fail(ERROR_CODES.INVALID_ARGUMENT, "Description is required");
|
|
320
322
|
return this.transact(`stage-${workspace}-${stage}`, () => {
|
|
321
323
|
const record = this.storage.readStage(workspace, stage);
|
|
@@ -330,8 +332,8 @@ export class WorkContext {
|
|
|
330
332
|
}
|
|
331
333
|
|
|
332
334
|
updateStagePrompt(workspace, stage, prompt) {
|
|
333
|
-
|
|
334
|
-
stage =
|
|
335
|
+
workspace = normalizeWorkspaceId(workspace);
|
|
336
|
+
stage = normalizeStageId(stage);
|
|
335
337
|
if (!prompt?.trim()) fail(ERROR_CODES.INVALID_ARGUMENT, "Prompt is required");
|
|
336
338
|
return this.transact(`stage-${workspace}-${stage}`, () => {
|
|
337
339
|
const record = this.storage.readStage(workspace, stage);
|
|
@@ -345,9 +347,27 @@ export class WorkContext {
|
|
|
345
347
|
});
|
|
346
348
|
}
|
|
347
349
|
|
|
350
|
+
updateStageResult(workspace, stage, result) {
|
|
351
|
+
workspace = normalizeWorkspaceId(workspace);
|
|
352
|
+
stage = normalizeStageId(stage);
|
|
353
|
+
if (!result?.trim()) fail(ERROR_CODES.INVALID_ARGUMENT, "Result is required");
|
|
354
|
+
return this.transact(`stage-${workspace}-${stage}`, () => {
|
|
355
|
+
const record = this.storage.readStage(workspace, stage);
|
|
356
|
+
const currentResult = stageResult(record);
|
|
357
|
+
if (currentResult === null) fail(ERROR_CODES.INVALID_STATE, "Stage has no result to update");
|
|
358
|
+
const nextResult = result.trim();
|
|
359
|
+
if (currentResult === nextResult) return this.result({ workspace, stage, result: nextResult }, []);
|
|
360
|
+
record.data.updated_at = new Date().toISOString();
|
|
361
|
+
const nextBody = `${body(record.data.title, record.data.goal, record.data.prompt).trimEnd()}\n\n## Result\n\n${nextResult}`;
|
|
362
|
+
this.storage.writeMarkdown(this.storage.stageFile(workspace, stage), record.data, nextBody);
|
|
363
|
+
generateProjections(this.storage);
|
|
364
|
+
return this.result({ workspace, stage, result: nextResult }, [workspace, stage]);
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
|
|
348
368
|
archiveStage(workspace, stage) {
|
|
349
|
-
|
|
350
|
-
stage =
|
|
369
|
+
workspace = normalizeWorkspaceId(workspace);
|
|
370
|
+
stage = normalizeStageId(stage);
|
|
351
371
|
return this.transact(`stage-${workspace}-${stage}`, () => {
|
|
352
372
|
const record = this.storage.readStage(workspace, stage);
|
|
353
373
|
if (record.data.status === "archived") return this.result({ workspace, stage, status: "archived" }, []);
|
|
@@ -361,7 +381,7 @@ export class WorkContext {
|
|
|
361
381
|
}
|
|
362
382
|
|
|
363
383
|
listKnowledge(workspace) {
|
|
364
|
-
|
|
384
|
+
workspace = normalizeWorkspaceId(workspace);
|
|
365
385
|
this.storage.assertNoSymlinks();
|
|
366
386
|
this.storage.readWorkspace(workspace);
|
|
367
387
|
const text = this.storage.readKnowledge(workspace);
|
|
@@ -369,7 +389,7 @@ export class WorkContext {
|
|
|
369
389
|
}
|
|
370
390
|
|
|
371
391
|
addKnowledge(workspace, input) {
|
|
372
|
-
|
|
392
|
+
workspace = normalizeWorkspaceId(workspace);
|
|
373
393
|
validateKnowledgeInput(input);
|
|
374
394
|
return this.transact(`workspace-${workspace}`, () => {
|
|
375
395
|
const records = this.listKnowledge(workspace).data;
|
|
@@ -381,7 +401,7 @@ export class WorkContext {
|
|
|
381
401
|
}
|
|
382
402
|
|
|
383
403
|
updateKnowledge(workspace, knowledgeId, input) {
|
|
384
|
-
|
|
404
|
+
workspace = normalizeWorkspaceId(workspace);
|
|
385
405
|
validateKnowledgeInput(input, true);
|
|
386
406
|
return this.transact(`workspace-${workspace}`, () => {
|
|
387
407
|
const records = this.listKnowledge(workspace).data;
|
|
@@ -402,10 +422,10 @@ export class WorkContext {
|
|
|
402
422
|
}
|
|
403
423
|
|
|
404
424
|
linkIssue(workspace, url, stage = null) {
|
|
405
|
-
const normalizedWorkspace =
|
|
406
|
-
const normalizedStage = stage ?
|
|
425
|
+
const normalizedWorkspace = normalizeWorkspaceId(workspace);
|
|
426
|
+
const normalizedStage = stage === null || stage === undefined ? null : normalizeStageId(stage);
|
|
407
427
|
const parsed = parseIssue(url);
|
|
408
|
-
return this.transact(`link-${
|
|
428
|
+
return this.transact(`link-${normalizedWorkspace}-${normalizedStage || "workspace"}`, () => {
|
|
409
429
|
const file = normalizedStage ? this.storage.stageFile(normalizedWorkspace, normalizedStage) : this.storage.workspaceFile(normalizedWorkspace);
|
|
410
430
|
const current = normalizedStage ? this.storage.readStage(normalizedWorkspace, normalizedStage) : this.storage.readWorkspace(normalizedWorkspace);
|
|
411
431
|
const links = current.data.tracker_links || [];
|
|
@@ -421,7 +441,8 @@ export class WorkContext {
|
|
|
421
441
|
|
|
422
442
|
renameSession(workspace, stage, sessionId, summary) {
|
|
423
443
|
if (!summary?.trim()) fail(ERROR_CODES.INVALID_ARGUMENT, "Summary is required");
|
|
424
|
-
|
|
444
|
+
workspace = normalizeWorkspaceId(workspace);
|
|
445
|
+
stage = normalizeStageId(stage);
|
|
425
446
|
return this.transact(`stage-${workspace}-${stage}`, () => {
|
|
426
447
|
const session = assertActive(this.storage.readEvents(), workspace, stage, sessionId);
|
|
427
448
|
if (session.summary === summary.trim()) return this.result({ session_id: sessionId, summary: summary.trim() }, []);
|
|
@@ -431,7 +452,8 @@ export class WorkContext {
|
|
|
431
452
|
}
|
|
432
453
|
|
|
433
454
|
closeSession(workspace, stage, sessionId, reason = "closed", state = "closed") {
|
|
434
|
-
|
|
455
|
+
workspace = normalizeWorkspaceId(workspace);
|
|
456
|
+
stage = normalizeStageId(stage);
|
|
435
457
|
return this.transact(`stage-${workspace}-${stage}`, () => {
|
|
436
458
|
const session = assertActive(this.storage.readEvents(), workspace, stage, sessionId);
|
|
437
459
|
this.writeEvents([event(`session.${state}`, workspace, stage, session.ordinal, sessionId, actor(this.options), { reason })]);
|
|
@@ -440,8 +462,8 @@ export class WorkContext {
|
|
|
440
462
|
}
|
|
441
463
|
|
|
442
464
|
forceCloseSession(workspace, stage, sessionId, reason, confirmation) {
|
|
443
|
-
|
|
444
|
-
stage =
|
|
465
|
+
workspace = normalizeWorkspaceId(workspace);
|
|
466
|
+
stage = normalizeStageId(stage);
|
|
445
467
|
if (!sessionId?.trim()) fail(ERROR_CODES.INVALID_ARGUMENT, "Session ID is required");
|
|
446
468
|
if (!reason?.trim()) fail(ERROR_CODES.INVALID_ARGUMENT, "Force-close reason is required");
|
|
447
469
|
if (confirmation !== "FORCE_CLOSE") fail(ERROR_CODES.CONFIRMATION_REQUIRED, "Force close requires confirmation FORCE_CLOSE", { expected: "FORCE_CLOSE" });
|
|
@@ -459,7 +481,8 @@ export class WorkContext {
|
|
|
459
481
|
}
|
|
460
482
|
|
|
461
483
|
handoff(workspace, stage, sessionId, options = {}) {
|
|
462
|
-
|
|
484
|
+
workspace = normalizeWorkspaceId(workspace);
|
|
485
|
+
stage = normalizeStageId(stage);
|
|
463
486
|
return this.transact(`stage-${workspace}-${stage}`, () => {
|
|
464
487
|
const session = assertActive(this.storage.readEvents(), workspace, stage, sessionId);
|
|
465
488
|
this.writeEvents([event("session.handed_off", workspace, stage, session.ordinal, sessionId, actor(this.options), { reason: options.reason || "handoff" })]);
|
|
@@ -473,7 +496,8 @@ export class WorkContext {
|
|
|
473
496
|
}
|
|
474
497
|
|
|
475
498
|
finish(workspace, stage, sessionId, options = {}) {
|
|
476
|
-
|
|
499
|
+
workspace = normalizeWorkspaceId(workspace);
|
|
500
|
+
stage = normalizeStageId(stage);
|
|
477
501
|
return this.transact(`stage-${workspace}-${stage}`, () => {
|
|
478
502
|
const events = this.storage.readEvents();
|
|
479
503
|
const current = this.storage.readStage(workspace, stage);
|
|
@@ -485,7 +509,7 @@ export class WorkContext {
|
|
|
485
509
|
}
|
|
486
510
|
const knowledgeReview = options.knowledgeReview || "auto";
|
|
487
511
|
if (!['auto', 'added', 'none'].includes(knowledgeReview)) fail(ERROR_CODES.INVALID_ARGUMENT, "Knowledge review must be 'auto', 'added' or 'none'");
|
|
488
|
-
const knowledgeEntries =
|
|
512
|
+
const knowledgeEntries = this.listKnowledge(workspace).data;
|
|
489
513
|
const active = activeSession(events, workspace, stage);
|
|
490
514
|
if (!active || active.session_id !== sessionId) fail(active ? ERROR_CODES.ACTIVE_SESSION_EXISTS : ERROR_CODES.SESSION_NOT_ACTIVE, active ? "Another active session owns this stage" : "Session is not active");
|
|
491
515
|
this.writeEvents([event("session.closed", workspace, stage, active.ordinal, sessionId, actor(this.options), { reason: "stage_completed" })]);
|
|
@@ -493,10 +517,10 @@ export class WorkContext {
|
|
|
493
517
|
current.data.updated_at = new Date().toISOString();
|
|
494
518
|
this.storage.writeMarkdown(this.storage.stageFile(workspace, stage), current.data, `${current.body}\n\n## Result\n\n${options.result || "Stage completed."}`);
|
|
495
519
|
generateProjections(this.storage);
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
520
|
+
const promptReview = this.listStages(workspace).data.stages
|
|
521
|
+
.filter((item) => Number(item.stage) > Number(stage) && !["completed", "archived"].includes(item.status))
|
|
522
|
+
.map(({ stage: id, title, description, prompt, status }) => ({ stage: id, title, description, prompt: prompt || null, status }));
|
|
523
|
+
const data = { session_id: sessionId, workspace, stage, state: "closed", status: "completed", next_stage_started: false, knowledge_review: knowledgeReview, knowledge_entries: knowledgeEntries.length, active_knowledge_entries: activeKnowledge(knowledgeEntries).length, prompt_review: promptReview };
|
|
500
524
|
const incompleteStages = this.listStages(workspace).data.stages.filter((item) => !["completed", "archived"].includes(item.status));
|
|
501
525
|
const next = incompleteStages.length ? null : {
|
|
502
526
|
action: "workspace_finish",
|
|
@@ -509,7 +533,7 @@ export class WorkContext {
|
|
|
509
533
|
}
|
|
510
534
|
|
|
511
535
|
help(command = "") {
|
|
512
|
-
return this.result({ command, syntax: "/wc [create|list|workspace list|workspace rename|workspace finish|resume|stage add|stage rename|stage update|stage update-prompt|stage force-close|stage archive|stage handoff|stage abandon|stage finish|link-issue|session rename|knowledge list|knowledge add|knowledge update|knowledge supersede|help]", note: "workspace and stage are optional for stage rename/update/update-prompt/archive/handoff/abandon/finish and session rename/close when the current session identifies them; finish <stage> is a shortcut for stage finish <stage>; when only one numeric identifier is supplied, six digits mean workspace and one or two digits mean stage; stage add accepts an optional prompt
|
|
536
|
+
return this.result({ command, syntax: "/wc [create|list|workspace list|workspace rename|workspace finish|resume|stage add|stage rename|stage update|stage update-prompt|stage update-result|stage force-close|stage archive|stage handoff|stage abandon|stage finish|link-issue|session rename|knowledge list|knowledge add|knowledge update|knowledge supersede|help]", note: "workspace and stage are optional for stage rename/update/update-prompt/update-result/archive/handoff/abandon/finish and session rename/close when the current session identifies them; explicit workspace and stage positions accept padded or unpadded positive integer IDs and structured results remain canonical; zero, signs, decimals, whitespace, and overlong identifiers are invalid; stage update-result requires an existing stage result; finish <stage> is a shortcut for stage finish <stage>; when only one numeric identifier is supplied, six digits mean workspace and one or two digits mean stage; stage add accepts an optional local prompt and only creates a planned stage; entering any added stage requires an explicit resume in a new OpenCode session; resume returns resume.next_action, resume.instruction, and active shared entries in resume.context.workspace_knowledge; implementation may begin only with a non-empty prompt and no unanswered questions; ask focused questions and do not modify application code when next_action is ask_questions; force-close requires a session ID, reason, and exact confirmation FORCE_CLOSE; before stage finish, add, update, or supersede durable findings, or explicitly declare none; stage finish closes only the current stage session and returns downstream stages for informational prompt review without starting one; workspace finish requires all non-archived stages to be completed; archived stages retain their IDs and history and are hidden from the TUI by default; mutating commands call structured tools; only explicit lifecycle operations change storage." }, []);
|
|
513
537
|
}
|
|
514
538
|
|
|
515
539
|
result(data, changed, next = null) {
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ERROR_CODES, fail } from "./errors.js";
|
|
2
|
+
|
|
3
|
+
const normalizeIdentifier = (value, { name, digits }) => {
|
|
4
|
+
const input = typeof value === "string" ? value : "";
|
|
5
|
+
if (!new RegExp(`^\\d{1,${digits}}$`).test(input) || Number(input) === 0) {
|
|
6
|
+
fail(ERROR_CODES.INVALID_ARGUMENT, `${name} ID must be an integer from 1 to ${"9".repeat(digits)}`);
|
|
7
|
+
}
|
|
8
|
+
return input.padStart(digits, "0");
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const normalizeWorkspaceId = (value) => normalizeIdentifier(value, { name: "Workspace", digits: 6 });
|
|
12
|
+
export const normalizeStageId = (value) => normalizeIdentifier(value, { name: "Stage", digits: 2 });
|
package/src/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export * from "./errors.js";
|
|
2
|
+
export * from "./identifiers.js";
|
|
2
3
|
export * from "./markdown.js";
|
|
3
4
|
export * from "./storage.js";
|
|
4
5
|
export * from "./sessions.js";
|
|
@@ -8,3 +9,4 @@ export * from "./core.js";
|
|
|
8
9
|
export * from "./knowledge.js";
|
|
9
10
|
export * from "./stages-snapshot.js";
|
|
10
11
|
export * from "./stages-renderer.js";
|
|
12
|
+
export * from "./work-context-snapshot.js";
|
package/src/opencode-adapter.js
CHANGED
|
@@ -12,6 +12,6 @@ export function titleFor(context, workspace, stage, sessionId, knownSession = nu
|
|
|
12
12
|
if (!current) return null;
|
|
13
13
|
const meta = context.storage.readWorkspace(workspace).data;
|
|
14
14
|
const stageMeta = context.storage.readStage(workspace, stage).data;
|
|
15
|
-
return renderTitle({ workspace,
|
|
15
|
+
return renderTitle({ workspace, stageTitle: stageMeta.title, stage, ordinal: current.ordinal, state: current.state, trackerLinks: stageMeta.tracker_links?.length ? stageMeta.tracker_links : meta.tracker_links, issuePrefix: context.storage.config.title?.issue_prefix || "short" });
|
|
16
16
|
}
|
|
17
17
|
export const packageRoot = () => path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
package/src/stages-renderer.js
CHANGED
|
@@ -12,6 +12,8 @@ export function renderStagesPanel(result) {
|
|
|
12
12
|
if (!snapshot.workspace) return `work-context stages\n(no workspace for this session)${result.stale ? `\n! stale: ${result.error?.code || "STORAGE_ERROR"}` : ""}`;
|
|
13
13
|
|
|
14
14
|
const lines = [
|
|
15
|
+
snapshot.workspace.title,
|
|
16
|
+
"",
|
|
15
17
|
`Stages · ${snapshot.workspace.status}`,
|
|
16
18
|
];
|
|
17
19
|
for (const stage of snapshot.stages) {
|
package/src/title.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export function renderTitle({ workspace,
|
|
1
|
+
export function renderTitle({ workspace, stageTitle, stage, ordinal, state = "active", trackerLinks = [], issuePrefix = "short" }) {
|
|
2
2
|
const link = trackerLinks[0]; let prefix = "";
|
|
3
3
|
if (link && issuePrefix !== "none") {
|
|
4
4
|
const identifier = link.key || link.iid;
|
|
@@ -6,5 +6,6 @@ export function renderTitle({ workspace, workspaceTitle, stage, ordinal, state =
|
|
|
6
6
|
prefix = issuePrefix === "full" ? `${link.project}#${identifier} | ` : `${short} | `;
|
|
7
7
|
}
|
|
8
8
|
const suffix = state === "active" ? "" : ` (${state})`;
|
|
9
|
-
|
|
9
|
+
const description = (stageTitle || stage).replace(/[\r\n|]+/g, " ").trim().slice(0, 80);
|
|
10
|
+
return `${description}\n${prefix}${workspace} ${stage}/${String(ordinal).padStart(2, "0")}${suffix}`;
|
|
10
11
|
}
|
package/src/tool-definitions.js
CHANGED
|
@@ -2,6 +2,7 @@ import { tool } from "@opencode-ai/plugin";
|
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
3
|
import { contextFor, titleFor } from "../src/opencode-adapter.js";
|
|
4
4
|
import { fail, ERROR_CODES } from "../src/errors.js";
|
|
5
|
+
import { normalizeStageId, normalizeWorkspaceId } from "../src/identifiers.js";
|
|
5
6
|
|
|
6
7
|
const run = (fn) => async (args, context) => {
|
|
7
8
|
try {
|
|
@@ -12,18 +13,18 @@ const run = (fn) => async (args, context) => {
|
|
|
12
13
|
return { output: JSON.stringify({ ok: false, error: { code: error.code || "STORAGE_ERROR", message: error.message, details: error.details || {} } }), metadata: { code: error.code || "STORAGE_ERROR" } };
|
|
13
14
|
}
|
|
14
15
|
};
|
|
15
|
-
const common = { workspace: tool.schema.string()
|
|
16
|
-
const contextualStage = { workspace: tool.schema.string().
|
|
16
|
+
const common = { workspace: tool.schema.string(), stage: tool.schema.string() };
|
|
17
|
+
const contextualStage = { workspace: tool.schema.string().optional(), stage: tool.schema.string().optional() };
|
|
17
18
|
const sessionFromContext = (ctx, workspace) => ctx.sessionByOpenCodeId(ctx.options.sessionId, workspace || null, null, null)
|
|
18
19
|
|| (!workspace ? ctx.sessionById(ctx.options.sessionId) : null);
|
|
19
20
|
const workspaceFromSession = (ctx, workspace) => {
|
|
20
|
-
if (workspace) return workspace;
|
|
21
|
+
if (workspace !== undefined) return normalizeWorkspaceId(workspace);
|
|
21
22
|
const session = sessionFromContext(ctx);
|
|
22
23
|
if (!session) fail(ERROR_CODES.INVALID_ARGUMENT, "Workspace is required when the current session is not associated with a workspace");
|
|
23
24
|
return session.workspace;
|
|
24
25
|
};
|
|
25
26
|
const stageFromSession = (ctx, workspace, stage) => {
|
|
26
|
-
if (stage) return stage;
|
|
27
|
+
if (stage !== undefined) return normalizeStageId(stage);
|
|
27
28
|
const session = sessionFromContext(ctx, workspace);
|
|
28
29
|
if (!session) fail(ERROR_CODES.STAGE_CONTEXT_REQUIRED, "Stage is required when the current session is not associated with a stage");
|
|
29
30
|
return session.stage;
|
|
@@ -32,48 +33,36 @@ const sessionFor = (ctx, oc, workspace, stage) => ctx.sessionById(oc.sessionID)?
|
|
|
32
33
|
&& ctx.sessionById(oc.sessionID)?.stage === stage
|
|
33
34
|
? oc.sessionID
|
|
34
35
|
: ctx.sessionByOpenCodeId(oc.sessionID, workspace, stage)?.session_id || oc.sessionID;
|
|
35
|
-
const addStageFromTool = (ctx, args
|
|
36
|
+
const addStageFromTool = (ctx, args) => {
|
|
36
37
|
const workspace = workspaceFromSession(ctx, args.workspace);
|
|
37
|
-
|
|
38
|
-
const currentSession = ctx.sessionByOpenCodeId(oc.sessionID) || ctx.sessionById(oc.sessionID);
|
|
39
|
-
if (currentSession) return created;
|
|
40
|
-
const session = ctx.startSession(workspace, created.data.stage, {
|
|
41
|
-
sessionId: randomUUID(),
|
|
42
|
-
opencodeSessionId: oc.sessionID,
|
|
43
|
-
summary: `started ${created.data.title}`,
|
|
44
|
-
takeover: true,
|
|
45
|
-
});
|
|
46
|
-
return {
|
|
47
|
-
...session,
|
|
48
|
-
data: { ...session.data, created: created.data },
|
|
49
|
-
changed: [...new Set([...created.changed, ...session.changed])],
|
|
50
|
-
};
|
|
38
|
+
return ctx.addStage(workspace, args.title, { goal: args.goal, prompt: args.prompt, dependsOn: args.dependsOn });
|
|
51
39
|
};
|
|
52
40
|
export const work_context_list_workspaces = tool({ description: "List work-context workspaces.", args: {}, execute: run((ctx) => ctx.listWorkspaces()) });
|
|
53
|
-
export const work_context_workspace_list = tool({ description: "List a workspace with stage descriptions and sessions.", args: { workspace: tool.schema.string()
|
|
54
|
-
export const work_context_rename_workspace = tool({ description: "Rename a workspace.", args: { workspace: tool.schema.string()
|
|
55
|
-
export const work_context_workspace_finish = tool({ description: "Finish a workspace after all stages are completed.", args: { workspace: tool.schema.string()
|
|
41
|
+
export const work_context_workspace_list = tool({ description: "List a workspace with stage descriptions and sessions.", args: { workspace: tool.schema.string() }, execute: run((ctx, a) => ctx.listStages(a.workspace)) });
|
|
42
|
+
export const work_context_rename_workspace = tool({ description: "Rename a workspace.", args: { workspace: tool.schema.string(), title: tool.schema.string() }, execute: run((ctx, a) => ctx.renameWorkspace(a.workspace, a.title)) });
|
|
43
|
+
export const work_context_workspace_finish = tool({ description: "Finish a workspace after all stages are completed.", args: { workspace: tool.schema.string() }, execute: run((ctx, a) => ctx.finishWorkspace(a.workspace)) });
|
|
56
44
|
export const work_context_create_workspace = tool({ description: "Create a workspace; enter its planning stage only when the current OpenCode session is not associated with a workspace.", args: { title: tool.schema.string() }, execute: run((ctx, a, oc) => {
|
|
57
45
|
const currentSession = ctx.sessionByOpenCodeId(oc.sessionID);
|
|
58
46
|
return ctx.createWorkspace(a.title, { sessionId: randomUUID(), ...(currentSession ? {} : { opencodeSessionId: oc.sessionID }) });
|
|
59
47
|
}) });
|
|
60
|
-
export const work_context_start_session = tool({ description: "Start a new active session for a stage.", args: { ...common, summary: tool.schema.string().optional() }, execute: run((ctx, a, oc) => ctx.startSession(a.workspace, a.stage, { sessionId: randomUUID(), opencodeSessionId: oc.sessionID, summary: a.summary, takeover: true })) });
|
|
61
|
-
export const work_context_add_stage = tool({ description: "Add a stage
|
|
48
|
+
export const work_context_start_session = tool({ description: "Start a new active session for a stage and return its prompt plus active workspace knowledge.", args: { ...common, summary: tool.schema.string().optional() }, execute: run((ctx, a, oc) => ctx.startSession(a.workspace, a.stage, { sessionId: randomUUID(), opencodeSessionId: oc.sessionID, summary: a.summary, takeover: true })) });
|
|
49
|
+
export const work_context_add_stage = tool({ description: "Add a planned stage without starting it; use resume explicitly in a new OpenCode session to enter the stage.", args: { workspace: tool.schema.string().optional(), title: tool.schema.string(), goal: tool.schema.string().optional(), prompt: tool.schema.string().optional(), dependsOn: tool.schema.array(tool.schema.string()).optional() }, execute: run(addStageFromTool) });
|
|
62
50
|
export const work_context_rename_stage = tool({ description: "Rename a stage while preserving its ID and history; workspace and stage can be omitted in the current OpenCode session.", args: { ...contextualStage, title: tool.schema.string() }, execute: run((ctx, a) => { const workspace = workspaceFromSession(ctx, a.workspace); return ctx.renameStage(workspace, stageFromSession(ctx, workspace, a.stage), a.title); }) });
|
|
63
51
|
export const work_context_update_stage = tool({ description: "Update an existing stage description; workspace and stage can be omitted in the current OpenCode session.", args: { ...contextualStage, description: tool.schema.string() }, execute: run((ctx, a) => { const workspace = workspaceFromSession(ctx, a.workspace); return ctx.updateStage(workspace, stageFromSession(ctx, workspace, a.stage), a.description); }) });
|
|
64
52
|
export const work_context_update_stage_prompt = tool({ description: "Update the optional working prompt of an existing stage; workspace and stage can be omitted in the current OpenCode session.", args: { ...contextualStage, prompt: tool.schema.string() }, execute: run((ctx, a) => { const workspace = workspaceFromSession(ctx, a.workspace); return ctx.updateStagePrompt(workspace, stageFromSession(ctx, workspace, a.stage), a.prompt); }) });
|
|
53
|
+
export const work_context_update_stage_result = tool({ description: "Update an existing stage result; workspace and stage can be omitted in the current OpenCode session.", args: { ...contextualStage, result: tool.schema.string() }, execute: run((ctx, a) => { const workspace = workspaceFromSession(ctx, a.workspace); return ctx.updateStageResult(workspace, stageFromSession(ctx, workspace, a.stage), a.result); }) });
|
|
65
54
|
export const work_context_archive_stage = tool({ description: "Archive a stage while preserving its ID and history; workspace and stage can be omitted in the current OpenCode session.", args: contextualStage, execute: run((ctx, a) => { const workspace = workspaceFromSession(ctx, a.workspace); return ctx.archiveStage(workspace, stageFromSession(ctx, workspace, a.stage)); }) });
|
|
66
55
|
export const work_context_link_issue = tool({ description: "Link a GitLab issue URL to workspace or stage.", args: { workspace: tool.schema.string(), url: tool.schema.string(), stage: tool.schema.string().optional() }, execute: run((ctx, a) => ctx.linkIssue(a.workspace, a.url, a.stage)) });
|
|
67
56
|
export const work_context_rename_session = tool({ description: "Rename the current active session summary; workspace and stage can be omitted in the current OpenCode session.", args: { ...contextualStage, summary: tool.schema.string() }, execute: run((ctx, a, oc) => { const workspace = workspaceFromSession(ctx, a.workspace); const stage = stageFromSession(ctx, workspace, a.stage); return ctx.renameSession(workspace, stage, sessionFor(ctx, oc, workspace, stage), a.summary); }) });
|
|
68
57
|
export const work_context_close_session = tool({ description: "Close the current session without finishing its stage; workspace and stage can be omitted in the current OpenCode session.", args: { ...contextualStage }, execute: run((ctx, a, oc) => { const workspace = workspaceFromSession(ctx, a.workspace); const stage = stageFromSession(ctx, workspace, a.stage); return ctx.closeSession(workspace, stage, sessionFor(ctx, oc, workspace, stage)); }) });
|
|
69
|
-
export const work_context_force_close_session = tool({ description: "Force close a stale active session with an explicit reason and confirmation.", args: { workspace: tool.schema.string()
|
|
58
|
+
export const work_context_force_close_session = tool({ description: "Force close a stale active session with an explicit reason and confirmation.", args: { workspace: tool.schema.string(), stage: tool.schema.string(), sessionId: tool.schema.string(), reason: tool.schema.string(), confirmation: tool.schema.string() }, execute: run((ctx, a) => ctx.forceCloseSession(a.workspace, a.stage, a.sessionId, a.reason, a.confirmation)) });
|
|
70
59
|
export const work_context_handoff_stage = tool({ description: "Hand off the current stage by closing the current session; workspace and stage can be omitted in the current OpenCode session.", args: contextualStage, execute: run((ctx, a, oc) => { const workspace = workspaceFromSession(ctx, a.workspace); const stage = stageFromSession(ctx, workspace, a.stage); return ctx.handoff(workspace, stage, sessionFor(ctx, oc, workspace, stage)); }) });
|
|
71
60
|
export const work_context_abandon_stage = tool({ description: "Abandon the current stage session without completing the stage; workspace and stage can be omitted in the current OpenCode session.", args: contextualStage, execute: run((ctx, a, oc) => { const workspace = workspaceFromSession(ctx, a.workspace); const stage = stageFromSession(ctx, workspace, a.stage); return ctx.abandon(workspace, stage, sessionFor(ctx, oc, workspace, stage)); }) });
|
|
72
|
-
export const work_context_finish_stage = tool({ description: "Finish a stage
|
|
61
|
+
export const work_context_finish_stage = tool({ description: "Finish a stage after reviewing durable workspace knowledge; use knowledgeReview=added after changes or none when no durable findings exist. The ledger is always validated.", args: { ...contextualStage, result: tool.schema.string().optional(), knowledgeReview: tool.schema.string().optional() }, execute: run((ctx, a, oc) => { const workspace = workspaceFromSession(ctx, a.workspace); const stage = stageFromSession(ctx, workspace, a.stage); return ctx.finish(workspace, stage, sessionFor(ctx, oc, workspace, stage), { result: a.result, knowledgeReview: a.knowledgeReview }); }) });
|
|
73
62
|
export const work_context_help = tool({ description: "Show work-context command help.", args: { command: tool.schema.string().optional() }, execute: run((ctx, a) => ctx.help(a.command)) });
|
|
74
63
|
export const work_context_list_knowledge = tool({ description: "List durable knowledge entries for a workspace.", args: { workspace: tool.schema.string() }, execute: run((ctx, a) => ctx.listKnowledge(a.workspace)) });
|
|
75
64
|
export const work_context_add_knowledge = tool({ description: "Add a durable knowledge entry.", args: { workspace: tool.schema.string(), title: tool.schema.string(), kind: tool.schema.string().optional(), text: tool.schema.string(), sources: tool.schema.array(tool.schema.string()).optional() }, execute: run((ctx, a) => ctx.addKnowledge(a.workspace, a)) });
|
|
76
65
|
export const work_context_update_knowledge = tool({ description: "Update a durable knowledge entry.", args: { workspace: tool.schema.string(), knowledgeId: tool.schema.string(), title: tool.schema.string().optional(), kind: tool.schema.string().optional(), status: tool.schema.string().optional(), text: tool.schema.string().optional(), sources: tool.schema.array(tool.schema.string()).optional(), replacement: tool.schema.string().optional() }, execute: run((ctx, a) => ctx.updateKnowledge(a.workspace, a.knowledgeId, a)) });
|
|
77
66
|
export const work_context_supersede_knowledge = tool({ description: "Supersede a durable knowledge entry.", args: { workspace: tool.schema.string(), knowledgeId: tool.schema.string(), replacement: tool.schema.string() }, execute: run((ctx, a) => ctx.supersedeKnowledge(a.workspace, a.knowledgeId, a.replacement) ) });
|
|
78
67
|
|
|
79
|
-
export default { work_context_list_workspaces, work_context_workspace_list, work_context_rename_workspace, work_context_workspace_finish, work_context_create_workspace, work_context_start_session, work_context_add_stage, work_context_rename_stage, work_context_update_stage, work_context_update_stage_prompt, work_context_archive_stage, work_context_link_issue, work_context_rename_session, work_context_close_session, work_context_force_close_session, work_context_handoff_stage, work_context_abandon_stage, work_context_finish_stage, work_context_help, work_context_list_knowledge, work_context_add_knowledge, work_context_update_knowledge, work_context_supersede_knowledge };
|
|
68
|
+
export default { work_context_list_workspaces, work_context_workspace_list, work_context_rename_workspace, work_context_workspace_finish, work_context_create_workspace, work_context_start_session, work_context_add_stage, work_context_rename_stage, work_context_update_stage, work_context_update_stage_prompt, work_context_update_stage_result, work_context_archive_stage, work_context_link_issue, work_context_rename_session, work_context_close_session, work_context_force_close_session, work_context_handoff_stage, work_context_abandon_stage, work_context_finish_stage, work_context_help, work_context_list_knowledge, work_context_add_knowledge, work_context_update_knowledge, work_context_supersede_knowledge };
|