Update server.js
Browse files
server.js
CHANGED
|
@@ -62,15 +62,66 @@ const ALLOWED_CMDS = [
|
|
| 62 |
];
|
| 63 |
|
| 64 |
const COMMANDS_REFERENCE = `
|
| 65 |
-
SHELL COMMANDS (cwd=/home)
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
`;
|
| 75 |
|
| 76 |
// ββ Multer βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
@@ -443,13 +494,38 @@ Return ONLY valid JSON (no markdown):
|
|
| 443 |
const smartCtx = getSmartContext(fileContent, message);
|
| 444 |
|
| 445 |
const masterPlanRaw = await callAI(
|
| 446 |
-
`You are Cryo - a sharp developer AI agent on code files.
|
|
|
|
|
|
|
| 447 |
${COMMANDS_REFERENCE}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 448 |
File: ${filePath} (${fileLines} lines)
|
| 449 |
-
|
| 450 |
-
${
|
| 451 |
-
|
| 452 |
-
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 453 |
message,
|
| 454 |
modelKey
|
| 455 |
);
|
|
@@ -511,7 +587,7 @@ Respond ONLY with valid JSON:
|
|
| 511 |
modelKey
|
| 512 |
);
|
| 513 |
const ans = parseJSON(ansRaw);
|
| 514 |
-
send("message", { text: ans?.answer || "No answer generated." });
|
| 515 |
}
|
| 516 |
} else {
|
| 517 |
const ansRaw = await callAI(
|
|
@@ -520,7 +596,7 @@ Respond ONLY with valid JSON:
|
|
| 520 |
modelKey
|
| 521 |
);
|
| 522 |
const ans = parseJSON(ansRaw);
|
| 523 |
-
send("message", { text: ans?.answer || "No answer generated." });
|
| 524 |
}
|
| 525 |
|
| 526 |
} else {
|
|
|
|
| 62 |
];
|
| 63 |
|
| 64 |
const COMMANDS_REFERENCE = `
|
| 65 |
+
=== SHELL COMMANDS AVAILABLE (cwd = /home) ===
|
| 66 |
+
|
| 67 |
+
FILE EXPLORATION:
|
| 68 |
+
ls -l List files & directories
|
| 69 |
+
find . -name "*.js" Find JS files recursively
|
| 70 |
+
find . -name "*.json" Find config files
|
| 71 |
+
file filename Show file type
|
| 72 |
+
stat filename File metadata (size, dates)
|
| 73 |
+
|
| 74 |
+
READING CONTENT:
|
| 75 |
+
cat file Read entire file
|
| 76 |
+
head -n N file First N lines
|
| 77 |
+
tail -n N file Last N lines
|
| 78 |
+
sed -n 'X,Yp' file Lines X to Y (surgical)
|
| 79 |
+
head -c N file First N bytes
|
| 80 |
+
grep -n "pattern" file Lines matching pattern (with line numbers)
|
| 81 |
+
grep -A5 "pattern" file Pattern + 5 lines after
|
| 82 |
+
grep -B3 "pattern" file Pattern + 3 lines before
|
| 83 |
+
grep -C3 "pattern" file Pattern + 3 lines context (before+after)
|
| 84 |
+
grep -rn "pattern" . Recursive search all files
|
| 85 |
+
|
| 86 |
+
COUNTING / STATS:
|
| 87 |
+
wc -l file Count lines
|
| 88 |
+
grep -c "pattern" file Count occurrences
|
| 89 |
+
awk 'END{print NR}' file Alternative line count
|
| 90 |
+
|
| 91 |
+
EDITING (surgical, safe):
|
| 92 |
+
sed -i 's/old/new/g' file Replace ALL occurrences
|
| 93 |
+
sed -i '12s/old/new/' file Replace on line 12 ONLY
|
| 94 |
+
sed -i 'X,Ys/old/new/g' file Replace in lines X-Y
|
| 95 |
+
awk '/pattern/' file Extract matching lines
|
| 96 |
+
cut -d',' -f2 file Extract 2nd CSV column
|
| 97 |
+
tr 'a-z' 'A-Z' Transform chars
|
| 98 |
+
|
| 99 |
+
COMPARING:
|
| 100 |
+
diff old.js new.js Show differences between files
|
| 101 |
+
patch file < patchfile Apply a patch file
|
| 102 |
+
|
| 103 |
+
SYNTAX / ERROR CHECKING:
|
| 104 |
+
node --check file.js JavaScript syntax validation
|
| 105 |
+
npm test Run project tests
|
| 106 |
+
|
| 107 |
+
PROJECT INFO:
|
| 108 |
+
cat package.json Show project dependencies
|
| 109 |
+
npm run scriptname Run npm scripts
|
| 110 |
+
|
| 111 |
+
UTILITIES:
|
| 112 |
+
echo "text" Print text
|
| 113 |
+
sort file Sort lines alphabetically
|
| 114 |
+
uniq file Remove duplicate lines
|
| 115 |
+
|
| 116 |
+
=== AGENT RULES ===
|
| 117 |
+
1. ALWAYS run "node --check file.js" BEFORE any edit
|
| 118 |
+
2. ALWAYS run "node --check file.js" AFTER any edit
|
| 119 |
+
3. Use grep -C3 to understand context BEFORE inserting new code
|
| 120 |
+
4. Match existing code style - grep for similar patterns first
|
| 121 |
+
5. Use sed -n 'X,Yp' to read specific sections before modifying them
|
| 122 |
+
6. Back up important sections mentally before sed -i changes
|
| 123 |
+
7. For adding new features: grep for existing similar features first
|
| 124 |
+
===============================================
|
| 125 |
`;
|
| 126 |
|
| 127 |
// ββ Multer βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
|
|
| 494 |
const smartCtx = getSmartContext(fileContent, message);
|
| 495 |
|
| 496 |
const masterPlanRaw = await callAI(
|
| 497 |
+
`You are Cryo - a razor-sharp developer AI agent operating on code files.
|
| 498 |
+
You use shell commands to explore, understand, then modify code.
|
| 499 |
+
|
| 500 |
${COMMANDS_REFERENCE}
|
| 501 |
+
|
| 502 |
+
WORKFLOW FOR EDITS:
|
| 503 |
+
1. EXPLORE: grep for existing patterns similar to what user wants
|
| 504 |
+
2. LOCATE: find exact line numbers (grep -n, wc -l, sed -n to read sections)
|
| 505 |
+
3. UNDERSTAND: read context around insertion points (grep -C5)
|
| 506 |
+
4. CHECK: node --check before any edit
|
| 507 |
+
5. EDIT: surgical sed -i on specific lines
|
| 508 |
+
6. VERIFY: node --check after edit
|
| 509 |
+
|
| 510 |
+
WORKFLOW FOR QUERIES:
|
| 511 |
+
1. grep for relevant functions/patterns
|
| 512 |
+
2. read surrounding context
|
| 513 |
+
3. answer precisely
|
| 514 |
+
|
| 515 |
File: ${filePath} (${fileLines} lines)
|
| 516 |
+
Current content preview:
|
| 517 |
+
${smartCtx.substring(0, 2500)}
|
| 518 |
+
|
| 519 |
+
${pendingTasks.length > 0 ? `UNFINISHED TASKS FROM LAST SESSION:\n${pendingTasks.map(t => ` - ${t.task}`).join("\n")}\n` : ""}
|
| 520 |
+
|
| 521 |
+
Respond ONLY with valid JSON (no markdown):
|
| 522 |
+
{
|
| 523 |
+
"task_type": "query" | "edit" | "create",
|
| 524 |
+
"status": "brief description shown to user",
|
| 525 |
+
"tasks": [{"task": "subtask name", "done": false}],
|
| 526 |
+
"commands": ["cmd1", "cmd2"],
|
| 527 |
+
"reasoning": "why these commands in this order"
|
| 528 |
+
}`,
|
| 529 |
message,
|
| 530 |
modelKey
|
| 531 |
);
|
|
|
|
| 587 |
modelKey
|
| 588 |
);
|
| 589 |
const ans = parseJSON(ansRaw);
|
| 590 |
+
send("message", { text: ans?.answer || ansRaw || "No answer generated." });
|
| 591 |
}
|
| 592 |
} else {
|
| 593 |
const ansRaw = await callAI(
|
|
|
|
| 596 |
modelKey
|
| 597 |
);
|
| 598 |
const ans = parseJSON(ansRaw);
|
| 599 |
+
send("message", { text: ans?.answer || ansRaw || "No answer generated." });
|
| 600 |
}
|
| 601 |
|
| 602 |
} else {
|