@crouton-kit/crouter 0.3.8 → 0.3.12

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 (184) hide show
  1. package/bin/crtrd +2 -0
  2. package/dist/builtin-personas/design/base.md +9 -0
  3. package/dist/builtin-personas/design/orchestrator.md +10 -0
  4. package/dist/builtin-personas/developer/base.md +9 -0
  5. package/dist/builtin-personas/developer/orchestrator.md +12 -0
  6. package/dist/builtin-personas/explore/base.md +9 -0
  7. package/dist/builtin-personas/explore/orchestrator.md +9 -0
  8. package/dist/builtin-personas/general/base.md +5 -0
  9. package/dist/builtin-personas/general/orchestrator.md +7 -0
  10. package/dist/builtin-personas/orchestration-kernel.md +71 -0
  11. package/dist/builtin-personas/plan/base.md +7 -0
  12. package/dist/builtin-personas/plan/orchestrator.md +12 -0
  13. package/dist/builtin-personas/review/base.md +7 -0
  14. package/dist/builtin-personas/review/orchestrator.md +9 -0
  15. package/dist/builtin-personas/runtime-base.md +39 -0
  16. package/dist/builtin-personas/spec/base.md +7 -0
  17. package/dist/builtin-personas/spec/orchestrator.md +10 -0
  18. package/dist/builtin-skills/skills/design/SKILL.md +51 -0
  19. package/dist/builtin-skills/skills/development/SKILL.md +109 -0
  20. package/dist/builtin-skills/skills/planning/SKILL.md +59 -0
  21. package/dist/builtin-skills/skills/spec/SKILL.md +83 -0
  22. package/dist/cli.js +25 -27
  23. package/dist/commands/{job.d.ts → attention.d.ts} +1 -1
  24. package/dist/commands/attention.js +152 -0
  25. package/dist/commands/canvas.d.ts +2 -0
  26. package/dist/commands/canvas.js +35 -0
  27. package/dist/commands/{agent.d.ts → daemon.d.ts} +1 -1
  28. package/dist/commands/daemon.js +111 -0
  29. package/dist/commands/dashboard.d.ts +2 -0
  30. package/dist/commands/dashboard.js +65 -0
  31. package/dist/commands/human/prompts.d.ts +5 -0
  32. package/dist/commands/human/prompts.js +269 -0
  33. package/dist/commands/human/queue.d.ts +3 -0
  34. package/dist/commands/human/queue.js +133 -0
  35. package/dist/commands/human/shared.d.ts +43 -0
  36. package/dist/commands/human/shared.js +107 -0
  37. package/dist/commands/human.js +15 -427
  38. package/dist/commands/node.d.ts +2 -0
  39. package/dist/commands/node.js +354 -0
  40. package/dist/commands/pkg/market-inspect.d.ts +1 -0
  41. package/dist/commands/pkg/market-inspect.js +157 -0
  42. package/dist/commands/pkg/market-manage.d.ts +1 -0
  43. package/dist/commands/pkg/market-manage.js +316 -0
  44. package/dist/commands/pkg/market.d.ts +1 -0
  45. package/dist/commands/pkg/market.js +16 -0
  46. package/dist/commands/pkg/plugin-inspect.d.ts +1 -0
  47. package/dist/commands/pkg/plugin-inspect.js +142 -0
  48. package/dist/commands/pkg/plugin-manage.d.ts +1 -0
  49. package/dist/commands/pkg/plugin-manage.js +294 -0
  50. package/dist/commands/pkg/plugin.d.ts +1 -0
  51. package/dist/commands/pkg/plugin.js +16 -0
  52. package/dist/commands/pkg/shared.d.ts +5 -0
  53. package/dist/commands/pkg/shared.js +61 -0
  54. package/dist/commands/pkg.js +8 -1004
  55. package/dist/commands/push.d.ts +3 -0
  56. package/dist/commands/push.js +159 -0
  57. package/dist/commands/revive.d.ts +2 -0
  58. package/dist/commands/revive.js +64 -0
  59. package/dist/commands/skill/author.d.ts +3 -0
  60. package/dist/commands/skill/author.js +147 -0
  61. package/dist/commands/skill/find.d.ts +4 -0
  62. package/dist/commands/skill/find.js +254 -0
  63. package/dist/commands/skill/read.d.ts +1 -0
  64. package/dist/commands/skill/read.js +89 -0
  65. package/dist/commands/skill/shared.d.ts +19 -0
  66. package/dist/commands/skill/shared.js +207 -0
  67. package/dist/commands/skill/state.d.ts +3 -0
  68. package/dist/commands/skill/state.js +69 -0
  69. package/dist/commands/skill.js +12 -681
  70. package/dist/commands/sys/config.d.ts +1 -0
  71. package/dist/commands/sys/config.js +186 -0
  72. package/dist/commands/sys/doctor.d.ts +1 -0
  73. package/dist/commands/sys/doctor.js +369 -0
  74. package/dist/commands/sys/shared.d.ts +3 -0
  75. package/dist/commands/sys/shared.js +24 -0
  76. package/dist/commands/sys/update.d.ts +2 -0
  77. package/dist/commands/sys/update.js +114 -0
  78. package/dist/commands/sys.js +9 -694
  79. package/dist/core/__tests__/argv-parser.test.js +19 -1
  80. package/dist/core/__tests__/canvas-inbox-watcher.test.js +100 -0
  81. package/dist/core/__tests__/canvas.test.js +154 -0
  82. package/dist/core/__tests__/reset.test.js +105 -0
  83. package/dist/core/__tests__/resolver.test.js +69 -1
  84. package/dist/core/__tests__/unknown-path.test.d.ts +1 -0
  85. package/dist/core/__tests__/unknown-path.test.js +52 -0
  86. package/dist/core/bootstrap.d.ts +2 -0
  87. package/dist/core/bootstrap.js +66 -0
  88. package/dist/core/canvas/attention.d.ts +24 -0
  89. package/dist/core/canvas/attention.js +94 -0
  90. package/dist/core/canvas/canvas.d.ts +40 -0
  91. package/dist/core/canvas/canvas.js +210 -0
  92. package/dist/core/canvas/db.d.ts +7 -0
  93. package/dist/core/canvas/db.js +61 -0
  94. package/dist/core/canvas/index.d.ts +4 -0
  95. package/dist/core/canvas/index.js +6 -0
  96. package/dist/core/canvas/paths.d.ts +16 -0
  97. package/dist/core/canvas/paths.js +62 -0
  98. package/dist/core/canvas/render.d.ts +30 -0
  99. package/dist/core/canvas/render.js +186 -0
  100. package/dist/core/canvas/types.d.ts +87 -0
  101. package/dist/core/canvas/types.js +8 -0
  102. package/dist/core/command.d.ts +63 -2
  103. package/dist/core/command.js +97 -24
  104. package/dist/core/feed/feed.d.ts +43 -0
  105. package/dist/core/feed/feed.js +116 -0
  106. package/dist/core/feed/inbox.d.ts +50 -0
  107. package/dist/core/feed/inbox.js +124 -0
  108. package/dist/core/frontmatter.d.ts +10 -0
  109. package/dist/core/frontmatter.js +24 -9
  110. package/dist/core/help.d.ts +39 -8
  111. package/dist/core/help.js +69 -35
  112. package/dist/core/io.d.ts +15 -1
  113. package/dist/core/io.js +56 -6
  114. package/dist/core/personas/index.d.ts +12 -0
  115. package/dist/core/personas/index.js +10 -0
  116. package/dist/core/personas/loader.d.ts +44 -0
  117. package/dist/core/personas/loader.js +157 -0
  118. package/dist/core/personas/resolve.d.ts +36 -0
  119. package/dist/core/personas/resolve.js +110 -0
  120. package/dist/core/render.d.ts +11 -0
  121. package/dist/core/render.js +126 -0
  122. package/dist/core/resolver.d.ts +10 -0
  123. package/dist/core/resolver.js +160 -2
  124. package/dist/core/runtime/front-door.d.ts +10 -0
  125. package/dist/core/runtime/front-door.js +97 -0
  126. package/dist/core/runtime/kickoff.d.ts +23 -0
  127. package/dist/core/runtime/kickoff.js +134 -0
  128. package/dist/core/runtime/launch.d.ts +34 -0
  129. package/dist/core/runtime/launch.js +85 -0
  130. package/dist/core/runtime/nodes.d.ts +38 -0
  131. package/dist/core/runtime/nodes.js +95 -0
  132. package/dist/core/runtime/presence.d.ts +38 -0
  133. package/dist/core/runtime/presence.js +152 -0
  134. package/dist/core/runtime/promote.d.ts +30 -0
  135. package/dist/core/runtime/promote.js +105 -0
  136. package/dist/core/runtime/reset.d.ts +13 -0
  137. package/dist/core/runtime/reset.js +97 -0
  138. package/dist/core/runtime/revive.d.ts +26 -0
  139. package/dist/core/runtime/revive.js +89 -0
  140. package/dist/core/runtime/roadmap.d.ts +12 -0
  141. package/dist/core/runtime/roadmap.js +52 -0
  142. package/dist/core/runtime/spawn.d.ts +33 -0
  143. package/dist/core/runtime/spawn.js +118 -0
  144. package/dist/core/runtime/stop-guard.d.ts +18 -0
  145. package/dist/core/runtime/stop-guard.js +33 -0
  146. package/dist/core/runtime/tmux.d.ts +88 -0
  147. package/dist/core/runtime/tmux.js +198 -0
  148. package/dist/core/spawn.d.ts +17 -80
  149. package/dist/core/spawn.js +15 -219
  150. package/dist/daemon/crtrd-cli.d.ts +1 -0
  151. package/dist/daemon/crtrd-cli.js +4 -0
  152. package/dist/daemon/crtrd.d.ts +20 -0
  153. package/dist/daemon/crtrd.js +200 -0
  154. package/dist/daemon/manage.d.ts +17 -0
  155. package/dist/daemon/manage.js +57 -0
  156. package/dist/pi-extensions/canvas-inbox-watcher.d.ts +16 -0
  157. package/dist/pi-extensions/canvas-inbox-watcher.js +229 -0
  158. package/dist/pi-extensions/canvas-nav.d.ts +32 -0
  159. package/dist/pi-extensions/canvas-nav.js +536 -0
  160. package/dist/pi-extensions/canvas-stophook.d.ts +17 -0
  161. package/dist/pi-extensions/canvas-stophook.js +373 -0
  162. package/dist/types.d.ts +21 -0
  163. package/dist/types.js +3 -0
  164. package/package.json +6 -5
  165. package/dist/commands/agent.js +0 -384
  166. package/dist/commands/debug.d.ts +0 -3
  167. package/dist/commands/debug.js +0 -179
  168. package/dist/commands/job.js +0 -344
  169. package/dist/commands/plan.d.ts +0 -4
  170. package/dist/commands/plan.js +0 -309
  171. package/dist/commands/spec.d.ts +0 -3
  172. package/dist/commands/spec.js +0 -286
  173. package/dist/core/__tests__/flow-leaves.test.js +0 -248
  174. package/dist/core/__tests__/job.test.js +0 -310
  175. package/dist/core/__tests__/jobs.test.js +0 -66
  176. package/dist/core/jobs.d.ts +0 -101
  177. package/dist/core/jobs.js +0 -462
  178. package/dist/prompts/agent.d.ts +0 -18
  179. package/dist/prompts/agent.js +0 -153
  180. package/dist/prompts/debug.d.ts +0 -8
  181. package/dist/prompts/debug.js +0 -44
  182. /package/dist/core/__tests__/{flow-leaves.test.d.ts → canvas-inbox-watcher.test.d.ts} +0 -0
  183. /package/dist/core/__tests__/{job.test.d.ts → canvas.test.d.ts} +0 -0
  184. /package/dist/core/__tests__/{jobs.test.d.ts → reset.test.d.ts} +0 -0
