opencode-work-context 0.7.0 → 0.9.0

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.
@@ -19,6 +19,14 @@ const run = (fn) => async (args, context) => {
19
19
  };
20
20
  const common = { workspace: tool.schema.string(), stage: tool.schema.string() };
21
21
  const contextualStage = { workspace: tool.schema.string().optional(), stage: tool.schema.string().optional() };
22
+ const executionSections = {
23
+ scope: tool.schema.array(tool.schema.string()).optional(),
24
+ completed: tool.schema.array(tool.schema.string()).optional(),
25
+ remaining: tool.schema.array(tool.schema.string()).optional(),
26
+ decisions: tool.schema.array(tool.schema.string()).optional(),
27
+ blockers: tool.schema.array(tool.schema.string()).optional(),
28
+ verification: tool.schema.array(tool.schema.string()).optional(),
29
+ };
22
30
  const sessionFromContext = (ctx, workspace) => ctx.sessionByOpenCodeId(ctx.options.sessionId, workspace || null, null, null)
23
31
  || (!workspace ? ctx.sessionById(ctx.options.sessionId) : null);
24
32
  const workspaceFromSession = (ctx, workspace) => {
@@ -65,6 +73,8 @@ export const work_context_list_candidates = tool({ description: "List local comm
65
73
  export const work_context_ready_candidate = tool({ description: "Mark a captured draft candidate ready for a later explicit commit operation.", args: { workspace: tool.schema.string(), candidateId: tool.schema.string() }, execute: run((ctx, a) => ctx.readyCandidate(a.workspace, a.candidateId)) });
66
74
  export const work_context_commit_candidate = tool({ description: "Commit a ready candidate atomically without using the ordinary Git index. Uses its stored message unless message is provided.", args: { workspace: tool.schema.string(), candidateId: tool.schema.string(), message: tool.schema.string().optional() }, execute: run((ctx, a) => ctx.commitCandidate(a.workspace, a.candidateId, a.message)) });
67
75
  export const work_context_discard_candidate = tool({ description: "Discard a local commit candidate without changing Git state.", args: { workspace: tool.schema.string(), candidateId: tool.schema.string() }, execute: run((ctx, a) => ctx.discardCandidate(a.workspace, a.candidateId)) });
76
+ export const work_context_read_delivery = tool({ description: "Read workspace-level delivery context. Exact Git inspection runs only when both immutable from and to commit hashes are provided.", args: { workspace: tool.schema.string(), environment: tool.schema.string().optional(), from: tool.schema.string().optional(), to: tool.schema.string().optional() }, execute: run((ctx, a) => ctx.readDelivery(a.workspace, { environment: a.environment, from: a.from, to: a.to })) });
77
+ export const work_context_mark_delivery = tool({ description: "Record a confirmed environment delivery checkpoint without executing deployment. Requires DELIVERY_CONFIRMED.", args: { workspace: tool.schema.string(), environment: tool.schema.string(), commit: tool.schema.string(), confirmation: tool.schema.string() }, execute: run((ctx, a) => ctx.markDelivery(a.workspace, a.environment, a.commit, a.confirmation)) });
68
78
  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)) });
69
79
  export const work_context_reopen_workspace = tool({ description: "Reopen a completed workspace with a required reason and durable history.", args: { workspace: tool.schema.string(), reason: tool.schema.string() }, execute: run((ctx, a) => ctx.reopenWorkspace(a.workspace, a.reason)) });
70
80
  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(), mode: tool.schema.enum(["standard", "startup"]).optional() }, execute: run((ctx, a, oc) => {
@@ -77,6 +87,9 @@ export const work_context_rename_stage = tool({ description: "Rename a stage whi
77
87
  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); }) });
78
88
  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); }) });
79
89
  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); }) });
90
+ export const work_context_read_stage_execution = tool({ description: "Read the bounded stage-local execution state; 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.readStageExecution(workspace, stageFromSession(ctx, workspace, a.stage)); }) });
91
+ export const work_context_replace_stage_execution = tool({ description: "Replace all stage-local execution sections using an optimistic revision guard. Requires the active stage session.", args: { ...contextualStage, expectedRevision: tool.schema.number().int().nonnegative(), state: tool.schema.object(executionSections) }, execute: run((ctx, a, oc) => { const workspace = workspaceFromSession(ctx, a.workspace); const stage = stageFromSession(ctx, workspace, a.stage); return ctx.replaceStageExecution(workspace, stage, sessionFor(ctx, oc, workspace, stage), a.expectedRevision, a.state); }) });
92
+ export const work_context_update_stage_execution = tool({ description: "Atomically add and remove stage-local execution items using an optimistic revision guard. Requires the active stage session.", args: { ...contextualStage, expectedRevision: tool.schema.number().int().nonnegative(), add: tool.schema.object(executionSections).optional(), remove: tool.schema.object(executionSections).optional() }, execute: run((ctx, a, oc) => { const workspace = workspaceFromSession(ctx, a.workspace); const stage = stageFromSession(ctx, workspace, a.stage); return ctx.updateStageExecution(workspace, stage, sessionFor(ctx, oc, workspace, stage), a.expectedRevision, { add: a.add, remove: a.remove }); }) });
80
93
  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)); }) });
