@getvibeguard/cli 1.0.0
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 +166 -0
- package/dashboard/dist/assets/Tableau10-B-NsZVaP.js +1 -0
- package/dashboard/dist/assets/arc-CZ1oDkm-.js +1 -0
- package/dashboard/dist/assets/array-BKyUJesY.js +1 -0
- package/dashboard/dist/assets/blockDiagram-c4efeb88-BLITAZDl.js +118 -0
- package/dashboard/dist/assets/c4Diagram-c83219d4-DErNj891.js +10 -0
- package/dashboard/dist/assets/channel-sWBGOq9p.js +1 -0
- package/dashboard/dist/assets/classDiagram-beda092f-Bj8IB6RW.js +2 -0
- package/dashboard/dist/assets/classDiagram-v2-2358418a-BZtd2g5W.js +2 -0
- package/dashboard/dist/assets/clone-DtEyH3ya.js +1 -0
- package/dashboard/dist/assets/createText-1719965b-DkNrTk-5.js +7 -0
- package/dashboard/dist/assets/edges-96097737-CYxl0j3g.js +4 -0
- package/dashboard/dist/assets/erDiagram-0228fc6a-ClEp9Atg.js +51 -0
- package/dashboard/dist/assets/flowDb-c6c81e3f-ClDJCJwu.js +10 -0
- package/dashboard/dist/assets/flowDiagram-50d868cf-DYxwClWS.js +4 -0
- package/dashboard/dist/assets/flowDiagram-v2-4f6560a1-D7vEnO1T.js +1 -0
- package/dashboard/dist/assets/flowchart-elk-definition-6af322e1-C-wX1mNx.js +139 -0
- package/dashboard/dist/assets/ganttDiagram-a2739b55-DTeLavAj.js +257 -0
- package/dashboard/dist/assets/gitGraphDiagram-82fe8481-ClxNoYya.js +70 -0
- package/dashboard/dist/assets/graph-CT-F3Got.js +1 -0
- package/dashboard/dist/assets/index-5325376f-C-jTCYZA.js +1 -0
- package/dashboard/dist/assets/index-CvYvquQR.js +283 -0
- package/dashboard/dist/assets/index-n43poL1x.css +1 -0
- package/dashboard/dist/assets/infoDiagram-8eee0895-Zljudo5L.js +7 -0
- package/dashboard/dist/assets/init-Gi6I4Gst.js +1 -0
- package/dashboard/dist/assets/journeyDiagram-c64418c1-DXzTbuum.js +139 -0
- package/dashboard/dist/assets/katex-Cu_Erd72.js +261 -0
- package/dashboard/dist/assets/layout-CVO3EizT.js +1 -0
- package/dashboard/dist/assets/line-CIgln-0z.js +1 -0
- package/dashboard/dist/assets/linear-bmIUMQqg.js +1 -0
- package/dashboard/dist/assets/mindmap-definition-8da855dc-BDLTNZYk.js +425 -0
- package/dashboard/dist/assets/ordinal-Cboi1Yqb.js +1 -0
- package/dashboard/dist/assets/path-CbwjOpE9.js +1 -0
- package/dashboard/dist/assets/pieDiagram-a8764435-DtcOKNPc.js +35 -0
- package/dashboard/dist/assets/quadrantDiagram-1e28029f-zoSI_Ltf.js +7 -0
- package/dashboard/dist/assets/requirementDiagram-08caed73-TsQZ9lTB.js +52 -0
- package/dashboard/dist/assets/sankeyDiagram-a04cb91d-DE5ciDwD.js +8 -0
- package/dashboard/dist/assets/sequenceDiagram-c5b8d532-DhabPb2n.js +122 -0
- package/dashboard/dist/assets/stateDiagram-1ecb1508-Bg2q_YNx.js +1 -0
- package/dashboard/dist/assets/stateDiagram-v2-c2b004d7-Bs5iRjYB.js +1 -0
- package/dashboard/dist/assets/styles-b4e223ce-DchmAmav.js +160 -0
- package/dashboard/dist/assets/styles-ca3715f6-Bu5zjaDx.js +207 -0
- package/dashboard/dist/assets/styles-d45a18b0-jCaD8baR.js +116 -0
- package/dashboard/dist/assets/svgDrawCommon-b86b1483-BrYVGY4c.js +1 -0
- package/dashboard/dist/assets/timeline-definition-faaaa080--sq0bTHe.js +61 -0
- package/dashboard/dist/assets/xychartDiagram-f5964ef8-ByvzN0uj.js +7 -0
- package/dashboard/dist/index.html +22 -0
- package/dist/cli.d.ts +4 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +641 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/dashboard.d.ts +2 -0
- package/dist/commands/dashboard.d.ts.map +1 -0
- package/dist/commands/dashboard.js +184 -0
- package/dist/commands/dashboard.js.map +1 -0
- package/dist/commands/init.d.ts +5 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +501 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +602 -0
- package/dist/index.js.map +1 -0
- package/dist/librarian/autofix.d.ts +34 -0
- package/dist/librarian/autofix.d.ts.map +1 -0
- package/dist/librarian/autofix.js +369 -0
- package/dist/librarian/autofix.js.map +1 -0
- package/dist/librarian/heartbeat.d.ts +38 -0
- package/dist/librarian/heartbeat.d.ts.map +1 -0
- package/dist/librarian/heartbeat.js +98 -0
- package/dist/librarian/heartbeat.js.map +1 -0
- package/dist/librarian/initializer.d.ts +41 -0
- package/dist/librarian/initializer.d.ts.map +1 -0
- package/dist/librarian/initializer.js +202 -0
- package/dist/librarian/initializer.js.map +1 -0
- package/dist/librarian/memory-manager.d.ts +37 -0
- package/dist/librarian/memory-manager.d.ts.map +1 -0
- package/dist/librarian/memory-manager.js +205 -0
- package/dist/librarian/memory-manager.js.map +1 -0
- package/dist/librarian/oracle.d.ts +51 -0
- package/dist/librarian/oracle.d.ts.map +1 -0
- package/dist/librarian/oracle.js +235 -0
- package/dist/librarian/oracle.js.map +1 -0
- package/dist/librarian/summarizer.d.ts +19 -0
- package/dist/librarian/summarizer.d.ts.map +1 -0
- package/dist/librarian/summarizer.js +175 -0
- package/dist/librarian/summarizer.js.map +1 -0
- package/dist/librarian/watcher.d.ts +51 -0
- package/dist/librarian/watcher.d.ts.map +1 -0
- package/dist/librarian/watcher.js +189 -0
- package/dist/librarian/watcher.js.map +1 -0
- package/dist/mcp-server.d.ts +10 -0
- package/dist/mcp-server.d.ts.map +1 -0
- package/dist/mcp-server.js +879 -0
- package/dist/mcp-server.js.map +1 -0
- package/dist/services/token-tracker.d.ts +58 -0
- package/dist/services/token-tracker.d.ts.map +1 -0
- package/dist/services/token-tracker.js +178 -0
- package/dist/services/token-tracker.js.map +1 -0
- package/dist/utils/chunker.d.ts +5 -0
- package/dist/utils/chunker.d.ts.map +1 -0
- package/dist/utils/chunker.js +121 -0
- package/dist/utils/chunker.js.map +1 -0
- package/dist/utils/config-manager.d.ts +65 -0
- package/dist/utils/config-manager.d.ts.map +1 -0
- package/dist/utils/config-manager.js +243 -0
- package/dist/utils/config-manager.js.map +1 -0
- package/dist/utils/config.d.ts +46 -0
- package/dist/utils/config.d.ts.map +1 -0
- package/dist/utils/config.js +171 -0
- package/dist/utils/config.js.map +1 -0
- package/dist/utils/diff-cleaner.d.ts +13 -0
- package/dist/utils/diff-cleaner.d.ts.map +1 -0
- package/dist/utils/diff-cleaner.js +80 -0
- package/dist/utils/diff-cleaner.js.map +1 -0
- package/dist/utils/git.d.ts +71 -0
- package/dist/utils/git.d.ts.map +1 -0
- package/dist/utils/git.js +285 -0
- package/dist/utils/git.js.map +1 -0
- package/dist/utils/llm.d.ts +30 -0
- package/dist/utils/llm.d.ts.map +1 -0
- package/dist/utils/llm.js +308 -0
- package/dist/utils/llm.js.map +1 -0
- package/dist/utils/pricing.d.ts +47 -0
- package/dist/utils/pricing.d.ts.map +1 -0
- package/dist/utils/pricing.js +171 -0
- package/dist/utils/pricing.js.map +1 -0
- package/package.json +45 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"autofix.d.ts","sourceRoot":"","sources":["../../src/librarian/autofix.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;CACzB;AAED,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,QAAQ,CAAW;IAC3B,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,GAAG,CAAY;gBAEX,QAAQ,GAAE,MAAsB;IAO5C;;OAEG;IACG,QAAQ,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IA4OtD;;OAEG;YACW,uBAAuB;IAkBrC;;OAEG;YACW,qBAAqB;IAqDnC;;OAEG;YACW,cAAc;IA8C5B;;OAEG;YACW,iBAAiB;CAQhC"}
|
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
import * as fs from 'fs/promises';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import { OracleService } from './oracle.js';
|
|
4
|
+
import { GitUtils } from '../utils/git.js';
|
|
5
|
+
import { generateSummary } from '../utils/llm.js';
|
|
6
|
+
import writeFileAtomic from 'write-file-atomic';
|
|
7
|
+
import { simpleGit } from 'simple-git';
|
|
8
|
+
export class AutoFixService {
|
|
9
|
+
repoPath;
|
|
10
|
+
gitUtils;
|
|
11
|
+
oracleService;
|
|
12
|
+
git;
|
|
13
|
+
constructor(repoPath = process.cwd()) {
|
|
14
|
+
this.repoPath = repoPath;
|
|
15
|
+
this.gitUtils = new GitUtils(repoPath);
|
|
16
|
+
this.oracleService = new OracleService(repoPath);
|
|
17
|
+
this.git = simpleGit(repoPath);
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Apply a fix for a prophecy by creating a git branch and refactoring code
|
|
21
|
+
*/
|
|
22
|
+
async applyFix(prophecyId) {
|
|
23
|
+
try {
|
|
24
|
+
// Step 1: Retrieve prophecy
|
|
25
|
+
const prophecies = await this.oracleService.getProphecies();
|
|
26
|
+
const prophecy = prophecies.find(p => p.id === prophecyId);
|
|
27
|
+
if (!prophecy) {
|
|
28
|
+
return {
|
|
29
|
+
success: false,
|
|
30
|
+
error: `Prophecy with id ${prophecyId} not found`,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
// Step 2: Check for clean working directory
|
|
34
|
+
const hasUncommittedChanges = await this.checkUncommittedChanges();
|
|
35
|
+
if (hasUncommittedChanges) {
|
|
36
|
+
return {
|
|
37
|
+
success: false,
|
|
38
|
+
error: 'Working directory has uncommitted changes. Please commit or stash changes before applying fixes.',
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
// Step 3: Create git branch with unique name
|
|
42
|
+
// Store original branch before switching
|
|
43
|
+
const originalBranch = await this.git.revparse(['--abbrev-ref', 'HEAD']);
|
|
44
|
+
const shortId = prophecyId.split('-').pop()?.substring(0, 8) || 'fix';
|
|
45
|
+
let branchName = `vibeguard/fix-${shortId}`;
|
|
46
|
+
let branchSuffix = 0;
|
|
47
|
+
let branchCreated = false;
|
|
48
|
+
// Find main/master branch name
|
|
49
|
+
const branches = await this.git.branchLocal();
|
|
50
|
+
const mainBranch = branches.all.find(b => b === 'main' || b === 'master') || 'main';
|
|
51
|
+
// Check if branch exists and make it unique if needed
|
|
52
|
+
while (true) {
|
|
53
|
+
try {
|
|
54
|
+
const branchExists = branches.all.some(b => b === branchName || b === `refs/heads/${branchName}`);
|
|
55
|
+
if (!branchExists) {
|
|
56
|
+
// Branch doesn't exist, create it from main branch
|
|
57
|
+
await this.git.checkout(mainBranch);
|
|
58
|
+
await this.git.checkoutLocalBranch(branchName);
|
|
59
|
+
branchCreated = true;
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
// Branch exists, check its state
|
|
64
|
+
try {
|
|
65
|
+
const branchRef = await this.git.revparse(['--abbrev-ref', branchName]);
|
|
66
|
+
const currentBranch = await this.git.revparse(['--abbrev-ref', 'HEAD']);
|
|
67
|
+
// If we're already on this branch, check if it's clean
|
|
68
|
+
if (branchRef === currentBranch) {
|
|
69
|
+
const status = await this.git.status();
|
|
70
|
+
const isClean = status.files.length === 0 &&
|
|
71
|
+
status.not_added.length === 0 &&
|
|
72
|
+
status.modified.length === 0;
|
|
73
|
+
if (isClean) {
|
|
74
|
+
// Branch exists and is clean - check if it's at base (main) commit
|
|
75
|
+
const mainCommit = await this.git.revparse([mainBranch]);
|
|
76
|
+
const branchCommit = await this.git.revparse([branchName]);
|
|
77
|
+
if (branchCommit === mainCommit) {
|
|
78
|
+
// Branch is at base commit - safe to reuse
|
|
79
|
+
console.warn(`[AutoFix] Branch ${branchName} already exists and is clean. Reusing it.`);
|
|
80
|
+
branchCreated = false;
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
// Branch has commits - create new unique branch
|
|
85
|
+
branchSuffix++;
|
|
86
|
+
branchName = `vibeguard/fix-${shortId}-${branchSuffix}`;
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
// Branch has uncommitted changes - create new unique branch
|
|
92
|
+
branchSuffix++;
|
|
93
|
+
branchName = `vibeguard/fix-${shortId}-${branchSuffix}`;
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
// Branch exists but we're not on it - check if it's at base commit
|
|
99
|
+
const mainCommit = await this.git.revparse([mainBranch]);
|
|
100
|
+
let branchCommit;
|
|
101
|
+
try {
|
|
102
|
+
branchCommit = await this.git.revparse([branchName]);
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
// Branch might not exist in current repo state, create it
|
|
106
|
+
await this.git.checkout(mainBranch);
|
|
107
|
+
await this.git.checkoutLocalBranch(branchName);
|
|
108
|
+
branchCreated = true;
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
// If branch is at the same commit as main, we can use it
|
|
112
|
+
if (branchCommit === mainCommit) {
|
|
113
|
+
await this.git.checkout(branchName);
|
|
114
|
+
branchCreated = false;
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
// Branch has diverged - create new unique branch
|
|
119
|
+
branchSuffix++;
|
|
120
|
+
branchName = `vibeguard/fix-${shortId}-${branchSuffix}`;
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
// Error checking branch state - try unique name
|
|
127
|
+
branchSuffix++;
|
|
128
|
+
branchName = `vibeguard/fix-${shortId}-${branchSuffix}`;
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
// If checkout fails for any reason, try unique name
|
|
135
|
+
if (error.message?.includes('already exists') || error.message?.includes('branch already exists')) {
|
|
136
|
+
branchSuffix++;
|
|
137
|
+
branchName = `vibeguard/fix-${shortId}-${branchSuffix}`;
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
throw error;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
// Step 4: Identify affected files using AI
|
|
144
|
+
const affectedFiles = await this.identifyAffectedFiles(prophecy);
|
|
145
|
+
if (affectedFiles.length === 0) {
|
|
146
|
+
// Switch back to original branch if no files found
|
|
147
|
+
const currentBranch = await this.git.revparse(['--abbrev-ref', 'HEAD']);
|
|
148
|
+
// Only clean up if we created a new branch (not reused existing)
|
|
149
|
+
if (branchCreated && (currentBranch === branchName || currentBranch.endsWith(`/${branchName}`))) {
|
|
150
|
+
await this.git.checkout(originalBranch);
|
|
151
|
+
// Only delete if branch has no commits
|
|
152
|
+
try {
|
|
153
|
+
const branchLog = await this.git.log([branchName, '--oneline']);
|
|
154
|
+
if (branchLog.total === 0) {
|
|
155
|
+
await this.git.branch(['-D', branchName]);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
159
|
+
// Branch might not have any log entries, try to delete anyway
|
|
160
|
+
try {
|
|
161
|
+
await this.git.branch(['-D', branchName]);
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
// Ignore deletion errors
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
else if (currentBranch === branchName || currentBranch.endsWith(`/${branchName}`)) {
|
|
169
|
+
// If we're on the branch but didn't create it, switch back
|
|
170
|
+
await this.git.checkout(originalBranch);
|
|
171
|
+
}
|
|
172
|
+
return {
|
|
173
|
+
success: false,
|
|
174
|
+
error: 'Could not identify files to fix. The prophecy may require manual intervention.',
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
// Step 5: Apply fixes using AI
|
|
178
|
+
const projectMemory = await this.readProjectMemory();
|
|
179
|
+
const filesChanged = [];
|
|
180
|
+
for (const filePath of affectedFiles) {
|
|
181
|
+
try {
|
|
182
|
+
const fullPath = path.join(this.repoPath, filePath);
|
|
183
|
+
const originalContent = await fs.readFile(fullPath, 'utf-8');
|
|
184
|
+
const fixedContent = await this.applyFixToFile(filePath, originalContent, prophecy, projectMemory);
|
|
185
|
+
if (fixedContent !== originalContent) {
|
|
186
|
+
// Write file atomically
|
|
187
|
+
await writeFileAtomic(fullPath, fixedContent, 'utf-8');
|
|
188
|
+
filesChanged.push(filePath);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
console.error(`[AutoFix] Failed to fix file ${filePath}:`, error.message);
|
|
193
|
+
// Continue with other files
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
if (filesChanged.length === 0) {
|
|
197
|
+
// No files were changed - clean up branch
|
|
198
|
+
const currentBranch = await this.git.revparse(['--abbrev-ref', 'HEAD']);
|
|
199
|
+
// Only clean up if we created a new branch (not reused existing)
|
|
200
|
+
if (branchCreated && (currentBranch === branchName || currentBranch.endsWith(`/${branchName}`))) {
|
|
201
|
+
await this.git.checkout(originalBranch);
|
|
202
|
+
// Only delete if branch has no commits
|
|
203
|
+
try {
|
|
204
|
+
const branchLog = await this.git.log([branchName, '--oneline']);
|
|
205
|
+
if (branchLog.total === 0) {
|
|
206
|
+
await this.git.branch(['-D', branchName]);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
catch {
|
|
210
|
+
// Branch might not have any log entries, try to delete anyway
|
|
211
|
+
try {
|
|
212
|
+
await this.git.branch(['-D', branchName]);
|
|
213
|
+
}
|
|
214
|
+
catch {
|
|
215
|
+
// Ignore deletion errors - branch might have commits
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
else if (currentBranch === branchName || currentBranch.endsWith(`/${branchName}`)) {
|
|
220
|
+
// If we're on the branch but didn't create it, switch back
|
|
221
|
+
await this.git.checkout(originalBranch);
|
|
222
|
+
}
|
|
223
|
+
return {
|
|
224
|
+
success: false,
|
|
225
|
+
error: 'No changes were made. The files may already be in the correct state or the fix could not be applied automatically.',
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
// Step 6: Stage and commit changes
|
|
229
|
+
await this.git.add('.');
|
|
230
|
+
await this.git.commit(`VibeGuard: ${prophecy.title}`);
|
|
231
|
+
return {
|
|
232
|
+
success: true,
|
|
233
|
+
branchName,
|
|
234
|
+
filesChanged,
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
catch (error) {
|
|
238
|
+
return {
|
|
239
|
+
success: false,
|
|
240
|
+
error: error.message || 'Failed to apply fix',
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Check if there are uncommitted changes in the working directory
|
|
246
|
+
*/
|
|
247
|
+
async checkUncommittedChanges() {
|
|
248
|
+
try {
|
|
249
|
+
const status = await this.git.status();
|
|
250
|
+
return (status.files.length > 0 ||
|
|
251
|
+
status.not_added.length > 0 ||
|
|
252
|
+
status.conflicted.length > 0 ||
|
|
253
|
+
status.created.length > 0 ||
|
|
254
|
+
status.deleted.length > 0 ||
|
|
255
|
+
status.modified.length > 0 ||
|
|
256
|
+
status.renamed.length > 0);
|
|
257
|
+
}
|
|
258
|
+
catch (error) {
|
|
259
|
+
// If status check fails, assume there are no uncommitted changes
|
|
260
|
+
return false;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Identify which files are affected by the prophecy using AI
|
|
265
|
+
*/
|
|
266
|
+
async identifyAffectedFiles(prophecy) {
|
|
267
|
+
const systemPrompt = `You are a code analyzer. Given a prophecy about architectural drift, identify the specific file paths that need to be modified to fix the issue.
|
|
268
|
+
|
|
269
|
+
Return your response as a JSON array of file paths (relative to the repository root). Only include files that directly need changes. If you cannot identify specific files, return an empty array.
|
|
270
|
+
|
|
271
|
+
Example response: ["src/components/App.tsx", "src/utils/helpers.ts"]`;
|
|
272
|
+
const userPrompt = `Prophecy:
|
|
273
|
+
Title: ${prophecy.title}
|
|
274
|
+
Type: ${prophecy.type}
|
|
275
|
+
Description: ${prophecy.description}
|
|
276
|
+
Suggested Action: ${prophecy.suggestedAction}
|
|
277
|
+
|
|
278
|
+
Analyze the above prophecy and identify which files need to be changed. Return only a JSON array of file paths.`;
|
|
279
|
+
try {
|
|
280
|
+
const response = await generateSummary(userPrompt, systemPrompt, {
|
|
281
|
+
thinkingLevel: 'pro',
|
|
282
|
+
maxTokens: 10000,
|
|
283
|
+
temperature: 0.3,
|
|
284
|
+
});
|
|
285
|
+
// Parse JSON array from response
|
|
286
|
+
let jsonText = response.trim();
|
|
287
|
+
const jsonMatch = jsonText.match(/```(?:json)?\s*([\s\S]*?)\s*```/);
|
|
288
|
+
if (jsonMatch) {
|
|
289
|
+
jsonText = jsonMatch[1];
|
|
290
|
+
}
|
|
291
|
+
const files = JSON.parse(jsonText);
|
|
292
|
+
if (Array.isArray(files)) {
|
|
293
|
+
// Filter to only include files that exist and are in src/
|
|
294
|
+
const validFiles = [];
|
|
295
|
+
for (const file of files) {
|
|
296
|
+
if (typeof file === 'string' && file.startsWith('src/')) {
|
|
297
|
+
const fullPath = path.join(this.repoPath, file);
|
|
298
|
+
try {
|
|
299
|
+
await fs.access(fullPath);
|
|
300
|
+
validFiles.push(file);
|
|
301
|
+
}
|
|
302
|
+
catch {
|
|
303
|
+
// File doesn't exist, skip it
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
return validFiles;
|
|
308
|
+
}
|
|
309
|
+
return [];
|
|
310
|
+
}
|
|
311
|
+
catch (error) {
|
|
312
|
+
console.error('[AutoFix] Failed to identify affected files:', error);
|
|
313
|
+
return [];
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Apply a fix to a specific file using AI
|
|
318
|
+
*/
|
|
319
|
+
async applyFixToFile(filePath, fileContent, prophecy, projectMemory) {
|
|
320
|
+
const systemPrompt = `You are an expert refactoring engine. Apply the following fix to the provided code to align it with the Project Soul. Return the full updated file content. No conversation, no explanations, just the complete corrected file.`;
|
|
321
|
+
const userPrompt = `Project Memory (Context):
|
|
322
|
+
${projectMemory}
|
|
323
|
+
|
|
324
|
+
Prophecy:
|
|
325
|
+
Title: ${prophecy.title}
|
|
326
|
+
Type: ${prophecy.type}
|
|
327
|
+
Description: ${prophecy.description}
|
|
328
|
+
Suggested Action: ${prophecy.suggestedAction}
|
|
329
|
+
|
|
330
|
+
File to fix: ${filePath}
|
|
331
|
+
|
|
332
|
+
Current file content:
|
|
333
|
+
\`\`\`
|
|
334
|
+
${fileContent}
|
|
335
|
+
\`\`\`
|
|
336
|
+
|
|
337
|
+
Apply the suggested fix to this file. Return the complete updated file content with all changes applied. Do not add comments explaining the changes.`;
|
|
338
|
+
try {
|
|
339
|
+
const response = await generateSummary(userPrompt, systemPrompt, {
|
|
340
|
+
thinkingLevel: 'pro',
|
|
341
|
+
maxTokens: 10000,
|
|
342
|
+
temperature: 0.2,
|
|
343
|
+
});
|
|
344
|
+
// Extract code from markdown code blocks if present
|
|
345
|
+
let code = response.trim();
|
|
346
|
+
const codeMatch = code.match(/```(?:\w+)?\s*([\s\S]*?)\s*```/);
|
|
347
|
+
if (codeMatch) {
|
|
348
|
+
code = codeMatch[1];
|
|
349
|
+
}
|
|
350
|
+
return code;
|
|
351
|
+
}
|
|
352
|
+
catch (error) {
|
|
353
|
+
throw new Error(`Failed to apply fix to ${filePath}: ${error.message}`);
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* Read PROJECT_MEMORY.md for context
|
|
358
|
+
*/
|
|
359
|
+
async readProjectMemory() {
|
|
360
|
+
const memoryPath = path.join(this.repoPath, 'PROJECT_MEMORY.md');
|
|
361
|
+
try {
|
|
362
|
+
return await fs.readFile(memoryPath, 'utf-8');
|
|
363
|
+
}
|
|
364
|
+
catch (error) {
|
|
365
|
+
return '';
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
//# sourceMappingURL=autofix.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"autofix.js","sourceRoot":"","sources":["../../src/librarian/autofix.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAY,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAa,MAAM,YAAY,CAAC;AASlD,MAAM,OAAO,cAAc;IACjB,QAAQ,CAAS;IACjB,QAAQ,CAAW;IACnB,aAAa,CAAgB;IAC7B,GAAG,CAAY;IAEvB,YAAY,WAAmB,OAAO,CAAC,GAAG,EAAE;QAC1C,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,QAAQ,GAAG,IAAI,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACvC,IAAI,CAAC,aAAa,GAAG,IAAI,aAAa,CAAC,QAAQ,CAAC,CAAC;QACjD,IAAI,CAAC,GAAG,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;IACjC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,QAAQ,CAAC,UAAkB;QAC/B,IAAI,CAAC;YACH,4BAA4B;YAC5B,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,aAAa,EAAE,CA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AC,IAAI,CAAC,QAAQ,EAAE,mBAAmB,CAAC,CAAC;QACjE,IAAI,CAAC;YACH,OAAO,MAAM,EAAE,CAAC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QAChD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { OracleService } from './oracle.js';
|
|
2
|
+
export declare class Heartbeat {
|
|
3
|
+
private oracle;
|
|
4
|
+
private inactivityTimer;
|
|
5
|
+
private lastActivityTime;
|
|
6
|
+
private quietReflectionInterval;
|
|
7
|
+
private isEnabled;
|
|
8
|
+
constructor(oracle: OracleService);
|
|
9
|
+
/**
|
|
10
|
+
* Record activity (called when commits or other activity happens)
|
|
11
|
+
*/
|
|
12
|
+
recordActivity(): void;
|
|
13
|
+
/**
|
|
14
|
+
* Schedule quiet reflection after inactivity period
|
|
15
|
+
*/
|
|
16
|
+
private scheduleQuietReflection;
|
|
17
|
+
/**
|
|
18
|
+
* Perform quiet reflection - trigger oracle to seek prophecy
|
|
19
|
+
*/
|
|
20
|
+
private performQuietReflection;
|
|
21
|
+
/**
|
|
22
|
+
* Start the heartbeat (enables quiet reflection)
|
|
23
|
+
*/
|
|
24
|
+
start(): void;
|
|
25
|
+
/**
|
|
26
|
+
* Stop the heartbeat
|
|
27
|
+
*/
|
|
28
|
+
stop(): void;
|
|
29
|
+
/**
|
|
30
|
+
* Get time since last activity (in milliseconds)
|
|
31
|
+
*/
|
|
32
|
+
getTimeSinceLastActivity(): number;
|
|
33
|
+
/**
|
|
34
|
+
* Check if quiet reflection is due
|
|
35
|
+
*/
|
|
36
|
+
isQuietReflectionDue(): boolean;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=heartbeat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"heartbeat.d.ts","sourceRoot":"","sources":["../../src/librarian/heartbeat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,qBAAa,SAAS;IACpB,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,eAAe,CAA+B;IACtD,OAAO,CAAC,gBAAgB,CAAsB;IAC9C,OAAO,CAAC,uBAAuB,CAA0B;IACzD,OAAO,CAAC,SAAS,CAAkB;gBAEvB,MAAM,EAAE,aAAa;IAIjC;;OAEG;IACH,cAAc,IAAI,IAAI;IAetB;;OAEG;IACH,OAAO,CAAC,uBAAuB;IAc/B;;OAEG;YACW,sBAAsB;IAsBpC;;OAEG;IACH,KAAK,IAAI,IAAI;IAWb;;OAEG;IACH,IAAI,IAAI,IAAI;IAWZ;;OAEG;IACH,wBAAwB,IAAI,MAAM;IAIlC;;OAEG;IACH,oBAAoB,IAAI,OAAO;CAGhC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
export class Heartbeat {
|
|
2
|
+
oracle;
|
|
3
|
+
inactivityTimer = null;
|
|
4
|
+
lastActivityTime = Date.now();
|
|
5
|
+
quietReflectionInterval = 10 * 60 * 1000; // 10 minutes
|
|
6
|
+
isEnabled = false;
|
|
7
|
+
constructor(oracle) {
|
|
8
|
+
this.oracle = oracle;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Record activity (called when commits or other activity happens)
|
|
12
|
+
*/
|
|
13
|
+
recordActivity() {
|
|
14
|
+
this.lastActivityTime = Date.now();
|
|
15
|
+
// Reset the inactivity timer
|
|
16
|
+
if (this.inactivityTimer) {
|
|
17
|
+
clearTimeout(this.inactivityTimer);
|
|
18
|
+
this.inactivityTimer = null;
|
|
19
|
+
}
|
|
20
|
+
// If enabled, restart the timer
|
|
21
|
+
if (this.isEnabled) {
|
|
22
|
+
this.scheduleQuietReflection();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Schedule quiet reflection after inactivity period
|
|
27
|
+
*/
|
|
28
|
+
scheduleQuietReflection() {
|
|
29
|
+
// Clear any existing timer
|
|
30
|
+
if (this.inactivityTimer) {
|
|
31
|
+
clearTimeout(this.inactivityTimer);
|
|
32
|
+
}
|
|
33
|
+
// Schedule quiet reflection after 10 minutes of inactivity
|
|
34
|
+
this.inactivityTimer = setTimeout(() => {
|
|
35
|
+
this.performQuietReflection().catch(error => {
|
|
36
|
+
console.error('[Heartbeat] Error during quiet reflection:', error);
|
|
37
|
+
});
|
|
38
|
+
}, this.quietReflectionInterval);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Perform quiet reflection - trigger oracle to seek prophecy
|
|
42
|
+
*/
|
|
43
|
+
async performQuietReflection() {
|
|
44
|
+
const now = Date.now();
|
|
45
|
+
const timeSinceActivity = now - this.lastActivityTime;
|
|
46
|
+
// Only perform if we've been inactive for at least the quiet reflection interval
|
|
47
|
+
if (timeSinceActivity >= this.quietReflectionInterval) {
|
|
48
|
+
console.log('[Heartbeat] Performing Quiet Reflection (10 minutes of inactivity)...');
|
|
49
|
+
try {
|
|
50
|
+
await this.oracle.seekProphecy();
|
|
51
|
+
console.log('[Heartbeat] Quiet Reflection complete');
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
console.error('[Heartbeat] Error during quiet reflection:', error);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
// Schedule next quiet reflection if still enabled
|
|
58
|
+
if (this.isEnabled) {
|
|
59
|
+
this.scheduleQuietReflection();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Start the heartbeat (enables quiet reflection)
|
|
64
|
+
*/
|
|
65
|
+
start() {
|
|
66
|
+
if (this.isEnabled) {
|
|
67
|
+
return; // Already started
|
|
68
|
+
}
|
|
69
|
+
this.isEnabled = true;
|
|
70
|
+
this.lastActivityTime = Date.now();
|
|
71
|
+
this.scheduleQuietReflection();
|
|
72
|
+
console.log('[Heartbeat] Started - Quiet Reflection enabled (10 min inactivity)');
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Stop the heartbeat
|
|
76
|
+
*/
|
|
77
|
+
stop() {
|
|
78
|
+
this.isEnabled = false;
|
|
79
|
+
if (this.inactivityTimer) {
|
|
80
|
+
clearTimeout(this.inactivityTimer);
|
|
81
|
+
this.inactivityTimer = null;
|
|
82
|
+
}
|
|
83
|
+
console.log('[Heartbeat] Stopped');
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Get time since last activity (in milliseconds)
|
|
87
|
+
*/
|
|
88
|
+
getTimeSinceLastActivity() {
|
|
89
|
+
return Date.now() - this.lastActivityTime;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Check if quiet reflection is due
|
|
93
|
+
*/
|
|
94
|
+
isQuietReflectionDue() {
|
|
95
|
+
return this.getTimeSinceLastActivity() >= this.quietReflectionInterval;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=heartbeat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"heartbeat.js","sourceRoot":"","sources":["../../src/librarian/heartbeat.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,SAAS;IACZ,MAAM,CAAgB;IACtB,eAAe,GAA0B,IAAI,CAAC;IAC9C,gBAAgB,GAAW,IAAI,CAAC,GAAG,EAAE,CAAC;IACtC,uBAAuB,GAAW,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,aAAa;IAC/D,SAAS,GAAY,KAAK,CAAC;IAEnC,YAAY,MAAqB;QAC/B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,cAAc;QACZ,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAEnC,6BAA6B;QAC7B,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;YACzB,YAAY,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;Y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jC,CAAC;IACH,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACnB,OAAO,CAAC,kBAAkB;QAC5B,CAAC;QAED,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACtB,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACnC,IAAI,CAAC,uBAAuB,EAAE,CAAC;QAC/B,OAAO,CAAC,GAAG,CAAC,oEAAoE,CAAC,CAAC;IACpF,CAAC;IAED;;OAEG;IACH,IAAI;QACF,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;QAEvB,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;YACzB,YAAY,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;YACnC,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;QAC9B,CAAC;QAED,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;IACrC,CAAC;IAED;;OAEG;IACH,wBAAwB;QACtB,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,gBAAgB,CAAC;IAC5C,CAAC;IAED;;OAEG;IACH,oBAAoB;QAClB,OAAO,IAAI,CAAC,wBAAwB,EAAE,IAAI,IAAI,CAAC,uBAAuB,CAAC;IACzE,CAAC;CACF"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export interface MilestoneCommit {
|
|
2
|
+
hash: string;
|
|
3
|
+
message: string;
|
|
4
|
+
date: string;
|
|
5
|
+
type: 'tag' | 'merge' | 'keyword' | 'other';
|
|
6
|
+
}
|
|
7
|
+
export interface MilestoneTimeline {
|
|
8
|
+
milestones: MilestoneCommit[];
|
|
9
|
+
totalCommits: number;
|
|
10
|
+
}
|
|
11
|
+
export declare class Initializer {
|
|
12
|
+
private repoPath;
|
|
13
|
+
private gitUtils;
|
|
14
|
+
private summarizer;
|
|
15
|
+
private memoryManager;
|
|
16
|
+
constructor(repoPath?: string);
|
|
17
|
+
/**
|
|
18
|
+
* Ensure PROJECT_MEMORY.md is tracked in Git
|
|
19
|
+
*/
|
|
20
|
+
ensureMemoryTrackedInGit(): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Tier 1: Oneline Sweep (0 tokens)
|
|
23
|
+
* Parse git log locally to identify milestone commits
|
|
24
|
+
*/
|
|
25
|
+
tier1OnelineSweep(): Promise<MilestoneTimeline>;
|
|
26
|
+
/**
|
|
27
|
+
* Tier 2: Deep Context (Mid-cost)
|
|
28
|
+
* Process last 5-10 commits with Gemini
|
|
29
|
+
*/
|
|
30
|
+
tier2DeepContext(): Promise<string>;
|
|
31
|
+
/**
|
|
32
|
+
* Tier 3: Skeleton Scan (High value)
|
|
33
|
+
* Infer architecture from file structure and README
|
|
34
|
+
*/
|
|
35
|
+
tier3SkeletonScan(): Promise<string>;
|
|
36
|
+
/**
|
|
37
|
+
* Main initialization orchestrator
|
|
38
|
+
*/
|
|
39
|
+
initialize(): Promise<void>;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=initializer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initializer.d.ts","sourceRoot":"","sources":["../../src/librarian/initializer.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,KAAK,GAAG,OAAO,GAAG,SAAS,GAAG,OAAO,CAAC;CAC7C;AAED,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,eAAe,EAAE,CAAC;IAC9B,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,QAAQ,CAAW;IAC3B,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,aAAa,CAAgB;gBAEzB,QAAQ,GAAE,MAAsB;IAO5C;;OAEG;IACG,wBAAwB,IAAI,OAAO,CAAC,IAAI,CAAC;IAiB/C;;;OAGG;IACG,iBAAiB,IAAI,OAAO,CAAC,iBAAiB,CAAC;IAoFrD;;;OAGG;IACG,gBAAgB,IAAI,OAAO,CAAC,MAAM,CAAC;IAmCzC;;;OAGG;IACG,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC;IAmB1C;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;CAmDlC"}
|