opencode-work-context 0.4.11 → 0.4.13
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 +54 -0
- package/bin/opencode-work-context.js +56 -1
- package/package.json +1 -1
- package/plugin/stages-tui.js +8 -1
package/README.md
CHANGED
|
@@ -138,6 +138,57 @@ stage. Use explicit workspace and stage positions for unpadded workspace IDs.
|
|
|
138
138
|
|
|
139
139
|
## Install
|
|
140
140
|
|
|
141
|
+
### Managed Package Activation
|
|
142
|
+
|
|
143
|
+
For one managed package installation shared by OpenCode while keeping activation
|
|
144
|
+
explicit per project, run this in each project that should use work-context:
|
|
145
|
+
|
|
146
|
+
```sh
|
|
147
|
+
npx opencode-work-context activate
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
`activate` writes `.opencode/opencode.json` with the supported package plugin
|
|
151
|
+
entry `opencode-work-context` and installs the `/wc` command contract. OpenCode
|
|
152
|
+
resolves, caches, and updates configured package plugins through its supported
|
|
153
|
+
plugin manager; the project does not import an npm-global path, create a local
|
|
154
|
+
`node_modules`, or create `.work-context` data merely by being activated. The
|
|
155
|
+
package's server and optional TUI parts are loaded together by OpenCode, so this
|
|
156
|
+
also works on server-only hosts.
|
|
157
|
+
|
|
158
|
+
Activation is opt-in. Projects without this entry stay inactive. If a machine
|
|
159
|
+
administrator or user has configured the package globally, a project can add
|
|
160
|
+
the explicit opt-out entry with:
|
|
161
|
+
|
|
162
|
+
```sh
|
|
163
|
+
npx opencode-work-context deactivate
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
This appends `"-work-context"` to the project plugin list, which OpenCode
|
|
167
|
+
processes after global configuration. `activate` and `deactivate` merge a plain
|
|
168
|
+
JSON `.opencode/opencode.json` plugin array without replacing other settings.
|
|
169
|
+
For an existing JSONC configuration, add the equivalent entry manually:
|
|
170
|
+
|
|
171
|
+
```jsonc
|
|
172
|
+
{
|
|
173
|
+
"plugins": ["opencode-work-context"] // or "-work-context" to opt out
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Restart OpenCode after changing plugin configuration. OpenCode checks unpinned
|
|
178
|
+
configured packages through its managed plugin flow; use the OpenCode plugin
|
|
179
|
+
management command available in your installed OpenCode version when you need
|
|
180
|
+
to refresh it immediately. Pinned plugin entries are intentionally not updated
|
|
181
|
+
automatically.
|
|
182
|
+
|
|
183
|
+
Do not activate the managed package in a project already configured through
|
|
184
|
+
the local installer below. The command refuses that combination so server tools
|
|
185
|
+
and TUI registrations cannot be duplicated. To migrate a local project, remove
|
|
186
|
+
the generated local server loader, TUI loader, and its `tui.json` entry, then
|
|
187
|
+
run `activate`; its existing `.work-context` data remains intact. To return to
|
|
188
|
+
the pinned local workflow, remove the managed package entry and run `init`.
|
|
189
|
+
|
|
190
|
+
### Pinned Local Installation
|
|
191
|
+
|
|
141
192
|
Run from the root of a standalone OpenCode project:
|
|
142
193
|
|
|
143
194
|
```sh
|
|
@@ -157,6 +208,9 @@ and generates ESM server and TUI loaders. OpenCode loads local plugins as JavaSc
|
|
|
157
208
|
modules; keeping the generated `.js` integration path ESM avoids a CommonJS
|
|
158
209
|
interop failure before custom tools are registered.
|
|
159
210
|
It does not create a workspace. Start one explicitly with `/wc create "Title"`.
|
|
211
|
+
This local setup takes precedence by remaining the only configured integration
|
|
212
|
+
for its project, and it preserves the exact version in the project's package
|
|
213
|
+
manifest.
|
|
160
214
|
|
|
161
215
|
Use `--force` to replace a conflicting package-owned generated file or package
|
|
162
216
|
version. Without it, existing files are never silently overwritten. Re-running
|
|
@@ -79,12 +79,65 @@ function parseArgs(args) {
|
|
|
79
79
|
if (unknown.length) return fail(`unknown option: ${unknown[0]}`);
|
|
80
80
|
return { syncCommand: true, force: args.includes("--force") };
|
|
81
81
|
}
|
|
82
|
-
if (args[0]
|
|
82
|
+
if (args[0] === "activate" || args[0] === "deactivate") {
|
|
83
|
+
const unknown = args.slice(1).filter((arg) => arg !== "--force");
|
|
84
|
+
if (unknown.length) return fail(`unknown option: ${unknown[0]}`);
|
|
85
|
+
return { activation: args[0] === "activate", force: args.includes("--force") };
|
|
86
|
+
}
|
|
87
|
+
if (args[0] !== "init") return fail("usage: opencode-work-context init [--force] | activate [--force] | deactivate [--force] | sync-command");
|
|
83
88
|
const unknown = args.slice(1).filter((arg) => arg !== "--force");
|
|
84
89
|
if (unknown.length) return fail(`unknown option: ${unknown[0]}`);
|
|
85
90
|
return { force: args.includes("--force") };
|
|
86
91
|
}
|
|
87
92
|
|
|
93
|
+
function activate(enabled, force) {
|
|
94
|
+
const localLoader = path.join(projectRoot, ".opencode", "plugins", "work-context.js");
|
|
95
|
+
if (exists(localLoader)) {
|
|
96
|
+
fail("project-local integration is already active; keep using it or remove its generated loaders before activating the managed package");
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const configRelative = path.join(".opencode", "opencode.json");
|
|
100
|
+
const configFile = path.join(projectRoot, configRelative);
|
|
101
|
+
const jsoncFile = path.join(projectRoot, ".opencode", "opencode.jsonc");
|
|
102
|
+
if (exists(jsoncFile)) {
|
|
103
|
+
fail("cannot update .opencode/opencode.jsonc; add the plugin entry manually or use .opencode/opencode.json");
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
let config = { $schema: "https://opencode.ai/config.json" };
|
|
107
|
+
if (exists(configFile)) {
|
|
108
|
+
if (hasSymlinkParent(configFile) || !fs.lstatSync(configFile).isFile() || fs.lstatSync(configFile).isSymbolicLink()) {
|
|
109
|
+
fail(`refusing to overwrite non-regular file: ${configRelative}`);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
try { config = JSON.parse(fs.readFileSync(configFile, "utf8")); }
|
|
113
|
+
catch { fail(`cannot update invalid JSON: ${configRelative}`); return; }
|
|
114
|
+
if (!config || typeof config !== "object" || Array.isArray(config) || (config.plugins !== undefined && !Array.isArray(config.plugins))) {
|
|
115
|
+
fail(`cannot update unsupported configuration: ${configRelative}`);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const entry = enabled ? packageManifest.name : "-work-context";
|
|
120
|
+
config.plugins = [...(config.plugins || []).filter((item) => item !== entry), entry];
|
|
121
|
+
const files = new Map([
|
|
122
|
+
[configRelative, JSON.stringify(config, null, 2) + "\n"],
|
|
123
|
+
[path.join(".opencode", "commands", "wc.md"), command],
|
|
124
|
+
]);
|
|
125
|
+
const conflicts = [...files].flatMap(([relative, content]) => {
|
|
126
|
+
const file = path.join(projectRoot, relative);
|
|
127
|
+
if (hasSymlinkParent(file) || (exists(file) && (!fs.lstatSync(file).isFile() || fs.lstatSync(file).isSymbolicLink()))) return [relative];
|
|
128
|
+
return relative !== configRelative && !force && exists(file) && fs.readFileSync(file, "utf8") !== content ? [relative] : [];
|
|
129
|
+
});
|
|
130
|
+
if (conflicts.length) {
|
|
131
|
+
fail(`refusing to overwrite existing files: ${conflicts.join(", ")}; rerun with --force`);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
for (const [relative, content] of files) {
|
|
135
|
+
const file = path.join(projectRoot, relative);
|
|
136
|
+
if (!exists(file) || fs.readFileSync(file, "utf8") !== content) writeAtomic(file, content);
|
|
137
|
+
}
|
|
138
|
+
console.log(`${enabled ? "Activated" : "Deactivated"} opencode-work-context for this project.`);
|
|
139
|
+
}
|
|
140
|
+
|
|
88
141
|
function syncCommandProjection(force) {
|
|
89
142
|
const relative = ".opencode/commands/wc.md";
|
|
90
143
|
const file = path.join(projectRoot, relative);
|
|
@@ -301,6 +354,8 @@ if (options?.syncCommand) {
|
|
|
301
354
|
catch (error) { fail(`command sync failed: ${error.message}`); }
|
|
302
355
|
finally { releaseInitLock(initLock); }
|
|
303
356
|
}
|
|
357
|
+
} else if (options?.activation !== undefined) {
|
|
358
|
+
activate(options.activation, options.force);
|
|
304
359
|
} else if (options) {
|
|
305
360
|
const initLock = acquireInitLock();
|
|
306
361
|
if (initLock.failed) process.exitCode = 1;
|
package/package.json
CHANGED
package/plugin/stages-tui.js
CHANGED
|
@@ -30,6 +30,12 @@ const statusMarker = (status) => ({
|
|
|
30
30
|
export { readStagesSnapshot, renderStagesPanel };
|
|
31
31
|
|
|
32
32
|
const defaultRuntime = { jsx };
|
|
33
|
+
const renderAttentionText = (value, runtime) => {
|
|
34
|
+
const parts = value.split(/(\[ATTN[^\]]*\])/g);
|
|
35
|
+
return parts.length === 1 ? value : parts.filter(Boolean).map((part) => part.startsWith("[ATTN")
|
|
36
|
+
? runtime.jsx("b", { children: part })
|
|
37
|
+
: part);
|
|
38
|
+
};
|
|
33
39
|
|
|
34
40
|
const renderStagesContent = (result, theme, runtime = defaultRuntime, attention, showDependencies = true, onStageSelect) => !result?.ok || !result.data?.workspace
|
|
35
41
|
? [
|
|
@@ -50,6 +56,7 @@ const renderStagesContent = (result, theme, runtime = defaultRuntime, attention,
|
|
|
50
56
|
}),
|
|
51
57
|
...result.data.stages.map((stage) => {
|
|
52
58
|
const unread = attention?.attentionForStage?.(result.data.workspace.id, stage.id);
|
|
59
|
+
const stageText = `${stage.id}. ${stage.title}${showDependencies && stage.depends_on?.length ? `\nDeps: ${stage.depends_on.join(", ")}` : ""}${unread ? ` [ATTN: ${attentionReasonText(unread.reason)}${unread.count > 1 ? ` x${unread.count}` : ""}]` : ""}`;
|
|
53
60
|
return runtime.jsx("box", {
|
|
54
61
|
flexDirection: "row",
|
|
55
62
|
onMouseDown: (event) => {
|
|
@@ -58,7 +65,7 @@ const renderStagesContent = (result, theme, runtime = defaultRuntime, attention,
|
|
|
58
65
|
},
|
|
59
66
|
children: [
|
|
60
67
|
runtime.jsx("text", { flexShrink: 0, marginRight: 1, fg: stage.current || stage.id === result.data.currentStage ? theme?.current?.warning : theme?.current?.textMuted, children: statusMarker(stage.status) }),
|
|
61
|
-
runtime.jsx("text", { flexGrow: 1, flexShrink: 1, wrapMode: "word", fg: stage.current || stage.id === result.data.currentStage ? theme?.current?.warning : theme?.current?.textMuted, children:
|
|
68
|
+
runtime.jsx("text", { flexGrow: 1, flexShrink: 1, wrapMode: "word", fg: stage.current || stage.id === result.data.currentStage ? theme?.current?.warning : theme?.current?.textMuted, children: renderAttentionText(stageText, runtime) }),
|
|
62
69
|
],
|
|
63
70
|
});
|
|
64
71
|
}),
|