@rachel_rotenberg/ai-contribution-tracker 1.0.27 → 1.0.29

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 +18 -6
  2. package/package.json +1 -1
package/cli.js CHANGED
@@ -22,7 +22,7 @@ const PLUGIN_NAME = "@rachel_rotenberg/ai-contribution-tracker";
22
22
  const HOOK_BEGIN = "# BEGIN ai-contribution-tracker-cli";
23
23
  const HOOK_END = "# END ai-contribution-tracker-cli";
24
24
  const HOOK_DELEGATION = [
25
- 'LOCAL_HOOK="$(git rev-parse --git-dir)/hooks/commit-msg"',
25
+ 'LOCAL_HOOK="$(git rev-parse --path-format=absolute --git-common-dir)/hooks/commit-msg"',
26
26
  'if [ -f "$LOCAL_HOOK" ] && [ -x "$LOCAL_HOOK" ]; then',
27
27
  ' "$LOCAL_HOOK" "$@" || exit $?',
28
28
  'fi',
@@ -61,12 +61,13 @@ function appendOrCreateHook(hooksDir) {
61
61
  const hookPath = path.join(hooksDir, "commit-msg");
62
62
 
63
63
  if (fs.existsSync(hookPath)) {
64
- let existing = fs.readFileSync(hookPath, "utf8");
64
+ let existing = fs.readFileSync(hookPath, "utf8").replace(/\r\n/g, "\n");
65
65
  if (existing.includes(HOOK_BEGIN)) {
66
66
  if (!existing.includes(HOOK_DELEGATION.split("\n")[0])) {
67
- const firstLine = existing.split("\n")[0];
68
- existing = firstLine + "\n" + HOOK_DELEGATION + "\n" + existing.split("\n").slice(1).join("\n");
69
- fs.writeFileSync(hookPath, existing.replace(/\r\n/g, "\n"));
67
+ const lines = existing.split("\n");
68
+ const firstLine = lines[0].replace(/\r$/, "");
69
+ existing = firstLine + "\n" + HOOK_DELEGATION + "\n" + lines.slice(1).map(l => l.replace(/\r$/, "")).join("\n");
70
+ fs.writeFileSync(hookPath, existing);
70
71
  ok(`Added local hook delegation to: ${hookPath}`);
71
72
  } else {
72
73
  skip(`commit-msg hook already up to date: ${hookPath}`);
@@ -100,7 +101,7 @@ function ensurePassthroughHooks(hooksDir) {
100
101
  if (fs.existsSync(hookPath)) continue;
101
102
  const content = [
102
103
  "#!/bin/sh",
103
- `LOCAL_HOOK="$(git rev-parse --git-dir)/hooks/${hookName}"`,
104
+ `LOCAL_HOOK="$(git rev-parse --path-format=absolute --git-common-dir)/hooks/${hookName}"`,
104
105
  'if [ -f "$LOCAL_HOOK" ] && [ -x "$LOCAL_HOOK" ]; then',
105
106
  ' "$LOCAL_HOOK" "$@" || exit $?',
106
107
  'fi',
@@ -288,6 +289,17 @@ function removeGitHook() {
288
289
  if (!skipping) filtered.push(line);
289
290
  }
290
291
 
292
+ for (const hookName of PASSTHROUGH_HOOKS) {
293
+ const p = path.join(hooksPath, hookName);
294
+ if (fs.existsSync(p)) {
295
+ const body = fs.readFileSync(p, "utf8");
296
+ if (body.includes(`git rev-parse --path-format=absolute --git-common-dir`)) {
297
+ fs.unlinkSync(p);
298
+ ok(`Removed passthrough hook: ${hookName}`);
299
+ }
300
+ }
301
+ }
302
+
291
303
  const remaining = filtered.join("\n").trim();
292
304
  if (remaining === "#!/bin/sh" || remaining === "") {
293
305
  fs.unlinkSync(hookFile);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rachel_rotenberg/ai-contribution-tracker",
3
- "version": "1.0.27",
3
+ "version": "1.0.29",
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",