@sjawhar/claude-envoy 2.35.1 → 2.37.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 +2 -1
- package/dist/dispatch.js +245 -35
- package/dist/envoy-channel.js +257 -44
- package/dist/session-hook.js +238 -32
- package/package.json +1 -1
- package/scripts/smoke-session-title.sh +11 -2
- package/skills/agent-secrets/SKILL.md +6 -4
- package/src/envoy-channel-server.ts +3 -3
- package/src/envoy-client.ts +17 -2
- package/src/subscription-topics.ts +2 -2
package/dist/session-hook.js
CHANGED
|
@@ -13633,17 +13633,18 @@ function isPictureType(mime) {
|
|
|
13633
13633
|
// ../contracts/src/subject.ts
|
|
13634
13634
|
var AGENT_TOPIC_PREFIX = "notifications.agent.";
|
|
13635
13635
|
var ROLE_TOPIC_PREFIX = "notifications.role.";
|
|
13636
|
+
var NO_PROJECT = "_";
|
|
13636
13637
|
var LEGION_NOTICE_TOPIC_PREFIX = "notifications.legion.";
|
|
13637
13638
|
var DISPATCH_TOPIC_PREFIX = "notifications.dispatch.";
|
|
13638
13639
|
var DISPATCH_ISSUE_TOPIC_PREFIX = `${DISPATCH_TOPIC_PREFIX}issue.`;
|
|
13639
13640
|
var DISPATCH_DOCUMENT_TOPIC_PREFIX = `${DISPATCH_TOPIC_PREFIX}document.`;
|
|
13640
|
-
function
|
|
13641
|
+
function legacyDispatchIssueSubject(issueKey, type) {
|
|
13641
13642
|
return `${DISPATCH_ISSUE_TOPIC_PREFIX}${issueKey}.${type}`;
|
|
13642
13643
|
}
|
|
13643
13644
|
function dispatchDocumentSubject(project, slug, type) {
|
|
13644
13645
|
return `${DISPATCH_DOCUMENT_TOPIC_PREFIX}${project}.${slug}.${type}`;
|
|
13645
13646
|
}
|
|
13646
|
-
function
|
|
13647
|
+
function legacyAgentSubject(session) {
|
|
13647
13648
|
return `${AGENT_TOPIC_PREFIX}${session}`;
|
|
13648
13649
|
}
|
|
13649
13650
|
var GHOSTWISPR_TOPIC_PREFIX = "notifications.ghostwispr.";
|
|
@@ -16756,6 +16757,95 @@ function canonicalRepo(owner, repo) {
|
|
|
16756
16757
|
}
|
|
16757
16758
|
// ../contracts/src/slack.ts
|
|
16758
16759
|
var SLACK_POST_TEXT_MAX = 4000;
|
|
16760
|
+
// ../contracts/src/subject-project.ts
|
|
16761
|
+
var EXCEPTION_PREFIX = "notifications.envoy.exceptions.";
|
|
16762
|
+
var KEPT_PREFIX = "notifications.envoy.kept.";
|
|
16763
|
+
function isLiteral(token) {
|
|
16764
|
+
return token !== undefined && token !== "" && token !== "*" && token !== ">";
|
|
16765
|
+
}
|
|
16766
|
+
function projectOfToken(token) {
|
|
16767
|
+
return token !== undefined && PROJECT_KEY_PATTERN.test(token) ? token : NO_PROJECT;
|
|
16768
|
+
}
|
|
16769
|
+
function issueProject(key) {
|
|
16770
|
+
const project = DISPATCH_KEY_PATTERN.exec(key)?.[1];
|
|
16771
|
+
return project !== undefined && PROJECT_KEY_PATTERN.test(project) ? project : undefined;
|
|
16772
|
+
}
|
|
16773
|
+
var LEGION_ROLE_TOKEN = /^legion-([a-z0-9]+)-[\s\S]/;
|
|
16774
|
+
function legionTokenProject(token) {
|
|
16775
|
+
return token !== undefined && isLegionProjectToken(token) ? projectOfToken(token.toUpperCase()) : NO_PROJECT;
|
|
16776
|
+
}
|
|
16777
|
+
function roleProject(role) {
|
|
16778
|
+
return legionTokenProject(LEGION_ROLE_TOKEN.exec(role)?.[1]);
|
|
16779
|
+
}
|
|
16780
|
+
function keptLane(topic) {
|
|
16781
|
+
if (!topic.startsWith(KEPT_PREFIX))
|
|
16782
|
+
return;
|
|
16783
|
+
const [kind, ...rest] = topic.slice(KEPT_PREFIX.length).split(".");
|
|
16784
|
+
return kind === "role" || kind === "cursor" ? { kind, rest } : undefined;
|
|
16785
|
+
}
|
|
16786
|
+
function canonicalTopic(topic) {
|
|
16787
|
+
const unchanged = { canonical: topic, legacy: false };
|
|
16788
|
+
if (topic.startsWith(DISPATCH_ISSUE_TOPIC_PREFIX)) {
|
|
16789
|
+
const rest = topic.slice(DISPATCH_ISSUE_TOPIC_PREFIX.length);
|
|
16790
|
+
const project = issueProject(rest.split(".")[0] ?? "");
|
|
16791
|
+
return project === undefined ? unchanged : { canonical: `${DISPATCH_ISSUE_TOPIC_PREFIX}${project}.${rest}`, legacy: true };
|
|
16792
|
+
}
|
|
16793
|
+
if (topic.startsWith(AGENT_TOPIC_PREFIX)) {
|
|
16794
|
+
const rest = topic.slice(AGENT_TOPIC_PREFIX.length).split(".");
|
|
16795
|
+
return rest.length === 1 && isLiteral(rest[0]) ? { canonical: `${AGENT_TOPIC_PREFIX}*.${rest[0]}`, legacy: true } : unchanged;
|
|
16796
|
+
}
|
|
16797
|
+
if (topic.startsWith(ROLE_TOPIC_PREFIX)) {
|
|
16798
|
+
const rest = topic.slice(ROLE_TOPIC_PREFIX.length).split(".");
|
|
16799
|
+
return rest.length === 1 && isLiteral(rest[0]) ? { canonical: `${ROLE_TOPIC_PREFIX}${roleProject(rest[0])}.${rest[0]}`, legacy: true } : unchanged;
|
|
16800
|
+
}
|
|
16801
|
+
if (topic.startsWith(EXCEPTION_PREFIX)) {
|
|
16802
|
+
const wrapped = canonicalTopic(topic.slice(EXCEPTION_PREFIX.length));
|
|
16803
|
+
return wrapped.legacy ? { canonical: `${EXCEPTION_PREFIX}${wrapped.canonical}`, legacy: true } : unchanged;
|
|
16804
|
+
}
|
|
16805
|
+
const kept = keptLane(topic);
|
|
16806
|
+
if (kept !== undefined && kept.rest.length === 1 && isLiteral(kept.rest[0])) {
|
|
16807
|
+
const role = kept.rest[0];
|
|
16808
|
+
return { canonical: `${KEPT_PREFIX}${kept.kind}.${roleProject(role)}.${role}`, legacy: true };
|
|
16809
|
+
}
|
|
16810
|
+
return unchanged;
|
|
16811
|
+
}
|
|
16812
|
+
function isProjectPosition(token) {
|
|
16813
|
+
return token !== undefined && (PROJECT_KEY_PATTERN.test(token) || token === NO_PROJECT || token === "*");
|
|
16814
|
+
}
|
|
16815
|
+
function legacyTwin(canonical) {
|
|
16816
|
+
if (canonical.startsWith(DISPATCH_ISSUE_TOPIC_PREFIX)) {
|
|
16817
|
+
const [project, key, ...rest] = canonical.slice(DISPATCH_ISSUE_TOPIC_PREFIX.length).split(".");
|
|
16818
|
+
if (key === undefined || project === undefined)
|
|
16819
|
+
return;
|
|
16820
|
+
const keyProject = issueProject(key);
|
|
16821
|
+
if (keyProject === undefined || project !== keyProject)
|
|
16822
|
+
return;
|
|
16823
|
+
return [`${DISPATCH_ISSUE_TOPIC_PREFIX}${key}`, ...rest].join(".");
|
|
16824
|
+
}
|
|
16825
|
+
for (const prefix of [AGENT_TOPIC_PREFIX, ROLE_TOPIC_PREFIX]) {
|
|
16826
|
+
if (canonical.startsWith(prefix)) {
|
|
16827
|
+
const rest = canonical.slice(prefix.length).split(".");
|
|
16828
|
+
return rest.length === 2 && isProjectPosition(rest[0]) && isLiteral(rest[1]) ? `${prefix}${rest[1]}` : undefined;
|
|
16829
|
+
}
|
|
16830
|
+
}
|
|
16831
|
+
if (canonical.startsWith(EXCEPTION_PREFIX)) {
|
|
16832
|
+
const twin = legacyTwin(canonical.slice(EXCEPTION_PREFIX.length));
|
|
16833
|
+
return twin === undefined ? undefined : `${EXCEPTION_PREFIX}${twin}`;
|
|
16834
|
+
}
|
|
16835
|
+
const kept = keptLane(canonical);
|
|
16836
|
+
if (kept !== undefined && kept.rest.length === 2 && isProjectPosition(kept.rest[0])) {
|
|
16837
|
+
const role = kept.rest[1];
|
|
16838
|
+
return isLiteral(role) ? `${KEPT_PREFIX}${kept.kind}.${role}` : undefined;
|
|
16839
|
+
}
|
|
16840
|
+
return;
|
|
16841
|
+
}
|
|
16842
|
+
function topicForms(topic) {
|
|
16843
|
+
const { canonical, legacy } = canonicalTopic(topic);
|
|
16844
|
+
if (legacy)
|
|
16845
|
+
return [topic, canonical];
|
|
16846
|
+
const twin = legacyTwin(topic);
|
|
16847
|
+
return twin === undefined ? [topic] : [topic, twin];
|
|
16848
|
+
}
|
|
16759
16849
|
// ../contracts/src/tool-schema.ts
|
|
16760
16850
|
function overCapMessage(length, max) {
|
|
16761
16851
|
return `is ${length - max} characters over the ${max}-character limit (${length}/${max})`;
|
|
@@ -17485,7 +17575,7 @@ function ownerTitle(owner) {
|
|
|
17485
17575
|
return "";
|
|
17486
17576
|
}
|
|
17487
17577
|
function issueTopic(key) {
|
|
17488
|
-
return { label: key, topic:
|
|
17578
|
+
return { label: key, topic: legacyDispatchIssueSubject(key, ">") };
|
|
17489
17579
|
}
|
|
17490
17580
|
function documentTopicOf(project, slug) {
|
|
17491
17581
|
return {
|
|
@@ -18970,14 +19060,15 @@ class DispatchClient {
|
|
|
18970
19060
|
}
|
|
18971
19061
|
async#sendPresenting(method, url, body, accept, signal, key) {
|
|
18972
19062
|
const headers = { Accept: accept };
|
|
18973
|
-
|
|
19063
|
+
const limit = signal === undefined ? this.#signal : AbortSignal.any([this.#signal, signal]);
|
|
19064
|
+
let presented = await this.#credential.headers(method, url, undefined, limit);
|
|
18974
19065
|
if (body !== undefined)
|
|
18975
19066
|
headers["Content-Type"] = body.type;
|
|
18976
19067
|
if (key === undefined) {
|
|
18977
19068
|
return this.fetchImpl(url, {
|
|
18978
19069
|
method,
|
|
18979
19070
|
headers: { ...headers, ...presented },
|
|
18980
|
-
signal:
|
|
19071
|
+
signal: limit,
|
|
18981
19072
|
...body === undefined ? {} : { body: body.content }
|
|
18982
19073
|
});
|
|
18983
19074
|
}
|
|
@@ -18997,7 +19088,7 @@ class DispatchClient {
|
|
|
18997
19088
|
let thrown;
|
|
18998
19089
|
try {
|
|
18999
19090
|
if (attempt > 1)
|
|
19000
|
-
presented = await this.#credential.headers(method, url);
|
|
19091
|
+
presented = await this.#credential.headers(method, url, undefined, limit);
|
|
19001
19092
|
const sent = { ...headers, ...presented };
|
|
19002
19093
|
answer = await writeAnswer(await this.#attempt(url, method, sent, body, silenceMs), key);
|
|
19003
19094
|
if (answer.echoed)
|
|
@@ -19100,10 +19191,14 @@ class DispatchClient {
|
|
|
19100
19191
|
async#probeKeyedLayer() {
|
|
19101
19192
|
try {
|
|
19102
19193
|
const probe = `${this.#baseUrl}/healthz`;
|
|
19194
|
+
const limit = AbortSignal.any([this.#signal, AbortSignal.timeout(KEY_LAYER_PROBE_MS)]);
|
|
19103
19195
|
const response = await this.fetchImpl(probe, {
|
|
19104
19196
|
method: "GET",
|
|
19105
|
-
headers: {
|
|
19106
|
-
|
|
19197
|
+
headers: {
|
|
19198
|
+
Accept: "application/json",
|
|
19199
|
+
...await this.#credential.headers("GET", probe, undefined, limit)
|
|
19200
|
+
},
|
|
19201
|
+
signal: limit
|
|
19107
19202
|
});
|
|
19108
19203
|
if (!isJson(response))
|
|
19109
19204
|
return false;
|
|
@@ -19982,7 +20077,7 @@ function renderInbound(raw, sessionID, subject, wholeBody) {
|
|
|
19982
20077
|
...dispatchIssue === undefined ? [] : [dispatchIssue]
|
|
19983
20078
|
].join(", ") || undefined;
|
|
19984
20079
|
const rendered = {
|
|
19985
|
-
...envelope.topic
|
|
20080
|
+
...envelope.topic !== undefined && topicForms(envelope.topic).includes(legacyAgentSubject(sessionID)) ? { to: `you (${sessionID})` } : {},
|
|
19986
20081
|
from: senderLabel(envelope),
|
|
19987
20082
|
at: inboundTimestamp(envelope.issued_at),
|
|
19988
20083
|
id: envelope.event_id ?? "unknown",
|
|
@@ -26698,6 +26793,7 @@ var SUBJECT_TOKEN_TYPE_GOOGLE = "urn:envoy:params:oauth:token-type:google-identi
|
|
|
26698
26793
|
var SUBJECT_TOKEN_TYPE_PERSON = "urn:envoy:params:oauth:token-type:person-google-identity";
|
|
26699
26794
|
var ACTOR_TOKEN_TYPE_MACHINE = "urn:envoy:params:oauth:token-type:machine-google-identity";
|
|
26700
26795
|
var TOKEN_TYPE_DPOP = "DPoP";
|
|
26796
|
+
var POD_SESSION_NOT_REGISTERED = "pod_session_not_registered";
|
|
26701
26797
|
|
|
26702
26798
|
// ../broker-client/src/metadata-identity.ts
|
|
26703
26799
|
var METADATA_HOST_VAR = "GCE_METADATA_HOST";
|
|
@@ -28128,6 +28224,26 @@ var DEFAULT_RENEW_BEFORE_MS = 5 * 60000;
|
|
|
28128
28224
|
var TOO_MANY_REQUESTS = 429;
|
|
28129
28225
|
var INVALID_DPOP_PROOF = "invalid_dpop_proof";
|
|
28130
28226
|
var USE_DPOP_NONCE = "use_dpop_nonce";
|
|
28227
|
+
var INVALID_GRANT = "invalid_grant";
|
|
28228
|
+
var UNREGISTERED_FIRST_WAIT_MS = 15000;
|
|
28229
|
+
var UNREGISTERED_MAX_WAIT_MS = 5 * 60000;
|
|
28230
|
+
var UNREGISTERED_LOG_EVERY_MS = 30 * 60000;
|
|
28231
|
+
function sleep2(ms, signal) {
|
|
28232
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
28233
|
+
if (signal?.aborted) {
|
|
28234
|
+
resolve();
|
|
28235
|
+
return promise;
|
|
28236
|
+
}
|
|
28237
|
+
const done = () => {
|
|
28238
|
+
clearTimeout(timer);
|
|
28239
|
+
signal?.removeEventListener("abort", done);
|
|
28240
|
+
resolve();
|
|
28241
|
+
};
|
|
28242
|
+
const timer = setTimeout(done, ms);
|
|
28243
|
+
timer.unref();
|
|
28244
|
+
signal?.addEventListener("abort", done, { once: true });
|
|
28245
|
+
return promise;
|
|
28246
|
+
}
|
|
28131
28247
|
|
|
28132
28248
|
class BrokerRefusedError extends Error {
|
|
28133
28249
|
status;
|
|
@@ -28141,7 +28257,19 @@ class BrokerRefusedError extends Error {
|
|
|
28141
28257
|
this.name = "BrokerRefusedError";
|
|
28142
28258
|
}
|
|
28143
28259
|
get permanent() {
|
|
28144
|
-
return this.status !== TOO_MANY_REQUESTS && this.code !== INVALID_DPOP_PROOF && this.code !== USE_DPOP_NONCE;
|
|
28260
|
+
return this.status !== TOO_MANY_REQUESTS && this.code !== INVALID_DPOP_PROOF && this.code !== USE_DPOP_NONCE && !this.podSessionUnregistered;
|
|
28261
|
+
}
|
|
28262
|
+
get podSessionUnregistered() {
|
|
28263
|
+
return this.code === INVALID_GRANT && this.description.startsWith(`${POD_SESSION_NOT_REGISTERED}:`);
|
|
28264
|
+
}
|
|
28265
|
+
}
|
|
28266
|
+
|
|
28267
|
+
class RegistrationPendingError extends Error {
|
|
28268
|
+
session;
|
|
28269
|
+
constructor(session, refusal) {
|
|
28270
|
+
super(`the secrets broker has no registration for this pod's session ${session} yet, and the trade is being retried in the background until it lands (${refusal.description})`, { cause: refusal });
|
|
28271
|
+
this.session = session;
|
|
28272
|
+
this.name = "RegistrationPendingError";
|
|
28145
28273
|
}
|
|
28146
28274
|
}
|
|
28147
28275
|
|
|
@@ -28190,10 +28318,16 @@ class BrokerTokenClient {
|
|
|
28190
28318
|
#launcherCredential;
|
|
28191
28319
|
#renewBeforeMs;
|
|
28192
28320
|
#now;
|
|
28321
|
+
#sleep;
|
|
28322
|
+
#log;
|
|
28193
28323
|
#fetch;
|
|
28194
28324
|
#nonce = "";
|
|
28195
28325
|
#held = null;
|
|
28196
28326
|
#trading = null;
|
|
28327
|
+
#waiters = new Set;
|
|
28328
|
+
#pending = null;
|
|
28329
|
+
#wake = null;
|
|
28330
|
+
#closed = new AbortController;
|
|
28197
28331
|
constructor(options) {
|
|
28198
28332
|
const brokerUrl = withoutTrailingSlashes(options.brokerUrl.trim());
|
|
28199
28333
|
if (brokerUrl === "")
|
|
@@ -28207,6 +28341,8 @@ class BrokerTokenClient {
|
|
|
28207
28341
|
this.#launcherCredential = options.launcherCredential ?? true;
|
|
28208
28342
|
this.#renewBeforeMs = options.renewBeforeMs ?? DEFAULT_RENEW_BEFORE_MS;
|
|
28209
28343
|
this.#now = options.now ?? Date.now;
|
|
28344
|
+
this.#sleep = options.sleep ?? sleep2;
|
|
28345
|
+
this.#log = options.log ?? console.warn;
|
|
28210
28346
|
this.#fetch = options.fetch ?? fetch;
|
|
28211
28347
|
}
|
|
28212
28348
|
get key() {
|
|
@@ -28219,31 +28355,95 @@ class BrokerTokenClient {
|
|
|
28219
28355
|
const held = this.#held;
|
|
28220
28356
|
if (held !== null && this.#now() < held.expiresAt.getTime() - this.#renewBeforeMs)
|
|
28221
28357
|
return held;
|
|
28222
|
-
if (this.#trading
|
|
28223
|
-
|
|
28224
|
-
|
|
28225
|
-
|
|
28226
|
-
|
|
28227
|
-
|
|
28228
|
-
}
|
|
28358
|
+
if (this.#trading === null) {
|
|
28359
|
+
const started = this.#renew();
|
|
28360
|
+
this.#trading = started;
|
|
28361
|
+
started.then((token) => this.#settled(started, (waiter) => waiter.resolve(token)), (error) => this.#settled(started, (waiter) => waiter.reject(error)));
|
|
28362
|
+
} else {
|
|
28363
|
+
this.#wake?.();
|
|
28364
|
+
}
|
|
28365
|
+
return await this.#joined(signal);
|
|
28366
|
+
}
|
|
28367
|
+
#settled(started, tell) {
|
|
28368
|
+
if (this.#trading === started)
|
|
28229
28369
|
this.#trading = null;
|
|
28370
|
+
const waiters = [...this.#waiters];
|
|
28371
|
+
this.#waiters.clear();
|
|
28372
|
+
for (const waiter of waiters)
|
|
28373
|
+
tell(waiter);
|
|
28374
|
+
}
|
|
28375
|
+
#joined(signal) {
|
|
28376
|
+
const { promise, resolve, reject } = Promise.withResolvers();
|
|
28377
|
+
const stop = () => {
|
|
28378
|
+
this.#waiters.delete(waiter);
|
|
28379
|
+
const pending = this.#pending;
|
|
28380
|
+
reject(pending === null ? signal?.reason : new RegistrationPendingError(this.#session, pending));
|
|
28381
|
+
};
|
|
28382
|
+
const waiter = {
|
|
28383
|
+
resolve: (token) => {
|
|
28384
|
+
signal?.removeEventListener("abort", stop);
|
|
28385
|
+
resolve(token);
|
|
28386
|
+
},
|
|
28387
|
+
reject: (error) => {
|
|
28388
|
+
signal?.removeEventListener("abort", stop);
|
|
28389
|
+
reject(error);
|
|
28390
|
+
}
|
|
28391
|
+
};
|
|
28392
|
+
if (signal?.aborted) {
|
|
28393
|
+
stop();
|
|
28394
|
+
return promise;
|
|
28230
28395
|
}
|
|
28396
|
+
this.#waiters.add(waiter);
|
|
28397
|
+
signal?.addEventListener("abort", stop, { once: true });
|
|
28398
|
+
return promise;
|
|
28399
|
+
}
|
|
28400
|
+
close() {
|
|
28401
|
+
this.#closed.abort();
|
|
28231
28402
|
}
|
|
28232
28403
|
drop() {
|
|
28233
28404
|
this.#held = null;
|
|
28234
28405
|
}
|
|
28235
|
-
async#renew(
|
|
28406
|
+
async#renew() {
|
|
28407
|
+
const closed = this.#closed.signal;
|
|
28408
|
+
let wait = UNREGISTERED_FIRST_WAIT_MS;
|
|
28409
|
+
let since = null;
|
|
28410
|
+
let logged = null;
|
|
28236
28411
|
try {
|
|
28237
|
-
|
|
28238
|
-
|
|
28239
|
-
|
|
28240
|
-
|
|
28241
|
-
|
|
28242
|
-
|
|
28243
|
-
|
|
28412
|
+
while (true) {
|
|
28413
|
+
try {
|
|
28414
|
+
const token = await this.#trade(closed);
|
|
28415
|
+
this.#held = token;
|
|
28416
|
+
return token;
|
|
28417
|
+
} catch (error) {
|
|
28418
|
+
const held = this.#held;
|
|
28419
|
+
if (!isFinalRefusal(error) && held !== null && this.#now() < held.expiresAt.getTime()) {
|
|
28420
|
+
return held;
|
|
28421
|
+
}
|
|
28422
|
+
this.#held = null;
|
|
28423
|
+
const unregistered = error instanceof BrokerRefusedError && error.podSessionUnregistered;
|
|
28424
|
+
if (!unregistered || closed.aborted)
|
|
28425
|
+
throw error;
|
|
28426
|
+
this.#pending = error;
|
|
28427
|
+
const now = this.#now();
|
|
28428
|
+
since ??= now;
|
|
28429
|
+
if (logged === null || now - logged >= UNREGISTERED_LOG_EVERY_MS) {
|
|
28430
|
+
logged = now;
|
|
28431
|
+
this.#log(`the secrets broker has no registration for this pod's session ${this.#session} yet (${Math.round((now - since) / 1000)} s so far); trading ${this.describe()} again until it lands`);
|
|
28432
|
+
}
|
|
28433
|
+
const woken = new AbortController;
|
|
28434
|
+
this.#wake = () => woken.abort();
|
|
28435
|
+
try {
|
|
28436
|
+
await this.#sleep(wait, AbortSignal.any([closed, woken.signal]));
|
|
28437
|
+
} finally {
|
|
28438
|
+
this.#wake = null;
|
|
28439
|
+
}
|
|
28440
|
+
if (closed.aborted)
|
|
28441
|
+
throw error;
|
|
28442
|
+
wait = Math.min(wait * 2, UNREGISTERED_MAX_WAIT_MS);
|
|
28443
|
+
}
|
|
28244
28444
|
}
|
|
28245
|
-
|
|
28246
|
-
|
|
28445
|
+
} finally {
|
|
28446
|
+
this.#pending = null;
|
|
28247
28447
|
}
|
|
28248
28448
|
}
|
|
28249
28449
|
async#trade(signal) {
|
|
@@ -28349,7 +28549,7 @@ class BrokerTokenClient {
|
|
|
28349
28549
|
|
|
28350
28550
|
// ../broker-client/src/person-identity.ts
|
|
28351
28551
|
var ISSUER_TIMEOUT_SECONDS = 30;
|
|
28352
|
-
var
|
|
28552
|
+
var INVALID_GRANT2 = "invalid_grant";
|
|
28353
28553
|
function issuerSaid(error) {
|
|
28354
28554
|
if (error instanceof ResponseBodyError) {
|
|
28355
28555
|
const description = error.error_description ?? "";
|
|
@@ -28406,7 +28606,7 @@ function personIdentity(record, flow, options = {}) {
|
|
|
28406
28606
|
config[customFetch2] = through(signal);
|
|
28407
28607
|
answered = await refreshTokenGrant(config, refreshToken);
|
|
28408
28608
|
} catch (error) {
|
|
28409
|
-
if (error instanceof ResponseBodyError && error.error ===
|
|
28609
|
+
if (error instanceof ResponseBodyError && error.error === INVALID_GRANT2) {
|
|
28410
28610
|
throw new SignInEndedError(flow.issuer, person, { cause: error });
|
|
28411
28611
|
}
|
|
28412
28612
|
throw new Error(`renew ${person}'s sign-in at ${flow.issuer}: ${issuerSaid(error)}`);
|
|
@@ -28688,8 +28888,14 @@ function brokerRouteConfigured(env) {
|
|
|
28688
28888
|
return { traded: true };
|
|
28689
28889
|
}
|
|
28690
28890
|
var CLIENTS = new Map;
|
|
28891
|
+
function closeAll(entries) {
|
|
28892
|
+
for (const held of entries?.values() ?? [])
|
|
28893
|
+
held.made?.client?.close();
|
|
28894
|
+
}
|
|
28691
28895
|
function forgetBrokerSession(session) {
|
|
28692
|
-
|
|
28896
|
+
const key = session.trim();
|
|
28897
|
+
closeAll(CLIENTS.get(key));
|
|
28898
|
+
CLIENTS.delete(key);
|
|
28693
28899
|
}
|
|
28694
28900
|
function signInName(record) {
|
|
28695
28901
|
return `${record.person}\x00${record.thumbprint}`;
|
|
@@ -28751,7 +28957,7 @@ function brokerCredential(env, session) {
|
|
|
28751
28957
|
const own = (acting) => (acting ?? "").trim() || sessionName(session);
|
|
28752
28958
|
return {
|
|
28753
28959
|
scheme: "DPoP",
|
|
28754
|
-
async headers(method, url, acting) {
|
|
28960
|
+
async headers(method, url, acting, signal) {
|
|
28755
28961
|
const { entry, made } = await clientFor(env, own(acting));
|
|
28756
28962
|
const { client } = made;
|
|
28757
28963
|
if (client === undefined) {
|
|
@@ -28759,7 +28965,7 @@ function brokerCredential(env, session) {
|
|
|
28759
28965
|
}
|
|
28760
28966
|
let token;
|
|
28761
28967
|
try {
|
|
28762
|
-
token = await client.token();
|
|
28968
|
+
token = await client.token(signal);
|
|
28763
28969
|
} catch (error) {
|
|
28764
28970
|
if (made.signIn !== "" && isFinalRefusal(error))
|
|
28765
28971
|
entry.refused.set(made.signIn, error);
|
package/package.json
CHANGED
|
@@ -46,15 +46,24 @@ fail() {
|
|
|
46
46
|
exit 1
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
# nats-server is a `go install` away and lands in GOPATH's bin, which is often off PATH.
|
|
49
|
+
# nats-server is a `go install` away and lands in GOPATH's bin, which is often off PATH. The
|
|
50
|
+
# listener refuses a nats-server below natsversion's floor, so install the hub's v2.15.1.
|
|
50
51
|
if ! command -v nats-server >/dev/null 2>&1; then
|
|
51
52
|
PATH="$(go env GOPATH 2>/dev/null)/bin:${PATH}"
|
|
52
53
|
export PATH
|
|
53
54
|
fi
|
|
54
55
|
for tool in bun curl jq go nats-server; do
|
|
55
56
|
command -v "$tool" >/dev/null 2>&1 ||
|
|
56
|
-
fail "$tool is required (nats-server: go install github.com/nats-io/nats-server/v2@v2.
|
|
57
|
+
fail "$tool is required (nats-server: go install github.com/nats-io/nats-server/v2@v2.15.1)"
|
|
57
58
|
done
|
|
59
|
+
# Whether the listener takes this nats-server is natsversion's own rule, which natsfloor answers
|
|
60
|
+
# (packages/envoy/natsversion/cmd/natsfloor), so this smoke holds no copy of it.
|
|
61
|
+
nats_version=$(nats-server --version 2>/dev/null | sed -n 's/^nats-server: \(v\{0,1\}[0-9][^[:space:]]*\).*$/\1/p')
|
|
62
|
+
[[ -n "$nats_version" ]] || fail "could not read nats-server's version from '$(nats-server --version 2>&1)'"
|
|
63
|
+
floor_verdict=$(go run -C "${repo_root}/packages/envoy" ./natsversion/cmd/natsfloor "$nats_version") ||
|
|
64
|
+
fail "could not ask natsversion whether the listener takes nats-server ${nats_version}"
|
|
65
|
+
[[ "$floor_verdict" == taken$'\t'* ]] ||
|
|
66
|
+
fail "$(command -v nats-server): ${floor_verdict##*$'\t'}: go install github.com/nats-io/nats-server/v2@v2.15.1"
|
|
58
67
|
|
|
59
68
|
workdir="$(mktemp -d /tmp/claude-session-title.XXXXXX)"
|
|
60
69
|
readonly workdir
|
|
@@ -100,11 +100,13 @@ A refusal comes from the proxy, not from the service:
|
|
|
100
100
|
- An HTTP error naming the rule that refused it: a TLS name or `Host` that is not the host the
|
|
101
101
|
command asked for, a method or a path outside the entry's `allow`, a path with a `.` or `..`
|
|
102
102
|
segment, an `X-HTTP-Method-Override`, `X-HTTP-Method` or `X-Method-Override` header where the
|
|
103
|
-
entry lists methods,
|
|
103
|
+
entry lists methods, a `CONNECT` or an `h2c` upgrade inside the proxied connection, plain
|
|
104
|
+
`http://` to a host an entry binds, or a private address. gRPC clients work through the proxy,
|
|
105
|
+
and a gRPC refusal shows the same text in its error message.
|
|
104
106
|
|
|
105
|
-
- `407` once the grant ends, on every call to any host. A
|
|
106
|
-
|
|
107
|
-
idle limit instead.
|
|
107
|
+
- `407` once the grant ends, on every call to any host. A call still running at that moment (a
|
|
108
|
+
WebSocket, a gRPC stream, a long poll) is ended with the grant. A tunnel to a host no entry binds
|
|
109
|
+
carries no value, so it runs to its idle limit instead.
|
|
108
110
|
|
|
109
111
|
- `503` when the broker could not read the grant at all. The grant has not ended and the call
|
|
110
112
|
can be made again.
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type Stats, unwatchFile, watchFile } from "node:fs"
|
|
2
2
|
import { rm } from "node:fs/promises"
|
|
3
3
|
import {
|
|
4
|
-
agentSubject,
|
|
5
4
|
DELIVERY_CAPABILITIES,
|
|
6
5
|
type DeliveryCapability,
|
|
6
|
+
legacyAgentSubject,
|
|
7
7
|
ROLE_TOPIC_PREFIX,
|
|
8
8
|
zodSchemaApi,
|
|
9
9
|
} from "@legion/contracts"
|
|
@@ -624,7 +624,7 @@ export function createChannelDelivery(input: {
|
|
|
624
624
|
*/
|
|
625
625
|
export async function startChannelSession(options: ChannelSessionOptions): Promise<ChannelSession> {
|
|
626
626
|
const { identity } = options
|
|
627
|
-
let directSubject =
|
|
627
|
+
let directSubject = legacyAgentSubject(identity.id)
|
|
628
628
|
/**
|
|
629
629
|
* What this session does with a person's direct messages, for the id now bound: the record is
|
|
630
630
|
* kept per session id (`./user-turn-state`), so a `/clear` builds another one. Undefined until
|
|
@@ -1359,7 +1359,7 @@ export async function startChannelSession(options: ChannelSessionOptions): Promi
|
|
|
1359
1359
|
if (next === undefined || next === identity.id) return
|
|
1360
1360
|
const previous = identity.id
|
|
1361
1361
|
const previousSubject = directSubject
|
|
1362
|
-
const nextSubject =
|
|
1362
|
+
const nextSubject = legacyAgentSubject(next)
|
|
1363
1363
|
followedTopics.follow(nextSubject)
|
|
1364
1364
|
try {
|
|
1365
1365
|
// Bounded: this runs inside the registry chain, and a flush on a stalled NATS
|
package/src/envoy-client.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { RequestCredential } from "@legion/envoy-client/bearer"
|
|
2
2
|
import ky from "ky"
|
|
3
3
|
|
|
4
|
+
/** How long one send may take, the credential's trade included. */
|
|
5
|
+
const SEND_TIMEOUT_MS = 5_000
|
|
6
|
+
|
|
4
7
|
export type SendEnvoyMessageOptions = {
|
|
5
8
|
readonly baseUrl: string
|
|
6
9
|
/** What the send presents (`EnabledEnvoySettings.credential`): the listener's bearer, this
|
|
@@ -9,11 +12,22 @@ export type SendEnvoyMessageOptions = {
|
|
|
9
12
|
readonly credential: RequestCredential | undefined
|
|
10
13
|
readonly targetSession: string
|
|
11
14
|
readonly message: string
|
|
15
|
+
/** Ends the send early, beside its own {@link SEND_TIMEOUT_MS}. */
|
|
16
|
+
readonly signal?: AbortSignal | undefined
|
|
12
17
|
}
|
|
13
18
|
|
|
19
|
+
/**
|
|
20
|
+
* Sends one direct message. One deadline bounds the whole send, and the credential is given it
|
|
21
|
+
* too (`RequestCredential.headers`): a broker credential waiting on a pod's missing registration
|
|
22
|
+
* stops at it, naming the session, while its trade goes on in the background.
|
|
23
|
+
*/
|
|
14
24
|
export async function sendEnvoyMessage(options: SendEnvoyMessageOptions): Promise<void> {
|
|
15
25
|
const url = new URL("/v1/messages/send", options.baseUrl)
|
|
16
|
-
const
|
|
26
|
+
const timeout = AbortSignal.timeout(SEND_TIMEOUT_MS)
|
|
27
|
+
const deadline =
|
|
28
|
+
options.signal === undefined ? timeout : AbortSignal.any([options.signal, timeout])
|
|
29
|
+
const headers =
|
|
30
|
+
(await options.credential?.headers("POST", url.toString(), undefined, deadline)) ?? {}
|
|
17
31
|
await ky.post(url, {
|
|
18
32
|
json: {
|
|
19
33
|
target_session: options.targetSession,
|
|
@@ -21,6 +35,7 @@ export async function sendEnvoyMessage(options: SendEnvoyMessageOptions): Promis
|
|
|
21
35
|
},
|
|
22
36
|
headers,
|
|
23
37
|
retry: 0,
|
|
24
|
-
timeout:
|
|
38
|
+
timeout: false,
|
|
39
|
+
signal: deadline,
|
|
25
40
|
})
|
|
26
41
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { legacyAgentSubject } from "@legion/contracts"
|
|
2
2
|
import { expandSubscriptionTopics } from "@legion/envoy-client/transport"
|
|
3
3
|
|
|
4
4
|
export type SubscriptionTopicsOptions = {
|
|
@@ -12,5 +12,5 @@ export function subscriptionTopics(options: SubscriptionTopicsOptions): readonly
|
|
|
12
12
|
.map((topic) => topic.trim())
|
|
13
13
|
.filter((topic) => topic.length > 0)
|
|
14
14
|
|
|
15
|
-
return expandSubscriptionTopics([
|
|
15
|
+
return expandSubscriptionTopics([legacyAgentSubject(options.sessionId), ...(additional ?? [])])
|
|
16
16
|
}
|