@shahmilsaari/memory-core 0.2.7 → 0.2.8
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 +52 -20
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -730,36 +730,45 @@ var reasonMap = new Map(
|
|
|
730
730
|
);
|
|
731
731
|
var HOOK_PATH = join4(".git", "hooks", "pre-commit");
|
|
732
732
|
var HOOK_MARKER = "# archmind-memory-core";
|
|
733
|
-
|
|
734
|
-
|
|
733
|
+
function buildHookScript(advisory) {
|
|
734
|
+
const suffix = advisory ? " || true" : "";
|
|
735
|
+
return `#!/bin/sh
|
|
736
|
+
${HOOK_MARKER}${advisory ? " advisory" : ""}
|
|
735
737
|
if command -v memory-core >/dev/null 2>&1; then
|
|
736
|
-
memory-core check --staged
|
|
738
|
+
memory-core check --staged${suffix}
|
|
737
739
|
elif [ -f "./node_modules/.bin/memory-core" ]; then
|
|
738
|
-
./node_modules/.bin/memory-core check --staged
|
|
740
|
+
./node_modules/.bin/memory-core check --staged${suffix}
|
|
739
741
|
elif [ -f "./dist/cli.js" ]; then
|
|
740
|
-
node ./dist/cli.js check --staged
|
|
742
|
+
node ./dist/cli.js check --staged${suffix}
|
|
741
743
|
else
|
|
742
744
|
npx --no-install memory-core check --staged 2>/dev/null || exit 0
|
|
743
745
|
fi
|
|
744
746
|
`;
|
|
745
|
-
|
|
747
|
+
}
|
|
748
|
+
function installHook(advisory = true) {
|
|
746
749
|
if (!existsSync4(".git")) {
|
|
747
750
|
console.error(chalk.red("\n Not a git repository. Run from project root.\n"));
|
|
748
751
|
process.exit(1);
|
|
749
752
|
}
|
|
753
|
+
const script = buildHookScript(advisory);
|
|
750
754
|
if (existsSync4(HOOK_PATH)) {
|
|
751
755
|
const existing = readFileSync3(HOOK_PATH, "utf-8");
|
|
752
756
|
if (existing.includes(HOOK_MARKER)) {
|
|
753
|
-
|
|
757
|
+
const markerIndex = existing.indexOf(HOOK_MARKER);
|
|
758
|
+
const before = markerIndex > 1 ? existing.slice(0, markerIndex).trimEnd() + "\n\n" : "";
|
|
759
|
+
writeFileSync2(HOOK_PATH, before + script);
|
|
760
|
+
chmodSync(HOOK_PATH, 493);
|
|
761
|
+
const modeLabel2 = advisory ? chalk.cyan("advisory") : chalk.yellow("strict");
|
|
762
|
+
console.log(chalk.green("\n \u2713 Pre-commit hook updated") + chalk.dim(` (${modeLabel2} mode)`));
|
|
754
763
|
return;
|
|
755
764
|
}
|
|
756
|
-
writeFileSync2(HOOK_PATH, existing.trimEnd() + "\n\n" +
|
|
765
|
+
writeFileSync2(HOOK_PATH, existing.trimEnd() + "\n\n" + script);
|
|
757
766
|
} else {
|
|
758
|
-
writeFileSync2(HOOK_PATH,
|
|
767
|
+
writeFileSync2(HOOK_PATH, script);
|
|
759
768
|
}
|
|
760
769
|
chmodSync(HOOK_PATH, 493);
|
|
761
|
-
|
|
762
|
-
console.log(chalk.
|
|
770
|
+
const modeLabel = advisory ? "advisory (logs violations, never blocks)" : "strict (blocks commits on violations)";
|
|
771
|
+
console.log(chalk.green("\n \u2713 Pre-commit hook installed") + chalk.dim(` \u2014 ${modeLabel}`));
|
|
763
772
|
console.log(chalk.gray(` Chat model: ${process.env.OLLAMA_CHAT_MODEL ?? "llama3.2"}`));
|
|
764
773
|
console.log(chalk.gray(" To uninstall: memory-core hook uninstall\n"));
|
|
765
774
|
}
|
|
@@ -1373,14 +1382,14 @@ program.command("init").description("Initialize memory-core in the current proje
|
|
|
1373
1382
|
process.env.OLLAMA_URL = ollamaUrl;
|
|
1374
1383
|
process.env.OLLAMA_MODEL = "nomic-embed-text";
|
|
1375
1384
|
process.env.OLLAMA_CHAT_MODEL = chatModel;
|
|
1376
|
-
const
|
|
1377
|
-
if (existsSync6(
|
|
1378
|
-
const gi = readFileSync5(
|
|
1385
|
+
const gitignorePath2 = join6(process.cwd(), ".gitignore");
|
|
1386
|
+
if (existsSync6(gitignorePath2)) {
|
|
1387
|
+
const gi = readFileSync5(gitignorePath2, "utf-8");
|
|
1379
1388
|
if (!gi.includes(".memory-core.env")) {
|
|
1380
|
-
appendFileSync(
|
|
1389
|
+
appendFileSync(gitignorePath2, "\n.memory-core.env\n");
|
|
1381
1390
|
}
|
|
1382
1391
|
} else {
|
|
1383
|
-
writeFileSync3(
|
|
1392
|
+
writeFileSync3(gitignorePath2, ".memory-core.env\n");
|
|
1384
1393
|
}
|
|
1385
1394
|
console.log(chalk3.green("\n \u2713 .memory-core.env created"));
|
|
1386
1395
|
console.log(chalk3.gray(" Added to .gitignore \u2014 your DB credentials stay local.\n"));
|
|
@@ -1449,9 +1458,20 @@ program.command("init").description("Initialize memory-core in the current proje
|
|
|
1449
1458
|
instructions: " (Space to toggle, A to select all, Enter to confirm)"
|
|
1450
1459
|
});
|
|
1451
1460
|
const enableHook = await confirm({
|
|
1452
|
-
message: "Enable pre-commit hook?
|
|
1461
|
+
message: "Enable pre-commit hook?",
|
|
1453
1462
|
default: true
|
|
1454
1463
|
});
|
|
1464
|
+
let hookAdvisory = true;
|
|
1465
|
+
if (enableHook) {
|
|
1466
|
+
const { select: selectMode } = await import("@inquirer/prompts");
|
|
1467
|
+
hookAdvisory = await selectMode({
|
|
1468
|
+
message: "Hook mode?",
|
|
1469
|
+
choices: [
|
|
1470
|
+
{ value: true, name: "Advisory \u2014 logs violations, never blocks commits (recommended)" },
|
|
1471
|
+
{ value: false, name: "Strict \u2014 blocks commits that violate your rules" }
|
|
1472
|
+
]
|
|
1473
|
+
});
|
|
1474
|
+
}
|
|
1455
1475
|
const config2 = {
|
|
1456
1476
|
projectName,
|
|
1457
1477
|
projectType,
|
|
@@ -1492,8 +1512,19 @@ program.command("init").description("Initialize memory-core in the current proje
|
|
|
1492
1512
|
);
|
|
1493
1513
|
writeProjectConfig(config2);
|
|
1494
1514
|
spinner.succeed(`Generated ${written.written.length} files`);
|
|
1515
|
+
const gitignorePath = join6(process.cwd(), ".gitignore");
|
|
1516
|
+
const generatedPaths = written.written;
|
|
1517
|
+
if (generatedPaths.length > 0) {
|
|
1518
|
+
const existing = existsSync6(gitignorePath) ? readFileSync5(gitignorePath, "utf-8") : "";
|
|
1519
|
+
const toAdd = generatedPaths.filter((p) => !existing.includes(p));
|
|
1520
|
+
if (toAdd.length > 0) {
|
|
1521
|
+
const block = "\n# memory-core generated files\n" + toAdd.join("\n") + "\n";
|
|
1522
|
+
appendFileSync(gitignorePath, block);
|
|
1523
|
+
console.log(chalk3.green(` \u2713 Added ${toAdd.length} generated files to .gitignore`));
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1495
1526
|
if (enableHook) {
|
|
1496
|
-
installHook();
|
|
1527
|
+
installHook(hookAdvisory);
|
|
1497
1528
|
}
|
|
1498
1529
|
const status = await checkConnections(
|
|
1499
1530
|
process.env.DATABASE_URL ?? "",
|
|
@@ -1758,8 +1789,9 @@ read:
|
|
|
1758
1789
|
await closePool();
|
|
1759
1790
|
});
|
|
1760
1791
|
var hook = program.command("hook").description("Manage the pre-commit rule enforcement hook");
|
|
1761
|
-
hook.command("install").description("Install pre-commit hook \u2014 blocks commits that violate your
|
|
1762
|
-
|
|
1792
|
+
hook.command("install").description("Install pre-commit hook (advisory mode by default \u2014 logs violations, never blocks)").option("--advisory", "Log violations but never block commits (default)").option("--strict", "Block commits that violate your rules").action((opts) => {
|
|
1793
|
+
const advisory = opts.strict ? false : true;
|
|
1794
|
+
installHook(advisory);
|
|
1763
1795
|
});
|
|
1764
1796
|
hook.command("uninstall").description("Remove the pre-commit hook").action(() => {
|
|
1765
1797
|
uninstallHook();
|