@polka-codes/cli 0.6.5 → 0.6.7
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/README.md +143 -49
- package/dist/index.js +96 -66
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,97 +7,191 @@
|
|
|
7
7
|
[](https://bun.sh)
|
|
8
8
|
[](https://www.typescriptlang.org)
|
|
9
9
|
|
|
10
|
-
The Polka Codes CLI provides a powerful command-line interface for interacting with
|
|
10
|
+
The Polka Codes CLI provides a powerful command-line interface for interacting with AI-powered coding assistants. It offers features like interactive chat, task execution, commit message generation, and pull request creation.
|
|
11
11
|
|
|
12
12
|
## Installation
|
|
13
13
|
|
|
14
|
-
### Global Installation
|
|
15
|
-
|
|
16
14
|
```bash
|
|
15
|
+
# Install globally with npm
|
|
17
16
|
npm install -g @polka-codes/cli
|
|
18
|
-
```
|
|
19
17
|
|
|
20
|
-
|
|
18
|
+
# Install globally with yarn
|
|
19
|
+
yarn global add @polka-codes/cli
|
|
21
20
|
|
|
22
|
-
|
|
21
|
+
# Install globally with bun
|
|
22
|
+
bun add -g @polka-codes/cli
|
|
23
|
+
|
|
24
|
+
# Or run directly with npx
|
|
23
25
|
npx @polka-codes/cli
|
|
24
26
|
```
|
|
25
27
|
|
|
26
|
-
##
|
|
28
|
+
## Commands
|
|
29
|
+
|
|
30
|
+
### Interactive Chat
|
|
27
31
|
|
|
28
|
-
|
|
32
|
+
Start an interactive chat session with the AI assistant:
|
|
29
33
|
|
|
30
34
|
```bash
|
|
31
|
-
|
|
32
|
-
|
|
35
|
+
polka chat
|
|
36
|
+
# or simply
|
|
37
|
+
polka
|
|
38
|
+
```
|
|
33
39
|
|
|
34
|
-
|
|
35
|
-
pokla task "improve readme"
|
|
40
|
+
### Task Execution
|
|
36
41
|
|
|
37
|
-
|
|
38
|
-
pokla config
|
|
42
|
+
Execute a specific task:
|
|
39
43
|
|
|
40
|
-
|
|
41
|
-
|
|
44
|
+
```bash
|
|
45
|
+
polka task "improve error handling in auth module"
|
|
46
|
+
# or pipe input
|
|
47
|
+
echo "optimize database queries" | polka task
|
|
42
48
|
```
|
|
43
49
|
|
|
44
|
-
###
|
|
50
|
+
### Project Creation
|
|
45
51
|
|
|
46
|
-
|
|
52
|
+
Create a new project with AI assistance:
|
|
47
53
|
|
|
48
54
|
```bash
|
|
49
|
-
|
|
50
|
-
|
|
55
|
+
polka create my-project
|
|
56
|
+
```
|
|
51
57
|
|
|
52
|
-
|
|
53
|
-
|
|
58
|
+
The command will:
|
|
59
|
+
1. Prompt for project location confirmation
|
|
60
|
+
2. Set up initial project structure
|
|
61
|
+
3. Configure basic dependencies
|
|
62
|
+
4. Generate starter code
|
|
63
|
+
|
|
64
|
+
### Configuration
|
|
54
65
|
|
|
66
|
+
Initialize Polka Codes configuration:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
# Create local config
|
|
70
|
+
polka init
|
|
71
|
+
|
|
72
|
+
# Create global config
|
|
73
|
+
polka init --global
|
|
55
74
|
```
|
|
56
75
|
|
|
57
|
-
###
|
|
76
|
+
### Git Integration
|
|
58
77
|
|
|
59
|
-
|
|
78
|
+
Generate commit messages based on staged changes:
|
|
60
79
|
|
|
61
80
|
```bash
|
|
62
|
-
|
|
81
|
+
# Generate commit message for staged changes
|
|
82
|
+
polka commit
|
|
83
|
+
|
|
84
|
+
# Generate commit message with context
|
|
85
|
+
polka commit "closes #123"
|
|
86
|
+
|
|
87
|
+
# Stage all changes and commit
|
|
88
|
+
polka commit -a
|
|
63
89
|
```
|
|
64
90
|
|
|
65
|
-
|
|
91
|
+
Create pull requests with AI-generated details:
|
|
66
92
|
|
|
67
|
-
|
|
93
|
+
```bash
|
|
94
|
+
# Create PR with current branch changes
|
|
95
|
+
polka pr
|
|
68
96
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
provider: deepseek
|
|
72
|
-
modelId: deepseek-chat
|
|
73
|
-
commands: # a set of available commands for the AI assistant
|
|
74
|
-
check: bun check # command
|
|
75
|
-
test: # command name
|
|
76
|
-
command: bun test # command to execute
|
|
77
|
-
description: Run tests. Pass file path to run a specific test file. # description of the command
|
|
78
|
-
rules: |
|
|
79
|
-
Additional rules for the AI assistant.
|
|
97
|
+
# Create PR with additional context
|
|
98
|
+
polka pr "implements feature #456"
|
|
80
99
|
```
|
|
81
100
|
|
|
82
|
-
|
|
101
|
+
## Configuration
|
|
83
102
|
|
|
84
|
-
|
|
85
|
-
1. DeepSeek / `deepseek` (recommended)
|
|
86
|
-
2. Anthropic / `anthropic` (Sonnet 3.5 recommended)
|
|
87
|
-
3. OpenRouter / `openrouter`
|
|
88
|
-
4. Ollama / `ollama`
|
|
103
|
+
### Provider Setup
|
|
89
104
|
|
|
90
|
-
|
|
105
|
+
Polka Codes supports multiple AI providers:
|
|
106
|
+
|
|
107
|
+
1. DeepSeek (Recommended)
|
|
108
|
+
2. Anthropic (Claude 3 Sonnet recommended)
|
|
109
|
+
3. OpenRouter
|
|
110
|
+
4. Ollama
|
|
111
|
+
|
|
112
|
+
Configure your provider in `.env`:
|
|
91
113
|
|
|
92
114
|
```bash
|
|
115
|
+
# Required
|
|
93
116
|
POLKA_API_KEY=your_api_key_here
|
|
94
117
|
|
|
95
|
-
# Optional - override
|
|
96
|
-
POLKA_API_PROVIDER=deepseek
|
|
118
|
+
# Optional - override defaults
|
|
119
|
+
POLKA_API_PROVIDER=deepseek # or anthropic, openrouter, ollama
|
|
97
120
|
POLKA_AI_MODEL_ID=deepseek-chat # or claude-3-sonnet-20240229
|
|
98
121
|
```
|
|
99
122
|
|
|
100
|
-
|
|
123
|
+
### Project Configuration
|
|
124
|
+
|
|
125
|
+
Create `.polkacodes.yml` in your project root:
|
|
126
|
+
|
|
127
|
+
```yaml
|
|
128
|
+
# AI provider settings
|
|
129
|
+
provider: deepseek # default provider
|
|
130
|
+
modelId: deepseek-chat # default model
|
|
131
|
+
|
|
132
|
+
# Custom commands available to AI
|
|
133
|
+
commands:
|
|
134
|
+
test:
|
|
135
|
+
command: bun test
|
|
136
|
+
description: Run tests. Pass file path to run specific tests.
|
|
137
|
+
check:
|
|
138
|
+
command: bun typecheck
|
|
139
|
+
description: Run type checker
|
|
140
|
+
format:
|
|
141
|
+
command: bun fix
|
|
142
|
+
description: Format code
|
|
143
|
+
|
|
144
|
+
# Additional rules/guidelines for AI
|
|
145
|
+
rules: |
|
|
146
|
+
- Use TypeScript for all new files
|
|
147
|
+
- Follow project's existing code style
|
|
148
|
+
- Add tests for new features
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Global vs Local Configuration
|
|
152
|
+
|
|
153
|
+
- Global config (`~/.config/polkacodes/config.yml`): Store API keys and default settings
|
|
154
|
+
- Local config (`.polkacodes.yml`): Project-specific settings and commands
|
|
101
155
|
|
|
156
|
+
## Features
|
|
157
|
+
|
|
158
|
+
- 🤖 Multiple AI provider support
|
|
159
|
+
- 💬 Interactive chat mode
|
|
160
|
+
- 🎯 Task-focused commands
|
|
161
|
+
- 🔄 Git workflow integration
|
|
162
|
+
- 📊 Project analysis and configuration
|
|
163
|
+
- 🛠️ Custom command integration
|
|
164
|
+
- 🔑 Secure API key management
|
|
165
|
+
- 📝 Detailed logging with `--verbose`
|
|
166
|
+
|
|
167
|
+
## Usage Tips
|
|
168
|
+
|
|
169
|
+
1. Use interactive mode for complex tasks:
|
|
170
|
+
```bash
|
|
171
|
+
polka chat
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
2. Pipe tasks for automation:
|
|
175
|
+
```bash
|
|
176
|
+
echo "update dependencies" | polka task
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
3. Combine with git workflow:
|
|
180
|
+
```bash
|
|
181
|
+
git add . && polka commit && polka pr
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
4. Monitor AI usage:
|
|
185
|
+
```bash
|
|
186
|
+
polka task "refactor auth" --verbose
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## Requirements
|
|
190
|
+
|
|
191
|
+
- Node.js 18+
|
|
192
|
+
- Git (for commit/PR features)
|
|
193
|
+
- GitHub CLI (for PR creation)
|
|
194
|
+
|
|
195
|
+
---
|
|
102
196
|
|
|
103
|
-
*This README was generated by polka.codes*
|
|
197
|
+
*This README was generated by polka.codes*
|
package/dist/index.js
CHANGED
|
@@ -24629,7 +24629,7 @@ var {
|
|
|
24629
24629
|
Help
|
|
24630
24630
|
} = import__.default;
|
|
24631
24631
|
// package.json
|
|
24632
|
-
var version = "0.6.
|
|
24632
|
+
var version = "0.6.7";
|
|
24633
24633
|
|
|
24634
24634
|
// ../../node_modules/@anthropic-ai/sdk/version.mjs
|
|
24635
24635
|
var VERSION = "0.36.2";
|
|
@@ -33291,7 +33291,8 @@ var toolInfo = {
|
|
|
33291
33291
|
}
|
|
33292
33292
|
]
|
|
33293
33293
|
}
|
|
33294
|
-
]
|
|
33294
|
+
],
|
|
33295
|
+
permissionLevel: 0 /* None */
|
|
33295
33296
|
};
|
|
33296
33297
|
var handler = async (provider, args2) => {
|
|
33297
33298
|
if (!provider.askFollowupQuestion) {
|
|
@@ -33339,7 +33340,8 @@ var toolInfo2 = {
|
|
|
33339
33340
|
}
|
|
33340
33341
|
]
|
|
33341
33342
|
}
|
|
33342
|
-
]
|
|
33343
|
+
],
|
|
33344
|
+
permissionLevel: 0 /* None */
|
|
33343
33345
|
};
|
|
33344
33346
|
var handler2 = async (provider, args2) => {
|
|
33345
33347
|
const result = getString(args2, "result");
|
|
@@ -33415,7 +33417,8 @@ var toolInfo3 = {
|
|
|
33415
33417
|
}
|
|
33416
33418
|
]
|
|
33417
33419
|
}
|
|
33418
|
-
]
|
|
33420
|
+
],
|
|
33421
|
+
permissionLevel: 0 /* None */
|
|
33419
33422
|
};
|
|
33420
33423
|
var handler3 = async (_provider, args2) => {
|
|
33421
33424
|
const agentName = getString(args2, "agent_name");
|
|
@@ -33470,7 +33473,8 @@ var toolInfo4 = {
|
|
|
33470
33473
|
}
|
|
33471
33474
|
]
|
|
33472
33475
|
}
|
|
33473
|
-
]
|
|
33476
|
+
],
|
|
33477
|
+
permissionLevel: 3 /* Arbitrary */
|
|
33474
33478
|
};
|
|
33475
33479
|
var handler4 = async (provider, args2) => {
|
|
33476
33480
|
if (!provider.executeCommand) {
|
|
@@ -33512,7 +33516,7 @@ var executeCommand_default = {
|
|
|
33512
33516
|
// ../core/src/tools/listCodeDefinitionNames.ts
|
|
33513
33517
|
var toolInfo5 = {
|
|
33514
33518
|
name: "list_code_definition_names",
|
|
33515
|
-
description: "Request to list definition names (classes, functions, methods, etc.) used in a
|
|
33519
|
+
description: "Request to list definition names (classes, functions, methods, etc.) used for all files in a directory. This tool provides insights into the codebase structure and important constructs, encapsulating high-level concepts and relationships that are crucial for understanding the overall architecture.",
|
|
33516
33520
|
parameters: [
|
|
33517
33521
|
{
|
|
33518
33522
|
name: "path",
|
|
@@ -33520,7 +33524,19 @@ var toolInfo5 = {
|
|
|
33520
33524
|
required: true,
|
|
33521
33525
|
usageValue: "Directory path here"
|
|
33522
33526
|
}
|
|
33523
|
-
]
|
|
33527
|
+
],
|
|
33528
|
+
examples: [
|
|
33529
|
+
{
|
|
33530
|
+
description: "Request to list code definition names in a directory",
|
|
33531
|
+
parameters: [
|
|
33532
|
+
{
|
|
33533
|
+
name: "path",
|
|
33534
|
+
value: "src/utils"
|
|
33535
|
+
}
|
|
33536
|
+
]
|
|
33537
|
+
}
|
|
33538
|
+
],
|
|
33539
|
+
permissionLevel: 1 /* Read */
|
|
33524
33540
|
};
|
|
33525
33541
|
var handler5 = async (provider, args2) => {
|
|
33526
33542
|
if (!provider.listCodeDefinitionNames) {
|
|
@@ -33585,7 +33601,8 @@ var toolInfo6 = {
|
|
|
33585
33601
|
}
|
|
33586
33602
|
]
|
|
33587
33603
|
}
|
|
33588
|
-
]
|
|
33604
|
+
],
|
|
33605
|
+
permissionLevel: 1 /* Read */
|
|
33589
33606
|
};
|
|
33590
33607
|
var handler6 = async (provider, args2) => {
|
|
33591
33608
|
if (!provider.listFiles) {
|
|
@@ -33647,7 +33664,8 @@ var toolInfo7 = {
|
|
|
33647
33664
|
}
|
|
33648
33665
|
]
|
|
33649
33666
|
}
|
|
33650
|
-
]
|
|
33667
|
+
],
|
|
33668
|
+
permissionLevel: 1 /* Read */
|
|
33651
33669
|
};
|
|
33652
33670
|
var handler7 = async (provider, args2) => {
|
|
33653
33671
|
if (!provider.readFile) {
|
|
@@ -33764,7 +33782,8 @@ return (
|
|
|
33764
33782
|
}
|
|
33765
33783
|
]
|
|
33766
33784
|
}
|
|
33767
|
-
]
|
|
33785
|
+
],
|
|
33786
|
+
permissionLevel: 2 /* Write */
|
|
33768
33787
|
};
|
|
33769
33788
|
var handler8 = async (provider, args2) => {
|
|
33770
33789
|
if (!provider.readFile || !provider.writeFile) {
|
|
@@ -33833,7 +33852,8 @@ var toolInfo9 = {
|
|
|
33833
33852
|
}
|
|
33834
33853
|
]
|
|
33835
33854
|
}
|
|
33836
|
-
]
|
|
33855
|
+
],
|
|
33856
|
+
permissionLevel: 1 /* Read */
|
|
33837
33857
|
};
|
|
33838
33858
|
var handler9 = async (provider, args2) => {
|
|
33839
33859
|
if (!provider.searchFiles) {
|
|
@@ -33909,7 +33929,8 @@ export default App;
|
|
|
33909
33929
|
}
|
|
33910
33930
|
]
|
|
33911
33931
|
}
|
|
33912
|
-
]
|
|
33932
|
+
],
|
|
33933
|
+
permissionLevel: 2 /* Write */
|
|
33913
33934
|
};
|
|
33914
33935
|
var handler10 = async (provider, args2) => {
|
|
33915
33936
|
if (!provider.writeFile) {
|
|
@@ -33986,7 +34007,8 @@ var toolInfo11 = {
|
|
|
33986
34007
|
}
|
|
33987
34008
|
]
|
|
33988
34009
|
}
|
|
33989
|
-
]
|
|
34010
|
+
],
|
|
34011
|
+
permissionLevel: 0 /* None */
|
|
33990
34012
|
};
|
|
33991
34013
|
var handler11 = async (_provider, args2) => {
|
|
33992
34014
|
const agentName = getString(args2, "agent_name");
|
|
@@ -34031,7 +34053,8 @@ var toolInfo12 = {
|
|
|
34031
34053
|
}
|
|
34032
34054
|
]
|
|
34033
34055
|
}
|
|
34034
|
-
]
|
|
34056
|
+
],
|
|
34057
|
+
permissionLevel: 2 /* Write */
|
|
34035
34058
|
};
|
|
34036
34059
|
var handler12 = async (provider, args2) => {
|
|
34037
34060
|
if (!provider.removeFile) {
|
|
@@ -34087,7 +34110,8 @@ var toolInfo13 = {
|
|
|
34087
34110
|
}
|
|
34088
34111
|
]
|
|
34089
34112
|
}
|
|
34090
|
-
]
|
|
34113
|
+
],
|
|
34114
|
+
permissionLevel: 2 /* Write */
|
|
34091
34115
|
};
|
|
34092
34116
|
var handler13 = async (provider, args2) => {
|
|
34093
34117
|
if (!provider.renameFile) {
|
|
@@ -34112,8 +34136,8 @@ var renameFile_default = {
|
|
|
34112
34136
|
handler: handler13,
|
|
34113
34137
|
isAvailable: isAvailable13
|
|
34114
34138
|
};
|
|
34115
|
-
// ../core/src/
|
|
34116
|
-
var getAvailableTools = (provider2, allTools2, hasAgent) => {
|
|
34139
|
+
// ../core/src/getAvailableTools.ts
|
|
34140
|
+
var getAvailableTools = (provider2, allTools2, hasAgent, permissionLevel) => {
|
|
34117
34141
|
const tools = [];
|
|
34118
34142
|
for (const tool of allTools2) {
|
|
34119
34143
|
if (!hasAgent) {
|
|
@@ -34123,7 +34147,7 @@ var getAvailableTools = (provider2, allTools2, hasAgent) => {
|
|
|
34123
34147
|
continue;
|
|
34124
34148
|
}
|
|
34125
34149
|
}
|
|
34126
|
-
if (tool.isAvailable(provider2)) {
|
|
34150
|
+
if (tool.isAvailable(provider2) && tool.permissionLevel <= permissionLevel) {
|
|
34127
34151
|
tools.push(tool);
|
|
34128
34152
|
}
|
|
34129
34153
|
}
|
|
@@ -34438,6 +34462,9 @@ ${agents}`;
|
|
|
34438
34462
|
return await this.#processLoop(userMessage);
|
|
34439
34463
|
}
|
|
34440
34464
|
async#request(userMessage) {
|
|
34465
|
+
if (!userMessage) {
|
|
34466
|
+
throw new Error("userMessage is missing");
|
|
34467
|
+
}
|
|
34441
34468
|
await this.#callback({ kind: "StartRequest" /* StartRequest */, agent: this, userMessage });
|
|
34442
34469
|
this.messages.push({
|
|
34443
34470
|
role: "user",
|
|
@@ -34486,6 +34513,12 @@ ${agents}`;
|
|
|
34486
34513
|
case "text":
|
|
34487
34514
|
break;
|
|
34488
34515
|
case "tool_use": {
|
|
34516
|
+
if (toolReponses.length > 0) {
|
|
34517
|
+
const toolLevel = this.handlers[content.name].permissionLevel;
|
|
34518
|
+
if (toolLevel > 1 /* Read */) {
|
|
34519
|
+
break outer;
|
|
34520
|
+
}
|
|
34521
|
+
}
|
|
34489
34522
|
await this.#callback({ kind: "ToolUse" /* ToolUse */, agent: this, tool: content.name });
|
|
34490
34523
|
const toolResp = await this.#invokeTool(content.name, content.params);
|
|
34491
34524
|
switch (toolResp.type) {
|
|
@@ -34508,7 +34541,7 @@ ${agents}`;
|
|
|
34508
34541
|
return { exit: toolResp };
|
|
34509
34542
|
case "HandOver" /* HandOver */:
|
|
34510
34543
|
if (toolReponses.length > 0) {
|
|
34511
|
-
|
|
34544
|
+
break outer;
|
|
34512
34545
|
}
|
|
34513
34546
|
await this.#callback({
|
|
34514
34547
|
kind: "ToolHandOver" /* ToolHandOver */,
|
|
@@ -34539,7 +34572,7 @@ ${agents}`;
|
|
|
34539
34572
|
}
|
|
34540
34573
|
}
|
|
34541
34574
|
}
|
|
34542
|
-
if (toolReponses.length === 0
|
|
34575
|
+
if (toolReponses.length === 0) {
|
|
34543
34576
|
return { replay: responsePrompts.requireUseTool };
|
|
34544
34577
|
}
|
|
34545
34578
|
const finalResp = toolReponses.map(({ tool, response: response2 }) => responsePrompts.toolResults(tool, response2)).join(`
|
|
@@ -34611,18 +34644,8 @@ ${interactiveMode(interactive)}
|
|
|
34611
34644
|
// ../core/src/Agent/AnalyzerAgent/index.ts
|
|
34612
34645
|
class AnalyzerAgent extends AgentBase {
|
|
34613
34646
|
constructor(options) {
|
|
34614
|
-
const
|
|
34615
|
-
|
|
34616
|
-
askFollowupQuestion_default,
|
|
34617
|
-
attemptCompletion_default,
|
|
34618
|
-
handOver_default,
|
|
34619
|
-
delegate_default,
|
|
34620
|
-
listCodeDefinitionNames_default,
|
|
34621
|
-
listFiles_default,
|
|
34622
|
-
readFile_default,
|
|
34623
|
-
searchFiles_default
|
|
34624
|
-
];
|
|
34625
|
-
const tools = getAvailableTools(options.provider, agentTools, (options.agents?.length ?? 0) > 0);
|
|
34647
|
+
const combinedTools = [...options.additionalTools ?? [], ...Object.values(exports_allTools)];
|
|
34648
|
+
const tools = getAvailableTools(options.provider, combinedTools, (options.agents?.length ?? 0) > 0, 1 /* Read */);
|
|
34626
34649
|
const toolNamePrefix = "tool_";
|
|
34627
34650
|
const systemPrompt = fullSystemPrompt({
|
|
34628
34651
|
os: options.os
|
|
@@ -34711,18 +34734,8 @@ ${interactiveMode(interactive)}
|
|
|
34711
34734
|
// ../core/src/Agent/ArchitectAgent/index.ts
|
|
34712
34735
|
class ArchitectAgent extends AgentBase {
|
|
34713
34736
|
constructor(options) {
|
|
34714
|
-
const
|
|
34715
|
-
|
|
34716
|
-
askFollowupQuestion_default,
|
|
34717
|
-
attemptCompletion_default,
|
|
34718
|
-
handOver_default,
|
|
34719
|
-
delegate_default,
|
|
34720
|
-
listCodeDefinitionNames_default,
|
|
34721
|
-
listFiles_default,
|
|
34722
|
-
readFile_default,
|
|
34723
|
-
searchFiles_default
|
|
34724
|
-
];
|
|
34725
|
-
const tools = getAvailableTools(options.provider, agentTools, (options.agents?.length ?? 0) > 0);
|
|
34737
|
+
const combinedTools = [...options.additionalTools ?? [], ...Object.values(exports_allTools)];
|
|
34738
|
+
const tools = getAvailableTools(options.provider, combinedTools, (options.agents?.length ?? 0) > 0, 1 /* Read */);
|
|
34726
34739
|
const toolNamePrefix = "tool_";
|
|
34727
34740
|
const systemPrompt = fullSystemPrompt2({
|
|
34728
34741
|
os: options.os
|
|
@@ -34835,7 +34848,7 @@ class CodeFixerAgent extends AgentBase {
|
|
|
34835
34848
|
#retryCount = 0;
|
|
34836
34849
|
constructor(options) {
|
|
34837
34850
|
const combinedTools = [...options.additionalTools ?? [], ...Object.values(exports_allTools)];
|
|
34838
|
-
const tools = getAvailableTools(options.provider, combinedTools, (options.agents?.length ?? 0) > 0);
|
|
34851
|
+
const tools = getAvailableTools(options.provider, combinedTools, (options.agents?.length ?? 0) > 0, 3 /* Arbitrary */);
|
|
34839
34852
|
const toolNamePrefix = "tool_";
|
|
34840
34853
|
const systemPrompt = fullSystemPrompt3({
|
|
34841
34854
|
os: options.os
|
|
@@ -35023,7 +35036,7 @@ ${interactiveMode(interactive)}
|
|
|
35023
35036
|
class CoderAgent extends AgentBase {
|
|
35024
35037
|
constructor(options) {
|
|
35025
35038
|
const combinedTools = [...options.additionalTools ?? [], ...Object.values(exports_allTools)];
|
|
35026
|
-
const tools = getAvailableTools(options.provider, combinedTools, (options.agents?.length ?? 0) > 0);
|
|
35039
|
+
const tools = getAvailableTools(options.provider, combinedTools, (options.agents?.length ?? 0) > 0, 3 /* Arbitrary */);
|
|
35027
35040
|
const toolNamePrefix = "tool_";
|
|
35028
35041
|
const systemPrompt = fullSystemPrompt4({
|
|
35029
35042
|
os: options.os
|
|
@@ -45355,6 +45368,7 @@ var agentSchema = providerModelSchema.extend({
|
|
|
45355
45368
|
}).optional()
|
|
45356
45369
|
});
|
|
45357
45370
|
var configSchema = z2.object({
|
|
45371
|
+
agent: z2.string().optional(),
|
|
45358
45372
|
providers: z2.record(z2.string(), z2.object({
|
|
45359
45373
|
apiKey: z2.string().optional(),
|
|
45360
45374
|
defaultModel: z2.string().optional()
|
|
@@ -45462,11 +45476,25 @@ var readConfig = (path4) => {
|
|
|
45462
45476
|
return configSchema.parse(config);
|
|
45463
45477
|
};
|
|
45464
45478
|
|
|
45479
|
+
// src/env.ts
|
|
45480
|
+
function getEnv(override) {
|
|
45481
|
+
return {
|
|
45482
|
+
POLKA_API_PROVIDER: process.env.POLKA_API_PROVIDER,
|
|
45483
|
+
POLKA_MODEL: process.env.POLKA_MODEL,
|
|
45484
|
+
POLKA_API_KEY: process.env.POLKA_API_KEY,
|
|
45485
|
+
POLKA_BUDGET: process.env.POLKA_BUDGET,
|
|
45486
|
+
ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY,
|
|
45487
|
+
DEEPSEEK_API_KEY: process.env.DEEPSEEK_API_KEY,
|
|
45488
|
+
OPENROUTER_API_KEY: process.env.OPENROUTER_API_KEY,
|
|
45489
|
+
...override
|
|
45490
|
+
};
|
|
45491
|
+
}
|
|
45492
|
+
|
|
45465
45493
|
// src/options.ts
|
|
45466
45494
|
function addSharedOptions(command) {
|
|
45467
|
-
return command.option("-c --config <paths>", "Path to config file(s)", (value, prev) => prev.concat(value), []).option("--api-provider <provider>", "API provider").option("--model <model>", "Model ID").option("--api-key <key>", "API key").option("--max-messages <iterations>", "Maximum number of messages to send. Default to 50", Number.parseInt, 50).option("--budget <budget>", "Budget for the AI service. Default to $
|
|
45495
|
+
return command.option("-c --config <paths>", "Path to config file(s)", (value, prev) => prev.concat(value), []).option("--api-provider <provider>", "API provider").option("--model <model>", "Model ID").option("--api-key <key>", "API key").option("--max-messages <iterations>", "Maximum number of messages to send. Default to 50", Number.parseInt, 50).option("--budget <budget>", "Budget for the AI service. Default to $10", Number.parseFloat).option("-v --verbose", "Enable verbose output. Use -v for level 1, -vv for level 2", (value, prev) => prev + 1, 0).option("-d --base-dir <path>", "Base directory to run commands in").option("--agent <agent>", "Initial agent to use (default: architect)");
|
|
45468
45496
|
}
|
|
45469
|
-
function parseOptions(options, cwdArg, home = os2.homedir()) {
|
|
45497
|
+
function parseOptions(options, cwdArg, home = os2.homedir(), env = getEnv()) {
|
|
45470
45498
|
let cwd = cwdArg;
|
|
45471
45499
|
if (options.baseDir) {
|
|
45472
45500
|
process.chdir(options.baseDir);
|
|
@@ -45476,23 +45504,26 @@ function parseOptions(options, cwdArg, home = os2.homedir()) {
|
|
|
45476
45504
|
cwd = process.cwd();
|
|
45477
45505
|
}
|
|
45478
45506
|
const config = loadConfig(options.config, cwd, home) ?? {};
|
|
45479
|
-
const defaultProvider = options.apiProvider ||
|
|
45480
|
-
const defaultModel = options.model ||
|
|
45507
|
+
const defaultProvider = options.apiProvider || env.POLKA_API_PROVIDER || config.defaultProvider;
|
|
45508
|
+
const defaultModel = options.model || env.POLKA_MODEL || config.defaultModel;
|
|
45481
45509
|
if (defaultProvider && defaultModel) {
|
|
45482
45510
|
import_lodash2.set(config, ["providers", defaultProvider, "defaultModel"], defaultModel);
|
|
45483
45511
|
}
|
|
45484
|
-
const apiKey = options.apiKey ||
|
|
45512
|
+
const apiKey = options.apiKey || env.POLKA_API_KEY;
|
|
45485
45513
|
if (apiKey) {
|
|
45486
45514
|
if (!defaultProvider) {
|
|
45487
45515
|
throw new Error("Must specify a provider if providing an API key");
|
|
45488
45516
|
}
|
|
45489
45517
|
import_lodash2.set(config, ["providers", defaultProvider, "apiKey"], apiKey);
|
|
45490
45518
|
}
|
|
45491
|
-
|
|
45492
|
-
|
|
45493
|
-
|
|
45494
|
-
|
|
45495
|
-
|
|
45519
|
+
if (env.ANTHROPIC_API_KEY) {
|
|
45520
|
+
import_lodash2.set(config, ["providers", "anthropic" /* Anthropic */, "apiKey"], env.ANTHROPIC_API_KEY);
|
|
45521
|
+
}
|
|
45522
|
+
if (env.DEEPSEEK_API_KEY) {
|
|
45523
|
+
import_lodash2.set(config, ["providers", "deepseek" /* DeepSeek */, "apiKey"], env.DEEPSEEK_API_KEY);
|
|
45524
|
+
}
|
|
45525
|
+
if (env.OPENROUTER_API_KEY) {
|
|
45526
|
+
import_lodash2.set(config, ["providers", "openrouter" /* OpenRouter */, "apiKey"], env.OPENROUTER_API_KEY);
|
|
45496
45527
|
}
|
|
45497
45528
|
const providerConfig = new ApiProviderConfig({
|
|
45498
45529
|
defaultProvider,
|
|
@@ -45500,10 +45531,11 @@ function parseOptions(options, cwdArg, home = os2.homedir()) {
|
|
|
45500
45531
|
});
|
|
45501
45532
|
return {
|
|
45502
45533
|
maxMessageCount: options.maxMessageCount ?? config.maxMessageCount ?? 30,
|
|
45503
|
-
budget: options.budget ?? Number(
|
|
45534
|
+
budget: options.budget ?? (env.POLKA_BUDGET ? Number.parseFloat(env.POLKA_BUDGET) : undefined) ?? config.budget ?? 10,
|
|
45504
45535
|
verbose: options.verbose ?? 0,
|
|
45505
45536
|
config,
|
|
45506
|
-
providerConfig
|
|
45537
|
+
providerConfig,
|
|
45538
|
+
agent: options.agent ?? config.agent ?? "architect"
|
|
45507
45539
|
};
|
|
45508
45540
|
}
|
|
45509
45541
|
|
|
@@ -46099,13 +46131,12 @@ ${event.systemPrompt}`);
|
|
|
46099
46131
|
// src/commands/chat.ts
|
|
46100
46132
|
var runChat = async (opts, command) => {
|
|
46101
46133
|
const options = command?.parent?.opts() ?? opts ?? {};
|
|
46102
|
-
const { config, providerConfig, maxMessageCount, verbose, budget } = parseOptions(options);
|
|
46134
|
+
const { config, providerConfig, maxMessageCount, verbose, budget, agent } = parseOptions(options);
|
|
46103
46135
|
if (!process.stdin.isTTY) {
|
|
46104
46136
|
console.error("Error: Terminal is not interactive. Please run this command in an interactive terminal.");
|
|
46105
46137
|
process.exit(1);
|
|
46106
46138
|
}
|
|
46107
|
-
|
|
46108
|
-
let { provider: provider2, model, apiKey } = providerConfig.getConfigForAgent(startAgent) ?? {};
|
|
46139
|
+
let { provider: provider2, model, apiKey } = providerConfig.getConfigForAgent(agent) ?? {};
|
|
46109
46140
|
if (!provider2) {
|
|
46110
46141
|
const newConfig = await configPrompt({ provider: provider2, model, apiKey });
|
|
46111
46142
|
provider2 = newConfig.provider;
|
|
@@ -46133,7 +46164,7 @@ var runChat = async (opts, command) => {
|
|
|
46133
46164
|
const reason = await runner.continueTask(message);
|
|
46134
46165
|
exitReason = reason;
|
|
46135
46166
|
} else {
|
|
46136
|
-
const reason = await runner.startTask(message);
|
|
46167
|
+
const reason = await runner.startTask(message, agent);
|
|
46137
46168
|
exitReason = reason;
|
|
46138
46169
|
}
|
|
46139
46170
|
switch (exitReason.type) {
|
|
@@ -47161,9 +47192,8 @@ async function runTask(taskArg, _options, command) {
|
|
|
47161
47192
|
process.exit(1);
|
|
47162
47193
|
}
|
|
47163
47194
|
}
|
|
47164
|
-
const { config, providerConfig, verbose, maxMessageCount, budget } = parseOptions(command.opts());
|
|
47165
|
-
const
|
|
47166
|
-
const { provider: provider2, model } = providerConfig.getConfigForAgent(startAgent) ?? {};
|
|
47195
|
+
const { config, providerConfig, verbose, maxMessageCount, budget, agent } = parseOptions(command.opts());
|
|
47196
|
+
const { provider: provider2, model } = providerConfig.getConfigForAgent(agent) ?? {};
|
|
47167
47197
|
if (!provider2 || !model) {
|
|
47168
47198
|
console.error("Provider and model must be configured");
|
|
47169
47199
|
process.exit(1);
|
|
@@ -47179,7 +47209,7 @@ async function runTask(taskArg, _options, command) {
|
|
|
47179
47209
|
eventCallback: printEvent(verbose),
|
|
47180
47210
|
enableCache: true
|
|
47181
47211
|
});
|
|
47182
|
-
await runner.startTask(task,
|
|
47212
|
+
await runner.startTask(task, agent);
|
|
47183
47213
|
runner.printUsage();
|
|
47184
47214
|
}
|
|
47185
47215
|
|