doer-agent 0.2.1 → 0.2.2

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/agent.js +59 -15
  2. package/package.json +1 -1
package/dist/agent.js CHANGED
@@ -357,6 +357,20 @@ function writeTaskStream(taskId, stream, chunk) {
357
357
  function writeTaskUpload(taskId, message) {
358
358
  process.stdout.write(`[doer-agent][task=${taskId}][upload] ${message}\n`);
359
359
  }
360
+ function writeRpcStream(requestId, stream, chunk) {
361
+ const target = stream === "stdout" ? process.stdout : process.stderr;
362
+ const lines = chunk.replace(/\r/g, "\n").split("\n");
363
+ for (let i = 0; i < lines.length; i += 1) {
364
+ const line = lines[i];
365
+ if (line.length === 0 && i === lines.length - 1) {
366
+ continue;
367
+ }
368
+ target.write(`[doer-agent][rpc=${requestId}][${stream}] ${line}\n`);
369
+ }
370
+ }
371
+ function writeRpcStatus(requestId, message) {
372
+ process.stdout.write(`[doer-agent][rpc=${requestId}][status] ${message}\n`);
373
+ }
360
374
  function isLikelyNatsAuthError(error) {
361
375
  const message = (error instanceof Error ? error.message : String(error)).toLowerCase();
362
376
  return (message.includes("auth")
@@ -753,10 +767,15 @@ function normalizeShellRpcRequest(args) {
753
767
  if (requestAgentId !== args.agentId) {
754
768
  throw new Error("agent id mismatch");
755
769
  }
770
+ const kind = args.request.kind === "apply_patch" ? "apply_patch" : "shell";
756
771
  const command = typeof args.request.command === "string" ? args.request.command.trim() : "";
757
- if (!command) {
772
+ const patch = typeof args.request.patch === "string" ? args.request.patch : "";
773
+ if (kind === "shell" && !command) {
758
774
  throw new Error("missing command");
759
775
  }
776
+ if (kind === "apply_patch" && !patch.trim()) {
777
+ throw new Error("missing patch");
778
+ }
760
779
  const responseSubject = typeof args.request.responseSubject === "string" ? args.request.responseSubject.trim() : "";
761
780
  if (!responseSubject) {
762
781
  throw new Error("missing responseSubject");
@@ -765,8 +784,10 @@ function normalizeShellRpcRequest(args) {
765
784
  const timeoutRaw = Number(args.request.timeoutMs);
766
785
  const timeoutMs = Number.isFinite(timeoutRaw) ? Math.max(1000, Math.min(Math.floor(timeoutRaw), 300000)) : 30000;
767
786
  return {
787
+ kind,
768
788
  requestId,
769
- command,
789
+ command: kind === "shell" ? command : null,
790
+ patch: kind === "apply_patch" ? patch : null,
770
791
  cwd,
771
792
  timeoutMs,
772
793
  responseSubject,
@@ -805,6 +826,7 @@ async function handleShellRpcMessage(args) {
805
826
  const request = normalizeShellRpcRequest({ request: payload, agentId: args.agentId });
806
827
  requestId = request.requestId;
807
828
  responseSubject = request.responseSubject;
829
+ const startedAtMs = Date.now();
808
830
  const shellPath = resolveShellPath();
809
831
  const taskWorkspace = resolveTaskWorkspace(request.cwd);
810
832
  const codexAuth = await prepareCodexAuthBundle(request.codexAuthBundle);
@@ -819,26 +841,46 @@ async function handleShellRpcMessage(args) {
819
841
  });
820
842
  const runtimeBinPath = path.join(AGENT_PROJECT_DIR, "runtime/bin");
821
843
  const taskPath = [runtimeBinPath, process.env.PATH || ""].filter(Boolean).join(path.delimiter);
822
- const child = spawn(request.command, {
823
- cwd: taskWorkspace,
824
- shell: shellPath,
825
- detached: process.platform !== "win32",
826
- env: {
827
- ...process.env,
828
- ...baseTaskEnvPatch,
829
- ...taskGitEnv.envPatch,
830
- PATH: taskPath,
831
- DOER_AGENT_TOKEN: args.agentToken,
832
- },
833
- stdio: ["ignore", "pipe", "pipe"],
834
- });
844
+ const child = request.kind === "apply_patch"
845
+ ? spawn("apply_patch", {
846
+ cwd: taskWorkspace,
847
+ detached: process.platform !== "win32",
848
+ env: {
849
+ ...process.env,
850
+ ...baseTaskEnvPatch,
851
+ ...taskGitEnv.envPatch,
852
+ PATH: taskPath,
853
+ DOER_AGENT_TOKEN: args.agentToken,
854
+ },
855
+ stdio: ["pipe", "pipe", "pipe"],
856
+ })
857
+ : spawn(request.command ?? "", {
858
+ cwd: taskWorkspace,
859
+ shell: shellPath,
860
+ detached: process.platform !== "win32",
861
+ env: {
862
+ ...process.env,
863
+ ...baseTaskEnvPatch,
864
+ ...taskGitEnv.envPatch,
865
+ PATH: taskPath,
866
+ DOER_AGENT_TOKEN: args.agentToken,
867
+ },
868
+ stdio: ["ignore", "pipe", "pipe"],
869
+ });
870
+ if (request.kind === "apply_patch") {
871
+ child.stdin?.write(request.patch ?? "");
872
+ child.stdin?.end();
873
+ }
874
+ writeRpcStatus(requestId, `started kind=${request.kind} cwd=${taskWorkspace} shell=${request.kind === "shell" ? shellPath : "apply_patch"}`);
835
875
  child.stdout.setEncoding("utf8");
836
876
  child.stderr.setEncoding("utf8");
837
877
  child.stdout.on("data", (chunk) => {
838
878
  stdout += chunk;
879
+ writeRpcStream(requestId, "stdout", chunk);
839
880
  });
840
881
  child.stderr.on("data", (chunk) => {
841
882
  stderr += chunk;
883
+ writeRpcStream(requestId, "stderr", chunk);
842
884
  });
843
885
  let timedOut = false;
844
886
  const timeout = setTimeout(() => {
@@ -870,6 +912,7 @@ async function handleShellRpcMessage(args) {
870
912
  ...(timedOut ? { error: `Command timed out after ${request.timeoutMs}ms` } : {}),
871
913
  },
872
914
  });
915
+ writeRpcStatus(requestId, `${timedOut ? "timed_out" : "completed"} exitCode=${result.exitCode ?? "null"} signal=${result.signal ?? "null"} durationMs=${Date.now() - startedAtMs}`);
873
916
  }
874
917
  catch (error) {
875
918
  const message = error instanceof Error ? error.message : String(error);
@@ -888,6 +931,7 @@ async function handleShellRpcMessage(args) {
888
931
  },
889
932
  });
890
933
  }
934
+ writeRpcStatus(requestId, `failed error=${message}`);
891
935
  writeAgentError(`shell rpc failed requestId=${requestId} error=${message}`);
892
936
  }
893
937
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "doer-agent",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "Reverse-polling agent runtime for doer",
5
5
  "type": "module",
6
6
  "main": "dist/agent.js",