@vibe-agent-toolkit/cli 0.2.0-rc.2 → 0.2.0-rc.4

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 (211) hide show
  1. package/dist/bin/vat +68 -16
  2. package/dist/bin/vat.js +68 -16
  3. package/dist/bin/vat.js.map +1 -1
  4. package/dist/bin.js +157 -37
  5. package/dist/bin.js.map +1 -1
  6. package/dist/command-loaders.d.ts +44 -0
  7. package/dist/command-loaders.d.ts.map +1 -0
  8. package/dist/command-loaders.js +58 -0
  9. package/dist/command-loaders.js.map +1 -0
  10. package/dist/commands/agent/index.js +1 -1
  11. package/dist/commands/agent/install.d.ts.map +1 -1
  12. package/dist/commands/agent/install.js +46 -5
  13. package/dist/commands/agent/install.js.map +1 -1
  14. package/dist/commands/audit/distributed-tree.d.ts +2 -2
  15. package/dist/commands/audit/distributed-tree.d.ts.map +1 -1
  16. package/dist/commands/audit/distributed-tree.js +2 -1
  17. package/dist/commands/audit/distributed-tree.js.map +1 -1
  18. package/dist/commands/audit/git-url-clone.d.ts +1 -1
  19. package/dist/commands/audit/git-url-clone.d.ts.map +1 -1
  20. package/dist/commands/audit/git-url-clone.js.map +1 -1
  21. package/dist/commands/audit/hierarchical-output.d.ts +1 -1
  22. package/dist/commands/audit/hierarchical-output.d.ts.map +1 -1
  23. package/dist/commands/audit/hierarchical-output.js +1 -1
  24. package/dist/commands/audit/hierarchical-output.js.map +1 -1
  25. package/dist/commands/audit.d.ts +22 -1
  26. package/dist/commands/audit.d.ts.map +1 -1
  27. package/dist/commands/audit.js +224 -24
  28. package/dist/commands/audit.js.map +1 -1
  29. package/dist/commands/build.d.ts +1 -1
  30. package/dist/commands/build.d.ts.map +1 -1
  31. package/dist/commands/build.js +15 -12
  32. package/dist/commands/build.js.map +1 -1
  33. package/dist/commands/cache/cache-control.d.ts +82 -0
  34. package/dist/commands/cache/cache-control.d.ts.map +1 -0
  35. package/dist/commands/cache/cache-control.js +86 -0
  36. package/dist/commands/cache/cache-control.js.map +1 -0
  37. package/dist/commands/cache/clear.d.ts +17 -3
  38. package/dist/commands/cache/clear.d.ts.map +1 -1
  39. package/dist/commands/cache/clear.js +68 -3
  40. package/dist/commands/cache/clear.js.map +1 -1
  41. package/dist/commands/cache/index.d.ts +13 -63
  42. package/dist/commands/cache/index.d.ts.map +1 -1
  43. package/dist/commands/cache/index.js +38 -79
  44. package/dist/commands/cache/index.js.map +1 -1
  45. package/dist/commands/claude/budget.d.ts +157 -0
  46. package/dist/commands/claude/budget.d.ts.map +1 -0
  47. package/dist/commands/claude/budget.js +412 -0
  48. package/dist/commands/claude/budget.js.map +1 -0
  49. package/dist/commands/claude/context.d.ts +340 -0
  50. package/dist/commands/claude/context.d.ts.map +1 -0
  51. package/dist/commands/claude/context.js +1079 -0
  52. package/dist/commands/claude/context.js.map +1 -0
  53. package/dist/commands/claude/index.d.ts +13 -0
  54. package/dist/commands/claude/index.d.ts.map +1 -1
  55. package/dist/commands/claude/index.js +24 -2
  56. package/dist/commands/claude/index.js.map +1 -1
  57. package/dist/commands/claude/marketplace/git-publish.d.ts.map +1 -1
  58. package/dist/commands/claude/marketplace/git-publish.js +18 -19
  59. package/dist/commands/claude/marketplace/git-publish.js.map +1 -1
  60. package/dist/commands/claude/marketplace/validate.d.ts +19 -1
  61. package/dist/commands/claude/marketplace/validate.d.ts.map +1 -1
  62. package/dist/commands/claude/marketplace/validate.js +41 -21
  63. package/dist/commands/claude/marketplace/validate.js.map +1 -1
  64. package/dist/commands/claude/plugin/build.d.ts +18 -2
  65. package/dist/commands/claude/plugin/build.d.ts.map +1 -1
  66. package/dist/commands/claude/plugin/build.js +55 -18
  67. package/dist/commands/claude/plugin/build.js.map +1 -1
  68. package/dist/commands/claude/plugin/helpers.d.ts.map +1 -1
  69. package/dist/commands/claude/plugin/helpers.js +2 -1
  70. package/dist/commands/claude/plugin/helpers.js.map +1 -1
  71. package/dist/commands/claude/plugin/install.d.ts.map +1 -1
  72. package/dist/commands/claude/plugin/install.js +24 -3
  73. package/dist/commands/claude/plugin/install.js.map +1 -1
  74. package/dist/commands/claude/plugin/tree-copy.d.ts.map +1 -1
  75. package/dist/commands/claude/plugin/tree-copy.js +2 -1
  76. package/dist/commands/claude/plugin/tree-copy.js.map +1 -1
  77. package/dist/commands/consistency-check.d.ts.map +1 -1
  78. package/dist/commands/consistency-check.js +4 -3
  79. package/dist/commands/consistency-check.js.map +1 -1
  80. package/dist/commands/corpus/report.d.ts +1 -1
  81. package/dist/commands/corpus/report.d.ts.map +1 -1
  82. package/dist/commands/corpus/runner.d.ts.map +1 -1
  83. package/dist/commands/corpus/runner.js +3 -2
  84. package/dist/commands/corpus/runner.js.map +1 -1
  85. package/dist/commands/corpus/scan.d.ts.map +1 -1
  86. package/dist/commands/corpus/scan.js +18 -8
  87. package/dist/commands/corpus/scan.js.map +1 -1
  88. package/dist/commands/doctor.d.ts +36 -0
  89. package/dist/commands/doctor.d.ts.map +1 -1
  90. package/dist/commands/doctor.js +99 -2
  91. package/dist/commands/doctor.js.map +1 -1
  92. package/dist/commands/inventory.d.ts +13 -1
  93. package/dist/commands/inventory.d.ts.map +1 -1
  94. package/dist/commands/inventory.js +118 -13
  95. package/dist/commands/inventory.js.map +1 -1
  96. package/dist/commands/mcp/collections.d.ts +1 -1
  97. package/dist/commands/mcp/collections.d.ts.map +1 -1
  98. package/dist/commands/phase-utils.d.ts +155 -104
  99. package/dist/commands/phase-utils.d.ts.map +1 -1
  100. package/dist/commands/phase-utils.js +109 -155
  101. package/dist/commands/phase-utils.js.map +1 -1
  102. package/dist/commands/rag/index-command.d.ts +39 -0
  103. package/dist/commands/rag/index-command.d.ts.map +1 -1
  104. package/dist/commands/rag/index-command.js +28 -2
  105. package/dist/commands/rag/index-command.js.map +1 -1
  106. package/dist/commands/rag/index.d.ts.map +1 -1
  107. package/dist/commands/rag/index.js +21 -10
  108. package/dist/commands/rag/index.js.map +1 -1
  109. package/dist/commands/resources/index.d.ts.map +1 -1
  110. package/dist/commands/resources/index.js +10 -2
  111. package/dist/commands/resources/index.js.map +1 -1
  112. package/dist/commands/resources/scan.d.ts +24 -0
  113. package/dist/commands/resources/scan.d.ts.map +1 -1
  114. package/dist/commands/resources/scan.js +19 -6
  115. package/dist/commands/resources/scan.js.map +1 -1
  116. package/dist/commands/resources/validate.d.ts +12 -1
  117. package/dist/commands/resources/validate.d.ts.map +1 -1
  118. package/dist/commands/resources/validate.js +102 -51
  119. package/dist/commands/resources/validate.js.map +1 -1
  120. package/dist/commands/skill/review-checklist.d.ts.map +1 -1
  121. package/dist/commands/skill/review-checklist.js +1 -0
  122. package/dist/commands/skill/review-checklist.js.map +1 -1
  123. package/dist/commands/skill/review.js +2 -2
  124. package/dist/commands/skill/review.js.map +1 -1
  125. package/dist/commands/skill/test/configure.d.ts +19 -0
  126. package/dist/commands/skill/test/configure.d.ts.map +1 -1
  127. package/dist/commands/skill/test/configure.js +18 -3
  128. package/dist/commands/skill/test/configure.js.map +1 -1
  129. package/dist/commands/skill/test/run.d.ts +51 -4
  130. package/dist/commands/skill/test/run.d.ts.map +1 -1
  131. package/dist/commands/skill/test/run.js +123 -12
  132. package/dist/commands/skill/test/run.js.map +1 -1
  133. package/dist/commands/skills/build.d.ts +11 -1
  134. package/dist/commands/skills/build.d.ts.map +1 -1
  135. package/dist/commands/skills/build.js +154 -61
  136. package/dist/commands/skills/build.js.map +1 -1
  137. package/dist/commands/skills/package.d.ts +1 -1
  138. package/dist/commands/skills/package.d.ts.map +1 -1
  139. package/dist/commands/skills/package.js.map +1 -1
  140. package/dist/commands/skills/skill-discovery.d.ts.map +1 -1
  141. package/dist/commands/skills/skill-discovery.js +2 -1
  142. package/dist/commands/skills/skill-discovery.js.map +1 -1
  143. package/dist/commands/skills/validate.d.ts +79 -2
  144. package/dist/commands/skills/validate.d.ts.map +1 -1
  145. package/dist/commands/skills/validate.js +101 -48
  146. package/dist/commands/skills/validate.js.map +1 -1
  147. package/dist/commands/validate.d.ts.map +1 -1
  148. package/dist/commands/validate.js +26 -16
  149. package/dist/commands/validate.js.map +1 -1
  150. package/dist/commands/verify.d.ts +11 -10
  151. package/dist/commands/verify.d.ts.map +1 -1
  152. package/dist/commands/verify.js +49 -38
  153. package/dist/commands/verify.js.map +1 -1
  154. package/dist/utils/command-error.d.ts +33 -2
  155. package/dist/utils/command-error.d.ts.map +1 -1
  156. package/dist/utils/command-error.js +34 -10
  157. package/dist/utils/command-error.js.map +1 -1
  158. package/dist/utils/config-loader.d.ts.map +1 -1
  159. package/dist/utils/config-loader.js +7 -1
  160. package/dist/utils/config-loader.js.map +1 -1
  161. package/dist/utils/context-budget-issues.d.ts +108 -0
  162. package/dist/utils/context-budget-issues.d.ts.map +1 -0
  163. package/dist/utils/context-budget-issues.js +280 -0
  164. package/dist/utils/context-budget-issues.js.map +1 -0
  165. package/dist/utils/corpus-target.d.ts +48 -0
  166. package/dist/utils/corpus-target.d.ts.map +1 -0
  167. package/dist/utils/corpus-target.js +61 -0
  168. package/dist/utils/corpus-target.js.map +1 -0
  169. package/dist/utils/issue-anchor.d.ts +2 -2
  170. package/dist/utils/issue-anchor.d.ts.map +1 -1
  171. package/dist/utils/issue-anchor.js +1 -1
  172. package/dist/utils/issue-rendering.d.ts +1 -1
  173. package/dist/utils/issue-rendering.d.ts.map +1 -1
  174. package/dist/utils/issue-rendering.js +1 -1
  175. package/dist/utils/issue-rendering.js.map +1 -1
  176. package/dist/utils/issue-severity.d.ts +1 -1
  177. package/dist/utils/issue-severity.d.ts.map +1 -1
  178. package/dist/utils/issue-severity.js +1 -1
  179. package/dist/utils/issue-severity.js.map +1 -1
  180. package/dist/utils/optional-backend.d.ts +77 -0
  181. package/dist/utils/optional-backend.d.ts.map +1 -0
  182. package/dist/utils/optional-backend.js +115 -0
  183. package/dist/utils/optional-backend.js.map +1 -0
  184. package/dist/utils/output.d.ts +17 -0
  185. package/dist/utils/output.d.ts.map +1 -1
  186. package/dist/utils/output.js +19 -0
  187. package/dist/utils/output.js.map +1 -1
  188. package/dist/utils/population-wiring.d.ts +100 -0
  189. package/dist/utils/population-wiring.d.ts.map +1 -0
  190. package/dist/utils/population-wiring.js +98 -0
  191. package/dist/utils/population-wiring.js.map +1 -0
  192. package/dist/utils/projection-store.d.ts +188 -0
  193. package/dist/utils/projection-store.d.ts.map +1 -0
  194. package/dist/utils/projection-store.js +257 -0
  195. package/dist/utils/projection-store.js.map +1 -0
  196. package/dist/utils/resource-loader.d.ts +128 -2
  197. package/dist/utils/resource-loader.d.ts.map +1 -1
  198. package/dist/utils/resource-loader.js +234 -7
  199. package/dist/utils/resource-loader.js.map +1 -1
  200. package/dist/utils/verdict-helpers.d.ts +1 -1
  201. package/dist/utils/verdict-helpers.d.ts.map +1 -1
  202. package/dist/utils/verdict-helpers.js +1 -1
  203. package/dist/utils/verdict-helpers.js.map +1 -1
  204. package/docs/agent.md +2 -2
  205. package/docs/mcp.md +2 -2
  206. package/docs/resources.md +8 -1
  207. package/package.json +15 -12
  208. package/dist/commands/resources/command-helpers.d.ts +0 -5
  209. package/dist/commands/resources/command-helpers.d.ts.map +0 -1
  210. package/dist/commands/resources/command-helpers.js +0 -6
  211. package/dist/commands/resources/command-helpers.js.map +0 -1
