@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.
Files changed (244) hide show
  1. package/README.md +18 -7
  2. package/build/plugins/claude/skills/keiyaku-akuma/SKILL.md +18 -11
  3. package/build/plugins/claude/skills/keiyaku-babysit/SKILL.md +8 -6
  4. package/build/plugins/claude/skills/keiyaku-debt/SKILL.md +2 -1
  5. package/build/plugins/claude/skills/keiyaku-workflow/SKILL.md +2 -1
  6. package/build/plugins/codex/skills/keiyaku-akuma/SKILL.md +18 -11
  7. package/build/plugins/codex/skills/keiyaku-babysit/SKILL.md +8 -6
  8. package/build/plugins/codex/skills/keiyaku-debt/SKILL.md +2 -1
  9. package/build/plugins/codex/skills/keiyaku-workflow/SKILL.md +2 -1
  10. package/build/plugins/opencode/skills/keiyaku-akuma/SKILL.md +18 -11
  11. package/build/plugins/opencode/skills/keiyaku-babysit/SKILL.md +8 -6
  12. package/build/plugins/opencode/skills/keiyaku-debt/SKILL.md +2 -1
  13. package/build/plugins/opencode/skills/keiyaku-workflow/SKILL.md +2 -1
  14. package/build/plugins/pi/README.md +55 -97
  15. package/build/plugins/pi/keiyaku.ts +1 -142
  16. package/build/skills/keiyaku-akuma/SKILL.md +18 -11
  17. package/build/skills/keiyaku-babysit/SKILL.md +8 -6
  18. package/build/skills/keiyaku-debt/SKILL.md +2 -1
  19. package/build/skills/keiyaku-workflow/SKILL.md +2 -1
  20. package/build/src/akuma/akuma-instance.d.ts +11 -0
  21. package/build/src/akuma/akuma-instance.js +1 -2
  22. package/build/src/akuma/akuma-observe.d.ts +8 -0
  23. package/build/src/akuma/akuma-observe.js +81 -14
  24. package/build/src/akuma/akuma-owner.d.ts +1 -0
  25. package/build/src/akuma/akuma-owner.js +3 -5
  26. package/build/src/akuma/akuma-selection-execution.d.ts +82 -7
  27. package/build/src/akuma/akuma-selection-execution.js +26 -27
  28. package/build/src/akuma/akuma-wait.d.ts +155 -1
  29. package/build/src/akuma/akuma-wait.js +94 -34
  30. package/build/src/akuma/akuma.d.ts +17 -1
  31. package/build/src/akuma/akuma.js +37 -18
  32. package/build/src/akuma/body.js +13 -18
  33. package/build/src/akuma/call-initial-tell.d.ts +0 -1
  34. package/build/src/akuma/call-initial-tell.js +0 -1
  35. package/build/src/akuma/heart/activity-schema.d.ts +16 -0
  36. package/build/src/akuma/heart/activity-schema.js +7 -0
  37. package/build/src/akuma/heart/facts.d.ts +1 -0
  38. package/build/src/akuma/heart/facts.js +14 -0
  39. package/build/src/akuma/heart/index.d.ts +7 -1
  40. package/build/src/akuma/heart/index.js +35 -9
  41. package/build/src/akuma/heart/rows.d.ts +1 -0
  42. package/build/src/akuma/heart/rows.js +4 -0
  43. package/build/src/akuma/heart/timeline.js +4 -4
  44. package/build/src/akuma/lineage-cache.d.ts +7 -2
  45. package/build/src/akuma/lineage-cache.js +48 -24
  46. package/build/src/akuma/projection-read.d.ts +4 -2
  47. package/build/src/akuma/projection-read.js +25 -23
  48. package/build/src/akuma/projection.d.ts +94 -2
  49. package/build/src/akuma/projection.js +47 -47
  50. package/build/src/akuma/provider.d.ts +2 -2
  51. package/build/src/akuma/provider.js +27 -20
  52. package/build/src/akuma/providers/acp/core.js +2 -5
  53. package/build/src/akuma/providers/opencode-sdk/events.d.ts +2 -1
  54. package/build/src/akuma/providers/opencode-sdk/events.js +31 -1
  55. package/build/src/akuma/publication.js +3 -2
  56. package/build/src/akuma/selection-observation.d.ts +645 -0
  57. package/build/src/akuma/selection-observation.js +22 -7
  58. package/build/src/akuma/status-projection.d.ts +14 -1
  59. package/build/src/akuma/status-projection.js +40 -2
  60. package/build/src/akuma/turn-drive.js +21 -15
  61. package/build/src/body/amend.js +5 -17
  62. package/build/src/body/decode.js +11 -1
  63. package/build/src/body/envelope.d.ts +5 -1
  64. package/build/src/body/envelope.js +4 -2
  65. package/build/src/body/render.js +4 -6
  66. package/build/src/bounded-list.d.ts +8 -0
  67. package/build/src/bounded-list.js +10 -0
  68. package/build/src/cli/commands/akuma-grammar.d.ts +5 -8
  69. package/build/src/cli/commands/akuma-grammar.js +52 -77
  70. package/build/src/cli/commands/akuma.d.ts +1 -2
  71. package/build/src/cli/commands/akuma.js +12 -61
  72. package/build/src/cli/commands/contract-grammar.d.ts +1 -0
  73. package/build/src/cli/commands/contract-grammar.js +39 -42
  74. package/build/src/cli/commands/contract-help.d.ts +6 -5
  75. package/build/src/cli/commands/contract-help.js +21 -13
  76. package/build/src/cli/commands/contract.d.ts +3 -3
  77. package/build/src/cli/commands/contract.js +13 -9
  78. package/build/src/cli/commands/debt-grammar.js +2 -4
  79. package/build/src/cli/parse.d.ts +4 -10
  80. package/build/src/cli/parse.js +2 -5
  81. package/build/src/cli/render/akuma-activity.d.ts +12 -34
  82. package/build/src/cli/render/akuma-activity.js +99 -180
  83. package/build/src/cli/render/akuma.d.ts +5 -11
  84. package/build/src/cli/render/akuma.js +22 -30
  85. package/build/src/cli/render/catalog.js +4 -6
  86. package/build/src/cli/render/contract-history.d.ts +1 -3
  87. package/build/src/cli/render/contract-history.js +70 -49
  88. package/build/src/cli/render/contract-observation.d.ts +2 -1
  89. package/build/src/cli/render/contract-observation.js +25 -1
  90. package/build/src/cli/render/contract-wait.d.ts +2 -2
  91. package/build/src/cli/render/contract-wait.js +21 -17
  92. package/build/src/cli/render/contract.js +12 -9
  93. package/build/src/cli/render/debt.js +1 -2
  94. package/build/src/cli/render/execution-progress.js +1 -3
  95. package/build/src/cli/render/kanshi-akuma.d.ts +4 -3
  96. package/build/src/cli/render/kanshi-akuma.js +27 -23
  97. package/build/src/cli/render/kanshi.js +45 -60
  98. package/build/src/cli/render/receipt.d.ts +1 -1
  99. package/build/src/cli/render/receipt.js +33 -28
  100. package/build/src/cli/render/reconcile.js +2 -5
  101. package/build/src/cli/render/refusal.js +3 -6
  102. package/build/src/cli/render/terminal.d.ts +2 -4
  103. package/build/src/cli/render/terminal.js +10 -17
  104. package/build/src/cli/render/verbs.d.ts +1 -0
  105. package/build/src/cli/render/verbs.js +39 -34
  106. package/build/src/cli/runtime.js +12 -32
  107. package/build/src/core/facts/codec.js +7 -2
  108. package/build/src/core/facts/eligibility.d.ts +4 -4
  109. package/build/src/core/facts/eligibility.js +11 -0
  110. package/build/src/core/facts/fold.js +9 -5
  111. package/build/src/core/facts/gate.d.ts +5 -1
  112. package/build/src/core/facts/gate.js +14 -10
  113. package/build/src/core/facts/types.d.ts +5 -1
  114. package/build/src/core/facts/types.js +7 -0
  115. package/build/src/core/subject.d.ts +4 -1
  116. package/build/src/core/subject.js +10 -2
  117. package/build/src/core/verbs/amend.d.ts +15 -4
  118. package/build/src/core/verbs/amend.js +19 -9
  119. package/build/src/debt/board.d.ts +2 -1
  120. package/build/src/debt/board.js +3 -3
  121. package/build/src/debt/catalog.js +2 -1
  122. package/build/src/debt/document.d.ts +1 -0
  123. package/build/src/debt/document.js +3 -0
  124. package/build/src/debt/index.d.ts +2 -2
  125. package/build/src/debt/index.js +9 -14
  126. package/build/src/debt/input.d.ts +2 -1
  127. package/build/src/debt/input.js +6 -4
  128. package/build/src/debt/operations.d.ts +2 -1
  129. package/build/src/dispatch/index.d.ts +0 -17
  130. package/build/src/dispatch/index.js +1 -10
  131. package/build/src/git/identity.js +16 -45
  132. package/build/src/git/nuke.js +13 -23
  133. package/build/src/git/observe.d.ts +7 -3
  134. package/build/src/git/observe.js +29 -26
  135. package/build/src/git/process.js +11 -18
  136. package/build/src/git/read-observation.d.ts +5 -4
  137. package/build/src/git/repository.d.ts +2 -0
  138. package/build/src/git/repository.js +13 -1
  139. package/build/src/git/scratch.js +2 -14
  140. package/build/src/git/terminal-reconcile.js +1 -13
  141. package/build/src/history.d.ts +26 -0
  142. package/build/src/history.js +43 -0
  143. package/build/src/index.d.ts +6 -3
  144. package/build/src/kanshi/counts.d.ts +15 -1
  145. package/build/src/kanshi/counts.js +14 -3
  146. package/build/src/kanshi/index.d.ts +3 -4
  147. package/build/src/kanshi/index.js +2 -3
  148. package/build/src/kanshi/read.d.ts +21 -0
  149. package/build/src/kanshi/read.js +7 -3
  150. package/build/src/kanshi/report.d.ts +94 -0
  151. package/build/src/library/address.d.ts +12 -5
  152. package/build/src/library/address.js +18 -32
  153. package/build/src/library/akuma-creation.d.ts +39 -0
  154. package/build/src/library/akuma-creation.js +3 -9
  155. package/build/src/library/akumas.d.ts +5 -1
  156. package/build/src/library/akumas.js +11 -5
  157. package/build/src/library/continuation.d.ts +10 -0
  158. package/build/src/library/contract-composition.js +10 -10
  159. package/build/src/library/contract-creation.js +12 -13
  160. package/build/src/library/contract-outcomes.d.ts +72 -1
  161. package/build/src/library/contract-outcomes.js +1 -0
  162. package/build/src/library/contract-types.d.ts +233 -25
  163. package/build/src/library/contract-types.js +32 -12
  164. package/build/src/library/contract-wait.d.ts +212 -0
  165. package/build/src/library/contract-wait.js +65 -49
  166. package/build/src/library/delivery.d.ts +25 -0
  167. package/build/src/library/input.d.ts +8 -26
  168. package/build/src/library/input.js +17 -12
  169. package/build/src/library/kei.js +167 -90
  170. package/build/src/library/keiyaku-attribution.d.ts +1 -1
  171. package/build/src/library/keiyaku-attribution.js +3 -1
  172. package/build/src/library/keiyaku-classify.js +8 -4
  173. package/build/src/library/keiyaku-debt.d.ts +8 -7
  174. package/build/src/library/keiyaku-debt.js +1 -2
  175. package/build/src/library/keiyaku-identity.d.ts +4 -3
  176. package/build/src/library/keiyaku-identity.js +35 -7
  177. package/build/src/library/keiyaku-verbs.d.ts +974 -1409
  178. package/build/src/library/keiyaku-verbs.js +154 -161
  179. package/build/src/library/keiyaku-wait.d.ts +753 -0
  180. package/build/src/library/keiyaku-wait.js +230 -0
  181. package/build/src/library/keiyaku.d.ts +3110 -29
  182. package/build/src/library/keiyaku.js +342 -438
  183. package/build/src/library/model-tools.d.ts +754 -0
  184. package/build/src/library/model-tools.js +362 -0
  185. package/build/src/library/outcome.js +5 -6
  186. package/build/src/library/refusal.d.ts +25 -1
  187. package/build/src/library/refusal.js +4 -5
  188. package/build/src/library/selection.d.ts +18 -5
  189. package/build/src/library/selection.js +11 -5
  190. package/build/src/mcp/adapter.d.ts +0 -6
  191. package/build/src/mcp/adapter.js +11 -160
  192. package/build/src/mcp/description.d.ts +2 -0
  193. package/build/src/mcp/description.js +2 -0
  194. package/build/src/mcp/help.d.ts +1 -1
  195. package/build/src/mcp/help.js +10 -7
  196. package/build/src/pi/index.d.ts +5 -0
  197. package/build/src/pi/index.js +99 -0
  198. package/build/src/pi/status.d.ts +12 -0
  199. package/build/src/pi/status.js +140 -0
  200. package/build/src/protocol/amend.d.ts +14 -3
  201. package/build/src/protocol/amend.js +113 -46
  202. package/build/src/protocol/bind.d.ts +1 -1
  203. package/build/src/protocol/bind.js +5 -16
  204. package/build/src/protocol/completion.d.ts +30 -0
  205. package/build/src/protocol/completion.js +8 -5
  206. package/build/src/protocol/deliver.js +7 -20
  207. package/build/src/protocol/delivery-preview.d.ts +5 -0
  208. package/build/src/protocol/execution-observation.d.ts +8 -0
  209. package/build/src/protocol/intent.d.ts +1 -0
  210. package/build/src/protocol/intent.js +4 -1
  211. package/build/src/protocol/operations.d.ts +56 -16
  212. package/build/src/protocol/operations.js +18 -32
  213. package/build/src/protocol/placement.js +7 -1
  214. package/build/src/protocol/progress.js +0 -6
  215. package/build/src/protocol/read/status.d.ts +52 -4
  216. package/build/src/protocol/read/status.js +26 -22
  217. package/build/src/protocol/reintegrate.js +2 -2
  218. package/build/src/protocol/result-leaves.d.ts +56 -8
  219. package/build/src/protocol/result-leaves.js +11 -2
  220. package/build/src/protocol/run.js +1 -4
  221. package/build/src/protocol/verify.d.ts +10 -0
  222. package/build/src/protocol/verify.js +1 -0
  223. package/build/src/runtime/proc/windows-launch.exe +0 -0
  224. package/build/src/settlement/settle.js +19 -68
  225. package/package.json +7 -3
  226. package/plugins/paseo/plugin/index.server.ts +6 -2
  227. package/plugins/paseo/plugin/server/attach.ts +68 -48
  228. package/plugins/paseo/plugin/server/directory.ts +259 -0
  229. package/plugins/paseo/plugin/server/mirror-identity.ts +3 -32
  230. package/plugins/paseo/plugin/server/reopen.ts +52 -38
  231. package/plugins/pi/README.md +55 -97
  232. package/plugins/pi/keiyaku.ts +1 -142
  233. package/skills/keiyaku-akuma/SKILL.md +18 -11
  234. package/skills/keiyaku-babysit/SKILL.md +8 -6
  235. package/skills/keiyaku-debt/SKILL.md +2 -1
  236. package/skills/keiyaku-workflow/SKILL.md +2 -1
  237. package/build/plugins/pi/akuma-tools.ts +0 -283
  238. package/build/src/body/keys.d.ts +0 -4
  239. package/build/src/body/keys.js +0 -11
  240. package/build/src/kanshi/roster.d.ts +0 -2
  241. package/build/src/kanshi/roster.js +0 -2
  242. package/build/src/mcp/output.d.ts +0 -385
  243. package/build/src/mcp/output.js +0 -193
  244. package/plugins/pi/akuma-tools.ts +0 -283
