shark-ai 0.3.0 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bin/shark.js
CHANGED
|
@@ -5,9 +5,10 @@ import {
|
|
|
5
5
|
colors,
|
|
6
6
|
configCommand,
|
|
7
7
|
loginCommand,
|
|
8
|
+
t,
|
|
8
9
|
tokenStorage,
|
|
9
10
|
tui
|
|
10
|
-
} from "../chunk-
|
|
11
|
+
} from "../chunk-JQAVZJTG.js";
|
|
11
12
|
|
|
12
13
|
// src/core/error/crash-handler.ts
|
|
13
14
|
import fs from "fs";
|
|
@@ -694,7 +695,7 @@ async function interactiveBusinessAnalyst() {
|
|
|
694
695
|
if (response.actions && response.actions.length > 0) {
|
|
695
696
|
for (const action of response.actions) {
|
|
696
697
|
if (action.type === "talk_with_user") {
|
|
697
|
-
tui.log.info(colors.
|
|
698
|
+
tui.log.info(colors.success("\u{1F916} BA Agent:"));
|
|
698
699
|
console.log(action.content);
|
|
699
700
|
} else {
|
|
700
701
|
tui.log.warning(`
|
|
@@ -717,9 +718,6 @@ async function interactiveBusinessAnalyst() {
|
|
|
717
718
|
}
|
|
718
719
|
}
|
|
719
720
|
}
|
|
720
|
-
if (response.tokens) {
|
|
721
|
-
tui.log.info(`Tokens used: ${response.tokens.output || 0}`);
|
|
722
|
-
}
|
|
723
721
|
}
|
|
724
722
|
});
|
|
725
723
|
tui.outro("Session complete");
|
|
@@ -1105,9 +1103,9 @@ function getAgentId3() {
|
|
|
1105
1103
|
}
|
|
1106
1104
|
async function interactiveScanAgent(options = {}) {
|
|
1107
1105
|
FileLogger.init();
|
|
1108
|
-
tui.intro("\u{1F575}\uFE0F\u200D\u2642\uFE0F Scan Agent");
|
|
1109
1106
|
const config = ConfigManager.getInstance().getConfig();
|
|
1110
1107
|
const language = config.language || "English";
|
|
1108
|
+
tui.intro(t("commands.scan.intro"));
|
|
1111
1109
|
const projectRoot = process.cwd();
|
|
1112
1110
|
let outputFile;
|
|
1113
1111
|
if (options.output) {
|
|
@@ -1130,58 +1128,296 @@ async function interactiveScanAgent(options = {}) {
|
|
|
1130
1128
|
outputFile = path4.join(outputDir, "project-context.md");
|
|
1131
1129
|
}
|
|
1132
1130
|
}
|
|
1133
|
-
tui.log.info(
|
|
1134
|
-
tui.log.info(
|
|
1135
|
-
tui.log.info(
|
|
1131
|
+
tui.log.info(`${t("commands.scan.scanningProject")} ${colors.bold(projectRoot)}`);
|
|
1132
|
+
tui.log.info(`${t("commands.scan.outputTarget")} ${colors.bold(outputFile)}`);
|
|
1133
|
+
tui.log.info(`${t("commands.scan.language")} ${colors.bold(language)}`);
|
|
1136
1134
|
const configFileRelative = path4.relative(projectRoot, outputFile);
|
|
1135
|
+
const initialTemplate = `# Project Context
|
|
1136
|
+
|
|
1137
|
+
## Overview
|
|
1138
|
+
[TO BE ANALYZED]
|
|
1139
|
+
|
|
1140
|
+
## Tech Stack
|
|
1141
|
+
[TO BE ANALYZED]
|
|
1142
|
+
|
|
1143
|
+
## Architecture
|
|
1144
|
+
[TO BE ANALYZED]
|
|
1145
|
+
|
|
1146
|
+
## Directory Structure
|
|
1147
|
+
[TO BE ANALYZED]
|
|
1148
|
+
|
|
1149
|
+
## Key Components
|
|
1150
|
+
[TO BE ANALYZED]
|
|
1151
|
+
|
|
1152
|
+
## API / Interfaces
|
|
1153
|
+
[TO BE ANALYZED]
|
|
1154
|
+
|
|
1155
|
+
## Data Layer
|
|
1156
|
+
[TO BE ANALYZED]
|
|
1157
|
+
|
|
1158
|
+
## Configuration & Environment
|
|
1159
|
+
[TO BE ANALYZED]
|
|
1160
|
+
|
|
1161
|
+
## Build & Development
|
|
1162
|
+
[TO BE ANALYZED]
|
|
1163
|
+
|
|
1164
|
+
## Key Patterns & Conventions
|
|
1165
|
+
[TO BE ANALYZED]
|
|
1166
|
+
`;
|
|
1167
|
+
if (!fs5.existsSync(outputFile)) {
|
|
1168
|
+
const BOM = "\uFEFF";
|
|
1169
|
+
fs5.writeFileSync(outputFile, BOM + initialTemplate, { encoding: "utf-8" });
|
|
1170
|
+
tui.log.success(`${t("commands.scan.templateCreated")} ${outputFile}`);
|
|
1171
|
+
} else {
|
|
1172
|
+
tui.log.info(t("commands.scan.fileExists"));
|
|
1173
|
+
}
|
|
1137
1174
|
const superPrompt = `
|
|
1138
1175
|
You are the **Scan Agent**, an expert software architect and analyst.
|
|
1139
|
-
Your mission is to explore this project's codebase and generate a
|
|
1176
|
+
Your mission is to explore this project's codebase THOROUGHLY and generate a COMPREHENSIVE context file that will be used by other AI agents (specifically a Developer Agent) to understand how to work on this project.
|
|
1140
1177
|
|
|
1141
|
-
**
|
|
1178
|
+
**IMPORTANT**: The file \`${configFileRelative}\` has already been created with a template structure. Your job is to FILL IN each section by analyzing the project.
|
|
1142
1179
|
|
|
1143
1180
|
**LANGUAGE INSTRUCTION**:
|
|
1144
|
-
You MUST write the content
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
**
|
|
1154
|
-
|
|
1181
|
+
You MUST write the content in **${language}**.
|
|
1182
|
+
|
|
1183
|
+
**CRITICAL STRATEGY - INCREMENTAL UPDATES**:
|
|
1184
|
+
DO NOT try to rewrite the entire file at once! Instead:
|
|
1185
|
+
|
|
1186
|
+
1. **Explore** the project using \`list_files\`, \`read_file\`, \`search_file\`
|
|
1187
|
+
2. **Update** specific sections incrementally using \`modify_file\`
|
|
1188
|
+
3. **Benefit**: Build a MUCH MORE DETAILED document without context size limitations
|
|
1189
|
+
|
|
1190
|
+
**WORKFLOW - FILL EACH SECTION:**
|
|
1191
|
+
|
|
1192
|
+
**Step 1 - Analyze Tech Stack:**
|
|
1193
|
+
- \`list_files\` root directory to see project structure
|
|
1194
|
+
- \`read_file\` package.json (or pom.xml, go.mod, requirements.txt, etc.)
|
|
1195
|
+
- \`modify_file\` to replace:
|
|
1196
|
+
- \`target_content\`: "## Tech Stack\\n[TO BE ANALYZED]"
|
|
1197
|
+
- \`content\`: Detailed tech stack with versions, dependencies, and their purposes
|
|
1198
|
+
|
|
1199
|
+
**Step 2 - Analyze Directory Structure:**
|
|
1200
|
+
- \`list_files\` on ALL key directories (src, tests, config, docs, etc.)
|
|
1201
|
+
- Map the complete directory tree
|
|
1202
|
+
- \`modify_file\` to replace:
|
|
1203
|
+
- \`target_content\`: "## Directory Structure\\n[TO BE ANALYZED]"
|
|
1204
|
+
- \`content\`: Visual directory tree with purpose of each folder
|
|
1205
|
+
|
|
1206
|
+
**Step 3 - Analyze Architecture:**
|
|
1207
|
+
- \`read_file\` entry points (main.ts, index.js, app.py, etc.)
|
|
1208
|
+
- \`read_file\` 5-10 source files to understand code patterns and organization
|
|
1209
|
+
- Identify architectural pattern (Clean Arch, MVC, Microservices, etc.)
|
|
1210
|
+
- \`modify_file\` to replace:
|
|
1211
|
+
- \`target_content\`: "## Architecture\\n[TO BE ANALYZED]"
|
|
1212
|
+
- \`content\`: Comprehensive architectural description with patterns and module organization
|
|
1213
|
+
|
|
1214
|
+
**Step 4 - Document Components:**
|
|
1215
|
+
- Identify ALL major modules/components by reading source files
|
|
1216
|
+
- For each component: location, purpose, key files
|
|
1217
|
+
- \`modify_file\` to replace:
|
|
1218
|
+
- \`target_content\`: "## Key Components\\n[TO BE ANALYZED]"
|
|
1219
|
+
- \`content\`: Detailed list of components with their purposes
|
|
1220
|
+
|
|
1221
|
+
**Step 5 - Document APIs (if applicable):**
|
|
1222
|
+
- Search for route definitions, controllers, API endpoints
|
|
1223
|
+
- Document base URL, main endpoints, request/response patterns
|
|
1224
|
+
- \`modify_file\` to replace:
|
|
1225
|
+
- \`target_content\`: "## API / Interfaces\\n[TO BE ANALYZED]"
|
|
1226
|
+
- \`content\`: API documentation (or "Not applicable" if no API)
|
|
1227
|
+
|
|
1228
|
+
**Step 6 - Document Data Layer (if applicable):**
|
|
1229
|
+
- Search for database configs, ORM setup, model definitions
|
|
1230
|
+
- Document database type, ORM tool, key entities/tables
|
|
1231
|
+
- \`modify_file\` to replace:
|
|
1232
|
+
- \`target_content\`: "## Data Layer\\n[TO BE ANALYZED]"
|
|
1233
|
+
- \`content\`: Data layer details (or "Not applicable" if no database)
|
|
1234
|
+
|
|
1235
|
+
**Step 7 - Configuration & Environment:**
|
|
1236
|
+
- Read config files (.env.example, config/, etc.)
|
|
1237
|
+
- Identify environment variables and their purposes
|
|
1238
|
+
- \`modify_file\` to replace:
|
|
1239
|
+
- \`target_content\`: "## Configuration & Environment\\n[TO BE ANALYZED]"
|
|
1240
|
+
- \`content\`: List of env vars and config files
|
|
1241
|
+
|
|
1242
|
+
**Step 8 - Build & Development:**
|
|
1243
|
+
- Read package.json scripts, Makefile, build configs
|
|
1244
|
+
- Document dev, build, test, lint commands
|
|
1245
|
+
- \`modify_file\` to replace:
|
|
1246
|
+
- \`target_content\`: "## Build & Development\\n[TO BE ANALYZED]"
|
|
1247
|
+
- \`content\`: Commands for development workflow
|
|
1248
|
+
|
|
1249
|
+
**Step 9 - Patterns & Conventions:**
|
|
1250
|
+
- Based on files read, document naming conventions, code organization
|
|
1251
|
+
- Note error handling, logging strategies
|
|
1252
|
+
- \`modify_file\` to replace:
|
|
1253
|
+
- \`target_content\`: "## Key Patterns & Conventions\\n[TO BE ANALYZED]"
|
|
1254
|
+
- \`content\`: Observed patterns and conventions
|
|
1255
|
+
|
|
1256
|
+
**Step 10 - Overview (LAST):**
|
|
1257
|
+
- Synthesize all findings into a comprehensive overview
|
|
1258
|
+
- \`modify_file\` to replace:
|
|
1259
|
+
- \`target_content\`: "## Overview\\n[TO BE ANALYZED]"
|
|
1260
|
+
- \`content\`: Detailed project description with purpose and main functionality
|
|
1261
|
+
|
|
1262
|
+
**HOW TO USE modify_file:**
|
|
1263
|
+
\`\`\`json
|
|
1264
|
+
{
|
|
1265
|
+
"actions": [{
|
|
1266
|
+
"type": "modify_file",
|
|
1267
|
+
"path": "${configFileRelative}",
|
|
1268
|
+
"target_content": "## Tech Stack\\n[TO BE ANALYZED]",
|
|
1269
|
+
"content": "## Tech Stack\\n- **Language**: TypeScript 5.3\\n- **Runtime**: Node.js 20.x\\n..."
|
|
1270
|
+
}]
|
|
1271
|
+
}
|
|
1272
|
+
\`\`\`
|
|
1155
1273
|
|
|
1274
|
+
\`\`\`markdown
|
|
1156
1275
|
# Project Context
|
|
1157
1276
|
|
|
1158
1277
|
## Overview
|
|
1159
|
-
[
|
|
1278
|
+
[TO BE ANALYZED]
|
|
1160
1279
|
|
|
1161
1280
|
## Tech Stack
|
|
1162
|
-
|
|
1163
|
-
- **Framework**: [e.g. React, Express, NestJS]
|
|
1164
|
-
- **Build Tool**: [e.g. Vite, Webpack]
|
|
1165
|
-
- **Database**: [e.g. PostgreSQL, Prisma] (if detected)
|
|
1281
|
+
[TO BE ANALYZED]
|
|
1166
1282
|
|
|
1167
1283
|
## Architecture
|
|
1168
|
-
[
|
|
1284
|
+
[TO BE ANALYZED]
|
|
1169
1285
|
|
|
1170
|
-
##
|
|
1171
|
-
|
|
1172
|
-
- **Tests**: [path/to/tests]
|
|
1173
|
-
- **Config**: [path/to/config]
|
|
1286
|
+
## Directory Structure
|
|
1287
|
+
[TO BE ANALYZED]
|
|
1174
1288
|
|
|
1175
|
-
##
|
|
1176
|
-
[
|
|
1289
|
+
## Key Components
|
|
1290
|
+
[TO BE ANALYZED]
|
|
1177
1291
|
|
|
1178
|
-
|
|
1292
|
+
## API / Interfaces
|
|
1293
|
+
[TO BE ANALYZED]
|
|
1294
|
+
|
|
1295
|
+
## Data Layer
|
|
1296
|
+
[TO BE ANALYZED]
|
|
1297
|
+
|
|
1298
|
+
## Configuration & Environment
|
|
1299
|
+
[TO BE ANALYZED]
|
|
1300
|
+
|
|
1301
|
+
## Build & Development
|
|
1302
|
+
[TO BE ANALYZED]
|
|
1303
|
+
|
|
1304
|
+
## Key Patterns & Conventions
|
|
1305
|
+
[TO BE ANALYZED]
|
|
1306
|
+
\`\`\`
|
|
1307
|
+
|
|
1308
|
+
**Step 2 - Explore and Update Incrementally:**
|
|
1309
|
+
After creating the template, perform these analyses and UPDATE each section:
|
|
1310
|
+
|
|
1311
|
+
**2.1 - Analyze Tech Stack:**
|
|
1312
|
+
- \`list_files\` root directory
|
|
1313
|
+
- \`read_file\` package.json (or equivalent manifest)
|
|
1314
|
+
- \`modify_file\` to replace "## Tech Stack\\n[TO BE ANALYZED]" with detailed findings
|
|
1315
|
+
|
|
1316
|
+
**2.2 - Analyze Directory Structure:**
|
|
1317
|
+
- \`list_files\` on key directories (src, tests, config, etc.)
|
|
1318
|
+
- \`modify_file\` to replace "## Directory Structure\\n[TO BE ANALYZED]" with complete structure
|
|
1319
|
+
|
|
1320
|
+
**2.3 - Analyze Architecture:**
|
|
1321
|
+
- \`read_file\` entry points (main.ts, index.js, etc.)
|
|
1322
|
+
- \`read_file\` 5-10 source files to understand patterns
|
|
1323
|
+
- \`modify_file\` to replace "## Architecture\\n[TO BE ANALYZED]" with architectural insights
|
|
1179
1324
|
|
|
1180
|
-
**
|
|
1181
|
-
-
|
|
1182
|
-
-
|
|
1183
|
-
|
|
1184
|
-
-
|
|
1325
|
+
**2.4 - Document Components:**
|
|
1326
|
+
- Identify major modules/components
|
|
1327
|
+
- \`modify_file\` to replace "## Key Components\\n[TO BE ANALYZED]" with component details
|
|
1328
|
+
|
|
1329
|
+
**2.5 - Document APIs (if applicable):**
|
|
1330
|
+
- Search for route definitions, controllers, API endpoints
|
|
1331
|
+
- \`modify_file\` to replace "## API / Interfaces\\n[TO BE ANALYZED]"
|
|
1332
|
+
|
|
1333
|
+
**2.6 - Document Data Layer (if applicable):**
|
|
1334
|
+
- Search for database configs, ORM, models
|
|
1335
|
+
- \`modify_file\` to replace "## Data Layer\\n[TO BE ANALYZED]"
|
|
1336
|
+
|
|
1337
|
+
**2.7 - Final Touches:**
|
|
1338
|
+
- Update remaining sections (Config, Build, Patterns)
|
|
1339
|
+
- Ensure Overview is comprehensive
|
|
1340
|
+
|
|
1341
|
+
**HOW TO USE modify_file:**
|
|
1342
|
+
\`\`\`json
|
|
1343
|
+
{
|
|
1344
|
+
"actions": [{
|
|
1345
|
+
"type": "modify_file",
|
|
1346
|
+
"path": "${configFileRelative}",
|
|
1347
|
+
"target_content": "## Tech Stack\\n[TO BE ANALYZED]",
|
|
1348
|
+
"content": "## Tech Stack\\n- **Language**: TypeScript 5.3\\n- **Runtime**: Node.js 20.x\\n- **Framework**: Express 4.18\\n..."
|
|
1349
|
+
}]
|
|
1350
|
+
}
|
|
1351
|
+
\`\`\`
|
|
1352
|
+
|
|
1353
|
+
**SECTION TEMPLATES (For your updates):**
|
|
1354
|
+
|
|
1355
|
+
**Tech Stack:**
|
|
1356
|
+
\`\`\`markdown
|
|
1357
|
+
## Tech Stack
|
|
1358
|
+
- **Language**: [name + version]
|
|
1359
|
+
- **Runtime**: [name + version]
|
|
1360
|
+
- **Framework**: [name + version]
|
|
1361
|
+
- **Build Tool**: [name]
|
|
1362
|
+
- **Testing**: [framework]
|
|
1363
|
+
- **Key Dependencies**:
|
|
1364
|
+
- [dep-name]: [purpose]
|
|
1365
|
+
- [dep-name]: [purpose]
|
|
1366
|
+
\`\`\`
|
|
1367
|
+
|
|
1368
|
+
**Architecture:**
|
|
1369
|
+
\`\`\`markdown
|
|
1370
|
+
## Architecture
|
|
1371
|
+
[Comprehensive description]
|
|
1372
|
+
- **Pattern**: [Clean Arch, MVC, etc.]
|
|
1373
|
+
- **Module Organization**: [how modules are structured]
|
|
1374
|
+
- **Layer Separation**: [controllers, services, repos]
|
|
1375
|
+
- **Configuration**: [how config is managed]
|
|
1376
|
+
\`\`\`
|
|
1377
|
+
|
|
1378
|
+
**Directory Structure:**
|
|
1379
|
+
\`\`\`markdown
|
|
1380
|
+
## Directory Structure
|
|
1381
|
+
\\\`\\\`\\\`
|
|
1382
|
+
/src
|
|
1383
|
+
/core - [Purpose]
|
|
1384
|
+
/commands - [Purpose]
|
|
1385
|
+
/ui - [Purpose]
|
|
1386
|
+
/tests - [Purpose]
|
|
1387
|
+
/docs - [Purpose]
|
|
1388
|
+
\\\`\\\`\\\`
|
|
1389
|
+
\`\`\`
|
|
1390
|
+
|
|
1391
|
+
**Key Components:**
|
|
1392
|
+
\`\`\`markdown
|
|
1393
|
+
## Key Components
|
|
1394
|
+
|
|
1395
|
+
### [Component Name 1]
|
|
1396
|
+
- **Location**: \\\`path/to/component\\\`
|
|
1397
|
+
- **Purpose**: [What it does]
|
|
1398
|
+
- **Key Files**: [Important files]
|
|
1399
|
+
|
|
1400
|
+
### [Component Name 2]
|
|
1401
|
+
- **Location**: \\\`path/to/component\\\`
|
|
1402
|
+
- **Purpose**: [What it does]
|
|
1403
|
+
- **Key Files**: [Important files]
|
|
1404
|
+
\`\`\`
|
|
1405
|
+
|
|
1406
|
+
**DEPTH REQUIREMENT**:
|
|
1407
|
+
- Read MULTIPLE files (5-10 minimum) to understand patterns
|
|
1408
|
+
- Identify ALL major modules/components
|
|
1409
|
+
- Document API routes, database schemas if applicable
|
|
1410
|
+
- Note design patterns and architectural decisions
|
|
1411
|
+
- List important dependencies with their purposes
|
|
1412
|
+
|
|
1413
|
+
**RULES**:
|
|
1414
|
+
- Create template FIRST (step 1)
|
|
1415
|
+
- Update sections INCREMENTALLY (steps 2-7)
|
|
1416
|
+
- Do NOT wait to write everything at the end
|
|
1417
|
+
- Use \`modify_file\` to replace "[TO BE ANALYZED]" sections
|
|
1418
|
+
- Be DETAILED and COMPREHENSIVE
|
|
1419
|
+
- Take your time - you have up to 30 steps
|
|
1420
|
+
- Verify facts with \`read_file\` or \`search_file\` before documenting
|
|
1185
1421
|
`.trim();
|
|
1186
1422
|
await runScanLoop(superPrompt, outputFile);
|
|
1187
1423
|
}
|
|
@@ -1189,38 +1425,39 @@ async function runScanLoop(initialPrompt, targetPath) {
|
|
|
1189
1425
|
let nextPrompt = initialPrompt;
|
|
1190
1426
|
let keepGoing = true;
|
|
1191
1427
|
let stepCount = 0;
|
|
1192
|
-
const MAX_STEPS =
|
|
1428
|
+
const MAX_STEPS = 60;
|
|
1193
1429
|
while (keepGoing && stepCount < MAX_STEPS) {
|
|
1194
1430
|
stepCount++;
|
|
1195
1431
|
const spinner = tui.spinner();
|
|
1196
|
-
|
|
1432
|
+
const msg = t("commands.scan.analyzing").replace("{step}", stepCount.toString());
|
|
1433
|
+
spinner.start(msg);
|
|
1197
1434
|
let responseText = "";
|
|
1198
1435
|
let lastResponse = null;
|
|
1199
1436
|
try {
|
|
1200
1437
|
lastResponse = await callScanAgentApi(nextPrompt, (chunk) => {
|
|
1201
1438
|
responseText += chunk;
|
|
1202
1439
|
});
|
|
1203
|
-
spinner.stop("
|
|
1204
|
-
if (lastResponse && lastResponse.actions) {
|
|
1440
|
+
spinner.stop(t("commands.scan.stepComplete"));
|
|
1441
|
+
if (lastResponse && lastResponse.actions && lastResponse.actions.length > 0) {
|
|
1205
1442
|
let executionResults = "";
|
|
1206
1443
|
let fileCreated = false;
|
|
1207
1444
|
for (const action of lastResponse.actions) {
|
|
1208
1445
|
if (action.type === "list_files") {
|
|
1209
|
-
tui.log.info(
|
|
1446
|
+
tui.log.info(t("commands.scan.scanningDir").replace("{0}", colors.bold(action.path || ".")));
|
|
1210
1447
|
const result = handleListFiles(action.path || ".");
|
|
1211
1448
|
executionResults += `[Action list_files(${action.path}) Result]:
|
|
1212
1449
|
${result}
|
|
1213
1450
|
|
|
1214
1451
|
`;
|
|
1215
1452
|
} else if (action.type === "read_file") {
|
|
1216
|
-
tui.log.info(
|
|
1453
|
+
tui.log.info(t("commands.scan.readingFile").replace("{0}", colors.bold(action.path || "")));
|
|
1217
1454
|
const result = handleReadFile(action.path || "");
|
|
1218
1455
|
executionResults += `[Action read_file(${action.path}) Result]:
|
|
1219
1456
|
${result}
|
|
1220
1457
|
|
|
1221
1458
|
`;
|
|
1222
1459
|
} else if (action.type === "search_file") {
|
|
1223
|
-
tui.log.info(
|
|
1460
|
+
tui.log.info(t("commands.scan.searching").replace("{0}", colors.bold(action.path || "")));
|
|
1224
1461
|
const result = handleSearchFile(action.path || "");
|
|
1225
1462
|
executionResults += `[Action search_file(${action.path}) Result]:
|
|
1226
1463
|
${result}
|
|
@@ -1231,52 +1468,87 @@ ${result}
|
|
|
1231
1468
|
const resolvedTargetPath = path4.resolve(targetPath);
|
|
1232
1469
|
let isTarget = resolvedActionPath === resolvedTargetPath;
|
|
1233
1470
|
if (!isTarget && path4.basename(action.path || "") === "project-context.md") {
|
|
1234
|
-
tui.log.warning(
|
|
1471
|
+
tui.log.warning(t("commands.scan.targetRedirect").replace("{0}", action.path || "").replace("{1}", path4.relative(process.cwd(), targetPath)));
|
|
1235
1472
|
isTarget = true;
|
|
1236
1473
|
action.path = targetPath;
|
|
1237
1474
|
}
|
|
1238
1475
|
if (isTarget) {
|
|
1239
1476
|
const finalPath = targetPath;
|
|
1477
|
+
const BOM = "\uFEFF";
|
|
1240
1478
|
if (action.type === "create_file") {
|
|
1241
|
-
|
|
1242
|
-
|
|
1479
|
+
const contentToWrite = action.content || "";
|
|
1480
|
+
const finalContent = contentToWrite.startsWith(BOM) ? contentToWrite : BOM + contentToWrite;
|
|
1481
|
+
fs5.writeFileSync(finalPath, finalContent, { encoding: "utf-8" });
|
|
1482
|
+
tui.log.success(t("commands.scan.generated").replace("{0}", finalPath));
|
|
1243
1483
|
fileCreated = true;
|
|
1244
1484
|
} else {
|
|
1245
|
-
fs5.
|
|
1246
|
-
|
|
1247
|
-
|
|
1485
|
+
if (fs5.existsSync(finalPath)) {
|
|
1486
|
+
const currentContent = fs5.readFileSync(finalPath, "utf-8");
|
|
1487
|
+
if (action.target_content && currentContent.includes(action.target_content)) {
|
|
1488
|
+
const newContent = currentContent.replace(action.target_content, action.content || "");
|
|
1489
|
+
const finalContent = newContent.startsWith(BOM) ? newContent : BOM + newContent;
|
|
1490
|
+
fs5.writeFileSync(finalPath, finalContent, { encoding: "utf-8" });
|
|
1491
|
+
tui.log.success(t("commands.scan.updated").replace("{0}", finalPath));
|
|
1492
|
+
fileCreated = true;
|
|
1493
|
+
} else {
|
|
1494
|
+
tui.log.warning(t("commands.scan.error") + ": " + t("commands.scan.contentNotFound"));
|
|
1495
|
+
executionResults += `[Action ${action.type}]: Failed. Target content not found in file.
|
|
1496
|
+
`;
|
|
1497
|
+
fileCreated = false;
|
|
1498
|
+
}
|
|
1499
|
+
} else {
|
|
1500
|
+
tui.log.warning(t("commands.scan.error") + ": " + t("commands.scan.notFound"));
|
|
1501
|
+
}
|
|
1248
1502
|
}
|
|
1249
1503
|
executionResults += `[Action ${action.type}]: Success. Task Completed.
|
|
1250
1504
|
`;
|
|
1251
1505
|
} else {
|
|
1252
|
-
tui.log.warning(
|
|
1253
|
-
executionResults += `[Action ${action.type}]:
|
|
1506
|
+
tui.log.warning(t("commands.scan.error"));
|
|
1507
|
+
executionResults += `[Action ${action.type}]: ${t("commands.scan.skipped")}
|
|
1254
1508
|
`;
|
|
1255
1509
|
}
|
|
1256
1510
|
} else if (action.type === "talk_with_user") {
|
|
1257
|
-
tui.log.info(colors.primary("
|
|
1511
|
+
tui.log.info(colors.primary(t("commands.scan.agentAsks")));
|
|
1258
1512
|
console.log(action.content);
|
|
1259
|
-
const reply = await tui.text({ message: "
|
|
1513
|
+
const reply = await tui.text({ message: t("commands.scan.agentInput"), placeholder: t("commands.scan.replyPlaceholder") });
|
|
1260
1514
|
executionResults += `[User Reply]: ${reply}
|
|
1261
1515
|
`;
|
|
1262
1516
|
}
|
|
1263
1517
|
}
|
|
1264
1518
|
if (fileCreated) {
|
|
1265
|
-
|
|
1266
|
-
|
|
1519
|
+
const currentContent = fs5.readFileSync(targetPath, "utf-8");
|
|
1520
|
+
const pendingSections = [];
|
|
1521
|
+
const lines = currentContent.split("\n");
|
|
1522
|
+
let currentSection = "";
|
|
1523
|
+
for (const line of lines) {
|
|
1524
|
+
if (line.startsWith("## ")) {
|
|
1525
|
+
currentSection = line.substring(3).trim();
|
|
1526
|
+
}
|
|
1527
|
+
if (line.includes("[TO BE ANALYZED]")) {
|
|
1528
|
+
if (currentSection && !pendingSections.includes(currentSection)) {
|
|
1529
|
+
pendingSections.push(currentSection);
|
|
1530
|
+
}
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
const pendingMsg = pendingSections.length > 0 ? `
|
|
1534
|
+
|
|
1535
|
+
[System Helper]: ${t("commands.scan.pendingSections").replace("{0}", pendingSections.join(", "))}` : `
|
|
1536
|
+
|
|
1537
|
+
[System Helper]: ${t("commands.scan.allPopulated")}`;
|
|
1538
|
+
nextPrompt = `${executionResults}
|
|
1539
|
+
|
|
1540
|
+
[System]: File updated successfully.${pendingMsg} Please continue with the next step of the analysis and focus on the pending sections.`;
|
|
1541
|
+
FileLogger.log("SCAN", "Section updated, continuing loop", { step: stepCount, pending: pendingSections.length });
|
|
1267
1542
|
} else {
|
|
1268
1543
|
nextPrompt = executionResults;
|
|
1269
1544
|
FileLogger.log("SCAN", "Auto-replying with results", { length: executionResults.length });
|
|
1270
1545
|
}
|
|
1271
1546
|
} else {
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
keepGoing = false;
|
|
1275
|
-
} else {
|
|
1276
|
-
}
|
|
1547
|
+
tui.log.success(t("commands.scan.completed"));
|
|
1548
|
+
keepGoing = false;
|
|
1277
1549
|
}
|
|
1278
1550
|
} catch (error) {
|
|
1279
|
-
spinner.stop("
|
|
1551
|
+
spinner.stop(t("common.error"));
|
|
1280
1552
|
tui.log.error(error.message);
|
|
1281
1553
|
keepGoing = false;
|
|
1282
1554
|
}
|