my-opencode 1.0.0 → 1.1.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 +18 -1
- package/bin/cli.js +51 -12
- package/package.json +5 -1
- package/scripts/postinstall.js +182 -0
package/README.md
CHANGED
|
@@ -29,8 +29,25 @@ npx my-opencode help # 顯示說明
|
|
|
29
29
|
|
|
30
30
|
### 發布(維護者專用)
|
|
31
31
|
|
|
32
|
+
#### Token 設定
|
|
33
|
+
|
|
34
|
+
發布前需要建立一個 **Access Token**(繞過 2FA):
|
|
35
|
+
|
|
36
|
+
1. 到 https://www.npmjs.com/settings/~/tokens
|
|
37
|
+
2. Generate New Token → Granular Access Token
|
|
38
|
+
3. 勾選 bypass two-factor authentication
|
|
39
|
+
4. 設定 Read and Write 權限
|
|
40
|
+
5. 將產生的 token 寫入專案 `.npmrc`:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
echo "//registry.npmjs.org/:_authToken=npm_xxxxxxxxxxxx" > .npmrc
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
> ⚠️ `.npmrc` 已加入 `.gitignore`,不會被 commit。
|
|
47
|
+
|
|
48
|
+
#### 發布指令
|
|
49
|
+
|
|
32
50
|
```bash
|
|
33
|
-
npm login
|
|
34
51
|
npm publish
|
|
35
52
|
```
|
|
36
53
|
|
package/bin/cli.js
CHANGED
|
@@ -3,10 +3,18 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* my-opencode CLI
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* my-opencode
|
|
9
|
-
*
|
|
6
|
+
* Two install methods:
|
|
7
|
+
*
|
|
8
|
+
* 1. npm install my-opencode
|
|
9
|
+
* → Files in node_modules/ (gitignored) + postinstall copies to .opencode/
|
|
10
|
+
*
|
|
11
|
+
* 2. npx my-opencode init
|
|
12
|
+
* → Files copied directly to .opencode/, no dependency in package.json
|
|
13
|
+
*
|
|
14
|
+
* Commands:
|
|
15
|
+
* init [target-dir] Install skills/agents into .opencode/
|
|
16
|
+
* list List available skills and agents
|
|
17
|
+
* help Show this help
|
|
10
18
|
*/
|
|
11
19
|
|
|
12
20
|
import { fileURLToPath } from "node:url";
|
|
@@ -96,8 +104,17 @@ function cmdHelp() {
|
|
|
96
104
|
console.log(`
|
|
97
105
|
\x1b[1mmy-opencode\x1b[0m — 高品質 opencode 開發流程 skill 與 agents 集合
|
|
98
106
|
|
|
99
|
-
\x1b[
|
|
100
|
-
|
|
107
|
+
\x1b[1m安裝方式 (擇一)\x1b[0m
|
|
108
|
+
|
|
109
|
+
\x1b[36m方法 A: npm install\x1b[0m (自動複製到 .opencode/)
|
|
110
|
+
npm install my-opencode
|
|
111
|
+
✓ postinstall 自動將 agents/ skills/ 複製到 .opencode/
|
|
112
|
+
✓ 原始檔案留在 node_modules/ (已 gitignore)
|
|
113
|
+
|
|
114
|
+
\x1b[36m方法 B: npx\x1b[0m (不留 package.json dependency)
|
|
115
|
+
npx my-opencode init
|
|
116
|
+
✓ 直接安裝到 .opencode/
|
|
117
|
+
✓ 不寫入 package.json
|
|
101
118
|
|
|
102
119
|
\x1b[1mCOMMANDS\x1b[0m
|
|
103
120
|
init [target-dir] 安裝 skills/agents 到 .opencode/ 下
|
|
@@ -106,10 +123,10 @@ function cmdHelp() {
|
|
|
106
123
|
help 顯示此說明
|
|
107
124
|
|
|
108
125
|
\x1b[1mEXAMPLES\x1b[0m
|
|
109
|
-
|
|
110
|
-
npx my-opencode init
|
|
111
|
-
npx my-opencode
|
|
112
|
-
npx my-opencode
|
|
126
|
+
npm install my-opencode # 方法 A (自動)
|
|
127
|
+
npx my-opencode init # 方法 B (手動)
|
|
128
|
+
npx my-opencode init ./my-project # 指定專案目錄
|
|
129
|
+
npx my-opencode list # 列出內容
|
|
113
130
|
`);
|
|
114
131
|
}
|
|
115
132
|
|
|
@@ -249,7 +266,7 @@ function copyDirSync(src, dst) {
|
|
|
249
266
|
|
|
250
267
|
function main() {
|
|
251
268
|
const args = process.argv.slice(2);
|
|
252
|
-
const cmd = args[0] || "
|
|
269
|
+
const cmd = args[0] || "";
|
|
253
270
|
|
|
254
271
|
switch (cmd) {
|
|
255
272
|
case "init":
|
|
@@ -263,9 +280,31 @@ function main() {
|
|
|
263
280
|
case "help":
|
|
264
281
|
case "--help":
|
|
265
282
|
case "-h":
|
|
266
|
-
default:
|
|
267
283
|
cmdHelp();
|
|
268
284
|
break;
|
|
285
|
+
default:
|
|
286
|
+
// No args — show a friendly welcome and prompt to init
|
|
287
|
+
console.log(`
|
|
288
|
+
\x1b[1mmy-opencode\x1b[0m — 高品質 opencode 開發流程 skill 與 agents 集合
|
|
289
|
+
|
|
290
|
+
在專案中執行以下指令來安裝到 \x1b[33m.opencode/\x1b[0m:
|
|
291
|
+
|
|
292
|
+
\x1b[36mnpx my-opencode init\x1b[0m
|
|
293
|
+
|
|
294
|
+
安裝後,將以下內容加入你的 \x1b[33mopencode.json\x1b[0m:
|
|
295
|
+
|
|
296
|
+
\x1b[2m"instructions": [
|
|
297
|
+
".opencode/skills/adr/SKILL.md",
|
|
298
|
+
".opencode/skills/dev-flow/SKILL.md",
|
|
299
|
+
".opencode/skills/pr-review/SKILL.md",
|
|
300
|
+
".opencode/skills/test-gen/SKILL.md",
|
|
301
|
+
".opencode/skills/docs-gen/SKILL.md",
|
|
302
|
+
".opencode/skills/orchestrate/SKILL.md"
|
|
303
|
+
]\x1b[0m
|
|
304
|
+
|
|
305
|
+
更多資訊請執行:\x1b[36mnpx my-opencode help\x1b[0m
|
|
306
|
+
`);
|
|
307
|
+
break;
|
|
269
308
|
}
|
|
270
309
|
}
|
|
271
310
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "my-opencode",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "高品質 opencode 開發流程 skill 與 agents 集合 — Contract-First 開發流程、ADR、PR Review、測試生成、文件生成",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"opencode",
|
|
@@ -25,11 +25,15 @@
|
|
|
25
25
|
"type": "git",
|
|
26
26
|
"url": "git+https://github.com/cfh00902455/my-opencode.git"
|
|
27
27
|
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"postinstall": "node scripts/postinstall.js"
|
|
30
|
+
},
|
|
28
31
|
"bin": {
|
|
29
32
|
"my-opencode": "./bin/cli.js"
|
|
30
33
|
},
|
|
31
34
|
"files": [
|
|
32
35
|
"bin/",
|
|
36
|
+
"scripts/",
|
|
33
37
|
"skills/",
|
|
34
38
|
"agents/",
|
|
35
39
|
"opencode.json"
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* postinstall.js — npm postinstall hook
|
|
5
|
+
*
|
|
6
|
+
* After `npm install my-opencode` in another project, this script
|
|
7
|
+
* automatically copies agents/, skills/, and opencode.json to the
|
|
8
|
+
* target project's .opencode/ directory.
|
|
9
|
+
*
|
|
10
|
+
* The package stays in node_modules/ (gitignored, no residue).
|
|
11
|
+
* The .opencode/ files are what opencode reads.
|
|
12
|
+
*
|
|
13
|
+
* To skip: npm install my-opencode --ignore-scripts
|
|
14
|
+
* To run manually: npx my-opencode init
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { fileURLToPath } from "node:url";
|
|
18
|
+
import path from "node:path";
|
|
19
|
+
import fs from "node:fs";
|
|
20
|
+
|
|
21
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
22
|
+
const __dirname = path.dirname(__filename);
|
|
23
|
+
|
|
24
|
+
const PKG_DIR = path.resolve(__dirname, "..");
|
|
25
|
+
const SKILLS_SRC = path.join(PKG_DIR, "skills");
|
|
26
|
+
const AGENTS_SRC = path.join(PKG_DIR, "agents");
|
|
27
|
+
const CONFIG_SRC = path.join(PKG_DIR, "opencode.json");
|
|
28
|
+
|
|
29
|
+
// ─── Detect project root ────────────────────────────────────────────────
|
|
30
|
+
//
|
|
31
|
+
// During npm postinstall, `process.cwd()` is typically the package root
|
|
32
|
+
// (node_modules/my-opencode/), but behavior varies by npm version.
|
|
33
|
+
// We try multiple strategies to find the parent project root.
|
|
34
|
+
|
|
35
|
+
function hasPackageJson(dir) {
|
|
36
|
+
try {
|
|
37
|
+
const pkgPath = path.join(dir, "package.json");
|
|
38
|
+
if (!fs.existsSync(pkgPath)) return false;
|
|
39
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
|
40
|
+
return pkg.name !== "my-opencode";
|
|
41
|
+
} catch {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function findProjectRoot() {
|
|
47
|
+
// Strategy 1: process.cwd() is the project root (npm v6 behavior)
|
|
48
|
+
let candidate = path.resolve(process.cwd());
|
|
49
|
+
if (hasPackageJson(candidate)) return candidate;
|
|
50
|
+
|
|
51
|
+
// Strategy 2: process.cwd() is node_modules/my-opencode/ (npm v7+)
|
|
52
|
+
candidate = path.resolve(process.cwd(), "..", "..");
|
|
53
|
+
if (hasPackageJson(candidate)) return candidate;
|
|
54
|
+
|
|
55
|
+
// Strategy 3: __dirname is scripts/, go up 3 levels
|
|
56
|
+
candidate = path.resolve(__dirname, "..", "..", "..");
|
|
57
|
+
if (hasPackageJson(candidate)) return candidate;
|
|
58
|
+
|
|
59
|
+
// Strategy 4: Walk up from __dirname until we find a project's package.json
|
|
60
|
+
candidate = path.resolve(__dirname);
|
|
61
|
+
while (candidate !== path.parse(candidate).root) {
|
|
62
|
+
const parent = path.resolve(candidate, "..");
|
|
63
|
+
if (hasPackageJson(parent)) return parent;
|
|
64
|
+
candidate = parent;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// ─── File utilities ─────────────────────────────────────────────────────
|
|
71
|
+
|
|
72
|
+
function copyDirSync(src, dst) {
|
|
73
|
+
let count = 0;
|
|
74
|
+
fs.mkdirSync(dst, { recursive: true });
|
|
75
|
+
const entries = fs.readdirSync(src, { withFileTypes: true });
|
|
76
|
+
for (const entry of entries) {
|
|
77
|
+
const srcPath = path.join(src, entry.name);
|
|
78
|
+
const dstPath = path.join(dst, entry.name);
|
|
79
|
+
if (entry.isDirectory()) {
|
|
80
|
+
count += copyDirSync(srcPath, dstPath);
|
|
81
|
+
} else if (entry.isFile()) {
|
|
82
|
+
if (!fs.existsSync(dstPath)) {
|
|
83
|
+
fs.copyFileSync(srcPath, dstPath);
|
|
84
|
+
count++;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return count;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function copyFileIfNotExists(src, dst) {
|
|
92
|
+
if (!fs.existsSync(dst)) {
|
|
93
|
+
fs.mkdirSync(path.dirname(dst), { recursive: true });
|
|
94
|
+
fs.copyFileSync(src, dst);
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// ─── Main ───────────────────────────────────────────────────────────────
|
|
101
|
+
|
|
102
|
+
function main() {
|
|
103
|
+
const INDENT = " ";
|
|
104
|
+
const CYAN = "\x1b[36m";
|
|
105
|
+
const GREEN = "\x1b[32m";
|
|
106
|
+
const YELLOW = "\x1b[33m";
|
|
107
|
+
const RESET = "\x1b[0m";
|
|
108
|
+
|
|
109
|
+
function header(text) {
|
|
110
|
+
console.log(`\n${CYAN}━━━ ${text} ━━━${RESET}\n`);
|
|
111
|
+
}
|
|
112
|
+
function success(text) {
|
|
113
|
+
console.log(`${GREEN}✓${RESET} ${text}`);
|
|
114
|
+
}
|
|
115
|
+
function warn(text) {
|
|
116
|
+
console.log(`${YELLOW}⚠${RESET} ${text}`);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const projectRoot = findProjectRoot();
|
|
120
|
+
if (!projectRoot) {
|
|
121
|
+
warn(
|
|
122
|
+
"Could not detect project root for my-opencode postinstall.\n" +
|
|
123
|
+
`${INDENT}Run "npx my-opencode init" to set up manually.`,
|
|
124
|
+
);
|
|
125
|
+
process.exit(0);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const targetDir = path.join(projectRoot, ".opencode");
|
|
129
|
+
const targetSkills = path.join(targetDir, "skills");
|
|
130
|
+
const targetAgents = path.join(targetDir, "agents");
|
|
131
|
+
const targetConfig = path.join(targetDir, "opencode.json");
|
|
132
|
+
|
|
133
|
+
// ── Create .opencode/ ──────────────────────────────────────────────────
|
|
134
|
+
if (!fs.existsSync(targetDir)) {
|
|
135
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// ── Copy skills ────────────────────────────────────────────────────────
|
|
139
|
+
let skillCount = 0;
|
|
140
|
+
if (fs.existsSync(SKILLS_SRC)) {
|
|
141
|
+
const skills = fs
|
|
142
|
+
.readdirSync(SKILLS_SRC, { withFileTypes: true })
|
|
143
|
+
.filter((d) => d.isDirectory())
|
|
144
|
+
.map((d) => d.name);
|
|
145
|
+
|
|
146
|
+
for (const s of skills) {
|
|
147
|
+
const dst = path.join(targetSkills, s);
|
|
148
|
+
if (!fs.existsSync(dst)) {
|
|
149
|
+
copyDirSync(path.join(SKILLS_SRC, s), dst);
|
|
150
|
+
skillCount++;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// ── Copy agents ────────────────────────────────────────────────────────
|
|
156
|
+
let agentCount = 0;
|
|
157
|
+
if (fs.existsSync(AGENTS_SRC)) {
|
|
158
|
+
const agents = fs
|
|
159
|
+
.readdirSync(AGENTS_SRC, { withFileTypes: true })
|
|
160
|
+
.filter((d) => d.isFile() && d.name.endsWith(".md"))
|
|
161
|
+
.map((d) => d.name);
|
|
162
|
+
|
|
163
|
+
for (const a of agents) {
|
|
164
|
+
const dst = path.join(targetAgents, a);
|
|
165
|
+
if (copyFileIfNotExists(path.join(AGENTS_SRC, a), dst)) {
|
|
166
|
+
agentCount++;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// ── Copy opencode.json ────────────────────────────────────────────────
|
|
172
|
+
copyFileIfNotExists(CONFIG_SRC, targetConfig);
|
|
173
|
+
|
|
174
|
+
// Suppress output if nothing changed (quiet idempotency)
|
|
175
|
+
if (skillCount === 0 && agentCount === 0) return;
|
|
176
|
+
|
|
177
|
+
header("my-opencode: installed to .opencode/");
|
|
178
|
+
if (skillCount > 0) success(`Skills: ${skillCount}`);
|
|
179
|
+
if (agentCount > 0) success(`Agents: ${agentCount}`);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
main();
|