@sjawhar/pi-envoy 15.1.3 → 15.2.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 +11 -5
- package/dist/dispatch.js +1 -1
- package/dist/envoy.js +107 -27
- package/dist/skills/dispatch/SKILL.md +1 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -105,8 +105,8 @@ set -g set-clipboard on
|
|
|
105
105
|
|
|
106
106
|
A session with Dispatch configured — a top-level session, a Legion pane or a `task` subagent —
|
|
107
107
|
sends two extra user messages with every model request of its conversation. At the head, after
|
|
108
|
-
any compaction summary, it sends the `dispatch-first` skill, whose text never changes.
|
|
109
|
-
|
|
108
|
+
any compaction summary, it sends the `dispatch-first` skill, whose text never changes. It also
|
|
109
|
+
sends what people wrote to the session in the last 72
|
|
110
110
|
hours that Dispatch delivered to it: answers to its asks, replies on them and in its comment
|
|
111
111
|
threads, comments on its documents and routed issues, mentions, and messages, newest first and
|
|
112
112
|
word for word. A subagent reads its parent's list. The list stays under 8,000 characters (at most 7,999): the oldest
|
|
@@ -119,9 +119,15 @@ own `404 NOT_FOUND` "no route for …". Against that Dispatch a request carries
|
|
|
119
119
|
`dispatch answers` cannot read it either; a list read before from it is still carried, its
|
|
120
120
|
left-out line naming no command; the log says once per session that the Dispatch has no answers
|
|
121
121
|
route; and that Dispatch is not asked again for 5 minutes. Any other answer, a proxy's 404 page or
|
|
122
|
-
a 200 that is no answers list included, is a failed read.
|
|
123
|
-
|
|
124
|
-
|
|
122
|
+
a 200 that is no answers list included, is a failed read.
|
|
123
|
+
|
|
124
|
+
The list goes after the request's last message only on the request where it first shows an item,
|
|
125
|
+
or new words in one. On every request after that it stays right after the message it followed
|
|
126
|
+
there, so the request ends with its own last message and the model does not take a list with
|
|
127
|
+
nothing new in it for a new turn; it keeps that place when it only loses items or its header
|
|
128
|
+
changes. After a compaction summarizes that message, or in a new process, the list goes after the
|
|
129
|
+
last message once more. It is never at the head, so a change in it costs only the bytes after it,
|
|
130
|
+
and a list that keeps its place is inside the cached prefix of the next request.
|
|
125
131
|
|
|
126
132
|
Oh My Pi also builds requests that are not turns of the conversation from it; those carry the
|
|
127
133
|
skill but no list, and wait on no read: a side turn (a Dispatch BTW, the stop-time self-check,
|
package/dist/dispatch.js
CHANGED
|
@@ -15292,7 +15292,7 @@ var dispatchToolSpecs = [
|
|
|
15292
15292
|
ops: [{ op: "delete_column", block: "table-123", index: 1 }],
|
|
15293
15293
|
precondition: { blocks: [{ id: "table-123", token: "sha256:current-table-token" }] }
|
|
15294
15294
|
},
|
|
15295
|
-
description: "Apply deterministic document edits: replace or delete quoted text, insert markdown at an anchor, retype an identified paragraph or typed block into a schema-declared typed block, delete or move a whole block by its id, or delete a table row or column in place. " + "Do not use it for review feedback or for reading; use dispatch comment, dispatch suggest, or dispatch doc-read instead. " +
|
|
15295
|
+
description: "Apply deterministic document edits: replace or delete quoted text, insert markdown at an anchor, retype an identified paragraph or typed block into a schema-declared typed block, delete or move a whole block by its id, or delete a table row or column in place. " + "Do not use it for review feedback or for reading; use dispatch comment, dispatch suggest, or dispatch doc-read instead. " + "For replace, delete, and quote anchors, find text as rendered: inline Markdown (**bold**, `code`) is tolerated and must be balanced; a leading '# ' matches a heading at any level. A find that opens with a list marker ('- ', '5. ', with an optional '[ ] ' or '[x] ' after it) and matches no text as written selects an item of that kind of list whose text starts with the rest, its number not matched and a box matching only a task item in that state. A find or quote anchor stays inside one block, and in a table inside one cell: ' | ' is the boundary markdown writes between two cells, not text a cell holds, so a quote that runs across cells is refused, naming the cells; change several cells with one operation per cell in the same batch, and anchor on one cell's text. replace is inline: with is the new text of the matched span, so a marker of a different kind from the block's own stays literal text ('4. Design' written into a heading). A with that opens with a marker of the same kind as the matched block's own would write it twice and is INVALID_OP - including prose that merely looks like one ('1999. was a year' into an ordered item), which you write as text by escaping it ('1999\\. was a year'). The exceptions are an item a find's list marker selected (it matched no text as written): replace(find=\"5. Old\", with=\"5. New\") gives the item the text 'New' under its own number, and a with that is the marker alone is INVALID_OP; and a heading rename whose find carried a heading marker: replace(find=\"## Old\", with=\"## New\") gives '## New', where a different level applies only when find named the heading's actual level (find \"## Old\" with \"### New\" makes it an h3), since '# ' selects a heading without naming its level. A task item (`- [ ]` / `- [x]`) is ticked the same way: when find matches from the start of the item's text and with opens with '[x] ' or '[ ] ', the opening sets the item's box and the rest is its new text (replace(find=\"Write it\", with=\"[x] Write it\") ticks it); the same opening over a plain list item or a paragraph stays literal text. Any non-empty with that renders to no text - a line indented four spaces or a tab, which markdown reads as a code block, or whitespace alone - is INVALID_OP rather than a silent deletion; pass an empty with to delete the matched text on purpose - a list item, quote, typed block or footnote definition left holding only the emptied paragraph keeps it. " + "with cannot open a new block: after a hard line break inside with (two trailing spaces, or a backslash, before the newline) a heading, bullet, '1.'/'1)' ordered, or '>' blockquote marker is INVALID_OP too, since that line would stay escaped text inside the matched block - use insert, plus delete for what it replaces, to add the block. A hard break in with is itself INVALID_OP when the matched text is in a heading or a table cell, which are written on one line. In a table cell, with is the cell's text: write a | in it bare, in code too, since code whose text has an odd run of backslashes right before a | cannot be stored in a cell and is INVALID_OP, naming the cell. " + "A delete whose find is a block's entire text removes the block (a list emptied of its items goes too); delete with block removes any block by id, and move with block relocates one. A delete or retype that would take an ask block out of the document while its ask is open is refused, with nothing sent. delete_row and delete_column take a table block and a zero-based index, preserving the table block id and refusing to remove cells with open asks or unresolved comments. " + `Insert and move anchors also accept "start", "end", "heading:<exact heading text>", and "block:<id>"; dispatch doc-read --blocks lists every block's id, type, opening words and token, and each table's rows and cells with the indexes delete_row and delete_column take (GET /api/v1/artifacts/{artifact UUID}/blocks serves the same list). ` + "Optionally require the state just read: precondition selects exactly one of a document token from dispatch doc-read, or block {id, token} values from dispatch doc-read --blocks. A block guard must include every block the batch changes; Dispatch resolves quote targets and rejects an uncovered batch rather than applying it. Use a document token for insert or move, which depend on document order. Prefer block tokens when the covered content blocks are independent sections. Tokens include inline marks, so a fresh human comment also makes a stale edit fail. PRECONDITION_FAILED means re-read; EDIT_QUEUE_FULL means back off before retrying. " + "The result carries the document token this edit produced, so a chain of guarded edits passes each result's token as the next edit's precondition with no dispatch doc-read between them. " + "A batch that leaves the document exactly as it was mints no version, named or not, and the result says nothing changed and names each operation that did nothing. " + "A change a browser removes while the edit is in flight is never reported as applied: EDIT_LOST_TO_CONCURRENT_CHANGE means the write was refused and nothing was written, so re-read the document and decide again, as with PRECONDITION_FAILED; lost_ops on a successful result names operations whose text the live document no longer has, because the deletion landed after the version was written. " + "One replace per paragraph: more new paragraphs go in one insert after the last one you rewrote, since two inserts at one anchor come out reversed; read the passage back with dispatch doc-read afterwards. " + "Each decision block the edit adds gets the related-item check dispatch ask gets, waiting at most five seconds for all of them together: the result prints, after its first line, `Decision block <id>:` and what that check found, that it found nothing, or that it was not made and why. " + "A block id written as {#id} longer than 256 bytes is stored, but its block is no graph node, so no reference reaches it. " + `The spec holds requirements, design, and decisions - never progress, status, or timestamps; a record of open items or progress is a document of its own. ${OWNER_REFERENCE} ${SPEC_WRITING_POINTER}`,
|
|
15296
15296
|
arguments: (z) => ({
|
|
15297
15297
|
issue: z.string().describe(ISSUE_REFERENCE).optional(),
|
|
15298
15298
|
project: z.string().describe("Project key owning the document.").optional(),
|
package/dist/envoy.js
CHANGED
|
@@ -30412,7 +30412,7 @@ var dispatchToolSpecs = [
|
|
|
30412
30412
|
ops: [{ op: "delete_column", block: "table-123", index: 1 }],
|
|
30413
30413
|
precondition: { blocks: [{ id: "table-123", token: "sha256:current-table-token" }] }
|
|
30414
30414
|
},
|
|
30415
|
-
description: "Apply deterministic document edits: replace or delete quoted text, insert markdown at an anchor, retype an identified paragraph or typed block into a schema-declared typed block, delete or move a whole block by its id, or delete a table row or column in place. " + "Do not use it for review feedback or for reading; use dispatch comment, dispatch suggest, or dispatch doc-read instead. " +
|
|
30415
|
+
description: "Apply deterministic document edits: replace or delete quoted text, insert markdown at an anchor, retype an identified paragraph or typed block into a schema-declared typed block, delete or move a whole block by its id, or delete a table row or column in place. " + "Do not use it for review feedback or for reading; use dispatch comment, dispatch suggest, or dispatch doc-read instead. " + "For replace, delete, and quote anchors, find text as rendered: inline Markdown (**bold**, `code`) is tolerated and must be balanced; a leading '# ' matches a heading at any level. A find that opens with a list marker ('- ', '5. ', with an optional '[ ] ' or '[x] ' after it) and matches no text as written selects an item of that kind of list whose text starts with the rest, its number not matched and a box matching only a task item in that state. A find or quote anchor stays inside one block, and in a table inside one cell: ' | ' is the boundary markdown writes between two cells, not text a cell holds, so a quote that runs across cells is refused, naming the cells; change several cells with one operation per cell in the same batch, and anchor on one cell's text. replace is inline: with is the new text of the matched span, so a marker of a different kind from the block's own stays literal text ('4. Design' written into a heading). A with that opens with a marker of the same kind as the matched block's own would write it twice and is INVALID_OP - including prose that merely looks like one ('1999. was a year' into an ordered item), which you write as text by escaping it ('1999\\. was a year'). The exceptions are an item a find's list marker selected (it matched no text as written): replace(find=\"5. Old\", with=\"5. New\") gives the item the text 'New' under its own number, and a with that is the marker alone is INVALID_OP; and a heading rename whose find carried a heading marker: replace(find=\"## Old\", with=\"## New\") gives '## New', where a different level applies only when find named the heading's actual level (find \"## Old\" with \"### New\" makes it an h3), since '# ' selects a heading without naming its level. A task item (`- [ ]` / `- [x]`) is ticked the same way: when find matches from the start of the item's text and with opens with '[x] ' or '[ ] ', the opening sets the item's box and the rest is its new text (replace(find=\"Write it\", with=\"[x] Write it\") ticks it); the same opening over a plain list item or a paragraph stays literal text. Any non-empty with that renders to no text - a line indented four spaces or a tab, which markdown reads as a code block, or whitespace alone - is INVALID_OP rather than a silent deletion; pass an empty with to delete the matched text on purpose - a list item, quote, typed block or footnote definition left holding only the emptied paragraph keeps it. " + "with cannot open a new block: after a hard line break inside with (two trailing spaces, or a backslash, before the newline) a heading, bullet, '1.'/'1)' ordered, or '>' blockquote marker is INVALID_OP too, since that line would stay escaped text inside the matched block - use insert, plus delete for what it replaces, to add the block. A hard break in with is itself INVALID_OP when the matched text is in a heading or a table cell, which are written on one line. In a table cell, with is the cell's text: write a | in it bare, in code too, since code whose text has an odd run of backslashes right before a | cannot be stored in a cell and is INVALID_OP, naming the cell. " + "A delete whose find is a block's entire text removes the block (a list emptied of its items goes too); delete with block removes any block by id, and move with block relocates one. A delete or retype that would take an ask block out of the document while its ask is open is refused, with nothing sent. delete_row and delete_column take a table block and a zero-based index, preserving the table block id and refusing to remove cells with open asks or unresolved comments. " + `Insert and move anchors also accept "start", "end", "heading:<exact heading text>", and "block:<id>"; dispatch doc-read --blocks lists every block's id, type, opening words and token, and each table's rows and cells with the indexes delete_row and delete_column take (GET /api/v1/artifacts/{artifact UUID}/blocks serves the same list). ` + "Optionally require the state just read: precondition selects exactly one of a document token from dispatch doc-read, or block {id, token} values from dispatch doc-read --blocks. A block guard must include every block the batch changes; Dispatch resolves quote targets and rejects an uncovered batch rather than applying it. Use a document token for insert or move, which depend on document order. Prefer block tokens when the covered content blocks are independent sections. Tokens include inline marks, so a fresh human comment also makes a stale edit fail. PRECONDITION_FAILED means re-read; EDIT_QUEUE_FULL means back off before retrying. " + "The result carries the document token this edit produced, so a chain of guarded edits passes each result's token as the next edit's precondition with no dispatch doc-read between them. " + "A batch that leaves the document exactly as it was mints no version, named or not, and the result says nothing changed and names each operation that did nothing. " + "A change a browser removes while the edit is in flight is never reported as applied: EDIT_LOST_TO_CONCURRENT_CHANGE means the write was refused and nothing was written, so re-read the document and decide again, as with PRECONDITION_FAILED; lost_ops on a successful result names operations whose text the live document no longer has, because the deletion landed after the version was written. " + "One replace per paragraph: more new paragraphs go in one insert after the last one you rewrote, since two inserts at one anchor come out reversed; read the passage back with dispatch doc-read afterwards. " + "Each decision block the edit adds gets the related-item check dispatch ask gets, waiting at most five seconds for all of them together: the result prints, after its first line, `Decision block <id>:` and what that check found, that it found nothing, or that it was not made and why. " + "A block id written as {#id} longer than 256 bytes is stored, but its block is no graph node, so no reference reaches it. " + `The spec holds requirements, design, and decisions - never progress, status, or timestamps; a record of open items or progress is a document of its own. ${OWNER_REFERENCE} ${SPEC_WRITING_POINTER}`,
|
|
30416
30416
|
arguments: (z) => ({
|
|
30417
30417
|
issue: z.string().describe(ISSUE_REFERENCE).optional(),
|
|
30418
30418
|
project: z.string().describe("Project key owning the document.").optional(),
|
|
@@ -36641,15 +36641,26 @@ function withinWindow(items, now) {
|
|
|
36641
36641
|
const start = now - SESSION_ANSWERS_WINDOW_MS;
|
|
36642
36642
|
return items.filter((item) => Date.parse(item.at) >= start);
|
|
36643
36643
|
}
|
|
36644
|
+
function sessionAnswersWords(items) {
|
|
36645
|
+
return items.map((item) => JSON.stringify([
|
|
36646
|
+
item.kind,
|
|
36647
|
+
item.id,
|
|
36648
|
+
item.author.id,
|
|
36649
|
+
item.at,
|
|
36650
|
+
item.edited_at ?? null,
|
|
36651
|
+
item.selected ?? null,
|
|
36652
|
+
item.text
|
|
36653
|
+
]));
|
|
36654
|
+
}
|
|
36644
36655
|
var MAX_CHARS_TEXT = SESSION_ANSWERS_MAX_CHARS.toLocaleString("en-US");
|
|
36645
36656
|
function leftOutLine(count, namesCommand) {
|
|
36646
36657
|
const counted = `${count} older ${count === 1 ? "item" : "items"} left out to stay under ${MAX_CHARS_TEXT} characters`;
|
|
36647
36658
|
return namesCommand ? `${counted}: run \`dispatch answers\` to read every one in full.` : `${counted}.`;
|
|
36648
36659
|
}
|
|
36649
|
-
function
|
|
36650
|
-
const
|
|
36651
|
-
const unsent =
|
|
36652
|
-
const count =
|
|
36660
|
+
function renderShown(items, options) {
|
|
36661
|
+
const inWindow = withinWindow(items, Number(options.now));
|
|
36662
|
+
const unsent = inWindow.length === items.length ? Math.max(0, (options.total ?? items.length) - items.length) : 0;
|
|
36663
|
+
const count = inWindow.length + unsent;
|
|
36653
36664
|
if (count === 0)
|
|
36654
36665
|
return;
|
|
36655
36666
|
const header = options.cached === undefined ? SESSION_ANSWERS_MARKER : `${SESSION_ANSWERS_MARKER}
|
|
@@ -36657,7 +36668,7 @@ As read at ${options.cached.readAt}; this read failed: ${failureSentence(options
|
|
|
36657
36668
|
const namesCommand = options.withoutCommand !== true;
|
|
36658
36669
|
const blocks = [];
|
|
36659
36670
|
let length = header.length;
|
|
36660
|
-
for (const item of
|
|
36671
|
+
for (const item of inWindow) {
|
|
36661
36672
|
const block = renderSessionAnswerItem(item);
|
|
36662
36673
|
const after = count - blocks.length - 1;
|
|
36663
36674
|
const needed = length + 2 + block.length + (after === 0 ? 0 : 2 + leftOutLine(after, namesCommand).length);
|
|
@@ -36667,9 +36678,14 @@ As read at ${options.cached.readAt}; this read failed: ${failureSentence(options
|
|
|
36667
36678
|
length += 2 + block.length;
|
|
36668
36679
|
}
|
|
36669
36680
|
const leftOut = count - blocks.length;
|
|
36670
|
-
|
|
36681
|
+
const text = [
|
|
36682
|
+
header,
|
|
36683
|
+
...blocks,
|
|
36684
|
+
...leftOut === 0 ? [] : [leftOutLine(leftOut, namesCommand)]
|
|
36685
|
+
].join(`
|
|
36671
36686
|
|
|
36672
36687
|
`);
|
|
36688
|
+
return { text, shown: inWindow.slice(0, blocks.length) };
|
|
36673
36689
|
}
|
|
36674
36690
|
function failureSentence(reason) {
|
|
36675
36691
|
const text = reason.replace(/\s+/g, " ").trim();
|
|
@@ -36731,18 +36747,24 @@ async function readSessionAnswers(options) {
|
|
|
36731
36747
|
const entries = state.sessions.get(session) ?? new Map;
|
|
36732
36748
|
state.sessions.set(session, entries);
|
|
36733
36749
|
const carry = (cache, reason, noRoute = false) => {
|
|
36734
|
-
const
|
|
36750
|
+
const rendered = cache === undefined ? undefined : renderShown(cache.items, {
|
|
36735
36751
|
now: now(),
|
|
36736
36752
|
total: cache.total,
|
|
36737
36753
|
cached: { readAt: cache.read_at, reason },
|
|
36738
36754
|
withoutCommand: noRoute
|
|
36739
36755
|
});
|
|
36740
|
-
if (cache === undefined ||
|
|
36756
|
+
if (cache === undefined || rendered === undefined) {
|
|
36741
36757
|
if (noRoute)
|
|
36742
36758
|
return { text: undefined, source: "unavailable", reason };
|
|
36743
36759
|
return { text: sessionAnswersFailureLine(reason), source: "failure", reason };
|
|
36744
36760
|
}
|
|
36745
|
-
return {
|
|
36761
|
+
return {
|
|
36762
|
+
text: rendered.text,
|
|
36763
|
+
source: "cache",
|
|
36764
|
+
readAt: cache.read_at,
|
|
36765
|
+
words: sessionAnswersWords(rendered.shown),
|
|
36766
|
+
reason
|
|
36767
|
+
};
|
|
36746
36768
|
};
|
|
36747
36769
|
if (!dispatch.enabled) {
|
|
36748
36770
|
const url = options.dispatchUrl;
|
|
@@ -36832,13 +36854,12 @@ async function readSessionAnswers(options) {
|
|
|
36832
36854
|
return noRoute();
|
|
36833
36855
|
if ("failure" in outcome)
|
|
36834
36856
|
return carry(current.cache, outcome.failure);
|
|
36857
|
+
const rendered = renderShown(outcome.cache.items, { now: now(), total: outcome.cache.total });
|
|
36835
36858
|
return {
|
|
36836
|
-
text:
|
|
36837
|
-
now: now(),
|
|
36838
|
-
total: outcome.cache.total
|
|
36839
|
-
}),
|
|
36859
|
+
text: rendered?.text,
|
|
36840
36860
|
source: "fresh",
|
|
36841
|
-
readAt: outcome.cache.read_at
|
|
36861
|
+
readAt: outcome.cache.read_at,
|
|
36862
|
+
words: sessionAnswersWords(rendered?.shown ?? [])
|
|
36842
36863
|
};
|
|
36843
36864
|
}
|
|
36844
36865
|
|
|
@@ -38259,7 +38280,7 @@ var import_nats2 = __toESM(require_mod4(), 1);
|
|
|
38259
38280
|
|
|
38260
38281
|
// package.json
|
|
38261
38282
|
var name = "@sjawhar/pi-envoy";
|
|
38262
|
-
var version2 = "15.
|
|
38283
|
+
var version2 = "15.2.0";
|
|
38263
38284
|
var package_default = {
|
|
38264
38285
|
name,
|
|
38265
38286
|
version: version2,
|
|
@@ -39941,6 +39962,14 @@ function endsWithSessionAnswers(messages) {
|
|
|
39941
39962
|
const text = leadingText(messages.at(-1), "user");
|
|
39942
39963
|
return text !== undefined && isSessionAnswersText(text);
|
|
39943
39964
|
}
|
|
39965
|
+
function messageKey(message) {
|
|
39966
|
+
if (typeof message !== "object" || message === null)
|
|
39967
|
+
return "";
|
|
39968
|
+
const role = "role" in message ? String(message.role) : "";
|
|
39969
|
+
const timestamp = "timestamp" in message ? String(message.timestamp) : "";
|
|
39970
|
+
const call = "toolCallId" in message ? `#${String(message.toolCallId)}` : "";
|
|
39971
|
+
return `${role}@${timestamp}${call}`;
|
|
39972
|
+
}
|
|
39944
39973
|
function isSideTurn(messages) {
|
|
39945
39974
|
if (hostText(messages.at(-1), "user") === undefined)
|
|
39946
39975
|
return false;
|
|
@@ -39965,11 +39994,21 @@ function entryMessage2(entry) {
|
|
|
39965
39994
|
const timestamp = "timestamp" in entry && typeof entry.timestamp === "string" ? new Date(entry.timestamp).getTime() : undefined;
|
|
39966
39995
|
return { role, timestamp };
|
|
39967
39996
|
}
|
|
39997
|
+
function failedCalls(message) {
|
|
39998
|
+
if (message.role !== "assistant" || message.stopReason !== "error" && message.stopReason !== "aborted") {
|
|
39999
|
+
return [];
|
|
40000
|
+
}
|
|
40001
|
+
return (Array.isArray(message.content) ? message.content : []).flatMap((block) => typeof block === "object" && block !== null && ("type" in block) && block.type === "toolCall" && ("id" in block) ? [String(block.id)] : []);
|
|
40002
|
+
}
|
|
39968
40003
|
function branchPosition(messages, entries) {
|
|
39969
40004
|
const last = messages.at(-1);
|
|
39970
40005
|
if (typeof last !== "object" || last === null || !("timestamp" in last) || !("role" in last)) {
|
|
39971
40006
|
return { at: "absent" };
|
|
39972
40007
|
}
|
|
40008
|
+
const dropped = new Set(entries.flatMap((entry) => {
|
|
40009
|
+
const message = entryMessage2(entry);
|
|
40010
|
+
return message === undefined ? [] : failedCalls(message);
|
|
40011
|
+
}));
|
|
39973
40012
|
let later = false;
|
|
39974
40013
|
let tip;
|
|
39975
40014
|
for (let index = entries.length - 1;index >= 0; index -= 1) {
|
|
@@ -39981,7 +40020,7 @@ function branchPosition(messages, entries) {
|
|
|
39981
40020
|
if (message.role === last.role && message.timestamp === last.timestamp) {
|
|
39982
40021
|
return later ? { at: "before" } : { at: "last", tip };
|
|
39983
40022
|
}
|
|
39984
|
-
const failed = message.role === "assistant" && (message.stopReason === "error" || message.stopReason === "aborted");
|
|
40023
|
+
const failed = message.role === "assistant" && (message.stopReason === "error" || message.stopReason === "aborted") || message.role === "toolResult" && dropped.has(String(message.toolCallId));
|
|
39985
40024
|
if (!failed)
|
|
39986
40025
|
later = true;
|
|
39987
40026
|
}
|
|
@@ -39991,10 +40030,39 @@ var CONVERSIONS_KEY = Symbol.for("legion.pi-envoy.session-answers-conversions.v1
|
|
|
39991
40030
|
var conversionsGlobal = globalThis;
|
|
39992
40031
|
var conversions = conversionsGlobal[CONVERSIONS_KEY] ?? new WeakMap;
|
|
39993
40032
|
conversionsGlobal[CONVERSIONS_KEY] = conversions;
|
|
40033
|
+
var PLACEMENTS_KEY = Symbol.for("legion.pi-envoy.session-answers-placements.v1");
|
|
40034
|
+
var placementsGlobal = globalThis;
|
|
40035
|
+
var placements = placementsGlobal[PLACEMENTS_KEY] ?? new WeakMap;
|
|
40036
|
+
placementsGlobal[PLACEMENTS_KEY] = placements;
|
|
40037
|
+
function showsNew(shown, next) {
|
|
40038
|
+
if (shown.words === undefined || next.words === undefined)
|
|
40039
|
+
return shown.text !== next.text;
|
|
40040
|
+
const before = new Set(shown.words);
|
|
40041
|
+
return next.words.some((word) => !before.has(word));
|
|
40042
|
+
}
|
|
40043
|
+
function placeList(messages, carried, request, compacting) {
|
|
40044
|
+
const list = userTextMessage(carried.text);
|
|
40045
|
+
if (compacting)
|
|
40046
|
+
return [...messages, list];
|
|
40047
|
+
const sessions = placements.get(request.session) ?? new Map;
|
|
40048
|
+
placements.set(request.session, sessions);
|
|
40049
|
+
const placed = sessions.get(request.id);
|
|
40050
|
+
if (placed !== undefined && !showsNew(placed.carried, carried)) {
|
|
40051
|
+
const index = messages.findLastIndex((message) => messageKey(message) === placed.after);
|
|
40052
|
+
if (index >= 0) {
|
|
40053
|
+
sessions.set(request.id, { after: placed.after, carried });
|
|
40054
|
+
return [...messages.slice(0, index + 1), list, ...messages.slice(index + 1)];
|
|
40055
|
+
}
|
|
40056
|
+
}
|
|
40057
|
+
sessions.set(request.id, { after: messageKey(messages.at(-1)), carried });
|
|
40058
|
+
return [...messages, list];
|
|
40059
|
+
}
|
|
39994
40060
|
async function withSessionAnswers(messages, request) {
|
|
39995
|
-
if (decided.has(messages)
|
|
40061
|
+
if (decided.has(messages))
|
|
39996
40062
|
return;
|
|
39997
40063
|
decided.add(messages);
|
|
40064
|
+
if (endsWithSessionAnswers(messages))
|
|
40065
|
+
return placedLegacy(messages, request);
|
|
39998
40066
|
if (isSideTurn(messages) || hostText(messages.at(-1), "user")?.startsWith(HANDOFF_PROMPT) === true) {
|
|
39999
40067
|
return;
|
|
40000
40068
|
}
|
|
@@ -40004,19 +40072,30 @@ async function withSessionAnswers(messages, request) {
|
|
|
40004
40072
|
conversions.set(request.session, "cut");
|
|
40005
40073
|
return;
|
|
40006
40074
|
}
|
|
40007
|
-
const key = position.at === "last" ? [
|
|
40008
|
-
position.tip,
|
|
40009
|
-
...messages.map((message) => typeof message === "object" && message !== null ? `${"role" in message ? String(message.role) : ""}@${"timestamp" in message ? String(message.timestamp) : ""}` : "")
|
|
40010
|
-
].join(`
|
|
40075
|
+
const key = position.at === "last" ? [position.tip, ...messages.map(messageKey)].join(`
|
|
40011
40076
|
`) : undefined;
|
|
40012
40077
|
conversions.set(request.session, { key, afterCut: previous === "cut" });
|
|
40013
40078
|
if (key !== undefined && typeof previous === "object" && previous.key === key && !previous.afterCut && request.compacting()) {
|
|
40014
40079
|
return;
|
|
40015
40080
|
}
|
|
40016
|
-
const
|
|
40017
|
-
if (
|
|
40081
|
+
const carried = await request.read();
|
|
40082
|
+
if (carried === undefined)
|
|
40083
|
+
return;
|
|
40084
|
+
const placed = placeList(messages, carried, request, previous === "cut" || request.compacting());
|
|
40085
|
+
decided.add(placed);
|
|
40086
|
+
return placed;
|
|
40087
|
+
}
|
|
40088
|
+
function placedLegacy(messages, request) {
|
|
40089
|
+
const last = messages.at(-1);
|
|
40090
|
+
const text = leadingText(last, "user");
|
|
40091
|
+
const added = typeof last === "object" && last !== null && "timestamp" in last && last.timestamp === 0;
|
|
40092
|
+
if (text === undefined || !added)
|
|
40018
40093
|
return;
|
|
40019
|
-
|
|
40094
|
+
const recorded = conversions.get(request.session);
|
|
40095
|
+
const compacting = typeof recorded === "object" && recorded.afterCut || request.compacting();
|
|
40096
|
+
const placed = placeList(messages.slice(0, -1), { text }, request, compacting);
|
|
40097
|
+
decided.add(placed);
|
|
40098
|
+
return placed;
|
|
40020
40099
|
}
|
|
40021
40100
|
|
|
40022
40101
|
// src/side-turn.ts
|
|
@@ -45631,10 +45710,10 @@ ${REPLAYED_BTW_NOTE}`, frame.envelope, "inert");
|
|
|
45631
45710
|
});
|
|
45632
45711
|
if (read.notice !== undefined)
|
|
45633
45712
|
logger3.warn(`envoy: ${read.notice}`);
|
|
45634
|
-
return read.text;
|
|
45713
|
+
return read.text === undefined ? undefined : { text: read.text, words: read.words ?? [] };
|
|
45635
45714
|
} catch (error) {
|
|
45636
45715
|
logger3.warn(`envoy: people's answers could not be read: ${messageFor(error)}`);
|
|
45637
|
-
return sessionAnswersFailureLine(messageFor(error));
|
|
45716
|
+
return { text: sessionAnswersFailureLine(messageFor(error)), words: [] };
|
|
45638
45717
|
}
|
|
45639
45718
|
};
|
|
45640
45719
|
if (atStart.dispatch.enabled || inbound) {
|
|
@@ -45646,6 +45725,7 @@ ${REPLAYED_BTW_NOTE}`, frame.envelope, "inert");
|
|
|
45646
45725
|
const messages = await withSessionAnswers(withSkill ?? aged ?? event.messages, {
|
|
45647
45726
|
branch: () => context.sessionManager.getBranch?.() ?? [],
|
|
45648
45727
|
session: context.sessionManager,
|
|
45728
|
+
id: context.sessionManager.getSessionId(),
|
|
45649
45729
|
compacting: () => {
|
|
45650
45730
|
const live = liveAgentSession(context.sessionManager.getSessionId());
|
|
45651
45731
|
return live !== undefined && (("isCompacting" in live) && live.isCompacting === true || ("compactionSpeculation" in live) && live.compactionSpeculation === "running");
|
|
@@ -47,8 +47,7 @@ A claim, or `dispatch issue-update --route session:<your id>` (`--route ''` on r
|
|
|
47
47
|
|
|
48
48
|
## Close what you opened
|
|
49
49
|
|
|
50
|
-
-
|
|
51
|
-
- Retract an ask a new one replaces.
|
|
50
|
+
- Resolve your open ask (`dispatch resolve-ask`) the turn it turns needless: another answer, a later write, dropped work, a replacement. If a person said keep it open, say why in its thread; they close it.
|
|
52
51
|
|
|
53
52
|
## Structure over stream
|
|
54
53
|
|