@polka-codes/cli 0.1.6 → 0.1.8
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 +32910 -28
- package/package.json +4 -1
- package/dist/config.d.ts +0 -38
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js +0 -44
- package/dist/config.js.map +0 -1
- package/dist/handlers.d.ts +0 -15
- package/dist/handlers.d.ts.map +0 -1
- package/dist/handlers.js +0 -254
- package/dist/handlers.js.map +0 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/runTask.d.ts +0 -10
- package/dist/runTask.d.ts.map +0 -1
- package/dist/runTask.js +0 -107
- package/dist/runTask.js.map +0 -1
- package/dist/utils/listFiles.d.ts +0 -12
- package/dist/utils/listFiles.d.ts.map +0 -1
- package/dist/utils/listFiles.js +0 -100
- package/dist/utils/listFiles.js.map +0 -1
- package/dist/utils/replaceInFile.d.ts +0 -2
- package/dist/utils/replaceInFile.d.ts.map +0 -1
- package/dist/utils/replaceInFile.js +0 -85
- package/dist/utils/replaceInFile.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@polka-codes/cli",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"license": "AGPL-3.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -12,6 +12,9 @@
|
|
|
12
12
|
"types": "./dist/index.d.ts"
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "bun build src/index.ts --outdir dist --target node"
|
|
17
|
+
},
|
|
15
18
|
"dependencies": {
|
|
16
19
|
"@polka-codes/core": "0.1.4",
|
|
17
20
|
"commander": "^13.0.0",
|
package/dist/config.d.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
export declare const configSchema: z.ZodObject<{
|
|
3
|
-
provider: z.ZodOptional<z.ZodString>;
|
|
4
|
-
apiKey: z.ZodOptional<z.ZodString>;
|
|
5
|
-
model: z.ZodOptional<z.ZodString>;
|
|
6
|
-
commands: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodString, z.ZodObject<{
|
|
7
|
-
command: z.ZodString;
|
|
8
|
-
description: z.ZodString;
|
|
9
|
-
}, "strip", z.ZodTypeAny, {
|
|
10
|
-
command: string;
|
|
11
|
-
description: string;
|
|
12
|
-
}, {
|
|
13
|
-
command: string;
|
|
14
|
-
description: string;
|
|
15
|
-
}>]>>>;
|
|
16
|
-
rules: z.ZodOptional<z.ZodUnion<[z.ZodOptional<z.ZodArray<z.ZodString, "many">>, z.ZodString]>>;
|
|
17
|
-
}, "strict", z.ZodTypeAny, {
|
|
18
|
-
provider?: string | undefined;
|
|
19
|
-
apiKey?: string | undefined;
|
|
20
|
-
model?: string | undefined;
|
|
21
|
-
commands?: Record<string, string | {
|
|
22
|
-
command: string;
|
|
23
|
-
description: string;
|
|
24
|
-
}> | undefined;
|
|
25
|
-
rules?: string | string[] | undefined;
|
|
26
|
-
}, {
|
|
27
|
-
provider?: string | undefined;
|
|
28
|
-
apiKey?: string | undefined;
|
|
29
|
-
model?: string | undefined;
|
|
30
|
-
commands?: Record<string, string | {
|
|
31
|
-
command: string;
|
|
32
|
-
description: string;
|
|
33
|
-
}> | undefined;
|
|
34
|
-
rules?: string | string[] | undefined;
|
|
35
|
-
}>;
|
|
36
|
-
export type Config = z.infer<typeof configSchema>;
|
|
37
|
-
export declare function loadConfig(path?: string, cwd?: string): Config | undefined;
|
|
38
|
-
//# sourceMappingURL=config.d.ts.map
|
package/dist/config.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAGA,OAAO,EAAY,CAAC,EAAE,MAAM,KAAK,CAAA;AAMjC,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAQd,CAAA;AAEX,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAA;AAEjD,wBAAgB,UAAU,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,GAAG,GAAE,MAAsB,GAAG,MAAM,GAAG,SAAS,CAsBzF"}
|
package/dist/config.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from 'node:fs';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
import { parse } from 'yaml';
|
|
4
|
-
import { ZodError, z } from 'zod';
|
|
5
|
-
import { createServiceLogger } from '@polka-codes/core';
|
|
6
|
-
const logger = createServiceLogger('cli/config');
|
|
7
|
-
export const configSchema = z
|
|
8
|
-
.object({
|
|
9
|
-
provider: z.string().optional(),
|
|
10
|
-
apiKey: z.string().optional(),
|
|
11
|
-
model: z.string().optional(),
|
|
12
|
-
commands: z.record(z.string(), z.string().or(z.object({ command: z.string(), description: z.string() }))).optional(),
|
|
13
|
-
rules: z.array(z.string()).optional().or(z.string()).optional(),
|
|
14
|
-
})
|
|
15
|
-
.strict();
|
|
16
|
-
export function loadConfig(path, cwd = process.cwd()) {
|
|
17
|
-
if (path) {
|
|
18
|
-
try {
|
|
19
|
-
return readConfig(path);
|
|
20
|
-
}
|
|
21
|
-
catch (error) {
|
|
22
|
-
logger.error(`Error loading config file: ${path}\n${error}`);
|
|
23
|
-
process.exit(1);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
const configPaths = [join(cwd, '.polkacodes.yml'), join(cwd, '.polkacodes.yaml')];
|
|
27
|
-
for (const path of configPaths) {
|
|
28
|
-
try {
|
|
29
|
-
return readConfig(path);
|
|
30
|
-
}
|
|
31
|
-
catch (error) {
|
|
32
|
-
if (error instanceof ZodError) {
|
|
33
|
-
logger.error(`Error in config file: ${path}\n${error}`);
|
|
34
|
-
process.exit(1);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
const readConfig = (path) => {
|
|
40
|
-
const file = readFileSync(path, 'utf8');
|
|
41
|
-
const config = parse(file);
|
|
42
|
-
return configSchema.parse(config);
|
|
43
|
-
};
|
|
44
|
-
//# sourceMappingURL=config.js.map
|
package/dist/config.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACtC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAA;AAC5B,OAAO,EAAE,QAAQ,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEjC,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAEvD,MAAM,MAAM,GAAG,mBAAmB,CAAC,YAAY,CAAC,CAAA;AAEhD,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC;KAC1B,MAAM,CAAC;IACN,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC/B,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC7B,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC5B,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;IACpH,KAAK,EAAE,CAAC,CAAC,KAAK,C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A"}
|
package/dist/handlers.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { type ChildProcessWithoutNullStreams } from 'node:child_process';
|
|
2
|
-
import { type ToolHandler } from '@polka-codes/core';
|
|
3
|
-
export type ToolHandlerOptions = {
|
|
4
|
-
executeCommand?: {
|
|
5
|
-
shouldExecute?: (command: string) => Promise<boolean>;
|
|
6
|
-
shouldApprove?: (command: string) => Promise<boolean>;
|
|
7
|
-
commandStarted?: (command: string, child: ChildProcessWithoutNullStreams) => void;
|
|
8
|
-
};
|
|
9
|
-
files?: {
|
|
10
|
-
isPathAllowed?: (path: string) => Promise<boolean>;
|
|
11
|
-
cwd?: string;
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
|
-
export declare const getToolHandler: (options: ToolHandlerOptions) => ToolHandler;
|
|
15
|
-
//# sourceMappingURL=handlers.d.ts.map
|
package/dist/handlers.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../src/handlers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,8BAA8B,EAAS,MAAM,oBAAoB,CAAA;AAE/E,OAAO,EAAE,KAAK,WAAW,EAAsE,MAAM,mBAAmB,CAAA;AA8RxH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,cAAc,CAAC,EAAE;QACf,aAAa,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;QACrD,aAAa,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;QACrD,cAAc,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,8BAA8B,KAAK,IAAI,CAAA;KAClF,CAAA;IACD,KAAK,CAAC,EAAE;QACN,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;QAClD,GAAG,CAAC,EAAE,MAAM,CAAA;KACb,CAAA;CACF,CAAA;AAED,eAAO,MAAM,cAAc,YAAa,kBAAkB,KAAG,WAQ5D,CAAA"}
|
package/dist/handlers.js
DELETED
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
import { spawn } from 'node:child_process';
|
|
2
|
-
import { readFile, writeFile } from 'node:fs/promises';
|
|
3
|
-
import { ToolResponseType, allTools, createServiceLogger } from '@polka-codes/core';
|
|
4
|
-
import { listFiles } from './utils/listFiles';
|
|
5
|
-
import { replaceInFile } from './utils/replaceInFile';
|
|
6
|
-
const logger = createServiceLogger('cli/handlers');
|
|
7
|
-
const handleError = async (name, fn) => {
|
|
8
|
-
try {
|
|
9
|
-
return await fn();
|
|
10
|
-
}
|
|
11
|
-
catch (error) {
|
|
12
|
-
logger.warn(error, `Error executing tool: ${name}`);
|
|
13
|
-
return {
|
|
14
|
-
type: ToolResponseType.Error,
|
|
15
|
-
message: `Error executing tool: ${name}
|
|
16
|
-
Error: ${error}`,
|
|
17
|
-
canRetry: false,
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
const getString = (args, name, defaultValue) => {
|
|
22
|
-
const ret = args[name] ?? defaultValue;
|
|
23
|
-
if (!ret) {
|
|
24
|
-
throw new Error(`Missing required argument: ${name}`);
|
|
25
|
-
}
|
|
26
|
-
return ret;
|
|
27
|
-
};
|
|
28
|
-
const getStringArray = (args, name, defaultValue) => {
|
|
29
|
-
const ret = args[name];
|
|
30
|
-
if (!ret) {
|
|
31
|
-
if (defaultValue === undefined) {
|
|
32
|
-
throw new Error(`Missing required argument: ${name}`);
|
|
33
|
-
}
|
|
34
|
-
return defaultValue;
|
|
35
|
-
}
|
|
36
|
-
return ret.split(',');
|
|
37
|
-
};
|
|
38
|
-
const getBoolean = (args, name, defaultValue) => {
|
|
39
|
-
const ret = args[name];
|
|
40
|
-
if (!ret) {
|
|
41
|
-
if (defaultValue === undefined) {
|
|
42
|
-
throw new Error(`Missing required argument: ${name}`);
|
|
43
|
-
}
|
|
44
|
-
return defaultValue;
|
|
45
|
-
}
|
|
46
|
-
switch (ret.toLowerCase()) {
|
|
47
|
-
case 'true':
|
|
48
|
-
return true;
|
|
49
|
-
case 'false':
|
|
50
|
-
return false;
|
|
51
|
-
default:
|
|
52
|
-
throw new Error(`Invalid argument value: ${name}`);
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
const getInt = (args, name, defaultValue) => {
|
|
56
|
-
const ret = args[name];
|
|
57
|
-
if (!ret) {
|
|
58
|
-
if (defaultValue === undefined) {
|
|
59
|
-
throw new Error(`Missing required argument: ${name}`);
|
|
60
|
-
}
|
|
61
|
-
return defaultValue;
|
|
62
|
-
}
|
|
63
|
-
const parsed = Number.parseInt(ret);
|
|
64
|
-
if (Number.isNaN(parsed)) {
|
|
65
|
-
throw new Error(`Invalid argument value: ${name}`);
|
|
66
|
-
}
|
|
67
|
-
return parsed;
|
|
68
|
-
};
|
|
69
|
-
const handlers = {
|
|
70
|
-
executeCommand: async (options, args) => {
|
|
71
|
-
const command = getString(args, 'command');
|
|
72
|
-
const shouldExecute = (await options.executeCommand?.shouldExecute?.(command)) ?? true;
|
|
73
|
-
if (!shouldExecute) {
|
|
74
|
-
return {
|
|
75
|
-
type: ToolResponseType.Invalid,
|
|
76
|
-
message: `<command>${command}</command><command_rejected>Rejected by policy</command_rejected>`,
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
const requiresApproval = getBoolean(args, 'requires_approval', false);
|
|
80
|
-
if (requiresApproval) {
|
|
81
|
-
const shouldApprove = await options.executeCommand?.shouldApprove?.(command);
|
|
82
|
-
if (!shouldApprove) {
|
|
83
|
-
return {
|
|
84
|
-
type: ToolResponseType.Invalid,
|
|
85
|
-
message: `<command>${command}</command><command_rejected>Rejected by policy</command_rejected>`,
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
// TODO: add timeout
|
|
90
|
-
return new Promise((resolve, reject) => {
|
|
91
|
-
// spawn a shell to execute the command
|
|
92
|
-
logger.trace(`Executing command: ${command}`);
|
|
93
|
-
const child = spawn(command, [], {
|
|
94
|
-
shell: true,
|
|
95
|
-
stdio: 'pipe',
|
|
96
|
-
});
|
|
97
|
-
options.executeCommand?.commandStarted?.(command, child);
|
|
98
|
-
let stdoutText = '';
|
|
99
|
-
let stderrText = '';
|
|
100
|
-
child.stdout.on('data', (data) => {
|
|
101
|
-
stdoutText += data.toString();
|
|
102
|
-
});
|
|
103
|
-
child.stderr.on('data', (data) => {
|
|
104
|
-
stderrText += data.toString();
|
|
105
|
-
});
|
|
106
|
-
child.on('close', (code) => {
|
|
107
|
-
const message = `<command>${command}</command>
|
|
108
|
-
<command_exit_code>${code}</command_exit_code>
|
|
109
|
-
<command_stdout>
|
|
110
|
-
${stdoutText}
|
|
111
|
-
</command_stdout>
|
|
112
|
-
<command_stderr>
|
|
113
|
-
${stderrText}
|
|
114
|
-
</command_stderr>
|
|
115
|
-
`;
|
|
116
|
-
if (code === 0) {
|
|
117
|
-
resolve({
|
|
118
|
-
type: ToolResponseType.Reply,
|
|
119
|
-
message,
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
resolve({
|
|
124
|
-
type: ToolResponseType.Error,
|
|
125
|
-
message,
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
child.on('error', (err) => {
|
|
130
|
-
reject(err);
|
|
131
|
-
});
|
|
132
|
-
});
|
|
133
|
-
},
|
|
134
|
-
readFile: async (options, args) => {
|
|
135
|
-
const paths = getStringArray(args, 'path');
|
|
136
|
-
for (const path of paths) {
|
|
137
|
-
const isPathAllowed = (await options.files?.isPathAllowed?.(path)) ?? true;
|
|
138
|
-
if (!isPathAllowed) {
|
|
139
|
-
return {
|
|
140
|
-
type: ToolResponseType.Invalid,
|
|
141
|
-
message: `<path>${path}</path><path_rejected>Rejected by policy</path_rejected>`,
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
const resp = [];
|
|
146
|
-
for (const path of paths) {
|
|
147
|
-
const fileContent = await readFile(path, 'utf8');
|
|
148
|
-
resp.push(`<read_file_file_conten path="${path}">${fileContent}</read_file_file_content>`);
|
|
149
|
-
}
|
|
150
|
-
return {
|
|
151
|
-
type: ToolResponseType.Reply,
|
|
152
|
-
message: resp.join('\n'),
|
|
153
|
-
};
|
|
154
|
-
},
|
|
155
|
-
writeToFile: async (options, args) => {
|
|
156
|
-
const path = getString(args, 'path');
|
|
157
|
-
const content = getString(args, 'content');
|
|
158
|
-
const isPathAllowed = (await options.files?.isPathAllowed?.(path)) ?? true;
|
|
159
|
-
if (!isPathAllowed) {
|
|
160
|
-
return {
|
|
161
|
-
type: ToolResponseType.Invalid,
|
|
162
|
-
message: `<path>${path}</path><path_rejected>Rejected by policy</path_rejected>`,
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
await writeFile(path, content, 'utf8');
|
|
166
|
-
return {
|
|
167
|
-
type: ToolResponseType.Reply,
|
|
168
|
-
message: `<write_file_path>${path}</write_file_path><status>Success</status>`,
|
|
169
|
-
};
|
|
170
|
-
},
|
|
171
|
-
replaceInFile: async (options, args) => {
|
|
172
|
-
const path = getString(args, 'path');
|
|
173
|
-
const diff = getString(args, 'diff');
|
|
174
|
-
const isPathAllowed = (await options.files?.isPathAllowed?.(path)) ?? true;
|
|
175
|
-
if (!isPathAllowed) {
|
|
176
|
-
return {
|
|
177
|
-
type: ToolResponseType.Invalid,
|
|
178
|
-
message: `<path>${path}</path><path_rejected>Rejected by policy</path_rejected>`,
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
|
-
const fileContent = await readFile(path, 'utf8');
|
|
182
|
-
const result = await replaceInFile(fileContent, diff);
|
|
183
|
-
await writeFile(path, result, 'utf8');
|
|
184
|
-
return {
|
|
185
|
-
type: ToolResponseType.Reply,
|
|
186
|
-
message: `<replace_in_file_path>${path}</replace_in_file_path>`,
|
|
187
|
-
};
|
|
188
|
-
},
|
|
189
|
-
searchFiles: async (options, args) => {
|
|
190
|
-
// TODO
|
|
191
|
-
return {
|
|
192
|
-
type: ToolResponseType.Exit,
|
|
193
|
-
message: 'Files searched successfully',
|
|
194
|
-
};
|
|
195
|
-
},
|
|
196
|
-
listFiles: async (options, args) => {
|
|
197
|
-
const path = getString(args, 'path');
|
|
198
|
-
const depth = getInt(args, 'depth', 5);
|
|
199
|
-
const isPathAllowed = (await options.files?.isPathAllowed?.(path)) ?? true;
|
|
200
|
-
if (!isPathAllowed) {
|
|
201
|
-
return {
|
|
202
|
-
type: ToolResponseType.Invalid,
|
|
203
|
-
message: `<path>${path}</path><path_rejected>Rejected by policy</path_rejected>`,
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
const recursive = depth > 0;
|
|
207
|
-
const [files, limitReached] = await listFiles(path, recursive, depth, options.files?.cwd ?? process.cwd());
|
|
208
|
-
return {
|
|
209
|
-
type: ToolResponseType.Reply,
|
|
210
|
-
message: `<list_files_path>${path}</list_files_path>
|
|
211
|
-
<list_files_depth>${depth}</list_files_depth>
|
|
212
|
-
<list_files_files>
|
|
213
|
-
${files.join('\n')}
|
|
214
|
-
</list_files_files>
|
|
215
|
-
<list_files_truncated>${limitReached}</list_files_truncated>`,
|
|
216
|
-
};
|
|
217
|
-
},
|
|
218
|
-
listCodeDefinitionNames: async (options, args) => {
|
|
219
|
-
// TODO
|
|
220
|
-
return {
|
|
221
|
-
type: ToolResponseType.Exit,
|
|
222
|
-
message: 'Code definition names listed successfully',
|
|
223
|
-
};
|
|
224
|
-
},
|
|
225
|
-
askFollowupQuestion: async (options, args) => {
|
|
226
|
-
// TODO
|
|
227
|
-
return {
|
|
228
|
-
type: ToolResponseType.Exit,
|
|
229
|
-
message: 'Followup question asked successfully',
|
|
230
|
-
};
|
|
231
|
-
},
|
|
232
|
-
attemptCompletion: async (options, args) => {
|
|
233
|
-
return {
|
|
234
|
-
type: ToolResponseType.Exit,
|
|
235
|
-
message: '<completed>true</completed>',
|
|
236
|
-
};
|
|
237
|
-
},
|
|
238
|
-
};
|
|
239
|
-
const processedHandlers = Object.fromEntries(Object.entries(handlers).map(([toolName, handler]) => {
|
|
240
|
-
return [
|
|
241
|
-
allTools[toolName].name,
|
|
242
|
-
async (options, args) => handleError(toolName, async () => handler(options, args)),
|
|
243
|
-
];
|
|
244
|
-
}));
|
|
245
|
-
export const getToolHandler = (options) => {
|
|
246
|
-
return async (toolName, args) => {
|
|
247
|
-
const handler = processedHandlers[toolName];
|
|
248
|
-
if (!handler) {
|
|
249
|
-
throw new Error(`Unknown tool: ${toolName}`);
|
|
250
|
-
}
|
|
251
|
-
return handler(options, args);
|
|
252
|
-
};
|
|
253
|
-
};
|
|
254
|
-
//# sourceMappingURL=handlers.js.map
|
package/dist/handlers.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"handlers.js","sourceRoot":"","sources":["../src/handlers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuC,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAC/E,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AACtD,OAAO,EAAuC,gBAAgB,EAAE,QAAQ,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAExH,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAMrD,MAAM,MAAM,GAAG,mBAAmB,CAAC,cAAc,CAAC,CAAA;AAElD,MAAM,WAAW,GAAG,KAAK,EAAE,IAAY,EAAE,EAA+B,EAAyB,EAAE;IACjG,IAAI,CAAC;QACH,OAAO,MAAM,EAAE,EAAE,CAAA;IACnB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,yBAAyB,IAAI,EAAE,CAAC,CAAA;QACnD,OAAO;YACL,IAAI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CAAC,CAAA;AACH,CAAC,CAAA"}
|
package/dist/index.d.ts
DELETED
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,MAAM,CAAC,iBAAiB,CAAC,CAAA;AAEnD,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAA;AAE7B,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;AAErE,mCAAmC;AACnC,OAAO;KACJ,QAAQ,CAAC,QAAQ,EAAE,qBAAqB,CAAC;KACzC,MAAM,CAAC,oBAAoB,EAAE,qBAAqB,CAAC;KACnD,MAAM,CAAC,2BAA2B,EAAE,cAAc,CAAC;KACnD,MAAM,CAAC,oBAAoB,EAAE,UAAU,CAAC;KACxC,MAAM,CAAC,iBAAiB,EAAE,SAAS,CAAC;KACpC,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE;IACjC,MAAM,MAAM,GAAG,UAAU,CAAC,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,CAAA;IAE5D,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,IAAI,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,MAAM,CAAC,QAAQ,IAAI,WAAW,CAAA;IAExG,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,IAAI,MAAM,CAAC,KAAK,CAAA;IAE3E,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,aAAa,IAAI,MAAM,CAAC,MAAM,CAAA;IAE3E,MAAM,OAAO,CAAC;QACZ,IAAI,EAAE,OAAO;QACb,QAAQ;QACR,KAAK;QACL,MAAM;QACN,MAAM;KACP,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA;AAEJ,OAAO,CAAC,KAAK,EAAE,CAAA"}
|
package/dist/runTask.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { Config } from './config';
|
|
2
|
-
export type RunTaskOptions = {
|
|
3
|
-
task: string;
|
|
4
|
-
provider: string;
|
|
5
|
-
model: string;
|
|
6
|
-
apiKey: string;
|
|
7
|
-
config: Config;
|
|
8
|
-
};
|
|
9
|
-
export declare const runTask: (options: RunTaskOptions) => Promise<void>;
|
|
10
|
-
//# sourceMappingURL=runTask.d.ts.map
|
package/dist/runTask.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"runTask.d.ts","sourceRoot":"","sources":["../src/runTask.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAItC,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,EAAE,MAAM,CAAA;IACd,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAID,eAAO,MAAM,OAAO,YAAmB,cAAc,kBA8GpD,CAAA"}
|
package/dist/runTask.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import os from 'node:os';
|
|
2
|
-
import { CoderAgent, createService, createServiceLogger } from '@polka-codes/core';
|
|
3
|
-
import { getToolHandler } from './handlers';
|
|
4
|
-
import { listFiles } from './utils/listFiles';
|
|
5
|
-
const logger = createServiceLogger('cli/runTask');
|
|
6
|
-
export const runTask = async (options) => {
|
|
7
|
-
logger.debug(options, 'Running task');
|
|
8
|
-
const { task, provider, model, apiKey, config } = options;
|
|
9
|
-
// Create service with the configured options
|
|
10
|
-
const service = createService(provider, {
|
|
11
|
-
apiKey,
|
|
12
|
-
modelId: model,
|
|
13
|
-
});
|
|
14
|
-
let rules = config.rules;
|
|
15
|
-
if (typeof rules === 'string') {
|
|
16
|
-
rules = [rules];
|
|
17
|
-
}
|
|
18
|
-
const agent = new CoderAgent({
|
|
19
|
-
ai: service,
|
|
20
|
-
os: os.platform(),
|
|
21
|
-
customInstructions: rules,
|
|
22
|
-
commands: config.commands,
|
|
23
|
-
toolHandler: getToolHandler({
|
|
24
|
-
executeCommand: {
|
|
25
|
-
async shouldExecute(command) {
|
|
26
|
-
// TODO: command whitelist
|
|
27
|
-
return true;
|
|
28
|
-
},
|
|
29
|
-
async shouldApprove(command) {
|
|
30
|
-
// TODO: config for auto approve
|
|
31
|
-
return true;
|
|
32
|
-
},
|
|
33
|
-
commandStarted(command, child) {
|
|
34
|
-
console.log(`$ >>>> $ ${command}`);
|
|
35
|
-
child.stdout.on('data', (data) => {
|
|
36
|
-
process.stdout.write(data.toString());
|
|
37
|
-
});
|
|
38
|
-
child.stderr.on('data', (data) => {
|
|
39
|
-
process.stderr.write(data.toString());
|
|
40
|
-
});
|
|
41
|
-
child.on('close', (code) => {
|
|
42
|
-
console.log(`$ <<<< $ Command exited with code: ${code}`);
|
|
43
|
-
});
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
}),
|
|
47
|
-
});
|
|
48
|
-
const cwd = process.cwd();
|
|
49
|
-
const [fileList, limited] = await listFiles(cwd, true, 100, cwd);
|
|
50
|
-
const fileContext = `<files>
|
|
51
|
-
${fileList.join('\n')}${limited ? '\n<files_truncated>true</files_truncated>' : ''}
|
|
52
|
-
</files>`;
|
|
53
|
-
const usage = {
|
|
54
|
-
inputTokens: 0,
|
|
55
|
-
outputTokens: 0,
|
|
56
|
-
cacheWriteTokens: 0,
|
|
57
|
-
cacheReadTokens: 0,
|
|
58
|
-
totalCost: 0,
|
|
59
|
-
};
|
|
60
|
-
await agent.startTask({
|
|
61
|
-
task,
|
|
62
|
-
context: `<now_date>${new Date().toISOString()}</now_date>${fileContext}`,
|
|
63
|
-
maxIterations: 10,
|
|
64
|
-
callback: (event) => {
|
|
65
|
-
if (event.kind === 'usage') {
|
|
66
|
-
usage.inputTokens += event.info.inputTokens;
|
|
67
|
-
usage.outputTokens += event.info.outputTokens;
|
|
68
|
-
usage.cacheWriteTokens += event.info.cacheWriteTokens ?? 0;
|
|
69
|
-
usage.cacheReadTokens += event.info.cacheReadTokens ?? 0;
|
|
70
|
-
usage.totalCost += event.info.totalCost ?? 0;
|
|
71
|
-
}
|
|
72
|
-
if (event.kind === 'start_request') {
|
|
73
|
-
console.log('>>>>');
|
|
74
|
-
const { userContent } = event;
|
|
75
|
-
if (userContent) {
|
|
76
|
-
for (const content of userContent) {
|
|
77
|
-
console.log(content.type === 'text' ? content.text : '');
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
console.log('====');
|
|
81
|
-
}
|
|
82
|
-
if (event.newText) {
|
|
83
|
-
process.stdout.write(event.newText);
|
|
84
|
-
}
|
|
85
|
-
if (event.kind === 'end_request') {
|
|
86
|
-
process.stdout.write('\n');
|
|
87
|
-
console.log('<<<<');
|
|
88
|
-
}
|
|
89
|
-
},
|
|
90
|
-
});
|
|
91
|
-
if (!usage.totalCost) {
|
|
92
|
-
// we need to calculate the total cost
|
|
93
|
-
const modelInfo = agent.model.info;
|
|
94
|
-
const inputCost = (modelInfo.inputPrice ?? 0) * usage.inputTokens;
|
|
95
|
-
const outputCost = (modelInfo.outputPrice ?? 0) * usage.outputTokens;
|
|
96
|
-
const cacheReadCost = (modelInfo.cacheReadsPrice ?? 0) * usage.cacheReadTokens;
|
|
97
|
-
const cacheWriteCost = (modelInfo.cacheWritesPrice ?? 0) * usage.cacheWriteTokens;
|
|
98
|
-
usage.totalCost = (inputCost + outputCost + cacheReadCost + cacheWriteCost) / 1_000_000;
|
|
99
|
-
}
|
|
100
|
-
console.log('Usages:');
|
|
101
|
-
console.log(`Input tokens: ${usage.inputTokens}`);
|
|
102
|
-
console.log(`Output tokens: ${usage.outputTokens}`);
|
|
103
|
-
console.log(`Cache read tokens: ${usage.cacheReadTokens}`);
|
|
104
|
-
console.log(`Cache write tokens: ${usage.cacheWriteTokens}`);
|
|
105
|
-
console.log(`Total cost: ${usage.totalCost}`);
|
|
106
|
-
};
|
|
107
|
-
//# sourceMappingURL=runTask.js.map
|
package/dist/runTask.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"runTask.js","sourceRoot":"","sources":["../src/runTask.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,EAA0B,UAAU,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAE1G,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAU7C,MAAM,MAAM,GAAG,mBAAmB,CAAC,aAAa,CAAC,CAAA;AAEjD,MAAM,CAAC,MAAM,OAAO,GAAG,KAAK,EAAE,OAAuB,EAAE,EAAE;IACvD,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,cAAc,CAAC,CAAA;IAErC,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAA;IAEzD,6CAA6C;IAC7C,MAAM,OAAO,GAAG,aAAa,CAAC,QAA6B,EAAE;QAC3D,MAAM;QACN,OAAO,EAAE,KAAK;KACf,CAAC,CAAA;IAEF,IAAI,KAAK,GAAG,MAAM,CAAC,KAAK,CA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A;IACzF,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;IACtB,OAAO,CAAC,GAAG,CAAC,iBAAiB,KAAK,CAAC,WAAW,EAAE,CAAC,CAAA;IACjD,OAAO,CAAC,GAAG,CAAC,kBAAkB,KAAK,CAAC,YAAY,EAAE,CAAC,CAAA;IACnD,OAAO,CAAC,GAAG,CAAC,sBAAsB,KAAK,CAAC,eAAe,EAAE,CAAC,CAAA;IAC1D,OAAO,CAAC,GAAG,CAAC,uBAAuB,KAAK,CAAC,gBAAgB,EAAE,CAAC,CAAA;IAC5D,OAAO,CAAC,GAAG,CAAC,eAAe,KAAK,CAAC,SAAS,EAAE,CAAC,CAAA;AAC/C,CAAC,CAAA"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Lists files under `dirPath` in BFS order, respecting:
|
|
3
|
-
* - A default set of ignores
|
|
4
|
-
* - A root .gitignore under `cwd`
|
|
5
|
-
* - Any .gitignore files in child directories (merged as we go)
|
|
6
|
-
*
|
|
7
|
-
* Returns `[files, limitReached]`:
|
|
8
|
-
* - `files` is the array of file paths (relative to `cwd`)
|
|
9
|
-
* - `limitReached` is `true` if `maxCount` was hit, otherwise `false`
|
|
10
|
-
*/
|
|
11
|
-
export declare function listFiles(dirPath: string, recursive: boolean, maxCount: number, cwd: string): Promise<[string[], boolean]>;
|
|
12
|
-
//# sourceMappingURL=listFiles.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"listFiles.d.ts","sourceRoot":"","sources":["../../src/utils/listFiles.ts"],"names":[],"mappings":"AA0CA;;;;;;;;;GASG;AACH,wBAAsB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,OAAO,CAAC,CAAC,CAwDhI"}
|