@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.
Files changed (177) hide show
  1. package/backend/auth/permissions.ts +48 -0
  2. package/backend/chat/stream-manager.ts +1 -1
  3. package/backend/database/crypto/secret-columns.ts +9 -1
  4. package/backend/database/migrations/075_create_deploy_bindings.ts +54 -0
  5. package/backend/database/migrations/076_remove_memory_code_graph.ts +229 -0
  6. package/backend/database/migrations/077_create_integration_db_links.ts +150 -0
  7. package/backend/database/migrations/078_create_worktree_branch_tables.ts +158 -0
  8. package/backend/database/migrations/index.ts +28 -0
  9. package/backend/database/queries/db-client-connection-queries.ts +19 -0
  10. package/backend/database/queries/deploy-queries.ts +124 -0
  11. package/backend/database/queries/graph-queries.ts +291 -247
  12. package/backend/database/queries/index.ts +10 -0
  13. package/backend/database/queries/integration-db-link-queries.ts +168 -0
  14. package/backend/database/queries/integration-queries.ts +34 -6
  15. package/backend/database/queries/worktree-branch-queries.ts +331 -0
  16. package/backend/db-client/cloning.test.ts +161 -0
  17. package/backend/db-client/cloning.ts +672 -0
  18. package/backend/db-client/connection-url.test.ts +117 -0
  19. package/backend/db-client/connection-url.ts +126 -0
  20. package/backend/db-client/drivers/mongodb.ts +2 -14
  21. package/backend/db-client/drivers/mysql.ts +2 -8
  22. package/backend/db-client/drivers/postgres.ts +10 -13
  23. package/backend/db-client/drivers/redis.ts +2 -6
  24. package/backend/db-client/env/detect.ts +438 -0
  25. package/backend/db-client/env/diff.ts +94 -0
  26. package/backend/db-client/env/env.test.ts +574 -0
  27. package/backend/db-client/env/index.ts +15 -0
  28. package/backend/db-client/env/naming.ts +202 -0
  29. package/backend/db-client/env/service.ts +487 -0
  30. package/backend/db-client/integrations/index.ts +44 -0
  31. package/backend/db-client/integrations/links.ts +564 -0
  32. package/backend/db-client/integrations/projector.test.ts +280 -0
  33. package/backend/db-client/integrations/projector.ts +256 -0
  34. package/backend/db-client/integrations/supabase-service.ts +266 -0
  35. package/backend/db-client/providers/neon/adapter.ts +522 -0
  36. package/backend/db-client/providers/neon/api-types.ts +182 -0
  37. package/backend/db-client/providers/neon/client.ts +298 -0
  38. package/backend/db-client/providers/neon/endpoints.test.ts +201 -0
  39. package/backend/db-client/providers/neon/endpoints.ts +314 -0
  40. package/backend/db-client/providers/neon/list.test.ts +181 -0
  41. package/backend/db-client/providers/registry.ts +27 -0
  42. package/backend/db-client/providers/supabase/adapter.ts +523 -0
  43. package/backend/db-client/providers/supabase/api-types.ts +92 -0
  44. package/backend/db-client/providers/supabase/apply-migration.ts +104 -0
  45. package/backend/db-client/providers/supabase/client.ts +259 -0
  46. package/backend/db-client/providers/supabase/features.ts +502 -0
  47. package/backend/db-client/providers/supabase/local.test.ts +78 -0
  48. package/backend/db-client/providers/supabase/local.ts +137 -0
  49. package/backend/db-client/providers/types.ts +194 -0
  50. package/backend/deployments/bindings.test.ts +43 -0
  51. package/backend/deployments/bindings.ts +216 -0
  52. package/backend/deployments/index.ts +53 -0
  53. package/backend/deployments/log-streams.ts +214 -0
  54. package/backend/deployments/prompts.ts +70 -0
  55. package/backend/deployments/providers/vercel/adapter.ts +757 -0
  56. package/backend/deployments/providers/vercel/build-logs.test.ts +80 -0
  57. package/backend/deployments/providers/vercel/build-logs.ts +211 -0
  58. package/backend/deployments/providers/vercel/client.ts +203 -0
  59. package/backend/deployments/providers/vercel/list.test.ts +624 -0
  60. package/backend/deployments/providers/vercel/normalise.test.ts +115 -0
  61. package/backend/deployments/providers/vercel/normalise.ts +113 -0
  62. package/backend/deployments/providers/vercel/types.ts +104 -0
  63. package/backend/deployments/registry.ts +27 -0
  64. package/backend/deployments/service.ts +458 -0
  65. package/backend/deployments/types.ts +278 -0
  66. package/backend/env-files/discovery.ts +48 -0
  67. package/backend/env-files/edit.ts +213 -0
  68. package/backend/env-files/env-files.test.ts +515 -0
  69. package/backend/env-files/git.ts +27 -0
  70. package/backend/env-files/index.ts +44 -0
  71. package/backend/env-files/keys.ts +69 -0
  72. package/backend/env-files/parse.ts +157 -0
  73. package/backend/env-files/write.ts +229 -0
  74. package/backend/index.ts +4 -0
  75. package/backend/integrations/health.ts +18 -4
  76. package/backend/integrations/projections/index.ts +0 -0
  77. package/backend/integrations/projections/mcp-projector.ts +7 -3
  78. package/backend/integrations/projections/types.ts +28 -9
  79. package/backend/integrations/registry/index.ts +8 -1
  80. package/backend/integrations/registry/providers/context7.ts +1 -0
  81. package/backend/integrations/registry/providers/firecrawl.ts +1 -0
  82. package/backend/integrations/registry/providers/github.ts +1 -0
  83. package/backend/integrations/registry/providers/neon.ts +55 -0
  84. package/backend/integrations/registry/providers/supabase.ts +62 -0
  85. package/backend/integrations/registry/providers/vercel.ts +47 -0
  86. package/backend/integrations/registry/types.ts +2 -0
  87. package/backend/mcp/internal/servers/memory-graph/description.ts +3 -3
  88. package/backend/mcp/internal/servers/memory-graph/runner.ts +4 -9
  89. package/backend/mcp/internal/servers/memory-graph/schema.ts +0 -4
  90. package/backend/memory/README.md +57 -34
  91. package/backend/memory/compose.test.ts +3 -3
  92. package/backend/memory/compose.ts +6 -9
  93. package/backend/memory/config.ts +0 -5
  94. package/backend/memory/consolidate.ts +1 -2
  95. package/backend/memory/context.test.ts +8 -54
  96. package/backend/memory/context.ts +19 -25
  97. package/backend/memory/extract/episodic.ts +10 -12
  98. package/backend/memory/extract/index.ts +23 -52
  99. package/backend/memory/extract/scheduler.ts +3 -6
  100. package/backend/memory/index.ts +6 -5
  101. package/backend/memory/invalidate.ts +36 -48
  102. package/backend/memory/layout.ts +319 -130
  103. package/backend/memory/retention.ts +12 -42
  104. package/backend/memory/retrieval.eval.test.ts +2 -2
  105. package/backend/memory/retrieval.test.ts +228 -183
  106. package/backend/memory/retrieval.ts +22 -21
  107. package/backend/memory/revise.test.ts +62 -116
  108. package/backend/memory/revise.ts +0 -1
  109. package/backend/memory/view.ts +8 -5
  110. package/backend/snapshot/helpers.ts +35 -41
  111. package/backend/snapshot/snapshot-service.ts +90 -0
  112. package/backend/snapshot/turn-changes.test.ts +163 -0
  113. package/backend/snapshot/turn-changes.ts +131 -0
  114. package/backend/work/start-work.ts +4 -0
  115. package/backend/worktrees/branching/engine.ts +557 -0
  116. package/backend/worktrees/branching/index.ts +56 -0
  117. package/backend/worktrees/branching/naming.test.ts +118 -0
  118. package/backend/worktrees/branching/naming.ts +97 -0
  119. package/backend/worktrees/branching/projector.test.ts +229 -0
  120. package/backend/worktrees/branching/projector.ts +139 -0
  121. package/backend/worktrees/branching/providers/neon.ts +220 -0
  122. package/backend/worktrees/branching/registry.ts +27 -0
  123. package/backend/worktrees/branching/service.ts +620 -0
  124. package/backend/worktrees/branching/suggest.test.ts +154 -0
  125. package/backend/worktrees/branching/suggest.ts +202 -0
  126. package/backend/worktrees/branching/types.ts +88 -0
  127. package/backend/worktrees/index.ts +7 -0
  128. package/backend/worktrees/service.ts +48 -1
  129. package/backend/ws/db-client/accounts.ts +225 -0
  130. package/backend/ws/db-client/connections.ts +34 -3
  131. package/backend/ws/db-client/context.ts +37 -0
  132. package/backend/ws/db-client/env.ts +142 -0
  133. package/backend/ws/db-client/index.ts +22 -1
  134. package/backend/ws/db-client/supabase.ts +188 -0
  135. package/backend/ws/deployments/actions.ts +360 -0
  136. package/backend/ws/deployments/context.ts +43 -0
  137. package/backend/ws/deployments/crud.ts +152 -0
  138. package/backend/ws/deployments/index.ts +15 -0
  139. package/backend/ws/deployments/schemas.ts +183 -0
  140. package/backend/ws/index.ts +6 -2
  141. package/backend/ws/memory/crud.ts +4 -16
  142. package/backend/ws/projects/index.ts +6 -1
  143. package/backend/ws/projects/info.ts +70 -6
  144. package/backend/ws/projects/overview.test.ts +108 -0
  145. package/backend/ws/projects/overview.ts +300 -0
  146. package/backend/ws/snapshot/changes.ts +279 -0
  147. package/backend/ws/snapshot/index.ts +4 -3
  148. package/backend/ws/system/device-info.ts +307 -76
  149. package/backend/ws/worktrees/branching.ts +212 -0
  150. package/backend/ws/worktrees/crud.ts +33 -7
  151. package/backend/ws/worktrees/index.ts +14 -0
  152. package/dist/assets/{index-DSHIANSy.js → index-D4igjF6e.js} +1 -1
  153. package/dist/assets/{index-CyH7fSbR.js → index-DONNwiXm.js} +1 -1
  154. package/dist/assets/main-BrfXH1bL.js +1205 -0
  155. package/dist/assets/main-CT1PygsW.css +1 -0
  156. package/dist/index.html +2 -2
  157. package/package.json +1 -1
  158. package/shared/constants/tool-icons.ts +13 -0
  159. package/shared/types/db-client/connection.ts +6 -0
  160. package/shared/types/db-client/env.ts +192 -0
  161. package/shared/types/db-client/index.ts +3 -0
  162. package/shared/types/db-client/integrations.ts +204 -0
  163. package/shared/types/db-client/supabase.ts +131 -0
  164. package/shared/types/deployments.ts +382 -0
  165. package/shared/types/integrations.ts +9 -0
  166. package/shared/types/memory.ts +34 -51
  167. package/shared/types/ui/components.ts +1 -1
  168. package/shared/types/worktree-branching.ts +315 -0
  169. package/shared/utils/diff-calculator.test.ts +89 -0
  170. package/shared/utils/diff-calculator.ts +30 -65
  171. package/shared/utils/logger.ts +2 -0
  172. package/backend/memory/extract/languages.ts +0 -176
  173. package/backend/memory/extract/structural.test.ts +0 -215
  174. package/backend/memory/extract/structural.ts +0 -364
  175. package/backend/ws/snapshot/content.ts +0 -85
  176. package/dist/assets/main-D2IOjftb.css +0 -1
  177. package/dist/assets/main-DM-tHKbW.js +0 -1152
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * Memory Graph schema + retrieval tests.
3
3
  *
