@myrialabs/clopen 0.4.25 → 0.4.27

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 (96) hide show
  1. package/backend/auth/permissions.ts +21 -0
  2. package/backend/bootstrap.ts +18 -1
  3. package/backend/chat/engine-handoff.test.ts +229 -0
  4. package/backend/chat/engine-handoff.ts +439 -0
  5. package/backend/chat/stream-manager.ts +200 -16
  6. package/backend/database/migrations/066_create_memory_graph.ts +369 -0
  7. package/backend/database/migrations/index.ts +7 -0
  8. package/backend/database/queries/audit-log-queries.test.ts +10 -1
  9. package/backend/database/queries/graph-queries.ts +1764 -0
  10. package/backend/database/queries/index.ts +2 -0
  11. package/backend/database/queries/memory-queue-queries.ts +381 -0
  12. package/backend/database/queries/snapshot-queries.ts +20 -0
  13. package/backend/engine/README.md +45 -2
  14. package/backend/engine/adapters/copilot/stream.ts +37 -1
  15. package/backend/engine/adapters/pi/models.ts +19 -7
  16. package/backend/engine/adapters/pi/stream.ts +2 -1
  17. package/backend/engine/docs/adapter-contract.md +25 -8
  18. package/backend/engine/docs/adding-an-engine.md +40 -4
  19. package/backend/engine/docs/frontend-and-chat.md +66 -1
  20. package/backend/engine/docs/lessons-learned.md +165 -6
  21. package/backend/engine/docs/quick-reference.md +10 -0
  22. package/backend/engine/docs/stack.md +10 -0
  23. package/backend/engine/docs/websocket-routes.md +15 -1
  24. package/backend/engine/engine-setup.ts +1 -1
  25. package/backend/engine/index.test.ts +186 -0
  26. package/backend/engine/index.ts +117 -71
  27. package/backend/engine/install-recipes.test.ts +105 -0
  28. package/backend/engine/install-recipes.ts +4 -1
  29. package/backend/index.ts +9 -0
  30. package/backend/mcp/internal/config.ts +6 -0
  31. package/backend/mcp/internal/servers/index.ts +2 -0
  32. package/backend/mcp/internal/servers/memory-graph/description.ts +33 -0
  33. package/backend/mcp/internal/servers/memory-graph/format.ts +45 -0
  34. package/backend/mcp/internal/servers/memory-graph/index.ts +52 -0
  35. package/backend/mcp/internal/servers/memory-graph/runner.ts +342 -0
  36. package/backend/mcp/internal/servers/memory-graph/schema.ts +140 -0
  37. package/backend/memory/README.md +432 -0
  38. package/backend/memory/bootstrap.ts +101 -0
  39. package/backend/memory/compose.test.ts +198 -0
  40. package/backend/memory/compose.ts +343 -0
  41. package/backend/memory/config.ts +100 -0
  42. package/backend/memory/consolidate.ts +280 -0
  43. package/backend/memory/context.test.ts +321 -0
  44. package/backend/memory/context.ts +451 -0
  45. package/backend/memory/embedding/embedder.test.ts +141 -0
  46. package/backend/memory/embedding/embedder.ts +269 -0
  47. package/backend/memory/embedding/index.ts +17 -0
  48. package/backend/memory/embedding/install.ts +254 -0
  49. package/backend/memory/embedding/paths.ts +101 -0
  50. package/backend/memory/embedding/vector-cache.ts +270 -0
  51. package/backend/memory/extract/episodic.ts +725 -0
  52. package/backend/memory/extract/index.ts +133 -0
  53. package/backend/memory/extract/languages.ts +176 -0
  54. package/backend/memory/extract/scheduler.test.ts +352 -0
  55. package/backend/memory/extract/scheduler.ts +406 -0
  56. package/backend/memory/extract/structural.test.ts +215 -0
  57. package/backend/memory/extract/structural.ts +364 -0
  58. package/backend/memory/index.ts +37 -0
  59. package/backend/memory/indexer.ts +150 -0
  60. package/backend/memory/invalidate.ts +134 -0
  61. package/backend/memory/judge.ts +285 -0
  62. package/backend/memory/maintenance.ts +132 -0
  63. package/backend/memory/model.ts +91 -0
  64. package/backend/memory/notify.ts +102 -0
  65. package/backend/memory/readiness.ts +74 -0
  66. package/backend/memory/redact.test.ts +101 -0
  67. package/backend/memory/redact.ts +133 -0
  68. package/backend/memory/retention.ts +139 -0
  69. package/backend/memory/retrieval.eval.test.ts +301 -0
  70. package/backend/memory/retrieval.test.ts +1023 -0
  71. package/backend/memory/retrieval.ts +707 -0
  72. package/backend/memory/revise.test.ts +693 -0
  73. package/backend/memory/revise.ts +400 -0
  74. package/backend/memory/time.ts +31 -0
  75. package/backend/memory/view.ts +164 -0
  76. package/backend/shipped-runtime-imports.test.ts +228 -0
  77. package/backend/ws/index.ts +5 -1
  78. package/backend/ws/memory/crud.ts +631 -0
  79. package/backend/ws/memory/index.ts +41 -0
  80. package/backend/ws/sessions/crud.ts +10 -0
  81. package/backend/ws/snapshot/content.ts +85 -0
  82. package/backend/ws/snapshot/index.ts +4 -1
  83. package/backend/ws/snapshot/restore.ts +38 -4
  84. package/dist/assets/graph-layout.worker-CRFqN7ZQ.js +1 -0
  85. package/dist/assets/{index-KBGloYDk.js → index-BCv5HlPk.js} +1 -1
  86. package/dist/assets/{index-C4PD7B-x.js → index-BTGcf_Vy.js} +1 -1
  87. package/dist/assets/main-BrqMMMRX.css +1 -0
  88. package/dist/assets/main-CgmAFpU3.js +1036 -0
  89. package/dist/index.html +2 -2
  90. package/package.json +8 -2
  91. package/shared/types/database/connection.ts +9 -0
  92. package/shared/types/memory.ts +519 -0
  93. package/shared/utils/logger.ts +1 -0
  94. package/dist/assets/main-B0AA-88X.js +0 -622
  95. package/dist/assets/main-OsjA5Ab5.css +0 -1
  96. package/shared/utils/anonymous-user.ts +0 -168
