@myrialabs/clopen 0.3.2 → 0.3.4
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/README.md +2 -1
- package/backend/auth/permissions.ts +7 -1
- package/backend/engine/adapters/opencode/message-converter.ts +26 -0
- package/backend/engine/adapters/opencode/server.ts +5 -2
- package/backend/engine/install-recipes.ts +393 -0
- package/backend/engine/install-runner.ts +362 -0
- package/backend/git/git-executor.ts +2 -1
- package/backend/index.ts +10 -0
- package/backend/preview/browser/browser-pool.ts +13 -5
- package/backend/utils/cli.ts +28 -5
- package/backend/utils/path-enrich.ts +248 -0
- package/backend/utils/privilege.ts +51 -0
- package/backend/ws/engine/claude/accounts.ts +2 -1
- package/backend/ws/index.ts +5 -1
- package/backend/ws/system-tools/index.ts +16 -0
- package/backend/ws/system-tools/install.ts +122 -0
- package/backend/ws/system-tools/status.ts +118 -0
- package/dist/assets/{index-7DYhZPkW.js → index-D4V47e9n.js} +2 -2
- package/dist/assets/{main-8urnNoR7.js → main-Be2TrEVr.js} +175 -167
- package/dist/assets/main-C184xHqk.css +1 -0
- package/dist/index.html +2 -2
- package/package.json +1 -1
- package/shared/types/stores/settings.ts +2 -0
- package/shared/utils/logger.ts +2 -1
- package/dist/assets/main-TEa2MRnh.css +0 -1
package/README.md
CHANGED
|
@@ -57,6 +57,7 @@ A complete development environment designed around AI-assisted workflows, built
|
|
|
57
57
|
- **Cloudflare Tunnel** — One-click public HTTPS URL for your local dev server. Built-in QR code for instant mobile access. Share your work without deploying
|
|
58
58
|
- **MCP Support** — Full Model Context Protocol integration. Connect AI tools, external APIs, and custom capabilities to your AI agents with zero friction
|
|
59
59
|
- **Flexible Authentication** — No Login or With Login mode with admin/member roles, invite links, rate-limited login, and CLI token recovery
|
|
60
|
+
- **System Tools Installer** — Install Git, Claude Code, OpenCode, and Chrome straight from the admin Settings UI, with live install output streamed to the browser via xterm.js
|
|
60
61
|
- **Background Processing** — Chat, terminal, and other processes continue running even when you close the browser — come back later and pick up where you left off
|
|
61
62
|
- **Database Management** — Browse tables, run queries, and inspect your database directly from the workspace *(coming soon)*
|
|
62
63
|
|
|
@@ -87,7 +88,7 @@ Or manually via Bun:
|
|
|
87
88
|
bun add -g @myrialabs/clopen
|
|
88
89
|
```
|
|
89
90
|
|
|
90
|
-
You can also update from the **Settings >
|
|
91
|
+
You can also update from the **Settings > Maintenance > Updates** section in the web UI.
|
|
91
92
|
|
|
92
93
|
### Usage
|
|
93
94
|
|
|
@@ -26,7 +26,13 @@ export const ADMIN_ONLY_ROUTES = new Set([
|
|
|
26
26
|
'auth:revoke-invite',
|
|
27
27
|
'auth:list-users',
|
|
28
28
|
'auth:remove-user',
|
|
29
|
-
'settings:update-system'
|
|
29
|
+
'settings:update-system',
|
|
30
|
+
// System Tools — binary installation is an admin-only operation.
|
|
31
|
+
'system-tools:status',
|
|
32
|
+
'system-tools:status-all',
|
|
33
|
+
'system-tools:install-start',
|
|
34
|
+
'system-tools:install-cancel',
|
|
35
|
+
'system-tools:install-session'
|
|
30
36
|
]);
|
|
31
37
|
|
|
32
38
|
/**
|
|
@@ -41,6 +41,7 @@ import type {
|
|
|
41
41
|
ListMcpResourcesInput,
|
|
42
42
|
ReadMcpResourceInput,
|
|
43
43
|
TodoWriteInput,
|
|
44
|
+
PatchInput,
|
|
44
45
|
} from '$shared/types/unified';
|
|
45
46
|
|
|
46
47
|
// ============================================================
|
|
@@ -86,6 +87,7 @@ type NormalizedToolInput =
|
|
|
86
87
|
| GlobInput | GrepInput | WebFetchInput | WebSearchInput
|
|
87
88
|
| AskUserQuestionInput | TodoWriteInput
|
|
88
89
|
| ListMcpResourcesInput | ReadMcpResourceInput
|
|
90
|
+
| PatchInput
|
|
89
91
|
| Record<string, unknown>;
|
|
90
92
|
|
|
91
93
|
// ============================================================
|
|
@@ -109,6 +111,9 @@ const TOOL_NAME_MAP: Record<string, string> = {
|
|
|
109
111
|
'write': 'Write',
|
|
110
112
|
'edit': 'Edit',
|
|
111
113
|
'patch': 'Patch',
|
|
114
|
+
// OpenAI GPT-5 family emits `apply_patch` with a V4A-format `patch_text`
|
|
115
|
+
// payload. Normalize to canonical `Patch` so PatchTool.svelte renders it.
|
|
116
|
+
'apply_patch': 'Patch',
|
|
112
117
|
// Search & discovery
|
|
113
118
|
'glob': 'Glob',
|
|
114
119
|
'grep': 'Grep',
|
|
@@ -315,6 +320,26 @@ function normalizeTodoWriteInput(raw: OCToolInput): TodoWriteInput {
|
|
|
315
320
|
};
|
|
316
321
|
}
|
|
317
322
|
|
|
323
|
+
/**
|
|
324
|
+
* Handle both OpenCode's `patch` tool (`{ file_path, patch }`) and OpenAI
|
|
325
|
+
* GPT-5's `apply_patch` (`{ patch_text }`). For apply_patch we extract the
|
|
326
|
+
* first file path from the V4A header so the Patch tool header has something
|
|
327
|
+
* meaningful; the full patch body still shows every file.
|
|
328
|
+
*/
|
|
329
|
+
function normalizePatchInput(raw: OCToolInput): PatchInput {
|
|
330
|
+
const patchText = str(raw, 'patch_text', 'patchText');
|
|
331
|
+
const patchBody = patchText || str(raw, 'patch', 'patch');
|
|
332
|
+
const explicitPath = str(raw, 'file_path', 'filePath');
|
|
333
|
+
|
|
334
|
+
let filePath = explicitPath;
|
|
335
|
+
if (!filePath && patchBody) {
|
|
336
|
+
const match = patchBody.match(/^\*\*\*\s+(?:Add|Update|Delete)\s+File:\s*(.+)$/m);
|
|
337
|
+
if (match) filePath = match[1].trim();
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
return { filePath, patch: patchBody };
|
|
341
|
+
}
|
|
342
|
+
|
|
318
343
|
// ============================================================
|
|
319
344
|
// Normalizer Dispatcher
|
|
320
345
|
// ============================================================
|
|
@@ -342,6 +367,7 @@ function normalizeToolInput(claudeToolName: string, raw: OCToolInput): Normalize
|
|
|
342
367
|
case 'ListMcpResources': return normalizeListMcpResourcesInput(raw);
|
|
343
368
|
case 'ReadMcpResource': return normalizeReadMcpResourceInput(raw);
|
|
344
369
|
case 'TodoWrite': return normalizeTodoWriteInput(raw);
|
|
370
|
+
case 'Patch': return normalizePatchInput(raw);
|
|
345
371
|
default: {
|
|
346
372
|
// Unknown tool: generic camelCase → snake_case key normalization
|
|
347
373
|
const normalized: Record<string, string | number | boolean> = {};
|
|
@@ -16,6 +16,7 @@ import type { Subprocess } from 'bun';
|
|
|
16
16
|
import { getOpenCodeMcpConfig } from '../../../mcp';
|
|
17
17
|
import { settingsQueries } from '../../../database/queries';
|
|
18
18
|
import { generateOpenCodeProviderConfig } from './config';
|
|
19
|
+
import { resolveBinaryWithRefresh } from '$backend/utils/cli';
|
|
19
20
|
import { debug } from '$shared/utils/logger';
|
|
20
21
|
|
|
21
22
|
const OPENCODE_HOST = '127.0.0.1';
|
|
@@ -117,8 +118,10 @@ async function init(): Promise<void> {
|
|
|
117
118
|
settingsQueries.delete(DB_KEY);
|
|
118
119
|
}
|
|
119
120
|
|
|
120
|
-
// 2. Spawn a new server via Bun.spawn with absolute binary path
|
|
121
|
-
|
|
121
|
+
// 2. Spawn a new server via Bun.spawn with absolute binary path.
|
|
122
|
+
// Re-harvest PATH and fall back to known install locations so freshly
|
|
123
|
+
// installed binaries are picked up without a clopen restart.
|
|
124
|
+
const command = await resolveBinaryWithRefresh('opencode');
|
|
122
125
|
if (!command) throw new Error('opencode binary not found on PATH');
|
|
123
126
|
const args = [command, 'serve', `--hostname=${OPENCODE_HOST}`, '--port=0'];
|
|
124
127
|
|
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* System Tool Install Recipes
|
|
3
|
+
*
|
|
4
|
+
* Data-driven registry of install commands for system tools that clopen
|
|
5
|
+
* depends on (Git, Claude Code, OpenCode, Chrome for puppeteer). Each
|
|
6
|
+
* recipe is platform-aware and privilege-aware: when the runner cannot
|
|
7
|
+
* reasonably complete the install non-interactively (e.g. `apt` without
|
|
8
|
+
* root, `choco` without Administrator), the recipe is marked
|
|
9
|
+
* `autoInstallable: false` and the frontend renders a copy-command
|
|
10
|
+
* fallback instead of the install button.
|
|
11
|
+
*
|
|
12
|
+
* Recipes also carry manual instructions so the frontend can always
|
|
13
|
+
* surface a copy-able command and a docs link, regardless of platform.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { homedir } from 'node:os';
|
|
17
|
+
import { existsSync, readdirSync } from 'node:fs';
|
|
18
|
+
import { join } from 'node:path';
|
|
19
|
+
import { isElevated } from '$backend/utils/privilege';
|
|
20
|
+
import { getClopenDir } from '$backend/utils/paths';
|
|
21
|
+
import { resolveBinary, resolveBinaryWithRefresh } from '$backend/utils/cli';
|
|
22
|
+
|
|
23
|
+
export type ToolId = 'git' | 'claude' | 'opencode' | 'chrome';
|
|
24
|
+
|
|
25
|
+
export interface ManualInstruction {
|
|
26
|
+
label: string;
|
|
27
|
+
command: string;
|
|
28
|
+
docs?: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface Recipe {
|
|
32
|
+
tool: ToolId;
|
|
33
|
+
autoInstallable: boolean;
|
|
34
|
+
/** Reason displayed when autoInstallable is false. */
|
|
35
|
+
unavailableReason?: string;
|
|
36
|
+
/** Spawn arg vector when autoInstallable. */
|
|
37
|
+
command?: string[];
|
|
38
|
+
/** Optional shell to wrap command (e.g. sh -c for pipe chains). */
|
|
39
|
+
shell?: { program: string; args: string[] };
|
|
40
|
+
/**
|
|
41
|
+
* Fetch a remote script via Bun.fetch and pipe its body to the
|
|
42
|
+
* interpreter's stdin. Used in place of `curl | bash` so clopen can
|
|
43
|
+
* install tools like Claude/OpenCode without requiring curl to be
|
|
44
|
+
* present on the system. Exclusive with `command`/`shell`.
|
|
45
|
+
*/
|
|
46
|
+
fetchAndPipe?: { url: string; interpreter: string[] };
|
|
47
|
+
/** Human-readable command string for confirmation dialog preview. */
|
|
48
|
+
displayCommand?: string;
|
|
49
|
+
/** Extra env vars for the install subprocess. */
|
|
50
|
+
env?: Record<string, string>;
|
|
51
|
+
/** Missing prerequisites (other tools that must be installed first). */
|
|
52
|
+
missingPrereqs: ToolId[];
|
|
53
|
+
/** Manual-install options shown regardless of autoInstallable. */
|
|
54
|
+
manualInstructions: ManualInstruction[];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface ToolStatus {
|
|
58
|
+
tool: ToolId;
|
|
59
|
+
installed: boolean;
|
|
60
|
+
version: string | null;
|
|
61
|
+
/** Where the binary was found (e.g. "/usr/bin/git", "system", "~/.clopen/bin"). */
|
|
62
|
+
source: string | null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
66
|
+
// Package manager detection
|
|
67
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
68
|
+
|
|
69
|
+
type LinuxPkgMgr = 'apt' | 'dnf' | 'pacman' | 'apk' | 'zypper';
|
|
70
|
+
type WindowsPkgMgr = 'winget' | 'scoop' | 'choco';
|
|
71
|
+
|
|
72
|
+
function detectLinuxPkgMgr(): LinuxPkgMgr | null {
|
|
73
|
+
if (resolveBinary('apt-get')) return 'apt';
|
|
74
|
+
if (resolveBinary('dnf')) return 'dnf';
|
|
75
|
+
if (resolveBinary('pacman')) return 'pacman';
|
|
76
|
+
if (resolveBinary('apk')) return 'apk';
|
|
77
|
+
if (resolveBinary('zypper')) return 'zypper';
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function detectWindowsPkgMgr(): WindowsPkgMgr | null {
|
|
82
|
+
if (resolveBinary('winget')) return 'winget';
|
|
83
|
+
if (resolveBinary('scoop')) return 'scoop';
|
|
84
|
+
if (resolveBinary('choco')) return 'choco';
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function detectMacPkgMgr(): 'brew' | null {
|
|
89
|
+
return resolveBinary('brew') ? 'brew' : null;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
93
|
+
// Chrome detection via puppeteer cache layout
|
|
94
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Resolve the Chrome executable path under ~/.clopen/bin using the
|
|
98
|
+
* @puppeteer/browsers cache layout. Checks common Chrome build IDs by
|
|
99
|
+
* scanning the cache directory.
|
|
100
|
+
*/
|
|
101
|
+
export function resolveClopenChromePath(): string | null {
|
|
102
|
+
const cacheDir = join(getClopenDir(), 'bin', 'chrome');
|
|
103
|
+
if (!existsSync(cacheDir)) return null;
|
|
104
|
+
|
|
105
|
+
try {
|
|
106
|
+
const entries = readdirSync(cacheDir);
|
|
107
|
+
for (const entry of entries) {
|
|
108
|
+
const buildDir = join(cacheDir, entry);
|
|
109
|
+
let candidate: string;
|
|
110
|
+
if (process.platform === 'darwin') {
|
|
111
|
+
candidate = join(buildDir, 'chrome-mac-arm64', 'Google Chrome for Testing.app', 'Contents', 'MacOS', 'Google Chrome for Testing');
|
|
112
|
+
if (existsSync(candidate)) return candidate;
|
|
113
|
+
candidate = join(buildDir, 'chrome-mac-x64', 'Google Chrome for Testing.app', 'Contents', 'MacOS', 'Google Chrome for Testing');
|
|
114
|
+
if (existsSync(candidate)) return candidate;
|
|
115
|
+
} else if (process.platform === 'win32') {
|
|
116
|
+
candidate = join(buildDir, 'chrome-win64', 'chrome.exe');
|
|
117
|
+
if (existsSync(candidate)) return candidate;
|
|
118
|
+
candidate = join(buildDir, 'chrome-win32', 'chrome.exe');
|
|
119
|
+
if (existsSync(candidate)) return candidate;
|
|
120
|
+
} else {
|
|
121
|
+
candidate = join(buildDir, 'chrome-linux64', 'chrome');
|
|
122
|
+
if (existsSync(candidate)) return candidate;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
} catch {
|
|
126
|
+
// Fall through
|
|
127
|
+
}
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function detectSystemChrome(): string | null {
|
|
132
|
+
if (process.platform === 'darwin') {
|
|
133
|
+
const paths = [
|
|
134
|
+
'/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
|
|
135
|
+
'/Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary',
|
|
136
|
+
'/Applications/Chromium.app/Contents/MacOS/Chromium'
|
|
137
|
+
];
|
|
138
|
+
for (const p of paths) if (existsSync(p)) return p;
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
if (process.platform === 'win32') {
|
|
142
|
+
const programFiles = process.env['PROGRAMFILES'] ?? 'C:\\Program Files';
|
|
143
|
+
const programFilesX86 = process.env['PROGRAMFILES(X86)'] ?? 'C:\\Program Files (x86)';
|
|
144
|
+
const localAppData = process.env['LOCALAPPDATA'] ?? join(homedir(), 'AppData', 'Local');
|
|
145
|
+
const paths = [
|
|
146
|
+
join(programFiles, 'Google', 'Chrome', 'Application', 'chrome.exe'),
|
|
147
|
+
join(programFilesX86, 'Google', 'Chrome', 'Application', 'chrome.exe'),
|
|
148
|
+
join(localAppData, 'Google', 'Chrome', 'Application', 'chrome.exe')
|
|
149
|
+
];
|
|
150
|
+
for (const p of paths) if (existsSync(p)) return p;
|
|
151
|
+
return null;
|
|
152
|
+
}
|
|
153
|
+
return resolveBinary('google-chrome')
|
|
154
|
+
?? resolveBinary('google-chrome-stable')
|
|
155
|
+
?? resolveBinary('chromium')
|
|
156
|
+
?? resolveBinary('chromium-browser');
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Preferred executable path for puppeteer. Clopen-managed install wins
|
|
161
|
+
* over system Chrome so users can keep the bundled version consistent.
|
|
162
|
+
*/
|
|
163
|
+
export function getChromeExecutablePath(): string | null {
|
|
164
|
+
return resolveClopenChromePath() ?? detectSystemChrome();
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
168
|
+
// Status detection
|
|
169
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
170
|
+
|
|
171
|
+
async function runVersion(binary: string, versionFlag = '--version'): Promise<string | null> {
|
|
172
|
+
try {
|
|
173
|
+
const proc = Bun.spawn([binary, versionFlag], { stdout: 'pipe', stderr: 'pipe' });
|
|
174
|
+
const exitCode = await proc.exited;
|
|
175
|
+
if (exitCode !== 0) return null;
|
|
176
|
+
const stdout = await new Response(proc.stdout).text();
|
|
177
|
+
const first = stdout.trim().split('\n')[0]?.trim() ?? '';
|
|
178
|
+
return first || null;
|
|
179
|
+
} catch {
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
export async function getToolStatus(tool: ToolId): Promise<ToolStatus> {
|
|
185
|
+
if (tool === 'chrome') {
|
|
186
|
+
const resolved = getChromeExecutablePath();
|
|
187
|
+
if (!resolved) return { tool, installed: false, version: null, source: null };
|
|
188
|
+
const version = await runVersion(resolved);
|
|
189
|
+
const source = resolveClopenChromePath() ? 'clopen' : 'system';
|
|
190
|
+
return { tool, installed: true, version, source };
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
const resolved = await resolveBinaryWithRefresh(tool);
|
|
194
|
+
if (!resolved) return { tool, installed: false, version: null, source: null };
|
|
195
|
+
const version = await runVersion(resolved);
|
|
196
|
+
if (!version) return { tool, installed: false, version: null, source: null };
|
|
197
|
+
return { tool, installed: true, version, source: resolved };
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
201
|
+
// Recipe resolution
|
|
202
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
203
|
+
|
|
204
|
+
async function resolveGitRecipe(): Promise<Recipe> {
|
|
205
|
+
const base: Recipe = {
|
|
206
|
+
tool: 'git',
|
|
207
|
+
autoInstallable: false,
|
|
208
|
+
missingPrereqs: [],
|
|
209
|
+
manualInstructions: []
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
if (process.platform === 'darwin') {
|
|
213
|
+
const mgr = detectMacPkgMgr();
|
|
214
|
+
base.manualInstructions.push({
|
|
215
|
+
label: 'Homebrew',
|
|
216
|
+
command: 'brew install git',
|
|
217
|
+
docs: 'https://git-scm.com/download/mac'
|
|
218
|
+
});
|
|
219
|
+
if (!mgr) {
|
|
220
|
+
base.unavailableReason = 'Homebrew not found. Install Homebrew first.';
|
|
221
|
+
base.manualInstructions.push({
|
|
222
|
+
label: 'Install Homebrew',
|
|
223
|
+
command: '/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"',
|
|
224
|
+
docs: 'https://brew.sh'
|
|
225
|
+
});
|
|
226
|
+
return base;
|
|
227
|
+
}
|
|
228
|
+
base.autoInstallable = true;
|
|
229
|
+
base.command = ['brew', 'install', 'git'];
|
|
230
|
+
base.displayCommand = 'brew install git';
|
|
231
|
+
return base;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (process.platform === 'win32') {
|
|
235
|
+
const mgr = detectWindowsPkgMgr();
|
|
236
|
+
base.manualInstructions.push(
|
|
237
|
+
{ label: 'winget', command: 'winget install --id Git.Git -e', docs: 'https://git-scm.com/download/win' },
|
|
238
|
+
{ label: 'scoop', command: 'scoop install git' },
|
|
239
|
+
{ label: 'Chocolatey', command: 'choco install git -y' }
|
|
240
|
+
);
|
|
241
|
+
if (!mgr) {
|
|
242
|
+
base.unavailableReason = 'No supported package manager found (winget / scoop / choco).';
|
|
243
|
+
return base;
|
|
244
|
+
}
|
|
245
|
+
if (mgr === 'winget') {
|
|
246
|
+
base.autoInstallable = true;
|
|
247
|
+
base.command = ['winget', 'install', '--id', 'Git.Git', '-e', '--accept-source-agreements', '--accept-package-agreements'];
|
|
248
|
+
base.displayCommand = 'winget install --id Git.Git -e';
|
|
249
|
+
return base;
|
|
250
|
+
}
|
|
251
|
+
if (mgr === 'scoop') {
|
|
252
|
+
base.autoInstallable = true;
|
|
253
|
+
base.command = ['scoop', 'install', 'git'];
|
|
254
|
+
base.displayCommand = 'scoop install git';
|
|
255
|
+
return base;
|
|
256
|
+
}
|
|
257
|
+
// choco — requires admin
|
|
258
|
+
const elevated = await isElevated();
|
|
259
|
+
if (!elevated) {
|
|
260
|
+
base.unavailableReason = 'Chocolatey requires Administrator. Run clopen as Administrator or use winget/scoop.';
|
|
261
|
+
return base;
|
|
262
|
+
}
|
|
263
|
+
base.autoInstallable = true;
|
|
264
|
+
base.command = ['choco', 'install', 'git', '-y'];
|
|
265
|
+
base.displayCommand = 'choco install git -y';
|
|
266
|
+
return base;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// Linux
|
|
270
|
+
const mgr = detectLinuxPkgMgr();
|
|
271
|
+
base.manualInstructions.push(
|
|
272
|
+
{ label: 'apt (Debian/Ubuntu)', command: 'sudo apt update && sudo apt install -y git' },
|
|
273
|
+
{ label: 'dnf (Fedora/RHEL)', command: 'sudo dnf install -y git' },
|
|
274
|
+
{ label: 'pacman (Arch)', command: 'sudo pacman -S --noconfirm git' },
|
|
275
|
+
{ label: 'apk (Alpine)', command: 'sudo apk add git' }
|
|
276
|
+
);
|
|
277
|
+
if (!mgr) {
|
|
278
|
+
base.unavailableReason = 'No supported Linux package manager found.';
|
|
279
|
+
return base;
|
|
280
|
+
}
|
|
281
|
+
const elevated = await isElevated();
|
|
282
|
+
if (!elevated) {
|
|
283
|
+
base.unavailableReason = 'Linux package install requires root. Run the command manually with sudo, or run clopen as root.';
|
|
284
|
+
return base;
|
|
285
|
+
}
|
|
286
|
+
base.autoInstallable = true;
|
|
287
|
+
if (mgr === 'apt') {
|
|
288
|
+
base.shell = { program: 'sh', args: ['-c'] };
|
|
289
|
+
base.command = ['apt-get update && apt-get install -y git'];
|
|
290
|
+
base.displayCommand = 'apt-get update && apt-get install -y git';
|
|
291
|
+
} else if (mgr === 'dnf') {
|
|
292
|
+
base.command = ['dnf', 'install', '-y', 'git'];
|
|
293
|
+
base.displayCommand = 'dnf install -y git';
|
|
294
|
+
} else if (mgr === 'pacman') {
|
|
295
|
+
base.command = ['pacman', '-S', '--noconfirm', 'git'];
|
|
296
|
+
base.displayCommand = 'pacman -S --noconfirm git';
|
|
297
|
+
} else if (mgr === 'apk') {
|
|
298
|
+
base.command = ['apk', 'add', 'git'];
|
|
299
|
+
base.displayCommand = 'apk add git';
|
|
300
|
+
} else if (mgr === 'zypper') {
|
|
301
|
+
base.command = ['zypper', '--non-interactive', 'install', 'git'];
|
|
302
|
+
base.displayCommand = 'zypper --non-interactive install git';
|
|
303
|
+
}
|
|
304
|
+
return base;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
async function resolveClaudeRecipe(): Promise<Recipe> {
|
|
308
|
+
const base: Recipe = {
|
|
309
|
+
tool: 'claude',
|
|
310
|
+
autoInstallable: false,
|
|
311
|
+
missingPrereqs: [],
|
|
312
|
+
manualInstructions: []
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
if (process.platform === 'win32') {
|
|
316
|
+
base.autoInstallable = true;
|
|
317
|
+
base.shell = { program: 'powershell.exe', args: ['-NoProfile', '-ExecutionPolicy', 'Bypass', '-Command'] };
|
|
318
|
+
base.command = ['irm https://claude.ai/install.ps1 | iex'];
|
|
319
|
+
base.displayCommand = 'irm https://claude.ai/install.ps1 | iex';
|
|
320
|
+
base.manualInstructions.push({
|
|
321
|
+
label: 'PowerShell',
|
|
322
|
+
command: 'irm https://claude.ai/install.ps1 | iex',
|
|
323
|
+
docs: 'https://docs.claude.com/en/docs/claude-code/overview'
|
|
324
|
+
});
|
|
325
|
+
return base;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
// macOS / Linux — fetch the script via Bun.fetch and pipe it to bash
|
|
329
|
+
// so curl does not need to be installed.
|
|
330
|
+
base.manualInstructions.push({
|
|
331
|
+
label: 'curl + bash',
|
|
332
|
+
command: 'curl -fsSL https://claude.ai/install.sh | bash',
|
|
333
|
+
docs: 'https://docs.claude.com/en/docs/claude-code/overview'
|
|
334
|
+
});
|
|
335
|
+
base.autoInstallable = true;
|
|
336
|
+
base.fetchAndPipe = { url: 'https://claude.ai/install.sh', interpreter: ['bash'] };
|
|
337
|
+
base.displayCommand = 'curl -fsSL https://claude.ai/install.sh | bash';
|
|
338
|
+
return base;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
async function resolveOpenCodeRecipe(): Promise<Recipe> {
|
|
342
|
+
const base: Recipe = {
|
|
343
|
+
tool: 'opencode',
|
|
344
|
+
autoInstallable: false,
|
|
345
|
+
missingPrereqs: [],
|
|
346
|
+
manualInstructions: [{
|
|
347
|
+
label: 'curl + bash',
|
|
348
|
+
command: 'curl -fsSL https://opencode.ai/install | bash',
|
|
349
|
+
docs: 'https://opencode.ai'
|
|
350
|
+
}]
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
if (process.platform === 'win32') {
|
|
354
|
+
base.unavailableReason = 'OpenCode install script is not available on Windows via PowerShell. Use WSL or the manual instructions.';
|
|
355
|
+
return base;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
base.autoInstallable = true;
|
|
359
|
+
base.fetchAndPipe = { url: 'https://opencode.ai/install', interpreter: ['bash'] };
|
|
360
|
+
base.displayCommand = 'curl -fsSL https://opencode.ai/install | bash';
|
|
361
|
+
return base;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
async function resolveChromeRecipe(): Promise<Recipe> {
|
|
365
|
+
const cacheDir = join(getClopenDir(), 'bin');
|
|
366
|
+
const base: Recipe = {
|
|
367
|
+
tool: 'chrome',
|
|
368
|
+
autoInstallable: true,
|
|
369
|
+
missingPrereqs: [],
|
|
370
|
+
manualInstructions: [{
|
|
371
|
+
label: 'Puppeteer browsers CLI',
|
|
372
|
+
command: `bun x @puppeteer/browsers install chrome@stable --path "${cacheDir}"`,
|
|
373
|
+
docs: 'https://pptr.dev/browsers-api'
|
|
374
|
+
}],
|
|
375
|
+
command: ['bun', 'x', '@puppeteer/browsers', 'install', 'chrome@stable', '--path', cacheDir],
|
|
376
|
+
displayCommand: `bun x @puppeteer/browsers install chrome@stable --path ${cacheDir}`
|
|
377
|
+
};
|
|
378
|
+
return base;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Resolve the install recipe for a tool on the current platform.
|
|
383
|
+
* Result is platform- and privilege-aware: recipes that would fail
|
|
384
|
+
* non-interactively are marked autoInstallable=false.
|
|
385
|
+
*/
|
|
386
|
+
export async function resolveRecipe(tool: ToolId): Promise<Recipe> {
|
|
387
|
+
switch (tool) {
|
|
388
|
+
case 'git': return resolveGitRecipe();
|
|
389
|
+
case 'claude': return resolveClaudeRecipe();
|
|
390
|
+
case 'opencode': return resolveOpenCodeRecipe();
|
|
391
|
+
case 'chrome': return resolveChromeRecipe();
|
|
392
|
+
}
|
|
393
|
+
}
|