@span-io/agent-link 0.1.2 → 0.1.3
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/process-runner.js +55 -4
- package/package.json +1 -1
package/dist/process-runner.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { mkdirSync } from "fs";
|
|
1
2
|
import { spawn } from "child_process";
|
|
2
3
|
const DEFAULT_CODEX_ARGS = "exec --skip-git-repo-check";
|
|
3
4
|
const DEFAULT_GEMINI_ARGS = "";
|
|
@@ -12,6 +13,50 @@ function shellQuote(value) {
|
|
|
12
13
|
// Simple single-quote wrapping for display purposes
|
|
13
14
|
return `'${value.replace(/'/g, `'"'"'`)}'`;
|
|
14
15
|
}
|
|
16
|
+
function collectDirectoriesFromArgs(args) {
|
|
17
|
+
const directories = [];
|
|
18
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
19
|
+
const arg = args[i];
|
|
20
|
+
const next = args[i + 1];
|
|
21
|
+
if ((arg === "--cd" || arg === "-C" || arg === "--add-dir" || arg === "--include-directories") && typeof next === "string") {
|
|
22
|
+
directories.push(next);
|
|
23
|
+
i += 1;
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
if (arg.startsWith("--cd=")) {
|
|
27
|
+
directories.push(arg.slice("--cd=".length));
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
if (arg.startsWith("--add-dir=")) {
|
|
31
|
+
directories.push(arg.slice("--add-dir=".length));
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (arg.startsWith("--include-directories=")) {
|
|
35
|
+
const raw = arg.slice("--include-directories=".length);
|
|
36
|
+
raw
|
|
37
|
+
.split(",")
|
|
38
|
+
.map((entry) => entry.trim())
|
|
39
|
+
.filter(Boolean)
|
|
40
|
+
.forEach((entry) => directories.push(entry));
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return directories;
|
|
45
|
+
}
|
|
46
|
+
function ensureDirectoriesExist(rawDirs) {
|
|
47
|
+
const deduped = new Set(rawDirs
|
|
48
|
+
.map((entry) => entry.trim())
|
|
49
|
+
.filter((entry) => entry.length > 0));
|
|
50
|
+
for (const dir of deduped) {
|
|
51
|
+
try {
|
|
52
|
+
mkdirSync(dir, { recursive: true });
|
|
53
|
+
}
|
|
54
|
+
catch (error) {
|
|
55
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
56
|
+
throw new Error(`Failed to create working directory '${dir}': ${message}`);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
15
60
|
export function buildCommand({ agent, prompt, optionsArgs = [], executablePath }, promptModeOverride) {
|
|
16
61
|
// 1. Gemini Models
|
|
17
62
|
if (agent.model.startsWith("gemini-")) {
|
|
@@ -34,7 +79,13 @@ export function buildCommand({ agent, prompt, optionsArgs = [], executablePath }
|
|
|
34
79
|
// 2. Claude Models
|
|
35
80
|
if (agent.model.startsWith("claude-")) {
|
|
36
81
|
const command = executablePath ?? process.env.CLAUDE_BIN ?? "claude";
|
|
37
|
-
const args = ["-p", prompt
|
|
82
|
+
const args = ["-p", prompt];
|
|
83
|
+
if (optionsArgs.length > 0) {
|
|
84
|
+
args.push(...optionsArgs);
|
|
85
|
+
}
|
|
86
|
+
if (!args.includes("--model") && !args.includes("-m")) {
|
|
87
|
+
args.push("--model", agent.model);
|
|
88
|
+
}
|
|
38
89
|
return { command, args, promptMode: "args" };
|
|
39
90
|
}
|
|
40
91
|
// 3. Generic Codex/Other Models
|
|
@@ -81,11 +132,11 @@ export function spawnAgentProcess(config) {
|
|
|
81
132
|
const { agent, optionsArgs = [] } = config;
|
|
82
133
|
const startedAt = new Date().toISOString();
|
|
83
134
|
const isCodexModel = !agent.model.startsWith("gemini-") && !agent.model.startsWith("claude-");
|
|
84
|
-
const sanitizedOptions =
|
|
85
|
-
? []
|
|
86
|
-
: optionsArgs;
|
|
135
|
+
const sanitizedOptions = optionsArgs;
|
|
87
136
|
const spawnWithMode = (promptModeOverride) => {
|
|
88
137
|
const { command, args, promptMode } = buildCommand({ ...config, optionsArgs: sanitizedOptions }, promptModeOverride);
|
|
138
|
+
// Ensure requested project/working directories exist before launching CLI.
|
|
139
|
+
ensureDirectoriesExist(collectDirectoriesFromArgs(args));
|
|
89
140
|
const ttyMode = process.env.CODEX_TTY_MODE ?? DEFAULT_TTY_MODE;
|
|
90
141
|
const hasExec = args.includes("exec");
|
|
91
142
|
const useScriptWrapper = ttyMode === "script" || (ttyMode === "auto" && hasExec);
|