@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
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Supabase — the first provider behind the `database` capability.
3
+ *
4
+ * ONE CREDENTIAL FIELD, for the reason Vercel has one. A personal access token
5
+ * reaches every project in every organisation its user belongs to, so "which
6
+ * project" is not a property of the credential — it is a choice, made as many
7
+ * times as the user has databases worth opening. Those choices live in
8
+ * `integration_db_links`, and each one projects a `db_client_connections` row.
9
+ *
10
+ * SCOPED TOKENS are the thing to know about this provider. Supabase is rolling
11
+ * out personal access tokens that carry only the permissions you pick, and they
12
+ * are prefixed `sbp_fc` where a classic full-access token is plain `sbp_`. A
13
+ * scoped token that is missing a permission fails with an undecorated
14
+ * "Forbidden" at the moment the feature is reached, so the client reads that
15
+ * prefix and says which scope is likely absent — the same trick `Task 2` used on
16
+ * GitHub's fine-grained token prefix, and for the same reason.
17
+ *
18
+ * The DATABASE PASSWORD is deliberately not a credential field here. It is not
19
+ * a property of the account either: every project has its own, and no API can
20
+ * read any of them back. It belongs to the link, which is where it is stored.
21
+ *
22
+ * NO `agent-tools`, even though Supabase ships an MCP server that takes exactly
23
+ * this token. That server is scoped with `--project-ref` to ONE project, and an
24
+ * account here can hold several — so there is no honest single row to project.
25
+ * A user who wants those tools installs the server from the MCP registry, which
26
+ * the hub still offers; the day this becomes a per-link capability rather than a
27
+ * per-account one it can be revisited.
28
+ *
29
+ * NO `inbound-events`. Supabase's webhooks are database triggers rather than a
30
+ * signed platform delivery, and `Task 7` is the first entry with a subscriber
31
+ * worth registering one for.
32
+ */
33
+
34
+ import { defineProvider } from '../define';
35
+
36
+ export default defineProvider({
37
+ id: 'supabase',
38
+ name: 'Supabase',
39
+ category: 'database',
40
+ description:
41
+ 'Postgres projects as connections in DB Client, with the Supabase surface on top: migrations and what is still pending, RLS policies and the security advisor, edge functions, storage buckets, auth users, and generated TypeScript types written into the project.',
42
+ docsUrl: 'https://supabase.com/dashboard/account/tokens',
43
+ consoleUrl: 'https://supabase.com/dashboard',
44
+ authMethod: 'api-key',
45
+ capabilities: ['database'],
46
+ credentialFields: [
47
+ {
48
+ name: 'accessToken',
49
+ label: 'Personal access token',
50
+ placeholder: 'sbp_…',
51
+ // Names the PERMISSIONS rather than describing the screen. Supabase is
52
+ // rolling out scoped tokens, and a scoped token missing one permission
53
+ // fails at the moment the feature is used, with a bare "Forbidden" that
54
+ // says nothing about which scope is absent — so the fix has to be
55
+ // stated before the token is created, not diagnosed afterwards.
56
+ help:
57
+ 'Account Settings → Access Tokens. A classic token works as is. A SCOPED token (they start with sbp_fc) needs: Projects (account-wide) Read to list, Project Settings Read, and Database Read-write. Add Organizations Read and Organization Projects Read-write to create projects from here.',
58
+ isSecret: true,
59
+ isRequired: true
60
+ }
61
+ ]
62
+ });
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Vercel — the first provider behind the Deployments surface.
3
+ *
4
+ * ONE CREDENTIAL FIELD, deliberately. A Vercel token reaches the personal
5
+ * account and every team its user belongs to, so "which team" is not a property
6
+ * of the credential — it is a property of the project you picked. Putting a
7
+ * `teamId` field here would force a user with two teams to connect the same
8
+ * token twice, and would make the first project they bind decide the second.
9
+ * The team is stored on the binding instead, where it belongs.
10
+ *
11
+ * NO `agent-tools`. Vercel does run an MCP server, but it authenticates with
12
+ * its own OAuth rather than this REST token — a different audience, which the
13
+ * account layer treats as a second credential rather than a reuse of this one.
14
+ * Declaring the capability would mean projecting an MCP row we cannot fill from
15
+ * what is stored here. It stays addable later as its own provider entry.
16
+ *
17
+ * NO `inbound-events`. Vercel can sign webhooks, but a Clopen that is usually
18
+ * reached on localhost has no public URL to register, and `Task 7` is the first
19
+ * entry that builds a subscriber worth registering one for.
20
+ */
21
+
22
+ import { defineProvider } from '../define';
23
+
24
+ export default defineProvider({
25
+ id: 'vercel',
26
+ name: 'Vercel',
27
+ category: 'deployment',
28
+ description:
29
+ 'Deployments for the project this repository builds to. Watch a build as it runs, send a failed build log into the chat, open a preview build in the browser panel, and redeploy, cancel, roll back or promote from here.',
30
+ docsUrl: 'https://vercel.com/account/tokens',
31
+ consoleUrl: 'https://vercel.com/dashboard',
32
+ authMethod: 'api-key',
33
+ capabilities: ['deployments'],
34
+ credentialFields: [
35
+ {
36
+ name: 'token',
37
+ label: 'Access token',
38
+ placeholder: 'Vercel access token',
39
+ // Scope guidance rather than a tutorial: the failure this prevents is
40
+ // a token scoped to one team that then cannot see another team's
41
+ // project, which arrives as an empty list rather than an error.
42
+ help: 'Account Settings → Tokens. A token scoped to a team only reaches that team\'s projects — pick "Full Account" if this Clopen deploys for more than one.',
43
+ isSecret: true,
44
+ isRequired: true
45
+ }
46
+ ]
47
+ });
@@ -83,6 +83,8 @@ export interface IntegrationProvider {
83
83
  category: IntegrationCategory;
84
84
  description: string;
85
85
  docsUrl?: string;
86
+ /** The provider's own dashboard, for what Clopen cannot do — see `IntegrationProviderInfo`. */
87
+ consoleUrl?: string;
86
88
  authMethod: IntegrationAuthMethod;
87
89
  credentialFields: IntegrationCredentialField[];
88
90
  /** Everything this provider is able to offer. */
@@ -4,7 +4,7 @@
4
4
  * as importantly, that it does not have to write anything.
5
5
  */
6
6
 
7
- export const memoryToolDescription = `Query and curate Clopen's Memory Graph — a persistent store of what has been decided, tried and learned across past sessions of this workspace, plus a map of the codebase those memories attach to. It is shared by every AI engine and survives session switches, so a memory written months ago by a different model is still here.
7
+ export const memoryToolDescription = `Query and curate Clopen's Memory Graph — a persistent store of what has been decided, tried and learned across past sessions of this workspace. It is shared by every AI engine and survives session switches, so a memory written months ago by a different model is still here.
8
8
 
9
9
  YOU DO NOT NEED TO RECORD ANYTHING. Memories are written automatically from each finished conversation turn, including anything the user asks you to remember — saying "remember that I prefer X" is enough on its own, and there is deliberately no action here that stores a new memory. That is one write path rather than two, so what ends up in the graph is predictable. This tool is for reading it and for correcting what is already there.
10
10
 
@@ -13,13 +13,13 @@ Reach for it when:
13
13
  - something is failing in a way that feels like it has failed before
14
14
  - you need to know why code looks the way it does, when the code itself does not say
15
15
  - the user refers to a past discussion, decision or preference
16
- - you want to know what a file or module is connected to before changing it
16
+ - you are about to change a file, and want to know what was decided about it
17
17
  - a memory you were shown is wrong, out of date, or filed under the wrong kind
18
18
 
19
19
  Relevant memories are already prepended to each turn automatically, so this tool is for going DEEPER than that: following up on something you have just discovered, asking about another project, or walking the graph. It is not a substitute for reading what you were given.
20
20
 
21
21
  Actions:
22
- - recall — natural-language search across memories and code entities. Runs keyword and semantic search together and expands into the graph, so it finds paraphrases as well as exact names. Use scope "all" to search every project, which is how you find that a problem was already solved in another repository.
22
+ - recall — natural-language search across the memories. Runs keyword and semantic search together and expands into the graph, so it finds paraphrases as well as exact names. Use scope "all" to search every project, which is how you find that a problem was already solved in another repository.
23
23
  - neighbours — walk outward from a node returned by recall. This is where the graph earns its keep: the memory you need is often adjacent to your match rather than being it.
24
24
  - timeline — recent memories in order, for "what have we been doing here".
25
25
  - update — correct a memory in place. Prefer this whenever an existing memory is nearly right: it keeps the node's connections and its history, where retiring it and letting a new one be written loses both.
@@ -69,10 +69,7 @@ function renderHit(hit: RetrievalHit, currentProjectId: string | null): string {
69
69
  : node.projectId !== currentProjectId
70
70
  ? 'learned in another project'
71
71
  : node.scope;
72
- const detail =
73
- node.kind === 'structural'
74
- ? (node.symbol ? `${node.symbol} — ${node.path}` : (node.path ?? ''))
75
- : node.body.split('\n')[0].slice(0, 260);
72
+ const detail = node.body.split('\n')[0].slice(0, 260);
76
73
 
77
74
  return [
78
75
  `[${node.id}] (${node.subkind}, ${where}, confidence ${node.confidence.toFixed(2)}, found by ${found})`,
@@ -84,7 +81,7 @@ function renderHit(hit: RetrievalHit, currentProjectId: string | null): string {
84
81
  }
85
82
 
86
83
  function renderNode(node: GraphNode, prefix = ''): string {
87
- const detail = node.kind === 'structural' ? (node.path ?? '') : node.body.split('\n')[0].slice(0, 200);
84
+ const detail = node.body.split('\n')[0].slice(0, 200);
88
85
  return `${prefix}[${node.id}] (${node.subkind}) ${node.label}${detail ? `\n${prefix} ${detail}` : ''}`;
89
86
  }
90
87
 
@@ -120,7 +117,6 @@ async function runOne(op: Operation, ctx: Context): Promise<OperationReport> {
120
117
  // case memory exists to cover.
121
118
  crossProject: true,
122
119
  sessionId: ctx.sessionId ?? undefined,
123
- kinds: op.kind && op.kind !== 'both' ? [op.kind] : undefined,
124
120
  limit: op.limit ?? 10,
125
121
  // An explicit lookup is answered with what MATCHES it, not with what
126
122
  // matches it plus everything one edge away. Expansion belongs to
@@ -260,7 +256,7 @@ async function runOne(op: Operation, ctx: Context): Promise<OperationReport> {
260
256
  ...(op.subkind !== undefined && { subkind: op.subkind })
261
257
  },
262
258
  // An agent's correction is an agent's correction. Recording it as the
263
- // user's would exempt the node from structural decay, from eviction and
259
+ // user's would exempt the node from staleness decay, from eviction and
264
260
  // from consolidation, and would tell every future turn a person had
265
261
  // stated it — authority the model did not earn by editing.
266
262
  'agent'
@@ -291,8 +287,7 @@ async function runOne(op: Operation, ctx: Context): Promise<OperationReport> {
291
287
  action: op.action,
292
288
  ok: true,
293
289
  text: [
294
- `${stats.nodes} nodes, ${stats.edges} edges`,
295
- ` episodic: ${stats.episodic} structural: ${stats.structural}`,
290
+ `${stats.nodes} memories, ${stats.edges} connections`,
296
291
  ` scope — session ${stats.byScope.session}, project ${stats.byScope.project}, global ${stats.byScope.global}`,
297
292
  ` ${stats.vectors} node(s) have semantic vectors`,
298
293
  ` ${stats.entities} canonical entity/entities, ${stats.confirmedUseful} confirmed useful`,
@@ -42,10 +42,6 @@ const recall = z.object({
42
42
  .describe(
43
43
  'project (default): this project plus global memories. all: every project — use when the question is not about the current codebase, or to find how something was solved elsewhere.'
44
44
  ),
45
- kind: z
46
- .enum(['episodic', 'structural', 'both'])
47
- .optional()
48
- .describe('episodic = decisions/patterns/failures; structural = files/symbols/dependencies; both (default)'),
49
45
  limit: z.number().int().min(1).max(40).optional().describe('Maximum results. Default 10.')
50
46
  });
51
47
 
@@ -32,14 +32,15 @@ what was already settled, and switching engine loses it entirely.
32
32
  ```
33
33
  a turn finishes
34
34
  │
35
- ├── snapshot disk diff ──→ structural extraction ──┐
36
- │ │
37
- └── transcript ──→ episodic extraction (model) ────┤
38
- ▼
39
- ┌─────────────┐
40
- │ graph_nodes │
41
- │ graph_edges │
42
- └──────┬──────┘
35
+ ├── snapshot disk diff ──→ invalidation (ages what moved) ─┐
36
+ │ │
37
+ └── transcript ──→ episodic extraction (model) ────────────┤
38
+ ▼
39
+ ┌──────────────────┐
40
+ │ graph_nodes │
41
+ │ graph_edges │
42
+ │ graph_node_paths │
43
+ └────────┬─────────┘
43
44
  │
44
45
  ┌──────────────────┴─────────┐
45
46
  ▼ ▼
@@ -58,24 +59,29 @@ Nothing on the read path calls a model or touches the network.
58
59
 
59
60
  ---
60
61
 
61
- ## Two Halves, One Store
62
+ ## One Store, Memories Only
62
63
 
63
- | Kind | Holds | Written by |
64
- | --- | --- | --- |
65
- | `episodic` | decisions, patterns, failures, preferences, observations | a model reading each finished turn |
66
- | `structural` | files, symbols, modules, dependencies | the snapshot service's disk diff |
64
+ Every node is a memory: a decision, a pattern, a failure, a preference, an
65
+ observation or an entity, written by a model reading each finished turn.
66
+
67
+ It used to hold the codebase alongside them — a node per file, per directory and
68
+ up to twenty-five per file's symbols. Measured on a real store that half was 81%
69
+ of the nodes and 88% of the edges, it never reached a prompt (an agent can read
70
+ the repository), and it won BM25 on any turn that mentioned a path. Migration 076
71
+ removed it.
67
72
 
68
- They live in **one** graph, joined by an `about` edge. That join is the whole
69
- point: asking "what touches this module" also surfaces the decisions made around
70
- it, and asking "what did we decide about X" surfaces the code it governs.
73
+ What the half was genuinely for survives as an attribute. `graph_node_paths`
74
+ records the files each memory claims something about — shaped exactly like
75
+ `graph_node_entities`, which records the subjects it names. Those paths:
71
76
 
72
- Structural nodes come from the **disk diff**, not from tool calls, so a file
73
- rewritten through Bash or a codemod is captured as reliably as one edited with an
74
- edit tool.
77
+ - are joined into the memory's indexed text, so a pasted path finds what is known
78
+ about it;
79
+ - are what `invalidate.ts` ages a memory against when the file changes;
80
+ - are what an anchored query seeds from when the turn's text says nothing.
75
81
 
76
- Structural hits are deliberately excluded from the injected block — an agent can
77
- read the repository itself. They earn their place by being the path retrieval
78
- *travels* to reach the relevant episodic memories.
82
+ The paths come from the **disk diff** and from extraction, not from tool calls, so
83
+ a file rewritten through Bash or a codemod counts as reliably as one edited with
84
+ an edit tool.
79
85
 
80
86
  ---
81
87
 
@@ -169,9 +175,9 @@ by then the secret is in a durable, re-injected, instance-wide store.
169
175
  | --- | --- | --- |
170
176
  | Belief revision | `revise.ts` | Records that two memories disagree (`contradicts`) |
171
177
  | Read-time resolution | `context.ts` | Decides which is current, per turn |
172
- | Structural invalidation | `invalidate.ts` | Sets `stale_at` when code a memory is `about` changes |
178
+ | Structural invalidation | `invalidate.ts` | Sets `stale_at` when a file the memory names changes |
173
179
  | Consolidation | `consolidate.ts` | Merges memories stating the same thing |
174
- | Retention | `retention.ts` | Bounds growth; retires unreferenced code entities |
180
+ | Retention | `retention.ts` | Bounds growth: evicts, then purges, what earned nothing |
175
181
  | Reach classification | `judge.ts` | Decides which memories travel between projects |
176
182
  | Maintenance loop | `maintenance.ts` | Runs the above on a timer |
177
183
 
@@ -277,8 +283,8 @@ Split across two settings screens on purpose:
277
283
 
278
284
  - **Settings → Model → Memory** — which model writes memories. The only place
279
285
  memory uses a model at all.
280
- - **Settings → Infrastructure → Memory** — what memory does: master switch, record code, record
281
- memories, auto-recall.
286
+ - **Settings → Infrastructure → Memory** — what memory does: master switch,
287
+ record memories, auto-recall.
282
288
 
283
289
  Stored in the `settings` table via `config.ts`. Mutations are admin-only
284
290
  (`backend/auth/permissions.ts`), matching skills and MCP servers: memory is
@@ -292,17 +298,25 @@ member repositories they have no access to.
292
298
 
293
299
  ## Schema
294
300
 
295
- Created by migration `066_create_memory_graph.ts`.
301
+ Created by migration `066_create_memory_graph.ts`, reshaped by
302
+ `076_remove_memory_code_graph.ts`.
296
303
 
297
304
  ```
298
- graph_nodes the memories and code entities
305
+ graph_nodes the memories
299
306
  graph_edges typed relations between them
300
307
  graph_node_entities subjects a memory is about (an ATTRIBUTE, not nodes)
308
+ graph_node_paths files a memory is about (likewise)
301
309
  graph_vectors one int8 vector per node, 260 bytes at 256 dims
302
310
  graph_nodes_fts FTS5 mirror for BM25
311
+ graph_layout persisted positions and communities (migration 067)
303
312
  memory_extraction_queue durable queue of turns awaiting summarisation
304
313
  ```
305
314
 
315
+ `graph_nodes.kind` survives 076 as the constant `'episodic'`: it is part of the
316
+ unique digest index and of the FTS mirror's schema, and rebuilding both across a
317
+ live memory store to reclaim one constant column would be risk without benefit.
318
+ Nothing above `graph-queries.ts` has the concept.
319
+
306
320
  `graph_nodes` groups its columns four ways:
307
321
 
308
322
  | Group | Columns | Answers |
@@ -320,12 +334,15 @@ both "where learned" and "where it applies" made cross-project recall impossible
320
334
  ### Relations
321
335
 
322
336
  ```
323
- structural ↔ structural : imports | calls | defines | contains
324
- episodic ↔ episodic : caused_by | supersedes | contradicts | generalizes
325
- episodic → structural : about ← the bridge between both halves
326
- any ↔ any : relates_to (user-drawn only)
337
+ memory ↔ memory : caused_by | supersedes | contradicts | generalizes
338
+ memory ↔ memory : relates_to (user-drawn only)
327
339
  ```
328
340
 
341
+ The code-shaped relations — `imports`, `defines`, `contains`, and `about`
342
+ pointing at a file node — went with the structural half in migration 076. What a
343
+ memory is about is a row in `graph_node_paths`, not an edge to a node standing in
344
+ for a file.
345
+
329
346
  `relates_to` is **never** inferred. An automatic similarity linker used to write
330
347
  it from vector neighbourhoods and fabricated most of the graph: against a corpus
331
348
  of sentences all shaped "X is a project that does Y", every pair is similar in
@@ -352,8 +369,6 @@ view.ts graph serialization for the UI
352
369
  extract/
353
370
  scheduler.ts durable queue, retries, concurrency
354
371
  episodic.ts model-driven summarisation of a finished turn
355
- structural.ts file/symbol/dependency nodes from the disk diff
356
- languages.ts per-language symbol extraction
357
372
 
358
373
  embedding/
359
374
  paths.ts version, pinned checksums, install location
@@ -410,6 +425,14 @@ could never be found semantically while still being offered to the model as
410
425
  something to adjudicate against. Subjects are now rows in `graph_node_entities`,
411
426
  folded into the FTS text.
412
427
 
428
+ **The same rule eventually removed the codebase.** Files, symbols and modules were
429
+ nodes for the same reason entities were — so a question about code could travel to
430
+ the decisions made around it. They were 81% of one real store and 88% of its
431
+ edges, they never reached a prompt, and 4,458 symbol nodes were never once the
432
+ reason a memory was found. The paths a memory names are rows in
433
+ `graph_node_paths` now (migration 076), and invalidation and anchoring got faster
434
+ for losing the hop through a node that stood in for a string.
435
+
413
436
  **Revision resolves at read time.** See [Keeping the Graph Honest](#keeping-the-graph-honest).
414
437
 
415
438
  **Retrieval never calls a model.** This is what makes injection on *every* turn
@@ -18,6 +18,7 @@ import { beforeEach, describe, expect, it, mock } from 'bun:test';
18
18
  import { Database } from 'bun:sqlite';
19
19
  import type { DatabaseConnection } from '$shared/types/database/connection';
20
20
  import * as migration066 from '$backend/database/migrations/066_create_memory_graph';
21
+ import * as migration076 from '$backend/database/migrations/076_remove_memory_code_graph';
21
22
 
22
23
  let db: Database;
23
24
 
@@ -38,7 +39,6 @@ mock.module('$backend/database', () => ({
38
39
  mock.module('./config', () => ({
39
40
  getMemoryConfig: () => ({
40
41
  enabled: true,
41
- recordCode: true,
42
42
  recordMemories: true,
43
43
  autoRecall: true,
44
44
  recallBudget: 2_400,
@@ -60,6 +60,7 @@ beforeEach(() => {
60
60
  db = new Database(':memory:');
61
61
  db.exec('PRAGMA foreign_keys = ON');
62
62
  migration066.up(db as unknown as DatabaseConnection);
63
+ migration076.up(db as unknown as DatabaseConnection);
63
64
  });
64
65
 
65
66
  describe('drafting', () => {
@@ -156,7 +157,6 @@ describe('saving', () => {
156
157
  // Agreeing with something already stored should make it stronger, not add a
157
158
  // near-copy that competes with it for the same recall budget.
158
159
  const existing = graphQueries.upsert({
159
- kind: 'episodic',
160
160
  subkind: 'preference',
161
161
  projectId: PROJECT,
162
162
  label: 'Prefers tabs',
@@ -174,7 +174,7 @@ describe('saving', () => {
174
174
 
175
175
  expect(node.id).toBe(existing.id);
176
176
  expect(node.confidence).toBe(0.95);
177
- expect(graphQueries.count({ projectId: PROJECT, kinds: ['episodic'] })).toBe(1);
177
+ expect(graphQueries.count({ projectId: PROJECT })).toBe(1);
178
178
  });
179
179
 
180
180
  it('makes it findable at once', () => {
@@ -172,7 +172,7 @@ export interface CreateInput {
172
172
  * Store a reviewed draft.
173
173
  *
174
174
  * `source: 'user'`, which is not bookkeeping — it is what exempts the node from
175
- * structural decay, from eviction and from being archived into a consolidation,
175
+ * staleness decay, from eviction and from being archived into a consolidation,
176
176
  * and what makes the injected block tell the agent a person said this rather
177
177
  * than that a model inferred it.
178
178
  */
@@ -205,7 +205,6 @@ export function createMemory(input: CreateInput): GraphNode | null {
205
205
  }
206
206
 
207
207
  const node = graphQueries.upsert({
208
- kind: 'episodic',
209
208
  subkind: input.subkind,
210
209
  scope,
211
210
  projectId,
@@ -226,13 +225,11 @@ export function createMemory(input: CreateInput): GraphNode | null {
226
225
  });
227
226
 
228
227
  linkEntities(node.id, input.entities ?? []);
229
-
230
- for (const raw of input.relatedPaths ?? []) {
231
- const path = raw.replace(/\\/g, '/').replace(/^\.\//, '');
232
- const target = input.projectId ? graphQueries.getByPath(input.projectId, path) : null;
233
- if (!target) continue;
234
- graphQueries.link({ srcId: node.id, dstId: target.id, rel: 'about', source: 'user' });
235
- }
228
+ // Recorded whether or not those files have ever been seen — a path is a string
229
+ // on the memory now rather than a node that had to have been observed first.
230
+ // A hand-written memory naming a file the agent had not touched yet used to
231
+ // lose its attribution silently.
232
+ graphQueries.setPaths(node.id, input.relatedPaths ?? []);
236
233
 
237
234
  scheduleVectorIndexing();
238
235
  resetGraphEmptiness();
@@ -28,8 +28,6 @@ export interface MemoryModelConfig {
28
28
  export interface MemoryConfig {
29
29
  /** Master switch: off means no recording, no retrieval, no injection. */
30
30
  enabled: boolean;
31
- /** Record the files and symbols each turn touches, read from the disk diff. */
32
- recordCode: boolean;
33
31
  /** Summarise finished turns into memories using `model`. */
34
32
  recordMemories: boolean;
35
33
  /** Hand relevant memories to the agent automatically at the start of a turn. */
@@ -56,7 +54,6 @@ export interface MemoryConfig {
56
54
  */
57
55
  const KEYS = {
58
56
  enabled: 'memory_enabled',
59
- recordCode: 'memory_record_code',
60
57
  recordMemories: 'memory_record_memories',
61
58
  autoRecall: 'memory_auto_recall',
62
59
  model: 'memory_model'
@@ -81,7 +78,6 @@ export function getMemoryConfig(): MemoryConfig {
81
78
 
82
79
  return {
83
80
  enabled: readBoolean(KEYS.enabled, true),
84
- recordCode: readBoolean(KEYS.recordCode, true),
85
81
  recordMemories: readBoolean(KEYS.recordMemories, true),
86
82
  autoRecall: readBoolean(KEYS.autoRecall, true),
87
83
  model
@@ -90,7 +86,6 @@ export function getMemoryConfig(): MemoryConfig {
90
86
 
91
87
  export function setMemoryConfig(patch: Partial<MemoryConfig>): MemoryConfig {
92
88
  if (patch.enabled !== undefined) settingsQueries.set(KEYS.enabled, String(patch.enabled));
93
- if (patch.recordCode !== undefined) settingsQueries.set(KEYS.recordCode, String(patch.recordCode));
94
89
  if (patch.recordMemories !== undefined) settingsQueries.set(KEYS.recordMemories, String(patch.recordMemories));
95
90
  if (patch.autoRecall !== undefined) settingsQueries.set(KEYS.autoRecall, String(patch.autoRecall));
96
91
  if (patch.model !== undefined) {
@@ -135,7 +135,6 @@ export async function consolidateMemories(projectId: string | null, projectPath:
135
135
  if (covered.length < MIN_CLUSTER) continue;
136
136
 
137
137
  const node = graphQueries.upsert({
138
- kind: 'episodic',
139
138
  subkind: summary.subkind,
140
139
  scope: projectId ? 'project' : 'global',
141
140
  projectId,
@@ -181,7 +180,7 @@ export async function consolidateMemories(projectId: string | null, projectPath:
181
180
  */
182
181
  function findClusters(projectId: string | null): GraphNode[][] {
183
182
  const nodes = graphQueries
184
- .list({ projectId, kinds: ['episodic'], limit: 2_000 })
183
+ .list({ projectId, limit: 2_000 })
185
184
  .filter(
186
185
  node =>
187
186
  node.source === 'agent' &&
@@ -5,12 +5,12 @@
5
5
  * turn that simply has no memory in it — which is indistinguishable from a graph
6
6
  * that had nothing to say.
7
7
  *
8
- * THE BLOCK CAME OUT EMPTY ON THE TURNS WITH THE MOST TO OFFER. Retrieval ranks
9
- * structural and episodic nodes together and the block only ever shows episodic
10
- * ones, so asking for eighteen hits and then filtering meant a project's file and
11
- * symbol nodes could take every slot. They win exactly when the turn mentions a
12
- * path or a symbol — and they outnumber memories by an order of magnitude, and
13
- * every anchor seed is one.
8
+ * THE BLOCK CAME OUT EMPTY ON THE TURNS WITH THE MOST TO OFFER. Retrieval used
9
+ * to rank the codebase alongside the memories while the block only ever showed
10
+ * memories, so a project's file and symbol nodes could take every slot. That half
11
+ * is gone (migration 076), and the test that guarded the filtering went with it;
12
+ * what remains worth pinning is that the block still fills from the memories the
13
+ * question earns.
14
14
  *
15
15
  * THE DIRECTIVE WAS SENT INTO AN EMPTY GRAPH. A few hundred characters on every
16
16
  * turn of every session on every engine, telling an agent about a store with
@@ -21,6 +21,7 @@ import { beforeEach, describe, expect, it, mock } from 'bun:test';
21
21
  import { Database } from 'bun:sqlite';
22
22
  import type { DatabaseConnection } from '$shared/types/database/connection';
23
23
  import * as migration066 from '$backend/database/migrations/066_create_memory_graph';
24
+ import * as migration076 from '$backend/database/migrations/076_remove_memory_code_graph';
24
25
 
25
26
  let db: Database;
26
27
 
@@ -40,7 +41,6 @@ mock.module('$backend/database', () => ({
40
41
  mock.module('./config', () => ({
41
42
  getMemoryConfig: () => ({
42
43
  enabled: true,
43
- recordCode: true,
44
44
  recordMemories: true,
45
45
  autoRecall: true,
46
46
  model: null
@@ -81,7 +81,6 @@ const PROJECT = 'project-a';
81
81
 
82
82
  function memory(label: string, body: string) {
83
83
  return graphQueries.upsert({
84
- kind: 'episodic',
85
84
  subkind: 'decision',
86
85
  projectId: PROJECT,
87
86
  label,
@@ -90,24 +89,11 @@ function memory(label: string, body: string) {
90
89
  });
91
90
  }
92
91
 
93
- /** A project's structural half: the nodes that outnumber and outrank memories. */
94
- function floodWithCode(count: number, token: string): void {
95
- for (let i = 0; i < count; i++) {
96
- graphQueries.upsert({
97
- kind: 'structural',
98
- subkind: 'file',
99
- projectId: PROJECT,
100
- label: `${token}-${i}.ts`,
101
- body: `src/${token}/${token}-${i}.ts`,
102
- path: `src/${token}/${token}-${i}.ts`
103
- });
104
- }
105
- }
106
-
107
92
  beforeEach(() => {
108
93
  db = new Database(':memory:');
109
94
  db.exec('PRAGMA foreign_keys = ON');
110
95
  migration066.up(db as unknown as DatabaseConnection);
96
+ migration076.up(db as unknown as DatabaseConnection);
111
97
  resetGraphEmptiness();
112
98
  });
113
99
 
@@ -129,34 +115,6 @@ describe('the injected block', () => {
129
115
  expect(block!.text).toContain('<clopen-memory>');
130
116
  });
131
117
 
132
- it('still finds the memory when the code half floods the ranking', () => {
133
- // Forty file nodes all matching the query's tokens, which is what a real
134
- // project looks like. With a limit of eighteen applied BEFORE the episodic
135
- // filter, none of the one memory that matters survived.
136
- const note = memory('Snapshot capture must not run mid-stream', 'It corrupts the working tree.');
137
- floodWithCode(40, 'snapshot');
138
- resetGraphEmptiness();
139
-
140
- const block = buildMemoryContext({
141
- query: 'snapshot capture',
142
- projectId: PROJECT,
143
- sessionId: 's'
144
- })!;
145
-
146
- expect(block.nodeIds).toContain(note.id);
147
- });
148
-
149
- it('never lists a code entity — the agent can read the repository itself', () => {
150
- memory('Snapshot capture must not run mid-stream', 'It corrupts the working tree.');
151
- floodWithCode(10, 'snapshot');
152
- resetGraphEmptiness();
153
-
154
- const block = buildMemoryContext({ query: 'snapshot capture', projectId: PROJECT, sessionId: 's' })!;
155
- const structural = graphQueries.list({ projectId: PROJECT, kinds: ['structural'] }).map(node => node.id);
156
-
157
- expect(block.nodeIds.filter(id => structural.includes(id))).toHaveLength(0);
158
- });
159
-
160
118
  it('carries as many memories as the question earns, never more than the ceiling', () => {
161
119
  // There is no setting for this any more. A character budget did not bound what
162
120
  // it claimed to, and a count could not be right for both "ok, continue" and a
@@ -230,7 +188,6 @@ describe('the injected block', () => {
230
188
  // the name, a travelling memory reads as a claim about the project in front
231
189
  // of it.
232
190
  graphQueries.upsert({
233
- kind: 'episodic',
234
191
  subkind: 'pattern',
235
192
  scope: 'project',
236
193
  projectId: 'project-b',
@@ -257,7 +214,6 @@ describe('the injected block', () => {
257
214
  // always rank it below whatever was actually asked — measured, human-stated
258
215
  // rules reached the prompt on 3 of 20 opportunities.
259
216
  graphQueries.upsert({
260
- kind: 'episodic',
261
217
  subkind: 'preference',
262
218
  scope: 'global',
263
219
  projectId: null,
@@ -277,7 +233,6 @@ describe('the injected block', () => {
277
233
 
278
234
  it('does not repeat a standing instruction in the recalled section', () => {
279
235
  graphQueries.upsert({
280
- kind: 'episodic',
281
236
  subkind: 'preference',
282
237
  scope: 'global',
283
238
  projectId: null,
@@ -303,7 +258,6 @@ describe('the injected block', () => {
303
258
  // about how the user works is background, and promoting it would make the
304
259
  // most privileged position in the prompt reachable by inference.
305
260
  graphQueries.upsert({
306
- kind: 'episodic',
307
261
  subkind: 'preference',
308
262
  scope: 'global',
309
263
  projectId: null,