memgineering 0.28.0 → 0.29.0

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/CHANGELOG.md CHANGED
@@ -9,6 +9,77 @@ upgrade and by agents summarising a release, and both re-render it in whatever
9
9
  language the reader wants. The bilingual rule the monorepo applies to
10
10
  `@rayul/kordis` does not extend here.
11
11
 
12
+ ## [0.29.0] — 2026-11-23
13
+
14
+ ### Fixed
15
+
16
+ - **`memgineering setup` no longer deletes your own notes from an instruction
17
+ file whose guide markers were damaged.** The guide sits between
18
+ `<!-- memgineering-start -->` and `<!-- memgineering-end -->` inside files
19
+ such as `CLAUDE.md`. If the end marker was lost with your own text below the
20
+ guide, the next run appended a second guide after your text, and the run after
21
+ that replaced everything from the first start to the new end, your text
22
+ included (measured: the notes were gone after the second run). Now the guide
23
+ is replaced only when the file has exactly one start line and one end line,
24
+ start first. Any other shape (a start with no end, an end with no start, an
25
+ end before the start, more than one of either) is refused for that file:
26
+ nothing is written, the report says which shape was found, and the hint names
27
+ the file and what to fix. Other files in the same run are still applied, and
28
+ `--dry-run` reports the same refusal. With `--json` the refusal is in
29
+ `marker_refusals` with `code: guide_markers_malformed`, `shape`, `file` and
30
+ `hint`; the hint gives the line numbers of the markers found, never tells you
31
+ where to put an end marker, and says that a marker quoted in your own notes
32
+ counts too (matching is by plain text), so change that mention. `memgineering
33
+ setup --web` now reports the same refusals when it finishes in the foreground
34
+ (it used to print "N tool(s) installed" and drop them), with exit 1. A file with no markers at all behaves as before. This also ends the
35
+ earlier self-repair for a lost end marker (the run after the damage appended a
36
+ block, the next collapsed it): that only held when nothing followed the guide.
37
+
38
+ ### Agent guidance
39
+
40
+ - **The `memgineering-setup` skill now covers a guide refused over its
41
+ markers.** It says what the refusal means, the `--json` fields, and to fix the
42
+ markers by following the hint rather than guessing where a marker goes. Restart the agent session
43
+ after upgrading to pick up the new text.
44
+
45
+ ## [0.28.1] — 2026-11-22
46
+
47
+ ### Changed
48
+
49
+ - **The package page now links to the public repository
50
+ [memgineering/memgineering-cli](https://github.com/memgineering/memgineering-cli)**,
51
+ which holds each published version exactly as npm serves it. Issues go there
52
+ too.
53
+
54
+ ### Fixed
55
+
56
+ - **`memgineering undo` on a folder brain no longer acts on a path outside the
57
+ brain.** The ledger lives inside the brain folder, so anyone who can write
58
+ that folder — a synced or shared vault, a folder handed over by someone else —
59
+ could add one line naming a target such as `../../Library/LaunchAgents/x.plist`.
60
+ The next `undo` then created that file with the line's own content (an
61
+ `exclude` or `unexclude` line) or deleted a file whose hash the line supplied
62
+ (a `remember` line). Now a target that leaves the brain, or reaches outside
63
+ through a symlink, is refused with `ledger_divergence` before anything is
64
+ read, written or removed: nothing is created, changed or removed, and the
65
+ hint says the line was not acted on and points to `memgineering log`. An
66
+ ordinary `undo` inside the brain behaves as before, including the
67
+ `undo_conflict` answer when the note was deleted since.
68
+ - **A comment written at the left edge inside a note's `memgineering:` block no
69
+ longer makes a change lose the note's id.** Before, a `conflict` change that
70
+ set `binding` or `never_store` — `memgineering revise --action conflict` with
71
+ `--rule` or `--never-store` — on a note whose block had such a comment between
72
+ two of its keys (a line starting with `#` in column 0) wrote the key it changed
73
+ twice. The note then failed to read, and was treated as having no id, no
74
+ `binding` and no `never_store` words, while the command reported success. Now
75
+ the comment stays inside the block: the keys around it are changed once, and the
76
+ comment keeps its text and its place but is indented with the rest of the block
77
+ (its column is not kept). `unbind` on such a note, which was refused, now goes
78
+ through. Every write is also checked against the note it started from, and one
79
+ that would leave the note unreadable or without the id it had is refused with
80
+ "Nothing was written." A note already damaged this way is restored by
81
+ `memgineering undo` on a folder brain, as long as it has not been edited since.
82
+
12
83
  ## [0.28.0] — 2026-11-01
