@shahmilsaari/memory-core 1.0.2 → 1.0.3
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/dist/cli.js +44 -7
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -122,10 +122,18 @@ var reasonMap = new Map(
|
|
|
122
122
|
);
|
|
123
123
|
var HOOK_PATH = join2(".git", "hooks", "pre-commit");
|
|
124
124
|
var HOOK_MARKER = "# archmind-memory-core";
|
|
125
|
-
function
|
|
125
|
+
function buildHookBody(advisory) {
|
|
126
126
|
const suffix = advisory ? " || true" : "";
|
|
127
|
-
return
|
|
128
|
-
|
|
127
|
+
return `${HOOK_MARKER}${advisory ? " advisory" : ""}
|
|
128
|
+
if [ "\${MEMORY_CORE_SKIP_HOOK:-}" = "1" ] || [ "\${ARCHMIND_SKIP_HOOK:-}" = "1" ] || [ "\${HUSKY:-}" = "0" ] || [ "\${HUSKY_SKIP_HOOKS:-}" = "1" ]; then
|
|
129
|
+
exit 0
|
|
130
|
+
fi
|
|
131
|
+
if [ -n "\${SKIP:-}" ] && echo ",$SKIP," | grep -qiE ',(memory-core|archmind),'; then
|
|
132
|
+
exit 0
|
|
133
|
+
fi
|
|
134
|
+
if [ -n "\${SKIP_HOOKS:-}" ]; then
|
|
135
|
+
exit 0
|
|
136
|
+
fi
|
|
129
137
|
if command -v memory-core >/dev/null 2>&1; then
|
|
130
138
|
memory-core check --staged${suffix}
|
|
131
139
|
elif [ -f "./node_modules/.bin/memory-core" ]; then
|
|
@@ -137,6 +145,26 @@ else
|
|
|
137
145
|
fi
|
|
138
146
|
`;
|
|
139
147
|
}
|
|
148
|
+
function buildHookScript(advisory) {
|
|
149
|
+
return `#!/bin/sh
|
|
150
|
+
|
|
151
|
+
${buildHookBody(advisory)}`;
|
|
152
|
+
}
|
|
153
|
+
function normalizeHookPreamble(content) {
|
|
154
|
+
const lines = content.split("\n");
|
|
155
|
+
const normalized = [];
|
|
156
|
+
let shebangSeen = false;
|
|
157
|
+
for (const line of lines) {
|
|
158
|
+
if (/^\s*#!\/bin\/sh\s*$/.test(line)) {
|
|
159
|
+
if (shebangSeen) continue;
|
|
160
|
+
shebangSeen = true;
|
|
161
|
+
normalized.push("#!/bin/sh");
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
normalized.push(line);
|
|
165
|
+
}
|
|
166
|
+
return normalized.join("\n").replace(/\n{3,}/g, "\n\n").trim();
|
|
167
|
+
}
|
|
140
168
|
function recordViolations(violations, source = "hook") {
|
|
141
169
|
const statsPath = join2(process.cwd(), ".memory-core-stats.json");
|
|
142
170
|
let stats = { rules: {}, files: {} };
|
|
@@ -403,18 +431,26 @@ function installHook(advisory = true) {
|
|
|
403
431
|
process.exit(1);
|
|
404
432
|
}
|
|
405
433
|
const script = buildHookScript(advisory);
|
|
434
|
+
const body = buildHookBody(advisory).trimEnd();
|
|
406
435
|
if (existsSync2(HOOK_PATH)) {
|
|
407
436
|
const existing = readFileSync2(HOOK_PATH, "utf-8");
|
|
408
437
|
if (existing.includes(HOOK_MARKER)) {
|
|
409
438
|
const markerIndex = existing.indexOf(HOOK_MARKER);
|
|
410
|
-
const
|
|
411
|
-
|
|
439
|
+
const beforeRaw = markerIndex > 0 ? existing.slice(0, markerIndex) : "";
|
|
440
|
+
const normalizedBefore = normalizeHookPreamble(beforeRaw);
|
|
441
|
+
const preamble = normalizedBefore.length > 0 ? normalizedBefore : "#!/bin/sh";
|
|
442
|
+
const preambleWithShebang = preamble.startsWith("#!/bin/sh") ? preamble : `#!/bin/sh
|
|
443
|
+
${preamble}`;
|
|
444
|
+
writeFileSync2(HOOK_PATH, `${preambleWithShebang}
|
|
445
|
+
|
|
446
|
+
${body}
|
|
447
|
+
`);
|
|
412
448
|
chmodSync(HOOK_PATH, 493);
|
|
413
449
|
const modeLabel2 = advisory ? chalk.cyan("advisory") : chalk.yellow("strict");
|
|
414
450
|
console.log(chalk.green("\n \u2713 Pre-commit hook updated") + chalk.dim(` (${modeLabel2} mode)`));
|
|
415
451
|
return;
|
|
416
452
|
}
|
|
417
|
-
writeFileSync2(HOOK_PATH, existing.trimEnd() + "\n\n" +
|
|
453
|
+
writeFileSync2(HOOK_PATH, existing.trimEnd() + "\n\n" + body + "\n");
|
|
418
454
|
} else {
|
|
419
455
|
writeFileSync2(HOOK_PATH, script);
|
|
420
456
|
}
|
|
@@ -435,7 +471,7 @@ function uninstallHook() {
|
|
|
435
471
|
return;
|
|
436
472
|
}
|
|
437
473
|
const markerIndex = content.indexOf(HOOK_MARKER);
|
|
438
|
-
const before = markerIndex > 1 ? content.slice(0, markerIndex)
|
|
474
|
+
const before = markerIndex > 1 ? normalizeHookPreamble(content.slice(0, markerIndex)) : "";
|
|
439
475
|
if (before && before !== "#!/bin/sh") {
|
|
440
476
|
writeFileSync2(HOOK_PATH, `${before}
|
|
441
477
|
`);
|
|
@@ -575,6 +611,7 @@ ${diffToSend}` }
|
|
|
575
611
|
});
|
|
576
612
|
console.log(chalk.dim(" Fix the violations above, then commit again."));
|
|
577
613
|
console.log(chalk.dim(" To bypass (not recommended): git commit --no-verify"));
|
|
614
|
+
console.log(chalk.dim(" Env bypass: MEMORY_CORE_SKIP_HOOK=1 git commit"));
|
|
578
615
|
console.log(chalk.dim(' To save as memory: memory-core remember "<lesson>"'));
|
|
579
616
|
console.log();
|
|
580
617
|
recordViolations(violations);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shahmilsaari/memory-core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Universal AI memory core — generate AI context files from architecture profiles with RAG support",
|
|
5
5
|
"homepage": "https://memory-core.shahmilsaari.my/",
|
|
6
6
|
"type": "module",
|