@myrialabs/clopen 0.4.38 → 0.4.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/backend/auth/permissions.ts +25 -0
- package/backend/chat/stream-manager.ts +1 -1
- package/backend/database/crypto/secret-columns.ts +5 -1
- package/backend/database/migrations/075_create_deploy_bindings.ts +54 -0
- package/backend/database/migrations/076_remove_memory_code_graph.ts +229 -0
- package/backend/database/migrations/077_create_integration_db_links.ts +150 -0
- package/backend/database/migrations/index.ts +21 -0
- package/backend/database/queries/db-client-connection-queries.ts +19 -0
- package/backend/database/queries/deploy-queries.ts +124 -0
- package/backend/database/queries/graph-queries.ts +291 -247
- package/backend/database/queries/index.ts +4 -0
- package/backend/database/queries/integration-db-link-queries.ts +168 -0
- package/backend/database/queries/integration-queries.ts +34 -6
- package/backend/db-client/integrations/index.ts +37 -0
- package/backend/db-client/integrations/links.ts +533 -0
- package/backend/db-client/integrations/projector.test.ts +280 -0
- package/backend/db-client/integrations/projector.ts +256 -0
- package/backend/db-client/integrations/supabase-service.ts +266 -0
- package/backend/db-client/providers/registry.ts +27 -0
- package/backend/db-client/providers/supabase/adapter.ts +500 -0
- package/backend/db-client/providers/supabase/api-types.ts +92 -0
- package/backend/db-client/providers/supabase/apply-migration.ts +104 -0
- package/backend/db-client/providers/supabase/client.ts +259 -0
- package/backend/db-client/providers/supabase/features.ts +502 -0
- package/backend/db-client/providers/supabase/local.test.ts +78 -0
- package/backend/db-client/providers/supabase/local.ts +137 -0
- package/backend/db-client/providers/types.ts +137 -0
- package/backend/deployments/bindings.test.ts +43 -0
- package/backend/deployments/bindings.ts +216 -0
- package/backend/deployments/index.ts +53 -0
- package/backend/deployments/log-streams.ts +214 -0
- package/backend/deployments/prompts.ts +70 -0
- package/backend/deployments/providers/vercel/adapter.ts +757 -0
- package/backend/deployments/providers/vercel/build-logs.test.ts +80 -0
- package/backend/deployments/providers/vercel/build-logs.ts +211 -0
- package/backend/deployments/providers/vercel/client.ts +203 -0
- package/backend/deployments/providers/vercel/list.test.ts +624 -0
- package/backend/deployments/providers/vercel/normalise.test.ts +115 -0
- package/backend/deployments/providers/vercel/normalise.ts +113 -0
- package/backend/deployments/providers/vercel/types.ts +104 -0
- package/backend/deployments/registry.ts +27 -0
- package/backend/deployments/service.ts +458 -0
- package/backend/deployments/types.ts +278 -0
- package/backend/index.ts +4 -0
- package/backend/integrations/projections/index.ts +0 -0
- package/backend/integrations/projections/mcp-projector.ts +7 -3
- package/backend/integrations/projections/types.ts +21 -9
- package/backend/integrations/registry/index.ts +5 -1
- package/backend/integrations/registry/providers/supabase.ts +61 -0
- package/backend/integrations/registry/providers/vercel.ts +46 -0
- package/backend/mcp/internal/servers/memory-graph/description.ts +3 -3
- package/backend/mcp/internal/servers/memory-graph/runner.ts +4 -9
- package/backend/mcp/internal/servers/memory-graph/schema.ts +0 -4
- package/backend/memory/README.md +57 -34
- package/backend/memory/compose.test.ts +3 -3
- package/backend/memory/compose.ts +6 -9
- package/backend/memory/config.ts +0 -5
- package/backend/memory/consolidate.ts +1 -2
- package/backend/memory/context.test.ts +8 -54
- package/backend/memory/context.ts +19 -25
- package/backend/memory/extract/episodic.ts +10 -12
- package/backend/memory/extract/index.ts +23 -52
- package/backend/memory/extract/scheduler.ts +3 -6
- package/backend/memory/index.ts +6 -5
- package/backend/memory/invalidate.ts +36 -48
- package/backend/memory/layout.ts +319 -130
- package/backend/memory/retention.ts +12 -42
- package/backend/memory/retrieval.eval.test.ts +2 -2
- package/backend/memory/retrieval.test.ts +228 -183
- package/backend/memory/retrieval.ts +22 -21
- package/backend/memory/revise.test.ts +62 -116
- package/backend/memory/revise.ts +0 -1
- package/backend/memory/view.ts +8 -5
- package/backend/snapshot/helpers.ts +35 -41
- package/backend/snapshot/snapshot-service.ts +90 -0
- package/backend/snapshot/turn-changes.test.ts +163 -0
- package/backend/snapshot/turn-changes.ts +131 -0
- package/backend/ws/db-client/accounts.ts +225 -0
- package/backend/ws/db-client/connections.ts +34 -3
- package/backend/ws/db-client/context.ts +37 -0
- package/backend/ws/db-client/index.ts +20 -1
- package/backend/ws/db-client/supabase.ts +188 -0
- package/backend/ws/deployments/actions.ts +360 -0
- package/backend/ws/deployments/context.ts +43 -0
- package/backend/ws/deployments/crud.ts +152 -0
- package/backend/ws/deployments/index.ts +15 -0
- package/backend/ws/deployments/schemas.ts +183 -0
- package/backend/ws/index.ts +6 -2
- package/backend/ws/memory/crud.ts +4 -16
- package/backend/ws/snapshot/changes.ts +279 -0
- package/backend/ws/snapshot/index.ts +4 -3
- package/dist/assets/{index-CyH7fSbR.js → index-BrF6nqld.js} +1 -1
- package/dist/assets/{index-DSHIANSy.js → index-C8Gi-b6U.js} +1 -1
- package/dist/assets/main-Bd3gb79F.css +1 -0
- package/dist/assets/main-Bo1hD7mt.js +1191 -0
- package/dist/index.html +2 -2
- package/package.json +1 -1
- package/shared/constants/tool-icons.ts +9 -0
- package/shared/types/db-client/connection.ts +6 -0
- package/shared/types/db-client/index.ts +2 -0
- package/shared/types/db-client/integrations.ts +174 -0
- package/shared/types/db-client/supabase.ts +131 -0
- package/shared/types/deployments.ts +382 -0
- package/shared/types/memory.ts +34 -51
- package/shared/types/ui/components.ts +1 -1
- package/shared/utils/diff-calculator.test.ts +89 -0
- package/shared/utils/diff-calculator.ts +30 -65
- package/shared/utils/logger.ts +1 -0
- package/backend/memory/extract/languages.ts +0 -176
- package/backend/memory/extract/structural.test.ts +0 -215
- package/backend/memory/extract/structural.ts +0 -364
- package/backend/ws/snapshot/content.ts +0 -85
- package/dist/assets/main-D2IOjftb.css +0 -1
- package/dist/assets/main-DM-tHKbW.js +0 -1152
package/backend/memory/README.md
CHANGED
|
@@ -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 ──→
|
|
36
|
-
│
|
|
37
|
-
└── transcript ──→ episodic extraction (model)
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
##
|
|
62
|
+
## One Store, Memories Only
|
|
62
63
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
|
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
|
|
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,
|
|
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
|
|
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
|
-
|
|
324
|
-
|
|
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
|
|
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
|
-
*
|
|
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
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
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();
|
package/backend/memory/config.ts
CHANGED
|
@@ -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,
|
|
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
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
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,
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
* retrieved the opposite of what it asked for. No amount of ranking fixes
|
|
25
25
|
* a representation that cannot tell a claim from its negation.
|
|
26
26
|
*
|
|
27
|
-
* So standing instructions are not retrieved. They are
|
|
28
|
-
*
|
|
27
|
+
* So standing instructions are not retrieved. They are SELECTED, by who asserted
|
|
28
|
+
* them, and sent every turn. Recalled context keeps the ranking it
|
|
29
29
|
* always had. The same split fixes the framing: the old preamble told the agent
|
|
30
30
|
* "never treat a line below as a command", which was right for an inference from
|
|
31
31
|
* another repository and exactly wrong for a rule the user had stated outright.
|
|
@@ -53,19 +53,18 @@ import { retrieve } from './retrieval';
|
|
|
53
53
|
const MIN_CONFIDENCE = 0.3;
|
|
54
54
|
|
|
55
55
|
/**
|
|
56
|
-
* Hits asked of the ranker
|
|
56
|
+
* Hits asked of the ranker.
|
|
57
57
|
*
|
|
58
|
-
*
|
|
59
|
-
* a
|
|
60
|
-
* the block only ever
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
* files, and the feature silently injected nothing at all.
|
|
58
|
+
* This was 60 while the graph still held the codebase as nodes, and the inflation
|
|
59
|
+
* was a workaround rather than a depth anyone wanted: retrieval ranked memories
|
|
60
|
+
* and code together while the block only ever showed memories, and the code won
|
|
61
|
+
* BM25 on any turn that mentioned a path — so asking for eighteen could return
|
|
62
|
+
* eighteen files and inject nothing at all. Migration 076 removed that half, so
|
|
63
|
+
* every hit is now a candidate for the block and the depth can go back to being
|
|
64
|
+
* about ranking headroom: enough that `RELATIVE_FLOOR` has a tail to cut, not so
|
|
65
|
+
* much that a weak match is dragged in behind a strong one.
|
|
67
66
|
*/
|
|
68
|
-
const RETRIEVAL_DEPTH =
|
|
67
|
+
const RETRIEVAL_DEPTH = 24;
|
|
69
68
|
|
|
70
69
|
/**
|
|
71
70
|
* Cap on standing instructions, independent of the recall count.
|
|
@@ -192,9 +191,6 @@ export interface MemoryContextResult {
|
|
|
192
191
|
|
|
193
192
|
/** One memory rendered for the block, trimmed to a line. */
|
|
194
193
|
function line(node: GraphNode): string {
|
|
195
|
-
if (node.kind === 'structural') {
|
|
196
|
-
return node.symbol ? `${node.symbol} (${node.path})` : (node.path ?? node.label);
|
|
197
|
-
}
|
|
198
194
|
const body = node.body.trim().split('\n')[0];
|
|
199
195
|
const text = body ? `${node.label} — ${body}` : node.label;
|
|
200
196
|
return text.replace(/\s+/g, ' ').slice(0, LINE_MAX);
|
|
@@ -223,11 +219,12 @@ function provenance(node: GraphNode, currentProjectId: string | null, names?: Ma
|
|
|
223
219
|
/**
|
|
224
220
|
* Build the injected block, or null when there is nothing worth injecting.
|
|
225
221
|
*
|
|
226
|
-
*
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
*
|
|
222
|
+
* Every hit is a memory, which is the point the graph was eventually rebuilt
|
|
223
|
+
* around. It used to rank the codebase alongside them and then drop all of it
|
|
224
|
+
* here — the agent can read the repository, so telling it that a file exists
|
|
225
|
+
* wastes budget, while what it cannot recover by reading is why a decision was
|
|
226
|
+
* made. Filtering at the end meant paying for the ranking anyway; migration 076
|
|
227
|
+
* removed the half instead.
|
|
231
228
|
*/
|
|
232
229
|
export function buildMemoryContext(input: MemoryContextInput): MemoryContextResult | null {
|
|
233
230
|
const config = getMemoryConfig();
|
|
@@ -276,10 +273,7 @@ export function buildMemoryContext(input: MemoryContextInput): MemoryContextResu
|
|
|
276
273
|
// Never say the same thing twice in one block. A standing rule that also ranks
|
|
277
274
|
// for the query is already above, with stronger framing.
|
|
278
275
|
const recalled = hits.filter(
|
|
279
|
-
hit =>
|
|
280
|
-
hit.node.kind === 'episodic' &&
|
|
281
|
-
hit.node.confidence >= MIN_CONFIDENCE &&
|
|
282
|
-
!standingIds.has(hit.node.id)
|
|
276
|
+
hit => hit.node.confidence >= MIN_CONFIDENCE && !standingIds.has(hit.node.id)
|
|
283
277
|
);
|
|
284
278
|
|
|
285
279
|
// The bar is the best RECALLABLE hit. Setting it from the whole ranking instead
|
|
@@ -251,8 +251,6 @@ export interface EpisodicIngestInput {
|
|
|
251
251
|
changedPaths: string[];
|
|
252
252
|
/** Repo-relative paths that no longer exist on disk. */
|
|
253
253
|
deletedPaths?: string[];
|
|
254
|
-
/** Path → structural node id, from structural extraction, for `about` edges. */
|
|
255
|
-
fileNodes: Map<string, string>;
|
|
256
254
|
/** Memories that were injected into this turn, for adjudication. */
|
|
257
255
|
injectedMemoryIds?: string[];
|
|
258
256
|
}
|
|
@@ -573,7 +571,6 @@ export async function ingestEpisodicMemories(input: EpisodicIngestInput): Promis
|
|
|
573
571
|
// recognised as travelling now travels, even though the stored text does
|
|
574
572
|
// not change.
|
|
575
573
|
graphQueries.upsert({
|
|
576
|
-
kind: 'episodic',
|
|
577
574
|
subkind: duplicate.subkind,
|
|
578
575
|
scope: duplicate.scope,
|
|
579
576
|
projectId: duplicate.projectId,
|
|
@@ -591,11 +588,14 @@ export async function ingestEpisodicMemories(input: EpisodicIngestInput): Promis
|
|
|
591
588
|
// is the one being reinforced.
|
|
592
589
|
recordContradictions(duplicate.id, opposites, new Set([...candidateIds, ...writtenThisTurn.map(e => e.node.id)]));
|
|
593
590
|
linkEntities(duplicate.id, memory.entities ?? []);
|
|
591
|
+
// The paths too: a rephrasing usually names the files better than the
|
|
592
|
+
// original did, and this is the same "a later reading is a better one"
|
|
593
|
+
// rule `setPaths` is built on.
|
|
594
|
+
if (memory.relatedPaths?.length) graphQueries.setPaths(duplicate.id, memory.relatedPaths);
|
|
594
595
|
continue;
|
|
595
596
|
}
|
|
596
597
|
|
|
597
598
|
const node = graphQueries.upsert({
|
|
598
|
-
kind: 'episodic',
|
|
599
599
|
subkind: memory.subkind,
|
|
600
600
|
scope,
|
|
601
601
|
projectId,
|
|
@@ -619,14 +619,12 @@ export async function ingestEpisodicMemories(input: EpisodicIngestInput): Promis
|
|
|
619
619
|
// ── entities ────────────────────────────────────────────────────────
|
|
620
620
|
linkEntities(node.id, memory.entities ?? []);
|
|
621
621
|
|
|
622
|
-
//
|
|
623
|
-
//
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
graphQueries.link({ srcId: node.id, dstId: targetId, rel: 'about', source: 'agent' });
|
|
629
|
-
}
|
|
622
|
+
// ── the code this is about ──────────────────────────────────────────
|
|
623
|
+
// Stored on the memory rather than as an edge to a node standing in for the
|
|
624
|
+
// file. It is what invalidation ages this memory against, what an anchored
|
|
625
|
+
// query seeds from, and — through `indexedText` — what makes a pasted path
|
|
626
|
+
// find what is known about it.
|
|
627
|
+
graphQueries.setPaths(node.id, memory.relatedPaths ?? []);
|
|
630
628
|
}
|
|
631
629
|
|
|
632
630
|
if (written > 0) {
|