apex-dev 3.4.0 → 3.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +392 -54
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -31679,6 +31679,8 @@ var require_config = __commonJS((exports, module2) => {
|
|
|
31679
31679
|
var THINKER_MODEL = "z-ai/glm4.7";
|
|
31680
31680
|
var COMMANDER_MODEL = "nvidia/llama-3.3-nemotron-70b-instruct";
|
|
31681
31681
|
var CONTEXT_PRUNER_MODEL = "nvidia/llama-3.3-nemotron-70b-instruct";
|
|
31682
|
+
var RESEARCHER_MODEL = "nvidia/llama-3.3-nemotron-70b-instruct";
|
|
31683
|
+
var GENERAL_AGENT_MODEL = "z-ai/glm4.7";
|
|
31682
31684
|
var MAX_TOOL_ITERATIONS = 50;
|
|
31683
31685
|
var MAX_OUTPUT_LEN = 12000;
|
|
31684
31686
|
var TOOL_TIMEOUT = 60000;
|
|
@@ -31777,6 +31779,30 @@ Output JSON only, no markdown fences:
|
|
|
31777
31779
|
"reason": "Brief explanation of why this is the best",
|
|
31778
31780
|
"improvements": "Any good ideas from other implementations to incorporate"
|
|
31779
31781
|
}`;
|
|
31782
|
+
var RESEARCHER_WEB_SYSTEM_PROMPT = `You are a web research specialist embedded in a coding assistant. You receive web search results and synthesize them into a clear, accurate answer.
|
|
31783
|
+
|
|
31784
|
+
Rules:
|
|
31785
|
+
1. Extract the most relevant information from results. Cite sources with URLs.
|
|
31786
|
+
2. Be specific and actionable \u2014 code examples and exact details over generic advice.
|
|
31787
|
+
3. If results don't contain the answer, say so clearly and share what you know from training data.
|
|
31788
|
+
4. Prefer recent/authoritative sources. Note when information may be outdated.
|
|
31789
|
+
5. Keep answers concise but thorough \u2014 developers are your audience.`;
|
|
31790
|
+
var RESEARCHER_DOCS_SYSTEM_PROMPT = `You are a documentation research specialist embedded in a coding assistant. You receive documentation search results and synthesize them into a precise, practical answer.
|
|
31791
|
+
|
|
31792
|
+
Rules:
|
|
31793
|
+
1. Extract exact API signatures, parameter types, return values, and defaults.
|
|
31794
|
+
2. Include code examples that can be used directly \u2014 prefer showing code over describing it.
|
|
31795
|
+
3. Note version-specific behavior when relevant.
|
|
31796
|
+
4. Highlight common pitfalls, gotchas, and deprecation warnings.
|
|
31797
|
+
5. If the docs don't cover the question, say so and provide your best guidance from training data.`;
|
|
31798
|
+
var GENERAL_AGENT_SYSTEM_PROMPT = `You are a general-purpose coding agent. You receive file contents and conversation context, then produce a thorough, actionable response.
|
|
31799
|
+
|
|
31800
|
+
Your strengths:
|
|
31801
|
+
1. Deep analysis \u2014 read and reason about complex codebases, trace call chains, identify patterns.
|
|
31802
|
+
2. Problem solving \u2014 identify root causes, suggest fixes, plan multi-step implementations.
|
|
31803
|
+
3. Code generation \u2014 write complete, working code that matches existing project conventions.
|
|
31804
|
+
|
|
31805
|
+
Be direct and comprehensive. Provide actual solutions, not descriptions of what to do. If you identify issues or risks, flag them clearly with severity.`;
|
|
31780
31806
|
var nvidiaClient = new OpenAI({
|
|
31781
31807
|
apiKey: process.env.NVIDIA_API_KEY || "",
|
|
31782
31808
|
baseURL: "https://integrate.api.nvidia.com/v1"
|
|
@@ -31821,6 +31847,8 @@ Output JSON only, no markdown fences:
|
|
|
31821
31847
|
THINKER_MODEL,
|
|
31822
31848
|
COMMANDER_MODEL,
|
|
31823
31849
|
CONTEXT_PRUNER_MODEL,
|
|
31850
|
+
RESEARCHER_MODEL,
|
|
31851
|
+
GENERAL_AGENT_MODEL,
|
|
31824
31852
|
MAX_TOOL_ITERATIONS,
|
|
31825
31853
|
MAX_OUTPUT_LEN,
|
|
31826
31854
|
TOOL_TIMEOUT,
|
|
@@ -31832,6 +31860,9 @@ Output JSON only, no markdown fences:
|
|
|
31832
31860
|
COMMANDER_SYSTEM_PROMPT,
|
|
31833
31861
|
CONTEXT_PRUNER_SYSTEM_PROMPT,
|
|
31834
31862
|
SELECTOR_SYSTEM_PROMPT,
|
|
31863
|
+
RESEARCHER_WEB_SYSTEM_PROMPT,
|
|
31864
|
+
RESEARCHER_DOCS_SYSTEM_PROMPT,
|
|
31865
|
+
GENERAL_AGENT_SYSTEM_PROMPT,
|
|
31835
31866
|
nvidiaClient,
|
|
31836
31867
|
session,
|
|
31837
31868
|
truncateOutput,
|
|
@@ -31879,15 +31910,17 @@ Scripts: ${Object.keys(pkg.scripts).join(", ")}`;
|
|
|
31879
31910
|
|
|
31880
31911
|
# Core Mandates
|
|
31881
31912
|
|
|
31882
|
-
- **Tone:** Professional, direct, and concise. Suitable for a CLI environment.
|
|
31883
31913
|
- **Understand first, act second:** Always gather context and read relevant files BEFORE editing. Use sub-agents (FilePickerMax, Grep, Read) to verify assumptions before implementing.
|
|
31884
31914
|
- **Quality over speed:** Prioritize correctness over appearing productive. Fewer, well-informed sub-agent calls are better than many rushed ones.
|
|
31915
|
+
- **Tone:** Professional, direct, and concise. Suitable for a CLI environment.
|
|
31885
31916
|
- **Validate assumptions:** Use FilePickerMax and Read to verify assumptions about libraries, APIs, and project structure before implementing.
|
|
31886
31917
|
- **Proactiveness:** Fulfill the user's request thoroughly, including reasonable, directly implied follow-up actions.
|
|
31887
31918
|
- **Confirm ambiguity:** Do not take significant actions beyond the clear scope of the request without confirming. If asked *how* to do something, explain first, don't just do it.
|
|
31888
31919
|
- **Do what the user asks:** If the user asks you to do something, even running a risky command, do it.
|
|
31889
31920
|
- **If a tool fails, try again or try a different tool.** Don't give up after one attempt.
|
|
31890
31921
|
- **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."
|
|
31922
|
+
- **Nothing is automatic.** The agent loop is a thin shell \u2014 it only executes tool calls you explicitly make. No code review, no context pruning, no validation happens unless YOU call the corresponding tool.
|
|
31923
|
+
- **Use <think></think> tags for moderate reasoning.** Call the Thinker sub-agent for anything more complex.
|
|
31891
31924
|
|
|
31892
31925
|
# Output Style
|
|
31893
31926
|
- Default to short answers (\u22644 lines) unless the user asks for detail.
|
|
@@ -31896,7 +31929,6 @@ Scripts: ${Object.keys(pkg.scripts).join(", ")}`;
|
|
|
31896
31929
|
- No emojis unless the user uses them first.
|
|
31897
31930
|
- For casual conversation, greetings, or quick questions, respond naturally without tools.
|
|
31898
31931
|
- NEVER say "I don't have any tool to call" \u2014 just respond with what you know.
|
|
31899
|
-
- Use <think></think> tags for moderate reasoning. Call the Thinker sub-agent for anything more complex.
|
|
31900
31932
|
|
|
31901
31933
|
# Code Editing Mandates
|
|
31902
31934
|
|
|
@@ -31916,47 +31948,79 @@ Scripts: ${Object.keys(pkg.scripts).join(", ")}`;
|
|
|
31916
31948
|
|
|
31917
31949
|
# Sub-Agent Orchestration
|
|
31918
31950
|
|
|
31919
|
-
You have specialized sub-agents available as tools. **
|
|
31951
|
+
You have specialized sub-agents available as tools. **Nothing happens automatically \u2014 you are responsible for orchestrating ALL sub-agent work through your own tool calls.** No code review, no context pruning, no validation runs unless YOU explicitly call the appropriate tool. Sub-agents are specialists \u2014 they produce better, more thorough results than you chaining basic tools manually.
|
|
31920
31952
|
|
|
31921
|
-
|
|
31922
|
-
|
|
31953
|
+
## Available Sub-Agents
|
|
31954
|
+
|
|
31955
|
+
**Context Gathering:**
|
|
31956
|
+
- **FilePickerMax** \u2014 Scans the full codebase to find files relevant to a prompt. Use instead of manually chaining Glob/Grep/ListDir. Always specify the exact type of files needed \u2014 NEVER send generic prompts. Spawn 2-5 of these in parallel for different aspects of the codebase.
|
|
31957
|
+
- **ResearcherWeb** \u2014 Searches the web and synthesizes results with an LLM. Use when you need up-to-date information, best practices, or answers that may not be in your training data. Falls back to LLM knowledge if web search is unavailable.
|
|
31958
|
+
- **ResearcherDocs** \u2014 Searches technical documentation for a library/framework and synthesizes a precise answer. Use when you need to verify API signatures, find usage patterns, or check library behavior.
|
|
31959
|
+
|
|
31960
|
+
**Reasoning & Planning:**
|
|
31923
31961
|
- **Thinker** \u2014 Deep reasoning and planning. Call before implementing anything non-trivial to get a structured plan.
|
|
31924
|
-
- **ThinkerBestOfN** \u2014 Multiple parallel reasoning passes, selects the best. Use for critical decisions.
|
|
31962
|
+
- **ThinkerBestOfN** \u2014 Multiple parallel reasoning passes, selects the best. Use for critical decisions that benefit from diverse perspectives.
|
|
31963
|
+
- **GeneralAgent** \u2014 Independent agent that reads specified files and solves problems. More powerful than Thinker because it receives actual file contents. Use when you need deep independent analysis, complex reasoning with full file context, or a second opinion.
|
|
31964
|
+
|
|
31965
|
+
**Implementation:**
|
|
31966
|
+
- **EditorMultiPrompt** \u2014 Tries multiple implementation strategies in parallel, selects the best, and **auto-applies the changes**. Use for important code changes where you want to explore multiple approaches.
|
|
31925
31967
|
- **Commander** \u2014 Terminal command specialist. Plans and executes shell commands for a goal. Use instead of calling Bash directly for multi-step operations.
|
|
31926
|
-
|
|
31927
|
-
|
|
31928
|
-
- **CodeReviewMulti** \u2014
|
|
31929
|
-
- **ContextPruner** \u2014 Summarizes conversation history to free context space.
|
|
31930
|
-
|
|
31931
|
-
|
|
31932
|
-
|
|
31933
|
-
|
|
31934
|
-
|
|
31935
|
-
|
|
31936
|
-
|
|
31937
|
-
|
|
31938
|
-
|
|
31939
|
-
|
|
31940
|
-
|
|
31968
|
+
|
|
31969
|
+
**Review & Maintenance:**
|
|
31970
|
+
- **CodeReview** / **CodeReviewMulti** \u2014 Reviews code changes for bugs, security, edge cases. You MUST call one of these yourself after making code changes.
|
|
31971
|
+
- **ContextPruner** \u2014 Summarizes conversation history to free context space. Call when the conversation is getting long.
|
|
31972
|
+
|
|
31973
|
+
## How to Orchestrate (use your judgment)
|
|
31974
|
+
|
|
31975
|
+
**Phase 1 \u2014 Context Gathering:**
|
|
31976
|
+
- 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").
|
|
31977
|
+
- Use Read to read all relevant files. For complex tasks, read 12-20 files to build a thorough understanding.
|
|
31978
|
+
- Use ResearcherWeb/ResearcherDocs when you need external information about libraries or APIs.
|
|
31979
|
+
- Bundle independent context-gathering calls in the same turn for parallel execution.
|
|
31980
|
+
|
|
31981
|
+
**Phase 2 \u2014 Planning:**
|
|
31982
|
+
- For tasks requiring 3+ steps, use TodoList to write out a step-by-step plan.
|
|
31983
|
+
- Call Thinker (or ThinkerBestOfN for critical decisions) to reason about the approach.
|
|
31984
|
+
- Call GeneralAgent when you need independent deep analysis with file context.
|
|
31985
|
+
|
|
31986
|
+
**Phase 3 \u2014 Implementation:**
|
|
31987
|
+
- Use EditorMultiPrompt for non-trivial code changes \u2014 it tries multiple strategies and auto-applies the best result.
|
|
31988
|
+
- For trivially simple edits on already-read files, use Edit or Patch directly.
|
|
31989
|
+
- Use Write only for creating new files.
|
|
31990
|
+
|
|
31991
|
+
**Phase 4 \u2014 Validation:**
|
|
31992
|
+
- After code changes, run the most relevant checks: tests, lint, typecheck, or build.
|
|
31993
|
+
- Use Commander for multi-step validation. Use Bash for single commands.
|
|
31994
|
+
- If checks fail, fix and re-run. If blocked, clearly state what's failing.
|
|
31995
|
+
|
|
31996
|
+
**Phase 5 \u2014 Review:**
|
|
31997
|
+
- After making code changes, call CodeReview or CodeReviewMulti yourself to review the changes. Nothing runs automatically.
|
|
31998
|
+
- If the review finds issues, fix them and re-validate.
|
|
31999
|
+
|
|
32000
|
+
## When to Skip Sub-Agents and Act Directly
|
|
31941
32001
|
- Reading a single known file path (just use Read)
|
|
31942
32002
|
- A single targeted grep for a known pattern (just use Grep)
|
|
31943
32003
|
- A quick one-line bash command (just use Bash)
|
|
31944
32004
|
- Answering a question from memory/context (just respond)
|
|
31945
32005
|
- Trivially simple edits where the file is already read and understood
|
|
31946
32006
|
|
|
32007
|
+
## Parallel Execution Rules
|
|
32008
|
+
- Bundle independent tool calls in the same turn \u2014 this is critical for speed.
|
|
32009
|
+
- Spawn multiple FilePickerMax simultaneously for different aspects of the codebase.
|
|
32010
|
+
- Run independent Read calls in parallel.
|
|
32011
|
+
- **Don't spawn dependent agents in parallel** \u2014 e.g. don't spawn EditorMultiPrompt at the same time as FilePickerMax, since editing depends on context.
|
|
32012
|
+
- After implementation, run tests AND typechecks in parallel.
|
|
32013
|
+
|
|
31947
32014
|
# Tool Usage (basic tools)
|
|
31948
|
-
- Use Read to understand files before modifying them.
|
|
32015
|
+
- Use Read to understand files before modifying them. NEVER modify a file you haven't read.
|
|
31949
32016
|
- Use Edit for surgical changes to existing files (preferred over Write).
|
|
31950
32017
|
- Use Patch for multiple edits to the same file.
|
|
31951
32018
|
- Use Write only for creating new files.
|
|
31952
32019
|
- Use Bash for simple, single commands. Use Commander for multi-step operations.
|
|
31953
32020
|
- Use Grep/Glob/ListDir for quick, targeted lookups. Use FilePickerMax for broad codebase discovery.
|
|
32021
|
+
- Use TodoList to track multi-step plans.
|
|
31954
32022
|
- Don't ask for permission to use tools \u2014 just use them.
|
|
31955
32023
|
|
|
31956
|
-
# Validation
|
|
31957
|
-
- After code changes, run the most relevant checks: tests, lint, typecheck, or build. Prefer Commander or scripts from package.json.
|
|
31958
|
-
- If checks fail, fix and re-run. If blocked, clearly state what's failing and why.
|
|
31959
|
-
|
|
31960
32024
|
# Environment
|
|
31961
32025
|
Working directory: ${PROJECT_ROOT}
|
|
31962
32026
|
OS: ${process.platform}
|
|
@@ -32297,6 +32361,59 @@ var require_tools = __commonJS((exports, module2) => {
|
|
|
32297
32361
|
required: []
|
|
32298
32362
|
}
|
|
32299
32363
|
}
|
|
32364
|
+
},
|
|
32365
|
+
{
|
|
32366
|
+
type: "function",
|
|
32367
|
+
function: {
|
|
32368
|
+
name: "ResearcherWeb",
|
|
32369
|
+
description: "Search the web and synthesize results into a clear answer using an LLM. Use when you need up-to-date information, best practices, or answers that may not be in your training data. Falls back to LLM knowledge if web search is unavailable.",
|
|
32370
|
+
parameters: {
|
|
32371
|
+
type: "object",
|
|
32372
|
+
properties: {
|
|
32373
|
+
prompt: { type: "string", description: "The question to research. Be specific for better results." },
|
|
32374
|
+
domains: {
|
|
32375
|
+
type: "array",
|
|
32376
|
+
description: 'Optional list of domains to restrict search to (e.g. ["stackoverflow.com", "github.com"]).',
|
|
32377
|
+
items: { type: "string" }
|
|
32378
|
+
}
|
|
32379
|
+
},
|
|
32380
|
+
required: ["prompt"]
|
|
32381
|
+
}
|
|
32382
|
+
}
|
|
32383
|
+
},
|
|
32384
|
+
{
|
|
32385
|
+
type: "function",
|
|
32386
|
+
function: {
|
|
32387
|
+
name: "ResearcherDocs",
|
|
32388
|
+
description: "Search technical documentation for a library or framework and synthesize a precise answer with API details and code examples. Use when you need to verify API signatures, find usage patterns, or check library behavior.",
|
|
32389
|
+
parameters: {
|
|
32390
|
+
type: "object",
|
|
32391
|
+
properties: {
|
|
32392
|
+
prompt: { type: "string", description: "The documentation question. Include the library/framework name and version if relevant." },
|
|
32393
|
+
library: { type: "string", description: 'The library or framework name (e.g. "React", "Express", "Prisma").' }
|
|
32394
|
+
},
|
|
32395
|
+
required: ["prompt"]
|
|
32396
|
+
}
|
|
32397
|
+
}
|
|
32398
|
+
},
|
|
32399
|
+
{
|
|
32400
|
+
type: "function",
|
|
32401
|
+
function: {
|
|
32402
|
+
name: "GeneralAgent",
|
|
32403
|
+
description: "Spawn an independent general-purpose agent that reads specified files and solves a problem. Use when you need deep independent analysis, complex reasoning with full file context, or a second opinion. More powerful than Thinker because it receives actual file contents.",
|
|
32404
|
+
parameters: {
|
|
32405
|
+
type: "object",
|
|
32406
|
+
properties: {
|
|
32407
|
+
prompt: { type: "string", description: "The problem to solve. Be specific about what analysis or output you need." },
|
|
32408
|
+
filePaths: {
|
|
32409
|
+
type: "array",
|
|
32410
|
+
description: "File paths to read and provide as context. The agent will analyze these files to solve the problem.",
|
|
32411
|
+
items: { type: "string" }
|
|
32412
|
+
}
|
|
32413
|
+
},
|
|
32414
|
+
required: ["prompt"]
|
|
32415
|
+
}
|
|
32416
|
+
}
|
|
32300
32417
|
}
|
|
32301
32418
|
];
|
|
32302
32419
|
module2.exports = { toolDefs };
|
|
@@ -32322,6 +32439,11 @@ var require_toolExecutors = __commonJS((exports, module2) => {
|
|
|
32322
32439
|
CONTEXT_PRUNER_MODEL,
|
|
32323
32440
|
CONTEXT_PRUNER_SYSTEM_PROMPT,
|
|
32324
32441
|
SELECTOR_SYSTEM_PROMPT,
|
|
32442
|
+
RESEARCHER_MODEL,
|
|
32443
|
+
GENERAL_AGENT_MODEL,
|
|
32444
|
+
RESEARCHER_WEB_SYSTEM_PROMPT,
|
|
32445
|
+
RESEARCHER_DOCS_SYSTEM_PROMPT,
|
|
32446
|
+
GENERAL_AGENT_SYSTEM_PROMPT,
|
|
32325
32447
|
NVIDIA_MODEL,
|
|
32326
32448
|
nvidiaClient,
|
|
32327
32449
|
session,
|
|
@@ -32361,6 +32483,35 @@ var require_toolExecutors = __commonJS((exports, module2) => {
|
|
|
32361
32483
|
}
|
|
32362
32484
|
}
|
|
32363
32485
|
}
|
|
32486
|
+
function parseEditorOps(text) {
|
|
32487
|
+
const ops = [];
|
|
32488
|
+
const editRe = /---\s*EDIT:\s*(.+?)\s*---[\s\S]*?OLD:\s*\n```[^\n]*\n([\s\S]*?)\n```[\s\S]*?NEW:\s*\n```[^\n]*\n([\s\S]*?)\n```/g;
|
|
32489
|
+
let m2;
|
|
32490
|
+
while ((m2 = editRe.exec(text)) !== null) {
|
|
32491
|
+
ops.push({ type: "edit", path: m2[1].trim(), old_str: m2[2], new_str: m2[3] });
|
|
32492
|
+
}
|
|
32493
|
+
const createRe = /---\s*CREATE:\s*(.+?)\s*---\s*\n```[^\n]*\n([\s\S]*?)\n```/g;
|
|
32494
|
+
while ((m2 = createRe.exec(text)) !== null) {
|
|
32495
|
+
const p = m2[1].trim();
|
|
32496
|
+
if (!ops.some((o) => o.path === p && o.type === "edit")) {
|
|
32497
|
+
ops.push({ type: "create", path: p, content: m2[2] });
|
|
32498
|
+
}
|
|
32499
|
+
}
|
|
32500
|
+
return ops;
|
|
32501
|
+
}
|
|
32502
|
+
async function applyEditorOps(ops, executeFn) {
|
|
32503
|
+
const results = [];
|
|
32504
|
+
for (const op of ops) {
|
|
32505
|
+
if (op.type === "edit") {
|
|
32506
|
+
const r = await executeFn("Edit", { path: op.path, old_str: op.old_str, new_str: op.new_str });
|
|
32507
|
+
results.push(r.startsWith("Error") ? `\u2717 Edit ${op.path}: ${r}` : `\u2713 Edit ${op.path}`);
|
|
32508
|
+
} else if (op.type === "create") {
|
|
32509
|
+
const r = await executeFn("Write", { path: op.path, content: op.content });
|
|
32510
|
+
results.push(r.startsWith("Error") ? `\u2717 Create ${op.path}: ${r}` : `\u2713 Create ${op.path}`);
|
|
32511
|
+
}
|
|
32512
|
+
}
|
|
32513
|
+
return results;
|
|
32514
|
+
}
|
|
32364
32515
|
async function executeTool(name, args, onStream) {
|
|
32365
32516
|
try {
|
|
32366
32517
|
switch (name) {
|
|
@@ -33049,17 +33200,37 @@ Reason: ${reason}`;
|
|
|
33049
33200
|
if (improvements)
|
|
33050
33201
|
result += `
|
|
33051
33202
|
Improvements to consider: ${improvements}`;
|
|
33052
|
-
|
|
33203
|
+
const ops = parseEditorOps(winning.result);
|
|
33204
|
+
if (ops.length > 0) {
|
|
33205
|
+
if (onStream)
|
|
33206
|
+
onStream(truncateOutput(result + `
|
|
33207
|
+
|
|
33208
|
+
Applying ${ops.length} change(s)...`));
|
|
33209
|
+
const applyResults = await applyEditorOps(ops, executeTool);
|
|
33210
|
+
result += `
|
|
33211
|
+
|
|
33212
|
+
--- Applied Changes ---
|
|
33213
|
+
${applyResults.join(`
|
|
33214
|
+
`)}`;
|
|
33215
|
+
} else {
|
|
33216
|
+
result += `
|
|
33053
33217
|
|
|
33054
33218
|
${winning.result}`;
|
|
33219
|
+
}
|
|
33055
33220
|
if (onStream)
|
|
33056
33221
|
onStream(truncateOutput(result));
|
|
33057
33222
|
return truncateOutput(result);
|
|
33058
33223
|
} catch (apiErr) {
|
|
33059
|
-
const
|
|
33224
|
+
const fallbackOps = parseEditorOps(implementations[0].result);
|
|
33225
|
+
if (fallbackOps.length > 0) {
|
|
33226
|
+
const applyResults = await applyEditorOps(fallbackOps, executeTool);
|
|
33227
|
+
return truncateOutput(`${header}Selector failed, applied Implementation A:
|
|
33228
|
+
${applyResults.join(`
|
|
33229
|
+
`)}`);
|
|
33230
|
+
}
|
|
33231
|
+
return truncateOutput(`${header}Selector failed, using Implementation A:
|
|
33060
33232
|
|
|
33061
|
-
${implementations[0].result}
|
|
33062
|
-
return truncateOutput(result);
|
|
33233
|
+
${implementations[0].result}`);
|
|
33063
33234
|
}
|
|
33064
33235
|
}
|
|
33065
33236
|
case "CodeReviewMulti": {
|
|
@@ -33242,6 +33413,187 @@ ${summary}`;
|
|
|
33242
33413
|
return `Error: Context pruning failed \u2014 ${apiErr.message}`;
|
|
33243
33414
|
}
|
|
33244
33415
|
}
|
|
33416
|
+
case "ResearcherWeb": {
|
|
33417
|
+
const header = `Web Research (${RESEARCHER_MODEL})
|
|
33418
|
+
${"\u2500".repeat(40)}
|
|
33419
|
+
`;
|
|
33420
|
+
if (onStream)
|
|
33421
|
+
onStream(header + "Searching the web...");
|
|
33422
|
+
let searchResults = "";
|
|
33423
|
+
const searchArgs = { query: args.prompt, num_results: 5 };
|
|
33424
|
+
if (args.domains && args.domains.length)
|
|
33425
|
+
searchArgs.include_domains = args.domains;
|
|
33426
|
+
try {
|
|
33427
|
+
searchResults = await executeTool("WebSearch", searchArgs);
|
|
33428
|
+
} catch {
|
|
33429
|
+
searchResults = "(Web search unavailable \u2014 answering from knowledge)";
|
|
33430
|
+
}
|
|
33431
|
+
if (searchResults.startsWith("Error")) {
|
|
33432
|
+
searchResults = `(Web search failed: ${searchResults.slice(0, 200)})
|
|
33433
|
+
|
|
33434
|
+
Please answer from your training data.`;
|
|
33435
|
+
}
|
|
33436
|
+
try {
|
|
33437
|
+
const streamCb = onStream ? (text) => onStream(truncateOutput(header + text)) : null;
|
|
33438
|
+
const result = await streamCompletion({
|
|
33439
|
+
model: RESEARCHER_MODEL,
|
|
33440
|
+
messages: [
|
|
33441
|
+
{ role: "system", content: RESEARCHER_WEB_SYSTEM_PROMPT },
|
|
33442
|
+
{ role: "user", content: `# Question
|
|
33443
|
+
${args.prompt}
|
|
33444
|
+
|
|
33445
|
+
# Web Search Results
|
|
33446
|
+
${searchResults}` }
|
|
33447
|
+
],
|
|
33448
|
+
max_tokens: 4096,
|
|
33449
|
+
temperature: 0.3
|
|
33450
|
+
}, streamCb) || "(No response from researcher)";
|
|
33451
|
+
return truncateOutput(header + result);
|
|
33452
|
+
} catch (apiErr) {
|
|
33453
|
+
return `Error: ResearcherWeb failed \u2014 ${apiErr.message}`;
|
|
33454
|
+
}
|
|
33455
|
+
}
|
|
33456
|
+
case "ResearcherDocs": {
|
|
33457
|
+
const header = `Docs Research (${RESEARCHER_MODEL})
|
|
33458
|
+
${"\u2500".repeat(40)}
|
|
33459
|
+
`;
|
|
33460
|
+
if (onStream)
|
|
33461
|
+
onStream(header + "Searching documentation...");
|
|
33462
|
+
const docDomains = [
|
|
33463
|
+
"developer.mozilla.org",
|
|
33464
|
+
"react.dev",
|
|
33465
|
+
"nodejs.org",
|
|
33466
|
+
"docs.python.org",
|
|
33467
|
+
"doc.rust-lang.org",
|
|
33468
|
+
"pkg.go.dev",
|
|
33469
|
+
"learn.microsoft.com",
|
|
33470
|
+
"typescriptlang.org",
|
|
33471
|
+
"expressjs.com",
|
|
33472
|
+
"nextjs.org",
|
|
33473
|
+
"vuejs.org",
|
|
33474
|
+
"angular.io",
|
|
33475
|
+
"svelte.dev",
|
|
33476
|
+
"docs.rs",
|
|
33477
|
+
"rubydoc.info",
|
|
33478
|
+
"docs.oracle.com",
|
|
33479
|
+
"npmjs.com"
|
|
33480
|
+
];
|
|
33481
|
+
const query = args.library ? `${args.library} ${args.prompt}` : args.prompt;
|
|
33482
|
+
let searchResults = "";
|
|
33483
|
+
try {
|
|
33484
|
+
searchResults = await executeTool("WebSearch", {
|
|
33485
|
+
query: `${query} documentation`,
|
|
33486
|
+
num_results: 8,
|
|
33487
|
+
include_domains: docDomains
|
|
33488
|
+
});
|
|
33489
|
+
} catch {
|
|
33490
|
+
searchResults = "";
|
|
33491
|
+
}
|
|
33492
|
+
if (!searchResults || searchResults === "No results found.") {
|
|
33493
|
+
try {
|
|
33494
|
+
searchResults = await executeTool("WebSearch", {
|
|
33495
|
+
query: `${query} documentation API reference`,
|
|
33496
|
+
num_results: 5
|
|
33497
|
+
});
|
|
33498
|
+
} catch {
|
|
33499
|
+
searchResults = "(Documentation search unavailable \u2014 answering from knowledge)";
|
|
33500
|
+
}
|
|
33501
|
+
}
|
|
33502
|
+
if (!searchResults || searchResults.startsWith("Error")) {
|
|
33503
|
+
searchResults = "(No documentation results found \u2014 answering from knowledge)";
|
|
33504
|
+
}
|
|
33505
|
+
try {
|
|
33506
|
+
const streamCb = onStream ? (text) => onStream(truncateOutput(header + text)) : null;
|
|
33507
|
+
const result = await streamCompletion({
|
|
33508
|
+
model: RESEARCHER_MODEL,
|
|
33509
|
+
messages: [
|
|
33510
|
+
{ role: "system", content: RESEARCHER_DOCS_SYSTEM_PROMPT },
|
|
33511
|
+
{
|
|
33512
|
+
role: "user",
|
|
33513
|
+
content: `# Question
|
|
33514
|
+
${args.prompt}${args.library ? `
|
|
33515
|
+
Library: ${args.library}` : ""}
|
|
33516
|
+
|
|
33517
|
+
# Documentation Search Results
|
|
33518
|
+
${searchResults}`
|
|
33519
|
+
}
|
|
33520
|
+
],
|
|
33521
|
+
max_tokens: 4096,
|
|
33522
|
+
temperature: 0.2
|
|
33523
|
+
}, streamCb) || "(No response from researcher)";
|
|
33524
|
+
return truncateOutput(header + result);
|
|
33525
|
+
} catch (apiErr) {
|
|
33526
|
+
return `Error: ResearcherDocs failed \u2014 ${apiErr.message}`;
|
|
33527
|
+
}
|
|
33528
|
+
}
|
|
33529
|
+
case "GeneralAgent": {
|
|
33530
|
+
const header = `General Agent (${GENERAL_AGENT_MODEL})
|
|
33531
|
+
${"\u2500".repeat(40)}
|
|
33532
|
+
`;
|
|
33533
|
+
if (onStream)
|
|
33534
|
+
onStream(header + "Reading files and analyzing...");
|
|
33535
|
+
const MAX_TOTAL_CHARS = 50000;
|
|
33536
|
+
let totalChars = 0;
|
|
33537
|
+
const fileContents = [];
|
|
33538
|
+
for (const fp of args.filePaths || []) {
|
|
33539
|
+
const absPath = resolvePath(fp);
|
|
33540
|
+
const stat = fs2.statSync(absPath, { throwIfNoEntry: false });
|
|
33541
|
+
if (!stat || stat.isDirectory()) {
|
|
33542
|
+
fileContents.push(`--- ${fp} ---
|
|
33543
|
+
[Not found or is a directory]`);
|
|
33544
|
+
continue;
|
|
33545
|
+
}
|
|
33546
|
+
if (stat.size > 256 * 1024) {
|
|
33547
|
+
fileContents.push(`--- ${fp} ---
|
|
33548
|
+
[File too large: ${(stat.size / 1024).toFixed(0)}KB \u2014 skipped]`);
|
|
33549
|
+
continue;
|
|
33550
|
+
}
|
|
33551
|
+
const content = fs2.readFileSync(absPath, "utf-8");
|
|
33552
|
+
if (totalChars + content.length > MAX_TOTAL_CHARS) {
|
|
33553
|
+
const remaining = MAX_TOTAL_CHARS - totalChars;
|
|
33554
|
+
if (remaining > 500) {
|
|
33555
|
+
fileContents.push(`--- ${fp} ---
|
|
33556
|
+
${content.slice(0, remaining)}
|
|
33557
|
+
[Truncated \u2014 context limit reached]`);
|
|
33558
|
+
}
|
|
33559
|
+
totalChars = MAX_TOTAL_CHARS;
|
|
33560
|
+
break;
|
|
33561
|
+
}
|
|
33562
|
+
fileContents.push(`--- ${fp} ---
|
|
33563
|
+
${content}`);
|
|
33564
|
+
totalChars += content.length;
|
|
33565
|
+
}
|
|
33566
|
+
const historyCtx = session.conversationHistory.slice(-8).map((m2) => `[${m2.role}]: ${(m2.content || "").slice(0, 400)}`).join(`
|
|
33567
|
+
`);
|
|
33568
|
+
const userContent = [
|
|
33569
|
+
`# Task
|
|
33570
|
+
${args.prompt}`,
|
|
33571
|
+
fileContents.length > 0 ? `
|
|
33572
|
+
# Files (${fileContents.length})
|
|
33573
|
+
${fileContents.join(`
|
|
33574
|
+
|
|
33575
|
+
`)}` : "",
|
|
33576
|
+
historyCtx ? `
|
|
33577
|
+
# Recent conversation
|
|
33578
|
+
${historyCtx}` : ""
|
|
33579
|
+
].filter(Boolean).join(`
|
|
33580
|
+
`);
|
|
33581
|
+
try {
|
|
33582
|
+
const streamCb = onStream ? (text) => onStream(truncateOutput(header + text)) : null;
|
|
33583
|
+
const result = await streamCompletion({
|
|
33584
|
+
model: GENERAL_AGENT_MODEL,
|
|
33585
|
+
messages: [
|
|
33586
|
+
{ role: "system", content: GENERAL_AGENT_SYSTEM_PROMPT },
|
|
33587
|
+
{ role: "user", content: userContent }
|
|
33588
|
+
],
|
|
33589
|
+
max_tokens: 4096,
|
|
33590
|
+
temperature: 0.4
|
|
33591
|
+
}, streamCb) || "(No response from agent)";
|
|
33592
|
+
return truncateOutput(header + result);
|
|
33593
|
+
} catch (apiErr) {
|
|
33594
|
+
return `Error: GeneralAgent failed \u2014 ${apiErr.message}`;
|
|
33595
|
+
}
|
|
33596
|
+
}
|
|
33245
33597
|
default:
|
|
33246
33598
|
return `Unknown tool: ${name}`;
|
|
33247
33599
|
}
|
|
@@ -33298,6 +33650,16 @@ var require_utils3 = __commonJS((exports, module2) => {
|
|
|
33298
33650
|
return args.prompt ? args.prompt.slice(0, 40) : "running commands";
|
|
33299
33651
|
case "ContextPruner":
|
|
33300
33652
|
return "pruning context";
|
|
33653
|
+
case "ResearcherWeb":
|
|
33654
|
+
return args.prompt ? args.prompt.slice(0, 40) : "web research";
|
|
33655
|
+
case "ResearcherDocs":
|
|
33656
|
+
return args.prompt ? `${args.library ? args.library + ": " : ""}${args.prompt.slice(0, 30)}` : "docs research";
|
|
33657
|
+
case "GeneralAgent":
|
|
33658
|
+
return args.prompt ? args.prompt.slice(0, 40) : "analyzing";
|
|
33659
|
+
case "WebSearch":
|
|
33660
|
+
return args.query ? args.query.slice(0, 40) : "searching";
|
|
33661
|
+
case "TodoList":
|
|
33662
|
+
return args.action || "";
|
|
33301
33663
|
default:
|
|
33302
33664
|
return JSON.stringify(args).slice(0, 60);
|
|
33303
33665
|
}
|
|
@@ -33402,9 +33764,7 @@ var require_agent = __commonJS((exports, module2) => {
|
|
|
33402
33764
|
session.turnCount++;
|
|
33403
33765
|
store.addMessage({ role: "user", content: userInput });
|
|
33404
33766
|
session.conversationHistory.push({ role: "user", content: userInput });
|
|
33405
|
-
const startTime2 = Date.now();
|
|
33406
33767
|
let turnTokens = 0;
|
|
33407
|
-
let turnToolCalls = 0;
|
|
33408
33768
|
try {
|
|
33409
33769
|
store.addMessage({ role: "divider" });
|
|
33410
33770
|
const systemPrompt = buildSystemPrompt();
|
|
@@ -33676,7 +34036,6 @@ var require_agent = __commonJS((exports, module2) => {
|
|
|
33676
34036
|
const success = !result.startsWith("Error");
|
|
33677
34037
|
const elapsed = Date.now() - callStart;
|
|
33678
34038
|
session.toolCallCount++;
|
|
33679
|
-
turnToolCalls++;
|
|
33680
34039
|
if (msgId) {
|
|
33681
34040
|
store.updateMessage(msgId, {
|
|
33682
34041
|
detail,
|
|
@@ -33717,27 +34076,6 @@ var require_agent = __commonJS((exports, module2) => {
|
|
|
33717
34076
|
store.addMessage({ role: "system", content: `\u26A0 Reached maximum tool iterations (${MAX_TOOL_ITERATIONS}). Stopping.` });
|
|
33718
34077
|
}
|
|
33719
34078
|
session.totalTokens += turnTokens;
|
|
33720
|
-
if (session.filesModified.size > 0) {
|
|
33721
|
-
const reviewPrompt = `User request: ${userInput}
|
|
33722
|
-
|
|
33723
|
-
${turnTokens > 0 ? `Processed with ${turnTokens} tokens and ${turnToolCalls} tool calls.` : ""}`;
|
|
33724
|
-
const reviewId = store.addMessage({ role: "system", content: "Multi-perspective code review...", label: "\uD83D\uDCCB Code Review" });
|
|
33725
|
-
try {
|
|
33726
|
-
const reviewResult = await executeTool("CodeReviewMulti", { prompt: reviewPrompt }, (partial) => {
|
|
33727
|
-
store.updateMessage(reviewId, { content: partial, label: "\uD83D\uDCCB Code Review" });
|
|
33728
|
-
});
|
|
33729
|
-
store.updateMessage(reviewId, { content: reviewResult, label: "\uD83D\uDCCB Code Review" });
|
|
33730
|
-
session.conversationHistory.push({
|
|
33731
|
-
role: "assistant",
|
|
33732
|
-
content: `
|
|
33733
|
-
|
|
33734
|
-
--- Code Review ---
|
|
33735
|
-
${reviewResult}`
|
|
33736
|
-
});
|
|
33737
|
-
} catch (err) {
|
|
33738
|
-
store.updateMessage(reviewId, { content: `Code review failed: ${err.message}` });
|
|
33739
|
-
}
|
|
33740
|
-
}
|
|
33741
34079
|
} catch (err) {
|
|
33742
34080
|
store.clearStreaming();
|
|
33743
34081
|
let errorMsg = `Error: ${err.message}`;
|