package/dist/index.html CHANGED
@@ -58,8 +58,8 @@
58
58
  }
59
59
  })();
60
60
  </script>
61
- <script type="module" crossorigin src="/assets/main-B0AA-88X.js"></script>
62
- <link rel="stylesheet" crossorigin href="/assets/main-OsjA5Ab5.css">
61
+ <script type="module" crossorigin src="/assets/main-CgmAFpU3.js"></script>
62
+ <link rel="stylesheet" crossorigin href="/assets/main-BrqMMMRX.css">
63
63
  </head>
64
64
  <body
65
65
  class="min-h-dvh bg-white text-slate-900 dark:bg-slate-950 dark:text-slate-100 transition-colors duration-200"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myrialabs/clopen",
3
- "version": "0.4.25",
3
+ "version": "0.4.27",
4
4
  "description": "All-in-one web workspace for AI coding agents — Claude Code, OpenCode, Codex, Copilot, Qwen Code, Pi, Cline, and Cursor — with chat, terminal, git, browser preview, database client, checkpoints, and real-time collaboration",
5
5
  "author": "Myria Labs",
6
6
  "license": "MIT",
@@ -114,6 +114,7 @@
114
114
  "dependencies": {
115
115
  "@dagrejs/dagre": "3.0.0",
116
116
  "@elysiajs/cors": "1.4.1",
117
+ "@huggingface/tokenizers": "0.1.3",
117
118
  "@iconify-json/lucide": "1.2.96",
118
119
  "@iconify-json/material-icon-theme": "1.2.55",
119
120
  "@modelcontextprotocol/sdk": "1.29.0",
@@ -127,6 +128,9 @@
127
128
  "dompurify": "3.4.9",
128
129
  "elysia": "1.4.27",
129
130
  "file-type": "21.3.1",
131
+ "graphology": "0.26.0",
132
+ "graphology-communities-louvain": "2.0.2",
133
+ "graphology-layout-forceatlas2": "0.10.1",
130
134
  "is-text-path": "3.0.0",
131
135
  "marked": "16.4.2",
132
136
  "monaco-editor": "0.52.2",
@@ -138,9 +142,11 @@
138
142
  "puppeteer-extra-plugin-stealth": "2.11.2",
139
143
  "qrcode": "1.5.4",
140
144
  "sharp": "0.34.5",
145
+ "sigma": "3.0.3",
141
146
  "ssh2": "1.17.0",
142
147
  "systeminformation": "5.33.1",
143
- "typebox": "1.1.38"
148
+ "typebox": "1.1.38",
149
+ "zod": "4.3.6"
144
150
  },
