@myrialabs/clopen 0.4.38 → 0.4.40
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 +48 -0
- package/backend/chat/stream-manager.ts +1 -1
- package/backend/database/crypto/secret-columns.ts +9 -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/078_create_worktree_branch_tables.ts +158 -0
- package/backend/database/migrations/index.ts +28 -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 +10 -0
- package/backend/database/queries/integration-db-link-queries.ts +168 -0
- package/backend/database/queries/integration-queries.ts +34 -6
- package/backend/database/queries/worktree-branch-queries.ts +331 -0
- package/backend/db-client/cloning.test.ts +161 -0
- package/backend/db-client/cloning.ts +672 -0
- package/backend/db-client/connection-url.test.ts +117 -0
- package/backend/db-client/connection-url.ts +126 -0
- package/backend/db-client/drivers/mongodb.ts +2 -14
- package/backend/db-client/drivers/mysql.ts +2 -8
- package/backend/db-client/drivers/postgres.ts +10 -13
- package/backend/db-client/drivers/redis.ts +2 -6
- package/backend/db-client/env/detect.ts +438 -0
- package/backend/db-client/env/diff.ts +94 -0
- package/backend/db-client/env/env.test.ts +574 -0
- package/backend/db-client/env/index.ts +15 -0
- package/backend/db-client/env/naming.ts +202 -0
- package/backend/db-client/env/service.ts +487 -0
- package/backend/db-client/integrations/index.ts +44 -0
- package/backend/db-client/integrations/links.ts +564 -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/neon/adapter.ts +522 -0
- package/backend/db-client/providers/neon/api-types.ts +182 -0
- package/backend/db-client/providers/neon/client.ts +298 -0
- package/backend/db-client/providers/neon/endpoints.test.ts +201 -0
- package/backend/db-client/providers/neon/endpoints.ts +314 -0
- package/backend/db-client/providers/neon/list.test.ts +181 -0
- package/backend/db-client/providers/registry.ts +27 -0
- package/backend/db-client/providers/supabase/adapter.ts +523 -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 +194 -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/env-files/discovery.ts +48 -0
- package/backend/env-files/edit.ts +213 -0
- package/backend/env-files/env-files.test.ts +515 -0
- package/backend/env-files/git.ts +27 -0
- package/backend/env-files/index.ts +44 -0
- package/backend/env-files/keys.ts +69 -0
- package/backend/env-files/parse.ts +157 -0
- package/backend/env-files/write.ts +229 -0
- package/backend/index.ts +4 -0
- package/backend/integrations/health.ts +18 -4
- package/backend/integrations/projections/index.ts +0 -0
- package/backend/integrations/projections/mcp-projector.ts +7 -3
- package/backend/integrations/projections/types.ts +28 -9
- package/backend/integrations/registry/index.ts +8 -1
- package/backend/integrations/registry/providers/context7.ts +1 -0
- package/backend/integrations/registry/providers/firecrawl.ts +1 -0
- package/backend/integrations/registry/providers/github.ts +1 -0
- package/backend/integrations/registry/providers/neon.ts +55 -0
- package/backend/integrations/registry/providers/supabase.ts +62 -0
- package/backend/integrations/registry/providers/vercel.ts +47 -0
- package/backend/integrations/registry/types.ts +2 -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/work/start-work.ts +4 -0
- package/backend/worktrees/branching/engine.ts +557 -0
- package/backend/worktrees/branching/index.ts +56 -0
- package/backend/worktrees/branching/naming.test.ts +118 -0
- package/backend/worktrees/branching/naming.ts +97 -0
- package/backend/worktrees/branching/projector.test.ts +229 -0
- package/backend/worktrees/branching/projector.ts +139 -0
- package/backend/worktrees/branching/providers/neon.ts +220 -0
- package/backend/worktrees/branching/registry.ts +27 -0
- package/backend/worktrees/branching/service.ts +620 -0
- package/backend/worktrees/branching/suggest.test.ts +154 -0
- package/backend/worktrees/branching/suggest.ts +202 -0
- package/backend/worktrees/branching/types.ts +88 -0
- package/backend/worktrees/index.ts +7 -0
- package/backend/worktrees/service.ts +48 -1
- 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/env.ts +142 -0
- package/backend/ws/db-client/index.ts +22 -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/projects/index.ts +6 -1
- package/backend/ws/projects/info.ts +70 -6
- package/backend/ws/projects/overview.test.ts +108 -0
- package/backend/ws/projects/overview.ts +300 -0
- package/backend/ws/snapshot/changes.ts +279 -0
- package/backend/ws/snapshot/index.ts +4 -3
- package/backend/ws/system/device-info.ts +307 -76
- package/backend/ws/worktrees/branching.ts +212 -0
- package/backend/ws/worktrees/crud.ts +33 -7
- package/backend/ws/worktrees/index.ts +14 -0
- package/dist/assets/{index-DSHIANSy.js → index-D4igjF6e.js} +1 -1
- package/dist/assets/{index-CyH7fSbR.js → index-DONNwiXm.js} +1 -1
- package/dist/assets/main-BrfXH1bL.js +1205 -0
- package/dist/assets/main-CT1PygsW.css +1 -0
- package/dist/index.html +2 -2
- package/package.json +1 -1
- package/shared/constants/tool-icons.ts +13 -0
- package/shared/types/db-client/connection.ts +6 -0
- package/shared/types/db-client/env.ts +192 -0
- package/shared/types/db-client/index.ts +3 -0
- package/shared/types/db-client/integrations.ts +204 -0
- package/shared/types/db-client/supabase.ts +131 -0
- package/shared/types/deployments.ts +382 -0
- package/shared/types/integrations.ts +9 -0
- package/shared/types/memory.ts +34 -51
- package/shared/types/ui/components.ts +1 -1
- package/shared/types/worktree-branching.ts +315 -0
- package/shared/utils/diff-calculator.test.ts +89 -0
- package/shared/utils/diff-calculator.ts +30 -65
- package/shared/utils/logger.ts +2 -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
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
*/
|
|
31
31
|
|
|
32
32
|
import { getDatabase } from '$backend/database';
|
|
33
|
-
import { graphQueries } from '$backend/database/queries/graph-queries';
|
|
33
|
+
import { graphQueries, normalizePath } from '$backend/database/queries/graph-queries';
|
|
34
34
|
import { debug } from '$shared/utils/logger';
|
|
35
35
|
import { embedder, vectorCache } from './embedding';
|
|
36
36
|
import { EMBEDDING_VERSION } from './embedding/paths';
|
|
@@ -134,8 +134,8 @@ interface FilterSql {
|
|
|
134
134
|
* How a query should be read.
|
|
135
135
|
*
|
|
136
136
|
* The two channels are not equally good at the two kinds of question, and which
|
|
137
|
-
* kind a query is can be told from its surface without a model. `
|
|
138
|
-
* `backend/memory/
|
|
137
|
+
* kind a query is can be told from its surface without a model. `setPaths` and
|
|
138
|
+
* `backend/memory/invalidate.ts` are identifiers: BM25 matches them exactly, while a
|
|
139
139
|
* mean-pooled static embedding of a path fragment lands in the crowded middle of
|
|
140
140
|
* the space and mostly adds noise. "kenapa kita pakai SQLite" is the reverse —
|
|
141
141
|
* it shares no token with the English memory that answers it, and only the vector
|
|
@@ -180,9 +180,9 @@ function buildFilter(options: RetrievalOptions, alias: string): FilterSql {
|
|
|
180
180
|
const params: unknown[] = [];
|
|
181
181
|
|
|
182
182
|
// `reach = 'anywhere'` is what a memory learned elsewhere needs to be admitted
|
|
183
|
-
// here
|
|
184
|
-
//
|
|
185
|
-
//
|
|
183
|
+
// here, and it defaults to `here` — so a claim about one repository cannot
|
|
184
|
+
// arrive in another's results unless a model judged that it travels. That is
|
|
185
|
+
// the leak the blanket project filter was originally added to stop.
|
|
186
186
|
const travelling = options.crossProject ? ` OR ${alias}.reach = 'anywhere'` : '';
|
|
187
187
|
|
|
188
188
|
if (options.projectIds !== undefined) {
|
|
@@ -212,10 +212,6 @@ function buildFilter(options: RetrievalOptions, alias: string): FilterSql {
|
|
|
212
212
|
where.push(`${alias}.scope IN (${options.scopes.map(() => '?').join(',')})`);
|
|
213
213
|
params.push(...options.scopes);
|
|
214
214
|
}
|
|
215
|
-
if (options.kinds?.length) {
|
|
216
|
-
where.push(`${alias}.kind IN (${options.kinds.map(() => '?').join(',')})`);
|
|
217
|
-
params.push(...options.kinds);
|
|
218
|
-
}
|
|
219
215
|
if (options.subkinds?.length) {
|
|
220
216
|
where.push(`${alias}.subkind IN (${options.subkinds.map(() => '?').join(',')})`);
|
|
221
217
|
params.push(...options.subkinds);
|
|
@@ -239,14 +235,12 @@ function buildFilter(options: RetrievalOptions, alias: string): FilterSql {
|
|
|
239
235
|
* Graph expansion reaches nodes through EDGES rather than through a query, and
|
|
240
236
|
* edges deliberately cross project boundaries (that is what lets a pattern
|
|
241
237
|
* proven in one repository be reused in another). Without re-checking the filter
|
|
242
|
-
* here, one hop
|
|
243
|
-
*
|
|
244
|
-
*
|
|
245
|
-
* rules the channels do.
|
|
238
|
+
* here, one hop would pull another project's memories into a block that is about
|
|
239
|
+
* to be injected into this project's prompt. Traversal has to obey the same
|
|
240
|
+
* scope rules the channels do.
|
|
246
241
|
*/
|
|
247
242
|
function makeFilterPredicate(options: RetrievalOptions): (node: GraphNode) => boolean {
|
|
248
243
|
const scopes = options.scopes?.length ? new Set(options.scopes) : null;
|
|
249
|
-
const kinds = options.kinds?.length ? new Set(options.kinds) : null;
|
|
250
244
|
const subkinds = options.subkinds?.length ? new Set(options.subkinds) : null;
|
|
251
245
|
const sources = options.sources?.length ? new Set(options.sources) : null;
|
|
252
246
|
|
|
@@ -255,7 +249,7 @@ function makeFilterPredicate(options: RetrievalOptions): (node: GraphNode) => bo
|
|
|
255
249
|
return (node: GraphNode): boolean => {
|
|
256
250
|
// Same admission rule as `buildFilter`, so traversal cannot reach anything
|
|
257
251
|
// the channels were not allowed to return.
|
|
258
|
-
const travels = options.crossProject === true && node.reach === 'anywhere'
|
|
252
|
+
const travels = options.crossProject === true && node.reach === 'anywhere';
|
|
259
253
|
if (projectIds) {
|
|
260
254
|
if (node.projectId !== null && !projectIds.has(node.projectId) && !travels) return false;
|
|
261
255
|
} else if (options.projectId !== undefined) {
|
|
@@ -267,7 +261,6 @@ function makeFilterPredicate(options: RetrievalOptions): (node: GraphNode) => bo
|
|
|
267
261
|
}
|
|
268
262
|
if (options.sessionId && node.scope === 'session' && node.sessionId !== options.sessionId) return false;
|
|
269
263
|
if (scopes && !scopes.has(node.scope)) return false;
|
|
270
|
-
if (kinds && !kinds.has(node.kind)) return false;
|
|
271
264
|
if (subkinds && !subkinds.has(node.subkind)) return false;
|
|
272
265
|
if (sources && !sources.has(node.source)) return false;
|
|
273
266
|
if (!options.includeArchived && node.archivedAt) return false;
|
|
@@ -588,16 +581,24 @@ function currentOf(a: GraphNode, b: GraphNode): GraphNode {
|
|
|
588
581
|
}
|
|
589
582
|
|
|
590
583
|
/**
|
|
591
|
-
*
|
|
584
|
+
* The memories attached to the files the caller says it is working in.
|
|
585
|
+
*
|
|
586
|
+
* Looked up rather than searched: a path is an exact key, and running it through
|
|
587
|
+
* BM25 would be both slower and less precise.
|
|
592
588
|
*
|
|
593
|
-
* These
|
|
594
|
-
*
|
|
589
|
+
* These used to be the FILE nodes for those paths, which then had to spend a hop
|
|
590
|
+
* of graph expansion crossing an `about` edge to reach the memories that are the
|
|
591
|
+
* actual answer — and each of those file nodes also occupied a slot in the
|
|
592
|
+
* result that a memory could have had. The seeds are the memories themselves
|
|
593
|
+
* now, at hop zero.
|
|
595
594
|
*/
|
|
596
595
|
function anchorSeeds(options: RetrievalOptions, accept: (node: GraphNode) => boolean): GraphNode[] {
|
|
597
596
|
const paths = options.anchorPaths;
|
|
598
597
|
if (!paths?.length || options.projectId === undefined || options.projectId === null) return [];
|
|
599
598
|
try {
|
|
600
|
-
return graphQueries
|
|
599
|
+
return graphQueries
|
|
600
|
+
.nodesForPaths(options.projectId, paths.slice(0, 40).map(normalizePath))
|
|
601
|
+
.filter(accept);
|
|
601
602
|
} catch (error) {
|
|
602
603
|
debug.warn('memory', 'Anchor seeding failed', error);
|
|
603
604
|
return [];
|
|
@@ -15,6 +15,7 @@ import { beforeEach, describe, expect, it, mock } from 'bun:test';
|
|
|
15
15
|
import { Database } from 'bun:sqlite';
|
|
16
16
|
import type { DatabaseConnection } from '$shared/types/database/connection';
|
|
17
17
|
import * as migration066 from '$backend/database/migrations/066_create_memory_graph';
|
|
18
|
+
import * as migration076 from '$backend/database/migrations/076_remove_memory_code_graph';
|
|
18
19
|
|
|
19
20
|
let db: Database;
|
|
20
21
|
|
|
@@ -41,7 +42,6 @@ const PROJECT = 'project-a';
|
|
|
41
42
|
|
|
42
43
|
function memory(label: string, overrides: Record<string, unknown> = {}) {
|
|
43
44
|
return graphQueries.upsert({
|
|
44
|
-
kind: 'episodic',
|
|
45
45
|
subkind: 'decision',
|
|
46
46
|
projectId: PROJECT,
|
|
47
47
|
label,
|
|
@@ -49,14 +49,9 @@ function memory(label: string, overrides: Record<string, unknown> = {}) {
|
|
|
49
49
|
} as Parameters<typeof graphQueries.upsert>[0]);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
subkind: 'file',
|
|
56
|
-
projectId: PROJECT,
|
|
57
|
-
label: path,
|
|
58
|
-
path
|
|
59
|
-
});
|
|
52
|
+
/** Attach a memory to the file it claims something about. */
|
|
53
|
+
function about(node: { id: string }, ...paths: string[]): void {
|
|
54
|
+
graphQueries.setPaths(node.id, paths);
|
|
60
55
|
}
|
|
61
56
|
|
|
62
57
|
/** Backdate a node so age-gated behaviour can be exercised without waiting. */
|
|
@@ -72,6 +67,7 @@ beforeEach(() => {
|
|
|
72
67
|
db = new Database(':memory:');
|
|
73
68
|
db.exec('PRAGMA foreign_keys = ON');
|
|
74
69
|
migration066.up(db as unknown as DatabaseConnection);
|
|
70
|
+
migration076.up(db as unknown as DatabaseConnection);
|
|
75
71
|
// The queue's orphan sweep joins against sessions; a stub is enough here.
|
|
76
72
|
db.exec(`CREATE TABLE IF NOT EXISTS chat_sessions (id TEXT PRIMARY KEY)`);
|
|
77
73
|
});
|
|
@@ -186,7 +182,7 @@ describe('supersession', () => {
|
|
|
186
182
|
graphQueries.supersede(old.id, current.id);
|
|
187
183
|
|
|
188
184
|
const stats = graphQueries.stats();
|
|
189
|
-
expect(stats.
|
|
185
|
+
expect(stats.nodes).toBe(1);
|
|
190
186
|
expect(stats.superseded).toBe(1);
|
|
191
187
|
expect(graphQueries.list({ projectId: PROJECT }).map(n => n.id)).not.toContain(old.id);
|
|
192
188
|
});
|
|
@@ -274,7 +270,6 @@ describe('canonical entities', () => {
|
|
|
274
270
|
|
|
275
271
|
describe('structural invalidation', () => {
|
|
276
272
|
it('ages an observation about changed code but not the decision behind it', () => {
|
|
277
|
-
const target = file('backend/chat/stream-manager.ts');
|
|
278
273
|
const observation = memory('Stream manager captures the snapshot in its finally block', {
|
|
279
274
|
subkind: 'observation',
|
|
280
275
|
confidence: 0.9
|
|
@@ -289,10 +284,10 @@ describe('structural invalidation', () => {
|
|
|
289
284
|
});
|
|
290
285
|
|
|
291
286
|
for (const node of [observation, decision, preference]) {
|
|
292
|
-
|
|
287
|
+
about(node, 'backend/chat/stream-manager.ts');
|
|
293
288
|
}
|
|
294
289
|
|
|
295
|
-
invalidateForChanges({
|
|
290
|
+
invalidateForChanges({ changedPaths: ['backend/chat/stream-manager.ts'] });
|
|
296
291
|
|
|
297
292
|
expect(graphQueries.getById(observation.id)!.confidence).toBeLessThan(0.9);
|
|
298
293
|
expect(graphQueries.getById(observation.id)!.staleAt).not.toBeNull();
|
|
@@ -303,7 +298,6 @@ describe('structural invalidation', () => {
|
|
|
303
298
|
});
|
|
304
299
|
|
|
305
300
|
it('never ages a memory a person wrote or pinned', () => {
|
|
306
|
-
const target = file('backend/a.ts');
|
|
307
301
|
const authored = memory('Hand-written note about a.ts', {
|
|
308
302
|
subkind: 'observation',
|
|
309
303
|
confidence: 0.9,
|
|
@@ -314,45 +308,51 @@ describe('structural invalidation', () => {
|
|
|
314
308
|
confidence: 0.9,
|
|
315
309
|
pinned: true
|
|
316
310
|
});
|
|
317
|
-
for (const node of [authored, pinned])
|
|
318
|
-
graphQueries.link({ srcId: node.id, dstId: target.id, rel: 'about' });
|
|
319
|
-
}
|
|
311
|
+
for (const node of [authored, pinned]) about(node, 'backend/a.ts');
|
|
320
312
|
|
|
321
|
-
invalidateForChanges({
|
|
313
|
+
invalidateForChanges({ changedPaths: ['backend/a.ts'] });
|
|
322
314
|
|
|
323
315
|
expect(graphQueries.getById(authored.id)!.confidence).toBe(0.9);
|
|
324
316
|
expect(graphQueries.getById(pinned.id)!.confidence).toBe(0.9);
|
|
325
317
|
});
|
|
326
318
|
|
|
327
|
-
it('
|
|
328
|
-
//
|
|
329
|
-
//
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
subkind: '
|
|
334
|
-
|
|
335
|
-
label: 'goneHelper',
|
|
336
|
-
path: 'backend/gone.ts',
|
|
337
|
-
symbol: 'goneHelper'
|
|
319
|
+
it('ages a memory about a file that no longer exists', () => {
|
|
320
|
+
// Deletion is the strongest form of "the code moved underneath this", so it
|
|
321
|
+
// runs through the same per-subkind rates rather than a category of its own.
|
|
322
|
+
// The attribution itself is kept: a memory about a since-deleted module is
|
|
323
|
+
// still the only record of what that module taught.
|
|
324
|
+
const note = memory('gone.ts owned the retry loop', {
|
|
325
|
+
subkind: 'observation',
|
|
326
|
+
confidence: 0.9
|
|
338
327
|
});
|
|
328
|
+
about(note, 'backend/gone.ts');
|
|
339
329
|
|
|
340
330
|
const result = invalidateForChanges({
|
|
341
|
-
projectId: PROJECT,
|
|
342
331
|
changedPaths: [],
|
|
343
332
|
deletedPaths: ['backend/gone.ts']
|
|
344
333
|
});
|
|
345
334
|
|
|
346
|
-
expect(result.
|
|
347
|
-
|
|
348
|
-
expect(
|
|
335
|
+
expect(result.decayed).toBe(1);
|
|
336
|
+
expect(graphQueries.getById(note.id)!.staleAt).not.toBeNull();
|
|
337
|
+
expect(graphQueries.pathsOf(note.id)).toEqual(['backend/gone.ts']);
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
it('matches a changed path however the caller spelled it', () => {
|
|
341
|
+
// The disk diff, a model and Windows all spell the same file differently.
|
|
342
|
+
const note = memory('The worker pool is drained on exit', {
|
|
343
|
+
subkind: 'observation',
|
|
344
|
+
confidence: 0.9
|
|
345
|
+
});
|
|
346
|
+
about(note, 'backend/pool.ts');
|
|
347
|
+
|
|
348
|
+
invalidateForChanges({ changedPaths: ['./backend/pool.ts'] });
|
|
349
|
+
expect(graphQueries.getById(note.id)!.staleAt).not.toBeNull();
|
|
349
350
|
});
|
|
350
351
|
|
|
351
352
|
it('clears staleness when the memory is re-observed', () => {
|
|
352
|
-
const target = file('backend/b.ts');
|
|
353
353
|
const node = memory('b.ts exports a queue', { subkind: 'observation', confidence: 0.9 });
|
|
354
|
-
|
|
355
|
-
invalidateForChanges({
|
|
354
|
+
about(node, 'backend/b.ts');
|
|
355
|
+
invalidateForChanges({ changedPaths: ['backend/b.ts'] });
|
|
356
356
|
expect(graphQueries.getById(node.id)!.staleAt).not.toBeNull();
|
|
357
357
|
|
|
358
358
|
// Re-extracting the same claim is the evidence that it survived the change.
|
|
@@ -419,33 +419,25 @@ describe('forgetting and deleting', () => {
|
|
|
419
419
|
* not, which is why forgotten memories kept reappearing.
|
|
420
420
|
*/
|
|
421
421
|
it('keeps a forgotten memory out of a neighbour walk', () => {
|
|
422
|
-
const target = file('backend/auth.ts');
|
|
423
422
|
const live = memory('Auth uses short-lived tokens');
|
|
424
423
|
const forgotten = memory('Auth used to use cookies');
|
|
425
|
-
|
|
426
|
-
graphQueries.link({ srcId: node.id, dstId: target.id, rel: 'about' });
|
|
427
|
-
}
|
|
424
|
+
graphQueries.link({ srcId: live.id, dstId: forgotten.id, rel: 'supersedes' });
|
|
428
425
|
|
|
429
426
|
graphQueries.archive(forgotten.id);
|
|
430
427
|
|
|
431
|
-
|
|
432
|
-
expect(ids).toContain(live.id);
|
|
433
|
-
expect(ids).not.toContain(forgotten.id);
|
|
428
|
+
expect(graphQueries.neighbours(live.id, 1).map(n => n.node.id)).not.toContain(forgotten.id);
|
|
434
429
|
// The edge itself is untouched: this is a display rule, not a deletion.
|
|
435
430
|
expect(graphQueries.edgesOf(forgotten.id)).toHaveLength(1);
|
|
436
431
|
});
|
|
437
432
|
|
|
438
433
|
it('keeps a superseded memory out of a neighbour walk', () => {
|
|
439
|
-
const target = file('backend/db.ts');
|
|
440
434
|
const current = memory('Storage is SQLite');
|
|
441
435
|
const old = memory('Storage is Postgres');
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
}
|
|
436
|
+
const related = memory('Migrations run at startup');
|
|
437
|
+
graphQueries.link({ srcId: related.id, dstId: old.id, rel: 'relates_to' });
|
|
445
438
|
graphQueries.supersede(old.id, current.id);
|
|
446
439
|
|
|
447
|
-
|
|
448
|
-
expect(ids).not.toContain(old.id);
|
|
440
|
+
expect(graphQueries.neighbours(related.id, 1).map(n => n.node.id)).not.toContain(old.id);
|
|
449
441
|
});
|
|
450
442
|
|
|
451
443
|
it('lists both the archived and the superseded as forgotten', () => {
|
|
@@ -463,13 +455,22 @@ describe('forgetting and deleting', () => {
|
|
|
463
455
|
|
|
464
456
|
it('hard-deletes selected nodes and their edges', () => {
|
|
465
457
|
const node = memory('To be deleted');
|
|
466
|
-
const
|
|
467
|
-
graphQueries.link({ srcId: node.id, dstId:
|
|
458
|
+
const other = memory('Still here');
|
|
459
|
+
graphQueries.link({ srcId: node.id, dstId: other.id, rel: 'relates_to' });
|
|
468
460
|
graphQueries.archive(node.id);
|
|
469
461
|
|
|
470
462
|
expect(graphQueries.deleteNodes([node.id])).toBe(1);
|
|
471
463
|
expect(graphQueries.getById(node.id)).toBeNull();
|
|
472
|
-
expect(graphQueries.edgesOf(
|
|
464
|
+
expect(graphQueries.edgesOf(other.id)).toHaveLength(0);
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
it('takes a deleted memory\'s path attributions with it', () => {
|
|
468
|
+
const node = memory('About a file');
|
|
469
|
+
about(node, 'src/thing.ts');
|
|
470
|
+
graphQueries.archive(node.id);
|
|
471
|
+
graphQueries.deleteNodes([node.id]);
|
|
472
|
+
|
|
473
|
+
expect(graphQueries.memoriesForPaths(['src/thing.ts'])).toHaveLength(0);
|
|
473
474
|
});
|
|
474
475
|
|
|
475
476
|
it('does not orphan a node whose replacement was deleted', () => {
|
|
@@ -488,7 +489,6 @@ describe('purge', () => {
|
|
|
488
489
|
it('empties one project and leaves the others alone', () => {
|
|
489
490
|
const mine = memory('Belongs to project A');
|
|
490
491
|
const theirs = graphQueries.upsert({
|
|
491
|
-
kind: 'episodic',
|
|
492
492
|
subkind: 'decision',
|
|
493
493
|
projectId: 'project-b',
|
|
494
494
|
label: 'Belongs to project B'
|
|
@@ -504,7 +504,6 @@ describe('purge', () => {
|
|
|
504
504
|
// Preferences and conventions were never that repository's to hold, so losing
|
|
505
505
|
// them because one project was cleaned would be a surprise.
|
|
506
506
|
const global = graphQueries.upsert({
|
|
507
|
-
kind: 'episodic',
|
|
508
507
|
subkind: 'preference',
|
|
509
508
|
scope: 'global',
|
|
510
509
|
projectId: null,
|
|
@@ -519,7 +518,6 @@ describe('purge', () => {
|
|
|
519
518
|
it('empties everything when no project is named', () => {
|
|
520
519
|
memory('Project memory');
|
|
521
520
|
graphQueries.upsert({
|
|
522
|
-
kind: 'episodic',
|
|
523
521
|
subkind: 'preference',
|
|
524
522
|
scope: 'global',
|
|
525
523
|
projectId: null,
|
|
@@ -554,12 +552,12 @@ describe('who wrote it', () => {
|
|
|
554
552
|
expect(edited!.label).toBe('The cache is invalidated on read');
|
|
555
553
|
});
|
|
556
554
|
|
|
557
|
-
it('leaves a hand-written memory untouched by
|
|
558
|
-
const target = file('src/cache.ts');
|
|
555
|
+
it('leaves a hand-written memory untouched by staleness decay', () => {
|
|
559
556
|
const mine = memory('The cache is invalidated on write', { subkind: 'observation', source: 'user' });
|
|
560
|
-
|
|
557
|
+
about(mine, 'src/cache.ts');
|
|
561
558
|
|
|
562
|
-
invalidateForChanges({
|
|
559
|
+
invalidateForChanges({ changedPaths: ['src/cache.ts'] });
|
|
560
|
+
invalidateForChanges({ changedPaths: ['src/cache.ts'] });
|
|
563
561
|
|
|
564
562
|
const after = graphQueries.getById(mine.id)!;
|
|
565
563
|
expect(after.staleAt).toBeNull();
|
|
@@ -573,15 +571,14 @@ describe('structural decay', () => {
|
|
|
573
571
|
// confidence by 0.82 ten times over — 0.14, below the injection floor — so an
|
|
574
572
|
// ordinary afternoon silently destroyed everything known about whatever was
|
|
575
573
|
// being worked on.
|
|
576
|
-
const target = file('src/stream.ts');
|
|
577
574
|
const note = memory('The stream captures its snapshot in a finally block', {
|
|
578
575
|
subkind: 'observation',
|
|
579
576
|
confidence: 0.9
|
|
580
577
|
});
|
|
581
|
-
|
|
578
|
+
about(note, 'src/stream.ts');
|
|
582
579
|
|
|
583
580
|
for (let turn = 0; turn < 10; turn++) {
|
|
584
|
-
invalidateForChanges({
|
|
581
|
+
invalidateForChanges({ changedPaths: ['src/stream.ts'] });
|
|
585
582
|
}
|
|
586
583
|
|
|
587
584
|
const after = graphQueries.getById(note.id)!;
|
|
@@ -591,13 +588,12 @@ describe('structural decay', () => {
|
|
|
591
588
|
});
|
|
592
589
|
|
|
593
590
|
it('ages it again once the cool-off has passed', () => {
|
|
594
|
-
const target = file('src/stream.ts');
|
|
595
591
|
const note = memory('An observation about the stream', { subkind: 'observation', confidence: 0.9 });
|
|
596
|
-
|
|
592
|
+
about(note, 'src/stream.ts');
|
|
597
593
|
|
|
598
|
-
invalidateForChanges({
|
|
594
|
+
invalidateForChanges({ changedPaths: ['src/stream.ts'] });
|
|
599
595
|
db.prepare(`UPDATE graph_nodes SET stale_at = datetime('now', '-2 days') WHERE id = ?`).run(note.id);
|
|
600
|
-
invalidateForChanges({
|
|
596
|
+
invalidateForChanges({ changedPaths: ['src/stream.ts'] });
|
|
601
597
|
|
|
602
598
|
expect(graphQueries.getById(note.id)!.confidence).toBeCloseTo(0.9 * 0.82 * 0.82, 5);
|
|
603
599
|
});
|
|
@@ -641,53 +637,3 @@ describe('restoring', () => {
|
|
|
641
637
|
expect(graphQueries.getById(b.id)!.archivedAt).toBeNull();
|
|
642
638
|
});
|
|
643
639
|
});
|
|
644
|
-
|
|
645
|
-
describe('bounding the structural half', () => {
|
|
646
|
-
it('removes symbols nothing refers to and nothing has touched', () => {
|
|
647
|
-
// The structural half is what actually grows without bound — a node per
|
|
648
|
-
// changed file, per directory and up to twenty-five per file's symbols, every
|
|
649
|
-
// turn — and none of the episodic retention queries look at it at all.
|
|
650
|
-
const symbol = graphQueries.upsert({
|
|
651
|
-
kind: 'structural',
|
|
652
|
-
subkind: 'symbol',
|
|
653
|
-
projectId: PROJECT,
|
|
654
|
-
label: 'forgottenHelper',
|
|
655
|
-
path: 'src/old.ts',
|
|
656
|
-
symbol: 'forgottenHelper'
|
|
657
|
-
});
|
|
658
|
-
backdate(symbol.id, 200);
|
|
659
|
-
|
|
660
|
-
expect(graphQueries.pruneStructural({ maxAgeDays: 120, limit: 100 })).toBe(1);
|
|
661
|
-
expect(graphQueries.getById(symbol.id)).toBeNull();
|
|
662
|
-
});
|
|
663
|
-
|
|
664
|
-
it('spares a symbol a memory is about', () => {
|
|
665
|
-
// Deleting it would sever the `about` edge, which is the join both halves of
|
|
666
|
-
// the graph exist for.
|
|
667
|
-
const symbol = graphQueries.upsert({
|
|
668
|
-
kind: 'structural',
|
|
669
|
-
subkind: 'symbol',
|
|
670
|
-
projectId: PROJECT,
|
|
671
|
-
label: 'loadBearing',
|
|
672
|
-
path: 'src/core.ts',
|
|
673
|
-
symbol: 'loadBearing'
|
|
674
|
-
});
|
|
675
|
-
const note = memory('loadBearing must stay synchronous');
|
|
676
|
-
graphQueries.link({ srcId: note.id, dstId: symbol.id, rel: 'about' });
|
|
677
|
-
backdate(symbol.id, 200);
|
|
678
|
-
|
|
679
|
-
expect(graphQueries.pruneStructural({ maxAgeDays: 120, limit: 100 })).toBe(0);
|
|
680
|
-
expect(graphQueries.getById(symbol.id)).not.toBeNull();
|
|
681
|
-
});
|
|
682
|
-
|
|
683
|
-
it('spares file nodes, however old', () => {
|
|
684
|
-
// A file node is what a path lookup resolves to, and `invalidate.ts` already
|
|
685
|
-
// retires files the moment the disk says they are gone — better evidence
|
|
686
|
-
// than age.
|
|
687
|
-
const node = file('src/rarely-touched.ts');
|
|
688
|
-
backdate(node.id, 400);
|
|
689
|
-
|
|
690
|
-
expect(graphQueries.pruneStructural({ maxAgeDays: 120, limit: 100 })).toBe(0);
|
|
691
|
-
expect(graphQueries.getById(node.id)).not.toBeNull();
|
|
692
|
-
});
|
|
693
|
-
});
|
package/backend/memory/revise.ts
CHANGED
package/backend/memory/view.ts
CHANGED
|
@@ -37,7 +37,6 @@
|
|
|
37
37
|
import { graphQueries, graphLayoutQueries, type GraphBinGrid } from '$backend/database/queries/graph-queries';
|
|
38
38
|
import type {
|
|
39
39
|
GraphNode,
|
|
40
|
-
GraphNodeKind,
|
|
41
40
|
GraphRegion,
|
|
42
41
|
GraphScope,
|
|
43
42
|
GraphSource,
|
|
@@ -69,7 +68,6 @@ export interface GraphViewFilter {
|
|
|
69
68
|
projectId?: string | null;
|
|
70
69
|
/** The multi-select's answer: absent = every project, empty = global only. */
|
|
71
70
|
projectIds?: string[];
|
|
72
|
-
kinds?: GraphNodeKind[];
|
|
73
71
|
/** Narrow to particular subkinds — decisions only, failures only, and so on. */
|
|
74
72
|
subkinds?: string[];
|
|
75
73
|
scopes?: GraphScope[];
|
|
@@ -340,7 +338,6 @@ function toViewNode(
|
|
|
340
338
|
): GraphViewNode {
|
|
341
339
|
return {
|
|
342
340
|
id: node.id,
|
|
343
|
-
kind: node.kind,
|
|
344
341
|
subkind: node.subkind,
|
|
345
342
|
scope: node.scope,
|
|
346
343
|
label: node.label,
|
|
@@ -458,13 +455,19 @@ function truncate(label: string): string {
|
|
|
458
455
|
return label.length > BIN_LABEL_MAX ? `${label.slice(0, BIN_LABEL_MAX - 1)}…` : label;
|
|
459
456
|
}
|
|
460
457
|
|
|
461
|
-
/**
|
|
458
|
+
/**
|
|
459
|
+
* A node plus the nodes it reaches — what the inspector renders.
|
|
460
|
+
*
|
|
461
|
+
* The paths are attached HERE and nowhere else on the read path. They are a
|
|
462
|
+
* per-node query, and a listing draws thousands of nodes at a time; the
|
|
463
|
+
* inspector draws one.
|
|
464
|
+
*/
|
|
462
465
|
export function buildNodeDetail(nodeId: string, hops = 1) {
|
|
463
466
|
const node = graphQueries.getById(nodeId);
|
|
464
467
|
if (!node) return null;
|
|
465
468
|
|
|
466
469
|
return {
|
|
467
|
-
node,
|
|
470
|
+
node: { ...node, relatedPaths: graphQueries.pathsOf(nodeId) },
|
|
468
471
|
neighbours: graphQueries.neighbours(nodeId, hops).map(n => ({ node: n.node, hops: n.hops }))
|
|
469
472
|
};
|
|
470
473
|
}
|
|
@@ -2,8 +2,8 @@ import { snapshotQueries, messageQueries, checkpointQueries } from '../database/
|
|
|
2
2
|
import { blobStore } from './blob-store';
|
|
3
3
|
import { debug } from '$shared/utils/logger';
|
|
4
4
|
import { loadMessage } from '$shared/utils/message-formatter';
|
|
5
|
-
import {
|
|
6
|
-
import type { DatabaseMessage } from '$shared/types/database/schema';
|
|
5
|
+
import { buildTurnFiles, summariseTurnFiles } from './turn-changes';
|
|
6
|
+
import type { DatabaseMessage, SessionScopedChanges } from '$shared/types/database/schema';
|
|
7
7
|
import type { UnifiedMessage, UserMessage } from '$shared/types/unified';
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -318,9 +318,16 @@ export function isDescendant(
|
|
|
318
318
|
}
|
|
319
319
|
|
|
320
320
|
/**
|
|
321
|
-
*
|
|
322
|
-
*
|
|
323
|
-
*
|
|
321
|
+
* The numbers a checkpoint shows: files changed, and lines in and out.
|
|
322
|
+
*
|
|
323
|
+
* Recomputed from the blobs rather than read off the snapshot row, through the
|
|
324
|
+
* same `buildTurnFiles` the Changes surface uses. Two reasons, and both were
|
|
325
|
+
* live bugs: rows written before binary files stopped being line-counted claim
|
|
326
|
+
* a PNG's bytes as source lines, and any second implementation of "how many
|
|
327
|
+
* lines is this" eventually disagrees with the first one on screen.
|
|
328
|
+
*
|
|
329
|
+
* Falls back to the stored numbers when the blobs are gone, which is the one
|
|
330
|
+
* case where the row knows something this cannot recover.
|
|
324
331
|
*/
|
|
325
332
|
export async function getCheckpointFileStats(
|
|
326
333
|
checkpointMsg: DatabaseMessage
|
|
@@ -330,42 +337,29 @@ export async function getCheckpointFileStats(
|
|
|
330
337
|
return { filesChanged: 0, insertions: 0, deletions: 0 };
|
|
331
338
|
}
|
|
332
339
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
try { previousSnapshot[filepath] = await blobStore.readBlob(entry.oldHash); }
|
|
353
|
-
catch { allBlobsOk = false; break; }
|
|
354
|
-
}
|
|
355
|
-
if (entry.newHash) {
|
|
356
|
-
try { currentSnapshot[filepath] = await blobStore.readBlob(entry.newHash); }
|
|
357
|
-
catch { allBlobsOk = false; break; }
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
if (allBlobsOk) {
|
|
361
|
-
const recomputed = calculateFileChangeStats(previousSnapshot, currentSnapshot);
|
|
362
|
-
filesChanged = recomputed.filesChanged;
|
|
363
|
-
insertions = recomputed.insertions;
|
|
364
|
-
deletions = recomputed.deletions;
|
|
365
|
-
}
|
|
340
|
+
const stored = {
|
|
341
|
+
filesChanged: snapshot.files_changed || 0,
|
|
342
|
+
insertions: snapshot.insertions || 0,
|
|
343
|
+
deletions: snapshot.deletions || 0
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
if (!snapshot.session_changes) return stored;
|
|
347
|
+
|
|
348
|
+
try {
|
|
349
|
+
const changes = JSON.parse(snapshot.session_changes as string) as SessionScopedChanges;
|
|
350
|
+
if (Object.keys(changes).length === 0) return stored;
|
|
351
|
+
|
|
352
|
+
let blobMissing = false;
|
|
353
|
+
const files = await buildTurnFiles(changes, async (hash) => {
|
|
354
|
+
try {
|
|
355
|
+
return await blobStore.readBlob(hash);
|
|
356
|
+
} catch (err) {
|
|
357
|
+
blobMissing = true;
|
|
358
|
+
throw err;
|
|
366
359
|
}
|
|
367
|
-
}
|
|
360
|
+
});
|
|
361
|
+
return blobMissing ? stored : summariseTurnFiles(files);
|
|
362
|
+
} catch {
|
|
363
|
+
return stored;
|
|
368
364
|
}
|
|
369
|
-
|
|
370
|
-
return { filesChanged, insertions, deletions };
|
|
371
365
|
}
|