opencode-work-context 0.1.1 → 0.1.3

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
@@ -41,6 +41,9 @@ Generated files:
41
41
  Tools are registered by the installed plugin and are not copied into the project.
42
42
  Knowledge operations are explicit: list, add, update, and supersede. Finishing a
43
43
  stage requires declaring whether its knowledge review was `added` or `none`.
44
+ Finish a workspace explicitly with `/wc workspace finish <workspace>`; it is
45
+ accepted only after every stage is `completed`. Use `/wc workspace list <workspace>`
46
+ to list stages with their descriptions.
44
47
 
45
48
  ## License
46
49
 
package/commands/wc.md CHANGED
@@ -1,6 +1,5 @@
1
1
  ---
2
2
  description: Explicit work-context lifecycle commands backed by structured tools
3
- agent: build
4
3
  subtask: false
5
4
  ---
6
5
 
@@ -10,11 +9,26 @@ Markdown, JSONL, INDEX, or SESSIONS projections directly. For mutating operation
10
9
  report the structured result and stable error code. Use `work_context_help` when
11
10
  the syntax is missing or ambiguous.
12
11
 
12
+ For `workspace list <workspace>` (or `<workspace> list`), report the workspace
13
+ status and every stage as `stage - status - title - description`.
14
+
15
+ Use these exact tool mappings; do not invent shortened tool names:
16
+
17
+ - `create` -> `work_context_create_workspace`
18
+ - `list` -> `work_context_list_workspaces`
19
+ - `workspace list <workspace>` or `<workspace> list` -> `work_context_workspace_list`
20
+ - `workspace finish <workspace>` -> `work_context_workspace_finish`
21
+ - `resume <workspace> <stage>` -> `work_context_start_session`
22
+ - `add-stage <workspace> ...` -> `work_context_add_stage`
23
+ - `finish <workspace> <stage>` -> `work_context_finish_stage`
24
+
13
25
  Supported syntax:
14
26
 
15
27
  - `help [command]`
16
28
  - `create "title"`
17
29
  - `list` or `<workspace> list`
30
+ - `workspace list <workspace>`
31
+ - `workspace finish <workspace>`
18
32
  - `resume <workspace> <stage>`
19
33
  - `add-stage <workspace> "title"`
20
34
  - `<workspace> [<stage>] link-issue <URL>`
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "opencode-work-context",
3
3
  "type": "module",
4
- "version": "0.1.1",
4
+ "version": "0.1.3",
5
5
  "description": "Filesystem work-context core and OpenCode adapter",
6
6
  "license": "MIT",
