opencode-work-context 0.4.15 → 0.5.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 +96 -10
- package/bin/opencode-work-context.js +29 -4
- package/commands/wc.md +34 -1
- package/package.json +1 -1
- package/plugin/stages-tui.js +47 -5
- package/plugin/work-context.js +2 -1
- package/src/candidates.js +165 -0
- package/src/core.js +105 -14
- package/src/errors.js +5 -0
- package/src/git-candidates.js +163 -0
- package/src/index.js +2 -0
- package/src/opencode-adapter.js +7 -2
- package/src/stages-renderer.js +4 -2
- package/src/stages-snapshot.js +4 -1
- package/src/storage.js +3 -3
- package/src/title.js +12 -3
- package/src/tool-definitions.js +14 -4
- package/src/work-context-snapshot.js +5 -0
- package/tools/work_context_capture_candidate.js +3 -0
- package/tools/work_context_commit_candidate.js +3 -0
- package/tools/work_context_create_candidate.js +3 -0
- package/tools/work_context_discard_candidate.js +3 -0
- package/tools/work_context_list_candidates.js +3 -0
- package/tools/work_context_preview_candidate.js +3 -0
- package/tools/work_context_ready_candidate.js +3 -0
- package/tools/work_context_set_workspace_mode.js +3 -0
- package/tools/work_context_show_candidate.js +3 -0
- package/tools/work_context_unlink_issue.js +2 -0
package/README.md
CHANGED
|
@@ -108,6 +108,15 @@ without touching project configuration or loaders:
|
|
|
108
108
|
npx opencode-work-context sync-command --force
|
|
109
109
|
```
|
|
110
110
|
|
|
111
|
+
The generated `.opencode/commands/wc.md` and package-owned plugin loaders are
|
|
112
|
+
replaceable package projections. Do not add project-specific workflow logic to
|
|
113
|
+
them. Put additive project guidance in `.opencode/work-context.md`; `/wc` reads
|
|
114
|
+
that file when present and merges it into the package command context. Local
|
|
115
|
+
guidance can specialize project workflow, but cannot replace structured tool
|
|
116
|
+
mapping, storage safety, or explicit lifecycle rules. Implement executable
|
|
117
|
+
project extensions as separate project plugins rather than modifying generated
|
|
118
|
+
loaders.
|
|
119
|
+
|
|
111
120
|
Useful commands:
|
|
112
121
|
|
|
113
122
|
```text
|
|
@@ -155,6 +164,12 @@ plugin manager; the project does not import an npm-global path, create a local
|
|
|
155
164
|
package's server and optional TUI parts are loaded together by OpenCode, so this
|
|
156
165
|
also works on server-only hosts.
|
|
157
166
|
|
|
167
|
+
Managed activation has two scopes: it enables the plugin only in the current
|
|
168
|
+
project, while OpenCode keeps the package in its shared managed cache for every
|
|
169
|
+
activated project. It does not require `npm install -g` or a project-local npm
|
|
170
|
+
dependency. Restart OpenCode after publishing a new unpinned package version so
|
|
171
|
+
the managed plugin flow can refresh the shared copy.
|
|
172
|
+
|
|
158
173
|
Activation is opt-in. Projects without this entry stay inactive. If a machine
|
|
159
174
|
administrator or user has configured the package globally, a project can add
|
|
160
175
|
the explicit opt-out entry with:
|
|
@@ -240,12 +255,18 @@ refresh mechanisms.
|
|
|
240
255
|
Use a specific version instead of `latest` when you need a pinned upgrade, for
|
|
241
256
|
example `npx --yes opencode-work-context@0.1.10 init --force`.
|
|
242
257
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
- `.work-context/config.yaml`
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
- `.opencode/
|
|
258
|
+
Installed files and project state:
|
|
259
|
+
|
|
260
|
+
- `.work-context/config.yaml` is project-owned filesystem configuration; `init`
|
|
261
|
+
creates it once and preserves subsequent project changes, including with
|
|
262
|
+
`--force`;
|
|
263
|
+
- `.opencode/commands/wc.md` is the package-managed `/wc` command contract;
|
|
264
|
+
- `.opencode/plugins/work-context.js` is a package-managed thin server loader;
|
|
265
|
+
- `.opencode/tui-plugins/work-context-stages.js` is a package-managed reactive
|
|
266
|
+
stages-panel loader;
|
|
267
|
+
- `.opencode/tui.json` is shared project configuration; `init` merges the
|
|
268
|
+
work-context TUI entry and preserves other settings and plugin entries;
|
|
269
|
+
- `.opencode/work-context.md` is the optional project-owned instruction overlay;
|
|
249
270
|
- `.work-context/local/` in `.gitignore` for personal session events.
|
|
250
271
|
- `<workspace>/KNOWLEDGE.md` is the canonical durable knowledge ledger and is
|
|
251
272
|
created on the first explicit knowledge operation.
|
|
@@ -367,10 +388,10 @@ Tools are registered by the installed server export and are not copied into the
|
|
|
367
388
|
project. Core and storage remain in the installed package; projects should not
|
|
368
389
|
copy `src/` or `tools/`. `.work-context` Markdown, JSONL, `INDEX.md`, and
|
|
369
390
|
`SESSIONS.md` are generated projections and must never be edited manually.
|
|
370
|
-
Tracker links support GitLab issues (`/-/issues/<number>`)
|
|
371
|
-
(
|
|
372
|
-
references only; the plugin does not
|
|
373
|
-
metadata.
|
|
391
|
+
Tracker links support GitLab issues (`/-/issues/<number>`) and work items
|
|
392
|
+
(`/-/work_items/<number>`), GitHub issues (`/issues/<number>`), and Jira issues
|
|
393
|
+
(`/browse/KEY-123`). They are URL-based references only; the plugin does not
|
|
394
|
+
call provider APIs or synchronize issue metadata.
|
|
374
395
|
Knowledge operations are explicit: list, add, update, and supersede. Finishing a
|
|
375
396
|
stage always validates the Knowledge Base and reports its total and active entry
|
|
376
397
|
counts. Before finishing, persist new durable findings, update changed entries,
|
|
@@ -391,6 +412,71 @@ accepted only after every stage is `completed`. Use `/wc workspace list <workspa
|
|
|
391
412
|
to list stages with their descriptions. Workspace titles can be changed with
|
|
392
413
|
`/wc workspace rename <workspace> "title"`, and existing stage descriptions can
|
|
393
414
|
be changed with `/wc stage update <workspace> <stage> "description"`.
|
|
415
|
+
Workspaces use `standard` mode by default. Switch deliberately to the shared-tree
|
|
416
|
+
startup workflow with `/wc workspace mode <workspace> startup`; switch back with
|
|
417
|
+
`/wc workspace mode <workspace> standard`. The active workflow is shown below the
|
|
418
|
+
workspace title in the sidebar. Standard mode keeps the existing conservative
|
|
419
|
+
worktree behavior. When an OpenCode session is associated with a startup-mode
|
|
420
|
+
workspace, every resume also supplies the agent with the startup policy:
|
|
421
|
+
|
|
422
|
+
- a shared dirty worktree and concurrent stages are expected;
|
|
423
|
+
- stages do not own files or commits;
|
|
424
|
+
- ready work is captured promptly as an explicit commit candidate;
|
|
425
|
+
- mixed-stage provenance alone is not a reason to stop;
|
|
426
|
+
- a concrete overlapping or stale candidate patch is a reason to stop and report
|
|
427
|
+
the conflict.
|
|
428
|
+
|
|
429
|
+
Startup-mode workspaces can snapshot an explicit ready subset as a local commit
|
|
430
|
+
candidate without creating a commit or modifying the ordinary Git index:
|
|
431
|
+
|
|
432
|
+
```text
|
|
433
|
+
/wc candidate create 000123 "Ship parser fix" "Fix parser edge cases"
|
|
434
|
+
/wc candidate capture 000123 CC-000001 paths src/parser.js test/parser.test.js
|
|
435
|
+
/wc candidate preview 000123 CC-000001
|
|
436
|
+
/wc candidate ready 000123 CC-000001
|
|
437
|
+
/wc candidate commit 000123 CC-000001
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
A typical shared-tree sequence can keep unrelated work moving:
|
|
441
|
+
|
|
442
|
+
1. Change `a.txt`, create candidate A, and capture only `a.txt`.
|
|
443
|
+
2. Continue unfinished work in `b.txt` after A has been captured.
|
|
444
|
+
3. Preview and mark candidate A ready, then commit it explicitly.
|
|
445
|
+
4. The new commit contains `a.txt`; `b.txt` remains unchanged as working-tree WIP.
|
|
446
|
+
|
|
447
|
+
The sidebar reads only candidate metadata and shows a compact
|
|
448
|
+
`Candidates · pending <count> · ready <count>` line when either count is nonzero.
|
|
449
|
+
It does not inspect Git state, patches, paths, or candidate freshness. A `ready`
|
|
450
|
+
label therefore means lifecycle status, not a guarantee that a later publication
|
|
451
|
+
cannot encounter a conflict.
|
|
452
|
+
|
|
453
|
+
Capture accepts either complete repository paths or one exact Git unified patch,
|
|
454
|
+
which permits selecting individual hunks. Candidate metadata and patches are
|
|
455
|
+
stored only in `.work-context/local/candidates/`; they are not written to tracked
|
|
456
|
+
workspace projections. Preview reconstructs the recorded base in a temporary
|
|
457
|
+
`GIT_INDEX_FILE`, so the normal index, unrelated files, and unrelated hunks remain
|
|
458
|
+
unchanged. Binary patches, paths outside the repository, malformed patches,
|
|
459
|
+
repositories without `HEAD`, and candidate operations in `standard` mode are
|
|
460
|
+
rejected. A preview reports when the current `HEAD` differs from the recorded
|
|
461
|
+
base. `candidate commit` requires a ready candidate and uses its stored message;
|
|
462
|
+
an optional final argument overrides that message. Publication reconstructs the
|
|
463
|
+
current `HEAD` in another temporary index, reapplies a stale candidate only when
|
|
464
|
+
its exact patch still applies cleanly, creates the commit, and compare-and-swaps
|
|
465
|
+
the attached branch ref. Overlap, detached `HEAD`, or a ref race leaves candidate
|
|
466
|
+
metadata, the worktree, the ordinary index, and the branch ref unchanged by the
|
|
467
|
+
operation. Commit publication uses `git commit-tree`, so it deliberately bypasses
|
|
468
|
+
Git hooks and signing rather than invoking interactive policy.
|
|
469
|
+
|
|
470
|
+
Candidate publication is serialized by the repository-scoped `candidate-git`
|
|
471
|
+
lock. Any operation that needs both locks acquires `candidate-git` before the
|
|
472
|
+
work-context `write` lock; integrations must preserve this ordering to avoid
|
|
473
|
+
deadlocks. Lock owners are released after success or failure. Existing stale-lock
|
|
474
|
+
handling remains explicit rather than removing an unknown owner's lock.
|
|
475
|
+
|
|
476
|
+
Use `/wc candidate show`, `/wc candidate list`, and `/wc candidate discard` to
|
|
477
|
+
inspect or retire local candidates. Candidate patches may contain source code or
|
|
478
|
+
secrets and follow the same local-only handling requirements as other files under
|
|
479
|
+
`.work-context/local/`.
|
|
394
480
|
`/wc workspace reopen <workspace> "reason"` records a recovery entry and returns
|
|
395
481
|
only a completed workspace to `in_progress`.
|
|
396
482
|
|
|
@@ -18,12 +18,14 @@ const dependencyRoot = fs.existsSync(path.join(projectRoot, "package.json"))
|
|
|
18
18
|
const dependencyManifestFile = path.join(dependencyRoot, "package.json");
|
|
19
19
|
let dependencyManifest = {};
|
|
20
20
|
try { dependencyManifest = JSON.parse(fs.readFileSync(dependencyManifestFile, "utf8")); } catch {}
|
|
21
|
-
const pluginLoader = `//
|
|
21
|
+
const pluginLoader = `// Package-managed loader: keep project extensions in separate plugin files.
|
|
22
|
+
// Server tools and lifecycle hooks stay in the installed package.
|
|
22
23
|
import serverPlugin from "${packageManifest.name}/server";
|
|
23
24
|
|
|
24
25
|
export default serverPlugin.server;
|
|
25
26
|
`;
|
|
26
|
-
const tuiLoader = `//
|
|
27
|
+
const tuiLoader = `// Package-managed loader: keep project extensions in separate TUI plugin files.
|
|
28
|
+
// TUI integration stays in the installed package; do not copy src/ or tools.
|
|
27
29
|
import { createSignal } from "solid-js";
|
|
28
30
|
import { jsx } from "@opentui/solid/jsx-runtime";
|
|
29
31
|
import plugin from "${packageManifest.name}/tui";
|
|
@@ -43,13 +45,16 @@ const tuiConfig = JSON.stringify({
|
|
|
43
45
|
plugin: ["./tui-plugins/work-context-stages.js"],
|
|
44
46
|
}, null, 2) + "\n";
|
|
45
47
|
const command = fs.readFileSync(path.join(packageRoot, "commands", "wc.md"), "utf8");
|
|
48
|
+
const configRelative = path.join(".work-context", "config.yaml");
|
|
49
|
+
const tuiConfigRelative = path.join(".opencode", "tui.json");
|
|
50
|
+
const tuiPluginEntry = "./tui-plugins/work-context-stages.js";
|
|
46
51
|
const generated = new Map([
|
|
47
|
-
[
|
|
52
|
+
[configRelative, defaultConfig()],
|
|
48
53
|
[path.join(".opencode", "commands", "wc.md"), command],
|
|
49
54
|
[path.join(".opencode", "plugins", "work-context.js"), `// Thin project integration; tools remain in the installed npm package.
|
|
50
55
|
${pluginLoader}`],
|
|
51
56
|
[path.join(".opencode", "tui-plugins", "work-context-stages.js"), tuiLoader],
|
|
52
|
-
[
|
|
57
|
+
[tuiConfigRelative, tuiConfig],
|
|
53
58
|
]);
|
|
54
59
|
|
|
55
60
|
const fail = (message) => {
|
|
@@ -171,6 +176,16 @@ function ensureModuleScope() {
|
|
|
171
176
|
}
|
|
172
177
|
|
|
173
178
|
function checkConflicts(force) {
|
|
179
|
+
const sharedTuiConfig = path.join(projectRoot, tuiConfigRelative);
|
|
180
|
+
if (exists(sharedTuiConfig) && fs.lstatSync(sharedTuiConfig).isFile() && !fs.lstatSync(sharedTuiConfig).isSymbolicLink()) {
|
|
181
|
+
try {
|
|
182
|
+
const config = JSON.parse(fs.readFileSync(sharedTuiConfig, "utf8"));
|
|
183
|
+
if (!config || typeof config !== "object" || Array.isArray(config) || (config.plugin !== undefined && (!Array.isArray(config.plugin) || config.plugin.some((item) => typeof item !== "string")))) throw new Error("unsupported shape");
|
|
184
|
+
} catch {
|
|
185
|
+
fail(`cannot merge unsupported configuration: ${tuiConfigRelative}`);
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
174
189
|
const conflicts = ["package.json", "package-lock.json", "npm-shrinkwrap.json"].flatMap((relative) => {
|
|
175
190
|
const file = path.join(dependencyRoot, relative);
|
|
176
191
|
if (!exists(file)) return [];
|
|
@@ -184,6 +199,8 @@ function checkConflicts(force) {
|
|
|
184
199
|
if (!exists(file)) return [];
|
|
185
200
|
const stat = fs.lstatSync(file);
|
|
186
201
|
if (!stat.isFile() || stat.isSymbolicLink()) return [relative];
|
|
202
|
+
if (relative === configRelative) return [];
|
|
203
|
+
if (relative === tuiConfigRelative) return [];
|
|
187
204
|
return !force && fs.readFileSync(file, "utf8") !== content ? [relative] : [];
|
|
188
205
|
}));
|
|
189
206
|
const gitignore = path.join(projectRoot, ".gitignore");
|
|
@@ -337,6 +354,14 @@ function installPackage(snapshot) {
|
|
|
337
354
|
function writeGenerated() {
|
|
338
355
|
for (const [relative, content] of generated) {
|
|
339
356
|
const file = path.join(projectRoot, relative);
|
|
357
|
+
if (relative === configRelative && exists(file)) continue;
|
|
358
|
+
if (relative === tuiConfigRelative && exists(file)) {
|
|
359
|
+
const config = JSON.parse(fs.readFileSync(file, "utf8"));
|
|
360
|
+
config.plugin = [...(config.plugin || []).filter((item) => item !== tuiPluginEntry), tuiPluginEntry];
|
|
361
|
+
const merged = JSON.stringify(config, null, 2) + "\n";
|
|
362
|
+
if (fs.readFileSync(file, "utf8") !== merged) writeAtomic(file, merged);
|
|
363
|
+
continue;
|
|
364
|
+
}
|
|
340
365
|
if (!exists(file) || fs.readFileSync(file, "utf8") !== content) writeAtomic(file, content);
|
|
341
366
|
}
|
|
342
367
|
const gitignore = path.join(projectRoot, ".gitignore");
|
package/commands/wc.md
CHANGED
|
@@ -10,8 +10,17 @@ other than `resume`, report the structured result and stable error code. For
|
|
|
10
10
|
`resume`, follow its human-oriented presentation rules instead. Use `work_context_help` when
|
|
11
11
|
the syntax is missing or ambiguous.
|
|
12
12
|
|
|
13
|
+
`.opencode/commands/wc.md` is package-managed and may be replaced during install,
|
|
14
|
+
activation, or `sync-command`. Never store project-specific workflow logic in this
|
|
15
|
+
file or generated plugin loaders. Keep additive project instructions in
|
|
16
|
+
`.opencode/work-context.md`; when that file exists, read it before dispatching the
|
|
17
|
+
operation and merge its guidance into this command context. Project guidance may
|
|
18
|
+
specialize local workflow, but it must not override this tool mapping, structured
|
|
19
|
+
arguments, storage safety, or explicit lifecycle requirements.
|
|
20
|
+
|
|
13
21
|
For `workspace list <workspace>` (or `<workspace> list`), report the workspace
|
|
14
|
-
status and every stage as
|
|
22
|
+
status and workflow mode, then every stage as
|
|
23
|
+
`stage - status - title - description`.
|
|
15
24
|
|
|
16
25
|
Use these exact tool mappings; do not invent shortened tool names:
|
|
17
26
|
|
|
@@ -19,6 +28,15 @@ Use these exact tool mappings; do not invent shortened tool names:
|
|
|
19
28
|
- `list` -> `work_context_list_workspaces`
|
|
20
29
|
- `workspace list <workspace>` or `<workspace> list` -> `work_context_workspace_list`
|
|
21
30
|
- `workspace rename <workspace> "title"` -> `work_context_rename_workspace`
|
|
31
|
+
- `workspace mode <workspace> <standard|startup>` -> `work_context_set_workspace_mode`
|
|
32
|
+
- `candidate create <workspace> "title" ["message"]` -> `work_context_create_candidate`
|
|
33
|
+
- `candidate capture <workspace> <candidateId> paths <path>...` or `candidate capture <workspace> <candidateId> patch "patch"` -> `work_context_capture_candidate`
|
|
34
|
+
- `candidate preview <workspace> <candidateId>` -> `work_context_preview_candidate`
|
|
35
|
+
- `candidate show <workspace> <candidateId>` -> `work_context_show_candidate`
|
|
36
|
+
- `candidate list <workspace>` -> `work_context_list_candidates`
|
|
37
|
+
- `candidate ready <workspace> <candidateId>` -> `work_context_ready_candidate`
|
|
38
|
+
- `candidate commit <workspace> <candidateId> ["message"]` -> `work_context_commit_candidate`
|
|
39
|
+
- `candidate discard <workspace> <candidateId>` -> `work_context_discard_candidate`
|
|
22
40
|
- `workspace finish <workspace>` -> `work_context_workspace_finish`
|
|
23
41
|
- `workspace reopen <workspace> "reason"` -> `work_context_reopen_workspace`
|
|
24
42
|
- `resume <workspace> <stage>` -> `work_context_start_session`
|
|
@@ -34,6 +52,7 @@ Use these exact tool mappings; do not invent shortened tool names:
|
|
|
34
52
|
- `stage handoff [<workspace>] [<stage>]` -> `work_context_handoff_stage`
|
|
35
53
|
- `stage abandon [<workspace>] [<stage>]` -> `work_context_abandon_stage`
|
|
36
54
|
- `stage finish [<workspace>] [<stage>]` -> `work_context_finish_stage`
|
|
55
|
+
- `<workspace> [<stage>] unlink-issue <URL>` -> `work_context_unlink_issue`
|
|
37
56
|
|
|
38
57
|
Supported syntax:
|
|
39
58
|
|
|
@@ -42,6 +61,16 @@ Supported syntax:
|
|
|
42
61
|
- `list` or `<workspace> list`
|
|
43
62
|
- `workspace list <workspace>`
|
|
44
63
|
- `workspace rename <workspace> "title"`
|
|
64
|
+
- `workspace mode <workspace> <standard|startup>`
|
|
65
|
+
- `candidate create <workspace> "title" ["message"]`
|
|
66
|
+
- `candidate capture <workspace> <candidateId> paths <path>...`
|
|
67
|
+
- `candidate capture <workspace> <candidateId> patch "patch"`
|
|
68
|
+
- `candidate preview <workspace> <candidateId>`
|
|
69
|
+
- `candidate show <workspace> <candidateId>`
|
|
70
|
+
- `candidate list <workspace>`
|
|
71
|
+
- `candidate ready <workspace> <candidateId>`
|
|
72
|
+
- `candidate commit <workspace> <candidateId> ["message"]`
|
|
73
|
+
- `candidate discard <workspace> <candidateId>`
|
|
45
74
|
- `workspace finish <workspace>`
|
|
46
75
|
- `workspace reopen <workspace> "reason"`
|
|
47
76
|
- `resume <workspace> <stage>`
|
|
@@ -58,6 +87,7 @@ Supported syntax:
|
|
|
58
87
|
- `stage abandon [<workspace>] [<stage>]`
|
|
59
88
|
- `stage finish [<workspace>] [<stage>]`
|
|
60
89
|
- `<workspace> [<stage>] link-issue <URL>`
|
|
90
|
+
- `<workspace> [<stage>] unlink-issue <URL>`
|
|
61
91
|
- `session rename "summary"`
|
|
62
92
|
- `stage handoff [<workspace>] <stage>`
|
|
63
93
|
- `stage abandon [<workspace>] <stage>`
|
|
@@ -70,6 +100,8 @@ Supported syntax:
|
|
|
70
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
|
|
71
101
|
- do not expose raw workspace/stage/session identifiers, ordinals, `ok` flags, or absent error codes in the user-facing resume summary
|
|
72
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
|
|
104
|
+
- standard-mode and unassociated core sessions do not receive startup policy; retain the existing conservative worktree behavior there
|
|
73
105
|
- after presenting the summary, continue work immediately when `resume.next_action` is `start_work`; do not ask for generic confirmation
|
|
74
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
|
|
75
107
|
- `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
|
|
@@ -85,6 +117,7 @@ Supported syntax:
|
|
|
85
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
|
|
86
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`.
|
|
87
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
|
|
88
121
|
- `knowledge list|add|update|supersede <workspace> ...`
|
|
89
122
|
|
|
90
123
|
Arguments: $ARGUMENTS
|
package/package.json
CHANGED
package/plugin/stages-tui.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { readStagesSnapshot } from "../src/stages-snapshot.js";
|
|
4
|
+
import { contextFor, titleFor } from "../src/opencode-adapter.js";
|
|
4
5
|
import { renderDependencyTree, renderStagesPanel } from "../src/stages-renderer.js";
|
|
5
6
|
import { jsx } from "@opentui/solid/jsx-runtime";
|
|
6
7
|
import { createSignal } from "solid-js";
|
|
@@ -26,6 +27,15 @@ const statusMarker = (status) => ({
|
|
|
26
27
|
cancelled: "[!]",
|
|
27
28
|
archived: "[-]",
|
|
28
29
|
}[status] || "[?]");
|
|
30
|
+
const trackerLinkText = (link) => {
|
|
31
|
+
const identifier = link.key || link.iid;
|
|
32
|
+
if (link.provider === "gitlab") return `GL#${identifier}`;
|
|
33
|
+
if (link.provider === "github") return `GH#${identifier}`;
|
|
34
|
+
return `JIRA ${identifier}`;
|
|
35
|
+
};
|
|
36
|
+
const candidateSummaryText = (workspace) => workspace.candidates && (workspace.candidates.pending || workspace.candidates.ready)
|
|
37
|
+
? `Candidates · pending ${workspace.candidates.pending} · ready ${workspace.candidates.ready}`
|
|
38
|
+
: null;
|
|
29
39
|
|
|
30
40
|
export { readStagesSnapshot, renderStagesPanel };
|
|
31
41
|
|
|
@@ -45,7 +55,12 @@ const renderStagesContent = (result, theme, runtime = defaultRuntime, attention,
|
|
|
45
55
|
: [
|
|
46
56
|
runtime.jsx("box", {
|
|
47
57
|
marginBottom: 1,
|
|
48
|
-
|
|
58
|
+
flexDirection: "column",
|
|
59
|
+
children: [
|
|
60
|
+
runtime.jsx("text", { wrapMode: "word", children: runtime.jsx("b", { children: `${attention?.attentionForWorkspace?.(result.data.workspace.id) ? "[ATTN] " : ""}${result.data.workspace.title}` }) }),
|
|
61
|
+
runtime.jsx("text", { fg: theme?.current?.textMuted, children: `Workflow · ${result.data.workspace.mode || "standard"}` }),
|
|
62
|
+
candidateSummaryText(result.data.workspace) && runtime.jsx("text", { fg: theme?.current?.textMuted, children: candidateSummaryText(result.data.workspace) }),
|
|
63
|
+
],
|
|
49
64
|
}),
|
|
50
65
|
runtime.jsx("box", {
|
|
51
66
|
flexDirection: "row",
|
|
@@ -56,7 +71,16 @@ const renderStagesContent = (result, theme, runtime = defaultRuntime, attention,
|
|
|
56
71
|
}),
|
|
57
72
|
...result.data.stages.map((stage) => {
|
|
58
73
|
const unread = attention?.attentionForStage?.(result.data.workspace.id, stage.id);
|
|
59
|
-
const
|
|
74
|
+
const metadata = showDependencies ? [
|
|
75
|
+
stage.tracker_links?.length && `Tasks: ${stage.tracker_links.map(trackerLinkText).join(", ")}`,
|
|
76
|
+
stage.depends_on?.length && `Deps: ${stage.depends_on.join(", ")}`,
|
|
77
|
+
].filter(Boolean).join(" · ") : "";
|
|
78
|
+
const attentionText = unread ? `[ATTN: ${attentionReasonText(unread.reason)}${unread.count > 1 ? ` x${unread.count}` : ""}]` : "";
|
|
79
|
+
const stageText = [
|
|
80
|
+
`${stage.id}. ${stage.title}`,
|
|
81
|
+
metadata,
|
|
82
|
+
attentionText,
|
|
83
|
+
].filter(Boolean).join("\n");
|
|
60
84
|
return runtime.jsx("box", {
|
|
61
85
|
flexDirection: "row",
|
|
62
86
|
onMouseDown: (event) => {
|
|
@@ -227,7 +251,21 @@ const renderStagesSlot = (controller, theme, sessionId, runtime = defaultRuntime
|
|
|
227
251
|
children: renderStagesElement(() => controller.resultFor(sessionId), theme, runtime, attention, controller.showDependencies, onStageSelect),
|
|
228
252
|
});
|
|
229
253
|
|
|
230
|
-
const
|
|
254
|
+
const updateSessionTitle = async (api, projectRoot) => {
|
|
255
|
+
const sessionId = api?.route?.current?.params?.sessionID
|
|
256
|
+
|| api?.route?.current?.params?.sessionId
|
|
257
|
+
|| api?.route?.current?.params?.session_id;
|
|
258
|
+
if (!sessionId || typeof api?.client?.session?.update !== "function") return;
|
|
259
|
+
try {
|
|
260
|
+
const context = contextFor(projectRoot, sessionId);
|
|
261
|
+
const session = context.sessionById(sessionId) || context.sessionByOpenCodeId(sessionId, null, null, null);
|
|
262
|
+
if (!session) return;
|
|
263
|
+
const title = titleFor(context, session.workspace, session.stage, sessionId, session, readTuiState(projectRoot).sidebar_dependencies === true);
|
|
264
|
+
await api.client.session.update({ path: { id: sessionId }, query: { directory: projectRoot }, body: { title } });
|
|
265
|
+
} catch {}
|
|
266
|
+
};
|
|
267
|
+
|
|
268
|
+
const registerDependencyToggle = (api, controller, projectRoot) => {
|
|
231
269
|
if (typeof api?.keymap?.registerLayer !== "function") return () => {};
|
|
232
270
|
const command = {
|
|
233
271
|
name: DEPENDENCIES_COMMAND,
|
|
@@ -235,7 +273,11 @@ const registerDependencyToggle = (api, controller) => {
|
|
|
235
273
|
desc: "Show or hide dependency IDs in the stages sidebar",
|
|
236
274
|
category: "Work Context",
|
|
237
275
|
namespace: "palette",
|
|
238
|
-
run: () =>
|
|
276
|
+
run: () => {
|
|
277
|
+
const visible = controller.toggleDependencies();
|
|
278
|
+
void updateSessionTitle(api, projectRoot);
|
|
279
|
+
return visible;
|
|
280
|
+
},
|
|
239
281
|
};
|
|
240
282
|
return api.keymap.registerLayer({
|
|
241
283
|
commands: [command],
|
|
@@ -312,7 +354,7 @@ export const tui = async (api, options = {}) => {
|
|
|
312
354
|
attention: api.workContextAttention,
|
|
313
355
|
});
|
|
314
356
|
const stageSwitcher = createStageSwitcherFlow(api);
|
|
315
|
-
const unregisterDependencyToggle = registerDependencyToggle(api, controller);
|
|
357
|
+
const unregisterDependencyToggle = registerDependencyToggle(api, controller, projectRoot);
|
|
316
358
|
let currentSessionId = initialSessionId;
|
|
317
359
|
const unregisterDependencyTree = registerDependencyTree(api, controller, () => currentSessionId || ACTIVE_WORKSPACE_SESSION);
|
|
318
360
|
await controller.load(initialSessionId);
|
package/plugin/work-context.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import tools from "../src/tool-definitions.js";
|
|
2
2
|
import { contextFor, titleFor } from "../src/opencode-adapter.js";
|
|
3
|
+
import { readTuiState } from "./tui-state.js";
|
|
3
4
|
|
|
4
5
|
export default async ({ client, directory, worktree }) => ({
|
|
5
6
|
tool: tools,
|
|
@@ -25,7 +26,7 @@ async function updateSessionTitle(client, projectRoot, directory, sessionId) {
|
|
|
25
26
|
const context = contextFor(projectRoot, sessionId);
|
|
26
27
|
const session = context.sessionById(sessionId) || context.sessionByOpenCodeId(sessionId, null, null, null);
|
|
27
28
|
if (!session) return;
|
|
28
|
-
const title = titleFor(context, session.workspace, session.stage, sessionId, session);
|
|
29
|
+
const title = titleFor(context, session.workspace, session.stage, sessionId, session, readTuiState(projectRoot).sidebar_dependencies === true);
|
|
29
30
|
if (!title) return;
|
|
30
31
|
const current = await client.session.get({ path: { id: sessionId }, query: { directory } });
|
|
31
32
|
const currentSession = current.data ?? current;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { atomicWrite } from "./storage.js";
|
|
4
|
+
import { ERROR_CODES, fail } from "./errors.js";
|
|
5
|
+
import { normalizeWorkspaceId } from "./identifiers.js";
|
|
6
|
+
import { capturePatch, capturePaths, commitPatch, previewPatch, repositoryState } from "./git-candidates.js";
|
|
7
|
+
|
|
8
|
+
const candidatePattern = /^CC-(\d{6})$/;
|
|
9
|
+
const statuses = new Set(["draft", "ready", "discarded", "committed"]);
|
|
10
|
+
const timestamp = (value) => typeof value === "string" && !Number.isNaN(Date.parse(value)) && new Date(value).toISOString() === value;
|
|
11
|
+
const metadataKeys = ["schema", "candidate", "workspace", "title", "message", "base_head", "status", "created_at", "updated_at", "selected_paths", "patch_file"];
|
|
12
|
+
|
|
13
|
+
function validateCandidate(data, expectedId = null) {
|
|
14
|
+
const valid = data && typeof data === "object" && !Array.isArray(data)
|
|
15
|
+
&& metadataKeys.every((key) => Object.hasOwn(data, key))
|
|
16
|
+
&& Object.keys(data).every((key) => metadataKeys.includes(key) || ["commit_hash", "committed_at"].includes(key))
|
|
17
|
+
&& data.schema === 1 && candidatePattern.test(data.candidate) && (!expectedId || data.candidate === expectedId)
|
|
18
|
+
&& /^\d{6}$/.test(data.workspace) && typeof data.title === "string" && data.title.trim()
|
|
19
|
+
&& typeof data.message === "string" && data.message.trim() && /^[0-9a-f]{40,64}$/.test(data.base_head)
|
|
20
|
+
&& statuses.has(data.status) && timestamp(data.created_at) && timestamp(data.updated_at)
|
|
21
|
+
&& Date.parse(data.updated_at) >= Date.parse(data.created_at)
|
|
22
|
+
&& Array.isArray(data.selected_paths) && data.selected_paths.every((item) => typeof item === "string" && item && !path.isAbsolute(item) && !item.split("/").includes(".."))
|
|
23
|
+
&& new Set(data.selected_paths).size === data.selected_paths.length
|
|
24
|
+
&& data.patch_file === `${data.candidate}.patch`
|
|
25
|
+
&& (data.status === "committed"
|
|
26
|
+
? /^[0-9a-f]{40,64}$/.test(data.commit_hash) && timestamp(data.committed_at)
|
|
27
|
+
: !Object.hasOwn(data, "commit_hash") && !Object.hasOwn(data, "committed_at"));
|
|
28
|
+
if (!valid) fail(ERROR_CODES.STORAGE_ERROR, "Invalid commit candidate metadata");
|
|
29
|
+
return data;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export class CandidateStore {
|
|
33
|
+
constructor(context) {
|
|
34
|
+
this.context = context;
|
|
35
|
+
this.directory = path.join(context.storage.personalRoot, "candidates");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
assertStartup(workspace) {
|
|
39
|
+
this.context.storage.assertNoSymlinks();
|
|
40
|
+
workspace = normalizeWorkspaceId(workspace);
|
|
41
|
+
const record = this.context.storage.readWorkspace(workspace);
|
|
42
|
+
if ((record.data.mode || "standard") !== "startup") fail(ERROR_CODES.CANDIDATE_MODE_REQUIRED, "Commit candidates require startup workflow mode", { workspace });
|
|
43
|
+
return workspace;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
metadataFile(id) { return path.join(this.directory, `${id}.json`); }
|
|
47
|
+
patchFile(id) { return path.join(this.directory, `${id}.patch`); }
|
|
48
|
+
|
|
49
|
+
nextId() {
|
|
50
|
+
if (!fs.existsSync(this.directory)) return "CC-000001";
|
|
51
|
+
const numbers = fs.readdirSync(this.directory).map((file) => file.match(/^CC-(\d{6})\.(?:json|patch)$/)?.[1]).filter(Boolean).map(Number);
|
|
52
|
+
const next = Math.max(0, ...numbers) + 1;
|
|
53
|
+
if (next > 999999) fail(ERROR_CODES.INVALID_STATE, "Commit candidate ID space is exhausted");
|
|
54
|
+
return `CC-${String(next).padStart(6, "0")}`;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
read(id, workspace = null, includePatch = false) {
|
|
58
|
+
if (typeof id !== "string" || !candidatePattern.test(id)) fail(ERROR_CODES.INVALID_ARGUMENT, "Invalid commit candidate ID");
|
|
59
|
+
let data;
|
|
60
|
+
try { data = JSON.parse(fs.readFileSync(this.metadataFile(id), "utf8")); }
|
|
61
|
+
catch (error) { if (error.code === "ENOENT") fail(ERROR_CODES.NOT_FOUND, "Commit candidate not found", { candidate: id }); fail(ERROR_CODES.STORAGE_ERROR, "Invalid commit candidate metadata", { cause: error.message }); }
|
|
62
|
+
validateCandidate(data, id);
|
|
63
|
+
if (workspace && data.workspace !== normalizeWorkspaceId(workspace)) fail(ERROR_CODES.NOT_FOUND, "Commit candidate is not associated with this workspace", { candidate: id });
|
|
64
|
+
if (!includePatch) return data;
|
|
65
|
+
let patch;
|
|
66
|
+
try { patch = fs.readFileSync(this.patchFile(id), "utf8"); }
|
|
67
|
+
catch (error) { fail(ERROR_CODES.STORAGE_ERROR, "Commit candidate patch is unavailable", { cause: error.message }); }
|
|
68
|
+
return { ...data, patch };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
write(data, patch = null) {
|
|
72
|
+
validateCandidate(data, data.candidate);
|
|
73
|
+
atomicWrite(this.metadataFile(data.candidate), `${JSON.stringify(data, null, 2)}\n`);
|
|
74
|
+
if (patch !== null) atomicWrite(this.patchFile(data.candidate), patch);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
create(workspace, title, message = null) {
|
|
78
|
+
workspace = this.assertStartup(workspace);
|
|
79
|
+
if (!title?.trim()) fail(ERROR_CODES.INVALID_ARGUMENT, "Candidate title is required");
|
|
80
|
+
const repository = repositoryState(this.context.storage.projectRoot);
|
|
81
|
+
const id = this.nextId();
|
|
82
|
+
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` };
|
|
84
|
+
this.write(data, "");
|
|
85
|
+
return data;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
list(workspace) {
|
|
89
|
+
workspace = this.assertStartup(workspace);
|
|
90
|
+
if (!fs.existsSync(this.directory)) return [];
|
|
91
|
+
return fs.readdirSync(this.directory).filter((file) => candidatePattern.test(file.slice(0, -5)) && file.endsWith(".json"))
|
|
92
|
+
.map((file) => this.read(file.slice(0, -5))).filter((item) => item.workspace === workspace)
|
|
93
|
+
.sort((a, b) => a.candidate.localeCompare(b.candidate));
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
summary(workspace) {
|
|
97
|
+
return this.list(workspace).reduce((summary, candidate) => {
|
|
98
|
+
if (candidate.status === "draft") summary.pending += 1;
|
|
99
|
+
if (candidate.status === "ready") summary.ready += 1;
|
|
100
|
+
return summary;
|
|
101
|
+
}, { pending: 0, ready: 0 });
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
capture(workspace, id, input) {
|
|
105
|
+
workspace = this.assertStartup(workspace);
|
|
106
|
+
const data = this.read(id, workspace);
|
|
107
|
+
if (data.status !== "draft") fail(ERROR_CODES.INVALID_STATE, "Only draft candidates can be captured", { status: data.status });
|
|
108
|
+
const hasPaths = Array.isArray(input.paths);
|
|
109
|
+
const hasPatch = input.patch !== undefined;
|
|
110
|
+
if (hasPaths === hasPatch) fail(ERROR_CODES.INVALID_ARGUMENT, "Provide exactly one of paths or patch");
|
|
111
|
+
const root = repositoryState(this.context.storage.projectRoot).root;
|
|
112
|
+
const captured = hasPaths
|
|
113
|
+
? capturePaths(root, this.context.storage.personalRoot, data.base_head, input.paths)
|
|
114
|
+
: capturePatch(root, this.context.storage.personalRoot, data.base_head, input.patch);
|
|
115
|
+
data.selected_paths = captured.paths;
|
|
116
|
+
data.updated_at = new Date().toISOString();
|
|
117
|
+
this.write(data, captured.patch);
|
|
118
|
+
return { ...data, patch: captured.patch };
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
preview(workspace, id) {
|
|
122
|
+
workspace = this.assertStartup(workspace);
|
|
123
|
+
const data = this.read(id, workspace, true);
|
|
124
|
+
if (!data.patch) fail(ERROR_CODES.INVALID_STATE, "Commit candidate has not captured a patch");
|
|
125
|
+
return { candidate: data, preview: previewPatch(this.context.storage.projectRoot, data.base_head, data.patch) };
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
setStatus(workspace, id, status) {
|
|
129
|
+
workspace = this.assertStartup(workspace);
|
|
130
|
+
const data = this.read(id, workspace, true);
|
|
131
|
+
if (status === "ready" && data.status !== "draft") fail(ERROR_CODES.INVALID_STATE, "Only draft candidates can become ready", { status: data.status });
|
|
132
|
+
if (status === "discarded" && data.status === "discarded") return data;
|
|
133
|
+
if (status === "discarded" && data.status === "committed") fail(ERROR_CODES.INVALID_STATE, "Committed candidates cannot be discarded", { status: data.status });
|
|
134
|
+
if (status === "ready" && !data.patch) fail(ERROR_CODES.INVALID_STATE, "Cannot ready a candidate without a captured patch");
|
|
135
|
+
data.status = status;
|
|
136
|
+
data.updated_at = new Date().toISOString();
|
|
137
|
+
const { patch, ...metadata } = data;
|
|
138
|
+
this.write(metadata);
|
|
139
|
+
return metadata;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
commit(workspace, id, message = undefined, options = {}) {
|
|
143
|
+
workspace = this.assertStartup(workspace);
|
|
144
|
+
const data = this.read(id, workspace, true);
|
|
145
|
+
if (data.status !== "ready") fail(ERROR_CODES.INVALID_STATE, "Only ready candidates can be committed", { status: data.status });
|
|
146
|
+
if (message !== undefined && (typeof message !== "string" || !message.trim())) fail(ERROR_CODES.INVALID_ARGUMENT, "Commit message must be a non-empty string");
|
|
147
|
+
const commitMessage = message === undefined ? data.message : message.trim();
|
|
148
|
+
let metadata;
|
|
149
|
+
const published = commitPatch(this.context.storage.projectRoot, data.base_head, data.patch, commitMessage, {
|
|
150
|
+
beforeUpdateRef: (pending) => {
|
|
151
|
+
const committedAt = new Date().toISOString();
|
|
152
|
+
data.message = commitMessage;
|
|
153
|
+
data.status = "committed";
|
|
154
|
+
data.commit_hash = pending.commit;
|
|
155
|
+
data.committed_at = committedAt;
|
|
156
|
+
data.updated_at = committedAt;
|
|
157
|
+
const { patch, ...record } = data;
|
|
158
|
+
metadata = record;
|
|
159
|
+
this.write(metadata);
|
|
160
|
+
options.beforeUpdateRef?.(pending);
|
|
161
|
+
},
|
|
162
|
+
});
|
|
163
|
+
return { ...metadata, branch: published.branch, previous_head: published.previous_head, stale: published.stale };
|
|
164
|
+
}
|
|
165
|
+
}
|