@astrosheep/keiyaku 4.6.32 → 4.6.33
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 +8 -6
- package/build/plugins/claude/skills/keiyaku-akuma/SKILL.md +13 -9
- package/build/plugins/claude/skills/keiyaku-babysit/SKILL.md +8 -6
- package/build/plugins/claude/skills/keiyaku-workflow/SKILL.md +2 -1
- package/build/plugins/codex/skills/keiyaku-akuma/SKILL.md +13 -9
- package/build/plugins/codex/skills/keiyaku-babysit/SKILL.md +8 -6
- package/build/plugins/codex/skills/keiyaku-workflow/SKILL.md +2 -1
- package/build/plugins/opencode/skills/keiyaku-akuma/SKILL.md +13 -9
- package/build/plugins/opencode/skills/keiyaku-babysit/SKILL.md +8 -6
- package/build/plugins/opencode/skills/keiyaku-workflow/SKILL.md +2 -1
- package/build/plugins/pi/README.md +55 -97
- package/build/plugins/pi/keiyaku.ts +2 -9
- package/build/skills/keiyaku-akuma/SKILL.md +13 -9
- package/build/skills/keiyaku-babysit/SKILL.md +8 -6
- package/build/skills/keiyaku-workflow/SKILL.md +2 -1
- package/build/src/akuma/akuma-instance.d.ts +11 -0
- package/build/src/akuma/akuma-instance.js +1 -2
- package/build/src/akuma/akuma-observe.js +73 -14
- package/build/src/akuma/akuma-selection-execution.d.ts +82 -7
- package/build/src/akuma/akuma-selection-execution.js +26 -27
- package/build/src/akuma/akuma-wait.d.ts +40 -1
- package/build/src/akuma/akuma-wait.js +58 -29
- package/build/src/akuma/akuma.d.ts +11 -0
- package/build/src/akuma/body.js +13 -18
- package/build/src/akuma/call-initial-tell.d.ts +0 -1
- package/build/src/akuma/call-initial-tell.js +0 -1
- package/build/src/akuma/heart/activity-schema.d.ts +16 -0
- package/build/src/akuma/heart/activity-schema.js +7 -0
- package/build/src/akuma/heart/index.d.ts +1 -1
- package/build/src/akuma/heart/index.js +9 -1
- package/build/src/akuma/heart/timeline.js +4 -4
- package/build/src/akuma/projection-read.d.ts +4 -2
- package/build/src/akuma/projection-read.js +21 -14
- package/build/src/akuma/projection.d.ts +94 -2
- package/build/src/akuma/projection.js +47 -47
- package/build/src/akuma/provider.d.ts +2 -2
- package/build/src/akuma/provider.js +27 -20
- package/build/src/akuma/providers/acp/core.js +2 -5
- package/build/src/akuma/providers/opencode-sdk/events.d.ts +2 -1
- package/build/src/akuma/providers/opencode-sdk/events.js +31 -1
- package/build/src/akuma/publication.js +3 -2
- package/build/src/akuma/selection-observation.d.ts +23 -0
- package/build/src/akuma/selection-observation.js +15 -4
- package/build/src/akuma/status-projection.d.ts +14 -1
- package/build/src/akuma/status-projection.js +40 -2
- package/build/src/akuma/turn-drive.js +21 -15
- package/build/src/body/amend.js +5 -17
- package/build/src/body/decode.js +11 -1
- package/build/src/body/envelope.d.ts +5 -1
- package/build/src/body/envelope.js +4 -2
- package/build/src/body/render.js +4 -6
- package/build/src/cli/commands/akuma-grammar.d.ts +3 -5
- package/build/src/cli/commands/akuma-grammar.js +22 -40
- package/build/src/cli/commands/akuma.d.ts +1 -2
- package/build/src/cli/commands/akuma.js +6 -58
- package/build/src/cli/commands/contract-grammar.d.ts +1 -0
- package/build/src/cli/commands/contract-grammar.js +7 -11
- package/build/src/cli/commands/contract-help.d.ts +3 -2
- package/build/src/cli/commands/contract-help.js +11 -5
- package/build/src/cli/commands/contract.js +3 -0
- package/build/src/cli/commands/debt-grammar.js +2 -4
- package/build/src/cli/parse.js +1 -4
- package/build/src/cli/render/akuma-activity.d.ts +3 -15
- package/build/src/cli/render/akuma-activity.js +19 -73
- package/build/src/cli/render/akuma.d.ts +5 -11
- package/build/src/cli/render/akuma.js +22 -30
- package/build/src/cli/render/catalog.js +1 -4
- package/build/src/cli/render/contract-history.js +2 -0
- package/build/src/cli/render/contract-observation.d.ts +2 -1
- package/build/src/cli/render/contract-observation.js +25 -1
- package/build/src/cli/render/contract-wait.d.ts +2 -2
- package/build/src/cli/render/contract-wait.js +13 -17
- package/build/src/cli/render/contract.js +12 -9
- package/build/src/cli/render/debt.js +1 -2
- package/build/src/cli/render/execution-progress.js +1 -3
- package/build/src/cli/render/kanshi-akuma.js +1 -2
- package/build/src/cli/render/kanshi.js +11 -17
- package/build/src/cli/render/receipt.d.ts +1 -1
- package/build/src/cli/render/receipt.js +33 -28
- package/build/src/cli/render/reconcile.js +2 -5
- package/build/src/cli/render/refusal.js +3 -6
- package/build/src/cli/render/terminal.d.ts +2 -4
- package/build/src/cli/render/terminal.js +10 -17
- package/build/src/cli/render/verbs.d.ts +1 -0
- package/build/src/cli/render/verbs.js +19 -17
- package/build/src/cli/runtime.js +3 -9
- package/build/src/core/facts/codec.js +7 -2
- package/build/src/core/facts/eligibility.d.ts +4 -4
- package/build/src/core/facts/eligibility.js +11 -0
- package/build/src/core/facts/fold.js +9 -5
- package/build/src/core/facts/gate.d.ts +5 -1
- package/build/src/core/facts/gate.js +14 -10
- package/build/src/core/facts/types.d.ts +5 -1
- package/build/src/core/facts/types.js +7 -0
- package/build/src/core/subject.d.ts +4 -1
- package/build/src/core/subject.js +10 -2
- package/build/src/core/verbs/amend.d.ts +15 -4
- package/build/src/core/verbs/amend.js +19 -9
- package/build/src/debt/index.d.ts +0 -1
- package/build/src/debt/index.js +6 -11
- package/build/src/debt/input.d.ts +2 -1
- package/build/src/debt/input.js +6 -4
- package/build/src/dispatch/index.d.ts +0 -17
- package/build/src/dispatch/index.js +1 -10
- package/build/src/git/identity.js +16 -45
- package/build/src/git/nuke.js +13 -23
- package/build/src/git/observe.d.ts +3 -0
- package/build/src/git/observe.js +25 -23
- package/build/src/git/process.js +11 -18
- package/build/src/git/read-observation.d.ts +5 -4
- package/build/src/git/repository.d.ts +2 -0
- package/build/src/git/repository.js +13 -1
- package/build/src/git/scratch.js +2 -14
- package/build/src/git/terminal-reconcile.js +1 -13
- package/build/src/index.d.ts +2 -0
- package/build/src/kanshi/index.d.ts +0 -1
- package/build/src/kanshi/index.js +0 -1
- package/build/src/kanshi/read.d.ts +21 -0
- package/build/src/kanshi/read.js +2 -1
- package/build/src/kanshi/report.d.ts +94 -0
- package/build/src/library/address.d.ts +12 -5
- package/build/src/library/address.js +18 -32
- package/build/src/library/akuma-creation.d.ts +39 -0
- package/build/src/library/akuma-creation.js +3 -9
- package/build/src/library/continuation.d.ts +10 -0
- package/build/src/library/contract-creation.js +10 -11
- package/build/src/library/contract-outcomes.d.ts +72 -1
- package/build/src/library/contract-outcomes.js +1 -0
- package/build/src/library/contract-types.d.ts +18 -0
- package/build/src/library/contract-types.js +2 -0
- package/build/src/library/contract-wait.d.ts +7 -0
- package/build/src/library/contract-wait.js +53 -49
- package/build/src/library/delivery.d.ts +25 -0
- package/build/src/library/input.d.ts +5 -23
- package/build/src/library/input.js +12 -7
- package/build/src/library/kei.js +39 -20
- package/build/src/library/keiyaku-classify.js +3 -3
- package/build/src/library/keiyaku-debt.js +1 -2
- package/build/src/library/keiyaku-identity.d.ts +3 -3
- package/build/src/library/keiyaku-identity.js +11 -6
- package/build/src/library/keiyaku-verbs.d.ts +456 -1362
- package/build/src/library/keiyaku-verbs.js +80 -92
- package/build/src/library/keiyaku-wait.d.ts +183 -0
- package/build/src/library/keiyaku-wait.js +213 -0
- package/build/src/library/keiyaku.d.ts +3 -1
- package/build/src/library/keiyaku.js +49 -73
- package/build/src/{mcp/output.d.ts → library/model-tools.d.ts} +227 -56
- package/build/src/library/model-tools.js +347 -0
- package/build/src/library/outcome.js +5 -6
- package/build/src/library/refusal.d.ts +25 -1
- package/build/src/library/refusal.js +4 -5
- package/build/src/library/selection.d.ts +12 -0
- package/build/src/library/selection.js +1 -2
- package/build/src/mcp/adapter.d.ts +0 -6
- package/build/src/mcp/adapter.js +10 -159
- package/build/src/mcp/description.d.ts +2 -0
- package/build/src/mcp/description.js +2 -0
- package/build/src/mcp/help.d.ts +1 -1
- package/build/src/mcp/help.js +6 -4
- package/build/src/pi/index.d.ts +3 -0
- package/build/src/pi/index.js +83 -0
- package/build/src/protocol/amend.d.ts +14 -3
- package/build/src/protocol/amend.js +113 -46
- package/build/src/protocol/bind.d.ts +1 -1
- package/build/src/protocol/bind.js +5 -16
- package/build/src/protocol/completion.d.ts +30 -0
- package/build/src/protocol/completion.js +8 -5
- package/build/src/protocol/deliver.js +7 -20
- package/build/src/protocol/delivery-preview.d.ts +5 -0
- package/build/src/protocol/execution-observation.d.ts +8 -0
- package/build/src/protocol/intent.d.ts +1 -0
- package/build/src/protocol/intent.js +4 -1
- package/build/src/protocol/operations.d.ts +54 -16
- package/build/src/protocol/operations.js +17 -31
- package/build/src/protocol/placement.js +7 -1
- package/build/src/protocol/progress.js +0 -6
- package/build/src/protocol/read/status.d.ts +40 -0
- package/build/src/protocol/read/status.js +7 -10
- package/build/src/protocol/reintegrate.js +2 -2
- package/build/src/protocol/result-leaves.d.ts +56 -8
- package/build/src/protocol/result-leaves.js +11 -2
- package/build/src/protocol/run.js +1 -4
- package/build/src/protocol/verify.d.ts +10 -0
- package/build/src/protocol/verify.js +1 -0
- package/build/src/runtime/proc/windows-launch.exe +0 -0
- package/build/src/settlement/settle.js +19 -68
- package/package.json +7 -3
- package/plugins/pi/README.md +55 -97
- package/plugins/pi/keiyaku.ts +2 -9
- package/skills/keiyaku-akuma/SKILL.md +13 -9
- package/skills/keiyaku-babysit/SKILL.md +8 -6
- package/skills/keiyaku-workflow/SKILL.md +2 -1
- package/build/plugins/pi/akuma-tools.ts +0 -283
- package/build/src/body/keys.d.ts +0 -4
- package/build/src/body/keys.js +0 -11
- package/build/src/kanshi/roster.d.ts +0 -2
- package/build/src/kanshi/roster.js +0 -2
- package/build/src/mcp/output.js +0 -193
- package/plugins/pi/akuma-tools.ts +0 -283
|
@@ -4,22 +4,23 @@ export { classifyVerb } from "./keiyaku-classify.js";
|
|
|
4
4
|
import { durationSchema } from "../akuma/call-input.js";
|
|
5
5
|
import { parseDuration } from "../duration.js";
|
|
6
6
|
import { addDebtInputSchema, updateDebtInputSchema } from "../debt/input.js";
|
|
7
|
-
import {
|
|
7
|
+
import { amendInputSchema } from "./input.js";
|
|
8
8
|
import { askProgressSchema } from "../akuma/akuma-selection-execution.js";
|
|
9
9
|
import { akumaReportResultSchema } from "../akuma/akuma-instance.js";
|
|
10
10
|
import { akumaIdSchema } from "../akuma/identity.js";
|
|
11
11
|
import { contractIdSchema } from "../git/identity.js";
|
|
12
12
|
import { akumaNameCatalogSchema } from "../akuma/archetype.js";
|
|
13
|
-
import { akumaCatalogueSchema, akumaObservationSchema, akumaAskResultSchema, akumaAskNormalResultSchema, akumaKillResultSchema, akumaTellResultSchema,
|
|
13
|
+
import { akumaCatalogueSchema, akumaObservationSchema, akumaAskResultSchema, akumaAskNormalResultSchema, akumaKillResultSchema, akumaTellResultSchema, } from "../akuma/selection-observation.js";
|
|
14
14
|
import { regionResultSchema, kanshiReportSchema, contractStatusSchema, contractNormalStatusSchema, } from "../kanshi/report.js";
|
|
15
15
|
import { settingsSchema } from "../settings.js";
|
|
16
16
|
import { contractCatalogueSchema } from "../protocol/read/status.js";
|
|
17
17
|
import { executionObservationSchema } from "../protocol/execution-observation.js";
|
|
18
|
-
import {
|
|
18
|
+
import { spawnResultSchema, spawnNormalResultSchema, forkResultSchema, forkNormalResultSchema, } from "./akuma-creation.js";
|
|
19
19
|
import { bindOutcomeSchema, bindNormalOutcomeSchema, amendOutcomeSchema, arcOutcomeSchema, deliverOutcomeSchema, deliveryPreviewOutcomeSchema, verifyOutcomeSchema, verifyNormalOutcomeSchema, reviewOutcomeSchema, abandonOutcomeSchema, } from "./contract-outcomes.js";
|
|
20
20
|
import { contractHistorySchema } from "./contract-types.js";
|
|
21
21
|
import { guidanceSchema, guidanceNormalSchema } from "./kei.js";
|
|
22
|
-
import {
|
|
22
|
+
import { invocationWaitResultSchema, invocationWaitNormalResultSchema } from "./keiyaku-wait.js";
|
|
23
|
+
import { parseAkumaGlob, parseReadableAkumaAlias } from "../identity/selector.js";
|
|
23
24
|
import { reconcileResultSchema } from "./reconcile.js";
|
|
24
25
|
import { akumaHistoryResultSchema, historySelectionSchemas } from "./selection.js";
|
|
25
26
|
import { whoamiFactsSchema } from "./keiyaku-identity.js";
|
|
@@ -52,25 +53,23 @@ const debtSelection = z
|
|
|
52
53
|
.enum(["active", "closed", "all"])
|
|
53
54
|
.exactOptional()
|
|
54
55
|
.describe('Debt lifecycle filter (valid only with "debt"/"debt/"): "active" (open, default), "closed" (done or drop), or "all".');
|
|
55
|
-
const listBound = { limit: positive.exactOptional().describe("Maximum rows to return (positive integer).") };
|
|
56
56
|
const catalogueSelector = 'Catalogue path selector: "kei"/"kei/", "debt"/"debt/", "aku"/"aku/" (akumaName values), or "aku/*" / "aku/*/*" / "aku/<name>" / "aku/<name>/*" (instances).';
|
|
57
|
-
const lsInputSchema = z
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
]);
|
|
57
|
+
const lsInputSchema = z
|
|
58
|
+
.strictObject({
|
|
59
|
+
selector: text
|
|
60
|
+
.regex(/^(?:kei|debt|aku)\/?$|^aku\/(?:\*(?:\/\*)?|[^/*]+(?:\/\*|\/)?)$/u)
|
|
61
|
+
.describe(catalogueSelector),
|
|
62
|
+
limit: positive.exactOptional().describe("Maximum rows to return (positive integer)."),
|
|
63
|
+
selection: debtSelection,
|
|
64
|
+
mine: optBool.describe("When true on an Akuma-instance selector, restrict to direct and transitive descendants of this server environment's caller identity."),
|
|
65
|
+
})
|
|
66
|
+
.superRefine(({ selector, selection, mine }, context) => {
|
|
67
|
+
if (selection !== undefined && selector !== "debt" && selector !== "debt/")
|
|
68
|
+
context.addIssue({ code: "custom", message: "selection is valid only with a Debt catalogue" });
|
|
69
|
+
if (mine !== undefined && (!selector.startsWith("aku/") || selector === "aku/"))
|
|
70
|
+
context.addIssue({ code: "custom", message: "mine is valid only with an Akuma-instance catalogue" });
|
|
71
|
+
})
|
|
72
|
+
.readonly();
|
|
74
73
|
const spawnFields = {
|
|
75
74
|
akumaName: nonblank.describe('akumaName to spawn. Use ls {"selector":"aku/"} to list valid names, including when the selected name is not found. Always births a new instance; use tell or ask to continue an existing Akuma.'),
|
|
76
75
|
contract: optText.describe("Contract ID (kei/...) to record as Dispatch association for status/kanshi; does not set workdir or inject Contract text."),
|
|
@@ -114,14 +113,16 @@ export const verbs = Object.freeze({
|
|
|
114
113
|
effect: "write",
|
|
115
114
|
},
|
|
116
115
|
amend: {
|
|
117
|
-
description: "Rewrite an active Contract's terms, prerequisites (after), or gates. markdown is H2 edits such as ## Replace: Objective, not a new Contract. Returns only what changed.",
|
|
118
|
-
input:
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
116
|
+
description: "Rewrite an active Contract's terms, target, prerequisites (after), or gates; naming none reports the Contract unchanged and writes nothing. markdown is H2 edits such as ## Replace: Objective, not a new Contract. Returns only what changed.",
|
|
117
|
+
input: amendInputSchema
|
|
118
|
+
.extend({
|
|
119
|
+
markdown: amendInputSchema.shape.markdown.describe("Replacement Contract Markdown document or section-level amendment."),
|
|
120
|
+
after: amendInputSchema.shape.after.describe("Replacement prerequisite Contract IDs (kei/...); pass [] to clear prerequisites."),
|
|
121
|
+
gates: amendInputSchema.shape.gates.describe("Replacement acceptance gate names; pass [] to clear all gates."),
|
|
122
|
+
target: amendInputSchema.shape.target.describe("Explicit existing branch or active Contract destination; omission retains the current target."),
|
|
122
123
|
})
|
|
123
124
|
.extend(contract)
|
|
124
|
-
.readonly()
|
|
125
|
+
.readonly(),
|
|
125
126
|
output: amendOutcomeSchema,
|
|
126
127
|
effect: "write",
|
|
127
128
|
},
|
|
@@ -245,20 +246,15 @@ export const verbs = Object.freeze({
|
|
|
245
246
|
effect: "write",
|
|
246
247
|
},
|
|
247
248
|
spawn: {
|
|
248
|
-
description: "Birth a new Akuma from akumaName (ls aku/), with an optional first order. contract only marks whose work it is; give it a workdir and the terms yourself. A failed result with an akumaId still left an Akuma alive.",
|
|
249
|
+
description: "Birth a new Akuma from akumaName (ls aku/), with an optional first order. Returns birth and admission, not an answer; observe separately with wait. contract only marks whose work it is; give it a workdir and the terms yourself. A failed result with an akumaId still left an Akuma alive.",
|
|
249
250
|
input: z
|
|
250
251
|
.strictObject({
|
|
251
252
|
...spawnFields,
|
|
252
|
-
|
|
253
|
-
.exactOptional()
|
|
254
|
-
.describe("Wait for the opening turn's text answer up to this duration (e.g. 10m); requires prompt. The deadline never kills the Akuma. Omit to return after birth and admission."),
|
|
255
|
-
prompt: nonblank.exactOptional().describe("Opening instruction text; omit to birth idle. Required with wait."),
|
|
253
|
+
prompt: nonblank.exactOptional().describe("Opening instruction text; omit to birth idle."),
|
|
256
254
|
})
|
|
257
|
-
.refine((input) => input.wait === undefined || input.prompt !== undefined, "spawn wait requires prompt")
|
|
258
255
|
.readonly(),
|
|
259
256
|
output: spawnResultSchema,
|
|
260
257
|
normal: spawnNormalResultSchema,
|
|
261
|
-
progress: spawnProgressSchema,
|
|
262
258
|
effect: "write",
|
|
263
259
|
},
|
|
264
260
|
fork: {
|
|
@@ -275,17 +271,13 @@ export const verbs = Object.freeze({
|
|
|
275
271
|
effect: "write",
|
|
276
272
|
},
|
|
277
273
|
tell: {
|
|
278
|
-
description: "Give an Akuma new orders: steers its current work or wakes it. Returns
|
|
274
|
+
description: "Give an Akuma new orders: steers its current work or wakes it. Returns admission, not an answer. Observe work separately with wait, or use ask for a structured answer.",
|
|
279
275
|
input: z
|
|
280
276
|
.strictObject({
|
|
281
277
|
...tellFields,
|
|
282
|
-
wait: waitDuration
|
|
283
|
-
.exactOptional()
|
|
284
|
-
.describe("Wait for this exact turn's text answer up to this duration (e.g. 10m). Omit to return after admission; the deadline never retracts the Tell or kills the Akuma."),
|
|
285
278
|
})
|
|
286
279
|
.readonly(),
|
|
287
280
|
output: akumaTellResultSchema,
|
|
288
|
-
progress: askProgressSchema,
|
|
289
281
|
effect: "write",
|
|
290
282
|
},
|
|
291
283
|
ask: {
|
|
@@ -315,41 +307,41 @@ export const verbs = Object.freeze({
|
|
|
315
307
|
effect: "destroy",
|
|
316
308
|
},
|
|
317
309
|
wait: {
|
|
318
|
-
description: "Wait
|
|
319
|
-
input: z
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
output:
|
|
352
|
-
normal:
|
|
310
|
+
description: "Wait for Contracts to change or close and Akumas to finish their current work, together or separately. Any/all applies to the whole selection. Already satisfied members count immediately. A timeout ends observation, never the work.",
|
|
311
|
+
input: z
|
|
312
|
+
.strictObject({
|
|
313
|
+
selectors: z
|
|
314
|
+
.array(z.union([
|
|
315
|
+
contractIdSchema,
|
|
316
|
+
text.refine((value) => {
|
|
317
|
+
try {
|
|
318
|
+
if (value.startsWith("@"))
|
|
319
|
+
parseReadableAkumaAlias(value);
|
|
320
|
+
else if (value.includes("*"))
|
|
321
|
+
parseAkumaGlob(value);
|
|
322
|
+
else
|
|
323
|
+
return akumaIdSchema.safeParse(value).success;
|
|
324
|
+
return true;
|
|
325
|
+
}
|
|
326
|
+
catch {
|
|
327
|
+
return false;
|
|
328
|
+
}
|
|
329
|
+
}, "Expected an Akuma ID, alias or glob"),
|
|
330
|
+
]))
|
|
331
|
+
.min(1)
|
|
332
|
+
.readonly()
|
|
333
|
+
.describe('Contract IDs (kei/...) and Akuma selectors (aku/<name>/<hex>, @alias, or "aku/<name-pattern>/<hex-pattern>"), in caller order. A Contract selects its journal, not dispatched Akumas.'),
|
|
334
|
+
completion: z
|
|
335
|
+
.enum(["any", "all"])
|
|
336
|
+
.exactOptional()
|
|
337
|
+
.describe('Wake when "any" member satisfies (default), or wait for "all" members.'),
|
|
338
|
+
timeout: waitDuration
|
|
339
|
+
.exactOptional()
|
|
340
|
+
.describe("One observation deadline as a duration (e.g. 5m); never cancels work."),
|
|
341
|
+
})
|
|
342
|
+
.readonly(),
|
|
343
|
+
output: invocationWaitResultSchema,
|
|
344
|
+
normal: invocationWaitNormalResultSchema,
|
|
353
345
|
effect: "read",
|
|
354
346
|
},
|
|
355
347
|
history: {
|
|
@@ -446,23 +438,19 @@ export const verbs = Object.freeze({
|
|
|
446
438
|
},
|
|
447
439
|
region: {
|
|
448
440
|
description: "Before parallel work: which files active Contracts claim to change and where those claims overlap. Advisory only; no locks, no conflict prediction.",
|
|
449
|
-
input: z
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
.readonly()
|
|
456
|
-
|
|
457
|
-
.
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
.describe("Nonempty repository-relative path or glob patterns to check against active Contract Regions; mutually exclusive with contract."),
|
|
463
|
-
})
|
|
464
|
-
.readonly(),
|
|
465
|
-
]),
|
|
441
|
+
input: z
|
|
442
|
+
.strictObject({
|
|
443
|
+
contract: optText.describe("Contract selector (kei/...) whose declared Region and overlaps to inspect; mutually exclusive with paths."),
|
|
444
|
+
paths: z
|
|
445
|
+
.array(text)
|
|
446
|
+
.min(1)
|
|
447
|
+
.readonly()
|
|
448
|
+
.refine((paths) => paths.length > 0)
|
|
449
|
+
.exactOptional()
|
|
450
|
+
.describe("Nonempty repository-relative path or glob patterns to check against active Contract Regions; mutually exclusive with contract."),
|
|
451
|
+
})
|
|
452
|
+
.refine((input) => !(input.contract !== undefined && input.paths !== undefined), "contract and paths are mutually exclusive")
|
|
453
|
+
.readonly(),
|
|
466
454
|
output: regionResultSchema,
|
|
467
455
|
effect: "read",
|
|
468
456
|
},
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { type AkumaId } from "../akuma/identity.js";
|
|
3
|
+
import type { ContractId } from "../core/facts/types.js";
|
|
4
|
+
import type { WorldRoot } from "../world.js";
|
|
5
|
+
import { type Repo } from "./repo.js";
|
|
6
|
+
export declare const invocationWaitMemberSchema: z.ZodUnion<readonly [z.ZodReadonly<z.ZodObject<{
|
|
7
|
+
kind: z.ZodLiteral<"contract">;
|
|
8
|
+
observation: z.ZodReadonly<z.ZodObject<{
|
|
9
|
+
id: z.ZodPipe<z.ZodString, z.ZodTransform<ContractId, string>>;
|
|
10
|
+
changed: z.ZodExactOptional<z.ZodLiteral<true>>;
|
|
11
|
+
presence: z.ZodExactOptional<z.ZodEnum<{
|
|
12
|
+
unknown: "unknown";
|
|
13
|
+
missing: "missing";
|
|
14
|
+
}>>;
|
|
15
|
+
terminal: z.ZodExactOptional<z.ZodEnum<{
|
|
16
|
+
claimed: "claimed";
|
|
17
|
+
abandoned: "abandoned";
|
|
18
|
+
}>>;
|
|
19
|
+
}, z.core.$strict>>;
|
|
20
|
+
}, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
|
|
21
|
+
kind: z.ZodLiteral<"akuma">;
|
|
22
|
+
observation: z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodReadonly<z.ZodObject<{
|
|
23
|
+
kind: z.ZodLiteral<"observed">;
|
|
24
|
+
id: z.ZodPipe<z.ZodString, z.ZodTransform<AkumaId, string>>;
|
|
25
|
+
life: z.ZodEnum<{
|
|
26
|
+
hung: "hung";
|
|
27
|
+
untidy: "untidy";
|
|
28
|
+
killed: "killed";
|
|
29
|
+
running: "running";
|
|
30
|
+
asleep: "asleep";
|
|
31
|
+
stranded: "stranded";
|
|
32
|
+
}>;
|
|
33
|
+
pending: z.ZodExactOptional<z.ZodLiteral<true>>;
|
|
34
|
+
outcome: z.ZodExactOptional<z.ZodUnion<readonly [z.ZodReadonly<z.ZodObject<{
|
|
35
|
+
kind: z.ZodLiteral<"answered">;
|
|
36
|
+
historyId: z.ZodTemplateLiteral<`turn/${number}`>;
|
|
37
|
+
answer: z.ZodString;
|
|
38
|
+
}, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
|
|
39
|
+
kind: z.ZodLiteral<"failed">;
|
|
40
|
+
historyId: z.ZodTemplateLiteral<`turn/${number}`>;
|
|
41
|
+
diagnostic: z.ZodString;
|
|
42
|
+
}, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
|
|
43
|
+
kind: z.ZodLiteral<"canceled">;
|
|
44
|
+
historyId: z.ZodTemplateLiteral<`turn/${number}`>;
|
|
45
|
+
}, z.core.$strict>>]>>;
|
|
46
|
+
strandedReason: z.ZodExactOptional<z.ZodLiteral<"resume-unsupported">>;
|
|
47
|
+
}, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
|
|
48
|
+
kind: z.ZodLiteral<"unobserved">;
|
|
49
|
+
id: z.ZodPipe<z.ZodString, z.ZodTransform<AkumaId, string>>;
|
|
50
|
+
diagnostic: z.ZodString;
|
|
51
|
+
}, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
|
|
52
|
+
kind: z.ZodLiteral<"missing">;
|
|
53
|
+
id: z.ZodPipe<z.ZodString, z.ZodTransform<AkumaId, string>>;
|
|
54
|
+
}, z.core.$strict>>]>, z.ZodReadonly<z.ZodObject<{
|
|
55
|
+
kind: z.ZodLiteral<"unknown">;
|
|
56
|
+
id: z.ZodPipe<z.ZodString, z.ZodTransform<AkumaId, string>>;
|
|
57
|
+
}, z.core.$strict>>]>;
|
|
58
|
+
}, z.core.$strict>>]>;
|
|
59
|
+
export declare const invocationWaitResultSchema: z.ZodReadonly<z.ZodObject<{
|
|
60
|
+
kind: z.ZodLiteral<"wait">;
|
|
61
|
+
reason: z.ZodEnum<{
|
|
62
|
+
deadline: "deadline";
|
|
63
|
+
unavailable: "unavailable";
|
|
64
|
+
missing: "missing";
|
|
65
|
+
completed: "completed";
|
|
66
|
+
}>;
|
|
67
|
+
members: z.ZodReadonly<z.ZodArray<z.ZodUnion<readonly [z.ZodReadonly<z.ZodObject<{
|
|
68
|
+
kind: z.ZodLiteral<"contract">;
|
|
69
|
+
observation: z.ZodReadonly<z.ZodObject<{
|
|
70
|
+
id: z.ZodPipe<z.ZodString, z.ZodTransform<ContractId, string>>;
|
|
71
|
+
changed: z.ZodExactOptional<z.ZodLiteral<true>>;
|
|
72
|
+
presence: z.ZodExactOptional<z.ZodEnum<{
|
|
73
|
+
unknown: "unknown";
|
|
74
|
+
missing: "missing";
|
|
75
|
+
}>>;
|
|
76
|
+
terminal: z.ZodExactOptional<z.ZodEnum<{
|
|
77
|
+
claimed: "claimed";
|
|
78
|
+
abandoned: "abandoned";
|
|
79
|
+
}>>;
|
|
80
|
+
}, z.core.$strict>>;
|
|
81
|
+
}, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
|
|
82
|
+
kind: z.ZodLiteral<"akuma">;
|
|
83
|
+
observation: z.ZodUnion<readonly [z.ZodUnion<readonly [z.ZodReadonly<z.ZodObject<{
|
|
84
|
+
kind: z.ZodLiteral<"observed">;
|
|
85
|
+
id: z.ZodPipe<z.ZodString, z.ZodTransform<AkumaId, string>>;
|
|
86
|
+
life: z.ZodEnum<{
|
|
87
|
+
hung: "hung";
|
|
88
|
+
untidy: "untidy";
|
|
89
|
+
killed: "killed";
|
|
90
|
+
running: "running";
|
|
91
|
+
asleep: "asleep";
|
|
92
|
+
stranded: "stranded";
|
|
93
|
+
}>;
|
|
94
|
+
pending: z.ZodExactOptional<z.ZodLiteral<true>>;
|
|
95
|
+
outcome: z.ZodExactOptional<z.ZodUnion<readonly [z.ZodReadonly<z.ZodObject<{
|
|
96
|
+
kind: z.ZodLiteral<"answered">;
|
|
97
|
+
historyId: z.ZodTemplateLiteral<`turn/${number}`>;
|
|
98
|
+
answer: z.ZodString;
|
|
99
|
+
}, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
|
|
100
|
+
kind: z.ZodLiteral<"failed">;
|
|
101
|
+
historyId: z.ZodTemplateLiteral<`turn/${number}`>;
|
|
102
|
+
diagnostic: z.ZodString;
|
|
103
|
+
}, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
|
|
104
|
+
kind: z.ZodLiteral<"canceled">;
|
|
105
|
+
historyId: z.ZodTemplateLiteral<`turn/${number}`>;
|
|
106
|
+
}, z.core.$strict>>]>>;
|
|
107
|
+
strandedReason: z.ZodExactOptional<z.ZodLiteral<"resume-unsupported">>;
|
|
108
|
+
}, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
|
|
109
|
+
kind: z.ZodLiteral<"unobserved">;
|
|
110
|
+
id: z.ZodPipe<z.ZodString, z.ZodTransform<AkumaId, string>>;
|
|
111
|
+
diagnostic: z.ZodString;
|
|
112
|
+
}, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
|
|
113
|
+
kind: z.ZodLiteral<"missing">;
|
|
114
|
+
id: z.ZodPipe<z.ZodString, z.ZodTransform<AkumaId, string>>;
|
|
115
|
+
}, z.core.$strict>>]>, z.ZodReadonly<z.ZodObject<{
|
|
116
|
+
kind: z.ZodLiteral<"unknown">;
|
|
117
|
+
id: z.ZodPipe<z.ZodString, z.ZodTransform<AkumaId, string>>;
|
|
118
|
+
}, z.core.$strict>>]>;
|
|
119
|
+
}, z.core.$strict>>]>>>;
|
|
120
|
+
}, z.core.$strict>>;
|
|
121
|
+
export declare const invocationWaitNormalResultSchema: z.ZodReadonly<z.ZodObject<{
|
|
122
|
+
kind: z.ZodLiteral<"wait">;
|
|
123
|
+
reason: z.ZodEnum<{
|
|
124
|
+
deadline: "deadline";
|
|
125
|
+
completed: "completed";
|
|
126
|
+
}>;
|
|
127
|
+
members: z.ZodReadonly<z.ZodArray<z.ZodUnion<readonly [z.ZodReadonly<z.ZodObject<{
|
|
128
|
+
kind: z.ZodLiteral<"contract">;
|
|
129
|
+
observation: z.ZodReadonly<z.ZodObject<{
|
|
130
|
+
id: z.ZodPipe<z.ZodString, z.ZodTransform<ContractId, string>>;
|
|
131
|
+
changed: z.ZodExactOptional<z.ZodLiteral<true>>;
|
|
132
|
+
terminal: z.ZodExactOptional<z.ZodEnum<{
|
|
133
|
+
claimed: "claimed";
|
|
134
|
+
abandoned: "abandoned";
|
|
135
|
+
}>>;
|
|
136
|
+
presence: z.ZodExactOptional<z.ZodLiteral<"unknown">>;
|
|
137
|
+
}, z.core.$strict>>;
|
|
138
|
+
}, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
|
|
139
|
+
kind: z.ZodLiteral<"akuma">;
|
|
140
|
+
observation: z.ZodUnion<readonly [z.ZodReadonly<z.ZodObject<{
|
|
141
|
+
kind: z.ZodLiteral<"observed">;
|
|
142
|
+
id: z.ZodPipe<z.ZodString, z.ZodTransform<AkumaId, string>>;
|
|
143
|
+
life: z.ZodEnum<{
|
|
144
|
+
hung: "hung";
|
|
145
|
+
untidy: "untidy";
|
|
146
|
+
killed: "killed";
|
|
147
|
+
running: "running";
|
|
148
|
+
asleep: "asleep";
|
|
149
|
+
stranded: "stranded";
|
|
150
|
+
}>;
|
|
151
|
+
pending: z.ZodExactOptional<z.ZodLiteral<true>>;
|
|
152
|
+
outcome: z.ZodExactOptional<z.ZodUnion<readonly [z.ZodReadonly<z.ZodObject<{
|
|
153
|
+
kind: z.ZodLiteral<"answered">;
|
|
154
|
+
historyId: z.ZodTemplateLiteral<`turn/${number}`>;
|
|
155
|
+
answer: z.ZodString;
|
|
156
|
+
}, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
|
|
157
|
+
kind: z.ZodLiteral<"failed">;
|
|
158
|
+
historyId: z.ZodTemplateLiteral<`turn/${number}`>;
|
|
159
|
+
diagnostic: z.ZodString;
|
|
160
|
+
}, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
|
|
161
|
+
kind: z.ZodLiteral<"canceled">;
|
|
162
|
+
historyId: z.ZodTemplateLiteral<`turn/${number}`>;
|
|
163
|
+
}, z.core.$strict>>]>>;
|
|
164
|
+
strandedReason: z.ZodExactOptional<z.ZodLiteral<"resume-unsupported">>;
|
|
165
|
+
}, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
|
|
166
|
+
kind: z.ZodLiteral<"unknown">;
|
|
167
|
+
id: z.ZodPipe<z.ZodString, z.ZodTransform<AkumaId, string>>;
|
|
168
|
+
}, z.core.$strict>>]>;
|
|
169
|
+
}, z.core.$strict>>]>>>;
|
|
170
|
+
}, z.core.$strict>>;
|
|
171
|
+
export type InvocationWaitMember = z.output<typeof invocationWaitMemberSchema>;
|
|
172
|
+
export type InvocationWaitResult = z.output<typeof invocationWaitResultSchema>;
|
|
173
|
+
type WaitInput = Readonly<{
|
|
174
|
+
selectors: readonly string[];
|
|
175
|
+
repo?: Repo;
|
|
176
|
+
world?: WorldRoot;
|
|
177
|
+
completion?: "any" | "all";
|
|
178
|
+
timeoutMs?: number;
|
|
179
|
+
signal?: AbortSignal;
|
|
180
|
+
}>;
|
|
181
|
+
/** Freeze selection once, then compose native observations under one invocation deadline. */
|
|
182
|
+
export declare function waitInvocation(input: WaitInput): Promise<InvocationWaitResult>;
|
|
183
|
+
export {};
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/** @architectureCompositionRoot */
|
|
2
|
+
import { setTimeout as delay } from "node:timers/promises";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { AKUMA_WAIT_POLL_MS, createAkumaWaitObserver } from "../akuma/akuma-wait.js";
|
|
5
|
+
import { akumaIdSchema } from "../akuma/identity.js";
|
|
6
|
+
import { akumaWaitItemSchema } from "../akuma/selection-observation.js";
|
|
7
|
+
import { outcomePluginObserver, stderrPluginDiagnostic, withAkumaWaitDeferrals } from "../plugin/akuma-signals.js";
|
|
8
|
+
import { addressAkumaSet } from "./address.js";
|
|
9
|
+
import { contractWaitMemberSchema, createContractWaitObserver } from "./contract-wait.js";
|
|
10
|
+
import { scopeForRepo } from "./repo.js";
|
|
11
|
+
const unknownAkuma = z.strictObject({ kind: z.literal("unknown"), id: akumaIdSchema }).readonly();
|
|
12
|
+
const contractMember = z
|
|
13
|
+
.strictObject({ kind: z.literal("contract"), observation: contractWaitMemberSchema })
|
|
14
|
+
.readonly();
|
|
15
|
+
const akumaMember = z
|
|
16
|
+
.strictObject({
|
|
17
|
+
kind: z.literal("akuma"),
|
|
18
|
+
observation: z.union([akumaWaitItemSchema, unknownAkuma]),
|
|
19
|
+
})
|
|
20
|
+
.readonly();
|
|
21
|
+
export const invocationWaitMemberSchema = z.union([contractMember, akumaMember]);
|
|
22
|
+
export const invocationWaitResultSchema = z
|
|
23
|
+
.strictObject({
|
|
24
|
+
kind: z.literal("wait"),
|
|
25
|
+
reason: z.enum(["completed", "deadline", "missing", "unavailable"]),
|
|
26
|
+
members: z.array(invocationWaitMemberSchema).nonempty().readonly(),
|
|
27
|
+
})
|
|
28
|
+
.readonly();
|
|
29
|
+
export const invocationWaitNormalResultSchema = invocationWaitResultSchema
|
|
30
|
+
.unwrap()
|
|
31
|
+
.extend({
|
|
32
|
+
reason: z.enum(["completed", "deadline"]),
|
|
33
|
+
members: z
|
|
34
|
+
.array(z.union([
|
|
35
|
+
contractMember
|
|
36
|
+
.unwrap()
|
|
37
|
+
.extend({
|
|
38
|
+
observation: contractWaitMemberSchema
|
|
39
|
+
.unwrap()
|
|
40
|
+
.extend({ presence: z.literal("unknown").exactOptional() })
|
|
41
|
+
.readonly(),
|
|
42
|
+
})
|
|
43
|
+
.readonly(),
|
|
44
|
+
akumaMember
|
|
45
|
+
.unwrap()
|
|
46
|
+
.extend({ observation: z.union([akumaWaitItemSchema.options[0], unknownAkuma]) })
|
|
47
|
+
.readonly(),
|
|
48
|
+
]))
|
|
49
|
+
.nonempty()
|
|
50
|
+
.readonly(),
|
|
51
|
+
})
|
|
52
|
+
.readonly();
|
|
53
|
+
function freezeSubjects(selectors, expansions) {
|
|
54
|
+
let index = 0;
|
|
55
|
+
const seen = new Set();
|
|
56
|
+
return selectors.flatMap((selector) => {
|
|
57
|
+
const selected = selector.startsWith("kei/")
|
|
58
|
+
? [{ kind: "contract", id: selector }]
|
|
59
|
+
: expansions[index++].map((id) => ({ kind: "akuma", id }));
|
|
60
|
+
return selected.filter(({ id }) => {
|
|
61
|
+
if (seen.has(id))
|
|
62
|
+
return false;
|
|
63
|
+
seen.add(id);
|
|
64
|
+
return true;
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/** Freeze selection once, then compose native observations under one invocation deadline. */
|
|
69
|
+
export async function waitInvocation(input) {
|
|
70
|
+
const akumaSelectors = input.selectors.filter((selector) => !selector.startsWith("kei/"));
|
|
71
|
+
const addressed = akumaSelectors.length === 0
|
|
72
|
+
? undefined
|
|
73
|
+
: await addressAkumaSet({
|
|
74
|
+
path: input.world,
|
|
75
|
+
akuma: akumaSelectors,
|
|
76
|
+
...(input.repo === undefined ? {} : { repo: input.repo }),
|
|
77
|
+
}, { contractSelectors: false });
|
|
78
|
+
input.signal?.throwIfAborted();
|
|
79
|
+
const subjects = freezeSubjects(input.selectors, addressed?.selections ?? []);
|
|
80
|
+
return await observeSubjects(input, subjects, addressed);
|
|
81
|
+
}
|
|
82
|
+
function waitEvidence(subjects, contracts, akumas, completion) {
|
|
83
|
+
const members = () => {
|
|
84
|
+
const observed = new Map(contracts?.members().map((member) => [member.id, member]));
|
|
85
|
+
return subjects.map((subject) => subject.kind === "contract"
|
|
86
|
+
? { kind: "contract", observation: observed.get(subject.id) }
|
|
87
|
+
: { kind: "akuma", observation: akumas?.items.get(subject.id) ?? { kind: "unknown", id: subject.id } });
|
|
88
|
+
};
|
|
89
|
+
const conclusion = () => {
|
|
90
|
+
const evidence = members();
|
|
91
|
+
if (evidence.some((member) => member.kind === "contract" && member.observation.presence === "missing"))
|
|
92
|
+
return "missing";
|
|
93
|
+
if (evidence.some((member) => member.kind === "akuma" && member.observation.kind === "missing"))
|
|
94
|
+
return "unavailable";
|
|
95
|
+
const changed = new Set(contracts?.satisfied());
|
|
96
|
+
const satisfied = subjects.map((subject) => subject.kind === "contract" ? changed.has(subject.id) : akumas.satisfied(subject.id));
|
|
97
|
+
return (completion === "all" ? satisfied.every(Boolean) : satisfied.some(Boolean)) ? "completed" : undefined;
|
|
98
|
+
};
|
|
99
|
+
return {
|
|
100
|
+
conclusion,
|
|
101
|
+
async answer(reason, signal, initialOnly = false) {
|
|
102
|
+
// Preserve the native deadline-edge snapshot after the last cheap probe.
|
|
103
|
+
if (reason === "deadline" && !initialOnly)
|
|
104
|
+
await akumas?.observe(signal);
|
|
105
|
+
return { kind: "wait", reason: conclusion() ?? reason, members: members() };
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
function pacedAkumaRounds(observer, completion) {
|
|
110
|
+
let initial = true;
|
|
111
|
+
let next = 0;
|
|
112
|
+
return {
|
|
113
|
+
remaining: () => Math.max(0, next - performance.now()),
|
|
114
|
+
async observe(signal) {
|
|
115
|
+
if (performance.now() < next)
|
|
116
|
+
return;
|
|
117
|
+
next = performance.now() + AKUMA_WAIT_POLL_MS;
|
|
118
|
+
if (!initial) {
|
|
119
|
+
let ready;
|
|
120
|
+
try {
|
|
121
|
+
ready = await observer.probe(completion, signal);
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
signal.throwIfAborted();
|
|
125
|
+
ready = true;
|
|
126
|
+
}
|
|
127
|
+
if (!ready)
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
initial = false;
|
|
131
|
+
await observer.observe(signal);
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
async function observeSubjects(input, subjects, addressed) {
|
|
136
|
+
const contracts = subjects.flatMap((subject) => (subject.kind === "contract" ? [subject.id] : []));
|
|
137
|
+
const journals = contracts.length === 0 ? undefined : createContractWaitObserver(scopeForRepo(input.repo), contracts);
|
|
138
|
+
const akumas = addressed === undefined ? undefined : createAkumaWaitObserver(addressed.path, addressed.orderedIds);
|
|
139
|
+
const deadline = input.timeoutMs === undefined ? Infinity : performance.now() + input.timeoutMs;
|
|
140
|
+
const stop = new AbortController();
|
|
141
|
+
const signal = input.signal === undefined ? stop.signal : AbortSignal.any([input.signal, stop.signal]);
|
|
142
|
+
let expired = false;
|
|
143
|
+
let timer;
|
|
144
|
+
const schedule = () => {
|
|
145
|
+
const remaining = deadline - performance.now();
|
|
146
|
+
if (remaining <= 0) {
|
|
147
|
+
expired = true;
|
|
148
|
+
stop.abort();
|
|
149
|
+
}
|
|
150
|
+
else
|
|
151
|
+
timer = setTimeout(schedule, Math.min(remaining, 2_147_483_647));
|
|
152
|
+
};
|
|
153
|
+
// Like native waits, zero still takes an initial snapshot; positive bounds also cover reads.
|
|
154
|
+
if (input.timeoutMs !== undefined && input.timeoutMs > 0)
|
|
155
|
+
schedule();
|
|
156
|
+
const { conclusion, answer } = waitEvidence(subjects, journals, akumas, input.completion);
|
|
157
|
+
const akumaRounds = akumas === undefined ? undefined : pacedAkumaRounds(akumas, input.completion ?? "any");
|
|
158
|
+
const observe = async () => {
|
|
159
|
+
let reason;
|
|
160
|
+
let failure;
|
|
161
|
+
try {
|
|
162
|
+
for (;;) {
|
|
163
|
+
const round = async (read) => {
|
|
164
|
+
try {
|
|
165
|
+
await read();
|
|
166
|
+
reason ??= conclusion();
|
|
167
|
+
if (reason !== undefined)
|
|
168
|
+
stop.abort();
|
|
169
|
+
}
|
|
170
|
+
catch (error) {
|
|
171
|
+
if (!signal.aborted) {
|
|
172
|
+
failure = { error };
|
|
173
|
+
stop.abort(error);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
// Await retirement of both reads even when one family completes, fails or is cancelled.
|
|
178
|
+
await Promise.all([
|
|
179
|
+
...(journals === undefined ? [] : [round(() => journals.observe(signal))]),
|
|
180
|
+
...(akumaRounds === undefined ? [] : [round(() => akumaRounds.observe(signal))]),
|
|
181
|
+
]);
|
|
182
|
+
input.signal?.throwIfAborted();
|
|
183
|
+
if (failure !== undefined)
|
|
184
|
+
throw failure.error;
|
|
185
|
+
reason ??= conclusion();
|
|
186
|
+
if (reason !== undefined || expired || performance.now() >= deadline) {
|
|
187
|
+
return await answer(reason ?? "deadline", input.signal, input.timeoutMs === 0);
|
|
188
|
+
}
|
|
189
|
+
const remaining = Math.min(akumaRounds?.remaining() ?? Infinity, deadline - performance.now());
|
|
190
|
+
await delay(journals === undefined ? remaining : Math.min(100, remaining), undefined, { signal });
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
catch (error) {
|
|
194
|
+
input.signal?.throwIfAborted();
|
|
195
|
+
if (expired)
|
|
196
|
+
return await answer(conclusion() ?? "deadline", input.signal, input.timeoutMs === 0);
|
|
197
|
+
throw error;
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
try {
|
|
201
|
+
const result = addressed === undefined
|
|
202
|
+
? await observe()
|
|
203
|
+
: await withAkumaWaitDeferrals({ world: addressed.path, reportDiagnostic: stderrPluginDiagnostic }, { akumaIds: addressed.orderedIds }, input.signal, observe);
|
|
204
|
+
if (addressed !== undefined)
|
|
205
|
+
await akumas.notify(outcomePluginObserver({ world: addressed.path, reportDiagnostic: stderrPluginDiagnostic }));
|
|
206
|
+
return result;
|
|
207
|
+
}
|
|
208
|
+
finally {
|
|
209
|
+
if (timer !== undefined)
|
|
210
|
+
clearTimeout(timer);
|
|
211
|
+
akumas?.clear();
|
|
212
|
+
}
|
|
213
|
+
}
|