@polka-codes/cli 0.5.3 → 0.6.0
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 +6 -6
- package/dist/index.js +103 -30
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -32,13 +32,13 @@ npx @polka-codes/cli
|
|
|
32
32
|
polka-codes
|
|
33
33
|
|
|
34
34
|
# Run specific task
|
|
35
|
-
|
|
35
|
+
pokla task "improve readme"
|
|
36
36
|
|
|
37
37
|
# Create config file
|
|
38
|
-
|
|
38
|
+
pokla config
|
|
39
39
|
|
|
40
40
|
# Generate commit message
|
|
41
|
-
|
|
41
|
+
pokla commit
|
|
42
42
|
```
|
|
43
43
|
|
|
44
44
|
### Commit Command
|
|
@@ -47,10 +47,10 @@ The `commit` subcommand helps generate meaningful commit messages based on your
|
|
|
47
47
|
|
|
48
48
|
```bash
|
|
49
49
|
# Generate commit message for staged changes
|
|
50
|
-
|
|
50
|
+
pokla commit
|
|
51
51
|
|
|
52
52
|
# Generate commit message with specific context
|
|
53
|
-
|
|
53
|
+
pokla commit "closes issue #123"
|
|
54
54
|
|
|
55
55
|
```
|
|
56
56
|
|
|
@@ -59,7 +59,7 @@ polka-codes commit "closes issue #123"
|
|
|
59
59
|
Create a GitHub pull request with AI-generated details:
|
|
60
60
|
|
|
61
61
|
```bash
|
|
62
|
-
|
|
62
|
+
pokla pr "optional message. e.g. closes #123"
|
|
63
63
|
```
|
|
64
64
|
|
|
65
65
|
### Configuration
|
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.
|
|
24632
|
+
var version = "0.6.0";
|
|
24633
24633
|
|
|
24634
24634
|
// ../../node_modules/@anthropic-ai/sdk/version.mjs
|
|
24635
24635
|
var VERSION = "0.36.2";
|
|
@@ -35150,6 +35150,9 @@ class MultiAgent {
|
|
|
35150
35150
|
const exitReason = await this.#agents[this.#agents.length - 1].continueTask(userMessage);
|
|
35151
35151
|
return await this.#handleTaskResult(exitReason);
|
|
35152
35152
|
}
|
|
35153
|
+
get hasActiveAgent() {
|
|
35154
|
+
return this.#agents.length > 0;
|
|
35155
|
+
}
|
|
35153
35156
|
}
|
|
35154
35157
|
|
|
35155
35158
|
// ../core/src/Agent/index.ts
|
|
@@ -35180,7 +35183,7 @@ var prompt = `You are an AiTool designed to assist users in creating new project
|
|
|
35180
35183
|
- Based on the collected information, generate a .polkacodes.yml configuration file that includes:
|
|
35181
35184
|
- scripts section with common development commands (test, format, check, etc.)
|
|
35182
35185
|
- rules section reflecting project conventions and tools
|
|
35183
|
-
- excludeFiles section for sensitive
|
|
35186
|
+
- excludeFiles section for sensitive files only
|
|
35184
35187
|
- Example structure:
|
|
35185
35188
|
\`\`\`yaml
|
|
35186
35189
|
scripts:
|
|
@@ -35412,7 +35415,6 @@ var prompt4 = `You are an analyzer agent responsible for examining project files
|
|
|
35412
35415
|
- Code style tools and rules
|
|
35413
35416
|
- Project structure and conventions
|
|
35414
35417
|
- Common development workflows
|
|
35415
|
-
- .gitignore patterns and sensitive/generated files
|
|
35416
35418
|
|
|
35417
35419
|
2. Generate a YAML configuration that captures:
|
|
35418
35420
|
- scripts section based on package.json scripts and CI workflows. If applicable, generate following scripts:
|
|
@@ -35421,7 +35423,7 @@ var prompt4 = `You are an analyzer agent responsible for examining project files
|
|
|
35421
35423
|
- test: Run tests using a test runner tool
|
|
35422
35424
|
- include other relevant scripts based on project conventions, tools, and patterns
|
|
35423
35425
|
- rules section based on project conventions, tools, and patterns
|
|
35424
|
-
- excludeFiles section for
|
|
35426
|
+
- excludeFiles section for sensitive files
|
|
35425
35427
|
|
|
35426
35428
|
3. Use tool_attempt_completion to return the final configuration in this format:
|
|
35427
35429
|
|
|
@@ -35445,10 +35447,6 @@ excludeFiles:
|
|
|
35445
35447
|
- ".env"
|
|
35446
35448
|
- ".env.*"
|
|
35447
35449
|
- ".npmrc"
|
|
35448
|
-
# Generated files
|
|
35449
|
-
- "package-lock.json"
|
|
35450
|
-
- "yarn.lock"
|
|
35451
|
-
- "pnpm-lock.yaml"
|
|
35452
35450
|
</tool_parameter_result>
|
|
35453
35451
|
</tool_attempt_completion>
|
|
35454
35452
|
|
|
@@ -35476,7 +35474,7 @@ var generateProjectConfig_default = {
|
|
|
35476
35474
|
return "";
|
|
35477
35475
|
},
|
|
35478
35476
|
parseOutput: (output) => {
|
|
35479
|
-
return output
|
|
35477
|
+
return output;
|
|
35480
35478
|
},
|
|
35481
35479
|
agent: "analyzer"
|
|
35482
35480
|
};
|
|
@@ -41183,6 +41181,9 @@ ${fileList.join(`
|
|
|
41183
41181
|
async continueTask(message) {
|
|
41184
41182
|
return await this.multiAgent.continueTask(message);
|
|
41185
41183
|
}
|
|
41184
|
+
get hasActiveAgent() {
|
|
41185
|
+
return this.multiAgent.hasActiveAgent;
|
|
41186
|
+
}
|
|
41186
41187
|
get usage() {
|
|
41187
41188
|
return this.#usageMeter.usage;
|
|
41188
41189
|
}
|
|
@@ -45446,10 +45447,18 @@ var readConfig = (path4) => {
|
|
|
45446
45447
|
|
|
45447
45448
|
// src/options.ts
|
|
45448
45449
|
function addSharedOptions(command) {
|
|
45449
|
-
return command.option("-c --config <path>", "Path to config file").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 $1000", Number.parseFloat, 1000).option("-v --verbose", "Enable verbose output. Use -v for level 1, -vv for level 2", (value, prev) => prev + 1, 0);
|
|
45450
|
-
}
|
|
45451
|
-
function parseOptions(options,
|
|
45452
|
-
|
|
45450
|
+
return command.option("-c --config <path>", "Path to config file").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 $1000", Number.parseFloat, 1000).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");
|
|
45451
|
+
}
|
|
45452
|
+
function parseOptions(options, cwdArg, home = os2.homedir()) {
|
|
45453
|
+
let cwd = cwdArg;
|
|
45454
|
+
if (options.baseDir) {
|
|
45455
|
+
process.chdir(options.baseDir);
|
|
45456
|
+
cwd = options.baseDir;
|
|
45457
|
+
console.log("Changed working directory to", cwd);
|
|
45458
|
+
} else {
|
|
45459
|
+
cwd = process.cwd();
|
|
45460
|
+
}
|
|
45461
|
+
const config = loadConfig(options.config, cwd, home) ?? {};
|
|
45453
45462
|
const defaultProvider = options.apiProvider || process.env.POLKA_API_PROVIDER || config.defaultProvider;
|
|
45454
45463
|
const defaultModel = options.model || process.env.POLKA_MODEL || config.defaultModel;
|
|
45455
45464
|
if (defaultProvider && defaultModel) {
|
|
@@ -46100,16 +46109,14 @@ var runChat = async (opts, command) => {
|
|
|
46100
46109
|
eventCallback: printEvent(verbose),
|
|
46101
46110
|
enableCache: true
|
|
46102
46111
|
});
|
|
46103
|
-
let started = false;
|
|
46104
46112
|
const chat2 = new Chat3({
|
|
46105
46113
|
onMessage: async (message) => {
|
|
46106
46114
|
let exitReason;
|
|
46107
|
-
if (
|
|
46115
|
+
if (runner.hasActiveAgent) {
|
|
46108
46116
|
const reason = await runner.continueTask(message);
|
|
46109
46117
|
exitReason = reason;
|
|
46110
46118
|
} else {
|
|
46111
46119
|
const reason = await runner.startTask(message);
|
|
46112
|
-
started = true;
|
|
46113
46120
|
exitReason = reason;
|
|
46114
46121
|
}
|
|
46115
46122
|
switch (exitReason.type) {
|
|
@@ -46752,7 +46759,7 @@ var commitCommand = new Command("commit").description("Create a commit with AI-g
|
|
|
46752
46759
|
console.log("Provider:", provider2);
|
|
46753
46760
|
console.log("Model:", model);
|
|
46754
46761
|
if (!provider2) {
|
|
46755
|
-
console.error('Error: No provider specified. Please run "
|
|
46762
|
+
console.error('Error: No provider specified. Please run "pokla config" to configure your AI provider.');
|
|
46756
46763
|
process.exit(1);
|
|
46757
46764
|
}
|
|
46758
46765
|
const usage = new UsageMeter;
|
|
@@ -46803,18 +46810,89 @@ ${result.response}`);
|
|
|
46803
46810
|
}
|
|
46804
46811
|
});
|
|
46805
46812
|
|
|
46813
|
+
// src/commands/create.ts
|
|
46814
|
+
import { existsSync as existsSync2 } from "node:fs";
|
|
46815
|
+
import { mkdir as mkdir2, stat } from "node:fs/promises";
|
|
46816
|
+
import { join as join4 } from "node:path";
|
|
46817
|
+
var askForPath = async (projectName) => {
|
|
46818
|
+
let targetPath = join4(process.cwd(), projectName);
|
|
46819
|
+
while (true) {
|
|
46820
|
+
const confirmPath = await esm_default2({
|
|
46821
|
+
message: `Do you want to create project at ${targetPath}?`,
|
|
46822
|
+
default: true
|
|
46823
|
+
});
|
|
46824
|
+
if (confirmPath) {
|
|
46825
|
+
if (existsSync2(targetPath)) {
|
|
46826
|
+
const targetStat = await stat(targetPath);
|
|
46827
|
+
if (targetStat.isDirectory()) {
|
|
46828
|
+
const confirmPath2 = await esm_default2({
|
|
46829
|
+
message: `Directory ${targetPath} already exists. Do you want to overwrite it?`,
|
|
46830
|
+
default: true
|
|
46831
|
+
});
|
|
46832
|
+
if (confirmPath2) {
|
|
46833
|
+
return targetPath;
|
|
46834
|
+
}
|
|
46835
|
+
} else {
|
|
46836
|
+
console.error("Target path is not a directory");
|
|
46837
|
+
}
|
|
46838
|
+
} else {
|
|
46839
|
+
return targetPath;
|
|
46840
|
+
}
|
|
46841
|
+
}
|
|
46842
|
+
const inputPath = await esm_default3({ message: "Please provide a new path:", default: targetPath });
|
|
46843
|
+
targetPath = inputPath.trim();
|
|
46844
|
+
}
|
|
46845
|
+
};
|
|
46846
|
+
var createCommand2 = new Command("create").description("Create a new project").argument("[name]", "Project name").action(async (name2, options, command) => {
|
|
46847
|
+
const cmdOptions = command.parent?.opts() ?? {};
|
|
46848
|
+
const { config, providerConfig, maxMessageCount, verbose, budget } = parseOptions(cmdOptions);
|
|
46849
|
+
let { provider: provider2, model, apiKey } = providerConfig.getConfigForAgent("architect") ?? {};
|
|
46850
|
+
if (!provider2) {
|
|
46851
|
+
const newConfig = await configPrompt({ provider: provider2, model, apiKey });
|
|
46852
|
+
provider2 = newConfig.provider;
|
|
46853
|
+
model = newConfig.model;
|
|
46854
|
+
apiKey = newConfig.apiKey;
|
|
46855
|
+
}
|
|
46856
|
+
let projectName = name2;
|
|
46857
|
+
if (!projectName) {
|
|
46858
|
+
const inputName = await esm_default3({ message: "What would you like to name your project?" });
|
|
46859
|
+
projectName = inputName.trim();
|
|
46860
|
+
}
|
|
46861
|
+
const targetPath = await askForPath(projectName);
|
|
46862
|
+
try {
|
|
46863
|
+
await mkdir2(targetPath, { recursive: true });
|
|
46864
|
+
} catch (error) {
|
|
46865
|
+
console.error(`Failed to create directory: ${targetPath}`, error);
|
|
46866
|
+
process.exit(1);
|
|
46867
|
+
}
|
|
46868
|
+
process.chdir(targetPath);
|
|
46869
|
+
const runner = new Runner({
|
|
46870
|
+
providerConfig: new ApiProviderConfig({ defaultProvider: provider2, defaultModel: model, providers: { [provider2]: { apiKey } } }),
|
|
46871
|
+
config: {},
|
|
46872
|
+
maxMessageCount,
|
|
46873
|
+
budget,
|
|
46874
|
+
interactive: true,
|
|
46875
|
+
eventCallback: printEvent(verbose),
|
|
46876
|
+
enableCache: true,
|
|
46877
|
+
availableAgents: [architectAgentInfo, coderAgentInfo]
|
|
46878
|
+
});
|
|
46879
|
+
await createNewProject(runner.multiAgent, projectName);
|
|
46880
|
+
});
|
|
46881
|
+
|
|
46806
46882
|
// src/commands/init.ts
|
|
46807
|
-
import { existsSync as
|
|
46883
|
+
import { existsSync as existsSync3, mkdirSync, readFileSync as readFileSync2, writeFileSync } from "node:fs";
|
|
46808
46884
|
import { dirname as dirname2 } from "node:path";
|
|
46809
46885
|
var import_lodash3 = __toESM(require_lodash(), 1);
|
|
46810
46886
|
var initCommand = new Command("init").description("Initialize polkacodes configuration").option("-g, --global", "Use global config");
|
|
46811
46887
|
initCommand.action(async (options, command) => {
|
|
46812
46888
|
const cmdOptions = command.parent?.opts() ?? {};
|
|
46889
|
+
parseOptions(cmdOptions);
|
|
46890
|
+
cmdOptions.baseDir = undefined;
|
|
46813
46891
|
const globalConfigPath = getGlobalConfigPath();
|
|
46814
46892
|
let gloabl = options.global;
|
|
46815
46893
|
let configPath = gloabl ? globalConfigPath : localConfigFileName;
|
|
46816
46894
|
try {
|
|
46817
|
-
if (
|
|
46895
|
+
if (existsSync3(configPath)) {
|
|
46818
46896
|
const proceed = await esm_default2({
|
|
46819
46897
|
message: `Found existing config at ${configPath}. Do you want to proceed? This will overwrite the existing config.`,
|
|
46820
46898
|
default: false
|
|
@@ -46854,7 +46932,7 @@ initCommand.action(async (options, command) => {
|
|
|
46854
46932
|
process.exit(1);
|
|
46855
46933
|
}
|
|
46856
46934
|
}
|
|
46857
|
-
const {
|
|
46935
|
+
const { providerConfig, verbose, maxMessageCount, budget } = parseOptions(cmdOptions);
|
|
46858
46936
|
let { provider: provider2, model, apiKey } = providerConfig.getConfigForCommand("init") ?? {};
|
|
46859
46937
|
let newConfig;
|
|
46860
46938
|
if (!provider2) {
|
|
@@ -46895,7 +46973,7 @@ initCommand.action(async (options, command) => {
|
|
|
46895
46973
|
}
|
|
46896
46974
|
case 3: {
|
|
46897
46975
|
let envFileContent;
|
|
46898
|
-
if (
|
|
46976
|
+
if (existsSync3(".env")) {
|
|
46899
46977
|
envFileContent = readFileSync2(".env", "utf8");
|
|
46900
46978
|
envFileContent += `
|
|
46901
46979
|
${newConfig.provider.toUpperCase()}_API_KEY=${newConfig.apiKey}`;
|
|
@@ -46926,7 +47004,7 @@ ${newConfig.provider.toUpperCase()}_API_KEY=${newConfig.apiKey}`;
|
|
|
46926
47004
|
availableAgents: [analyzerAgentInfo]
|
|
46927
47005
|
});
|
|
46928
47006
|
console.log("Analyzing project files...");
|
|
46929
|
-
const
|
|
47007
|
+
const response = await generateProjectConfig(runner.multiAgent, undefined);
|
|
46930
47008
|
generatedConfig = response ? $parse(response) : {};
|
|
46931
47009
|
}
|
|
46932
47010
|
const finalConfig = {
|
|
@@ -46940,12 +47018,6 @@ ${newConfig.provider.toUpperCase()}_API_KEY=${newConfig.apiKey}`;
|
|
|
46940
47018
|
import_lodash3.set(finalConfig, ["providers", newConfig.provider, "apiKey"], newConfig.apiKey);
|
|
46941
47019
|
}
|
|
46942
47020
|
}
|
|
46943
|
-
if (!finalConfig.defaultProvider) {
|
|
46944
|
-
finalConfig.defaultProvider = provider2;
|
|
46945
|
-
}
|
|
46946
|
-
if (!finalConfig.defaultModel) {
|
|
46947
|
-
finalConfig.defaultModel = model;
|
|
46948
|
-
}
|
|
46949
47021
|
mkdirSync(dirname2(configPath), { recursive: true });
|
|
46950
47022
|
writeFileSync(configPath, $stringify(finalConfig));
|
|
46951
47023
|
console.log(`Configuration saved to ${configPath}`);
|
|
@@ -46965,7 +47037,7 @@ var prCommand = new Command("pr").description("Create a GitHub pull request").ar
|
|
|
46965
47037
|
console.log("Provider:", provider2);
|
|
46966
47038
|
console.log("Model:", model);
|
|
46967
47039
|
if (!provider2) {
|
|
46968
|
-
console.error('Error: No provider specified. Please run "
|
|
47040
|
+
console.error('Error: No provider specified. Please run "pokla config" to configure your AI provider.');
|
|
46969
47041
|
process.exit(1);
|
|
46970
47042
|
}
|
|
46971
47043
|
try {
|
|
@@ -47064,7 +47136,7 @@ async function runTask(taskArg, _options, command) {
|
|
|
47064
47136
|
if (stdinInput) {
|
|
47065
47137
|
task = stdinInput;
|
|
47066
47138
|
} else {
|
|
47067
|
-
runChat(
|
|
47139
|
+
runChat(command.opts());
|
|
47068
47140
|
return;
|
|
47069
47141
|
}
|
|
47070
47142
|
} catch (error) {
|
|
@@ -47102,6 +47174,7 @@ program2.command("chat").description("Start an interactive chat session").action
|
|
|
47102
47174
|
program2.addCommand(initCommand);
|
|
47103
47175
|
program2.addCommand(commitCommand);
|
|
47104
47176
|
program2.addCommand(prCommand);
|
|
47177
|
+
program2.addCommand(createCommand2);
|
|
47105
47178
|
addSharedOptions(program2);
|
|
47106
47179
|
program2.parse();
|
|
47107
47180
|
process.on("uncaughtException", (error) => {
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polka-codes/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"license": "AGPL-3.0",
|
|
5
|
+
"author": "github@polka.codes",
|
|
5
6
|
"type": "module",
|
|
6
7
|
"bin": {
|
|
7
8
|
"polka-codes": "cli.mjs"
|
|
@@ -17,7 +18,7 @@
|
|
|
17
18
|
},
|
|
18
19
|
"dependencies": {
|
|
19
20
|
"@inquirer/prompts": "^7.2.3",
|
|
20
|
-
"@polka-codes/core": "0.5.
|
|
21
|
+
"@polka-codes/core": "0.5.4",
|
|
21
22
|
"@vscode/ripgrep": "^1.15.10",
|
|
22
23
|
"chalk": "^5.4.1",
|
|
23
24
|
"commander": "^13.0.0",
|