@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
@@ -2,6 +2,7 @@ import { CliUsageError, commandGuide, usageLine } from "../usage.js";
2
2
  import { scanArgs } from "../scan.js";
3
3
  import { parseDuration as decodeDuration } from "../../duration.js";
4
4
  import { parseAkumaAlias, parseAkumaGlob } from "../../identity/selector.js";
5
+ import { canonicalDecimalSchema } from "../../history.js";
5
6
  import { parseExactHistorySelector } from "../../akuma/identity.js";
6
7
  const SET_SELECTORS = '(<aku/...> | @name | <kei/...> | "aku/<name-pattern>/<hex-pattern>")...';
7
8
  const SET_DETAILS = "Globs contain * and use lowercase hex digits or * in the suffix. --repo requires at least one Contract (kei/...) selector.";
@@ -21,23 +22,20 @@ const AKUMA_COMMAND_SPECS = {
21
22
  flags: {
22
23
  contract: "value",
23
24
  alias: "value",
24
- wait: "value",
25
25
  bare: "boolean",
26
26
  json: "boolean",
27
27
  },
28
- usage: "spawn <akuma-name> [--contract <kei/...>] [--repo <path>] [--workdir <path>] [--alias <name>] [--bare] [--wait <duration>] [<prompt> | -]",
28
+ usage: "spawn <akuma-name> [--contract <kei/...>] [--repo <path>] [--workdir <path>] [--alias <name>] [--bare] [<prompt> | -]",
29
29
  purpose: "Spawn a new Akuma into the world.",
30
30
  details: [
31
31
  "Use keiyaku ls aku/ to list available Akuma names.",
32
32
  "Omit the prompt to birth without a Tell; otherwise give <prompt> as one argument, or use - to read stdin.",
33
- "--wait requires a prompt.",
34
33
  "--bare omits Keiyaku's runtime instruction section for this birth and its later execution; personality, tools, permissions, and report remain unchanged.",
35
34
  "Generic ACP needs --bare: it has no verified native runtime-instruction channel. Existing sessions without the section are not retrofitted; ordinary resume retains existing native instructions.",
36
- "By default, spawn returns after birth and optional first Tell admission; --wait also waits for its first answer, up to the given duration.",
35
+ "Spawn returns birth and optional first Tell admission, not an answer. Observe work separately with wait.",
37
36
  "--contract records an association, not the work or execution directory; include the Contract and worktree context in the prompt as needed. --repo requires --contract.",
38
37
  "--workdir selects where the Akuma works; relative paths resolve from the invocation directory selected by -C/--cwd, or the process cwd when omitted. Without --workdir, the invocation directory is used.",
39
38
  "--alias <name> gives the new Akuma the selector @name instead of aku/<id>; an existing @name is reassigned to this Akuma.",
40
- "With --wait, completed activity streams on stderr and the final answer is written to stdout once.",
41
39
  ].join("\n"),
42
40
  },
