@astrosheep/keiyaku 4.5.11 → 4.5.13
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/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-workflow/SKILL.md +135 -377
- package/build/integrations/pi/keiyaku.ts +11 -116
- package/build/src/akuma/akuma-errors.d.ts +1 -0
- package/build/src/akuma/akuma-errors.js +1 -0
- package/build/src/akuma/akuma-handle.d.ts +1 -0
- package/build/src/akuma/akuma-handle.js +6 -7
- package/build/src/akuma/akuma-product.d.ts +6 -8
- package/build/src/akuma/akuma-product.js +141 -57
- package/build/src/akuma/akuma.d.ts +5 -7
- package/build/src/akuma/akuma.js +1 -22
- package/build/src/akuma/archetype.d.ts +6 -5
- package/build/src/akuma/archetype.js +137 -38
- package/build/src/akuma/body.d.ts +5 -5
- package/build/src/akuma/body.js +223 -63
- package/build/src/akuma/call-input.d.ts +4 -0
- package/build/src/akuma/call-input.js +21 -0
- package/build/src/akuma/call-request.d.ts +5 -8
- package/build/src/akuma/call-request.js +28 -73
- package/build/src/akuma/fleet-execution.d.ts +26 -0
- package/build/src/akuma/fleet-execution.js +109 -0
- package/build/src/{library/fleet-result.d.ts → akuma/fleet-observation.d.ts} +13 -57
- package/build/src/{library/fleet-result.js → akuma/fleet-observation.js} +4 -25
- package/build/src/akuma/fleet-request.d.ts +122 -0
- package/build/src/akuma/fleet-request.js +168 -0
- package/build/src/akuma/heart/facts.d.ts +23 -0
- package/build/src/akuma/heart/facts.js +7 -0
- package/build/src/akuma/heart/index.d.ts +43 -4
- package/build/src/akuma/heart/index.js +107 -7
- package/build/src/akuma/heart/request-authority.d.ts +2 -0
- package/build/src/akuma/heart/request-authority.js +28 -3
- package/build/src/akuma/heart/request-rows.d.ts +2 -0
- package/build/src/akuma/heart/request-rows.js +24 -5
- package/build/src/akuma/heart/rows.d.ts +4 -1
- package/build/src/akuma/heart/rows.js +46 -19
- package/build/src/akuma/heart/schema.d.ts +1 -1
- package/build/src/akuma/heart/schema.js +28 -6
- package/build/src/akuma/heart/storage.d.ts +1 -1
- package/build/src/akuma/heart/tells.d.ts +29 -0
- package/build/src/akuma/heart/tells.js +136 -5
- package/build/src/akuma/heart/timeline.js +9 -3
- package/build/src/akuma/projection-read.js +36 -3
- package/build/src/akuma/projection.js +3 -4
- package/build/src/akuma/provider.d.ts +4 -0
- package/build/src/akuma/provider.js +56 -3
- package/build/src/akuma/providers/claude/index.js +3 -0
- package/build/src/akuma/providers/codex-app-server/index.js +14 -12
- package/build/src/akuma/providers/pi/index.js +7 -1
- package/build/src/akuma/publication.js +65 -49
- package/build/src/akuma/request-lifecycle.d.ts +5 -4
- package/build/src/akuma/request-lifecycle.js +29 -16
- package/build/src/akuma/request-rendezvous.d.ts +15 -12
- package/build/src/akuma/request-rendezvous.js +80 -51
- package/build/src/akuma/request-serve.d.ts +1 -2
- package/build/src/akuma/request-serve.js +94 -39
- package/build/src/akuma/request-wire.d.ts +57 -26
- package/build/src/akuma/request-wire.js +64 -25
- package/build/src/akuma/turn-drive.d.ts +5 -4
- package/build/src/akuma/turn-drive.js +27 -11
- package/build/src/akuma-body.d.ts +4 -6
- package/build/src/akuma-body.js +19 -17
- package/build/src/bounded-list.d.ts +8 -0
- package/build/src/bounded-list.js +14 -0
- package/build/src/cli/accepted.d.ts +1 -1
- package/build/src/cli/accepted.js +1 -0
- package/build/src/cli/commands/akuma-invoke.js +1 -25
- package/build/src/cli/commands/contract-help.d.ts +5 -2
- package/build/src/cli/commands/contract-help.js +62 -12
- package/build/src/cli/commands/contract-invoke.d.ts +5 -0
- package/build/src/cli/commands/contract-invoke.js +26 -1
- package/build/src/cli/commands/contract.js +50 -18
- package/build/src/cli/commands/task-invoke.js +10 -2
- package/build/src/cli/commands/task-query.js +3 -4
- package/build/src/cli/coordinates.d.ts +13 -0
- package/build/src/cli/coordinates.js +38 -24
- package/build/src/cli/draft.d.ts +1 -1
- package/build/src/cli/invoke.js +14 -1
- package/build/src/cli/render/akuma-activity.d.ts +0 -1
- package/build/src/cli/render/akuma-activity.js +5 -38
- package/build/src/cli/render/akuma.js +4 -1
- package/build/src/cli/render/audit.js +4 -1
- package/build/src/cli/render/catalog.js +13 -39
- package/build/src/cli/render/contract.js +4 -14
- package/build/src/cli/render/kanshi-akuma.js +3 -8
- package/build/src/cli/render/kanshi.js +8 -34
- package/build/src/cli/render/nuke.js +7 -3
- package/build/src/cli/render/receipt.d.ts +1 -0
- package/build/src/cli/render/receipt.js +8 -0
- package/build/src/cli/render/refusal.js +4 -3
- package/build/src/cli/render/task.js +4 -37
- package/build/src/cli/render/terminal.d.ts +2 -6
- package/build/src/cli/render/terminal.js +4 -9
- package/build/src/cli/result.d.ts +2 -1
- package/build/src/contract-guidance.js +13 -3
- package/build/src/contract-worktree.d.ts +1 -0
- package/build/src/contract-worktree.js +26 -2
- package/build/src/core/facts/codec.d.ts +2 -1
- package/build/src/core/facts/codec.js +3 -0
- package/build/src/core/facts/gate.d.ts +2 -1
- package/build/src/core/facts/gate.js +63 -0
- package/build/src/core/verbs/abandon.d.ts +2 -1
- package/build/src/core/verbs/abandon.js +16 -0
- package/build/src/core/verbs/amend.d.ts +2 -1
- package/build/src/core/verbs/amend.js +20 -0
- package/build/src/core/verbs/arc.d.ts +2 -1
- package/build/src/core/verbs/arc.js +16 -0
- package/build/src/core/verbs/attestation.d.ts +2 -1
- package/build/src/core/verbs/attestation.js +16 -0
- package/build/src/core/verbs/bind.d.ts +2 -1
- package/build/src/core/verbs/bind.js +16 -0
- package/build/src/core/verbs/deliver.d.ts +2 -1
- package/build/src/core/verbs/deliver.js +16 -0
- package/build/src/core/verbs/placement.d.ts +2 -1
- package/build/src/core/verbs/placement.js +58 -1
- package/build/src/dispatch/association.d.ts +13 -0
- package/build/src/dispatch/association.js +20 -0
- package/build/src/dispatch/index.d.ts +6 -0
- package/build/src/dispatch/index.js +27 -3
- package/build/src/git/hooks.d.ts +9 -1
- package/build/src/git/hooks.js +79 -1
- package/build/src/git/nuke.d.ts +2 -1
- package/build/src/git/nuke.js +6 -11
- package/build/src/git/private-state-seat.d.ts +26 -1
- package/build/src/git/private-state-seat.js +78 -13
- package/build/src/git/process.d.ts +2 -0
- package/build/src/git/reconcile.d.ts +1 -2
- package/build/src/git/reconcile.js +0 -6
- package/build/src/git/repository.d.ts +0 -2
- package/build/src/git/repository.js +27 -25
- package/build/src/git/result-codec.d.ts +29 -0
- package/build/src/git/result-codec.js +306 -0
- package/build/src/git/target-placement.js +2 -8
- package/build/src/git/workspace.d.ts +2 -0
- package/build/src/git/workspace.js +4 -0
- package/build/src/index.d.ts +1 -0
- package/build/src/kanshi/fleet.js +1 -1
- package/build/src/kanshi/read.js +55 -28
- package/build/src/kanshi/report.d.ts +4 -3
- package/build/src/kanshi/select.js +14 -1
- package/build/src/library/address.d.ts +1 -0
- package/build/src/library/address.js +4 -7
- package/build/src/library/akuma-creation.d.ts +5 -3
- package/build/src/library/akuma-creation.js +90 -33
- package/build/src/library/audit.js +2 -1
- package/build/src/library/catalog.d.ts +10 -2
- package/build/src/library/catalog.js +65 -25
- package/build/src/library/composition.d.ts +1 -0
- package/build/src/library/composition.js +1 -0
- package/build/src/library/configuration.d.ts +4 -21
- package/build/src/library/configuration.js +2 -158
- package/build/src/library/continuation.d.ts +20 -1
- package/build/src/library/continuation.js +36 -0
- package/build/src/library/contract-bind.d.ts +1 -0
- package/build/src/library/contract-bind.js +16 -5
- package/build/src/library/contract-forwarding.d.ts +2 -2
- package/build/src/library/contract-forwarding.js +18 -4
- package/build/src/library/contract-handle.js +4 -3
- package/build/src/library/contract-operations.d.ts +5 -9
- package/build/src/library/contract-operations.js +34 -47
- package/build/src/library/contract.d.ts +11 -2
- package/build/src/library/contract.js +21 -1
- package/build/src/library/delivery.d.ts +4 -1
- package/build/src/library/delivery.js +47 -0
- package/build/src/library/fleet.d.ts +4 -136
- package/build/src/library/fleet.js +31 -315
- package/build/src/library/keiyaku.d.ts +7 -3
- package/build/src/library/keiyaku.js +1 -0
- package/build/src/library/mutation.d.ts +431 -3
- package/build/src/library/mutation.js +192 -19
- package/build/src/library/nuke.d.ts +7 -1
- package/build/src/library/nuke.js +18 -4
- package/build/src/library/reconcile.d.ts +14 -0
- package/build/src/library/reconcile.js +22 -8
- package/build/src/library/refusal.d.ts +9 -1
- package/build/src/library/refusal.js +76 -0
- package/build/src/library/region.d.ts +0 -8
- package/build/src/library/region.js +1 -29
- package/build/src/library/result-codec.d.ts +2 -0
- package/build/src/library/result-codec.js +12 -0
- package/build/src/markdown/lex.js +9 -2
- package/build/src/markdown/types.d.ts +2 -1
- package/build/src/markdown/types.js +3 -1
- package/build/src/plugin/akuma-signals.d.ts +12 -0
- package/build/src/plugin/akuma-signals.js +14 -0
- package/build/src/plugin/public.d.ts +51 -0
- package/build/src/plugin/public.js +1 -0
- package/build/src/plugin/runtime.d.ts +14 -0
- package/build/src/plugin/runtime.js +357 -0
- package/build/src/protocol/amend.js +3 -3
- package/build/src/protocol/attempt.d.ts +2 -1
- package/build/src/protocol/attempt.js +1 -1
- package/build/src/protocol/audit.d.ts +1 -1
- package/build/src/protocol/audit.js +1 -1
- package/build/src/protocol/bind.d.ts +3 -1
- package/build/src/protocol/bind.js +26 -0
- package/build/src/protocol/completion.js +0 -1
- package/build/src/protocol/deliver.d.ts +1 -1
- package/build/src/protocol/deliver.js +136 -57
- package/build/src/protocol/intent.d.ts +0 -1
- package/build/src/protocol/intent.js +0 -1
- package/build/src/protocol/operations.d.ts +9 -2
- package/build/src/protocol/operations.js +16 -1
- package/build/src/protocol/outcome.d.ts +3 -0
- package/build/src/protocol/outcome.js +17 -1
- package/build/src/protocol/placement.js +10 -3
- package/build/src/protocol/read/status.d.ts +8 -0
- package/build/src/protocol/read/status.js +49 -0
- package/build/src/protocol/reintegrate.js +10 -3
- package/build/src/protocol/result-codec.d.ts +22 -0
- package/build/src/protocol/result-codec.js +442 -0
- package/build/src/protocol/review.d.ts +1 -1
- package/build/src/protocol/review.js +81 -46
- package/build/src/protocol/run.d.ts +22 -2
- package/build/src/protocol/run.js +119 -29
- package/build/src/runtime/proc/lifecycle.js +1 -1
- package/build/src/runtime/proc/line-rpc.d.ts +7 -1
- package/build/src/runtime/proc/line-rpc.js +49 -9
- package/build/src/runtime/proc/run.d.ts +0 -1
- package/build/src/runtime/proc/run.js +1 -11
- package/build/src/runtime/proc/termination.d.ts +1 -0
- package/build/src/runtime/proc/termination.js +63 -18
- package/build/src/runtime/proc/windows-launch.exe +0 -0
- package/build/src/settings.d.ts +10 -0
- package/build/src/settings.js +88 -2
- package/build/src/settlement/result-codec.d.ts +2 -0
- package/build/src/settlement/result-codec.js +56 -0
- package/build/src/settlement/settle.d.ts +5 -12
- package/build/src/settlement/settle.js +60 -55
- package/build/src/task/board.d.ts +3 -0
- package/build/src/task/board.js +22 -4
- package/build/src/task/catalog.d.ts +13 -2
- package/build/src/task/catalog.js +59 -5
- package/build/src/task/compose.d.ts +4 -2
- package/build/src/task/compose.js +56 -30
- package/build/src/task/created-observation.d.ts +39 -0
- package/build/src/task/created-observation.js +26 -0
- package/build/src/task/identity.d.ts +6 -0
- package/build/src/task/identity.js +48 -7
- package/build/src/task/index.d.ts +4 -3
- package/build/src/task/index.js +19 -16
- package/build/src/task/input.d.ts +3 -1
- package/build/src/task/input.js +7 -4
- package/build/src/task/lifecycle-operations.d.ts +6 -0
- package/build/src/task/lifecycle-operations.js +116 -0
- package/build/src/task/mutation-result.d.ts +762 -20
- package/build/src/task/mutation-result.js +34 -9
- package/build/src/task/mutation.d.ts +4 -9
- package/build/src/task/mutation.js +17 -52
- package/build/src/task/operation-types.d.ts +114 -0
- package/build/src/task/operation-types.js +1 -0
- package/build/src/task/operations.d.ts +6 -113
- package/build/src/task/operations.js +75 -117
- package/build/src/task/query.d.ts +8 -11
- package/build/src/task/query.js +7 -14
- package/build/src/task/store.d.ts +11 -1
- package/build/src/task/store.js +169 -55
- package/build/src/task/view.d.ts +4 -0
- package/build/src/task/view.js +7 -0
- package/build/src/verification/declaration.d.ts +1 -0
- package/build/src/verification/declaration.js +18 -1
- package/build/src/verification/execution.d.ts +0 -1
- package/build/src/verification/execution.js +5 -5
- package/build/src/world.d.ts +0 -2
- package/build/src/world.js +3 -7
- package/package.json +17 -5
- package/build/src/cli/square-edge.d.ts +0 -7
- package/build/src/cli/square-edge.js +0 -159
- package/build/src/git/ref-migration.d.ts +0 -22
- package/build/src/git/ref-migration.js +0 -55
- package/build/src/library/contract-forwarding-reconciliation-result.d.ts +0 -102
- package/build/src/library/contract-forwarding-reconciliation-result.js +0 -92
- package/build/src/library/contract-forwarding-result.d.ts +0 -4270
- package/build/src/library/contract-forwarding-result.js +0 -521
|
@@ -1,43 +1,216 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { decodeJournalEntry } from "../core/facts/codec.js";
|
|
2
|
+
import { contractHead, snapshotId, } from "../core/facts/types.js";
|
|
3
|
+
import { decodePrivateStateSeatCloseLag, decodeWorktreeLeak } from "../git/result-codec.js";
|
|
4
|
+
import { concatenatePrivateStateSeatClose } from "../git/private-state-seat.js";
|
|
5
|
+
import { decodeVerificationCleanupFailure } from "../protocol/result-codec.js";
|
|
6
|
+
import { decodeSettlementLag } from "../settlement/result-codec.js";
|
|
7
|
+
import { completeReconcile, decodeReconciliationLag } from "./reconcile.js";
|
|
8
|
+
import { decodeAuditReport } from "../protocol/audit.js";
|
|
9
|
+
import { decodeMaterializedConflict } from "../protocol/deliver.js";
|
|
10
|
+
import { decodeReviewValue } from "../protocol/review.js";
|
|
11
|
+
import { decodeContinuationReport } from "./continuation.js";
|
|
12
|
+
import { deliveryValueSchema } from "./delivery.js";
|
|
13
|
+
import { ownerSchema } from "./result-codec.js";
|
|
14
|
+
import { z } from "zod";
|
|
15
|
+
function pendingSurface(surface, required) {
|
|
16
|
+
return { surface, required };
|
|
17
|
+
}
|
|
18
|
+
export function decodeMutationPendingSurface(value) {
|
|
19
|
+
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
20
|
+
throw new Error("malformed pending surface");
|
|
21
|
+
const object = value;
|
|
22
|
+
if (Object.keys(object).some((key) => key !== "surface" && key !== "required"))
|
|
23
|
+
throw new Error("malformed pending surface");
|
|
24
|
+
if (object.surface !== "verification" &&
|
|
25
|
+
object.surface !== "placement" &&
|
|
26
|
+
object.surface !== "continuation" &&
|
|
27
|
+
object.surface !== "reconciliation" &&
|
|
28
|
+
object.surface !== "settlement" &&
|
|
29
|
+
object.surface !== "cleanup")
|
|
30
|
+
throw new Error("malformed pending surface");
|
|
31
|
+
if (typeof object.required !== "boolean")
|
|
32
|
+
throw new Error("malformed pending surface");
|
|
33
|
+
return { surface: object.surface, required: object.required };
|
|
34
|
+
}
|
|
35
|
+
export const mutationPendingSurfaceSchema = ownerSchema(decodeMutationPendingSurface, "expected pending surface");
|
|
36
|
+
export function decodeReview(value) {
|
|
37
|
+
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
38
|
+
throw new Error("malformed review");
|
|
39
|
+
const { continuation, ...protocol } = value;
|
|
40
|
+
const review = decodeReviewValue(protocol);
|
|
41
|
+
return continuation === undefined ? review : { ...review, continuation: decodeContinuationReport(continuation) };
|
|
42
|
+
}
|
|
43
|
+
export const auditReportSchema = ownerSchema(decodeAuditReport, "expected audit report");
|
|
44
|
+
const reviewSchema = ownerSchema(decodeReview, "expected review");
|
|
45
|
+
const materializedConflictSchema = ownerSchema(decodeMaterializedConflict, "expected materialized conflict");
|
|
46
|
+
export const mutationResultSchema = (value) => ownerSchema((input) => {
|
|
47
|
+
if (input === null || typeof input !== "object" || Array.isArray(input))
|
|
48
|
+
throw new Error("malformed mutation result");
|
|
49
|
+
const object = input;
|
|
50
|
+
if (object.kind !== "accepted")
|
|
51
|
+
throw new Error("malformed mutation result");
|
|
52
|
+
if (typeof object.head !== "string")
|
|
53
|
+
throw new Error("malformed mutation result");
|
|
54
|
+
const parsedValue = value.safeParse(object.value);
|
|
55
|
+
if (!parsedValue.success)
|
|
56
|
+
throw new Error("malformed mutation result");
|
|
57
|
+
if (!Array.isArray(object.facts) ||
|
|
58
|
+
!Array.isArray(object.lags) ||
|
|
59
|
+
!Array.isArray(object.settlementLags) ||
|
|
60
|
+
!Array.isArray(object.pending))
|
|
61
|
+
throw new Error("malformed mutation result");
|
|
62
|
+
const allowed = new Set([
|
|
63
|
+
"kind",
|
|
64
|
+
"facts",
|
|
65
|
+
"head",
|
|
66
|
+
"value",
|
|
67
|
+
"lags",
|
|
68
|
+
"settlementLags",
|
|
69
|
+
"pending",
|
|
70
|
+
"recoverySnapshot",
|
|
71
|
+
"cleanup",
|
|
72
|
+
"leak",
|
|
73
|
+
"seatClose",
|
|
74
|
+
]);
|
|
75
|
+
for (const key of Object.keys(object))
|
|
76
|
+
if (!allowed.has(key))
|
|
77
|
+
throw new Error("malformed mutation result");
|
|
78
|
+
return {
|
|
79
|
+
kind: "accepted",
|
|
80
|
+
facts: object.facts.map(decodeJournalEntry),
|
|
81
|
+
head: contractHead(object.head),
|
|
82
|
+
value: parsedValue.data,
|
|
83
|
+
lags: object.lags.map(decodeReconciliationLag),
|
|
84
|
+
settlementLags: object.settlementLags.map(decodeSettlementLag),
|
|
85
|
+
pending: object.pending.map(decodeMutationPendingSurface),
|
|
86
|
+
...(object.recoverySnapshot === undefined
|
|
87
|
+
? {}
|
|
88
|
+
: { recoverySnapshot: snapshotId(String(object.recoverySnapshot)) }),
|
|
89
|
+
...(object.cleanup === undefined ? {} : { cleanup: decodeVerificationCleanupFailure(object.cleanup) }),
|
|
90
|
+
...(object.leak === undefined ? {} : { leak: decodeWorktreeLeak(object.leak) }),
|
|
91
|
+
...(object.seatClose === undefined
|
|
92
|
+
? {}
|
|
93
|
+
: {
|
|
94
|
+
seatClose: Array.isArray(object.seatClose)
|
|
95
|
+
? object.seatClose.map(decodePrivateStateSeatCloseLag)
|
|
96
|
+
: (() => {
|
|
97
|
+
throw new Error("malformed mutation result");
|
|
98
|
+
})(),
|
|
99
|
+
}),
|
|
100
|
+
};
|
|
101
|
+
}, "expected mutation result");
|
|
102
|
+
export const deliveryResultSchema = z.union([
|
|
103
|
+
mutationResultSchema(deliveryValueSchema),
|
|
104
|
+
materializedConflictSchema,
|
|
105
|
+
]);
|
|
106
|
+
export const reviewResultSchema = mutationResultSchema(reviewSchema);
|
|
107
|
+
export const auditResultSchema = mutationResultSchema(auditReportSchema);
|
|
108
|
+
export function noValuePending(_value) {
|
|
109
|
+
return [];
|
|
110
|
+
}
|
|
111
|
+
export function auditPending(value) {
|
|
112
|
+
return value.verification.kind === "stopped" ? [pendingSurface("verification", true)] : [];
|
|
113
|
+
}
|
|
114
|
+
export function completionPending(value) {
|
|
115
|
+
const pending = [];
|
|
116
|
+
if (value.verification !== undefined)
|
|
117
|
+
pending.push(pendingSurface("verification", true));
|
|
118
|
+
if (value.placement !== undefined)
|
|
119
|
+
pending.push(pendingSurface("placement", true));
|
|
120
|
+
if (value.continuation !== undefined && value.continuation.stopped.length > 0) {
|
|
121
|
+
pending.push(pendingSurface("continuation", true));
|
|
122
|
+
}
|
|
123
|
+
return pending;
|
|
124
|
+
}
|
|
125
|
+
export function obligationPending(input) {
|
|
126
|
+
const pending = [];
|
|
127
|
+
if (input.lags.length > 0)
|
|
128
|
+
pending.push(pendingSurface("reconciliation", true));
|
|
129
|
+
if (input.settlementLags.length > 0)
|
|
130
|
+
pending.push(pendingSurface("settlement", true));
|
|
131
|
+
if (input.cleanup !== undefined || input.leak !== undefined || (input.seatClose?.length ?? 0) > 0) {
|
|
132
|
+
pending.push(pendingSurface("cleanup", false));
|
|
133
|
+
}
|
|
134
|
+
return pending;
|
|
135
|
+
}
|
|
136
|
+
export function collectAcceptedPending(valuePending, obligations) {
|
|
137
|
+
return [...valuePending, ...obligationPending(obligations)];
|
|
138
|
+
}
|
|
139
|
+
function isRecord(value) {
|
|
140
|
+
return value !== null && typeof value === "object";
|
|
141
|
+
}
|
|
142
|
+
function phasePendingFromValue(value) {
|
|
143
|
+
if (!isRecord(value))
|
|
144
|
+
return [];
|
|
145
|
+
if ("candidate" in value && "verification" in value && "target" in value) {
|
|
146
|
+
return auditPending(value);
|
|
147
|
+
}
|
|
148
|
+
if ("verification" in value || "placement" in value || "continuation" in value) {
|
|
149
|
+
return completionPending(value);
|
|
150
|
+
}
|
|
151
|
+
return [];
|
|
152
|
+
}
|
|
153
|
+
function obligationSurfacesFromAccepted(input) {
|
|
154
|
+
return {
|
|
155
|
+
lags: input.lags,
|
|
156
|
+
settlementLags: input.settlementLags,
|
|
157
|
+
...(input.cleanup === undefined ? {} : { cleanup: input.cleanup }),
|
|
158
|
+
...(input.leak === undefined ? {} : { leak: input.leak }),
|
|
159
|
+
...(input.seatClose === undefined || input.seatClose.length === 0 ? {} : { seatClose: input.seatClose }),
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
/** Purely projects the leading mutation's finality without changing its details. */
|
|
163
|
+
export function projectMutationFinality(input) {
|
|
164
|
+
if (input.kind !== "accepted")
|
|
165
|
+
return { kind: "not-admitted" };
|
|
166
|
+
const pending = collectAcceptedPending(phasePendingFromValue(input.value), obligationSurfacesFromAccepted(input));
|
|
167
|
+
return pending.length === 0 ? { kind: "complete" } : { kind: "accepted-pending", pending };
|
|
168
|
+
}
|
|
169
|
+
export function completionInput(input) {
|
|
170
|
+
return { ...input, valuePending: input.valuePending ?? noValuePending };
|
|
171
|
+
}
|
|
172
|
+
function concatenateSettlementSeatClose(current, reports) {
|
|
173
|
+
return reports.reduce((seatClose, report) => concatenatePrivateStateSeatClose(seatClose, report.settlement.seatClose), current);
|
|
5
174
|
}
|
|
6
175
|
export async function completeMutation(input) {
|
|
7
176
|
const { scope, channel, contractId, accepted, value, hooks } = input;
|
|
177
|
+
const valuePending = input.valuePending ?? noValuePending;
|
|
8
178
|
const contracts = [...new Set([contractId, ...accepted.facts.map((fact) => fact.contract)])];
|
|
9
179
|
const reports = [];
|
|
10
180
|
for (const affected of contracts) {
|
|
11
181
|
reports.push(await completeReconcile({ scope, channel, contractId: affected, hooks, retryHooks: false }));
|
|
12
182
|
}
|
|
183
|
+
const seatClose = concatenateSettlementSeatClose(accepted.seatClose, reports);
|
|
13
184
|
const obligations = {
|
|
14
185
|
...(accepted.cleanup === undefined ? {} : { cleanup: accepted.cleanup }),
|
|
15
186
|
...(accepted.leak === undefined ? {} : { leak: accepted.leak }),
|
|
187
|
+
...(seatClose === undefined || seatClose.length === 0 ? {} : { seatClose }),
|
|
16
188
|
};
|
|
17
189
|
const effects = [...(accepted.physical?.effects ?? []), ...reports.flatMap((report) => report.effects)];
|
|
18
190
|
const recoverySnapshot = effects.findLast((effect) => effect.kind === "recovery-snapshot")?.snapshot;
|
|
191
|
+
const publicValue = value(accepted.value);
|
|
192
|
+
const lags = [...(accepted.physical?.lag ?? []), ...reports.flatMap((report) => report.lag)];
|
|
193
|
+
const settlementLags = reports.flatMap((report) => report.settlement.lags);
|
|
19
194
|
return {
|
|
195
|
+
kind: "accepted",
|
|
20
196
|
facts: accepted.facts,
|
|
21
197
|
head: accepted.head,
|
|
22
|
-
value:
|
|
23
|
-
lags
|
|
24
|
-
settlementLags
|
|
198
|
+
value: publicValue,
|
|
199
|
+
lags,
|
|
200
|
+
settlementLags,
|
|
201
|
+
pending: collectAcceptedPending(valuePending(publicValue), {
|
|
202
|
+
lags,
|
|
203
|
+
settlementLags,
|
|
204
|
+
...obligations,
|
|
205
|
+
}),
|
|
25
206
|
...(recoverySnapshot === undefined ? {} : { recoverySnapshot }),
|
|
26
207
|
...obligations,
|
|
27
208
|
};
|
|
28
209
|
}
|
|
29
210
|
export async function completeHolderMutation(input) {
|
|
30
211
|
const accepted = input.requireAccepted(input.admission.result);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
contractId: input.completion.contractId,
|
|
36
|
-
taskId: input.admission.taskId,
|
|
37
|
-
diagnostic: input.admission.diagnostic,
|
|
38
|
-
});
|
|
39
|
-
return {
|
|
40
|
-
...completed,
|
|
41
|
-
settlementLags: [...completed.settlementLags, ...deferred.lags],
|
|
42
|
-
};
|
|
212
|
+
// Fence teardown after confirmed admission is custodial residue. Settlement in
|
|
213
|
+
// completeMutation already reports any still-owed holder publication; do not
|
|
214
|
+
// invent a second owed-holder lag from fence close alone.
|
|
215
|
+
return await completeMutation({ ...input.completion, accepted });
|
|
43
216
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { type PrivateStateSeatCloseLag } from "../git/private-state-seat.js";
|
|
2
|
+
import type { GitRepository } from "../git/process.js";
|
|
1
3
|
import { type WorldRoot } from "../world.js";
|
|
2
4
|
export type NukeInput = Readonly<{
|
|
3
5
|
world: WorldRoot;
|
|
@@ -6,9 +8,13 @@ export type NukeInput = Readonly<{
|
|
|
6
8
|
export type NukeResult = Readonly<{
|
|
7
9
|
kind: "success";
|
|
8
10
|
world: WorldRoot;
|
|
11
|
+
seatClose?: readonly PrivateStateSeatCloseLag[];
|
|
9
12
|
}> | Readonly<{
|
|
10
13
|
kind: "failed";
|
|
11
14
|
world: WorldRoot;
|
|
12
15
|
diagnostic: string;
|
|
16
|
+
seatClose?: readonly PrivateStateSeatCloseLag[];
|
|
13
17
|
}>;
|
|
14
|
-
|
|
18
|
+
type NukeGitOptions = Readonly<Pick<GitRepository, "onPrivateStateSeatContention" | "onPrivateStateSeatClose">>;
|
|
19
|
+
export declare function nukeKeiyaku(input: NukeInput, gitOptions?: NukeGitOptions): Promise<NukeResult>;
|
|
20
|
+
export {};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
/** @architectureCompositionRoot */
|
|
1
2
|
import { rmdir } from "node:fs/promises";
|
|
2
3
|
import { resolve } from "node:path";
|
|
3
4
|
import { stopAkuma } from "../akuma/nuke.js";
|
|
4
5
|
import { nukeGit } from "../git/nuke.js";
|
|
6
|
+
import { appendPrivateStateSeatClose } from "../git/private-state-seat.js";
|
|
5
7
|
import { nukeTask } from "../task/operations.js";
|
|
6
8
|
import { World } from "../world.js";
|
|
7
9
|
import { KeiyakuRefused } from "./refusal.js";
|
|
@@ -25,7 +27,10 @@ async function nukeInput(input) {
|
|
|
25
27
|
const confirm = value.confirm === undefined ? undefined : requireMarkdown(value.confirm, "confirm");
|
|
26
28
|
return { world, ...(confirm === undefined ? {} : { confirm }) };
|
|
27
29
|
}
|
|
28
|
-
|
|
30
|
+
function withSeatClose(result, seatClose) {
|
|
31
|
+
return seatClose === undefined || seatClose.length === 0 ? result : { ...result, seatClose };
|
|
32
|
+
}
|
|
33
|
+
export async function nukeKeiyaku(input, gitOptions) {
|
|
29
34
|
const value = await nukeInput(input);
|
|
30
35
|
if (value.confirm === undefined) {
|
|
31
36
|
throw new KeiyakuRefused({ kind: "nuke-confirmation-required", world: value.world });
|
|
@@ -37,6 +42,7 @@ export async function nukeKeiyaku(input) {
|
|
|
37
42
|
confirmation: value.confirm,
|
|
38
43
|
});
|
|
39
44
|
}
|
|
45
|
+
let seatClose;
|
|
40
46
|
try {
|
|
41
47
|
const deleteAkuma = await stopAkuma(value.world);
|
|
42
48
|
let failed = false;
|
|
@@ -52,13 +58,21 @@ export async function nukeKeiyaku(input) {
|
|
|
52
58
|
}
|
|
53
59
|
}
|
|
54
60
|
};
|
|
55
|
-
await Promise.all([
|
|
61
|
+
await Promise.all([
|
|
62
|
+
attempt(deleteAkuma()),
|
|
63
|
+
attempt(nukeGit(value.world, "git", gitOptions).then((outcome) => {
|
|
64
|
+
if (outcome.closeLag !== undefined) {
|
|
65
|
+
seatClose = appendPrivateStateSeatClose(seatClose, outcome.closeLag);
|
|
66
|
+
}
|
|
67
|
+
})),
|
|
68
|
+
attempt(nukeTask(value.world)),
|
|
69
|
+
]);
|
|
56
70
|
if (failed)
|
|
57
71
|
throw firstDiagnostic;
|
|
58
72
|
await removeEmptyWorldMarker(value.world);
|
|
59
|
-
return { kind: "success", world: value.world };
|
|
73
|
+
return withSeatClose({ kind: "success", world: value.world }, seatClose);
|
|
60
74
|
}
|
|
61
75
|
catch (error) {
|
|
62
|
-
return { kind: "failed", world: value.world, diagnostic: diagnostic(error) };
|
|
76
|
+
return withSeatClose({ kind: "failed", world: value.world, diagnostic: diagnostic(error) }, seatClose);
|
|
63
77
|
}
|
|
64
78
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/** @architectureCompositionRoot */
|
|
1
2
|
import type { ContractId } from "../core/facts/types.js";
|
|
2
3
|
import type { GitDecodeChannel } from "../git/read-observation.js";
|
|
3
4
|
import { type ReconcileReport } from "../protocol/reconcile.js";
|
|
@@ -5,6 +6,7 @@ import { type RepositoryScope } from "../protocol/operations.js";
|
|
|
5
6
|
import { type SettlementReport } from "../settlement/settle.js";
|
|
6
7
|
import type { WorktreeHooks } from "./configuration.js";
|
|
7
8
|
import { type ContractFileEffect, type ContractFileLag } from "../contract-worktree.js";
|
|
9
|
+
import { z } from "zod";
|
|
8
10
|
export type ReconcileCompletion = Readonly<{
|
|
9
11
|
effects: readonly (ReconcileReport["effects"][number] | ContractFileEffect)[];
|
|
10
12
|
lag: readonly (ReconcileReport["lag"][number] | ContractFileLag)[];
|
|
@@ -14,6 +16,18 @@ export type ReconcileCompletion = Readonly<{
|
|
|
14
16
|
name: string;
|
|
15
17
|
}[];
|
|
16
18
|
}>;
|
|
19
|
+
export declare function decodeReconciliationLag(value: unknown): ReconcileCompletion["lag"][number];
|
|
20
|
+
export declare const reconciliationLagSchema: z.ZodType<import("../git/reconcile.js").ReconcileLag | Readonly<{
|
|
21
|
+
kind: "contract-file-failed";
|
|
22
|
+
worktree: string;
|
|
23
|
+
path: string;
|
|
24
|
+
diagnostic: string;
|
|
25
|
+
}>, unknown, z.core.$ZodTypeInternals<import("../git/reconcile.js").ReconcileLag | Readonly<{
|
|
26
|
+
kind: "contract-file-failed";
|
|
27
|
+
worktree: string;
|
|
28
|
+
path: string;
|
|
29
|
+
diagnostic: string;
|
|
30
|
+
}>, unknown>>;
|
|
17
31
|
export type RepoContractReconcileReport = ReconcileCompletion;
|
|
18
32
|
type RepoReconcileContracts = readonly Readonly<{
|
|
19
33
|
contractId: ContractId;
|
|
@@ -4,8 +4,19 @@ import { reconcileObservationFailure } from "../git/reconcile.js";
|
|
|
4
4
|
import { worktreePath } from "../git/workspace.js";
|
|
5
5
|
import { stateOperation } from "../protocol/operations.js";
|
|
6
6
|
import { settle, settleAll } from "../settlement/settle.js";
|
|
7
|
-
import { projectContractWorktree } from "../contract-worktree.js";
|
|
7
|
+
import { decodeContractFileLag, projectContractWorktree, } from "../contract-worktree.js";
|
|
8
|
+
import { decodeGitReconcileLag } from "../git/result-codec.js";
|
|
9
|
+
import { ownerSchema } from "./result-codec.js";
|
|
8
10
|
import { appointManagedWorktrees, placeRegisterPath, releaseManagedWorktrees, } from "../workspace-place.js";
|
|
11
|
+
export function decodeReconciliationLag(value) {
|
|
12
|
+
try {
|
|
13
|
+
return decodeGitReconcileLag(value);
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return decodeContractFileLag(value);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export const reconciliationLagSchema = ownerSchema(decodeReconciliationLag, "expected reconciliation lag");
|
|
9
20
|
function registerLag(scope, error) {
|
|
10
21
|
return {
|
|
11
22
|
kind: "contract-file-failed",
|
|
@@ -169,6 +180,12 @@ export async function completeRepoReconcile(input) {
|
|
|
169
180
|
retainTerminalWorktree: true,
|
|
170
181
|
places,
|
|
171
182
|
});
|
|
183
|
+
const projections = [];
|
|
184
|
+
for (const contract of retained.contracts) {
|
|
185
|
+
projections.push(realizedOrRetainedManagedWorktree(input.scope, contract.report, places.get(contract.contractId))
|
|
186
|
+
? await projectContractWorktree(input.scope, contract.state, appointed)
|
|
187
|
+
: { effects: [], lag: [] });
|
|
188
|
+
}
|
|
172
189
|
const settlements = await settleAll({
|
|
173
190
|
repository: input.scope,
|
|
174
191
|
channel: input.channel,
|
|
@@ -181,16 +198,13 @@ export async function completeRepoReconcile(input) {
|
|
|
181
198
|
? await reconcileAllOperation({ ...input, states, places })
|
|
182
199
|
: null;
|
|
183
200
|
const later = cleanup === null ? null : new Map(cleanup.contracts.map((contract) => [contract.contractId, contract.report]));
|
|
184
|
-
const released =
|
|
201
|
+
const released = retained.contracts
|
|
202
|
+
.filter((contract) => releaseEligible(contract.state, later?.get(contract.contractId), places.has(contract.contractId)))
|
|
203
|
+
.map((contract) => contract.contractId);
|
|
185
204
|
const contracts = [];
|
|
186
205
|
for (const [index, contract] of retained.contracts.entries()) {
|
|
187
206
|
const report = later?.get(contract.contractId);
|
|
188
|
-
|
|
189
|
-
released.push(contract.contractId);
|
|
190
|
-
}
|
|
191
|
-
const projection = realizedOrRetainedManagedWorktree(input.scope, contract.report, places.get(contract.contractId))
|
|
192
|
-
? await projectContractWorktree(input.scope, contract.state, appointed)
|
|
193
|
-
: { effects: [], lag: [] };
|
|
207
|
+
const projection = projections[index];
|
|
194
208
|
contracts.push({
|
|
195
209
|
contractId: contract.contractId,
|
|
196
210
|
report: {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ContractId } from "../core/facts/types.js";
|
|
2
2
|
import type { IntentOutcome, IntentRefusal, IntentRetry } from "../protocol/operations.js";
|
|
3
3
|
import type { AcceptedIntent } from "./mutation.js";
|
|
4
|
+
import { z } from "zod";
|
|
4
5
|
export type ForkSourceRefusal = Readonly<{
|
|
5
6
|
kind: "fork-source-missing" | "fork-source-unavailable" | "fork-source-invalid" | "fork-source-moved";
|
|
6
7
|
contractId: ContractId;
|
|
@@ -16,14 +17,21 @@ export type NukeConfirmationRequiredRefusal = Readonly<{
|
|
|
16
17
|
}>;
|
|
17
18
|
export type KeiyakuRefusal = IntentRefusal | ForkSourceRefusal | NukeConfirmationRefusal | NukeConfirmationRequiredRefusal;
|
|
18
19
|
export type KeiyakuRetryReason = IntentRetry;
|
|
20
|
+
export declare function decodeKeiyakuRefusal(value: unknown): KeiyakuRefusal;
|
|
21
|
+
export declare const keiyakuRefusalSchema: z.ZodType<KeiyakuRefusal, unknown, z.core.$ZodTypeInternals<KeiyakuRefusal, unknown>>;
|
|
22
|
+
export declare const keiyakuRetryReasonSchema: z.ZodType<import("../protocol/run.js").ProtocolTerminal, unknown, z.core.$ZodTypeInternals<import("../protocol/run.js").ProtocolTerminal, unknown>>;
|
|
19
23
|
export declare class KeiyakuRefused extends Error {
|
|
20
24
|
readonly refusal: KeiyakuRefusal;
|
|
25
|
+
readonly kind: "refused";
|
|
21
26
|
constructor(refusal: KeiyakuRefusal);
|
|
22
27
|
get code(): KeiyakuRefusal["kind"];
|
|
23
28
|
}
|
|
24
29
|
export declare class KeiyakuRetry extends Error {
|
|
25
30
|
readonly reason: KeiyakuRetryReason;
|
|
31
|
+
readonly kind: "retry";
|
|
26
32
|
constructor(reason: KeiyakuRetryReason);
|
|
27
33
|
get code(): KeiyakuRetryReason["kind"];
|
|
28
34
|
}
|
|
35
|
+
export declare function encodeContractLiveFailure(error: unknown): unknown | null;
|
|
36
|
+
export declare function decodeContractLiveFailure(value: unknown): Error | null;
|
|
29
37
|
export declare function requireAccepted<Value, Refusal extends KeiyakuRefusal>(result: IntentOutcome<Value, Refusal>): AcceptedIntent<Value>;
|
|
@@ -1,5 +1,59 @@
|
|
|
1
|
+
import { contractId } from "../core/facts/types.js";
|
|
2
|
+
import { decodeIntentRefusal, decodeProtocolTerminal } from "../protocol/result-codec.js";
|
|
3
|
+
import { ownerSchema } from "./result-codec.js";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
function decodeForkSourceRefusal(value) {
|
|
6
|
+
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
7
|
+
throw new Error("malformed fork-source refusal");
|
|
8
|
+
const object = value;
|
|
9
|
+
if (Object.keys(object).some((key) => key !== "kind" && key !== "contractId"))
|
|
10
|
+
throw new Error("malformed fork-source refusal");
|
|
11
|
+
if (object.kind !== "fork-source-missing" &&
|
|
12
|
+
object.kind !== "fork-source-unavailable" &&
|
|
13
|
+
object.kind !== "fork-source-invalid" &&
|
|
14
|
+
object.kind !== "fork-source-moved")
|
|
15
|
+
throw new Error("malformed fork-source refusal");
|
|
16
|
+
if (typeof object.contractId !== "string")
|
|
17
|
+
throw new Error("malformed fork-source refusal");
|
|
18
|
+
return { kind: object.kind, contractId: contractId(object.contractId) };
|
|
19
|
+
}
|
|
20
|
+
function decodeNukeRefusal(value) {
|
|
21
|
+
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
22
|
+
throw new Error("malformed nuke refusal");
|
|
23
|
+
const object = value;
|
|
24
|
+
if (object.kind === "nuke-confirmation-required") {
|
|
25
|
+
if (Object.keys(object).some((key) => key !== "kind" && key !== "world"))
|
|
26
|
+
throw new Error("malformed nuke refusal");
|
|
27
|
+
if (typeof object.world !== "string" || object.world.trim() === "")
|
|
28
|
+
throw new Error("malformed nuke refusal");
|
|
29
|
+
return { kind: "nuke-confirmation-required", world: object.world };
|
|
30
|
+
}
|
|
31
|
+
if (object.kind !== "nuke-confirmation-mismatch")
|
|
32
|
+
throw new Error("malformed nuke refusal");
|
|
33
|
+
if (Object.keys(object).some((key) => key !== "kind" && key !== "world" && key !== "confirmation"))
|
|
34
|
+
throw new Error("malformed nuke refusal");
|
|
35
|
+
if (typeof object.world !== "string" || object.world.trim() === "" || typeof object.confirmation !== "string")
|
|
36
|
+
throw new Error("malformed nuke refusal");
|
|
37
|
+
return { kind: "nuke-confirmation-mismatch", world: object.world, confirmation: object.confirmation };
|
|
38
|
+
}
|
|
39
|
+
export function decodeKeiyakuRefusal(value) {
|
|
40
|
+
try {
|
|
41
|
+
return decodeIntentRefusal(value);
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
try {
|
|
45
|
+
return decodeForkSourceRefusal(value);
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return decodeNukeRefusal(value);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
export const keiyakuRefusalSchema = ownerSchema(decodeKeiyakuRefusal, "expected keiyaku refusal");
|
|
53
|
+
export const keiyakuRetryReasonSchema = ownerSchema(decodeProtocolTerminal, "expected keiyaku retry");
|
|
1
54
|
export class KeiyakuRefused extends Error {
|
|
2
55
|
refusal;
|
|
56
|
+
kind = "refused";
|
|
3
57
|
constructor(refusal) {
|
|
4
58
|
super(`Keiyaku refused: ${refusal.kind}`);
|
|
5
59
|
this.refusal = refusal;
|
|
@@ -11,6 +65,7 @@ export class KeiyakuRefused extends Error {
|
|
|
11
65
|
}
|
|
12
66
|
export class KeiyakuRetry extends Error {
|
|
13
67
|
reason;
|
|
68
|
+
kind = "retry";
|
|
14
69
|
constructor(reason) {
|
|
15
70
|
super(reason.kind === "publication-failed" ? reason.diagnostic : `Keiyaku retry required: ${reason.kind}`);
|
|
16
71
|
this.reason = reason;
|
|
@@ -20,6 +75,27 @@ export class KeiyakuRetry extends Error {
|
|
|
20
75
|
return this.reason.kind;
|
|
21
76
|
}
|
|
22
77
|
}
|
|
78
|
+
const contractLiveFailureSchema = z.union([
|
|
79
|
+
z.object({ kind: z.literal("refused"), refusal: keiyakuRefusalSchema }).strict(),
|
|
80
|
+
z.object({ kind: z.literal("retry"), reason: keiyakuRetryReasonSchema }).strict(),
|
|
81
|
+
]);
|
|
82
|
+
export function encodeContractLiveFailure(error) {
|
|
83
|
+
if (error instanceof KeiyakuRefused) {
|
|
84
|
+
return { kind: "refused", refusal: error.refusal };
|
|
85
|
+
}
|
|
86
|
+
if (error instanceof KeiyakuRetry) {
|
|
87
|
+
return { kind: "retry", reason: error.reason };
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
export function decodeContractLiveFailure(value) {
|
|
92
|
+
const parsed = contractLiveFailureSchema.safeParse(value);
|
|
93
|
+
if (!parsed.success)
|
|
94
|
+
return null;
|
|
95
|
+
return parsed.data.kind === "refused"
|
|
96
|
+
? new KeiyakuRefused(decodeKeiyakuRefusal(parsed.data.refusal))
|
|
97
|
+
: new KeiyakuRetry(parsed.data.reason);
|
|
98
|
+
}
|
|
23
99
|
export function requireAccepted(result) {
|
|
24
100
|
if (result.kind === "refused")
|
|
25
101
|
throw new KeiyakuRefused(result.refusal);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { ContractId } from "../core/facts/types.js";
|
|
2
2
|
import { type GitDecodeChannel } from "../git/read-observation.js";
|
|
3
3
|
import { type RepositoryScope } from "../protocol/operations.js";
|
|
4
|
-
import type { ContractDocumentProjection } from "../protocol/read/documents.js";
|
|
5
4
|
export type RegionOverlap = Readonly<{
|
|
6
5
|
contract: ContractId;
|
|
7
6
|
patterns: readonly Readonly<{
|
|
@@ -20,12 +19,5 @@ export type AmendRegionObservation = RegionObservation | Readonly<{
|
|
|
20
19
|
overlaps?: never;
|
|
21
20
|
overlapFailure?: never;
|
|
22
21
|
}>;
|
|
23
|
-
export type RegionDeclarationRead = Readonly<{
|
|
24
|
-
contract: ContractId;
|
|
25
|
-
patterns: readonly string[];
|
|
26
|
-
}>;
|
|
27
|
-
export declare function readRegionDeclarations(documents: readonly ContractDocumentProjection[]): readonly RegionDeclarationRead[];
|
|
28
|
-
export declare function regionOverlaps(mine: readonly string[], declarations: readonly RegionDeclarationRead[]): readonly RegionOverlap[];
|
|
29
|
-
export declare function validateRegionPatterns(patterns: unknown): readonly [string, ...string[]];
|
|
30
22
|
export declare function observeRegion(scope: RepositoryScope, channel: GitDecodeChannel, self: ContractId, mine: readonly string[]): Promise<RegionObservation>;
|
|
31
23
|
export declare function observeChangedRegion(scope: RepositoryScope, self: ContractId, changed: ReadonlySet<string> | undefined, mine: readonly string[]): Promise<AmendRegionObservation>;
|
|
@@ -1,35 +1,7 @@
|
|
|
1
1
|
import { decodeContractDocument } from "../body/decode.js";
|
|
2
|
-
import {
|
|
2
|
+
import { regionsOverlap } from "../body/region.js";
|
|
3
3
|
import { withGitDecodeChannel } from "../git/read-observation.js";
|
|
4
4
|
import { documentsOperationAt } from "../protocol/operations.js";
|
|
5
|
-
export function readRegionDeclarations(documents) {
|
|
6
|
-
return documents.map((document) => ({
|
|
7
|
-
contract: document.contract,
|
|
8
|
-
patterns: decodeContractDocument(document.documentBytes).region,
|
|
9
|
-
}));
|
|
10
|
-
}
|
|
11
|
-
export function regionOverlaps(mine, declarations) {
|
|
12
|
-
const overlaps = [];
|
|
13
|
-
for (const declaration of declarations) {
|
|
14
|
-
const pairs = regionsOverlap(mine, declaration.patterns);
|
|
15
|
-
if (pairs.length === 0)
|
|
16
|
-
continue;
|
|
17
|
-
overlaps.push({
|
|
18
|
-
contract: declaration.contract,
|
|
19
|
-
patterns: pairs.map(([minePattern, theirsPattern]) => ({ mine: minePattern, theirs: theirsPattern })),
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
return overlaps;
|
|
23
|
-
}
|
|
24
|
-
export function validateRegionPatterns(patterns) {
|
|
25
|
-
if (!Array.isArray(patterns) || patterns.length === 0)
|
|
26
|
-
throw new Error("Region query requires one or more path patterns");
|
|
27
|
-
return patterns.map((pattern) => {
|
|
28
|
-
if (typeof pattern !== "string")
|
|
29
|
-
throw new Error("Region path patterns must be strings");
|
|
30
|
-
return assertRegionPattern(pattern);
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
5
|
function diagnostic(error) {
|
|
34
6
|
return error instanceof Error ? error.message : String(error);
|
|
35
7
|
}
|
|
@@ -131,10 +131,17 @@ function frontmatterValue(value) {
|
|
|
131
131
|
}
|
|
132
132
|
throw new MarkdownParseError("unsupported frontmatter value");
|
|
133
133
|
}
|
|
134
|
+
function parserDiagnostics(errors) {
|
|
135
|
+
return [...errors]
|
|
136
|
+
.sort((left, right) => left.pos[0] - right.pos[0] || left.pos[1] - right.pos[1])
|
|
137
|
+
.map((error) => error.message);
|
|
138
|
+
}
|
|
134
139
|
function parseFrontmatter(source) {
|
|
135
140
|
const parsed = parseDocument(source, { merge: false, prettyErrors: false, strict: true, uniqueKeys: true });
|
|
136
|
-
if (parsed.errors.length > 0)
|
|
137
|
-
|
|
141
|
+
if (parsed.errors.length > 0) {
|
|
142
|
+
const diagnostics = parserDiagnostics(parsed.errors);
|
|
143
|
+
throw new MarkdownParseError(diagnostics.join("\n"), diagnostics);
|
|
144
|
+
}
|
|
138
145
|
validateFrontmatterNode(parsed.contents);
|
|
139
146
|
if (!isMap(parsed.contents))
|
|
140
147
|
throw new MarkdownParseError("frontmatter must be a mapping");
|
|
@@ -113,6 +113,7 @@ export type HeadingNode = Spanned & Readonly<{
|
|
|
113
113
|
export type MarkdownBlockNode = SectionNode | ListNode | CodeBlockNode | BlockquoteNode | TextNode | HeadingNode;
|
|
114
114
|
export type MarkdownNode = DocumentNode | MarkdownBlockNode | ListItemNode;
|
|
115
115
|
export declare class MarkdownParseError extends Error {
|
|
116
|
-
|
|
116
|
+
readonly diagnostics: readonly string[];
|
|
117
|
+
constructor(message: string, diagnostics?: readonly string[]);
|
|
117
118
|
}
|
|
118
119
|
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Settings } from "../settings.js";
|
|
2
|
+
import type { WorldRoot } from "../world.js";
|
|
3
|
+
type CalledPluginSignalInput = Readonly<{
|
|
4
|
+
world: WorldRoot;
|
|
5
|
+
settings?: Settings;
|
|
6
|
+
reportDiagnostic: (message: string) => void;
|
|
7
|
+
akumaId: string;
|
|
8
|
+
callerAkumaId?: string;
|
|
9
|
+
contractId?: string;
|
|
10
|
+
}>;
|
|
11
|
+
export declare function emitCalledPluginSignal(input: CalledPluginSignalInput): Promise<void>;
|
|
12
|
+
export {};
|