@losoft/taube 0.1.6 → 0.1.7
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/README.md +123 -21
- package/dist/cli.js +811 -162
- package/package.json +3 -3
- package/plugins/taube/.claude-plugin/plugin.json +1 -1
- package/plugins/taube/.codex-plugin/plugin.json +1 -1
- package/plugins/taube/.cursor-plugin/plugin.json +1 -1
- package/plugins/taube/.grok-plugin/plugin.json +1 -1
- package/plugins/taube/skills/taube-dispatch/SKILL.md +22 -4
package/dist/cli.js
CHANGED
|
@@ -1,90 +1,198 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
var __esm = (fn, res, err) => () => {
|
|
3
|
+
if (fn)
|
|
4
|
+
try {
|
|
5
|
+
res = fn(fn = 0);
|
|
6
|
+
} catch (e) {
|
|
7
|
+
err = [e];
|
|
8
|
+
}
|
|
9
|
+
if (err)
|
|
10
|
+
throw err[0];
|
|
11
|
+
return res;
|
|
12
|
+
};
|
|
2
13
|
|
|
3
|
-
// src/
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import { constants } from "node:os";
|
|
11
|
-
import { resolve as resolve2 } from "node:path";
|
|
12
|
-
import { text } from "node:stream/consumers";
|
|
14
|
+
// src/home.ts
|
|
15
|
+
import { homedir } from "node:os";
|
|
16
|
+
import { join, resolve } from "node:path";
|
|
17
|
+
function taubeHome() {
|
|
18
|
+
return resolve(process.env.LOSOFT_TABE_HOME || join(homedir(), ".taube"));
|
|
19
|
+
}
|
|
20
|
+
var init_home = () => {};
|
|
13
21
|
|
|
14
|
-
// src/
|
|
15
|
-
import {
|
|
16
|
-
|
|
22
|
+
// src/sessions.ts
|
|
23
|
+
import { randomUUID } from "node:crypto";
|
|
24
|
+
import {
|
|
25
|
+
mkdir,
|
|
26
|
+
readdir,
|
|
27
|
+
readFile,
|
|
28
|
+
rename,
|
|
29
|
+
rm,
|
|
30
|
+
writeFile
|
|
31
|
+
} from "node:fs/promises";
|
|
32
|
+
import { join as join2 } from "node:path";
|
|
33
|
+
async function linuxProcess(pid) {
|
|
34
|
+
if (process.platform !== "linux")
|
|
35
|
+
return;
|
|
17
36
|
try {
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
37
|
+
const [stat, boot] = await Promise.all([
|
|
38
|
+
readFile(`/proc/${pid}/stat`, "utf8"),
|
|
39
|
+
readFile("/proc/sys/kernel/random/boot_id", "utf8")
|
|
40
|
+
]);
|
|
41
|
+
const fields = stat.slice(stat.lastIndexOf(")") + 2).split(" ");
|
|
42
|
+
return {
|
|
43
|
+
identity: `${boot.trim()}:${fields[19]}`,
|
|
44
|
+
zombie: fields[0] === "Z" || fields[0] === "X"
|
|
45
|
+
};
|
|
46
|
+
} catch {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
22
49
|
}
|
|
23
|
-
function
|
|
24
|
-
const
|
|
25
|
-
if (
|
|
26
|
-
return
|
|
50
|
+
async function ownerAlive(owner) {
|
|
51
|
+
const proc = await linuxProcess(owner.pid);
|
|
52
|
+
if (proc)
|
|
53
|
+
return !proc.zombie && (!owner.identity || proc.identity === owner.identity);
|
|
54
|
+
try {
|
|
55
|
+
process.kill(owner.pid, 0);
|
|
56
|
+
return true;
|
|
57
|
+
} catch (error) {
|
|
58
|
+
if (error.code === "ESRCH")
|
|
59
|
+
return false;
|
|
60
|
+
if (error.code === "EPERM")
|
|
61
|
+
return true;
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
async function save(path, value) {
|
|
66
|
+
const temporary = `${path}.${randomUUID()}.tmp`;
|
|
67
|
+
try {
|
|
68
|
+
await writeFile(temporary, JSON.stringify(value), {
|
|
69
|
+
mode: 384,
|
|
70
|
+
flag: "wx"
|
|
71
|
+
});
|
|
72
|
+
await rename(temporary, path);
|
|
73
|
+
} finally {
|
|
74
|
+
await rm(temporary, { force: true });
|
|
27
75
|
}
|
|
28
76
|
}
|
|
29
|
-
async function
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
77
|
+
async function startSession(target, cwd, dispatcher) {
|
|
78
|
+
const directory = join2(taubeHome(), "sessions");
|
|
79
|
+
await mkdir(directory, { mode: 448, recursive: true });
|
|
80
|
+
const id = randomUUID();
|
|
81
|
+
const path = join2(directory, `${id}.json`);
|
|
82
|
+
const owner = {
|
|
83
|
+
pid: process.pid,
|
|
84
|
+
identity: (await linuxProcess(process.pid))?.identity ?? null
|
|
85
|
+
};
|
|
86
|
+
let session = {
|
|
87
|
+
id,
|
|
88
|
+
acpSessionId: null,
|
|
89
|
+
target,
|
|
90
|
+
cwd,
|
|
91
|
+
dispatcher,
|
|
92
|
+
status: "running",
|
|
93
|
+
startedAt: new Date().toISOString(),
|
|
94
|
+
finishedAt: null,
|
|
95
|
+
exitCode: null
|
|
96
|
+
};
|
|
97
|
+
await save(path, { session, owner });
|
|
98
|
+
let pending = Promise.resolve();
|
|
99
|
+
function update(changes) {
|
|
100
|
+
session = { ...session, ...changes };
|
|
101
|
+
const snapshot = { owner, session };
|
|
102
|
+
const write = pending.then(() => save(path, snapshot));
|
|
103
|
+
pending = write.catch(() => {});
|
|
104
|
+
return write;
|
|
105
|
+
}
|
|
106
|
+
return {
|
|
107
|
+
id,
|
|
108
|
+
attach: (acpSessionId) => update({ acpSessionId }),
|
|
109
|
+
finish: (status, exitCode) => update({ status, exitCode, finishedAt: new Date().toISOString() })
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
async function read(path) {
|
|
113
|
+
return JSON.parse(await readFile(path, "utf8"));
|
|
114
|
+
}
|
|
115
|
+
async function listSessions() {
|
|
116
|
+
const directory = join2(taubeHome(), "sessions");
|
|
117
|
+
let names;
|
|
118
|
+
try {
|
|
119
|
+
names = await readdir(directory);
|
|
120
|
+
} catch (error) {
|
|
121
|
+
if (error.code === "ENOENT")
|
|
122
|
+
return [];
|
|
123
|
+
throw error;
|
|
124
|
+
}
|
|
125
|
+
const sessions = [];
|
|
126
|
+
for (const name of names) {
|
|
127
|
+
if (!name.endsWith(".json"))
|
|
37
128
|
continue;
|
|
129
|
+
const path = join2(directory, name);
|
|
130
|
+
let entry = await read(path);
|
|
131
|
+
if (entry.session.status === "running" && !await ownerAlive(entry.owner)) {
|
|
132
|
+
entry = await read(path);
|
|
133
|
+
if (entry.session.status === "running") {
|
|
134
|
+
entry.session.status = "interrupted";
|
|
135
|
+
await save(path, entry);
|
|
136
|
+
}
|
|
38
137
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
138
|
+
sessions.push(entry.session);
|
|
139
|
+
}
|
|
140
|
+
return sessions.sort((a, b) => b.startedAt.localeCompare(a.startedAt) || a.id.localeCompare(b.id));
|
|
141
|
+
}
|
|
142
|
+
var init_sessions = __esm(() => {
|
|
143
|
+
init_home();
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
// src/auth-state.ts
|
|
147
|
+
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
148
|
+
import { mkdir as mkdir2, readFile as readFile2, rename as rename2, rm as rm2, writeFile as writeFile2 } from "node:fs/promises";
|
|
149
|
+
import { join as join3 } from "node:path";
|
|
150
|
+
async function readAuth(target) {
|
|
151
|
+
const path = join3(taubeHome(), "auth", `${target}.json`);
|
|
152
|
+
let contents;
|
|
153
|
+
try {
|
|
154
|
+
contents = await readFile2(path, "utf8");
|
|
155
|
+
} catch (error) {
|
|
156
|
+
if (error.code === "ENOENT")
|
|
157
|
+
return { authenticated: false, checkedAt: null };
|
|
158
|
+
throw error;
|
|
159
|
+
}
|
|
160
|
+
try {
|
|
161
|
+
const { authenticated, checkedAt } = JSON.parse(contents);
|
|
162
|
+
if (typeof authenticated === "boolean" && typeof checkedAt === "string" && Number.isFinite(Date.parse(checkedAt)))
|
|
163
|
+
return { authenticated, checkedAt };
|
|
164
|
+
} catch {}
|
|
165
|
+
throw new Error(`Invalid authentication cache for ${target}.`);
|
|
166
|
+
}
|
|
167
|
+
async function recordAuth(target, authenticated) {
|
|
168
|
+
const directory = join3(taubeHome(), "auth");
|
|
169
|
+
await mkdir2(directory, { recursive: true, mode: 448 });
|
|
170
|
+
const result = { authenticated, checkedAt: new Date().toISOString() };
|
|
171
|
+
const path = join3(directory, `${target}.json`);
|
|
172
|
+
const temporary = `${path}.${randomUUID2()}.tmp`;
|
|
173
|
+
try {
|
|
174
|
+
await writeFile2(temporary, JSON.stringify(result), {
|
|
175
|
+
mode: 384,
|
|
176
|
+
flag: "wx"
|
|
177
|
+
});
|
|
178
|
+
await rename2(temporary, path);
|
|
179
|
+
} finally {
|
|
180
|
+
await rm2(temporary, { force: true });
|
|
50
181
|
}
|
|
51
182
|
return result;
|
|
52
183
|
}
|
|
184
|
+
var init_auth_state = __esm(() => {
|
|
185
|
+
init_home();
|
|
186
|
+
});
|
|
53
187
|
|
|
54
188
|
// src/targets.ts
|
|
55
189
|
import { accessSync, constants as fsConstants, statSync } from "node:fs";
|
|
56
|
-
import { delimiter, resolve } from "node:path";
|
|
57
|
-
var targets = [
|
|
58
|
-
{
|
|
59
|
-
id: "codex",
|
|
60
|
-
profile: "codex",
|
|
61
|
-
launcher: "codex-acp",
|
|
62
|
-
effortOption: "reasoning_effort"
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
id: "claude",
|
|
66
|
-
profile: "claude",
|
|
67
|
-
launcher: "claude-agent-acp",
|
|
68
|
-
effortOption: "effort"
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
id: "grok",
|
|
72
|
-
profile: "grok-build",
|
|
73
|
-
launcher: "grok",
|
|
74
|
-
effortOption: "reasoning_effort"
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
id: "cursor",
|
|
78
|
-
profile: "cursor",
|
|
79
|
-
launcher: "cursor-agent",
|
|
80
|
-
effortOption: null
|
|
81
|
-
}
|
|
82
|
-
];
|
|
190
|
+
import { delimiter, resolve as resolve2 } from "node:path";
|
|
83
191
|
function executableOnPath(command) {
|
|
84
192
|
const extensions = process.platform === "win32" ? (process.env.PATHEXT ?? ".EXE;.CMD;.BAT").split(";") : [""];
|
|
85
193
|
for (const directory of (process.env.PATH ?? "").split(delimiter)) {
|
|
86
194
|
for (const extension of extensions) {
|
|
87
|
-
const candidate =
|
|
195
|
+
const candidate = resolve2(directory, command + extension);
|
|
88
196
|
try {
|
|
89
197
|
accessSync(candidate, fsConstants.X_OK);
|
|
90
198
|
if (statSync(candidate).isFile())
|
|
@@ -93,139 +201,675 @@ function executableOnPath(command) {
|
|
|
93
201
|
}
|
|
94
202
|
}
|
|
95
203
|
}
|
|
96
|
-
function surfaces() {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
204
|
+
async function surfaces() {
|
|
205
|
+
const entries = await Promise.all(targets.map(async ({ id, profile, effortOption, launcher }) => ({
|
|
206
|
+
id,
|
|
207
|
+
profile,
|
|
208
|
+
effortOption,
|
|
209
|
+
launcher: {
|
|
210
|
+
command: launcher,
|
|
211
|
+
onPath: Boolean(executableOnPath(launcher))
|
|
212
|
+
},
|
|
213
|
+
...await readAuth(id)
|
|
214
|
+
})));
|
|
215
|
+
return { targets: entries };
|
|
216
|
+
}
|
|
217
|
+
var targets;
|
|
218
|
+
var init_targets = __esm(() => {
|
|
219
|
+
init_auth_state();
|
|
220
|
+
targets = [
|
|
221
|
+
{
|
|
222
|
+
id: "codex",
|
|
223
|
+
profile: "codex",
|
|
224
|
+
launcher: "codex-acp",
|
|
225
|
+
effortOption: "reasoning_effort"
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
id: "claude",
|
|
229
|
+
profile: "claude",
|
|
230
|
+
launcher: "claude-agent-acp",
|
|
231
|
+
effortOption: "effort"
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
id: "grok",
|
|
235
|
+
profile: "grok-build",
|
|
236
|
+
launcher: "grok",
|
|
237
|
+
effortOption: "reasoning_effort"
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
id: "cursor",
|
|
241
|
+
profile: "cursor",
|
|
242
|
+
launcher: "cursor-agent",
|
|
243
|
+
effortOption: null
|
|
244
|
+
}
|
|
245
|
+
];
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
// src/auth-check.ts
|
|
249
|
+
import { execFile } from "node:child_process";
|
|
250
|
+
import { stripVTControlCharacters } from "node:util";
|
|
251
|
+
function probe(target, command, args) {
|
|
252
|
+
return new Promise((resolve, reject) => {
|
|
253
|
+
const child = execFile(command, args, {
|
|
254
|
+
encoding: "utf8",
|
|
255
|
+
timeout: 8000,
|
|
256
|
+
killSignal: "SIGKILL",
|
|
257
|
+
maxBuffer: 128 * 1024,
|
|
258
|
+
windowsHide: true,
|
|
259
|
+
env: { ...process.env, NO_COLOR: "1" }
|
|
260
|
+
}, (error, stdout, stderr) => {
|
|
261
|
+
if (error && (error.killed || error.signal || error.code !== 1)) {
|
|
262
|
+
const reason = error.code === "ENOENT" ? "CLI not found" : "status command did not complete";
|
|
263
|
+
reject(new Error(`Could not check ${target} authentication: ${reason}.`));
|
|
264
|
+
} else {
|
|
265
|
+
resolve({ code: error ? 1 : 0, stdout, stderr });
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
child.stdin?.end();
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
function jsonObject(output) {
|
|
272
|
+
try {
|
|
273
|
+
const value = JSON.parse(output);
|
|
274
|
+
if (value !== null && typeof value === "object" && !Array.isArray(value))
|
|
275
|
+
return value;
|
|
276
|
+
} catch {}
|
|
277
|
+
}
|
|
278
|
+
function authenticated(target, code, stdout, stderr) {
|
|
279
|
+
if (target === "claude") {
|
|
280
|
+
const loggedIn = jsonObject(stdout)?.loggedIn;
|
|
281
|
+
if (loggedIn === false || code === 0 && loggedIn === true)
|
|
282
|
+
return loggedIn;
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
const lines = stripVTControlCharacters(`${stdout}
|
|
286
|
+
${stderr}`).split(/\r?\n/).map((line) => line.trim().replace(/^[✔✓✗✘×]\s*/u, ""));
|
|
287
|
+
if (target === "grok") {
|
|
288
|
+
const report = jsonObject(stdout);
|
|
289
|
+
if (code === 0 && report && !("error" in report) && typeof report.authenticated === "boolean")
|
|
290
|
+
return report.authenticated;
|
|
291
|
+
if (code === 1 && lines.some((line) => /^(?:error:\s*)?(?:unauthenticated|unauthorized|authentication required|not (?:logged in|authenticated))\b/i.test(line)))
|
|
292
|
+
return false;
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
if (lines.some((line) => /^(?:not (?:logged in|authenticated)|you are not logged in)\b/i.test(line)))
|
|
296
|
+
return false;
|
|
297
|
+
if (code !== 0)
|
|
298
|
+
return;
|
|
299
|
+
const signedIn = target === "codex" ? /^logged in using\s+/i : /^(?:logged in(?:\s+as\s+.+)?|authenticated(?:\s+as\s+.+)?)[.!]?$/i;
|
|
300
|
+
if (lines.some((line) => signedIn.test(line)))
|
|
301
|
+
return true;
|
|
302
|
+
}
|
|
303
|
+
async function checkAuth(target) {
|
|
304
|
+
const commands = {
|
|
305
|
+
codex: [process.env.CODEX_PATH ?? "codex", "login", "status"],
|
|
306
|
+
claude: ["claude", "auth", "status", "--json"],
|
|
307
|
+
grok: ["grok", "usage", "--json"],
|
|
308
|
+
cursor: ["cursor-agent", "status"]
|
|
108
309
|
};
|
|
310
|
+
const [command, ...args] = commands[target];
|
|
311
|
+
const { code, stdout, stderr } = await probe(target, command, args);
|
|
312
|
+
const result = authenticated(target, code, stdout, stderr);
|
|
313
|
+
if (result === undefined)
|
|
314
|
+
throw new Error(`Could not determine ${target} authentication from its status command.`);
|
|
315
|
+
return { target, ...await recordAuth(target, result) };
|
|
109
316
|
}
|
|
317
|
+
var init_auth_check = __esm(() => {
|
|
318
|
+
init_auth_state();
|
|
319
|
+
});
|
|
110
320
|
|
|
111
|
-
// src/
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
"
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
321
|
+
// src/adapter.ts
|
|
322
|
+
import { access, readFile as readFile3 } from "node:fs/promises";
|
|
323
|
+
import { dirname, join as join4 } from "node:path";
|
|
324
|
+
function isRecord(value) {
|
|
325
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
326
|
+
}
|
|
327
|
+
async function configuredArgv(cwd, profile) {
|
|
328
|
+
const path = join4(cwd, ".acpxrc.json");
|
|
329
|
+
let source;
|
|
330
|
+
try {
|
|
331
|
+
source = await readFile3(path, "utf8");
|
|
332
|
+
} catch (error) {
|
|
333
|
+
if (error.code === "ENOENT")
|
|
334
|
+
return;
|
|
335
|
+
throw error;
|
|
336
|
+
}
|
|
337
|
+
let config;
|
|
338
|
+
try {
|
|
339
|
+
config = JSON.parse(source);
|
|
340
|
+
} catch (cause) {
|
|
341
|
+
throw new Error(`Invalid JSON in ${path}`, { cause });
|
|
342
|
+
}
|
|
343
|
+
if (!isRecord(config))
|
|
344
|
+
throw new Error(`Expected an object in ${path}`);
|
|
345
|
+
const { agents } = config;
|
|
346
|
+
if (agents === undefined)
|
|
347
|
+
return;
|
|
348
|
+
if (!isRecord(agents))
|
|
349
|
+
throw new Error(`Expected an agents object in ${path}`);
|
|
350
|
+
if (!Object.hasOwn(agents, profile))
|
|
351
|
+
return;
|
|
352
|
+
const agent = agents[profile];
|
|
353
|
+
if (!isRecord(agent) || Object.keys(agent).some((key) => key !== "argv")) {
|
|
354
|
+
throw new Error(`The direct adapter accepts only agents.${profile}.argv in ${path}`);
|
|
355
|
+
}
|
|
356
|
+
const { argv } = agent;
|
|
357
|
+
if (!Array.isArray(argv) || !argv.every((arg) => typeof arg === "string" && !arg.includes("\x00")) || !argv[0]?.trim()) {
|
|
358
|
+
throw new Error(`agents.${profile}.argv in ${path} requires a command and string arguments`);
|
|
359
|
+
}
|
|
360
|
+
return argv;
|
|
361
|
+
}
|
|
362
|
+
function requiresWindowsShell(command) {
|
|
363
|
+
return process.platform === "win32" && /\.(bat|cmd)$/i.test(command);
|
|
364
|
+
}
|
|
365
|
+
async function packageLauncher(spec, launcher) {
|
|
366
|
+
const npx = executableOnPath("npx");
|
|
367
|
+
if (!npx)
|
|
368
|
+
throw new Error(`Install ${launcher} or put npx on PATH.`);
|
|
369
|
+
const args = ["--yes", "--package", spec, "--", launcher];
|
|
370
|
+
if (!requiresWindowsShell(npx))
|
|
371
|
+
return { command: npx, args };
|
|
372
|
+
const entry = join4(dirname(npx), "node_modules", "npm", "bin", "npx-cli.js");
|
|
373
|
+
try {
|
|
374
|
+
await access(entry);
|
|
375
|
+
} catch (cause) {
|
|
376
|
+
throw new Error(`Could not find npx-cli.js beside ${npx}. Install ${launcher} as a native executable.`, { cause });
|
|
377
|
+
}
|
|
378
|
+
return { command: process.execPath, args: [entry, ...args] };
|
|
379
|
+
}
|
|
380
|
+
async function resolveAdapter(target, cwd) {
|
|
381
|
+
const codexPath = target.id === "codex" && process.env.CODEX_PATH === undefined ? executableOnPath("codex") : undefined;
|
|
382
|
+
const env = codexPath ? { ...process.env, CODEX_PATH: codexPath } : process.env;
|
|
383
|
+
const override = await configuredArgv(cwd, target.profile);
|
|
384
|
+
if (override) {
|
|
385
|
+
const [command, ...args] = override;
|
|
386
|
+
if (requiresWindowsShell(command))
|
|
387
|
+
throw new Error("On Windows, set the adapter command to a native executable or an interpreter.");
|
|
388
|
+
return { command, args, env };
|
|
389
|
+
}
|
|
390
|
+
const command = executableOnPath(target.launcher);
|
|
391
|
+
if (target.id === "codex" || target.id === "claude") {
|
|
392
|
+
if (command && !requiresWindowsShell(command))
|
|
393
|
+
return { command, args: [], env };
|
|
394
|
+
return {
|
|
395
|
+
...await packageLauncher(packages[target.id], target.launcher),
|
|
396
|
+
env
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
if (!command)
|
|
400
|
+
throw new Error(`Install ${target.launcher} and put it on PATH.`);
|
|
401
|
+
if (requiresWindowsShell(command))
|
|
402
|
+
throw new Error(`Install ${target.launcher} as a native Windows executable.`);
|
|
403
|
+
const args = target.id === "grok" ? ["agent", "stdio"] : ["acp"];
|
|
404
|
+
return { command, args, env };
|
|
405
|
+
}
|
|
406
|
+
var packages;
|
|
407
|
+
var init_adapter = __esm(() => {
|
|
408
|
+
init_targets();
|
|
409
|
+
packages = {
|
|
410
|
+
codex: "@agentclientprotocol/codex-acp@1.13.1",
|
|
411
|
+
claude: "@agentclientprotocol/claude-agent-acp@0.95.0"
|
|
412
|
+
};
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
// src/direct-session.ts
|
|
416
|
+
async function setOption(agent, sessionId, option, flag, value) {
|
|
417
|
+
if (option?.type !== "select" || !option.options.some((entry) => ("group" in entry) ? entry.options.some((choice) => choice.value === value) : entry.value === value))
|
|
418
|
+
throw new Error(`The adapter does not advertise --${flag} ${value}.`);
|
|
419
|
+
const result = await agent.request("session/set_config_option", {
|
|
420
|
+
sessionId,
|
|
421
|
+
configId: option.id,
|
|
422
|
+
value
|
|
423
|
+
});
|
|
424
|
+
return result.configOptions;
|
|
425
|
+
}
|
|
426
|
+
async function configureSession(agent, session, target, { model, effort }) {
|
|
427
|
+
const { sessionId } = session;
|
|
428
|
+
let options = session.configOptions ?? [];
|
|
429
|
+
if (model) {
|
|
430
|
+
const selector = options.find((option) => option.id === "model") ?? options.find((option) => option.category === "model");
|
|
431
|
+
if (!selector && session.models?.availableModels?.some((choice) => choice.modelId === model)) {
|
|
432
|
+
await agent.request("session/set_model", { sessionId, modelId: model });
|
|
433
|
+
} else {
|
|
434
|
+
options = await setOption(agent, sessionId, selector, "model", model);
|
|
435
|
+
}
|
|
436
|
+
}
|
|
126
437
|
if (effort) {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
acpxArgs.push("--config-option", `${target.effortOption}=${effort}`);
|
|
438
|
+
const selector = options.find((option) => option.id === target.effortOption) ?? options.find((option) => option.category === "thought_level");
|
|
439
|
+
await setOption(agent, sessionId, selector, "effort", effort);
|
|
130
440
|
}
|
|
131
|
-
return acpxArgs;
|
|
132
441
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
442
|
+
|
|
443
|
+
// src/direct-acp.ts
|
|
444
|
+
import { execFile as execFile2, spawn } from "node:child_process";
|
|
445
|
+
import { constants } from "node:os";
|
|
446
|
+
import { resolve as resolve3 } from "node:path";
|
|
447
|
+
import { Writable } from "node:stream";
|
|
448
|
+
import { text } from "node:stream/consumers";
|
|
449
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
450
|
+
import {
|
|
451
|
+
client,
|
|
452
|
+
ndJsonStream,
|
|
453
|
+
PROTOCOL_VERSION,
|
|
454
|
+
RequestError
|
|
455
|
+
} from "@agentclientprotocol/sdk";
|
|
456
|
+
async function stopAdapter(child, exited) {
|
|
457
|
+
if (!child.pid)
|
|
458
|
+
return;
|
|
459
|
+
if (process.platform === "win32") {
|
|
460
|
+
if (child.exitCode === null && child.signalCode === null) {
|
|
461
|
+
await new Promise((done) => execFile2("taskkill.exe", ["/PID", String(child.pid), "/T", "/F"], {
|
|
462
|
+
timeout: 2000,
|
|
463
|
+
windowsHide: true
|
|
464
|
+
}, () => done()));
|
|
465
|
+
child.kill();
|
|
466
|
+
}
|
|
467
|
+
return;
|
|
137
468
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
469
|
+
const group = -child.pid;
|
|
470
|
+
const signalGroup = (signal) => {
|
|
471
|
+
try {
|
|
472
|
+
process.kill(group, signal);
|
|
473
|
+
return true;
|
|
474
|
+
} catch (error) {
|
|
475
|
+
if (error.code === "ESRCH")
|
|
476
|
+
return false;
|
|
477
|
+
throw error;
|
|
478
|
+
}
|
|
479
|
+
};
|
|
480
|
+
if (signalGroup("SIGTERM")) {
|
|
481
|
+
await Promise.race([
|
|
482
|
+
exited,
|
|
483
|
+
delay(shutdownGrace, undefined, { ref: false })
|
|
484
|
+
]);
|
|
485
|
+
signalGroup("SIGKILL");
|
|
141
486
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
487
|
+
}
|
|
488
|
+
function signalOutcome(signal) {
|
|
489
|
+
console.error(`taube: interrupted (${signal})`);
|
|
490
|
+
return { status: "interrupted", exitCode: 128 + constants.signals[signal] };
|
|
491
|
+
}
|
|
492
|
+
async function rememberAuth(target, authenticated) {
|
|
493
|
+
try {
|
|
494
|
+
await recordAuth(target.id, authenticated);
|
|
495
|
+
} catch (error) {
|
|
496
|
+
console.error("taube: could not update auth cache:", error instanceof Error ? error.message : String(error));
|
|
147
497
|
}
|
|
148
|
-
return 0;
|
|
149
498
|
}
|
|
150
|
-
async function
|
|
151
|
-
|
|
152
|
-
|
|
499
|
+
async function runDirectAcp(target, options) {
|
|
500
|
+
if (options.effort && !target.effortOption)
|
|
501
|
+
throw new Error("Cursor does not support a separate --effort setting. Use --model with an advertised Cursor model variant.");
|
|
502
|
+
const cwd = resolve3(options.cwd ?? ".");
|
|
153
503
|
const instruction = await text(process.stdin);
|
|
154
504
|
if (!instruction.trim())
|
|
155
505
|
throw new Error("Supply a non-empty instruction on stdin.");
|
|
156
|
-
const
|
|
157
|
-
const
|
|
158
|
-
const
|
|
506
|
+
const controller = new AbortController;
|
|
507
|
+
const signals = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
508
|
+
const onSignal = (signal) => controller.abort(signal);
|
|
509
|
+
for (const signal of signals)
|
|
510
|
+
process.on(signal, onSignal);
|
|
511
|
+
let record;
|
|
512
|
+
let outcome = { status: "failed", exitCode: 1 };
|
|
513
|
+
try {
|
|
514
|
+
record = await startSession(target.id, cwd, options.dispatcher ?? null);
|
|
515
|
+
outcome = await runAdapter(target, options, instruction, cwd, record, controller.signal);
|
|
516
|
+
} catch (error) {
|
|
517
|
+
if (!controller.signal.aborted)
|
|
518
|
+
throw error;
|
|
519
|
+
} finally {
|
|
520
|
+
if (controller.signal.aborted)
|
|
521
|
+
outcome = signalOutcome(controller.signal.reason);
|
|
522
|
+
try {
|
|
523
|
+
await record?.finish(outcome.status, outcome.exitCode);
|
|
524
|
+
} catch (error) {
|
|
525
|
+
if (outcome.exitCode === 0)
|
|
526
|
+
outcome = { status: "failed", exitCode: 1 };
|
|
527
|
+
console.error("taube: could not finish session record:", error instanceof Error ? error.message : String(error));
|
|
528
|
+
} finally {
|
|
529
|
+
for (const signal of signals)
|
|
530
|
+
process.off(signal, onSignal);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
if (outcome.status === "completed")
|
|
534
|
+
await rememberAuth(target, true);
|
|
535
|
+
return outcome.exitCode;
|
|
536
|
+
}
|
|
537
|
+
async function runAdapter(target, options, instruction, cwd, record, signal) {
|
|
538
|
+
signal.throwIfAborted();
|
|
539
|
+
const adapter = await resolveAdapter(target, cwd);
|
|
540
|
+
signal.throwIfAborted();
|
|
541
|
+
const child = spawn(adapter.command, adapter.args, {
|
|
159
542
|
cwd,
|
|
160
|
-
env:
|
|
543
|
+
env: {
|
|
544
|
+
...adapter.env,
|
|
545
|
+
LOSOFT_TABE_HOME: taubeHome(),
|
|
546
|
+
TAUBE_DISPATCHER: record.id
|
|
547
|
+
},
|
|
548
|
+
detached: process.platform !== "win32",
|
|
161
549
|
stdio: ["pipe", "pipe", "inherit"]
|
|
162
550
|
});
|
|
163
|
-
const
|
|
164
|
-
exited
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
551
|
+
const { promise: failed, reject: fail } = Promise.withResolvers();
|
|
552
|
+
const exited = new Promise((done) => {
|
|
553
|
+
child.once("exit", () => done());
|
|
554
|
+
child.once("error", (error) => {
|
|
555
|
+
fail(error);
|
|
556
|
+
done();
|
|
557
|
+
});
|
|
168
558
|
});
|
|
169
|
-
|
|
170
|
-
let
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
559
|
+
let sessionId;
|
|
560
|
+
let prompting = false;
|
|
561
|
+
let attaching;
|
|
562
|
+
let permissionDenied = false;
|
|
563
|
+
let graceTimer;
|
|
564
|
+
const failAfterGrace = (reason) => {
|
|
565
|
+
graceTimer ??= setTimeout(() => fail(reason), shutdownGrace);
|
|
174
566
|
};
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
567
|
+
let flushed = Promise.resolve();
|
|
568
|
+
const bytes = child.stdout[Symbol.asyncIterator]();
|
|
569
|
+
const input = new ReadableStream({
|
|
570
|
+
async pull(controller) {
|
|
571
|
+
await flushed;
|
|
572
|
+
const next = await bytes.next();
|
|
573
|
+
if (next.done)
|
|
574
|
+
controller.close();
|
|
575
|
+
else
|
|
576
|
+
controller.enqueue(next.value);
|
|
577
|
+
},
|
|
578
|
+
cancel() {
|
|
579
|
+
child.stdout.destroy();
|
|
580
|
+
}
|
|
581
|
+
});
|
|
582
|
+
const connection = client().onNotification("session/update", ({ params }) => {
|
|
583
|
+
const { update } = params;
|
|
584
|
+
if (prompting && params.sessionId === sessionId && update.sessionUpdate === "agent_message_chunk" && update.content.type === "text") {
|
|
585
|
+
const chunk = update.content.text;
|
|
586
|
+
flushed = new Promise((done) => {
|
|
587
|
+
process.stdout.write(chunk, (error) => {
|
|
588
|
+
if (error)
|
|
589
|
+
fail(error);
|
|
590
|
+
done();
|
|
591
|
+
});
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
}).onRequest("session/request_permission", () => {
|
|
595
|
+
permissionDenied = true;
|
|
596
|
+
failAfterGrace(new Error("The adapter requested permission during a non-interactive dispatch."));
|
|
597
|
+
return { outcome: { outcome: "cancelled" } };
|
|
598
|
+
}).connect(ndJsonStream(Writable.toWeb(child.stdin), input));
|
|
599
|
+
const { agent } = connection;
|
|
600
|
+
const cancel = () => {
|
|
601
|
+
if (sessionId)
|
|
602
|
+
agent.notify("session/cancel", { sessionId }).catch(fail);
|
|
603
|
+
failAfterGrace(new Error(`Interrupted (${signal.reason})`));
|
|
182
604
|
};
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
605
|
+
signal.addEventListener("abort", cancel, { once: true });
|
|
606
|
+
process.stdout.on("error", fail);
|
|
607
|
+
child.stdin.on("error", fail);
|
|
608
|
+
child.stdout.on("error", fail);
|
|
609
|
+
let finished = false;
|
|
610
|
+
const onExit = async () => {
|
|
611
|
+
let pending;
|
|
612
|
+
do {
|
|
613
|
+
pending = flushed;
|
|
614
|
+
await pending;
|
|
615
|
+
await delay(shutdownGrace, undefined, { ref: false });
|
|
616
|
+
} while (!finished && pending !== flushed);
|
|
617
|
+
if (!finished)
|
|
618
|
+
fail(new Error("The adapter exited before completing the ACP exchange."));
|
|
619
|
+
};
|
|
620
|
+
child.once("exit", onExit);
|
|
621
|
+
const run = async () => {
|
|
622
|
+
const init = await agent.request("initialize", {
|
|
623
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
624
|
+
clientCapabilities: {}
|
|
625
|
+
});
|
|
626
|
+
if (init?.protocolVersion !== PROTOCOL_VERSION)
|
|
627
|
+
throw new Error(`Unsupported ACP protocol version: ${init?.protocolVersion}.`);
|
|
628
|
+
const session = await agent.request("session/new", { cwd, mcpServers: [] });
|
|
629
|
+
if (typeof session?.sessionId !== "string" || !session.sessionId)
|
|
630
|
+
throw new Error("The adapter did not return an ACP session ID.");
|
|
631
|
+
if (finished)
|
|
632
|
+
return;
|
|
633
|
+
sessionId = session.sessionId;
|
|
634
|
+
attaching = record.attach(sessionId);
|
|
635
|
+
await attaching;
|
|
636
|
+
if (finished || signal.aborted)
|
|
637
|
+
return;
|
|
638
|
+
await configureSession(agent, session, target, options);
|
|
639
|
+
if (finished || signal.aborted || permissionDenied)
|
|
640
|
+
return;
|
|
641
|
+
prompting = true;
|
|
642
|
+
try {
|
|
643
|
+
const result = await agent.request("session/prompt", {
|
|
644
|
+
sessionId,
|
|
645
|
+
prompt: [{ type: "text", text: instruction }]
|
|
646
|
+
});
|
|
647
|
+
return result?.stopReason;
|
|
648
|
+
} finally {
|
|
649
|
+
prompting = false;
|
|
650
|
+
await flushed;
|
|
187
651
|
}
|
|
188
652
|
};
|
|
653
|
+
let stopReason;
|
|
654
|
+
let failure;
|
|
655
|
+
let exitSignal = null;
|
|
656
|
+
let status = null;
|
|
189
657
|
try {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
throw outputError;
|
|
194
|
-
return exitCode(status, interrupted ?? exitSignal, result);
|
|
658
|
+
stopReason = await Promise.race([run(), failed]);
|
|
659
|
+
} catch (error) {
|
|
660
|
+
failure = error;
|
|
195
661
|
} finally {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
662
|
+
finished = true;
|
|
663
|
+
child.off("exit", onExit);
|
|
664
|
+
clearTimeout(graceTimer);
|
|
665
|
+
connection.close();
|
|
666
|
+
if (process.platform !== "win32") {
|
|
667
|
+
child.stdin.end();
|
|
668
|
+
await Promise.race([
|
|
669
|
+
exited,
|
|
670
|
+
delay(shutdownGrace, undefined, { ref: false })
|
|
671
|
+
]);
|
|
199
672
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
673
|
+
exitSignal = child.signalCode;
|
|
674
|
+
status = child.exitCode;
|
|
675
|
+
try {
|
|
676
|
+
await stopAdapter(child, exited);
|
|
677
|
+
} finally {
|
|
678
|
+
child.stdin.destroy();
|
|
679
|
+
child.stdout.destroy();
|
|
680
|
+
clearTimeout(graceTimer);
|
|
681
|
+
if (signal.aborted && process.stdout.writableLength)
|
|
682
|
+
process.stdout.destroy();
|
|
683
|
+
process.stdout.off("error", fail);
|
|
684
|
+
signal.removeEventListener("abort", cancel);
|
|
685
|
+
await attaching;
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
signal.throwIfAborted();
|
|
689
|
+
if (exitSignal)
|
|
690
|
+
return signalOutcome(exitSignal);
|
|
691
|
+
if (permissionDenied)
|
|
692
|
+
throw new Error("The adapter requested permission during a non-interactive dispatch.");
|
|
693
|
+
if (failure instanceof RequestError && failure.code === -32000) {
|
|
694
|
+
await rememberAuth(target, false);
|
|
695
|
+
throw new Error(`Authentication required. Sign in to ${target.id} before dispatching.`);
|
|
203
696
|
}
|
|
697
|
+
if (status !== null && status > 0) {
|
|
698
|
+
console.error(`taube: adapter exited with status ${status}`);
|
|
699
|
+
return { status: "failed", exitCode: status };
|
|
700
|
+
}
|
|
701
|
+
if (failure)
|
|
702
|
+
throw failure;
|
|
703
|
+
if (!stopReason)
|
|
704
|
+
throw new Error("The adapter returned an incomplete prompt response.");
|
|
705
|
+
if (stopReason !== "end_turn") {
|
|
706
|
+
console.error(`taube: target stopped with ${stopReason}`);
|
|
707
|
+
return stopReason === "cancelled" ? { status: "interrupted", exitCode: 130 } : { status: "failed", exitCode: 1 };
|
|
708
|
+
}
|
|
709
|
+
return { status: "completed", exitCode: 0 };
|
|
204
710
|
}
|
|
711
|
+
var shutdownGrace = 300;
|
|
712
|
+
var init_direct_acp = __esm(() => {
|
|
713
|
+
init_adapter();
|
|
714
|
+
init_auth_state();
|
|
715
|
+
init_home();
|
|
716
|
+
init_sessions();
|
|
717
|
+
});
|
|
205
718
|
|
|
206
719
|
// src/cli.ts
|
|
720
|
+
import { parseArgs } from "node:util";
|
|
721
|
+
// package.json
|
|
722
|
+
var package_default = {
|
|
723
|
+
name: "@losoft/taube",
|
|
724
|
+
version: "0.1.7",
|
|
725
|
+
description: "Delegate a coding task to Codex, Claude Code, Grok Build, or Cursor over the Agent Client Protocol.",
|
|
726
|
+
type: "module",
|
|
727
|
+
license: "MIT",
|
|
728
|
+
repository: {
|
|
729
|
+
type: "git",
|
|
730
|
+
url: "git+https://github.com/lorenzh/taube.git"
|
|
731
|
+
},
|
|
732
|
+
publishConfig: {
|
|
733
|
+
access: "public"
|
|
734
|
+
},
|
|
735
|
+
bin: {
|
|
736
|
+
taube: "dist/cli.js"
|
|
737
|
+
},
|
|
738
|
+
files: [
|
|
739
|
+
"dist",
|
|
740
|
+
"plugins",
|
|
741
|
+
".agents/plugins",
|
|
742
|
+
".claude-plugin",
|
|
743
|
+
".cursor-plugin"
|
|
744
|
+
],
|
|
745
|
+
packageManager: "bun@1.4.2",
|
|
746
|
+
engines: {
|
|
747
|
+
node: ">=22.13.0"
|
|
748
|
+
},
|
|
749
|
+
scripts: {
|
|
750
|
+
check: "biome check . && tsc --noEmit",
|
|
751
|
+
test: "bun test",
|
|
752
|
+
build: "bun build src/cli.ts --target=node --packages=external --outdir=dist",
|
|
753
|
+
prepare: "bun run build"
|
|
754
|
+
},
|
|
755
|
+
dependencies: {
|
|
756
|
+
"@agentclientprotocol/sdk": "1.9.0"
|
|
757
|
+
},
|
|
758
|
+
devDependencies: {
|
|
759
|
+
"@biomejs/biome": "2.6.9",
|
|
760
|
+
"@types/bun": "1.4.2",
|
|
761
|
+
typescript: "6.0.3"
|
|
762
|
+
}
|
|
763
|
+
};
|
|
764
|
+
|
|
765
|
+
// src/cli.ts
|
|
766
|
+
init_sessions();
|
|
767
|
+
init_targets();
|
|
207
768
|
var targetIds = targets.map(({ id }) => id);
|
|
208
769
|
var help = `Usage:
|
|
770
|
+
taube --version
|
|
209
771
|
taube surfaces
|
|
210
|
-
taube
|
|
772
|
+
taube auth check <${targetIds.join("|")}>
|
|
773
|
+
taube sessions [list] [--dispatcher ID | --mine | --all] [--status STATUS]
|
|
774
|
+
taube dispatch <${targetIds.join("|")}> [--model ID] [--effort LEVEL] [--cwd DIR] [--dispatcher ID]
|
|
775
|
+
|
|
776
|
+
surfaces lists the target launchers and their last known authentication status.
|
|
777
|
+
auth check queries one target CLI and records its login status.
|
|
778
|
+
sessions prints JSON listing dispatches started by the current dispatcher.
|
|
779
|
+
dispatch reads one instruction from stdin and starts a fresh ACP session.
|
|
780
|
+
Assistant text streams to stdout. Diagnostics go to stderr. Partial turns and
|
|
781
|
+
permission requests exit nonzero.
|
|
211
782
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
783
|
+
--cwd DIR Run the adapter in DIR (default: current directory).
|
|
784
|
+
--model ID Select a model advertised by the adapter.
|
|
785
|
+
--effort LEVEL Select an advertised reasoning effort for Codex, Claude or Grok.
|
|
786
|
+
--dispatcher ID Identify the caller of a dispatch, or filter sessions by caller.
|
|
787
|
+
--mine List sessions started by the current dispatcher (default).
|
|
788
|
+
--all List sessions from all dispatchers.
|
|
789
|
+
--status STATUS Filter by running, finished, completed, failed or interrupted.
|
|
790
|
+
-V, --version Print the installed Taube version.
|
|
791
|
+
-h, --help Show this help.
|
|
792
|
+
|
|
793
|
+
Omit --model and --effort to use the target defaults. For Cursor, use --model
|
|
794
|
+
to select a model variant with the desired effort.`;
|
|
795
|
+
function currentDispatcher(explicit) {
|
|
796
|
+
if (explicit !== undefined) {
|
|
797
|
+
if (!explicit.trim())
|
|
798
|
+
throw new Error("--dispatcher needs a non-empty value");
|
|
799
|
+
return explicit;
|
|
800
|
+
}
|
|
801
|
+
if (process.env.TAUBE_DISPATCHER?.trim())
|
|
802
|
+
return process.env.TAUBE_DISPATCHER;
|
|
803
|
+
const codex = process.env.CODEX_THREAD_ID?.trim();
|
|
804
|
+
const claude = process.env.CLAUDE_CODE_SESSION_ID?.trim();
|
|
805
|
+
if (codex && !claude)
|
|
806
|
+
return `codex:${codex}`;
|
|
807
|
+
if (claude && !codex)
|
|
808
|
+
return `claude:${claude}`;
|
|
809
|
+
return null;
|
|
810
|
+
}
|
|
811
|
+
async function showSessions(args) {
|
|
812
|
+
const { values } = parseArgs({
|
|
813
|
+
args: args[0] === "list" ? args.slice(1) : args,
|
|
814
|
+
options: {
|
|
815
|
+
dispatcher: { type: "string" },
|
|
816
|
+
mine: { type: "boolean" },
|
|
817
|
+
all: { type: "boolean" },
|
|
818
|
+
status: { type: "string" },
|
|
819
|
+
help: { type: "boolean", short: "h" }
|
|
820
|
+
}
|
|
821
|
+
});
|
|
822
|
+
if (values.help) {
|
|
823
|
+
console.log(help);
|
|
824
|
+
return 0;
|
|
825
|
+
}
|
|
826
|
+
if ([values.mine, values.all, values.dispatcher !== undefined].filter(Boolean).length > 1)
|
|
827
|
+
throw new Error("Choose one of --mine, --dispatcher ID or --all.");
|
|
828
|
+
const dispatcher = values.all ? null : currentDispatcher(values.dispatcher);
|
|
829
|
+
if (!values.all && dispatcher === null)
|
|
830
|
+
throw new Error("Could not identify the current dispatcher. Use --dispatcher ID to select a dispatcher or --all to list every session.");
|
|
831
|
+
const statuses = [
|
|
832
|
+
"running",
|
|
833
|
+
"finished",
|
|
834
|
+
"completed",
|
|
835
|
+
"failed",
|
|
836
|
+
"interrupted"
|
|
837
|
+
];
|
|
838
|
+
const status = values.status;
|
|
839
|
+
if (status !== undefined && !statuses.includes(status))
|
|
840
|
+
throw new Error(`Choose a --status: ${statuses.join(", ")}.`);
|
|
841
|
+
const sessions = (await listSessions()).filter((session) => (dispatcher === null || session.dispatcher === dispatcher) && (!status || (status === "finished" ? session.status !== "running" : session.status === status)));
|
|
842
|
+
console.log(JSON.stringify({ sessions }, null, 2));
|
|
843
|
+
return 0;
|
|
844
|
+
}
|
|
218
845
|
async function main([command, targetId, ...args]) {
|
|
219
|
-
if (
|
|
846
|
+
if (command === "--version" || command === "-V") {
|
|
847
|
+
if (targetId !== undefined)
|
|
848
|
+
throw new Error("Usage: taube --version");
|
|
849
|
+
console.log(package_default.version);
|
|
850
|
+
return 0;
|
|
851
|
+
}
|
|
852
|
+
if (!command || command === "--help" || command === "-h" || targetId === "--help" || targetId === "-h") {
|
|
220
853
|
console.log(help);
|
|
221
854
|
return 0;
|
|
222
855
|
}
|
|
223
856
|
if (command === "surfaces" && !targetId) {
|
|
224
|
-
console.log(JSON.stringify(surfaces(), null, 2));
|
|
857
|
+
console.log(JSON.stringify(await surfaces(), null, 2));
|
|
225
858
|
return 0;
|
|
226
859
|
}
|
|
860
|
+
if (command === "auth") {
|
|
861
|
+
const target = targets.find(({ id }) => id === args[0]);
|
|
862
|
+
if (targetId !== "check" || args.length !== 1 || !target)
|
|
863
|
+
throw new Error(`Usage: taube auth check <${targetIds.join("|")}>.`);
|
|
864
|
+
await Promise.resolve().then(() => init_auth_check());
|
|
865
|
+
const result = await checkAuth(target.id);
|
|
866
|
+
console.log(JSON.stringify(result, null, 2));
|
|
867
|
+
return result.authenticated ? 0 : 1;
|
|
868
|
+
}
|
|
869
|
+
if (command === "sessions")
|
|
870
|
+
return showSessions(targetId === undefined ? [] : [targetId, ...args]);
|
|
227
871
|
if (command !== "dispatch")
|
|
228
|
-
throw new Error("Expected surfaces or dispatch. See taube --help.");
|
|
872
|
+
throw new Error("Expected surfaces, auth, sessions or dispatch. See taube --help.");
|
|
229
873
|
const target = targets.find(({ id }) => id === targetId);
|
|
230
874
|
if (!target)
|
|
231
875
|
throw new Error(`Choose one target: ${targetIds.join(", ")}.`);
|
|
@@ -233,6 +877,7 @@ async function main([command, targetId, ...args]) {
|
|
|
233
877
|
args,
|
|
234
878
|
options: {
|
|
235
879
|
cwd: { type: "string" },
|
|
880
|
+
dispatcher: { type: "string" },
|
|
236
881
|
model: { type: "string" },
|
|
237
882
|
effort: { type: "string" },
|
|
238
883
|
help: { type: "boolean", short: "h" }
|
|
@@ -246,7 +891,11 @@ async function main([command, targetId, ...args]) {
|
|
|
246
891
|
if (typeof value === "string" && !value.trim())
|
|
247
892
|
throw new Error(`--${name} needs a non-empty value`);
|
|
248
893
|
}
|
|
249
|
-
|
|
894
|
+
await Promise.resolve().then(() => init_direct_acp());
|
|
895
|
+
return runDirectAcp(target, {
|
|
896
|
+
...values,
|
|
897
|
+
dispatcher: currentDispatcher(values.dispatcher)
|
|
898
|
+
});
|
|
250
899
|
}
|
|
251
900
|
try {
|
|
252
901
|
process.exitCode = await main(process.argv.slice(2));
|