@myrialabs/clopen 0.4.46 → 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/presets.ts +27 -2
- package/backend/engine/adapters/opencode/server.ts +6 -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/opencode/providers.ts +2 -1
- 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
|
@@ -20,7 +20,6 @@ const TABLE = 'git_identities';
|
|
|
20
20
|
|
|
21
21
|
export interface GitIdentityRow {
|
|
22
22
|
id: string;
|
|
23
|
-
owner_user_id: string;
|
|
24
23
|
label: string;
|
|
25
24
|
name: string;
|
|
26
25
|
email: string;
|
|
@@ -40,7 +39,6 @@ export interface GitIdentityRow {
|
|
|
40
39
|
|
|
41
40
|
export interface GitIdentityBindingRow {
|
|
42
41
|
project_id: string;
|
|
43
|
-
user_id: string;
|
|
44
42
|
identity_id: string;
|
|
45
43
|
created_at: string;
|
|
46
44
|
updated_at: string;
|
|
@@ -97,46 +95,45 @@ export const gitIdentityQueries = {
|
|
|
97
95
|
return row ? openRow(TABLE, row) : null;
|
|
98
96
|
},
|
|
99
97
|
|
|
100
|
-
|
|
98
|
+
list(): GitIdentityRow[] {
|
|
101
99
|
const db = getDatabase();
|
|
102
100
|
const rows = db
|
|
103
|
-
.prepare(`SELECT * FROM ${TABLE}
|
|
104
|
-
.all(
|
|
101
|
+
.prepare(`SELECT * FROM ${TABLE} ORDER BY is_default DESC, label`)
|
|
102
|
+
.all() as GitIdentityRow[];
|
|
105
103
|
return openRows(TABLE, rows);
|
|
106
104
|
},
|
|
107
105
|
|
|
108
106
|
/** The row mirrored from the machine's global git config, if there is one. */
|
|
109
|
-
getLocalMachine(
|
|
107
|
+
getLocalMachine(): GitIdentityRow | null {
|
|
110
108
|
const db = getDatabase();
|
|
111
109
|
const row = db
|
|
112
|
-
.prepare(`SELECT * FROM ${TABLE} WHERE
|
|
113
|
-
.get(
|
|
110
|
+
.prepare(`SELECT * FROM ${TABLE} WHERE source = 'local-machine'`)
|
|
111
|
+
.get() as GitIdentityRow | undefined;
|
|
114
112
|
return row ? openRow(TABLE, row) : null;
|
|
115
113
|
},
|
|
116
114
|
|
|
117
|
-
|
|
115
|
+
getDefault(): GitIdentityRow | null {
|
|
118
116
|
const db = getDatabase();
|
|
119
117
|
const row = db
|
|
120
|
-
.prepare(`SELECT * FROM ${TABLE} WHERE
|
|
121
|
-
.get(
|
|
118
|
+
.prepare(`SELECT * FROM ${TABLE} WHERE is_default = 1`)
|
|
119
|
+
.get() as GitIdentityRow | undefined;
|
|
122
120
|
return row ? openRow(TABLE, row) : null;
|
|
123
121
|
},
|
|
124
122
|
|
|
125
|
-
create(id: string,
|
|
123
|
+
create(id: string, input: GitIdentityWrite): GitIdentityRow {
|
|
126
124
|
const db = getDatabase();
|
|
127
125
|
const now = new Date().toISOString();
|
|
128
126
|
db.prepare(
|
|
129
127
|
`
|
|
130
128
|
INSERT INTO ${TABLE} (
|
|
131
|
-
id,
|
|
129
|
+
id, label, name, email, auth_method,
|
|
132
130
|
ssh_private_key, ssh_public_key, ssh_passphrase,
|
|
133
131
|
https_username, https_token, integration_account_id,
|
|
134
132
|
hosts, is_default, source, created_at, updated_at
|
|
135
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
|
|
133
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, ?, ?, ?)
|
|
136
134
|
`
|
|
137
135
|
).run(
|
|
138
136
|
id,
|
|
139
|
-
userId,
|
|
140
137
|
input.label,
|
|
141
138
|
input.name,
|
|
142
139
|
input.email,
|
|
@@ -205,22 +202,19 @@ export const gitIdentityQueries = {
|
|
|
205
202
|
},
|
|
206
203
|
|
|
207
204
|
/**
|
|
208
|
-
* Make one identity the
|
|
205
|
+
* Make one identity the default, clearing any previous one.
|
|
209
206
|
*
|
|
210
207
|
* Both statements run in a transaction because the partial unique index
|
|
211
208
|
* rejects a moment where two rows claim the default — clearing first and
|
|
212
209
|
* setting second is not optional, it is what makes the write legal.
|
|
213
210
|
*/
|
|
214
|
-
setDefault(
|
|
211
|
+
setDefault(id: string): void {
|
|
215
212
|
const db = getDatabase();
|
|
216
213
|
const swap = () => {
|
|
217
|
-
db.prepare(`UPDATE ${TABLE} SET is_default = 0 WHERE
|
|
218
|
-
|
|
219
|
-
);
|
|
220
|
-
db.prepare(`UPDATE ${TABLE} SET is_default = 1, updated_at = ? WHERE id = ? AND owner_user_id = ?`).run(
|
|
214
|
+
db.prepare(`UPDATE ${TABLE} SET is_default = 0 WHERE is_default = 1`).run();
|
|
215
|
+
db.prepare(`UPDATE ${TABLE} SET is_default = 1, updated_at = ? WHERE id = ?`).run(
|
|
221
216
|
new Date().toISOString(),
|
|
222
|
-
id
|
|
223
|
-
userId
|
|
217
|
+
id
|
|
224
218
|
);
|
|
225
219
|
};
|
|
226
220
|
// Not every driver exposes transactions (see `DatabaseConnection`). Running
|
|
@@ -236,47 +230,42 @@ export const gitIdentityQueries = {
|
|
|
236
230
|
return result.changes > 0;
|
|
237
231
|
},
|
|
238
232
|
|
|
239
|
-
/** True when the label is already taken by another
|
|
240
|
-
labelTaken(
|
|
233
|
+
/** True when the label is already taken by another identity. */
|
|
234
|
+
labelTaken(label: string, exceptId?: string): boolean {
|
|
241
235
|
const db = getDatabase();
|
|
242
236
|
const row = db
|
|
243
|
-
.prepare(
|
|
244
|
-
|
|
245
|
-
)
|
|
246
|
-
.get(userId, label, exceptId ?? null);
|
|
237
|
+
.prepare(`SELECT id FROM ${TABLE} WHERE label = ? AND id IS NOT ?`)
|
|
238
|
+
.get(label, exceptId ?? null);
|
|
247
239
|
return !!row;
|
|
248
240
|
}
|
|
249
241
|
};
|
|
250
242
|
|
|
251
243
|
export const gitIdentityBindingQueries = {
|
|
252
|
-
get(projectId: string
|
|
244
|
+
get(projectId: string): GitIdentityBindingRow | null {
|
|
253
245
|
const db = getDatabase();
|
|
254
246
|
const row = db
|
|
255
|
-
.prepare('SELECT * FROM git_identity_bindings WHERE project_id = ?
|
|
256
|
-
.get(projectId
|
|
247
|
+
.prepare('SELECT * FROM git_identity_bindings WHERE project_id = ?')
|
|
248
|
+
.get(projectId) as GitIdentityBindingRow | undefined;
|
|
257
249
|
return row ?? null;
|
|
258
250
|
},
|
|
259
251
|
|
|
260
|
-
set(projectId: string,
|
|
252
|
+
set(projectId: string, identityId: string): void {
|
|
261
253
|
const db = getDatabase();
|
|
262
254
|
const now = new Date().toISOString();
|
|
263
255
|
db.prepare(
|
|
264
256
|
`
|
|
265
|
-
INSERT INTO git_identity_bindings (project_id,
|
|
266
|
-
VALUES (?, ?, ?,
|
|
267
|
-
ON CONFLICT(project_id
|
|
257
|
+
INSERT INTO git_identity_bindings (project_id, identity_id, created_at, updated_at)
|
|
258
|
+
VALUES (?, ?, ?, ?)
|
|
259
|
+
ON CONFLICT(project_id) DO UPDATE SET
|
|
268
260
|
identity_id = excluded.identity_id,
|
|
269
261
|
updated_at = excluded.updated_at
|
|
270
262
|
`
|
|
271
|
-
).run(projectId,
|
|
263
|
+
).run(projectId, identityId, now, now);
|
|
272
264
|
},
|
|
273
265
|
|
|
274
|
-
clear(projectId: string
|
|
266
|
+
clear(projectId: string): void {
|
|
275
267
|
const db = getDatabase();
|
|
276
|
-
db.prepare('DELETE FROM git_identity_bindings WHERE project_id = ?
|
|
277
|
-
projectId,
|
|
278
|
-
userId
|
|
279
|
-
);
|
|
268
|
+
db.prepare('DELETE FROM git_identity_bindings WHERE project_id = ?').run(projectId);
|
|
280
269
|
},
|
|
281
270
|
|
|
282
271
|
/** Projects this identity is bound to — what a delete confirmation shows. */
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Memory Graph Queries
|
|
3
3
|
*
|
|
4
4
|
* CRUD and traversal for `graph_nodes` / `graph_edges` / `graph_vectors` plus the
|
|
5
|
-
* `graph_nodes_fts` mirror (migration 066). Instance-global
|
|
5
|
+
* `graph_nodes_fts` mirror (migration 066). Instance-global —
|
|
6
6
|
* no `user_id` column — mirroring skills / mcp_servers / subagents.
|
|
7
7
|
*
|
|
8
8
|
* Two invariants live here rather than in callers:
|
|
@@ -17,7 +17,7 @@ export { sshPortForwardQueries } from './ssh-port-forward-queries';
|
|
|
17
17
|
export { auditLogQueries } from './audit-log-queries';
|
|
18
18
|
export { fileAuditLogQueries } from './file-audit-log-queries';
|
|
19
19
|
export { fileShareQueries } from './file-share-queries';
|
|
20
|
-
export type { FileShareRow
|
|
20
|
+
export type { FileShareRow } from './file-share-queries';
|
|
21
21
|
export { mcpServerQueries } from './mcp-server-queries';
|
|
22
22
|
export type { McpServerRow, McpServerInput, McpTransport, McpSource, McpConfigField, McpToolOverride, McpToolOverrides } from './mcp-server-queries';
|
|
23
23
|
export { skillQueries, parseTriggers, stringifyTriggers, parseUses, stringifyUses, SKILL_TRIGGERS } from './skill-queries';
|
|
@@ -51,5 +51,17 @@ export {
|
|
|
51
51
|
export { gitIdentityQueries, gitIdentityBindingQueries, parseHosts } from './git-identity-queries';
|
|
52
52
|
export type { GitIdentityRow, GitIdentityBindingRow, GitIdentityWrite } from './git-identity-queries';
|
|
53
53
|
export { pushSubscriptionQueries } from './push-subscription-queries';
|
|
54
|
+
export {
|
|
55
|
+
channelLinkQueries,
|
|
56
|
+
channelMessageQueries,
|
|
57
|
+
newChannelMessageId
|
|
58
|
+
} from './channel-queries';
|
|
59
|
+
export type {
|
|
60
|
+
ChannelLinkRow,
|
|
61
|
+
ChannelMessageRow,
|
|
62
|
+
ChannelMessageKind,
|
|
63
|
+
ChannelMessageState,
|
|
64
|
+
ChannelMessageInput
|
|
65
|
+
} from './channel-queries';
|
|
54
66
|
export type { PushSubscription, PushSubscriptionInput } from './push-subscription-queries';
|
|
55
67
|
export type { WorktreeBranchBindingRow, WorktreeBranchRow } from './worktree-branch-queries';
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A sent message is saved under the id its optimistic bubble already shows,
|
|
3
|
+
* when that id is safe to take; and which messages count as on a session's
|
|
4
|
+
* active branch.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { describe, it, expect, beforeAll, afterAll } from 'bun:test';
|
|
8
|
+
import { initializeDatabase, closeDatabase } from '$backend/database';
|
|
9
|
+
import { messageQueries, projectQueries, sessionQueries } from '$backend/database/queries';
|
|
10
|
+
import type { UnifiedMessage } from '$shared/types/unified';
|
|
11
|
+
|
|
12
|
+
let projectId: string;
|
|
13
|
+
|
|
14
|
+
const engine = { type: 'claude-code', provider: '', model: { id: '', name: '' }, account: { id: 0, name: '' } };
|
|
15
|
+
const user = (text: string, messageId = '') => ({
|
|
16
|
+
type: 'user',
|
|
17
|
+
createdAt: '',
|
|
18
|
+
messageId,
|
|
19
|
+
sessionId: null,
|
|
20
|
+
parent: { messageId: null, sessionId: null, toolUseId: null },
|
|
21
|
+
engine,
|
|
22
|
+
content: [{ type: 'text', text }]
|
|
23
|
+
}) as unknown as UnifiedMessage;
|
|
24
|
+
|
|
25
|
+
function newSession(): string {
|
|
26
|
+
return sessionQueries.create({ project_id: projectId, engine: 'claude-code', started_at: new Date().toISOString() } as never).id;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Append to a session's branch, moving HEAD like the stream does. */
|
|
30
|
+
function append(sessionId: string, text: string, parent?: string): string {
|
|
31
|
+
const row = messageQueries.create({ session_id: sessionId, message: user(text), parent_message_id: parent });
|
|
32
|
+
sessionQueries.updateHead(sessionId, row.id);
|
|
33
|
+
return row.id;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
beforeAll(async () => {
|
|
37
|
+
await initializeDatabase();
|
|
38
|
+
projectId = projectQueries.create({ name: 'message-queries', path: `/tmp/message-queries-${crypto.randomUUID()}`, created_at: new Date().toISOString(), last_opened_at: new Date().toISOString() } as never).id;
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
afterAll(() => {
|
|
42
|
+
sessionQueries.deleteAllByProjectId(projectId);
|
|
43
|
+
projectQueries.deleteProject(projectId);
|
|
44
|
+
closeDatabase();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe('messageQueries.create preferred_id', () => {
|
|
48
|
+
it('keeps a fresh UUID, in the row and in the stored message alike', () => {
|
|
49
|
+
const session = newSession();
|
|
50
|
+
const id = crypto.randomUUID();
|
|
51
|
+
const row = messageQueries.create({ session_id: session, message: user('hi', id), preferred_id: id });
|
|
52
|
+
expect(row.id).toBe(id);
|
|
53
|
+
expect(JSON.parse(row.data).messageId).toBe(id);
|
|
54
|
+
expect(messageQueries.getById(id)?.session_id).toBe(session);
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('accepts an upper-case UUID as is', () => {
|
|
58
|
+
const id = crypto.randomUUID().toUpperCase();
|
|
59
|
+
const row = messageQueries.create({ session_id: newSession(), message: user('hi'), preferred_id: id });
|
|
60
|
+
expect(row.id).toBe(id);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('never takes an id that is already saved — not even from another session', () => {
|
|
64
|
+
const id = crypto.randomUUID();
|
|
65
|
+
messageQueries.create({ session_id: newSession(), message: user('first'), preferred_id: id });
|
|
66
|
+
const second = messageQueries.create({ session_id: newSession(), message: user('second'), preferred_id: id });
|
|
67
|
+
expect(second.id).not.toBe(id);
|
|
68
|
+
expect(JSON.parse(messageQueries.getById(id)!.data).content[0].text).toBe('first');
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('gives a fresh id to anything that is not a canonical UUID', () => {
|
|
72
|
+
const session = newSession();
|
|
73
|
+
const uuid = crypto.randomUUID();
|
|
74
|
+
const hostile: unknown[] = [
|
|
75
|
+
'',
|
|
76
|
+
' ',
|
|
77
|
+
'abc',
|
|
78
|
+
`${uuid} `,
|
|
79
|
+
` ${uuid}`,
|
|
80
|
+
`${uuid}\n`,
|
|
81
|
+
`${uuid}x`,
|
|
82
|
+
uuid.replace(/-/g, ''),
|
|
83
|
+
`{${uuid}}`,
|
|
84
|
+
`${uuid}'; DROP TABLE messages; --`,
|
|
85
|
+
"' OR 1=1 --",
|
|
86
|
+
'../../etc/passwd',
|
|
87
|
+
'00000000-0000-0000-0000-00000000000g',
|
|
88
|
+
'a'.repeat(10_000),
|
|
89
|
+
'💥💥💥💥💥💥💥💥-💥💥💥💥-💥💥💥💥-💥💥💥💥-💥💥💥💥💥💥💥💥💥💥💥💥',
|
|
90
|
+
null,
|
|
91
|
+
42,
|
|
92
|
+
{ toString: () => crypto.randomUUID() },
|
|
93
|
+
[crypto.randomUUID()]
|
|
94
|
+
];
|
|
95
|
+
for (const preferred of hostile) {
|
|
96
|
+
const row = messageQueries.create({ session_id: session, message: user('x'), preferred_id: preferred as string });
|
|
97
|
+
expect(row.id).not.toBe(preferred as string);
|
|
98
|
+
expect(row.id).toMatch(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/);
|
|
99
|
+
}
|
|
100
|
+
expect(messageQueries.getById(uuid)).toBeNull();
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('gives a fresh id when none is asked for', () => {
|
|
104
|
+
const a = messageQueries.create({ session_id: newSession(), message: user('a') });
|
|
105
|
+
const b = messageQueries.create({ session_id: newSession(), message: user('b') });
|
|
106
|
+
expect(a.id).not.toBe(b.id);
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
describe('messageQueries.isOnActivePath', () => {
|
|
111
|
+
it('is true for HEAD and every ancestor of it', () => {
|
|
112
|
+
const session = newSession();
|
|
113
|
+
const one = append(session, 'one');
|
|
114
|
+
const two = append(session, 'two', one);
|
|
115
|
+
const three = append(session, 'three', two);
|
|
116
|
+
for (const id of [one, two, three]) expect(messageQueries.isOnActivePath(session, id)).toBe(true);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it('is false for a branch the session moved away from', () => {
|
|
120
|
+
const session = newSession();
|
|
121
|
+
const one = append(session, 'one');
|
|
122
|
+
const abandoned = append(session, 'abandoned', one);
|
|
123
|
+
const taken = append(session, 'taken', one);
|
|
124
|
+
expect(messageQueries.isOnActivePath(session, abandoned)).toBe(false);
|
|
125
|
+
expect(messageQueries.isOnActivePath(session, taken)).toBe(true);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('is false after rewinding before the message', () => {
|
|
129
|
+
const session = newSession();
|
|
130
|
+
const one = append(session, 'one');
|
|
131
|
+
const two = append(session, 'two', one);
|
|
132
|
+
sessionQueries.updateHead(session, one);
|
|
133
|
+
expect(messageQueries.isOnActivePath(session, two)).toBe(false);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('is false for another session’s message, an unknown id, and a session without HEAD', () => {
|
|
137
|
+
const session = newSession();
|
|
138
|
+
append(session, 'mine');
|
|
139
|
+
const other = newSession();
|
|
140
|
+
const theirs = append(other, 'theirs');
|
|
141
|
+
expect(messageQueries.isOnActivePath(session, theirs)).toBe(false);
|
|
142
|
+
expect(messageQueries.isOnActivePath(session, crypto.randomUUID())).toBe(false);
|
|
143
|
+
expect(messageQueries.isOnActivePath(newSession(), theirs)).toBe(false);
|
|
144
|
+
expect(messageQueries.isOnActivePath(crypto.randomUUID(), theirs)).toBe(false);
|
|
145
|
+
});
|
|
146
|
+
});
|
|
@@ -4,6 +4,9 @@ import type { UnifiedMessage } from '$shared/types/unified';
|
|
|
4
4
|
import { debug } from '$shared/utils/logger';
|
|
5
5
|
import { trimSubAgentForWire } from '$shared/utils/subagent-wire-trim';
|
|
6
6
|
|
|
7
|
+
/** A UUID in canonical 8-4-4-4-12 form, as crypto.randomUUID() produces. */
|
|
8
|
+
const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
9
|
+
|
|
7
10
|
/** Parse message JSON from a DB row. */
|
|
8
11
|
function parseMessage(row: DatabaseMessage): UnifiedMessage {
|
|
9
12
|
return JSON.parse(row.data) as UnifiedMessage;
|
|
@@ -130,9 +133,22 @@ export const messageQueries = {
|
|
|
130
133
|
timestamp?: string;
|
|
131
134
|
branch_id?: string;
|
|
132
135
|
parent_message_id?: string;
|
|
136
|
+
/**
|
|
137
|
+
* The id the sender already shows this message under (the composer's
|
|
138
|
+
* optimistic bubble). Kept when it is a well-formed UUID nobody holds yet,
|
|
139
|
+
* so the bubble and the saved row are one message from the start —
|
|
140
|
+
* otherwise anything acting on the bubble before its echo arrives (edit,
|
|
141
|
+
* undo) names a row that never existed. Anything else gets a fresh id.
|
|
142
|
+
*/
|
|
143
|
+
preferred_id?: string;
|
|
133
144
|
}): DatabaseMessage {
|
|
134
145
|
const db = getDatabase();
|
|
135
|
-
const
|
|
146
|
+
const preferred = messageData.preferred_id;
|
|
147
|
+
const id = typeof preferred === 'string'
|
|
148
|
+
&& UUID_PATTERN.test(preferred)
|
|
149
|
+
&& !db.prepare('SELECT 1 FROM messages WHERE id = ?').get(preferred)
|
|
150
|
+
? preferred
|
|
151
|
+
: crypto.randomUUID();
|
|
136
152
|
const timestamp = messageData.timestamp || new Date().toISOString();
|
|
137
153
|
const parentMessageId = messageData.parent_message_id || null;
|
|
138
154
|
|
|
@@ -403,6 +419,31 @@ export const messageQueries = {
|
|
|
403
419
|
return path;
|
|
404
420
|
},
|
|
405
421
|
|
|
422
|
+
/**
|
|
423
|
+
* Whether a message of this session is on the branch the session shows:
|
|
424
|
+
* its HEAD or one of HEAD's ancestors. Walks parent ids only, without
|
|
425
|
+
* loading message bodies.
|
|
426
|
+
*/
|
|
427
|
+
isOnActivePath(sessionId: string, messageId: string): boolean {
|
|
428
|
+
const db = getDatabase();
|
|
429
|
+
const session = db.prepare(`
|
|
430
|
+
SELECT head_message_id FROM chat_sessions WHERE id = ?
|
|
431
|
+
`).get(sessionId) as { head_message_id: string | null } | null;
|
|
432
|
+
|
|
433
|
+
const parentOf = db.prepare(`
|
|
434
|
+
SELECT parent_message_id FROM messages WHERE id = ? AND session_id = ?
|
|
435
|
+
`);
|
|
436
|
+
const seen = new Set<string>();
|
|
437
|
+
let currentId = session?.head_message_id ?? null;
|
|
438
|
+
while (currentId && !seen.has(currentId)) {
|
|
439
|
+
if (currentId === messageId) return true;
|
|
440
|
+
seen.add(currentId);
|
|
441
|
+
const row = parentOf.get(currentId, sessionId) as { parent_message_id: string | null } | null;
|
|
442
|
+
currentId = row?.parent_message_id ?? null;
|
|
443
|
+
}
|
|
444
|
+
return false;
|
|
445
|
+
},
|
|
446
|
+
|
|
406
447
|
/**
|
|
407
448
|
* Get all descendants of a message (entire subtree)
|
|
408
449
|
*/
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* CRUD for per-engine tool allow/deny rules (Settings → Permissions). Each row
|
|
5
5
|
* carries the `allow` + `deny` tool-pattern lists for one
|
|
6
6
|
* `(scope, project_id, engine)` combination — see migration 049 for the resolved
|
|
7
|
-
* semantics. Instance-global
|
|
7
|
+
* semantics. Instance-global (no `user_id`), mirroring
|
|
8
8
|
* `skills` / `mcp_servers` / `subagents`.
|
|
9
9
|
*
|
|
10
10
|
* `allow` / `deny` are stored as JSON `string[]`; callers get parsed arrays back
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* `profile_items` table holds the (artifact_type, ref) references. Neither
|
|
8
8
|
* duplicates artifact data — see migration 050.
|
|
9
9
|
*
|
|
10
|
-
* Instance-global
|
|
10
|
+
* Instance-global (no `user_id`), mirroring
|
|
11
11
|
* `skills` / `mcp_servers` / `subagents` / `permission_sets`.
|
|
12
12
|
*/
|
|
13
13
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Project MCP trust — which version of a repository's `.agents/mcp.json` an
|
|
3
|
-
*
|
|
3
|
+
* owner approved. Approval is keyed by the file's sha256 (see migration 083), so
|
|
4
4
|
* a changed file is simply "not the approved one" until re-approved.
|
|
5
5
|
*/
|
|
6
6
|
|
|
@@ -10,14 +10,14 @@ export const projectQueries = {
|
|
|
10
10
|
`).all() as Project[];
|
|
11
11
|
},
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
/** Projects in the workspace list — everything except projects the owner removed. */
|
|
14
|
+
getListed(): Project[] {
|
|
14
15
|
const db = getDatabase();
|
|
15
16
|
return db.prepare(`
|
|
16
17
|
SELECT p.* FROM projects p
|
|
17
|
-
INNER JOIN
|
|
18
|
-
WHERE up.user_id = ?
|
|
18
|
+
INNER JOIN workspace_projects wp ON p.id = wp.project_id
|
|
19
19
|
ORDER BY p.created_at ASC
|
|
20
|
-
`).all(
|
|
20
|
+
`).all() as Project[];
|
|
21
21
|
},
|
|
22
22
|
|
|
23
23
|
getById(id: string): Project | null {
|
|
@@ -34,29 +34,35 @@ export const projectQueries = {
|
|
|
34
34
|
`).get(path) as Project | null;
|
|
35
35
|
},
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
isListed(projectId: string): boolean {
|
|
38
38
|
const db = getDatabase();
|
|
39
39
|
const result = db.prepare(`
|
|
40
|
-
SELECT 1 as ok FROM
|
|
41
|
-
|
|
42
|
-
LIMIT 1
|
|
43
|
-
`).get(userId, projectId) as { ok: number } | undefined;
|
|
40
|
+
SELECT 1 as ok FROM workspace_projects WHERE project_id = ? LIMIT 1
|
|
41
|
+
`).get(projectId) as { ok: number } | undefined;
|
|
44
42
|
return Boolean(result);
|
|
45
43
|
},
|
|
46
44
|
|
|
47
45
|
create(project: Omit<Project, 'id'>): Project {
|
|
48
46
|
const db = getDatabase();
|
|
49
47
|
const id = crypto.randomUUID();
|
|
50
|
-
const newProject = { id, ...project };
|
|
48
|
+
const newProject: Project = { id, kind: 'project', ...project };
|
|
51
49
|
|
|
52
50
|
db.prepare(`
|
|
53
|
-
INSERT INTO projects (id, name, path, created_at, last_opened_at)
|
|
54
|
-
VALUES (?, ?, ?, ?, ?)
|
|
55
|
-
`).run(id, project.name, project.path, project.created_at, project.last_opened_at);
|
|
51
|
+
INSERT INTO projects (id, name, path, created_at, last_opened_at, kind)
|
|
52
|
+
VALUES (?, ?, ?, ?, ?, ?)
|
|
53
|
+
`).run(id, project.name, project.path, project.created_at, project.last_opened_at, newProject.kind ?? 'project');
|
|
56
54
|
|
|
57
55
|
return newProject;
|
|
58
56
|
},
|
|
59
57
|
|
|
58
|
+
/** The Home workspace, if it has been created. */
|
|
59
|
+
getHome(): Project | null {
|
|
60
|
+
const db = getDatabase();
|
|
61
|
+
return db.prepare(`
|
|
62
|
+
SELECT * FROM projects WHERE kind = 'home'
|
|
63
|
+
`).get() as Project | null;
|
|
64
|
+
},
|
|
65
|
+
|
|
60
66
|
updateLastOpened(id: string): void {
|
|
61
67
|
const db = getDatabase();
|
|
62
68
|
const now = new Date().toISOString();
|
|
@@ -67,7 +73,7 @@ export const projectQueries = {
|
|
|
67
73
|
`).run(now, id);
|
|
68
74
|
},
|
|
69
75
|
|
|
70
|
-
/** The project-wide default profile
|
|
76
|
+
/** The project-wide default profile, or null. */
|
|
71
77
|
getDefaultProfileId(id: string): number | null {
|
|
72
78
|
const db = getDatabase();
|
|
73
79
|
const row = db.prepare(`SELECT default_profile_id FROM projects WHERE id = ?`)
|
|
@@ -83,92 +89,73 @@ export const projectQueries = {
|
|
|
83
89
|
|
|
84
90
|
deleteProject(id: string): void {
|
|
85
91
|
const db = getDatabase();
|
|
86
|
-
db.prepare('DELETE FROM
|
|
92
|
+
db.prepare('DELETE FROM workspace_projects WHERE project_id = ?').run(id);
|
|
87
93
|
db.prepare('DELETE FROM projects WHERE id = ?').run(id);
|
|
88
94
|
},
|
|
89
95
|
|
|
90
|
-
|
|
96
|
+
/** Put a project in the workspace list (idempotent). */
|
|
97
|
+
list(projectId: string): void {
|
|
91
98
|
const db = getDatabase();
|
|
92
99
|
const now = new Date().toISOString();
|
|
93
100
|
db.prepare(`
|
|
94
|
-
INSERT OR IGNORE INTO
|
|
95
|
-
VALUES (?,
|
|
96
|
-
`).run(
|
|
101
|
+
INSERT OR IGNORE INTO workspace_projects (project_id, joined_at)
|
|
102
|
+
VALUES (?, ?)
|
|
103
|
+
`).run(projectId, now);
|
|
97
104
|
},
|
|
98
105
|
|
|
99
|
-
|
|
106
|
+
/** Take a project out of the workspace list, keeping its record and chats. */
|
|
107
|
+
unlist(projectId: string): void {
|
|
100
108
|
const db = getDatabase();
|
|
101
|
-
db.prepare(
|
|
102
|
-
DELETE FROM user_projects WHERE user_id = ? AND project_id = ?
|
|
103
|
-
`).run(userId, projectId);
|
|
104
|
-
},
|
|
105
|
-
|
|
106
|
-
getUserCountForProject(projectId: string): number {
|
|
107
|
-
const db = getDatabase();
|
|
108
|
-
const result = db.prepare(`
|
|
109
|
-
SELECT COUNT(*) as count FROM user_projects WHERE project_id = ?
|
|
110
|
-
`).get(projectId) as { count: number };
|
|
111
|
-
return result.count;
|
|
109
|
+
db.prepare('DELETE FROM workspace_projects WHERE project_id = ?').run(projectId);
|
|
112
110
|
},
|
|
113
111
|
|
|
114
|
-
getCurrentSessionId(
|
|
112
|
+
getCurrentSessionId(projectId: string): string | null {
|
|
115
113
|
const db = getDatabase();
|
|
116
114
|
const result = db.prepare(`
|
|
117
|
-
SELECT current_session_id FROM
|
|
118
|
-
|
|
119
|
-
`).get(userId, projectId) as { current_session_id: string | null } | null;
|
|
115
|
+
SELECT current_session_id FROM workspace_projects WHERE project_id = ?
|
|
116
|
+
`).get(projectId) as { current_session_id: string | null } | null;
|
|
120
117
|
return result?.current_session_id || null;
|
|
121
118
|
},
|
|
122
119
|
|
|
123
|
-
setCurrentSessionId(
|
|
120
|
+
setCurrentSessionId(projectId: string, sessionId: string | null): void {
|
|
124
121
|
const db = getDatabase();
|
|
125
|
-
// Ensure the user_projects row exists
|
|
126
122
|
const now = new Date().toISOString();
|
|
127
123
|
db.prepare(`
|
|
128
|
-
INSERT OR IGNORE INTO
|
|
129
|
-
VALUES (?,
|
|
130
|
-
`).run(
|
|
131
|
-
// Update the current session
|
|
124
|
+
INSERT OR IGNORE INTO workspace_projects (project_id, joined_at)
|
|
125
|
+
VALUES (?, ?)
|
|
126
|
+
`).run(projectId, now);
|
|
132
127
|
db.prepare(`
|
|
133
|
-
UPDATE
|
|
134
|
-
|
|
135
|
-
WHERE user_id = ? AND project_id = ?
|
|
136
|
-
`).run(sessionId, userId, projectId);
|
|
128
|
+
UPDATE workspace_projects SET current_session_id = ? WHERE project_id = ?
|
|
129
|
+
`).run(sessionId, projectId);
|
|
137
130
|
},
|
|
138
131
|
|
|
139
|
-
getFilesPanelState(
|
|
132
|
+
getFilesPanelState(projectId: string): string | null {
|
|
140
133
|
const db = getDatabase();
|
|
141
134
|
const result = db.prepare(`
|
|
142
|
-
SELECT files_panel_state FROM
|
|
143
|
-
|
|
144
|
-
`).get(userId, projectId) as { files_panel_state: string | null } | null;
|
|
135
|
+
SELECT files_panel_state FROM workspace_projects WHERE project_id = ?
|
|
136
|
+
`).get(projectId) as { files_panel_state: string | null } | null;
|
|
145
137
|
return result?.files_panel_state || null;
|
|
146
138
|
},
|
|
147
139
|
|
|
148
|
-
setFilesPanelState(
|
|
140
|
+
setFilesPanelState(projectId: string, state: string | null): void {
|
|
149
141
|
const db = getDatabase();
|
|
150
142
|
db.prepare(`
|
|
151
|
-
UPDATE
|
|
152
|
-
|
|
153
|
-
WHERE user_id = ? AND project_id = ?
|
|
154
|
-
`).run(state, userId, projectId);
|
|
143
|
+
UPDATE workspace_projects SET files_panel_state = ? WHERE project_id = ?
|
|
144
|
+
`).run(state, projectId);
|
|
155
145
|
},
|
|
156
146
|
|
|
157
|
-
getWorkspaceState(
|
|
147
|
+
getWorkspaceState(projectId: string): string | null {
|
|
158
148
|
const db = getDatabase();
|
|
159
149
|
const result = db.prepare(`
|
|
160
|
-
SELECT workspace_state FROM
|
|
161
|
-
|
|
162
|
-
`).get(userId, projectId) as { workspace_state: string | null } | null;
|
|
150
|
+
SELECT workspace_state FROM workspace_projects WHERE project_id = ?
|
|
151
|
+
`).get(projectId) as { workspace_state: string | null } | null;
|
|
163
152
|
return result?.workspace_state || null;
|
|
164
153
|
},
|
|
165
154
|
|
|
166
|
-
setWorkspaceState(
|
|
155
|
+
setWorkspaceState(projectId: string, state: string | null): void {
|
|
167
156
|
const db = getDatabase();
|
|
168
157
|
db.prepare(`
|
|
169
|
-
UPDATE
|
|
170
|
-
|
|
171
|
-
WHERE user_id = ? AND project_id = ?
|
|
172
|
-
`).run(state, userId, projectId);
|
|
158
|
+
UPDATE workspace_projects SET workspace_state = ? WHERE project_id = ?
|
|
159
|
+
`).run(state, projectId);
|
|
173
160
|
}
|
|
174
161
|
};
|