@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.
Files changed (199) hide show
  1. package/README.md +8 -6
  2. package/build/plugins/claude/skills/keiyaku-akuma/SKILL.md +13 -9
  3. package/build/plugins/claude/skills/keiyaku-babysit/SKILL.md +8 -6
  4. package/build/plugins/claude/skills/keiyaku-workflow/SKILL.md +2 -1
  5. package/build/plugins/codex/skills/keiyaku-akuma/SKILL.md +13 -9
  6. package/build/plugins/codex/skills/keiyaku-babysit/SKILL.md +8 -6
  7. package/build/plugins/codex/skills/keiyaku-workflow/SKILL.md +2 -1
  8. package/build/plugins/opencode/skills/keiyaku-akuma/SKILL.md +13 -9
  9. package/build/plugins/opencode/skills/keiyaku-babysit/SKILL.md +8 -6
  10. package/build/plugins/opencode/skills/keiyaku-workflow/SKILL.md +2 -1
  11. package/build/plugins/pi/README.md +55 -97
  12. package/build/plugins/pi/keiyaku.ts +2 -9
  13. package/build/skills/keiyaku-akuma/SKILL.md +13 -9
  14. package/build/skills/keiyaku-babysit/SKILL.md +8 -6
  15. package/build/skills/keiyaku-workflow/SKILL.md +2 -1
  16. package/build/src/akuma/akuma-instance.d.ts +11 -0
  17. package/build/src/akuma/akuma-instance.js +1 -2
  18. package/build/src/akuma/akuma-observe.js +73 -14
  19. package/build/src/akuma/akuma-selection-execution.d.ts +82 -7
  20. package/build/src/akuma/akuma-selection-execution.js +26 -27
  21. package/build/src/akuma/akuma-wait.d.ts +40 -1
  22. package/build/src/akuma/akuma-wait.js +58 -29
  23. package/build/src/akuma/akuma.d.ts +11 -0
  24. package/build/src/akuma/body.js +13 -18
  25. package/build/src/akuma/call-initial-tell.d.ts +0 -1
  26. package/build/src/akuma/call-initial-tell.js +0 -1
  27. package/build/src/akuma/heart/activity-schema.d.ts +16 -0
  28. package/build/src/akuma/heart/activity-schema.js +7 -0
  29. package/build/src/akuma/heart/index.d.ts +1 -1
  30. package/build/src/akuma/heart/index.js +9 -1
  31. package/build/src/akuma/heart/timeline.js +4 -4
  32. package/build/src/akuma/projection-read.d.ts +4 -2
  33. package/build/src/akuma/projection-read.js +21 -14
  34. package/build/src/akuma/projection.d.ts +94 -2
  35. package/build/src/akuma/projection.js +47 -47
  36. package/build/src/akuma/provider.d.ts +2 -2
  37. package/build/src/akuma/provider.js +27 -20
  38. package/build/src/akuma/providers/acp/core.js +2 -5
  39. package/build/src/akuma/providers/opencode-sdk/events.d.ts +2 -1
  40. package/build/src/akuma/providers/opencode-sdk/events.js +31 -1
  41. package/build/src/akuma/publication.js +3 -2
  42. package/build/src/akuma/selection-observation.d.ts +23 -0
  43. package/build/src/akuma/selection-observation.js +15 -4
  44. package/build/src/akuma/status-projection.d.ts +14 -1
  45. package/build/src/akuma/status-projection.js +40 -2
  46. package/build/src/akuma/turn-drive.js +21 -15
  47. package/build/src/body/amend.js +5 -17
  48. package/build/src/body/decode.js +11 -1
  49. package/build/src/body/envelope.d.ts +5 -1
  50. package/build/src/body/envelope.js +4 -2
  51. package/build/src/body/render.js +4 -6
  52. package/build/src/cli/commands/akuma-grammar.d.ts +3 -5
  53. package/build/src/cli/commands/akuma-grammar.js +22 -40
  54. package/build/src/cli/commands/akuma.d.ts +1 -2
  55. package/build/src/cli/commands/akuma.js +6 -58
  56. package/build/src/cli/commands/contract-grammar.d.ts +1 -0
  57. package/build/src/cli/commands/contract-grammar.js +7 -11
  58. package/build/src/cli/commands/contract-help.d.ts +3 -2
  59. package/build/src/cli/commands/contract-help.js +11 -5
  60. package/build/src/cli/commands/contract.js +3 -0
  61. package/build/src/cli/commands/debt-grammar.js +2 -4
  62. package/build/src/cli/parse.js +1 -4
  63. package/build/src/cli/render/akuma-activity.d.ts +3 -15
  64. package/build/src/cli/render/akuma-activity.js +19 -73
  65. package/build/src/cli/render/akuma.d.ts +5 -11
  66. package/build/src/cli/render/akuma.js +22 -30
  67. package/build/src/cli/render/catalog.js +1 -4
  68. package/build/src/cli/render/contract-history.js +2 -0
  69. package/build/src/cli/render/contract-observation.d.ts +2 -1
  70. package/build/src/cli/render/contract-observation.js +25 -1
  71. package/build/src/cli/render/contract-wait.d.ts +2 -2
  72. package/build/src/cli/render/contract-wait.js +13 -17
  73. package/build/src/cli/render/contract.js +12 -9
  74. package/build/src/cli/render/debt.js +1 -2
  75. package/build/src/cli/render/execution-progress.js +1 -3
  76. package/build/src/cli/render/kanshi-akuma.js +1 -2
  77. package/build/src/cli/render/kanshi.js +11 -17
  78. package/build/src/cli/render/receipt.d.ts +1 -1
  79. package/build/src/cli/render/receipt.js +33 -28
  80. package/build/src/cli/render/reconcile.js +2 -5
  81. package/build/src/cli/render/refusal.js +3 -6
  82. package/build/src/cli/render/terminal.d.ts +2 -4
  83. package/build/src/cli/render/terminal.js +10 -17
  84. package/build/src/cli/render/verbs.d.ts +1 -0
  85. package/build/src/cli/render/verbs.js +19 -17
  86. package/build/src/cli/runtime.js +3 -9
  87. package/build/src/core/facts/codec.js +7 -2
  88. package/build/src/core/facts/eligibility.d.ts +4 -4
  89. package/build/src/core/facts/eligibility.js +11 -0
  90. package/build/src/core/facts/fold.js +9 -5
  91. package/build/src/core/facts/gate.d.ts +5 -1
  92. package/build/src/core/facts/gate.js +14 -10
  93. package/build/src/core/facts/types.d.ts +5 -1
  94. package/build/src/core/facts/types.js +7 -0
  95. package/build/src/core/subject.d.ts +4 -1
  96. package/build/src/core/subject.js +10 -2
  97. package/build/src/core/verbs/amend.d.ts +15 -4
  98. package/build/src/core/verbs/amend.js +19 -9
  99. package/build/src/debt/index.d.ts +0 -1
  100. package/build/src/debt/index.js +6 -11
  101. package/build/src/debt/input.d.ts +2 -1
  102. package/build/src/debt/input.js +6 -4
  103. package/build/src/dispatch/index.d.ts +0 -17
  104. package/build/src/dispatch/index.js +1 -10
  105. package/build/src/git/identity.js +16 -45
  106. package/build/src/git/nuke.js +13 -23
  107. package/build/src/git/observe.d.ts +3 -0
  108. package/build/src/git/observe.js +25 -23
  109. package/build/src/git/process.js +11 -18
  110. package/build/src/git/read-observation.d.ts +5 -4
  111. package/build/src/git/repository.d.ts +2 -0
  112. package/build/src/git/repository.js +13 -1
  113. package/build/src/git/scratch.js +2 -14
  114. package/build/src/git/terminal-reconcile.js +1 -13
  115. package/build/src/index.d.ts +2 -0
  116. package/build/src/kanshi/index.d.ts +0 -1
  117. package/build/src/kanshi/index.js +0 -1
  118. package/build/src/kanshi/read.d.ts +21 -0
  119. package/build/src/kanshi/read.js +2 -1
  120. package/build/src/kanshi/report.d.ts +94 -0
  121. package/build/src/library/address.d.ts +12 -5
  122. package/build/src/library/address.js +18 -32
  123. package/build/src/library/akuma-creation.d.ts +39 -0
  124. package/build/src/library/akuma-creation.js +3 -9
  125. package/build/src/library/continuation.d.ts +10 -0
  126. package/build/src/library/contract-creation.js +10 -11
  127. package/build/src/library/contract-outcomes.d.ts +72 -1
  128. package/build/src/library/contract-outcomes.js +1 -0
  129. package/build/src/library/contract-types.d.ts +18 -0
  130. package/build/src/library/contract-types.js +2 -0
  131. package/build/src/library/contract-wait.d.ts +7 -0
  132. package/build/src/library/contract-wait.js +53 -49
  133. package/build/src/library/delivery.d.ts +25 -0
  134. package/build/src/library/input.d.ts +5 -23
  135. package/build/src/library/input.js +12 -7
  136. package/build/src/library/kei.js +39 -20
  137. package/build/src/library/keiyaku-classify.js +3 -3
  138. package/build/src/library/keiyaku-debt.js +1 -2
  139. package/build/src/library/keiyaku-identity.d.ts +3 -3
  140. package/build/src/library/keiyaku-identity.js +11 -6
  141. package/build/src/library/keiyaku-verbs.d.ts +456 -1362
  142. package/build/src/library/keiyaku-verbs.js +80 -92
  143. package/build/src/library/keiyaku-wait.d.ts +183 -0
  144. package/build/src/library/keiyaku-wait.js +213 -0
  145. package/build/src/library/keiyaku.d.ts +3 -1
  146. package/build/src/library/keiyaku.js +49 -73
  147. package/build/src/{mcp/output.d.ts → library/model-tools.d.ts} +227 -56
  148. package/build/src/library/model-tools.js +347 -0
  149. package/build/src/library/outcome.js +5 -6
  150. package/build/src/library/refusal.d.ts +25 -1
  151. package/build/src/library/refusal.js +4 -5
  152. package/build/src/library/selection.d.ts +12 -0
  153. package/build/src/library/selection.js +1 -2
  154. package/build/src/mcp/adapter.d.ts +0 -6
  155. package/build/src/mcp/adapter.js +10 -159
  156. package/build/src/mcp/description.d.ts +2 -0
  157. package/build/src/mcp/description.js +2 -0
  158. package/build/src/mcp/help.d.ts +1 -1
  159. package/build/src/mcp/help.js +6 -4
  160. package/build/src/pi/index.d.ts +3 -0
  161. package/build/src/pi/index.js +83 -0
  162. package/build/src/protocol/amend.d.ts +14 -3
  163. package/build/src/protocol/amend.js +113 -46
  164. package/build/src/protocol/bind.d.ts +1 -1
  165. package/build/src/protocol/bind.js +5 -16
  166. package/build/src/protocol/completion.d.ts +30 -0
  167. package/build/src/protocol/completion.js +8 -5
  168. package/build/src/protocol/deliver.js +7 -20
  169. package/build/src/protocol/delivery-preview.d.ts +5 -0
  170. package/build/src/protocol/execution-observation.d.ts +8 -0
  171. package/build/src/protocol/intent.d.ts +1 -0
  172. package/build/src/protocol/intent.js +4 -1
  173. package/build/src/protocol/operations.d.ts +54 -16
  174. package/build/src/protocol/operations.js +17 -31
  175. package/build/src/protocol/placement.js +7 -1
  176. package/build/src/protocol/progress.js +0 -6
  177. package/build/src/protocol/read/status.d.ts +40 -0
  178. package/build/src/protocol/read/status.js +7 -10
  179. package/build/src/protocol/reintegrate.js +2 -2
  180. package/build/src/protocol/result-leaves.d.ts +56 -8
  181. package/build/src/protocol/result-leaves.js +11 -2
  182. package/build/src/protocol/run.js +1 -4
  183. package/build/src/protocol/verify.d.ts +10 -0
  184. package/build/src/protocol/verify.js +1 -0
  185. package/build/src/runtime/proc/windows-launch.exe +0 -0
  186. package/build/src/settlement/settle.js +19 -68
  187. package/package.json +7 -3
  188. package/plugins/pi/README.md +55 -97
  189. package/plugins/pi/keiyaku.ts +2 -9
  190. package/skills/keiyaku-akuma/SKILL.md +13 -9
  191. package/skills/keiyaku-babysit/SKILL.md +8 -6
  192. package/skills/keiyaku-workflow/SKILL.md +2 -1
  193. package/build/plugins/pi/akuma-tools.ts +0 -283
  194. package/build/src/body/keys.d.ts +0 -4
  195. package/build/src/body/keys.js +0 -11
  196. package/build/src/kanshi/roster.d.ts +0 -2
  197. package/build/src/kanshi/roster.js +0 -2
  198. package/build/src/mcp/output.js +0 -193
  199. 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] ?? 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, words(refusal.reason)),
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 one body grapheme plus its omission and any diagnostic omission before clipping the prefix.
188
- // All budgets are nonnegative; sharing spare cells monotonically keeps wider rows from reducing the body allowance.
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, callRawAnswer, historyRawAnswer, historyText, snapshotText, tellControlLines, tellText, waitText, } from "./akuma-activity.js";
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 { contractWaitText } from "./contract-wait.js";
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 alias(selector) {
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
- if ("contracts" in result)
118
- return contractWaitText(result);
119
- const selectors = input.selectors;
120
- const selectedAlias = selectors.length === 1 ? alias(selectors[0]) : undefined;
121
- return waitText(result, selectedAlias === undefined ? {} : { alias: selectedAlias }, context);
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 = alias(query.selector);
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, alias(input.akuma), context);
167
+ return renderKillText(value, aliasSelector(input.akuma), context);
164
168
  }
