(ctx)
| 246 | // ─── Helpers ───────────────────────────────────────────────────────────────── |
| 247 | |
| 248 | function buildSystemPrompt(ctx) { |
| 249 | const { config, conversationHistory, currentTaskType } = ctx; |
| 250 | const memCtx = getMemoryContext(ctx); |
| 251 | const skillCtx = getSkillContext(ctx); |
| 252 | const pluginCtx = getPluginPrompts(ctx); |
| 253 | |
| 254 | let prompt = `You are SmallCode, a coding assistant that operates in the user's project directory. |
| 255 | |
| 256 | You have tools to read, write, and edit files, run shell commands, and search code. |
| 257 | You also have project memory and compound tools that do multiple operations in one call. |
| 258 | You have a CODE GRAPH indexed for this project — use it for understanding questions. |
| 259 | |
| 260 | IMPORTANT — Code Graph (use these FIRST for understanding/analysis questions): |
| 261 | - list_projects: Lists ALL projects in the workspace with stats. Use FIRST when asked "what projects are here". |
| 262 | - graph_search: Search for a specific symbol/function/class in the graph. |
| 263 | - explain_symbol: Get full explanation of a function/class. |
| 264 | - memory_load: Load relevant project memory. |
| 265 | |
| 266 | IMPORTANT — Environment: |
| 267 | - OS: ${process.platform === 'win32' ? 'Windows (cmd.exe shell)' : process.platform === 'darwin' ? 'macOS (zsh)' : 'Linux (bash)'} |
| 268 | ${process.platform === 'win32' ? '- Use "dir" not "ls", "type" not "cat", "del" not "rm"\n- Do NOT use bash-specific commands (touch, export, chmod)' : ''} |
| 269 | |
| 270 | Rules: |
| 271 | - PREFER compound tools to reduce back-and-forth. |
| 272 | - Use "patch" for edits. Do NOT rewrite whole files. |
| 273 | - Be concise — show what you did, not lengthy explanations. |
| 274 | - If a tool fails, explain what went wrong. Do NOT output a greeting. |
| 275 | - Create files with write_file directly. Do NOT run mkdir first.`; |
| 276 | |
| 277 | if (currentTaskType === 'backend') { |
| 278 | prompt += `\n\nBONESCRIPT MODE — For Node.js/TypeScript backends, use BoneScript.`; |
| 279 | } |
| 280 | |
| 281 | // Web research tools — only advertise them when web browsing is enabled. |
| 282 | // Smaller models trust the prose tool description over the raw `tools` |
| 283 | // array and will refuse research tasks ("my tools are for code files...") |
| 284 | // unless the prompt explicitly says the web tools exist (issue #58). |
| 285 | if (String(process.env.SMALLCODE_WEB_BROWSE).toLowerCase() === 'true') { |
| 286 | prompt += ` |
| 287 | |
| 288 | WEB RESEARCH — you have live internet access: |
| 289 | - web_search: focused query -> relevant results with URLs. |
| 290 | - web_fetch: one URL -> that page's readable text. |
| 291 | Use these whenever asked to research, look up, or find current information. Report a short summary with source URL(s); do NOT write scripts to fetch the web.`; |
| 292 | } |
| 293 | |
| 294 | prompt += `\nWorking directory: ${process.cwd()}`; |
| 295 | prompt += memCtx + skillCtx + pluginCtx; |
| 296 | return prompt; |
| 297 | } |
| 298 | |
| 299 | function getMemoryContext(ctx) { |
| 300 | try { |
no test coverage detected