13
84
 
14
85
  ### Added
@@ -2,7 +2,7 @@
2
2
  name: memgineering
3
3
  description: Use whenever the user refers to something they told you before, asks what was decided, tells you something worth keeping, or settles something that should hold next time. The memory lives in their own folder and outlives this session; check it before answering from guesswork, and write to it when you learn something durable.
4
4
  type: skill
5
- version: 0.28.0
5
+ version: 0.29.0
6
6
  ---
7
7
 
8
8
  # memgineering
@@ -194,6 +194,24 @@ again. Two outcomes are worth recognising:
194
194
  file is not mistaken for a clean install. Put the markers back around the
195
195
  block, or delete the block, then run setup again. Never append a second copy
196
196
  by hand: two guides means both are in the user's context every session.
197
+ - **A guide file refused over its markers** — setup replaces the guide only
198
+ where the file holds exactly one start line and one end line, start first.
199
+ A start with no end, an end with no start, an end before the start, or more
200
+ than one of either leaves that file untouched, because setup cannot tell
201
+ where the guide stops and the user's own text begins. Everything else in the
202
+ run is still applied, and the exit code is non-zero. The message (and, under
203
+ `--json`, `marker_refusals[]` with `code: guide_markers_malformed`, `shape`,
204
+ `file`, `hint`; the same fields in the `setup --web` result) names the file,
205
+ the shape and the line numbers where markers were found, and what to do. Follow
206
+ that hint, and tell the user which file it is. **Never add or move a marker by
207
+ guessing where the guide ends**: the next run replaces everything between the
208
+ markers, the user's own notes included. Delete the lone marker and the guide
209
+ text next to it only if you can see exactly where the guide ends; otherwise
210
+ move the user's own notes out of the file, delete the guide block and the
211
+ markers, run setup, and put the notes back outside them. If the marker text is
212
+ quoted in the user's own notes (a code example, say), change that mention so
213
+ it is no longer an exact copy: markers are matched as plain text, so a mention
214
+ anywhere in the file counts. Then run setup again.
197
215
  - **`Appended below an unmarked guide`** — the same shape, on a file setup has
198
216
  no record of writing, so it installed rather than refusing. Look at the file:
199
217
  if an older unmarked copy is now sitting above the new block, delete that copy.
