@astrosheep/keiyaku 4.1.1 → 4.1.2

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.
Files changed (58) hide show
  1. package/build/src/akuma/akuma-errors.d.ts +6 -0
  2. package/build/src/akuma/akuma-errors.js +9 -0
  3. package/build/src/akuma/akuma-handle.d.ts +39 -0
  4. package/build/src/akuma/akuma-handle.js +263 -0
  5. package/build/src/akuma/akuma-observe.d.ts +19 -0
  6. package/build/src/akuma/akuma-observe.js +74 -0
  7. package/build/src/akuma/akuma-product-symbols.d.ts +1 -0
  8. package/build/src/akuma/akuma-product-symbols.js +1 -0
  9. package/build/src/akuma/akuma-product.d.ts +18 -0
  10. package/build/src/akuma/akuma-product.js +154 -0
  11. package/build/src/akuma/akuma.d.ts +23 -70
  12. package/build/src/akuma/akuma.js +17 -433
  13. package/build/src/akuma/body-supervisor.d.ts +26 -0
  14. package/build/src/akuma/body-supervisor.js +89 -0
  15. package/build/src/akuma/body.d.ts +1 -1
  16. package/build/src/akuma/body.js +3 -2
  17. package/build/src/akuma/projection-read.d.ts +17 -0
  18. package/build/src/akuma/projection-read.js +135 -0
  19. package/build/src/akuma/projection.d.ts +1 -18
  20. package/build/src/akuma/projection.js +21 -155
  21. package/build/src/akuma/request-execution.d.ts +6 -0
  22. package/build/src/akuma/request-execution.js +86 -0
  23. package/build/src/akuma/request-serve.d.ts +12 -1
  24. package/build/src/akuma/request-serve.js +2 -102
  25. package/build/src/akuma/{body-turn.d.ts → turn-drive.d.ts} +2 -25
  26. package/build/src/akuma/{body-turn.js → turn-drive.js} +4 -99
  27. package/build/src/cli/commands/akuma.d.ts +0 -6
  28. package/build/src/cli/commands/akuma.js +1 -11
  29. package/build/src/cli/commands/contract-invoke.d.ts +25 -0
  30. package/build/src/cli/commands/contract-invoke.js +193 -0
  31. package/build/src/cli/commands/contract.d.ts +12 -0
  32. package/build/src/cli/commands/contract.js +229 -0
  33. package/build/src/cli/invoke.js +24 -184
  34. package/build/src/cli/parse.d.ts +1 -1
  35. package/build/src/cli/parse.js +8 -222
  36. package/build/src/cli/render/akuma-activity.d.ts +38 -0
  37. package/build/src/cli/render/akuma-activity.js +362 -0
  38. package/build/src/cli/render/akuma.d.ts +1 -1
  39. package/build/src/cli/render/akuma.js +14 -371
  40. package/build/src/cli/render/contract-history.d.ts +2 -0
  41. package/build/src/cli/render/contract-history.js +83 -0
  42. package/build/src/cli/render/contract.d.ts +1 -2
  43. package/build/src/cli/render/contract.js +1 -83
  44. package/build/src/git/reconcile.d.ts +8 -1
  45. package/build/src/git/reconcile.js +13 -301
  46. package/build/src/git/scratch.d.ts +8 -5
  47. package/build/src/git/scratch.js +29 -2
  48. package/build/src/git/terminal-reconcile.d.ts +21 -0
  49. package/build/src/git/terminal-reconcile.js +278 -0
  50. package/build/src/library/contract-bind.d.ts +26 -0
  51. package/build/src/library/contract-bind.js +106 -0
  52. package/build/src/library/contract-operations.d.ts +77 -0
  53. package/build/src/library/contract-operations.js +130 -0
  54. package/build/src/library/contract-types.d.ts +95 -0
  55. package/build/src/library/contract-types.js +1 -0
  56. package/build/src/library/contract.d.ts +11 -136
  57. package/build/src/library/contract.js +9 -222
  58. package/package.json +1 -1
