@polka-codes/core 0.9.33 → 0.9.34
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 +31 -71
- package/dist/index.d.ts +1 -2
- package/dist/index.js +79 -233
- package/package.json +1 -1
|
@@ -71,8 +71,6 @@ export { AgentBaseConfig as AgentBaseConfig_alias_1 }
|
|
|
71
71
|
export { AgentBaseConfig as AgentBaseConfig_alias_2 }
|
|
72
72
|
|
|
73
73
|
declare type AgentContextParameters = {
|
|
74
|
-
budget?: number;
|
|
75
|
-
maxMessages?: number;
|
|
76
74
|
toolFormat?: ToolFormat;
|
|
77
75
|
os?: string;
|
|
78
76
|
policies?: AgentPolicy[];
|
|
@@ -81,6 +79,9 @@ declare type AgentContextParameters = {
|
|
|
81
79
|
command: string;
|
|
82
80
|
description: string;
|
|
83
81
|
}>;
|
|
82
|
+
retryCount?: number;
|
|
83
|
+
requestTimeoutSeconds?: number;
|
|
84
|
+
usageMeter?: UsageMeter;
|
|
84
85
|
};
|
|
85
86
|
export { AgentContextParameters }
|
|
86
87
|
export { AgentContextParameters as AgentContextParameters_alias_1 }
|
|
@@ -124,11 +125,9 @@ declare type AgentStepSpec<TInput extends Record<string, Json> = Record<string,
|
|
|
124
125
|
type: 'agent';
|
|
125
126
|
messages: (UserContent_2 | TemplatedString<TInput>)[];
|
|
126
127
|
outputSchema?: z.ZodType<TOutput>;
|
|
127
|
-
parseOutput?: (raw: string) => TOutput
|
|
128
|
+
parseOutput?: (raw: string) => ParseOutputResult<TOutput>;
|
|
128
129
|
provider?: string;
|
|
129
130
|
model?: string;
|
|
130
|
-
budget?: number;
|
|
131
|
-
maxMessages?: number;
|
|
132
131
|
modelParameters?: Record<string, any>;
|
|
133
132
|
toolFormat?: ToolFormat;
|
|
134
133
|
agent?: AgentNameType;
|
|
@@ -483,7 +482,7 @@ declare const _default: {
|
|
|
483
482
|
};
|
|
484
483
|
export { _default as askFollowupQuestion }
|
|
485
484
|
export { _default as askFollowupQuestion_alias_1 }
|
|
486
|
-
export { _default as
|
|
485
|
+
export { _default as default_alias_2 }
|
|
487
486
|
|
|
488
487
|
declare const _default_10: {
|
|
489
488
|
handler: ToolHandler<{
|
|
@@ -500,7 +499,7 @@ declare const _default_10: {
|
|
|
500
499
|
path: z.ZodString;
|
|
501
500
|
}, z.core.$strip>;
|
|
502
501
|
};
|
|
503
|
-
export { _default_10 as
|
|
502
|
+
export { _default_10 as default_alias_11 }
|
|
504
503
|
export { _default_10 as removeFile }
|
|
505
504
|
export { _default_10 as removeFile_alias_1 }
|
|
506
505
|
|
|
@@ -521,7 +520,7 @@ declare const _default_11: {
|
|
|
521
520
|
target_path: z.ZodString;
|
|
522
521
|
}, z.core.$strip>;
|
|
523
522
|
};
|
|
524
|
-
export { _default_11 as
|
|
523
|
+
export { _default_11 as default_alias_12 }
|
|
525
524
|
export { _default_11 as renameFile }
|
|
526
525
|
export { _default_11 as renameFile_alias_1 }
|
|
527
526
|
|
|
@@ -542,7 +541,7 @@ declare const _default_12: {
|
|
|
542
541
|
diff: z.ZodString;
|
|
543
542
|
}, z.core.$strip>;
|
|
544
543
|
};
|
|
545
|
-
export { _default_12 as
|
|
544
|
+
export { _default_12 as default_alias_13 }
|
|
546
545
|
export { _default_12 as replaceInFile }
|
|
547
546
|
export { _default_12 as replaceInFile_alias_1 }
|
|
548
547
|
|
|
@@ -565,7 +564,7 @@ declare const _default_13: {
|
|
|
565
564
|
filePattern: z.ZodOptional<z.ZodString>;
|
|
566
565
|
}, z.core.$strip>;
|
|
567
566
|
};
|
|
568
|
-
export { _default_13 as
|
|
567
|
+
export { _default_13 as default_alias_14 }
|
|
569
568
|
export { _default_13 as searchFiles }
|
|
570
569
|
export { _default_13 as searchFiles_alias_1 }
|
|
571
570
|
|
|
@@ -586,7 +585,7 @@ declare const _default_14: {
|
|
|
586
585
|
content: z.ZodString;
|
|
587
586
|
}, z.core.$strip>;
|
|
588
587
|
};
|
|
589
|
-
export { _default_14 as
|
|
588
|
+
export { _default_14 as default_alias_15 }
|
|
590
589
|
export { _default_14 as writeToFile }
|
|
591
590
|
export { _default_14 as writeToFile_alias_1 }
|
|
592
591
|
|
|
@@ -607,7 +606,7 @@ declare const _default_2: {
|
|
|
607
606
|
};
|
|
608
607
|
export { _default_2 as attemptCompletion }
|
|
609
608
|
export { _default_2 as attemptCompletion_alias_1 }
|
|
610
|
-
export { _default_2 as
|
|
609
|
+
export { _default_2 as default_alias_3 }
|
|
611
610
|
|
|
612
611
|
declare const _default_3: {
|
|
613
612
|
handler: ToolHandler<{
|
|
@@ -630,7 +629,7 @@ declare const _default_3: {
|
|
|
630
629
|
files: z.ZodOptional<z.ZodPipe<z.ZodTransform<string[], unknown>, z.ZodArray<z.ZodString>>>;
|
|
631
630
|
}, z.core.$strip>;
|
|
632
631
|
};
|
|
633
|
-
export { _default_3 as
|
|
632
|
+
export { _default_3 as default_alias_4 }
|
|
634
633
|
export { _default_3 as delegate }
|
|
635
634
|
export { _default_3 as delegate_alias_1 }
|
|
636
635
|
|
|
@@ -651,7 +650,7 @@ declare const _default_4: {
|
|
|
651
650
|
requiresApproval: z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodDefault<z.ZodOptional<z.ZodBoolean>>>;
|
|
652
651
|
}, z.core.$strip>;
|
|
653
652
|
};
|
|
654
|
-
export { _default_4 as
|
|
653
|
+
export { _default_4 as default_alias_5 }
|
|
655
654
|
export { _default_4 as executeCommand }
|
|
656
655
|
export { _default_4 as executeCommand_alias_1 }
|
|
657
656
|
|
|
@@ -670,7 +669,7 @@ declare const _default_5: {
|
|
|
670
669
|
url: z.ZodPipe<z.ZodTransform<string[], unknown>, z.ZodArray<z.ZodString>>;
|
|
671
670
|
}, z.core.$strip>;
|
|
672
671
|
};
|
|
673
|
-
export { _default_5 as
|
|
672
|
+
export { _default_5 as default_alias_6 }
|
|
674
673
|
export { _default_5 as fetchUrl }
|
|
675
674
|
export { _default_5 as fetchUrl_alias_1 }
|
|
676
675
|
|
|
@@ -695,7 +694,7 @@ declare const _default_6: {
|
|
|
695
694
|
files: z.ZodOptional<z.ZodPipe<z.ZodTransform<string[], unknown>, z.ZodArray<z.ZodString>>>;
|
|
696
695
|
}, z.core.$strip>;
|
|
697
696
|
};
|
|
698
|
-
export { _default_6 as
|
|
697
|
+
export { _default_6 as default_alias_7 }
|
|
699
698
|
export { _default_6 as handOver }
|
|
700
699
|
export { _default_6 as handOver_alias_1 }
|
|
701
700
|
|
|
@@ -720,7 +719,7 @@ declare const _default_7: {
|
|
|
720
719
|
includeIgnored: z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodDefault<z.ZodOptional<z.ZodBoolean>>>;
|
|
721
720
|
}, z.core.$strip>;
|
|
722
721
|
};
|
|
723
|
-
export { _default_7 as
|
|
722
|
+
export { _default_7 as default_alias_8 }
|
|
724
723
|
export { _default_7 as listFiles }
|
|
725
724
|
export { _default_7 as listFiles_alias_1 }
|
|
726
725
|
|
|
@@ -739,7 +738,7 @@ declare const _default_8: {
|
|
|
739
738
|
url: z.ZodString;
|
|
740
739
|
}, z.core.$strip>;
|
|
741
740
|
};
|
|
742
|
-
export { _default_8 as
|
|
741
|
+
export { _default_8 as default_alias_9 }
|
|
743
742
|
export { _default_8 as readBinaryFile }
|
|
744
743
|
export { _default_8 as readBinaryFile_alias_1 }
|
|
745
744
|
|
|
@@ -760,7 +759,7 @@ declare const _default_9: {
|
|
|
760
759
|
includeIgnored: z.ZodPipe<z.ZodTransform<unknown, unknown>, z.ZodDefault<z.ZodOptional<z.ZodBoolean>>>;
|
|
761
760
|
}, z.core.$strip>;
|
|
762
761
|
};
|
|
763
|
-
export { _default_9 as
|
|
762
|
+
export { _default_9 as default_alias_10 }
|
|
764
763
|
export { _default_9 as readFile }
|
|
765
764
|
export { _default_9 as readFile_alias_1 }
|
|
766
765
|
|
|
@@ -777,30 +776,11 @@ export declare const default_alias: {
|
|
|
777
776
|
readonly agent: "architect";
|
|
778
777
|
};
|
|
779
778
|
|
|
780
|
-
export declare const default_alias_1: {
|
|
781
|
-
readonly name: "generateGitCommitMessage";
|
|
782
|
-
readonly description: "Generates git commit messages from git diff output";
|
|
783
|
-
readonly prompt: "\nYou are an advanced assistant specialized in creating concise and accurate Git commit messages. When you receive:\n- A Git diff inside the <tool_input> tag.\n- Additional user-supplied context inside the <tool_input_context> tag (if any).\n\nYou will produce a single commit message enclosed within <tool_output> tags. The commit message must accurately reflect the changes shown in the diff and should be clear, descriptive, and devoid of unnecessary or repeated information. If a context is provided, it MUST be incorporated into the commit message.\n\nHere’s an example of the input and the expected output format:\n\n<tool_input>\n--- a/example_file.py\n+++ b/example_file.py\n@@ -10,7 +10,7 @@ def example_function():\n- print(\"Old behavior\")\n+ print(\"New behavior\")\n</tool_input>\n<tool_input_context>\nChanging print statement to update the user-facing message.\n</tool_input_context>\n\nExample Output:\n\n<tool_output>\nUpdate print statement for revised user-facing message\n</tool_output>\n\nFollow the same structure for any new input. Never repeat questions; focus on generating a concise commit message that captures the essence of the changes.\n";
|
|
784
|
-
readonly formatInput: (params: {
|
|
785
|
-
diff: string;
|
|
786
|
-
context?: string;
|
|
787
|
-
}) => string;
|
|
788
|
-
readonly parseOutput: (output: string) => string;
|
|
789
|
-
};
|
|
790
|
-
|
|
791
|
-
export declare const default_alias_2: {
|
|
792
|
-
readonly name: "generateGithubPullRequestDetails";
|
|
793
|
-
readonly description: "Generates a GitHub pull request title and description from git commits";
|
|
794
|
-
readonly prompt: "\n# Generate Github Pull Request Details\n\nYou are given:\n- A branch name in <tool_input_branch_name>.\n- An optional context message in <tool_input_context> (which may or may not be present).\n- All commit messages combined in <tool_input_commit_messages>.\n- All diffs combined in <tool_input_commit_diff>.\n\nYour task:\n1. Consider the optional context (if provided).\n - If an issue number is found, add \"Closes #xxx\" at the beginning of the PR description\n - IMPORTANT: Use ONLY the exact format \"Closes #xxx\" at the beginning of the description\n - DO NOT use variations like \"Closes issue #xxx\" or other formats\n2. Analyze the combined commit messages and diffs.\n3. Produce a single GitHub Pull Request title.\n4. Produce a Pull Request description that explains the changes.\n\nUse the following template for the Pull Request description:\n\n---\n**Context (if provided)**:\n- Acknowledge any guiding concerns or instructions.\n\n**Summary of Changes**:\n- Provide a concise list or overview of what changed.\n\n**Highlights of Changed Code**:\n- Mention only the specific sections or functionalities updated, without showing full surrounding context.\n\n**Additional Information (if needed)**:\n- Testing steps (if applicable).\n- Any notes or caveats.\n\n---\n\nOutput format:\n<tool_output>\n <tool_output_pr_title>YOUR PR TITLE HERE</tool_output_pr_title>\n <tool_output_pr_description>\n YOUR PR DESCRIPTION HERE\n </tool_output_pr_description>\n</tool_output>\n\nBelow is an **example** of the input and output:\n\nExample Input:\n<tool_input>\n<tool_input_branch_name>feature/refactor-logging</tool_input_branch_name>\n<tool_input_context>Implementing changes for issue #123 - Focus on clean code and maintainability</tool_input_context>\n<tool_input_commit_messages>\nRemove debug logs\nRefactor order validation logic\n</tool_input_commit_messages>\n<tool_input_commit_diff>\ndiff --git a/user_service.py b/user_service.py\n- print(\"Debug info\")\n+ # Removed debug print statements\n\ndiff --git a/order_service.py b/order_service.py\n- if is_valid_order(order):\n- process_order(order)\n+ validate_and_process(order)\n</tool_input_commit_diff>\n</tool_input>\n\nExample Output:\n<tool_output>\n<tool_output_pr_title>Refactor Order Validation and Remove Debug Logs</tool_output_pr_title>\n<tool_output_pr_description>\nCloses #123\n\n**Context**:\n- Implementing changes for issue #123 - Focus on clean code and maintainability\n\n**Summary of Changes**:\n- Refactored order validation logic to use a new `validate_and_process` method.\n- Removed debug print statements from `user_service.py`.\n\n**Highlights of Changed Code**:\n- `order_service.py`: Replaced direct call to `process_order` with `validate_and_process`.\n- `user_service.py`: Removed `print(\"Debug info\")`.\n</tool_output_pr_description>\n</tool_output>\n\n---\n\nUse the above format whenever you receive <tool_input> that may include a branch name, an optional context, aggregated commit messages in a single tag, and a combined diff in a single tag. Provide your final output strictly in <tool_output> with <tool_output_pr_title> and <tool_output_pr_description>. Only highlight the changed code and avoid including the context around the changes in the description.\n";
|
|
795
|
-
readonly formatInput: (params: Input) => string;
|
|
796
|
-
readonly parseOutput: (output: string) => Output;
|
|
797
|
-
};
|
|
798
|
-
|
|
799
779
|
/**
|
|
800
780
|
* AI tool for analyzing project files and generating polkacodes config sections.
|
|
801
781
|
* Generated by polka.codes
|
|
802
782
|
*/
|
|
803
|
-
export declare const
|
|
783
|
+
export declare const default_alias_1: {
|
|
804
784
|
readonly name: "generateProjectConfig";
|
|
805
785
|
readonly description: "Analyzes project files to generate polkacodes config sections";
|
|
806
786
|
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";
|
|
@@ -907,25 +887,6 @@ declare type FullToolInfoV2 = ToolInfoV2 & {
|
|
|
907
887
|
export { FullToolInfoV2 }
|
|
908
888
|
export { FullToolInfoV2 as FullToolInfoV2_alias_1 }
|
|
909
889
|
|
|
910
|
-
declare const generateGitCommitMessage: (ai: LanguageModelV2, params: {
|
|
911
|
-
diff: string;
|
|
912
|
-
context?: string;
|
|
913
|
-
}, usageMeter: UsageMeter) => Promise<string>;
|
|
914
|
-
export { generateGitCommitMessage }
|
|
915
|
-
export { generateGitCommitMessage as generateGitCommitMessage_alias_1 }
|
|
916
|
-
|
|
917
|
-
declare const generateGithubPullRequestDetails: (ai: LanguageModelV2, params: {
|
|
918
|
-
commitMessages: string;
|
|
919
|
-
commitDiff: string;
|
|
920
|
-
context?: string;
|
|
921
|
-
branchName: string;
|
|
922
|
-
}, usageMeter: UsageMeter) => Promise<{
|
|
923
|
-
title: string;
|
|
924
|
-
description: string;
|
|
925
|
-
}>;
|
|
926
|
-
export { generateGithubPullRequestDetails }
|
|
927
|
-
export { generateGithubPullRequestDetails as generateGithubPullRequestDetails_alias_1 }
|
|
928
|
-
|
|
929
890
|
declare const generateProjectConfig: (agent: MultiAgent, params: unknown) => Promise<string>;
|
|
930
891
|
export { generateProjectConfig }
|
|
931
892
|
export { generateProjectConfig as generateProjectConfig_alias_1 }
|
|
@@ -993,13 +954,6 @@ export declare const handler_alias_8: ToolHandler<typeof toolInfo_alias_8, Files
|
|
|
993
954
|
|
|
994
955
|
export declare const handler_alias_9: ToolHandler<typeof toolInfo_alias_9, FilesystemProvider>;
|
|
995
956
|
|
|
996
|
-
declare type Input = {
|
|
997
|
-
commitMessages: string;
|
|
998
|
-
commitDiff: string;
|
|
999
|
-
context?: string;
|
|
1000
|
-
branchName: string;
|
|
1001
|
-
};
|
|
1002
|
-
|
|
1003
957
|
declare type InputType = {
|
|
1004
958
|
$: Record<string, Record<string, Json>>;
|
|
1005
959
|
[key: string]: Json;
|
|
@@ -1126,11 +1080,6 @@ export { MultiAgentConfig as MultiAgentConfig_alias_2 }
|
|
|
1126
1080
|
|
|
1127
1081
|
export declare const objectives: (toolNamePrefix: string) => string;
|
|
1128
1082
|
|
|
1129
|
-
declare type Output = {
|
|
1130
|
-
title: string;
|
|
1131
|
-
description: string;
|
|
1132
|
-
};
|
|
1133
|
-
|
|
1134
1083
|
declare interface ParallelStepSpec<TInput extends Record<string, Json> = Record<string, Json>, TOutput extends Record<string, Json> = Record<string, Json>> extends BaseStepSpec<Record<string, Json>, Record<string, Json>> {
|
|
1135
1084
|
type: 'parallel';
|
|
1136
1085
|
step: BaseStepSpec<TInput, TOutput>;
|
|
@@ -1211,11 +1160,22 @@ export { parseAssistantMessage }
|
|
|
1211
1160
|
export { parseAssistantMessage as parseAssistantMessage_alias_1 }
|
|
1212
1161
|
export { parseAssistantMessage as parseAssistantMessage_alias_2 }
|
|
1213
1162
|
|
|
1214
|
-
declare const parseJsonFromMarkdown: (markdown: string) => any
|
|
1163
|
+
declare const parseJsonFromMarkdown: (markdown: string) => ParseOutputResult<any>;
|
|
1215
1164
|
export { parseJsonFromMarkdown }
|
|
1216
1165
|
export { parseJsonFromMarkdown as parseJsonFromMarkdown_alias_1 }
|
|
1217
1166
|
export { parseJsonFromMarkdown as parseJsonFromMarkdown_alias_2 }
|
|
1218
1167
|
|
|
1168
|
+
declare type ParseOutputResult<T> = {
|
|
1169
|
+
success: true;
|
|
1170
|
+
data: T;
|
|
1171
|
+
} | {
|
|
1172
|
+
success: false;
|
|
1173
|
+
error?: string;
|
|
1174
|
+
};
|
|
1175
|
+
export { ParseOutputResult }
|
|
1176
|
+
export { ParseOutputResult as ParseOutputResult_alias_1 }
|
|
1177
|
+
export { ParseOutputResult as ParseOutputResult_alias_2 }
|
|
1178
|
+
|
|
1219
1179
|
declare enum Policies {
|
|
1220
1180
|
TruncateContext = "truncatecontext",
|
|
1221
1181
|
EnableCache = "enablecache"
|
package/dist/index.d.ts
CHANGED
|
@@ -60,8 +60,6 @@ export { executeAgentTool } from './_tsup-dts-rollup.js';
|
|
|
60
60
|
export { makeTool } from './_tsup-dts-rollup.js';
|
|
61
61
|
export { makeMultiAgentTool } from './_tsup-dts-rollup.js';
|
|
62
62
|
export { makeAgentTool } from './_tsup-dts-rollup.js';
|
|
63
|
-
export { generateGitCommitMessage } from './_tsup-dts-rollup.js';
|
|
64
|
-
export { generateGithubPullRequestDetails } from './_tsup-dts-rollup.js';
|
|
65
63
|
export { generateProjectConfig } from './_tsup-dts-rollup.js';
|
|
66
64
|
export { createNewProject } from './_tsup-dts-rollup.js';
|
|
67
65
|
export { AiToolDefinition } from './_tsup-dts-rollup.js';
|
|
@@ -145,5 +143,6 @@ export { WorkflowRunResultSuccess } from './_tsup-dts-rollup.js';
|
|
|
145
143
|
export { WorkflowRunResultError } from './_tsup-dts-rollup.js';
|
|
146
144
|
export { WorkflowRunResultPaused } from './_tsup-dts-rollup.js';
|
|
147
145
|
export { WorkflowRunResult } from './_tsup-dts-rollup.js';
|
|
146
|
+
export { ParseOutputResult } from './_tsup-dts-rollup.js';
|
|
148
147
|
export { run } from './_tsup-dts-rollup.js';
|
|
149
148
|
export { resume } from './_tsup-dts-rollup.js';
|
package/dist/index.js
CHANGED
|
@@ -87,9 +87,9 @@ var handler = async (provider, args) => {
|
|
|
87
87
|
}
|
|
88
88
|
const answers = [];
|
|
89
89
|
for (const question of questions) {
|
|
90
|
-
const { prompt:
|
|
91
|
-
const answer = await provider.askFollowupQuestion(
|
|
92
|
-
answers.push(`<ask_followup_question_answer question="${
|
|
90
|
+
const { prompt: prompt3, options } = question;
|
|
91
|
+
const answer = await provider.askFollowupQuestion(prompt3, options);
|
|
92
|
+
answers.push(`<ask_followup_question_answer question="${prompt3}">
|
|
93
93
|
${answer}
|
|
94
94
|
</ask_followup_question_answer>`);
|
|
95
95
|
}
|
|
@@ -1958,9 +1958,9 @@ ${instance.prompt}`;
|
|
|
1958
1958
|
async #callback(event) {
|
|
1959
1959
|
await this.config.callback?.(event);
|
|
1960
1960
|
}
|
|
1961
|
-
async start(
|
|
1961
|
+
async start(prompt3) {
|
|
1962
1962
|
this.#callback({ kind: "StartTask" /* StartTask */, agent: this, systemPrompt: this.config.systemPrompt });
|
|
1963
|
-
return await this.#processLoop(
|
|
1963
|
+
return await this.#processLoop(prompt3);
|
|
1964
1964
|
}
|
|
1965
1965
|
async step(message) {
|
|
1966
1966
|
if (this.#messages.length === 0) {
|
|
@@ -3033,24 +3033,24 @@ var MultiAgent = class {
|
|
|
3033
3033
|
switch (exitReason.type) {
|
|
3034
3034
|
case "HandOver" /* HandOver */: {
|
|
3035
3035
|
this.#agents.pop();
|
|
3036
|
-
const
|
|
3036
|
+
const prompt3 = await this.#config.getPrompt?.(
|
|
3037
3037
|
exitReason.agentName,
|
|
3038
3038
|
exitReason.task,
|
|
3039
3039
|
exitReason.context,
|
|
3040
3040
|
exitReason.files,
|
|
3041
3041
|
this.#originalTask
|
|
3042
3042
|
) ?? exitReason.task;
|
|
3043
|
-
return await this.#startTask(exitReason.agentName,
|
|
3043
|
+
return await this.#startTask(exitReason.agentName, prompt3);
|
|
3044
3044
|
}
|
|
3045
3045
|
case "Delegate" /* Delegate */: {
|
|
3046
|
-
const
|
|
3046
|
+
const prompt3 = await this.#config.getPrompt?.(
|
|
3047
3047
|
exitReason.agentName,
|
|
3048
3048
|
exitReason.task,
|
|
3049
3049
|
exitReason.context,
|
|
3050
3050
|
exitReason.files,
|
|
3051
3051
|
this.#originalTask
|
|
3052
3052
|
) ?? exitReason.task;
|
|
3053
|
-
const delegateResult = await this.#startTask(exitReason.agentName,
|
|
3053
|
+
const delegateResult = await this.#startTask(exitReason.agentName, prompt3);
|
|
3054
3054
|
switch (delegateResult.type) {
|
|
3055
3055
|
case "HandOver" /* HandOver */:
|
|
3056
3056
|
case "Delegate" /* Delegate */:
|
|
@@ -3113,22 +3113,30 @@ var MultiAgent = class {
|
|
|
3113
3113
|
var parseJsonFromMarkdown = (markdown) => {
|
|
3114
3114
|
const jsonRegex = /```(?:json)?\n([\s\S]*?)\n```/;
|
|
3115
3115
|
const match = markdown.match(jsonRegex);
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3116
|
+
const tryParse = (str) => {
|
|
3117
|
+
try {
|
|
3118
|
+
let parsed = JSON.parse(str);
|
|
3119
|
+
if (typeof parsed === "string") {
|
|
3120
|
+
try {
|
|
3121
|
+
parsed = JSON.parse(parsed);
|
|
3122
|
+
} catch {
|
|
3123
|
+
}
|
|
3123
3124
|
}
|
|
3125
|
+
return { success: true, data: parsed };
|
|
3126
|
+
} catch (e) {
|
|
3127
|
+
const error = e instanceof Error ? e.message : String(e);
|
|
3128
|
+
return { success: false, error: `Failed to parse JSON: ${error}` };
|
|
3124
3129
|
}
|
|
3125
|
-
|
|
3130
|
+
};
|
|
3131
|
+
if (match?.[1]) {
|
|
3132
|
+
const content = match[1].trim();
|
|
3133
|
+
return tryParse(content);
|
|
3126
3134
|
}
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3135
|
+
const parseResult = tryParse(markdown);
|
|
3136
|
+
if (parseResult.success) {
|
|
3137
|
+
return parseResult;
|
|
3130
3138
|
}
|
|
3131
|
-
return
|
|
3139
|
+
return { success: false, error: "No JSON object found in the string." };
|
|
3132
3140
|
};
|
|
3133
3141
|
|
|
3134
3142
|
// src/config.ts
|
|
@@ -3457,189 +3465,8 @@ var createNewProject_default = {
|
|
|
3457
3465
|
agent: "architect"
|
|
3458
3466
|
};
|
|
3459
3467
|
|
|
3460
|
-
// src/AiTool/generateGitCommitMessage.ts
|
|
3461
|
-
var prompt2 = `
|
|
3462
|
-
You are an advanced assistant specialized in creating concise and accurate Git commit messages. When you receive:
|
|
3463
|
-
- A Git diff inside the <tool_input> tag.
|
|
3464
|
-
- Additional user-supplied context inside the <tool_input_context> tag (if any).
|
|
3465
|
-
|
|
3466
|
-
You will produce a single commit message enclosed within <tool_output> tags. The commit message must accurately reflect the changes shown in the diff and should be clear, descriptive, and devoid of unnecessary or repeated information. If a context is provided, it MUST be incorporated into the commit message.
|
|
3467
|
-
|
|
3468
|
-
Here\u2019s an example of the input and the expected output format:
|
|
3469
|
-
|
|
3470
|
-
<tool_input>
|
|
3471
|
-
--- a/example_file.py
|
|
3472
|
-
+++ b/example_file.py
|
|
3473
|
-
@@ -10,7 +10,7 @@ def example_function():
|
|
3474
|
-
- print("Old behavior")
|
|
3475
|
-
+ print("New behavior")
|
|
3476
|
-
</tool_input>
|
|
3477
|
-
<tool_input_context>
|
|
3478
|
-
Changing print statement to update the user-facing message.
|
|
3479
|
-
</tool_input_context>
|
|
3480
|
-
|
|
3481
|
-
Example Output:
|
|
3482
|
-
|
|
3483
|
-
<tool_output>
|
|
3484
|
-
Update print statement for revised user-facing message
|
|
3485
|
-
</tool_output>
|
|
3486
|
-
|
|
3487
|
-
Follow the same structure for any new input. Never repeat questions; focus on generating a concise commit message that captures the essence of the changes.
|
|
3488
|
-
`;
|
|
3489
|
-
var generateGitCommitMessage_default = {
|
|
3490
|
-
name: "generateGitCommitMessage",
|
|
3491
|
-
description: "Generates git commit messages from git diff output",
|
|
3492
|
-
prompt: prompt2,
|
|
3493
|
-
formatInput: (params) => {
|
|
3494
|
-
let ret = `<tool_input>
|
|
3495
|
-
${params.diff}
|
|
3496
|
-
</tool_input>`;
|
|
3497
|
-
if (params.context) {
|
|
3498
|
-
ret += `
|
|
3499
|
-
<tool_input_context>
|
|
3500
|
-
${params.context}
|
|
3501
|
-
</tool_input_context>`;
|
|
3502
|
-
}
|
|
3503
|
-
return ret;
|
|
3504
|
-
},
|
|
3505
|
-
parseOutput: (output) => {
|
|
3506
|
-
const regex = /<tool_output>([\s\S]*)<\/tool_output>/gm;
|
|
3507
|
-
const match = regex.exec(output);
|
|
3508
|
-
if (match) {
|
|
3509
|
-
return match[1];
|
|
3510
|
-
}
|
|
3511
|
-
throw new Error(`Could not parse output:
|
|
3512
|
-
${output}`);
|
|
3513
|
-
}
|
|
3514
|
-
};
|
|
3515
|
-
|
|
3516
|
-
// src/AiTool/generateGithubPullRequestDetails.ts
|
|
3517
|
-
var prompt3 = `
|
|
3518
|
-
# Generate Github Pull Request Details
|
|
3519
|
-
|
|
3520
|
-
You are given:
|
|
3521
|
-
- A branch name in <tool_input_branch_name>.
|
|
3522
|
-
- An optional context message in <tool_input_context> (which may or may not be present).
|
|
3523
|
-
- All commit messages combined in <tool_input_commit_messages>.
|
|
3524
|
-
- All diffs combined in <tool_input_commit_diff>.
|
|
3525
|
-
|
|
3526
|
-
Your task:
|
|
3527
|
-
1. Consider the optional context (if provided).
|
|
3528
|
-
- If an issue number is found, add "Closes #xxx" at the beginning of the PR description
|
|
3529
|
-
- IMPORTANT: Use ONLY the exact format "Closes #xxx" at the beginning of the description
|
|
3530
|
-
- DO NOT use variations like "Closes issue #xxx" or other formats
|
|
3531
|
-
2. Analyze the combined commit messages and diffs.
|
|
3532
|
-
3. Produce a single GitHub Pull Request title.
|
|
3533
|
-
4. Produce a Pull Request description that explains the changes.
|
|
3534
|
-
|
|
3535
|
-
Use the following template for the Pull Request description:
|
|
3536
|
-
|
|
3537
|
-
---
|
|
3538
|
-
**Context (if provided)**:
|
|
3539
|
-
- Acknowledge any guiding concerns or instructions.
|
|
3540
|
-
|
|
3541
|
-
**Summary of Changes**:
|
|
3542
|
-
- Provide a concise list or overview of what changed.
|
|
3543
|
-
|
|
3544
|
-
**Highlights of Changed Code**:
|
|
3545
|
-
- Mention only the specific sections or functionalities updated, without showing full surrounding context.
|
|
3546
|
-
|
|
3547
|
-
**Additional Information (if needed)**:
|
|
3548
|
-
- Testing steps (if applicable).
|
|
3549
|
-
- Any notes or caveats.
|
|
3550
|
-
|
|
3551
|
-
---
|
|
3552
|
-
|
|
3553
|
-
Output format:
|
|
3554
|
-
<tool_output>
|
|
3555
|
-
<tool_output_pr_title>YOUR PR TITLE HERE</tool_output_pr_title>
|
|
3556
|
-
<tool_output_pr_description>
|
|
3557
|
-
YOUR PR DESCRIPTION HERE
|
|
3558
|
-
</tool_output_pr_description>
|
|
3559
|
-
</tool_output>
|
|
3560
|
-
|
|
3561
|
-
Below is an **example** of the input and output:
|
|
3562
|
-
|
|
3563
|
-
Example Input:
|
|
3564
|
-
<tool_input>
|
|
3565
|
-
<tool_input_branch_name>feature/refactor-logging</tool_input_branch_name>
|
|
3566
|
-
<tool_input_context>Implementing changes for issue #123 - Focus on clean code and maintainability</tool_input_context>
|
|
3567
|
-
<tool_input_commit_messages>
|
|
3568
|
-
Remove debug logs
|
|
3569
|
-
Refactor order validation logic
|
|
3570
|
-
</tool_input_commit_messages>
|
|
3571
|
-
<tool_input_commit_diff>
|
|
3572
|
-
diff --git a/user_service.py b/user_service.py
|
|
3573
|
-
- print("Debug info")
|
|
3574
|
-
+ # Removed debug print statements
|
|
3575
|
-
|
|
3576
|
-
diff --git a/order_service.py b/order_service.py
|
|
3577
|
-
- if is_valid_order(order):
|
|
3578
|
-
- process_order(order)
|
|
3579
|
-
+ validate_and_process(order)
|
|
3580
|
-
</tool_input_commit_diff>
|
|
3581
|
-
</tool_input>
|
|
3582
|
-
|
|
3583
|
-
Example Output:
|
|
3584
|
-
<tool_output>
|
|
3585
|
-
<tool_output_pr_title>Refactor Order Validation and Remove Debug Logs</tool_output_pr_title>
|
|
3586
|
-
<tool_output_pr_description>
|
|
3587
|
-
Closes #123
|
|
3588
|
-
|
|
3589
|
-
**Context**:
|
|
3590
|
-
- Implementing changes for issue #123 - Focus on clean code and maintainability
|
|
3591
|
-
|
|
3592
|
-
**Summary of Changes**:
|
|
3593
|
-
- Refactored order validation logic to use a new \`validate_and_process\` method.
|
|
3594
|
-
- Removed debug print statements from \`user_service.py\`.
|
|
3595
|
-
|
|
3596
|
-
**Highlights of Changed Code**:
|
|
3597
|
-
- \`order_service.py\`: Replaced direct call to \`process_order\` with \`validate_and_process\`.
|
|
3598
|
-
- \`user_service.py\`: Removed \`print("Debug info")\`.
|
|
3599
|
-
</tool_output_pr_description>
|
|
3600
|
-
</tool_output>
|
|
3601
|
-
|
|
3602
|
-
---
|
|
3603
|
-
|
|
3604
|
-
Use the above format whenever you receive <tool_input> that may include a branch name, an optional context, aggregated commit messages in a single tag, and a combined diff in a single tag. Provide your final output strictly in <tool_output> with <tool_output_pr_title> and <tool_output_pr_description>. Only highlight the changed code and avoid including the context around the changes in the description.
|
|
3605
|
-
`;
|
|
3606
|
-
var generateGithubPullRequestDetails_default = {
|
|
3607
|
-
name: "generateGithubPullRequestDetails",
|
|
3608
|
-
description: "Generates a GitHub pull request title and description from git commits",
|
|
3609
|
-
prompt: prompt3,
|
|
3610
|
-
formatInput: (params) => {
|
|
3611
|
-
return `<tool_input>
|
|
3612
|
-
<tool_input_branch_name>${params.branchName}</tool_input_branch_name>${params.context ? `
|
|
3613
|
-
<tool_input_context>${params.context}</tool_input_context>` : ""}
|
|
3614
|
-
<tool_input_commit_messages>${params.commitMessages}</tool_input_commit_messages>
|
|
3615
|
-
<tool_input_commit_diff>${params.commitDiff}</tool_input_commit_diff>
|
|
3616
|
-
</tool_input>`;
|
|
3617
|
-
},
|
|
3618
|
-
parseOutput: (output) => {
|
|
3619
|
-
const regex = /<tool_output>([\s\S]*)<\/tool_output>/gm;
|
|
3620
|
-
const match = regex.exec(output);
|
|
3621
|
-
if (!match) {
|
|
3622
|
-
throw new Error(`Could not parse output:
|
|
3623
|
-
${output}`);
|
|
3624
|
-
}
|
|
3625
|
-
const [, outputContent] = match;
|
|
3626
|
-
const titleRegex = /<tool_output_pr_title>([\s\S]*)<\/tool_output_pr_title>/gm;
|
|
3627
|
-
const titleMatch = titleRegex.exec(outputContent);
|
|
3628
|
-
const descriptionRegex = /<tool_output_pr_description>([\s\S]*)<\/tool_output_pr_description>/gm;
|
|
3629
|
-
const descriptionMatch = descriptionRegex.exec(outputContent);
|
|
3630
|
-
if (titleMatch && descriptionMatch) {
|
|
3631
|
-
return {
|
|
3632
|
-
title: titleMatch[1],
|
|
3633
|
-
description: descriptionMatch[1]
|
|
3634
|
-
};
|
|
3635
|
-
}
|
|
3636
|
-
throw new Error(`Could not parse output:
|
|
3637
|
-
${output}`);
|
|
3638
|
-
}
|
|
3639
|
-
};
|
|
3640
|
-
|
|
3641
3468
|
// src/AiTool/generateProjectConfig.ts
|
|
3642
|
-
var
|
|
3469
|
+
var prompt2 = `
|
|
3643
3470
|
Role: Analyzer agent
|
|
3644
3471
|
Goal: Produce a valid polkacodes YAML configuration for the project.
|
|
3645
3472
|
|
|
@@ -3686,7 +3513,7 @@ excludeFiles: # only files likely to hold secrets
|
|
|
3686
3513
|
var generateProjectConfig_default = {
|
|
3687
3514
|
name: "generateProjectConfig",
|
|
3688
3515
|
description: "Analyzes project files to generate polkacodes config sections",
|
|
3689
|
-
prompt:
|
|
3516
|
+
prompt: prompt2,
|
|
3690
3517
|
formatInput: () => {
|
|
3691
3518
|
return "";
|
|
3692
3519
|
},
|
|
@@ -3748,11 +3575,12 @@ var makeAgentTool = (definition) => {
|
|
|
3748
3575
|
return executeAgentTool(definition, options, params);
|
|
3749
3576
|
};
|
|
3750
3577
|
};
|
|
3751
|
-
var generateGitCommitMessage = makeTool(generateGitCommitMessage_default);
|
|
3752
|
-
var generateGithubPullRequestDetails = makeTool(generateGithubPullRequestDetails_default);
|
|
3753
3578
|
var generateProjectConfig = makeMultiAgentTool(generateProjectConfig_default);
|
|
3754
3579
|
var createNewProject = makeMultiAgentTool(createNewProject_default);
|
|
3755
3580
|
|
|
3581
|
+
// src/workflow/agent.ts
|
|
3582
|
+
import { toJSONSchema as toJSONSchema2 } from "zod/v4";
|
|
3583
|
+
|
|
3756
3584
|
// src/workflow/utils.ts
|
|
3757
3585
|
import { template } from "lodash";
|
|
3758
3586
|
var resolveTemplatedString = (templatedString, input) => {
|
|
@@ -3790,9 +3618,7 @@ var makeAgentStepSpecHandler = (getModelFn) => ({
|
|
|
3790
3618
|
try {
|
|
3791
3619
|
const model = await getModelFn(step2, context);
|
|
3792
3620
|
const parameters = context.parameters ?? {};
|
|
3793
|
-
const
|
|
3794
|
-
const maxMessages = step2.maxMessages ?? parameters?.maxMessages;
|
|
3795
|
-
const usageMeter = new UsageMeter({}, { maxMessages, maxCost: budget });
|
|
3621
|
+
const usageMeter = parameters?.usageMeter ?? new UsageMeter();
|
|
3796
3622
|
const toolFormat = step2.toolFormat ?? parameters.toolFormat ?? "native";
|
|
3797
3623
|
const policies = parameters.policies ?? [];
|
|
3798
3624
|
const modelParameters = { ...parameters.modelParameters ?? {}, ...step2.modelParameters ?? {} };
|
|
@@ -3820,7 +3646,9 @@ var makeAgentStepSpecHandler = (getModelFn) => ({
|
|
|
3820
3646
|
parameters: modelParameters,
|
|
3821
3647
|
scripts: parameters.scripts,
|
|
3822
3648
|
callback: context.agentCallback,
|
|
3823
|
-
requireToolUse: false
|
|
3649
|
+
requireToolUse: false,
|
|
3650
|
+
retryCount: parameters.retryCount,
|
|
3651
|
+
requestTimeoutSeconds: parameters.requestTimeoutSeconds
|
|
3824
3652
|
});
|
|
3825
3653
|
} else {
|
|
3826
3654
|
if (!step2.systemPrompt) {
|
|
@@ -3842,7 +3670,9 @@ var makeAgentStepSpecHandler = (getModelFn) => ({
|
|
|
3842
3670
|
toolFormat,
|
|
3843
3671
|
parameters: modelParameters,
|
|
3844
3672
|
usageMeter,
|
|
3845
|
-
requireToolUse: false
|
|
3673
|
+
requireToolUse: false,
|
|
3674
|
+
retryCount: parameters.retryCount,
|
|
3675
|
+
requestTimeoutSeconds: parameters.requestTimeoutSeconds
|
|
3846
3676
|
});
|
|
3847
3677
|
}
|
|
3848
3678
|
};
|
|
@@ -3871,7 +3701,7 @@ var makeAgentStepSpecHandler = (getModelFn) => ({
|
|
|
3871
3701
|
if (context.verbose && context.verbose >= 1) {
|
|
3872
3702
|
logger.log(`[agent-step] Agent exited with reason:`, exitReason);
|
|
3873
3703
|
}
|
|
3874
|
-
const handleExitReason = (reason) => {
|
|
3704
|
+
const handleExitReason = async (reason) => {
|
|
3875
3705
|
switch (reason.type) {
|
|
3876
3706
|
case "Pause":
|
|
3877
3707
|
return { type: "paused", state: { messages: agent.messages } };
|
|
@@ -3880,24 +3710,34 @@ var makeAgentStepSpecHandler = (getModelFn) => ({
|
|
|
3880
3710
|
case "Exit" /* Exit */: {
|
|
3881
3711
|
const raw = reason.message;
|
|
3882
3712
|
if (step2.parseOutput) {
|
|
3883
|
-
|
|
3884
|
-
|
|
3713
|
+
const result = step2.parseOutput(raw);
|
|
3714
|
+
if (result.success) {
|
|
3885
3715
|
if (step2.outputSchema) {
|
|
3886
|
-
const validationResult = step2.outputSchema.safeParse(
|
|
3716
|
+
const validationResult = step2.outputSchema.safeParse(result.data);
|
|
3887
3717
|
if (validationResult.success) {
|
|
3888
3718
|
return { type: "success", output: validationResult.data };
|
|
3889
3719
|
}
|
|
3890
|
-
|
|
3891
|
-
|
|
3892
|
-
|
|
3893
|
-
|
|
3720
|
+
let errorMessage2 = `Output validation failed: ${validationResult.error.toString()}`;
|
|
3721
|
+
if (step2.outputSchema) {
|
|
3722
|
+
errorMessage2 += `
|
|
3723
|
+
|
|
3724
|
+
Expected JSON schema:
|
|
3725
|
+
${JSON.stringify(toJSONSchema2(step2.outputSchema), null, 2)}`;
|
|
3726
|
+
}
|
|
3727
|
+
const newReason2 = await agent.continueTask(errorMessage2);
|
|
3728
|
+
return handleExitReason(newReason2);
|
|
3894
3729
|
}
|
|
3895
|
-
return { type: "success", output:
|
|
3896
|
-
}
|
|
3897
|
-
|
|
3898
|
-
|
|
3899
|
-
|
|
3730
|
+
return { type: "success", output: result.data };
|
|
3731
|
+
}
|
|
3732
|
+
let errorMessage = result.error ?? "Invalid format.";
|
|
3733
|
+
if (step2.outputSchema) {
|
|
3734
|
+
errorMessage += `
|
|
3735
|
+
|
|
3736
|
+
Expected JSON schema:
|
|
3737
|
+
${JSON.stringify(toJSONSchema2(step2.outputSchema), null, 2)}`;
|
|
3900
3738
|
}
|
|
3739
|
+
const newReason = await agent.continueTask(errorMessage);
|
|
3740
|
+
return handleExitReason(newReason);
|
|
3901
3741
|
} else if (step2.outputSchema) {
|
|
3902
3742
|
try {
|
|
3903
3743
|
const output = JSON.parse(raw);
|
|
@@ -3905,14 +3745,22 @@ var makeAgentStepSpecHandler = (getModelFn) => ({
|
|
|
3905
3745
|
if (validationResult.success) {
|
|
3906
3746
|
return { type: "success", output: validationResult.data };
|
|
3907
3747
|
}
|
|
3908
|
-
|
|
3909
|
-
|
|
3910
|
-
|
|
3911
|
-
|
|
3748
|
+
let errorMessage = `Output validation failed: ${validationResult.error.toString()}`;
|
|
3749
|
+
errorMessage += `
|
|
3750
|
+
|
|
3751
|
+
Expected JSON schema:
|
|
3752
|
+
${JSON.stringify(toJSONSchema2(step2.outputSchema), null, 2)}`;
|
|
3753
|
+
const newReason = await agent.continueTask(errorMessage);
|
|
3754
|
+
return handleExitReason(newReason);
|
|
3912
3755
|
} catch (e) {
|
|
3913
3756
|
const error = e instanceof Error ? e : new Error(String(e));
|
|
3914
|
-
|
|
3915
|
-
|
|
3757
|
+
let errorMessage = `Failed to parse agent output as JSON: ${error.message}`;
|
|
3758
|
+
errorMessage += `
|
|
3759
|
+
|
|
3760
|
+
Expected JSON schema:
|
|
3761
|
+
${JSON.stringify(toJSONSchema2(step2.outputSchema), null, 2)}`;
|
|
3762
|
+
const newReason = await agent.continueTask(errorMessage);
|
|
3763
|
+
return handleExitReason(newReason);
|
|
3916
3764
|
}
|
|
3917
3765
|
}
|
|
3918
3766
|
return { type: "success", output: reason };
|
|
@@ -3932,7 +3780,7 @@ var makeAgentStepSpecHandler = (getModelFn) => ({
|
|
|
3932
3780
|
};
|
|
3933
3781
|
}
|
|
3934
3782
|
};
|
|
3935
|
-
return handleExitReason(exitReason);
|
|
3783
|
+
return await handleExitReason(exitReason);
|
|
3936
3784
|
} catch (e) {
|
|
3937
3785
|
return { type: "error", error: e instanceof Error ? e : new Error(String(e)) };
|
|
3938
3786
|
}
|
|
@@ -4248,8 +4096,6 @@ export {
|
|
|
4248
4096
|
executeMultiAgentTool,
|
|
4249
4097
|
executeTool,
|
|
4250
4098
|
fetchUrl_default as fetchUrl,
|
|
4251
|
-
generateGitCommitMessage,
|
|
4252
|
-
generateGithubPullRequestDetails,
|
|
4253
4099
|
generateProjectConfig,
|
|
4254
4100
|
getAvailableTools,
|
|
4255
4101
|
handOver_default as handOver,
|