@astrosheep/keiyaku 4.5.7 → 4.5.8
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 +10 -0
- package/build/integrations/marketplace/plugins/keiyaku/.claude-plugin/plugin.json +1 -1
- package/build/integrations/marketplace/plugins/keiyaku/.codex-plugin/plugin.json +1 -1
- package/build/integrations/marketplace/plugins/keiyaku/opencode.js +3 -2
- package/build/integrations/marketplace/plugins/keiyaku/package.json +1 -1
- package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku/SKILL.md +10 -9
- package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-akuma/SKILL.md +22 -1
- package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-babysit/SKILL.md +35 -96
- package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-bind/SKILL.md +28 -49
- package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-task/SKILL.md +21 -15
- package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-workflow/SKILL.md +148 -89
- package/build/src/akuma/abort.d.ts +2 -1
- package/build/src/akuma/abort.js +6 -23
- package/build/src/akuma/akuma-handle.js +4 -2
- package/build/src/akuma/akuma-observe.d.ts +2 -0
- package/build/src/akuma/akuma-observe.js +1 -0
- package/build/src/akuma/akuma-product.js +9 -7
- package/build/src/akuma/akuma.d.ts +372 -9
- package/build/src/akuma/akuma.js +31 -1
- package/build/src/akuma/allowed.d.ts +1 -1
- package/build/src/akuma/allowed.js +1 -0
- package/build/src/akuma/body.d.ts +6 -4
- package/build/src/akuma/body.js +5 -3
- package/build/src/akuma/call-request.d.ts +80 -0
- package/build/src/akuma/call-request.js +211 -0
- package/build/src/akuma/heart/facts.d.ts +6 -78
- package/build/src/akuma/heart/index.d.ts +1 -1
- package/build/src/akuma/heart/request-authority.d.ts +5 -4
- package/build/src/akuma/heart/request-authority.js +20 -34
- package/build/src/akuma/heart/request-rows.js +12 -23
- package/build/src/akuma/heart/schema.d.ts +1 -1
- package/build/src/akuma/heart/schema.js +5 -13
- package/build/src/akuma/index.d.ts +1 -1
- package/build/src/akuma/index.js +1 -1
- package/build/src/akuma/projection-read.d.ts +1 -0
- package/build/src/akuma/projection-read.js +8 -1
- package/build/src/akuma/projection.d.ts +856 -137
- package/build/src/akuma/projection.js +190 -0
- package/build/src/akuma/provider.d.ts +30 -3
- package/build/src/akuma/provider.js +104 -0
- package/build/src/akuma/providers/acp/core.d.ts +2 -2
- package/build/src/akuma/providers/acp/core.js +13 -6
- package/build/src/akuma/providers/acp/index.js +5 -4
- package/build/src/akuma/providers/claude/index.d.ts +3 -3
- package/build/src/akuma/providers/claude/index.js +16 -5
- package/build/src/akuma/providers/codex-app-server/events.js +1 -1
- package/build/src/akuma/providers/codex-app-server/index.js +18 -6
- package/build/src/akuma/providers/grok-build/index.js +5 -4
- package/build/src/akuma/providers/opencode-sdk/index.js +66 -25
- package/build/src/akuma/providers/opencode-sdk/session.d.ts +3 -2
- package/build/src/akuma/providers/opencode-sdk/session.js +28 -11
- package/build/src/akuma/providers/pi/index.js +42 -14
- package/build/src/akuma/request-lifecycle.d.ts +3 -9
- package/build/src/akuma/request-lifecycle.js +4 -4
- package/build/src/akuma/request-rendezvous.d.ts +26 -0
- package/build/src/akuma/request-rendezvous.js +100 -0
- package/build/src/akuma/request-serve.d.ts +5 -65
- package/build/src/akuma/request-serve.js +81 -208
- package/build/src/akuma/request-wire.d.ts +109 -115
- package/build/src/akuma/request-wire.js +63 -318
- package/build/src/akuma/requests.d.ts +19 -47
- package/build/src/akuma/requests.js +51 -107
- package/build/src/akuma/turn-drive.d.ts +5 -3
- package/build/src/akuma/turn-drive.js +32 -10
- package/build/src/akuma-body.d.ts +7 -2
- package/build/src/akuma-body.js +68 -46
- package/build/src/cli/accepted.d.ts +1 -1
- package/build/src/cli/accepted.js +2 -2
- package/build/src/cli/commands/akuma-invoke.d.ts +2 -0
- package/build/src/cli/commands/akuma-invoke.js +17 -9
- package/build/src/cli/commands/akuma.js +7 -7
- package/build/src/cli/commands/contract-invoke.d.ts +3 -2
- package/build/src/cli/commands/contract-invoke.js +26 -19
- package/build/src/cli/commands/contract.d.ts +13 -13
- package/build/src/cli/commands/contract.js +32 -17
- package/build/src/cli/commands/install.d.ts +1 -1
- package/build/src/cli/commands/install.js +1 -1
- package/build/src/cli/commands/task-invoke.d.ts +3 -0
- package/build/src/cli/commands/task-invoke.js +23 -140
- package/build/src/cli/commands/task.js +54 -20
- package/build/src/cli/invoke.js +39 -25
- package/build/src/cli/main.js +2 -1
- package/build/src/cli/parse.d.ts +2 -2
- package/build/src/cli/parse.js +37 -22
- package/build/src/cli/render/akuma-activity.d.ts +4 -1
- package/build/src/cli/render/akuma-activity.js +45 -30
- package/build/src/cli/render/akuma-tool.d.ts +5 -1
- package/build/src/cli/render/akuma.js +5 -9
- package/build/src/cli/render/audit.js +1 -1
- package/build/src/cli/render/catalog.js +80 -21
- package/build/src/cli/render/contract-observation.d.ts +2 -0
- package/build/src/cli/render/contract-observation.js +11 -0
- package/build/src/cli/render/contract.js +25 -65
- package/build/src/cli/render/kanshi-akuma.d.ts +8 -0
- package/build/src/cli/render/kanshi-akuma.js +111 -0
- package/build/src/cli/render/kanshi.js +108 -213
- package/build/src/cli/render/receipt.d.ts +1 -2
- package/build/src/cli/render/receipt.js +76 -26
- package/build/src/cli/render/refusal.js +2 -10
- package/build/src/cli/render/region.js +5 -2
- package/build/src/cli/render/settings.d.ts +1 -1
- package/build/src/cli/render/settings.js +27 -8
- package/build/src/cli/render/task.js +22 -5
- package/build/src/cli/render/terminal.d.ts +28 -0
- package/build/src/cli/render/terminal.js +65 -0
- package/build/src/cli/result.d.ts +3 -3
- package/build/src/cli/runtime.js +3 -1
- package/build/src/cli/selectors.d.ts +2 -1
- package/build/src/cli/selectors.js +4 -3
- package/build/src/cli/square-edge.js +120 -36
- package/build/src/cli/usage.js +2 -1
- package/build/src/contract-guidance.d.ts +5 -0
- package/build/src/contract-guidance.js +121 -0
- package/build/src/contract-worktree.d.ts +0 -1
- package/build/src/contract-worktree.js +32 -83
- package/build/src/coordination/sqlite-transaction-lock.d.ts +1 -0
- package/build/src/coordination/sqlite-transaction-lock.js +5 -0
- package/build/src/core/facts/codec.d.ts +2 -0
- package/build/src/core/facts/codec.js +4 -0
- package/build/src/core/verbs/placement.d.ts +6 -1
- package/build/src/core/verbs/placement.js +5 -3
- package/build/src/dispatch/index.d.ts +0 -2
- package/build/src/dispatch/index.js +54 -55
- package/build/src/git/admission.js +2 -2
- package/build/src/git/hooks.d.ts +9 -15
- package/build/src/git/hooks.js +23 -317
- package/build/src/git/nuke.d.ts +2 -1
- package/build/src/git/nuke.js +36 -18
- package/build/src/git/private-state-seat.d.ts +12 -0
- package/build/src/git/private-state-seat.js +39 -0
- package/build/src/git/process.d.ts +6 -0
- package/build/src/git/process.js +19 -7
- package/build/src/git/read-observation.js +29 -20
- package/build/src/git/reconcile.d.ts +11 -0
- package/build/src/git/reconcile.js +64 -11
- package/build/src/git/repository.d.ts +6 -2
- package/build/src/git/repository.js +8 -0
- package/build/src/git/target-placement.d.ts +1 -0
- package/build/src/git/target-placement.js +5 -0
- package/build/src/git/tender.d.ts +1 -0
- package/build/src/git/terminal-reconcile.d.ts +1 -1
- package/build/src/git/terminal-reconcile.js +22 -20
- package/build/src/git/workspace.d.ts +14 -0
- package/build/src/git/workspace.js +44 -0
- package/build/src/kanshi/index.d.ts +1 -1
- package/build/src/kanshi/read.js +16 -16
- package/build/src/kanshi/report.d.ts +2 -2
- package/build/src/library/address.d.ts +9 -3
- package/build/src/library/address.js +3 -2
- package/build/src/library/akuma-creation.d.ts +4 -3
- package/build/src/library/akuma-creation.js +19 -13
- package/build/src/library/audit.d.ts +1 -1
- package/build/src/library/audit.js +5 -3
- package/build/src/library/catalog.d.ts +3 -1
- package/build/src/library/catalog.js +20 -6
- package/build/src/library/composition.d.ts +371 -0
- package/build/src/library/composition.js +28 -0
- package/build/src/library/configuration.js +8 -2
- package/build/src/library/continuation.js +66 -30
- package/build/src/library/contract-bind.js +10 -2
- package/build/src/library/contract-forwarding-reconciliation-result.d.ts +96 -0
- package/build/src/library/contract-forwarding-reconciliation-result.js +83 -0
- package/build/src/library/contract-forwarding-result.d.ts +6723 -0
- package/build/src/library/contract-forwarding-result.js +521 -0
- package/build/src/library/contract-forwarding.d.ts +72 -0
- package/build/src/library/contract-forwarding.js +125 -0
- package/build/src/library/contract-handle.d.ts +36 -0
- package/build/src/library/contract-handle.js +313 -0
- package/build/src/library/contract-operations.d.ts +1044 -67
- package/build/src/library/contract-operations.js +190 -118
- package/build/src/library/contract.d.ts +11 -32
- package/build/src/library/contract.js +16 -289
- package/build/src/library/fleet-result.d.ts +1454 -0
- package/build/src/library/fleet-result.js +96 -0
- package/build/src/library/fleet.d.ts +112 -54
- package/build/src/library/fleet.js +211 -71
- package/build/src/library/input.d.ts +2 -0
- package/build/src/library/input.js +4 -0
- package/build/src/library/keiyaku.d.ts +371 -20
- package/build/src/library/keiyaku.js +8 -21
- package/build/src/library/mutation.d.ts +3 -3
- package/build/src/library/mutation.js +5 -9
- package/build/src/library/nuke.d.ts +1 -1
- package/build/src/library/nuke.js +4 -3
- package/build/src/library/reconcile.d.ts +4 -0
- package/build/src/library/reconcile.js +2 -0
- package/build/src/library/refusal.d.ts +0 -9
- package/build/src/library/refusal.js +0 -7
- package/build/src/protocol/amend.js +56 -50
- package/build/src/protocol/attempt.d.ts +2 -0
- package/build/src/protocol/attempt.js +8 -1
- package/build/src/protocol/completion.js +7 -0
- package/build/src/protocol/deliver.js +6 -2
- package/build/src/protocol/operations.d.ts +4 -1
- package/build/src/protocol/operations.js +5 -2
- package/build/src/protocol/placement.d.ts +1 -0
- package/build/src/protocol/placement.js +52 -38
- package/build/src/protocol/read/observation.d.ts +1 -4
- package/build/src/protocol/read/observation.js +2 -15
- package/build/src/protocol/reintegrate.js +62 -58
- package/build/src/protocol/review.js +5 -0
- package/build/src/protocol/run.js +17 -13
- package/build/src/runtime/proc/run.d.ts +8 -0
- package/build/src/runtime/proc/run.js +27 -0
- package/build/src/runtime/proc/termination.js +26 -22
- package/build/src/runtime/proc/windows-launch.exe +0 -0
- package/build/src/settlement/holder.d.ts +2 -1
- package/build/src/settlement/holder.js +15 -4
- package/build/src/settlement/settle.js +99 -33
- package/build/src/task/board.d.ts +68 -27
- package/build/src/task/board.js +31 -1
- package/build/src/task/catalog.d.ts +4 -0
- package/build/src/task/catalog.js +23 -0
- package/build/src/task/compose-language.js +33 -7
- package/build/src/task/compose-parser.d.ts +1 -1
- package/build/src/task/compose-parser.js +1 -1
- package/build/src/task/compose.js +2 -0
- package/build/src/task/index.d.ts +12 -4
- package/build/src/task/index.js +97 -16
- package/build/src/task/mutation-result.d.ts +923 -0
- package/build/src/task/mutation-result.js +140 -0
- package/build/src/task/mutation.d.ts +552 -28
- package/build/src/task/mutation.js +304 -97
- package/build/src/task/operations.d.ts +1 -4
- package/build/src/task/operations.js +0 -6
- package/build/src/task/public.d.ts +2 -0
- package/build/src/task/public.js +1 -0
- package/build/src/workspace-place.d.ts +7 -2
- package/build/src/workspace-place.js +34 -24
- package/build/src/world.d.ts +1 -0
- package/build/src/world.js +11 -0
- package/package.json +8 -6
- package/build/src/akuma/request-execution.d.ts +0 -8
- package/build/src/akuma/request-execution.js +0 -98
|
@@ -1,248 +1,121 @@
|
|
|
1
|
-
import { admitRequest, isRequestInputConflict, readRequest,
|
|
2
|
-
import {
|
|
3
|
-
import { publishAkuma } from "./publication.js";
|
|
4
|
-
import { atomicJson, canonicalAkuId, decodeRecipe, receiptPath, } from "./request-wire.js";
|
|
5
|
-
import { isTaskMutationAction } from "../task/mutation.js";
|
|
6
|
-
import { executeRequest } from "./request-execution.js";
|
|
1
|
+
import { admitRequest, isRequestInputConflict, readRequest, serveRequest as serveChildRequest, serveUpstreamRequest, voidRequest, } from "./heart/index.js";
|
|
2
|
+
import { atomicJson, receiptPath, } from "./request-wire.js";
|
|
7
3
|
import { BodyRequestPump as LifecycleBodyRequestPump, } from "./request-lifecycle.js";
|
|
8
4
|
export { clearBodyRequestTransport, settleBodyRequests } from "./request-lifecycle.js";
|
|
9
|
-
function
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
return isTaskMutationAction(value.action);
|
|
14
|
-
}
|
|
15
|
-
function refusalRecipe(value) {
|
|
16
|
-
if (value !== null && typeof value === "object" && !Array.isArray(value)) {
|
|
17
|
-
const recipe = value;
|
|
18
|
-
if (Array.isArray(recipe.allowed))
|
|
19
|
-
return recipe;
|
|
20
|
-
return { ...recipe, allowed: [] };
|
|
21
|
-
}
|
|
22
|
-
return { allowed: [] };
|
|
23
|
-
}
|
|
24
|
-
function acceptedReceipt(fact, service) {
|
|
25
|
-
return {
|
|
26
|
-
id: fact.id,
|
|
27
|
-
action: fact.action,
|
|
28
|
-
state: fact.state,
|
|
29
|
-
reference: service.action === "contract.deliver"
|
|
5
|
+
async function projectCommandReceipt(input, fact, command, outcome, failure) {
|
|
6
|
+
const receipt = fact.state === "refused"
|
|
7
|
+
? { id: fact.id, action: fact.action, state: "refused", diagnostic: fact.diagnostic }
|
|
8
|
+
: fact.state === "voided"
|
|
30
9
|
? {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
10
|
+
id: fact.id,
|
|
11
|
+
action: fact.action,
|
|
12
|
+
state: "voided",
|
|
13
|
+
evidence: fact.evidence,
|
|
14
|
+
...(failure === undefined ? {} : { failure }),
|
|
35
15
|
}
|
|
36
|
-
:
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
if (fact.state !== "served")
|
|
55
|
-
return null;
|
|
56
|
-
if (fact.action === "contract.deliver") {
|
|
57
|
-
return acceptedReceipt(fact, fact.service);
|
|
58
|
-
}
|
|
59
|
-
if (fact.action === "contract.review") {
|
|
60
|
-
return acceptedReceipt(fact, fact.service);
|
|
61
|
-
}
|
|
62
|
-
if (isTask(fact)) {
|
|
63
|
-
return {
|
|
64
|
-
id: fact.id,
|
|
65
|
-
action: fact.action,
|
|
66
|
-
state: fact.state,
|
|
67
|
-
reference: { kind: "served-reference", action: fact.action },
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
72
|
-
async function projectReceipt(directory, transportId, fact, outcome) {
|
|
73
|
-
const receipt = outcome === undefined
|
|
74
|
-
? receiptFor(fact)
|
|
75
|
-
: fact.action === "akuma.call"
|
|
76
|
-
? null
|
|
77
|
-
: { id: fact.id, action: fact.action, state: "served", outcome };
|
|
16
|
+
: outcome === undefined
|
|
17
|
+
? "serviceJson" in fact
|
|
18
|
+
? {
|
|
19
|
+
id: fact.id,
|
|
20
|
+
action: fact.action,
|
|
21
|
+
state: "served",
|
|
22
|
+
reference: command.projectServiceJson(fact.serviceJson),
|
|
23
|
+
}
|
|
24
|
+
: "child" in fact
|
|
25
|
+
? {
|
|
26
|
+
id: fact.id,
|
|
27
|
+
action: fact.action,
|
|
28
|
+
state: "served",
|
|
29
|
+
reference: command.projectChild(fact.child),
|
|
30
|
+
}
|
|
31
|
+
: null
|
|
32
|
+
: { id: fact.id, action: fact.action, state: "served", outcome };
|
|
78
33
|
if (receipt === null)
|
|
79
34
|
return;
|
|
80
35
|
try {
|
|
81
|
-
await atomicJson(receiptPath(directory, transportId), receipt);
|
|
36
|
+
await atomicJson(receiptPath(input.directory, input.transportId), receipt);
|
|
82
37
|
}
|
|
83
38
|
catch (error) {
|
|
84
39
|
if (error.code !== "ENOENT")
|
|
85
40
|
throw error;
|
|
86
41
|
}
|
|
87
42
|
}
|
|
88
|
-
async function
|
|
43
|
+
async function serveCommand(input, command) {
|
|
44
|
+
const request = command.resolve(input.claim.payload);
|
|
45
|
+
if (request === null)
|
|
46
|
+
return false;
|
|
89
47
|
let fact = await admitRequest(input.paths, {
|
|
90
|
-
|
|
91
|
-
|
|
48
|
+
id: input.claim.id,
|
|
49
|
+
action: input.claim.action,
|
|
50
|
+
payloadJson: request.payloadJson,
|
|
92
51
|
admittedAt: input.now(),
|
|
52
|
+
permitted: request.isPermitted(input.parent.allowed),
|
|
93
53
|
});
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
fact = await refuseRequest(input.paths, input.claim.id, "invalid akuma.call recipe");
|
|
100
|
-
await projectReceipt(input.directory, input.transportId, fact);
|
|
101
|
-
}
|
|
102
|
-
async function serveCall(input) {
|
|
103
|
-
input.signal.throwIfAborted();
|
|
104
|
-
if (!input.admissionOpen())
|
|
105
|
-
return;
|
|
106
|
-
const recipe = decodeRecipe(input.claim.recipe);
|
|
107
|
-
if (recipe === null) {
|
|
108
|
-
await refuseInvalidCall(input);
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
let fact = await admitRequest(input.paths, { ...input.claim, recipe, admittedAt: input.now() });
|
|
112
|
-
const existing = receiptFor(fact);
|
|
113
|
-
if (existing !== null) {
|
|
114
|
-
await projectReceipt(input.directory, input.transportId, fact);
|
|
115
|
-
return;
|
|
54
|
+
if (fact.state !== "admitted") {
|
|
55
|
+
await projectCommandReceipt(input, fact, request);
|
|
56
|
+
return true;
|
|
116
57
|
}
|
|
117
58
|
if (!input.admissionOpen()) {
|
|
118
|
-
fact = await voidRequest(input.paths,
|
|
119
|
-
await
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
if (fact.action !== "akuma.call" || fact.state !== "admitted") {
|
|
123
|
-
throw new Error(`Akuma request ${fact.id} cannot be replayed from ${fact.state}`);
|
|
124
|
-
}
|
|
125
|
-
const request = fact;
|
|
126
|
-
const world = worldRootForAkumaPaths(input.paths);
|
|
127
|
-
if (request.world !== world) {
|
|
128
|
-
fact = await refuseRequest(input.paths, request.id, `request world ${request.world} does not match ${world}`);
|
|
129
|
-
await projectReceipt(input.directory, input.transportId, fact);
|
|
130
|
-
return;
|
|
59
|
+
fact = await voidRequest(input.paths, fact.id, "body closed request admission");
|
|
60
|
+
await projectCommandReceipt(input, fact, request);
|
|
61
|
+
return true;
|
|
131
62
|
}
|
|
132
63
|
try {
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
64
|
+
const served = await request.execute({
|
|
65
|
+
id: fact.id,
|
|
66
|
+
admittedAt: fact.admittedAt,
|
|
67
|
+
requester: fact.requester,
|
|
136
68
|
signal: input.signal,
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
paths: allocated.paths,
|
|
143
|
-
seed: {
|
|
144
|
-
id: allocated.id,
|
|
145
|
-
archetype: allocated.archetype,
|
|
146
|
-
...(request.recipe.description === undefined ? {} : { description: request.recipe.description }),
|
|
147
|
-
provider: request.recipe.provider,
|
|
148
|
-
options: request.recipe.options,
|
|
149
|
-
...(request.recipe.readonly === undefined ? {} : { readonly: request.recipe.readonly }),
|
|
150
|
-
allowed: request.recipe.allowed,
|
|
151
|
-
cwd: request.cwd ?? input.parent.cwd,
|
|
152
|
-
origin: {
|
|
153
|
-
kind: "request",
|
|
154
|
-
parent: input.parent.id,
|
|
155
|
-
requestId: request.id,
|
|
156
|
-
},
|
|
157
|
-
},
|
|
158
|
-
initialBody: request.body,
|
|
159
|
-
});
|
|
160
|
-
},
|
|
69
|
+
upstream: input.upstream,
|
|
70
|
+
paths: input.paths,
|
|
71
|
+
parent: input.parent,
|
|
72
|
+
spawn: input.spawn,
|
|
73
|
+
admissionOpen: input.admissionOpen,
|
|
161
74
|
});
|
|
162
|
-
fact =
|
|
75
|
+
fact =
|
|
76
|
+
"child" in served
|
|
77
|
+
? await serveChildRequest(input.paths, fact.id, served.child)
|
|
78
|
+
: await serveUpstreamRequest(input.paths, fact.id, served.serviceJson);
|
|
79
|
+
await projectCommandReceipt(input, fact, request, { kind: "returned", result: served.result });
|
|
163
80
|
}
|
|
164
81
|
catch (error) {
|
|
165
|
-
const
|
|
82
|
+
const failure = encodedFailure(request, error);
|
|
83
|
+
const current = await readRequest(input.paths, fact.id);
|
|
166
84
|
if (current === null)
|
|
167
85
|
throw error;
|
|
168
86
|
fact =
|
|
169
87
|
current.state === "admitted" || current.state === "reserved"
|
|
170
|
-
? await voidRequest(input.paths,
|
|
88
|
+
? await voidRequest(input.paths, fact.id, diagnostic(error))
|
|
171
89
|
: current;
|
|
90
|
+
await projectCommandReceipt(input, fact, request, undefined, failure);
|
|
172
91
|
}
|
|
173
|
-
|
|
92
|
+
return true;
|
|
174
93
|
}
|
|
175
|
-
function
|
|
176
|
-
|
|
177
|
-
if (value?.kind === "akuma-not-born") {
|
|
178
|
-
const id = canonicalAkuId(value.id);
|
|
179
|
-
if (id !== null)
|
|
180
|
-
return { kind: "akuma-not-born", id };
|
|
181
|
-
}
|
|
182
|
-
return { kind: "failed", diagnostic: diagnostic(error) };
|
|
94
|
+
function diagnostic(error) {
|
|
95
|
+
return error instanceof Error ? error.message : String(error);
|
|
183
96
|
}
|
|
184
|
-
function
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
return { action: request.action, target: request.target, tellId: request.id };
|
|
97
|
+
function encodedFailure(request, error) {
|
|
98
|
+
try {
|
|
99
|
+
const failure = request.encodeFailure(error);
|
|
100
|
+
return failure === null ? undefined : failure;
|
|
189
101
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
async function serveUpstream(input) {
|
|
193
|
-
input.signal.throwIfAborted();
|
|
194
|
-
let fact = await admitRequest(input.paths, {
|
|
195
|
-
...input.claim,
|
|
196
|
-
admittedAt: input.now(),
|
|
197
|
-
});
|
|
198
|
-
const existing = receiptFor(fact);
|
|
199
|
-
if (existing !== null) {
|
|
200
|
-
await projectReceipt(input.directory, input.transportId, fact);
|
|
201
|
-
return;
|
|
102
|
+
catch {
|
|
103
|
+
return undefined;
|
|
202
104
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
105
|
+
}
|
|
106
|
+
export async function serveRequest(input) {
|
|
107
|
+
const command = input.commands[input.claim.action];
|
|
108
|
+
if (command === undefined) {
|
|
109
|
+
await atomicJson(receiptPath(input.directory, input.transportId), {
|
|
110
|
+
id: input.claim.id,
|
|
111
|
+
action: input.claim.action,
|
|
112
|
+
state: "refused",
|
|
113
|
+
diagnostic: `request action ${input.claim.action} is not registered`,
|
|
210
114
|
});
|
|
211
115
|
return;
|
|
212
116
|
}
|
|
213
|
-
if (
|
|
214
|
-
fact = await voidRequest(input.paths, input.claim.id, "body closed request admission");
|
|
215
|
-
await projectReceipt(input.directory, input.transportId, fact);
|
|
117
|
+
if (await serveCommand(input, command))
|
|
216
118
|
return;
|
|
217
|
-
}
|
|
218
|
-
if (fact.state !== "admitted" || fact.action === "akuma.call") {
|
|
219
|
-
throw new Error(`Akuma request ${fact.id} cannot be served from ${fact.state}`);
|
|
220
|
-
}
|
|
221
|
-
const request = fact;
|
|
222
|
-
let outcome;
|
|
223
|
-
let service = pendingService(request);
|
|
224
|
-
try {
|
|
225
|
-
const served = await executeRequest(input, request);
|
|
226
|
-
outcome = { kind: "returned", result: served.result };
|
|
227
|
-
if (served.service !== undefined)
|
|
228
|
-
service = served.service;
|
|
229
|
-
}
|
|
230
|
-
catch (error) {
|
|
231
|
-
outcome = { kind: "failed", failure: failure(error) };
|
|
232
|
-
fact = await voidRequest(input.paths, request.id, "body failed before serving the request");
|
|
233
|
-
await projectReceipt(input.directory, input.transportId, fact);
|
|
234
|
-
return;
|
|
235
|
-
}
|
|
236
|
-
fact =
|
|
237
|
-
service === undefined
|
|
238
|
-
? await voidRequest(input.paths, request.id, "body completed without a durable Contract fact reference")
|
|
239
|
-
: await serveUpstreamRequest(input.paths, request.id, service);
|
|
240
|
-
await projectReceipt(input.directory, input.transportId, fact, outcome);
|
|
241
|
-
}
|
|
242
|
-
export async function serveRequest(input) {
|
|
243
|
-
return input.claim.action === "akuma.call"
|
|
244
|
-
? await serveCall({ ...input, claim: input.claim })
|
|
245
|
-
: await serveUpstream({ ...input, claim: input.claim });
|
|
246
119
|
}
|
|
247
120
|
async function serveTransportClaim(input) {
|
|
248
121
|
try {
|
|
@@ -261,6 +134,6 @@ async function serveTransportClaim(input) {
|
|
|
261
134
|
}
|
|
262
135
|
export class BodyRequestPump extends LifecycleBodyRequestPump {
|
|
263
136
|
static async open(input) {
|
|
264
|
-
return (await LifecycleBodyRequestPump.openWithService(input, async (claim) => await serveTransportClaim(claim)));
|
|
137
|
+
return (await LifecycleBodyRequestPump.openWithService(input, async (claim) => await serveTransportClaim({ ...claim, commands: input.commands })));
|
|
265
138
|
}
|
|
266
139
|
}
|
|
@@ -1,124 +1,118 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
declare const requestEnvelopeSchema: z.ZodObject<{
|
|
3
|
+
id: z.ZodString;
|
|
4
|
+
action: z.ZodString;
|
|
5
|
+
payload: z.ZodUnknown;
|
|
6
|
+
}, z.core.$strict>;
|
|
7
|
+
declare const upstreamRequestFailureSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
8
|
+
kind: z.ZodLiteral<"akuma-not-born">;
|
|
9
|
+
id: z.ZodString;
|
|
10
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
11
|
+
kind: z.ZodLiteral<"failed">;
|
|
12
|
+
diagnostic: z.ZodString;
|
|
13
|
+
}, z.core.$strict>]>;
|
|
14
|
+
declare const returnedEnvelopeSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
15
|
+
kind: z.ZodLiteral<"returned">;
|
|
16
|
+
result: z.ZodUnknown;
|
|
17
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
18
|
+
kind: z.ZodLiteral<"failed">;
|
|
19
|
+
failure: z.ZodUnion<readonly [z.ZodObject<{
|
|
20
|
+
kind: z.ZodLiteral<"akuma-not-born">;
|
|
21
|
+
id: z.ZodString;
|
|
22
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
23
|
+
kind: z.ZodLiteral<"failed">;
|
|
24
|
+
diagnostic: z.ZodString;
|
|
25
|
+
}, z.core.$strict>]>;
|
|
26
|
+
}, z.core.$strict>]>;
|
|
27
|
+
declare const receiptEnvelopeSchema: z.ZodUnion<readonly [z.ZodObject<{
|
|
28
|
+
id: z.ZodString;
|
|
29
|
+
action: z.ZodString;
|
|
30
|
+
state: z.ZodLiteral<"served">;
|
|
31
|
+
outcome: z.ZodUnion<readonly [z.ZodObject<{
|
|
32
|
+
kind: z.ZodLiteral<"returned">;
|
|
33
|
+
result: z.ZodUnknown;
|
|
34
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
35
|
+
kind: z.ZodLiteral<"failed">;
|
|
36
|
+
failure: z.ZodUnion<readonly [z.ZodObject<{
|
|
37
|
+
kind: z.ZodLiteral<"akuma-not-born">;
|
|
38
|
+
id: z.ZodString;
|
|
39
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
40
|
+
kind: z.ZodLiteral<"failed">;
|
|
41
|
+
diagnostic: z.ZodString;
|
|
42
|
+
}, z.core.$strict>]>;
|
|
43
|
+
}, z.core.$strict>]>;
|
|
44
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
45
|
+
id: z.ZodString;
|
|
46
|
+
action: z.ZodString;
|
|
47
|
+
state: z.ZodLiteral<"served">;
|
|
48
|
+
reference: z.ZodUnknown;
|
|
49
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
50
|
+
id: z.ZodString;
|
|
51
|
+
action: z.ZodString;
|
|
52
|
+
state: z.ZodLiteral<"refused">;
|
|
53
|
+
diagnostic: z.ZodString;
|
|
54
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
55
|
+
id: z.ZodString;
|
|
56
|
+
action: z.ZodString;
|
|
57
|
+
state: z.ZodLiteral<"voided">;
|
|
58
|
+
evidence: z.ZodString;
|
|
59
|
+
failure: z.ZodOptional<z.ZodUnknown>;
|
|
60
|
+
}, z.core.$strict>]>;
|
|
61
|
+
export type RequestEnvelope = z.infer<typeof requestEnvelopeSchema>;
|
|
62
|
+
/**
|
|
63
|
+
* A Body Request operation is owned by the verb that defines its public
|
|
64
|
+
* values. Transport only carries the opaque values produced here.
|
|
65
|
+
*/
|
|
66
|
+
export type RequestCommand<Input, Output, Service, Reference = Service, Context = unknown> = Readonly<{
|
|
67
|
+
action: string;
|
|
68
|
+
encodeRequest(input: Input): unknown;
|
|
69
|
+
decodeRequest(payload: unknown): Input | null;
|
|
70
|
+
encodeResult(result: Output): unknown;
|
|
71
|
+
decodeResult(result: unknown): Output;
|
|
72
|
+
encodeFailure?(error: unknown): unknown | null;
|
|
73
|
+
decodeFailure?(failure: unknown): Error | null;
|
|
74
|
+
encodeService(service: Service): unknown;
|
|
75
|
+
decodeService(service: unknown): Service;
|
|
76
|
+
projectService(service: Service): Reference;
|
|
77
|
+
projectChild?(child: string): Reference;
|
|
78
|
+
decodeReference(reference: unknown): Reference;
|
|
79
|
+
/** The operation owner proves the Body-owned execution capability before use. */
|
|
80
|
+
decodeExecutionContext(value: unknown): Context;
|
|
81
|
+
isPermitted(allowed: readonly string[]): boolean;
|
|
82
|
+
execute(input: Input, context: Context): Promise<Readonly<{
|
|
83
|
+
result: Output;
|
|
84
|
+
}> & (Readonly<{
|
|
85
|
+
service: Service;
|
|
86
|
+
}> | Readonly<{
|
|
87
|
+
child: string;
|
|
88
|
+
}>)>;
|
|
11
89
|
}>;
|
|
12
|
-
export type
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
world: string;
|
|
16
|
-
archetype: string;
|
|
17
|
-
body: string;
|
|
18
|
-
cwd?: string;
|
|
19
|
-
recipe: RequestRecipe;
|
|
90
|
+
export type ErasedRequestCommand = Readonly<{
|
|
91
|
+
action: string;
|
|
92
|
+
resolve(payload: unknown): ErasedRequest | null;
|
|
20
93
|
}>;
|
|
21
|
-
export type
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
94
|
+
export type ErasedRequest = Readonly<{
|
|
95
|
+
payloadJson: string;
|
|
96
|
+
isPermitted(allowed: readonly string[]): boolean;
|
|
97
|
+
execute(context: unknown): Promise<ErasedRequestExecution>;
|
|
98
|
+
encodeFailure(error: unknown): unknown | null;
|
|
99
|
+
projectServiceJson(serviceJson: string): unknown;
|
|
100
|
+
projectChild(child: string): unknown;
|
|
27
101
|
}>;
|
|
28
|
-
export type
|
|
29
|
-
id: string;
|
|
30
|
-
action: "akuma.tell";
|
|
31
|
-
target: AkuId;
|
|
32
|
-
body: string;
|
|
33
|
-
}>;
|
|
34
|
-
export type KillRequestClaim = Readonly<{
|
|
35
|
-
id: string;
|
|
36
|
-
action: "akuma.kill";
|
|
37
|
-
targets: readonly AkuId[];
|
|
38
|
-
}>;
|
|
39
|
-
export type DeliverRequestClaim = Readonly<{
|
|
40
|
-
id: string;
|
|
41
|
-
action: "contract.deliver";
|
|
42
|
-
repoRoot: string;
|
|
43
|
-
contractId: string;
|
|
44
|
-
message?: string;
|
|
45
|
-
includeDirty: boolean;
|
|
46
|
-
materializeConflict: boolean;
|
|
47
|
-
}>;
|
|
48
|
-
export type ReviewRequestClaim = Readonly<{
|
|
49
|
-
id: string;
|
|
50
|
-
action: "contract.review";
|
|
51
|
-
repoRoot: string;
|
|
52
|
-
contractId: string;
|
|
53
|
-
verdict: "satisfied" | "unsatisfied";
|
|
54
|
-
summary?: string;
|
|
55
|
-
}>;
|
|
56
|
-
export type TaskRequestClaim = Readonly<{
|
|
57
|
-
id: string;
|
|
58
|
-
action: TaskMutationAction;
|
|
59
|
-
world: string;
|
|
60
|
-
request: TaskMutationRequest;
|
|
61
|
-
}>;
|
|
62
|
-
export type RequestClaim = CallRequestClaim | WaitRequestClaim | TellRequestClaim | KillRequestClaim | DeliverRequestClaim | ReviewRequestClaim | TaskRequestClaim;
|
|
63
|
-
export type StructuralRequestClaim = (Omit<CallRequestClaim, "recipe"> & Readonly<{
|
|
64
|
-
recipe: unknown;
|
|
65
|
-
}>) | Exclude<RequestClaim, CallRequestClaim>;
|
|
66
|
-
export type UpstreamRequestFailure = Readonly<{
|
|
67
|
-
kind: "akuma-not-born";
|
|
68
|
-
id: AkuId;
|
|
69
|
-
}> | Readonly<{
|
|
70
|
-
kind: "failed";
|
|
71
|
-
diagnostic: string;
|
|
72
|
-
}>;
|
|
73
|
-
export type UpstreamRequestOutcome = Readonly<{
|
|
74
|
-
kind: "returned";
|
|
102
|
+
export type ErasedRequestExecution = Readonly<{
|
|
75
103
|
result: unknown;
|
|
104
|
+
serviceJson: string;
|
|
76
105
|
}> | Readonly<{
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}>;
|
|
80
|
-
export type ForwardedDeliveryReference = Readonly<{
|
|
81
|
-
kind: "accepted-reference";
|
|
82
|
-
repoRoot: string;
|
|
83
|
-
contractId: string;
|
|
84
|
-
deliveryFactId: string;
|
|
85
|
-
}>;
|
|
86
|
-
export type ForwardedReviewReference = Readonly<{
|
|
87
|
-
kind: "accepted-reference";
|
|
88
|
-
repoRoot: string;
|
|
89
|
-
contractId: string;
|
|
90
|
-
reviewFactId: string;
|
|
91
|
-
}>;
|
|
92
|
-
export type ForwardedTaskReference = Readonly<{
|
|
93
|
-
kind: "served-reference";
|
|
94
|
-
action: TaskMutationAction;
|
|
95
|
-
}>;
|
|
96
|
-
type ReceiptBase<A extends RequestClaim["action"], S extends string> = Readonly<{
|
|
97
|
-
id: string;
|
|
98
|
-
action: A;
|
|
99
|
-
state: S;
|
|
106
|
+
result: unknown;
|
|
107
|
+
child: string;
|
|
100
108
|
}>;
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
reference: ForwardedTaskReference;
|
|
109
|
-
}>) | (ReceiptBase<Exclude<RequestClaim["action"], "akuma.call">, "served"> & Readonly<{
|
|
110
|
-
outcome: UpstreamRequestOutcome;
|
|
111
|
-
}>) | (ReceiptBase<RequestClaim["action"], "refused"> & Readonly<{
|
|
112
|
-
diagnostic: string;
|
|
113
|
-
}>) | (ReceiptBase<RequestClaim["action"], "voided"> & Readonly<{
|
|
114
|
-
evidence: string;
|
|
115
|
-
}>);
|
|
116
|
-
export declare function absolute(value: unknown): value is string;
|
|
117
|
-
export declare function canonicalAkuId(value: unknown): AkuId | null;
|
|
118
|
-
export declare function decodeRecipe(value: unknown): RequestRecipe | null;
|
|
119
|
-
export declare function decodeClaim(bytes: string, fileId: string): StructuralRequestClaim | null;
|
|
120
|
-
export declare function decodeReceipt(bytes: string, id: string, action: RequestClaim["action"]): RequestReceipt | null;
|
|
121
|
-
export declare function requestPayload(claim: RequestClaim): unknown;
|
|
109
|
+
/** Erases only static TypeScript parameters; each operation codec remains captured by its owner descriptor. */
|
|
110
|
+
export declare function eraseRequestCommand<Input, Output, Service, Reference, Context>(command: RequestCommand<Input, Output, Service, Reference, Context>): ErasedRequestCommand;
|
|
111
|
+
export type UpstreamRequestFailure = z.infer<typeof upstreamRequestFailureSchema>;
|
|
112
|
+
export type ReturnedEnvelope = z.infer<typeof returnedEnvelopeSchema>;
|
|
113
|
+
export type ReceiptEnvelope = z.infer<typeof receiptEnvelopeSchema>;
|
|
114
|
+
export declare function decodeEnvelope(bytes: string, fileId: string): RequestEnvelope | null;
|
|
115
|
+
export declare function decodeReceiptEnvelope(bytes: string, id: string, action: string): ReceiptEnvelope | null;
|
|
122
116
|
export declare function requestPath(directory: string, id: string): string;
|
|
123
117
|
export declare function receiptPath(directory: string, id: string): string;
|
|
124
118
|
export declare function atomicJson(path: string, value: unknown): Promise<void>;
|