@polka-codes/runner 0.8.17 → 0.8.18

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.
Files changed (2) hide show
  1. package/dist/index.js +74 -131
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -32748,7 +32748,7 @@ var {
32748
32748
  Help
32749
32749
  } = import__.default;
32750
32750
  // package.json
32751
- var version = "0.8.17";
32751
+ var version = "0.8.18";
32752
32752
 
32753
32753
  // src/runner.ts
32754
32754
  import { execSync } from "node:child_process";
@@ -42056,78 +42056,31 @@ var editFile = async (fileContent, operations) => {
42056
42056
  if (!operations || operations.length === 0) {
42057
42057
  throw new Error("At least one edit operation is required");
42058
42058
  }
42059
- const originalLines = fileContent.split(`
42060
- `);
42061
42059
  let updatedContent = fileContent;
42062
42060
  for (const operation of operations) {
42063
- updatedContent = await applyEditOperation(updatedContent, operation, originalLines);
42061
+ updatedContent = await applyEditOperation(updatedContent, operation);
42064
42062
  }
42065
42063
  return updatedContent;
42066
42064
  };
42067
- async function applyEditOperation(fileContent, operation, originalLines) {
42068
- const { start_anchor, end_anchor, new_text, start_anchor_line_start, end_anchor_line_start } = operation;
42069
- if (start_anchor === START_OF_FILE && end_anchor === END_OF_FILE) {
42070
- return new_text;
42071
- }
42072
- if (start_anchor === START_OF_FILE) {
42073
- if (!end_anchor) {
42074
- return new_text + fileContent;
42075
- }
42076
- const afterIndex = findTextWithHint(fileContent, end_anchor, end_anchor_line_start, originalLines);
42077
- return new_text + fileContent.slice(afterIndex);
42065
+ async function applyEditOperation(fileContent, operation) {
42066
+ const { search, replace } = operation;
42067
+ if (search === START_OF_FILE && replace === END_OF_FILE) {
42068
+ throw new Error("Cannot search for START_OF_FILE and replace with END_OF_FILE");
42078
42069
  }
42079
- if (end_anchor === END_OF_FILE) {
42080
- if (!start_anchor) {
42081
- return fileContent + new_text;
42082
- }
42083
- const beforeIndex = findTextWithHint(fileContent, start_anchor, start_anchor_line_start, originalLines);
42084
- const beforeEndIndex = beforeIndex + start_anchor.length;
42085
- return fileContent.slice(0, beforeEndIndex) + new_text;
42086
- }
42087
- if (start_anchor && end_anchor) {
42088
- const beforeIndex = findTextWithHint(fileContent, start_anchor, start_anchor_line_start, originalLines);
42089
- const beforeEndIndex = beforeIndex + start_anchor.length;
42090
- const afterIndex = findTextWithHint(fileContent, end_anchor, end_anchor_line_start, originalLines, beforeEndIndex);
42091
- return fileContent.slice(0, beforeEndIndex) + new_text + fileContent.slice(afterIndex);
42070
+ if (search === END_OF_FILE && replace === START_OF_FILE) {
42071
+ throw new Error("Cannot search for END_OF_FILE and replace with START_OF_FILE");
42092
42072
  }
42093
- if (start_anchor) {
42094
- const beforeIndex = findTextWithHint(fileContent, start_anchor, start_anchor_line_start, originalLines);
42095
- const beforeEndIndex = beforeIndex + start_anchor.length;
42096
- return fileContent.slice(0, beforeEndIndex) + new_text + fileContent.slice(beforeEndIndex);
42073
+ if (search === START_OF_FILE) {
42074
+ return replace + fileContent;
42097
42075
  }
42098
- if (end_anchor) {
42099
- const afterIndex = findTextWithHint(fileContent, end_anchor, end_anchor_line_start, originalLines);
42100
- return fileContent.slice(0, afterIndex) + new_text + fileContent.slice(afterIndex);
42076
+ if (search === END_OF_FILE) {
42077
+ return fileContent + replace;
42101
42078
  }
42102
- throw new Error("Either start_anchor or end_anchor must be specified");
42103
- }
42104
- function findTextWithHint(content, searchText, lineHint, originalLines, startIndex = 0) {
42105
- if (lineHint && lineHint > 0 && lineHint <= originalLines.length) {
42106
- const hintIndex = getLineStartIndex(originalLines, lineHint - 1);
42107
- const searchRadius = 5;
42108
- const windowStart = Math.max(0, hintIndex - searchRadius * 50);
42109
- const windowEnd = Math.min(content.length, hintIndex + searchRadius * 50);
42110
- const windowContent = content.slice(windowStart, windowEnd);
42111
- const relativeIndex = windowContent.indexOf(searchText);
42112
- if (relativeIndex !== -1) {
42113
- const absoluteIndex = windowStart + relativeIndex;
42114
- if (absoluteIndex >= startIndex) {
42115
- return absoluteIndex;
42116
- }
42117
- }
42118
- }
42119
- const index = content.indexOf(searchText, startIndex);
42079
+ const index = fileContent.indexOf(search);
42120
42080
  if (index === -1) {
42121
- throw new Error(`Could not find text: ${searchText}`);
42122
- }
42123
- return index;
42124
- }
42125
- function getLineStartIndex(lines, lineIndex) {
42126
- let index = 0;
42127
- for (let i2 = 0;i2 < lineIndex && i2 < lines.length; i2++) {
42128
- index += lines[i2].length + 1;
42081
+ throw new Error(`Could not find text: ${search}`);
42129
42082
  }
42130
- return index;
42083
+ return fileContent.slice(0, index) + replace + fileContent.slice(index + search.length);
42131
42084
  }
42132
42085
  // ../core/src/tools/utils/getArg.ts
42133
42086
  var getString = (args, name, defaultValue) => {
@@ -43310,7 +43263,7 @@ var renameFile_default = {
43310
43263
  // ../core/src/tools/editFile.ts
43311
43264
  var toolInfo13 = {
43312
43265
  name: "edit_file",
43313
- description: "Request to edit file contents using before/after text anchors with flexible operations. Supports multiple edit operations in a single call.",
43266
+ description: "Request to edit file contents using search/replace operations. Supports multiple edit operations in a single call.",
43314
43267
  parameters: [
43315
43268
  {
43316
43269
  name: "path",
@@ -43320,39 +43273,21 @@ var toolInfo13 = {
43320
43273
  },
43321
43274
  {
43322
43275
  name: "operations",
43323
- description: "Edit operation with start_anchor, end_anchor, new_text, and optional line range hints",
43276
+ description: "Edit operation with search and replace parameters",
43324
43277
  required: true,
43325
43278
  allowMultiple: true,
43326
43279
  children: [
43327
43280
  {
43328
- name: "start_anchor",
43329
- description: `Text to find as the start anchor (use ${START_OF_FILE} for file start)`,
43330
- required: false,
43331
- usageValue: "Text before the edit location"
43332
- },
43333
- {
43334
- name: "end_anchor",
43335
- description: `Text to find as the end anchor (use ${END_OF_FILE} for file end)`,
43336
- required: false,
43337
- usageValue: "Text after the edit location"
43338
- },
43339
- {
43340
- name: "new_text",
43341
- description: "Text to replace the content between start_anchor and end_anchor",
43281
+ name: "search",
43282
+ description: `Text to search for and replace (use ${START_OF_FILE} to insert at file start, ${END_OF_FILE} to insert at file end)`,
43342
43283
  required: true,
43343
- usageValue: "New text content"
43284
+ usageValue: "Text to find and replace"
43344
43285
  },
43345
43286
  {
43346
- name: "start_anchor_line_start",
43347
- description: "Optional line number hint for start_anchor location (1-based)",
43348
- required: false,
43349
- usageValue: "10"
43350
- },
43351
- {
43352
- name: "end_anchor_line_start",
43353
- description: "Optional line number hint for end_anchor location (1-based)",
43354
- required: false,
43355
- usageValue: "20"
43287
+ name: "replace",
43288
+ description: "Text to replace the search text with",
43289
+ required: true,
43290
+ usageValue: "Replacement text"
43356
43291
  }
43357
43292
  ],
43358
43293
  usageValue: "operations here"
@@ -43360,7 +43295,7 @@ var toolInfo13 = {
43360
43295
  ],
43361
43296
  examples: [
43362
43297
  {
43363
- description: "Replace content between two text anchors",
43298
+ description: "Replace specific text",
43364
43299
  parameters: [
43365
43300
  {
43366
43301
  name: "path",
@@ -43369,11 +43304,12 @@ var toolInfo13 = {
43369
43304
  {
43370
43305
  name: "operations",
43371
43306
  value: {
43372
- start_anchor: "function oldFunction() {",
43373
- end_anchor: "}",
43374
- new_text: `
43307
+ search: `function oldFunction() {
43308
+ return 42;
43309
+ }`,
43310
+ replace: `function newFunction() {
43375
43311
  return "new implementation";
43376
- `
43312
+ }`
43377
43313
  }
43378
43314
  }
43379
43315
  ]
@@ -43388,9 +43324,8 @@ var toolInfo13 = {
43388
43324
  {
43389
43325
  name: "operations",
43390
43326
  value: {
43391
- start_anchor: START_OF_FILE,
43392
- end_anchor: "export",
43393
- new_text: `// File header comment
43327
+ search: START_OF_FILE,
43328
+ replace: `// File header comment
43394
43329
  `
43395
43330
  }
43396
43331
  }
@@ -43407,20 +43342,37 @@ var toolInfo13 = {
43407
43342
  name: "operations",
43408
43343
  value: [
43409
43344
  {
43410
- start_anchor: "import React",
43411
- end_anchor: 'from "react"',
43412
- new_text: ", { useState }"
43345
+ search: 'import React from "react"',
43346
+ replace: 'import React, { useState } from "react"'
43413
43347
  },
43414
43348
  {
43415
- start_anchor: "function Component() {",
43416
- end_anchor: "return (",
43417
- new_text: `
43349
+ search: `function Component() {
43350
+ return (`,
43351
+ replace: `function Component() {
43418
43352
  const [state, setState] = useState(false);
43419
- `
43353
+ return (`
43420
43354
  }
43421
43355
  ]
43422
43356
  }
43423
43357
  ]
43358
+ },
43359
+ {
43360
+ description: "Append content at end of file",
43361
+ parameters: [
43362
+ {
43363
+ name: "path",
43364
+ value: "src/footer.ts"
43365
+ },
43366
+ {
43367
+ name: "operations",
43368
+ value: {
43369
+ search: END_OF_FILE,
43370
+ replace: `
43371
+ // End of file appended comment
43372
+ `
43373
+ }
43374
+ }
43375
+ ]
43424
43376
  }
43425
43377
  ],
43426
43378
  permissionLevel: 2 /* Write */
@@ -43967,7 +43919,6 @@ class AgentBase {
43967
43919
  config;
43968
43920
  handlers;
43969
43921
  #messages = [];
43970
- #originalTask;
43971
43922
  #policies;
43972
43923
  constructor(name, ai, config) {
43973
43924
  this.ai = ai;
@@ -44013,7 +43964,6 @@ ${instance.prompt}`;
44013
43964
  await this.config.callback?.(event);
44014
43965
  }
44015
43966
  async start(prompt) {
44016
- this.#originalTask = prompt;
44017
43967
  this.#callback({ kind: "StartTask" /* StartTask */, agent: this, systemPrompt: this.config.systemPrompt });
44018
43968
  return await this.#processLoop(prompt);
44019
43969
  }
@@ -44140,41 +44090,31 @@ ${instance.prompt}`;
44140
44090
  if (toolResponses.length > 0) {
44141
44091
  break outer;
44142
44092
  }
44143
- const handOverResp = {
44144
- ...toolResp,
44145
- originalTask: this.#originalTask
44146
- };
44147
44093
  await this.#callback({
44148
44094
  kind: "ToolHandOver" /* ToolHandOver */,
44149
44095
  agent: this,
44150
44096
  tool: content.name,
44151
- agentName: handOverResp.agentName,
44152
- task: handOverResp.task,
44153
- context: handOverResp.context,
44154
- files: handOverResp.files,
44155
- originalTask: handOverResp.originalTask
44097
+ agentName: toolResp.agentName,
44098
+ task: toolResp.task,
44099
+ context: toolResp.context,
44100
+ files: toolResp.files
44156
44101
  });
44157
- return { type: "exit", reason: handOverResp };
44102
+ return { type: "exit", reason: toolResp };
44158
44103
  }
44159
44104
  case "Delegate" /* Delegate */: {
44160
44105
  if (toolResponses.length > 0) {
44161
44106
  break outer;
44162
44107
  }
44163
- const delegateResp = {
44164
- ...toolResp,
44165
- originalTask: this.#originalTask
44166
- };
44167
44108
  await this.#callback({
44168
44109
  kind: "ToolDelegate" /* ToolDelegate */,
44169
44110
  agent: this,
44170
44111
  tool: content.name,
44171
- agentName: delegateResp.agentName,
44172
- task: delegateResp.task,
44173
- context: delegateResp.context,
44174
- files: delegateResp.files,
44175
- originalTask: delegateResp.originalTask
44112
+ agentName: toolResp.agentName,
44113
+ task: toolResp.task,
44114
+ context: toolResp.context,
44115
+ files: toolResp.files
44176
44116
  });
44177
- return { type: "exit", reason: delegateResp };
44117
+ return { type: "exit", reason: toolResp };
44178
44118
  }
44179
44119
  case "Pause" /* Pause */: {
44180
44120
  await this.#callback({ kind: "ToolPause" /* ToolPause */, agent: this, tool: content.name, object: toolResp.object });
@@ -44398,6 +44338,7 @@ var codeFixerAgentInfo = {
44398
44338
  class MultiAgent {
44399
44339
  #config;
44400
44340
  #agents = [];
44341
+ #originalTask;
44401
44342
  constructor(config) {
44402
44343
  this.#config = config;
44403
44344
  }
@@ -44405,11 +44346,11 @@ class MultiAgent {
44405
44346
  switch (exitReason.type) {
44406
44347
  case "HandOver" /* HandOver */: {
44407
44348
  this.#agents.pop();
44408
- const prompt = await this.#config.getPrompt?.(exitReason.agentName, exitReason.task, exitReason.context, exitReason.files, exitReason.originalTask) ?? exitReason.task;
44349
+ const prompt = await this.#config.getPrompt?.(exitReason.agentName, exitReason.task, exitReason.context, exitReason.files, this.#originalTask) ?? exitReason.task;
44409
44350
  return await this.#startTask(exitReason.agentName, prompt);
44410
44351
  }
44411
44352
  case "Delegate" /* Delegate */: {
44412
- const prompt = await this.#config.getPrompt?.(exitReason.agentName, exitReason.task, exitReason.context, exitReason.files, exitReason.originalTask) ?? exitReason.task;
44353
+ const prompt = await this.#config.getPrompt?.(exitReason.agentName, exitReason.task, exitReason.context, exitReason.files, this.#originalTask) ?? exitReason.task;
44413
44354
  const delegateResult = await this.#startTask(exitReason.agentName, prompt);
44414
44355
  switch (delegateResult.type) {
44415
44356
  case "HandOver" /* HandOver */:
@@ -44441,7 +44382,9 @@ class MultiAgent {
44441
44382
  if (this.#agents.length > 0) {
44442
44383
  throw new Error("An active agent already exists");
44443
44384
  }
44444
- return this.#startTask(options.agentName, options.task);
44385
+ this.#originalTask = options.task;
44386
+ return this.#startTask(options.agentName, `<task>${options.task}</task>
44387
+ <context>${options.context}</context>`);
44445
44388
  }
44446
44389
  async continueTask(userMessage) {
44447
44390
  if (!this.#agents.length) {
@@ -48859,8 +48802,8 @@ var executeAgentTool = async (definition, agent, params) => {
48859
48802
  }
48860
48803
  const exitReason = await agent.startTask({
48861
48804
  agentName: definition.agent,
48862
- task: `<task>${definition.prompt}</task>
48863
- <context>${definition.formatInput(params)}</context>`
48805
+ task: definition.prompt,
48806
+ context: definition.formatInput(params)
48864
48807
  });
48865
48808
  if (exitReason.type === "Exit" /* Exit */) {
48866
48809
  return definition.parseOutput(exitReason.message);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/runner",
3
- "version": "0.8.17",
3
+ "version": "0.8.18",
4
4
  "license": "AGPL-3.0",
5
5
  "author": "github@polka.codes",
6
6
  "type": "module",