@sjawhar/pi-envoy 15.6.1 → 16.0.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/dist/envoy.js
CHANGED
|
@@ -37959,7 +37959,7 @@ var envoyToolSpecs = [
|
|
|
37959
37959
|
},
|
|
37960
37960
|
{
|
|
37961
37961
|
name: "envoy_publish",
|
|
37962
|
-
description: `Publish an Envoy message to a notifications. topic. ${STORED_DELIVERY} A role or built-in topic is delivered as its guide says; a role message errs when its holder did not confirm it within the listener's window. A team or ad-hoc topic (such as notifications.team.deploy-squad.all) reaches every session subscribed to it when you publish, and is not kept for a session that subscribes later. The listener confirms it with each other session that holds its own NATS connection and registered the topic, and errs naming each session that did not confirm; a session that stopped without unregistering stays registered for up to 5 minutes and is named in that time, and a named session is not a failed delivery to the other sessions. A session that holds its own NATS connection receives such a live topic directly, yours included
|
|
37962
|
+
description: `Publish an Envoy message to a notifications. topic. ${STORED_DELIVERY} A role or built-in topic is delivered as its guide says; a role message errs when its holder did not confirm it within the listener's window. A team or ad-hoc topic (such as notifications.team.deploy-squad.all) reaches every session subscribed to it when you publish, and is not kept for a session that subscribes later. The listener confirms it with each other session that holds its own NATS connection and registered the topic, and errs naming each session that did not confirm; a session that stopped without unregistering stays registered for up to 5 minutes and is named in that time, and a named session is not a failed delivery to the other sessions. A session that holds its own NATS connection receives such a live topic directly, yours included. ${DELIVERY_CONTRACT}`,
|
|
37963
37963
|
arguments: (schema) => ({ topic: schema.string(), ...messageArguments(schema) }),
|
|
37964
37964
|
operation: EnvoyToolOperation.publish
|
|
37965
37965
|
},
|
|
@@ -38327,7 +38327,7 @@ var import_nats2 = __toESM(require_mod4(), 1);
|
|
|
38327
38327
|
|
|
38328
38328
|
// package.json
|
|
38329
38329
|
var name = "@sjawhar/pi-envoy";
|
|
38330
|
-
var version2 = "
|
|
38330
|
+
var version2 = "16.0.0";
|
|
38331
38331
|
var package_default = {
|
|
38332
38332
|
name,
|
|
38333
38333
|
version: version2,
|
|
@@ -44768,6 +44768,8 @@ ${REPLAYED_BTW_NOTE}`, "inert", identity, claim);
|
|
|
44768
44768
|
let shuttingDown = false;
|
|
44769
44769
|
const intentionallyClosed = new Set;
|
|
44770
44770
|
const awaitingRetry = new Set;
|
|
44771
|
+
const SUBSCRIBE_FLUSH_TIMEOUT_MS = 1e4;
|
|
44772
|
+
const unconfirmed = new Map;
|
|
44771
44773
|
const closeIntentionally = (topic) => {
|
|
44772
44774
|
const subscription = subscriptions.get(topic);
|
|
44773
44775
|
if (subscription === undefined) {
|
|
@@ -44816,7 +44818,7 @@ ${REPLAYED_BTW_NOTE}`, "inert", identity, claim);
|
|
|
44816
44818
|
awaitingRetry.add(topic);
|
|
44817
44819
|
setTimeout(() => {
|
|
44818
44820
|
awaitingRetry.delete(topic);
|
|
44819
|
-
if (shuttingDown || subscriptions.has(topic))
|
|
44821
|
+
if (shuttingDown || subscriptions.has(topic) && !unconfirmed.has(topic))
|
|
44820
44822
|
return;
|
|
44821
44823
|
if (intentionallyClosed.delete(topic))
|
|
44822
44824
|
return;
|
|
@@ -44828,19 +44830,62 @@ ${REPLAYED_BTW_NOTE}`, "inert", identity, claim);
|
|
|
44828
44830
|
};
|
|
44829
44831
|
retry(RESUBSCRIBE_DELAY_MS);
|
|
44830
44832
|
};
|
|
44833
|
+
const within = async (promise, ms, what) => {
|
|
44834
|
+
const expired = Promise.withResolvers();
|
|
44835
|
+
const timer = setTimeout(() => expired.reject(new Error(`${what} timed out after ${ms} ms`)), ms);
|
|
44836
|
+
try {
|
|
44837
|
+
return await Promise.race([promise, expired.promise]);
|
|
44838
|
+
} finally {
|
|
44839
|
+
clearTimeout(timer);
|
|
44840
|
+
}
|
|
44841
|
+
};
|
|
44831
44842
|
const subscribe = async (topic, connect = ensureConnection) => {
|
|
44832
|
-
const subjects = expandSubscriptionTopics([topic])
|
|
44833
|
-
|
|
44843
|
+
const subjects = expandSubscriptionTopics([topic]);
|
|
44844
|
+
const fresh = subjects.filter((candidate) => !subscriptions.has(candidate));
|
|
44845
|
+
const confirming = subjects.filter((candidate) => !subscriptions.has(candidate) || unconfirmed.has(candidate));
|
|
44846
|
+
if (confirming.length === 0)
|
|
44834
44847
|
return false;
|
|
44835
44848
|
const activeConnection = await connect();
|
|
44836
|
-
for (const subject of
|
|
44849
|
+
for (const subject of fresh) {
|
|
44837
44850
|
const subscription = activeConnection.subscribe(subject);
|
|
44838
44851
|
intentionallyClosed.delete(subject);
|
|
44839
44852
|
subscriptions.set(subject, subscription);
|
|
44840
44853
|
pump(subject, subscription);
|
|
44841
44854
|
}
|
|
44855
|
+
const pending = confirming.flatMap((subject) => {
|
|
44856
|
+
const subscription = subscriptions.get(subject);
|
|
44857
|
+
return subscription === undefined ? [] : [[subject, subscription]];
|
|
44858
|
+
});
|
|
44859
|
+
for (const [subject, subscription] of pending)
|
|
44860
|
+
unconfirmed.set(subject, subscription);
|
|
44861
|
+
await within(activeConnection.flush(), SUBSCRIBE_FLUSH_TIMEOUT_MS, `confirming the subscription to ${topic}`);
|
|
44862
|
+
for (const [subject, subscription] of pending) {
|
|
44863
|
+
if (unconfirmed.get(subject) === subscription && subscriptions.get(subject) === subscription) {
|
|
44864
|
+
unconfirmed.delete(subject);
|
|
44865
|
+
}
|
|
44866
|
+
}
|
|
44842
44867
|
return true;
|
|
44843
44868
|
};
|
|
44869
|
+
const confirmPending = async (connect = ensureConnection) => {
|
|
44870
|
+
for (const [subject, subscription] of unconfirmed) {
|
|
44871
|
+
if (subscriptions.get(subject) !== subscription)
|
|
44872
|
+
unconfirmed.delete(subject);
|
|
44873
|
+
}
|
|
44874
|
+
const pending = [...unconfirmed];
|
|
44875
|
+
if (pending.length === 0)
|
|
44876
|
+
return;
|
|
44877
|
+
const activeConnection = await connect();
|
|
44878
|
+
await within(activeConnection.flush(), SUBSCRIBE_FLUSH_TIMEOUT_MS, `confirming the subscriptions to ${pending.map(([subject]) => subject).join(", ")}`);
|
|
44879
|
+
for (const [subject, subscription] of pending) {
|
|
44880
|
+
if (unconfirmed.get(subject) === subscription && subscriptions.get(subject) === subscription) {
|
|
44881
|
+
unconfirmed.delete(subject);
|
|
44882
|
+
}
|
|
44883
|
+
}
|
|
44884
|
+
};
|
|
44885
|
+
const agentSubjectUnconfirmed = (session) => {
|
|
44886
|
+
const own = agentSubject(session);
|
|
44887
|
+
return subscriptions.has(own) && unconfirmed.has(own);
|
|
44888
|
+
};
|
|
44844
44889
|
const noteInbox = (envelope) => {
|
|
44845
44890
|
inbox.unshift({
|
|
44846
44891
|
event_id: envelope.event_id ?? "unknown",
|
|
@@ -45049,6 +45094,7 @@ ${REPLAYED_BTW_NOTE}`, frame.envelope, "inert");
|
|
|
45049
45094
|
});
|
|
45050
45095
|
let agentStreamControl;
|
|
45051
45096
|
let agentStreamControlSession = "";
|
|
45097
|
+
let agentStreamControlConfirmed = false;
|
|
45052
45098
|
let agentStreamCommandsRefreshedOnWatchAt = -Infinity;
|
|
45053
45099
|
let agentStreamViewerAttached = false;
|
|
45054
45100
|
const refreshAgentStreamCommands = (session) => {
|
|
@@ -45150,20 +45196,30 @@ ${REPLAYED_BTW_NOTE}`, frame.envelope, "inert");
|
|
|
45150
45196
|
}, RESUBSCRIBE_DELAY_MS);
|
|
45151
45197
|
};
|
|
45152
45198
|
const watchAgentStream = async (session, connect = ensureConnection) => {
|
|
45153
|
-
|
|
45154
|
-
|
|
45155
|
-
|
|
45156
|
-
|
|
45157
|
-
|
|
45158
|
-
|
|
45159
|
-
|
|
45160
|
-
|
|
45161
|
-
|
|
45162
|
-
|
|
45163
|
-
|
|
45164
|
-
|
|
45165
|
-
|
|
45166
|
-
|
|
45199
|
+
let subscription = agentStreamControlSession === session ? agentStreamControl : undefined;
|
|
45200
|
+
let connected;
|
|
45201
|
+
if (subscription !== undefined) {
|
|
45202
|
+
if (agentStreamControlConfirmed)
|
|
45203
|
+
return;
|
|
45204
|
+
connected = await connect();
|
|
45205
|
+
} else {
|
|
45206
|
+
agentStreamControl?.unsubscribe();
|
|
45207
|
+
agentStreamControl = undefined;
|
|
45208
|
+
if (agentStreamControlSession !== session) {
|
|
45209
|
+
agentStream.reset();
|
|
45210
|
+
agentStreamViewerAttached = false;
|
|
45211
|
+
agentStreamCommandsRefreshedOnWatchAt = -Infinity;
|
|
45212
|
+
}
|
|
45213
|
+
agentStreamControlSession = session;
|
|
45214
|
+
connected = await connect();
|
|
45215
|
+
subscription = connected.subscribe(agentStreamControlSubject(session));
|
|
45216
|
+
agentStreamControl = subscription;
|
|
45217
|
+
agentStreamControlConfirmed = false;
|
|
45218
|
+
pumpAgentStreamControl(subscription, session);
|
|
45219
|
+
}
|
|
45220
|
+
await within(connected.flush(), SUBSCRIBE_FLUSH_TIMEOUT_MS, `confirming the agent stream control subscription for ${session}`);
|
|
45221
|
+
if (agentStreamControl === subscription)
|
|
45222
|
+
agentStreamControlConfirmed = true;
|
|
45167
45223
|
};
|
|
45168
45224
|
const recordAgentStreamMessage = (message, streaming) => {
|
|
45169
45225
|
if (sessionID === "")
|
|
@@ -45233,7 +45289,7 @@ ${REPLAYED_BTW_NOTE}`, frame.envelope, "inert");
|
|
|
45233
45289
|
const topics = [
|
|
45234
45290
|
...new Set([
|
|
45235
45291
|
own,
|
|
45236
|
-
...[...subscriptions.keys()].filter((subject) => !registrationState.isRoleBound(subject) && !reachesPrivateStreamSubject(own, subject))
|
|
45292
|
+
...[...subscriptions.keys()].filter((subject) => !unconfirmed.has(subject) && !registrationState.isRoleBound(subject) && !reachesPrivateStreamSubject(own, subject))
|
|
45237
45293
|
])
|
|
45238
45294
|
];
|
|
45239
45295
|
if (asking !== undefined)
|
|
@@ -45253,6 +45309,9 @@ ${REPLAYED_BTW_NOTE}`, frame.envelope, "inert");
|
|
|
45253
45309
|
};
|
|
45254
45310
|
const sendRegistration = (send) => {
|
|
45255
45311
|
const registeringFor = sessionID;
|
|
45312
|
+
if (agentSubjectUnconfirmed(registeringFor)) {
|
|
45313
|
+
return Promise.reject(new Error(`the server has not confirmed this session's subscription to ${agentSubject(registeringFor)}, so the session is not registered until it does`));
|
|
45314
|
+
}
|
|
45256
45315
|
const asking = relay?.sessionID === registeringFor && relay.subscription !== undefined ? relay : undefined;
|
|
45257
45316
|
const input = registrationInput(asking);
|
|
45258
45317
|
return send(input).then((result) => {
|
|
@@ -45459,10 +45518,18 @@ ${REPLAYED_BTW_NOTE}`, frame.envelope, "inert");
|
|
|
45459
45518
|
inboundFailure = error;
|
|
45460
45519
|
}
|
|
45461
45520
|
}
|
|
45521
|
+
let confirmFailure;
|
|
45522
|
+
if (inbound && inboundFailure === undefined) {
|
|
45523
|
+
await confirmPending(handle.connect).catch((error) => {
|
|
45524
|
+
confirmFailure = error;
|
|
45525
|
+
});
|
|
45526
|
+
}
|
|
45462
45527
|
handle.check();
|
|
45463
45528
|
const registration = await sendRegistration(handle.register).then(() => {
|
|
45464
45529
|
return;
|
|
45465
|
-
}, (error) => ({
|
|
45530
|
+
}, (error) => ({
|
|
45531
|
+
error: agentSubjectUnconfirmed(host) ? inboundFailure ?? confirmFailure ?? error : error
|
|
45532
|
+
}));
|
|
45466
45533
|
handle.check();
|
|
45467
45534
|
if (registration === undefined) {
|
|
45468
45535
|
handle.markEstablished(host);
|
|
@@ -67,6 +67,6 @@ Every topic starts with `notifications.`.
|
|
|
67
67
|
|
|
68
68
|
- Send to one session with `envoy_send`, to the one session that holds a named duty with a role, and to a group with a team topic.
|
|
69
69
|
- Publish to a role with `envoy_publish(topic="notifications.role.<role>", ...)`; never subscribe to a role topic, because the listener forwards a role message to its holder only. A publish returns once the holder's session confirmed it, with the live `holder`. An unheld role returns an error, and so does a holder that did not confirm the message within about 4 seconds; that error names the holder, and you see it after about 8 seconds, because the client tries once more. `envoy_role_get(role=...)` finds the holder first. The stream keeps the forward on the holder's inbox, so the holder's session gets it once from its own durable consumer, also after a restart or a reconnect.
|
|
70
|
-
- For a team, the group subscribes to `notifications.team.<name>.>`, and any member publishes to `notifications.team.<name>.all`. Envoy treats any other `notifications.` topic that no source in the table uses the same way. It reaches every session subscribed when it is published
|
|
70
|
+
- For a team, the group subscribes to `notifications.team.<name>.>`, and any member publishes to `notifications.team.<name>.all`. Envoy treats any other `notifications.` topic that no source in the table uses the same way. It reaches every session subscribed when it is published, yours too when you subscribe. The listener also asks each other session that holds its own NATS connection and registered the topic (every session that follows it with `envoy_subscribe`) to confirm the message; your own session is never asked. A publish returns an error naming each such session that did not confirm within about 4 seconds, and you see it after about 8 seconds, because the client tries once more. A session named with `receipt_timeout` still gets the message: the listener kept a copy in that session's inbox, which the session reads back once its connection returns. A session that stopped without unregistering stays registered for up to 5 minutes and is named in that time; a named session is not a failed delivery to the others. A team topic is not kept for a session that subscribes later. A topic outside `notifications.` is refused.
|
|
71
71
|
- How a role claim survives a resume, a fork or a dead process: `skill://envoy/references/roles.md`.
|
|
72
72
|
- In a Legion pane, the plugin claims your role at session start; read `skill://envoy/references/legion.md` before you claim, release or publish to a role, or answer a role delivery failure there.
|
|
@@ -59,7 +59,6 @@ It depends on where a session takes its deliveries, not on whether the topic is
|
|
|
59
59
|
|
|
60
60
|
- An Oh My Pi or Claude Code session takes its messages from a durable consumer the listener keeps for it on Envoy's stream and relays to it in order, acknowledging each one only once the session wrote it. So every message the stream keeps — your inbox, and each topic you follow with `envoy_subscribe` — reaches you once, whoever sent it: your own publish included, and a subagent's publish to a topic its parent follows. One published while you were restarting, disconnected or not running reaches you when you are back, up to 72 hours later. A session does not take its messages from a NATS subscription of its own; `packages/envoy/AGENTS.md`, "Session consumers", is the rule.
|
|
61
61
|
- A team or other ad-hoc topic is the exception: the stream keeps none, so such a topic reaches only the sessions connected and subscribed when it is published, and nothing recovers it. The listener also forwards the message to the inbox of every other session registered on the topic with `envoy_subscribe`, and the stream keeps that copy, so a session that registered it gets it once after a restart too. What a team topic you subscribed to without registering carried meanwhile is gone.
|
|
62
|
-
- A session the listener delivers to by push, over a serve port, does not receive its own publish, and receives a team topic only through the listener that owns it when that listener runs with `ENVOY_SUBSCRIBE_ALL_TOPICS=1` (the shared hub's listener does not). It receives the stored messages for it by the listener's push, which the listener repeats until the port accepts each one.
|
|
63
62
|
- A role is not a subject its holder subscribes to: the listener finds the live holder and forwards the message to it, and drops the message when that holder is the message's source session. The stream keeps the forward on the holder's inbox, so the holder's session gets it once, also after a restart.
|
|
64
63
|
- A session whose plugin, or whose listener, is of an earlier release falls back to the core path while the rollout lasts (dispatch://INFRA-771 removes it): there it receives live on its own NATS subscriptions, and recovers what the stream stored for it itself, marked as published while its connection was down. It does not recover a role message that way.
|
|
65
64
|
|
|
@@ -38,4 +38,4 @@ envoy_publish(
|
|
|
38
38
|
)
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
-
The subscribed session should receive it. An Oh My Pi or Claude Code session receives its own publish, so it can run both steps
|
|
41
|
+
The subscribed session should receive it. An Oh My Pi or Claude Code session receives its own publish, so it can run both steps. Real WhatsApp delivery also needs the listener's MCP bridge configured with a `whatsapp` server (`packages/envoy/internal/mcpbridge`).
|