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.
- package/.claude-plugin/marketplace.json +1 -1
- package/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +31 -0
- package/README.ko.md +5 -5
- package/README.md +5 -5
- package/commands/crystallize.md +21 -15
- package/commands/upgrade.md +13 -2
- package/docs/ARCHITECTURE.md +127 -63
- package/docs/CONTRIBUTING.md +7 -11
- package/hooks/base-store.mjs +31 -17
- package/hooks/hypo-auto-minimal-crystallize.mjs +39 -6
- package/hooks/hypo-auto-stage.mjs +123 -63
- package/hooks/hypo-close-guard.mjs +3 -37
- package/hooks/hypo-compact-guard.mjs +9 -6
- package/hooks/hypo-file-watch.mjs +18 -10
- package/hooks/hypo-personal-check.mjs +137 -55
- package/hooks/hypo-session-start.mjs +17 -6
- package/hooks/hypo-shared.mjs +1507 -569
- package/hooks/hypo-stop.mjs +8 -0
- package/hooks/session-views.mjs +9 -3
- package/package.json +2 -1
- package/scripts/crystallize.mjs +1 -1
- package/scripts/doctor.mjs +160 -9
- package/scripts/init.mjs +60 -22
- package/scripts/lib/crystallize-close-apply.mjs +156 -22
- package/scripts/lib/crystallize-close-check.mjs +1 -1
- package/scripts/lib/extensions.mjs +2 -2
- package/scripts/lib/git-hooks-dir.mjs +228 -31
- package/scripts/lib/plugin-detect.mjs +57 -4
- package/scripts/lib/settings-write.mjs +254 -0
- package/scripts/lib/wikilink.mjs +10 -1
- package/scripts/uninstall.mjs +3 -2
- package/scripts/upgrade.mjs +94 -23
- package/templates/Home.md +1 -1
- package/templates/hypo-config.md +1 -1
- package/templates/hypo-guide.md +60 -22
- package/templates/session-state.md +0 -12
package/hooks/hypo-stop.mjs
CHANGED
|
@@ -96,6 +96,11 @@ function parseStageOutput(stdout) {
|
|
|
96
96
|
* reports the kill as ETIMEDOUT); `signal` without a timeout is a death from
|
|
97
97
|
* outside, such as an OOM kill.
|
|
98
98
|
*
|
|
99
|
+
* `spawnEndKind` in hypo-shared.mjs makes the same judgment for the lint and
|
|
100
|
+
* feedback runs of the close gate, in the same order (timeout, spawn error,
|
|
101
|
+
* signal, exit status). This file uses Node built-ins only, so the two cannot
|
|
102
|
+
* share one function: change the order in both or in neither.
|
|
103
|
+
*
|
|
99
104
|
* @param {{file: string, timeoutMs: number}} stage
|
|
100
105
|
* @param {{error?: Error, status: number|null, signal: string|null}} res
|
|
101
106
|
* @returns {string|null}
|
|
@@ -147,6 +152,9 @@ for (const stage of STAGES) {
|
|
|
147
152
|
input: raw,
|
|
148
153
|
encoding: 'utf-8',
|
|
149
154
|
timeout: stage.timeoutMs,
|
|
155
|
+
// The stage's own budget, so a stage that caps its work by it reads the same number
|
|
156
|
+
// this table enforces instead of keeping a copy that can drift.
|
|
157
|
+
env: { ...process.env, HYPO_STAGE_TIMEOUT_MS: String(stage.timeoutMs) },
|
|
150
158
|
});
|
|
151
159
|
} catch (err) {
|
|
152
160
|
process.stderr.write(`[hypo-stop] error: ${stage.file}: ${err?.message ?? String(err)}\n`);
|
package/hooks/session-views.mjs
CHANGED
|
@@ -943,8 +943,9 @@ function returnStrandedIndex(hypoDir, sha, headBefore) {
|
|
|
943
943
|
* `archived[]`, `localOnly[]`, `unowned[]` and `cleared[]` are for the caller, after a successful
|
|
944
944
|
* merge). The `.gitignore` goes back as the exact bytes it held (`undoClearedPaths`), not as lines
|
|
945
945
|
* appended; a `.gitignore` that is staged when the clearing step checks is deferred, not moved.
|
|
946
|
-
* `notice` carries git's whole stderr after a failed merge, which names the files in the way,
|
|
947
|
-
*
|
|
946
|
+
* `notice` carries git's whole stderr after a failed merge, which names the files in the way, git's
|
|
947
|
+
* own first lines when the clearing step stopped on a failed checkout or reset (a stale index lock),
|
|
948
|
+
* and any path that could not be put back.
|
|
948
949
|
*/
|
|
949
950
|
export function fastForwardTo(hypoDir, sha, { testHooks } = {}) {
|
|
950
951
|
const pre = clearGeneratedPathsBlockingPull(hypoDir, sha, { testHooks });
|
|
@@ -958,7 +959,12 @@ export function fastForwardTo(hypoDir, sha, { testHooks } = {}) {
|
|
|
958
959
|
0;
|
|
959
960
|
if (!pre.ok) {
|
|
960
961
|
const undone = moved ? undoClearedPaths(hypoDir, pre).notices : [];
|
|
961
|
-
|
|
962
|
+
// git's own first lines (a stale .git/index.lock) say why the clearing step stopped; without
|
|
963
|
+
// them the same notice repeats every run with no diagnosis. Same wording as pullRemote.
|
|
964
|
+
const gitSaid = pre.gitError
|
|
965
|
+
? `git의 말: ${pre.gitError}. git이 잠금 파일(.lock)을 가리키는데 실행 중인 git 프로세스가 없다면, 그 파일을 직접 지운 뒤 다시 시도하면 됩니다`
|
|
966
|
+
: null;
|
|
967
|
+
const notice = [pre.notice, gitSaid, ...undone].filter(Boolean).join('\n') || undefined;
|
|
962
968
|
return { ok: false, pre, deferred: pre.deferred, reason: pre.reason, notice };
|
|
963
969
|
}
|
|
964
970
|
const headBefore = gitRun(hypoDir, ['rev-parse', '--verify', '--quiet', 'HEAD']).stdout.trim();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hypomnema",
|
|
3
|
-
"version": "1.10.
|
|
3
|
+
"version": "1.10.2",
|
|
4
4
|
"description": "LLM-native personal wiki system for Claude Code",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -51,6 +51,7 @@
|
|
|
51
51
|
"scripts/lib/project-create.mjs",
|
|
52
52
|
"scripts/lib/rename-marker.mjs",
|
|
53
53
|
"scripts/lib/schema-vocab.mjs",
|
|
54
|
+
"scripts/lib/settings-write.mjs",
|
|
54
55
|
"scripts/lib/slug-resolver.mjs",
|
|
55
56
|
"scripts/lib/template-schema-version.mjs",
|
|
56
57
|
"scripts/lib/time.mjs",
|
package/scripts/crystallize.mjs
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* letters/marks/numbers of any script plus ._-, projects/<slug>/ must exist). On --check it NARROWS the
|
|
18
18
|
* gate to that one project: a project-scoped diagnostic, NOT a global
|
|
19
19
|
* close verdict. On --mark it is ATTRIBUTION only; the gate stays
|
|
20
|
-
* global (the marker gate is the
|
|
20
|
+
* global (the marker gate is the same gate, and it runs the same git check as --check). Ignored on --apply.
|
|
21
21
|
* --apply-session-close Apply a JSON payload that updates the 4 mandatory memory files
|
|
22
22
|
* (+ optional open-questions). Idempotent — re-running with the same
|
|
23
23
|
* payload is a no-op. Always finishes with the strict gate check.
|
package/scripts/doctor.mjs
CHANGED
|
@@ -23,6 +23,7 @@ import { loadHypoIgnore, isScanIgnored } from './lib/hypo-ignore.mjs';
|
|
|
23
23
|
import { readRenameMarker, renameMarkerPath, RENAME_MARKER_REL } from './lib/rename-marker.mjs';
|
|
24
24
|
import {
|
|
25
25
|
resolveGitHooksDir,
|
|
26
|
+
shellSingleQuote,
|
|
26
27
|
WIKI_PRE_COMMIT_MARKER_START,
|
|
27
28
|
parseWikiPreCommitRoot,
|
|
28
29
|
} from './lib/git-hooks-dir.mjs';
|
|
@@ -86,7 +87,12 @@ import {
|
|
|
86
87
|
computeHooksDigest,
|
|
87
88
|
} from './lib/pkg-provenance.mjs';
|
|
88
89
|
import { resolveCliOnPath, classifyInstall, upgradeApplyHint } from '../hooks/version-check.mjs';
|
|
89
|
-
import {
|
|
90
|
+
import {
|
|
91
|
+
closeCheckpointState,
|
|
92
|
+
isCloseComplete,
|
|
93
|
+
readReceiptStrict,
|
|
94
|
+
verifyEntriesInCommit,
|
|
95
|
+
} from '../hooks/close-receipt.mjs';
|
|
90
96
|
import {
|
|
91
97
|
enabledHypomnemaPluginKey,
|
|
92
98
|
usablePkgRoot,
|
|
@@ -677,7 +683,18 @@ function checkGit(hypoDir) {
|
|
|
677
683
|
// plugin-cache leaf-drift precedent: reporting must never turn into
|
|
678
684
|
// filtering, or a still-real, still-resolvable root looks like it vanished).
|
|
679
685
|
const parsedRoot = parseWikiPreCommitRoot(content);
|
|
680
|
-
if (parsedRoot.ok && parsedRoot.
|
|
686
|
+
if (parsedRoot.ok && parsedRoot.previousResolver === true) {
|
|
687
|
+
// Also resolves at commit time, but through the previous resolver, which
|
|
688
|
+
// reads the sidecar before the enabled plugin and so can keep running a
|
|
689
|
+
// stale install. Only the current form earns the pass below.
|
|
690
|
+
warn(
|
|
691
|
+
`${label} root`,
|
|
692
|
+
'Uses an older commit-time resolver that reads the sidecar before the enabled ' +
|
|
693
|
+
`plugin, so it can run a stale install. Run ${upgradeApplyHint(
|
|
694
|
+
pluginMode || hypomnemaPluginEnabled,
|
|
695
|
+
)} to update it.`,
|
|
696
|
+
);
|
|
697
|
+
} else if (parsedRoot.ok && parsedRoot.root === null) {
|
|
681
698
|
// The runtime-resolving form: the hook looks up its own
|
|
682
699
|
// install root at commit time, so there is no baked value to compare
|
|
683
700
|
// against the active install — it cannot structurally go stale the way
|
|
@@ -1255,6 +1272,18 @@ function checkSessionCloseArtifacts(hypoDir) {
|
|
|
1255
1272
|
brokenMarkers.push({ sessionId, reason: checkpoint.reason });
|
|
1256
1273
|
continue;
|
|
1257
1274
|
}
|
|
1275
|
+
// A closed checkpoint whose receipt names file versions its commit does
|
|
1276
|
+
// not hold vouches for nothing, the same as a missing receipt.
|
|
1277
|
+
if (checkpoint.receipt) {
|
|
1278
|
+
const bad = receiptEvidenceMismatches(hypoDir, checkpoint.receipt);
|
|
1279
|
+
if (bad.length > 0) {
|
|
1280
|
+
brokenMarkers.push({
|
|
1281
|
+
sessionId,
|
|
1282
|
+
reason: `receipt evidence mismatch: ${describeMismatches(bad)}`,
|
|
1283
|
+
});
|
|
1284
|
+
continue;
|
|
1285
|
+
}
|
|
1286
|
+
}
|
|
1258
1287
|
// ONLY the v4 `projects` array counts as project-scope evidence. A
|
|
1259
1288
|
// legacy flat `project` field can be a recency-derived misattribution
|
|
1260
1289
|
// (the P1 bug resolveCloseScope's own doc comment describes) — the
|
|
@@ -1294,14 +1323,12 @@ function checkSessionCloseArtifacts(hypoDir) {
|
|
|
1294
1323
|
.map((a) => `${a.where}${a.date ? ` (${a.date})` : ''}`)
|
|
1295
1324
|
.join(', ');
|
|
1296
1325
|
const extra = unmatched.length > 5 ? ` (+${unmatched.length - 5} more)` : '';
|
|
1326
|
+
const namedBrokenMarkers = brokenMarkers.slice(0, 3);
|
|
1297
1327
|
const brokenNote =
|
|
1298
1328
|
brokenMarkers.length > 0
|
|
1299
1329
|
? `. ${brokenMarkers.length} session-closed marker(s) did not count because their close ` +
|
|
1300
1330
|
`checkpoint is broken: ` +
|
|
1301
|
-
|
|
1302
|
-
.slice(0, 3)
|
|
1303
|
-
.map((b) => `${b.sessionId} (${b.reason})`)
|
|
1304
|
-
.join('; ')
|
|
1331
|
+
namedBrokenMarkers.map((b) => `${b.sessionId} (${b.reason})`).join('; ')
|
|
1305
1332
|
: '';
|
|
1306
1333
|
// Not necessarily UNAPPROVED — an approved log-only marker (deliberately
|
|
1307
1334
|
// empty `projects`) or one scoped to a different project would ALSO land
|
|
@@ -1314,6 +1341,129 @@ function checkSessionCloseArtifacts(hypoDir) {
|
|
|
1314
1341
|
`date and project scope — may be an unapproved hand-made close, or an approved close ` +
|
|
1315
1342
|
`whose marker doesn't attribute this project: ${sample}${extra}${brokenNote}`,
|
|
1316
1343
|
);
|
|
1344
|
+
// The sessions whose receipt evidence mismatch the line above names, so the receipt check
|
|
1345
|
+
// does not warn about the same receipt a second time. Only what was named counts: a marker
|
|
1346
|
+
// walk that passes, or names no more than three, leaves the rest to the receipt check.
|
|
1347
|
+
return new Set(
|
|
1348
|
+
namedBrokenMarkers
|
|
1349
|
+
.filter((b) => b.reason.startsWith('receipt evidence mismatch'))
|
|
1350
|
+
.map((b) => b.sessionId),
|
|
1351
|
+
);
|
|
1352
|
+
}
|
|
1353
|
+
|
|
1354
|
+
// The commit-based entries of a receipt (everything but local-create) against
|
|
1355
|
+
// the commit it names. A local-create entry is the bytes on disk, which a human
|
|
1356
|
+
// may legitimately edit after the close, so it is not compared here. Reads git
|
|
1357
|
+
// objects only, so doctor stays read-only.
|
|
1358
|
+
function receiptEvidenceMismatches(hypoDir, receipt) {
|
|
1359
|
+
return verifyEntriesInCommit(
|
|
1360
|
+
hypoDir,
|
|
1361
|
+
receipt.commit,
|
|
1362
|
+
receipt.entries.filter((e) => e.kind !== 'local-create'),
|
|
1363
|
+
).mismatches;
|
|
1364
|
+
}
|
|
1365
|
+
|
|
1366
|
+
function describeMismatches(mismatches) {
|
|
1367
|
+
return (
|
|
1368
|
+
mismatches
|
|
1369
|
+
.slice(0, 3)
|
|
1370
|
+
.map((m) => `${m.path} (${m.reason})`)
|
|
1371
|
+
.join(', ') + (mismatches.length > 3 ? ` (+${mismatches.length - 3} more)` : '')
|
|
1372
|
+
);
|
|
1373
|
+
}
|
|
1374
|
+
|
|
1375
|
+
// Warn when a valid receipt in the 7-day window names file versions its commit
|
|
1376
|
+
// does not hold (a forged or hand-edited receipt, an older writer's defect, a
|
|
1377
|
+
// damaged git object). Silent when every receipt checks out, like
|
|
1378
|
+
// checkHalfClosedReceipts.
|
|
1379
|
+
function checkReceiptEvidence(hypoDir, namedByMarkerWalk = new Set()) {
|
|
1380
|
+
const sessionsDir = join(hypoDir, '.cache', 'sessions');
|
|
1381
|
+
let dirs = [];
|
|
1382
|
+
try {
|
|
1383
|
+
dirs = readdirSync(sessionsDir);
|
|
1384
|
+
} catch {
|
|
1385
|
+
return; // no sessions directory, or unreadable: nothing to judge
|
|
1386
|
+
}
|
|
1387
|
+
const bad = [];
|
|
1388
|
+
for (const name of dirs) {
|
|
1389
|
+
const file = join(sessionsDir, name, 'close-receipt.json');
|
|
1390
|
+
try {
|
|
1391
|
+
if (Date.now() - statSync(file).mtimeMs > SESSION_CLOSED_MARKER_STALE_MS) continue;
|
|
1392
|
+
// The directory name is the sanitized id; the receipt body carries the real one.
|
|
1393
|
+
const body = JSON.parse(readFileSync(file, 'utf-8'));
|
|
1394
|
+
const sessionId =
|
|
1395
|
+
typeof body?.sessionId === 'string' && body.sessionId ? body.sessionId : name;
|
|
1396
|
+
if (namedByMarkerWalk.has(sessionId)) continue; // already warned by the marker walk
|
|
1397
|
+
const read = readReceiptStrict(hypoDir, sessionId);
|
|
1398
|
+
if (read.status !== 'valid') continue; // checkHalfClosedReceipts and the marker walk own these
|
|
1399
|
+
const mismatches = receiptEvidenceMismatches(hypoDir, read.receipt);
|
|
1400
|
+
if (mismatches.length > 0) bad.push({ sessionId, file, mismatches });
|
|
1401
|
+
} catch {
|
|
1402
|
+
// unreadable or corrupt receipt: not this check's job to diagnose
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1405
|
+
if (bad.length === 0) return;
|
|
1406
|
+
// The close such a receipt certifies is no longer proven by its commit, so the advice is the
|
|
1407
|
+
// check that says where that close stands now, and closing again when it is not closed.
|
|
1408
|
+
const crystallize = join(PKG_ROOT, 'scripts', 'crystallize.mjs');
|
|
1409
|
+
warn(
|
|
1410
|
+
'Session-close receipt evidence',
|
|
1411
|
+
`${bad.length} close receipt(s) name file versions their commit does not hold: ` +
|
|
1412
|
+
bad
|
|
1413
|
+
.slice(0, 3)
|
|
1414
|
+
.map(
|
|
1415
|
+
(b) =>
|
|
1416
|
+
`${b.sessionId} (${b.file}): ${describeMismatches(b.mismatches)}. Check with: ` +
|
|
1417
|
+
`node "${crystallize}" --check-session-close --session-id=${b.sessionId} ` +
|
|
1418
|
+
`--hypo-dir=${shellSingleQuote(hypoDir)} --json`,
|
|
1419
|
+
)
|
|
1420
|
+
.join('; ') +
|
|
1421
|
+
(bad.length > 3 ? ` (+${bad.length - 3} more)` : '') +
|
|
1422
|
+
'. The close such a receipt certifies is no longer proven by its commit: if the check does ' +
|
|
1423
|
+
'not report it closed, ask the user to close that project again and apply it with ' +
|
|
1424
|
+
'/hypo:crystallize',
|
|
1425
|
+
);
|
|
1426
|
+
}
|
|
1427
|
+
|
|
1428
|
+
// The scope a receipt body names, when its shape is one a writer emits: a log-only receipt, or
|
|
1429
|
+
// a project receipt naming at least one slug. Anything else is unknown (null), so the recovery
|
|
1430
|
+
// text asks for the scope instead of guessing it.
|
|
1431
|
+
function receiptScope(body) {
|
|
1432
|
+
const scope = body?.scope;
|
|
1433
|
+
if (!scope || typeof scope !== 'object') return null;
|
|
1434
|
+
if (scope.mode === 'log-only') return { logOnly: true, projects: [] };
|
|
1435
|
+
const ok =
|
|
1436
|
+
scope.mode === 'project' &&
|
|
1437
|
+
Array.isArray(scope.projects) &&
|
|
1438
|
+
scope.projects.length > 0 &&
|
|
1439
|
+
scope.projects.every((p) => typeof p === 'string' && p);
|
|
1440
|
+
return ok ? { logOnly: false, projects: scope.projects } : null;
|
|
1441
|
+
}
|
|
1442
|
+
|
|
1443
|
+
// The recovery text for one markerless receipt. `--mark-session-closed` is told the vault and the
|
|
1444
|
+
// scope the receipt certified: without `--hypo-dir` it can act on another vault, and without
|
|
1445
|
+
// `--project` or `--log-only` an apply whose project only appeared in its payload leaves it no
|
|
1446
|
+
// attribution evidence (a Bash apply edits no close file the transcript could show). The writer
|
|
1447
|
+
// takes one `--project`, so a receipt that names several projects has no single command that
|
|
1448
|
+
// restores its full scope: that case sends the user back through the close instead.
|
|
1449
|
+
function recoveryAdvice(hypoDir, crystallize, b) {
|
|
1450
|
+
const base = `node "${crystallize}" --mark-session-closed --session-id=${b.sessionId} --hypo-dir=${shellSingleQuote(hypoDir)}`;
|
|
1451
|
+
const { scope } = b;
|
|
1452
|
+
if (scope?.logOnly) return `Recover with: ${base} --log-only`;
|
|
1453
|
+
if (scope?.projects.length === 1) {
|
|
1454
|
+
return `Recover with: ${base} --project=${shellSingleQuote(scope.projects[0])}`;
|
|
1455
|
+
}
|
|
1456
|
+
if (scope) {
|
|
1457
|
+
return (
|
|
1458
|
+
`Its receipt covers ${scope.projects.length} projects (${scope.projects.join(', ')}) and ` +
|
|
1459
|
+
`--mark-session-closed takes one --project, so it would attest only one of them. Ask the ` +
|
|
1460
|
+
`user to close again and apply it with /hypo:crystallize`
|
|
1461
|
+
);
|
|
1462
|
+
}
|
|
1463
|
+
return (
|
|
1464
|
+
`Recover with: ${base} plus --project=<slug> for the project it closed, or --log-only for a ` +
|
|
1465
|
+
`session that closed no project (the receipt names no readable scope)`
|
|
1466
|
+
);
|
|
1317
1467
|
}
|
|
1318
1468
|
|
|
1319
1469
|
// A close receipt with no session-closed marker beside it is a half-finished
|
|
@@ -1352,7 +1502,7 @@ function checkHalfClosedReceipts(hypoDir) {
|
|
|
1352
1502
|
0 &&
|
|
1353
1503
|
spawnSync('git', ['-C', hypoDir, 'merge-base', '--is-ancestor', commit, 'HEAD']).status !==
|
|
1354
1504
|
0;
|
|
1355
|
-
broken.push({ sessionId, reason: checkpoint.reason, rewritten });
|
|
1505
|
+
broken.push({ sessionId, reason: checkpoint.reason, rewritten, scope: receiptScope(body) });
|
|
1356
1506
|
} catch {
|
|
1357
1507
|
// unreadable or corrupt receipt: not this check's job to diagnose
|
|
1358
1508
|
}
|
|
@@ -1367,7 +1517,7 @@ function checkHalfClosedReceipts(hypoDir) {
|
|
|
1367
1517
|
.map((b) =>
|
|
1368
1518
|
b.rewritten
|
|
1369
1519
|
? `${b.sessionId} (${b.reason}; the commit it certified is no longer in this branch's history). Restore that commit, or ask the user to close again and apply it with /hypo:crystallize`
|
|
1370
|
-
: `${b.sessionId} (${b.reason}).
|
|
1520
|
+
: `${b.sessionId} (${b.reason}). ${recoveryAdvice(hypoDir, crystallize, b)}`,
|
|
1371
1521
|
)
|
|
1372
1522
|
.join('; ') +
|
|
1373
1523
|
(broken.length > 3 ? ` (+${broken.length - 3} more)` : ''),
|
|
@@ -3168,8 +3318,9 @@ if (args.codex) checkCodexPaths();
|
|
|
3168
3318
|
if (rootOk) checkExtensions(args.hypoDir, args.claudeHome, 'claude');
|
|
3169
3319
|
if (rootOk && args.codex) checkExtensions(args.hypoDir, args.claudeHome, 'codex');
|
|
3170
3320
|
if (rootOk) checkProjectIndexAnchors(args.hypoDir);
|
|
3171
|
-
|
|
3321
|
+
const namedByMarkerWalk = rootOk ? checkSessionCloseArtifacts(args.hypoDir) : undefined;
|
|
3172
3322
|
if (rootOk) checkHalfClosedReceipts(args.hypoDir);
|
|
3323
|
+
if (rootOk) checkReceiptEvidence(args.hypoDir, namedByMarkerWalk);
|
|
3173
3324
|
if (rootOk) checkBaselineIntegrity(args.hypoDir);
|
|
3174
3325
|
if (rootOk) checkSessionEntries(args.hypoDir);
|
|
3175
3326
|
if (rootOk) checkSyncState(args.hypoDir);
|
package/scripts/init.mjs
CHANGED
|
@@ -26,7 +26,6 @@ import {
|
|
|
26
26
|
mkdirSync,
|
|
27
27
|
readFileSync,
|
|
28
28
|
writeFileSync,
|
|
29
|
-
chmodSync,
|
|
30
29
|
copyFileSync,
|
|
31
30
|
readdirSync,
|
|
32
31
|
renameSync,
|
|
@@ -40,6 +39,7 @@ import { createHash } from 'crypto';
|
|
|
40
39
|
import { expandHome, resolveHypoRoot } from './lib/hypo-root.mjs';
|
|
41
40
|
import {
|
|
42
41
|
hooksDirForInstall,
|
|
42
|
+
unsafeHookTarget,
|
|
43
43
|
unsafeHookTargetReason,
|
|
44
44
|
findMarkerSpan,
|
|
45
45
|
WIKI_PRE_COMMIT_MARKER_START,
|
|
@@ -49,6 +49,7 @@ import {
|
|
|
49
49
|
SHELL_FUNCTION_BODY,
|
|
50
50
|
wikiPreCommitContent,
|
|
51
51
|
uniqueBakPath,
|
|
52
|
+
publishHookFile,
|
|
52
53
|
} from './lib/git-hooks-dir.mjs';
|
|
53
54
|
import { loadHookInventory } from './lib/hook-inventory.mjs';
|
|
54
55
|
import { renderViews, missingBlockLines, GITATTRIBUTES_BLOCK } from '../hooks/session-entries.mjs';
|
|
@@ -62,6 +63,7 @@ import {
|
|
|
62
63
|
} from './lib/pkg-json.mjs';
|
|
63
64
|
import { syncExtensions } from './lib/extensions.mjs';
|
|
64
65
|
import { writeProvenanceSidecar } from './lib/pkg-provenance.mjs';
|
|
66
|
+
import { writeSettingsJson } from './lib/settings-write.mjs';
|
|
65
67
|
import { templateSchemaVersion } from './lib/template-schema-version.mjs';
|
|
66
68
|
import { classifyInstall, downgradeGuardMessage } from '../hooks/version-check.mjs';
|
|
67
69
|
import { resolvePluginChannel, isHypomnemaInstallRoot } from './lib/plugin-detect.mjs';
|
|
@@ -502,8 +504,7 @@ function mergeSettingsJson(settingsPath, hooksDir, dryRun, hookMap) {
|
|
|
502
504
|
}
|
|
503
505
|
|
|
504
506
|
if (changed && !dryRun) {
|
|
505
|
-
|
|
506
|
-
writeFileSync(settingsPath, JSON.stringify(settings, null, 2) + '\n');
|
|
507
|
+
writeSettingsJson(settingsPath, JSON.stringify(settings, null, 2) + '\n');
|
|
507
508
|
}
|
|
508
509
|
}
|
|
509
510
|
|
|
@@ -759,22 +760,47 @@ function installPkgGitHook(dryRun) {
|
|
|
759
760
|
// it generates resolves that itself, at commit time, so there is nothing here
|
|
760
761
|
// for a plugin-channel version bump to make stale.
|
|
761
762
|
|
|
763
|
+
// Replaces the hook through a complete candidate file, so a write that fails
|
|
764
|
+
// partway leaves the live hook as it was. A failure is reported as an error
|
|
765
|
+
// with the .bak path (when one was written) and any candidate that could not be
|
|
766
|
+
// removed; the caller stops without logging the hook as written.
|
|
767
|
+
function publishWikiHook(hookPath, newContent, bakPath) {
|
|
768
|
+
const published = publishHookFile(hookPath, newContent);
|
|
769
|
+
if (published.ok) return true;
|
|
770
|
+
const code = published.error.code || published.error.message;
|
|
771
|
+
const saved = bakPath ? `; the existing hook is unchanged and also saved at ${bakPath}` : '';
|
|
772
|
+
const leftover = published.cleaned
|
|
773
|
+
? ''
|
|
774
|
+
: `; the unused candidate file ${published.candidatePath} could not be removed`;
|
|
775
|
+
log('errors', `${hookPath} (could not write the pre-commit hook: ${code}${saved}${leftover})`);
|
|
776
|
+
return false;
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
// Returns 'installed' (written, or already current), 'skipped' (a legitimate
|
|
780
|
+
// reason not to touch the hook, logged where it is worth surfacing) or 'failed'
|
|
781
|
+
// (the write was attempted and did not land). Only 'failed' stops the first
|
|
782
|
+
// commit: a skipped install is today's behavior, but a failed one would let
|
|
783
|
+
// that commit run without the .hypoignore guard the install was meant to put
|
|
784
|
+
// in front of it.
|
|
762
785
|
function installWikiPreCommitHook(hypoDir, dryRun, force, lintStrict) {
|
|
763
|
-
const { dir: hooksDir, skip } = hooksDirForInstall(hypoDir);
|
|
786
|
+
const { dir: hooksDir, skip, operational } = hooksDirForInstall(hypoDir);
|
|
764
787
|
if (!hooksDir) {
|
|
765
|
-
// no git repo
|
|
766
|
-
|
|
767
|
-
|
|
788
|
+
// no git repo is silent, as before; a refusal on purpose (hooks disabled, shared hooks dir,
|
|
789
|
+
// git missing) is a skip; git or the filesystem failing to resolve the dir is a failure
|
|
790
|
+
if (skip) log(operational ? 'errors' : 'skipped', `${hypoDir} pre-commit (${skip})`);
|
|
791
|
+
return operational ? 'failed' : 'skipped';
|
|
768
792
|
}
|
|
769
793
|
const hookPath = join(hooksDir, 'pre-commit');
|
|
770
794
|
const newContent = wikiPreCommitContent(hypoDir, lintStrict);
|
|
771
795
|
|
|
772
796
|
// Before every branch below, including --force: a symlink here would send the
|
|
773
797
|
// write through to an arbitrary external file.
|
|
774
|
-
const unsafe =
|
|
798
|
+
const unsafe = unsafeHookTarget(hookPath);
|
|
775
799
|
if (unsafe) {
|
|
776
|
-
|
|
777
|
-
|
|
800
|
+
// a stat that failed with an errno (EACCES on the hooks dir) is not a decision to leave
|
|
801
|
+
// the hook alone: the guard is not in place and the first commit must not run
|
|
802
|
+
log(unsafe.operational ? 'errors' : 'skipped', `${hookPath} (${unsafe.reason})`);
|
|
803
|
+
return unsafe.operational ? 'failed' : 'skipped';
|
|
778
804
|
}
|
|
779
805
|
|
|
780
806
|
if (existsSync(hookPath)) {
|
|
@@ -782,7 +808,7 @@ function installWikiPreCommitHook(hypoDir, dryRun, force, lintStrict) {
|
|
|
782
808
|
if (existing.includes(WIKI_PRE_COMMIT_MARKER_START)) {
|
|
783
809
|
if (existing === newContent) {
|
|
784
810
|
log('skipped', `${hookPath} (pre-commit up to date)`);
|
|
785
|
-
return;
|
|
811
|
+
return 'installed';
|
|
786
812
|
}
|
|
787
813
|
// Back this up first. The marker's presence says our block is IN the
|
|
788
814
|
// file; it says nothing about what else is, and this branch replaces the
|
|
@@ -795,12 +821,11 @@ function installWikiPreCommitHook(hypoDir, dryRun, force, lintStrict) {
|
|
|
795
821
|
const bakPath = uniqueBakPath(hookPath);
|
|
796
822
|
if (!bakPath) {
|
|
797
823
|
log('skipped', `${hookPath} (unsafe backup path) — not overwriting without a safe backup`);
|
|
798
|
-
return;
|
|
824
|
+
return 'skipped';
|
|
799
825
|
}
|
|
800
826
|
if (!dryRun) {
|
|
801
827
|
writeFileSync(bakPath, existing);
|
|
802
|
-
|
|
803
|
-
chmodSync(hookPath, 0o755);
|
|
828
|
+
if (!publishWikiHook(hookPath, newContent, bakPath)) return 'failed';
|
|
804
829
|
}
|
|
805
830
|
log('merged', `${hookPath} (pre-commit updated, backup at ${basename(bakPath)})`);
|
|
806
831
|
} else if (force) {
|
|
@@ -814,12 +839,11 @@ function installWikiPreCommitHook(hypoDir, dryRun, force, lintStrict) {
|
|
|
814
839
|
'skipped',
|
|
815
840
|
`${hookPath} (unsafe backup path) — not force-overwriting without a safe backup`,
|
|
816
841
|
);
|
|
817
|
-
return;
|
|
842
|
+
return 'skipped';
|
|
818
843
|
}
|
|
819
844
|
if (!dryRun) {
|
|
820
845
|
writeFileSync(bakPath, existing);
|
|
821
|
-
|
|
822
|
-
chmodSync(hookPath, 0o755);
|
|
846
|
+
if (!publishWikiHook(hookPath, newContent, bakPath)) return 'failed';
|
|
823
847
|
}
|
|
824
848
|
log('merged', `${hookPath} (force-overwritten, backup at ${basename(bakPath)})`);
|
|
825
849
|
} else {
|
|
@@ -827,14 +851,16 @@ function installWikiPreCommitHook(hypoDir, dryRun, force, lintStrict) {
|
|
|
827
851
|
'skipped',
|
|
828
852
|
`${hookPath} (user pre-commit exists — re-run with --force-commands to install)`,
|
|
829
853
|
);
|
|
854
|
+
return 'skipped';
|
|
830
855
|
}
|
|
831
|
-
return;
|
|
856
|
+
return 'installed';
|
|
832
857
|
}
|
|
833
858
|
if (!dryRun) {
|
|
834
859
|
mkdirSync(hooksDir, { recursive: true });
|
|
835
|
-
|
|
860
|
+
if (!publishWikiHook(hookPath, newContent)) return 'failed';
|
|
836
861
|
}
|
|
837
862
|
log('created', hookPath);
|
|
863
|
+
return 'installed';
|
|
838
864
|
}
|
|
839
865
|
|
|
840
866
|
// ── shell function setup ─────────────────────────────────────────────────────
|
|
@@ -1151,7 +1177,6 @@ if (args.fromRemote) {
|
|
|
1151
1177
|
copyTemplate('Overview.md', join(args.hypoDir, 'Overview.md'), args.dryRun);
|
|
1152
1178
|
copyTemplate('hypo-help.md', join(args.hypoDir, 'hypo-help.md'), args.dryRun);
|
|
1153
1179
|
copyTemplate('hypo-automation.md', join(args.hypoDir, 'hypo-automation.md'), args.dryRun);
|
|
1154
|
-
copyTemplate('session-state.md', join(args.hypoDir, 'session-state.md'), args.dryRun);
|
|
1155
1180
|
copyTemplate(join('pages', '_index.md'), join(args.hypoDir, 'pages', '_index.md'), args.dryRun);
|
|
1156
1181
|
copyTemplate(
|
|
1157
1182
|
join('pages', 'observability', '_index.md'),
|
|
@@ -1327,8 +1352,11 @@ if (args.hooks) {
|
|
|
1327
1352
|
// back on — skip installing the hook with a guessed root; an existing hook (if
|
|
1328
1353
|
// any) is left exactly as-is, and channelUnresolvedNotice() above says what to
|
|
1329
1354
|
// do next.
|
|
1355
|
+
let wikiHookFailed = false;
|
|
1330
1356
|
if (!channelUnresolved) {
|
|
1331
|
-
|
|
1357
|
+
wikiHookFailed =
|
|
1358
|
+
installWikiPreCommitHook(args.hypoDir, args.dryRun, args.forceCommands, args.lintStrict) ===
|
|
1359
|
+
'failed';
|
|
1332
1360
|
} else {
|
|
1333
1361
|
log(
|
|
1334
1362
|
'skipped',
|
|
@@ -1337,8 +1365,18 @@ if (!channelUnresolved) {
|
|
|
1337
1365
|
}
|
|
1338
1366
|
|
|
1339
1367
|
// 9. first commit + push (skip when cloned from remote — already has commits)
|
|
1368
|
+
// A failed hook install means the commit below would run without the .hypoignore
|
|
1369
|
+
// guard, so files excluded only by .hypoignore could be committed and pushed.
|
|
1340
1370
|
if (args.gitInit && !args.fromRemote) {
|
|
1341
|
-
|
|
1371
|
+
if (wikiHookFailed) {
|
|
1372
|
+
log(
|
|
1373
|
+
'errors',
|
|
1374
|
+
'first commit was not made because the pre-commit hook could not be installed; ' +
|
|
1375
|
+
'fix the permissions of the hooks directory and re-run `hypomnema init`',
|
|
1376
|
+
);
|
|
1377
|
+
} else {
|
|
1378
|
+
madeFirstCommit = firstCommit(args.hypoDir, args.gitRemote, args.dryRun);
|
|
1379
|
+
}
|
|
1342
1380
|
}
|
|
1343
1381
|
|
|
1344
1382
|
// ── report ───────────────────────────────────────────────────────────────────
|