@polka-codes/cli 0.8.24 → 0.8.26
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 +186 -49
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -38447,20 +38447,25 @@ var {
|
|
|
38447
38447
|
Help
|
|
38448
38448
|
} = import__.default;
|
|
38449
38449
|
// package.json
|
|
38450
|
-
var version = "0.8.
|
|
38450
|
+
var version = "0.8.26";
|
|
38451
38451
|
|
|
38452
38452
|
// ../core/src/AiService/AiServiceBase.ts
|
|
38453
38453
|
class AiServiceBase {
|
|
38454
38454
|
usageMeter;
|
|
38455
38455
|
options;
|
|
38456
|
+
#abortController;
|
|
38456
38457
|
constructor(options) {
|
|
38457
38458
|
this.options = options;
|
|
38458
38459
|
this.usageMeter = options.usageMeter;
|
|
38459
38460
|
}
|
|
38461
|
+
abort() {
|
|
38462
|
+
this.#abortController?.abort();
|
|
38463
|
+
}
|
|
38460
38464
|
async* send(systemPrompt, messages) {
|
|
38461
38465
|
this.usageMeter.checkLimit();
|
|
38462
38466
|
this.usageMeter.incrementMessageCount();
|
|
38463
|
-
|
|
38467
|
+
this.#abortController = new AbortController;
|
|
38468
|
+
const stream = this.sendImpl(systemPrompt, messages, this.#abortController.signal);
|
|
38464
38469
|
for await (const chunk of stream) {
|
|
38465
38470
|
switch (chunk.type) {
|
|
38466
38471
|
case "usage":
|
|
@@ -38473,7 +38478,8 @@ class AiServiceBase {
|
|
|
38473
38478
|
async request(systemPrompt, messages) {
|
|
38474
38479
|
this.usageMeter.checkLimit();
|
|
38475
38480
|
this.usageMeter.incrementMessageCount();
|
|
38476
|
-
|
|
38481
|
+
this.#abortController = new AbortController;
|
|
38482
|
+
const stream = this.sendImpl(systemPrompt, messages, this.#abortController.signal);
|
|
38477
38483
|
const usage = {
|
|
38478
38484
|
inputTokens: 0,
|
|
38479
38485
|
outputTokens: 0,
|
|
@@ -41978,7 +41984,7 @@ class AnthropicService extends AiServiceBase {
|
|
|
41978
41984
|
info: anthropicModels[id] ?? anthropicModels[anthropicDefaultModelId]
|
|
41979
41985
|
};
|
|
41980
41986
|
}
|
|
41981
|
-
async* sendImpl(systemPrompt, messages) {
|
|
41987
|
+
async* sendImpl(systemPrompt, messages, signal) {
|
|
41982
41988
|
let stream;
|
|
41983
41989
|
const modelId = this.model.id;
|
|
41984
41990
|
const cacheControl = this.#options.enableCache ? { type: "ephemeral" } : undefined;
|
|
@@ -42036,7 +42042,7 @@ class AnthropicService extends AiServiceBase {
|
|
|
42036
42042
|
return message;
|
|
42037
42043
|
}),
|
|
42038
42044
|
stream: true
|
|
42039
|
-
});
|
|
42045
|
+
}, { signal });
|
|
42040
42046
|
break;
|
|
42041
42047
|
}
|
|
42042
42048
|
default: {
|
|
@@ -42047,7 +42053,7 @@ class AnthropicService extends AiServiceBase {
|
|
|
42047
42053
|
system: [{ text: systemPrompt, type: "text" }],
|
|
42048
42054
|
messages,
|
|
42049
42055
|
stream: true
|
|
42050
|
-
});
|
|
42056
|
+
}, { signal });
|
|
42051
42057
|
break;
|
|
42052
42058
|
}
|
|
42053
42059
|
}
|
|
@@ -47405,7 +47411,7 @@ class DeepSeekService extends AiServiceBase {
|
|
|
47405
47411
|
info: deepSeekModels[id] ?? deepSeekModels[deepSeekDefaultModelId]
|
|
47406
47412
|
};
|
|
47407
47413
|
}
|
|
47408
|
-
async* sendImpl(systemPrompt, messages) {
|
|
47414
|
+
async* sendImpl(systemPrompt, messages, signal) {
|
|
47409
47415
|
const openAiMessages = [
|
|
47410
47416
|
{ role: "system", content: systemPrompt },
|
|
47411
47417
|
...convertToOpenAiMessages(messages)
|
|
@@ -47417,7 +47423,7 @@ class DeepSeekService extends AiServiceBase {
|
|
|
47417
47423
|
temperature: 0,
|
|
47418
47424
|
stream: true,
|
|
47419
47425
|
stream_options: { include_usage: true }
|
|
47420
|
-
});
|
|
47426
|
+
}, { signal });
|
|
47421
47427
|
for await (const chunk of stream) {
|
|
47422
47428
|
const delta = chunk.choices[0]?.delta;
|
|
47423
47429
|
if (delta?.reasoning_content) {
|
|
@@ -47461,7 +47467,7 @@ class OllamaService extends AiServiceBase {
|
|
|
47461
47467
|
info: openAiModelInfoSaneDefaults
|
|
47462
47468
|
};
|
|
47463
47469
|
}
|
|
47464
|
-
async* sendImpl(systemPrompt, messages) {
|
|
47470
|
+
async* sendImpl(systemPrompt, messages, signal) {
|
|
47465
47471
|
const openAiMessages = [
|
|
47466
47472
|
{ role: "system", content: systemPrompt },
|
|
47467
47473
|
...convertToOpenAiMessages(messages)
|
|
@@ -47471,7 +47477,7 @@ class OllamaService extends AiServiceBase {
|
|
|
47471
47477
|
messages: openAiMessages,
|
|
47472
47478
|
temperature: 0,
|
|
47473
47479
|
stream: true
|
|
47474
|
-
});
|
|
47480
|
+
}, { signal });
|
|
47475
47481
|
for await (const chunk of stream) {
|
|
47476
47482
|
const delta = chunk.choices[0]?.delta;
|
|
47477
47483
|
if (delta?.content) {
|
|
@@ -47518,7 +47524,7 @@ class OpenRouterService extends AiServiceBase {
|
|
|
47518
47524
|
this.#modelProviderInfo = data.data;
|
|
47519
47525
|
});
|
|
47520
47526
|
}
|
|
47521
|
-
async* sendImpl(systemPrompt, messages) {
|
|
47527
|
+
async* sendImpl(systemPrompt, messages, signal) {
|
|
47522
47528
|
const openAiMessages = [
|
|
47523
47529
|
{ role: "system", content: systemPrompt },
|
|
47524
47530
|
...convertToOpenAiMessages(messages)
|
|
@@ -47578,7 +47584,7 @@ class OpenRouterService extends AiServiceBase {
|
|
|
47578
47584
|
transforms: shouldApplyMiddleOutTransform ? ["middle-out"] : undefined,
|
|
47579
47585
|
include_reasoning: true,
|
|
47580
47586
|
...reasoning
|
|
47581
|
-
});
|
|
47587
|
+
}, { signal });
|
|
47582
47588
|
let genId;
|
|
47583
47589
|
for await (const chunk of stream) {
|
|
47584
47590
|
if ("error" in chunk) {
|
|
@@ -47851,7 +47857,7 @@ var getArray = (args, name, defaultValue) => {
|
|
|
47851
47857
|
return [ret];
|
|
47852
47858
|
};
|
|
47853
47859
|
// ../core/src/tools/utils/replaceInFile.ts
|
|
47854
|
-
var replaceInFile =
|
|
47860
|
+
var replaceInFile = (fileContent, diff) => {
|
|
47855
47861
|
const blockPattern = /<<<<<+ SEARCH>?\s*\r?\n([\s\S]*?)\r?\n=======[ \t]*\r?\n([\s\S]*?)\r?\n?>>>>>+ REPLACE/g;
|
|
47856
47862
|
const blocks = [];
|
|
47857
47863
|
for (let match = blockPattern.exec(diff);match !== null; match = blockPattern.exec(diff)) {
|
|
@@ -47896,14 +47902,32 @@ var replaceInFile = async (fileContent, diff) => {
|
|
|
47896
47902
|
const startPos = endPos - strippedSearch.length;
|
|
47897
47903
|
return content.slice(0, startPos) + replace + content.slice(endPos);
|
|
47898
47904
|
}
|
|
47899
|
-
|
|
47900
|
-
${search}`);
|
|
47905
|
+
return null;
|
|
47901
47906
|
};
|
|
47902
47907
|
let updatedFile = fileContent;
|
|
47908
|
+
let appliedCount = 0;
|
|
47909
|
+
const totalCount = blocks.length;
|
|
47903
47910
|
for (const { search, replace } of blocks) {
|
|
47904
|
-
|
|
47911
|
+
const result = findAndReplace(updatedFile, search, replace);
|
|
47912
|
+
if (result !== null) {
|
|
47913
|
+
updatedFile = result;
|
|
47914
|
+
appliedCount++;
|
|
47915
|
+
}
|
|
47916
|
+
}
|
|
47917
|
+
let status;
|
|
47918
|
+
if (appliedCount === 0) {
|
|
47919
|
+
status = "no_diff_applied";
|
|
47920
|
+
} else if (appliedCount < totalCount) {
|
|
47921
|
+
status = "some_diff_applied";
|
|
47922
|
+
} else {
|
|
47923
|
+
status = "all_diff_applied";
|
|
47905
47924
|
}
|
|
47906
|
-
return
|
|
47925
|
+
return {
|
|
47926
|
+
content: updatedFile,
|
|
47927
|
+
status,
|
|
47928
|
+
appliedCount,
|
|
47929
|
+
totalCount
|
|
47930
|
+
};
|
|
47907
47931
|
};
|
|
47908
47932
|
// ../core/src/tools/askFollowupQuestion.ts
|
|
47909
47933
|
var toolInfo = {
|
|
@@ -48598,14 +48622,30 @@ var handler8 = async (provider, args) => {
|
|
|
48598
48622
|
if (fileContent == null) {
|
|
48599
48623
|
return {
|
|
48600
48624
|
type: "Error" /* Error */,
|
|
48601
|
-
message: `<
|
|
48625
|
+
message: `<replace_in_file_result path="${path}" status="failed" message="File not found" />`
|
|
48626
|
+
};
|
|
48627
|
+
}
|
|
48628
|
+
const result = replaceInFile(fileContent, diff);
|
|
48629
|
+
if (result.status === "no_diff_applied") {
|
|
48630
|
+
return {
|
|
48631
|
+
type: "Error" /* Error */,
|
|
48632
|
+
message: `<replace_in_file_result path="${path}" status="failed" message="Unable to apply changes">
|
|
48633
|
+
<file_content path="${path}">${fileContent}</file_content>
|
|
48634
|
+
</replace_in_file_result>`
|
|
48635
|
+
};
|
|
48636
|
+
}
|
|
48637
|
+
await provider.writeFile(path, result.content);
|
|
48638
|
+
if (result.status === "some_diff_applied") {
|
|
48639
|
+
return {
|
|
48640
|
+
type: "Reply" /* Reply */,
|
|
48641
|
+
message: `<replace_in_file_result path="${path}" status="some_diff_applied" applied_count="${result.appliedCount}" total_count="${result.totalCount}">
|
|
48642
|
+
<file_content path="${path}">${result.content}</file_content>
|
|
48643
|
+
</replace_in_file_result>`
|
|
48602
48644
|
};
|
|
48603
48645
|
}
|
|
48604
|
-
const result = await replaceInFile(fileContent, diff);
|
|
48605
|
-
await provider.writeFile(path, result);
|
|
48606
48646
|
return {
|
|
48607
48647
|
type: "Reply" /* Reply */,
|
|
48608
|
-
message: `<
|
|
48648
|
+
message: `<replace_in_file_result path="${path}" status="all_diff_applied" />`
|
|
48609
48649
|
};
|
|
48610
48650
|
};
|
|
48611
48651
|
var isAvailable8 = (provider) => {
|
|
@@ -49663,6 +49703,7 @@ class AgentBase {
|
|
|
49663
49703
|
handlers;
|
|
49664
49704
|
#messages = [];
|
|
49665
49705
|
#policies;
|
|
49706
|
+
#aborted = false;
|
|
49666
49707
|
constructor(name, ai, config) {
|
|
49667
49708
|
this.ai = ai;
|
|
49668
49709
|
if (config.agents && config.agents.length > 0) {
|
|
@@ -49694,6 +49735,10 @@ ${instance.prompt}`;
|
|
|
49694
49735
|
this.config = config;
|
|
49695
49736
|
this.#policies = policies;
|
|
49696
49737
|
}
|
|
49738
|
+
abort() {
|
|
49739
|
+
this.#aborted = true;
|
|
49740
|
+
this.ai.abort();
|
|
49741
|
+
}
|
|
49697
49742
|
get parameters() {
|
|
49698
49743
|
return this.ai.options.parameters;
|
|
49699
49744
|
}
|
|
@@ -49722,11 +49767,17 @@ ${instance.prompt}`;
|
|
|
49722
49767
|
async#processLoop(userMessage) {
|
|
49723
49768
|
let nextRequest = userMessage;
|
|
49724
49769
|
while (true) {
|
|
49770
|
+
if (this.#aborted) {
|
|
49771
|
+
return { type: "Aborted" };
|
|
49772
|
+
}
|
|
49725
49773
|
if (this.ai.usageMeter.isLimitExceeded().result) {
|
|
49726
49774
|
this.#callback({ kind: "UsageExceeded" /* UsageExceeded */, agent: this });
|
|
49727
49775
|
return { type: "UsageExceeded" };
|
|
49728
49776
|
}
|
|
49729
49777
|
const response = await this.#request(nextRequest);
|
|
49778
|
+
if (this.#aborted) {
|
|
49779
|
+
return { type: "Aborted" };
|
|
49780
|
+
}
|
|
49730
49781
|
const resp = await this.#handleResponse(response);
|
|
49731
49782
|
if (resp.type === "exit") {
|
|
49732
49783
|
this.#callback({ kind: "EndTask" /* EndTask */, agent: this, exitReason: resp.reason });
|
|
@@ -49773,14 +49824,23 @@ ${instance.prompt}`;
|
|
|
49773
49824
|
}
|
|
49774
49825
|
}
|
|
49775
49826
|
} catch (error) {
|
|
49827
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
49828
|
+
break;
|
|
49829
|
+
}
|
|
49776
49830
|
console.error("Error in stream:", error);
|
|
49777
49831
|
}
|
|
49778
49832
|
if (currentAssistantMessage) {
|
|
49779
49833
|
break;
|
|
49780
49834
|
}
|
|
49835
|
+
if (this.#aborted) {
|
|
49836
|
+
break;
|
|
49837
|
+
}
|
|
49781
49838
|
console.debug(`Retrying request ${i2 + 1} of ${retryCount}`);
|
|
49782
49839
|
}
|
|
49783
49840
|
if (!currentAssistantMessage) {
|
|
49841
|
+
if (this.#aborted) {
|
|
49842
|
+
return [];
|
|
49843
|
+
}
|
|
49784
49844
|
throw new Error("No assistant message received");
|
|
49785
49845
|
}
|
|
49786
49846
|
this.#messages.push({
|
|
@@ -50457,6 +50517,7 @@ class MultiAgent {
|
|
|
50457
50517
|
case "Delegate" /* Delegate */:
|
|
50458
50518
|
console.warn("Unexpected exit reason", delegateResult);
|
|
50459
50519
|
break;
|
|
50520
|
+
case "Aborted":
|
|
50460
50521
|
case "Interrupted" /* Interrupted */:
|
|
50461
50522
|
return delegateResult;
|
|
50462
50523
|
case "Exit" /* Exit */:
|
|
@@ -50464,6 +50525,7 @@ class MultiAgent {
|
|
|
50464
50525
|
}
|
|
50465
50526
|
return delegateResult;
|
|
50466
50527
|
}
|
|
50528
|
+
case "Aborted":
|
|
50467
50529
|
case "Interrupted" /* Interrupted */:
|
|
50468
50530
|
case "Exit" /* Exit */:
|
|
50469
50531
|
this.#agents.pop();
|
|
@@ -50496,6 +50558,11 @@ class MultiAgent {
|
|
|
50496
50558
|
get hasActiveAgent() {
|
|
50497
50559
|
return this.#agents.length > 0;
|
|
50498
50560
|
}
|
|
50561
|
+
abort() {
|
|
50562
|
+
if (this.hasActiveAgent) {
|
|
50563
|
+
this.#agents[this.#agents.length - 1].abort();
|
|
50564
|
+
}
|
|
50565
|
+
}
|
|
50499
50566
|
}
|
|
50500
50567
|
// ../core/node_modules/zod/lib/index.mjs
|
|
50501
50568
|
var util;
|
|
@@ -54554,27 +54621,26 @@ var prompt = `
|
|
|
54554
54621
|
You are equipped with **Knowledge Management** capabilities:
|
|
54555
54622
|
|
|
54556
54623
|
1. **What to capture**
|
|
54557
|
-
|
|
54558
|
-
|
|
54559
|
-
|
|
54560
|
-
|
|
54561
|
-
|
|
54562
|
-
• Any other insight that a future contributor would find crucial.
|
|
54624
|
+
- Public API of each file (public classes, functions, methods, parameters, return types).
|
|
54625
|
+
- High-level description of each file's purpose.
|
|
54626
|
+
- Invariants and assumptions that must always hold.
|
|
54627
|
+
- Project or directory-specific coding patterns, styles, and architectural conventions.
|
|
54628
|
+
- Any other insight that a future contributor would find crucial.
|
|
54563
54629
|
|
|
54564
54630
|
2. **Where to store it**
|
|
54565
|
-
|
|
54566
|
-
|
|
54567
|
-
|
|
54631
|
+
- Save knowledge in a YAML file named \`knowledge.ai.yml\`.
|
|
54632
|
+
- **Create the file in the repository root if it does not yet exist.**
|
|
54633
|
+
- One file per directory.
|
|
54568
54634
|
- The repository root file records knowledge that applies project-wide (e.g., service responsibilities, global patterns).
|
|
54569
54635
|
- Each sub-directory keeps only the knowledge relevant to that directory or package.
|
|
54570
|
-
|
|
54636
|
+
- Use clear top-level keys such as \`description\`, \`files\`, \`rules\`.
|
|
54571
54637
|
|
|
54572
54638
|
3. **When to update**
|
|
54573
|
-
|
|
54639
|
+
- **Default behaviour:** only create / update knowledge for the files you actively read, create, or modify during the current task.
|
|
54574
54640
|
- Operate on other files **only if the user explicitly requests it**.
|
|
54575
|
-
|
|
54576
|
-
|
|
54577
|
-
|
|
54641
|
+
- **While working**: after reading, analysing, creating, or modifying code, immediately record any new or changed knowledge.
|
|
54642
|
+
- **On refactor / deletion**: locate and delete or amend obsolete entries so that knowledge never drifts from the codebase.
|
|
54643
|
+
- **Granularity**: update only the affected directory's \`knowledge.ai.yml\`, except when the change has global impact.
|
|
54578
54644
|
|
|
54579
54645
|
4. **How to format (illustrative)**
|
|
54580
54646
|
\`\`\`yaml
|
|
@@ -54584,19 +54650,14 @@ files:
|
|
|
54584
54650
|
description: "Numeric helpers for currency calculations"
|
|
54585
54651
|
api:
|
|
54586
54652
|
functions:
|
|
54587
|
-
1:
|
|
54588
|
-
name: "add"
|
|
54589
|
-
params:
|
|
54590
|
-
1: { name: "a", type: "number" }
|
|
54591
|
-
2: { name: "b", type: "number" }
|
|
54592
|
-
returns: "number"
|
|
54653
|
+
1: add(a: number, b: number): number
|
|
54593
54654
|
rules:
|
|
54594
54655
|
1: "rules that apply to all files in this directory"
|
|
54595
54656
|
\`\`\`
|
|
54596
54657
|
|
|
54597
54658
|
5. **Source of truth**
|
|
54598
|
-
|
|
54599
|
-
|
|
54659
|
+
- **Never invent knowledge.** Everything you record must be *directly derived* from existing code, comments, commit messages, or explicit user instructions.
|
|
54660
|
+
- If a section has no confirmed content, omit it rather than guessing.
|
|
54600
54661
|
|
|
54601
54662
|
6. **Automatic context**
|
|
54602
54663
|
When you are asked to read or modify a file, the orchestration layer will supply any existing knowledge for that path automatically. Use it, refine it, and keep it accurate.
|
|
@@ -54605,11 +54666,11 @@ rules:
|
|
|
54605
54666
|
You can use the \`updateKnowledge\` tool to efficiently update knowledge files with smart merging capabilities.
|
|
54606
54667
|
|
|
54607
54668
|
8. **Dictionary-First Format**
|
|
54608
|
-
|
|
54609
|
-
|
|
54610
|
-
|
|
54611
|
-
|
|
54612
|
-
|
|
54669
|
+
- **Always prefer dictionaries** for structured data.
|
|
54670
|
+
- The **\`files\` section must be a dictionary keyed by file path** (e.g., \`"math.ts": {...}\`).
|
|
54671
|
+
- For other lists (rules, functions, etc.), use numbered dictionaries.
|
|
54672
|
+
- Arrays are allowed only when strict ordering is essential and dictionaries cannot express it.
|
|
54673
|
+
- When removing items, refer to them by their numeric key or index; gaps are fine.
|
|
54613
54674
|
|
|
54614
54675
|
Your workflow **must**:
|
|
54615
54676
|
1. Detect knowledge deltas.
|
|
@@ -55223,6 +55284,12 @@ Available commands:
|
|
|
55223
55284
|
}
|
|
55224
55285
|
});
|
|
55225
55286
|
this.#rl.on("SIGINT", () => {
|
|
55287
|
+
if (this.#busy) {
|
|
55288
|
+
console.log(`
|
|
55289
|
+
Aborting request...`);
|
|
55290
|
+
this.#options.onInterrupt?.();
|
|
55291
|
+
return;
|
|
55292
|
+
}
|
|
55226
55293
|
if (this.#isMultilineMode) {
|
|
55227
55294
|
this.#isMultilineMode = false;
|
|
55228
55295
|
this.#multilineBuffer = [];
|
|
@@ -61370,11 +61437,13 @@ var chalkStderr = createChalk({ level: stderrColor ? stderrColor.level : 0 });
|
|
|
61370
61437
|
var source_default = chalk;
|
|
61371
61438
|
|
|
61372
61439
|
// ../cli-shared/src/utils/eventHandler.ts
|
|
61440
|
+
var toolCallStats = new Map;
|
|
61373
61441
|
var printEvent = (verbose, usageMeter) => {
|
|
61374
61442
|
let hadReasoning = false;
|
|
61375
61443
|
return (event) => {
|
|
61376
61444
|
switch (event.kind) {
|
|
61377
61445
|
case "StartTask" /* StartTask */:
|
|
61446
|
+
toolCallStats.clear();
|
|
61378
61447
|
if (verbose > 1) {
|
|
61379
61448
|
console.log(`
|
|
61380
61449
|
====== System Prompt ======
|
|
@@ -61391,7 +61460,28 @@ ${event.systemPrompt}`);
|
|
|
61391
61460
|
======== New Request ========
|
|
61392
61461
|
`);
|
|
61393
61462
|
if (verbose) {
|
|
61394
|
-
|
|
61463
|
+
const { userMessage } = event;
|
|
61464
|
+
if (typeof userMessage === "string") {
|
|
61465
|
+
console.log(userMessage);
|
|
61466
|
+
} else {
|
|
61467
|
+
for (const content of userMessage) {
|
|
61468
|
+
if (content.type === "text") {
|
|
61469
|
+
console.log(content.text);
|
|
61470
|
+
} else if (content.type === "image") {
|
|
61471
|
+
if (content.source.type === "base64") {
|
|
61472
|
+
console.log(source_default.yellow(`[Image content: ${content.source.media_type}]`));
|
|
61473
|
+
} else if (content.source.type === "url") {
|
|
61474
|
+
console.log(source_default.yellow(`[Image content from URL: ${content.source.url}]`));
|
|
61475
|
+
} else {
|
|
61476
|
+
console.log(source_default.red("[Unknown image source type]"));
|
|
61477
|
+
console.log(content.source);
|
|
61478
|
+
}
|
|
61479
|
+
} else {
|
|
61480
|
+
console.log(source_default.red("[Unknown content type]"));
|
|
61481
|
+
console.log(content);
|
|
61482
|
+
}
|
|
61483
|
+
}
|
|
61484
|
+
}
|
|
61395
61485
|
console.log(`
|
|
61396
61486
|
|
|
61397
61487
|
======== Request Message Ended ========
|
|
@@ -61423,12 +61513,27 @@ ${event.systemPrompt}`);
|
|
|
61423
61513
|
hadReasoning = true;
|
|
61424
61514
|
break;
|
|
61425
61515
|
case "ToolUse" /* ToolUse */:
|
|
61516
|
+
{
|
|
61517
|
+
const stats = toolCallStats.get(event.tool) ?? { calls: 0, success: 0, errors: 0 };
|
|
61518
|
+
stats.calls++;
|
|
61519
|
+
toolCallStats.set(event.tool, stats);
|
|
61520
|
+
}
|
|
61426
61521
|
break;
|
|
61427
61522
|
case "ToolReply" /* ToolReply */:
|
|
61523
|
+
{
|
|
61524
|
+
const stats = toolCallStats.get(event.tool) ?? { calls: 0, success: 0, errors: 0 };
|
|
61525
|
+
stats.success++;
|
|
61526
|
+
toolCallStats.set(event.tool, stats);
|
|
61527
|
+
}
|
|
61428
61528
|
break;
|
|
61429
61529
|
case "ToolInvalid" /* ToolInvalid */:
|
|
61430
61530
|
break;
|
|
61431
61531
|
case "ToolError" /* ToolError */:
|
|
61532
|
+
{
|
|
61533
|
+
const stats = toolCallStats.get(event.tool) ?? { calls: 0, success: 0, errors: 0 };
|
|
61534
|
+
stats.errors++;
|
|
61535
|
+
toolCallStats.set(event.tool, stats);
|
|
61536
|
+
}
|
|
61432
61537
|
break;
|
|
61433
61538
|
case "ToolInterrupted" /* ToolInterrupted */:
|
|
61434
61539
|
break;
|
|
@@ -61474,6 +61579,24 @@ ${event.systemPrompt}`);
|
|
|
61474
61579
|
console.log("Interrupted Message:", event.exitReason.message);
|
|
61475
61580
|
break;
|
|
61476
61581
|
}
|
|
61582
|
+
console.log(`
|
|
61583
|
+
|
|
61584
|
+
======== Tool Call Stats ========`);
|
|
61585
|
+
if (toolCallStats.size > 0) {
|
|
61586
|
+
const tableData = [...toolCallStats.entries()].map(([tool2, stats]) => {
|
|
61587
|
+
const successRate = stats.calls > 0 ? stats.success / stats.calls * 100 : 0;
|
|
61588
|
+
return {
|
|
61589
|
+
"Tool Name": tool2,
|
|
61590
|
+
Calls: stats.calls,
|
|
61591
|
+
Success: stats.success,
|
|
61592
|
+
Errors: stats.errors,
|
|
61593
|
+
"Success Rate": `${successRate.toFixed(2)}%`
|
|
61594
|
+
};
|
|
61595
|
+
});
|
|
61596
|
+
console.table(tableData);
|
|
61597
|
+
} else {
|
|
61598
|
+
console.log("No tools were called.");
|
|
61599
|
+
}
|
|
61477
61600
|
break;
|
|
61478
61601
|
}
|
|
61479
61602
|
};
|
|
@@ -61678,6 +61801,9 @@ ${fileList.join(`
|
|
|
61678
61801
|
async continueTask(message) {
|
|
61679
61802
|
return await this.multiAgent.continueTask(message);
|
|
61680
61803
|
}
|
|
61804
|
+
abort() {
|
|
61805
|
+
this.multiAgent.abort();
|
|
61806
|
+
}
|
|
61681
61807
|
get hasActiveAgent() {
|
|
61682
61808
|
return this.multiAgent.hasActiveAgent;
|
|
61683
61809
|
}
|
|
@@ -61920,6 +62046,9 @@ var runChat = async (opts, command) => {
|
|
|
61920
62046
|
console.log();
|
|
61921
62047
|
runner.printUsage();
|
|
61922
62048
|
process.exit(0);
|
|
62049
|
+
},
|
|
62050
|
+
onInterrupt: () => {
|
|
62051
|
+
runner.abort();
|
|
61923
62052
|
}
|
|
61924
62053
|
});
|
|
61925
62054
|
};
|
|
@@ -66839,7 +66968,15 @@ async function runTask(taskArg, _options, command) {
|
|
|
66839
66968
|
verbose,
|
|
66840
66969
|
enableCache: true
|
|
66841
66970
|
});
|
|
66971
|
+
const sigintHandler = () => {
|
|
66972
|
+
runner.abort();
|
|
66973
|
+
console.log();
|
|
66974
|
+
runner.printUsage();
|
|
66975
|
+
process.exit(0);
|
|
66976
|
+
};
|
|
66977
|
+
process.on("SIGINT", sigintHandler);
|
|
66842
66978
|
await runner.startTask(task, agent);
|
|
66979
|
+
process.off("SIGINT", sigintHandler);
|
|
66843
66980
|
runner.printUsage();
|
|
66844
66981
|
}
|
|
66845
66982
|
|