4
- * These run against a REAL in-memory SQLite database with migration 066 applied,
5
- * rather than a hand-mocked query surface. The interesting behaviour here lives
4
+ * These run against a REAL in-memory SQLite database with migrations 066 and 076
5
+ * applied, rather than a hand-mocked query surface. The interesting behaviour here lives
6
6
  * in the SQL — the COALESCE-based digest uniqueness, the FTS5 mirror, the
7
7
  * cross-project filters — and a mock would assert the test's own idea of that
8
8
  * SQL instead of the database's.
@@ -16,6 +16,7 @@ import { beforeEach, describe, expect, it, mock } from 'bun:test';
16
16
  import { Database } from 'bun:sqlite';
17
17
  import type { DatabaseConnection } from '$shared/types/database/connection';
18
18
  import * as migration066 from '$backend/database/migrations/066_create_memory_graph';
19
+ import * as migration076 from '$backend/database/migrations/076_remove_memory_code_graph';
19
20
 
20
21
  let db: Database;
21
22
 
@@ -44,6 +45,7 @@ function resetDatabase(): void {
44
45
  db = new Database(':memory:');
45
46
  db.exec('PRAGMA foreign_keys = ON');
46
47
  migration066.up(db as unknown as DatabaseConnection);
48
+ migration076.up(db as unknown as DatabaseConnection);
47
49
  }
48
50
 
