@polka-codes/cli 0.10.21 → 0.10.23
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 +3990 -353
- package/package.json +4 -4
- package/dist/chunk-2LRQ2QH6.js +0 -1353
- package/dist/chunk-FSNPWI3C.js +0 -128
- package/dist/chunk-HB7PTE3H.js +0 -176
- package/dist/chunk-LLMPMGV3.js +0 -140
- package/dist/chunk-NRDSZGMF.js +0 -675
- package/dist/chunk-UEEU3SCC.js +0 -390
- package/dist/chunk-YPUL66UK.js +0 -277
- package/dist/chunk-ZS4K5RFU.js +0 -176
- package/dist/chunk-ZU4UU65A.js +0 -40
- package/dist/code.workflow-5TAWK2DE.js +0 -10
- package/dist/commit.workflow-Z64PNSTS.js +0 -9
- package/dist/fix.workflow-KLHJU5Z6.js +0 -7
- package/dist/plan.workflow-P2Y6W4FA.js +0 -8
- package/dist/review.workflow-I7RHWKU7.js +0 -8
- package/dist/sdk-client-KBYJRPEG.js +0 -155
package/dist/chunk-FSNPWI3C.js
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
UserCancelledError
|
|
3
|
-
} from "./chunk-LLMPMGV3.js";
|
|
4
|
-
import {
|
|
5
|
-
gitDiff_default
|
|
6
|
-
} from "./chunk-UEEU3SCC.js";
|
|
7
|
-
import {
|
|
8
|
-
COMMIT_MESSAGE_SYSTEM_PROMPT,
|
|
9
|
-
parseGitDiffNameStatus
|
|
10
|
-
} from "./chunk-2LRQ2QH6.js";
|
|
11
|
-
|
|
12
|
-
// src/workflows/commit.workflow.ts
|
|
13
|
-
import { agentWorkflow, listFiles, readBinaryFile, readFile, searchFiles } from "@polka-codes/core";
|
|
14
|
-
import { z } from "zod";
|
|
15
|
-
var commitWorkflow = async (input, context) => {
|
|
16
|
-
const { step, tools, logger } = context;
|
|
17
|
-
const { stagedFiles, unstagedFiles } = await tools.printChangeFile();
|
|
18
|
-
let hasStaged = stagedFiles.length > 0;
|
|
19
|
-
const hasUnstaged = unstagedFiles.length > 0;
|
|
20
|
-
if (input.files && input.files.length > 0) {
|
|
21
|
-
await step("stage-files", async () => {
|
|
22
|
-
const result2 = await tools.executeCommand({
|
|
23
|
-
command: "git",
|
|
24
|
-
args: ["add", ...input.files ?? []]
|
|
25
|
-
});
|
|
26
|
-
if (result2.exitCode !== 0) {
|
|
27
|
-
throw new Error(`Failed to stage files: ${result2.stderr}`);
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
hasStaged = true;
|
|
31
|
-
} else if (!hasStaged) {
|
|
32
|
-
if (input.all) {
|
|
33
|
-
await step("stage-all", async () => {
|
|
34
|
-
const result2 = await tools.executeCommand({ command: "git", args: ["add", "."] });
|
|
35
|
-
if (result2.exitCode !== 0) {
|
|
36
|
-
throw new Error(`Failed to stage files: ${result2.stderr}`);
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
hasStaged = true;
|
|
40
|
-
} else if (hasUnstaged) {
|
|
41
|
-
let confirmed = false;
|
|
42
|
-
if (input.interactive !== false) {
|
|
43
|
-
confirmed = await tools.confirm({
|
|
44
|
-
message: "No staged files found. Stage all files?",
|
|
45
|
-
default: false
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
if (confirmed) {
|
|
49
|
-
await step("stage-all", async () => {
|
|
50
|
-
const result2 = await tools.executeCommand({
|
|
51
|
-
command: "git",
|
|
52
|
-
args: ["add", "."]
|
|
53
|
-
});
|
|
54
|
-
if (result2.exitCode !== 0) {
|
|
55
|
-
throw new Error(`Failed to stage files: ${result2.stderr}`);
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
hasStaged = true;
|
|
59
|
-
} else if (input.interactive !== false) {
|
|
60
|
-
throw new UserCancelledError();
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
if (!hasStaged) {
|
|
65
|
-
throw new Error("No files to commit. Aborting.");
|
|
66
|
-
}
|
|
67
|
-
const { changedFiles, diff } = await step("get-diff", async () => {
|
|
68
|
-
let changedFiles2 = [];
|
|
69
|
-
const diffNameStatusResult = await tools.executeCommand({
|
|
70
|
-
command: "git",
|
|
71
|
-
args: ["diff", "--name-status", "--no-color", "--staged"]
|
|
72
|
-
});
|
|
73
|
-
if (diffNameStatusResult.exitCode === 0) {
|
|
74
|
-
changedFiles2 = parseGitDiffNameStatus(diffNameStatusResult.stdout);
|
|
75
|
-
}
|
|
76
|
-
const diffResult = await tools.executeCommand({
|
|
77
|
-
command: "git",
|
|
78
|
-
args: ["diff", "--staged"]
|
|
79
|
-
});
|
|
80
|
-
const diff2 = diffResult.stdout;
|
|
81
|
-
return { changedFiles: changedFiles2, diff: diff2 };
|
|
82
|
-
});
|
|
83
|
-
const fileList = changedFiles.map((file) => `${file.status}: ${file.path}`).join("\n");
|
|
84
|
-
const fileListPrompt = `<file_status>
|
|
85
|
-
${fileList}
|
|
86
|
-
</file_status>`;
|
|
87
|
-
const diffPrompt = `<diff>
|
|
88
|
-
${diff}
|
|
89
|
-
</diff>`;
|
|
90
|
-
const contextPrompt = input.context ? `
|
|
91
|
-
<tool_input_context>
|
|
92
|
-
${input.context}
|
|
93
|
-
</tool_input_context>` : "";
|
|
94
|
-
const commitMessageSchema = z.object({
|
|
95
|
-
commitMessage: z.string()
|
|
96
|
-
});
|
|
97
|
-
const result = await step("generate-commit-message", async () => {
|
|
98
|
-
return await agentWorkflow(
|
|
99
|
-
{
|
|
100
|
-
systemPrompt: COMMIT_MESSAGE_SYSTEM_PROMPT,
|
|
101
|
-
userMessage: [
|
|
102
|
-
{
|
|
103
|
-
role: "user",
|
|
104
|
-
content: `${fileListPrompt}${diffPrompt}${contextPrompt}`
|
|
105
|
-
}
|
|
106
|
-
],
|
|
107
|
-
tools: [readFile, readBinaryFile, searchFiles, listFiles, gitDiff_default],
|
|
108
|
-
outputSchema: commitMessageSchema
|
|
109
|
-
},
|
|
110
|
-
context
|
|
111
|
-
);
|
|
112
|
-
});
|
|
113
|
-
if (result.type === "Exit" && result.object) {
|
|
114
|
-
const { commitMessage } = commitMessageSchema.parse(result.object);
|
|
115
|
-
if (commitMessage) {
|
|
116
|
-
logger.info(`
|
|
117
|
-
Commit message:
|
|
118
|
-
${commitMessage}`);
|
|
119
|
-
await tools.createCommit({ message: commitMessage });
|
|
120
|
-
return commitMessage;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
context.logger.warn("Failed to generate commit message.", result);
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
export {
|
|
127
|
-
commitWorkflow
|
|
128
|
-
};
|
package/dist/chunk-HB7PTE3H.js
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
fixWorkflow
|
|
3
|
-
} from "./chunk-ZS4K5RFU.js";
|
|
4
|
-
import {
|
|
5
|
-
planWorkflow
|
|
6
|
-
} from "./chunk-YPUL66UK.js";
|
|
7
|
-
import {
|
|
8
|
-
getCoderSystemPrompt,
|
|
9
|
-
getDefaultContext,
|
|
10
|
-
getImplementPrompt
|
|
11
|
-
} from "./chunk-2LRQ2QH6.js";
|
|
12
|
-
|
|
13
|
-
// src/workflows/code.workflow.ts
|
|
14
|
-
import {
|
|
15
|
-
agentWorkflow,
|
|
16
|
-
askFollowupQuestion,
|
|
17
|
-
executeCommand,
|
|
18
|
-
fetchUrl,
|
|
19
|
-
listFiles,
|
|
20
|
-
readBinaryFile,
|
|
21
|
-
readFile,
|
|
22
|
-
removeFile,
|
|
23
|
-
renameFile,
|
|
24
|
-
replaceInFile,
|
|
25
|
-
searchFiles,
|
|
26
|
-
writeToFile
|
|
27
|
-
} from "@polka-codes/core";
|
|
28
|
-
import { z } from "zod";
|
|
29
|
-
var ImplementOutputSchema = z.object({
|
|
30
|
-
summary: z.string().nullish().describe("Short summary of the changes made"),
|
|
31
|
-
bailReason: z.string().nullish().describe("Reason for bailing out of the implementation loop")
|
|
32
|
-
}).refine((data) => data.summary != null !== (data.bailReason != null), {
|
|
33
|
-
message: "Either summary or bailReason must be provided, but not both"
|
|
34
|
-
});
|
|
35
|
-
var codeWorkflow = async (input, context) => {
|
|
36
|
-
const { logger, step, tools } = context;
|
|
37
|
-
const { task, files, mode: inputMode, customTools, additionalInstructions, interactive, additionalTools } = input;
|
|
38
|
-
const mode = interactive === false ? "noninteractive" : inputMode ?? "interactive";
|
|
39
|
-
const summaries = [];
|
|
40
|
-
logger.info("\nPhase 1: Creating implementation plan...\n");
|
|
41
|
-
const planResult = await step("plan", async () => {
|
|
42
|
-
return await planWorkflow(
|
|
43
|
-
{ task, files, mode: mode === "interactive" ? "confirm" : "noninteractive", interactive, additionalTools },
|
|
44
|
-
context
|
|
45
|
-
);
|
|
46
|
-
});
|
|
47
|
-
if (!planResult) {
|
|
48
|
-
logger.info("Plan not approved. Exiting.");
|
|
49
|
-
return { success: false, reason: "Plan not approved", summaries };
|
|
50
|
-
}
|
|
51
|
-
const { plan, files: planFiles } = planResult;
|
|
52
|
-
logger.info("\nPhase 2: Implementing the plan...\n");
|
|
53
|
-
let implementPrompt = getImplementPrompt(plan);
|
|
54
|
-
if (planFiles && planFiles.length > 0) {
|
|
55
|
-
const fileContentString = planFiles.map((f) => `<file path="${f.path}">${f.content}</file>`).join("\n");
|
|
56
|
-
implementPrompt += `
|
|
57
|
-
|
|
58
|
-
Here are the files related to the plan:
|
|
59
|
-
${fileContentString}`;
|
|
60
|
-
}
|
|
61
|
-
const userContent = [{ type: "text", text: implementPrompt }];
|
|
62
|
-
if (files) {
|
|
63
|
-
for (const file of files) {
|
|
64
|
-
if (file.type === "file") {
|
|
65
|
-
userContent.push({
|
|
66
|
-
type: "file",
|
|
67
|
-
mediaType: file.mediaType,
|
|
68
|
-
filename: file.filename,
|
|
69
|
-
data: { type: "base64", value: file.data }
|
|
70
|
-
});
|
|
71
|
-
} else if (file.type === "image") {
|
|
72
|
-
userContent.push({
|
|
73
|
-
type: "image",
|
|
74
|
-
mediaType: file.mediaType,
|
|
75
|
-
image: { type: "base64", value: file.image }
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
const agentTools = [
|
|
81
|
-
readFile,
|
|
82
|
-
writeToFile,
|
|
83
|
-
replaceInFile,
|
|
84
|
-
searchFiles,
|
|
85
|
-
listFiles,
|
|
86
|
-
executeCommand,
|
|
87
|
-
fetchUrl,
|
|
88
|
-
readBinaryFile,
|
|
89
|
-
removeFile,
|
|
90
|
-
renameFile
|
|
91
|
-
];
|
|
92
|
-
if (mode === "interactive") {
|
|
93
|
-
agentTools.push(askFollowupQuestion);
|
|
94
|
-
}
|
|
95
|
-
if (customTools) {
|
|
96
|
-
agentTools.push(...customTools);
|
|
97
|
-
}
|
|
98
|
-
if (additionalTools?.search) {
|
|
99
|
-
agentTools.push(additionalTools.search);
|
|
100
|
-
}
|
|
101
|
-
if (additionalTools?.mcpTools) {
|
|
102
|
-
agentTools.push(...additionalTools.mcpTools);
|
|
103
|
-
}
|
|
104
|
-
const res = await step("implement", async () => {
|
|
105
|
-
const { context: defaultContext, loadRules } = await getDefaultContext(input.config, "code");
|
|
106
|
-
const memoryContext = await tools.getMemoryContext();
|
|
107
|
-
const textContent = userContent.find((c) => c.type === "text");
|
|
108
|
-
if (textContent && textContent.type === "text") {
|
|
109
|
-
textContent.text = `${textContent.text}
|
|
110
|
-
|
|
111
|
-
${defaultContext}
|
|
112
|
-
${memoryContext}`;
|
|
113
|
-
} else {
|
|
114
|
-
userContent.push({
|
|
115
|
-
type: "text",
|
|
116
|
-
text: `${defaultContext}
|
|
117
|
-
${memoryContext}`
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
const baseSystemPrompt = getCoderSystemPrompt(loadRules);
|
|
121
|
-
const systemPrompt = additionalInstructions ? `${baseSystemPrompt}
|
|
122
|
-
|
|
123
|
-
${additionalInstructions}` : baseSystemPrompt;
|
|
124
|
-
return await agentWorkflow(
|
|
125
|
-
{
|
|
126
|
-
systemPrompt,
|
|
127
|
-
userMessage: [{ role: "user", content: userContent }],
|
|
128
|
-
tools: agentTools,
|
|
129
|
-
outputSchema: ImplementOutputSchema
|
|
130
|
-
},
|
|
131
|
-
context
|
|
132
|
-
);
|
|
133
|
-
});
|
|
134
|
-
if (res.type === "Exit" && res.object) {
|
|
135
|
-
const { summary, bailReason } = res.object;
|
|
136
|
-
if (bailReason) {
|
|
137
|
-
logger.error(`
|
|
138
|
-
Implementation failed: ${bailReason}
|
|
139
|
-
`);
|
|
140
|
-
return { success: false, reason: bailReason, summaries };
|
|
141
|
-
}
|
|
142
|
-
if (summary) {
|
|
143
|
-
logger.info("\nImplementation complete!\n");
|
|
144
|
-
summaries.push(summary);
|
|
145
|
-
logger.info(`Summary: ${summary}`);
|
|
146
|
-
await step("summarize-implementation", async () => {
|
|
147
|
-
await tools.updateMemory({
|
|
148
|
-
operation: "append",
|
|
149
|
-
topic: "implementation-summary",
|
|
150
|
-
content: summary
|
|
151
|
-
});
|
|
152
|
-
});
|
|
153
|
-
} else {
|
|
154
|
-
logger.info("\nImplementation complete!\n");
|
|
155
|
-
}
|
|
156
|
-
} else if (res.type === "Exit") {
|
|
157
|
-
logger.info("\nImplementation complete!\n");
|
|
158
|
-
} else {
|
|
159
|
-
logger.warn("\nWarning: Implementation failed. Please check the output for errors.\n", res);
|
|
160
|
-
}
|
|
161
|
-
logger.info("\nPhase 3: Checking for errors...\n");
|
|
162
|
-
const fixResult = await step("fix", async () => {
|
|
163
|
-
return await fixWorkflow({ interactive: false, task: input.task, additionalTools: input.additionalTools }, context);
|
|
164
|
-
});
|
|
165
|
-
if (fixResult.summaries) {
|
|
166
|
-
summaries.push(...fixResult.summaries);
|
|
167
|
-
}
|
|
168
|
-
if (!fixResult.success) {
|
|
169
|
-
return { success: false, reason: fixResult.reason, summaries };
|
|
170
|
-
}
|
|
171
|
-
return { success: true, summaries };
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
export {
|
|
175
|
-
codeWorkflow
|
|
176
|
-
};
|
package/dist/chunk-LLMPMGV3.js
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
// src/errors.ts
|
|
2
|
-
import { createErrorClass } from "@polka-codes/core";
|
|
3
|
-
var UserCancelledError = createErrorClass("UserCancelledError", (args) => args[0] ?? "User cancelled");
|
|
4
|
-
var ProviderError = class extends Error {
|
|
5
|
-
provider;
|
|
6
|
-
model;
|
|
7
|
-
retryable;
|
|
8
|
-
cause;
|
|
9
|
-
constructor(provider, model, message, retryable, cause) {
|
|
10
|
-
super(message);
|
|
11
|
-
this.name = this.constructor.name;
|
|
12
|
-
this.provider = provider;
|
|
13
|
-
this.model = model;
|
|
14
|
-
this.retryable = retryable;
|
|
15
|
-
this.cause = cause;
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
var ProviderUnavailableError = class extends ProviderError {
|
|
19
|
-
constructor(provider, model, statusCode, cause) {
|
|
20
|
-
super(
|
|
21
|
-
provider,
|
|
22
|
-
model,
|
|
23
|
-
`${provider} API is temporarily unavailable (HTTP ${statusCode}). The service may be experiencing issues. Please try again in a few minutes.`,
|
|
24
|
-
true,
|
|
25
|
-
cause
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
var RateLimitError = class extends ProviderError {
|
|
30
|
-
retryAfter;
|
|
31
|
-
constructor(provider, model, retryAfter, cause) {
|
|
32
|
-
const message = retryAfter ? `${provider} rate limit exceeded. Please retry after ${retryAfter} seconds.` : `${provider} rate limit exceeded. Please wait a few minutes before retrying.`;
|
|
33
|
-
super(provider, model, message, true, cause);
|
|
34
|
-
this.retryAfter = retryAfter;
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
var ProviderTimeoutError = class extends ProviderError {
|
|
38
|
-
timeoutSeconds;
|
|
39
|
-
constructor(provider, model, timeoutSeconds, cause) {
|
|
40
|
-
super(
|
|
41
|
-
provider,
|
|
42
|
-
model,
|
|
43
|
-
`${provider} request timed out after ${timeoutSeconds} seconds. This could be due to network issues or the service being slow. Please check your connection and try again.`,
|
|
44
|
-
true,
|
|
45
|
-
cause
|
|
46
|
-
);
|
|
47
|
-
this.timeoutSeconds = timeoutSeconds;
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
var AuthenticationError = class extends ProviderError {
|
|
51
|
-
constructor(provider, model, cause) {
|
|
52
|
-
super(
|
|
53
|
-
provider,
|
|
54
|
-
model,
|
|
55
|
-
`${provider} authentication failed for model '${model}'. Please check your API key is valid and has not expired. Run 'polka init' to reconfigure.`,
|
|
56
|
-
false,
|
|
57
|
-
cause
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
var ModelAccessError = class extends ProviderError {
|
|
62
|
-
constructor(provider, model, statusCode, cause) {
|
|
63
|
-
super(
|
|
64
|
-
provider,
|
|
65
|
-
model,
|
|
66
|
-
`${provider} model '${model}' is not available (HTTP ${statusCode}). This could mean the model doesn't exist, you don't have access, or it's not enabled in your account. Please check your model configuration.`,
|
|
67
|
-
false,
|
|
68
|
-
cause
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
var InvalidRequestError = class extends ProviderError {
|
|
73
|
-
constructor(provider, model, details, cause) {
|
|
74
|
-
super(
|
|
75
|
-
provider,
|
|
76
|
-
model,
|
|
77
|
-
`${provider} rejected the request: ${details}. Please check your request parameters and try again.`,
|
|
78
|
-
false,
|
|
79
|
-
cause
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
var QuotaExceededError = class extends ProviderError {
|
|
84
|
-
currentCost;
|
|
85
|
-
maxCost;
|
|
86
|
-
constructor(provider, model, currentCost, maxCost) {
|
|
87
|
-
super(
|
|
88
|
-
provider,
|
|
89
|
-
model,
|
|
90
|
-
`${provider} quota exceeded for model '${model}'. Current cost: $${currentCost.toFixed(2)}, Max budget: $${maxCost.toFixed(2)}. Adjust your budget with 'polka init' or reduce usage.`,
|
|
91
|
-
false
|
|
92
|
-
);
|
|
93
|
-
this.currentCost = currentCost;
|
|
94
|
-
this.maxCost = maxCost;
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
var MaxRetriesExceededError = class extends ProviderError {
|
|
98
|
-
attempts;
|
|
99
|
-
lastError;
|
|
100
|
-
constructor(provider, model, attempts, lastError) {
|
|
101
|
-
super(
|
|
102
|
-
provider,
|
|
103
|
-
model,
|
|
104
|
-
`${provider} failed after ${attempts} retry attempts for model '${model}'. Last error: ${lastError.message}. Please check your network connection and verify the service is operational.`,
|
|
105
|
-
false,
|
|
106
|
-
lastError
|
|
107
|
-
);
|
|
108
|
-
this.attempts = attempts;
|
|
109
|
-
this.lastError = lastError;
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
function createProviderErrorFromStatus(provider, model, statusCode, cause) {
|
|
113
|
-
switch (statusCode) {
|
|
114
|
-
case 400:
|
|
115
|
-
return new InvalidRequestError(provider, model, "Bad request", cause);
|
|
116
|
-
case 401:
|
|
117
|
-
return new AuthenticationError(provider, model, cause);
|
|
118
|
-
case 403:
|
|
119
|
-
case 404:
|
|
120
|
-
return new ModelAccessError(provider, model, statusCode, cause);
|
|
121
|
-
case 429:
|
|
122
|
-
return new RateLimitError(provider, model, void 0, cause);
|
|
123
|
-
default:
|
|
124
|
-
if (statusCode >= 500) {
|
|
125
|
-
return new ProviderUnavailableError(provider, model, statusCode, cause);
|
|
126
|
-
}
|
|
127
|
-
return new InvalidRequestError(provider, model, `HTTP ${statusCode}`, cause);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export {
|
|
132
|
-
UserCancelledError,
|
|
133
|
-
ProviderError,
|
|
134
|
-
ProviderTimeoutError,
|
|
135
|
-
AuthenticationError,
|
|
136
|
-
ModelAccessError,
|
|
137
|
-
QuotaExceededError,
|
|
138
|
-
MaxRetriesExceededError,
|
|
139
|
-
createProviderErrorFromStatus
|
|
140
|
-
};
|