chutes-plugin 0.1.1 → 0.1.2

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.
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import './cli/index.js';
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import './index.js';
package/dist/cli/index.js CHANGED
@@ -51,23 +51,15 @@ async function install(options) {
51
51
  input: process.stdin,
52
52
  output: process.stdout
53
53
  });
54
- try {
55
- installType = await new Promise((resolve, reject) => {
56
- rl.question("> ", (answer) => {
57
- rl.close();
58
- resolve(answer.trim());
59
- });
60
- setTimeout(() => {
61
- rl.close();
62
- reject(new Error("Timeout waiting for user input"));
63
- }, 1e4);
54
+ installType = await new Promise((resolve) => {
55
+ rl.question("> ", (answer) => {
56
+ rl.close();
57
+ resolve(answer.trim());
64
58
  });
65
- } catch {
66
- console.log(`No input detected, defaulting to npm installation...
67
- `);
68
- installType = "npm";
69
- }
59
+ });
70
60
  }
61
+ console.log(`Installing type: ${installType}
62
+ `);
71
63
  switch (installType) {
72
64
  case "1":
73
65
  case "project":
@@ -82,7 +74,7 @@ async function install(options) {
82
74
  await installNpm();
83
75
  break;
84
76
  default:
85
- console.log(`Invalid installation type: "${installType}"`);
77
+ console.log(`\u274C Invalid installation type: "${installType}"`);
86
78
  console.log("Please choose: 1 (project), 2 (global), or 3 (npm)");
87
79
  process.exit(1);
88
80
  }
@@ -93,142 +85,129 @@ async function installProject() {
93
85
  const pluginDir = path.join(opencodeDir, "plugin", "chutes-plugin");
94
86
  console.log(`Installing to project...
95
87
  `);
96
- try {
97
- if (!fs.existsSync(opencodeDir)) {
98
- fs.mkdirSync(opencodeDir, { recursive: true });
99
- }
100
- if (!fs.existsSync(path.join(opencodeDir, "plugin"))) {
101
- fs.mkdirSync(path.join(opencodeDir, "plugin"), { recursive: true });
102
- }
103
- fs.mkdirSync(pluginDir, { recursive: true });
104
- const distDir = path.join(__dirname, "..", "..", "dist");
105
- if (fs.existsSync(distDir)) {
106
- fs.cpSync(distDir, path.join(pluginDir, "dist"), { recursive: true });
107
- }
108
- const srcCliDir = path.join(__dirname, "..");
109
- if (fs.existsSync(srcCliDir)) {
110
- fs.cpSync(srcCliDir, path.join(pluginDir, "src"), { recursive: true });
111
- }
112
- const packageJsonPath = path.join(opencodeDir, "opencode.json");
113
- let config = {};
114
- if (fs.existsSync(packageJsonPath)) {
115
- const content = fs.readFileSync(packageJsonPath, "utf-8");
116
- try {
117
- config = JSON.parse(content);
118
- } catch {
119
- console.log("\u26A0\uFE0F Warning: Could not parse existing opencode.json, creating new one");
120
- config = {};
121
- }
122
- }
123
- const plugins = config.plugins || [];
124
- if (!Array.isArray(plugins)) {
125
- config.plugins = [];
126
- }
127
- const pluginPath = "./.opencode/plugin/chutes-plugin/dist/index.js";
128
- if (!plugins.includes(pluginPath)) {
129
- config.plugins.push(pluginPath);
88
+ if (!fs.existsSync(opencodeDir)) {
89
+ fs.mkdirSync(opencodeDir, { recursive: true });
90
+ }
91
+ if (!fs.existsSync(path.join(opencodeDir, "plugin"))) {
92
+ fs.mkdirSync(path.join(opencodeDir, "plugin"), { recursive: true });
93
+ }
94
+ fs.mkdirSync(pluginDir, { recursive: true });
95
+ const distDir = path.join(__dirname, "..", "..", "dist");
96
+ if (fs.existsSync(distDir)) {
97
+ fs.cpSync(distDir, path.join(pluginDir, "dist"), { recursive: true });
98
+ }
99
+ const srcCliDir = path.join(__dirname, "..");
100
+ if (fs.existsSync(srcCliDir)) {
101
+ fs.cpSync(srcCliDir, path.join(pluginDir, "src"), { recursive: true });
102
+ }
103
+ const packageJsonPath = path.join(opencodeDir, "opencode.json");
104
+ let config = {};
105
+ if (fs.existsSync(packageJsonPath)) {
106
+ const content = fs.readFileSync(packageJsonPath, "utf-8");
107
+ try {
108
+ config = JSON.parse(content);
109
+ } catch (e) {
110
+ console.error("\u274C Failed to parse opencode.json:", e);
111
+ process.exit(1);
130
112
  }
131
- fs.writeFileSync(packageJsonPath, JSON.stringify(config, null, 2));
132
- console.log("\u2705 Successfully installed to project!");
133
- console.log(`
113
+ }
114
+ config.plugins = config.plugins || [];
115
+ if (!Array.isArray(config.plugins)) {
116
+ config.plugins = [];
117
+ }
118
+ const pluginPath = "./.opencode/plugin/chutes-plugin/dist/index.js";
119
+ if (!config.plugins.includes(pluginPath)) {
120
+ config.plugins.push(pluginPath);
121
+ }
122
+ fs.writeFileSync(packageJsonPath, JSON.stringify(config, null, 2));
123
+ console.log("\u2705 Successfully installed to project!");
124
+ console.log(` Location: ${pluginDir}`);
125
+ console.log(`
134
126
  Next steps:`);
135
- console.log("1. Start OpenCode: opencode");
136
- console.log("2. Connect your Chutes token: /connect chutes");
137
- console.log(`3. Select a Chutes model from the dropdown
127
+ console.log("1. Start OpenCode: opencode");
128
+ console.log("2. Connect your Chutes token: /connect chutes");
129
+ console.log(`3. Select a Chutes model from the dropdown
138
130
  `);
139
- } catch (error) {
140
- console.log(`\u274C Error installing to project: ${error instanceof Error ? error.message : String(error)}`);
141
- process.exit(1);
142
- }
143
131
  }
144
132
  async function installGlobal() {
145
133
  const homeDir = process.env.HOME || process.env.USERPROFILE;
146
134
  if (!homeDir) {
147
- console.log("\u274C Error: Could not determine home directory");
135
+ console.error("\u274C Error: Could not determine home directory");
148
136
  process.exit(1);
149
137
  }
150
138
  const configDir = path.join(homeDir, ".config", "opencode");
151
139
  const pluginDir = path.join(configDir, "plugin", "chutes-plugin");
152
140
  console.log(`Installing globally...
153
141
  `);
154
- try {
155
- fs.mkdirSync(pluginDir, { recursive: true });
156
- const distDir = path.join(__dirname, "..", "..", "dist");
157
- if (fs.existsSync(distDir)) {
158
- fs.cpSync(distDir, path.join(pluginDir, "dist"), { recursive: true });
159
- }
160
- const srcCliDir = path.join(__dirname, "..");
161
- if (fs.existsSync(srcCliDir)) {
162
- fs.cpSync(srcCliDir, path.join(pluginDir, "src"), { recursive: true });
163
- }
164
- const configPath = path.join(configDir, "opencode.json");
165
- let config = {};
166
- if (fs.existsSync(configPath)) {
167
- const content = fs.readFileSync(configPath, "utf-8");
168
- try {
169
- config = JSON.parse(content);
170
- } catch {
171
- console.log("\u26A0\uFE0F Warning: Could not parse existing opencode.json, creating new one");
172
- config = {};
173
- }
174
- }
175
- config.plugins = config.plugins || [];
176
- if (!Array.isArray(config.plugins)) {
177
- config.plugins = [];
178
- }
179
- const pluginPath = `${configDir}/plugin/chutes-plugin/dist/index.js`;
180
- if (!config.plugins.includes(pluginPath)) {
181
- config.plugins.push(pluginPath);
142
+ fs.mkdirSync(pluginDir, { recursive: true });
143
+ const distDir = path.join(__dirname, "..", "..", "dist");
144
+ if (fs.existsSync(distDir)) {
145
+ fs.cpSync(distDir, path.join(pluginDir, "dist"), { recursive: true });
146
+ }
147
+ const srcCliDir = path.join(__dirname, "..");
148
+ if (fs.existsSync(srcCliDir)) {
149
+ fs.cpSync(srcCliDir, path.join(pluginDir, "src"), { recursive: true });
150
+ }
151
+ const configPath = path.join(configDir, "opencode.json");
152
+ let config = {};
153
+ if (fs.existsSync(configPath)) {
154
+ const content = fs.readFileSync(configPath, "utf-8");
155
+ try {
156
+ config = JSON.parse(content);
157
+ } catch (e) {
158
+ console.error("\u274C Failed to parse opencode.json:", e);
159
+ process.exit(1);
182
160
  }
183
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
184
- console.log("\u2705 Successfully installed globally!");
185
- console.log(`
161
+ }
162
+ config.plugins = config.plugins || [];
163
+ if (!Array.isArray(config.plugins)) {
164
+ config.plugins = [];
165
+ }
166
+ const pluginPath = `${configDir}/plugin/chutes-plugin/dist/index.js`;
167
+ if (!config.plugins.includes(pluginPath)) {
168
+ config.plugins.push(pluginPath);
169
+ }
170
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
171
+ console.log("\u2705 Successfully installed globally!");
172
+ console.log(` Location: ${pluginDir}`);
173
+ console.log(`
186
174
  Next steps:`);
187
- console.log("1. Start OpenCode: opencode");
188
- console.log("2. Connect your Chutes token: /connect chutes");
189
- console.log(`3. Select a Chutes model from the dropdown
175
+ console.log("1. Start OpenCode: opencode");
176
+ console.log("2. Connect your Chutes token: /connect chutes");
177
+ console.log(`3. Select a Chutes model from the dropdown
190
178
  `);
191
- } catch (error) {
192
- console.log(`\u274C Error installing globally: ${error instanceof Error ? error.message : String(error)}`);
193
- process.exit(1);
194
- }
195
179
  }
196
180
  async function installNpm() {
197
181
  const projectDir = process.cwd();
198
182
  const configPath = path.join(projectDir, "opencode.json");
199
183
  console.log(`Installing via npm...
200
184
  `);
201
- try {
202
- let config = {};
203
- if (fs.existsSync(configPath)) {
204
- const content = fs.readFileSync(configPath, "utf-8");
205
- try {
206
- config = JSON.parse(content);
207
- } catch {
208
- console.log("\u26A0\uFE0F Warning: Could not parse existing opencode.json, creating new one");
209
- config = {};
210
- }
211
- }
212
- config.plugins = config.plugins || [];
213
- if (!Array.isArray(config.plugins)) {
214
- config.plugins = [];
215
- }
216
- if (!config.plugins.includes("chutes-plugin")) {
217
- config.plugins.push("chutes-plugin");
185
+ let config = {};
186
+ if (fs.existsSync(configPath)) {
187
+ const content = fs.readFileSync(configPath, "utf-8");
188
+ try {
189
+ config = JSON.parse(content);
190
+ } catch (e) {
191
+ console.error("\u274C Failed to parse opencode.json:", e);
192
+ process.exit(1);
218
193
  }
219
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
220
- console.log('\u2705 Added "chutes-plugin" to opencode.json!');
221
- console.log(`
194
+ }
195
+ config.plugins = config.plugins || [];
196
+ if (!Array.isArray(config.plugins)) {
197
+ config.plugins = [];
198
+ }
199
+ if (!config.plugins.includes("chutes-plugin")) {
200
+ config.plugins.push("chutes-plugin");
201
+ }
202
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
203
+ console.log('\u2705 Added "chutes-plugin" to opencode.json!');
204
+ console.log(`
222
205
  Next steps:`);
223
- console.log("1. Start OpenCode: opencode");
224
- console.log("2. The plugin will be auto-installed on first run");
225
- console.log("3. Connect your Chutes token: /connect chutes");
226
- console.log(`4. Select a Chutes model from the dropdown
206
+ console.log("1. Start OpenCode: opencode");
207
+ console.log("2. The plugin will be auto-installed on first run");
208
+ console.log("3. Connect your Chutes token: /connect chutes");
209
+ console.log(`4. Select a Chutes model from the dropdown
227
210
  `);
228
- } catch (error) {
229
- console.log(`\u274C Error installing via npm: ${error instanceof Error ? error.message : String(error)}`);
230
- process.exit(1);
231
- }
232
211
  }
233
212
  var __dirname = "/home/mark182/code/chutes-plugin/src/cli";
234
213
  var init_install = () => {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chutes-plugin",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Chutes Models plugin for OpenCode - Access 48+ state-of-the-art AI models through the Chutes API",
5
5
  "author": {
6
6
  "name": "Gianmarco Martinelli",
@@ -14,7 +14,7 @@
14
14
  }
15
15
  },
16
16
  "bin": {
17
- "chutes-plugin": "dist/cli/index.js"
17
+ "chutes-plugin": "dist/cli/chutes-plugin.js"
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",
@@ -26,7 +26,8 @@
26
26
  "files": [
27
27
  "dist",
28
28
  "src/version.ts",
29
- "src/cli"
29
+ "src/cli",
30
+ "bin"
30
31
  ],
31
32
  "dependencies": {
32
33
  "@opencode-ai/plugin": "1.0.85",
@@ -23,24 +23,16 @@ export async function install(options: InstallOptions): Promise<void> {
23
23
  output: process.stdout,
24
24
  });
25
25
 
26
- try {
27
- installType = await new Promise<string>((resolve, reject) => {
28
- rl.question('> ', (answer) => {
29
- rl.close();
30
- resolve(answer.trim());
31
- });
32
-
33
- setTimeout(() => {
34
- rl.close();
35
- reject(new Error('Timeout waiting for user input'));
36
- }, 10000);
26
+ installType = await new Promise<string>((resolve) => {
27
+ rl.question('> ', (answer) => {
28
+ rl.close();
29
+ resolve(answer.trim());
37
30
  });
38
- } catch {
39
- console.log('No input detected, defaulting to npm installation...\n');
40
- installType = 'npm';
41
- }
31
+ });
42
32
  }
43
33
 
34
+ console.log(`Installing type: ${installType}\n`);
35
+
44
36
  switch (installType) {
45
37
  case '1':
46
38
  case 'project':
@@ -55,7 +47,7 @@ export async function install(options: InstallOptions): Promise<void> {
55
47
  await installNpm();
56
48
  break;
57
49
  default:
58
- console.log(`Invalid installation type: "${installType}"`);
50
+ console.log(`❌ Invalid installation type: "${installType}"`);
59
51
  console.log('Please choose: 1 (project), 2 (global), or 3 (npm)');
60
52
  process.exit(1);
61
53
  }
@@ -68,68 +60,62 @@ async function installProject(): Promise<void> {
68
60
 
69
61
  console.log('Installing to project...\n');
70
62
 
71
- try {
72
- if (!fs.existsSync(opencodeDir)) {
73
- fs.mkdirSync(opencodeDir, { recursive: true });
74
- }
75
-
76
- if (!fs.existsSync(path.join(opencodeDir, 'plugin'))) {
77
- fs.mkdirSync(path.join(opencodeDir, 'plugin'), { recursive: true });
78
- }
63
+ if (!fs.existsSync(opencodeDir)) {
64
+ fs.mkdirSync(opencodeDir, { recursive: true });
65
+ }
79
66
 
80
- fs.mkdirSync(pluginDir, { recursive: true });
67
+ if (!fs.existsSync(path.join(opencodeDir, 'plugin'))) {
68
+ fs.mkdirSync(path.join(opencodeDir, 'plugin'), { recursive: true });
69
+ }
81
70
 
82
- const distDir = path.join(__dirname, '..', '..', 'dist');
83
- if (fs.existsSync(distDir)) {
84
- fs.cpSync(distDir, path.join(pluginDir, 'dist'), { recursive: true });
85
- }
71
+ fs.mkdirSync(pluginDir, { recursive: true });
86
72
 
87
- const srcCliDir = path.join(__dirname, '..');
88
- if (fs.existsSync(srcCliDir)) {
89
- fs.cpSync(srcCliDir, path.join(pluginDir, 'src'), { recursive: true });
90
- }
73
+ const distDir = path.join(__dirname, '..', '..', 'dist');
74
+ if (fs.existsSync(distDir)) {
75
+ fs.cpSync(distDir, path.join(pluginDir, 'dist'), { recursive: true });
76
+ }
91
77
 
92
- const packageJsonPath = path.join(opencodeDir, 'opencode.json');
93
- let config: Record<string, unknown> = {};
94
- if (fs.existsSync(packageJsonPath)) {
95
- const content = fs.readFileSync(packageJsonPath, 'utf-8');
96
- try {
97
- config = JSON.parse(content);
98
- } catch {
99
- console.log('⚠️ Warning: Could not parse existing opencode.json, creating new one');
100
- config = {};
101
- }
102
- }
78
+ const srcCliDir = path.join(__dirname, '..');
79
+ if (fs.existsSync(srcCliDir)) {
80
+ fs.cpSync(srcCliDir, path.join(pluginDir, 'src'), { recursive: true });
81
+ }
103
82
 
104
- const plugins = (config.plugins as string[]) || [];
105
- if (!Array.isArray(plugins)) {
106
- config.plugins = [];
83
+ const packageJsonPath = path.join(opencodeDir, 'opencode.json');
84
+ let config: Record<string, unknown> = {};
85
+ if (fs.existsSync(packageJsonPath)) {
86
+ const content = fs.readFileSync(packageJsonPath, 'utf-8');
87
+ try {
88
+ config = JSON.parse(content);
89
+ } catch (e) {
90
+ console.error('❌ Failed to parse opencode.json:', e);
91
+ process.exit(1);
107
92
  }
93
+ }
108
94
 
109
- const pluginPath = './.opencode/plugin/chutes-plugin/dist/index.js';
110
- if (!plugins.includes(pluginPath)) {
111
- config.plugins.push(pluginPath);
112
- }
95
+ config.plugins = config.plugins || [];
96
+ if (!Array.isArray(config.plugins)) {
97
+ config.plugins = [];
98
+ }
113
99
 
114
- fs.writeFileSync(packageJsonPath, JSON.stringify(config, null, 2));
115
-
116
- console.log('✅ Successfully installed to project!');
117
- console.log('\nNext steps:');
118
- console.log('1. Start OpenCode: opencode');
119
- console.log('2. Connect your Chutes token: /connect chutes');
120
- console.log('3. Select a Chutes model from the dropdown\n');
121
- } catch (error) {
122
- console.log(
123
- `❌ Error installing to project: ${error instanceof Error ? error.message : String(error)}`
124
- );
125
- process.exit(1);
100
+ const pluginPath = './.opencode/plugin/chutes-plugin/dist/index.js';
101
+ if (!config.plugins.includes(pluginPath)) {
102
+ config.plugins.push(pluginPath);
126
103
  }
104
+
105
+ fs.writeFileSync(packageJsonPath, JSON.stringify(config, null, 2));
106
+
107
+ console.log('✅ Successfully installed to project!');
108
+ console.log(` Location: ${pluginDir}`);
109
+ console.log('\nNext steps:');
110
+ console.log('1. Start OpenCode: opencode');
111
+ console.log('2. Connect your Chutes token: /connect chutes');
112
+ console.log('3. Select a Chutes model from the dropdown\n');
127
113
  }
128
114
 
129
115
  async function installGlobal(): Promise<void> {
130
116
  const homeDir = process.env.HOME || process.env.USERPROFILE;
131
117
  if (!homeDir) {
132
- console.log('❌ Error: Could not determine home directory');
118
+ console.error('❌ Error: Could not determine home directory');
133
119
  process.exit(1);
134
120
  }
135
121
 
@@ -138,54 +124,48 @@ async function installGlobal(): Promise<void> {
138
124
 
139
125
  console.log('Installing globally...\n');
140
126
 
141
- try {
142
- fs.mkdirSync(pluginDir, { recursive: true });
143
-
144
- const distDir = path.join(__dirname, '..', '..', 'dist');
145
- if (fs.existsSync(distDir)) {
146
- fs.cpSync(distDir, path.join(pluginDir, 'dist'), { recursive: true });
147
- }
127
+ fs.mkdirSync(pluginDir, { recursive: true });
148
128
 
149
- const srcCliDir = path.join(__dirname, '..');
150
- if (fs.existsSync(srcCliDir)) {
151
- fs.cpSync(srcCliDir, path.join(pluginDir, 'src'), { recursive: true });
152
- }
129
+ const distDir = path.join(__dirname, '..', '..', 'dist');
130
+ if (fs.existsSync(distDir)) {
131
+ fs.cpSync(distDir, path.join(pluginDir, 'dist'), { recursive: true });
132
+ }
153
133
 
154
- const configPath = path.join(configDir, 'opencode.json');
155
- let config: Record<string, unknown> = {};
156
- if (fs.existsSync(configPath)) {
157
- const content = fs.readFileSync(configPath, 'utf-8');
158
- try {
159
- config = JSON.parse(content);
160
- } catch {
161
- console.log('⚠️ Warning: Could not parse existing opencode.json, creating new one');
162
- config = {};
163
- }
164
- }
134
+ const srcCliDir = path.join(__dirname, '..');
135
+ if (fs.existsSync(srcCliDir)) {
136
+ fs.cpSync(srcCliDir, path.join(pluginDir, 'src'), { recursive: true });
137
+ }
165
138
 
166
- config.plugins = config.plugins || [];
167
- if (!Array.isArray(config.plugins)) {
168
- config.plugins = [];
139
+ const configPath = path.join(configDir, 'opencode.json');
140
+ let config: Record<string, unknown> = {};
141
+ if (fs.existsSync(configPath)) {
142
+ const content = fs.readFileSync(configPath, 'utf-8');
143
+ try {
144
+ config = JSON.parse(content);
145
+ } catch (e) {
146
+ console.error('❌ Failed to parse opencode.json:', e);
147
+ process.exit(1);
169
148
  }
149
+ }
170
150
 
171
- const pluginPath = `${configDir}/plugin/chutes-plugin/dist/index.js`;
172
- if (!config.plugins.includes(pluginPath)) {
173
- config.plugins.push(pluginPath);
174
- }
151
+ config.plugins = config.plugins || [];
152
+ if (!Array.isArray(config.plugins)) {
153
+ config.plugins = [];
154
+ }
175
155
 
176
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
177
-
178
- console.log('✅ Successfully installed globally!');
179
- console.log('\nNext steps:');
180
- console.log('1. Start OpenCode: opencode');
181
- console.log('2. Connect your Chutes token: /connect chutes');
182
- console.log('3. Select a Chutes model from the dropdown\n');
183
- } catch (error) {
184
- console.log(
185
- `❌ Error installing globally: ${error instanceof Error ? error.message : String(error)}`
186
- );
187
- process.exit(1);
156
+ const pluginPath = `${configDir}/plugin/chutes-plugin/dist/index.js`;
157
+ if (!config.plugins.includes(pluginPath)) {
158
+ config.plugins.push(pluginPath);
188
159
  }
160
+
161
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
162
+
163
+ console.log('✅ Successfully installed globally!');
164
+ console.log(` Location: ${pluginDir}`);
165
+ console.log('\nNext steps:');
166
+ console.log('1. Start OpenCode: opencode');
167
+ console.log('2. Connect your Chutes token: /connect chutes');
168
+ console.log('3. Select a Chutes model from the dropdown\n');
189
169
  }
190
170
 
191
171
  async function installNpm(): Promise<void> {
@@ -194,39 +174,32 @@ async function installNpm(): Promise<void> {
194
174
 
195
175
  console.log('Installing via npm...\n');
196
176
 
197
- try {
198
- let config: Record<string, unknown> = {};
199
- if (fs.existsSync(configPath)) {
200
- const content = fs.readFileSync(configPath, 'utf-8');
201
- try {
202
- config = JSON.parse(content);
203
- } catch {
204
- console.log('⚠️ Warning: Could not parse existing opencode.json, creating new one');
205
- config = {};
206
- }
207
- }
208
-
209
- config.plugins = config.plugins || [];
210
- if (!Array.isArray(config.plugins)) {
211
- config.plugins = [];
177
+ let config: Record<string, unknown> = {};
178
+ if (fs.existsSync(configPath)) {
179
+ const content = fs.readFileSync(configPath, 'utf-8');
180
+ try {
181
+ config = JSON.parse(content);
182
+ } catch (e) {
183
+ console.error('❌ Failed to parse opencode.json:', e);
184
+ process.exit(1);
212
185
  }
186
+ }
213
187
 
214
- if (!config.plugins.includes('chutes-plugin')) {
215
- config.plugins.push('chutes-plugin');
216
- }
188
+ config.plugins = config.plugins || [];
189
+ if (!Array.isArray(config.plugins)) {
190
+ config.plugins = [];
191
+ }
217
192
 
218
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
219
-
220
- console.log('✅ Added "chutes-plugin" to opencode.json!');
221
- console.log('\nNext steps:');
222
- console.log('1. Start OpenCode: opencode');
223
- console.log('2. The plugin will be auto-installed on first run');
224
- console.log('3. Connect your Chutes token: /connect chutes');
225
- console.log('4. Select a Chutes model from the dropdown\n');
226
- } catch (error) {
227
- console.log(
228
- `❌ Error installing via npm: ${error instanceof Error ? error.message : String(error)}`
229
- );
230
- process.exit(1);
193
+ if (!config.plugins.includes('chutes-plugin')) {
194
+ config.plugins.push('chutes-plugin');
231
195
  }
196
+
197
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
198
+
199
+ console.log('✅ Added "chutes-plugin" to opencode.json!');
200
+ console.log('\nNext steps:');
201
+ console.log('1. Start OpenCode: opencode');
202
+ console.log('2. The plugin will be auto-installed on first run');
203
+ console.log('3. Connect your Chutes token: /connect chutes');
204
+ console.log('4. Select a Chutes model from the dropdown\n');
232
205
  }