opencode-work-context 0.1.8 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -44,11 +44,16 @@ Then create a task and its first stage in OpenCode:
44
44
  ```text
45
45
  /wc create "Add CSV export to analytics report"
46
46
  /wc stage rename 000001 01 "Planning"
47
- /wc stage add 000001 "Update the export endpoint"
47
+ /wc stage add 000001 "Update the export endpoint" "Inspect the current endpoint, implement CSV export, add regression tests, and verify the result."
48
48
  /wc resume 000001 02
49
49
  ```
50
50
 
51
- When you return later, continue from the active stage:
51
+ When you return later, continue from the active stage. A stage must have a
52
+ non-empty prompt before implementation begins; if the prompt is missing or
53
+ ambiguous, `/wc resume` instructs the agent to ask focused questions first.
54
+ Before working, the agent reports the stage essence, the previous session's
55
+ result or stopping point, and what it will do now. On subsequent resumes, it
56
+ only reports that context and waits for explicit confirmation before continuing:
52
57
 
53
58
  ```text
54
59
  /wc resume 000001 02
@@ -19,7 +19,20 @@ const dependencyManifestFile = path.join(dependencyRoot, "package.json");
19
19
  let dependencyManifest = {};
20
20
  try { dependencyManifest = JSON.parse(fs.readFileSync(dependencyManifestFile, "utf8")); } catch {}
21
21
  const pluginLoader = `export { default } from "${packageManifest.name}/plugin";\n`;
22
- const tuiLoader = `export { default } from "${packageManifest.name}/tui";\n`;
22
+ const tuiLoader = `import { createSignal } from "solid-js";
23
+ import { jsx } from "@opentui/solid/jsx-runtime";
24
+ import plugin from "${packageManifest.name}/tui";
25
+
26
+ export default {
27
+ ...plugin,
28
+ async tui(api, options) {
29
+ return plugin.tui(api, {
30
+ ...options,
31
+ runtime: { createSignal, jsx },
32
+ });
33
+ },
34
+ };
35
+ `;
23
36
  const tuiConfig = JSON.stringify({
24
37
  $schema: "https://opencode.ai/tui.json",
25
38
  plugin: ["./tui-plugins/work-context-stages.js"],
package/commands/wc.md CHANGED
@@ -22,13 +22,13 @@ Use these exact tool mappings; do not invent shortened tool names:
22
22
  - `resume <workspace> <stage>` -> `work_context_start_session`
23
23
  - `stage force-close <workspace> <stage> <sessionId> "reason" FORCE_CLOSE` -> `work_context_force_close_session`
24
24
  - `stage add [<workspace>] ...` -> `work_context_add_stage` (optional `prompt`; detailed prompt is expected for stages created from planning)
25
- - `stage rename [<workspace>] <stage> "title"` -> `work_context_rename_stage`
26
- - `stage update [<workspace>] <stage> "description"` -> `work_context_update_stage`
27
- - `stage update-prompt [<workspace>] <stage> "prompt"` -> `work_context_update_stage_prompt`
28
- - `stage archive [<workspace>] <stage>` -> `work_context_archive_stage`
29
- - `stage handoff <workspace> <stage>` -> `work_context_handoff_stage`
30
- - `stage abandon <workspace> <stage>` -> `work_context_abandon_stage`
31
- - `stage finish <workspace> <stage>` -> `work_context_finish_stage`
25
+ - `stage rename [<workspace>] [<stage>] "title"` -> `work_context_rename_stage`
26
+ - `stage update [<workspace>] [<stage>] "description"` -> `work_context_update_stage`
27
+ - `stage update-prompt [<workspace>] [<stage>] "prompt"` -> `work_context_update_stage_prompt`
28
+ - `stage archive [<workspace>] [<stage>]` -> `work_context_archive_stage`
29
+ - `stage handoff [<workspace>] [<stage>]` -> `work_context_handoff_stage`
30
+ - `stage abandon [<workspace>] [<stage>]` -> `work_context_abandon_stage`
31
+ - `stage finish [<workspace>] [<stage>]` -> `work_context_finish_stage`
32
32
 
33
33
  Supported syntax:
34
34
 
@@ -41,17 +41,26 @@ Supported syntax:
41
41
  - `resume <workspace> <stage>`
42
42
  - `stage force-close <workspace> <stage> <sessionId> "reason" FORCE_CLOSE`
43
43
  - `stage add [<workspace>] "title" ["prompt"]`
44
- - `stage rename [<workspace>] <stage> "title"`
45
- - `stage update [<workspace>] <stage> "description"`
46
- - `stage update-prompt [<workspace>] <stage> "prompt"`
47
- - `stage archive [<workspace>] <stage>`
48
- - `stage finish <workspace> <stage>`
44
+ - `stage rename [<workspace>] [<stage>] "title"`
45
+ - `stage update [<workspace>] [<stage>] "description"`
46
+ - `stage update-prompt [<workspace>] [<stage>] "prompt"`
47
+ - `stage archive [<workspace>] [<stage>]`
48
+ - `stage handoff [<workspace>] [<stage>]`
49
+ - `stage abandon [<workspace>] [<stage>]`
50
+ - `stage finish [<workspace>] [<stage>]`
49
51
  - `<workspace> [<stage>] link-issue <URL>`
50
52
  - `session rename "summary"`
51
- - `stage handoff <workspace> <stage>`
52
- - `stage abandon <workspace> <stage>`
53
- - `stage finish <workspace> <stage>` automatically reviews the Knowledge Base (`auto` by default)
54
- - `resume` returns an actionable `resume.next_action` and `resume.instruction`; begin or continue the work immediately from that structured context
53
+ - `stage handoff [<workspace>] <stage>`
54
+ - `stage abandon [<workspace>] <stage>`
55
+ - `stage finish [<workspace>] <stage>` automatically reviews the Knowledge Base (`auto` by default)
56
+ - stage lifecycle commands may omit stage, using the current OpenCode session; with one numeric identifier, six digits mean workspace and one or two digits mean stage
57
+ - `resume` returns `resume.context` with the stage essence, the previous session's result/stopping point, and the current plan; report this concise context to the user before doing any work
58
+ - on every subsequent resume, report the context and wait for explicit user confirmation; do not automatically continue implementation
59
+ - when `resume.next_action` is `await_confirmation`, do not inspect or modify application code until the user confirms
60
+ - `create` enters the new workspace's Planning stage in the current OpenCode session only when that session is not yet in a workspace; otherwise it only creates the workspace and its planning session
61
+ - `stage add` enters the newly created stage and returns its actionable `resume` context when the current OpenCode session is not yet in a workspace; otherwise it only creates the planned stage
62
+ - `resume` returns `resume.next_action` and `resume.instruction`; begin or continue implementation only when the stage prompt is non-empty and, after reviewing it, there are no unanswered questions
63
+ - when `resume.next_action` is `ask_questions`, do not inspect or modify application code and ask the user focused questions needed to make the prompt actionable
55
64
  - `stage finish` returns downstream unfinished stages whose prompts should be reviewed after new findings
56
65
  - `knowledge list|add|update|supersede <workspace> ...`
57
66
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "opencode-work-context",
3
3
  "type": "module",
4
- "version": "0.1.8",
4
+ "version": "0.1.10",
5
5
  "description": "Filesystem work-context core and OpenCode adapter",
6
6
  "license": "MIT",
7
7
  "author": {
package/src/core.js CHANGED
@@ -172,7 +172,27 @@ export class WorkContext {
172
172
  if (this.storage.readEvents().some((item) => item.session_id === sessionId)) fail(ERROR_CODES.CONFLICT, "Session ID already exists");
173
173
  this.writeEvents([event("session.started", workspace, "01", 1, sessionId, actor(this.options), { summary: `planning ${title.trim()}`, opencode_session_id: options.opencodeSessionId || null, branch: options.branch || null })]);
174
174
  generateProjections(this.storage);
175
- return this.result({ workspace, stage: "01", session_id: sessionId, ordinal: "01/01" }, [workspace, "01"]);
175
+ return this.result({
176
+ workspace,
177
+ stage: "01",
178
+ session_id: sessionId,
179
+ ordinal: "01/01",
180
+ title: "Planning",
181
+ description: planningGoal,
182
+ prompt: planningPrompt,
183
+ resume: {
184
+ first: true,
185
+ summary: "Starting work on stage 01: Planning.",
186
+ last_session_summary: null,
187
+ context: {
188
+ essence: planningGoal,
189
+ previous: "The previous session did not save a result; the stopping point needs to be clarified.",
190
+ now: planningPrompt,
191
+ },
192
+ next_action: "start_work",
193
+ instruction: planningPrompt,
194
+ },
195
+ }, [workspace, "01"]);
176
196
  });
177
197
  }
178
198
 
@@ -225,6 +245,7 @@ export class WorkContext {
225
245
  generateProjections(this.storage);
226
246
  const previousSession = previous.at(-1) || null;
227
247
  const firstResume = previous.length === 0;
248
+ const hasPrompt = Boolean(stageRecord.data.prompt?.trim());
228
249
  return this.result({
229
250
  workspace,
230
251
  stage,
@@ -239,10 +260,18 @@ export class WorkContext {
239
260
  ? `Starting work on stage ${stage}: ${stageRecord.data.title}.`
240
261
  : `Continuing work on stage ${stage}: ${stageRecord.data.title}. Last recorded summary: ${previousSession?.summary || "no saved report"}.`,
241
262
  last_session_summary: previousSession?.summary || null,
242
- next_action: firstResume ? "start_work" : "continue_work",
243
- instruction: stageRecord.data.prompt || (firstResume
244
- ? `Review stage ${stage}: ${stageRecord.data.title} and begin work.`
245
- : `Continue work on stage ${stage}: ${stageRecord.data.title}.`),
263
+ context: {
264
+ essence: stageRecord.data.goal || stageRecord.data.title,
265
+ previous: previousSession?.summary || "The previous session did not save a result; the stopping point needs to be clarified.",
266
+ now: hasPrompt ? stageRecord.data.prompt : "First clarify the task and work plan with the user.",
267
+ },
268
+ next_action: hasPrompt ? (firstResume ? "start_work" : "await_confirmation") : "ask_questions",
269
+ instruction: hasPrompt
270
+ ? firstResume
271
+ ? stageRecord.data.prompt
272
+ || `Review stage ${stage}: ${stageRecord.data.title} and begin work only after confirming there are no unanswered questions.`
273
+ : `Stage ${stage}: ${stageRecord.data.title} was resumed before. Report the context and wait for the user's confirmation before continuing work.`
274
+ : `Stage ${stage}: ${stageRecord.data.title} has no non-empty prompt. Do not start implementation; ask the user the questions needed to define the work.`,
246
275
  },