@@ -1,5 +1,6 @@
1
1
  /** @architectureCompositionRoot */
2
2
  import { isAbsolute, resolve } from "node:path";
3
+ import { requireOwner } from "@astrosheep/square";
3
4
  import { parseDuration } from "../duration.js";
4
5
  import { ZodError } from "zod";
5
6
  import { verbs, } from "./keiyaku-verbs.js";
@@ -8,6 +9,8 @@ import { World, WorldError } from "../world.js";
8
9
  import { Akuma } from "../akuma/akuma-instance.js";
9
10
  import { Kanshi } from "../kanshi/index.js";
10
11
  import { Akumas } from "./akumas.js";
12
+ import { observeNamedAddress, resolveNamedAddress } from "./address.js";
13
+ import { waitInvocation } from "./keiyaku-wait.js";
11
14
  import { deliveryOwner } from "./keiyaku-attribution.js";
12
15
  import { akumaCallerFromEnvironment } from "./keiyaku-identity.js";
13
16
  import { contractId } from "../core/facts/types.js";
@@ -21,19 +24,43 @@ import { nukeKeiyaku } from "./nuke.js";
21
24
  import * as debt from "./keiyaku-debt.js";
22
25
  import { validateAkumaName } from "../identity/normalize.js";
23
26
  export { KeiyakuArcDocumentError, KeiyakuUsageError } from "./keiyaku-coordinates.js";
