doer-agent 0.1.7 → 0.1.8
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/agent.js +29 -4
- package/package.json +1 -1
package/dist/agent.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { spawn, spawnSync } from "node:child_process";
|
|
2
|
-
import { existsSync } from "node:fs";
|
|
2
|
+
import { existsSync, statSync } from "node:fs";
|
|
3
3
|
import { chmod, mkdir, readFile, writeFile } from "node:fs/promises";
|
|
4
4
|
import { homedir } from "node:os";
|
|
5
5
|
import path from "node:path";
|
|
@@ -509,6 +509,30 @@ function resolveShellPath() {
|
|
|
509
509
|
}
|
|
510
510
|
throw new Error("No shell executable found. Set SHELL env or install /bin/sh (or bash).");
|
|
511
511
|
}
|
|
512
|
+
function resolveTaskWorkspace(rawCwd) {
|
|
513
|
+
const workspaceRoot = process.env.WORKSPACE?.trim() || process.cwd();
|
|
514
|
+
const requestedCwd = rawCwd?.trim() || "";
|
|
515
|
+
const resolvedCwd = requestedCwd
|
|
516
|
+
? path.isAbsolute(requestedCwd)
|
|
517
|
+
? path.resolve(requestedCwd)
|
|
518
|
+
: path.resolve(workspaceRoot, requestedCwd)
|
|
519
|
+
: workspaceRoot;
|
|
520
|
+
if (!existsSync(resolvedCwd)) {
|
|
521
|
+
throw new Error(`Invalid cwd: ${requestedCwd || "(empty)"} resolved to ${resolvedCwd} (path does not exist)`);
|
|
522
|
+
}
|
|
523
|
+
let stats;
|
|
524
|
+
try {
|
|
525
|
+
stats = statSync(resolvedCwd);
|
|
526
|
+
}
|
|
527
|
+
catch (error) {
|
|
528
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
529
|
+
throw new Error(`Invalid cwd: ${requestedCwd || "(empty)"} resolved to ${resolvedCwd} (${message})`);
|
|
530
|
+
}
|
|
531
|
+
if (!stats.isDirectory()) {
|
|
532
|
+
throw new Error(`Invalid cwd: ${requestedCwd || "(empty)"} resolved to ${resolvedCwd} (not a directory)`);
|
|
533
|
+
}
|
|
534
|
+
return resolvedCwd;
|
|
535
|
+
}
|
|
512
536
|
async function postJson(url, body) {
|
|
513
537
|
const res = await fetch(url, {
|
|
514
538
|
method: "POST",
|
|
@@ -714,6 +738,7 @@ async function runTask(args) {
|
|
|
714
738
|
userId: args.userId,
|
|
715
739
|
};
|
|
716
740
|
const shellPath = resolveShellPath();
|
|
741
|
+
const taskWorkspace = resolveTaskWorkspace(args.cwd);
|
|
717
742
|
const runtimeConfig = await prepareTaskRuntimeConfig({
|
|
718
743
|
serverBaseUrl: args.serverBaseUrl,
|
|
719
744
|
taskId: args.taskId,
|
|
@@ -726,7 +751,6 @@ async function runTask(args) {
|
|
|
726
751
|
userId: args.userId,
|
|
727
752
|
agentToken: args.agentToken,
|
|
728
753
|
});
|
|
729
|
-
const taskWorkspace = args.cwd || process.env.WORKSPACE?.trim() || process.cwd();
|
|
730
754
|
const baseTaskEnvPatch = {
|
|
731
755
|
...(runtimeConfig?.envPatch ?? {}),
|
|
732
756
|
...(codexAuth?.envPatch ?? {}),
|
|
@@ -747,7 +771,8 @@ async function runTask(args) {
|
|
|
747
771
|
pid: process.pid,
|
|
748
772
|
startedAt: formatLocalTimestamp(),
|
|
749
773
|
command: args.command,
|
|
750
|
-
cwd:
|
|
774
|
+
cwd: taskWorkspace,
|
|
775
|
+
requestedCwd: args.cwd,
|
|
751
776
|
shell: shellPath,
|
|
752
777
|
...(runtimeConfig?.meta ?? { runtimeConfigSynced: false }),
|
|
753
778
|
...(codexAuth?.meta ?? { codexAuthSynced: false }),
|
|
@@ -763,7 +788,7 @@ async function runTask(args) {
|
|
|
763
788
|
const runtimeBinPath = path.join(AGENT_PROJECT_DIR, "runtime/bin");
|
|
764
789
|
const taskPath = [runtimeBinPath, process.env.PATH || ""].filter(Boolean).join(path.delimiter);
|
|
765
790
|
const child = spawn(args.command, {
|
|
766
|
-
cwd:
|
|
791
|
+
cwd: taskWorkspace,
|
|
767
792
|
shell: shellPath,
|
|
768
793
|
detached: process.platform !== "win32",
|
|
769
794
|
env: {
|