@zenera/cli 1.1.54 → 1.1.56

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 (32) hide show
  1. package/dist/archive.js +3 -1
  2. package/dist/batch.d.ts +7 -7
  3. package/dist/batch.js +18 -27
  4. package/dist/commands/export.js +82 -62
  5. package/dist/commands/inspect.js +6 -6
  6. package/dist/commands/memory.js +80 -39
  7. package/dist/commands/sandbox.js +1 -17
  8. package/dist/meta/finetune/memories.d.ts +1 -1
  9. package/dist/meta/finetune/memories.js +25 -8
  10. package/dist/sandbox.js +1 -1
  11. package/dist/validate.js +6 -8
  12. package/package.json +4 -4
  13. package/templates/editor/.github/copilot-instructions.md +17 -30
  14. package/templates/editor/.github/skills/zen-analyze-run/SKILL.md +2 -1
  15. package/templates/editor/.github/skills/zen-cli/SKILL.md +1 -1
  16. package/templates/editor/.github/skills/zen-cli/references/export.md +7 -6
  17. package/templates/editor/.github/skills/zen-cli/references/memory.md +14 -13
  18. package/templates/editor/.github/skills/zen-cli/references/run.md +5 -5
  19. package/templates/editor/.github/skills/zen-finetune/SKILL.md +1 -1
  20. package/templates/editor/.github/skills/zen-finetune/scripts/memory.mjs +21 -7
  21. package/templates/editor/.github/skills/zen-finetune/scripts/report.mjs +2 -2
  22. package/templates/editor/.github/skills/zen-instructions/SKILL.md +3 -2
  23. package/templates/editor/.github/skills/zen-memory/SKILL.md +38 -38
  24. package/templates/editor/.github/skills/zen-memory-warmup/SKILL.md +2 -2
  25. package/templates/editor/.github/skills/zen-review/SKILL.md +3 -3
  26. package/templates/editor/.github/skills/zen-review/scripts/check-paths.sh +3 -3
  27. package/templates/editor/.github/skills/zen-sandbox/SKILL.md +5 -16
  28. package/templates/editor/.vscode/agents.schema.json +3 -2
  29. package/templates/project/agents/files-instructions.md +3 -2
  30. package/templates/project/agents/memory-instructions.md +8 -6
  31. package/templates/project/gitignore +6 -4
  32. package/templates/project/sandbox/Dockerfile.tmpl +28 -2
@@ -1,9 +1,9 @@
1
- import { appendFileSync, cpSync, existsSync, mkdirSync, readFileSync, rmSync } from 'node:fs';
1
+ import { isMemory, MemoryStore } from '@zenera/neo';
2
+ import { appendFileSync, cpSync, mkdirSync, readFileSync, rmSync } from 'node:fs';
2
3
  import { basename, join } from 'node:path';
3
4
  import { DatasetStore } from "./dataset/store.js";
4
5
  import { errorIn, sizeOf } from "./failure.js";
5
6
  import { writeFeedback } from "./report.js";
