my-opencode 1.3.4 → 2.0.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.
Files changed (46) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +299 -270
  3. package/agents/architect.md +30 -30
  4. package/agents/backend-dev.md +29 -0
  5. package/agents/business-analyst.md +30 -0
  6. package/agents/code-reviewer.md +29 -29
  7. package/agents/design-evidence.md +29 -0
  8. package/agents/frontend-dev.md +29 -0
  9. package/agents/system-designer.md +30 -0
  10. package/agents/team-lead.md +65 -60
  11. package/agents/tech-writer.md +30 -30
  12. package/agents/test-engineer.md +30 -30
  13. package/agents/verifier.md +38 -33
  14. package/bin/cli.js +366 -364
  15. package/bin/moc +198 -198
  16. package/opencode.json +218 -170
  17. package/package.json +53 -51
  18. package/plugins/README.md +67 -67
  19. package/plugins/provider-profile.mjs +203 -194
  20. package/scripts/postinstall.js +202 -202
  21. package/scripts/validate-role-flow.mjs +90 -0
  22. package/skills/adr/SKILL.md +91 -91
  23. package/skills/adr/references/templates.md +100 -100
  24. package/skills/adr/scripts/README.md +5 -5
  25. package/skills/design-evidence/SKILL.md +56 -0
  26. package/skills/dev-flow/SKILL.md +126 -188
  27. package/skills/dev-flow/references/code-phase.md +35 -72
  28. package/skills/dev-flow/references/contract-phase.md +66 -81
  29. package/skills/dev-flow/references/verify-phase.md +70 -129
  30. package/skills/dev-flow/scripts/README.md +3 -3
  31. package/skills/docs-gen/SKILL.md +162 -162
  32. package/skills/docs-gen/references/doc-styles.md +216 -216
  33. package/skills/docs-gen/scripts/README.md +5 -5
  34. package/skills/orchestrate/SKILL.md +63 -112
  35. package/skills/orchestrate/references/orchestration-patterns.md +49 -56
  36. package/skills/pr-review/SKILL.md +110 -110
  37. package/skills/pr-review/references/review-dimensions.md +117 -117
  38. package/skills/pr-review/references/security-checklist.md +122 -122
  39. package/skills/pr-review/scripts/README.md +5 -5
  40. package/skills/test-gen/SKILL.md +143 -143
  41. package/skills/test-gen/references/framework-detection.md +105 -105
  42. package/skills/test-gen/references/test-patterns.md +260 -260
  43. package/skills/test-gen/scripts/README.md +5 -5
  44. package/agents/executor.md +0 -30
  45. package/agents/fullstack-dev.md +0 -57
  46. package/agents/spec-writer.md +0 -37
package/bin/cli.js CHANGED
@@ -1,365 +1,367 @@
1
1
  #!/usr/bin/env node
