@polka-codes/cli 0.5.0 → 0.5.2
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 +600 -393
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -24629,7 +24629,7 @@ var {
|
|
|
24629
24629
|
Help
|
|
24630
24630
|
} = import__.default;
|
|
24631
24631
|
// package.json
|
|
24632
|
-
var version = "0.5.
|
|
24632
|
+
var version = "0.5.2";
|
|
24633
24633
|
|
|
24634
24634
|
// ../../node_modules/@anthropic-ai/sdk/version.mjs
|
|
24635
24635
|
var VERSION = "0.36.2";
|
|
@@ -27807,62 +27807,11 @@ Anthropic.Models = Models2;
|
|
|
27807
27807
|
Anthropic.ModelInfosPage = ModelInfosPage;
|
|
27808
27808
|
Anthropic.Beta = Beta;
|
|
27809
27809
|
|
|
27810
|
-
// ../core/src/AiService/UsageMeter.ts
|
|
27811
|
-
class UsageMeter {
|
|
27812
|
-
#usage = {
|
|
27813
|
-
inputTokens: 0,
|
|
27814
|
-
outputTokens: 0,
|
|
27815
|
-
cacheWriteTokens: 0,
|
|
27816
|
-
cacheReadTokens: 0,
|
|
27817
|
-
totalCost: 0
|
|
27818
|
-
};
|
|
27819
|
-
#messageCount = 0;
|
|
27820
|
-
maxCost;
|
|
27821
|
-
maxMessageCount;
|
|
27822
|
-
constructor(options = {}) {
|
|
27823
|
-
this.maxCost = options.maxCost || 1000;
|
|
27824
|
-
this.maxMessageCount = options.maxMessageCount || 1000;
|
|
27825
|
-
}
|
|
27826
|
-
addUsage(usage, model) {
|
|
27827
|
-
this.#usage.inputTokens += usage.inputTokens ?? 0;
|
|
27828
|
-
this.#usage.outputTokens += usage.outputTokens ?? 0;
|
|
27829
|
-
this.#usage.cacheWriteTokens += usage.cacheWriteTokens ?? 0;
|
|
27830
|
-
this.#usage.cacheReadTokens += usage.cacheReadTokens ?? 0;
|
|
27831
|
-
if (!usage.totalCost && model) {
|
|
27832
|
-
usage.totalCost = ((model.inputPrice ?? 0) * (usage.inputTokens ?? 0) + (model.outputPrice ?? 0) * (usage.outputTokens ?? 0) + (model.cacheWritesPrice ?? 0) * (usage.cacheWriteTokens ?? 0) + (model.cacheReadsPrice ?? 0) * (usage.cacheReadTokens ?? 0)) / 1e6;
|
|
27833
|
-
}
|
|
27834
|
-
this.#usage.totalCost += usage.totalCost ?? 0;
|
|
27835
|
-
}
|
|
27836
|
-
incrementMessageCount(count = 1) {
|
|
27837
|
-
this.#messageCount += count;
|
|
27838
|
-
}
|
|
27839
|
-
isLimitExceeded() {
|
|
27840
|
-
const messageCount = this.#messageCount >= this.maxMessageCount;
|
|
27841
|
-
const cost = this.#usage.totalCost >= this.maxCost;
|
|
27842
|
-
return {
|
|
27843
|
-
messageCount,
|
|
27844
|
-
cost,
|
|
27845
|
-
result: messageCount || cost
|
|
27846
|
-
};
|
|
27847
|
-
}
|
|
27848
|
-
get usage() {
|
|
27849
|
-
return { ...this.#usage };
|
|
27850
|
-
}
|
|
27851
|
-
printUsage() {
|
|
27852
|
-
console.log("Usages:");
|
|
27853
|
-
console.log(`Input tokens: ${this.#usage.inputTokens}`);
|
|
27854
|
-
console.log(`Output tokens: ${this.#usage.outputTokens}`);
|
|
27855
|
-
console.log(`Cache read tokens: ${this.#usage.cacheReadTokens}`);
|
|
27856
|
-
console.log(`Cache write tokens: ${this.#usage.cacheWriteTokens}`);
|
|
27857
|
-
console.log(`Total cost: ${this.#usage.totalCost}`);
|
|
27858
|
-
}
|
|
27859
|
-
}
|
|
27860
|
-
|
|
27861
27810
|
// ../core/src/AiService/AiServiceBase.ts
|
|
27862
27811
|
class AiServiceBase {
|
|
27863
27812
|
usageMeter;
|
|
27864
27813
|
constructor(usageMeter) {
|
|
27865
|
-
this.usageMeter = usageMeter
|
|
27814
|
+
this.usageMeter = usageMeter;
|
|
27866
27815
|
}
|
|
27867
27816
|
async* send(systemPrompt, messages) {
|
|
27868
27817
|
this.usageMeter.incrementMessageCount();
|
|
@@ -33095,6 +33044,61 @@ class OpenRouterService extends AiServiceBase {
|
|
|
33095
33044
|
}
|
|
33096
33045
|
}
|
|
33097
33046
|
|
|
33047
|
+
// ../core/src/AiService/UsageMeter.ts
|
|
33048
|
+
class UsageMeter {
|
|
33049
|
+
#usage = {
|
|
33050
|
+
inputTokens: 0,
|
|
33051
|
+
outputTokens: 0,
|
|
33052
|
+
cacheWriteTokens: 0,
|
|
33053
|
+
cacheReadTokens: 0,
|
|
33054
|
+
totalCost: 0
|
|
33055
|
+
};
|
|
33056
|
+
#messageCount = 0;
|
|
33057
|
+
maxCost;
|
|
33058
|
+
maxMessageCount;
|
|
33059
|
+
constructor(options = {}) {
|
|
33060
|
+
this.maxCost = options.maxCost || 1000;
|
|
33061
|
+
this.maxMessageCount = options.maxMessageCount || 1000;
|
|
33062
|
+
}
|
|
33063
|
+
addUsage(usage, model) {
|
|
33064
|
+
this.#usage.inputTokens += usage.inputTokens ?? 0;
|
|
33065
|
+
this.#usage.outputTokens += usage.outputTokens ?? 0;
|
|
33066
|
+
this.#usage.cacheWriteTokens += usage.cacheWriteTokens ?? 0;
|
|
33067
|
+
this.#usage.cacheReadTokens += usage.cacheReadTokens ?? 0;
|
|
33068
|
+
if (!usage.totalCost && model) {
|
|
33069
|
+
usage.totalCost = ((model.inputPrice ?? 0) * (usage.inputTokens ?? 0) + (model.outputPrice ?? 0) * (usage.outputTokens ?? 0) + (model.cacheWritesPrice ?? 0) * (usage.cacheWriteTokens ?? 0) + (model.cacheReadsPrice ?? 0) * (usage.cacheReadTokens ?? 0)) / 1e6;
|
|
33070
|
+
}
|
|
33071
|
+
this.#usage.totalCost += usage.totalCost ?? 0;
|
|
33072
|
+
}
|
|
33073
|
+
incrementMessageCount(count = 1) {
|
|
33074
|
+
this.#messageCount += count;
|
|
33075
|
+
}
|
|
33076
|
+
isLimitExceeded() {
|
|
33077
|
+
const messageCount = this.#messageCount >= this.maxMessageCount;
|
|
33078
|
+
const cost = this.#usage.totalCost >= this.maxCost;
|
|
33079
|
+
return {
|
|
33080
|
+
messageCount,
|
|
33081
|
+
cost,
|
|
33082
|
+
result: messageCount || cost
|
|
33083
|
+
};
|
|
33084
|
+
}
|
|
33085
|
+
get usage() {
|
|
33086
|
+
return { ...this.#usage };
|
|
33087
|
+
}
|
|
33088
|
+
printUsage() {
|
|
33089
|
+
const { inputTokens, outputTokens, cacheReadTokens, cacheWriteTokens } = this.#usage;
|
|
33090
|
+
const allTokensZero = inputTokens === 0 && outputTokens === 0 && cacheReadTokens === 0 && cacheWriteTokens === 0;
|
|
33091
|
+
console.log("Usages:");
|
|
33092
|
+
if (!allTokensZero) {
|
|
33093
|
+
console.log(`Input tokens: ${this.#usage.inputTokens}`);
|
|
33094
|
+
console.log(`Output tokens: ${this.#usage.outputTokens}`);
|
|
33095
|
+
console.log(`Cache read tokens: ${this.#usage.cacheReadTokens}`);
|
|
33096
|
+
console.log(`Cache write tokens: ${this.#usage.cacheWriteTokens}`);
|
|
33097
|
+
}
|
|
33098
|
+
console.log(`Total cost: ${this.#usage.totalCost}`);
|
|
33099
|
+
}
|
|
33100
|
+
}
|
|
33101
|
+
|
|
33098
33102
|
// ../core/src/AiService/index.ts
|
|
33099
33103
|
var AiServiceProvider;
|
|
33100
33104
|
((AiServiceProvider2) => {
|
|
@@ -33121,10 +33125,6 @@ var createService = (provider, options) => {
|
|
|
33121
33125
|
return new OpenRouterService(options);
|
|
33122
33126
|
}
|
|
33123
33127
|
};
|
|
33124
|
-
// ../core/src/tool.ts
|
|
33125
|
-
var getAvailableTools = (provider, allTools) => {
|
|
33126
|
-
return allTools.filter((tool) => tool.isAvailable(provider));
|
|
33127
|
-
};
|
|
33128
33128
|
// ../core/src/tools/allTools.ts
|
|
33129
33129
|
var exports_allTools = {};
|
|
33130
33130
|
__export(exports_allTools, {
|
|
@@ -33138,6 +33138,7 @@ __export(exports_allTools, {
|
|
|
33138
33138
|
listCodeDefinitionNames: () => listCodeDefinitionNames_default,
|
|
33139
33139
|
handOver: () => handOver_default,
|
|
33140
33140
|
executeCommand: () => executeCommand_default,
|
|
33141
|
+
delegate: () => delegate_default,
|
|
33141
33142
|
attemptCompletion: () => attemptCompletion_default,
|
|
33142
33143
|
askFollowupQuestion: () => askFollowupQuestion_default
|
|
33143
33144
|
});
|
|
@@ -33362,8 +33363,83 @@ var attemptCompletion_default = {
|
|
|
33362
33363
|
handler: handler2,
|
|
33363
33364
|
isAvailable: isAvailable2
|
|
33364
33365
|
};
|
|
33365
|
-
// ../core/src/tools/
|
|
33366
|
+
// ../core/src/tools/delegate.ts
|
|
33366
33367
|
var toolInfo3 = {
|
|
33368
|
+
name: "delegate",
|
|
33369
|
+
description: "Temporarily delegate a task to another agent and receive the result back",
|
|
33370
|
+
parameters: [
|
|
33371
|
+
{
|
|
33372
|
+
name: "agent_name",
|
|
33373
|
+
description: "The name of the agent to delegate the task to",
|
|
33374
|
+
required: true,
|
|
33375
|
+
usageValue: "Name of the target agent"
|
|
33376
|
+
},
|
|
33377
|
+
{
|
|
33378
|
+
name: "task",
|
|
33379
|
+
description: "The task to be completed by the target agent",
|
|
33380
|
+
required: true,
|
|
33381
|
+
usageValue: "Task description"
|
|
33382
|
+
},
|
|
33383
|
+
{
|
|
33384
|
+
name: "context",
|
|
33385
|
+
description: "The context information for the task",
|
|
33386
|
+
required: true,
|
|
33387
|
+
usageValue: "Context information"
|
|
33388
|
+
},
|
|
33389
|
+
{
|
|
33390
|
+
name: "files",
|
|
33391
|
+
description: "The files relevant to the task. Comma separated paths",
|
|
33392
|
+
required: false,
|
|
33393
|
+
usageValue: "Relevant files"
|
|
33394
|
+
}
|
|
33395
|
+
],
|
|
33396
|
+
examples: [
|
|
33397
|
+
{
|
|
33398
|
+
description: "Delegate a code analysis task to the analyzer agent",
|
|
33399
|
+
parameters: [
|
|
33400
|
+
{
|
|
33401
|
+
name: "agent_name",
|
|
33402
|
+
value: "analyzer"
|
|
33403
|
+
},
|
|
33404
|
+
{
|
|
33405
|
+
name: "task",
|
|
33406
|
+
value: "Analyze the authentication implementation"
|
|
33407
|
+
},
|
|
33408
|
+
{
|
|
33409
|
+
name: "context",
|
|
33410
|
+
value: "Need to understand the security implications of the current auth system"
|
|
33411
|
+
},
|
|
33412
|
+
{
|
|
33413
|
+
name: "files",
|
|
33414
|
+
value: "src/auth/login.ts,src/auth/types.ts"
|
|
33415
|
+
}
|
|
33416
|
+
]
|
|
33417
|
+
}
|
|
33418
|
+
]
|
|
33419
|
+
};
|
|
33420
|
+
var handler3 = async (_provider, args) => {
|
|
33421
|
+
const agentName = getString(args, "agent_name");
|
|
33422
|
+
const task = getString(args, "task");
|
|
33423
|
+
const context = getString(args, "context", undefined);
|
|
33424
|
+
const files = getStringArray(args, "files", []);
|
|
33425
|
+
return {
|
|
33426
|
+
type: "Delegate" /* Delegate */,
|
|
33427
|
+
agentName,
|
|
33428
|
+
task,
|
|
33429
|
+
context,
|
|
33430
|
+
files
|
|
33431
|
+
};
|
|
33432
|
+
};
|
|
33433
|
+
var isAvailable3 = (_provider) => {
|
|
33434
|
+
return true;
|
|
33435
|
+
};
|
|
33436
|
+
var delegate_default = {
|
|
33437
|
+
...toolInfo3,
|
|
33438
|
+
handler: handler3,
|
|
33439
|
+
isAvailable: isAvailable3
|
|
33440
|
+
};
|
|
33441
|
+
// ../core/src/tools/executeCommand.ts
|
|
33442
|
+
var toolInfo4 = {
|
|
33367
33443
|
name: "execute_command",
|
|
33368
33444
|
description: `Request to execute a CLI command on the system. Use this when you need to perform system operations or run specific commands to accomplish any step in the user's task. You must tailor your command to the user's system and provide a clear explanation of what the command does. Prefer to execute complex CLI commands over creating executable scripts, as they are more flexible and easier to run. Commands will also be executed in the project root directory regardless of executed commands in previous tool uses.`,
|
|
33369
33445
|
parameters: [
|
|
@@ -33396,7 +33472,7 @@ var toolInfo3 = {
|
|
|
33396
33472
|
}
|
|
33397
33473
|
]
|
|
33398
33474
|
};
|
|
33399
|
-
var
|
|
33475
|
+
var handler4 = async (provider, args) => {
|
|
33400
33476
|
if (!provider.executeCommand) {
|
|
33401
33477
|
return {
|
|
33402
33478
|
type: "Error" /* Error */,
|
|
@@ -33425,16 +33501,16 @@ ${result.stderr}
|
|
|
33425
33501
|
message
|
|
33426
33502
|
};
|
|
33427
33503
|
};
|
|
33428
|
-
var
|
|
33504
|
+
var isAvailable4 = (provider) => {
|
|
33429
33505
|
return !!provider.executeCommand;
|
|
33430
33506
|
};
|
|
33431
33507
|
var executeCommand_default = {
|
|
33432
|
-
...
|
|
33433
|
-
handler:
|
|
33434
|
-
isAvailable:
|
|
33508
|
+
...toolInfo4,
|
|
33509
|
+
handler: handler4,
|
|
33510
|
+
isAvailable: isAvailable4
|
|
33435
33511
|
};
|
|
33436
33512
|
// ../core/src/tools/listCodeDefinitionNames.ts
|
|
33437
|
-
var
|
|
33513
|
+
var toolInfo5 = {
|
|
33438
33514
|
name: "list_code_definition_names",
|
|
33439
33515
|
description: "Request to list definition names (classes, functions, methods, etc.) used in a file. This tool provides insights into the codebase structure and important constructs, encapsulating high-level concepts and relationships that are crucial for understanding the overall architecture.",
|
|
33440
33516
|
parameters: [
|
|
@@ -33446,7 +33522,7 @@ var toolInfo4 = {
|
|
|
33446
33522
|
}
|
|
33447
33523
|
]
|
|
33448
33524
|
};
|
|
33449
|
-
var
|
|
33525
|
+
var handler5 = async (provider, args) => {
|
|
33450
33526
|
if (!provider.listCodeDefinitionNames) {
|
|
33451
33527
|
return {
|
|
33452
33528
|
type: "Error" /* Error */,
|
|
@@ -33464,16 +33540,16 @@ ${files.join(`
|
|
|
33464
33540
|
</list_code_definition_names_files>`
|
|
33465
33541
|
};
|
|
33466
33542
|
};
|
|
33467
|
-
var
|
|
33543
|
+
var isAvailable5 = (provider) => {
|
|
33468
33544
|
return !!provider.listCodeDefinitionNames;
|
|
33469
33545
|
};
|
|
33470
33546
|
var listCodeDefinitionNames_default = {
|
|
33471
|
-
...
|
|
33472
|
-
handler:
|
|
33473
|
-
isAvailable:
|
|
33547
|
+
...toolInfo5,
|
|
33548
|
+
handler: handler5,
|
|
33549
|
+
isAvailable: isAvailable5
|
|
33474
33550
|
};
|
|
33475
33551
|
// ../core/src/tools/listFiles.ts
|
|
33476
|
-
var
|
|
33552
|
+
var toolInfo6 = {
|
|
33477
33553
|
name: "list_files",
|
|
33478
33554
|
description: "Request to list files and directories within the specified directory. If recursive is true, it will list all files and directories recursively. If recursive is false or not provided, it will only list the top-level contents. Do not use this tool to confirm the existence of files you may have created, as the user will let you know if the files were created successfully or not.",
|
|
33479
33555
|
parameters: [
|
|
@@ -33512,7 +33588,7 @@ var toolInfo5 = {
|
|
|
33512
33588
|
}
|
|
33513
33589
|
]
|
|
33514
33590
|
};
|
|
33515
|
-
var
|
|
33591
|
+
var handler6 = async (provider, args) => {
|
|
33516
33592
|
if (!provider.listFiles) {
|
|
33517
33593
|
return {
|
|
33518
33594
|
type: "Error" /* Error */,
|
|
@@ -33533,16 +33609,16 @@ ${files.join(`
|
|
|
33533
33609
|
<list_files_truncated>${limitReached}</list_files_truncated>`
|
|
33534
33610
|
};
|
|
33535
33611
|
};
|
|
33536
|
-
var
|
|
33612
|
+
var isAvailable6 = (provider) => {
|
|
33537
33613
|
return !!provider.listFiles;
|
|
33538
33614
|
};
|
|
33539
33615
|
var listFiles_default = {
|
|
33540
|
-
...
|
|
33541
|
-
handler:
|
|
33542
|
-
isAvailable:
|
|
33616
|
+
...toolInfo6,
|
|
33617
|
+
handler: handler6,
|
|
33618
|
+
isAvailable: isAvailable6
|
|
33543
33619
|
};
|
|
33544
33620
|
// ../core/src/tools/readFile.ts
|
|
33545
|
-
var
|
|
33621
|
+
var toolInfo7 = {
|
|
33546
33622
|
name: "read_file",
|
|
33547
33623
|
description: "Request to read the contents of one or multiple files at the specified paths. Use comma separated paths to read multiple files. Use this when you need to examine the contents of an existing file you do not know the contents of, for example to analyze code, review text files, or extract information from configuration files. May not be suitable for other types of binary files, as it returns the raw content as a string. Try to list all the potential files are relevent to the task, and then use this tool to read all the relevant files.",
|
|
33548
33624
|
parameters: [
|
|
@@ -33574,7 +33650,7 @@ var toolInfo6 = {
|
|
|
33574
33650
|
}
|
|
33575
33651
|
]
|
|
33576
33652
|
};
|
|
33577
|
-
var
|
|
33653
|
+
var handler7 = async (provider, args) => {
|
|
33578
33654
|
if (!provider.readFile) {
|
|
33579
33655
|
return {
|
|
33580
33656
|
type: "Error" /* Error */,
|
|
@@ -33598,16 +33674,16 @@ var handler6 = async (provider, args) => {
|
|
|
33598
33674
|
`)
|
|
33599
33675
|
};
|
|
33600
33676
|
};
|
|
33601
|
-
var
|
|
33677
|
+
var isAvailable7 = (provider) => {
|
|
33602
33678
|
return !!provider.readFile;
|
|
33603
33679
|
};
|
|
33604
33680
|
var readFile_default = {
|
|
33605
|
-
...
|
|
33606
|
-
handler:
|
|
33607
|
-
isAvailable:
|
|
33681
|
+
...toolInfo7,
|
|
33682
|
+
handler: handler7,
|
|
33683
|
+
isAvailable: isAvailable7
|
|
33608
33684
|
};
|
|
33609
33685
|
// ../core/src/tools/replaceInFile.ts
|
|
33610
|
-
var
|
|
33686
|
+
var toolInfo8 = {
|
|
33611
33687
|
name: "replace_in_file",
|
|
33612
33688
|
description: "Request to replace sections of content in an existing file using SEARCH/REPLACE blocks that define exact changes to specific parts of the file. This tool should be used when you need to make targeted changes to specific parts of a file.",
|
|
33613
33689
|
parameters: [
|
|
@@ -33691,7 +33767,7 @@ return (
|
|
|
33691
33767
|
}
|
|
33692
33768
|
]
|
|
33693
33769
|
};
|
|
33694
|
-
var
|
|
33770
|
+
var handler8 = async (provider, args) => {
|
|
33695
33771
|
if (!provider.readFile || !provider.writeFile) {
|
|
33696
33772
|
return {
|
|
33697
33773
|
type: "Error" /* Error */,
|
|
@@ -33708,16 +33784,16 @@ var handler7 = async (provider, args) => {
|
|
|
33708
33784
|
message: `<replace_in_file_path>${path}</replace_in_file_path>`
|
|
33709
33785
|
};
|
|
33710
33786
|
};
|
|
33711
|
-
var
|
|
33787
|
+
var isAvailable8 = (provider) => {
|
|
33712
33788
|
return !!provider.readFile && !!provider.writeFile;
|
|
33713
33789
|
};
|
|
33714
33790
|
var replaceInFile_default = {
|
|
33715
|
-
...
|
|
33716
|
-
handler:
|
|
33717
|
-
isAvailable:
|
|
33791
|
+
...toolInfo8,
|
|
33792
|
+
handler: handler8,
|
|
33793
|
+
isAvailable: isAvailable8
|
|
33718
33794
|
};
|
|
33719
33795
|
// ../core/src/tools/searchFiles.ts
|
|
33720
|
-
var
|
|
33796
|
+
var toolInfo9 = {
|
|
33721
33797
|
name: "search_files",
|
|
33722
33798
|
description: "Request to perform a regex search across files in a specified directory, outputting context-rich results that include surrounding lines. This tool searches for patterns or specific content across multiple files, displaying each match with encapsulating context.",
|
|
33723
33799
|
parameters: [
|
|
@@ -33760,7 +33836,7 @@ var toolInfo8 = {
|
|
|
33760
33836
|
}
|
|
33761
33837
|
]
|
|
33762
33838
|
};
|
|
33763
|
-
var
|
|
33839
|
+
var handler9 = async (provider, args) => {
|
|
33764
33840
|
if (!provider.searchFiles) {
|
|
33765
33841
|
return {
|
|
33766
33842
|
type: "Error" /* Error */,
|
|
@@ -33783,16 +33859,16 @@ ${files.join(`
|
|
|
33783
33859
|
`
|
|
33784
33860
|
};
|
|
33785
33861
|
};
|
|
33786
|
-
var
|
|
33862
|
+
var isAvailable9 = (provider) => {
|
|
33787
33863
|
return !!provider.searchFiles;
|
|
33788
33864
|
};
|
|
33789
33865
|
var searchFiles_default = {
|
|
33790
|
-
...
|
|
33791
|
-
handler:
|
|
33792
|
-
isAvailable:
|
|
33866
|
+
...toolInfo9,
|
|
33867
|
+
handler: handler9,
|
|
33868
|
+
isAvailable: isAvailable9
|
|
33793
33869
|
};
|
|
33794
33870
|
// ../core/src/tools/writeToFile.ts
|
|
33795
|
-
var
|
|
33871
|
+
var toolInfo10 = {
|
|
33796
33872
|
name: "write_to_file",
|
|
33797
33873
|
description: "Request to write content to a file at the specified path. If the file exists, it will be overwritten with the provided content. If the file doesn't exist, it will be created. This tool will automatically create any directories needed to write the file.",
|
|
33798
33874
|
parameters: [
|
|
@@ -33836,7 +33912,7 @@ export default App;
|
|
|
33836
33912
|
}
|
|
33837
33913
|
]
|
|
33838
33914
|
};
|
|
33839
|
-
var
|
|
33915
|
+
var handler10 = async (provider, args) => {
|
|
33840
33916
|
if (!provider.writeFile) {
|
|
33841
33917
|
return {
|
|
33842
33918
|
type: "Error" /* Error */,
|
|
@@ -33851,16 +33927,16 @@ var handler9 = async (provider, args) => {
|
|
|
33851
33927
|
message: `<write_to_file_path>${path}</write_to_file_path><status>Success</status>`
|
|
33852
33928
|
};
|
|
33853
33929
|
};
|
|
33854
|
-
var
|
|
33930
|
+
var isAvailable10 = (provider) => {
|
|
33855
33931
|
return !!provider.writeFile;
|
|
33856
33932
|
};
|
|
33857
33933
|
var writeToFile_default = {
|
|
33858
|
-
...
|
|
33859
|
-
handler:
|
|
33860
|
-
isAvailable:
|
|
33934
|
+
...toolInfo10,
|
|
33935
|
+
handler: handler10,
|
|
33936
|
+
isAvailable: isAvailable10
|
|
33861
33937
|
};
|
|
33862
33938
|
// ../core/src/tools/handOver.ts
|
|
33863
|
-
var
|
|
33939
|
+
var toolInfo11 = {
|
|
33864
33940
|
name: "hand_over",
|
|
33865
33941
|
description: "Hand over the current task to another agent to complete",
|
|
33866
33942
|
parameters: [
|
|
@@ -33884,7 +33960,7 @@ var toolInfo10 = {
|
|
|
33884
33960
|
},
|
|
33885
33961
|
{
|
|
33886
33962
|
name: "files",
|
|
33887
|
-
description: "The files relevant to the task",
|
|
33963
|
+
description: "The files relevant to the task. Comma separated paths",
|
|
33888
33964
|
required: false,
|
|
33889
33965
|
usageValue: "Relevant files"
|
|
33890
33966
|
}
|
|
@@ -33913,7 +33989,7 @@ var toolInfo10 = {
|
|
|
33913
33989
|
}
|
|
33914
33990
|
]
|
|
33915
33991
|
};
|
|
33916
|
-
var
|
|
33992
|
+
var handler11 = async (_provider, args) => {
|
|
33917
33993
|
const agentName = getString(args, "agent_name");
|
|
33918
33994
|
const task = getString(args, "task");
|
|
33919
33995
|
const context = getString(args, "context", undefined);
|
|
@@ -33926,16 +34002,16 @@ var handler10 = async (_provider, args) => {
|
|
|
33926
34002
|
files
|
|
33927
34003
|
};
|
|
33928
34004
|
};
|
|
33929
|
-
var
|
|
34005
|
+
var isAvailable11 = (_provider) => {
|
|
33930
34006
|
return true;
|
|
33931
34007
|
};
|
|
33932
34008
|
var handOver_default = {
|
|
33933
|
-
...
|
|
33934
|
-
handler:
|
|
33935
|
-
isAvailable:
|
|
34009
|
+
...toolInfo11,
|
|
34010
|
+
handler: handler11,
|
|
34011
|
+
isAvailable: isAvailable11
|
|
33936
34012
|
};
|
|
33937
34013
|
// ../core/src/tools/removeFile.ts
|
|
33938
|
-
var
|
|
34014
|
+
var toolInfo12 = {
|
|
33939
34015
|
name: "remove_file",
|
|
33940
34016
|
description: "Request to remove a file at the specified path.",
|
|
33941
34017
|
parameters: [
|
|
@@ -33958,7 +34034,7 @@ var toolInfo11 = {
|
|
|
33958
34034
|
}
|
|
33959
34035
|
]
|
|
33960
34036
|
};
|
|
33961
|
-
var
|
|
34037
|
+
var handler12 = async (provider, args) => {
|
|
33962
34038
|
if (!provider.removeFile) {
|
|
33963
34039
|
return {
|
|
33964
34040
|
type: "Error" /* Error */,
|
|
@@ -33972,16 +34048,16 @@ var handler11 = async (provider, args) => {
|
|
|
33972
34048
|
message: `<remove_file_path>${path}</remove_file_path><status>Success</status>`
|
|
33973
34049
|
};
|
|
33974
34050
|
};
|
|
33975
|
-
var
|
|
34051
|
+
var isAvailable12 = (provider) => {
|
|
33976
34052
|
return !!provider.removeFile;
|
|
33977
34053
|
};
|
|
33978
34054
|
var removeFile_default = {
|
|
33979
|
-
...
|
|
33980
|
-
handler:
|
|
33981
|
-
isAvailable:
|
|
34055
|
+
...toolInfo12,
|
|
34056
|
+
handler: handler12,
|
|
34057
|
+
isAvailable: isAvailable12
|
|
33982
34058
|
};
|
|
33983
34059
|
// ../core/src/tools/renameFile.ts
|
|
33984
|
-
var
|
|
34060
|
+
var toolInfo13 = {
|
|
33985
34061
|
name: "rename_file",
|
|
33986
34062
|
description: "Request to rename a file from source path to target path.",
|
|
33987
34063
|
parameters: [
|
|
@@ -34014,7 +34090,7 @@ var toolInfo12 = {
|
|
|
34014
34090
|
}
|
|
34015
34091
|
]
|
|
34016
34092
|
};
|
|
34017
|
-
var
|
|
34093
|
+
var handler13 = async (provider, args) => {
|
|
34018
34094
|
if (!provider.renameFile) {
|
|
34019
34095
|
return {
|
|
34020
34096
|
type: "Error" /* Error */,
|
|
@@ -34029,14 +34105,32 @@ var handler12 = async (provider, args) => {
|
|
|
34029
34105
|
message: `<rename_file_path>${targetPath}</rename_file_path><status>Success</status>`
|
|
34030
34106
|
};
|
|
34031
34107
|
};
|
|
34032
|
-
var
|
|
34108
|
+
var isAvailable13 = (provider) => {
|
|
34033
34109
|
return !!provider.renameFile;
|
|
34034
34110
|
};
|
|
34035
34111
|
var renameFile_default = {
|
|
34036
|
-
...
|
|
34037
|
-
handler:
|
|
34038
|
-
isAvailable:
|
|
34112
|
+
...toolInfo13,
|
|
34113
|
+
handler: handler13,
|
|
34114
|
+
isAvailable: isAvailable13
|
|
34115
|
+
};
|
|
34116
|
+
// ../core/src/tool.ts
|
|
34117
|
+
var getAvailableTools = (provider2, allTools2, hasAgent) => {
|
|
34118
|
+
const tools = [];
|
|
34119
|
+
for (const tool of allTools2) {
|
|
34120
|
+
if (!hasAgent) {
|
|
34121
|
+
switch (tool.name) {
|
|
34122
|
+
case handOver_default.name:
|
|
34123
|
+
case delegate_default.name:
|
|
34124
|
+
continue;
|
|
34125
|
+
}
|
|
34126
|
+
}
|
|
34127
|
+
if (tool.isAvailable(provider2)) {
|
|
34128
|
+
tools.push(tool);
|
|
34129
|
+
}
|
|
34130
|
+
}
|
|
34131
|
+
return tools;
|
|
34039
34132
|
};
|
|
34133
|
+
|
|
34040
34134
|
// ../core/src/Agent/parseAssistantMessage.ts
|
|
34041
34135
|
function parseAssistantMessage(assistantMessage, tools, toolNamePrefix) {
|
|
34042
34136
|
const parameterPrefix = `${toolNamePrefix}parameter_`;
|
|
@@ -34168,17 +34262,21 @@ ${tools.map((tool) => {
|
|
|
34168
34262
|
}).join("")}
|
|
34169
34263
|
# Tool Use Guidelines
|
|
34170
34264
|
|
|
34171
|
-
1. **
|
|
34172
|
-
|
|
34173
|
-
|
|
34174
|
-
|
|
34175
|
-
|
|
34176
|
-
|
|
34177
|
-
|
|
34178
|
-
|
|
34179
|
-
|
|
34180
|
-
|
|
34181
|
-
|
|
34265
|
+
1. **Thinking Tags**: Use \`<thinking>\` tags to clearly outline your thought process *before* using any tools. This includes:
|
|
34266
|
+
* Assessing the current situation and available information.
|
|
34267
|
+
* Defining specific goals and a plan to achieve them.
|
|
34268
|
+
* Justifying the selection of a particular tool.
|
|
34269
|
+
* Explaining how you intend to use the tool and what you expect to achieve.
|
|
34270
|
+
2. **Tool Selection**: Choose one tool at a time per message based on the task and its description. Do not assume a tool’s outcome without explicit confirmation.
|
|
34271
|
+
3. **Formatting**: Formulate tool use only in the specified XML format for each tool.
|
|
34272
|
+
4. **User Response**: Wait for the user’s response after each tool use. Do not proceed until you have their confirmation. The user’s response may include:
|
|
34273
|
+
* Tool success or failure details
|
|
34274
|
+
* Linter errors
|
|
34275
|
+
* Terminal output or other relevant feedback
|
|
34276
|
+
5. **Conciseness**: Never repeat or quote the entire tool command in your final user-facing message. Summarize outcomes clearly and avoid echoing commands verbatim.
|
|
34277
|
+
6. **Brevity**: Respond concisely and move the conversation forward. Do not re-issue the same command or re-trigger tool use without necessity.
|
|
34278
|
+
7. **Iteration**: Follow these steps iteratively, confirming success and addressing issues as you go.
|
|
34279
|
+
8. **Error Handling**: If a tool returns an error, analyze the error message and adjust your approach accordingly. Consider alternative tools or strategies to achieve the desired outcome.
|
|
34182
34280
|
|
|
34183
34281
|
By adhering to these guidelines:
|
|
34184
34282
|
- You maintain clarity without accidentally re-invoking tools.
|
|
@@ -34294,9 +34392,10 @@ class AgentBase {
|
|
|
34294
34392
|
ai;
|
|
34295
34393
|
config;
|
|
34296
34394
|
handlers;
|
|
34395
|
+
messages = [];
|
|
34297
34396
|
constructor(name, ai, config) {
|
|
34298
34397
|
this.ai = ai;
|
|
34299
|
-
if (config.agents &&
|
|
34398
|
+
if (config.agents && config.agents.length > 0) {
|
|
34300
34399
|
const agents = agentsPrompt(config.agents, name);
|
|
34301
34400
|
config.systemPrompt += `
|
|
34302
34401
|
${agents}`;
|
|
@@ -34308,89 +34407,80 @@ ${agents}`;
|
|
|
34308
34407
|
}
|
|
34309
34408
|
this.handlers = handlers;
|
|
34310
34409
|
}
|
|
34311
|
-
async
|
|
34312
|
-
|
|
34313
|
-
|
|
34314
|
-
|
|
34315
|
-
}
|
|
34316
|
-
}) {
|
|
34317
|
-
const taskInfo = {
|
|
34318
|
-
messages: [],
|
|
34319
|
-
inputTokens: 0,
|
|
34320
|
-
outputTokens: 0,
|
|
34321
|
-
cacheWriteTokens: 0,
|
|
34322
|
-
cacheReadTokens: 0,
|
|
34323
|
-
totalCost: 0
|
|
34324
|
-
};
|
|
34410
|
+
async#callback(event) {
|
|
34411
|
+
await this.config.callback?.(event);
|
|
34412
|
+
}
|
|
34413
|
+
async startTask({ task, context }) {
|
|
34325
34414
|
let text = `<task>${task}</task>`;
|
|
34326
34415
|
if (context) {
|
|
34327
34416
|
text += `
|
|
34328
34417
|
<context>${context}</context>`;
|
|
34329
34418
|
}
|
|
34330
|
-
callback({ kind: "StartTask" /* StartTask */,
|
|
34331
|
-
return await this.#processLoop(text
|
|
34419
|
+
this.#callback({ kind: "StartTask" /* StartTask */, agent: this, systemPrompt: this.config.systemPrompt });
|
|
34420
|
+
return await this.#processLoop(text);
|
|
34332
34421
|
}
|
|
34333
|
-
async#processLoop(userMessage
|
|
34422
|
+
async#processLoop(userMessage) {
|
|
34334
34423
|
let nextRequest = userMessage;
|
|
34335
|
-
while (
|
|
34424
|
+
while (true) {
|
|
34336
34425
|
if (this.ai.usageMeter.isLimitExceeded().result) {
|
|
34337
|
-
callback({ kind: "UsageExceeded" /* UsageExceeded */,
|
|
34338
|
-
return
|
|
34426
|
+
this.#callback({ kind: "UsageExceeded" /* UsageExceeded */, agent: this });
|
|
34427
|
+
return { type: "UsageExceeded" };
|
|
34339
34428
|
}
|
|
34340
|
-
const response = await this.#request(
|
|
34341
|
-
const
|
|
34342
|
-
if (
|
|
34343
|
-
callback({ kind: "EndTask" /* EndTask */,
|
|
34344
|
-
return
|
|
34429
|
+
const response = await this.#request(nextRequest);
|
|
34430
|
+
const resp = await this.#handleResponse(response);
|
|
34431
|
+
if ("exit" in resp) {
|
|
34432
|
+
this.#callback({ kind: "EndTask" /* EndTask */, agent: this, exitReason: resp.exit });
|
|
34433
|
+
return resp.exit;
|
|
34345
34434
|
}
|
|
34346
|
-
nextRequest =
|
|
34435
|
+
nextRequest = resp.replay;
|
|
34347
34436
|
}
|
|
34348
|
-
callback({ kind: "EndTask" /* EndTask */, info: taskInfo });
|
|
34349
|
-
return [{ type: "Exit" /* Exit */, message: "Task completed successfully" }, taskInfo];
|
|
34350
34437
|
}
|
|
34351
|
-
async continueTask(userMessage
|
|
34352
|
-
|
|
34353
|
-
return await this.#processLoop(userMessage, taskInfo, callback);
|
|
34438
|
+
async continueTask(userMessage) {
|
|
34439
|
+
return await this.#processLoop(userMessage);
|
|
34354
34440
|
}
|
|
34355
|
-
async#request(
|
|
34356
|
-
await callback({ kind: "StartRequest" /* StartRequest */,
|
|
34357
|
-
|
|
34441
|
+
async#request(userMessage) {
|
|
34442
|
+
await this.#callback({ kind: "StartRequest" /* StartRequest */, agent: this, userMessage });
|
|
34443
|
+
this.messages.push({
|
|
34358
34444
|
role: "user",
|
|
34359
34445
|
content: userMessage
|
|
34360
34446
|
});
|
|
34361
|
-
const stream = this.ai.send(this.config.systemPrompt, info.messages);
|
|
34362
34447
|
let currentAssistantMessage = "";
|
|
34363
|
-
|
|
34364
|
-
|
|
34365
|
-
|
|
34366
|
-
|
|
34367
|
-
|
|
34368
|
-
|
|
34369
|
-
|
|
34370
|
-
|
|
34371
|
-
|
|
34372
|
-
|
|
34373
|
-
|
|
34374
|
-
|
|
34375
|
-
|
|
34376
|
-
|
|
34377
|
-
|
|
34378
|
-
|
|
34379
|
-
|
|
34448
|
+
const retryCount = 3;
|
|
34449
|
+
for (let i2 = 0;i2 < retryCount; i2++) {
|
|
34450
|
+
let gotAnything = false;
|
|
34451
|
+
currentAssistantMessage = "";
|
|
34452
|
+
const stream = this.ai.send(this.config.systemPrompt, this.messages);
|
|
34453
|
+
for await (const chunk of stream) {
|
|
34454
|
+
gotAnything = true;
|
|
34455
|
+
switch (chunk.type) {
|
|
34456
|
+
case "usage":
|
|
34457
|
+
await this.#callback({ kind: "Usage" /* Usage */, agent: this });
|
|
34458
|
+
break;
|
|
34459
|
+
case "text":
|
|
34460
|
+
currentAssistantMessage += chunk.text;
|
|
34461
|
+
await this.#callback({ kind: "Text" /* Text */, agent: this, newText: chunk.text });
|
|
34462
|
+
break;
|
|
34463
|
+
case "reasoning":
|
|
34464
|
+
await this.#callback({ kind: "Reasoning" /* Reasoning */, agent: this, newText: chunk.text });
|
|
34465
|
+
break;
|
|
34466
|
+
}
|
|
34467
|
+
}
|
|
34468
|
+
if (currentAssistantMessage) {
|
|
34469
|
+
break;
|
|
34470
|
+
}
|
|
34471
|
+
if (gotAnything) {
|
|
34472
|
+
throw new Error("No assistant message received");
|
|
34380
34473
|
}
|
|
34381
34474
|
}
|
|
34382
|
-
|
|
34383
|
-
throw new Error("No assistant message received");
|
|
34384
|
-
}
|
|
34385
|
-
info.messages.push({
|
|
34475
|
+
this.messages.push({
|
|
34386
34476
|
role: "assistant",
|
|
34387
34477
|
content: currentAssistantMessage
|
|
34388
34478
|
});
|
|
34389
34479
|
const ret = parseAssistantMessage(currentAssistantMessage, this.config.tools, this.config.toolNamePrefix);
|
|
34390
|
-
await callback({ kind: "EndRequest" /* EndRequest */,
|
|
34480
|
+
await this.#callback({ kind: "EndRequest" /* EndRequest */, agent: this });
|
|
34391
34481
|
return ret;
|
|
34392
34482
|
}
|
|
34393
|
-
async#handleResponse(
|
|
34483
|
+
async#handleResponse(response) {
|
|
34394
34484
|
const toolReponses = [];
|
|
34395
34485
|
outer:
|
|
34396
34486
|
for (const content of response) {
|
|
@@ -34398,54 +34488,65 @@ ${agents}`;
|
|
|
34398
34488
|
case "text":
|
|
34399
34489
|
break;
|
|
34400
34490
|
case "tool_use": {
|
|
34401
|
-
await callback({ kind: "ToolUse" /* ToolUse */,
|
|
34491
|
+
await this.#callback({ kind: "ToolUse" /* ToolUse */, agent: this, tool: content.name });
|
|
34402
34492
|
const toolResp = await this.#invokeTool(content.name, content.params);
|
|
34403
34493
|
switch (toolResp.type) {
|
|
34404
34494
|
case "Reply" /* Reply */:
|
|
34405
|
-
await callback({ kind: "ToolReply" /* ToolReply */,
|
|
34495
|
+
await this.#callback({ kind: "ToolReply" /* ToolReply */, agent: this, tool: content.name });
|
|
34406
34496
|
toolReponses.push({ tool: content.name, response: toolResp.message });
|
|
34407
34497
|
break;
|
|
34408
34498
|
case "Exit" /* Exit */:
|
|
34409
|
-
return
|
|
34499
|
+
return { exit: toolResp };
|
|
34410
34500
|
case "Invalid" /* Invalid */:
|
|
34411
|
-
await callback({ kind: "ToolInvalid" /* ToolInvalid */,
|
|
34501
|
+
await this.#callback({ kind: "ToolInvalid" /* ToolInvalid */, agent: this, tool: content.name });
|
|
34412
34502
|
toolReponses.push({ tool: content.name, response: toolResp.message });
|
|
34413
34503
|
break outer;
|
|
34414
34504
|
case "Error" /* Error */:
|
|
34415
|
-
await callback({ kind: "ToolError" /* ToolError */,
|
|
34505
|
+
await this.#callback({ kind: "ToolError" /* ToolError */, agent: this, tool: content.name });
|
|
34416
34506
|
toolReponses.push({ tool: content.name, response: toolResp.message });
|
|
34417
34507
|
break outer;
|
|
34418
34508
|
case "Interrupted" /* Interrupted */:
|
|
34419
|
-
await callback({ kind: "ToolInterrupted" /* ToolInterrupted */,
|
|
34420
|
-
return
|
|
34509
|
+
await this.#callback({ kind: "ToolInterrupted" /* ToolInterrupted */, agent: this, tool: content.name });
|
|
34510
|
+
return { exit: toolResp };
|
|
34421
34511
|
case "HandOver" /* HandOver */:
|
|
34422
|
-
await callback({
|
|
34512
|
+
await this.#callback({
|
|
34423
34513
|
kind: "ToolHandOver" /* ToolHandOver */,
|
|
34424
|
-
|
|
34514
|
+
agent: this,
|
|
34515
|
+
tool: content.name,
|
|
34516
|
+
agentName: toolResp.agentName,
|
|
34517
|
+
task: toolResp.task,
|
|
34518
|
+
context: toolResp.context,
|
|
34519
|
+
files: toolResp.files
|
|
34520
|
+
});
|
|
34521
|
+
return { exit: toolResp };
|
|
34522
|
+
case "Delegate" /* Delegate */:
|
|
34523
|
+
await this.#callback({
|
|
34524
|
+
kind: "ToolDelegate" /* ToolDelegate */,
|
|
34525
|
+
agent: this,
|
|
34425
34526
|
tool: content.name,
|
|
34426
34527
|
agentName: toolResp.agentName,
|
|
34427
34528
|
task: toolResp.task,
|
|
34428
34529
|
context: toolResp.context,
|
|
34429
34530
|
files: toolResp.files
|
|
34430
34531
|
});
|
|
34431
|
-
return
|
|
34532
|
+
return { exit: toolResp };
|
|
34432
34533
|
}
|
|
34433
34534
|
break;
|
|
34434
34535
|
}
|
|
34435
34536
|
}
|
|
34436
34537
|
}
|
|
34437
34538
|
if (toolReponses.length === 0 && !this.config.interactive) {
|
|
34438
|
-
return
|
|
34539
|
+
return { replay: responsePrompts.requireUseTool };
|
|
34439
34540
|
}
|
|
34440
34541
|
const finalResp = toolReponses.map(({ tool, response: response2 }) => responsePrompts.toolResults(tool, response2)).join(`
|
|
34441
34542
|
|
|
34442
34543
|
`);
|
|
34443
|
-
return
|
|
34544
|
+
return { replay: finalResp };
|
|
34444
34545
|
}
|
|
34445
34546
|
async#invokeTool(name, args) {
|
|
34446
34547
|
try {
|
|
34447
|
-
const
|
|
34448
|
-
if (!
|
|
34548
|
+
const handler14 = this.handlers[name]?.handler;
|
|
34549
|
+
if (!handler14) {
|
|
34449
34550
|
return {
|
|
34450
34551
|
type: "Error" /* Error */,
|
|
34451
34552
|
message: responsePrompts.errorInvokeTool(name, "Tool not found"),
|
|
@@ -34456,7 +34557,7 @@ ${agents}`;
|
|
|
34456
34557
|
if (resp) {
|
|
34457
34558
|
return resp;
|
|
34458
34559
|
}
|
|
34459
|
-
return await
|
|
34560
|
+
return await handler14(this.config.provider, args);
|
|
34460
34561
|
} catch (error) {
|
|
34461
34562
|
return {
|
|
34462
34563
|
type: "Error" /* Error */,
|
|
@@ -34511,12 +34612,13 @@ class AnalyzerAgent extends AgentBase {
|
|
|
34511
34612
|
askFollowupQuestion_default,
|
|
34512
34613
|
attemptCompletion_default,
|
|
34513
34614
|
handOver_default,
|
|
34615
|
+
delegate_default,
|
|
34514
34616
|
listCodeDefinitionNames_default,
|
|
34515
34617
|
listFiles_default,
|
|
34516
34618
|
readFile_default,
|
|
34517
34619
|
searchFiles_default
|
|
34518
34620
|
];
|
|
34519
|
-
const tools = getAvailableTools(options.provider, agentTools);
|
|
34621
|
+
const tools = getAvailableTools(options.provider, agentTools, (options.agents?.length ?? 0) > 0);
|
|
34520
34622
|
const toolNamePrefix = "tool_";
|
|
34521
34623
|
const systemPrompt = fullSystemPrompt({
|
|
34522
34624
|
os: options.os
|
|
@@ -34528,7 +34630,8 @@ class AnalyzerAgent extends AgentBase {
|
|
|
34528
34630
|
provider: options.provider,
|
|
34529
34631
|
interactive: options.interactive,
|
|
34530
34632
|
agents: options.agents,
|
|
34531
|
-
scripts: options.scripts
|
|
34633
|
+
scripts: options.scripts,
|
|
34634
|
+
callback: options.callback
|
|
34532
34635
|
});
|
|
34533
34636
|
}
|
|
34534
34637
|
onBeforeInvokeTool() {
|
|
@@ -34557,7 +34660,7 @@ You are the **Architect** agent, responsible for:
|
|
|
34557
34660
|
3. **File Reading** – Use the provided tools to gather information from these files.
|
|
34558
34661
|
4. **Implementation Plan** – Draft a concise plan detailing steps, resources, and dependencies.
|
|
34559
34662
|
5. **Review & Improve** – Evaluate and refine the plan.
|
|
34560
|
-
6. **Handover** – Provide the final plan, context, and files to the **Coder** agent.
|
|
34663
|
+
6. **Handover/Delegate** – Provide the final plan, context, and files to the **Coder** agent.
|
|
34561
34664
|
|
|
34562
34665
|
> **Note**: The **Architect** agent must not make any direct modifications. Your role is limited to creating the implementation plan and handing it over to the **Coder** agent, who will perform any actual changes.
|
|
34563
34666
|
|
|
@@ -34590,7 +34693,7 @@ You are the **Architect** agent, responsible for:
|
|
|
34590
34693
|
- Check the plan for consistency, clarity, and feasibility.
|
|
34591
34694
|
- Make adjustments or refinements to ensure accuracy and efficiency.
|
|
34592
34695
|
|
|
34593
|
-
6. **Handover**
|
|
34696
|
+
6. **Handover/Delegate**
|
|
34594
34697
|
- Deliver the final implementation plan, context, and relevant files to the **Coder** agent.
|
|
34595
34698
|
- Provide any additional instructions or clarifications needed for successful implementation.
|
|
34596
34699
|
${toolUsePrompt(tools, toolNamePrefix)}
|
|
@@ -34609,12 +34712,13 @@ class ArchitectAgent extends AgentBase {
|
|
|
34609
34712
|
askFollowupQuestion_default,
|
|
34610
34713
|
attemptCompletion_default,
|
|
34611
34714
|
handOver_default,
|
|
34715
|
+
delegate_default,
|
|
34612
34716
|
listCodeDefinitionNames_default,
|
|
34613
34717
|
listFiles_default,
|
|
34614
34718
|
readFile_default,
|
|
34615
34719
|
searchFiles_default
|
|
34616
34720
|
];
|
|
34617
|
-
const tools = getAvailableTools(options.provider, agentTools);
|
|
34721
|
+
const tools = getAvailableTools(options.provider, agentTools, (options.agents?.length ?? 0) > 0);
|
|
34618
34722
|
const toolNamePrefix = "tool_";
|
|
34619
34723
|
const systemPrompt = fullSystemPrompt2({
|
|
34620
34724
|
os: options.os
|
|
@@ -34626,7 +34730,8 @@ class ArchitectAgent extends AgentBase {
|
|
|
34626
34730
|
provider: options.provider,
|
|
34627
34731
|
interactive: options.interactive,
|
|
34628
34732
|
agents: options.agents,
|
|
34629
|
-
scripts: options.scripts
|
|
34733
|
+
scripts: options.scripts,
|
|
34734
|
+
callback: options.callback
|
|
34630
34735
|
});
|
|
34631
34736
|
}
|
|
34632
34737
|
onBeforeInvokeTool() {
|
|
@@ -34761,7 +34866,7 @@ ${interactiveMode(interactive)}
|
|
|
34761
34866
|
class CoderAgent extends AgentBase {
|
|
34762
34867
|
constructor(options) {
|
|
34763
34868
|
const combinedTools = [...options.additionalTools ?? [], ...Object.values(exports_allTools)];
|
|
34764
|
-
const tools = getAvailableTools(options.provider, combinedTools);
|
|
34869
|
+
const tools = getAvailableTools(options.provider, combinedTools, (options.agents?.length ?? 0) > 0);
|
|
34765
34870
|
const toolNamePrefix = "tool_";
|
|
34766
34871
|
const systemPrompt = fullSystemPrompt3({
|
|
34767
34872
|
os: options.os
|
|
@@ -34773,7 +34878,8 @@ class CoderAgent extends AgentBase {
|
|
|
34773
34878
|
provider: options.provider,
|
|
34774
34879
|
interactive: options.interactive,
|
|
34775
34880
|
agents: options.agents,
|
|
34776
|
-
scripts: options.scripts
|
|
34881
|
+
scripts: options.scripts,
|
|
34882
|
+
callback: options.callback
|
|
34777
34883
|
});
|
|
34778
34884
|
}
|
|
34779
34885
|
async onBeforeInvokeTool(name, args) {
|
|
@@ -34834,48 +34940,140 @@ var coderAgentInfo = {
|
|
|
34834
34940
|
// ../core/src/Agent/MultiAgent.ts
|
|
34835
34941
|
class MultiAgent {
|
|
34836
34942
|
#config;
|
|
34837
|
-
#
|
|
34943
|
+
#agents = [];
|
|
34838
34944
|
constructor(config) {
|
|
34839
34945
|
this.#config = config;
|
|
34840
34946
|
}
|
|
34841
|
-
|
|
34842
|
-
|
|
34947
|
+
async#handleTaskResult(exitReason) {
|
|
34948
|
+
switch (exitReason.type) {
|
|
34949
|
+
case "HandOver" /* HandOver */: {
|
|
34950
|
+
this.#agents.pop();
|
|
34951
|
+
const newContext = await this.#config.getContext?.(exitReason.agentName, exitReason.context, exitReason.files);
|
|
34952
|
+
return await this.#startTask(exitReason.agentName, exitReason.task, newContext);
|
|
34953
|
+
}
|
|
34954
|
+
case "Delegate" /* Delegate */: {
|
|
34955
|
+
const newContext = await this.#config.getContext?.(exitReason.agentName, exitReason.context, exitReason.files);
|
|
34956
|
+
const delegateResult = await this.#startTask(exitReason.agentName, exitReason.task, newContext);
|
|
34957
|
+
switch (delegateResult.type) {
|
|
34958
|
+
case "HandOver" /* HandOver */:
|
|
34959
|
+
case "Delegate" /* Delegate */:
|
|
34960
|
+
console.warn("Unexpected exit reason", delegateResult);
|
|
34961
|
+
break;
|
|
34962
|
+
case "Interrupted" /* Interrupted */:
|
|
34963
|
+
return delegateResult;
|
|
34964
|
+
case "Exit" /* Exit */:
|
|
34965
|
+
return this.continueTask(delegateResult.message);
|
|
34966
|
+
}
|
|
34967
|
+
return delegateResult;
|
|
34968
|
+
}
|
|
34969
|
+
case "Interrupted" /* Interrupted */:
|
|
34970
|
+
case "Exit" /* Exit */:
|
|
34971
|
+
this.#agents.pop();
|
|
34972
|
+
return exitReason;
|
|
34973
|
+
default:
|
|
34974
|
+
return exitReason;
|
|
34975
|
+
}
|
|
34843
34976
|
}
|
|
34844
|
-
async#startTask(agentName, task, context
|
|
34845
|
-
|
|
34846
|
-
|
|
34977
|
+
async#startTask(agentName, task, context) {
|
|
34978
|
+
const newAgent = await this.#config.createAgent(agentName);
|
|
34979
|
+
this.#agents.push(newAgent);
|
|
34980
|
+
const exitReason = await newAgent.startTask({
|
|
34847
34981
|
task,
|
|
34848
|
-
context
|
|
34849
|
-
callback
|
|
34982
|
+
context
|
|
34850
34983
|
});
|
|
34851
|
-
|
|
34852
|
-
return [exitReason, info];
|
|
34853
|
-
}
|
|
34854
|
-
if (exitReason.type === "HandOver") {
|
|
34855
|
-
const context2 = await this.#config.getContext?.(agentName, exitReason.context, exitReason.files);
|
|
34856
|
-
return await this.#startTask(exitReason.agentName, exitReason.task, context2, callback);
|
|
34857
|
-
}
|
|
34858
|
-
return [exitReason, info];
|
|
34984
|
+
return await this.#handleTaskResult(exitReason);
|
|
34859
34985
|
}
|
|
34860
34986
|
async startTask(options) {
|
|
34861
|
-
if (this.#
|
|
34987
|
+
if (this.#agents.length > 0) {
|
|
34862
34988
|
throw new Error("An active agent already exists");
|
|
34863
34989
|
}
|
|
34864
|
-
return this.#startTask(options.agentName, options.task, options.context
|
|
34990
|
+
return this.#startTask(options.agentName, options.task, options.context);
|
|
34865
34991
|
}
|
|
34866
|
-
async continueTask(userMessage
|
|
34867
|
-
|
|
34868
|
-
if (!this.#activeAgent) {
|
|
34992
|
+
async continueTask(userMessage) {
|
|
34993
|
+
if (!this.#agents.length) {
|
|
34869
34994
|
throw new Error("No active agent");
|
|
34870
34995
|
}
|
|
34871
|
-
|
|
34996
|
+
const exitReason = await this.#agents[this.#agents.length - 1].continueTask(userMessage);
|
|
34997
|
+
return await this.#handleTaskResult(exitReason);
|
|
34872
34998
|
}
|
|
34873
34999
|
}
|
|
34874
35000
|
|
|
34875
35001
|
// ../core/src/Agent/index.ts
|
|
34876
35002
|
var allAgents = [architectAgentInfo, coderAgentInfo, analyzerAgentInfo];
|
|
35003
|
+
// ../core/src/AiTool/createNewProject.ts
|
|
35004
|
+
var prompt = `You are an AiTool designed to assist users in creating new projects. Follow these guidelines:
|
|
35005
|
+
|
|
35006
|
+
1. **Gather Information:**
|
|
35007
|
+
- Begin by asking the user for essential project details, including:
|
|
35008
|
+
- Project type (e.g., web, mobile, desktop, etc.)
|
|
35009
|
+
- Desired programming languages
|
|
35010
|
+
- Preferred frameworks or libraries
|
|
35011
|
+
- Build tools and package manager preferences
|
|
35012
|
+
- Testing frameworks and patterns
|
|
35013
|
+
- Code style and linting preferences
|
|
35014
|
+
- Any additional specifications or requirements
|
|
35015
|
+
|
|
35016
|
+
2. **Clarification & Confirmation:**
|
|
35017
|
+
- Do not make any decisions or assumptions on behalf of the user.
|
|
35018
|
+
- Ask clarifying questions if any detail is ambiguous.
|
|
35019
|
+
- Confirm each piece of information with the user before proceeding to the next step.
|
|
35020
|
+
|
|
35021
|
+
3. **Avoid Redundancy:**
|
|
35022
|
+
- Do not repeat questions or details that have already been confirmed.
|
|
35023
|
+
- Keep interactions concise and focused on gathering complete and accurate details.
|
|
35024
|
+
|
|
35025
|
+
4. **Generate Configuration:**
|
|
35026
|
+
- Based on the collected information, generate a .polkacodes.yml configuration file that includes:
|
|
35027
|
+
- scripts section with common development commands (test, format, check, etc.)
|
|
35028
|
+
- rules section reflecting project conventions and tools
|
|
35029
|
+
- excludeFiles section for sensitive and generated files
|
|
35030
|
+
- Example structure:
|
|
35031
|
+
\`\`\`yaml
|
|
35032
|
+
scripts:
|
|
35033
|
+
test:
|
|
35034
|
+
command: "[test-command]"
|
|
35035
|
+
description: "Run tests"
|
|
35036
|
+
format:
|
|
35037
|
+
command: "[format-command]"
|
|
35038
|
+
description: "Format code"
|
|
35039
|
+
check:
|
|
35040
|
+
command: "[check-command]"
|
|
35041
|
+
description: "Check code"
|
|
35042
|
+
|
|
35043
|
+
rules:
|
|
35044
|
+
- "[package-manager-rule]"
|
|
35045
|
+
- "[testing-framework-rule]"
|
|
35046
|
+
- "[code-style-rule]"
|
|
35047
|
+
- "[other-rule]"
|
|
35048
|
+
|
|
35049
|
+
excludeFiles:
|
|
35050
|
+
- ".env"
|
|
35051
|
+
- ".env.*"
|
|
35052
|
+
\`\`\`
|
|
35053
|
+
|
|
35054
|
+
5. **Handover to Coder Agent:**
|
|
35055
|
+
- Once all required information is collected and validated by the user, compile:
|
|
35056
|
+
1. The final project specifications
|
|
35057
|
+
2. The .polkacodes.yml configuration content
|
|
35058
|
+
- Clearly hand over these details to the coder agent, instructing them to:
|
|
35059
|
+
1. Create the new project based on the confirmed specifications
|
|
35060
|
+
2. Include the .polkacodes.yml file in the project root
|
|
35061
|
+
3. Ensure all specified tools and configurations are properly set up`;
|
|
35062
|
+
var createNewProject_default = {
|
|
35063
|
+
name: "createNewProject",
|
|
35064
|
+
description: "Creates a new project",
|
|
35065
|
+
prompt,
|
|
35066
|
+
formatInput: (params) => {
|
|
35067
|
+
return `<project_name>${params}</project_name>`;
|
|
35068
|
+
},
|
|
35069
|
+
parseOutput: (output) => {
|
|
35070
|
+
return output.trim();
|
|
35071
|
+
},
|
|
35072
|
+
agent: "architect"
|
|
35073
|
+
};
|
|
35074
|
+
|
|
34877
35075
|
// ../core/src/AiTool/generateGitCommitMessage.ts
|
|
34878
|
-
var
|
|
35076
|
+
var prompt2 = `
|
|
34879
35077
|
You are an advanced assistant specialized in creating concise and accurate Git commit messages. When you receive:
|
|
34880
35078
|
- A Git diff inside the <tool_input> tag.
|
|
34881
35079
|
- Additional user-supplied context inside the <tool_input_context> tag (if any).
|
|
@@ -34910,7 +35108,7 @@ Follow the same structure for any new input. Never repeat questions; focus on ge
|
|
|
34910
35108
|
var generateGitCommitMessage_default = {
|
|
34911
35109
|
name: "generateGitCommitMessage",
|
|
34912
35110
|
description: "Generates git commit messages from git diff output",
|
|
34913
|
-
prompt,
|
|
35111
|
+
prompt: prompt2,
|
|
34914
35112
|
formatInput: (params) => {
|
|
34915
35113
|
let ret = `<tool_input>
|
|
34916
35114
|
${params.diff}
|
|
@@ -34935,7 +35133,7 @@ ${output}`);
|
|
|
34935
35133
|
};
|
|
34936
35134
|
|
|
34937
35135
|
// ../core/src/AiTool/generateGithubPullRequestDetails.ts
|
|
34938
|
-
var
|
|
35136
|
+
var prompt3 = `
|
|
34939
35137
|
# Generate Github Pull Request Details
|
|
34940
35138
|
|
|
34941
35139
|
You are given:
|
|
@@ -35019,7 +35217,7 @@ Use the above format whenever you receive <tool_input> that may include a branch
|
|
|
35019
35217
|
var generateGithubPullRequestDetails_default = {
|
|
35020
35218
|
name: "generateGithubPullRequestDetails",
|
|
35021
35219
|
description: "Generates a GitHub pull request title and description from git commits",
|
|
35022
|
-
prompt:
|
|
35220
|
+
prompt: prompt3,
|
|
35023
35221
|
formatInput: (params) => {
|
|
35024
35222
|
return `<tool_input>
|
|
35025
35223
|
<tool_input_branch_name>${params.branchName}</tool_input_branch_name>${params.context ? `
|
|
@@ -35052,7 +35250,7 @@ ${output}`);
|
|
|
35052
35250
|
};
|
|
35053
35251
|
|
|
35054
35252
|
// ../core/src/AiTool/generateProjectConfig.ts
|
|
35055
|
-
var
|
|
35253
|
+
var prompt4 = `You are an analyzer agent responsible for examining project files and generating appropriate polkacodes configuration. Your task is to:
|
|
35056
35254
|
|
|
35057
35255
|
1. Read and analyze the provided files using tool_read_file to understand:
|
|
35058
35256
|
- Build tools and package manager (e.g., bun, npm)
|
|
@@ -35119,12 +35317,9 @@ The configuration should accurately reflect the project's structure, tools, and
|
|
|
35119
35317
|
var generateProjectConfig_default = {
|
|
35120
35318
|
name: "generateProjectConfig",
|
|
35121
35319
|
description: "Analyzes project files to generate polkacodes config sections",
|
|
35122
|
-
prompt:
|
|
35123
|
-
formatInput: (
|
|
35124
|
-
return
|
|
35125
|
-
${params.join(`
|
|
35126
|
-
`)}
|
|
35127
|
-
</tool_input>`;
|
|
35320
|
+
prompt: prompt4,
|
|
35321
|
+
formatInput: () => {
|
|
35322
|
+
return "";
|
|
35128
35323
|
},
|
|
35129
35324
|
parseOutput: (output) => {
|
|
35130
35325
|
return output.trim();
|
|
@@ -35142,15 +35337,14 @@ var executeTool = async (definition, ai, params) => {
|
|
|
35142
35337
|
usage
|
|
35143
35338
|
};
|
|
35144
35339
|
};
|
|
35145
|
-
var executeAgentTool = async (definition, agent, params
|
|
35340
|
+
var executeAgentTool = async (definition, agent, params) => {
|
|
35146
35341
|
if (!definition.agent) {
|
|
35147
35342
|
throw new Error("Agent not specified");
|
|
35148
35343
|
}
|
|
35149
|
-
const
|
|
35344
|
+
const exitReason = await agent.startTask({
|
|
35150
35345
|
agentName: definition.agent,
|
|
35151
35346
|
task: definition.prompt,
|
|
35152
|
-
context: definition.formatInput(params)
|
|
35153
|
-
callback
|
|
35347
|
+
context: definition.formatInput(params)
|
|
35154
35348
|
});
|
|
35155
35349
|
if (exitReason.type === "Exit" /* Exit */) {
|
|
35156
35350
|
return definition.parseOutput(exitReason.message);
|
|
@@ -35163,13 +35357,14 @@ var makeTool = (definition) => {
|
|
|
35163
35357
|
};
|
|
35164
35358
|
};
|
|
35165
35359
|
var makeAgentTool = (definition) => {
|
|
35166
|
-
return async (agent, params
|
|
35167
|
-
return executeAgentTool(definition, agent, params
|
|
35360
|
+
return async (agent, params) => {
|
|
35361
|
+
return executeAgentTool(definition, agent, params);
|
|
35168
35362
|
};
|
|
35169
35363
|
};
|
|
35170
35364
|
var generateGitCommitMessage = makeTool(generateGitCommitMessage_default);
|
|
35171
35365
|
var generateGithubPullRequestDetails = makeTool(generateGithubPullRequestDetails_default);
|
|
35172
35366
|
var generateProjectConfig = makeAgentTool(generateProjectConfig_default);
|
|
35367
|
+
var createNewProject = makeAgentTool(createNewProject_default);
|
|
35173
35368
|
// src/Chat.ts
|
|
35174
35369
|
import readline from "node:readline";
|
|
35175
35370
|
|
|
@@ -35870,15 +36065,15 @@ function useKeypress(userHandler) {
|
|
|
35870
36065
|
signal.current = userHandler;
|
|
35871
36066
|
useEffect((rl) => {
|
|
35872
36067
|
let ignore = false;
|
|
35873
|
-
const
|
|
36068
|
+
const handler14 = withUpdates((_input, event) => {
|
|
35874
36069
|
if (ignore)
|
|
35875
36070
|
return;
|
|
35876
36071
|
signal.current(event, rl);
|
|
35877
36072
|
});
|
|
35878
|
-
rl.input.on("keypress",
|
|
36073
|
+
rl.input.on("keypress", handler14);
|
|
35879
36074
|
return () => {
|
|
35880
36075
|
ignore = true;
|
|
35881
|
-
rl.input.removeListener("keypress",
|
|
36076
|
+
rl.input.removeListener("keypress", handler14);
|
|
35882
36077
|
};
|
|
35883
36078
|
}, []);
|
|
35884
36079
|
}
|
|
@@ -36060,16 +36255,16 @@ class Emitter {
|
|
|
36060
36255
|
|
|
36061
36256
|
class SignalExitBase {
|
|
36062
36257
|
}
|
|
36063
|
-
var signalExitWrap = (
|
|
36258
|
+
var signalExitWrap = (handler14) => {
|
|
36064
36259
|
return {
|
|
36065
36260
|
onExit(cb, opts) {
|
|
36066
|
-
return
|
|
36261
|
+
return handler14.onExit(cb, opts);
|
|
36067
36262
|
},
|
|
36068
36263
|
load() {
|
|
36069
|
-
return
|
|
36264
|
+
return handler14.load();
|
|
36070
36265
|
},
|
|
36071
36266
|
unload() {
|
|
36072
|
-
return
|
|
36267
|
+
return handler14.unload();
|
|
36073
36268
|
}
|
|
36074
36269
|
};
|
|
36075
36270
|
};
|
|
@@ -36232,11 +36427,11 @@ class ScreenManager {
|
|
|
36232
36427
|
render(content, bottomContent = "") {
|
|
36233
36428
|
const promptLine = lastLine(content);
|
|
36234
36429
|
const rawPromptLine = import_strip_ansi.default(promptLine);
|
|
36235
|
-
let
|
|
36430
|
+
let prompt5 = rawPromptLine;
|
|
36236
36431
|
if (this.rl.line.length > 0) {
|
|
36237
|
-
|
|
36432
|
+
prompt5 = prompt5.slice(0, -this.rl.line.length);
|
|
36238
36433
|
}
|
|
36239
|
-
this.rl.setPrompt(
|
|
36434
|
+
this.rl.setPrompt(prompt5);
|
|
36240
36435
|
this.cursorPos = this.rl.getCursorPos();
|
|
36241
36436
|
const width = readlineWidth();
|
|
36242
36437
|
content = breakLines(content, width);
|
|
@@ -36306,7 +36501,7 @@ function getCallSites() {
|
|
|
36306
36501
|
function createPrompt(view) {
|
|
36307
36502
|
const callSites = getCallSites();
|
|
36308
36503
|
const callerFilename = callSites[1]?.getFileName?.();
|
|
36309
|
-
const
|
|
36504
|
+
const prompt5 = (config, context = {}) => {
|
|
36310
36505
|
const { input = process.stdin, signal } = context;
|
|
36311
36506
|
const cleanups = new Set;
|
|
36312
36507
|
const output = new import_mute_stream.default;
|
|
@@ -36367,7 +36562,7 @@ function createPrompt(view) {
|
|
|
36367
36562
|
}).then(() => promise), { cancel });
|
|
36368
36563
|
});
|
|
36369
36564
|
};
|
|
36370
|
-
return
|
|
36565
|
+
return prompt5;
|
|
36371
36566
|
}
|
|
36372
36567
|
// ../../node_modules/@inquirer/core/dist/esm/lib/Separator.js
|
|
36373
36568
|
var import_yoctocolors_cjs2 = __toESM(require_yoctocolors_cjs(), 1);
|
|
@@ -36901,20 +37096,14 @@ var getProvider = (agentName, config, options = {}) => {
|
|
|
36901
37096
|
// src/Runner.ts
|
|
36902
37097
|
class Runner {
|
|
36903
37098
|
#options;
|
|
36904
|
-
#multiAgent;
|
|
36905
37099
|
#usageMeter;
|
|
37100
|
+
multiAgent;
|
|
36906
37101
|
constructor(options) {
|
|
36907
37102
|
this.#options = options;
|
|
36908
37103
|
this.#usageMeter = new UsageMeter({
|
|
36909
37104
|
maxCost: options.budget,
|
|
36910
37105
|
maxMessageCount: options.maxMessageCount
|
|
36911
37106
|
});
|
|
36912
|
-
const service = createService(options.provider, {
|
|
36913
|
-
apiKey: options.apiKey,
|
|
36914
|
-
model: options.model,
|
|
36915
|
-
usageMeter: this.#usageMeter,
|
|
36916
|
-
enableCache: options.enableCache
|
|
36917
|
-
});
|
|
36918
37107
|
let rules2 = options.config.rules;
|
|
36919
37108
|
if (typeof rules2 === "string") {
|
|
36920
37109
|
rules2 = [rules2];
|
|
@@ -36941,40 +37130,56 @@ class Runner {
|
|
|
36941
37130
|
interactive: options.interactive
|
|
36942
37131
|
};
|
|
36943
37132
|
const platform = os.platform();
|
|
36944
|
-
const
|
|
36945
|
-
|
|
37133
|
+
const services = {};
|
|
37134
|
+
const getOrCreateService = (agentName) => {
|
|
37135
|
+
const config = this.#options.providerConfig.getConfigForAgent(agentName);
|
|
37136
|
+
if (!config) {
|
|
37137
|
+
const service2 = Object.values(Object.values(services)[0] ?? {})[0];
|
|
37138
|
+
if (service2) {
|
|
37139
|
+
return service2;
|
|
37140
|
+
}
|
|
37141
|
+
throw new Error(`No provider configured for agent: ${agentName}`);
|
|
37142
|
+
}
|
|
37143
|
+
const { provider: provider2, model, apiKey } = config;
|
|
37144
|
+
let service = services[provider2]?.[model];
|
|
37145
|
+
if (!service) {
|
|
37146
|
+
service = createService(provider2, {
|
|
37147
|
+
apiKey,
|
|
37148
|
+
model,
|
|
37149
|
+
usageMeter: this.#usageMeter,
|
|
37150
|
+
enableCache: options.enableCache
|
|
37151
|
+
});
|
|
37152
|
+
services[provider2] = { [model]: service };
|
|
37153
|
+
}
|
|
37154
|
+
return service;
|
|
37155
|
+
};
|
|
37156
|
+
this.multiAgent = new MultiAgent({
|
|
36946
37157
|
createAgent: async (name) => {
|
|
36947
37158
|
const agentName = name.trim().toLowerCase();
|
|
37159
|
+
const args = {
|
|
37160
|
+
ai: getOrCreateService(agentName),
|
|
37161
|
+
os: platform,
|
|
37162
|
+
customInstructions: rules2,
|
|
37163
|
+
scripts: options.config.scripts,
|
|
37164
|
+
interactive: options.interactive,
|
|
37165
|
+
agents: this.#options.availableAgents ?? [coderAgentInfo, architectAgentInfo, analyzerAgentInfo],
|
|
37166
|
+
callback: this.#options.eventCallback
|
|
37167
|
+
};
|
|
36948
37168
|
switch (agentName) {
|
|
36949
37169
|
case coderAgentInfo.name:
|
|
36950
37170
|
return new CoderAgent({
|
|
36951
|
-
|
|
36952
|
-
|
|
36953
|
-
customInstructions: rules2,
|
|
36954
|
-
scripts: options.config.scripts,
|
|
36955
|
-
provider: getProvider("coder", options.config, providerOptions),
|
|
36956
|
-
interactive: options.interactive,
|
|
36957
|
-
agents
|
|
37171
|
+
...args,
|
|
37172
|
+
provider: getProvider(agentName, options.config, providerOptions)
|
|
36958
37173
|
});
|
|
36959
37174
|
case architectAgentInfo.name:
|
|
36960
37175
|
return new ArchitectAgent({
|
|
36961
|
-
|
|
36962
|
-
|
|
36963
|
-
customInstructions: rules2,
|
|
36964
|
-
scripts: options.config.scripts,
|
|
36965
|
-
provider: getProvider("architect", options.config, providerOptions),
|
|
36966
|
-
interactive: options.interactive,
|
|
36967
|
-
agents
|
|
37176
|
+
...args,
|
|
37177
|
+
provider: getProvider(agentName, options.config, providerOptions)
|
|
36968
37178
|
});
|
|
36969
37179
|
case analyzerAgentInfo.name:
|
|
36970
37180
|
return new AnalyzerAgent({
|
|
36971
|
-
|
|
36972
|
-
|
|
36973
|
-
customInstructions: rules2,
|
|
36974
|
-
scripts: options.config.scripts,
|
|
36975
|
-
provider: getProvider("analyzer", options.config, providerOptions),
|
|
36976
|
-
interactive: options.interactive,
|
|
36977
|
-
agents
|
|
37181
|
+
...args,
|
|
37182
|
+
provider: getProvider(agentName, options.config, providerOptions)
|
|
36978
37183
|
});
|
|
36979
37184
|
default:
|
|
36980
37185
|
throw new Error(`Unknown agent: ${name}`);
|
|
@@ -37028,18 +37233,16 @@ ${fileList.join(`
|
|
|
37028
37233
|
</files>`;
|
|
37029
37234
|
return `<now_date>${new Date().toISOString()}</now_date>${fileContext}`;
|
|
37030
37235
|
}
|
|
37031
|
-
async startTask(task) {
|
|
37032
|
-
const
|
|
37033
|
-
const [exitReason, info] = await this.#multiAgent.startTask({
|
|
37236
|
+
async startTask(task, agentName = architectAgentInfo.name, context) {
|
|
37237
|
+
const exitReason = await this.multiAgent.startTask({
|
|
37034
37238
|
agentName,
|
|
37035
37239
|
task,
|
|
37036
|
-
context: await this.#defaultContext(agentName)
|
|
37037
|
-
callback: this.#options.eventCallback
|
|
37240
|
+
context: context ?? await this.#defaultContext(agentName)
|
|
37038
37241
|
});
|
|
37039
|
-
return
|
|
37242
|
+
return exitReason;
|
|
37040
37243
|
}
|
|
37041
|
-
async continueTask(message
|
|
37042
|
-
return await this
|
|
37244
|
+
async continueTask(message) {
|
|
37245
|
+
return await this.multiAgent.continueTask(message);
|
|
37043
37246
|
}
|
|
37044
37247
|
get usage() {
|
|
37045
37248
|
return this.#usageMeter.usage;
|
|
@@ -37107,6 +37310,48 @@ async function configPrompt(existingConfig) {
|
|
|
37107
37310
|
import os2 from "node:os";
|
|
37108
37311
|
var import_lodash2 = __toESM(require_lodash(), 1);
|
|
37109
37312
|
|
|
37313
|
+
// src/ApiProviderConfig.ts
|
|
37314
|
+
class ApiProviderConfig {
|
|
37315
|
+
defaultProvider;
|
|
37316
|
+
providers;
|
|
37317
|
+
commands;
|
|
37318
|
+
agents;
|
|
37319
|
+
constructor(config) {
|
|
37320
|
+
this.defaultProvider = config.defaultProvider;
|
|
37321
|
+
this.providers = config.providers ?? {};
|
|
37322
|
+
this.commands = config.commands;
|
|
37323
|
+
this.agents = config.agents;
|
|
37324
|
+
}
|
|
37325
|
+
getConfigForCommand(command) {
|
|
37326
|
+
const { provider: provider2, model } = this.commands?.[command] ?? this.commands?.default ?? {};
|
|
37327
|
+
const finalProvider = provider2 ?? this.defaultProvider;
|
|
37328
|
+
if (!finalProvider) {
|
|
37329
|
+
return;
|
|
37330
|
+
}
|
|
37331
|
+
const finalModel = model ?? this.providers[finalProvider]?.defaultModel ?? defaultModels[finalProvider];
|
|
37332
|
+
const apiKey = this.providers[finalProvider]?.apiKey;
|
|
37333
|
+
return {
|
|
37334
|
+
provider: finalProvider,
|
|
37335
|
+
model: finalModel,
|
|
37336
|
+
apiKey
|
|
37337
|
+
};
|
|
37338
|
+
}
|
|
37339
|
+
getConfigForAgent(agent) {
|
|
37340
|
+
const { provider: provider2, model } = this.agents?.[agent] ?? this.agents?.default ?? {};
|
|
37341
|
+
const finalProvider = provider2 ?? this.defaultProvider;
|
|
37342
|
+
if (!finalProvider) {
|
|
37343
|
+
return;
|
|
37344
|
+
}
|
|
37345
|
+
const finalModel = model ?? this.providers[finalProvider]?.defaultModel ?? defaultModels[finalProvider];
|
|
37346
|
+
const apiKey = this.providers[finalProvider]?.apiKey;
|
|
37347
|
+
return {
|
|
37348
|
+
provider: finalProvider,
|
|
37349
|
+
model: finalModel,
|
|
37350
|
+
apiKey
|
|
37351
|
+
};
|
|
37352
|
+
}
|
|
37353
|
+
}
|
|
37354
|
+
|
|
37110
37355
|
// src/config.ts
|
|
37111
37356
|
var import_lodash = __toESM(require_lodash(), 1);
|
|
37112
37357
|
import { existsSync, readFileSync } from "node:fs";
|
|
@@ -41264,47 +41509,6 @@ var readConfig = (path2) => {
|
|
|
41264
41509
|
function addSharedOptions(command) {
|
|
41265
41510
|
return command.option("-c --config <path>", "Path to config file").option("--api-provider <provider>", "API provider").option("--model <model>", "Model ID").option("--api-key <key>", "API key").option("--max-messages <iterations>", "Maximum number of messages to send. Default to 50", Number.parseInt, 50).option("--budget <budget>", "Budget for the AI service. Default to $1000", Number.parseFloat, 1000).option("-v --verbose", "Enable verbose output. Use -v for level 1, -vv for level 2", (value, prev) => prev + 1, 0);
|
|
41266
41511
|
}
|
|
41267
|
-
|
|
41268
|
-
class ApiProviderConfig {
|
|
41269
|
-
defaultProvider;
|
|
41270
|
-
providers;
|
|
41271
|
-
commands;
|
|
41272
|
-
agents;
|
|
41273
|
-
constructor(config) {
|
|
41274
|
-
this.defaultProvider = config.defaultProvider;
|
|
41275
|
-
this.providers = config.providers ?? {};
|
|
41276
|
-
this.commands = config.commands;
|
|
41277
|
-
this.agents = config.agents;
|
|
41278
|
-
}
|
|
41279
|
-
getConfigForCommand(command) {
|
|
41280
|
-
const { provider: provider2, model } = this.commands?.[command] ?? this.commands?.default ?? {};
|
|
41281
|
-
const finalProvider = provider2 ?? this.defaultProvider;
|
|
41282
|
-
if (!finalProvider) {
|
|
41283
|
-
return;
|
|
41284
|
-
}
|
|
41285
|
-
const finalModel = model ?? this.providers[finalProvider]?.defaultModel;
|
|
41286
|
-
const apiKey = this.providers[finalProvider]?.apiKey;
|
|
41287
|
-
return {
|
|
41288
|
-
provider: finalProvider,
|
|
41289
|
-
model: finalModel,
|
|
41290
|
-
apiKey
|
|
41291
|
-
};
|
|
41292
|
-
}
|
|
41293
|
-
getConfigForAgent(agent) {
|
|
41294
|
-
const { provider: provider2, model } = this.agents?.[agent] ?? this.agents?.default ?? {};
|
|
41295
|
-
const finalProvider = provider2 ?? this.defaultProvider;
|
|
41296
|
-
if (!finalProvider) {
|
|
41297
|
-
return;
|
|
41298
|
-
}
|
|
41299
|
-
const finalModel = model ?? this.providers[finalProvider]?.defaultModel;
|
|
41300
|
-
const apiKey = this.providers[finalProvider]?.apiKey;
|
|
41301
|
-
return {
|
|
41302
|
-
provider: finalProvider,
|
|
41303
|
-
model: finalModel,
|
|
41304
|
-
apiKey
|
|
41305
|
-
};
|
|
41306
|
-
}
|
|
41307
|
-
}
|
|
41308
41512
|
function parseOptions(options, cwd = process.cwd(), home = os2.homedir()) {
|
|
41309
41513
|
const config = loadConfig(options.config ?? options.c, cwd, home) ?? {};
|
|
41310
41514
|
const defaultProvider = options.apiProvider || process.env.POLKA_API_PROVIDER || config.defaultProvider;
|
|
@@ -41885,6 +42089,17 @@ ${event.systemPrompt}`);
|
|
|
41885
42089
|
console.log(`
|
|
41886
42090
|
|
|
41887
42091
|
======== Task Handed Over ========
|
|
42092
|
+
`);
|
|
42093
|
+
console.log("Agent:", event.agentName);
|
|
42094
|
+
console.log("Task:", event.task);
|
|
42095
|
+
console.log("Context:", event.context);
|
|
42096
|
+
console.log("Files:", event.files);
|
|
42097
|
+
console.log();
|
|
42098
|
+
break;
|
|
42099
|
+
case "ToolDelegate" /* ToolDelegate */:
|
|
42100
|
+
console.log(`
|
|
42101
|
+
|
|
42102
|
+
======== Task Delegated ========
|
|
41888
42103
|
`);
|
|
41889
42104
|
console.log("Agent:", event.agentName);
|
|
41890
42105
|
console.log("Task:", event.task);
|
|
@@ -41899,6 +42114,19 @@ ${event.systemPrompt}`);
|
|
|
41899
42114
|
`);
|
|
41900
42115
|
break;
|
|
41901
42116
|
case "EndTask" /* EndTask */:
|
|
42117
|
+
console.log(`
|
|
42118
|
+
|
|
42119
|
+
======== Task Ended ========
|
|
42120
|
+
`);
|
|
42121
|
+
console.log("Reason:", event.exitReason.type);
|
|
42122
|
+
switch (event.exitReason.type) {
|
|
42123
|
+
case "Exit" /* Exit */:
|
|
42124
|
+
console.log("Exit Message:", event.exitReason.message);
|
|
42125
|
+
break;
|
|
42126
|
+
case "Interrupted" /* Interrupted */:
|
|
42127
|
+
console.log("Interrupted Message:", event.exitReason.message);
|
|
42128
|
+
break;
|
|
42129
|
+
}
|
|
41902
42130
|
break;
|
|
41903
42131
|
}
|
|
41904
42132
|
};
|
|
@@ -41911,7 +42139,8 @@ var runChat = async (opts, command) => {
|
|
|
41911
42139
|
console.error("Error: Terminal is not interactive. Please run this command in an interactive terminal.");
|
|
41912
42140
|
process.exit(1);
|
|
41913
42141
|
}
|
|
41914
|
-
|
|
42142
|
+
const startAgent = architectAgentInfo.name;
|
|
42143
|
+
let { provider: provider2, model, apiKey } = providerConfig.getConfigForAgent(startAgent) ?? {};
|
|
41915
42144
|
if (!provider2) {
|
|
41916
42145
|
const newConfig = await configPrompt({ provider: provider2, model, apiKey });
|
|
41917
42146
|
provider2 = newConfig.provider;
|
|
@@ -41924,9 +42153,7 @@ var runChat = async (opts, command) => {
|
|
|
41924
42153
|
console.log('Type ".help" for more information.');
|
|
41925
42154
|
console.log("What can I do for you?");
|
|
41926
42155
|
const runner = new Runner({
|
|
41927
|
-
|
|
41928
|
-
model: model ?? defaultModels[provider2],
|
|
41929
|
-
apiKey,
|
|
42156
|
+
providerConfig,
|
|
41930
42157
|
config: config ?? {},
|
|
41931
42158
|
maxMessageCount,
|
|
41932
42159
|
budget,
|
|
@@ -41934,17 +42161,16 @@ var runChat = async (opts, command) => {
|
|
|
41934
42161
|
eventCallback: printEvent(verbose),
|
|
41935
42162
|
enableCache: true
|
|
41936
42163
|
});
|
|
41937
|
-
let
|
|
42164
|
+
let started = false;
|
|
41938
42165
|
const chat2 = new Chat3({
|
|
41939
42166
|
onMessage: async (message) => {
|
|
41940
42167
|
let exitReason;
|
|
41941
|
-
if (
|
|
41942
|
-
const
|
|
41943
|
-
taskInfo = info;
|
|
42168
|
+
if (started) {
|
|
42169
|
+
const reason = await runner.continueTask(message);
|
|
41944
42170
|
exitReason = reason;
|
|
41945
42171
|
} else {
|
|
41946
|
-
const
|
|
41947
|
-
|
|
42172
|
+
const reason = await runner.startTask(message);
|
|
42173
|
+
started = true;
|
|
41948
42174
|
exitReason = reason;
|
|
41949
42175
|
}
|
|
41950
42176
|
switch (exitReason.type) {
|
|
@@ -42590,9 +42816,11 @@ var commitCommand = new Command("commit").description("Create a commit with AI-g
|
|
|
42590
42816
|
console.error('Error: No provider specified. Please run "polka-codes config" to configure your AI provider.');
|
|
42591
42817
|
process.exit(1);
|
|
42592
42818
|
}
|
|
42819
|
+
const usage = new UsageMeter;
|
|
42593
42820
|
const ai = createService(provider2, {
|
|
42594
42821
|
apiKey,
|
|
42595
|
-
model
|
|
42822
|
+
model,
|
|
42823
|
+
usageMeter: usage
|
|
42596
42824
|
});
|
|
42597
42825
|
try {
|
|
42598
42826
|
const status = execSync("git status --porcelain").toString();
|
|
@@ -42619,6 +42847,7 @@ var commitCommand = new Command("commit").description("Create a commit with AI-g
|
|
|
42619
42847
|
const diff = execSync("git diff --cached -U200").toString();
|
|
42620
42848
|
spinner.text = "Generating commit message...";
|
|
42621
42849
|
const result = await generateGitCommitMessage(ai, { diff, context: message });
|
|
42850
|
+
usage.printUsage();
|
|
42622
42851
|
spinner.succeed("Commit message generated");
|
|
42623
42852
|
console.log(`
|
|
42624
42853
|
Commit message:
|
|
@@ -42637,7 +42866,6 @@ ${result.response}`);
|
|
|
42637
42866
|
|
|
42638
42867
|
// src/commands/init.ts
|
|
42639
42868
|
import { existsSync as existsSync2, mkdirSync, readFileSync as readFileSync2, writeFileSync } from "node:fs";
|
|
42640
|
-
import os4 from "node:os";
|
|
42641
42869
|
import { dirname as dirname2 } from "node:path";
|
|
42642
42870
|
var import_lodash3 = __toESM(require_lodash(), 1);
|
|
42643
42871
|
var initCommand = new Command("init").description("Initialize polkacodes configuration").option("-g, --global", "Use global config");
|
|
@@ -42687,7 +42915,7 @@ initCommand.action(async (options, command) => {
|
|
|
42687
42915
|
process.exit(1);
|
|
42688
42916
|
}
|
|
42689
42917
|
}
|
|
42690
|
-
const { config, providerConfig, verbose } = parseOptions(cmdOptions);
|
|
42918
|
+
const { config, providerConfig, verbose, maxMessageCount, budget } = parseOptions(cmdOptions);
|
|
42691
42919
|
let { provider: provider2, model, apiKey } = providerConfig.getConfigForCommand("init") ?? {};
|
|
42692
42920
|
let newConfig;
|
|
42693
42921
|
if (!provider2) {
|
|
@@ -42748,41 +42976,18 @@ ${newConfig.provider.toUpperCase()}_API_KEY=${newConfig.apiKey}`;
|
|
|
42748
42976
|
});
|
|
42749
42977
|
let generatedConfig = {};
|
|
42750
42978
|
if (shouldAnalyze) {
|
|
42751
|
-
const
|
|
42752
|
-
apiKey,
|
|
42753
|
-
|
|
42754
|
-
|
|
42755
|
-
|
|
42756
|
-
|
|
42757
|
-
|
|
42758
|
-
|
|
42759
|
-
|
|
42760
|
-
case analyzerAgentInfo.name:
|
|
42761
|
-
return new AnalyzerAgent({
|
|
42762
|
-
ai: service,
|
|
42763
|
-
os: os4.platform(),
|
|
42764
|
-
provider: getProvider("analyzer", config),
|
|
42765
|
-
interactive: false
|
|
42766
|
-
});
|
|
42767
|
-
default:
|
|
42768
|
-
throw new Error(`Unknown agent: ${name}`);
|
|
42769
|
-
}
|
|
42770
|
-
}
|
|
42979
|
+
const runner = new Runner({
|
|
42980
|
+
providerConfig: new ApiProviderConfig({ defaultProvider: provider2, defaultModel: model, providers: { [provider2]: { apiKey } } }),
|
|
42981
|
+
config: {},
|
|
42982
|
+
maxMessageCount,
|
|
42983
|
+
budget,
|
|
42984
|
+
interactive: true,
|
|
42985
|
+
eventCallback: printEvent(verbose),
|
|
42986
|
+
enableCache: true,
|
|
42987
|
+
availableAgents: [analyzerAgentInfo]
|
|
42771
42988
|
});
|
|
42772
42989
|
console.log("Analyzing project files...");
|
|
42773
|
-
const
|
|
42774
|
-
const [relevantFiles] = await listFiles(".", true, 1000, process.cwd());
|
|
42775
|
-
for (const filePath of relevantFiles) {
|
|
42776
|
-
if (typeof filePath === "string" && existsSync2(filePath)) {
|
|
42777
|
-
try {
|
|
42778
|
-
const content = readFileSync2(filePath, "utf8");
|
|
42779
|
-
files[filePath] = content;
|
|
42780
|
-
} catch (error) {
|
|
42781
|
-
console.warn(`Failed to read file: ${filePath}`);
|
|
42782
|
-
}
|
|
42783
|
-
}
|
|
42784
|
-
}
|
|
42785
|
-
const { response } = await generateProjectConfig(multiAgent, relevantFiles, printEvent(verbose));
|
|
42990
|
+
const { response } = await generateProjectConfig(runner.multiAgent, undefined);
|
|
42786
42991
|
generatedConfig = response ? $parse(response) : {};
|
|
42787
42992
|
}
|
|
42788
42993
|
const finalConfig = {
|
|
@@ -42852,9 +43057,11 @@ var prCommand = new Command("pr").description("Create a GitHub pull request").ar
|
|
|
42852
43057
|
encoding: "utf-8"
|
|
42853
43058
|
});
|
|
42854
43059
|
const diff = execSync2(`git diff --cached -U200 ${defaultBranch}`, { encoding: "utf-8" });
|
|
43060
|
+
const usage = new UsageMeter;
|
|
42855
43061
|
const ai = createService(provider2, {
|
|
42856
43062
|
apiKey,
|
|
42857
|
-
model
|
|
43063
|
+
model,
|
|
43064
|
+
usageMeter: usage
|
|
42858
43065
|
});
|
|
42859
43066
|
spinner.text = "Generating pull request details...";
|
|
42860
43067
|
const prDetails = await generateGithubPullRequestDetails(ai, {
|
|
@@ -42868,6 +43075,7 @@ var prCommand = new Command("pr").description("Create a GitHub pull request").ar
|
|
|
42868
43075
|
spawnSync2("gh", ["pr", "create", "--title", prDetails.response.title.trim(), "--body", prDetails.response.description.trim()], {
|
|
42869
43076
|
stdio: "inherit"
|
|
42870
43077
|
});
|
|
43078
|
+
usage.printUsage();
|
|
42871
43079
|
} catch (error) {
|
|
42872
43080
|
console.error("Error creating pull request:", error);
|
|
42873
43081
|
process.exit(1);
|
|
@@ -42926,7 +43134,8 @@ async function runTask(taskArg, _options, command) {
|
|
|
42926
43134
|
}
|
|
42927
43135
|
}
|
|
42928
43136
|
const { config, providerConfig, verbose, maxMessageCount, budget } = parseOptions(command.opts());
|
|
42929
|
-
const
|
|
43137
|
+
const startAgent = architectAgentInfo.name;
|
|
43138
|
+
const { provider: provider2, model } = providerConfig.getConfigForAgent(startAgent) ?? {};
|
|
42930
43139
|
if (!provider2 || !model) {
|
|
42931
43140
|
console.error("Provider and model must be configured");
|
|
42932
43141
|
process.exit(1);
|
|
@@ -42934,9 +43143,7 @@ async function runTask(taskArg, _options, command) {
|
|
|
42934
43143
|
console.log("Provider:", provider2);
|
|
42935
43144
|
console.log("Model:", model);
|
|
42936
43145
|
const runner = new Runner({
|
|
42937
|
-
|
|
42938
|
-
model,
|
|
42939
|
-
apiKey,
|
|
43146
|
+
providerConfig,
|
|
42940
43147
|
config,
|
|
42941
43148
|
maxMessageCount,
|
|
42942
43149
|
budget,
|
|
@@ -42944,7 +43151,7 @@ async function runTask(taskArg, _options, command) {
|
|
|
42944
43151
|
eventCallback: printEvent(verbose),
|
|
42945
43152
|
enableCache: true
|
|
42946
43153
|
});
|
|
42947
|
-
await runner.startTask(task);
|
|
43154
|
+
await runner.startTask(task, startAgent);
|
|
42948
43155
|
runner.printUsage();
|
|
42949
43156
|
}
|
|
42950
43157
|
|