@astrosheep/keiyaku 4.0.4 → 4.0.6
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/.claude-plugin/plugin.json +1 -1
- package/build/integrations/marketplace/plugins/keiyaku/.codex-plugin/plugin.json +1 -1
- package/build/integrations/marketplace/plugins/keiyaku/package.json +1 -1
- package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku/SKILL.md +4 -4
- package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-akuma/SKILL.md +15 -7
- package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-bind/SKILL.md +5 -3
- package/build/integrations/marketplace/plugins/keiyaku/skills/keiyaku-workflow/SKILL.md +24 -4
- package/build/src/akuma/akuma.d.ts +2 -1
- package/build/src/akuma/akuma.js +27 -9
- package/build/src/akuma/allowed.d.ts +1 -1
- package/build/src/akuma/allowed.js +3 -10
- package/build/src/akuma/archetype.d.ts +3 -1
- package/build/src/akuma/archetype.js +11 -6
- package/build/src/akuma/body-turn.d.ts +64 -0
- package/build/src/akuma/body-turn.js +449 -0
- package/build/src/akuma/body.d.ts +4 -5
- package/build/src/akuma/body.js +9 -414
- package/build/src/akuma/heart/facts.d.ts +37 -9
- package/build/src/akuma/heart/facts.js +3 -1
- package/build/src/akuma/heart/index.d.ts +4 -13
- package/build/src/akuma/heart/index.js +14 -135
- package/build/src/akuma/heart/request-authority.d.ts +12 -0
- package/build/src/akuma/heart/request-authority.js +119 -0
- package/build/src/akuma/heart/request-rows.d.ts +16 -0
- package/build/src/akuma/heart/request-rows.js +88 -0
- package/build/src/akuma/heart/rows.d.ts +1 -28
- package/build/src/akuma/heart/rows.js +4 -138
- package/build/src/akuma/heart/schema.d.ts +1 -1
- package/build/src/akuma/heart/schema.js +11 -3
- package/build/src/akuma/heart/soul.js +0 -36
- package/build/src/akuma/heart/timeline.d.ts +1 -0
- package/build/src/akuma/heart/timeline.js +19 -0
- package/build/src/akuma/index.d.ts +1 -1
- package/build/src/akuma/nuke.d.ts +2 -0
- package/build/src/akuma/nuke.js +152 -0
- package/build/src/akuma/provider-recipe.js +1 -11
- package/build/src/akuma/provider.d.ts +4 -7
- package/build/src/akuma/providers/acp/config.d.ts +8 -0
- package/build/src/akuma/providers/acp/config.js +37 -0
- package/build/src/akuma/providers/acp/core.js +12 -2
- package/build/src/akuma/providers/acp/index.d.ts +1 -8
- package/build/src/akuma/providers/acp/index.js +2 -38
- package/build/src/akuma/providers/claude/index.d.ts +0 -4
- package/build/src/akuma/providers/claude/index.js +12 -3
- package/build/src/akuma/providers/codex-app-server/index.d.ts +2 -27
- package/build/src/akuma/providers/codex-app-server/index.js +5 -2
- package/build/src/akuma/providers/grok-build/index.js +1 -2
- package/build/src/akuma/providers/index.d.ts +3 -2
- package/build/src/akuma/providers/index.js +36 -36
- package/build/src/akuma/providers/opencode-sdk/index.d.ts +2 -28
- package/build/src/akuma/providers/opencode-sdk/index.js +14 -4
- package/build/src/akuma/providers/opencode-sdk/session.d.ts +2 -2
- package/build/src/akuma/providers/opencode-sdk/session.js +2 -2
- package/build/src/akuma/providers/pi/index.d.ts +1 -1
- package/build/src/akuma/providers/pi/index.js +29 -6
- package/build/src/akuma/request-serve.d.ts +88 -0
- package/build/src/akuma/request-serve.js +484 -0
- package/build/src/akuma/request-wire.d.ts +125 -0
- package/build/src/akuma/request-wire.js +383 -0
- package/build/src/akuma/requests.d.ts +28 -94
- package/build/src/akuma/requests.js +52 -562
- package/build/src/akuma-body.d.ts +7 -0
- package/build/src/akuma-body.js +69 -2
- package/build/src/alias/index.d.ts +1 -0
- package/build/src/alias/index.js +34 -1
- package/build/src/body/arc.js +4 -29
- package/build/src/body/decode.js +5 -39
- package/build/src/body/envelope.d.ts +7 -0
- package/build/src/body/envelope.js +37 -0
- package/build/src/cli/accepted.js +21 -9
- package/build/src/cli/commands/akuma-invoke.js +1 -0
- package/build/src/cli/commands/akuma.d.ts +1 -0
- package/build/src/cli/commands/akuma.js +13 -10
- package/build/src/cli/commands/contract.d.ts +28 -17
- package/build/src/cli/commands/contract.js +23 -17
- package/build/src/cli/commands/install.d.ts +2 -2
- package/build/src/cli/commands/install.js +6 -6
- package/build/src/cli/commands/nuke.d.ts +10 -0
- package/build/src/cli/commands/nuke.js +20 -0
- package/build/src/cli/commands/task-invoke.d.ts +15 -0
- package/build/src/cli/commands/task-invoke.js +144 -24
- package/build/src/cli/commands/task-query.d.ts +2 -2
- package/build/src/cli/commands/task-query.js +1 -2
- package/build/src/cli/commands/task.js +22 -22
- package/build/src/cli/coordinates.d.ts +6 -2
- package/build/src/cli/coordinates.js +12 -56
- package/build/src/cli/invoke.d.ts +5 -4
- package/build/src/cli/invoke.js +112 -58
- package/build/src/cli/main.d.ts +0 -2
- package/build/src/cli/main.js +4 -140
- package/build/src/cli/parse.d.ts +17 -4
- package/build/src/cli/parse.js +93 -15
- package/build/src/cli/render/akuma.js +111 -53
- package/build/src/cli/render/audit.js +2 -6
- package/build/src/cli/render/contract.js +61 -20
- package/build/src/cli/render/kanshi.js +15 -5
- package/build/src/cli/render/nuke.d.ts +3 -0
- package/build/src/cli/render/nuke.js +8 -0
- package/build/src/cli/render/receipt.js +28 -1
- package/build/src/cli/render/refusal.d.ts +2 -1
- package/build/src/cli/render/refusal.js +31 -0
- package/build/src/cli/render/terminal.d.ts +0 -2
- package/build/src/cli/render/terminal.js +0 -29
- package/build/src/cli/render/text.js +6 -1
- package/build/src/cli/result.d.ts +36 -9
- package/build/src/cli/runtime.d.ts +2 -0
- package/build/src/cli/runtime.js +140 -0
- package/build/src/cli/usage.d.ts +0 -2
- package/build/src/cli/usage.js +0 -4
- package/build/src/contract-worktree.d.ts +29 -14
- package/build/src/contract-worktree.js +131 -70
- package/build/src/core/facts/codec.js +9 -0
- package/build/src/core/facts/fold.js +13 -1
- package/build/src/core/facts/types.d.ts +8 -1
- package/build/src/core/subject.js +4 -3
- package/build/src/core/verbs/placement.d.ts +9 -1
- package/build/src/core/verbs/placement.js +24 -6
- package/build/src/core/verbs/reintegrate.d.ts +13 -0
- package/build/src/core/verbs/reintegrate.js +24 -0
- package/build/src/dispatch/index.d.ts +1 -1
- package/build/src/git/admission.d.ts +2 -1
- package/build/src/git/hooks.d.ts +2 -0
- package/build/src/git/hooks.js +34 -1
- package/build/src/git/integration.d.ts +9 -2
- package/build/src/git/integration.js +92 -1
- package/build/src/git/nuke.d.ts +2 -0
- package/build/src/git/nuke.js +97 -0
- package/build/src/git/observe.d.ts +2 -1
- package/build/src/git/observe.js +6 -5
- package/build/src/git/process.d.ts +28 -0
- package/build/src/git/process.js +94 -0
- package/build/src/git/read-observation.d.ts +2 -1
- package/build/src/git/read-observation.js +3 -2
- package/build/src/git/reconcile.d.ts +4 -1
- package/build/src/git/reconcile.js +42 -8
- package/build/src/git/repository.d.ts +2 -29
- package/build/src/git/repository.js +7 -118
- package/build/src/git/scratch.d.ts +1 -1
- package/build/src/git/scratch.js +1 -1
- package/build/src/git/target-placement.d.ts +3 -2
- package/build/src/git/target-placement.js +15 -14
- package/build/src/git/tender.d.ts +2 -1
- package/build/src/git/tender.js +4 -3
- package/build/src/git/terminal-seal.d.ts +2 -2
- package/build/src/git/terminal-seal.js +3 -6
- package/build/src/git/workspace.d.ts +4 -1
- package/build/src/git/workspace.js +1 -1
- package/build/src/index.d.ts +1 -2
- package/build/src/index.js +1 -1
- package/build/src/kanshi/read.js +5 -1
- package/build/src/library/address.js +7 -1
- package/build/src/library/akuma-creation.d.ts +1 -0
- package/build/src/library/akuma-creation.js +8 -1
- package/build/src/library/audit.d.ts +3 -1
- package/build/src/library/audit.js +2 -1
- package/build/src/library/bind.d.ts +2 -1
- package/build/src/library/bind.js +1 -1
- package/build/src/library/configuration.d.ts +1 -1
- package/build/src/library/configuration.js +52 -18
- package/build/src/library/contract.d.ts +59 -4
- package/build/src/library/contract.js +195 -34
- package/build/src/library/delivery.d.ts +4 -2
- package/build/src/library/fleet.d.ts +27 -7
- package/build/src/library/fleet.js +79 -39
- package/build/src/library/input.d.ts +0 -1
- package/build/src/library/input.js +0 -5
- package/build/src/library/keiyaku.d.ts +6 -2
- package/build/src/library/keiyaku.js +2 -0
- package/build/src/library/mutation.d.ts +3 -1
- package/build/src/library/mutation.js +3 -0
- package/build/src/library/nuke.d.ts +14 -0
- package/build/src/library/nuke.js +54 -0
- package/build/src/library/reconcile.d.ts +2 -1
- package/build/src/library/reconcile.js +8 -3
- package/build/src/library/refusal.d.ts +10 -1
- package/build/src/library/region.d.ts +1 -1
- package/build/src/library/repo.d.ts +4 -1
- package/build/src/library/repo.js +10 -4
- package/build/src/protocol/abandon.d.ts +9 -0
- package/build/src/protocol/abandon.js +15 -0
- package/build/src/protocol/amend.d.ts +16 -0
- package/build/src/protocol/amend.js +77 -0
- package/build/src/protocol/arc.d.ts +6 -0
- package/build/src/protocol/arc.js +12 -0
- package/build/src/protocol/attempt.d.ts +2 -1
- package/build/src/protocol/audit.d.ts +53 -0
- package/build/src/protocol/audit.js +147 -0
- package/build/src/protocol/bind.d.ts +1 -1
- package/build/src/protocol/completion.d.ts +42 -0
- package/build/src/protocol/completion.js +183 -0
- package/build/src/protocol/deliver.d.ts +49 -0
- package/build/src/protocol/deliver.js +261 -0
- package/build/src/protocol/intent.d.ts +2 -1
- package/build/src/protocol/intent.js +8 -2
- package/build/src/protocol/operations.d.ts +93 -202
- package/build/src/protocol/operations.js +23 -642
- package/build/src/protocol/placement.d.ts +12 -13
- package/build/src/protocol/placement.js +8 -19
- package/build/src/protocol/read/status.d.ts +17 -5
- package/build/src/protocol/read/status.js +57 -13
- package/build/src/protocol/reconcile.d.ts +35 -0
- package/build/src/protocol/reconcile.js +41 -0
- package/build/src/protocol/reintegrate.d.ts +31 -0
- package/build/src/protocol/reintegrate.js +74 -0
- package/build/src/protocol/review.d.ts +34 -0
- package/build/src/protocol/review.js +156 -0
- package/build/src/protocol/run.d.ts +1 -1
- package/build/src/runtime/proc/run.js +9 -5
- package/build/src/settlement/fence.d.ts +3 -1
- package/build/src/settlement/fence.js +24 -0
- package/build/src/settlement/holder.d.ts +1 -1
- package/build/src/settlement/settle.d.ts +1 -1
- package/build/src/settlement/settle.js +1 -2
- package/build/src/task/board.d.ts +0 -1
- package/build/src/task/board.js +0 -3
- package/build/src/task/compose.d.ts +2 -2
- package/build/src/task/compose.js +13 -11
- package/build/src/task/context.d.ts +14 -2
- package/build/src/task/context.js +30 -7
- package/build/src/task/index.d.ts +7 -6
- package/build/src/task/index.js +17 -145
- package/build/src/task/input.d.ts +18 -0
- package/build/src/task/input.js +189 -0
- package/build/src/task/mutation.d.ts +44 -0
- package/build/src/task/mutation.js +93 -0
- package/build/src/task/operations.d.ts +14 -6
- package/build/src/task/operations.js +57 -57
- package/build/src/task/store.d.ts +1 -0
- package/build/src/task/store.js +91 -3
- package/build/src/verification/execution.d.ts +1 -1
- package/build/src/workspace-place.d.ts +3 -4
- package/build/src/workspace-place.js +26 -15
- package/package.json +3 -3
|
@@ -1,31 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { reconcile, reconcileBatch, reconcileObservationFailure, } from "../git/reconcile.js";
|
|
5
|
-
import { NoGitWorldError, repositoryAt } from "../git/repository.js";
|
|
1
|
+
import { readDeliveryDiff } from "../git/integration.js";
|
|
2
|
+
import { currentBranch, observeContractAt } from "../git/observe.js";
|
|
3
|
+
import { repositoryAt } from "../git/repository.js";
|
|
6
4
|
import { withGitReadObservation } from "../git/read-observation.js";
|
|
7
|
-
import { dependencyKeySet } from "../core/subject.js";
|
|
8
|
-
import { AuthorityCorruptionError } from "../core/facts/errors.js";
|
|
9
|
-
import { activeContract, contractState, documentIsCurrent } from "../core/facts/observation.js";
|
|
10
|
-
import { gate } from "../core/facts/types.js";
|
|
11
|
-
import { decideAbandon } from "../core/verbs/abandon.js";
|
|
12
|
-
import { decideAmend } from "../core/verbs/amend.js";
|
|
13
|
-
import { decideArc } from "../core/verbs/arc.js";
|
|
14
|
-
import { decideDeliver } from "../core/verbs/deliver.js";
|
|
15
|
-
import { decideAttestation } from "../core/verbs/attestation.js";
|
|
16
|
-
import { admitIntent, currentVerifiedAttestation, verifyDelivery, } from "./intent.js";
|
|
17
|
-
import { admitPlacement, } from "./placement.js";
|
|
18
|
-
import { adjudicateAuditTarget } from "../git/target-placement.js";
|
|
19
5
|
import { readDocuments } from "./read/documents.js";
|
|
20
6
|
import { readContractBoard, readContractObservationAt, } from "./read/status.js";
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
export { bindOperation } from "./bind.js";
|
|
24
|
-
export { reconcileObservationFailure } from "../git/reconcile.js";
|
|
25
|
-
import { accepted, admitted, complete, } from "./outcome.js";
|
|
26
|
-
const REVIEWED = gate("reviewed");
|
|
27
|
-
function timestamp() { return new Date().toISOString(); }
|
|
28
|
-
function mergeAdmissions(current, next) {
|
|
7
|
+
export function timestamp() { return new Date().toISOString(); }
|
|
8
|
+
export function mergeAdmissions(current, next) {
|
|
29
9
|
const effects = [...(current.physical?.effects ?? []), ...(next.physical?.effects ?? [])];
|
|
30
10
|
const lag = [...(current.physical?.lag ?? []), ...(next.physical?.lag ?? [])];
|
|
31
11
|
return {
|
|
@@ -34,19 +14,15 @@ function mergeAdmissions(current, next) {
|
|
|
34
14
|
...(effects.length === 0 && lag.length === 0 ? {} : { physical: { effects, lag } }),
|
|
35
15
|
};
|
|
36
16
|
}
|
|
37
|
-
function stepStop(result) {
|
|
17
|
+
export function stepStop(result) {
|
|
38
18
|
if (result.kind === "accepted")
|
|
39
19
|
return undefined;
|
|
40
20
|
return result.kind === "refused" ? { refusal: result.refusal } : { retry: result };
|
|
41
21
|
}
|
|
42
|
-
function
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const stop = verificationStop(verification.step);
|
|
47
|
-
const admission = !("failure" in verification.step) && verification.step.kind === "accepted"
|
|
48
|
-
? verification.step
|
|
49
|
-
: undefined;
|
|
22
|
+
export function unpackVerificationOutcome(verification) {
|
|
23
|
+
const step = verification.step;
|
|
24
|
+
const stop = "failure" in step ? step : stepStop(step);
|
|
25
|
+
const admission = !("failure" in step) && step.kind === "accepted" ? step : undefined;
|
|
50
26
|
return {
|
|
51
27
|
...(verification.cleanup === undefined ? {} : { cleanup: verification.cleanup }),
|
|
52
28
|
...(verification.leak === undefined ? {} : { leak: verification.leak }),
|
|
@@ -55,30 +31,28 @@ function unpackVerificationOutcome(verification) {
|
|
|
55
31
|
...(verification.counts === undefined ? {} : { counts: verification.counts }),
|
|
56
32
|
};
|
|
57
33
|
}
|
|
58
|
-
function placementStop(result) {
|
|
34
|
+
export function placementStop(result) {
|
|
59
35
|
if (result.kind === "accepted")
|
|
60
36
|
return undefined;
|
|
61
|
-
if (result.kind === "placement-failed")
|
|
37
|
+
if (result.kind === "placement-failed")
|
|
62
38
|
return { failure: "target-placement-failed", diagnostic: result.diagnostic };
|
|
63
|
-
}
|
|
64
39
|
if (result.kind === "target-moved") {
|
|
65
40
|
const { contractId, target, expected, observed } = result;
|
|
66
41
|
return { failure: "target-moved", contractId, target, expected, observed };
|
|
67
42
|
}
|
|
68
43
|
return result.kind === "refused" ? { refusal: result.refusal } : { retry: result };
|
|
69
44
|
}
|
|
70
|
-
export { NoGitWorldError };
|
|
71
45
|
export async function scopeOperation(input) {
|
|
72
|
-
return await repositoryAt(input.coordinate);
|
|
46
|
+
return await repositoryAt(input.coordinate, input.gitPath);
|
|
73
47
|
}
|
|
74
48
|
export async function currentBranchOperation(input) {
|
|
75
49
|
return await currentBranch(input.scope);
|
|
76
50
|
}
|
|
77
51
|
export async function contractsOperation(input) {
|
|
78
|
-
return withGitReadObservation(input.scope, input.channel, readContractBoard);
|
|
52
|
+
return withGitReadObservation(input.scope, input.channel, (observation) => readContractBoard(observation, undefined, input.hereWorkspace));
|
|
79
53
|
}
|
|
80
54
|
export async function contractObservationOperation(input) {
|
|
81
|
-
return await readContractObservationAt(input.scope, input.channel, input.contractId);
|
|
55
|
+
return await readContractObservationAt(input.scope, input.channel, input.contractId, input.hereWorkspace);
|
|
82
56
|
}
|
|
83
57
|
export async function documentsOperationAt(scope, channel) {
|
|
84
58
|
return withGitReadObservation(scope, channel, readDocuments);
|
|
@@ -91,605 +65,12 @@ export async function stateOperation(input) {
|
|
|
91
65
|
}
|
|
92
66
|
export async function deliveryOperation(input) {
|
|
93
67
|
const state = (await observeContractAt(input.scope, input.channel, input.contractId)).state;
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
const batch = [...new Set(pending.filter((id) => !visited.has(id)))];
|
|
103
|
-
pending = [];
|
|
104
|
-
if (batch.length === 0)
|
|
105
|
-
break;
|
|
106
|
-
current = await extendContractsForAdmissionAt(channel, current, batch);
|
|
107
|
-
for (const id of batch) {
|
|
108
|
-
visited.add(id);
|
|
109
|
-
const state = contractState(current.decision, id);
|
|
110
|
-
if (state !== null)
|
|
111
|
-
pending.push(...state.terms.after);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return current;
|
|
115
|
-
}
|
|
116
|
-
export async function amendOperation(input) {
|
|
117
|
-
const attempts = mintAttempts({ entryCount: 1 });
|
|
118
|
-
let source = input.source;
|
|
119
|
-
for (let index = 0; index < attempts.length; index += 1) {
|
|
120
|
-
let observation = await observeContractsForAdmissionAt(input.scope, input.channel, [input.contractId]);
|
|
121
|
-
const state = contractState(observation.decision, input.contractId);
|
|
122
|
-
if (source === undefined && state !== null)
|
|
123
|
-
source = state.terms;
|
|
124
|
-
const amendment = source === undefined || input.deriveAmendment === undefined
|
|
125
|
-
? undefined
|
|
126
|
-
: { source, ...input.deriveAmendment(source) };
|
|
127
|
-
if (amendment !== undefined) {
|
|
128
|
-
observation = await extendPrerequisiteClosureAt(input.channel, observation, [...new Set([...(state?.terms.after ?? []), ...amendment.terms.after])]);
|
|
129
|
-
}
|
|
130
|
-
const preparation = amendment === undefined
|
|
131
|
-
? undefined
|
|
132
|
-
: amendment.verification.kind === "prepared"
|
|
133
|
-
? { kind: "prepared", data: amendment.terms }
|
|
134
|
-
: { kind: "refused", refusal: amendment.verification.refusal };
|
|
135
|
-
const decision = decideAmend({
|
|
136
|
-
input: {
|
|
137
|
-
contractId: input.contractId,
|
|
138
|
-
...(input.actor === undefined ? {} : { actor: input.actor }),
|
|
139
|
-
at: timestamp(),
|
|
140
|
-
...(amendment === undefined ? {} : { source: amendment.source }),
|
|
141
|
-
...(preparation === undefined ? {} : { preparation }),
|
|
142
|
-
},
|
|
143
|
-
attempt: attempts[index],
|
|
144
|
-
observation: observation.decision,
|
|
145
|
-
});
|
|
146
|
-
if (decision.kind === "refused")
|
|
147
|
-
return decision;
|
|
148
|
-
const admission = await admitDecidedOffer({
|
|
149
|
-
channel: input.channel,
|
|
150
|
-
repository: input.scope,
|
|
151
|
-
decisionObservation: observation,
|
|
152
|
-
attempt: attempts[index],
|
|
153
|
-
offer: decision.offer,
|
|
154
|
-
primaryContract: input.contractId,
|
|
155
|
-
});
|
|
156
|
-
if (admission.kind === "accepted") {
|
|
157
|
-
if (amendment === undefined)
|
|
158
|
-
throw new Error("accepted amendment is missing its document derivation");
|
|
159
|
-
return admitted(admission, amendment);
|
|
160
|
-
}
|
|
161
|
-
if (admission.kind === "publication-failed")
|
|
162
|
-
return { kind: "retry", reason: admission };
|
|
163
|
-
if (admission.kind === "collision" && index + 1 === attempts.length)
|
|
164
|
-
return { kind: "retry", reason: admission };
|
|
165
|
-
}
|
|
166
|
-
return { kind: "retry", reason: { kind: "exhausted" } };
|
|
167
|
-
}
|
|
168
|
-
export async function prepareDelivery(repository, stage, input) {
|
|
169
|
-
const { contractId, coordinates } = stage;
|
|
170
|
-
if (coordinates.workspace === "here" && coordinates.target !== undefined) {
|
|
171
|
-
const branch = await currentBranch(repository);
|
|
172
|
-
if (branch !== coordinates.target) {
|
|
173
|
-
return { kind: "refused", refusal: { kind: "workspace-not-on-target", contractId, target: coordinates.target, branch } };
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
const appointed = coordinates.workspace === "worktree"
|
|
177
|
-
? stage.appointment === undefined
|
|
178
|
-
? appointmentFor(await readPlaceRegister(repository), contractId)
|
|
179
|
-
: { contract: contractId, place: stage.appointment.place }
|
|
180
|
-
: undefined;
|
|
181
|
-
const tender = await captureTender(repository, {
|
|
182
|
-
contractId,
|
|
183
|
-
coordinates,
|
|
184
|
-
...(appointed === undefined ? {} : { place: appointed.place }),
|
|
185
|
-
});
|
|
186
|
-
if (tender.kind === "refused")
|
|
187
|
-
return tender;
|
|
188
|
-
if ((tender.data.dirty && input.includeDirty !== true) || tender.data.changes.submodules.length > 0) {
|
|
189
|
-
return { kind: "refused", refusal: await dirtyTenderRefusal(repository, contractId, tender.data) };
|
|
190
|
-
}
|
|
191
|
-
const commit = await prepareDeliveryCommitMetadata(repository, {
|
|
192
|
-
contractId,
|
|
193
|
-
title: input.title,
|
|
194
|
-
document: input.document,
|
|
195
|
-
at: tender.data.at,
|
|
196
|
-
...(input.actor === undefined ? {} : { actor: input.actor }),
|
|
197
|
-
...(input.message === undefined ? {} : { message: input.message }),
|
|
198
|
-
});
|
|
199
|
-
const tenderSnapshot = await materializeTenderSnapshot(repository, tender.data, commit);
|
|
200
|
-
const requireBranchesToBeUpToDate = input.requireBranchesToBeUpToDate ?? false;
|
|
201
|
-
const integration = await planIntegration(repository, { contractId, coordinates }, { ...tender.data, head: tenderSnapshot }, requireBranchesToBeUpToDate);
|
|
202
|
-
if (integration.kind === "refused")
|
|
203
|
-
return integration;
|
|
204
|
-
const integrationSnapshot = coordinates.target === undefined
|
|
205
|
-
? tenderSnapshot
|
|
206
|
-
: await materializeIntegrationSnapshot(repository, integration.data.tree, integration.data.predecessor, commit);
|
|
207
|
-
return {
|
|
208
|
-
kind: "prepared",
|
|
209
|
-
data: {
|
|
210
|
-
tenderSnapshot,
|
|
211
|
-
integration: {
|
|
212
|
-
predecessor: integration.data.predecessor,
|
|
213
|
-
snapshot: integrationSnapshot,
|
|
214
|
-
changeId: await worktreeChangeId(repository, { contractId, coordinates }, tender.data),
|
|
215
|
-
},
|
|
216
|
-
method: "squash",
|
|
217
|
-
policy: { requireBranchesToBeUpToDate },
|
|
218
|
-
},
|
|
219
|
-
};
|
|
220
|
-
}
|
|
221
|
-
async function captureReviewableWorktree(repository, stage) {
|
|
222
|
-
const appointed = stage.coordinates.workspace === "worktree"
|
|
223
|
-
? appointmentFor(await readPlaceRegister(repository), stage.contractId)
|
|
224
|
-
: undefined;
|
|
225
|
-
const tender = await captureTender(repository, {
|
|
226
|
-
...stage,
|
|
227
|
-
...(appointed === undefined ? {} : { place: appointed.place }),
|
|
228
|
-
});
|
|
229
|
-
if (tender.kind === "refused")
|
|
230
|
-
return tender;
|
|
231
|
-
if (tender.data.changes.submodules.length > 0) {
|
|
232
|
-
return { kind: "refused", refusal: await dirtyTenderRefusal(repository, stage.contractId, tender.data) };
|
|
233
|
-
}
|
|
234
|
-
const workspace = await dirtyTenderDelta(repository, tender.data);
|
|
235
|
-
return {
|
|
236
|
-
kind: "prepared",
|
|
237
|
-
data: {
|
|
238
|
-
changeId: await worktreeChangeId(repository, stage, tender.data),
|
|
239
|
-
tender: tender.data,
|
|
240
|
-
...(workspace === undefined ? {} : { workspace }),
|
|
241
|
-
},
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
export async function prepareReview(repository, stage) {
|
|
245
|
-
const prepared = await captureReviewableWorktree(repository, stage);
|
|
246
|
-
if (prepared.kind === "refused")
|
|
247
|
-
return prepared;
|
|
248
|
-
return {
|
|
249
|
-
kind: "prepared",
|
|
250
|
-
data: {
|
|
251
|
-
changeId: prepared.data.changeId,
|
|
252
|
-
...(prepared.data.workspace === undefined ? {} : { workspace: prepared.data.workspace }),
|
|
253
|
-
},
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
async function deliverAttempt(input, attempt) {
|
|
257
|
-
const decisionObservation = await observeContractsForAdmissionAt(input.scope, input.channel, [input.contractId]);
|
|
258
|
-
const state = contractState(decisionObservation.decision, input.contractId);
|
|
259
|
-
const derivation = state === null || input.deriveDocument === undefined
|
|
260
|
-
? undefined
|
|
261
|
-
: input.deriveDocument(state);
|
|
262
|
-
let preparation;
|
|
263
|
-
if (state === null || derivation === undefined) {
|
|
264
|
-
preparation = { kind: "unavailable" };
|
|
265
|
-
}
|
|
266
|
-
else if (derivation.verification.kind === "refused") {
|
|
267
|
-
preparation = {
|
|
268
|
-
kind: "refused",
|
|
269
|
-
document: derivation.document,
|
|
270
|
-
refusal: derivation.verification.refusal,
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
else {
|
|
274
|
-
const prepared = await prepareDelivery(input.scope, {
|
|
275
|
-
contractId: state.id,
|
|
276
|
-
coordinates: state.coordinates,
|
|
277
|
-
}, {
|
|
278
|
-
title: derivation.title,
|
|
279
|
-
document: derivation.bytes,
|
|
280
|
-
...(input.actor === undefined ? {} : { actor: input.actor }),
|
|
281
|
-
...(input.message === undefined ? {} : { message: input.message }),
|
|
282
|
-
requireBranchesToBeUpToDate: input.requireBranchesToBeUpToDate,
|
|
283
|
-
includeDirty: input.includeDirty,
|
|
284
|
-
});
|
|
285
|
-
preparation = prepared.kind === "refused"
|
|
286
|
-
? { kind: "refused", document: derivation.document, refusal: prepared.refusal }
|
|
287
|
-
: { kind: "prepared", document: derivation.document, data: prepared.data };
|
|
288
|
-
}
|
|
289
|
-
const decisionInput = {
|
|
290
|
-
contractId: input.contractId,
|
|
291
|
-
...(input.actor === undefined ? {} : { actor: input.actor }),
|
|
292
|
-
at: timestamp(),
|
|
293
|
-
preparation,
|
|
294
|
-
};
|
|
295
|
-
const decision = decideDeliver({ input: decisionInput, attempt, observation: decisionObservation.decision });
|
|
296
|
-
if (decision.kind === "refused")
|
|
297
|
-
return { kind: "refused", refusal: decision.refusal };
|
|
298
|
-
if (preparation.kind !== "prepared") {
|
|
299
|
-
throw new Error("offered delivery is missing its mechanical preparation");
|
|
300
|
-
}
|
|
301
|
-
const admitted = await admitDecidedOffer({
|
|
302
|
-
channel: input.channel,
|
|
303
|
-
repository: input.scope,
|
|
304
|
-
decisionObservation,
|
|
305
|
-
attempt,
|
|
306
|
-
offer: decision.offer,
|
|
307
|
-
primaryContract: input.contractId,
|
|
308
|
-
});
|
|
309
|
-
if (admitted.kind === "accepted") {
|
|
310
|
-
if (derivation === undefined)
|
|
311
|
-
throw new Error("accepted delivery is missing its document derivation");
|
|
312
|
-
return { ...admitted, value: { delivery: preparation.data, derivation } };
|
|
313
|
-
}
|
|
314
|
-
return admitted;
|
|
315
|
-
}
|
|
316
|
-
async function completeDelivery(input, first) {
|
|
317
|
-
const derivation = first.value.derivation;
|
|
318
|
-
if (derivation.verification.kind !== "prepared") {
|
|
319
|
-
throw new Error("accepted delivery is missing its Verification preparation");
|
|
320
|
-
}
|
|
321
|
-
let admission = first;
|
|
322
|
-
let verificationValue;
|
|
323
|
-
let verificationReuse;
|
|
324
|
-
let cleanup;
|
|
325
|
-
let leak;
|
|
326
|
-
const currentVerified = currentVerifiedAttestation(first.state);
|
|
327
|
-
if (currentVerified !== undefined) {
|
|
328
|
-
verificationReuse = currentVerified;
|
|
329
|
-
}
|
|
330
|
-
else {
|
|
331
|
-
const verification = await verifyDelivery({
|
|
332
|
-
channel: input.channel,
|
|
333
|
-
repository: input.scope,
|
|
334
|
-
contractId: input.contractId,
|
|
335
|
-
...(input.actor === undefined ? {} : { actor: input.actor }),
|
|
336
|
-
at: timestamp(),
|
|
337
|
-
state: first.state,
|
|
338
|
-
snapshot: first.value.delivery.integration.snapshot,
|
|
339
|
-
environment: process.env,
|
|
340
|
-
...(input.signal === undefined ? {} : { signal: input.signal }),
|
|
341
|
-
...(derivation.verification.data === null
|
|
342
|
-
? {}
|
|
343
|
-
: { verification: derivation.verification.data }),
|
|
344
|
-
});
|
|
345
|
-
if (verification !== null) {
|
|
346
|
-
const unpacked = unpackVerificationOutcome(verification);
|
|
347
|
-
cleanup = unpacked.cleanup;
|
|
348
|
-
leak = unpacked.leak;
|
|
349
|
-
verificationValue = unpacked.stop;
|
|
350
|
-
if (unpacked.admission !== undefined)
|
|
351
|
-
admission = mergeAdmissions(admission, unpacked.admission);
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
const placement = await admitPlacement(input.channel, input.scope, first.state.coordinates.target, {
|
|
355
|
-
contractId: input.contractId,
|
|
356
|
-
...(input.actor === undefined ? {} : { actor: input.actor }),
|
|
357
|
-
at: timestamp(),
|
|
358
|
-
});
|
|
359
|
-
const placementValue = placementStop(placement);
|
|
360
|
-
if (placement.kind === "accepted")
|
|
361
|
-
admission = mergeAdmissions(admission, placement);
|
|
362
|
-
return admitted(admission, {
|
|
363
|
-
...first.value.delivery,
|
|
364
|
-
...(verificationValue === undefined ? {} : { verification: verificationValue }),
|
|
365
|
-
...(verificationReuse === undefined ? {} : { verificationReuse }),
|
|
366
|
-
...(placementValue === undefined ? {} : { placement: placementValue }),
|
|
367
|
-
...(cleanup === undefined ? {} : { cleanup }),
|
|
368
|
-
...(leak === undefined ? {} : { leak }),
|
|
369
|
-
});
|
|
370
|
-
}
|
|
371
|
-
export async function deliverOperation(input) {
|
|
372
|
-
const attempts = mintAttempts({ entryCount: 2 });
|
|
373
|
-
let first = null;
|
|
374
|
-
for (let index = 0; index < attempts.length; index += 1) {
|
|
375
|
-
const result = await deliverAttempt(input, attempts[index]);
|
|
376
|
-
if (result.kind === "accepted") {
|
|
377
|
-
first = result;
|
|
378
|
-
break;
|
|
379
|
-
}
|
|
380
|
-
if (result.kind === "refused")
|
|
381
|
-
return result;
|
|
382
|
-
if (result.kind === "publication-failed")
|
|
383
|
-
return { kind: "retry", reason: result };
|
|
384
|
-
if (result.kind === "collision" && index + 1 === attempts.length)
|
|
385
|
-
return { kind: "retry", reason: result };
|
|
386
|
-
if (result.kind === "redecide")
|
|
387
|
-
continue;
|
|
388
|
-
}
|
|
389
|
-
if (first === null)
|
|
390
|
-
return { kind: "retry", reason: { kind: "exhausted" } };
|
|
391
|
-
return await completeDelivery(input, first);
|
|
392
|
-
}
|
|
393
|
-
export async function abandonOperation(input) {
|
|
394
|
-
return complete(await admitIntent(input.channel, input.scope, {
|
|
395
|
-
contractId: input.contractId,
|
|
396
|
-
...(input.actor === undefined ? {} : { actor: input.actor }),
|
|
397
|
-
at: timestamp(),
|
|
398
|
-
...(input.note === undefined ? {} : { note: input.note }),
|
|
399
|
-
}, decideAbandon, {
|
|
400
|
-
...(input.decorateOffer === undefined ? {} : { decorateOffer: input.decorateOffer }),
|
|
401
|
-
...(input.observationSelection === undefined ? {} : { observationSelection: input.observationSelection }),
|
|
402
|
-
}), undefined);
|
|
403
|
-
}
|
|
404
|
-
export async function arcOperation(input) {
|
|
405
|
-
return complete(await admitIntent(input.channel, input.scope, {
|
|
406
|
-
contractId: input.contractId,
|
|
407
|
-
...(input.actor === undefined ? {} : { actor: input.actor }),
|
|
408
|
-
at: timestamp(),
|
|
409
|
-
data: input.chapter,
|
|
410
|
-
}, decideArc), undefined);
|
|
411
|
-
}
|
|
412
|
-
function reviewValue(value, placement) {
|
|
413
|
-
return {
|
|
414
|
-
...(value.workspace === undefined ? {} : { workspace: value.workspace }),
|
|
415
|
-
...(placement === undefined ? {} : { placement }),
|
|
416
|
-
};
|
|
417
|
-
}
|
|
418
|
-
async function reviewAttempt(input, attempt) {
|
|
419
|
-
const decisionObservation = await observeContractsForAdmissionAt(input.scope, input.channel, [input.contractId]);
|
|
420
|
-
const state = contractState(decisionObservation.decision, input.contractId);
|
|
421
|
-
let preparation;
|
|
422
|
-
let workspace;
|
|
423
|
-
let tender;
|
|
424
|
-
if (state !== null) {
|
|
425
|
-
const prepared = await captureReviewableWorktree(input.scope, { contractId: state.id, coordinates: state.coordinates });
|
|
426
|
-
preparation = prepared.kind === "refused"
|
|
427
|
-
? { kind: "refused", refusal: prepared.refusal }
|
|
428
|
-
: {
|
|
429
|
-
kind: "prepared",
|
|
430
|
-
data: {
|
|
431
|
-
gate: REVIEWED,
|
|
432
|
-
subject: dependencyKeySet([
|
|
433
|
-
{ kind: "document", value: state.terms.document.key },
|
|
434
|
-
{ kind: "change", value: prepared.data.changeId },
|
|
435
|
-
]),
|
|
436
|
-
verdict: input.verdict,
|
|
437
|
-
...(input.summary === undefined ? {} : { summary: input.summary }),
|
|
438
|
-
},
|
|
439
|
-
};
|
|
440
|
-
if (prepared.kind === "prepared") {
|
|
441
|
-
workspace = prepared.data.workspace;
|
|
442
|
-
tender = prepared.data.tender;
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
const decisionInput = {
|
|
446
|
-
contractId: input.contractId,
|
|
447
|
-
...(input.actor === undefined ? {} : { actor: input.actor }),
|
|
448
|
-
at: timestamp(),
|
|
449
|
-
...(preparation === undefined ? {} : { preparation }),
|
|
450
|
-
};
|
|
451
|
-
const decision = decideAttestation({ input: decisionInput, attempt, observation: decisionObservation.decision });
|
|
452
|
-
if (decision.kind === "refused")
|
|
453
|
-
return { kind: "refused", refusal: decision.refusal };
|
|
454
|
-
const admitted = await admitDecidedOffer({
|
|
455
|
-
channel: input.channel,
|
|
456
|
-
repository: input.scope,
|
|
457
|
-
decisionObservation,
|
|
458
|
-
attempt,
|
|
459
|
-
offer: decision.offer,
|
|
460
|
-
primaryContract: input.contractId,
|
|
461
|
-
});
|
|
462
|
-
if (admitted.kind === "accepted")
|
|
463
|
-
return {
|
|
464
|
-
...admitted,
|
|
465
|
-
value: {
|
|
466
|
-
...(workspace === undefined ? {} : { workspace }),
|
|
467
|
-
...(tender === undefined ? {} : { tender }),
|
|
468
|
-
},
|
|
469
|
-
};
|
|
470
|
-
return admitted;
|
|
471
|
-
}
|
|
472
|
-
export async function reviewOperation(input) {
|
|
473
|
-
const git = input.scope;
|
|
474
|
-
const attempts = mintAttempts({ entryCount: 1 });
|
|
475
|
-
let review = null;
|
|
476
|
-
for (let index = 0; index < attempts.length; index += 1) {
|
|
477
|
-
const result = await reviewAttempt(input, attempts[index]);
|
|
478
|
-
if (result.kind === "accepted" || result.kind === "refused") {
|
|
479
|
-
review = result;
|
|
480
|
-
break;
|
|
481
|
-
}
|
|
482
|
-
if (result.kind === "publication-failed")
|
|
483
|
-
return { kind: "retry", reason: result };
|
|
484
|
-
if (result.kind === "collision" && index + 1 === attempts.length)
|
|
485
|
-
return { kind: "retry", reason: result };
|
|
486
|
-
}
|
|
487
|
-
if (review === null)
|
|
488
|
-
return { kind: "retry", reason: { kind: "exhausted" } };
|
|
489
|
-
if (review.kind !== "accepted")
|
|
490
|
-
return review;
|
|
491
|
-
if (input.verdict !== "satisfied")
|
|
492
|
-
return admitted(review, reviewValue(review.value));
|
|
493
|
-
const target = review.state.coordinates.target;
|
|
494
|
-
const tender = review.value.tender;
|
|
495
|
-
const placement = await admitPlacement(input.channel, git, target, {
|
|
496
|
-
contractId: input.contractId,
|
|
497
|
-
...(input.actor === undefined ? {} : { actor: input.actor }),
|
|
498
|
-
at: timestamp(),
|
|
499
|
-
}, tender === undefined || target === undefined ? undefined : async () => {
|
|
500
|
-
const integration = await planIntegration(git, {
|
|
501
|
-
contractId: input.contractId,
|
|
502
|
-
coordinates: review.state.coordinates,
|
|
503
|
-
}, tender, false);
|
|
504
|
-
if (integration.kind === "refused" && integration.refusal.kind !== "target-missing") {
|
|
505
|
-
return { kind: "refused", refusal: integration.refusal };
|
|
506
|
-
}
|
|
507
|
-
return undefined;
|
|
508
|
-
});
|
|
509
|
-
const stopped = placementStop(placement);
|
|
510
|
-
const admission = placement.kind === "accepted" ? mergeAdmissions(review, placement) : review;
|
|
511
|
-
return admitted(admission, reviewValue(review.value, stopped));
|
|
512
|
-
}
|
|
513
|
-
async function auditWorkspace(repository, state) {
|
|
514
|
-
if (state.coordinates.workspace === "here") {
|
|
515
|
-
return { kind: "ready", answer: { kind: "here", path: repository.effectiveCwd } };
|
|
516
|
-
}
|
|
517
|
-
const appointed = await readManagedWorktreeAppointment(repository, state.id);
|
|
518
|
-
if (appointed.kind === "failed")
|
|
519
|
-
throw new Error(appointed.diagnostic);
|
|
520
|
-
if (appointed.kind === "unappointed")
|
|
521
|
-
return appointed;
|
|
522
|
-
return {
|
|
523
|
-
kind: "ready",
|
|
524
|
-
answer: { kind: "worktree", path: appointed.path },
|
|
525
|
-
appointment: appointed,
|
|
526
|
-
};
|
|
527
|
-
}
|
|
528
|
-
function auditDeliveryRelation(state, candidate) {
|
|
529
|
-
const recorded = state.delivery?.data.integration.changeId;
|
|
530
|
-
if (recorded === undefined)
|
|
531
|
-
return undefined;
|
|
532
|
-
return {
|
|
533
|
-
changeId: recorded,
|
|
534
|
-
relation: recorded === candidate.integration.changeId ? "identical" : "differs",
|
|
535
|
-
};
|
|
536
|
-
}
|
|
537
|
-
async function auditCandidateVerification(input, state, snapshot, definition) {
|
|
538
|
-
const verification = await verifyDelivery({
|
|
539
|
-
channel: input.channel,
|
|
540
|
-
repository: input.scope,
|
|
541
|
-
contractId: input.contractId,
|
|
542
|
-
...(input.actor === undefined ? {} : { actor: input.actor }),
|
|
543
|
-
at: timestamp(),
|
|
544
|
-
state,
|
|
545
|
-
snapshot,
|
|
546
|
-
environment: process.env,
|
|
547
|
-
...(input.signal === undefined ? {} : { signal: input.signal }),
|
|
548
|
-
verification: definition,
|
|
549
|
-
});
|
|
550
|
-
if (verification === null) {
|
|
551
|
-
throw new Error("audit verification preparation unexpectedly produced no attempt");
|
|
552
|
-
}
|
|
553
|
-
return unpackVerificationOutcome(verification);
|
|
554
|
-
}
|
|
555
|
-
function auditVerificationAnswer(verified) {
|
|
556
|
-
if (verified === undefined)
|
|
557
|
-
return { kind: "not-run" };
|
|
558
|
-
if (verified.stop !== undefined)
|
|
559
|
-
return { kind: "stopped", stop: verified.stop };
|
|
560
|
-
if (verified.counts === undefined) {
|
|
561
|
-
throw new Error("terminal Verification is missing producer counts");
|
|
562
|
-
}
|
|
563
|
-
return {
|
|
564
|
-
kind: verified.counts.verdict,
|
|
565
|
-
passed: verified.counts.passed,
|
|
566
|
-
total: verified.counts.total,
|
|
567
|
-
...(verified.counts.summary === undefined ? {} : { summary: verified.counts.summary }),
|
|
568
|
-
};
|
|
569
|
-
}
|
|
570
|
-
async function readyAuditCandidate(repository, candidate, workspace, showDiff) {
|
|
571
|
-
const predecessor = candidate.integration.predecessor;
|
|
572
|
-
const snapshot = candidate.integration.snapshot;
|
|
573
|
-
const scope = await readDeliveryScope(repository, predecessor, snapshot, showDiff);
|
|
574
|
-
const diff = showDiff ? await readDeliveryDiff(repository, predecessor, snapshot) : undefined;
|
|
575
|
-
return {
|
|
576
|
-
kind: "ready",
|
|
577
|
-
workspace,
|
|
578
|
-
identity: candidate,
|
|
579
|
-
scope,
|
|
580
|
-
...(diff === undefined || diff === null ? {} : { diff }),
|
|
581
|
-
};
|
|
582
|
-
}
|
|
583
|
-
async function auditTargetAnswer(repository, state, candidate) {
|
|
584
|
-
const target = state.coordinates.target;
|
|
585
|
-
if (target === undefined)
|
|
586
|
-
return { kind: "not-observed" };
|
|
587
|
-
return await adjudicateAuditTarget(repository, {
|
|
588
|
-
contractId: state.id,
|
|
589
|
-
coordinates: { ...state.coordinates, target },
|
|
590
|
-
predecessor: candidate.integration.predecessor,
|
|
591
|
-
candidate: candidate.integration.snapshot,
|
|
592
|
-
});
|
|
593
|
-
}
|
|
594
|
-
function blockedAudit(refusal) {
|
|
595
|
-
return {
|
|
596
|
-
candidate: { kind: "blocked", refusal },
|
|
597
|
-
verification: { kind: "not-run" },
|
|
598
|
-
target: { kind: "not-observed" },
|
|
599
|
-
};
|
|
600
|
-
}
|
|
601
|
-
function completedAudit(state, verified, value) {
|
|
602
|
-
const obligations = {
|
|
603
|
-
...(verified?.cleanup === undefined ? {} : { cleanup: verified.cleanup }),
|
|
604
|
-
...(verified?.leak === undefined ? {} : { leak: verified.leak }),
|
|
605
|
-
};
|
|
606
|
-
return verified?.admission === undefined
|
|
607
|
-
? accepted(state, [], value, undefined, obligations)
|
|
608
|
-
: {
|
|
609
|
-
...admitted(verified.admission, value),
|
|
610
|
-
...obligations,
|
|
611
|
-
};
|
|
612
|
-
}
|
|
613
|
-
export async function auditOperation(input) {
|
|
614
|
-
const observed = await observeContractsForAdmissionAt(input.scope, input.channel, [input.contractId]);
|
|
615
|
-
const state = activeContract(observed.decision, input.contractId);
|
|
616
|
-
if ("kind" in state)
|
|
617
|
-
return { kind: "refused", refusal: state };
|
|
618
|
-
const derivation = input.deriveDocument?.(state);
|
|
619
|
-
if (derivation === undefined || !documentIsCurrent(state, derivation.document)) {
|
|
620
|
-
return { kind: "refused", refusal: { kind: "document-moved", contractId: input.contractId } };
|
|
621
|
-
}
|
|
622
|
-
if (derivation.verification.kind === "refused") {
|
|
623
|
-
return { kind: "refused", refusal: derivation.verification.refusal };
|
|
624
|
-
}
|
|
625
|
-
const workspace = await auditWorkspace(input.scope, state);
|
|
626
|
-
if (workspace.kind === "unappointed") {
|
|
627
|
-
return accepted(state, [], blockedAudit({ kind: "worktree-missing", contractId: state.id }));
|
|
628
|
-
}
|
|
629
|
-
const prepared = await prepareDelivery(input.scope, {
|
|
630
|
-
contractId: state.id,
|
|
631
|
-
coordinates: state.coordinates,
|
|
632
|
-
...(workspace.appointment === undefined ? {} : { appointment: workspace.appointment }),
|
|
633
|
-
}, {
|
|
634
|
-
title: derivation.title,
|
|
635
|
-
document: derivation.bytes,
|
|
636
|
-
...(input.actor === undefined ? {} : { actor: input.actor }),
|
|
637
|
-
requireBranchesToBeUpToDate: input.requireBranchesToBeUpToDate ?? false,
|
|
638
|
-
includeDirty: input.includeDirty ?? false,
|
|
639
|
-
});
|
|
640
|
-
if (prepared.kind === "refused") {
|
|
641
|
-
return accepted(state, [], blockedAudit(prepared.refusal));
|
|
642
|
-
}
|
|
643
|
-
const verified = derivation.verification.data === null
|
|
644
|
-
? undefined
|
|
645
|
-
: await auditCandidateVerification(input, state, prepared.data.integration.snapshot, derivation.verification.data);
|
|
646
|
-
const delivery = auditDeliveryRelation(state, prepared.data);
|
|
647
|
-
const verification = auditVerificationAnswer(verified);
|
|
648
|
-
const value = {
|
|
649
|
-
candidate: await readyAuditCandidate(input.scope, prepared.data, workspace.answer, input.showDiff === true),
|
|
650
|
-
verification,
|
|
651
|
-
target: verification.kind === "stopped"
|
|
652
|
-
? { kind: "not-observed" }
|
|
653
|
-
: await auditTargetAnswer(input.scope, state, prepared.data),
|
|
654
|
-
...(delivery === undefined ? {} : { delivery }),
|
|
655
|
-
};
|
|
656
|
-
return completedAudit(state, verified, value);
|
|
657
|
-
}
|
|
658
|
-
export async function reconcileOperation(input) {
|
|
659
|
-
try {
|
|
660
|
-
const observation = await reconcile({
|
|
661
|
-
repository: input.scope,
|
|
662
|
-
channel: input.channel,
|
|
663
|
-
contractId: input.contractId,
|
|
664
|
-
hooks: input.hooks,
|
|
665
|
-
retryHooks: input.retryHooks,
|
|
666
|
-
...(input.retainTerminalWorktree === undefined ? {} : { retainTerminalWorktree: input.retainTerminalWorktree }),
|
|
667
|
-
...(input.place === undefined ? {} : { place: input.place }),
|
|
668
|
-
});
|
|
669
|
-
return { state: observation.state, report: observation.result };
|
|
670
|
-
}
|
|
671
|
-
catch (error) {
|
|
672
|
-
if (error instanceof AuthorityCorruptionError || error instanceof TypeError)
|
|
673
|
-
throw error;
|
|
674
|
-
return { state: null, report: reconcileObservationFailure(error) };
|
|
675
|
-
}
|
|
676
|
-
}
|
|
677
|
-
export async function worldContractStates(input) {
|
|
678
|
-
const observation = await withGitReadObservation(input.scope, input.channel, async (read) => await observeContractWorld(read));
|
|
679
|
-
return [...observation.contracts.values()].flatMap((value) => value.state === null ? [] : [value.state]);
|
|
680
|
-
}
|
|
681
|
-
export async function reconcileAllOperation(input) {
|
|
682
|
-
const git = input.scope;
|
|
683
|
-
const observation = await withGitReadObservation(input.scope, input.channel, async (read) => await observeContractWorld(read));
|
|
684
|
-
const contracts = (await reconcileBatch(git, input.channel, observation.contracts.keys(), {
|
|
685
|
-
hooks: input.hooks,
|
|
686
|
-
retryHooks: input.retryHooks,
|
|
687
|
-
retainTerminalWorktree: input.retainTerminalWorktree ?? false,
|
|
688
|
-
...(input.places === undefined ? {} : { places: input.places }),
|
|
689
|
-
})).map((item) => ({
|
|
690
|
-
contractId: item.contract,
|
|
691
|
-
state: item.state,
|
|
692
|
-
report: item.result,
|
|
693
|
-
}));
|
|
694
|
-
return { contracts };
|
|
68
|
+
if (state === null || state === undefined || state.delivery === null)
|
|
69
|
+
return null;
|
|
70
|
+
return state.currentIntegration === null
|
|
71
|
+
? state.delivery.data
|
|
72
|
+
: { ...state.delivery.data, integration: state.currentIntegration };
|
|
73
|
+
}
|
|
74
|
+
export async function deliveryDiffOperation(input) {
|
|
75
|
+
return await readDeliveryDiff(input.scope, input.integrationPredecessor, input.integrationSnapshot);
|
|
695
76
|
}
|