@polka-codes/runner 0.7.24 → 0.8.1

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 +86 -34
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -25790,11 +25790,11 @@ var {
25790
25790
  Help
25791
25791
  } = import__.default;
25792
25792
  // package.json
25793
- var version = "0.7.24";
25793
+ var version = "0.8.1";
25794
25794
 
25795
25795
  // src/runner.ts
25796
25796
  import { execSync } from "node:child_process";
25797
- import { existsSync as existsSync2, readFileSync as readFileSync2 } from "node:fs";
25797
+ import { promises as fs5 } from "node:fs";
25798
25798
 
25799
25799
  // ../cli-shared/src/config.ts
25800
25800
  import { existsSync, readFileSync } from "node:fs";
@@ -54535,6 +54535,11 @@ var wsOutgoingMessageSchema = z3.discriminatedUnion("type", [
54535
54535
  response: z3.string()
54536
54536
  }))
54537
54537
  }),
54538
+ z3.object({
54539
+ type: z3.literal("pending_tools_response_completed"),
54540
+ step: z3.number(),
54541
+ index: z3.number()
54542
+ }),
54538
54543
  z3.object({
54539
54544
  type: z3.literal("file"),
54540
54545
  path: z3.string(),
@@ -54742,29 +54747,71 @@ class Runner {
54742
54747
  console.log(`Received tool requests for step ${message.step}:`, message.requests.map((r2) => r2.tool));
54743
54748
  const responses = [];
54744
54749
  for (const request of message.requests) {
54745
- let respMsg;
54746
- try {
54747
- console.log(`Executing tool: ${request.tool} with params:`, request.params);
54748
- const tool2 = this.availableTools[request.tool];
54749
- if (tool2) {
54750
- const resp = await tool2.handler(this.provider, request.params);
54751
- if (resp.type === "Reply" /* Reply */) {
54752
- respMsg = responsePrompts.toolResults(request.tool, resp.message);
54753
- } else {
54754
- respMsg = responsePrompts.errorInvokeTool(request.tool, `Unexpected tool response: ${JSON.stringify(resp)}`);
54750
+ const fn = async () => {
54751
+ try {
54752
+ console.log(`Executing tool: ${request.tool} with params:`, request.params);
54753
+ if (request.params.overridenAgent === "coder" && this.provider.executeCommand) {
54754
+ const { format, check, test } = request.params;
54755
+ if (format) {
54756
+ try {
54757
+ await this.provider.executeCommand(format, false);
54758
+ } catch (error) {
54759
+ console.warn(`Failed to format code using command: ${format}`, error);
54760
+ }
54761
+ }
54762
+ if (check) {
54763
+ try {
54764
+ const { exitCode, stdout, stderr } = await this.provider.executeCommand(check, false);
54765
+ if (exitCode !== 0) {
54766
+ return responsePrompts.commandResult(check, exitCode, stdout, stderr);
54767
+ }
54768
+ } catch (error) {
54769
+ console.warn(`Failed to check code using command: ${check}`, error);
54770
+ }
54771
+ }
54772
+ if (test) {
54773
+ try {
54774
+ const { exitCode, stdout, stderr } = await this.provider.executeCommand(test, false);
54775
+ if (exitCode !== 0) {
54776
+ return responsePrompts.commandResult(test, exitCode, stdout, stderr);
54777
+ }
54778
+ } catch (error) {
54779
+ console.warn(`Failed to test code using command: ${test}`, error);
54780
+ }
54781
+ }
54782
+ return {
54783
+ type: "exit"
54784
+ };
54755
54785
  }
54756
- } else {
54757
- respMsg = responsePrompts.errorInvokeTool(request.tool, "Tool not available");
54786
+ const tool2 = this.availableTools[request.tool];
54787
+ if (tool2) {
54788
+ const resp = await tool2.handler(this.provider, request.params);
54789
+ if (resp.type === "Reply" /* Reply */) {
54790
+ return responsePrompts.toolResults(request.tool, resp.message);
54791
+ }
54792
+ return responsePrompts.errorInvokeTool(request.tool, `Unexpected tool response: ${JSON.stringify(resp)}`);
54793
+ }
54794
+ return responsePrompts.errorInvokeTool(request.tool, "Tool not available");
54795
+ } catch (toolError) {
54796
+ console.error(`Error executing tool ${request.tool}:`, toolError);
54797
+ return responsePrompts.errorInvokeTool(request.tool, toolError);
54758
54798
  }
54759
- } catch (toolError) {
54760
- console.error(`Error executing tool ${request.tool}:`, toolError);
54761
- respMsg = responsePrompts.errorInvokeTool(request.tool, toolError);
54799
+ };
54800
+ const respMsg = await fn();
54801
+ if (typeof respMsg === "string") {
54802
+ responses.push({
54803
+ index: request.index,
54804
+ tool: request.tool,
54805
+ response: respMsg
54806
+ });
54807
+ } else if (respMsg.type === "exit") {
54808
+ this.wsManager.sendMessage({
54809
+ type: "pending_tools_response_completed",
54810
+ step: message.step,
54811
+ index: request.index
54812
+ });
54813
+ return;
54762
54814
  }
54763
- responses.push({
54764
- index: request.index,
54765
- tool: request.tool,
54766
- response: respMsg
54767
- });
54768
54815
  }
54769
54816
  this.wsManager.sendMessage({
54770
54817
  type: "pending_tools_response",
@@ -54781,7 +54828,7 @@ class Runner {
54781
54828
  switch (change.status) {
54782
54829
  case "added":
54783
54830
  case "modified":
54784
- this.sendFileContent(change.path);
54831
+ await this.sendFileContent(change.path);
54785
54832
  break;
54786
54833
  case "deleted":
54787
54834
  this.sendFileDeleted(change.path);
@@ -54789,7 +54836,7 @@ class Runner {
54789
54836
  case "renamed":
54790
54837
  if (change.oldPath) {
54791
54838
  this.sendFileDeleted(change.oldPath);
54792
- this.sendFileContent(change.path);
54839
+ await this.sendFileContent(change.path);
54793
54840
  }
54794
54841
  break;
54795
54842
  }
@@ -54841,10 +54888,20 @@ class Runner {
54841
54888
  }
54842
54889
  return changes;
54843
54890
  }
54844
- sendFileContent(path4) {
54891
+ async sendFileContent(path4) {
54845
54892
  try {
54846
- if (existsSync2(path4)) {
54847
- const content = readFileSync2(path4, "utf8");
54893
+ const stat = await fs5.stat(path4).catch(() => null);
54894
+ if (!stat) {
54895
+ console.error(`File or directory not found: ${path4}`);
54896
+ return;
54897
+ }
54898
+ if (stat.isDirectory()) {
54899
+ const [files] = await listFiles(path4, true, 1000, process.cwd());
54900
+ for (const file of files) {
54901
+ await this.sendFileContent(file);
54902
+ }
54903
+ } else if (stat.isFile()) {
54904
+ const content = await fs5.readFile(path4, "utf8");
54848
54905
  this.wsManager.sendMessage({
54849
54906
  type: "file",
54850
54907
  path: path4,
@@ -54852,15 +54909,10 @@ class Runner {
54852
54909
  });
54853
54910
  console.log(`Sent content for file: ${path4}`);
54854
54911
  } else {
54855
- console.error(`File not found: ${path4}`);
54856
- this.wsManager.sendMessage({
54857
- type: "error",
54858
- message: "File not found",
54859
- details: path4
54860
- });
54912
+ console.error(`Path is not a file or directory: ${path4}`);
54861
54913
  }
54862
54914
  } catch (error) {
54863
- console.error(`Error reading file ${path4}:`, error);
54915
+ console.error(`Error processing path ${path4}:`, error);
54864
54916
  }
54865
54917
  }
54866
54918
  sendFileDeleted(path4) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@polka-codes/runner",
3
- "version": "0.7.24",
3
+ "version": "0.8.1",
4
4
  "license": "AGPL-3.0",
5
5
  "author": "github@polka.codes",
6
6
  "type": "module",