@myrialabs/clopen 0.3.21 → 0.4.0
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/auth/permissions.ts +11 -1
- package/backend/chat/stream-manager.ts +14 -3
- package/backend/database/migrations/040_create_mcp_servers_table.ts +34 -0
- package/backend/database/migrations/index.ts +7 -0
- package/backend/database/queries/index.ts +3 -1
- package/backend/database/queries/mcp-server-queries.ts +166 -0
- package/backend/engine/README.md +2 -2
- package/backend/engine/adapters/claude/environment.ts +0 -17
- package/backend/engine/adapters/claude/error-handler.ts +0 -4
- package/backend/engine/adapters/codex/message-converter.ts +1 -1
- package/backend/engine/adapters/codex/stream.ts +1 -1
- package/backend/engine/adapters/copilot/message-converter.ts +1 -1
- package/backend/engine/adapters/copilot/stream.ts +1 -1
- package/backend/engine/adapters/qwen/message-converter.ts +1 -1
- package/backend/engine/adapters/qwen/stream.ts +1 -1
- package/backend/engine/docs/adapter-contract.md +2 -2
- package/backend/engine/docs/lessons-learned.md +3 -3
- package/backend/engine/docs/quick-reference.md +1 -1
- package/backend/engine/install-recipes.ts +26 -95
- package/backend/files/file-operations.test.ts +75 -0
- package/backend/files/file-operations.ts +10 -56
- package/backend/files/image-processing.test.ts +52 -0
- package/backend/files/image-processing.ts +11 -1
- package/backend/files/path-browsing.ts +141 -139
- package/backend/git/git-service.ts +13 -2
- package/backend/http/files-upload.test.ts +174 -0
- package/backend/http/files-upload.ts +27 -7
- package/backend/http/upload-temp-cleanup.ts +53 -0
- package/backend/index.ts +9 -1
- package/backend/mcp/README.md +67 -32
- package/backend/mcp/external/config.ts +200 -0
- package/backend/mcp/external/registry-client.ts +214 -0
- package/backend/mcp/external/types.ts +69 -0
- package/backend/mcp/index.ts +104 -19
- package/backend/mcp/{config.ts → internal/config.ts} +82 -18
- package/backend/mcp/internal/remote-server.test.ts +150 -0
- package/backend/mcp/{remote-server.ts → internal/remote-server.ts} +68 -0
- package/backend/mcp/{servers → internal/servers}/browser-automation/actions.ts +1 -1
- package/backend/mcp/{servers → internal/servers}/browser-automation/browser.ts +1 -1
- package/backend/mcp/{servers → internal/servers}/browser-automation/index.ts +2 -0
- package/backend/mcp/{servers → internal/servers}/browser-automation/inspection.ts +1 -1
- package/backend/mcp/{servers → internal/servers}/helper.ts +11 -0
- package/backend/mcp/{servers → internal/servers}/index.ts +0 -2
- package/backend/mcp/{types.ts → internal/types.ts} +3 -3
- package/backend/mcp/shared/constants.ts +66 -0
- package/backend/projects/project-cleanup.ts +1 -1
- package/backend/terminal/pty-session-manager.ts +18 -11
- package/backend/ws/engine/index.ts +3 -1
- package/backend/ws/engine/restart.ts +54 -0
- package/backend/ws/files/index.ts +5 -0
- package/backend/ws/files/reveal.ts +61 -0
- package/backend/ws/files/search.test.ts +115 -0
- package/backend/ws/files/search.ts +77 -26
- package/backend/ws/files/write.ts +3 -1
- package/backend/ws/git/branch-name.ts +170 -0
- package/backend/ws/git/branch.ts +15 -2
- package/backend/ws/git/commit-message.ts +8 -2
- package/backend/ws/git/index.ts +3 -1
- package/backend/ws/index.ts +5 -1
- package/backend/ws/mcp/catalog.ts +56 -0
- package/backend/ws/mcp/crud.ts +174 -0
- package/backend/ws/mcp/index.ts +18 -0
- package/backend/ws/user/crud.ts +8 -4
- package/dist/assets/main-B7f2Gzb3.css +1 -0
- package/dist/assets/main-DYt1fDrp.js +383 -0
- package/dist/index.html +2 -2
- package/package.json +1 -1
- package/shared/constants/git.ts +5 -0
- package/shared/types/git.ts +5 -0
- package/shared/types/stores/settings.ts +19 -0
- package/backend/mcp/servers/weather/get-temperature.ts +0 -56
- package/backend/mcp/servers/weather/index.ts +0 -31
- package/dist/assets/main-BgOiIS43.js +0 -360
- package/dist/assets/main-CJdJeen6.css +0 -1
- /package/backend/mcp/{output-validator.test.ts → internal/output-validator.test.ts} +0 -0
- /package/backend/mcp/{output-validator.ts → internal/output-validator.ts} +0 -0
- /package/backend/mcp/{project-context.test.ts → internal/project-context.test.ts} +0 -0
- /package/backend/mcp/{project-context.ts → internal/project-context.ts} +0 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, mock, test } from 'bun:test';
|
|
2
|
+
import { rm, mkdir, stat } from 'node:fs/promises';
|
|
3
|
+
import { join } from 'node:path';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
5
|
+
|
|
6
|
+
// Stub settingsQueries so the module under test never touches a real database.
|
|
7
|
+
await mock.module('../database/queries', () => ({
|
|
8
|
+
settingsQueries: {
|
|
9
|
+
get: () => null,
|
|
10
|
+
getAll: () => [],
|
|
11
|
+
set: () => {},
|
|
12
|
+
delete: () => {}
|
|
13
|
+
}
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
const { deleteOperation, renameOperation, createDirectoryOperation } = await import('./file-operations');
|
|
17
|
+
|
|
18
|
+
// Shell-special name that would break cmd /c or rm -f via argument injection.
|
|
19
|
+
const SPECIAL_NAME = 'foo & bar.txt';
|
|
20
|
+
|
|
21
|
+
describe('file-operations — shell-special filenames', () => {
|
|
22
|
+
let testDir: string;
|
|
23
|
+
|
|
24
|
+
beforeEach(async () => {
|
|
25
|
+
testDir = join(tmpdir(), `clopen-file-ops-test-${Date.now()}-${Math.random().toString(36).slice(2)}`);
|
|
26
|
+
await mkdir(testDir, { recursive: true });
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
afterEach(async () => {
|
|
30
|
+
await rm(testDir, { recursive: true, force: true });
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('deleteOperation removes a file whose name contains shell metacharacters', async () => {
|
|
34
|
+
const filePath = join(testDir, SPECIAL_NAME);
|
|
35
|
+
await Bun.write(filePath, 'contents');
|
|
36
|
+
|
|
37
|
+
await expect(deleteOperation(filePath)).resolves.toMatchObject({ message: 'File deleted successfully' });
|
|
38
|
+
await expect(stat(filePath)).rejects.toThrow();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('deleteOperation removes an empty directory', async () => {
|
|
42
|
+
const dirPath = join(testDir, 'empty-dir');
|
|
43
|
+
await mkdir(dirPath, { recursive: true });
|
|
44
|
+
|
|
45
|
+
await expect(deleteOperation(dirPath)).resolves.toMatchObject({ message: 'Directory deleted successfully' });
|
|
46
|
+
await expect(stat(dirPath)).rejects.toThrow();
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test('deleteOperation force-removes a non-empty directory', async () => {
|
|
50
|
+
const dirPath = join(testDir, 'non-empty-dir');
|
|
51
|
+
await mkdir(dirPath, { recursive: true });
|
|
52
|
+
await Bun.write(join(dirPath, 'child.txt'), 'contents');
|
|
53
|
+
|
|
54
|
+
await expect(deleteOperation(dirPath, true)).resolves.toMatchObject({ message: 'Directory deleted successfully' });
|
|
55
|
+
await expect(stat(dirPath)).rejects.toThrow();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('renameOperation renames a file whose name contains shell metacharacters', async () => {
|
|
59
|
+
const src = join(testDir, SPECIAL_NAME);
|
|
60
|
+
const dest = join(testDir, 'safe-name.txt');
|
|
61
|
+
await Bun.write(src, 'contents');
|
|
62
|
+
|
|
63
|
+
await expect(renameOperation(src, dest)).resolves.toMatchObject({ message: 'File/directory renamed successfully' });
|
|
64
|
+
await expect(stat(dest)).resolves.toBeTruthy();
|
|
65
|
+
await expect(stat(src)).rejects.toThrow();
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('createDirectoryOperation creates a directory whose name contains shell metacharacters', async () => {
|
|
69
|
+
const dirPath = join(testDir, 'dir & name');
|
|
70
|
+
|
|
71
|
+
await expect(createDirectoryOperation(dirPath)).resolves.toMatchObject({ message: 'Directory created successfully' });
|
|
72
|
+
const s = await stat(dirPath);
|
|
73
|
+
expect(s.isDirectory()).toBe(true);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
@@ -1,46 +1,18 @@
|
|
|
1
1
|
import { dirname, extname, join } from 'path';
|
|
2
|
-
import { stat as fsStat } from 'node:fs/promises';
|
|
2
|
+
import { mkdir as fsMkdir, readdir as fsReaddir, rename as fsRename, rmdir as fsRmdir, stat as fsStat, unlink as fsUnlink, rm as fsRm } from 'node:fs/promises';
|
|
3
3
|
|
|
4
4
|
import { debug } from '$shared/utils/logger';
|
|
5
5
|
import { validateFileSize } from './file-size-limit';
|
|
6
6
|
|
|
7
|
-
//
|
|
8
|
-
const { spawn } = Bun;
|
|
9
|
-
|
|
10
|
-
// Bun-compatible readdir implementation (cross-platform)
|
|
7
|
+
// Cross-platform readdir using fs.promises
|
|
11
8
|
async function readdir(path: string): Promise<string[]> {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
proc = Bun.spawn(['cmd', '/c', 'dir', '/b', '/a', path], { stdout: 'pipe', stderr: 'ignore' });
|
|
15
|
-
} else {
|
|
16
|
-
proc = Bun.spawn(['ls', '-1A', path], { stdout: 'pipe', stderr: 'ignore' });
|
|
17
|
-
}
|
|
18
|
-
const result = await new Response(proc.stdout).text();
|
|
19
|
-
// Split and clean up, removing \r characters for Windows compatibility
|
|
20
|
-
return result.trim().split(/\r?\n/).map(line => line.trim()).filter(Boolean);
|
|
9
|
+
const entries = await fsReaddir(path, { withFileTypes: true });
|
|
10
|
+
return entries.map(e => e.name);
|
|
21
11
|
}
|
|
22
12
|
|
|
23
13
|
async function mkdir(path: string, options?: { recursive?: boolean }) {
|
|
24
|
-
// Pure Bun approach: create directory by writing a temp file
|
|
25
14
|
try {
|
|
26
|
-
|
|
27
|
-
await Bun.write(tempFile, '');
|
|
28
|
-
// Clean up the temp file
|
|
29
|
-
try {
|
|
30
|
-
if (process.platform === 'win32') {
|
|
31
|
-
await spawn(['cmd', '/c', 'del', '/f', '/q', tempFile.replace(/\//g, '\\')], {
|
|
32
|
-
stdout: 'ignore',
|
|
33
|
-
stderr: 'ignore'
|
|
34
|
-
}).exited;
|
|
35
|
-
} else {
|
|
36
|
-
await spawn(['rm', '-f', tempFile], {
|
|
37
|
-
stdout: 'ignore',
|
|
38
|
-
stderr: 'ignore'
|
|
39
|
-
}).exited;
|
|
40
|
-
}
|
|
41
|
-
} catch {
|
|
42
|
-
// Ignore cleanup errors
|
|
43
|
-
}
|
|
15
|
+
await fsMkdir(path, { recursive: options?.recursive ?? false });
|
|
44
16
|
} catch (error) {
|
|
45
17
|
throw new Error(`Failed to create directory ${path}: ${error}`);
|
|
46
18
|
}
|
|
@@ -79,37 +51,19 @@ async function copyDirectory(src: string, dest: string) {
|
|
|
79
51
|
}
|
|
80
52
|
|
|
81
53
|
async function rename(oldPath: string, newPath: string) {
|
|
82
|
-
|
|
83
|
-
const proc = spawn(['cmd', '/c', 'move', oldPath.replace(/\//g, '\\'), newPath.replace(/\//g, '\\')], { stdout: 'ignore', stderr: 'ignore' });
|
|
84
|
-
await proc.exited;
|
|
85
|
-
} else {
|
|
86
|
-
const proc = spawn(['mv', oldPath, newPath], { stdout: 'ignore', stderr: 'ignore' });
|
|
87
|
-
await proc.exited;
|
|
88
|
-
}
|
|
54
|
+
await fsRename(oldPath, newPath);
|
|
89
55
|
}
|
|
90
56
|
|
|
91
57
|
async function unlink(path: string) {
|
|
92
|
-
|
|
93
|
-
const proc = spawn(['cmd', '/c', 'del', '/f', '/q', path.replace(/\//g, '\\')], { stdout: 'ignore', stderr: 'ignore' });
|
|
94
|
-
await proc.exited;
|
|
95
|
-
} else {
|
|
96
|
-
const proc = spawn(['rm', '-f', path], { stdout: 'ignore', stderr: 'ignore' });
|
|
97
|
-
await proc.exited;
|
|
98
|
-
}
|
|
58
|
+
await fsUnlink(path);
|
|
99
59
|
}
|
|
100
60
|
|
|
101
61
|
async function rm(path: string, options?: { recursive?: boolean }) {
|
|
102
|
-
|
|
103
|
-
const proc = spawn(['cmd', '/c', 'rmdir', '/s', '/q', path.replace(/\//g, '\\')], { stdout: 'ignore', stderr: 'ignore' });
|
|
104
|
-
await proc.exited;
|
|
105
|
-
} else {
|
|
106
|
-
const proc = spawn(['rm', '-rf', path], { stdout: 'ignore', stderr: 'ignore' });
|
|
107
|
-
await proc.exited;
|
|
108
|
-
}
|
|
62
|
+
await fsRm(path, { recursive: options?.recursive ?? false, force: true });
|
|
109
63
|
}
|
|
110
64
|
|
|
111
|
-
async function rmdir(path: string
|
|
112
|
-
|
|
65
|
+
async function rmdir(path: string) {
|
|
66
|
+
await fsRmdir(path);
|
|
113
67
|
}
|
|
114
68
|
|
|
115
69
|
export async function writeFileOperation(filePath: string, content: string, baseModified?: string) {
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { describe, expect, mock, test } from 'bun:test';
|
|
2
|
+
|
|
3
|
+
// Stub sharp before importing the module under test so no real image I/O
|
|
4
|
+
// happens during unit tests. mockPages is set per-test to control metadata.
|
|
5
|
+
let mockPages: number | undefined;
|
|
6
|
+
|
|
7
|
+
await mock.module('sharp', () => ({
|
|
8
|
+
default: (_input: unknown, _opts?: unknown) => ({
|
|
9
|
+
metadata: () =>
|
|
10
|
+
Promise.resolve({
|
|
11
|
+
width: 100,
|
|
12
|
+
height: 100,
|
|
13
|
+
format: 'gif',
|
|
14
|
+
pages: mockPages,
|
|
15
|
+
}),
|
|
16
|
+
}),
|
|
17
|
+
}));
|
|
18
|
+
|
|
19
|
+
// Stub file-size-limit so the database is never touched.
|
|
20
|
+
await mock.module('./file-size-limit', () => ({
|
|
21
|
+
validateFileSize: () => {},
|
|
22
|
+
}));
|
|
23
|
+
|
|
24
|
+
const { processImageEdit } = await import('./image-processing');
|
|
25
|
+
|
|
26
|
+
const RECIPE = { output: { format: 'gif' as const } };
|
|
27
|
+
|
|
28
|
+
describe('processImageEdit — animation frame limit', () => {
|
|
29
|
+
test('rejects when frame count exceeds the 100-frame limit', async () => {
|
|
30
|
+
mockPages = 101;
|
|
31
|
+
await expect(processImageEdit('/dev/null', RECIPE)).rejects.toThrow(
|
|
32
|
+
'Cannot process animated image: 101 frames exceeds the limit of 100'
|
|
33
|
+
);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('error message includes the actual and maximum frame counts', async () => {
|
|
37
|
+
mockPages = 500;
|
|
38
|
+
await expect(processImageEdit('/dev/null', RECIPE)).rejects.toThrow(
|
|
39
|
+
'Cannot process animated image: 500 frames exceeds the limit of 100'
|
|
40
|
+
);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('allows animated images at exactly 100 frames', async () => {
|
|
44
|
+
mockPages = 100;
|
|
45
|
+
await expect(processImageEdit('/dev/null', RECIPE)).resolves.toBeDefined();
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
test('allows static images with no pages field', async () => {
|
|
49
|
+
mockPages = undefined;
|
|
50
|
+
await expect(processImageEdit('/dev/null', RECIPE)).resolves.toBeDefined();
|
|
51
|
+
});
|
|
52
|
+
});
|
|
@@ -27,6 +27,9 @@ export interface ProcessedImage {
|
|
|
27
27
|
size: number;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
/** Hard cap on animation frames — prevents resource exhaustion via GIF bomb. */
|
|
31
|
+
const MAX_ANIMATION_FRAMES = 100;
|
|
32
|
+
|
|
30
33
|
/** Clamp a value into [min, max], rounding to an integer. */
|
|
31
34
|
function clampInt(value: number, min: number, max: number): number {
|
|
32
35
|
return Math.max(min, Math.min(max, Math.round(value)));
|
|
@@ -193,6 +196,13 @@ export async function processImageEdit(
|
|
|
193
196
|
throw new Error('Source file is not a readable image');
|
|
194
197
|
}
|
|
195
198
|
|
|
199
|
+
const frameCount = srcMeta.pages ?? 1;
|
|
200
|
+
if (frameCount > MAX_ANIMATION_FRAMES) {
|
|
201
|
+
throw new Error(
|
|
202
|
+
`Cannot process animated image: ${frameCount} frames exceeds the limit of ${MAX_ANIMATION_FRAMES}`
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
|
|
196
206
|
// Nothing to do: not compressing, no edits, and the format is unchanged →
|
|
197
207
|
// return the original bytes verbatim so an untouched file stays identical.
|
|
198
208
|
const compress = recipe.output.compress ?? false;
|
|
@@ -208,7 +218,7 @@ export async function processImageEdit(
|
|
|
208
218
|
};
|
|
209
219
|
}
|
|
210
220
|
|
|
211
|
-
const animated =
|
|
221
|
+
const animated = frameCount > 1;
|
|
212
222
|
const rotate = recipe.rotate ?? 0;
|
|
213
223
|
|
|
214
224
|
let pipeline: Sharp;
|
|
@@ -1,19 +1,34 @@
|
|
|
1
1
|
import { join, extname } from 'path';
|
|
2
|
+
import { readdir as fsReaddir } from 'node:fs/promises';
|
|
2
3
|
import { existsSync } from 'fs';
|
|
3
4
|
|
|
4
5
|
import { debug } from '$shared/utils/logger';
|
|
5
6
|
|
|
6
|
-
//
|
|
7
|
+
// Cross-platform readdir using fs.promises
|
|
7
8
|
async function readdir(path: string): Promise<string[]> {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
const entries = await fsReaddir(path, { withFileTypes: true });
|
|
10
|
+
return entries.map(e => e.name);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async function statIfExists(path: string): Promise<Awaited<ReturnType<ReturnType<typeof Bun.file>['stat']>> | null> {
|
|
14
|
+
try {
|
|
15
|
+
return await Bun.file(path).stat();
|
|
16
|
+
} catch {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Returns true when every visible entry is a .app bundle or the "Applications" alias —
|
|
22
|
+
// the signature of a DMG/installer mount, not a general-purpose volume.
|
|
23
|
+
async function isLikelyMacAppVolume(volumePath: string): Promise<boolean> {
|
|
24
|
+
try {
|
|
25
|
+
const entries = await readdir(volumePath);
|
|
26
|
+
const visible = entries.filter(e => !e.startsWith('.'));
|
|
27
|
+
if (visible.length === 0) return false;
|
|
28
|
+
return visible.every(e => e.endsWith('.app') || e === 'Applications');
|
|
29
|
+
} catch {
|
|
30
|
+
return false;
|
|
13
31
|
}
|
|
14
|
-
const result = await new Response(proc.stdout).text();
|
|
15
|
-
// Split and clean up, removing \r characters for Windows compatibility
|
|
16
|
-
return result.trim().split(/\r?\n/).map(line => line.trim()).filter(Boolean);
|
|
17
32
|
}
|
|
18
33
|
|
|
19
34
|
// Return types
|
|
@@ -29,6 +44,7 @@ export interface PathBrowseData {
|
|
|
29
44
|
type: 'file' | 'directory';
|
|
30
45
|
path: string;
|
|
31
46
|
modified: string;
|
|
47
|
+
kind?: 'home' | 'root' | 'volume' | 'drive';
|
|
32
48
|
size?: number;
|
|
33
49
|
extension?: string;
|
|
34
50
|
}>;
|
|
@@ -58,6 +74,16 @@ export async function handlePathBrowsing(path: string): Promise<PathBrowseData>
|
|
|
58
74
|
targetPath = path;
|
|
59
75
|
}
|
|
60
76
|
|
|
77
|
+
// Windows: a bare drive letter ("C:") is drive-relative — it points at the
|
|
78
|
+
// drive's *current* directory, not its root. Path normalization (resolve /
|
|
79
|
+
// realpath) and manual entry can both strip the trailing separator, which
|
|
80
|
+
// then makes join() produce drive-relative child paths like "C:Users" whose
|
|
81
|
+
// stat() fails, leaving the listing empty. Append the separator so we always
|
|
82
|
+
// browse the drive root.
|
|
83
|
+
if (/^[A-Za-z]:$/.test(targetPath)) {
|
|
84
|
+
targetPath += '\\';
|
|
85
|
+
}
|
|
86
|
+
|
|
61
87
|
// Check if path exists (use stat instead of exists for directories)
|
|
62
88
|
const file = Bun.file(targetPath);
|
|
63
89
|
const stats = await file.stat();
|
|
@@ -161,165 +187,138 @@ export async function handlePathBrowsing(path: string): Promise<PathBrowseData>
|
|
|
161
187
|
|
|
162
188
|
// Helper function to handle Unix mount points listing (Linux, macOS, etc.)
|
|
163
189
|
export async function handleUnixMountPoints(): Promise<PathBrowseData> {
|
|
164
|
-
const
|
|
190
|
+
const items: Array<{
|
|
165
191
|
name: string;
|
|
166
192
|
type: 'file' | 'directory';
|
|
167
193
|
path: string;
|
|
168
194
|
modified: string;
|
|
169
|
-
|
|
170
|
-
extension?: string;
|
|
195
|
+
kind: 'home' | 'root' | 'volume';
|
|
171
196
|
}> = [];
|
|
172
197
|
|
|
173
|
-
//
|
|
174
|
-
const rootFile = Bun.file('/');
|
|
175
|
-
if (await rootFile.exists()) {
|
|
176
|
-
const stats = await rootFile.stat();
|
|
177
|
-
commonMountPoints.push({
|
|
178
|
-
name: 'Root (/) Filesystem',
|
|
179
|
-
type: 'directory',
|
|
180
|
-
path: '/',
|
|
181
|
-
modified: stats.mtime.toISOString()
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
// Add user home directory
|
|
198
|
+
// Home directory — all Unix platforms
|
|
186
199
|
const homeDir = process.env.HOME;
|
|
187
200
|
if (homeDir) {
|
|
188
|
-
const
|
|
189
|
-
if (
|
|
190
|
-
|
|
191
|
-
commonMountPoints.push({
|
|
192
|
-
name: 'Home Directory',
|
|
193
|
-
type: 'directory',
|
|
194
|
-
path: homeDir,
|
|
195
|
-
modified: stats.mtime.toISOString()
|
|
196
|
-
});
|
|
201
|
+
const stats = await statIfExists(homeDir);
|
|
202
|
+
if (stats?.isDirectory()) {
|
|
203
|
+
items.push({ name: 'Home Directory', type: 'directory', path: homeDir, modified: stats.mtime.toISOString(), kind: 'home' });
|
|
197
204
|
}
|
|
198
205
|
}
|
|
199
206
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
'/
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
const stats = await mountFile.stat();
|
|
216
|
-
if (stats.isDirectory()) {
|
|
217
|
-
let displayName = mountPath;
|
|
218
|
-
|
|
219
|
-
// Special names for common directories
|
|
220
|
-
switch (mountPath) {
|
|
221
|
-
case '/mnt':
|
|
222
|
-
displayName = 'Mount Points (/mnt)';
|
|
223
|
-
break;
|
|
224
|
-
case '/media':
|
|
225
|
-
displayName = 'Media (/media)';
|
|
226
|
-
break;
|
|
227
|
-
case '/Volumes':
|
|
228
|
-
displayName = 'Volumes (/Volumes)';
|
|
229
|
-
break;
|
|
230
|
-
case '/usr':
|
|
231
|
-
displayName = 'System (/usr)';
|
|
232
|
-
break;
|
|
233
|
-
case '/var':
|
|
234
|
-
displayName = 'Variable (/var)';
|
|
235
|
-
break;
|
|
236
|
-
case '/opt':
|
|
237
|
-
displayName = 'Optional (/opt)';
|
|
238
|
-
break;
|
|
239
|
-
case '/tmp':
|
|
240
|
-
displayName = 'Temporary (/tmp)';
|
|
241
|
-
break;
|
|
207
|
+
if (process.platform === 'darwin') {
|
|
208
|
+
// macOS: enumerate /Volumes/* — skip installer/DMG mounts
|
|
209
|
+
const volumesStats = await statIfExists('/Volumes');
|
|
210
|
+
if (volumesStats?.isDirectory()) {
|
|
211
|
+
try {
|
|
212
|
+
const volumeNames = await readdir('/Volumes');
|
|
213
|
+
for (const name of volumeNames) {
|
|
214
|
+
const vPath = `/Volumes/${name}`;
|
|
215
|
+
try {
|
|
216
|
+
const vStats = await statIfExists(vPath);
|
|
217
|
+
if (!vStats?.isDirectory()) continue;
|
|
218
|
+
if (await isLikelyMacAppVolume(vPath)) continue;
|
|
219
|
+
items.push({ name, type: 'directory', path: vPath, modified: vStats.mtime.toISOString(), kind: 'volume' });
|
|
220
|
+
} catch {
|
|
221
|
+
// Skip inaccessible volumes
|
|
242
222
|
}
|
|
243
|
-
|
|
244
|
-
commonMountPoints.push({
|
|
245
|
-
name: displayName,
|
|
246
|
-
type: 'directory',
|
|
247
|
-
path: mountPath,
|
|
248
|
-
modified: stats.mtime.toISOString()
|
|
249
|
-
});
|
|
250
223
|
}
|
|
224
|
+
} catch {
|
|
225
|
+
// Skip if /Volumes is unreadable
|
|
251
226
|
}
|
|
252
|
-
} catch {
|
|
253
|
-
// Skip inaccessible mount points
|
|
254
227
|
}
|
|
255
|
-
}
|
|
228
|
+
} else if (process.platform === 'linux') {
|
|
229
|
+
// Linux: root + /mnt/*, /media/*, /run/media/{user}/* (systemd automount)
|
|
230
|
+
const rootStats = await statIfExists('/');
|
|
231
|
+
if (rootStats?.isDirectory()) {
|
|
232
|
+
items.push({ name: 'Root (/) Filesystem', type: 'directory', path: '/', modified: rootStats.mtime.toISOString(), kind: 'root' });
|
|
233
|
+
}
|
|
256
234
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
if (stats.isDirectory()) {
|
|
269
|
-
commonMountPoints.push({
|
|
270
|
-
name: `${volume} Volume`,
|
|
271
|
-
type: 'directory',
|
|
272
|
-
path: volumePath,
|
|
273
|
-
modified: stats.mtime.toISOString()
|
|
274
|
-
});
|
|
235
|
+
for (const base of ['/mnt', '/media']) {
|
|
236
|
+
const baseStats = await statIfExists(base);
|
|
237
|
+
if (!baseStats?.isDirectory()) continue;
|
|
238
|
+
try {
|
|
239
|
+
const entries = await readdir(base);
|
|
240
|
+
for (const entry of entries) {
|
|
241
|
+
const entryPath = `${base}/${entry}`;
|
|
242
|
+
try {
|
|
243
|
+
const entryStats = await statIfExists(entryPath);
|
|
244
|
+
if (entryStats?.isDirectory()) {
|
|
245
|
+
items.push({ name: entry, type: 'directory', path: entryPath, modified: entryStats.mtime.toISOString(), kind: 'volume' });
|
|
275
246
|
}
|
|
247
|
+
} catch {
|
|
248
|
+
// Skip inaccessible mounts
|
|
276
249
|
}
|
|
277
|
-
} catch {
|
|
278
|
-
// Skip inaccessible volumes
|
|
279
250
|
}
|
|
251
|
+
} catch {
|
|
252
|
+
// Skip if base is unreadable
|
|
280
253
|
}
|
|
281
|
-
} catch {
|
|
282
|
-
// Skip if can't read /Volumes
|
|
283
254
|
}
|
|
284
|
-
}
|
|
285
255
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
const
|
|
293
|
-
|
|
294
|
-
const
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
path: mountPath,
|
|
304
|
-
modified: stats.mtime.toISOString()
|
|
305
|
-
});
|
|
256
|
+
// systemd automount: /run/media/{user}/{volume}
|
|
257
|
+
const runMediaStats = await statIfExists('/run/media');
|
|
258
|
+
if (runMediaStats?.isDirectory()) {
|
|
259
|
+
try {
|
|
260
|
+
const users = await readdir('/run/media');
|
|
261
|
+
for (const user of users) {
|
|
262
|
+
const userPath = `/run/media/${user}`;
|
|
263
|
+
try {
|
|
264
|
+
const userStats = await statIfExists(userPath);
|
|
265
|
+
if (!userStats?.isDirectory()) continue;
|
|
266
|
+
const volumes = await readdir(userPath);
|
|
267
|
+
for (const vol of volumes) {
|
|
268
|
+
const volPath = `${userPath}/${vol}`;
|
|
269
|
+
try {
|
|
270
|
+
const volStats = await statIfExists(volPath);
|
|
271
|
+
if (volStats?.isDirectory()) {
|
|
272
|
+
items.push({ name: vol, type: 'directory', path: volPath, modified: volStats.mtime.toISOString(), kind: 'volume' });
|
|
306
273
|
}
|
|
274
|
+
} catch {
|
|
275
|
+
// Skip inaccessible
|
|
307
276
|
}
|
|
308
|
-
} catch {
|
|
309
|
-
// Skip inaccessible mounts
|
|
310
277
|
}
|
|
278
|
+
} catch {
|
|
279
|
+
// Skip inaccessible user dir
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
} catch {
|
|
283
|
+
// Skip if /run/media is unreadable
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
} else {
|
|
287
|
+
// Other Unix (FreeBSD, OpenBSD, etc.): root + /mnt and /media subdirectories
|
|
288
|
+
const rootStats = await statIfExists('/');
|
|
289
|
+
if (rootStats?.isDirectory()) {
|
|
290
|
+
items.push({ name: 'Root (/) Filesystem', type: 'directory', path: '/', modified: rootStats.mtime.toISOString(), kind: 'root' });
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
for (const base of ['/mnt', '/media']) {
|
|
294
|
+
const baseStats = await statIfExists(base);
|
|
295
|
+
if (!baseStats?.isDirectory()) continue;
|
|
296
|
+
try {
|
|
297
|
+
const entries = await readdir(base);
|
|
298
|
+
for (const entry of entries) {
|
|
299
|
+
const entryPath = `${base}/${entry}`;
|
|
300
|
+
try {
|
|
301
|
+
const entryStats = await statIfExists(entryPath);
|
|
302
|
+
if (entryStats?.isDirectory()) {
|
|
303
|
+
items.push({ name: entry, type: 'directory', path: entryPath, modified: entryStats.mtime.toISOString(), kind: 'volume' });
|
|
304
|
+
}
|
|
305
|
+
} catch {
|
|
306
|
+
// Skip inaccessible
|
|
311
307
|
}
|
|
312
|
-
} catch {
|
|
313
|
-
// Skip if can't read mount directory
|
|
314
308
|
}
|
|
309
|
+
} catch {
|
|
310
|
+
// Skip if base is unreadable
|
|
315
311
|
}
|
|
316
312
|
}
|
|
317
313
|
}
|
|
318
314
|
|
|
319
|
-
//
|
|
320
|
-
const
|
|
321
|
-
|
|
322
|
-
|
|
315
|
+
// Deduplicate by path
|
|
316
|
+
const seen = new Set<string>();
|
|
317
|
+
const uniqueMounts = items.filter(item => {
|
|
318
|
+
if (seen.has(item.path)) return false;
|
|
319
|
+
seen.add(item.path);
|
|
320
|
+
return true;
|
|
321
|
+
});
|
|
323
322
|
|
|
324
323
|
return {
|
|
325
324
|
name: 'System',
|
|
@@ -341,6 +340,7 @@ export async function handleWindowsDrives(): Promise<PathBrowseData> {
|
|
|
341
340
|
type: 'file' | 'directory';
|
|
342
341
|
path: string;
|
|
343
342
|
modified: string;
|
|
343
|
+
kind: 'drive';
|
|
344
344
|
size?: number;
|
|
345
345
|
extension?: string;
|
|
346
346
|
}> = [];
|
|
@@ -364,7 +364,8 @@ export async function handleWindowsDrives(): Promise<PathBrowseData> {
|
|
|
364
364
|
name: `${drive} Drive`,
|
|
365
365
|
type: 'directory',
|
|
366
366
|
path: drivePath,
|
|
367
|
-
modified: new Date().toISOString()
|
|
367
|
+
modified: new Date().toISOString(),
|
|
368
|
+
kind: 'drive'
|
|
368
369
|
});
|
|
369
370
|
}
|
|
370
371
|
|
|
@@ -378,7 +379,8 @@ export async function handleWindowsDrives(): Promise<PathBrowseData> {
|
|
|
378
379
|
name: `${drive} Drive`,
|
|
379
380
|
type: 'directory',
|
|
380
381
|
path: drivePath,
|
|
381
|
-
modified: new Date().toISOString()
|
|
382
|
+
modified: new Date().toISOString(),
|
|
383
|
+
kind: 'drive'
|
|
382
384
|
});
|
|
383
385
|
}
|
|
384
386
|
} catch {
|
|
@@ -317,6 +317,14 @@ export class GitService {
|
|
|
317
317
|
}
|
|
318
318
|
}
|
|
319
319
|
|
|
320
|
+
async checkoutCommit(cwd: string, commitHash: string): Promise<void> {
|
|
321
|
+
assertSafeGitRevish(commitHash, 'commit hash');
|
|
322
|
+
const result = await execGit(['checkout', commitHash], cwd);
|
|
323
|
+
if (result.exitCode !== 0) {
|
|
324
|
+
throw new Error(`git checkout failed: ${result.stderr}`);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
320
328
|
async deleteBranch(cwd: string, name: string, force = false): Promise<void> {
|
|
321
329
|
assertSafeGitRevish(name, 'branch name');
|
|
322
330
|
const flag = force ? '-D' : '-d';
|
|
@@ -335,9 +343,12 @@ export class GitService {
|
|
|
335
343
|
}
|
|
336
344
|
}
|
|
337
345
|
|
|
338
|
-
async mergeBranch(cwd: string, branchName: string): Promise<{ success: boolean; message: string }> {
|
|
346
|
+
async mergeBranch(cwd: string, branchName: string, noFastForward = false): Promise<{ success: boolean; message: string }> {
|
|
339
347
|
assertSafeGitRevish(branchName, 'merge branch');
|
|
340
|
-
const
|
|
348
|
+
const args = ['merge'];
|
|
349
|
+
if (noFastForward) args.push('--no-ff');
|
|
350
|
+
args.push(branchName);
|
|
351
|
+
const result = await execGit(args, cwd);
|
|
341
352
|
return {
|
|
342
353
|
success: result.exitCode === 0,
|
|
343
354
|
message: result.exitCode === 0 ? result.stdout : result.stderr
|