@polka-codes/runner 0.8.3 → 0.8.5
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 +200 -54
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -32736,7 +32736,7 @@ var {
|
|
|
32736
32736
|
Help
|
|
32737
32737
|
} = import__.default;
|
|
32738
32738
|
// package.json
|
|
32739
|
-
var version = "0.8.
|
|
32739
|
+
var version = "0.8.5";
|
|
32740
32740
|
|
|
32741
32741
|
// src/runner.ts
|
|
32742
32742
|
import { execSync } from "node:child_process";
|
|
@@ -42106,10 +42106,16 @@ ${search}`);
|
|
|
42106
42106
|
};
|
|
42107
42107
|
// ../core/src/tools/utils/getArg.ts
|
|
42108
42108
|
var getString = (args2, name2, defaultValue) => {
|
|
42109
|
+
if (typeof args2 !== "object" || Array.isArray(args2)) {
|
|
42110
|
+
throw new Error(`Invalid argument type: ${name2} ${args2}`);
|
|
42111
|
+
}
|
|
42109
42112
|
const ret = args2[name2] ?? defaultValue;
|
|
42110
42113
|
if (ret === undefined) {
|
|
42111
42114
|
throw new Error(`Missing required argument: ${name2}`);
|
|
42112
42115
|
}
|
|
42116
|
+
if (typeof ret !== "string") {
|
|
42117
|
+
throw new Error(`Invalid argument type: ${name2} ${ret}`);
|
|
42118
|
+
}
|
|
42113
42119
|
return ret;
|
|
42114
42120
|
};
|
|
42115
42121
|
var getStringArray = (args2, name2, defaultValue) => {
|
|
@@ -42123,6 +42129,9 @@ var getStringArray = (args2, name2, defaultValue) => {
|
|
|
42123
42129
|
if (ret === "") {
|
|
42124
42130
|
return [];
|
|
42125
42131
|
}
|
|
42132
|
+
if (typeof ret !== "string") {
|
|
42133
|
+
throw new Error(`Invalid argument type: ${name2} ${ret}`);
|
|
42134
|
+
}
|
|
42126
42135
|
return ret.split(",").map((s2) => s2.trim());
|
|
42127
42136
|
};
|
|
42128
42137
|
var getBoolean = (args2, name2, defaultValue) => {
|
|
@@ -42133,13 +42142,16 @@ var getBoolean = (args2, name2, defaultValue) => {
|
|
|
42133
42142
|
}
|
|
42134
42143
|
return defaultValue;
|
|
42135
42144
|
}
|
|
42145
|
+
if (typeof ret !== "string") {
|
|
42146
|
+
throw new Error(`Invalid argument type: ${name2} ${ret}`);
|
|
42147
|
+
}
|
|
42136
42148
|
switch (ret.toLowerCase()) {
|
|
42137
42149
|
case "true":
|
|
42138
42150
|
return true;
|
|
42139
42151
|
case "false":
|
|
42140
42152
|
return false;
|
|
42141
42153
|
default:
|
|
42142
|
-
throw new Error(`Invalid argument value: ${name2}`);
|
|
42154
|
+
throw new Error(`Invalid argument value: ${name2} ${ret}`);
|
|
42143
42155
|
}
|
|
42144
42156
|
};
|
|
42145
42157
|
var getInt = (args2, name2, defaultValue) => {
|
|
@@ -42150,50 +42162,104 @@ var getInt = (args2, name2, defaultValue) => {
|
|
|
42150
42162
|
}
|
|
42151
42163
|
return defaultValue;
|
|
42152
42164
|
}
|
|
42165
|
+
if (typeof ret !== "string") {
|
|
42166
|
+
throw new Error(`Invalid argument type: ${name2} ${ret}`);
|
|
42167
|
+
}
|
|
42153
42168
|
const parsed = Number.parseInt(ret);
|
|
42154
42169
|
if (Number.isNaN(parsed)) {
|
|
42155
|
-
throw new Error(`Invalid argument value: ${name2}`);
|
|
42170
|
+
throw new Error(`Invalid argument value: ${name2} ${ret}`);
|
|
42156
42171
|
}
|
|
42157
42172
|
return parsed;
|
|
42158
42173
|
};
|
|
42174
|
+
var getArray = (args2, name2, defaultValue) => {
|
|
42175
|
+
if (typeof args2 !== "object" || Array.isArray(args2)) {
|
|
42176
|
+
throw new Error(`Invalid argument type: ${name2} ${args2}`);
|
|
42177
|
+
}
|
|
42178
|
+
const ret = args2[name2];
|
|
42179
|
+
if (ret === undefined) {
|
|
42180
|
+
if (defaultValue === undefined) {
|
|
42181
|
+
throw new Error(`Missing required argument: ${name2}`);
|
|
42182
|
+
}
|
|
42183
|
+
return defaultValue;
|
|
42184
|
+
}
|
|
42185
|
+
if (Array.isArray(ret)) {
|
|
42186
|
+
return ret;
|
|
42187
|
+
}
|
|
42188
|
+
return [ret];
|
|
42189
|
+
};
|
|
42159
42190
|
// ../core/src/tools/askFollowupQuestion.ts
|
|
42160
42191
|
var toolInfo = {
|
|
42161
42192
|
name: "ask_followup_question",
|
|
42162
|
-
description: "
|
|
42193
|
+
description: "Call this when vital details are missing. Pose each follow-up as one direct, unambiguous question. If it speeds the reply, add up to five short, mutually-exclusive answer options. Group any related questions in the same call to avoid a back-and-forth chain.",
|
|
42163
42194
|
parameters: [
|
|
42164
42195
|
{
|
|
42165
|
-
name: "
|
|
42166
|
-
description: "
|
|
42196
|
+
name: "questions",
|
|
42197
|
+
description: "One or more follow-up questions you need answered before you can continue.",
|
|
42167
42198
|
required: true,
|
|
42168
|
-
|
|
42169
|
-
|
|
42170
|
-
|
|
42171
|
-
|
|
42172
|
-
|
|
42173
|
-
|
|
42174
|
-
|
|
42199
|
+
allowMultiple: true,
|
|
42200
|
+
children: [
|
|
42201
|
+
{
|
|
42202
|
+
name: "prompt",
|
|
42203
|
+
description: "The text of the question.",
|
|
42204
|
+
required: true,
|
|
42205
|
+
usageValue: "question text here"
|
|
42206
|
+
},
|
|
42207
|
+
{
|
|
42208
|
+
name: "options",
|
|
42209
|
+
description: "Ordered list of suggested answers (omit if none).",
|
|
42210
|
+
required: false,
|
|
42211
|
+
allowMultiple: true,
|
|
42212
|
+
usageValue: "suggested answer here"
|
|
42213
|
+
}
|
|
42214
|
+
]
|
|
42175
42215
|
}
|
|
42176
42216
|
],
|
|
42177
42217
|
examples: [
|
|
42178
42218
|
{
|
|
42179
|
-
description: "
|
|
42219
|
+
description: "Single clarifying question (no options)",
|
|
42180
42220
|
parameters: [
|
|
42181
42221
|
{
|
|
42182
|
-
name: "
|
|
42183
|
-
value: "What is the
|
|
42222
|
+
name: "questions",
|
|
42223
|
+
value: { prompt: "What is the target deployment environment?" }
|
|
42184
42224
|
}
|
|
42185
42225
|
]
|
|
42186
42226
|
},
|
|
42187
42227
|
{
|
|
42188
|
-
description: "
|
|
42228
|
+
description: "Single question with multiple-choice options",
|
|
42189
42229
|
parameters: [
|
|
42190
42230
|
{
|
|
42191
|
-
name: "
|
|
42192
|
-
value:
|
|
42193
|
-
|
|
42231
|
+
name: "questions",
|
|
42232
|
+
value: {
|
|
42233
|
+
prompt: "Which frontend framework are you using?",
|
|
42234
|
+
options: ["React", "Angular", "Vue", "Svelte"]
|
|
42235
|
+
}
|
|
42236
|
+
}
|
|
42237
|
+
]
|
|
42238
|
+
},
|
|
42239
|
+
{
|
|
42240
|
+
description: "Two related questions in one call",
|
|
42241
|
+
parameters: [
|
|
42194
42242
|
{
|
|
42195
|
-
name: "
|
|
42196
|
-
value:
|
|
42243
|
+
name: "questions",
|
|
42244
|
+
value: [
|
|
42245
|
+
{ prompt: "What type of application are you building?" },
|
|
42246
|
+
{
|
|
42247
|
+
prompt: "Preferred programming language?",
|
|
42248
|
+
options: ["JavaScript", "TypeScript", "Python", "Java"]
|
|
42249
|
+
}
|
|
42250
|
+
]
|
|
42251
|
+
}
|
|
42252
|
+
]
|
|
42253
|
+
},
|
|
42254
|
+
{
|
|
42255
|
+
description: "Binary (yes/no) confirmation",
|
|
42256
|
+
parameters: [
|
|
42257
|
+
{
|
|
42258
|
+
name: "questions",
|
|
42259
|
+
value: {
|
|
42260
|
+
prompt: "Is it acceptable to refactor existing tests to improve performance?",
|
|
42261
|
+
options: ["Yes", "No"]
|
|
42262
|
+
}
|
|
42197
42263
|
}
|
|
42198
42264
|
]
|
|
42199
42265
|
}
|
|
@@ -42207,13 +42273,26 @@ var handler = async (provider, args2) => {
|
|
|
42207
42273
|
message: "Not possible to ask followup question. Abort."
|
|
42208
42274
|
};
|
|
42209
42275
|
}
|
|
42210
|
-
const
|
|
42211
|
-
|
|
42212
|
-
|
|
42276
|
+
const questions = getArray(args2, "questions");
|
|
42277
|
+
if (!questions || questions.length === 0) {
|
|
42278
|
+
return {
|
|
42279
|
+
type: "Error" /* Error */,
|
|
42280
|
+
message: "No questions provided"
|
|
42281
|
+
};
|
|
42282
|
+
}
|
|
42283
|
+
const answers = [];
|
|
42284
|
+
for (const question of questions) {
|
|
42285
|
+
const prompt = getString(question, "prompt");
|
|
42286
|
+
const options = getArray(question, "options", []);
|
|
42287
|
+
const answer = await provider.askFollowupQuestion(prompt, options);
|
|
42288
|
+
answers.push(`<ask_followup_question_answer question="${prompt}">
|
|
42289
|
+
${answer}
|
|
42290
|
+
</ask_followup_question_answer>`);
|
|
42291
|
+
}
|
|
42213
42292
|
return {
|
|
42214
42293
|
type: "Reply" /* Reply */,
|
|
42215
|
-
message:
|
|
42216
|
-
|
|
42294
|
+
message: answers.join(`
|
|
42295
|
+
`)
|
|
42217
42296
|
};
|
|
42218
42297
|
};
|
|
42219
42298
|
var isAvailable = (provider) => {
|
|
@@ -42350,33 +42429,27 @@ var delegate_default = {
|
|
|
42350
42429
|
// ../core/src/tools/executeCommand.ts
|
|
42351
42430
|
var toolInfo4 = {
|
|
42352
42431
|
name: "execute_command",
|
|
42353
|
-
description:
|
|
42432
|
+
description: "Run a single CLI command. The command is always executed in the project-root working directory (regardless of earlier commands). Prefer one-off shell commands over wrapper scripts for flexibility. After an `execute_command` call, no other tool calls are allowed in the same assistant response.",
|
|
42354
42433
|
parameters: [
|
|
42355
42434
|
{
|
|
42356
42435
|
name: "command",
|
|
42357
|
-
description: "The
|
|
42436
|
+
description: "The exact command to run (valid for the current OS). It must be correctly formatted and free of harmful instructions.",
|
|
42358
42437
|
required: true,
|
|
42359
|
-
usageValue: "
|
|
42438
|
+
usageValue: "your-command-here"
|
|
42360
42439
|
},
|
|
42361
42440
|
{
|
|
42362
42441
|
name: "requires_approval",
|
|
42363
|
-
description:
|
|
42442
|
+
description: "Set to `true` for commands that install/uninstall software, modify or delete files, change system settings, perform network operations, or have other side effects. Use `false` for safe, read-only, or purely local development actions (e.g., listing files, make a build, running tests).",
|
|
42364
42443
|
required: false,
|
|
42365
|
-
usageValue: "true
|
|
42444
|
+
usageValue: "true | false"
|
|
42366
42445
|
}
|
|
42367
42446
|
],
|
|
42368
42447
|
examples: [
|
|
42369
42448
|
{
|
|
42370
|
-
description: "
|
|
42449
|
+
description: "Make a build",
|
|
42371
42450
|
parameters: [
|
|
42372
|
-
{
|
|
42373
|
-
|
|
42374
|
-
value: "npm run dev"
|
|
42375
|
-
},
|
|
42376
|
-
{
|
|
42377
|
-
name: "requires_approval",
|
|
42378
|
-
value: "false"
|
|
42379
|
-
}
|
|
42451
|
+
{ name: "command", value: "npm run build" },
|
|
42452
|
+
{ name: "requires_approval", value: "false" }
|
|
42380
42453
|
]
|
|
42381
42454
|
}
|
|
42382
42455
|
],
|
|
@@ -43338,6 +43411,23 @@ var getAvailableTools = ({
|
|
|
43338
43411
|
};
|
|
43339
43412
|
|
|
43340
43413
|
// ../core/src/Agent/parseAssistantMessage.ts
|
|
43414
|
+
function parseNestedParameters(content, parameterPrefix) {
|
|
43415
|
+
const result = {};
|
|
43416
|
+
const nestedParamRegex = new RegExp(`<${parameterPrefix}([^>]+)>([\\s\\S]*?)<\\/${parameterPrefix}\\1>`, "gs");
|
|
43417
|
+
while (true) {
|
|
43418
|
+
const match = nestedParamRegex.exec(content);
|
|
43419
|
+
if (match === null)
|
|
43420
|
+
break;
|
|
43421
|
+
const paramName = match[1];
|
|
43422
|
+
const paramContent = match[2].trim();
|
|
43423
|
+
if (paramContent.includes(`<${parameterPrefix}`)) {
|
|
43424
|
+
result[paramName] = parseNestedParameters(paramContent, parameterPrefix);
|
|
43425
|
+
} else {
|
|
43426
|
+
result[paramName] = paramContent;
|
|
43427
|
+
}
|
|
43428
|
+
}
|
|
43429
|
+
return result;
|
|
43430
|
+
}
|
|
43341
43431
|
function parseAssistantMessage(assistantMessage, tools, toolNamePrefix) {
|
|
43342
43432
|
const parameterPrefix = `${toolNamePrefix}parameter_`;
|
|
43343
43433
|
const results = [];
|
|
@@ -43366,10 +43456,25 @@ function parseAssistantMessage(assistantMessage, tools, toolNamePrefix) {
|
|
|
43366
43456
|
for (const param of tool.parameters) {
|
|
43367
43457
|
const paramName = `${parameterPrefix}${param.name}`;
|
|
43368
43458
|
const escapedParamName = paramName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
43369
|
-
const
|
|
43370
|
-
const
|
|
43371
|
-
|
|
43372
|
-
|
|
43459
|
+
const paramRegex = new RegExp(`<${escapedParamName}>([\\s\\S]*?)<\\/${escapedParamName}>`, "gs");
|
|
43460
|
+
const paramMatches = [];
|
|
43461
|
+
while (true) {
|
|
43462
|
+
const paramMatch = paramRegex.exec(fullTagContent);
|
|
43463
|
+
if (paramMatch === null)
|
|
43464
|
+
break;
|
|
43465
|
+
paramMatches.push(paramMatch[1].trim());
|
|
43466
|
+
}
|
|
43467
|
+
if (paramMatches.length > 0) {
|
|
43468
|
+
if (paramMatches.length === 1) {
|
|
43469
|
+
const paramContent = paramMatches[0];
|
|
43470
|
+
if (paramContent.includes(`<${parameterPrefix}`)) {
|
|
43471
|
+
params[param.name] = parseNestedParameters(paramContent, parameterPrefix);
|
|
43472
|
+
} else {
|
|
43473
|
+
params[param.name] = paramContent;
|
|
43474
|
+
}
|
|
43475
|
+
} else {
|
|
43476
|
+
params[param.name] = paramMatches;
|
|
43477
|
+
}
|
|
43373
43478
|
}
|
|
43374
43479
|
}
|
|
43375
43480
|
results.push({
|
|
@@ -43401,6 +43506,20 @@ function parseAssistantMessage(assistantMessage, tools, toolNamePrefix) {
|
|
|
43401
43506
|
}
|
|
43402
43507
|
|
|
43403
43508
|
// ../core/src/Agent/prompts.ts
|
|
43509
|
+
var renderParameterValue = (key, value, parameterPrefix) => {
|
|
43510
|
+
if (typeof value === "string") {
|
|
43511
|
+
return `<${parameterPrefix}${key}>${value}</${parameterPrefix}${key}>`;
|
|
43512
|
+
}
|
|
43513
|
+
if (Array.isArray(value)) {
|
|
43514
|
+
return value.map((v2) => renderParameterValue(key, v2, parameterPrefix)).join(`
|
|
43515
|
+
`);
|
|
43516
|
+
}
|
|
43517
|
+
const inner = Object.entries(value).map(([key2, v2]) => renderParameterValue(key2, v2, parameterPrefix)).join(`
|
|
43518
|
+
`);
|
|
43519
|
+
return `<${parameterPrefix}${key}>
|
|
43520
|
+
${inner}
|
|
43521
|
+
</${parameterPrefix}${key}>`;
|
|
43522
|
+
};
|
|
43404
43523
|
var toolInfoPrompt = (tool, toolNamePrefix, parameterPrefix) => `
|
|
43405
43524
|
## ${toolNamePrefix}${tool.name}
|
|
43406
43525
|
|
|
@@ -43415,11 +43534,11 @@ Usage:
|
|
|
43415
43534
|
${tool.parameters.map((param) => `<${parameterPrefix}${param.name}>${param.usageValue}</${parameterPrefix}${param.name}>`).join(`
|
|
43416
43535
|
`)}
|
|
43417
43536
|
</${toolNamePrefix}${tool.name}>`;
|
|
43418
|
-
var toolInfoExamplesPrompt = (
|
|
43419
|
-
## Example
|
|
43537
|
+
var toolInfoExamplesPrompt = (tool, example, toolNamePrefix, parameterPrefix) => `
|
|
43538
|
+
## Example: ${example.description}
|
|
43420
43539
|
|
|
43421
43540
|
<${toolNamePrefix}${tool.name}>
|
|
43422
|
-
${example.parameters.map((param) =>
|
|
43541
|
+
${example.parameters.map((param) => `${renderParameterValue(param.name, param.value, parameterPrefix)}`).join(`
|
|
43423
43542
|
`)}
|
|
43424
43543
|
</${toolNamePrefix}${tool.name}>
|
|
43425
43544
|
`;
|
|
@@ -43428,7 +43547,6 @@ var toolUsePrompt = (tools, toolNamePrefix) => {
|
|
|
43428
43547
|
return "";
|
|
43429
43548
|
}
|
|
43430
43549
|
const parameterPrefix = `${toolNamePrefix}parameter_`;
|
|
43431
|
-
let exampleIndex = 0;
|
|
43432
43550
|
return `
|
|
43433
43551
|
====
|
|
43434
43552
|
|
|
@@ -43446,11 +43564,39 @@ Tool use is formatted using XML-style tags. The tool name is enclosed in opening
|
|
|
43446
43564
|
...
|
|
43447
43565
|
</${toolNamePrefix}tool_name>
|
|
43448
43566
|
|
|
43449
|
-
|
|
43567
|
+
## Array Parameters
|
|
43568
|
+
|
|
43569
|
+
To create an array of values for a parameter, repeat the parameter tag multiple times:
|
|
43570
|
+
|
|
43571
|
+
<${toolNamePrefix}process_file>
|
|
43572
|
+
<${parameterPrefix}path>test.ts</${parameterPrefix}path>
|
|
43573
|
+
<${parameterPrefix}path>main.ts</${parameterPrefix}path>
|
|
43574
|
+
</${toolNamePrefix}process_file>
|
|
43575
|
+
|
|
43576
|
+
## Nested Object Parameters
|
|
43577
|
+
|
|
43578
|
+
To create nested objects, nest parameter tags within other parameter tags:
|
|
43579
|
+
|
|
43580
|
+
<${toolNamePrefix}example_tool>
|
|
43581
|
+
<${parameterPrefix}key>
|
|
43582
|
+
<${parameterPrefix}key2>value</${parameterPrefix}key2>
|
|
43583
|
+
<${parameterPrefix}key3>value2</${parameterPrefix}key3>
|
|
43584
|
+
</${parameterPrefix}key>
|
|
43585
|
+
</${toolNamePrefix}example_tool>
|
|
43586
|
+
|
|
43587
|
+
You can also combine array parameters with nested objects:
|
|
43450
43588
|
|
|
43451
|
-
<${toolNamePrefix}
|
|
43452
|
-
<${parameterPrefix}
|
|
43453
|
-
</${
|
|
43589
|
+
<${toolNamePrefix}example_tool>
|
|
43590
|
+
<${parameterPrefix}key>
|
|
43591
|
+
<${parameterPrefix}key2>value</${parameterPrefix}key2>
|
|
43592
|
+
<${parameterPrefix}key3>value2</${parameterPrefix}key3>
|
|
43593
|
+
</${parameterPrefix}key>
|
|
43594
|
+
<${parameterPrefix}key>
|
|
43595
|
+
<${parameterPrefix}key2>value3</${parameterPrefix}key2>
|
|
43596
|
+
<${parameterPrefix}key3>value4</${parameterPrefix}key3>
|
|
43597
|
+
<${parameterPrefix}key3>value5</${parameterPrefix}key3>
|
|
43598
|
+
</${parameterPrefix}key>
|
|
43599
|
+
</${toolNamePrefix}example_tool>
|
|
43454
43600
|
|
|
43455
43601
|
Always adhere to this format for the tool use to ensure proper parsing and execution.
|
|
43456
43602
|
|
|
@@ -43464,7 +43610,7 @@ ${tools.map((tool) => toolInfoPrompt(tool, toolNamePrefix, parameterPrefix)).joi
|
|
|
43464
43610
|
${tools.map((tool) => {
|
|
43465
43611
|
let promp = "";
|
|
43466
43612
|
for (const example of tool.examples ?? []) {
|
|
43467
|
-
promp += toolInfoExamplesPrompt(
|
|
43613
|
+
promp += toolInfoExamplesPrompt(tool, example, toolNamePrefix, parameterPrefix);
|
|
43468
43614
|
}
|
|
43469
43615
|
return promp;
|
|
43470
43616
|
}).join("")}
|