@myrialabs/clopen 0.4.47 → 0.4.48
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 +11 -11
- package/backend/artifacts/project/sources.ts +1 -1
- package/backend/auth/auth-service.ts +52 -358
- package/backend/auth/onboarding.test.ts +2 -3
- package/backend/auth/permissions.test.ts +10 -20
- package/backend/auth/permissions.ts +4 -290
- package/backend/auth/rate-limiter.test.ts +8 -9
- package/backend/auth/rate-limiter.ts +0 -2
- package/backend/auth/tokens.ts +1 -8
- package/backend/bootstrap.ts +7 -0
- package/backend/chat/attachments.test.ts +88 -0
- package/backend/chat/attachments.ts +159 -0
- package/backend/chat/engine-handoff.test.ts +0 -2
- package/backend/chat/stream-manager.ts +62 -62
- package/backend/chat/turn-answer.test.ts +64 -0
- package/backend/chat/turn-answer.ts +125 -0
- package/backend/chat-apps/awaiting.test.ts +39 -0
- package/backend/chat-apps/awaiting.ts +49 -0
- package/backend/chat-apps/conversation.ts +746 -0
- package/backend/chat-apps/inbound.ts +324 -0
- package/backend/chat-apps/index.ts +309 -0
- package/backend/chat-apps/link-events.ts +20 -0
- package/backend/chat-apps/media.test.ts +62 -0
- package/backend/chat-apps/media.ts +208 -0
- package/backend/chat-apps/messages.test.ts +229 -0
- package/backend/chat-apps/messages.ts +365 -0
- package/backend/chat-apps/outbound.ts +243 -0
- package/backend/chat-apps/pairing.test.ts +45 -0
- package/backend/chat-apps/pairing.ts +74 -0
- package/backend/chat-apps/platforms/index.ts +20 -0
- package/backend/chat-apps/platforms/telegram.test.ts +35 -0
- package/backend/chat-apps/platforms/telegram.ts +191 -0
- package/backend/chat-apps/platforms/types.ts +114 -0
- package/backend/chat-apps/questions.ts +133 -0
- package/backend/chat-apps/runtime.ts +572 -0
- package/backend/chat-apps/storage.test.ts +201 -0
- package/backend/chat-apps/turns.test.ts +45 -0
- package/backend/chat-apps/turns.ts +208 -0
- package/backend/containers/pty.ts +3 -11
- package/backend/control/actions/accounts.ts +89 -0
- package/backend/control/actions/files.ts +116 -0
- package/backend/control/actions/models.ts +188 -0
- package/backend/control/actions/projects.ts +272 -0
- package/backend/control/actions/sessions.ts +280 -0
- package/backend/control/actions/skills.ts +111 -0
- package/backend/control/control.test.ts +169 -0
- package/backend/control/define.ts +20 -0
- package/backend/control/folders.test.ts +67 -0
- package/backend/control/index.ts +213 -0
- package/backend/control/invoke.ts +44 -0
- package/backend/control/links.ts +35 -0
- package/backend/control/paging.ts +26 -0
- package/backend/control/types.ts +117 -0
- package/backend/control/workspace.ts +127 -0
- package/backend/database/migrations/084_create_channel_links.ts +71 -0
- package/backend/database/migrations/085_add_home_projects.ts +36 -0
- package/backend/database/migrations/086_single_owner.test.ts +170 -0
- package/backend/database/migrations/086_single_owner.ts +418 -0
- package/backend/database/migrations/index.ts +21 -0
- package/backend/database/queries/auth-queries.ts +7 -85
- package/backend/database/queries/channel-queries.ts +270 -0
- package/backend/database/queries/db-client-connection-queries.ts +18 -56
- package/backend/database/queries/file-share-queries.ts +5 -23
- package/backend/database/queries/git-identity-queries.ts +31 -42
- package/backend/database/queries/graph-queries.ts +1 -1
- package/backend/database/queries/index.ts +13 -1
- package/backend/database/queries/message-queries.test.ts +146 -0
- package/backend/database/queries/message-queries.ts +42 -1
- package/backend/database/queries/permission-set-queries.ts +1 -1
- package/backend/database/queries/profile-queries.ts +1 -1
- package/backend/database/queries/project-mcp-trust-queries.ts +1 -1
- package/backend/database/queries/project-queries.ts +50 -63
- package/backend/database/queries/session-queries.ts +28 -56
- package/backend/database/queries/ssh-connection-queries.ts +18 -41
- package/backend/db-client/integrations/projector.ts +0 -5
- package/backend/engine/adapters/claude/message-converter.test.ts +47 -0
- package/backend/engine/adapters/claude/message-converter.ts +25 -2
- package/backend/engine/adapters/cline/message-converter.ts +0 -1
- package/backend/engine/adapters/cline/stream.ts +11 -15
- package/backend/engine/adapters/codex/message-converter.ts +0 -2
- package/backend/engine/adapters/copilot/message-converter.ts +1 -2
- package/backend/engine/adapters/cursor/message-converter.ts +0 -1
- package/backend/engine/adapters/opencode/message-converter.ts +2 -4
- package/backend/engine/adapters/opencode/stream.ts +11 -0
- package/backend/engine/adapters/parent-scope.test.ts +38 -0
- package/backend/engine/adapters/parent-scope.ts +44 -0
- package/backend/engine/adapters/pi/message-converter.ts +0 -1
- package/backend/engine/adapters/pi/stream.ts +4 -5
- package/backend/engine/adapters/qwen/message-converter.ts +0 -2
- package/backend/engine/bootstrap-default-engine.ts +2 -2
- package/backend/engine/docs/adapter-contract.md +8 -1
- package/backend/engine/install-runner.ts +8 -17
- package/backend/files/file-shares.ts +20 -44
- package/backend/files/file-size-limit.ts +3 -3
- package/backend/files/image-processing.ts +1 -1
- package/backend/files/os-clipboard.ts +2 -2
- package/backend/git/git-executor.ts +25 -5
- package/backend/git/git-service.ts +420 -19
- package/backend/git/identity/credential-helper.test.ts +2 -7
- package/backend/git/identity/import-local.test.ts +11 -16
- package/backend/git/identity/import-local.ts +12 -12
- package/backend/git/identity/index.ts +10 -24
- package/backend/git/identity/resolve.ts +13 -14
- package/backend/git/identity/scope-config.ts +33 -28
- package/backend/git/identity/service.ts +44 -47
- package/backend/git/op-lock.test.ts +111 -0
- package/backend/git/op-lock.ts +180 -0
- package/backend/git/remote-sync.test.ts +249 -0
- package/backend/host/metrics.ts +1 -1
- package/backend/http/bearer-auth.ts +1 -2
- package/backend/http/files-download.test.ts +8 -9
- package/backend/http/files-download.ts +2 -2
- package/backend/http/files-shared.test.ts +62 -89
- package/backend/http/files-shared.ts +2 -2
- package/backend/http/files-upload.test.ts +3 -7
- package/backend/http/files-upload.ts +3 -3
- package/backend/http/notes-images.test.ts +15 -38
- package/backend/http/notes-images.ts +6 -8
- package/backend/http/ssh-sftp.ts +5 -10
- package/backend/index.ts +21 -7
- package/backend/integrations/accounts.ts +61 -3
- package/backend/integrations/index.ts +2 -2
- package/backend/integrations/registry/define.ts +15 -0
- package/backend/integrations/registry/index.ts +2 -0
- package/backend/integrations/registry/providers/telegram.ts +54 -0
- package/backend/integrations/registry/types.ts +21 -1
- package/backend/integrations/webhooks/gateway.ts +7 -6
- package/backend/integrations/webhooks/verify.test.ts +30 -0
- package/backend/integrations/webhooks/verify.ts +4 -0
- package/backend/mcp/external/project.ts +1 -1
- package/backend/mcp/internal/remote-server.test.ts +1 -3
- package/backend/mcp/internal/remote-server.ts +4 -4
- package/backend/mcp/internal/servers/browser-automation/actions/dialogs.ts +67 -0
- package/backend/mcp/internal/servers/browser-automation/actions/index.ts +3 -1
- package/backend/mcp/internal/servers/browser-automation/actions/input.ts +5 -5
- package/backend/mcp/internal/servers/browser-automation/actions/tabs.ts +157 -28
- package/backend/mcp/internal/servers/browser-automation/context.ts +1 -0
- package/backend/mcp/internal/servers/browser-automation/description.ts +5 -2
- package/backend/mcp/internal/servers/browser-automation/format.ts +24 -1
- package/backend/mcp/internal/servers/browser-automation/runner.ts +68 -3
- package/backend/memory/redact.ts +1 -1
- package/backend/notes/access.test.ts +28 -29
- package/backend/notes/access.ts +6 -11
- package/backend/permissions/service.ts +1 -1
- package/backend/preview/browser/browser-clipboard.test.ts +46 -0
- package/backend/preview/browser/browser-clipboard.ts +67 -0
- package/backend/preview/browser/browser-dialog-handler.ts +95 -6
- package/backend/preview/browser/browser-host-bridge.ts +9 -0
- package/backend/preview/browser/browser-interaction-handler.ts +316 -86
- package/backend/preview/browser/browser-mcp-control.ts +34 -0
- package/backend/preview/browser/browser-pool.ts +67 -6
- package/backend/preview/browser/browser-preview-service.ts +361 -25
- package/backend/preview/browser/browser-tab-manager.ts +66 -23
- package/backend/preview/browser/browser-video-capture.ts +92 -5
- package/backend/preview/browser/element-locator.ts +190 -17
- package/backend/preview/browser/keyboard-chords.test.ts +68 -0
- package/backend/preview/browser/keyboard-chords.ts +132 -0
- package/backend/preview/browser/paste.ts +81 -0
- package/backend/preview/browser/process-usage.ts +142 -0
- package/backend/preview/browser/profile-lock.ts +209 -0
- package/backend/preview/browser/scripts/host-bridge.ts +59 -0
- package/backend/preview/browser/scripts/video-stream.ts +58 -0
- package/backend/preview/browser/types.ts +40 -2
- package/backend/preview/browser/viewport.test.ts +45 -0
- package/backend/preview/browser/viewport.ts +96 -0
- package/backend/profiles/service.ts +2 -2
- package/backend/project/status-manager.ts +43 -172
- package/backend/projects/home.ts +61 -0
- package/backend/projects/project-cleanup.integration.test.ts +2 -2
- package/backend/projects/project-cleanup.ts +0 -8
- package/backend/skills/service.ts +2 -3
- package/backend/snapshot/helpers.ts +0 -1
- package/backend/snapshot/restore.ts +252 -0
- package/backend/ssh/ptykit.ts +1 -2
- package/backend/terminal/ptykit.ts +5 -8
- package/backend/tunnel/public-origin.ts +31 -20
- package/backend/utils/user-helpers.ts +0 -55
- package/backend/utils/ws.ts +61 -154
- package/backend/worktrees/branching/engine.ts +3 -16
- package/backend/worktrees/branching/index.ts +1 -1
- package/backend/worktrees/branching/projector.ts +1 -1
- package/backend/worktrees/branching/service.ts +13 -25
- package/backend/ws/access.ts +12 -21
- package/backend/ws/artifacts/generate.ts +2 -2
- package/backend/ws/auth/device.ts +16 -71
- package/backend/ws/auth/index.ts +4 -22
- package/backend/ws/auth/login.test.ts +14 -60
- package/backend/ws/auth/login.ts +24 -124
- package/backend/ws/auth/status.ts +0 -1
- package/backend/ws/chat/composer.ts +118 -118
- package/backend/ws/chat/stream.ts +64 -47
- package/backend/ws/chat-apps/index.ts +117 -0
- package/backend/ws/containers/actions.ts +11 -25
- package/backend/ws/containers/index.ts +3 -4
- package/backend/ws/containers/list.ts +10 -36
- package/backend/ws/containers/logs.ts +2 -2
- package/backend/ws/containers/tunnel.ts +1 -2
- package/backend/ws/db-client/access.ts +2 -16
- package/backend/ws/db-client/accounts.ts +5 -15
- package/backend/ws/db-client/connections.ts +17 -25
- package/backend/ws/db-client/context.ts +1 -1
- package/backend/ws/db-client/env.ts +7 -10
- package/backend/ws/db-client/index.ts +2 -2
- package/backend/ws/db-client/io.ts +5 -5
- package/backend/ws/db-client/query-history-retention.test.ts +8 -8
- package/backend/ws/db-client/query.ts +18 -17
- package/backend/ws/db-client/schema.ts +13 -13
- package/backend/ws/db-client/structure.ts +35 -35
- package/backend/ws/db-client/supabase.ts +4 -21
- package/backend/ws/deployments/context.ts +1 -1
- package/backend/ws/deployments/crud.ts +0 -5
- package/backend/ws/engine/access.ts +7 -20
- package/backend/ws/engine/claude/accounts.ts +4 -4
- package/backend/ws/engine/cline/accounts.ts +5 -5
- package/backend/ws/engine/codex/accounts.ts +3 -3
- package/backend/ws/engine/pi/accounts.ts +5 -5
- package/backend/ws/files/clipboard.ts +8 -27
- package/backend/ws/files/image-edit.ts +6 -6
- package/backend/ws/files/index.ts +1 -1
- package/backend/ws/files/path-access.test.ts +32 -131
- package/backend/ws/files/path-access.ts +8 -87
- package/backend/ws/files/read.ts +15 -19
- package/backend/ws/files/reveal.ts +3 -3
- package/backend/ws/files/search.ts +7 -7
- package/backend/ws/files/share.ts +9 -13
- package/backend/ws/files/state.ts +9 -12
- package/backend/ws/files/watch.ts +3 -3
- package/backend/ws/files/write.ts +30 -31
- package/backend/ws/git/branch.ts +80 -59
- package/backend/ws/git/commit.ts +63 -44
- package/backend/ws/git/conflict.ts +16 -18
- package/backend/ws/git/identity-context.ts +8 -17
- package/backend/ws/git/identity.ts +17 -27
- package/backend/ws/git/index.ts +3 -1
- package/backend/ws/git/op-state.ts +139 -0
- package/backend/ws/git/remote.ts +241 -141
- package/backend/ws/git/repo-context.ts +67 -0
- package/backend/ws/git/staging.ts +18 -28
- package/backend/ws/git/status.ts +5 -2
- package/backend/ws/index.ts +5 -1
- package/backend/ws/instructions/crud.ts +1 -1
- package/backend/ws/integrations/crud.ts +1 -3
- package/backend/ws/mcp/crud.ts +3 -5
- package/backend/ws/mcp/tools.ts +1 -1
- package/backend/ws/memory/crud.ts +14 -46
- package/backend/ws/memory/index.ts +2 -2
- package/backend/ws/messages/crud.ts +29 -8
- package/backend/ws/notes/index.ts +33 -39
- package/backend/ws/permissions/crud.ts +3 -4
- package/backend/ws/ports/index.ts +1 -2
- package/backend/ws/ports/kill.ts +5 -10
- package/backend/ws/ports/list.ts +4 -10
- package/backend/ws/preview/access.ts +1 -1
- package/backend/ws/preview/browser/interact.ts +52 -79
- package/backend/ws/preview/browser/native-ui.ts +24 -0
- package/backend/ws/preview/browser/stats.ts +98 -1
- package/backend/ws/preview/browser/tab-info.ts +15 -0
- package/backend/ws/preview/browser/tab.ts +19 -4
- package/backend/ws/preview/index.ts +27 -0
- package/backend/ws/profiles/crud.ts +6 -8
- package/backend/ws/project-artifacts/index.ts +30 -31
- package/backend/ws/projects/crud.ts +33 -35
- package/backend/ws/projects/index.ts +3 -8
- package/backend/ws/projects/info.ts +3 -3
- package/backend/ws/projects/overview.ts +19 -30
- package/backend/ws/projects/status.ts +17 -57
- package/backend/ws/sessions/crud.ts +34 -45
- package/backend/ws/sessions/index.ts +1 -1
- package/backend/ws/settings/crud.ts +1 -1
- package/backend/ws/skills/crud.ts +3 -4
- package/backend/ws/skills/index.ts +1 -1
- package/backend/ws/snapshot/changes.ts +7 -7
- package/backend/ws/snapshot/restore.ts +11 -295
- package/backend/ws/snapshot/timeline.ts +2 -4
- package/backend/ws/ssh/access.ts +6 -21
- package/backend/ws/ssh/connections.ts +21 -31
- package/backend/ws/ssh/forwards.ts +12 -12
- package/backend/ws/ssh/sftp.ts +34 -34
- package/backend/ws/ssh/tunnel.ts +1 -2
- package/backend/ws/stack/install.ts +7 -17
- package/backend/ws/subagents/crud.ts +1 -1
- package/backend/ws/tunnel/share.ts +0 -2
- package/backend/ws/user/crud.ts +1 -59
- package/backend/ws/user/index.ts +1 -1
- package/backend/ws/work/context.ts +1 -1
- package/backend/ws/work/crud.ts +0 -5
- package/backend/ws/workspace/state.ts +10 -13
- package/backend/ws/worktrees/branching.ts +7 -36
- package/backend/ws/worktrees/crud.ts +2 -2
- package/bin/clopen.ts +10 -11
- package/dist/assets/{index-CwuKQelV.js → index-CONlwAXZ.js} +1 -1
- package/dist/assets/{index-BTcR1byF.js → index-DJzwt-hq.js} +1 -1
- package/dist/assets/main-BUiUL3eZ.css +1 -0
- package/dist/assets/main-nBOb9YOA.js +1240 -0
- package/dist/index.html +2 -2
- package/package.json +2 -1
- package/shared/constants/attachments.ts +14 -0
- package/shared/constants/engine-tools.ts +1 -1
- package/shared/constants/preview.test.ts +259 -0
- package/shared/constants/preview.ts +1018 -57
- package/shared/constants/tool-icons.ts +5 -0
- package/shared/types/containers/container.ts +1 -1
- package/shared/types/database/schema.ts +9 -6
- package/shared/types/git-identity.ts +1 -1
- package/shared/types/git.ts +116 -0
- package/shared/types/integrations.ts +7 -0
- package/shared/types/stores/settings.ts +1 -1
- package/shared/types/unified/index.ts +1 -1
- package/shared/types/unified/message.ts +0 -7
- package/shared/types/unified/stream.ts +2 -4
- package/shared/types/unified/tool.ts +15 -1
- package/shared/utils/ask-user-question.test.ts +319 -0
- package/shared/utils/ask-user-question.ts +154 -0
- package/shared/utils/home-project.ts +25 -0
- package/shared/utils/logger.ts +2 -0
- package/shared/utils/ws-server.ts +32 -7
- package/backend/auth/session-invalidation.test.ts +0 -112
- package/backend/auth/session-invalidation.ts +0 -77
- package/backend/project/status-manager.test.ts +0 -32
- package/backend/ws/auth/invites.ts +0 -94
- package/backend/ws/auth/users.ts +0 -112
- package/backend/ws/projects/presence.ts +0 -46
- package/backend/ws/stack/access.ts +0 -31
- package/dist/assets/main-BiDNMWb3.css +0 -1
- package/dist/assets/main-BlhKWz2B.js +0 -1241
|
@@ -23,97 +23,46 @@ async function canCreateSymlinks(): Promise<boolean> {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
// Mock dependencies before importing the module under test
|
|
26
|
-
const mockGetAllForUser = mock(() => [] as Array<{ id: string; path: string }>);
|
|
27
26
|
const mockGetAll = mock(() => [] as Array<{ id: string; path: string }>);
|
|
28
|
-
const mockUserHasProject = mock(() => false);
|
|
29
27
|
const mockGetByPath = mock(() => null as { id: string; path: string } | null);
|
|
30
28
|
const mockGetById = mock(() => null as { id: string; path: string } | null);
|
|
31
29
|
|
|
32
30
|
mock.module('../../database/queries/project-queries', () => ({
|
|
33
31
|
projectQueries: {
|
|
34
|
-
getAllForUser: mockGetAllForUser,
|
|
35
32
|
getAll: mockGetAll,
|
|
36
|
-
userHasProject: mockUserHasProject,
|
|
37
33
|
getByPath: mockGetByPath,
|
|
38
34
|
getById: mockGetById,
|
|
39
35
|
}
|
|
40
36
|
}));
|
|
41
37
|
|
|
42
|
-
// A project's accessible area now includes its worktrees, so the lookup is part
|
|
43
|
-
// of the data layer this test models.
|
|
44
|
-
const mockWorktreesByProject = mock(() => [] as Array<{ id: string; path: string }>);
|
|
45
38
|
const mockWorktreeByPath = mock(() => null as { id: string; project_id: string; path: string } | null);
|
|
46
39
|
|
|
47
40
|
mock.module('../../database/queries/worktree-queries', () => ({
|
|
48
41
|
worktreeQueries: {
|
|
49
|
-
getByProjectId:
|
|
42
|
+
getByProjectId: mock(() => []),
|
|
50
43
|
getByPath: mockWorktreeByPath,
|
|
51
44
|
}
|
|
52
45
|
}));
|
|
53
46
|
|
|
54
|
-
const mockGetRole = mock((): 'admin' | 'member' => 'member');
|
|
55
|
-
const mockGetUserId = mock(() => 'user-1');
|
|
56
|
-
|
|
57
|
-
mock.module('$backend/utils/ws', () => ({
|
|
58
|
-
ws: {
|
|
59
|
-
getRole: mockGetRole,
|
|
60
|
-
getUserId: mockGetUserId,
|
|
61
|
-
}
|
|
62
|
-
}));
|
|
63
|
-
|
|
64
|
-
mock.module('../access', () => ({
|
|
65
|
-
requireProjectAccess: mock(() => ({ id: 'proj-1', path: '' })),
|
|
66
|
-
}));
|
|
67
|
-
|
|
68
47
|
// Import after mocking
|
|
69
|
-
const {
|
|
48
|
+
const { resolveFilePath, findContainingProjectId, resolveProjectForRoot, requireWorkspaceRoot } = await import('./path-access');
|
|
70
49
|
|
|
71
50
|
let testDir: string;
|
|
72
51
|
|
|
73
|
-
describe('
|
|
52
|
+
describe('workspace roots', () => {
|
|
74
53
|
beforeEach(async () => {
|
|
75
54
|
const rawTestDir = join(tmpdir(), `clopen-path-access-test-${randomUUID()}`);
|
|
76
55
|
await mkdir(rawTestDir, { recursive: true });
|
|
77
56
|
// Canonicalize so test expectations match what resolveRealPath returns.
|
|
78
57
|
// macOS tmpdir lives under /var → /private/var, which realpath follows.
|
|
79
58
|
testDir = await realpath(rawTestDir);
|
|
80
|
-
mockGetRole.mockImplementation(() => 'member');
|
|
81
|
-
mockGetUserId.mockImplementation(() => 'user-1');
|
|
82
59
|
});
|
|
83
60
|
|
|
84
61
|
afterEach(async () => {
|
|
85
62
|
await rm(testDir, { recursive: true, force: true });
|
|
86
|
-
mockWorktreesByProject.mockReturnValue([]);
|
|
87
63
|
mockWorktreeByPath.mockReturnValue(null);
|
|
88
64
|
});
|
|
89
65
|
|
|
90
|
-
test('allows a path inside a worktree of an accessible project', async () => {
|
|
91
|
-
const projectPath = join(testDir, 'project');
|
|
92
|
-
const worktreePath = join(testDir, 'worktrees', 'feature');
|
|
93
|
-
await mkdir(projectPath, { recursive: true });
|
|
94
|
-
await mkdir(worktreePath, { recursive: true });
|
|
95
|
-
await writeFile(join(worktreePath, 'index.ts'), 'export {};');
|
|
96
|
-
|
|
97
|
-
mockGetAllForUser.mockReturnValue([{ id: 'proj-1', path: projectPath }]);
|
|
98
|
-
mockWorktreesByProject.mockReturnValue([{ id: 'wt-1', path: worktreePath }]);
|
|
99
|
-
|
|
100
|
-
const target = join(worktreePath, 'index.ts');
|
|
101
|
-
await expect(requireFilePathAccess({} as any, target)).resolves.toBe(target);
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
test('still denies a worktree of a project the user cannot access', async () => {
|
|
105
|
-
const worktreePath = join(testDir, 'worktrees', 'other');
|
|
106
|
-
await mkdir(worktreePath, { recursive: true });
|
|
107
|
-
await writeFile(join(worktreePath, 'secret.txt'), 'nope');
|
|
108
|
-
|
|
109
|
-
mockGetAllForUser.mockReturnValue([]);
|
|
110
|
-
mockWorktreesByProject.mockReturnValue([{ id: 'wt-1', path: worktreePath }]);
|
|
111
|
-
|
|
112
|
-
await expect(
|
|
113
|
-
requireFilePathAccess({} as any, join(worktreePath, 'secret.txt'))
|
|
114
|
-
).rejects.toThrow('Access denied');
|
|
115
|
-
});
|
|
116
|
-
|
|
117
66
|
test('resolves a worktree root back to its owning project', async () => {
|
|
118
67
|
const worktreePath = join(testDir, 'worktrees', 'feature');
|
|
119
68
|
mockGetByPath.mockReturnValue(null);
|
|
@@ -133,9 +82,8 @@ describe('path-access symlink resolution', () => {
|
|
|
133
82
|
mockGetByPath.mockReturnValue(null);
|
|
134
83
|
mockWorktreeByPath.mockReturnValue({ id: 'wt-1', project_id: 'proj-1', path: worktreePath });
|
|
135
84
|
mockGetById.mockReturnValue({ id: 'proj-1', path: projectPath });
|
|
136
|
-
mockGetRole.mockImplementation(() => 'admin');
|
|
137
85
|
|
|
138
|
-
const resolved =
|
|
86
|
+
const resolved = requireWorkspaceRoot(worktreePath);
|
|
139
87
|
expect(resolved.root).toBe(worktreePath);
|
|
140
88
|
expect(resolved.worktreeId).toBe('wt-1');
|
|
141
89
|
expect(resolved.project.id).toBe('proj-1');
|
|
@@ -146,9 +94,8 @@ describe('path-access symlink resolution', () => {
|
|
|
146
94
|
|
|
147
95
|
mockWorktreeByPath.mockReturnValue(null);
|
|
148
96
|
mockGetByPath.mockReturnValue({ id: 'proj-1', path: projectPath });
|
|
149
|
-
mockGetRole.mockImplementation(() => 'admin');
|
|
150
97
|
|
|
151
|
-
const resolved =
|
|
98
|
+
const resolved = requireWorkspaceRoot(projectPath);
|
|
152
99
|
expect(resolved.root).toBe(projectPath);
|
|
153
100
|
expect(resolved.worktreeId).toBeNull();
|
|
154
101
|
});
|
|
@@ -156,104 +103,58 @@ describe('path-access symlink resolution', () => {
|
|
|
156
103
|
test('denies an unknown root', async () => {
|
|
157
104
|
mockWorktreeByPath.mockReturnValue(null);
|
|
158
105
|
mockGetByPath.mockReturnValue(null);
|
|
159
|
-
mockGetRole.mockImplementation(() => 'admin');
|
|
160
106
|
|
|
161
|
-
expect(() =>
|
|
162
|
-
'Access denied'
|
|
163
|
-
);
|
|
107
|
+
expect(() => requireWorkspaceRoot(join(testDir, 'nowhere'))).toThrow('Access denied');
|
|
164
108
|
});
|
|
109
|
+
});
|
|
165
110
|
|
|
166
|
-
|
|
111
|
+
describe('resolveFilePath', () => {
|
|
112
|
+
beforeEach(async () => {
|
|
113
|
+
const rawTestDir = join(tmpdir(), `clopen-resolve-path-test-${randomUUID()}`);
|
|
114
|
+
await mkdir(rawTestDir, { recursive: true });
|
|
115
|
+
testDir = await realpath(rawTestDir);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
afterEach(async () => {
|
|
119
|
+
await rm(testDir, { recursive: true, force: true });
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test('follows a symlink to its real location', async () => {
|
|
167
123
|
if (!(await canCreateSymlinks())) {
|
|
168
124
|
console.log('SKIP: symlink creation requires admin on this platform');
|
|
169
125
|
return;
|
|
170
126
|
}
|
|
171
|
-
// Setup: project at testDir/project, symlink pointing to testDir/external
|
|
172
127
|
const projectPath = join(testDir, 'project');
|
|
173
128
|
const externalPath = join(testDir, 'external');
|
|
174
|
-
const symlinkPath = join(projectPath, 'escape');
|
|
175
|
-
|
|
176
129
|
await mkdir(projectPath, { recursive: true });
|
|
177
130
|
await mkdir(externalPath, { recursive: true });
|
|
178
|
-
await writeFile(join(externalPath, '
|
|
179
|
-
await symlink(externalPath,
|
|
131
|
+
await writeFile(join(externalPath, 'notes.txt'), 'content');
|
|
132
|
+
await symlink(externalPath, join(projectPath, 'linked'), 'dir');
|
|
180
133
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
// Attempt to access file through symlink
|
|
184
|
-
const targetPath = join(symlinkPath, 'secret.txt');
|
|
185
|
-
await expect(requireFilePathAccess({} as any, targetPath)).rejects.toThrow('Access denied');
|
|
134
|
+
const result = await resolveFilePath(join(projectPath, 'linked', 'notes.txt'));
|
|
135
|
+
expect(result).toBe(join(externalPath, 'notes.txt'));
|
|
186
136
|
});
|
|
187
137
|
|
|
188
|
-
test('
|
|
138
|
+
test('follows a symlinked parent for a leaf that does not exist yet', async () => {
|
|
189
139
|
if (!(await canCreateSymlinks())) {
|
|
190
140
|
console.log('SKIP: symlink creation requires admin on this platform');
|
|
191
141
|
return;
|
|
192
142
|
}
|
|
193
|
-
//
|
|
143
|
+
// realpath throws for a missing leaf; the symlinked parent must still be
|
|
144
|
+
// resolved so a write lands where it really will.
|
|
194
145
|
const projectPath = join(testDir, 'project');
|
|
195
146
|
const externalPath = join(testDir, 'external');
|
|
196
|
-
const symlinkPath = join(projectPath, 'escape');
|
|
197
|
-
|
|
198
147
|
await mkdir(projectPath, { recursive: true });
|
|
199
148
|
await mkdir(externalPath, { recursive: true });
|
|
200
|
-
await symlink(externalPath,
|
|
149
|
+
await symlink(externalPath, join(projectPath, 'linked'), 'dir');
|
|
201
150
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
// Attempt to write to a non-existing file through symlink
|
|
205
|
-
// This is the key regression: realpath throws for non-existing paths,
|
|
206
|
-
// but resolveRealPath should still resolve the symlinked parent
|
|
207
|
-
const targetPath = join(symlinkPath, 'new-file.txt');
|
|
208
|
-
await expect(requireFilePathAccess({} as any, targetPath)).rejects.toThrow('Access denied');
|
|
151
|
+
const result = await resolveFilePath(join(projectPath, 'linked', 'new-file.txt'));
|
|
152
|
+
expect(result).toBe(join(externalPath, 'new-file.txt'));
|
|
209
153
|
});
|
|
210
154
|
|
|
211
|
-
test('
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
const childProjectPath = join(parentPath, 'child-project');
|
|
215
|
-
|
|
216
|
-
await mkdir(childProjectPath, { recursive: true });
|
|
217
|
-
|
|
218
|
-
mockGetAll.mockReturnValue([{ id: 'proj-2', path: childProjectPath }]);
|
|
219
|
-
mockUserHasProject.mockReturnValue(false);
|
|
220
|
-
|
|
221
|
-
// user-1 attempts to rename the parent directory
|
|
222
|
-
await expect(requireSharedFilePathAccess({} as any, parentPath)).rejects.toThrow('Access denied');
|
|
223
|
-
});
|
|
224
|
-
|
|
225
|
-
test('allows access to files inside user own project', async () => {
|
|
226
|
-
const projectPath = join(testDir, 'project');
|
|
227
|
-
const filePath = join(projectPath, 'file.txt');
|
|
228
|
-
|
|
229
|
-
await mkdir(projectPath, { recursive: true });
|
|
230
|
-
await writeFile(filePath, 'content');
|
|
231
|
-
|
|
232
|
-
mockGetAllForUser.mockReturnValue([{ id: 'proj-1', path: projectPath }]);
|
|
233
|
-
|
|
234
|
-
const result = await requireFilePathAccess({} as any, filePath);
|
|
235
|
-
expect(result).toBe(filePath);
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
test('allows creating new files inside user own project', async () => {
|
|
239
|
-
const projectPath = join(testDir, 'project');
|
|
240
|
-
const newFilePath = join(projectPath, 'new-file.txt');
|
|
241
|
-
|
|
242
|
-
await mkdir(projectPath, { recursive: true });
|
|
243
|
-
|
|
244
|
-
mockGetAllForUser.mockReturnValue([{ id: 'proj-1', path: projectPath }]);
|
|
245
|
-
|
|
246
|
-
// new-file.txt doesn't exist yet, but should still be allowed
|
|
247
|
-
const result = await requireFilePathAccess({} as any, newFilePath);
|
|
248
|
-
expect(result).toBe(newFilePath);
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
test('admin bypasses all checks', async () => {
|
|
252
|
-
mockGetRole.mockImplementation(() => 'admin');
|
|
253
|
-
|
|
254
|
-
const anyPath = join(testDir, 'any', 'path', 'file.txt');
|
|
255
|
-
const result = await requireFilePathAccess({} as any, anyPath);
|
|
256
|
-
expect(result).toBe(anyPath);
|
|
155
|
+
test('returns a plain path unchanged', async () => {
|
|
156
|
+
const filePath = join(testDir, 'any', 'path', 'file.txt');
|
|
157
|
+
expect(await resolveFilePath(filePath)).toBe(filePath);
|
|
257
158
|
});
|
|
258
159
|
});
|
|
259
160
|
|
|
@@ -3,10 +3,7 @@ import { realpath } from 'node:fs/promises';
|
|
|
3
3
|
|
|
4
4
|
import { projectQueries } from '../../database/queries/project-queries';
|
|
5
5
|
import { worktreeQueries } from '../../database/queries/worktree-queries';
|
|
6
|
-
import { ws } from '$backend/utils/ws';
|
|
7
|
-
import type { WSConnection } from '$shared/utils/ws-server';
|
|
8
6
|
import type { Project } from '$shared/types/database/schema';
|
|
9
|
-
import { requireProjectAccess } from '../access';
|
|
10
7
|
|
|
11
8
|
/**
|
|
12
9
|
* Resolve a path to its real (canonical) location, following symlinks.
|
|
@@ -63,13 +60,13 @@ export interface WorkspaceRoot {
|
|
|
63
60
|
}
|
|
64
61
|
|
|
65
62
|
/**
|
|
66
|
-
*
|
|
63
|
+
* Resolve a workspace root and hand back the root that was requested.
|
|
67
64
|
*
|
|
68
65
|
* Returning the root rather than only the project is the point: callers used to
|
|
69
66
|
* validate a path and then operate on `project.path`, which was identical until
|
|
70
67
|
* worktrees existed and silently became "list the main tree" afterwards.
|
|
71
68
|
*/
|
|
72
|
-
export function
|
|
69
|
+
export function requireWorkspaceRoot(rootPath: string): WorkspaceRoot {
|
|
73
70
|
const worktree = worktreeQueries.getByPath(rootPath);
|
|
74
71
|
const project = worktree
|
|
75
72
|
? projectQueries.getById(worktree.project_id)
|
|
@@ -78,9 +75,6 @@ export function requireWorkspaceRootAccess(conn: WSConnection, rootPath: string)
|
|
|
78
75
|
if (!project) {
|
|
79
76
|
throw new Error('Access denied');
|
|
80
77
|
}
|
|
81
|
-
if (ws.getRole(conn) !== 'admin') {
|
|
82
|
-
requireProjectAccess(conn, project.id);
|
|
83
|
-
}
|
|
84
78
|
|
|
85
79
|
return {
|
|
86
80
|
project,
|
|
@@ -89,46 +83,19 @@ export function requireWorkspaceRootAccess(conn: WSConnection, rootPath: string)
|
|
|
89
83
|
};
|
|
90
84
|
}
|
|
91
85
|
|
|
92
|
-
export async function requireFilePathAccess(conn: WSConnection, filePath: string): Promise<string> {
|
|
93
|
-
return await requireFilePathAccessFor(filePath, ws.getRole(conn), ws.getUserId(conn));
|
|
94
|
-
}
|
|
95
|
-
|
|
96
86
|
/**
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
87
|
+
* The canonical location of a path the owner named. Clopen controls the whole
|
|
88
|
+
* machine it runs on, so there is nothing to refuse — but every file operation
|
|
89
|
+
* still runs against the real path, never a symlink alias of it.
|
|
100
90
|
*/
|
|
101
|
-
export async function
|
|
102
|
-
|
|
103
|
-
if (role === 'admin') {
|
|
104
|
-
return normalizedPath;
|
|
105
|
-
}
|
|
106
|
-
if (!userId) {
|
|
107
|
-
throw new Error('Access denied');
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// A project's accessible area is its own tree plus every worktree cloned
|
|
111
|
-
// from it — both are workspaces the user is already entitled to.
|
|
112
|
-
const projects = projectQueries.getAllForUser(userId);
|
|
113
|
-
for (const project of projects) {
|
|
114
|
-
if (await isPathInside(project.path, normalizedPath)) {
|
|
115
|
-
return normalizedPath;
|
|
116
|
-
}
|
|
117
|
-
for (const worktree of worktreeQueries.getByProjectId(project.id)) {
|
|
118
|
-
if (await isPathInside(worktree.path, normalizedPath)) {
|
|
119
|
-
return normalizedPath;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
throw new Error('Access denied');
|
|
91
|
+
export async function resolveFilePath(filePath: string): Promise<string> {
|
|
92
|
+
return await resolveRealPath(filePath);
|
|
125
93
|
}
|
|
126
94
|
|
|
127
95
|
/**
|
|
128
96
|
* Best-effort resolution of the project that contains a path, for audit
|
|
129
97
|
* logging. Returns the most specific (longest-root) containing project's id,
|
|
130
|
-
* or null when the path lives outside every registered project.
|
|
131
|
-
* access decision — callers enforce access separately.
|
|
98
|
+
* or null when the path lives outside every registered project.
|
|
132
99
|
*/
|
|
133
100
|
export async function findContainingProjectId(filePath: string): Promise<string | null> {
|
|
134
101
|
const normalizedPath = await resolveRealPath(filePath);
|
|
@@ -145,52 +112,6 @@ export async function findContainingProjectId(filePath: string): Promise<string
|
|
|
145
112
|
return containing?.id ?? null;
|
|
146
113
|
}
|
|
147
114
|
|
|
148
|
-
// Picker-style guard: allow paths inside the user's accessible projects OR
|
|
149
|
-
// outside every registered project. Rejects only when the path lives inside
|
|
150
|
-
// another project the user cannot access. Used by FolderBrowser flows that
|
|
151
|
-
// operate around / before a project exists.
|
|
152
|
-
export async function requireSharedFilePathAccess(conn: WSConnection, filePath: string): Promise<string> {
|
|
153
|
-
const normalizedPath = await resolveRealPath(filePath);
|
|
154
|
-
if (ws.getRole(conn) === 'admin') {
|
|
155
|
-
return normalizedPath;
|
|
156
|
-
}
|
|
157
|
-
const userId = ws.getUserId(conn);
|
|
158
|
-
const allProjects = projectQueries.getAll();
|
|
159
|
-
|
|
160
|
-
// Ancestor guard: reject if the path is a parent of another user's project.
|
|
161
|
-
// Without this, renaming/deleting `/foo` would break a project rooted at
|
|
162
|
-
// `/foo/bar` even though `/foo` itself is not "inside" any project.
|
|
163
|
-
for (const project of allProjects) {
|
|
164
|
-
const projectRoot = await resolveRealPath(project.path);
|
|
165
|
-
if (projectRoot === normalizedPath) continue; // equality is handled below
|
|
166
|
-
if (!(await isPathInside(normalizedPath, project.path))) continue;
|
|
167
|
-
if (!projectQueries.userHasProject(userId, project.id)) {
|
|
168
|
-
throw new Error('Access denied');
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// Pick the most specific (longest matching root) project so nested project
|
|
173
|
-
// roots resolve to the inner one, not whichever the DB returns first.
|
|
174
|
-
let containing: { id: string; path: string } | null = null;
|
|
175
|
-
for (const project of allProjects) {
|
|
176
|
-
if (!(await isPathInside(project.path, normalizedPath))) continue;
|
|
177
|
-
const projectRoot = await resolveRealPath(project.path);
|
|
178
|
-
if (!containing || projectRoot.length > resolve(containing.path).length) {
|
|
179
|
-
containing = project;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
if (!containing) {
|
|
184
|
-
return normalizedPath;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
const hasAccess = projectQueries.userHasProject(userId, containing.id);
|
|
188
|
-
if (!hasAccess) {
|
|
189
|
-
throw new Error('Access denied');
|
|
190
|
-
}
|
|
191
|
-
return normalizedPath;
|
|
192
|
-
}
|
|
193
|
-
|
|
194
115
|
export async function filterAccessibleExpandedPaths(rootPath: string, expandedPaths?: Set<string>): Promise<Set<string> | undefined> {
|
|
195
116
|
if (!expandedPaths) return undefined;
|
|
196
117
|
const filtered = new Set<string>();
|
package/backend/ws/files/read.ts
CHANGED
|
@@ -25,9 +25,8 @@ import { isAbsolute, relative } from 'node:path';
|
|
|
25
25
|
import { requireProjectAccess } from '../access';
|
|
26
26
|
import {
|
|
27
27
|
filterAccessibleExpandedPaths,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
requireSharedFilePathAccess
|
|
28
|
+
resolveFilePath,
|
|
29
|
+
requireWorkspaceRoot
|
|
31
30
|
} from './path-access';
|
|
32
31
|
|
|
33
32
|
// Bun-compatible existsSync implementation
|
|
@@ -71,10 +70,10 @@ export const readHandler = createRouter()
|
|
|
71
70
|
})
|
|
72
71
|
])
|
|
73
72
|
)
|
|
74
|
-
}, async ({ data
|
|
73
|
+
}, async ({ data }) => {
|
|
75
74
|
// The requested root, not the project's: for a worktree these differ, and
|
|
76
75
|
// listing the project would hand back the main tree's files and paths.
|
|
77
|
-
const { root: projectPath } =
|
|
76
|
+
const { root: projectPath } = requireWorkspaceRoot(data.project_path);
|
|
78
77
|
|
|
79
78
|
if (!(await existsSync(projectPath))) {
|
|
80
79
|
throw new Error('Project path does not exist');
|
|
@@ -123,18 +122,15 @@ export const readHandler = createRouter()
|
|
|
123
122
|
),
|
|
124
123
|
error: t.Optional(t.String())
|
|
125
124
|
})
|
|
126
|
-
}, async ({ data
|
|
125
|
+
}, async ({ data }) => {
|
|
127
126
|
// FolderBrowser uses this before a project exists, so it must be able to
|
|
128
127
|
// browse roots like "home", "drives", ".", and arbitrary candidate paths.
|
|
129
|
-
// Security: enforce backend path ownership checks for real filesystem
|
|
130
|
-
// paths so non-admin users can't enumerate directories inside projects
|
|
131
|
-
// they are not assigned to.
|
|
132
128
|
const requestedPath = data.path === 'home'
|
|
133
129
|
? (process.env.HOME || process.env.USERPROFILE || process.cwd())
|
|
134
130
|
: (data.path === '.' || data.path === '' ? process.cwd() : data.path);
|
|
135
131
|
const guardedPath = data.path === 'drives'
|
|
136
132
|
? 'drives'
|
|
137
|
-
: await
|
|
133
|
+
: await resolveFilePath(requestedPath);
|
|
138
134
|
const result = await handlePathBrowsing(guardedPath);
|
|
139
135
|
return result;
|
|
140
136
|
})
|
|
@@ -157,8 +153,8 @@ export const readHandler = createRouter()
|
|
|
157
153
|
})
|
|
158
154
|
)
|
|
159
155
|
)
|
|
160
|
-
}, async ({ data
|
|
161
|
-
const dirPath = await
|
|
156
|
+
}, async ({ data }) => {
|
|
157
|
+
const dirPath = await resolveFilePath(data.dir_path);
|
|
162
158
|
const result = await listDirectoryContents(dirPath);
|
|
163
159
|
return result;
|
|
164
160
|
})
|
|
@@ -177,8 +173,8 @@ export const readHandler = createRouter()
|
|
|
177
173
|
isBinary: t.Optional(t.Boolean()),
|
|
178
174
|
error: t.Optional(t.String())
|
|
179
175
|
})
|
|
180
|
-
}, async ({ data
|
|
181
|
-
const filePath = await
|
|
176
|
+
}, async ({ data }) => {
|
|
177
|
+
const filePath = await resolveFilePath(data.file_path);
|
|
182
178
|
const result = await readFileContents(filePath);
|
|
183
179
|
return result;
|
|
184
180
|
})
|
|
@@ -196,12 +192,12 @@ export const readHandler = createRouter()
|
|
|
196
192
|
content: t.Union([t.String(), t.Null()]),
|
|
197
193
|
ref: t.String()
|
|
198
194
|
})
|
|
199
|
-
}, async ({ data
|
|
195
|
+
}, async ({ data }) => {
|
|
200
196
|
// A worktree is its own checkout, so the gutter diff has to resolve
|
|
201
197
|
// against the tree the file is in rather than the project's.
|
|
202
198
|
const { root } = data.rootPath
|
|
203
|
-
?
|
|
204
|
-
: { root: requireProjectAccess(
|
|
199
|
+
? requireWorkspaceRoot(data.rootPath)
|
|
200
|
+
: { root: requireProjectAccess(data.projectId).path };
|
|
205
201
|
|
|
206
202
|
const ref = data.ref || 'HEAD';
|
|
207
203
|
|
|
@@ -238,8 +234,8 @@ export const readHandler = createRouter()
|
|
|
238
234
|
modified: t.Optional(t.String()),
|
|
239
235
|
size: t.Optional(t.Number())
|
|
240
236
|
})
|
|
241
|
-
}, async ({ data
|
|
242
|
-
const path = await
|
|
237
|
+
}, async ({ data }) => {
|
|
238
|
+
const path = await resolveFilePath(data.path);
|
|
243
239
|
|
|
244
240
|
// Read file as binary
|
|
245
241
|
const file = Bun.file(path);
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
import { sep } from 'node:path';
|
|
11
11
|
import { t } from 'elysia';
|
|
12
12
|
import { createRouter } from '$shared/utils/ws-server';
|
|
13
|
-
import {
|
|
13
|
+
import { resolveFilePath } from './path-access';
|
|
14
14
|
|
|
15
15
|
export const revealHandler = createRouter()
|
|
16
16
|
|
|
@@ -21,8 +21,8 @@ export const revealHandler = createRouter()
|
|
|
21
21
|
response: t.Object({
|
|
22
22
|
ok: t.Boolean()
|
|
23
23
|
})
|
|
24
|
-
}, async ({ data
|
|
25
|
-
const targetPath = await
|
|
24
|
+
}, async ({ data }) => {
|
|
25
|
+
const targetPath = await resolveFilePath(data.path);
|
|
26
26
|
|
|
27
27
|
if (process.platform === 'darwin') {
|
|
28
28
|
const proc = Bun.spawn(['open', '-R', targetPath], {
|
|
@@ -3,7 +3,7 @@ import { createRouter } from '$shared/utils/ws-server';
|
|
|
3
3
|
import { debug } from '$shared/utils/logger';
|
|
4
4
|
import { join, extname, basename, relative } from 'path';
|
|
5
5
|
import { readdir } from 'fs/promises';
|
|
6
|
-
import {
|
|
6
|
+
import { requireWorkspaceRoot } from './path-access';
|
|
7
7
|
import { validateFileSize } from '../../files/file-size-limit';
|
|
8
8
|
|
|
9
9
|
// Heuristic patterns that indicate potential ReDoS risk:
|
|
@@ -405,9 +405,9 @@ export const fileSearchHandler = createRouter()
|
|
|
405
405
|
query: t.String()
|
|
406
406
|
}),
|
|
407
407
|
response: t.Array(FileSearchResultSchema)
|
|
408
|
-
}, async ({ data
|
|
408
|
+
}, async ({ data }) => {
|
|
409
409
|
const { project_path, query } = data;
|
|
410
|
-
const { root } =
|
|
410
|
+
const { root } = requireWorkspaceRoot(project_path);
|
|
411
411
|
|
|
412
412
|
if (!query || query.trim().length === 0) {
|
|
413
413
|
return [];
|
|
@@ -436,7 +436,7 @@ export const fileSearchHandler = createRouter()
|
|
|
436
436
|
})),
|
|
437
437
|
totalMatches: t.Number()
|
|
438
438
|
}))
|
|
439
|
-
}, async ({ data
|
|
439
|
+
}, async ({ data }) => {
|
|
440
440
|
const {
|
|
441
441
|
project_path,
|
|
442
442
|
query,
|
|
@@ -446,7 +446,7 @@ export const fileSearchHandler = createRouter()
|
|
|
446
446
|
include_pattern,
|
|
447
447
|
exclude_pattern
|
|
448
448
|
} = data;
|
|
449
|
-
const { root } =
|
|
449
|
+
const { root } = requireWorkspaceRoot(project_path);
|
|
450
450
|
|
|
451
451
|
if (!query || query.trim().length === 0) {
|
|
452
452
|
return [];
|
|
@@ -480,7 +480,7 @@ export const fileSearchHandler = createRouter()
|
|
|
480
480
|
totalReplacements: t.Number(),
|
|
481
481
|
totalFiles: t.Number()
|
|
482
482
|
})
|
|
483
|
-
}, async ({ data
|
|
483
|
+
}, async ({ data }) => {
|
|
484
484
|
const {
|
|
485
485
|
project_path,
|
|
486
486
|
search_query,
|
|
@@ -491,7 +491,7 @@ export const fileSearchHandler = createRouter()
|
|
|
491
491
|
include_pattern,
|
|
492
492
|
exclude_pattern
|
|
493
493
|
} = data;
|
|
494
|
-
const { root } =
|
|
494
|
+
const { root } = requireWorkspaceRoot(project_path);
|
|
495
495
|
|
|
496
496
|
if (!search_query || search_query.trim().length === 0) {
|
|
497
497
|
return { results: [], totalReplacements: 0, totalFiles: 0 };
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
* its one-time / deadline options. The raw token is embedded in the share
|
|
6
6
|
* URL; only its hash is stored, and the row id comes back alongside it so
|
|
7
7
|
* the link stays manageable afterwards.
|
|
8
|
-
* - files:list-shares — live links
|
|
9
|
-
*
|
|
10
|
-
* - files:revoke-share —
|
|
8
|
+
* - files:list-shares — live links. Carries no token material, so it can
|
|
9
|
+
* never rebuild a URL.
|
|
10
|
+
* - files:revoke-share — invalidates a link by row id.
|
|
11
11
|
* - files:shares-changed — broadcast whenever that list moves, so every open
|
|
12
12
|
* management view reflects a mint, a revoke or an open without polling.
|
|
13
13
|
*
|
|
@@ -33,8 +33,6 @@ const shareSummary = t.Object({
|
|
|
33
33
|
projectName: t.Union([t.String(), t.Null()]),
|
|
34
34
|
worktreeName: t.Union([t.String(), t.Null()]),
|
|
35
35
|
relativePath: t.String(),
|
|
36
|
-
createdBy: t.String(),
|
|
37
|
-
createdByName: t.Union([t.String(), t.Null()]),
|
|
38
36
|
createdAt: t.String(),
|
|
39
37
|
oneTime: t.Boolean(),
|
|
40
38
|
expiresAt: t.Union([t.String(), t.Null()]),
|
|
@@ -61,7 +59,7 @@ export const fileShareHandler = createRouter()
|
|
|
61
59
|
expiresAt: t.Union([t.String(), t.Null()])
|
|
62
60
|
})
|
|
63
61
|
}, async ({ data, conn }) => {
|
|
64
|
-
const result = await createFileShareLink(data.file_path, ws.
|
|
62
|
+
const result = await createFileShareLink(data.file_path, ws.getUserId(conn), {
|
|
65
63
|
oneTime: data.oneTime,
|
|
66
64
|
expiresInMinutes: data.expiresInMinutes
|
|
67
65
|
});
|
|
@@ -72,8 +70,8 @@ export const fileShareHandler = createRouter()
|
|
|
72
70
|
.http('files:list-shares', {
|
|
73
71
|
data: t.Object({}),
|
|
74
72
|
response: t.Object({ shares: t.Array(shareSummary) })
|
|
75
|
-
}, async (
|
|
76
|
-
return { shares: listFileShares(
|
|
73
|
+
}, async () => {
|
|
74
|
+
return { shares: listFileShares() };
|
|
77
75
|
})
|
|
78
76
|
|
|
79
77
|
.http('files:revoke-share', {
|
|
@@ -81,15 +79,13 @@ export const fileShareHandler = createRouter()
|
|
|
81
79
|
shareId: t.String({ minLength: 1 })
|
|
82
80
|
}),
|
|
83
81
|
response: t.Object({ success: t.Boolean() })
|
|
84
|
-
}, async ({ data
|
|
85
|
-
const success = revokeFileShareLink(data.shareId
|
|
82
|
+
}, async ({ data }) => {
|
|
83
|
+
const success = revokeFileShareLink(data.shareId);
|
|
86
84
|
if (success) ws.emit.global('files:shares-changed', { kind: 'revoked' });
|
|
87
85
|
return { success };
|
|
88
86
|
})
|
|
89
87
|
|
|
90
|
-
// Broadcast-only:
|
|
91
|
-
// every listener re-reads its own role-scoped list. A global ping cannot
|
|
92
|
-
// leak what a user is not allowed to see.
|
|
88
|
+
// Broadcast-only: every listener re-reads the list.
|
|
93
89
|
.emit('files:shares-changed', t.Object({
|
|
94
90
|
kind: t.String()
|
|
95
91
|
}));
|