@astrosheep/keiyaku 4.6.32 → 4.6.33
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 +8 -6
- package/build/plugins/claude/skills/keiyaku-akuma/SKILL.md +13 -9
- package/build/plugins/claude/skills/keiyaku-babysit/SKILL.md +8 -6
- package/build/plugins/claude/skills/keiyaku-workflow/SKILL.md +2 -1
- package/build/plugins/codex/skills/keiyaku-akuma/SKILL.md +13 -9
- package/build/plugins/codex/skills/keiyaku-babysit/SKILL.md +8 -6
- package/build/plugins/codex/skills/keiyaku-workflow/SKILL.md +2 -1
- package/build/plugins/opencode/skills/keiyaku-akuma/SKILL.md +13 -9
- package/build/plugins/opencode/skills/keiyaku-babysit/SKILL.md +8 -6
- 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 +2 -9
- package/build/skills/keiyaku-akuma/SKILL.md +13 -9
- package/build/skills/keiyaku-babysit/SKILL.md +8 -6
- 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.js +73 -14
- 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 +40 -1
- package/build/src/akuma/akuma-wait.js +58 -29
- package/build/src/akuma/akuma.d.ts +11 -0
- 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/index.d.ts +1 -1
- package/build/src/akuma/heart/index.js +9 -1
- package/build/src/akuma/heart/timeline.js +4 -4
- package/build/src/akuma/projection-read.d.ts +4 -2
- package/build/src/akuma/projection-read.js +21 -14
- 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 +23 -0
- package/build/src/akuma/selection-observation.js +15 -4
- 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/cli/commands/akuma-grammar.d.ts +3 -5
- package/build/src/cli/commands/akuma-grammar.js +22 -40
- package/build/src/cli/commands/akuma.d.ts +1 -2
- package/build/src/cli/commands/akuma.js +6 -58
- package/build/src/cli/commands/contract-grammar.d.ts +1 -0
- package/build/src/cli/commands/contract-grammar.js +7 -11
- package/build/src/cli/commands/contract-help.d.ts +3 -2
- package/build/src/cli/commands/contract-help.js +11 -5
- package/build/src/cli/commands/contract.js +3 -0
- package/build/src/cli/commands/debt-grammar.js +2 -4
- package/build/src/cli/parse.js +1 -4
- package/build/src/cli/render/akuma-activity.d.ts +3 -15
- package/build/src/cli/render/akuma-activity.js +19 -73
- 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 +1 -4
- package/build/src/cli/render/contract-history.js +2 -0
- 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 +13 -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.js +1 -2
- package/build/src/cli/render/kanshi.js +11 -17
- 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 +19 -17
- package/build/src/cli/runtime.js +3 -9
- 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/index.d.ts +0 -1
- package/build/src/debt/index.js +6 -11
- package/build/src/debt/input.d.ts +2 -1
- package/build/src/debt/input.js +6 -4
- 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 +3 -0
- package/build/src/git/observe.js +25 -23
- 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/index.d.ts +2 -0
- package/build/src/kanshi/index.d.ts +0 -1
- package/build/src/kanshi/index.js +0 -1
- package/build/src/kanshi/read.d.ts +21 -0
- package/build/src/kanshi/read.js +2 -1
- 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/continuation.d.ts +10 -0
- package/build/src/library/contract-creation.js +10 -11
- 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 +18 -0
- package/build/src/library/contract-types.js +2 -0
- package/build/src/library/contract-wait.d.ts +7 -0
- package/build/src/library/contract-wait.js +53 -49
- package/build/src/library/delivery.d.ts +25 -0
- package/build/src/library/input.d.ts +5 -23
- package/build/src/library/input.js +12 -7
- package/build/src/library/kei.js +39 -20
- package/build/src/library/keiyaku-classify.js +3 -3
- package/build/src/library/keiyaku-debt.js +1 -2
- package/build/src/library/keiyaku-identity.d.ts +3 -3
- package/build/src/library/keiyaku-identity.js +11 -6
- package/build/src/library/keiyaku-verbs.d.ts +456 -1362
- package/build/src/library/keiyaku-verbs.js +80 -92
- package/build/src/library/keiyaku-wait.d.ts +183 -0
- package/build/src/library/keiyaku-wait.js +213 -0
- package/build/src/library/keiyaku.d.ts +3 -1
- package/build/src/library/keiyaku.js +49 -73
- package/build/src/{mcp/output.d.ts → library/model-tools.d.ts} +227 -56
- package/build/src/library/model-tools.js +347 -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 +12 -0
- package/build/src/library/selection.js +1 -2
- package/build/src/mcp/adapter.d.ts +0 -6
- package/build/src/mcp/adapter.js +10 -159
- 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 +6 -4
- package/build/src/pi/index.d.ts +3 -0
- package/build/src/pi/index.js +83 -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 +54 -16
- package/build/src/protocol/operations.js +17 -31
- package/build/src/protocol/placement.js +7 -1
- package/build/src/protocol/progress.js +0 -6
- package/build/src/protocol/read/status.d.ts +40 -0
- package/build/src/protocol/read/status.js +7 -10
- 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/pi/README.md +55 -97
- package/plugins/pi/keiyaku.ts +2 -9
- package/skills/keiyaku-akuma/SKILL.md +13 -9
- package/skills/keiyaku-babysit/SKILL.md +8 -6
- 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.js +0 -193
- package/plugins/pi/akuma-tools.ts +0 -283
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import { usageAcceptanceLines } from "../usage.js";
|
|
2
2
|
import { contractOperationName, shortGitId } from "./contract-observation.js";
|
|
3
|
-
import { DEFAULT_CLI_COLUMNS, formatNextCall, orderRefusalFacts, renderOpaqueBlock, safeText, } from "./terminal.js";
|
|
3
|
+
import { DEFAULT_CLI_COLUMNS, formatNextCall, kindWords, orderRefusalFacts, renderOpaqueBlock, safeText, } from "./terminal.js";
|
|
4
4
|
function wrap(lines, text, indent, columns) {
|
|
5
5
|
lines.push(...renderOpaqueBlock(text, indent, columns));
|
|
6
6
|
}
|
|
7
|
-
function words(kind) {
|
|
8
|
-
return kind.replaceAll("-", " ");
|
|
9
|
-
}
|
|
10
7
|
function collectionLines(name, members, indent) {
|
|
11
8
|
if (members.length === 0)
|
|
12
9
|
return [];
|
|
@@ -23,7 +20,7 @@ const REFUSAL_WORDS = {
|
|
|
23
20
|
"contract-missing": "contract missing",
|
|
24
21
|
};
|
|
25
22
|
function refusalWords(kind) {
|
|
26
|
-
return REFUSAL_WORDS[kind] ??
|
|
23
|
+
return REFUSAL_WORDS[kind] ?? kindWords(kind);
|
|
27
24
|
}
|
|
28
25
|
function renderDirtyRefusal(refusal, indent, columns, surface) {
|
|
29
26
|
const lines = [];
|
|
@@ -134,7 +131,7 @@ function refusalFacts(refusal, indent, columns, addressed, surface) {
|
|
|
134
131
|
if (refusal.kind === "target-workspace-unavailable") {
|
|
135
132
|
return [
|
|
136
133
|
`${indent}reason target workspace unavailable`,
|
|
137
|
-
...targetRefusalLines(target, indent, identity,
|
|
134
|
+
...targetRefusalLines(target, indent, identity, kindWords(refusal.reason)),
|
|
138
135
|
];
|
|
139
136
|
}
|
|
140
137
|
if (refusal.kind === "target-contract-missing" || refusal.kind === "target-contract-terminal") {
|
|
@@ -21,10 +21,6 @@ export declare function takeDisplayColumns(value: string, maximum: number): Read
|
|
|
21
21
|
text: string;
|
|
22
22
|
rest: string;
|
|
23
23
|
}>;
|
|
24
|
-
export declare function takeDisplayColumnsFromEnd(value: string, maximum: number): Readonly<{
|
|
25
|
-
text: string;
|
|
26
|
-
rest: string;
|
|
27
|
-
}>;
|
|
28
24
|
export declare function truncateDisplayText(value: string, maximum: number): string;
|
|
29
25
|
/** Pad text to a terminal-column width; raw string length is never the measuring stick. */
|
|
30
26
|
export declare function padToDisplay(text: string, width: number): string;
|
|
@@ -76,6 +72,8 @@ export declare function elapsedMilliseconds(source: string | null | undefined, o
|
|
|
76
72
|
*/
|
|
77
73
|
export declare function ageText(source: string, observedAt: string, future?: "now" | "future"): string;
|
|
78
74
|
export declare function tone(value: string, kind: SemanticTone, color: boolean): string;
|
|
75
|
+
/** One machine kind as words; every receipt vocabulary spells kinds through this one rule. */
|
|
76
|
+
export declare function kindWords(kind: string): string;
|
|
79
77
|
export declare function plumbFacts(facts: readonly string[], columns: number): readonly string[];
|
|
80
78
|
export declare function identityLine(mark: string, identity: string, extra?: string): string;
|
|
81
79
|
export declare function entityLines(entity: Readonly<{
|
|
@@ -113,18 +113,6 @@ export function takeDisplayColumns(value, maximum) {
|
|
|
113
113
|
}
|
|
114
114
|
return { text: clusters.slice(0, index).join(""), rest: clusters.slice(index).join("") };
|
|
115
115
|
}
|
|
116
|
-
export function takeDisplayColumnsFromEnd(value, maximum) {
|
|
117
|
-
const clusters = [...GRAPHEMES.segment(value)].map(({ segment }) => segment);
|
|
118
|
-
let columns = 0;
|
|
119
|
-
let index = clusters.length;
|
|
120
|
-
for (; index > 0; index -= 1) {
|
|
121
|
-
const width = graphemeColumns(clusters[index - 1]);
|
|
122
|
-
if (columns + width > maximum)
|
|
123
|
-
break;
|
|
124
|
-
columns += width;
|
|
125
|
-
}
|
|
126
|
-
return { text: clusters.slice(index).join(""), rest: clusters.slice(0, index).join("") };
|
|
127
|
-
}
|
|
128
116
|
export function truncateDisplayText(value, maximum) {
|
|
129
117
|
const clean = safeText(value);
|
|
130
118
|
if (displayColumns(clean) <= maximum)
|
|
@@ -182,10 +170,11 @@ export function renderBoundedPayload(input) {
|
|
|
182
170
|
const diagnostic = safeText(input.trailer.diagnostic).replace(/\s+/gu, " ").trim();
|
|
183
171
|
const extra = diagnostic === "" ? "" : `${suffix === "" ? " — " : " · "}${diagnostic}`;
|
|
184
172
|
const extraWidth = displayColumns(extra);
|
|
185
|
-
const [firstBody] = GRAPHEMES.segment(input.text
|
|
186
|
-
const bodyMinimum = displayColumns(firstBody.segment) + omissionWidth;
|
|
187
|
-
// Reserve
|
|
188
|
-
//
|
|
173
|
+
const [firstBody] = GRAPHEMES.segment(input.text);
|
|
174
|
+
const bodyMinimum = firstBody === undefined ? 0 : displayColumns(firstBody.segment) + omissionWidth;
|
|
175
|
+
// Reserve the body's first grapheme plus its omission and any diagnostic omission before clipping the prefix.
|
|
176
|
+
// An absent preview reserves nothing, so the tool identity keeps its full width; sharing spare cells
|
|
177
|
+
// monotonically keeps wider rows from reducing the body allowance.
|
|
189
178
|
const minimumPayload = bodyMinimum + (extra === "" ? 0 : omissionWidth);
|
|
190
179
|
const prefixWidth = Math.min(displayColumns(input.first), Math.max(0, columns - displayColumns(suffix) - minimumPayload));
|
|
191
180
|
const labelWidth = Math.max(0, prefixWidth - displayColumns(" "));
|
|
@@ -196,7 +185,7 @@ export function renderBoundedPayload(input) {
|
|
|
196
185
|
const body = renderFoldedPayload({
|
|
197
186
|
...input,
|
|
198
187
|
first,
|
|
199
|
-
text: input.text
|
|
188
|
+
text: input.text,
|
|
200
189
|
columns: columns - displayColumns(suffix) - diagnosticReserve,
|
|
201
190
|
maxLines: 1,
|
|
202
191
|
})[0];
|
|
@@ -432,6 +421,10 @@ export function tone(value, kind, color) {
|
|
|
432
421
|
const code = kind === "dim" ? 2 : kind === "recent" ? 32 : kind === "attention" ? 33 : 31;
|
|
433
422
|
return `\u001b[${code}m${value}\u001b[0m`;
|
|
434
423
|
}
|
|
424
|
+
/** One machine kind as words; every receipt vocabulary spells kinds through this one rule. */
|
|
425
|
+
export function kindWords(kind) {
|
|
426
|
+
return kind.replaceAll("-", " ");
|
|
427
|
+
}
|
|
435
428
|
export function plumbFacts(facts, columns) {
|
|
436
429
|
const lines = [];
|
|
437
430
|
let current = " ";
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { VerbCompletion, VerbInput, VerbName, VerbOutput } from "../../library/keiyaku-verbs.js";
|
|
2
2
|
import { type TextRenderContext } from "./terminal.js";
|
|
3
|
+
export declare function aliasSelector(selector: string | undefined): string | undefined;
|
|
3
4
|
/** Render native completion values without observing the World or parsing output. */
|
|
4
5
|
export declare function renderVerb<K extends VerbName>(name: K, input: VerbInput<K>, completion: VerbCompletion<VerbOutput<K>>, context: TextRenderContext & Readonly<{
|
|
5
6
|
alias?: string;
|
|
@@ -3,13 +3,13 @@ import { AkumaNameError } from "../../akuma/archetype.js";
|
|
|
3
3
|
import { AkumaAddressError, AkumaWorldScopeError } from "../../library/address.js";
|
|
4
4
|
import { KeiyakuArcDocumentError, KeiyakuUsageError } from "../../library/keiyaku-coordinates.js";
|
|
5
5
|
import { KeiyakuError, projectFailure } from "../../library/outcome.js";
|
|
6
|
-
import { askRawAnswer,
|
|
6
|
+
import { askRawAnswer, historyRawAnswer, historyText, snapshotText, tellControlLines, tellText, waitText, } from "./akuma-activity.js";
|
|
7
7
|
import { renderCallText, renderForkText, renderKillText, renderSpawnFailure, waitedTellProgress } from "./akuma.js";
|
|
8
8
|
import { renderAkumaNameCatalogue, renderContractCatalogue } from "./catalog.js";
|
|
9
9
|
import { renderAkumaBoard } from "./kanshi-akuma.js";
|
|
10
10
|
import { contractIssueLines, renderAccepted, renderContractHistory, renderRetry, } from "./contract.js";
|
|
11
11
|
import { renderDeliveryPreview } from "./delivery-preview.js";
|
|
12
|
-
import {
|
|
12
|
+
import { contractWaitMemberText } from "./contract-wait.js";
|
|
13
13
|
import { renderDebtList, renderDebtMutation, renderDebtShow, renderDebtUpdate, renderDoctor } from "./debt.js";
|
|
14
14
|
import { renderKanshiText } from "./kanshi.js";
|
|
15
15
|
import { renderNukeText } from "./nuke.js";
|
|
@@ -20,7 +20,7 @@ import { renderRegionText } from "./region.js";
|
|
|
20
20
|
import { renderSettingsText } from "./settings.js";
|
|
21
21
|
import { formatNextCall, safeText } from "./terminal.js";
|
|
22
22
|
import { renderWhoami } from "./whoami.js";
|
|
23
|
-
function
|
|
23
|
+
export function aliasSelector(selector) {
|
|
24
24
|
return selector?.startsWith("@") === true ? selector : undefined;
|
|
25
25
|
}
|
|
26
26
|
function missing(operation, contract, context) {
|
|
@@ -114,11 +114,15 @@ function renderRegion(input, result, context) {
|
|
|
114
114
|
return renderRegionText(result, input);
|
|
115
115
|
}
|
|
116
116
|
function renderWait(input, result, context) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
117
|
+
const selectedAlias = input.selectors.length === 1 ? aliasSelector(input.selectors[0]) : undefined;
|
|
118
|
+
const rows = result.members.map((member) => {
|
|
119
|
+
if (member.kind === "contract")
|
|
120
|
+
return contractWaitMemberText(member.observation);
|
|
121
|
+
if (member.observation.kind === "unknown")
|
|
122
|
+
return `? ${member.observation.id} (unobserved)`;
|
|
123
|
+
return waitText({ kind: "akuma", reason: result.reason === "deadline" ? "deadline" : "completed", results: [member.observation] }, selectedAlias === undefined ? {} : { alias: selectedAlias }, context);
|
|
124
|
+
});
|
|
125
|
+
return [result.reason, ...rows].join("\n");
|
|
122
126
|
}
|
|
123
127
|
function renderHistory(query, result, context) {
|
|
124
128
|
const options = query;
|
|
@@ -133,7 +137,7 @@ function renderHistory(query, result, context) {
|
|
|
133
137
|
throw new Error("Akuma history returned a non-Akuma result");
|
|
134
138
|
const id = options.id;
|
|
135
139
|
const last = options.last === true;
|
|
136
|
-
const selectedAlias =
|
|
140
|
+
const selectedAlias = aliasSelector(query.selector);
|
|
137
141
|
return (historyRawAnswer(result, id) ??
|
|
138
142
|
(last && result.kind === "akuma-last"
|
|
139
143
|
? result.answer
|
|
@@ -160,11 +164,11 @@ function renderDebtVerb(name, input, value, context) {
|
|
|
160
164
|
}
|
|
161
165
|
}
|
|
162
166
|
function renderKill(input, value, context) {
|
|
163
|
-
return renderKillText(value,
|
|
167
|
+
return renderKillText(value, aliasSelector(input.akuma), context);
|
|
164
168
|
}
|
|
165
|
-
function
|
|
166
|
-
const selectedAlias =
|
|
167
|
-
if (
|
|
169
|
+
function renderInput(input, result, context) {
|
|
170
|
+
const selectedAlias = aliasSelector(input.akuma);
|
|
171
|
+
if (result.kind === "admitted" || (result.kind === "failed" && "failures" in result))
|
|
168
172
|
return tellText(result, input.prompt, selectedAlias, context);
|
|
169
173
|
const answer = askRawAnswer(result);
|
|
170
174
|
return answer !== undefined && tellControlLines(result, context).length === 0
|
|
@@ -179,10 +183,8 @@ function spawnPresentation(input) {
|
|
|
179
183
|
...(input.contract === undefined ? {} : { contractId: input.contract }),
|
|
180
184
|
};
|
|
181
185
|
}
|
|
182
|
-
/** Spawn's optional observation carries text. */
|
|
183
186
|
function renderSpawn(input, result, context) {
|
|
184
|
-
|
|
185
|
-
return raw ?? renderCallText(result, false, context, spawnPresentation(input));
|
|
187
|
+
return renderCallText(result, context, spawnPresentation(input));
|
|
186
188
|
}
|
|
187
189
|
function renderReport(result, context) {
|
|
188
190
|
const actor = context.actor === undefined ? "" : ` ${context.actor}`;
|
|
@@ -255,7 +257,7 @@ export function renderVerb(name, input, completion, context) {
|
|
|
255
257
|
return renderForkText(value, input);
|
|
256
258
|
case "tell":
|
|
257
259
|
case "ask":
|
|
258
|
-
return
|
|
260
|
+
return renderInput(input, value, context);
|
|
259
261
|
case "kill":
|
|
260
262
|
return renderKill(input, value, context);
|
|
261
263
|
case "wait":
|
package/build/src/cli/runtime.js
CHANGED
|
@@ -5,7 +5,7 @@ import { errorCategory } from "../errors.js";
|
|
|
5
5
|
import { AkumaAddressError, AkumaWorldScopeError, observeNamedAddress, resolveNamedAddress, } 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,7 +151,7 @@ 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 {
|
|
@@ -210,9 +206,7 @@ async function runCommand(invocation, input) {
|
|
|
210
206
|
: await acquireContractRequest(command, runtime)
|
|
211
207
|
: command;
|
|
212
208
|
}
|
|
213
|
-
if (request.name === "
|
|
214
|
-
return await runSpawn(request, runtime);
|
|
215
|
-
if (request.name === "ask" || (request.name === "tell" && request.input.wait !== undefined))
|
|
209
|
+
if (request.name === "ask")
|
|
216
210
|
return await runAsk(request, runtime);
|
|
217
211
|
if (request.name === "history" && !request.input.selector.startsWith("kei/"))
|
|
218
212
|
return await runAkumaHistory(request, runtime);
|
|
@@ -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" } };
|
|
@@ -2,7 +2,6 @@ import { z } from "zod";
|
|
|
2
2
|
import { debtRefSchema, blockedDebtRowSchema, readyDebtRowSchema, debtDoctorIssueSchema, debtSummarySchema, debtDispositionSchema, debtDetailSchema, type BlockedDebtRow, type DebtDetail, type DebtDoctorIssue, type DebtRef, type DebtSummary, type ReadyDebtRow } from "./board.js";
|
|
3
3
|
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
4
|
import type { WorldRoot } from "../world.js";
|
|
5
|
-
export type { WorldRoot } from "../world.js";
|
|
6
5
|
import { DebtAuthorityCorruptionError, type DebtPriority, type DebtState } from "./document.js";
|
|
7
6
|
import { type DebtId } from "./identity.js";
|
|
8
7
|
import { type AddDebtDocumentInput, type AddDebtInput, type UpdateDebtInput } from "./operations.js";
|
package/build/src/debt/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import { debtIdSchema } from "./identity.js";
|
|
|
7
7
|
import { addDebt, addDebtDocument, blockedDebts, listDebts, readDebtDetail, readyDebts, updateDebt, } from "./operations.js";
|
|
8
8
|
import { boundedListLimit } from "../bounded-list.js";
|
|
9
9
|
import { readBoard } from "./store.js";
|
|
10
|
-
import { addDocumentInput, addInput,
|
|
10
|
+
import { addDocumentInput, addInput, fields, debtId as id, updateInput } from "./input.js";
|
|
11
11
|
export const debtAbsentSchema = z.strictObject({ kind: z.literal("absent") }).readonly();
|
|
12
12
|
export const debtReadResultSchema = z.union([
|
|
13
13
|
z.strictObject({ kind: z.literal("present"), ...debtDetailSchema.unwrap().shape }).readonly(),
|
|
@@ -77,8 +77,7 @@ class DebtsHandle {
|
|
|
77
77
|
this.root = world;
|
|
78
78
|
}
|
|
79
79
|
debt(input) {
|
|
80
|
-
const v =
|
|
81
|
-
closed(v, ["id"], "debt input");
|
|
80
|
+
const v = fields(input, ["id"], "debt input");
|
|
82
81
|
return new DebtHandle(id(v.id), this.world);
|
|
83
82
|
}
|
|
84
83
|
add(input) {
|
|
@@ -88,8 +87,7 @@ class DebtsHandle {
|
|
|
88
87
|
return addDebtDocument(this.world, addDocumentInput(input));
|
|
89
88
|
}
|
|
90
89
|
async list(input = {}) {
|
|
91
|
-
const v =
|
|
92
|
-
closed(v, ["selection", "limit"], "list input");
|
|
90
|
+
const v = fields(input, ["selection", "limit"], "list input");
|
|
93
91
|
if (v.selection !== undefined && v.selection !== "active" && v.selection !== "closed" && v.selection !== "all")
|
|
94
92
|
throw new KeiyakuError("invalid-input", "selection must be active, closed, or all");
|
|
95
93
|
return {
|
|
@@ -98,18 +96,15 @@ class DebtsHandle {
|
|
|
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;
|