@astrosheep/keiyaku 4.6.32 → 4.6.34
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 +18 -7
- package/build/plugins/claude/skills/keiyaku-akuma/SKILL.md +18 -11
- package/build/plugins/claude/skills/keiyaku-babysit/SKILL.md +8 -6
- package/build/plugins/claude/skills/keiyaku-debt/SKILL.md +2 -1
- package/build/plugins/claude/skills/keiyaku-workflow/SKILL.md +2 -1
- package/build/plugins/codex/skills/keiyaku-akuma/SKILL.md +18 -11
- package/build/plugins/codex/skills/keiyaku-babysit/SKILL.md +8 -6
- package/build/plugins/codex/skills/keiyaku-debt/SKILL.md +2 -1
- package/build/plugins/codex/skills/keiyaku-workflow/SKILL.md +2 -1
- package/build/plugins/opencode/skills/keiyaku-akuma/SKILL.md +18 -11
- package/build/plugins/opencode/skills/keiyaku-babysit/SKILL.md +8 -6
- package/build/plugins/opencode/skills/keiyaku-debt/SKILL.md +2 -1
- package/build/plugins/opencode/skills/keiyaku-workflow/SKILL.md +2 -1
- package/build/plugins/pi/README.md +55 -97
- package/build/plugins/pi/keiyaku.ts +1 -142
- package/build/skills/keiyaku-akuma/SKILL.md +18 -11
- package/build/skills/keiyaku-babysit/SKILL.md +8 -6
- package/build/skills/keiyaku-debt/SKILL.md +2 -1
- package/build/skills/keiyaku-workflow/SKILL.md +2 -1
- package/build/src/akuma/akuma-instance.d.ts +11 -0
- package/build/src/akuma/akuma-instance.js +1 -2
- package/build/src/akuma/akuma-observe.d.ts +8 -0
- package/build/src/akuma/akuma-observe.js +81 -14
- package/build/src/akuma/akuma-owner.d.ts +1 -0
- package/build/src/akuma/akuma-owner.js +3 -5
- package/build/src/akuma/akuma-selection-execution.d.ts +82 -7
- package/build/src/akuma/akuma-selection-execution.js +26 -27
- package/build/src/akuma/akuma-wait.d.ts +155 -1
- package/build/src/akuma/akuma-wait.js +94 -34
- package/build/src/akuma/akuma.d.ts +17 -1
- package/build/src/akuma/akuma.js +37 -18
- package/build/src/akuma/body.js +13 -18
- package/build/src/akuma/call-initial-tell.d.ts +0 -1
- package/build/src/akuma/call-initial-tell.js +0 -1
- package/build/src/akuma/heart/activity-schema.d.ts +16 -0
- package/build/src/akuma/heart/activity-schema.js +7 -0
- package/build/src/akuma/heart/facts.d.ts +1 -0
- package/build/src/akuma/heart/facts.js +14 -0
- package/build/src/akuma/heart/index.d.ts +7 -1
- package/build/src/akuma/heart/index.js +35 -9
- package/build/src/akuma/heart/rows.d.ts +1 -0
- package/build/src/akuma/heart/rows.js +4 -0
- package/build/src/akuma/heart/timeline.js +4 -4
- package/build/src/akuma/lineage-cache.d.ts +7 -2
- package/build/src/akuma/lineage-cache.js +48 -24
- package/build/src/akuma/projection-read.d.ts +4 -2
- package/build/src/akuma/projection-read.js +25 -23
- package/build/src/akuma/projection.d.ts +94 -2
- package/build/src/akuma/projection.js +47 -47
- package/build/src/akuma/provider.d.ts +2 -2
- package/build/src/akuma/provider.js +27 -20
- package/build/src/akuma/providers/acp/core.js +2 -5
- package/build/src/akuma/providers/opencode-sdk/events.d.ts +2 -1
- package/build/src/akuma/providers/opencode-sdk/events.js +31 -1
- package/build/src/akuma/publication.js +3 -2
- package/build/src/akuma/selection-observation.d.ts +645 -0
- package/build/src/akuma/selection-observation.js +22 -7
- package/build/src/akuma/status-projection.d.ts +14 -1
- package/build/src/akuma/status-projection.js +40 -2
- package/build/src/akuma/turn-drive.js +21 -15
- package/build/src/body/amend.js +5 -17
- package/build/src/body/decode.js +11 -1
- package/build/src/body/envelope.d.ts +5 -1
- package/build/src/body/envelope.js +4 -2
- package/build/src/body/render.js +4 -6
- package/build/src/bounded-list.d.ts +8 -0
- package/build/src/bounded-list.js +10 -0
- package/build/src/cli/commands/akuma-grammar.d.ts +5 -8
- package/build/src/cli/commands/akuma-grammar.js +52 -77
- package/build/src/cli/commands/akuma.d.ts +1 -2
- package/build/src/cli/commands/akuma.js +12 -61
- package/build/src/cli/commands/contract-grammar.d.ts +1 -0
- package/build/src/cli/commands/contract-grammar.js +39 -42
- package/build/src/cli/commands/contract-help.d.ts +6 -5
- package/build/src/cli/commands/contract-help.js +21 -13
- package/build/src/cli/commands/contract.d.ts +3 -3
- package/build/src/cli/commands/contract.js +13 -9
- package/build/src/cli/commands/debt-grammar.js +2 -4
- package/build/src/cli/parse.d.ts +4 -10
- package/build/src/cli/parse.js +2 -5
- package/build/src/cli/render/akuma-activity.d.ts +12 -34
- package/build/src/cli/render/akuma-activity.js +99 -180
- package/build/src/cli/render/akuma.d.ts +5 -11
- package/build/src/cli/render/akuma.js +22 -30
- package/build/src/cli/render/catalog.js +4 -6
- package/build/src/cli/render/contract-history.d.ts +1 -3
- package/build/src/cli/render/contract-history.js +70 -49
- package/build/src/cli/render/contract-observation.d.ts +2 -1
- package/build/src/cli/render/contract-observation.js +25 -1
- package/build/src/cli/render/contract-wait.d.ts +2 -2
- package/build/src/cli/render/contract-wait.js +21 -17
- package/build/src/cli/render/contract.js +12 -9
- package/build/src/cli/render/debt.js +1 -2
- package/build/src/cli/render/execution-progress.js +1 -3
- package/build/src/cli/render/kanshi-akuma.d.ts +4 -3
- package/build/src/cli/render/kanshi-akuma.js +27 -23
- package/build/src/cli/render/kanshi.js +45 -60
- package/build/src/cli/render/receipt.d.ts +1 -1
- package/build/src/cli/render/receipt.js +33 -28
- package/build/src/cli/render/reconcile.js +2 -5
- package/build/src/cli/render/refusal.js +3 -6
- package/build/src/cli/render/terminal.d.ts +2 -4
- package/build/src/cli/render/terminal.js +10 -17
- package/build/src/cli/render/verbs.d.ts +1 -0
- package/build/src/cli/render/verbs.js +39 -34
- package/build/src/cli/runtime.js +12 -32
- package/build/src/core/facts/codec.js +7 -2
- package/build/src/core/facts/eligibility.d.ts +4 -4
- package/build/src/core/facts/eligibility.js +11 -0
- package/build/src/core/facts/fold.js +9 -5
- package/build/src/core/facts/gate.d.ts +5 -1
- package/build/src/core/facts/gate.js +14 -10
- package/build/src/core/facts/types.d.ts +5 -1
- package/build/src/core/facts/types.js +7 -0
- package/build/src/core/subject.d.ts +4 -1
- package/build/src/core/subject.js +10 -2
- package/build/src/core/verbs/amend.d.ts +15 -4
- package/build/src/core/verbs/amend.js +19 -9
- package/build/src/debt/board.d.ts +2 -1
- package/build/src/debt/board.js +3 -3
- package/build/src/debt/catalog.js +2 -1
- package/build/src/debt/document.d.ts +1 -0
- package/build/src/debt/document.js +3 -0
- package/build/src/debt/index.d.ts +2 -2
- package/build/src/debt/index.js +9 -14
- package/build/src/debt/input.d.ts +2 -1
- package/build/src/debt/input.js +6 -4
- package/build/src/debt/operations.d.ts +2 -1
- package/build/src/dispatch/index.d.ts +0 -17
- package/build/src/dispatch/index.js +1 -10
- package/build/src/git/identity.js +16 -45
- package/build/src/git/nuke.js +13 -23
- package/build/src/git/observe.d.ts +7 -3
- package/build/src/git/observe.js +29 -26
- package/build/src/git/process.js +11 -18
- package/build/src/git/read-observation.d.ts +5 -4
- package/build/src/git/repository.d.ts +2 -0
- package/build/src/git/repository.js +13 -1
- package/build/src/git/scratch.js +2 -14
- package/build/src/git/terminal-reconcile.js +1 -13
- package/build/src/history.d.ts +26 -0
- package/build/src/history.js +43 -0
- package/build/src/index.d.ts +6 -3
- package/build/src/kanshi/counts.d.ts +15 -1
- package/build/src/kanshi/counts.js +14 -3
- package/build/src/kanshi/index.d.ts +3 -4
- package/build/src/kanshi/index.js +2 -3
- package/build/src/kanshi/read.d.ts +21 -0
- package/build/src/kanshi/read.js +7 -3
- package/build/src/kanshi/report.d.ts +94 -0
- package/build/src/library/address.d.ts +12 -5
- package/build/src/library/address.js +18 -32
- package/build/src/library/akuma-creation.d.ts +39 -0
- package/build/src/library/akuma-creation.js +3 -9
- package/build/src/library/akumas.d.ts +5 -1
- package/build/src/library/akumas.js +11 -5
- package/build/src/library/continuation.d.ts +10 -0
- package/build/src/library/contract-composition.js +10 -10
- package/build/src/library/contract-creation.js +12 -13
- package/build/src/library/contract-outcomes.d.ts +72 -1
- package/build/src/library/contract-outcomes.js +1 -0
- package/build/src/library/contract-types.d.ts +233 -25
- package/build/src/library/contract-types.js +32 -12
- package/build/src/library/contract-wait.d.ts +212 -0
- package/build/src/library/contract-wait.js +65 -49
- package/build/src/library/delivery.d.ts +25 -0
- package/build/src/library/input.d.ts +8 -26
- package/build/src/library/input.js +17 -12
- package/build/src/library/kei.js +167 -90
- package/build/src/library/keiyaku-attribution.d.ts +1 -1
- package/build/src/library/keiyaku-attribution.js +3 -1
- package/build/src/library/keiyaku-classify.js +8 -4
- package/build/src/library/keiyaku-debt.d.ts +8 -7
- package/build/src/library/keiyaku-debt.js +1 -2
- package/build/src/library/keiyaku-identity.d.ts +4 -3
- package/build/src/library/keiyaku-identity.js +35 -7
- package/build/src/library/keiyaku-verbs.d.ts +974 -1409
- package/build/src/library/keiyaku-verbs.js +154 -161
- package/build/src/library/keiyaku-wait.d.ts +753 -0
- package/build/src/library/keiyaku-wait.js +230 -0
- package/build/src/library/keiyaku.d.ts +3110 -29
- package/build/src/library/keiyaku.js +342 -438
- package/build/src/library/model-tools.d.ts +754 -0
- package/build/src/library/model-tools.js +362 -0
- package/build/src/library/outcome.js +5 -6
- package/build/src/library/refusal.d.ts +25 -1
- package/build/src/library/refusal.js +4 -5
- package/build/src/library/selection.d.ts +18 -5
- package/build/src/library/selection.js +11 -5
- package/build/src/mcp/adapter.d.ts +0 -6
- package/build/src/mcp/adapter.js +11 -160
- package/build/src/mcp/description.d.ts +2 -0
- package/build/src/mcp/description.js +2 -0
- package/build/src/mcp/help.d.ts +1 -1
- package/build/src/mcp/help.js +10 -7
- package/build/src/pi/index.d.ts +5 -0
- package/build/src/pi/index.js +99 -0
- package/build/src/pi/status.d.ts +12 -0
- package/build/src/pi/status.js +140 -0
- package/build/src/protocol/amend.d.ts +14 -3
- package/build/src/protocol/amend.js +113 -46
- package/build/src/protocol/bind.d.ts +1 -1
- package/build/src/protocol/bind.js +5 -16
- package/build/src/protocol/completion.d.ts +30 -0
- package/build/src/protocol/completion.js +8 -5
- package/build/src/protocol/deliver.js +7 -20
- package/build/src/protocol/delivery-preview.d.ts +5 -0
- package/build/src/protocol/execution-observation.d.ts +8 -0
- package/build/src/protocol/intent.d.ts +1 -0
- package/build/src/protocol/intent.js +4 -1
- package/build/src/protocol/operations.d.ts +56 -16
- package/build/src/protocol/operations.js +18 -32
- package/build/src/protocol/placement.js +7 -1
- package/build/src/protocol/progress.js +0 -6
- package/build/src/protocol/read/status.d.ts +52 -4
- package/build/src/protocol/read/status.js +26 -22
- package/build/src/protocol/reintegrate.js +2 -2
- package/build/src/protocol/result-leaves.d.ts +56 -8
- package/build/src/protocol/result-leaves.js +11 -2
- package/build/src/protocol/run.js +1 -4
- package/build/src/protocol/verify.d.ts +10 -0
- package/build/src/protocol/verify.js +1 -0
- package/build/src/runtime/proc/windows-launch.exe +0 -0
- package/build/src/settlement/settle.js +19 -68
- package/package.json +7 -3
- package/plugins/paseo/plugin/index.server.ts +6 -2
- package/plugins/paseo/plugin/server/attach.ts +68 -48
- package/plugins/paseo/plugin/server/directory.ts +259 -0
- package/plugins/paseo/plugin/server/mirror-identity.ts +3 -32
- package/plugins/paseo/plugin/server/reopen.ts +52 -38
- package/plugins/pi/README.md +55 -97
- package/plugins/pi/keiyaku.ts +1 -142
- package/skills/keiyaku-akuma/SKILL.md +18 -11
- package/skills/keiyaku-babysit/SKILL.md +8 -6
- package/skills/keiyaku-debt/SKILL.md +2 -1
- package/skills/keiyaku-workflow/SKILL.md +2 -1
- package/build/plugins/pi/akuma-tools.ts +0 -283
- package/build/src/body/keys.d.ts +0 -4
- package/build/src/body/keys.js +0 -11
- package/build/src/kanshi/roster.d.ts +0 -2
- package/build/src/kanshi/roster.js +0 -2
- package/build/src/mcp/output.d.ts +0 -385
- package/build/src/mcp/output.js +0 -193
- package/plugins/pi/akuma-tools.ts +0 -283
package/build/src/cli/runtime.js
CHANGED
|
@@ -2,10 +2,10 @@ import { resolve } from "node:path";
|
|
|
2
2
|
import { AkumaNotBornError, AkumaObservationError } from "../akuma/akuma-errors.js";
|
|
3
3
|
import { AkumaNameError, Keiyaku } from "../index.js";
|
|
4
4
|
import { errorCategory } from "../errors.js";
|
|
5
|
-
import { AkumaAddressError, AkumaWorldScopeError
|
|
5
|
+
import { AkumaAddressError, AkumaWorldScopeError } from "../library/address.js";
|
|
6
6
|
import { projectFailure, KeiyakuError } from "../library/outcome.js";
|
|
7
7
|
import { classifyVerb } from "../library/keiyaku-verbs.js";
|
|
8
|
-
import { acquireAkumaRequest,
|
|
8
|
+
import { acquireAkumaRequest, runAsk, runAkumaHistory } from "./commands/akuma.js";
|
|
9
9
|
import { acquireContractRequest, admitBindMarkdown, runContractRequest } from "./commands/contract.js";
|
|
10
10
|
import { installOutcome, installHarnesses, renderInstallText } from "./commands/install.js";
|
|
11
11
|
import { runDebtCommand } from "./commands/debt.js";
|
|
@@ -30,10 +30,6 @@ function memoized(reader) {
|
|
|
30
30
|
let value;
|
|
31
31
|
return () => (value ??= reader());
|
|
32
32
|
}
|
|
33
|
-
function homeFromEnvironment(environment) {
|
|
34
|
-
const mapped = environment.KEIYAKU_HOME?.trim();
|
|
35
|
-
return mapped === undefined || mapped.length === 0 ? undefined : mapped;
|
|
36
|
-
}
|
|
37
33
|
/** Builds the one live progress observer for an invocation; the leaf owns when it finishes. */
|
|
38
34
|
export async function writeExecutionProgress(stream = process.stderr) {
|
|
39
35
|
const terminal = stream;
|
|
@@ -155,14 +151,14 @@ function invocationCoordinates(invocation, input, environment) {
|
|
|
155
151
|
async function runCommand(invocation, input) {
|
|
156
152
|
const command = invocation.command;
|
|
157
153
|
const environment = { ...(input.environment ?? process.env) };
|
|
158
|
-
const home =
|
|
154
|
+
const home = environment.KEIYAKU_HOME?.trim() || undefined;
|
|
159
155
|
const cancellation = cliCancellation(input.signal);
|
|
160
156
|
let progress;
|
|
161
157
|
try {
|
|
162
158
|
assertExplicitRepoUse(command, invocation.repo);
|
|
163
159
|
const runtime = {
|
|
164
160
|
environment,
|
|
165
|
-
facet: Keiyaku.
|
|
161
|
+
facet: Keiyaku.for({
|
|
166
162
|
cwd: resolve(input.cwd ?? process.cwd(), invocation.cwd ?? "."),
|
|
167
163
|
environment,
|
|
168
164
|
...(home === undefined ? {} : { home }),
|
|
@@ -186,37 +182,21 @@ async function runCommand(invocation, input) {
|
|
|
186
182
|
}
|
|
187
183
|
if (command.name === "bind" && "acquire" in command) {
|
|
188
184
|
await admitBindMarkdown({
|
|
189
|
-
|
|
185
|
+
terms: await runtime.readStdin(),
|
|
190
186
|
processCwd: input.cwd ?? process.cwd(),
|
|
191
187
|
...(invocation.cwd === undefined ? {} : { cwd: invocation.cwd }),
|
|
192
188
|
});
|
|
193
189
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
const address = resolveNamedAddress({ selector, ...authority });
|
|
201
|
-
if (address.kind === "akuma")
|
|
202
|
-
selectedAlias = selector;
|
|
203
|
-
request = { name: "status", input: { id: address.id }, output: command.output };
|
|
204
|
-
}
|
|
205
|
-
else {
|
|
206
|
-
request =
|
|
207
|
-
"acquire" in command
|
|
208
|
-
? command.name === "spawn" || command.name === "tell" || command.name === "ask"
|
|
209
|
-
? await acquireAkumaRequest(command, invocation.workdir, runtime)
|
|
210
|
-
: await acquireContractRequest(command, runtime)
|
|
211
|
-
: command;
|
|
212
|
-
}
|
|
213
|
-
if (request.name === "spawn")
|
|
214
|
-
return await runSpawn(request, runtime);
|
|
215
|
-
if (request.name === "ask" || (request.name === "tell" && request.input.wait !== undefined))
|
|
190
|
+
const request = "acquire" in command
|
|
191
|
+
? command.name === "spawn" || command.name === "tell" || command.name === "ask"
|
|
192
|
+
? await acquireAkumaRequest(command, invocation.workdir, runtime)
|
|
193
|
+
: await acquireContractRequest(command, runtime)
|
|
194
|
+
: command;
|
|
195
|
+
if (request.name === "ask")
|
|
216
196
|
return await runAsk(request, runtime);
|
|
217
197
|
if (request.name === "history" && !request.input.selector.startsWith("kei/"))
|
|
218
198
|
return await runAkumaHistory(request, runtime);
|
|
219
|
-
return await runContractRequest(request, runtime
|
|
199
|
+
return await runContractRequest(request, runtime);
|
|
220
200
|
}
|
|
221
201
|
catch (error) {
|
|
222
202
|
return writeFailure(error, command);
|
|
@@ -183,8 +183,13 @@ function validateData(kind, value) {
|
|
|
183
183
|
terms: termsValue(object.terms, `${path}.terms`),
|
|
184
184
|
};
|
|
185
185
|
}
|
|
186
|
-
case "amend":
|
|
187
|
-
|
|
186
|
+
case "amend": {
|
|
187
|
+
const object = requireRecord(value, path);
|
|
188
|
+
return {
|
|
189
|
+
...termsValue(object, path),
|
|
190
|
+
...(object.target === undefined ? {} : { target: targetValue(object.target, `${path}.target`) }),
|
|
191
|
+
};
|
|
192
|
+
}
|
|
188
193
|
case "deliver": {
|
|
189
194
|
const object = requireRecord(value, path);
|
|
190
195
|
requireKeys(object, ["tenderSnapshot", "integration", "method", "policy"], path);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type ContractsObservation } from "./observation.js";
|
|
2
|
-
import type { ContractId } from "./types.js";
|
|
3
|
-
|
|
2
|
+
import type { ContractId, ContractTarget } from "./types.js";
|
|
3
|
+
/** Decide whether a destination chain would cycle through the amended Contract. */
|
|
4
|
+
export declare function targetCycles(contract: ContractId, target: ContractTarget | undefined, observation: ContractsObservation): boolean;
|
|
4
5
|
/** Decide whether resulting prerequisites reach the amended contract. */
|
|
5
|
-
export declare function prerequisitesReach(contract: ContractId, prerequisites: readonly ContractId[], observation:
|
|
6
|
+
export declare function prerequisitesReach(contract: ContractId, prerequisites: readonly ContractId[], observation: ContractsObservation): boolean;
|
|
6
7
|
export declare function samePrerequisites(left: readonly ContractId[], right: readonly ContractId[]): boolean;
|
|
7
|
-
export {};
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
import { contractState } from "./observation.js";
|
|
2
|
+
/** Decide whether a destination chain would cycle through the amended Contract. */
|
|
3
|
+
export function targetCycles(contract, target, observation) {
|
|
4
|
+
const visited = new Set([contract]);
|
|
5
|
+
while (target !== undefined && typeof target !== "string") {
|
|
6
|
+
if (visited.has(target.contractId))
|
|
7
|
+
return true;
|
|
8
|
+
visited.add(target.contractId);
|
|
9
|
+
target = contractState(observation, target.contractId)?.coordinates.target;
|
|
10
|
+
}
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
2
13
|
/** Decide whether resulting prerequisites reach the amended contract. */
|
|
3
14
|
export function prerequisitesReach(contract, prerequisites, observation) {
|
|
4
15
|
const pending = [...prerequisites];
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { gatesSatisfied } from "./gate.js";
|
|
2
|
+
import { sameTarget } from "./types.js";
|
|
2
3
|
import { AuthorityCorruptionError } from "./errors.js";
|
|
3
4
|
function foldError(message) {
|
|
4
5
|
throw new AuthorityCorruptionError(`invalid journal fold: ${message}`);
|
|
@@ -12,16 +13,13 @@ function cloneTerms(terms) {
|
|
|
12
13
|
after: [...terms.after],
|
|
13
14
|
};
|
|
14
15
|
}
|
|
15
|
-
function cloneCoordinates(coordinates) {
|
|
16
|
-
return { ...coordinates };
|
|
17
|
-
}
|
|
18
16
|
function stateFromBind(id, head, bind, attestations) {
|
|
19
17
|
if (bind.contract !== id)
|
|
20
18
|
foldError(`entry belongs to ${bind.contract}, not ${id}`);
|
|
21
19
|
return {
|
|
22
20
|
id,
|
|
23
21
|
head,
|
|
24
|
-
coordinates:
|
|
22
|
+
coordinates: { ...bind.data.coordinates },
|
|
25
23
|
terms: cloneTerms(bind.data.terms),
|
|
26
24
|
delivery: null,
|
|
27
25
|
currentIntegration: null,
|
|
@@ -48,7 +46,13 @@ function foldEntry(state, entry, attestations) {
|
|
|
48
46
|
case "bind":
|
|
49
47
|
foldError("bind may appear only once");
|
|
50
48
|
case "amend":
|
|
51
|
-
return {
|
|
49
|
+
return {
|
|
50
|
+
...state,
|
|
51
|
+
terms: cloneTerms(entry.data),
|
|
52
|
+
...(entry.data.target === undefined || sameTarget(state.coordinates.target, entry.data.target)
|
|
53
|
+
? {}
|
|
54
|
+
: { coordinates: { ...state.coordinates, target: entry.data.target }, targetRevision: entry.entry }),
|
|
55
|
+
};
|
|
52
56
|
case "deliver":
|
|
53
57
|
return { ...state, delivery: entry, currentIntegration: { ...entry.data.integration } };
|
|
54
58
|
case "reintegrated":
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
-
import { type AttestationEntry, type ChangeId, type ContractState, type Gate, type RequirementId } from "./types.js";
|
|
1
|
+
import { type AttestationEntry, type ChangeId, type ContractState, type Gate, type RequirementId, type SnapshotId } from "./types.js";
|
|
2
2
|
export type GateStaleReason = Readonly<{
|
|
3
3
|
kind: "candidate-content-changed";
|
|
4
4
|
target?: string;
|
|
5
5
|
previousChange: ChangeId;
|
|
6
6
|
currentChange: ChangeId;
|
|
7
|
+
}> | Readonly<{
|
|
8
|
+
kind: "snapshot-changed";
|
|
9
|
+
previousSnapshot: SnapshotId;
|
|
10
|
+
currentSnapshot: SnapshotId;
|
|
7
11
|
}>;
|
|
8
12
|
export type GateCurrent = Readonly<{
|
|
9
13
|
kind: "attested";
|
|
@@ -2,18 +2,22 @@ import { dependencyKeys, currentSubjectPredicate } from "../subject.js";
|
|
|
2
2
|
import { targetName, } from "./types.js";
|
|
3
3
|
function staleReason(state, previous) {
|
|
4
4
|
const target = state.coordinates.target;
|
|
5
|
-
const
|
|
6
|
-
if (
|
|
5
|
+
const integration = state.currentIntegration ?? state.delivery?.data.integration;
|
|
6
|
+
if (integration === undefined)
|
|
7
7
|
return undefined;
|
|
8
|
-
const
|
|
9
|
-
|
|
8
|
+
const keys = dependencyKeys(previous.data.subject);
|
|
9
|
+
const previousChange = keys.find((key) => key.kind === "change")?.value;
|
|
10
|
+
if (previousChange !== undefined && previousChange !== integration.changeId)
|
|
11
|
+
return {
|
|
12
|
+
kind: "candidate-content-changed",
|
|
13
|
+
...(target === undefined ? {} : { target: targetName(target) }),
|
|
14
|
+
previousChange,
|
|
15
|
+
currentChange: integration.changeId,
|
|
16
|
+
};
|
|
17
|
+
const previousSnapshot = keys.find((key) => key.kind === "snapshot")?.value;
|
|
18
|
+
if (previousSnapshot === undefined || previousSnapshot === integration.snapshot)
|
|
10
19
|
return undefined;
|
|
11
|
-
return {
|
|
12
|
-
kind: "candidate-content-changed",
|
|
13
|
-
...(target === undefined ? {} : { target: targetName(target) }),
|
|
14
|
-
previousChange,
|
|
15
|
-
currentChange,
|
|
16
|
-
};
|
|
20
|
+
return { kind: "snapshot-changed", previousSnapshot, currentSnapshot: integration.snapshot };
|
|
17
21
|
}
|
|
18
22
|
/** Resolve latest current testimony independently for each gate and requirement. */
|
|
19
23
|
export function latestCurrentAttestations(state, requested) {
|
|
@@ -58,6 +58,7 @@ export type ContractTarget = string | Readonly<{
|
|
|
58
58
|
}>;
|
|
59
59
|
}>;
|
|
60
60
|
export declare function targetName(target: ContractTarget): string;
|
|
61
|
+
export declare function sameTarget(left: ContractTarget | undefined, right: ContractTarget | undefined): boolean;
|
|
61
62
|
export type ContractCoordinates = Readonly<{
|
|
62
63
|
start: SnapshotId;
|
|
63
64
|
target?: ContractTarget;
|
|
@@ -77,7 +78,9 @@ export type BindData = Readonly<{
|
|
|
77
78
|
coordinates: ContractCoordinates;
|
|
78
79
|
terms: ContractTerms;
|
|
79
80
|
}>;
|
|
80
|
-
export type AmendData = ContractTerms
|
|
81
|
+
export type AmendData = ContractTerms & Readonly<{
|
|
82
|
+
target?: ContractTarget;
|
|
83
|
+
}>;
|
|
81
84
|
export type DeliverData = Readonly<{
|
|
82
85
|
note?: string;
|
|
83
86
|
tenderSnapshot: SnapshotId;
|
|
@@ -149,6 +152,7 @@ export type ContractState = Readonly<{
|
|
|
149
152
|
id: ContractId;
|
|
150
153
|
head: ContractHead | null;
|
|
151
154
|
coordinates: ContractCoordinates;
|
|
155
|
+
targetRevision?: EntryUlid;
|
|
152
156
|
terms: ContractTerms;
|
|
153
157
|
delivery: DeliverEntry | null;
|
|
154
158
|
currentIntegration: CurrentIntegration | null;
|
|
@@ -66,6 +66,13 @@ export function gate(value) {
|
|
|
66
66
|
export function targetName(target) {
|
|
67
67
|
return typeof target === "string" ? target : target.contractId;
|
|
68
68
|
}
|
|
69
|
+
export function sameTarget(left, right) {
|
|
70
|
+
if (typeof left !== "object" || typeof right !== "object")
|
|
71
|
+
return left === right;
|
|
72
|
+
return (left.contractId === right.contractId &&
|
|
73
|
+
left.worktree.id === right.worktree.id &&
|
|
74
|
+
left.worktree.identity === right.worktree.identity);
|
|
75
|
+
}
|
|
69
76
|
/**
|
|
70
77
|
* The one journal-envelope constructor for every verb offering a single fact: entry identity, the
|
|
71
78
|
* invoking decision input's Contract and timestamp, and the verb's own payload.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ChangeId, type ContractState, type DependencyKeySet, type DocumentKey, type DocumentSegmentKey, type SnapshotId } from "./facts/types.js";
|
|
1
|
+
import { type EntryUlid, type ChangeId, type ContractState, type DependencyKeySet, type DocumentKey, type DocumentSegmentKey, type SnapshotId } from "./facts/types.js";
|
|
2
2
|
export type DependencyKey = Readonly<{
|
|
3
3
|
readonly kind: "document";
|
|
4
4
|
readonly value: DocumentKey;
|
|
@@ -11,6 +11,9 @@ export type DependencyKey = Readonly<{
|
|
|
11
11
|
} | {
|
|
12
12
|
readonly kind: "change";
|
|
13
13
|
readonly value: ChangeId;
|
|
14
|
+
} | {
|
|
15
|
+
readonly kind: "target";
|
|
16
|
+
readonly value: EntryUlid;
|
|
14
17
|
}>;
|
|
15
18
|
/** Mint the opaque persisted representation of an ordered producer-selected key set. */
|
|
16
19
|
export declare function dependencyKeySet(keys: readonly DependencyKey[]): DependencyKeySet;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { changeId, documentKey, documentSegmentKey, snapshotId, } from "./facts/types.js";
|
|
1
|
+
import { changeId, entryUlid, documentKey, documentSegmentKey, snapshotId, } from "./facts/types.js";
|
|
2
2
|
import { AuthorityCorruptionError } from "./facts/errors.js";
|
|
3
3
|
function keyTuple(key) {
|
|
4
4
|
return [key.kind, key.value];
|
|
@@ -20,6 +20,8 @@ function parseKey(value, index) {
|
|
|
20
20
|
return { kind: "snapshot", value: snapshotId(value[1]) };
|
|
21
21
|
case "change":
|
|
22
22
|
return { kind: "change", value: changeId(value[1]) };
|
|
23
|
+
case "target":
|
|
24
|
+
return { kind: "target", value: entryUlid(value[1]) };
|
|
23
25
|
default:
|
|
24
26
|
throw new AuthorityCorruptionError(`unknown dependency key kind '${value[0]}'`);
|
|
25
27
|
}
|
|
@@ -78,6 +80,7 @@ function currentKeys(state) {
|
|
|
78
80
|
return new Set([
|
|
79
81
|
encodeKey({ kind: "document", value: state.terms.document.key }),
|
|
80
82
|
...state.terms.segments.map((value) => encodeKey({ kind: "segment", value })),
|
|
83
|
+
...(state.targetRevision === undefined ? [] : [encodeKey({ kind: "target", value: state.targetRevision })]),
|
|
81
84
|
...(integration === undefined
|
|
82
85
|
? []
|
|
83
86
|
: [
|
|
@@ -94,7 +97,12 @@ export function currentSubjectPredicate(state) {
|
|
|
94
97
|
const known = current.get(subject);
|
|
95
98
|
if (known !== undefined)
|
|
96
99
|
return known;
|
|
97
|
-
const
|
|
100
|
+
const decoded = decodeDependencyKeySet(subject);
|
|
101
|
+
// Snapshot-only testimony cannot cross a target change, even when the new target has the same head.
|
|
102
|
+
const snapshotTargetCurrent = state.targetRevision === undefined ||
|
|
103
|
+
!decoded.keys.some((key) => key.kind === "snapshot") ||
|
|
104
|
+
decoded.keys.some((key) => key.kind === "target" && key.value === state.targetRevision);
|
|
105
|
+
const value = snapshotTargetCurrent && decoded.encodedKeys.every((key) => available.has(key));
|
|
98
106
|
current.set(subject, value);
|
|
99
107
|
return value;
|
|
100
108
|
};
|
|
@@ -1,12 +1,23 @@
|
|
|
1
1
|
import type { DecideInput, OfferDecision, Preparation } from "../decide.js";
|
|
2
|
+
import { type TargetContractRefusal } from "../facts/observation.js";
|
|
2
3
|
import { type AmendData, type ContractId, type ContractTerms } from "../facts/types.js";
|
|
4
|
+
/** What one amendment replaces: the source terms it stamps and the terms it asks for. */
|
|
5
|
+
export type AmendEdit<Failure = never> = Readonly<{
|
|
6
|
+
source: ContractTerms;
|
|
7
|
+
targetContract?: ContractId;
|
|
8
|
+
preparation: Preparation<AmendData, Failure>;
|
|
9
|
+
}>;
|
|
3
10
|
export type AmendInput<Failure = never> = Readonly<{
|
|
4
11
|
contractId: ContractId;
|
|
5
12
|
at: string;
|
|
6
|
-
|
|
7
|
-
|
|
13
|
+
/** Absent when the amendment requests no change: an ordinary no-op, not an empty edit. */
|
|
14
|
+
edit?: AmendEdit<Failure>;
|
|
8
15
|
}>;
|
|
9
16
|
export type AmendRefusal = Readonly<{
|
|
10
|
-
kind: "contract-missing" | "terminal" | "terms-moved" | "unknown-prerequisite" | "cyclic-prerequisite";
|
|
17
|
+
kind: "contract-missing" | "terminal" | "terms-moved" | "unknown-prerequisite" | "cyclic-prerequisite" | "cyclic-target";
|
|
18
|
+
}> | TargetContractRefusal;
|
|
19
|
+
/** The owner's answer for a well-formed amendment request, including one that asks for nothing. */
|
|
20
|
+
export type AmendDecision<Failure> = OfferDecision<AmendRefusal | Failure> | Readonly<{
|
|
21
|
+
kind: "unchanged";
|
|
11
22
|
}>;
|
|
12
|
-
export declare function decideAmend<Failure>({ input, attempt, observation, }: DecideInput<AmendInput<Failure>>):
|
|
23
|
+
export declare function decideAmend<Failure>({ input, attempt, observation, }: DecideInput<AmendInput<Failure>>): AmendDecision<Failure>;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import { prerequisitesReach, samePrerequisites } from "../facts/eligibility.js";
|
|
2
|
-
import { activeContract, prerequisiteStatus } from "../facts/observation.js";
|
|
1
|
+
import { prerequisitesReach, samePrerequisites, targetCycles } from "../facts/eligibility.js";
|
|
2
|
+
import { activeContract, prerequisiteStatus, targetContractRefusal, targetContractIdRefusal, } from "../facts/observation.js";
|
|
3
3
|
import { journalEntry } from "../facts/types.js";
|
|
4
4
|
export function decideAmend({ input, attempt, observation, }) {
|
|
5
5
|
const id = input.contractId;
|
|
6
6
|
const current = activeContract(observation, id);
|
|
7
7
|
if ("kind" in current)
|
|
8
8
|
return { kind: "refused", refusal: current };
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const source =
|
|
9
|
+
const edit = input.edit;
|
|
10
|
+
if (edit === undefined)
|
|
11
|
+
return { kind: "unchanged" };
|
|
12
|
+
const source = edit.source;
|
|
13
13
|
const termsCurrent = source.document.key === current.terms.document.key &&
|
|
14
14
|
source.segments.length === current.terms.segments.length &&
|
|
15
15
|
source.segments.every((value, index) => value === current.terms.segments[index]) &&
|
|
@@ -27,9 +27,19 @@ export function decideAmend({ input, attempt, observation, }) {
|
|
|
27
27
|
if (!termsCurrent) {
|
|
28
28
|
return { kind: "refused", refusal: { kind: "terms-moved" } };
|
|
29
29
|
}
|
|
30
|
-
if (
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
if (edit.targetContract !== undefined) {
|
|
31
|
+
const refusal = targetContractIdRefusal(observation, edit.targetContract);
|
|
32
|
+
if (refusal !== undefined)
|
|
33
|
+
return { kind: "refused", refusal };
|
|
34
|
+
}
|
|
35
|
+
if (edit.preparation.kind === "refused")
|
|
36
|
+
return { kind: "refused", refusal: edit.preparation.refusal };
|
|
37
|
+
const { data } = edit.preparation;
|
|
38
|
+
const targetRefusal = targetContractRefusal(observation, data.target);
|
|
39
|
+
if (targetRefusal !== undefined)
|
|
40
|
+
return { kind: "refused", refusal: targetRefusal };
|
|
41
|
+
if (targetCycles(id, data.target, observation))
|
|
42
|
+
return { kind: "refused", refusal: { kind: "cyclic-target" } };
|
|
33
43
|
const prerequisites = prerequisiteStatus(data.after, observation);
|
|
34
44
|
if (prerequisites === "unknown") {
|
|
35
45
|
return { kind: "refused", refusal: { kind: "unknown-prerequisite" } };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type DebtDocument } from "./document.js";
|
|
2
2
|
import { type DebtId } from "./identity.js";
|
|
3
3
|
import { z } from "zod";
|
|
4
|
+
import type { LifecycleSelection } from "../bounded-list.js";
|
|
4
5
|
export declare const debtRefSchema: z.ZodReadonly<z.ZodObject<{
|
|
5
6
|
id: z.ZodPipe<z.ZodString, z.ZodTransform<`debt/${string}`, string>>;
|
|
6
7
|
state: z.ZodUnion<readonly [z.ZodEnum<{
|
|
@@ -90,7 +91,7 @@ export declare function debtDisposition(board: DebtBoard, debt: DebtDocument): D
|
|
|
90
91
|
export declare function debtBlocked(board: DebtBoard, debt: DebtDocument): boolean;
|
|
91
92
|
export declare function projectDebtDetail(board: DebtBoard, id: DebtId): DebtDetail | null;
|
|
92
93
|
export declare function projectDebtSummary(board: DebtBoard, debt: DebtDocument): DebtSummary;
|
|
93
|
-
export declare function projectRows(board: DebtBoard, selection:
|
|
94
|
+
export declare function projectRows(board: DebtBoard, selection: LifecycleSelection): readonly DebtSummary[];
|
|
94
95
|
export declare function projectBlocked(board: DebtBoard): readonly BlockedDebtRow[];
|
|
95
96
|
export declare function relationProblem(board: DebtBoard, before: DebtDocument | null, after: DebtDocument): string | null;
|
|
96
97
|
export declare function diagnoseBoard(board: DebtBoard): readonly DebtDoctorIssue[];
|
package/build/src/debt/board.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { debtNonblankTextSchema, debtStateSchema, debtPrioritySchema, } from "./document.js";
|
|
1
|
+
import { debtNonblankTextSchema, debtStateSchema, debtLifecycle, debtPrioritySchema, } from "./document.js";
|
|
2
2
|
import { debtIdSchema } from "./identity.js";
|
|
3
3
|
import { nonEmptyDebtValues, nonEmptyDebtArraySchema } from "./operation-types.js";
|
|
4
4
|
import { z } from "zod";
|
|
@@ -64,7 +64,7 @@ export const debtDoctorIssueSchema = z.union([
|
|
|
64
64
|
})
|
|
65
65
|
.readonly(),
|
|
66
66
|
]);
|
|
67
|
-
const terminal = (state) => state === "
|
|
67
|
+
const terminal = (state) => debtLifecycle(state) === "settled";
|
|
68
68
|
const sorted = (values) => [...values].sort((a, b) => Buffer.compare(Buffer.from(a.id), Buffer.from(b.id)));
|
|
69
69
|
export function debtRef(board, id) {
|
|
70
70
|
const debt = board.debts.get(id);
|
|
@@ -110,7 +110,7 @@ export function projectDebtSummary(board, debt) {
|
|
|
110
110
|
}
|
|
111
111
|
export function projectRows(board, selection) {
|
|
112
112
|
return [...board.debts.values()]
|
|
113
|
-
.filter((debt) => selection === "all" || (
|
|
113
|
+
.filter((debt) => selection === "all" || debtLifecycle(debt.state) === selection)
|
|
114
114
|
.map((debt) => projectDebtSummary(board, debt))
|
|
115
115
|
.sort(compareDebtRows);
|
|
116
116
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { debtLifecycle } from "./document.js";
|
|
1
2
|
import { readRecentDebtDocuments, readDebtDocument } from "./store.js";
|
|
2
3
|
function terminal(debt) {
|
|
3
|
-
return debt
|
|
4
|
+
return debt !== undefined && debtLifecycle(debt.state) === "settled";
|
|
4
5
|
}
|
|
5
6
|
async function catalogRow(world, debt, documents) {
|
|
6
7
|
const needs = await Promise.all(debt.needs.map(async (id) => documents.get(id) ?? (await readDebtDocument(world, id))));
|
|
@@ -10,6 +10,7 @@ export declare const debtStateSchema: z.ZodEnum<{
|
|
|
10
10
|
export type DebtPriority = 0 | 1 | 2 | 3;
|
|
11
11
|
export declare const debtPrioritySchema: z.ZodType<DebtPriority, DebtPriority>;
|
|
12
12
|
export type DebtState = z.infer<typeof debtStateSchema>;
|
|
13
|
+
export declare function debtLifecycle(state: DebtState): "active" | "settled";
|
|
13
14
|
export declare const debtDocumentSchema: z.ZodReadonly<z.ZodObject<{
|
|
14
15
|
id: z.ZodPipe<z.ZodString, z.ZodTransform<`debt/${string}`, string>>;
|
|
15
16
|
title: z.ZodString;
|
|
@@ -6,6 +6,9 @@ export const debtNonblankTextSchema = z.string().refine((value) => value.trim()
|
|
|
6
6
|
export const debtStateSchema = z.enum(["open", "done", "drop"]);
|
|
7
7
|
// Integer bounds prove the finite priority type without a four-branch wire union.
|
|
8
8
|
export const debtPrioritySchema = z.number().int().min(0).max(3);
|
|
9
|
+
export function debtLifecycle(state) {
|
|
10
|
+
return state === "open" ? "active" : "settled";
|
|
11
|
+
}
|
|
9
12
|
export const debtDocumentSchema = z
|
|
10
13
|
.strictObject({
|
|
11
14
|
id: debtIdSchema,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
+
import { type LifecycleSelection } from "../bounded-list.js";
|
|
1
2
|
import { z } from "zod";
|
|
2
3
|
import { debtRefSchema, blockedDebtRowSchema, readyDebtRowSchema, debtDoctorIssueSchema, debtSummarySchema, debtDispositionSchema, debtDetailSchema, type BlockedDebtRow, type DebtDetail, type DebtDoctorIssue, type DebtRef, type DebtSummary, type ReadyDebtRow } from "./board.js";
|
|
3
4
|
import { debtWarningSchema, debtRefusalSchema, debtRetrySchema, debtReadPageSchema, debtMutationResultSchema, debtMutationNormalResultSchema, debtUpdateResultSchema, debtChangeSchema, type DebtWarning, type DebtRefusal, type DebtRetry, type DebtReadPage, type DebtMutationResult, type DebtUpdateResult, type DebtChange } from "./operation-types.js";
|
|
4
5
|
import type { WorldRoot } from "../world.js";
|
|
5
|
-
export type { WorldRoot } from "../world.js";
|
|
6
6
|
import { DebtAuthorityCorruptionError, type DebtPriority, type DebtState } from "./document.js";
|
|
7
7
|
import { type DebtId } from "./identity.js";
|
|
8
8
|
import { type AddDebtDocumentInput, type AddDebtInput, type UpdateDebtInput } from "./operations.js";
|
|
@@ -254,7 +254,7 @@ declare class DebtsHandle {
|
|
|
254
254
|
add(input: AddDebtInput): Promise<DebtMutationResult>;
|
|
255
255
|
addDocument(input: AddDebtDocumentInput): Promise<DebtMutationResult>;
|
|
256
256
|
list(input?: Readonly<{
|
|
257
|
-
selection?:
|
|
257
|
+
selection?: LifecycleSelection;
|
|
258
258
|
limit?: number;
|
|
259
259
|
}>): Promise<DebtList>;
|
|
260
260
|
ready(input?: Readonly<{
|
package/build/src/debt/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { KeiyakuError } from "../errors.js";
|
|
2
|
+
import { lifecycleSelection } from "../bounded-list.js";
|
|
2
3
|
import { z } from "zod";
|
|
3
4
|
import { debtRefSchema, blockedDebtRowSchema, readyDebtRowSchema, debtDoctorIssueSchema, debtSummarySchema, debtDispositionSchema, debtDetailSchema, diagnoseBoard, projectDebtDetail, } from "./board.js";
|
|
4
5
|
import { debtWarningSchema, debtRefusalSchema, debtRetrySchema, debtReadPageSchema, nonEmptyDebtValues, nonEmptyDebtArraySchema, debtMutationResultSchema, debtMutationNormalResultSchema, debtUpdateResultSchema, debtChangeSchema, } from "./operation-types.js";
|
|
@@ -7,7 +8,7 @@ import { debtIdSchema } from "./identity.js";
|
|
|
7
8
|
import { addDebt, addDebtDocument, blockedDebts, listDebts, readDebtDetail, readyDebts, updateDebt, } from "./operations.js";
|
|
8
9
|
import { boundedListLimit } from "../bounded-list.js";
|
|
9
10
|
import { readBoard } from "./store.js";
|
|
10
|
-
import { addDocumentInput, addInput,
|
|
11
|
+
import { addDocumentInput, addInput, fields, debtId as id, updateInput } from "./input.js";
|
|
11
12
|
export const debtAbsentSchema = z.strictObject({ kind: z.literal("absent") }).readonly();
|
|
12
13
|
export const debtReadResultSchema = z.union([
|
|
13
14
|
z.strictObject({ kind: z.literal("present"), ...debtDetailSchema.unwrap().shape }).readonly(),
|
|
@@ -77,8 +78,7 @@ class DebtsHandle {
|
|
|
77
78
|
this.root = world;
|
|
78
79
|
}
|
|
79
80
|
debt(input) {
|
|
80
|
-
const v =
|
|
81
|
-
closed(v, ["id"], "debt input");
|
|
81
|
+
const v = fields(input, ["id"], "debt input");
|
|
82
82
|
return new DebtHandle(id(v.id), this.world);
|
|
83
83
|
}
|
|
84
84
|
add(input) {
|
|
@@ -88,28 +88,23 @@ class DebtsHandle {
|
|
|
88
88
|
return addDebtDocument(this.world, addDocumentInput(input));
|
|
89
89
|
}
|
|
90
90
|
async list(input = {}) {
|
|
91
|
-
const v =
|
|
92
|
-
|
|
93
|
-
if (v.selection !== undefined && v.selection !== "active" && v.selection !== "closed" && v.selection !== "all")
|
|
94
|
-
throw new KeiyakuError("invalid-input", "selection must be active, closed, or all");
|
|
91
|
+
const v = fields(input, ["selection", "limit"], "list input");
|
|
92
|
+
const selection = lifecycleSelection(v.selection);
|
|
95
93
|
return {
|
|
96
|
-
...(await listDebts(this.world,
|
|
94
|
+
...(await listDebts(this.world, selection, boundedListLimit(v.limit))),
|
|
97
95
|
kind: "debt-catalogue",
|
|
98
96
|
};
|
|
99
97
|
}
|
|
100
98
|
async ready(input = {}) {
|
|
101
|
-
const v =
|
|
102
|
-
closed(v, ["limit"], "ready input");
|
|
99
|
+
const v = fields(input, ["limit"], "ready input");
|
|
103
100
|
return readyDebts(this.world, boundedListLimit(v.limit));
|
|
104
101
|
}
|
|
105
102
|
async blocked(input = {}) {
|
|
106
|
-
const v =
|
|
107
|
-
closed(v, ["limit"], "blocked input");
|
|
103
|
+
const v = fields(input, ["limit"], "blocked input");
|
|
108
104
|
return blockedDebts(this.world, boundedListLimit(v.limit));
|
|
109
105
|
}
|
|
110
106
|
async read(input) {
|
|
111
|
-
const v =
|
|
112
|
-
closed(v, ["ids"], "read input");
|
|
107
|
+
const v = fields(input, ["ids"], "read input");
|
|
113
108
|
if (!Array.isArray(v.ids) || v.ids.length === 0)
|
|
114
109
|
throw new KeiyakuError("invalid-input", "ids requires at least one DebtId");
|
|
115
110
|
const ids = v.ids.map(id);
|
|
@@ -2,7 +2,8 @@ import { z } from "zod";
|
|
|
2
2
|
import { type DebtId } from "./identity.js";
|
|
3
3
|
import type { AddDebtDocumentInput, AddDebtInput, UpdateDebtInput } from "./operations.js";
|
|
4
4
|
export declare function record(value: unknown, label: string): Record<string, unknown>;
|
|
5
|
-
|
|
5
|
+
/** One closed caller object: an object with only the fields its surface names. */
|
|
6
|
+
export declare function fields(value: unknown, allowed: readonly string[], label: string): Record<string, unknown>;
|
|
6
7
|
export declare function debtId(value: unknown): DebtId;
|
|
7
8
|
export declare function signal(value: unknown): AbortSignal | undefined;
|
|
8
9
|
export declare function text(value: unknown, label: string): string | undefined;
|
package/build/src/debt/input.js
CHANGED
|
@@ -8,11 +8,14 @@ export function record(value, label) {
|
|
|
8
8
|
}
|
|
9
9
|
return value;
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
/** One closed caller object: an object with only the fields its surface names. */
|
|
12
|
+
export function fields(value, allowed, label) {
|
|
13
|
+
const recordValue = record(value, label);
|
|
14
|
+
for (const key of Object.keys(recordValue)) {
|
|
13
15
|
if (!allowed.includes(key))
|
|
14
16
|
throw new KeiyakuError("invalid-input", `${label} has unknown field: ${key}`);
|
|
15
17
|
}
|
|
18
|
+
return recordValue;
|
|
16
19
|
}
|
|
17
20
|
export function debtId(value) {
|
|
18
21
|
if (typeof value !== "string")
|
|
@@ -74,8 +77,7 @@ export function addInput(input) {
|
|
|
74
77
|
return parseDebtInput(addDebtInputSchema.extend({ signal: signalSchema }), input);
|
|
75
78
|
}
|
|
76
79
|
export function addDocumentInput(input) {
|
|
77
|
-
const v =
|
|
78
|
-
closed(v, ["markdown", "signal"], "addDocument input");
|
|
80
|
+
const v = fields(input, ["markdown", "signal"], "addDocument input");
|
|
79
81
|
const markdown = text(v.markdown, "markdown");
|
|
80
82
|
if (markdown === undefined)
|
|
81
83
|
throw new KeiyakuError("invalid-input", "markdown is required");
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type BlockedDebtRow, type DebtDetail, type DebtSummary, type ReadyDebtRow } from "./board.js";
|
|
2
2
|
import { type DebtId } from "./identity.js";
|
|
3
3
|
import type { WorldRoot } from "../world.js";
|
|
4
|
+
import { type LifecycleSelection } from "../bounded-list.js";
|
|
4
5
|
export type { AddDebtDocumentInput, AddDebtInput, DebtMutationResult, DebtReadPage, DebtRefusal, DebtRetry, DebtUpdateResult, SettledDebtResult, UpdateDebtInput, } from "./operation-types.js";
|
|
5
6
|
import type { AddDebtDocumentInput, AddDebtInput, DebtMutationResult, DebtReadPage, DebtUpdateResult, UpdateDebtInput } from "./operation-types.js";
|
|
6
7
|
export declare function nukeDebt(world: WorldRoot, options?: Readonly<{
|
|
@@ -11,7 +12,7 @@ export declare function addDebt(world: WorldRoot, input: AddDebtInput): Promise<
|
|
|
11
12
|
export declare function addDebtDocument(world: WorldRoot, input: AddDebtDocumentInput): Promise<DebtMutationResult>;
|
|
12
13
|
export declare function updateDebt(world: WorldRoot, id: DebtId, input: UpdateDebtInput): Promise<DebtUpdateResult>;
|
|
13
14
|
export { settleDebt } from "./lifecycle-operations.js";
|
|
14
|
-
export declare function listDebts(world: WorldRoot, selection:
|
|
15
|
+
export declare function listDebts(world: WorldRoot, selection: LifecycleSelection, limit?: number): Promise<Extract<DebtReadPage<DebtSummary>, {
|
|
15
16
|
kind: "present";
|
|
16
17
|
}>>;
|
|
17
18
|
export declare function readDebtDetail(world: WorldRoot, id: DebtId): Promise<DebtDetail | null>;
|
|
@@ -1,26 +1,9 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
1
|
import { type ContractId } from "../core/facts/types.js";
|
|
3
2
|
import { type AkumaId } from "../akuma/identity.js";
|
|
4
3
|
import { type PrivateStateSeatCloseLag } from "../git/private-state-seat.js";
|
|
5
4
|
import type { GitRepository } from "../git/process.js";
|
|
6
5
|
import { type GitReadObservation } from "../git/read-observation.js";
|
|
7
6
|
import { type DispatchAssociation } from "../akuma/dispatch-association.js";
|
|
8
|
-
export declare const dispatchSchema: z.ZodReadonly<z.ZodObject<{
|
|
9
|
-
akumaId: z.ZodPipe<z.ZodString, z.ZodTransform<AkumaId, string>>;
|
|
10
|
-
contractId: z.ZodPipe<z.ZodString, z.ZodTransform<ContractId, string>>;
|
|
11
|
-
dispatchedAt: z.ZodString;
|
|
12
|
-
}, z.core.$strict>>;
|
|
13
|
-
export declare const dispatchFailureSchema: z.ZodUnion<readonly [z.ZodReadonly<z.ZodObject<{
|
|
14
|
-
kind: z.ZodLiteral<"conflict">;
|
|
15
|
-
current: z.ZodReadonly<z.ZodObject<{
|
|
16
|
-
akumaId: z.ZodPipe<z.ZodString, z.ZodTransform<AkumaId, string>>;
|
|
17
|
-
contractId: z.ZodPipe<z.ZodString, z.ZodTransform<ContractId, string>>;
|
|
18
|
-
dispatchedAt: z.ZodString;
|
|
19
|
-
}, z.core.$strict>>;
|
|
20
|
-
}, z.core.$strict>>, z.ZodReadonly<z.ZodObject<{
|
|
21
|
-
kind: z.ZodLiteral<"publication-failed">;
|
|
22
|
-
diagnostic: z.ZodString;
|
|
23
|
-
}, z.core.$strict>>]>;
|
|
24
7
|
export type Dispatch = Readonly<{
|
|
25
8
|
akumaId: AkumaId;
|
|
26
9
|
contractId: ContractId;
|