@rachel_rotenberg/ai-contribution-tracker 1.0.12 → 1.0.14
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/index.ts +15 -6
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -48,7 +48,7 @@ function loadState(g: string): TrackerState {
|
|
|
48
48
|
const p = getStatePath(g);
|
|
49
49
|
if (fs.existsSync(p)) { try {
|
|
50
50
|
const s = JSON.parse(fs.readFileSync(p, "utf8")) as TrackerState;
|
|
51
|
-
s.mainAgentTypes
|
|
51
|
+
s.mainAgentTypes ??= []; s.subagentTypes ??= []; s.models ??= []; s.subagentModels ??= []; s.tokensByModel ??= {};
|
|
52
52
|
if (typeof s.subagentCount !== "number") s.subagentCount = 0;
|
|
53
53
|
if (typeof s.activeSubagents !== "number") s.activeSubagents = 0;
|
|
54
54
|
if (typeof s.stateCreatedAt !== "string") s.stateCreatedAt = s.lastUpdated || new Date().toISOString();
|
|
@@ -74,7 +74,16 @@ function formatMarker(s: TrackerState): string {
|
|
|
74
74
|
if (t.reasoningTokens > 0) r += ` +${formatK(t.reasoningTokens)} reasoning`;
|
|
75
75
|
return r;
|
|
76
76
|
}).join(" | ")}`); }
|
|
77
|
-
|
|
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.
|
|
82
|
+
const models = s.models.join(", ");
|
|
83
|
+
const coAuthorName = models || s.promptCount > 0
|
|
84
|
+
? `OpenCode (${[models, s.promptCount > 0 ? `${s.promptCount}p` : ""].filter(Boolean).join(", ")})`
|
|
85
|
+
: "OpenCode";
|
|
86
|
+
return `${marker}\nCo-authored-by: ${coAuthorName} <noreply@opencode.dev>`;
|
|
78
87
|
}
|
|
79
88
|
function writeFlag(g: string, s: TrackerState) {
|
|
80
89
|
if (s.promptCount === 0 && s.mainAgentTypes.length === 0 && s.subagentTypes.length === 0 && s.subagentCount === 0 && Object.keys(s.tokensByModel).length === 0) return;
|
|
@@ -84,12 +93,13 @@ function writeFlag(g: string, s: TrackerState) {
|
|
|
84
93
|
if (ex.includes("Inline")) {
|
|
85
94
|
// Merge: preserve Inline marker, add agent data
|
|
86
95
|
const inner = marker.match(/\((.+)\)$/)?.[1];
|
|
87
|
-
|
|
96
|
+
const merged = inner ? `Impacted by AI (Inline + ${inner})` : "Impacted by AI (Inline)";
|
|
97
|
+
fs.writeFileSync(fp, merged);
|
|
88
98
|
return;
|
|
89
99
|
}
|
|
90
100
|
// Always overwrite with latest state — state only grows, never shrinks
|
|
91
101
|
}
|
|
92
|
-
fs.writeFileSync(fp, marker
|
|
102
|
+
fs.writeFileSync(fp, marker);
|
|
93
103
|
}
|
|
94
104
|
|
|
95
105
|
// ─── Plugin ─────────────────────────────────────────────────
|
|
@@ -152,8 +162,7 @@ function extractSessionId(event: any): string | null {
|
|
|
152
162
|
}
|
|
153
163
|
|
|
154
164
|
function sanitizeAgentName(name: string): string {
|
|
155
|
-
|
|
156
|
-
return name.replace(/[^\x20-\x7E]/g, "").trim();
|
|
165
|
+
return name.trim();
|
|
157
166
|
}
|
|
158
167
|
|
|
159
168
|
function getOrCreateSession(sid: string, agent?: string): SessionState {
|
package/package.json
CHANGED