@polka-codes/core 0.8.25 → 0.8.27
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/_tsup-dts-rollup.d.ts +21 -1
- package/dist/index.js +66 -54
- package/package.json +1 -1
|
@@ -54,6 +54,8 @@ declare type AgentBaseConfig = {
|
|
|
54
54
|
}>;
|
|
55
55
|
callback?: TaskEventCallback;
|
|
56
56
|
policies: AgentPolicy[];
|
|
57
|
+
retryCount?: number;
|
|
58
|
+
requestTimeoutSeconds?: number;
|
|
57
59
|
};
|
|
58
60
|
export { AgentBaseConfig }
|
|
59
61
|
export { AgentBaseConfig as AgentBaseConfig_alias_1 }
|
|
@@ -482,6 +484,8 @@ declare const configSchema: z.ZodObject<{
|
|
|
482
484
|
defaultParameters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
483
485
|
maxMessageCount: z.ZodOptional<z.ZodNumber>;
|
|
484
486
|
budget: z.ZodOptional<z.ZodNumber>;
|
|
487
|
+
retryCount: z.ZodOptional<z.ZodNumber>;
|
|
488
|
+
requestTimeoutSeconds: z.ZodOptional<z.ZodNumber>;
|
|
485
489
|
scripts: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodObject<{
|
|
486
490
|
command: z.ZodString;
|
|
487
491
|
description: z.ZodString;
|
|
@@ -507,6 +511,8 @@ declare const configSchema: z.ZodObject<{
|
|
|
507
511
|
maxFileCount?: number | undefined;
|
|
508
512
|
excludes?: string[] | undefined;
|
|
509
513
|
}>>;
|
|
514
|
+
retryCount: z.ZodOptional<z.ZodNumber>;
|
|
515
|
+
requestTimeoutSeconds: z.ZodOptional<z.ZodNumber>;
|
|
510
516
|
}>, "strip", z.ZodTypeAny, {
|
|
511
517
|
provider?: string | undefined;
|
|
512
518
|
model?: string | undefined;
|
|
@@ -515,6 +521,8 @@ declare const configSchema: z.ZodObject<{
|
|
|
515
521
|
maxFileCount?: number | undefined;
|
|
516
522
|
excludes?: string[] | undefined;
|
|
517
523
|
} | undefined;
|
|
524
|
+
retryCount?: number | undefined;
|
|
525
|
+
requestTimeoutSeconds?: number | undefined;
|
|
518
526
|
}, {
|
|
519
527
|
provider?: string | undefined;
|
|
520
528
|
model?: string | undefined;
|
|
@@ -523,6 +531,8 @@ declare const configSchema: z.ZodObject<{
|
|
|
523
531
|
maxFileCount?: number | undefined;
|
|
524
532
|
excludes?: string[] | undefined;
|
|
525
533
|
} | undefined;
|
|
534
|
+
retryCount?: number | undefined;
|
|
535
|
+
requestTimeoutSeconds?: number | undefined;
|
|
526
536
|
}>>>;
|
|
527
537
|
commands: z.ZodOptional<z.ZodObject<{
|
|
528
538
|
default: z.ZodOptional<z.ZodObject<{
|
|
@@ -607,6 +617,8 @@ declare const configSchema: z.ZodObject<{
|
|
|
607
617
|
excludeFiles: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
608
618
|
policies: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
609
619
|
}, "strict", z.ZodTypeAny, {
|
|
620
|
+
retryCount?: number | undefined;
|
|
621
|
+
requestTimeoutSeconds?: number | undefined;
|
|
610
622
|
agent?: string | undefined;
|
|
611
623
|
prices?: Record<string, Record<string, {
|
|
612
624
|
inputPrice?: number | undefined;
|
|
@@ -636,6 +648,8 @@ declare const configSchema: z.ZodObject<{
|
|
|
636
648
|
maxFileCount?: number | undefined;
|
|
637
649
|
excludes?: string[] | undefined;
|
|
638
650
|
} | undefined;
|
|
651
|
+
retryCount?: number | undefined;
|
|
652
|
+
requestTimeoutSeconds?: number | undefined;
|
|
639
653
|
}> | undefined;
|
|
640
654
|
commands?: z.objectOutputType<{
|
|
641
655
|
default: z.ZodOptional<z.ZodObject<{
|
|
@@ -668,6 +682,8 @@ declare const configSchema: z.ZodObject<{
|
|
|
668
682
|
excludeFiles?: string[] | undefined;
|
|
669
683
|
policies?: string[] | undefined;
|
|
670
684
|
}, {
|
|
685
|
+
retryCount?: number | undefined;
|
|
686
|
+
requestTimeoutSeconds?: number | undefined;
|
|
671
687
|
agent?: string | undefined;
|
|
672
688
|
prices?: Record<string, Record<string, {
|
|
673
689
|
inputPrice?: number | undefined;
|
|
@@ -697,6 +713,8 @@ declare const configSchema: z.ZodObject<{
|
|
|
697
713
|
maxFileCount?: number | undefined;
|
|
698
714
|
excludes?: string[] | undefined;
|
|
699
715
|
} | undefined;
|
|
716
|
+
retryCount?: number | undefined;
|
|
717
|
+
requestTimeoutSeconds?: number | undefined;
|
|
700
718
|
}> | undefined;
|
|
701
719
|
commands?: z.objectInputType<{
|
|
702
720
|
default: z.ZodOptional<z.ZodObject<{
|
|
@@ -1910,7 +1928,7 @@ export declare const default_alias_2: {
|
|
|
1910
1928
|
export declare const default_alias_3: {
|
|
1911
1929
|
readonly name: "generateProjectConfig";
|
|
1912
1930
|
readonly description: "Analyzes project files to generate polkacodes config sections";
|
|
1913
|
-
readonly prompt: "
|
|
1931
|
+
readonly prompt: "\nRole: Analyzer agent\nGoal: Produce a valid polkacodes YAML configuration for the project.\n\nWorkflow\n1. Scan project files with tool_read_file and identify:\n - Package/build tool (npm, bun, pnpm, etc.)\n - Test framework and patterns (snapshot tests, coverage, etc.)\n - Formatter / linter and their rules\n - Folder structure and naming conventions\n - CI / development workflows\n\n2. Build a YAML config with three root keys:\n\n```yaml\nscripts: # derive from package.json and CI\n format: # code formatter\n command: \"<formatter cmd>\"\n description: \"Format code\"\n check: # linter / type checker\n command: \"<linter cmd>\"\n description: \"Static checks\"\n test: # test runner\n command: \"<test cmd>\"\n description: \"Run tests\"\n # add any other meaningful project scripts\n\nrules: # bullet list of key conventions/tools\n\nexcludeFiles: # only files likely to hold secrets\n - \".env\"\n - \".env.*\"\n - \".npmrc\"\n # do NOT list build artifacts, lockfiles, or paths already in .gitignore\n```\n\n3. Return the YAML exactly once, wrapped like:\n\n<tool_attempt_completion>\n<tool_parameter_result>\n# YAML (2-space indents, double-quoted commands)\n</tool_parameter_result>\n</tool_attempt_completion>\n";
|
|
1914
1932
|
readonly formatInput: () => string;
|
|
1915
1933
|
readonly parseOutput: (output: string) => string;
|
|
1916
1934
|
readonly agent: "analyzer";
|
|
@@ -2655,6 +2673,8 @@ declare type SharedAgentOptions = {
|
|
|
2655
2673
|
agents?: Readonly<AgentInfo[]>;
|
|
2656
2674
|
callback?: TaskEventCallback;
|
|
2657
2675
|
policies: AgentPolicy[];
|
|
2676
|
+
retryCount?: number;
|
|
2677
|
+
requestTimeoutSeconds?: number;
|
|
2658
2678
|
};
|
|
2659
2679
|
export { SharedAgentOptions }
|
|
2660
2680
|
export { SharedAgentOptions as SharedAgentOptions_alias_1 }
|
package/dist/index.js
CHANGED
|
@@ -1805,14 +1805,18 @@ var handler8 = async (provider, args) => {
|
|
|
1805
1805
|
if (result.status === "no_diff_applied") {
|
|
1806
1806
|
return {
|
|
1807
1807
|
type: "Error" /* Error */,
|
|
1808
|
-
message: `<replace_in_file_result path="${path}" status="failed" message="Unable to apply changes"
|
|
1808
|
+
message: `<replace_in_file_result path="${path}" status="failed" message="Unable to apply changes">
|
|
1809
|
+
<file_content path="${path}">${fileContent}</file_content>
|
|
1810
|
+
</replace_in_file_result>`
|
|
1809
1811
|
};
|
|
1810
1812
|
}
|
|
1811
1813
|
await provider.writeFile(path, result.content);
|
|
1812
1814
|
if (result.status === "some_diff_applied") {
|
|
1813
1815
|
return {
|
|
1814
1816
|
type: "Reply" /* Reply */,
|
|
1815
|
-
message: `<replace_in_file_result path="${path}" status="some_diff_applied" applied_count="${result.appliedCount}" total_count="${result.totalCount}"
|
|
1817
|
+
message: `<replace_in_file_result path="${path}" status="some_diff_applied" applied_count="${result.appliedCount}" total_count="${result.totalCount}">
|
|
1818
|
+
<file_content path="${path}">${result.content}</file_content>
|
|
1819
|
+
</replace_in_file_result>`
|
|
1816
1820
|
};
|
|
1817
1821
|
}
|
|
1818
1822
|
return {
|
|
@@ -2984,12 +2988,27 @@ ${instance.prompt}`;
|
|
|
2984
2988
|
}
|
|
2985
2989
|
}
|
|
2986
2990
|
let currentAssistantMessage = "";
|
|
2987
|
-
const retryCount = 5;
|
|
2991
|
+
const retryCount = this.config.retryCount ?? 5;
|
|
2992
|
+
const requestTimeoutSeconds = this.config.requestTimeoutSeconds ?? 10;
|
|
2988
2993
|
for (let i = 0; i < retryCount; i++) {
|
|
2989
2994
|
currentAssistantMessage = "";
|
|
2995
|
+
let timeout;
|
|
2996
|
+
const resetTimeout = () => {
|
|
2997
|
+
if (timeout) {
|
|
2998
|
+
clearTimeout(timeout);
|
|
2999
|
+
}
|
|
3000
|
+
if (requestTimeoutSeconds > 0) {
|
|
3001
|
+
timeout = setTimeout(() => {
|
|
3002
|
+
console.debug(`No data received for ${requestTimeoutSeconds} seconds. Aborting request.`);
|
|
3003
|
+
this.ai.abort();
|
|
3004
|
+
}, requestTimeoutSeconds * 1e3);
|
|
3005
|
+
}
|
|
3006
|
+
};
|
|
2990
3007
|
const stream = this.ai.send(this.config.systemPrompt, this.#messages);
|
|
2991
3008
|
try {
|
|
3009
|
+
resetTimeout();
|
|
2992
3010
|
for await (const chunk of stream) {
|
|
3011
|
+
resetTimeout();
|
|
2993
3012
|
switch (chunk.type) {
|
|
2994
3013
|
case "usage":
|
|
2995
3014
|
await this.#callback({ kind: "Usage" /* Usage */, agent: this });
|
|
@@ -3008,6 +3027,10 @@ ${instance.prompt}`;
|
|
|
3008
3027
|
break;
|
|
3009
3028
|
}
|
|
3010
3029
|
console.error("Error in stream:", error);
|
|
3030
|
+
} finally {
|
|
3031
|
+
if (timeout) {
|
|
3032
|
+
clearTimeout(timeout);
|
|
3033
|
+
}
|
|
3011
3034
|
}
|
|
3012
3035
|
if (currentAssistantMessage) {
|
|
3013
3036
|
break;
|
|
@@ -3793,7 +3816,9 @@ var agentSchema = providerModelSchema.extend({
|
|
|
3793
3816
|
initialContext: z.object({
|
|
3794
3817
|
maxFileCount: z.number().int().positive().optional(),
|
|
3795
3818
|
excludes: z.array(z.string()).optional()
|
|
3796
|
-
}).optional()
|
|
3819
|
+
}).optional(),
|
|
3820
|
+
retryCount: z.number().int().min(0).optional(),
|
|
3821
|
+
requestTimeoutSeconds: z.number().int().positive().optional()
|
|
3797
3822
|
});
|
|
3798
3823
|
var configSchema = z.object({
|
|
3799
3824
|
agent: z.string().optional(),
|
|
@@ -3824,6 +3849,8 @@ var configSchema = z.object({
|
|
|
3824
3849
|
defaultParameters: z.record(z.string(), z.any()).optional(),
|
|
3825
3850
|
maxMessageCount: z.number().int().positive().optional(),
|
|
3826
3851
|
budget: z.number().positive().optional(),
|
|
3852
|
+
retryCount: z.number().int().min(0).optional(),
|
|
3853
|
+
requestTimeoutSeconds: z.number().int().positive().optional(),
|
|
3827
3854
|
scripts: z.record(
|
|
3828
3855
|
z.string(),
|
|
3829
3856
|
z.string().or(
|
|
@@ -4319,64 +4346,49 @@ ${output}`);
|
|
|
4319
4346
|
};
|
|
4320
4347
|
|
|
4321
4348
|
// src/AiTool/generateProjectConfig.ts
|
|
4322
|
-
var prompt5 = `
|
|
4323
|
-
|
|
4324
|
-
|
|
4325
|
-
- Build tools and package manager (e.g., bun, npm)
|
|
4326
|
-
- Testing frameworks and patterns
|
|
4327
|
-
- Code style tools and rules
|
|
4328
|
-
- Project structure and conventions
|
|
4329
|
-
- Common development workflows
|
|
4330
|
-
|
|
4331
|
-
2. Generate a YAML configuration that captures:
|
|
4332
|
-
- scripts section based on package.json scripts and CI workflows. If applicable, generate following scripts:
|
|
4333
|
-
- format: Format the code using a code formatter tool
|
|
4334
|
-
- check: Check the code for errors using a linter tool
|
|
4335
|
-
- test: Run tests using a test runner tool
|
|
4336
|
-
- include other relevant scripts based on project conventions, tools, and patterns
|
|
4337
|
-
- rules section based on project conventions, tools, and patterns
|
|
4338
|
-
- excludeFiles section for sensitive files
|
|
4339
|
-
|
|
4340
|
-
3. Use tool_attempt_completion to return the final configuration in this format:
|
|
4349
|
+
var prompt5 = `
|
|
4350
|
+
Role: Analyzer agent
|
|
4351
|
+
Goal: Produce a valid polkacodes YAML configuration for the project.
|
|
4341
4352
|
|
|
4342
|
-
|
|
4343
|
-
|
|
4344
|
-
|
|
4345
|
-
|
|
4346
|
-
|
|
4347
|
-
|
|
4348
|
-
|
|
4349
|
-
command: "biome check ."
|
|
4350
|
-
description: "Check code style with Biome"
|
|
4353
|
+
Workflow
|
|
4354
|
+
1. Scan project files with tool_read_file and identify:
|
|
4355
|
+
- Package/build tool (npm, bun, pnpm, etc.)
|
|
4356
|
+
- Test framework and patterns (snapshot tests, coverage, etc.)
|
|
4357
|
+
- Formatter / linter and their rules
|
|
4358
|
+
- Folder structure and naming conventions
|
|
4359
|
+
- CI / development workflows
|
|
4351
4360
|
|
|
4352
|
-
|
|
4353
|
-
- "Use \`bun\` as package manager"
|
|
4354
|
-
- "Write tests using bun:test with snapshots"
|
|
4355
|
-
- "Follow Biome code style"
|
|
4361
|
+
2. Build a YAML config with three root keys:
|
|
4356
4362
|
|
|
4357
|
-
|
|
4358
|
-
|
|
4363
|
+
\`\`\`yaml
|
|
4364
|
+
scripts: # derive from package.json and CI
|
|
4365
|
+
format: # code formatter
|
|
4366
|
+
command: "<formatter cmd>"
|
|
4367
|
+
description: "Format code"
|
|
4368
|
+
check: # linter / type checker
|
|
4369
|
+
command: "<linter cmd>"
|
|
4370
|
+
description: "Static checks"
|
|
4371
|
+
test: # test runner
|
|
4372
|
+
command: "<test cmd>"
|
|
4373
|
+
description: "Run tests"
|
|
4374
|
+
# add any other meaningful project scripts
|
|
4375
|
+
|
|
4376
|
+
rules: # bullet list of key conventions/tools
|
|
4377
|
+
|
|
4378
|
+
excludeFiles: # only files likely to hold secrets
|
|
4359
4379
|
- ".env"
|
|
4360
4380
|
- ".env.*"
|
|
4361
4381
|
- ".npmrc"
|
|
4382
|
+
# do NOT list build artifacts, lockfiles, or paths already in .gitignore
|
|
4383
|
+
\`\`\`
|
|
4384
|
+
|
|
4385
|
+
3. Return the YAML exactly once, wrapped like:
|
|
4386
|
+
|
|
4387
|
+
<tool_attempt_completion>
|
|
4388
|
+
<tool_parameter_result>
|
|
4389
|
+
# YAML (2-space indents, double-quoted commands)
|
|
4362
4390
|
</tool_parameter_result>
|
|
4363
4391
|
</tool_attempt_completion>
|
|
4364
|
-
|
|
4365
|
-
Focus on:
|
|
4366
|
-
- Package manager and dependency management
|
|
4367
|
-
- Testing frameworks and patterns
|
|
4368
|
-
- Code style and linting rules
|
|
4369
|
-
- File organization and naming conventions
|
|
4370
|
-
- Build and development workflows
|
|
4371
|
-
- Sensitive files that should not be committed:
|
|
4372
|
-
- Environment files (.env*)
|
|
4373
|
-
- Configuration files with potential secrets
|
|
4374
|
-
- Generated files to exclude:
|
|
4375
|
-
- Lock files from package managers
|
|
4376
|
-
- Build artifacts and outputs
|
|
4377
|
-
- Generated file that are not ignored by .gitignore
|
|
4378
|
-
|
|
4379
|
-
The configuration should accurately reflect the project's structure, tools, and conventions.
|
|
4380
4392
|
`;
|
|
4381
4393
|
var generateProjectConfig_default = {
|
|
4382
4394
|
name: "generateProjectConfig",
|