7
7
  "author": {
package/src/core.js CHANGED
@@ -86,7 +86,10 @@ export class WorkContext {
86
86
  id(workspace, 6);
87
87
  const dir = path.join(this.storage.workspaceDir(workspace), "stages");
88
88
  if (!fs.existsSync(dir)) fail(ERROR_CODES.NOT_FOUND, "Workspace not found");
89
- const stages = fs.readdirSync(dir).filter((file) => /^\d{2}\.md$/.test(file)).map((file) => this.storage.readStage(workspace, file.slice(0, 2)).data);
89
+ const stages = fs.readdirSync(dir).filter((file) => /^\d{2}\.md$/.test(file)).map((file) => {
90
+ const stage = this.storage.readStage(workspace, file.slice(0, 2)).data;
91
+ return { ...stage, description: stage.goal };
92
+ });
90
93
  const ids = new Set(stages.map((item) => item.stage));
91
94
  const visiting = new Set();
92
95
  const visited = new Set();
@@ -104,6 +107,26 @@ export class WorkContext {
104
107
  return { ok: true, data: { workspace, stages, sessions: reduceSessions(this.storage.readEvents()).filter((session) => session.workspace === workspace) } };
105
108
  }
106
109
 
110
+ finishWorkspace(workspace) {
111
+ id(workspace, 6);
112
+ return this.transact(`workspace-${workspace}`, () => {
113
+ const record = this.storage.readWorkspace(workspace);
114
+ const stages = this.listStages(workspace).data.stages;
115
+ if (record.data.status === "cancelled") fail(ERROR_CODES.INVALID_STATE, "Cancelled workspace cannot be finished", { workspace, status: record.data.status });
116
+ const incompleteStages = stages.filter((stage) => stage.status !== "completed");
117
+ if (incompleteStages.length) fail(ERROR_CODES.INVALID_STATE, "All workspace stages must be completed before finishing", {
118
+ workspace,
119
+ incompleteStages: incompleteStages.map(({ stage, title, description, status }) => ({ stage, title, description, status })),
120
+ });
121
+ if (record.data.status === "completed") return this.result({ workspace, status: "completed", stages }, []);
122
+ record.data.status = "completed";
123
+ record.data.updated_at = new Date().toISOString();
124
+ this.storage.writeMarkdown(this.storage.workspaceFile(workspace), record.data, record.body);
125
+ generateProjections(this.storage);
126
+ return this.result({ workspace, status: "completed", stages }, [workspace]);
127
+ });
128
+ }
129
+
107
130
  sessionById(sessionId) {
108
131
  return reduceSessions(this.storage.readEvents()).find((session) => session.session_id === sessionId) || null;
109
132
  }
@@ -295,7 +318,7 @@ export class WorkContext {
295
318
  }
296
319
 
297
320
  help(command = "") {
298
- return this.result({ command, syntax: "/wc [create|list|resume|add-stage|link-issue|session rename|session close|handoff|finish|knowledge list|knowledge add|knowledge update|knowledge supersede|help]", note: "finish requires knowledgeReview=added|none; mutating commands call structured tools; only explicit lifecycle operations change storage." }, []);
321
+ return this.result({ command, syntax: "/wc [create|list|workspace list|workspace finish|resume|add-stage|link-issue|session rename|session close|handoff|finish|knowledge list|knowledge add|knowledge update|knowledge supersede|help]", note: "workspace finish requires all stages to be completed; stage finish requires knowledgeReview=added|none; mutating commands call structured tools; only explicit lifecycle operations change storage." }, []);
299
322
  }
300
323
 
301
324
  result(data, changed) {
@@ -13,6 +13,8 @@ const run = (fn) => async (args, context) => {
13
13
  const common = { workspace: tool.schema.string().regex(/^\d{6}$/), stage: tool.schema.string().regex(/^\d{1,2}$/) };
14
14
  export const work_context_list_workspaces = tool({ description: "List work-context workspaces.", args: {}, execute: run((ctx) => ctx.listWorkspaces()) });
15
15
  export const work_context_list_stages = tool({ description: "List stages and sessions for a workspace.", args: { workspace: tool.schema.string() }, execute: run((ctx, a) => ctx.listStages(a.workspace)) });
16
+ 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)) });
17
+ 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)) });
16
18
  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: oc.sessionID })) });
17
19
  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: oc.sessionID, summary: a.summary })) });
18
20
  export const work_context_add_stage = tool({ description: "Add a planned stage.", args: { workspace: tool.schema.string(), title: tool.schema.string(), goal: tool.schema.string().optional(), dependsOn: tool.schema.array(tool.schema.string()).optional() }, execute: run((ctx, a) => ctx.addStage(a.workspace, a.title, { goal: a.goal, dependsOn: a.dependsOn })) });
@@ -27,4 +29,4 @@ export const work_context_add_knowledge = tool({ description: "Add a durable kno
27
29
  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)) });
28
30
  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) ) });
29
31
 
30
- export default { work_context_list_workspaces, work_context_list_stages, work_context_create_workspace, work_context_start_session, work_context_add_stage, work_context_link_issue, work_context_rename_session, work_context_close_session, work_context_handoff_stage, work_context_finish_stage, work_context_help, work_context_list_knowledge, work_context_add_knowledge, work_context_update_knowledge, work_context_supersede_knowledge };
32
+ export default { work_context_list_workspaces, work_context_list_stages, work_context_workspace_list, work_context_workspace_finish, work_context_create_workspace, work_context_start_session, work_context_add_stage, work_context_link_issue, work_context_rename_session, work_context_close_session, work_context_handoff_stage, work_context_finish_stage, work_context_help, work_context_list_knowledge, work_context_add_knowledge, work_context_update_knowledge, work_context_supersede_knowledge };