hypomnema 1.10.0 → 1.10.2

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.
@@ -0,0 +1,254 @@
1
+ // settings.json only. The write itself is hooks/atomic-write.mjs (`atomicWrite`);
2
+ // this file decides where to write and cleans up around it, and never grows a
3
+ // second temp+rename of its own.
4
+ //
5
+ // What the rename costs (the helper accepts these rather than fork the writer):
6
+ // - mode window: closed. The write runs under umask 0o077, so the temp file and the
7
+ // renamed file are never wider than 0o600 and the chmod back only widens to the
8
+ // original mode. A brand-new file is chmodded to 0o666 & ~umask to keep the
9
+ // default mode. The directory is made before the umask is lowered, for the
10
+ // same reason.
11
+ // - chmod failure: the write already happened, so the call never throws for it (a caller
12
+ // that goes on to copy a hook the new settings name would otherwise leave settings pointing
13
+ // at a missing file). The file keeps the narrower mode and one line goes to stderr; when
14
+ // that is wider than the original (the umask makes it close to unreachable) the result
15
+ // carries `modeWidened: true` and the line names both modes. A new file whose chmod to the
16
+ // default mode fails stays at 0o600 and the line says so.
17
+ // - read-only file: a 0o444 settings.json in a writable directory is now replaced
18
+ // (the old direct write refused with EACCES) and put back to 0o444.
19
+ // - hard links, owner, ACL and xattr: rename breaks a hard link (the other name
20
+ // keeps the old inode) and does not carry owner, ACL or xattr to the new file.
21
+ // Only the mode is restored.
22
+ // - in-place fallback: when no atomic replace is possible the bytes go straight into
23
+ // the live file, and a kill or a partial write would leave truncated JSON with no copy
24
+ // of the old file. So the current bytes are saved first, beside the file
25
+ // (`settings.json.hypo-bak`) or else in a fresh directory under the OS temp dir. With
26
+ // no backup possible the write is refused. The backup is removed once the file reads
27
+ // back as what was written and kept, with its path in the error, when it does not.
28
+ import {
29
+ chmodSync,
30
+ lstatSync,
31
+ mkdirSync,
32
+ mkdtempSync,
33
+ readFileSync,
34
+ readlinkSync,
35
+ realpathSync,
36
+ rmSync,
37
+ rmdirSync,
38
+ statSync,
39
+ unlinkSync,
40
+ writeFileSync,
41
+ } from 'node:fs';
42
+ import { tmpdir } from 'node:os';
43
+ import { basename, dirname, isAbsolute, join, sep } from 'node:path';
44
+ import { atomicWrite } from '../../hooks/atomic-write.mjs';
45
+
46
+ const MAX_LINKS = 40;
47
+
48
+ /**
49
+ * Follow `path` one readlink at a time to the last path of the chain. Each link
50
+ * body is read against the physical parent of the link: `path.resolve` would fold
51
+ * a `..` before the directory links above it and pick a different file.
52
+ *
53
+ * @returns {{target: string, viaLink: boolean}} `target` has a physical parent.
54
+ */
55
+ function resolveSettingsTarget(path) {
56
+ const seen = new Set();
57
+ const finish = (p) => {
58
+ try {
59
+ return { target: join(realpathSync(dirname(p)), basename(p)), viaLink: p !== path };
60
+ } catch (err) {
61
+ if (err.code !== 'ENOENT' && err.code !== 'ENOTDIR') throw err;
62
+ const refuse = p !== path;
63
+ if (refuse) {
64
+ throw Object.assign(
65
+ new Error(
66
+ `ENOENT: ${path} is a symlink whose target directory ${dirname(p)} does not exist`,
67
+ ),
68
+ { code: 'ENOENT' },
69
+ );
70
+ }
71
+ return { target: p, viaLink: false }; // first write (init): atomicWrite makes the directory
72
+ }
73
+ };
74
+ let p = path;
75
+ for (;;) {
76
+ let st;
77
+ try {
78
+ st = lstatSync(p);
79
+ } catch (err) {
80
+ if (err.code === 'ENOENT') return finish(p);
81
+ throw err;
82
+ }
83
+ const isLink = st.isSymbolicLink();
84
+ if (!isLink) return finish(p);
85
+ const loop = seen.has(p) || seen.size >= MAX_LINKS;
86
+ if (loop) {
87
+ throw Object.assign(
88
+ new Error(`ELOOP: too many symbolic links (or a loop) starting at ${path}`),
89
+ {
90
+ code: 'ELOOP',
91
+ },
92
+ );
93
+ }
94
+ seen.add(p);
95
+ const text = readlinkSync(p);
96
+ const next = isAbsolute(text) ? text : `${realpathSync(dirname(p))}${sep}${text}`;
97
+ p = next;
98
+ }
99
+ }
100
+
101
+ /**
102
+ * Save the current bytes of `target` before an in-place write. 'wx' so a backup kept by an
103
+ * earlier failed run (or a link planted at that name) is never overwritten or followed.
104
+ *
105
+ * @returns {{path: string, tempDir: string|null}|null} the backup path and the temp directory
106
+ * this call made for it (null for a sibling backup), or null when the bytes could not be read
107
+ * or no backup file could be written.
108
+ */
109
+ function saveBackup(target) {
110
+ let bytes;
111
+ try {
112
+ bytes = readFileSync(target);
113
+ } catch {
114
+ return null;
115
+ }
116
+ const name = `${basename(target)}.hypo-bak`;
117
+ const sibling = join(dirname(target), name);
118
+ try {
119
+ writeFileSync(sibling, bytes, { flag: 'wx', mode: 0o600 });
120
+ return { path: sibling, tempDir: null };
121
+ } catch {
122
+ // the directory that refused the temp file usually refuses this too; try the OS temp dir
123
+ }
124
+ let dir;
125
+ try {
126
+ dir = mkdtempSync(join(tmpdir(), 'hypo-settings-'));
127
+ const inTmp = join(dir, name);
128
+ writeFileSync(inTmp, bytes, { flag: 'wx', mode: 0o600 });
129
+ return { path: inTmp, tempDir: dir };
130
+ } catch {
131
+ if (dir) rmSync(dir, { recursive: true, force: true });
132
+ return null;
133
+ }
134
+ }
135
+
136
+ // Removes the backup file, then only the temp directory saveBackup recorded, and only if it is
137
+ // empty. A directory is never chosen by its name: a settings.json may live in a user directory
138
+ // called hypo-settings-something.
139
+ function removeBackup(backup) {
140
+ try {
141
+ unlinkSync(backup.path);
142
+ if (backup.tempDir) rmdirSync(backup.tempDir);
143
+ } catch {
144
+ // a leftover backup is harmless; the file itself is already correct
145
+ }
146
+ }
147
+
148
+ /**
149
+ * Write `text` to settings.json at `path`. A symlink stays a link and its last
150
+ * target gets the bytes. A dangling link into an existing directory is created
151
+ * through the link; into a missing directory it is refused (ENOENT) and no
152
+ * directory is made. A path that is not a link and does not exist is created.
153
+ *
154
+ * `atomic` is false when the directory refused the temp file (EACCES, EPERM) and
155
+ * the bytes went in place instead, after the old bytes were saved to a backup (see the header).
156
+ * `modeRestored` is true only when the rename
157
+ * changed the mode and the chmod back succeeded. `modeWidened` is true when that chmod failed and
158
+ * the file is now wider than it was (never thrown: the bytes are already written).
159
+ *
160
+ * @returns {{atomic: boolean, target: string, viaLink: boolean, modeRestored: boolean, modeWidened: boolean}}
161
+ */
162
+ export function writeSettingsJson(path, text) {
163
+ const { target, viaLink } = resolveSettingsTarget(path);
164
+ let mode;
165
+ try {
166
+ mode = statSync(target).mode & 0o7777;
167
+ } catch (err) {
168
+ if (err.code !== 'ENOENT') throw err;
169
+ }
170
+ let atomic = true;
171
+ mkdirSync(dirname(target), { recursive: true }); // before the umask below, so a new directory keeps its default mode
172
+ const oldMask = process.umask(0o077);
173
+ try {
174
+ try {
175
+ atomicWrite(target, text);
176
+ } finally {
177
+ process.umask(oldMask);
178
+ }
179
+ } catch (err) {
180
+ // EBUSY (rename onto a bind-mounted file) and EXDEV take the in-place path like a read-only directory.
181
+ const fallback = ['EACCES', 'EPERM', 'EBUSY', 'EXDEV'].includes(err.code);
182
+ if (!fallback) throw err;
183
+ // A missing target has no old bytes to lose. Otherwise no backup means no write.
184
+ const backup = mode === undefined ? null : saveBackup(target);
185
+ if (mode !== undefined && !backup) {
186
+ throw Object.assign(
187
+ new Error(
188
+ `settings.json: ${target} was not changed because neither an atomic replace (${err.code}) nor a backup of the current file was possible`,
189
+ ),
190
+ { code: err.code, cause: err },
191
+ );
192
+ }
193
+ atomic = false;
194
+ // Printed before the write so a kill mid-write still leaves the backup path on screen.
195
+ process.stderr.write(
196
+ `settings.json: ${dirname(target)} is not writable for an atomic replace, wrote in place` +
197
+ (backup ? ` (previous bytes saved at ${backup.path} until the write is verified)` : '') +
198
+ '\n',
199
+ );
200
+ try {
201
+ writeFileSync(target, text); // opens the file as is, so its mode stays
202
+ } catch (werr) {
203
+ if (!backup) throw werr;
204
+ throw Object.assign(
205
+ new Error(
206
+ `settings.json: the in-place write to ${target} failed (${werr.code ?? werr.message}); the previous bytes are kept at ${backup.path}`,
207
+ ),
208
+ { code: werr.code, cause: werr },
209
+ );
210
+ }
211
+ if (backup) {
212
+ let intact = false;
213
+ try {
214
+ intact = Buffer.from(text).equals(readFileSync(target));
215
+ } catch {
216
+ // unreadable counts as not intact
217
+ }
218
+ if (!intact) {
219
+ throw new Error(
220
+ `settings.json: ${target} does not read back as what was written; the previous bytes are kept at ${backup.path}`,
221
+ );
222
+ }
223
+ removeBackup(backup);
224
+ }
225
+ }
226
+ if (atomic && mode === undefined) {
227
+ try {
228
+ chmodSync(target, 0o666 & ~oldMask); // a new file keeps the default mode
229
+ } catch (err) {
230
+ const now = (statSync(target).mode & 0o7777).toString(8);
231
+ process.stderr.write(
232
+ `settings.json: written, ${target} stays at mode ${now} (chmod failed: ${err.code ?? err.message})\n`,
233
+ );
234
+ }
235
+ }
236
+ let modeRestored = false;
237
+ let modeWidened = false;
238
+ if (atomic && mode !== undefined) {
239
+ const newMode = statSync(target).mode & 0o7777;
240
+ const restoreMode = newMode !== mode;
241
+ if (restoreMode) {
242
+ try {
243
+ chmodSync(target, mode);
244
+ modeRestored = true;
245
+ } catch (err) {
246
+ modeWidened = (newMode & ~mode) !== 0;
247
+ process.stderr.write(
248
+ `settings.json: written, mode not restored: ${target} is ${newMode.toString(8)}, was ${mode.toString(8)} (${err.code ?? err.message})\n`,
249
+ );
250
+ }
251
+ }
252
+ }
253
+ return { atomic, target, viaLink, modeRestored, modeWidened };
254
+ }
@@ -55,7 +55,16 @@ function walkMarkdown(dir, root, ignorePatterns, policy, acc) {
55
55
  if (policy.skipDotEntry && entry.startsWith('.')) continue;
56
56
  const full = join(dir, entry);
57
57
  if (isScanIgnored(full, root, ignorePatterns)) continue;
58
- const st = policy.lstat ? lstatSync(full) : statSync(full);
58
+ let st;
59
+ try {
60
+ st = policy.lstat ? lstatSync(full) : statSync(full);
61
+ } catch (err) {
62
+ // readdir listed it, stat cannot find it: another session's atomic-write temp file that was
63
+ // renamed away in between, or a dangling symlink. Neither is a page; skip it instead of
64
+ // letting one vanished entry kill the whole scan.
65
+ if (err?.code === 'ENOENT' || err?.code === 'ENOTDIR') continue;
66
+ throw err;
67
+ }
59
68
  if (policy.lstat && st.isSymbolicLink()) continue;
60
69
  if (st.isDirectory()) {
61
70
  if (policy.skipUnderscoreDir && entry.startsWith('_')) continue;
@@ -80,6 +80,7 @@ import {
80
80
  provenancePath,
81
81
  } from './lib/pkg-provenance.mjs';
82
82
  import { loadHookInventory } from './lib/hook-inventory.mjs';
83
+ import { writeSettingsJson } from './lib/settings-write.mjs';
83
84
  import {
84
85
  hooksDirForInstall,
85
86
  unsafeHookTargetReason,
@@ -463,7 +464,7 @@ function stripExtensionSettings(settingsPath, hooksDir, apply, ownedCommands = n
463
464
  }
464
465
 
465
466
  if (changed && apply) {
466
- writeFileSync(settingsPath, JSON.stringify(settings, null, 2) + '\n');
467
+ writeSettingsJson(settingsPath, JSON.stringify(settings, null, 2) + '\n');
467
468
  }
468
469
  return { stripped };
469
470
  }
@@ -892,7 +893,7 @@ function stripSettingsJson(settingsPath, hooksDir, hookFiles, apply) {
892
893
  }
893
894
 
894
895
  if (changed && apply) {
895
- writeFileSync(settingsPath, JSON.stringify(settings, null, 2) + '\n');
896
+ writeSettingsJson(settingsPath, JSON.stringify(settings, null, 2) + '\n');
896
897
  }
897
898
 
898
899
  return { stripped, kept: 0 };
@@ -67,10 +67,12 @@ import {
67
67
  parseWikiPreCommitRoot,
68
68
  wikiPreCommitContent,
69
69
  oldFormPreCommitContent,
70
+ previousFormPreCommitContent,
71
+ publishHookFile,
70
72
  uniqueBakPath,
71
73
  } from './lib/git-hooks-dir.mjs';
72
74
  import { classifyInstall, downgradeGuardMessage } from '../hooks/version-check.mjs';
73
- import { atomicWrite } from '../hooks/atomic-write.mjs';
75
+ import { writeSettingsJson } from './lib/settings-write.mjs';
74
76
  import {
75
77
  GITATTRIBUTES_BLOCK,
76
78
  GITIGNORE_BLOCK,
@@ -113,6 +115,12 @@ const PKG_INTEGRITY_HINT =
113
115
  // the same reason; kept as a separate local constant here rather than an
114
116
  // import, since that file is not this task's to change.
115
117
  const DOCTOR_HINT = '`/hypo:doctor` in Claude Code, or `hypomnema doctor` with the npm CLI';
118
+ // Said wherever this report tells a person to /reload-plugins: a reload swaps the hooks of an open
119
+ // session, but a session that began before the upgrade has no record stamp, so the close gate
120
+ // keeps the old project-folder rule for it (commands/upgrade.md and hypo-guide.md say the same).
121
+ const NEW_SESSION_HINT =
122
+ 'A session that was already open before this upgrade keeps the old project-folder close rule ' +
123
+ 'until you start a new session; `/reload-plugins` alone does not switch it.';
116
124
  const HOOKS_SRC = join(PKG_ROOT, 'hooks');
117
125
  const COMMANDS_SRC = join(PKG_ROOT, 'commands');
118
126
  const TEMPLATES = join(PKG_ROOT, 'templates');
@@ -505,7 +513,7 @@ function removeRetiredRegistrations(settings, hooksDir) {
505
513
 
506
514
  // The one place settings.json is mutated by --apply: rename, add, and retire
507
515
  // merged into a single in-memory transform, committed with exactly one
508
- // atomicWrite (temp file plus rename, see hooks/atomic-write.mjs). So there is
516
+ // writeSettingsJson (temp file plus rename, see lib/settings-write.mjs). So there is
509
517
  // no window where the file on disk reflects only some of the three, and a
510
518
  // crash mid-write lands on a throwaway temp name instead of a torn
511
519
  // settings.json. Known gap this does not close: no lock guards settingsPath,
@@ -529,7 +537,7 @@ function applySettingsJsonTransform(settingsPath, hooksDir) {
529
537
  const retired = removeRetiredRegistrations(settings, hooksDir);
530
538
 
531
539
  if (renamed.length > 0 || added.length > 0 || retired.length > 0) {
532
- atomicWrite(settingsPath, JSON.stringify(settings, null, 2) + '\n');
540
+ writeSettingsJson(settingsPath, JSON.stringify(settings, null, 2) + '\n');
533
541
  }
534
542
  if (renamed.length > 0) copyRenamedHookFiles(hooksDir);
535
543
  return { renamed, added, retired };
@@ -693,6 +701,11 @@ function applyGitignoreMigration(result) {
693
701
  // a shape isOwnedWikiPreCommitBody() recognizes (old OR new — see
694
702
  // lib/git-hooks-dir.mjs), what parseWikiPreCommitRoot() read back from it.
695
703
  //
704
+ // A hook on the previous commit-time resolver (v1.8.4 through v1.10.0) comes
705
+ // back with `previousResolver: true` and `root: null`. It bakes no root, but it
706
+ // reads hypo-pkg.json before the enabled plugin, so upgrade rewrites it onto the
707
+ // current resolver like an old-form one.
708
+ //
696
709
  // Returns `null` when there is nothing of ours to report (no hook, or a hook
697
710
  // with no Hypomnema marker at all: some other tool's or the user's own).
698
711
  // Returns `{ hookPath, unrecognized: true, root: null }` when our marker IS
@@ -720,10 +733,17 @@ function checkWikiPreCommitRoot(hypoDir) {
720
733
  if (!parsed.ok) {
721
734
  return parsed.hasMarker ? { hookPath, unrecognized: true, root: null } : null;
722
735
  }
723
- return { hookPath, root: parsed.root, lintStrict: parsed.lintStrict, hypoDir: parsed.hypoDir };
736
+ return {
737
+ hookPath,
738
+ root: parsed.root,
739
+ previousResolver: parsed.previousResolver === true,
740
+ lintStrict: parsed.lintStrict,
741
+ hypoDir: parsed.hypoDir,
742
+ };
724
743
  }
725
744
 
726
- // Rewrites an OLD-form hook onto the runtime-resolving form, reusing the exact
745
+ // Rewrites an OLD-form hook (or one on the previous commit-time resolver) onto
746
+ // the current runtime-resolving form, reusing the exact
727
747
  // writer init.mjs itself uses so the regenerated hook is byte-identical to
728
748
  // what a fresh init would produce today — the --lint-strict step count
729
749
  // (info.lintStrict) is preserved exactly, never collapsed to one step, or the
@@ -746,7 +766,9 @@ function checkWikiPreCommitRoot(hypoDir) {
746
766
  //
747
767
  // Returns `{ ok: true }` on a successful rewrite, or `{ ok: false, reason }`
748
768
  // naming why the write was refused or failed, so the caller can surface that
749
- // reason instead of silently reporting "unchanged".
769
+ // reason instead of silently reporting "unchanged". The final swap goes through
770
+ // publishHookFile, so a failed write or rename leaves the live hook untouched
771
+ // and the reason names the .bak path.
750
772
  function applyWikiPreCommitRoot(info) {
751
773
  const unsafe = unsafeHookTargetReason(info.hookPath);
752
774
  if (unsafe) return { ok: false, reason: unsafe };
@@ -781,7 +803,9 @@ function applyWikiPreCommitRoot(info) {
781
803
  reason: `cannot read hook to verify before migrating (${e.code || e.message})`,
782
804
  };
783
805
  }
784
- const expectedOld = oldFormPreCommitContent(info.root, hypoDir, info.lintStrict);
806
+ const expectedOld = info.previousResolver
807
+ ? previousFormPreCommitContent(hypoDir, info.lintStrict)
808
+ : oldFormPreCommitContent(info.root, hypoDir, info.lintStrict);
785
809
  if (currentContent !== expectedOld) {
786
810
  return {
787
811
  ok: false,
@@ -810,14 +834,26 @@ function applyWikiPreCommitRoot(info) {
810
834
  writeFileSync(bakPath, currentContent);
811
835
 
812
836
  // A REFUSAL (above) is a soft skip, matching init's contract that an unsafe
813
- // or unresolvable target is logged and stepped over. A real I/O failure is
814
- // not that: every other apply write in this file lets the exception through,
815
- // and init does the same, so swallowing EACCES here would make this one
816
- // migration quieter than the rest of --apply for no reason. It also reported
817
- // the wrong thing: a chmod that fails AFTER the write says "still on the old
818
- // form" while the file already holds the new one.
819
- writeFileSync(info.hookPath, newContent);
820
- chmodSync(info.hookPath, 0o755);
837
+ // or unresolvable target is logged and stepped over. A failed write is
838
+ // reported the same way, because publishHookFile keeps it from touching the
839
+ // live hook: the old bytes are still in place, so "still on the older form" is
840
+ // true and the .bak path in the reason is a second copy, not the only one.
841
+ const published = publishHookFile(info.hookPath, newContent);
842
+ if (!published.ok) {
843
+ const leftover = published.cleaned
844
+ ? ''
845
+ : `; the unused candidate file ${published.candidatePath} could not be removed`;
846
+ return {
847
+ ok: false,
848
+ // Set only here, not on the refusals above: a refusal is a soft skip, but
849
+ // a write that failed leaves a hook the user asked --apply to migrate
850
+ // still on the old form, so the run must not exit 0.
851
+ writeFailed: true,
852
+ reason:
853
+ `writing the new hook failed (${published.error.code || published.error.message}); ` +
854
+ `the existing hook is unchanged and its bytes are also saved at ${bakPath}${leftover}`,
855
+ };
856
+ }
821
857
  return { ok: true };
822
858
  }
823
859
 
@@ -917,8 +953,9 @@ This report was generated during an upgrade apply. ${
917
953
  pluginMode
918
954
  ? 'You are on a **plugin install**, so the core hook files and settings.json hook ' +
919
955
  'registrations were NOT touched — the Claude Code plugin loader owns them (upgrade the ' +
920
- 'plugin via `/plugin marketplace update hypomnema` then `/reload-plugins`). Vault ' +
921
- 'extensions, if any, were still synced.'
956
+ 'plugin via `/plugin marketplace update hypomnema` then `/reload-plugins`). ' +
957
+ NEW_SESSION_HINT +
958
+ ' Vault extensions, if any, were still synced.'
922
959
  : 'Hook files and settings.json entries were applied by that run (or skipped with a ' +
923
960
  'warning if the target was malformed — see the upgrade output).'
924
961
  } \`SCHEMA.md\` is intentionally **not** overwritten by upgrade — the
@@ -1469,8 +1506,10 @@ const wikiHookWantRoot = hypomnemaPluginEnabled ? pluginRegistryRoot : PKG_ROOT;
1469
1506
  const wikiPreCommitInfo = checkWikiPreCommitRoot(args.hypoDir);
1470
1507
  // `wikiPreCommitInfo.root` is non-null only for a hook still on the
1471
1508
  // OLD, version-pinned form (see parseWikiPreCommitRoot in
1472
- // lib/git-hooks-dir.mjs) — the NEW, runtime-resolving form never bakes one in,
1473
- // so `root === null` there means "nothing to migrate", not "unresolved".
1509
+ // lib/git-hooks-dir.mjs). A runtime-resolving hook never bakes one in, so
1510
+ // `root === null` alone does not say whether there is anything to migrate: a
1511
+ // hook on the previous resolver (`previousResolver === true`) also has no root
1512
+ // and still needs rewriting; only the current form is "nothing to migrate".
1474
1513
  // Migrating does not need wikiHookWantRoot at all: unlike the old repoint
1475
1514
  // (which had to pick the CORRECT root to bake in, and had to stay silent when
1476
1515
  // it could not positively resolve one — see the dual-install preserve case
@@ -1478,7 +1517,9 @@ const wikiPreCommitInfo = checkWikiPreCommitRoot(args.hypoDir);
1478
1517
  // even when this run cannot resolve the active install itself, because the
1479
1518
  // rewritten hook resolves it fresh at every future commit instead of baking
1480
1519
  // in a guess now.
1481
- const wikiPreCommitDrift = wikiPreCommitInfo !== null && wikiPreCommitInfo.root !== null;
1520
+ const wikiPreCommitDrift =
1521
+ wikiPreCommitInfo !== null &&
1522
+ (wikiPreCommitInfo.root !== null || wikiPreCommitInfo.previousResolver === true);
1482
1523
  const commands = checkCommands();
1483
1524
  const oldHookRefs = checkOldHookNames(claudeSettingsPath);
1484
1525
  const retiredSettings = checkRetiredRegistrations(claudeSettingsPath, claudeHooksDir);
@@ -1604,6 +1645,7 @@ let appliedHypoignore = [];
1604
1645
  let appliedGitignore = [];
1605
1646
  let appliedWikiPreCommitRoot = false;
1606
1647
  let wikiPreCommitApplyFailReason = null;
1648
+ let wikiPreCommitWriteFailed = false;
1607
1649
  let appliedExtensions = null;
1608
1650
  let appliedExtensionsCodex = null;
1609
1651
 
@@ -1696,7 +1738,7 @@ if (args.apply) {
1696
1738
  });
1697
1739
  }
1698
1740
  if (managesClaudeCore) {
1699
- // Rename, add, and retire all commit through one atomicWrite inside this
1741
+ // Rename, add, and retire all commit through one writeSettingsJson inside this
1700
1742
  // call. See applySettingsJsonTransform's own comment for why they are no
1701
1743
  // longer three separate writeFileSync calls.
1702
1744
  const claudeSettingsResult = applySettingsJsonTransform(claudeSettingsPath, claudeHooksDir);
@@ -1804,6 +1846,7 @@ if (args.apply) {
1804
1846
  const wikiPreCommitResult = applyWikiPreCommitRoot(wikiPreCommitInfo);
1805
1847
  appliedWikiPreCommitRoot = wikiPreCommitResult.ok;
1806
1848
  if (!wikiPreCommitResult.ok) wikiPreCommitApplyFailReason = wikiPreCommitResult.reason;
1849
+ wikiPreCommitWriteFailed = wikiPreCommitResult.writeFailed === true;
1807
1850
  }
1808
1851
  // codex core hooks + settings + wiki-*→hypo-* rename mirror. Same merged,
1809
1852
  // single-write transform as the claude side above.
@@ -1913,10 +1956,17 @@ if (args.json) {
1913
1956
  // active install to, kept as diagnostic output.
1914
1957
  wantRoot: wikiHookWantRoot,
1915
1958
  drift: wikiPreCommitDrift,
1959
+ // true for a hook on the previous commit-time resolver (no baked
1960
+ // root, but upgrade --apply rewrites it onto the current one).
1961
+ previousResolver: wikiPreCommitInfo.previousResolver === true,
1916
1962
  // true only for "marker present, body unreadable" (see
1917
1963
  // checkWikiPreCommitRoot above). Absent/false for both a clean
1918
1964
  // new-form hook and an old-form one this run can still parse.
1919
1965
  unrecognized: wikiPreCommitInfo.unrecognized === true,
1966
+ // Why --apply left the hook as it was (null when it did not try, or
1967
+ // when it migrated). Together with applied.wikiPreCommitRoot this
1968
+ // tells a refusal from a write that failed.
1969
+ applyFailure: wikiPreCommitApplyFailReason,
1920
1970
  }
1921
1971
  : null,
1922
1972
  extensions: extCheck,
@@ -1951,6 +2001,7 @@ if (args.json) {
1951
2001
  );
1952
2002
  process.exit(
1953
2003
  (hasDrift && !args.apply) ||
2004
+ wikiPreCommitWriteFailed ||
1954
2005
  extCheck.conflicts.length > 0 ||
1955
2006
  (extCheckCodex?.conflicts.length ?? 0) > 0
1956
2007
  ? 1
@@ -1971,6 +2022,7 @@ if (pluginMode) {
1971
2022
  ' plugin loader, so `/hypo:upgrade` does NOT manage them (and `--apply` will',
1972
2023
  ' not copy/register them — that would double-register every hook).',
1973
2024
  ' → To upgrade the plugin: `/plugin marketplace update hypomnema` then `/reload-plugins`.',
2025
+ ` ${NEW_SESSION_HINT}`,
1974
2026
  ' → `/hypo:upgrade` (apply step confirmed) here applies vault-side migrations (SCHEMA,',
1975
2027
  ' .hypoignore), refreshes package metadata, and still syncs any vault',
1976
2028
  ' extensions — but does NOT install the core hooks/commands/settings.',
@@ -1990,6 +2042,7 @@ if (dualSkip) {
1990
2042
  ' → Recommended: pick ONE install. To keep the plugin, remove the npm/manual copy',
1991
2043
  ' (`npm uninstall -g hypomnema`) and upgrade via `/plugin marketplace update',
1992
2044
  ' hypomnema` + `/reload-plugins`. Vault extensions + codex (if any) are still synced.',
2045
+ ` ${NEW_SESSION_HINT}`,
1993
2046
  ' → To register the core surface here anyway (knowingly accept the double-register',
1994
2047
  ' risk), re-run with `--allow-dual-install`.',
1995
2048
  '',
@@ -2018,6 +2071,7 @@ if (dualSkip) {
2018
2071
  ' → Fix: repair or refresh ~/.claude/plugins/installed_plugins.json (reinstall the plugin,',
2019
2072
  ' or run `/plugin marketplace update hypomnema` then `/reload-plugins`),',
2020
2073
  ' then re-run `hypomnema upgrade --apply` to record the confirmed root.',
2074
+ ` ${NEW_SESSION_HINT}`,
2021
2075
  '',
2022
2076
  );
2023
2077
  }
@@ -2226,7 +2280,24 @@ if (dualSkip && dualSkipCorrected) {
2226
2280
  }
2227
2281
 
2228
2282
  // Vault pre-commit hook install root
2229
- if (wikiPreCommitInfo && wikiPreCommitDrift) {
2283
+ if (wikiPreCommitInfo && wikiPreCommitDrift && wikiPreCommitInfo.previousResolver) {
2284
+ if (appliedWikiPreCommitRoot) {
2285
+ lines.push(
2286
+ `✓ Wiki pre-commit hook moved to the current commit-time resolver, which checks the` +
2287
+ ` enabled plugin before hypo-pkg.json`,
2288
+ );
2289
+ } else if (args.apply) {
2290
+ lines.push(
2291
+ `⚠ Wiki pre-commit could not update hook (${wikiPreCommitApplyFailReason}) —` +
2292
+ ` it is still on the older resolver`,
2293
+ );
2294
+ } else {
2295
+ lines.push(
2296
+ `⚠ Wiki pre-commit hook uses an older resolver that reads hypo-pkg.json before the` +
2297
+ ` enabled plugin — run --apply to update it`,
2298
+ );
2299
+ }
2300
+ } else if (wikiPreCommitInfo && wikiPreCommitDrift) {
2230
2301
  if (appliedWikiPreCommitRoot) {
2231
2302
  lines.push(
2232
2303
  `✓ Wiki pre-commit hook migrated off the baked-in root ${wikiPreCommitInfo.root}` +
@@ -2552,4 +2623,4 @@ console.log(lines.join('\n'));
2552
2623
  // drift, which only fails check mode). --force-extensions clears the resolvable
2553
2624
  // cases; an unfollowable symlink/non-regular dest still counts and stays exit 1.
2554
2625
  const extBlocked = extCheck.conflicts.length > 0 || (extCheckCodex?.conflicts.length ?? 0) > 0;
2555
- process.exit((hasDrift && !args.apply) || extBlocked ? 1 : 0);
2626
+ process.exit((hasDrift && !args.apply) || extBlocked || wikiPreCommitWriteFailed ? 1 : 0);
package/templates/Home.md CHANGED
@@ -19,7 +19,7 @@ tags: [wiki, home]
19
19
  - [[SCHEMA]] — type system reference
20
20
  - [[hypo-guide]] — operations guide
21
21
 
22
- > **Auto-ingest rule**: after any `WebFetch` / `WebSearch` that yields relevant knowledge, run `/hypo:ingest` immediately without waiting for an explicit request.
22
+ > **Ingest nudge**: after a `WebFetch` / `WebSearch`, a hook only reminds Claude about `/hypo:ingest`. When the result is worth keeping, Claude runs `/hypo:ingest` itself.
23
23
 
24
24
  ---
25
25
 
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  title: Hypomnema Config
3
3
  type: config
4
- version: "1.10.0"
4
+ version: "1.10.2"
5
5
  created: YYYY-MM-DD
6
6
  ---
7
7