@polka-codes/cli 0.9.4 → 0.9.5
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 +80 -43
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -39731,7 +39731,7 @@ var {
|
|
|
39731
39731
|
Help
|
|
39732
39732
|
} = import__.default;
|
|
39733
39733
|
// package.json
|
|
39734
|
-
var version = "0.9.
|
|
39734
|
+
var version = "0.9.5";
|
|
39735
39735
|
|
|
39736
39736
|
// ../../node_modules/@inquirer/core/dist/esm/lib/key.js
|
|
39737
39737
|
var isUpKey = (key) => key.name === "up" || key.name === "k" || key.ctrl && key.name === "p";
|
|
@@ -52567,7 +52567,17 @@ var toolInfo7 = {
|
|
|
52567
52567
|
return true;
|
|
52568
52568
|
}
|
|
52569
52569
|
return val;
|
|
52570
|
-
}, exports_external.boolean().optional().default(true)).describe("Whether to list files recursively. Use true for recursive listing, false or omit for top-level only.").meta({ usageValue: "true or false (optional)" })
|
|
52570
|
+
}, exports_external.boolean().optional().default(true)).describe("Whether to list files recursively. Use true for recursive listing, false or omit for top-level only.").meta({ usageValue: "true or false (optional)" }),
|
|
52571
|
+
includeIgnored: exports_external.preprocess((val) => {
|
|
52572
|
+
if (typeof val === "string") {
|
|
52573
|
+
const lower = val.toLowerCase();
|
|
52574
|
+
if (lower === "false")
|
|
52575
|
+
return false;
|
|
52576
|
+
if (lower === "true")
|
|
52577
|
+
return true;
|
|
52578
|
+
}
|
|
52579
|
+
return val;
|
|
52580
|
+
}, exports_external.boolean().optional().default(false)).describe("Whether to include ignored files. Use true to include files ignored by .gitignore.").meta({ usageValue: "true or false (optional)" })
|
|
52571
52581
|
}).meta({
|
|
52572
52582
|
examples: [
|
|
52573
52583
|
{
|
|
@@ -52588,8 +52598,8 @@ var handler7 = async (provider, args) => {
|
|
|
52588
52598
|
message: "Not possible to list files. Abort."
|
|
52589
52599
|
};
|
|
52590
52600
|
}
|
|
52591
|
-
const { path, maxCount, recursive } = toolInfo7.parameters.parse(args);
|
|
52592
|
-
const [files, limitReached] = await provider.listFiles(path, recursive, maxCount);
|
|
52601
|
+
const { path, maxCount, recursive, includeIgnored } = toolInfo7.parameters.parse(args);
|
|
52602
|
+
const [files, limitReached] = await provider.listFiles(path, recursive, maxCount, includeIgnored);
|
|
52593
52603
|
return {
|
|
52594
52604
|
type: "Reply" /* Reply */,
|
|
52595
52605
|
message: `<list_files_path>${path}</list_files_path>
|
|
@@ -52618,7 +52628,17 @@ var toolInfo8 = {
|
|
|
52618
52628
|
return [];
|
|
52619
52629
|
const values = Array.isArray(val) ? val : [val];
|
|
52620
52630
|
return values.flatMap((i) => typeof i === "string" ? i.split(",") : []).filter((s) => s.length > 0);
|
|
52621
|
-
}, exports_external.array(exports_external.string())).describe("The path of the file to read").meta({ usageValue: "Comma separated paths here" })
|
|
52631
|
+
}, exports_external.array(exports_external.string())).describe("The path of the file to read").meta({ usageValue: "Comma separated paths here" }),
|
|
52632
|
+
includeIgnored: exports_external.preprocess((val) => {
|
|
52633
|
+
if (typeof val === "string") {
|
|
52634
|
+
const lower = val.toLowerCase();
|
|
52635
|
+
if (lower === "false")
|
|
52636
|
+
return false;
|
|
52637
|
+
if (lower === "true")
|
|
52638
|
+
return true;
|
|
52639
|
+
}
|
|
52640
|
+
return val;
|
|
52641
|
+
}, exports_external.boolean().optional().default(false)).describe("Whether to include ignored files. Use true to include files ignored by .gitignore.").meta({ usageValue: "true or false (optional)" })
|
|
52622
52642
|
}).meta({
|
|
52623
52643
|
examples: [
|
|
52624
52644
|
{
|
|
@@ -52644,10 +52664,10 @@ var handler8 = async (provider, args) => {
|
|
|
52644
52664
|
message: "Not possible to read file. Abort."
|
|
52645
52665
|
};
|
|
52646
52666
|
}
|
|
52647
|
-
const { path: paths } = toolInfo8.parameters.parse(args);
|
|
52667
|
+
const { path: paths, includeIgnored } = toolInfo8.parameters.parse(args);
|
|
52648
52668
|
const resp = [];
|
|
52649
52669
|
for (const path of paths) {
|
|
52650
|
-
const fileContent = await provider.readFile(path);
|
|
52670
|
+
const fileContent = await provider.readFile(path, includeIgnored);
|
|
52651
52671
|
if (!fileContent) {
|
|
52652
52672
|
resp.push(`<read_file_file_content path="${path}" file_not_found="true" />`);
|
|
52653
52673
|
} else {
|
|
@@ -52957,7 +52977,7 @@ var handler11 = async (provider, args) => {
|
|
|
52957
52977
|
}
|
|
52958
52978
|
try {
|
|
52959
52979
|
const { path, diff } = toolInfo11.parameters.parse(args);
|
|
52960
|
-
const fileContent = await provider.readFile(path);
|
|
52980
|
+
const fileContent = await provider.readFile(path, false);
|
|
52961
52981
|
if (fileContent == null) {
|
|
52962
52982
|
return {
|
|
52963
52983
|
type: "Error" /* Error */,
|
|
@@ -76695,6 +76715,7 @@ ${instance.prompt}`;
|
|
|
76695
76715
|
resetTimeout();
|
|
76696
76716
|
const streamTextOptions = {
|
|
76697
76717
|
model: this.ai,
|
|
76718
|
+
temperature: 0,
|
|
76698
76719
|
messages,
|
|
76699
76720
|
providerOptions: this.config.parameters?.providerOptions,
|
|
76700
76721
|
onChunk: async ({ chunk }) => {
|
|
@@ -76763,6 +76784,14 @@ ${instance.prompt}`;
|
|
|
76763
76784
|
}
|
|
76764
76785
|
this.#messages.push(...respMessages);
|
|
76765
76786
|
if (this.config.toolFormat === "native") {
|
|
76787
|
+
const assistantText = respMessages.map((msg) => {
|
|
76788
|
+
if (typeof msg.content === "string") {
|
|
76789
|
+
return msg.content;
|
|
76790
|
+
}
|
|
76791
|
+
return msg.content.map((part) => part.type === "text" || part.type === "reasoning" ? part.text : "").join("");
|
|
76792
|
+
}).join(`
|
|
76793
|
+
`);
|
|
76794
|
+
await this.#callback({ kind: "EndRequest" /* EndRequest */, agent: this, message: assistantText });
|
|
76766
76795
|
return respMessages.flatMap((msg) => {
|
|
76767
76796
|
if (msg.role === "assistant") {
|
|
76768
76797
|
const content = msg.content;
|
|
@@ -78285,6 +78314,7 @@ ${output}`,
|
|
|
78285
78314
|
var executeTool = async (definition, ai, params, usageMeter) => {
|
|
78286
78315
|
const resp = await generateText({
|
|
78287
78316
|
model: ai,
|
|
78317
|
+
temperature: 0,
|
|
78288
78318
|
system: definition.prompt,
|
|
78289
78319
|
messages: [
|
|
78290
78320
|
{
|
|
@@ -86328,21 +86358,6 @@ var OpenRouterChatLanguageModel = class {
|
|
|
86328
86358
|
return;
|
|
86329
86359
|
}
|
|
86330
86360
|
const delta = choice.delta;
|
|
86331
|
-
if (delta.content != null) {
|
|
86332
|
-
if (!textStarted) {
|
|
86333
|
-
textId = openrouterResponseId || generateId2();
|
|
86334
|
-
controller.enqueue({
|
|
86335
|
-
type: "text-start",
|
|
86336
|
-
id: textId
|
|
86337
|
-
});
|
|
86338
|
-
textStarted = true;
|
|
86339
|
-
}
|
|
86340
|
-
controller.enqueue({
|
|
86341
|
-
type: "text-delta",
|
|
86342
|
-
delta: delta.content,
|
|
86343
|
-
id: textId || generateId2()
|
|
86344
|
-
});
|
|
86345
|
-
}
|
|
86346
86361
|
const emitReasoningChunk = (chunkText) => {
|
|
86347
86362
|
if (!reasoningStarted) {
|
|
86348
86363
|
reasoningId = openrouterResponseId || generateId2();
|
|
@@ -86358,9 +86373,6 @@ var OpenRouterChatLanguageModel = class {
|
|
|
86358
86373
|
id: reasoningId || generateId2()
|
|
86359
86374
|
});
|
|
86360
86375
|
};
|
|
86361
|
-
if (delta.reasoning != null) {
|
|
86362
|
-
emitReasoningChunk(delta.reasoning);
|
|
86363
|
-
}
|
|
86364
86376
|
if (delta.reasoning_details && delta.reasoning_details.length > 0) {
|
|
86365
86377
|
for (const detail of delta.reasoning_details) {
|
|
86366
86378
|
switch (detail.type) {
|
|
@@ -86387,6 +86399,23 @@ var OpenRouterChatLanguageModel = class {
|
|
|
86387
86399
|
}
|
|
86388
86400
|
}
|
|
86389
86401
|
}
|
|
86402
|
+
} else if (delta.reasoning != null) {
|
|
86403
|
+
emitReasoningChunk(delta.reasoning);
|
|
86404
|
+
}
|
|
86405
|
+
if (delta.content != null) {
|
|
86406
|
+
if (!textStarted) {
|
|
86407
|
+
textId = openrouterResponseId || generateId2();
|
|
86408
|
+
controller.enqueue({
|
|
86409
|
+
type: "text-start",
|
|
86410
|
+
id: textId
|
|
86411
|
+
});
|
|
86412
|
+
textStarted = true;
|
|
86413
|
+
}
|
|
86414
|
+
controller.enqueue({
|
|
86415
|
+
type: "text-delta",
|
|
86416
|
+
delta: delta.content,
|
|
86417
|
+
id: textId || generateId2()
|
|
86418
|
+
});
|
|
86390
86419
|
}
|
|
86391
86420
|
if (delta.tool_calls != null) {
|
|
86392
86421
|
for (const toolCallDelta of delta.tool_calls) {
|
|
@@ -86486,7 +86515,7 @@ var OpenRouterChatLanguageModel = class {
|
|
|
86486
86515
|
var _a16;
|
|
86487
86516
|
if (finishReason === "tool-calls") {
|
|
86488
86517
|
for (const toolCall of toolCalls) {
|
|
86489
|
-
if (!toolCall.sent) {
|
|
86518
|
+
if (toolCall && !toolCall.sent) {
|
|
86490
86519
|
controller.enqueue({
|
|
86491
86520
|
type: "tool-call",
|
|
86492
86521
|
toolCallId: (_a16 = toolCall.id) != null ? _a16 : generateId2(),
|
|
@@ -103830,11 +103859,12 @@ var getModel = (config5, debugLogging = false) => {
|
|
|
103830
103859
|
console.log("<- Stream chunk:", text2.replace(/\n/g, "\\n"));
|
|
103831
103860
|
}
|
|
103832
103861
|
if (TRACING_FILE) {
|
|
103833
|
-
appendFileSync(TRACING_FILE, JSON.stringify({
|
|
103862
|
+
appendFileSync(TRACING_FILE, `${JSON.stringify({
|
|
103834
103863
|
type: "response-chunk",
|
|
103835
103864
|
timestamp: new Date().toISOString(),
|
|
103836
103865
|
chunk: text2
|
|
103837
|
-
}, null, 2)
|
|
103866
|
+
}, null, 2)}
|
|
103867
|
+
`);
|
|
103838
103868
|
}
|
|
103839
103869
|
}
|
|
103840
103870
|
}
|
|
@@ -103851,13 +103881,14 @@ var getModel = (config5, debugLogging = false) => {
|
|
|
103851
103881
|
console.dir(responseBody, { depth: null });
|
|
103852
103882
|
}
|
|
103853
103883
|
if (TRACING_FILE) {
|
|
103854
|
-
appendFileSync(TRACING_FILE, JSON.stringify({
|
|
103884
|
+
appendFileSync(TRACING_FILE, `${JSON.stringify({
|
|
103855
103885
|
type: "response",
|
|
103856
103886
|
timestamp: new Date().toISOString(),
|
|
103857
103887
|
status: res.status,
|
|
103858
103888
|
headers: Object.fromEntries(res.headers.entries()),
|
|
103859
103889
|
body: responseBody
|
|
103860
|
-
}, null, 2)
|
|
103890
|
+
}, null, 2)}
|
|
103891
|
+
`);
|
|
103861
103892
|
}
|
|
103862
103893
|
return new Response(full, {
|
|
103863
103894
|
headers: res.headers,
|
|
@@ -108270,13 +108301,16 @@ async function extendPatterns(basePatterns, dirPath) {
|
|
|
108270
108301
|
function createIgnore(patterns) {
|
|
108271
108302
|
return import_ignore.default().add(patterns);
|
|
108272
108303
|
}
|
|
108273
|
-
async function listFiles(dirPath, recursive, maxCount, cwd, excludeFiles) {
|
|
108274
|
-
let rootPatterns = [...
|
|
108275
|
-
|
|
108276
|
-
|
|
108277
|
-
|
|
108278
|
-
|
|
108279
|
-
|
|
108304
|
+
async function listFiles(dirPath, recursive, maxCount, cwd, excludeFiles, includeIgnored) {
|
|
108305
|
+
let rootPatterns = [...excludeFiles || []];
|
|
108306
|
+
if (!includeIgnored) {
|
|
108307
|
+
rootPatterns.push(...DEFAULT_IGNORES);
|
|
108308
|
+
try {
|
|
108309
|
+
const rootGitignore = await fs.readFile(join2(cwd, ".gitignore"), "utf8");
|
|
108310
|
+
const lines = rootGitignore.split(/\r?\n/).filter(Boolean);
|
|
108311
|
+
rootPatterns = [...rootPatterns, ...lines];
|
|
108312
|
+
} catch {}
|
|
108313
|
+
}
|
|
108280
108314
|
const results = [];
|
|
108281
108315
|
const processedDirs = new Set;
|
|
108282
108316
|
const queue = [
|
|
@@ -108289,7 +108323,7 @@ async function listFiles(dirPath, recursive, maxCount, cwd, excludeFiles) {
|
|
|
108289
108323
|
while (queue.length > 0) {
|
|
108290
108324
|
const { path: currentPath, patterns: parentPatterns, relPath: currentRelPath } = queue.shift();
|
|
108291
108325
|
processedDirs.add(currentRelPath);
|
|
108292
|
-
const mergedPatterns = await extendPatterns(parentPatterns, currentPath);
|
|
108326
|
+
const mergedPatterns = includeIgnored ? parentPatterns : await extendPatterns(parentPatterns, currentPath);
|
|
108293
108327
|
const folderIg = createIgnore(mergedPatterns);
|
|
108294
108328
|
const entries = await fs.readdir(currentPath, { withFileTypes: true });
|
|
108295
108329
|
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
@@ -108385,8 +108419,8 @@ async function searchFiles(path, regex, filePattern, cwd, excludeFiles) {
|
|
|
108385
108419
|
var getProvider = (_agentName, _config, options = {}) => {
|
|
108386
108420
|
const ig = import_ignore2.default().add(options.excludeFiles ?? []);
|
|
108387
108421
|
const provider2 = {
|
|
108388
|
-
readFile: async (path) => {
|
|
108389
|
-
if (ig.ignores(path)) {
|
|
108422
|
+
readFile: async (path, includeIgnored) => {
|
|
108423
|
+
if (!includeIgnored && ig.ignores(path)) {
|
|
108390
108424
|
throw new Error(`Not allow to access file ${path}`);
|
|
108391
108425
|
}
|
|
108392
108426
|
try {
|
|
@@ -108414,8 +108448,8 @@ var getProvider = (_agentName, _config, options = {}) => {
|
|
|
108414
108448
|
}
|
|
108415
108449
|
return await rename(sourcePath, targetPath);
|
|
108416
108450
|
},
|
|
108417
|
-
listFiles: async (path, recursive, maxCount) => {
|
|
108418
|
-
return await listFiles(path, recursive, maxCount, process.cwd(), options.excludeFiles);
|
|
108451
|
+
listFiles: async (path, recursive, maxCount, includeIgnored) => {
|
|
108452
|
+
return await listFiles(path, recursive, maxCount, process.cwd(), options.excludeFiles, includeIgnored);
|
|
108419
108453
|
},
|
|
108420
108454
|
executeCommand: (command, _needApprove) => {
|
|
108421
108455
|
return new Promise((resolve3, reject) => {
|
|
@@ -109239,6 +109273,9 @@ function getProviderOptions(provider3, modelId, thinkingBudgetTokens, supportThi
|
|
|
109239
109273
|
};
|
|
109240
109274
|
break;
|
|
109241
109275
|
case "openrouter" /* OpenRouter */:
|
|
109276
|
+
if (modelId.startsWith("anthropic/")) {
|
|
109277
|
+
break;
|
|
109278
|
+
}
|
|
109242
109279
|
providerOptions.openrouter = {
|
|
109243
109280
|
reasoning: {
|
|
109244
109281
|
max_tokens: thinkingBudgetTokens
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polka-codes/cli",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.5",
|
|
4
4
|
"license": "AGPL-3.0",
|
|
5
5
|
"author": "github@polka.codes",
|
|
6
6
|
"type": "module",
|
|
@@ -24,9 +24,9 @@
|
|
|
24
24
|
"@ai-sdk/provider": "2.0.0-beta.1",
|
|
25
25
|
"@ai-sdk/provider-utils": "3.0.0-beta.5",
|
|
26
26
|
"@inquirer/prompts": "^7.2.3",
|
|
27
|
-
"@openrouter/ai-sdk-provider": "^1.0.0-beta.
|
|
28
|
-
"@polka-codes/cli-shared": "0.9.
|
|
29
|
-
"@polka-codes/core": "0.9.
|
|
27
|
+
"@openrouter/ai-sdk-provider": "^1.0.0-beta.6",
|
|
28
|
+
"@polka-codes/cli-shared": "0.9.4",
|
|
29
|
+
"@polka-codes/core": "0.9.4",
|
|
30
30
|
"ai": "5.0.0-beta.24",
|
|
31
31
|
"commander": "^13.0.0",
|
|
32
32
|
"dotenv": "^16.4.7",
|