@@ -0,0 +1,95 @@
1
+ import type { ContractId, JournalEntry, SnapshotId } from "../core/facts/types.js";
2
+ import type { ContractFileEffect, ContractFileLag } from "../contract-worktree.js";
3
+ import type { ReconcileReport as ProtocolReconcileReport } from "../protocol/reconcile.js";
4
+ import type { Dispatch } from "../dispatch/index.js";
5
+ import type { Gate, WorktreeHooks } from "./configuration.js";
6
+ import type { AmendRegionObservation, RegionObservation } from "./region.js";
7
+ import type { Repo } from "./repo.js";
8
+ import type { MutationResult } from "./mutation.js";
9
+ import type { SettlementReport } from "../settlement/settle.js";
10
+ import type { Keiyaku, AttestationVerdict } from "./contract.js";
11
+ import type { TaskId } from "../task/identity.js";
12
+ export type BindResult = Readonly<Omit<MutationResult<Keiyaku>, "value"> & {
13
+ keiyaku: Keiyaku;
14
+ } & RegionObservation>;
15
+ export type Fact = JournalEntry;
16
+ export type ContractHistoryEvent = Readonly<{
17
+ source: "journal";
18
+ fact: Fact;
19
+ }> | Readonly<{
20
+ source: "dispatch";
21
+ dispatch: Dispatch;
22
+ }>;
23
+ export type ContractHistory = Readonly<{
24
+ id: ContractId;
25
+ state: SnapshotId;
26
+ events: readonly ContractHistoryEvent[];
27
+ }>;
28
+ export type TopologyEffect = ProtocolReconcileReport["effects"][number] | ContractFileEffect;
29
+ export type Lag = ProtocolReconcileReport["lag"][number] | ContractFileLag;
30
+ export type AmendResult = Readonly<MutationResult<void> & {
31
+ documentDiff: string;
32
+ }> & AmendRegionObservation;
33
+ export type ReconcileReport = Readonly<{
34
+ effects: readonly (ProtocolReconcileReport["effects"][number] | ContractFileEffect)[];
35
+ lag: readonly (ProtocolReconcileReport["lag"][number] | ContractFileLag)[];
36
+ settlement: SettlementReport;
37
+ }>;
38
+ export type MarkdownBindInput = Readonly<{
39
+ repo: Repo;
40
+ markdown: string;
41
+ task?: TaskId;
42
+ target?: string;
43
+ workspace?: "worktree";
44
+ actor?: string;
45
+ after?: readonly ContractId[];
46
+ gates?: readonly Gate[];
47
+ hooks?: WorktreeHooks;
48
+ }>;
49
+ export type ForkBindInput = Readonly<{
50
+ repo: Repo;
51
+ forkOf: ContractId;
52
+ target?: string;
53
+ workspace?: "worktree";
54
+ actor?: string;
55
+ hooks?: WorktreeHooks;
56
+ }>;
57
+ export type BindInput = MarkdownBindInput | ForkBindInput;
58
+ type ActorOptions = Readonly<{
59
+ actor?: string;
60
+ hooks?: WorktreeHooks;
61
+ }>;
62
+ export type AmendInput = ActorOptions & Readonly<{
63
+ markdown?: string;
64
+ after?: readonly ContractId[];
65
+ gates?: readonly Gate[];
66
+ }>;
67
+ export type ArcInput = ActorOptions & Readonly<{
68
+ markdown: string;
69
+ }>;
70
+ export type ContractListInput = Readonly<{
71
+ repo: Repo;
72
+ }>;
73
+ export type ContractObservationInput = Readonly<{
74
+ repo: Repo;
75
+ id: ContractId;
76
+ }>;
77
+ export type KeiyakuOfInput = Readonly<{
78
+ repo: Repo;
79
+ id: ContractId;
80
+ }>;
81
+ export type ReviewInput = ActorOptions & Readonly<{
82
+ verdict: AttestationVerdict;
83
+ summary?: string;
84
+ }>;
85
+ export type AbandonInput = ActorOptions & Readonly<{
86
+ note?: string;
87
+ }>;
88
+ export type DeliverInput = ActorOptions & Readonly<{
89
+ message?: string;
90
+ requireBranchesToBeUpToDate?: boolean;
91
+ includeDirty?: boolean;
92
+ materializeConflict?: boolean;
93
+ signal?: AbortSignal;
94
+ }>;
95
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1,156 +1,31 @@
1
- import { type ContractFileEffect, type ContractFileLag } from "../contract-worktree.js";
2
- import { type AmendRegionObservation, type RegionObservation, type RegionOverlap } from "./region.js";
3
- import { type Gate, type WorktreeHooks } from "./configuration.js";
4
- import { type ChangeId, type FactKind, type ContractId, type ContractState, type JournalEntry, type SnapshotId } from "../core/facts/types.js";
1
+ import { type RegionOverlap } from "./region.js";
2
+ import { type ChangeId, type FactKind, type ContractId, type ContractState, type SnapshotId } from "../core/facts/types.js";
5
3
  export { AuthorityCorruptionError } from "../core/facts/errors.js";
