@nerviq/cli 0.0.1 → 0.9.0-beta.2
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/CHANGELOG.md +181 -0
- package/LICENSE +21 -0
- package/README.md +447 -0
- package/bin/cli.js +749 -0
- package/content/case-study-template.md +91 -0
- package/content/claims-governance.md +37 -0
- package/content/claude-code/audit-repo/SKILL.md +20 -0
- package/content/claude-native-integration.md +60 -0
- package/content/devto-article.json +9 -0
- package/content/launch-posts.md +226 -0
- package/content/pilot-rollout-kit.md +30 -0
- package/content/release-checklist.md +31 -0
- package/package.json +53 -4
- package/src/activity.js +529 -0
- package/src/aider/activity.js +226 -0
- package/src/aider/config-parser.js +166 -0
- package/src/aider/context.js +158 -0
- package/src/aider/deep-review.js +316 -0
- package/src/aider/domain-packs.js +278 -0
- package/src/aider/freshness.js +168 -0
- package/src/aider/governance.js +253 -0
- package/src/aider/interactive.js +334 -0
- package/src/aider/mcp-packs.js +98 -0
- package/src/aider/patch.js +214 -0
- package/src/aider/plans.js +186 -0
- package/src/aider/premium.js +360 -0
- package/src/aider/setup.js +404 -0
- package/src/aider/techniques.js +1323 -0
- package/src/analyze.js +821 -0
- package/src/audit.js +1003 -0
- package/src/badge.js +13 -0
- package/src/benchmark.js +339 -0
- package/src/claudex-sync.json +7 -0
- package/src/codex/activity.js +324 -0
- package/src/codex/config-parser.js +183 -0
- package/src/codex/context.js +221 -0
- package/src/codex/deep-review.js +493 -0
- package/src/codex/domain-packs.js +372 -0
- package/src/codex/freshness.js +167 -0
- package/src/codex/governance.js +192 -0
- package/src/codex/interactive.js +618 -0
- package/src/codex/mcp-packs.js +660 -0
- package/src/codex/patch.js +209 -0
- package/src/codex/plans.js +251 -0
- package/src/codex/premium.js +614 -0
- package/src/codex/setup.js +603 -0
- package/src/codex/techniques.js +2649 -0
- package/src/context.js +272 -0
- package/src/copilot/activity.js +309 -0
- package/src/copilot/config-parser.js +226 -0
- package/src/copilot/context.js +197 -0
- package/src/copilot/deep-review.js +346 -0
- package/src/copilot/domain-packs.js +350 -0
- package/src/copilot/freshness.js +197 -0
- package/src/copilot/governance.js +222 -0
- package/src/copilot/interactive.js +406 -0
- package/src/copilot/mcp-packs.js +572 -0
- package/src/copilot/patch.js +238 -0
- package/src/copilot/plans.js +253 -0
- package/src/copilot/premium.js +450 -0
- package/src/copilot/setup.js +488 -0
- package/src/copilot/techniques.js +1822 -0
- package/src/cursor/activity.js +301 -0
- package/src/cursor/config-parser.js +265 -0
- package/src/cursor/context.js +236 -0
- package/src/cursor/deep-review.js +334 -0
- package/src/cursor/domain-packs.js +346 -0
- package/src/cursor/freshness.js +214 -0
- package/src/cursor/governance.js +229 -0
- package/src/cursor/interactive.js +391 -0
- package/src/cursor/mcp-packs.js +571 -0
- package/src/cursor/patch.js +243 -0
- package/src/cursor/plans.js +254 -0
- package/src/cursor/premium.js +468 -0
- package/src/cursor/setup.js +488 -0
- package/src/cursor/techniques.js +1786 -0
- package/src/deep-review.js +345 -0
- package/src/domain-packs.js +364 -0
- package/src/formatters/sarif.js +115 -0
- package/src/gemini/activity.js +402 -0
- package/src/gemini/config-parser.js +275 -0
- package/src/gemini/context.js +221 -0
- package/src/gemini/deep-review.js +559 -0
- package/src/gemini/domain-packs.js +371 -0
- package/src/gemini/freshness.js +204 -0
- package/src/gemini/governance.js +201 -0
- package/src/gemini/interactive.js +860 -0
- package/src/gemini/mcp-packs.js +658 -0
- package/src/gemini/patch.js +229 -0
- package/src/gemini/plans.js +269 -0
- package/src/gemini/premium.js +759 -0
- package/src/gemini/setup.js +692 -0
- package/src/gemini/techniques.js +2084 -0
- package/src/governance.js +523 -0
- package/src/harmony/advisor.js +383 -0
- package/src/harmony/audit.js +303 -0
- package/src/harmony/canon.js +444 -0
- package/src/harmony/cli.js +331 -0
- package/src/harmony/drift.js +401 -0
- package/src/harmony/governance.js +313 -0
- package/src/harmony/memory.js +238 -0
- package/src/harmony/sync.js +458 -0
- package/src/harmony/watch.js +336 -0
- package/src/index.js +256 -0
- package/src/insights.js +119 -0
- package/src/interactive.js +118 -0
- package/src/mcp-packs.js +597 -0
- package/src/opencode/activity.js +286 -0
- package/src/opencode/config-parser.js +109 -0
- package/src/opencode/context.js +247 -0
- package/src/opencode/deep-review.js +313 -0
- package/src/opencode/domain-packs.js +240 -0
- package/src/opencode/freshness.js +158 -0
- package/src/opencode/governance.js +159 -0
- package/src/opencode/interactive.js +392 -0
- package/src/opencode/mcp-packs.js +474 -0
- package/src/opencode/patch.js +184 -0
- package/src/opencode/plans.js +231 -0
- package/src/opencode/premium.js +413 -0
- package/src/opencode/setup.js +449 -0
- package/src/opencode/techniques.js +1713 -0
- package/src/plans.js +655 -0
- package/src/secret-patterns.js +30 -0
- package/src/setup.js +1274 -0
- package/src/synergy/adaptive.js +261 -0
- package/src/synergy/compensation.js +156 -0
- package/src/synergy/evidence.js +193 -0
- package/src/synergy/learning.js +184 -0
- package/src/synergy/patterns.js +227 -0
- package/src/synergy/ranking.js +83 -0
- package/src/synergy/report.js +163 -0
- package/src/synergy/routing.js +152 -0
- package/src/techniques.js +1354 -0
- package/src/watch.js +229 -0
- package/src/windsurf/activity.js +302 -0
- package/src/windsurf/config-parser.js +267 -0
- package/src/windsurf/context.js +249 -0
- package/src/windsurf/deep-review.js +337 -0
- package/src/windsurf/domain-packs.js +348 -0
- package/src/windsurf/freshness.js +215 -0
- package/src/windsurf/governance.js +231 -0
- package/src/windsurf/interactive.js +388 -0
- package/src/windsurf/mcp-packs.js +535 -0
- package/src/windsurf/patch.js +231 -0
- package/src/windsurf/plans.js +247 -0
- package/src/windsurf/premium.js +467 -0
- package/src/windsurf/setup.js +471 -0
- package/src/windsurf/techniques.js +1758 -0
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Aider Repeat-Usage Surfaces — 6 activity surfaces
|
|
3
|
+
*
|
|
4
|
+
* Adapts the shared activity/snapshot backend for Aider platform.
|
|
5
|
+
* Provides: history, compare, trend, watch, feedback, insights.
|
|
6
|
+
*
|
|
7
|
+
* Aider snapshots stored in .claude/claudex-setup/snapshots/ filtered by platform='aider'.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const path = require('path');
|
|
11
|
+
const {
|
|
12
|
+
getHistory: getSharedHistory,
|
|
13
|
+
compareLatest: sharedCompareLatest,
|
|
14
|
+
readSnapshotIndex,
|
|
15
|
+
writeSnapshotArtifact,
|
|
16
|
+
exportTrendReport: sharedExportTrendReport,
|
|
17
|
+
recordRecommendationOutcome,
|
|
18
|
+
readOutcomeIndex,
|
|
19
|
+
summarizeOutcomeEntries,
|
|
20
|
+
} = require('../activity');
|
|
21
|
+
const { version } = require('../../package.json');
|
|
22
|
+
|
|
23
|
+
// --- History ---
|
|
24
|
+
|
|
25
|
+
function getAiderHistory(dir, limit = 20) {
|
|
26
|
+
const entries = readSnapshotIndex(dir);
|
|
27
|
+
return entries
|
|
28
|
+
.filter(e => e.snapshotKind === 'audit' && (e.platform === 'aider' || e.summary?.platform === 'aider'))
|
|
29
|
+
.sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt))
|
|
30
|
+
.slice(0, limit);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function formatAiderHistory(dir) {
|
|
34
|
+
const history = getAiderHistory(dir, 10);
|
|
35
|
+
if (history.length === 0) {
|
|
36
|
+
return 'No Aider snapshots found. Run `npx nerviq --platform aider --snapshot` to save one.';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const lines = ['Aider Score History (most recent first):', ''];
|
|
40
|
+
for (const entry of history) {
|
|
41
|
+
const date = entry.createdAt?.split('T')[0] || 'unknown';
|
|
42
|
+
const score = entry.summary?.score ?? '?';
|
|
43
|
+
const passed = entry.summary?.passed ?? '?';
|
|
44
|
+
const total = entry.summary?.checkCount ?? '?';
|
|
45
|
+
lines.push(` ${date} ${score}/100 (${passed}/${total} passing)`);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const comparison = compareAiderLatest(dir);
|
|
49
|
+
if (comparison) {
|
|
50
|
+
lines.push('');
|
|
51
|
+
const sign = comparison.delta.score >= 0 ? '+' : '';
|
|
52
|
+
lines.push(` Trend: ${comparison.trend} (${sign}${comparison.delta.score} since previous)`);
|
|
53
|
+
if (comparison.improvements.length > 0) {
|
|
54
|
+
lines.push(` Fixed: ${comparison.improvements.join(', ')}`);
|
|
55
|
+
}
|
|
56
|
+
if (comparison.regressions.length > 0) {
|
|
57
|
+
lines.push(` New gaps: ${comparison.regressions.join(', ')}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return lines.join('\n');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// --- Compare ---
|
|
65
|
+
|
|
66
|
+
function compareAiderLatest(dir) {
|
|
67
|
+
const audits = getAiderHistory(dir, 2);
|
|
68
|
+
if (audits.length < 2) return null;
|
|
69
|
+
|
|
70
|
+
const current = audits[0];
|
|
71
|
+
const previous = audits[1];
|
|
72
|
+
|
|
73
|
+
const currentPassed = new Set(current.summary?.passedIds || []);
|
|
74
|
+
const previousPassed = new Set(previous.summary?.passedIds || []);
|
|
75
|
+
|
|
76
|
+
const improvements = [];
|
|
77
|
+
const regressions = [];
|
|
78
|
+
|
|
79
|
+
for (const id of currentPassed) {
|
|
80
|
+
if (!previousPassed.has(id)) improvements.push(id);
|
|
81
|
+
}
|
|
82
|
+
for (const id of previousPassed) {
|
|
83
|
+
if (!currentPassed.has(id)) regressions.push(id);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const scoreDelta = (current.summary?.score ?? 0) - (previous.summary?.score ?? 0);
|
|
87
|
+
|
|
88
|
+
return {
|
|
89
|
+
trend: scoreDelta > 0 ? 'improving' : scoreDelta < 0 ? 'regressing' : 'stable',
|
|
90
|
+
delta: { score: scoreDelta },
|
|
91
|
+
improvements,
|
|
92
|
+
regressions,
|
|
93
|
+
currentSnapshot: current,
|
|
94
|
+
previousSnapshot: previous,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// --- Trend Export ---
|
|
99
|
+
|
|
100
|
+
function exportAiderTrendReport(dir) {
|
|
101
|
+
const history = getAiderHistory(dir, 50);
|
|
102
|
+
if (history.length === 0) return null;
|
|
103
|
+
|
|
104
|
+
return {
|
|
105
|
+
platform: 'aider',
|
|
106
|
+
generatedAt: new Date().toISOString(),
|
|
107
|
+
nerviqVersion: version,
|
|
108
|
+
snapshotCount: history.length,
|
|
109
|
+
dataPoints: history.map(entry => ({
|
|
110
|
+
date: entry.createdAt,
|
|
111
|
+
score: entry.summary?.score ?? null,
|
|
112
|
+
passed: entry.summary?.passed ?? null,
|
|
113
|
+
checkCount: entry.summary?.checkCount ?? null,
|
|
114
|
+
})),
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// --- Feedback ---
|
|
119
|
+
|
|
120
|
+
function recordAiderFeedback(dir, recommendationId, outcome, notes = '') {
|
|
121
|
+
return recordRecommendationOutcome(dir, {
|
|
122
|
+
platform: 'aider',
|
|
123
|
+
recommendationId,
|
|
124
|
+
outcome,
|
|
125
|
+
notes,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function getAiderFeedbackSummary(dir) {
|
|
130
|
+
const entries = readOutcomeIndex(dir);
|
|
131
|
+
const aiderEntries = entries.filter(e => e.platform === 'aider');
|
|
132
|
+
return summarizeOutcomeEntries(aiderEntries);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function formatAiderFeedback(dir) {
|
|
136
|
+
const summary = getAiderFeedbackSummary(dir);
|
|
137
|
+
if (summary.total === 0) {
|
|
138
|
+
return 'No Aider recommendation feedback recorded yet.';
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const lines = [
|
|
142
|
+
'Aider Recommendation Feedback:',
|
|
143
|
+
'',
|
|
144
|
+
` Total: ${summary.total}`,
|
|
145
|
+
` Accepted: ${summary.accepted}`,
|
|
146
|
+
` Rejected: ${summary.rejected}`,
|
|
147
|
+
` Deferred: ${summary.deferred}`,
|
|
148
|
+
];
|
|
149
|
+
|
|
150
|
+
if (summary.acceptanceRate !== null) {
|
|
151
|
+
lines.push(` Acceptance rate: ${(summary.acceptanceRate * 100).toFixed(0)}%`);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return lines.join('\n');
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// --- Insights ---
|
|
158
|
+
|
|
159
|
+
function generateAiderInsights(dir) {
|
|
160
|
+
const history = getAiderHistory(dir, 10);
|
|
161
|
+
const feedback = getAiderFeedbackSummary(dir);
|
|
162
|
+
const insights = [];
|
|
163
|
+
|
|
164
|
+
if (history.length >= 3) {
|
|
165
|
+
const recent = history.slice(0, 3);
|
|
166
|
+
const avgScore = recent.reduce((sum, e) => sum + (e.summary?.score ?? 0), 0) / recent.length;
|
|
167
|
+
|
|
168
|
+
if (avgScore < 40) {
|
|
169
|
+
insights.push({
|
|
170
|
+
severity: 'high',
|
|
171
|
+
message: 'Aider setup score consistently low — prioritize .aider.conf.yml and CONVENTIONS.md.',
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const comparison = compareAiderLatest(dir);
|
|
176
|
+
if (comparison && comparison.regressions.length > 2) {
|
|
177
|
+
insights.push({
|
|
178
|
+
severity: 'medium',
|
|
179
|
+
message: `${comparison.regressions.length} checks regressed since last snapshot.`,
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (feedback.total > 5 && feedback.acceptanceRate !== null && feedback.acceptanceRate < 0.5) {
|
|
185
|
+
insights.push({
|
|
186
|
+
severity: 'medium',
|
|
187
|
+
message: 'Low recommendation acceptance rate — review convention file relevance.',
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return {
|
|
192
|
+
platform: 'aider',
|
|
193
|
+
insights,
|
|
194
|
+
summary: insights.length === 0
|
|
195
|
+
? 'No actionable Aider insights at this time.'
|
|
196
|
+
: `${insights.length} Aider insight(s) found.`,
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function formatAiderInsights(dir) {
|
|
201
|
+
const result = generateAiderInsights(dir);
|
|
202
|
+
if (result.insights.length === 0) {
|
|
203
|
+
return result.summary;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const lines = ['Aider Insights:', ''];
|
|
207
|
+
for (const insight of result.insights) {
|
|
208
|
+
const severity = insight.severity.toUpperCase();
|
|
209
|
+
lines.push(` [${severity}] ${insight.message}`);
|
|
210
|
+
}
|
|
211
|
+
lines.push('');
|
|
212
|
+
lines.push(result.summary);
|
|
213
|
+
return lines.join('\n');
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
module.exports = {
|
|
217
|
+
getAiderHistory,
|
|
218
|
+
formatAiderHistory,
|
|
219
|
+
compareAiderLatest,
|
|
220
|
+
exportAiderTrendReport,
|
|
221
|
+
recordAiderFeedback,
|
|
222
|
+
getAiderFeedbackSummary,
|
|
223
|
+
formatAiderFeedback,
|
|
224
|
+
generateAiderInsights,
|
|
225
|
+
formatAiderInsights,
|
|
226
|
+
};
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Aider Config Parser — YAML parser for .aider.conf.yml
|
|
3
|
+
*
|
|
4
|
+
* Aider uses YAML config (.aider.conf.yml) with a 4-level precedence:
|
|
5
|
+
* env vars > CLI args > .aider.conf.yml > defaults
|
|
6
|
+
*
|
|
7
|
+
* This is a lightweight YAML subset parser (no dependency on js-yaml).
|
|
8
|
+
* Handles the flat key-value pairs and simple lists that .aider.conf.yml uses.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
function stripInlineComment(line) {
|
|
12
|
+
let inSingle = false;
|
|
13
|
+
let inDouble = false;
|
|
14
|
+
|
|
15
|
+
for (let i = 0; i < line.length; i++) {
|
|
16
|
+
const char = line[i];
|
|
17
|
+
const prev = i > 0 ? line[i - 1] : '';
|
|
18
|
+
|
|
19
|
+
if (char === "'" && !inDouble && prev !== '\\') {
|
|
20
|
+
inSingle = !inSingle;
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (char === '"' && !inSingle && prev !== '\\') {
|
|
25
|
+
inDouble = !inDouble;
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (char === '#' && !inSingle && !inDouble) {
|
|
30
|
+
return line.slice(0, i).trimEnd();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return line;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function parseYamlValue(rawValue) {
|
|
38
|
+
const value = rawValue.trim();
|
|
39
|
+
|
|
40
|
+
if (value === '' || value === '~' || value === 'null') return null;
|
|
41
|
+
if (value === 'true' || value === 'True' || value === 'TRUE') return true;
|
|
42
|
+
if (value === 'false' || value === 'False' || value === 'FALSE') return false;
|
|
43
|
+
|
|
44
|
+
if (/^-?\d+$/.test(value)) return Number.parseInt(value, 10);
|
|
45
|
+
if (/^-?\d+\.\d+$/.test(value)) return Number.parseFloat(value);
|
|
46
|
+
|
|
47
|
+
// Quoted strings
|
|
48
|
+
if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
|
|
49
|
+
return value.slice(1, -1);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Inline list: [a, b, c]
|
|
53
|
+
if (value.startsWith('[') && value.endsWith(']')) {
|
|
54
|
+
const inner = value.slice(1, -1).trim();
|
|
55
|
+
if (!inner) return [];
|
|
56
|
+
return inner.split(',').map(item => parseYamlValue(item.trim()));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return value;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function getIndentLevel(line) {
|
|
63
|
+
const match = line.match(/^(\s*)/);
|
|
64
|
+
return match ? match[1].length : 0;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Parse a simple YAML config file (flat keys, simple lists, no nested objects).
|
|
69
|
+
* Covers the subset used by .aider.conf.yml and .aider.model.settings.yml.
|
|
70
|
+
*/
|
|
71
|
+
function parseYaml(content) {
|
|
72
|
+
const root = {};
|
|
73
|
+
const lines = content.split(/\r?\n/);
|
|
74
|
+
let currentKey = null;
|
|
75
|
+
let collectingList = false;
|
|
76
|
+
|
|
77
|
+
for (let i = 0; i < lines.length; i++) {
|
|
78
|
+
const rawLine = lines[i];
|
|
79
|
+
const stripped = stripInlineComment(rawLine);
|
|
80
|
+
const trimmed = stripped.trim();
|
|
81
|
+
|
|
82
|
+
if (!trimmed || trimmed.startsWith('#')) continue;
|
|
83
|
+
|
|
84
|
+
const indent = getIndentLevel(stripped);
|
|
85
|
+
|
|
86
|
+
// List item under a key
|
|
87
|
+
if (trimmed.startsWith('- ') && collectingList && currentKey) {
|
|
88
|
+
const listValue = parseYamlValue(trimmed.slice(2).trim());
|
|
89
|
+
if (!Array.isArray(root[currentKey])) {
|
|
90
|
+
root[currentKey] = [];
|
|
91
|
+
}
|
|
92
|
+
root[currentKey].push(listValue);
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Key-value pair
|
|
97
|
+
const colonIdx = trimmed.indexOf(':');
|
|
98
|
+
if (colonIdx === -1) {
|
|
99
|
+
throw new Error(`Line ${i + 1}: expected key: value — got "${trimmed}"`);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const key = trimmed.slice(0, colonIdx).trim();
|
|
103
|
+
const afterColon = trimmed.slice(colonIdx + 1).trim();
|
|
104
|
+
|
|
105
|
+
if (!afterColon) {
|
|
106
|
+
// Could be start of a list or nested block
|
|
107
|
+
currentKey = key;
|
|
108
|
+
collectingList = true;
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
collectingList = false;
|
|
113
|
+
currentKey = key;
|
|
114
|
+
root[key] = parseYamlValue(afterColon);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
return root;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function tryParseYaml(content) {
|
|
121
|
+
try {
|
|
122
|
+
return { ok: true, data: parseYaml(content), error: null };
|
|
123
|
+
} catch (error) {
|
|
124
|
+
return { ok: false, data: null, error: error.message };
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function getValueByKey(obj, key) {
|
|
129
|
+
if (!obj || typeof obj !== 'object') return undefined;
|
|
130
|
+
return obj[key];
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Parse .env file content into key-value pairs.
|
|
135
|
+
*/
|
|
136
|
+
function parseDotEnv(content) {
|
|
137
|
+
const result = {};
|
|
138
|
+
const lines = content.split(/\r?\n/);
|
|
139
|
+
|
|
140
|
+
for (const line of lines) {
|
|
141
|
+
const trimmed = line.trim();
|
|
142
|
+
if (!trimmed || trimmed.startsWith('#')) continue;
|
|
143
|
+
|
|
144
|
+
const eqIdx = trimmed.indexOf('=');
|
|
145
|
+
if (eqIdx === -1) continue;
|
|
146
|
+
|
|
147
|
+
const key = trimmed.slice(0, eqIdx).trim();
|
|
148
|
+
let value = trimmed.slice(eqIdx + 1).trim();
|
|
149
|
+
|
|
150
|
+
// Strip surrounding quotes
|
|
151
|
+
if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
|
|
152
|
+
value = value.slice(1, -1);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
result[key] = value;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return result;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
module.exports = {
|
|
162
|
+
parseYaml,
|
|
163
|
+
tryParseYaml,
|
|
164
|
+
getValueByKey,
|
|
165
|
+
parseDotEnv,
|
|
166
|
+
};
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Aider Project Context
|
|
3
|
+
*
|
|
4
|
+
* Aider is a git-first CLI tool. Key surfaces:
|
|
5
|
+
* - .aider.conf.yml (project-level YAML config)
|
|
6
|
+
* - .aider.model.settings.yml (model role configuration)
|
|
7
|
+
* - .env (API keys, model overrides)
|
|
8
|
+
* - Convention files (passed explicitly via --read or --convention)
|
|
9
|
+
* - .gitignore (must include .aider* artifacts)
|
|
10
|
+
* - Git repo (Aider's ONLY safety mechanism — commits before changes)
|
|
11
|
+
*
|
|
12
|
+
* 4-level config precedence: env vars > CLI args > .aider.conf.yml > defaults
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const fs = require('fs');
|
|
16
|
+
const path = require('path');
|
|
17
|
+
const { spawnSync } = require('child_process');
|
|
18
|
+
const { ProjectContext } = require('../context');
|
|
19
|
+
const { tryParseYaml, getValueByKey, parseDotEnv } = require('./config-parser');
|
|
20
|
+
|
|
21
|
+
let aiderVersionCache = null;
|
|
22
|
+
|
|
23
|
+
function detectAiderVersion() {
|
|
24
|
+
if (aiderVersionCache !== null) {
|
|
25
|
+
return aiderVersionCache;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
try {
|
|
29
|
+
const result = spawnSync('aider', ['--version'], { encoding: 'utf8' });
|
|
30
|
+
const output = `${result.stdout || ''} ${result.stderr || ''}`.trim();
|
|
31
|
+
const match = output.match(/aider\s+v?([^\s]+)/i);
|
|
32
|
+
aiderVersionCache = match ? match[1] : (output || null);
|
|
33
|
+
return aiderVersionCache;
|
|
34
|
+
} catch {
|
|
35
|
+
aiderVersionCache = null;
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
class AiderProjectContext extends ProjectContext {
|
|
41
|
+
configContent() {
|
|
42
|
+
return this.fileContent('.aider.conf.yml');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
modelSettingsContent() {
|
|
46
|
+
return this.fileContent('.aider.model.settings.yml');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
envContent() {
|
|
50
|
+
return this.fileContent('.env');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
parsedConfig() {
|
|
54
|
+
const content = this.configContent();
|
|
55
|
+
if (!content) {
|
|
56
|
+
return { ok: false, data: null, error: 'missing .aider.conf.yml', source: '.aider.conf.yml' };
|
|
57
|
+
}
|
|
58
|
+
const parsed = tryParseYaml(content);
|
|
59
|
+
return { ...parsed, source: '.aider.conf.yml' };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
parsedModelSettings() {
|
|
63
|
+
const content = this.modelSettingsContent();
|
|
64
|
+
if (!content) {
|
|
65
|
+
return { ok: false, data: null, error: 'missing .aider.model.settings.yml', source: '.aider.model.settings.yml' };
|
|
66
|
+
}
|
|
67
|
+
const parsed = tryParseYaml(content);
|
|
68
|
+
return { ...parsed, source: '.aider.model.settings.yml' };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
parsedEnv() {
|
|
72
|
+
const content = this.envContent();
|
|
73
|
+
if (!content) return {};
|
|
74
|
+
return parseDotEnv(content);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
configValue(key) {
|
|
78
|
+
const parsed = this.parsedConfig();
|
|
79
|
+
if (parsed.ok) {
|
|
80
|
+
const value = getValueByKey(parsed.data, key);
|
|
81
|
+
if (value !== undefined) return value;
|
|
82
|
+
}
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
conventionFiles() {
|
|
87
|
+
// Aider convention files are explicitly listed in config or CLI
|
|
88
|
+
const readFiles = this.configValue('read') || [];
|
|
89
|
+
const conventionFiles = Array.isArray(readFiles) ? readFiles : [readFiles];
|
|
90
|
+
|
|
91
|
+
// Also check for common convention file names
|
|
92
|
+
const commonNames = ['CONVENTIONS.md', 'CODING_CONVENTIONS.md', '.aider.conventions.md', 'STYLE.md'];
|
|
93
|
+
for (const name of commonNames) {
|
|
94
|
+
if (this.fileContent(name) && !conventionFiles.includes(name)) {
|
|
95
|
+
conventionFiles.push(name);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return conventionFiles.filter(Boolean);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
gitignoreContent() {
|
|
103
|
+
return this.fileContent('.gitignore');
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
hasGitRepo() {
|
|
107
|
+
try {
|
|
108
|
+
return fs.existsSync(path.join(this.dir, '.git'));
|
|
109
|
+
} catch {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
gitStatus() {
|
|
115
|
+
try {
|
|
116
|
+
const result = spawnSync('git', ['status', '--porcelain'], {
|
|
117
|
+
cwd: this.dir,
|
|
118
|
+
encoding: 'utf8',
|
|
119
|
+
});
|
|
120
|
+
return (result.stdout || '').trim();
|
|
121
|
+
} catch {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
workflowFiles() {
|
|
127
|
+
return this.dirFiles('.github/workflows')
|
|
128
|
+
.filter(file => /\.ya?ml$/i.test(file))
|
|
129
|
+
.map(file => path.join('.github', 'workflows', file).replace(/\\/g, '/'));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/** Aider model roles: main (coding), editor (applying), weak (commit messages) */
|
|
133
|
+
modelRoles() {
|
|
134
|
+
const config = this.parsedConfig();
|
|
135
|
+
const data = config.ok ? config.data : {};
|
|
136
|
+
return {
|
|
137
|
+
main: data.model || data['main-model'] || null,
|
|
138
|
+
editor: data['editor-model'] || null,
|
|
139
|
+
weak: data['weak-model'] || null,
|
|
140
|
+
architect: data.architect || false,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
static isAiderRepo(dir) {
|
|
145
|
+
try {
|
|
146
|
+
return fs.existsSync(path.join(dir, '.aider.conf.yml')) ||
|
|
147
|
+
fs.existsSync(path.join(dir, '.aider.model.settings.yml')) ||
|
|
148
|
+
fs.existsSync(path.join(dir, '.aider.tags.cache.v3'));
|
|
149
|
+
} catch {
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
module.exports = {
|
|
156
|
+
AiderProjectContext,
|
|
157
|
+
detectAiderVersion,
|
|
158
|
+
};
|