145
151
  "trustedDependencies": [
146
152
  "puppeteer",
@@ -13,4 +13,13 @@ export interface DatabaseConnection {
13
13
  };
14
14
  exec(query: string): unknown;
15
15
  close(): void;
16
+ /**
17
+ * Wrap a synchronous block of statements in one transaction.
18
+ *
19
+ * Optional because it is a property of the driver, not of the contract: the
20
+ * local `bun:sqlite` connection provides it, and a caller that needs it must
21
+ * degrade gracefully when it is absent rather than assume. Callers get
22
+ * correctness either way — without it the statements simply run unbatched.
23
+ */
24
+ transaction?<T>(fn: () => T): () => T;
16
25
  }
@@ -0,0 +1,519 @@
1
+ /**
2
+ * Memory Graph types.
3
+ *
4
+ * One graph holds both kinds of memory (see migration 066): `episodic` for what
5
+ * happened and what was decided, `structural` for the codebase as entities. They
6
+ * are connected by real edges, so a query can travel from a decision to the code
7
+ * it governs and back.
8
+ *
9
+ * Shared between backend and frontend — the visualization, the MCP tool surface
10
+ * and the retrieval engine all speak these shapes.
11
+ */
12
+
13
+ // ─────────────────────────────────────────────────────────────────────────────
14
+ // Nodes
15
+ // ─────────────────────────────────────────────────────────────────────────────
16
+
17
+ export type GraphNodeKind = 'episodic' | 'structural';
18
+
19
+ /** What kind of memory an episodic node holds. */
20
+ export type EpisodicSubkind =
21
+ | 'decision'
22
+ | 'pattern'
23
+ | 'failure'
24
+ | 'preference'
25
+ | 'observation'
26
+ | 'entity';
27
+
28
+ /** What kind of code entity a structural node represents. */
29
+ export type StructuralSubkind = 'file' | 'symbol' | 'module' | 'dependency';
30
+
31
+ export type GraphNodeSubkind = EpisodicSubkind | StructuralSubkind;
32
+
33
+ /**
34
+ * How LONG a claim holds — its durability, not its geography.
35
+ *
36
+ * `session` is a one-off: an instruction for the task at hand, which says
37
+ * nothing about how future work should be done and can never repeal a standing
38
+ * rule. `project` and `global` are standing claims, differing in whether they
39
+ * are about one repository or about the user's way of working.
40
+ *
41
+ * The `session` value existed from migration 066, was filtered for in retrieval
42
+ * and covered by a test, and was never written by any path — extraction's schema
43
+ * only ever offered `project` and `global`. That gap is why "use the agent tool
44
+ * for this analysis" was filed as a global policy and superseded the standing
45
+ * prohibition it was an exception to.
46
+ */
47
+ export type GraphScope = 'session' | 'project' | 'global';
48
+
49
+ /**
50
+ * WHERE a claim applies, which is a different question from where it was
51
+ * learned (`projectId`).
52
+ *
53
+ * `here` is about this codebase — its choices, its layout, its configuration.
54
+ * Someone on another project cannot act on it, and handing it to them is worse
55
+ * than saying nothing, because every project answers "where does this deploy"
56
+ * differently.
57
+ *
58
+ * `anywhere` is about a language, runtime, library or practice. It was learned
59
+ * in one repository and is true in all of them, and it is the reason a single
60
+ * shared graph is worth having: a Svelte reactivity gotcha debugged in one
61
+ * project should not have to be rediscovered in the next.
62
+ *
63
+ * Measured: a model fills this correctly 15 times in 16, with zero errors in the
64
+ * damaging direction (a codebase fact wrongly released to travel). The same
65
+ * model asked to judge durability scored 6 of 14 — reach is a property of the
66
+ * sentence, durability a property of intent, and only the first is legible.
67
+ */
68
+ export type GraphReach = 'here' | 'anywhere';
69
+
70
+ /**
71
+ * Whose claim this is, which is a different question from which code path wrote
72
+ * it (`source`).
73
+ *
74
+ * `user` — the person said it, in the conversation, or typed it by hand.
75
+ * `assistant` — the assistant asserted it while working.
76
+ * `inferred` — nobody said it; a model concluded it from what it read.
77
+ *
78
+ * Authority is read from here, not from `source`. Conflating the two is what
79
+ * allowed a model's inference to retire a memory a person had written: both were
80
+ * "a memory", and the only column that could have told them apart was answering
81
+ * a different question.
82
+ */
83
+ export type GraphAssertedBy = 'user' | 'assistant' | 'inferred';
84
+
85
+ /**
86
+ * How much weight a claim carries when two of them disagree.
87
+ *
88
+ * Read-time conflict resolution walks this ordering first, then durability, then
89
+ * recency. Higher wins.
90
+ */
91
+ export const AUTHORITY_RANK: Record<GraphAssertedBy, number> = {
92
+ user: 2,
93
+ assistant: 1,
94
+ inferred: 0
95
+ };
96
+
97
+ /**
98
+ * Who created a node or edge — matters for trust and for what may be pruned.
99
+ *
100
+ * Exactly two values, and the absence of a third is deliberate. This used to
101
+ * carry `auto` as well, for "written by the automatic extraction", alongside
102
+ * `agent` for "written through the MCP tool" — but nothing could act on the
103
+ * distinction, because both are a model reading text and deciding what to store.
104
+ * Meanwhile `auto` was doing the work of the real question every consumer
105
+ * actually asks: *did a person say this, or did a model infer it?* Retention,
106
+ * structural decay, consolidation and the trust line in the injected block all
107
+ * branch on precisely that. Two values answer it without ambiguity; three
108
+ * invited every reader to guess which of the two model-written kinds a predicate
109
+ * meant.
110
+ */
111
+ export type GraphSource = 'agent' | 'user';
112
+
113
+ export interface GraphNode {
114
+ id: string;
115
+ kind: GraphNodeKind;
116
+ subkind: GraphNodeSubkind;
117
+ scope: GraphScope;
118
+ projectId: string | null;
119
+ sessionId: string | null;
120
+ /** Short, human-readable title shown on the graph and in listings. */
121
+ label: string;
122
+ /** Full memory text, or a signature/summary for structural nodes. */
123
+ body: string;
124
+ /** Repo-relative path for structural nodes. */
125
+ path: string | null;
126
+ /** Symbol name for structural nodes of subkind `symbol`. */
127
+ symbol: string | null;
128
+ /** Detected language of the file a structural node came from. */
129
+ language: string | null;
130
+ /** Stable identity hash used to upsert instead of duplicating. */
131
+ digest: string;
132
+ /** How much the writer trusts this memory, 0–1. */
133
+ confidence: number;
134
+ /** Reinforcement: grows when a memory is re-observed or proves useful. */
135
+ weight: number;
136
+ accessCount: number;
137
+ source: GraphSource;
138
+ /** Whose claim this is — the basis for authority. See `GraphAssertedBy`. */
139
+ assertedBy: GraphAssertedBy;
140
+ /** Whether this travels to other projects. See `GraphReach`. */
141
+ reach: GraphReach;
142
+ /** False until a model has judged `reach`; the backfill defaults to `here`. */
143
+ reachJudged: boolean;
144
+ /** Pinned nodes are exempt from decay and automatic pruning. */
145
+ pinned: boolean;
146
+ /** Soft-delete timestamp; archived nodes keep their edges but leave retrieval. */
147
+ archivedAt: string | null;
148
+ createdAt: string;
149
+ updatedAt: string;
150
+ accessedAt: string | null;
151
+
152
+ /**
153
+ * Id of the memory that replaced this one. Non-null means "no longer the
154
+ * current belief": the node keeps its edges so the reasoning path stays
155
+ * visible, but retrieval skips it so an agent is never handed two versions of
156
+ * the same fact and asked to adjudicate.
157
+ */
158
+ supersededBy: string | null;
159
+ /** Times a later turn actually used this memory. Evidence, unlike accessCount. */
160
+ usefulCount: number;
161
+ /** Times a later turn found this memory wrong or misleading. */
162
+ unhelpfulCount: number;
163
+ /** When the code this memory is `about` last changed underneath it. */
164
+ staleAt: string | null;
165
+ /** Canonical identity for `entity` nodes — the slug every statement hangs off. */
166
+ entityKey: string | null;
167
+ }
168
+
169
+ // ─────────────────────────────────────────────────────────────────────────────
170
+ // Edges
171
+ // ─────────────────────────────────────────────────────────────────────────────
172
+
173
+ /**
174
+ * Relation types, grouped by what they connect.
175
+ *
176
+ * `about` is the load-bearing one: it links an episodic memory to the code it
177
+ * concerns, which is what fuses the two halves into a single graph instead of
178
+ * two indexes in one database.
179
+ */
180
+ export type GraphRelation =
181
+ // structural ↔ structural
182
+ | 'imports'
183
+ | 'calls'
184
+ | 'defines'
185
+ | 'contains'
186
+ // episodic ↔ episodic
187
+ | 'caused_by'
188
+ | 'supersedes'
189
+ | 'contradicts'
190
+ | 'generalizes'
191
+ // episodic → structural
192
+ | 'about'
193
+ // anything, drawn by hand
194
+ | 'relates_to';
195
+
196
+ export interface GraphEdge {
197
+ id: number;
198
+ srcId: string;
199
+ dstId: string;
200
+ rel: GraphRelation;
201
+ weight: number;
202
+ source: GraphSource;
203
+ createdAt: string;
204
+ }
205
+
206
+ // ─────────────────────────────────────────────────────────────────────────────
207
+ // Writes
208
+ // ─────────────────────────────────────────────────────────────────────────────
209
+
210
+ export interface GraphNodeInput {
211
+ kind: GraphNodeKind;
212
+ subkind: GraphNodeSubkind;
213
+ scope?: GraphScope;
214
+ projectId?: string | null;
215
+ sessionId?: string | null;
216
+ label: string;
217
+ body?: string;
218
+ path?: string | null;
219
+ symbol?: string | null;
220
+ language?: string | null;
221
+ /** Supply to control identity; otherwise derived from the node's content. */
222
+ digest?: string;
223
+ confidence?: number;
224
+ source?: GraphSource;
225
+ assertedBy?: GraphAssertedBy;
226
+ reach?: GraphReach;
227
+ reachJudged?: boolean;
228
+ pinned?: boolean;
229
+ /**
230
+ * Canonical entity slug. When present it REPLACES content as the node's
231
+ * identity, which is what makes every statement about one person converge on
232
+ * a single node instead of one node per phrasing.
233
+ */
234
+ entityKey?: string | null;
235
+ }
236
+
237
+ /** What a later turn did with a memory that was injected into it. */
238
+ export type MemoryVerdict = 'used' | 'wrong' | 'ignored';
239
+
240
+ export interface GraphEdgeInput {
241
+ srcId: string;
242
+ dstId: string;
243
+ rel: GraphRelation;
244
+ weight?: number;
245
+ source?: GraphSource;
246
+ }
247
+
248
+ // ─────────────────────────────────────────────────────────────────────────────
249
+ // Retrieval
250
+ // ─────────────────────────────────────────────────────────────────────────────
251
+
252
+ /**
253
+ * Where a result came from. Both retrievers run on every query and their ranks
254
+ * are fused, so a result is frequently `both` — which is exactly the signal that
255
+ * it is a strong match.
256
+ */
257
+ export type RetrievalChannel = 'lexical' | 'vector' | 'both' | 'graph';
258
+
259
+ export interface RetrievalHit {
260
+ node: GraphNode;
261
+ /** Fused score after RRF, decay and reinforcement weighting. */
262
+ score: number;
263
+ channel: RetrievalChannel;
264
+ /** Rank in the BM25 result list, when it appeared there. */
265
+ lexicalRank: number | null;
266
+ /** Rank in the vector result list, when it appeared there. */
267
+ vectorRank: number | null;
268
+ /** Hops from a directly-matched node; 0 when matched directly. */
269
+ hops: number;
270
+ /** Highlighted BM25 snippet, when the lexical channel produced one. */
271
+ snippet: string | null;
272
+ }
273
+
274
+ export interface RetrievalOptions {
275
+ /** Free text. Both retrievers consume it as-is; no LLM is involved. */
276
+ query: string;
277
+ /** Narrow to a single project. Omit to search across every project. */
278
+ projectId?: string | null;
279
+ /**
280
+ * Narrow to a SET of projects — what the modal's multi-select produces.
281
+ *
282
+ * Takes precedence over `projectId` when present. An empty array is not "no
283
+ * filter", it is "global only": nothing selected means the user has narrowed
284
+ * away every repository, and the memories that remain are the ones that were
285
+ * never a repository's to begin with. Global-scope nodes are always included
286
+ * alongside a non-empty selection, because a user-level convention applies
287
+ * inside every project it is viewed next to.
288
+ */
289
+ projectIds?: string[];
290
+ /** Narrow to a single session's memories. */
291
+ sessionId?: string | null;
292
+ /** Restrict which scopes may match. Defaults to all three. */
293
+ scopes?: GraphScope[];
294
+ /** Restrict to one kind of memory. Defaults to both. */
295
+ kinds?: GraphNodeKind[];
296
+ /** Restrict to particular subkinds (decision, failure, entity, file, …). */
297
+ subkinds?: string[];
298
+ /** Restrict by who wrote it: inferred, asked for by an agent, or hand-written. */
299
+ sources?: GraphSource[];
300
+ /**
301
+ * Let `reach: 'anywhere'` memories from OTHER projects into the results,
302
+ * ranked below equally-matching local ones.
303
+ *
304
+ * Off by default so the modal, the graph view and any listing keep answering
305
+ * "what does this project know". Turn-start injection and the MCP `recall`
306
+ * action turn it on, because that is where "we already solved this in the
307
+ * other repo" has to arrive without being asked for.
308
+ *
309
+ * Structural nodes never travel whatever this says — another repository's
310
+ * file paths are noise here, and admitting them is the leak the hard project
311
+ * filter was originally added to stop.
312
+ */
313
+ crossProject?: boolean;
314
+ /** Maximum hits returned after fusion. */
315
+ limit?: number;
316
+ /** How many hops to expand from directly-matched nodes. 0 disables expansion. */
317
+ expandHops?: number;
318
+ /** Include archived nodes. Defaults to false. */
319
+ includeArchived?: boolean;
320
+ /**
321
+ * Repo-relative paths the session is currently working in. Their structural
322
+ * nodes join the query's seeds, so a turn whose text carries no signal
323
+ * ("continue", "fix it") still reaches the memories attached to the code in
324
+ * front of it.
325
+ */
326
+ anchorPaths?: string[];
327
+ /**
328
+ * Include memories that have been superseded. Off by default: a superseded
329
+ * memory is history, and history competing with the current belief is the
330
+ * failure mode revision exists to remove.
331
+ */
332
+ includeSuperseded?: boolean;
333
+ /**
334
+ * Favour precision over recall — what an explicit search box wants.
335
+ *
336
+ * The vector channel normally admits any positive cosine, because for
337
+ * turn-start injection a weak semantic lead is still worth ranking and BM25
338
+ * corrects it. Typed into a search box that same behaviour looks broken: with
339
+ * static embeddings almost every pair scores positive, so a one-word query
340
+ * returns sixty loosely-related memories and the user concludes the search is
341
+ * wrong. When set, a vector-only hit must stand out from the scanned
342
+ * distribution instead of merely beating zero.
343
+ */
344
+ precise?: boolean;
345
+ }
346
+
347
+ /** How a query was read, and therefore how the two channels were weighted. */
348
+ export interface QueryProfile {
349
+ /** `code` when the query looks like identifiers or paths, `prose` otherwise. */
350
+ shape: 'code' | 'prose' | 'mixed';
351
+ lexicalWeight: number;
352
+ vectorWeight: number;
353
+ }
354
+
355
+ export interface RetrievalResult {
356
+ hits: RetrievalHit[];
357
+ /** True when the vector channel contributed — false while the artifact installs. */
358
+ vectorUsed: boolean;
359
+ /** Wall-clock cost, so the cost of injection stays observable. */
360
+ elapsedMs: number;
361
+ /** How the query was read and how the channels were weighted for it. */
362
+ profile: QueryProfile;
363
+ }
364
+
365
+ // ─────────────────────────────────────────────────────────────────────────────
366
+ // Visualization
367
+ // ─────────────────────────────────────────────────────────────────────────────
368
+
369
+ /** A node as sent to the graph view: display fields plus its community. */
370
+ export interface GraphViewNode {
371
+ id: string;
372
+ kind: GraphNodeKind;
373
+ subkind: GraphNodeSubkind;
374
+ scope: GraphScope;
375
+ label: string;
376
+ projectId: string | null;
377
+ /** Degree, used to size the node. */
378
+ degree: number;
379
+ weight: number;
380
+ pinned: boolean;
381
+ /** Louvain community index — the "lobe" a node belongs to. */
382
+ community: number;
383
+ createdAt: string;
384
+ }
385
+
386
+ export interface GraphViewEdge {
387
+ id: number;
388
+ source: string;
389
+ target: string;
390
+ rel: GraphRelation;
391
+ weight: number;
392
+ }
393
+
394
+ export interface GraphView {
395
+ nodes: GraphViewNode[];
396
+ edges: GraphViewEdge[];
397
+ /** Total nodes matching the filter before any display cap was applied. */
398
+ totalNodes: number;
399
+ /** True when `totalNodes` exceeded the cap and the view was trimmed. */
400
+ truncated: boolean;
401
+ }
402
+
403
+ /**
404
+ * What the extraction queue is doing right now.
405
+ *
406
+ * Surfaced in the UI because the alternative is a feature that silently stops
407
+ * working: recording happens in the background, so a model outage or an
408
+ * unconfigured model looks exactly like "nothing worth remembering happened".
409
+ */
410
+ export interface MemoryQueueStatus {
411
+ /** Conversations waiting to be summarised. */
412
+ pending: number;
413
+ /** Of those, how many have already failed at least once. */
414
+ retrying: number;
415
+ /** Gave up after repeated failures. Kept, and retryable. */
416
+ failed: number;
417
+ /** Being summarised at this moment. */
418
+ running: number;
419
+ /** When the next queued conversation becomes eligible. */
420
+ nextAttemptAt: string | null;
421
+ /** The most recent failure, whatever it was. */
422
+ lastError: string | null;
423
+ /** False when no model is chosen, which is why nothing is being recorded. */
424
+ modelConfigured: boolean;
425
+ }
426
+
427
+ /** How an artifact download ended. `corrupt` and `unpublished` are not retried. */
428
+ export type EmbeddingFailureKind = 'network' | 'corrupt' | 'unpublished';
429
+
430
+ export interface EmbeddingInstallStatus {
431
+ ready: boolean;
432
+ phase: 'idle' | 'downloading' | 'installed' | 'waiting' | 'failed';
433
+ attempts: number;
434
+ error: string | null;
435
+ failure: EmbeddingFailureKind | null;
436
+ /** True when no further automatic attempt is scheduled. */
437
+ permanent: boolean;
438
+ nextAttemptAt: string | null;
439
+ receivedBytes: number;
440
+ totalBytes: number;
441
+ }
442
+
443
+ /** What is still missing before memory works. */
444
+ export type MemoryBlocker = 'embedding' | 'model';
445
+
446
+ /**
447
+ * Whether memory is usable, and what is missing when it is not.
448
+ *
449
+ * The two halves have DIFFERENT prerequisites and are reported separately on
450
+ * purpose: recall needs the embedding artifact, recording only needs a model.
451
+ * Recording therefore runs during setup, so the turns a user has while a 44 MB
452
+ * download completes are still captured — they are usually the ones that
453
+ * establish a project. See backend/memory/readiness.ts.
454
+ */
455
+ export interface MemoryReadiness {
456
+ enabled: boolean;
457
+ canRecall: boolean;
458
+ canRecord: boolean;
459
+ /** True while anything still needs doing; what the setup banner keys on. */
460
+ setupRequired: boolean;
461
+ blockers: MemoryBlocker[];
462
+ embedding: EmbeddingInstallStatus;
463
+ model: { configured: boolean; engine: string | null; modelId: string | null };
464
+ }
465
+
466
+ export interface GraphStats {
467
+ nodes: number;
468
+ edges: number;
469
+ episodic: number;
470
+ structural: number;
471
+ vectors: number;
472
+ byScope: Record<GraphScope, number>;
473
+ byProject: { projectId: string | null; count: number }[];
474
+ /** Memories replaced by a newer belief — history, no longer retrieved. */
475
+ superseded: number;
476
+ /** Memories whose code changed underneath them since they were written. */
477
+ stale: number;
478
+ /** Canonical entity nodes (people, tools, systems) everything else hangs off. */
479
+ entities: number;
480
+ /** Memories a later turn confirmed it actually used. */
481
+ confirmedUseful: number;
482
+ /** Archived or superseded — what the Forgotten list holds. */
483
+ forgotten: number;
484
+ }
485
+
486
+ // ─────────────────────────────────────────────────────────────────────────────
487
+ // Hand-written memory
488
+ // ─────────────────────────────────────────────────────────────────────────────
489
+
490
+ /**
491
+ * A memory a person typed, after it has been shaped but before it is stored.
492
+ *
493
+ * The manual path exists because the automatic one has a hard limit: it can only
494
+ * record what a conversation happened to state. A constraint someone already
495
+ * knows — "never touch the vendored directory", "the staging box is on the old
496
+ * schema until March" — has to be said to an agent before it can be remembered,
497
+ * which means the mistake it would have prevented has usually already happened.
498
+ *
499
+ * The draft is returned for review rather than saved directly. What the user
500
+ * typed is one field; what the graph stores is six, and letting a model fill the
501
+ * other five without showing its work would mean a store whose contents nobody
502
+ * had actually read.
503
+ */
504
+ export interface MemoryDraft {
505
+ subkind: EpisodicSubkind;
506
+ scope: 'project' | 'global';
507
+ label: string;
508
+ body: string;
509
+ /** Named subjects, which become canonical entity nodes on save. */
510
+ entities: string[];
511
+ /** Repo-relative paths the memory concerns, which become `about` edges. */
512
+ relatedPaths: string[];
513
+ /** True when a model shaped this, false when it is the raw text split in two. */
514
+ structured: boolean;
515
+ /** An existing memory that already says this, if one was found. */
516
+ duplicateOf: { id: string; label: string; score: number } | null;
517
+ /** Why the model was not used, when it was not. Shown as a quiet note. */
518
+ note: string | null;
519
+ }
@@ -32,6 +32,7 @@ export type LogLabel =
32
32
  | 'commands'
33
33
  | 'subagents'
34
34
  | 'instructions'
35
+ | 'memory'
35
36
  | 'permissions'
36
37
  | 'profiles'
37
38
  | 'notification'