@sjawhar/claude-envoy 6.12.4 → 6.12.6
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 +5 -1
- package/dist/dispatch.js +4 -5
- package/dist/envoy-channel.js +44 -22
- package/package.json +2 -2
- package/src/envoy-channel-server.ts +20 -4
- package/src/legion-claim.ts +10 -2
- package/src/role-claim-warnings.ts +19 -0
package/.omp-plugin/plugin.json
CHANGED
package/README.md
CHANGED
|
@@ -150,7 +150,11 @@ message from Dispatch's Agents page as that person's own turn.
|
|
|
150
150
|
decided on the standing claim: the listener grants it to the process that claim names, grants
|
|
151
151
|
it once nobody renewed that claim inside its live window, and otherwise refuses it naming this
|
|
152
152
|
very session, which keeps the role and the record here and asks again on the next heartbeat.
|
|
153
|
-
Only a refusal naming a different session ends the role and removes the record. Every
|
|
153
|
+
Only a refusal naming a different session ends the role and removes the record. Every claim
|
|
154
|
+
that lands, the tool's, a restore's, a heartbeat's or a Legion pane's, writes each warning the
|
|
155
|
+
listener answers it with to stderr, naming the role and the session, such as that it handed over
|
|
156
|
+
no message of the replaced session and why; `envoy_role_set` also returns them beside the
|
|
157
|
+
interest row, as `warnings`. Every healthy
|
|
154
158
|
registration heartbeat checks and reasserts the role if the listener lost it, and it confirms
|
|
155
159
|
the role only when the lookup names this session *and* this process and reports no hand-back
|
|
156
160
|
(`handed_back`); each heartbeat also renews the claims this process holds, whatever topics
|
package/dist/dispatch.js
CHANGED
|
@@ -39956,6 +39956,7 @@ var DeliveryAnswerWireSchema = object({
|
|
|
39956
39956
|
consumer_start: number2().int().nonnegative().optional()
|
|
39957
39957
|
});
|
|
39958
39958
|
var StringListWireSchema = array(string2()).nullish().transform((list) => list ?? []);
|
|
39959
|
+
var RoleSetWireSchema = InterestWireSchema.extend({ warnings: StringListWireSchema });
|
|
39959
39960
|
var SessionWireSchema = object({
|
|
39960
39961
|
session_id: string2(),
|
|
39961
39962
|
machine_id: string2(),
|
|
@@ -40416,7 +40417,7 @@ function createEnvoyClient(config) {
|
|
|
40416
40417
|
},
|
|
40417
40418
|
setRole: async (input) => {
|
|
40418
40419
|
const soft = input.soft === true;
|
|
40419
|
-
const previous =
|
|
40420
|
+
const previous = input.previousSessionID ?? "";
|
|
40420
40421
|
const body = {
|
|
40421
40422
|
session_id: input.sessionID,
|
|
40422
40423
|
role: input.role,
|
|
@@ -40441,10 +40442,8 @@ function createEnvoyClient(config) {
|
|
|
40441
40442
|
}
|
|
40442
40443
|
throw error;
|
|
40443
40444
|
}
|
|
40444
|
-
|
|
40445
|
-
|
|
40446
|
-
interest: InterestWireSchema.parse(answerJson(raw, "POST", "/v1/roles/set"))
|
|
40447
|
-
};
|
|
40445
|
+
const { warnings, ...interest } = RoleSetWireSchema.parse(answerJson(raw, "POST", "/v1/roles/set"));
|
|
40446
|
+
return { claimed: true, interest, warnings };
|
|
40448
40447
|
},
|
|
40449
40448
|
getRole: async (role) => RoleWireSchema.parse(answerJson(await request(`/v1/roles/${encodeURIComponent(role)}`, { method: "GET" }), "GET", `/v1/roles/${encodeURIComponent(role)}`)),
|
|
40450
40449
|
listSessions: async (input = {}) => {
|
package/dist/envoy-channel.js
CHANGED
|
@@ -61395,6 +61395,7 @@ var DeliveryAnswerWireSchema = object({
|
|
|
61395
61395
|
consumer_start: number2().int().nonnegative().optional()
|
|
61396
61396
|
});
|
|
61397
61397
|
var StringListWireSchema = array(string2()).nullish().transform((list) => list ?? []);
|
|
61398
|
+
var RoleSetWireSchema = InterestWireSchema.extend({ warnings: StringListWireSchema });
|
|
61398
61399
|
var SessionWireSchema = object({
|
|
61399
61400
|
session_id: string2(),
|
|
61400
61401
|
machine_id: string2(),
|
|
@@ -61855,7 +61856,7 @@ function createEnvoyClient(config) {
|
|
|
61855
61856
|
},
|
|
61856
61857
|
setRole: async (input) => {
|
|
61857
61858
|
const soft = input.soft === true;
|
|
61858
|
-
const previous =
|
|
61859
|
+
const previous = input.previousSessionID ?? "";
|
|
61859
61860
|
const body = {
|
|
61860
61861
|
session_id: input.sessionID,
|
|
61861
61862
|
role: input.role,
|
|
@@ -61880,10 +61881,8 @@ function createEnvoyClient(config) {
|
|
|
61880
61881
|
}
|
|
61881
61882
|
throw error;
|
|
61882
61883
|
}
|
|
61883
|
-
|
|
61884
|
-
|
|
61885
|
-
interest: InterestWireSchema.parse(answerJson(raw, "POST", "/v1/roles/set"))
|
|
61886
|
-
};
|
|
61884
|
+
const { warnings, ...interest } = RoleSetWireSchema.parse(answerJson(raw, "POST", "/v1/roles/set"));
|
|
61885
|
+
return { claimed: true, interest, warnings };
|
|
61887
61886
|
},
|
|
61888
61887
|
getRole: async (role) => RoleWireSchema.parse(answerJson(await request(`/v1/roles/${encodeURIComponent(role)}`, { method: "GET" }), "GET", `/v1/roles/${encodeURIComponent(role)}`)),
|
|
61889
61888
|
listSessions: async (input = {}) => {
|
|
@@ -66855,7 +66854,7 @@ var import_nats5 = __toESM(require_mod4(), 1);
|
|
|
66855
66854
|
|
|
66856
66855
|
// package.json
|
|
66857
66856
|
var name2 = "@sjawhar/claude-envoy";
|
|
66858
|
-
var version2 = "6.12.
|
|
66857
|
+
var version2 = "6.12.6";
|
|
66859
66858
|
var package_default = {
|
|
66860
66859
|
name: name2,
|
|
66861
66860
|
version: version2,
|
|
@@ -66866,7 +66865,7 @@ var package_default = {
|
|
|
66866
66865
|
repository: { type: "git", url: "https://github.com/cybermonklabs/legion" },
|
|
66867
66866
|
scripts: { channel: "bun bin/envoy-channel.ts", "verify-build": "bash scripts/verify-build.sh", prepack: "bash scripts/pack-skills.sh", postpack: "bash scripts/pack-skills.sh --restore", typecheck: "bun ../contracts/scripts/gen-api.ts && bunx tsc --noEmit", test: "bun test --timeout=60000", lint: "bunx biome check src/ hooks/ scripts/" },
|
|
66868
66867
|
devDependencies: { "@biomejs/biome": "^2.3.14", "@legion/cipher-client": "workspace:*", "@legion/contracts": "workspace:*", "@legion/envoy-client": "workspace:*", "@legion/pi-shared": "workspace:*", "@legion/test-fixtures": "workspace:*", "@modelcontextprotocol/sdk": "^1.30.0", "bun-types": "latest", nats: "^2.29.2", typescript: "^5.3.0", zod: "4.3.6" },
|
|
66869
|
-
legion: { daemonApiVersion:
|
|
66868
|
+
legion: { daemonApiVersion: 285 }
|
|
66870
66869
|
};
|
|
66871
66870
|
|
|
66872
66871
|
// ../envoy-client/src/inbound-card.ts
|
|
@@ -68936,7 +68935,8 @@ var LegionRegisterResponse = object({
|
|
|
68936
68935
|
role: _enum2(LEGION_ROLES),
|
|
68937
68936
|
generation: number2().int().positive(),
|
|
68938
68937
|
secret: nonEmptyString2,
|
|
68939
|
-
promptAgents: array(nonEmptyString2)
|
|
68938
|
+
promptAgents: array(nonEmptyString2),
|
|
68939
|
+
replaces: nonEmptyString2.optional()
|
|
68940
68940
|
});
|
|
68941
68941
|
var LegionCapabilityReport = strictObject({
|
|
68942
68942
|
measuredAt: timestamp,
|
|
@@ -69039,7 +69039,8 @@ var LegionControllerRegisterResponse = object({
|
|
|
69039
69039
|
claimToken: nonEmptyString2,
|
|
69040
69040
|
role: literal("controller").optional(),
|
|
69041
69041
|
generation: number2().int().positive(),
|
|
69042
|
-
secret: nonEmptyString2
|
|
69042
|
+
secret: nonEmptyString2,
|
|
69043
|
+
replaces: nonEmptyString2.optional()
|
|
69043
69044
|
});
|
|
69044
69045
|
var LegionControllerSecretResponse = object({
|
|
69045
69046
|
secret: nonEmptyString2,
|
|
@@ -69451,9 +69452,10 @@ var LEGION_ANSWER_READS = {
|
|
|
69451
69452
|
"role",
|
|
69452
69453
|
"generation",
|
|
69453
69454
|
"secret",
|
|
69454
|
-
"promptAgents"
|
|
69455
|
+
"promptAgents",
|
|
69456
|
+
"replaces"
|
|
69455
69457
|
],
|
|
69456
|
-
LegionControllerRegisterResponse: ["claimToken", "generation", "secret"],
|
|
69458
|
+
LegionControllerRegisterResponse: ["claimToken", "generation", "secret", "replaces"],
|
|
69457
69459
|
LegionGrantResponse: ["grantId"],
|
|
69458
69460
|
LegionErrorResponse: ["error", "code"],
|
|
69459
69461
|
LegionReleaseRecordsResponse: [
|
|
@@ -69822,7 +69824,7 @@ async function bootLegionClaim(host) {
|
|
|
69822
69824
|
stopAfterRegistration(host, claim.claimToken, error);
|
|
69823
69825
|
return { claimed: Promise.resolve() };
|
|
69824
69826
|
}
|
|
69825
|
-
return { claimed: claimRoleAtFirstTurn(host, claim.claimToken, firstTurn) };
|
|
69827
|
+
return { claimed: claimRoleAtFirstTurn(host, claim.claimToken, claim.replaces, firstTurn) };
|
|
69826
69828
|
}
|
|
69827
69829
|
function stopAfterRegistration(host, role, error) {
|
|
69828
69830
|
host.log(`claim boot failed after claims/register registered ${role}; ${host.stopping}: ${messageFor(error)}`);
|
|
@@ -69841,7 +69843,7 @@ function listenForFirstTurn(host) {
|
|
|
69841
69843
|
step();
|
|
69842
69844
|
};
|
|
69843
69845
|
}
|
|
69844
|
-
function claimRoleAtFirstTurn(host, role, firstTurn) {
|
|
69846
|
+
function claimRoleAtFirstTurn(host, role, replaces, firstTurn) {
|
|
69845
69847
|
const done = Promise.withResolvers();
|
|
69846
69848
|
let ran = false;
|
|
69847
69849
|
const claim = () => {
|
|
@@ -69851,7 +69853,7 @@ function claimRoleAtFirstTurn(host, role, firstTurn) {
|
|
|
69851
69853
|
clearTimeout(bound);
|
|
69852
69854
|
(async () => {
|
|
69853
69855
|
try {
|
|
69854
|
-
await claimRoleAgainOnBusy(() => host.claimRole(role), role, {
|
|
69856
|
+
await claimRoleAgainOnBusy(() => host.claimRole(role, replaces), role, {
|
|
69855
69857
|
log: host.log,
|
|
69856
69858
|
firstDelayMs: host.roleClaimRetryFirstDelayMs,
|
|
69857
69859
|
signal: host.signal
|
|
@@ -69881,7 +69883,7 @@ async function claimRoleAgainOnBusy(claim, role, options) {
|
|
|
69881
69883
|
throw error;
|
|
69882
69884
|
if (options.maxAttempts !== undefined && attempt >= options.maxAttempts)
|
|
69883
69885
|
throw error;
|
|
69884
|
-
options.log(`claim of Envoy role ${role} was answered 503 at attempt ${attempt}
|
|
69886
|
+
options.log(`claim of Envoy role ${role} was answered 503 at attempt ${attempt}; claiming it again in ${wait} ms: ${messageFor(error)}`, error);
|
|
69885
69887
|
const waited = Promise.withResolvers();
|
|
69886
69888
|
const timer = setTimeout(waited.resolve, wait);
|
|
69887
69889
|
timer.unref?.();
|
|
@@ -70600,6 +70602,13 @@ function createPhaseHookEndpoint(deps) {
|
|
|
70600
70602
|
};
|
|
70601
70603
|
}
|
|
70602
70604
|
|
|
70605
|
+
// src/role-claim-warnings.ts
|
|
70606
|
+
function logRoleClaimWarnings(log, role, sessionID, warnings) {
|
|
70607
|
+
for (const warning of warnings) {
|
|
70608
|
+
log(`the Envoy listener warned about the claim of role ${role} for session ${sessionID}: ${warning}`);
|
|
70609
|
+
}
|
|
70610
|
+
}
|
|
70611
|
+
|
|
70603
70612
|
// src/legion-claim.ts
|
|
70604
70613
|
var PLUGIN_CONTRACT = daemonContract(package_default, import.meta.dir);
|
|
70605
70614
|
async function legionPane(env) {
|
|
@@ -70685,7 +70694,7 @@ function startLegionClaim(deps) {
|
|
|
70685
70694
|
setCapability: (registered) => {
|
|
70686
70695
|
capability = registered;
|
|
70687
70696
|
},
|
|
70688
|
-
claimRole: async (role) => {
|
|
70697
|
+
claimRole: async (role, replaces) => {
|
|
70689
70698
|
const deadline = Date.now() + roleWaitMs;
|
|
70690
70699
|
let waited = false;
|
|
70691
70700
|
for (;; ) {
|
|
@@ -70693,10 +70702,13 @@ function startLegionClaim(deps) {
|
|
|
70693
70702
|
sessionID,
|
|
70694
70703
|
role,
|
|
70695
70704
|
soft: true,
|
|
70696
|
-
clientInstanceID: deps.clientInstanceID
|
|
70705
|
+
clientInstanceID: deps.clientInstanceID,
|
|
70706
|
+
...replaces ? { previousSessionID: replaces } : {}
|
|
70697
70707
|
});
|
|
70698
|
-
if (claimed.claimed)
|
|
70708
|
+
if (claimed.claimed) {
|
|
70709
|
+
logRoleClaimWarnings(deps.log, role, sessionID, claimed.warnings);
|
|
70699
70710
|
break;
|
|
70711
|
+
}
|
|
70700
70712
|
if (claimed.holder !== sessionID) {
|
|
70701
70713
|
throw new Error(`Envoy role ${role} is held by live session ${claimed.holder}`);
|
|
70702
70714
|
}
|
|
@@ -72525,6 +72537,10 @@ function parseArguments(spec, input) {
|
|
|
72525
72537
|
function mcpResult(value) {
|
|
72526
72538
|
return { content: [{ type: "text", text: JSON.stringify(value) }] };
|
|
72527
72539
|
}
|
|
72540
|
+
function warnOnStderr(line) {
|
|
72541
|
+
process.stderr.write(`envoy-channel: ${line}
|
|
72542
|
+
`);
|
|
72543
|
+
}
|
|
72528
72544
|
function projectDirectory() {
|
|
72529
72545
|
return claudeProjectDirectory({ CLAUDE_PROJECT_DIR: process.env["CLAUDE_PROJECT_DIR"] }, process.cwd());
|
|
72530
72546
|
}
|
|
@@ -73126,8 +73142,9 @@ async function startChannelSession(options) {
|
|
|
73126
73142
|
if (!mayActOnRoleRecord(persisted.client_instance_id, options.clientInstanceID, heldRole !== undefined)) {
|
|
73127
73143
|
return "settled";
|
|
73128
73144
|
}
|
|
73145
|
+
const sessionID = identity.id;
|
|
73129
73146
|
const claim = await options.client.setRole({
|
|
73130
|
-
sessionID
|
|
73147
|
+
sessionID,
|
|
73131
73148
|
role: persisted.role,
|
|
73132
73149
|
soft: true,
|
|
73133
73150
|
previousSessionID: persisted.session_id,
|
|
@@ -73140,6 +73157,7 @@ async function startChannelSession(options) {
|
|
|
73140
73157
|
await rm5(previousFile, { force: true });
|
|
73141
73158
|
return "settled";
|
|
73142
73159
|
}
|
|
73160
|
+
logRoleClaimWarnings(warnOnStderr, persisted.role, sessionID, claim.warnings);
|
|
73143
73161
|
heldRole = persisted.role;
|
|
73144
73162
|
const currentFile = roleStateFile(options.stateDirectory, identity.id);
|
|
73145
73163
|
if (previousFile !== currentFile)
|
|
@@ -73182,8 +73200,9 @@ async function startChannelSession(options) {
|
|
|
73182
73200
|
fireRegained(role, "reregistered");
|
|
73183
73201
|
return;
|
|
73184
73202
|
}
|
|
73203
|
+
const sessionID = identity.id;
|
|
73185
73204
|
const result = await options.client.setRole({
|
|
73186
|
-
sessionID
|
|
73205
|
+
sessionID,
|
|
73187
73206
|
role,
|
|
73188
73207
|
soft: true,
|
|
73189
73208
|
clientInstanceID: options.clientInstanceID
|
|
@@ -73197,6 +73216,7 @@ async function startChannelSession(options) {
|
|
|
73197
73216
|
await refreshRoleRecord();
|
|
73198
73217
|
return;
|
|
73199
73218
|
}
|
|
73219
|
+
logRoleClaimWarnings(warnOnStderr, role, sessionID, result.warnings);
|
|
73200
73220
|
fireRegained(role, "reclaimed");
|
|
73201
73221
|
};
|
|
73202
73222
|
let roleTransferFailureReported = false;
|
|
@@ -73664,15 +73684,17 @@ async function executeEnvoyTool(runtime, name, input) {
|
|
|
73664
73684
|
}
|
|
73665
73685
|
case EnvoyToolOperation.setRole: {
|
|
73666
73686
|
const args = parseArguments(spec, input);
|
|
73687
|
+
const sessionID = identity.id;
|
|
73667
73688
|
const result = await runtime.client.setRole({
|
|
73668
|
-
sessionID
|
|
73689
|
+
sessionID,
|
|
73669
73690
|
role: args.role,
|
|
73670
73691
|
clientInstanceID: runtime.clientInstanceID
|
|
73671
73692
|
});
|
|
73672
73693
|
if (!result.claimed)
|
|
73673
73694
|
throw new Error(`role ${args.role} is held by ${result.holder}`);
|
|
73695
|
+
logRoleClaimWarnings(warnOnStderr, args.role, sessionID, result.warnings);
|
|
73674
73696
|
await runtime.session.rememberRole(args.role);
|
|
73675
|
-
return result.interest;
|
|
73697
|
+
return result.warnings.length === 0 ? result.interest : { ...result.interest, warnings: result.warnings };
|
|
73676
73698
|
}
|
|
73677
73699
|
case EnvoyToolOperation.getRole: {
|
|
73678
73700
|
const args = parseArguments(spec, input);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sjawhar/claude-envoy",
|
|
3
|
-
"version": "6.12.
|
|
3
|
+
"version": "6.12.6",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "Claude Code plugin for Legion's Envoy bus",
|
|
6
6
|
"type": "module",
|
|
@@ -45,6 +45,6 @@
|
|
|
45
45
|
"zod": "4.3.6"
|
|
46
46
|
},
|
|
47
47
|
"legion": {
|
|
48
|
-
"daemonApiVersion":
|
|
48
|
+
"daemonApiVersion": 285
|
|
49
49
|
}
|
|
50
50
|
}
|
|
@@ -149,6 +149,7 @@ import {
|
|
|
149
149
|
replayStateFile,
|
|
150
150
|
replayStateWriter,
|
|
151
151
|
} from "./replay-state"
|
|
152
|
+
import { logRoleClaimWarnings } from "./role-claim-warnings"
|
|
152
153
|
import {
|
|
153
154
|
pruneStaleSessionHandoffs,
|
|
154
155
|
pruneStaleSessionRoles,
|
|
@@ -478,6 +479,11 @@ export function mcpResult(value: unknown): {
|
|
|
478
479
|
return { content: [{ type: "text", text: JSON.stringify(value) }] }
|
|
479
480
|
}
|
|
480
481
|
|
|
482
|
+
/** Writes one line to the server's warning log, its stderr. */
|
|
483
|
+
function warnOnStderr(line: string): void {
|
|
484
|
+
process.stderr.write(`envoy-channel: ${line}\n`)
|
|
485
|
+
}
|
|
486
|
+
|
|
481
487
|
function projectDirectory(): string {
|
|
482
488
|
return claudeProjectDirectory(
|
|
483
489
|
{ CLAUDE_PROJECT_DIR: process.env["CLAUDE_PROJECT_DIR"] },
|
|
@@ -1592,8 +1598,9 @@ export async function startChannelSession(options: ChannelSessionOptions): Promi
|
|
|
1592
1598
|
) {
|
|
1593
1599
|
return "settled"
|
|
1594
1600
|
}
|
|
1601
|
+
const sessionID = identity.id
|
|
1595
1602
|
const claim = await options.client.setRole({
|
|
1596
|
-
sessionID
|
|
1603
|
+
sessionID,
|
|
1597
1604
|
role: persisted.role,
|
|
1598
1605
|
soft: true,
|
|
1599
1606
|
previousSessionID: persisted.session_id,
|
|
@@ -1604,6 +1611,7 @@ export async function startChannelSession(options: ChannelSessionOptions): Promi
|
|
|
1604
1611
|
if (claim.holder !== persisted.session_id) await rm(previousFile, { force: true })
|
|
1605
1612
|
return "settled"
|
|
1606
1613
|
}
|
|
1614
|
+
logRoleClaimWarnings(warnOnStderr, persisted.role, sessionID, claim.warnings)
|
|
1607
1615
|
heldRole = persisted.role
|
|
1608
1616
|
const currentFile = roleStateFile(options.stateDirectory, identity.id)
|
|
1609
1617
|
if (previousFile !== currentFile) await rm(previousFile, { force: true })
|
|
@@ -1682,8 +1690,9 @@ export async function startChannelSession(options: ChannelSessionOptions): Promi
|
|
|
1682
1690
|
if (afterOutage) fireRegained(role, "reregistered")
|
|
1683
1691
|
return
|
|
1684
1692
|
}
|
|
1693
|
+
const sessionID = identity.id
|
|
1685
1694
|
const result = await options.client.setRole({
|
|
1686
|
-
sessionID
|
|
1695
|
+
sessionID,
|
|
1687
1696
|
role,
|
|
1688
1697
|
soft: true,
|
|
1689
1698
|
clientInstanceID: options.clientInstanceID,
|
|
@@ -1697,6 +1706,7 @@ export async function startChannelSession(options: ChannelSessionOptions): Promi
|
|
|
1697
1706
|
await refreshRoleRecord()
|
|
1698
1707
|
return
|
|
1699
1708
|
}
|
|
1709
|
+
logRoleClaimWarnings(warnOnStderr, role, sessionID, result.warnings)
|
|
1700
1710
|
fireRegained(role, "reclaimed")
|
|
1701
1711
|
}
|
|
1702
1712
|
|
|
@@ -2450,14 +2460,20 @@ export async function executeEnvoyTool(
|
|
|
2450
2460
|
// The claim names this process, as every claim this server makes does: the listener
|
|
2451
2461
|
// records it as the role's holder, so a second process on this session id cannot be
|
|
2452
2462
|
// mistaken for the one holding the role.
|
|
2463
|
+
const sessionID = identity.id
|
|
2453
2464
|
const result = await runtime.client.setRole({
|
|
2454
|
-
sessionID
|
|
2465
|
+
sessionID,
|
|
2455
2466
|
role: args.role,
|
|
2456
2467
|
clientInstanceID: runtime.clientInstanceID,
|
|
2457
2468
|
})
|
|
2458
2469
|
if (!result.claimed) throw new Error(`role ${args.role} is held by ${result.holder}`)
|
|
2470
|
+
// The listener's warnings about the claim go to the log and, beside the interest row, to the
|
|
2471
|
+
// agent, which must know of a handover of the replaced session the claim did not make.
|
|
2472
|
+
logRoleClaimWarnings(warnOnStderr, args.role, sessionID, result.warnings)
|
|
2459
2473
|
await runtime.session.rememberRole(args.role)
|
|
2460
|
-
return result.
|
|
2474
|
+
return result.warnings.length === 0
|
|
2475
|
+
? result.interest
|
|
2476
|
+
: { ...result.interest, warnings: result.warnings }
|
|
2461
2477
|
}
|
|
2462
2478
|
case EnvoyToolOperation.getRole: {
|
|
2463
2479
|
const args = parseArguments(spec, input)
|
package/src/legion-claim.ts
CHANGED
|
@@ -14,6 +14,7 @@ import pkg from "../package.json" with { type: "json" }
|
|
|
14
14
|
import { configuredValue } from "./claude-session"
|
|
15
15
|
import type { ChannelSession } from "./envoy-channel-server"
|
|
16
16
|
import { paneReminderLog } from "./legion-phase-hook"
|
|
17
|
+
import { logRoleClaimWarnings } from "./role-claim-warnings"
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
20
|
* A Claude Code phase worker's claim on the Legion daemon, made by the MCP server Claude Code runs
|
|
@@ -286,10 +287,13 @@ export function startLegionClaim(deps: {
|
|
|
286
287
|
setCapability: (registered) => {
|
|
287
288
|
capability = registered
|
|
288
289
|
},
|
|
289
|
-
claimRole: async (role) => {
|
|
290
|
+
claimRole: async (role, replaces) => {
|
|
290
291
|
// Soft, so a role another live session holds is left with it, and naming this process,
|
|
291
292
|
// so the listener records the claim as this process's: a second `claude` that resumed
|
|
292
293
|
// this session id can then neither be taken for the holder nor release what it holds.
|
|
294
|
+
// `replaces`, the session the registration says this one replaces, is named as the
|
|
295
|
+
// claim's predecessor: the listener hands that session's unread direct and role messages
|
|
296
|
+
// to this one once the claim lands.
|
|
293
297
|
//
|
|
294
298
|
// A refusal naming this very session is that same claim seen from the other side: the
|
|
295
299
|
// process this pane was relaunched from renewed it at its last heartbeat, so it stands
|
|
@@ -306,8 +310,12 @@ export function startLegionClaim(deps: {
|
|
|
306
310
|
role,
|
|
307
311
|
soft: true,
|
|
308
312
|
clientInstanceID: deps.clientInstanceID,
|
|
313
|
+
...(replaces ? { previousSessionID: replaces } : {}),
|
|
309
314
|
})
|
|
310
|
-
if (claimed.claimed)
|
|
315
|
+
if (claimed.claimed) {
|
|
316
|
+
logRoleClaimWarnings(deps.log, role, sessionID, claimed.warnings)
|
|
317
|
+
break
|
|
318
|
+
}
|
|
311
319
|
if (claimed.holder !== sessionID) {
|
|
312
320
|
throw new Error(`Envoy role ${role} is held by live session ${claimed.holder}`)
|
|
313
321
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Logs each warning the Envoy listener answered a granted claim of `role` for `sessionID` with
|
|
3
|
+
* (`SetRoleResult.warnings`), one `log` line each, naming the role and the session: what the
|
|
4
|
+
* listener says about a claim that landed, such as a handover of the replaced session it did not
|
|
5
|
+
* make. Every claim the channel server makes logs them, whoever made it: a restore, a heartbeat,
|
|
6
|
+
* the Legion claim, or `envoy_role_set`, which also answers them to the agent.
|
|
7
|
+
*/
|
|
8
|
+
export function logRoleClaimWarnings(
|
|
9
|
+
log: (line: string) => void,
|
|
10
|
+
role: string,
|
|
11
|
+
sessionID: string,
|
|
12
|
+
warnings: readonly string[],
|
|
13
|
+
): void {
|
|
14
|
+
for (const warning of warnings) {
|
|
15
|
+
log(
|
|
16
|
+
`the Envoy listener warned about the claim of role ${role} for session ${sessionID}: ${warning}`,
|
|
17
|
+
)
|
|
18
|
+
}
|
|
19
|
+
}
|