my-opencode 1.0.0 → 1.2.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/LICENSE +21 -21
- package/README.md +180 -163
- package/agents/architect.md +30 -30
- package/agents/code-reviewer.md +29 -29
- package/agents/executor.md +30 -30
- package/agents/fullstack-dev.md +57 -53
- package/agents/spec-writer.md +37 -37
- package/agents/team-lead.md +60 -60
- package/agents/tech-writer.md +30 -30
- package/agents/test-engineer.md +30 -30
- package/agents/verifier.md +33 -33
- package/bin/cli.js +311 -272
- package/opencode.json +167 -164
- package/package.json +48 -44
- package/scripts/postinstall.js +182 -0
- package/skills/adr/SKILL.md +91 -91
- package/skills/adr/references/templates.md +100 -100
- package/skills/adr/scripts/README.md +5 -5
- package/skills/dev-flow/SKILL.md +188 -188
- package/skills/dev-flow/references/code-phase.md +72 -72
- package/skills/dev-flow/references/contract-phase.md +81 -81
- package/skills/dev-flow/references/verify-phase.md +129 -129
- package/skills/dev-flow/scripts/README.md +3 -3
- package/skills/docs-gen/SKILL.md +162 -162
- package/skills/docs-gen/references/doc-styles.md +216 -216
- package/skills/docs-gen/scripts/README.md +5 -5
- package/skills/orchestrate/SKILL.md +112 -112
- package/skills/orchestrate/references/orchestration-patterns.md +56 -56
- package/skills/pr-review/SKILL.md +110 -110
- package/skills/pr-review/references/review-dimensions.md +117 -117
- package/skills/pr-review/references/security-checklist.md +122 -122
- package/skills/pr-review/scripts/README.md +5 -5
- package/skills/test-gen/SKILL.md +143 -143
- package/skills/test-gen/references/framework-detection.md +105 -105
- package/skills/test-gen/references/test-patterns.md +260 -260
- package/skills/test-gen/scripts/README.md +5 -5
package/opencode.json
CHANGED
|
@@ -1,164 +1,167 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://opencode.ai/config.json",
|
|
3
|
-
"model": "opencode/deepseek-v4-flash-free",
|
|
4
|
-
"small_model": "opencode/nemotron-3-super-free",
|
|
5
|
-
"default_agent": "fullstack-dev",
|
|
6
|
-
"instructions": [
|
|
7
|
-
"skills/adr/SKILL.md",
|
|
8
|
-
"skills/dev-flow/SKILL.md",
|
|
9
|
-
"skills/pr-review/SKILL.md",
|
|
10
|
-
"skills/test-gen/SKILL.md",
|
|
11
|
-
"skills/docs-gen/SKILL.md",
|
|
12
|
-
"skills/orchestrate/SKILL.md"
|
|
13
|
-
],
|
|
14
|
-
"agent": {
|
|
15
|
-
"fullstack-dev": {
|
|
16
|
-
"description": "Primary development agent. Orchestrates contract-first ADR → contract → code → verify flow.",
|
|
17
|
-
"mode": "primary",
|
|
18
|
-
"prompt": "{file:agents/fullstack-dev.md}",
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
"
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
"
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
"
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
"
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
"
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
"
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
"
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
"
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
"
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
"
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
"
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
"
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
"
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
"
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
"
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
"
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
"
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
"
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
"
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
"
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
"
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
"
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
"
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
"
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
"
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
"
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://opencode.ai/config.json",
|
|
3
|
+
"model": "opencode/deepseek-v4-flash-free",
|
|
4
|
+
"small_model": "opencode/nemotron-3-super-free",
|
|
5
|
+
"default_agent": "fullstack-dev",
|
|
6
|
+
"instructions": [
|
|
7
|
+
"skills/adr/SKILL.md",
|
|
8
|
+
"skills/dev-flow/SKILL.md",
|
|
9
|
+
"skills/pr-review/SKILL.md",
|
|
10
|
+
"skills/test-gen/SKILL.md",
|
|
11
|
+
"skills/docs-gen/SKILL.md",
|
|
12
|
+
"skills/orchestrate/SKILL.md"
|
|
13
|
+
],
|
|
14
|
+
"agent": {
|
|
15
|
+
"fullstack-dev": {
|
|
16
|
+
"description": "Primary development agent. Orchestrates contract-first ADR → contract → code → verify flow.",
|
|
17
|
+
"mode": "primary",
|
|
18
|
+
"prompt": "{file:agents/fullstack-dev.md}",
|
|
19
|
+
"permission": {
|
|
20
|
+
"task": "ask"
|
|
21
|
+
},
|
|
22
|
+
"tools": {
|
|
23
|
+
"read": true,
|
|
24
|
+
"write": true,
|
|
25
|
+
"edit": true,
|
|
26
|
+
"bash": true
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"spec-writer": {
|
|
30
|
+
"description": "Analyze requirements and produce contract specifications in docs/specs/. Writes persistent contracts for parallel development.",
|
|
31
|
+
"mode": "subagent",
|
|
32
|
+
"model": "opencode/big-pickle",
|
|
33
|
+
"prompt": "{file:agents/spec-writer.md}",
|
|
34
|
+
"tools": {
|
|
35
|
+
"read": true,
|
|
36
|
+
"bash": true,
|
|
37
|
+
"write": true,
|
|
38
|
+
"edit": true
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"executor": {
|
|
42
|
+
"description": "Implement code changes following an approved contract. Full read/write access for coding.",
|
|
43
|
+
"mode": "subagent",
|
|
44
|
+
"prompt": "{file:agents/executor.md}",
|
|
45
|
+
"tools": {
|
|
46
|
+
"read": true,
|
|
47
|
+
"write": true,
|
|
48
|
+
"edit": true,
|
|
49
|
+
"bash": true
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"verifier": {
|
|
53
|
+
"description": "Run lint, typecheck, tests, and build to verify code changes. Read-only + bash.",
|
|
54
|
+
"mode": "subagent",
|
|
55
|
+
"model": "opencode/nemotron-3-super-free",
|
|
56
|
+
"prompt": "{file:agents/verifier.md}",
|
|
57
|
+
"tools": {
|
|
58
|
+
"read": true,
|
|
59
|
+
"bash": true,
|
|
60
|
+
"write": false,
|
|
61
|
+
"edit": false
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
"code-reviewer": {
|
|
65
|
+
"description": "Systematic code review across correctness, security, quality, testing, and style dimensions.",
|
|
66
|
+
"mode": "subagent",
|
|
67
|
+
"model": "opencode/big-pickle",
|
|
68
|
+
"prompt": "{file:agents/code-reviewer.md}",
|
|
69
|
+
"tools": {
|
|
70
|
+
"read": true,
|
|
71
|
+
"bash": true,
|
|
72
|
+
"write": false,
|
|
73
|
+
"edit": false
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
"test-engineer": {
|
|
77
|
+
"description": "Generate meaningful tests for source code — unit, integration, and E2E. Framework-aware.",
|
|
78
|
+
"mode": "subagent",
|
|
79
|
+
"prompt": "{file:agents/test-engineer.md}",
|
|
80
|
+
"tools": {
|
|
81
|
+
"read": true,
|
|
82
|
+
"write": true,
|
|
83
|
+
"edit": true,
|
|
84
|
+
"bash": true
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
"tech-writer": {
|
|
88
|
+
"description": "Generate and update project documentation — code comments, API docs, README, and CHANGELOG.",
|
|
89
|
+
"mode": "subagent",
|
|
90
|
+
"prompt": "{file:agents/tech-writer.md}",
|
|
91
|
+
"tools": {
|
|
92
|
+
"read": true,
|
|
93
|
+
"write": true,
|
|
94
|
+
"edit": true,
|
|
95
|
+
"bash": true
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
"team-lead": {
|
|
99
|
+
"description": "Multi-agent orchestrator for complex tasks. Delegates to architect, spec-writer, executor, code-reviewer, test-engineer, verifier.",
|
|
100
|
+
"mode": "subagent",
|
|
101
|
+
"model": "opencode/big-pickle",
|
|
102
|
+
"prompt": "{file:agents/team-lead.md}",
|
|
103
|
+
"tools": {
|
|
104
|
+
"read": true,
|
|
105
|
+
"write": true,
|
|
106
|
+
"edit": true,
|
|
107
|
+
"bash": true
|
|
108
|
+
}
|
|
109
|
+
},
|
|
110
|
+
"architect": {
|
|
111
|
+
"description": "Capture architecture decisions as ADR documents. Analyzes tradeoffs and records context.",
|
|
112
|
+
"mode": "subagent",
|
|
113
|
+
"model": "opencode/big-pickle",
|
|
114
|
+
"prompt": "{file:agents/architect.md}",
|
|
115
|
+
"tools": {
|
|
116
|
+
"read": true,
|
|
117
|
+
"write": true,
|
|
118
|
+
"edit": true,
|
|
119
|
+
"bash": true
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
"command": {
|
|
124
|
+
"spec": {
|
|
125
|
+
"description": "Create a contract specification in docs/specs/ — source of truth for implementation",
|
|
126
|
+
"agent": "spec-writer",
|
|
127
|
+
"subtask": true,
|
|
128
|
+
"template": "Analyze the request and produce a contract specification document.\n\n$ARGUMENTS"
|
|
129
|
+
},
|
|
130
|
+
"review": {
|
|
131
|
+
"description": "Review code changes across 5 dimensions (correctness, security, quality, testing, style)",
|
|
132
|
+
"agent": "code-reviewer",
|
|
133
|
+
"subtask": true,
|
|
134
|
+
"template": "Review the current changes.\n\n$ARGUMENTS"
|
|
135
|
+
},
|
|
136
|
+
"test": {
|
|
137
|
+
"description": "Generate tests for source code — auto-detects framework and conventions",
|
|
138
|
+
"agent": "test-engineer",
|
|
139
|
+
"subtask": true,
|
|
140
|
+
"template": "Generate tests for the current code.\n\n$ARGUMENTS"
|
|
141
|
+
},
|
|
142
|
+
"docs": {
|
|
143
|
+
"description": "Generate or update documentation — code comments, README, API docs, ADRs",
|
|
144
|
+
"agent": "tech-writer",
|
|
145
|
+
"subtask": true,
|
|
146
|
+
"template": "Generate or update documentation.\n\n$ARGUMENTS"
|
|
147
|
+
},
|
|
148
|
+
"orchestrate": {
|
|
149
|
+
"description": "Coordinate multiple agents for complex, multi-domain tasks",
|
|
150
|
+
"agent": "team-lead",
|
|
151
|
+
"subtask": true,
|
|
152
|
+
"template": "Orchestrate the following complex task.\n\n$ARGUMENTS"
|
|
153
|
+
},
|
|
154
|
+
"adr": {
|
|
155
|
+
"description": "Create or update an Architecture Decision Record",
|
|
156
|
+
"agent": "architect",
|
|
157
|
+
"subtask": true,
|
|
158
|
+
"template": "Create an Architecture Decision Record.\n\n$ARGUMENTS"
|
|
159
|
+
},
|
|
160
|
+
"verify": {
|
|
161
|
+
"description": "Run lint, typecheck, tests, and build to verify changes",
|
|
162
|
+
"template": "Use the verifier agent to run the full verification suite on the current changes.\n\n$ARGUMENTS",
|
|
163
|
+
"agent": "verifier",
|
|
164
|
+
"subtask": true
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
package/package.json
CHANGED
|
@@ -1,44 +1,48 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "my-opencode",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "高品質 opencode 開發流程 skill 與 agents 集合 — Contract-First 開發流程、ADR、PR Review、測試生成、文件生成",
|
|
5
|
-
"keywords": [
|
|
6
|
-
"opencode",
|
|
7
|
-
"claude-code",
|
|
8
|
-
"ai-coding",
|
|
9
|
-
"development-workflow",
|
|
10
|
-
"contract-first",
|
|
11
|
-
"adr",
|
|
12
|
-
"code-review",
|
|
13
|
-
"test-generation",
|
|
14
|
-
"documentation",
|
|
15
|
-
"agents",
|
|
16
|
-
"skills"
|
|
17
|
-
],
|
|
18
|
-
"homepage": "https://github.com/cfh00902455/my-opencode#readme",
|
|
19
|
-
"bugs": {
|
|
20
|
-
"url": "https://github.com/cfh00902455/my-opencode/issues"
|
|
21
|
-
},
|
|
22
|
-
"license": "MIT",
|
|
23
|
-
"author": "cfh00902455",
|
|
24
|
-
"repository": {
|
|
25
|
-
"type": "git",
|
|
26
|
-
"url": "git+https://github.com/cfh00902455/my-opencode.git"
|
|
27
|
-
},
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
},
|
|
31
|
-
"
|
|
32
|
-
"bin/"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
"
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
}
|
|
44
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "my-opencode",
|
|
3
|
+
"version": "1.2.0",
|
|
4
|
+
"description": "高品質 opencode 開發流程 skill 與 agents 集合 — Contract-First 開發流程、ADR、PR Review、測試生成、文件生成",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"opencode",
|
|
7
|
+
"claude-code",
|
|
8
|
+
"ai-coding",
|
|
9
|
+
"development-workflow",
|
|
10
|
+
"contract-first",
|
|
11
|
+
"adr",
|
|
12
|
+
"code-review",
|
|
13
|
+
"test-generation",
|
|
14
|
+
"documentation",
|
|
15
|
+
"agents",
|
|
16
|
+
"skills"
|
|
17
|
+
],
|
|
18
|
+
"homepage": "https://github.com/cfh00902455/my-opencode#readme",
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/cfh00902455/my-opencode/issues"
|
|
21
|
+
},
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"author": "cfh00902455",
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/cfh00902455/my-opencode.git"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"postinstall": "node scripts/postinstall.js"
|
|
30
|
+
},
|
|
31
|
+
"bin": {
|
|
32
|
+
"my-opencode": "bin/cli.js"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"bin/",
|
|
36
|
+
"scripts/",
|
|
37
|
+
"skills/",
|
|
38
|
+
"agents/",
|
|
39
|
+
"opencode.json"
|
|
40
|
+
],
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=18.0.0"
|
|
43
|
+
},
|
|
44
|
+
"type": "module",
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -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();
|