@@ -1,3 +0,0 @@
1
- export declare const SPEC_NEW_GUIDE = "## Spec workflow\n\nBuild and save a design + requirements spec: a document describing what to\nbuild, the shape of the solution, and the behaviors it must satisfy. A spec is\nupstream of a plan \u2014 it captures decisions, not implementation steps.\n\nAnti-pattern: do not fish for clarifications upfront. Draft a concrete spec\nfirst based on your investigation, then iterate. A specific draft the user can\nreact to converges faster than a list of questions in a vacuum.\n\n### Phase 1: Shape\n\nBuild a comprehensive picture of the problem and the relevant code. Surface\nexisting patterns, constraints, and prior decisions.\n\nLaunch up to 3 Explore subagents IN PARALLEL (single message, multiple tool\ncalls). Use 1 agent for narrow, well-scoped problems; use more when the spec\ntouches several subsystems or you need to compare existing implementations.\nQuality over quantity \u2014 3 agents maximum.\n\nAfter exploration, draft a high-level design: the shape of the solution, new or\nchanged pieces, the boundaries.\n\n### Phase 2: Requirements\n\nTranslate the shape into concrete behavioral requirements. Each requirement\nmust be:\n\n- Testable \u2014 has a clear pass/fail condition.\n- Behavior-focused \u2014 describes what the system does, not how.\n- Scoped \u2014 covers one observable behavior.\n\nGroup requirements by capability. Plain English is fine. For conditional or\nstateful behaviors, EARS templates sharpen phrasing:\n`When <trigger>, the system shall <behavior>` or\n`If <condition>, then the system shall <response>`.\n\nFor larger / multi-component designs, walk the design end-to-end: at each step\nfrom trigger to final state, verify preconditions, state, failure handling, and\nhandoffs between components are specified. Skip this for small self-contained\nspecs.\n\n### Phase 3: Deepen\n\nRead the critical files identified during Phase 1. Reconcile requirements\nagainst the shape \u2014 if a requirement reveals a gap in the design, refine the\ndesign before saving.\n\nUse AskUserQuestion ONLY to clarify requirements or choose between approaches.\nNever use it to ask \"is this spec okay?\" or \"should I save?\".\n\n### Phase 4: Compose the spec body\n\nRequired sections:\n\n # Spec: <one-line title>\n\n ## Context\n <the problem this spec addresses, what motivates it, and the intended outcome.\n Include relevant constraints \u2014 user goals, stakeholders, deadlines.>\n\n ## Design\n <the shape of the solution. Components, data flow, key decisions and why they\n were chosen. Reference existing code with `file_path:line_number`.>\n\n ## Requirements\n <grouped behavioral requirements. Each one testable. Plain English is fine.>\n\n ### <Capability A>\n - <one observable behavior>\n\n ### <Capability B>\n - ...\n\n ## Out of scope\n <things explicitly NOT covered, so the next reader knows where the edges are.>\n\n ## Open questions\n <anything you could not resolve. Empty if all decisions are pinned.>\n\n### Phase 5: Save\n\nRun `crtr agent spec new`:\n\n echo '<spec markdown>' | crtr agent spec new <kebab-case-name>\n\n- NAME: short kebab-case slug. Nested names become subdirectories\n (e.g. `auth/refresh-tokens`).\n- Pipe the full spec markdown composed in Phase 4 on stdin.\n\nOutput: `{path, follow_up}`. The `follow_up` field names the exact next call\n\u2014 run it.\n\n### Phase 6: Done\n\nAfter the reviewer approves the spec, your turn ends. Do not summarize in chat.\nFor a human gate, optionally run `crtr human review` on the spec for anchored\ncomments and `crtr human approve` to gate the handoff \u2014 this complements, not\nreplaces, `crtr agent new reviewer`.\nIf the user is ready to plan, ask once whether to hand off; if yes, follow the\n`follow_up` instructions from the save output.";
2
- import type { BranchDef } from '../core/command.js';
3
- export declare function registerSpec(): BranchDef;
@@ -1,286 +0,0 @@
1
- // `crtr agent spec` subtree — spec new / show / list handlers.
2
- export const SPEC_NEW_GUIDE = `## Spec workflow
3
-
4
- Build and save a design + requirements spec: a document describing what to
5
- build, the shape of the solution, and the behaviors it must satisfy. A spec is
6
- upstream of a plan — it captures decisions, not implementation steps.
7
-
8
- Anti-pattern: do not fish for clarifications upfront. Draft a concrete spec
9
- first based on your investigation, then iterate. A specific draft the user can
10
- react to converges faster than a list of questions in a vacuum.
11
-
12
- ### Phase 1: Shape
13
-
14
- Build a comprehensive picture of the problem and the relevant code. Surface
15
- existing patterns, constraints, and prior decisions.
16
-
17
- Launch up to 3 Explore subagents IN PARALLEL (single message, multiple tool
18
- calls). Use 1 agent for narrow, well-scoped problems; use more when the spec
19
- touches several subsystems or you need to compare existing implementations.
20
- Quality over quantity — 3 agents maximum.
21
-
22
- After exploration, draft a high-level design: the shape of the solution, new or
23
- changed pieces, the boundaries.
24
-
25
- ### Phase 2: Requirements
26
-
27
- Translate the shape into concrete behavioral requirements. Each requirement
28
- must be:
29
-
30
- - Testable — has a clear pass/fail condition.
31
- - Behavior-focused — describes what the system does, not how.
32
- - Scoped — covers one observable behavior.
33
-
34
- Group requirements by capability. Plain English is fine. For conditional or
35
- stateful behaviors, EARS templates sharpen phrasing:
36
- \`When <trigger>, the system shall <behavior>\` or
37
- \`If <condition>, then the system shall <response>\`.
38
-
39
- For larger / multi-component designs, walk the design end-to-end: at each step
40
- from trigger to final state, verify preconditions, state, failure handling, and
41
- handoffs between components are specified. Skip this for small self-contained
42
- specs.
43
-
44
- ### Phase 3: Deepen
45
-
46
- Read the critical files identified during Phase 1. Reconcile requirements
47
- against the shape — if a requirement reveals a gap in the design, refine the
48
- design before saving.
49
-
50
- Use AskUserQuestion ONLY to clarify requirements or choose between approaches.
51
- Never use it to ask "is this spec okay?" or "should I save?".
52
-
53
- ### Phase 4: Compose the spec body
54
-
55
- Required sections:
56
-
57
- # Spec: <one-line title>
58
-
59
- ## Context
60
- <the problem this spec addresses, what motivates it, and the intended outcome.
61
- Include relevant constraints — user goals, stakeholders, deadlines.>
62
-
63
- ## Design
64
- <the shape of the solution. Components, data flow, key decisions and why they
65
- were chosen. Reference existing code with \`file_path:line_number\`.>
66
-
67
- ## Requirements
68
- <grouped behavioral requirements. Each one testable. Plain English is fine.>
69
-
70
- ### <Capability A>
71
- - <one observable behavior>
72
-
73
- ### <Capability B>
74
- - ...
75
-
76
- ## Out of scope
77
- <things explicitly NOT covered, so the next reader knows where the edges are.>
78
-
79
- ## Open questions
80
- <anything you could not resolve. Empty if all decisions are pinned.>
81
-
82
- ### Phase 5: Save
83
-
84
- Run \`crtr agent spec new\`:
85
-
86
- echo '<spec markdown>' | crtr agent spec new <kebab-case-name>
87
-
88
- - NAME: short kebab-case slug. Nested names become subdirectories
89
- (e.g. \`auth/refresh-tokens\`).
90
- - Pipe the full spec markdown composed in Phase 4 on stdin.
91
-
92
- Output: \`{path, follow_up}\`. The \`follow_up\` field names the exact next call
93
- — run it.
94
-
95
- ### Phase 6: Done
96
-
97
- After the reviewer approves the spec, your turn ends. Do not summarize in chat.
98
- For a human gate, optionally run \`crtr human review\` on the spec for anchored
99
- comments and \`crtr human approve\` to gate the handoff — this complements, not
100
- replaces, \`crtr agent new reviewer\`.
101
- If the user is ready to plan, ask once whether to hand off; if yes, follow the
102
- \`follow_up\` instructions from the save output.`;
103
- import { defineBranch, defineLeaf } from '../core/command.js';
104
- import { saveArtifact, readArtifact, listArtifacts, OVERSIZE_WARN_LINES } from '../core/artifact.js';
105
- import { paginate } from '../core/pagination.js';
106
- export function registerSpec() {
107
- const specNew = defineLeaf({
108
- name: 'new',
109
- help: {
110
- name: 'agent spec new',
111
- summary: 'draft a specification artifact from intent',
112
- guide: SPEC_NEW_GUIDE,
113
- params: [
114
- {
115
- kind: 'positional',
116
- name: 'name',
117
- type: 'string',
118
- required: true,
119
- constraint: 'Kebab-case slug used as the artifact filename. No spaces; use hyphens.',
120
- },
121
- {
122
- kind: 'stdin',
123
- name: 'body',
124
- required: true,
125
- constraint: 'Full specification prose. Treated as ground truth for downstream planning.',
126
- },
127
- ],
128
- output: [
129
- {
130
- name: 'path',
131
- type: 'string',
132
- required: true,
133
- constraint: 'Absolute path to the written spec artifact.',
134
- },
135
- {
136
- name: 'follow_up',
137
- type: 'string',
138
- required: true,
139
- constraint: 'Recommended next call (planner spawn via `crtr agent new planner`).',
140
- },
141
- ],
142
- outputKind: 'object',
143
- effects: ['Writes a spec artifact to the specs artifact directory.'],
144
- },
145
- run: async (input) => {
146
- const name = input['name'];
147
- const body = input['body'];
148
- const { path, oversize, lineCount } = saveArtifact('specs', name, body);
149
- let follow_up = `Plan it: crtr agent new planner ${path} (returns {job_id}), then crtr job read result <job_id> --wait.`;
150
- follow_up +=
151
- ` Optional human gate before planning (complements, does not replace \`crtr agent new reviewer\`): crtr human review --file ${path} for anchored comments, then gate with crtr human approve --title "Approve this spec?".`;
152
- if (oversize) {
153
- follow_up +=
154
- ` OVERSIZE ADVISORY: this spec is ${lineCount} lines (> ${OVERSIZE_WARN_LINES}). Split into focused sub-specs before planning.`;
155
- }
156
- return { path, follow_up };
157
- },
158
- });
159
- const specShow = defineLeaf({
160
- name: 'show',
161
- help: {
162
- name: 'agent spec show',
163
- summary: 'read a spec artifact by name',
164
- params: [
165
- {
166
- kind: 'positional',
167
- name: 'name',
168
- type: 'string',
169
- required: true,
170
- constraint: 'Exact artifact name (no path extension). Use `spec list` to enumerate.',
171
- },
172
- ],
173
- output: [
174
- {
175
- name: 'name',
176
- type: 'string',
177
- required: true,
178
- constraint: 'Artifact name as stored.',
179
- },
180
- {
181
- name: 'path',
182
- type: 'string',
183
- required: true,
184
- constraint: 'Absolute path to the artifact file.',
185
- },
186
- {
187
- name: 'body',
188
- type: 'string',
189
- required: true,
190
- constraint: 'Full spec body text.',
191
- },
192
- ],
193
- outputKind: 'object',
194
- effects: ['None. Read-only.'],
195
- },
196
- run: async (input) => {
197
- const name = input['name'];
198
- const record = readArtifact('specs', name);
199
- return { name: record.name, path: record.path, body: record.body };
200
- },
201
- });
202
- const specList = defineLeaf({
203
- name: 'list',
204
- help: {
205
- name: 'agent spec list',
206
- summary: 'paginated list of spec artifacts, sorted ascending by name',
207
- params: [
208
- {
209
- kind: 'flag',
210
- name: 'scope',
211
- type: 'enum',
212
- choices: ['user', 'project', 'all'],
213
- required: false,
214
- constraint: 'Filter by scope. Omit to list all.',
215
- },
216
- {
217
- kind: 'flag',
218
- name: 'limit',
219
- type: 'int',
220
- required: false,
221
- default: 20,
222
- constraint: 'Default 20, max 100.',
223
- },
224
- {
225
- kind: 'flag',
226
- name: 'cursor',
227
- type: 'string',
228
- required: false,
229
- constraint: "Opaque token from a previous response's next_cursor. Omit on first call.",
230
- },
231
- ],
232
- output: [
233
- {
234
- name: 'items',
235
- type: 'object[]',
236
- required: true,
237
- constraint: 'Each: {name, path, updated_at}. Sorted ascending by name.',
238
- },
239
- {
240
- name: 'next_cursor',
241
- type: 'string | null',
242
- required: true,
243
- constraint: 'Pass on the next call to continue. null means no more items.',
244
- },
245
- {
246
- name: 'total',
247
- type: 'integer | null',
248
- required: true,
249
- constraint: 'Total specs matching the query. Exact when cheap; null on large/filtered sets — do not retry to force it.',
250
- },
251
- ],
252
- outputKind: 'object',
253
- effects: ['None. Read-only.'],
254
- },
255
- run: async (input) => {
256
- const limit = input['limit'] ?? 20;
257
- const cursor = input['cursor'];
258
- const all = listArtifacts('specs');
259
- const result = paginate(all, { limit, cursor }, {
260
- defaultLimit: 20,
261
- maxLimit: 100,
262
- keyOf: (item) => item.name,
263
- total: 'count',
264
- });
265
- return {
266
- items: result.items,
267
- next_cursor: result.next_cursor,
268
- total: result.total,
269
- };
270
- },
271
- });
272
- return defineBranch({
273
- name: 'spec',
274
- help: {
275
- name: 'agent spec',
276
- summary: 'create and read specification artifacts',
277
- model: 'Lifecycle: draft -> approved. Approved specs drive plan creation.',
278
- children: [
279
- { name: 'new', desc: 'draft a spec from intent', useWhen: 'capturing requirements before planning' },
280
- { name: 'show', desc: 'read a spec by name', useWhen: 'reasoning about an existing spec' },
281
- { name: 'list', desc: 'enumerate specs', useWhen: 'discovering what specs exist' },
282
- ],
283
- },
284
- children: [specNew, specShow, specList],
285
- });
286
- }
@@ -1,248 +0,0 @@
1
- // Tests for flow subtree leaves (spec new/show/list, plan new/show/list, debug).
2
- // Exercises the argv parsing path for each leaf via parseArgv and verifies
3
- // help.params structure (not help.input).
4
- //
5
- // Run with: node --import tsx/esm --test src/core/__tests__/flow-leaves.test.ts
6
- import { test, describe } from 'node:test';
7
- import assert from 'node:assert/strict';
8
- import { parseArgv } from '../command.js';
9
- import { renderLeafArgv } from '../help.js';
10
- import { registerSpec } from '../../commands/spec.js';
11
- import { registerPlan } from '../../commands/plan.js';
12
- import { registerDebug } from '../../commands/debug.js';
13
- // ---------------------------------------------------------------------------
14
- // Helpers
15
- // ---------------------------------------------------------------------------
16
- function getLeaf(branch, name) {
17
- const leaf = branch.children.find((c) => c.name === name);
18
- assert.ok(leaf !== undefined, `leaf '${name}' not found in branch`);
19
- assert.equal(leaf.kind, 'leaf');
20
- return leaf;
21
- }
22
- // ---------------------------------------------------------------------------
23
- // spec new
24
- // ---------------------------------------------------------------------------
25
- describe('spec new: argv model', () => {
26
- const specBranch = registerSpec();
27
- const leaf = getLeaf(specBranch, 'new');
28
- test('help.params defined', () => {
29
- assert.ok(leaf.help.params !== undefined);
30
- });
31
- test('has positional name param', () => {
32
- const pos = leaf.help.params.find((p) => p.kind === 'positional' && p.name === 'name');
33
- assert.ok(pos !== undefined);
34
- assert.equal(pos.required, true);
35
- });
36
- test('has stdin body param', () => {
37
- const stdin = leaf.help.params.find((p) => p.kind === 'stdin' && p.name === 'body');
38
- assert.ok(stdin !== undefined);
39
- assert.equal(stdin.required, true);
40
- });
41
- test('parseArgv: positional name parsed correctly', async () => {
42
- const params = leaf.help.params;
43
- // Remove stdin param for parse-only test (stdin reads from process.stdin)
44
- const noStdin = params.filter((p) => p.kind !== 'stdin');
45
- const result = await parseArgv(noStdin, ['my-spec-name']);
46
- assert.equal(result['name'], 'my-spec-name');
47
- });
48
- test('parseArgv: missing required positional throws', async () => {
49
- const params = leaf.help.params.filter((p) => p.kind !== 'stdin');
50
- await assert.rejects(() => parseArgv(params, []), (err) => { assert.match(err.message, /required parameter is missing/); return true; });
51
- });
52
- test('renderLeafArgv renders Input section with positional', () => {
53
- const out = renderLeafArgv(leaf.help);
54
- assert.ok(out.includes('Input'));
55
- assert.ok(out.includes('NAME'));
56
- assert.ok(out.includes('stdin'));
57
- });
58
- });
59
- // ---------------------------------------------------------------------------
60
- // spec show
61
- // ---------------------------------------------------------------------------
62
- describe('spec show: argv model', () => {
63
- const specBranch = registerSpec();
64
- const leaf = getLeaf(specBranch, 'show');
65
- test('help.params defined', () => {
66
- assert.ok(leaf.help.params !== undefined);
67
- });
68
- test('parseArgv: positional name', async () => {
69
- const result = await parseArgv(leaf.help.params, ['my-spec']);
70
- assert.equal(result['name'], 'my-spec');
71
- });
72
- test('parseArgv: rejects unknown flag', async () => {
73
- await assert.rejects(() => parseArgv(leaf.help.params, ['my-spec', '--bogus']), (err) => { assert.match(err.message, /unknown flag/); return true; });
74
- });
75
- });
76
- // ---------------------------------------------------------------------------
77
- // spec list
78
- // ---------------------------------------------------------------------------
79
- describe('spec list: argv model', () => {
80
- const specBranch = registerSpec();
81
- const leaf = getLeaf(specBranch, 'list');
82
- test('help.params defined', () => {
83
- assert.ok(leaf.help.params !== undefined);
84
- });
85
- test('has --scope enum flag', () => {
86
- const flag = leaf.help.params.find((p) => p.kind === 'flag' && p.name === 'scope');
87
- assert.ok(flag !== undefined);
88
- assert.equal(flag.kind, 'flag');
89
- if (flag.kind === 'flag') {
90
- assert.equal(flag.type, 'enum');
91
- assert.deepEqual(flag.choices, ['user', 'project', 'all']);
92
- }
93
- });
94
- test('has --limit int flag with default 20', () => {
95
- const flag = leaf.help.params.find((p) => p.kind === 'flag' && p.name === 'limit');
96
- assert.ok(flag !== undefined);
97
- assert.equal(flag.kind, 'flag');
98
- if (flag.kind === 'flag') {
99
- assert.equal(flag.type, 'int');
100
- assert.equal(flag.default, 20);
101
- }
102
- });
103
- test('has --cursor string flag', () => {
104
- const flag = leaf.help.params.find((p) => p.kind === 'flag' && p.name === 'cursor');
105
- assert.ok(flag !== undefined);
106
- });
107
- test('parseArgv: --limit 50 parses as integer', async () => {
108
- const result = await parseArgv(leaf.help.params, ['--limit', '50']);
109
- assert.equal(result['limit'], 50);
110
- });
111
- test('parseArgv: --scope user parses', async () => {
112
- const result = await parseArgv(leaf.help.params, ['--scope', 'user']);
113
- assert.equal(result['scope'], 'user');
114
- });
115
- test('parseArgv: --scope invalid throws', async () => {
116
- await assert.rejects(() => parseArgv(leaf.help.params, ['--scope', 'invalid']), (err) => { assert.match(err.message, /must be one of/); return true; });
117
- });
118
- test('parseArgv: default limit applied when absent', async () => {
119
- const result = await parseArgv(leaf.help.params, []);
120
- assert.equal(result['limit'], 20);
121
- });
122
- test('parseArgv: --cursor token', async () => {
123
- const result = await parseArgv(leaf.help.params, ['--cursor', 'tok123']);
124
- assert.equal(result['cursor'], 'tok123');
125
- });
126
- });
127
- // ---------------------------------------------------------------------------
128
- // plan new
129
- // ---------------------------------------------------------------------------
130
- describe('plan new: argv model', () => {
131
- const planBranch = registerPlan();
132
- const leaf = getLeaf(planBranch, 'new');
133
- test('help.params defined', () => {
134
- assert.ok(leaf.help.params !== undefined);
135
- });
136
- test('has positional name param', () => {
137
- const pos = leaf.help.params.find((p) => p.kind === 'positional' && p.name === 'name');
138
- assert.ok(pos !== undefined);
139
- assert.equal(pos.required, true);
140
- });
141
- test('has stdin body param', () => {
142
- const stdin = leaf.help.params.find((p) => p.kind === 'stdin' && p.name === 'body');
143
- assert.ok(stdin !== undefined);
144
- assert.equal(stdin.required, true);
145
- });
146
- test('has optional --spec flag', () => {
147
- const flag = leaf.help.params.find((p) => p.kind === 'flag' && p.name === 'spec');
148
- assert.ok(flag !== undefined);
149
- assert.equal(flag.required, false);
150
- });
151
- test('parseArgv: positional name and --spec flag', async () => {
152
- const params = leaf.help.params.filter((p) => p.kind !== 'stdin');
153
- const result = await parseArgv(params, ['my-plan', '--spec', 'my-spec']);
154
- assert.equal(result['name'], 'my-plan');
155
- assert.equal(result['spec'], 'my-spec');
156
- });
157
- test('parseArgv: positional name without --spec', async () => {
158
- const params = leaf.help.params.filter((p) => p.kind !== 'stdin');
159
- const result = await parseArgv(params, ['my-plan']);
160
- assert.equal(result['name'], 'my-plan');
161
- assert.equal(result['spec'], undefined);
162
- });
163
- });
164
- // ---------------------------------------------------------------------------
165
- // plan show
166
- // ---------------------------------------------------------------------------
167
- describe('plan show: argv model', () => {
168
- const planBranch = registerPlan();
169
- const leaf = getLeaf(planBranch, 'show');
170
- test('help.params defined', () => {
171
- assert.ok(leaf.help.params !== undefined);
172
- });
173
- test('parseArgv: positional name', async () => {
174
- const result = await parseArgv(leaf.help.params, ['my-plan']);
175
- assert.equal(result['name'], 'my-plan');
176
- });
177
- });
178
- // ---------------------------------------------------------------------------
179
- // plan list
180
- // ---------------------------------------------------------------------------
181
- describe('plan list: argv model', () => {
182
- const planBranch = registerPlan();
183
- const leaf = getLeaf(planBranch, 'list');
184
- test('help.params defined', () => {
185
- assert.ok(leaf.help.params !== undefined);
186
- });
187
- test('has --scope, --limit, --cursor flags', () => {
188
- const names = leaf.help.params.map((p) => p.name);
189
- assert.ok(names.includes('scope'));
190
- assert.ok(names.includes('limit'));
191
- assert.ok(names.includes('cursor'));
192
- });
193
- test('parseArgv: --limit 10 --cursor abc', async () => {
194
- const result = await parseArgv(leaf.help.params, ['--limit', '10', '--cursor', 'abc']);
195
- assert.equal(result['limit'], 10);
196
- assert.equal(result['cursor'], 'abc');
197
- });
198
- });
199
- // ---------------------------------------------------------------------------
200
- // debug
201
- // ---------------------------------------------------------------------------
202
- describe('debug: argv model', () => {
203
- const leaf = registerDebug();
204
- test('help.params defined', () => {
205
- assert.ok(leaf.help.params !== undefined);
206
- });
207
- test('has stdin steps_to_reproduce param', () => {
208
- const stdin = leaf.help.params.find((p) => p.kind === 'stdin' && p.name === 'steps_to_reproduce');
209
- assert.ok(stdin !== undefined);
210
- assert.equal(stdin.required, true);
211
- });
212
- test('has required --summary flag', () => {
213
- const flag = leaf.help.params.find((p) => p.kind === 'flag' && p.name === 'summary');
214
- assert.ok(flag !== undefined);
215
- assert.equal(flag.required, true);
216
- if (flag.kind === 'flag')
217
- assert.equal(flag.type, 'string');
218
- });
219
- test('has optional --cwd flag of type path', () => {
220
- const flag = leaf.help.params.find((p) => p.kind === 'flag' && p.name === 'cwd');
221
- assert.ok(flag !== undefined);
222
- assert.equal(flag.required, false);
223
- if (flag.kind === 'flag')
224
- assert.equal(flag.type, 'path');
225
- });
226
- test('parseArgv: --summary and --cwd flags (no stdin)', async () => {
227
- const params = leaf.help.params.filter((p) => p.kind !== 'stdin');
228
- const result = await parseArgv(params, ['--summary', 'test fails on startup', '--cwd', '/tmp/project']);
229
- assert.equal(result['summary'], 'test fails on startup');
230
- assert.equal(result['cwd'], '/tmp/project');
231
- });
232
- test('parseArgv: missing required --summary throws', async () => {
233
- const params = leaf.help.params.filter((p) => p.kind !== 'stdin');
234
- await assert.rejects(() => parseArgv(params, []), (err) => { assert.match(err.message, /required parameter is missing/); return true; });
235
- });
236
- test('renderLeafArgv renders --summary and stdin', () => {
237
- const out = renderLeafArgv(leaf.help);
238
- assert.ok(out.includes('--summary'));
239
- assert.ok(out.includes('stdin'));
240
- assert.ok(out.includes('--cwd'));
241
- });
242
- test('stdin name is steps_to_reproduce (underscores, no camelCase transform)', () => {
243
- // flagNameToKey only converts hyphen segments; underscores are passed through.
244
- // The handler reads input['steps_to_reproduce'], not input['stepsToReproduce'].
245
- const stdin = leaf.help.params.find((p) => p.kind === 'stdin');
246
- assert.equal(stdin?.name, 'steps_to_reproduce');
247
- });
248
- });