6
4
  import { type PlacementStop, type RepositoryScope, type VerificationStop, type DeliveryPreparationRefusal } from "../protocol/operations.js";
7
5
  import type { ContractBoard, ContractDisposition, ContractGateCurrent, ContractGateReport, ContractObservation, ContractPhase, ContractRow, AfterEndpointObservation, ContractAfterEdge, ContractDependent, ContractWorkspaceObservation } from "../protocol/read/status.js";
8
6
  import type { AuditReport } from "../protocol/audit.js";
9
- import { type IntegrationConflictMaterialized, type VerificationReuse } from "../protocol/deliver.js";
10
- import type { ReconcileReport as ProtocolReconcileReport } from "../protocol/reconcile.js";
11
- import { type ReviewValue } from "../protocol/review.js";
12
- import { type Dispatch } from "../dispatch/index.js";
13
- import { type SettlementReport } from "../settlement/settle.js";
7
+ import type { IntegrationConflictMaterialized, VerificationReuse } from "../protocol/deliver.js";
14
8
  import type { TaskId } from "../task/identity.js";
15
- import { Repo, type ReconcileInput } from "./repo.js";
9
+ import { type ReconcileInput } from "./repo.js";
16
10
  import { type AuditInput } from "./audit.js";
17
- import { Delivery, type DeliveryValue } from "./delivery.js";
11
+ import { Delivery } from "./delivery.js";
18
12
  import { type ContinuationReport } from "./continuation.js";
19
13
  import { type MutationResult } from "./mutation.js";
14
+ import type { AbandonInput, AmendInput, AmendResult, ArcInput, BindInput, BindResult, ContractListInput, ContractObservationInput, DeliverInput, ForkBindInput, KeiyakuOfInput, MarkdownBindInput, ReconcileReport, ReviewInput, ContractHistory, ContractHistoryEvent, Fact, Lag, TopologyEffect } from "./contract-types.js";
15
+ import { type AttestationVerdict as OperationAttestationVerdict, type Review as OperationReview } from "./contract-operations.js";
20
16
  import { KeiyakuRetry, type KeiyakuRefusal, type KeiyakuRetryReason } from "./refusal.js";
21
17
  export { KeiyakuRefused } from "./refusal.js";
22
18
  export { KeiyakuRetry, type KeiyakuRefusal, type KeiyakuRetryReason };
19
+ export { executeForwardedDeliver, executeForwardedReview } from "./contract-operations.js";
23
20
  export { gatesFrom, requireBranchesToBeUpToDateFrom, SettingsError } from "./configuration.js";
24
21
  export type { Gate, GatesFromInput, HookCommand, RequireBranchesToBeUpToDateFromInput, WorktreeHooks, } from "./configuration.js";