24
- function waitTimeout(wait) {
25
- const duration = parseDuration(wait);
27
+ function executionSignal(controls) {
28
+ return controls.signal === undefined ? {} : { signal: controls.signal };
29
+ }
30
+ function mutationProgress(controls) {
31
+ return controls.observe === undefined ? undefined : { observe: controls.observe };
32
+ }
33
+ function observationTimeout(timeout) {
34
+ const duration = parseDuration(timeout);
26
35
  if (duration.kind !== "parsed")
27
- throw new KeiyakuUsageError("invalid wait duration");
36
+ throw new KeiyakuUsageError("invalid timeout duration");
28
37
  return duration.milliseconds;
29
38
  }
30
39
  export class Keiyaku {
31
40
  static verbs = verbs;
32
41
  #input;
33
42
  constructor(input) {
34
- this.#input = { ...input, environment: { ...input.environment } };
43
+ let owner;
44
+ const identity = input.identity;
45
+ if (identity !== undefined) {
46
+ try {
47
+ if (typeof identity !== "object" || identity === null || Array.isArray(identity))
48
+ throw new Error("identity must be an object");
49
+ owner = requireOwner(identity.owner);
50
+ if (!owner.trim())
51
+ throw new Error("owner must be nonblank");
52
+ }
53
+ catch (error) {
54
+ throw new KeiyakuUsageError(`invalid identity: ${error instanceof Error ? error.message : String(error)}`);
55
+ }
56
+ }
57
+ this.#input = {
58
+ ...input,
59
+ environment: { ...input.environment },
60
+ ...(owner === undefined ? {} : { identity: { owner } }),
61
+ };
35
62
  }
36
- static at(input) {
63
+ static for(input) {
37
64
  if (typeof input?.cwd !== "string" || !isAbsolute(input.cwd))
38
65
  throw new KeiyakuUsageError("cwd must be an absolute string");
39
66
  if (typeof input.environment !== "object" ||
@@ -69,214 +96,312 @@ export class Keiyaku {
69
96
  /* Observation cannot affect execution. */
70
97
  }
71
98
  };
72
- return (await this.#dispatch({ name, input: parsed }, run, notify));
99
+ return this.#execute[name](parsed, {
100
+ ...executionSignal(run ?? {}),
101
+ ...(observe === undefined ? {} : { observe: notify }),
102
+ });
73
103
  }
74
- async #dispatch(request, run, notify) {
75
- const signal = run?.signal === undefined ? {} : { signal: run.signal };
76
- const progress = run?.observe === undefined ? undefined : { observe: notify };
77
- switch (request.name) {
78
- case "bind":
79
- return this.#bind(request.input);
80
- case "amend":
81
- return this.#amend(request.input);
82
- case "arc":
83
- return this.#arc(request.input);
84
- case "deliver":
85
- return this.#deliver({ ...request.input, ...signal }, progress);
86
- case "verify":
87
- return this.#verify({ ...request.input, ...signal }, progress);
88
- case "review":
89
- return this.#review({ ...request.input, ...signal }, progress);
90
- case "abandon":
91
- return this.#abandon(request.input);
92
- case "show":
93
- return this.#show(request.input);
94
- case "reconcile":
95
- return this.#reconcile(request.input);
96
- case "spawn":
97
- case "fork":
98
- case "tell":
99
- case "ask":
100
- case "kill":
101
- case "wait":
102
- case "history":
103
- case "report":
104
- return this.#dispatchAkuma(request, run, notify);
105
- case "whoami":
106
- return this.#whoami();
107
- case "settings":
108
- return this.#settings();
109
- case "nuke":
110
- return this.#nuke(request.input);
111
- case "kanshi": {
112
- const at = await this.#coordinates("optional");
113
- return Kanshi.of({ world: at.world, ...(at.repo === undefined ? {} : { repo: at.repo }) }).board();
104
+ #execute = {
105
+ bind: async (input) => {
106
+ const { library } = await this.#keis();
107
+ if ("forkOf" in input)
108
+ return await library.bind({
109
+ ...input,
110
+ forkOf: this.#fullId(library, input.forkOf),
111
+ });
112
+ const { after, ...rest } = input;
113
+ return await library.bind({
114
+ ...rest,
115
+ ...(after === undefined ? {} : { after: after.map((id) => this.#fullId(library, id)) }),
116
+ });
117
+ },
118
+ amend: async ({ contract, ...input }) => {
119
+ const { cwd, library } = await this.#keis();
120
+ const id = await this.#resolve(library, contract, cwd);
121
+ const { after, ...rest } = input;
122
+ return await library.kei({ id }).amend({
123
+ ...rest,
124
+ ...(after === undefined ? {} : { after: after.map((value) => this.#fullId(library, value)) }),
125
+ });
126
+ },
127
+ arc: async ({ contract, ...input }) => {
128
+ const selected = await this.#selected(contract);
129
+ try {
130
+ validateArcMarkdown(input.body);
131
+ }
132
+ catch (error) {
133
+ if (errorCategory(error) === "invalid-input")
134
+ throw new KeiyakuArcDocumentError(selected.id, error);
135
+ throw error;
114
136
  }
115
- case "status": {
116
- const at = await this.#coordinates("optional");
117
- if (request.input.id.startsWith("aku/")) {
118
- if (at.world === null)
119
- throw new KeiyakuUsageError("no Keiyaku world contains the invocation cwd");
120
- return Akumas.of(at.world).status({
121
- akuma: request.input.id,
122
- ...(at.repo === undefined ? {} : { repo: at.repo }),
123
- });
124
- }
137
+ return await selected.contract.arc(input);
138
+ },
139
+ deliver: async ({ contract, ...input }, controls) => {
140
+ const selected = (await this.#selected(contract)).contract;
141
+ const { dryRun, ...native } = input;
142
+ return dryRun
143
+ ? await selected.previewDelivery({ ...native, ...executionSignal(controls) }, mutationProgress(controls))
144
+ : await selected.deliver({ ...native, ...executionSignal(controls) }, mutationProgress(controls));
145
+ },
146
+ verify: async ({ contract, ...input }, controls) => {
147
+ return await (await this.#selected(contract)).contract.verify({ ...input, ...executionSignal(controls) }, mutationProgress(controls));
148
+ },
149
+ review: async ({ contract, ...input }, controls) => {
150
+ const selected = await this.#selected(contract);
151
+ return await selected.contract.review({ ...input, ...executionSignal(controls) }, mutationProgress(controls));
152
+ },
153
+ abandon: async ({ contract, ...input }) => {
154
+ const selected = await this.#selected(contract);
155
+ return await selected.contract.abandon(input);
156
+ },
157
+ show: async ({ selector }) => {
158
+ if (selector.startsWith("debt/"))
159
+ return debt.debtShow(this.#input, selector);
160
+ return await (await this.#selected(selector)).contract.guidance();
161
+ },
162
+ reconcile: async (input) => {
163
+ const { cwd, library } = await this.#keis();
164
+ if (input.contract === undefined)
165
+ return await library.reconcile(input);
166
+ const id = await this.#resolve(library, input.contract, cwd);
167
+ return await library.reconcile({ ...input, contract: id });
168
+ },
169
+ spawn: async ({ prompt, contract, workdir, alias, ...input }, controls) => {
170
+ const at = await this.#coordinates(contract === undefined ? "none" : "required");
171
+ const cwd = workdir === undefined
172
+ ? at.cwd
173
+ : await canonicalBirthCwd(resolve(at.cwd, workdir), `workdir is not an existing directory: ${workdir}`);
174
+ const caller = await this.#caller();
175
+ const initiator = deliveryOwner(this.#input.environment, this.#input.identity?.owner);
176
+ const world = at.candidateWorld ?? (await at.establishWorld());
177
+ await World.at(world);
178
+ const configuration = await Settings.load({
179
+ cwd: world,
180
+ ...(this.#input.home === undefined ? {} : { home: this.#input.home }),
181
+ });
182
+ const selected = contract === undefined ? undefined : Keis.of(at.repo).kei({ id: this.#fullId(Keis.of(at.repo), contract) });
183
+ return await Akumas.of(world).spawn({
184
+ ...input,
185
+ ...executionSignal(controls),
186
+ cwd,
187
+ settings: configuration,
188
+ ...(alias === undefined ? {} : { alias: alias }),
189
+ ...(this.#input.home === undefined ? {} : { home: this.#input.home }),
190
+ ...(prompt === undefined ? {} : { body: prompt }),
191
+ ...(selected === undefined ? {} : { contract: selected }),
192
+ ...(caller === undefined ? {} : { caller }),
193
+ ...(initiator === undefined ? {} : { initiator }),
194
+ });
195
+ },
196
+ fork: async (input) => {
197
+ const { at, akumas } = await this.#akumas();
198
+ const caller = await this.#caller();
199
+ const initiator = deliveryOwner(this.#input.environment, this.#input.identity?.owner);
200
+ return await akumas.fork({
201
+ ...input,
202
+ ...(at.repo === undefined ? {} : { repo: at.repo }),
203
+ ...(caller === undefined ? {} : { caller }),
204
+ ...(initiator === undefined ? {} : { initiator }),
205
+ });
206
+ },
207
+ tell: (input, controls) => this.#tell({ name: "tell", input }, executionSignal(controls)),
208
+ ask: (input, controls) => this.#tell({ name: "ask", input }, {
209
+ ...executionSignal(controls),
210
+ ...(controls.observe === undefined
211
+ ? {}
212
+ : {
213
+ observe: {
214
+ admitted: (tell, id) => controls.observe?.({ kind: "admitted", tell, id }),
215
+ observe: (observation) => controls.observe?.({ kind: "live", observation }),
216
+ },
217
+ }),
218
+ }),
219
+ kill: async (input, controls) => {
220
+ const { at, akumas } = await this.#akumas();
221
+ return await akumas.kill({
222
+ ...input,
223
+ ...executionSignal(controls),
224
+ ...(at.repo === undefined ? {} : { repo: at.repo }),
225
+ });
226
+ },
227
+ wait: async ({ selectors, timeout, ...input }, controls) => {
228
+ const hasContracts = selectors.some((selector) => selector.startsWith("kei/"));
229
+ const contractOnly = selectors.every((selector) => selector.startsWith("kei/"));
230
+ const at = await this.#coordinates(hasContracts ? "required" : "optional", contractOnly);
231
+ if (hasContracts && at.repo === undefined)
232
+ throw new KeiyakuUsageError("Contract wait requires a repository");
233
+ if (!contractOnly && at.world === null)
234
+ throw new KeiyakuUsageError("Akuma wait requires a World");
235
+ return await waitInvocation({
236
+ selectors,
237
+ ...input,
238
+ ...executionSignal(controls),
239
+ ...(at.repo === undefined ? {} : { repo: at.repo }),
240
+ ...(at.world === null ? {} : { world: at.world }),
241
+ ...(timeout === undefined ? {} : { timeoutMs: observationTimeout(timeout) }),
242
+ });
243
+ },
244
+ history: async ({ selector, ...input }) => {
245
+ if (selector.startsWith("kei/")) {
246
+ const at = await this.#coordinates("required");
125
247
  if (at.repo === undefined)
126
248
  throw new KeiyakuUsageError("this command requires a resolved Repo");
127
- const report = await Kanshi.of({ world: at.world, repo: at.repo }).contract(contractId(request.input.id));
128
- if (report.kind === "contract-absent")
129
- throw new Error("Contract observation with a Repo cannot be absent");
130
- return report;
249
+ const library = Keis.of(at.repo);
250
+ return await library.kei({ id: this.#fullId(library, selector) }).history(input);
131
251
  }
132
- case "region":
133
- return this.#region(request.input);
134
- case "ls":
135
- return this.#ls(request.input);
136
- default:
137
- return this.#dispatchDebt(request, signal);
138
- }
139
- }
140
- async #dispatchAkuma(request, run, notify) {
141
- const signal = run?.signal === undefined ? {} : { signal: run.signal };
142
- const observe = run?.observe;
143
- switch (request.name) {
144
- case "spawn": {
145
- return this.#spawn({
146
- ...request.input,
147
- ...signal,
148
- ...(observe === undefined
149
- ? {}
150
- : {
151
- observe: {
152
- admitted: (tell, id, head) => notify({ kind: "admitted", tell, id, head }),
153
- observe: (observation) => notify({ kind: "live", observation }),
154
- },
155
- }),
252
+ const { at, akumas } = await this.#akumas();
253
+ return await akumas.history({
254
+ akuma: selector,
255
+ ...("item" in input ? (input.item === "answer" ? { last: true } : { id: input.item }) : input),
256
+ ...(at.repo === undefined ? {} : { repo: at.repo }),
257
+ });
258
+ },
259
+ report: async (input, controls) => {
260
+ await this.#coordinates("none");
261
+ let caller;
262
+ try {
263
+ caller = await this.#caller();
264
+ }
265
+ catch (error) {
266
+ if (error instanceof WorldError)
267
+ throw new KeiyakuUsageError(error.message);
268
+ throw error;
269
+ }
270
+ if (caller?.kind !== "akuma")
271
+ throw new KeiyakuUsageError(this.#input.identity === undefined
272
+ ? "report requires explicit KEIYAKU_ACTOR_ID and KEIYAKU_ACTOR_WORLD"
273
+ : "report requires explicit Akuma execution identity");
274
+ return Akuma.select(caller.world, caller.akumaId).report(input.text, executionSignal(controls));
275
+ },
276
+ whoami: async () => {
277
+ return await whoami(await this.#coordinates("optional"), this.#input.environment, this.#input.identity?.owner);
278
+ },
279
+ settings: async () => {
280
+ const at = await this.#coordinates("none");
281
+ return await Settings.load({
282
+ ...(at.world === null ? {} : { cwd: at.world }),
283
+ ...(this.#input.home === undefined ? {} : { home: this.#input.home }),
284
+ });
285
+ },
286
+ nuke: async (input) => {
287
+ const at = await this.#coordinates("none");
288
+ if (at.world === null)
289
+ throw new KeiyakuUsageError("no Keiyaku world contains the invocation cwd");
290
+ return await nukeKeiyaku({ world: at.world, ...input });
291
+ },
292
+ kanshi: async () => {
293
+ const at = await this.#coordinates("optional");
294
+ return Kanshi.of({ world: at.world, ...(at.repo === undefined ? {} : { repo: at.repo }) }).board();
295
+ },
296
+ status: async (input) => {
297
+ const at = await this.#coordinates("optional");
298
+ const selector = input.selector;
299
+ const id = selector.startsWith("@")
300
+ ? resolveNamedAddress({
301
+ selector,
302
+ ...(await observeNamedAddress({ world: at.world, repo: at.repo ?? null, selectors: [selector] })),
303
+ }).id
304
+ : selector;
305
+ if (id.startsWith("aku/")) {
306
+ if (at.world === null)
307
+ throw new KeiyakuUsageError("no Keiyaku world contains the invocation cwd");
308
+ return Akumas.of(at.world).status({
309
+ akuma: id,
310
+ ...(at.repo === undefined ? {} : { repo: at.repo }),
156
311
  });
157
312
  }
158
- case "fork":
159
- return this.#fork(request.input);
160
- case "tell":
161
- case "ask":
162
- return this.#tell({
163
- ...request.input,
164
- ...signal,
165
- ...(observe === undefined
166
- ? {}
167
- : {
168
- observe: {
169
- admitted: (tell, id) => notify({ kind: "admitted", tell, id }),
170
- observe: (observation) => notify({ kind: "live", observation }),
171
- },
172
- }),
313
+ if (at.repo === undefined)
314
+ throw new KeiyakuUsageError("this command requires a resolved Repo");
315
+ const report = await Kanshi.of({ world: at.world, repo: at.repo }).contract(contractId(id));
316
+ if (report.kind === "contract-absent")
317
+ throw new Error("Contract observation with a Repo cannot be absent");
318
+ return report;
319
+ },
320
+ region: async (input) => {
321
+ const at = await this.#coordinates("required");
322
+ if (at.repo === undefined)
323
+ throw new KeiyakuUsageError("this command requires a resolved Repo");
324
+ const repo = at.repo;
325
+ const selected = input.paths !== undefined
326
+ ? { kind: "path", patterns: input.paths }
327
+ : input.contract === undefined
328
+ ? { kind: "declarations" }
329
+ : { kind: "contract", contract: await this.#resolve(Keis.of(repo), input.contract, at.cwd) };
330
+ const result = await Kanshi.of({ world: at.world, repo }).region(selected);
331
+ if (result.kind === "absent")
332
+ throw new Error("Region observation with a Repo cannot be absent");
333
+ return result;
334
+ },
335
+ ls: async (input) => {
336
+ const bound = input.limit === undefined ? {} : { limit: input.limit };
337
+ const lifecycle = input.lifecycle === undefined ? {} : { selection: input.lifecycle };
338
+ if (input.selector === "kei" || input.selector === "kei/") {
339
+ const at = await this.#coordinates("required");
340
+ return Keis.of(at.repo).list({ ...bound, ...lifecycle });
341
+ }
342
+ if (input.selector === "debt" || input.selector === "debt/")
343
+ return debt.debtLs(this.#input, {
344
+ ...bound,
345
+ ...lifecycle,
173
346
  });
174
- case "kill":
175
- return this.#kill({ ...request.input, ...signal });
176
- case "wait":
177
- return this.#wait({ ...request.input, ...signal });
178
- case "history":
179
- return this.#history(request.input);
180
- case "report":
181
- return this.#report({ ...request.input, ...signal });
182
- }
183
- }
184
- #dispatchDebt(request, signal) {
185
- switch (request.name) {
186
- case "debt.add":
187
- return debt.debtAdd(this.#input, { ...request.input, ...signal }, false);
188
- case "debt.addDocument":
189
- return debt.debtAdd(this.#input, { ...request.input, ...signal }, true);
190
- case "debt.update":
191
- return debt.debtUpdate(this.#input, { ...request.input, ...signal });
192
- case "debt.doctor":
193
- return debt.debtDoctor(this.#input);
194
- }
195
- }
347
+ if (input.selector === "aku" || input.selector === "aku/") {
348
+ const at = await this.#coordinates("none");
349
+ return Akumas.akumaNames({
350
+ ...bound,
351
+ ...(at.world === null ? {} : { cwd: at.world }),
352
+ ...(this.#input.home === undefined ? {} : { home: this.#input.home }),
353
+ });
354
+ }
355
+ const name = input.selector.split("/")[1];
356
+ const akumaName = name === "*" ? undefined : validateAkumaName(name);
357
+ const { at, akumas } = await this.#akumas();
358
+ const caller = await this.#resolveLsCaller(input.mine);
359
+ return akumas.list({
360
+ ...bound,
361
+ ...lifecycle,
362
+ ...(akumaName === undefined ? {} : { akumaName }),
363
+ ...(caller === undefined ? {} : { caller }),
364
+ ...(at.repo === undefined ? {} : { repo: at.repo }),
365
+ });
366
+ },
367
+ "debt.add": (input, controls) => debt.debtAdd(this.#input, { ...input, ...executionSignal(controls) }, false),
368
+ "debt.addDocument": (input, controls) => debt.debtAdd(this.#input, { ...input, ...executionSignal(controls) }, true),
369
+ "debt.update": (input, controls) => debt.debtUpdate(this.#input, { ...input, ...executionSignal(controls) }),
370
+ "debt.doctor": () => debt.debtDoctor(this.#input),
371
+ };
196
372
  bind(input, run) {
197
373
  // Generic output describes the wire form; the same execution retains the native handle.
198
374
  return this.run("bind", input, run);
199
375
  }
200
- amend(input, run) {
201
- return this.run("amend", input, run);
202
- }
203
- arc(input, run) {
204
- return this.run("arc", input, run);
205
- }
206
- deliver(input = {}, run) {
207
- return this.run("deliver", input, run);
208
- }
209
- verify(input = {}, run) {
210
- return this.run("verify", input, run);
211
- }
212
- review(input, run) {
213
- return this.run("review", input, run);
214
- }
215
- abandon(input = {}, run) {
216
- return this.run("abandon", input, run);
217
- }
218
- show(input = {}, run) {
219
- return this.run("show", input, run);
220
- }
221
- reconcile(input = {}, run) {
222
- return this.run("reconcile", input, run);
223
- }
224
- spawn(input, run) {
225
- return this.run("spawn", input, run);
226
- }
227
- fork(input, run) {
228
- return this.run("fork", input, run);
229
- }
230
- tell(input, run) {
231
- return this.run("tell", input, run);
232
- }
233
- ask(input, run) {
234
- return this.run("ask", input, run);
235
- }
236
- kill(input, run) {
237
- return this.run("kill", input, run);
238
- }
239
- wait(input, run) {
240
- return this.run("wait", input, run);
241
- }
242
- history(input, run) {
243
- return this.run("history", input, run);
244
- }
245
- report(input, run) {
246
- return this.run("report", input, run);
247
- }
248
- ls(input, run) {
249
- return this.run("ls", input, run);
250
- }
251
- debtAdd(input, run) {
252
- return this.run("debt.add", input, run);
253
- }
254
- debtAddDocument(input, run) {
255
- return this.run("debt.addDocument", input, run);
256
- }
257
- debtUpdate(input, run) {
258
- return this.run("debt.update", input, run);
259
- }
260
- debtDoctor(input = {}, run) {
261
- return this.run("debt.doctor", input, run);
262
- }
263
- kanshi(input = {}, run) {
264
- return this.run("kanshi", input, run);
265
- }
266
- status(input, run) {
267
- return this.run("status", input, run);
268
- }
269
- region(input = {}, run) {
270
- return this.run("region", input, run);
271
- }
272
- whoami(input = {}, run) {
273
- return this.run("whoami", input, run);
274
- }
275
- settings(input = {}, run) {
276
- return this.run("settings", input, run);
277
- }
278
- nuke(input = {}, run) {
279
- return this.run("nuke", input, run);
376
+ amend = this.#verb("amend", {});
377
+ arc = this.#verb("arc");
378
+ deliver = this.#verb("deliver", {});
379
+ verify = this.#verb("verify", {});
380
+ review = this.#verb("review");
381
+ abandon = this.#verb("abandon", {});
382
+ show = this.#verb("show");
383
+ reconcile = this.#verb("reconcile", {});
384
+ spawn = this.#verb("spawn");
385
+ fork = this.#verb("fork");
386
+ tell = this.#verb("tell");
387
+ ask = this.#verb("ask");
388
+ kill = this.#verb("kill");
389
+ wait = this.#verb("wait");
390
+ history = this.#verb("history");
391
+ report = this.#verb("report");
392
+ ls = this.#verb("ls");
393
+ debtAdd = this.#verb("debt.add");
394
+ debtAddDocument = this.#verb("debt.addDocument");
395
+ debtUpdate = this.#verb("debt.update");
396
+ debtDoctor = this.#verb("debt.doctor", {});
397
+ kanshi = this.#verb("kanshi", {});
398
+ status = this.#verb("status");
399
+ region = this.#verb("region", {});
400
+ whoami = this.#verb("whoami", {});
401
+ settings = this.#verb("settings", {});
402
+ nuke = this.#verb("nuke", {});
403
+ #verb(name, empty) {
404
+ return (input = empty, run) => this.run(name, input, run);
280
405
  }
281
406
  #coordinates(use, contractWait = false) {
282
407
  return invocationCoordinates({ ...this.#input, use, contractWait });
@@ -328,109 +453,8 @@ export class Keiyaku {
328
453
  const id = await this.#resolve(library, selector, cwd);
329
454
  return { id, contract: library.kei({ id }) };
330
455
  }
331
- async #bind(input) {
332
- const { library } = await this.#keis();
333
- if ("forkOf" in input)
334
- return await library.bind({
335
- ...input,
336
- forkOf: this.#fullId(library, input.forkOf),
337
- });
338
- const { after, ...rest } = input;
339
- return await library.bind({
340
- ...rest,
341
- ...(after === undefined ? {} : { after: after.map((id) => this.#fullId(library, id)) }),
342
- });
343
- }
344
- async #amend({ contract, ...input }) {
345
- const { cwd, library } = await this.#keis();
346
- const id = await this.#resolve(library, contract, cwd);
347
- const { after, ...rest } = input;
348
- return await library.kei({ id }).amend({
349
- ...rest,
350
- ...(after === undefined ? {} : { after: after.map((value) => this.#fullId(library, value)) }),
351
- });
352
- }
353
- async #arc({ contract, ...input }) {
354
- const selected = await this.#selected(contract);
355
- try {
356
- validateArcMarkdown(input.markdown);
357
- }
358
- catch (error) {
359
- if (errorCategory(error) === "invalid-input")
360
- throw new KeiyakuArcDocumentError(selected.id, error);
361
- throw error;
362
- }
363
- return await selected.contract.arc(input);
364
- }
365
- async #deliver({ contract, ...input }, progress) {
366
- const selected = (await this.#selected(contract)).contract;
367
- const { dryRun, ...native } = input;
368
- return dryRun ? await selected.previewDelivery(native, progress) : await selected.deliver(native, progress);
369
- }
370
- async #verify({ contract, ...input }, progress) {
371
- return await (await this.#selected(contract)).contract.verify(input, progress);
372
- }
373
- async #review({ contract, ...input }, progress) {
374
- const selected = await this.#selected(contract);
375
- return await selected.contract.review(input, progress);
376
- }
377
- async #abandon({ contract, ...input }) {
378
- const selected = await this.#selected(contract);
379
- return await selected.contract.abandon(input);
380
- }
381
- async #show({ id }) {
382
- if (id?.startsWith("debt/") === true)
383
- return debt.debtShow(this.#input, id);
384
- return await (await this.#selected(id)).contract.guidance();
385
- }
386
- async #reconcile(input) {
387
- const { cwd, library } = await this.#keis();
388
- if (input.contract === undefined)
389
- return await library.reconcile(input);
390
- const id = await this.#resolve(library, input.contract, cwd);
391
- return await library.reconcile({ ...input, contract: id });
392
- }
393
- async #spawn({ prompt, wait, contract, workdir, alias, observe, ...input }) {
394
- const at = await this.#coordinates(contract === undefined ? "none" : "required");
395
- const cwd = workdir === undefined
396
- ? at.cwd
397
- : await canonicalBirthCwd(resolve(at.cwd, workdir), `workdir is not an existing directory: ${workdir}`);
398
- const caller = await this.#caller();
399
- const initiator = deliveryOwner(this.#input.environment);
400
- const world = at.candidateWorld ?? (await at.establishWorld());
401
- await World.at(world);
402
- const configuration = await Settings.load({
403
- cwd: world,
404
- ...(this.#input.home === undefined ? {} : { home: this.#input.home }),
405
- });
406
- const selected = contract === undefined ? undefined : Keis.of(at.repo).kei({ id: this.#fullId(Keis.of(at.repo), contract) });
407
- return await Akumas.of(world).spawn({
408
- ...input,
409
- ...(wait === undefined ? {} : { mode: "wait", timeoutMs: waitTimeout(wait) }),
410
- cwd,
411
- settings: configuration,
412
- ...(alias === undefined ? {} : { alias: alias }),
413
- ...(this.#input.home === undefined ? {} : { home: this.#input.home }),
414
- ...(prompt === undefined ? {} : { body: prompt }),
415
- ...(selected === undefined ? {} : { contract: selected }),
416
- ...(caller === undefined ? {} : { caller }),
417
- ...(initiator === undefined ? {} : { initiator }),
418
- ...(observe === undefined
419
- ? {}
420
- : {
421
- observe: {
422
- ...(observe.observe === undefined ? {} : { observe: observe.observe }),
423
- ...(observe.admitted === undefined
424
- ? {}
425
- : {
426
- admitted: (tell, id, head) => observe.admitted(tell, id, { ...head, cwd }),
427
- }),
428
- },
429
- }),
430
- });
431
- }
432
456
  #caller() {
433
- return akumaCallerFromEnvironment(this.#input.environment);
457
+ return akumaCallerFromEnvironment(this.#input.environment, this.#input.identity?.owner);
434
458
  }
435
459
  async #akumas(use = "optional") {
436
460
  const at = await this.#coordinates(use);
@@ -438,83 +462,32 @@ export class Keiyaku {
438
462
  throw new KeiyakuUsageError("no Keiyaku world contains the invocation cwd");
439
463
  return { at, akumas: Akumas.of(at.world) };
440
464
  }
441
- async #fork(input) {
442
- const { at, akumas } = await this.#akumas();
443
- const caller = await this.#caller();
444
- const initiator = deliveryOwner(this.#input.environment);
445
- return await akumas.fork({
446
- ...input,
447
- ...(at.repo === undefined ? {} : { repo: at.repo }),
448
- ...(caller === undefined ? {} : { caller }),
449
- ...(initiator === undefined ? {} : { initiator }),
450
- });
451
- }
452
- async #tell({ prompt, ...input }) {
465
+ async #tell(request, controls) {
453
466
  const { at, akumas } = await this.#akumas();
454
- const initiator = deliveryOwner(this.#input.environment);
455
- const native = {
456
- ...input,
457
- body: prompt,
467
+ const initiator = deliveryOwner(this.#input.environment, this.#input.identity?.owner);
468
+ const common = {
469
+ ...controls,
470
+ body: request.input.prompt,
458
471
  ...(at.repo === undefined ? {} : { repo: at.repo }),
459
472
  ...(initiator === undefined ? {} : { initiator }),
460
473
  };
461
- if ("schema" in native)
462
- return akumas.ask(native);
463
- const { wait, ...tell } = native;
464
- return akumas.tell({ ...tell, ...(wait === undefined ? {} : { wait: true, timeoutMs: waitTimeout(wait) }) });
465
- }
466
- async #kill(input) {
467
- const { at, akumas } = await this.#akumas();
468
- return await akumas.kill({ ...input, ...(at.repo === undefined ? {} : { repo: at.repo }) });
469
- }
470
- async #wait({ selectors, ...input }) {
471
- const contracts = selectors.filter((selector) => selector.startsWith("kei/"));
472
- if (contracts.length > 0) {
473
- const at = await this.#coordinates("required", true);
474
- if (at.repo === undefined)
475
- throw new KeiyakuUsageError("Contract wait requires a repository");
476
- return await Keis.of(at.repo).wait({ contracts, ...input });
477
- }
478
- const { at, akumas } = await this.#akumas();
479
- return await akumas.wait({ akuma: selectors, ...input, ...(at.repo === undefined ? {} : { repo: at.repo }) });
480
- }
481
- async #history({ selector, ...input }) {
482
- if (selector.startsWith("kei/")) {
483
- const at = await this.#coordinates("required");
484
- if (at.repo === undefined)
485
- throw new KeiyakuUsageError("this command requires a resolved Repo");
486
- const library = Keis.of(at.repo);
487
- return await library
488
- .kei({ id: this.#fullId(library, selector) })
489
- .history("full" in input ? { full: input.full } : undefined);
490
- }
491
- const { at, akumas } = await this.#akumas();
492
- return await akumas.history({ akuma: selector, ...input, ...(at.repo === undefined ? {} : { repo: at.repo }) });
493
- }
494
- async #report(input) {
495
- await this.#coordinates("none");
496
- const environment = this.#input.environment;
497
- if (environment.KEIYAKU_ACTOR_ID === undefined || environment.KEIYAKU_ACTOR_WORLD === undefined)
498
- throw new KeiyakuUsageError("report requires explicit KEIYAKU_ACTOR_ID and KEIYAKU_ACTOR_WORLD");
499
- let caller;
500
- try {
501
- caller = await akumaCallerFromEnvironment(environment);
502
- }
503
- catch (error) {
504
- if (error instanceof WorldError)
505
- throw new KeiyakuUsageError(error.message);
506
- throw error;
474
+ if (request.name === "ask") {
475
+ const { prompt: _prompt, timeout, ...input } = request.input;
476
+ return akumas.ask({
477
+ ...input,
478
+ ...common,
479
+ ...(timeout === undefined ? {} : { timeoutMs: observationTimeout(timeout) }),
480
+ });
507
481
  }
508
- if (caller?.kind !== "akuma")
509
- throw new KeiyakuUsageError("report requires explicit Akuma identity");
510
- return Akuma.select(caller.world, caller.akumaId).report(input.text, input.signal === undefined ? {} : { signal: input.signal });
482
+ const { prompt: _prompt, ...input } = request.input;
483
+ return akumas.tell({ ...input, ...common });
511
484
  }
512
485
  async #resolveLsCaller(mine) {
513
486
  if (mine !== true)
514
487
  return undefined;
515
488
  let caller;
516
489
  try {
517
- caller = await akumaCallerFromEnvironment(this.#input.environment);
490
+ caller = await this.#caller();
518
491
  }
519
492
  catch (error) {
520
493
  throw new KeiyakuUsageError(error instanceof Error ? error.message : String(error));
@@ -524,73 +497,4 @@ export class Keiyaku {
524
497
  }
525
498
  return caller;
526
499
  }
527
- async #ls(input) {
528
- const bound = input.limit === undefined ? {} : { limit: input.limit };
529
- if (input.selector === "kei" || input.selector === "kei/") {
530
- const at = await this.#coordinates("required");
531
- return Keis.of(at.repo).list(bound);
532
- }
533
- if (input.selector === "debt" || input.selector === "debt/")
534
- return debt.debtLs(this.#input, {
535
- ...bound,
536
- ...("selection" in input && input.selection !== undefined ? { selection: input.selection } : {}),
537
- });
538
- if (input.selector === "aku" || input.selector === "aku/") {
539
- const at = await this.#coordinates("none");
540
- return Akumas.akumaNames({
541
- ...bound,
542
- ...(at.world === null ? {} : { cwd: at.world }),
543
- ...(this.#input.home === undefined ? {} : { home: this.#input.home }),
544
- });
545
- }
546
- const name = input.selector.split("/")[1];
547
- const akumaName = name === "*" ? undefined : validateAkumaName(name);
548
- const { at, akumas } = await this.#akumas();
549
- const caller = await this.#resolveLsCaller("mine" in input ? input.mine : undefined);
550
- return akumas.list({
551
- ...bound,
552
- ...(akumaName === undefined ? {} : { akumaName }),
553
- ...(caller === undefined ? {} : { caller }),
554
- ...(at.repo === undefined ? {} : { repo: at.repo }),
555
- });
556
- }
557
- async #region(input = {}) {
558
- const at = await this.#coordinates("required");
559
- if (at.repo === undefined)
560
- throw new KeiyakuUsageError("this command requires a resolved Repo");
561
- const repo = at.repo;
562
- let selected;
563
- if (input.paths !== undefined) {
564
- const [first, ...rest] = input.paths;
565
- if (first === undefined)
566
- throw new KeiyakuUsageError("Region query requires one or more path patterns");
567
- selected = { kind: "path", patterns: [first, ...rest] };
568
- }
569
- else {
570
- selected =
571
- input.contract === undefined
572
- ? { kind: "declarations" }
573
- : { kind: "contract", contract: await this.#resolve(Keis.of(repo), input.contract, at.cwd) };
574
- }
575
- const result = await Kanshi.of({ world: at.world, repo }).region(selected);
576
- if (result.kind === "absent")
577
- throw new Error("Region observation with a Repo cannot be absent");
578
- return result;
579
- }
580
- async #whoami() {
581
- return await whoami(await this.#coordinates("optional"), this.#input.environment);
582
- }
583
- async #settings() {
584
- const at = await this.#coordinates("none");
585
- return await Settings.load({
586
- ...(at.world === null ? {} : { cwd: at.world }),
587
- ...(this.#input.home === undefined ? {} : { home: this.#input.home }),
588
- });
589
- }
590
- async #nuke(input) {
591
- const at = await this.#coordinates("none");
592
- if (at.world === null)
593
- throw new KeiyakuUsageError("no Keiyaku world contains the invocation cwd");
594
- return await nukeKeiyaku({ world: at.world, ...input });
595
- }
596
500
  }