opencode-workflow-guard 1.7.0 → 1.7.1
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 +1 -1
- package/bin/opencode-workflow-guard.mjs +15 -5
- package/package.json +1 -1
- package/src/workflow-guard-ui.ts +1 -1
package/README.md
CHANGED
|
@@ -31,7 +31,7 @@ For server-only setup, add the package to your project's `opencode.json` or glob
|
|
|
31
31
|
|
|
32
32
|
*Requires OpenCode >= 1.18.* Restart OpenCode after setup. See [docs/installation.md](docs/installation.md) for full setup options.
|
|
33
33
|
|
|
34
|
-
For the optional TUI badge, configure `"opencode-workflow-guard
|
|
34
|
+
For the optional TUI badge, configure `"opencode-workflow-guard"` in `tui.json`. OpenCode resolves the package's exported `./tui` entrypoint automatically for TUI plugins. Do not place the TUI module under the server `plugins/` directory.
|
|
35
35
|
|
|
36
36
|
### 2. Verification
|
|
37
37
|
|
|
@@ -6,7 +6,8 @@ import { join } from "node:path";
|
|
|
6
6
|
import { parse, modify, applyEdits } from "jsonc-parser";
|
|
7
7
|
|
|
8
8
|
const SERVER_SPEC = "opencode-workflow-guard";
|
|
9
|
-
const TUI_SPEC = "opencode-workflow-guard
|
|
9
|
+
const TUI_SPEC = "opencode-workflow-guard";
|
|
10
|
+
const LEGACY_TUI_SPEC = "opencode-workflow-guard/tui";
|
|
10
11
|
|
|
11
12
|
function configHome() {
|
|
12
13
|
return process.env.XDG_CONFIG_HOME || join(homedir(), ".config");
|
|
@@ -18,7 +19,7 @@ function existingConfig(base, name) {
|
|
|
18
19
|
return existsSync(json) ? json : existsSync(jsonc) ? jsonc : json;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
function preparePluginUpdate(path, schema, spec) {
|
|
22
|
+
function preparePluginUpdate(path, schema, spec, legacySpec) {
|
|
22
23
|
const source = existsSync(path) ? readFileSync(path, "utf8") : `{
|
|
23
24
|
"$schema": "${schema}"
|
|
24
25
|
}\n`;
|
|
@@ -31,8 +32,17 @@ function preparePluginUpdate(path, schema, spec) {
|
|
|
31
32
|
throw new Error(`Cannot update ${path}: "plugin" must be an array`);
|
|
32
33
|
}
|
|
33
34
|
const plugins = config.plugin ?? [];
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
const matches = (entry, target) => entry === target || (Array.isArray(entry) && entry[0] === target);
|
|
36
|
+
if (!legacySpec) {
|
|
37
|
+
if (plugins.some((entry) => matches(entry, spec))) return undefined;
|
|
38
|
+
return applyEdits(source, modify(source, ["plugin", plugins.length], spec, {
|
|
39
|
+
formattingOptions: { insertSpaces: true, tabSize: 2 },
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
const updatedPlugins = plugins.filter((entry) => !matches(entry, legacySpec));
|
|
43
|
+
if (!updatedPlugins.some((entry) => matches(entry, spec))) updatedPlugins.push(spec);
|
|
44
|
+
if (updatedPlugins.length === plugins.length && updatedPlugins.every((entry, index) => entry === plugins[index])) return undefined;
|
|
45
|
+
return applyEdits(source, modify(source, ["plugin"], updatedPlugins, {
|
|
36
46
|
formattingOptions: { insertSpaces: true, tabSize: 2 },
|
|
37
47
|
}));
|
|
38
48
|
}
|
|
@@ -46,7 +56,7 @@ if (process.argv[2] !== "setup" || process.argv.length > 3) {
|
|
|
46
56
|
const serverPath = existingConfig(base, "opencode");
|
|
47
57
|
const tuiPath = existingConfig(base, "tui");
|
|
48
58
|
const serverUpdate = preparePluginUpdate(serverPath, "https://opencode.ai/config.json", SERVER_SPEC);
|
|
49
|
-
const tuiUpdate = preparePluginUpdate(tuiPath, "https://opencode.ai/tui.json", TUI_SPEC);
|
|
59
|
+
const tuiUpdate = preparePluginUpdate(tuiPath, "https://opencode.ai/tui.json", TUI_SPEC, LEGACY_TUI_SPEC);
|
|
50
60
|
mkdirSync(base, { recursive: true });
|
|
51
61
|
if (serverUpdate !== undefined) writeFileSync(serverPath, serverUpdate);
|
|
52
62
|
if (tuiUpdate !== undefined) writeFileSync(tuiPath, tuiUpdate);
|
package/package.json
CHANGED
package/src/workflow-guard-ui.ts
CHANGED
|
@@ -29,7 +29,7 @@ function text(props: Record<string, unknown>, children: Child[]) {
|
|
|
29
29
|
return element("text", props, children);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
const BADGE_ACTIVE = "
|
|
32
|
+
const BADGE_ACTIVE = "Workflow Guard 🛡️";
|
|
33
33
|
let lastBlockedReason: string | undefined;
|
|
34
34
|
const sessionBlockedReasons = new Map<string, string>();
|
|
35
35
|
const badgeNodes = new Map<string, unknown>();
|