@@ -1,10 +1,7 @@
1
1
  /**
2
2
  * Shared utilities for top-level phase orchestration commands (vat build, vat verify, vat validate).
3
3
  */
4
- import { spawnSync } from 'node:child_process';
5
- import { safePath } from '@vibe-agent-toolkit/utils';
6
4
  import { Option } from 'commander';
7
- import * as YAML from 'yaml';
8
5
  import { createLogger } from '../utils/logger.js';
9
6
  import { writeYamlOutput } from '../utils/output.js';
10
7
  /**
@@ -55,61 +52,47 @@ export function rejectRetiredOnly(only, command, seconds) {
55
52
  }
56
53
  /** The phase outcome for "we did not learn what this phase would have said". */
57
54
  export const SYSTEM_ERROR = 'system-error';
58
- /**
59
- * Resolve the absolute path to the vat binary.
60
- * This file lives in commands/, one level above bin/.
61
- */
62
- export function resolveBinPath() {
63
- // Use bin.js directly (not the vat.js wrapper) so phase subprocesses always
64
- // run the same binary that is currently executing, regardless of cwd or
65
- // context detection (which would pick up the adopter project's local install).
66
- return safePath.resolve(safePath.join(import.meta.dirname, '../bin.js'));
67
- }
68
55
  /**
69
56
  * Create the shared phase command context: logger, startTime, and bin path.
70
57
  *
71
- * It used to THROW when the phase list came out empty — and it was called
72
- * before the command's try block, so an unroutable `--only` reached the user as
73
- * a raw Node stack trace with zero bytes of stdout and an exit 1 that looked
74
- * like "validation errors". `--only` routing is decided by
75
- * {@link decidePhaseSelection} and reported by {@link applyPhaseSelection} now,
76
- * which emit the command's normal structured document.
58
+ * Total by design: it builds the context and decides nothing.
59
+ *
60
+ * ⚠️ This runs BEFORE the command's try block, so anything that throws here
61
+ * reaches the user as a raw Node stack trace with zero bytes of stdout and an
62
+ * exit 1 indistinguishable from "validation errors". Phase routing therefore
63
+ * belongs to {@link decidePhaseSelection} and {@link applyPhaseSelection}, which
64
+ * emit the command's normal structured document.
77
65
  */
