my-opencode 1.3.0 → 1.3.1
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 +253 -248
- 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 +340 -340
- package/bin/moc +198 -198
- package/bin/moc.js +350 -0
- package/opencode.json +170 -170
- package/package.json +50 -50
- package/plugins/README.md +64 -64
- package/plugins/provider-profile.mjs +139 -139
- package/scripts/postinstall.js +202 -202
- 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/package.json
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "my-opencode",
|
|
3
|
-
"version": "1.3.
|
|
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/jjyung/my-opencode#readme",
|
|
19
|
-
"bugs": {
|
|
20
|
-
"url": "https://github.com/jjyung/my-opencode/issues"
|
|
21
|
-
},
|
|
22
|
-
"license": "MIT",
|
|
23
|
-
"author": "cfh00902455",
|
|
24
|
-
"repository": {
|
|
25
|
-
"type": "git",
|
|
26
|
-
"url": "git+https://github.com/jjyung/my-opencode.git"
|
|
27
|
-
},
|
|
28
|
-
"scripts": {
|
|
29
|
-
"postinstall": "node scripts/postinstall.js"
|
|
30
|
-
},
|
|
31
|
-
"bin": {
|
|
32
|
-
"my-opencode": "bin/cli.js",
|
|
33
|
-
"moc": "bin/moc"
|
|
34
|
-
},
|
|
35
|
-
"files": [
|
|
36
|
-
"bin/",
|
|
37
|
-
"scripts/",
|
|
38
|
-
"skills/",
|
|
39
|
-
"agents/",
|
|
40
|
-
"plugins/",
|
|
41
|
-
"opencode.json"
|
|
42
|
-
],
|
|
43
|
-
"engines": {
|
|
44
|
-
"node": ">=18.0.0"
|
|
45
|
-
},
|
|
46
|
-
"type": "module",
|
|
47
|
-
"publishConfig": {
|
|
48
|
-
"access": "public"
|
|
49
|
-
}
|
|
50
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "my-opencode",
|
|
3
|
+
"version": "1.3.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/jjyung/my-opencode#readme",
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/jjyung/my-opencode/issues"
|
|
21
|
+
},
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"author": "cfh00902455",
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "git+https://github.com/jjyung/my-opencode.git"
|
|
27
|
+
},
|
|
28
|
+
"scripts": {
|
|
29
|
+
"postinstall": "node scripts/postinstall.js"
|
|
30
|
+
},
|
|
31
|
+
"bin": {
|
|
32
|
+
"my-opencode": "bin/cli.js",
|
|
33
|
+
"moc": "bin/moc.js"
|
|
34
|
+
},
|
|
35
|
+
"files": [
|
|
36
|
+
"bin/",
|
|
37
|
+
"scripts/",
|
|
38
|
+
"skills/",
|
|
39
|
+
"agents/",
|
|
40
|
+
"plugins/",
|
|
41
|
+
"opencode.json"
|
|
42
|
+
],
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": ">=18.0.0"
|
|
45
|
+
},
|
|
46
|
+
"type": "module",
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public"
|
|
49
|
+
}
|
|
50
|
+
}
|
package/plugins/README.md
CHANGED
|
@@ -1,64 +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/`
|
|
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/`
|
|
@@ -1,139 +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
|
-
}
|
|
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
|
+
}
|