6
- import { readJson } from "./tuning.js";
7
7
  function rows(file) {
8
8
  try {
9
9
  return readFileSync(file, 'utf8')
@@ -15,6 +15,24 @@ function rows(file) {
15
15
  return [];
16
16
  }
17
17
  }
18
+ /** How big a memory is, or nothing when there is no memory there to open. */
19
+ async function sizeOfMemory(dir) {
20
+ if (!isMemory(dir)) {
21
+ return undefined;
22
+ }
23
+ try {
24
+ const store = await MemoryStore.open(dir, { readOnly: true });
25
+ try {
26
+ return { nodes: store.graph.order, edges: store.graph.size };
27
+ }
28
+ finally {
29
+ store.release();
30
+ }
31
+ }
32
+ catch {
33
+ return undefined;
34
+ }
35
+ }
18
36
  export class Memories {
19
37
  #t;
20
38
  #chain = Promise.resolve();
@@ -47,7 +65,7 @@ export class Memories {
47
65
  return;
48
66
  }
49
67
  const dir = join(this.dir, 'submitted', key);
50
- const empty = !existsSync(join(run.memory, 'manifest.json'));
68
+ const empty = !isMemory(run.memory);
51
69
  rmSync(dir, { recursive: true, force: true });
52
70
  if (!empty) {
53
71
  cpSync(run.memory, dir, {
@@ -116,7 +134,7 @@ export class Memories {
116
134
  .finally(() => {
117
135
  this.merging = undefined;
118
136
  });
119
- const manifest = readJson(join(target, 'manifest.json'));
137
+ const size = await sizeOfMemory(target);
120
138
  const row = {
121
139
  n,
122
140
  name,
@@ -125,14 +143,13 @@ export class Memories {
125
143
  log,
126
144
  includes: [...(last?.includes ?? []), ...fresh.map((s) => s.key)],
127
145
  added: fresh.map((s) => s.key),
128
- ok: res.code === 0 && manifest !== undefined,
129
- ...(manifest?.nodes !== undefined ? { nodes: manifest.nodes } : {}),
130
- ...(manifest?.edges !== undefined ? { edges: manifest.edges } : {}),
146
+ ok: res.code === 0 && size !== undefined,
147
+ ...(size ? { nodes: size.nodes, edges: size.edges } : {}),
131
148
  };
132
149
  appendFileSync(join(this.dir, 'merges.jsonl'), `${JSON.stringify(row)}\n`);
133
150
  if (!row.ok) {
134
151
  const e = errorIn(log, from);
135
- this.#t.error(`memory ${name}`, e.message ?? 'the merge wrote no manifest', e.log);
152
+ this.#t.error(`memory ${name}`, e.message ?? 'the merge wrote no memory', e.log);
136
153
  }
137
154
  const store = DatasetStore.open(this.#t.root);
138
155
  for (const s of fresh) {
package/dist/sandbox.js CHANGED
@@ -18,7 +18,7 @@ export async function preflight(setup, yes) {
18
18
  yes,
19
19
  });
20
20
  // A resumed session restarts its own stopped container, which needs no lock.
21
- await assertLocks(1, { reuses: setup.pool.for().name });
21
+ await assertLocks(1, { reuses: setup.sandbox.name });
22
22
  READY.add(setup.image);
23
23
  }
24
24
  //# sourceMappingURL=sandbox.js.map
package/dist/validate.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { SHAPES, auditModels, credentialFor, envNames, form, machinePluginTools, PLUGINS_ENV, resolveBuild, } from '@zenera/engine';
2
- import { EXA_GROUP, FileSkillProvider, SANDBOX_MOUNT, Sandbox, exaTools, fileTools, frontmatter, projectRegistry, readProjectConfig, sandboxTools, selectTools, toList, } from '@zenera/neo';
2
+ import { EXA_GROUP, FileSkillProvider, PodmanSandbox, WORKSPACE_MOUNT, exaTools, fileTools, frontmatter, projectRegistry, readProjectConfig, sandboxTools, selectTools, toList, } from '@zenera/neo';
3
3
  import { existsSync, mkdtempSync, readFileSync, readdirSync, realpathSync, rmSync, statSync, writeFileSync, } from 'node:fs';
4
4
  import { tmpdir } from 'node:os';
5
5
  import { basename, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
@@ -625,9 +625,9 @@ export function availableTools(root, config) {
625
625
  return [
626
626
  ...fileTools({
627
627
  root,
628
- mount: config.sandbox?.workdir ?? SANDBOX_MOUNT,
628
+ mount: config.sandbox?.workdir ?? WORKSPACE_MOUNT,
629
629
  }),
630
- ...sandboxTools({ root, key: 'check' }),
630
+ ...sandboxTools(new PodmanSandbox({ root, key: 'check' })),
631
631
  ...exaTools(),
632
632
  ];
633
633
  }
@@ -1435,7 +1435,7 @@ async function probeSandbox(config, build, opts, add) {
1435
1435
  return false;
1436
1436
  }
1437
1437
  const root = realpathSync(mkdtempSync(join(tmpdir(), 'zen-check-')));
1438
- const box = new Sandbox({
1438
+ const box = new PodmanSandbox({
1439
1439
  root,
1440
1440
  key: 'check',
1441
1441
  image,
@@ -1444,13 +1444,11 @@ async function probeSandbox(config, build, opts, add) {
1444
1444
  network: config.sandbox?.network,
1445
1445
  workdir: config.sandbox?.workdir,
1446
1446
  user: config.sandbox?.user,
1447
- engine,
1448
- exec: opts.exec,
1449
1447
  // Not the project's: a check forwards no host values, and keeping the
1450
1448
  // container is the caller's choice about their work, not about this.
1451
1449
  env: {},
1452
1450
  persist: false,
1453
- });
1451
+ }, { engine, exec: opts.exec });
1454
1452
  opts.onProgress?.(`starting ${image ?? 'the container'}`);
1455
1453
  try {
1456
1454
  const res = await box.exec([
@@ -1483,7 +1481,7 @@ async function probeSandbox(config, build, opts, add) {
1483
1481
  return false;
1484
1482
  }
1485
1483
  finally {
1486
- await box.dispose().catch(() => undefined);
1484
+ await box.close().catch(() => undefined);
1487
1485
  rmSync(root, { recursive: true, force: true });
1488
1486
  }
1489
1487
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenera/cli",
3
- "version": "1.1.54",
3
+ "version": "1.1.56",
4
4
  "description": "Command-line front end for @zenera/neo: agentic projects you can run, share and commit.",
5
5
  "keywords": [
6
6
  "agents",
@@ -54,9 +54,9 @@
54
54
  "@google/genai": "^2.30.0",
55
55
  "@inkjs/ui": "^2.0.0",
56
56
  "@openrouter/sdk": "^1.4.25",
57
- "@zenera/engine": "^1.1.54",
58
- "@zenera/neo": "^1.1.54",
59
- "@zenera/view": "^1.1.54",
57
+ "@zenera/engine": "^1.1.56",
58
+ "@zenera/neo": "^1.1.56",
59
+ "@zenera/view": "^1.1.56",
60
60
  "google-auth-library": "^10.0.0",
61
61
  "ink": "^7.1.1",
62
62
  "openai": "^6.0.0",
@@ -128,9 +128,9 @@ reports the first as `memory.uninstructed` and the second as `rules.stale` -
128
128
  by bytes, so trailing whitespace inside a table, invisible on screen, is caught
129
129
  too - and `zen check --fix` repairs both.
130
130
 
131
- Nothing else tells a running agent how the store works, so without it nothing
132
- forbids an agent from pointing `grep` or `cat` at `/memory` - a read that
133
- bypasses the audience mask and serves superseded nodes as current. Leave the
131
+ Nothing else tells a running agent how the store works, so without it an agent
132
+ guesses at paths for remembered files instead of copying them into the workspace
133
+ with `memory_copy_file`, and treats a stale recollection as current. Leave the
134
134
  file untouched and put this project's own memory policy in a second topic file,
135
135
  `agents/memory-policy-instructions.md`, which is read straight after it: then
136
136
  `zen check --fix` can replace the first after any upgrade without losing
@@ -381,10 +381,10 @@ it. Its entire world is the tools it was granted (§3.5) and four paths:
381
381
  | `/workspace` | the session's workspace - the work itself | read/write; `zen run --read-only` withholds the writes |
382
382
  | `/assets` | `assets/`, reference material - §3.11 | read-only |
383
383
  | `/skills` | the whole skill catalog - §3.4.1 | read-only |
384
- | `/memory` | files carried by remembered nodes - §5.3 | read-only, and only when `memory:` is configured |
385
384
 
386
385
  Commands run inside the container `sandbox:` describes (§3.7): the same
387
- `/workspace`, and whatever the image ships.
386
+ `/workspace`, and whatever the image ships. Remembered files are not mounted
387
+ anywhere: an agent copies one into `/workspace` with `memory_copy_file` (§5.3).
388
388
 
389
389
  Everything else in the project directory is **invisible at run time** -
390
390
  `agents.yaml`, `agents/instructions.md`, `agents/prompts/`, `agents/skills/`
@@ -413,8 +413,9 @@ Run this over every `agents/*instructions.md`, every `agents/prompts/*.md` and
413
413
  every `agents/skills/*/SKILL.md` after editing any of them. Every path-shaped
414
414
  token in those files is read by a model as an instruction to open something:
415
415
 
416
- - [ ] Every absolute path begins `/workspace`, `/assets`, `/skills` or
417
- `/memory`. Nothing else exists.
416
+ - [ ] Every absolute path begins `/workspace`, `/assets` or `/skills`. Nothing
417
+ else exists - remembered files included; they reach the workspace through
418
+ `memory_copy_file`.
418
419
  - [ ] No project file is named: `agents.yaml`, `agents/instructions.md`,
419
420
  `agents/prompts/…`, `agents/skills/…`, `sandbox/Dockerfile`, `.env`,
420
421
  `.github/…`, `sessions/…`, `SPECIFICATION.md`, `README.md`, `docs/…`.
@@ -426,8 +427,8 @@ token in those files is read by a model as an instruction to open something:
426
427
  - [ ] A skill referring to its own sibling file writes the full
427
428
  `/skills/<name>/` prefix, not `./rates.csv`: the body is rendered into a
428
429
  prompt, not executed from its folder.
429
- - [ ] `/memory` is named only in prompts for agents that have `memory:` (§5.3),
430
- and `/assets` only where an `assets/` directory exists.
430
+ - [ ] `memory_copy_file` is named only in prompts for agents that have
431
+ `memory:` (§5.3), and `/assets` only where an `assets/` directory exists.
431
432
  - [ ] The agent holding the prompt has the tool the path implies - `read_file`
432
433
  to open one, `sandbox:*` to run one (§3.4.1).
433
434
  - [ ] Every instruction that opens a file states what to do when it is not there
@@ -1031,22 +1032,9 @@ prompt is executed on every run, by an agent that is root in a filesystem that
1031
1032
  is about to be thrown away.
1032
1033
 
1033
1034
  Agents share one container, because they share the workspace and a hand-off is
1034
- meant to be continuous. An agent that needs something else says so and gets its
1035
- own, with its block merged over the top-level one:
1036
-
1037
- ```yaml
1038
- sandbox:
1039
- image: docker.io/library/python:3.14-slim-bookworm
1040
-
1041
- agents:
1042
- - name: builder
1043
- tools: [files:*, sandbox:*]
1044
- sandbox:
1045
- image: docker.io/library/node:22-bookworm-slim
1046
- memory: 8192
1047
- - name: analyst
1048
- tools: [files:*, sandbox:*] # shares the project's container
1049
- ```
1035
+ meant to be continuous. There is one `sandbox:` block, at the top level; an
1036
+ agent cannot have its own (`agents[].sandbox` fails to load). A tool one agent
1037
+ needs goes into the project's image, so every agent has it.
1050
1038
 
1051
1039
  **Write `persist: true` unless you have a reason not to.** By default the
1052
1040
  container is _removed_ when the session closes, and only two paths survive it:
@@ -1407,7 +1395,7 @@ zen check --fix
1407
1395
 
1408
1396
  It is what tells the agent that the store is reached only through the tools, that
1409
1397
  `memory_search` clips a node's text and `memory_load` reads it whole, that a
1410
- remembered file's path comes from `memory_load` and not from listing `/memory`,
1398
+ remembered file is run by copying it into the workspace with `memory_copy_file`,
1411
1399
  what a node must carry to be worth having, and that a correction is a
1412
1400
  `SUPERSEDES` edge rather than an edit. It is its own file rather than a section of
1413
1401
  `agents/instructions.md` because it arrives with the `memory:` block and leaves
@@ -1431,7 +1419,7 @@ persist. Anything authoritative - a rate, a policy clause, a procedure - belongs
1431
1419
  in a skill, where it is versioned and reviewable.
1432
1420
 
1433
1421
  The full treatment - kinds and relations, how ranking and stitching spend their
1434
- budget, remembered files under `/memory`, audience design, and how to put memory
1422
+ budget, remembered files and `memory_copy_file`, audience design, and how to put memory
1435
1423
  in front of a `zen rag` index - is in the `zen-memory` skill.
1436
1424
 
1437
1425
  ### 5.4 Cache discipline
@@ -1979,8 +1967,7 @@ Before finishing any change here:
1979
1967
  candidates; these are the judgements to make about each one)**
1980
1968
 
1981
1969
  - [ ] Every absolute path in `agents/*instructions.md`, `agents/prompts/*.md` and
1982
- `agents/skills/*/SKILL.md` is under `/workspace`, `/assets`, `/skills` or
1983
- `/memory`
1970
+ `agents/skills/*/SKILL.md` is under `/workspace`, `/assets` or `/skills`
1984
1971
  - [ ] No prompt or skill names a project file - `agents.yaml`, a prompt path, a
1985
1972
  skill's repository path, `sandbox/Dockerfile`, `.env`, `sessions/`
1986
1973
  - [ ] No `../`, `~`, or host path; nothing assumes the workspace is the project
@@ -2089,7 +2076,7 @@ candidates; these are the judgements to make about each one)**
2089
2076
  | Fails only on genuinely hard cases | Promote that agent's tier, or split the hard path out |
2090
2077
  | Shows no reasoning while it works | Turn summaries on for that model - §7.6 |
2091
2078
  | Forgets across conversations | Continue the session rather than starting a new one |
2092
- | Greps `/memory` or reads `graph.json` | `agents/memory-instructions.md` is missing the block - §5.3 |
2079
+ | Guesses a path for a remembered file | `agents/memory-instructions.md` is missing the block - §5.3 |
2093
2080
  | Recalls a note it cannot check or continue | Same block: it is what requires provenance on every node - §5.3 |
2094
2081
  | Breaks at load with a named path | Read the message - it names the exact key |
2095
2082
 
@@ -268,7 +268,8 @@ steps 2-3. Otherwise work through these with node ids:
268
268
  memory (`--dir <memory dir>`). Today's results are only a findability
269
269
  probe: memory may have changed since the run. Do not claim a hit was
270
270
  available then, or memory was empty then, without historical evidence.
271
- 5. **Wrong channel.** Any `run_command` or file tool touching `/memory` breaks
271
+ 5. **Wrong channel.** A remembered file is reached only by `memory_copy_file`;
272
+ a `run_command` or file tool guessing a path for one breaks
272
273
  `agents/memory-instructions.md`.
273
274
 
274
275
  ### Memory - saved correctly
@@ -26,7 +26,7 @@ zen key <ls|add|use|check|rm|show|env> [ref] [options]
26
26
  zen models <providers|ls|search|show|test|browse> [ref] [options]
27
27
  zen check [name|dir] [--project <name|dir>] [--no-sandbox] [--no-models] [--strict] [--quiet]
28
28
  zen inspect [report|graph|node|ask] [run] [--dir <run dir>] [--part <name>] [--full] [--open]
29
- zen memory [stats|ls|search|grep|show|export|merge|forget] [args] [options]
29
+ zen memory [stats|ls|search|grep|show|export|merge|forget|migrate] [args] [options]
30
30
  zen export [project] [--out <file>] [--no-vectors] [--no-memory] [--force]
31
31
  zen import <file.zip> [dir] [--name <name>] [--force] [--no-register]
32
32
  zen sandbox [status|up|pull|clean|disk] [options]
@@ -22,7 +22,7 @@ one silently replaced; an `--out` that already exists is a usage error until
22
22
  | `--out <file>` | Where the archive goes |
23
23
  | `--no-vectors` | Leave out `assets/**/lance/` - much smaller, needs a restore |
24
24
  | `--no-memory` | Leave out `memory/` entirely |
25
- | `--force` | Overwrite the target, and export past a held memory lock |
25
+ | `--force` | Overwrite the target |
26
26
 
27
27
  ### What travels
28
28
 
@@ -44,8 +44,10 @@ knows which credentials to supply without being handed any.
44
44
 
45
45
  This is the decision the command is built around. A rag index without its
46
46
  `lance/` tree looks built and cannot search, and memory has no fallback at all:
47
- a graph without `vectors.f32` recalls by term overlap until every node is
48
- written again. So the default archive works when it is opened.
47
+ a memory without its vectors recalls by term overlap until every node is
48
+ written again. So the default archive works when it is opened. The memory
49
+ travels as a snapshot of its database taken at one moment, so a run writing to
50
+ it meanwhile cannot tear the archive.
49
51
 
50
52
  `--no-vectors` makes a much smaller one for someone who will run
51
53
  `zen rag <subject> restore` on arrival. The manifest records the choice and
@@ -53,9 +55,8 @@ written again. So the default archive works when it is opened.
53
55
 
54
56
  ### What it refuses
55
57
 
56
- Only one thing: memory held by a live run, because a graph copied mid-write is
57
- an archive that opens and is wrong. `--force` overrides it, and
58
- `--no-memory` sidesteps it.
58
+ Nothing for being busy: memory is copied as of one moment, so a run writing
59
+ to it meanwhile cannot tear the archive.
59
60
 
60
61
  A project that fails `zen check` is exported anyway, with a warning. Sending
61
62
  someone a broken project to ask for help is a legitimate reason to export one.
@@ -1,7 +1,7 @@
1
1
  # Memory - `zen memory`
2
2
 
3
3
  ```
4
- zen memory [stats|ls|search|grep|show|export|merge|forget] [args] [options]
4
+ zen memory [stats|ls|search|grep|show|export|merge|forget|migrate] [args] [options]
5
5
  ```
6
6
 
7
7
  Alias: `mem`.
@@ -29,9 +29,10 @@ skill.
29
29
  | `zen memory export [f]` | The whole graph as one HTML page |
30
30
  | `zen memory merge <dir…>` | Fold other memories into this one |
31
31
  | `zen memory forget <id…>` | Remove nodes, their vectors and their files |
32
+ | `zen memory migrate` | Convert a version 1 memory (`graph.json`) once |
32
33
 
33
34
  `ls` cuts the text to the terminal's width; piped, or run by an agent, it prints
34
- all of it. Never read `graph.json` directly - `ls --json` is the same nodes in a
35
+ all of it. Never query `memory.db` directly - `ls --json` is the same nodes in a
35
36
  shape that does not change under you.
36
37
 
37
38
  | Flag | Meaning |
@@ -120,22 +121,21 @@ zen memory diff <candidate> --dir <batch-dir>/<id>/memory
120
121
  - **used** - nodes `memory_load` returned, and how often: what the run read.
121
122
  - **removed**, and new `SUPERSEDES` edges.
122
123
 
123
- It reads both sides without the lock, so it works on a memory a run is writing.
124
+ It reads one consistent snapshot of each side, so it works on a memory a run is
125
+ writing.
124
126
 
125
127
  Superseded nodes are left out unless you ask: `--all` includes them marked, and
126
128
  `--stale` narrows to them alone.
127
129
 
128
- Nothing that only reads takes the directory lock, so this and every other
129
- subcommand but `merge` and `forget` works while a run is writing the memory, and
130
- against the read-only `/memory` mount inside a sandbox.
130
+ Every subcommand reads one consistent snapshot, so all of them work while a run
131
+ is writing the memory - and the run keeps writing while they do.
131
132
 
132
133
  ## A graph that is not the project's
133
134
 
134
135
  `--dir` opens a memory directory as it stands, and skips project resolution
135
136
  entirely: there need be no `agents.yaml` anywhere above it. That is what to use
136
- for a graph a run was pointed at with `zen run --memory <dir>`, and for a copy
137
- taken out of a running session - though for reading a live memory, `grep` needs
138
- no copy at all.
137
+ for a graph a run was pointed at with `zen run --memory <dir>`, and for the one
138
+ a running session is writing to - no copy needed.
139
139
 
140
140
  ```
141
141
  zen run --memory .tmp/mem "…" remember into .tmp/mem for this run
@@ -182,8 +182,9 @@ working list and detail view.
182
182
 
183
183
  ## Merging
184
184
 
185
- The lock is per directory, so two runs cannot warm the same memory at once.
186
- They each warm their own, and `merge` puts the results back together:
185
+ Several runs may write one memory at once - each write is a transaction - but a
186
+ warmup should not share one: runs learning together see each other's commits
187
+ mid-round. They each warm their own, and `merge` puts the results back together:
187
188
 
188
189
  ```sh
189
190
  zen memory merge .tmp/warmup-*/batch/*/memory into the project’s
@@ -194,8 +195,8 @@ zen memory merge <batch-dir>/*/memory after `zen run batch`
194
195
  `zen run batch` is the fan-out with the bookkeeping done for you: each item
195
196
  gets its own copy of the memory, the project's is left alone, and the summary
196
197
  prints the `merge` line. A batch that is only asking should say
197
- `--memory-read-only` instead — nobody writes, so nobody needs the lock, and
198
- every item recalls from the one graph.
198
+ `--memory-read-only` instead — nobody writes, so nothing changes under anyone,
199
+ and every item recalls from the one graph.
199
200
 
200
201
  Sources are positional and the target is `--dir`, or the project you are in —
201
202
  the same shape as everywhere else here. The shell expands the glob, so a
@@ -244,10 +244,10 @@ well.
244
244
  A memory is a locked directory, so sixteen runs cannot hold one. Which leaves
245
245
  two honest arrangements, and the flag picks between them:
246
246
 
247
- | Mode | What happens |
248
- | -------------------- | ------------------------------------------------------------------ |
249
- | `--memory-read-only` | Every item recalls from the one graph. Nothing is written, no lock |
250
- | default | Each item gets a copy under `<batch-dir>/<id>/memory` |
247
+ | Mode | What happens |
248
+ | -------------------- | --------------------------------------------------------- |
249
+ | `--memory-read-only` | Every item recalls from the one graph. Nothing is written |
250
+ | default | Each item gets a copy under `<batch-dir>/<id>/memory` |
251
251
 
252
252
  In the copying mode the project's own memory is never touched. Fold what the
253
253
  items learned back in afterwards, having read it:
@@ -265,7 +265,7 @@ source that does not exist yet is not an error in the copying mode: a project
265
265
  declares its memory directory and the first run makes it, so every item simply
266
266
  starts from an empty graph. That is how a cold project is warmed, and pointing
267
267
  `--memory` at a directory that is not there is how you ask for it deliberately.
268
- A batch refuses to start while another run holds that memory's lock.
268
+ Each copy is the source as of one moment, so a run still writing it is fine.
269
269
 
270
270
  `--memory-read-only` works on a single `zen run` too. It is how you ask a
271
271
  question of what the agents know without changing what they know.
@@ -843,7 +843,7 @@ last thing this phase does — read the trajectories before the numbers, or the
843
843
  numbers decide what you look at.
844
844
 
845
845
  **Every question about a run has a command.** Never open `output.json`,
846
- `batch.json`, `state.json` or a memory's `graph.json` with `node -e`,
846
+ `batch.json`, `state.json` or a memory's `memory.db` with `node -e`,
847
847
  `python -c` or `jq` — the formats are the CLI's, and a guess at one costs a
848
848
  probe call to find out it was wrong.
849
849
 
@@ -14,9 +14,9 @@
14
14
  //
15
15
  // When a with-memory run passes, `checkpoint <run>` makes the candidate the last
16
16
  // good memory: it renames the directory and only then repoints
17
- // finetune/memory/last-good.json at it. `zen memory merge` writes its files one
18
- // after another, so a merge killed half-way can leave a graph whose files
19
- // disagree - but only ever a candidate, never the one the pointer names. Stop the
17
+ // finetune/memory/last-good.json at it. A merge killed half-way leaves the
18
+ // candidate it was writing without that merge, and never touches the one the
19
+ // pointer names. Stop the
20
20
  // tuning at any moment and `memory.mjs path` still names a usable graph.
21
21
  //
22
22
  // Needs `zen` on PATH. Run it from anywhere; it finds the project root from its
@@ -34,6 +34,7 @@ import {
34
34
  writeFileSync,
35
35
  } from 'node:fs';
36
36
  import { dirname, join, resolve } from 'node:path';
37
+ import { DatabaseSync } from 'node:sqlite';
37
38
  import { fileURLToPath } from 'node:url';
38
39
 
39
40
  const NAME = 'memory.mjs';
@@ -81,7 +82,17 @@ function writeAtomic(path, value) {
81
82
  }
82
83
 
83
84
  /** @param {string} dir @returns {number} */
84
- const nodesIn = (dir) => Number(json(join(dir, 'manifest.json'))?.nodes) || 0;
85
+ function nodesIn(dir) {
86
+ if (!existsSync(join(dir, 'memory.db'))) {
87
+ return 0;
88
+ }
89
+ const db = new DatabaseSync(join(dir, 'memory.db'), { readOnly: true });
90
+ try {
91
+ return Number(db.prepare('SELECT count(*) AS n FROM nodes').get()?.n) || 0;
92
+ } finally {
93
+ db.close();
94
+ }
95
+ }
85
96
 
86
97
  /** @param {string} run */
87
98
  function passed(run) {
@@ -178,17 +189,20 @@ if (command === 'candidate') {
178
189
  die(`batch ${batch} is already in the last good memory`);
179
190
  }
180
191
 
181
- // Only case memories with a manifest: a case that committed nothing has none.
192
+ // Only case memories with a database: a case that committed nothing has none.
182
193
  const dir = join(RUNS, arg, 'batch');
183
194
  const sources = (existsSync(dir) ? readdirSync(dir, { withFileTypes: true }) : [])
184
- .filter((e) => e.isDirectory() && existsSync(join(dir, e.name, 'memory', 'manifest.json')))
195
+ .filter((e) => e.isDirectory() && existsSync(join(dir, e.name, 'memory', 'memory.db')))
185
196
  .map((e) => join(dir, e.name, 'memory'));
186
197
 
187
198
  const target = join(ROOT, `candidate-batch${pad}`);
188
199
  rmSync(target, { recursive: true, force: true });
189
200
  mkdirSync(ROOT, { recursive: true });
190
201
  if (pointer && existsSync(pointer.dir)) {
191
- cpSync(pointer.dir, target, { recursive: true, filter: (src) => !src.endsWith('/.lock') });
202
+ cpSync(pointer.dir, target, {
203
+ recursive: true,
204
+ filter: (src) => !/\/(\.lock|memory\.db-(wal|shm))$/.test(src),
205
+ });
192
206
  } else {
193
207
  mkdirSync(target, { recursive: true });
194
208
  }
@@ -368,7 +368,7 @@ function memory(dir) {
368
368
  };
369
369
  }
370
370
  if (mode === 'copied') {
371
- return source && existsSync(join(source, 'graph.json'))
371
+ return source && existsSync(join(source, 'memory.db'))
372
372
  ? {
373
373
  kind: 'with memory',
374
374
  line: `WITH MEMORY — each case got its own copy of an existing graph (${source})`,
@@ -593,7 +593,7 @@ if (mode === 'index') {
593
593
  for (const { id } of roster(batch)) {
594
594
  const dir = join(batch, id, 'memory');
595
595
  say('');
596
- if (!existsSync(join(dir, 'manifest.json'))) {
596
+ if (!existsSync(join(dir, 'memory.db'))) {
597
597
  say(`-- ${id} committed nothing`);
598
598
  continue;
599
599
  }
@@ -177,8 +177,9 @@ a file short.
177
177
  ## Paths
178
178
 
179
179
  Every path-shaped token in these files is read by a model as an instruction to
180
- open something, and a running agent sees four: `/workspace`, `/assets`,
181
- `/skills`, `/memory`. The sweep is in the `zen-review` skill:
180
+ open something, and a running agent sees three: `/workspace`, `/assets`,
181
+ `/skills`. Remembered files are not mounted; `memory_copy_file` brings one into
182
+ `/workspace`. The sweep is in the `zen-review` skill:
182
183
 
183
184
  ```sh
184
185
  .github/skills/zen-review/scripts/check-paths.sh