my-opencode 1.2.0 → 1.3.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 +259 -180
- 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 -57
- 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 +341 -311
- package/bin/moc +199 -0
- package/opencode.json +170 -167
- package/package.json +50 -48
- package/plugins/README.md +64 -0
- package/plugins/provider-profile.mjs +139 -0
- package/scripts/postinstall.js +202 -182
- 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
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Plugins
|
|
2
|
+
|
|
3
|
+
opencode plugin 是透過 `opencode.json` 的 `plugin` 區塊註冊的 npm 或本地封裝,可包含自訂 tool、MCP 整合、或額外的 subagent 類型。
|
|
4
|
+
|
|
5
|
+
## 目前包含
|
|
6
|
+
|
|
7
|
+
### `provider-profile.mjs`
|
|
8
|
+
|
|
9
|
+
零依賴 ESM plugin / resolver,用來切換本 repo 的模型 profile。
|
|
10
|
+
|
|
11
|
+
- 預設 profile:`opencode`
|
|
12
|
+
- 支援:`opencode`、`openai`、`google`、`copilot`
|
|
13
|
+
- 讀取:`OPENCODE_PROVIDER_PROFILE`
|
|
14
|
+
- 可透過 plugin tuple options 覆寫:`["plugins/provider-profile.mjs", { "profile": "google" }]`
|
|
15
|
+
|
|
16
|
+
| Profile | Primary / heavy | Small / verifier |
|
|
17
|
+
|---------|------------------|------------------|
|
|
18
|
+
| `opencode` | `opencode/big-pickle` | `opencode/deepseek-v4-flash-free` |
|
|
19
|
+
| `openai` | `openai/gpt-5.4` | `openai/gpt-5.4-mini` |
|
|
20
|
+
| `google` | `google/gemini-3.1-pro-preview-customtools` | `google/gemini-3.5-flash` |
|
|
21
|
+
| `copilot` | `copilot/gpt-5.4` | `copilot/gpt-5.4-mini` |
|
|
22
|
+
|
|
23
|
+
### 用法
|
|
24
|
+
|
|
25
|
+
建議優先使用 `moc`:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
moc
|
|
29
|
+
moc openai
|
|
30
|
+
moc google --list-agents
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
`moc` 會對四個已知 profile 快取 provider-profile 產生出的 JSON override,位置在 `.opencode/cache/provider-profile/`。快取是否有效由以下條件決定:
|
|
34
|
+
|
|
35
|
+
- profile 名稱
|
|
36
|
+
- `.opencode/plugins/provider-profile.mjs` 的 mtime
|
|
37
|
+
- `.opencode/opencode.json` 的 mtime
|
|
38
|
+
|
|
39
|
+
若三者都沒變,`moc` 會直接重用快取,不再重新執行 `node .opencode/plugins/provider-profile.mjs`。
|
|
40
|
+
|
|
41
|
+
進階情境可直接設定環境變數:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
OPENCODE_CONFIG_CONTENT="$(node .opencode/plugins/provider-profile.mjs)" opencode
|
|
45
|
+
|
|
46
|
+
OPENCODE_PROVIDER_PROFILE=openai \
|
|
47
|
+
OPENCODE_CONFIG_CONTENT="$(node .opencode/plugins/provider-profile.mjs)" \
|
|
48
|
+
opencode
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
直接執行模組時,會輸出可供 `OPENCODE_CONFIG_CONTENT` 使用的 JSON override。
|
|
52
|
+
|
|
53
|
+
> 備註:目前 OpenCode plugin API 可註冊 runtime hooks / tools,但不會在載入時直接改寫 `opencode.json`;因此這個模組同時扮演 plugin 與 config override generator。
|
|
54
|
+
|
|
55
|
+
## 何時需要 Plugin
|
|
56
|
+
|
|
57
|
+
- 需要封裝自訂 tool 給多個專案共用
|
|
58
|
+
- 需要透過 MCP 串接外部 API
|
|
59
|
+
- 需要 hook opencode 的生命週期事件
|
|
60
|
+
|
|
61
|
+
## 開發參考
|
|
62
|
+
|
|
63
|
+
- [opencode 官方文件 — Plugins](https://opencode.ai/plugins)
|
|
64
|
+
- 範本可參考 `templates/plugin-template/`
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
|
|
5
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
6
|
+
const __dirname = path.dirname(__filename);
|
|
7
|
+
const CONFIG_PATH = path.resolve(__dirname, "..", "opencode.json");
|
|
8
|
+
|
|
9
|
+
const PROFILE_MAP = Object.freeze({
|
|
10
|
+
opencode: Object.freeze({
|
|
11
|
+
model: "opencode/big-pickle",
|
|
12
|
+
small_model: "opencode/deepseek-v4-flash-free",
|
|
13
|
+
heavy_model: "opencode/big-pickle",
|
|
14
|
+
}),
|
|
15
|
+
openai: Object.freeze({
|
|
16
|
+
model: "openai/gpt-5.4",
|
|
17
|
+
small_model: "openai/gpt-5.4-mini",
|
|
18
|
+
heavy_model: "openai/gpt-5.4",
|
|
19
|
+
}),
|
|
20
|
+
google: Object.freeze({
|
|
21
|
+
model: "google/gemini-3.1-pro-preview-customtools",
|
|
22
|
+
small_model: "google/gemini-3.5-flash",
|
|
23
|
+
heavy_model: "google/gemini-3.1-pro-preview-customtools",
|
|
24
|
+
}),
|
|
25
|
+
copilot: Object.freeze({
|
|
26
|
+
model: "copilot/gpt-5.4",
|
|
27
|
+
small_model: "copilot/gpt-5.4-mini",
|
|
28
|
+
heavy_model: "copilot/gpt-5.4",
|
|
29
|
+
}),
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const SUPPORTED_PROFILES = Object.keys(PROFILE_MAP);
|
|
33
|
+
const HEAVY_AGENTS = ["spec-writer", "code-reviewer", "team-lead", "architect"];
|
|
34
|
+
const ALL_OVERRIDDEN_AGENTS = [...HEAVY_AGENTS, "verifier"];
|
|
35
|
+
|
|
36
|
+
function normalizeProfileValue(value) {
|
|
37
|
+
return typeof value === "string" ? value.trim() : "";
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function assertKnownProfile(value) {
|
|
41
|
+
if (!SUPPORTED_PROFILES.includes(value)) {
|
|
42
|
+
throw new Error(
|
|
43
|
+
`Unknown provider profile "${value}". Must be one of: ${SUPPORTED_PROFILES.join(", ")}`,
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function pickProfile(options = {}) {
|
|
49
|
+
const optionProfile = normalizeProfileValue(options.profile);
|
|
50
|
+
const envProfile = normalizeProfileValue(process.env.OPENCODE_PROVIDER_PROFILE);
|
|
51
|
+
const activeProfile = optionProfile || envProfile || "opencode";
|
|
52
|
+
|
|
53
|
+
assertKnownProfile(activeProfile);
|
|
54
|
+
|
|
55
|
+
return activeProfile;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export default function resolveProfile(options = {}) {
|
|
59
|
+
const activeProfile = pickProfile(options);
|
|
60
|
+
const profile = PROFILE_MAP[activeProfile];
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
model: profile.model,
|
|
64
|
+
small_model: profile.small_model,
|
|
65
|
+
agent_overrides: {
|
|
66
|
+
"spec-writer": profile.heavy_model,
|
|
67
|
+
verifier: profile.small_model,
|
|
68
|
+
"code-reviewer": profile.heavy_model,
|
|
69
|
+
"team-lead": profile.heavy_model,
|
|
70
|
+
architect: profile.heavy_model,
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function buildProfileConfig(options = {}) {
|
|
76
|
+
const resolved = resolveProfile(options);
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
model: resolved.model,
|
|
80
|
+
small_model: resolved.small_model,
|
|
81
|
+
agent: Object.fromEntries(
|
|
82
|
+
ALL_OVERRIDDEN_AGENTS.map((name) => [name, { model: resolved.agent_overrides[name] }]),
|
|
83
|
+
),
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function isProviderProfilePlugin(entry) {
|
|
88
|
+
return typeof entry === "string" && entry.replaceAll("\\", "/").endsWith("provider-profile.mjs");
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function readPluginOptions(configPath = CONFIG_PATH) {
|
|
92
|
+
try {
|
|
93
|
+
const config = JSON.parse(fs.readFileSync(configPath, "utf8"));
|
|
94
|
+
const plugins = Array.isArray(config.plugin) ? config.plugin : [];
|
|
95
|
+
|
|
96
|
+
for (const plugin of plugins) {
|
|
97
|
+
if (Array.isArray(plugin) && plugin.length === 2 && isProviderProfilePlugin(plugin[0])) {
|
|
98
|
+
return plugin[1] && typeof plugin[1] === "object" ? plugin[1] : {};
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
} catch {
|
|
102
|
+
return {};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return {};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* ProviderProfilePlugin — runtime hook placeholder (no-op).
|
|
110
|
+
*
|
|
111
|
+
* This is a no-op runtime hook for opencode's plugin system.
|
|
112
|
+
* The actual model-profile switching happens outside the runtime hook:
|
|
113
|
+
*
|
|
114
|
+
* 1) `bin/moc` (the shell launcher) or direct invocation sets
|
|
115
|
+
* `OPENCODE_CONFIG_CONTENT` by running this module directly:
|
|
116
|
+
* `node plugins/provider-profile.mjs`
|
|
117
|
+
*
|
|
118
|
+
* 2) The direct-execution path at the bottom of this file generates
|
|
119
|
+
* the JSON config override fragment that opencode merges at startup.
|
|
120
|
+
*
|
|
121
|
+
* This function exists so the module is loadable as an opencode plugin,
|
|
122
|
+
* but no runtime transformation is needed because the config override is
|
|
123
|
+
* already applied via `OPENCODE_CONFIG_CONTENT` at process launch.
|
|
124
|
+
*
|
|
125
|
+
* @returns {object} Empty object — no runtime hook behavior.
|
|
126
|
+
*/
|
|
127
|
+
export function ProviderProfilePlugin() {
|
|
128
|
+
return {};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function isDirectExecution() {
|
|
132
|
+
const scriptPath = process.argv[1];
|
|
133
|
+
return scriptPath ? path.resolve(scriptPath) === __filename : false;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (isDirectExecution()) {
|
|
137
|
+
const options = readPluginOptions();
|
|
138
|
+
process.stdout.write(`${JSON.stringify(buildProfileConfig(options))}\n`);
|
|
139
|
+
}
|
package/scripts/postinstall.js
CHANGED
|
@@ -1,182 +1,202 @@
|
|
|
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
|
|
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
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
fs.
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
const
|
|
105
|
-
const
|
|
106
|
-
const
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
const
|
|
130
|
-
const
|
|
131
|
-
const
|
|
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
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
if (
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
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/, plugins/, 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 PLUGINS_SRC = path.join(PKG_DIR, "plugins");
|
|
28
|
+
const CONFIG_SRC = path.join(PKG_DIR, "opencode.json");
|
|
29
|
+
|
|
30
|
+
// ─── Detect project root ────────────────────────────────────────────────
|
|
31
|
+
//
|
|
32
|
+
// During npm postinstall, `process.cwd()` is typically the package root
|
|
33
|
+
// (node_modules/my-opencode/), but behavior varies by npm version.
|
|
34
|
+
// We try multiple strategies to find the parent project root.
|
|
35
|
+
|
|
36
|
+
function hasPackageJson(dir) {
|
|
37
|
+
try {
|
|
38
|
+
const pkgPath = path.join(dir, "package.json");
|
|
39
|
+
if (!fs.existsSync(pkgPath)) return false;
|
|
40
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
|
41
|
+
return pkg.name !== "my-opencode";
|
|
42
|
+
} catch {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function findProjectRoot() {
|
|
48
|
+
// Strategy 1: process.cwd() is the project root (npm v6 behavior)
|
|
49
|
+
let candidate = path.resolve(process.cwd());
|
|
50
|
+
if (hasPackageJson(candidate)) return candidate;
|
|
51
|
+
|
|
52
|
+
// Strategy 2: process.cwd() is node_modules/my-opencode/ (npm v7+)
|
|
53
|
+
candidate = path.resolve(process.cwd(), "..", "..");
|
|
54
|
+
if (hasPackageJson(candidate)) return candidate;
|
|
55
|
+
|
|
56
|
+
// Strategy 3: __dirname is scripts/, go up 3 levels
|
|
57
|
+
candidate = path.resolve(__dirname, "..", "..", "..");
|
|
58
|
+
if (hasPackageJson(candidate)) return candidate;
|
|
59
|
+
|
|
60
|
+
// Strategy 4: Walk up from __dirname until we find a project's package.json
|
|
61
|
+
candidate = path.resolve(__dirname);
|
|
62
|
+
while (candidate !== path.parse(candidate).root) {
|
|
63
|
+
const parent = path.resolve(candidate, "..");
|
|
64
|
+
if (hasPackageJson(parent)) return parent;
|
|
65
|
+
candidate = parent;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// ─── File utilities ─────────────────────────────────────────────────────
|
|
72
|
+
|
|
73
|
+
function copyDirSync(src, dst) {
|
|
74
|
+
let count = 0;
|
|
75
|
+
fs.mkdirSync(dst, { recursive: true });
|
|
76
|
+
const entries = fs.readdirSync(src, { withFileTypes: true });
|
|
77
|
+
for (const entry of entries) {
|
|
78
|
+
const srcPath = path.join(src, entry.name);
|
|
79
|
+
const dstPath = path.join(dst, entry.name);
|
|
80
|
+
if (entry.isDirectory()) {
|
|
81
|
+
count += copyDirSync(srcPath, dstPath);
|
|
82
|
+
} else if (entry.isFile()) {
|
|
83
|
+
if (!fs.existsSync(dstPath)) {
|
|
84
|
+
fs.copyFileSync(srcPath, dstPath);
|
|
85
|
+
count++;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return count;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function copyFileIfNotExists(src, dst) {
|
|
93
|
+
if (!fs.existsSync(dst)) {
|
|
94
|
+
fs.mkdirSync(path.dirname(dst), { recursive: true });
|
|
95
|
+
fs.copyFileSync(src, dst);
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// ─── Main ───────────────────────────────────────────────────────────────
|
|
102
|
+
|
|
103
|
+
function main() {
|
|
104
|
+
const INDENT = " ";
|
|
105
|
+
const CYAN = "\x1b[36m";
|
|
106
|
+
const GREEN = "\x1b[32m";
|
|
107
|
+
const YELLOW = "\x1b[33m";
|
|
108
|
+
const RESET = "\x1b[0m";
|
|
109
|
+
|
|
110
|
+
function header(text) {
|
|
111
|
+
console.log(`\n${CYAN}━━━ ${text} ━━━${RESET}\n`);
|
|
112
|
+
}
|
|
113
|
+
function success(text) {
|
|
114
|
+
console.log(`${GREEN}✓${RESET} ${text}`);
|
|
115
|
+
}
|
|
116
|
+
function warn(text) {
|
|
117
|
+
console.log(`${YELLOW}⚠${RESET} ${text}`);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const projectRoot = findProjectRoot();
|
|
121
|
+
if (!projectRoot) {
|
|
122
|
+
warn(
|
|
123
|
+
"Could not detect project root for my-opencode postinstall.\n" +
|
|
124
|
+
`${INDENT}Run "npx my-opencode init" to set up manually.`,
|
|
125
|
+
);
|
|
126
|
+
process.exit(0);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const targetDir = path.join(projectRoot, ".opencode");
|
|
130
|
+
const targetSkills = path.join(targetDir, "skills");
|
|
131
|
+
const targetAgents = path.join(targetDir, "agents");
|
|
132
|
+
const targetPlugins = path.join(targetDir, "plugins");
|
|
133
|
+
const targetConfig = path.join(targetDir, "opencode.json");
|
|
134
|
+
|
|
135
|
+
// ── Create .opencode/ ──────────────────────────────────────────────────
|
|
136
|
+
if (!fs.existsSync(targetDir)) {
|
|
137
|
+
fs.mkdirSync(targetDir, { recursive: true });
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// ── Copy skills ────────────────────────────────────────────────────────
|
|
141
|
+
let skillCount = 0;
|
|
142
|
+
if (fs.existsSync(SKILLS_SRC)) {
|
|
143
|
+
const skills = fs
|
|
144
|
+
.readdirSync(SKILLS_SRC, { withFileTypes: true })
|
|
145
|
+
.filter((d) => d.isDirectory())
|
|
146
|
+
.map((d) => d.name);
|
|
147
|
+
|
|
148
|
+
for (const s of skills) {
|
|
149
|
+
const dst = path.join(targetSkills, s);
|
|
150
|
+
if (!fs.existsSync(dst)) {
|
|
151
|
+
copyDirSync(path.join(SKILLS_SRC, s), dst);
|
|
152
|
+
skillCount++;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// ── Copy agents ────────────────────────────────────────────────────────
|
|
158
|
+
let agentCount = 0;
|
|
159
|
+
if (fs.existsSync(AGENTS_SRC)) {
|
|
160
|
+
const agents = fs
|
|
161
|
+
.readdirSync(AGENTS_SRC, { withFileTypes: true })
|
|
162
|
+
.filter((d) => d.isFile() && d.name.endsWith(".md"))
|
|
163
|
+
.map((d) => d.name);
|
|
164
|
+
|
|
165
|
+
for (const a of agents) {
|
|
166
|
+
const dst = path.join(targetAgents, a);
|
|
167
|
+
if (copyFileIfNotExists(path.join(AGENTS_SRC, a), dst)) {
|
|
168
|
+
agentCount++;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// ── Copy plugins ───────────────────────────────────────────────────────
|
|
174
|
+
let pluginCount = 0;
|
|
175
|
+
if (fs.existsSync(PLUGINS_SRC)) {
|
|
176
|
+
fs.mkdirSync(targetPlugins, { recursive: true });
|
|
177
|
+
const plugins = fs
|
|
178
|
+
.readdirSync(PLUGINS_SRC, { withFileTypes: true })
|
|
179
|
+
.filter((d) => d.isFile() && d.name.endsWith(".mjs"))
|
|
180
|
+
.map((d) => d.name);
|
|
181
|
+
|
|
182
|
+
for (const plugin of plugins) {
|
|
183
|
+
const dst = path.join(targetPlugins, plugin);
|
|
184
|
+
if (copyFileIfNotExists(path.join(PLUGINS_SRC, plugin), dst)) {
|
|
185
|
+
pluginCount++;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// ── Copy opencode.json ────────────────────────────────────────────────
|
|
191
|
+
copyFileIfNotExists(CONFIG_SRC, targetConfig);
|
|
192
|
+
|
|
193
|
+
// Suppress output if nothing changed (quiet idempotency)
|
|
194
|
+
if (skillCount === 0 && agentCount === 0 && pluginCount === 0) return;
|
|
195
|
+
|
|
196
|
+
header("my-opencode: installed to .opencode/");
|
|
197
|
+
if (skillCount > 0) success(`Skills: ${skillCount}`);
|
|
198
|
+
if (agentCount > 0) success(`Agents: ${agentCount}`);
|
|
199
|
+
if (pluginCount > 0) success(`Plugins: ${pluginCount}`);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
main();
|