@sjawhar/pi-envoy 17.23.0 → 17.24.1
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 +16 -9
- package/dist/dispatch.js +48 -9
- package/dist/envoy.js +39 -9
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -496,12 +496,12 @@ gated write only when it consumes one, so a write sent any other way is refused
|
|
|
496
496
|
help only: the gate refuses nothing for it.
|
|
497
497
|
- **The unmarked write that carries an ask.** The `unmarked` entry reaches only this machine's
|
|
498
498
|
disk. Where such a write carries at least one ask for a person, the CLI counts those asks from
|
|
499
|
-
the write's own text (`
|
|
500
|
-
into the session's ledger as `asksCarried`, and pi-envoy publishes one decision record
|
|
501
|
-
Dispatch (below), with the tool, the mode and that count and no ask text.
|
|
502
|
-
asks the write carries, so a re-upload of ask blocks the stored version
|
|
503
|
-
them as carried: in `warn` mode the write has already posted when the
|
|
504
|
-
of the stored version would see the new text and count nothing.
|
|
499
|
+
the write's own text (`newAskCount` in `@legion/envoy-client/askgate-new-asks`) and writes the
|
|
500
|
+
count into the session's ledger as `asksCarried`, and pi-envoy publishes one decision record
|
|
501
|
+
for it on Dispatch (below), with the tool, the mode and that count and no ask text.
|
|
502
|
+
The count is of the asks the write carries, so a re-upload of ask blocks the stored version
|
|
503
|
+
already holds counts them as carried: in `warn` mode the write has already posted when the
|
|
504
|
+
ledger is read, so a read of the stored version would see the new text and count nothing.
|
|
505
505
|
|
|
506
506
|
The gated writes are the same list for the gate and the CLI (`gatedWrite` in
|
|
507
507
|
`@legion/envoy-client/askgate-marker`): the six commands above, an `issue` with a spec and an
|
|
@@ -839,9 +839,16 @@ documents and prints the day's refusals by rule, the refusals the agent overrode
|
|
|
839
839
|
judged on part of their asks and those that judged none, the unmarked writes by mode with the asks
|
|
840
840
|
they carried, and the rules-call error rate, each split by `source`, with the documents and lines
|
|
841
841
|
it could not read, and the records it read twice, counted beside them. An unmarked write is in no
|
|
842
|
-
rules-call count and in no override count: no check judged it.
|
|
843
|
-
and ask block the write carries,
|
|
844
|
-
|
|
842
|
+
rules-call count and in no override count: no check judged it.
|
|
843
|
+
Its `asksCarried` counts each ask and ask block the write carries as one, and groups none of them
|
|
844
|
+
by id or by text, so two ask blocks that open with the same words count two.
|
|
845
|
+
`newAskCount` reads a `doc-edit` `replace`'s `with` as every string the server might parse it as,
|
|
846
|
+
and the server parses one of them, so a `replace` counts as the most asks any one of those
|
|
847
|
+
readings opens.
|
|
848
|
+
The count is taken before the write goes out, so it cannot know which reading the server takes,
|
|
849
|
+
and the largest can only over-count.
|
|
850
|
+
A re-upload of blocks a stored version already holds counts them as carried.
|
|
851
|
+
The same script's `--sessions <dir>` mode still reports the entries on disk, the
|
|
845
852
|
decision records not confirmed among them. Each flag is given once: the
|
|
846
853
|
script refuses a flag given twice by name, rather than reading only its last value.
|
|
847
854
|
|
package/dist/dispatch.js
CHANGED
|
@@ -1313,13 +1313,13 @@ function newAsks(toolName, input) {
|
|
|
1313
1313
|
case "dispatch_artifact":
|
|
1314
1314
|
return typeof input.content === "string" ? askBlocks(input.content) : [];
|
|
1315
1315
|
case "dispatch_doc_edit":
|
|
1316
|
-
return (
|
|
1317
|
-
|
|
1318
|
-
return [];
|
|
1319
|
-
const { op: kind, markdown, type, block } = op;
|
|
1316
|
+
return editOps(input).flatMap((op) => {
|
|
1317
|
+
const { op: kind, markdown, with: replacement, type, block } = op;
|
|
1320
1318
|
if (kind === "insert" && typeof markdown === "string") {
|
|
1321
|
-
|
|
1322
|
-
|
|
1319
|
+
return scanAsks(markdown, op.before === "start" || op.after === "start");
|
|
1320
|
+
}
|
|
1321
|
+
if (kind === "replace" && typeof replacement === "string") {
|
|
1322
|
+
return replacementAsks(replacement);
|
|
1323
1323
|
}
|
|
1324
1324
|
if (kind === "retype" && type === "ask" && typeof block === "string") {
|
|
1325
1325
|
return [{ kind: "retype", id: block, text: "", opening: "" }];
|
|
@@ -1330,6 +1330,18 @@ function newAsks(toolName, input) {
|
|
|
1330
1330
|
return [];
|
|
1331
1331
|
}
|
|
1332
1332
|
}
|
|
1333
|
+
function newAskCount(toolName, input) {
|
|
1334
|
+
if (toolName !== "dispatch_doc_edit")
|
|
1335
|
+
return newAsks(toolName, input).length;
|
|
1336
|
+
let count = 0;
|
|
1337
|
+
for (const op of editOps(input)) {
|
|
1338
|
+
count += op.op === "replace" && typeof op.with === "string" ? Math.max(...replacementReadings(op.with).map((text) => scanAsks(text, false).length)) : newAsks(toolName, { ops: [op] }).length;
|
|
1339
|
+
}
|
|
1340
|
+
return count;
|
|
1341
|
+
}
|
|
1342
|
+
function editOps(input) {
|
|
1343
|
+
return (Array.isArray(input.ops) ? input.ops : []).filter((op) => typeof op === "object" && op !== null);
|
|
1344
|
+
}
|
|
1333
1345
|
function questionAsk(input) {
|
|
1334
1346
|
const question = typeof input.question === "string" ? input.question.trim() : "";
|
|
1335
1347
|
const options = (Array.isArray(input.options) ? input.options : []).flatMap((option) => {
|
|
@@ -1394,6 +1406,30 @@ function scanAsks(markdown, frontMatter) {
|
|
|
1394
1406
|
return { kind: "block", ...id === undefined ? {} : { id }, text, opening: openingOf(text) };
|
|
1395
1407
|
});
|
|
1396
1408
|
}
|
|
1409
|
+
function replacementAsks(replacement) {
|
|
1410
|
+
const variants = new Map;
|
|
1411
|
+
for (const reading of replacementReadings(replacement)) {
|
|
1412
|
+
for (const ask of scanAsks(reading, false)) {
|
|
1413
|
+
const key = JSON.stringify([ask.id ?? null, ask.text]);
|
|
1414
|
+
if (!variants.has(key))
|
|
1415
|
+
variants.set(key, ask);
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1418
|
+
const found = [...variants.values()];
|
|
1419
|
+
const idsWithText = new Set(found.flatMap((ask) => ask.text !== "" && ask.id !== undefined ? [ask.id] : []));
|
|
1420
|
+
const anyText = found.some((ask) => ask.text !== "");
|
|
1421
|
+
return found.filter((ask) => ask.text !== "" || (ask.id === undefined ? !anyText : !idsWithText.has(ask.id)));
|
|
1422
|
+
}
|
|
1423
|
+
function replacementReadings(replacement) {
|
|
1424
|
+
const readings = [replacement];
|
|
1425
|
+
let text = replacement;
|
|
1426
|
+
for (let strip = LEADING_STRIP.exec(text);strip !== null; strip = LEADING_STRIP.exec(text)) {
|
|
1427
|
+
text = text.slice(strip[0].length);
|
|
1428
|
+
readings.push(text);
|
|
1429
|
+
}
|
|
1430
|
+
return readings;
|
|
1431
|
+
}
|
|
1432
|
+
var LEADING_STRIP = /^(?:[ \t]*(?:#{1,6}|[0-9]{1,9}[.)]|[-*+])[ \t]+|\[[ xX]\][ \t]+)/u;
|
|
1397
1433
|
|
|
1398
1434
|
class Line {
|
|
1399
1435
|
text;
|
|
@@ -15435,7 +15471,7 @@ var dispatchToolSpecs = [
|
|
|
15435
15471
|
ops: [{ op: "delete_column", block: "table-123", index: 1 }],
|
|
15436
15472
|
precondition: { blocks: [{ id: "table-123", token: "sha256:current-table-token" }] }
|
|
15437
15473
|
},
|
|
15438
|
-
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
|
|
15474
|
+
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 parses with as markdown, as insert parses its markdown: a with that parses to one paragraph is the new text of the matched span, and one that parses to blocks ('---' over a paragraph, a list, a table, two paragraphs) writes those blocks where the match sits, so a marker of a different kind from the block's own opens the block it names ('4. Design' is an ordered list, which a heading cannot hold) unless you escape it ('4\\. Design'). 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 - 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. " + "The blocks a with writes are refused, with the document unchanged, where the block holding the match cannot hold them: a heading and any cell of a table, which hold one line of text, and a typed block whose content rule they break - write that block's new text alone, and insert the blocks beside it. A hard break in with is 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. " + `${CI_CHECK_RULE} ` + "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. " + "Several paragraphs, or a list, go in one replace, since with writes the blocks its markdown names; blocks beside a block go in one insert, since two inserts at one anchor come out reversed. The result prints the markdown of each block the edit wrote, so read that rather than the document again. " + "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}`,
|
|
15439
15475
|
arguments: (z) => ({
|
|
15440
15476
|
issue: z.string().describe(ISSUE_REFERENCE).optional(),
|
|
15441
15477
|
project: z.string().describe("Project key owning the document.").optional(),
|
|
@@ -15444,7 +15480,7 @@ var dispatchToolSpecs = [
|
|
|
15444
15480
|
ops: z.array(z.object({
|
|
15445
15481
|
op: z.enum(DOC_EDIT_OPS).describe("Edit operation."),
|
|
15446
15482
|
find: z.string().describe("Text of the target as rendered, for replace or delete; inline markdown (**bold**, `code`) is tolerated and must be balanced; a leading '# ' matches a heading. A delete of a block's entire text removes the block.").optional(),
|
|
15447
|
-
with: z.string().describe("Replacement text for replace: inside a code block, the code's literal text as sent (line breaks at its end do not survive a read);
|
|
15483
|
+
with: z.string().describe("Replacement text for replace: inside a code block, the code's literal text as sent (line breaks at its end do not survive a read); elsewhere parsed as markdown, as insert's markdown is. Text that parses to one paragraph is written inside the matched block, where a backslash escape keeps prose that merely looks like a marker, a leading '[x] ' or '[ ] ' over a task item's text matched from its start sets the item's checkbox, and any non-empty value that renders to no text is refused - only an empty value deletes the match. Text that parses to blocks ('---' over a paragraph, a list, a table, two paragraphs) writes those blocks where the match sits, fitted as the editor fits them, and is refused, with the document unchanged, where the block holding the match cannot hold them: a heading, any cell of a table, and a typed block whose content rule they break. A leading marker of the same kind as the matched block's own is refused either way, since the block renders it already, unless it is a heading rename (where a level named by find is what lets with change it) or an item find's own marker selected. A CR LF or a lone carriage return in it is written as a line feed.").optional(),
|
|
15448
15484
|
occurrence: z.number({ int: true, min: 0 }).describe("Optional zero-based match occurrence.").optional(),
|
|
15449
15485
|
markdown: z.string().describe("Markdown to insert; a CR LF or a lone carriage return in it is written as a line feed.").optional(),
|
|
15450
15486
|
after: z.string().describe(`Insert or move after this anchor: a quote of the neighbouring block's text, or one of "start", "end", "heading:<exact heading text>", "block:<id>".`).optional(),
|
|
@@ -22417,12 +22453,15 @@ async function docEditCommand(context) {
|
|
|
22417
22453
|
});
|
|
22418
22454
|
const declinedLines = resolved.issue === undefined ? [] : declinedAskLines(edited.advice, resolved.issue.key, linkBase);
|
|
22419
22455
|
const adviceLines = await otherAdviceLines(() => renderAdvice(input.tool, resolvedTopic(resolved).label, edited.advice, {}));
|
|
22456
|
+
const written = edited.written;
|
|
22457
|
+
const writtenLines = written === undefined || written === "" ? [] : [written];
|
|
22420
22458
|
const tokenTrailer = edited.token === undefined ? [] : [`Document token: ${edited.token}`];
|
|
22421
22459
|
return {
|
|
22422
22460
|
text: [
|
|
22423
22461
|
`${applied}${await notSubscribed(resolvedTopic(resolved), input.subscriptions)}`,
|
|
22424
22462
|
...checkLines,
|
|
22425
22463
|
...declinedLines,
|
|
22464
|
+
...writtenLines,
|
|
22426
22465
|
...tokenTrailer,
|
|
22427
22466
|
...adviceLines
|
|
22428
22467
|
].join(`
|
|
@@ -28233,7 +28272,7 @@ async function runDispatchCli(argv, rawEnv, io) {
|
|
|
28233
28272
|
uploadBytes = bytes;
|
|
28234
28273
|
}
|
|
28235
28274
|
const spent = consumeMarker(gate.stores, argv, parsed.args, files, Date.now());
|
|
28236
|
-
const asksCarried = spent.ok ? 0 :
|
|
28275
|
+
const asksCarried = spent.ok ? 0 : newAskCount(parsed.tool, uploadBytes === undefined ? parsed.args : { ...parsed.args, content: new TextDecoder().decode(uploadBytes) });
|
|
28237
28276
|
if (!spent.ok && gate.mode === "block") {
|
|
28238
28277
|
return refuse(spent.changed === undefined ? `${notCalled} AskGate is on for this session, and ${spent.why}. ${LITERAL_FORM} Send the write again in that form, as a bash call of its own.` : `${notCalled} AskGate is on for this session, and ${spent.why}. ${SAME_MESSAGE} Send the call again in a later message than the one that changes the file.`, REFUSED, parsed.tool, { mode: "block", why: spent.why, asksCarried });
|
|
28239
28278
|
}
|
package/dist/envoy.js
CHANGED
|
@@ -30528,7 +30528,7 @@ var dispatchToolSpecs = [
|
|
|
30528
30528
|
ops: [{ op: "delete_column", block: "table-123", index: 1 }],
|
|
30529
30529
|
precondition: { blocks: [{ id: "table-123", token: "sha256:current-table-token" }] }
|
|
30530
30530
|
},
|
|
30531
|
-
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
|
|
30531
|
+
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 parses with as markdown, as insert parses its markdown: a with that parses to one paragraph is the new text of the matched span, and one that parses to blocks ('---' over a paragraph, a list, a table, two paragraphs) writes those blocks where the match sits, so a marker of a different kind from the block's own opens the block it names ('4. Design' is an ordered list, which a heading cannot hold) unless you escape it ('4\\. Design'). 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 - 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. " + "The blocks a with writes are refused, with the document unchanged, where the block holding the match cannot hold them: a heading and any cell of a table, which hold one line of text, and a typed block whose content rule they break - write that block's new text alone, and insert the blocks beside it. A hard break in with is 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. " + `${CI_CHECK_RULE} ` + "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. " + "Several paragraphs, or a list, go in one replace, since with writes the blocks its markdown names; blocks beside a block go in one insert, since two inserts at one anchor come out reversed. The result prints the markdown of each block the edit wrote, so read that rather than the document again. " + "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}`,
|
|
30532
30532
|
arguments: (z) => ({
|
|
30533
30533
|
issue: z.string().describe(ISSUE_REFERENCE).optional(),
|
|
30534
30534
|
project: z.string().describe("Project key owning the document.").optional(),
|
|
@@ -30537,7 +30537,7 @@ var dispatchToolSpecs = [
|
|
|
30537
30537
|
ops: z.array(z.object({
|
|
30538
30538
|
op: z.enum(DOC_EDIT_OPS).describe("Edit operation."),
|
|
30539
30539
|
find: z.string().describe("Text of the target as rendered, for replace or delete; inline markdown (**bold**, `code`) is tolerated and must be balanced; a leading '# ' matches a heading. A delete of a block's entire text removes the block.").optional(),
|
|
30540
|
-
with: z.string().describe("Replacement text for replace: inside a code block, the code's literal text as sent (line breaks at its end do not survive a read);
|
|
30540
|
+
with: z.string().describe("Replacement text for replace: inside a code block, the code's literal text as sent (line breaks at its end do not survive a read); elsewhere parsed as markdown, as insert's markdown is. Text that parses to one paragraph is written inside the matched block, where a backslash escape keeps prose that merely looks like a marker, a leading '[x] ' or '[ ] ' over a task item's text matched from its start sets the item's checkbox, and any non-empty value that renders to no text is refused - only an empty value deletes the match. Text that parses to blocks ('---' over a paragraph, a list, a table, two paragraphs) writes those blocks where the match sits, fitted as the editor fits them, and is refused, with the document unchanged, where the block holding the match cannot hold them: a heading, any cell of a table, and a typed block whose content rule they break. A leading marker of the same kind as the matched block's own is refused either way, since the block renders it already, unless it is a heading rename (where a level named by find is what lets with change it) or an item find's own marker selected. A CR LF or a lone carriage return in it is written as a line feed.").optional(),
|
|
30541
30541
|
occurrence: z.number({ int: true, min: 0 }).describe("Optional zero-based match occurrence.").optional(),
|
|
30542
30542
|
markdown: z.string().describe("Markdown to insert; a CR LF or a lone carriage return in it is written as a line feed.").optional(),
|
|
30543
30543
|
after: z.string().describe(`Insert or move after this anchor: a quote of the neighbouring block's text, or one of "start", "end", "heading:<exact heading text>", "block:<id>".`).optional(),
|
|
@@ -42881,12 +42881,15 @@ async function docEditCommand(context) {
|
|
|
42881
42881
|
});
|
|
42882
42882
|
const declinedLines = resolved.issue === undefined ? [] : declinedAskLines(edited.advice, resolved.issue.key, linkBase);
|
|
42883
42883
|
const adviceLines = await otherAdviceLines(() => renderAdvice(input.tool, resolvedTopic(resolved).label, edited.advice, {}));
|
|
42884
|
+
const written = edited.written;
|
|
42885
|
+
const writtenLines = written === undefined || written === "" ? [] : [written];
|
|
42884
42886
|
const tokenTrailer = edited.token === undefined ? [] : [`Document token: ${edited.token}`];
|
|
42885
42887
|
return {
|
|
42886
42888
|
text: [
|
|
42887
42889
|
`${applied}${await notSubscribed(resolvedTopic(resolved), input.subscriptions)}`,
|
|
42888
42890
|
...checkLines,
|
|
42889
42891
|
...declinedLines,
|
|
42892
|
+
...writtenLines,
|
|
42890
42893
|
...tokenTrailer,
|
|
42891
42894
|
...adviceLines
|
|
42892
42895
|
].join(`
|
|
@@ -46729,7 +46732,7 @@ var import_nats2 = __toESM(require_mod4(), 1);
|
|
|
46729
46732
|
|
|
46730
46733
|
// package.json
|
|
46731
46734
|
var name = "@sjawhar/pi-envoy";
|
|
46732
|
-
var version2 = "17.
|
|
46735
|
+
var version2 = "17.24.1";
|
|
46733
46736
|
var package_default = {
|
|
46734
46737
|
name,
|
|
46735
46738
|
version: version2,
|
|
@@ -48665,13 +48668,13 @@ function newAsks(toolName, input) {
|
|
|
48665
48668
|
case "dispatch_artifact":
|
|
48666
48669
|
return typeof input.content === "string" ? askBlocks(input.content) : [];
|
|
48667
48670
|
case "dispatch_doc_edit":
|
|
48668
|
-
return (
|
|
48669
|
-
|
|
48670
|
-
return [];
|
|
48671
|
-
const { op: kind, markdown, type, block } = op;
|
|
48671
|
+
return editOps(input).flatMap((op) => {
|
|
48672
|
+
const { op: kind, markdown, with: replacement, type, block } = op;
|
|
48672
48673
|
if (kind === "insert" && typeof markdown === "string") {
|
|
48673
|
-
|
|
48674
|
-
|
|
48674
|
+
return scanAsks(markdown, op.before === "start" || op.after === "start");
|
|
48675
|
+
}
|
|
48676
|
+
if (kind === "replace" && typeof replacement === "string") {
|
|
48677
|
+
return replacementAsks(replacement);
|
|
48675
48678
|
}
|
|
48676
48679
|
if (kind === "retype" && type === "ask" && typeof block === "string") {
|
|
48677
48680
|
return [{ kind: "retype", id: block, text: "", opening: "" }];
|
|
@@ -48682,6 +48685,9 @@ function newAsks(toolName, input) {
|
|
|
48682
48685
|
return [];
|
|
48683
48686
|
}
|
|
48684
48687
|
}
|
|
48688
|
+
function editOps(input) {
|
|
48689
|
+
return (Array.isArray(input.ops) ? input.ops : []).filter((op) => typeof op === "object" && op !== null);
|
|
48690
|
+
}
|
|
48685
48691
|
function questionAsk(input) {
|
|
48686
48692
|
const question = typeof input.question === "string" ? input.question.trim() : "";
|
|
48687
48693
|
const options = (Array.isArray(input.options) ? input.options : []).flatMap((option) => {
|
|
@@ -48746,6 +48752,30 @@ function scanAsks(markdown, frontMatter) {
|
|
|
48746
48752
|
return { kind: "block", ...id === undefined ? {} : { id }, text, opening: openingOf(text) };
|
|
48747
48753
|
});
|
|
48748
48754
|
}
|
|
48755
|
+
function replacementAsks(replacement) {
|
|
48756
|
+
const variants = new Map;
|
|
48757
|
+
for (const reading of replacementReadings(replacement)) {
|
|
48758
|
+
for (const ask of scanAsks(reading, false)) {
|
|
48759
|
+
const key = JSON.stringify([ask.id ?? null, ask.text]);
|
|
48760
|
+
if (!variants.has(key))
|
|
48761
|
+
variants.set(key, ask);
|
|
48762
|
+
}
|
|
48763
|
+
}
|
|
48764
|
+
const found = [...variants.values()];
|
|
48765
|
+
const idsWithText = new Set(found.flatMap((ask) => ask.text !== "" && ask.id !== undefined ? [ask.id] : []));
|
|
48766
|
+
const anyText = found.some((ask) => ask.text !== "");
|
|
48767
|
+
return found.filter((ask) => ask.text !== "" || (ask.id === undefined ? !anyText : !idsWithText.has(ask.id)));
|
|
48768
|
+
}
|
|
48769
|
+
function replacementReadings(replacement) {
|
|
48770
|
+
const readings = [replacement];
|
|
48771
|
+
let text = replacement;
|
|
48772
|
+
for (let strip = LEADING_STRIP.exec(text);strip !== null; strip = LEADING_STRIP.exec(text)) {
|
|
48773
|
+
text = text.slice(strip[0].length);
|
|
48774
|
+
readings.push(text);
|
|
48775
|
+
}
|
|
48776
|
+
return readings;
|
|
48777
|
+
}
|
|
48778
|
+
var LEADING_STRIP = /^(?:[ \t]*(?:#{1,6}|[0-9]{1,9}[.)]|[-*+])[ \t]+|\[[ xX]\][ \t]+)/u;
|
|
48749
48779
|
|
|
48750
48780
|
class Line {
|
|
48751
48781
|
text;
|