@rachel_rotenberg/ai-contribution-tracker 1.0.14 → 1.0.16

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/index.ts +15 -21
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -60,7 +60,7 @@ function loadState(g: string): TrackerState {
60
60
  }
61
61
  function saveState(g: string, s: TrackerState) { s.lastUpdated = new Date().toISOString(); fs.writeFileSync(getStatePath(g), JSON.stringify(s, null, 2)); }
62
62
  function formatK(n: number) { return n >= 1000 ? `${Math.round(n / 1000)}k` : String(n); }
63
- function formatMarker(s: TrackerState): string {
63
+ function buildMarkerParts(s: TrackerState): string[] {
64
64
  const p: string[] = [];
65
65
  const ma = [...new Set(s.mainAgentTypes)]; if (ma.length) p.push(`Agent mode: ${ma.join(", ")}`);
66
66
  if (s.models.length) p.push(`Model: ${s.models.join(", ")}`);
@@ -74,32 +74,26 @@ function formatMarker(s: TrackerState): string {
74
74
  if (t.reasoningTokens > 0) r += ` +${formatK(t.reasoningTokens)} reasoning`;
75
75
  return r;
76
76
  }).join(" | ")}`); }
77
- const marker = p.length ? `Impacted by AI (${p.join(" | ")})` : "Impacted by AI";
78
- // Append Co-authored-by trailer — GitHub preserves these through squash merges,
79
- // so AI attribution survives even when the source branch is deleted after merge.
80
- // Essential metadata (model, prompts) is encoded in the name field as a fallback
81
- // when the full "Impacted by AI" body text is lost in squash merge.
77
+ return p;
78
+ }
79
+ function buildCoAuthoredBy(s: TrackerState): string {
82
80
  const models = s.models.join(", ");
83
81
  const coAuthorName = models || s.promptCount > 0
84
82
  ? `OpenCode (${[models, s.promptCount > 0 ? `${s.promptCount}p` : ""].filter(Boolean).join(", ")})`
85
83
  : "OpenCode";
86
- return `${marker}\nCo-authored-by: ${coAuthorName} <noreply@opencode.dev>`;
84
+ return `Co-authored-by: ${coAuthorName} <noreply@opencode.dev>`;
85
+ }
86
+ function formatMarker(s: TrackerState, prefix?: string): string {
87
+ const parts = buildMarkerParts(s);
88
+ if (prefix) parts.unshift(prefix);
89
+ const marker = parts.length ? `Impacted by AI (${parts.join(" | ")})` : "Impacted by AI";
90
+ return `${marker}\n${buildCoAuthoredBy(s)}`;
87
91
  }
88
92
  function writeFlag(g: string, s: TrackerState) {
89
93
  if (s.promptCount === 0 && s.mainAgentTypes.length === 0 && s.subagentTypes.length === 0 && s.subagentCount === 0 && Object.keys(s.tokensByModel).length === 0) return;
90
- const fp = getFlagPath(g), marker = formatMarker(s);
91
- if (fs.existsSync(fp)) {
92
- const ex = fs.readFileSync(fp, "utf8").trim();
93
- if (ex.includes("Inline")) {
94
- // Merge: preserve Inline marker, add agent data
95
- const inner = marker.match(/\((.+)\)$/)?.[1];
96
- const merged = inner ? `Impacted by AI (Inline + ${inner})` : "Impacted by AI (Inline)";
97
- fs.writeFileSync(fp, merged);
98
- return;
99
- }
100
- // Always overwrite with latest state — state only grows, never shrinks
101
- }
102
- fs.writeFileSync(fp, marker);
94
+ const fp = getFlagPath(g);
95
+ const isInline = fs.existsSync(fp) && fs.readFileSync(fp, "utf8").includes("Inline");
96
+ fs.writeFileSync(fp, formatMarker(s, isInline ? "Inline" : undefined));
103
97
  }
104
98
 
105
99
  // ─── Plugin ─────────────────────────────────────────────────
@@ -115,7 +109,7 @@ function appendOrCreateHook(hooksDir: string) {
115
109
  'if [ -f "$IMPACT_FLAG" ]; then',
116
110
  ' MARKER=$(cat "$IMPACT_FLAG")',
117
111
  ' if [ -z "$MARKER" ]; then MARKER="Impacted by AI"; fi',
118
- ' if ! grep -qF "$MARKER" "$1"; then',
112
+ ' if ! grep -qF "Impacted by AI" "$1"; then',
119
113
  ' echo "" >> "$1"',
120
114
  ' echo "$MARKER" >> "$1"',
121
115
  ' fi',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rachel_rotenberg/ai-contribution-tracker",
3
- "version": "1.0.14",
3
+ "version": "1.0.16",
4
4
  "description": "OpenCode plugin \u2014 tracks AI coding sessions and tags git commits with Impacted by AI markers",
5
5
  "main": "index.ts",
6
6
  "types": "index.ts",