25
- export type { AuditInput, AuditReport, ChangeId, ContinuationReport, ContractBoard, ContractDisposition, ContractGateCurrent, ContractGateReport, ContractAfterEdge, ContractId, ContractDependent, ContractObservation, ContractPhase, ContractRow, ContractState, ContractWorkspaceObservation, DeliveryPreparationRefusal, FactKind, IntegrationConflictMaterialized, MutationResult, PlacementStop, RegionOverlap, SnapshotId, TaskId, VerificationReuse, VerificationStop, };
22
+ export type { AbandonInput, AmendInput, AmendResult, ArcInput, AuditInput, AuditReport, ChangeId, ContinuationReport, ContractBoard, ContractDisposition, ContractGateCurrent, ContractGateReport, ContractAfterEdge, ContractId, ContractHistory, ContractHistoryEvent, ContractDependent, ContractObservation, ContractPhase, ContractRow, ContractState, ContractWorkspaceObservation, BindInput, BindResult, ContractListInput, ContractObservationInput, DeliverInput, ForkBindInput, KeiyakuOfInput, MarkdownBindInput, ReconcileReport, ReviewInput, DeliveryPreparationRefusal, Fact, FactKind, IntegrationConflictMaterialized, Lag, MutationResult, PlacementStop, RegionOverlap, SnapshotId, TaskId, TopologyEffect, VerificationReuse, VerificationStop, };
26
23
  export type { AfterEndpointObservation };
27
- export type Fact = JournalEntry;
28
- export type ContractHistoryEvent = Readonly<{
29
- source: "journal";
30
- fact: Fact;
31
- }> | Readonly<{
32
- source: "dispatch";
33
- dispatch: Dispatch;
34
- }>;
35
- export type ContractHistory = Readonly<{
36
- id: ContractId;
37
- state: SnapshotId;
38
- events: readonly ContractHistoryEvent[];
39
- }>;
40
24
  export type ActorId = string;
41
- export type AttestationVerdict = "satisfied" | "unsatisfied";
42
- export type Review = ReviewValue & Readonly<{
43
- continuation?: ContinuationReport;
44
- }>;
45
- export type TopologyEffect = ProtocolReconcileReport["effects"][number] | ContractFileEffect;
46
- export type Lag = ProtocolReconcileReport["lag"][number] | ContractFileLag;
25
+ export type AttestationVerdict = OperationAttestationVerdict;
26
+ export type Review = OperationReview;
47
27
  export { Delivery };
48
- export type BindResult = Readonly<Omit<MutationResult<Keiyaku>, "value"> & {
49
- keiyaku: Keiyaku;
50
- } & RegionObservation>;
51
- export type AmendResult = Readonly<MutationResult<void> & {
52
- documentDiff: string;
53
- }> & AmendRegionObservation;
54
- export type ReconcileReport = Readonly<{
55
- effects: readonly TopologyEffect[];
56
- lag: readonly Lag[];
57
- settlement: SettlementReport;
58
- }>;
59
28
  export type { SettlementAction, SettlementLag, SettlementReport } from "../settlement/settle.js";
