@sjawhar/claude-envoy 5.4.1 → 5.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/.omp-plugin/plugin.json +1 -1
- package/dist/codex-hook.js +386 -38
- package/dist/dispatch.js +2029 -1783
- package/dist/envoy-channel.js +388 -40
- package/dist/session-hook.js +612 -64
- package/hooks/session-hook.ts +73 -27
- package/legion/agents/plan-reviewer.md +1 -1
- package/package.json +1 -1
- package/src/codex/codex-session-record.ts +18 -10
package/.omp-plugin/plugin.json
CHANGED
package/dist/codex-hook.js
CHANGED
|
@@ -14068,7 +14068,7 @@ var DOCUMENT_IS_MARKDOWN = "a document holds Markdown, which rewrites other text
|
|
|
14068
14068
|
var PATH_KEEPS_BYTES = "path (--path <file>), which stores a file whose path does not end in .md or .markdown as its bytes, unchanged";
|
|
14069
14069
|
var ARTIFACT_CONTENT_NAME_RULE = `${CONTENT_IS_MARKDOWN}, so a document's name ends in .md or .markdown or has no extension, under content and under neither flag alike; upload any other file (.jsonl, .tsv, .json, .txt) with ${PATH_KEEPS_BYTES}.`;
|
|
14070
14070
|
var ARTIFACT_NAME_EXISTS_RULE = `An upload under the name of a document the owner already holds is refused: it writes that document's next version, over the text it holds. Change a document with dispatch doc-edit. To write the next version, send the upload again with force (--force) and the token of the version it replaces (--precondition-json '{"document":"sha256:\u2026"}', the token dispatch doc-read prints).`;
|
|
14071
|
-
var ARTIFACT_STORED_TEXT_RULE = `content and content-file hold text Dispatch stores as Markdown, and a text the store would write under another spelling is refused. The refusal prints the text Dispatch stores: send that text. A name that does not end in .md or .markdown has a second way out, which keeps the text as it was written: send it as a file with ${PATH_KEEPS_BYTES}.`;
|
|
14071
|
+
var ARTIFACT_STORED_TEXT_RULE = `content and content-file hold text Dispatch stores as Markdown, and a text the store would write under another spelling is refused. A typed block whose attributes differ from Dispatch's only in their order is not refused: the command uploads it with them in Dispatch's order and names each such block. A refusal names the first difference: a changed line by the attribute or the word that differs, a word of more than 200 characters by a window from its first character that differs, and a line the store adds or drops by a quote cut at 200 characters, each cut named. The refusal prints the text Dispatch stores: send that text. A name that does not end in .md or .markdown has a second way out, which keeps the text as it was written: send it as a file with ${PATH_KEEPS_BYTES}.`;
|
|
14072
14072
|
var NAME_EXTENSION = /\.([^\s.]+)$/u;
|
|
14073
14073
|
var MARKDOWN_EXTENSION = /^(md|markdown)$/i;
|
|
14074
14074
|
function preconditionArgument(z) {
|
|
@@ -14370,7 +14370,7 @@ var dispatchToolSpecs = [
|
|
|
14370
14370
|
{
|
|
14371
14371
|
name: "dispatch_issue",
|
|
14372
14372
|
example: { project: "DSP", title: "Native workspace" },
|
|
14373
|
-
description: "Create a native Dispatch issue for newly tracked work. Search first with dispatch search; if potentially duplicate issues exist, this returns 409 POSSIBLE_DUPLICATE unless --force is set after reading them, or, when the refusal cannot be recorded, creates the issue and names the near copy to read in the result. " + "
|
|
14373
|
+
description: "Create a native Dispatch issue for newly tracked work. Search first with dispatch search; if potentially duplicate issues exist, this returns 409 POSSIBLE_DUPLICATE unless --force is set after reading them, or, when the refusal cannot be recorded, creates the issue and names the near copy to read in the result. " + "Where the spec is large, or changed in a way you cannot check alone, a fresh read-only reader can find its gaps and check its factual claims; a Legion architect can use `plan-gap-analyst` and `plan-reviewer`. " + "A spec holding an ask block whose body breaks its content rule (one or more question paragraphs, then at most one bullet list of options, last) is refused with 400 INVALID_ASK_BLOCK. " + `${CI_CHECK_RULE} ` + "Create a project only when a person asks for one; work that spans projects goes in the project that owns most of it. " + `${RELATED_CHECK_RESULT} With --force, the result also names each issue whose title you forced past. ` + `Do not use it when an existing issue already covers the work; read or update that issue instead. ${ISSUE_REFERENCE}`,
|
|
14374
14374
|
arguments: (z) => ({
|
|
14375
14375
|
project: z.string().describe("Project key for the new issue."),
|
|
14376
14376
|
title: z.string({ max: ISSUE_TITLE_MAX }).describe("Concise issue title, at most 1,000 characters."),
|
|
@@ -14655,12 +14655,12 @@ var dispatchToolSpecs = [
|
|
|
14655
14655
|
{
|
|
14656
14656
|
name: "dispatch_request_approval",
|
|
14657
14657
|
example: { issue: "DSP-1", summary: "A live sync replaces the nightly export." },
|
|
14658
|
-
description: "Ask a human to approve a document at its current version.
|
|
14658
|
+
description: "Ask a human to approve a document at its current version. Where the spec is large, or changed in a way you cannot check alone, a fresh read-only reader can find its gaps and check its factual claims; a Legion architect can use `plan-gap-analyst` and `plan-reviewer`. Opens an approval ask (Approve / " + "Request changes) in the human's Inbox whose question names the document and version, " + "followed by the summary; the answer pins a review to that version and arrives as " + "artifact.approved or artifact.changes_requested. " + "The request reaches the person it was handed to, else the issue's assignee, else the " + "project's default assignee, so it always reaches a person, and this tool's answer names " + "that person. " + "An open request follows the document: a " + "later version moves it to that version and leaves it waiting on you, as a human's reply in " + "its thread does. Only the first move since the request was opened or handed back sends an " + "event, and never to the session whose version made it; dispatch doc-read shows whom it " + "waits on. Once the revision is complete and " + HUMAN_AGREED_TO_DOCUMENT + ", call this again to hand that same Inbox row back. The request carries nothing new. A " + "call while it already waits on the human hands nothing back: the same summary changes " + "nothing, and a different one is refused, since it would rewrite the card the human is " + "reading. Approve and Request changes each close the request, so the next call opens a new " + "one. Call it once per revision, when the revision is complete, never after each edit. An " + "approval goes stale when the document changes outside its decision blocks after it, until " + "a later version's text is exactly the approved version's again, as when an accidental " + "edit is undone exactly, and no decision block in it was decided since: that version " + "carries the approval and the document reads approved at it, so nothing is requested for " + "it. When the document does not read approved, request approval again once that revision " + "is complete and " + HUMAN_AGREED_TO_DOCUMENT + ", with a one-sentence summary naming what changed since the earlier approval: the card " + "names that approval (version, date, reviewer) and its Show diff control carries the detail. " + "A human's own answer to a decision block carries the approval to the version it writes when " + "that answer is the whole change since the approved version, so nothing is requested for " + "it. A new version of a Legion root spec closes its armed design gate until a human " + "approves it; a carried approval reopens it too. " + "Refused, with nothing sent, while the document holds an open decision block, even when a " + "human asked for approval: the refusal names each block; ask the human to answer or waive " + "it first. " + "Refused 409 PLAN_APPROVED_BY_REVIEW on an issue's plan, which its plan review approves " + "(dispatch plan-approve), never a person. " + "On an issue's spec the answer ends with a `Coverage of <name>:` line naming each requirement " + "the spec marks that no check serves, in any document of the issue or of its descendants, or saying " + "the spec marks no requirements; a spec every requirement of which has a check gets no such line. It never " + "names a missing plan task, and a gap refuses nothing. " + OWNER_REFERENCE,
|
|
14659
14659
|
arguments: (z) => ({
|
|
14660
14660
|
issue: z.string().describe(ISSUE_REFERENCE).optional(),
|
|
14661
14661
|
project: z.string().describe("Project key owning the document.").optional(),
|
|
14662
14662
|
artifact: z.string().describe("Project document artifact id, slug, or filename; primary document by default for an issue.").optional(),
|
|
14663
|
-
summary: z.string({ min: 1 }).describe(`What the human is approving, in one to three sentences, and nothing else: no commentary on itself or the conversation, and no question; after an earlier approval, one sentence naming what changed since it, since the card shows that approval and a diff.
|
|
14663
|
+
summary: z.string({ min: 1 }).describe(`What the human is approving, in one to three sentences, and nothing else: no commentary on itself or the conversation, and no question; after an earlier approval, one sentence naming what changed since it, since the card shows that approval and a diff. Request approval only once ${HUMAN_AGREED_TO_DOCUMENT}.`),
|
|
14664
14664
|
include_verification: z.boolean().describe("Ask for the issue's Verification document in the same request, beside this one: one Inbox card names both at their current versions, and the answer records the human's review on each. 409 NO_VERIFICATION_DOCUMENT when the issue has no verification.md. Without it the request names this document alone and records nothing on the Verification document.").optional()
|
|
14665
14665
|
}),
|
|
14666
14666
|
validation: documentOwnerValidation(true)
|
|
@@ -14742,7 +14742,7 @@ var dispatchToolSpecs = [
|
|
|
14742
14742
|
project: z.string().describe("Project key for an unlinked document.").optional(),
|
|
14743
14743
|
name: z.string().describe("Artifact filename shown in Dispatch."),
|
|
14744
14744
|
path: z.string().describe("Local path to the file to upload.").optional(),
|
|
14745
|
-
content: z.string().describe("Inline text to store as a Markdown document, under a name ending in .md or .markdown or with no extension. The command refuses a text the store would write under another spelling, a CR LF or a lone carriage return among them, which Dispatch stores as a line feed. A missing line feed at the end is not such a text: Dispatch adds one, and the upload goes on. The refusal prints the text Dispatch stores, which is the text to send.").optional(),
|
|
14745
|
+
content: z.string().describe("Inline text to store as a Markdown document, under a name ending in .md or .markdown or with no extension. The command refuses a text the store would write under another spelling, a CR LF or a lone carriage return among them, which Dispatch stores as a line feed. A missing line feed at the end is not such a text: Dispatch adds one, and the upload goes on. Nor is a typed block whose attributes differ only in their order: the upload puts them in Dispatch's order. The refusal names the first difference: a changed line by the attribute or the word that differs, a word of more than 200 characters by a window from its first character that differs, and a line the store adds or drops by a quote cut at 200 characters, each cut named. It prints the text Dispatch stores, which is the text to send.").optional(),
|
|
14746
14746
|
force: z.boolean().describe("Write the next version of a document the owner already holds under this name; without it the upload of a name that exists is refused.").optional(),
|
|
14747
14747
|
precondition: uploadPreconditionArgument(z),
|
|
14748
14748
|
summary: z.string().describe("Optional version summary.").optional()
|
|
@@ -19253,6 +19253,13 @@ function readSecretFile(variable, filePath) {
|
|
|
19253
19253
|
|
|
19254
19254
|
// ../envoy-client/src/envoy-config.ts
|
|
19255
19255
|
var COMMAND_TIMEOUT_MS = 1e4;
|
|
19256
|
+
var COMMAND_TIMEOUT_VARIABLE = "ENVOY_COMMAND_TIMEOUT_MS";
|
|
19257
|
+
var LONGEST_TIMEOUT_MS = 2147483647;
|
|
19258
|
+
function commandTimeoutMs(env) {
|
|
19259
|
+
const text = env[COMMAND_TIMEOUT_VARIABLE] ?? "";
|
|
19260
|
+
const ms = /^[1-9]\d*$/.test(text) ? Number(text) : Number.NaN;
|
|
19261
|
+
return ms <= LONGEST_TIMEOUT_MS ? ms : COMMAND_TIMEOUT_MS;
|
|
19262
|
+
}
|
|
19256
19263
|
function nonEmpty(value) {
|
|
19257
19264
|
return value === undefined || value === "" ? undefined : value;
|
|
19258
19265
|
}
|
|
@@ -19411,6 +19418,7 @@ var processGlobal = globalThis;
|
|
|
19411
19418
|
var commandOutcomes = processGlobal[COMMAND_OUTCOMES] ?? new Map;
|
|
19412
19419
|
processGlobal[COMMAND_OUTCOMES] = commandOutcomes;
|
|
19413
19420
|
function runCommand(command, env, cwd) {
|
|
19421
|
+
const timeoutMs = commandTimeoutMs(env);
|
|
19414
19422
|
const childEnv = {};
|
|
19415
19423
|
for (const [name, variable] of Object.entries(env)) {
|
|
19416
19424
|
if (variable !== undefined)
|
|
@@ -19429,7 +19437,7 @@ function runCommand(command, env, cwd) {
|
|
|
19429
19437
|
stdin: "ignore",
|
|
19430
19438
|
stdout: fd,
|
|
19431
19439
|
stderr: "ignore",
|
|
19432
|
-
timeout:
|
|
19440
|
+
timeout: timeoutMs,
|
|
19433
19441
|
detached: true
|
|
19434
19442
|
});
|
|
19435
19443
|
} catch (error) {
|
|
@@ -19442,7 +19450,7 @@ function runCommand(command, env, cwd) {
|
|
|
19442
19450
|
} catch {}
|
|
19443
19451
|
if (result.exitedDueToTimeout) {
|
|
19444
19452
|
return {
|
|
19445
|
-
failure: `did not finish within ${
|
|
19453
|
+
failure: `did not finish within ${timeoutMs / 1000} s, and does not run again in this process`,
|
|
19446
19454
|
timedOut: true
|
|
19447
19455
|
};
|
|
19448
19456
|
}
|
|
@@ -25451,27 +25459,327 @@ import { resolve as resolvePath2 } from "path";
|
|
|
25451
25459
|
// ../contracts/src/go-blank.ts
|
|
25452
25460
|
var goBlankPattern = /^[\t\n\v\f\r \u0085\u00A0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000]*$/u;
|
|
25453
25461
|
|
|
25454
|
-
// ../envoy-client/src/
|
|
25455
|
-
function
|
|
25456
|
-
|
|
25457
|
-
|
|
25462
|
+
// ../envoy-client/src/typed-block-opener.ts
|
|
25463
|
+
function runOf(text, index, char) {
|
|
25464
|
+
let end = index;
|
|
25465
|
+
while (text.charAt(end) === char)
|
|
25466
|
+
end++;
|
|
25467
|
+
return end - index;
|
|
25468
|
+
}
|
|
25469
|
+
function directiveNameChar(char) {
|
|
25470
|
+
return /^[A-Za-z0-9_-]$/.test(char);
|
|
25471
|
+
}
|
|
25472
|
+
function typedFenceBrace(text, at) {
|
|
25473
|
+
const nameStart = at + runOf(text, at, ":");
|
|
25474
|
+
if (nameStart - at < 3)
|
|
25475
|
+
return -1;
|
|
25476
|
+
let brace = nameStart;
|
|
25477
|
+
while (directiveNameChar(text.charAt(brace)))
|
|
25478
|
+
brace++;
|
|
25479
|
+
return brace > nameStart && text.charAt(brace) === "{" ? brace : -1;
|
|
25480
|
+
}
|
|
25481
|
+
function typedOpenerAt(text, at) {
|
|
25482
|
+
const brace = typedFenceBrace(text, at);
|
|
25483
|
+
if (brace === -1 || !text.endsWith("}"))
|
|
25484
|
+
return;
|
|
25485
|
+
const attributes = directiveAttributes(text.slice(brace + 1, -1));
|
|
25486
|
+
if (attributes === undefined)
|
|
25487
|
+
return;
|
|
25488
|
+
const colons = runOf(text, at, ":");
|
|
25489
|
+
return { ...attributes, name: text.slice(at + colons, brace), colons };
|
|
25490
|
+
}
|
|
25491
|
+
function refusedDirective(text) {
|
|
25492
|
+
if (text.startsWith(":::"))
|
|
25493
|
+
return text !== ":::" && typedOpenerAt(text, 0) === undefined;
|
|
25494
|
+
if (text.startsWith("::"))
|
|
25495
|
+
return text.length > 2 && directiveNameChar(text.charAt(2));
|
|
25496
|
+
return text.length > 1 && directiveNameChar(text.charAt(1)) && text.includes("{");
|
|
25497
|
+
}
|
|
25498
|
+
function attributeSpace(char) {
|
|
25499
|
+
return char === " " || char >= "\t" && char <= "\r";
|
|
25500
|
+
}
|
|
25501
|
+
var BLOCK_ID_ATTRIBUTE = "blockId";
|
|
25502
|
+
function directiveAttributes(value) {
|
|
25503
|
+
const attributes = [];
|
|
25504
|
+
const gaps = [];
|
|
25505
|
+
const named = new Set;
|
|
25506
|
+
let hasId = false;
|
|
25507
|
+
let id;
|
|
25508
|
+
let offset = 0;
|
|
25509
|
+
for (;; ) {
|
|
25510
|
+
const gap = offset;
|
|
25511
|
+
while (offset < value.length && attributeSpace(value.charAt(offset)))
|
|
25512
|
+
offset++;
|
|
25513
|
+
gaps.push(value.slice(gap, offset));
|
|
25514
|
+
if (offset === value.length)
|
|
25515
|
+
break;
|
|
25516
|
+
const start = offset;
|
|
25517
|
+
const sigil = value.charAt(start);
|
|
25518
|
+
let name;
|
|
25519
|
+
if (sigil === "#") {
|
|
25520
|
+
offset = start + 1;
|
|
25521
|
+
while (offset < value.length && !TYPED_BLOCK_ID_SHORTCUT_EXCLUDED.includes(value.charAt(offset)))
|
|
25522
|
+
offset++;
|
|
25523
|
+
if (offset === start + 1 || hasId)
|
|
25524
|
+
return;
|
|
25525
|
+
hasId = true;
|
|
25526
|
+
id = value.slice(start + 1, offset);
|
|
25527
|
+
name = "id";
|
|
25528
|
+
} else if (sigil === ".") {
|
|
25529
|
+
offset = start + 1;
|
|
25530
|
+
while (offset < value.length && directiveNameChar(value.charAt(offset)))
|
|
25531
|
+
offset++;
|
|
25532
|
+
if (offset === start + 1)
|
|
25533
|
+
return;
|
|
25534
|
+
named.add("class");
|
|
25535
|
+
name = "class";
|
|
25536
|
+
} else {
|
|
25537
|
+
while (offset < value.length && directiveNameChar(value.charAt(offset)))
|
|
25538
|
+
offset++;
|
|
25539
|
+
name = value.slice(start, offset);
|
|
25540
|
+
if (name === "")
|
|
25541
|
+
return;
|
|
25542
|
+
if (name === "id") {
|
|
25543
|
+
const close = value.startsWith('="', offset) ? value.indexOf('"', offset + 2) : -1;
|
|
25544
|
+
if (close === -1 || close === offset + 2 || hasId)
|
|
25545
|
+
return;
|
|
25546
|
+
hasId = true;
|
|
25547
|
+
id = decodedId(value.slice(offset + 2, close));
|
|
25548
|
+
offset = close + 1;
|
|
25549
|
+
} else {
|
|
25550
|
+
if (name === BLOCK_ID_ATTRIBUTE || named.has(name))
|
|
25551
|
+
return;
|
|
25552
|
+
named.add(name);
|
|
25553
|
+
if (offset < value.length && value.charAt(offset) !== " ") {
|
|
25554
|
+
const close = value.startsWith('="', offset) ? value.indexOf('"', offset + 2) : -1;
|
|
25555
|
+
if (close === -1)
|
|
25556
|
+
return;
|
|
25557
|
+
offset = close + 1;
|
|
25558
|
+
}
|
|
25559
|
+
}
|
|
25560
|
+
}
|
|
25561
|
+
if (offset < value.length && !attributeSpace(value.charAt(offset)))
|
|
25562
|
+
return;
|
|
25563
|
+
attributes.push({ name, text: value.slice(start, offset) });
|
|
25564
|
+
}
|
|
25565
|
+
return { attributes, gaps, id };
|
|
25566
|
+
}
|
|
25567
|
+
var NAMED_REFERENCES = new Map([
|
|
25568
|
+
["amp;", "&"],
|
|
25569
|
+
["amp", "&"],
|
|
25570
|
+
["lt;", "<"],
|
|
25571
|
+
["lt", "<"],
|
|
25572
|
+
["gt;", ">"],
|
|
25573
|
+
["gt", ">"],
|
|
25574
|
+
["quot;", '"'],
|
|
25575
|
+
["quot", '"'],
|
|
25576
|
+
["apos;", "'"],
|
|
25577
|
+
["nbsp;", "\xA0"],
|
|
25578
|
+
["nbsp", "\xA0"]
|
|
25579
|
+
]);
|
|
25580
|
+
var WINDOWS_1252 = "\u20AC\x81\u201A\u0192\u201E\u2026\u2020\u2021\u02C6\u2030\u0160\u2039\u0152\x8D\u017D\x8F" + "\x90\u2018\u2019\u201C\u201D\u2022\u2013\u2014\u02DC\u2122\u0161\u203A\u0153\x9D\u017E\u0178";
|
|
25581
|
+
function decodedId(raw) {
|
|
25582
|
+
let id = "";
|
|
25583
|
+
let at = 0;
|
|
25584
|
+
for (let amp = raw.indexOf("&");amp !== -1; amp = raw.indexOf("&", at)) {
|
|
25585
|
+
id += raw.slice(at, amp);
|
|
25586
|
+
const s = raw.slice(amp);
|
|
25587
|
+
let i = 1;
|
|
25588
|
+
if (s.charAt(1) === "#") {
|
|
25589
|
+
const hex = s.charAt(2) === "x" || s.charAt(2) === "X";
|
|
25590
|
+
let x = 0;
|
|
25591
|
+
i = hex ? 3 : 2;
|
|
25592
|
+
while (s.length > 3 && i < s.length) {
|
|
25593
|
+
const c = s.charAt(i++);
|
|
25594
|
+
const digit = (hex ? /^[0-9A-Fa-f]$/ : /^[0-9]$/).test(c) ? Number.parseInt(c, 16) : -1;
|
|
25595
|
+
if (digit >= 0) {
|
|
25596
|
+
x = Math.imul(x, hex ? 16 : 10) + digit | 0;
|
|
25597
|
+
continue;
|
|
25598
|
+
}
|
|
25599
|
+
if (c !== ";")
|
|
25600
|
+
i--;
|
|
25601
|
+
break;
|
|
25602
|
+
}
|
|
25603
|
+
if (s.length <= 3 || i <= 3) {
|
|
25604
|
+
id += "&";
|
|
25605
|
+
i = 1;
|
|
25606
|
+
} else if (x >= 128 && x <= 159) {
|
|
25607
|
+
id += WINDOWS_1252.charAt(x - 128);
|
|
25608
|
+
} else if (x <= 0 || x >= 55296 && x <= 57343 || x > 1114111) {
|
|
25609
|
+
id += "\uFFFD";
|
|
25610
|
+
} else {
|
|
25611
|
+
id += String.fromCodePoint(x);
|
|
25612
|
+
}
|
|
25613
|
+
} else {
|
|
25614
|
+
while (i < s.length && /^[A-Za-z0-9]$/.test(s.charAt(i)))
|
|
25615
|
+
i++;
|
|
25616
|
+
if (s.charAt(i) === ";")
|
|
25617
|
+
i++;
|
|
25618
|
+
const name = s.slice(1, i);
|
|
25619
|
+
const decoded = NAMED_REFERENCES.get(name);
|
|
25620
|
+
if (decoded !== undefined)
|
|
25621
|
+
id += decoded;
|
|
25622
|
+
else if (name.replace(/;$/, "").length > 1 && /^[A-Za-z]/.test(name))
|
|
25623
|
+
return;
|
|
25624
|
+
else
|
|
25625
|
+
id += s.slice(0, i);
|
|
25626
|
+
}
|
|
25627
|
+
at = amp + i;
|
|
25628
|
+
}
|
|
25629
|
+
return id + raw.slice(at);
|
|
25458
25630
|
}
|
|
25459
|
-
|
|
25460
|
-
|
|
25461
|
-
|
|
25462
|
-
|
|
25463
|
-
|
|
25631
|
+
|
|
25632
|
+
// ../envoy-client/src/dispatch-commands/stored-spelling.ts
|
|
25633
|
+
function headedOpener(line) {
|
|
25634
|
+
for (let at = 0;at < line.length; at += Math.max(1, runOf(line, at, ":"))) {
|
|
25635
|
+
const brace = typedFenceBrace(line, at);
|
|
25636
|
+
if (brace === -1)
|
|
25637
|
+
continue;
|
|
25638
|
+
const opener = typedOpenerAt(line, at);
|
|
25639
|
+
return opener === undefined ? undefined : { ...opener, head: line.slice(0, brace + 1) };
|
|
25464
25640
|
}
|
|
25465
|
-
|
|
25466
|
-
|
|
25467
|
-
|
|
25641
|
+
return;
|
|
25642
|
+
}
|
|
25643
|
+
function attributesByName(attributes) {
|
|
25644
|
+
const byName = new Map(attributes.map((attribute) => [attribute.name, attribute.text]));
|
|
25645
|
+
return byName.size === attributes.length ? byName : undefined;
|
|
25646
|
+
}
|
|
25647
|
+
function inStoredOrder(given, stored) {
|
|
25648
|
+
const written = attributesByName(given.attributes);
|
|
25649
|
+
if (written === undefined || attributesByName(stored.attributes) === undefined || stored.attributes.length !== given.attributes.length) {
|
|
25650
|
+
return;
|
|
25651
|
+
}
|
|
25652
|
+
let line = `${given.head}${given.gaps[0] ?? ""}`;
|
|
25653
|
+
for (const [index, attribute] of stored.attributes.entries()) {
|
|
25654
|
+
const text = written.get(attribute.name);
|
|
25655
|
+
if (text === undefined)
|
|
25656
|
+
return;
|
|
25657
|
+
line += `${text}${given.gaps[index + 1] ?? ""}`;
|
|
25658
|
+
}
|
|
25659
|
+
return `${line}}`;
|
|
25660
|
+
}
|
|
25661
|
+
function onlyReordered(given, held, stored) {
|
|
25662
|
+
return given !== undefined && stored !== undefined && inStoredOrder(given, stored) === held;
|
|
25663
|
+
}
|
|
25664
|
+
function reorderedBlockLine(line, opener) {
|
|
25665
|
+
const named = `${opener.name} block${opener.id === undefined ? "" : ` ${opener.id}`}`;
|
|
25666
|
+
const order = opener.attributes.map((attribute) => attribute.name).join(", ");
|
|
25667
|
+
return `This upload put the attributes of ${named} (line ${line}) in the order Dispatch stores: ${order}.`;
|
|
25668
|
+
}
|
|
25669
|
+
function attributesReordered(given, stored) {
|
|
25670
|
+
const written = withoutFinalLineFeed(given).split(`
|
|
25671
|
+
`);
|
|
25672
|
+
const holds = withoutFinalLineFeed(stored).split(`
|
|
25673
|
+
`);
|
|
25674
|
+
if (written.length !== holds.length)
|
|
25675
|
+
return;
|
|
25676
|
+
const lines = [];
|
|
25677
|
+
for (const [index, held] of holds.entries()) {
|
|
25678
|
+
const wrote = written[index];
|
|
25679
|
+
if (wrote === held)
|
|
25680
|
+
continue;
|
|
25681
|
+
const opener = headedOpener(held);
|
|
25682
|
+
if (wrote === undefined || opener === undefined || !onlyReordered(headedOpener(wrote), held, opener)) {
|
|
25683
|
+
return;
|
|
25684
|
+
}
|
|
25685
|
+
lines.push(reorderedBlockLine(index + 1, opener));
|
|
25686
|
+
}
|
|
25687
|
+
return lines;
|
|
25468
25688
|
}
|
|
25469
25689
|
var STORED_LINE_QUOTED = 200;
|
|
25470
|
-
function quotedStoredLine(
|
|
25471
|
-
|
|
25472
|
-
|
|
25473
|
-
const
|
|
25474
|
-
|
|
25690
|
+
function quotedStoredLine(characters, from) {
|
|
25691
|
+
const shown = characters.slice(from, from + STORED_LINE_QUOTED);
|
|
25692
|
+
const quote = JSON.stringify(shown.join(""));
|
|
25693
|
+
const cutAfter = from + shown.length < characters.length;
|
|
25694
|
+
if (from === 0 && !cutAfter)
|
|
25695
|
+
return quote;
|
|
25696
|
+
const cut = from === 0 ? "after" : cutAfter ? "before and after" : "before the last";
|
|
25697
|
+
return `${quote} (cut ${cut} ${shown.length} of its ${characters.length} characters)`;
|
|
25698
|
+
}
|
|
25699
|
+
function lineWords(line, opener) {
|
|
25700
|
+
const plain = (text) => (text.match(/\s+|\S+/g) ?? []).map((word) => ({ text: word, attribute: false }));
|
|
25701
|
+
if (opener === undefined)
|
|
25702
|
+
return plain(line);
|
|
25703
|
+
const words = plain(opener.head);
|
|
25704
|
+
for (const [index, gap] of opener.gaps.entries()) {
|
|
25705
|
+
if (gap !== "")
|
|
25706
|
+
words.push({ text: gap, attribute: false });
|
|
25707
|
+
const attribute = opener.attributes[index];
|
|
25708
|
+
if (attribute !== undefined)
|
|
25709
|
+
words.push({ text: attribute.text, attribute: true });
|
|
25710
|
+
}
|
|
25711
|
+
words.push({ text: "}", attribute: false });
|
|
25712
|
+
return words;
|
|
25713
|
+
}
|
|
25714
|
+
function wordText(word, from = 0, characters = Array.from(word.text)) {
|
|
25715
|
+
if (word.attribute)
|
|
25716
|
+
return `the attribute ${word.text}`;
|
|
25717
|
+
return `${/\S/.test(word.text) ? "the word" : "the space"} ${quotedStoredLine(characters, from)}`;
|
|
25718
|
+
}
|
|
25719
|
+
function wordDifference(written, holds) {
|
|
25720
|
+
let before = 0;
|
|
25721
|
+
for (let index = 0;index < Math.max(written.length, holds.length); index += 1) {
|
|
25722
|
+
const given = written[index];
|
|
25723
|
+
const stored = holds[index];
|
|
25724
|
+
if (given !== undefined && stored !== undefined && given.text === stored.text) {
|
|
25725
|
+
before += Array.from(given.text).length;
|
|
25726
|
+
continue;
|
|
25727
|
+
}
|
|
25728
|
+
if (given === undefined && stored !== undefined) {
|
|
25729
|
+
return `ends after character ${before}, where Dispatch goes on with ${wordText(stored)}`;
|
|
25730
|
+
}
|
|
25731
|
+
if (given !== undefined && stored === undefined) {
|
|
25732
|
+
return `reads ${wordText(given)} at character ${before + 1}, where Dispatch ends the line`;
|
|
25733
|
+
}
|
|
25734
|
+
if (given !== undefined && stored !== undefined) {
|
|
25735
|
+
const wrote = Array.from(given.text);
|
|
25736
|
+
const held = Array.from(stored.text);
|
|
25737
|
+
let from = 0;
|
|
25738
|
+
if (!given.attribute && !stored.attribute && Math.max(wrote.length, held.length) > STORED_LINE_QUOTED) {
|
|
25739
|
+
while (from < wrote.length && wrote[from] === held[from])
|
|
25740
|
+
from += 1;
|
|
25741
|
+
const tail = Math.max(0, from - STORED_LINE_QUOTED);
|
|
25742
|
+
if (from === wrote.length) {
|
|
25743
|
+
return `ends ${wordText(given, tail, wrote)} after character ${before + from}, where Dispatch goes on with ${wordText(stored, from, held)}`;
|
|
25744
|
+
}
|
|
25745
|
+
if (from === held.length) {
|
|
25746
|
+
return `reads ${wordText(given, from, wrote)} at character ${before + from + 1}, where Dispatch ends ${wordText(stored, tail, held)}`;
|
|
25747
|
+
}
|
|
25748
|
+
}
|
|
25749
|
+
return `reads ${wordText(given, from, wrote)} at character ${before + from + 1}, where Dispatch stores ${wordText(stored, from, held)}`;
|
|
25750
|
+
}
|
|
25751
|
+
}
|
|
25752
|
+
return "differs from the line Dispatch stores";
|
|
25753
|
+
}
|
|
25754
|
+
function attributeDifference(line, given, stored) {
|
|
25755
|
+
const written = attributesByName(given.attributes);
|
|
25756
|
+
if (written === undefined)
|
|
25757
|
+
return;
|
|
25758
|
+
for (const attribute of stored.attributes) {
|
|
25759
|
+
const text = written.get(attribute.name);
|
|
25760
|
+
if (text === undefined)
|
|
25761
|
+
return `Dispatch adds the attribute ${attribute.text} to line ${line}`;
|
|
25762
|
+
if (text !== attribute.text) {
|
|
25763
|
+
return `line ${line} holds the attribute ${text}, which Dispatch stores as ${attribute.text}`;
|
|
25764
|
+
}
|
|
25765
|
+
}
|
|
25766
|
+
const held = new Set(stored.attributes.map((attribute) => attribute.name));
|
|
25767
|
+
const dropped = given.attributes.find((attribute) => !held.has(attribute.name));
|
|
25768
|
+
return dropped === undefined ? undefined : `line ${line} holds the attribute ${dropped.text}, which Dispatch drops`;
|
|
25769
|
+
}
|
|
25770
|
+
function lineDifference(line, wrote, given, held, stored) {
|
|
25771
|
+
if (given === undefined || stored === undefined) {
|
|
25772
|
+
return `line ${line} ${wordDifference(lineWords(wrote, undefined), lineWords(held, undefined))}`;
|
|
25773
|
+
}
|
|
25774
|
+
const attribute = attributeDifference(line, given, stored);
|
|
25775
|
+
if (attribute !== undefined)
|
|
25776
|
+
return attribute;
|
|
25777
|
+
const reordered = inStoredOrder(given, stored);
|
|
25778
|
+
if (reordered !== undefined && reordered !== wrote) {
|
|
25779
|
+
const words = lineWords(reordered, headedOpener(reordered));
|
|
25780
|
+
return `line ${line}, with its attributes put in the order Dispatch stores, ${wordDifference(words, lineWords(held, stored))}`;
|
|
25781
|
+
}
|
|
25782
|
+
return `line ${line} ${wordDifference(lineWords(wrote, given), lineWords(held, stored))}`;
|
|
25475
25783
|
}
|
|
25476
25784
|
function firstStoredDifference(given, stored) {
|
|
25477
25785
|
const written = given.split(`
|
|
@@ -25484,13 +25792,17 @@ function firstStoredDifference(given, stored) {
|
|
|
25484
25792
|
if (wrote === held)
|
|
25485
25793
|
continue;
|
|
25486
25794
|
if (wrote === undefined && held !== undefined) {
|
|
25487
|
-
return `the store writes a line ${line + 1}, ${quotedStoredLine(held)}`;
|
|
25795
|
+
return `the store writes a line ${line + 1}, ${quotedStoredLine(Array.from(held), 0)}`;
|
|
25488
25796
|
}
|
|
25489
25797
|
if (held === undefined && wrote !== undefined) {
|
|
25490
|
-
return `the store drops line ${line + 1}, ${quotedStoredLine(wrote)}`;
|
|
25798
|
+
return `the store drops line ${line + 1}, ${quotedStoredLine(Array.from(wrote), 0)}`;
|
|
25491
25799
|
}
|
|
25492
25800
|
if (wrote !== undefined && held !== undefined) {
|
|
25493
|
-
|
|
25801
|
+
const givenOpener = headedOpener(wrote);
|
|
25802
|
+
const storedOpener = headedOpener(held);
|
|
25803
|
+
if (onlyReordered(givenOpener, held, storedOpener))
|
|
25804
|
+
continue;
|
|
25805
|
+
return lineDifference(line + 1, wrote, givenOpener, held, storedOpener);
|
|
25494
25806
|
}
|
|
25495
25807
|
}
|
|
25496
25808
|
return "the stored text differs from the text given";
|
|
@@ -25520,6 +25832,33 @@ ${printed.text}`,
|
|
|
25520
25832
|
"--- end of the text Dispatch stores ---"
|
|
25521
25833
|
].join("");
|
|
25522
25834
|
}
|
|
25835
|
+
function withoutFinalLineFeed(text) {
|
|
25836
|
+
return text.endsWith(`
|
|
25837
|
+
`) ? text.slice(0, -1) : text;
|
|
25838
|
+
}
|
|
25839
|
+
function storedUpload(given, stored, name) {
|
|
25840
|
+
if (withoutFinalLineFeed(stored) === withoutFinalLineFeed(given)) {
|
|
25841
|
+
return { sent: given, reordered: [] };
|
|
25842
|
+
}
|
|
25843
|
+
const reordered = attributesReordered(given, stored);
|
|
25844
|
+
return reordered === undefined ? { refusal: storedTextProblem(given, stored, name) } : { sent: stored, reordered };
|
|
25845
|
+
}
|
|
25846
|
+
|
|
25847
|
+
// ../envoy-client/src/dispatch-commands/upload-checks.ts
|
|
25848
|
+
function artifactUnderName(artifacts, name) {
|
|
25849
|
+
const written = name.trim();
|
|
25850
|
+
return artifacts.find((held) => held.slug === written) ?? artifacts.find((held) => held.name === written);
|
|
25851
|
+
}
|
|
25852
|
+
function artifactNameExistsProblem(held, owner) {
|
|
25853
|
+
const versions = held.versions ?? [];
|
|
25854
|
+
const newest = versions[versions.length - 1];
|
|
25855
|
+
if (newest === undefined) {
|
|
25856
|
+
return `${owner} already holds ${held.name} (slug ${held.slug}, kind ${held.kind}), which has no version yet and which ${actorText(held.created_by)} created. ${ARTIFACT_NAME_EXISTS_RULE}`;
|
|
25857
|
+
}
|
|
25858
|
+
const authors = (newest.authors ?? []).map(actorText);
|
|
25859
|
+
const wroteIt = authors.length === 0 ? actorText(held.created_by) : authors.join(" and ");
|
|
25860
|
+
return `${owner} already holds ${held.name} (slug ${held.slug}, kind ${held.kind}) at version ${newest.number}, which ${wroteIt} wrote. ${ARTIFACT_NAME_EXISTS_RULE}`;
|
|
25861
|
+
}
|
|
25523
25862
|
function storedTextCheckFailed(error, name) {
|
|
25524
25863
|
const failure = `Dispatch could not say how it would store this text, so nothing was uploaded: POST /api/v1/markdown/round-trip failed with ${messageFor(error)}.`;
|
|
25525
25864
|
if (!dispatchAnswered(error, 413)) {
|
|
@@ -25531,10 +25870,6 @@ function storedTextCheckFailed(error, name) {
|
|
|
25531
25870
|
function roundTripRouteAbsent(error) {
|
|
25532
25871
|
return dispatchAnswered(error, 404) || dispatchAnswered(error, 405);
|
|
25533
25872
|
}
|
|
25534
|
-
function withoutFinalLineFeed(text) {
|
|
25535
|
-
return text.endsWith(`
|
|
25536
|
-
`) ? text.slice(0, -1) : text;
|
|
25537
|
-
}
|
|
25538
25873
|
|
|
25539
25874
|
// ../envoy-client/src/dispatch-commands/documents.ts
|
|
25540
25875
|
async function blockAsks(client, resolved, state) {
|
|
@@ -25918,6 +26253,8 @@ async function artifactCommand(context) {
|
|
|
25918
26253
|
]);
|
|
25919
26254
|
}
|
|
25920
26255
|
}
|
|
26256
|
+
let sent = content;
|
|
26257
|
+
let reordered = [];
|
|
25921
26258
|
if (!blank) {
|
|
25922
26259
|
let stored;
|
|
25923
26260
|
try {
|
|
@@ -25927,8 +26264,12 @@ async function artifactCommand(context) {
|
|
|
25927
26264
|
throw new Error(storedTextCheckFailed(error, name), { cause: error });
|
|
25928
26265
|
}
|
|
25929
26266
|
}
|
|
25930
|
-
if (stored !== undefined
|
|
25931
|
-
|
|
26267
|
+
if (stored !== undefined) {
|
|
26268
|
+
const upload = storedUpload(content, stored, name);
|
|
26269
|
+
if ("refusal" in upload)
|
|
26270
|
+
throw new ToolInputError(input.tool, [upload.refusal]);
|
|
26271
|
+
sent = upload.sent;
|
|
26272
|
+
reordered = upload.reordered;
|
|
25932
26273
|
}
|
|
25933
26274
|
}
|
|
25934
26275
|
const artifactInput = path !== undefined ? {
|
|
@@ -25936,7 +26277,7 @@ async function artifactCommand(context) {
|
|
|
25936
26277
|
file: input.uploadBytes === undefined ? Bun.file(resolvePath2(input.cwd, path)) : new Blob([new Uint8Array(input.uploadBytes)], {
|
|
25937
26278
|
type: Bun.file(resolvePath2(input.cwd, path)).type
|
|
25938
26279
|
})
|
|
25939
|
-
} :
|
|
26280
|
+
} : sent !== undefined ? { ...options, content: sent } : options;
|
|
25940
26281
|
const result = artifactOwner.kind === "project" ? await client.projectArtifact(artifactOwner.project, artifactInput) : await client.artifact(issue(), artifactInput);
|
|
25941
26282
|
const artifactRef = dispatchDocumentRef(artifactOwner.kind === "project" ? artifactOwner.project : issue(), result.artifact.slug);
|
|
25942
26283
|
const uploadOwner = artifactOwner.kind === "project" ? documentTopic(result.artifact) : issueTopic(issue());
|
|
@@ -25947,6 +26288,7 @@ async function artifactCommand(context) {
|
|
|
25947
26288
|
return {
|
|
25948
26289
|
text: [
|
|
25949
26290
|
path === undefined && content === undefined ? `Made ${result.artifact.name} as an empty document (artifact slug ${result.artifact.slug}; ${artifactRef}). Write in it with dispatch doc-edit.${await notSubscribed(uploadOwner, input.subscriptions)}` : `Uploaded ${result.artifact.name} as version ${result.version.number} (artifact slug ${result.artifact.slug}; ${artifactRef})${await notSubscribed(uploadOwner, input.subscriptions)}`,
|
|
26291
|
+
...reordered,
|
|
25950
26292
|
...adviceLines
|
|
25951
26293
|
].join(`
|
|
25952
26294
|
`),
|
|
@@ -32218,16 +32560,22 @@ var PS_OPTIONS = {
|
|
|
32218
32560
|
env: { LC_ALL: "C", PATH: process.env["PATH"] ?? "/usr/bin:/bin", TZ: "UTC" },
|
|
32219
32561
|
timeout: 1000
|
|
32220
32562
|
};
|
|
32221
|
-
function
|
|
32563
|
+
function procStarted(pid) {
|
|
32222
32564
|
try {
|
|
32223
32565
|
const stat = readFileSync5(`/proc/${pid}/stat`, "utf8");
|
|
32224
32566
|
return stat.slice(stat.lastIndexOf(")") + 2).split(" ")[19];
|
|
32225
32567
|
} catch {
|
|
32226
|
-
|
|
32227
|
-
const started = ps.status === 0 ? ps.stdout.trim() : "";
|
|
32228
|
-
return started === "" ? undefined : `ps:${started}`;
|
|
32568
|
+
return;
|
|
32229
32569
|
}
|
|
32230
32570
|
}
|
|
32571
|
+
function processStarted(pid) {
|
|
32572
|
+
const started = procStarted(pid);
|
|
32573
|
+
if (started !== undefined)
|
|
32574
|
+
return started;
|
|
32575
|
+
const ps = spawnSync("ps", ["-o", "lstart=", "-p", String(pid)], PS_OPTIONS);
|
|
32576
|
+
const fromPs = ps.status === 0 ? ps.stdout.trim() : "";
|
|
32577
|
+
return fromPs === "" ? undefined : `ps:${fromPs}`;
|
|
32578
|
+
}
|
|
32231
32579
|
function recordOfProcess(record, pid) {
|
|
32232
32580
|
const started = processStarted(pid);
|
|
32233
32581
|
return record.codex_started !== null && started !== undefined && record.codex_started === started;
|