carto-md 1.0.3 → 1.0.4

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/cli/init.js +29 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carto-md",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "The context layer for AI-native development.",
5
5
  "bin": {
6
6
  "carto": "src/cli/index.js"
package/src/cli/init.js CHANGED
@@ -55,11 +55,14 @@ async function run(projectRoot) {
55
55
  'utf-8'
56
56
  );
57
57
 
58
+ // Install pre-commit hook
59
+ installGitHook(projectRoot);
60
+
58
61
  // Run first sync
59
62
  const syncConfig = resolveConfig(projectRoot, config);
60
63
  await runFullSync(syncConfig);
61
64
 
62
- console.log('[CARTO] AGENTS.md generated. Run "carto watch" to keep it live.');
65
+ console.log('[CARTO] AGENTS.md generated. Carto will sync on every git commit.');
63
66
  }
64
67
 
65
68
  /**
@@ -77,4 +80,29 @@ function resolveConfig(projectRoot, config) {
77
80
  };
78
81
  }
79
82
 
83
+ function installGitHook(projectRoot) {
84
+ const gitDir = path.join(projectRoot, '.git');
85
+ if (!fs.existsSync(gitDir)) return;
86
+
87
+ const hooksDir = path.join(gitDir, 'hooks');
88
+ if (!fs.existsSync(hooksDir)) fs.mkdirSync(hooksDir, { recursive: true });
89
+
90
+ const hookPath = path.join(hooksDir, 'pre-commit');
91
+ const hookLine = 'carto sync\n';
92
+
93
+ if (fs.existsSync(hookPath)) {
94
+ const existing = fs.readFileSync(hookPath, 'utf-8');
95
+ if (existing.includes('carto sync')) {
96
+ console.log('[CARTO] Git hook already installed.');
97
+ return;
98
+ }
99
+ fs.appendFileSync(hookPath, '\n' + hookLine);
100
+ } else {
101
+ fs.writeFileSync(hookPath, '#!/bin/sh\n' + hookLine);
102
+ }
103
+
104
+ fs.chmodSync(hookPath, '755');
105
+ console.log('[CARTO] Git pre-commit hook installed.');
106
+ }
107
+
80
108
  module.exports = { run, resolveConfig };