package/dist/index.js CHANGED
@@ -4108,16 +4108,12 @@ function findBlock(lines2) {
4108
4108
  if (start === -1) return null;
4109
4109
  if (inlineValueOf(lines2[start] ?? "") !== null) return { start, end: start + 1 };
4110
4110
  let end = start + 1;
4111
- while (end < lines2.length) {
4112
- const line = lines2[end] ?? "";
4113
- if (line.trim() === "") {
4114
- end += 1;
4115
- continue;
4116
- }
4111
+ for (let i = start + 1; i < lines2.length; i += 1) {
4112
+ const line = lines2[i] ?? "";
4113
+ if (line.trim() === "" || line.startsWith("#")) continue;
4117
4114
  if (!/^\s/.test(line)) break;
4118
- end += 1;
4115
+ end = i + 1;
4119
4116
  }
4120
- while (end > start + 1 && (lines2[end - 1] ?? "").trim() === "") end -= 1;
4121
4117
  return { start, end };
4122
4118
  }
4123
4119
  function blockBodyOf(lines2, span) {
@@ -4392,8 +4388,28 @@ function readNamespace(noteContent) {
4392
4388
  return {};
4393
4389
  }
4394
4390
  }
4391
+ function hasUnreadableFrontmatter(mapped) {
4392
+ return mapped.issues.some((issue) => issue.startsWith(UNREADABLE_FRONTMATTER));
4393
+ }
4395
4394
  function verifyPatch(patched, proposal, before) {
4396
4395
  const mapped = mapNoteToMemory({ path: proposal.target.path, content: patched, revision: null });
4396
+ if (before !== void 0) {
4397
+ const was = mapNoteToMemory({ path: proposal.target.path, content: before, revision: null });
4398
+ if (!hasUnreadableFrontmatter(was)) {
4399
+ if (hasUnreadableFrontmatter(mapped)) {
4400
+ throw new PatchError(
4401
+ "the patched note has frontmatter that no longer parses, so the note would lose what it declared",
4402
+ "This is a defect in the patcher, not in your note \u2014 it would have dropped the note\u2019s id, binding and never-store words. Nothing was written."
4403
+ );
4404
+ }
4405
+ if (mapped.memory.id !== was.memory.id) {
4406
+ throw new PatchError(
4407
+ `the patched note no longer reads with its own id (${was.memory.id})`,
4408
+ "This is a defect in the patcher, not in your note \u2014 a note that loses its id is a different memory to everything that points at it. Nothing was written."
4409
+ );
4410
+ }
4411
+ }
4412
+ }
4397
4413
  if (isLifecycleAction(proposal.action)) {
4398
4414
  const want = STATUS_FOR_ACTION[proposal.action];
4399
4415
  if (mapped.memory.status !== want) {
@@ -4629,7 +4645,7 @@ function reversePatch(content, patch) {
4629
4645
  }
4630
4646
  return null;
4631
4647
  }
4632
- var NAMESPACE2, FENCE_RE, LOOKS_FENCED_RE, PatchError, BLOCK_KEY_RE, ANY_INDENTED_KEY_RE;
4648
+ var NAMESPACE2, FENCE_RE, LOOKS_FENCED_RE, PatchError, BLOCK_KEY_RE, ANY_INDENTED_KEY_RE, UNREADABLE_FRONTMATTER;
4633
4649
  var init_patch = __esm({
4634
4650
  "../../packages/memory-engine/src/proposal/patch.ts"() {
4635
4651
  "use strict";
@@ -4650,6 +4666,7 @@ var init_patch = __esm({
4650
4666
  };
4651
4667
  BLOCK_KEY_RE = /^([^\s#][^:]*?)\s*:/;
4652
4668
  ANY_INDENTED_KEY_RE = /^(\s*)([^\s#][^:]*?)\s*:/;
4669
+ UNREADABLE_FRONTMATTER = "frontmatter is not valid YAML";
4653
4670
  }
4654
4671
  });
4655
4672
 
@@ -8661,9 +8678,11 @@ async function applyAnswers(setupToken, claim, detected, guards = { candidates:
8661
8678
  // and a later flag-less refresh keeps it only if it is recorded as one.
8662
8679
  hookAnswer: answers.hook ? "on" : "off"
8663
8680
  };
8664
- await applySetup(choice, false);
8681
+ const results = await applySetup(choice, false);
8682
+ const refusals = results.filter((r) => r.result === "refused");
8665
8683
  const parts = [];
8666
8684
  parts.push(`${choice.tools.length} tool(s) installed`);
8685
+ if (refusals.length > 0) parts.push(`${refusals.length} file(s) refused`);
8667
8686
  if (answers.location === "local" && answers.local_path) {
8668
8687
  if (answers.local_mode === "link") {
8669
8688
  const target = await openLinkTarget(answers.local_path, { quiet: true });
@@ -8723,7 +8742,7 @@ async function applyAnswers(setupToken, claim, detected, guards = { candidates:
8723
8742
  }
8724
8743
  }
8725
8744
  if (account?.email) parts.push(`signed in as ${account.email}`);
8726
- return { summary: parts.join(" \xB7 ") };
8745
+ return { summary: parts.join(" \xB7 "), refusals };
8727
8746
  }
8728
8747
  async function whoIs(token) {
8729
8748
  const me = await apiRequest({ method: "GET", path: "/v1/me", token }).catch(() => null);
@@ -8899,15 +8918,36 @@ async function runSetupCloud(opts) {
8899
8918
  ${line}`));
8900
8919
  return;
8901
8920
  }
8902
- if (isJsonMode()) notice(JSON.stringify({ setup_web: "applied" }));
8903
- else {
8904
- printHuman(c.green("\nSetup finished."));
8921
+ const { refusals } = outcome;
8922
+ const hints = refusalHints(refusals);
8923
+ const label = refusals.map((r) => `${r.what} (${r.tool})`).join(", ");
8924
+ if (isJsonMode()) {
8925
+ notice(
8926
+ JSON.stringify({
8927
+ setup_web: "applied",
8928
+ ...refusals.length > 0 ? {
8929
+ refused: refusals.map((r) => `${r.what} (${r.tool})`),
8930
+ ...refusals.some((r) => r.reason !== void 0) ? { marker_refusals: markerRefusalsJson(refusals) } : {},
8931
+ hint: hints.join("\n\n")
8932
+ } : {}
8933
+ })
8934
+ );
8935
+ } else {
8936
+ printHuman(
8937
+ refusals.length > 0 ? c.yellow("\nSetup finished, except for the file(s) listed below.") : c.green("\nSetup finished.")
8938
+ );
8905
8939
  printHuman(
8906
8940
  c.gray(
8907
8941
  " recall and remember work now.\n The newly installed guidance is read from the next conversation on."
8908
8942
  )
8909
8943
  );
8944
+ if (refusals.length > 0) {
8945
+ printHuman(c.yellow(`
8946
+ Could not touch ${refusals.length} file(s): ${label}`));
8947
+ printHuman(c.gray(` ${hints.join("\n\n").split("\n").join("\n ")}`));
8948
+ }
8910
8949
  }
8950
+ if (refusals.length > 0) process.exitCode = 1;
8911
8951
  }
8912
8952
  function insideFolder(target, folder) {
8913
8953
  const real = (p) => {
@@ -9070,7 +9110,7 @@ function setupCommand() {
9070
9110
  (r) => Object.values(HOOK_WHAT).includes(r.what) && r.result !== "refused" && r.result !== "removed"
9071
9111
  );
9072
9112
  const hints = [
9073
- ...refusals.length > 0 ? [REFUSAL_HINT] : [],
9113
+ ...refusalHints(refusals),
9074
9114
  ...duplicated.length > 0 ? [DUPLICATE_HINT] : [],
9075
9115
  ...notByName !== null ? [globalInstallHint(notByName, hooksLanded)] : [],
9076
9116
  /*
@@ -9122,6 +9162,8 @@ function setupCommand() {
9122
9162
  brains_linked: brains.length,
9123
9163
  ...refusals.length > 0 ? { refused: refusals.map((r) => `${r.what} (${r.tool})`) } : {},
9124
9164
  ...duplicated.length > 0 ? { duplicated: duplicated.map((r) => `${r.what} (${r.tool})`) } : {},
9165
+ // Guides refused over their markers, as data: the shape found, the file, the fix.
9166
+ ...refusals.some((r) => r.reason !== void 0) ? { marker_refusals: markerRefusalsJson(refusals) } : {},
9125
9167
  /*
9126
9168
  * One key, composed above in order, instead of three spreads racing
9127
9169
  * for it. Written as three conditionals the last one won — and the
@@ -9296,7 +9338,7 @@ Run: memgineering link ${path.trim()}`));
9296
9338
  c.yellow(`
9297
9339
  \u2717 ${refusals.length} file(s) could not be written: ${label(refusals)}`)
9298
9340
  );
9299
- printHuman(c.gray(` ${REFUSAL_HINT.split("\n").join("\n ")}`));
9341
+ printHuman(c.gray(` ${refusalHints(refusals).join("\n\n").split("\n").join("\n ")}`));
9300
9342
  }
9301
9343
  process.exitCode = 1;
9302
9344
  }
@@ -9355,6 +9397,7 @@ async function applySetup(choice, dryRun) {
9355
9397
  tool: tool.label,
9356
9398
  what: "guide",
9357
9399
  result: written.outcome,
9400
+ ...written.shape !== void 0 && written.hint !== void 0 ? { reason: written.shape, file: hubPath, hint: written.hint } : {},
9358
9401
  ...wasEdited(hubPath, written.before) ? { edited: true } : {}
9359
9402
  });
9360
9403
  if (!dryRun && written.after !== null) mark(hubPath, written.after);
@@ -9440,6 +9483,54 @@ function globalInstallHint(reason, hooks) {
9440
9483
  return `${hooks ? "The hooks and the guide call" : "The guide tells your agent to run"} \`memgineering\` by name, and ${reason} \u2014
9441
9484
  so nothing reaches it until a global install exists: \`npm i -g memgineering\`. Nothing needs re-running after that.`;
9442
9485
  }
9486
+ function linesOf(text, needle) {
9487
+ const lines2 = [];
9488
+ for (let at = text.indexOf(needle); at !== -1; at = text.indexOf(needle, at + needle.length)) {
9489
+ lines2.push(text.slice(0, at).split("\n").length);
9490
+ }
9491
+ return lines2;
9492
+ }
9493
+ function markerFindings(text) {
9494
+ const starts = linesOf(text, BRAND.hubMarkerStart);
9495
+ const ends = linesOf(text, BRAND.hubMarkerEnd);
9496
+ const shape = (() => {
9497
+ if (starts.length === 0 && ends.length === 0) return "none";
9498
+ if (starts.length > 1) return "multiple_starts";
9499
+ if (ends.length > 1) return "multiple_ends";
9500
+ if (starts.length === 0) return "missing_start";
9501
+ if (ends.length === 0) return "missing_end";
9502
+ return text.indexOf(BRAND.hubMarkerStart) < text.indexOf(BRAND.hubMarkerEnd) ? "ok" : "end_before_start";
9503
+ })();
9504
+ return { shape, starts, ends };
9505
+ }
9506
+ function markerRefusalHint(file, f, shape) {
9507
+ const where = (n) => n.length === 1 ? `line ${n[0]}` : `lines ${n.join(", ")}`;
9508
+ const found = (n) => n.length === 0 ? "is not in the file" : `is on ${where(n)}`;
9509
+ const repair = {
9510
+ missing_end: `If you can see where the guide ends, delete the start line (${where(f.starts)}) and the guide text after it up to that point, then run setup to install a fresh guide. Do not add an end line by guessing where the guide ends: the next run would replace everything up to it.`,
9511
+ missing_start: `If you can see where the guide begins, delete the end line (${where(f.ends)}) and the guide text before it back to that point, then run setup to install a fresh guide. Do not add a start line by guessing where the guide begins: the next run would replace everything after it.`,
9512
+ end_before_start: "If you can see exactly where the guide text is, delete that text together with its marker lines.",
9513
+ multiple_starts: "If the extra markers belong to an extra copy of the guide that you can see exactly (an earlier run may have appended one), delete that copy together with its markers, so one start line and one end line remain.",
9514
+ multiple_ends: "If the extra markers belong to an extra copy of the guide that you can see exactly (an earlier run may have appended one), delete that copy together with its markers, so one start line and one end line remain."
9515
+ };
9516
+ const all = [...f.starts, ...f.ends].sort((a, b) => a - b);
9517
+ return `${file} was not changed. Found: the start line ${BRAND.hubMarkerStart} ${found(f.starts)}, the end line ${BRAND.hubMarkerEnd} ${found(f.ends)}; ${MARKER_SHAPE_WORDS[shape]}. Setup cannot tell where the memgineering guide ends and the user's own text begins, so it left the file alone.
9518
+ ${repair[shape]}
9519
+ Otherwise, move the user's own notes out of the file, delete the guide block and every marker line (${where(all)}), run \`memgineering setup\`, then put the notes back outside the markers.
9520
+ If the marker text above appears in the user's own notes, for example in a code example, change that mention so it is no longer an exact copy of the marker: markers are matched as plain text, so a mention anywhere in the file counts.
9521
+ Then run \`memgineering setup\` again.`;
9522
+ }
9523
+ function refusalHints(refusals) {
9524
+ return [
9525
+ ...refusals.some((r) => r.reason === void 0) ? [REFUSAL_HINT] : [],
9526
+ ...refusals.flatMap((r) => r.reason !== void 0 && r.hint !== void 0 ? [r.hint] : [])
9527
+ ];
9528
+ }
9529
+ function markerRefusalsJson(refusals) {
9530
+ return refusals.flatMap(
9531
+ (r) => r.reason !== void 0 && r.file !== void 0 && r.hint !== void 0 ? [{ code: MARKER_REFUSAL_CODE, shape: r.reason, file: r.file, hint: r.hint }] : []
9532
+ );
9533
+ }
9443
9534
  async function recordedChoices(detected) {
9444
9535
  const cfg = await loadConfig();
9445
9536
  if (!isSetUp(cfg)) return {};
@@ -9599,9 +9690,11 @@ ${BRAND.hubMarkerEnd}`;
9599
9690
  }
9600
9691
  return { outcome: "injected", before: null, after: fingerprint(block) };
9601
9692
  }
9602
- const start = existing.indexOf(BRAND.hubMarkerStart);
9603
- const end = existing.indexOf(BRAND.hubMarkerEnd);
9604
- if (start !== -1 && end !== -1) {
9693
+ const found = markerFindings(existing);
9694
+ const shape = found.shape;
9695
+ if (shape === "ok") {
9696
+ const start = existing.indexOf(BRAND.hubMarkerStart);
9697
+ const end = existing.indexOf(BRAND.hubMarkerEnd);
9605
9698
  const was = existing.slice(start, end + BRAND.hubMarkerEnd.length);
9606
9699
  if (was === block) return { outcome: "unchanged", before: was, after: fingerprint(block) };
9607
9700
  if (!dryRun) {
@@ -9612,7 +9705,16 @@ ${BRAND.hubMarkerEnd}`;
9612
9705
  }
9613
9706
  return { outcome: "updated", before: was, after: fingerprint(block) };
9614
9707
  }
9615
- if (start === -1 && end === -1 && looksLikeOurGuide(existing)) {
9708
+ if (shape !== "none") {
9709
+ return {
9710
+ outcome: "refused",
9711
+ before: null,
9712
+ after: null,
9713
+ shape,
9714
+ hint: markerRefusalHint(filePath, found, shape)
9715
+ };
9716
+ }
9717
+ if (looksLikeOurGuide(existing)) {
9616
9718
  if (weWroteThis) return { outcome: "refused", before: null, after: null };
9617
9719
  if (!dryRun) await writeThenRename(filePath, `${existing.trimEnd()}
9618
9720
 
@@ -9789,7 +9891,7 @@ async function exists2(path) {
9789
9891
  return false;
9790
9892
  }
9791
9893
  }
9792
- var TOOLS, HOSTED_CONNECTOR_URL, SUPPORTED_LIST, REFUSAL_HINT, DUPLICATE_HINT, HOOK_TIMEOUT_S, DEFAULT_HOOK_TOOLS, HOOK_WHAT, HOOKS, SHIPPED_HOOK_COMMANDS;
9894
+ var TOOLS, HOSTED_CONNECTOR_URL, SUPPORTED_LIST, REFUSAL_HINT, DUPLICATE_HINT, MARKER_REFUSAL_CODE, MARKER_SHAPE_WORDS, HOOK_TIMEOUT_S, DEFAULT_HOOK_TOOLS, HOOK_WHAT, HOOKS, SHIPPED_HOOK_COMMANDS;
9793
9895
  var init_setup = __esm({
9794
9896
  "src/commands/setup.ts"() {
9795
9897
  "use strict";
@@ -9878,6 +9980,14 @@ var init_setup = __esm({
9878
9980
  REFUSAL_HINT = `Either a guide setup wrote is still there with its markers removed, or a settings file is not valid JSON. Everything else in this run was applied.
9879
9981
  For a guide: put ${BRAND.hubMarkerStart} and ${BRAND.hubMarkerEnd} back around that block, or delete the block, then run setup again.`;
9880
9982
  DUPLICATE_HINT = "That file already looked like it held a memgineering guide with no markers around it, so the new one was appended below rather than replacing it.\nIf an older copy is now sitting above it, delete that copy \u2014 two guides means both are in every session. If those lines are your own writing, nothing is wrong.";
9983
+ MARKER_REFUSAL_CODE = "guide_markers_malformed";
9984
+ MARKER_SHAPE_WORDS = {
9985
+ missing_end: "the end line is missing",
9986
+ missing_start: "the start line is missing",
9987
+ end_before_start: "the end line comes before the start line",
9988
+ multiple_starts: "there is more than one start line",
9989
+ multiple_ends: "there is more than one end line"
9990
+ };
9881
9991
  HOOK_TIMEOUT_S = Math.ceil(HOOK_DEADLINE_MS / 1e3) + 3;
9882
9992
  DEFAULT_HOOK_TOOLS = ["claude", "codex"];
9883
9993
  HOOK_WHAT = {
@@ -25297,6 +25407,7 @@ init_src();
25297
25407
  import { readFile as readFile31, rm as rm9 } from "fs/promises";
25298
25408
  import { join as join33 } from "path";
25299
25409
  import { Command as Command43 } from "commander";
25410
+ init_walk();
25300
25411
  init_atomic();
25301
25412
  init_errors();
25302
25413
  init_cloud_brain();
@@ -25392,7 +25503,7 @@ ${matches.slice(0, 8).map((id) => ` ${id}`).join("\n")}${matches.length > 8 ? "
25392
25503
  );
25393
25504
  }
25394
25505
  const record = await withWriteLock(brain.root, async () => {
25395
- const absolute = join33(brain.root, target.target);
25506
+ const absolute = await containedTarget(brain.root, target);
25396
25507
  const current = await readFile31(absolute, "utf8").catch(() => null);
25397
25508
  const actualHash = current === null ? null : hashContent(current);
25398
25509
  if (actualHash !== target.hash_after) {
@@ -25402,7 +25513,7 @@ ${matches.slice(0, 8).map((id) => ` ${id}`).join("\n")}${matches.length > 8 ? "
25402
25513
  await conflictHint(brain.root, target)
25403
25514
  );
25404
25515
  }
25405
- const reverted = await reverse(brain, target, current);
25516
+ const reverted = await reverse(brain, target, absolute, current);
25406
25517
  return appendOp(brain.root, {
25407
25518
  verb: "undo",
25408
25519
  target: target.target,
@@ -25454,8 +25565,7 @@ function minutesSince(iso) {
25454
25565
  if (!Number.isFinite(at)) return null;
25455
25566
  return Math.max(0, Math.floor((Date.now() - at) / 6e4));
25456
25567
  }
25457
- async function reverse(brain, op, current) {
25458
- const absolute = join33(brain.root, op.target);
25568
+ async function reverse(brain, op, absolute, current) {
25459
25569
  if (op.verb === "remember") {
25460
25570
  if (current === null) {
25461
25571
  throw memgError(
@@ -25507,6 +25617,19 @@ async function reverse(brain, op, current) {
25507
25617
  }
25508
25618
  return reverted;
25509
25619
  }
25620
+ async function containedTarget(root, op) {
25621
+ try {
25622
+ return await resolveRealInside(root, op.target);
25623
+ } catch (err) {
25624
+ const code = err.code;
25625
+ if (code === "ENOENT" || code === "ENOTDIR") return resolveInside(root, op.target);
25626
+ throw memgError(
25627
+ "ledger_divergence",
25628
+ `${oneLine(op.op_id, WIDTH.handle)} names a path outside this brain, or one that is not a plain file path inside it`,
25629
+ "The ledger names a path outside this brain (or one reached through a symlink), so that line was not acted on and nothing was created, changed or removed. This tool only records files inside the brain, so the line was added or edited by something else. `memgineering log --verbose` shows what the ledger says; check who can write this brain's folder, and do not undo by id until the line is explained."
25630
+ );
25631
+ }
25632
+ }
25510
25633
  async function conflictHint(vaultRoot, op) {
25511
25634
  const base2 = `Nothing was changed. Someone \u2014 you, an editor, or a sync \u2014 has written to that file since.
25512
25635
  Read what it says now, then decide what should stay.`;
package/package.json CHANGED
@@ -1,16 +1,17 @@
1
1
  {
2
2
  "name": "memgineering",
3
- "version": "0.28.0",
3
+ "version": "0.29.0",
4
4
  "private": false,
5
5
  "description": "One memory for the AI you connect. Recall, remember, and revise a brain your agents share — stored in your own folder.",
6
6
  "license": "Apache-2.0",
7
7
  "homepage": "https://memgineering.com",
8
8
  "repository": {
9
9
  "type": "git",
10
- "url": "git+https://github.com/memgineering/memgineering.git"
10
+ "url": "git+https://github.com/memgineering/memgineering-cli.git",
11
+ "directory": "memgineering"
11
12
  },
12
13
  "bugs": {
13
- "url": "https://github.com/memgineering/memgineering/issues"
14
+ "url": "https://github.com/memgineering/memgineering-cli/issues"
14
15
  },
15
16
  "type": "module",
16
17
  "bin": {