@sjawhar/claude-envoy 4.0.1 → 4.1.0
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/.claude-plugin/plugin.json +1 -1
- package/.omp-plugin/plugin.json +1 -1
- package/README.md +81 -0
- package/bin/envoy-channel.ts +7 -2
- package/dist/codex-hook.js +29834 -0
- package/dist/codex-tool-hook.js +136 -0
- package/dist/dispatch.js +121 -24
- package/dist/envoy-channel.js +16570 -14818
- package/dist/session-hook.js +42 -15
- package/hooks/codex-hook.ts +168 -0
- package/hooks/codex-tool-hook.ts +51 -0
- package/hooks/hook-arguments.ts +23 -0
- package/hooks/session-hook.ts +14 -6
- package/package.json +1 -1
- package/scripts/build.ts +116 -12
- package/src/codex/codex-agent-stream.ts +240 -0
- package/src/codex/codex-cli.ts +280 -0
- package/src/codex/codex-delivery.ts +194 -0
- package/src/codex/codex-inbox.ts +197 -0
- package/src/codex/codex-owner.ts +273 -0
- package/src/codex/codex-server.ts +594 -0
- package/src/codex/codex-session-record.ts +308 -0
- package/src/codex/codex-transcript.ts +373 -0
- package/src/codex/codex-user-turns.ts +107 -0
- package/src/envoy-channel-server.ts +7 -1
- package/src/session-identity.ts +1 -1
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/codex/codex-inbox.ts
|
|
3
|
+
import { randomBytes } from "crypto";
|
|
4
|
+
import { mkdir, readdir, readFile, rename, rm, writeFile } from "fs/promises";
|
|
5
|
+
import { join } from "path";
|
|
6
|
+
var TAKEN_DIRECTORY = { hook: "taken", server: "queued" };
|
|
7
|
+
function codexInboxDirectory(stateDirectory, sessionId) {
|
|
8
|
+
return join(stateDirectory, "codex-inbox", encodeURIComponent(sessionId));
|
|
9
|
+
}
|
|
10
|
+
var lastOrder = 0;
|
|
11
|
+
function itemName() {
|
|
12
|
+
const order = Math.max(Date.now(), lastOrder + 1);
|
|
13
|
+
lastOrder = order;
|
|
14
|
+
return `${String(order).padStart(15, "0")}-${randomBytes(4).toString("hex")}.json`;
|
|
15
|
+
}
|
|
16
|
+
async function putInbox(directory, item) {
|
|
17
|
+
const waiting = join(directory, "waiting");
|
|
18
|
+
await mkdir(waiting, { recursive: true, mode: 448 });
|
|
19
|
+
const name = itemName();
|
|
20
|
+
const temporary = join(directory, `.${name}.tmp`);
|
|
21
|
+
await writeFile(temporary, JSON.stringify(item), { mode: 384 });
|
|
22
|
+
await rename(temporary, join(waiting, name));
|
|
23
|
+
return name;
|
|
24
|
+
}
|
|
25
|
+
async function takenBy(directory, name) {
|
|
26
|
+
for (const taker of ["hook", "server"]) {
|
|
27
|
+
try {
|
|
28
|
+
await readFile(join(directory, TAKEN_DIRECTORY[taker], name));
|
|
29
|
+
return taker;
|
|
30
|
+
} catch {}
|
|
31
|
+
}
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
async function withdrawWaiting(directory, name) {
|
|
35
|
+
try {
|
|
36
|
+
await rm(join(directory, "waiting", name));
|
|
37
|
+
return true;
|
|
38
|
+
} catch {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async function discardWaiting(directory, keep = () => false) {
|
|
43
|
+
const waiting = join(directory, "waiting");
|
|
44
|
+
let names;
|
|
45
|
+
try {
|
|
46
|
+
names = await readdir(waiting);
|
|
47
|
+
} catch {
|
|
48
|
+
return 0;
|
|
49
|
+
}
|
|
50
|
+
let removed = 0;
|
|
51
|
+
for (const name of names) {
|
|
52
|
+
if (!name.endsWith(".json") || keep(name))
|
|
53
|
+
continue;
|
|
54
|
+
try {
|
|
55
|
+
await rm(join(waiting, name));
|
|
56
|
+
removed++;
|
|
57
|
+
} catch {}
|
|
58
|
+
}
|
|
59
|
+
return removed;
|
|
60
|
+
}
|
|
61
|
+
var HOOK_CONTEXT_MAX_BYTES = 8000;
|
|
62
|
+
async function takeInbox(directory, taker, maxContextBytes) {
|
|
63
|
+
const waiting = join(directory, "waiting");
|
|
64
|
+
let names;
|
|
65
|
+
try {
|
|
66
|
+
names = (await readdir(waiting)).filter((name) => name.endsWith(".json")).sort();
|
|
67
|
+
} catch {
|
|
68
|
+
return [];
|
|
69
|
+
}
|
|
70
|
+
if (names.length === 0)
|
|
71
|
+
return [];
|
|
72
|
+
const destination = join(directory, TAKEN_DIRECTORY[taker]);
|
|
73
|
+
await mkdir(destination, { recursive: true, mode: 448 });
|
|
74
|
+
const taken = [];
|
|
75
|
+
for (const name of names) {
|
|
76
|
+
if (maxContextBytes !== undefined) {
|
|
77
|
+
let waitingItem;
|
|
78
|
+
try {
|
|
79
|
+
waitingItem = JSON.parse(await readFile(join(waiting, name), "utf8"));
|
|
80
|
+
} catch {
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
if (typeof waitingItem?.content !== "string")
|
|
84
|
+
continue;
|
|
85
|
+
const items = [...taken.map(({ item }) => item), waitingItem];
|
|
86
|
+
if (Buffer.byteLength(inboxContext(items)) > maxContextBytes)
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
try {
|
|
90
|
+
await rename(join(waiting, name), join(destination, name));
|
|
91
|
+
} catch {
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
try {
|
|
95
|
+
const parsed = JSON.parse(await readFile(join(destination, name), "utf8"));
|
|
96
|
+
if (typeof parsed === "object" && parsed !== null && typeof parsed.content === "string") {
|
|
97
|
+
taken.push({ item: parsed, name });
|
|
98
|
+
}
|
|
99
|
+
} catch {}
|
|
100
|
+
}
|
|
101
|
+
return taken;
|
|
102
|
+
}
|
|
103
|
+
function inboxContext(items) {
|
|
104
|
+
return [
|
|
105
|
+
"Messages delivered to this session while it worked (Envoy, through the Envoy plugin):",
|
|
106
|
+
...items.map((item) => item.dispatchMessageId === undefined ? item.content : `A person wrote to you from Dispatch (message ${item.dispatchMessageId}):
|
|
107
|
+
${item.content}`)
|
|
108
|
+
].join(`
|
|
109
|
+
|
|
110
|
+
`);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// hooks/codex-tool-hook.ts
|
|
114
|
+
async function postToolUse(text) {
|
|
115
|
+
const input = JSON.parse(text);
|
|
116
|
+
const sessionId = typeof input === "object" && input !== null ? input.session_id : undefined;
|
|
117
|
+
const pluginData = process.env["PLUGIN_DATA"] || process.env["CLAUDE_PLUGIN_DATA"];
|
|
118
|
+
if (typeof sessionId !== "string" || sessionId === "" || !pluginData)
|
|
119
|
+
return;
|
|
120
|
+
const taken = await takeInbox(codexInboxDirectory(pluginData, sessionId), "hook", HOOK_CONTEXT_MAX_BYTES);
|
|
121
|
+
if (taken.length === 0)
|
|
122
|
+
return;
|
|
123
|
+
process.stdout.write(JSON.stringify({
|
|
124
|
+
hookSpecificOutput: {
|
|
125
|
+
additionalContext: inboxContext(taken.map(({ item }) => item)),
|
|
126
|
+
hookEventName: "PostToolUse"
|
|
127
|
+
}
|
|
128
|
+
}));
|
|
129
|
+
}
|
|
130
|
+
try {
|
|
131
|
+
await postToolUse(await Bun.stdin.text());
|
|
132
|
+
} catch (error) {
|
|
133
|
+
process.stderr.write(`envoy: codex-tool-hook: ${error instanceof Error ? error.message : String(error)}
|
|
134
|
+
`);
|
|
135
|
+
}
|
|
136
|
+
process.exit(0);
|
package/dist/dispatch.js
CHANGED
|
@@ -980,10 +980,10 @@ __export(exports_coerce, {
|
|
|
980
980
|
});
|
|
981
981
|
|
|
982
982
|
// ../envoy-client/bin/dispatch.ts
|
|
983
|
-
import { readFileSync as
|
|
983
|
+
import { readFileSync as readFileSync8 } from "fs";
|
|
984
984
|
|
|
985
985
|
// ../envoy-client/src/dispatch-cli.ts
|
|
986
|
-
import { closeSync as closeSync4, constants as constants2, fstatSync as fstatSync2, openSync as openSync4, readFileSync as
|
|
986
|
+
import { closeSync as closeSync4, constants as constants2, fstatSync as fstatSync2, openSync as openSync4, readFileSync as readFileSync7 } from "fs";
|
|
987
987
|
|
|
988
988
|
// ../envoy-client/src/askgate-marker.ts
|
|
989
989
|
import { createHash, randomBytes } from "crypto";
|
|
@@ -15689,7 +15689,7 @@ var dispatchToolSpecs = [
|
|
|
15689
15689
|
verdict: "pass",
|
|
15690
15690
|
commit: "1111111111111111111111111111111111111111"
|
|
15691
15691
|
},
|
|
15692
|
-
description: "Record one result of one check of an issue's Verification document, or retract a result " + "recorded before. A record prints the pull-request body line it implies. Write that line " + "into the pull-request body unchanged: it is the one grammar every writer uses, and it " + "carries no link to Dispatch. " + "Name the check by its block id. Where two Verification documents in reach hold that id, " + "name it by its canonical reference (dispatch://KEY/artifact/verification-md#b-<id>). " + "409 CHECK_AMBIGUOUS names both documents. An id no Verification document of the issue " + "or of an issue above it holds is 400 UNKNOWN_CHECK. " + `${CHECK_PROVED_BY_CI}. ` + "Dispatch reads its result from that run, so a record for it is 409 " + "CHECK_PROVED_BY_CI from every role, which names the check and the run. " + "A pass that counts a failed, a skipped or an excluded case contradicts itself, and is " + "400 RESULT_CONTRADICTS. " + "Dispatch asks GitHub whether the repository of the check's issue holds the commit. A " + "commit that repository does not hold is 400 RESULT_COMMIT_UNKNOWN, which names the " + "commit and that owner/repo. Record the result after the commit is pushed. A repository " + "Dispatch cannot read records the result as before. " + "The result is recorded against the check's own issue, so a child's run of a parent's " + "check appears under that check. A closed issue takes a result only for a check whose " + "when is after_merge or default_branch, the production check after the merge. It refuses " + "every other record with 409 ISSUE_CLOSED, as it refuses every other write. " + RESULT_RETRACT_RULE + " The retraction keeps both records: the result stays readable, and it proves nothing " + "from then on. Record a new result where the check still needs one. A retraction is " + "taken on a closed issue and for a check of any when. Three callers may retract: the " + "session that recorded the result, a session that holds the Dispatch claim of the issue " + "the result was recorded on, and a caller whose credential carries a person. Every other " + "caller is 403 RETRACTION_FORBIDDEN. A result retracted already is 409 RESULT_RETRACTED. " + ISSUE_REFERENCE,
|
|
15692
|
+
description: "Record one result of one check of an issue's Verification document, or retract a result " + "recorded before. A record prints the pull-request body line it implies. Write that line " + "into the pull-request body unchanged: it is the one grammar every writer uses, and it " + "carries no link to Dispatch. " + "Name the check by its block id. Where two Verification documents in reach hold that id, " + "name it by its canonical reference (dispatch://KEY/artifact/verification-md#b-<id>). " + "409 CHECK_AMBIGUOUS names both documents. An id no Verification document of the issue " + "or of an issue above it holds is 400 UNKNOWN_CHECK. " + `${CHECK_PROVED_BY_CI}. ` + "Dispatch reads its result from that run, so a record for it is 409 " + "CHECK_PROVED_BY_CI from every role, which names the check and the run. " + "A pass that counts a failed, a skipped or an excluded case contradicts itself, and is " + "400 RESULT_CONTRADICTS. " + "Dispatch asks GitHub whether the repository of the check's issue holds the commit. A " + "commit that repository does not hold is 400 RESULT_COMMIT_UNKNOWN, which names the " + "commit and that owner/repo. Record the result after the commit is pushed. A repository " + "Dispatch cannot read records the result as before. " + "The result is recorded against the check's own issue, so a child's run of a parent's " + "check appears under that check. A closed issue takes a result only for a check whose " + "when is after_merge or default_branch, the production check after the merge. It refuses " + "every other record with 409 ISSUE_CLOSED, as it refuses every other write. " + "A check a document version rewords while the result is being written is 409 " + "CHECK_CONTENDED, with nothing recorded: run the same command again. " + RESULT_RETRACT_RULE + " The retraction keeps both records: the result stays readable, and it proves nothing " + "from then on. Record a new result where the check still needs one. A retraction is " + "taken on a closed issue and for a check of any when. Three callers may retract: the " + "session that recorded the result, a session that holds the Dispatch claim of the issue " + "the result was recorded on, and a caller whose credential carries a person. Every other " + "caller is 403 RETRACTION_FORBIDDEN. A result retracted already is 409 RESULT_RETRACTED. " + ISSUE_REFERENCE,
|
|
15693
15693
|
arguments: (z) => ({
|
|
15694
15694
|
issue: z.string().describe(ISSUE_REFERENCE).optional(),
|
|
15695
15695
|
check: z.string().describe("The check block's id, or its canonical reference dispatch://KEY/artifact/verification-md#b-<id> when the id is not unique among the issue's Verification document and those of the issues above it.").optional(),
|
|
@@ -25201,14 +25201,22 @@ The result stays readable, and it proves nothing from now on. Record a new resul
|
|
|
25201
25201
|
...defined("excluded", optionalNumber(args, "excluded")),
|
|
25202
25202
|
...defined("screenshots", optionalStringArray(args, "screenshots"))
|
|
25203
25203
|
};
|
|
25204
|
-
|
|
25205
|
-
|
|
25206
|
-
|
|
25207
|
-
|
|
25208
|
-
|
|
25209
|
-
|
|
25210
|
-
|
|
25211
|
-
|
|
25204
|
+
let recorded;
|
|
25205
|
+
try {
|
|
25206
|
+
recorded = await client.recordResult(issue, {
|
|
25207
|
+
actor,
|
|
25208
|
+
check: stringArg(args, "check"),
|
|
25209
|
+
role: stringArg(args, "role"),
|
|
25210
|
+
verdict: stringArg(args, "verdict"),
|
|
25211
|
+
commit: stringArg(args, "commit"),
|
|
25212
|
+
...optional
|
|
25213
|
+
});
|
|
25214
|
+
} catch (error) {
|
|
25215
|
+
if (dispatchAnswered(error, 409) && error.code === "CHECK_CONTENDED") {
|
|
25216
|
+
throw refusalWithCode(error, "the check moved twice while this result was being written, and nothing was recorded: run the same dispatch result command again");
|
|
25217
|
+
}
|
|
25218
|
+
throw error;
|
|
25219
|
+
}
|
|
25212
25220
|
return {
|
|
25213
25221
|
text: `Recorded ${recorded.result.verdict} for check ${recorded.result.check_block_id} of ${recorded.result.check_issue_key} at ${recorded.result.commit_sha}, as ${recorded.result.role}.
|
|
25214
25222
|
|
|
@@ -26362,6 +26370,74 @@ function pruneSessions(root, now) {
|
|
|
26362
26370
|
writeFileSync3(stamp, "", { mode: PRIVATE_FILE2 });
|
|
26363
26371
|
}
|
|
26364
26372
|
|
|
26373
|
+
// ../envoy-client/src/process-ancestry.ts
|
|
26374
|
+
import { execFileSync } from "child_process";
|
|
26375
|
+
import { readFileSync as readFileSync4 } from "fs";
|
|
26376
|
+
var MAX_ANCESTORS = 64;
|
|
26377
|
+
var PARENT_LOOKUP_MS = 1000;
|
|
26378
|
+
function procParentPid(pid) {
|
|
26379
|
+
try {
|
|
26380
|
+
const stat = readFileSync4(`/proc/${pid}/stat`, "utf8");
|
|
26381
|
+
const parent = Number(stat.slice(stat.lastIndexOf(")") + 2).split(" ")[1]);
|
|
26382
|
+
return Number.isInteger(parent) ? parent : undefined;
|
|
26383
|
+
} catch {
|
|
26384
|
+
return;
|
|
26385
|
+
}
|
|
26386
|
+
}
|
|
26387
|
+
function processTable() {
|
|
26388
|
+
const table = new Map;
|
|
26389
|
+
try {
|
|
26390
|
+
const listing = execFileSync("ps", ["-Ao", "pid=,ppid="], {
|
|
26391
|
+
encoding: "utf8",
|
|
26392
|
+
killSignal: "SIGKILL",
|
|
26393
|
+
timeout: PARENT_LOOKUP_MS
|
|
26394
|
+
});
|
|
26395
|
+
for (const line of listing.split(`
|
|
26396
|
+
`)) {
|
|
26397
|
+
const [, pid = "", parent = ""] = line.match(/^\s*(\d+)\s+(\d+)\s*$/) ?? [];
|
|
26398
|
+
if (pid !== "")
|
|
26399
|
+
table.set(Number(pid), Number(parent));
|
|
26400
|
+
}
|
|
26401
|
+
} catch {}
|
|
26402
|
+
return table;
|
|
26403
|
+
}
|
|
26404
|
+
function isAncestor(candidate, pid = process.pid) {
|
|
26405
|
+
let table;
|
|
26406
|
+
const parentPid = (child) => {
|
|
26407
|
+
if (process.platform === "linux")
|
|
26408
|
+
return procParentPid(child);
|
|
26409
|
+
table ??= processTable();
|
|
26410
|
+
return table.get(child);
|
|
26411
|
+
};
|
|
26412
|
+
let current = pid;
|
|
26413
|
+
for (let step = 0;current !== undefined && current > 1 && step < MAX_ANCESTORS; step++) {
|
|
26414
|
+
if (String(current) === candidate)
|
|
26415
|
+
return true;
|
|
26416
|
+
current = parentPid(current);
|
|
26417
|
+
}
|
|
26418
|
+
return false;
|
|
26419
|
+
}
|
|
26420
|
+
function procCommand(pid) {
|
|
26421
|
+
try {
|
|
26422
|
+
return readFileSync4(`/proc/${pid}/comm`, "utf8").trim();
|
|
26423
|
+
} catch {
|
|
26424
|
+
return;
|
|
26425
|
+
}
|
|
26426
|
+
}
|
|
26427
|
+
var PROC_READER = { command: procCommand, parent: procParentPid };
|
|
26428
|
+
function nearestAncestorNamed(names, pid = process.pid, reader = PROC_READER) {
|
|
26429
|
+
if (reader === PROC_READER && process.platform !== "linux")
|
|
26430
|
+
return;
|
|
26431
|
+
let current = pid;
|
|
26432
|
+
for (let step = 0;current !== undefined && current > 1 && step < MAX_ANCESTORS; step++) {
|
|
26433
|
+
const command = reader.command(current)?.replace(/\.exe$/, "");
|
|
26434
|
+
if (command !== undefined && names.includes(command))
|
|
26435
|
+
return command;
|
|
26436
|
+
current = reader.parent(current);
|
|
26437
|
+
}
|
|
26438
|
+
return;
|
|
26439
|
+
}
|
|
26440
|
+
|
|
26365
26441
|
// ../envoy-client/src/envoy-config.ts
|
|
26366
26442
|
import {
|
|
26367
26443
|
chmodSync,
|
|
@@ -26370,7 +26446,7 @@ import {
|
|
|
26370
26446
|
lstatSync,
|
|
26371
26447
|
mkdtempSync,
|
|
26372
26448
|
openSync as openSync3,
|
|
26373
|
-
readFileSync as
|
|
26449
|
+
readFileSync as readFileSync6,
|
|
26374
26450
|
readlinkSync as readlinkSync2,
|
|
26375
26451
|
rmSync as rmSync4,
|
|
26376
26452
|
statSync as statSync3
|
|
@@ -26465,14 +26541,14 @@ function jsonErrorPosition(text) {
|
|
|
26465
26541
|
}
|
|
26466
26542
|
|
|
26467
26543
|
// ../envoy-client/src/secret-file.ts
|
|
26468
|
-
import { readFileSync as
|
|
26544
|
+
import { readFileSync as readFileSync5 } from "fs";
|
|
26469
26545
|
function sendable(value) {
|
|
26470
26546
|
return !/[\s\p{Cc}]/u.test(value);
|
|
26471
26547
|
}
|
|
26472
26548
|
function readSecretFile(variable, filePath) {
|
|
26473
26549
|
let contents;
|
|
26474
26550
|
try {
|
|
26475
|
-
contents =
|
|
26551
|
+
contents = readFileSync5(filePath, "utf8");
|
|
26476
26552
|
} catch (error) {
|
|
26477
26553
|
throw new Error(`${variable} names ${filePath}, which could not be read: ${messageFor(error)}`);
|
|
26478
26554
|
}
|
|
@@ -26518,6 +26594,8 @@ function namedDirectory(harness, env) {
|
|
|
26518
26594
|
return nonEmpty(env[HARNESS_DIRECTORY_VARIABLE[harness]]);
|
|
26519
26595
|
}
|
|
26520
26596
|
function harnessDirectory(harness, env) {
|
|
26597
|
+
if (harness === "codex")
|
|
26598
|
+
return;
|
|
26521
26599
|
for (const plugin of harness === "command" ? PLUGIN_HARNESSES : [harness]) {
|
|
26522
26600
|
if (harness === "command" && plugin === "claude" && env.CLAUDE_CODE_CHILD_SESSION !== "1") {
|
|
26523
26601
|
continue;
|
|
@@ -26606,7 +26684,7 @@ function danglingLink(filePath) {
|
|
|
26606
26684
|
function parseFile(filePath, schema, checkout) {
|
|
26607
26685
|
let raw;
|
|
26608
26686
|
try {
|
|
26609
|
-
raw =
|
|
26687
|
+
raw = readFileSync6(filePath, "utf-8");
|
|
26610
26688
|
} catch (error) {
|
|
26611
26689
|
if (hasErrnoCode(error, "ENOENT") || hasErrnoCode(error, "ENOTDIR")) {
|
|
26612
26690
|
return { kind: "absent", link: danglingLink(filePath) };
|
|
@@ -26682,7 +26760,7 @@ function runCommand(command, env, cwd) {
|
|
|
26682
26760
|
timedOut: false
|
|
26683
26761
|
};
|
|
26684
26762
|
}
|
|
26685
|
-
const value =
|
|
26763
|
+
const value = readFileSync6(output, "utf-8").trim();
|
|
26686
26764
|
if (value.length === 0)
|
|
26687
26765
|
return { failure: "printed nothing", timedOut: false };
|
|
26688
26766
|
if (!sendable(value)) {
|
|
@@ -31060,7 +31138,7 @@ function lastSeenOf(lastSeen) {
|
|
|
31060
31138
|
var OK = 0;
|
|
31061
31139
|
var REFUSED = 1;
|
|
31062
31140
|
var USAGE = 2;
|
|
31063
|
-
var HOSTS = ["omp", "claude"];
|
|
31141
|
+
var HOSTS = ["omp", "claude", "codex"];
|
|
31064
31142
|
var CLAUDE_OUTPUT_MAX = 25000;
|
|
31065
31143
|
var SAME_MESSAGE = "AskGate reads the files of a message's calls before any of them runs, so it did not see that change.";
|
|
31066
31144
|
var STATE_WRITE_FAILED = "dispatch: Dispatch took the call, but this session's state";
|
|
@@ -31101,6 +31179,18 @@ function fitOutput(text, pictures, kept, limit, writeFull) {
|
|
|
31101
31179
|
return room >= 0 ? `${text.slice(0, room)}
|
|
31102
31180
|
${after}` : after.slice(0, limit);
|
|
31103
31181
|
}
|
|
31182
|
+
function commandHost(env, nearest) {
|
|
31183
|
+
const inherited = env.DISPATCH_HOST !== undefined && env.DISPATCH_HOST !== "codex" || env.CLAUDE_CODE_CHILD_SESSION === "1";
|
|
31184
|
+
if (env.CODEX_THREAD_ID !== undefined && env.DISPATCH_HOST !== "codex") {
|
|
31185
|
+
if (!inherited)
|
|
31186
|
+
return "codex";
|
|
31187
|
+
if (nearest(["codex", "claude", "omp"]) === "codex")
|
|
31188
|
+
return "codex";
|
|
31189
|
+
}
|
|
31190
|
+
if (env.DISPATCH_HOST !== undefined)
|
|
31191
|
+
return env.DISPATCH_HOST;
|
|
31192
|
+
return env.CLAUDE_CODE_CHILD_SESSION === "1" ? "claude" : undefined;
|
|
31193
|
+
}
|
|
31104
31194
|
async function runDispatchCli(argv, rawEnv, io) {
|
|
31105
31195
|
const print = (text) => io.stdout(text.endsWith(`
|
|
31106
31196
|
`) ? text : `${text}
|
|
@@ -31111,9 +31201,16 @@ async function runDispatchCli(argv, rawEnv, io) {
|
|
|
31111
31201
|
env[name] = value;
|
|
31112
31202
|
}
|
|
31113
31203
|
const claudeSession = env.ENVOY_SESSION_ID ?? env.CLAUDE_CODE_SESSION_ID;
|
|
31204
|
+
let resolvedHost;
|
|
31205
|
+
const ledgerHost = () => {
|
|
31206
|
+
resolvedHost ??= {
|
|
31207
|
+
name: commandHost(env, (names) => (io.nearestAncestorNamed ?? nearestAncestorNamed)(names))
|
|
31208
|
+
};
|
|
31209
|
+
return resolvedHost.name;
|
|
31210
|
+
};
|
|
31114
31211
|
const refuse = (text, code, tool, askgate) => {
|
|
31115
31212
|
print(text);
|
|
31116
|
-
const sessionId = claudeSession ?? env.DISPATCH_SESSION_ID;
|
|
31213
|
+
const sessionId = ledgerHost() === "codex" ? env.CODEX_THREAD_ID : claudeSession ?? env.DISPATCH_SESSION_ID ?? env.CODEX_THREAD_ID;
|
|
31117
31214
|
if (sessionId !== undefined) {
|
|
31118
31215
|
try {
|
|
31119
31216
|
appendResult(sessionDirectory(env, sessionId), {
|
|
@@ -31140,12 +31237,12 @@ async function runDispatchCli(argv, rawEnv, io) {
|
|
|
31140
31237
|
`)}`, "Run dispatch --help."].join(`
|
|
31141
31238
|
`), USAGE) : refuse(new ToolInputError(parsed.tool, parsed.problems, defined("aboutAFlag", parsed.aboutAFlag)).message, USAGE, parsed.tool);
|
|
31142
31239
|
}
|
|
31143
|
-
const hostName =
|
|
31240
|
+
const hostName = ledgerHost();
|
|
31144
31241
|
const host = HOSTS.find((name) => name === hostName);
|
|
31145
31242
|
if (host === undefined) {
|
|
31146
|
-
return refuse(hostName === undefined ? "dispatch: DISPATCH_HOST is not set. The host plugin sets it in an agent's shell. From an agent's session, send the command as a bash call. To run dispatch by hand, set DISPATCH_HOST, and set DISPATCH_SESSION_ID to the id of your own session." : `dispatch: DISPATCH_HOST is ${JSON.stringify(hostName)}, not omp or
|
|
31243
|
+
return refuse(hostName === undefined ? "dispatch: DISPATCH_HOST is not set. The host plugin sets it in an agent's shell. From an agent's session, send the command as a bash call. To run dispatch by hand, set DISPATCH_HOST, and set DISPATCH_SESSION_ID to the id of your own session." : `dispatch: DISPATCH_HOST is ${JSON.stringify(hostName)}, not omp, claude or codex.`, USAGE, parsed.tool);
|
|
31147
31244
|
}
|
|
31148
|
-
const [sessionId, sessionVariable] = host === "claude" ? [claudeSession, "ENVOY_SESSION_ID or CLAUDE_CODE_SESSION_ID"] : [env.DISPATCH_SESSION_ID, "DISPATCH_SESSION_ID"];
|
|
31245
|
+
const [sessionId, sessionVariable] = host === "claude" ? [claudeSession, "ENVOY_SESSION_ID or CLAUDE_CODE_SESSION_ID"] : host === "codex" ? [env.CODEX_THREAD_ID, "CODEX_THREAD_ID"] : [env.DISPATCH_SESSION_ID, "DISPATCH_SESSION_ID"];
|
|
31149
31246
|
if (sessionId === undefined) {
|
|
31150
31247
|
return refuse(`dispatch: ${sessionVariable} is not set, so this call has no session to act as. The host plugin sets it in an agent's shell.`, USAGE, parsed.tool);
|
|
31151
31248
|
}
|
|
@@ -31200,7 +31297,7 @@ async function runDispatchCli(argv, rawEnv, io) {
|
|
|
31200
31297
|
const fd = openSync4(operandPath(io.cwd, file), constants2.O_RDONLY | constants2.O_NONBLOCK);
|
|
31201
31298
|
try {
|
|
31202
31299
|
if (fstatSync2(fd).isFile())
|
|
31203
|
-
bytes =
|
|
31300
|
+
bytes = readFileSync7(fd);
|
|
31204
31301
|
} finally {
|
|
31205
31302
|
closeSync4(fd);
|
|
31206
31303
|
}
|
|
@@ -31327,12 +31424,12 @@ async function runDispatchCli(argv, rawEnv, io) {
|
|
|
31327
31424
|
return `not written, ${messageFor(error)}`;
|
|
31328
31425
|
}
|
|
31329
31426
|
};
|
|
31330
|
-
print(fitOutput(text, pictures, kept, host === "claude" ? CLAUDE_OUTPUT_MAX : Number.POSITIVE_INFINITY, writeFull));
|
|
31427
|
+
print(fitOutput(text, pictures, kept, host === "claude" || host === "codex" ? CLAUDE_OUTPUT_MAX : Number.POSITIVE_INFINITY, writeFull));
|
|
31331
31428
|
return code;
|
|
31332
31429
|
}
|
|
31333
31430
|
|
|
31334
31431
|
// ../envoy-client/bin/dispatch.ts
|
|
31335
|
-
var readText = (path) =>
|
|
31432
|
+
var readText = (path) => readFileSync8(path === "-" ? 0 : path, "utf-8");
|
|
31336
31433
|
var pending = [];
|
|
31337
31434
|
var writeTo = (stream) => (text) => {
|
|
31338
31435
|
const { promise, resolve } = Promise.withResolvers();
|