@polka-codes/cli 0.8.23 → 0.8.25
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 +207 -63
- 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.25";
|
|
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,26 @@ 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
|
+
};
|
|
48634
|
+
}
|
|
48635
|
+
await provider.writeFile(path, result.content);
|
|
48636
|
+
if (result.status === "some_diff_applied") {
|
|
48637
|
+
return {
|
|
48638
|
+
type: "Reply" /* Reply */,
|
|
48639
|
+
message: `<replace_in_file_result path="${path}" status="some_diff_applied" applied_count="${result.appliedCount}" total_count="${result.totalCount}" />`
|
|
48602
48640
|
};
|
|
48603
48641
|
}
|
|
48604
|
-
const result = await replaceInFile(fileContent, diff);
|
|
48605
|
-
await provider.writeFile(path, result);
|
|
48606
48642
|
return {
|
|
48607
48643
|
type: "Reply" /* Reply */,
|
|
48608
|
-
message: `<
|
|
48644
|
+
message: `<replace_in_file_result path="${path}" status="all_diff_applied" />`
|
|
48609
48645
|
};
|
|
48610
48646
|
};
|
|
48611
48647
|
var isAvailable8 = (provider) => {
|
|
@@ -49012,7 +49048,7 @@ var updateKnowledge_default = {
|
|
|
49012
49048
|
// ../core/src/tools/writeToFile.ts
|
|
49013
49049
|
var toolInfo11 = {
|
|
49014
49050
|
name: "write_to_file",
|
|
49015
|
-
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. Ensure that the output content does not include incorrect escaped character patterns such as `<
|
|
49051
|
+
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. Ensure that the output content does not include incorrect escaped character patterns such as `<`, `>`, or `&`. Also ensure there is no unwanted CDATA tags in the content.",
|
|
49016
49052
|
parameters: [
|
|
49017
49053
|
{
|
|
49018
49054
|
name: "path",
|
|
@@ -49063,7 +49099,10 @@ var handler11 = async (provider, args) => {
|
|
|
49063
49099
|
};
|
|
49064
49100
|
}
|
|
49065
49101
|
const path = getString(args, "path");
|
|
49066
|
-
|
|
49102
|
+
let content = getString(args, "content");
|
|
49103
|
+
const trimmedContent = content.trim();
|
|
49104
|
+
if (trimmedContent.startsWith("<![CDATA[") && content.endsWith("]]>"))
|
|
49105
|
+
content = trimmedContent.slice(9, -3);
|
|
49067
49106
|
await provider.writeFile(path, content);
|
|
49068
49107
|
return {
|
|
49069
49108
|
type: "Reply" /* Reply */,
|
|
@@ -49622,12 +49661,27 @@ Ensure the opening and closing tags are correctly nested and closed, and that yo
|
|
|
49622
49661
|
Avoid unnecessary text or symbols before or after the tool use.
|
|
49623
49662
|
Avoid unnecessary escape characters or special characters.
|
|
49624
49663
|
`,
|
|
49625
|
-
toolResults: (tool, result) =>
|
|
49626
|
-
|
|
49627
|
-
|
|
49628
|
-
|
|
49629
|
-
|
|
49630
|
-
</tool_response
|
|
49664
|
+
toolResults: (tool, result) => {
|
|
49665
|
+
if (typeof result === "string") {
|
|
49666
|
+
return [
|
|
49667
|
+
{
|
|
49668
|
+
type: "text",
|
|
49669
|
+
text: `<tool_response name=${tool}>${result}</tool_response>`
|
|
49670
|
+
}
|
|
49671
|
+
];
|
|
49672
|
+
}
|
|
49673
|
+
return [
|
|
49674
|
+
{
|
|
49675
|
+
type: "text",
|
|
49676
|
+
text: `<tool_response name=${tool}>`
|
|
49677
|
+
},
|
|
49678
|
+
...result,
|
|
49679
|
+
{
|
|
49680
|
+
type: "text",
|
|
49681
|
+
text: "</tool_response>"
|
|
49682
|
+
}
|
|
49683
|
+
];
|
|
49684
|
+
},
|
|
49631
49685
|
commandResult: (command, exitCode, stdout, stderr) => `<command>${command}</command>
|
|
49632
49686
|
<command_exit_code>${exitCode}</command_exit_code>
|
|
49633
49687
|
<command_stdout>
|
|
@@ -49645,6 +49699,7 @@ class AgentBase {
|
|
|
49645
49699
|
handlers;
|
|
49646
49700
|
#messages = [];
|
|
49647
49701
|
#policies;
|
|
49702
|
+
#aborted = false;
|
|
49648
49703
|
constructor(name, ai, config) {
|
|
49649
49704
|
this.ai = ai;
|
|
49650
49705
|
if (config.agents && config.agents.length > 0) {
|
|
@@ -49676,6 +49731,10 @@ ${instance.prompt}`;
|
|
|
49676
49731
|
this.config = config;
|
|
49677
49732
|
this.#policies = policies;
|
|
49678
49733
|
}
|
|
49734
|
+
abort() {
|
|
49735
|
+
this.#aborted = true;
|
|
49736
|
+
this.ai.abort();
|
|
49737
|
+
}
|
|
49679
49738
|
get parameters() {
|
|
49680
49739
|
return this.ai.options.parameters;
|
|
49681
49740
|
}
|
|
@@ -49704,11 +49763,17 @@ ${instance.prompt}`;
|
|
|
49704
49763
|
async#processLoop(userMessage) {
|
|
49705
49764
|
let nextRequest = userMessage;
|
|
49706
49765
|
while (true) {
|
|
49766
|
+
if (this.#aborted) {
|
|
49767
|
+
return { type: "Aborted" };
|
|
49768
|
+
}
|
|
49707
49769
|
if (this.ai.usageMeter.isLimitExceeded().result) {
|
|
49708
49770
|
this.#callback({ kind: "UsageExceeded" /* UsageExceeded */, agent: this });
|
|
49709
49771
|
return { type: "UsageExceeded" };
|
|
49710
49772
|
}
|
|
49711
49773
|
const response = await this.#request(nextRequest);
|
|
49774
|
+
if (this.#aborted) {
|
|
49775
|
+
return { type: "Aborted" };
|
|
49776
|
+
}
|
|
49712
49777
|
const resp = await this.#handleResponse(response);
|
|
49713
49778
|
if (resp.type === "exit") {
|
|
49714
49779
|
this.#callback({ kind: "EndTask" /* EndTask */, agent: this, exitReason: resp.reason });
|
|
@@ -49755,14 +49820,23 @@ ${instance.prompt}`;
|
|
|
49755
49820
|
}
|
|
49756
49821
|
}
|
|
49757
49822
|
} catch (error) {
|
|
49823
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
49824
|
+
break;
|
|
49825
|
+
}
|
|
49758
49826
|
console.error("Error in stream:", error);
|
|
49759
49827
|
}
|
|
49760
49828
|
if (currentAssistantMessage) {
|
|
49761
49829
|
break;
|
|
49762
49830
|
}
|
|
49831
|
+
if (this.#aborted) {
|
|
49832
|
+
break;
|
|
49833
|
+
}
|
|
49763
49834
|
console.debug(`Retrying request ${i2 + 1} of ${retryCount}`);
|
|
49764
49835
|
}
|
|
49765
49836
|
if (!currentAssistantMessage) {
|
|
49837
|
+
if (this.#aborted) {
|
|
49838
|
+
return [];
|
|
49839
|
+
}
|
|
49766
49840
|
throw new Error("No assistant message received");
|
|
49767
49841
|
}
|
|
49768
49842
|
this.#messages.push({
|
|
@@ -49791,23 +49865,26 @@ ${instance.prompt}`;
|
|
|
49791
49865
|
await this.#callback({ kind: "ToolUse" /* ToolUse */, agent: this, tool: content.name });
|
|
49792
49866
|
const toolResp = await this.#invokeTool(content.name, content.params);
|
|
49793
49867
|
switch (toolResp.type) {
|
|
49794
|
-
case "Reply" /* Reply */:
|
|
49868
|
+
case "Reply" /* Reply */: {
|
|
49795
49869
|
await this.#callback({ kind: "ToolReply" /* ToolReply */, agent: this, tool: content.name });
|
|
49796
49870
|
toolResponses.push({ type: "response", tool: content.name, response: toolResp.message });
|
|
49797
49871
|
break;
|
|
49872
|
+
}
|
|
49798
49873
|
case "Exit" /* Exit */:
|
|
49799
49874
|
if (toolResponses.length > 0) {
|
|
49800
49875
|
break outer;
|
|
49801
49876
|
}
|
|
49802
49877
|
return { type: "exit", reason: toolResp };
|
|
49803
|
-
case "Invalid" /* Invalid */:
|
|
49878
|
+
case "Invalid" /* Invalid */: {
|
|
49804
49879
|
await this.#callback({ kind: "ToolInvalid" /* ToolInvalid */, agent: this, tool: content.name });
|
|
49805
49880
|
toolResponses.push({ type: "response", tool: content.name, response: toolResp.message });
|
|
49806
49881
|
break outer;
|
|
49807
|
-
|
|
49882
|
+
}
|
|
49883
|
+
case "Error" /* Error */: {
|
|
49808
49884
|
await this.#callback({ kind: "ToolError" /* ToolError */, agent: this, tool: content.name });
|
|
49809
49885
|
toolResponses.push({ type: "response", tool: content.name, response: toolResp.message });
|
|
49810
49886
|
break outer;
|
|
49887
|
+
}
|
|
49811
49888
|
case "Interrupted" /* Interrupted */:
|
|
49812
49889
|
await this.#callback({ kind: "ToolInterrupted" /* ToolInterrupted */, agent: this, tool: content.name });
|
|
49813
49890
|
return { type: "exit", reason: toolResp };
|
|
@@ -49857,9 +49934,7 @@ ${instance.prompt}`;
|
|
|
49857
49934
|
if (toolResponses.length === 0) {
|
|
49858
49935
|
return { type: "reply", message: responsePrompts.requireUseTool };
|
|
49859
49936
|
}
|
|
49860
|
-
const finalResp = toolResponses.filter((resp) => resp.type === "response").
|
|
49861
|
-
|
|
49862
|
-
`);
|
|
49937
|
+
const finalResp = toolResponses.filter((resp) => resp.type === "response").flatMap(({ tool, response: response2 }) => responsePrompts.toolResults(tool, response2));
|
|
49863
49938
|
return { type: "reply", message: finalResp };
|
|
49864
49939
|
}
|
|
49865
49940
|
async#invokeTool(name, args) {
|
|
@@ -50438,6 +50513,7 @@ class MultiAgent {
|
|
|
50438
50513
|
case "Delegate" /* Delegate */:
|
|
50439
50514
|
console.warn("Unexpected exit reason", delegateResult);
|
|
50440
50515
|
break;
|
|
50516
|
+
case "Aborted":
|
|
50441
50517
|
case "Interrupted" /* Interrupted */:
|
|
50442
50518
|
return delegateResult;
|
|
50443
50519
|
case "Exit" /* Exit */:
|
|
@@ -50445,6 +50521,7 @@ class MultiAgent {
|
|
|
50445
50521
|
}
|
|
50446
50522
|
return delegateResult;
|
|
50447
50523
|
}
|
|
50524
|
+
case "Aborted":
|
|
50448
50525
|
case "Interrupted" /* Interrupted */:
|
|
50449
50526
|
case "Exit" /* Exit */:
|
|
50450
50527
|
this.#agents.pop();
|
|
@@ -50477,6 +50554,11 @@ class MultiAgent {
|
|
|
50477
50554
|
get hasActiveAgent() {
|
|
50478
50555
|
return this.#agents.length > 0;
|
|
50479
50556
|
}
|
|
50557
|
+
abort() {
|
|
50558
|
+
if (this.hasActiveAgent) {
|
|
50559
|
+
this.#agents[this.#agents.length - 1].abort();
|
|
50560
|
+
}
|
|
50561
|
+
}
|
|
50480
50562
|
}
|
|
50481
50563
|
// ../core/node_modules/zod/lib/index.mjs
|
|
50482
50564
|
var util;
|
|
@@ -54535,27 +54617,26 @@ var prompt = `
|
|
|
54535
54617
|
You are equipped with **Knowledge Management** capabilities:
|
|
54536
54618
|
|
|
54537
54619
|
1. **What to capture**
|
|
54538
|
-
|
|
54539
|
-
|
|
54540
|
-
|
|
54541
|
-
|
|
54542
|
-
|
|
54543
|
-
• Any other insight that a future contributor would find crucial.
|
|
54620
|
+
- Public API of each file (public classes, functions, methods, parameters, return types).
|
|
54621
|
+
- High-level description of each file's purpose.
|
|
54622
|
+
- Invariants and assumptions that must always hold.
|
|
54623
|
+
- Project or directory-specific coding patterns, styles, and architectural conventions.
|
|
54624
|
+
- Any other insight that a future contributor would find crucial.
|
|
54544
54625
|
|
|
54545
54626
|
2. **Where to store it**
|
|
54546
|
-
|
|
54547
|
-
|
|
54548
|
-
|
|
54627
|
+
- Save knowledge in a YAML file named \`knowledge.ai.yml\`.
|
|
54628
|
+
- **Create the file in the repository root if it does not yet exist.**
|
|
54629
|
+
- One file per directory.
|
|
54549
54630
|
- The repository root file records knowledge that applies project-wide (e.g., service responsibilities, global patterns).
|
|
54550
54631
|
- Each sub-directory keeps only the knowledge relevant to that directory or package.
|
|
54551
|
-
|
|
54632
|
+
- Use clear top-level keys such as \`description\`, \`files\`, \`rules\`.
|
|
54552
54633
|
|
|
54553
54634
|
3. **When to update**
|
|
54554
|
-
|
|
54635
|
+
- **Default behaviour:** only create / update knowledge for the files you actively read, create, or modify during the current task.
|
|
54555
54636
|
- Operate on other files **only if the user explicitly requests it**.
|
|
54556
|
-
|
|
54557
|
-
|
|
54558
|
-
|
|
54637
|
+
- **While working**: after reading, analysing, creating, or modifying code, immediately record any new or changed knowledge.
|
|
54638
|
+
- **On refactor / deletion**: locate and delete or amend obsolete entries so that knowledge never drifts from the codebase.
|
|
54639
|
+
- **Granularity**: update only the affected directory's \`knowledge.ai.yml\`, except when the change has global impact.
|
|
54559
54640
|
|
|
54560
54641
|
4. **How to format (illustrative)**
|
|
54561
54642
|
\`\`\`yaml
|
|
@@ -54565,19 +54646,14 @@ files:
|
|
|
54565
54646
|
description: "Numeric helpers for currency calculations"
|
|
54566
54647
|
api:
|
|
54567
54648
|
functions:
|
|
54568
|
-
1:
|
|
54569
|
-
name: "add"
|
|
54570
|
-
params:
|
|
54571
|
-
1: { name: "a", type: "number" }
|
|
54572
|
-
2: { name: "b", type: "number" }
|
|
54573
|
-
returns: "number"
|
|
54649
|
+
1: add(a: number, b: number): number
|
|
54574
54650
|
rules:
|
|
54575
54651
|
1: "rules that apply to all files in this directory"
|
|
54576
54652
|
\`\`\`
|
|
54577
54653
|
|
|
54578
54654
|
5. **Source of truth**
|
|
54579
|
-
|
|
54580
|
-
|
|
54655
|
+
- **Never invent knowledge.** Everything you record must be *directly derived* from existing code, comments, commit messages, or explicit user instructions.
|
|
54656
|
+
- If a section has no confirmed content, omit it rather than guessing.
|
|
54581
54657
|
|
|
54582
54658
|
6. **Automatic context**
|
|
54583
54659
|
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.
|
|
@@ -54586,11 +54662,11 @@ rules:
|
|
|
54586
54662
|
You can use the \`updateKnowledge\` tool to efficiently update knowledge files with smart merging capabilities.
|
|
54587
54663
|
|
|
54588
54664
|
8. **Dictionary-First Format**
|
|
54589
|
-
|
|
54590
|
-
|
|
54591
|
-
|
|
54592
|
-
|
|
54593
|
-
|
|
54665
|
+
- **Always prefer dictionaries** for structured data.
|
|
54666
|
+
- The **\`files\` section must be a dictionary keyed by file path** (e.g., \`"math.ts": {...}\`).
|
|
54667
|
+
- For other lists (rules, functions, etc.), use numbered dictionaries.
|
|
54668
|
+
- Arrays are allowed only when strict ordering is essential and dictionaries cannot express it.
|
|
54669
|
+
- When removing items, refer to them by their numeric key or index; gaps are fine.
|
|
54594
54670
|
|
|
54595
54671
|
Your workflow **must**:
|
|
54596
54672
|
1. Detect knowledge deltas.
|
|
@@ -55204,6 +55280,12 @@ Available commands:
|
|
|
55204
55280
|
}
|
|
55205
55281
|
});
|
|
55206
55282
|
this.#rl.on("SIGINT", () => {
|
|
55283
|
+
if (this.#busy) {
|
|
55284
|
+
console.log(`
|
|
55285
|
+
Aborting request...`);
|
|
55286
|
+
this.#options.onInterrupt?.();
|
|
55287
|
+
return;
|
|
55288
|
+
}
|
|
55207
55289
|
if (this.#isMultilineMode) {
|
|
55208
55290
|
this.#isMultilineMode = false;
|
|
55209
55291
|
this.#multilineBuffer = [];
|
|
@@ -61351,11 +61433,13 @@ var chalkStderr = createChalk({ level: stderrColor ? stderrColor.level : 0 });
|
|
|
61351
61433
|
var source_default = chalk;
|
|
61352
61434
|
|
|
61353
61435
|
// ../cli-shared/src/utils/eventHandler.ts
|
|
61436
|
+
var toolCallStats = new Map;
|
|
61354
61437
|
var printEvent = (verbose, usageMeter) => {
|
|
61355
61438
|
let hadReasoning = false;
|
|
61356
61439
|
return (event) => {
|
|
61357
61440
|
switch (event.kind) {
|
|
61358
61441
|
case "StartTask" /* StartTask */:
|
|
61442
|
+
toolCallStats.clear();
|
|
61359
61443
|
if (verbose > 1) {
|
|
61360
61444
|
console.log(`
|
|
61361
61445
|
====== System Prompt ======
|
|
@@ -61372,7 +61456,28 @@ ${event.systemPrompt}`);
|
|
|
61372
61456
|
======== New Request ========
|
|
61373
61457
|
`);
|
|
61374
61458
|
if (verbose) {
|
|
61375
|
-
|
|
61459
|
+
const { userMessage } = event;
|
|
61460
|
+
if (typeof userMessage === "string") {
|
|
61461
|
+
console.log(userMessage);
|
|
61462
|
+
} else {
|
|
61463
|
+
for (const content of userMessage) {
|
|
61464
|
+
if (content.type === "text") {
|
|
61465
|
+
console.log(content.text);
|
|
61466
|
+
} else if (content.type === "image") {
|
|
61467
|
+
if (content.source.type === "base64") {
|
|
61468
|
+
console.log(source_default.yellow(`[Image content: ${content.source.media_type}]`));
|
|
61469
|
+
} else if (content.source.type === "url") {
|
|
61470
|
+
console.log(source_default.yellow(`[Image content from URL: ${content.source.url}]`));
|
|
61471
|
+
} else {
|
|
61472
|
+
console.log(source_default.red("[Unknown image source type]"));
|
|
61473
|
+
console.log(content.source);
|
|
61474
|
+
}
|
|
61475
|
+
} else {
|
|
61476
|
+
console.log(source_default.red("[Unknown content type]"));
|
|
61477
|
+
console.log(content);
|
|
61478
|
+
}
|
|
61479
|
+
}
|
|
61480
|
+
}
|
|
61376
61481
|
console.log(`
|
|
61377
61482
|
|
|
61378
61483
|
======== Request Message Ended ========
|
|
@@ -61404,12 +61509,27 @@ ${event.systemPrompt}`);
|
|
|
61404
61509
|
hadReasoning = true;
|
|
61405
61510
|
break;
|
|
61406
61511
|
case "ToolUse" /* ToolUse */:
|
|
61512
|
+
{
|
|
61513
|
+
const stats = toolCallStats.get(event.tool) ?? { calls: 0, success: 0, errors: 0 };
|
|
61514
|
+
stats.calls++;
|
|
61515
|
+
toolCallStats.set(event.tool, stats);
|
|
61516
|
+
}
|
|
61407
61517
|
break;
|
|
61408
61518
|
case "ToolReply" /* ToolReply */:
|
|
61519
|
+
{
|
|
61520
|
+
const stats = toolCallStats.get(event.tool) ?? { calls: 0, success: 0, errors: 0 };
|
|
61521
|
+
stats.success++;
|
|
61522
|
+
toolCallStats.set(event.tool, stats);
|
|
61523
|
+
}
|
|
61409
61524
|
break;
|
|
61410
61525
|
case "ToolInvalid" /* ToolInvalid */:
|
|
61411
61526
|
break;
|
|
61412
61527
|
case "ToolError" /* ToolError */:
|
|
61528
|
+
{
|
|
61529
|
+
const stats = toolCallStats.get(event.tool) ?? { calls: 0, success: 0, errors: 0 };
|
|
61530
|
+
stats.errors++;
|
|
61531
|
+
toolCallStats.set(event.tool, stats);
|
|
61532
|
+
}
|
|
61413
61533
|
break;
|
|
61414
61534
|
case "ToolInterrupted" /* ToolInterrupted */:
|
|
61415
61535
|
break;
|
|
@@ -61455,6 +61575,24 @@ ${event.systemPrompt}`);
|
|
|
61455
61575
|
console.log("Interrupted Message:", event.exitReason.message);
|
|
61456
61576
|
break;
|
|
61457
61577
|
}
|
|
61578
|
+
console.log(`
|
|
61579
|
+
|
|
61580
|
+
======== Tool Call Stats ========`);
|
|
61581
|
+
if (toolCallStats.size > 0) {
|
|
61582
|
+
const tableData = [...toolCallStats.entries()].map(([tool2, stats]) => {
|
|
61583
|
+
const successRate = stats.calls > 0 ? stats.success / stats.calls * 100 : 0;
|
|
61584
|
+
return {
|
|
61585
|
+
"Tool Name": tool2,
|
|
61586
|
+
Calls: stats.calls,
|
|
61587
|
+
Success: stats.success,
|
|
61588
|
+
Errors: stats.errors,
|
|
61589
|
+
"Success Rate": `${successRate.toFixed(2)}%`
|
|
61590
|
+
};
|
|
61591
|
+
});
|
|
61592
|
+
console.table(tableData);
|
|
61593
|
+
} else {
|
|
61594
|
+
console.log("No tools were called.");
|
|
61595
|
+
}
|
|
61458
61596
|
break;
|
|
61459
61597
|
}
|
|
61460
61598
|
};
|
|
@@ -61659,6 +61797,9 @@ ${fileList.join(`
|
|
|
61659
61797
|
async continueTask(message) {
|
|
61660
61798
|
return await this.multiAgent.continueTask(message);
|
|
61661
61799
|
}
|
|
61800
|
+
abort() {
|
|
61801
|
+
this.multiAgent.abort();
|
|
61802
|
+
}
|
|
61662
61803
|
get hasActiveAgent() {
|
|
61663
61804
|
return this.multiAgent.hasActiveAgent;
|
|
61664
61805
|
}
|
|
@@ -61901,6 +62042,9 @@ var runChat = async (opts, command) => {
|
|
|
61901
62042
|
console.log();
|
|
61902
62043
|
runner.printUsage();
|
|
61903
62044
|
process.exit(0);
|
|
62045
|
+
},
|
|
62046
|
+
onInterrupt: () => {
|
|
62047
|
+
runner.abort();
|
|
61904
62048
|
}
|
|
61905
62049
|
});
|
|
61906
62050
|
};
|