@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,402 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gemini Repeat-Usage Surfaces
|
|
3
|
+
*
|
|
4
|
+
* Adapts the shared activity/snapshot backend for Gemini CLI platform.
|
|
5
|
+
* Provides: history, compare, trend, feedback, insights.
|
|
6
|
+
*
|
|
7
|
+
* Gemini snapshots are stored alongside Claude snapshots in
|
|
8
|
+
* .claude/claudex-setup/snapshots/ but filtered by platform='gemini'.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const path = require('path');
|
|
12
|
+
const {
|
|
13
|
+
readSnapshotIndex,
|
|
14
|
+
recordRecommendationOutcome,
|
|
15
|
+
readOutcomeIndex,
|
|
16
|
+
summarizeOutcomeEntries,
|
|
17
|
+
} = require('../activity');
|
|
18
|
+
const { version } = require('../../package.json');
|
|
19
|
+
|
|
20
|
+
// --- History ---
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Get Gemini audit history from snapshots.
|
|
24
|
+
* Filters to platform='gemini' snapshots only.
|
|
25
|
+
*/
|
|
26
|
+
function getGeminiHistory(dir, limit = 20) {
|
|
27
|
+
const entries = readSnapshotIndex(dir);
|
|
28
|
+
return entries
|
|
29
|
+
.filter(e => e.snapshotKind === 'audit' && (e.platform === 'gemini' || e.summary?.platform === 'gemini'))
|
|
30
|
+
.sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt))
|
|
31
|
+
.slice(0, limit);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function formatGeminiHistory(dir) {
|
|
35
|
+
const history = getGeminiHistory(dir, 10);
|
|
36
|
+
if (history.length === 0) {
|
|
37
|
+
return 'No Gemini snapshots found. Run `npx nerviq --platform gemini --snapshot` to save one.';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const lines = ['Gemini Score History (most recent first):', ''];
|
|
41
|
+
for (const entry of history) {
|
|
42
|
+
const date = entry.createdAt?.split('T')[0] || 'unknown';
|
|
43
|
+
const score = entry.summary?.score ?? '?';
|
|
44
|
+
const passed = entry.summary?.passed ?? '?';
|
|
45
|
+
const total = entry.summary?.checkCount ?? '?';
|
|
46
|
+
lines.push(` ${date} ${score}/100 (${passed}/${total} passing)`);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const comparison = compareGeminiLatest(dir);
|
|
50
|
+
if (comparison) {
|
|
51
|
+
lines.push('');
|
|
52
|
+
const sign = comparison.delta.score >= 0 ? '+' : '';
|
|
53
|
+
lines.push(` Trend: ${comparison.trend} (${sign}${comparison.delta.score} since previous)`);
|
|
54
|
+
if (comparison.improvements.length > 0) {
|
|
55
|
+
lines.push(` Fixed: ${comparison.improvements.join(', ')}`);
|
|
56
|
+
}
|
|
57
|
+
if (comparison.regressions.length > 0) {
|
|
58
|
+
lines.push(` New gaps: ${comparison.regressions.join(', ')}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return lines.join('\n');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// --- Compare ---
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Compare the two most recent Gemini audit snapshots.
|
|
69
|
+
*/
|
|
70
|
+
function compareGeminiLatest(dir) {
|
|
71
|
+
const audits = getGeminiHistory(dir, 2);
|
|
72
|
+
if (audits.length < 2) return null;
|
|
73
|
+
|
|
74
|
+
const current = audits[0];
|
|
75
|
+
const previous = audits[1];
|
|
76
|
+
|
|
77
|
+
const delta = {
|
|
78
|
+
score: (current.summary?.score || 0) - (previous.summary?.score || 0),
|
|
79
|
+
organic: (current.summary?.organicScore || 0) - (previous.summary?.organicScore || 0),
|
|
80
|
+
passed: (current.summary?.passed || 0) - (previous.summary?.passed || 0),
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const regressions = [];
|
|
84
|
+
const improvements = [];
|
|
85
|
+
|
|
86
|
+
const prevKeys = new Set(previous.summary?.topActionKeys || []);
|
|
87
|
+
const currKeys = new Set(current.summary?.topActionKeys || []);
|
|
88
|
+
|
|
89
|
+
for (const key of currKeys) {
|
|
90
|
+
if (!prevKeys.has(key)) regressions.push(key);
|
|
91
|
+
}
|
|
92
|
+
for (const key of prevKeys) {
|
|
93
|
+
if (!currKeys.has(key)) improvements.push(key);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return {
|
|
97
|
+
platform: 'gemini',
|
|
98
|
+
current: { date: current.createdAt, score: current.summary?.score, passed: current.summary?.passed },
|
|
99
|
+
previous: { date: previous.createdAt, score: previous.summary?.score, passed: previous.summary?.passed },
|
|
100
|
+
delta,
|
|
101
|
+
regressions,
|
|
102
|
+
improvements,
|
|
103
|
+
trend: delta.score > 0 ? 'improving' : delta.score < 0 ? 'regressing' : 'stable',
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// --- Trend ---
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Export Gemini trend report as markdown.
|
|
111
|
+
*/
|
|
112
|
+
function exportGeminiTrendReport(dir) {
|
|
113
|
+
const history = getGeminiHistory(dir, 50);
|
|
114
|
+
if (history.length === 0) return null;
|
|
115
|
+
|
|
116
|
+
const comparison = compareGeminiLatest(dir);
|
|
117
|
+
const lines = [
|
|
118
|
+
'# Gemini CLI Setup Trend Report',
|
|
119
|
+
'',
|
|
120
|
+
`**Project:** ${path.basename(dir)}`,
|
|
121
|
+
`**Platform:** Gemini CLI`,
|
|
122
|
+
`**Generated:** ${new Date().toISOString().split('T')[0]}`,
|
|
123
|
+
`**Snapshots:** ${history.length}`,
|
|
124
|
+
'',
|
|
125
|
+
'## Score History',
|
|
126
|
+
'',
|
|
127
|
+
'| Date | Score | Passed | Checks |',
|
|
128
|
+
'|------|-------|--------|--------|',
|
|
129
|
+
];
|
|
130
|
+
|
|
131
|
+
for (const entry of history) {
|
|
132
|
+
const date = entry.createdAt?.split('T')[0] || '?';
|
|
133
|
+
lines.push(`| ${date} | ${entry.summary?.score ?? '?'}/100 | ${entry.summary?.passed ?? '?'} | ${entry.summary?.checkCount ?? '?'} |`);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (comparison) {
|
|
137
|
+
lines.push('');
|
|
138
|
+
lines.push('## Latest Comparison');
|
|
139
|
+
lines.push('');
|
|
140
|
+
lines.push(`- **Previous:** ${comparison.previous.score}/100 (${comparison.previous.date?.split('T')[0]})`);
|
|
141
|
+
lines.push(`- **Current:** ${comparison.current.score}/100 (${comparison.current.date?.split('T')[0]})`);
|
|
142
|
+
lines.push(`- **Delta:** ${comparison.delta.score >= 0 ? '+' : ''}${comparison.delta.score} points`);
|
|
143
|
+
lines.push(`- **Trend:** ${comparison.trend}`);
|
|
144
|
+
if (comparison.improvements.length > 0) lines.push(`- **Fixed:** ${comparison.improvements.join(', ')}`);
|
|
145
|
+
if (comparison.regressions.length > 0) lines.push(`- **New gaps:** ${comparison.regressions.join(', ')}`);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// ASCII trend chart
|
|
149
|
+
if (history.length >= 3) {
|
|
150
|
+
lines.push('');
|
|
151
|
+
lines.push('## Trend Chart');
|
|
152
|
+
lines.push('');
|
|
153
|
+
lines.push('```');
|
|
154
|
+
const scores = history.slice().reverse().map(e => e.summary?.score ?? 0);
|
|
155
|
+
const max = Math.max(...scores, 100);
|
|
156
|
+
const chartHeight = 10;
|
|
157
|
+
for (let row = chartHeight; row >= 0; row--) {
|
|
158
|
+
const threshold = (row / chartHeight) * max;
|
|
159
|
+
const rowLabel = String(Math.round(threshold)).padStart(3);
|
|
160
|
+
const bar = scores.map(s => s >= threshold ? '#' : ' ').join('');
|
|
161
|
+
lines.push(`${rowLabel} |${bar}`);
|
|
162
|
+
}
|
|
163
|
+
lines.push(` +${'─'.repeat(scores.length)}`);
|
|
164
|
+
lines.push('```');
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
lines.push('');
|
|
168
|
+
lines.push(`---`);
|
|
169
|
+
lines.push(`*Generated by nerviq v${version} for Gemini CLI*`);
|
|
170
|
+
return lines.join('\n');
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// --- Feedback ---
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Record feedback on a Gemini recommendation.
|
|
177
|
+
*/
|
|
178
|
+
function recordGeminiFeedback(dir, payload) {
|
|
179
|
+
return recordRecommendationOutcome(dir, {
|
|
180
|
+
...payload,
|
|
181
|
+
source: payload.source || 'gemini-cli',
|
|
182
|
+
platform: 'gemini',
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Get Gemini feedback summary.
|
|
188
|
+
*/
|
|
189
|
+
function getGeminiFeedbackSummary(dir) {
|
|
190
|
+
const entries = readOutcomeIndex(dir)
|
|
191
|
+
.filter(e => e.source === 'gemini-cli' || e.platform === 'gemini');
|
|
192
|
+
return summarizeOutcomeEntries(entries);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function formatGeminiFeedback(dir) {
|
|
196
|
+
const summary = getGeminiFeedbackSummary(dir);
|
|
197
|
+
if (!summary || Object.keys(summary).length === 0) {
|
|
198
|
+
return 'No Gemini feedback recorded yet. Use `npx nerviq --platform gemini feedback` to rate recommendations.';
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const lines = ['Gemini Recommendation Feedback:', ''];
|
|
202
|
+
const entries = Array.isArray(summary) ? summary : Object.values(summary);
|
|
203
|
+
for (const entry of entries) {
|
|
204
|
+
const key = entry.key || 'unknown';
|
|
205
|
+
const accepted = entry.accepted || 0;
|
|
206
|
+
const rejected = entry.rejected || 0;
|
|
207
|
+
const total = entry.total || 0;
|
|
208
|
+
lines.push(` ${key}: ${accepted} accepted, ${rejected} rejected (${total} total)`);
|
|
209
|
+
}
|
|
210
|
+
return lines.join('\n');
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// --- Insights ---
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Generate Gemini-specific insights from audit history and feedback.
|
|
217
|
+
* Includes Gemini-unique patterns: sandbox-drift, policy-complexity,
|
|
218
|
+
* caveat-persistence, trust-class-stagnation.
|
|
219
|
+
*/
|
|
220
|
+
function generateGeminiInsights(dir) {
|
|
221
|
+
const history = getGeminiHistory(dir, 50);
|
|
222
|
+
const feedback = getGeminiFeedbackSummary(dir);
|
|
223
|
+
const insights = [];
|
|
224
|
+
|
|
225
|
+
// Pattern 1: Persistent failures
|
|
226
|
+
if (history.length >= 3) {
|
|
227
|
+
const recentFailKeys = new Map();
|
|
228
|
+
for (const entry of history.slice(0, 5)) {
|
|
229
|
+
for (const key of (entry.summary?.topActionKeys || [])) {
|
|
230
|
+
recentFailKeys.set(key, (recentFailKeys.get(key) || 0) + 1);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
for (const [key, count] of recentFailKeys) {
|
|
234
|
+
if (count >= 3) {
|
|
235
|
+
insights.push({
|
|
236
|
+
type: 'persistent-failure',
|
|
237
|
+
severity: 'high',
|
|
238
|
+
key,
|
|
239
|
+
message: `Check ${key} has failed in ${count} of the last ${Math.min(history.length, 5)} audits. Consider addressing it or marking it as intentionally skipped.`,
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// Pattern 2: Score regression
|
|
246
|
+
if (history.length >= 2) {
|
|
247
|
+
const scores = history.map(e => e.summary?.score ?? 0);
|
|
248
|
+
if (scores[0] < scores[1]) {
|
|
249
|
+
insights.push({
|
|
250
|
+
type: 'regression-pattern',
|
|
251
|
+
severity: 'medium',
|
|
252
|
+
message: `Score dropped from ${scores[1]} to ${scores[0]} in the most recent audit. Review recent changes.`,
|
|
253
|
+
delta: scores[0] - scores[1],
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// Pattern 3: Improvement velocity stall
|
|
259
|
+
if (history.length >= 5) {
|
|
260
|
+
const recentScores = history.slice(0, 5).map(e => e.summary?.score ?? 0);
|
|
261
|
+
const range = Math.max(...recentScores) - Math.min(...recentScores);
|
|
262
|
+
if (range <= 2) {
|
|
263
|
+
insights.push({
|
|
264
|
+
type: 'velocity-stall',
|
|
265
|
+
severity: 'low',
|
|
266
|
+
message: `Score has been flat (range: ${range} points) over the last 5 audits. Consider addressing lower-priority checks.`,
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// Pattern 4: Feedback signals
|
|
272
|
+
const feedbackEntries = Array.isArray(feedback) ? feedback : Object.values(feedback || {});
|
|
273
|
+
for (const entry of feedbackEntries) {
|
|
274
|
+
if (entry.rejected > entry.accepted && entry.total >= 2) {
|
|
275
|
+
insights.push({
|
|
276
|
+
type: 'feedback-signal',
|
|
277
|
+
severity: 'medium',
|
|
278
|
+
key: entry.key,
|
|
279
|
+
message: `Recommendation ${entry.key} has been rejected more than accepted (${entry.rejected}/${entry.total}). Consider adjusting or removing this recommendation.`,
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// Gemini-specific Pattern 5: Sandbox drift
|
|
285
|
+
if (history.length >= 3) {
|
|
286
|
+
const sandboxKeys = [];
|
|
287
|
+
for (const entry of history.slice(0, 5)) {
|
|
288
|
+
for (const key of (entry.summary?.topActionKeys || [])) {
|
|
289
|
+
if (key.includes('sandbox') || key.includes('isolation')) {
|
|
290
|
+
sandboxKeys.push(key);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
if (sandboxKeys.length >= 2) {
|
|
295
|
+
insights.push({
|
|
296
|
+
type: 'sandbox-drift',
|
|
297
|
+
severity: 'high',
|
|
298
|
+
message: `Sandbox-related checks have appeared in ${sandboxKeys.length} recent audits. Gemini sandbox configuration may be drifting from recommended posture.`,
|
|
299
|
+
keys: [...new Set(sandboxKeys)],
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// Gemini-specific Pattern 6: Policy complexity
|
|
305
|
+
if (history.length >= 2) {
|
|
306
|
+
const latest = history[0];
|
|
307
|
+
const policyKeys = (latest.summary?.topActionKeys || []).filter(
|
|
308
|
+
k => k.includes('policy') || k.includes('governance') || k.includes('rule')
|
|
309
|
+
);
|
|
310
|
+
if (policyKeys.length >= 3) {
|
|
311
|
+
insights.push({
|
|
312
|
+
type: 'policy-complexity',
|
|
313
|
+
severity: 'medium',
|
|
314
|
+
message: `${policyKeys.length} policy/governance checks are failing simultaneously. Gemini policy configuration may be overly complex or misconfigured.`,
|
|
315
|
+
keys: policyKeys,
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// Gemini-specific Pattern 7: Caveat persistence
|
|
321
|
+
if (history.length >= 3) {
|
|
322
|
+
const caveatKeys = new Map();
|
|
323
|
+
for (const entry of history.slice(0, 5)) {
|
|
324
|
+
for (const key of (entry.summary?.topActionKeys || [])) {
|
|
325
|
+
if (key.includes('caveat') || key.includes('warning') || key.includes('limitation')) {
|
|
326
|
+
caveatKeys.set(key, (caveatKeys.get(key) || 0) + 1);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
for (const [key, count] of caveatKeys) {
|
|
331
|
+
if (count >= 3) {
|
|
332
|
+
insights.push({
|
|
333
|
+
type: 'caveat-persistence',
|
|
334
|
+
severity: 'medium',
|
|
335
|
+
key,
|
|
336
|
+
message: `Caveat/limitation ${key} has persisted across ${count} audits. This may indicate a Gemini CLI limitation that should be documented or worked around.`,
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// Gemini-specific Pattern 8: Trust class stagnation
|
|
343
|
+
if (history.length >= 5) {
|
|
344
|
+
const trustKeys = new Map();
|
|
345
|
+
for (const entry of history.slice(0, 5)) {
|
|
346
|
+
for (const key of (entry.summary?.topActionKeys || [])) {
|
|
347
|
+
if (key.includes('trust') || key.includes('approval') || key.includes('permission')) {
|
|
348
|
+
trustKeys.set(key, (trustKeys.get(key) || 0) + 1);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
for (const [key, count] of trustKeys) {
|
|
353
|
+
if (count >= 4) {
|
|
354
|
+
insights.push({
|
|
355
|
+
type: 'trust-class-stagnation',
|
|
356
|
+
severity: 'medium',
|
|
357
|
+
key,
|
|
358
|
+
message: `Trust/permission check ${key} has been failing in ${count} of the last 5 audits. Gemini trust classification may need elevation or explicit override.`,
|
|
359
|
+
});
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
return {
|
|
365
|
+
platform: 'gemini',
|
|
366
|
+
generatedAt: new Date().toISOString(),
|
|
367
|
+
snapshotCount: history.length,
|
|
368
|
+
feedbackCount: feedbackEntries.length,
|
|
369
|
+
insights,
|
|
370
|
+
summary: insights.length === 0
|
|
371
|
+
? 'No actionable insights detected. Keep running audits to build pattern data.'
|
|
372
|
+
: `${insights.length} insight(s) detected across ${history.length} snapshots.`,
|
|
373
|
+
};
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
function formatGeminiInsights(dir) {
|
|
377
|
+
const result = generateGeminiInsights(dir);
|
|
378
|
+
if (result.insights.length === 0) {
|
|
379
|
+
return result.summary;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
const lines = ['Gemini Insights:', ''];
|
|
383
|
+
for (const insight of result.insights) {
|
|
384
|
+
const severity = insight.severity.toUpperCase();
|
|
385
|
+
lines.push(` [${severity}] ${insight.message}`);
|
|
386
|
+
}
|
|
387
|
+
lines.push('');
|
|
388
|
+
lines.push(result.summary);
|
|
389
|
+
return lines.join('\n');
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
module.exports = {
|
|
393
|
+
getGeminiHistory,
|
|
394
|
+
formatGeminiHistory,
|
|
395
|
+
compareGeminiLatest,
|
|
396
|
+
exportGeminiTrendReport,
|
|
397
|
+
recordGeminiFeedback,
|
|
398
|
+
getGeminiFeedbackSummary,
|
|
399
|
+
formatGeminiFeedback,
|
|
400
|
+
generateGeminiInsights,
|
|
401
|
+
formatGeminiInsights,
|
|
402
|
+
};
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gemini CLI config parser.
|
|
3
|
+
*
|
|
4
|
+
* Gemini uses JSON for settings.json and TOML for commands and policy files.
|
|
5
|
+
* This module handles both formats with unified value extraction.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// ─── TOML parsing (reused from codex pattern) ───────────────────────────────
|
|
9
|
+
|
|
10
|
+
const COMMENT_MARKER = '#';
|
|
11
|
+
|
|
12
|
+
function stripInlineComment(line) {
|
|
13
|
+
let inSingle = false;
|
|
14
|
+
let inDouble = false;
|
|
15
|
+
|
|
16
|
+
for (let i = 0; i < line.length; i++) {
|
|
17
|
+
const char = line[i];
|
|
18
|
+
const prev = i > 0 ? line[i - 1] : '';
|
|
19
|
+
|
|
20
|
+
if (char === "'" && !inDouble && prev !== '\\') {
|
|
21
|
+
inSingle = !inSingle;
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (char === '"' && !inSingle && prev !== '\\') {
|
|
26
|
+
inDouble = !inDouble;
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (char === COMMENT_MARKER && !inSingle && !inDouble) {
|
|
31
|
+
return line.slice(0, i).trimEnd();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return line;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function assignPath(target, pathParts, value) {
|
|
39
|
+
let cursor = target;
|
|
40
|
+
for (let i = 0; i < pathParts.length - 1; i++) {
|
|
41
|
+
const key = pathParts[i];
|
|
42
|
+
if (!cursor[key] || typeof cursor[key] !== 'object' || Array.isArray(cursor[key])) {
|
|
43
|
+
cursor[key] = {};
|
|
44
|
+
}
|
|
45
|
+
cursor = cursor[key];
|
|
46
|
+
}
|
|
47
|
+
cursor[pathParts[pathParts.length - 1]] = value;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function parseString(value) {
|
|
51
|
+
if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
|
|
52
|
+
return value.slice(1, -1);
|
|
53
|
+
}
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function splitInlineItems(value, separator = ',') {
|
|
58
|
+
const items = [];
|
|
59
|
+
let current = '';
|
|
60
|
+
let inSingle = false;
|
|
61
|
+
let inDouble = false;
|
|
62
|
+
let depth = 0;
|
|
63
|
+
|
|
64
|
+
for (let i = 0; i < value.length; i++) {
|
|
65
|
+
const char = value[i];
|
|
66
|
+
const prev = i > 0 ? value[i - 1] : '';
|
|
67
|
+
|
|
68
|
+
if (char === "'" && !inDouble && prev !== '\\') {
|
|
69
|
+
inSingle = !inSingle;
|
|
70
|
+
} else if (char === '"' && !inSingle && prev !== '\\') {
|
|
71
|
+
inDouble = !inDouble;
|
|
72
|
+
} else if (!inSingle && !inDouble) {
|
|
73
|
+
if (char === '[' || char === '{') depth++;
|
|
74
|
+
if (char === ']' || char === '}') depth--;
|
|
75
|
+
if (char === separator && depth === 0) {
|
|
76
|
+
items.push(current.trim());
|
|
77
|
+
current = '';
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
current += char;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (current.trim()) {
|
|
86
|
+
items.push(current.trim());
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return items;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function parseValue(rawValue) {
|
|
93
|
+
const value = rawValue.trim();
|
|
94
|
+
|
|
95
|
+
const asString = parseString(value);
|
|
96
|
+
if (asString !== null) return asString;
|
|
97
|
+
|
|
98
|
+
if (value === 'true') return true;
|
|
99
|
+
if (value === 'false') return false;
|
|
100
|
+
if (/^-?\d+$/.test(value)) return Number.parseInt(value, 10);
|
|
101
|
+
if (/^-?\d+\.\d+$/.test(value)) return Number.parseFloat(value);
|
|
102
|
+
|
|
103
|
+
if (value.startsWith('[') && value.endsWith(']')) {
|
|
104
|
+
const inner = value.slice(1, -1).trim();
|
|
105
|
+
if (!inner) return [];
|
|
106
|
+
return splitInlineItems(inner).map(parseValue);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (value.startsWith('{') && value.endsWith('}')) {
|
|
110
|
+
const inner = value.slice(1, -1).trim();
|
|
111
|
+
const result = {};
|
|
112
|
+
if (!inner) return result;
|
|
113
|
+
|
|
114
|
+
for (const entry of splitInlineItems(inner)) {
|
|
115
|
+
const idx = entry.indexOf('=');
|
|
116
|
+
if (idx === -1) {
|
|
117
|
+
throw new Error(`Invalid inline table entry: ${entry}`);
|
|
118
|
+
}
|
|
119
|
+
const key = entry.slice(0, idx).trim();
|
|
120
|
+
const entryValue = entry.slice(idx + 1).trim();
|
|
121
|
+
assignPath(result, key.split('.').map(part => part.trim()).filter(Boolean), parseValue(entryValue));
|
|
122
|
+
}
|
|
123
|
+
return result;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return value;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function parseToml(content) {
|
|
130
|
+
const root = {};
|
|
131
|
+
let currentSection = [];
|
|
132
|
+
|
|
133
|
+
const lines = content.split(/\r?\n/);
|
|
134
|
+
for (let i = 0; i < lines.length; i++) {
|
|
135
|
+
const rawLine = lines[i];
|
|
136
|
+
const line = stripInlineComment(rawLine).trim();
|
|
137
|
+
if (!line) continue;
|
|
138
|
+
|
|
139
|
+
if (line.startsWith('[') && line.endsWith(']')) {
|
|
140
|
+
const sectionName = line.slice(1, -1).trim();
|
|
141
|
+
if (!sectionName) {
|
|
142
|
+
throw new Error(`Line ${i + 1}: empty section header`);
|
|
143
|
+
}
|
|
144
|
+
currentSection = sectionName.split('.').map(part => part.trim()).filter(Boolean);
|
|
145
|
+
assignPath(root, currentSection, {});
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const eqIndex = line.indexOf('=');
|
|
150
|
+
if (eqIndex === -1) {
|
|
151
|
+
throw new Error(`Line ${i + 1}: expected key = value`);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const key = line.slice(0, eqIndex).trim();
|
|
155
|
+
const rawVal = line.slice(eqIndex + 1).trim();
|
|
156
|
+
if (!key || !rawVal) {
|
|
157
|
+
throw new Error(`Line ${i + 1}: invalid key/value pair`);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const keyPath = key.split('.').map(part => part.trim()).filter(Boolean);
|
|
161
|
+
assignPath(root, [...currentSection, ...keyPath], parseValue(rawVal));
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
return root;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function tryParseToml(content) {
|
|
168
|
+
try {
|
|
169
|
+
return { ok: true, data: parseToml(content), error: null };
|
|
170
|
+
} catch (error) {
|
|
171
|
+
return { ok: false, data: null, error: error.message };
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// ─── JSON parsing ────────────────────────────────────────────────────────────
|
|
176
|
+
|
|
177
|
+
function tryParseJson(content) {
|
|
178
|
+
try {
|
|
179
|
+
const data = JSON.parse(content);
|
|
180
|
+
return { ok: true, data, error: null };
|
|
181
|
+
} catch (error) {
|
|
182
|
+
return { ok: false, data: null, error: error.message };
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// ─── Value extraction ────────────────────────────────────────────────────────
|
|
187
|
+
|
|
188
|
+
function getValueByPath(obj, dottedPath) {
|
|
189
|
+
if (!obj) return undefined;
|
|
190
|
+
const parts = dottedPath.split('.').filter(Boolean);
|
|
191
|
+
let cursor = obj;
|
|
192
|
+
for (const part of parts) {
|
|
193
|
+
if (cursor == null || typeof cursor !== 'object' || !(part in cursor)) {
|
|
194
|
+
return undefined;
|
|
195
|
+
}
|
|
196
|
+
cursor = cursor[part];
|
|
197
|
+
}
|
|
198
|
+
return cursor;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// ─── Validation ──────────────────────────────────────────────────────────────
|
|
202
|
+
|
|
203
|
+
const KNOWN_SETTINGS_KEYS = new Set([
|
|
204
|
+
'sandbox',
|
|
205
|
+
'sandbox.mode',
|
|
206
|
+
'sandbox.permissions',
|
|
207
|
+
'model',
|
|
208
|
+
'temperature',
|
|
209
|
+
'maxTokens',
|
|
210
|
+
'mcpServers',
|
|
211
|
+
'hooks',
|
|
212
|
+
'hooks.BeforeTool',
|
|
213
|
+
'hooks.AfterTool',
|
|
214
|
+
'theme',
|
|
215
|
+
'telemetry',
|
|
216
|
+
'safety',
|
|
217
|
+
'context',
|
|
218
|
+
'context.fileName',
|
|
219
|
+
'extensions',
|
|
220
|
+
'agents',
|
|
221
|
+
'commands',
|
|
222
|
+
'policy',
|
|
223
|
+
]);
|
|
224
|
+
|
|
225
|
+
const DEPRECATED_KEYS = new Map([
|
|
226
|
+
['sandbox_mode', 'Use "sandbox.mode" instead'],
|
|
227
|
+
['max_tokens', 'Use "maxTokens" instead'],
|
|
228
|
+
['mcp_servers', 'Use "mcpServers" instead'],
|
|
229
|
+
]);
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Validate settings.json keys against known and deprecated key lists.
|
|
233
|
+
* @param {object} data - Parsed settings object.
|
|
234
|
+
* @returns {{ unknown: string[], deprecated: Array<{key: string, message: string}> }}
|
|
235
|
+
*/
|
|
236
|
+
function validateSettingsKeys(data) {
|
|
237
|
+
if (!data || typeof data !== 'object') {
|
|
238
|
+
return { unknown: [], deprecated: [] };
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const unknown = [];
|
|
242
|
+
const deprecated = [];
|
|
243
|
+
|
|
244
|
+
function walk(obj, prefix) {
|
|
245
|
+
for (const key of Object.keys(obj)) {
|
|
246
|
+
const fullKey = prefix ? `${prefix}.${key}` : key;
|
|
247
|
+
|
|
248
|
+
if (DEPRECATED_KEYS.has(fullKey)) {
|
|
249
|
+
deprecated.push({ key: fullKey, message: DEPRECATED_KEYS.get(fullKey) });
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if (!KNOWN_SETTINGS_KEYS.has(fullKey) && !DEPRECATED_KEYS.has(fullKey)) {
|
|
253
|
+
// Allow arbitrary sub-keys under known namespace objects
|
|
254
|
+
const parentKnown = prefix && (KNOWN_SETTINGS_KEYS.has(prefix) || DEPRECATED_KEYS.has(prefix));
|
|
255
|
+
if (!parentKnown) {
|
|
256
|
+
unknown.push(fullKey);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if (obj[key] && typeof obj[key] === 'object' && !Array.isArray(obj[key])) {
|
|
261
|
+
walk(obj[key], fullKey);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
walk(data, '');
|
|
267
|
+
return { unknown, deprecated };
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
module.exports = {
|
|
271
|
+
tryParseJson,
|
|
272
|
+
tryParseToml,
|
|
273
|
+
getValueByPath,
|
|
274
|
+
validateSettingsKeys,
|
|
275
|
+
};
|