78
66
  export function createPhaseContext(debugFlag) {
79
67
  return {
80
68
  logger: createLogger(debugFlag ? { debug: true } : {}),
81
69
  startTime: Date.now(),
82
- binPath: resolveBinPath(),
83
70
  };
84
71
  }
85
72
  /**
86
73
  * Decide what an orchestrator should do with its `--only` value and the phase
87
74
  * list its config produced.
88
75
  *
89
- * Shared by all three orchestrators because they used to disagree: `vat verify`
90
- * built its phase list without consulting the config at all, so `vat verify
91
- * --only skills` in a project with no `skills:` block exited 0 while `vat
92
- * validate --only skills` on the same project exited 1 — opposite verdicts on
93
- * the same question. (`vat verify` has since retired `--only` entirely and now
94
- * always passes `only: undefined`; `vat validate` and `vat build` still route
95
- * their own `--only` through here.)
76
+ * THE single decision site for all three orchestrators, so they cannot answer
77
+ * the same question differently. An orchestrator that builds its phase list
78
+ * without consulting the config exits 0 on `--only skills` in a project with no
79
+ * `skills:` block while another exits 1 — opposite verdicts on one question.
80
+ * `vat verify` has retired `--only` and always passes `only: undefined`;
81
+ * `vat validate` and `vat build` route their own `--only` through here.
96
82
  *
97
- * There used to be a third option, `emptyIsValid`, which existed solely so
98
- * `vat verify --only consistency` could run with an empty SUBPROCESS list
99
- * (consistency runs in-process). It was checked BEFORE `unreadableConfig`, so
100
- * `vat verify --only consistency` against an unparseable config answered the
101
- * confidently-wrong "no skills: block" instead of reporting the config error.
102
- * `--only` is gone from verify, `emptyIsValid` went with it, and that ordering
103
- * hazard cannot recur: nothing short-circuits ahead of the config-error arm.
83
+ * ⚠️ **Nothing may short-circuit ahead of the config-error arm.** A check
84
+ * evaluated before `unreadableConfig` answers a confident "not configured" for a
85
+ * tree whose config could not be parsed — which is the one answer this function
86
+ * must never give, because it is indistinguishable from a correct one.
104
87
  *
105
88
  * @param unreadableConfig - The config-load error, when the config exists but
106
89
  * could not be parsed. A broken config is NOT "the phase is unconfigured":
107
90
  * we do not know what it declares, so we must not answer with a confident
108
91
  * "not configured". Only `vat verify` passes it, and only defensively — its
109
- * phase builder pushes every subprocess phase when the config is unreadable
110
- * (so the CHILD reports the real error), which makes the list non-empty and
111
- * this arm unreachable by construction today. It is kept because the arm that
112
- * would otherwise catch an empty list is the "not configured" lie.
92
+ * phase builder pushes every configured phase when the config is unreadable
93
+ * (so the phase itself reports the real error), which makes the list non-empty
94
+ * and this arm unreachable by construction today. It is kept because the arm
95
+ * that would otherwise catch an empty list is the "not configured" lie.
113
96
  */
