@goodnesshq/opencode-notification 0.1.0 → 0.1.2
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 +32 -20
- package/bin/ocn.mjs +80 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,43 +4,55 @@ This repo implements a per-repo notification plugin for OpenCode. It uses a repo
|
|
|
4
4
|
|
|
5
5
|
## Quick Start
|
|
6
6
|
|
|
7
|
-
1)
|
|
7
|
+
1) One-command setup (recommended):
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
|
|
10
|
+
npx @goodnesshq/opencode-notification setup
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
This will:
|
|
14
|
+
- Copy the plugin to `~/.config/opencode/plugins/opencode-notifications.mjs`
|
|
15
|
+
- Update `~/.config/opencode/opencode.json`
|
|
16
|
+
- Install repo assets and launch the repo installer
|
|
17
|
+
|
|
18
|
+
2) Optional: repo-only install (advanced)
|
|
14
19
|
|
|
15
20
|
```bash
|
|
16
|
-
|
|
21
|
+
npx @goodnesshq/opencode-notification install
|
|
17
22
|
```
|
|
18
23
|
|
|
19
|
-
|
|
24
|
+
This only installs repo assets and prints next steps for manual setup.
|
|
20
25
|
|
|
21
|
-
|
|
26
|
+
### Update guidance
|
|
22
27
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"<path-from-ocn-plugin-path>"
|
|
28
|
-
]
|
|
29
|
-
}
|
|
30
|
-
```
|
|
28
|
+
- One-off: `npx @goodnesshq/opencode-notification@latest setup`
|
|
29
|
+
- Global: `npm update -g @goodnesshq/opencode-notification`
|
|
30
|
+
|
|
31
|
+
## Publish (maintainers)
|
|
31
32
|
|
|
32
|
-
|
|
33
|
+
1) Ensure you are authenticated with publish access for `@goodnesshq`.
|
|
33
34
|
|
|
34
35
|
```bash
|
|
35
|
-
|
|
36
|
+
npm whoami
|
|
36
37
|
```
|
|
37
38
|
|
|
38
|
-
|
|
39
|
+
If you see an auth error or 2FA error, create a publish token scoped to `@goodnesshq`, then set it:
|
|
39
40
|
|
|
40
|
-
|
|
41
|
+
```bash
|
|
42
|
+
npm token create \
|
|
43
|
+
--name "opencode-notification-publish" \
|
|
44
|
+
--scopes @goodnesshq \
|
|
45
|
+
--packages-and-scopes-permission read-write \
|
|
46
|
+
--bypass-2fa
|
|
47
|
+
npm set //registry.npmjs.org/:_authToken=YOUR_TOKEN
|
|
48
|
+
npm whoami
|
|
49
|
+
```
|
|
41
50
|
|
|
42
|
-
|
|
43
|
-
|
|
51
|
+
2) Publish:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
npm publish --access public
|
|
55
|
+
```
|
|
44
56
|
|
|
45
57
|
## Troubleshooting
|
|
46
58
|
|
package/bin/ocn.mjs
CHANGED
|
@@ -1,15 +1,30 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { copyFile, mkdir, stat } from "node:fs/promises";
|
|
3
|
-
import { basename, join } from "node:path";
|
|
2
|
+
import { copyFile, mkdir, readFile, stat, writeFile } from "node:fs/promises";
|
|
3
|
+
import { basename, join, dirname } from "node:path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
|
|
6
6
|
const PACKAGE_ROOT = fileURLToPath(new URL("..", import.meta.url));
|
|
7
7
|
const ASSET_NOTIFY_INIT = join(PACKAGE_ROOT, ".opencode", "notify-init.mjs");
|
|
8
8
|
const ASSET_SCHEMA = join(PACKAGE_ROOT, ".opencode", "oc-notify.schema.json");
|
|
9
9
|
const PLUGIN_PATH = join(PACKAGE_ROOT, "plugins", "opencode-notifications.mjs");
|
|
10
|
+
const GLOBAL_PLUGIN_DIR = join(
|
|
11
|
+
process.env.HOME || "",
|
|
12
|
+
".config",
|
|
13
|
+
"opencode",
|
|
14
|
+
"plugins"
|
|
15
|
+
);
|
|
16
|
+
const GLOBAL_PLUGIN_PATH = join(GLOBAL_PLUGIN_DIR, "opencode-notifications.mjs");
|
|
17
|
+
const GLOBAL_OPENCODE_CONFIG = join(
|
|
18
|
+
process.env.HOME || "",
|
|
19
|
+
".config",
|
|
20
|
+
"opencode",
|
|
21
|
+
"opencode.json"
|
|
22
|
+
);
|
|
10
23
|
|
|
11
24
|
function usage() {
|
|
12
|
-
console.log(
|
|
25
|
+
console.log(
|
|
26
|
+
"Usage: ocn <command>\n\nCommands:\n setup Configure global plugin and repo installer\n install Copy installer assets into the current repo\n plugin-path Print absolute path to the plugin entry file\n"
|
|
27
|
+
);
|
|
13
28
|
}
|
|
14
29
|
|
|
15
30
|
async function ensureDir(path) {
|
|
@@ -25,6 +40,20 @@ async function fileExists(path) {
|
|
|
25
40
|
}
|
|
26
41
|
}
|
|
27
42
|
|
|
43
|
+
async function readJson(path) {
|
|
44
|
+
try {
|
|
45
|
+
const content = await readFile(path, "utf8");
|
|
46
|
+
return JSON.parse(content);
|
|
47
|
+
} catch {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function writeJson(path, data) {
|
|
53
|
+
const content = JSON.stringify(data, null, 2) + "\n";
|
|
54
|
+
await writeFile(path, content, "utf8");
|
|
55
|
+
}
|
|
56
|
+
|
|
28
57
|
async function install() {
|
|
29
58
|
const cwd = process.cwd();
|
|
30
59
|
const repoName = basename(cwd);
|
|
@@ -42,11 +71,50 @@ async function install() {
|
|
|
42
71
|
console.log(`Installed OpenCode Notifications installer in ${repoName}.`);
|
|
43
72
|
console.log("Next steps:");
|
|
44
73
|
console.log(" 1) Run: node .opencode/notify-init.mjs");
|
|
45
|
-
console.log(" 2) Add the plugin path to ~/.config/opencode/opencode.json");
|
|
46
|
-
console.log("
|
|
74
|
+
console.log(" 2) Add the plugin path to ~/.config/opencode/opencode.json:");
|
|
75
|
+
console.log(" npx @goodnesshq/opencode-notification plugin-path");
|
|
47
76
|
console.log("\nUpdate guidance:");
|
|
48
|
-
console.log(" -
|
|
49
|
-
console.log(" -
|
|
77
|
+
console.log(" - npx @goodnesshq/opencode-notification@latest install");
|
|
78
|
+
console.log(" - npm update -g @goodnesshq/opencode-notification");
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function setup() {
|
|
82
|
+
const cwd = process.cwd();
|
|
83
|
+
const repoName = basename(cwd);
|
|
84
|
+
|
|
85
|
+
if (!(await fileExists(PLUGIN_PATH))) {
|
|
86
|
+
console.error("ocn: plugin entry file missing from package");
|
|
87
|
+
process.exit(1);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
await ensureDir(GLOBAL_PLUGIN_DIR);
|
|
91
|
+
await copyFile(PLUGIN_PATH, GLOBAL_PLUGIN_PATH);
|
|
92
|
+
|
|
93
|
+
let config = await readJson(GLOBAL_OPENCODE_CONFIG);
|
|
94
|
+
if (!config || typeof config !== "object" || Array.isArray(config)) {
|
|
95
|
+
config = {};
|
|
96
|
+
}
|
|
97
|
+
if (!Array.isArray(config.plugin)) config.plugin = [];
|
|
98
|
+
|
|
99
|
+
if (!config.plugin.includes(GLOBAL_PLUGIN_PATH)) {
|
|
100
|
+
config.plugin.push(GLOBAL_PLUGIN_PATH);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
await ensureDir(dirname(GLOBAL_OPENCODE_CONFIG));
|
|
104
|
+
await writeJson(GLOBAL_OPENCODE_CONFIG, config);
|
|
105
|
+
|
|
106
|
+
await install();
|
|
107
|
+
|
|
108
|
+
console.log("\nRunning repo installer...");
|
|
109
|
+
const notifyPath = join(cwd, ".opencode", "notify-init.mjs");
|
|
110
|
+
const { spawnSync } = await import("node:child_process");
|
|
111
|
+
const result = spawnSync("node", [notifyPath], { stdio: "inherit" });
|
|
112
|
+
if (result.status !== 0) {
|
|
113
|
+
console.error(`ocn: repo installer exited with code ${result.status}`);
|
|
114
|
+
process.exit(result.status || 1);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
console.log(`\nSetup complete for ${repoName}.`);
|
|
50
118
|
}
|
|
51
119
|
|
|
52
120
|
async function pluginPath() {
|
|
@@ -69,6 +137,11 @@ async function main() {
|
|
|
69
137
|
return;
|
|
70
138
|
}
|
|
71
139
|
|
|
140
|
+
if (command === "setup") {
|
|
141
|
+
await setup();
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
|
|
72
145
|
if (command === "plugin-path") {
|
|
73
146
|
await pluginPath();
|
|
74
147
|
return;
|