memorix 0.2.2 → 0.2.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/index.js CHANGED
@@ -2427,6 +2427,258 @@ var init_engine2 = __esm({
2427
2427
  }
2428
2428
  });
2429
2429
 
2430
+ // src/hooks/installers/index.ts
2431
+ var installers_exports = {};
2432
+ __export(installers_exports, {
2433
+ detectInstalledAgents: () => detectInstalledAgents,
2434
+ getHookStatus: () => getHookStatus,
2435
+ installHooks: () => installHooks,
2436
+ uninstallHooks: () => uninstallHooks
2437
+ });
2438
+ import * as fs3 from "fs/promises";
2439
+ import * as path5 from "path";
2440
+ import * as os2 from "os";
2441
+ function generateClaudeConfig() {
2442
+ const hookEntry = {
2443
+ type: "command",
2444
+ command: `${HOOK_COMMAND} ${HOOK_ARGS.join(" ")}`,
2445
+ timeout: 10
2446
+ };
2447
+ return {
2448
+ hooks: {
2449
+ SessionStart: [hookEntry],
2450
+ PostToolUse: [hookEntry],
2451
+ UserPromptSubmit: [hookEntry],
2452
+ PreCompact: [hookEntry],
2453
+ Stop: [hookEntry]
2454
+ }
2455
+ };
2456
+ }
2457
+ function generateWindsurfConfig() {
2458
+ const hookEntry = {
2459
+ command: `${HOOK_COMMAND} ${HOOK_ARGS.join(" ")}`,
2460
+ timeout: 10
2461
+ };
2462
+ return {
2463
+ hooks: {
2464
+ post_write_code: [hookEntry],
2465
+ post_run_command: [hookEntry],
2466
+ post_mcp_tool_use: [hookEntry],
2467
+ pre_user_prompt: [hookEntry],
2468
+ post_cascade_response: [hookEntry]
2469
+ }
2470
+ };
2471
+ }
2472
+ function generateCursorConfig() {
2473
+ return {
2474
+ hooks: {
2475
+ beforeSubmitPrompt: {
2476
+ command: `${HOOK_COMMAND} ${HOOK_ARGS.join(" ")}`
2477
+ },
2478
+ afterFileEdit: {
2479
+ command: `${HOOK_COMMAND} ${HOOK_ARGS.join(" ")}`
2480
+ },
2481
+ stop: {
2482
+ command: `${HOOK_COMMAND} ${HOOK_ARGS.join(" ")}`
2483
+ }
2484
+ }
2485
+ };
2486
+ }
2487
+ function generateKiroHookFile() {
2488
+ return `---
2489
+ title: Memorix Auto-Memory
2490
+ description: Automatically record development context for cross-agent memory sharing
2491
+ event: file_saved
2492
+ filePattern: "**/*"
2493
+ ---
2494
+
2495
+ Run the memorix hook command to analyze changes and store relevant memories:
2496
+
2497
+ \`\`\`bash
2498
+ memorix hook
2499
+ \`\`\`
2500
+ `;
2501
+ }
2502
+ function getProjectConfigPath(agent, projectRoot) {
2503
+ switch (agent) {
2504
+ case "claude":
2505
+ case "copilot":
2506
+ return path5.join(projectRoot, ".github", "hooks", "memorix.json");
2507
+ case "windsurf":
2508
+ return path5.join(projectRoot, ".windsurf", "hooks.json");
2509
+ case "cursor":
2510
+ return path5.join(projectRoot, ".cursor", "hooks.json");
2511
+ case "kiro":
2512
+ return path5.join(projectRoot, ".kiro", "hooks", "memorix.hook.md");
2513
+ case "codex":
2514
+ return path5.join(projectRoot, ".codex", "hooks.json");
2515
+ default:
2516
+ return path5.join(projectRoot, ".memorix", "hooks.json");
2517
+ }
2518
+ }
2519
+ function getGlobalConfigPath(agent) {
2520
+ const home = os2.homedir();
2521
+ switch (agent) {
2522
+ case "claude":
2523
+ case "copilot":
2524
+ return path5.join(home, ".claude", "settings.json");
2525
+ case "windsurf":
2526
+ return path5.join(home, ".codeium", "windsurf", "hooks.json");
2527
+ case "cursor":
2528
+ return path5.join(home, ".cursor", "hooks.json");
2529
+ default:
2530
+ return path5.join(home, ".memorix", "hooks.json");
2531
+ }
2532
+ }
2533
+ async function detectInstalledAgents() {
2534
+ const agents = [];
2535
+ const home = os2.homedir();
2536
+ const claudeDir = path5.join(home, ".claude");
2537
+ try {
2538
+ await fs3.access(claudeDir);
2539
+ agents.push("claude");
2540
+ } catch {
2541
+ }
2542
+ const windsurfDir = path5.join(home, ".codeium", "windsurf");
2543
+ try {
2544
+ await fs3.access(windsurfDir);
2545
+ agents.push("windsurf");
2546
+ } catch {
2547
+ }
2548
+ const cursorDir = path5.join(home, ".cursor");
2549
+ try {
2550
+ await fs3.access(cursorDir);
2551
+ agents.push("cursor");
2552
+ } catch {
2553
+ }
2554
+ if (!agents.includes("claude")) {
2555
+ const vscodeDir = path5.join(home, ".vscode");
2556
+ try {
2557
+ await fs3.access(vscodeDir);
2558
+ agents.push("copilot");
2559
+ } catch {
2560
+ }
2561
+ }
2562
+ const kiroConfig = path5.join(home, ".kiro");
2563
+ try {
2564
+ await fs3.access(kiroConfig);
2565
+ agents.push("kiro");
2566
+ } catch {
2567
+ }
2568
+ return agents;
2569
+ }
2570
+ async function installHooks(agent, projectRoot, global = false) {
2571
+ const configPath = global ? getGlobalConfigPath(agent) : getProjectConfigPath(agent, projectRoot);
2572
+ let generated;
2573
+ switch (agent) {
2574
+ case "claude":
2575
+ case "copilot":
2576
+ generated = generateClaudeConfig();
2577
+ break;
2578
+ case "windsurf":
2579
+ generated = generateWindsurfConfig();
2580
+ break;
2581
+ case "cursor":
2582
+ generated = generateCursorConfig();
2583
+ break;
2584
+ case "kiro":
2585
+ generated = generateKiroHookFile();
2586
+ break;
2587
+ default:
2588
+ generated = generateClaudeConfig();
2589
+ }
2590
+ await fs3.mkdir(path5.dirname(configPath), { recursive: true });
2591
+ if (agent === "kiro") {
2592
+ await fs3.writeFile(configPath, generated, "utf-8");
2593
+ } else {
2594
+ let existing = {};
2595
+ try {
2596
+ const content = await fs3.readFile(configPath, "utf-8");
2597
+ existing = JSON.parse(content);
2598
+ } catch {
2599
+ }
2600
+ const merged = {
2601
+ ...existing,
2602
+ ...generated
2603
+ };
2604
+ await fs3.writeFile(configPath, JSON.stringify(merged, null, 2), "utf-8");
2605
+ }
2606
+ const events = [];
2607
+ switch (agent) {
2608
+ case "claude":
2609
+ case "copilot":
2610
+ events.push("session_start", "post_tool", "user_prompt", "pre_compact", "session_end");
2611
+ break;
2612
+ case "windsurf":
2613
+ events.push("post_edit", "post_command", "post_tool", "user_prompt", "post_response");
2614
+ break;
2615
+ case "cursor":
2616
+ events.push("user_prompt", "post_edit", "session_end");
2617
+ break;
2618
+ case "kiro":
2619
+ events.push("post_edit");
2620
+ break;
2621
+ }
2622
+ return {
2623
+ agent,
2624
+ configPath,
2625
+ events,
2626
+ generated: typeof generated === "string" ? { content: generated } : generated
2627
+ };
2628
+ }
2629
+ async function uninstallHooks(agent, projectRoot, global = false) {
2630
+ const configPath = global ? getGlobalConfigPath(agent) : getProjectConfigPath(agent, projectRoot);
2631
+ try {
2632
+ if (agent === "kiro") {
2633
+ await fs3.unlink(configPath);
2634
+ } else {
2635
+ const content = await fs3.readFile(configPath, "utf-8");
2636
+ const config = JSON.parse(content);
2637
+ delete config.hooks;
2638
+ if (Object.keys(config).length === 0) {
2639
+ await fs3.unlink(configPath);
2640
+ } else {
2641
+ await fs3.writeFile(configPath, JSON.stringify(config, null, 2), "utf-8");
2642
+ }
2643
+ }
2644
+ return true;
2645
+ } catch {
2646
+ return false;
2647
+ }
2648
+ }
2649
+ async function getHookStatus(projectRoot) {
2650
+ const results = [];
2651
+ const agents = ["claude", "copilot", "windsurf", "cursor", "kiro", "codex"];
2652
+ for (const agent of agents) {
2653
+ const projectPath = getProjectConfigPath(agent, projectRoot);
2654
+ const globalPath = getGlobalConfigPath(agent);
2655
+ let installed = false;
2656
+ let usedPath = projectPath;
2657
+ try {
2658
+ await fs3.access(projectPath);
2659
+ installed = true;
2660
+ } catch {
2661
+ try {
2662
+ await fs3.access(globalPath);
2663
+ installed = true;
2664
+ usedPath = globalPath;
2665
+ } catch {
2666
+ }
2667
+ }
2668
+ results.push({ agent, installed, configPath: usedPath });
2669
+ }
2670
+ return results;
2671
+ }
2672
+ var HOOK_COMMAND, HOOK_ARGS;
2673
+ var init_installers = __esm({
2674
+ "src/hooks/installers/index.ts"() {
2675
+ "use strict";
2676
+ init_esm_shims();
2677
+ HOOK_COMMAND = "memorix";
2678
+ HOOK_ARGS = ["hook"];
2679
+ }
2680
+ });
2681
+
2430
2682
  // src/memory/retention.ts
