@polka-codes/core 0.5.2 → 0.5.3
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 +173 -17
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -8207,7 +8207,7 @@ class MockProvider {
|
|
|
8207
8207
|
return ["mock-file.txt"];
|
|
8208
8208
|
}
|
|
8209
8209
|
async listCodeDefinitionNames(path) {
|
|
8210
|
-
return
|
|
8210
|
+
return "mockDefinition";
|
|
8211
8211
|
}
|
|
8212
8212
|
async executeCommand(command, needApprove) {
|
|
8213
8213
|
return { stdout: "mock output", stderr: "", exitCode: 0 };
|
|
@@ -8624,14 +8624,13 @@ var handler5 = async (provider, args) => {
|
|
|
8624
8624
|
};
|
|
8625
8625
|
}
|
|
8626
8626
|
const path = getString(args, "path");
|
|
8627
|
-
const
|
|
8627
|
+
const result = await provider.listCodeDefinitionNames(path);
|
|
8628
8628
|
return {
|
|
8629
8629
|
type: "Reply" /* Reply */,
|
|
8630
8630
|
message: `<list_code_definition_names_path>${path}</list_code_definition_names_path>
|
|
8631
|
-
<
|
|
8632
|
-
${
|
|
8633
|
-
|
|
8634
|
-
</list_code_definition_names_files>`
|
|
8631
|
+
<list_code_definition_names_result>
|
|
8632
|
+
${result}
|
|
8633
|
+
</list_code_definition_names_result>`
|
|
8635
8634
|
};
|
|
8636
8635
|
};
|
|
8637
8636
|
var isAvailable5 = (provider) => {
|
|
@@ -9570,11 +9569,9 @@ ${agents}`;
|
|
|
9570
9569
|
let currentAssistantMessage = "";
|
|
9571
9570
|
const retryCount = 3;
|
|
9572
9571
|
for (let i = 0;i < retryCount; i++) {
|
|
9573
|
-
let gotAnything = false;
|
|
9574
9572
|
currentAssistantMessage = "";
|
|
9575
9573
|
const stream = this.ai.send(this.config.systemPrompt, this.messages);
|
|
9576
9574
|
for await (const chunk of stream) {
|
|
9577
|
-
gotAnything = true;
|
|
9578
9575
|
switch (chunk.type) {
|
|
9579
9576
|
case "usage":
|
|
9580
9577
|
await this.#callback({ kind: "Usage" /* Usage */, agent: this });
|
|
@@ -9591,9 +9588,10 @@ ${agents}`;
|
|
|
9591
9588
|
if (currentAssistantMessage) {
|
|
9592
9589
|
break;
|
|
9593
9590
|
}
|
|
9594
|
-
|
|
9595
|
-
|
|
9596
|
-
|
|
9591
|
+
console.debug(`Retrying request ${i + 1} of ${retryCount}`);
|
|
9592
|
+
}
|
|
9593
|
+
if (!currentAssistantMessage) {
|
|
9594
|
+
throw new Error("No assistant message received");
|
|
9597
9595
|
}
|
|
9598
9596
|
this.messages.push({
|
|
9599
9597
|
role: "assistant",
|
|
@@ -9676,7 +9674,7 @@ ${agents}`;
|
|
|
9676
9674
|
canRetry: false
|
|
9677
9675
|
};
|
|
9678
9676
|
}
|
|
9679
|
-
const resp = await this.onBeforeInvokeTool(name, args);
|
|
9677
|
+
const resp = await this.onBeforeInvokeTool(this.handlers[name].name, args);
|
|
9680
9678
|
if (resp) {
|
|
9681
9679
|
return resp;
|
|
9682
9680
|
}
|
|
@@ -9871,8 +9869,161 @@ var architectAgentInfo = {
|
|
|
9871
9869
|
]
|
|
9872
9870
|
};
|
|
9873
9871
|
|
|
9872
|
+
// src/Agent/CodeFixerAgent/prompts.ts
|
|
9873
|
+
var basePrompt = `You are a highly skilled software engineer specializing in debugging and fixing code issues. You have extensive experience with:
|
|
9874
|
+
- Type systems and type checking
|
|
9875
|
+
- Test frameworks and debugging test failures
|
|
9876
|
+
- Code quality tools and best practices
|
|
9877
|
+
- Systematic debugging approaches`;
|
|
9878
|
+
var codeFixingStrategies = `
|
|
9879
|
+
====
|
|
9880
|
+
|
|
9881
|
+
CODE FIXING STRATEGIES
|
|
9882
|
+
|
|
9883
|
+
1. Type Errors
|
|
9884
|
+
- Analyze type error messages carefully
|
|
9885
|
+
- Check type definitions and imports
|
|
9886
|
+
- Consider type assertions only as a last resort
|
|
9887
|
+
- Verify type compatibility across function boundaries
|
|
9888
|
+
- Look for null/undefined handling issues
|
|
9889
|
+
|
|
9890
|
+
2. Test Failures
|
|
9891
|
+
- Examine test output and error messages
|
|
9892
|
+
- Check test setup and fixtures
|
|
9893
|
+
- Verify assertions and expectations
|
|
9894
|
+
- Look for async/timing issues
|
|
9895
|
+
- Consider edge cases and input validation
|
|
9896
|
+
|
|
9897
|
+
3. Code Quality Issues
|
|
9898
|
+
- Follow project's coding standards
|
|
9899
|
+
- Address linter warnings systematically
|
|
9900
|
+
- Improve code readability
|
|
9901
|
+
- Fix potential runtime issues
|
|
9902
|
+
- Consider performance implications
|
|
9903
|
+
|
|
9904
|
+
4. General Approach
|
|
9905
|
+
- Start with the most critical issues
|
|
9906
|
+
- Make minimal necessary changes
|
|
9907
|
+
- Verify fixes don't introduce new issues
|
|
9908
|
+
- Document complex fixes with comments
|
|
9909
|
+
- Track attempted solutions for each issue`;
|
|
9910
|
+
var retryGuidelines = `
|
|
9911
|
+
====
|
|
9912
|
+
|
|
9913
|
+
RETRY GUIDELINES
|
|
9914
|
+
|
|
9915
|
+
1. Before Retrying
|
|
9916
|
+
- Analyze previous attempt's failure
|
|
9917
|
+
- Consider alternative approaches
|
|
9918
|
+
- Check if similar issues were fixed
|
|
9919
|
+
- Verify no new issues were introduced
|
|
9920
|
+
|
|
9921
|
+
2. When to Retry
|
|
9922
|
+
- Error message changed but issue persists
|
|
9923
|
+
- New information available about the root cause
|
|
9924
|
+
- Different fixing strategy available
|
|
9925
|
+
- Previous attempt partially successful
|
|
9926
|
+
|
|
9927
|
+
3. When to Stop
|
|
9928
|
+
- Maximum retry limit reached
|
|
9929
|
+
- Same error occurs repeatedly
|
|
9930
|
+
- Fix would require major refactoring
|
|
9931
|
+
- Issue requires human intervention
|
|
9932
|
+
|
|
9933
|
+
4. After Maximum Retries
|
|
9934
|
+
- Document attempted solutions
|
|
9935
|
+
- Explain why the issue remains
|
|
9936
|
+
- Suggest manual intervention steps
|
|
9937
|
+
- Report any partial improvements`;
|
|
9938
|
+
var fullSystemPrompt3 = (info, tools, toolNamePrefix, instructions, scripts, interactive) => `
|
|
9939
|
+
${basePrompt}
|
|
9940
|
+
${toolUsePrompt(tools, toolNamePrefix)}
|
|
9941
|
+
${codeFixingStrategies}
|
|
9942
|
+
${retryGuidelines}
|
|
9943
|
+
${capabilities(toolNamePrefix)}
|
|
9944
|
+
${systemInformation(info)}
|
|
9945
|
+
${customInstructions(instructions)}
|
|
9946
|
+
${customScripts(scripts)}
|
|
9947
|
+
${interactiveMode(interactive)}`;
|
|
9948
|
+
|
|
9949
|
+
// src/Agent/CodeFixerAgent/index.ts
|
|
9950
|
+
class CodeFixerAgent extends AgentBase {
|
|
9951
|
+
#maxRetries;
|
|
9952
|
+
#retryCount = 0;
|
|
9953
|
+
constructor(options) {
|
|
9954
|
+
const combinedTools = [...options.additionalTools ?? [], ...Object.values(exports_allTools)];
|
|
9955
|
+
const tools = getAvailableTools(options.provider, combinedTools, (options.agents?.length ?? 0) > 0);
|
|
9956
|
+
const toolNamePrefix = "tool_";
|
|
9957
|
+
const systemPrompt = fullSystemPrompt3({
|
|
9958
|
+
os: options.os
|
|
9959
|
+
}, tools, toolNamePrefix, options.customInstructions ?? [], options.scripts ?? {}, options.interactive);
|
|
9960
|
+
super(codeFixerAgentInfo.name, options.ai, {
|
|
9961
|
+
systemPrompt,
|
|
9962
|
+
tools,
|
|
9963
|
+
toolNamePrefix,
|
|
9964
|
+
provider: options.provider,
|
|
9965
|
+
interactive: options.interactive,
|
|
9966
|
+
agents: options.agents,
|
|
9967
|
+
scripts: options.scripts,
|
|
9968
|
+
callback: options.callback
|
|
9969
|
+
});
|
|
9970
|
+
this.#maxRetries = options.maxRetries ?? 5;
|
|
9971
|
+
}
|
|
9972
|
+
async onBeforeInvokeTool(name, args) {
|
|
9973
|
+
if (name === attemptCompletion_default.name) {
|
|
9974
|
+
if (this.#retryCount > this.#maxRetries) {
|
|
9975
|
+
return;
|
|
9976
|
+
}
|
|
9977
|
+
this.#retryCount++;
|
|
9978
|
+
const executeCommand = this.config.provider.executeCommand;
|
|
9979
|
+
if (!executeCommand) {
|
|
9980
|
+
return;
|
|
9981
|
+
}
|
|
9982
|
+
const check = this.config.scripts?.check;
|
|
9983
|
+
const checkCommand = typeof check === "string" ? check : check?.command;
|
|
9984
|
+
if (checkCommand) {
|
|
9985
|
+
try {
|
|
9986
|
+
const { exitCode, stdout, stderr } = await executeCommand(checkCommand, false);
|
|
9987
|
+
if (exitCode !== 0) {
|
|
9988
|
+
return {
|
|
9989
|
+
type: "Reply" /* Reply */,
|
|
9990
|
+
message: responsePrompts.commandResult(checkCommand, exitCode, stdout, stderr)
|
|
9991
|
+
};
|
|
9992
|
+
}
|
|
9993
|
+
} catch (error) {
|
|
9994
|
+
console.warn(`Failed to check code using command: ${checkCommand}`, error);
|
|
9995
|
+
}
|
|
9996
|
+
}
|
|
9997
|
+
const test = this.config.scripts?.test;
|
|
9998
|
+
const testCommand = typeof test === "string" ? test : test?.command;
|
|
9999
|
+
if (testCommand) {
|
|
10000
|
+
try {
|
|
10001
|
+
const { exitCode, stdout, stderr } = await executeCommand(testCommand, false);
|
|
10002
|
+
if (exitCode !== 0) {
|
|
10003
|
+
return {
|
|
10004
|
+
type: "Reply" /* Reply */,
|
|
10005
|
+
message: responsePrompts.commandResult(testCommand, exitCode, stdout, stderr)
|
|
10006
|
+
};
|
|
10007
|
+
}
|
|
10008
|
+
} catch (error) {
|
|
10009
|
+
console.warn(`Failed to test code using command: ${testCommand}`, error);
|
|
10010
|
+
}
|
|
10011
|
+
}
|
|
10012
|
+
}
|
|
10013
|
+
}
|
|
10014
|
+
}
|
|
10015
|
+
var codeFixerAgentInfo = {
|
|
10016
|
+
name: "codefixer",
|
|
10017
|
+
responsibilities: [
|
|
10018
|
+
"Fixing type errors and type-related issues",
|
|
10019
|
+
"Resolving failing tests",
|
|
10020
|
+
"Addressing code quality issues",
|
|
10021
|
+
"Tracking and reporting unfixed issues"
|
|
10022
|
+
]
|
|
10023
|
+
};
|
|
10024
|
+
|
|
9874
10025
|
// src/Agent/CoderAgent/prompts.ts
|
|
9875
|
-
var
|
|
10026
|
+
var basePrompt2 = "You are a highly skilled software engineer with extensive knowledge in many programming languages, frameworks, design patterns, and best practices.";
|
|
9876
10027
|
var editingFilesPrompt = (toolNamePrefix) => `
|
|
9877
10028
|
====
|
|
9878
10029
|
|
|
@@ -9972,8 +10123,8 @@ You accomplish a given task iteratively, breaking it down into clear steps and w
|
|
|
9972
10123
|
3. Remember, you have extensive capabilities with access to a wide range of tools that can be used in powerful and clever ways as necessary to accomplish each goal. Before calling a tool, do some analysis within <thinking></thinking> tags. First, analyze the file structure provided in environment_details to gain context and insights for proceeding effectively. Then, think about which of the provided tools is the most relevant tool to accomplish the user's task. Next, go through each of the required parameters of the relevant tool and determine if the user has directly provided or given enough information to infer a value. When deciding if the parameter can be inferred, carefully consider all the context to see if it supports a specific value. If all of the required parameters are present or can be reasonably inferred, close the thinking tag and proceed with the tool use.
|
|
9973
10124
|
4. Once you've completed the user's task, you must use the ${toolNamePrefix}attempt_completion tool to present the result of the task to the user.
|
|
9974
10125
|
5. The user may provide feedback, which you can use to make improvements and try again. But DO NOT continue in pointless back and forth conversations, i.e. don't end your responses with questions or offers for further assistance.`;
|
|
9975
|
-
var
|
|
9976
|
-
${
|
|
10126
|
+
var fullSystemPrompt4 = (info, tools, toolNamePrefix, instructions, scripts, interactive) => `
|
|
10127
|
+
${basePrompt2}
|
|
9977
10128
|
${toolUsePrompt(tools, toolNamePrefix)}
|
|
9978
10129
|
${editingFilesPrompt(toolNamePrefix)}
|
|
9979
10130
|
${capabilities(toolNamePrefix)}
|
|
@@ -9991,7 +10142,7 @@ class CoderAgent extends AgentBase {
|
|
|
9991
10142
|
const combinedTools = [...options.additionalTools ?? [], ...Object.values(exports_allTools)];
|
|
9992
10143
|
const tools = getAvailableTools(options.provider, combinedTools, (options.agents?.length ?? 0) > 0);
|
|
9993
10144
|
const toolNamePrefix = "tool_";
|
|
9994
|
-
const systemPrompt =
|
|
10145
|
+
const systemPrompt = fullSystemPrompt4({
|
|
9995
10146
|
os: options.os
|
|
9996
10147
|
}, tools, toolNamePrefix, options.customInstructions ?? [], options.scripts ?? {}, options.interactive);
|
|
9997
10148
|
super(coderAgentInfo.name, options.ai, {
|
|
@@ -10006,6 +10157,9 @@ class CoderAgent extends AgentBase {
|
|
|
10006
10157
|
});
|
|
10007
10158
|
}
|
|
10008
10159
|
async onBeforeInvokeTool(name, args) {
|
|
10160
|
+
if (name !== attemptCompletion_default.name) {
|
|
10161
|
+
return;
|
|
10162
|
+
}
|
|
10009
10163
|
const executeCommand = this.config.provider.executeCommand;
|
|
10010
10164
|
if (!executeCommand) {
|
|
10011
10165
|
return;
|
|
@@ -10122,7 +10276,7 @@ class MultiAgent {
|
|
|
10122
10276
|
}
|
|
10123
10277
|
|
|
10124
10278
|
// src/Agent/index.ts
|
|
10125
|
-
var allAgents = [architectAgentInfo, coderAgentInfo, analyzerAgentInfo];
|
|
10279
|
+
var allAgents = [architectAgentInfo, coderAgentInfo, analyzerAgentInfo, codeFixerAgentInfo];
|
|
10126
10280
|
// src/AiTool/createNewProject.ts
|
|
10127
10281
|
var prompt = `You are an AiTool designed to assist users in creating new projects. Follow these guidelines:
|
|
10128
10282
|
|
|
@@ -10515,6 +10669,7 @@ export {
|
|
|
10515
10669
|
createService,
|
|
10516
10670
|
createNewProject,
|
|
10517
10671
|
coderAgentInfo,
|
|
10672
|
+
codeFixerAgentInfo,
|
|
10518
10673
|
attemptCompletion_default as attemptCompletion,
|
|
10519
10674
|
askFollowupQuestion_default as askFollowupQuestion,
|
|
10520
10675
|
architectAgentInfo,
|
|
@@ -10529,6 +10684,7 @@ export {
|
|
|
10529
10684
|
MultiAgent,
|
|
10530
10685
|
MockProvider,
|
|
10531
10686
|
CoderAgent,
|
|
10687
|
+
CodeFixerAgent,
|
|
10532
10688
|
ArchitectAgent,
|
|
10533
10689
|
AnalyzerAgent,
|
|
10534
10690
|
AiServiceProvider,
|