opencode-morphllm 0.0.10 → 0.1.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/DEVELOPMENT.md +32 -0
- package/README.md +46 -35
- package/dist/index.js +3 -0
- package/dist/morph/system-transform.d.ts +5 -0
- package/dist/morph/system-transform.js +8 -0
- package/dist/shared/config.d.ts +7 -0
- package/dist/shared/config.js +16 -1
- package/package.json +1 -1
package/DEVELOPMENT.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# Development
|
|
2
|
+
|
|
3
|
+
To work on the plugin locally:
|
|
4
|
+
|
|
5
|
+
1. Clone the repository
|
|
6
|
+
2. Point OpenCode to your local copy in `~/.config/opencode/opencode.json`:
|
|
7
|
+
|
|
8
|
+
```json
|
|
9
|
+
{
|
|
10
|
+
"plugins": ["/path/to/morph-opencode-plugin/"]
|
|
11
|
+
}
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
3. Changes are immediately reflected when you run OpenCode
|
|
15
|
+
|
|
16
|
+
## Scripts
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
# Build
|
|
20
|
+
bun run build
|
|
21
|
+
|
|
22
|
+
# Test
|
|
23
|
+
bun test
|
|
24
|
+
|
|
25
|
+
# Format
|
|
26
|
+
bun run format
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Developer Notes
|
|
30
|
+
|
|
31
|
+
- The config logic now exposes a small helper function (computeRouterEnabled) that encapsulates the decision logic for whether the router is enabled. This is exported primarily to make the behavior easily testable and to avoid brittle module-cache workarounds in tests.
|
|
32
|
+
- If you change how config values are consumed, prefer adding unit tests that call computeRouterEnabled with a trimmed test fixture rather than trying to reload module-level constants.
|
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# MorphLLM OpenCode Plugin
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/opencode-morphllm)
|
|
4
4
|
[](https://www.npmjs.com/package/opencode-morphllm)
|
|
5
5
|
[](https://www.npmjs.com/package/opencode-morphllm)
|
|
6
6
|
|
|
@@ -40,7 +40,9 @@ Add the plugin to your OpenCode configuration at `~/.config/opencode/opencode.js
|
|
|
40
40
|
|
|
41
41
|
### 2. Configure MorphLLM
|
|
42
42
|
|
|
43
|
-
Create a configuration file at `~/.config/opencode/morph.json
|
|
43
|
+
Create a configuration file at `~/.config/opencode/morph.json` or for repo level configs, you can create the config at your repo root at `.opencode/morph.json`.
|
|
44
|
+
|
|
45
|
+
Example:
|
|
44
46
|
|
|
45
47
|
```json
|
|
46
48
|
{
|
|
@@ -67,14 +69,47 @@ Find available models at [models.dev](https://models.dev).
|
|
|
67
69
|
|
|
68
70
|
### Router Settings (inside `MORPH_ROUTER_CONFIGS`)
|
|
69
71
|
|
|
70
|
-
| Option | Description | Default
|
|
71
|
-
| ----------------------------------- | --------------------------------------------------------- |
|
|
72
|
-
| `MORPH_ROUTER_ENABLED` | Enable/disable the intelligent router | `true`
|
|
73
|
-
| `MORPH_MODEL_EASY` | Model for easy prompts (simple questions, formatting) |
|
|
74
|
-
| `MORPH_MODEL_MEDIUM` | Model for medium prompts (standard coding tasks) |
|
|
75
|
-
| `MORPH_MODEL_HARD` | Model for hard prompts (complex architecture, debugging) |
|
|
76
|
-
| `MORPH_MODEL_DEFAULT` | Fallback model when classification fails | `MORPH_MODEL_MEDIUM`
|
|
77
|
-
| `MORPH_ROUTER_PROMPT_CACHING_AWARE` | Stick to first model per session for caching optimization | `false`
|
|
72
|
+
| Option | Description | Default |
|
|
73
|
+
| ----------------------------------- | --------------------------------------------------------- | ------------------------------- |
|
|
74
|
+
| `MORPH_ROUTER_ENABLED` | Enable/disable the intelligent router | `true` |
|
|
75
|
+
| `MORPH_MODEL_EASY` | Model for easy prompts (simple questions, formatting) | `your currently selected model` |
|
|
76
|
+
| `MORPH_MODEL_MEDIUM` | Model for medium prompts (standard coding tasks) | `your currently selected model` |
|
|
77
|
+
| `MORPH_MODEL_HARD` | Model for hard prompts (complex architecture, debugging) | `your currently selected model` |
|
|
78
|
+
| `MORPH_MODEL_DEFAULT` | Fallback model when classification fails | `MORPH_MODEL_MEDIUM` |
|
|
79
|
+
| `MORPH_ROUTER_PROMPT_CACHING_AWARE` | Stick to first model per session for caching optimization | `false` |
|
|
80
|
+
|
|
81
|
+
> Note about router enablement
|
|
82
|
+
>
|
|
83
|
+
> - The router will be automatically disabled if none of the model slots (`MORPH_MODEL_EASY`, `MORPH_MODEL_MEDIUM`, `MORPH_MODEL_HARD`) are configured (i.e., all are empty strings). This prevents the router from being active when there are no target models configured. An explicit `MORPH_ROUTER_ENABLED: false` in your config will also disable the router even if models are present.
|
|
84
|
+
|
|
85
|
+
### System Message Customization
|
|
86
|
+
|
|
87
|
+
| Option | Description | Default |
|
|
88
|
+
| ---------------------- | ---------------------------------------------------------- | --------- |
|
|
89
|
+
| `MORPH_SYSTEM_MESSAGE` | Custom system message appended to OpenCode's system prompt | See below |
|
|
90
|
+
|
|
91
|
+
The `MORPH_SYSTEM_MESSAGE` setting allows you to customize or override the default system message that MorphLLM appends to OpenCode's system prompt. This message guides the AI on using Morph's MCP tools effectively.
|
|
92
|
+
|
|
93
|
+
**Default message:**
|
|
94
|
+
|
|
95
|
+
```
|
|
96
|
+
You **MUST** consider using morph_mcp. For editing files, consider using morph_mcp_edit_file. For searching the code base, consider using warpgrep_codebase_search
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
**When to customize:**
|
|
100
|
+
|
|
101
|
+
- You want to emphasize different tool preferences for your workflow
|
|
102
|
+
- You need to add project-specific conventions or guidelines
|
|
103
|
+
- You want to disable the default guidance entirely (set to empty string `""`)
|
|
104
|
+
|
|
105
|
+
**Example:**
|
|
106
|
+
|
|
107
|
+
```json
|
|
108
|
+
{
|
|
109
|
+
"MORPH_API_KEY": "your_morph_api_key_here",
|
|
110
|
+
"MORPH_SYSTEM_MESSAGE": "Your custom system message here"
|
|
111
|
+
}
|
|
112
|
+
```
|
|
78
113
|
|
|
79
114
|
### Model Format
|
|
80
115
|
|
|
@@ -137,31 +172,7 @@ When `MORPH_ROUTER_PROMPT_CACHING_AWARE` is enabled:
|
|
|
137
172
|
|
|
138
173
|
## Development
|
|
139
174
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
1. Clone the repository
|
|
143
|
-
2. Point OpenCode to your local copy in `~/.config/opencode/opencode.json`:
|
|
144
|
-
|
|
145
|
-
```json
|
|
146
|
-
{
|
|
147
|
-
"plugins": ["/path/to/morph-opencode-plugin/"]
|
|
148
|
-
}
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
3. Changes are immediately reflected when you run OpenCode
|
|
152
|
-
|
|
153
|
-
### Scripts
|
|
154
|
-
|
|
155
|
-
```bash
|
|
156
|
-
# Build
|
|
157
|
-
bun run build
|
|
158
|
-
|
|
159
|
-
# Test
|
|
160
|
-
bun test
|
|
161
|
-
|
|
162
|
-
# Format
|
|
163
|
-
bun run format
|
|
164
|
-
```
|
|
175
|
+
See [DEVELOPMENT.md](DEVELOPMENT.md) for setup instructions and development notes.
|
|
165
176
|
|
|
166
177
|
## Troubleshooting
|
|
167
178
|
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { createBuiltinMcps } from './morph/mcps';
|
|
2
2
|
import { createModelRouterHook } from './morph/router';
|
|
3
|
+
import { createSystemTransformHook } from './morph/system-transform';
|
|
3
4
|
const MorphOpenCodePlugin = async () => {
|
|
4
5
|
const builtinMcps = createBuiltinMcps();
|
|
6
|
+
const systemTransformHook = createSystemTransformHook();
|
|
5
7
|
const routerHook = createModelRouterHook();
|
|
6
8
|
return {
|
|
7
9
|
config: async (currentConfig) => {
|
|
@@ -10,6 +12,7 @@ const MorphOpenCodePlugin = async () => {
|
|
|
10
12
|
...builtinMcps,
|
|
11
13
|
};
|
|
12
14
|
},
|
|
15
|
+
...systemTransformHook,
|
|
13
16
|
...routerHook,
|
|
14
17
|
};
|
|
15
18
|
};
|
package/dist/shared/config.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ interface MorphRouterConfigs {
|
|
|
9
9
|
}
|
|
10
10
|
interface MorphConfig {
|
|
11
11
|
MORPH_API_KEY?: string;
|
|
12
|
+
MORPH_SYSTEM_MESSAGE?: string;
|
|
12
13
|
MORPH_ROUTER_CONFIGS?: MorphRouterConfigs;
|
|
13
14
|
MORPH_ROUTER_ENABLED?: boolean;
|
|
14
15
|
MORPH_ROUTER_PROMPT_CACHING_AWARE?: boolean;
|
|
@@ -24,6 +25,12 @@ export declare const MORPH_MODEL_EASY: string;
|
|
|
24
25
|
export declare const MORPH_MODEL_MEDIUM: string;
|
|
25
26
|
export declare const MORPH_MODEL_HARD: string;
|
|
26
27
|
export declare const MORPH_MODEL_DEFAULT: string;
|
|
28
|
+
/**
|
|
29
|
+
* Computes whether the router should be enabled based on config and model availability.
|
|
30
|
+
* Exported for testing purposes.
|
|
31
|
+
*/
|
|
32
|
+
export declare function computeRouterEnabled(routerConfigs: MorphRouterConfigs, config: MorphConfig): boolean;
|
|
27
33
|
export declare const MORPH_ROUTER_ENABLED: boolean;
|
|
28
34
|
export declare const MORPH_ROUTER_PROMPT_CACHING_AWARE: boolean;
|
|
35
|
+
export declare const MORPH_SYSTEM_MESSAGE: string;
|
|
29
36
|
export {};
|
package/dist/shared/config.js
CHANGED
|
@@ -74,7 +74,22 @@ export const MORPH_MODEL_HARD = routerConfigs.MORPH_MODEL_HARD || config.MORPH_M
|
|
|
74
74
|
export const MORPH_MODEL_DEFAULT = routerConfigs.MORPH_MODEL_DEFAULT ||
|
|
75
75
|
config.MORPH_MODEL_DEFAULT ||
|
|
76
76
|
MORPH_MODEL_MEDIUM;
|
|
77
|
-
|
|
77
|
+
/**
|
|
78
|
+
* Computes whether the router should be enabled based on config and model availability.
|
|
79
|
+
* Exported for testing purposes.
|
|
80
|
+
*/
|
|
81
|
+
export function computeRouterEnabled(routerConfigs, config) {
|
|
82
|
+
const easy = routerConfigs.MORPH_MODEL_EASY || config.MORPH_MODEL_EASY || '';
|
|
83
|
+
const medium = routerConfigs.MORPH_MODEL_MEDIUM || config.MORPH_MODEL_MEDIUM || '';
|
|
84
|
+
const hard = routerConfigs.MORPH_MODEL_HARD || config.MORPH_MODEL_HARD || '';
|
|
85
|
+
// Router should be disabled if all model values are empty strings
|
|
86
|
+
const allModelsEmpty = !easy && !medium && !hard;
|
|
87
|
+
return (!allModelsEmpty &&
|
|
88
|
+
(routerConfigs.MORPH_ROUTER_ENABLED ?? config.MORPH_ROUTER_ENABLED ?? true));
|
|
89
|
+
}
|
|
90
|
+
export const MORPH_ROUTER_ENABLED = computeRouterEnabled(routerConfigs, config);
|
|
78
91
|
export const MORPH_ROUTER_PROMPT_CACHING_AWARE = routerConfigs.MORPH_ROUTER_PROMPT_CACHING_AWARE ??
|
|
79
92
|
config.MORPH_ROUTER_PROMPT_CACHING_AWARE ??
|
|
80
93
|
false;
|
|
94
|
+
const DEFAULT_SYSTEM_MESSAGE = '\nYou **MUST** consider using morph_mcp. For editing files, consider using morph_mcp_edit_file. For searching the code base, consider using warpgrep_codebase_search';
|
|
95
|
+
export const MORPH_SYSTEM_MESSAGE = config.MORPH_SYSTEM_MESSAGE || DEFAULT_SYSTEM_MESSAGE;
|