@polka-codes/cli 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 +80 -137
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -38447,7 +38447,7 @@ var {
38447
38447
  Help
38448
38448
  } = import__.default;
38449
38449
  // package.json
38450
- var version = "0.8.17";
38450
+ var version = "0.8.18";
38451
38451
 
38452
38452
  // ../core/src/AiService/AiServiceBase.ts
38453
38453
  class AiServiceBase {
@@ -47765,78 +47765,31 @@ var editFile = async (fileContent, operations) => {
47765
47765
  if (!operations || operations.length === 0) {
47766
47766
  throw new Error("At least one edit operation is required");
47767
47767
  }
47768
- const originalLines = fileContent.split(`
47769
- `);
47770
47768
  let updatedContent = fileContent;
47771
47769
  for (const operation of operations) {
47772
- updatedContent = await applyEditOperation(updatedContent, operation, originalLines);
47770
+ updatedContent = await applyEditOperation(updatedContent, operation);
47773
47771
  }
47774
47772
  return updatedContent;
47775
47773
  };
47776
- async function applyEditOperation(fileContent, operation, originalLines) {
47777
- const { start_anchor, end_anchor, new_text, start_anchor_line_start, end_anchor_line_start } = operation;
47778
- if (start_anchor === START_OF_FILE && end_anchor === END_OF_FILE) {
47779
- return new_text;
47780
- }
47781
- if (start_anchor === START_OF_FILE) {
47782
- if (!end_anchor) {
47783
- return new_text + fileContent;
47784
- }
47785
- const afterIndex = findTextWithHint(fileContent, end_anchor, end_anchor_line_start, originalLines);
47786
- return new_text + fileContent.slice(afterIndex);
47787
- }
47788
- if (end_anchor === END_OF_FILE) {
47789
- if (!start_anchor) {
47790
- return fileContent + new_text;
47791
- }
47792
- const beforeIndex = findTextWithHint(fileContent, start_anchor, start_anchor_line_start, originalLines);
47793
- const beforeEndIndex = beforeIndex + start_anchor.length;
47794
- return fileContent.slice(0, beforeEndIndex) + new_text;
47795
- }
47796
- if (start_anchor && end_anchor) {
47797
- const beforeIndex = findTextWithHint(fileContent, start_anchor, start_anchor_line_start, originalLines);
47798
- const beforeEndIndex = beforeIndex + start_anchor.length;
47799
- const afterIndex = findTextWithHint(fileContent, end_anchor, end_anchor_line_start, originalLines, beforeEndIndex);
47800
- return fileContent.slice(0, beforeEndIndex) + new_text + fileContent.slice(afterIndex);
47801
- }
47802
- if (start_anchor) {
47803
- const beforeIndex = findTextWithHint(fileContent, start_anchor, start_anchor_line_start, originalLines);
47804
- const beforeEndIndex = beforeIndex + start_anchor.length;
47805
- return fileContent.slice(0, beforeEndIndex) + new_text + fileContent.slice(beforeEndIndex);
47806
- }
47807
- if (end_anchor) {
47808
- const afterIndex = findTextWithHint(fileContent, end_anchor, end_anchor_line_start, originalLines);
47809
- return fileContent.slice(0, afterIndex) + new_text + fileContent.slice(afterIndex);
47810
- }
47811
- throw new Error("Either start_anchor or end_anchor must be specified");
47812
- }
47813
- function findTextWithHint(content, searchText, lineHint, originalLines, startIndex = 0) {
47814
- if (lineHint && lineHint > 0 && lineHint <= originalLines.length) {
47815
- const hintIndex = getLineStartIndex(originalLines, lineHint - 1);
47816
- const searchRadius = 5;
47817
- const windowStart = Math.max(0, hintIndex - searchRadius * 50);
47818
- const windowEnd = Math.min(content.length, hintIndex + searchRadius * 50);
47819
- const windowContent = content.slice(windowStart, windowEnd);
47820
- const relativeIndex = windowContent.indexOf(searchText);
47821
- if (relativeIndex !== -1) {
47822
- const absoluteIndex = windowStart + relativeIndex;
47823
- if (absoluteIndex >= startIndex) {
47824
- return absoluteIndex;
47825
- }
47826
- }
47827
- }
47828
- const index = content.indexOf(searchText, startIndex);
47829
- if (index === -1) {
47830
- throw new Error(`Could not find text: ${searchText}`);
47774
+ async function applyEditOperation(fileContent, operation) {
47775
+ const { search, replace } = operation;
47776
+ if (search === START_OF_FILE && replace === END_OF_FILE) {
47777
+ throw new Error("Cannot search for START_OF_FILE and replace with END_OF_FILE");
47831
47778
  }
47832
- return index;
47833
- }
47834
- function getLineStartIndex(lines, lineIndex) {
47835
- let index = 0;
47836
- for (let i2 = 0;i2 < lineIndex && i2 < lines.length; i2++) {
47837
- index += lines[i2].length + 1;
47779
+ if (search === END_OF_FILE && replace === START_OF_FILE) {
47780
+ throw new Error("Cannot search for END_OF_FILE and replace with START_OF_FILE");
47781
+ }
47782
+ if (search === START_OF_FILE) {
47783
+ return replace + fileContent;
47838
47784
  }
47839
- return index;
47785
+ if (search === END_OF_FILE) {
47786
+ return fileContent + replace;
47787
+ }
47788
+ const index = fileContent.indexOf(search);
47789
+ if (index === -1) {
47790
+ throw new Error(`Could not find text: ${search}`);
47791
+ }
47792
+ return fileContent.slice(0, index) + replace + fileContent.slice(index + search.length);
47840
47793
  }
47841
47794
  // ../core/src/tools/utils/getArg.ts
47842
47795
  var getString = (args, name, defaultValue) => {
@@ -49019,7 +48972,7 @@ var renameFile_default = {
49019
48972
  // ../core/src/tools/editFile.ts
49020
48973
  var toolInfo13 = {
49021
48974
  name: "edit_file",
49022
- description: "Request to edit file contents using before/after text anchors with flexible operations. Supports multiple edit operations in a single call.",
48975
+ description: "Request to edit file contents using search/replace operations. Supports multiple edit operations in a single call.",
49023
48976
  parameters: [
49024
48977
  {
49025
48978
  name: "path",
@@ -49029,39 +48982,21 @@ var toolInfo13 = {
49029
48982
  },
49030
48983
  {
49031
48984
  name: "operations",
49032
- description: "Edit operation with start_anchor, end_anchor, new_text, and optional line range hints",
48985
+ description: "Edit operation with search and replace parameters",
49033
48986
  required: true,
49034
48987
  allowMultiple: true,
49035
48988
  children: [
49036
48989
  {
49037
- name: "start_anchor",
49038
- description: `Text to find as the start anchor (use ${START_OF_FILE} for file start)`,
49039
- required: false,
49040
- usageValue: "Text before the edit location"
49041
- },
49042
- {
49043
- name: "end_anchor",
49044
- description: `Text to find as the end anchor (use ${END_OF_FILE} for file end)`,
49045
- required: false,
49046
- usageValue: "Text after the edit location"
49047
- },
49048
- {
49049
- name: "new_text",
49050
- description: "Text to replace the content between start_anchor and end_anchor",
48990
+ name: "search",
48991
+ description: `Text to search for and replace (use ${START_OF_FILE} to insert at file start, ${END_OF_FILE} to insert at file end)`,
49051
48992
  required: true,
49052
- usageValue: "New text content"
49053
- },
49054
- {
49055
- name: "start_anchor_line_start",
49056
- description: "Optional line number hint for start_anchor location (1-based)",
49057
- required: false,
49058
- usageValue: "10"
48993
+ usageValue: "Text to find and replace"
49059
48994
  },
49060
48995
  {
49061
- name: "end_anchor_line_start",
49062
- description: "Optional line number hint for end_anchor location (1-based)",
49063
- required: false,
49064
- usageValue: "20"
48996
+ name: "replace",
48997
+ description: "Text to replace the search text with",
48998
+ required: true,
48999
+ usageValue: "Replacement text"
49065
49000
  }
49066
49001
  ],
49067
49002
  usageValue: "operations here"
@@ -49069,7 +49004,7 @@ var toolInfo13 = {
49069
49004
  ],
49070
49005
  examples: [
49071
49006
  {
49072
- description: "Replace content between two text anchors",
49007
+ description: "Replace specific text",
49073
49008
  parameters: [
49074
49009
  {
49075
49010
  name: "path",
@@ -49078,11 +49013,12 @@ var toolInfo13 = {
49078
49013
  {
49079
49014
  name: "operations",
49080
49015
  value: {
49081
- start_anchor: "function oldFunction() {",
49082
- end_anchor: "}",
49083
- new_text: `
49016
+ search: `function oldFunction() {
49017
+ return 42;
49018
+ }`,
49019
+ replace: `function newFunction() {
49084
49020
  return "new implementation";
49085
- `
49021
+ }`
49086
49022
  }
49087
49023
  }
49088
49024
  ]
@@ -49097,9 +49033,8 @@ var toolInfo13 = {
49097
49033
  {
49098
49034
  name: "operations",
49099
49035
  value: {
49100
- start_anchor: START_OF_FILE,
49101
- end_anchor: "export",
49102
- new_text: `// File header comment
49036
+ search: START_OF_FILE,
49037
+ replace: `// File header comment
49103
49038
  `
49104
49039
  }
49105
49040
  }
@@ -49116,20 +49051,37 @@ var toolInfo13 = {
49116
49051
  name: "operations",
49117
49052
  value: [
49118
49053
  {
49119
- start_anchor: "import React",
49120
- end_anchor: 'from "react"',
49121
- new_text: ", { useState }"
49054
+ search: 'import React from "react"',
49055
+ replace: 'import React, { useState } from "react"'
49122
49056
  },
49123
49057
  {
49124
- start_anchor: "function Component() {",
49125
- end_anchor: "return (",
49126
- new_text: `
49058
+ search: `function Component() {
49059
+ return (`,
49060
+ replace: `function Component() {
49127
49061
  const [state, setState] = useState(false);
49128
- `
49062
+ return (`
49129
49063
  }
49130
49064
  ]
49131
49065
  }
49132
49066
  ]
49067
+ },
49068
+ {
49069
+ description: "Append content at end of file",
49070
+ parameters: [
49071
+ {
49072
+ name: "path",
49073
+ value: "src/footer.ts"
49074
+ },
49075
+ {
49076
+ name: "operations",
49077
+ value: {
49078
+ search: END_OF_FILE,
49079
+ replace: `
49080
+ // End of file appended comment
49081
+ `
49082
+ }
49083
+ }
49084
+ ]
49133
49085
  }
49134
49086
  ],
49135
49087
  permissionLevel: 2 /* Write */
@@ -49676,7 +49628,6 @@ class AgentBase {
49676
49628
  config;
49677
49629
  handlers;
49678
49630
  #messages = [];
49679
- #originalTask;
49680
49631
  #policies;
49681
49632
  constructor(name, ai, config) {
49682
49633
  this.ai = ai;
@@ -49722,7 +49673,6 @@ ${instance.prompt}`;
49722
49673
  await this.config.callback?.(event);
49723
49674
  }
49724
49675
  async start(prompt) {
49725
- this.#originalTask = prompt;
49726
49676
  this.#callback({ kind: "StartTask" /* StartTask */, agent: this, systemPrompt: this.config.systemPrompt });
49727
49677
  return await this.#processLoop(prompt);
49728
49678
  }
@@ -49849,41 +49799,31 @@ ${instance.prompt}`;
49849
49799
  if (toolResponses.length > 0) {
49850
49800
  break outer;
49851
49801
  }
49852
- const handOverResp = {
49853
- ...toolResp,
49854
- originalTask: this.#originalTask
49855
- };
49856
49802
  await this.#callback({
49857
49803
  kind: "ToolHandOver" /* ToolHandOver */,
49858
49804
  agent: this,
49859
49805
  tool: content.name,
49860
- agentName: handOverResp.agentName,
49861
- task: handOverResp.task,
49862
- context: handOverResp.context,
49863
- files: handOverResp.files,
49864
- originalTask: handOverResp.originalTask
49806
+ agentName: toolResp.agentName,
49807
+ task: toolResp.task,
49808
+ context: toolResp.context,
49809
+ files: toolResp.files
49865
49810
  });
49866
- return { type: "exit", reason: handOverResp };
49811
+ return { type: "exit", reason: toolResp };
49867
49812
  }
49868
49813
  case "Delegate" /* Delegate */: {
49869
49814
  if (toolResponses.length > 0) {
49870
49815
  break outer;
49871
49816
  }
49872
- const delegateResp = {
49873
- ...toolResp,
49874
- originalTask: this.#originalTask
49875
- };
49876
49817
  await this.#callback({
49877
49818
  kind: "ToolDelegate" /* ToolDelegate */,
49878
49819
  agent: this,
49879
49820
  tool: content.name,
49880
- agentName: delegateResp.agentName,
49881
- task: delegateResp.task,
49882
- context: delegateResp.context,
49883
- files: delegateResp.files,
49884
- originalTask: delegateResp.originalTask
49821
+ agentName: toolResp.agentName,
49822
+ task: toolResp.task,
49823
+ context: toolResp.context,
49824
+ files: toolResp.files
49885
49825
  });
49886
- return { type: "exit", reason: delegateResp };
49826
+ return { type: "exit", reason: toolResp };
49887
49827
  }
49888
49828
  case "Pause" /* Pause */: {
49889
49829
  await this.#callback({ kind: "ToolPause" /* ToolPause */, agent: this, tool: content.name, object: toolResp.object });
@@ -50463,6 +50403,7 @@ var coderAgentInfo = {
50463
50403
  class MultiAgent {
50464
50404
  #config;
50465
50405
  #agents = [];
50406
+ #originalTask;
50466
50407
  constructor(config) {
50467
50408
  this.#config = config;
50468
50409
  }
@@ -50470,11 +50411,11 @@ class MultiAgent {
50470
50411
  switch (exitReason.type) {
50471
50412
  case "HandOver" /* HandOver */: {
50472
50413
  this.#agents.pop();
50473
- const prompt = await this.#config.getPrompt?.(exitReason.agentName, exitReason.task, exitReason.context, exitReason.files, exitReason.originalTask) ?? exitReason.task;
50414
+ const prompt = await this.#config.getPrompt?.(exitReason.agentName, exitReason.task, exitReason.context, exitReason.files, this.#originalTask) ?? exitReason.task;
50474
50415
  return await this.#startTask(exitReason.agentName, prompt);
50475
50416
  }
50476
50417
  case "Delegate" /* Delegate */: {
50477
- const prompt = await this.#config.getPrompt?.(exitReason.agentName, exitReason.task, exitReason.context, exitReason.files, exitReason.originalTask) ?? exitReason.task;
50418
+ const prompt = await this.#config.getPrompt?.(exitReason.agentName, exitReason.task, exitReason.context, exitReason.files, this.#originalTask) ?? exitReason.task;
50478
50419
  const delegateResult = await this.#startTask(exitReason.agentName, prompt);
50479
50420
  switch (delegateResult.type) {
50480
50421
  case "HandOver" /* HandOver */:
@@ -50506,7 +50447,9 @@ class MultiAgent {
50506
50447
  if (this.#agents.length > 0) {
50507
50448
  throw new Error("An active agent already exists");
50508
50449
  }
50509
- return this.#startTask(options.agentName, options.task);
50450
+ this.#originalTask = options.task;
50451
+ return this.#startTask(options.agentName, `<task>${options.task}</task>
50452
+ <context>${options.context}</context>`);
50510
50453
  }
50511
50454
  async continueTask(userMessage) {
50512
50455
  if (!this.#agents.length) {
@@ -55132,8 +55075,8 @@ var executeAgentTool = async (definition, agent, params) => {
55132
55075
  }
55133
55076
  const exitReason = await agent.startTask({
55134
55077
  agentName: definition.agent,
55135
- task: `<task>${definition.prompt}</task>
55136
- <context>${definition.formatInput(params)}</context>`
55078
+ task: definition.prompt,
55079
+ context: definition.formatInput(params)
55137
55080
  });
55138
55081
  if (exitReason.type === "Exit" /* Exit */) {
55139
55082
  return definition.parseOutput(exitReason.message);
@@ -61660,8 +61603,8 @@ ${fileList.join(`
61660
61603
  const finalContext = await this.#defaultContext(agentName);
61661
61604
  const exitReason = await this.multiAgent.startTask({
61662
61605
  agentName,
61663
- task: `<task>${task}</task>
61664
- <context>${finalContext}</context>`
61606
+ task,
61607
+ context: finalContext
61665
61608
  });
61666
61609
  return exitReason;
61667
61610
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/cli",
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",