@astrosheep/keiyaku 2.8.5 → 2.9.1

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 (238) hide show
  1. package/README.md +35 -15
  2. package/build/.tsbuildinfo +1 -1
  3. package/build/agents/{call-terms_v2.js → call-terms.js} +12 -8
  4. package/build/agents/harness/control-types.js +1 -0
  5. package/build/agents/harness/execution-handle.js +23 -3
  6. package/build/agents/harness/index.js +6 -607
  7. package/build/agents/harness/outcome.js +141 -0
  8. package/build/agents/harness/projection.js +310 -0
  9. package/build/agents/harness/router.js +201 -0
  10. package/build/agents/harness/runtime.js +2 -1
  11. package/build/agents/{launch-snapshot_v2.js → launch-snapshot/model.js} +69 -74
  12. package/build/agents/launch-snapshot/resolve.js +72 -0
  13. package/build/agents/opencode-sdk.js +24 -3
  14. package/build/agents/providers/{claude-agent-sdk.js → claude-agent-sdk/adapter.js} +46 -368
  15. package/build/agents/providers/claude-agent-sdk/events.js +218 -0
  16. package/build/agents/providers/claude-agent-sdk/session.js +158 -0
  17. package/build/agents/providers/codex-app-server/adapter.js +347 -0
  18. package/build/agents/providers/codex-app-server/events.js +352 -0
  19. package/build/agents/providers/codex-app-server/session.js +266 -0
  20. package/build/agents/providers/codex-sdk.js +23 -5
  21. package/build/agents/providers/opencode-sdk/adapter.js +344 -0
  22. package/build/agents/providers/opencode-sdk/events.js +354 -0
  23. package/build/agents/providers/opencode-sdk/session.js +180 -0
  24. package/build/agents/providers/pi/adapter.js +269 -0
  25. package/build/agents/providers/pi/checkpoint.js +41 -0
  26. package/build/agents/providers/pi/events.js +282 -0
  27. package/build/agents/{selector_v2.js → selector.js} +8 -6
  28. package/build/cli/commands/akuma/akuma/handler.js +4 -0
  29. package/build/cli/commands/akuma/akuma/meta.js +16 -0
  30. package/build/cli/commands/akuma/catalog.js +8 -0
  31. package/build/cli/commands/akuma/list/handler.js +15 -0
  32. package/build/cli/commands/akuma/list/meta-ls.js +9 -0
  33. package/build/cli/commands/akuma/view/handler.js +34 -0
  34. package/build/cli/commands/akuma/view/meta.js +8 -0
  35. package/build/cli/commands/akuma.js +1 -1
  36. package/build/cli/commands/contract/amend/handler.js +10 -0
  37. package/build/cli/commands/contract/amend/meta.js +12 -0
  38. package/build/cli/commands/contract/arc/handler.js +9 -0
  39. package/build/cli/commands/contract/arc/meta.js +26 -0
  40. package/build/cli/commands/contract/bind/handler.js +23 -0
  41. package/build/cli/commands/contract/bind/meta.js +30 -0
  42. package/build/cli/commands/contract/catalog.js +16 -0
  43. package/build/cli/commands/contract/forfeit/handler.js +13 -0
  44. package/build/cli/commands/contract/forfeit/meta.js +12 -0
  45. package/build/cli/commands/contract/log/handler.js +12 -0
  46. package/build/cli/commands/contract/log/meta.js +12 -0
  47. package/build/cli/commands/contract/petition/handler.js +26 -0
  48. package/build/cli/commands/contract/petition/meta.js +23 -0
  49. package/build/cli/commands/contract/renew/handler.js +10 -0
  50. package/build/cli/commands/contract/renew/meta.js +17 -0
  51. package/build/cli/commands/projection/call/handler.js +42 -0
  52. package/build/cli/commands/projection/call/meta.js +9 -0
  53. package/build/cli/commands/projection/catalog.js +14 -0
  54. package/build/cli/commands/projection/kill/handler.js +37 -0
  55. package/build/cli/commands/projection/kill/meta.js +11 -0
  56. package/build/cli/commands/projection/revive/handler.js +56 -0
  57. package/build/cli/commands/projection/revive/meta.js +9 -0
  58. package/build/cli/commands/projection/status/handler.js +25 -0
  59. package/build/cli/commands/projection/status/meta.js +9 -0
  60. package/build/cli/commands/projection/tell/handler.js +36 -0
  61. package/build/cli/commands/projection/tell/meta.js +9 -0
  62. package/build/cli/commands/projection/wait/handler.js +23 -0
  63. package/build/cli/commands/projection/wait/meta.js +11 -0
  64. package/build/cli/commands/registry.js +100 -0
  65. package/build/cli/commands/shared.js +71 -0
  66. package/build/cli/commands/skills/catalog.js +6 -0
  67. package/build/cli/commands/skills/install/handler.js +10 -0
  68. package/build/cli/commands/skills/install/meta.js +9 -0
  69. package/build/cli/commands/skills/skills/handler.js +4 -0
  70. package/build/cli/commands/skills/skills/meta.js +10 -0
  71. package/build/cli/commands/system/catalog.js +8 -0
  72. package/build/cli/commands/system/completion/handler.js +10 -0
  73. package/build/cli/commands/system/completion/meta.js +9 -0
  74. package/build/cli/commands/system/dump-env/handler.js +3 -0
  75. package/build/cli/commands/system/dump-env/meta.js +10 -0
  76. package/build/cli/commands/system/guide/handler.js +4 -0
  77. package/build/cli/commands/system/guide/meta.js +9 -0
  78. package/build/cli/commands/task/add/handler.js +21 -0
  79. package/build/cli/commands/task/add/meta.js +8 -0
  80. package/build/cli/commands/task/catalog.js +22 -0
  81. package/build/cli/commands/task/doctor/handler.js +4 -0
  82. package/build/cli/commands/task/doctor/meta.js +8 -0
  83. package/build/cli/commands/task/done/handler.js +17 -0
  84. package/build/cli/commands/task/done/meta.js +8 -0
  85. package/build/cli/commands/task/drop/handler.js +6 -0
  86. package/build/cli/commands/task/drop/meta.js +8 -0
  87. package/build/cli/commands/task/ls/handler.js +13 -0
  88. package/build/cli/commands/task/ls/meta.js +8 -0
  89. package/build/cli/commands/task/shared.js +131 -0
  90. package/build/cli/commands/task/start/handler.js +6 -0
  91. package/build/cli/commands/task/start/meta.js +8 -0
  92. package/build/cli/commands/task/stop/handler.js +17 -0
  93. package/build/cli/commands/task/stop/meta.js +8 -0
  94. package/build/cli/commands/task/task/handler.js +5 -0
  95. package/build/cli/commands/task/task/meta.js +11 -0
  96. package/build/cli/commands/task/update/handler.js +18 -0
  97. package/build/cli/commands/task/update/meta.js +8 -0
  98. package/build/cli/commands/task/view/handler.js +14 -0
  99. package/build/cli/commands/task/view/meta.js +8 -0
  100. package/build/cli/completion.js +26 -27
  101. package/build/cli/flags.js +79 -2
  102. package/build/cli/help.js +27 -49
  103. package/build/cli/index.js +121 -374
  104. package/build/cli/output-stream-error-policy.js +17 -0
  105. package/build/cli/parse-flags.js +197 -0
  106. package/build/cli/parse-metadata.js +129 -0
  107. package/build/cli/parse-selectors.js +65 -0
  108. package/build/cli/parse.js +46 -313
  109. package/build/cli/projection-address.js +5 -0
  110. package/build/cli/render/arc.js +1 -1
  111. package/build/cli/render/errors.js +4 -3
  112. package/build/cli/render/format.js +14 -0
  113. package/build/cli/render/kanshi.js +106 -0
  114. package/build/cli/render/petition.js +24 -1
  115. package/build/cli/render/projection-activity.js +5 -1
  116. package/build/cli/render/shared.js +2 -2
  117. package/build/cli/render/status.js +79 -13
  118. package/build/cli/render/task.js +113 -0
  119. package/build/cli/render/wait.js +23 -3
  120. package/build/cli/types.js +1 -1
  121. package/build/config/{akuma-loader_v2.js → akuma-loader.js} +7 -4
  122. package/build/config/env.js +9 -4
  123. package/build/config/settings/disease.js +26 -0
  124. package/build/config/settings/knobs.js +8 -0
  125. package/build/config/settings/loader.js +244 -0
  126. package/build/config/settings/schema.js +276 -0
  127. package/build/core/addressing.js +1 -1
  128. package/build/core/amend.js +5 -8
  129. package/build/core/arc.js +7 -8
  130. package/build/core/bind-workspace.js +123 -0
  131. package/build/core/bind.js +75 -155
  132. package/build/core/call/call.js +229 -0
  133. package/build/core/call/context.js +251 -0
  134. package/build/core/call/execution.js +217 -0
  135. package/build/core/call/prompt.js +42 -0
  136. package/build/core/call/reference.js +24 -0
  137. package/build/core/call-persist.js +10 -3
  138. package/build/core/claim-delivery.js +247 -0
  139. package/build/core/claim.js +39 -277
  140. package/build/core/context.js +2 -1
  141. package/build/core/{render.js → contract-view.js} +12 -140
  142. package/build/core/draft.js +107 -9
  143. package/build/core/entry.js +9 -1
  144. package/build/core/execution-coordinate.js +4 -20
  145. package/build/core/execution-pact.js +16 -31
  146. package/build/core/forfeit.js +35 -22
  147. package/build/core/hints.js +2 -2
  148. package/build/core/log.js +2 -2
  149. package/build/core/path-coordinate.js +27 -0
  150. package/build/core/petition-claim-gates.js +8 -6
  151. package/build/core/petition-preview.js +97 -0
  152. package/build/core/petition-run.js +5 -7
  153. package/build/core/petition.js +39 -26
  154. package/build/core/projection/generation/database.js +306 -0
  155. package/build/core/projection/generation/identity.js +84 -0
  156. package/build/core/projection/generation/model.js +201 -0
  157. package/build/core/projection/generation/store.js +73 -0
  158. package/build/core/projection/generation/transitions.js +258 -0
  159. package/build/core/projection/heart.js +0 -307
  160. package/build/core/projection/tell/database.js +109 -0
  161. package/build/core/projection/tell/model.js +97 -0
  162. package/build/core/{projection-tells.js → projection/tell/store.js} +3 -158
  163. package/build/core/projection-activity.js +23 -2
  164. package/build/core/projection-coordinate.js +14 -2
  165. package/build/core/projection-core.js +2 -1
  166. package/build/core/projection-execution-observer.js +259 -0
  167. package/build/core/projection-generation-continuation.js +1 -1
  168. package/build/core/projection-generation-execution.js +90 -20
  169. package/build/core/projection-generation-launcher.js +1 -1
  170. package/build/core/projection-generation-runner.js +198 -4
  171. package/build/core/projection-identity.js +1 -1
  172. package/build/core/projection-kill.js +50 -17
  173. package/build/core/projection-life-observer.js +1 -1
  174. package/build/core/projection-life-protocol.js +10 -0
  175. package/build/core/projection-mint.js +1 -1
  176. package/build/core/projection-status.js +45 -32
  177. package/build/core/projection-wait.js +12 -2
  178. package/build/core/projection-wake.js +5 -2
  179. package/build/core/{queue_v2.js → queue.js} +2 -1
  180. package/build/core/registry.js +1 -1
  181. package/build/core/renew.js +9 -11
  182. package/build/core/response-artifact-catalog-sqlite.js +112 -0
  183. package/build/core/response-artifact-catalog.js +7 -0
  184. package/build/core/seal.js +44 -16
  185. package/build/core/status/board.js +289 -0
  186. package/build/core/status/drift.js +99 -0
  187. package/build/core/status/lifecycle.js +84 -0
  188. package/build/core/status/reconciliation.js +131 -0
  189. package/build/core/stored-agent-event.js +28 -4
  190. package/build/core/target-ref.js +10 -0
  191. package/build/core/task/board.js +175 -0
  192. package/build/core/task/commands.js +211 -0
  193. package/build/core/task/document.js +189 -0
  194. package/build/core/task/model.js +1 -0
  195. package/build/core/task/settlement-git.js +207 -0
  196. package/build/core/task/settlement-policy.js +82 -0
  197. package/build/core/task/source-board.js +84 -0
  198. package/build/core/task/source-model.js +1 -0
  199. package/build/core/task/validation.js +44 -0
  200. package/build/core/task-contract.js +237 -0
  201. package/build/core/task-doctor.js +14 -0
  202. package/build/core/task-git-actor.js +38 -0
  203. package/build/core/task-git-runtime.js +37 -0
  204. package/build/core/task-git-store.js +385 -0
  205. package/build/core/task-repository.js +1 -0
  206. package/build/core/task-store-repository.js +86 -0
  207. package/build/core/task-store.js +1 -0
  208. package/build/core/task-worktree.js +51 -0
  209. package/build/core/task.js +4 -0
  210. package/build/core/transcripts.js +138 -56
  211. package/build/core/validation.js +17 -0
  212. package/build/core/verdict.js +2 -2
  213. package/build/core/worktree-path.js +33 -8
  214. package/build/flow-error.js +5 -2
  215. package/build/generated/version.js +1 -1
  216. package/build/git/branches.js +33 -9
  217. package/build/git/commits.js +3 -0
  218. package/build/git/core.js +9 -0
  219. package/build/git/diff/parsers.js +0 -94
  220. package/build/index.js +2 -0
  221. package/build/keiyaku-constants.js +2 -0
  222. package/build/keiyaku.js +4 -3
  223. package/package.json +3 -2
  224. package/skills/keiyaku/SKILL.md +30 -13
  225. package/skills/keiyaku-akuma/SKILL.md +30 -57
  226. package/skills/keiyaku-task/SKILL.md +51 -0
  227. package/skills/keiyaku-workflow/SKILL.md +71 -0
  228. package/build/agents/harness/pump.js +0 -158
  229. package/build/agents/providers/codex-app-server.js +0 -864
  230. package/build/agents/providers/opencode-sdk.js +0 -363
  231. package/build/agents/providers/pi.js +0 -557
  232. package/build/config/settings.js +0 -533
  233. package/build/core/call.js +0 -686
  234. package/build/core/projection/generation.js +0 -412
  235. package/build/core/projection/identity.js +0 -81
  236. package/build/core/projection/mint.js +0 -174
  237. package/build/core/projection-generation-store.js +0 -707
  238. package/build/core/status.js +0 -539
