grok-cli-hurry-mode 1.0.30 → 1.0.32
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/dist/index.js +290 -192
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import * as
|
|
3
|
-
import { existsSync } from 'fs';
|
|
2
|
+
import * as fs from 'fs';
|
|
3
|
+
import fs__default, { existsSync } from 'fs';
|
|
4
4
|
import * as path7 from 'path';
|
|
5
5
|
import path7__default from 'path';
|
|
6
6
|
import * as os from 'os';
|
|
@@ -16,6 +16,7 @@ import axios from 'axios';
|
|
|
16
16
|
import { exec, execSync, spawn } from 'child_process';
|
|
17
17
|
import { promisify } from 'util';
|
|
18
18
|
import { writeFile } from 'fs/promises';
|
|
19
|
+
import * as ops6 from 'fs-extra';
|
|
19
20
|
import { parse } from '@typescript-eslint/typescript-estree';
|
|
20
21
|
import Fuse from 'fuse.js';
|
|
21
22
|
import { glob } from 'glob';
|
|
@@ -90,8 +91,8 @@ var init_settings_manager = __esm({
|
|
|
90
91
|
*/
|
|
91
92
|
ensureDirectoryExists(filePath) {
|
|
92
93
|
const dir = path7.dirname(filePath);
|
|
93
|
-
if (!
|
|
94
|
-
|
|
94
|
+
if (!fs.existsSync(dir)) {
|
|
95
|
+
fs.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
95
96
|
}
|
|
96
97
|
}
|
|
97
98
|
/**
|
|
@@ -99,11 +100,11 @@ var init_settings_manager = __esm({
|
|
|
99
100
|
*/
|
|
100
101
|
loadUserSettings() {
|
|
101
102
|
try {
|
|
102
|
-
if (!
|
|
103
|
+
if (!fs.existsSync(this.userSettingsPath)) {
|
|
103
104
|
this.saveUserSettings(DEFAULT_USER_SETTINGS);
|
|
104
105
|
return { ...DEFAULT_USER_SETTINGS };
|
|
105
106
|
}
|
|
106
|
-
const content =
|
|
107
|
+
const content = fs.readFileSync(this.userSettingsPath, "utf-8");
|
|
107
108
|
const settings = JSON.parse(content);
|
|
108
109
|
return { ...DEFAULT_USER_SETTINGS, ...settings };
|
|
109
110
|
} catch (error) {
|
|
@@ -121,9 +122,9 @@ var init_settings_manager = __esm({
|
|
|
121
122
|
try {
|
|
122
123
|
this.ensureDirectoryExists(this.userSettingsPath);
|
|
123
124
|
let existingSettings = { ...DEFAULT_USER_SETTINGS };
|
|
124
|
-
if (
|
|
125
|
+
if (fs.existsSync(this.userSettingsPath)) {
|
|
125
126
|
try {
|
|
126
|
-
const content =
|
|
127
|
+
const content = fs.readFileSync(this.userSettingsPath, "utf-8");
|
|
127
128
|
const parsed = JSON.parse(content);
|
|
128
129
|
existingSettings = { ...DEFAULT_USER_SETTINGS, ...parsed };
|
|
129
130
|
} catch (error) {
|
|
@@ -131,7 +132,7 @@ var init_settings_manager = __esm({
|
|
|
131
132
|
}
|
|
132
133
|
}
|
|
133
134
|
const mergedSettings = { ...existingSettings, ...settings };
|
|
134
|
-
|
|
135
|
+
fs.writeFileSync(
|
|
135
136
|
this.userSettingsPath,
|
|
136
137
|
JSON.stringify(mergedSettings, null, 2),
|
|
137
138
|
{ mode: 384 }
|
|
@@ -164,11 +165,11 @@ var init_settings_manager = __esm({
|
|
|
164
165
|
*/
|
|
165
166
|
loadProjectSettings() {
|
|
166
167
|
try {
|
|
167
|
-
if (!
|
|
168
|
+
if (!fs.existsSync(this.projectSettingsPath)) {
|
|
168
169
|
this.saveProjectSettings(DEFAULT_PROJECT_SETTINGS);
|
|
169
170
|
return { ...DEFAULT_PROJECT_SETTINGS };
|
|
170
171
|
}
|
|
171
|
-
const content =
|
|
172
|
+
const content = fs.readFileSync(this.projectSettingsPath, "utf-8");
|
|
172
173
|
const settings = JSON.parse(content);
|
|
173
174
|
return { ...DEFAULT_PROJECT_SETTINGS, ...settings };
|
|
174
175
|
} catch (error) {
|
|
@@ -186,9 +187,9 @@ var init_settings_manager = __esm({
|
|
|
186
187
|
try {
|
|
187
188
|
this.ensureDirectoryExists(this.projectSettingsPath);
|
|
188
189
|
let existingSettings = { ...DEFAULT_PROJECT_SETTINGS };
|
|
189
|
-
if (
|
|
190
|
+
if (fs.existsSync(this.projectSettingsPath)) {
|
|
190
191
|
try {
|
|
191
|
-
const content =
|
|
192
|
+
const content = fs.readFileSync(this.projectSettingsPath, "utf-8");
|
|
192
193
|
const parsed = JSON.parse(content);
|
|
193
194
|
existingSettings = { ...DEFAULT_PROJECT_SETTINGS, ...parsed };
|
|
194
195
|
} catch (error) {
|
|
@@ -196,7 +197,7 @@ var init_settings_manager = __esm({
|
|
|
196
197
|
}
|
|
197
198
|
}
|
|
198
199
|
const mergedSettings = { ...existingSettings, ...settings };
|
|
199
|
-
|
|
200
|
+
fs.writeFileSync(
|
|
200
201
|
this.projectSettingsPath,
|
|
201
202
|
JSON.stringify(mergedSettings, null, 2)
|
|
202
203
|
);
|
|
@@ -1469,7 +1470,7 @@ STDERR: ${stderr}` : "");
|
|
|
1469
1470
|
};
|
|
1470
1471
|
var pathExists = async (filePath) => {
|
|
1471
1472
|
try {
|
|
1472
|
-
await
|
|
1473
|
+
await fs.promises.access(filePath, fs.constants.F_OK);
|
|
1473
1474
|
return true;
|
|
1474
1475
|
} catch {
|
|
1475
1476
|
return false;
|
|
@@ -1482,16 +1483,16 @@ var TextEditorTool = class {
|
|
|
1482
1483
|
try {
|
|
1483
1484
|
const resolvedPath = path7.resolve(filePath);
|
|
1484
1485
|
if (await pathExists(resolvedPath)) {
|
|
1485
|
-
const stats = await
|
|
1486
|
+
const stats = await fs.promises.stat(resolvedPath);
|
|
1486
1487
|
if (stats.isDirectory()) {
|
|
1487
|
-
const files = await
|
|
1488
|
+
const files = await fs.promises.readdir(resolvedPath);
|
|
1488
1489
|
return {
|
|
1489
1490
|
success: true,
|
|
1490
1491
|
output: `Directory contents of ${filePath}:
|
|
1491
1492
|
${files.join("\n")}`
|
|
1492
1493
|
};
|
|
1493
1494
|
}
|
|
1494
|
-
const content = await
|
|
1495
|
+
const content = await fs.promises.readFile(resolvedPath, "utf-8");
|
|
1495
1496
|
const lines = content.split("\n");
|
|
1496
1497
|
if (viewRange) {
|
|
1497
1498
|
const [start, end] = viewRange;
|
|
@@ -1541,7 +1542,7 @@ ${numberedLines}${additionalLinesMessage}`
|
|
|
1541
1542
|
error: `File not found: ${filePath}`
|
|
1542
1543
|
};
|
|
1543
1544
|
}
|
|
1544
|
-
const content = await
|
|
1545
|
+
const content = await fs.promises.readFile(resolvedPath, "utf-8");
|
|
1545
1546
|
if (!content.includes(oldStr)) {
|
|
1546
1547
|
if (oldStr.includes("\n")) {
|
|
1547
1548
|
const fuzzyResult = this.findFuzzyMatch(content, oldStr);
|
|
@@ -1641,7 +1642,7 @@ ${numberedLines}${additionalLinesMessage}`
|
|
|
1641
1642
|
}
|
|
1642
1643
|
}
|
|
1643
1644
|
const dir = path7.dirname(resolvedPath);
|
|
1644
|
-
await
|
|
1645
|
+
await fs.promises.mkdir(dir, { recursive: true });
|
|
1645
1646
|
await writeFile(resolvedPath, content, "utf-8");
|
|
1646
1647
|
this.editHistory.push({
|
|
1647
1648
|
command: "create",
|
|
@@ -1671,7 +1672,7 @@ ${numberedLines}${additionalLinesMessage}`
|
|
|
1671
1672
|
error: `File not found: ${filePath}`
|
|
1672
1673
|
};
|
|
1673
1674
|
}
|
|
1674
|
-
const fileContent = await
|
|
1675
|
+
const fileContent = await fs.promises.readFile(resolvedPath, "utf-8");
|
|
1675
1676
|
const lines = fileContent.split("\n");
|
|
1676
1677
|
if (startLine < 1 || startLine > lines.length) {
|
|
1677
1678
|
return {
|
|
@@ -1739,7 +1740,7 @@ ${numberedLines}${additionalLinesMessage}`
|
|
|
1739
1740
|
error: `File not found: ${filePath}`
|
|
1740
1741
|
};
|
|
1741
1742
|
}
|
|
1742
|
-
const fileContent = await
|
|
1743
|
+
const fileContent = await fs.promises.readFile(resolvedPath, "utf-8");
|
|
1743
1744
|
const lines = fileContent.split("\n");
|
|
1744
1745
|
lines.splice(insertLine - 1, 0, content);
|
|
1745
1746
|
const newContent = lines.join("\n");
|
|
@@ -1773,7 +1774,7 @@ ${numberedLines}${additionalLinesMessage}`
|
|
|
1773
1774
|
switch (lastEdit.command) {
|
|
1774
1775
|
case "str_replace":
|
|
1775
1776
|
if (lastEdit.path && lastEdit.old_str && lastEdit.new_str) {
|
|
1776
|
-
const content = await
|
|
1777
|
+
const content = await fs.promises.readFile(lastEdit.path, "utf-8");
|
|
1777
1778
|
const revertedContent = content.replace(
|
|
1778
1779
|
lastEdit.new_str,
|
|
1779
1780
|
lastEdit.old_str
|
|
@@ -1783,12 +1784,12 @@ ${numberedLines}${additionalLinesMessage}`
|
|
|
1783
1784
|
break;
|
|
1784
1785
|
case "create":
|
|
1785
1786
|
if (lastEdit.path) {
|
|
1786
|
-
await
|
|
1787
|
+
await fs.promises.rm(lastEdit.path);
|
|
1787
1788
|
}
|
|
1788
1789
|
break;
|
|
1789
1790
|
case "insert":
|
|
1790
1791
|
if (lastEdit.path && lastEdit.insert_line) {
|
|
1791
|
-
const content = await
|
|
1792
|
+
const content = await fs.promises.readFile(lastEdit.path, "utf-8");
|
|
1792
1793
|
const lines = content.split("\n");
|
|
1793
1794
|
lines.splice(lastEdit.insert_line - 1, 1);
|
|
1794
1795
|
await writeFile(lastEdit.path, lines.join("\n"), "utf-8");
|
|
@@ -1988,7 +1989,7 @@ ${numberedLines}${additionalLinesMessage}`
|
|
|
1988
1989
|
};
|
|
1989
1990
|
var pathExists2 = async (filePath) => {
|
|
1990
1991
|
try {
|
|
1991
|
-
await
|
|
1992
|
+
await fs.promises.access(filePath, fs.constants.F_OK);
|
|
1992
1993
|
return true;
|
|
1993
1994
|
} catch {
|
|
1994
1995
|
return false;
|
|
@@ -2042,7 +2043,7 @@ var MorphEditorTool = class {
|
|
|
2042
2043
|
error: "MORPH_API_KEY not configured. Please set your Morph API key."
|
|
2043
2044
|
};
|
|
2044
2045
|
}
|
|
2045
|
-
const initialCode = await
|
|
2046
|
+
const initialCode = await fs.promises.readFile(resolvedPath, "utf-8");
|
|
2046
2047
|
const sessionFlags = this.confirmationService.getSessionFlags();
|
|
2047
2048
|
if (!sessionFlags.fileOperations && !sessionFlags.allOperations) {
|
|
2048
2049
|
const confirmationResult = await this.confirmationService.requestConfirmation(
|
|
@@ -2065,7 +2066,7 @@ ${codeEdit}`
|
|
|
2065
2066
|
}
|
|
2066
2067
|
}
|
|
2067
2068
|
const mergedCode = await this.callMorphApply(instructions, initialCode, codeEdit);
|
|
2068
|
-
await
|
|
2069
|
+
await fs.promises.writeFile(resolvedPath, mergedCode, "utf-8");
|
|
2069
2070
|
const oldLines = initialCode.split("\n");
|
|
2070
2071
|
const newLines = mergedCode.split("\n");
|
|
2071
2072
|
const diff = this.generateDiff(oldLines, newLines, targetFile);
|
|
@@ -2239,16 +2240,16 @@ ${codeEdit}`
|
|
|
2239
2240
|
try {
|
|
2240
2241
|
const resolvedPath = path7.resolve(filePath);
|
|
2241
2242
|
if (await pathExists2(resolvedPath)) {
|
|
2242
|
-
const stats = await
|
|
2243
|
+
const stats = await fs.promises.stat(resolvedPath);
|
|
2243
2244
|
if (stats.isDirectory()) {
|
|
2244
|
-
const files = await
|
|
2245
|
+
const files = await fs.promises.readdir(resolvedPath);
|
|
2245
2246
|
return {
|
|
2246
2247
|
success: true,
|
|
2247
2248
|
output: `Directory contents of ${filePath}:
|
|
2248
2249
|
${files.join("\n")}`
|
|
2249
2250
|
};
|
|
2250
2251
|
}
|
|
2251
|
-
const content = await
|
|
2252
|
+
const content = await fs.promises.readFile(resolvedPath, "utf-8");
|
|
2252
2253
|
const lines = content.split("\n");
|
|
2253
2254
|
if (viewRange) {
|
|
2254
2255
|
const [start, end] = viewRange;
|
|
@@ -2656,7 +2657,7 @@ var SearchTool = class {
|
|
|
2656
2657
|
const walkDir = async (dir, depth = 0) => {
|
|
2657
2658
|
if (depth > 10 || files.length >= maxResults) return;
|
|
2658
2659
|
try {
|
|
2659
|
-
const entries = await
|
|
2660
|
+
const entries = await fs.promises.readdir(dir, { withFileTypes: true });
|
|
2660
2661
|
for (const entry of entries) {
|
|
2661
2662
|
if (files.length >= maxResults) break;
|
|
2662
2663
|
const fullPath = path7.join(dir, entry.name);
|
|
@@ -2770,7 +2771,7 @@ var SearchTool = class {
|
|
|
2770
2771
|
};
|
|
2771
2772
|
var pathExists3 = async (filePath) => {
|
|
2772
2773
|
try {
|
|
2773
|
-
await
|
|
2774
|
+
await ops6.promises.access(filePath, ops6.constants.F_OK);
|
|
2774
2775
|
return true;
|
|
2775
2776
|
} catch {
|
|
2776
2777
|
return false;
|
|
@@ -3125,15 +3126,15 @@ ${results.join("\n")}`
|
|
|
3125
3126
|
filePath: operation.filePath
|
|
3126
3127
|
};
|
|
3127
3128
|
case "edit":
|
|
3128
|
-
const originalContent = await
|
|
3129
|
+
const originalContent = await ops6.promises.readFile(resolvedPath, "utf-8");
|
|
3129
3130
|
return {
|
|
3130
3131
|
type: "restore_content",
|
|
3131
3132
|
filePath: operation.filePath,
|
|
3132
3133
|
originalContent
|
|
3133
3134
|
};
|
|
3134
3135
|
case "delete":
|
|
3135
|
-
const contentToRestore = await
|
|
3136
|
-
const stats = await
|
|
3136
|
+
const contentToRestore = await ops6.promises.readFile(resolvedPath, "utf-8");
|
|
3137
|
+
const stats = await ops6.promises.stat(resolvedPath);
|
|
3137
3138
|
return {
|
|
3138
3139
|
type: "restore_deleted",
|
|
3139
3140
|
filePath: operation.filePath,
|
|
@@ -3159,25 +3160,25 @@ ${results.join("\n")}`
|
|
|
3159
3160
|
switch (operation.type) {
|
|
3160
3161
|
case "create":
|
|
3161
3162
|
const dir = path7.dirname(resolvedPath);
|
|
3162
|
-
await
|
|
3163
|
+
await ops6.promises.mkdir(dir, { recursive: true });
|
|
3163
3164
|
await writeFile(resolvedPath, operation.content, "utf-8");
|
|
3164
3165
|
return { success: true, output: `Created ${operation.filePath}` };
|
|
3165
3166
|
case "edit":
|
|
3166
|
-
let content = await
|
|
3167
|
+
let content = await ops6.promises.readFile(resolvedPath, "utf-8");
|
|
3167
3168
|
for (const editOp of operation.operations) {
|
|
3168
3169
|
content = await this.applyEditOperation(content, editOp);
|
|
3169
3170
|
}
|
|
3170
3171
|
await writeFile(resolvedPath, content, "utf-8");
|
|
3171
3172
|
return { success: true, output: `Edited ${operation.filePath}` };
|
|
3172
3173
|
case "delete":
|
|
3173
|
-
await
|
|
3174
|
+
await ops6.promises.rm(resolvedPath);
|
|
3174
3175
|
return { success: true, output: `Deleted ${operation.filePath}` };
|
|
3175
3176
|
case "rename":
|
|
3176
3177
|
case "move":
|
|
3177
3178
|
const newResolvedPath = path7.resolve(operation.newFilePath);
|
|
3178
3179
|
const newDir = path7.dirname(newResolvedPath);
|
|
3179
|
-
await
|
|
3180
|
-
await
|
|
3180
|
+
await ops6.promises.mkdir(newDir, { recursive: true });
|
|
3181
|
+
await ops6.move(resolvedPath, newResolvedPath);
|
|
3181
3182
|
return { success: true, output: `${operation.type === "rename" ? "Renamed" : "Moved"} ${operation.filePath} to ${operation.newFilePath}` };
|
|
3182
3183
|
default:
|
|
3183
3184
|
throw new Error(`Unknown operation type: ${operation.type}`);
|
|
@@ -3221,7 +3222,7 @@ ${results.join("\n")}`
|
|
|
3221
3222
|
case "delete_created":
|
|
3222
3223
|
const createdPath = path7.resolve(rollback.filePath);
|
|
3223
3224
|
if (await pathExists3(createdPath)) {
|
|
3224
|
-
await
|
|
3225
|
+
await ops6.promises.rm(createdPath);
|
|
3225
3226
|
}
|
|
3226
3227
|
break;
|
|
3227
3228
|
case "restore_content":
|
|
@@ -3231,7 +3232,7 @@ ${results.join("\n")}`
|
|
|
3231
3232
|
case "restore_deleted":
|
|
3232
3233
|
const deletedPath = path7.resolve(rollback.filePath);
|
|
3233
3234
|
const deletedDir = path7.dirname(deletedPath);
|
|
3234
|
-
await
|
|
3235
|
+
await ops6.promises.mkdir(deletedDir, { recursive: true });
|
|
3235
3236
|
await writeFile(deletedPath, rollback.content, "utf-8");
|
|
3236
3237
|
break;
|
|
3237
3238
|
case "restore_move":
|
|
@@ -3239,8 +3240,8 @@ ${results.join("\n")}`
|
|
|
3239
3240
|
const movedOldPath = path7.resolve(rollback.oldPath);
|
|
3240
3241
|
if (await pathExists3(movedNewPath)) {
|
|
3241
3242
|
const oldDir = path7.dirname(movedOldPath);
|
|
3242
|
-
await
|
|
3243
|
-
await
|
|
3243
|
+
await ops6.promises.mkdir(oldDir, { recursive: true });
|
|
3244
|
+
await ops6.move(movedNewPath, movedOldPath);
|
|
3244
3245
|
}
|
|
3245
3246
|
break;
|
|
3246
3247
|
}
|
|
@@ -3282,7 +3283,7 @@ ${results.join("\n")}`
|
|
|
3282
3283
|
};
|
|
3283
3284
|
var pathExists4 = async (filePath) => {
|
|
3284
3285
|
try {
|
|
3285
|
-
await
|
|
3286
|
+
await fs.promises.access(filePath, fs.constants.F_OK);
|
|
3286
3287
|
return true;
|
|
3287
3288
|
} catch {
|
|
3288
3289
|
return false;
|
|
@@ -3302,7 +3303,7 @@ var AdvancedSearchTool = class {
|
|
|
3302
3303
|
error: `Path not found: ${searchPath}`
|
|
3303
3304
|
};
|
|
3304
3305
|
}
|
|
3305
|
-
const stats = await
|
|
3306
|
+
const stats = await fs.promises.stat(resolvedPath);
|
|
3306
3307
|
const filesToSearch = [];
|
|
3307
3308
|
if (stats.isFile()) {
|
|
3308
3309
|
filesToSearch.push(resolvedPath);
|
|
@@ -3345,7 +3346,7 @@ var AdvancedSearchTool = class {
|
|
|
3345
3346
|
error: `Path not found: ${searchPath}`
|
|
3346
3347
|
};
|
|
3347
3348
|
}
|
|
3348
|
-
const stats = await
|
|
3349
|
+
const stats = await fs.promises.stat(resolvedPath);
|
|
3349
3350
|
const filesToProcess = [];
|
|
3350
3351
|
if (stats.isFile()) {
|
|
3351
3352
|
filesToProcess.push(resolvedPath);
|
|
@@ -3390,7 +3391,7 @@ var AdvancedSearchTool = class {
|
|
|
3390
3391
|
}
|
|
3391
3392
|
for (const result of results) {
|
|
3392
3393
|
if (result.success && result.preview) {
|
|
3393
|
-
await
|
|
3394
|
+
await fs.promises.writeFile(result.filePath, result.preview, "utf-8");
|
|
3394
3395
|
}
|
|
3395
3396
|
}
|
|
3396
3397
|
}
|
|
@@ -3452,7 +3453,7 @@ ${matchingFiles.join("\n")}` : "No matching files found"
|
|
|
3452
3453
|
* Search in a single file
|
|
3453
3454
|
*/
|
|
3454
3455
|
async searchInFile(filePath, options) {
|
|
3455
|
-
const content = await
|
|
3456
|
+
const content = await fs.promises.readFile(filePath, "utf-8");
|
|
3456
3457
|
const lines = content.split("\n");
|
|
3457
3458
|
const matches = [];
|
|
3458
3459
|
let pattern;
|
|
@@ -3503,7 +3504,7 @@ ${matchingFiles.join("\n")}` : "No matching files found"
|
|
|
3503
3504
|
*/
|
|
3504
3505
|
async replaceInFile(filePath, options) {
|
|
3505
3506
|
try {
|
|
3506
|
-
const content = await
|
|
3507
|
+
const content = await fs.promises.readFile(filePath, "utf-8");
|
|
3507
3508
|
let pattern;
|
|
3508
3509
|
try {
|
|
3509
3510
|
if (options.isRegex) {
|
|
@@ -3554,7 +3555,7 @@ ${matchingFiles.join("\n")}` : "No matching files found"
|
|
|
3554
3555
|
async getFilesRecursively(dirPath, options) {
|
|
3555
3556
|
const files = [];
|
|
3556
3557
|
const walk = async (currentPath) => {
|
|
3557
|
-
const entries = await
|
|
3558
|
+
const entries = await fs.promises.readdir(currentPath, { withFileTypes: true });
|
|
3558
3559
|
for (const entry of entries) {
|
|
3559
3560
|
const fullPath = path7.join(currentPath, entry.name);
|
|
3560
3561
|
if (entry.isDirectory()) {
|
|
@@ -3717,7 +3718,7 @@ ${matchingFiles.join("\n")}` : "No matching files found"
|
|
|
3717
3718
|
};
|
|
3718
3719
|
var pathExists5 = async (filePath) => {
|
|
3719
3720
|
try {
|
|
3720
|
-
await
|
|
3721
|
+
await ops6.promises.access(filePath, ops6.constants.F_OK);
|
|
3721
3722
|
return true;
|
|
3722
3723
|
} catch {
|
|
3723
3724
|
return false;
|
|
@@ -3906,11 +3907,11 @@ ${category}/
|
|
|
3906
3907
|
let movedFiles = 0;
|
|
3907
3908
|
for (const [category, fileList] of Object.entries(organization)) {
|
|
3908
3909
|
const categoryDir = path7.join(destBase, category);
|
|
3909
|
-
await
|
|
3910
|
+
await ops6.promises.mkdir(categoryDir, { recursive: true });
|
|
3910
3911
|
for (const filePath of fileList) {
|
|
3911
3912
|
const fileName = path7.basename(filePath);
|
|
3912
3913
|
const destPath = path7.join(categoryDir, fileName);
|
|
3913
|
-
await
|
|
3914
|
+
await ops6.move(filePath, destPath);
|
|
3914
3915
|
movedFiles++;
|
|
3915
3916
|
}
|
|
3916
3917
|
}
|
|
@@ -3966,7 +3967,7 @@ ${emptyDirs.map((dir) => `- ${path7.relative(rootPath, dir)}`).join("\n")}`;
|
|
|
3966
3967
|
}
|
|
3967
3968
|
emptyDirs.sort((a, b) => b.length - a.length);
|
|
3968
3969
|
for (const dir of emptyDirs) {
|
|
3969
|
-
await
|
|
3970
|
+
await ops6.rmdir(dir);
|
|
3970
3971
|
}
|
|
3971
3972
|
return {
|
|
3972
3973
|
success: true,
|
|
@@ -3983,7 +3984,7 @@ ${emptyDirs.map((dir) => `- ${path7.relative(rootPath, dir)}`).join("\n")}`;
|
|
|
3983
3984
|
* Build tree structure recursively
|
|
3984
3985
|
*/
|
|
3985
3986
|
async buildTreeStructure(dirPath, options, currentDepth) {
|
|
3986
|
-
const stats = await
|
|
3987
|
+
const stats = await ops6.promises.stat(dirPath);
|
|
3987
3988
|
const name = path7.basename(dirPath);
|
|
3988
3989
|
const node = {
|
|
3989
3990
|
name: name || path7.basename(dirPath),
|
|
@@ -3995,7 +3996,7 @@ ${emptyDirs.map((dir) => `- ${path7.relative(rootPath, dir)}`).join("\n")}`;
|
|
|
3995
3996
|
if (stats.isDirectory() && (!options.maxDepth || currentDepth < options.maxDepth)) {
|
|
3996
3997
|
node.children = [];
|
|
3997
3998
|
try {
|
|
3998
|
-
const entries = await
|
|
3999
|
+
const entries = await ops6.promises.readdir(dirPath, { withFileTypes: true });
|
|
3999
4000
|
for (const entry of entries) {
|
|
4000
4001
|
if (!options.includeHidden && entry.name.startsWith(".")) {
|
|
4001
4002
|
continue;
|
|
@@ -4145,24 +4146,24 @@ ${emptyDirs.map((dir) => `- ${path7.relative(rootPath, dir)}`).join("\n")}`;
|
|
|
4145
4146
|
switch (operation.type) {
|
|
4146
4147
|
case "copy":
|
|
4147
4148
|
const copyDest = path7.resolve(operation.destination);
|
|
4148
|
-
await
|
|
4149
|
+
await ops6.copy(sourcePath, copyDest);
|
|
4149
4150
|
return `Copied ${operation.source} to ${operation.destination}`;
|
|
4150
4151
|
case "move":
|
|
4151
4152
|
const moveDest = path7.resolve(operation.destination);
|
|
4152
|
-
await
|
|
4153
|
+
await ops6.move(sourcePath, moveDest);
|
|
4153
4154
|
return `Moved ${operation.source} to ${operation.destination}`;
|
|
4154
4155
|
case "delete":
|
|
4155
|
-
await
|
|
4156
|
+
await ops6.promises.rm(sourcePath);
|
|
4156
4157
|
return `Deleted ${operation.source}`;
|
|
4157
4158
|
case "create_dir":
|
|
4158
|
-
await
|
|
4159
|
+
await ops6.promises.mkdir(sourcePath, { recursive: true });
|
|
4159
4160
|
return `Created directory ${operation.source}`;
|
|
4160
4161
|
case "chmod":
|
|
4161
|
-
await
|
|
4162
|
+
await ops6.promises.chmod(sourcePath, operation.mode);
|
|
4162
4163
|
return `Changed permissions of ${operation.source} to ${operation.mode}`;
|
|
4163
4164
|
case "rename":
|
|
4164
4165
|
const renameDest = path7.resolve(operation.destination);
|
|
4165
|
-
await
|
|
4166
|
+
await ops6.move(sourcePath, renameDest);
|
|
4166
4167
|
return `Renamed ${operation.source} to ${operation.destination}`;
|
|
4167
4168
|
default:
|
|
4168
4169
|
throw new Error(`Unknown operation type: ${operation.type}`);
|
|
@@ -4191,17 +4192,17 @@ ${emptyDirs.map((dir) => `- ${path7.relative(rootPath, dir)}`).join("\n")}`;
|
|
|
4191
4192
|
* Copy structure recursively
|
|
4192
4193
|
*/
|
|
4193
4194
|
async copyStructureRecursive(source, destination, options) {
|
|
4194
|
-
const stats = await
|
|
4195
|
+
const stats = await ops6.promises.stat(source);
|
|
4195
4196
|
if (stats.isDirectory()) {
|
|
4196
|
-
await
|
|
4197
|
-
const entries = await
|
|
4197
|
+
await ops6.promises.mkdir(destination, { recursive: true });
|
|
4198
|
+
const entries = await ops6.promises.readdir(source);
|
|
4198
4199
|
for (const entry of entries) {
|
|
4199
4200
|
const srcPath = path7.join(source, entry);
|
|
4200
4201
|
const destPath = path7.join(destination, entry);
|
|
4201
4202
|
await this.copyStructureRecursive(srcPath, destPath, options);
|
|
4202
4203
|
}
|
|
4203
4204
|
} else if (options.includeFiles) {
|
|
4204
|
-
await
|
|
4205
|
+
await ops6.copy(source, destination, { overwrite: options.overwrite });
|
|
4205
4206
|
}
|
|
4206
4207
|
}
|
|
4207
4208
|
/**
|
|
@@ -4210,7 +4211,7 @@ ${emptyDirs.map((dir) => `- ${path7.relative(rootPath, dir)}`).join("\n")}`;
|
|
|
4210
4211
|
async getFilesRecursively(dirPath) {
|
|
4211
4212
|
const files = [];
|
|
4212
4213
|
const walk = async (currentPath) => {
|
|
4213
|
-
const entries = await
|
|
4214
|
+
const entries = await ops6.promises.readdir(currentPath, { withFileTypes: true });
|
|
4214
4215
|
for (const entry of entries) {
|
|
4215
4216
|
const fullPath = path7.join(currentPath, entry.name);
|
|
4216
4217
|
if (entry.isDirectory()) {
|
|
@@ -4236,14 +4237,14 @@ ${emptyDirs.map((dir) => `- ${path7.relative(rootPath, dir)}`).join("\n")}`;
|
|
|
4236
4237
|
category = ext || "no-extension";
|
|
4237
4238
|
break;
|
|
4238
4239
|
case "size":
|
|
4239
|
-
const stats = await
|
|
4240
|
+
const stats = await ops6.promises.stat(filePath);
|
|
4240
4241
|
if (stats.size < 1024) category = "small (< 1KB)";
|
|
4241
4242
|
else if (stats.size < 1024 * 1024) category = "medium (< 1MB)";
|
|
4242
4243
|
else if (stats.size < 1024 * 1024 * 10) category = "large (< 10MB)";
|
|
4243
4244
|
else category = "very-large (> 10MB)";
|
|
4244
4245
|
break;
|
|
4245
4246
|
case "date":
|
|
4246
|
-
const fileStats = await
|
|
4247
|
+
const fileStats = await ops6.promises.stat(filePath);
|
|
4247
4248
|
const year = fileStats.mtime.getFullYear();
|
|
4248
4249
|
const month = fileStats.mtime.getMonth() + 1;
|
|
4249
4250
|
category = `${year}-${month.toString().padStart(2, "0")}`;
|
|
@@ -4265,7 +4266,7 @@ ${emptyDirs.map((dir) => `- ${path7.relative(rootPath, dir)}`).join("\n")}`;
|
|
|
4265
4266
|
const emptyDirs = [];
|
|
4266
4267
|
const checkDirectory = async (currentPath) => {
|
|
4267
4268
|
try {
|
|
4268
|
-
const entries = await
|
|
4269
|
+
const entries = await ops6.promises.readdir(currentPath);
|
|
4269
4270
|
if (entries.length === 0) {
|
|
4270
4271
|
emptyDirs.push(currentPath);
|
|
4271
4272
|
return true;
|
|
@@ -4273,7 +4274,7 @@ ${emptyDirs.map((dir) => `- ${path7.relative(rootPath, dir)}`).join("\n")}`;
|
|
|
4273
4274
|
let hasNonEmptyChildren = false;
|
|
4274
4275
|
for (const entry of entries) {
|
|
4275
4276
|
const fullPath = path7.join(currentPath, entry);
|
|
4276
|
-
const stats = await
|
|
4277
|
+
const stats = await ops6.promises.stat(fullPath);
|
|
4277
4278
|
if (stats.isDirectory()) {
|
|
4278
4279
|
const isEmpty = await checkDirectory(fullPath);
|
|
4279
4280
|
if (!isEmpty) {
|
|
@@ -4298,7 +4299,7 @@ ${emptyDirs.map((dir) => `- ${path7.relative(rootPath, dir)}`).join("\n")}`;
|
|
|
4298
4299
|
};
|
|
4299
4300
|
var pathExists6 = async (filePath) => {
|
|
4300
4301
|
try {
|
|
4301
|
-
await
|
|
4302
|
+
await fs.promises.access(filePath, fs.constants.F_OK);
|
|
4302
4303
|
return true;
|
|
4303
4304
|
} catch {
|
|
4304
4305
|
return false;
|
|
@@ -4318,7 +4319,7 @@ var CodeAwareEditorTool = class {
|
|
|
4318
4319
|
error: `File not found: ${filePath}`
|
|
4319
4320
|
};
|
|
4320
4321
|
}
|
|
4321
|
-
const content = await
|
|
4322
|
+
const content = await fs.promises.readFile(resolvedPath, "utf-8");
|
|
4322
4323
|
const language = this.detectLanguage(filePath);
|
|
4323
4324
|
const context = await this.parseCodeContext(content, language);
|
|
4324
4325
|
const output = this.formatCodeAnalysis(context, filePath);
|
|
@@ -4345,7 +4346,7 @@ var CodeAwareEditorTool = class {
|
|
|
4345
4346
|
error: `File not found: ${filePath}`
|
|
4346
4347
|
};
|
|
4347
4348
|
}
|
|
4348
|
-
const content = await
|
|
4349
|
+
const content = await fs.promises.readFile(resolvedPath, "utf-8");
|
|
4349
4350
|
const language = this.detectLanguage(filePath);
|
|
4350
4351
|
const context = await this.parseCodeContext(content, language);
|
|
4351
4352
|
const result = await this.performRefactoring(content, context, operation, language);
|
|
@@ -4371,7 +4372,7 @@ var CodeAwareEditorTool = class {
|
|
|
4371
4372
|
};
|
|
4372
4373
|
}
|
|
4373
4374
|
}
|
|
4374
|
-
await
|
|
4375
|
+
await fs.promises.writeFile(resolvedPath, result.newContent, "utf-8");
|
|
4375
4376
|
return {
|
|
4376
4377
|
success: true,
|
|
4377
4378
|
output: result.output
|
|
@@ -4395,7 +4396,7 @@ var CodeAwareEditorTool = class {
|
|
|
4395
4396
|
error: `File not found: ${filePath}`
|
|
4396
4397
|
};
|
|
4397
4398
|
}
|
|
4398
|
-
const content = await
|
|
4399
|
+
const content = await fs.promises.readFile(resolvedPath, "utf-8");
|
|
4399
4400
|
const language = this.detectLanguage(filePath);
|
|
4400
4401
|
const context = await this.parseCodeContext(content, language);
|
|
4401
4402
|
const insertionPoint = this.findInsertionPoint(content, context, location, target);
|
|
@@ -4425,7 +4426,7 @@ var CodeAwareEditorTool = class {
|
|
|
4425
4426
|
};
|
|
4426
4427
|
}
|
|
4427
4428
|
}
|
|
4428
|
-
await
|
|
4429
|
+
await fs.promises.writeFile(resolvedPath, newContent, "utf-8");
|
|
4429
4430
|
return {
|
|
4430
4431
|
success: true,
|
|
4431
4432
|
output: `Code inserted at line ${insertionPoint.line + 1} in ${filePath}`
|
|
@@ -4449,7 +4450,7 @@ var CodeAwareEditorTool = class {
|
|
|
4449
4450
|
error: `File not found: ${filePath}`
|
|
4450
4451
|
};
|
|
4451
4452
|
}
|
|
4452
|
-
const content = await
|
|
4453
|
+
const content = await fs.promises.readFile(resolvedPath, "utf-8");
|
|
4453
4454
|
const language = this.detectLanguage(filePath);
|
|
4454
4455
|
const formattedContent = await this.formatCodeContent(content, language, options);
|
|
4455
4456
|
if (formattedContent === content) {
|
|
@@ -4477,7 +4478,7 @@ var CodeAwareEditorTool = class {
|
|
|
4477
4478
|
};
|
|
4478
4479
|
}
|
|
4479
4480
|
}
|
|
4480
|
-
await
|
|
4481
|
+
await fs.promises.writeFile(resolvedPath, formattedContent, "utf-8");
|
|
4481
4482
|
return {
|
|
4482
4483
|
success: true,
|
|
4483
4484
|
output: `Code formatted in ${filePath}`
|
|
@@ -4501,7 +4502,7 @@ var CodeAwareEditorTool = class {
|
|
|
4501
4502
|
error: `File not found: ${filePath}`
|
|
4502
4503
|
};
|
|
4503
4504
|
}
|
|
4504
|
-
const content = await
|
|
4505
|
+
const content = await fs.promises.readFile(resolvedPath, "utf-8");
|
|
4505
4506
|
const language = this.detectLanguage(filePath);
|
|
4506
4507
|
const context = await this.parseCodeContext(content, language);
|
|
4507
4508
|
const missingImports = symbols.filter(
|
|
@@ -4542,7 +4543,7 @@ ${importsToAdd.join("\n")}`;
|
|
|
4542
4543
|
};
|
|
4543
4544
|
}
|
|
4544
4545
|
}
|
|
4545
|
-
await
|
|
4546
|
+
await fs.promises.writeFile(resolvedPath, newContent, "utf-8");
|
|
4546
4547
|
return {
|
|
4547
4548
|
success: true,
|
|
4548
4549
|
output: `Added ${missingImports.length} missing imports to ${filePath}`
|
|
@@ -5239,7 +5240,7 @@ ${extractedCode}`;
|
|
|
5239
5240
|
};
|
|
5240
5241
|
var pathExists7 = async (filePath) => {
|
|
5241
5242
|
try {
|
|
5242
|
-
await
|
|
5243
|
+
await ops6.promises.access(filePath, ops6.constants.F_OK);
|
|
5243
5244
|
return true;
|
|
5244
5245
|
} catch {
|
|
5245
5246
|
return false;
|
|
@@ -5560,9 +5561,9 @@ This action cannot be undone.`
|
|
|
5560
5561
|
existed: exists
|
|
5561
5562
|
};
|
|
5562
5563
|
if (exists) {
|
|
5563
|
-
const stats = await
|
|
5564
|
+
const stats = await ops6.promises.stat(resolvedPath);
|
|
5564
5565
|
if (stats.isFile() && this.shouldSnapshotFile(resolvedPath)) {
|
|
5565
|
-
snapshot.content = await
|
|
5566
|
+
snapshot.content = await ops6.promises.readFile(resolvedPath, "utf-8");
|
|
5566
5567
|
snapshot.size = stats.size;
|
|
5567
5568
|
snapshot.lastModified = stats.mtime;
|
|
5568
5569
|
snapshot.permissions = stats.mode.toString(8);
|
|
@@ -5583,7 +5584,7 @@ This action cannot be undone.`
|
|
|
5583
5584
|
*/
|
|
5584
5585
|
shouldSnapshotFile(filePath) {
|
|
5585
5586
|
try {
|
|
5586
|
-
const stats =
|
|
5587
|
+
const stats = ops6.statSync(filePath);
|
|
5587
5588
|
if (stats.size > 1024 * 1024) {
|
|
5588
5589
|
return false;
|
|
5589
5590
|
}
|
|
@@ -5676,14 +5677,14 @@ This action cannot be undone.`
|
|
|
5676
5677
|
try {
|
|
5677
5678
|
const currentExists = await pathExists7(snapshot.filePath);
|
|
5678
5679
|
if (snapshot.existed && snapshot.content !== void 0) {
|
|
5679
|
-
await
|
|
5680
|
-
await
|
|
5680
|
+
await ops6.ensureDir(path7.dirname(snapshot.filePath));
|
|
5681
|
+
await ops6.promises.writeFile(snapshot.filePath, snapshot.content, "utf-8");
|
|
5681
5682
|
if (snapshot.permissions) {
|
|
5682
|
-
await
|
|
5683
|
+
await ops6.promises.chmod(snapshot.filePath, parseInt(snapshot.permissions, 8));
|
|
5683
5684
|
}
|
|
5684
5685
|
restored.push(`Restored: ${snapshot.filePath}`);
|
|
5685
5686
|
} else if (!snapshot.existed && currentExists) {
|
|
5686
|
-
await
|
|
5687
|
+
await ops6.promises.rm(snapshot.filePath);
|
|
5687
5688
|
restored.push(`Removed: ${snapshot.filePath}`);
|
|
5688
5689
|
}
|
|
5689
5690
|
} catch (error) {
|
|
@@ -5830,7 +5831,7 @@ ${errors.join("\n")}`;
|
|
|
5830
5831
|
async loadHistory() {
|
|
5831
5832
|
try {
|
|
5832
5833
|
if (await pathExists7(this.historyFile)) {
|
|
5833
|
-
const data = await
|
|
5834
|
+
const data = await ops6.promises.readFile(this.historyFile, "utf-8");
|
|
5834
5835
|
const parsed = JSON.parse(data);
|
|
5835
5836
|
this.history = parsed.entries.map((entry) => ({
|
|
5836
5837
|
...entry,
|
|
@@ -5848,13 +5849,13 @@ ${errors.join("\n")}`;
|
|
|
5848
5849
|
*/
|
|
5849
5850
|
async saveHistory() {
|
|
5850
5851
|
try {
|
|
5851
|
-
await
|
|
5852
|
+
await ops6.ensureDir(path7.dirname(this.historyFile));
|
|
5852
5853
|
const data = {
|
|
5853
5854
|
entries: this.history,
|
|
5854
5855
|
currentPosition: this.currentPosition,
|
|
5855
5856
|
lastUpdated: (/* @__PURE__ */ new Date()).toISOString()
|
|
5856
5857
|
};
|
|
5857
|
-
await
|
|
5858
|
+
await ops6.promises.writeFile(this.historyFile, JSON.stringify(data, null, 2), "utf-8");
|
|
5858
5859
|
} catch (error) {
|
|
5859
5860
|
}
|
|
5860
5861
|
}
|
|
@@ -5884,7 +5885,7 @@ try {
|
|
|
5884
5885
|
}
|
|
5885
5886
|
var pathExists8 = async (filePath) => {
|
|
5886
5887
|
try {
|
|
5887
|
-
await
|
|
5888
|
+
await fs.promises.access(filePath, fs.constants.F_OK);
|
|
5888
5889
|
return true;
|
|
5889
5890
|
} catch {
|
|
5890
5891
|
return false;
|
|
@@ -5960,7 +5961,7 @@ var ASTParserTool = class {
|
|
|
5960
5961
|
if (!await pathExists8(filePath)) {
|
|
5961
5962
|
throw new Error(`File not found: ${filePath}`);
|
|
5962
5963
|
}
|
|
5963
|
-
const content = await
|
|
5964
|
+
const content = await fs.promises.readFile(filePath, "utf-8");
|
|
5964
5965
|
const language = this.detectLanguage(filePath);
|
|
5965
5966
|
let result;
|
|
5966
5967
|
if (language === "typescript" || language === "tsx") {
|
|
@@ -6649,7 +6650,7 @@ var SymbolSearchTool = class {
|
|
|
6649
6650
|
async findSymbolUsages(symbolRef) {
|
|
6650
6651
|
const usages = [];
|
|
6651
6652
|
try {
|
|
6652
|
-
const content = await
|
|
6653
|
+
const content = await fs.promises.readFile(symbolRef.filePath, "utf-8");
|
|
6653
6654
|
const lines = content.split("\n");
|
|
6654
6655
|
for (let i = 0; i < lines.length; i++) {
|
|
6655
6656
|
const line = lines[i];
|
|
@@ -6704,7 +6705,7 @@ var SymbolSearchTool = class {
|
|
|
6704
6705
|
const usageFiles = symbolRef.usages.filter((usage) => usage.type === "reference" || usage.type === "call").map(() => symbolRef.filePath);
|
|
6705
6706
|
const importedBy = symbolRef.usages.filter((usage) => usage.type === "import").map(() => symbolRef.filePath);
|
|
6706
6707
|
const exportedTo = symbolRef.usages.filter((usage) => usage.type === "export").map(() => symbolRef.filePath);
|
|
6707
|
-
|
|
6708
|
+
crossRefs.push({
|
|
6708
6709
|
symbol: symbolName,
|
|
6709
6710
|
definitionFile,
|
|
6710
6711
|
usageFiles: [...new Set(usageFiles)],
|
|
@@ -6823,7 +6824,7 @@ var SymbolSearchTool = class {
|
|
|
6823
6824
|
};
|
|
6824
6825
|
var pathExists9 = async (filePath) => {
|
|
6825
6826
|
try {
|
|
6826
|
-
await
|
|
6827
|
+
await fs.promises.access(filePath, fs.constants.F_OK);
|
|
6827
6828
|
return true;
|
|
6828
6829
|
} catch {
|
|
6829
6830
|
return false;
|
|
@@ -7026,10 +7027,10 @@ var DependencyAnalyzerTool = class {
|
|
|
7026
7027
|
const circularDeps = [];
|
|
7027
7028
|
const visited = /* @__PURE__ */ new Set();
|
|
7028
7029
|
const visiting = /* @__PURE__ */ new Set();
|
|
7029
|
-
const dfs = (filePath,
|
|
7030
|
+
const dfs = (filePath, path25) => {
|
|
7030
7031
|
if (visiting.has(filePath)) {
|
|
7031
|
-
const cycleStart =
|
|
7032
|
-
const cycle =
|
|
7032
|
+
const cycleStart = path25.indexOf(filePath);
|
|
7033
|
+
const cycle = path25.slice(cycleStart).concat([filePath]);
|
|
7033
7034
|
circularDeps.push({
|
|
7034
7035
|
cycle: cycle.map((fp) => graph.nodes.get(fp)?.filePath || fp),
|
|
7035
7036
|
severity: cycle.length <= 2 ? "error" : "warning",
|
|
@@ -7045,7 +7046,7 @@ var DependencyAnalyzerTool = class {
|
|
|
7045
7046
|
if (node) {
|
|
7046
7047
|
for (const dependency of node.dependencies) {
|
|
7047
7048
|
if (graph.nodes.has(dependency)) {
|
|
7048
|
-
dfs(dependency, [...
|
|
7049
|
+
dfs(dependency, [...path25, filePath]);
|
|
7049
7050
|
}
|
|
7050
7051
|
}
|
|
7051
7052
|
}
|
|
@@ -7294,7 +7295,7 @@ var DependencyAnalyzerTool = class {
|
|
|
7294
7295
|
};
|
|
7295
7296
|
var pathExists10 = async (filePath) => {
|
|
7296
7297
|
try {
|
|
7297
|
-
await
|
|
7298
|
+
await fs.promises.access(filePath, fs.constants.F_OK);
|
|
7298
7299
|
return true;
|
|
7299
7300
|
} catch {
|
|
7300
7301
|
return false;
|
|
@@ -7442,7 +7443,7 @@ var CodeContextTool = class {
|
|
|
7442
7443
|
async analyzeUsagePatterns(symbol, filePath) {
|
|
7443
7444
|
const patterns = [];
|
|
7444
7445
|
try {
|
|
7445
|
-
const content = await
|
|
7446
|
+
const content = await fs.promises.readFile(filePath, "utf-8");
|
|
7446
7447
|
const lines = content.split("\n");
|
|
7447
7448
|
let callCount = 0;
|
|
7448
7449
|
let assignmentCount = 0;
|
|
@@ -7595,7 +7596,7 @@ var CodeContextTool = class {
|
|
|
7595
7596
|
}
|
|
7596
7597
|
async analyzeSemanticContext(filePath, symbols, dependencies) {
|
|
7597
7598
|
const fileName = path7__default.basename(filePath);
|
|
7598
|
-
const content = await
|
|
7599
|
+
const content = await fs.promises.readFile(filePath, "utf-8");
|
|
7599
7600
|
const purpose = this.inferPurpose(fileName, symbols, content);
|
|
7600
7601
|
const domain = this.extractDomain(filePath, symbols, dependencies);
|
|
7601
7602
|
const patterns = this.detectDesignPatterns(content, symbols);
|
|
@@ -7724,7 +7725,7 @@ var CodeContextTool = class {
|
|
|
7724
7725
|
};
|
|
7725
7726
|
}
|
|
7726
7727
|
async calculateCodeMetrics(filePath, symbols) {
|
|
7727
|
-
const content = await
|
|
7728
|
+
const content = await fs.promises.readFile(filePath, "utf-8");
|
|
7728
7729
|
const lines = content.split("\n");
|
|
7729
7730
|
const codeLines = lines.filter((line) => line.trim().length > 0 && !line.trim().startsWith("//"));
|
|
7730
7731
|
const linesOfCode = codeLines.length;
|
|
@@ -7824,7 +7825,7 @@ var CodeContextTool = class {
|
|
|
7824
7825
|
};
|
|
7825
7826
|
var pathExists11 = async (filePath) => {
|
|
7826
7827
|
try {
|
|
7827
|
-
await
|
|
7828
|
+
await fs.promises.access(filePath, fs.constants.F_OK);
|
|
7828
7829
|
return true;
|
|
7829
7830
|
} catch {
|
|
7830
7831
|
return false;
|
|
@@ -7908,8 +7909,8 @@ var RefactoringAssistantTool = class {
|
|
|
7908
7909
|
throw new Error("Failed to find symbol occurrences");
|
|
7909
7910
|
}
|
|
7910
7911
|
const symbolRefs = parsed.result.symbols;
|
|
7911
|
-
const relevantRefs = scope === "file" && filePath ?
|
|
7912
|
-
if (
|
|
7912
|
+
const relevantRefs = scope === "file" && filePath ? symbolRefs.filter((ref) => ref.filePath === filePath) : symbolRefs;
|
|
7913
|
+
if (relevantRefs.length === 0) {
|
|
7913
7914
|
throw new Error(`Symbol '${symbolName}' not found in specified scope`);
|
|
7914
7915
|
}
|
|
7915
7916
|
const safety = await this.analyzeSafety(relevantRefs, "rename");
|
|
@@ -7948,7 +7949,7 @@ var RefactoringAssistantTool = class {
|
|
|
7948
7949
|
if (!await pathExists11(filePath)) {
|
|
7949
7950
|
throw new Error(`File not found: ${filePath}`);
|
|
7950
7951
|
}
|
|
7951
|
-
const content = await
|
|
7952
|
+
const content = await fs.promises.readFile(filePath, "utf-8");
|
|
7952
7953
|
const lines = content.split("\n");
|
|
7953
7954
|
if (startLine < 0 || endLine >= lines.length || startLine > endLine) {
|
|
7954
7955
|
throw new Error("Invalid line range");
|
|
@@ -8023,7 +8024,7 @@ var RefactoringAssistantTool = class {
|
|
|
8023
8024
|
if (!filePath || !variableName) {
|
|
8024
8025
|
throw new Error("File path and variable name are required");
|
|
8025
8026
|
}
|
|
8026
|
-
const content = await
|
|
8027
|
+
const content = await fs.promises.readFile(filePath, "utf-8");
|
|
8027
8028
|
const lines = content.split("\n");
|
|
8028
8029
|
const startLineContent = lines[startLine];
|
|
8029
8030
|
const endLineContent = lines[endLine];
|
|
@@ -8098,7 +8099,7 @@ var RefactoringAssistantTool = class {
|
|
|
8098
8099
|
if (!functionSymbol) {
|
|
8099
8100
|
throw new Error(`Function '${symbolName}' not found`);
|
|
8100
8101
|
}
|
|
8101
|
-
const content = await
|
|
8102
|
+
const content = await fs.promises.readFile(filePath, "utf-8");
|
|
8102
8103
|
const lines = content.split("\n");
|
|
8103
8104
|
const functionLines = lines.slice(functionSymbol.startPosition.row, functionSymbol.endPosition.row + 1);
|
|
8104
8105
|
const functionBody = this.extractFunctionBody(functionLines.join("\n"));
|
|
@@ -8182,8 +8183,8 @@ var RefactoringAssistantTool = class {
|
|
|
8182
8183
|
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
|
|
8183
8184
|
}
|
|
8184
8185
|
async analyzeSafety(refs, operation) {
|
|
8185
|
-
const affectedFiles = new Set(
|
|
8186
|
-
const affectedSymbols =
|
|
8186
|
+
const affectedFiles = new Set(refs.map((ref) => ref.filePath)).size;
|
|
8187
|
+
const affectedSymbols = refs.length;
|
|
8187
8188
|
let riskLevel = "low";
|
|
8188
8189
|
const potentialIssues = [];
|
|
8189
8190
|
if (affectedFiles > 5) {
|
|
@@ -8208,7 +8209,7 @@ var RefactoringAssistantTool = class {
|
|
|
8208
8209
|
}
|
|
8209
8210
|
async generateRenameChanges(ref, oldName, newName, includeComments, includeStrings) {
|
|
8210
8211
|
const changes = [];
|
|
8211
|
-
const content = await
|
|
8212
|
+
const content = await fs.promises.readFile(ref.filePath, "utf-8");
|
|
8212
8213
|
const lines = content.split("\n");
|
|
8213
8214
|
for (let i = 0; i < lines.length; i++) {
|
|
8214
8215
|
const line = lines[i];
|
|
@@ -8499,10 +8500,10 @@ function createTokenCounter(model) {
|
|
|
8499
8500
|
function loadCustomInstructions(workingDirectory = process.cwd()) {
|
|
8500
8501
|
try {
|
|
8501
8502
|
const instructionsPath = path7.join(workingDirectory, ".grok", "GROK.md");
|
|
8502
|
-
if (!
|
|
8503
|
+
if (!fs.existsSync(instructionsPath)) {
|
|
8503
8504
|
return null;
|
|
8504
8505
|
}
|
|
8505
|
-
const customInstructions =
|
|
8506
|
+
const customInstructions = fs.readFileSync(instructionsPath, "utf-8");
|
|
8506
8507
|
return customInstructions.trim();
|
|
8507
8508
|
} catch (error) {
|
|
8508
8509
|
console.warn("Failed to load custom instructions:", error);
|
|
@@ -9011,10 +9012,10 @@ Current working directory: ${process.cwd()}`
|
|
|
9011
9012
|
return await this.textEditor.view(args.path, range);
|
|
9012
9013
|
} catch (error) {
|
|
9013
9014
|
console.warn(`view_file tool failed, falling back to bash: ${error.message}`);
|
|
9014
|
-
const
|
|
9015
|
-
let command = `cat "${
|
|
9015
|
+
const path25 = args.path;
|
|
9016
|
+
let command = `cat "${path25}"`;
|
|
9016
9017
|
if (args.start_line && args.end_line) {
|
|
9017
|
-
command = `sed -n '${args.start_line},${args.end_line}p' "${
|
|
9018
|
+
command = `sed -n '${args.start_line},${args.end_line}p' "${path25}"`;
|
|
9018
9019
|
}
|
|
9019
9020
|
return await this.bash.execute(command);
|
|
9020
9021
|
}
|
|
@@ -9239,10 +9240,6 @@ EOF`;
|
|
|
9239
9240
|
}
|
|
9240
9241
|
};
|
|
9241
9242
|
|
|
9242
|
-
// package.json
|
|
9243
|
-
var package_default = {
|
|
9244
|
-
version: "1.0.30"};
|
|
9245
|
-
|
|
9246
9243
|
// src/utils/text-utils.ts
|
|
9247
9244
|
function isWordBoundary(char) {
|
|
9248
9245
|
if (!char) return true;
|
|
@@ -9636,7 +9633,7 @@ var ClaudeMdParserImpl = class {
|
|
|
9636
9633
|
};
|
|
9637
9634
|
}
|
|
9638
9635
|
try {
|
|
9639
|
-
const content = await
|
|
9636
|
+
const content = await ops6.promises.readFile(claudePath, "utf-8");
|
|
9640
9637
|
const hasDocumentationSection = content.includes("Documentation System Workflow") || content.includes(".agent documentation system");
|
|
9641
9638
|
return {
|
|
9642
9639
|
exists: true,
|
|
@@ -9671,7 +9668,7 @@ This document provides context and instructions for Claude Code when working wit
|
|
|
9671
9668
|
|
|
9672
9669
|
${documentationSection}`;
|
|
9673
9670
|
}
|
|
9674
|
-
await
|
|
9671
|
+
await ops6.promises.writeFile(claudePath, newContent);
|
|
9675
9672
|
return {
|
|
9676
9673
|
success: true,
|
|
9677
9674
|
message: exists ? "\u2705 Updated existing CLAUDE.md with documentation system instructions" : "\u2705 Created CLAUDE.md with documentation system instructions"
|
|
@@ -9739,15 +9736,15 @@ var AgentSystemGenerator = class {
|
|
|
9739
9736
|
filesCreated: []
|
|
9740
9737
|
};
|
|
9741
9738
|
}
|
|
9742
|
-
await
|
|
9743
|
-
await
|
|
9744
|
-
await
|
|
9745
|
-
await
|
|
9746
|
-
await
|
|
9747
|
-
await
|
|
9748
|
-
await
|
|
9739
|
+
await ops6.mkdir(agentPath, { recursive: true });
|
|
9740
|
+
await ops6.mkdir(path7__default.join(agentPath, "system"), { recursive: true });
|
|
9741
|
+
await ops6.mkdir(path7__default.join(agentPath, "tasks"), { recursive: true });
|
|
9742
|
+
await ops6.mkdir(path7__default.join(agentPath, "sop"), { recursive: true });
|
|
9743
|
+
await ops6.mkdir(path7__default.join(agentPath, "incidents"), { recursive: true });
|
|
9744
|
+
await ops6.mkdir(path7__default.join(agentPath, "guardrails"), { recursive: true });
|
|
9745
|
+
await ops6.mkdir(path7__default.join(agentPath, "commands"), { recursive: true });
|
|
9749
9746
|
const readmeContent = this.generateReadmeContent();
|
|
9750
|
-
await
|
|
9747
|
+
await ops6.promises.writeFile(path7__default.join(agentPath, "README.md"), readmeContent);
|
|
9751
9748
|
filesCreated.push(".agent/README.md");
|
|
9752
9749
|
const systemFiles = await this.generateSystemDocs(agentPath);
|
|
9753
9750
|
filesCreated.push(...systemFiles);
|
|
@@ -9857,13 +9854,13 @@ Documentation for documentation system commands:
|
|
|
9857
9854
|
const systemPath = path7__default.join(agentPath, "system");
|
|
9858
9855
|
const files = [];
|
|
9859
9856
|
const archContent = this.config.projectType === "grok-cli" ? this.generateGrokArchitecture() : this.generateExternalArchitecture();
|
|
9860
|
-
await
|
|
9857
|
+
await ops6.promises.writeFile(path7__default.join(systemPath, "architecture.md"), archContent);
|
|
9861
9858
|
files.push(".agent/system/architecture.md");
|
|
9862
9859
|
const criticalStateContent = this.generateCriticalState();
|
|
9863
|
-
await
|
|
9860
|
+
await ops6.promises.writeFile(path7__default.join(systemPath, "critical-state.md"), criticalStateContent);
|
|
9864
9861
|
files.push(".agent/system/critical-state.md");
|
|
9865
9862
|
const apiContent = this.generateApiSchema();
|
|
9866
|
-
await
|
|
9863
|
+
await ops6.promises.writeFile(path7__default.join(systemPath, "api-schema.md"), apiContent);
|
|
9867
9864
|
files.push(".agent/system/api-schema.md");
|
|
9868
9865
|
return files;
|
|
9869
9866
|
}
|
|
@@ -10220,7 +10217,7 @@ interface Tool {
|
|
|
10220
10217
|
|
|
10221
10218
|
*Updated: ${(/* @__PURE__ */ new Date()).toISOString().split("T")[0]}*
|
|
10222
10219
|
`;
|
|
10223
|
-
await
|
|
10220
|
+
await ops6.promises.writeFile(path7__default.join(sopPath, "documentation-workflow.md"), docWorkflowContent);
|
|
10224
10221
|
files.push(".agent/sop/documentation-workflow.md");
|
|
10225
10222
|
if (this.config.projectType === "grok-cli") {
|
|
10226
10223
|
const newCommandContent = `# \u2699\uFE0F Adding New Commands SOP
|
|
@@ -10295,7 +10292,7 @@ Create tool in \`src/tools/\`, then reference in command handler.
|
|
|
10295
10292
|
|
|
10296
10293
|
*Updated: ${(/* @__PURE__ */ new Date()).toISOString().split("T")[0]}*
|
|
10297
10294
|
`;
|
|
10298
|
-
await
|
|
10295
|
+
await ops6.promises.writeFile(path7__default.join(sopPath, "adding-new-command.md"), newCommandContent);
|
|
10299
10296
|
files.push(".agent/sop/adding-new-command.md");
|
|
10300
10297
|
}
|
|
10301
10298
|
return files;
|
|
@@ -10304,7 +10301,7 @@ Create tool in \`src/tools/\`, then reference in command handler.
|
|
|
10304
10301
|
const tasksPath = path7__default.join(agentPath, "tasks");
|
|
10305
10302
|
const files = [];
|
|
10306
10303
|
const exampleContent = this.config.projectType === "grok-cli" ? this.generateGrokExampleTask() : this.generateExternalExampleTask();
|
|
10307
|
-
await
|
|
10304
|
+
await ops6.promises.writeFile(path7__default.join(tasksPath, "example-prd.md"), exampleContent);
|
|
10308
10305
|
files.push(".agent/tasks/example-prd.md");
|
|
10309
10306
|
return files;
|
|
10310
10307
|
}
|
|
@@ -10496,7 +10493,7 @@ After initialization:
|
|
|
10496
10493
|
|
|
10497
10494
|
*Updated: ${(/* @__PURE__ */ new Date()).toISOString().split("T")[0]}*
|
|
10498
10495
|
`;
|
|
10499
|
-
await
|
|
10496
|
+
await ops6.promises.writeFile(path7__default.join(commandsPath, "init-agent.md"), initAgentContent);
|
|
10500
10497
|
files.push(".agent/commands/init-agent.md");
|
|
10501
10498
|
return files;
|
|
10502
10499
|
}
|
|
@@ -10504,7 +10501,7 @@ After initialization:
|
|
|
10504
10501
|
const agentPath = path7__default.join(this.config.rootPath, ".agent");
|
|
10505
10502
|
try {
|
|
10506
10503
|
if (existsSync(agentPath)) {
|
|
10507
|
-
await
|
|
10504
|
+
await ops6.rm(agentPath, { recursive: true, force: true });
|
|
10508
10505
|
}
|
|
10509
10506
|
return await this.generateAgentSystem();
|
|
10510
10507
|
} catch (error) {
|
|
@@ -10591,7 +10588,7 @@ var ReadmeGenerator = class {
|
|
|
10591
10588
|
};
|
|
10592
10589
|
}
|
|
10593
10590
|
const content = this.generateReadmeContent(analysis);
|
|
10594
|
-
await
|
|
10591
|
+
await ops6.promises.writeFile(readmePath, content);
|
|
10595
10592
|
return {
|
|
10596
10593
|
success: true,
|
|
10597
10594
|
message: readmeExists ? "\u2705 Updated existing README.md with comprehensive documentation" : "\u2705 Created new README.md with project documentation",
|
|
@@ -10618,7 +10615,7 @@ var ReadmeGenerator = class {
|
|
|
10618
10615
|
try {
|
|
10619
10616
|
const packagePath = path7__default.join(this.config.rootPath, "package.json");
|
|
10620
10617
|
if (existsSync(packagePath)) {
|
|
10621
|
-
const packageContent = await
|
|
10618
|
+
const packageContent = await ops6.promises.readFile(packagePath, "utf-8");
|
|
10622
10619
|
analysis.packageJson = JSON.parse(packageContent);
|
|
10623
10620
|
analysis.dependencies = Object.keys(analysis.packageJson.dependencies || {});
|
|
10624
10621
|
analysis.devDependencies = Object.keys(analysis.packageJson.devDependencies || {});
|
|
@@ -10647,13 +10644,13 @@ var ReadmeGenerator = class {
|
|
|
10647
10644
|
}
|
|
10648
10645
|
}
|
|
10649
10646
|
generateReadmeContent(analysis) {
|
|
10650
|
-
const
|
|
10651
|
-
const projectName = this.config.projectName ||
|
|
10647
|
+
const pkg2 = analysis.packageJson;
|
|
10648
|
+
const projectName = this.config.projectName || pkg2?.name || "Project";
|
|
10652
10649
|
let content = `# ${projectName}
|
|
10653
10650
|
|
|
10654
10651
|
`;
|
|
10655
|
-
if (
|
|
10656
|
-
content += `${
|
|
10652
|
+
if (pkg2?.description) {
|
|
10653
|
+
content += `${pkg2.description}
|
|
10657
10654
|
|
|
10658
10655
|
`;
|
|
10659
10656
|
} else {
|
|
@@ -10661,7 +10658,7 @@ var ReadmeGenerator = class {
|
|
|
10661
10658
|
|
|
10662
10659
|
`;
|
|
10663
10660
|
}
|
|
10664
|
-
if (
|
|
10661
|
+
if (pkg2) {
|
|
10665
10662
|
content += this.generateBadges(analysis);
|
|
10666
10663
|
}
|
|
10667
10664
|
content += `## \u{1F4CB} Table of Contents
|
|
@@ -10675,7 +10672,7 @@ var ReadmeGenerator = class {
|
|
|
10675
10672
|
`;
|
|
10676
10673
|
if (analysis.hasTests) content += `- [Testing](#testing)
|
|
10677
10674
|
`;
|
|
10678
|
-
if (
|
|
10675
|
+
if (pkg2?.scripts?.build) content += `- [Building](#building)
|
|
10679
10676
|
`;
|
|
10680
10677
|
content += `- [Configuration](#configuration)
|
|
10681
10678
|
`;
|
|
@@ -10687,10 +10684,10 @@ var ReadmeGenerator = class {
|
|
|
10687
10684
|
content += `## \u{1F680} Installation
|
|
10688
10685
|
|
|
10689
10686
|
`;
|
|
10690
|
-
if (
|
|
10687
|
+
if (pkg2?.bin) {
|
|
10691
10688
|
content += `### Global Installation
|
|
10692
10689
|
\`\`\`bash
|
|
10693
|
-
npm install -g ${
|
|
10690
|
+
npm install -g ${pkg2.name}
|
|
10694
10691
|
\`\`\`
|
|
10695
10692
|
|
|
10696
10693
|
`;
|
|
@@ -10701,7 +10698,7 @@ npm install -g ${pkg.name}
|
|
|
10701
10698
|
content += `# Clone the repository
|
|
10702
10699
|
git clone <repository-url>
|
|
10703
10700
|
`;
|
|
10704
|
-
content += `cd ${
|
|
10701
|
+
content += `cd ${pkg2?.name || projectName.toLowerCase()}
|
|
10705
10702
|
|
|
10706
10703
|
`;
|
|
10707
10704
|
content += `# Install dependencies
|
|
@@ -10712,8 +10709,8 @@ npm install
|
|
|
10712
10709
|
content += `## \u{1F4BB} Usage
|
|
10713
10710
|
|
|
10714
10711
|
`;
|
|
10715
|
-
if (
|
|
10716
|
-
const binName = Object.keys(
|
|
10712
|
+
if (pkg2?.bin) {
|
|
10713
|
+
const binName = Object.keys(pkg2.bin)[0];
|
|
10717
10714
|
content += `### Command Line
|
|
10718
10715
|
\`\`\`bash
|
|
10719
10716
|
${binName} [options]
|
|
@@ -10772,7 +10769,7 @@ npm run test:watch
|
|
|
10772
10769
|
`;
|
|
10773
10770
|
}
|
|
10774
10771
|
}
|
|
10775
|
-
if (
|
|
10772
|
+
if (pkg2?.scripts?.build) {
|
|
10776
10773
|
content += `## \u{1F4E6} Building
|
|
10777
10774
|
|
|
10778
10775
|
`;
|
|
@@ -10823,7 +10820,7 @@ TypeScript is configured via \`tsconfig.json\`.
|
|
|
10823
10820
|
|
|
10824
10821
|
`;
|
|
10825
10822
|
}
|
|
10826
|
-
if (analysis.framework === "Express.js" ||
|
|
10823
|
+
if (analysis.framework === "Express.js" || pkg2?.main?.includes("api")) {
|
|
10827
10824
|
content += `## \u{1F4D6} API Documentation
|
|
10828
10825
|
|
|
10829
10826
|
`;
|
|
@@ -10848,8 +10845,8 @@ TypeScript is configured via \`tsconfig.json\`.
|
|
|
10848
10845
|
content += `## \u{1F4C4} License
|
|
10849
10846
|
|
|
10850
10847
|
`;
|
|
10851
|
-
if (
|
|
10852
|
-
content += `This project is licensed under the ${
|
|
10848
|
+
if (pkg2?.license) {
|
|
10849
|
+
content += `This project is licensed under the ${pkg2.license} License.
|
|
10853
10850
|
|
|
10854
10851
|
`;
|
|
10855
10852
|
} else {
|
|
@@ -10909,7 +10906,7 @@ var CommentsGenerator = class {
|
|
|
10909
10906
|
message: "File not found"
|
|
10910
10907
|
};
|
|
10911
10908
|
}
|
|
10912
|
-
const content = await
|
|
10909
|
+
const content = await ops6.promises.readFile(this.config.filePath, "utf-8");
|
|
10913
10910
|
const analysis = this.analyzeCode(content);
|
|
10914
10911
|
if (analysis.hasExistingComments) {
|
|
10915
10912
|
return {
|
|
@@ -10919,8 +10916,8 @@ var CommentsGenerator = class {
|
|
|
10919
10916
|
}
|
|
10920
10917
|
const modifiedContent = this.addComments(content, analysis);
|
|
10921
10918
|
const backupPath = this.config.filePath + ".backup";
|
|
10922
|
-
await
|
|
10923
|
-
await
|
|
10919
|
+
await ops6.promises.writeFile(backupPath, content);
|
|
10920
|
+
await ops6.promises.writeFile(this.config.filePath, modifiedContent);
|
|
10924
10921
|
const commentCount = this.countAddedComments(analysis);
|
|
10925
10922
|
return {
|
|
10926
10923
|
success: true,
|
|
@@ -11136,7 +11133,7 @@ var ApiDocsGenerator = class {
|
|
|
11136
11133
|
const content = this.config.outputFormat === "md" ? this.generateMarkdown(documentation) : this.generateHtml(documentation);
|
|
11137
11134
|
const outputFileName = `api-docs.${this.config.outputFormat}`;
|
|
11138
11135
|
const outputPath = path7__default.join(this.config.rootPath, outputFileName);
|
|
11139
|
-
await
|
|
11136
|
+
await ops6.promises.writeFile(outputPath, content);
|
|
11140
11137
|
const stats = this.getDocumentationStats(documentation);
|
|
11141
11138
|
return {
|
|
11142
11139
|
success: true,
|
|
@@ -11172,7 +11169,7 @@ ${stats}`,
|
|
|
11172
11169
|
}
|
|
11173
11170
|
async scanDirectory(dirPath, documentation) {
|
|
11174
11171
|
try {
|
|
11175
|
-
const entries = await
|
|
11172
|
+
const entries = await ops6.promises.readdir(dirPath, { withFileTypes: true });
|
|
11176
11173
|
for (const entry of entries) {
|
|
11177
11174
|
const fullPath = path7__default.join(dirPath, entry.name);
|
|
11178
11175
|
if (entry.isDirectory() && !entry.name.startsWith(".") && entry.name !== "node_modules") {
|
|
@@ -11191,7 +11188,7 @@ ${stats}`,
|
|
|
11191
11188
|
}
|
|
11192
11189
|
async parseApiFile(filePath, documentation) {
|
|
11193
11190
|
try {
|
|
11194
|
-
const content = await
|
|
11191
|
+
const content = await ops6.promises.readFile(filePath, "utf-8");
|
|
11195
11192
|
const relativePath = path7__default.relative(this.config.rootPath, filePath);
|
|
11196
11193
|
const moduleName = this.getModuleName(relativePath);
|
|
11197
11194
|
const lines = content.split("\n");
|
|
@@ -11518,12 +11515,12 @@ var ChangelogGenerator = class {
|
|
|
11518
11515
|
const changelogPath = path7__default.join(this.config.rootPath, "CHANGELOG.md");
|
|
11519
11516
|
const exists = existsSync(changelogPath);
|
|
11520
11517
|
if (exists) {
|
|
11521
|
-
const existingContent = await
|
|
11518
|
+
const existingContent = await ops6.promises.readFile(changelogPath, "utf-8");
|
|
11522
11519
|
const newContent = content + "\n\n" + existingContent;
|
|
11523
|
-
await
|
|
11520
|
+
await ops6.promises.writeFile(changelogPath, newContent);
|
|
11524
11521
|
} else {
|
|
11525
11522
|
const fullContent = this.generateChangelogHeader() + content;
|
|
11526
|
-
await
|
|
11523
|
+
await ops6.promises.writeFile(changelogPath, fullContent);
|
|
11527
11524
|
}
|
|
11528
11525
|
return {
|
|
11529
11526
|
success: true,
|
|
@@ -11815,13 +11812,13 @@ var UpdateAgentDocs = class {
|
|
|
11815
11812
|
const recentFiles = [];
|
|
11816
11813
|
const scanDir = async (dirPath) => {
|
|
11817
11814
|
try {
|
|
11818
|
-
const entries = await
|
|
11815
|
+
const entries = await ops6.promises.readdir(dirPath, { withFileTypes: true });
|
|
11819
11816
|
for (const entry of entries) {
|
|
11820
11817
|
const fullPath = path7__default.join(dirPath, entry.name);
|
|
11821
11818
|
if (entry.isDirectory() && !entry.name.startsWith(".") && entry.name !== "node_modules") {
|
|
11822
11819
|
await scanDir(fullPath);
|
|
11823
11820
|
} else if (entry.isFile()) {
|
|
11824
|
-
const stats = await
|
|
11821
|
+
const stats = await ops6.promises.stat(fullPath);
|
|
11825
11822
|
if (stats.mtime.getTime() > oneDayAgo) {
|
|
11826
11823
|
recentFiles.push(path7__default.relative(this.config.rootPath, fullPath));
|
|
11827
11824
|
}
|
|
@@ -11877,9 +11874,9 @@ var UpdateAgentDocs = class {
|
|
|
11877
11874
|
try {
|
|
11878
11875
|
const archPath = path7__default.join(systemPath, "architecture.md");
|
|
11879
11876
|
if (existsSync(archPath)) {
|
|
11880
|
-
const content = await
|
|
11877
|
+
const content = await ops6.promises.readFile(archPath, "utf-8");
|
|
11881
11878
|
const updatedContent = await this.updateArchitectureDoc(content, analysis);
|
|
11882
|
-
await
|
|
11879
|
+
await ops6.promises.writeFile(archPath, updatedContent);
|
|
11883
11880
|
updatedFiles.push(".agent/system/architecture.md");
|
|
11884
11881
|
}
|
|
11885
11882
|
} catch (error) {
|
|
@@ -11893,7 +11890,7 @@ var UpdateAgentDocs = class {
|
|
|
11893
11890
|
if (!existsSync(criticalStatePath)) {
|
|
11894
11891
|
return false;
|
|
11895
11892
|
}
|
|
11896
|
-
const content = await
|
|
11893
|
+
const content = await ops6.promises.readFile(criticalStatePath, "utf-8");
|
|
11897
11894
|
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
11898
11895
|
const changesSummary = this.generateChangesSummary(analysis);
|
|
11899
11896
|
let updatedContent = content.replace(
|
|
@@ -11918,7 +11915,7 @@ Updated By: /update-agent-docs after detecting changes${recentChangesSection}`
|
|
|
11918
11915
|
);
|
|
11919
11916
|
}
|
|
11920
11917
|
}
|
|
11921
|
-
await
|
|
11918
|
+
await ops6.promises.writeFile(criticalStatePath, updatedContent);
|
|
11922
11919
|
return true;
|
|
11923
11920
|
} catch (error) {
|
|
11924
11921
|
return false;
|
|
@@ -12368,9 +12365,9 @@ var SelfHealingSystem = class {
|
|
|
12368
12365
|
try {
|
|
12369
12366
|
const incident = await this.analyzeAndCreateIncident(error, context);
|
|
12370
12367
|
const incidentPath = path7__default.join(this.agentPath, "incidents", `${incident.id}.md`);
|
|
12371
|
-
await
|
|
12368
|
+
await ops6.mkdir(path7__default.dirname(incidentPath), { recursive: true });
|
|
12372
12369
|
const incidentContent = this.generateIncidentContent(incident);
|
|
12373
|
-
await
|
|
12370
|
+
await ops6.promises.writeFile(incidentPath, incidentContent);
|
|
12374
12371
|
const guardrail = await this.generateGuardrailFromIncident(incident);
|
|
12375
12372
|
if (guardrail) {
|
|
12376
12373
|
await this.saveGuardrail(guardrail);
|
|
@@ -12500,12 +12497,12 @@ ${guardrail ? `\u{1F6E1}\uFE0F Guardrail created: ${guardrail.name}` : ""}
|
|
|
12500
12497
|
if (!existsSync(incidentsPath)) {
|
|
12501
12498
|
return 0;
|
|
12502
12499
|
}
|
|
12503
|
-
const files = await
|
|
12500
|
+
const files = await ops6.promises.readdir(incidentsPath);
|
|
12504
12501
|
let count = 0;
|
|
12505
12502
|
for (const file of files) {
|
|
12506
12503
|
if (file.endsWith(".md")) {
|
|
12507
12504
|
const filePath = path7__default.join(incidentsPath, file);
|
|
12508
|
-
const content = await
|
|
12505
|
+
const content = await ops6.promises.readFile(filePath, "utf-8");
|
|
12509
12506
|
if (content.includes(title)) {
|
|
12510
12507
|
count++;
|
|
12511
12508
|
}
|
|
@@ -12598,10 +12595,10 @@ ${incident.guardrailCreated ? `Guardrail created: ${incident.guardrailCreated}`
|
|
|
12598
12595
|
}
|
|
12599
12596
|
async saveGuardrail(guardrail) {
|
|
12600
12597
|
const guardrailsPath = path7__default.join(this.agentPath, "guardrails");
|
|
12601
|
-
await
|
|
12598
|
+
await ops6.mkdir(guardrailsPath, { recursive: true });
|
|
12602
12599
|
const filePath = path7__default.join(guardrailsPath, `${guardrail.id}.md`);
|
|
12603
12600
|
const content = this.generateGuardrailContent(guardrail);
|
|
12604
|
-
await
|
|
12601
|
+
await ops6.promises.writeFile(filePath, content);
|
|
12605
12602
|
}
|
|
12606
12603
|
generateGuardrailContent(guardrail) {
|
|
12607
12604
|
return `# ${guardrail.name}
|
|
@@ -12660,12 +12657,12 @@ ${guardrail.createdFrom ? `- Created from incident: ${guardrail.createdFrom}` :
|
|
|
12660
12657
|
if (!existsSync(guardrailsPath)) {
|
|
12661
12658
|
return [];
|
|
12662
12659
|
}
|
|
12663
|
-
const files = await
|
|
12660
|
+
const files = await ops6.promises.readdir(guardrailsPath);
|
|
12664
12661
|
const guardrails = [];
|
|
12665
12662
|
for (const file of files) {
|
|
12666
12663
|
if (file.endsWith(".md")) {
|
|
12667
12664
|
try {
|
|
12668
|
-
const content = await
|
|
12665
|
+
const content = await ops6.promises.readFile(path7__default.join(guardrailsPath, file), "utf-8");
|
|
12669
12666
|
const guardrail = this.parseGuardrailFromContent(content);
|
|
12670
12667
|
if (guardrail) {
|
|
12671
12668
|
guardrails.push(guardrail);
|
|
@@ -12725,12 +12722,12 @@ ${guardrail.createdFrom ? `- Created from incident: ${guardrail.createdFrom}` :
|
|
|
12725
12722
|
if (!existsSync(incidentsPath)) {
|
|
12726
12723
|
return [];
|
|
12727
12724
|
}
|
|
12728
|
-
const files = await
|
|
12725
|
+
const files = await ops6.promises.readdir(incidentsPath);
|
|
12729
12726
|
const incidents = [];
|
|
12730
12727
|
for (const file of files) {
|
|
12731
12728
|
if (file.endsWith(".md")) {
|
|
12732
12729
|
try {
|
|
12733
|
-
const content = await
|
|
12730
|
+
const content = await ops6.promises.readFile(path7__default.join(incidentsPath, file), "utf-8");
|
|
12734
12731
|
const incident = this.parseIncidentFromContent(content);
|
|
12735
12732
|
if (incident) {
|
|
12736
12733
|
incidents.push(incident);
|
|
@@ -12900,6 +12897,63 @@ function useInputHandler({
|
|
|
12900
12897
|
process.exit(0);
|
|
12901
12898
|
return;
|
|
12902
12899
|
}
|
|
12900
|
+
const AUTO_COMPRESS_THRESHOLD = 20;
|
|
12901
|
+
const MIN_HISTORY_SIZE = 10;
|
|
12902
|
+
const PRESERVE_RECENT = 5;
|
|
12903
|
+
if (chatHistory.length > AUTO_COMPRESS_THRESHOLD) {
|
|
12904
|
+
const currentHistoryLength = chatHistory.length;
|
|
12905
|
+
const canCompress = currentHistoryLength >= MIN_HISTORY_SIZE;
|
|
12906
|
+
if (canCompress) {
|
|
12907
|
+
try {
|
|
12908
|
+
setIsProcessing(true);
|
|
12909
|
+
const autoCompressEntry = {
|
|
12910
|
+
type: "assistant",
|
|
12911
|
+
content: `\u{1F916} **Automatic Compression Triggered**
|
|
12912
|
+
|
|
12913
|
+
History has ${currentHistoryLength} entries (threshold: ${AUTO_COMPRESS_THRESHOLD}). Compressing to maintain performance...`,
|
|
12914
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
12915
|
+
};
|
|
12916
|
+
setChatHistory((prev) => [...prev, autoCompressEntry]);
|
|
12917
|
+
const olderEntries = chatHistory.slice(0, -PRESERVE_RECENT);
|
|
12918
|
+
const contentToCompress = olderEntries.map((entry) => entry.content).join("\n");
|
|
12919
|
+
const subagentFramework = new SubagentFramework();
|
|
12920
|
+
const taskId = await subagentFramework.spawnSubagent({
|
|
12921
|
+
type: "summarizer",
|
|
12922
|
+
input: {
|
|
12923
|
+
content: contentToCompress,
|
|
12924
|
+
compressionTarget: 0.3
|
|
12925
|
+
},
|
|
12926
|
+
priority: "medium"
|
|
12927
|
+
});
|
|
12928
|
+
const result = await subagentFramework.waitForResult(taskId, 1e4);
|
|
12929
|
+
if (result.success) {
|
|
12930
|
+
const compressedEntry = {
|
|
12931
|
+
type: "assistant",
|
|
12932
|
+
content: `\u{1F4DD} **Auto-Compressed History Summary**
|
|
12933
|
+
|
|
12934
|
+
${result.summary}
|
|
12935
|
+
|
|
12936
|
+
*Auto-compressed ${currentHistoryLength - PRESERVE_RECENT} entries at ${(/* @__PURE__ */ new Date()).toLocaleString()}*`,
|
|
12937
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
12938
|
+
};
|
|
12939
|
+
const recentEntries = chatHistory.slice(-PRESERVE_RECENT);
|
|
12940
|
+
const newHistory = [compressedEntry, ...recentEntries];
|
|
12941
|
+
setChatHistory(newHistory);
|
|
12942
|
+
const successEntry = {
|
|
12943
|
+
type: "assistant",
|
|
12944
|
+
content: `\u2705 **Auto-Compression Complete**
|
|
12945
|
+
|
|
12946
|
+
Reduced from ${currentHistoryLength} to ${PRESERVE_RECENT + 1} entries.`,
|
|
12947
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
12948
|
+
};
|
|
12949
|
+
setChatHistory((prev) => [...prev, successEntry]);
|
|
12950
|
+
}
|
|
12951
|
+
setIsProcessing(false);
|
|
12952
|
+
} catch (error) {
|
|
12953
|
+
setIsProcessing(false);
|
|
12954
|
+
}
|
|
12955
|
+
}
|
|
12956
|
+
}
|
|
12903
12957
|
if (userInput.trim()) {
|
|
12904
12958
|
const directCommandResult = await handleDirectCommand(userInput);
|
|
12905
12959
|
if (!directCommandResult) {
|
|
@@ -13610,11 +13664,16 @@ ${result.suggestions.map((s) => `- ${s}`).join("\n")}
|
|
|
13610
13664
|
const args = trimmedInput.split(" ").slice(1);
|
|
13611
13665
|
const force = args.includes("--force");
|
|
13612
13666
|
const dryRun = args.includes("--dry-run");
|
|
13667
|
+
const MIN_HISTORY_SIZE = 10;
|
|
13668
|
+
const PRESERVE_RECENT = 5;
|
|
13669
|
+
const currentHistoryLength = chatHistory.length;
|
|
13670
|
+
const olderEntries = chatHistory.slice(0, -PRESERVE_RECENT);
|
|
13671
|
+
const contentToCompress = olderEntries.map((entry) => entry.content).join("\n");
|
|
13613
13672
|
const subagentFramework = new SubagentFramework();
|
|
13614
13673
|
const taskId = await subagentFramework.spawnSubagent({
|
|
13615
13674
|
type: "summarizer",
|
|
13616
13675
|
input: {
|
|
13617
|
-
content:
|
|
13676
|
+
content: contentToCompress,
|
|
13618
13677
|
compressionTarget: 0.3
|
|
13619
13678
|
// 70% reduction
|
|
13620
13679
|
},
|
|
@@ -13623,31 +13682,62 @@ ${result.suggestions.map((s) => `- ${s}`).join("\n")}
|
|
|
13623
13682
|
const result = await subagentFramework.waitForResult(taskId, 1e4);
|
|
13624
13683
|
if (result.success) {
|
|
13625
13684
|
const metrics = subagentFramework.getPerformanceMetrics();
|
|
13685
|
+
const canCompress = currentHistoryLength >= MIN_HISTORY_SIZE || force;
|
|
13686
|
+
const wouldCompressCount = Math.max(0, currentHistoryLength - PRESERVE_RECENT);
|
|
13626
13687
|
const resultEntry = {
|
|
13627
13688
|
type: "assistant",
|
|
13628
13689
|
content: dryRun ? `\u{1F4CA} **Compression Preview (Dry Run)**
|
|
13629
13690
|
|
|
13691
|
+
**Current history:** ${currentHistoryLength} entries
|
|
13692
|
+
**Would compress:** ${wouldCompressCount} older entries into 1 summary
|
|
13693
|
+
**Would preserve:** Last ${PRESERVE_RECENT} recent entries
|
|
13694
|
+
**Estimated reduction:** ~70%
|
|
13695
|
+
|
|
13696
|
+
**Compressed summary:**
|
|
13630
13697
|
${result.summary}
|
|
13631
13698
|
|
|
13632
|
-
\u{1F4A1} Use \`/compact\` to apply compression` : `\u{1F9F9} **Context Compressed Successfully**
|
|
13699
|
+
\u{1F4A1} Use \`/compact\` to apply compression${!canCompress ? ` (requires ${MIN_HISTORY_SIZE}+ entries or --force)` : ""}` : canCompress ? `\u{1F9F9} **Context Compressed Successfully**
|
|
13633
13700
|
|
|
13634
13701
|
${result.summary}
|
|
13635
13702
|
|
|
13636
13703
|
\u{1F4C8} **Performance:**
|
|
13704
|
+
- Original entries: ${currentHistoryLength}
|
|
13705
|
+
- Compressed to: ${PRESERVE_RECENT + 1} entries
|
|
13637
13706
|
- Tokens saved: ~${result.output.compressionRatio * 100}%
|
|
13638
13707
|
- Processing time: ${result.executionTime}ms
|
|
13639
|
-
- Subagent tokens used: ${result.tokensUsed}
|
|
13708
|
+
- Subagent tokens used: ${result.tokensUsed}` : `\u26A0\uFE0F **Compression Skipped**
|
|
13709
|
+
|
|
13710
|
+
History too small for compression (${currentHistoryLength} < ${MIN_HISTORY_SIZE} entries).
|
|
13711
|
+
|
|
13712
|
+
**Preview:**
|
|
13713
|
+
${result.summary}
|
|
13714
|
+
|
|
13715
|
+
\u{1F4A1} Use \`/compact --force\` to compress anyway`,
|
|
13640
13716
|
timestamp: /* @__PURE__ */ new Date()
|
|
13641
13717
|
};
|
|
13718
|
+
if (!dryRun && canCompress) {
|
|
13719
|
+
const compressedEntry = {
|
|
13720
|
+
type: "assistant",
|
|
13721
|
+
content: `\u{1F4DD} **Compressed History Summary**
|
|
13722
|
+
|
|
13723
|
+
${result.summary}
|
|
13724
|
+
|
|
13725
|
+
*Compressed ${wouldCompressCount} entries at ${(/* @__PURE__ */ new Date()).toLocaleString()}*`,
|
|
13726
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
13727
|
+
};
|
|
13728
|
+
const recentEntries = chatHistory.slice(-PRESERVE_RECENT);
|
|
13729
|
+
const newHistory = [compressedEntry, ...recentEntries];
|
|
13730
|
+
setChatHistory(newHistory);
|
|
13731
|
+
}
|
|
13642
13732
|
setChatHistory((prev) => [...prev, resultEntry]);
|
|
13643
|
-
if (!dryRun &&
|
|
13733
|
+
if (!dryRun && canCompress) {
|
|
13644
13734
|
const tipsEntry = {
|
|
13645
13735
|
type: "assistant",
|
|
13646
13736
|
content: `\u2728 **Context Optimization Complete**
|
|
13647
13737
|
|
|
13648
13738
|
**What happened:**
|
|
13649
|
-
-
|
|
13650
|
-
-
|
|
13739
|
+
- ${wouldCompressCount} older conversations summarized
|
|
13740
|
+
- Last ${PRESERVE_RECENT} recent entries preserved
|
|
13651
13741
|
- Key decisions and TODOs maintained
|
|
13652
13742
|
|
|
13653
13743
|
**Options:**
|
|
@@ -14605,6 +14695,10 @@ function ApiKeyInput({ onApiKeySet }) {
|
|
|
14605
14695
|
}
|
|
14606
14696
|
|
|
14607
14697
|
// src/ui/components/chat-interface.tsx
|
|
14698
|
+
var pkgPath = path7__default.resolve(process.cwd(), "package.json");
|
|
14699
|
+
console.log("Reading package.json from:", pkgPath);
|
|
14700
|
+
var pkg = JSON.parse(fs__default.readFileSync(pkgPath, "utf8"));
|
|
14701
|
+
console.log("Version:", pkg.version);
|
|
14608
14702
|
function ChatInterfaceWithAgent({
|
|
14609
14703
|
agent,
|
|
14610
14704
|
initialMessage
|
|
@@ -14651,7 +14745,7 @@ function ChatInterfaceWithAgent({
|
|
|
14651
14745
|
const grokLogo = {
|
|
14652
14746
|
string: "\x1B[33m ##### ##### ##### # #\n# # # # # # #\n# ### # # # # # #\n# # ##### # # # #\n# ### # # # # # #\n# # # # # # #\n ##### # # ##### # #\x1B[0m"
|
|
14653
14747
|
};
|
|
14654
|
-
const logoOutput = (typeof grokLogo === "object" && "string" in grokLogo ? grokLogo.string : String(grokLogo)) + "\nHURRY MODE\n" +
|
|
14748
|
+
const logoOutput = (typeof grokLogo === "object" && "string" in grokLogo ? grokLogo.string : String(grokLogo)) + "\nHURRY MODE\n" + pkg.version;
|
|
14655
14749
|
const logoLines = logoOutput.split("\n");
|
|
14656
14750
|
logoLines.forEach((line) => {
|
|
14657
14751
|
if (line.trim()) {
|
|
@@ -15078,6 +15172,10 @@ function createMCPCommand() {
|
|
|
15078
15172
|
return mcpCommand;
|
|
15079
15173
|
}
|
|
15080
15174
|
|
|
15175
|
+
// package.json
|
|
15176
|
+
var package_default = {
|
|
15177
|
+
version: "1.0.32"};
|
|
15178
|
+
|
|
15081
15179
|
// src/index.ts
|
|
15082
15180
|
dotenv.config();
|
|
15083
15181
|
process.on("SIGTERM", () => {
|