@myrialabs/clopen 0.4.40 → 0.4.42
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/.env.example +1 -1
- package/backend/artifacts/detect.ts +15 -3
- package/backend/artifacts/generate.ts +2 -2
- package/backend/artifacts/index.ts +12 -4
- package/backend/artifacts/markers.ts +24 -1
- package/backend/artifacts/matrix.ts +47 -3
- package/backend/artifacts/sync.test.ts +3 -3
- package/backend/artifacts/sync.ts +8 -20
- package/backend/artifacts/types.ts +9 -3
- package/backend/auth/permissions.ts +6 -11
- package/backend/auth/session-cleanup.ts +10 -1
- package/backend/auth/tokens.ts +9 -1
- package/backend/chat/stream-manager.ts +50 -0
- package/backend/database/crypto/secret-columns.ts +5 -1
- package/backend/database/index.ts +18 -0
- package/backend/database/migrations/079_merge_commands_into_skills.ts +222 -0
- package/backend/database/migrations/080_create_file_shares.ts +111 -0
- package/backend/database/migrations/081_create_push_subscriptions.ts +32 -0
- package/backend/database/migrations/082_create_git_identities.test.ts +186 -0
- package/backend/database/migrations/082_create_git_identities.ts +122 -0
- package/backend/database/migrations/index.ts +28 -0
- package/backend/database/queries/file-share-queries.ts +163 -0
- package/backend/database/queries/git-identity-queries.ts +290 -0
- package/backend/database/queries/index.ts +8 -4
- package/backend/database/queries/profile-queries.ts +5 -3
- package/backend/database/queries/push-subscription-queries.test.ts +90 -0
- package/backend/database/queries/push-subscription-queries.ts +99 -0
- package/backend/database/queries/skill-queries.ts +96 -18
- package/backend/engine/adapters/claude/environment.ts +11 -1
- package/backend/engine/adapters/claude/stream.ts +3 -2
- package/backend/engine/adapters/cline/stream.ts +3 -3
- package/backend/engine/adapters/codex/stream.ts +38 -6
- package/backend/engine/adapters/copilot/stream.ts +3 -3
- package/backend/engine/adapters/cursor/stream.ts +25 -3
- package/backend/engine/adapters/opencode/server.ts +26 -2
- package/backend/engine/adapters/opencode/stream.ts +8 -7
- package/backend/engine/adapters/pi/stream.ts +2 -2
- package/backend/engine/adapters/qwen/stream.ts +5 -3
- package/backend/engine/artifact-sync.ts +26 -20
- package/backend/engine/docs/artifacts.md +81 -22
- package/backend/engine/docs/quick-reference.md +2 -1
- package/backend/engine/resolve-model.test.ts +108 -0
- package/backend/engine/resolve-model.ts +53 -10
- package/backend/engine/structured-helpers.ts +22 -0
- package/backend/engine/types.ts +10 -0
- package/backend/files/file-shares.ts +369 -0
- package/backend/files/path-browsing.ts +27 -21
- package/backend/git/git-executor.ts +28 -2
- package/backend/git/git-service.ts +59 -40
- package/backend/git/identity/cli.test.ts +58 -0
- package/backend/git/identity/cli.ts +201 -0
- package/backend/git/identity/credential-helper.test.ts +242 -0
- package/backend/git/identity/env.test.ts +214 -0
- package/backend/git/identity/env.ts +193 -0
- package/backend/git/identity/import-local.test.ts +199 -0
- package/backend/git/identity/import-local.ts +141 -0
- package/backend/git/identity/index.ts +78 -0
- package/backend/git/identity/keys.ts +183 -0
- package/backend/git/identity/resolve.ts +140 -0
- package/backend/git/identity/scope-config.test.ts +145 -0
- package/backend/git/identity/scope-config.ts +175 -0
- package/backend/git/identity/service.ts +297 -0
- package/backend/http/files-shared.test.ts +505 -0
- package/backend/http/files-shared.ts +351 -0
- package/backend/http/push.ts +150 -0
- package/backend/index.ts +24 -0
- package/backend/instructions/index.ts +1 -1
- package/backend/instructions/sync.ts +30 -6
- package/backend/memory/compose.ts +2 -2
- package/backend/memory/consolidate.ts +2 -2
- package/backend/memory/extract/episodic.ts +2 -2
- package/backend/memory/judge.ts +2 -2
- package/backend/preview/browser/browser-console-manager.ts +214 -34
- package/backend/preview/browser/browser-pool.ts +526 -123
- package/backend/preview/browser/browser-preview-service.ts +192 -8
- package/backend/preview/browser/browser-tab-lifecycle.test.ts +240 -0
- package/backend/preview/browser/browser-tab-lifecycle.ts +495 -0
- package/backend/preview/browser/browser-tab-manager.ts +291 -65
- package/backend/preview/browser/capture-profile.ts +15 -1
- package/backend/preview/browser/types.ts +26 -1
- package/backend/profiles/service.ts +7 -6
- package/backend/push/sender.ts +172 -0
- package/backend/push/tags.ts +25 -0
- package/backend/push/vapid-keys.ts +77 -0
- package/backend/push/webpush-crypto.test.ts +200 -0
- package/backend/push/webpush-crypto.ts +231 -0
- package/backend/skills/detect.ts +28 -0
- package/backend/skills/index.ts +22 -4
- package/backend/skills/invoke.test.ts +114 -0
- package/backend/skills/invoke.ts +222 -0
- package/backend/skills/service.ts +194 -44
- package/backend/skills/spec.ts +35 -0
- package/backend/skills/sync.ts +85 -55
- package/backend/subagents/detect.ts +2 -3
- package/backend/subagents/sync.ts +15 -8
- package/backend/terminal/ptykit.ts +24 -0
- package/backend/work/pull-requests.ts +2 -2
- package/backend/ws/chat/stream.ts +100 -8
- package/backend/ws/files/index.ts +4 -0
- package/backend/ws/files/share.ts +95 -0
- package/backend/ws/git/branch-name.ts +2 -2
- package/backend/ws/git/branch.ts +17 -6
- package/backend/ws/git/commit-message.ts +2 -2
- package/backend/ws/git/commit.ts +6 -5
- package/backend/ws/git/conflict.ts +3 -2
- package/backend/ws/git/identity-context.ts +91 -0
- package/backend/ws/git/identity.ts +200 -0
- package/backend/ws/git/index.ts +3 -1
- package/backend/ws/git/remote.ts +57 -11
- package/backend/ws/index.ts +3 -4
- package/backend/ws/preview/browser/data.ts +60 -0
- package/backend/ws/preview/browser/interact.ts +6 -0
- package/backend/ws/preview/browser/tab-info.ts +9 -1
- package/backend/ws/preview/browser/tab.ts +64 -8
- package/backend/ws/preview/index.ts +21 -0
- package/backend/ws/profiles/crud.ts +2 -3
- package/backend/ws/skills/catalog.ts +5 -1
- package/backend/ws/skills/crud.ts +128 -22
- package/backend/ws/skills/index.ts +4 -1
- package/backend/ws/user/crud.ts +12 -3
- package/bin/clopen.ts +9 -0
- package/dist/assets/{index-D4igjF6e.js → index-BynqyvF4.js} +1 -1
- package/dist/assets/{index-DONNwiXm.js → index-DLoJsmNQ.js} +1 -1
- package/dist/assets/{main-BrfXH1bL.js → main-CUyZAmqt.js} +601 -592
- package/dist/assets/main-DVCW3cfr.css +1 -0
- package/dist/index.html +7 -2
- package/dist/sw.js +112 -0
- package/package.json +2 -2
- package/shared/constants/engine-tools.ts +31 -6
- package/shared/constants/notification-messages.ts +142 -0
- package/shared/types/git-identity.ts +112 -0
- package/shared/types/unified/stream.ts +7 -0
- package/backend/commands/detect.ts +0 -25
- package/backend/commands/index.ts +0 -9
- package/backend/commands/service.ts +0 -178
- package/backend/commands/store.ts +0 -45
- package/backend/commands/sync.ts +0 -94
- package/backend/database/queries/command-queries.ts +0 -82
- package/backend/ws/commands/crud.ts +0 -157
- package/backend/ws/commands/index.ts +0 -8
- package/dist/assets/main-CT1PygsW.css +0 -1
|
@@ -77,6 +77,10 @@ import * as migration075 from './075_create_deploy_bindings';
|
|
|
77
77
|
import * as migration076 from './076_remove_memory_code_graph';
|
|
78
78
|
import * as migration077 from './077_create_integration_db_links';
|
|
79
79
|
import * as migration078 from './078_create_worktree_branch_tables';
|
|
80
|
+
import * as migration079 from './079_merge_commands_into_skills';
|
|
81
|
+
import * as migration080 from './080_create_file_shares';
|
|
82
|
+
import * as migration081 from './081_create_push_subscriptions';
|
|
83
|
+
import * as migration082 from './082_create_git_identities';
|
|
80
84
|
|
|
81
85
|
// Export all migrations in order
|
|
82
86
|
export const migrations = [
|
|
@@ -547,6 +551,30 @@ export const migrations = [
|
|
|
547
551
|
description: migration078.description,
|
|
548
552
|
up: migration078.up,
|
|
549
553
|
down: migration078.down
|
|
554
|
+
},
|
|
555
|
+
{
|
|
556
|
+
id: '079',
|
|
557
|
+
description: migration079.description,
|
|
558
|
+
up: migration079.up,
|
|
559
|
+
down: migration079.down
|
|
560
|
+
},
|
|
561
|
+
{
|
|
562
|
+
id: '080',
|
|
563
|
+
description: migration080.description,
|
|
564
|
+
up: migration080.up,
|
|
565
|
+
down: migration080.down
|
|
566
|
+
},
|
|
567
|
+
{
|
|
568
|
+
id: '081',
|
|
569
|
+
description: migration081.description,
|
|
570
|
+
up: migration081.up,
|
|
571
|
+
down: migration081.down
|
|
572
|
+
},
|
|
573
|
+
{
|
|
574
|
+
id: '082',
|
|
575
|
+
description: migration082.description,
|
|
576
|
+
up: migration082.up,
|
|
577
|
+
down: migration082.down
|
|
550
578
|
}
|
|
551
579
|
];
|
|
552
580
|
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* File Share Queries
|
|
3
|
+
*
|
|
4
|
+
* Storage for shareable single-file links ("Share Link…" in the File
|
|
5
|
+
* Explorer). Only the token's SHA-256 hash is stored; the raw token lives in
|
|
6
|
+
* the shared URL and is never written down.
|
|
7
|
+
*
|
|
8
|
+
* Everything a caller can act on is keyed by `id`, not by the token: the raw
|
|
9
|
+
* token exists once, in the browser that minted it, so a revoke keyed on the
|
|
10
|
+
* secret would be unreachable the moment that view closes.
|
|
11
|
+
*
|
|
12
|
+
* A NULL `expires_at` means "until revoked" — every query that filters on the
|
|
13
|
+
* deadline has to admit that row, which is why the condition is spelled out
|
|
14
|
+
* rather than left to a plain comparison (SQL comparisons against NULL are
|
|
15
|
+
* neither true nor false, so `expires_at > ?` alone would silently hide them).
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { getDatabase } from '../index';
|
|
19
|
+
import { nanoid } from 'nanoid';
|
|
20
|
+
|
|
21
|
+
export interface FileShareRow {
|
|
22
|
+
id: string;
|
|
23
|
+
token_hash: string;
|
|
24
|
+
file_path: string;
|
|
25
|
+
created_by: string;
|
|
26
|
+
/** 1 = dies on the first open, 0 = openable until it expires or is revoked. */
|
|
27
|
+
one_time: number;
|
|
28
|
+
/** ISO deadline, or null for a link that only a revoke ends. */
|
|
29
|
+
expires_at: string | null;
|
|
30
|
+
consumed_at: string | null;
|
|
31
|
+
consumer_hash: string | null;
|
|
32
|
+
open_count: number;
|
|
33
|
+
last_opened_at: string | null;
|
|
34
|
+
created_at: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** A row joined with its creator's display name, for the management list. */
|
|
38
|
+
export interface FileShareListRow extends FileShareRow {
|
|
39
|
+
created_by_name: string | null;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface CreateFileShareParams {
|
|
43
|
+
tokenHash: string;
|
|
44
|
+
filePath: string;
|
|
45
|
+
createdBy: string;
|
|
46
|
+
oneTime: boolean;
|
|
47
|
+
expiresAt: string | null;
|
|
48
|
+
createdAt: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const LIST_SELECT = `
|
|
52
|
+
SELECT s.*, u.name AS created_by_name
|
|
53
|
+
FROM file_shares s
|
|
54
|
+
LEFT JOIN users u ON u.id = s.created_by
|
|
55
|
+
`;
|
|
56
|
+
|
|
57
|
+
/** Rows that have not passed their deadline — including the ones without one. */
|
|
58
|
+
const LIVE = '(s.expires_at IS NULL OR s.expires_at > ?)';
|
|
59
|
+
|
|
60
|
+
export const fileShareQueries = {
|
|
61
|
+
create(params: CreateFileShareParams): FileShareRow {
|
|
62
|
+
const db = getDatabase();
|
|
63
|
+
const id = nanoid();
|
|
64
|
+
db.prepare(`
|
|
65
|
+
INSERT INTO file_shares (
|
|
66
|
+
id, token_hash, file_path, created_by, one_time, expires_at,
|
|
67
|
+
consumed_at, consumer_hash, open_count, last_opened_at, created_at
|
|
68
|
+
)
|
|
69
|
+
VALUES (?, ?, ?, ?, ?, ?, NULL, NULL, 0, NULL, ?)
|
|
70
|
+
`).run(
|
|
71
|
+
id,
|
|
72
|
+
params.tokenHash,
|
|
73
|
+
params.filePath,
|
|
74
|
+
params.createdBy,
|
|
75
|
+
params.oneTime ? 1 : 0,
|
|
76
|
+
params.expiresAt,
|
|
77
|
+
params.createdAt
|
|
78
|
+
);
|
|
79
|
+
return db.prepare('SELECT * FROM file_shares WHERE id = ?').get(id) as FileShareRow;
|
|
80
|
+
},
|
|
81
|
+
|
|
82
|
+
getByHash(tokenHash: string): FileShareRow | null {
|
|
83
|
+
const db = getDatabase();
|
|
84
|
+
return db.prepare('SELECT * FROM file_shares WHERE token_hash = ?').get(tokenHash) as FileShareRow | null;
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
getById(id: string): FileShareRow | null {
|
|
88
|
+
const db = getDatabase();
|
|
89
|
+
return db.prepare('SELECT * FROM file_shares WHERE id = ?').get(id) as FileShareRow | null;
|
|
90
|
+
},
|
|
91
|
+
|
|
92
|
+
/** Every live link, newest first — the admin view of what is currently open. */
|
|
93
|
+
listAll(now: string): FileShareListRow[] {
|
|
94
|
+
const db = getDatabase();
|
|
95
|
+
return db.prepare(`${LIST_SELECT} WHERE ${LIVE} ORDER BY s.created_at DESC`)
|
|
96
|
+
.all(now) as FileShareListRow[];
|
|
97
|
+
},
|
|
98
|
+
|
|
99
|
+
/** One user's live links, newest first. */
|
|
100
|
+
listForUser(userId: string, now: string): FileShareListRow[] {
|
|
101
|
+
const db = getDatabase();
|
|
102
|
+
return db.prepare(`${LIST_SELECT} WHERE s.created_by = ? AND ${LIVE} ORDER BY s.created_at DESC`)
|
|
103
|
+
.all(userId, now) as FileShareListRow[];
|
|
104
|
+
},
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Burn the single use of a one-time link. Conditional on `consumed_at IS
|
|
108
|
+
* NULL` and on the deadline, so exactly one of any number of concurrent
|
|
109
|
+
* opens gets `changes === 1` — the same single-use guarantee
|
|
110
|
+
* `markDeviceCodeClaimed` relies on.
|
|
111
|
+
*/
|
|
112
|
+
consume(tokenHash: string, consumedAt: string, consumerHash: string): number {
|
|
113
|
+
const db = getDatabase();
|
|
114
|
+
const result = db.prepare(`
|
|
115
|
+
UPDATE file_shares
|
|
116
|
+
SET consumed_at = ?, consumer_hash = ?, open_count = open_count + 1, last_opened_at = ?
|
|
117
|
+
WHERE token_hash = ?
|
|
118
|
+
AND one_time = 1
|
|
119
|
+
AND consumed_at IS NULL
|
|
120
|
+
AND (expires_at IS NULL OR expires_at > ?)
|
|
121
|
+
`).run(consumedAt, consumerHash, consumedAt, tokenHash, consumedAt) as { changes: number };
|
|
122
|
+
return result.changes;
|
|
123
|
+
},
|
|
124
|
+
|
|
125
|
+
/** Record an open of a reusable link — the counter the list reports from. */
|
|
126
|
+
recordOpen(tokenHash: string, openedAt: string): number {
|
|
127
|
+
const db = getDatabase();
|
|
128
|
+
const result = db.prepare(`
|
|
129
|
+
UPDATE file_shares
|
|
130
|
+
SET open_count = open_count + 1, last_opened_at = ?
|
|
131
|
+
WHERE token_hash = ?
|
|
132
|
+
`).run(openedAt, tokenHash) as { changes: number };
|
|
133
|
+
return result.changes;
|
|
134
|
+
},
|
|
135
|
+
|
|
136
|
+
deleteById(id: string): number {
|
|
137
|
+
const db = getDatabase();
|
|
138
|
+
const result = db.prepare('DELETE FROM file_shares WHERE id = ?').run(id) as { changes: number };
|
|
139
|
+
return result.changes;
|
|
140
|
+
},
|
|
141
|
+
|
|
142
|
+
deleteByHash(tokenHash: string): number {
|
|
143
|
+
const db = getDatabase();
|
|
144
|
+
const result = db.prepare('DELETE FROM file_shares WHERE token_hash = ?').run(tokenHash) as { changes: number };
|
|
145
|
+
return result.changes;
|
|
146
|
+
},
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Remove links that can never serve bytes again: past their deadline, or
|
|
150
|
+
* burned longer ago than the streaming-continuation window. A link without
|
|
151
|
+
* a deadline is never swept — ending it is a deliberate revoke.
|
|
152
|
+
*/
|
|
153
|
+
deleteStale(drainCutoff: string): number {
|
|
154
|
+
const db = getDatabase();
|
|
155
|
+
const now = new Date().toISOString();
|
|
156
|
+
const result = db.prepare(`
|
|
157
|
+
DELETE FROM file_shares
|
|
158
|
+
WHERE (expires_at IS NOT NULL AND expires_at < ?)
|
|
159
|
+
OR (consumed_at IS NOT NULL AND consumed_at < ?)
|
|
160
|
+
`).run(now, drainCutoff) as { changes: number };
|
|
161
|
+
return result.changes;
|
|
162
|
+
}
|
|
163
|
+
};
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Git identity storage — rows in, rows out, secrets sealed at this boundary.
|
|
3
|
+
*
|
|
4
|
+
* Every write that touches `ssh_private_key`, `ssh_passphrase` or `https_token`
|
|
5
|
+
* goes through `sealFor`, and every read goes through `openRow`, which is the
|
|
6
|
+
* contract `backend/database/crypto/secret-columns.ts` audits at startup.
|
|
7
|
+
* Nothing above this module handles a sealed value.
|
|
8
|
+
*
|
|
9
|
+
* Secrets are UPDATED ONLY WHEN SUPPLIED. `undefined` means "leave what is
|
|
10
|
+
* stored", `null` means "clear it". Without that distinction every edit of a
|
|
11
|
+
* label would have to round-trip the private key through the browser to avoid
|
|
12
|
+
* wiping it — which is exactly what the DTO refuses to do.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { getDatabase } from '../index';
|
|
16
|
+
import { openRow, openRows, sealFor } from '../crypto/secret-columns';
|
|
17
|
+
import type { GitIdentityAuthMethod, GitIdentitySource } from '$shared/types/git-identity';
|
|
18
|
+
|
|
19
|
+
const TABLE = 'git_identities';
|
|
20
|
+
|
|
21
|
+
export interface GitIdentityRow {
|
|
22
|
+
id: string;
|
|
23
|
+
owner_user_id: string;
|
|
24
|
+
label: string;
|
|
25
|
+
name: string;
|
|
26
|
+
email: string;
|
|
27
|
+
auth_method: GitIdentityAuthMethod;
|
|
28
|
+
ssh_private_key: string | null;
|
|
29
|
+
ssh_public_key: string | null;
|
|
30
|
+
ssh_passphrase: string | null;
|
|
31
|
+
https_username: string | null;
|
|
32
|
+
https_token: string | null;
|
|
33
|
+
integration_account_id: string | null;
|
|
34
|
+
hosts: string;
|
|
35
|
+
is_default: number;
|
|
36
|
+
source: GitIdentitySource;
|
|
37
|
+
created_at: string;
|
|
38
|
+
updated_at: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface GitIdentityBindingRow {
|
|
42
|
+
project_id: string;
|
|
43
|
+
user_id: string;
|
|
44
|
+
identity_id: string;
|
|
45
|
+
created_at: string;
|
|
46
|
+
updated_at: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Create/update payload. Omitted secret fields keep their stored value. */
|
|
50
|
+
export interface GitIdentityWrite {
|
|
51
|
+
label: string;
|
|
52
|
+
name: string;
|
|
53
|
+
email: string;
|
|
54
|
+
authMethod: GitIdentityAuthMethod;
|
|
55
|
+
hosts: string[];
|
|
56
|
+
sshPrivateKey?: string | null;
|
|
57
|
+
sshPublicKey?: string | null;
|
|
58
|
+
sshPassphrase?: string | null;
|
|
59
|
+
httpsUsername?: string | null;
|
|
60
|
+
httpsToken?: string | null;
|
|
61
|
+
integrationAccountId?: string | null;
|
|
62
|
+
/** Only honoured on create — `update` never moves a row between sources. */
|
|
63
|
+
source?: GitIdentitySource;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Parse the stored `hosts` JSON into a lowercased list.
|
|
68
|
+
*
|
|
69
|
+
* Tolerant on read: a malformed blob yields no host claim rather than throwing,
|
|
70
|
+
* because the identity is still perfectly usable for attribution and failing
|
|
71
|
+
* the whole read would take the user's commit identity with it.
|
|
72
|
+
*/
|
|
73
|
+
export function parseHosts(raw: string): string[] {
|
|
74
|
+
try {
|
|
75
|
+
const parsed = JSON.parse(raw);
|
|
76
|
+
if (!Array.isArray(parsed)) return [];
|
|
77
|
+
return parsed
|
|
78
|
+
.filter((h): h is string => typeof h === 'string')
|
|
79
|
+
.map((h) => h.trim().toLowerCase())
|
|
80
|
+
.filter(Boolean);
|
|
81
|
+
} catch {
|
|
82
|
+
return [];
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function serializeHosts(hosts: string[]): string {
|
|
87
|
+
const normalized = hosts.map((h) => h.trim().toLowerCase()).filter(Boolean);
|
|
88
|
+
return JSON.stringify([...new Set(normalized)]);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export const gitIdentityQueries = {
|
|
92
|
+
getById(id: string): GitIdentityRow | null {
|
|
93
|
+
const db = getDatabase();
|
|
94
|
+
const row = db.prepare(`SELECT * FROM ${TABLE} WHERE id = ?`).get(id) as
|
|
95
|
+
| GitIdentityRow
|
|
96
|
+
| undefined;
|
|
97
|
+
return row ? openRow(TABLE, row) : null;
|
|
98
|
+
},
|
|
99
|
+
|
|
100
|
+
listByUser(userId: string): GitIdentityRow[] {
|
|
101
|
+
const db = getDatabase();
|
|
102
|
+
const rows = db
|
|
103
|
+
.prepare(`SELECT * FROM ${TABLE} WHERE owner_user_id = ? ORDER BY is_default DESC, label`)
|
|
104
|
+
.all(userId) as GitIdentityRow[];
|
|
105
|
+
return openRows(TABLE, rows);
|
|
106
|
+
},
|
|
107
|
+
|
|
108
|
+
/** The row mirrored from the machine's global git config, if there is one. */
|
|
109
|
+
getLocalMachine(userId: string): GitIdentityRow | null {
|
|
110
|
+
const db = getDatabase();
|
|
111
|
+
const row = db
|
|
112
|
+
.prepare(`SELECT * FROM ${TABLE} WHERE owner_user_id = ? AND source = 'local-machine'`)
|
|
113
|
+
.get(userId) as GitIdentityRow | undefined;
|
|
114
|
+
return row ? openRow(TABLE, row) : null;
|
|
115
|
+
},
|
|
116
|
+
|
|
117
|
+
getDefaultForUser(userId: string): GitIdentityRow | null {
|
|
118
|
+
const db = getDatabase();
|
|
119
|
+
const row = db
|
|
120
|
+
.prepare(`SELECT * FROM ${TABLE} WHERE owner_user_id = ? AND is_default = 1`)
|
|
121
|
+
.get(userId) as GitIdentityRow | undefined;
|
|
122
|
+
return row ? openRow(TABLE, row) : null;
|
|
123
|
+
},
|
|
124
|
+
|
|
125
|
+
create(id: string, userId: string, input: GitIdentityWrite): GitIdentityRow {
|
|
126
|
+
const db = getDatabase();
|
|
127
|
+
const now = new Date().toISOString();
|
|
128
|
+
db.prepare(
|
|
129
|
+
`
|
|
130
|
+
INSERT INTO ${TABLE} (
|
|
131
|
+
id, owner_user_id, label, name, email, auth_method,
|
|
132
|
+
ssh_private_key, ssh_public_key, ssh_passphrase,
|
|
133
|
+
https_username, https_token, integration_account_id,
|
|
134
|
+
hosts, is_default, source, created_at, updated_at
|
|
135
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, ?, ?, ?)
|
|
136
|
+
`
|
|
137
|
+
).run(
|
|
138
|
+
id,
|
|
139
|
+
userId,
|
|
140
|
+
input.label,
|
|
141
|
+
input.name,
|
|
142
|
+
input.email,
|
|
143
|
+
input.authMethod,
|
|
144
|
+
sealFor(TABLE, 'ssh_private_key', input.sshPrivateKey ?? null),
|
|
145
|
+
input.sshPublicKey ?? null,
|
|
146
|
+
sealFor(TABLE, 'ssh_passphrase', input.sshPassphrase ?? null),
|
|
147
|
+
input.httpsUsername ?? null,
|
|
148
|
+
sealFor(TABLE, 'https_token', input.httpsToken ?? null),
|
|
149
|
+
input.integrationAccountId ?? null,
|
|
150
|
+
serializeHosts(input.hosts),
|
|
151
|
+
input.source ?? 'manual',
|
|
152
|
+
now,
|
|
153
|
+
now
|
|
154
|
+
);
|
|
155
|
+
return this.getById(id)!;
|
|
156
|
+
},
|
|
157
|
+
|
|
158
|
+
update(id: string, input: GitIdentityWrite): GitIdentityRow | null {
|
|
159
|
+
const db = getDatabase();
|
|
160
|
+
const existing = db.prepare(`SELECT id FROM ${TABLE} WHERE id = ?`).get(id);
|
|
161
|
+
if (!existing) return null;
|
|
162
|
+
|
|
163
|
+
// Secrets are appended conditionally so an omitted field never becomes a
|
|
164
|
+
// stored NULL. Column and parameter lists are built together to keep them
|
|
165
|
+
// impossible to misalign.
|
|
166
|
+
const sets: string[] = [
|
|
167
|
+
'label = ?',
|
|
168
|
+
'name = ?',
|
|
169
|
+
'email = ?',
|
|
170
|
+
'auth_method = ?',
|
|
171
|
+
'hosts = ?',
|
|
172
|
+
'ssh_public_key = ?',
|
|
173
|
+
'https_username = ?',
|
|
174
|
+
'integration_account_id = ?',
|
|
175
|
+
'updated_at = ?'
|
|
176
|
+
];
|
|
177
|
+
const params: unknown[] = [
|
|
178
|
+
input.label,
|
|
179
|
+
input.name,
|
|
180
|
+
input.email,
|
|
181
|
+
input.authMethod,
|
|
182
|
+
serializeHosts(input.hosts),
|
|
183
|
+
input.sshPublicKey ?? null,
|
|
184
|
+
input.httpsUsername ?? null,
|
|
185
|
+
input.integrationAccountId ?? null,
|
|
186
|
+
new Date().toISOString()
|
|
187
|
+
];
|
|
188
|
+
|
|
189
|
+
if (input.sshPrivateKey !== undefined) {
|
|
190
|
+
sets.push('ssh_private_key = ?');
|
|
191
|
+
params.push(sealFor(TABLE, 'ssh_private_key', input.sshPrivateKey));
|
|
192
|
+
}
|
|
193
|
+
if (input.sshPassphrase !== undefined) {
|
|
194
|
+
sets.push('ssh_passphrase = ?');
|
|
195
|
+
params.push(sealFor(TABLE, 'ssh_passphrase', input.sshPassphrase));
|
|
196
|
+
}
|
|
197
|
+
if (input.httpsToken !== undefined) {
|
|
198
|
+
sets.push('https_token = ?');
|
|
199
|
+
params.push(sealFor(TABLE, 'https_token', input.httpsToken));
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
params.push(id);
|
|
203
|
+
db.prepare(`UPDATE ${TABLE} SET ${sets.join(', ')} WHERE id = ?`).run(...(params as never[]));
|
|
204
|
+
return this.getById(id);
|
|
205
|
+
},
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Make one identity the user's default, clearing any previous one.
|
|
209
|
+
*
|
|
210
|
+
* Both statements run in a transaction because the partial unique index
|
|
211
|
+
* rejects a moment where two rows claim the default — clearing first and
|
|
212
|
+
* setting second is not optional, it is what makes the write legal.
|
|
213
|
+
*/
|
|
214
|
+
setDefault(userId: string, id: string): void {
|
|
215
|
+
const db = getDatabase();
|
|
216
|
+
const swap = () => {
|
|
217
|
+
db.prepare(`UPDATE ${TABLE} SET is_default = 0 WHERE owner_user_id = ? AND is_default = 1`).run(
|
|
218
|
+
userId
|
|
219
|
+
);
|
|
220
|
+
db.prepare(`UPDATE ${TABLE} SET is_default = 1, updated_at = ? WHERE id = ? AND owner_user_id = ?`).run(
|
|
221
|
+
new Date().toISOString(),
|
|
222
|
+
id,
|
|
223
|
+
userId
|
|
224
|
+
);
|
|
225
|
+
};
|
|
226
|
+
// Not every driver exposes transactions (see `DatabaseConnection`). Running
|
|
227
|
+
// it unbatched is a worse guarantee, not a wrong result: the clear still
|
|
228
|
+
// precedes the set, which is what the partial unique index requires.
|
|
229
|
+
if (db.transaction) db.transaction(swap)();
|
|
230
|
+
else swap();
|
|
231
|
+
},
|
|
232
|
+
|
|
233
|
+
remove(id: string): boolean {
|
|
234
|
+
const db = getDatabase();
|
|
235
|
+
const result = db.prepare(`DELETE FROM ${TABLE} WHERE id = ?`).run(id) as { changes: number };
|
|
236
|
+
return result.changes > 0;
|
|
237
|
+
},
|
|
238
|
+
|
|
239
|
+
/** True when the label is already taken by another of this user's identities. */
|
|
240
|
+
labelTaken(userId: string, label: string, exceptId?: string): boolean {
|
|
241
|
+
const db = getDatabase();
|
|
242
|
+
const row = db
|
|
243
|
+
.prepare(
|
|
244
|
+
`SELECT id FROM ${TABLE} WHERE owner_user_id = ? AND label = ? AND id IS NOT ?`
|
|
245
|
+
)
|
|
246
|
+
.get(userId, label, exceptId ?? null);
|
|
247
|
+
return !!row;
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
export const gitIdentityBindingQueries = {
|
|
252
|
+
get(projectId: string, userId: string): GitIdentityBindingRow | null {
|
|
253
|
+
const db = getDatabase();
|
|
254
|
+
const row = db
|
|
255
|
+
.prepare('SELECT * FROM git_identity_bindings WHERE project_id = ? AND user_id = ?')
|
|
256
|
+
.get(projectId, userId) as GitIdentityBindingRow | undefined;
|
|
257
|
+
return row ?? null;
|
|
258
|
+
},
|
|
259
|
+
|
|
260
|
+
set(projectId: string, userId: string, identityId: string): void {
|
|
261
|
+
const db = getDatabase();
|
|
262
|
+
const now = new Date().toISOString();
|
|
263
|
+
db.prepare(
|
|
264
|
+
`
|
|
265
|
+
INSERT INTO git_identity_bindings (project_id, user_id, identity_id, created_at, updated_at)
|
|
266
|
+
VALUES (?, ?, ?, ?, ?)
|
|
267
|
+
ON CONFLICT(project_id, user_id) DO UPDATE SET
|
|
268
|
+
identity_id = excluded.identity_id,
|
|
269
|
+
updated_at = excluded.updated_at
|
|
270
|
+
`
|
|
271
|
+
).run(projectId, userId, identityId, now, now);
|
|
272
|
+
},
|
|
273
|
+
|
|
274
|
+
clear(projectId: string, userId: string): void {
|
|
275
|
+
const db = getDatabase();
|
|
276
|
+
db.prepare('DELETE FROM git_identity_bindings WHERE project_id = ? AND user_id = ?').run(
|
|
277
|
+
projectId,
|
|
278
|
+
userId
|
|
279
|
+
);
|
|
280
|
+
},
|
|
281
|
+
|
|
282
|
+
/** Projects this identity is bound to — what a delete confirmation shows. */
|
|
283
|
+
countForIdentity(identityId: string): number {
|
|
284
|
+
const db = getDatabase();
|
|
285
|
+
const row = db
|
|
286
|
+
.prepare('SELECT COUNT(*) as count FROM git_identity_bindings WHERE identity_id = ?')
|
|
287
|
+
.get(identityId) as { count: number };
|
|
288
|
+
return row.count;
|
|
289
|
+
}
|
|
290
|
+
};
|
|
@@ -16,12 +16,12 @@ export { sshKnownHostQueries } from './ssh-known-host-queries';
|
|
|
16
16
|
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
|
+
export { fileShareQueries } from './file-share-queries';
|
|
20
|
+
export type { FileShareRow, FileShareListRow } from './file-share-queries';
|
|
19
21
|
export { mcpServerQueries } from './mcp-server-queries';
|
|
20
22
|
export type { McpServerRow, McpServerInput, McpTransport, McpSource, McpConfigField, McpToolOverride, McpToolOverrides } from './mcp-server-queries';
|
|
21
|
-
export { skillQueries } from './skill-queries';
|
|
22
|
-
export type { SkillRow, SkillInput, SkillSource } from './skill-queries';
|
|
23
|
-
export { commandQueries } from './command-queries';
|
|
24
|
-
export type { CommandRow, CommandInput, CommandSource } from './command-queries';
|
|
23
|
+
export { skillQueries, parseTriggers, stringifyTriggers, parseUses, stringifyUses, SKILL_TRIGGERS } from './skill-queries';
|
|
24
|
+
export type { SkillRow, SkillInput, SkillSource, SkillTrigger } from './skill-queries';
|
|
25
25
|
export { subagentQueries } from './subagent-queries';
|
|
26
26
|
export type { SubagentRow, SubagentInput, SubagentSource } from './subagent-queries';
|
|
27
27
|
export { instructionQueries } from './instruction-queries';
|
|
@@ -46,4 +46,8 @@ export {
|
|
|
46
46
|
worktreeBranchQueries,
|
|
47
47
|
parseWorktreeBranchConfig
|
|
48
48
|
} from './worktree-branch-queries';
|
|
49
|
+
export { gitIdentityQueries, gitIdentityBindingQueries, parseHosts } from './git-identity-queries';
|
|
50
|
+
export type { GitIdentityRow, GitIdentityBindingRow, GitIdentityWrite } from './git-identity-queries';
|
|
51
|
+
export { pushSubscriptionQueries } from './push-subscription-queries';
|
|
52
|
+
export type { PushSubscription, PushSubscriptionInput } from './push-subscription-queries';
|
|
49
53
|
export type { WorktreeBranchBindingRow, WorktreeBranchRow } from './worktree-branch-queries';
|
|
@@ -14,10 +14,12 @@
|
|
|
14
14
|
import { getDatabase } from '../index';
|
|
15
15
|
|
|
16
16
|
/** Artifact kinds a profile can bundle. Permissions are handled separately
|
|
17
|
-
* (they are a per-engine allow/deny overlay, not a slug-referenced artifact).
|
|
18
|
-
|
|
17
|
+
* (they are a per-engine allow/deny overlay, not a slug-referenced artifact).
|
|
18
|
+
* `'command'` is gone since migration 079 folded Commands into Skills — the
|
|
19
|
+
* migration re-typed existing `command` rows to `skill` under their new slug. */
|
|
20
|
+
export type ProfileItemType = 'skill' | 'subagent' | 'mcp';
|
|
19
21
|
|
|
20
|
-
export const PROFILE_ITEM_TYPES: ProfileItemType[] = ['skill', '
|
|
22
|
+
export const PROFILE_ITEM_TYPES: ProfileItemType[] = ['skill', 'subagent', 'mcp'];
|
|
21
23
|
|
|
22
24
|
export interface ProfileRow {
|
|
23
25
|
id: number;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for the Web Push subscription store.
|
|
3
|
+
*
|
|
4
|
+
* Two invariants carry the feature. One row per device endpoint, so a phone
|
|
5
|
+
* that re-subscribes on every app open does not accumulate duplicates and
|
|
6
|
+
* receive N copies of every notification. And a purge that covers the whole
|
|
7
|
+
* user, because `pushNotifications` is a single per-user setting synced
|
|
8
|
+
* across devices — switching it off on a laptop has to silence the phone.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { describe, it, expect, beforeAll, afterAll, beforeEach } from 'bun:test';
|
|
12
|
+
import { randomUUID } from 'node:crypto';
|
|
13
|
+
|
|
14
|
+
import { initializeDatabase, closeDatabase } from '../index';
|
|
15
|
+
import { pushSubscriptionQueries } from './push-subscription-queries';
|
|
16
|
+
|
|
17
|
+
const userA = `user-a-${randomUUID()}`;
|
|
18
|
+
const userB = `user-b-${randomUUID()}`;
|
|
19
|
+
|
|
20
|
+
function subscribe(userId: string, suffix: string) {
|
|
21
|
+
return pushSubscriptionQueries.upsert({
|
|
22
|
+
userId,
|
|
23
|
+
endpoint: `https://push.example.com/${suffix}`,
|
|
24
|
+
p256dh: 'p256dh-'.padEnd(20, 'x'),
|
|
25
|
+
auth: 'auth-'.padEnd(16, 'x'),
|
|
26
|
+
userAgent: 'test-agent'
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
beforeAll(async () => {
|
|
31
|
+
await initializeDatabase();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
beforeEach(() => {
|
|
35
|
+
pushSubscriptionQueries.deleteAllByUser(userA);
|
|
36
|
+
pushSubscriptionQueries.deleteAllByUser(userB);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
afterAll(() => {
|
|
40
|
+
pushSubscriptionQueries.deleteAllByUser(userA);
|
|
41
|
+
pushSubscriptionQueries.deleteAllByUser(userB);
|
|
42
|
+
closeDatabase();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe('pushSubscriptionQueries', () => {
|
|
46
|
+
it('keeps one row per endpoint when the same device re-subscribes', () => {
|
|
47
|
+
const first = subscribe(userA, 'device-1');
|
|
48
|
+
const second = pushSubscriptionQueries.upsert({
|
|
49
|
+
userId: userA,
|
|
50
|
+
endpoint: 'https://push.example.com/device-1',
|
|
51
|
+
p256dh: 'rotated-p256dh'.padEnd(20, 'x'),
|
|
52
|
+
auth: 'rotated-auth'.padEnd(16, 'x')
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
expect(second.id).toBe(first.id);
|
|
56
|
+
expect(second.p256dh).toBe('rotated-p256dh'.padEnd(20, 'x'));
|
|
57
|
+
expect(pushSubscriptionQueries.listByUser(userA)).toHaveLength(1);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('deletes every device of one user and leaves other users untouched', () => {
|
|
61
|
+
subscribe(userA, 'phone');
|
|
62
|
+
subscribe(userA, 'tablet');
|
|
63
|
+
subscribe(userB, 'other-phone');
|
|
64
|
+
|
|
65
|
+
expect(pushSubscriptionQueries.deleteAllByUser(userA)).toBe(2);
|
|
66
|
+
expect(pushSubscriptionQueries.listByUser(userA)).toHaveLength(0);
|
|
67
|
+
expect(pushSubscriptionQueries.listByUser(userB)).toHaveLength(1);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('scopes a single-endpoint delete to its owner', () => {
|
|
71
|
+
subscribe(userA, 'shared-looking-endpoint');
|
|
72
|
+
|
|
73
|
+
expect(
|
|
74
|
+
pushSubscriptionQueries.deleteByEndpoint(
|
|
75
|
+
userB,
|
|
76
|
+
'https://push.example.com/shared-looking-endpoint'
|
|
77
|
+
)
|
|
78
|
+
).toBe(false);
|
|
79
|
+
expect(pushSubscriptionQueries.listByUser(userA)).toHaveLength(1);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('prunes a stale endpoint regardless of owner', () => {
|
|
83
|
+
subscribe(userA, 'expired');
|
|
84
|
+
|
|
85
|
+
expect(
|
|
86
|
+
pushSubscriptionQueries.deleteStaleByEndpoint('https://push.example.com/expired')
|
|
87
|
+
).toBe(true);
|
|
88
|
+
expect(pushSubscriptionQueries.listByUser(userA)).toHaveLength(0);
|
|
89
|
+
});
|
|
90
|
+
});
|