@shahmilsaari/memory-core 0.2.6 → 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 +69 -24
- 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"));
|
|
@@ -1442,17 +1451,35 @@ program.command("init").description("Initialize memory-core in the current proje
|
|
|
1442
1451
|
]
|
|
1443
1452
|
});
|
|
1444
1453
|
}
|
|
1454
|
+
const { checkbox } = await import("@inquirer/prompts");
|
|
1455
|
+
const selectedAgents = await checkbox({
|
|
1456
|
+
message: "Which AI agents do you want to generate files for?",
|
|
1457
|
+
choices: AGENT_NAMES.filter((a) => a !== "Shared").map((name) => ({ name, value: name, checked: true })),
|
|
1458
|
+
instructions: " (Space to toggle, A to select all, Enter to confirm)"
|
|
1459
|
+
});
|
|
1445
1460
|
const enableHook = await confirm({
|
|
1446
|
-
message: "Enable pre-commit hook?
|
|
1461
|
+
message: "Enable pre-commit hook?",
|
|
1447
1462
|
default: true
|
|
1448
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
|
+
}
|
|
1449
1475
|
const config2 = {
|
|
1450
1476
|
projectName,
|
|
1451
1477
|
projectType,
|
|
1452
1478
|
backendArchitecture,
|
|
1453
1479
|
frontendFramework,
|
|
1454
1480
|
language,
|
|
1455
|
-
caveman: { enabled: installCaveman, intensity: cavemanIntensity }
|
|
1481
|
+
caveman: { enabled: installCaveman, intensity: cavemanIntensity },
|
|
1482
|
+
agents: selectedAgents
|
|
1456
1483
|
};
|
|
1457
1484
|
let memories = [];
|
|
1458
1485
|
if (pullMemories) {
|
|
@@ -1480,12 +1507,24 @@ program.command("init").description("Initialize memory-core in the current proje
|
|
|
1480
1507
|
const spinner = ora("Generating AI agent context files\u2026").start();
|
|
1481
1508
|
const written = await generate(
|
|
1482
1509
|
{ projectName, projectType, backendArchitecture, frontendFramework, language, memories, caveman: config2.caveman },
|
|
1483
|
-
process.cwd()
|
|
1510
|
+
process.cwd(),
|
|
1511
|
+
[...selectedAgents, "Shared"]
|
|
1484
1512
|
);
|
|
1485
1513
|
writeProjectConfig(config2);
|
|
1486
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
|
+
}
|
|
1487
1526
|
if (enableHook) {
|
|
1488
|
-
installHook();
|
|
1527
|
+
installHook(hookAdvisory);
|
|
1489
1528
|
}
|
|
1490
1529
|
const status = await checkConnections(
|
|
1491
1530
|
process.env.DATABASE_URL ?? "",
|
|
@@ -1502,9 +1541,14 @@ program.command("sync").description("Re-pull memories and regenerate AI agent fi
|
|
|
1502
1541
|
process.exit(1);
|
|
1503
1542
|
}
|
|
1504
1543
|
const { checkbox } = await import("@inquirer/prompts");
|
|
1544
|
+
const savedAgents = new Set(config2.agents ?? AGENT_NAMES.filter((a) => a !== "Shared"));
|
|
1505
1545
|
const selectedAgents = await checkbox({
|
|
1506
1546
|
message: "Which agents do you want to sync?",
|
|
1507
|
-
choices: AGENT_NAMES.
|
|
1547
|
+
choices: AGENT_NAMES.filter((a) => a !== "Shared").map((name) => ({
|
|
1548
|
+
name,
|
|
1549
|
+
value: name,
|
|
1550
|
+
checked: savedAgents.has(name)
|
|
1551
|
+
})),
|
|
1508
1552
|
instructions: " (Space to toggle, A to select all, Enter to confirm)"
|
|
1509
1553
|
});
|
|
1510
1554
|
if (selectedAgents.length === 0) {
|
|
@@ -1531,7 +1575,7 @@ program.command("sync").description("Re-pull memories and regenerate AI agent fi
|
|
|
1531
1575
|
caveman: config2.caveman
|
|
1532
1576
|
},
|
|
1533
1577
|
process.cwd(),
|
|
1534
|
-
selectedAgents
|
|
1578
|
+
[...selectedAgents, "Shared"]
|
|
1535
1579
|
);
|
|
1536
1580
|
const updatedCount = result.written.length;
|
|
1537
1581
|
const skippedCount = result.skipped.length;
|
|
@@ -1745,8 +1789,9 @@ read:
|
|
|
1745
1789
|
await closePool();
|
|
1746
1790
|
});
|
|
1747
1791
|
var hook = program.command("hook").description("Manage the pre-commit rule enforcement hook");
|
|
1748
|
-
hook.command("install").description("Install pre-commit hook \u2014 blocks commits that violate your
|
|
1749
|
-
|
|
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);
|
|
1750
1795
|
});
|
|
1751
1796
|
hook.command("uninstall").description("Remove the pre-commit hook").action(() => {
|
|
1752
1797
|
uninstallHook();
|