43
41
  wait: {
@@ -47,7 +45,7 @@ const AKUMA_COMMAND_SPECS = {
47
45
  usage: `wait ${SET_SELECTORS} [--any | --all] [--timeout <duration>] [--repo <path>]`,
48
46
  purpose: "Wait for Contract changes or terminal state, or Akumas to finish work.",
49
47
  details: [
50
- "Select Contracts or Akumas, never both in one wait. Contract IDs wait for their next journal change or terminal state, not associated Akumas.",
48
+ "Select Contracts and Akumas together or separately. Contract IDs wait for their next journal change or terminal state, not associated Akumas. One deadline and any/all mode cover the whole selection.",
51
49
  "The default mode is any; --all waits for every selected member. Each Contract starts from its current journal head; already accepted or abandoned Contracts complete immediately.",
52
50
  SET_DETAILS,
53
51
  "An already completed Akuma counts immediately; a deadline only bounds observation.",
@@ -57,15 +55,13 @@ const AKUMA_COMMAND_SPECS = {
57
55
  tell: {
58
56
  arity: 1,
59
57
  stdin: true,
60
- flags: { interrupt: "boolean", wait: "value", json: "boolean" },
61
- usage: "tell <aku/...|@name> [--interrupt] [--wait <duration>] (<prompt> | -)",
62
- purpose: "Tell an Akuma something, optionally observing its answer.",
58
+ flags: { interrupt: "boolean", json: "boolean" },
59
+ usage: "tell <aku/...|@name> [--interrupt] (<prompt> | -)",
60
+ purpose: "Admit new orders for an Akuma.",
63
61
  details: [
64
62
  "Give <prompt> as one argument, or use - to read stdin.",
65
63
  "--interrupt admits the Tell and asks current work to yield; the Tell remains admitted even if yielding cannot be confirmed.",
66
- "--wait bounds how long to block for the answer; the Tell stays admitted past the deadline.",
67
- "Without --wait, returns after Tell admission.",
68
- "With observation, completed activity streams on stderr and the final answer is written to stdout once.",
64
+ "Returns Tell admission, not an answer. Observe work separately with wait, or use ask for a structured answer.",
69
65
  ].join("\n"),
70
66
  },
71
67
  ask: {
@@ -84,19 +80,18 @@ const AKUMA_COMMAND_SPECS = {
84
80
  before: "value",
85
81
  since: "value",
86
82
  limit: "value",
87
- last: "boolean",
88
- full: "boolean",
83
+ answer: "boolean",
89
84
  json: "boolean",
90
85
  },
91
- usage: "history <aku/...|@name> [--before <index> | --since <index>] [--limit <count>]\nhistory <aku/...|@name> --id <historyId>\nhistory <aku/...|@name> --last\nhistory <kei/...> [--full] [--repo <path>]",
86
+ usage: "history <kei/...|aku/...|@name> [--before <index> | --since <index>] [--limit <count>]\nhistory <kei/...|aku/...|@name> --id <historyId>\nhistory <aku/...|@name> --answer",
92
87
  purpose: "Read an Akuma's answers and activity, or a Contract's history of changes and assigned work.",
93
88
  details: [
94
- "--id reads exact retained activity by its positive decimal id, a terminal turn (turn/<number>), or a report (report/<number>).",
95
- "--before <index> pages older rows before that sequence; --since <index> pages newer rows after it.",
96
- "--limit bounds page size (default 12); without --since, the latest rows are shown.",
97
- "With --since, paging starts at the earliest newer rows.",
98
- "--last returns only the most recent answer, if one exists; it is not a history page.",
99
- "Contract history defaults to a causal skeleton; --full prints every event with complete fields.",
89
+ "--id opens one complete Contract record by its decimal address, or retained Akuma activity by a decimal address, turn/<number>, or report/<number>.",
90
+ "--before <index> pages older entries before that sequence; --since <index> pages newer entries after it.",
91
+ "--limit bounds page size (1..5000, default 12); without --since, the latest entries are shown.",
92
+ "With --since, paging starts at the earliest newer entries.",
93
+ "--answer returns the latest retained answered Turn, even after later failed or cancelled work; it is not a history page.",
94
+ "Exact reads cannot be combined with paging. --repo selects the repository for Contract history.",
100
95
  ].join("\n"),
101
96
  },
102
97
  fork: {
@@ -166,16 +161,13 @@ function positiveIndex(raw, option, fail) {
166
161
  return value;
167
162
  }
168
163
  function validateSet(value, fail) {
169
- if (value.startsWith("kei/"))
170
- return value;
171
- if (value.includes("*")) {
164
+ if (!value.startsWith("kei/") && value.includes("*")) {
172
165
  try {
173
166
  parseAkumaGlob(value);
174
167
  }
175
168
  catch (error) {
176
169
  fail(error instanceof Error ? error.message : `invalid Akuma glob: ${value}`);
177
170
  }
178
- return value;
179
171
  }
180
172
  return value;
181
173
  }
@@ -184,55 +176,48 @@ function parseWait(rawSelectors, flags, output, fail) {
184
176
  fail("wait --any and --all are mutually exclusive");
185
177
  const completion = flags.any === true ? "any" : flags.all === true ? "all" : undefined;
186
178
  const selectors = rawSelectors.map((value) => validateSet(value, fail));
187
- if (selectors.some((value) => value.startsWith("kei/")) && selectors.some((value) => !value.startsWith("kei/")))
188
- fail("wait cannot mix Contract and Akuma selectors");
179
+ const timeout = flags.timeout === undefined ? undefined : stringFlag(flags.timeout, "--timeout requires a duration", fail);
180
+ if (timeout !== undefined)
181
+ parseDuration(timeout, "--timeout", fail);
189
182
  return {
190
183
  name: "wait",
191
184
  input: {
192
185
  selectors,
193
186
  ...(completion === undefined ? {} : { completion }),
194
- ...(flags.timeout === undefined ? {} : { timeoutMs: parseDuration(flags.timeout, "--timeout", fail) }),
187
+ ...(timeout === undefined ? {} : { timeout }),
195
188
  },
196
189
  output,
197
190
  };
198
191
  }
199
192
  function parseHistory(selector, flags, output, fail) {
200
- if (selector.startsWith("kei/")) {
201
- if ([flags.id, flags.before, flags.since, flags.limit, flags.last].some((value) => value !== undefined)) {
202
- fail("history kei/... does not accept --id, --before, --since, --limit, or --last");
203
- }
204
- return { name: "history", input: { selector, full: flags.full === true }, output };
205
- }
206
- return parseAkumaHistory(selector, flags, output, fail);
207
- }
208
- function refuseHistoryIdConflict(flags, bounded, fail) {
209
- if (flags.id !== undefined && (flags.last === true || bounded))
210
- fail("history --id cannot be combined with --last, --before, --since, or --limit");
211
- }
212
- function parseAkumaHistory(selector, flags, output, fail) {
213
- if (flags.full === true)
214
- fail("history --full is only valid for kei/...");
215
- const bounded = flags.before !== undefined || flags.since !== undefined || flags.limit !== undefined;
193
+ const bounded = ["before", "since", "limit"].some((key) => flags[key] !== undefined);
216
194
  if (flags.before !== undefined && flags.since !== undefined)
217
195
  fail("history --before and --since are mutually exclusive");
218
- refuseHistoryIdConflict(flags, bounded, fail);
219
- if (flags.last === true && bounded)
220
- fail("history --last cannot be combined with --before, --since, or --limit");
221
- const limit = flags.limit === undefined ? undefined : positiveIndex(flags.limit, "--limit", fail);
222
- if (limit !== undefined && limit > 5_000)
196
+ if (flags.id !== undefined && (flags.answer === true || bounded))
197
+ fail("history --id cannot be combined with --answer, --before, --since, or --limit");
198
+ if (flags.answer === true && bounded)
199
+ fail("history --answer cannot be combined with --before, --since, or --limit");
200
+ if (selector.startsWith("kei/") && flags.answer === true)
201
+ fail("history --answer requires an Akuma");
202
+ const page = {};
203
+ for (const key of ["before", "since", "limit"]) {
204
+ if (flags[key] !== undefined)
205
+ page[key] = positiveIndex(flags[key], `--${key}`, fail);
206
+ }
207
+ if (page.limit !== undefined && page.limit > 5_000)
223
208
  fail("--limit must be no greater than 5000");
224
209
  const id = flags.id === undefined ? undefined : stringFlag(flags.id, "history --id requires a nonblank historyId", fail);
225
- if (id !== undefined && parseExactHistorySelector(id) === null)
226
- fail("history --id requires a positive safe decimal integer, turn/<positive safe integer> or report/<positive safe integer>");
210
+ if (id !== undefined &&
211
+ (selector.startsWith("kei/")
212
+ ? !canonicalDecimalSchema.safeParse(id).success
213
+ : parseExactHistorySelector(id) === null))
214
+ fail("history --id requires a positive safe decimal integer for a Contract; Akumas also accept turn/<positive safe integer> or report/<positive safe integer>");
227
215
  return {
228
216
  name: "history",
229
217
  input: {
230
218
  selector,
231
- ...(id === undefined ? {} : { id }),
232
- last: flags.last === true,
233
- ...(flags.before === undefined ? {} : { before: positiveIndex(flags.before, "--before", fail) }),
234
- ...(flags.since === undefined ? {} : { since: positiveIndex(flags.since, "--since", fail) }),
235
- ...(limit === undefined ? {} : { limit }),
219
+ ...(id === undefined ? (flags.answer === true ? { item: "answer" } : {}) : { item: id }),
220
+ ...page,
236
221
  },
237
222
  output,
238
223
  };
@@ -273,25 +258,21 @@ function parsePrompted(action, positionals, stdin, fail) {
273
258
  }
274
259
  function parseTell(action, flags, subject, prompt, fail) {
275
260
  const output = flags.json === true ? "json" : "text";
276
- const wait = flags.wait === undefined ? undefined : stringFlag(flags.wait, "--wait requires a duration", fail);
277
- const timeoutMs = wait === undefined ? undefined : parseDuration(wait, "--wait", fail);
278
261
  const input = {
279
262
  akuma: subject,
280
263
  ...(flags.interrupt === true ? { interrupt: true } : {}),
281
264
  };
282
- return action === "tell"
283
- ? {
284
- name: action,
285
- input: { ...input, ...(wait === undefined ? {} : { wait }) },
286
- acquire: { prompt },
287
- output,
288
- }
289
- : {
290
- name: action,
291
- input: { ...input, ...(timeoutMs === undefined ? {} : { timeoutMs }) },
292
- acquire: { prompt, schema: stringFlag(flags.schema, "ask requires --schema <file>", fail) },
293
- output,
294
- };
265
+ if (action === "tell")
266
+ return { name: action, input, acquire: { prompt }, output };
267
+ const wait = flags.wait === undefined ? undefined : stringFlag(flags.wait, "--wait requires a duration", fail);
268
+ if (wait !== undefined)
269
+ parseDuration(wait, "--wait", fail);
270
+ return {
271
+ name: action,
272
+ input: { ...input, ...(wait === undefined ? {} : { timeout: wait }) },
273
+ acquire: { prompt, schema: stringFlag(flags.schema, "ask requires --schema <file>", fail) },
274
+ output,
275
+ };
295
276
  }
296
277
  function parseSpawn(flags, akumaName, prompt, output, fail) {
297
278
  let alias;
@@ -304,18 +285,12 @@ function parseSpawn(flags, akumaName, prompt, output, fail) {
304
285
  fail(error instanceof Error ? error.message : "invalid Akuma alias");
305
286
  }
306
287
  }
307
- const wait = flags.wait === undefined ? undefined : stringFlag(flags.wait, "--wait requires a duration", fail);
308
- if (wait !== undefined)
309
- parseDuration(wait, "--wait", fail);
310
- if (prompt === undefined && flags.wait !== undefined)
311
- fail("spawn --wait requires a prompt");
312
288
  return {
313
289
  name: "spawn",
314
290
  input: {
315
291
  akumaName,
316
292
  ...(typeof flags.contract === "string" ? { contract: flags.contract } : {}),
317
293
  ...(alias === undefined ? {} : { alias }),
318
- ...(wait === undefined ? {} : { wait }),
319
294
  ...(flags.bare === true ? { bare: true } : {}),
320
295
  },
321
296
  acquire: { ...(prompt === undefined ? {} : { prompt }) },
@@ -5,6 +5,5 @@ import type { CliRuntime } from "../runtime.js";
5
5
  export declare function acquireAkumaRequest(request: Extract<PendingRequest, {
6
6
  name: "spawn" | "tell" | "ask";
7
7
  }>, workdir: string | undefined, runtime: CliRuntime): Promise<VerbRequest<"spawn" | "tell" | "ask">>;
8
- export declare function runSpawn(request: VerbRequest<"spawn">, runtime: CliRuntime): Promise<CliOutcome>;
9
- export declare function runAsk(request: VerbRequest<"ask" | "tell">, runtime: CliRuntime): Promise<CliOutcome>;
8
+ export declare function runAsk(request: VerbRequest<"ask">, runtime: CliRuntime): Promise<CliOutcome>;
10
9
  export declare function runAkumaHistory(request: VerbRequest<"history">, runtime: CliRuntime): Promise<CliOutcome>;
@@ -4,10 +4,10 @@ import { readFile } from "node:fs/promises";
4
4
  import { canonicalDocument } from "../../akuma/schema.js";
5
5
  import { classifyVerb, verbs } from "../../library/keiyaku-verbs.js";
6
6
  import { ActivityDriver } from "../activity.js";
7
- import { displayContext, resultContext, writeJson, writeStderr, writeStdout } from "../streams.js";
8
- import { askRawAnswer, callObservationStream, callRawAnswer, historyRawAnswer } from "../render/akuma-activity.js";
9
- import { askProgressStream, callObservationHead, renderFailedCallObservation } from "../render/akuma.js";
10
- import { renderVerb } from "../render/verbs.js";
7
+ import { displayContext, resultContext, writeJson, writeStdout } from "../streams.js";
8
+ import { askRawAnswer, historyRawAnswer } from "../render/akuma-activity.js";
9
+ import { askProgressStream } from "../render/akuma.js";
10
+ import { aliasSelector, renderVerb } from "../render/verbs.js";
11
11
  async function schemaFromFile(path) {
12
12
  try {
13
13
  const parsed = JSON.parse(await readFile(path, "utf8"));
@@ -17,9 +17,6 @@ async function schemaFromFile(path) {
17
17
  throw new CliUsageError(`cannot read JSON Schema file ${path}: ${error instanceof Error ? error.message : String(error)}`);
18
18
  }
19
19
  }
20
- function inputAlias(selector) {
21
- return selector.startsWith("@") ? selector : undefined;
22
- }
23
20
  async function promptBody(action, prompt, runtime) {
24
21
  if (prompt.kind !== "stdin")
25
22
  return prompt.value;
@@ -53,56 +50,9 @@ function emitAnswer(body, exact) {
53
50
  else
54
51
  writeStdout(body);
55
52
  }
56
- export async function runSpawn(request, runtime) {
57
- const { input, output } = request;
58
- let stream;
59
- const driver = new ActivityDriver(process.stderr);
60
- const observing = input.wait !== undefined && output === "text";
61
- const observe = observing
62
- ? (event) => {
63
- if (event.kind === "admitted") {
64
- stream = callObservationStream(resultContext(), callObservationHead({ akumaId: event.id, ...event.head }), {
65
- admittedAt: event.tell.row.at,
66
- });
67
- driver.redraw(stream.frame());
68
- }
69
- else {
70
- driver.settle(stream?.observe(event.observation) ?? [], stream?.frame() ?? []);
71
- }
72
- }
73
- : undefined;
74
- try {
75
- const result = await runtime.facet.run("spawn", input, {
76
- signal: runtime.signal,
77
- ...(observe === undefined ? {} : { observe }),
78
- });
79
- let streamed = stream !== undefined;
80
- if (stream !== undefined)
81
- driver.conclude(stream.conclude(result));
82
- else if (observing && result.kind === "failed") {
83
- writeStderr(renderFailedCallObservation(result, resultContext(), input.prompt === undefined ? {} : { prompt: input.prompt }));
84
- streamed = true;
85
- }
86
- const completion = { kind: "returned", value: result };
87
- if (output === "json")
88
- writeJson(result);
89
- else if (streamed) {
90
- const raw = callRawAnswer(result, true);
91
- emitAnswer(raw ?? "", raw !== undefined);
92
- }
93
- else {
94
- const raw = callRawAnswer(result, false);
95
- emitAnswer(renderVerb("spawn", input, completion, displayContext()), raw !== undefined);
96
- }
97
- return classifyVerb("spawn", input, completion);
98
- }
99
- finally {
100
- driver.close(stream?.flush() ?? []);
101
- }
102
- }
103
53
  export async function runAsk(request, runtime) {
104
54
  const { input, output } = request;
105
- const progress = output === "text" ? askProgressStream(undefined, inputAlias(input.akuma), resultContext()) : undefined;
55
+ const progress = output === "text" ? askProgressStream(undefined, aliasSelector(input.akuma), resultContext()) : undefined;
106
56
  const driver = new ActivityDriver(process.stderr);
107
57
  const observe = progress === undefined
108
58
  ? undefined
@@ -117,9 +67,7 @@ export async function runAsk(request, runtime) {
117
67
  signal: runtime.signal,
118
68
  ...(observe === undefined ? {} : { observe }),
119
69
  };
120
- const result = request.name === "ask"
121
- ? await runtime.facet.run("ask", request.input, run)
122
- : await runtime.facet.run("tell", request.input, run);
70
+ const result = await runtime.facet.run("ask", request.input, run);
123
71
  if (progress !== undefined)
124
72
  driver.conclude(progress.conclude(result).join("\n"));
125
73
  const completion = { kind: "returned", value: result };
@@ -136,14 +84,17 @@ export async function runAsk(request, runtime) {
136
84
  export async function runAkumaHistory(request, runtime) {
137
85
  const { input, output } = request;
138
86
  const result = await runtime.facet.run("history", input, { signal: runtime.signal });
139
- if (result.kind === "contract" || result.kind === "contract-missing")
87
+ if (result.kind === "contract" ||
88
+ result.kind === "contract-exact" ||
89
+ result.kind === "contract-unknown-history" ||
90
+ result.kind === "contract-missing")
140
91
  throw new Error("Akuma history returned a non-Akuma result");
141
92
  const completion = { kind: "returned", value: result };
142
93
  if (output === "json")
143
94
  writeJson(result);
144
95
  else {
145
- const raw = historyRawAnswer(result, "id" in input ? input.id : undefined) !== undefined ||
146
- ("last" in input && input.last === true && result.kind === "akuma-last");
96
+ const raw = historyRawAnswer(result, "item" in input && input.item !== "answer" ? input.item : undefined) !== undefined ||
97
+ ("item" in input && input.item === "answer" && result.kind === "akuma-answer");
147
98
  emitAnswer(renderVerb("history", input, completion, displayContext()), raw);
148
99
  }
149
100
  return classifyVerb("history", input, completion);
@@ -7,4 +7,5 @@ export type ContractTokens = Readonly<{
7
7
  stdin: boolean;
8
8
  output: "text" | "json";
9
9
  }>;
10
+ export declare function refuse(command: ContractCommand, message: string): never;
10
11
  export declare function parseContractCommand(parts: ContractTokens): CliRequest;
@@ -1,14 +1,15 @@
1
1
  import { validateAkumaName } from "../../identity/normalize.js";
2
2
  import { parseAkumaId } from "../../akuma/identity.js";
3
- import { canonicalDebtId } from "../../debt/identity.js";
4
3
  import { contractId } from "../../core/facts/types.js";
4
+ import { parseReadableAkumaAlias } from "../../identity/selector.js";
5
+ import { canonicalDebtId } from "../../debt/identity.js";
5
6
  import { CliUsageError, commandGuide } from "../usage.js";
6
7
  import { CONTRACT_COMMAND_SPECS } from "./contract-help.js";
7
8
  function optionalFlag(flags, name) {
8
9
  const value = flags[name];
9
10
  return typeof value === "string" ? value : undefined;
10
11
  }
11
- function refuse(command, message) {
12
+ export function refuse(command, message) {
12
13
  throw new CliUsageError(message, commandGuide(command, CONTRACT_COMMAND_SPECS[command].usage));
13
14
  }
14
15
  // The CLI restates the literal gate-word grammar its help prints; the corpus
@@ -80,21 +81,17 @@ function parseAmend(parts) {
80
81
  if (parts.flags["clear-after"] === true && after.length > 0)
81
82
  refuse("amend", "--clear-after and --after are mutually exclusive");
82
83
  const gates = parseGateNames(parts, "amend");
83
- if (!parts.stdin && parts.flags.after === undefined && parts.flags["clear-after"] !== true && gates === undefined) {
84
- refuse("amend", "amend requires stdin or --after, --clear-after, or --gates");
85
- }
84
+ const target = optionalFlag(parts.flags, "target");
85
+ // Omitted fields stay omitted: only an explicit empty selection clears anything.
86
86
  const input = {
87
87
  ...(contract === undefined ? {} : { contract }),
88
88
  ...(parts.flags["clear-after"] === true ? { after: [] } : parts.flags.after === undefined ? {} : { after }),
89
89
  ...(gates === undefined ? {} : { gates }),
90
+ ...(target === undefined ? {} : { target }),
90
91
  };
91
- if (parts.stdin)
92
- return { name: "amend", input, acquire: { markdown: true }, output: parts.output };
93
- return {
94
- name: "amend",
95
- input: gates === undefined ? { ...input, after } : { ...input, gates },
96
- output: parts.output,
97
- };
92
+ return parts.stdin
93
+ ? { name: "amend", input, acquire: { markdown: true }, output: parts.output }
94
+ : { name: "amend", input, output: parts.output };
98
95
  }
99
96
  function parseDeliver(parts) {
100
97
  const contract = parts.positionals[0];
@@ -162,11 +159,13 @@ function showSelector(parts) {
162
159
  if (parts.positionals.length > 1)
163
160
  refuse("show", "show accepts at most one selector");
164
161
  const selected = parts.positionals[0];
165
- if (selected !== undefined && ["aku/", "kei", "kei/", "kei/*"].includes(selected))
162
+ if (selected === undefined)
163
+ refuse("show", "show requires one explicit selector");
164
+ if (["aku/", "kei", "kei/", "kei/*"].includes(selected))
166
165
  refuse("show", "show cannot select a category");
167
- if (selected === "aku" || selected?.startsWith("aku/") === true)
166
+ if (selected === "aku" || selected.startsWith("aku/"))
168
167
  refuse("show", "show cannot select an Akuma");
169
- if (selected !== undefined && !selected.startsWith("@") && /[*?\[\]]/u.test(selected))
168
+ if (!selected.startsWith("@") && /[*?\[\]]/u.test(selected))
170
169
  refuse("show", `unsupported show glob: ${selected}`);
171
170
  return selected;
172
171
  }
@@ -178,18 +177,20 @@ function parseStatus(parts) {
178
177
  refuse("status", "status requires one subject; use kanshi for the World board");
179
178
  if (/[*?\[\]]/u.test(selector))
180
179
  refuse("status", `unsupported status glob: ${selector}`);
181
- if (selector.startsWith("@"))
182
- return { name: "status", input: {}, acquire: { selector }, output: parts.output };
183
180
  try {
184
- if (selector.startsWith("kei/"))
185
- return { name: "status", input: { id: contractId(selector) }, output: parts.output };
186
- if (selector.startsWith("aku/"))
187
- return { name: "status", input: { id: parseAkumaId(selector).id }, output: parts.output };
181
+ if (selector.startsWith("@"))
182
+ parseReadableAkumaAlias(selector);
183
+ else if (selector.startsWith("kei/"))
184
+ contractId(selector);
185
+ else if (selector.startsWith("aku/"))
186
+ parseAkumaId(selector);
187
+ else
188
+ refuse("status", "status requires one complete Contract or Akuma identity or @name");
188
189
  }
189
190
  catch (error) {
190
191
  refuse("status", error instanceof Error ? error.message : String(error));
191
192
  }
192
- refuse("status", "status requires one complete Contract or Akuma identity or @name");
193
+ return { name: "status", input: { selector }, output: parts.output };
193
194
  }
194
195
  function parseRegion(parts) {
195
196
  const contract = parts.positionals[0];
@@ -229,21 +230,12 @@ function parseLs(parts) {
229
230
  const limit = listLimit(parts);
230
231
  const bound = limit === undefined ? {} : { limit };
231
232
  const mine = parts.flags.mine === true;
232
- const all = parts.flags.all === true, closed = parts.flags.closed === true;
233
- if (all && closed)
234
- refuse("ls", "--all and --closed are mutually exclusive");
235
- if (selector === "debt" || selector === "debt/") {
236
- if (mine)
237
- refuse("ls", "--mine selects Akuma instances only");
238
- return {
239
- name: "ls",
240
- input: { selector, ...bound, ...(all ? { selection: "all" } : closed ? { selection: "closed" } : {}) },
241
- output: parts.output,
242
- };
243
- }
244
- if (all || closed)
245
- refuse("ls", "--all and --closed select Debts only");
246
- if (["kei", "kei/", "aku", "aku/"].includes(selector)) {
233
+ const all = parts.flags.all === true, settled = parts.flags.settled === true;
234
+ if (all && settled)
235
+ refuse("ls", "--all and --settled are mutually exclusive");
236
+ if ((all || settled) && (selector === "aku" || selector === "aku/"))
237
+ refuse("ls", "--all and --settled select Contract, Debt, or Akuma-instance lifecycles only");
238
+ if (["debt", "debt/", "kei", "kei/", "aku", "aku/"].includes(selector)) {
247
239
  if (mine)
248
240
  refuse("ls", "--mine selects Akuma instances only");
249
241
  }
@@ -251,7 +243,12 @@ function parseLs(parts) {
251
243
  validateInstanceCatalogue(selector);
252
244
  return {
253
245
  name: "ls",
254
- input: { selector, ...bound, ...(mine ? { mine: true } : {}) },
246
+ input: {
247
+ selector,
248
+ ...bound,
249
+ ...(mine ? { mine: true } : {}),
250
+ ...(all ? { lifecycle: "all" } : settled ? { lifecycle: "settled" } : {}),
251
+ },
255
252
  output: parts.output,
256
253
  };
257
254
  }
@@ -277,16 +274,16 @@ export function parseContractCommand(parts) {
277
274
  return { name: "abandon", input: { ...selected, ...(note === undefined ? {} : { note }) }, output };
278
275
  }
279
276
  case "show": {
280
- const id = showSelector(parts);
281
- if (id?.startsWith("debt/") === true) {
277
+ const selector = showSelector(parts);
278
+ if (selector.startsWith("debt/")) {
282
279
  try {
283
- canonicalDebtId(id);
280
+ canonicalDebtId(selector);
284
281
  }
285
282
  catch (error) {
286
283
  refuse("show", error instanceof Error ? error.message : String(error));
287
284
  }
288
285
  }
289
- return { name: "show", input: id === undefined ? {} : { id }, output };
286
+ return { name: "show", input: { selector }, output };
290
287
  }
291
288
  case "kanshi":
292
289
  return { name: "kanshi", input: {}, output };
@@ -31,10 +31,11 @@ export declare const CONTRACT_COMMAND_SPECS: {
31
31
  readonly after: "repeat";
32
32
  readonly "clear-after": "boolean";
33
33
  readonly gates: "raw-value";
34
+ readonly target: "value";
34
35
  readonly json: "boolean";
35
36
  };
36
- readonly usage: "amend [<contract>|@name] [--after <kei/...> [--after <kei/...>]... | --clear-after] [--gates <name,...>] [--repo <path>] [-]";
37
- readonly purpose: "Change a Contract's document, prerequisites, or acceptance gates.";
37
+ readonly usage: "amend [<contract>|@name] [--after <kei/...> [--after <kei/...>]... | --clear-after] [--gates <name,...>] [--target <branch|kei/...>] [--repo <path>] [-]";
38
+ readonly purpose: "Change a Contract's document, target, prerequisites, or acceptance gates.";
38
39
  readonly details: string;
39
40
  };
40
41
  readonly deliver: {
@@ -104,7 +105,7 @@ export declare const CONTRACT_COMMAND_SPECS: {
104
105
  readonly flags: {
105
106
  readonly json: "boolean";
106
107
  };
107
- readonly usage: "show [<contract>|@name] [--repo <path>]\nshow <debt/...>";
108
+ readonly usage: "show <contract|@name> [--repo <path>]\nshow <debt/...>";
108
109
  readonly purpose: "Read one Contract's guidance or one Debt and its prerequisites.";
109
110
  readonly details: string;
110
111
  };
@@ -135,10 +136,10 @@ export declare const CONTRACT_COMMAND_SPECS: {
135
136
  readonly limit: "value";
136
137
  readonly json: "boolean";
137
138
  readonly mine: "boolean";
138
- readonly closed: "boolean";
139
+ readonly settled: "boolean";
139
140
  readonly all: "boolean";
140
141
  };
141
- readonly usage: "ls debt[/] [--closed | --all] [--limit <count>]\nls kei[/] [--limit <count>]\nls aku[/] [--limit <count>]\nls aku/<name>[/] [--limit <count>]\nls \"aku/<name>/*\" [--limit <count>]\nls \"aku/*\" [--limit <count>]\nls \"aku/*/*\" [--limit <count>]\nls [aku/<name>[/] | \"aku/<name>/*\" | \"aku/*/*\"] --mine [--limit <count>]";
142
+ readonly usage: "ls debt[/] [--settled | --all] [--limit <count>]\nls kei[/] [--settled | --all] [--limit <count>]\nls aku[/] [--limit <count>]\nls aku/<name>[/] [--settled | --all] [--limit <count>]\nls \"aku/<name>/*\" [--settled | --all] [--limit <count>]\nls \"aku/*\" [--settled | --all] [--limit <count>]\nls \"aku/*/*\" [--settled | --all] [--limit <count>]\nls [aku/<name>[/] | \"aku/<name>/*\" | \"aku/*/*\"] --mine [--settled | --all] [--limit <count>]";
142
143
  readonly purpose: "List debts (ls debt), contracts (ls kei), or akumas (ls aku).";
143
144
  readonly details: string;
144
145
  };