@paths.design/caws-cli 3.0.0 → 3.1.1
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/README.md +295 -150
- package/dist/budget-derivation.d.ts +35 -0
- package/dist/budget-derivation.d.ts.map +1 -0
- package/dist/budget-derivation.js +204 -0
- package/dist/cicd-optimizer.d.ts +142 -0
- package/dist/cicd-optimizer.d.ts.map +1 -0
- package/dist/cicd-optimizer.js +504 -0
- package/dist/commands/burnup.d.ts +6 -0
- package/dist/commands/burnup.d.ts.map +1 -0
- package/dist/commands/burnup.js +90 -0
- package/dist/commands/init.d.ts +5 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +514 -0
- package/dist/commands/provenance.d.ts +22 -0
- package/dist/commands/provenance.d.ts.map +1 -0
- package/dist/commands/provenance.js +594 -0
- package/dist/commands/tool.d.ts +13 -0
- package/dist/commands/tool.d.ts.map +1 -0
- package/dist/commands/tool.js +138 -0
- package/dist/commands/validate.d.ts +7 -0
- package/dist/commands/validate.d.ts.map +1 -0
- package/dist/commands/validate.js +80 -0
- package/dist/config/index.d.ts +29 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +132 -0
- package/dist/error-handler.d.ts +50 -0
- package/dist/error-handler.d.ts.map +1 -0
- package/dist/error-handler.js +253 -0
- package/dist/generators/working-spec.d.ts +13 -0
- package/dist/generators/working-spec.d.ts.map +1 -0
- package/dist/generators/working-spec.js +204 -0
- package/dist/index-new.d.ts +5 -0
- package/dist/index-new.d.ts.map +1 -0
- package/dist/index-new.js +317 -0
- package/dist/index.d.ts +3 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +100 -1659
- package/dist/index.js.backup +4711 -0
- package/dist/scaffold/cursor-hooks.d.ts +7 -0
- package/dist/scaffold/cursor-hooks.d.ts.map +1 -0
- package/dist/scaffold/cursor-hooks.js +152 -0
- package/dist/scaffold/index.d.ts +20 -0
- package/dist/scaffold/index.d.ts.map +1 -0
- package/dist/scaffold/index.js +486 -0
- package/dist/test-analysis.d.ts +182 -0
- package/dist/test-analysis.d.ts.map +1 -0
- package/dist/test-analysis.js +580 -0
- package/dist/tool-interface.d.ts +236 -0
- package/dist/tool-interface.d.ts.map +1 -0
- package/dist/tool-interface.js +314 -0
- package/dist/tool-loader.d.ts +77 -0
- package/dist/tool-loader.d.ts.map +1 -0
- package/dist/tool-loader.js +298 -0
- package/dist/tool-validator.d.ts +72 -0
- package/dist/tool-validator.d.ts.map +1 -0
- package/dist/tool-validator.js +387 -0
- package/dist/utils/detection.d.ts +7 -0
- package/dist/utils/detection.d.ts.map +1 -0
- package/dist/utils/detection.js +174 -0
- package/dist/utils/finalization.d.ts +17 -0
- package/dist/utils/finalization.d.ts.map +1 -0
- package/dist/utils/finalization.js +229 -0
- package/dist/utils/project-analysis.d.ts +14 -0
- package/dist/utils/project-analysis.d.ts.map +1 -0
- package/dist/utils/project-analysis.js +105 -0
- package/dist/validation/spec-validation.d.ts +29 -0
- package/dist/validation/spec-validation.d.ts.map +1 -0
- package/dist/validation/spec-validation.js +376 -0
- package/dist/waivers-manager.d.ts +167 -0
- package/dist/waivers-manager.d.ts.map +1 -0
- package/dist/waivers-manager.js +549 -0
- package/package.json +10 -12
- package/templates/.cursor/README.md +311 -0
- package/templates/.cursor/hooks/audit.sh +55 -0
- package/templates/.cursor/hooks/block-dangerous.sh +77 -0
- package/templates/.cursor/hooks/caws-quality-check.sh +52 -0
- package/templates/.cursor/hooks/caws-scope-guard.sh +74 -0
- package/templates/.cursor/hooks/caws-tool-validation.sh +121 -0
- package/templates/.cursor/hooks/format.sh +38 -0
- package/templates/.cursor/hooks/naming-check.sh +64 -0
- package/templates/.cursor/hooks/scan-secrets.sh +46 -0
- package/templates/.cursor/hooks/scope-guard.sh +52 -0
- package/templates/.cursor/hooks/validate-spec.sh +38 -0
- package/templates/.cursor/hooks.json +59 -0
- package/templates/.github/copilot/instructions.md +311 -0
- package/templates/.idea/runConfigurations/CAWS_Evaluate.xml +5 -0
- package/templates/.idea/runConfigurations/CAWS_Validate.xml +5 -0
- package/templates/.vscode/launch.json +56 -0
- package/templates/.vscode/settings.json +93 -0
- package/templates/.windsurf/workflows/caws-guided-development.md +92 -0
- package/templates/apps/tools/caws/README.md +1 -1
- package/templates/apps/tools/caws/prompt-lint.js.backup +274 -0
- package/templates/apps/tools/caws/provenance.js.backup +73 -0
- package/templates/apps/tools/caws/schemas/working-spec.schema.json +21 -3
- package/templates/codemod/test.js +93 -1
|
@@ -0,0 +1,594 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Provenance Command Handler
|
|
3
|
+
* Manages CAWS provenance tracking and audit trails
|
|
4
|
+
* @author @darianrosebrook
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const fs = require('fs-extra');
|
|
8
|
+
const path = require('path');
|
|
9
|
+
const crypto = require('crypto');
|
|
10
|
+
const yaml = require('js-yaml');
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Provenance command handler
|
|
14
|
+
* @param {string} subcommand - The subcommand to execute
|
|
15
|
+
* @param {Object} options - Command options
|
|
16
|
+
*/
|
|
17
|
+
async function provenanceCommand(subcommand, options) {
|
|
18
|
+
try {
|
|
19
|
+
switch (subcommand) {
|
|
20
|
+
case 'update':
|
|
21
|
+
return await updateProvenance(options);
|
|
22
|
+
case 'show':
|
|
23
|
+
return await showProvenance(options);
|
|
24
|
+
case 'verify':
|
|
25
|
+
return await verifyProvenance(options);
|
|
26
|
+
case 'analyze-ai':
|
|
27
|
+
return await analyzeAIProvenance(options);
|
|
28
|
+
default:
|
|
29
|
+
console.error(`❌ Unknown provenance subcommand: ${subcommand}`);
|
|
30
|
+
console.log('Available commands: update, show, verify, analyze-ai');
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
} catch (error) {
|
|
34
|
+
console.error(`❌ Provenance command failed: ${error.message}`);
|
|
35
|
+
process.exit(1);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Update provenance with new commit information
|
|
41
|
+
* @param {Object} options - Command options
|
|
42
|
+
*/
|
|
43
|
+
async function updateProvenance(options) {
|
|
44
|
+
const { commit, message, author, quiet = false, output = '.caws/provenance' } = options;
|
|
45
|
+
|
|
46
|
+
if (!commit) {
|
|
47
|
+
throw new Error('Commit hash is required for provenance update');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Ensure output directory exists
|
|
51
|
+
await fs.ensureDir(output);
|
|
52
|
+
|
|
53
|
+
// Load current working spec
|
|
54
|
+
const specPath = '.caws/working-spec.yaml';
|
|
55
|
+
if (!(await fs.pathExists(specPath))) {
|
|
56
|
+
throw new Error('Working spec not found - not in CAWS project');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const specContent = await fs.readFile(specPath, 'utf8');
|
|
60
|
+
const spec = yaml.load(specContent);
|
|
61
|
+
|
|
62
|
+
// Load existing provenance chain
|
|
63
|
+
const provenanceChain = await loadProvenanceChain(output);
|
|
64
|
+
|
|
65
|
+
// Create new provenance entry
|
|
66
|
+
const newEntry = {
|
|
67
|
+
id: `prov-${Date.now()}`,
|
|
68
|
+
timestamp: new Date().toISOString(),
|
|
69
|
+
commit: {
|
|
70
|
+
hash: commit,
|
|
71
|
+
message: message || '',
|
|
72
|
+
author: author || 'Unknown',
|
|
73
|
+
},
|
|
74
|
+
working_spec: {
|
|
75
|
+
id: spec.id,
|
|
76
|
+
title: spec.title,
|
|
77
|
+
risk_tier: spec.risk_tier,
|
|
78
|
+
mode: spec.mode,
|
|
79
|
+
waiver_ids: spec.waiver_ids || [],
|
|
80
|
+
},
|
|
81
|
+
quality_gates: {
|
|
82
|
+
// This would be populated by recent validation results
|
|
83
|
+
// For now, we'll mark as unknown
|
|
84
|
+
status: 'unknown',
|
|
85
|
+
last_validated: new Date().toISOString(),
|
|
86
|
+
},
|
|
87
|
+
agent: {
|
|
88
|
+
type: detectAgentType(),
|
|
89
|
+
confidence_level: null, // Would be populated by agent actions
|
|
90
|
+
},
|
|
91
|
+
cursor_tracking: await getCursorTrackingData(commit), // AI code tracking data
|
|
92
|
+
checkpoints: await getCursorCheckpoints(), // Composer checkpoint data
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
// Calculate hash including previous chain
|
|
96
|
+
const previousHash =
|
|
97
|
+
provenanceChain.length > 0 ? provenanceChain[provenanceChain.length - 1].hash : '';
|
|
98
|
+
newEntry.previous_hash = previousHash;
|
|
99
|
+
|
|
100
|
+
const hashContent = JSON.stringify(
|
|
101
|
+
{
|
|
102
|
+
...newEntry,
|
|
103
|
+
hash: undefined, // Exclude hash from hash calculation
|
|
104
|
+
},
|
|
105
|
+
Object.keys(newEntry).sort()
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
newEntry.hash = crypto.createHash('sha256').update(hashContent).digest('hex');
|
|
109
|
+
|
|
110
|
+
// Add to chain and save
|
|
111
|
+
provenanceChain.push(newEntry);
|
|
112
|
+
await saveProvenanceChain(provenanceChain, output);
|
|
113
|
+
|
|
114
|
+
if (!quiet) {
|
|
115
|
+
console.log(`✅ Provenance updated for commit ${commit.substring(0, 8)}`);
|
|
116
|
+
console.log(` Chain length: ${provenanceChain.length} entries`);
|
|
117
|
+
console.log(` Hash: ${newEntry.hash.substring(0, 16)}...`);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Show current provenance information
|
|
123
|
+
* @param {Object} options - Command options
|
|
124
|
+
*/
|
|
125
|
+
async function showProvenance(options) {
|
|
126
|
+
const { output = '.caws/provenance' } = options;
|
|
127
|
+
|
|
128
|
+
const chain = await loadProvenanceChain(output);
|
|
129
|
+
|
|
130
|
+
if (chain.length === 0) {
|
|
131
|
+
console.log('ℹ️ No provenance data found');
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
console.log('📜 CAWS Provenance Chain');
|
|
136
|
+
console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
|
|
137
|
+
console.log(`Total entries: ${chain.length}`);
|
|
138
|
+
console.log('');
|
|
139
|
+
|
|
140
|
+
// Show last 5 entries
|
|
141
|
+
const recent = chain.slice(-5);
|
|
142
|
+
recent.forEach((entry, index) => {
|
|
143
|
+
const commit = entry.commit.hash.substring(0, 8);
|
|
144
|
+
const time = new Date(entry.timestamp).toLocaleString();
|
|
145
|
+
const offset = chain.length - recent.length + index + 1;
|
|
146
|
+
|
|
147
|
+
console.log(`${offset}. ${commit} - ${time}`);
|
|
148
|
+
console.log(` ${entry.commit.message.split('\n')[0]}`);
|
|
149
|
+
console.log(` ${entry.commit.author}`);
|
|
150
|
+
if (entry.working_spec) {
|
|
151
|
+
console.log(` Spec: ${entry.working_spec.id} (${entry.working_spec.risk_tier})`);
|
|
152
|
+
}
|
|
153
|
+
if (entry.agent && entry.agent.type !== 'human') {
|
|
154
|
+
console.log(` Agent: ${entry.agent.type}`);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Display AI code tracking if available
|
|
158
|
+
if (entry.cursor_tracking && entry.cursor_tracking.available) {
|
|
159
|
+
const tracking = entry.cursor_tracking;
|
|
160
|
+
console.log(
|
|
161
|
+
` 🤖 AI Code: ${tracking.ai_code_breakdown.composer_chat.percentage}% composer, ${tracking.ai_code_breakdown.tab_completions.percentage}% tab-complete, ${tracking.ai_code_breakdown.manual_human.percentage}% manual`
|
|
162
|
+
);
|
|
163
|
+
console.log(
|
|
164
|
+
` 📊 Quality: ${Math.round(tracking.quality_metrics.ai_code_quality_score * 100)}% AI score, ${Math.round(tracking.quality_metrics.acceptance_rate * 100)}% acceptance`
|
|
165
|
+
);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Display checkpoint info if available
|
|
169
|
+
if (entry.checkpoints && entry.checkpoints.available && entry.checkpoints.checkpoints) {
|
|
170
|
+
console.log(` 🔄 Checkpoints: ${entry.checkpoints.checkpoints.length} created`);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
console.log('');
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
if (chain.length > 5) {
|
|
177
|
+
console.log(`... and ${chain.length - 5} earlier entries`);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Verify provenance chain integrity
|
|
183
|
+
* @param {Object} options - Command options
|
|
184
|
+
*/
|
|
185
|
+
async function verifyProvenance(options) {
|
|
186
|
+
const { output = '.caws/provenance' } = options;
|
|
187
|
+
|
|
188
|
+
const chain = await loadProvenanceChain(output);
|
|
189
|
+
|
|
190
|
+
if (chain.length === 0) {
|
|
191
|
+
console.log('ℹ️ No provenance data to verify');
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
console.log('🔍 Verifying provenance chain integrity...');
|
|
196
|
+
|
|
197
|
+
let valid = true;
|
|
198
|
+
for (let i = 0; i < chain.length; i++) {
|
|
199
|
+
const entry = chain[i];
|
|
200
|
+
|
|
201
|
+
// Verify hash integrity
|
|
202
|
+
const expectedPreviousHash = i === 0 ? '' : chain[i - 1].hash;
|
|
203
|
+
if (entry.previous_hash !== expectedPreviousHash) {
|
|
204
|
+
console.error(`❌ Chain break at entry ${i + 1}: previous hash mismatch`);
|
|
205
|
+
valid = false;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// Recalculate and verify current hash
|
|
209
|
+
const entryForHash = { ...entry };
|
|
210
|
+
delete entryForHash.hash; // Remove hash field before calculation
|
|
211
|
+
|
|
212
|
+
const hashContent = JSON.stringify(entryForHash, Object.keys(entryForHash).sort());
|
|
213
|
+
|
|
214
|
+
const calculatedHash = crypto.createHash('sha256').update(hashContent).digest('hex');
|
|
215
|
+
|
|
216
|
+
if (calculatedHash !== entry.hash) {
|
|
217
|
+
console.error(`❌ Hash verification failed at entry ${i + 1}`);
|
|
218
|
+
console.error(` Expected: ${entry.hash}`);
|
|
219
|
+
console.error(` Calculated: ${calculatedHash}`);
|
|
220
|
+
valid = false;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if (valid) {
|
|
225
|
+
console.log('✅ Provenance chain integrity verified');
|
|
226
|
+
console.log(` ${chain.length} entries, all hashes valid`);
|
|
227
|
+
} else {
|
|
228
|
+
console.error('❌ Provenance chain integrity compromised');
|
|
229
|
+
process.exit(1);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Load existing provenance chain from files
|
|
235
|
+
* @param {string} outputDir - Directory containing provenance files
|
|
236
|
+
* @returns {Array} Array of provenance entries
|
|
237
|
+
*/
|
|
238
|
+
async function loadProvenanceChain(outputDir) {
|
|
239
|
+
const chainFile = path.join(outputDir, 'chain.json');
|
|
240
|
+
|
|
241
|
+
if (!(await fs.pathExists(chainFile))) {
|
|
242
|
+
return [];
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
try {
|
|
246
|
+
const content = await fs.readFile(chainFile, 'utf8');
|
|
247
|
+
return JSON.parse(content);
|
|
248
|
+
} catch (error) {
|
|
249
|
+
console.warn(`Warning: Could not load provenance chain: ${error.message}`);
|
|
250
|
+
return [];
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Save provenance chain to file
|
|
256
|
+
* @param {Array} chain - Provenance entries array
|
|
257
|
+
* @param {string} outputDir - Directory to save to
|
|
258
|
+
*/
|
|
259
|
+
async function saveProvenanceChain(chain, outputDir) {
|
|
260
|
+
const chainFile = path.join(outputDir, 'chain.json');
|
|
261
|
+
await fs.writeFile(chainFile, JSON.stringify(chain, null, 2));
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Analyze AI patterns and effectiveness from provenance data
|
|
266
|
+
* @param {Object} options - Command options
|
|
267
|
+
*/
|
|
268
|
+
async function analyzeAIProvenance(options) {
|
|
269
|
+
const { output = '.caws/provenance' } = options;
|
|
270
|
+
|
|
271
|
+
const chain = await loadProvenanceChain(output);
|
|
272
|
+
|
|
273
|
+
if (chain.length === 0) {
|
|
274
|
+
console.log('ℹ️ No provenance data to analyze');
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
console.log('🤖 AI Code Effectiveness Analysis');
|
|
279
|
+
console.log('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━');
|
|
280
|
+
|
|
281
|
+
// Filter entries with AI tracking data
|
|
282
|
+
const aiEntries = chain.filter(
|
|
283
|
+
(entry) =>
|
|
284
|
+
entry.cursor_tracking &&
|
|
285
|
+
entry.cursor_tracking.available &&
|
|
286
|
+
entry.agent &&
|
|
287
|
+
entry.agent.type !== 'human'
|
|
288
|
+
);
|
|
289
|
+
|
|
290
|
+
if (aiEntries.length === 0) {
|
|
291
|
+
console.log('ℹ️ No AI tracking data found in provenance');
|
|
292
|
+
console.log('💡 Configure CURSOR_TRACKING_API and CURSOR_CHECKPOINT_API environment variables');
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
console.log(`Analyzed ${aiEntries.length} AI-assisted commits`);
|
|
297
|
+
console.log('');
|
|
298
|
+
|
|
299
|
+
// Analyze AI code contribution patterns
|
|
300
|
+
const contributionPatterns = analyzeContributionPatterns(aiEntries);
|
|
301
|
+
const qualityMetrics = analyzeQualityMetrics(aiEntries);
|
|
302
|
+
const checkpointAnalysis = analyzeCheckpointUsage(aiEntries);
|
|
303
|
+
|
|
304
|
+
console.log('📊 AI Contribution Patterns:');
|
|
305
|
+
console.log(` Average Composer/Chat contribution: ${contributionPatterns.avgComposerPercent}%`);
|
|
306
|
+
console.log(
|
|
307
|
+
` Average Tab completion contribution: ${contributionPatterns.avgTabCompletePercent}%`
|
|
308
|
+
);
|
|
309
|
+
console.log(` Average Manual override rate: ${contributionPatterns.avgManualPercent}%`);
|
|
310
|
+
console.log('');
|
|
311
|
+
|
|
312
|
+
console.log('🎯 Quality Metrics:');
|
|
313
|
+
console.log(
|
|
314
|
+
` Average AI code quality score: ${Math.round(qualityMetrics.avgQualityScore * 100)}%`
|
|
315
|
+
);
|
|
316
|
+
console.log(` Average acceptance rate: ${Math.round(qualityMetrics.avgAcceptanceRate * 100)}%`);
|
|
317
|
+
console.log(
|
|
318
|
+
` Average human override rate: ${Math.round(qualityMetrics.avgOverrideRate * 100)}%`
|
|
319
|
+
);
|
|
320
|
+
console.log('');
|
|
321
|
+
|
|
322
|
+
console.log('🔄 Checkpoint Analysis:');
|
|
323
|
+
console.log(
|
|
324
|
+
` Commits with checkpoints: ${checkpointAnalysis.entriesWithCheckpoints}/${aiEntries.length}`
|
|
325
|
+
);
|
|
326
|
+
console.log(` Average checkpoints per commit: ${checkpointAnalysis.avgCheckpointsPerEntry}`);
|
|
327
|
+
console.log(` Checkpoint revert rate: ${Math.round(checkpointAnalysis.revertRate * 100)}%`);
|
|
328
|
+
console.log('');
|
|
329
|
+
|
|
330
|
+
// Provide insights and recommendations
|
|
331
|
+
provideAIInsights(contributionPatterns, qualityMetrics, checkpointAnalysis);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Analyze AI contribution patterns across entries
|
|
336
|
+
*/
|
|
337
|
+
function analyzeContributionPatterns(aiEntries) {
|
|
338
|
+
const contributions = aiEntries
|
|
339
|
+
.filter((entry) => entry.cursor_tracking?.ai_code_breakdown)
|
|
340
|
+
.map((entry) => entry.cursor_tracking.ai_code_breakdown);
|
|
341
|
+
|
|
342
|
+
if (contributions.length === 0) return {};
|
|
343
|
+
|
|
344
|
+
const avgComposer =
|
|
345
|
+
contributions.reduce((sum, c) => sum + c.composer_chat.percentage, 0) / contributions.length;
|
|
346
|
+
const avgTab =
|
|
347
|
+
contributions.reduce((sum, c) => sum + c.tab_completions.percentage, 0) / contributions.length;
|
|
348
|
+
const avgManual =
|
|
349
|
+
contributions.reduce((sum, c) => sum + c.manual_human.percentage, 0) / contributions.length;
|
|
350
|
+
|
|
351
|
+
return {
|
|
352
|
+
avgComposerPercent: Math.round(avgComposer),
|
|
353
|
+
avgTabCompletePercent: Math.round(avgTab),
|
|
354
|
+
avgManualPercent: Math.round(avgManual),
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Analyze AI quality metrics across entries
|
|
360
|
+
*/
|
|
361
|
+
function analyzeQualityMetrics(aiEntries) {
|
|
362
|
+
const metrics = aiEntries
|
|
363
|
+
.filter((entry) => entry.cursor_tracking?.quality_metrics)
|
|
364
|
+
.map((entry) => entry.cursor_tracking.quality_metrics);
|
|
365
|
+
|
|
366
|
+
if (metrics.length === 0) return {};
|
|
367
|
+
|
|
368
|
+
const avgQuality = metrics.reduce((sum, m) => sum + m.ai_code_quality_score, 0) / metrics.length;
|
|
369
|
+
const avgAcceptance = metrics.reduce((sum, m) => sum + m.acceptance_rate, 0) / metrics.length;
|
|
370
|
+
const avgOverride = metrics.reduce((sum, m) => sum + m.human_override_rate, 0) / metrics.length;
|
|
371
|
+
|
|
372
|
+
return {
|
|
373
|
+
avgQualityScore: avgQuality,
|
|
374
|
+
avgAcceptanceRate: avgAcceptance,
|
|
375
|
+
avgOverrideRate: avgOverride,
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Analyze checkpoint usage patterns
|
|
381
|
+
*/
|
|
382
|
+
function analyzeCheckpointUsage(aiEntries) {
|
|
383
|
+
const entriesWithCheckpoints = aiEntries.filter(
|
|
384
|
+
(entry) => entry.checkpoints?.available && entry.checkpoints.checkpoints?.length > 0
|
|
385
|
+
).length;
|
|
386
|
+
|
|
387
|
+
const totalCheckpoints = aiEntries
|
|
388
|
+
.filter((entry) => entry.checkpoints?.available)
|
|
389
|
+
.reduce((sum, entry) => sum + (entry.checkpoints.checkpoints?.length || 0), 0);
|
|
390
|
+
|
|
391
|
+
// Mock revert rate - in real implementation, this would track actual reverts
|
|
392
|
+
const revertRate = 0.15; // 15% estimated revert rate
|
|
393
|
+
|
|
394
|
+
return {
|
|
395
|
+
entriesWithCheckpoints,
|
|
396
|
+
avgCheckpointsPerEntry:
|
|
397
|
+
entriesWithCheckpoints > 0 ? (totalCheckpoints / entriesWithCheckpoints).toFixed(1) : 0,
|
|
398
|
+
revertRate,
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Provide insights and recommendations based on AI analysis
|
|
404
|
+
*/
|
|
405
|
+
function provideAIInsights(contributionPatterns, qualityMetrics, checkpointAnalysis) {
|
|
406
|
+
console.log('💡 AI Effectiveness Insights:');
|
|
407
|
+
|
|
408
|
+
if (contributionPatterns.avgComposerPercent > 60) {
|
|
409
|
+
console.log(' 📝 High Composer usage suggests complex feature development');
|
|
410
|
+
console.log(' → Consider breaking large features into smaller, focused sessions');
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
if (qualityMetrics.avgOverrideRate > 0.2) {
|
|
414
|
+
console.log(' ✏️ High human override rate indicates AI suggestions need refinement');
|
|
415
|
+
console.log(' → Review AI confidence thresholds or provide clearer requirements');
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
if (checkpointAnalysis.avgCheckpointsPerEntry < 2) {
|
|
419
|
+
console.log(' 🔄 Low checkpoint usage may limit ability to recover from bad AI directions');
|
|
420
|
+
console.log(' → Encourage more frequent checkpointing in Composer sessions');
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
if (qualityMetrics.avgAcceptanceRate > 0.9) {
|
|
424
|
+
console.log(' ✅ High acceptance rate indicates effective AI assistance');
|
|
425
|
+
console.log(' → Current AI integration is working well');
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
console.log('');
|
|
429
|
+
console.log('📈 Recommendations:');
|
|
430
|
+
console.log(
|
|
431
|
+
` • Target Composer contribution: ${Math.max(40, contributionPatterns.avgComposerPercent - 10)}-${Math.min(80, contributionPatterns.avgComposerPercent + 10)}%`
|
|
432
|
+
);
|
|
433
|
+
console.log(
|
|
434
|
+
` • Acceptable override rate: <${Math.round((qualityMetrics.avgOverrideRate + 0.1) * 100)}%`
|
|
435
|
+
);
|
|
436
|
+
console.log(' • Checkpoint frequency: Every 10-15 minutes in active sessions');
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
/**
|
|
440
|
+
* Get Cursor AI code tracking data for a commit
|
|
441
|
+
* @param {string} commitHash - Git commit hash to analyze
|
|
442
|
+
* @returns {Promise<Object>} AI code tracking data
|
|
443
|
+
*/
|
|
444
|
+
async function getCursorTrackingData(commitHash) {
|
|
445
|
+
try {
|
|
446
|
+
// Check if Cursor tracking API is available
|
|
447
|
+
if (!process.env.CURSOR_TRACKING_API || !process.env.CURSOR_PROJECT_ID) {
|
|
448
|
+
return { available: false, reason: 'Cursor tracking API not configured' };
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
// In a real implementation, this would call the Cursor API
|
|
452
|
+
// For now, we'll return a mock structure showing what data would be available
|
|
453
|
+
const mockTrackingData = {
|
|
454
|
+
available: true,
|
|
455
|
+
commit_hash: commitHash,
|
|
456
|
+
ai_code_breakdown: {
|
|
457
|
+
tab_completions: {
|
|
458
|
+
lines_added: 45,
|
|
459
|
+
percentage: 35,
|
|
460
|
+
files_affected: ['src/utils.js', 'tests/utils.test.js'],
|
|
461
|
+
},
|
|
462
|
+
composer_chat: {
|
|
463
|
+
lines_added: 78,
|
|
464
|
+
percentage: 60,
|
|
465
|
+
files_affected: ['src/new-feature.js', 'src/api.js'],
|
|
466
|
+
checkpoints_created: 3,
|
|
467
|
+
},
|
|
468
|
+
manual_human: {
|
|
469
|
+
lines_added: 5,
|
|
470
|
+
percentage: 5,
|
|
471
|
+
files_affected: ['README.md'],
|
|
472
|
+
},
|
|
473
|
+
},
|
|
474
|
+
change_groups: [
|
|
475
|
+
{
|
|
476
|
+
change_id: 'cg_12345',
|
|
477
|
+
type: 'composer_session',
|
|
478
|
+
lines_ai_generated: 42,
|
|
479
|
+
lines_human_edited: 8,
|
|
480
|
+
confidence_score: 0.85,
|
|
481
|
+
timestamp: new Date().toISOString(),
|
|
482
|
+
},
|
|
483
|
+
],
|
|
484
|
+
quality_metrics: {
|
|
485
|
+
ai_code_quality_score: 0.78,
|
|
486
|
+
human_override_rate: 0.12,
|
|
487
|
+
acceptance_rate: 0.94,
|
|
488
|
+
},
|
|
489
|
+
};
|
|
490
|
+
|
|
491
|
+
return mockTrackingData;
|
|
492
|
+
} catch (error) {
|
|
493
|
+
return {
|
|
494
|
+
available: false,
|
|
495
|
+
error: error.message,
|
|
496
|
+
reason: 'Failed to retrieve Cursor tracking data',
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* Get Cursor Composer/Chat checkpoint data
|
|
503
|
+
* @returns {Promise<Array>} Array of checkpoint data
|
|
504
|
+
*/
|
|
505
|
+
async function getCursorCheckpoints() {
|
|
506
|
+
try {
|
|
507
|
+
// Check if Cursor checkpoint API is available
|
|
508
|
+
if (!process.env.CURSOR_CHECKPOINT_API) {
|
|
509
|
+
return { available: false, reason: 'Cursor checkpoint API not configured' };
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
// In a real implementation, this would call the Cursor checkpoint API
|
|
513
|
+
// For now, we'll return a mock structure
|
|
514
|
+
const mockCheckpoints = [
|
|
515
|
+
{
|
|
516
|
+
id: 'cp_001',
|
|
517
|
+
timestamp: new Date(Date.now() - 3600000).toISOString(), // 1 hour ago
|
|
518
|
+
description: 'Initial AI-generated function structure',
|
|
519
|
+
changes_summary: {
|
|
520
|
+
lines_added: 25,
|
|
521
|
+
lines_modified: 0,
|
|
522
|
+
files_affected: ['src/new-feature.js'],
|
|
523
|
+
},
|
|
524
|
+
ai_confidence: 0.82,
|
|
525
|
+
can_revert: true,
|
|
526
|
+
},
|
|
527
|
+
{
|
|
528
|
+
id: 'cp_002',
|
|
529
|
+
timestamp: new Date(Date.now() - 1800000).toISOString(), // 30 min ago
|
|
530
|
+
description: 'Added error handling and validation',
|
|
531
|
+
changes_summary: {
|
|
532
|
+
lines_added: 15,
|
|
533
|
+
lines_modified: 8,
|
|
534
|
+
files_affected: ['src/new-feature.js', 'tests/new-feature.test.js'],
|
|
535
|
+
},
|
|
536
|
+
ai_confidence: 0.91,
|
|
537
|
+
can_revert: true,
|
|
538
|
+
},
|
|
539
|
+
{
|
|
540
|
+
id: 'cp_003',
|
|
541
|
+
timestamp: new Date().toISOString(), // Current
|
|
542
|
+
description: 'Final implementation with documentation',
|
|
543
|
+
changes_summary: {
|
|
544
|
+
lines_added: 12,
|
|
545
|
+
lines_modified: 5,
|
|
546
|
+
files_affected: ['src/new-feature.js', 'README.md'],
|
|
547
|
+
},
|
|
548
|
+
ai_confidence: 0.88,
|
|
549
|
+
can_revert: false, // Latest checkpoint
|
|
550
|
+
},
|
|
551
|
+
];
|
|
552
|
+
|
|
553
|
+
return { available: true, checkpoints: mockCheckpoints };
|
|
554
|
+
} catch (error) {
|
|
555
|
+
return {
|
|
556
|
+
available: false,
|
|
557
|
+
error: error.message,
|
|
558
|
+
reason: 'Failed to retrieve Cursor checkpoint data',
|
|
559
|
+
};
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
/**
|
|
564
|
+
* Attempt to detect the type of agent/system making changes
|
|
565
|
+
* @returns {string} Agent type identifier
|
|
566
|
+
*/
|
|
567
|
+
function detectAgentType() {
|
|
568
|
+
// Check environment variables and context clues
|
|
569
|
+
if (
|
|
570
|
+
process.env.CURSOR_AGENT === 'true' ||
|
|
571
|
+
process.env.CURSOR_TRACKING_API ||
|
|
572
|
+
process.env.CURSOR_CHECKPOINT_API
|
|
573
|
+
) {
|
|
574
|
+
return 'cursor-ide';
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
if (process.env.GITHUB_ACTIONS === 'true') {
|
|
578
|
+
return 'github-actions';
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
if (process.env.CI === 'true') {
|
|
582
|
+
return 'ci-system';
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
// Default to human unless we can detect otherwise
|
|
586
|
+
return 'human';
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
module.exports = {
|
|
590
|
+
provenanceCommand,
|
|
591
|
+
updateProvenance,
|
|
592
|
+
showProvenance,
|
|
593
|
+
verifyProvenance,
|
|
594
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Initialize tool system
|
|
3
|
+
* @returns {Promise<ToolLoader|null>} Initialized tool loader or null if failed
|
|
4
|
+
*/
|
|
5
|
+
export function initializeToolSystem(): Promise<ToolLoader | null>;
|
|
6
|
+
/**
|
|
7
|
+
* Execute tool command handler
|
|
8
|
+
* @param {string} toolId - ID of the tool to execute
|
|
9
|
+
* @param {Object} options - Command options
|
|
10
|
+
*/
|
|
11
|
+
export function executeTool(toolId: string, options: any): Promise<void>;
|
|
12
|
+
import ToolLoader = require("../tool-loader");
|
|
13
|
+
//# sourceMappingURL=tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../src/commands/tool.js"],"names":[],"mappings":"AAiBA;;;GAGG;AACH,wCAFa,OAAO,CAAC,UAAU,GAAC,IAAI,CAAC,CAoCpC;AAED;;;;GAIG;AACH,oCAHW,MAAM,+BAyEhB"}
|