@myrialabs/clopen 0.4.38 → 0.4.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/backend/auth/permissions.ts +25 -0
- package/backend/chat/stream-manager.ts +1 -1
- package/backend/database/crypto/secret-columns.ts +5 -1
- package/backend/database/migrations/075_create_deploy_bindings.ts +54 -0
- package/backend/database/migrations/076_remove_memory_code_graph.ts +229 -0
- package/backend/database/migrations/077_create_integration_db_links.ts +150 -0
- package/backend/database/migrations/index.ts +21 -0
- package/backend/database/queries/db-client-connection-queries.ts +19 -0
- package/backend/database/queries/deploy-queries.ts +124 -0
- package/backend/database/queries/graph-queries.ts +291 -247
- package/backend/database/queries/index.ts +4 -0
- package/backend/database/queries/integration-db-link-queries.ts +168 -0
- package/backend/database/queries/integration-queries.ts +34 -6
- package/backend/db-client/integrations/index.ts +37 -0
- package/backend/db-client/integrations/links.ts +533 -0
- package/backend/db-client/integrations/projector.test.ts +280 -0
- package/backend/db-client/integrations/projector.ts +256 -0
- package/backend/db-client/integrations/supabase-service.ts +266 -0
- package/backend/db-client/providers/registry.ts +27 -0
- package/backend/db-client/providers/supabase/adapter.ts +500 -0
- package/backend/db-client/providers/supabase/api-types.ts +92 -0
- package/backend/db-client/providers/supabase/apply-migration.ts +104 -0
- package/backend/db-client/providers/supabase/client.ts +259 -0
- package/backend/db-client/providers/supabase/features.ts +502 -0
- package/backend/db-client/providers/supabase/local.test.ts +78 -0
- package/backend/db-client/providers/supabase/local.ts +137 -0
- package/backend/db-client/providers/types.ts +137 -0
- package/backend/deployments/bindings.test.ts +43 -0
- package/backend/deployments/bindings.ts +216 -0
- package/backend/deployments/index.ts +53 -0
- package/backend/deployments/log-streams.ts +214 -0
- package/backend/deployments/prompts.ts +70 -0
- package/backend/deployments/providers/vercel/adapter.ts +757 -0
- package/backend/deployments/providers/vercel/build-logs.test.ts +80 -0
- package/backend/deployments/providers/vercel/build-logs.ts +211 -0
- package/backend/deployments/providers/vercel/client.ts +203 -0
- package/backend/deployments/providers/vercel/list.test.ts +624 -0
- package/backend/deployments/providers/vercel/normalise.test.ts +115 -0
- package/backend/deployments/providers/vercel/normalise.ts +113 -0
- package/backend/deployments/providers/vercel/types.ts +104 -0
- package/backend/deployments/registry.ts +27 -0
- package/backend/deployments/service.ts +458 -0
- package/backend/deployments/types.ts +278 -0
- package/backend/index.ts +4 -0
- package/backend/integrations/projections/index.ts +0 -0
- package/backend/integrations/projections/mcp-projector.ts +7 -3
- package/backend/integrations/projections/types.ts +21 -9
- package/backend/integrations/registry/index.ts +5 -1
- package/backend/integrations/registry/providers/supabase.ts +61 -0
- package/backend/integrations/registry/providers/vercel.ts +46 -0
- package/backend/mcp/internal/servers/memory-graph/description.ts +3 -3
- package/backend/mcp/internal/servers/memory-graph/runner.ts +4 -9
- package/backend/mcp/internal/servers/memory-graph/schema.ts +0 -4
- package/backend/memory/README.md +57 -34
- package/backend/memory/compose.test.ts +3 -3
- package/backend/memory/compose.ts +6 -9
- package/backend/memory/config.ts +0 -5
- package/backend/memory/consolidate.ts +1 -2
- package/backend/memory/context.test.ts +8 -54
- package/backend/memory/context.ts +19 -25
- package/backend/memory/extract/episodic.ts +10 -12
- package/backend/memory/extract/index.ts +23 -52
- package/backend/memory/extract/scheduler.ts +3 -6
- package/backend/memory/index.ts +6 -5
- package/backend/memory/invalidate.ts +36 -48
- package/backend/memory/layout.ts +319 -130
- package/backend/memory/retention.ts +12 -42
- package/backend/memory/retrieval.eval.test.ts +2 -2
- package/backend/memory/retrieval.test.ts +228 -183
- package/backend/memory/retrieval.ts +22 -21
- package/backend/memory/revise.test.ts +62 -116
- package/backend/memory/revise.ts +0 -1
- package/backend/memory/view.ts +8 -5
- package/backend/snapshot/helpers.ts +35 -41
- package/backend/snapshot/snapshot-service.ts +90 -0
- package/backend/snapshot/turn-changes.test.ts +163 -0
- package/backend/snapshot/turn-changes.ts +131 -0
- package/backend/ws/db-client/accounts.ts +225 -0
- package/backend/ws/db-client/connections.ts +34 -3
- package/backend/ws/db-client/context.ts +37 -0
- package/backend/ws/db-client/index.ts +20 -1
- package/backend/ws/db-client/supabase.ts +188 -0
- package/backend/ws/deployments/actions.ts +360 -0
- package/backend/ws/deployments/context.ts +43 -0
- package/backend/ws/deployments/crud.ts +152 -0
- package/backend/ws/deployments/index.ts +15 -0
- package/backend/ws/deployments/schemas.ts +183 -0
- package/backend/ws/index.ts +6 -2
- package/backend/ws/memory/crud.ts +4 -16
- package/backend/ws/snapshot/changes.ts +279 -0
- package/backend/ws/snapshot/index.ts +4 -3
- package/dist/assets/{index-CyH7fSbR.js → index-BrF6nqld.js} +1 -1
- package/dist/assets/{index-DSHIANSy.js → index-C8Gi-b6U.js} +1 -1
- package/dist/assets/main-Bd3gb79F.css +1 -0
- package/dist/assets/main-Bo1hD7mt.js +1191 -0
- package/dist/index.html +2 -2
- package/package.json +1 -1
- package/shared/constants/tool-icons.ts +9 -0
- package/shared/types/db-client/connection.ts +6 -0
- package/shared/types/db-client/index.ts +2 -0
- package/shared/types/db-client/integrations.ts +174 -0
- package/shared/types/db-client/supabase.ts +131 -0
- package/shared/types/deployments.ts +382 -0
- package/shared/types/memory.ts +34 -51
- package/shared/types/ui/components.ts +1 -1
- package/shared/utils/diff-calculator.test.ts +89 -0
- package/shared/utils/diff-calculator.ts +30 -65
- package/shared/utils/logger.ts +1 -0
- package/backend/memory/extract/languages.ts +0 -176
- package/backend/memory/extract/structural.test.ts +0 -215
- package/backend/memory/extract/structural.ts +0 -364
- package/backend/ws/snapshot/content.ts +0 -85
- package/dist/assets/main-D2IOjftb.css +0 -1
- package/dist/assets/main-DM-tHKbW.js +0 -1152
|
@@ -157,6 +157,31 @@ export const ADMIN_ONLY_ROUTES = new Set([
|
|
|
157
157
|
'integrations:disconnect',
|
|
158
158
|
'integrations:health',
|
|
159
159
|
'integrations:secrets-health',
|
|
160
|
+
// Account-backed database connections. Linking reads a credential belonging
|
|
161
|
+
// to the install rather than to the caller, and projects a connection every
|
|
162
|
+
// admin sees — the same reason the rest of the integrations surface is
|
|
163
|
+
// admin-only. The ordinary db-client routes stay open: a member still
|
|
164
|
+
// manages their own hand-typed connections exactly as before.
|
|
165
|
+
'db-client:providers',
|
|
166
|
+
'db-client:remote-databases',
|
|
167
|
+
'db-client:create-options',
|
|
168
|
+
// Provisions real infrastructure against the account's quota, which is as
|
|
169
|
+
// outward-facing as anything on this surface gets. Creating an organisation
|
|
170
|
+
// creates a BILLING entity, which is more so.
|
|
171
|
+
'db-client:create-group',
|
|
172
|
+
'db-client:create-database',
|
|
173
|
+
// Renames a database everyone at the provider sees.
|
|
174
|
+
'db-client:rename-database',
|
|
175
|
+
// Destroys a database and everything in it.
|
|
176
|
+
'db-client:delete-database',
|
|
177
|
+
'db-client:link',
|
|
178
|
+
'db-client:update-link',
|
|
179
|
+
'db-client:unlink',
|
|
180
|
+
// Applying a migration changes a schema everyone shares, and writing types
|
|
181
|
+
// writes a file into the repository. The Supabase READS are not listed, so
|
|
182
|
+
// anyone who can use the connection can look.
|
|
183
|
+
'db-client:supabase-apply-migration',
|
|
184
|
+
'db-client:supabase-write-types',
|
|
160
185
|
// Memory Graph — the graph is instance-global and is injected into every
|
|
161
186
|
// future turn on every engine, so editing it changes what every agent is told.
|
|
162
187
|
// Mutations only: the read surface (memory:graph / :node / :search / :stats /
|
|
@@ -27,7 +27,11 @@ export const SECRET_COLUMNS: Record<string, readonly string[]> = {
|
|
|
27
27
|
db_client_connections: ['password', 'ssh_password', 'ssh_private_key', 'ssh_passphrase'],
|
|
28
28
|
ssh_connections: ['password', 'private_key', 'passphrase'],
|
|
29
29
|
engine_accounts: ['credential'],
|
|
30
|
-
integration_accounts: ['credentials']
|
|
30
|
+
integration_accounts: ['credentials'],
|
|
31
|
+
// The secret a linked remote database needs, which is NOT always the same as
|
|
32
|
+
// the account's credential — a Supabase Management API token cannot read
|
|
33
|
+
// back the Postgres password, so the password lives here and nowhere else.
|
|
34
|
+
integration_db_links: ['secrets']
|
|
31
35
|
} as const;
|
|
32
36
|
|
|
33
37
|
/** Column names of one table, or an empty list when the table holds no secrets. */
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { DatabaseConnection } from '$shared/types/database/connection';
|
|
2
|
+
import { debug } from '$shared/utils/logger';
|
|
3
|
+
|
|
4
|
+
export const description = 'Create deploy_bindings for the Deployments surface';
|
|
5
|
+
|
|
6
|
+
export const up = (db: DatabaseConnection): void => {
|
|
7
|
+
debug.log('migration', 'Creating deploy_bindings table...');
|
|
8
|
+
|
|
9
|
+
// Which remote project a Clopen project deploys to, through one account.
|
|
10
|
+
//
|
|
11
|
+
// Belongs to the SURFACE, not to the account layer, for the same reason
|
|
12
|
+
// `work_bindings` does: an account is one Vercel token, while "which Vercel
|
|
13
|
+
// project is this" is per project, and two projects sharing one token is the
|
|
14
|
+
// normal case.
|
|
15
|
+
//
|
|
16
|
+
// This is a sibling of `work_bindings` rather than a generalisation of it.
|
|
17
|
+
// The columns differ where it matters: `display_name` exists because a
|
|
18
|
+
// deployment locator is an opaque `prj_8Qc…` that means nothing to a reader,
|
|
19
|
+
// unlike an `owner/repo` that describes itself, and `team_id` exists because
|
|
20
|
+
// one token reaches several teams and the team is a property of which
|
|
21
|
+
// project you picked — not of the credential.
|
|
22
|
+
//
|
|
23
|
+
// Nothing about a deployment itself is stored. The provider is the truthful
|
|
24
|
+
// answer for state, logs and URLs, all three go stale within seconds, and
|
|
25
|
+
// there is no local artifact (no worktree, no branch) that would survive the
|
|
26
|
+
// remote record — so unlike the Issues surface there is not even a link
|
|
27
|
+
// table here.
|
|
28
|
+
db.exec(`
|
|
29
|
+
CREATE TABLE IF NOT EXISTS deploy_bindings (
|
|
30
|
+
project_id TEXT NOT NULL REFERENCES projects(id) ON DELETE CASCADE,
|
|
31
|
+
account_id TEXT NOT NULL REFERENCES integration_accounts(id) ON DELETE CASCADE,
|
|
32
|
+
locator TEXT NOT NULL,
|
|
33
|
+
display_name TEXT NOT NULL DEFAULT '',
|
|
34
|
+
team_id TEXT,
|
|
35
|
+
detected INTEGER NOT NULL DEFAULT 0,
|
|
36
|
+
config_json TEXT NOT NULL DEFAULT '{}',
|
|
37
|
+
created_at TEXT NOT NULL,
|
|
38
|
+
updated_at TEXT NOT NULL,
|
|
39
|
+
PRIMARY KEY (project_id, account_id)
|
|
40
|
+
)
|
|
41
|
+
`);
|
|
42
|
+
|
|
43
|
+
db.exec(`
|
|
44
|
+
CREATE INDEX IF NOT EXISTS idx_deploy_bindings_account
|
|
45
|
+
ON deploy_bindings(account_id)
|
|
46
|
+
`);
|
|
47
|
+
|
|
48
|
+
debug.log('migration', 'Deploy bindings table created');
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export const down = (db: DatabaseConnection): void => {
|
|
52
|
+
debug.log('migration', 'Dropping deploy_bindings table...');
|
|
53
|
+
db.exec('DROP TABLE IF EXISTS deploy_bindings');
|
|
54
|
+
};
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import type { DatabaseConnection } from '$shared/types/database/connection';
|
|
2
|
+
import { debug } from '$shared/utils/logger';
|
|
3
|
+
|
|
4
|
+
export const description =
|
|
5
|
+
'Remove the structural half of the Memory Graph and keep a memory\'s file paths as an attribute';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The code half of the graph is removed, and the paths it existed to anchor
|
|
9
|
+
* become an attribute of the memory itself.
|
|
10
|
+
*
|
|
11
|
+
* Migration 066 stored the codebase as nodes — a node per file, per directory
|
|
12
|
+
* and up to twenty-five per file's symbols — on the argument that a question
|
|
13
|
+
* about code could then travel to the decisions made around it. Measured on a
|
|
14
|
+
* real store, that half was 81% of the nodes (9,053 of 11,159) and 88% of the
|
|
15
|
+
* edges, and it was paying for almost none of what it cost:
|
|
16
|
+
*
|
|
17
|
+
* - IT NEVER REACHED THE AGENT. `context.ts` drops structural hits before
|
|
18
|
+
* building the injected block, deliberately: the agent can read the
|
|
19
|
+
* repository, so spending recall budget to tell it a file exists is worse
|
|
20
|
+
* than saying nothing.
|
|
21
|
+
* - IT CROWDED OUT THE MEMORIES. Structural nodes carry no vector (they are
|
|
22
|
+
* names and paths; embedding them produces a bag of fragments), so they
|
|
23
|
+
* competed only in BM25 — where they won, because there were four times as
|
|
24
|
+
* many of them and they match exactly whenever a turn mentions a path.
|
|
25
|
+
* `RETRIEVAL_DEPTH` had been raised from 18 to 60 purely to leave room for
|
|
26
|
+
* the episodic hits underneath them.
|
|
27
|
+
* - MOST OF IT WAS UNREFERENCED. Of 1,920 `about` edges, 1,903 pointed at a
|
|
28
|
+
* file and 17 at a module. NONE pointed at a symbol — so 4,458 symbol nodes
|
|
29
|
+
* and their 4,458 `defines` edges were never once the reason a memory was
|
|
30
|
+
* found.
|
|
31
|
+
*
|
|
32
|
+
* What the half genuinely did was answer one question: WHICH FILES DOES THIS
|
|
33
|
+
* MEMORY CLAIM SOMETHING ABOUT. Structural invalidation needs it (age the
|
|
34
|
+
* memories standing on code that just changed) and so does anchor seeding (a
|
|
35
|
+
* turn that says only "continue" still reaches the memories attached to the file
|
|
36
|
+
* in front of it). That question needs a path, not a node.
|
|
37
|
+
*
|
|
38
|
+
* So paths are demoted from nodes to an attribute, exactly as migration 066
|
|
39
|
+
* already did for entities after canonical entity nodes became half the graph.
|
|
40
|
+
* The lookups get cheaper rather than poorer: invalidation and anchoring are now
|
|
41
|
+
* one index seek into `graph_node_paths` instead of a path → file-node → `about`
|
|
42
|
+
* edge hop, and nothing has to be kept in sync with a parallel node population.
|
|
43
|
+
*
|
|
44
|
+
* `kind` stays on `graph_nodes` as a constant `'episodic'`. It is part of the
|
|
45
|
+
* unique digest index and of the FTS mirror's schema, and rebuilding both across
|
|
46
|
+
* a live memory store to reclaim one constant column would be real risk for no
|
|
47
|
+
* benefit. The application no longer has the concept at all.
|
|
48
|
+
*
|
|
49
|
+
* EVERY STEP HERE IS RE-RUNNABLE, and that is a correctness requirement rather
|
|
50
|
+
* than tidiness. The runner records a migration only after `up` RETURNS, and it
|
|
51
|
+
* wraps nothing in a transaction — so an interrupted run leaves the schema
|
|
52
|
+
* partly changed and the migration still pending. The second run then hits its
|
|
53
|
+
* own output: the backfill reads `graph_nodes.path`, which the first run had
|
|
54
|
+
* already dropped, and the failure is not soft. `initializeDatabase` refuses to
|
|
55
|
+
* start, so the app will not boot again until someone edits the database by
|
|
56
|
+
* hand. Deletes keyed on `kind = 'structural'` are naturally idempotent; the two
|
|
57
|
+
* steps that are not are guarded on whether the old column is still there.
|
|
58
|
+
*
|
|
59
|
+
* There is deliberately NO `VACUUM`. Deleting four fifths of the graph leaves
|
|
60
|
+
* free pages worth reclaiming, but on a real 2.7 GB store the vacuum took around
|
|
61
|
+
* ninety seconds — with the server not yet listening and nothing on screen to
|
|
62
|
+
* explain the wait. A user who gives up and restarts then has two processes
|
|
63
|
+
* racing on one file. The pages are reused as the database grows; reclaiming
|
|
64
|
+
* them is not worth owning that window.
|
|
65
|
+
*/
|
|
66
|
+
/**
|
|
67
|
+
* Whether a table exists, so this migration can run against a database holding
|
|
68
|
+
* only the graph. The memory tests build one from 066 and this file alone, and
|
|
69
|
+
* both `graph_layout` (067) and `settings` are outside that pair.
|
|
70
|
+
*/
|
|
71
|
+
function hasTable(db: DatabaseConnection, name: string): boolean {
|
|
72
|
+
const row = db
|
|
73
|
+
.prepare(`SELECT name FROM sqlite_master WHERE type = 'table' AND name = ?`)
|
|
74
|
+
.get(name) as { name: string } | null;
|
|
75
|
+
return row !== null && row !== undefined;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** Whether a column is still present — the test for "has this already run". */
|
|
79
|
+
function hasColumn(db: DatabaseConnection, table: string, column: string): boolean {
|
|
80
|
+
const rows = db.prepare(`PRAGMA table_info(${table})`).all() as { name: string }[];
|
|
81
|
+
return rows.some(row => row.name === column);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export const up = (db: DatabaseConnection): void => {
|
|
85
|
+
debug.log('migration', 'Removing the structural half of the memory graph...');
|
|
86
|
+
|
|
87
|
+
// ── the paths a memory is about ──────────────────────────────────────────
|
|
88
|
+
// Shaped like `graph_node_entities`: keyed by node, replaced wholesale when
|
|
89
|
+
// extraction re-reads a memory, cascading away with it. `path` is indexed on
|
|
90
|
+
// its own because the hot direction is the reverse one — "these files just
|
|
91
|
+
// changed, which memories claimed something about them".
|
|
92
|
+
db.exec(`
|
|
93
|
+
CREATE TABLE IF NOT EXISTS graph_node_paths (
|
|
94
|
+
node_id TEXT NOT NULL REFERENCES graph_nodes(id) ON DELETE CASCADE,
|
|
95
|
+
path TEXT NOT NULL,
|
|
96
|
+
PRIMARY KEY (node_id, path)
|
|
97
|
+
)
|
|
98
|
+
`);
|
|
99
|
+
db.exec(`CREATE INDEX IF NOT EXISTS idx_graph_node_paths_path ON graph_node_paths (path)`);
|
|
100
|
+
|
|
101
|
+
// Carry the existing attributions over BEFORE anything is deleted: an `about`
|
|
102
|
+
// edge already records precisely this, it is simply pointing at a node instead
|
|
103
|
+
// of naming a string.
|
|
104
|
+
//
|
|
105
|
+
// Skipped when `path` is already gone, which means an earlier run of this
|
|
106
|
+
// migration got at least this far. Reading it unconditionally is what turned an
|
|
107
|
+
// interrupted run into a database that would not open.
|
|
108
|
+
if (hasColumn(db, 'graph_nodes', 'path')) {
|
|
109
|
+
db.exec(`
|
|
110
|
+
INSERT OR IGNORE INTO graph_node_paths (node_id, path)
|
|
111
|
+
SELECT e.src_id, d.path
|
|
112
|
+
FROM graph_edges e
|
|
113
|
+
INNER JOIN graph_nodes d ON d.id = e.dst_id
|
|
114
|
+
WHERE e.rel = 'about' AND d.kind = 'structural' AND d.path IS NOT NULL AND d.path <> ''
|
|
115
|
+
`);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const carried = (
|
|
119
|
+
db.prepare(`SELECT COUNT(*) AS c FROM graph_node_paths`).get() as { c: number }
|
|
120
|
+
).c;
|
|
121
|
+
|
|
122
|
+
// ── remove the code nodes ────────────────────────────────────────────────
|
|
123
|
+
// The lexical mirror goes first and goes through `fts_rowid`, the way every
|
|
124
|
+
// other delete in this feature does: `graph_nodes_fts.node_id` is UNINDEXED,
|
|
125
|
+
// so matching on it is a full scan of a table that only grows.
|
|
126
|
+
db.exec(`
|
|
127
|
+
DELETE FROM graph_nodes_fts
|
|
128
|
+
WHERE rowid IN (
|
|
129
|
+
SELECT fts_rowid FROM graph_nodes WHERE kind = 'structural' AND fts_rowid IS NOT NULL
|
|
130
|
+
)
|
|
131
|
+
`);
|
|
132
|
+
// Then anything the rowid could not reach — a mirror row whose node was hard
|
|
133
|
+
// deleted at some point without its `fts_rowid` being cleared.
|
|
134
|
+
db.exec(`DELETE FROM graph_nodes_fts WHERE kind = 'structural'`);
|
|
135
|
+
|
|
136
|
+
// A memory pointing at a code node as its current belief would be left
|
|
137
|
+
// superseded by something that no longer exists, which hides it from retrieval
|
|
138
|
+
// forever with nothing to explain why. Supersession never crossed the two
|
|
139
|
+
// halves, so this should find nothing — it costs one indexed update to be sure.
|
|
140
|
+
db.exec(`
|
|
141
|
+
UPDATE graph_nodes SET superseded_by = NULL
|
|
142
|
+
WHERE superseded_by IN (SELECT id FROM graph_nodes WHERE kind = 'structural')
|
|
143
|
+
`);
|
|
144
|
+
|
|
145
|
+
// Dependent rows are deleted explicitly rather than left to ON DELETE CASCADE.
|
|
146
|
+
// Foreign keys are a per-connection pragma and this codebase does not rely on
|
|
147
|
+
// them being on anywhere else either (see `graphLayoutQueries.pruneOrphans`).
|
|
148
|
+
db.exec(`
|
|
149
|
+
DELETE FROM graph_edges
|
|
150
|
+
WHERE src_id IN (SELECT id FROM graph_nodes WHERE kind = 'structural')
|
|
151
|
+
OR dst_id IN (SELECT id FROM graph_nodes WHERE kind = 'structural')
|
|
152
|
+
`);
|
|
153
|
+
db.exec(
|
|
154
|
+
`DELETE FROM graph_vectors WHERE node_id IN (SELECT id FROM graph_nodes WHERE kind = 'structural')`
|
|
155
|
+
);
|
|
156
|
+
db.exec(
|
|
157
|
+
`DELETE FROM graph_node_entities WHERE node_id IN (SELECT id FROM graph_nodes WHERE kind = 'structural')`
|
|
158
|
+
);
|
|
159
|
+
// `graph_layout` arrived in a later migration (067) and is derived data that is
|
|
160
|
+
// documented as safe to drop wholesale, so its absence is not an error here.
|
|
161
|
+
if (hasTable(db, 'graph_layout')) {
|
|
162
|
+
db.exec(
|
|
163
|
+
`DELETE FROM graph_layout WHERE node_id IN (SELECT id FROM graph_nodes WHERE kind = 'structural')`
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const removed = (
|
|
168
|
+
db.prepare(`SELECT COUNT(*) AS c FROM graph_nodes WHERE kind = 'structural'`).get() as {
|
|
169
|
+
c: number;
|
|
170
|
+
}
|
|
171
|
+
).c;
|
|
172
|
+
db.exec(`DELETE FROM graph_nodes WHERE kind = 'structural'`);
|
|
173
|
+
|
|
174
|
+
// ── drop what only the code half used ────────────────────────────────────
|
|
175
|
+
// The indexes go before the columns: SQLite refuses to drop a column that any
|
|
176
|
+
// index, view or trigger still mentions.
|
|
177
|
+
db.exec(`DROP INDEX IF EXISTS idx_graph_nodes_path`);
|
|
178
|
+
db.exec(`DROP INDEX IF EXISTS idx_graph_nodes_structural_path`);
|
|
179
|
+
|
|
180
|
+
// `path`, `symbol` and `language` were only ever written for structural nodes,
|
|
181
|
+
// so every surviving row holds three NULLs. Best-effort: DROP COLUMN needs
|
|
182
|
+
// SQLite 3.35, and a column left behind is dead weight rather than a fault.
|
|
183
|
+
for (const column of ['path', 'symbol', 'language']) {
|
|
184
|
+
if (!hasColumn(db, 'graph_nodes', column)) continue;
|
|
185
|
+
try {
|
|
186
|
+
db.exec(`ALTER TABLE graph_nodes DROP COLUMN ${column}`);
|
|
187
|
+
} catch (error) {
|
|
188
|
+
debug.warn('migration', `Could not drop graph_nodes.${column} (harmless)`, error);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// "Map the code" is no longer a thing memory can be asked to do.
|
|
193
|
+
if (hasTable(db, 'settings')) {
|
|
194
|
+
db.exec(`DELETE FROM settings WHERE key = 'memory_record_code'`);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
debug.log(
|
|
198
|
+
'migration',
|
|
199
|
+
`Memory graph: ${removed} code node(s) removed, ${carried} path attribution(s) carried over`
|
|
200
|
+
);
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Down restores the SHAPE, not the data.
|
|
205
|
+
*
|
|
206
|
+
* The code half was derived from the disk in the first place — re-running a turn
|
|
207
|
+
* re-observes whatever it described — so there is nothing here worth trying to
|
|
208
|
+
* reconstruct. The columns and indexes come back so an older build can write to
|
|
209
|
+
* the table again; the path attributions stay, because they are the one thing
|
|
210
|
+
* that was not derivable.
|
|
211
|
+
*/
|
|
212
|
+
export const down = (db: DatabaseConnection): void => {
|
|
213
|
+
debug.log('migration', 'Restoring the structural columns on the memory graph...');
|
|
214
|
+
|
|
215
|
+
for (const column of ['path TEXT', 'symbol TEXT', 'language TEXT']) {
|
|
216
|
+
try {
|
|
217
|
+
db.exec(`ALTER TABLE graph_nodes ADD COLUMN ${column}`);
|
|
218
|
+
} catch (error) {
|
|
219
|
+
debug.warn('migration', `Could not restore graph_nodes.${column} (harmless)`, error);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
db.exec(
|
|
224
|
+
`CREATE INDEX IF NOT EXISTS idx_graph_nodes_path ON graph_nodes (COALESCE(project_id, ''), path)`
|
|
225
|
+
);
|
|
226
|
+
db.exec(
|
|
227
|
+
`CREATE INDEX IF NOT EXISTS idx_graph_nodes_structural_path ON graph_nodes (project_id, kind, path)`
|
|
228
|
+
);
|
|
229
|
+
};
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import type { DatabaseConnection } from '$shared/types/database/connection';
|
|
2
|
+
import { debug } from '$shared/utils/logger';
|
|
3
|
+
|
|
4
|
+
export const description = 'Create integration_db_links and widen integration_projections to many rows per capability';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* One account, many derived rows.
|
|
8
|
+
*
|
|
9
|
+
* `integration_projections` was keyed `(account_id, capability, target_kind)`,
|
|
10
|
+
* which encoded an assumption that only held for the first capability shipped:
|
|
11
|
+
* an account with agent tools owns exactly one `mcp_servers` row. A database
|
|
12
|
+
* account does not work that way. One Supabase personal access token reaches
|
|
13
|
+
* every project in every organisation the user belongs to, so "which database"
|
|
14
|
+
* is not a property of the credential — it is a choice the user makes, possibly
|
|
15
|
+
* several times.
|
|
16
|
+
*
|
|
17
|
+
* The alternative was one account per remote database, and it is the same
|
|
18
|
+
* mistake `Task 3` refused for Vercel teams: it would make a user with a
|
|
19
|
+
* production and a staging project paste the same token twice and rotate it in
|
|
20
|
+
* two places. So the key gains `target_id`, and the choices themselves get a
|
|
21
|
+
* table.
|
|
22
|
+
*/
|
|
23
|
+
export const up = (db: DatabaseConnection): void => {
|
|
24
|
+
debug.log('migration', 'Widening integration_projections primary key...');
|
|
25
|
+
|
|
26
|
+
// SQLite cannot alter a primary key, so the table is rebuilt. It is small
|
|
27
|
+
// (one row per projected surface row) and the copy is a straight SELECT —
|
|
28
|
+
// every column keeps its meaning, only the key widens.
|
|
29
|
+
db.exec('PRAGMA foreign_keys = OFF;');
|
|
30
|
+
|
|
31
|
+
db.exec(`
|
|
32
|
+
CREATE TABLE IF NOT EXISTS integration_projections_new (
|
|
33
|
+
account_id TEXT NOT NULL REFERENCES integration_accounts(id) ON DELETE CASCADE,
|
|
34
|
+
capability TEXT NOT NULL,
|
|
35
|
+
target_kind TEXT NOT NULL,
|
|
36
|
+
target_id TEXT NOT NULL,
|
|
37
|
+
adopted INTEGER NOT NULL DEFAULT 0,
|
|
38
|
+
restore_json TEXT,
|
|
39
|
+
created_at TEXT NOT NULL,
|
|
40
|
+
PRIMARY KEY (account_id, capability, target_kind, target_id)
|
|
41
|
+
)
|
|
42
|
+
`);
|
|
43
|
+
|
|
44
|
+
db.exec(`
|
|
45
|
+
INSERT INTO integration_projections_new (
|
|
46
|
+
account_id, capability, target_kind, target_id, adopted, restore_json, created_at
|
|
47
|
+
)
|
|
48
|
+
SELECT account_id, capability, target_kind, target_id, adopted, restore_json, created_at
|
|
49
|
+
FROM integration_projections;
|
|
50
|
+
`);
|
|
51
|
+
|
|
52
|
+
db.exec('DROP TABLE integration_projections;');
|
|
53
|
+
db.exec('ALTER TABLE integration_projections_new RENAME TO integration_projections;');
|
|
54
|
+
|
|
55
|
+
db.exec(`
|
|
56
|
+
CREATE INDEX IF NOT EXISTS idx_integration_projections_target
|
|
57
|
+
ON integration_projections(target_kind, target_id)
|
|
58
|
+
`);
|
|
59
|
+
|
|
60
|
+
db.exec('PRAGMA foreign_keys = ON;');
|
|
61
|
+
|
|
62
|
+
debug.log('migration', 'Creating integration_db_links table...');
|
|
63
|
+
|
|
64
|
+
// One row per remote database the user chose to bring into DB Client.
|
|
65
|
+
//
|
|
66
|
+
// `secrets` is a sealed JSON blob rather than a password column because the
|
|
67
|
+
// secret a database provider needs is not the same everywhere: Supabase
|
|
68
|
+
// needs the Postgres password (which its Management API deliberately cannot
|
|
69
|
+
// read back), Turso needs an auth token, and a later provider may need a
|
|
70
|
+
// client certificate. It lives HERE rather than only on the projected
|
|
71
|
+
// connection because a projection must be rebuildable from the account plus
|
|
72
|
+
// the link alone — a release followed by a re-project must not silently drop
|
|
73
|
+
// the password and leave a connection that can no longer log in.
|
|
74
|
+
//
|
|
75
|
+
// `remote_ref` is the provider's own identifier for the database (a Supabase
|
|
76
|
+
// project ref, a Neon project id). `(account_id, remote_ref)` is unique: two
|
|
77
|
+
// links to the same remote database from one account would project two
|
|
78
|
+
// connections to the same place.
|
|
79
|
+
db.exec(`
|
|
80
|
+
CREATE TABLE IF NOT EXISTS integration_db_links (
|
|
81
|
+
id TEXT PRIMARY KEY,
|
|
82
|
+
account_id TEXT NOT NULL REFERENCES integration_accounts(id) ON DELETE CASCADE,
|
|
83
|
+
remote_ref TEXT NOT NULL,
|
|
84
|
+
label TEXT NOT NULL,
|
|
85
|
+
driver TEXT NOT NULL,
|
|
86
|
+
mode TEXT NOT NULL DEFAULT 'pooler-session',
|
|
87
|
+
secrets TEXT NOT NULL DEFAULT '{}',
|
|
88
|
+
config_json TEXT NOT NULL DEFAULT '{}',
|
|
89
|
+
detected INTEGER NOT NULL DEFAULT 0,
|
|
90
|
+
created_at TEXT NOT NULL,
|
|
91
|
+
updated_at TEXT NOT NULL,
|
|
92
|
+
UNIQUE (account_id, remote_ref)
|
|
93
|
+
)
|
|
94
|
+
`);
|
|
95
|
+
|
|
96
|
+
db.exec(`
|
|
97
|
+
CREATE INDEX IF NOT EXISTS idx_integration_db_links_account
|
|
98
|
+
ON integration_db_links(account_id)
|
|
99
|
+
`);
|
|
100
|
+
|
|
101
|
+
debug.log('migration', 'integration_db_links created');
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
export const down = (db: DatabaseConnection): void => {
|
|
105
|
+
debug.log('migration', 'Dropping integration_db_links...');
|
|
106
|
+
db.exec('DROP INDEX IF EXISTS idx_integration_db_links_account');
|
|
107
|
+
db.exec('DROP TABLE IF EXISTS integration_db_links');
|
|
108
|
+
|
|
109
|
+
// Narrow the key back. A row that only exists because the wider key allowed
|
|
110
|
+
// it would collide, so the copy keeps the first row per narrow key — the
|
|
111
|
+
// projections it drops are exactly the ones the old schema could not hold,
|
|
112
|
+
// and the surface rows they point at are left where they are rather than
|
|
113
|
+
// being deleted by a rollback.
|
|
114
|
+
debug.log('migration', 'Narrowing integration_projections primary key...');
|
|
115
|
+
db.exec('PRAGMA foreign_keys = OFF;');
|
|
116
|
+
|
|
117
|
+
db.exec(`
|
|
118
|
+
CREATE TABLE IF NOT EXISTS integration_projections_old (
|
|
119
|
+
account_id TEXT NOT NULL REFERENCES integration_accounts(id) ON DELETE CASCADE,
|
|
120
|
+
capability TEXT NOT NULL,
|
|
121
|
+
target_kind TEXT NOT NULL,
|
|
122
|
+
target_id TEXT NOT NULL,
|
|
123
|
+
adopted INTEGER NOT NULL DEFAULT 0,
|
|
124
|
+
restore_json TEXT,
|
|
125
|
+
created_at TEXT NOT NULL,
|
|
126
|
+
PRIMARY KEY (account_id, capability, target_kind)
|
|
127
|
+
)
|
|
128
|
+
`);
|
|
129
|
+
|
|
130
|
+
db.exec(`
|
|
131
|
+
INSERT OR IGNORE INTO integration_projections_old (
|
|
132
|
+
account_id, capability, target_kind, target_id, adopted, restore_json, created_at
|
|
133
|
+
)
|
|
134
|
+
SELECT account_id, capability, target_kind, target_id, adopted, restore_json, created_at
|
|
135
|
+
FROM integration_projections
|
|
136
|
+
ORDER BY created_at ASC;
|
|
137
|
+
`);
|
|
138
|
+
|
|
139
|
+
db.exec('DROP TABLE integration_projections;');
|
|
140
|
+
db.exec('ALTER TABLE integration_projections_old RENAME TO integration_projections;');
|
|
141
|
+
|
|
142
|
+
db.exec(`
|
|
143
|
+
CREATE INDEX IF NOT EXISTS idx_integration_projections_target
|
|
144
|
+
ON integration_projections(target_kind, target_id)
|
|
145
|
+
`);
|
|
146
|
+
|
|
147
|
+
db.exec('PRAGMA foreign_keys = ON;');
|
|
148
|
+
|
|
149
|
+
debug.log('migration', 'integration_db_links migration rolled back');
|
|
150
|
+
};
|
|
@@ -73,6 +73,9 @@ import * as migration071 from './071_create_notes_tables';
|
|
|
73
73
|
import * as migration072 from './072_encrypt_stored_secrets';
|
|
74
74
|
import * as migration073 from './073_create_integration_tables';
|
|
75
75
|
import * as migration074 from './074_create_work_tables';
|
|
76
|
+
import * as migration075 from './075_create_deploy_bindings';
|
|
77
|
+
import * as migration076 from './076_remove_memory_code_graph';
|
|
78
|
+
import * as migration077 from './077_create_integration_db_links';
|
|
76
79
|
|
|
77
80
|
// Export all migrations in order
|
|
78
81
|
export const migrations = [
|
|
@@ -519,6 +522,24 @@ export const migrations = [
|
|
|
519
522
|
description: migration074.description,
|
|
520
523
|
up: migration074.up,
|
|
521
524
|
down: migration074.down
|
|
525
|
+
},
|
|
526
|
+
{
|
|
527
|
+
id: '075',
|
|
528
|
+
description: migration075.description,
|
|
529
|
+
up: migration075.up,
|
|
530
|
+
down: migration075.down
|
|
531
|
+
},
|
|
532
|
+
{
|
|
533
|
+
id: '076',
|
|
534
|
+
description: migration076.description,
|
|
535
|
+
up: migration076.up,
|
|
536
|
+
down: migration076.down
|
|
537
|
+
},
|
|
538
|
+
{
|
|
539
|
+
id: '077',
|
|
540
|
+
description: migration077.description,
|
|
541
|
+
up: migration077.up,
|
|
542
|
+
down: migration077.down
|
|
522
543
|
}
|
|
523
544
|
];
|
|
524
545
|
|
|
@@ -341,6 +341,25 @@ export const dbClientConnectionQueries = {
|
|
|
341
341
|
return redactConnectionSecrets(updated);
|
|
342
342
|
},
|
|
343
343
|
|
|
344
|
+
/**
|
|
345
|
+
* Write the password exactly, including clearing it.
|
|
346
|
+
*
|
|
347
|
+
* `update()` treats an empty password as "the field was not re-typed" and
|
|
348
|
+
* keeps what is stored, which is right for a form and wrong for a
|
|
349
|
+
* projection: a derived row must equal what it was derived FROM, and
|
|
350
|
+
* releasing an adopted row back to a user who never set a password has to
|
|
351
|
+
* remove ours rather than leave it behind. This is that path, and it exists
|
|
352
|
+
* for the integration projector alone.
|
|
353
|
+
*/
|
|
354
|
+
replacePassword(id: string, password: string | null): void {
|
|
355
|
+
const db = getDatabase();
|
|
356
|
+
db.prepare('UPDATE db_client_connections SET password = ?, updated_at = ? WHERE id = ?').run(
|
|
357
|
+
sealFor(TABLE, 'password', password && password.length > 0 ? password : null),
|
|
358
|
+
new Date().toISOString(),
|
|
359
|
+
id
|
|
360
|
+
);
|
|
361
|
+
},
|
|
362
|
+
|
|
344
363
|
delete(id: string): void {
|
|
345
364
|
const db = getDatabase();
|
|
346
365
|
db.prepare('DELETE FROM db_client_connections WHERE id = ?').run(id);
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deployments surface queries — bindings only.
|
|
3
|
+
*
|
|
4
|
+
* This table holds no secret, so nothing here goes through the crypto layer: a
|
|
5
|
+
* locator is a provider project id and the config is two display preferences.
|
|
6
|
+
* The credential that reaches the provider always comes from
|
|
7
|
+
* `integration_accounts`.
|
|
8
|
+
*
|
|
9
|
+
* There is no second table. Unlike the Issues surface, which records which
|
|
10
|
+
* worktree someone opened for an issue, a deployment leaves nothing local
|
|
11
|
+
* behind that would outlive the remote record — so nothing about a deployment
|
|
12
|
+
* is persisted at all. See migration 075.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { getDatabase } from '../index';
|
|
16
|
+
import type { DeployBindingConfig } from '$shared/types/deployments';
|
|
17
|
+
import { DEFAULT_DEPLOY_BINDING_CONFIG } from '$shared/types/deployments';
|
|
18
|
+
|
|
19
|
+
export interface DeployBindingRow {
|
|
20
|
+
project_id: string;
|
|
21
|
+
account_id: string;
|
|
22
|
+
locator: string;
|
|
23
|
+
display_name: string;
|
|
24
|
+
team_id: string | null;
|
|
25
|
+
detected: number;
|
|
26
|
+
config_json: string;
|
|
27
|
+
created_at: string;
|
|
28
|
+
updated_at: string;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Parse the stored config over the defaults.
|
|
33
|
+
*
|
|
34
|
+
* Merged rather than replaced for the reason `parseBindingConfig` is: a config
|
|
35
|
+
* written before an option existed must not read back with that option
|
|
36
|
+
* `undefined`, or `environment` becomes a filter nothing matches and the list
|
|
37
|
+
* renders empty on a project that has deployments.
|
|
38
|
+
*/
|
|
39
|
+
export function parseDeployConfig(raw: string | null): DeployBindingConfig {
|
|
40
|
+
if (!raw) return { ...DEFAULT_DEPLOY_BINDING_CONFIG };
|
|
41
|
+
try {
|
|
42
|
+
const parsed = JSON.parse(raw) as Partial<DeployBindingConfig> | null;
|
|
43
|
+
return { ...DEFAULT_DEPLOY_BINDING_CONFIG, ...(parsed ?? {}) };
|
|
44
|
+
} catch {
|
|
45
|
+
return { ...DEFAULT_DEPLOY_BINDING_CONFIG };
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export const deployBindingQueries = {
|
|
50
|
+
getForProject(projectId: string): DeployBindingRow[] {
|
|
51
|
+
const db = getDatabase();
|
|
52
|
+
return db.prepare(
|
|
53
|
+
`SELECT * FROM deploy_bindings WHERE project_id = ?`
|
|
54
|
+
).all(projectId) as DeployBindingRow[];
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
get(projectId: string, accountId: string): DeployBindingRow | null {
|
|
58
|
+
const db = getDatabase();
|
|
59
|
+
return db.prepare(
|
|
60
|
+
`SELECT * FROM deploy_bindings WHERE project_id = ? AND account_id = ?`
|
|
61
|
+
).get(projectId, accountId) as DeployBindingRow | null;
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
upsert(input: {
|
|
65
|
+
projectId: string;
|
|
66
|
+
accountId: string;
|
|
67
|
+
locator: string;
|
|
68
|
+
displayName: string;
|
|
69
|
+
teamId: string | null;
|
|
70
|
+
detected: boolean;
|
|
71
|
+
config?: DeployBindingConfig;
|
|
72
|
+
}): DeployBindingRow {
|
|
73
|
+
const db = getDatabase();
|
|
74
|
+
const now = new Date().toISOString();
|
|
75
|
+
const existing = this.get(input.projectId, input.accountId);
|
|
76
|
+
|
|
77
|
+
db.prepare(`
|
|
78
|
+
INSERT INTO deploy_bindings (
|
|
79
|
+
project_id, account_id, locator, display_name, team_id, detected,
|
|
80
|
+
config_json, created_at, updated_at
|
|
81
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
82
|
+
ON CONFLICT (project_id, account_id) DO UPDATE SET
|
|
83
|
+
locator = excluded.locator,
|
|
84
|
+
display_name = excluded.display_name,
|
|
85
|
+
team_id = excluded.team_id,
|
|
86
|
+
detected = excluded.detected,
|
|
87
|
+
config_json = excluded.config_json,
|
|
88
|
+
updated_at = excluded.updated_at
|
|
89
|
+
`).run(
|
|
90
|
+
input.projectId,
|
|
91
|
+
input.accountId,
|
|
92
|
+
input.locator,
|
|
93
|
+
input.displayName,
|
|
94
|
+
input.teamId,
|
|
95
|
+
input.detected ? 1 : 0,
|
|
96
|
+
JSON.stringify(input.config ?? parseDeployConfig(existing?.config_json ?? null)),
|
|
97
|
+
existing?.created_at ?? now,
|
|
98
|
+
now
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
return this.get(input.projectId, input.accountId)!;
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Store the config alone.
|
|
106
|
+
*
|
|
107
|
+
* Separate from `upsert` so toggling auto-refresh cannot clobber a locator
|
|
108
|
+
* the user repointed while the toggle was in flight — the same race
|
|
109
|
+
* `setDefaultBranch` avoids on the Issues side.
|
|
110
|
+
*/
|
|
111
|
+
setConfig(projectId: string, accountId: string, config: DeployBindingConfig): void {
|
|
112
|
+
const db = getDatabase();
|
|
113
|
+
db.prepare(
|
|
114
|
+
`UPDATE deploy_bindings SET config_json = ?, updated_at = ? WHERE project_id = ? AND account_id = ?`
|
|
115
|
+
).run(JSON.stringify(config), new Date().toISOString(), projectId, accountId);
|
|
116
|
+
},
|
|
117
|
+
|
|
118
|
+
remove(projectId: string, accountId: string): void {
|
|
119
|
+
const db = getDatabase();
|
|
120
|
+
db.prepare(
|
|
121
|
+
`DELETE FROM deploy_bindings WHERE project_id = ? AND account_id = ?`
|
|
122
|
+
).run(projectId, accountId);
|
|
123
|
+
}
|
|
124
|
+
};
|