@myrialabs/clopen 0.2.22 → 0.2.23
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/backend/engine/adapters/opencode/server.ts +3 -3
- package/backend/engine/adapters/opencode/stream.ts +4 -2
- package/backend/git/git-executor.ts +4 -1
- package/backend/terminal/shell-utils.ts +7 -13
- package/backend/utils/cli.ts +27 -0
- package/backend/utils/index.ts +7 -1
- package/backend/utils/os.ts +7 -0
- package/backend/ws/engine/claude/accounts.ts +2 -2
- package/backend/ws/engine/claude/status.ts +3 -2
- package/backend/ws/engine/opencode/status.ts +3 -2
- package/package.json +1 -1
- package/backend/ws/engine/utils.ts +0 -68
|
@@ -15,7 +15,6 @@ import type { OpencodeClient } from '@opencode-ai/sdk';
|
|
|
15
15
|
import type { Subprocess } from 'bun';
|
|
16
16
|
import { getOpenCodeMcpConfig } from '../../../mcp';
|
|
17
17
|
import { settingsQueries } from '../../../database/queries';
|
|
18
|
-
import { resolveCommand } from '../../../ws/engine/utils';
|
|
19
18
|
import { debug } from '$shared/utils/logger';
|
|
20
19
|
|
|
21
20
|
const OPENCODE_HOST = '127.0.0.1';
|
|
@@ -117,8 +116,9 @@ async function init(): Promise<void> {
|
|
|
117
116
|
settingsQueries.delete(DB_KEY);
|
|
118
117
|
}
|
|
119
118
|
|
|
120
|
-
// 2. Spawn a new server via Bun.spawn
|
|
121
|
-
const command =
|
|
119
|
+
// 2. Spawn a new server via Bun.spawn with absolute binary path
|
|
120
|
+
const command = Bun.which('opencode');
|
|
121
|
+
if (!command) throw new Error('opencode binary not found on PATH');
|
|
122
122
|
const args = [command, 'serve', `--hostname=${OPENCODE_HOST}`, '--port=0'];
|
|
123
123
|
|
|
124
124
|
// Build MCP config — but only inject if the MCP endpoint is actually reachable.
|
|
@@ -214,7 +214,8 @@ export class OpenCodeEngine implements AIEngine {
|
|
|
214
214
|
});
|
|
215
215
|
|
|
216
216
|
// 2. Send prompt asynchronously (non-blocking) — parse "providerId/modelId"
|
|
217
|
-
const
|
|
217
|
+
const idx = model.indexOf('/');
|
|
218
|
+
const [providerID, modelID] = idx >= 0 ? [model.substring(0, idx), model.substring(idx + 1)] : ['', model];
|
|
218
219
|
|
|
219
220
|
client.session.promptAsync({
|
|
220
221
|
path: { id: sessionId },
|
|
@@ -1059,7 +1060,8 @@ export class OpenCodeEngine implements AIEngine {
|
|
|
1059
1060
|
}
|
|
1060
1061
|
|
|
1061
1062
|
// Parse model into providerID/modelID
|
|
1062
|
-
const
|
|
1063
|
+
const idx = model.indexOf('/');
|
|
1064
|
+
const [providerID, modelID] = idx >= 0 ? [model.substring(0, idx), model.substring(idx + 1)] : ['', model];
|
|
1063
1065
|
|
|
1064
1066
|
// Wrap prompt with JSON instruction since v1 doesn't support format option
|
|
1065
1067
|
const jsonPrompt = `${prompt}
|
|
@@ -22,8 +22,11 @@ export async function execGit(
|
|
|
22
22
|
): Promise<GitExecResult> {
|
|
23
23
|
debug.log('git', `Executing: git ${args.join(' ')} in ${cwd}`);
|
|
24
24
|
|
|
25
|
+
const gitPath = Bun.which('git');
|
|
26
|
+
if (!gitPath) throw new Error('git binary not found on PATH');
|
|
27
|
+
|
|
25
28
|
const safeCwd = cwd.replace(/\\/g, '/');
|
|
26
|
-
const proc = Bun.spawn([
|
|
29
|
+
const proc = Bun.spawn([gitPath, '-c', `safe.directory=${safeCwd}`, ...args], {
|
|
27
30
|
cwd,
|
|
28
31
|
stdout: 'pipe',
|
|
29
32
|
stderr: 'pipe',
|
|
@@ -99,10 +99,9 @@ export async function getShellConfig(preferGitBash = false): Promise<{
|
|
|
99
99
|
isUnixLike: boolean;
|
|
100
100
|
}> {
|
|
101
101
|
if (isWindows) {
|
|
102
|
-
|
|
103
|
-
// PowerShell is available on all modern Windows systems
|
|
102
|
+
const psPath = Bun.which('powershell.exe') ?? 'powershell.exe';
|
|
104
103
|
return {
|
|
105
|
-
shell:
|
|
104
|
+
shell: psPath,
|
|
106
105
|
args: (command: string) => ['-NoProfile', '-Command', command],
|
|
107
106
|
name: 'PowerShell',
|
|
108
107
|
isUnixLike: false
|
|
@@ -184,16 +183,12 @@ export function createPty(shell: string, args: string[], cwd: string, terminalSi
|
|
|
184
183
|
const cols = terminalSize?.cols || 80;
|
|
185
184
|
const rows = terminalSize?.rows || 24;
|
|
186
185
|
|
|
187
|
-
// Extract the actual command from args
|
|
188
|
-
const actualCommand: string = '';
|
|
189
|
-
|
|
190
186
|
if (isWindows) {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
187
|
+
const psPath = Bun.which('powershell.exe') ?? 'powershell.exe';
|
|
188
|
+
const isPowershell = shell === 'powershell' || shell === 'powershell.exe' || shell.endsWith('powershell.exe') || shell.endsWith('pwsh.exe');
|
|
189
|
+
if (isPowershell) {
|
|
194
190
|
let actualCommand = args.join(' ');
|
|
195
191
|
if (args.length >= 2 && (args[0] === '-Command' || args[0] === '-NoProfile')) {
|
|
196
|
-
// Find the actual command in the args
|
|
197
192
|
const commandIndex = args.findIndex(arg => arg === '-Command');
|
|
198
193
|
if (commandIndex !== -1 && commandIndex + 1 < args.length) {
|
|
199
194
|
actualCommand = args[commandIndex + 1];
|
|
@@ -201,7 +196,7 @@ export function createPty(shell: string, args: string[], cwd: string, terminalSi
|
|
|
201
196
|
actualCommand = args[args.length - 1];
|
|
202
197
|
}
|
|
203
198
|
}
|
|
204
|
-
return spawn(
|
|
199
|
+
return spawn(psPath, ['-NoProfile', '-NoLogo', '-Command', actualCommand], {
|
|
205
200
|
name: 'xterm-256color',
|
|
206
201
|
cols,
|
|
207
202
|
rows,
|
|
@@ -210,8 +205,7 @@ export function createPty(shell: string, args: string[], cwd: string, terminalSi
|
|
|
210
205
|
});
|
|
211
206
|
}
|
|
212
207
|
|
|
213
|
-
|
|
214
|
-
return spawn('powershell.exe', ['-NoProfile', '-NoLogo', '-Command', args.join(' ') || 'Write-Host "Terminal ready"'], {
|
|
208
|
+
return spawn(psPath, ['-NoProfile', '-NoLogo', '-Command', args.join(' ') || 'Write-Host "Terminal ready"'], {
|
|
215
209
|
name: 'xterm-256color',
|
|
216
210
|
cols,
|
|
217
211
|
rows,
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI Binary Resolution & Status
|
|
3
|
+
*
|
|
4
|
+
* Uses Bun.which() for cross-platform PATH resolution.
|
|
5
|
+
* Bun.which() returns absolute paths and handles PATHEXT
|
|
6
|
+
* extensions (.exe, .cmd) on Windows automatically.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export type CLIStatus = { installed: boolean; version: string | null };
|
|
10
|
+
|
|
11
|
+
export async function getStatus(command: string): Promise<CLIStatus> {
|
|
12
|
+
const resolved = Bun.which(command);
|
|
13
|
+
if (!resolved) return { installed: false, version: null };
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
const proc = Bun.spawn([resolved, '--version'], { stdout: 'pipe', stderr: 'pipe' });
|
|
17
|
+
const exitCode = await proc.exited;
|
|
18
|
+
if (exitCode !== 0) return { installed: false, version: null };
|
|
19
|
+
|
|
20
|
+
const stdout = await new Response(proc.stdout).text();
|
|
21
|
+
const raw = stdout.trim();
|
|
22
|
+
const version = raw.split(/[\s(]/)[0] || raw || null;
|
|
23
|
+
return { installed: true, version };
|
|
24
|
+
} catch {
|
|
25
|
+
return { installed: false, version: null };
|
|
26
|
+
}
|
|
27
|
+
}
|
package/backend/utils/index.ts
CHANGED
|
@@ -4,5 +4,11 @@ export * from './process-manager.js';
|
|
|
4
4
|
// Export environment sanitizer
|
|
5
5
|
export * from './env.js';
|
|
6
6
|
|
|
7
|
+
// Export OS utilities
|
|
8
|
+
export * from './os.js';
|
|
9
|
+
|
|
7
10
|
// Export path utilities
|
|
8
|
-
export * from './paths.js';
|
|
11
|
+
export * from './paths.js';
|
|
12
|
+
|
|
13
|
+
// Export CLI utilities
|
|
14
|
+
export * from './cli.js';
|
|
@@ -21,7 +21,6 @@ import { engineQueries } from '../../../database/queries';
|
|
|
21
21
|
import { resetEnvironment, getClaudeUserConfigDir } from '../../../engine/adapters/claude/environment';
|
|
22
22
|
import { debug } from '$shared/utils/logger';
|
|
23
23
|
import { getCleanSpawnEnv } from '../../../utils/env';
|
|
24
|
-
import { resolveCommand } from '../utils';
|
|
25
24
|
|
|
26
25
|
// ── Helpers ──
|
|
27
26
|
|
|
@@ -189,7 +188,8 @@ export const accountsHandler = createRouter()
|
|
|
189
188
|
ptyEnv['CLAUDE_CONFIG_DIR'] = getClaudeUserConfigDir();
|
|
190
189
|
ptyEnv['BROWSER'] = 'false';
|
|
191
190
|
|
|
192
|
-
const claudeCmd =
|
|
191
|
+
const claudeCmd = Bun.which('claude');
|
|
192
|
+
if (!claudeCmd) throw new Error('claude binary not found on PATH');
|
|
193
193
|
let pty: ReturnType<typeof spawn>;
|
|
194
194
|
try {
|
|
195
195
|
pty = spawn(claudeCmd, ['setup-token'], {
|
|
@@ -8,7 +8,8 @@ import { t } from 'elysia';
|
|
|
8
8
|
import { createRouter } from '$shared/utils/ws-server';
|
|
9
9
|
import { engineQueries } from '../../../database/queries';
|
|
10
10
|
import { debug } from '$shared/utils/logger';
|
|
11
|
-
import { getBackendOS
|
|
11
|
+
import { getBackendOS } from '../../../utils/os';
|
|
12
|
+
import { getStatus } from '../../../utils/cli';
|
|
12
13
|
|
|
13
14
|
export const claudeCodeStatusHandler = createRouter()
|
|
14
15
|
.http('engine:claude-status', {
|
|
@@ -29,7 +30,7 @@ export const claudeCodeStatusHandler = createRouter()
|
|
|
29
30
|
}, async () => {
|
|
30
31
|
debug.log('engine', 'Checking Claude Code status...');
|
|
31
32
|
|
|
32
|
-
const { installed, version } = await
|
|
33
|
+
const { installed, version } = await getStatus('claude');
|
|
33
34
|
const accounts = engineQueries.getClaudeAccounts();
|
|
34
35
|
const activeAccount = engineQueries.getActiveClaudeAccount();
|
|
35
36
|
|
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
import { t } from 'elysia';
|
|
8
8
|
import { createRouter } from '$shared/utils/ws-server';
|
|
9
9
|
import { debug } from '$shared/utils/logger';
|
|
10
|
-
import { getBackendOS
|
|
10
|
+
import { getBackendOS } from '../../../utils/os';
|
|
11
|
+
import { getStatus } from '../../../utils/cli';
|
|
11
12
|
|
|
12
13
|
export const openCodeStatusHandler = createRouter()
|
|
13
14
|
.http('engine:opencode-status', {
|
|
@@ -20,7 +21,7 @@ export const openCodeStatusHandler = createRouter()
|
|
|
20
21
|
}, async () => {
|
|
21
22
|
debug.log('engine', 'Checking Open Code status...');
|
|
22
23
|
|
|
23
|
-
const { installed, version } = await
|
|
24
|
+
const { installed, version } = await getStatus('opencode');
|
|
24
25
|
|
|
25
26
|
return {
|
|
26
27
|
installed,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@myrialabs/clopen",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.23",
|
|
4
4
|
"description": "All-in-one web workspace for Claude Code & OpenCode — chat, terminal, git, browser preview, checkpoints, and real-time collaboration",
|
|
5
5
|
"author": "Myria Labs",
|
|
6
6
|
"license": "MIT",
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Engine Utilities
|
|
3
|
-
*
|
|
4
|
-
* Shared helpers used by engine status handlers.
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
type EngineCommand = 'claude' | 'opencode';
|
|
8
|
-
|
|
9
|
-
export function getBackendOS(): 'windows' | 'macos' | 'linux' {
|
|
10
|
-
switch (process.platform) {
|
|
11
|
-
case 'win32': return 'windows';
|
|
12
|
-
case 'darwin': return 'macos';
|
|
13
|
-
default: return 'linux';
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const resolvedCommands = new Map<EngineCommand, string>();
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Resolves the correct CLI command for the current platform.
|
|
21
|
-
* On Windows, tries the base command first, then falls back to
|
|
22
|
-
* command.cmd for older CLI installations. Result is cached.
|
|
23
|
-
*/
|
|
24
|
-
export async function resolveCommand(command: EngineCommand): Promise<string> {
|
|
25
|
-
const cached = resolvedCommands.get(command);
|
|
26
|
-
if (cached) return cached;
|
|
27
|
-
|
|
28
|
-
let resolved: string = command;
|
|
29
|
-
|
|
30
|
-
if (!await trySpawn(command) && process.platform === 'win32') {
|
|
31
|
-
const fallback = command + '.cmd';
|
|
32
|
-
if (await trySpawn(fallback)) resolved = fallback;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
resolvedCommands.set(command, resolved);
|
|
36
|
-
return resolved;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
async function trySpawn(command: string): Promise<boolean> {
|
|
40
|
-
try {
|
|
41
|
-
const proc = Bun.spawn([command, '--version'], { stdout: 'pipe', stderr: 'pipe' });
|
|
42
|
-
return (await proc.exited) === 0;
|
|
43
|
-
} catch {
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export async function detectCLI(command: EngineCommand): Promise<{ installed: boolean; version: string | null }> {
|
|
49
|
-
const resolved = await resolveCommand(command);
|
|
50
|
-
|
|
51
|
-
try {
|
|
52
|
-
const proc = Bun.spawn([resolved, '--version'], {
|
|
53
|
-
stdout: 'pipe',
|
|
54
|
-
stderr: 'pipe'
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
const exitCode = await proc.exited;
|
|
58
|
-
if (exitCode !== 0) return { installed: false, version: null };
|
|
59
|
-
|
|
60
|
-
const stdout = await new Response(proc.stdout).text();
|
|
61
|
-
const raw = stdout.trim();
|
|
62
|
-
// Extract only the version token (e.g. "2.1.52" from "2.1.52 (Claude Code)")
|
|
63
|
-
const version = raw.split(/[\s(]/)[0] || raw || null;
|
|
64
|
-
return { installed: true, version };
|
|
65
|
-
} catch {
|
|
66
|
-
return { installed: false, version: null };
|
|
67
|
-
}
|
|
68
|
-
}
|