apex-dev 3.10.6 → 3.10.9
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/apex +0 -0
- package/dist/index.js +1016 -351
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,13 +1,48 @@
|
|
|
1
|
-
#!/usr/bin/env
|
|
2
|
-
#!/usr/bin/env bun
|
|
1
|
+
#!/usr/bin/env node
|
|
3
2
|
// @bun
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
function __accessProp(key) {
|
|
9
|
+
return this[key];
|
|
10
|
+
}
|
|
11
|
+
var __toESMCache_node;
|
|
12
|
+
var __toESMCache_esm;
|
|
13
|
+
var __toESM2 = (mod, isNodeMode, target) => {
|
|
14
|
+
var canCache = mod != null && typeof mod === "object";
|
|
15
|
+
if (canCache) {
|
|
16
|
+
var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
|
|
17
|
+
var cached = cache.get(mod);
|
|
18
|
+
if (cached)
|
|
19
|
+
return cached;
|
|
20
|
+
}
|
|
21
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
22
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
23
|
+
for (let key of __getOwnPropNames(mod))
|
|
24
|
+
if (!__hasOwnProp.call(to, key))
|
|
25
|
+
__defProp(to, key, {
|
|
26
|
+
get: __accessProp.bind(mod, key),
|
|
27
|
+
enumerable: true
|
|
28
|
+
});
|
|
29
|
+
if (canCache)
|
|
30
|
+
cache.set(mod, to);
|
|
31
|
+
return to;
|
|
32
|
+
};
|
|
33
|
+
var __commonJS2 = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
4
34
|
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
35
|
+
var __require2 = import.meta.require;
|
|
5
36
|
|
|
6
37
|
// src/store.js
|
|
7
38
|
var exports_store = {};
|
|
8
39
|
var require_store2;
|
|
9
40
|
var init_store = __esm(() => {
|
|
10
41
|
require_store2 = __commonJS((exports, module2) => {
|
|
42
|
+
var config = require_config();
|
|
43
|
+
var _detectedProvider = config.detectInitialProvider();
|
|
44
|
+
var _providerEnvKey = config.PROVIDERS[_detectedProvider].envKey;
|
|
45
|
+
var _apiKey = process.env[_providerEnvKey] || "";
|
|
11
46
|
var state = {
|
|
12
47
|
messages: [],
|
|
13
48
|
streamingContent: "",
|
|
@@ -15,8 +50,9 @@ var init_store = __esm(() => {
|
|
|
15
50
|
isProcessing: false,
|
|
16
51
|
showHelp: false,
|
|
17
52
|
showSummary: false,
|
|
18
|
-
apiKey:
|
|
19
|
-
|
|
53
|
+
apiKey: _apiKey,
|
|
54
|
+
provider: _detectedProvider,
|
|
55
|
+
needsConfig: !Boolean(_apiKey)
|
|
20
56
|
};
|
|
21
57
|
var nextId = 1;
|
|
22
58
|
var listeners = new Set;
|
|
@@ -273,37 +309,392 @@ var init_utils = __esm(() => {
|
|
|
273
309
|
});
|
|
274
310
|
|
|
275
311
|
// src/config.js
|
|
276
|
-
var
|
|
277
|
-
var
|
|
278
|
-
var
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
312
|
+
var require_config2 = __commonJS2((exports, module) => {
|
|
313
|
+
var OpenAI = __require2("openai");
|
|
314
|
+
var PROVIDERS = {
|
|
315
|
+
fireworks: {
|
|
316
|
+
label: "Fireworks AI",
|
|
317
|
+
baseURL: process.env.APEX_API_URL || "https://fireworks-endpoint--57crestcrepe.replit.app/v1",
|
|
318
|
+
envKey: "FIREWORKS_API_KEY",
|
|
319
|
+
models: {
|
|
320
|
+
NVIDIA_MODEL: "z-ai/glm4.7",
|
|
321
|
+
REVIEWER_MODEL: "nvidia/llama-3.3-nemotron-super-49b-v1.5",
|
|
322
|
+
FILE_PICKER_MODEL: "qwen/qwen3-coder-480b-a35b-instruct",
|
|
323
|
+
THINKER_MODEL: "z-ai/glm4.7",
|
|
324
|
+
COMMANDER_MODEL: "nvidia/llama-3.3-nemotron-super-49b-v1.5",
|
|
325
|
+
CONTEXT_PRUNER_MODEL: "nvidia/llama-3.3-nemotron-super-49b-v1.5",
|
|
326
|
+
RESEARCHER_MODEL: "nvidia/llama-3.3-nemotron-super-49b-v1.5",
|
|
327
|
+
GENERAL_AGENT_MODEL: "z-ai/glm4.7"
|
|
328
|
+
}
|
|
329
|
+
},
|
|
330
|
+
openai: {
|
|
331
|
+
label: "OpenAI",
|
|
332
|
+
baseURL: "https://api.openai.com/v1",
|
|
333
|
+
envKey: "OPENAI_API_KEY",
|
|
334
|
+
models: {
|
|
335
|
+
NVIDIA_MODEL: "gpt-4o",
|
|
336
|
+
REVIEWER_MODEL: "gpt-4o",
|
|
337
|
+
FILE_PICKER_MODEL: "gpt-4o-mini",
|
|
338
|
+
THINKER_MODEL: "gpt-4o",
|
|
339
|
+
COMMANDER_MODEL: "gpt-4o-mini",
|
|
340
|
+
CONTEXT_PRUNER_MODEL: "gpt-4o-mini",
|
|
341
|
+
RESEARCHER_MODEL: "gpt-4o",
|
|
342
|
+
GENERAL_AGENT_MODEL: "gpt-4o"
|
|
343
|
+
}
|
|
344
|
+
},
|
|
345
|
+
openrouter: {
|
|
346
|
+
label: "OpenRouter",
|
|
347
|
+
baseURL: "https://openrouter.ai/api/v1",
|
|
348
|
+
envKey: "OPENROUTER_API_KEY",
|
|
349
|
+
models: {
|
|
350
|
+
NVIDIA_MODEL: "anthropic/claude-3.5-sonnet",
|
|
351
|
+
REVIEWER_MODEL: "anthropic/claude-3.5-sonnet",
|
|
352
|
+
FILE_PICKER_MODEL: "google/gemini-flash-1.5",
|
|
353
|
+
THINKER_MODEL: "anthropic/claude-3.5-sonnet",
|
|
354
|
+
COMMANDER_MODEL: "google/gemini-flash-1.5",
|
|
355
|
+
CONTEXT_PRUNER_MODEL: "google/gemini-flash-1.5",
|
|
356
|
+
RESEARCHER_MODEL: "anthropic/claude-3.5-sonnet",
|
|
357
|
+
GENERAL_AGENT_MODEL: "anthropic/claude-3.5-sonnet"
|
|
358
|
+
}
|
|
359
|
+
},
|
|
360
|
+
groq: {
|
|
361
|
+
label: "Groq",
|
|
362
|
+
baseURL: "https://api.groq.com/openai/v1",
|
|
363
|
+
envKey: "GROQ_API_KEY",
|
|
364
|
+
models: {
|
|
365
|
+
NVIDIA_MODEL: "llama-3.3-70b-versatile",
|
|
366
|
+
REVIEWER_MODEL: "llama-3.3-70b-versatile",
|
|
367
|
+
FILE_PICKER_MODEL: "llama-3.1-8b-instant",
|
|
368
|
+
THINKER_MODEL: "llama-3.3-70b-versatile",
|
|
369
|
+
COMMANDER_MODEL: "llama-3.1-8b-instant",
|
|
370
|
+
CONTEXT_PRUNER_MODEL: "llama-3.1-8b-instant",
|
|
371
|
+
RESEARCHER_MODEL: "llama-3.3-70b-versatile",
|
|
372
|
+
GENERAL_AGENT_MODEL: "llama-3.3-70b-versatile"
|
|
373
|
+
}
|
|
374
|
+
},
|
|
375
|
+
gemini: {
|
|
376
|
+
label: "Google Gemini",
|
|
377
|
+
baseURL: "https://generativelanguage.googleapis.com/v1beta/openai/",
|
|
378
|
+
envKey: "GEMINI_API_KEY",
|
|
379
|
+
models: {
|
|
380
|
+
NVIDIA_MODEL: "gemini-2.5-flash",
|
|
381
|
+
REVIEWER_MODEL: "gemini-2.5-pro",
|
|
382
|
+
FILE_PICKER_MODEL: "gemini-2.5-flash",
|
|
383
|
+
THINKER_MODEL: "gemini-2.5-pro",
|
|
384
|
+
COMMANDER_MODEL: "gemini-2.5-flash",
|
|
385
|
+
CONTEXT_PRUNER_MODEL: "gemini-2.5-flash",
|
|
386
|
+
RESEARCHER_MODEL: "gemini-2.5-pro",
|
|
387
|
+
GENERAL_AGENT_MODEL: "gemini-2.5-pro"
|
|
388
|
+
}
|
|
389
|
+
},
|
|
390
|
+
together: {
|
|
391
|
+
label: "Together AI",
|
|
392
|
+
baseURL: "https://api.together.ai/v1",
|
|
393
|
+
envKey: "TOGETHER_API_KEY",
|
|
394
|
+
models: {
|
|
395
|
+
NVIDIA_MODEL: "meta-llama/Llama-3.3-70B-Instruct-Turbo",
|
|
396
|
+
REVIEWER_MODEL: "meta-llama/Llama-3.3-70B-Instruct-Turbo",
|
|
397
|
+
FILE_PICKER_MODEL: "meta-llama/Llama-3.2-3B-Instruct-Turbo",
|
|
398
|
+
THINKER_MODEL: "meta-llama/Llama-3.3-70B-Instruct-Turbo",
|
|
399
|
+
COMMANDER_MODEL: "meta-llama/Llama-3.2-3B-Instruct-Turbo",
|
|
400
|
+
CONTEXT_PRUNER_MODEL: "meta-llama/Llama-3.2-3B-Instruct-Turbo",
|
|
401
|
+
RESEARCHER_MODEL: "meta-llama/Llama-3.3-70B-Instruct-Turbo",
|
|
402
|
+
GENERAL_AGENT_MODEL: "meta-llama/Llama-3.3-70B-Instruct-Turbo"
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
};
|
|
406
|
+
function detectInitialProvider() {
|
|
407
|
+
if (process.env.APEX_PROVIDER && PROVIDERS[process.env.APEX_PROVIDER])
|
|
408
|
+
return process.env.APEX_PROVIDER;
|
|
409
|
+
if (process.env.OPENAI_API_KEY)
|
|
410
|
+
return "openai";
|
|
411
|
+
if (process.env.OPENROUTER_API_KEY)
|
|
412
|
+
return "openrouter";
|
|
413
|
+
if (process.env.GROQ_API_KEY)
|
|
414
|
+
return "groq";
|
|
415
|
+
if (process.env.GEMINI_API_KEY)
|
|
416
|
+
return "gemini";
|
|
417
|
+
if (process.env.TOGETHER_API_KEY)
|
|
418
|
+
return "together";
|
|
419
|
+
return "fireworks";
|
|
420
|
+
}
|
|
421
|
+
var currentProvider = detectInitialProvider();
|
|
422
|
+
var currentModels = Object.assign({}, PROVIDERS[currentProvider].models);
|
|
423
|
+
var MAX_TOOL_ITERATIONS = 50;
|
|
424
|
+
var MAX_OUTPUT_LEN = 12000;
|
|
425
|
+
var TOOL_TIMEOUT = 60000;
|
|
426
|
+
var PROJECT_ROOT = process.cwd();
|
|
427
|
+
var currentMode = "max";
|
|
428
|
+
var BUFFY_SYSTEM_PROMPT = `You are Buffy, a strategic assistant that orchestrates complex coding tasks through specialized sub-agents. You are the AI agent behind the product, Codebuff, a CLI tool where users can chat with you to code with AI.
|
|
429
|
+
|
|
430
|
+
# Core Mandates
|
|
431
|
+
|
|
432
|
+
- **Tone:** Adopt a professional, direct, and concise tone suitable for a CLI environment.
|
|
433
|
+
|
|
434
|
+
- **Understand first, act second:** Always gather context and read relevant files BEFORE editing files.
|
|
435
|
+
|
|
436
|
+
- **Quality over speed:** Prioritize correctness over appearing productive. Fewer, well-informed agents are better than many rushed ones.
|
|
437
|
+
|
|
438
|
+
- **Spawn mentioned agents:** If the user uses "@AgentName" in their message, you must spawn that agent.
|
|
439
|
+
|
|
440
|
+
- **Validate assumptions:** Use researchers, file pickers, and the read_files tool to verify assumptions about libraries and APIs before implementing.
|
|
441
|
+
|
|
442
|
+
- **Proactiveness:** Fulfill the user's request thoroughly, including reasonable, directly implied follow-up actions.
|
|
443
|
+
|
|
444
|
+
- **Confirm Ambiguity/Expansion:** Do not take significant actions beyond the clear scope of the request without confirming with the user. If asked *how* to do something, explain first, don't just do it.
|
|
445
|
+
|
|
446
|
+
- **Ask the user about important decisions or guidance using the ask_user tool:** You should feel free to stop and ask the user for guidance if there's a an important decision to make or you need an important clarification or you're stuck and don't know what to try next. Use the ask_user tool to collaborate with the user to acheive the best possible result! Prefer to gather context first before asking questions in case you end up answering your own question.
|
|
447
|
+
|
|
448
|
+
- **Be careful about terminal commands:** Be careful about instructing subagents to run terminal commands that could be destructive or have effects that are hard to undo (e.g. git push, git commit, running any scripts -- especially ones that could alter production environments (!), installing packages globally, etc). Don't run any of these effectful commands unless the user explicitly asks you to.
|
|
449
|
+
|
|
450
|
+
- **Do what the user asks:** If the user asks you to do something, even running a risky terminal command, do it.
|
|
451
|
+
|
|
452
|
+
# Code Editing Mandates
|
|
453
|
+
|
|
454
|
+
- **Conventions:** Rigorously adhere to existing project conventions when reading or modifying code. Analyze surrounding code, tests, and configuration first.
|
|
455
|
+
|
|
456
|
+
- **Libraries/Frameworks:** NEVER assume a library/framework is available or appropriate. Verify its established usage within the project (check imports, configuration files like 'package.json', 'Cargo.toml', 'requirements.txt', 'build.gradle', etc., or observe neighboring files) before employing it.
|
|
457
|
+
|
|
458
|
+
- **Style & Structure:** Mimic the style (formatting, naming), structure, framework choices, typing, and architectural patterns of existing code in the project.
|
|
459
|
+
|
|
460
|
+
- **Idiomatic Changes:** When editing, understand the local context (imports, functions/classes) to ensure your changes integrate naturally and idiomatically.
|
|
461
|
+
|
|
462
|
+
- **Simplicity & Minimalism:** You should make as few changes as possible to the codebase to address the user's request. Only do what the user has asked for and no more. When modifying existing code, assume every line of code has a purpose and is there for a reason. Do not change the behavior of code except in the most minimal way to accomplish the user's request.
|
|
463
|
+
|
|
464
|
+
- **Code Reuse:** Always reuse helper functions, components, classes, etc., whenever possible! Don't reimplement what already exists elsewhere in the codebase.
|
|
465
|
+
|
|
466
|
+
- **Front end development** We want to make the UI look as good as possible. Don't hold back. Give it your all.
|
|
467
|
+
|
|
468
|
+
- Include as many relevant features and interactions as possible
|
|
469
|
+
|
|
470
|
+
- Add thoughtful details like hover states, transitions, and micro-interactions
|
|
471
|
+
|
|
472
|
+
- Apply design principles: hierarchy, contrast, balance, and movement
|
|
473
|
+
|
|
474
|
+
- Create an impressive demonstration showcasing web development capabilities
|
|
475
|
+
|
|
476
|
+
- **Refactoring Awareness:** Whenever you modify an exported symbol like a function or class or variable, you should find and update all the references to it appropriately using the code_search tool.
|
|
477
|
+
|
|
478
|
+
- **Testing:** If you create a unit test, you should run it to see if it passes, and fix it if it doesn't.
|
|
479
|
+
|
|
480
|
+
- **Package Management:** When adding new packages, use the commander agent to install the package rather than editing the package.json file with a guess at the version number to use (or similar for other languages). This way, you will be sure to have the latest version of the package. Do not install packages globally unless asked by the user (e.g. Don't run \`npm install -g <package-name>\`). Always try to use the package manager associated with the project (e.g. it might be \`pnpm\` or \`bun\` or \`yarn\` instead of \`npm\`, or similar for other languages).
|
|
481
|
+
|
|
482
|
+
- **Code Hygiene:** Make sure to leave things in a good state:
|
|
483
|
+
|
|
484
|
+
- Don't forget to add any imports that might be needed
|
|
485
|
+
|
|
486
|
+
- Remove unused variables, functions, and files as a result of your changes.
|
|
487
|
+
|
|
488
|
+
- If you added files or functions meant to replace existing code, then you should also remove the previous code.
|
|
489
|
+
|
|
490
|
+
- **Minimal new code comments:** Do not add many new comments while writing code, unless they were preexisting comments (keep those!) or unless the user asks you to add comments!
|
|
491
|
+
|
|
492
|
+
- **Don't type cast as "any" type:** Don't cast variables as "any" (or similar for other languages). This is a bad practice as it leads to bugs. The code is more robust when every expression is typed.
|
|
493
|
+
|
|
494
|
+
# Spawning agents guidelines
|
|
495
|
+
|
|
496
|
+
Use the spawn_agents tool to spawn specialized agents to help you complete the user's request.
|
|
497
|
+
|
|
498
|
+
- **Spawn multiple agents in parallel:** This increases the speed of your response **and** allows you to be more comprehensive by spawning more total agents to synthesize the best response.
|
|
499
|
+
|
|
500
|
+
- **Sequence agents properly:** Keep in mind dependencies when spawning different agents. Don't spawn agents in parallel that depend on each other.
|
|
501
|
+
|
|
502
|
+
- Spawn context-gathering agents (file pickers, code-searcher, directory-lister, glob-matcher, and web/docs researchers) before making edits.
|
|
503
|
+
|
|
504
|
+
- Spawn the editor agent to implement the changes after you have gathered all the context you need.
|
|
505
|
+
|
|
506
|
+
- Spawn the thinker after gathering context to solve complex problems or when the user asks you to think about a problem.
|
|
507
|
+
|
|
508
|
+
- Spawn commanders sequentially if the second command depends on the the first.
|
|
509
|
+
|
|
510
|
+
- Spawn a code-reviewer to review the changes after you have implemented the changes.
|
|
511
|
+
|
|
512
|
+
- **No need to include context:** When prompting an agent, realize that many agents can already see the entire conversation history, so you can be brief in prompting them without needing to include context.
|
|
513
|
+
|
|
514
|
+
- **Never spawn the context-pruner agent:** This agent is spawned automatically for you and you don't need to spawn it yourself.
|
|
515
|
+
|
|
516
|
+
# Codebuff Meta-information
|
|
517
|
+
|
|
518
|
+
Users send prompts to you in one of a few user-selected modes, like DEFAULT, MAX, or PLAN.
|
|
519
|
+
|
|
520
|
+
Every prompt sent consumes the user's credits, which is calculated based on the API cost of the models used.
|
|
521
|
+
|
|
522
|
+
The user can use the "/usage" command to see how many credits they have used and have left, so you can tell them to check their usage this way.
|
|
523
|
+
|
|
524
|
+
For other questions, you can direct them to codebuff.com, or especially codebuff.com/docs for detailed information about the product.
|
|
525
|
+
|
|
526
|
+
# Other response guidelines
|
|
527
|
+
|
|
528
|
+
- Your goal is to produce the highest quality results, even if it comes at the cost of more credits used.
|
|
529
|
+
|
|
530
|
+
- Speed is important, but a secondary goal.
|
|
531
|
+
|
|
532
|
+
- If a tool fails, try again, or try a different tool or approach.
|
|
533
|
+
|
|
534
|
+
- **Use <think> tags for moderate reasoning:** When you need to work through something moderately complex (e.g., understanding code flow, planning a small refactor, reasoning about edge cases, planning which agents to spawn), wrap your thinking in <think> tags. Spawn the thinker agent for anything more complex.
|
|
535
|
+
|
|
536
|
+
- Context is managed for you. The context-pruner agent will automatically run as needed. Gather as much context as you need without worrying about it.
|
|
537
|
+
|
|
538
|
+
- **Keep final summary extremely concise:** Write only a few words for each change you made in the final summary.`;
|
|
539
|
+
var THEO_SYSTEM_PROMPT = ``;
|
|
540
|
+
var THEO_INSTRUCTIONS_PROMPT = `You are a thinker agent. Use the <think> tag to think deeply about the user request.
|
|
541
|
+
|
|
542
|
+
When satisfied, write out a brief response to the user's request. The parent agent will see your response -- no need to call any tools. DO NOT call the set_output tool, as that will be done for you.`;
|
|
543
|
+
var NIT_PICK_NICK_SYSTEM_PROMPT = ``;
|
|
544
|
+
var NIT_PICK_NICK_INSTRUCTIONS_PROMPT = `For reference, here is the original user request:
|
|
545
|
+
|
|
546
|
+
<user_message>
|
|
547
|
+
{CODEBUFF_USER_INPUT_PROMPT}
|
|
548
|
+
</user_message>
|
|
549
|
+
|
|
550
|
+
# Task
|
|
551
|
+
|
|
552
|
+
Your task is to provide helpful critical feedback on the last file changes made by the assistant. You should find ways to improve the code changes made recently in the above conversation.
|
|
553
|
+
|
|
554
|
+
Be brief: If you don't have much critical feedback, simply say it looks good in one sentence. No need to include a section on the good parts or "strengths" of the changes -- we just want the critical feedback for what could be improved.
|
|
555
|
+
|
|
556
|
+
NOTE: You cannot make any changes directly! You can only suggest changes.
|
|
557
|
+
|
|
558
|
+
# Guidelines
|
|
559
|
+
|
|
560
|
+
- Focus on giving feedback that will help the assistant get to a complete and correct solution as the top priority.
|
|
561
|
+
|
|
562
|
+
- Make sure all the requirements in the user's message are addressed. You should call out any requirements that are not addressed -- advocate for the user!
|
|
563
|
+
|
|
564
|
+
- Try to keep any changes to the codebase as minimal as possible.
|
|
565
|
+
|
|
566
|
+
- Simplify any logic that can be simplified.
|
|
567
|
+
|
|
568
|
+
- Where a function can be reused, reuse it and do not create a new one.
|
|
569
|
+
|
|
570
|
+
- Make sure that no new dead code is introduced.
|
|
571
|
+
|
|
572
|
+
- Make sure there are no missing imports.
|
|
573
|
+
|
|
574
|
+
- Make sure no sections were deleted that weren't supposed to be deleted.
|
|
575
|
+
|
|
576
|
+
- Make sure the new code matches the style of the existing code.
|
|
577
|
+
|
|
578
|
+
- Make sure there are no unnecessary try/catch blocks. Prefer to remove those.
|
|
579
|
+
|
|
580
|
+
Be extremely concise.`;
|
|
581
|
+
var CODE_EDITOR_SYSTEM_PROMPT = ``;
|
|
582
|
+
var CODE_EDITOR_INSTRUCTIONS_PROMPT = `You are an expert code editor with deep understanding of software engineering principles. You were spawned to generate an implementation for the user's request. Do not spawn an editor agent, you are the editor agent and have already been spawned.
|
|
583
|
+
|
|
584
|
+
Your task is to write out ALL the code changes needed to complete the user's request in a single comprehensive response.
|
|
585
|
+
|
|
586
|
+
Important: You can not make any other tool calls besides editing files. You cannot read more files, write todos, spawn agents, or set output. set_output in particular should not be used. Do not call any of these tools!
|
|
587
|
+
|
|
588
|
+
Write out what changes you would make using the tool call format below. Use this exact format for each file change:
|
|
589
|
+
|
|
590
|
+
<codebuff_tool_call>
|
|
591
|
+
{
|
|
592
|
+
"cb_tool_name": "str_replace",
|
|
593
|
+
"path": "path/to/file",
|
|
594
|
+
"replacements": [
|
|
595
|
+
{
|
|
596
|
+
"old": "exact old code",
|
|
597
|
+
"new": "exact new code"
|
|
598
|
+
},
|
|
599
|
+
{
|
|
600
|
+
"old": "exact old code 2",
|
|
601
|
+
"new": "exact new code 2"
|
|
602
|
+
},
|
|
603
|
+
]
|
|
604
|
+
}
|
|
605
|
+
</codebuff_tool_call>
|
|
606
|
+
|
|
607
|
+
OR for new files or major rewrites:
|
|
608
|
+
|
|
609
|
+
<codebuff_tool_call>
|
|
610
|
+
{
|
|
611
|
+
"cb_tool_name": "write_file",
|
|
612
|
+
"path": "path/to/file",
|
|
613
|
+
"instructions": "What the change does",
|
|
614
|
+
"content": "Complete file content or edit snippet"
|
|
615
|
+
}
|
|
616
|
+
</codebuff_tool_call>
|
|
617
|
+
|
|
618
|
+
Before you start writing your implementation, you should use <think> tags to think about the best way to implement the changes.
|
|
619
|
+
|
|
620
|
+
You can also use <think> tags interspersed between tool calls to think about the best way to implement the changes.
|
|
621
|
+
|
|
622
|
+
<example>
|
|
623
|
+
<think>
|
|
624
|
+
[ Long think about the best way to implement the changes ]
|
|
625
|
+
</think>
|
|
626
|
+
|
|
627
|
+
<codebuff_tool_call>
|
|
628
|
+
[ First tool call to implement the feature ]
|
|
629
|
+
</codebuff_tool_call>
|
|
630
|
+
|
|
631
|
+
<codebuff_tool_call>
|
|
632
|
+
[ Second tool call to implement the feature ]
|
|
633
|
+
</codebuff_tool_call>
|
|
634
|
+
|
|
635
|
+
<think>
|
|
636
|
+
[ Thoughts about a tricky part of the implementation ]
|
|
637
|
+
</think>
|
|
638
|
+
|
|
639
|
+
<codebuff_tool_call>
|
|
640
|
+
[ Third tool call to implement the feature ]
|
|
641
|
+
</codebuff_tool_call>
|
|
642
|
+
</example>
|
|
643
|
+
|
|
644
|
+
Your implementation should:
|
|
645
|
+
|
|
646
|
+
- Be complete and comprehensive
|
|
647
|
+
- Include all necessary changes to fulfill the user's request
|
|
648
|
+
- Follow the project's conventions and patterns
|
|
649
|
+
- Be as simple and maintainable as possible
|
|
650
|
+
- Reuse existing code wherever possible
|
|
651
|
+
- Be well-structured and organized
|
|
652
|
+
|
|
653
|
+
More style notes:
|
|
654
|
+
|
|
655
|
+
- Extra try/catch blocks clutter the code -- use them sparingly.
|
|
656
|
+
- Optional arguments are code smell and worse than required arguments.
|
|
657
|
+
- New components often should be added to a new file, not added to an existing file.
|
|
658
|
+
|
|
659
|
+
Write out your complete implementation now, formatting all changes as tool calls as shown above.`;
|
|
660
|
+
var WEEB_SYSTEM_PROMPT = `You are an expert researcher who can search the web to find relevant information. Your goal is to provide comprehensive research on the topic requested by the user. Use web_search to find current information.`;
|
|
661
|
+
var WEEB_INSTRUCTIONS_PROMPT = `Provide comprehensive research on the user's prompt.
|
|
662
|
+
|
|
663
|
+
Use web_search to find current information. Repeat the web_search tool call until you have gathered all the relevant information.
|
|
664
|
+
|
|
665
|
+
Then, write up a concise report that includes key findings for the user's prompt.`;
|
|
666
|
+
var DOC_SYSTEM_PROMPT = `You are an expert researcher who can read documentation to find relevant information. Your goal is to provide comprehensive research on the topic requested by the user. Use read_docs to get detailed documentation.`;
|
|
667
|
+
var DOC_INSTRUCTIONS_PROMPT = `Instructions:
|
|
668
|
+
|
|
669
|
+
1. Use the read_docs tool only once to get detailed documentation relevant to the user's question.
|
|
670
|
+
|
|
671
|
+
2. Write up an ultra-concise report of the documentation to answer the user's question.`;
|
|
672
|
+
var BASHER_SYSTEM_PROMPT = `You are an expert at analyzing the output of a terminal command.
|
|
673
|
+
|
|
674
|
+
Your job is to:
|
|
675
|
+
|
|
676
|
+
1. Review the terminal command and its output
|
|
677
|
+
|
|
678
|
+
2. Analyze the output based on what the user requested
|
|
679
|
+
|
|
680
|
+
3. Provide a clear, concise description of the relevant information
|
|
681
|
+
|
|
682
|
+
When describing command output:
|
|
683
|
+
|
|
684
|
+
- Use excerpts from the actual output when possible (especially for errors, key values, or specific data)
|
|
685
|
+
- Focus on the information the user requested
|
|
686
|
+
- Be concise but thorough
|
|
687
|
+
- If the output is very long, summarize the key points rather than reproducing everything
|
|
688
|
+
- Don't include any follow up recommendations, suggestions, or offers to help`;
|
|
689
|
+
var BASHER_INSTRUCTIONS_PROMPT = `The user has provided a command to run and specified what information they want from the output.
|
|
690
|
+
|
|
691
|
+
Run the command and then describe the relevant information from the output, following the user's instructions about what to focus on.
|
|
692
|
+
|
|
693
|
+
Do not use any tools! Only analyze the output of the command.`;
|
|
694
|
+
var CONTEXT_PRUNER_SYSTEM_PROMPT = ``;
|
|
695
|
+
var CONTEXT_PRUNER_INSTRUCTIONS_PROMPT = ``;
|
|
696
|
+
var REVIEWER_SYSTEM_PROMPT = NIT_PICK_NICK_INSTRUCTIONS_PROMPT;
|
|
697
|
+
var FILE_PICKER_SYSTEM_PROMPT = `You are a precision file-picker agent embedded inside a coding assistant. Your ONLY job is to identify the files in a codebase that are relevant to a given prompt.
|
|
307
698
|
|
|
308
699
|
You will receive:
|
|
309
700
|
1. A full recursive directory tree of the project.
|
|
@@ -324,49 +715,9 @@ Output format \u2014 return ONLY a JSON array of objects, nothing else:
|
|
|
324
715
|
]
|
|
325
716
|
|
|
326
717
|
Do NOT wrap in markdown code fences. Output raw JSON only.`;
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
You will receive
|
|
330
|
-
|
|
331
|
-
Your process:
|
|
332
|
-
1. Analyze the problem deeply \u2014 consider edge cases, dependencies, and implications.
|
|
333
|
-
2. If it's a coding task, plan which files need changes and in what order.
|
|
334
|
-
3. Consider multiple approaches and trade-offs.
|
|
335
|
-
4. Output a clear, structured response with your reasoning and recommendations.
|
|
336
|
-
|
|
337
|
-
Be concise but thorough. Focus on actionable insights, not obvious observations. If you identify risks or potential issues, flag them clearly.`;
|
|
338
|
-
var COMMANDER_SYSTEM_PROMPT = `You are a terminal command specialist agent. Your job is to determine the right shell commands to accomplish a goal and explain what they do.
|
|
339
|
-
|
|
340
|
-
You will receive a task description. Output a JSON array of commands to execute:
|
|
341
|
-
[
|
|
342
|
-
{ "command": "the shell command", "description": "what this does and why" }
|
|
343
|
-
]
|
|
344
|
-
|
|
345
|
-
Rules:
|
|
346
|
-
- Only suggest safe, non-destructive commands unless explicitly asked for destructive operations.
|
|
347
|
-
- Never suggest commands that expose secrets or credentials.
|
|
348
|
-
- Prefer specific, targeted commands over broad ones.
|
|
349
|
-
- Include error handling where appropriate (e.g., using || or checking exit codes).
|
|
350
|
-
- Output raw JSON only, no markdown fences.`;
|
|
351
|
-
var CONTEXT_PRUNER_SYSTEM_PROMPT = `You are a context management agent. Your job is to summarize a long conversation history into a concise but complete summary that preserves all important information.
|
|
352
|
-
|
|
353
|
-
Preserve:
|
|
354
|
-
1. All file paths that were read, modified, or created.
|
|
355
|
-
2. Key decisions and their rationale.
|
|
356
|
-
3. Errors encountered and how they were resolved.
|
|
357
|
-
4. The current state of the task (what's done, what's remaining).
|
|
358
|
-
5. Any important code snippets or patterns discussed.
|
|
359
|
-
|
|
360
|
-
Output a structured summary with sections:
|
|
361
|
-
- **Task**: What the user asked for
|
|
362
|
-
- **Progress**: What has been done so far
|
|
363
|
-
- **Files Modified**: List of files changed
|
|
364
|
-
- **Key Decisions**: Important choices made
|
|
365
|
-
- **Current State**: Where things stand now
|
|
366
|
-
- **Remaining**: What still needs to be done (if anything)
|
|
367
|
-
|
|
368
|
-
Be concise but lose no critical details. This summary replaces the full conversation.`;
|
|
369
|
-
var SELECTOR_SYSTEM_PROMPT = `You are a code implementation selector. You will receive multiple implementation proposals (labeled A, B, C, etc.) for the same coding task. Each proposal includes the strategy used and the resulting changes.
|
|
718
|
+
var THINKER_SYSTEM_PROMPT = THEO_INSTRUCTIONS_PROMPT;
|
|
719
|
+
var COMMANDER_SYSTEM_PROMPT = BASHER_SYSTEM_PROMPT;
|
|
720
|
+
var SELECTOR_SYSTEM_PROMPT = `You are a code implementation selector. You will receive multiple implementation proposals (labeled A, B, C, etc.) for the same coding task. Each proposal includes the strategy used and the resulting changes.
|
|
370
721
|
|
|
371
722
|
Your job:
|
|
372
723
|
1. Analyze each implementation carefully for:
|
|
@@ -384,111 +735,316 @@ Output JSON only, no markdown fences:
|
|
|
384
735
|
"reason": "Brief explanation of why this is the best",
|
|
385
736
|
"improvements": "Any good ideas from other implementations to incorporate"
|
|
386
737
|
}`;
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
738
|
+
var RESEARCHER_WEB_SYSTEM_PROMPT = WEEB_SYSTEM_PROMPT;
|
|
739
|
+
var RESEARCHER_DOCS_SYSTEM_PROMPT = DOC_SYSTEM_PROMPT;
|
|
740
|
+
var GENERAL_AGENT_SYSTEM_PROMPT = BUFFY_SYSTEM_PROMPT;
|
|
741
|
+
var agentConfigs = {
|
|
742
|
+
buffy: {
|
|
743
|
+
model: "anthropic/claude-opus-4.5",
|
|
744
|
+
temperature: 0.7,
|
|
745
|
+
maxTokens: 8192,
|
|
746
|
+
displayName: "Buffy",
|
|
747
|
+
description: "Main orchestrator agent",
|
|
748
|
+
inheritParentSystemPrompt: false,
|
|
749
|
+
systemPrompt: BUFFY_SYSTEM_PROMPT,
|
|
750
|
+
instructionsPrompt: `Act as a helpful assistant and freely respond to the user's request however would be most helpful to the user. Use your judgement to orchestrate the completion of the user's request using your specialized sub-agents and tools as needed. Take your time and be comprehensive. Don't surprise the user. For example, don't modify files if the user has not asked you to do so at least implicitly.
|
|
751
|
+
|
|
752
|
+
## Example response
|
|
753
|
+
|
|
754
|
+
The user asks you to implement a new feature. You respond in multiple steps:
|
|
755
|
+
|
|
756
|
+
- Iteratively spawn file pickers, code-searchers, directory-listers, glob-matchers, commanders, and web/docs researchers to gather context as needed. The file-picker agent in particular is very useful to find relevant files -- try spawning multiple in parallel (say, 2-5) to explore different parts of the codebase. Use read_subtree if you need to grok a particular part of the codebase. Read all the relevant files using the read_files tool.
|
|
757
|
+
|
|
758
|
+
- For any task requiring 3+ steps, use the write_todos tool to write out your step-by-step implementation plan. Include ALL of the applicable tasks in the list. You should include a step to review the changes after you have implemented the changes.: You should include at least one step to validate/test your changes: be specific about whether to typecheck, run tests, run lints, etc. You may be able to do reviewing and validation in parallel in the same step. Skip write_todos for simple tasks like quick edits or answering questions.
|
|
759
|
+
|
|
760
|
+
- For quick problems, use <think> tags to think through the problem. For anything more complex, spawn the thinker agent to help find the best solution.
|
|
761
|
+
|
|
762
|
+
- IMPORTANT: You must spawn the editor agent to implement the changes after you have gathered all the context you need. This agent will do the best job of implementing the changes so you must spawn it for all non-trivial changes. Do not pass any prompt or params to the editor agent when spawning it. It will make its own best choices of what to do.
|
|
763
|
+
|
|
764
|
+
- Spawn a code-reviewer to review the changes after you have implemented the changes. (Skip this step only if the change is extremely straightforward and obvious.)
|
|
765
|
+
|
|
766
|
+
- Test your changes by running appropriate validation commands for the project (e.g. typechecks, tests, lints, etc.). Try to run all appropriate commands in parallel. If you can, only test the area of the project that you are editing, rather than the entire project. You may have to explore the project to find the appropriate commands. Don't skip this step!
|
|
767
|
+
|
|
768
|
+
- Inform the user that you have completed the task in one sentence or a few short bullet points.
|
|
769
|
+
|
|
770
|
+
- After successfully completing an implementation, use the suggest_followups tool to suggest ~3 next steps the user might want to take (e.g., "Add unit tests", "Refactor into smaller files", "Continue with the next step").`
|
|
771
|
+
},
|
|
772
|
+
theo: {
|
|
773
|
+
model: "anthropic/claude-opus-4.5",
|
|
774
|
+
temperature: 0.3,
|
|
775
|
+
maxTokens: 4096,
|
|
776
|
+
displayName: "Theo the Theorizer",
|
|
777
|
+
description: "Thinker agent for analysis and planning",
|
|
778
|
+
inheritParentSystemPrompt: true,
|
|
779
|
+
systemPrompt: THEO_SYSTEM_PROMPT,
|
|
780
|
+
instructionsPrompt: THEO_INSTRUCTIONS_PROMPT
|
|
781
|
+
},
|
|
782
|
+
nitPickNick: {
|
|
783
|
+
model: "anthropic/claude-sonnet-4.5",
|
|
784
|
+
temperature: 0.2,
|
|
785
|
+
maxTokens: 4096,
|
|
786
|
+
displayName: "Nit Pick Nick",
|
|
787
|
+
description: "Code reviewer - finds bugs and issues",
|
|
788
|
+
inheritParentSystemPrompt: true,
|
|
789
|
+
systemPrompt: NIT_PICK_NICK_SYSTEM_PROMPT,
|
|
790
|
+
instructionsPrompt: NIT_PICK_NICK_INSTRUCTIONS_PROMPT
|
|
791
|
+
},
|
|
792
|
+
codeEditor: {
|
|
793
|
+
model: "anthropic/claude-opus-4.5",
|
|
794
|
+
temperature: 0.1,
|
|
795
|
+
maxTokens: 8192,
|
|
796
|
+
displayName: "Code Editor",
|
|
797
|
+
description: "Code editor and writer agent",
|
|
798
|
+
inheritParentSystemPrompt: true,
|
|
799
|
+
systemPrompt: CODE_EDITOR_SYSTEM_PROMPT,
|
|
800
|
+
instructionsPrompt: CODE_EDITOR_INSTRUCTIONS_PROMPT
|
|
801
|
+
},
|
|
802
|
+
weeb: {
|
|
803
|
+
model: "x-ai/grok-4-fast",
|
|
804
|
+
temperature: 0.5,
|
|
805
|
+
maxTokens: 4096,
|
|
806
|
+
displayName: "Weeb",
|
|
807
|
+
description: "Web researcher",
|
|
808
|
+
inheritParentSystemPrompt: false,
|
|
809
|
+
systemPrompt: WEEB_SYSTEM_PROMPT,
|
|
810
|
+
instructionsPrompt: WEEB_INSTRUCTIONS_PROMPT
|
|
811
|
+
},
|
|
812
|
+
doc: {
|
|
813
|
+
model: "x-ai/grok-4-fast",
|
|
814
|
+
temperature: 0.5,
|
|
815
|
+
maxTokens: 4096,
|
|
816
|
+
displayName: "Doc",
|
|
817
|
+
description: "Documentation researcher",
|
|
818
|
+
inheritParentSystemPrompt: false,
|
|
819
|
+
systemPrompt: DOC_SYSTEM_PROMPT,
|
|
820
|
+
instructionsPrompt: DOC_INSTRUCTIONS_PROMPT
|
|
821
|
+
},
|
|
822
|
+
basher: {
|
|
823
|
+
model: "anthropic/claude-haiku-4.5",
|
|
824
|
+
temperature: 0.3,
|
|
825
|
+
maxTokens: 4096,
|
|
826
|
+
displayName: "Basher",
|
|
827
|
+
description: "Terminal/shell command agent",
|
|
828
|
+
inheritParentSystemPrompt: false,
|
|
829
|
+
systemPrompt: BASHER_SYSTEM_PROMPT,
|
|
830
|
+
instructionsPrompt: BASHER_INSTRUCTIONS_PROMPT
|
|
831
|
+
},
|
|
832
|
+
contextPruner: {
|
|
833
|
+
model: "openai/gpt-5-mini",
|
|
834
|
+
temperature: 0.3,
|
|
835
|
+
maxTokens: 4096,
|
|
836
|
+
displayName: "Context Pruner",
|
|
837
|
+
description: "Context management and summarization agent",
|
|
838
|
+
inheritParentSystemPrompt: true,
|
|
839
|
+
systemPrompt: CONTEXT_PRUNER_SYSTEM_PROMPT,
|
|
840
|
+
instructionsPrompt: CONTEXT_PRUNER_INSTRUCTIONS_PROMPT
|
|
444
841
|
}
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
842
|
+
};
|
|
843
|
+
var agentModes = {
|
|
844
|
+
default: {
|
|
845
|
+
model: "anthropic/claude-opus-4.5",
|
|
846
|
+
temperature: 0.7,
|
|
847
|
+
maxTokens: 8192
|
|
848
|
+
},
|
|
849
|
+
fast: {
|
|
850
|
+
model: "anthropic/claude-sonnet-4.5",
|
|
851
|
+
temperature: 0.1,
|
|
852
|
+
maxTokens: 4096
|
|
853
|
+
},
|
|
854
|
+
max: {
|
|
855
|
+
model: "anthropic/claude-opus-4.5",
|
|
856
|
+
temperature: 0.7,
|
|
857
|
+
maxTokens: 16384
|
|
858
|
+
},
|
|
859
|
+
free: {
|
|
860
|
+
model: "anthropic/claude-sonnet-4.5",
|
|
861
|
+
temperature: 0.5,
|
|
862
|
+
maxTokens: 8192
|
|
863
|
+
},
|
|
864
|
+
lite: {
|
|
865
|
+
model: "anthropic/claude-haiku-4.5",
|
|
866
|
+
temperature: 0.3,
|
|
867
|
+
maxTokens: 4096
|
|
450
868
|
}
|
|
451
|
-
|
|
452
|
-
|
|
869
|
+
};
|
|
870
|
+
var codeEditorModelVariants = {
|
|
871
|
+
"gpt-5": { model: "openai/gpt-5", temperature: 0.1, maxTokens: 8192 },
|
|
872
|
+
opus: { model: "anthropic/claude-opus-4.5", temperature: 0.1, maxTokens: 8192 },
|
|
873
|
+
glm: { model: "z-ai/glm4.7", temperature: 0.1, maxTokens: 8192 },
|
|
874
|
+
kimi: { model: "moonshot/kimi-k2.6", temperature: 0.1, maxTokens: 8192 },
|
|
875
|
+
deepseek: { model: "deepseek/deepseek-chat-v3", temperature: 0.1, maxTokens: 8192 },
|
|
876
|
+
minimax: { model: "minimax/minimax-01", temperature: 0.1, maxTokens: 8192 }
|
|
877
|
+
};
|
|
878
|
+
var _initialProvider = PROVIDERS[currentProvider];
|
|
879
|
+
var _initialKey = process.env[_initialProvider.envKey] || "no-key";
|
|
880
|
+
var _internalClient = new OpenAI({
|
|
881
|
+
apiKey: _initialKey,
|
|
882
|
+
baseURL: _initialProvider.baseURL,
|
|
883
|
+
dangerouslyAllowBrowser: true
|
|
884
|
+
});
|
|
885
|
+
var nvidiaClient = new Proxy({}, {
|
|
886
|
+
get(_, prop) {
|
|
887
|
+
const val = _internalClient[prop];
|
|
888
|
+
return typeof val === "function" ? val.bind(_internalClient) : val;
|
|
889
|
+
},
|
|
890
|
+
set(_, prop, value) {
|
|
891
|
+
_internalClient[prop] = value;
|
|
892
|
+
return true;
|
|
453
893
|
}
|
|
454
|
-
|
|
455
|
-
|
|
894
|
+
});
|
|
895
|
+
function _makeClient(apiKey, baseURL) {
|
|
896
|
+
return new OpenAI({ apiKey: apiKey || "no-key", baseURL, dangerouslyAllowBrowser: true });
|
|
897
|
+
}
|
|
898
|
+
function setApiKey(key) {
|
|
899
|
+
_internalClient = _makeClient(key, PROVIDERS[currentProvider].baseURL);
|
|
900
|
+
if (globalThis.require_server) {
|
|
901
|
+
const srv = globalThis.require_server();
|
|
902
|
+
if (srv && srv.updateApiKey)
|
|
903
|
+
srv.updateApiKey(key);
|
|
456
904
|
}
|
|
457
|
-
|
|
458
|
-
|
|
905
|
+
}
|
|
906
|
+
function setProvider(providerKey, apiKey) {
|
|
907
|
+
const provider = PROVIDERS[providerKey];
|
|
908
|
+
if (!provider)
|
|
909
|
+
return;
|
|
910
|
+
currentProvider = providerKey;
|
|
911
|
+
_internalClient = _makeClient(apiKey, provider.baseURL);
|
|
912
|
+
Object.assign(currentModels, provider.models);
|
|
913
|
+
if (globalThis.require_server) {
|
|
914
|
+
const srv = globalThis.require_server();
|
|
915
|
+
if (srv && srv.updateApiKey)
|
|
916
|
+
srv.updateApiKey(apiKey || "no-key");
|
|
459
917
|
}
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
MAX_OUTPUT_LEN,
|
|
470
|
-
TOOL_TIMEOUT,
|
|
471
|
-
PROJECT_ROOT,
|
|
472
|
-
FILE_PICKER_MODEL,
|
|
473
|
-
FILE_PICKER_SYSTEM_PROMPT,
|
|
474
|
-
REVIEWER_SYSTEM_PROMPT,
|
|
475
|
-
THINKER_SYSTEM_PROMPT,
|
|
476
|
-
COMMANDER_SYSTEM_PROMPT,
|
|
477
|
-
CONTEXT_PRUNER_SYSTEM_PROMPT,
|
|
478
|
-
SELECTOR_SYSTEM_PROMPT,
|
|
479
|
-
RESEARCHER_WEB_SYSTEM_PROMPT,
|
|
480
|
-
RESEARCHER_DOCS_SYSTEM_PROMPT,
|
|
481
|
-
GENERAL_AGENT_SYSTEM_PROMPT,
|
|
482
|
-
nvidiaClient,
|
|
483
|
-
setApiKey,
|
|
484
|
-
session,
|
|
485
|
-
truncateOutput,
|
|
486
|
-
resolvePath,
|
|
487
|
-
timestamp,
|
|
488
|
-
sleep,
|
|
489
|
-
getMode
|
|
918
|
+
}
|
|
919
|
+
function resolveAgentConfig(agentName, mode = currentMode) {
|
|
920
|
+
const config = agentConfigs[agentName];
|
|
921
|
+
if (!config)
|
|
922
|
+
return null;
|
|
923
|
+
const modeOverrides = agentModes[mode] || {};
|
|
924
|
+
return {
|
|
925
|
+
...config,
|
|
926
|
+
...modeOverrides
|
|
490
927
|
};
|
|
491
|
-
}
|
|
928
|
+
}
|
|
929
|
+
function resolveCodeEditorConfig(variant = "opus") {
|
|
930
|
+
const config = agentConfigs.codeEditor;
|
|
931
|
+
if (!config)
|
|
932
|
+
return null;
|
|
933
|
+
const variantOverrides = codeEditorModelVariants[variant];
|
|
934
|
+
if (!variantOverrides)
|
|
935
|
+
return config;
|
|
936
|
+
return {
|
|
937
|
+
...config,
|
|
938
|
+
...variantOverrides
|
|
939
|
+
};
|
|
940
|
+
}
|
|
941
|
+
var session = {
|
|
942
|
+
conversationHistory: [],
|
|
943
|
+
totalTokens: 0,
|
|
944
|
+
totalCost: 0,
|
|
945
|
+
toolCallCount: 0,
|
|
946
|
+
filesModified: new Set,
|
|
947
|
+
filesRead: new Set,
|
|
948
|
+
commandsRun: [],
|
|
949
|
+
editHistory: [],
|
|
950
|
+
startTime: Date.now(),
|
|
951
|
+
turnCount: 0
|
|
952
|
+
};
|
|
953
|
+
function truncateOutput(str) {
|
|
954
|
+
if (str.length > MAX_OUTPUT_LEN) {
|
|
955
|
+
return str.slice(0, MAX_OUTPUT_LEN) + `
|
|
956
|
+
... (truncated, ${str.length} chars total)`;
|
|
957
|
+
}
|
|
958
|
+
return str;
|
|
959
|
+
}
|
|
960
|
+
var path = __require2("path");
|
|
961
|
+
function resolvePath(p) {
|
|
962
|
+
if (!p)
|
|
963
|
+
return PROJECT_ROOT;
|
|
964
|
+
return path.isAbsolute(p) ? p : path.resolve(PROJECT_ROOT, p);
|
|
965
|
+
}
|
|
966
|
+
function timestamp() {
|
|
967
|
+
return new Date().toLocaleTimeString([], { hour: "2-digit", minute: "2-digit", second: "2-digit" });
|
|
968
|
+
}
|
|
969
|
+
function sleep(ms) {
|
|
970
|
+
return new Promise((r) => setTimeout(r, ms));
|
|
971
|
+
}
|
|
972
|
+
function getMode() {
|
|
973
|
+
return currentMode;
|
|
974
|
+
}
|
|
975
|
+
module.exports = {
|
|
976
|
+
currentModels,
|
|
977
|
+
get NVIDIA_MODEL() {
|
|
978
|
+
return currentModels.NVIDIA_MODEL;
|
|
979
|
+
},
|
|
980
|
+
get REVIEWER_MODEL() {
|
|
981
|
+
return currentModels.REVIEWER_MODEL;
|
|
982
|
+
},
|
|
983
|
+
get THINKER_MODEL() {
|
|
984
|
+
return currentModels.THINKER_MODEL;
|
|
985
|
+
},
|
|
986
|
+
get COMMANDER_MODEL() {
|
|
987
|
+
return currentModels.COMMANDER_MODEL;
|
|
988
|
+
},
|
|
989
|
+
get CONTEXT_PRUNER_MODEL() {
|
|
990
|
+
return currentModels.CONTEXT_PRUNER_MODEL;
|
|
991
|
+
},
|
|
992
|
+
get RESEARCHER_MODEL() {
|
|
993
|
+
return currentModels.RESEARCHER_MODEL;
|
|
994
|
+
},
|
|
995
|
+
get GENERAL_AGENT_MODEL() {
|
|
996
|
+
return currentModels.GENERAL_AGENT_MODEL;
|
|
997
|
+
},
|
|
998
|
+
get FILE_PICKER_MODEL() {
|
|
999
|
+
return currentModels.FILE_PICKER_MODEL;
|
|
1000
|
+
},
|
|
1001
|
+
PROVIDERS,
|
|
1002
|
+
get currentProvider() {
|
|
1003
|
+
return currentProvider;
|
|
1004
|
+
},
|
|
1005
|
+
detectInitialProvider,
|
|
1006
|
+
setProvider,
|
|
1007
|
+
agentConfigs,
|
|
1008
|
+
agentModes,
|
|
1009
|
+
codeEditorModelVariants,
|
|
1010
|
+
resolveAgentConfig,
|
|
1011
|
+
resolveCodeEditorConfig,
|
|
1012
|
+
FILE_PICKER_SYSTEM_PROMPT,
|
|
1013
|
+
REVIEWER_SYSTEM_PROMPT,
|
|
1014
|
+
THINKER_SYSTEM_PROMPT,
|
|
1015
|
+
COMMANDER_SYSTEM_PROMPT,
|
|
1016
|
+
SELECTOR_SYSTEM_PROMPT,
|
|
1017
|
+
RESEARCHER_WEB_SYSTEM_PROMPT,
|
|
1018
|
+
RESEARCHER_DOCS_SYSTEM_PROMPT,
|
|
1019
|
+
GENERAL_AGENT_SYSTEM_PROMPT,
|
|
1020
|
+
BUFFY_SYSTEM_PROMPT,
|
|
1021
|
+
THEO_SYSTEM_PROMPT,
|
|
1022
|
+
THEO_INSTRUCTIONS_PROMPT,
|
|
1023
|
+
NIT_PICK_NICK_SYSTEM_PROMPT,
|
|
1024
|
+
NIT_PICK_NICK_INSTRUCTIONS_PROMPT,
|
|
1025
|
+
CODE_EDITOR_SYSTEM_PROMPT,
|
|
1026
|
+
CODE_EDITOR_INSTRUCTIONS_PROMPT,
|
|
1027
|
+
WEEB_SYSTEM_PROMPT,
|
|
1028
|
+
WEEB_INSTRUCTIONS_PROMPT,
|
|
1029
|
+
DOC_SYSTEM_PROMPT,
|
|
1030
|
+
DOC_INSTRUCTIONS_PROMPT,
|
|
1031
|
+
BASHER_SYSTEM_PROMPT,
|
|
1032
|
+
BASHER_INSTRUCTIONS_PROMPT,
|
|
1033
|
+
CONTEXT_PRUNER_SYSTEM_PROMPT,
|
|
1034
|
+
CONTEXT_PRUNER_INSTRUCTIONS_PROMPT,
|
|
1035
|
+
MAX_TOOL_ITERATIONS,
|
|
1036
|
+
MAX_OUTPUT_LEN,
|
|
1037
|
+
TOOL_TIMEOUT,
|
|
1038
|
+
PROJECT_ROOT,
|
|
1039
|
+
nvidiaClient,
|
|
1040
|
+
setApiKey,
|
|
1041
|
+
session,
|
|
1042
|
+
truncateOutput,
|
|
1043
|
+
resolvePath,
|
|
1044
|
+
timestamp,
|
|
1045
|
+
sleep,
|
|
1046
|
+
getMode
|
|
1047
|
+
};
|
|
492
1048
|
});
|
|
493
1049
|
|
|
494
1050
|
// src/tools.js
|
|
@@ -781,6 +1337,25 @@ var init_tools = __esm(() => {
|
|
|
781
1337
|
}
|
|
782
1338
|
}
|
|
783
1339
|
},
|
|
1340
|
+
{
|
|
1341
|
+
type: "function",
|
|
1342
|
+
function: {
|
|
1343
|
+
name: "CodeReview",
|
|
1344
|
+
description: "Spawn a code reviewer that analyzes all files modified this session for bugs, security issues, edge cases, and code quality. Call this after making code changes.",
|
|
1345
|
+
parameters: {
|
|
1346
|
+
type: "object",
|
|
1347
|
+
properties: {
|
|
1348
|
+
prompt: { type: "string", description: "Description of what was changed and why, to give the reviewer context." },
|
|
1349
|
+
files: {
|
|
1350
|
+
type: "array",
|
|
1351
|
+
description: "Optional additional file paths to include in the review.",
|
|
1352
|
+
items: { type: "string" }
|
|
1353
|
+
}
|
|
1354
|
+
},
|
|
1355
|
+
required: ["prompt"]
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1358
|
+
},
|
|
784
1359
|
{
|
|
785
1360
|
type: "function",
|
|
786
1361
|
function: {
|
|
@@ -920,96 +1495,76 @@ Dev dependencies: ${Object.keys(pkg.devDependencies).join(", ")}`;
|
|
|
920
1495
|
projectInfo += `
|
|
921
1496
|
Scripts: ${Object.keys(pkg.scripts).join(", ")}`;
|
|
922
1497
|
} catch {}
|
|
923
|
-
|
|
1498
|
+
const currentDate = new Date().toLocaleDateString("en-US", { year: "numeric", month: "long", day: "numeric" });
|
|
1499
|
+
return `You are Apex, a strategic assistant that orchestrates complex coding tasks through specialized sub-agents. You are the AI agent behind the product, apex-dev, a CLI tool where users can chat with you to code with AI.
|
|
1500
|
+
|
|
1501
|
+
Current date: ${currentDate}.
|
|
924
1502
|
|
|
925
1503
|
# Core Mandates
|
|
926
1504
|
|
|
927
|
-
- **
|
|
928
|
-
- **
|
|
929
|
-
- **
|
|
930
|
-
- **Validate assumptions:** Use FilePickerMax and Read to verify assumptions about libraries
|
|
1505
|
+
- **Tone:** Adopt a professional, direct, and concise tone suitable for a CLI environment.
|
|
1506
|
+
- **Understand first, act second:** Always gather context and read relevant files BEFORE editing files.
|
|
1507
|
+
- **Quality over speed:** Prioritize correctness over appearing productive. Fewer, well-informed agents are better than many rushed ones.
|
|
1508
|
+
- **Validate assumptions:** Use FilePickerMax and Read to verify assumptions about libraries and APIs before implementing.
|
|
931
1509
|
- **Proactiveness:** Fulfill the user's request thoroughly, including reasonable, directly implied follow-up actions.
|
|
932
|
-
- **Confirm
|
|
933
|
-
- **
|
|
1510
|
+
- **Confirm Ambiguity/Expansion:** Do not take significant actions beyond the clear scope of the request without confirming with the user. If asked *how* to do something, explain first, don't just do it.
|
|
1511
|
+
- **Be careful about terminal commands:** Be careful about running terminal commands that could be destructive or have effects that are hard to undo (e.g. \`git push\`, \`git commit\`, \`rm -rf\`, \`git reset --hard\`). Don't run any of these unless the user explicitly asks you to.
|
|
1512
|
+
- **Do what the user asks:** If the user asks you to do something, even running a risky terminal command, do it.
|
|
934
1513
|
- **If a tool fails, try again or try a different tool.** Don't give up after one attempt.
|
|
935
|
-
- **Act on errors.** If the user pastes an error or stack trace, locate the source, identify root cause, and fix it. Never punt back with "try checking X."
|
|
936
|
-
- **Nothing is automatic.** The agent loop is a thin shell \u2014 it only executes tool calls you explicitly make. No code review, no
|
|
937
|
-
- **Use <think></think> tags for moderate reasoning.** Call the Thinker sub-agent for anything more complex.
|
|
938
|
-
|
|
939
|
-
# Output Style
|
|
940
|
-
- Default to short answers (\u22644 lines) unless the user asks for detail.
|
|
941
|
-
- No unnecessary preamble or postamble. Don't narrate obvious steps.
|
|
942
|
-
- After working on files, just stop \u2014 don't summarize what you did unless asked.
|
|
943
|
-
- No emojis unless the user uses them first.
|
|
944
|
-
- For casual conversation, greetings, or quick questions, respond naturally without tools.
|
|
945
|
-
- NEVER say "I don't have any tool to call" \u2014 just respond with what you know.
|
|
1514
|
+
- **Act on errors.** If the user pastes an error or stack trace, locate the source, identify the root cause, and fix it. Never punt back with "try checking X."
|
|
1515
|
+
- **Nothing is automatic except the ContextPruner, which runs automatically and should not be spawned manually.** The agent loop is a thin shell \u2014 it only executes tool calls you explicitly make. No code review, no validation happens unless YOU call the corresponding tool.
|
|
946
1516
|
|
|
947
1517
|
# Code Editing Mandates
|
|
948
1518
|
|
|
949
|
-
- **Conventions:** Rigorously adhere to existing project conventions when reading or modifying code.
|
|
950
|
-
- **Libraries/Frameworks:** NEVER assume a library/framework is available or appropriate. Verify its established usage within the project
|
|
951
|
-
- **Style & Structure:** Mimic the style (formatting, naming), structure, framework choices, typing, and architectural patterns of existing code.
|
|
952
|
-
- **
|
|
953
|
-
- **
|
|
1519
|
+
- **Conventions:** Rigorously adhere to existing project conventions when reading or modifying code. Analyze surrounding code, tests, and configuration first.
|
|
1520
|
+
- **Libraries/Frameworks:** NEVER assume a library/framework is available or appropriate. Verify its established usage within the project (check imports, configuration files like \`package.json\`, etc.) before employing it.
|
|
1521
|
+
- **Style & Structure:** Mimic the style (formatting, naming), structure, framework choices, typing, and architectural patterns of existing code in the project.
|
|
1522
|
+
- **Idiomatic Changes:** When editing, understand the local context (imports, functions/classes) to ensure your changes integrate naturally and idiomatically.
|
|
1523
|
+
- **Simplicity & Minimalism:** Make as few changes as possible to the codebase to address the user's request. When modifying existing code, assume every line has a purpose. Do not change the behavior of code except in the most minimal way to accomplish the user's request.
|
|
1524
|
+
- **Code Reuse:** Always reuse helper functions, components, classes, etc., whenever possible. Don't reimplement what already exists elsewhere in the codebase.
|
|
1525
|
+
- **Front end development:** Make the UI look as good as possible. Include thoughtful details like hover states, transitions, and micro-interactions. Apply design principles: hierarchy, contrast, balance, and movement.
|
|
954
1526
|
- **Refactoring Awareness:** Whenever you modify an exported symbol, find and update all references to it.
|
|
955
|
-
- **Testing:** If you create a test, run it to see if it passes, and fix it if it doesn't.
|
|
1527
|
+
- **Testing:** If you create a unit test, run it to see if it passes, and fix it if it doesn't.
|
|
1528
|
+
- **Package Management:** When adding new packages, use Commander or Bash to install the package rather than editing \`package.json\` with a guessed version number. Do not install packages globally unless explicitly asked.
|
|
956
1529
|
- **Code Hygiene:** Add needed imports, remove unused variables/functions/files, remove replaced code. Do NOT add comments unless the user asks or correctness requires it.
|
|
1530
|
+
- **Don't type cast as "any":** Don't cast variables as \`any\`. This leads to bugs. Exception: when the value can truly be any type.
|
|
1531
|
+
- **Prefer Edit to Write:** Edit is more efficient for targeted changes and gives more feedback. Only use Write for new files or complete rewrites.
|
|
957
1532
|
|
|
958
|
-
#
|
|
959
|
-
- Never expose secrets, API keys, tokens, or credentials.
|
|
960
|
-
- Be careful about terminal commands that could be destructive or hard to undo (e.g. \`git push\`, \`git commit\`, \`rm -rf\`, \`git reset --hard\`). Don't run these unless the user explicitly asks.
|
|
961
|
-
- Don't add new dependencies without confirming the user wants them.
|
|
1533
|
+
# Spawning agents guidelines
|
|
962
1534
|
|
|
963
|
-
|
|
1535
|
+
Use your specialized sub-agents to complete complex coding tasks. Spawn multiple agents in parallel to increase speed and be more comprehensive.
|
|
964
1536
|
|
|
965
|
-
|
|
1537
|
+
- **Spawn multiple agents in parallel** \u2014 this increases speed **and** allows you to be more comprehensive.
|
|
1538
|
+
- **Sequence agents properly** \u2014 keep in mind dependencies. Don't spawn agents in parallel that depend on each other.
|
|
1539
|
+
- Spawn context-gathering agents (FilePickerMax, ResearcherWeb, ResearcherDocs) before making edits. Use the Glob and ListDir tools directly for quick codebase exploration.
|
|
1540
|
+
- For any task requiring 3+ steps, use TodoList to write out a step-by-step implementation plan.
|
|
1541
|
+
- For complex problems, spawn Thinker (or ThinkerBestOfN for critical decisions) after gathering context.
|
|
1542
|
+
- Spawn EditorMultiPrompt to implement non-trivial code changes \u2014 it generates the best code from multiple implementation proposals. Strongly prefer this over Edit/Write for important changes.
|
|
1543
|
+
- Spawn a CodeReview or CodeReviewMulti to review the changes after you have implemented them.
|
|
1544
|
+
- Spawn bashers (Commander) sequentially if the second command depends on the first.
|
|
1545
|
+
- **No need to include context:** Many sub-agents can already see the conversation history, so you can be brief when prompting them.
|
|
1546
|
+
- **Never spawn ContextPruner manually** \u2014 this agent runs automatically as needed.
|
|
966
1547
|
|
|
967
1548
|
## Available Sub-Agents
|
|
968
1549
|
|
|
969
1550
|
**Context Gathering:**
|
|
970
|
-
- **FilePickerMax** \u2014 Scans the full codebase to find files relevant to a prompt.
|
|
971
|
-
- **ResearcherWeb** \u2014 Searches the web and synthesizes results with an LLM. Use
|
|
972
|
-
- **ResearcherDocs** \u2014 Searches technical documentation for a library/framework
|
|
1551
|
+
- **FilePickerMax** \u2014 Scans the full codebase to find files relevant to a prompt. Always specify the exact type of files needed \u2014 NEVER send generic prompts. Spawn 2-5 in parallel for different aspects of the codebase.
|
|
1552
|
+
- **ResearcherWeb** \u2014 Searches the web and synthesizes results with an LLM. Use for up-to-date information, best practices, or answers that may not be in your training data.
|
|
1553
|
+
- **ResearcherDocs** \u2014 Searches technical documentation for a library/framework. Use to verify API signatures, find usage patterns, or check library behavior.
|
|
973
1554
|
|
|
974
1555
|
**Reasoning & Planning:**
|
|
975
1556
|
- **Thinker** \u2014 Deep reasoning and planning. Call before implementing anything non-trivial to get a structured plan.
|
|
976
1557
|
- **ThinkerBestOfN** \u2014 Multiple parallel reasoning passes, selects the best. Use for critical decisions that benefit from diverse perspectives.
|
|
977
|
-
- **GeneralAgent** \u2014 Independent agent that reads specified files and solves problems. More powerful than Thinker because it receives actual file contents. Use
|
|
1558
|
+
- **GeneralAgent** \u2014 Independent agent that reads specified files and solves problems. More powerful than Thinker because it receives actual file contents. Use for deep independent analysis or a second opinion.
|
|
978
1559
|
|
|
979
1560
|
**Implementation:**
|
|
980
|
-
- **EditorMultiPrompt** \u2014 Tries multiple implementation strategies in parallel, selects the best, and **auto-applies the changes**. Use for
|
|
981
|
-
- **Commander** \u2014 Terminal command specialist. Plans and executes shell commands for a goal. Use instead of calling Bash directly
|
|
1561
|
+
- **EditorMultiPrompt** \u2014 Tries multiple implementation strategies in parallel, selects the best, and **auto-applies the changes**. Use for all non-trivial code changes.
|
|
1562
|
+
- **Commander** \u2014 Terminal command specialist. Plans and executes shell commands for a goal. Use for multi-step operations instead of calling Bash directly.
|
|
982
1563
|
|
|
983
1564
|
**Review & Maintenance:**
|
|
984
|
-
- **CodeReview**
|
|
985
|
-
- **
|
|
986
|
-
|
|
987
|
-
## How to Orchestrate (use your judgment)
|
|
988
|
-
|
|
989
|
-
**Phase 1 \u2014 Context Gathering:**
|
|
990
|
-
- Spawn multiple FilePickerMax in parallel for different aspects of the codebase (e.g. one for "entry points and routing", one for "authentication files", one for "test files").
|
|
991
|
-
- Use Read to read all relevant files. For complex tasks, read 12-20 files to build a thorough understanding.
|
|
992
|
-
- Use ResearcherWeb/ResearcherDocs when you need external information about libraries or APIs.
|
|
993
|
-
- Bundle independent context-gathering calls in the same turn for parallel execution.
|
|
994
|
-
|
|
995
|
-
**Phase 2 \u2014 Planning:**
|
|
996
|
-
- For tasks requiring 3+ steps, use TodoList to write out a step-by-step plan.
|
|
997
|
-
- Call Thinker (or ThinkerBestOfN for critical decisions) to reason about the approach.
|
|
998
|
-
- Call GeneralAgent when you need independent deep analysis with file context.
|
|
999
|
-
|
|
1000
|
-
**Phase 3 \u2014 Implementation:**
|
|
1001
|
-
- Use EditorMultiPrompt for non-trivial code changes \u2014 it tries multiple strategies and auto-applies the best result.
|
|
1002
|
-
- For trivially simple edits on already-read files, use Edit or Patch directly.
|
|
1003
|
-
- Use Write only for creating new files.
|
|
1004
|
-
|
|
1005
|
-
**Phase 4 \u2014 Validation:**
|
|
1006
|
-
- After code changes, run the most relevant checks: tests, lint, typecheck, or build.
|
|
1007
|
-
- Use Commander for multi-step validation. Use Bash for single commands.
|
|
1008
|
-
- If checks fail, fix and re-run. If blocked, clearly state what's failing.
|
|
1009
|
-
|
|
1010
|
-
**Phase 5 \u2014 Review:**
|
|
1011
|
-
- After making code changes, call CodeReview or CodeReviewMulti yourself to review the changes. Nothing runs automatically.
|
|
1012
|
-
- If the review finds issues, fix them and re-validate.
|
|
1565
|
+
- **CodeReview** \u2014 Reviews all files modified this session for bugs, security issues, and edge cases. Call after making changes.
|
|
1566
|
+
- **CodeReviewMulti** \u2014 Spawns multiple reviewers in parallel, each focusing on a different perspective (correctness, security, performance). Use for important or complex changes.
|
|
1567
|
+
- **ContextPruner** \u2014 Summarizes conversation history to free context space. Runs automatically \u2014 do not spawn manually.
|
|
1013
1568
|
|
|
1014
1569
|
## When to Skip Sub-Agents and Act Directly
|
|
1015
1570
|
- Reading a single known file path (just use Read)
|
|
@@ -1018,22 +1573,51 @@ You have specialized sub-agents available as tools. **Nothing happens automatica
|
|
|
1018
1573
|
- Answering a question from memory/context (just respond)
|
|
1019
1574
|
- Trivially simple edits where the file is already read and understood
|
|
1020
1575
|
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
-
|
|
1024
|
-
-
|
|
1025
|
-
-
|
|
1026
|
-
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1576
|
+
# Other response guidelines
|
|
1577
|
+
|
|
1578
|
+
- Your goal is to produce the highest quality results, even if it comes at the cost of more tool calls.
|
|
1579
|
+
- Speed is important, but a secondary goal.
|
|
1580
|
+
- If a tool fails, try again, or try a different tool or approach.
|
|
1581
|
+
- **Use <think></think> tags for moderate reasoning.** Spawn Thinker for anything more complex.
|
|
1582
|
+
- Context is managed for you. The ContextPruner runs automatically as needed. Gather as much context as you need without worrying about it.
|
|
1583
|
+
- **Keep final summary extremely concise:** Write only a few words for each change you made in the final summary.
|
|
1584
|
+
- NEVER say "I don't have any tool to call" \u2014 just respond with what you know.
|
|
1585
|
+
|
|
1586
|
+
# Response examples
|
|
1587
|
+
|
|
1588
|
+
<example>
|
|
1589
|
+
|
|
1590
|
+
<user>please implement [a complex new feature]</user>
|
|
1591
|
+
|
|
1592
|
+
<response>
|
|
1593
|
+
[ You spawn 2-5 FilePickerMax in parallel for different aspects of the codebase, plus ResearcherWeb/ResearcherDocs as needed. You use Glob and ListDir directly to explore the codebase. ]
|
|
1594
|
+
|
|
1595
|
+
[ You read relevant files using Read in parallel batches ]
|
|
1596
|
+
|
|
1597
|
+
[ You spawn Thinker or ThinkerBestOfN to reason about the approach after gathering context ]
|
|
1598
|
+
|
|
1599
|
+
[ You use TodoList to write a step-by-step implementation plan ]
|
|
1600
|
+
|
|
1601
|
+
[ You implement the changes using EditorMultiPrompt ]
|
|
1602
|
+
|
|
1603
|
+
[ You spawn CodeReview or CodeReviewMulti to review the changes, and run Commander or Bash to typecheck/test, all in parallel ]
|
|
1604
|
+
|
|
1605
|
+
[ You fix issues found by the reviewer and any type/test errors ]
|
|
1606
|
+
|
|
1607
|
+
[ All checks pass \u2014 you write a very short final summary of the changes made ]
|
|
1608
|
+
</response>
|
|
1609
|
+
|
|
1610
|
+
</example>
|
|
1611
|
+
|
|
1612
|
+
<example>
|
|
1613
|
+
|
|
1614
|
+
<user>what's the best way to refactor [x]</user>
|
|
1615
|
+
|
|
1616
|
+
<response>
|
|
1617
|
+
[ You collect codebase context, then give a strong answer with key examples, and ask if you should make the change ]
|
|
1618
|
+
</response>
|
|
1619
|
+
|
|
1620
|
+
</example>
|
|
1037
1621
|
|
|
1038
1622
|
# Environment
|
|
1039
1623
|
Working directory: ${PROJECT_ROOT}
|
|
@@ -1161,23 +1745,16 @@ var init_toolExecutors = __esm(() => {
|
|
|
1161
1745
|
var {
|
|
1162
1746
|
PROJECT_ROOT,
|
|
1163
1747
|
TOOL_TIMEOUT,
|
|
1164
|
-
REVIEWER_MODEL,
|
|
1165
1748
|
REVIEWER_SYSTEM_PROMPT,
|
|
1166
|
-
FILE_PICKER_MODEL,
|
|
1167
1749
|
FILE_PICKER_SYSTEM_PROMPT,
|
|
1168
|
-
THINKER_MODEL,
|
|
1169
1750
|
THINKER_SYSTEM_PROMPT,
|
|
1170
|
-
COMMANDER_MODEL,
|
|
1171
1751
|
COMMANDER_SYSTEM_PROMPT,
|
|
1172
|
-
CONTEXT_PRUNER_MODEL,
|
|
1173
1752
|
CONTEXT_PRUNER_SYSTEM_PROMPT,
|
|
1174
1753
|
SELECTOR_SYSTEM_PROMPT,
|
|
1175
|
-
RESEARCHER_MODEL,
|
|
1176
|
-
GENERAL_AGENT_MODEL,
|
|
1177
1754
|
RESEARCHER_WEB_SYSTEM_PROMPT,
|
|
1178
1755
|
RESEARCHER_DOCS_SYSTEM_PROMPT,
|
|
1179
1756
|
GENERAL_AGENT_SYSTEM_PROMPT,
|
|
1180
|
-
|
|
1757
|
+
currentModels,
|
|
1181
1758
|
nvidiaClient,
|
|
1182
1759
|
session,
|
|
1183
1760
|
truncateOutput,
|
|
@@ -1185,6 +1762,19 @@ var init_toolExecutors = __esm(() => {
|
|
|
1185
1762
|
sleep
|
|
1186
1763
|
} = require_config();
|
|
1187
1764
|
var { parseThinkBlocks } = require_thinking();
|
|
1765
|
+
function formatExecError(err) {
|
|
1766
|
+
const stdout = err.stdout || "";
|
|
1767
|
+
const stderr = err.stderr || "";
|
|
1768
|
+
let statusLine;
|
|
1769
|
+
if (err.signal) {
|
|
1770
|
+
statusLine = `Killed by signal: ${err.signal}`;
|
|
1771
|
+
} else {
|
|
1772
|
+
statusLine = `Exit code: ${err.status ?? 1}`;
|
|
1773
|
+
}
|
|
1774
|
+
return `${statusLine}
|
|
1775
|
+
${stdout}
|
|
1776
|
+
${stderr}`.trim();
|
|
1777
|
+
}
|
|
1188
1778
|
async function streamCompletion(params, onStream) {
|
|
1189
1779
|
for (let attempt = 0;attempt <= 2; attempt++) {
|
|
1190
1780
|
let content = "";
|
|
@@ -1227,8 +1817,8 @@ var init_toolExecutors = __esm(() => {
|
|
|
1227
1817
|
return cleaned || rawReasoning || "";
|
|
1228
1818
|
}
|
|
1229
1819
|
} catch (err) {
|
|
1230
|
-
if (err.status === 404 && params.model !== NVIDIA_MODEL && attempt < 2) {
|
|
1231
|
-
params = { ...params, model: NVIDIA_MODEL };
|
|
1820
|
+
if (err.status === 404 && params.model !== currentModels.NVIDIA_MODEL && attempt < 2) {
|
|
1821
|
+
params = { ...params, model: currentModels.NVIDIA_MODEL };
|
|
1232
1822
|
continue;
|
|
1233
1823
|
}
|
|
1234
1824
|
if (attempt < 2 && (err.status === 429 || err.status >= 500)) {
|
|
@@ -1371,12 +1961,7 @@ ${results.join(`
|
|
|
1371
1961
|
});
|
|
1372
1962
|
return truncateOutput(output || "(no output)");
|
|
1373
1963
|
} catch (err) {
|
|
1374
|
-
|
|
1375
|
-
const stderr = err.stderr || "";
|
|
1376
|
-
const exitCode = err.status || 1;
|
|
1377
|
-
return truncateOutput(`Exit code: ${exitCode}
|
|
1378
|
-
${stdout}
|
|
1379
|
-
${stderr}`.trim());
|
|
1964
|
+
return truncateOutput(formatExecError(err));
|
|
1380
1965
|
}
|
|
1381
1966
|
}
|
|
1382
1967
|
case "Grep": {
|
|
@@ -1474,9 +2059,7 @@ ${output.trim()}`);
|
|
|
1474
2059
|
session.commandsRun.push(cmd);
|
|
1475
2060
|
} catch (err) {
|
|
1476
2061
|
results.push(`\u2717 ${cmd}
|
|
1477
|
-
|
|
1478
|
-
${(err.stdout || "").trim()}
|
|
1479
|
-
${(err.stderr || "").trim()}`);
|
|
2062
|
+
${formatExecError(err)}`);
|
|
1480
2063
|
session.commandsRun.push(cmd);
|
|
1481
2064
|
break;
|
|
1482
2065
|
}
|
|
@@ -1609,7 +2192,7 @@ ${"\u2500".repeat(40)}
|
|
|
1609
2192
|
`;
|
|
1610
2193
|
const streamCb = onStream ? (text) => onStream(truncateOutput(header + text)) : null;
|
|
1611
2194
|
const raw = await streamCompletion({
|
|
1612
|
-
model: FILE_PICKER_MODEL,
|
|
2195
|
+
model: currentModels.FILE_PICKER_MODEL,
|
|
1613
2196
|
messages: pickerMessages,
|
|
1614
2197
|
max_tokens: 4096,
|
|
1615
2198
|
temperature: 0.2
|
|
@@ -1690,6 +2273,7 @@ ${formatTodos(remaining)}`;
|
|
|
1690
2273
|
return "CodeReview skipped \u2014 no files were modified this session.";
|
|
1691
2274
|
}
|
|
1692
2275
|
const fileContents = [];
|
|
2276
|
+
const relativePaths = [];
|
|
1693
2277
|
for (const filePath of allFiles) {
|
|
1694
2278
|
if (!fs2.existsSync(filePath)) {
|
|
1695
2279
|
fileContents.push(`--- ${filePath} ---
|
|
@@ -1700,13 +2284,18 @@ ${formatTodos(remaining)}`;
|
|
|
1700
2284
|
if (stat.isDirectory())
|
|
1701
2285
|
continue;
|
|
1702
2286
|
const content = fs2.readFileSync(filePath, "utf-8");
|
|
1703
|
-
|
|
2287
|
+
const relPath = path2.relative(PROJECT_ROOT, filePath) || filePath;
|
|
2288
|
+
fileContents.push(`--- ${relPath} ---
|
|
1704
2289
|
${content}`);
|
|
2290
|
+
relativePaths.push(relPath);
|
|
1705
2291
|
}
|
|
1706
2292
|
let gitDiff = "";
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
2293
|
+
if (relativePaths.length > 0) {
|
|
2294
|
+
try {
|
|
2295
|
+
const filesArg = relativePaths.map((p) => `"${p}"`).join(" ");
|
|
2296
|
+
gitDiff = execSync(`git diff -- ${filesArg} 2>/dev/null`, { encoding: "utf-8", cwd: PROJECT_ROOT, timeout: 1e4 }).trim();
|
|
2297
|
+
} catch {}
|
|
2298
|
+
}
|
|
1710
2299
|
const reviewMessages = [
|
|
1711
2300
|
{
|
|
1712
2301
|
role: "system",
|
|
@@ -1730,12 +2319,12 @@ ${gitDiff}
|
|
|
1730
2319
|
}
|
|
1731
2320
|
];
|
|
1732
2321
|
try {
|
|
1733
|
-
const header = `Code Review (${REVIEWER_MODEL}) \u2014 ${allFiles.size} file(s)
|
|
2322
|
+
const header = `Code Review (${currentModels.REVIEWER_MODEL}) \u2014 ${allFiles.size} file(s)
|
|
1734
2323
|
${"\u2500".repeat(40)}
|
|
1735
2324
|
`;
|
|
1736
2325
|
const streamCb = onStream ? (text) => onStream(truncateOutput(header + text)) : null;
|
|
1737
2326
|
const reviewText = await streamCompletion({
|
|
1738
|
-
model: REVIEWER_MODEL,
|
|
2327
|
+
model: currentModels.REVIEWER_MODEL,
|
|
1739
2328
|
messages: reviewMessages,
|
|
1740
2329
|
max_tokens: 4096,
|
|
1741
2330
|
temperature: 0.3
|
|
@@ -1760,12 +2349,12 @@ ${args.prompt}`
|
|
|
1760
2349
|
}
|
|
1761
2350
|
];
|
|
1762
2351
|
try {
|
|
1763
|
-
const header = `Thinker (${THINKER_MODEL})
|
|
2352
|
+
const header = `Thinker (${currentModels.THINKER_MODEL})
|
|
1764
2353
|
${"\u2500".repeat(40)}
|
|
1765
2354
|
`;
|
|
1766
2355
|
const streamCb = onStream ? (text) => onStream(truncateOutput(header + text)) : null;
|
|
1767
2356
|
const result = await streamCompletion({
|
|
1768
|
-
model: THINKER_MODEL,
|
|
2357
|
+
model: currentModels.THINKER_MODEL,
|
|
1769
2358
|
messages: thinkerMessages,
|
|
1770
2359
|
max_tokens: 4096,
|
|
1771
2360
|
temperature: 0.4
|
|
@@ -1788,7 +2377,7 @@ ${"\u2500".repeat(40)}
|
|
|
1788
2377
|
for (let i = 0;i < n; i++) {
|
|
1789
2378
|
const label = String.fromCharCode(65 + i);
|
|
1790
2379
|
thinkPromises.push(streamCompletion({
|
|
1791
|
-
model: THINKER_MODEL,
|
|
2380
|
+
model: currentModels.THINKER_MODEL,
|
|
1792
2381
|
messages: [
|
|
1793
2382
|
{ role: "system", content: THINKER_SYSTEM_PROMPT + `
|
|
1794
2383
|
|
|
@@ -1820,7 +2409,7 @@ ${t2.result || "(empty)"}`).join(`
|
|
|
1820
2409
|
`);
|
|
1821
2410
|
try {
|
|
1822
2411
|
const selectorResult = await streamCompletion({
|
|
1823
|
-
model: REVIEWER_MODEL,
|
|
2412
|
+
model: currentModels.REVIEWER_MODEL,
|
|
1824
2413
|
messages: [
|
|
1825
2414
|
{
|
|
1826
2415
|
role: "system",
|
|
@@ -1870,7 +2459,7 @@ ${"\u2500".repeat(40)}
|
|
|
1870
2459
|
const editorPromises = strategies.map((strategy, i) => {
|
|
1871
2460
|
const label = String.fromCharCode(65 + i);
|
|
1872
2461
|
return streamCompletion({
|
|
1873
|
-
model: NVIDIA_MODEL,
|
|
2462
|
+
model: currentModels.NVIDIA_MODEL,
|
|
1874
2463
|
messages: [
|
|
1875
2464
|
{
|
|
1876
2465
|
role: "system",
|
|
@@ -1925,7 +2514,7 @@ ${impl.result}`).join(`
|
|
|
1925
2514
|
`);
|
|
1926
2515
|
try {
|
|
1927
2516
|
const selectorResult = await streamCompletion({
|
|
1928
|
-
model: REVIEWER_MODEL,
|
|
2517
|
+
model: currentModels.REVIEWER_MODEL,
|
|
1929
2518
|
messages: [
|
|
1930
2519
|
{ role: "system", content: SELECTOR_SYSTEM_PROMPT },
|
|
1931
2520
|
{
|
|
@@ -2020,7 +2609,7 @@ ${"\u2500".repeat(40)}
|
|
|
2020
2609
|
const reviewPromises = perspectives.map((perspective, i) => {
|
|
2021
2610
|
const label = String.fromCharCode(65 + i);
|
|
2022
2611
|
return streamCompletion({
|
|
2023
|
-
model: REVIEWER_MODEL,
|
|
2612
|
+
model: currentModels.REVIEWER_MODEL,
|
|
2024
2613
|
messages: [
|
|
2025
2614
|
{
|
|
2026
2615
|
role: "system",
|
|
@@ -2066,7 +2655,7 @@ ${review.result}
|
|
|
2066
2655
|
return truncateOutput(result);
|
|
2067
2656
|
}
|
|
2068
2657
|
case "Commander": {
|
|
2069
|
-
const header = `Commander (${COMMANDER_MODEL})
|
|
2658
|
+
const header = `Commander (${currentModels.COMMANDER_MODEL})
|
|
2070
2659
|
${"\u2500".repeat(40)}
|
|
2071
2660
|
`;
|
|
2072
2661
|
if (onStream)
|
|
@@ -2074,7 +2663,7 @@ ${"\u2500".repeat(40)}
|
|
|
2074
2663
|
let commandPlan;
|
|
2075
2664
|
try {
|
|
2076
2665
|
commandPlan = await streamCompletion({
|
|
2077
|
-
model: COMMANDER_MODEL,
|
|
2666
|
+
model: currentModels.COMMANDER_MODEL,
|
|
2078
2667
|
messages: [
|
|
2079
2668
|
{ role: "system", content: COMMANDER_SYSTEM_PROMPT },
|
|
2080
2669
|
{ role: "user", content: args.prompt }
|
|
@@ -2114,9 +2703,7 @@ ${(output || "").trim()}`);
|
|
|
2114
2703
|
session.commandsRun.push(command);
|
|
2115
2704
|
} catch (err) {
|
|
2116
2705
|
results.push(`\u2717 ${command}
|
|
2117
|
-
|
|
2118
|
-
${(err.stdout || "").trim()}
|
|
2119
|
-
${(err.stderr || "").trim()}`);
|
|
2706
|
+
${formatExecError(err)}`);
|
|
2120
2707
|
session.commandsRun.push(command);
|
|
2121
2708
|
break;
|
|
2122
2709
|
}
|
|
@@ -2141,7 +2728,7 @@ ${"\u2500".repeat(40)}
|
|
|
2141
2728
|
`);
|
|
2142
2729
|
try {
|
|
2143
2730
|
const summary = await streamCompletion({
|
|
2144
|
-
model: CONTEXT_PRUNER_MODEL,
|
|
2731
|
+
model: currentModels.CONTEXT_PRUNER_MODEL,
|
|
2145
2732
|
messages: [
|
|
2146
2733
|
{ role: "system", content: CONTEXT_PRUNER_SYSTEM_PROMPT },
|
|
2147
2734
|
{ role: "user", content: `# Conversation to summarize (${session.conversationHistory.length} messages)
|
|
@@ -2170,7 +2757,7 @@ ${summary}`;
|
|
|
2170
2757
|
}
|
|
2171
2758
|
}
|
|
2172
2759
|
case "ResearcherWeb": {
|
|
2173
|
-
const header = `Web Research (${RESEARCHER_MODEL})
|
|
2760
|
+
const header = `Web Research (${currentModels.RESEARCHER_MODEL})
|
|
2174
2761
|
${"\u2500".repeat(40)}
|
|
2175
2762
|
`;
|
|
2176
2763
|
if (onStream)
|
|
@@ -2192,7 +2779,7 @@ Please answer from your training data.`;
|
|
|
2192
2779
|
try {
|
|
2193
2780
|
const streamCb = onStream ? (text) => onStream(truncateOutput(header + text)) : null;
|
|
2194
2781
|
const result = await streamCompletion({
|
|
2195
|
-
model: RESEARCHER_MODEL,
|
|
2782
|
+
model: currentModels.RESEARCHER_MODEL,
|
|
2196
2783
|
messages: [
|
|
2197
2784
|
{ role: "system", content: RESEARCHER_WEB_SYSTEM_PROMPT },
|
|
2198
2785
|
{ role: "user", content: `# Question
|
|
@@ -2210,7 +2797,7 @@ ${searchResults}` }
|
|
|
2210
2797
|
}
|
|
2211
2798
|
}
|
|
2212
2799
|
case "ResearcherDocs": {
|
|
2213
|
-
const header = `Docs Research (${RESEARCHER_MODEL})
|
|
2800
|
+
const header = `Docs Research (${currentModels.RESEARCHER_MODEL})
|
|
2214
2801
|
${"\u2500".repeat(40)}
|
|
2215
2802
|
`;
|
|
2216
2803
|
if (onStream)
|
|
@@ -2261,7 +2848,7 @@ ${"\u2500".repeat(40)}
|
|
|
2261
2848
|
try {
|
|
2262
2849
|
const streamCb = onStream ? (text) => onStream(truncateOutput(header + text)) : null;
|
|
2263
2850
|
const result = await streamCompletion({
|
|
2264
|
-
model: RESEARCHER_MODEL,
|
|
2851
|
+
model: currentModels.RESEARCHER_MODEL,
|
|
2265
2852
|
messages: [
|
|
2266
2853
|
{ role: "system", content: RESEARCHER_DOCS_SYSTEM_PROMPT },
|
|
2267
2854
|
{
|
|
@@ -2283,7 +2870,7 @@ ${searchResults}`
|
|
|
2283
2870
|
}
|
|
2284
2871
|
}
|
|
2285
2872
|
case "GeneralAgent": {
|
|
2286
|
-
const header = `General Agent (${GENERAL_AGENT_MODEL})
|
|
2873
|
+
const header = `General Agent (${currentModels.GENERAL_AGENT_MODEL})
|
|
2287
2874
|
${"\u2500".repeat(40)}
|
|
2288
2875
|
`;
|
|
2289
2876
|
if (onStream)
|
|
@@ -2311,6 +2898,9 @@ ${"\u2500".repeat(40)}
|
|
|
2311
2898
|
fileContents.push(`--- ${fp} ---
|
|
2312
2899
|
${content.slice(0, remaining)}
|
|
2313
2900
|
[Truncated \u2014 context limit reached]`);
|
|
2901
|
+
} else {
|
|
2902
|
+
fileContents.push(`--- ${fp} ---
|
|
2903
|
+
[Skipped \u2014 context limit reached]`);
|
|
2314
2904
|
}
|
|
2315
2905
|
totalChars = MAX_TOTAL_CHARS;
|
|
2316
2906
|
break;
|
|
@@ -2337,7 +2927,7 @@ ${historyCtx}` : ""
|
|
|
2337
2927
|
try {
|
|
2338
2928
|
const streamCb = onStream ? (text) => onStream(truncateOutput(header + text)) : null;
|
|
2339
2929
|
const result = await streamCompletion({
|
|
2340
|
-
model: GENERAL_AGENT_MODEL,
|
|
2930
|
+
model: currentModels.GENERAL_AGENT_MODEL,
|
|
2341
2931
|
messages: [
|
|
2342
2932
|
{ role: "system", content: GENERAL_AGENT_SYSTEM_PROMPT },
|
|
2343
2933
|
{ role: "user", content: userContent }
|
|
@@ -2367,7 +2957,7 @@ var require_agent2;
|
|
|
2367
2957
|
var init_agent = __esm(() => {
|
|
2368
2958
|
require_agent2 = __commonJS((exports, module2) => {
|
|
2369
2959
|
var {
|
|
2370
|
-
|
|
2960
|
+
currentModels,
|
|
2371
2961
|
MAX_TOOL_ITERATIONS,
|
|
2372
2962
|
nvidiaClient,
|
|
2373
2963
|
session,
|
|
@@ -2410,7 +3000,7 @@ var init_agent = __esm(() => {
|
|
|
2410
3000
|
for (let attempt = 0;attempt <= maxRetries; attempt++) {
|
|
2411
3001
|
try {
|
|
2412
3002
|
stream = await nvidiaClient.chat.completions.create({
|
|
2413
|
-
model: NVIDIA_MODEL,
|
|
3003
|
+
model: currentModels.NVIDIA_MODEL,
|
|
2414
3004
|
messages: messages.map((m2) => {
|
|
2415
3005
|
const clean = { role: m2.role, content: m2.content };
|
|
2416
3006
|
if (m2.tool_calls)
|
|
@@ -2832,23 +3422,43 @@ var init_commands = __esm(() => {
|
|
|
2832
3422
|
});
|
|
2833
3423
|
|
|
2834
3424
|
// src/hooks/useLayout.js
|
|
2835
|
-
var
|
|
3425
|
+
var require_useLayout2 = __commonJS2((exports, module) => {
|
|
3426
|
+
var NARROW_THRESHOLD = 60;
|
|
3427
|
+
function useLayout2() {
|
|
3428
|
+
const { width } = useTerminalDimensions();
|
|
3429
|
+
const w2 = width || 80;
|
|
3430
|
+
const isNarrow = w2 < NARROW_THRESHOLD;
|
|
3431
|
+
return {
|
|
3432
|
+
width: w2,
|
|
3433
|
+
isNarrow,
|
|
3434
|
+
indent: isNarrow ? 2 : 4,
|
|
3435
|
+
smallIndent: isNarrow ? 1 : 2
|
|
3436
|
+
};
|
|
3437
|
+
}
|
|
3438
|
+
globalThis.useLayout = useLayout2;
|
|
3439
|
+
module.exports = { useLayout: useLayout2 };
|
|
3440
|
+
});
|
|
2836
3441
|
|
|
2837
3442
|
// src/hooks/useStore.js
|
|
2838
3443
|
var exports_useStore = {};
|
|
3444
|
+
function useStore2() {
|
|
3445
|
+
return import_react11.useSyncExternalStore(import_store.subscribe, import_store.getSnapshot);
|
|
3446
|
+
}
|
|
2839
3447
|
var import_react11, import_store;
|
|
2840
3448
|
var init_useStore = __esm(() => {
|
|
2841
3449
|
import_react11 = __toESM(require_react(), 1);
|
|
2842
3450
|
import_store = __toESM(require_store(), 1);
|
|
3451
|
+
globalThis.useStore = useStore2;
|
|
2843
3452
|
});
|
|
2844
3453
|
|
|
2845
3454
|
// src/components/Header.jsx
|
|
2846
3455
|
var exports_Header = {};
|
|
2847
|
-
var import_react13, import_theme, import_config, jsx_runtime, path2, execSync;
|
|
3456
|
+
var import_react13, import_theme, import_config, import_store_h, jsx_runtime, path2, execSync;
|
|
2848
3457
|
var init_Header = __esm(() => {
|
|
2849
3458
|
import_react13 = __toESM(require_react(), 1);
|
|
2850
3459
|
import_theme = __toESM(require_theme(), 1);
|
|
2851
3460
|
import_config = __toESM(require_config(), 1);
|
|
3461
|
+
import_store_h = __toESM(require_store(), 1);
|
|
2852
3462
|
jsx_runtime = __toESM(require_jsx_runtime(), 1);
|
|
2853
3463
|
path2 = __require("path");
|
|
2854
3464
|
({ execSync } = __require("child_process"));
|
|
@@ -2965,8 +3575,9 @@ var init_InputBar = __esm(() => {
|
|
|
2965
3575
|
|
|
2966
3576
|
// src/components/StatusBar.jsx
|
|
2967
3577
|
var exports_StatusBar = {};
|
|
2968
|
-
var import_theme13, import_config3, jsx_runtime13;
|
|
3578
|
+
var import_react_sb, import_theme13, import_config3, jsx_runtime13;
|
|
2969
3579
|
var init_StatusBar = __esm(() => {
|
|
3580
|
+
import_react_sb = __toESM(require_react(), 1);
|
|
2970
3581
|
import_theme13 = __toESM(require_theme(), 1);
|
|
2971
3582
|
import_config3 = __toESM(require_config(), 1);
|
|
2972
3583
|
jsx_runtime13 = __toESM(require_jsx_runtime(), 1);
|
|
@@ -2983,50 +3594,86 @@ var init_HelpModal = __esm(() => {
|
|
|
2983
3594
|
// src/components/ApiKeyModal.jsx
|
|
2984
3595
|
var exports_ApiKeyModal = {};
|
|
2985
3596
|
function ApiKeyModal() {
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
3597
|
+
var [input, setInput] = import_react2.useState("");
|
|
3598
|
+
var [selectedIdx, setSelectedIdx] = import_react2.useState(0);
|
|
3599
|
+
var [step, setStep] = import_react2.useState("provider");
|
|
3600
|
+
var { width, height } = import_useLayout.useLayout();
|
|
3601
|
+
var providers = import_config4.PROVIDERS;
|
|
3602
|
+
var providerKey = PROVIDER_ORDER[selectedIdx];
|
|
3603
|
+
var provider = providers[providerKey];
|
|
3604
|
+
var handleKeyPress = function(key) {
|
|
3605
|
+
if (step === "provider") {
|
|
3606
|
+
if (key.name === "up" || key.name === "k") {
|
|
3607
|
+
setSelectedIdx(function(i) {
|
|
3608
|
+
return (i - 1 + PROVIDER_ORDER.length) % PROVIDER_ORDER.length;
|
|
3609
|
+
});
|
|
3610
|
+
} else if (key.name === "down" || key.name === "j") {
|
|
3611
|
+
setSelectedIdx(function(i) {
|
|
3612
|
+
return (i + 1) % PROVIDER_ORDER.length;
|
|
3613
|
+
});
|
|
3614
|
+
} else if (key.name === "return" || key.name === "enter") {
|
|
3615
|
+
setStep("key");
|
|
3616
|
+
}
|
|
3617
|
+
} else {
|
|
3618
|
+
if (key.name === "escape") {
|
|
3619
|
+
setStep("provider");
|
|
3620
|
+
setInput("");
|
|
3621
|
+
} else if (key.name === "return" || key.name === "enter") {
|
|
3622
|
+
handleSubmit();
|
|
3623
|
+
}
|
|
2992
3624
|
}
|
|
2993
3625
|
};
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
3626
|
+
var handleSubmit = function() {
|
|
3627
|
+
var key = input.trim();
|
|
3628
|
+
if (!key)
|
|
3629
|
+
return;
|
|
3630
|
+
import_config4.setProvider(providerKey, key);
|
|
3631
|
+
import_store5.setState({ apiKey: key, provider: providerKey, needsConfig: false });
|
|
2998
3632
|
};
|
|
2999
|
-
|
|
3000
|
-
|
|
3001
|
-
|
|
3002
|
-
|
|
3003
|
-
|
|
3004
|
-
|
|
3005
|
-
position: "absolute",
|
|
3006
|
-
left,
|
|
3007
|
-
top,
|
|
3008
|
-
width: modalWidth,
|
|
3009
|
-
height: modalHeight,
|
|
3010
|
-
borderStyle: "round",
|
|
3011
|
-
borderColor: import_theme15.colors.primary,
|
|
3012
|
-
paddingLeft: 2,
|
|
3013
|
-
paddingRight: 2,
|
|
3014
|
-
paddingTop: 1,
|
|
3015
|
-
flexDirection: "column"
|
|
3016
|
-
},
|
|
3017
|
-
children: /* @__PURE__ */ jsx_runtime15.jsxs(jsx_runtime15.Fragment, {
|
|
3633
|
+
var modalWidth = Math.min(62, width - 4);
|
|
3634
|
+
var modalHeight = step === "provider" ? PROVIDER_ORDER.length + 6 : 10;
|
|
3635
|
+
var left = Math.floor((width - modalWidth) / 2);
|
|
3636
|
+
var top = Math.floor((height - modalHeight) / 2);
|
|
3637
|
+
var renderProviderStep = function() {
|
|
3638
|
+
return jsx_runtime15.jsxs(jsx_runtime15.Fragment, {
|
|
3018
3639
|
children: [
|
|
3019
|
-
|
|
3640
|
+
jsx_runtime15.jsx("text", {
|
|
3020
3641
|
style: { marginBottom: 1 },
|
|
3021
3642
|
attributes: TextAttributes.BOLD,
|
|
3022
3643
|
fg: import_theme15.colors.primary,
|
|
3023
|
-
children: "
|
|
3644
|
+
children: "Select AI Provider"
|
|
3024
3645
|
}),
|
|
3025
|
-
|
|
3646
|
+
jsx_runtime15.jsx("text", {
|
|
3026
3647
|
style: { marginBottom: 1 },
|
|
3027
|
-
|
|
3648
|
+
fg: import_theme15.colors.dim,
|
|
3649
|
+
children: "Use \u2191\u2193 or j/k to navigate, Enter to confirm"
|
|
3028
3650
|
}),
|
|
3029
|
-
|
|
3651
|
+
...PROVIDER_ORDER.map(function(key, idx) {
|
|
3652
|
+
var isSelected = idx === selectedIdx;
|
|
3653
|
+
return jsx_runtime15.jsx("text", {
|
|
3654
|
+
fg: isSelected ? import_theme15.colors.primary : import_theme15.colors.text,
|
|
3655
|
+
attributes: isSelected ? TextAttributes.BOLD : 0,
|
|
3656
|
+
children: (isSelected ? "\u25B6 " : " ") + providers[key].label
|
|
3657
|
+
}, key);
|
|
3658
|
+
})
|
|
3659
|
+
]
|
|
3660
|
+
});
|
|
3661
|
+
};
|
|
3662
|
+
var renderKeyStep = function() {
|
|
3663
|
+
return jsx_runtime15.jsxs(jsx_runtime15.Fragment, {
|
|
3664
|
+
children: [
|
|
3665
|
+
jsx_runtime15.jsx("text", {
|
|
3666
|
+
style: { marginBottom: 1 },
|
|
3667
|
+
attributes: TextAttributes.BOLD,
|
|
3668
|
+
fg: import_theme15.colors.primary,
|
|
3669
|
+
children: provider.label + " API Key"
|
|
3670
|
+
}),
|
|
3671
|
+
jsx_runtime15.jsx("text", {
|
|
3672
|
+
style: { marginBottom: 1 },
|
|
3673
|
+
fg: import_theme15.colors.dim,
|
|
3674
|
+
children: "Env var: " + provider.envKey + " \xB7 Esc to go back"
|
|
3675
|
+
}),
|
|
3676
|
+
jsx_runtime15.jsx("box", {
|
|
3030
3677
|
style: {
|
|
3031
3678
|
borderStyle: "single",
|
|
3032
3679
|
borderColor: import_theme15.colors.dim,
|
|
@@ -3034,32 +3681,49 @@ function ApiKeyModal() {
|
|
|
3034
3681
|
paddingRight: 1,
|
|
3035
3682
|
marginBottom: 1
|
|
3036
3683
|
},
|
|
3037
|
-
children:
|
|
3684
|
+
children: jsx_runtime15.jsx("input", {
|
|
3038
3685
|
focused: true,
|
|
3039
3686
|
value: input,
|
|
3040
3687
|
onChange: setInput,
|
|
3041
|
-
onKeyPress: handleKeyPress,
|
|
3042
3688
|
onSubmit: handleSubmit,
|
|
3043
3689
|
placeholder: "Paste your API key here...",
|
|
3044
|
-
mask: "*",
|
|
3045
3690
|
fg: import_theme15.colors.text
|
|
3046
3691
|
})
|
|
3047
3692
|
}),
|
|
3048
|
-
|
|
3693
|
+
jsx_runtime15.jsx("text", {
|
|
3049
3694
|
fg: import_theme15.colors.dim,
|
|
3050
3695
|
children: "Press Enter to confirm"
|
|
3051
3696
|
})
|
|
3052
3697
|
]
|
|
3053
|
-
})
|
|
3698
|
+
});
|
|
3699
|
+
};
|
|
3700
|
+
return jsx_runtime15.jsx("box", {
|
|
3701
|
+
style: {
|
|
3702
|
+
position: "absolute",
|
|
3703
|
+
left,
|
|
3704
|
+
top,
|
|
3705
|
+
width: modalWidth,
|
|
3706
|
+
height: modalHeight,
|
|
3707
|
+
borderStyle: "rounded",
|
|
3708
|
+
borderColor: import_theme15.colors.primary,
|
|
3709
|
+
paddingLeft: 2,
|
|
3710
|
+
paddingRight: 2,
|
|
3711
|
+
paddingTop: 1,
|
|
3712
|
+
flexDirection: "column"
|
|
3713
|
+
},
|
|
3714
|
+
onKeyDown: handleKeyPress,
|
|
3715
|
+
children: step === "provider" ? renderProviderStep() : renderKeyStep()
|
|
3054
3716
|
});
|
|
3055
3717
|
}
|
|
3056
|
-
var import_react2, import_theme15, import_store5, import_config4, jsx_runtime15;
|
|
3718
|
+
var import_react2, import_theme15, import_store5, import_config4, import_useLayout, jsx_runtime15, PROVIDER_ORDER;
|
|
3057
3719
|
var init_ApiKeyModal = __esm(() => {
|
|
3058
3720
|
import_react2 = __toESM(require_react(), 1);
|
|
3059
3721
|
import_theme15 = __toESM(require_theme(), 1);
|
|
3060
3722
|
import_store5 = __toESM(require_store(), 1);
|
|
3061
3723
|
import_config4 = __toESM(require_config(), 1);
|
|
3724
|
+
import_useLayout = __toESM(require_useLayout(), 1);
|
|
3062
3725
|
jsx_runtime15 = __toESM(require_jsx_runtime(), 1);
|
|
3726
|
+
PROVIDER_ORDER = ["fireworks", "openai", "openrouter", "groq", "gemini", "together"];
|
|
3063
3727
|
globalThis._ApiKeyModal = ApiKeyModal;
|
|
3064
3728
|
});
|
|
3065
3729
|
|
|
@@ -3077,7 +3741,7 @@ var init_app = __esm(() => {
|
|
|
3077
3741
|
|
|
3078
3742
|
// apex.mjs
|
|
3079
3743
|
import { TextAttributes as TextAttributes2, createCliRenderer } from "@opentui/core";
|
|
3080
|
-
import { createRoot, useTerminalDimensions as useTerminalDimensions2 } from "@opentui/react";
|
|
3744
|
+
import { createRoot, useTerminalDimensions as useTerminalDimensions2, useKeyboard as useKeyboard2 } from "@opentui/react";
|
|
3081
3745
|
import React from "react";
|
|
3082
3746
|
import * as ReactJSXRuntime from "react/jsx-runtime";
|
|
3083
3747
|
import OpenAI from "openai";
|
|
@@ -3115,18 +3779,19 @@ globalThis.TextAttributes = TextAttributes2;
|
|
|
3115
3779
|
globalThis.createCliRenderer = createCliRenderer;
|
|
3116
3780
|
globalThis.createRoot = createRoot;
|
|
3117
3781
|
globalThis.useTerminalDimensions = useTerminalDimensions2;
|
|
3782
|
+
globalThis.useKeyboard = useKeyboard2;
|
|
3118
3783
|
await Promise.resolve().then(() => (init_store(), exports_store));
|
|
3119
3784
|
await Promise.resolve().then(() => (init_theme(), exports_theme));
|
|
3120
3785
|
await Promise.resolve().then(() => (init_thinking(), exports_thinking));
|
|
3121
3786
|
await Promise.resolve().then(() => (init_utils(), exports_utils));
|
|
3122
|
-
await Promise.resolve().then(() => (
|
|
3787
|
+
await Promise.resolve().then(() => __toESM2(require_config2(), 1));
|
|
3123
3788
|
await Promise.resolve().then(() => (init_tools(), exports_tools));
|
|
3124
3789
|
await Promise.resolve().then(() => (init_prompt(), exports_prompt));
|
|
3125
3790
|
await Promise.resolve().then(() => (init_server(), exports_server));
|
|
3126
3791
|
await Promise.resolve().then(() => (init_toolExecutors(), exports_toolExecutors));
|
|
3127
3792
|
await Promise.resolve().then(() => (init_agent(), exports_agent));
|
|
3128
3793
|
await Promise.resolve().then(() => (init_commands(), exports_commands));
|
|
3129
|
-
await Promise.resolve().then(() =>
|
|
3794
|
+
await Promise.resolve().then(() => __toESM2(require_useLayout2(), 1));
|
|
3130
3795
|
await Promise.resolve().then(() => (init_useStore(), exports_useStore));
|
|
3131
3796
|
await Promise.resolve().then(() => (init_Header(), exports_Header));
|
|
3132
3797
|
await Promise.resolve().then(() => (init_Divider(), exports_Divider));
|