@myrialabs/clopen 0.3.8 → 0.3.10
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 +22 -19
- package/backend/auth/auth-service.ts +56 -1
- package/backend/auth/permissions.ts +66 -2
- package/backend/auth/session-cleanup.ts +58 -0
- package/backend/chat/stream-manager.ts +143 -13
- package/backend/database/migrations/032_seed_copilot_provider.ts +19 -0
- package/backend/database/migrations/033_seed_codex_provider.ts +19 -0
- package/backend/database/migrations/034_seed_qwen_provider.ts +119 -0
- package/backend/database/migrations/035_add_owner_to_db_client_connections.ts +34 -0
- package/backend/database/migrations/index.ts +29 -1
- package/backend/database/queries/db-client-connection-queries.ts +160 -54
- package/backend/database/queries/engine-queries.ts +12 -0
- package/backend/database/queries/project-queries.ts +10 -5
- package/backend/db-client/connection-manager.ts +9 -3
- package/backend/engine/README.md +1702 -0
- package/backend/engine/adapters/claude/models.ts +141 -0
- package/backend/engine/adapters/claude/stream.ts +1 -1
- package/backend/engine/adapters/codex/credential.ts +179 -0
- package/backend/engine/adapters/codex/error-handler.ts +65 -0
- package/backend/engine/adapters/codex/index.ts +1 -0
- package/backend/engine/adapters/codex/message-converter.ts +646 -0
- package/backend/engine/adapters/codex/models.ts +105 -0
- package/backend/engine/adapters/codex/patch-rollout.ts +169 -0
- package/backend/engine/adapters/codex/session-fork.ts +149 -0
- package/backend/engine/adapters/codex/stream.ts +310 -0
- package/backend/engine/adapters/codex/usage-rollout.ts +145 -0
- package/backend/engine/adapters/copilot/error-handler.ts +94 -0
- package/backend/engine/adapters/copilot/index.ts +1 -0
- package/backend/engine/adapters/copilot/message-converter.ts +973 -0
- package/backend/engine/adapters/copilot/models.ts +92 -0
- package/backend/engine/adapters/copilot/session-fork.ts +111 -0
- package/backend/engine/adapters/copilot/stream.ts +570 -0
- package/backend/engine/adapters/opencode/config.ts +56 -104
- package/backend/engine/adapters/opencode/error-handler.ts +71 -0
- package/backend/engine/adapters/opencode/models.ts +79 -0
- package/backend/engine/adapters/opencode/presets.ts +91 -0
- package/backend/engine/adapters/opencode/stream.ts +8 -114
- package/backend/engine/adapters/qwen/credential.ts +78 -0
- package/backend/engine/adapters/qwen/environment.ts +84 -0
- package/backend/engine/adapters/qwen/error-handler.ts +71 -0
- package/backend/engine/adapters/qwen/index.ts +1 -0
- package/backend/engine/adapters/qwen/message-converter.ts +1055 -0
- package/backend/engine/adapters/qwen/models.ts +81 -0
- package/backend/engine/adapters/qwen/presets.ts +51 -0
- package/backend/engine/adapters/qwen/session-fork.ts +97 -0
- package/backend/engine/adapters/qwen/stream.ts +379 -0
- package/backend/engine/index.ts +35 -0
- package/backend/engine/install-recipes.ts +80 -1
- package/backend/engine/install-runner.ts +4 -0
- package/backend/files/path-browsing.ts +20 -0
- package/backend/git/git-service.ts +81 -11
- package/backend/git/git-spawn-validation.test.ts +75 -0
- package/backend/git/git-spawn-validation.ts +77 -0
- package/backend/index.ts +5 -0
- package/backend/mcp/README.md +84 -14
- package/backend/mcp/config.ts +218 -17
- package/backend/mcp/index.ts +2 -0
- package/backend/mcp/project-context.ts +55 -0
- package/backend/mcp/servers/browser-automation/actions.ts +6 -1
- package/backend/mcp/servers/helper.ts +13 -0
- package/backend/middleware/error-handler.ts +16 -2
- package/backend/preview/browser/browser-preview-service.ts +4 -4
- package/backend/preview/browser/browser-tab-manager.ts +23 -3
- package/backend/snapshot/gitignore.ts +4 -9
- package/backend/tunnel/cloudflared/binary.ts +2 -2
- package/backend/tunnel/global-tunnel-manager.ts +9 -3
- package/backend/utils/ws.ts +5 -1
- package/backend/ws/README.md +128 -3
- package/backend/ws/access.ts +56 -0
- package/backend/ws/auth/index.ts +14 -0
- package/backend/ws/auth/login.ts +3 -0
- package/backend/ws/auth/users.ts +61 -1
- package/backend/ws/chat/stream.ts +139 -22
- package/backend/ws/db-client/access.ts +19 -0
- package/backend/ws/db-client/connections.ts +31 -17
- package/backend/ws/db-client/io.ts +7 -9
- package/backend/ws/db-client/query.ts +86 -32
- package/backend/ws/db-client/schema.ts +9 -4
- package/backend/ws/db-client/structure.ts +22 -10
- package/backend/ws/engine/access.ts +39 -0
- package/backend/ws/engine/claude/accounts.ts +15 -10
- package/backend/ws/engine/codex/accounts.ts +516 -0
- package/backend/ws/engine/codex/index.ts +14 -0
- package/backend/ws/engine/codex/status.ts +87 -0
- package/backend/ws/engine/copilot/accounts.ts +122 -0
- package/backend/ws/engine/copilot/index.ts +13 -0
- package/backend/ws/engine/copilot/status.ts +54 -0
- package/backend/ws/engine/index.ts +7 -1
- package/backend/ws/engine/opencode/providers.ts +1 -1
- package/backend/ws/engine/qwen/accounts.ts +137 -0
- package/backend/ws/engine/qwen/index.ts +15 -0
- package/backend/ws/engine/qwen/presets.ts +40 -0
- package/backend/ws/engine/qwen/status.ts +54 -0
- package/backend/ws/files/path-access.ts +101 -0
- package/backend/ws/files/read.ts +26 -11
- package/backend/ws/files/search.ts +10 -6
- package/backend/ws/files/state.ts +3 -0
- package/backend/ws/files/watch.ts +7 -1
- package/backend/ws/files/write.ts +109 -15
- package/backend/ws/git/branch.ts +13 -19
- package/backend/ws/git/commit-message.ts +3 -4
- package/backend/ws/git/commit.ts +5 -7
- package/backend/ws/git/conflict.ts +7 -10
- package/backend/ws/git/diff.ts +7 -10
- package/backend/ws/git/log.ts +3 -4
- package/backend/ws/git/remote.ts +30 -43
- package/backend/ws/git/staging.ts +13 -19
- package/backend/ws/git/status.ts +7 -11
- package/backend/ws/messages/crud.ts +7 -13
- package/backend/ws/preview/access.ts +45 -0
- package/backend/ws/preview/browser/cleanup.ts +3 -11
- package/backend/ws/preview/browser/console.ts +7 -42
- package/backend/ws/preview/browser/interact.ts +2 -6
- package/backend/ws/preview/browser/native-ui.ts +5 -18
- package/backend/ws/preview/browser/stats.ts +2 -12
- package/backend/ws/preview/browser/tab-info.ts +4 -20
- package/backend/ws/preview/browser/tab.ts +4 -27
- package/backend/ws/preview/browser/webcodecs.ts +6 -47
- package/backend/ws/projects/crud.ts +15 -16
- package/backend/ws/projects/status.ts +5 -1
- package/backend/ws/sessions/crud.ts +31 -36
- package/backend/ws/settings/crud.ts +13 -13
- package/backend/ws/snapshot/restore.ts +5 -2
- package/backend/ws/snapshot/timeline.ts +3 -1
- package/backend/ws/system-tools/access.ts +28 -0
- package/backend/ws/system-tools/install.ts +13 -4
- package/backend/ws/system-tools/status.ts +5 -2
- package/backend/ws/terminal/access.ts +56 -0
- package/backend/ws/terminal/persistence.ts +13 -7
- package/backend/ws/terminal/session.ts +35 -14
- package/backend/ws/terminal/stream.ts +4 -1
- package/dist/assets/{index-DqAGCTFT.js → index-C1afGwHY.js} +2 -2
- package/dist/assets/main-CZb3Y_Z_.js +315 -0
- package/dist/assets/main-Cn8cX2DY.css +1 -0
- package/dist/index.html +2 -2
- package/package.json +5 -1
- package/shared/constants/engines.ts +45 -140
- package/shared/types/database/schema.ts +1 -0
- package/shared/types/unified/common.ts +1 -1
- package/shared/types/unified/engine.ts +29 -1
- package/shared/types/unified/index.ts +2 -0
- package/shared/types/unified/message.ts +1 -1
- package/shared/types/unified/tool.ts +17 -2
- package/shared/utils/ws-server.ts +14 -0
- package/dist/assets/main-DsED0rLr.js +0 -304
- package/dist/assets/main-eWY9R8g9.css +0 -1
|
@@ -20,7 +20,7 @@ import { getClopenDir } from '$backend/utils/paths';
|
|
|
20
20
|
import { resolveBinary, resolveBinaryWithRefresh } from '$backend/utils/cli';
|
|
21
21
|
import { resolveStaticCurlAsset } from '$backend/utils/static-curl';
|
|
22
22
|
|
|
23
|
-
export type ToolId = 'git' | 'claude' | 'opencode' | 'chrome' | 'cloudflared';
|
|
23
|
+
export type ToolId = 'git' | 'claude' | 'opencode' | 'copilot' | 'codex' | 'qwen' | 'chrome' | 'cloudflared';
|
|
24
24
|
|
|
25
25
|
export interface ManualInstruction {
|
|
26
26
|
label: string;
|
|
@@ -409,6 +409,82 @@ async function resolveOpenCodeRecipe(): Promise<Recipe> {
|
|
|
409
409
|
return base;
|
|
410
410
|
}
|
|
411
411
|
|
|
412
|
+
async function resolveCopilotRecipe(): Promise<Recipe> {
|
|
413
|
+
const base: Recipe = {
|
|
414
|
+
tool: 'copilot',
|
|
415
|
+
autoInstallable: true,
|
|
416
|
+
missingPrereqs: [],
|
|
417
|
+
manualInstructions: [{
|
|
418
|
+
label: 'bun',
|
|
419
|
+
command: 'bun add -g @github/copilot',
|
|
420
|
+
docs: 'https://docs.github.com/en/copilot/how-tos/copilot-cli/set-up-copilot-cli/install-copilot-cli'
|
|
421
|
+
}],
|
|
422
|
+
command: ['bun', 'add', '-g', '@github/copilot'],
|
|
423
|
+
displayCommand: 'bun add -g @github/copilot'
|
|
424
|
+
};
|
|
425
|
+
return base;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
async function resolveQwenRecipe(): Promise<Recipe> {
|
|
429
|
+
const manualInstructions: ManualInstruction[] = [{
|
|
430
|
+
label: 'bun',
|
|
431
|
+
command: 'bun add -g @qwen-code/qwen-code',
|
|
432
|
+
docs: 'https://github.com/QwenLM/qwen-code'
|
|
433
|
+
}];
|
|
434
|
+
|
|
435
|
+
// Qwen Code CLI ships bundled with `@qwen-code/sdk` from v0.1.1+ so the
|
|
436
|
+
// SDK path doesn't need a standalone install. We still expose this recipe
|
|
437
|
+
// for users who prefer the standalone CLI for `qwen-oauth` / shell use.
|
|
438
|
+
if (!resolveBinary('bun')) {
|
|
439
|
+
return {
|
|
440
|
+
tool: 'qwen',
|
|
441
|
+
autoInstallable: false,
|
|
442
|
+
unavailableReason: 'Bun is required to install the Qwen Code CLI. Install Bun first (https://bun.sh).',
|
|
443
|
+
missingPrereqs: [],
|
|
444
|
+
manualInstructions
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
return {
|
|
449
|
+
tool: 'qwen',
|
|
450
|
+
autoInstallable: true,
|
|
451
|
+
missingPrereqs: [],
|
|
452
|
+
manualInstructions,
|
|
453
|
+
command: ['bun', 'add', '-g', '@qwen-code/qwen-code'],
|
|
454
|
+
displayCommand: 'bun add -g @qwen-code/qwen-code'
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
async function resolveCodexRecipe(): Promise<Recipe> {
|
|
459
|
+
const manualInstructions: ManualInstruction[] = [{
|
|
460
|
+
label: 'bun',
|
|
461
|
+
command: 'bun add -g @openai/codex',
|
|
462
|
+
docs: 'https://developers.openai.com/codex'
|
|
463
|
+
}];
|
|
464
|
+
|
|
465
|
+
// Codex CLI is installed via `bun add -g`. Bun must be on PATH for the
|
|
466
|
+
// auto-installer to work; otherwise we fall back to the manual instructions
|
|
467
|
+
// (the user installs Bun first via the existing Bun recipe / website).
|
|
468
|
+
if (!resolveBinary('bun')) {
|
|
469
|
+
return {
|
|
470
|
+
tool: 'codex',
|
|
471
|
+
autoInstallable: false,
|
|
472
|
+
unavailableReason: 'Bun is required to install the Codex CLI. Install Bun first (https://bun.sh).',
|
|
473
|
+
missingPrereqs: [],
|
|
474
|
+
manualInstructions
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
return {
|
|
479
|
+
tool: 'codex',
|
|
480
|
+
autoInstallable: true,
|
|
481
|
+
missingPrereqs: [],
|
|
482
|
+
manualInstructions,
|
|
483
|
+
command: ['bun', 'add', '-g', '@openai/codex'],
|
|
484
|
+
displayCommand: 'bun add -g @openai/codex'
|
|
485
|
+
};
|
|
486
|
+
}
|
|
487
|
+
|
|
412
488
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
413
489
|
// Chrome recipe — Puppeteer download (macOS/Windows) or Google Chrome (Linux)
|
|
414
490
|
// ─────────────────────────────────────────────────────────────────────────────
|
|
@@ -660,6 +736,9 @@ export async function resolveRecipe(tool: ToolId): Promise<Recipe> {
|
|
|
660
736
|
case 'git': return resolveGitRecipe();
|
|
661
737
|
case 'claude': return resolveClaudeRecipe();
|
|
662
738
|
case 'opencode': return resolveOpenCodeRecipe();
|
|
739
|
+
case 'copilot': return resolveCopilotRecipe();
|
|
740
|
+
case 'codex': return resolveCodexRecipe();
|
|
741
|
+
case 'qwen': return resolveQwenRecipe();
|
|
663
742
|
case 'chrome': return resolveChromeRecipe();
|
|
664
743
|
case 'cloudflared': return resolveCloudflaredRecipe();
|
|
665
744
|
}
|
|
@@ -361,6 +361,10 @@ export function getSession(sessionId: string) {
|
|
|
361
361
|
return session ? sessionSnapshot(session) : null;
|
|
362
362
|
}
|
|
363
363
|
|
|
364
|
+
export function getSessionOwner(sessionId: string): string | null {
|
|
365
|
+
return sessions.get(sessionId)?.startedBy ?? null;
|
|
366
|
+
}
|
|
367
|
+
|
|
364
368
|
export function getActiveSessionForTool(tool: ToolId) {
|
|
365
369
|
const id = activeByTool.get(tool);
|
|
366
370
|
if (!id) return null;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { join, extname } from 'path';
|
|
2
|
+
import { existsSync } from 'fs';
|
|
2
3
|
|
|
3
4
|
import { debug } from '$shared/utils/logger';
|
|
4
5
|
|
|
@@ -367,6 +368,25 @@ export async function handleWindowsDrives(): Promise<PathBrowseData> {
|
|
|
367
368
|
});
|
|
368
369
|
}
|
|
369
370
|
|
|
371
|
+
if (drives.length === 0) {
|
|
372
|
+
for (let code = 65; code <= 90; code++) {
|
|
373
|
+
const drive = String.fromCharCode(code) + ':';
|
|
374
|
+
const drivePath = drive + '\\';
|
|
375
|
+
try {
|
|
376
|
+
if (existsSync(drivePath)) {
|
|
377
|
+
drives.push({
|
|
378
|
+
name: `${drive} Drive`,
|
|
379
|
+
type: 'directory',
|
|
380
|
+
path: drivePath,
|
|
381
|
+
modified: new Date().toISOString()
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
} catch {
|
|
385
|
+
// Skip unavailable drives.
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
370
390
|
// If no drives found, throw error
|
|
371
391
|
if (drives.length === 0) {
|
|
372
392
|
throw new Error('Unable to list drives');
|
|
@@ -24,6 +24,14 @@ import type {
|
|
|
24
24
|
GitConflictFile
|
|
25
25
|
} from '$shared/types/git';
|
|
26
26
|
import { debug } from '$shared/utils/logger';
|
|
27
|
+
import {
|
|
28
|
+
assertSafeGitCommitMessage,
|
|
29
|
+
assertSafeGitPathOperand,
|
|
30
|
+
assertSafeGitRemoteName,
|
|
31
|
+
assertSafeGitRemoteUrl,
|
|
32
|
+
assertSafeGitRevish,
|
|
33
|
+
assertSafeGitShowRef
|
|
34
|
+
} from './git-spawn-validation';
|
|
27
35
|
|
|
28
36
|
export class GitService {
|
|
29
37
|
/**
|
|
@@ -45,7 +53,10 @@ export class GitService {
|
|
|
45
53
|
*/
|
|
46
54
|
async init(cwd: string, defaultBranch?: string): Promise<void> {
|
|
47
55
|
const args = ['init'];
|
|
48
|
-
if (defaultBranch)
|
|
56
|
+
if (defaultBranch) {
|
|
57
|
+
assertSafeGitRevish(defaultBranch, 'default branch');
|
|
58
|
+
args.push('-b', defaultBranch);
|
|
59
|
+
}
|
|
49
60
|
const result = await execGit(args, cwd);
|
|
50
61
|
if (result.exitCode !== 0) {
|
|
51
62
|
throw new Error(`git init failed: ${result.stderr}`);
|
|
@@ -69,6 +80,7 @@ export class GitService {
|
|
|
69
80
|
// ============================================
|
|
70
81
|
|
|
71
82
|
async stageFile(cwd: string, filePath: string): Promise<void> {
|
|
83
|
+
assertSafeGitPathOperand(filePath, 'stage path');
|
|
72
84
|
const result = await execGit(['add', '--', filePath], cwd);
|
|
73
85
|
if (result.exitCode !== 0) {
|
|
74
86
|
throw new Error(`git add failed: ${result.stderr}`);
|
|
@@ -83,10 +95,11 @@ export class GitService {
|
|
|
83
95
|
}
|
|
84
96
|
|
|
85
97
|
async unstageFile(cwd: string, filePath: string): Promise<void> {
|
|
98
|
+
assertSafeGitPathOperand(filePath, 'unstage path');
|
|
86
99
|
// Try normal reset first, fall back to rm --cached for initial commit
|
|
87
100
|
const result = await execGit(['reset', 'HEAD', '--', filePath], cwd);
|
|
88
101
|
if (result.exitCode !== 0) {
|
|
89
|
-
const fallback = await execGit(['rm', '--cached', '--', filePath], cwd);
|
|
102
|
+
const fallback = await execGit(['rm', '--cached', '--', filePath], cwd); // filePath validated above
|
|
90
103
|
if (fallback.exitCode !== 0) {
|
|
91
104
|
throw new Error(`git unstage failed: ${result.stderr}`);
|
|
92
105
|
}
|
|
@@ -105,6 +118,7 @@ export class GitService {
|
|
|
105
118
|
}
|
|
106
119
|
|
|
107
120
|
async discardFile(cwd: string, filePath: string): Promise<void> {
|
|
121
|
+
assertSafeGitPathOperand(filePath, 'discard path');
|
|
108
122
|
// Check if file is untracked
|
|
109
123
|
const statusResult = await execGit(['status', '--porcelain=v1', '--', filePath], cwd);
|
|
110
124
|
const statusLine = statusResult.stdout.trim();
|
|
@@ -135,6 +149,7 @@ export class GitService {
|
|
|
135
149
|
// ============================================
|
|
136
150
|
|
|
137
151
|
async commit(cwd: string, message: string): Promise<string> {
|
|
152
|
+
assertSafeGitCommitMessage(message);
|
|
138
153
|
const result = await execGit(['commit', '-m', message], cwd);
|
|
139
154
|
if (result.exitCode !== 0) {
|
|
140
155
|
throw new Error(`git commit failed: ${result.stderr}`);
|
|
@@ -147,6 +162,7 @@ export class GitService {
|
|
|
147
162
|
async amendCommit(cwd: string, message?: string): Promise<string> {
|
|
148
163
|
const args = ['commit', '--amend'];
|
|
149
164
|
if (message) {
|
|
165
|
+
assertSafeGitCommitMessage(message);
|
|
150
166
|
args.push('-m', message);
|
|
151
167
|
} else {
|
|
152
168
|
args.push('--no-edit');
|
|
@@ -165,24 +181,33 @@ export class GitService {
|
|
|
165
181
|
|
|
166
182
|
async getDiffUnstaged(cwd: string, filePath?: string): Promise<GitFileDiff[]> {
|
|
167
183
|
const args = ['diff'];
|
|
168
|
-
if (filePath)
|
|
184
|
+
if (filePath) {
|
|
185
|
+
assertSafeGitPathOperand(filePath, 'diff path');
|
|
186
|
+
args.push('--', filePath);
|
|
187
|
+
}
|
|
169
188
|
const result = await execGit(args, cwd);
|
|
170
189
|
return parseDiff(result.stdout);
|
|
171
190
|
}
|
|
172
191
|
|
|
173
192
|
async getDiffStaged(cwd: string, filePath?: string): Promise<GitFileDiff[]> {
|
|
174
193
|
const args = ['diff', '--cached'];
|
|
175
|
-
if (filePath)
|
|
194
|
+
if (filePath) {
|
|
195
|
+
assertSafeGitPathOperand(filePath, 'diff path');
|
|
196
|
+
args.push('--', filePath);
|
|
197
|
+
}
|
|
176
198
|
const result = await execGit(args, cwd);
|
|
177
199
|
return parseDiff(result.stdout);
|
|
178
200
|
}
|
|
179
201
|
|
|
180
202
|
async getDiffCommit(cwd: string, commitHash: string): Promise<GitFileDiff[]> {
|
|
203
|
+
assertSafeGitRevish(commitHash, 'commit hash');
|
|
181
204
|
const result = await execGit(['diff', `${commitHash}^`, commitHash], cwd);
|
|
182
205
|
return parseDiff(result.stdout);
|
|
183
206
|
}
|
|
184
207
|
|
|
185
208
|
async getDiffBetween(cwd: string, from: string, to: string): Promise<GitFileDiff[]> {
|
|
209
|
+
assertSafeGitRevish(from, 'diff from');
|
|
210
|
+
assertSafeGitRevish(to, 'diff to');
|
|
186
211
|
const result = await execGit(['diff', from, to], cwd);
|
|
187
212
|
return parseDiff(result.stdout);
|
|
188
213
|
}
|
|
@@ -192,6 +217,8 @@ export class GitService {
|
|
|
192
217
|
* Returns null when the file does not exist at that ref (untracked / new file).
|
|
193
218
|
*/
|
|
194
219
|
async getFileAtRef(cwd: string, ref: string, filePath: string): Promise<string | null> {
|
|
220
|
+
assertSafeGitShowRef(ref);
|
|
221
|
+
assertSafeGitPathOperand(filePath, 'show path');
|
|
195
222
|
const result = await execGit(['show', `${ref}:${filePath}`], cwd);
|
|
196
223
|
if (result.exitCode !== 0) {
|
|
197
224
|
return null;
|
|
@@ -247,8 +274,12 @@ export class GitService {
|
|
|
247
274
|
}
|
|
248
275
|
|
|
249
276
|
async createBranch(cwd: string, name: string, startPoint?: string): Promise<void> {
|
|
277
|
+
assertSafeGitRevish(name, 'branch name');
|
|
250
278
|
const args = ['checkout', '-b', name];
|
|
251
|
-
if (startPoint)
|
|
279
|
+
if (startPoint) {
|
|
280
|
+
assertSafeGitRevish(startPoint, 'start point');
|
|
281
|
+
args.push(startPoint);
|
|
282
|
+
}
|
|
252
283
|
const result = await execGit(args, cwd);
|
|
253
284
|
if (result.exitCode !== 0) {
|
|
254
285
|
throw new Error(`git checkout -b failed: ${result.stderr}`);
|
|
@@ -256,6 +287,7 @@ export class GitService {
|
|
|
256
287
|
}
|
|
257
288
|
|
|
258
289
|
async switchBranch(cwd: string, name: string): Promise<void> {
|
|
290
|
+
assertSafeGitRevish(name, 'branch name');
|
|
259
291
|
const result = await execGit(['checkout', name], cwd);
|
|
260
292
|
if (result.exitCode !== 0) {
|
|
261
293
|
throw new Error(`git checkout failed: ${result.stderr}`);
|
|
@@ -263,6 +295,7 @@ export class GitService {
|
|
|
263
295
|
}
|
|
264
296
|
|
|
265
297
|
async deleteBranch(cwd: string, name: string, force = false): Promise<void> {
|
|
298
|
+
assertSafeGitRevish(name, 'branch name');
|
|
266
299
|
const flag = force ? '-D' : '-d';
|
|
267
300
|
const result = await execGit(['branch', flag, name], cwd);
|
|
268
301
|
if (result.exitCode !== 0) {
|
|
@@ -271,6 +304,8 @@ export class GitService {
|
|
|
271
304
|
}
|
|
272
305
|
|
|
273
306
|
async renameBranch(cwd: string, oldName: string, newName: string): Promise<void> {
|
|
307
|
+
assertSafeGitRevish(oldName, 'old branch name');
|
|
308
|
+
assertSafeGitRevish(newName, 'new branch name');
|
|
274
309
|
const result = await execGit(['branch', '-m', oldName, newName], cwd);
|
|
275
310
|
if (result.exitCode !== 0) {
|
|
276
311
|
throw new Error(`git branch -m failed: ${result.stderr}`);
|
|
@@ -278,6 +313,7 @@ export class GitService {
|
|
|
278
313
|
}
|
|
279
314
|
|
|
280
315
|
async mergeBranch(cwd: string, branchName: string): Promise<{ success: boolean; message: string }> {
|
|
316
|
+
assertSafeGitRevish(branchName, 'merge branch');
|
|
281
317
|
const result = await execGit(['merge', branchName], cwd);
|
|
282
318
|
return {
|
|
283
319
|
success: result.exitCode === 0,
|
|
@@ -301,7 +337,10 @@ export class GitService {
|
|
|
301
337
|
`--skip=${skip}`
|
|
302
338
|
];
|
|
303
339
|
|
|
304
|
-
if (branch)
|
|
340
|
+
if (branch) {
|
|
341
|
+
assertSafeGitRevish(branch, 'log branch');
|
|
342
|
+
args.push(branch);
|
|
343
|
+
}
|
|
305
344
|
|
|
306
345
|
const result = await execGit(args, cwd);
|
|
307
346
|
if (result.exitCode !== 0) {
|
|
@@ -313,7 +352,8 @@ export class GitService {
|
|
|
313
352
|
if (hasMore) commits.pop(); // Remove the extra one
|
|
314
353
|
|
|
315
354
|
// Get total count
|
|
316
|
-
const
|
|
355
|
+
const countRef = branch ?? 'HEAD';
|
|
356
|
+
const countResult = await execGit(['rev-list', '--count', countRef], cwd);
|
|
317
357
|
const total = parseInt(countResult.stdout.trim()) || commits.length;
|
|
318
358
|
|
|
319
359
|
return { commits, total, hasMore };
|
|
@@ -329,6 +369,7 @@ export class GitService {
|
|
|
329
369
|
}
|
|
330
370
|
|
|
331
371
|
async fetch(cwd: string, remote = 'origin'): Promise<string> {
|
|
372
|
+
assertSafeGitRemoteName(remote);
|
|
332
373
|
// Use explicit refspec to ensure all branches are fetched regardless of clone config
|
|
333
374
|
const result = await execGit(['fetch', remote, `+refs/heads/*:refs/remotes/${remote}/*`, '--prune'], cwd, 60000);
|
|
334
375
|
if (result.exitCode !== 0) {
|
|
@@ -338,8 +379,12 @@ export class GitService {
|
|
|
338
379
|
}
|
|
339
380
|
|
|
340
381
|
async pull(cwd: string, remote = 'origin', branch?: string): Promise<{ success: boolean; message: string }> {
|
|
382
|
+
assertSafeGitRemoteName(remote);
|
|
341
383
|
const args = ['pull', remote];
|
|
342
|
-
if (branch)
|
|
384
|
+
if (branch) {
|
|
385
|
+
assertSafeGitRevish(branch, 'pull branch');
|
|
386
|
+
args.push(branch);
|
|
387
|
+
}
|
|
343
388
|
const result = await execGit(args, cwd, 60000);
|
|
344
389
|
return {
|
|
345
390
|
success: result.exitCode === 0,
|
|
@@ -348,8 +393,12 @@ export class GitService {
|
|
|
348
393
|
}
|
|
349
394
|
|
|
350
395
|
async push(cwd: string, remote = 'origin', branch?: string, force = false): Promise<{ success: boolean; message: string }> {
|
|
396
|
+
assertSafeGitRemoteName(remote);
|
|
351
397
|
const args = ['push', remote];
|
|
352
|
-
if (branch)
|
|
398
|
+
if (branch) {
|
|
399
|
+
assertSafeGitRevish(branch, 'push branch');
|
|
400
|
+
args.push(branch);
|
|
401
|
+
}
|
|
353
402
|
if (force) args.push('--force-with-lease');
|
|
354
403
|
// Set upstream if needed
|
|
355
404
|
args.push('-u');
|
|
@@ -361,6 +410,8 @@ export class GitService {
|
|
|
361
410
|
}
|
|
362
411
|
|
|
363
412
|
async addRemote(cwd: string, name: string, url: string): Promise<void> {
|
|
413
|
+
assertSafeGitRemoteName(name);
|
|
414
|
+
assertSafeGitRemoteUrl(url);
|
|
364
415
|
const result = await execGit(['remote', 'add', name, url], cwd);
|
|
365
416
|
if (result.exitCode !== 0) {
|
|
366
417
|
throw new Error(`git remote add failed: ${result.stderr}`);
|
|
@@ -368,6 +419,7 @@ export class GitService {
|
|
|
368
419
|
}
|
|
369
420
|
|
|
370
421
|
async removeRemote(cwd: string, name: string): Promise<void> {
|
|
422
|
+
assertSafeGitRemoteName(name);
|
|
371
423
|
const result = await execGit(['remote', 'remove', name], cwd);
|
|
372
424
|
if (result.exitCode !== 0) {
|
|
373
425
|
throw new Error(`git remote remove failed: ${result.stderr}`);
|
|
@@ -385,7 +437,10 @@ export class GitService {
|
|
|
385
437
|
|
|
386
438
|
async stashSave(cwd: string, message?: string): Promise<void> {
|
|
387
439
|
const args = ['stash', 'push'];
|
|
388
|
-
if (message)
|
|
440
|
+
if (message) {
|
|
441
|
+
assertSafeGitCommitMessage(message);
|
|
442
|
+
args.push('-m', message);
|
|
443
|
+
}
|
|
389
444
|
const result = await execGit(args, cwd);
|
|
390
445
|
if (result.exitCode !== 0) {
|
|
391
446
|
throw new Error(`git stash failed: ${result.stderr}`);
|
|
@@ -393,6 +448,9 @@ export class GitService {
|
|
|
393
448
|
}
|
|
394
449
|
|
|
395
450
|
async stashPop(cwd: string, index = 0): Promise<void> {
|
|
451
|
+
if (!Number.isInteger(index) || index < 0) {
|
|
452
|
+
throw new Error('Invalid stash index');
|
|
453
|
+
}
|
|
396
454
|
const result = await execGit(['stash', 'pop', `stash@{${index}}`], cwd);
|
|
397
455
|
if (result.exitCode !== 0) {
|
|
398
456
|
throw new Error(`git stash pop failed: ${result.stderr}`);
|
|
@@ -400,6 +458,9 @@ export class GitService {
|
|
|
400
458
|
}
|
|
401
459
|
|
|
402
460
|
async stashDrop(cwd: string, index = 0): Promise<void> {
|
|
461
|
+
if (!Number.isInteger(index) || index < 0) {
|
|
462
|
+
throw new Error('Invalid stash index');
|
|
463
|
+
}
|
|
403
464
|
const result = await execGit(['stash', 'drop', `stash@{${index}}`], cwd);
|
|
404
465
|
if (result.exitCode !== 0) {
|
|
405
466
|
throw new Error(`git stash drop failed: ${result.stderr}`);
|
|
@@ -435,13 +496,18 @@ export class GitService {
|
|
|
435
496
|
}
|
|
436
497
|
|
|
437
498
|
async createTag(cwd: string, name: string, message?: string, commitHash?: string): Promise<void> {
|
|
499
|
+
assertSafeGitRevish(name, 'tag name');
|
|
438
500
|
const args = ['tag'];
|
|
439
501
|
if (message) {
|
|
502
|
+
assertSafeGitCommitMessage(message);
|
|
440
503
|
args.push('-a', name, '-m', message);
|
|
441
504
|
} else {
|
|
442
505
|
args.push(name);
|
|
443
506
|
}
|
|
444
|
-
if (commitHash)
|
|
507
|
+
if (commitHash) {
|
|
508
|
+
assertSafeGitRevish(commitHash, 'tag target');
|
|
509
|
+
args.push(commitHash);
|
|
510
|
+
}
|
|
445
511
|
const result = await execGit(args, cwd);
|
|
446
512
|
if (result.exitCode !== 0) {
|
|
447
513
|
throw new Error(`git tag failed: ${result.stderr}`);
|
|
@@ -449,6 +515,7 @@ export class GitService {
|
|
|
449
515
|
}
|
|
450
516
|
|
|
451
517
|
async deleteTag(cwd: string, name: string): Promise<void> {
|
|
518
|
+
assertSafeGitRevish(name, 'tag name');
|
|
452
519
|
const result = await execGit(['tag', '-d', name], cwd);
|
|
453
520
|
if (result.exitCode !== 0) {
|
|
454
521
|
throw new Error(`git tag -d failed: ${result.stderr}`);
|
|
@@ -456,6 +523,8 @@ export class GitService {
|
|
|
456
523
|
}
|
|
457
524
|
|
|
458
525
|
async pushTag(cwd: string, name: string, remote = 'origin'): Promise<{ success: boolean; message: string }> {
|
|
526
|
+
assertSafeGitRemoteName(remote);
|
|
527
|
+
assertSafeGitRevish(name, 'tag name');
|
|
459
528
|
const result = await execGit(['push', remote, name], cwd, 60000);
|
|
460
529
|
return {
|
|
461
530
|
success: result.exitCode === 0,
|
|
@@ -492,6 +561,7 @@ export class GitService {
|
|
|
492
561
|
resolution: 'ours' | 'theirs' | 'custom',
|
|
493
562
|
customContent?: string
|
|
494
563
|
): Promise<void> {
|
|
564
|
+
assertSafeGitPathOperand(filePath, 'conflict path');
|
|
495
565
|
if (resolution === 'custom' && customContent !== undefined) {
|
|
496
566
|
// Write custom content
|
|
497
567
|
const { writeFile } = await import('node:fs/promises');
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test';
|
|
2
|
+
import {
|
|
3
|
+
assertSafeGitCommitMessage,
|
|
4
|
+
assertSafeGitPathOperand,
|
|
5
|
+
assertSafeGitRemoteName,
|
|
6
|
+
assertSafeGitRemoteUrl,
|
|
7
|
+
assertSafeGitRevish,
|
|
8
|
+
assertSafeGitShowRef
|
|
9
|
+
} from './git-spawn-validation';
|
|
10
|
+
|
|
11
|
+
describe('assertSafeGitRevish', () => {
|
|
12
|
+
test('accepts typical branch and hash tokens', () => {
|
|
13
|
+
expect(() => assertSafeGitRevish('main', 'x')).not.toThrow();
|
|
14
|
+
expect(() => assertSafeGitRevish('feature/foo-bar', 'x')).not.toThrow();
|
|
15
|
+
expect(() => assertSafeGitRevish('abc123deadbeef', 'x')).not.toThrow();
|
|
16
|
+
expect(() => assertSafeGitRevish('HEAD', 'x')).not.toThrow();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('rejects option-shaped values', () => {
|
|
20
|
+
expect(() => assertSafeGitRevish('--output=/tmp/pwn', 'branch')).toThrow(/must not start/);
|
|
21
|
+
expect(() => assertSafeGitRevish('-c', 'branch')).toThrow(/must not start/);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('rejects NUL and newlines', () => {
|
|
25
|
+
expect(() => assertSafeGitRevish('a\nb', 'branch')).toThrow();
|
|
26
|
+
expect(() => assertSafeGitRevish('a\0b', 'branch')).toThrow();
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe('assertSafeGitRemoteName', () => {
|
|
31
|
+
test('accepts origin', () => {
|
|
32
|
+
expect(() => assertSafeGitRemoteName('origin')).not.toThrow();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('rejects spaces and specials', () => {
|
|
36
|
+
expect(() => assertSafeGitRemoteName('my remote')).toThrow(/Invalid git remote name/);
|
|
37
|
+
expect(() => assertSafeGitRemoteName('-bad')).toThrow();
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
describe('assertSafeGitRemoteUrl', () => {
|
|
42
|
+
test('accepts normal https url', () => {
|
|
43
|
+
expect(() => assertSafeGitRemoteUrl('https://github.com/foo/bar.git')).not.toThrow();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('rejects argv injection prefix', () => {
|
|
47
|
+
expect(() => assertSafeGitRemoteUrl('-force evil')).toThrow();
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
describe('assertSafeGitShowRef', () => {
|
|
52
|
+
test('rejects colon in ref', () => {
|
|
53
|
+
expect(() => assertSafeGitShowRef('HEAD:readme')).toThrow(/must not contain/);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe('assertSafeGitPathOperand', () => {
|
|
58
|
+
test('allows normal relative paths', () => {
|
|
59
|
+
expect(() => assertSafeGitPathOperand('src/index.ts')).not.toThrow();
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test('rejects newlines', () => {
|
|
63
|
+
expect(() => assertSafeGitPathOperand('a\nb')).toThrow();
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
describe('assertSafeGitCommitMessage', () => {
|
|
68
|
+
test('allows multiline messages', () => {
|
|
69
|
+
expect(() => assertSafeGitCommitMessage('line1\nline2')).not.toThrow();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test('rejects NUL', () => {
|
|
73
|
+
expect(() => assertSafeGitCommitMessage('a\0b')).toThrow();
|
|
74
|
+
});
|
|
75
|
+
});
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Guards for values passed into git CLI argv arrays.
|
|
3
|
+
*
|
|
4
|
+
* Bun.spawn / execGit use argv mode (no shell), but git itself still parses
|
|
5
|
+
* leading `-` tokens as options. User-controlled branch / remote / ref names
|
|
6
|
+
* must therefore be rejected when they look like flags.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const MAX_GIT_ARG = 8192;
|
|
10
|
+
const MAX_COMMIT_MESSAGE = 256 * 1024;
|
|
11
|
+
|
|
12
|
+
/** Branch names, tag names, commit-ish, remote names in refspecs, etc. */
|
|
13
|
+
export function assertSafeGitRevish(value: string, label: string): void {
|
|
14
|
+
if (value.length === 0) {
|
|
15
|
+
throw new Error(`${label}: value must not be empty`);
|
|
16
|
+
}
|
|
17
|
+
if (value.length > MAX_GIT_ARG) {
|
|
18
|
+
throw new Error(`${label}: value too long`);
|
|
19
|
+
}
|
|
20
|
+
if (/[\0\n\r]/.test(value)) {
|
|
21
|
+
throw new Error(`${label}: invalid control characters`);
|
|
22
|
+
}
|
|
23
|
+
if (value.startsWith('-')) {
|
|
24
|
+
throw new Error(`${label}: must not start with '-' (git option injection)`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** `git remote` names are a small charset in practice; keep strict. */
|
|
29
|
+
export function assertSafeGitRemoteName(name: string): void {
|
|
30
|
+
assertSafeGitRevish(name, 'remote name');
|
|
31
|
+
if (!/^[A-Za-z0-9._-]+$/.test(name)) {
|
|
32
|
+
throw new Error('Invalid git remote name');
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** `git remote add <name> <url>` — avoid NUL/newline and argv-shaped URLs. */
|
|
37
|
+
export function assertSafeGitRemoteUrl(url: string): void {
|
|
38
|
+
if (url.length === 0) {
|
|
39
|
+
throw new Error('remote URL must not be empty');
|
|
40
|
+
}
|
|
41
|
+
if (url.length > MAX_GIT_ARG * 8) {
|
|
42
|
+
throw new Error('remote URL too long');
|
|
43
|
+
}
|
|
44
|
+
if (/[\0\n\r]/.test(url)) {
|
|
45
|
+
throw new Error('remote URL contains invalid characters');
|
|
46
|
+
}
|
|
47
|
+
if (url.startsWith('-')) {
|
|
48
|
+
throw new Error('remote URL must not start with "-"');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Paths appended after `--` in git argv (still reject NUL / newlines). */
|
|
53
|
+
export function assertSafeGitPathOperand(path: string, label = 'path'): void {
|
|
54
|
+
if (path.length > MAX_GIT_ARG) {
|
|
55
|
+
throw new Error(`${label}: path too long`);
|
|
56
|
+
}
|
|
57
|
+
if (/[\0\n\r]/.test(path)) {
|
|
58
|
+
throw new Error(`${label}: invalid path characters`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function assertSafeGitCommitMessage(message: string): void {
|
|
63
|
+
if (message.length > MAX_COMMIT_MESSAGE) {
|
|
64
|
+
throw new Error('commit message too long');
|
|
65
|
+
}
|
|
66
|
+
if (message.includes('\0')) {
|
|
67
|
+
throw new Error('commit message contains NUL byte');
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** `ref` side of `git show rev:path` — disallow `:` so `rev` stays unambiguous. */
|
|
72
|
+
export function assertSafeGitShowRef(ref: string): void {
|
|
73
|
+
assertSafeGitRevish(ref, 'git ref');
|
|
74
|
+
if (ref.includes(':')) {
|
|
75
|
+
throw new Error('git ref for show must not contain ":"');
|
|
76
|
+
}
|
|
77
|
+
}
|
package/backend/index.ts
CHANGED
|
@@ -37,6 +37,7 @@ import { handleMcpRequest, closeMcpServer } from './mcp/remote-server';
|
|
|
37
37
|
// Auth middleware
|
|
38
38
|
import { checkRouteAccess } from './auth/permissions';
|
|
39
39
|
import { authRateLimiter } from './auth';
|
|
40
|
+
import { sessionCleanupScheduler } from './auth/session-cleanup';
|
|
40
41
|
import { ws as wsServer } from './utils/ws';
|
|
41
42
|
|
|
42
43
|
// Register auth gate on WebSocket router — blocks unauthenticated/unauthorized access
|
|
@@ -141,6 +142,8 @@ async function startServer() {
|
|
|
141
142
|
try {
|
|
142
143
|
await initializeDatabase();
|
|
143
144
|
debug.log('database', '✅ Database initialized successfully');
|
|
145
|
+
// Start expired session cleanup now that the database is ready
|
|
146
|
+
sessionCleanupScheduler.start();
|
|
144
147
|
} catch (error) {
|
|
145
148
|
debug.warn('database', '⚠️ Database initialization failed:', error);
|
|
146
149
|
}
|
|
@@ -189,6 +192,8 @@ async function gracefulShutdown() {
|
|
|
189
192
|
app.stop();
|
|
190
193
|
// Dispose rate limiter timer
|
|
191
194
|
authRateLimiter.dispose();
|
|
195
|
+
// Dispose expired session cleanup timer
|
|
196
|
+
sessionCleanupScheduler.dispose();
|
|
192
197
|
// Close MCP remote server (before engines, as they may still reference it)
|
|
193
198
|
await closeMcpServer();
|
|
194
199
|
// Cleanup browser preview sessions
|