@polka-codes/cli-shared 0.9.4 → 0.9.6
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 +272 -27
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -27185,7 +27185,17 @@ var toolInfo7 = {
|
|
|
27185
27185
|
return true;
|
|
27186
27186
|
}
|
|
27187
27187
|
return val;
|
|
27188
|
-
}, 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)" })
|
|
27188
|
+
}, 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)" }),
|
|
27189
|
+
includeIgnored: exports_external.preprocess((val) => {
|
|
27190
|
+
if (typeof val === "string") {
|
|
27191
|
+
const lower = val.toLowerCase();
|
|
27192
|
+
if (lower === "false")
|
|
27193
|
+
return false;
|
|
27194
|
+
if (lower === "true")
|
|
27195
|
+
return true;
|
|
27196
|
+
}
|
|
27197
|
+
return val;
|
|
27198
|
+
}, 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)" })
|
|
27189
27199
|
}).meta({
|
|
27190
27200
|
examples: [
|
|
27191
27201
|
{
|
|
@@ -27206,8 +27216,8 @@ var handler7 = async (provider, args) => {
|
|
|
27206
27216
|
message: "Not possible to list files. Abort."
|
|
27207
27217
|
};
|
|
27208
27218
|
}
|
|
27209
|
-
const { path, maxCount, recursive } = toolInfo7.parameters.parse(args);
|
|
27210
|
-
const [files, limitReached] = await provider.listFiles(path, recursive, maxCount);
|
|
27219
|
+
const { path, maxCount, recursive, includeIgnored } = toolInfo7.parameters.parse(args);
|
|
27220
|
+
const [files, limitReached] = await provider.listFiles(path, recursive, maxCount, includeIgnored);
|
|
27211
27221
|
return {
|
|
27212
27222
|
type: "Reply" /* Reply */,
|
|
27213
27223
|
message: `<list_files_path>${path}</list_files_path>
|
|
@@ -27236,7 +27246,17 @@ var toolInfo8 = {
|
|
|
27236
27246
|
return [];
|
|
27237
27247
|
const values = Array.isArray(val) ? val : [val];
|
|
27238
27248
|
return values.flatMap((i) => typeof i === "string" ? i.split(",") : []).filter((s) => s.length > 0);
|
|
27239
|
-
}, exports_external.array(exports_external.string())).describe("The path of the file to read").meta({ usageValue: "Comma separated paths here" })
|
|
27249
|
+
}, exports_external.array(exports_external.string())).describe("The path of the file to read").meta({ usageValue: "Comma separated paths here" }),
|
|
27250
|
+
includeIgnored: exports_external.preprocess((val) => {
|
|
27251
|
+
if (typeof val === "string") {
|
|
27252
|
+
const lower = val.toLowerCase();
|
|
27253
|
+
if (lower === "false")
|
|
27254
|
+
return false;
|
|
27255
|
+
if (lower === "true")
|
|
27256
|
+
return true;
|
|
27257
|
+
}
|
|
27258
|
+
return val;
|
|
27259
|
+
}, 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)" })
|
|
27240
27260
|
}).meta({
|
|
27241
27261
|
examples: [
|
|
27242
27262
|
{
|
|
@@ -27262,10 +27282,10 @@ var handler8 = async (provider, args) => {
|
|
|
27262
27282
|
message: "Not possible to read file. Abort."
|
|
27263
27283
|
};
|
|
27264
27284
|
}
|
|
27265
|
-
const { path: paths } = toolInfo8.parameters.parse(args);
|
|
27285
|
+
const { path: paths, includeIgnored } = toolInfo8.parameters.parse(args);
|
|
27266
27286
|
const resp = [];
|
|
27267
27287
|
for (const path of paths) {
|
|
27268
|
-
const fileContent = await provider.readFile(path);
|
|
27288
|
+
const fileContent = await provider.readFile(path, includeIgnored);
|
|
27269
27289
|
if (!fileContent) {
|
|
27270
27290
|
resp.push(`<read_file_file_content path="${path}" file_not_found="true" />`);
|
|
27271
27291
|
} else {
|
|
@@ -27273,7 +27293,7 @@ var handler8 = async (provider, args) => {
|
|
|
27273
27293
|
if (isEmpty) {
|
|
27274
27294
|
resp.push(`<read_file_file_content path="${path}" is_empty="true" />`);
|
|
27275
27295
|
} else {
|
|
27276
|
-
resp.push(`<
|
|
27296
|
+
resp.push(`<read_file_file_content path="${path}">${fileContent}</read_file_file_content>`);
|
|
27277
27297
|
}
|
|
27278
27298
|
}
|
|
27279
27299
|
}
|
|
@@ -27573,9 +27593,16 @@ var handler11 = async (provider, args) => {
|
|
|
27573
27593
|
message: "Not possible to replace in file. Abort."
|
|
27574
27594
|
};
|
|
27575
27595
|
}
|
|
27596
|
+
const parsed = toolInfo11.parameters.safeParse(args);
|
|
27597
|
+
if (!parsed.success) {
|
|
27598
|
+
return {
|
|
27599
|
+
type: "Invalid" /* Invalid */,
|
|
27600
|
+
message: `Invalid arguments for replace_in_file: ${parsed.error.message}`
|
|
27601
|
+
};
|
|
27602
|
+
}
|
|
27603
|
+
const { path, diff } = parsed.data;
|
|
27576
27604
|
try {
|
|
27577
|
-
const
|
|
27578
|
-
const fileContent = await provider.readFile(path);
|
|
27605
|
+
const fileContent = await provider.readFile(path, false);
|
|
27579
27606
|
if (fileContent == null) {
|
|
27580
27607
|
return {
|
|
27581
27608
|
type: "Error" /* Error */,
|
|
@@ -27652,8 +27679,15 @@ var handler12 = async (provider, args) => {
|
|
|
27652
27679
|
message: "Not possible to search files. Abort."
|
|
27653
27680
|
};
|
|
27654
27681
|
}
|
|
27682
|
+
const parsed = toolInfo12.parameters.safeParse(args);
|
|
27683
|
+
if (!parsed.success) {
|
|
27684
|
+
return {
|
|
27685
|
+
type: "Invalid" /* Invalid */,
|
|
27686
|
+
message: `Invalid arguments for search_files: ${parsed.error.message}`
|
|
27687
|
+
};
|
|
27688
|
+
}
|
|
27689
|
+
const { path, regex, filePattern } = parsed.data;
|
|
27655
27690
|
try {
|
|
27656
|
-
const { path, regex, filePattern } = toolInfo12.parameters.parse(args);
|
|
27657
27691
|
const files = await provider.searchFiles(path, regex, filePattern ?? "*");
|
|
27658
27692
|
return {
|
|
27659
27693
|
type: "Reply" /* Reply */,
|
|
@@ -27668,8 +27702,8 @@ ${files.join(`
|
|
|
27668
27702
|
};
|
|
27669
27703
|
} catch (error40) {
|
|
27670
27704
|
return {
|
|
27671
|
-
type: "
|
|
27672
|
-
message: `
|
|
27705
|
+
type: "Error" /* Error */,
|
|
27706
|
+
message: `Error searching files: ${error40}`
|
|
27673
27707
|
};
|
|
27674
27708
|
}
|
|
27675
27709
|
};
|
|
@@ -51020,6 +51054,7 @@ ${instance.prompt}`;
|
|
|
51020
51054
|
resetTimeout();
|
|
51021
51055
|
const streamTextOptions = {
|
|
51022
51056
|
model: this.ai,
|
|
51057
|
+
temperature: 0,
|
|
51023
51058
|
messages,
|
|
51024
51059
|
providerOptions: this.config.parameters?.providerOptions,
|
|
51025
51060
|
onChunk: async ({ chunk }) => {
|
|
@@ -51088,6 +51123,14 @@ ${instance.prompt}`;
|
|
|
51088
51123
|
}
|
|
51089
51124
|
this.#messages.push(...respMessages);
|
|
51090
51125
|
if (this.config.toolFormat === "native") {
|
|
51126
|
+
const assistantText = respMessages.map((msg) => {
|
|
51127
|
+
if (typeof msg.content === "string") {
|
|
51128
|
+
return msg.content;
|
|
51129
|
+
}
|
|
51130
|
+
return msg.content.map((part) => part.type === "text" || part.type === "reasoning" ? part.text : "").join("");
|
|
51131
|
+
}).join(`
|
|
51132
|
+
`);
|
|
51133
|
+
await this.#callback({ kind: "EndRequest" /* EndRequest */, agent: this, message: assistantText });
|
|
51091
51134
|
return respMessages.flatMap((msg) => {
|
|
51092
51135
|
if (msg.role === "assistant") {
|
|
51093
51136
|
const content = msg.content;
|
|
@@ -51520,6 +51563,196 @@ var codeFixerAgentInfo = {
|
|
|
51520
51563
|
"Tracking and reporting unfixed issues"
|
|
51521
51564
|
]
|
|
51522
51565
|
};
|
|
51566
|
+
|
|
51567
|
+
// ../core/src/Agent/CoderAgent/prompts.ts
|
|
51568
|
+
var basePrompt2 = "You are a highly skilled software engineer with extensive knowledge in many programming languages, frameworks, design patterns, and best practices.";
|
|
51569
|
+
var editingFilesPrompt = (toolNamePrefix) => `
|
|
51570
|
+
====
|
|
51571
|
+
|
|
51572
|
+
EDITING FILES
|
|
51573
|
+
|
|
51574
|
+
You have two file-manipulation tools: **${toolNamePrefix}write_to_file** (full overwrite) and **${toolNamePrefix}replace_in_file** (targeted anchor-based edits). Choose the smallest safe operation for every change.
|
|
51575
|
+
|
|
51576
|
+
# ${toolNamePrefix}write_to_file
|
|
51577
|
+
|
|
51578
|
+
## Purpose
|
|
51579
|
+
|
|
51580
|
+
- Create a new file, or overwrite the entire contents of an existing file.
|
|
51581
|
+
|
|
51582
|
+
## When to Use
|
|
51583
|
+
|
|
51584
|
+
- Initial file creation, such as when scaffolding a new project.
|
|
51585
|
+
- Overwriting large boilerplate files where you want to replace the entire content at once.
|
|
51586
|
+
- When the complexity or number of changes would make ${toolNamePrefix}replace_in_file unwieldy or error-prone.
|
|
51587
|
+
- When you need to completely restructure a file's content or change its fundamental organization.
|
|
51588
|
+
|
|
51589
|
+
## Important Considerations
|
|
51590
|
+
|
|
51591
|
+
- Using ${toolNamePrefix}write_to_file requires providing the file's complete final content.
|
|
51592
|
+
- If you only need to make small changes to an existing file, consider using ${toolNamePrefix}replace_in_file instead to avoid unnecessarily rewriting the entire file.
|
|
51593
|
+
- While ${toolNamePrefix}write_to_file should not be your default choice, don't hesitate to use it when the situation truly calls for it.
|
|
51594
|
+
|
|
51595
|
+
# ${toolNamePrefix}replace_in_file
|
|
51596
|
+
|
|
51597
|
+
## Purpose
|
|
51598
|
+
|
|
51599
|
+
- Make targeted edits to specific parts of an existing file without overwriting the entire file.
|
|
51600
|
+
|
|
51601
|
+
## When to Use
|
|
51602
|
+
|
|
51603
|
+
- Small, localized changes like updating a few lines, function implementations, changing variable names, modifying a section of text, etc.
|
|
51604
|
+
- Targeted improvements where only specific portions of the file's content needs to be altered.
|
|
51605
|
+
- Especially useful for long files where much of the file will remain unchanged.
|
|
51606
|
+
|
|
51607
|
+
## Advantages
|
|
51608
|
+
|
|
51609
|
+
- More efficient for minor edits, since you don't need to supply the entire file content.
|
|
51610
|
+
- Reduces the chance of errors that can occur when overwriting large files.
|
|
51611
|
+
|
|
51612
|
+
# Choosing the Appropriate Tool
|
|
51613
|
+
|
|
51614
|
+
- **Default to ${toolNamePrefix}replace_in_file** for most changes. It keeps diffs small and reduces risk.
|
|
51615
|
+
- **Use ${toolNamePrefix}write_to_file** when:
|
|
51616
|
+
- Creating new files
|
|
51617
|
+
- The changes are so extensive that using ${toolNamePrefix}replace_in_file would be more complex or risky
|
|
51618
|
+
- You need to completely reorganize or restructure a file
|
|
51619
|
+
- The file is relatively small and the changes affect most of its content
|
|
51620
|
+
- You're generating boilerplate or template files
|
|
51621
|
+
|
|
51622
|
+
# Workflow Tips
|
|
51623
|
+
|
|
51624
|
+
1. Before editing, assess the scope of your changes and decide which tool to use.
|
|
51625
|
+
2. For targeted edits, apply ${toolNamePrefix}replace_in_file with carefully crafted before/after text anchors. If you need multiple changes, you can stack multiple operations within a single ${toolNamePrefix}replace_in_file call.
|
|
51626
|
+
3. For major overhauls or initial file creation, rely on ${toolNamePrefix}write_to_file.
|
|
51627
|
+
4. Once the file has been edited with either ${toolNamePrefix}write_to_file or ${toolNamePrefix}replace_in_file, the system will provide you with the final state of the modified file. Use this updated content as the reference point for any subsequent operations, since it reflects any auto-formatting or user-applied changes.
|
|
51628
|
+
|
|
51629
|
+
Picking the right tool keeps edits minimal, safe, and easy to review.
|
|
51630
|
+
`;
|
|
51631
|
+
var rules = (toolNamePrefix) => `
|
|
51632
|
+
====
|
|
51633
|
+
|
|
51634
|
+
RULES
|
|
51635
|
+
|
|
51636
|
+
- Work only with relative paths; you may \`cd\` into child directories but never use \`cd ..\`, root, or absolute paths.
|
|
51637
|
+
- When generating code, tests, or other comment-capable files, prepend a comment describing the file's purpose plus “generated by polka.codes”.
|
|
51638
|
+
For text files (e.g. README.md), append a footer with the same notice.
|
|
51639
|
+
- Never describe what changed inside code comments; comments must focus on purpose or usage only.
|
|
51640
|
+
- Before using ${toolNamePrefix}execute_command, consider SYSTEM INFORMATION to ensure commands suit the user's OS. If a command must run in a subdirectory, prepend a single \`cd childDir &&\` segment.
|
|
51641
|
+
- Use ${toolNamePrefix}search_files for broad analysis, then ${toolNamePrefix}read_file to inspect context, and finally ${toolNamePrefix}replace_in_file or ${toolNamePrefix}write_to_file to modify.
|
|
51642
|
+
- Prefer ${toolNamePrefix}replace_in_file for focused edits; choose ${toolNamePrefix}write_to_file for new files or complete rewrites.
|
|
51643
|
+
- When creating a new file, look for existing files with similar content or patterns; if found, read them and use their structure or conventions as a reference.
|
|
51644
|
+
- Use before/after text anchors in ${toolNamePrefix}replace_in_file to target changes. If multiple operations are needed, list them in file order.
|
|
51645
|
+
- Do not guess unseen content. Read existing files first unless creating new ones.
|
|
51646
|
+
- Follow existing style, lint, and naming conventions. Ensure all changes compile and pass tests where applicable.
|
|
51647
|
+
- ALWAYS wait for the user's confirmation after each tool call before starting the next step.
|
|
51648
|
+
- The agent must never invoke more than 5 tools in a single response.
|
|
51649
|
+
- Do not end ${toolNamePrefix}attempt_completion output with questions or conversational prompts.
|
|
51650
|
+
- Avoid filler words like “Great”, “Certainly”, “Okay”, “Sure” at the start of responses; be direct and technical.
|
|
51651
|
+
- Keep inline documentation current as you edit.
|
|
51652
|
+
`;
|
|
51653
|
+
var objectives = (toolNamePrefix) => `
|
|
51654
|
+
====
|
|
51655
|
+
|
|
51656
|
+
OBJECTIVE
|
|
51657
|
+
|
|
51658
|
+
You solve the user's task by working in small, verifiable steps.
|
|
51659
|
+
|
|
51660
|
+
1. **Plan** - Parse the task, list clear goals, and order them logically.
|
|
51661
|
+
2. **Think** - Wrap private reasoning in <thinking></thinking>.
|
|
51662
|
+
• Review project context.
|
|
51663
|
+
• Select the single best tool for the next goal.
|
|
51664
|
+
• Ensure every required parameter is available or can be inferred.
|
|
51665
|
+
3. **Act** - Invoke one tool per step. Wait for the system's response (and user confirmation where required) before continuing.
|
|
51666
|
+
4. **Iterate** - Repeat Plan → Think → Act until all goals are complete.
|
|
51667
|
+
5. **Complete** - Use ${toolNamePrefix}attempt_completion to deliver the final result. Do not invite further discussion unless the user explicitly requests changes.
|
|
51668
|
+
`;
|
|
51669
|
+
var fullSystemPrompt4 = (info, tools, toolNamePrefix, instructions, scripts, useNativeTool) => `
|
|
51670
|
+
${basePrompt2}
|
|
51671
|
+
${useNativeTool ? "" : toolUsePrompt(tools, toolNamePrefix)}
|
|
51672
|
+
${editingFilesPrompt(toolNamePrefix)}
|
|
51673
|
+
${capabilities(toolNamePrefix)}
|
|
51674
|
+
${rules(toolNamePrefix)}
|
|
51675
|
+
${objectives(toolNamePrefix)}
|
|
51676
|
+
${systemInformation(info)}
|
|
51677
|
+
${customInstructions(instructions)}
|
|
51678
|
+
${customScripts(scripts)}
|
|
51679
|
+
`;
|
|
51680
|
+
|
|
51681
|
+
// ../core/src/Agent/CoderAgent/index.ts
|
|
51682
|
+
class CoderAgent extends AgentBase {
|
|
51683
|
+
constructor(options) {
|
|
51684
|
+
const combinedTools = [...options.additionalTools ?? [], ...Object.values(exports_allTools)];
|
|
51685
|
+
const tools = getAvailableTools({
|
|
51686
|
+
provider: options.provider,
|
|
51687
|
+
allTools: combinedTools,
|
|
51688
|
+
hasAgent: (options.agents?.length ?? 0) > 0,
|
|
51689
|
+
permissionLevel: 3 /* Arbitrary */,
|
|
51690
|
+
interactive: true
|
|
51691
|
+
});
|
|
51692
|
+
const toolNamePrefix = options.toolFormat === "native" ? "" : "tool_";
|
|
51693
|
+
const systemPrompt = fullSystemPrompt4({
|
|
51694
|
+
os: options.os
|
|
51695
|
+
}, tools, toolNamePrefix, options.customInstructions ?? [], options.scripts ?? {}, options.toolFormat === "native");
|
|
51696
|
+
super(coderAgentInfo.name, options.ai, {
|
|
51697
|
+
systemPrompt,
|
|
51698
|
+
tools,
|
|
51699
|
+
toolNamePrefix,
|
|
51700
|
+
provider: options.provider,
|
|
51701
|
+
interactive: options.interactive,
|
|
51702
|
+
agents: options.agents,
|
|
51703
|
+
scripts: options.scripts,
|
|
51704
|
+
callback: options.callback,
|
|
51705
|
+
policies: options.policies,
|
|
51706
|
+
toolFormat: options.toolFormat,
|
|
51707
|
+
parameters: options.parameters ?? {},
|
|
51708
|
+
usageMeter: options.usageMeter ?? new UsageMeter
|
|
51709
|
+
});
|
|
51710
|
+
}
|
|
51711
|
+
async#runScript(scriptName, shouldReplyWithError) {
|
|
51712
|
+
const executeCommand = this.config.provider.executeCommand;
|
|
51713
|
+
if (!executeCommand) {
|
|
51714
|
+
return;
|
|
51715
|
+
}
|
|
51716
|
+
const script = this.config.scripts?.[scriptName];
|
|
51717
|
+
const command = typeof script === "string" ? script : script?.command;
|
|
51718
|
+
if (command) {
|
|
51719
|
+
try {
|
|
51720
|
+
const { exitCode, stdout, stderr } = await executeCommand(command, false);
|
|
51721
|
+
if (exitCode !== 0 && shouldReplyWithError) {
|
|
51722
|
+
return {
|
|
51723
|
+
type: "Reply" /* Reply */,
|
|
51724
|
+
message: responsePrompts.commandResult(command, exitCode, stdout, stderr)
|
|
51725
|
+
};
|
|
51726
|
+
}
|
|
51727
|
+
} catch (error81) {
|
|
51728
|
+
console.warn(`Failed to run ${scriptName} using command: ${command}`, error81);
|
|
51729
|
+
}
|
|
51730
|
+
}
|
|
51731
|
+
}
|
|
51732
|
+
async onBeforeInvokeTool(name17, _args) {
|
|
51733
|
+
if (name17 !== attemptCompletion_default.name) {
|
|
51734
|
+
return;
|
|
51735
|
+
}
|
|
51736
|
+
await this.#runScript("format", false);
|
|
51737
|
+
const checkResult = await this.#runScript("check", true);
|
|
51738
|
+
if (checkResult) {
|
|
51739
|
+
return checkResult;
|
|
51740
|
+
}
|
|
51741
|
+
const testResult = await this.#runScript("test", true);
|
|
51742
|
+
if (testResult) {
|
|
51743
|
+
return testResult;
|
|
51744
|
+
}
|
|
51745
|
+
}
|
|
51746
|
+
}
|
|
51747
|
+
var coderAgentInfo = {
|
|
51748
|
+
name: "coder",
|
|
51749
|
+
responsibilities: [
|
|
51750
|
+
"Editing and refactoring existing code.",
|
|
51751
|
+
"Creating new features or modules.",
|
|
51752
|
+
"Running tests and analyzing test results.",
|
|
51753
|
+
"Maintaining coding standards, lint rules, and general code quality."
|
|
51754
|
+
]
|
|
51755
|
+
};
|
|
51523
51756
|
// ../core/src/Agent/MultiAgent.ts
|
|
51524
51757
|
class MultiAgent {
|
|
51525
51758
|
#config;
|
|
@@ -51865,10 +52098,18 @@ Example Output:
|
|
|
51865
52098
|
<tool_output>
|
|
51866
52099
|
<tool_output_pr_title>Refactor Order Validation and Remove Debug Logs</tool_output_pr_title>
|
|
51867
52100
|
<tool_output_pr_description>
|
|
51868
|
-
|
|
52101
|
+
Closes #123
|
|
52102
|
+
|
|
52103
|
+
**Context**:
|
|
52104
|
+
- Implementing changes for issue #123 - Focus on clean code and maintainability
|
|
51869
52105
|
|
|
51870
|
-
|
|
51871
|
-
to use
|
|
52106
|
+
**Summary of Changes**:
|
|
52107
|
+
- Refactored order validation logic to use a new \`validate_and_process\` method.
|
|
52108
|
+
- Removed debug print statements from \`user_service.py\`.
|
|
52109
|
+
|
|
52110
|
+
**Highlights of Changed Code**:
|
|
52111
|
+
- \`order_service.py\`: Replaced direct call to \`process_order\` with \`validate_and_process\`.
|
|
52112
|
+
- \`user_service.py\`: Removed \`print("Debug info")\`.
|
|
51872
52113
|
</tool_output_pr_description>
|
|
51873
52114
|
</tool_output>
|
|
51874
52115
|
|
|
@@ -52169,6 +52410,7 @@ ${output}`,
|
|
|
52169
52410
|
var executeTool = async (definition, ai, params, usageMeter) => {
|
|
52170
52411
|
const resp = await generateText({
|
|
52171
52412
|
model: ai,
|
|
52413
|
+
temperature: 0,
|
|
52172
52414
|
system: definition.prompt,
|
|
52173
52415
|
messages: [
|
|
52174
52416
|
{
|
|
@@ -57530,13 +57772,16 @@ async function extendPatterns(basePatterns, dirPath) {
|
|
|
57530
57772
|
function createIgnore(patterns) {
|
|
57531
57773
|
return import_ignore.default().add(patterns);
|
|
57532
57774
|
}
|
|
57533
|
-
async function listFiles(dirPath, recursive, maxCount, cwd, excludeFiles) {
|
|
57534
|
-
let rootPatterns = [...
|
|
57535
|
-
|
|
57536
|
-
|
|
57537
|
-
|
|
57538
|
-
|
|
57539
|
-
|
|
57775
|
+
async function listFiles(dirPath, recursive, maxCount, cwd, excludeFiles, includeIgnored) {
|
|
57776
|
+
let rootPatterns = [...excludeFiles || []];
|
|
57777
|
+
if (!includeIgnored) {
|
|
57778
|
+
rootPatterns.push(...DEFAULT_IGNORES);
|
|
57779
|
+
try {
|
|
57780
|
+
const rootGitignore = await fs.readFile(join2(cwd, ".gitignore"), "utf8");
|
|
57781
|
+
const lines = rootGitignore.split(/\r?\n/).filter(Boolean);
|
|
57782
|
+
rootPatterns = [...rootPatterns, ...lines];
|
|
57783
|
+
} catch {}
|
|
57784
|
+
}
|
|
57540
57785
|
const results = [];
|
|
57541
57786
|
const processedDirs = new Set;
|
|
57542
57787
|
const queue = [
|
|
@@ -57549,7 +57794,7 @@ async function listFiles(dirPath, recursive, maxCount, cwd, excludeFiles) {
|
|
|
57549
57794
|
while (queue.length > 0) {
|
|
57550
57795
|
const { path: currentPath, patterns: parentPatterns, relPath: currentRelPath } = queue.shift();
|
|
57551
57796
|
processedDirs.add(currentRelPath);
|
|
57552
|
-
const mergedPatterns = await extendPatterns(parentPatterns, currentPath);
|
|
57797
|
+
const mergedPatterns = includeIgnored ? parentPatterns : await extendPatterns(parentPatterns, currentPath);
|
|
57553
57798
|
const folderIg = createIgnore(mergedPatterns);
|
|
57554
57799
|
const entries = await fs.readdir(currentPath, { withFileTypes: true });
|
|
57555
57800
|
entries.sort((a, b) => a.name.localeCompare(b.name));
|
|
@@ -57645,8 +57890,8 @@ async function searchFiles(path, regex, filePattern, cwd, excludeFiles) {
|
|
|
57645
57890
|
var getProvider = (_agentName, _config, options = {}) => {
|
|
57646
57891
|
const ig = import_ignore2.default().add(options.excludeFiles ?? []);
|
|
57647
57892
|
const provider2 = {
|
|
57648
|
-
readFile: async (path) => {
|
|
57649
|
-
if (ig.ignores(path)) {
|
|
57893
|
+
readFile: async (path, includeIgnored) => {
|
|
57894
|
+
if (!includeIgnored && ig.ignores(path)) {
|
|
57650
57895
|
throw new Error(`Not allow to access file ${path}`);
|
|
57651
57896
|
}
|
|
57652
57897
|
try {
|
|
@@ -57674,8 +57919,8 @@ var getProvider = (_agentName, _config, options = {}) => {
|
|
|
57674
57919
|
}
|
|
57675
57920
|
return await rename(sourcePath, targetPath);
|
|
57676
57921
|
},
|
|
57677
|
-
listFiles: async (path, recursive, maxCount) => {
|
|
57678
|
-
return await listFiles(path, recursive, maxCount, process.cwd(), options.excludeFiles);
|
|
57922
|
+
listFiles: async (path, recursive, maxCount, includeIgnored) => {
|
|
57923
|
+
return await listFiles(path, recursive, maxCount, process.cwd(), options.excludeFiles, includeIgnored);
|
|
57679
57924
|
},
|
|
57680
57925
|
executeCommand: (command, _needApprove) => {
|
|
57681
57926
|
return new Promise((resolve3, reject) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polka-codes/cli-shared",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.6",
|
|
4
4
|
"license": "AGPL-3.0",
|
|
5
5
|
"author": "github@polka.codes",
|
|
6
6
|
"type": "module",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"build": "bun build src/index.ts --outdir dist --target node"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@polka-codes/core": "0.9.
|
|
20
|
+
"@polka-codes/core": "0.9.4",
|
|
21
21
|
"ignore": "^7.0.3",
|
|
22
22
|
"lodash": "^4.17.21",
|
|
23
23
|
"yaml": "^2.7.0",
|