60
- export type MarkdownBindInput = Readonly<{
61
- repo: Repo;
62
- markdown: string;
63
- task?: TaskId;
64
- target?: string;
65
- workspace?: "worktree";
66
- actor?: ActorId;
67
- after?: readonly ContractId[];
68
- gates?: readonly Gate[];
69
- hooks?: WorktreeHooks;
70
- }>;
71
- export type ForkBindInput = Readonly<{
72
- repo: Repo;
73
- forkOf: ContractId;
74
- target?: string;
75
- workspace?: "worktree";
76
- actor?: ActorId;
77
- hooks?: WorktreeHooks;
78
- }>;
79
- export type BindInput = MarkdownBindInput | ForkBindInput;
80
- type ActorOptions = Readonly<{
81
- actor?: ActorId;
82
- hooks?: WorktreeHooks;
83
- }>;
84
- export type AmendInput = ActorOptions & Readonly<{
85
- markdown?: string;
86
- after?: readonly ContractId[];
87
- gates?: readonly Gate[];
88
- }>;
89
- export type ArcInput = ActorOptions & Readonly<{
90
- markdown: string;
91
- }>;
92
- export type ContractListInput = Readonly<{
93
- repo: Repo;
94
- }>;
95
- export type ContractObservationInput = Readonly<{
96
- repo: Repo;
97
- id: ContractId;
98
- }>;
99
- export type KeiyakuOfInput = Readonly<{
100
- repo: Repo;
101
- id: ContractId;
102
- }>;
103
- export type ReviewInput = ActorOptions & Readonly<{
104
- verdict: AttestationVerdict;
105
- summary?: string;
106
- }>;
107
- export type AbandonInput = ActorOptions & Readonly<{
108
- note?: string;
109
- }>;
110
- export type DeliverInput = ActorOptions & Readonly<{
111
- message?: string;
112
- requireBranchesToBeUpToDate?: boolean;
113
- includeDirty?: boolean;
114
- materializeConflict?: boolean;
115
- signal?: AbortSignal;
116
- }>;
117
- type ForwardedMutationReceipt<Value> = Readonly<{
118
- kind: "accepted";
119
- result: MutationResult<Value>;
120
- }> | Readonly<{
121
- kind: "refused";
122
- refusal: KeiyakuRefusal;
123
- }> | Readonly<{
124
- kind: "retry";
125
- reason: KeiyakuRetryReason;
126
- }>;
127
- type ForwardedDeliveryReceipt = ForwardedMutationReceipt<DeliveryValue> | IntegrationConflictMaterialized;
128
- type ForwardedReviewReceipt = ForwardedMutationReceipt<Review>;
129
- export declare function executeForwardedDeliver(input: Readonly<{
130
- repo: Repo;
131
- contractId: string;
132
- requester: string;
133
- message?: string;
134
- includeDirty: boolean;
135
- materializeConflict: boolean;
136
- requireBranchesToBeUpToDate: boolean;
137
- hooks: WorktreeHooks;
138
- signal?: AbortSignal;
139
- }>): Promise<Readonly<{
140
- result: ForwardedDeliveryReceipt;
141
- deliveryFactId?: string;
142
- }>>;
143
- export declare function executeForwardedReview(input: Readonly<{
144
- repo: Repo;
145
- contractId: string;
146
- requester: string;
147
- verdict: AttestationVerdict;
148
- summary?: string;
149
- hooks: WorktreeHooks;
150
- }>): Promise<Readonly<{
151
- result: ForwardedReviewReceipt;
152
- reviewFactId?: string;
153
- }>>;
154
29
  export declare class KeiyakuHandle {
155
30
  private readonly id;
156
31
  private readonly scope;
@@ -3,8 +3,8 @@ import { applyAmendDocument } from "../body/amend.js";
3
3
  import { decodeArcDocument } from "../body/arc.js";
4
4
  import { decodeContractDocument } from "../body/decode.js";
5
5
  import { renderContractGuidance } from "../contract-worktree.js";
6
- import { actorOption, contractTerms, documentDerivation, normalizedGates, normalizedList, optionalBoolean, optionalNonblank, optionalSignal, requireInput, requireMarkdown, taskOption, } from "./input.js";
7
- import { observeChangedRegion, observeRegion, } from "./region.js";
6
+ import { actorOption, contractTerms, documentDerivation, normalizedGates, normalizedList, optionalBoolean, optionalNonblank, optionalSignal, requireInput, requireMarkdown, } from "./input.js";
7
+ import { observeChangedRegion } from "./region.js";
8
8
  import { worktreeHooksOption } from "./configuration.js";
9
9
  import { contractId, } from "../core/facts/types.js";
10
10
  export { AuthorityCorruptionError } from "../core/facts/errors.js";
@@ -12,151 +12,25 @@ import { contractObservationOperation, contractsOperation, deliveryDiffOperation
12
12
  import { abandonOperation } from "../protocol/abandon.js";
13
13
  import { amendOperation } from "../protocol/amend.js";
14
14
  import { arcOperation } from "../protocol/arc.js";
15
- import { deliverOperation } from "../protocol/deliver.js";
16
- import { reviewOperation } from "../protocol/review.js";
17
15
  import { readDispatchesAt } from "../dispatch/index.js";
18
16
  import { mintSnapshotId } from "../git/identity.js";
19
17
  import { observeContractsForAdmissionInObservationAt } from "../git/observe.js";
20
18
  import { withGitDecodeChannel, withGitReadObservation } from "../git/read-observation.js";
21
19
  import { releaseTaskHolder, releaseTaskHolderWithFence, taskHolderObservationSelection } from "../settlement/holder.js";
22
20
  import { reconcileInput, scopeForRepo } from "./repo.js";
23
- import { injectedBodyRequests, requestBodyDeliver, requestBodyReview, } from "../akuma/requests.js";
21
+ import { injectedBodyRequests, requestBodyDeliver, requestBodyReview } from "../akuma/requests.js";
24
22
  import { auditContract } from "./audit.js";
25
23
  import { Delivery, deliveryHandle } from "./delivery.js";
26
- import { continueAcceptedCompletion } from "./continuation.js";
27
24
  import { completionInput, completeHolderMutation, completeMutation } from "./mutation.js";
28
25
  import { completeReconcile } from "./reconcile.js";
29
- import { admitForkBindWithAppointment, prepareMarkdownBind } from "./bind.js";
30
- import { forwardedMutationFailure, KeiyakuRefused, KeiyakuRetry, requireAccepted, } from "./refusal.js";
26
+ import { bindFromCli as bindFromCliImplementation, bindKeiyaku as bindKeiyakuImplementation } from "./contract-bind.js";
27
+ import { executeLocalDelivery, executeLocalReview, forwardedReceipt, requireForwarded, } from "./contract-operations.js";
28
+ import { KeiyakuRefused, KeiyakuRetry, requireAccepted, } from "./refusal.js";
31
29
  export { KeiyakuRefused } from "./refusal.js";
32
30
  export { KeiyakuRetry };
31
+ export { executeForwardedDeliver, executeForwardedReview } from "./contract-operations.js";
33
32
  export { gatesFrom, requireBranchesToBeUpToDateFrom, SettingsError } from "./configuration.js";
34
33
  export { Delivery };
35
- function derivedDocument(state) {
36
- return documentDerivation(decodeContractDocument(state.terms.document.bytes), state.terms.gates, state.id);
37
- }
38
- function operationContext(scope, channel, contractId) {
39
- return {
40
- scope,
41
- channel,
42
- contractId,
43
- deriveDocument: derivedDocument,
44
- };
45
- }
46
- async function executeLocalDelivery(input) {
47
- return withGitDecodeChannel(input.scope, async (channel) => {
48
- const operation = operationContext(input.scope, channel, input.contractId);
49
- const outcome = await deliverOperation({
50
- ...operation,
51
- ...(input.actor === undefined ? {} : { actor: input.actor }),
52
- ...(input.message === undefined ? {} : { message: input.message }),
53
- requireBranchesToBeUpToDate: input.requireBranchesToBeUpToDate,
54
- includeDirty: input.includeDirty,
55
- materializeConflict: input.materializeConflict,
56
- ...(input.signal === undefined ? {} : { signal: input.signal }),
57
- });
58
- if (outcome.kind === "integration-conflict-materialized")
59
- return outcome;
60
- const accepted = requireAccepted(outcome);
61
- const continued = await continueAcceptedCompletion({
62
- ...operation,
63
- accepted,
64
- ...(input.actor === undefined ? {} : { actor: input.actor }),
65
- ...(input.signal === undefined ? {} : { signal: input.signal }),
66
- });
67
- return completeMutation({
68
- ...completionInput(input.scope, channel, input.contractId, (delivery) => delivery, input.hooks),
69
- accepted: continued,
70
- });
71
- });
72
- }
73
- async function executeLocalReview(input) {
74
- return withGitDecodeChannel(input.scope, async (channel) => {
75
- const operation = operationContext(input.scope, channel, input.contractId);
76
- const accepted = requireAccepted(await reviewOperation({
77
- ...operation,
78
- verdict: input.verdict,
79
- ...(input.summary === undefined ? {} : { summary: input.summary }),
80
- ...(input.actor === undefined ? {} : { actor: input.actor }),
81
- }));
82
- const continued = await continueAcceptedCompletion({
83
- ...operation,
84
- accepted,
85
- ...(input.actor === undefined ? {} : { actor: input.actor }),
86
- });
87
- return completeMutation({
88
- ...completionInput(input.scope, channel, input.contractId, (review) => review, input.hooks),
89
- accepted: continued,
90
- });
91
- });
92
- }
93
- function forwardedReceipt(outcome, action) {
94
- if (outcome.kind === "failed") {
95
- throw new Error(outcome.failure.kind === "failed"
96
- ? outcome.failure.diagnostic
97
- : `Unexpected Akuma target failure for ${action}: ${outcome.failure.id}`);
98
- }
99
- return outcome.result;
100
- }
101
- function requireForwarded(receipt) {
102
- if (receipt.kind === "refused")
103
- throw new KeiyakuRefused(receipt.refusal);
104
- if (receipt.kind === "retry")
105
- throw new KeiyakuRetry(receipt.reason);
106
- return receipt.kind === "accepted" ? receipt.result : receipt;
107
- }
108
- export async function executeForwardedDeliver(input) {
109
- const id = contractId(input.contractId);
110
- const actor = actorOption(input.requester).actor;
111
- const message = optionalNonblank(input.message, "deliver message");
112
- try {
113
- const result = await executeLocalDelivery({
114
- scope: scopeForRepo(input.repo),
115
- contractId: id,
116
- ...(actor === undefined ? {} : { actor }),
117
- ...(message === undefined ? {} : { message }),
118
- requireBranchesToBeUpToDate: input.requireBranchesToBeUpToDate,
119
- includeDirty: input.includeDirty,
120
- materializeConflict: input.materializeConflict,
121
- ...(input.signal === undefined ? {} : { signal: input.signal }),
122
- hooks: input.hooks,
123
- });
124
- if (!("facts" in result))
125
- return { result };
126
- const delivery = result.facts.find((fact) => fact.kind === "deliver");
127
- if (delivery === undefined)
128
- throw new Error("accepted delivery is missing its journal fact");
129
- return { result: { kind: "accepted", result }, deliveryFactId: delivery.entry };
130
- }
131
- catch (error) {
132
- return forwardedMutationFailure(error);
133
- }
134
- }
135
- export async function executeForwardedReview(input) {
136
- const id = contractId(input.contractId);
137
- const actor = actorOption(input.requester).actor;
138
- if (input.verdict !== "satisfied" && input.verdict !== "unsatisfied") {
139
- throw new TypeError("verdict must be satisfied or unsatisfied");
140
- }
141
- const summary = optionalNonblank(input.summary, "review summary");
142
- try {
143
- const result = await executeLocalReview({
144
- scope: scopeForRepo(input.repo),
145
- contractId: id,
146
- ...(actor === undefined ? {} : { actor }),
147
- verdict: input.verdict,
148
- ...(summary === undefined ? {} : { summary }),
149
- hooks: input.hooks,
150
- });
151
- const review = result.facts.find((fact) => fact.kind === "attestation");
152
- if (review === undefined)
153
- throw new Error("accepted review is missing its journal fact");
154
- return { result: { kind: "accepted", result }, reviewFactId: review.entry };
155
- }
156
- catch (error) {
157
- return forwardedMutationFailure(error);
158
- }
159
- }
160
34
  export class KeiyakuHandle {
161
35
  id;
162
36
  scope;
@@ -446,97 +320,10 @@ export async function observeKeiyaku(input) {
446
320
  }
447
321
  return withGitDecodeChannel(scope, (channel) => contractObservationOperation({ scope, channel, contractId: id }));
448
322
  }
449
- function acceptedBindResult(result, region) {
450
- const { facts, head, effects, lags, settlement } = result;
451
- return { facts, head, keiyaku: result.value, effects, lags, settlement, ...region };
452
- }
453
323
  export async function bindKeiyaku(input) {
454
- const values = requireInput(input, "Keiyaku.bind input");
455
- const hooks = worktreeHooksOption(values.hooks);
456
- const forkOf = values.forkOf;
457
- if (forkOf !== undefined) {
458
- for (const key of Object.keys(values)) {
459
- if (!["repo", "forkOf", "target", "workspace", "actor", "hooks"].includes(key)) {
460
- throw new TypeError(`fork bind input has unknown field: ${key}`);
461
- }
462
- }
463
- if (typeof forkOf !== "string")
464
- throw new TypeError("forkOf must be a ContractId");
465
- let sourceId;
466
- try {
467
- sourceId = contractId(forkOf);
468
- }
469
- catch (error) {
470
- throw new TypeError(error instanceof Error ? error.message : "forkOf must be a ContractId");
471
- }
472
- const sourceScope = scopeForRepo(values.repo);
473
- if ((values.workspace ?? "worktree") !== "worktree")
474
- throw new TypeError("workspace must be worktree");
475
- const target = values.target;
476
- if (target !== undefined && typeof target !== "string")
477
- throw new TypeError("target must be a string");
478
- const actor = actorOption(values.actor);
479
- return withGitDecodeChannel(sourceScope, async (channel) => {
480
- const fork = await admitForkBindWithAppointment({
481
- scope: sourceScope,
482
- channel,
483
- sourceId,
484
- ...(target === undefined ? {} : { target }),
485
- ...actor,
486
- });
487
- const admission = requireAccepted(fork.admission);
488
- const id = admission.value.contractId;
489
- const toHandle = ({ contractId: contract }) => new KeiyakuHandle(contract, sourceScope);
490
- const result = await completeMutation({
491
- ...completionInput(sourceScope, channel, id, toHandle, hooks),
492
- accepted: admission,
493
- });
494
- return acceptedBindResult(result, await observeRegion(sourceScope, channel, id, fork.document.region));
495
- });
496
- }
497
- return bindMarkdownFromValues(values, "targetless");
324
+ return bindKeiyakuImplementation(input, (id, scope) => new KeiyakuHandle(id, scope));
498
325
  }
499
326
  /** Internal CLI composition; not exported from the package root. */
500
327
  export async function bindFromCli(input) {
501
- const values = requireInput(input, "Keiyaku.bind input");
502
- return values.forkOf !== undefined ? bindKeiyaku(input) : bindMarkdownFromValues(values, "current-branch");
503
- }
504
- async function bindMarkdownFromValues(values, omittedTarget) {
505
- const hooks = worktreeHooksOption(values.hooks);
506
- const scope = scopeForRepo(values.repo);
507
- const task = taskOption(values.task);
508
- const document = decodeContractDocument(requireMarkdown(values.markdown));
509
- if ((values.workspace ?? "worktree") !== "worktree")
510
- throw new TypeError("workspace must be worktree");
511
- const target = values.target;
512
- if (target !== undefined && typeof target !== "string")
513
- throw new TypeError("target must be a string");
514
- const actor = actorOption(values.actor);
515
- const gates = normalizedGates(values.gates);
516
- const after = normalizedList(values.after, "after", contractId);
517
- const targetSelection = target !== undefined ? { kind: "explicit", target } : { kind: omittedTarget };
518
- return withGitDecodeChannel(scope, async (channel) => {
519
- const admission = await prepareMarkdownBind({
520
- scope,
521
- channel,
522
- document,
523
- gates,
524
- after,
525
- workspace: "worktree",
526
- targetSelection,
527
- ...(task === undefined ? {} : { task }),
528
- ...actor,
529
- });
530
- const accepted = requireAccepted(admission.admission === null ? admission.result : admission.admission.result);
531
- const id = accepted.value.contractId;
532
- const toHandle = ({ contractId: contract }) => new KeiyakuHandle(contract, scope);
533
- const result = admission.admission === null
534
- ? await completeMutation({ ...completionInput(scope, channel, id, toHandle, hooks), accepted })
535
- : await completeHolderMutation({
536
- completion: completionInput(scope, channel, id, toHandle, hooks),
537
- admission: admission.admission,
538
- requireAccepted,
539
- });
540
- return acceptedBindResult(result, await observeRegion(scope, channel, id, document.region));
541
- });
328
+ return bindFromCliImplementation(input, (id, scope) => new KeiyakuHandle(id, scope));
542
329
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astrosheep/keiyaku",
3
- "version": "4.1.1",
3
+ "version": "4.1.2",
4
4
  "files": [
5
5
  "build"
6
6
  ],