@polka-codes/cli 0.5.1 → 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 +516 -382
- 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
|
|
34039
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;
|
|
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,41 +34940,61 @@ 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
|
|
|
@@ -35192,11 +35318,8 @@ var generateProjectConfig_default = {
|
|
|
35192
35318
|
name: "generateProjectConfig",
|
|
35193
35319
|
description: "Analyzes project files to generate polkacodes config sections",
|
|
35194
35320
|
prompt: prompt4,
|
|
35195
|
-
formatInput: (
|
|
35196
|
-
return
|
|
35197
|
-
${params.join(`
|
|
35198
|
-
`)}
|
|
35199
|
-
</tool_input>`;
|
|
35321
|
+
formatInput: () => {
|
|
35322
|
+
return "";
|
|
35200
35323
|
},
|
|
35201
35324
|
parseOutput: (output) => {
|
|
35202
35325
|
return output.trim();
|
|
@@ -35214,15 +35337,14 @@ var executeTool = async (definition, ai, params) => {
|
|
|
35214
35337
|
usage
|
|
35215
35338
|
};
|
|
35216
35339
|
};
|
|
35217
|
-
var executeAgentTool = async (definition, agent, params
|
|
35340
|
+
var executeAgentTool = async (definition, agent, params) => {
|
|
35218
35341
|
if (!definition.agent) {
|
|
35219
35342
|
throw new Error("Agent not specified");
|
|
35220
35343
|
}
|
|
35221
|
-
const
|
|
35344
|
+
const exitReason = await agent.startTask({
|
|
35222
35345
|
agentName: definition.agent,
|
|
35223
35346
|
task: definition.prompt,
|
|
35224
|
-
context: definition.formatInput(params)
|
|
35225
|
-
callback
|
|
35347
|
+
context: definition.formatInput(params)
|
|
35226
35348
|
});
|
|
35227
35349
|
if (exitReason.type === "Exit" /* Exit */) {
|
|
35228
35350
|
return definition.parseOutput(exitReason.message);
|
|
@@ -35235,8 +35357,8 @@ var makeTool = (definition) => {
|
|
|
35235
35357
|
};
|
|
35236
35358
|
};
|
|
35237
35359
|
var makeAgentTool = (definition) => {
|
|
35238
|
-
return async (agent, params
|
|
35239
|
-
return executeAgentTool(definition, agent, params
|
|
35360
|
+
return async (agent, params) => {
|
|
35361
|
+
return executeAgentTool(definition, agent, params);
|
|
35240
35362
|
};
|
|
35241
35363
|
};
|
|
35242
35364
|
var generateGitCommitMessage = makeTool(generateGitCommitMessage_default);
|
|
@@ -35943,15 +36065,15 @@ function useKeypress(userHandler) {
|
|
|
35943
36065
|
signal.current = userHandler;
|
|
35944
36066
|
useEffect((rl) => {
|
|
35945
36067
|
let ignore = false;
|
|
35946
|
-
const
|
|
36068
|
+
const handler14 = withUpdates((_input, event) => {
|
|
35947
36069
|
if (ignore)
|
|
35948
36070
|
return;
|
|
35949
36071
|
signal.current(event, rl);
|
|
35950
36072
|
});
|
|
35951
|
-
rl.input.on("keypress",
|
|
36073
|
+
rl.input.on("keypress", handler14);
|
|
35952
36074
|
return () => {
|
|
35953
36075
|
ignore = true;
|
|
35954
|
-
rl.input.removeListener("keypress",
|
|
36076
|
+
rl.input.removeListener("keypress", handler14);
|
|
35955
36077
|
};
|
|
35956
36078
|
}, []);
|
|
35957
36079
|
}
|
|
@@ -36133,16 +36255,16 @@ class Emitter {
|
|
|
36133
36255
|
|
|
36134
36256
|
class SignalExitBase {
|
|
36135
36257
|
}
|
|
36136
|
-
var signalExitWrap = (
|
|
36258
|
+
var signalExitWrap = (handler14) => {
|
|
36137
36259
|
return {
|
|
36138
36260
|
onExit(cb, opts) {
|
|
36139
|
-
return
|
|
36261
|
+
return handler14.onExit(cb, opts);
|
|
36140
36262
|
},
|
|
36141
36263
|
load() {
|
|
36142
|
-
return
|
|
36264
|
+
return handler14.load();
|
|
36143
36265
|
},
|
|
36144
36266
|
unload() {
|
|
36145
|
-
return
|
|
36267
|
+
return handler14.unload();
|
|
36146
36268
|
}
|
|
36147
36269
|
};
|
|
36148
36270
|
};
|
|
@@ -36974,20 +37096,14 @@ var getProvider = (agentName, config, options = {}) => {
|
|
|
36974
37096
|
// src/Runner.ts
|
|
36975
37097
|
class Runner {
|
|
36976
37098
|
#options;
|
|
36977
|
-
#multiAgent;
|
|
36978
37099
|
#usageMeter;
|
|
37100
|
+
multiAgent;
|
|
36979
37101
|
constructor(options) {
|
|
36980
37102
|
this.#options = options;
|
|
36981
37103
|
this.#usageMeter = new UsageMeter({
|
|
36982
37104
|
maxCost: options.budget,
|
|
36983
37105
|
maxMessageCount: options.maxMessageCount
|
|
36984
37106
|
});
|
|
36985
|
-
const service = createService(options.provider, {
|
|
36986
|
-
apiKey: options.apiKey,
|
|
36987
|
-
model: options.model,
|
|
36988
|
-
usageMeter: this.#usageMeter,
|
|
36989
|
-
enableCache: options.enableCache
|
|
36990
|
-
});
|
|
36991
37107
|
let rules2 = options.config.rules;
|
|
36992
37108
|
if (typeof rules2 === "string") {
|
|
36993
37109
|
rules2 = [rules2];
|
|
@@ -37014,40 +37130,56 @@ class Runner {
|
|
|
37014
37130
|
interactive: options.interactive
|
|
37015
37131
|
};
|
|
37016
37132
|
const platform = os.platform();
|
|
37017
|
-
const
|
|
37018
|
-
|
|
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({
|
|
37019
37157
|
createAgent: async (name) => {
|
|
37020
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
|
+
};
|
|
37021
37168
|
switch (agentName) {
|
|
37022
37169
|
case coderAgentInfo.name:
|
|
37023
37170
|
return new CoderAgent({
|
|
37024
|
-
|
|
37025
|
-
|
|
37026
|
-
customInstructions: rules2,
|
|
37027
|
-
scripts: options.config.scripts,
|
|
37028
|
-
provider: getProvider("coder", options.config, providerOptions),
|
|
37029
|
-
interactive: options.interactive,
|
|
37030
|
-
agents
|
|
37171
|
+
...args,
|
|
37172
|
+
provider: getProvider(agentName, options.config, providerOptions)
|
|
37031
37173
|
});
|
|
37032
37174
|
case architectAgentInfo.name:
|
|
37033
37175
|
return new ArchitectAgent({
|
|
37034
|
-
|
|
37035
|
-
|
|
37036
|
-
customInstructions: rules2,
|
|
37037
|
-
scripts: options.config.scripts,
|
|
37038
|
-
provider: getProvider("architect", options.config, providerOptions),
|
|
37039
|
-
interactive: options.interactive,
|
|
37040
|
-
agents
|
|
37176
|
+
...args,
|
|
37177
|
+
provider: getProvider(agentName, options.config, providerOptions)
|
|
37041
37178
|
});
|
|
37042
37179
|
case analyzerAgentInfo.name:
|
|
37043
37180
|
return new AnalyzerAgent({
|
|
37044
|
-
|
|
37045
|
-
|
|
37046
|
-
customInstructions: rules2,
|
|
37047
|
-
scripts: options.config.scripts,
|
|
37048
|
-
provider: getProvider("analyzer", options.config, providerOptions),
|
|
37049
|
-
interactive: options.interactive,
|
|
37050
|
-
agents
|
|
37181
|
+
...args,
|
|
37182
|
+
provider: getProvider(agentName, options.config, providerOptions)
|
|
37051
37183
|
});
|
|
37052
37184
|
default:
|
|
37053
37185
|
throw new Error(`Unknown agent: ${name}`);
|
|
@@ -37101,18 +37233,16 @@ ${fileList.join(`
|
|
|
37101
37233
|
</files>`;
|
|
37102
37234
|
return `<now_date>${new Date().toISOString()}</now_date>${fileContext}`;
|
|
37103
37235
|
}
|
|
37104
|
-
async startTask(task) {
|
|
37105
|
-
const
|
|
37106
|
-
const [exitReason, info] = await this.#multiAgent.startTask({
|
|
37236
|
+
async startTask(task, agentName = architectAgentInfo.name, context) {
|
|
37237
|
+
const exitReason = await this.multiAgent.startTask({
|
|
37107
37238
|
agentName,
|
|
37108
37239
|
task,
|
|
37109
|
-
context: await this.#defaultContext(agentName)
|
|
37110
|
-
callback: this.#options.eventCallback
|
|
37240
|
+
context: context ?? await this.#defaultContext(agentName)
|
|
37111
37241
|
});
|
|
37112
|
-
return
|
|
37242
|
+
return exitReason;
|
|
37113
37243
|
}
|
|
37114
|
-
async continueTask(message
|
|
37115
|
-
return await this
|
|
37244
|
+
async continueTask(message) {
|
|
37245
|
+
return await this.multiAgent.continueTask(message);
|
|
37116
37246
|
}
|
|
37117
37247
|
get usage() {
|
|
37118
37248
|
return this.#usageMeter.usage;
|
|
@@ -37180,6 +37310,48 @@ async function configPrompt(existingConfig) {
|
|
|
37180
37310
|
import os2 from "node:os";
|
|
37181
37311
|
var import_lodash2 = __toESM(require_lodash(), 1);
|
|
37182
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
|
+
|
|
37183
37355
|
// src/config.ts
|
|
37184
37356
|
var import_lodash = __toESM(require_lodash(), 1);
|
|
37185
37357
|
import { existsSync, readFileSync } from "node:fs";
|
|
@@ -41337,47 +41509,6 @@ var readConfig = (path2) => {
|
|
|
41337
41509
|
function addSharedOptions(command) {
|
|
41338
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);
|
|
41339
41511
|
}
|
|
41340
|
-
|
|
41341
|
-
class ApiProviderConfig {
|
|
41342
|
-
defaultProvider;
|
|
41343
|
-
providers;
|
|
41344
|
-
commands;
|
|
41345
|
-
agents;
|
|
41346
|
-
constructor(config) {
|
|
41347
|
-
this.defaultProvider = config.defaultProvider;
|
|
41348
|
-
this.providers = config.providers ?? {};
|
|
41349
|
-
this.commands = config.commands;
|
|
41350
|
-
this.agents = config.agents;
|
|
41351
|
-
}
|
|
41352
|
-
getConfigForCommand(command) {
|
|
41353
|
-
const { provider: provider2, model } = this.commands?.[command] ?? this.commands?.default ?? {};
|
|
41354
|
-
const finalProvider = provider2 ?? this.defaultProvider;
|
|
41355
|
-
if (!finalProvider) {
|
|
41356
|
-
return;
|
|
41357
|
-
}
|
|
41358
|
-
const finalModel = model ?? this.providers[finalProvider]?.defaultModel;
|
|
41359
|
-
const apiKey = this.providers[finalProvider]?.apiKey;
|
|
41360
|
-
return {
|
|
41361
|
-
provider: finalProvider,
|
|
41362
|
-
model: finalModel,
|
|
41363
|
-
apiKey
|
|
41364
|
-
};
|
|
41365
|
-
}
|
|
41366
|
-
getConfigForAgent(agent) {
|
|
41367
|
-
const { provider: provider2, model } = this.agents?.[agent] ?? this.agents?.default ?? {};
|
|
41368
|
-
const finalProvider = provider2 ?? this.defaultProvider;
|
|
41369
|
-
if (!finalProvider) {
|
|
41370
|
-
return;
|
|
41371
|
-
}
|
|
41372
|
-
const finalModel = model ?? this.providers[finalProvider]?.defaultModel;
|
|
41373
|
-
const apiKey = this.providers[finalProvider]?.apiKey;
|
|
41374
|
-
return {
|
|
41375
|
-
provider: finalProvider,
|
|
41376
|
-
model: finalModel,
|
|
41377
|
-
apiKey
|
|
41378
|
-
};
|
|
41379
|
-
}
|
|
41380
|
-
}
|
|
41381
41512
|
function parseOptions(options, cwd = process.cwd(), home = os2.homedir()) {
|
|
41382
41513
|
const config = loadConfig(options.config ?? options.c, cwd, home) ?? {};
|
|
41383
41514
|
const defaultProvider = options.apiProvider || process.env.POLKA_API_PROVIDER || config.defaultProvider;
|
|
@@ -41958,6 +42089,17 @@ ${event.systemPrompt}`);
|
|
|
41958
42089
|
console.log(`
|
|
41959
42090
|
|
|
41960
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 ========
|
|
41961
42103
|
`);
|
|
41962
42104
|
console.log("Agent:", event.agentName);
|
|
41963
42105
|
console.log("Task:", event.task);
|
|
@@ -41972,6 +42114,19 @@ ${event.systemPrompt}`);
|
|
|
41972
42114
|
`);
|
|
41973
42115
|
break;
|
|
41974
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
|
+
}
|
|
41975
42130
|
break;
|
|
41976
42131
|
}
|
|
41977
42132
|
};
|
|
@@ -41984,7 +42139,8 @@ var runChat = async (opts, command) => {
|
|
|
41984
42139
|
console.error("Error: Terminal is not interactive. Please run this command in an interactive terminal.");
|
|
41985
42140
|
process.exit(1);
|
|
41986
42141
|
}
|
|
41987
|
-
|
|
42142
|
+
const startAgent = architectAgentInfo.name;
|
|
42143
|
+
let { provider: provider2, model, apiKey } = providerConfig.getConfigForAgent(startAgent) ?? {};
|
|
41988
42144
|
if (!provider2) {
|
|
41989
42145
|
const newConfig = await configPrompt({ provider: provider2, model, apiKey });
|
|
41990
42146
|
provider2 = newConfig.provider;
|
|
@@ -41997,9 +42153,7 @@ var runChat = async (opts, command) => {
|
|
|
41997
42153
|
console.log('Type ".help" for more information.');
|
|
41998
42154
|
console.log("What can I do for you?");
|
|
41999
42155
|
const runner = new Runner({
|
|
42000
|
-
|
|
42001
|
-
model: model ?? defaultModels[provider2],
|
|
42002
|
-
apiKey,
|
|
42156
|
+
providerConfig,
|
|
42003
42157
|
config: config ?? {},
|
|
42004
42158
|
maxMessageCount,
|
|
42005
42159
|
budget,
|
|
@@ -42007,17 +42161,16 @@ var runChat = async (opts, command) => {
|
|
|
42007
42161
|
eventCallback: printEvent(verbose),
|
|
42008
42162
|
enableCache: true
|
|
42009
42163
|
});
|
|
42010
|
-
let
|
|
42164
|
+
let started = false;
|
|
42011
42165
|
const chat2 = new Chat3({
|
|
42012
42166
|
onMessage: async (message) => {
|
|
42013
42167
|
let exitReason;
|
|
42014
|
-
if (
|
|
42015
|
-
const
|
|
42016
|
-
taskInfo = info;
|
|
42168
|
+
if (started) {
|
|
42169
|
+
const reason = await runner.continueTask(message);
|
|
42017
42170
|
exitReason = reason;
|
|
42018
42171
|
} else {
|
|
42019
|
-
const
|
|
42020
|
-
|
|
42172
|
+
const reason = await runner.startTask(message);
|
|
42173
|
+
started = true;
|
|
42021
42174
|
exitReason = reason;
|
|
42022
42175
|
}
|
|
42023
42176
|
switch (exitReason.type) {
|
|
@@ -42663,9 +42816,11 @@ var commitCommand = new Command("commit").description("Create a commit with AI-g
|
|
|
42663
42816
|
console.error('Error: No provider specified. Please run "polka-codes config" to configure your AI provider.');
|
|
42664
42817
|
process.exit(1);
|
|
42665
42818
|
}
|
|
42819
|
+
const usage = new UsageMeter;
|
|
42666
42820
|
const ai = createService(provider2, {
|
|
42667
42821
|
apiKey,
|
|
42668
|
-
model
|
|
42822
|
+
model,
|
|
42823
|
+
usageMeter: usage
|
|
42669
42824
|
});
|
|
42670
42825
|
try {
|
|
42671
42826
|
const status = execSync("git status --porcelain").toString();
|
|
@@ -42692,6 +42847,7 @@ var commitCommand = new Command("commit").description("Create a commit with AI-g
|
|
|
42692
42847
|
const diff = execSync("git diff --cached -U200").toString();
|
|
42693
42848
|
spinner.text = "Generating commit message...";
|
|
42694
42849
|
const result = await generateGitCommitMessage(ai, { diff, context: message });
|
|
42850
|
+
usage.printUsage();
|
|
42695
42851
|
spinner.succeed("Commit message generated");
|
|
42696
42852
|
console.log(`
|
|
42697
42853
|
Commit message:
|
|
@@ -42710,7 +42866,6 @@ ${result.response}`);
|
|
|
42710
42866
|
|
|
42711
42867
|
// src/commands/init.ts
|
|
42712
42868
|
import { existsSync as existsSync2, mkdirSync, readFileSync as readFileSync2, writeFileSync } from "node:fs";
|
|
42713
|
-
import os4 from "node:os";
|
|
42714
42869
|
import { dirname as dirname2 } from "node:path";
|
|
42715
42870
|
var import_lodash3 = __toESM(require_lodash(), 1);
|
|
42716
42871
|
var initCommand = new Command("init").description("Initialize polkacodes configuration").option("-g, --global", "Use global config");
|
|
@@ -42760,7 +42915,7 @@ initCommand.action(async (options, command) => {
|
|
|
42760
42915
|
process.exit(1);
|
|
42761
42916
|
}
|
|
42762
42917
|
}
|
|
42763
|
-
const { config, providerConfig, verbose } = parseOptions(cmdOptions);
|
|
42918
|
+
const { config, providerConfig, verbose, maxMessageCount, budget } = parseOptions(cmdOptions);
|
|
42764
42919
|
let { provider: provider2, model, apiKey } = providerConfig.getConfigForCommand("init") ?? {};
|
|
42765
42920
|
let newConfig;
|
|
42766
42921
|
if (!provider2) {
|
|
@@ -42821,41 +42976,18 @@ ${newConfig.provider.toUpperCase()}_API_KEY=${newConfig.apiKey}`;
|
|
|
42821
42976
|
});
|
|
42822
42977
|
let generatedConfig = {};
|
|
42823
42978
|
if (shouldAnalyze) {
|
|
42824
|
-
const
|
|
42825
|
-
apiKey,
|
|
42826
|
-
|
|
42827
|
-
|
|
42828
|
-
|
|
42829
|
-
|
|
42830
|
-
|
|
42831
|
-
|
|
42832
|
-
|
|
42833
|
-
case analyzerAgentInfo.name:
|
|
42834
|
-
return new AnalyzerAgent({
|
|
42835
|
-
ai: service,
|
|
42836
|
-
os: os4.platform(),
|
|
42837
|
-
provider: getProvider("analyzer", config),
|
|
42838
|
-
interactive: false
|
|
42839
|
-
});
|
|
42840
|
-
default:
|
|
42841
|
-
throw new Error(`Unknown agent: ${name}`);
|
|
42842
|
-
}
|
|
42843
|
-
}
|
|
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]
|
|
42844
42988
|
});
|
|
42845
42989
|
console.log("Analyzing project files...");
|
|
42846
|
-
const
|
|
42847
|
-
const [relevantFiles] = await listFiles(".", true, 1000, process.cwd());
|
|
42848
|
-
for (const filePath of relevantFiles) {
|
|
42849
|
-
if (typeof filePath === "string" && existsSync2(filePath)) {
|
|
42850
|
-
try {
|
|
42851
|
-
const content = readFileSync2(filePath, "utf8");
|
|
42852
|
-
files[filePath] = content;
|
|
42853
|
-
} catch (error) {
|
|
42854
|
-
console.warn(`Failed to read file: ${filePath}`);
|
|
42855
|
-
}
|
|
42856
|
-
}
|
|
42857
|
-
}
|
|
42858
|
-
const { response } = await generateProjectConfig(multiAgent, relevantFiles, printEvent(verbose));
|
|
42990
|
+
const { response } = await generateProjectConfig(runner.multiAgent, undefined);
|
|
42859
42991
|
generatedConfig = response ? $parse(response) : {};
|
|
42860
42992
|
}
|
|
42861
42993
|
const finalConfig = {
|
|
@@ -42925,9 +43057,11 @@ var prCommand = new Command("pr").description("Create a GitHub pull request").ar
|
|
|
42925
43057
|
encoding: "utf-8"
|
|
42926
43058
|
});
|
|
42927
43059
|
const diff = execSync2(`git diff --cached -U200 ${defaultBranch}`, { encoding: "utf-8" });
|
|
43060
|
+
const usage = new UsageMeter;
|
|
42928
43061
|
const ai = createService(provider2, {
|
|
42929
43062
|
apiKey,
|
|
42930
|
-
model
|
|
43063
|
+
model,
|
|
43064
|
+
usageMeter: usage
|
|
42931
43065
|
});
|
|
42932
43066
|
spinner.text = "Generating pull request details...";
|
|
42933
43067
|
const prDetails = await generateGithubPullRequestDetails(ai, {
|
|
@@ -42941,6 +43075,7 @@ var prCommand = new Command("pr").description("Create a GitHub pull request").ar
|
|
|
42941
43075
|
spawnSync2("gh", ["pr", "create", "--title", prDetails.response.title.trim(), "--body", prDetails.response.description.trim()], {
|
|
42942
43076
|
stdio: "inherit"
|
|
42943
43077
|
});
|
|
43078
|
+
usage.printUsage();
|
|
42944
43079
|
} catch (error) {
|
|
42945
43080
|
console.error("Error creating pull request:", error);
|
|
42946
43081
|
process.exit(1);
|
|
@@ -42999,7 +43134,8 @@ async function runTask(taskArg, _options, command) {
|
|
|
42999
43134
|
}
|
|
43000
43135
|
}
|
|
43001
43136
|
const { config, providerConfig, verbose, maxMessageCount, budget } = parseOptions(command.opts());
|
|
43002
|
-
const
|
|
43137
|
+
const startAgent = architectAgentInfo.name;
|
|
43138
|
+
const { provider: provider2, model } = providerConfig.getConfigForAgent(startAgent) ?? {};
|
|
43003
43139
|
if (!provider2 || !model) {
|
|
43004
43140
|
console.error("Provider and model must be configured");
|
|
43005
43141
|
process.exit(1);
|
|
@@ -43007,9 +43143,7 @@ async function runTask(taskArg, _options, command) {
|
|
|
43007
43143
|
console.log("Provider:", provider2);
|
|
43008
43144
|
console.log("Model:", model);
|
|
43009
43145
|
const runner = new Runner({
|
|
43010
|
-
|
|
43011
|
-
model,
|
|
43012
|
-
apiKey,
|
|
43146
|
+
providerConfig,
|
|
43013
43147
|
config,
|
|
43014
43148
|
maxMessageCount,
|
|
43015
43149
|
budget,
|
|
@@ -43017,7 +43151,7 @@ async function runTask(taskArg, _options, command) {
|
|
|
43017
43151
|
eventCallback: printEvent(verbose),
|
|
43018
43152
|
enableCache: true
|
|
43019
43153
|
});
|
|
43020
|
-
await runner.startTask(task);
|
|
43154
|
+
await runner.startTask(task, startAgent);
|
|
43021
43155
|
runner.printUsage();
|
|
43022
43156
|
}
|
|
43023
43157
|
|