@rachel_rotenberg/ai-contribution-tracker 1.0.24 → 1.0.26

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/cli.js +63 -1
  2. package/package.json +1 -1
package/cli.js CHANGED
@@ -89,6 +89,64 @@ function appendOrCreateHook(hooksDir) {
89
89
  try { fs.chmodSync(hookPath, "755"); } catch { /* Windows */ }
90
90
  }
91
91
 
92
+ const PASSTHROUGH_HOOKS = [
93
+ "pre-commit", "pre-push", "prepare-commit-msg",
94
+ "post-commit", "post-merge", "pre-rebase",
95
+ ];
96
+
97
+ function ensurePassthroughHooks(hooksDir) {
98
+ for (const hookName of PASSTHROUGH_HOOKS) {
99
+ const hookPath = path.join(hooksDir, hookName);
100
+ if (fs.existsSync(hookPath)) continue;
101
+ const content = [
102
+ "#!/bin/sh",
103
+ `LOCAL_HOOK="$(git rev-parse --git-dir)/hooks/${hookName}"`,
104
+ 'if [ -f "$LOCAL_HOOK" ] && [ -x "$LOCAL_HOOK" ]; then',
105
+ ' "$LOCAL_HOOK" "$@" || exit $?',
106
+ 'fi',
107
+ "",
108
+ ].join("\n");
109
+ fs.writeFileSync(hookPath, content);
110
+ try { fs.chmodSync(hookPath, "755"); } catch { }
111
+ ok(`Created passthrough hook: ${hookName}`);
112
+ }
113
+ }
114
+
115
+ function installPreCommitFramework(hooksDir) {
116
+ const configFile = path.join(process.cwd(), ".pre-commit-config.yaml");
117
+ if (!fs.existsSync(configFile)) return;
118
+
119
+ let preCommitBin = "";
120
+ try {
121
+ preCommitBin = execSync("which pre-commit 2>/dev/null || command -v pre-commit 2>/dev/null", {
122
+ encoding: "utf8", shell: true, stdio: ["pipe", "pipe", "pipe"],
123
+ }).trim();
124
+ } catch { }
125
+ if (!preCommitBin) return;
126
+
127
+ try {
128
+ execFileSync("git", ["config", "--global", "--unset", "core.hooksPath"], {
129
+ encoding: "utf8", stdio: ["pipe", "pipe", "pipe"],
130
+ });
131
+ } catch { }
132
+
133
+ try {
134
+ execFileSync(preCommitBin, ["install"], {
135
+ encoding: "utf8", stdio: ["pipe", "pipe", "pipe"], cwd: process.cwd(),
136
+ });
137
+ ok("Installed pre-commit framework hooks");
138
+ } catch (e) {
139
+ warn(`Could not run pre-commit install: ${e.message}`);
140
+ }
141
+
142
+ try {
143
+ const gitPath = hooksDir.replace(/\\/g, "/");
144
+ execFileSync("git", ["config", "--global", "core.hooksPath", gitPath], {
145
+ encoding: "utf8", stdio: ["pipe", "pipe", "pipe"],
146
+ });
147
+ } catch { }
148
+ }
149
+
92
150
  /** Install the global git commit-msg hook. */
93
151
  function installGitHook() {
94
152
  console.log("\nGit commit-msg hook:");
@@ -105,13 +163,15 @@ function installGitHook() {
105
163
  }
106
164
 
107
165
  if (existingPath) {
108
- // Use existing hooksPath directory
109
166
  fs.mkdirSync(existingPath, { recursive: true });
110
167
  appendOrCreateHook(existingPath);
168
+ ensurePassthroughHooks(existingPath);
169
+ installPreCommitFramework(existingPath);
111
170
  } else {
112
171
  const hooksDir = path.join(os.homedir(), ".config", "ai-contribution-tracker", "git-hooks");
113
172
  fs.mkdirSync(hooksDir, { recursive: true });
114
173
  appendOrCreateHook(hooksDir);
174
+ ensurePassthroughHooks(hooksDir);
115
175
 
116
176
  try {
117
177
  const gitPath = hooksDir.replace(/\\/g, "/");
@@ -123,6 +183,8 @@ function installGitHook() {
123
183
  } catch (e) {
124
184
  fail(`Could not set core.hooksPath: ${e.message}`);
125
185
  }
186
+
187
+ installPreCommitFramework(hooksDir);
126
188
  }
127
189
  }
128
190
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rachel_rotenberg/ai-contribution-tracker",
3
- "version": "1.0.24",
3
+ "version": "1.0.26",
4
4
  "description": "OpenCode plugin — tracks AI coding sessions and tags git commits with Impacted by AI markers",
5
5
  "main": "index.ts",
6
6
  "types": "index.ts",