165
- function renderAsk(input, result, context) {
166
- const selectedAlias = alias(input.akuma);
167
- if ((result.kind === "admitted" || (result.kind === "failed" && "failures" in result)) && result.input === undefined)
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
- const raw = callRawAnswer(result, false);
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 renderAsk(input, value, context);
260
+ return renderInput(input, value, context);
259
261
  case "kill":
260
262
  return renderKill(input, value, context);
261
263
  case "wait":
@@ -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, runSpawn, runAsk, runAkumaHistory } from "./commands/akuma.js";
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 = homeFromEnvironment(environment);
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 === "spawn")
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
- return termsValue(value, path);
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
- type EligibilityObservation = ContractsObservation;
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: EligibilityObservation): boolean;
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: cloneCoordinates(bind.data.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 { ...state, terms: cloneTerms(entry.data) };
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 currentChange = state.currentIntegration?.changeId ?? state.delivery?.data.integration.changeId;
6
- if (currentChange === undefined)
5
+ const integration = state.currentIntegration ?? state.delivery?.data.integration;
6
+ if (integration === undefined)
7
7
  return undefined;
8
- const previousChange = dependencyKeys(previous.data.subject).find((key) => key.kind === "change")?.value;
9
- if (previousChange === undefined || previousChange === currentChange)
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 value = decodeDependencyKeySet(subject).encodedKeys.every((key) => available.has(key));
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
- source?: ContractTerms;
7
- preparation?: Preparation<AmendData, Failure>;
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>>): OfferDecision<AmendRefusal | 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
- if (input.preparation === undefined || input.source === undefined) {
10
- throw new Error("existing contract requires an amend preparation and source terms");
11
- }
12
- const source = input.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 (input.preparation.kind === "refused")
31
- return { kind: "refused", refusal: input.preparation.refusal };
32
- const { data } = input.preparation;
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";
@@ -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, closed, record, debtId as id, updateInput } from "./input.js";
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 = record(input, "debt input");
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 = record(input, "list input");
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 = record(input, "ready input");
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 = record(input, "blocked input");
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 = record(input, "read input");
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
- export declare function closed(value: Record<string, unknown>, allowed: readonly string[], label: string): void;
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;