@polka-codes/cli-shared 0.8.20 → 0.8.22
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 +189 -258
- package/package.json +1 -2
package/dist/index.js
CHANGED
|
@@ -36783,39 +36783,6 @@ __export(exports_allTools, {
|
|
|
36783
36783
|
askFollowupQuestion: () => askFollowupQuestion_default
|
|
36784
36784
|
});
|
|
36785
36785
|
|
|
36786
|
-
// ../core/src/tools/utils/editFile.ts
|
|
36787
|
-
var START_OF_FILE = "<<<START_OF_FILE>>>";
|
|
36788
|
-
var END_OF_FILE = "<<<END_OF_FILE>>>";
|
|
36789
|
-
var editFile = async (fileContent, operations) => {
|
|
36790
|
-
if (!operations || operations.length === 0) {
|
|
36791
|
-
throw new Error("At least one edit operation is required");
|
|
36792
|
-
}
|
|
36793
|
-
let updatedContent = fileContent;
|
|
36794
|
-
for (const operation of operations) {
|
|
36795
|
-
updatedContent = await applyEditOperation(updatedContent, operation);
|
|
36796
|
-
}
|
|
36797
|
-
return updatedContent;
|
|
36798
|
-
};
|
|
36799
|
-
async function applyEditOperation(fileContent, operation) {
|
|
36800
|
-
const { search, replace } = operation;
|
|
36801
|
-
if (search === START_OF_FILE && replace === END_OF_FILE) {
|
|
36802
|
-
throw new Error("Cannot search for START_OF_FILE and replace with END_OF_FILE");
|
|
36803
|
-
}
|
|
36804
|
-
if (search === END_OF_FILE && replace === START_OF_FILE) {
|
|
36805
|
-
throw new Error("Cannot search for END_OF_FILE and replace with START_OF_FILE");
|
|
36806
|
-
}
|
|
36807
|
-
if (search === START_OF_FILE) {
|
|
36808
|
-
return replace + fileContent;
|
|
36809
|
-
}
|
|
36810
|
-
if (search === END_OF_FILE) {
|
|
36811
|
-
return fileContent + replace;
|
|
36812
|
-
}
|
|
36813
|
-
const index = fileContent.indexOf(search);
|
|
36814
|
-
if (index === -1) {
|
|
36815
|
-
throw new Error(`Could not find text: ${search}`);
|
|
36816
|
-
}
|
|
36817
|
-
return fileContent.slice(0, index) + replace + fileContent.slice(index + search.length);
|
|
36818
|
-
}
|
|
36819
36786
|
// ../core/src/tools/utils/getArg.ts
|
|
36820
36787
|
var getString = (args, name, defaultValue) => {
|
|
36821
36788
|
if (typeof args !== "object" || Array.isArray(args)) {
|
|
@@ -37422,29 +37389,29 @@ var toolInfo7 = {
|
|
|
37422
37389
|
{
|
|
37423
37390
|
name: "diff",
|
|
37424
37391
|
description: `One or more SEARCH/REPLACE blocks following this exact format:
|
|
37425
|
-
|
|
37426
|
-
|
|
37427
|
-
|
|
37428
|
-
|
|
37429
|
-
|
|
37430
|
-
|
|
37431
|
-
|
|
37432
|
-
|
|
37433
|
-
|
|
37434
|
-
|
|
37435
|
-
|
|
37436
|
-
|
|
37437
|
-
|
|
37438
|
-
|
|
37439
|
-
|
|
37440
|
-
|
|
37441
|
-
|
|
37442
|
-
|
|
37443
|
-
|
|
37444
|
-
|
|
37445
|
-
|
|
37446
|
-
|
|
37447
|
-
|
|
37392
|
+
\`\`\`
|
|
37393
|
+
<<<<<<< SEARCH
|
|
37394
|
+
[exact content to find]
|
|
37395
|
+
=======
|
|
37396
|
+
[new content to replace with]
|
|
37397
|
+
>>>>>>> REPLACE
|
|
37398
|
+
\`\`\`
|
|
37399
|
+
Critical rules:
|
|
37400
|
+
1. SEARCH content must match the associated file section to find EXACTLY:
|
|
37401
|
+
* Match character-for-character including whitespace, indentation, line endings
|
|
37402
|
+
* Include all comments, docstrings, etc.
|
|
37403
|
+
2. SEARCH/REPLACE blocks will ONLY replace the first match occurrence.
|
|
37404
|
+
* Including multiple unique SEARCH/REPLACE blocks if you need to make multiple changes.
|
|
37405
|
+
* Include *just* enough lines in each SEARCH section to uniquely match each set of lines that need to change.
|
|
37406
|
+
* When using multiple SEARCH/REPLACE blocks, list them in the order they appear in the file.
|
|
37407
|
+
3. Keep SEARCH/REPLACE blocks concise:
|
|
37408
|
+
* Break large SEARCH/REPLACE blocks into a series of smaller blocks that each change a small portion of the file.
|
|
37409
|
+
* Include just the changing lines, and a few surrounding lines if needed for uniqueness.
|
|
37410
|
+
* Do not include long runs of unchanging lines in SEARCH/REPLACE blocks.
|
|
37411
|
+
* Each line must be complete. Never truncate lines mid-way through as this can cause matching failures.
|
|
37412
|
+
4. Special operations:
|
|
37413
|
+
* To move code: Use two SEARCH/REPLACE blocks (one to delete from original + one to insert at new location)
|
|
37414
|
+
* To delete code: Use empty REPLACE section`,
|
|
37448
37415
|
required: true,
|
|
37449
37416
|
usageValue: "Search and replace blocks here"
|
|
37450
37417
|
}
|
|
@@ -37487,6 +37454,73 @@ function handleSubmit() {
|
|
|
37487
37454
|
return (
|
|
37488
37455
|
<div>
|
|
37489
37456
|
>>>>>>> REPLACE
|
|
37457
|
+
`
|
|
37458
|
+
}
|
|
37459
|
+
]
|
|
37460
|
+
},
|
|
37461
|
+
{
|
|
37462
|
+
description: "Request to perform a simple, single-line replacement",
|
|
37463
|
+
parameters: [
|
|
37464
|
+
{
|
|
37465
|
+
name: "path",
|
|
37466
|
+
value: "src/config.js"
|
|
37467
|
+
},
|
|
37468
|
+
{
|
|
37469
|
+
name: "diff",
|
|
37470
|
+
value: `
|
|
37471
|
+
<<<<<<< SEARCH
|
|
37472
|
+
const API_URL = 'https://api.example.com';
|
|
37473
|
+
=======
|
|
37474
|
+
const API_URL = 'https://api.staging.example.com';
|
|
37475
|
+
>>>>>>> REPLACE
|
|
37476
|
+
`
|
|
37477
|
+
}
|
|
37478
|
+
]
|
|
37479
|
+
},
|
|
37480
|
+
{
|
|
37481
|
+
description: "Request to add a new function to a file",
|
|
37482
|
+
parameters: [
|
|
37483
|
+
{
|
|
37484
|
+
name: "path",
|
|
37485
|
+
value: "src/utils.js"
|
|
37486
|
+
},
|
|
37487
|
+
{
|
|
37488
|
+
name: "diff",
|
|
37489
|
+
value: `
|
|
37490
|
+
<<<<<<< SEARCH
|
|
37491
|
+
function helperA() {
|
|
37492
|
+
// ...
|
|
37493
|
+
}
|
|
37494
|
+
=======
|
|
37495
|
+
function helperA() {
|
|
37496
|
+
// ...
|
|
37497
|
+
}
|
|
37498
|
+
|
|
37499
|
+
function newHelper() {
|
|
37500
|
+
// implementation
|
|
37501
|
+
}
|
|
37502
|
+
>>>>>>> REPLACE
|
|
37503
|
+
`
|
|
37504
|
+
}
|
|
37505
|
+
]
|
|
37506
|
+
},
|
|
37507
|
+
{
|
|
37508
|
+
description: "Request to delete a block of code from a file",
|
|
37509
|
+
parameters: [
|
|
37510
|
+
{
|
|
37511
|
+
name: "path",
|
|
37512
|
+
value: "src/app.js"
|
|
37513
|
+
},
|
|
37514
|
+
{
|
|
37515
|
+
name: "diff",
|
|
37516
|
+
value: `
|
|
37517
|
+
<<<<<<< SEARCH
|
|
37518
|
+
function oldFeature() {
|
|
37519
|
+
// This is no longer needed
|
|
37520
|
+
}
|
|
37521
|
+
|
|
37522
|
+
=======
|
|
37523
|
+
>>>>>>> REPLACE
|
|
37490
37524
|
`
|
|
37491
37525
|
}
|
|
37492
37526
|
]
|
|
@@ -37603,7 +37637,48 @@ var searchFiles_default = {
|
|
|
37603
37637
|
};
|
|
37604
37638
|
// ../core/src/tools/updateKnowledge.ts
|
|
37605
37639
|
var import_yaml = __toESM(require_dist(), 1);
|
|
37606
|
-
|
|
37640
|
+
|
|
37641
|
+
// ../core/src/path.ts
|
|
37642
|
+
function normalize(path) {
|
|
37643
|
+
const isAbsolute = path.startsWith("/");
|
|
37644
|
+
const segments = path.split("/").filter(Boolean);
|
|
37645
|
+
const stack = [];
|
|
37646
|
+
for (const seg of segments) {
|
|
37647
|
+
if (seg === ".")
|
|
37648
|
+
continue;
|
|
37649
|
+
if (seg === "..") {
|
|
37650
|
+
if (stack.length && stack[stack.length - 1] !== "..") {
|
|
37651
|
+
stack.pop();
|
|
37652
|
+
} else if (!isAbsolute) {
|
|
37653
|
+
stack.push("..");
|
|
37654
|
+
}
|
|
37655
|
+
} else {
|
|
37656
|
+
stack.push(seg);
|
|
37657
|
+
}
|
|
37658
|
+
}
|
|
37659
|
+
let result = stack.join("/");
|
|
37660
|
+
if (!result && !isAbsolute)
|
|
37661
|
+
return ".";
|
|
37662
|
+
if (result && path.endsWith("/"))
|
|
37663
|
+
result += "/";
|
|
37664
|
+
return (isAbsolute ? "/" : "") + result;
|
|
37665
|
+
}
|
|
37666
|
+
function join(...parts) {
|
|
37667
|
+
if (parts.length === 0)
|
|
37668
|
+
return ".";
|
|
37669
|
+
let combined = "";
|
|
37670
|
+
for (const p2 of parts) {
|
|
37671
|
+
if (typeof p2 !== "string") {
|
|
37672
|
+
throw new TypeError("Arguments to join must be strings");
|
|
37673
|
+
}
|
|
37674
|
+
if (p2) {
|
|
37675
|
+
combined = combined ? `${combined}/${p2}` : p2;
|
|
37676
|
+
}
|
|
37677
|
+
}
|
|
37678
|
+
return normalize(combined);
|
|
37679
|
+
}
|
|
37680
|
+
|
|
37681
|
+
// ../core/src/tools/updateKnowledge.ts
|
|
37607
37682
|
var toolInfo9 = {
|
|
37608
37683
|
name: "update_knowledge",
|
|
37609
37684
|
description: "Update knowledge in a knowledge.ai.yml file with smart merging capabilities. This tool lets you add, update, or remove information using path-based updates and special directives.",
|
|
@@ -38111,167 +38186,6 @@ var renameFile_default = {
|
|
|
38111
38186
|
handler: handler13,
|
|
38112
38187
|
isAvailable: isAvailable13
|
|
38113
38188
|
};
|
|
38114
|
-
// ../core/src/tools/editFile.ts
|
|
38115
|
-
var toolInfo14 = {
|
|
38116
|
-
name: "edit_file",
|
|
38117
|
-
description: "Request to edit file contents using search/replace operations. Supports multiple edit operations in a single call.",
|
|
38118
|
-
parameters: [
|
|
38119
|
-
{
|
|
38120
|
-
name: "path",
|
|
38121
|
-
description: "The path of the file to edit",
|
|
38122
|
-
required: true,
|
|
38123
|
-
usageValue: "File path here"
|
|
38124
|
-
},
|
|
38125
|
-
{
|
|
38126
|
-
name: "operations",
|
|
38127
|
-
description: "Edit operation with search and replace parameters",
|
|
38128
|
-
required: true,
|
|
38129
|
-
allowMultiple: true,
|
|
38130
|
-
children: [
|
|
38131
|
-
{
|
|
38132
|
-
name: "search",
|
|
38133
|
-
description: `Text to search for and replace (use ${START_OF_FILE} to insert at file start, ${END_OF_FILE} to insert at file end)`,
|
|
38134
|
-
required: true,
|
|
38135
|
-
usageValue: "Text to find and replace"
|
|
38136
|
-
},
|
|
38137
|
-
{
|
|
38138
|
-
name: "replace",
|
|
38139
|
-
description: "Text to replace the search text with",
|
|
38140
|
-
required: true,
|
|
38141
|
-
usageValue: "Replacement text"
|
|
38142
|
-
}
|
|
38143
|
-
],
|
|
38144
|
-
usageValue: "operations here"
|
|
38145
|
-
}
|
|
38146
|
-
],
|
|
38147
|
-
examples: [
|
|
38148
|
-
{
|
|
38149
|
-
description: "Replace specific text",
|
|
38150
|
-
parameters: [
|
|
38151
|
-
{
|
|
38152
|
-
name: "path",
|
|
38153
|
-
value: "src/main.ts"
|
|
38154
|
-
},
|
|
38155
|
-
{
|
|
38156
|
-
name: "operations",
|
|
38157
|
-
value: {
|
|
38158
|
-
search: `function oldFunction() {
|
|
38159
|
-
return 42;
|
|
38160
|
-
}`,
|
|
38161
|
-
replace: `function newFunction() {
|
|
38162
|
-
return "new implementation";
|
|
38163
|
-
}`
|
|
38164
|
-
}
|
|
38165
|
-
}
|
|
38166
|
-
]
|
|
38167
|
-
},
|
|
38168
|
-
{
|
|
38169
|
-
description: "Insert at start of file",
|
|
38170
|
-
parameters: [
|
|
38171
|
-
{
|
|
38172
|
-
name: "path",
|
|
38173
|
-
value: "src/header.ts"
|
|
38174
|
-
},
|
|
38175
|
-
{
|
|
38176
|
-
name: "operations",
|
|
38177
|
-
value: {
|
|
38178
|
-
search: START_OF_FILE,
|
|
38179
|
-
replace: `// File header comment
|
|
38180
|
-
`
|
|
38181
|
-
}
|
|
38182
|
-
}
|
|
38183
|
-
]
|
|
38184
|
-
},
|
|
38185
|
-
{
|
|
38186
|
-
description: "Multiple operations in one call",
|
|
38187
|
-
parameters: [
|
|
38188
|
-
{
|
|
38189
|
-
name: "path",
|
|
38190
|
-
value: "src/utils.ts"
|
|
38191
|
-
},
|
|
38192
|
-
{
|
|
38193
|
-
name: "operations",
|
|
38194
|
-
value: [
|
|
38195
|
-
{
|
|
38196
|
-
search: 'import React from "react"',
|
|
38197
|
-
replace: 'import React, { useState } from "react"'
|
|
38198
|
-
},
|
|
38199
|
-
{
|
|
38200
|
-
search: `function Component() {
|
|
38201
|
-
return (`,
|
|
38202
|
-
replace: `function Component() {
|
|
38203
|
-
const [state, setState] = useState(false);
|
|
38204
|
-
return (`
|
|
38205
|
-
}
|
|
38206
|
-
]
|
|
38207
|
-
}
|
|
38208
|
-
]
|
|
38209
|
-
},
|
|
38210
|
-
{
|
|
38211
|
-
description: "Append content at end of file",
|
|
38212
|
-
parameters: [
|
|
38213
|
-
{
|
|
38214
|
-
name: "path",
|
|
38215
|
-
value: "src/footer.ts"
|
|
38216
|
-
},
|
|
38217
|
-
{
|
|
38218
|
-
name: "operations",
|
|
38219
|
-
value: {
|
|
38220
|
-
search: END_OF_FILE,
|
|
38221
|
-
replace: `
|
|
38222
|
-
// End of file appended comment
|
|
38223
|
-
`
|
|
38224
|
-
}
|
|
38225
|
-
}
|
|
38226
|
-
]
|
|
38227
|
-
}
|
|
38228
|
-
],
|
|
38229
|
-
permissionLevel: 2 /* Write */
|
|
38230
|
-
};
|
|
38231
|
-
var handler14 = async (provider, args) => {
|
|
38232
|
-
if (!provider.readFile || !provider.writeFile) {
|
|
38233
|
-
return {
|
|
38234
|
-
type: "Error" /* Error */,
|
|
38235
|
-
message: "Not possible to edit file. Abort."
|
|
38236
|
-
};
|
|
38237
|
-
}
|
|
38238
|
-
const path = getString(args, "path");
|
|
38239
|
-
const operations = getArray(args, "operations");
|
|
38240
|
-
if (!operations || operations.length === 0) {
|
|
38241
|
-
return {
|
|
38242
|
-
type: "Error" /* Error */,
|
|
38243
|
-
message: `<error><edit_file_path>${path}</edit_file_path><error_message>At least one edit operation is required</error_message></error>`
|
|
38244
|
-
};
|
|
38245
|
-
}
|
|
38246
|
-
const fileContent = await provider.readFile(path);
|
|
38247
|
-
if (fileContent == null) {
|
|
38248
|
-
return {
|
|
38249
|
-
type: "Error" /* Error */,
|
|
38250
|
-
message: `<error><edit_file_path>${path}</edit_file_path><error_message>File not found</error_message></error>`
|
|
38251
|
-
};
|
|
38252
|
-
}
|
|
38253
|
-
try {
|
|
38254
|
-
const result = await editFile(fileContent, operations);
|
|
38255
|
-
await provider.writeFile(path, result);
|
|
38256
|
-
return {
|
|
38257
|
-
type: "Reply" /* Reply */,
|
|
38258
|
-
message: `<edit_file_path>${path}</edit_file_path>`
|
|
38259
|
-
};
|
|
38260
|
-
} catch (error) {
|
|
38261
|
-
return {
|
|
38262
|
-
type: "Error" /* Error */,
|
|
38263
|
-
message: `<error><edit_file_path>${path}</edit_file_path><error_message>${error instanceof Error ? error.message : String(error)}</error_message></error>`
|
|
38264
|
-
};
|
|
38265
|
-
}
|
|
38266
|
-
};
|
|
38267
|
-
var isAvailable14 = (provider) => {
|
|
38268
|
-
return !!provider.readFile && !!provider.writeFile;
|
|
38269
|
-
};
|
|
38270
|
-
var editFile_default = {
|
|
38271
|
-
...toolInfo14,
|
|
38272
|
-
handler: handler14,
|
|
38273
|
-
isAvailable: isAvailable14
|
|
38274
|
-
};
|
|
38275
38189
|
// ../core/src/getAvailableTools.ts
|
|
38276
38190
|
var getAvailableTools = ({
|
|
38277
38191
|
provider: provider2,
|
|
@@ -38496,6 +38410,8 @@ Tool use is formatted using XML-style tags. The tool name is enclosed in opening
|
|
|
38496
38410
|
...
|
|
38497
38411
|
</${toolNamePrefix}tool_name>
|
|
38498
38412
|
|
|
38413
|
+
**It is crucial that all tags are correctly nested and closed.**
|
|
38414
|
+
|
|
38499
38415
|
## Array Parameters
|
|
38500
38416
|
|
|
38501
38417
|
To create an array of values for a parameter, repeat the parameter tag multiple times:
|
|
@@ -38530,7 +38446,7 @@ You can also combine array parameters with nested objects:
|
|
|
38530
38446
|
</${parameterPrefix}key>
|
|
38531
38447
|
</${toolNamePrefix}example_tool>
|
|
38532
38448
|
|
|
38533
|
-
Always adhere to this format
|
|
38449
|
+
Always adhere to this format, ensuring every opening tag has a matching closing tag, to ensure proper parsing and execution.
|
|
38534
38450
|
|
|
38535
38451
|
NEVER surround tool use with triple backticks (\`\`\`).
|
|
38536
38452
|
|
|
@@ -38869,8 +38785,8 @@ ${instance.prompt}`;
|
|
|
38869
38785
|
}
|
|
38870
38786
|
async#invokeTool(name, args) {
|
|
38871
38787
|
try {
|
|
38872
|
-
const
|
|
38873
|
-
if (!
|
|
38788
|
+
const handler14 = this.handlers[name]?.handler;
|
|
38789
|
+
if (!handler14) {
|
|
38874
38790
|
return {
|
|
38875
38791
|
type: "Error" /* Error */,
|
|
38876
38792
|
message: responsePrompts.errorInvokeTool(name, "Tool not found"),
|
|
@@ -38889,7 +38805,7 @@ ${instance.prompt}`;
|
|
|
38889
38805
|
if (resp) {
|
|
38890
38806
|
return resp;
|
|
38891
38807
|
}
|
|
38892
|
-
return await
|
|
38808
|
+
return await handler14(this.config.provider, args);
|
|
38893
38809
|
} catch (error) {
|
|
38894
38810
|
return {
|
|
38895
38811
|
type: "Error" /* Error */,
|
|
@@ -47536,7 +47452,7 @@ var readLocalConfig = (path) => {
|
|
|
47536
47452
|
var import_ignore2 = __toESM(require_ignore(), 1);
|
|
47537
47453
|
import { spawn as spawn2 } from "node:child_process";
|
|
47538
47454
|
import { mkdir, readFile, rename, unlink, writeFile } from "node:fs/promises";
|
|
47539
|
-
import { dirname } from "node:path";
|
|
47455
|
+
import { dirname as dirname2 } from "node:path";
|
|
47540
47456
|
|
|
47541
47457
|
// ../../node_modules/@inquirer/core/dist/esm/lib/key.js
|
|
47542
47458
|
var isUpKey = (key) => key.name === "up" || key.name === "k" || key.ctrl && key.name === "p";
|
|
@@ -48098,15 +48014,15 @@ function useKeypress(userHandler) {
|
|
|
48098
48014
|
signal.current = userHandler;
|
|
48099
48015
|
useEffect((rl) => {
|
|
48100
48016
|
let ignore = false;
|
|
48101
|
-
const
|
|
48017
|
+
const handler14 = withUpdates((_input, event) => {
|
|
48102
48018
|
if (ignore)
|
|
48103
48019
|
return;
|
|
48104
48020
|
signal.current(event, rl);
|
|
48105
48021
|
});
|
|
48106
|
-
rl.input.on("keypress",
|
|
48022
|
+
rl.input.on("keypress", handler14);
|
|
48107
48023
|
return () => {
|
|
48108
48024
|
ignore = true;
|
|
48109
|
-
rl.input.removeListener("keypress",
|
|
48025
|
+
rl.input.removeListener("keypress", handler14);
|
|
48110
48026
|
};
|
|
48111
48027
|
}, []);
|
|
48112
48028
|
}
|
|
@@ -48288,16 +48204,16 @@ class Emitter {
|
|
|
48288
48204
|
|
|
48289
48205
|
class SignalExitBase {
|
|
48290
48206
|
}
|
|
48291
|
-
var signalExitWrap = (
|
|
48207
|
+
var signalExitWrap = (handler14) => {
|
|
48292
48208
|
return {
|
|
48293
48209
|
onExit(cb, opts) {
|
|
48294
|
-
return
|
|
48210
|
+
return handler14.onExit(cb, opts);
|
|
48295
48211
|
},
|
|
48296
48212
|
load() {
|
|
48297
|
-
return
|
|
48213
|
+
return handler14.load();
|
|
48298
48214
|
},
|
|
48299
48215
|
unload() {
|
|
48300
|
-
return
|
|
48216
|
+
return handler14.unload();
|
|
48301
48217
|
}
|
|
48302
48218
|
};
|
|
48303
48219
|
};
|
|
@@ -48813,6 +48729,24 @@ ${theme.style.description(selectedChoice.description)}` : ``;
|
|
|
48813
48729
|
return `${[prefix, message, helpTipTop].filter(Boolean).join(" ")}
|
|
48814
48730
|
${page}${helpTipBottom}${choiceDescription}${import_ansi_escapes2.default.cursorHide}`;
|
|
48815
48731
|
});
|
|
48732
|
+
// src/utils/checkRipgrep.ts
|
|
48733
|
+
import { spawnSync } from "node:child_process";
|
|
48734
|
+
var rgAvailability = {
|
|
48735
|
+
isAvailable: null
|
|
48736
|
+
};
|
|
48737
|
+
function checkRipgrep() {
|
|
48738
|
+
if (rgAvailability.isAvailable !== null) {
|
|
48739
|
+
return rgAvailability.isAvailable;
|
|
48740
|
+
}
|
|
48741
|
+
const rg = spawnSync("rg", ["--version"]);
|
|
48742
|
+
if (rg.error || rg.status !== 0) {
|
|
48743
|
+
rgAvailability.isAvailable = false;
|
|
48744
|
+
return false;
|
|
48745
|
+
}
|
|
48746
|
+
rgAvailability.isAvailable = true;
|
|
48747
|
+
return true;
|
|
48748
|
+
}
|
|
48749
|
+
|
|
48816
48750
|
// src/utils/listFiles.ts
|
|
48817
48751
|
var import_ignore = __toESM(require_ignore(), 1);
|
|
48818
48752
|
import { promises as fs2 } from "node:fs";
|
|
@@ -48910,14 +48844,7 @@ async function listFiles(dirPath, recursive, maxCount, cwd, excludeFiles) {
|
|
|
48910
48844
|
|
|
48911
48845
|
// src/utils/searchFiles.ts
|
|
48912
48846
|
import { spawn } from "node:child_process";
|
|
48913
|
-
|
|
48914
|
-
// ../../node_modules/@vscode/ripgrep/lib/index.js
|
|
48915
|
-
var __dirname = "/Users/xiliangchen/projects/polka-codes/node_modules/@vscode/ripgrep/lib";
|
|
48916
|
-
var path = __require("path");
|
|
48917
|
-
var $rgPath = path.join(__dirname, `../bin/rg${process.platform === "win32" ? ".exe" : ""}`);
|
|
48918
|
-
|
|
48919
|
-
// src/utils/searchFiles.ts
|
|
48920
|
-
async function searchFiles(path2, regex, filePattern, cwd, excludeFiles) {
|
|
48847
|
+
async function searchFiles(path, regex, filePattern, cwd, excludeFiles) {
|
|
48921
48848
|
const args = [
|
|
48922
48849
|
"--line-number",
|
|
48923
48850
|
"--context=5",
|
|
@@ -48938,10 +48865,10 @@ async function searchFiles(path2, regex, filePattern, cwd, excludeFiles) {
|
|
|
48938
48865
|
args.push("--glob", `!${pattern}`);
|
|
48939
48866
|
}
|
|
48940
48867
|
}
|
|
48941
|
-
args.push(regex,
|
|
48868
|
+
args.push(regex, path);
|
|
48942
48869
|
return new Promise((resolve2, reject) => {
|
|
48943
48870
|
const results = [];
|
|
48944
|
-
const rg = spawn(
|
|
48871
|
+
const rg = spawn("rg", args, {
|
|
48945
48872
|
cwd,
|
|
48946
48873
|
stdio: ["ignore", "pipe", "pipe"]
|
|
48947
48874
|
});
|
|
@@ -48967,28 +48894,28 @@ async function searchFiles(path2, regex, filePattern, cwd, excludeFiles) {
|
|
|
48967
48894
|
var getProvider = (agentName, config2, options = {}) => {
|
|
48968
48895
|
const ig = import_ignore2.default().add(options.excludeFiles ?? []);
|
|
48969
48896
|
const provider2 = {
|
|
48970
|
-
readFile: async (
|
|
48971
|
-
if (ig.ignores(
|
|
48972
|
-
throw new Error(`Not allow to access file ${
|
|
48897
|
+
readFile: async (path) => {
|
|
48898
|
+
if (ig.ignores(path)) {
|
|
48899
|
+
throw new Error(`Not allow to access file ${path}`);
|
|
48973
48900
|
}
|
|
48974
48901
|
try {
|
|
48975
|
-
return await readFile(
|
|
48902
|
+
return await readFile(path, "utf8");
|
|
48976
48903
|
} catch (_e2) {
|
|
48977
48904
|
return;
|
|
48978
48905
|
}
|
|
48979
48906
|
},
|
|
48980
|
-
writeFile: async (
|
|
48981
|
-
if (ig.ignores(
|
|
48982
|
-
throw new Error(`Not allow to access file ${
|
|
48907
|
+
writeFile: async (path, content) => {
|
|
48908
|
+
if (ig.ignores(path)) {
|
|
48909
|
+
throw new Error(`Not allow to access file ${path}`);
|
|
48983
48910
|
}
|
|
48984
|
-
await mkdir(
|
|
48985
|
-
return await writeFile(
|
|
48911
|
+
await mkdir(dirname2(path), { recursive: true });
|
|
48912
|
+
return await writeFile(path, content, "utf8");
|
|
48986
48913
|
},
|
|
48987
|
-
removeFile: async (
|
|
48988
|
-
if (ig.ignores(
|
|
48989
|
-
throw new Error(`Not allow to access file ${
|
|
48914
|
+
removeFile: async (path) => {
|
|
48915
|
+
if (ig.ignores(path)) {
|
|
48916
|
+
throw new Error(`Not allow to access file ${path}`);
|
|
48990
48917
|
}
|
|
48991
|
-
return await unlink(
|
|
48918
|
+
return await unlink(path);
|
|
48992
48919
|
},
|
|
48993
48920
|
renameFile: async (sourcePath, targetPath) => {
|
|
48994
48921
|
if (ig.ignores(sourcePath) || ig.ignores(targetPath)) {
|
|
@@ -48996,11 +48923,8 @@ var getProvider = (agentName, config2, options = {}) => {
|
|
|
48996
48923
|
}
|
|
48997
48924
|
return await rename(sourcePath, targetPath);
|
|
48998
48925
|
},
|
|
48999
|
-
listFiles: async (
|
|
49000
|
-
return await listFiles(
|
|
49001
|
-
},
|
|
49002
|
-
searchFiles: async (path2, regex, filePattern) => {
|
|
49003
|
-
return await searchFiles(path2, regex, filePattern, process.cwd(), options.excludeFiles);
|
|
48926
|
+
listFiles: async (path, recursive, maxCount) => {
|
|
48927
|
+
return await listFiles(path, recursive, maxCount, process.cwd(), options.excludeFiles);
|
|
49004
48928
|
},
|
|
49005
48929
|
executeCommand: (command, needApprove) => {
|
|
49006
48930
|
return new Promise((resolve2, reject) => {
|
|
@@ -49057,6 +48981,13 @@ var getProvider = (agentName, config2, options = {}) => {
|
|
|
49057
48981
|
return;
|
|
49058
48982
|
}
|
|
49059
48983
|
};
|
|
48984
|
+
if (checkRipgrep()) {
|
|
48985
|
+
provider2.searchFiles = async (path, regex, filePattern) => {
|
|
48986
|
+
return await searchFiles(path, regex, filePattern, process.cwd(), options.excludeFiles);
|
|
48987
|
+
};
|
|
48988
|
+
} else {
|
|
48989
|
+
console.error("Error: ripgrep (rg) is not installed. Search file tool is disabled. Please install it from https://github.com/BurntSushi/ripgrep#installation");
|
|
48990
|
+
}
|
|
49060
48991
|
return provider2;
|
|
49061
48992
|
};
|
|
49062
48993
|
// ../../node_modules/chalk/source/vendor/ansi-styles/index.js
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polka-codes/cli-shared",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.22",
|
|
4
4
|
"license": "AGPL-3.0",
|
|
5
5
|
"author": "github@polka.codes",
|
|
6
6
|
"type": "module",
|
|
@@ -16,7 +16,6 @@
|
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@polka-codes/core": "0.8.10",
|
|
19
|
-
"@vscode/ripgrep": "^1.15.10",
|
|
20
19
|
"ignore": "^7.0.3",
|
|
21
20
|
"lodash": "^4.17.21",
|
|
22
21
|
"yaml": "^2.7.0",
|