@sjawhar/pi-envoy 11.7.0 → 11.8.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/README.md CHANGED
@@ -38,7 +38,9 @@ A message published while the session's NATS connection or one of its subscripti
38
38
  recovered from Envoy's notification stream, which keeps messages for 72 hours: the session asks
39
39
  its listener (`POST /v1/replay`) for what the stream stored on its own agent subject and on each
40
40
  topic it follows, after the place it last read to, and shows each missed message once, as a card
41
- saying it was published while the connection was down. It asks after it reconnects, after a
41
+ saying it was published while the connection was down. The session pings NATS every 10 seconds
42
+ and drops a connection that leaves two pings unanswered, so a connection that stops answering
43
+ without closing is left within 30 seconds and redialed. It asks after it reconnects, after a
42
44
  subscription is reopened, when it starts or resumes, and on every heartbeat. A targeted Dispatch
43
45
  delivery recovered this way (BTW, Aside, Steer, a person's Send) is shown as that card only and
44
46
  runs nothing. Role messages and team or other ad-hoc topics are live only and are not recovered,
package/dist/dispatch.js CHANGED
@@ -14663,7 +14663,7 @@ var dispatchToolSpecs = [
14663
14663
  {
14664
14664
  name: "dispatch_doc_read",
14665
14665
  example: { issue: "DSP-1" },
14666
- description: "Read a live document or a named document version, or the text of an uploaded file at its latest or named version. " + "Do not use it for issue status, asks, or events; " + "use dispatch read instead. Supply ref, issue, or project plus artifact; issue plus an omitted artifact reads the primary document. " + "A live read returns its document token for an optional dispatch doc-edit precondition. With blocks it lists the live document's blocks instead of its markdown, in document order: each block's id, type, token, anchored comments and asks, and opening words, and under a table each row by the index delete_row takes and each cell by its row and the column delete_column takes; block ids, block tokens and those indexes are what dispatch doc-edit takes. " + "A picture (an uploaded PNG, JPEG, GIF or WebP of at most 3,750,000 bytes, 5 MB once base64-encoded) comes back as an image you see, with its name, type, size and version, every time you ask, including one a read already showed this session; " + "any other file that is not UTF-8 text is described, with the route that serves its bytes. " + OWNER_REFERENCE,
14666
+ description: "Read a live document or a named document version, or the text of an uploaded file at its latest or named version. " + "Do not use it for issue status, asks, or events; " + "use dispatch read instead. Supply ref, issue, or project plus artifact; issue plus an omitted artifact reads the primary document. " + "A live read returns its document token for an optional dispatch doc-edit precondition. With blocks it lists the live document's blocks instead of its markdown, in document order: each block's id, type, token, anchored comments and asks, and opening words, and under a table each row by the index delete_row takes and each cell by its row and the column delete_column takes; block ids, block tokens and those indexes are what dispatch doc-edit takes. " + "After the markdown it prints every open thread anchored on the document in full: an open ask with its id and question and each reply's author, time and text, and a comment thread with its root's id, author, quote and text and each reply's author, time and text, in order; a resolved thread, and an ask that is answered or resolved, is not printed. " + "A picture (an uploaded PNG, JPEG, GIF or WebP of at most 3,750,000 bytes, 5 MB once base64-encoded) comes back as an image you see, with its name, type, size and version, every time you ask, including one a read already showed this session; " + "any other file that is not UTF-8 text is described, with the route that serves its bytes. " + OWNER_REFERENCE,
14667
14667
  arguments: (z) => ({
14668
14668
  issue: z.string().describe(ISSUE_REFERENCE).optional(),
14669
14669
  project: z.string().describe("Project key owning the document.").optional(),
@@ -15933,8 +15933,8 @@ class DispatchClient {
15933
15933
  async resolveComment(id, actor) {
15934
15934
  return this.#json("POST", ["api", "v1", "comments", id, "resolve"], { actor });
15935
15935
  }
15936
- async getComments(issue, artifact) {
15937
- return this.#json("GET", ["api", "v1", "issues", await this.#resolveIssue(issue), "comments"], undefined, artifact ? { artifact } : undefined);
15936
+ async getComments(issue) {
15937
+ return this.#json("GET", ["api", "v1", "issues", await this.#resolveIssue(issue), "comments"]);
15938
15938
  }
15939
15939
  async getIssueReferences(issue) {
15940
15940
  return this.#json("GET", [
@@ -18040,22 +18040,64 @@ function messageSummary({ message, replies }, graph) {
18040
18040
  ].join(`
18041
18041
  `);
18042
18042
  }
18043
- async function openArtifactMarks(client, resolved) {
18043
+ async function openAnchoredThreads(client, resolved) {
18044
18044
  const asksPromise = resolved.owner.kind === "project" ? client.getArtifactAsks(resolved.artifact.id) : Promise.resolve(resolved.issue?.open_asks ?? []);
18045
- const commentsPromise = resolved.owner.kind === "project" ? client.getArtifactComments(resolved.artifact.id) : client.getComments(resolved.issue?.key ?? "", resolved.artifact.id);
18045
+ const commentsPromise = resolved.owner.kind === "project" ? client.getArtifactComments(resolved.artifact.id) : client.getComments(resolved.issue?.key ?? "");
18046
18046
  const commentsResultPromise = commentsPromise.then((value) => ({ status: "fulfilled", value }), (reason) => ({ status: "rejected", reason }));
18047
- const asks = await asksPromise;
18048
- const marks = asks.filter((ask) => ask.state === "open" && ask.anchor?.artifact_id === resolved.artifact.id).map((ask) => `ask ${ask.id}`);
18047
+ const asks = (await asksPromise).filter((ask) => ask.state === "open" && ask.anchor?.artifact_id === resolved.artifact.id);
18049
18048
  const commentsResult = await commentsResultPromise;
18050
- if (commentsResult.status === "rejected") {
18051
- if (dispatchAnswered(commentsResult.reason, 404))
18052
- return marks;
18049
+ if (commentsResult.status === "rejected" && !dispatchAnswered(commentsResult.reason, 404)) {
18053
18050
  throw commentsResult.reason;
18054
18051
  }
18055
- return [
18056
- ...marks,
18057
- ...commentsResult.value.filter((comment) => !comment.resolved && comment.anchor?.artifact_id === resolved.artifact.id).map((comment) => `comment ${comment.id}`)
18058
- ];
18052
+ const comments = commentsResult.status === "fulfilled" ? commentsResult.value : [];
18053
+ const askReplies = new Map(asks.map((ask) => [ask.id, []]));
18054
+ for (const comment of comments) {
18055
+ if (comment.ask_id)
18056
+ askReplies.get(comment.ask_id)?.push(comment);
18057
+ }
18058
+ const askThreads = asks.map((ask) => [
18059
+ `ask ${ask.id} \xB7 ${actorText(ask.author)} \xB7 ${ask.created_at}`,
18060
+ ...anchorLines(ask),
18061
+ `Question: ${ask.question}`,
18062
+ ...threadReplyLines(askReplies.get(ask.id) ?? [])
18063
+ ].join(`
18064
+ `));
18065
+ const byId = new Map(comments.map((comment) => [comment.id, comment]));
18066
+ const roots = comments.filter((comment) => comment.reply_to === null && !comment.ask_id && !comment.resolved && comment.anchor?.artifact_id === resolved.artifact.id);
18067
+ const replies = new Map(roots.map((root) => [root.id, []]));
18068
+ for (const comment of comments) {
18069
+ const root = comment.reply_to === null ? undefined : threadRootId(comment, byId);
18070
+ if (root !== undefined)
18071
+ replies.get(root)?.push(comment);
18072
+ }
18073
+ const commentThreads = roots.map((root) => [
18074
+ `comment ${root.id} \xB7 ${actorText(root.author)} \xB7 ${root.created_at}`,
18075
+ ...anchorLines(root),
18076
+ `Body: ${root.body}`,
18077
+ ...threadReplyLines(replies.get(root.id) ?? [])
18078
+ ].join(`
18079
+ `));
18080
+ return [...askThreads, ...commentThreads];
18081
+ }
18082
+ function threadReplyLines(replies) {
18083
+ return replies.flatMap((reply) => [
18084
+ `reply ${reply.id} \xB7 ${actorText(reply.author)} \xB7 ${reply.created_at}`,
18085
+ `Body: ${reply.body}`
18086
+ ]);
18087
+ }
18088
+ function threadRootId(comment, byId) {
18089
+ const seen = new Set;
18090
+ let current = comment;
18091
+ while (current.reply_to !== null) {
18092
+ if (seen.has(current.id))
18093
+ return;
18094
+ seen.add(current.id);
18095
+ const parent = byId.get(current.reply_to);
18096
+ if (parent === undefined)
18097
+ return;
18098
+ current = parent;
18099
+ }
18100
+ return current.id;
18059
18101
  }
18060
18102
  async function blockAsks(client, resolved, state) {
18061
18103
  const asks = await (resolved.issue === undefined ? client.getArtifactAsks(resolved.artifact.id, state) : client.listIssueAsks(resolved.issue.key, state));
@@ -19020,24 +19062,27 @@ Document token: ${listed.token}`,
19020
19062
  } : { issue: resolved.issue?.key }, version, resolved.owner.kind === "project" ? resolved.owner.project : resolved.owner.issue, shown);
19021
19063
  }
19022
19064
  const documentPromise = client.docRead(resolved.artifact.id, version);
19023
- const marksPromise = openArtifactMarks(client, resolved);
19024
- const marksResultPromise = marksPromise.then((value) => ({ status: "fulfilled", value }), (reason) => ({ status: "rejected", reason }));
19065
+ const threadsPromise = openAnchoredThreads(client, resolved);
19066
+ const threadsResultPromise = threadsPromise.then((value) => ({ status: "fulfilled", value }), (reason) => ({ status: "rejected", reason }));
19025
19067
  const document = await documentPromise;
19026
- const marksResult = await marksResultPromise;
19027
- if (marksResult.status === "rejected")
19028
- throw marksResult.reason;
19029
- const marks = marksResult.value;
19068
+ const threadsResult = await threadsResultPromise;
19069
+ if (threadsResult.status === "rejected")
19070
+ throw threadsResult.reason;
19071
+ const threads = threadsResult.value;
19030
19072
  const approval = approvalLine(resolved.artifact);
19031
19073
  const trailer = [
19032
19074
  ..."token" in document && document.token !== undefined ? [`Document token: ${document.token}`] : [],
19033
- ...marks.length === 0 ? [] : [`Open anchored asks/comments: ${marks.join(", ")}`],
19034
19075
  ...approval === undefined ? [] : [approval]
19035
19076
  ];
19036
19077
  return {
19037
- text: trailer.length === 0 ? document.markdown : `${document.markdown}
19078
+ text: [
19079
+ document.markdown,
19080
+ ...trailer.length === 0 ? [] : [trailer.join(`
19081
+ `)],
19082
+ ...threads.length === 0 ? [] : ["Open anchored threads:", ...threads]
19083
+ ].join(`
19038
19084
 
19039
- ${trailer.join(`
19040
- `)}`,
19085
+ `),
19041
19086
  details: resolved.owner.kind === "project" ? {
19042
19087
  project: resolved.artifact.project,
19043
19088
  document: `${resolved.artifact.project}/${resolved.artifact.slug}`
@@ -20191,7 +20236,9 @@ var SessionWireSchema = object({
20191
20236
  roles: array(string2()).optional(),
20192
20237
  capabilities: array(string2()).optional(),
20193
20238
  self_subscribed: boolean2(),
20194
- last_seen: number2().int().optional()
20239
+ last_seen: number2().int().optional(),
20240
+ plugin: string2().optional(),
20241
+ plugin_version: string2().optional()
20195
20242
  });
20196
20243
  var RoleWireSchema = object({
20197
20244
  role: string2(),
@@ -20327,7 +20374,9 @@ function createEnvoyClient(config) {
20327
20374
  ...input.capabilities === undefined ? {} : { capabilities: input.capabilities },
20328
20375
  driving: input.driving,
20329
20376
  ...input.selfSubscribed === undefined ? {} : { self_subscribed: input.selfSubscribed },
20330
- host: machineID()
20377
+ host: machineID(),
20378
+ plugin: input.plugin.name,
20379
+ plugin_version: input.plugin.version
20331
20380
  }))),
20332
20381
  unsubscribe: async (input) => {
20333
20382
  await post("/v1/interests/unsubscribe", {
package/dist/envoy.js CHANGED
@@ -6792,7 +6792,7 @@ var require_protocol = __commonJS(function(exports) {
6792
6792
  }
6793
6793
  disconnect() {
6794
6794
  this.dispatchStatus({ type: core_1.DebugEvents.StaleConnection, data: "" });
6795
- this.transport.disconnect();
6795
+ this.transport.close();
6796
6796
  }
6797
6797
  reconnect() {
6798
6798
  if (this.connected) {
@@ -15633,6 +15633,7 @@ var require_node_transport = __commonJS(function(exports) {
15633
15633
  d.resolve(socket);
15634
15634
  socket.removeAllListeners();
15635
15635
  });
15636
+ this.socket = socket;
15636
15637
  socket.on("error", (err) => {
15637
15638
  dialError = err;
15638
15639
  });
@@ -15915,8 +15916,11 @@ var require_node_transport = __commonJS(function(exports) {
15915
15916
  }
15916
15917
  _closed(err_1) {
15917
15918
  return __awaiter(this, arguments, undefined, function* (err, internal = true) {
15918
- if (!this.connected)
15919
+ if (!this.connected) {
15920
+ if (this.socket)
15921
+ this.socket.destroy();
15919
15922
  return;
15923
+ }
15920
15924
  if (this.done)
15921
15925
  return;
15922
15926
  this.closeError = err;
@@ -30354,7 +30358,7 @@ var dispatchToolSpecs = [
30354
30358
  {
30355
30359
  name: "dispatch_doc_read",
30356
30360
  example: { issue: "DSP-1" },
30357
- description: "Read a live document or a named document version, or the text of an uploaded file at its latest or named version. " + "Do not use it for issue status, asks, or events; " + "use dispatch read instead. Supply ref, issue, or project plus artifact; issue plus an omitted artifact reads the primary document. " + "A live read returns its document token for an optional dispatch doc-edit precondition. With blocks it lists the live document's blocks instead of its markdown, in document order: each block's id, type, token, anchored comments and asks, and opening words, and under a table each row by the index delete_row takes and each cell by its row and the column delete_column takes; block ids, block tokens and those indexes are what dispatch doc-edit takes. " + "A picture (an uploaded PNG, JPEG, GIF or WebP of at most 3,750,000 bytes, 5 MB once base64-encoded) comes back as an image you see, with its name, type, size and version, every time you ask, including one a read already showed this session; " + "any other file that is not UTF-8 text is described, with the route that serves its bytes. " + OWNER_REFERENCE,
30361
+ description: "Read a live document or a named document version, or the text of an uploaded file at its latest or named version. " + "Do not use it for issue status, asks, or events; " + "use dispatch read instead. Supply ref, issue, or project plus artifact; issue plus an omitted artifact reads the primary document. " + "A live read returns its document token for an optional dispatch doc-edit precondition. With blocks it lists the live document's blocks instead of its markdown, in document order: each block's id, type, token, anchored comments and asks, and opening words, and under a table each row by the index delete_row takes and each cell by its row and the column delete_column takes; block ids, block tokens and those indexes are what dispatch doc-edit takes. " + "After the markdown it prints every open thread anchored on the document in full: an open ask with its id and question and each reply's author, time and text, and a comment thread with its root's id, author, quote and text and each reply's author, time and text, in order; a resolved thread, and an ask that is answered or resolved, is not printed. " + "A picture (an uploaded PNG, JPEG, GIF or WebP of at most 3,750,000 bytes, 5 MB once base64-encoded) comes back as an image you see, with its name, type, size and version, every time you ask, including one a read already showed this session; " + "any other file that is not UTF-8 text is described, with the route that serves its bytes. " + OWNER_REFERENCE,
30358
30362
  arguments: (z) => ({
30359
30363
  issue: z.string().describe(ISSUE_REFERENCE).optional(),
30360
30364
  project: z.string().describe("Project key owning the document.").optional(),
@@ -33561,8 +33565,8 @@ class DispatchClient {
33561
33565
  async resolveComment(id, actor) {
33562
33566
  return this.#json("POST", ["api", "v1", "comments", id, "resolve"], { actor });
33563
33567
  }
33564
- async getComments(issue, artifact) {
33565
- return this.#json("GET", ["api", "v1", "issues", await this.#resolveIssue(issue), "comments"], undefined, artifact ? { artifact } : undefined);
33568
+ async getComments(issue) {
33569
+ return this.#json("GET", ["api", "v1", "issues", await this.#resolveIssue(issue), "comments"]);
33566
33570
  }
33567
33571
  async getIssueReferences(issue) {
33568
33572
  return this.#json("GET", [
@@ -34251,6 +34255,22 @@ function natsAuthOptions(seed) {
34251
34255
  return { authenticator: import_nats.nkeyAuthenticator(bytes) };
34252
34256
  }
34253
34257
 
34258
+ // ../envoy-client/src/nats-connection.ts
34259
+ var NATS_PING_INTERVAL_MS = 1e4;
34260
+ var NATS_MAX_PINGS_OUT = 2;
34261
+ function natsConnectionOptions(input) {
34262
+ return {
34263
+ servers: [...input.servers],
34264
+ name: input.name,
34265
+ ...natsAuthOptions(input.seed),
34266
+ reconnect: true,
34267
+ maxReconnectAttempts: -1,
34268
+ reconnectTimeWait: 2000,
34269
+ pingInterval: NATS_PING_INTERVAL_MS,
34270
+ maxPingOut: NATS_MAX_PINGS_OUT
34271
+ };
34272
+ }
34273
+
34254
34274
  // ../envoy-client/src/transport.ts
34255
34275
  var DEFAULT_TIMEOUT_MS = 5000;
34256
34276
  var RETRY_DELAY_MS = 250;
@@ -34275,7 +34295,9 @@ var SessionWireSchema = object({
34275
34295
  roles: array(string2()).optional(),
34276
34296
  capabilities: array(string2()).optional(),
34277
34297
  self_subscribed: boolean2(),
34278
- last_seen: number2().int().optional()
34298
+ last_seen: number2().int().optional(),
34299
+ plugin: string2().optional(),
34300
+ plugin_version: string2().optional()
34279
34301
  });
34280
34302
  var RoleWireSchema = object({
34281
34303
  role: string2(),
@@ -34422,7 +34444,9 @@ function createEnvoyClient(config) {
34422
34444
  ...input.capabilities === undefined ? {} : { capabilities: input.capabilities },
34423
34445
  driving: input.driving,
34424
34446
  ...input.selfSubscribed === undefined ? {} : { self_subscribed: input.selfSubscribed },
34425
- host: machineID()
34447
+ host: machineID(),
34448
+ plugin: input.plugin.name,
34449
+ plugin_version: input.plugin.version
34426
34450
  }))),
34427
34451
  unsubscribe: async (input) => {
34428
34452
  await post("/v1/interests/unsubscribe", {
@@ -35103,9 +35127,10 @@ function createReplayEngine(options) {
35103
35127
  function replaySuppressed(rendered) {
35104
35128
  return rendered.skip || rendered.malformedDelivery === true;
35105
35129
  }
35130
+ var REPLAYED_SUFFIX = "while this session's connection was down.";
35106
35131
  function replayedText(content, publishedAt) {
35107
35132
  return `${content}
35108
- Published at ${publishedAt} while this session's connection was down.`;
35133
+ Published at ${publishedAt} ${REPLAYED_SUFFIX}`;
35109
35134
  }
35110
35135
  function failureNoticeFields(notice) {
35111
35136
  const readWith = notice.readWith === "dispatch read" ? "Read it with the `dispatch read` command on the issue or ask it concerns." : "Read it with the envoy_inbox tool.";
@@ -36030,6 +36055,10 @@ import * as host2 from "@oh-my-pi/pi-coding-agent";
36030
36055
  import { logger as logger3, procmgr, VERSION } from "@oh-my-pi/pi-utils";
36031
36056
  var import_nats2 = __toESM(require_mod4(), 1);
36032
36057
 
36058
+ // package.json
36059
+ var name = "@sjawhar/pi-envoy";
36060
+ var version2 = "11.8.0";
36061
+
36033
36062
  // src/agent-stream.ts
36034
36063
  var encoder2 = new TextEncoder;
36035
36064
  var REPLAY_ARRAY_BYTES = 2;
@@ -39428,14 +39457,11 @@ function envoyExtension(pi) {
39428
39457
  if (connection?.isClosed() === false)
39429
39458
  return connection;
39430
39459
  const { natsUrls, natsSeed } = requireInbound();
39431
- const dialled = await import_nats2.connect({
39432
- servers: [...natsUrls],
39460
+ const dialled = await import_nats2.connect(natsConnectionOptions({
39461
+ servers: natsUrls,
39433
39462
  name: `omp-${sessionID || "unknown"}`,
39434
- ...natsAuthOptions(natsSeed),
39435
- reconnect: true,
39436
- maxReconnectAttempts: -1,
39437
- reconnectTimeWait: 2000
39438
- });
39463
+ seed: natsSeed
39464
+ }));
39439
39465
  if (!live() || shuttingDown || connection?.isClosed() === false) {
39440
39466
  await dialled.close().catch(() => {});
39441
39467
  if (!shuttingDown && connection?.isClosed() === false)
@@ -40110,7 +40136,8 @@ ${REPLAYED_BTW_NOTE}`, frame.envelope, "inert");
40110
40136
  title: activeSessionContext?.sessionManager.getSessionName?.() ?? "",
40111
40137
  capabilities: sideTurn(activeSessionContext) === undefined ? CAPABILITIES_WITHOUT_BTW : DELIVERY_CAPABILITIES,
40112
40138
  driving: false,
40113
- selfSubscribed: true
40139
+ selfSubscribed: true,
40140
+ plugin: { name, version: version2 }
40114
40141
  }).then((result) => {
40115
40142
  registeredFor = registeringFor;
40116
40143
  registeredAt = Date.now();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sjawhar/pi-envoy",
3
- "version": "11.7.0",
3
+ "version": "11.8.0",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "omp": {