81
94
  export const work_context_reopen_stage = tool({ description: "Reopen a completed stage with a reason. This preserves completion history and requires explicit resume in a separate OpenCode session.", args: { ...common, reason: tool.schema.string() }, execute: run((ctx, a) => ctx.reopenStage(a.workspace, a.stage, a.reason)) });
82
95
  export const work_context_restore_stage = tool({ description: "Restore an archived stage to its saved pre-archive status with a required reason. Actionable stages require explicit resume in a separate OpenCode session.", args: { ...common, reason: tool.schema.string() }, execute: run((ctx, a) => ctx.restoreStage(a.workspace, a.stage, a.reason)) });
@@ -94,4 +107,4 @@ export const work_context_add_knowledge = tool({ description: "Add a durable kno
94
107
  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)) });
95
108
  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) ) });
96
109
 
97
- export default { work_context_list_workspaces, work_context_workspace_list, work_context_rename_workspace, work_context_set_workspace_mode, work_context_create_candidate, work_context_capture_candidate, work_context_preview_candidate, work_context_show_candidate, work_context_list_candidates, work_context_ready_candidate, work_context_commit_candidate, work_context_discard_candidate, work_context_workspace_finish, work_context_reopen_workspace, 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_reopen_stage, work_context_restore_stage, work_context_link_issue, work_context_unlink_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 };
110
+ export default { work_context_list_workspaces, work_context_workspace_list, work_context_rename_workspace, work_context_set_workspace_mode, work_context_create_candidate, work_context_capture_candidate, work_context_preview_candidate, work_context_show_candidate, work_context_list_candidates, work_context_ready_candidate, work_context_commit_candidate, work_context_discard_candidate, work_context_read_delivery, work_context_mark_delivery, work_context_workspace_finish, work_context_reopen_workspace, 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_read_stage_execution, work_context_replace_stage_execution, work_context_update_stage_execution, work_context_archive_stage, work_context_reopen_stage, work_context_restore_stage, work_context_link_issue, work_context_unlink_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 };
@@ -32,23 +32,31 @@ const readWorkspace = (context, record, currentSession) => {
32
32
  : sessions.find((session) => session.session_id === currentSession?.session_id);
33
33
  const currentStage = matchingSession?.stage || null;
34
34
  const mode = record.mode || "standard";
35
- const candidates = mode === "startup" ? context.candidates().summary(record.workspace) : null;
35
+ const candidateProjection = mode === "startup" ? context.candidates().activeProjection(record.workspace) : null;
36
+ const deliveryProjection = context.deliveries().projection(record.workspace);
37
+ const delivery = deliveryProjection.committed.count || deliveryProjection.environments.length || deliveryProjection.unavailable
38
+ ? { committed: deliveryProjection.committed.count, plan_needed: deliveryProjection.plan_needed, environments: deliveryProjection.environments, ...(deliveryProjection.unavailable ? { unavailable: true } : {}) }
39
+ : null;
40
+ const visibleStages = listed.stages
41
+ .filter((stage) => stage.status !== "archived")
42
+ .sort((left, right) => Number(left.stage) - Number(right.stage));
43
+ const visibleStageIds = new Set(visibleStages.map((stage) => stage.stage));
36
44
  return {
37
45
  id: record.workspace,
38
46
  title: record.title,
39
47
  status: record.status,
40
48
  mode,
41
- ...(candidates ? { candidates } : {}),
42
- stages: listed.stages
43
- .filter((stage) => stage.status !== "archived")
44
- .sort((left, right) => Number(left.stage) - Number(right.stage))
49
+ ...(candidateProjection ? { candidates: candidateProjection.summary } : {}),
50
+ ...(delivery ? { delivery } : {}),
51
+ stages: visibleStages
45
52
  .map((stage) => ({
46
53
  id: stage.stage,
47
54
  title: stage.title,
48
55
  status: stage.status,
49
56
  description: stage.description,
50
- depends_on: stage.depends_on,
57
+ depends_on: stage.depends_on.filter((dependency) => visibleStageIds.has(dependency)),
51
58
  tracker_links: stage.tracker_links || [],
59
+ ...(candidateProjection?.by_stage[stage.stage] ? { candidates: candidateProjection.by_stage[stage.stage] } : {}),
52
60
  current: stage.stage === currentStage,
53
61
  })),
54
62
  currentStage,
@@ -0,0 +1,3 @@
1
+ import { work_context_mark_delivery } from "../src/tool-definitions.js";
2
+
3
+ export default work_context_mark_delivery;
@@ -0,0 +1,3 @@
1
+ import { work_context_read_delivery } from "../src/tool-definitions.js";
2
+
3
+ export default work_context_read_delivery;
@@ -0,0 +1 @@
1
+ export { work_context_read_stage_execution as default } from "../src/tool-definitions.js";
@@ -0,0 +1 @@
1
+ export { work_context_replace_stage_execution as default } from "../src/tool-definitions.js";
@@ -0,0 +1 @@
1
+ export { work_context_update_stage_execution as default } from "../src/tool-definitions.js";