@@ -0,0 +1,197 @@
1
+ import { FlowError } from "../flow-error.js";
2
+ import { getCommandMetadata } from "./commands/registry.js";
3
+ import { BOOLEAN_FLAGS, CONTROL_FLAGS, SHORT_FLAG_ALIASES, VALUE_FLAGS, } from "./flags.js";
4
+ import { normalizeContractAddress, parseWaitTimeout } from "./parse-metadata.js";
5
+ function allowedFlagsForParse(command) {
6
+ const meta = getCommandMetadata(command);
7
+ return meta.parseFlags ?? meta.flags;
8
+ }
9
+ export function parseFlagName(raw) {
10
+ return raw.slice(2);
11
+ }
12
+ export function assertAllowedFlag(command, name) {
13
+ if (!allowedFlagsForParse(command).includes(name)) {
14
+ throw new FlowError("EMPTY_PARAM", `option --${name} is not valid for ${command}`);
15
+ }
16
+ }
17
+ export function assignFlag(flags, name, value) {
18
+ switch (name) {
19
+ case "cwd":
20
+ flags.cwd = String(value);
21
+ return;
22
+ case "repo":
23
+ flags.repo = String(value);
24
+ return;
25
+ case "contract":
26
+ flags.contractId = normalizeContractAddress(String(value));
27
+ flags.contractAddressSource = "explicit-flag";
28
+ return;
29
+ case "akuma":
30
+ flags.akuma = String(value);
31
+ return;
32
+ case "projection":
33
+ flags.projection = String(value);
34
+ return;
35
+ case "alias":
36
+ flags.alias = String(value);
37
+ return;
38
+ case "timeout":
39
+ case "wait":
40
+ flags.timeoutMs = parseWaitTimeout(String(value));
41
+ return;
42
+ case "model":
43
+ flags.model = String(value);
44
+ return;
45
+ case "effort":
46
+ flags.effort = String(value);
47
+ return;
48
+ case "incognito":
49
+ flags.incognito = Boolean(value);
50
+ return;
51
+ case "bare":
52
+ flags.bare = Boolean(value);
53
+ return;
54
+ case "detach":
55
+ flags.detach = Boolean(value);
56
+ return;
57
+ case "draft-only":
58
+ flags.draftOnly = Boolean(value);
59
+ return;
60
+ case "exclusive":
61
+ flags.exclusive = Boolean(value);
62
+ return;
63
+ case "place":
64
+ if (flags.bindPlace !== undefined) {
65
+ throw new FlowError("EMPTY_PARAM", "option --place may only be specified once");
66
+ }
67
+ flags.bindPlace = String(value);
68
+ return;
69
+ case "objective":
70
+ if (flags.bindObjective !== undefined) {
71
+ throw new FlowError("EMPTY_PARAM", "option --objective may only be specified once");
72
+ }
73
+ flags.bindObjective = String(value);
74
+ return;
75
+ case "scope":
76
+ if (flags.bindScope !== undefined) {
77
+ throw new FlowError("EMPTY_PARAM", "option --scope may only be specified once");
78
+ }
79
+ flags.bindScope = String(value);
80
+ return;
81
+ case "checks":
82
+ if (flags.bindChecks !== undefined) {
83
+ throw new FlowError("EMPTY_PARAM", "option --checks may only be specified once");
84
+ }
85
+ flags.bindChecks = String(value);
86
+ return;
87
+ case "task":
88
+ if (flags.bindTaskId !== undefined) {
89
+ throw new FlowError("EMPTY_PARAM", "option --task may only be specified once");
90
+ }
91
+ flags.bindTaskId = String(value);
92
+ return;
93
+ case "after":
94
+ flags.after = [...(flags.after ?? []), String(value)];
95
+ return;
96
+ case "force":
97
+ flags.force = Boolean(value);
98
+ return;
99
+ case "reason":
100
+ flags.reason = String(value);
101
+ return;
102
+ case "dry-run":
103
+ flags.dryRun = Boolean(value);
104
+ return;
105
+ case "waive":
106
+ flags.waivePaths = [...(flags.waivePaths ?? []), String(value)];
107
+ return;
108
+ case "shell":
109
+ flags.shell = String(value);
110
+ return;
111
+ case "word":
112
+ flags.word = String(value);
113
+ return;
114
+ case "previous":
115
+ flags.previous = String(value);
116
+ return;
117
+ case "complete":
118
+ flags.complete = Boolean(value);
119
+ return;
120
+ case "all":
121
+ flags.all = Boolean(value);
122
+ return;
123
+ case "target":
124
+ if (flags.target !== undefined) {
125
+ throw new FlowError("EMPTY_PARAM", "option --target may only be specified once");
126
+ }
127
+ flags.target = String(value);
128
+ return;
129
+ case "json":
130
+ flags.json = Boolean(value);
131
+ return;
132
+ case "done":
133
+ flags.done = Boolean(value);
134
+ return;
135
+ case "pri": {
136
+ const raw = String(value);
137
+ if (!/^[0-3]$/.test(raw)) {
138
+ throw new FlowError("EMPTY_PARAM", "task priority must be an integer from 0 through 3");
139
+ }
140
+ if (flags.taskPri !== undefined) {
141
+ throw new FlowError("EMPTY_PARAM", "option --pri may only be specified once");
142
+ }
143
+ flags.taskPri = Number(raw);
144
+ return;
145
+ }
146
+ case "needs":
147
+ flags.taskNeeds = [...(flags.taskNeeds ?? []), String(value)];
148
+ return;
149
+ case "drop-needs":
150
+ flags.taskDropNeeds = [...(flags.taskDropNeeds ?? []), String(value)];
151
+ return;
152
+ case "from":
153
+ flags.taskFrom = [...(flags.taskFrom ?? []), String(value)];
154
+ return;
155
+ case "parent":
156
+ if (flags.taskParent !== undefined) {
157
+ throw new FlowError("EMPTY_PARAM", "option --parent may only be specified once");
158
+ }
159
+ flags.taskParent = String(value);
160
+ return;
161
+ case "no-parent":
162
+ flags.taskNoParent = Boolean(value);
163
+ return;
164
+ case "title":
165
+ if (flags.taskTitle !== undefined) {
166
+ throw new FlowError("EMPTY_PARAM", "option --title may only be specified once");
167
+ }
168
+ flags.taskTitle = String(value);
169
+ return;
170
+ case "body":
171
+ if (flags.taskBody !== undefined) {
172
+ throw new FlowError("EMPTY_PARAM", "option --body may only be specified once");
173
+ }
174
+ flags.taskBody = String(value);
175
+ return;
176
+ default:
177
+ throw new FlowError("EMPTY_PARAM", `unknown option: --${name}`);
178
+ }
179
+ }
180
+ export function readValueFlag(name, token, eq, tokens, index) {
181
+ if (eq !== -1) {
182
+ const value = token.slice(eq + 1);
183
+ if (value === "" && name !== "target" && name !== "body") {
184
+ throw new FlowError("EMPTY_PARAM", `option --${name} requires a value`);
185
+ }
186
+ return { value, nextIndex: index };
187
+ }
188
+ const value = tokens[index + 1];
189
+ if (value === undefined || value === "--" || value.startsWith("--")) {
190
+ throw new FlowError("EMPTY_PARAM", `option --${name} requires a value`);
191
+ }
192
+ if (value === "" && name !== "target" && name !== "body") {
193
+ throw new FlowError("EMPTY_PARAM", `option --${name} requires a value`);
194
+ }
195
+ return { value, nextIndex: index + 1 };
196
+ }
197
+ export { BOOLEAN_FLAGS, CONTROL_FLAGS, SHORT_FLAG_ALIASES, VALUE_FLAGS };
@@ -0,0 +1,129 @@
1
+ import { FlowError } from "../flow-error.js";
2
+ import { HELP_FLAGS, SHORT_FLAG_ALIASES, VALUE_FLAGS } from "./flags.js";
3
+ import { commandParseOrder, getCommandMetadata } from "./commands/registry.js";
4
+ import { TASK_SUBCOMMANDS } from "./types.js";
5
+ export function normalizeContractAddress(raw) {
6
+ const value = raw.startsWith("@") ? raw.slice(1) : raw;
7
+ if (!value.trim()) {
8
+ throw new FlowError("EMPTY_PARAM", "contract address cannot be empty");
9
+ }
10
+ return value.trim();
11
+ }
12
+ export function isCallCommand(command) {
13
+ return command === "call";
14
+ }
15
+ export function isPetitionDryRunInvocation(tokens) {
16
+ const boundary = tokens.indexOf("--");
17
+ const head = boundary === -1 ? tokens : tokens.slice(0, boundary);
18
+ if (!head.some((token) => token === "--dry-run" || token.startsWith("--dry-run="))) {
19
+ return false;
20
+ }
21
+ for (let index = 0; index < head.length; index += 1) {
22
+ const token = head[index];
23
+ if (HELP_FLAGS.has(token) || token.startsWith("@")) {
24
+ continue;
25
+ }
26
+ if (/^-[A-Za-z]$/.test(token)) {
27
+ const name = SHORT_FLAG_ALIASES[token.slice(1)];
28
+ if (name && VALUE_FLAGS.has(name)) {
29
+ index += 1;
30
+ }
31
+ continue;
32
+ }
33
+ if (token.startsWith("--")) {
34
+ const eq = token.indexOf("=");
35
+ const name = (eq === -1 ? token : token.slice(0, eq)).slice(2);
36
+ if (eq === -1 && VALUE_FLAGS.has(name)) {
37
+ index += 1;
38
+ }
39
+ continue;
40
+ }
41
+ return token === "petition";
42
+ }
43
+ return false;
44
+ }
45
+ export function commandUsesPromptInput(command) {
46
+ return isCallCommand(command) || command === "tell" || command === "revive";
47
+ }
48
+ export function parseWaitTimeout(value) {
49
+ const matched = /^(?<amount>[1-9][0-9]*)(?<unit>[smh])$/.exec(value);
50
+ if (!matched?.groups) {
51
+ throw new FlowError("EMPTY_PARAM", "wait timeout must use <positive integer><s|m|h>, for example 45s, 5m, or 2h (maximum 24h)");
52
+ }
53
+ const amount = Number(matched.groups.amount);
54
+ const multiplier = matched.groups.unit === "s" ? 1_000 : matched.groups.unit === "m" ? 60_000 : 3_600_000;
55
+ const timeoutMs = amount * multiplier;
56
+ if (!Number.isSafeInteger(timeoutMs) || timeoutMs > 24 * 3_600_000) {
57
+ throw new FlowError("EMPTY_PARAM", "wait timeout must use <positive integer><s|m|h>, for example 45s, 5m, or 2h (maximum 24h)");
58
+ }
59
+ return timeoutMs;
60
+ }
61
+ export function commandPositionalRange(command) {
62
+ if (command === "akuma view") {
63
+ return { min: 1, max: 1, label: "<name>" };
64
+ }
65
+ if (command === "log") {
66
+ return { min: 0, max: 0, label: "" };
67
+ }
68
+ if (isCallCommand(command)) {
69
+ return { min: 1, max: 1, label: "<BODY|->" };
70
+ }
71
+ if (command === "tell") {
72
+ return { min: 2, max: 2, label: "<PROJECTION> <BODY|->" };
73
+ }
74
+ if (command === "revive") {
75
+ return { min: 1, max: 2, label: "<ARTIFACT> [BODY|-]" };
76
+ }
77
+ if (command === "wait") {
78
+ return { min: 1, max: 1, label: "<projection-address>" };
79
+ }
80
+ if (command === "kill") {
81
+ return { min: 1, max: 1, label: "<projection-address>" };
82
+ }
83
+ if (command === "status") {
84
+ return { min: 0, max: 1, label: "[projection-id]" };
85
+ }
86
+ if (command === "task add") {
87
+ return { min: 1, max: 1, label: "<BODY|->" };
88
+ }
89
+ if (command === "task view" || command === "task start" || command === "task drop") {
90
+ return { min: 1, max: 1, label: "<ID>" };
91
+ }
92
+ if (command === "task update") {
93
+ return { min: 1, max: 1, label: "<ID>" };
94
+ }
95
+ if (command === "task stop" || command === "task done") {
96
+ return { min: 0, max: 1, label: "[ID]" };
97
+ }
98
+ return { min: 0, max: 0 };
99
+ }
100
+ export function commandRequiresStdin(command) {
101
+ return getCommandMetadata(command).stdin === "required";
102
+ }
103
+ export function resolveCommand(tokens) {
104
+ if (tokens[0] === "petition" && (tokens[1] === "claim" || tokens[1] === "forfeit")) {
105
+ throw new FlowError("UNKNOWN_COMMAND", `unknown command: petition ${tokens[1]}`);
106
+ }
107
+ for (const command of commandParseOrder()) {
108
+ const parts = command.split(" ");
109
+ if (parts.every((part, index) => tokens[index] === part)) {
110
+ return { command, rest: tokens.slice(parts.length) };
111
+ }
112
+ }
113
+ const [head] = tokens;
114
+ if (head === "skills") {
115
+ return { command: "skills", rest: tokens.slice(1) };
116
+ }
117
+ if (!head) {
118
+ throw new FlowError("EMPTY_PARAM", "command cannot be empty");
119
+ }
120
+ throw new FlowError("UNKNOWN_COMMAND", `unknown command: ${head ?? ""}`.trim());
121
+ }
122
+ export function splitAtLiteralBoundary(tokens) {
123
+ const boundary = tokens.indexOf("--");
124
+ if (boundary === -1) {
125
+ return { head: tokens, payload: [] };
126
+ }
127
+ return { head: tokens.slice(0, boundary), payload: tokens.slice(boundary + 1) };
128
+ }
129
+ export { TASK_SUBCOMMANDS };
@@ -0,0 +1,65 @@
1
+ import { FlowError } from "../flow-error.js";
2
+ import { assignFlag } from "./parse-flags.js";
3
+ import { normalizeContractAddress } from "./parse-metadata.js";
4
+ const COMMISSION_SELECTOR_COMMANDS = new Set([
5
+ "arc",
6
+ "amend",
7
+ "call",
8
+ "wait",
9
+ "tell",
10
+ "kill",
11
+ "log",
12
+ "renew",
13
+ "petition",
14
+ "forfeit",
15
+ ]);
16
+ function formatSelectorList(items) {
17
+ if (items.length <= 1) {
18
+ return items[0] ?? "";
19
+ }
20
+ if (items.length === 2) {
21
+ return `${items[0]} and ${items[1]}`;
22
+ }
23
+ return `${items.slice(0, -1).join(", ")}, and ${items[items.length - 1]}`;
24
+ }
25
+ export function applyCommissionSelector(command, flags, atTokens, contractFlagRaws) {
26
+ if (atTokens.length > 0 && contractFlagRaws.length > 0) {
27
+ throw new FlowError("EMPTY_PARAM", `commission address supplied twice: ${atTokens[0]} and --contract ${contractFlagRaws[0]}; use exactly one form`);
28
+ }
29
+ if (atTokens.length > 1) {
30
+ throw new FlowError("EMPTY_PARAM", `${command} accepts one commission address; got ${formatSelectorList(atTokens)}`);
31
+ }
32
+ if (contractFlagRaws.length > 1) {
33
+ throw new FlowError("EMPTY_PARAM", `${command} accepts one commission address; got ${formatSelectorList(contractFlagRaws.map((raw) => `--contract ${raw}`))}`);
34
+ }
35
+ if (atTokens.length === 1) {
36
+ flags.contractId = normalizeContractAddress(atTokens[0]);
37
+ flags.contractAddressSource = "at-address";
38
+ }
39
+ else if (contractFlagRaws.length === 1) {
40
+ assignFlag(flags, "contract", contractFlagRaws[0]);
41
+ }
42
+ }
43
+ export function assertCommissionSelectorAllowed(command, flags) {
44
+ if (flags.contractId === undefined || COMMISSION_SELECTOR_COMMANDS.has(command)) {
45
+ return;
46
+ }
47
+ throw new FlowError("EMPTY_PARAM", command === "bind"
48
+ ? `bind creates a commission and does not accept @${flags.contractId}; use -C/--cwd to select the repository`
49
+ : `contract address @${flags.contractId} is not valid for ${command}`);
50
+ }
51
+ export function assertProjectionSelectorPresent(command, flags, atTokens, contractFlagRaws, restLength, payloadLength) {
52
+ if ((command !== "wait" && command !== "tell") || flags.contractId === undefined) {
53
+ return;
54
+ }
55
+ const selectorSpelling = flags.contractAddressSource === "at-address"
56
+ ? atTokens[0] ?? `@${flags.contractId}`
57
+ : `--contract ${contractFlagRaws[0] ?? flags.contractId}`;
58
+ const message = `${command} requires a projection id or alias; ${selectorSpelling} only limits projection lookup, so add the projection address`;
59
+ if (command === "wait" && restLength + payloadLength === 0) {
60
+ throw new FlowError("EMPTY_PARAM", message);
61
+ }
62
+ if (command === "tell" && restLength === 0) {
63
+ throw new FlowError("EMPTY_PARAM", message);
64
+ }
65
+ }