@sveltejs/opencode 0.1.1 → 0.1.3
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/config.ts +22 -7
- package/index.ts +64 -2
- package/instructions/opencode-agents.md +1 -1
- package/package.json +1 -1
- package/skills/svelte-code-writer/SKILL.md +1 -1
package/config.ts
CHANGED
|
@@ -71,8 +71,15 @@ function get_config_paths() {
|
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
//
|
|
75
|
-
|
|
74
|
+
// Project-local: ./.opencode/svelte.json (cwd)
|
|
75
|
+
let project_path: string | null = null;
|
|
76
|
+
const project_config = join(process.cwd(), '.opencode', 'svelte.json');
|
|
77
|
+
if (existsSync(project_config)) {
|
|
78
|
+
project_path = project_config;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// Lowest priority first, highest priority last (project overrides global)
|
|
82
|
+
return [global_path, config_dir_path, project_path];
|
|
76
83
|
}
|
|
77
84
|
|
|
78
85
|
function load_config_file(config_path: string): ConfigLoadResult {
|
|
@@ -121,6 +128,9 @@ function merge_with_defaults(user_config: Partial<McpConfig>): McpConfig {
|
|
|
121
128
|
|
|
122
129
|
export function get_mcp_config(ctx: PluginInput) {
|
|
123
130
|
const config_paths = get_config_paths();
|
|
131
|
+
let merged: Partial<McpConfig> = {};
|
|
132
|
+
|
|
133
|
+
// Iterate from lowest to highest priority, merging as we go
|
|
124
134
|
for (const path of config_paths) {
|
|
125
135
|
if (path && existsSync(path)) {
|
|
126
136
|
const result = load_config_file(path);
|
|
@@ -129,23 +139,28 @@ export function get_mcp_config(ctx: PluginInput) {
|
|
|
129
139
|
ctx.client.tui.showToast({
|
|
130
140
|
body: {
|
|
131
141
|
title: 'Svelte: Invalid opencode plugin config',
|
|
132
|
-
message: `${result.parse_error}\
|
|
142
|
+
message: `${result.parse_error} (${path})\nSkipping this config file`,
|
|
133
143
|
variant: 'warning',
|
|
134
144
|
duration: 7000,
|
|
135
145
|
},
|
|
136
146
|
});
|
|
137
147
|
}, 7000);
|
|
138
|
-
|
|
148
|
+
continue;
|
|
139
149
|
}
|
|
140
150
|
const parsed = v.safeParse(config_schema, result.data);
|
|
141
151
|
if (parsed.success) {
|
|
142
|
-
|
|
152
|
+
merged = {
|
|
153
|
+
mcp: { ...merged.mcp, ...parsed.output.mcp },
|
|
154
|
+
subagent: { ...merged.subagent, ...parsed.output.subagent },
|
|
155
|
+
instructions: { ...merged.instructions, ...parsed.output.instructions },
|
|
156
|
+
skills: { ...merged.skills, ...parsed.output.skills },
|
|
157
|
+
};
|
|
143
158
|
} else {
|
|
144
159
|
setTimeout(() => {
|
|
145
160
|
ctx.client.tui.showToast({
|
|
146
161
|
body: {
|
|
147
162
|
title: 'Svelte: Invalid opencode plugin config',
|
|
148
|
-
message:
|
|
163
|
+
message: `Invalid config schema (${path})\nSkipping this config file`,
|
|
149
164
|
variant: 'warning',
|
|
150
165
|
duration: 7000,
|
|
151
166
|
},
|
|
@@ -155,5 +170,5 @@ export function get_mcp_config(ctx: PluginInput) {
|
|
|
155
170
|
}
|
|
156
171
|
}
|
|
157
172
|
|
|
158
|
-
return
|
|
173
|
+
return merge_with_defaults(merged);
|
|
159
174
|
}
|
package/index.ts
CHANGED
|
@@ -64,9 +64,71 @@ export const svelte_plugin: Plugin = async (ctx) => {
|
|
|
64
64
|
input.agent['svelte-file-editor'] = {
|
|
65
65
|
color: '#ff3e00',
|
|
66
66
|
mode: 'subagent',
|
|
67
|
-
prompt: `You are a
|
|
67
|
+
prompt: `You are a Svelte 5 expert responsible for writing, editing, and validating Svelte components and modules. You have access to the Svelte MCP server which provides documentation and code analysis tools. Always use the tools from the svelte MCP server to fetch documentation with \`get_documentation\` and validating the code with \`svelte_autofixer\`. If the autofixer returns any issue or suggestions try to solve them.
|
|
68
|
+
|
|
69
|
+
If the MCP tools are not available you can use the \`svelte-code-editor\` skill to learn how to use the \`@sveltejs/mcp\` cli to access the same tools.
|
|
70
|
+
|
|
71
|
+
If the skill is not available you can run \`npx @sveltejs/mcp@latest -y --help\` to learn how to use it.
|
|
72
|
+
|
|
73
|
+
## Available MCP Tools
|
|
74
|
+
|
|
75
|
+
### 1. list-sections
|
|
76
|
+
|
|
77
|
+
Lists all available Svelte 5 and SvelteKit documentation sections with titles and paths. Use this first to discover what documentation is available.
|
|
78
|
+
|
|
79
|
+
### 2. get-documentation
|
|
80
|
+
|
|
81
|
+
Retrieves full documentation for specified sections. Accepts a single section name or an array of section names. Use after \`list-sections\` to fetch relevant docs for the task at hand.
|
|
82
|
+
|
|
83
|
+
**Example sections:** \`$state\`, \`$derived\`, \`$effect\`, \`$props\`, \`$bindable\`, \`snippets\`, \`routing\`, \`load functions\`
|
|
84
|
+
|
|
85
|
+
### 3. svelte-autofixer
|
|
86
|
+
|
|
87
|
+
Analyzes Svelte code and returns suggestions to fix issues. Pass the component code directly to this tool. It will detect common mistakes like:
|
|
88
|
+
|
|
89
|
+
- Using \`$effect\` instead of \`$derived\` for computations
|
|
90
|
+
- Missing cleanup in effects
|
|
91
|
+
- Svelte 4 syntax (\`on:click\`, \`export let\`, \`<slot>\`)
|
|
92
|
+
- Missing keys in \`{#each}\` blocks
|
|
93
|
+
- And more
|
|
94
|
+
|
|
95
|
+
## Workflow
|
|
96
|
+
|
|
97
|
+
When invoked to work on a Svelte file:
|
|
98
|
+
|
|
99
|
+
### 1. Gather Context (if needed)
|
|
100
|
+
|
|
101
|
+
If you're uncertain about Svelte 5 syntax or patterns, use the MCP tools:
|
|
102
|
+
|
|
103
|
+
1. Call \`list-sections\` to see available documentation
|
|
104
|
+
2. Call \`get-documentation\` with relevant section names
|
|
105
|
+
|
|
106
|
+
### 2. Read the Target File
|
|
107
|
+
|
|
108
|
+
Read the file to understand the current implementation.
|
|
109
|
+
|
|
110
|
+
### 3. Make Changes
|
|
111
|
+
|
|
112
|
+
Apply edits following Svelte 5 best practices:
|
|
113
|
+
|
|
114
|
+
### 4. Validate Changes
|
|
115
|
+
|
|
116
|
+
After editing, ALWAYS call \`svelte-autofixer\` with the updated code to check for issues.
|
|
117
|
+
|
|
118
|
+
### 5. Fix Any Issues
|
|
119
|
+
|
|
120
|
+
If the autofixer reports problems, fix them and re-validate until no issues remain.
|
|
121
|
+
|
|
122
|
+
## Output Format
|
|
123
|
+
|
|
124
|
+
After completing your work, provide:
|
|
125
|
+
|
|
126
|
+
1. Summary of changes made
|
|
127
|
+
2. Any issues found and fixed by the autofixer
|
|
128
|
+
3. Recommendations for further improvements (if any)
|
|
129
|
+
`,
|
|
68
130
|
description:
|
|
69
|
-
'Specialized Svelte 5 code editor. MUST BE USED PROACTIVELY when creating, editing, or reviewing any .svelte file or .svelte.ts/.svelte.js module and MUST use the tools from the MCP server. Fetches relevant documentation and validates code using the Svelte MCP server tools.',
|
|
131
|
+
'Specialized Svelte 5 code editor. MUST BE USED PROACTIVELY when creating, editing, or reviewing any .svelte file or .svelte.ts/.svelte.js module and MUST use the tools from the MCP server or the `svelte-code-writer` skill if they are available. Fetches relevant documentation and validates code using the Svelte MCP server tools.',
|
|
70
132
|
permission: {
|
|
71
133
|
bash: 'ask',
|
|
72
134
|
edit: 'allow',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: svelte-code-writer
|
|
3
|
-
description: CLI tools for Svelte 5 documentation lookup and code analysis. MUST be used whenever creating or
|
|
3
|
+
description: CLI tools for Svelte 5 documentation lookup and code analysis. MUST be used whenever creating, editing or analyzing any Svelte component (.svelte) or Svelte module (.svelte.ts/.svelte.js). If possible, this skill should be executed within the svelte-file-editor agent for optimal results.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Svelte 5 Code Writer
|