my-opencode 1.3.4 → 3.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 (47) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +309 -271
  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 +206 -198
  16. package/bin/moc.js +9 -3
  17. package/opencode.json +240 -170
  18. package/package.json +53 -51
  19. package/plugins/README.md +74 -67
  20. package/plugins/provider-profile.mjs +238 -194
  21. package/scripts/postinstall.js +202 -202
  22. package/scripts/validate-role-flow.mjs +90 -0
  23. package/skills/adr/SKILL.md +91 -91
  24. package/skills/adr/references/templates.md +100 -100
  25. package/skills/adr/scripts/README.md +5 -5
  26. package/skills/design-evidence/SKILL.md +56 -0
  27. package/skills/dev-flow/SKILL.md +126 -188
  28. package/skills/dev-flow/references/code-phase.md +35 -72
  29. package/skills/dev-flow/references/contract-phase.md +66 -81
  30. package/skills/dev-flow/references/verify-phase.md +70 -129
  31. package/skills/dev-flow/scripts/README.md +3 -3
  32. package/skills/docs-gen/SKILL.md +162 -162
  33. package/skills/docs-gen/references/doc-styles.md +216 -216
  34. package/skills/docs-gen/scripts/README.md +5 -5
  35. package/skills/orchestrate/SKILL.md +63 -112
  36. package/skills/orchestrate/references/orchestration-patterns.md +49 -56
  37. package/skills/pr-review/SKILL.md +110 -110
  38. package/skills/pr-review/references/review-dimensions.md +117 -117
  39. package/skills/pr-review/references/security-checklist.md +122 -122
  40. package/skills/pr-review/scripts/README.md +5 -5
  41. package/skills/test-gen/SKILL.md +143 -143
  42. package/skills/test-gen/references/framework-detection.md +105 -105
  43. package/skills/test-gen/references/test-patterns.md +260 -260
  44. package/skills/test-gen/scripts/README.md +5 -5
  45. package/agents/executor.md +0 -30
  46. package/agents/fullstack-dev.md +0 -57
  47. package/agents/spec-writer.md +0 -37
