claude-task-worker 0.27.0 → 0.27.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.
- package/dist/index.js +34 -39
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -65,7 +65,6 @@ __export(herdr_exports, {
|
|
|
65
65
|
getCurrentWorkspaceId: () => getCurrentWorkspaceId,
|
|
66
66
|
paneClose: () => paneClose,
|
|
67
67
|
paneGet: () => paneGet,
|
|
68
|
-
paneMoveToNewTab: () => paneMoveToNewTab,
|
|
69
68
|
paneProcessInfo: () => paneProcessInfo,
|
|
70
69
|
paneRead: () => paneRead,
|
|
71
70
|
paneSendKeys: () => paneSendKeys,
|
|
@@ -79,6 +78,7 @@ __export(herdr_exports, {
|
|
|
79
78
|
workspaceList: () => workspaceList
|
|
80
79
|
});
|
|
81
80
|
import { createRequire as createRequire2 } from "node:module";
|
|
81
|
+
import { resolve as resolvePath } from "node:path";
|
|
82
82
|
function runHerdr(args) {
|
|
83
83
|
return new Promise((resolve3) => {
|
|
84
84
|
childProcess2.execFile(
|
|
@@ -86,24 +86,30 @@ function runHerdr(args) {
|
|
|
86
86
|
args,
|
|
87
87
|
{ timeout: HERDR_TIMEOUT_MS, killSignal: "SIGKILL" },
|
|
88
88
|
(error, stdout, stderr) => {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
} catch {
|
|
93
|
-
parsed = void 0;
|
|
94
|
-
}
|
|
95
|
-
resolve3({ execError: error, parsed, stdout, stderr });
|
|
89
|
+
const parsed = parseHerdrResponse(stdout);
|
|
90
|
+
const stderrError = parsed?.error ? void 0 : parseHerdrResponse(stderr)?.error;
|
|
91
|
+
resolve3({ execError: error, parsed, stderrError, stdout, stderr });
|
|
96
92
|
}
|
|
97
93
|
);
|
|
98
94
|
});
|
|
99
95
|
}
|
|
96
|
+
function parseHerdrResponse(output) {
|
|
97
|
+
try {
|
|
98
|
+
const parsed = JSON.parse(output);
|
|
99
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) return void 0;
|
|
100
|
+
return parsed;
|
|
101
|
+
} catch {
|
|
102
|
+
return void 0;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
100
105
|
async function execHerdr(args, options) {
|
|
101
|
-
const { execError, parsed, stdout, stderr } = await runHerdr(args);
|
|
106
|
+
const { execError, parsed, stderrError, stdout, stderr } = await runHerdr(args);
|
|
102
107
|
const stderrSuffix = stderr.trim() ? `: ${stderr.trim()}` : "";
|
|
103
|
-
|
|
108
|
+
const errorPayload = parsed?.error ?? stderrError;
|
|
109
|
+
if (errorPayload) {
|
|
104
110
|
throw new HerdrError(
|
|
105
|
-
`herdr ${args.join(" ")} failed: [${
|
|
106
|
-
|
|
111
|
+
`herdr ${args.join(" ")} failed: [${errorPayload.code}] ${errorPayload.message}`,
|
|
112
|
+
errorPayload.code
|
|
107
113
|
);
|
|
108
114
|
}
|
|
109
115
|
if (execError) {
|
|
@@ -121,6 +127,9 @@ function envArgs(env) {
|
|
|
121
127
|
if (!env) return [];
|
|
122
128
|
return Object.entries(env).flatMap(([key, value]) => ["--env", `${key}=${value}`]);
|
|
123
129
|
}
|
|
130
|
+
function cwdArgs(cwd) {
|
|
131
|
+
return ["--cwd", resolvePath(cwd)];
|
|
132
|
+
}
|
|
124
133
|
async function tabCreate({
|
|
125
134
|
label,
|
|
126
135
|
cwd,
|
|
@@ -133,8 +142,7 @@ async function tabCreate({
|
|
|
133
142
|
...workspaceId ? ["--workspace", workspaceId] : [],
|
|
134
143
|
"--label",
|
|
135
144
|
label,
|
|
136
|
-
|
|
137
|
-
cwd,
|
|
145
|
+
...cwdArgs(cwd),
|
|
138
146
|
...envArgs(env),
|
|
139
147
|
"--no-focus"
|
|
140
148
|
]);
|
|
@@ -183,8 +191,7 @@ async function workspaceCreate({
|
|
|
183
191
|
"create",
|
|
184
192
|
"--label",
|
|
185
193
|
label,
|
|
186
|
-
|
|
187
|
-
cwd,
|
|
194
|
+
...cwdArgs(cwd),
|
|
188
195
|
...envArgs(env),
|
|
189
196
|
"--no-focus"
|
|
190
197
|
]);
|
|
@@ -214,6 +221,7 @@ async function agentStart({
|
|
|
214
221
|
cwd,
|
|
215
222
|
argv,
|
|
216
223
|
workspaceId,
|
|
224
|
+
tabId: targetTabId,
|
|
217
225
|
env
|
|
218
226
|
}) {
|
|
219
227
|
const result = await execHerdr([
|
|
@@ -221,8 +229,8 @@ async function agentStart({
|
|
|
221
229
|
"start",
|
|
222
230
|
name,
|
|
223
231
|
...workspaceId ? ["--workspace", workspaceId] : [],
|
|
224
|
-
"--
|
|
225
|
-
cwd,
|
|
232
|
+
...targetTabId ? ["--tab", targetTabId] : [],
|
|
233
|
+
...cwdArgs(cwd),
|
|
226
234
|
...envArgs(env),
|
|
227
235
|
"--no-focus",
|
|
228
236
|
"--",
|
|
@@ -235,23 +243,6 @@ async function agentStart({
|
|
|
235
243
|
}
|
|
236
244
|
return { paneId, tabId };
|
|
237
245
|
}
|
|
238
|
-
async function paneMoveToNewTab(paneId, { label, workspaceId }) {
|
|
239
|
-
const result = await execHerdr([
|
|
240
|
-
"pane",
|
|
241
|
-
"move",
|
|
242
|
-
paneId,
|
|
243
|
-
"--new-tab",
|
|
244
|
-
...workspaceId ? ["--workspace", workspaceId] : [],
|
|
245
|
-
"--label",
|
|
246
|
-
label,
|
|
247
|
-
"--no-focus"
|
|
248
|
-
]);
|
|
249
|
-
const tabId = result?.move_result?.created_tab?.tab_id;
|
|
250
|
-
if (!tabId) {
|
|
251
|
-
throw new Error("Failed to move pane to a new tab: invalid response structure from herdr");
|
|
252
|
-
}
|
|
253
|
-
return { tabId };
|
|
254
|
-
}
|
|
255
246
|
function toAgentStatus(value) {
|
|
256
247
|
return value === "working" || value === "idle" || value === "blocked" ? value : "unknown";
|
|
257
248
|
}
|
|
@@ -430,15 +421,19 @@ async function startHerdrTask({
|
|
|
430
421
|
herdr
|
|
431
422
|
}) {
|
|
432
423
|
const mod = herdr ?? await loadHerdr();
|
|
433
|
-
const { paneId } = await mod.
|
|
424
|
+
const { tabId, paneId: shellPaneId } = await mod.tabCreate({ label, cwd, workspaceId, env });
|
|
425
|
+
let paneId;
|
|
434
426
|
try {
|
|
435
|
-
|
|
436
|
-
return { paneId, tabId };
|
|
427
|
+
({ paneId } = await mod.agentStart({ name: label, cwd, argv, env, workspaceId, tabId }));
|
|
437
428
|
} catch (err) {
|
|
438
|
-
await mod.
|
|
429
|
+
await mod.tabClose(tabId).catch(() => {
|
|
439
430
|
});
|
|
440
431
|
throw err;
|
|
441
432
|
}
|
|
433
|
+
await mod.paneClose(shellPaneId).catch((err) => {
|
|
434
|
+
console.error(`[herdr-runner] failed to close the placeholder shell pane ${shellPaneId}: ${err}`);
|
|
435
|
+
});
|
|
436
|
+
return { paneId, tabId };
|
|
442
437
|
}
|
|
443
438
|
async function waitForHerdrTask(paneId, options) {
|
|
444
439
|
const mod = options?.herdr ?? await loadHerdr();
|