opencode-work-context 0.6.2 → 0.7.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.
package/README.md CHANGED
@@ -441,15 +441,18 @@ workspace, every resume also supplies the agent with the startup policy:
441
441
  - a shared dirty worktree and concurrent stages are expected;
442
442
  - stages do not own files or commits;
443
443
  - ready work is captured promptly as an explicit commit candidate;
444
- - mixed-stage provenance alone is not a reason to stop;
445
- - a concrete overlapping or stale candidate patch is a reason to stop and report
446
- the conflict.
444
+ - exact, shared-foundation, and integration candidates express the intended
445
+ commit boundary without claiming stage ownership;
446
+ - mixed-stage provenance and complete files containing unrelated stage work are
447
+ not reasons to require prior commits or stop;
448
+ - only a concrete patch conflict, an incoherent candidate boundary, or failed
449
+ required verification stops candidate publication.
447
450
 
448
451
  Startup-mode workspaces can snapshot an explicit ready subset as a local commit
449
452
  candidate without creating a commit or modifying the ordinary Git index:
450
453
 
451
454
  ```text
452
- /wc candidate create 000123 "Ship parser fix" "Fix parser edge cases"
455
+ /wc candidate create 000123 "Ship parser fix" "Fix parser edge cases" strategy exact stages 02
453
456
  /wc candidate capture 000123 CC-000001 paths src/parser.js test/parser.test.js
454
457
  /wc candidate preview 000123 CC-000001
455
458
  /wc candidate ready 000123 CC-000001
@@ -463,6 +466,23 @@ A typical shared-tree sequence can keep unrelated work moving:
463
466
  3. Preview and mark candidate A ready, then commit it explicitly.
464
467
  4. The new commit contains `a.txt`; `b.txt` remains unchanged as working-tree WIP.
465
468
 
469
+ Choose the candidate strategy by the coherent repository change being published,
470
+ not by which stage touched each file:
471
+
472
+ - `exact` is the default and is preferred when the intended patch can be safely
473
+ separated from other WIP;
474
+ - `shared_foundation` captures one coherent prerequisite used by several stages;
475
+ - `integration` captures already-intertwined work from several stages when it
476
+ forms one reviewable and testable result and cannot be split safely.
477
+
478
+ Candidate creation may include several related stage IDs. They are normalized
479
+ and validated within the candidate workspace, then returned by create, list,
480
+ show, preview, ready, and commit operations. These references provide
481
+ traceability only: they do not assign files or hunks, change stage lifecycle or
482
+ dependencies, or infer relations from Git or session history. Existing candidate
483
+ records without strategy or stage-reference metadata remain readable; new
484
+ candidates default to `exact` with no related stages.
485
+
466
486
  The sidebar reads only candidate metadata and shows a compact
467
487
  `Candidates · pending <count> · ready <count>` line when either count is nonzero.
468
488
  It does not inspect Git state, patches, paths, or candidate freshness. A `ready`
@@ -486,6 +506,11 @@ metadata, the worktree, the ordinary index, and the branch ref unchanged by the
486
506
  operation. Commit publication uses `git commit-tree`, so it deliberately bypasses
487
507
  Git hooks and signing rather than invoking interactive policy.
488
508
 
509
+ If multiple stages have edited the same lines, Work Context cannot retrospectively
510
+ separate those edits by provenance. Use an integration candidate only when the
511
+ combined patch is coherent and verified; otherwise stop and establish a safe
512
+ candidate boundary before publication.
513
+
489
514
  Candidate publication is serialized by the repository-scoped `candidate-git`
490
515
  lock. Any operation that needs both locks acquires `candidate-git` before the
491
516
  work-context `write` lock; integrations must preserve this ordering to avoid
package/commands/wc.md CHANGED
@@ -29,7 +29,7 @@ Use these exact tool mappings; do not invent shortened tool names:
29
29
  - `workspace list <workspace>` or `<workspace> list` -> `work_context_workspace_list`
30
30
  - `workspace rename <workspace> "title"` -> `work_context_rename_workspace`
31
31
  - `workspace mode <workspace> <standard|startup>` -> `work_context_set_workspace_mode`
32
- - `candidate create <workspace> "title" ["message"]` -> `work_context_create_candidate`
32
+ - `candidate create <workspace> "title" ["message"] [strategy <exact|shared_foundation|integration>] [stages <stage>...]` -> `work_context_create_candidate`
33
33
  - `candidate capture <workspace> <candidateId> paths <path>...` or `candidate capture <workspace> <candidateId> patch "patch"` -> `work_context_capture_candidate`
34
34
  - `candidate preview <workspace> <candidateId>` -> `work_context_preview_candidate`
35
35
  - `candidate show <workspace> <candidateId>` -> `work_context_show_candidate`
@@ -62,7 +62,7 @@ Supported syntax:
62
62
  - `workspace list <workspace>`
63
63
  - `workspace rename <workspace> "title"`
64
64
  - `workspace mode <workspace> <standard|startup>`
65
- - `candidate create <workspace> "title" ["message"]`
65
+ - `candidate create <workspace> "title" ["message"] [strategy <exact|shared_foundation|integration>] [stages <stage>...]`
66
66
  - `candidate capture <workspace> <candidateId> paths <path>...`
67
67
  - `candidate capture <workspace> <candidateId> patch "patch"`
68
68
  - `candidate preview <workspace> <candidateId>`
@@ -100,7 +100,7 @@ Supported syntax:
100
100
  - when the saved prompt contains several clear deliverables, add `In this stage we will` with 2-5 short outcome-oriented bullets derived only from the prompt, previous result, and workspace knowledge; do not invent scope, and omit this block for a small stage
101
101
  - do not expose raw workspace/stage/session identifiers, ordinals, `ok` flags, or absent error codes in the user-facing resume summary
102
102
  - `resume.context.workspace_knowledge` contains every active durable knowledge entry for the workspace; treat it as established shared context, and do not repeat earlier analysis unless an entry is incomplete, contradicted, or needs verification
103
- - an associated OpenCode session resumed in a `startup` workspace receives `resume.context.workflow_policy`; follow it as active agent policy: a shared dirty worktree and concurrent stages are expected, stages do not own files or commits, ready work should be captured promptly into an explicit candidate, mixed-stage provenance alone is not a reason to stop, and an actual overlapping or stale candidate conflict must stop with a concrete report
103
+ - an associated OpenCode session resumed in a `startup` workspace receives `resume.context.workflow_policy`; follow it as active agent policy: a shared dirty worktree and concurrent stages are expected, stages do not own files or commits, and ready work should be captured promptly into an explicit candidate; prefer an `exact` candidate when safely separable, use `shared_foundation` when several stages use one coherent change, and use `integration` when intertwined changes form one reviewable and testable result; mixed provenance and complete files containing unrelated stage work are not reasons to require prior commits or stop; stop only for a concrete patch conflict, an incoherent candidate boundary, or failed required verification
104
104
  - standard-mode and unassociated core sessions do not receive startup policy; retain the existing conservative worktree behavior there
105
105
  - after presenting the summary, continue work immediately when `resume.next_action` is `start_work`; do not ask for generic confirmation
106
106
  - a stage may require confirmation only with an exact standalone `RESUME_CONFIRMATION: required` line in its saved prompt; when `resume.next_action` is `await_confirmation`, present the summary and wait before inspecting or modifying application code
@@ -117,7 +117,7 @@ Supported syntax:
117
117
  - `stage reopen <workspace> <stage> "reason"` applies only to a completed stage, preserves its result and completion history, records the reason, changes it to `in_progress`, and does not start a session or affect downstream stages; use an explicit separate-session `resume` to work on it again
118
118
  - `stage restore <workspace> <stage> "reason"` applies only to an archived stage and restores its saved pre-archive status. New archives preserve that status; legacy archives restore to `in_progress`. It records the reason, preserves stage content and results, does not start a session, and requires explicit separate-session `resume` when restored to `planned` or `in_progress`.
119
119
  - `workspace reopen <workspace> "reason"` applies only to a completed workspace, changes it to `in_progress`, and records durable recovery history. Cancelled workspaces cannot be reopened.
120
- - candidate operations require `startup` workflow mode and store metadata and patch payloads only under `.work-context/local/`; capture requires exactly one explicit list of complete paths or one Git unified patch and never infers stage ownership; commit requires a ready candidate, uses its stored message unless a non-empty override is supplied, serializes Git publication, bypasses hooks and signing, and never uses the ordinary Git index
120
+ - candidate operations require `startup` workflow mode and store metadata and patch payloads only under `.work-context/local/`; create accepts an optional strategy and related stages, which are normalized references for traceability only and never ownership or lifecycle; capture requires exactly one explicit list of complete paths or one Git unified patch and never infers stage ownership; commit requires a ready candidate, uses its stored message unless a non-empty override is supplied, serializes Git publication, bypasses hooks and signing, and never uses the ordinary Git index
121
121
  - `knowledge list|add|update|supersede <workspace> ...`
122
122
 
123
123
  Arguments: $ARGUMENTS
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "opencode-work-context",
3
3
  "type": "module",
4
- "version": "0.6.2",
4
+ "version": "0.7.0",
5
5
  "description": "Filesystem work-context core and OpenCode adapter",
6
6
  "license": "MIT",
7
7
  "author": {
package/src/candidates.js CHANGED
@@ -2,18 +2,20 @@ import fs from "node:fs";
2
2
  import path from "node:path";
3
3
  import { atomicWrite } from "./storage.js";
4
4
  import { ERROR_CODES, fail } from "./errors.js";
5
- import { normalizeWorkspaceId } from "./identifiers.js";
5
+ import { normalizeStageId, normalizeWorkspaceId } from "./identifiers.js";
6
6
  import { capturePatch, capturePaths, commitPatch, previewPatch, repositoryState } from "./git-candidates.js";
7
7
 
8
8
  const candidatePattern = /^CC-(\d{6})$/;
9
9
  const statuses = new Set(["draft", "ready", "discarded", "committed"]);
10
+ const strategies = new Set(["exact", "shared_foundation", "integration"]);
10
11
  const timestamp = (value) => typeof value === "string" && !Number.isNaN(Date.parse(value)) && new Date(value).toISOString() === value;
11
12
  const metadataKeys = ["schema", "candidate", "workspace", "title", "message", "base_head", "status", "created_at", "updated_at", "selected_paths", "patch_file"];
13
+ const optionalMetadataKeys = ["strategy", "related_stages"];
12
14
 
13
15
  function validateCandidate(data, expectedId = null) {
14
16
  const valid = data && typeof data === "object" && !Array.isArray(data)
15
17
  && metadataKeys.every((key) => Object.hasOwn(data, key))
16
- && Object.keys(data).every((key) => metadataKeys.includes(key) || ["commit_hash", "committed_at"].includes(key))
18
+ && Object.keys(data).every((key) => metadataKeys.includes(key) || optionalMetadataKeys.includes(key) || ["commit_hash", "committed_at"].includes(key))
17
19
  && data.schema === 1 && candidatePattern.test(data.candidate) && (!expectedId || data.candidate === expectedId)
18
20
  && /^\d{6}$/.test(data.workspace) && typeof data.title === "string" && data.title.trim()
19
21
  && typeof data.message === "string" && data.message.trim() && /^[0-9a-f]{40,64}$/.test(data.base_head)
@@ -22,6 +24,10 @@ function validateCandidate(data, expectedId = null) {
22
24
  && Array.isArray(data.selected_paths) && data.selected_paths.every((item) => typeof item === "string" && item && !path.isAbsolute(item) && !item.split("/").includes(".."))
23
25
  && new Set(data.selected_paths).size === data.selected_paths.length
24
26
  && data.patch_file === `${data.candidate}.patch`
27
+ && (Object.hasOwn(data, "strategy") === Object.hasOwn(data, "related_stages"))
28
+ && (!Object.hasOwn(data, "strategy") || (strategies.has(data.strategy)
29
+ && Array.isArray(data.related_stages) && data.related_stages.every((stage) => /^\d{2}$/.test(stage) && stage !== "00")
30
+ && new Set(data.related_stages).size === data.related_stages.length))
25
31
  && (data.status === "committed"
26
32
  ? /^[0-9a-f]{40,64}$/.test(data.commit_hash) && timestamp(data.committed_at)
27
33
  : !Object.hasOwn(data, "commit_hash") && !Object.hasOwn(data, "committed_at"));
@@ -74,13 +80,19 @@ export class CandidateStore {
74
80
  if (patch !== null) atomicWrite(this.patchFile(data.candidate), patch);
75
81
  }
76
82
 
77
- create(workspace, title, message = null) {
83
+ create(workspace, title, message = null, options = {}) {
78
84
  workspace = this.assertStartup(workspace);
79
85
  if (!title?.trim()) fail(ERROR_CODES.INVALID_ARGUMENT, "Candidate title is required");
86
+ const strategy = options.strategy ?? "exact";
87
+ if (!strategies.has(strategy)) fail(ERROR_CODES.INVALID_ARGUMENT, "Candidate strategy must be 'exact', 'shared_foundation' or 'integration'");
88
+ if (options.relatedStages !== undefined && !Array.isArray(options.relatedStages)) fail(ERROR_CODES.INVALID_ARGUMENT, "Related stages must be an array");
89
+ const relatedStages = (options.relatedStages || []).map(normalizeStageId);
90
+ if (new Set(relatedStages).size !== relatedStages.length) fail(ERROR_CODES.INVALID_ARGUMENT, "Related stages must be unique");
91
+ for (const stage of relatedStages) this.context.storage.readStage(workspace, stage);
80
92
  const repository = repositoryState(this.context.storage.projectRoot);
81
93
  const id = this.nextId();
82
94
  const now = new Date().toISOString();
83
- const data = { schema: 1, candidate: id, workspace, title: title.trim(), message: message?.trim() || title.trim(), base_head: repository.head, status: "draft", created_at: now, updated_at: now, selected_paths: [], patch_file: `${id}.patch` };
95
+ const data = { schema: 1, candidate: id, workspace, title: title.trim(), message: message?.trim() || title.trim(), strategy, related_stages: relatedStages, base_head: repository.head, status: "draft", created_at: now, updated_at: now, selected_paths: [], patch_file: `${id}.patch` };
84
96
  this.write(data, "");
85
97
  return data;
86
98
  }
package/src/core.js CHANGED
@@ -34,8 +34,9 @@ const startupWorkflowPolicy = () => ({
34
34
  guidance: [
35
35
  "A shared dirty worktree and concurrent stages are expected; stages do not own files or commits.",
36
36
  "Capture ready work promptly as an explicit commit candidate while unrelated work remains in progress.",
37
- "Mixed-stage provenance alone is not a reason to stop; do not reconstruct ownership after the fact.",
38
- "Stop only for a concrete overlapping or stale candidate conflict, and report that conflict explicitly.",
37
+ "Choose an exact candidate when separable, a shared foundation candidate when several stages use one change, or an integration candidate when intertwined changes form one coherent reviewable result.",
38
+ "Mixed-stage provenance or complete files containing unrelated stage work are not reasons to stop, require prior commits, or reconstruct ownership after the fact.",
39
+ "Stop only for a concrete patch conflict, an incoherent candidate boundary, or failed required verification, and report it explicitly.",
39
40
  ],
40
41
  });
41
42
  const startupWorkflowInstruction = (policy) => policy ? `\n\nStartup workflow policy:\n${policy.guidance.map((item) => `- ${item}`).join("\n")}` : "";
@@ -282,8 +283,8 @@ export class WorkContext {
282
283
 
283
284
  candidates() { return new CandidateStore(this); }
284
285
 
285
- createCandidate(workspace, title, message = null) {
286
- return this.transact("candidate-create", () => this.result(this.candidates().create(workspace, title, message), ["local:candidates"]));
286
+ createCandidate(workspace, title, message = null, options = {}) {
287
+ return this.transact("candidate-create", () => this.result(this.candidates().create(workspace, title, message, options), ["local:candidates"]));
287
288
  }
288
289
 
289
290
  listCandidates(workspace) { return { ok: true, data: this.candidates().list(workspace) }; }
@@ -743,7 +744,7 @@ export class WorkContext {
743
744
  return this.result({
744
745
  command,
745
746
  syntax: "/wc [create|list|workspace list|workspace rename|workspace mode|candidate create|candidate capture|candidate preview|candidate show|candidate list|candidate ready|candidate commit|candidate discard|workspace finish|workspace reopen|resume|stage add|stage reopen|stage restore|stage rename|stage update|stage update-prompt|stage update-result|stage force-close|stage archive|stage handoff|stage abandon|stage finish|link-issue|unlink-issue|session rename|knowledge list|knowledge add|knowledge update|knowledge supersede|help]",
746
- note: "associated OpenCode sessions in startup-mode workspaces receive the shared-worktree and commit-candidate policy on resume; standard mode remains conservative; commit candidates are local-only and require startup workflow mode; capture and commit use isolated Git indexes and never alter the ordinary index; candidate commit uses the stored message unless an explicit non-empty override is provided, and bypasses Git hooks and signing; stage finish requires an explicit user lifecycle request unless the Planning-stage prompt contains the exact line AUTO_STAGE_FINISH: allowed; stage reopen requires a completed stage and a reason; stage restore requires an archived stage and a reason, returns its saved pre-archive status (or in_progress for legacy archives), and requires explicit separate-session resume when actionable; workspace reopen requires a completed workspace and a reason.",
747
+ note: "associated OpenCode sessions in startup-mode workspaces receive the shared-worktree and commit-candidate policy on resume; standard mode remains conservative; candidate strategies are exact, shared_foundation, and integration, with optional related stage references for traceability only; commit candidates are local-only and require startup workflow mode; capture and commit use isolated Git indexes and never alter the ordinary index; candidate commit uses the stored message unless an explicit non-empty override is provided, and bypasses Git hooks and signing; stage finish requires an explicit user lifecycle request unless the Planning-stage prompt contains the exact line AUTO_STAGE_FINISH: allowed; stage reopen requires a completed stage and a reason; stage restore requires an archived stage and a reason, returns its saved pre-archive status (or in_progress for legacy archives), and requires explicit separate-session resume when actionable; workspace reopen requires a completed workspace and a reason.",
747
748
  }, []);
748
749
  }
749
750
 
@@ -57,7 +57,7 @@ export const work_context_list_workspaces = tool({ description: "List work-conte
57
57
  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)) });
58
58
  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)) });
59
59
  export const work_context_set_workspace_mode = tool({ description: "Set a workspace workflow mode.", args: { workspace: tool.schema.string(), mode: tool.schema.enum(["standard", "startup"]) }, execute: run((ctx, a) => ctx.setWorkspaceMode(a.workspace, a.mode)) });
60
- export const work_context_create_candidate = tool({ description: "Create a local draft commit candidate for a startup-mode workspace.", args: { workspace: tool.schema.string(), title: tool.schema.string(), message: tool.schema.string().optional() }, execute: run((ctx, a) => ctx.createCandidate(a.workspace, a.title, a.message)) });
60
+ export const work_context_create_candidate = tool({ description: "Create an exact, shared-foundation, or integration draft candidate. Related stages are optional traceability and never ownership.", args: { workspace: tool.schema.string(), title: tool.schema.string(), message: tool.schema.string().optional(), strategy: tool.schema.enum(["exact", "shared_foundation", "integration"]).optional(), relatedStages: tool.schema.array(tool.schema.string()).optional() }, execute: run((ctx, a) => ctx.createCandidate(a.workspace, a.title, a.message, { strategy: a.strategy, relatedStages: a.relatedStages })) });
61
61
  export const work_context_capture_candidate = tool({ description: "Capture explicit complete paths or an exact unified patch into a draft commit candidate.", args: { workspace: tool.schema.string(), candidateId: tool.schema.string(), paths: tool.schema.array(tool.schema.string()).optional(), patch: tool.schema.string().optional() }, execute: run((ctx, a) => ctx.captureCandidate(a.workspace, a.candidateId, { paths: a.paths, patch: a.patch })) });
62
62
  export const work_context_preview_candidate = tool({ description: "Preview a candidate using an isolated temporary Git index.", args: { workspace: tool.schema.string(), candidateId: tool.schema.string() }, execute: run((ctx, a) => ctx.previewCandidate(a.workspace, a.candidateId)) });
63
63
  export const work_context_show_candidate = tool({ description: "Show local candidate metadata and its exact captured patch.", args: { workspace: tool.schema.string(), candidateId: tool.schema.string() }, execute: run((ctx, a) => ctx.showCandidate(a.workspace, a.candidateId)) });