@sjawhar/codex-envoy 5.1.3 → 5.2.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/.codex-plugin/plugin.json +1 -1
- package/dist/codex-hook.js +33 -4
- package/dist/dispatch.js +33 -4
- package/dist/envoy-channel.js +128 -47
- package/dist/session-hook.js +33 -4
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codex-envoy",
|
|
3
|
-
"version": "5.1
|
|
3
|
+
"version": "5.2.1",
|
|
4
4
|
"description": "Put Envoy and Dispatch messages into the Codex session's own conversation, show it on Dispatch's Agents page, and expose the Envoy and dispatch tools.",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Legion",
|
package/dist/codex-hook.js
CHANGED
|
@@ -14116,16 +14116,45 @@ function preconditionKept(value) {
|
|
|
14116
14116
|
const precondition = input.precondition;
|
|
14117
14117
|
return typeof precondition.document === "string" !== Array.isArray(precondition.blocks);
|
|
14118
14118
|
}
|
|
14119
|
+
var REPLACE_OP_KEYS = {
|
|
14120
|
+
op: true,
|
|
14121
|
+
find: true,
|
|
14122
|
+
with: true,
|
|
14123
|
+
occurrence: true
|
|
14124
|
+
};
|
|
14125
|
+
var REPLACE_OP_RULE = 'A replace names with and takes find, with and occurrence alone: with "" deletes the match on purpose, and a replace without with, or with its new text under another key such as markdown, would delete the match too.';
|
|
14126
|
+
function replaceOpsProblem(value) {
|
|
14127
|
+
if (typeof value !== "object" || value === null || !("ops" in value))
|
|
14128
|
+
return;
|
|
14129
|
+
const ops = value.ops;
|
|
14130
|
+
if (!Array.isArray(ops))
|
|
14131
|
+
return;
|
|
14132
|
+
const problems = [];
|
|
14133
|
+
ops.forEach((op, index) => {
|
|
14134
|
+
if (typeof op !== "object" || op === null || !("op" in op) || op.op !== "replace")
|
|
14135
|
+
return;
|
|
14136
|
+
const foreign = Object.entries(op).filter(([key, held]) => REPLACE_OP_KEYS[key] !== true && held !== undefined).map(([key]) => key);
|
|
14137
|
+
if (foreign.length > 0) {
|
|
14138
|
+
problems.push(`ops[${index}] is a replace carrying ${foreign.join(" and ")}, which replace does not take: it takes find, with and occurrence, and its new text goes in with.`);
|
|
14139
|
+
}
|
|
14140
|
+
if (!("with" in op) || op.with === undefined) {
|
|
14141
|
+
problems.push(`ops[${index}] is a replace with no with, which would delete the text find matches: write the new text in with, or with "" to delete it on purpose.`);
|
|
14142
|
+
}
|
|
14143
|
+
});
|
|
14144
|
+
return problems.length === 0 ? undefined : problems.join(" ");
|
|
14145
|
+
}
|
|
14119
14146
|
function documentEditProblem(value) {
|
|
14147
|
+
const replaceProblem = replaceOpsProblem(value);
|
|
14120
14148
|
return brokenParts([
|
|
14121
14149
|
[documentEditOwner.check(value), documentEditOwner.message],
|
|
14122
|
-
[preconditionKept(value), PRECONDITION_RULE]
|
|
14150
|
+
[preconditionKept(value), PRECONDITION_RULE],
|
|
14151
|
+
[replaceProblem === undefined, replaceProblem ?? REPLACE_OP_RULE]
|
|
14123
14152
|
]);
|
|
14124
14153
|
}
|
|
14125
14154
|
var documentEditValidation = {
|
|
14126
14155
|
check: (value) => documentEditProblem(value) === undefined,
|
|
14127
|
-
message: `${documentEditOwner.message} ${PRECONDITION_RULE}`,
|
|
14128
|
-
refusal: (value) => documentEditProblem(value) ?? `${documentEditOwner.message} ${PRECONDITION_RULE}`
|
|
14156
|
+
message: `${documentEditOwner.message} ${PRECONDITION_RULE} ${REPLACE_OP_RULE}`,
|
|
14157
|
+
refusal: (value) => documentEditProblem(value) ?? `${documentEditOwner.message} ${PRECONDITION_RULE} ${REPLACE_OP_RULE}`
|
|
14129
14158
|
};
|
|
14130
14159
|
var commentOwner = documentOwnerValidation(true);
|
|
14131
14160
|
var COMMENT_TURN_RULE = "turn requires reply_to_ask: turn says who holds an open ask's thread after the reply. Pass reply_to_ask with the open ask's id, or drop turn.";
|
|
@@ -14594,7 +14623,7 @@ var dispatchToolSpecs = [
|
|
|
14594
14623
|
ops: z.array(z.object({
|
|
14595
14624
|
op: z.enum(DOC_EDIT_OPS).describe("Edit operation."),
|
|
14596
14625
|
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(),
|
|
14597
|
-
with: z.string().describe("Replacement text for replace:
|
|
14626
|
+
with: z.string().describe("Replacement text for replace, which every replace names: an empty value deletes the match on purpose. A replace takes op, find, with and occurrence alone, and one without with, or carrying any other key whatever it holds, is refused before it is sent, and by the server with 400 REPLACE_FIELDS, the document unchanged. Inside a code block, with is 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(),
|
|
14598
14627
|
occurrence: z.number({ int: true, min: 0 }).describe("Optional zero-based match occurrence.").optional(),
|
|
14599
14628
|
markdown: z.string().describe("Markdown to insert; a CR LF or a lone carriage return in it is written as a line feed.").optional(),
|
|
14600
14629
|
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(),
|
package/dist/dispatch.js
CHANGED
|
@@ -15413,16 +15413,45 @@ function preconditionKept(value) {
|
|
|
15413
15413
|
const precondition = input.precondition;
|
|
15414
15414
|
return typeof precondition.document === "string" !== Array.isArray(precondition.blocks);
|
|
15415
15415
|
}
|
|
15416
|
+
var REPLACE_OP_KEYS = {
|
|
15417
|
+
op: true,
|
|
15418
|
+
find: true,
|
|
15419
|
+
with: true,
|
|
15420
|
+
occurrence: true
|
|
15421
|
+
};
|
|
15422
|
+
var REPLACE_OP_RULE = 'A replace names with and takes find, with and occurrence alone: with "" deletes the match on purpose, and a replace without with, or with its new text under another key such as markdown, would delete the match too.';
|
|
15423
|
+
function replaceOpsProblem(value) {
|
|
15424
|
+
if (typeof value !== "object" || value === null || !("ops" in value))
|
|
15425
|
+
return;
|
|
15426
|
+
const ops = value.ops;
|
|
15427
|
+
if (!Array.isArray(ops))
|
|
15428
|
+
return;
|
|
15429
|
+
const problems = [];
|
|
15430
|
+
ops.forEach((op, index) => {
|
|
15431
|
+
if (typeof op !== "object" || op === null || !("op" in op) || op.op !== "replace")
|
|
15432
|
+
return;
|
|
15433
|
+
const foreign = Object.entries(op).filter(([key, held]) => REPLACE_OP_KEYS[key] !== true && held !== undefined).map(([key]) => key);
|
|
15434
|
+
if (foreign.length > 0) {
|
|
15435
|
+
problems.push(`ops[${index}] is a replace carrying ${foreign.join(" and ")}, which replace does not take: it takes find, with and occurrence, and its new text goes in with.`);
|
|
15436
|
+
}
|
|
15437
|
+
if (!("with" in op) || op.with === undefined) {
|
|
15438
|
+
problems.push(`ops[${index}] is a replace with no with, which would delete the text find matches: write the new text in with, or with "" to delete it on purpose.`);
|
|
15439
|
+
}
|
|
15440
|
+
});
|
|
15441
|
+
return problems.length === 0 ? undefined : problems.join(" ");
|
|
15442
|
+
}
|
|
15416
15443
|
function documentEditProblem(value) {
|
|
15444
|
+
const replaceProblem = replaceOpsProblem(value);
|
|
15417
15445
|
return brokenParts([
|
|
15418
15446
|
[documentEditOwner.check(value), documentEditOwner.message],
|
|
15419
|
-
[preconditionKept(value), PRECONDITION_RULE]
|
|
15447
|
+
[preconditionKept(value), PRECONDITION_RULE],
|
|
15448
|
+
[replaceProblem === undefined, replaceProblem ?? REPLACE_OP_RULE]
|
|
15420
15449
|
]);
|
|
15421
15450
|
}
|
|
15422
15451
|
var documentEditValidation = {
|
|
15423
15452
|
check: (value) => documentEditProblem(value) === undefined,
|
|
15424
|
-
message: `${documentEditOwner.message} ${PRECONDITION_RULE}`,
|
|
15425
|
-
refusal: (value) => documentEditProblem(value) ?? `${documentEditOwner.message} ${PRECONDITION_RULE}`
|
|
15453
|
+
message: `${documentEditOwner.message} ${PRECONDITION_RULE} ${REPLACE_OP_RULE}`,
|
|
15454
|
+
refusal: (value) => documentEditProblem(value) ?? `${documentEditOwner.message} ${PRECONDITION_RULE} ${REPLACE_OP_RULE}`
|
|
15426
15455
|
};
|
|
15427
15456
|
var commentOwner = documentOwnerValidation(true);
|
|
15428
15457
|
var COMMENT_TURN_RULE = "turn requires reply_to_ask: turn says who holds an open ask's thread after the reply. Pass reply_to_ask with the open ask's id, or drop turn.";
|
|
@@ -15891,7 +15920,7 @@ var dispatchToolSpecs = [
|
|
|
15891
15920
|
ops: z.array(z.object({
|
|
15892
15921
|
op: z.enum(DOC_EDIT_OPS).describe("Edit operation."),
|
|
15893
15922
|
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(),
|
|
15894
|
-
with: z.string().describe("Replacement text for replace:
|
|
15923
|
+
with: z.string().describe("Replacement text for replace, which every replace names: an empty value deletes the match on purpose. A replace takes op, find, with and occurrence alone, and one without with, or carrying any other key whatever it holds, is refused before it is sent, and by the server with 400 REPLACE_FIELDS, the document unchanged. Inside a code block, with is 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(),
|
|
15895
15924
|
occurrence: z.number({ int: true, min: 0 }).describe("Optional zero-based match occurrence.").optional(),
|
|
15896
15925
|
markdown: z.string().describe("Markdown to insert; a CR LF or a lone carriage return in it is written as a line feed.").optional(),
|
|
15897
15926
|
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(),
|
package/dist/envoy-channel.js
CHANGED
|
@@ -36916,16 +36916,45 @@ function preconditionKept(value) {
|
|
|
36916
36916
|
const precondition = input.precondition;
|
|
36917
36917
|
return typeof precondition.document === "string" !== Array.isArray(precondition.blocks);
|
|
36918
36918
|
}
|
|
36919
|
+
var REPLACE_OP_KEYS = {
|
|
36920
|
+
op: true,
|
|
36921
|
+
find: true,
|
|
36922
|
+
with: true,
|
|
36923
|
+
occurrence: true
|
|
36924
|
+
};
|
|
36925
|
+
var REPLACE_OP_RULE = 'A replace names with and takes find, with and occurrence alone: with "" deletes the match on purpose, and a replace without with, or with its new text under another key such as markdown, would delete the match too.';
|
|
36926
|
+
function replaceOpsProblem(value) {
|
|
36927
|
+
if (typeof value !== "object" || value === null || !("ops" in value))
|
|
36928
|
+
return;
|
|
36929
|
+
const ops = value.ops;
|
|
36930
|
+
if (!Array.isArray(ops))
|
|
36931
|
+
return;
|
|
36932
|
+
const problems = [];
|
|
36933
|
+
ops.forEach((op, index) => {
|
|
36934
|
+
if (typeof op !== "object" || op === null || !("op" in op) || op.op !== "replace")
|
|
36935
|
+
return;
|
|
36936
|
+
const foreign = Object.entries(op).filter(([key, held]) => REPLACE_OP_KEYS[key] !== true && held !== undefined).map(([key]) => key);
|
|
36937
|
+
if (foreign.length > 0) {
|
|
36938
|
+
problems.push(`ops[${index}] is a replace carrying ${foreign.join(" and ")}, which replace does not take: it takes find, with and occurrence, and its new text goes in with.`);
|
|
36939
|
+
}
|
|
36940
|
+
if (!("with" in op) || op.with === undefined) {
|
|
36941
|
+
problems.push(`ops[${index}] is a replace with no with, which would delete the text find matches: write the new text in with, or with "" to delete it on purpose.`);
|
|
36942
|
+
}
|
|
36943
|
+
});
|
|
36944
|
+
return problems.length === 0 ? undefined : problems.join(" ");
|
|
36945
|
+
}
|
|
36919
36946
|
function documentEditProblem(value) {
|
|
36947
|
+
const replaceProblem = replaceOpsProblem(value);
|
|
36920
36948
|
return brokenParts([
|
|
36921
36949
|
[documentEditOwner.check(value), documentEditOwner.message],
|
|
36922
|
-
[preconditionKept(value), PRECONDITION_RULE]
|
|
36950
|
+
[preconditionKept(value), PRECONDITION_RULE],
|
|
36951
|
+
[replaceProblem === undefined, replaceProblem ?? REPLACE_OP_RULE]
|
|
36923
36952
|
]);
|
|
36924
36953
|
}
|
|
36925
36954
|
var documentEditValidation = {
|
|
36926
36955
|
check: (value) => documentEditProblem(value) === undefined,
|
|
36927
|
-
message: `${documentEditOwner.message} ${PRECONDITION_RULE}`,
|
|
36928
|
-
refusal: (value) => documentEditProblem(value) ?? `${documentEditOwner.message} ${PRECONDITION_RULE}`
|
|
36956
|
+
message: `${documentEditOwner.message} ${PRECONDITION_RULE} ${REPLACE_OP_RULE}`,
|
|
36957
|
+
refusal: (value) => documentEditProblem(value) ?? `${documentEditOwner.message} ${PRECONDITION_RULE} ${REPLACE_OP_RULE}`
|
|
36929
36958
|
};
|
|
36930
36959
|
var commentOwner = documentOwnerValidation(true);
|
|
36931
36960
|
var COMMENT_TURN_RULE = "turn requires reply_to_ask: turn says who holds an open ask's thread after the reply. Pass reply_to_ask with the open ask's id, or drop turn.";
|
|
@@ -37394,7 +37423,7 @@ var dispatchToolSpecs = [
|
|
|
37394
37423
|
ops: z.array(z.object({
|
|
37395
37424
|
op: z.enum(DOC_EDIT_OPS).describe("Edit operation."),
|
|
37396
37425
|
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(),
|
|
37397
|
-
with: z.string().describe("Replacement text for replace:
|
|
37426
|
+
with: z.string().describe("Replacement text for replace, which every replace names: an empty value deletes the match on purpose. A replace takes op, find, with and occurrence alone, and one without with, or carrying any other key whatever it holds, is refused before it is sent, and by the server with 400 REPLACE_FIELDS, the document unchanged. Inside a code block, with is 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(),
|
|
37398
37427
|
occurrence: z.number({ int: true, min: 0 }).describe("Optional zero-based match occurrence.").optional(),
|
|
37399
37428
|
markdown: z.string().describe("Markdown to insert; a CR LF or a lone carriage return in it is written as a line feed.").optional(),
|
|
37400
37429
|
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(),
|
|
@@ -60481,7 +60510,7 @@ var import_nats5 = __toESM(require_mod4(), 1);
|
|
|
60481
60510
|
|
|
60482
60511
|
// package.json
|
|
60483
60512
|
var name2 = "@sjawhar/claude-envoy";
|
|
60484
|
-
var version2 = "5.1
|
|
60513
|
+
var version2 = "5.2.1";
|
|
60485
60514
|
var legion = {
|
|
60486
60515
|
daemonApiVersion: 205
|
|
60487
60516
|
};
|
|
@@ -68009,15 +68038,16 @@ function codexServersDirectory(stateDirectory, codexPid) {
|
|
|
68009
68038
|
return join18(stateDirectory, "codex-servers", String(codexPid));
|
|
68010
68039
|
}
|
|
68011
68040
|
var ENTRY_NAME = /^(\d+)\.json$/;
|
|
68041
|
+
var TEMPORARY_NAME = /^\.\d+\.\d+\.tmp$/;
|
|
68012
68042
|
function entryName(entry) {
|
|
68013
68043
|
return `${entry.seq}.json`;
|
|
68014
68044
|
}
|
|
68015
|
-
async function registerServer(directory, pid, started) {
|
|
68045
|
+
async function registerServer(directory, pid, started, list = (path) => readdir6(path)) {
|
|
68016
68046
|
await mkdir6(directory, { mode: 448, recursive: true });
|
|
68017
68047
|
const temporary = join18(directory, `.${pid}.${process.hrtime.bigint()}.tmp`);
|
|
68018
68048
|
await writeFile4(temporary, JSON.stringify({ pid, started }), { mode: 384 });
|
|
68019
68049
|
try {
|
|
68020
|
-
let seq = Math.max(0, ...(await
|
|
68050
|
+
let seq = Math.max(0, ...numbered(await list(directory)).map(({ seq: taken }) => taken)) + 1;
|
|
68021
68051
|
for (;; ) {
|
|
68022
68052
|
try {
|
|
68023
68053
|
await place(temporary, join18(directory, entryName({ seq })), pid, started);
|
|
@@ -68048,7 +68078,12 @@ async function place(temporary, target, pid, started) {
|
|
|
68048
68078
|
await writeFile4(target, JSON.stringify({ pid, started }), { flag: "wx", mode: 384 });
|
|
68049
68079
|
}
|
|
68050
68080
|
async function unregisterServer(directory, self2) {
|
|
68051
|
-
|
|
68081
|
+
const file = join18(directory, entryName(self2));
|
|
68082
|
+
const named = await readFile8(file, "utf8").then(serverOf, () => {
|
|
68083
|
+
return;
|
|
68084
|
+
});
|
|
68085
|
+
if (named?.pid === self2.pid && named.started === self2.started)
|
|
68086
|
+
await rm6(file, { force: true });
|
|
68052
68087
|
}
|
|
68053
68088
|
var startedOf = new Map;
|
|
68054
68089
|
var SYSTEM_PROBE = {
|
|
@@ -68076,95 +68111,141 @@ function serverAlive(entry, probe = SYSTEM_PROBE) {
|
|
|
68076
68111
|
const now = probe.started(entry.pid);
|
|
68077
68112
|
return entry.started === null || now === undefined || now === entry.started;
|
|
68078
68113
|
}
|
|
68079
|
-
|
|
68080
|
-
let names;
|
|
68081
|
-
try {
|
|
68082
|
-
names = await readdir6(directory);
|
|
68083
|
-
} catch {
|
|
68084
|
-
return [];
|
|
68085
|
-
}
|
|
68114
|
+
function numbered(names) {
|
|
68086
68115
|
return names.flatMap((name) => {
|
|
68087
68116
|
const match = ENTRY_NAME.exec(name);
|
|
68088
68117
|
return match === null ? [] : [{ name, seq: Number(match[1]) }];
|
|
68089
68118
|
});
|
|
68090
68119
|
}
|
|
68120
|
+
function serverOf(text) {
|
|
68121
|
+
let parsed;
|
|
68122
|
+
try {
|
|
68123
|
+
parsed = JSON.parse(text);
|
|
68124
|
+
} catch {
|
|
68125
|
+
return;
|
|
68126
|
+
}
|
|
68127
|
+
if (typeof parsed?.pid !== "number")
|
|
68128
|
+
return;
|
|
68129
|
+
return { pid: parsed.pid, started: typeof parsed.started === "string" ? parsed.started : null };
|
|
68130
|
+
}
|
|
68091
68131
|
var UNREADABLE_ENTRY_MS = 5000;
|
|
68092
|
-
async function readEntries(directory, now = Date.now) {
|
|
68093
|
-
|
|
68094
|
-
|
|
68132
|
+
async function readEntries(directory, probe, now = Date.now) {
|
|
68133
|
+
let names;
|
|
68134
|
+
try {
|
|
68135
|
+
names = await readdir6(directory);
|
|
68136
|
+
} catch (error) {
|
|
68137
|
+
if (hasErrnoCode(error, "ENOENT"))
|
|
68138
|
+
return { entries: [], publishing: false, held: new Map };
|
|
68139
|
+
throw error;
|
|
68140
|
+
}
|
|
68141
|
+
let publishing = false;
|
|
68142
|
+
for (const name of names.filter((each) => TEMPORARY_NAME.test(each))) {
|
|
68095
68143
|
let text;
|
|
68096
68144
|
try {
|
|
68097
68145
|
text = await readFile8(join18(directory, name), "utf8");
|
|
68098
68146
|
} catch {
|
|
68099
|
-
|
|
68147
|
+
publishing = true;
|
|
68148
|
+
break;
|
|
68100
68149
|
}
|
|
68101
|
-
|
|
68150
|
+
const server = serverOf(text);
|
|
68151
|
+
if (server !== undefined && serverAlive(server, probe)) {
|
|
68152
|
+
publishing = true;
|
|
68153
|
+
break;
|
|
68154
|
+
}
|
|
68155
|
+
}
|
|
68156
|
+
const entries = [];
|
|
68157
|
+
const held = new Map;
|
|
68158
|
+
for (const { name, seq } of numbered(names)) {
|
|
68159
|
+
let text;
|
|
68102
68160
|
try {
|
|
68103
|
-
|
|
68161
|
+
text = await readFile8(join18(directory, name), "utf8");
|
|
68104
68162
|
} catch {
|
|
68105
|
-
|
|
68163
|
+
continue;
|
|
68106
68164
|
}
|
|
68107
|
-
|
|
68165
|
+
const server = serverOf(text);
|
|
68166
|
+
if (server === undefined) {
|
|
68108
68167
|
const written = await stat6(join18(directory, name)).then((info) => info.mtimeMs, () => {
|
|
68109
68168
|
return;
|
|
68110
68169
|
});
|
|
68111
|
-
if (written === undefined
|
|
68170
|
+
if (written === undefined)
|
|
68112
68171
|
continue;
|
|
68113
|
-
|
|
68172
|
+
if (now() - written <= UNREADABLE_ENTRY_MS)
|
|
68173
|
+
return;
|
|
68174
|
+
held.set(seq, text);
|
|
68175
|
+
continue;
|
|
68114
68176
|
}
|
|
68115
|
-
|
|
68116
|
-
|
|
68117
|
-
seq,
|
|
68118
|
-
started: typeof parsed.started === "string" ? parsed.started : null
|
|
68119
|
-
});
|
|
68177
|
+
held.set(seq, text);
|
|
68178
|
+
entries.push({ ...server, seq });
|
|
68120
68179
|
}
|
|
68121
|
-
return entries;
|
|
68180
|
+
return { entries, publishing, held };
|
|
68122
68181
|
}
|
|
68123
68182
|
async function currentOwner(directory, probe = SYSTEM_PROBE) {
|
|
68124
|
-
const
|
|
68125
|
-
if (
|
|
68183
|
+
const seen = await readEntries(directory, probe);
|
|
68184
|
+
if (seen === undefined)
|
|
68126
68185
|
return;
|
|
68127
|
-
const live = entries.filter((entry) => serverAlive(entry, probe));
|
|
68186
|
+
const live = seen.entries.filter((entry) => serverAlive(entry, probe));
|
|
68128
68187
|
live.sort((a, b) => a.seq - b.seq);
|
|
68129
|
-
|
|
68188
|
+
const owner = live[0];
|
|
68189
|
+
if (owner === undefined || !seen.publishing)
|
|
68190
|
+
return owner;
|
|
68191
|
+
for (let seq = 1;seq < owner.seq; seq++) {
|
|
68192
|
+
const text = seen.held.get(seq);
|
|
68193
|
+
if (text === undefined)
|
|
68194
|
+
return;
|
|
68195
|
+
const now = await readFile8(join18(directory, entryName({ seq })), "utf8").catch(() => {
|
|
68196
|
+
return;
|
|
68197
|
+
});
|
|
68198
|
+
if (now !== text)
|
|
68199
|
+
return;
|
|
68200
|
+
}
|
|
68201
|
+
return owner;
|
|
68130
68202
|
}
|
|
68131
68203
|
function waitForOwnership(directory, pid, started, signal, published = () => {
|
|
68132
68204
|
return;
|
|
68133
|
-
}, pollMs = 1000, probe = SYSTEM_PROBE) {
|
|
68205
|
+
}, pollMs = 1000, probe = SYSTEM_PROBE, warn = (text) => void process.stderr.write(`envoy-channel: ${text}
|
|
68206
|
+
`)) {
|
|
68134
68207
|
return new Promise((done) => {
|
|
68135
68208
|
let self2;
|
|
68136
68209
|
let timer;
|
|
68210
|
+
let failing = false;
|
|
68137
68211
|
const look = async () => {
|
|
68138
68212
|
if (signal.aborted)
|
|
68139
68213
|
return done(undefined);
|
|
68140
|
-
const
|
|
68141
|
-
|
|
68142
|
-
|
|
68143
|
-
|
|
68214
|
+
const seen = await readEntries(directory, probe);
|
|
68215
|
+
const had = self2;
|
|
68216
|
+
if (seen !== undefined && !seen.entries.some((entry) => entry.seq === had?.seq && entry.pid === pid && entry.started === started)) {
|
|
68217
|
+
self2 = undefined;
|
|
68218
|
+
if (had !== undefined)
|
|
68219
|
+
await unregisterServer(directory, had);
|
|
68144
68220
|
self2 = await registerServer(directory, pid, started);
|
|
68145
68221
|
published(self2);
|
|
68146
68222
|
}
|
|
68147
68223
|
const owner = await currentOwner(directory, probe);
|
|
68224
|
+
failing = false;
|
|
68148
68225
|
if (owner?.pid === pid)
|
|
68149
68226
|
done(self2);
|
|
68150
68227
|
else
|
|
68151
|
-
|
|
68228
|
+
next();
|
|
68152
68229
|
};
|
|
68153
|
-
const
|
|
68154
|
-
timer = setTimeout(() => void look().catch(
|
|
68230
|
+
const next = () => {
|
|
68231
|
+
timer = setTimeout(() => void look().catch(failed), pollMs);
|
|
68232
|
+
};
|
|
68233
|
+
const failed = (error) => {
|
|
68234
|
+
if (!failing) {
|
|
68235
|
+
warn(`this plugin server could not read or publish its entry in ${directory}, so it stands by and tries again: ${messageFor(error)}`);
|
|
68236
|
+
}
|
|
68237
|
+
failing = true;
|
|
68238
|
+
next();
|
|
68155
68239
|
};
|
|
68156
68240
|
signal.addEventListener("abort", () => {
|
|
68157
68241
|
if (timer !== undefined)
|
|
68158
68242
|
clearTimeout(timer);
|
|
68159
68243
|
done(undefined);
|
|
68160
68244
|
});
|
|
68161
|
-
look().catch(
|
|
68245
|
+
look().catch(failed);
|
|
68162
68246
|
});
|
|
68163
68247
|
}
|
|
68164
68248
|
async function stillOwner(directory, self2, probe = SYSTEM_PROBE) {
|
|
68165
|
-
const entries = await readEntries(directory);
|
|
68166
|
-
if (entries === undefined)
|
|
68167
|
-
return true;
|
|
68168
68249
|
const owner = await currentOwner(directory, probe);
|
|
68169
68250
|
return owner === undefined || owner.pid === self2.pid;
|
|
68170
68251
|
}
|
package/dist/session-hook.js
CHANGED
|
@@ -14320,16 +14320,45 @@ function preconditionKept(value) {
|
|
|
14320
14320
|
const precondition = input.precondition;
|
|
14321
14321
|
return typeof precondition.document === "string" !== Array.isArray(precondition.blocks);
|
|
14322
14322
|
}
|
|
14323
|
+
var REPLACE_OP_KEYS = {
|
|
14324
|
+
op: true,
|
|
14325
|
+
find: true,
|
|
14326
|
+
with: true,
|
|
14327
|
+
occurrence: true
|
|
14328
|
+
};
|
|
14329
|
+
var REPLACE_OP_RULE = 'A replace names with and takes find, with and occurrence alone: with "" deletes the match on purpose, and a replace without with, or with its new text under another key such as markdown, would delete the match too.';
|
|
14330
|
+
function replaceOpsProblem(value) {
|
|
14331
|
+
if (typeof value !== "object" || value === null || !("ops" in value))
|
|
14332
|
+
return;
|
|
14333
|
+
const ops = value.ops;
|
|
14334
|
+
if (!Array.isArray(ops))
|
|
14335
|
+
return;
|
|
14336
|
+
const problems = [];
|
|
14337
|
+
ops.forEach((op, index) => {
|
|
14338
|
+
if (typeof op !== "object" || op === null || !("op" in op) || op.op !== "replace")
|
|
14339
|
+
return;
|
|
14340
|
+
const foreign = Object.entries(op).filter(([key, held]) => REPLACE_OP_KEYS[key] !== true && held !== undefined).map(([key]) => key);
|
|
14341
|
+
if (foreign.length > 0) {
|
|
14342
|
+
problems.push(`ops[${index}] is a replace carrying ${foreign.join(" and ")}, which replace does not take: it takes find, with and occurrence, and its new text goes in with.`);
|
|
14343
|
+
}
|
|
14344
|
+
if (!("with" in op) || op.with === undefined) {
|
|
14345
|
+
problems.push(`ops[${index}] is a replace with no with, which would delete the text find matches: write the new text in with, or with "" to delete it on purpose.`);
|
|
14346
|
+
}
|
|
14347
|
+
});
|
|
14348
|
+
return problems.length === 0 ? undefined : problems.join(" ");
|
|
14349
|
+
}
|
|
14323
14350
|
function documentEditProblem(value) {
|
|
14351
|
+
const replaceProblem = replaceOpsProblem(value);
|
|
14324
14352
|
return brokenParts([
|
|
14325
14353
|
[documentEditOwner.check(value), documentEditOwner.message],
|
|
14326
|
-
[preconditionKept(value), PRECONDITION_RULE]
|
|
14354
|
+
[preconditionKept(value), PRECONDITION_RULE],
|
|
14355
|
+
[replaceProblem === undefined, replaceProblem ?? REPLACE_OP_RULE]
|
|
14327
14356
|
]);
|
|
14328
14357
|
}
|
|
14329
14358
|
var documentEditValidation = {
|
|
14330
14359
|
check: (value) => documentEditProblem(value) === undefined,
|
|
14331
|
-
message: `${documentEditOwner.message} ${PRECONDITION_RULE}`,
|
|
14332
|
-
refusal: (value) => documentEditProblem(value) ?? `${documentEditOwner.message} ${PRECONDITION_RULE}`
|
|
14360
|
+
message: `${documentEditOwner.message} ${PRECONDITION_RULE} ${REPLACE_OP_RULE}`,
|
|
14361
|
+
refusal: (value) => documentEditProblem(value) ?? `${documentEditOwner.message} ${PRECONDITION_RULE} ${REPLACE_OP_RULE}`
|
|
14333
14362
|
};
|
|
14334
14363
|
var commentOwner = documentOwnerValidation(true);
|
|
14335
14364
|
var COMMENT_TURN_RULE = "turn requires reply_to_ask: turn says who holds an open ask's thread after the reply. Pass reply_to_ask with the open ask's id, or drop turn.";
|
|
@@ -14798,7 +14827,7 @@ var dispatchToolSpecs = [
|
|
|
14798
14827
|
ops: z.array(z.object({
|
|
14799
14828
|
op: z.enum(DOC_EDIT_OPS).describe("Edit operation."),
|
|
14800
14829
|
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(),
|
|
14801
|
-
with: z.string().describe("Replacement text for replace:
|
|
14830
|
+
with: z.string().describe("Replacement text for replace, which every replace names: an empty value deletes the match on purpose. A replace takes op, find, with and occurrence alone, and one without with, or carrying any other key whatever it holds, is refused before it is sent, and by the server with 400 REPLACE_FIELDS, the document unchanged. Inside a code block, with is 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(),
|
|
14802
14831
|
occurrence: z.number({ int: true, min: 0 }).describe("Optional zero-based match occurrence.").optional(),
|
|
14803
14832
|
markdown: z.string().describe("Markdown to insert; a CR LF or a lone carriage return in it is written as a line feed.").optional(),
|
|
14804
14833
|
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(),
|