49
51
  beforeEach(() => {
@@ -53,14 +55,12 @@ beforeEach(() => {
53
55
  describe('graph schema', () => {
54
56
  it('upserts on digest instead of duplicating, and reinforces weight', () => {
55
57
  const first = graphQueries.upsert({
56
- kind: 'episodic',
57
58
  subkind: 'decision',
58
59
  projectId: PROJECT_A,
59
60
  label: 'Engine SDKs install on demand',
60
61
  body: 'They are not bundled into the global install.'
61
62
  });
62
63
  const second = graphQueries.upsert({
63
- kind: 'episodic',
64
64
  subkind: 'decision',
65
65
  projectId: PROJECT_A,
66
66
  label: 'Engine SDKs install on demand',
@@ -104,7 +104,6 @@ describe('graph schema', () => {
104
104
 
105
105
  it('never lets an automatic write overwrite user-authored text', () => {
106
106
  const node = graphQueries.upsert({
107
- kind: 'episodic',
108
107
  subkind: 'decision',
109
108
  projectId: PROJECT_A,
110
109
  label: 'Original label',
@@ -112,7 +111,6 @@ describe('graph schema', () => {
112
111
  });
113
112
 
114
113
  graphQueries.upsert({
115
- kind: 'episodic',
116
114
  subkind: 'decision',
117
115
  projectId: PROJECT_A,
118
116
  label: 'Machine-rewritten label',
@@ -125,7 +123,6 @@ describe('graph schema', () => {
125
123
 
126
124
  it('re-derives the digest after a manual edit so extraction cannot revert it', () => {
127
125
  const node = graphQueries.upsert({
128
- kind: 'episodic',
129
126
  subkind: 'observation',
130
127
  projectId: PROJECT_A,
131
128
  label: 'Snapshots use the file watcher'
@@ -138,7 +135,6 @@ describe('graph schema', () => {
138
135
  // The original claim now hashes to a free digest, so re-extracting it adds a
139
136
  // new node rather than overwriting the correction.
140
137
  graphQueries.upsert({
141
- kind: 'episodic',
142
138
  subkind: 'observation',
143
139
  projectId: PROJECT_A,
144
140
  label: 'Snapshots use the file watcher'
@@ -147,52 +143,53 @@ describe('graph schema', () => {
147
143
  expect(graphQueries.count({ projectId: PROJECT_A })).toBe(2);
148
144
  });
149
145
 
150
- it('gives each dependency its own identity', () => {
151
- // Dependencies carry no path or symbol, so without a name-based fallback they
152
- // all hash to the same digest and each new package overwrites the last.
153
- const lodash = deriveDigest({ kind: 'structural', subkind: 'dependency', label: 'lodash' });
154
- const zod = deriveDigest({ kind: 'structural', subkind: 'dependency', label: 'zod' });
155
- expect(lodash).not.toBe(zod);
156
- });
157
-
158
- it('keeps structural identity tied to path and symbol', () => {
159
- const a = deriveDigest({ kind: 'structural', subkind: 'file', label: 'x', path: 'backend/a.ts' });
160
- const b = deriveDigest({ kind: 'structural', subkind: 'file', label: 'totally different label', path: 'backend/a.ts' });
161
- const c = deriveDigest({ kind: 'structural', subkind: 'file', label: 'x', path: 'backend/b.ts' });
146
+ it('keeps identity in the claim, not in the spelling of it', () => {
147
+ // Whitespace and casing are not a different belief. Without normalising them
148
+ // the same decision, re-extracted, forks into a second node competing with
149
+ // the first for the same recall slot.
150
+ const a = deriveDigest({ subkind: 'decision', label: 'Bun only', body: 'No Node.' });
151
+ const b = deriveDigest({ subkind: 'decision', label: 'BUN ONLY', body: 'no node.' });
152
+ const c = deriveDigest({ subkind: 'decision', label: 'Bun only', body: 'Node is fine.' });
162
153
 
163
154
  expect(a).toBe(b);
164
155
  expect(a).not.toBe(c);
165
156
  });
157
+
158
+ it('separates the subkinds, because a preference is not an observation', () => {
159
+ const preference = deriveDigest({ subkind: 'preference', label: 'Tabs' });
160
+ const observation = deriveDigest({ subkind: 'observation', label: 'Tabs' });
161
+ expect(preference).not.toBe(observation);
162
+ });
166
163
  });
167
164
 
168
165
  describe('graph edges', () => {
169
166
  it('rejects self-loops and strengthens repeated links', () => {
170
- const a = graphQueries.upsert({ kind: 'episodic', subkind: 'decision', projectId: PROJECT_A, label: 'A' });
171
- const b = graphQueries.upsert({ kind: 'structural', subkind: 'file', projectId: PROJECT_A, label: 'b.ts', path: 'b.ts' });
167
+ const a = graphQueries.upsert({ subkind: 'decision', projectId: PROJECT_A, label: 'A' });
168
+ const b = graphQueries.upsert({ subkind: 'observation', projectId: PROJECT_A, label: 'B' });
172
169
 
173
- expect(graphQueries.link({ srcId: a.id, dstId: a.id, rel: 'about' })).toBeNull();
170
+ expect(graphQueries.link({ srcId: a.id, dstId: a.id, rel: 'relates_to' })).toBeNull();
174
171
 
175
- const first = graphQueries.link({ srcId: a.id, dstId: b.id, rel: 'about' })!;
176
- const second = graphQueries.link({ srcId: a.id, dstId: b.id, rel: 'about' })!;
172
+ const first = graphQueries.link({ srcId: a.id, dstId: b.id, rel: 'relates_to' })!;
173
+ const second = graphQueries.link({ srcId: a.id, dstId: b.id, rel: 'relates_to' })!;
177
174
  expect(second.id).toBe(first.id);
178
175
  expect(second.weight).toBeGreaterThan(first.weight);
179
176
  });
180
177
 
181
178
  it('cascades edges when a node is hard-deleted', () => {
182
- const a = graphQueries.upsert({ kind: 'episodic', subkind: 'decision', projectId: PROJECT_A, label: 'A' });
183
- const b = graphQueries.upsert({ kind: 'structural', subkind: 'file', projectId: PROJECT_A, label: 'b.ts', path: 'b.ts' });
184
- graphQueries.link({ srcId: a.id, dstId: b.id, rel: 'about' });
179
+ const a = graphQueries.upsert({ subkind: 'decision', projectId: PROJECT_A, label: 'A' });
180
+ const b = graphQueries.upsert({ subkind: 'observation', projectId: PROJECT_A, label: 'B' });
181
+ graphQueries.link({ srcId: a.id, dstId: b.id, rel: 'relates_to' });
185
182
 
186
183
  graphQueries.remove(b.id);
187
184
  expect(graphQueries.edgesOf(a.id)).toHaveLength(0);
188
185
  });
189
186
 
190
187
  it('walks multiple hops and reports distance', () => {
191
- const a = graphQueries.upsert({ kind: 'episodic', subkind: 'decision', projectId: PROJECT_A, label: 'A' });
192
- const b = graphQueries.upsert({ kind: 'structural', subkind: 'file', projectId: PROJECT_A, label: 'b.ts', path: 'b.ts' });
193
- const c = graphQueries.upsert({ kind: 'structural', subkind: 'file', projectId: PROJECT_A, label: 'c.ts', path: 'c.ts' });
194
- graphQueries.link({ srcId: a.id, dstId: b.id, rel: 'about' });
195
- graphQueries.link({ srcId: b.id, dstId: c.id, rel: 'imports' });
188
+ const a = graphQueries.upsert({ subkind: 'decision', projectId: PROJECT_A, label: 'A' });
189
+ const b = graphQueries.upsert({ subkind: 'observation', projectId: PROJECT_A, label: 'B' });
190
+ const c = graphQueries.upsert({ subkind: 'failure', projectId: PROJECT_A, label: 'C' });
191
+ graphQueries.link({ srcId: a.id, dstId: b.id, rel: 'relates_to' });
192
+ graphQueries.link({ srcId: b.id, dstId: c.id, rel: 'caused_by' });
196
193
 
197
194
  const oneHop = graphQueries.neighbours(a.id, 1);
198
195
  expect(oneHop.map(n => n.node.id)).toEqual([b.id]);
@@ -201,46 +198,129 @@ describe('graph edges', () => {
201
198
  expect(twoHops.find(n => n.node.id === c.id)?.hops).toBe(2);
202
199
  });
203
200
 
204
- it('bridges episodic and structural memory through `about`', () => {
201
+ it('records the files a memory is about as an attribute, not a node', () => {
202
+ // The one thing the code half was still doing, and the whole reason migration
203
+ // 076 could remove it: a memory names the code it concerns, and nothing has
204
+ // to exist on the other end of an edge for that to be true.
205
205
  const decision = graphQueries.upsert({
206
- kind: 'episodic',
207
206
  subkind: 'decision',
208
207
  projectId: PROJECT_A,
209
208
  label: 'Credentials are read from the database, never from env vars'
210
209
  });
211
- const file = graphQueries.upsert({
212
- kind: 'structural',
213
- subkind: 'file',
214
- projectId: PROJECT_A,
215
- label: 'engine-queries.ts',
216
- path: 'backend/database/queries/engine-queries.ts'
217
- });
218
- graphQueries.link({ srcId: decision.id, dstId: file.id, rel: 'about' });
210
+ graphQueries.setPaths(decision.id, ['backend/database/queries/engine-queries.ts']);
211
+
212
+ expect(graphQueries.pathsOf(decision.id)).toEqual([
213
+ 'backend/database/queries/engine-queries.ts'
214
+ ]);
215
+ // Arriving from the code reaches the decision made about it.
216
+ expect(
217
+ graphQueries
218
+ .nodesForPaths(PROJECT_A, ['backend/database/queries/engine-queries.ts'])
219
+ .map(n => n.id)
220
+ ).toContain(decision.id);
221
+ // And no node was created to stand in for the file.
222
+ expect(graphQueries.count({ projectId: PROJECT_A })).toBe(1);
223
+ });
224
+
225
+ it('normalizes a path however it was spelled', () => {
226
+ // They arrive from a model, from a disk diff and from Windows. Three
227
+ // spellings of one file would be three keys, and invalidation would miss two.
228
+ const note = graphQueries.upsert({ subkind: 'observation', projectId: PROJECT_A, label: 'N' });
229
+ graphQueries.setPaths(note.id, ['./backend/a.ts', 'backend\\a.ts', '/backend/a.ts']);
230
+
231
+ expect(graphQueries.pathsOf(note.id)).toEqual(['backend/a.ts']);
232
+ });
233
+
234
+ it('damps a subject shared by much of the graph instead of dropping it', () => {
235
+ // This used to assert the opposite, and the reversal is the point. Dropping
236
+ // any group over two dozen sounded like it was excluding "a word everyone
237
+ // uses"; measured on a real store it excluded `Clopen` (496 memories),
238
+ // `Arga` (299) and `wpuploader` (131) — the product names that are the most
239
+ // meaningful lobes the picture could have — and left 62% of the graph as
240
+ // isolated dots. The concern was right but the lever was wrong: a broad
241
+ // subject says LESS about any two of its members, which is a weight, not a
242
+ // veto.
243
+ const ids: string[] = [];
244
+ for (let i = 0; i < 30; i++) {
245
+ const node = graphQueries.upsert({ subkind: 'observation', projectId: PROJECT_A, label: `Note ${i}` });
246
+ graphQueries.setEntities(node.id, [{ key: 'typescript', name: 'TypeScript' }]);
247
+ ids.push(node.id);
248
+ }
249
+
250
+ const subject = graphQueries.derivedEdges(ids).filter(e => e.via === 'subject');
251
+ expect(subject.length).toBeGreaterThan(0);
252
+ // Weaker than a small group's, which is what Louvain reads.
253
+ for (const edge of subject) expect(edge.weight).toBeLessThan(1);
254
+
255
+ // And still bounded: a thirty-member subject is not a 435-edge clique.
256
+ const degree = new Map<string, number>();
257
+ for (const edge of subject) {
258
+ degree.set(edge.srcId, (degree.get(edge.srcId) ?? 0) + 1);
259
+ degree.set(edge.dstId, (degree.get(edge.dstId) ?? 0) + 1);
260
+ }
261
+ expect(Math.max(...degree.values())).toBeLessThanOrEqual(6);
262
+ });
263
+
264
+ it('connects two memories that claim something about the same file', () => {
265
+ // What the code half provided by accident: two memories about `retrieval.ts`
266
+ // used to be joined through the file NODE between them. Migration 076 kept
267
+ // the attribution and dropped the connection, which left 985 of one real
268
+ // graph's memories sharing a file with nobody to show for it.
269
+ const a = graphQueries.upsert({ subkind: 'observation', projectId: PROJECT_A, label: 'Retrieval fuses two channels with RRF' });
270
+ const b = graphQueries.upsert({ subkind: 'decision', projectId: PROJECT_A, label: 'The vector channel was made precise for the search box' });
271
+ const elsewhere = graphQueries.upsert({ subkind: 'observation', projectId: PROJECT_A, label: 'Unrelated note' });
272
+ graphQueries.setPaths(a.id, ['backend/memory/retrieval.ts']);
273
+ graphQueries.setPaths(b.id, ['backend/memory/retrieval.ts']);
274
+ graphQueries.setPaths(elsewhere.id, ['frontend/app.ts']);
275
+
276
+ const viaPath = graphQueries.derivedEdges([a.id, b.id, elsewhere.id]).filter(e => e.via === 'path');
277
+ expect(viaPath.some(e => [e.srcId, e.dstId].includes(a.id) && [e.srcId, e.dstId].includes(b.id))).toBe(true);
278
+ expect(viaPath.some(e => [e.srcId, e.dstId].includes(elsewhere.id))).toBe(false);
279
+
280
+ // Derived, not stored: nothing was written that could outlive the claim.
281
+ expect(graphQueries.edgesOf(a.id)).toHaveLength(0);
282
+ });
283
+
284
+ it('reaches a memory about the same file in one traversal hop', () => {
285
+ // The recall half of the same loss. Before 076 a question that matched one
286
+ // memory about a file could reach the others in two hops, through the file
287
+ // node; without this it could not reach them at all.
288
+ const a = graphQueries.upsert({ subkind: 'observation', projectId: PROJECT_A, label: 'First note about the stream manager' });
289
+ const b = graphQueries.upsert({ subkind: 'failure', projectId: PROJECT_A, label: 'Second note, worded nothing like the first' });
290
+ graphQueries.setPaths(a.id, ['backend/chat/stream-manager.ts']);
291
+ graphQueries.setPaths(b.id, ['backend/chat/stream-manager.ts']);
219
292
 
220
- // Arriving from the code should reach the decision made about it.
221
- const fromCode = graphQueries.neighbours(file.id, 1);
222
- expect(fromCode.map(n => n.node.id)).toContain(decision.id);
293
+ expect(graphQueries.pathNeighbourIds(a.id)).toContain(b.id);
294
+ expect(graphQueries.neighbours(a.id, 1).map(n => n.node.id)).toContain(b.id);
295
+ });
296
+
297
+ it('replaces the paths on a memory rather than accumulating them', () => {
298
+ // Extraction re-reads the same memory whenever it is reinforced, and a later
299
+ // reading is a better one. Appending would keep every path an abandoned
300
+ // approach ever touched.
301
+ const note = graphQueries.upsert({ subkind: 'observation', projectId: PROJECT_A, label: 'N' });
302
+ graphQueries.setPaths(note.id, ['backend/old.ts']);
303
+ graphQueries.setPaths(note.id, ['backend/new.ts']);
304
+
305
+ expect(graphQueries.pathsOf(note.id)).toEqual(['backend/new.ts']);
223
306
  });
224
307
  });
225
308
 
226
309
  describe('lexical retrieval', () => {
227
310
  beforeEach(() => {
228
311
  graphQueries.upsert({
229
- kind: 'episodic',
230
312
  subkind: 'failure',
231
313
  projectId: PROJECT_A,
232
314
  label: 'Codex exits with code 1 when its home directory is missing',
233
315
  body: 'getCodexHomeDir now creates the directory on access.'
234
316
  });
235
- graphQueries.upsert({
236
- kind: 'structural',
237
- subkind: 'file',
317
+ const loader = graphQueries.upsert({
318
+ subkind: 'pattern',
238
319
  projectId: PROJECT_A,
239
- label: 'sdk-loader.ts',
240
- path: 'backend/engine/sdk-loader.ts'
320
+ label: 'Engine SDKs are resolved lazily, one module per engine'
241
321
  });
322
+ graphQueries.setPaths(loader.id, ['backend/engine/sdk-loader.ts']);
242
323
  graphQueries.upsert({
243
- kind: 'episodic',
244
324
  subkind: 'decision',
245
325
  projectId: PROJECT_B,
246
326
  label: 'Preview capture uses fitScale times device pixel ratio'
@@ -253,13 +333,15 @@ describe('lexical retrieval', () => {
253
333
  });
254
334
 
255
335
  it('matches a path fragment, because paths are indexed split as well as whole', () => {
336
+ // The paths a memory names are joined into its own indexed text (see
337
+ // `indexedText`). Without that, removing the file nodes would have made a
338
+ // pasted path match nothing at all.
256
339
  const result = retrieve({ query: 'sdk loader', projectId: PROJECT_A, expandHops: 0 });
257
- expect(result.hits.map(h => h.node.path)).toContain('backend/engine/sdk-loader.ts');
340
+ expect(result.hits[0].node.label).toContain('Engine SDKs are resolved lazily');
258
341
  });
259
342
 
260
343
  it('scopes results to one project but still admits global memories', () => {
261
344
  graphQueries.upsert({
262
- kind: 'episodic',
263
345
  subkind: 'preference',
264
346
  scope: 'global',
265
347
  projectId: null,
@@ -285,7 +367,6 @@ describe('lexical retrieval', () => {
285
367
 
286
368
  it('drops archived nodes from the index and restores them on demand', () => {
287
369
  const node = graphQueries.upsert({
288
- kind: 'episodic',
289
370
  subkind: 'observation',
290
371
  projectId: PROJECT_A,
291
372
  label: 'Zstd compresses large WebSocket responses'
@@ -301,25 +382,26 @@ describe('lexical retrieval', () => {
301
382
 
302
383
  describe('graph expansion', () => {
303
384
  it('surfaces a neighbour of a match that the query itself never mentions', () => {
304
- const file = graphQueries.upsert({
305
- kind: 'structural',
306
- subkind: 'file',
385
+ // Expansion travels the structure that is left: memories about the same
386
+ // subject are neighbours, without an edge in the table. The neighbour shares
387
+ // no token with the query, so only the hop can reach it.
388
+ const match = graphQueries.upsert({
389
+ subkind: 'observation',
307
390
  projectId: PROJECT_A,
308
- label: 'snapshot-service.ts',
309
- path: 'backend/snapshot/snapshot-service.ts'
391
+ label: 'Snapshot capture reads from disk'
310
392
  });
311
393
  const decision = graphQueries.upsert({
312
- kind: 'episodic',
313
394
  subkind: 'decision',
314
395
  projectId: PROJECT_A,
315
- label: 'The disk is the source of truth, not the watcher dirty set'
396
+ label: 'A working tree beats any watcher dirty set'
316
397
  });
317
- graphQueries.link({ srcId: decision.id, dstId: file.id, rel: 'about' });
398
+ graphQueries.setEntities(match.id, [{ key: 'zeta', name: 'Zeta' }]);
399
+ graphQueries.setEntities(decision.id, [{ key: 'zeta', name: 'Zeta' }]);
318
400
 
319
- const direct = retrieve({ query: 'snapshot-service', projectId: PROJECT_A, expandHops: 0 });
401
+ const direct = retrieve({ query: 'snapshot capture reads', projectId: PROJECT_A, expandHops: 0 });
320
402
  expect(direct.hits.map(h => h.node.id)).not.toContain(decision.id);
321
403
 
322
- const expanded = retrieve({ query: 'snapshot-service', projectId: PROJECT_A, expandHops: 1 });
404
+ const expanded = retrieve({ query: 'snapshot capture reads', projectId: PROJECT_A, expandHops: 1 });
323
405
  const hit = expanded.hits.find(h => h.node.id === decision.id);
324
406
  expect(hit).toBeDefined();
325
407
  expect(hit!.channel).toBe('graph');
@@ -327,36 +409,32 @@ describe('graph expansion', () => {
327
409
  });
328
410
 
329
411
  it('ranks an expanded neighbour below the direct match that produced it', () => {
330
- const file = graphQueries.upsert({
331
- kind: 'structural',
332
- subkind: 'file',
412
+ const match = graphQueries.upsert({
413
+ subkind: 'pattern',
333
414
  projectId: PROJECT_A,
334
- label: 'stream-manager.ts',
335
- path: 'backend/chat/stream-manager.ts'
415
+ label: 'The stream manager owns every engine turn'
336
416
  });
337
417
  const note = graphQueries.upsert({
338
- kind: 'episodic',
339
418
  subkind: 'observation',
340
419
  projectId: PROJECT_A,
341
420
  label: 'Unrelated wording entirely'
342
421
  });
343
- graphQueries.link({ srcId: note.id, dstId: file.id, rel: 'about' });
422
+ graphQueries.setEntities(match.id, [{ key: 'streams', name: 'Streams' }]);
423
+ graphQueries.setEntities(note.id, [{ key: 'streams', name: 'Streams' }]);
344
424
 
345
- const result = retrieve({ query: 'stream-manager', projectId: PROJECT_A, expandHops: 1 });
346
- expect(result.hits[0].node.id).toBe(file.id);
425
+ const result = retrieve({ query: 'stream manager engine turn', projectId: PROJECT_A, expandHops: 1 });
426
+ expect(result.hits[0].node.id).toBe(match.id);
347
427
  });
348
428
  });
349
429
 
350
430
  describe('ranking priors', () => {
351
431
  it('prefers a pinned memory over an equally-matching unpinned one', () => {
352
432
  graphQueries.upsert({
353
- kind: 'episodic',
354
433
  subkind: 'decision',
355
434
  projectId: PROJECT_A,
356
435
  label: 'Compression applies to websocket responses'
357
436
  });
358
437
  const pinned = graphQueries.upsert({
359
- kind: 'episodic',
360
438
  subkind: 'decision',
361
439
  projectId: PROJECT_A,
362
440
  label: 'Compression applies to websocket payloads',
@@ -376,7 +454,6 @@ describe('ranking priors', () => {
376
454
  */
377
455
  it('does not count an access merely for retrieving a node', () => {
378
456
  const node = graphQueries.upsert({
379
- kind: 'episodic',
380
457
  subkind: 'decision',
381
458
  projectId: PROJECT_A,
382
459
  label: 'Cursor pagination replaced full chain loading'
@@ -388,7 +465,6 @@ describe('ranking priors', () => {
388
465
 
389
466
  it('counts an access when a caller says the result was consulted', () => {
390
467
  const node = graphQueries.upsert({
391
- kind: 'episodic',
392
468
  subkind: 'decision',
393
469
  projectId: PROJECT_A,
394
470
  label: 'Cursor pagination replaced full chain loading'
@@ -407,19 +483,16 @@ describeIfEmbedding('vector retrieval', () => {
407
483
  await embedder.load();
408
484
 
409
485
  const target = graphQueries.upsert({
410
- kind: 'episodic',
411
486
  subkind: 'failure',
412
487
  projectId: PROJECT_A,
413
488
  label: 'The browser preview stayed stuck on Loading because early ICE candidates were not buffered'
414
489
  });
415
490
  graphQueries.upsert({
416
- kind: 'episodic',
417
491
  subkind: 'pattern',
418
492
  projectId: PROJECT_A,
419
493
  label: 'Svelte runes are used for state management across the frontend'
420
494
  });
421
495
  graphQueries.upsert({
422
- kind: 'episodic',
423
496
  subkind: 'observation',
424
497
  projectId: PROJECT_A,
425
498
  label: 'SQLite migrations are numbered sequentially and seeders run after them'
@@ -442,7 +515,6 @@ describeIfEmbedding('vector retrieval', () => {
442
515
  await embedder.load();
443
516
 
444
517
  const target = graphQueries.upsert({
445
- kind: 'episodic',
446
518
  subkind: 'decision',
447
519
  projectId: PROJECT_A,
448
520
  label: 'Permissions are enforced by a runtime hook because Clopen auto approves everything'
@@ -452,7 +524,6 @@ describeIfEmbedding('vector retrieval', () => {
452
524
  // static embeddings put short texts closer together than their meanings do.
453
525
  // A vector-only retriever would answer wrongly here.
454
526
  graphQueries.upsert({
455
- kind: 'episodic',
456
527
  subkind: 'observation',
457
528
  projectId: PROJECT_A,
458
529
  label: 'The git panel actions stay visible regardless of repository state'
@@ -480,11 +551,10 @@ describeIfEmbedding('vector retrieval', () => {
480
551
  'Arga is a full-stack developer working in the JavaScript and TypeScript ecosystem',
481
552
  'Arga is a full-stack developer with five years of experience based in Indonesia',
482
553
  'Arga is the user of this workspace: a JavaScript and TypeScript full-stack developer'
483
- ].map(label => graphQueries.upsert({ kind: 'episodic', subkind: 'entity', projectId: PROJECT_A, label }));
554
+ ].map(label => graphQueries.upsert({ subkind: 'entity', projectId: PROJECT_A, label }));
484
555
  for (const node of arga) graphQueries.setEntities(node.id, [{ key: 'arga', name: 'Arga' }]);
485
556
 
486
557
  const unrelated = graphQueries.upsert({
487
- kind: 'episodic',
488
558
  subkind: 'observation',
489
559
  projectId: PROJECT_A,
490
560
  label: 'Zstd compression is applied to large WebSocket responses'
@@ -500,9 +570,9 @@ describeIfEmbedding('vector retrieval', () => {
500
570
  // the view a field of disconnected dots. What was wrong with those edges was
501
571
  // that COSINE chose them — two memories are related when they are about the
502
572
  // same THING, which extraction already records.
503
- const a = graphQueries.upsert({ kind: 'episodic', subkind: 'observation', projectId: PROJECT_A, label: 'TunnelKit exposes three tunnel modes' });
504
- const b = graphQueries.upsert({ kind: 'episodic', subkind: 'decision', projectId: PROJECT_A, label: 'TunnelKit was extracted into its own library' });
505
- const unrelated = graphQueries.upsert({ kind: 'episodic', subkind: 'observation', projectId: 'project-z', label: 'Something else entirely' });
573
+ const a = graphQueries.upsert({ subkind: 'observation', projectId: PROJECT_A, label: 'TunnelKit exposes three tunnel modes' });
574
+ const b = graphQueries.upsert({ subkind: 'decision', projectId: PROJECT_A, label: 'TunnelKit was extracted into its own library' });
575
+ const unrelated = graphQueries.upsert({ subkind: 'observation', projectId: 'project-z', label: 'Something else entirely' });
506
576
  graphQueries.setEntities(a.id, [{ key: 'tunnelkit', name: 'TunnelKit' }]);
507
577
  graphQueries.setEntities(b.id, [{ key: 'tunnelkit', name: 'TunnelKit' }]);
508
578
 
@@ -514,27 +584,14 @@ describeIfEmbedding('vector retrieval', () => {
514
584
  });
515
585
 
516
586
  it('reaches a memory about the same subject in one traversal hop', () => {
517
- const a = graphQueries.upsert({ kind: 'episodic', subkind: 'observation', projectId: PROJECT_A, label: 'First note about the subject' });
518
- const b = graphQueries.upsert({ kind: 'episodic', subkind: 'observation', projectId: PROJECT_A, label: 'Second note about the subject' });
587
+ const a = graphQueries.upsert({ subkind: 'observation', projectId: PROJECT_A, label: 'First note about the subject' });
588
+ const b = graphQueries.upsert({ subkind: 'observation', projectId: PROJECT_A, label: 'Second note about the subject' });
519
589
  graphQueries.setEntities(a.id, [{ key: 'ptykit', name: 'PtyKit' }]);
520
590
  graphQueries.setEntities(b.id, [{ key: 'ptykit', name: 'PtyKit' }]);
521
591
 
522
592
  expect(graphQueries.neighbours(a.id, 1).map(n => n.node.id)).toContain(b.id);
523
593
  });
524
594
 
525
- it('does not connect a subject shared by too much of the graph', () => {
526
- // A word everyone uses is not a relationship. Connecting forty memories
527
- // through "TypeScript" would recreate the fabricated structure that
528
- // similarity linking produced, from a different cause.
529
- const ids: string[] = [];
530
- for (let i = 0; i < 30; i++) {
531
- const node = graphQueries.upsert({ kind: 'episodic', subkind: 'observation', projectId: PROJECT_A, label: `Note ${i}` });
532
- graphQueries.setEntities(node.id, [{ key: 'typescript', name: 'TypeScript' }]);
533
- ids.push(node.id);
534
- }
535
- expect(graphQueries.derivedEdges(ids).some(e => e.via === 'subject')).toBe(false);
536
- });
537
-
538
595
  it('never invents an edge between two memories', async () => {
539
596
  await embedder.load();
540
597
 
@@ -546,7 +603,7 @@ describeIfEmbedding('vector retrieval', () => {
546
603
  'ChatKit runs on Node.js 18 and Bun with its design tokens kept local',
547
604
  'CommonForms Detection Service is a FastAPI PDF pipeline',
548
605
  'Programmer Finder uses Flutter for the app and Elixir for the API'
549
- ].map(label => graphQueries.upsert({ kind: 'episodic', subkind: 'observation', projectId: PROJECT_A, label }));
606
+ ].map(label => graphQueries.upsert({ subkind: 'observation', projectId: PROJECT_A, label }));
550
607
 
551
608
  for (const node of nodes) {
552
609
  expect(graphQueries.edgesOf(node.id).filter(e => e.rel === 'relates_to')).toHaveLength(0);
@@ -557,7 +614,6 @@ describeIfEmbedding('vector retrieval', () => {
557
614
  await embedder.load();
558
615
 
559
616
  graphQueries.upsert({
560
- kind: 'episodic',
561
617
  subkind: 'decision',
562
618
  projectId: PROJECT_A,
563
619
  label: 'Engine SDKs are installed on demand into the managed stack directory'
@@ -609,58 +665,48 @@ describe('graph expansion', () => {
609
665
  /**
610
666
  * Edges deliberately cross project boundaries — that is what lets a pattern
611
667
  * proven in one repository be reused in another. Traversal therefore has to
612
- * re-apply the scope filter, or one hop from a shared dependency node reaches
613
- * another project's files and, through them, another project's memories — into a
614
- * block that is about to be injected into THIS project's prompt.
668
+ * re-apply the scope filter, or one hop from a memory about a shared subject
669
+ * reaches another project's memories — into a block that is about to be
670
+ * injected into THIS project's prompt.
615
671
  */
616
672
  it('does not cross into another project through a shared node', () => {
617
- const shared = graphQueries.upsert({
618
- kind: 'structural',
619
- subkind: 'dependency',
620
- scope: 'global',
621
- projectId: null,
622
- label: 'zod'
623
- });
624
673
  const mine = graphQueries.upsert({
625
- kind: 'structural',
626
- subkind: 'file',
674
+ subkind: 'pattern',
627
675
  projectId: PROJECT_A,
628
- label: 'mine.ts',
629
- path: 'mine.ts'
676
+ label: 'Every boundary here is validated with zod'
630
677
  });
631
678
  const theirs = graphQueries.upsert({
632
- kind: 'episodic',
633
679
  subkind: 'decision',
634
680
  projectId: PROJECT_B,
635
681
  label: 'Another team decided to validate every boundary with zod'
636
682
  });
637
- graphQueries.link({ srcId: mine.id, dstId: shared.id, rel: 'imports' });
638
- graphQueries.link({ srcId: theirs.id, dstId: shared.id, rel: 'about' });
683
+ // The bridge that WOULD carry the hop, if the filter did not re-apply.
684
+ graphQueries.setEntities(mine.id, [{ key: 'zod', name: 'Zod' }]);
685
+ graphQueries.setEntities(theirs.id, [{ key: 'zod', name: 'Zod' }]);
639
686
 
640
687
  const hits = retrieve({ query: 'zod', projectId: PROJECT_A, expandHops: 2 }).hits;
688
+ expect(hits.map(h => h.node.id)).toContain(mine.id);
641
689
  expect(hits.map(h => h.node.id)).not.toContain(theirs.id);
642
690
  });
643
691
 
644
692
  it('does not leak another session\'s private memories', () => {
645
693
  const shared = graphQueries.upsert({
646
- kind: 'structural',
647
- subkind: 'file',
694
+ subkind: 'observation',
648
695
  projectId: PROJECT_A,
649
- label: 'shared.ts',
650
- path: 'shared.ts'
696
+ label: 'The shared queue is drained on a timer'
651
697
  });
652
698
  const priv = graphQueries.upsert({
653
- kind: 'episodic',
654
699
  subkind: 'observation',
655
700
  scope: 'session',
656
701
  projectId: PROJECT_A,
657
702
  sessionId: 'other-session',
658
703
  label: 'Private to another conversation entirely'
659
704
  });
660
- graphQueries.link({ srcId: priv.id, dstId: shared.id, rel: 'about' });
705
+ graphQueries.setEntities(shared.id, [{ key: 'queue', name: 'Queue' }]);
706
+ graphQueries.setEntities(priv.id, [{ key: 'queue', name: 'Queue' }]);
661
707
 
662
708
  const hits = retrieve({
663
- query: 'shared.ts',
709
+ query: 'shared queue drained',
664
710
  projectId: PROJECT_A,
665
711
  sessionId: 'my-session',
666
712
  expandHops: 2
@@ -670,59 +716,72 @@ describe('graph expansion', () => {
670
716
 
671
717
  it('reaches a memory through the file the turn is working in', () => {
672
718
  // The "continue" case: the query says nothing, the working set says plenty.
673
- const target = graphQueries.upsert({
674
- kind: 'structural',
675
- subkind: 'file',
676
- projectId: PROJECT_A,
677
- label: 'auth.ts',
678
- path: 'backend/auth.ts'
679
- });
719
+ // The seed IS the memory now — it used to be the file node, which then spent
720
+ // a hop of expansion crossing an `about` edge to get here.
680
721
  const lesson = graphQueries.upsert({
681
- kind: 'episodic',
682
722
  subkind: 'failure',
683
723
  projectId: PROJECT_A,
684
724
  label: 'Rotating the signing key without a grace period logged everyone out'
685
725
  });
686
- graphQueries.link({ srcId: lesson.id, dstId: target.id, rel: 'about' });
726
+ graphQueries.setPaths(lesson.id, ['backend/auth.ts']);
687
727
 
688
728
  const hits = retrieve({
689
729
  query: 'lanjutkan',
690
730
  projectId: PROJECT_A,
691
731
  anchorPaths: ['backend/auth.ts'],
692
- expandHops: 1
732
+ expandHops: 0
693
733
  }).hits;
694
734
  expect(hits.map(h => h.node.id)).toContain(lesson.id);
695
735
  });
696
736
 
697
- it('does not let a hub node drown the result in its neighbours', () => {
698
- // Activation is divided by the neighbour count, so a forty-edge hub passes
699
- // almost nothing to any one of them. A flat per-hop bonus — what a plain BFS
700
- // expansion gives — has exactly the opposite behaviour.
701
- const hub = graphQueries.upsert({
702
- kind: 'structural',
703
- subkind: 'file',
704
- projectId: PROJECT_A,
705
- label: 'hub.ts',
706
- path: 'hub.ts'
737
+ it('does not anchor on a path another project claimed', () => {
738
+ // `nodesForPaths` is project-scoped, unlike the invalidation lookup: a memory
739
+ // about `src/index.ts` in another repository says nothing about this one.
740
+ const theirs = graphQueries.upsert({
741
+ subkind: 'observation',
742
+ projectId: PROJECT_B,
743
+ label: 'Their entry point re-exports everything'
707
744
  });
745
+ graphQueries.setPaths(theirs.id, ['src/index.ts']);
746
+
747
+ const hits = retrieve({
748
+ query: 'lanjutkan',
749
+ projectId: PROJECT_A,
750
+ anchorPaths: ['src/index.ts'],
751
+ expandHops: 0
752
+ }).hits;
753
+ expect(hits.map(h => h.node.id)).not.toContain(theirs.id);
754
+ });
755
+
756
+ it('does not let a hub drown the result in its neighbours', () => {
757
+ // Activation is divided by the neighbour count, so a thirty-member subject
758
+ // passes almost nothing to any one of them. A flat per-hop bonus — what a
759
+ // plain BFS expansion gives — has exactly the opposite behaviour.
760
+ //
761
+ // The subject's NAME is deliberately nothing the query says: entity names are
762
+ // joined into each memory's indexed text, so naming it "Barrel" would have
763
+ // every leaf matching "barrel" lexically and the hop would not be what was
764
+ // under test.
708
765
  const direct = graphQueries.upsert({
709
- kind: 'episodic',
710
766
  subkind: 'decision',
711
767
  projectId: PROJECT_A,
712
- label: 'hub.ts is the shared barrel export for the module'
768
+ label: 'The barrel export is the only public surface here'
713
769
  });
714
- graphQueries.link({ srcId: direct.id, dstId: hub.id, rel: 'about' });
770
+ graphQueries.setEntities(direct.id, [{ key: 'zeta', name: 'Zeta' }]);
715
771
  for (let i = 0; i < 30; i++) {
716
772
  const leaf = graphQueries.upsert({
717
- kind: 'episodic',
718
773
  subkind: 'observation',
719
774
  projectId: PROJECT_A,
720
775
  label: `Unrelated note number ${i} about nothing in particular`
721
776
  });
722
- graphQueries.link({ srcId: leaf.id, dstId: hub.id, rel: 'about' });
777
+ graphQueries.setEntities(leaf.id, [{ key: 'zeta', name: 'Zeta' }]);
723
778
  }
724
779
 
725
- const hits = retrieve({ query: 'hub.ts barrel export', projectId: PROJECT_A, expandHops: 1 }).hits;
780
+ const hits = retrieve({
781
+ query: 'barrel export public surface',
782
+ projectId: PROJECT_A,
783
+ expandHops: 1
784
+ }).hits;
726
785
  expect(hits[0].node.id).toBe(direct.id);
727
786
  });
728
787
  });
@@ -755,7 +814,6 @@ describe('lexical query building', () => {
755
814
  describe('multi-project scoping', () => {
756
815
  function memoryIn(projectId: string | null, label: string) {
757
816
  return graphQueries.upsert({
758
- kind: 'episodic',
759
817
  subkind: 'decision',
760
818
  scope: projectId ? 'project' : 'global',
761
819
  projectId,
@@ -798,20 +856,13 @@ describe('multi-project scoping', () => {
798
856
  });
799
857
 
800
858
  it('keeps expansion inside the selection', () => {
801
- // Edges deliberately cross projects, so one hop from a shared dependency used
802
- // to reach another project's files and, through them, another project's
803
- // memories — into a block about to be injected into this project's prompt.
859
+ // Edges and shared subjects deliberately cross projects, so one hop used to
860
+ // reach another project's memories — into a block about to be injected into
861
+ // this project's prompt.
804
862
  const mine = memoryIn(PROJECT_A, 'Uses the shared queue distinctivetoken');
805
863
  const theirs = memoryIn('project-c', 'Also uses the shared queue');
806
- const shared = graphQueries.upsert({
807
- kind: 'structural',
808
- subkind: 'dependency',
809
- scope: 'global',
810
- projectId: null,
811
- label: 'shared-queue'
812
- });
813
- graphQueries.link({ srcId: mine.id, dstId: shared.id, rel: 'about' });
814
- graphQueries.link({ srcId: theirs.id, dstId: shared.id, rel: 'about' });
864
+ graphQueries.setEntities(mine.id, [{ key: 'sharedqueue', name: 'Shared queue' }]);
865
+ graphQueries.setEntities(theirs.id, [{ key: 'sharedqueue', name: 'Shared queue' }]);
815
866
 
816
867
  const ids = retrieve({
817
868
  query: 'distinctivetoken',
@@ -835,7 +886,6 @@ describe('memory that crosses projects', () => {
835
886
  */
836
887
  function travelling(projectId: string, label: string, body = '') {
837
888
  return graphQueries.upsert({
838
- kind: 'episodic',
839
889
  subkind: 'pattern',
840
890
  scope: 'project',
841
891
  projectId,
@@ -848,7 +898,6 @@ describe('memory that crosses projects', () => {
848
898
 
849
899
  function local(projectId: string, label: string, body = '') {
850
900
  return graphQueries.upsert({
851
- kind: 'episodic',
852
901
  subkind: 'decision',
853
902
  scope: 'project',
854
903
  projectId,
@@ -894,18 +943,15 @@ describe('memory that crosses projects', () => {
894
943
  expect(ids).not.toContain(theirs.id);
895
944
  });
896
945
 
897
- it('never lets another project\'s files travel', () => {
898
- // `reach` is forced to `here` for structural nodes on insert, so a path from
899
- // another repository cannot arrive however the caller asks. This is the leak
900
- // the blanket project filter was originally added to stop, kept.
901
- graphQueries.upsert({
902
- kind: 'structural',
903
- subkind: 'file',
946
+ it('never lets a memory travel unless it was judged to', () => {
947
+ // `reach` is the only thing that admits another repository's memory here, and
948
+ // it defaults to `here`. This is the leak the blanket project filter was
949
+ // originally added to stop, kept after the filter was relaxed.
950
+ const local = graphQueries.upsert({
951
+ subkind: 'observation',
904
952
  scope: 'project',
905
953
  projectId: 'project-b',
906
- label: 'packages/distinctivemodule/index.ts',
907
- path: 'packages/distinctivemodule/index.ts',
908
- reach: 'anywhere'
954
+ label: 'The distinctivemodule package is vendored in this repository'
909
955
  });
910
956
 
911
957
  const hits = retrieve({
@@ -915,7 +961,7 @@ describe('memory that crosses projects', () => {
915
961
  expandHops: 1
916
962
  }).hits;
917
963
 
918
- expect(hits.filter(hit => hit.node.kind === 'structural')).toHaveLength(0);
964
+ expect(hits.map(hit => hit.node.id)).not.toContain(local.id);
919
965
  });
920
966
 
921
967
  it('ranks a local memory above an equally-matching travelled one', () => {
@@ -953,7 +999,6 @@ describe('conflicting memories', () => {
953
999
  */
954
1000
  function preference(label: string, overrides: Record<string, unknown> = {}) {
955
1001
  return graphQueries.upsert({
956
- kind: 'episodic',
957
1002
  subkind: 'preference',
958
1003
  scope: 'global',
959
1004
  projectId: null,