247
276
  }, [workspace, stage]);
248
277
  });
@@ -480,7 +509,7 @@ export class WorkContext {
480
509
  }
481
510
 
482
511
  help(command = "") {
483
- 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 is optional for stage add/rename/update/archive when the current session identifies one workspace; stage add accepts an optional prompt, which should contain the complete implementation context when the stage is created from stage 01 planning; resume returns resume.next_action and resume.instruction for immediate work; force-close requires a session ID, reason, and exact confirmation FORCE_CLOSE; stage finish returns downstream stages for prompt review; 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; stage finish reviews Knowledge Base automatically by default (knowledgeReview=auto); mutating commands call structured tools; only explicit lifecycle operations change storage." }, []);
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, which should contain the complete implementation context when the stage is created from stage 01 planning; resume returns resume.next_action and resume.instruction, but 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; stage finish returns downstream stages for prompt review; 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; stage finish reviews Knowledge Base automatically by default (knowledgeReview=auto); mutating commands call structured tools; only explicit lifecycle operations change storage." }, []);
484
513
  }
485
514
 
486
515
  result(data, changed, next = null) {
package/src/errors.js CHANGED
@@ -3,6 +3,7 @@ export const ERROR_CODES = Object.freeze({
3
3
  ACTIVE_SESSION_EXISTS: "ACTIVE_SESSION_EXISTS", SESSION_NOT_ACTIVE: "SESSION_NOT_ACTIVE",
4
4
  LOCKED: "LOCKED", STALE_LOCK: "STALE_LOCK", CONFLICT: "CONFLICT", INVALID_ISSUE_URL: "INVALID_ISSUE_URL",
5
5
  ADAPTER_UNAVAILABLE: "ADAPTER_UNAVAILABLE", STORAGE_ERROR: "STORAGE_ERROR", CONFIRMATION_REQUIRED: "CONFIRMATION_REQUIRED",
6
+ STAGE_CONTEXT_REQUIRED: "STAGE_CONTEXT_REQUIRED",
6
7
  });
7
8
 
8
9
  export class WorkContextError extends Error {
@@ -19,7 +19,7 @@ export function readStagesSnapshot({ projectRoot, sessionId }) {
19
19
  if (!session && sessionId) {
20
20
  for (const workspace of context.listWorkspaces().data) {
21
21
  const candidate = context.listStages(workspace.workspace).data.sessions
22
- .find((item) => item.opencode_session_id === sessionId);
22
+ .filter((item) => item.opencode_session_id === sessionId).at(-1);
23
23
  if (candidate) { session = candidate; break; }
24
24
  }
25
25
  }
@@ -13,34 +13,63 @@ const run = (fn) => async (args, context) => {
13
13
  }
14
14
  };
15
15
  const common = { workspace: tool.schema.string().regex(/^\d{6}$/), stage: tool.schema.string().regex(/^\d{1,2}$/) };
16
+ const contextualStage = { workspace: tool.schema.string().regex(/^\d{6}$/).optional(), stage: tool.schema.string().regex(/^\d{1,2}$/).optional() };
17
+ const sessionFromContext = (ctx, workspace) => ctx.sessionByOpenCodeId(ctx.options.sessionId, workspace || null, null, null)
18
+ || (!workspace ? ctx.sessionById(ctx.options.sessionId) : null);
16
19
  const workspaceFromSession = (ctx, workspace) => {
17
20
  if (workspace) return workspace;
18
- const session = ctx.sessionByOpenCodeId(ctx.options.sessionId) || ctx.sessionById(ctx.options.sessionId);
21
+ const session = sessionFromContext(ctx);
19
22
  if (!session) fail(ERROR_CODES.INVALID_ARGUMENT, "Workspace is required when the current session is not associated with a workspace");
20
23
  return session.workspace;
21
24
  };
25
+ const stageFromSession = (ctx, workspace, stage) => {
26
+ if (stage) return stage;
27
+ const session = sessionFromContext(ctx, workspace);
28
+ if (!session) fail(ERROR_CODES.STAGE_CONTEXT_REQUIRED, "Stage is required when the current session is not associated with a stage");
29
+ return session.stage;
30
+ };
22
31
  const sessionFor = (ctx, oc, workspace, stage) => ctx.sessionById(oc.sessionID)?.workspace === workspace
23
32
  && ctx.sessionById(oc.sessionID)?.stage === stage
24
33
  ? oc.sessionID
25
34
  : ctx.sessionByOpenCodeId(oc.sessionID, workspace, stage)?.session_id || oc.sessionID;
35
+ const addStageFromTool = (ctx, args, oc) => {
36
+ const workspace = workspaceFromSession(ctx, args.workspace);
37
+ const created = ctx.addStage(workspace, args.title, { goal: args.goal, prompt: args.prompt, dependsOn: args.dependsOn });
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
+ };
51
+ };
26
52
  export const work_context_list_workspaces = tool({ description: "List work-context workspaces.", args: {}, execute: run((ctx) => ctx.listWorkspaces()) });
27
53
  export const work_context_workspace_list = tool({ description: "List a workspace with stage descriptions and sessions.", args: { workspace: tool.schema.string().regex(/^\d{6}$/) }, execute: run((ctx, a) => ctx.listStages(a.workspace)) });
28
54
  export const work_context_rename_workspace = tool({ description: "Rename a workspace.", args: { workspace: tool.schema.string().regex(/^\d{6}$/), title: tool.schema.string() }, execute: run((ctx, a) => ctx.renameWorkspace(a.workspace, a.title)) });
29
55
  export const work_context_workspace_finish = tool({ description: "Finish a workspace after all stages are completed.", args: { workspace: tool.schema.string().regex(/^\d{6}$/) }, execute: run((ctx, a) => ctx.finishWorkspace(a.workspace)) });
30
- export const work_context_create_workspace = tool({ description: "Create workspace, stage 01, and active session.", args: { title: tool.schema.string() }, execute: run((ctx, a, oc) => ctx.createWorkspace(a.title, { sessionId: randomUUID(), opencodeSessionId: oc.sessionID })) });
56
+ 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
+ const currentSession = ctx.sessionByOpenCodeId(oc.sessionID);
58
+ return ctx.createWorkspace(a.title, { sessionId: randomUUID(), ...(currentSession ? {} : { opencodeSessionId: oc.sessionID }) });
59
+ }) });
31
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 })) });
32
- export const work_context_add_stage = tool({ description: "Add a planned stage. Prompt is optional for manually created stages and should be detailed when the stage comes from planning.", args: { workspace: tool.schema.string().regex(/^\d{6}$/).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((ctx, a) => ctx.addStage(workspaceFromSession(ctx, a.workspace), a.title, { goal: a.goal, prompt: a.prompt, dependsOn: a.dependsOn })) });
33
- export const work_context_rename_stage = tool({ description: "Rename a stage while preserving its ID and history.", args: { workspace: tool.schema.string().regex(/^\d{6}$/).optional(), stage: tool.schema.string().regex(/^\d{1,2}$/), title: tool.schema.string() }, execute: run((ctx, a) => ctx.renameStage(workspaceFromSession(ctx, a.workspace), a.stage, a.title)) });
34
- export const work_context_update_stage = tool({ description: "Update an existing stage description.", args: { workspace: tool.schema.string().regex(/^\d{6}$/).optional(), stage: tool.schema.string().regex(/^\d{1,2}$/), description: tool.schema.string() }, execute: run((ctx, a) => ctx.updateStage(workspaceFromSession(ctx, a.workspace), a.stage, a.description)) });
35
- export const work_context_update_stage_prompt = tool({ description: "Update the optional working prompt of an existing stage.", args: { workspace: tool.schema.string().regex(/^\d{6}$/).optional(), stage: tool.schema.string().regex(/^\d{1,2}$/), prompt: tool.schema.string() }, execute: run((ctx, a) => ctx.updateStagePrompt(workspaceFromSession(ctx, a.workspace), a.stage, a.prompt)) });
36
- export const work_context_archive_stage = tool({ description: "Archive a stage while preserving its ID and history.", args: { workspace: tool.schema.string().regex(/^\d{6}$/), stage: tool.schema.string().regex(/^\d{1,2}$/) }, execute: run((ctx, a) => ctx.archiveStage(a.workspace, a.stage)) });
61
+ export const work_context_add_stage = tool({ description: "Add a stage; when workspace is omitted, enter the new stage in the current OpenCode session and return resume context.", args: { workspace: tool.schema.string().regex(/^\d{6}$/).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
+ 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
+ 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
+ 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); }) });
65
+ 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)); }) });
37
66
  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)) });