package/plugins/README.md CHANGED
@@ -1,67 +1,74 @@
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-go/deepseek-v4-pro` | `opencode-go/deepseek-v4-flash` |
19
- | `openai` | `openai/gpt-5.6` | `openai/gpt-5.6-luna` |
20
- | `google` | `google/gemini-3.1-pro-preview-customtools` | `google/gemini-3.5-flash` |
21
- | `copilot` | `github-copilot/gpt-5.6-sol` | `github-copilot/gpt-5.6-luna` |
22
-
23
- > 💡 `openai` 與 `copilot` profile 的 `gpt-5.6-luna` 支援 reasoning effort 切換(high / medium / low,預設 `low`),
24
- > 在 opencode 內用 `variant_cycle` 快捷鍵循環切換。
25
-
26
- ### 用法
27
-
28
- 建議優先使用 `moc`:
29
-
30
- ```bash
31
- moc
32
- moc openai
33
- moc google --list-agents
34
- ```
35
-
36
- `moc` 會對四個已知 profile 快取 provider-profile 產生出的 JSON override,位置在 `.opencode/cache/provider-profile/`。快取是否有效由以下條件決定:
37
-
38
- - profile 名稱
39
- - `.opencode/plugins/provider-profile.mjs` 的 mtime
40
- - `.opencode/opencode.json` 的 mtime
41
-
42
- 若三者都沒變,`moc` 會直接重用快取,不再重新執行 `node .opencode/plugins/provider-profile.mjs`。
43
-
44
- 進階情境可直接設定環境變數:
45
-
46
- ```bash
47
- OPENCODE_CONFIG_CONTENT="$(node .opencode/plugins/provider-profile.mjs)" opencode
48
-
49
- OPENCODE_PROVIDER_PROFILE=openai \
50
- OPENCODE_CONFIG_CONTENT="$(node .opencode/plugins/provider-profile.mjs)" \
51
- opencode
52
- ```
53
-
54
- 直接執行模組時,會輸出可供 `OPENCODE_CONFIG_CONTENT` 使用的 JSON override。
55
-
56
- > 備註:目前 OpenCode plugin API 可註冊 runtime hooks / tools,但不會在載入時直接改寫 `opencode.json`;因此這個模組同時扮演 plugin 與 config override generator。
57
-
58
- ## 何時需要 Plugin
59
-
60
- - 需要封裝自訂 tool 給多個專案共用
61
- - 需要透過 MCP 串接外部 API
62
- - 需要 hook opencode 的生命週期事件
63
-
64
- ## 開發參考
65
-
66
- - [opencode 官方文件 — Plugins](https://opencode.ai/plugins)
67
- - 範本可參考 `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`、`copilot`、`anthropic`
13
+ - 讀取:`OPENCODE_PROVIDER_PROFILE`
14
+ - 可透過 plugin tuple options 覆寫:`["plugins/provider-profile.mjs", { "profile": "openai" }]`
15
+
16
+ | Profile | Primary / heavy | Small / verifier |
17
+ |---------|------------------|------------------|
18
+ | `opencode` | model:`opencode-go/gpt-6-luna#max`;heavy:`opencode-go/claude-haiku-5-5#max` | `opencode-go/deepseek-v4.1-flash#max` |
19
+ | `openai` | heavy:`openai/gpt-6.2-sol#medium`;model:`openai/gpt-6.2-sol#low` | `openai/gpt-6.1-terra#medium` |
20
+ | `copilot` | heavy:`github-copilot/gpt-6.1-sol#medium`;model:`github-copilot/claude-haiku-5.5#xhigh` | `github-copilot/gpt-6-luna#max` |
21
+ | `anthropic` | heavy:`anthropic/claude-sonnet-5-5#high`;default:`anthropic/claude-haiku-5-5#max` | `anthropic/claude-haiku-5-5#high` |
22
+
23
+ > 💡 `anthropic` profile 的 `#<variant>` 後綴為 opencode 的 effort 指定語法(`provider/model#variant`),
24
+ > 同一顆 haiku 可依 agent 使用不同 effort。variant 由 opencode 內建 model catalog 提供,因此此 profile 不產生 `provider` 覆寫區塊。
25
+
26
+ > 💡 `opencode` profile 全部使用 `max` effort(variant 皆由 opencode 內建 catalog 提供):model 用 `gpt-6-luna#max`,heavy 用 `claude-haiku-5-5#max`,small 用 `deepseek-v4.1-flash#max`。
27
+ > `deepseek-v4.1-flash` 另有 low / high / max 可在 opencode 內用 `variant_cycle` 快捷鍵循環切換。
28
+ >
29
+ > 💡 `openai` profile 以 `#variant` 指定 effort(heavy `gpt-6.2-sol#medium`、model `gpt-6.2-sol#low`、small `gpt-6.1-terra#medium`;variant 由 opencode 內建 catalog 提供)。
30
+
31
+ > 💡 `copilot` profile 以 `#variant` 指定 effort(heavy `gpt-6.1-sol#medium`、model `claude-haiku-5.5#xhigh`、small `gpt-6-luna#max`;variant 由 opencode 內建 catalog 提供)。
32
+
33
+ ### 用法
34
+
35
+ 建議優先使用 `moc`:
36
+
37
+ ```bash
38
+ moc
39
+ moc openai
40
+ moc anthropic --list-agents
41
+ ```
42
+
43
+ `moc` 會對四個已知 profile 快取 provider-profile 產生出的 JSON override,位置在 `.opencode/cache/provider-profile/`。快取是否有效由以下條件決定:
44
+
45
+ - profile 名稱
46
+ - `.opencode/plugins/provider-profile.mjs` 的 mtime
47
+ - `.opencode/opencode.json` 的 mtime
48
+
49
+ 若三者都沒變,`moc` 會直接重用快取,不再重新執行 `node .opencode/plugins/provider-profile.mjs`。
50
+
51
+ 進階情境可直接設定環境變數:
52
+
53
+ ```bash
54
+ OPENCODE_CONFIG_CONTENT="$(node .opencode/plugins/provider-profile.mjs)" opencode
55
+
56
+ OPENCODE_PROVIDER_PROFILE=openai \
57
+ OPENCODE_CONFIG_CONTENT="$(node .opencode/plugins/provider-profile.mjs)" \
58
+ opencode
59
+ ```
60
+
61
+ 直接執行模組時,會輸出可供 `OPENCODE_CONFIG_CONTENT` 使用的 JSON override。
62
+
63
+ > 備註:目前 OpenCode plugin API 可註冊 runtime hooks / tools,但不會在載入時直接改寫 `opencode.json`;因此這個模組同時扮演 plugin 與 config override generator。
64
+
65
+ ## 何時需要 Plugin
66
+
67
+ - 需要封裝自訂 tool 給多個專案共用
68
+ - 需要透過 MCP 串接外部 API
69
+ - 需要 hook opencode 的生命週期事件
70
+
71
+ ## 開發參考
72
+
73
+ - [opencode 官方文件 — Plugins](https://opencode.ai/plugins)
74
+ - 範本可參考 `templates/plugin-template/`
@@ -1,194 +1,238 @@
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-go/deepseek-v4-pro",
12
- small_model: "opencode-go/deepseek-v4-flash",
13
- heavy_model: "opencode-go/deepseek-v4-pro",
14
- }),
15
- openai: Object.freeze({
16
- model: "openai/gpt-5.6",
17
- small_model: "openai/gpt-5.6-luna",
18
- heavy_model: "openai/gpt-5.6",
19
- reasoning: Object.freeze({
20
- "openai/gpt-5.6-luna": Object.freeze({
21
- default_effort: "low",
22
- efforts: ["high", "medium", "low"],
23
- }),
24
- }),
25
- }),
26
- google: Object.freeze({
27
- model: "google/gemini-3.1-pro-preview-customtools",
28
- small_model: "google/gemini-3.5-flash",
29
- heavy_model: "google/gemini-3.1-pro-preview-customtools",
30
- }),
31
- copilot: Object.freeze({
32
- model: "github-copilot/gpt-5.6-sol",
33
- small_model: "github-copilot/gpt-5.6-luna",
34
- heavy_model: "github-copilot/gpt-5.6-sol",
35
- reasoning: Object.freeze({
36
- "github-copilot/gpt-5.6-luna": Object.freeze({
37
- default_effort: "low",
38
- efforts: ["high", "medium", "low"],
39
- }),
40
- }),
41
- }),
42
- });
43
-
44
- const SUPPORTED_PROFILES = Object.keys(PROFILE_MAP);
45
- const HEAVY_AGENTS = ["spec-writer", "code-reviewer", "team-lead", "architect"];
46
- const ALL_OVERRIDDEN_AGENTS = [...HEAVY_AGENTS, "verifier"];
47
-
48
- function normalizeProfileValue(value) {
49
- return typeof value === "string" ? value.trim() : "";
50
- }
51
-
52
- function assertKnownProfile(value) {
53
- if (!SUPPORTED_PROFILES.includes(value)) {
54
- throw new Error(
55
- `Unknown provider profile "${value}". Must be one of: ${SUPPORTED_PROFILES.join(", ")}`,
56
- );
57
- }
58
- }
59
-
60
- function pickProfile(options = {}) {
61
- const optionProfile = normalizeProfileValue(options.profile);
62
- const envProfile = normalizeProfileValue(process.env.OPENCODE_PROVIDER_PROFILE);
63
- const activeProfile = optionProfile || envProfile || "opencode";
64
-
65
- assertKnownProfile(activeProfile);
66
-
67
- return activeProfile;
68
- }
69
-
70
- export default function resolveProfile(options = {}) {
71
- const activeProfile = pickProfile(options);
72
- const profile = PROFILE_MAP[activeProfile];
73
-
74
- return {
75
- model: profile.model,
76
- small_model: profile.small_model,
77
- agent_overrides: {
78
- "spec-writer": profile.heavy_model,
79
- verifier: profile.small_model,
80
- "code-reviewer": profile.heavy_model,
81
- "team-lead": profile.heavy_model,
82
- architect: profile.heavy_model,
83
- },
84
- };
85
- }
86
-
87
- export function buildProfileConfig(options = {}) {
88
- const activeProfile = pickProfile(options);
89
- const profile = PROFILE_MAP[activeProfile];
90
- const resolved = resolveProfile(options);
91
- const provider = buildProviderOverrides(profile);
92
-
93
- return {
94
- model: resolved.model,
95
- small_model: resolved.small_model,
96
- ...(Object.keys(provider).length > 0 ? { provider } : {}),
97
- agent: Object.fromEntries(
98
- ALL_OVERRIDDEN_AGENTS.map((name) => [name, { model: resolved.agent_overrides[name] }]),
99
- ),
100
- };
101
- }
102
-
103
- /**
104
- * Build the `provider` config fragment for models that need reasoning-effort
105
- * variants (e.g. gpt-5.6-luna with high/medium/low effort switching).
106
- *
107
- * Output shape (merged into opencode config via OPENCODE_CONFIG_CONTENT):
108
- * provider.openai.models["gpt-5.6-luna"] = {
109
- * options: { reasoningEffort: <default_effort> },
110
- * variants: { high: { reasoningEffort: "high" }, ... },
111
- * }
112
- */
113
- function buildProviderOverrides(profile) {
114
- if (!profile.reasoning) return {};
115
-
116
- const provider = {};
117
- for (const [modelRef, cfg] of Object.entries(profile.reasoning)) {
118
- const [providerId, ...rest] = modelRef.split("/");
119
- const modelId = rest.join("/");
120
- if (!providerId || !modelId) continue;
121
-
122
- const variants = {};
123
- for (const effort of cfg.efforts) {
124
- variants[effort] = { reasoningEffort: effort };
125
- }
126
-
127
- const modelConfig = { variants };
128
- if (cfg.default_effort) {
129
- modelConfig.options = { reasoningEffort: cfg.default_effort };
130
- }
131
-
132
- provider[providerId] = {
133
- models: {
134
- [modelId]: modelConfig,
135
- },
136
- };
137
- }
138
-
139
- return provider;
140
- }
141
-
142
- function isProviderProfilePlugin(entry) {
143
- return typeof entry === "string" && entry.replaceAll("\\", "/").endsWith("provider-profile.mjs");
144
- }
145
-
146
- export function readPluginOptions(configPath = CONFIG_PATH) {
147
- try {
148
- const config = JSON.parse(fs.readFileSync(configPath, "utf8"));
149
- const plugins = Array.isArray(config.plugin) ? config.plugin : [];
150
-
151
- for (const plugin of plugins) {
152
- if (Array.isArray(plugin) && plugin.length === 2 && isProviderProfilePlugin(plugin[0])) {
153
- return plugin[1] && typeof plugin[1] === "object" ? plugin[1] : {};
154
- }
155
- }
156
- } catch {
157
- return {};
158
- }
159
-
160
- return {};
161
- }
162
-
163
- /**
164
- * ProviderProfilePlugin — runtime hook placeholder (no-op).
165
- *
166
- * This is a no-op runtime hook for opencode's plugin system.
167
- * The actual model-profile switching happens outside the runtime hook:
168
- *
169
- * 1) `bin/moc` (the shell launcher) or direct invocation sets
170
- * `OPENCODE_CONFIG_CONTENT` by running this module directly:
171
- * `node plugins/provider-profile.mjs`
172
- *
173
- * 2) The direct-execution path at the bottom of this file generates
174
- * the JSON config override fragment that opencode merges at startup.
175
- *
176
- * This function exists so the module is loadable as an opencode plugin,
177
- * but no runtime transformation is needed because the config override is
178
- * already applied via `OPENCODE_CONFIG_CONTENT` at process launch.
179
- *
180
- * @returns {object} Empty object — no runtime hook behavior.
181
- */
182
- export function ProviderProfilePlugin() {
183
- return {};
184
- }
185
-
186
- function isDirectExecution() {
187
- const scriptPath = process.argv[1];
188
- return scriptPath ? path.resolve(scriptPath) === __filename : false;
189
- }
190
-
191
- if (isDirectExecution()) {
192
- const options = readPluginOptions();
193
- process.stdout.write(`${JSON.stringify(buildProfileConfig(options))}\n`);
194
- }
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-go(全部 max effort):
11
+ // model (預設 implementation agents) → gpt-6-luna max
12
+ // heavy (SA/SD/reviewer/team-lead/architect) → claude-haiku-5-5 max
13
+ // small (verifier / title) → deepseek-v4.1-flash max
14
+ opencode: Object.freeze({
15
+ model: "opencode-go/gpt-6-luna",
16
+ model_variant: "max",
17
+ small_model: "opencode-go/deepseek-v4.1-flash",
18
+ small_variant: "max",
19
+ heavy_model: "opencode-go/claude-haiku-5-5",
20
+ heavy_variant: "max",
21
+ reasoning: Object.freeze({
22
+ "opencode-go/deepseek-v4.1-flash": Object.freeze({
23
+ default_effort: "max",
24
+ efforts: ["low", "high", "max"],
25
+ }),
26
+ }),
27
+ }),
28
+ // OpenAI 系列:effort 透過 `provider/model#variant` 指定(opencode 內建 variant,不需 provider 覆寫)。
29
+ // heavy (SA/SD/reviewer/team-lead/architect) → gpt-6.2-sol medium (最高)
30
+ // model (預設 implementation agents) → gpt-6.2-sol low (其次)
31
+ // small (verifier / title) → gpt-6.1-terra medium(最低)
32
+ openai: Object.freeze({
33
+ model: "openai/gpt-6.2-sol",
34
+ model_variant: "low",
35
+ small_model: "openai/gpt-6.1-terra",
36
+ small_variant: "medium",
37
+ heavy_model: "openai/gpt-6.2-sol",
38
+ heavy_variant: "medium",
39
+ }),
40
+ // GitHub Copilot:effort 透過 `provider/model#variant` 指定(opencode 內建 variant,不需 provider 覆寫)。
41
+ // heavy (SA/SD/reviewer/team-lead/architect) → gpt-6.1-sol medium (最高)
42
+ // model (預設 implementation agents) → claude-haiku-5.5 xhigh(其次)
43
+ // small (verifier / title) → gpt-6-luna max (最低)
44
+ copilot: Object.freeze({
45
+ model: "github-copilot/claude-haiku-5.5",
46
+ model_variant: "xhigh",
47
+ small_model: "github-copilot/gpt-6-luna",
48
+ small_variant: "max",
49
+ heavy_model: "github-copilot/gpt-6.1-sol",
50
+ heavy_variant: "medium",
51
+ }),
52
+ // Anthropic 系列:effort 透過 `provider/model#variant` 指定(opencode 內建 variant,不需 provider 覆寫)。
53
+ // heavy (SA/SD/reviewer/team-lead/architect) → sonnet-5-5 high (最高)
54
+ // model (預設 implementation agents) → haiku-5-5 max (其次)
55
+ // small (verifier / title) → haiku-5-5 high (最低)
56
+ anthropic: Object.freeze({
57
+ model: "anthropic/claude-haiku-5-5",
58
+ model_variant: "max",
59
+ small_model: "anthropic/claude-haiku-5-5",
60
+ small_variant: "high",
61
+ heavy_model: "anthropic/claude-sonnet-5-5",
62
+ heavy_variant: "high",
63
+ }),
64
+ });
65
+
66
+ const SUPPORTED_PROFILES = Object.keys(PROFILE_MAP);
67
+ const HEAVY_AGENTS = [
68
+ "design-evidence",
69
+ "business-analyst",
70
+ "system-designer",
71
+ "code-reviewer",
72
+ "team-lead",
73
+ "architect",
74
+ ];
75
+ const ALL_OVERRIDDEN_AGENTS = [...HEAVY_AGENTS, "verifier"];
76
+
77
+ function normalizeProfileValue(value) {
78
+ return typeof value === "string" ? value.trim() : "";
79
+ }
80
+
81
+ function assertKnownProfile(value) {
82
+ if (!SUPPORTED_PROFILES.includes(value)) {
83
+ throw new Error(
84
+ `Unknown provider profile "${value}". Must be one of: ${SUPPORTED_PROFILES.join(", ")}`,
85
+ );
86
+ }
87
+ }
88
+
89
+ function pickProfile(options = {}) {
90
+ const optionProfile = normalizeProfileValue(options.profile);
91
+ const envProfile = normalizeProfileValue(process.env.OPENCODE_PROVIDER_PROFILE);
92
+ const activeProfile = optionProfile || envProfile || "opencode";
93
+
94
+ assertKnownProfile(activeProfile);
95
+
96
+ return activeProfile;
97
+ }
98
+
99
+ /**
100
+ * Append an optional reasoning variant to a model ref using opencode's
101
+ * `provider/model#variant` syntax (e.g. `anthropic/claude-haiku-5-5#max`).
102
+ */
103
+ function withVariant(modelRef, variant) {
104
+ return variant ? `${modelRef}#${variant}` : modelRef;
105
+ }
106
+
107
+ export default function resolveProfile(options = {}) {
108
+ const activeProfile = pickProfile(options);
109
+ const profile = PROFILE_MAP[activeProfile];
110
+
111
+ const model = withVariant(profile.model, profile.model_variant);
112
+ const smallModel = withVariant(profile.small_model, profile.small_variant);
113
+ const heavyModel = withVariant(profile.heavy_model, profile.heavy_variant);
114
+
115
+ return {
116
+ model,
117
+ small_model: smallModel,
118
+ agent_overrides: {
119
+ "design-evidence": heavyModel,
120
+ "business-analyst": heavyModel,
121
+ "system-designer": heavyModel,
122
+ verifier: smallModel,
123
+ "code-reviewer": heavyModel,
124
+ "team-lead": heavyModel,
125
+ architect: heavyModel,
126
+ },
127
+ };
128
+ }
129
+
130
+ export function buildProfileConfig(options = {}) {
131
+ const activeProfile = pickProfile(options);
132
+ const profile = PROFILE_MAP[activeProfile];
133
+ const resolved = resolveProfile(options);
134
+ const provider = buildProviderOverrides(profile);
135
+
136
+ return {
137
+ model: resolved.model,
138
+ small_model: resolved.small_model,
139
+ ...(Object.keys(provider).length > 0 ? { provider } : {}),
140
+ agent: Object.fromEntries(
141
+ ALL_OVERRIDDEN_AGENTS.map((name) => [name, { model: resolved.agent_overrides[name] }]),
142
+ ),
143
+ };
144
+ }
145
+
146
+ /**
147
+ * Build the `provider` config fragment for models that need reasoning-effort
148
+ * variants (e.g. gpt-5.6-luna with high/medium/low effort switching, or
149
+ * deepseek-v4.1-flash with low/high/max effort switching).
150
+ *
151
+ * Output shape (merged into opencode config via OPENCODE_CONFIG_CONTENT):
152
+ * provider.openai.models["gpt-5.6-luna"] = {
153
+ * options: { reasoningEffort: <default_effort> },
154
+ * variants: { high: { reasoningEffort: "high" }, ... },
155
+ * }
156
+ */
157
+ function buildProviderOverrides(profile) {
158
+ if (!profile.reasoning) return {};
159
+
160
+ const provider = {};
161
+ for (const [modelRef, cfg] of Object.entries(profile.reasoning)) {
162
+ const [providerId, ...rest] = modelRef.split("/");
163
+ const modelId = rest.join("/");
164
+ if (!providerId || !modelId) continue;
165
+
166
+ const variants = {};
167
+ for (const effort of cfg.efforts) {
168
+ variants[effort] = { reasoningEffort: effort };
169
+ }
170
+
171
+ const modelConfig = { variants };
172
+ if (cfg.default_effort) {
173
+ modelConfig.options = { reasoningEffort: cfg.default_effort };
174
+ }
175
+
176
+ provider[providerId] = {
177
+ models: {
178
+ [modelId]: modelConfig,
179
+ },
180
+ };
181
+ }
182
+
183
+ return provider;
184
+ }
185
+
186
+ function isProviderProfilePlugin(entry) {
187
+ return typeof entry === "string" && entry.replaceAll("\\", "/").endsWith("provider-profile.mjs");
188
+ }
189
+
190
+ export function readPluginOptions(configPath = CONFIG_PATH) {
191
+ try {
192
+ const config = JSON.parse(fs.readFileSync(configPath, "utf8"));
193
+ const plugins = Array.isArray(config.plugin) ? config.plugin : [];
194
+
195
+ for (const plugin of plugins) {
196
+ if (Array.isArray(plugin) && plugin.length === 2 && isProviderProfilePlugin(plugin[0])) {
197
+ return plugin[1] && typeof plugin[1] === "object" ? plugin[1] : {};
198
+ }
199
+ }
200
+ } catch {
201
+ return {};
202
+ }
203
+
204
+ return {};
205
+ }
206
+
207
+ /**
208
+ * ProviderProfilePlugin — runtime hook placeholder (no-op).
209
+ *
210
+ * This is a no-op runtime hook for opencode's plugin system.
211
+ * The actual model-profile switching happens outside the runtime hook:
212
+ *
213
+ * 1) `bin/moc` (the shell launcher) or direct invocation sets
214
+ * `OPENCODE_CONFIG_CONTENT` by running this module directly:
215
+ * `node plugins/provider-profile.mjs`
216
+ *
217
+ * 2) The direct-execution path at the bottom of this file generates
218
+ * the JSON config override fragment that opencode merges at startup.
219
+ *
220
+ * This function exists so the module is loadable as an opencode plugin,
221
+ * but no runtime transformation is needed because the config override is
222
+ * already applied via `OPENCODE_CONFIG_CONTENT` at process launch.
223
+ *
224
+ * @returns {object} Empty object — no runtime hook behavior.
225
+ */
226
+ export function ProviderProfilePlugin() {
227
+ return {};
228
+ }
229
+
230
+ function isDirectExecution() {
231
+ const scriptPath = process.argv[1];
232
+ return scriptPath ? path.resolve(scriptPath) === __filename : false;
233
+ }
234
+
235
+ if (isDirectExecution()) {
236
+ const options = readPluginOptions();
237
+ process.stdout.write(`${JSON.stringify(buildProfileConfig(options))}\n`);
238
+ }