114
97
  export function decidePhaseSelection(only, phases, vocab, options = {}) {
115
98
  const lower = vocab.noun.toLowerCase();
@@ -139,9 +122,9 @@ export function decidePhaseSelection(only, phases, vocab, options = {}) {
139
122
  * Act on a {@link PhaseSelection}: return the phases to run, or emit the
140
123
  * command's normal structured document and exit.
141
124
  *
142
- * Both terminal arms go through `writeYamlOutput` deliberately. A `--only`
143
- * failure used to be an uncaught throw, so the one output a scripted caller
144
- * parses — the YAML document on stdout — was never written at all.
125
+ * Both terminal arms go through `writeYamlOutput` deliberately: the YAML
126
+ * document on stdout is the one output a scripted caller parses, so a routing
127
+ * failure has to publish one rather than throw past it.
145
128
  */
146
129
  export function applyPhaseSelection(selection, logger, startTime) {
147
130
  if (selection.kind === 'run') {
@@ -172,46 +155,9 @@ const PHASE_STATUS_ORDER = ['success', 'warning', 'error', 'system-error'];
172
155
  export function worseOf(a, b) {
173
156
  return PHASE_STATUS_ORDER.indexOf(b) > PHASE_STATUS_ORDER.indexOf(a) ? b : a;
174
157
  }
175
- /** Every value a child may legitimately report as its own `status`. */
158
+ /** Every value a phase may legitimately report as its own `status`. */
176
159
  const REPORTABLE_STATUSES = new Set(PHASE_STATUS_ORDER);
177
- /**
178
- * Parse the child's captured stdout into its reported document.
179
- *
180
- * Takes the LAST non-empty document in the stream: every orchestrated child
181
- * writes its summary last, and a child that happens to emit more than one
182
- * document must not make the summary unreadable.
183
- *
184
- * Empty stdout is NOT a failure — `vat skills validate` legitimately exits 0
185
- * printing nothing when there is no `skills:` block. Stdout that exists but
186
- * cannot be parsed IS a failure: the child crashed mid-answer, and the phase
187
- * must degrade to `system-error` rather than throw an unhandled exception out
188
- * of the orchestrator.
189
- */
190
- function parseChildReport(name, stdout) {
191
- if (stdout === undefined || stdout === null || stdout.trim() === '') {
192
- return {};
193
- }
194
- let documents;
195
- try {
196
- documents = YAML.parseAllDocuments(stdout);
197
- }
198
- catch (error) {
199
- return { parseError: unparseableMessage(name, error) };
200
- }
201
- const last = documents.findLast((doc) => doc.contents !== null);
202
- if (last === undefined) {
203
- return {};
204
- }
205
- if (last.errors.length > 0) {
206
- return { parseError: unparseableMessage(name, last.errors[0]) };
207
- }
208
- return { report: last.toJS() };
209
- }
210
- function unparseableMessage(name, cause) {
211
- const detail = cause instanceof Error ? cause.message : String(cause);
212
- return `Phase '${name}' wrote unparseable output on stdout: ${detail}`;
213
- }
214
- /** The status an exit code alone implies, before the child's report is read. */
160
+ /** The status an exit code alone implies, before the phase's report is read. */
215
161
  function statusFromExitCode(status) {
216
162
  if (status === 0)
217
163
  return 'success';
@@ -219,7 +165,7 @@ function statusFromExitCode(status) {
219
165
  return 'error';
220
166
  return SYSTEM_ERROR;
221
167
  }
222
- /** The status the child claimed for itself, when it claimed a recognized one. */
168
+ /** The status the phase claimed for itself, when it claimed a recognized one. */
223
169
  function statusFromReport(report) {
224
170
  if (typeof report !== 'object' || report === null)
225
171
  return undefined;
@@ -229,49 +175,30 @@ function statusFromReport(report) {
229
175
  : undefined;
230
176
  }
231
177
  /**
232
- * Map a spawn outcome to a phase outcome. The pure core of {@link runPhase}.
178
+ * Map what a phase produced to its outcome. The pure core of {@link runPhase}.
233
179
  *
234
- * Every branch that is NOT "the child ran and told us what it found" is a
235
- * system error, because the orchestrator learned nothing about the artifact:
180
+ * | exit code | phase status | why |
181
+ * |-----------------------|----------------|-----------------------------------------|
182
+ * | 0 | `success` | ran, found nothing actionable |
183
+ * | 1 | `error` | ran, found validation errors |
184
+ * | 2 (or any other) | `system-error` | the phase itself reported a system error |
236
185
  *
237
- * | spawn outcome | phase status | why |
238
- * |--------------------------|----------------|--------------------------------------------|
239
- * | `error` set | `system-error` | the child never ran |
240
- * | killed by a signal | `system-error` | the child was cut off mid-answer |
241
- * | no exit code, no signal | `system-error` | there is no answer to read |
242
- * | stdout not parseable | `system-error` | the child's answer cannot be read |
243
- * | exit 0 | `success` | ran, found nothing actionable |
244
- * | exit 1 | `error` | ran, found validation errors |
245
- * | exit 2 (or any other) | `system-error` | the child itself reported a system error |
186
+ * The exit code is then reconciled with the phase's OWN reported `status`,
187
+ * worst-wins. An exit code has three values and cannot express `warning`:
188
+ * `vat skills validate` exits 0 while reporting `status: warning`, so its exit
189
+ * code alone reads as `success` — including on the tree VAT's CI dogfoods on
190
+ * VAT itself.
246
191
  *
247
- * The exit code is then reconciled with the child's OWN reported `status`,
248
- * worst-wins. An exit code has three values and cannot express `warning`, so
249
- * `vat skills validate` — which exits 0 while reporting `status: warning` —
250
- * was being recorded as `success` by every orchestrator, including the one
251
- * VAT's CI dogfoods on VAT itself.
192
+ * The table has no row for a signal kill, a missing status code, or a document
193
+ * that fails to parse, and that is the design rather than an omission. A phase
194
+ * runs in this process: there is no serialization step in which to lose a
195
+ * document, and no signal that could take a phase without taking the
196
+ * orchestrator with it.
252
197
  */
253
- export function phaseResultFromSpawn(name, outcome) {
254
- if (outcome.error !== undefined) {
255
- return { name, status: SYSTEM_ERROR, error: `Failed to spawn phase: ${outcome.error.message}` };
256
- }
257
- if (outcome.signal !== null) {
258
- return {
259
- name,
260
- status: SYSTEM_ERROR,
261
- signal: outcome.signal,
262
- error: `Phase '${name}' was killed by signal ${outcome.signal}`,
263
- };
264
- }
265
- if (outcome.status === null) {
266
- return { name, status: SYSTEM_ERROR, error: `Phase '${name}' exited without a status code` };
267
- }
268
- const exitCode = outcome.status;
269
- const { report, parseError } = parseChildReport(name, outcome.stdout);
270
- if (parseError !== undefined) {
271
- return { name, status: SYSTEM_ERROR, exitCode, error: parseError };
272
- }
198
+ export function phaseResultFromOutcome(name, outcome) {
199
+ const { exitCode, document } = outcome;
273
200
  const exitStatus = statusFromExitCode(exitCode);
274
- const reported = statusFromReport(report);
201
+ const reported = statusFromReport(document);
275
202
  const status = reported === undefined ? exitStatus : worseOf(exitStatus, reported);
276
203
  return {
277
204
  name,
@@ -280,37 +207,64 @@ export function phaseResultFromSpawn(name, outcome) {
280
207
  ...(exitStatus === SYSTEM_ERROR
281
208
  ? { error: `Phase '${name}' exited with system-error code ${exitCode}` }
282
209
  : {}),
283
- ...(report === undefined ? {} : { report }),
210
+ ...(document === undefined ? {} : { report: document }),
284
211
  };
285
212
  }
286
213
  /**
287
- * Cap on a captured child document, well above the ~2.3 MB a large real project
288
- * produces. spawnSync's 1 MB default would set ENOBUFS and hand back a
289
- * TRUNCATED (and therefore unparseable) document; exceeding this cap surfaces
290
- * as a loud `system-error`, never as a silently shortened report.
214
+ * End a command-line run from a phase outcome: publish the document, then exit.
215
+ *
216
+ * THE single place the two lanes diverge, so they cannot diverge anywhere else.
217
+ * A phase hands back the same `{ document, exitCode }` either way; this decides
218
+ * what a *command* does with it, while an orchestrator folds it into
219
+ * `phases[].report` instead.
220
+ *
221
+ * Three cases, and the middle one is the one to get right:
222
+ * - an unexpected failure publishes the shared envelope through
223
+ * `writeYamlOutput`, matching `handleCommandError`;
224
+ * - a command's own report goes through the command's own `render`;
225
+ * - no document at all (an unconfigured run, a dry run) publishes nothing.
226
+ *
227
+ * @param outcome - What the phase produced
228
+ * @param render - How this command publishes its OWN report shape
291
229
  */
292
- const MAX_PHASE_STDOUT_BYTES = 256 * 1024 * 1024;
230
+ export function finishCommand(outcome, render) {
231
+ if (outcome.failed === true) {
232
+ writeYamlOutput(outcome.document);
233
+ }
234
+ else if (outcome.document !== undefined) {
235
+ render(outcome.document);
236
+ }
237
+ return process.exit(outcome.exitCode);
238
+ }
293
239
  /**
294
- * Run a single phase by spawning the vat binary with the phase args.
240
+ * Run a single phase in THIS process and fold its outcome into a result.
241
+ *
242
+ * In THIS process, because everything an orchestrator reads back from a phase is
243
+ * the {@link PhaseOutcome} pair. A process per phase buys neither half of it and
244
+ * charges, on every phase, a full Node startup and the whole module graph again
245
+ * (~730 ms of remark per isolate), a parse cache whose miss counters restart
246
+ * from zero, and a worker pool built and torn down before the next phase begins.
247
+ * Phases run sequentially, so none of that cost is ever overlapped with work.
248
+ *
249
+ * The `catch` is a BACKSTOP, not the error path. Every phase function reports
250
+ * its own failures through `reportCommandError` and returns them as a document.
295
251
  *
296
- * stdout is CAPTURED, not inherited: the child's YAML document belongs in this
297
- * phase's `report`, and letting it stream onto the parent's stdout is what made
298
- * `vat validate`'s output a run of documents with no `---` between them.
299
- * stderr stays inherited — progress output is on stderr by design and must keep
300
- * streaming live rather than arriving in one lump at the end.
252
+ * ⚠️ This arm exists for a throw that escaped that handling. Sharing the
253
+ * orchestrator's process is what makes it load-bearing: an escaped throw aborts
254
+ * the orchestrator itself and silently skips every later phase.
301
255
  */
302
- export function runPhase(binPath, phase) {
303
- const result = spawnSync(process.execPath, [binPath, ...phase.args], {
304
- stdio: ['inherit', 'pipe', 'inherit'],
305
- encoding: 'utf8',
306
- maxBuffer: MAX_PHASE_STDOUT_BYTES,
307
- });
308
- return phaseResultFromSpawn(phase.name, {
309
- status: result.status,
310
- signal: result.signal,
311
- error: result.error,
312
- stdout: result.stdout,
313
- });
256
+ export async function runPhase(phase) {
257
+ try {
258
+ return phaseResultFromOutcome(phase.name, await phase.run());
259
+ }
260
+ catch (error) {
261
+ const detail = error instanceof Error ? error.message : String(error);
262
+ return {
263
+ name: phase.name,
264
+ status: SYSTEM_ERROR,
265
+ error: `Phase '${phase.name}' threw past its own error handling: ${detail}`,
266
+ };
267
+ }
314
268
  }
315
269
  /**
316
270
  * Worst-wins aggregate across phases. `system-error` outranks `error`: "we could
@@ -326,16 +280,16 @@ export function aggregatePhaseStatus(results) {
326
280
  /**
327
281
  * One phase's per-severity distribution, wherever that phase keeps it.
328
282
  *
329
- * An in-process phase holds its own findings and publishes {@link
330
- * PhaseResult.issueCounts}. A subprocess phase deliberately does not — the child
331
- * owns its findings, and its document rides verbatim in {@link
332
- * PhaseResult.report}. Reading only the former is why an orchestrator's header
333
- * could report `{0, 0, 0}` over children that had just reported 12 warnings.
283
+ * A phase that holds its own findings publishes {@link PhaseResult.issueCounts}.
284
+ * A phase that publishes its own document deliberately does not — it owns its
285
+ * findings, and its document rides verbatim in {@link PhaseResult.report}.
286
+ *
287
+ * ⚠️ Both places must be read. Reading only `issueCounts` makes an
288
+ * orchestrator's header report `{0, 0, 0}` over phases that just reported 12
289
+ * warnings.
334
290
  *
335
291
  * Absent or malformed counts read as zero rather than throwing: a phase that
336
- * published no distribution contributes nothing to the total, which is the same
337
- * answer as before this function existed — just no longer the answer for phases
338
- * that DID publish one.
292
+ * publishes no distribution contributes nothing to the total.
339
293
  */
340
294
  export function phaseIssueCounts(result) {
341
295
  if (result.issueCounts)
@@ -354,10 +308,10 @@ export function phaseIssueCounts(result) {
354
308
  * Sum every phase's distribution, so an orchestrator's header total reconciles
355
309
  * against the phases printed beneath it.
356
310
  *
357
- * The companion to {@link aggregatePhaseStatus}: status has always been
358
- * worst-wins ACROSS phases, and a header whose `status` can see the children
359
- * while its `issueCounts` cannot is the same contradiction in one document —
360
- * `status: warning` beside `warnings: 0`.
311
+ * The companion to {@link aggregatePhaseStatus}: status is worst-wins ACROSS
312
+ * phases, so a header whose `status` can see the phases while its `issueCounts`
313
+ * cannot publishes a contradiction in one document — `status: warning` beside
314
+ * `warnings: 0`.
361
315
  */
362
316
  export function aggregatePhaseIssueCounts(results) {
363
317
  const total = { errors: 0, warnings: 0, info: 0 };
@@ -1 +1 @@
1
- {"version":3,"file":"phase-utils.js","sourceRoot":"","sources":["../../src/commands/phase-utils.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAG/C,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AACrD,OAAO,EAAgB,MAAM,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAOrD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAAgB;IACnD,OAAO,OAAO,CAAC,SAAS,CACtB,IAAI,MAAM,CAAC,gBAAgB,EAAE,qCAAqC,CAAC,CAAC,QAAQ,EAAE,CAC/E,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAwB,EAAE,OAAe,EAAE,OAAe;IAC1F,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO;IAE/B,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,qCAAqC,OAAO,MAAM;QAChD,IAAI;QACJ,0BAA0B,OAAO,8CAA8C;QAC/E,8EAA8E;QAC9E,gFAAgF;QAChF,IAAI;QACJ,2BAA2B,OAAO,oCAAoC;QACtE,yFAAyF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oB,CAAC,OAAO,CAAC,CAAC;IAC5C,IAAI,KAAK,KAAK,YAAY;QAAE,OAAO,CAAC,CAAC;IACrC,OAAO,KAAK,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACnC,CAAC"}
@@ -1,10 +1,49 @@
1
1
  /**
2
2
  * RAG index command - index markdown resources into vector database
3
3
  */
4
+ import type { IndexResult } from '@vibe-agent-toolkit/rag';
4
5
  interface IndexOptions {
5
6
  db?: string;
6
7
  debug?: boolean;
7
8
  }
9
+ /**
10
+ * What an index run is allowed to report, and the exit code that agrees with it.
11
+ *
12
+ * `partial` is spelled the way `vat cache clear` spells it (see
13
+ * `../cache/clear.ts` — `status: 'success' | 'partial'`, exiting
14
+ * `partial ? 1 : 0`): a command that finished, published a complete report, and
15
+ * did not do all of what was asked. The vocabulary is deliberately the sibling's
16
+ * rather than a new one.
17
+ *
18
+ * Exit 1, not 2. This command family documents `1 - reported/expected failure`
19
+ * and `2 - system error` (`vat claude budget`, and the `Exit Codes:` block on
20
+ * every `vat rag` subcommand). A run that indexed most of a corpus and named the
21
+ * resources it dropped is a REPORTED outcome — the report on stdout is complete
22
+ * and parseable. 2 belongs to a command that could not run at all, which here is
23
+ * the `handleCommandError` path below.
24
+ */
25
+ export interface IndexOutcome {
26
+ status: 'success' | 'partial';
27
+ exitCode: 0 | 1;
28
+ }
29
+ /**
30
+ * Derive the reported status and exit code from what indexing actually did.
31
+ *
32
+ * This existed as a hardcoded `status: 'success'` next to an unconditional
33
+ * `process.exit(0)`, so a run that failed a fifth of its corpus told the user —
34
+ * and any CI step parsing it — that everything was fine, while the dropped
35
+ * documents were simply unsearchable. A status field that cannot express failure
36
+ * is the defect; the particular failures it hid are incidental, and
37
+ * `indexResources` can fail a resource for any reason (unreadable file,
38
+ * embedding-provider error, provider unavailable).
39
+ *
40
+ * `errors` is optional on `IndexResult`: the provider omits it entirely when
41
+ * nothing failed, and can also return `[]`. Both are success.
42
+ *
43
+ * @param indexResult - The result of the indexing run (only `errors` is read)
44
+ * @returns The status to publish and the exit code that agrees with it
45
+ */
46
+ export declare function indexOutcome(indexResult: Pick<IndexResult, 'errors'>): IndexOutcome;
8
47
  export declare function indexCommand(pathArg: string | undefined, options: IndexOptions): Promise<void>;
9
48
  export {};
10
49
  //# sourceMappingURL=index-command.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index-command.d.ts","sourceRoot":"","sources":["../../../src/commands/rag/index-command.ts"],"names":[],"mappings":"AAAA;;GAEG;AAWH,UAAU,YAAY;IACpB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,wBAAsB,YAAY,CAChC,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,OAAO,EAAE,YAAY,GACpB,OAAO,CAAC,IAAI,CAAC,CAuDf"}
1
+ {"version":3,"file":"index-command.d.ts","sourceRoot":"","sources":["../../../src/commands/rag/index-command.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAU3D,UAAU,YAAY;IACpB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,SAAS,GAAG,SAAS,CAAC;IAC9B,QAAQ,EAAE,CAAC,GAAG,CAAC,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,YAAY,CAAC,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAC,GAAG,YAAY,CAInF;AAED,wBAAsB,YAAY,CAChC,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,OAAO,EAAE,YAAY,GACpB,OAAO,CAAC,IAAI,CAAC,CA6Df"}
@@ -7,6 +7,27 @@ import { writeYamlOutput } from '../../utils/output.js';
7
7
  import { projectRootOrNull } from '../../utils/project-root-policy.js';
8
8
  import { loadResourcesWithConfig } from '../../utils/resource-loader.js';
9
9
  import { formatDuration, handleCommandError, resolveDbPath } from './command-helpers.js';
10
+ /**
11
+ * Derive the reported status and exit code from what indexing actually did.
12
+ *
13
+ * This existed as a hardcoded `status: 'success'` next to an unconditional
14
+ * `process.exit(0)`, so a run that failed a fifth of its corpus told the user —
15
+ * and any CI step parsing it — that everything was fine, while the dropped
16
+ * documents were simply unsearchable. A status field that cannot express failure
17
+ * is the defect; the particular failures it hid are incidental, and
18
+ * `indexResources` can fail a resource for any reason (unreadable file,
19
+ * embedding-provider error, provider unavailable).
20
+ *
21
+ * `errors` is optional on `IndexResult`: the provider omits it entirely when
22
+ * nothing failed, and can also return `[]`. Both are success.
23
+ *
24
+ * @param indexResult - The result of the indexing run (only `errors` is read)
25
+ * @returns The status to publish and the exit code that agrees with it
26
+ */
27
+ export function indexOutcome(indexResult) {
28
+ const failed = indexResult.errors?.length ?? 0;
29
+ return failed > 0 ? { status: 'partial', exitCode: 1 } : { status: 'success', exitCode: 0 };
30
+ }
10
31
  export async function indexCommand(pathArg, options) {
11
32
  const logger = createLogger({ debug: options.debug ?? false });
12
33
  const startTime = Date.now();
@@ -35,9 +56,11 @@ export async function indexCommand(pathArg, options) {
35
56
  // Close provider
36
57
  await ragProvider.close();
37
58
  const duration = Date.now() - startTime;
59
+ // Status is DERIVED, never asserted: see `indexOutcome`.
60
+ const outcome = indexOutcome(indexResult);
38
61
  // Output results as YAML
39
62
  writeYamlOutput({
40
- status: 'success',
63
+ status: outcome.status,
41
64
  resourcesIndexed: indexResult.resourcesIndexed,
42
65
  resourcesSkipped: indexResult.resourcesSkipped,
43
66
  resourcesUpdated: indexResult.resourcesUpdated,
@@ -48,7 +71,10 @@ export async function indexCommand(pathArg, options) {
48
71
  ? { errors: indexResult.errors }
49
72
  : {}),
50
73
  });
51
- process.exit(0);
74
+ // The report is published FIRST and the failure signalled after, so a
75
+ // partial run still hands the operator the `errors` list naming exactly
76
+ // which resources are missing from the database.
77
+ process.exit(outcome.exitCode);
52
78
  }
53
79
  catch (error) {
54
80
  handleCommandError(error, logger, startTime, 'Index');
@@ -1 +1 @@
1
- {"version":3,"file":"index-command.js","sourceRoot":"","sources":["../../../src/commands/rag/index-command.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAErE,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,oCAAoC,CAAC;AACvE,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAEzE,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAOzF,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,OAA2B,EAC3B,OAAqB;IAErB,MAAM,MAAM,GAAG,YAAY,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,KAAK,EAAE,CAAC,CAAC;IAC/D,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAE7B,IAAI,CAAC;QACH,2CAA2C;QAC3C,sEAAsE;QACtE,gDAAgD;QAChD,MAAM,WAAW,GAAG,iBAAiB,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;QAErD,qEAAqE;QACrE,MAAM,MAAM,GAAG,aAAa,CAAC,OAAO,CAAC,EAAE,EAAE,WAAW,IAAI,SAAS,CAAC,CAAC;QACnE,MAAM,CAAC,KAAK,CAAC,kBAAkB,MAAM,EAAE,CAAC,CAAC;QAEzC,yEAAyE;QACzE,sEAAsE;QACtE,0EAA0E;QAC1E,MAAM,SAAS,GAAG,WAAW,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;QAC/C,MAAM,EAAE,QAAQ,EAAE,GAAG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,CAAC,MAAM,EAAE;gBAChC,CAAC,CAAC,EAAE,CAAC;SACR,CAAC,CAAC;QAEH,sEAAsE;QACtE,wEAAwE;QACxE,iDAAiD;QACjD,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IACjC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;IACxD,CAAC;AACH,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/rag/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAYpC,wBAAgB,gBAAgB,IAAI,OAAO,CAsM1C;AAED,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/rag/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAsBpC,wBAAgB,gBAAgB,IAAI,OAAO,CAwM1C;AAED,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC"}
@@ -2,10 +2,19 @@
2
2
  * RAG command group
3
3
  */
4
4
  import { Command } from 'commander';
5
- import { clearCommand } from './clear-command.js';
6
- import { indexCommand } from './index-command.js';
7
- import { queryCommand } from './query-command.js';
8
- import { statsCommand } from './stats-command.js';
5
+ import { lazyAction } from '../../utils/optional-backend.js';
6
+ /**
7
+ * The RAG lane ships as an optional install.
8
+ *
9
+ * `rag-lancedb` carries a platform-native LanceDB binary
10
+ * and pulls `onnxruntime-web` and `gpt-tokenizer` behind it -- 275 MB of a
11
+ * 351 MB install, and 1,350 ms of cold module load, for a lane most vat
12
+ * commands never touch.
13
+ */
14
+ const RAG_BACKEND = {
15
+ feature: 'RAG',
16
+ packageName: '@vibe-agent-toolkit/rag-lancedb',
17
+ };
9
18
  // Common option descriptions
10
19
  const DB_PATH_OPTION = '--db <path>';
11
20
  const DB_PATH_DESC = 'Database path (default: .rag-db in project root)';
@@ -40,7 +49,7 @@ Configuration:
40
49
  .description('Index markdown resources into vector database')
41
50
  .option(DB_PATH_OPTION, DB_PATH_DESC)
42
51
  .option('--debug', DEBUG_OPTION_DESC)
43
- .action(indexCommand)
52
+ .action(lazyAction(RAG_BACKEND, async () => (await import('./index-command.js')).indexCommand))
44
53
  .addHelpText('after', `
45
54
  Description:
46
55
  Indexes markdown files into LanceDB vector database for semantic search.
@@ -53,16 +62,18 @@ Description:
53
62
  When no path: uses vibe-agent-toolkit.config.yaml include/exclude patterns
54
63
 
55
64
  Output Structure (YAML):
56
- status: success/error
65
+ status: success (every resource indexed) / partial (some failed) / error
57
66
  resourcesIndexed: new/updated files
58
67
  resourcesSkipped: unchanged files (content hash match)
59
68
  resourcesUpdated: files with new content
60
69
  chunksCreated: total chunks added
61
70
  chunksDeleted: chunks removed from updated files
62
71
  duration: total indexing time
72
+ errors: resources that failed, present only when non-empty. Their content
73
+ is NOT in the index and NOT searchable.
63
74
 
64
75
  Exit Codes:
65
- 0 - Success | 2 - System error
76
+ 0 - Success | 1 - Indexed with errors (see 'errors') | 2 - System error
66
77
 
67
78
  Requirements:
68
79
  projectRoot: optional (tolerates absence — use --db to specify path)
@@ -81,7 +92,7 @@ Example:
81
92
  .option(DB_PATH_OPTION, DB_PATH_DESC)
82
93
  .option('--limit <n>', 'Maximum results to return (default: 10)', Number.parseInt)
83
94
  .option('--debug', DEBUG_OPTION_DESC)
84
- .action(queryCommand)
95
+ .action(lazyAction(RAG_BACKEND, async () => (await import('./query-command.js')).queryCommand))
85
96
  .addHelpText('after', `
86
97
  Description:
87
98
  Searches vector database using semantic similarity. Converts your query
@@ -123,7 +134,7 @@ Example:
123
134
  .description('Show RAG database statistics')
124
135
  .option(DB_PATH_OPTION, DB_PATH_DESC)
125
136
  .option('--debug', DEBUG_OPTION_DESC)
126
- .action(statsCommand)
137
+ .action(lazyAction(RAG_BACKEND, async () => (await import('./stats-command.js')).statsCommand))
127
138
  .addHelpText('after', `
128
139
  Description:
129
140
  Displays vector database statistics including indexed content count,
@@ -157,7 +168,7 @@ Example:
157
168
  .description('Delete entire RAG database directory')
158
169
  .option(DB_PATH_OPTION, DB_PATH_DESC)
159
170
  .option('--debug', DEBUG_OPTION_DESC)
160
- .action(clearCommand)
171
+ .action(lazyAction(RAG_BACKEND, async () => (await import('./clear-command.js')).clearCommand))
161
172
  .addHelpText('after', `
162
173
  Description:
163
174
  Deletes the entire RAG database directory and all indexed data.
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/rag/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,6BAA6B;AAC7B,MAAM,cAAc,GAAG,aAAa,CAAC;AACrC,MAAM,YAAY,GAAG,kDAAkD,CAAC;AACxE,MAAM,iBAAiB,GAAG,sBAAsB,CAAC;AAEjD,MAAM,UAAU,gBAAgB;IAC9B,MAAM,GAAG,GAAG,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC;IAE/B,GAAG;SACA,WAAW,CAAC,qEAAqE,CAAC;SAClF,WAAW,CAAC,KAAK,CAAC,CAAC,uDAAuD;SAC1E,WAAW,CACV,OAAO,EACP;;;;;;;;;;;;;;;;;;;CAmBL,CACI,CAAC;IAEJ,GAAG;SACA,OAAO,CAAC,cAAc,CAAC;SACvB,WAAW,CAAC,+CAA+C,CAAC;SAC5D,MAAM,CAAC,cAAc,EAAE,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