38
- export const work_context_rename_session = tool({ description: "Rename the current active session summary.", args: { ...common, summary: tool.schema.string() }, execute: run((ctx, a, oc) => ctx.renameSession(a.workspace, a.stage, sessionFor(ctx, oc, a.workspace, a.stage), a.summary)) });
39
- export const work_context_close_session = tool({ description: "Close the current session without finishing its stage.", args: { ...common }, execute: run((ctx, a, oc) => ctx.closeSession(a.workspace, a.stage, sessionFor(ctx, oc, a.workspace, a.stage))) });
67
+ 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
+ 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)); }) });
40
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().regex(/^\d{6}$/), stage: tool.schema.string().regex(/^\d{1,2}$/), 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)) });
41
- export const work_context_handoff_stage = tool({ description: "Hand off the current stage by closing the current session.", args: { ...common }, execute: run((ctx, a, oc) => ctx.handoff(a.workspace, a.stage, sessionFor(ctx, oc, a.workspace, a.stage))) });
42
- export const work_context_abandon_stage = tool({ description: "Abandon the current stage session without completing the stage.", args: { ...common }, execute: run((ctx, a, oc) => ctx.abandon(a.workspace, a.stage, sessionFor(ctx, oc, a.workspace, a.stage))) });
43
- export const work_context_finish_stage = tool({ description: "Finish a stage and automatically validate the Knowledge Base by default.", args: { ...common, result: tool.schema.string().optional(), knowledgeReview: tool.schema.string().optional() }, execute: run((ctx, a, oc) => ctx.finish(a.workspace, a.stage, sessionFor(ctx, oc, a.workspace, a.stage), { result: a.result, knowledgeReview: a.knowledgeReview })) });
70
+ 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
+ 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 and automatically validate the Knowledge Base by default; workspace and stage can be omitted in the current OpenCode session.", 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 }); }) });
44
73
  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)) });
45
74
  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)) });
46
75
  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)) });