2
-
3
- /**
4
- * my-opencode CLI
5
- *
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/plugins into .opencode/
16
- * list List available skills and agents
17
- * help Show this help
18
- */
19
-
20
- import { fileURLToPath } from "node:url";
21
- import path from "node:path";
22
- import fs from "node:fs";
23
-
24
- const __filename = fileURLToPath(import.meta.url);
25
- const PKG_ROOT = path.resolve(path.dirname(__filename), "..");
26
-
27
- const SKILLS_DIR = path.join(PKG_ROOT, "skills");
28
- const AGENTS_DIR = path.join(PKG_ROOT, "agents");
29
- const PLUGINS_DIR = path.join(PKG_ROOT, "plugins");
30
- const OPENCODE_CONFIG = path.join(PKG_ROOT, "opencode.json");
31
-
32
- const INDENT = " ";
33
-
34
- // ─── Helpers ────────────────────────────────────────────────────────────────
35
-
36
- function header(text) {
37
- console.log(`\n\x1b[36m━━━ ${text} ━━━\x1b[0m\n`);
38
- }
39
-
40
- function success(text) {
41
- console.log(`\x1b[32m✓\x1b[0m ${text}`);
42
- }
43
-
44
- function warn(text) {
45
- console.log(`\x1b[33m⚠\x1b[0m ${text}`);
46
- }
47
-
48
- function info(text) {
49
- console.log(`\x1b[34mℹ\x1b[0m ${text}`);
50
- }
51
-
52
- function getDirectories(dirPath) {
53
- try {
54
- return fs.readdirSync(dirPath, { withFileTypes: true })
55
- .filter(d => d.isDirectory())
56
- .map(d => d.name);
57
- } catch {
58
- return [];
59
- }
60
- }
61
-
62
- function extractFrontmatterDescription(filePath) {
63
- try {
64
- const content = fs.readFileSync(filePath, "utf-8");
65
- const match = content.match(/^---\n([\s\S]+?)\n---/);
66
- if (!match) return "";
67
- const frontmatter = match[1];
68
-
69
- // Try multi-line YAML (description: | ...)
70
- const multiLine = frontmatter.match(/^description:\s*\|\s*\n((?:\s{2}.*\n?)*)/m);
71
- if (multiLine) {
72
- return multiLine[1]
73
- .split("\n")
74
- .map(l => l.replace(/^\s{2}/, "").trim())
75
- .filter(l => l)
76
- .join(" ");
77
- }
78
-
79
- // Try single-line: description: text
80
- const singleLine = frontmatter.match(/^description:\s*(.+)$/m);
81
- if (singleLine) {
82
- const val = singleLine[1].trim();
83
- if (val && val !== "|") return val;
84
- }
85
-
86
- return "";
87
- } catch {
88
- return "";
89
- }
90
- }
91
-
92
- function getFiles(dirPath) {
93
- try {
94
- return fs.readdirSync(dirPath, { withFileTypes: true })
95
- .filter(d => d.isFile())
96
- .map(d => d.name);
97
- } catch {
98
- return [];
99
- }
100
- }
101
-
102
- // ─── Commands ───────────────────────────────────────────────────────────────
103
-
104
- function cmdHelp() {
105
- console.log(`
106
- \x1b[1mmy-opencode\x1b[0m — 高品質 opencode 開發流程 skill 與 agents 集合
107
-
108
- \x1b[1m安裝方式 (擇一)\x1b[0m
109
-
110
- \x1b[36m方法 A: npm install\x1b[0m (自動複製到 .opencode/)
111
- npm install my-opencode
112
- ✓ postinstall 自動將 agents/ skills/ plugins/ 複製到 .opencode/
113
- ✓ 原始檔案留在 node_modules/ (已 gitignore)
114
-
115
- \x1b[36m方法 B: npx\x1b[0m (不留 package.json dependency)
116
- npx my-opencode init
117
- ✓ 直接安裝到 .opencode/
118
- ✓ 不寫入 package.json
119
-
120
- \x1b[1mCOMMANDS\x1b[0m
121
- init [target-dir] [--force] 安裝 skills/agents/plugins 到 .opencode/ 下
122
- (預設: 當前目錄的 .opencode/)
123
- --force/-f/--overwrite 覆寫既有檔案 (升級用)
124
- list 列出可用的 skills 與 agents
125
- help 顯示此說明
126
-
127
- \x1b[1mLAUNCHER\x1b[0m
128
- moc 預設使用 opencode profile 啟動 opencode
129
- moc openai 使用 openai profile 啟動 opencode
130
- moc google 使用 google profile 啟動 opencode
131
- moc --help 透明轉發到 opencode --help
132
-
133
- \x1b[1mEXAMPLES\x1b[0m
134
- npm install my-opencode # 方法 A (自動)
135
- npx my-opencode init # 方法 B (手動)
136
- npx my-opencode init ./my-project # 指定專案目錄
137
- npx my-opencode init --force # 覆寫既有檔案 (升級)
138
- npx my-opencode list # 列出內容
139
- moc openai # 用 openai profile 啟動
140
- `);
141
- }
142
-
143
- function cmdList() {
144
- header("Available Skills");
145
- const skills = getDirectories(SKILLS_DIR);
146
- if (skills.length === 0) {
147
- warn("No skills found.");
148
- } else {
149
- for (const s of skills) {
150
- const skillPath = path.join(SKILLS_DIR, s, "SKILL.md");
151
- const desc = extractFrontmatterDescription(skillPath);
152
- console.log(`${INDENT}\x1b[33m${s}\x1b[0m`);
153
- if (desc) console.log(`${INDENT} ${desc}`);
154
- console.log();
155
- }
156
- }
157
-
158
- header("Available Agents");
159
- const agents = getFiles(AGENTS_DIR);
160
- if (agents.length === 0) {
161
- warn("No agents found.");
162
- } else {
163
- for (const a of agents) {
164
- const agentPath = path.join(AGENTS_DIR, a);
165
- const desc = extractFrontmatterDescription(agentPath);
166
- const name = a.replace(/\.md$/, "");
167
- console.log(`${INDENT}\x1b[33m${name}\x1b[0m`);
168
- if (desc) console.log(`${INDENT} ${desc}`);
169
- console.log();
170
- }
171
- }
172
- }
173
-
174
- function cmdInit(targetDir, force) {
175
- // If no target specified, default to .opencode/ in CWD
176
- const target = targetDir
177
- ? path.resolve(targetDir, ".opencode")
178
- : path.resolve(process.cwd(), ".opencode");
179
-
180
- header(`Installing my-opencode → ${target}`);
181
-
182
- if (force) {
183
- info("--force: overwriting existing files");
184
- }
185
-
186
- if (!fs.existsSync(target)) {
187
- fs.mkdirSync(target, { recursive: true });
188
- success(`Created .opencode/`);
189
- }
190
-
191
- // ── Copy skills ───────────────────────────────────────────────────────────
192
- const targetSkills = path.join(target, "skills");
193
- if (!fs.existsSync(targetSkills)) {
194
- fs.mkdirSync(targetSkills, { recursive: true });
195
- }
196
- const skills = getDirectories(SKILLS_DIR);
197
- let skillCount = 0;
198
- for (const s of skills) {
199
- const src = path.join(SKILLS_DIR, s);
200
- const dst = path.join(targetSkills, s);
201
- copyDirSync(src, dst, force);
202
- skillCount++;
203
- }
204
- success(`Skills: ${skillCount} installed → .opencode/skills/`);
205
-
206
- // ── Copy agents ──────────────────────────────────────────────────────────
207
- const targetAgents = path.join(target, "agents");
208
- if (!fs.existsSync(targetAgents)) {
209
- fs.mkdirSync(targetAgents, { recursive: true });
210
- }
211
- const agents = getFiles(AGENTS_DIR);
212
- let agentCount = 0;
213
- for (const a of agents) {
214
- const src = path.join(AGENTS_DIR, a);
215
- const dst = path.join(targetAgents, a);
216
- if (force || !fs.existsSync(dst)) {
217
- fs.copyFileSync(src, dst);
218
- agentCount++;
219
- } else {
220
- warn(`Skipped (already exists): agents/${a}`);
221
- }
222
- }
223
- success(`Agents: ${agentCount} installed → .opencode/agents/`);
224
-
225
- // ── Copy plugins ─────────────────────────────────────────────────────────
226
- const targetPlugins = path.join(target, "plugins");
227
- if (!fs.existsSync(targetPlugins)) {
228
- fs.mkdirSync(targetPlugins, { recursive: true });
229
- }
230
- const plugins = getFiles(PLUGINS_DIR).filter((name) => name.endsWith(".mjs"));
231
- let pluginCount = 0;
232
- for (const plugin of plugins) {
233
- const src = path.join(PLUGINS_DIR, plugin);
234
- const dst = path.join(targetPlugins, plugin);
235
- if (force || !fs.existsSync(dst)) {
236
- fs.copyFileSync(src, dst);
237
- pluginCount++;
238
- } else {
239
- warn(`Skipped (already exists): plugins/${plugin}`);
240
- }
241
- }
242
- success(`Plugins: ${pluginCount} installed → .opencode/plugins/`);
243
-
244
- // ── Generate opencode.json ──────────────────────────────────────────────
245
- const targetConfig = path.join(target, "opencode.json");
246
- if (force || !fs.existsSync(targetConfig)) {
247
- try {
248
- const config = JSON.parse(fs.readFileSync(OPENCODE_CONFIG, "utf-8"));
249
- fs.writeFileSync(targetConfig, JSON.stringify(config, null, 2) + "\n");
250
- success("Generated .opencode/opencode.json — ready to use");
251
- } catch {
252
- warn("Could not generate opencode.json (source config missing or invalid)");
253
- }
254
- } else {
255
- warn("Skipped (already exists): .opencode/opencode.json");
256
- }
257
-
258
- // ── Summary ──────────────────────────────────────────────────────────────
259
- console.log();
260
- header("Installation Complete");
261
- info("my-opencode is ready at .opencode/");
262
- info('Use "moc" as the primary launcher once the bin is on your PATH');
263
- console.log();
264
- console.log(`${INDENT}Your project's opencode.json should reference:`);
265
- console.log(`${INDENT} "instructions": [`);
266
- console.log(`${INDENT} ".opencode/skills/adr/SKILL.md",`);
267
- console.log(`${INDENT} ".opencode/skills/dev-flow/SKILL.md",`);
268
- console.log(`${INDENT} ".opencode/skills/pr-review/SKILL.md",`);
269
- console.log(`${INDENT} ".opencode/skills/test-gen/SKILL.md",`);
270
- console.log(`${INDENT} ".opencode/skills/docs-gen/SKILL.md",`);
271
- console.log(`${INDENT} ".opencode/skills/orchestrate/SKILL.md"`);
272
- console.log(`${INDENT} ]`);
273
- console.log();
274
- console.log(`${INDENT}Agents, commands, and plugins from .opencode/opencode.json`);
275
- console.log(`${INDENT}are auto-discovered by opencode.`);
276
- console.log();
277
- info("Documentation: https://github.com/jjyung/my-opencode");
278
- console.log();
279
- }
280
-
281
- // ─── File Utilities ─────────────────────────────────────────────────────────
282
-
283
- function copyDirSync(src, dst, force) {
284
- fs.mkdirSync(dst, { recursive: true });
285
- const entries = fs.readdirSync(src, { withFileTypes: true });
286
- for (const entry of entries) {
287
- const srcPath = path.join(src, entry.name);
288
- const dstPath = path.join(dst, entry.name);
289
- if (entry.isDirectory()) {
290
- copyDirSync(srcPath, dstPath, force);
291
- } else if (entry.isFile()) {
292
- if (force || !fs.existsSync(dstPath)) {
293
- fs.copyFileSync(srcPath, dstPath);
294
- }
295
- }
296
- }
297
- }
298
-
299
- // ─── Argument parsing ─────────────────────────────────────────────────────────
300
-
301
- function parseInitArgs(args) {
302
- let targetDir = null;
303
- let force = false;
304
- for (const arg of args) {
305
- if (arg === "--force" || arg === "-f" || arg === "--overwrite") {
306
- force = true;
307
- } else if (!targetDir && !arg.startsWith("-")) {
308
- targetDir = arg;
309
- }
310
- }
311
- return { targetDir, force };
312
- }
313
-
314
- // ─── Main ───────────────────────────────────────────────────────────────────
315
-
316
- function main() {
317
- const args = process.argv.slice(2);
318
- const cmd = args[0] || "";
319
-
320
- switch (cmd) {
321
- case "init":
322
- case "install": {
323
- const { targetDir, force } = parseInitArgs(args.slice(1));
324
- cmdInit(targetDir, force);
325
- break;
326
- }
327
- case "list":
328
- case "ls":
329
- cmdList();
330
- break;
331
- case "help":
332
- case "--help":
333
- case "-h":
334
- cmdHelp();
335
- break;
336
- default:
337
- // No args — show a friendly welcome and prompt to init
338
- console.log(`
339
- \x1b[1mmy-opencode\x1b[0m — 高品質 opencode 開發流程 skill 與 agents 集合
340
-
341
- 在專案中執行以下指令來安裝到 \x1b[33m.opencode/\x1b[0m:
342
-
343
- \x1b[36mnpx my-opencode init\x1b[0m
344
- \x1b[36mnpx my-opencode init --force\x1b[0m (升級時覆寫既有檔案)
345
-
346
- 安裝後,將以下內容加入你的 \x1b[33mopencode.json\x1b[0m:
347
-
348
- \x1b[2m"instructions": [
349
- ".opencode/skills/adr/SKILL.md",
350
- ".opencode/skills/dev-flow/SKILL.md",
351
- ".opencode/skills/pr-review/SKILL.md",
352
- ".opencode/skills/test-gen/SKILL.md",
353
- ".opencode/skills/docs-gen/SKILL.md",
354
- ".opencode/skills/orchestrate/SKILL.md"
355
- ]\x1b[0m
356
-
357
- 更多資訊請執行:\x1b[36mnpx my-opencode help\x1b[0m
358
-
359
- 若已透過 npm install 安裝,也可直接使用:\x1b[36mmoc\x1b[0m / \x1b[36mmoc openai\x1b[0m
360
- `);
361
- break;
362
- }
363
- }
364
-
365
- main();
2
+
3
+ /**
4
+ * my-opencode CLI
5
+ *
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/plugins into .opencode/
16
+ * list List available skills and agents
17
+ * help Show this help
18
+ */
19
+
20
+ import { fileURLToPath } from "node:url";
21
+ import path from "node:path";
22
+ import fs from "node:fs";
23
+
24
+ const __filename = fileURLToPath(import.meta.url);
25
+ const PKG_ROOT = path.resolve(path.dirname(__filename), "..");
26
+
27
+ const SKILLS_DIR = path.join(PKG_ROOT, "skills");
28
+ const AGENTS_DIR = path.join(PKG_ROOT, "agents");
29
+ const PLUGINS_DIR = path.join(PKG_ROOT, "plugins");
30
+ const OPENCODE_CONFIG = path.join(PKG_ROOT, "opencode.json");
31
+
32
+ const INDENT = " ";
33
+
34
+ // ─── Helpers ────────────────────────────────────────────────────────────────
35
+
36
+ function header(text) {
37
+ console.log(`\n\x1b[36m━━━ ${text} ━━━\x1b[0m\n`);
38
+ }
39
+
40
+ function success(text) {
41
+ console.log(`\x1b[32m✓\x1b[0m ${text}`);
42
+ }
43
+
44
+ function warn(text) {
45
+ console.log(`\x1b[33m⚠\x1b[0m ${text}`);
46
+ }
47
+
48
+ function info(text) {
49
+ console.log(`\x1b[34mℹ\x1b[0m ${text}`);
50
+ }
51
+
52
+ function getDirectories(dirPath) {
53
+ try {
54
+ return fs.readdirSync(dirPath, { withFileTypes: true })
55
+ .filter(d => d.isDirectory())
56
+ .map(d => d.name);
57
+ } catch {
58
+ return [];
59
+ }
60
+ }
61
+
62
+ function extractFrontmatterDescription(filePath) {
63
+ try {
64
+ const content = fs.readFileSync(filePath, "utf-8");
65
+ const match = content.match(/^---\n([\s\S]+?)\n---/);
66
+ if (!match) return "";
67
+ const frontmatter = match[1];
68
+
69
+ // Try multi-line YAML (description: | ...)
70
+ const multiLine = frontmatter.match(/^description:\s*\|\s*\n((?:\s{2}.*\n?)*)/m);
71
+ if (multiLine) {
72
+ return multiLine[1]
73
+ .split("\n")
74
+ .map(l => l.replace(/^\s{2}/, "").trim())
75
+ .filter(l => l)
76
+ .join(" ");
77
+ }
78
+
79
+ // Try single-line: description: text
80
+ const singleLine = frontmatter.match(/^description:\s*(.+)$/m);
81
+ if (singleLine) {
82
+ const val = singleLine[1].trim();
83
+ if (val && val !== "|") return val;
84
+ }
85
+
86
+ return "";
87
+ } catch {
88
+ return "";
89
+ }
90
+ }
91
+
92
+ function getFiles(dirPath) {
93
+ try {
94
+ return fs.readdirSync(dirPath, { withFileTypes: true })
95
+ .filter(d => d.isFile())
96
+ .map(d => d.name);
97
+ } catch {
98
+ return [];
99
+ }
100
+ }
101
+
102
+ // ─── Commands ───────────────────────────────────────────────────────────────
103
+
104
+ function cmdHelp() {
105
+ console.log(`
106
+ \x1b[1mmy-opencode\x1b[0m — 高品質 opencode 開發流程 skill 與 agents 集合
107
+
108
+ \x1b[1m安裝方式 (擇一)\x1b[0m
109
+
110
+ \x1b[36m方法 A: npm install\x1b[0m (自動複製到 .opencode/)
111
+ npm install my-opencode
112
+ ✓ postinstall 自動將 agents/ skills/ plugins/ 複製到 .opencode/
113
+ ✓ 原始檔案留在 node_modules/ (已 gitignore)
114
+
115
+ \x1b[36m方法 B: npx\x1b[0m (不留 package.json dependency)
116
+ npx my-opencode init
117
+ ✓ 直接安裝到 .opencode/
118
+ ✓ 不寫入 package.json
119
+
120
+ \x1b[1mCOMMANDS\x1b[0m
121
+ init [target-dir] [--force] 安裝 skills/agents/plugins 到 .opencode/ 下
122
+ (預設: 當前目錄的 .opencode/)
123
+ --force/-f/--overwrite 覆寫既有檔案 (升級用)
124
+ list 列出可用的 skills 與 agents
125
+ help 顯示此說明
126
+
127
+ \x1b[1mLAUNCHER\x1b[0m
128
+ moc 預設使用 opencode profile 啟動 opencode
129
+ moc openai 使用 openai profile 啟動 opencode
130
+ moc google 使用 google profile 啟動 opencode
131
+ moc --help 透明轉發到 opencode --help
132
+
133
+ \x1b[1mEXAMPLES\x1b[0m
134
+ npm install my-opencode # 方法 A (自動)
135
+ npx my-opencode init # 方法 B (手動)
136
+ npx my-opencode init ./my-project # 指定專案目錄
137
+ npx my-opencode init --force # 覆寫既有檔案 (升級)
138
+ npx my-opencode list # 列出內容
139
+ moc openai # 用 openai profile 啟動
140
+ `);
141
+ }
142
+
143
+ function cmdList() {
144
+ header("Available Skills");
145
+ const skills = getDirectories(SKILLS_DIR);
146
+ if (skills.length === 0) {
147
+ warn("No skills found.");
148
+ } else {
149
+ for (const s of skills) {
150
+ const skillPath = path.join(SKILLS_DIR, s, "SKILL.md");
151
+ const desc = extractFrontmatterDescription(skillPath);
152
+ console.log(`${INDENT}\x1b[33m${s}\x1b[0m`);
153
+ if (desc) console.log(`${INDENT} ${desc}`);
154
+ console.log();
155
+ }
156
+ }
157
+
158
+ header("Available Agents");
159
+ const agents = getFiles(AGENTS_DIR);
160
+ if (agents.length === 0) {
161
+ warn("No agents found.");
162
+ } else {
163
+ for (const a of agents) {
164
+ const agentPath = path.join(AGENTS_DIR, a);
165
+ const desc = extractFrontmatterDescription(agentPath);
166
+ const name = a.replace(/\.md$/, "");
167
+ console.log(`${INDENT}\x1b[33m${name}\x1b[0m`);
168
+ if (desc) console.log(`${INDENT} ${desc}`);
169
+ console.log();
170
+ }
171
+ }
172
+ }
173
+
174
+ function cmdInit(targetDir, force) {
175
+ // If no target specified, default to .opencode/ in CWD
176
+ const target = targetDir
177
+ ? path.resolve(targetDir, ".opencode")
178
+ : path.resolve(process.cwd(), ".opencode");
179
+
180
+ header(`Installing my-opencode → ${target}`);
181
+
182
+ if (force) {
183
+ info("--force: overwriting existing files");
184
+ }
185
+
186
+ if (!fs.existsSync(target)) {
187
+ fs.mkdirSync(target, { recursive: true });
188
+ success(`Created .opencode/`);
189
+ }
190
+
191
+ // ── Copy skills ───────────────────────────────────────────────────────────
192
+ const targetSkills = path.join(target, "skills");
193
+ if (!fs.existsSync(targetSkills)) {
194
+ fs.mkdirSync(targetSkills, { recursive: true });
195
+ }
196
+ const skills = getDirectories(SKILLS_DIR);
197
+ let skillCount = 0;
198
+ for (const s of skills) {
199
+ const src = path.join(SKILLS_DIR, s);
200
+ const dst = path.join(targetSkills, s);
201
+ copyDirSync(src, dst, force);
202
+ skillCount++;
203
+ }
204
+ success(`Skills: ${skillCount} installed → .opencode/skills/`);
205
+
206
+ // ── Copy agents ──────────────────────────────────────────────────────────
207
+ const targetAgents = path.join(target, "agents");
208
+ if (!fs.existsSync(targetAgents)) {
209
+ fs.mkdirSync(targetAgents, { recursive: true });
210
+ }
211
+ const agents = getFiles(AGENTS_DIR);
212
+ let agentCount = 0;
213
+ for (const a of agents) {
214
+ const src = path.join(AGENTS_DIR, a);
215
+ const dst = path.join(targetAgents, a);
216
+ if (force || !fs.existsSync(dst)) {
217
+ fs.copyFileSync(src, dst);
218
+ agentCount++;
219
+ } else {
220
+ warn(`Skipped (already exists): agents/${a}`);
221
+ }
222
+ }
223
+ success(`Agents: ${agentCount} installed → .opencode/agents/`);
224
+
225
+ // ── Copy plugins ─────────────────────────────────────────────────────────
226
+ const targetPlugins = path.join(target, "plugins");
227
+ if (!fs.existsSync(targetPlugins)) {
228
+ fs.mkdirSync(targetPlugins, { recursive: true });
229
+ }
230
+ const plugins = getFiles(PLUGINS_DIR).filter((name) => name.endsWith(".mjs"));
231
+ let pluginCount = 0;
232
+ for (const plugin of plugins) {
233
+ const src = path.join(PLUGINS_DIR, plugin);
234
+ const dst = path.join(targetPlugins, plugin);
235
+ if (force || !fs.existsSync(dst)) {
236
+ fs.copyFileSync(src, dst);
237
+ pluginCount++;
238
+ } else {
239
+ warn(`Skipped (already exists): plugins/${plugin}`);
240
+ }
241
+ }
242
+ success(`Plugins: ${pluginCount} installed → .opencode/plugins/`);
243
+
244
+ // ── Generate opencode.json ──────────────────────────────────────────────
245
+ const targetConfig = path.join(target, "opencode.json");
246
+ if (force || !fs.existsSync(targetConfig)) {
247
+ try {
248
+ const config = JSON.parse(fs.readFileSync(OPENCODE_CONFIG, "utf-8"));
249
+ fs.writeFileSync(targetConfig, JSON.stringify(config, null, 2) + "\n");
250
+ success("Generated .opencode/opencode.json — ready to use");
251
+ } catch {
252
+ warn("Could not generate opencode.json (source config missing or invalid)");
253
+ }
254
+ } else {
255
+ warn("Skipped (already exists): .opencode/opencode.json");
256
+ }
257
+
258
+ // ── Summary ──────────────────────────────────────────────────────────────
259
+ console.log();
260
+ header("Installation Complete");
261
+ info("my-opencode is ready at .opencode/");
262
+ info('Use "moc" as the primary launcher once the bin is on your PATH');
263
+ console.log();
264
+ console.log(`${INDENT}Your project's opencode.json should reference:`);
265
+ console.log(`${INDENT} "instructions": [`);
266
+ console.log(`${INDENT} ".opencode/skills/adr/SKILL.md",`);
267
+ console.log(`${INDENT} ".opencode/skills/dev-flow/SKILL.md",`);
268
+ console.log(`${INDENT} ".opencode/skills/pr-review/SKILL.md",`);
269
+ console.log(`${INDENT} ".opencode/skills/test-gen/SKILL.md",`);
270
+ console.log(`${INDENT} ".opencode/skills/docs-gen/SKILL.md",`);
271
+ console.log(`${INDENT} ".opencode/skills/orchestrate/SKILL.md",`);
272
+ console.log(`${INDENT} ".opencode/skills/design-evidence/SKILL.md"`);
273
+ console.log(`${INDENT} ]`);
274
+ console.log();
275
+ console.log(`${INDENT}Agents, commands, and plugins from .opencode/opencode.json`);
276
+ console.log(`${INDENT}are auto-discovered by opencode.`);
277
+ console.log();
278
+ info("Documentation: https://github.com/jjyung/my-opencode");
279
+ console.log();
280
+ }
281
+
282
+ // ─── File Utilities ─────────────────────────────────────────────────────────
283
+
284
+ function copyDirSync(src, dst, force) {
285
+ fs.mkdirSync(dst, { recursive: true });
286
+ const entries = fs.readdirSync(src, { withFileTypes: true });
287
+ for (const entry of entries) {
288
+ const srcPath = path.join(src, entry.name);
289
+ const dstPath = path.join(dst, entry.name);
290
+ if (entry.isDirectory()) {
291
+ copyDirSync(srcPath, dstPath, force);
292
+ } else if (entry.isFile()) {
293
+ if (force || !fs.existsSync(dstPath)) {
294
+ fs.copyFileSync(srcPath, dstPath);
295
+ }
296
+ }
297
+ }
298
+ }
299
+
300
+ // ─── Argument parsing ─────────────────────────────────────────────────────────
301
+
302
+ function parseInitArgs(args) {
303
+ let targetDir = null;
304
+ let force = false;
305
+ for (const arg of args) {
306
+ if (arg === "--force" || arg === "-f" || arg === "--overwrite") {
307
+ force = true;
308
+ } else if (!targetDir && !arg.startsWith("-")) {
309
+ targetDir = arg;
310
+ }
311
+ }
312
+ return { targetDir, force };
313
+ }
314
+
315
+ // ─── Main ───────────────────────────────────────────────────────────────────
316
+
317
+ function main() {
318
+ const args = process.argv.slice(2);
319
+ const cmd = args[0] || "";
320
+
321
+ switch (cmd) {
322
+ case "init":
323
+ case "install": {
324
+ const { targetDir, force } = parseInitArgs(args.slice(1));
325
+ cmdInit(targetDir, force);
326
+ break;
327
+ }
328
+ case "list":
329
+ case "ls":
330
+ cmdList();
331
+ break;
332
+ case "help":
333
+ case "--help":
334
+ case "-h":
335
+ cmdHelp();
336
+ break;
337
+ default:
338
+ // No args — show a friendly welcome and prompt to init
339
+ console.log(`
340
+ \x1b[1mmy-opencode\x1b[0m — 高品質 opencode 開發流程 skill 與 agents 集合
341
+
342
+ 在專案中執行以下指令來安裝到 \x1b[33m.opencode/\x1b[0m:
343
+
344
+ \x1b[36mnpx my-opencode init\x1b[0m
345
+ \x1b[36mnpx my-opencode init --force\x1b[0m (升級時覆寫既有檔案)
346
+
347
+ 安裝後,將以下內容加入你的 \x1b[33mopencode.json\x1b[0m:
348
+
349
+ \x1b[2m"instructions": [
350
+ ".opencode/skills/adr/SKILL.md",
351
+ ".opencode/skills/dev-flow/SKILL.md",
352
+ ".opencode/skills/pr-review/SKILL.md",
353
+ ".opencode/skills/test-gen/SKILL.md",
354
+ ".opencode/skills/docs-gen/SKILL.md",
355
+ ".opencode/skills/orchestrate/SKILL.md",
356
+ ".opencode/skills/design-evidence/SKILL.md"
357
+ ]\x1b[0m
358
+
359
+ 更多資訊請執行:\x1b[36mnpx my-opencode help\x1b[0m
360
+
361
+ 若已透過 npm install 安裝,也可直接使用:\x1b[36mmoc\x1b[0m / \x1b[36mmoc openai\x1b[0m
362
+ `);
363
+ break;
364
+ }
365
+ }
366
+
367
+ main();