@sjawhar/claude-envoy 5.25.0 → 5.25.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/.claude-plugin/plugin.json +1 -1
- package/.omp-plugin/plugin.json +1 -1
- package/bin/envoy-send.ts +1 -1
- package/dist/codex-hook.js +229 -155
- package/dist/dispatch.js +233 -155
- package/dist/envoy-channel.js +285 -206
- package/dist/session-hook.js +213 -143
- package/hooks/codex-hook.ts +1 -1
- package/hooks/session-hook.ts +10 -8
- package/package.json +1 -1
- package/src/codex/codex-server.ts +4 -3
- package/src/codex/codex-user-turns.ts +3 -1
- package/src/envoy-channel-server.ts +10 -8
- package/src/legion-claim.ts +4 -4
- package/src/legion-phase-hook.ts +1 -1
- package/src/user-turn-router.ts +2 -2
package/hooks/codex-hook.ts
CHANGED
|
@@ -127,7 +127,7 @@ async function sessionStart(raw: unknown): Promise<void> {
|
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
const chosen = sessionConfigFile("codex", process.env)
|
|
130
|
-
const { dispatch, warnings } = sessionDispatchSettings(chosen, process.env, {
|
|
130
|
+
const { dispatch, warnings } = await sessionDispatchSettings(chosen, process.env, {
|
|
131
131
|
cwd: input.cwd,
|
|
132
132
|
session: input.session_id,
|
|
133
133
|
})
|
package/hooks/session-hook.ts
CHANGED
|
@@ -369,7 +369,7 @@ async function openAsks(raw: unknown): Promise<void> {
|
|
|
369
369
|
{ CLAUDE_PROJECT_DIR: process.env["CLAUDE_PROJECT_DIR"] },
|
|
370
370
|
input.cwd ?? process.cwd(),
|
|
371
371
|
)
|
|
372
|
-
const { dispatch, warnings, missing } = sessionDispatchSettings(chosen, process.env, {
|
|
372
|
+
const { dispatch, warnings, missing } = await sessionDispatchSettings(chosen, process.env, {
|
|
373
373
|
cwd: directory,
|
|
374
374
|
session: input.session_id,
|
|
375
375
|
})
|
|
@@ -397,14 +397,16 @@ async function openAsks(raw: unknown): Promise<void> {
|
|
|
397
397
|
}
|
|
398
398
|
}
|
|
399
399
|
|
|
400
|
-
function dispatchFirst(raw: unknown): void {
|
|
400
|
+
async function dispatchFirst(raw: unknown): Promise<void> {
|
|
401
401
|
const input = DispatchFirstInput.parse(raw)
|
|
402
402
|
const directory = claudeProjectDirectory(
|
|
403
403
|
{ CLAUDE_PROJECT_DIR: process.env["CLAUDE_PROJECT_DIR"] },
|
|
404
404
|
input.cwd ?? process.cwd(),
|
|
405
405
|
)
|
|
406
406
|
const chosen = sessionConfigFile(HOST, process.env)
|
|
407
|
-
if (!sessionDispatchSettings(chosen, process.env, { cwd: directory }).dispatch.enabled)
|
|
407
|
+
if (!(await sessionDispatchSettings(chosen, process.env, { cwd: directory })).dispatch.enabled) {
|
|
408
|
+
return
|
|
409
|
+
}
|
|
408
410
|
const pluginRoot = configuredValue(process.env["CLAUDE_PLUGIN_ROOT"])
|
|
409
411
|
if (pluginRoot === undefined) {
|
|
410
412
|
throw new Error("CLAUDE_PLUGIN_ROOT is unset; Claude Code sets it for every plugin hook")
|
|
@@ -547,7 +549,7 @@ async function answersMessage(
|
|
|
547
549
|
by: number,
|
|
548
550
|
): Promise<{ readonly text: string | undefined; readonly notice?: string | undefined }> {
|
|
549
551
|
const file = sessionConfigFile(HOST, process.env)
|
|
550
|
-
let { dispatch } = sessionDispatchSettings(file, process.env, {
|
|
552
|
+
let { dispatch } = await sessionDispatchSettings(file, process.env, {
|
|
551
553
|
cwd,
|
|
552
554
|
commands: "kept",
|
|
553
555
|
session,
|
|
@@ -557,7 +559,7 @@ async function answersMessage(
|
|
|
557
559
|
// The configured URL alone, no command run. With none (envoy.json unreadable, Dispatch off or
|
|
558
560
|
// no URL), no token command can name one either: the hook starts no refresher and carries the
|
|
559
561
|
// failure line naming why, never a list read for some URL.
|
|
560
|
-
dispatchUrl = sessionDispatchUrl(file, process.env, { cwd })
|
|
562
|
+
dispatchUrl = await sessionDispatchUrl(file, process.env, { cwd })
|
|
561
563
|
if (dispatchUrl !== undefined) {
|
|
562
564
|
const refreshed = await refreshedAnswers(session, cwd, dispatchUrl, startedAt, by)
|
|
563
565
|
if ("text" in refreshed) return refreshed
|
|
@@ -637,8 +639,8 @@ async function answersRefresh(session: string, cwd: string): Promise<never> {
|
|
|
637
639
|
// before any command runs: when envoy.json moved on since the hook started this refresher, no
|
|
638
640
|
// hook carries what it read, and when the token command fails, the hook for the same URL
|
|
639
641
|
// carries this refresher's failure line naming why.
|
|
640
|
-
const dispatchUrl = sessionDispatchUrl(file, process.env, { cwd }) ?? null
|
|
641
|
-
const { dispatch } = sessionDispatchSettings(file, process.env, { cwd, session })
|
|
642
|
+
const dispatchUrl = (await sessionDispatchUrl(file, process.env, { cwd })) ?? null
|
|
643
|
+
const { dispatch } = await sessionDispatchSettings(file, process.env, { cwd, session })
|
|
642
644
|
const read = await readSessionAnswers({
|
|
643
645
|
session,
|
|
644
646
|
dispatch,
|
|
@@ -695,4 +697,4 @@ if (mode === "open-asks") {
|
|
|
695
697
|
await endOnceWritten([process.stdout, process.stderr], holdsDeviceLoginLock, (code) =>
|
|
696
698
|
process.exit(code),
|
|
697
699
|
)
|
|
698
|
-
} else dispatchFirst(input)
|
|
700
|
+
} else await dispatchFirst(input)
|
package/package.json
CHANGED
|
@@ -452,7 +452,7 @@ export async function runCodexEnvoyServer(): Promise<void> {
|
|
|
452
452
|
RECORD_POLL_MS,
|
|
453
453
|
)
|
|
454
454
|
const id = new SessionIdentity(bound.session_id, bound.cwd)
|
|
455
|
-
const { dispatch, envoy, notice } = sessionSettings(configFile, process.env, {
|
|
455
|
+
const { dispatch, envoy, notice } = await sessionSettings(configFile, process.env, {
|
|
456
456
|
cwd: bound.cwd,
|
|
457
457
|
session: () => id.id,
|
|
458
458
|
})
|
|
@@ -612,9 +612,10 @@ export async function runCodexEnvoyServer(): Promise<void> {
|
|
|
612
612
|
createCodexUserTurnRouter({
|
|
613
613
|
ask: (question) => askSideQuestion(command(), id.id, question),
|
|
614
614
|
deliver: (item) => codexDelivery.deliver(item),
|
|
615
|
-
dispatch: (ms) => {
|
|
615
|
+
dispatch: async (ms) => {
|
|
616
616
|
const active = activeDispatchSettings(
|
|
617
|
-
sessionDispatchSettings(configFile, process.env, { cwd: bound.cwd })
|
|
617
|
+
(await sessionDispatchSettings(configFile, process.env, { cwd: bound.cwd }))
|
|
618
|
+
.dispatch,
|
|
618
619
|
)
|
|
619
620
|
return active === null
|
|
620
621
|
? undefined
|
|
@@ -28,7 +28,9 @@ import type { CodexInboxItem } from "./codex-inbox"
|
|
|
28
28
|
export interface CodexUserTurnOptions {
|
|
29
29
|
readonly sessionId: () => string
|
|
30
30
|
readonly state: UserTurnState
|
|
31
|
-
|
|
31
|
+
/** The session's Dispatch for one request, with `ms` to answer; undefined when Dispatch is not
|
|
32
|
+
* configured, and a rejection when its configuration cannot be read. */
|
|
33
|
+
readonly dispatch: (ms: number) => Promise<DispatchClient | undefined>
|
|
32
34
|
readonly reply: (
|
|
33
35
|
delivery: DispatchDelivery,
|
|
34
36
|
result: { readonly body?: string; readonly error?: string },
|
|
@@ -513,10 +513,12 @@ export async function postDispatchReply(
|
|
|
513
513
|
delivery: DispatchDelivery,
|
|
514
514
|
result: { readonly body?: string; readonly error?: string; readonly followUp?: boolean },
|
|
515
515
|
): Promise<void> {
|
|
516
|
-
const config =
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
516
|
+
const config = (
|
|
517
|
+
await sessionDispatchSettings(configFile, process.env, {
|
|
518
|
+
cwd: identity.directory,
|
|
519
|
+
session: () => identity.id,
|
|
520
|
+
})
|
|
521
|
+
).dispatch
|
|
520
522
|
if (!config.enabled) throw new Error(config.error ?? config.notice)
|
|
521
523
|
await postDeliveryReply(config, identity.id, delivery, result)
|
|
522
524
|
}
|
|
@@ -2478,7 +2480,7 @@ function pluginStateDirectory(): string {
|
|
|
2478
2480
|
* notifications (`./legion-inbox`). */
|
|
2479
2481
|
export async function runEnvoyChannelServer(): Promise<void> {
|
|
2480
2482
|
const directory = projectDirectory()
|
|
2481
|
-
const pane = legionPane(process.env)
|
|
2483
|
+
const pane = await legionPane(process.env)
|
|
2482
2484
|
// The session's envoy.json, by Claude Code's rule (`$CLAUDE_CONFIG_DIR/envoy.json` when that is
|
|
2483
2485
|
// set), worked out once as the server starts; Dispatch's URL and token are re-read from it on each
|
|
2484
2486
|
// use, so a file that moved its server takes effect without a restart.
|
|
@@ -2486,7 +2488,7 @@ export async function runEnvoyChannelServer(): Promise<void> {
|
|
|
2486
2488
|
// The session this server drives, read at every broker trade: Claude Code mints a new id on
|
|
2487
2489
|
// /clear and `identity` is set to it, so a token this session presents names this session.
|
|
2488
2490
|
const currentSessionId = (): string => identity.id
|
|
2489
|
-
const { dispatch, envoy, notice } = sessionSettings(configFile, process.env, {
|
|
2491
|
+
const { dispatch, envoy, notice } = await sessionSettings(configFile, process.env, {
|
|
2490
2492
|
cwd: directory,
|
|
2491
2493
|
session: currentSessionId,
|
|
2492
2494
|
})
|
|
@@ -2796,9 +2798,9 @@ export async function runEnvoyChannelServer(): Promise<void> {
|
|
|
2796
2798
|
*/
|
|
2797
2799
|
const router = (state: UserTurnState): UserTurnRouter => {
|
|
2798
2800
|
const options: UserTurnRouterOptions = {
|
|
2799
|
-
dispatch: (ms) => {
|
|
2801
|
+
dispatch: async (ms) => {
|
|
2800
2802
|
const active = activeDispatchSettings(
|
|
2801
|
-
sessionDispatchSettings(configFile, process.env, { cwd: directory }).dispatch,
|
|
2803
|
+
(await sessionDispatchSettings(configFile, process.env, { cwd: directory })).dispatch,
|
|
2802
2804
|
)
|
|
2803
2805
|
return active === null
|
|
2804
2806
|
? undefined
|
package/src/legion-claim.ts
CHANGED
|
@@ -35,10 +35,10 @@ export interface LegionPane {
|
|
|
35
35
|
/**
|
|
36
36
|
* The Legion pane this server runs in, or undefined when no boot token is on its environment (a
|
|
37
37
|
* Claude Code session outside Legion). A set `LEGION_BOOT_TOKEN_FILE` is authoritative, as in
|
|
38
|
-
* every pane: a missing or blank file
|
|
39
|
-
* `CLAUDE_CONFIG_DIR`
|
|
38
|
+
* every pane, and read without holding the event loop: a missing or blank file rejects naming it.
|
|
39
|
+
* A pane without `LEGION_DAEMON_URL` or `CLAUDE_CONFIG_DIR` rejects naming the variable.
|
|
40
40
|
*/
|
|
41
|
-
export function legionPane(env: NodeJS.ProcessEnv): LegionPane | undefined {
|
|
41
|
+
export async function legionPane(env: NodeJS.ProcessEnv): Promise<LegionPane | undefined> {
|
|
42
42
|
const pointer = env["LEGION_BOOT_TOKEN_FILE"]
|
|
43
43
|
if (pointer === undefined && configuredValue(env["LEGION_BOOT_TOKEN"]) === undefined) {
|
|
44
44
|
return undefined
|
|
@@ -56,7 +56,7 @@ export function legionPane(env: NodeJS.ProcessEnv): LegionPane | undefined {
|
|
|
56
56
|
bootToken:
|
|
57
57
|
pointer === undefined
|
|
58
58
|
? required("LEGION_BOOT_TOKEN")
|
|
59
|
-
: readSecretFile("LEGION_BOOT_TOKEN_FILE", pointer),
|
|
59
|
+
: await readSecretFile("LEGION_BOOT_TOKEN_FILE", pointer),
|
|
60
60
|
launcherSaves: configuredValue(env["LEGION_CLAUDE_SESSION_ID"]) !== undefined,
|
|
61
61
|
}
|
|
62
62
|
}
|
package/src/legion-phase-hook.ts
CHANGED
|
@@ -419,7 +419,7 @@ export function createPhaseHookEndpoint(deps: PhaseHookDeps): PhaseHookEndpoint
|
|
|
419
419
|
// The server's own listener client, so the notice reaches the one this session already talks
|
|
420
420
|
// to; Envoy off for the session leaves it undefined, the runner says so once at debug, and
|
|
421
421
|
// the reminder keeps coming without a notice.
|
|
422
|
-
publisher: () => deps.publish,
|
|
422
|
+
publisher: async () => deps.publish,
|
|
423
423
|
project: configuredValue(deps.env["LEGION_PROJECT"]),
|
|
424
424
|
limits,
|
|
425
425
|
log: deps.log,
|
package/src/user-turn-router.ts
CHANGED
|
@@ -197,8 +197,8 @@ export interface UserTurnRouterOptions {
|
|
|
197
197
|
/** The Claude Code session itself (`./mod-session`). */
|
|
198
198
|
readonly session: ModSession
|
|
199
199
|
/** The session's Dispatch for one request, with `ms` to answer; undefined when Dispatch is not
|
|
200
|
-
* configured, and a
|
|
201
|
-
readonly dispatch: (ms: number) => DispatchClient | undefined
|
|
200
|
+
* configured, and a rejection when its configuration cannot be read. */
|
|
201
|
+
readonly dispatch: (ms: number) => Promise<DispatchClient | undefined>
|
|
202
202
|
/** Answers a delivery on Dispatch: the reply the person reads, or the error that stopped it.
|
|
203
203
|
* `followUp` is the ask that Dispatch post this answer although the attempt is already
|
|
204
204
|
* answered, which every answer to a delivery after the first carries (`post`). */
|