@sjawhar/claude-envoy 6.14.0 → 6.14.2
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 +42 -2
- package/dist/codex-hook.js +3 -0
- package/dist/dispatch.js +108 -57
- package/dist/envoy-channel.js +558 -219
- package/dist/session-hook.js +3 -0
- package/package.json +1 -1
- package/src/agent-stream-runner.ts +10 -7
- package/src/channel-connection.ts +21 -9
- package/src/codex/codex-server.ts +23 -2
- package/src/envoy-channel-server.ts +296 -113
- package/src/envoy-off.ts +16 -1
- package/src/inbound-outage-lines.ts +65 -0
- package/src/legion-claim.ts +13 -3
- package/src/stop-gates.ts +17 -0
package/src/envoy-off.ts
CHANGED
|
@@ -9,13 +9,20 @@ import { roleStateFile, type SessionIdentity, writePersistedRole } from "./sessi
|
|
|
9
9
|
* consumer, nothing registered with the listener (which would route a delivery to a deaf process),
|
|
10
10
|
* an empty inbox, and following a topic refused naming `why`. A role an explicit `envoy_role_set`
|
|
11
11
|
* claimed through the listener is still persisted, so a later server with NATS takes it back.
|
|
12
|
+
*
|
|
13
|
+
* `stopping` is the server's stop reading (R24 of dispatch://INFRA-3589). The session reads as
|
|
14
|
+
* stopping from then on, and from `shutdown()` on: the role tool claims nothing, and a claim the
|
|
15
|
+
* listener answers after that leaves no record (the write gate).
|
|
12
16
|
*/
|
|
13
17
|
export function inboundOffChannelSession(options: {
|
|
14
18
|
readonly identity: SessionIdentity
|
|
15
19
|
readonly stateDirectory: string
|
|
16
20
|
readonly why: string
|
|
21
|
+
readonly stopping: () => boolean
|
|
17
22
|
}): ChannelSession {
|
|
18
23
|
const { identity, stateDirectory, why } = options
|
|
24
|
+
let shutDown = false
|
|
25
|
+
const stopping = (): boolean => shutDown || options.stopping()
|
|
19
26
|
return {
|
|
20
27
|
delivery: { enqueue: async () => false, inbox: () => [] },
|
|
21
28
|
topics: () => [],
|
|
@@ -31,12 +38,20 @@ export function inboundOffChannelSession(options: {
|
|
|
31
38
|
observe: () => undefined,
|
|
32
39
|
messageOf: () => undefined,
|
|
33
40
|
async rememberRole(role) {
|
|
41
|
+
// A stopping session keeps no role: a claim the listener granted after the stop began is
|
|
42
|
+
// not held here and leaves no record.
|
|
43
|
+
if (stopping()) return
|
|
34
44
|
await writePersistedRole(roleStateFile(stateDirectory, identity.id), {
|
|
35
45
|
session_id: identity.id,
|
|
36
46
|
role,
|
|
37
47
|
})
|
|
38
48
|
},
|
|
39
|
-
|
|
49
|
+
// It registers nothing and deletes no record. Once the stop has begun, the role tool refuses
|
|
50
|
+
// a claim (`refuseClaimWhileStopping`), and so does the client's stop gate.
|
|
51
|
+
stopping,
|
|
52
|
+
shutdown: async () => {
|
|
53
|
+
shutDown = true
|
|
54
|
+
},
|
|
40
55
|
}
|
|
41
56
|
}
|
|
42
57
|
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { InboundOutageKind } from "@legion/envoy-client/inbound-outage"
|
|
2
|
+
|
|
3
|
+
/** The stderr line of an outage of one kind, with the failure's message, and what the session is
|
|
4
|
+
* told of it, as the line of a notice that could not be shown names it. */
|
|
5
|
+
interface OutageLines {
|
|
6
|
+
readonly line: (why: string) => string
|
|
7
|
+
readonly told: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** The stderr line of an outage that leaves the session nothing. */
|
|
11
|
+
const RECEIVES_NOTHING: OutageLines = {
|
|
12
|
+
line: (why) =>
|
|
13
|
+
`envoy-channel: this session receives nothing (${why}); registering again every heartbeat\n`,
|
|
14
|
+
told: "that it receives nothing",
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* What the server's stderr says of an outage the outage report told (`inboundUnavailable`), by its
|
|
19
|
+
* kind (`InboundOutageKind`, which says what each kind means for what reaches the session). The
|
|
20
|
+
* session's notice card beside it is `inboundUnavailableNoticeText`.
|
|
21
|
+
*/
|
|
22
|
+
export const INBOUND_UNAVAILABLE_LINES: Record<InboundOutageKind, OutageLines> = {
|
|
23
|
+
unrecorded: {
|
|
24
|
+
line: (why) =>
|
|
25
|
+
`envoy-channel: this session's registration is not recorded for certain (${why}), and the session registers again at every heartbeat\n`,
|
|
26
|
+
told: "that its registration is not recorded for certain",
|
|
27
|
+
},
|
|
28
|
+
github_withheld: {
|
|
29
|
+
line: (why) =>
|
|
30
|
+
`envoy-channel: the listener follows none of this session's GitHub topics now (${why}); the session's other messages still reach it if the listener already held its registration, and none reach it until a registration is accepted if it held none; registering again every heartbeat\n`,
|
|
31
|
+
told: "that its GitHub messages are withheld",
|
|
32
|
+
},
|
|
33
|
+
refused: RECEIVES_NOTHING,
|
|
34
|
+
no_relay: RECEIVES_NOTHING,
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** The stderr line of an outage of one kind that ended, and what the session is told of it. */
|
|
38
|
+
interface RestoredLines {
|
|
39
|
+
readonly line: string
|
|
40
|
+
readonly told: string
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** The stderr line of a session that receives again after it received nothing. */
|
|
44
|
+
const RECEIVES_AGAIN: RestoredLines = {
|
|
45
|
+
line: "envoy-channel: this session receives again: a registration was accepted\n",
|
|
46
|
+
told: "that it receives again",
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* What the server's stderr says once a registration is accepted after a told outage, by the kind
|
|
51
|
+
* of that outage (`InboundOutageKind`). The session's notice card beside it is
|
|
52
|
+
* `inboundRestoredNoticeText`.
|
|
53
|
+
*/
|
|
54
|
+
export const INBOUND_RESTORED_LINES: Record<InboundOutageKind, RestoredLines> = {
|
|
55
|
+
unrecorded: {
|
|
56
|
+
line: "envoy-channel: the listener recorded a registration of this session\n",
|
|
57
|
+
told: "that the listener recorded its registration",
|
|
58
|
+
},
|
|
59
|
+
github_withheld: {
|
|
60
|
+
line: "envoy-channel: the listener follows this session's GitHub topics again: a registration was accepted\n",
|
|
61
|
+
told: "that the listener follows its GitHub topics again",
|
|
62
|
+
},
|
|
63
|
+
refused: RECEIVES_AGAIN,
|
|
64
|
+
no_relay: RECEIVES_AGAIN,
|
|
65
|
+
}
|
package/src/legion-claim.ts
CHANGED
|
@@ -92,9 +92,19 @@ export function endPane(): void {
|
|
|
92
92
|
process.kill(process.ppid, "SIGTERM")
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
-
/**
|
|
96
|
-
|
|
97
|
-
|
|
95
|
+
/**
|
|
96
|
+
* Logs why the pane cannot run, then ends it (`endPane`). `server` is the channel server's stop
|
|
97
|
+
* and its writer of the pane's log, which passes each line through the server's tell gate
|
|
98
|
+
* (`logLegionLine` in `./envoy-channel-server`). Once the server's stop has begun this does
|
|
99
|
+
* nothing (R24 of dispatch://INFRA-3589): the stop ends the pane already, and `endPane` would
|
|
100
|
+
* SIGTERM the `claude` this server runs under on its way out.
|
|
101
|
+
*/
|
|
102
|
+
export function stopPane(
|
|
103
|
+
why: string,
|
|
104
|
+
server: { readonly stopping: () => boolean; readonly log: (line: string) => void },
|
|
105
|
+
): void {
|
|
106
|
+
if (server.stopping()) return
|
|
107
|
+
server.log(`${why}; stopping the pane so the daemon launches it again`)
|
|
98
108
|
endPane()
|
|
99
109
|
}
|
|
100
110
|
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A channel server's tell gate over its stderr (R24 of dispatch://INFRA-3589). Once the session's
|
|
3
|
+
* stop has begun, the server tells the session and its stderr nothing (the tell gate), and writes
|
|
4
|
+
* no role record and no ledger entry (the write gate). Each notice card, role record and ledger
|
|
5
|
+
* entry reads the stop itself before it is told or written; the stderr lines of the server's own
|
|
6
|
+
* go through the writer below. The stop's own lines are written with `process.stderr.write`,
|
|
7
|
+
* which has no gate (`ChannelSession.shutdown`, `ChannelTopics.close`). The listener calls have a
|
|
8
|
+
* gate of their own, in the client (`EnvoyClientConfig.stopping`).
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** A writer of stderr lines for one stop reading, `stopping`: a session's, or its server's. It
|
|
12
|
+
* writes each line to stderr before the stop has begun, and nothing once it has. */
|
|
13
|
+
export function gatedStderr(stopping: () => boolean): (line: string) => void {
|
|
14
|
+
return (line) => {
|
|
15
|
+
if (!stopping()) process.stderr.write(line)
|
|
16
|
+
}
|
|
17
|
+
}
|