2431
2683
  var retention_exports = {};
2432
2684
  __export(retention_exports, {
@@ -2562,6 +2814,23 @@ async function createMemorixServer(cwd) {
2562
2814
  }
2563
2815
  console.error(`[memorix] Project: ${project.id} (${project.name})`);
2564
2816
  console.error(`[memorix] Data dir: ${projectDir2}`);
2817
+ try {
2818
+ const { getHookStatus: getHookStatus2, installHooks: installHooks2, detectInstalledAgents: detectInstalledAgents2 } = await Promise.resolve().then(() => (init_installers(), installers_exports));
2819
+ const workDir = cwd ?? process.cwd();
2820
+ const statuses = await getHookStatus2(workDir);
2821
+ const anyInstalled = statuses.some((s) => s.installed);
2822
+ if (!anyInstalled) {
2823
+ const agents = await detectInstalledAgents2();
2824
+ for (const agent of agents) {
2825
+ try {
2826
+ const config = await installHooks2(agent, workDir);
2827
+ console.error(`[memorix] Auto-installed hooks for ${agent} \u2192 ${config.configPath}`);
2828
+ } catch {
2829
+ }
2830
+ }
2831
+ }
2832
+ } catch {
2833
+ }
2565
2834
  const observationsFile = projectDir2 + "/observations.json";
2566
2835
  let reloadDebounce = null;
2567
2836
  try {
@@ -3803,258 +4072,6 @@ var init_hook = __esm({
3803
4072
  }
3804
4073
  });
3805
4074
 
3806
- // src/hooks/installers/index.ts
3807
- var installers_exports = {};
3808
- __export(installers_exports, {
3809
- detectInstalledAgents: () => detectInstalledAgents,
3810
- getHookStatus: () => getHookStatus,
3811
- installHooks: () => installHooks,
3812
- uninstallHooks: () => uninstallHooks
3813
- });
3814
- import * as fs3 from "fs/promises";
3815
- import * as path5 from "path";
3816
- import * as os2 from "os";
3817
- function generateClaudeConfig() {
3818
- const hookEntry = {
3819
- type: "command",
3820
- command: `${HOOK_COMMAND} ${HOOK_ARGS.join(" ")}`,
3821
- timeout: 10
3822
- };
3823
- return {
3824
- hooks: {
3825
- SessionStart: [hookEntry],
3826
- PostToolUse: [hookEntry],
3827
- UserPromptSubmit: [hookEntry],
3828
- PreCompact: [hookEntry],
3829
- Stop: [hookEntry]
3830
- }
3831
- };
3832
- }
3833
- function generateWindsurfConfig() {
3834
- const hookEntry = {
3835
- command: `${HOOK_COMMAND} ${HOOK_ARGS.join(" ")}`,
3836
- timeout: 10
3837
- };
3838
- return {
3839
- hooks: {
3840
- post_write_code: [hookEntry],
3841
- post_run_command: [hookEntry],
3842
- post_mcp_tool_use: [hookEntry],
3843
- pre_user_prompt: [hookEntry],
3844
- post_cascade_response: [hookEntry]
3845
- }
3846
- };
3847
- }
3848
- function generateCursorConfig() {
3849
- return {
3850
- hooks: {
3851
- beforeSubmitPrompt: {
3852
- command: `${HOOK_COMMAND} ${HOOK_ARGS.join(" ")}`
3853
- },
3854
- afterFileEdit: {
3855
- command: `${HOOK_COMMAND} ${HOOK_ARGS.join(" ")}`
3856
- },
3857
- stop: {
3858
- command: `${HOOK_COMMAND} ${HOOK_ARGS.join(" ")}`
3859
- }
3860
- }
3861
- };
3862
- }
3863
- function generateKiroHookFile() {
3864
- return `---
3865
- title: Memorix Auto-Memory
3866
- description: Automatically record development context for cross-agent memory sharing
3867
- event: file_saved
3868
- filePattern: "**/*"
3869
- ---
3870
-
3871
- Run the memorix hook command to analyze changes and store relevant memories:
3872
-
3873
- \`\`\`bash
3874
- memorix hook
3875
- \`\`\`
3876
- `;
3877
- }
3878
- function getProjectConfigPath(agent, projectRoot) {
3879
- switch (agent) {
3880
- case "claude":
3881
- case "copilot":
3882
- return path5.join(projectRoot, ".github", "hooks", "memorix.json");
3883
- case "windsurf":
3884
- return path5.join(projectRoot, ".windsurf", "hooks.json");
3885
- case "cursor":
3886
- return path5.join(projectRoot, ".cursor", "hooks.json");
3887
- case "kiro":
3888
- return path5.join(projectRoot, ".kiro", "hooks", "memorix.hook.md");
3889
- case "codex":
3890
- return path5.join(projectRoot, ".codex", "hooks.json");
3891
- default:
3892
- return path5.join(projectRoot, ".memorix", "hooks.json");
3893
- }
3894
- }
3895
- function getGlobalConfigPath(agent) {
3896
- const home = os2.homedir();
3897
- switch (agent) {
3898
- case "claude":
3899
- case "copilot":
3900
- return path5.join(home, ".claude", "settings.json");
3901
- case "windsurf":
3902
- return path5.join(home, ".codeium", "windsurf", "hooks.json");
3903
- case "cursor":
3904
- return path5.join(home, ".cursor", "hooks.json");
3905
- default:
3906
- return path5.join(home, ".memorix", "hooks.json");
3907
- }
3908
- }
3909
- async function detectInstalledAgents() {
3910
- const agents = [];
3911
- const home = os2.homedir();
3912
- const claudeDir = path5.join(home, ".claude");
3913
- try {
3914
- await fs3.access(claudeDir);
3915
- agents.push("claude");
3916
- } catch {
3917
- }
3918
- const windsurfDir = path5.join(home, ".codeium", "windsurf");
3919
- try {
3920
- await fs3.access(windsurfDir);
3921
- agents.push("windsurf");
3922
- } catch {
3923
- }
3924
- const cursorDir = path5.join(home, ".cursor");
3925
- try {
3926
- await fs3.access(cursorDir);
3927
- agents.push("cursor");
3928
- } catch {
3929
- }
3930
- if (!agents.includes("claude")) {
3931
- const vscodeDir = path5.join(home, ".vscode");
3932
- try {
3933
- await fs3.access(vscodeDir);
3934
- agents.push("copilot");
3935
- } catch {
3936
- }
3937
- }
3938
- const kiroConfig = path5.join(home, ".kiro");
3939
- try {
3940
- await fs3.access(kiroConfig);
3941
- agents.push("kiro");
3942
- } catch {
3943
- }
3944
- return agents;
3945
- }
3946
- async function installHooks(agent, projectRoot, global = false) {
3947
- const configPath = global ? getGlobalConfigPath(agent) : getProjectConfigPath(agent, projectRoot);
3948
- let generated;
3949
- switch (agent) {
3950
- case "claude":
3951
- case "copilot":
3952
- generated = generateClaudeConfig();
3953
- break;
3954
- case "windsurf":
3955
- generated = generateWindsurfConfig();
3956
- break;
3957
- case "cursor":
3958
- generated = generateCursorConfig();
3959
- break;
3960
- case "kiro":
3961
- generated = generateKiroHookFile();
3962
- break;
3963
- default:
3964
- generated = generateClaudeConfig();
3965
- }
3966
- await fs3.mkdir(path5.dirname(configPath), { recursive: true });
3967
- if (agent === "kiro") {
3968
- await fs3.writeFile(configPath, generated, "utf-8");
3969
- } else {
3970
- let existing = {};
3971
- try {
3972
- const content = await fs3.readFile(configPath, "utf-8");
3973
- existing = JSON.parse(content);
3974
- } catch {
3975
- }
3976
- const merged = {
3977
- ...existing,
3978
- ...generated
3979
- };
3980
- await fs3.writeFile(configPath, JSON.stringify(merged, null, 2), "utf-8");
3981
- }
3982
- const events = [];
3983
- switch (agent) {
3984
- case "claude":
3985
- case "copilot":
3986
- events.push("session_start", "post_tool", "user_prompt", "pre_compact", "session_end");
3987
- break;
3988
- case "windsurf":
3989
- events.push("post_edit", "post_command", "post_tool", "user_prompt", "post_response");
3990
- break;
3991
- case "cursor":
3992
- events.push("user_prompt", "post_edit", "session_end");
3993
- break;
3994
- case "kiro":
3995
- events.push("post_edit");
3996
- break;
3997
- }
3998
- return {
3999
- agent,
4000
- configPath,
4001
- events,
4002
- generated: typeof generated === "string" ? { content: generated } : generated
4003
- };
4004
- }
4005
- async function uninstallHooks(agent, projectRoot, global = false) {
4006
- const configPath = global ? getGlobalConfigPath(agent) : getProjectConfigPath(agent, projectRoot);
4007
- try {
4008
- if (agent === "kiro") {
4009
- await fs3.unlink(configPath);
4010
- } else {
4011
- const content = await fs3.readFile(configPath, "utf-8");
4012
- const config = JSON.parse(content);
4013
- delete config.hooks;
4014
- if (Object.keys(config).length === 0) {
4015
- await fs3.unlink(configPath);
4016
- } else {
4017
- await fs3.writeFile(configPath, JSON.stringify(config, null, 2), "utf-8");
4018
- }
4019
- }
4020
- return true;
4021
- } catch {
4022
- return false;
4023
- }
4024
- }
4025
- async function getHookStatus(projectRoot) {
4026
- const results = [];
4027
- const agents = ["claude", "copilot", "windsurf", "cursor", "kiro", "codex"];
4028
- for (const agent of agents) {
4029
- const projectPath = getProjectConfigPath(agent, projectRoot);
4030
- const globalPath = getGlobalConfigPath(agent);
4031
- let installed = false;
4032
- let usedPath = projectPath;
4033
- try {
4034
- await fs3.access(projectPath);
4035
- installed = true;
4036
- } catch {
4037
- try {
4038
- await fs3.access(globalPath);
4039
- installed = true;
4040
- usedPath = globalPath;
4041
- } catch {
4042
- }
4043
- }
4044
- results.push({ agent, installed, configPath: usedPath });
4045
- }
4046
- return results;
4047
- }
4048
- var HOOK_COMMAND, HOOK_ARGS;
4049
- var init_installers = __esm({
4050
- "src/hooks/installers/index.ts"() {
4051
- "use strict";
4052
- init_esm_shims();
4053
- HOOK_COMMAND = "memorix";
4054
- HOOK_ARGS = ["hook"];
4055
- }
4056
- });
4057
-
4058
4075
  // src/cli/commands/hooks-install.ts
4059
4076
  var hooks_install_exports = {};
4060
4077
  __export(hooks_install_exports, {