cicy-code 0.2.3 → 0.2.5
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/bin/cicy-code +0 -0
- package/bin/cicy-code.js +123 -0
- package/package.json +1 -1
- package/scripts/install.js +5 -1
package/bin/cicy-code
ADDED
|
Binary file
|
package/bin/cicy-code.js
CHANGED
|
@@ -6,8 +6,10 @@ const https = require('https');
|
|
|
6
6
|
|
|
7
7
|
const pkg = require('../package.json');
|
|
8
8
|
const binPath = path.join(__dirname, 'cicy-code');
|
|
9
|
+
const os = require('os');
|
|
9
10
|
|
|
10
11
|
const cn = process.argv.includes('--cn') || process.env.CN_MIRROR === '1';
|
|
12
|
+
const desktopMode = process.argv.includes('--desktop');
|
|
11
13
|
|
|
12
14
|
if (process.argv.includes('--cn')) {
|
|
13
15
|
process.env.CN_MIRROR = '1';
|
|
@@ -86,6 +88,11 @@ async function main() {
|
|
|
86
88
|
process.exit(1);
|
|
87
89
|
}
|
|
88
90
|
|
|
91
|
+
// Desktop mode: start API server in background, then launch Electron
|
|
92
|
+
if (desktopMode) {
|
|
93
|
+
return launchDesktop();
|
|
94
|
+
}
|
|
95
|
+
|
|
89
96
|
const child = spawn(binPath, process.argv.slice(2), {
|
|
90
97
|
stdio: 'inherit',
|
|
91
98
|
env: process.env
|
|
@@ -93,4 +100,120 @@ async function main() {
|
|
|
93
100
|
child.on('exit', (code) => process.exit(code || 0));
|
|
94
101
|
}
|
|
95
102
|
|
|
103
|
+
function getToken() {
|
|
104
|
+
try {
|
|
105
|
+
const globalJson = path.join(os.homedir(), 'global.json');
|
|
106
|
+
const data = JSON.parse(fs.readFileSync(globalJson, 'utf8'));
|
|
107
|
+
return data.api_token || '';
|
|
108
|
+
} catch { return ''; }
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function waitForServer(port, timeout) {
|
|
112
|
+
const http = require('http');
|
|
113
|
+
const start = Date.now();
|
|
114
|
+
return new Promise((resolve, reject) => {
|
|
115
|
+
const check = () => {
|
|
116
|
+
if (Date.now() - start > timeout) return reject(new Error('Server start timeout'));
|
|
117
|
+
const req = http.get(`http://127.0.0.1:${port}/api/health`, (res) => {
|
|
118
|
+
resolve();
|
|
119
|
+
});
|
|
120
|
+
req.on('error', () => setTimeout(check, 500));
|
|
121
|
+
req.setTimeout(1000, () => { req.destroy(); setTimeout(check, 500); });
|
|
122
|
+
};
|
|
123
|
+
check();
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async function launchDesktop() {
|
|
128
|
+
const port = process.env.PORT || 18008;
|
|
129
|
+
const desktopPort = 18101;
|
|
130
|
+
|
|
131
|
+
// 1. Start API server in background
|
|
132
|
+
const serverArgs = process.argv.slice(2).filter(a => a !== '--desktop');
|
|
133
|
+
const server = spawn(binPath, serverArgs, {
|
|
134
|
+
stdio: 'ignore',
|
|
135
|
+
detached: true,
|
|
136
|
+
env: process.env
|
|
137
|
+
});
|
|
138
|
+
server.unref();
|
|
139
|
+
console.log(` 🚀 Starting cicy-code server (PID: ${server.pid})...`);
|
|
140
|
+
|
|
141
|
+
// 2. Wait for server ready
|
|
142
|
+
try {
|
|
143
|
+
await waitForServer(port, 30000);
|
|
144
|
+
} catch {
|
|
145
|
+
console.error(' ❌ Server failed to start within 30s');
|
|
146
|
+
process.exit(1);
|
|
147
|
+
}
|
|
148
|
+
console.log(` ✅ Server ready on port ${port}`);
|
|
149
|
+
|
|
150
|
+
// 3. Get token
|
|
151
|
+
const token = getToken();
|
|
152
|
+
const url = `http://127.0.0.1:${port}/?token=${token}`;
|
|
153
|
+
|
|
154
|
+
// 4. Launch Electron via global 'electron' binary (no signing needed)
|
|
155
|
+
// cicy-desktop uses official Electron binary + our JS code
|
|
156
|
+
// RPC/MCP server starts on desktopPort (18101)
|
|
157
|
+
let electronBinary = null;
|
|
158
|
+
try {
|
|
159
|
+
electronBinary = execSync('which electron 2>/dev/null', { encoding: 'utf8' }).trim();
|
|
160
|
+
} catch {}
|
|
161
|
+
|
|
162
|
+
if (!electronBinary) {
|
|
163
|
+
console.log(' ⚠️ Electron not found. Installing...');
|
|
164
|
+
try {
|
|
165
|
+
execSync('npm install -g electron', { stdio: 'inherit' });
|
|
166
|
+
electronBinary = execSync('which electron', { encoding: 'utf8' }).trim();
|
|
167
|
+
} catch {
|
|
168
|
+
console.error(' ❌ Failed to install Electron. Install manually: npm install -g electron');
|
|
169
|
+
console.log(` 📱 Fallback: open browser → ${url}`);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Find cicy-desktop package (global cicy or bundled desktop/)
|
|
175
|
+
let desktopDir = null;
|
|
176
|
+
|
|
177
|
+
// Check global 'cicy-desktop' package
|
|
178
|
+
try {
|
|
179
|
+
const cicyBin = execSync('which cicy 2>/dev/null', { encoding: 'utf8' }).trim();
|
|
180
|
+
desktopDir = path.resolve(path.dirname(cicyBin), '..', 'lib', 'node_modules', 'cicy-desktop');
|
|
181
|
+
if (!fs.existsSync(path.join(desktopDir, 'src', 'main.js'))) desktopDir = null;
|
|
182
|
+
} catch {}
|
|
183
|
+
|
|
184
|
+
// Fallback: bundled desktop/ submodule
|
|
185
|
+
if (!desktopDir) {
|
|
186
|
+
const bundled = path.join(__dirname, '..', '..', 'desktop');
|
|
187
|
+
if (fs.existsSync(path.join(bundled, 'src', 'main.js'))) {
|
|
188
|
+
desktopDir = bundled;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (!desktopDir) {
|
|
193
|
+
console.log(' ⚠️ cicy-desktop not found. Installing...');
|
|
194
|
+
try {
|
|
195
|
+
execSync('npm install -g cicy-desktop', { stdio: 'inherit' });
|
|
196
|
+
const cicyBin = execSync('which cicy', { encoding: 'utf8' }).trim();
|
|
197
|
+
desktopDir = path.resolve(path.dirname(cicyBin), '..', 'lib', 'node_modules', 'cicy-desktop');
|
|
198
|
+
} catch {
|
|
199
|
+
console.error(' ❌ Failed to install cicy. Install manually: npm install -g cicy-desktop');
|
|
200
|
+
console.log(` 📱 Fallback: open browser → ${url}`);
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
console.log(` 🖥️ Opening desktop: ${url}`);
|
|
206
|
+
console.log(` 🔧 RPC/MCP server: http://127.0.0.1:${desktopPort}`);
|
|
207
|
+
|
|
208
|
+
const desktop = spawn(electronBinary, [desktopDir, `--url=${url}`, `--port=${desktopPort}`], {
|
|
209
|
+
stdio: 'inherit',
|
|
210
|
+
env: { ...process.env, PORT: String(desktopPort) }
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
desktop.on('exit', (code) => {
|
|
214
|
+
try { process.kill(server.pid); } catch {}
|
|
215
|
+
process.exit(code || 0);
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
96
219
|
main();
|
package/package.json
CHANGED
package/scripts/install.js
CHANGED
|
@@ -20,7 +20,11 @@ const key = `${process.platform}-${process.arch}`;
|
|
|
20
20
|
const binName = PLATFORMS[key];
|
|
21
21
|
|
|
22
22
|
if (!binName) {
|
|
23
|
-
|
|
23
|
+
if (process.platform === 'win32') {
|
|
24
|
+
console.error('Windows is not supported natively. Please use WSL:\n wsl --install\n wsl npx cicy-code');
|
|
25
|
+
} else {
|
|
26
|
+
console.error(`Unsupported platform: ${key}`);
|
|
27
|
+
}
|
|
24
28
|
process.exit(1);
|
|
25
29
|
}
|
|
26
30
|
|