@selvakumaresra/specship 0.1.3 → 0.4.0

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 (718) hide show
  1. package/README.md +2 -2
  2. package/commands/ss-design-implement.md +84 -0
  3. package/commands/ss-design-loop.md +125 -0
  4. package/commands/{cg-drifted.md → ss-drifted.md} +2 -2
  5. package/commands/{cg-fix.md → ss-fix.md} +1 -1
  6. package/commands/{cg-implement.md → ss-implement.md} +1 -1
  7. package/commands/ss-spec-author.md +43 -0
  8. package/commands/ss-spec-review.md +48 -0
  9. package/dist/bin/node-version-check.d.ts +37 -0
  10. package/dist/bin/node-version-check.d.ts.map +1 -0
  11. package/dist/bin/node-version-check.js +79 -0
  12. package/dist/bin/node-version-check.js.map +1 -0
  13. package/dist/bin/specship.d.ts +25 -0
  14. package/dist/bin/specship.d.ts.map +1 -0
  15. package/dist/bin/specship.js +2085 -0
  16. package/dist/bin/specship.js.map +1 -0
  17. package/dist/bin/uninstall.d.ts +13 -0
  18. package/dist/bin/uninstall.d.ts.map +1 -0
  19. package/dist/bin/uninstall.js +35 -0
  20. package/dist/bin/uninstall.js.map +1 -0
  21. package/dist/context/formatter.d.ts +30 -0
  22. package/dist/context/formatter.d.ts.map +1 -0
  23. package/dist/context/formatter.js +263 -0
  24. package/dist/context/formatter.js.map +1 -0
  25. package/dist/context/index.d.ts +119 -0
  26. package/dist/context/index.d.ts.map +1 -0
  27. package/dist/context/index.js +1289 -0
  28. package/dist/context/index.js.map +1 -0
  29. package/dist/context/markers.d.ts +19 -0
  30. package/dist/context/markers.d.ts.map +1 -0
  31. package/dist/context/markers.js +22 -0
  32. package/dist/context/markers.js.map +1 -0
  33. package/dist/db/index.d.ts +103 -0
  34. package/dist/db/index.d.ts.map +1 -0
  35. package/dist/db/index.js +279 -0
  36. package/dist/db/index.js.map +1 -0
  37. package/dist/db/migrations.d.ts +44 -0
  38. package/dist/db/migrations.d.ts.map +1 -0
  39. package/dist/db/migrations.js +462 -0
  40. package/dist/db/migrations.js.map +1 -0
  41. package/dist/db/queries.d.ts +357 -0
  42. package/dist/db/queries.d.ts.map +1 -0
  43. package/dist/db/queries.js +1504 -0
  44. package/dist/db/queries.js.map +1 -0
  45. package/dist/db/schema.sql +419 -0
  46. package/dist/db/spec-queries.d.ts +101 -0
  47. package/dist/db/spec-queries.d.ts.map +1 -0
  48. package/dist/db/spec-queries.js +675 -0
  49. package/dist/db/spec-queries.js.map +1 -0
  50. package/dist/db/sqlite-adapter.d.ts +65 -0
  51. package/dist/db/sqlite-adapter.d.ts.map +1 -0
  52. package/dist/db/sqlite-adapter.js +214 -0
  53. package/dist/db/sqlite-adapter.js.map +1 -0
  54. package/dist/designer/artifact-store.js +54 -0
  55. package/dist/designer/browser.js +141 -0
  56. package/dist/designer/cdp-ensure.js +60 -0
  57. package/dist/designer/cdp-env.js +18 -0
  58. package/dist/designer/cdp-trace.js +599 -0
  59. package/dist/designer/cross-platform.js +74 -0
  60. package/dist/designer/designer-controller.js +1413 -0
  61. package/dist/designer/file-panel.js +39 -0
  62. package/dist/designer/interstitials.js +97 -0
  63. package/dist/designer/oopif-reader.js +176 -0
  64. package/dist/designer/package-meta.js +18 -0
  65. package/dist/designer/preview-host.js +50 -0
  66. package/dist/designer/repo-root.js +31 -0
  67. package/dist/designer/run-state.js +353 -0
  68. package/dist/designer/session-store.js +59 -0
  69. package/dist/designer/ui-anchors.js +651 -0
  70. package/dist/directory.d.ts +67 -0
  71. package/dist/directory.d.ts.map +1 -0
  72. package/dist/directory.js +267 -0
  73. package/dist/directory.js.map +1 -0
  74. package/dist/errors.d.ts +136 -0
  75. package/dist/errors.d.ts.map +1 -0
  76. package/dist/errors.js +219 -0
  77. package/dist/errors.js.map +1 -0
  78. package/dist/extraction/dfm-extractor.d.ts +31 -0
  79. package/dist/extraction/dfm-extractor.d.ts.map +1 -0
  80. package/dist/extraction/dfm-extractor.js +151 -0
  81. package/dist/extraction/dfm-extractor.js.map +1 -0
  82. package/dist/extraction/generated-detection.d.ts +30 -0
  83. package/dist/extraction/generated-detection.d.ts.map +1 -0
  84. package/dist/extraction/generated-detection.js +80 -0
  85. package/dist/extraction/generated-detection.js.map +1 -0
  86. package/dist/extraction/grammars.d.ts +100 -0
  87. package/dist/extraction/grammars.d.ts.map +1 -0
  88. package/dist/extraction/grammars.js +426 -0
  89. package/dist/extraction/grammars.js.map +1 -0
  90. package/dist/extraction/index.d.ts +138 -0
  91. package/dist/extraction/index.d.ts.map +1 -0
  92. package/dist/extraction/index.js +1394 -0
  93. package/dist/extraction/index.js.map +1 -0
  94. package/dist/extraction/languages/c-cpp.d.ts +4 -0
  95. package/dist/extraction/languages/c-cpp.d.ts.map +1 -0
  96. package/dist/extraction/languages/c-cpp.js +171 -0
  97. package/dist/extraction/languages/c-cpp.js.map +1 -0
  98. package/dist/extraction/languages/csharp.d.ts +3 -0
  99. package/dist/extraction/languages/csharp.d.ts.map +1 -0
  100. package/dist/extraction/languages/csharp.js +73 -0
  101. package/dist/extraction/languages/csharp.js.map +1 -0
  102. package/dist/extraction/languages/dart.d.ts +3 -0
  103. package/dist/extraction/languages/dart.d.ts.map +1 -0
  104. package/dist/extraction/languages/dart.js +192 -0
  105. package/dist/extraction/languages/dart.js.map +1 -0
  106. package/dist/extraction/languages/go.d.ts +3 -0
  107. package/dist/extraction/languages/go.d.ts.map +1 -0
  108. package/dist/extraction/languages/go.js +74 -0
  109. package/dist/extraction/languages/go.js.map +1 -0
  110. package/dist/extraction/languages/index.d.ts +10 -0
  111. package/dist/extraction/languages/index.d.ts.map +1 -0
  112. package/dist/extraction/languages/index.js +51 -0
  113. package/dist/extraction/languages/index.js.map +1 -0
  114. package/dist/extraction/languages/java.d.ts +3 -0
  115. package/dist/extraction/languages/java.d.ts.map +1 -0
  116. package/dist/extraction/languages/java.js +70 -0
  117. package/dist/extraction/languages/java.js.map +1 -0
  118. package/dist/extraction/languages/javascript.d.ts +3 -0
  119. package/dist/extraction/languages/javascript.d.ts.map +1 -0
  120. package/dist/extraction/languages/javascript.js +90 -0
  121. package/dist/extraction/languages/javascript.js.map +1 -0
  122. package/dist/extraction/languages/kotlin.d.ts +3 -0
  123. package/dist/extraction/languages/kotlin.d.ts.map +1 -0
  124. package/dist/extraction/languages/kotlin.js +259 -0
  125. package/dist/extraction/languages/kotlin.js.map +1 -0
  126. package/dist/extraction/languages/lua.d.ts +3 -0
  127. package/dist/extraction/languages/lua.d.ts.map +1 -0
  128. package/dist/extraction/languages/lua.js +150 -0
  129. package/dist/extraction/languages/lua.js.map +1 -0
  130. package/dist/extraction/languages/luau.d.ts +3 -0
  131. package/dist/extraction/languages/luau.d.ts.map +1 -0
  132. package/dist/extraction/languages/luau.js +37 -0
  133. package/dist/extraction/languages/luau.js.map +1 -0
  134. package/dist/extraction/languages/objc.d.ts +3 -0
  135. package/dist/extraction/languages/objc.d.ts.map +1 -0
  136. package/dist/extraction/languages/objc.js +133 -0
  137. package/dist/extraction/languages/objc.js.map +1 -0
  138. package/dist/extraction/languages/pascal.d.ts +3 -0
  139. package/dist/extraction/languages/pascal.d.ts.map +1 -0
  140. package/dist/extraction/languages/pascal.js +66 -0
  141. package/dist/extraction/languages/pascal.js.map +1 -0
  142. package/dist/extraction/languages/php.d.ts +3 -0
  143. package/dist/extraction/languages/php.d.ts.map +1 -0
  144. package/dist/extraction/languages/php.js +107 -0
  145. package/dist/extraction/languages/php.js.map +1 -0
  146. package/dist/extraction/languages/python.d.ts +3 -0
  147. package/dist/extraction/languages/python.d.ts.map +1 -0
  148. package/dist/extraction/languages/python.js +56 -0
  149. package/dist/extraction/languages/python.js.map +1 -0
  150. package/dist/extraction/languages/ruby.d.ts +3 -0
  151. package/dist/extraction/languages/ruby.d.ts.map +1 -0
  152. package/dist/extraction/languages/ruby.js +114 -0
  153. package/dist/extraction/languages/ruby.js.map +1 -0
  154. package/dist/extraction/languages/rust.d.ts +3 -0
  155. package/dist/extraction/languages/rust.d.ts.map +1 -0
  156. package/dist/extraction/languages/rust.js +109 -0
  157. package/dist/extraction/languages/rust.js.map +1 -0
  158. package/dist/extraction/languages/scala.d.ts +3 -0
  159. package/dist/extraction/languages/scala.d.ts.map +1 -0
  160. package/dist/extraction/languages/scala.js +139 -0
  161. package/dist/extraction/languages/scala.js.map +1 -0
  162. package/dist/extraction/languages/swift.d.ts +3 -0
  163. package/dist/extraction/languages/swift.d.ts.map +1 -0
  164. package/dist/extraction/languages/swift.js +91 -0
  165. package/dist/extraction/languages/swift.js.map +1 -0
  166. package/dist/extraction/languages/typescript.d.ts +3 -0
  167. package/dist/extraction/languages/typescript.d.ts.map +1 -0
  168. package/dist/extraction/languages/typescript.js +129 -0
  169. package/dist/extraction/languages/typescript.js.map +1 -0
  170. package/dist/extraction/liquid-extractor.d.ts +52 -0
  171. package/dist/extraction/liquid-extractor.d.ts.map +1 -0
  172. package/dist/extraction/liquid-extractor.js +313 -0
  173. package/dist/extraction/liquid-extractor.js.map +1 -0
  174. package/dist/extraction/mybatis-extractor.d.ts +48 -0
  175. package/dist/extraction/mybatis-extractor.d.ts.map +1 -0
  176. package/dist/extraction/mybatis-extractor.js +198 -0
  177. package/dist/extraction/mybatis-extractor.js.map +1 -0
  178. package/dist/extraction/parse-worker.d.ts +8 -0
  179. package/dist/extraction/parse-worker.d.ts.map +1 -0
  180. package/dist/extraction/parse-worker.js +94 -0
  181. package/dist/extraction/parse-worker.js.map +1 -0
  182. package/dist/extraction/specs/markdown-spec-extractor.d.ts +59 -0
  183. package/dist/extraction/specs/markdown-spec-extractor.d.ts.map +1 -0
  184. package/dist/extraction/specs/markdown-spec-extractor.js +327 -0
  185. package/dist/extraction/specs/markdown-spec-extractor.js.map +1 -0
  186. package/dist/extraction/specs/types.d.ts +39 -0
  187. package/dist/extraction/specs/types.d.ts.map +1 -0
  188. package/dist/extraction/specs/types.js +8 -0
  189. package/dist/extraction/specs/types.js.map +1 -0
  190. package/dist/extraction/svelte-extractor.d.ts +56 -0
  191. package/dist/extraction/svelte-extractor.d.ts.map +1 -0
  192. package/dist/extraction/svelte-extractor.js +272 -0
  193. package/dist/extraction/svelte-extractor.js.map +1 -0
  194. package/dist/extraction/tree-sitter-helpers.d.ts +28 -0
  195. package/dist/extraction/tree-sitter-helpers.d.ts.map +1 -0
  196. package/dist/extraction/tree-sitter-helpers.js +103 -0
  197. package/dist/extraction/tree-sitter-helpers.js.map +1 -0
  198. package/dist/extraction/tree-sitter-types.d.ts +193 -0
  199. package/dist/extraction/tree-sitter-types.d.ts.map +1 -0
  200. package/dist/extraction/tree-sitter-types.js +10 -0
  201. package/dist/extraction/tree-sitter-types.js.map +1 -0
  202. package/dist/extraction/tree-sitter.d.ts +317 -0
  203. package/dist/extraction/tree-sitter.d.ts.map +1 -0
  204. package/dist/extraction/tree-sitter.js +3092 -0
  205. package/dist/extraction/tree-sitter.js.map +1 -0
  206. package/dist/extraction/vue-extractor.d.ts +51 -0
  207. package/dist/extraction/vue-extractor.d.ts.map +1 -0
  208. package/dist/extraction/vue-extractor.js +251 -0
  209. package/dist/extraction/vue-extractor.js.map +1 -0
  210. package/dist/extraction/wasm/tree-sitter-lua.wasm +0 -0
  211. package/dist/extraction/wasm/tree-sitter-luau.wasm +0 -0
  212. package/dist/extraction/wasm/tree-sitter-pascal.wasm +0 -0
  213. package/dist/extraction/wasm/tree-sitter-scala.wasm +0 -0
  214. package/dist/extraction/wasm-runtime-flags.d.ts +38 -0
  215. package/dist/extraction/wasm-runtime-flags.d.ts.map +1 -0
  216. package/dist/extraction/wasm-runtime-flags.js +106 -0
  217. package/dist/extraction/wasm-runtime-flags.js.map +1 -0
  218. package/dist/graph/index.d.ts +8 -0
  219. package/dist/graph/index.d.ts.map +1 -0
  220. package/dist/graph/index.js +13 -0
  221. package/dist/graph/index.js.map +1 -0
  222. package/dist/graph/queries.d.ts +106 -0
  223. package/dist/graph/queries.d.ts.map +1 -0
  224. package/dist/graph/queries.js +366 -0
  225. package/dist/graph/queries.js.map +1 -0
  226. package/dist/graph/traversal.d.ts +127 -0
  227. package/dist/graph/traversal.d.ts.map +1 -0
  228. package/dist/graph/traversal.js +531 -0
  229. package/dist/graph/traversal.js.map +1 -0
  230. package/dist/index.d.ts +551 -0
  231. package/dist/index.d.ts.map +1 -0
  232. package/dist/index.js +1165 -0
  233. package/dist/index.js.map +1 -0
  234. package/dist/installer/config-writer.d.ts +28 -0
  235. package/dist/installer/config-writer.d.ts.map +1 -0
  236. package/dist/installer/config-writer.js +91 -0
  237. package/dist/installer/config-writer.js.map +1 -0
  238. package/dist/installer/index.d.ts +92 -0
  239. package/dist/installer/index.d.ts.map +1 -0
  240. package/dist/installer/index.js +416 -0
  241. package/dist/installer/index.js.map +1 -0
  242. package/dist/installer/instructions-template.d.ts +35 -0
  243. package/dist/installer/instructions-template.d.ts.map +1 -0
  244. package/dist/installer/instructions-template.js +51 -0
  245. package/dist/installer/instructions-template.js.map +1 -0
  246. package/dist/installer/targets/claude.d.ts +117 -0
  247. package/dist/installer/targets/claude.d.ts.map +1 -0
  248. package/dist/installer/targets/claude.js +736 -0
  249. package/dist/installer/targets/claude.js.map +1 -0
  250. package/dist/installer/targets/registry.d.ts +19 -0
  251. package/dist/installer/targets/registry.d.ts.map +1 -0
  252. package/dist/installer/targets/registry.js +31 -0
  253. package/dist/installer/targets/registry.js.map +1 -0
  254. package/dist/installer/targets/shared.d.ts +76 -0
  255. package/dist/installer/targets/shared.d.ts.map +1 -0
  256. package/dist/installer/targets/shared.js +256 -0
  257. package/dist/installer/targets/shared.js.map +1 -0
  258. package/dist/installer/targets/types.d.ts +84 -0
  259. package/dist/installer/targets/types.d.ts.map +1 -0
  260. package/dist/installer/targets/types.js +12 -0
  261. package/dist/installer/targets/types.js.map +1 -0
  262. package/dist/isolation/worktree.d.ts +65 -0
  263. package/dist/isolation/worktree.d.ts.map +1 -0
  264. package/dist/isolation/worktree.js +231 -0
  265. package/dist/isolation/worktree.js.map +1 -0
  266. package/dist/mcp/daemon-paths.d.ts +46 -0
  267. package/dist/mcp/daemon-paths.d.ts.map +1 -0
  268. package/dist/mcp/daemon-paths.js +125 -0
  269. package/dist/mcp/daemon-paths.js.map +1 -0
  270. package/dist/mcp/daemon.d.ts +161 -0
  271. package/dist/mcp/daemon.d.ts.map +1 -0
  272. package/dist/mcp/daemon.js +403 -0
  273. package/dist/mcp/daemon.js.map +1 -0
  274. package/dist/mcp/designer-tools.d.ts +33 -0
  275. package/dist/mcp/designer-tools.d.ts.map +1 -0
  276. package/dist/mcp/designer-tools.js +313 -0
  277. package/dist/mcp/designer-tools.js.map +1 -0
  278. package/dist/mcp/engine.d.ts +105 -0
  279. package/dist/mcp/engine.d.ts.map +1 -0
  280. package/dist/mcp/engine.js +270 -0
  281. package/dist/mcp/engine.js.map +1 -0
  282. package/dist/mcp/index.d.ts +112 -0
  283. package/dist/mcp/index.d.ts.map +1 -0
  284. package/dist/mcp/index.js +477 -0
  285. package/dist/mcp/index.js.map +1 -0
  286. package/dist/mcp/proxy.d.ts +81 -0
  287. package/dist/mcp/proxy.d.ts.map +1 -0
  288. package/dist/mcp/proxy.js +510 -0
  289. package/dist/mcp/proxy.js.map +1 -0
  290. package/dist/mcp/server-instructions.d.ts +18 -0
  291. package/dist/mcp/server-instructions.d.ts.map +1 -0
  292. package/dist/mcp/server-instructions.js +77 -0
  293. package/dist/mcp/server-instructions.js.map +1 -0
  294. package/dist/mcp/session.d.ts +77 -0
  295. package/dist/mcp/session.d.ts.map +1 -0
  296. package/dist/mcp/session.js +294 -0
  297. package/dist/mcp/session.js.map +1 -0
  298. package/dist/mcp/spec-tools.d.ts +39 -0
  299. package/dist/mcp/spec-tools.d.ts.map +1 -0
  300. package/dist/mcp/spec-tools.js +326 -0
  301. package/dist/mcp/spec-tools.js.map +1 -0
  302. package/dist/mcp/tools.d.ts +404 -0
  303. package/dist/mcp/tools.d.ts.map +1 -0
  304. package/dist/mcp/tools.js +3087 -0
  305. package/dist/mcp/tools.js.map +1 -0
  306. package/dist/mcp/transport.d.ts +188 -0
  307. package/dist/mcp/transport.d.ts.map +1 -0
  308. package/dist/mcp/transport.js +343 -0
  309. package/dist/mcp/transport.js.map +1 -0
  310. package/dist/mcp/version.d.ts +19 -0
  311. package/dist/mcp/version.d.ts.map +1 -0
  312. package/dist/mcp/version.js +71 -0
  313. package/dist/mcp/version.js.map +1 -0
  314. package/dist/resolution/callback-synthesizer.d.ts +10 -0
  315. package/dist/resolution/callback-synthesizer.d.ts.map +1 -0
  316. package/dist/resolution/callback-synthesizer.js +1300 -0
  317. package/dist/resolution/callback-synthesizer.js.map +1 -0
  318. package/dist/resolution/frameworks/cargo-workspace.d.ts +18 -0
  319. package/dist/resolution/frameworks/cargo-workspace.d.ts.map +1 -0
  320. package/dist/resolution/frameworks/cargo-workspace.js +225 -0
  321. package/dist/resolution/frameworks/cargo-workspace.js.map +1 -0
  322. package/dist/resolution/frameworks/csharp.d.ts +8 -0
  323. package/dist/resolution/frameworks/csharp.d.ts.map +1 -0
  324. package/dist/resolution/frameworks/csharp.js +241 -0
  325. package/dist/resolution/frameworks/csharp.js.map +1 -0
  326. package/dist/resolution/frameworks/drupal.d.ts +51 -0
  327. package/dist/resolution/frameworks/drupal.d.ts.map +1 -0
  328. package/dist/resolution/frameworks/drupal.js +367 -0
  329. package/dist/resolution/frameworks/drupal.js.map +1 -0
  330. package/dist/resolution/frameworks/expo-modules.d.ts +3 -0
  331. package/dist/resolution/frameworks/expo-modules.d.ts.map +1 -0
  332. package/dist/resolution/frameworks/expo-modules.js +143 -0
  333. package/dist/resolution/frameworks/expo-modules.js.map +1 -0
  334. package/dist/resolution/frameworks/express.d.ts +8 -0
  335. package/dist/resolution/frameworks/express.d.ts.map +1 -0
  336. package/dist/resolution/frameworks/express.js +308 -0
  337. package/dist/resolution/frameworks/express.js.map +1 -0
  338. package/dist/resolution/frameworks/fabric.d.ts +3 -0
  339. package/dist/resolution/frameworks/fabric.d.ts.map +1 -0
  340. package/dist/resolution/frameworks/fabric.js +354 -0
  341. package/dist/resolution/frameworks/fabric.js.map +1 -0
  342. package/dist/resolution/frameworks/go.d.ts +8 -0
  343. package/dist/resolution/frameworks/go.d.ts.map +1 -0
  344. package/dist/resolution/frameworks/go.js +161 -0
  345. package/dist/resolution/frameworks/go.js.map +1 -0
  346. package/dist/resolution/frameworks/index.d.ts +48 -0
  347. package/dist/resolution/frameworks/index.d.ts.map +1 -0
  348. package/dist/resolution/frameworks/index.js +161 -0
  349. package/dist/resolution/frameworks/index.js.map +1 -0
  350. package/dist/resolution/frameworks/java.d.ts +8 -0
  351. package/dist/resolution/frameworks/java.d.ts.map +1 -0
  352. package/dist/resolution/frameworks/java.js +504 -0
  353. package/dist/resolution/frameworks/java.js.map +1 -0
  354. package/dist/resolution/frameworks/laravel.d.ts +13 -0
  355. package/dist/resolution/frameworks/laravel.d.ts.map +1 -0
  356. package/dist/resolution/frameworks/laravel.js +257 -0
  357. package/dist/resolution/frameworks/laravel.js.map +1 -0
  358. package/dist/resolution/frameworks/nestjs.d.ts +26 -0
  359. package/dist/resolution/frameworks/nestjs.d.ts.map +1 -0
  360. package/dist/resolution/frameworks/nestjs.js +698 -0
  361. package/dist/resolution/frameworks/nestjs.js.map +1 -0
  362. package/dist/resolution/frameworks/play.d.ts +19 -0
  363. package/dist/resolution/frameworks/play.d.ts.map +1 -0
  364. package/dist/resolution/frameworks/play.js +111 -0
  365. package/dist/resolution/frameworks/play.js.map +1 -0
  366. package/dist/resolution/frameworks/python.d.ts +10 -0
  367. package/dist/resolution/frameworks/python.d.ts.map +1 -0
  368. package/dist/resolution/frameworks/python.js +396 -0
  369. package/dist/resolution/frameworks/python.js.map +1 -0
  370. package/dist/resolution/frameworks/react-native.d.ts +3 -0
  371. package/dist/resolution/frameworks/react-native.d.ts.map +1 -0
  372. package/dist/resolution/frameworks/react-native.js +360 -0
  373. package/dist/resolution/frameworks/react-native.js.map +1 -0
  374. package/dist/resolution/frameworks/react.d.ts +8 -0
  375. package/dist/resolution/frameworks/react.d.ts.map +1 -0
  376. package/dist/resolution/frameworks/react.js +365 -0
  377. package/dist/resolution/frameworks/react.js.map +1 -0
  378. package/dist/resolution/frameworks/ruby.d.ts +8 -0
  379. package/dist/resolution/frameworks/ruby.d.ts.map +1 -0
  380. package/dist/resolution/frameworks/ruby.js +302 -0
  381. package/dist/resolution/frameworks/ruby.js.map +1 -0
  382. package/dist/resolution/frameworks/rust.d.ts +8 -0
  383. package/dist/resolution/frameworks/rust.d.ts.map +1 -0
  384. package/dist/resolution/frameworks/rust.js +304 -0
  385. package/dist/resolution/frameworks/rust.js.map +1 -0
  386. package/dist/resolution/frameworks/svelte.d.ts +9 -0
  387. package/dist/resolution/frameworks/svelte.d.ts.map +1 -0
  388. package/dist/resolution/frameworks/svelte.js +249 -0
  389. package/dist/resolution/frameworks/svelte.js.map +1 -0
  390. package/dist/resolution/frameworks/swift-objc.d.ts +37 -0
  391. package/dist/resolution/frameworks/swift-objc.d.ts.map +1 -0
  392. package/dist/resolution/frameworks/swift-objc.js +252 -0
  393. package/dist/resolution/frameworks/swift-objc.js.map +1 -0
  394. package/dist/resolution/frameworks/swift.d.ts +10 -0
  395. package/dist/resolution/frameworks/swift.d.ts.map +1 -0
  396. package/dist/resolution/frameworks/swift.js +400 -0
  397. package/dist/resolution/frameworks/swift.js.map +1 -0
  398. package/dist/resolution/frameworks/vue.d.ts +9 -0
  399. package/dist/resolution/frameworks/vue.d.ts.map +1 -0
  400. package/dist/resolution/frameworks/vue.js +306 -0
  401. package/dist/resolution/frameworks/vue.js.map +1 -0
  402. package/dist/resolution/go-module.d.ts +26 -0
  403. package/dist/resolution/go-module.d.ts.map +1 -0
  404. package/dist/resolution/go-module.js +78 -0
  405. package/dist/resolution/go-module.js.map +1 -0
  406. package/dist/resolution/import-resolver.d.ts +68 -0
  407. package/dist/resolution/import-resolver.d.ts.map +1 -0
  408. package/dist/resolution/import-resolver.js +1275 -0
  409. package/dist/resolution/import-resolver.js.map +1 -0
  410. package/dist/resolution/index.d.ts +117 -0
  411. package/dist/resolution/index.d.ts.map +1 -0
  412. package/dist/resolution/index.js +895 -0
  413. package/dist/resolution/index.js.map +1 -0
  414. package/dist/resolution/lru-cache.d.ts +24 -0
  415. package/dist/resolution/lru-cache.d.ts.map +1 -0
  416. package/dist/resolution/lru-cache.js +62 -0
  417. package/dist/resolution/lru-cache.js.map +1 -0
  418. package/dist/resolution/name-matcher.d.ts +32 -0
  419. package/dist/resolution/name-matcher.d.ts.map +1 -0
  420. package/dist/resolution/name-matcher.js +596 -0
  421. package/dist/resolution/name-matcher.js.map +1 -0
  422. package/dist/resolution/path-aliases.d.ts +68 -0
  423. package/dist/resolution/path-aliases.d.ts.map +1 -0
  424. package/dist/resolution/path-aliases.js +238 -0
  425. package/dist/resolution/path-aliases.js.map +1 -0
  426. package/dist/resolution/spec-link-resolver.d.ts +103 -0
  427. package/dist/resolution/spec-link-resolver.d.ts.map +1 -0
  428. package/dist/resolution/spec-link-resolver.js +259 -0
  429. package/dist/resolution/spec-link-resolver.js.map +1 -0
  430. package/dist/resolution/strip-comments.d.ts +27 -0
  431. package/dist/resolution/strip-comments.d.ts.map +1 -0
  432. package/dist/resolution/strip-comments.js +441 -0
  433. package/dist/resolution/strip-comments.js.map +1 -0
  434. package/dist/resolution/swift-objc-bridge.d.ts +134 -0
  435. package/dist/resolution/swift-objc-bridge.d.ts.map +1 -0
  436. package/dist/resolution/swift-objc-bridge.js +256 -0
  437. package/dist/resolution/swift-objc-bridge.js.map +1 -0
  438. package/dist/resolution/types.d.ts +216 -0
  439. package/dist/resolution/types.d.ts.map +1 -0
  440. package/dist/resolution/types.js +8 -0
  441. package/dist/resolution/types.js.map +1 -0
  442. package/dist/resolution/workspace-packages.d.ts +48 -0
  443. package/dist/resolution/workspace-packages.d.ts.map +1 -0
  444. package/dist/resolution/workspace-packages.js +208 -0
  445. package/dist/resolution/workspace-packages.js.map +1 -0
  446. package/dist/search/query-parser.d.ts +57 -0
  447. package/dist/search/query-parser.d.ts.map +1 -0
  448. package/dist/search/query-parser.js +177 -0
  449. package/dist/search/query-parser.js.map +1 -0
  450. package/dist/search/query-utils.d.ts +71 -0
  451. package/dist/search/query-utils.d.ts.map +1 -0
  452. package/dist/search/query-utils.js +380 -0
  453. package/dist/search/query-utils.js.map +1 -0
  454. package/dist/server/cli.js +152 -0
  455. package/dist/server/index.js +12 -0
  456. package/dist/server/ingest/index.js +18 -0
  457. package/dist/server/ingest/ingestor.js +506 -0
  458. package/dist/server/ingest/parser.js +104 -0
  459. package/dist/server/ingest/pricing.js +78 -0
  460. package/dist/server/ingest/types.js +9 -0
  461. package/dist/server/ingest/watcher.js +77 -0
  462. package/dist/server/package.json +3 -0
  463. package/dist/server/project-registry.js +101 -0
  464. package/dist/server/routes/claude.js +868 -0
  465. package/dist/server/routes/graph.js +211 -0
  466. package/dist/server/routes/memory.js +272 -0
  467. package/dist/server/routes/projects.js +197 -0
  468. package/dist/server/routes/spec.js +265 -0
  469. package/dist/server/routes/status.js +112 -0
  470. package/dist/server/routes/workflow.js +212 -0
  471. package/dist/server/server.js +206 -0
  472. package/dist/server/static-handler.js +87 -0
  473. package/dist/sync/git-hooks.d.ts +45 -0
  474. package/dist/sync/git-hooks.d.ts.map +1 -0
  475. package/dist/sync/git-hooks.js +225 -0
  476. package/dist/sync/git-hooks.js.map +1 -0
  477. package/dist/sync/index.d.ts +19 -0
  478. package/dist/sync/index.d.ts.map +1 -0
  479. package/dist/sync/index.js +35 -0
  480. package/dist/sync/index.js.map +1 -0
  481. package/dist/sync/watch-policy.d.ts +48 -0
  482. package/dist/sync/watch-policy.d.ts.map +1 -0
  483. package/dist/sync/watch-policy.js +124 -0
  484. package/dist/sync/watch-policy.js.map +1 -0
  485. package/dist/sync/watcher.d.ts +283 -0
  486. package/dist/sync/watcher.d.ts.map +1 -0
  487. package/dist/sync/watcher.js +606 -0
  488. package/dist/sync/watcher.js.map +1 -0
  489. package/dist/sync/worktree.d.ts +54 -0
  490. package/dist/sync/worktree.d.ts.map +1 -0
  491. package/dist/sync/worktree.js +137 -0
  492. package/dist/sync/worktree.js.map +1 -0
  493. package/dist/types.d.ts +623 -0
  494. package/dist/types.d.ts.map +1 -0
  495. package/dist/types.js +108 -0
  496. package/dist/types.js.map +1 -0
  497. package/dist/ui/glyphs.d.ts +42 -0
  498. package/dist/ui/glyphs.d.ts.map +1 -0
  499. package/dist/ui/glyphs.js +78 -0
  500. package/dist/ui/glyphs.js.map +1 -0
  501. package/dist/ui/shimmer-progress.d.ts +11 -0
  502. package/dist/ui/shimmer-progress.d.ts.map +1 -0
  503. package/dist/ui/shimmer-progress.js +90 -0
  504. package/dist/ui/shimmer-progress.js.map +1 -0
  505. package/dist/ui/shimmer-worker.d.ts +2 -0
  506. package/dist/ui/shimmer-worker.d.ts.map +1 -0
  507. package/dist/ui/shimmer-worker.js +118 -0
  508. package/dist/ui/shimmer-worker.js.map +1 -0
  509. package/dist/ui/types.d.ts +17 -0
  510. package/dist/ui/types.d.ts.map +1 -0
  511. package/dist/ui/types.js +3 -0
  512. package/dist/ui/types.js.map +1 -0
  513. package/dist/utils.d.ts +205 -0
  514. package/dist/utils.d.ts.map +1 -0
  515. package/dist/utils.js +549 -0
  516. package/dist/utils.js.map +1 -0
  517. package/dist/web/chunk-2AJCHB7P.js +1 -0
  518. package/dist/web/chunk-2CPLUFCH.js +2 -0
  519. package/dist/web/chunk-2GBEK2GM.js +1 -0
  520. package/dist/web/chunk-2I7L37NS.js +1 -0
  521. package/dist/web/chunk-2NAWAJB5.js +1 -0
  522. package/dist/web/chunk-2OJBIPE4.js +1 -0
  523. package/dist/web/chunk-2YUJNZ2Y.js +6 -0
  524. package/dist/web/chunk-3E2WB6D5.js +1 -0
  525. package/dist/web/chunk-3EBFYSCH.js +2 -0
  526. package/dist/web/chunk-3QCQ4BXS.js +1 -0
  527. package/dist/web/chunk-42XVAQ6I.js +1 -0
  528. package/dist/web/chunk-45QHGCB4.js +17 -0
  529. package/dist/web/chunk-4IMMPEYM.js +1 -0
  530. package/dist/web/chunk-4TJQJPCZ.js +1 -0
  531. package/dist/web/chunk-4WZIHTPC.js +1 -0
  532. package/dist/web/chunk-4YVSYOSD.js +1 -0
  533. package/dist/web/chunk-5BQIOYKW.js +1 -0
  534. package/dist/web/chunk-5HGWHUJA.js +1 -0
  535. package/dist/web/chunk-5Y244R4G.js +1 -0
  536. package/dist/web/chunk-6RRDPT5Z.js +1 -0
  537. package/dist/web/chunk-6VKB2ZWM.js +1 -0
  538. package/dist/web/chunk-7DMFVTU4.js +1 -0
  539. package/dist/web/chunk-7RNS77UP.js +1 -0
  540. package/dist/web/chunk-7SMPKVEP.js +1 -0
  541. package/dist/web/chunk-A5R3MJMO.js +1 -0
  542. package/dist/web/chunk-ASZ77FMZ.js +1 -0
  543. package/dist/web/chunk-AZJVTPLU.js +1 -0
  544. package/dist/web/chunk-B3YPFY6A.js +1 -0
  545. package/dist/web/chunk-BLBRMCN2.js +1 -0
  546. package/dist/web/chunk-BMIAXD2V.js +2 -0
  547. package/dist/web/chunk-BUXWEHIY.js +1 -0
  548. package/dist/web/chunk-BYZFQSM6.js +1 -0
  549. package/dist/web/chunk-D5OCNEJA.js +2 -0
  550. package/dist/web/chunk-DLQPZWSI.css +1 -0
  551. package/dist/web/chunk-DTRN7FZR.js +1 -0
  552. package/dist/web/chunk-DYRFLPJA.js +1 -0
  553. package/dist/web/chunk-E3J3CXR5.js +1 -0
  554. package/dist/web/chunk-E44X4RH2.js +1 -0
  555. package/dist/web/chunk-E73OX2P7.js +1 -0
  556. package/dist/web/chunk-EAXRKDLV.js +1 -0
  557. package/dist/web/chunk-EBKKDHYI.js +1 -0
  558. package/dist/web/chunk-EE7V7Q5P.js +1 -0
  559. package/dist/web/chunk-EKY2FUHU.js +1 -0
  560. package/dist/web/chunk-EMGMOEVR.js +1 -0
  561. package/dist/web/chunk-EP6XOPXH.js +1 -0
  562. package/dist/web/chunk-ESGDLJOJ.js +1 -0
  563. package/dist/web/chunk-ETJG7NCY.js +1 -0
  564. package/dist/web/chunk-EUUEFEDI.js +1 -0
  565. package/dist/web/chunk-FGNZDHTL.js +11 -0
  566. package/dist/web/chunk-FHZHD2ZG.js +1 -0
  567. package/dist/web/chunk-FIJW2UNJ.js +1 -0
  568. package/dist/web/chunk-FMV5PXRC.js +5 -0
  569. package/dist/web/chunk-G7VZT5KB.js +3 -0
  570. package/dist/web/chunk-GR72OOCN.js +1 -0
  571. package/dist/web/chunk-GRZYXPSO.js +7 -0
  572. package/dist/web/chunk-GWPVKJIY.js +1 -0
  573. package/dist/web/chunk-GYGPS3AN.js +1 -0
  574. package/dist/web/chunk-H7AF7YS4.js +1 -0
  575. package/dist/web/chunk-HDZDQILN.js +1 -0
  576. package/dist/web/chunk-HMK6UO6N.js +1 -0
  577. package/dist/web/chunk-HZA6NEAB.js +1 -0
  578. package/dist/web/chunk-IHEE5NYJ.js +1 -0
  579. package/dist/web/chunk-ISNEBICW.js +1 -0
  580. package/dist/web/chunk-J2GZVLHH.js +1 -0
  581. package/dist/web/chunk-JTFXTIPE.js +903 -0
  582. package/dist/web/chunk-L37MTFSG.js +3 -0
  583. package/dist/web/chunk-LB6JPLX2.js +1 -0
  584. package/dist/web/chunk-LNSVDHCI.js +1 -0
  585. package/dist/web/chunk-LVGIY3SO.js +1 -0
  586. package/dist/web/chunk-LXLHIHEN.js +1 -0
  587. package/dist/web/chunk-MC4DFIHG.js +1 -0
  588. package/dist/web/chunk-MVOMVPYB.js +1 -0
  589. package/dist/web/chunk-N6SS4G6S.js +1 -0
  590. package/dist/web/chunk-NTBJG6SJ.js +1 -0
  591. package/dist/web/chunk-NUDB3Q2Y.js +3 -0
  592. package/dist/web/chunk-NZEZCT65.js +1 -0
  593. package/dist/web/chunk-OXEF5E3E.js +1 -0
  594. package/dist/web/chunk-PDN6QYGJ.js +4 -0
  595. package/dist/web/chunk-PGGJPDJG.js +1 -0
  596. package/dist/web/chunk-PUYSJNJR.js +1 -0
  597. package/dist/web/chunk-Q2RVFS45.js +1 -0
  598. package/dist/web/chunk-Q7L6LLAK.js +1 -0
  599. package/dist/web/chunk-QCMKJIWY.js +1 -0
  600. package/dist/web/chunk-QH6CF3M3.js +1 -0
  601. package/dist/web/chunk-QQ5LD7PI.js +1 -0
  602. package/dist/web/chunk-QR6L3KAC.js +1 -0
  603. package/dist/web/chunk-R2DLK4HO.js +1 -0
  604. package/dist/web/chunk-R5W2MDZN.js +1 -0
  605. package/dist/web/chunk-RD6TVPOT.js +1 -0
  606. package/dist/web/chunk-RKY4EJYJ.js +1 -0
  607. package/dist/web/chunk-RONYWVY7.js +1 -0
  608. package/dist/web/chunk-RXKXYF2C.js +1 -0
  609. package/dist/web/chunk-SBWU7JFC.js +1 -0
  610. package/dist/web/chunk-SEXBRGYK.js +1 -0
  611. package/dist/web/chunk-SHPTC4RL.js +1 -0
  612. package/dist/web/chunk-SUZYBYDW.js +1 -0
  613. package/dist/web/chunk-SWKJRNYY.js +1 -0
  614. package/dist/web/chunk-T66XVKGB.js +1 -0
  615. package/dist/web/chunk-T7AZ65JP.js +1 -0
  616. package/dist/web/chunk-TCZDVOHD.js +1 -0
  617. package/dist/web/chunk-TPTITA3V.js +1 -0
  618. package/dist/web/chunk-TR335633.js +1 -0
  619. package/dist/web/chunk-UBOZGQNK.js +1 -0
  620. package/dist/web/chunk-UR5KDXPX.js +1 -0
  621. package/dist/web/chunk-UR6O2GEH.js +1 -0
  622. package/dist/web/chunk-UTNMGWTP.js +1 -0
  623. package/dist/web/chunk-UYC52MBC.js +1 -0
  624. package/dist/web/chunk-VECWMHJP.js +1 -0
  625. package/dist/web/chunk-VUACT35R.js +3 -0
  626. package/dist/web/chunk-VZI7H4SZ.js +1 -0
  627. package/dist/web/chunk-WAI2JMZP.js +1 -0
  628. package/dist/web/chunk-WB6YHOD4.js +1 -0
  629. package/dist/web/chunk-WBT64AWV.js +1 -0
  630. package/dist/web/chunk-WCKHQIYN.js +1 -0
  631. package/dist/web/chunk-WDU3WICG.js +1 -0
  632. package/dist/web/chunk-WFXJIXZE.js +4 -0
  633. package/dist/web/chunk-WLIMNDS3.js +1 -0
  634. package/dist/web/chunk-WTGYRH3Z.js +298 -0
  635. package/dist/web/chunk-WXTCVDTP.js +1 -0
  636. package/dist/web/chunk-X2HTISHL.js +1 -0
  637. package/dist/web/chunk-XCDHWLVH.js +1 -0
  638. package/dist/web/chunk-Y3H6FFUZ.js +1 -0
  639. package/dist/web/chunk-Y4F5ULGJ.js +1 -0
  640. package/dist/web/chunk-YAMRN47K.js +2 -0
  641. package/dist/web/chunk-YEGKAAEE.js +1 -0
  642. package/dist/web/chunk-YM2KU57F.js +1 -0
  643. package/dist/web/chunk-YRERBP6T.js +1 -0
  644. package/dist/web/chunk-ZLV4VCDG.js +3 -0
  645. package/dist/web/chunk-ZTVI5KFF.js +1 -0
  646. package/dist/web/favicon-16.png +0 -0
  647. package/dist/web/favicon-180.png +0 -0
  648. package/dist/web/favicon-32.png +0 -0
  649. package/dist/web/favicon-512.png +0 -0
  650. package/dist/web/favicon-small.svg +15 -0
  651. package/dist/web/favicon.ico +0 -0
  652. package/dist/web/favicon.svg +20 -0
  653. package/dist/web/index.html +145 -0
  654. package/dist/web/main-ESADRXN2.css +1 -0
  655. package/dist/web/main-R53HA54V.js +1 -0
  656. package/dist/web/media/codicon-LN6W7LCM.ttf +0 -0
  657. package/dist/web/styles-KSOPUVDA.css +1 -0
  658. package/dist/web/sw.js +69 -0
  659. package/dist/workflows/condition-evaluator.d.ts +75 -0
  660. package/dist/workflows/condition-evaluator.d.ts.map +1 -0
  661. package/dist/workflows/condition-evaluator.js +282 -0
  662. package/dist/workflows/condition-evaluator.js.map +1 -0
  663. package/dist/workflows/defaults/claude-design-implement.yaml +336 -0
  664. package/dist/workflows/defaults/index.d.ts +26 -0
  665. package/dist/workflows/defaults/index.d.ts.map +1 -0
  666. package/dist/workflows/defaults/index.js +94 -0
  667. package/dist/workflows/defaults/index.js.map +1 -0
  668. package/dist/workflows/defaults/spec-author.yaml +214 -0
  669. package/dist/workflows/defaults/spec-fix.yaml +110 -0
  670. package/dist/workflows/defaults/spec-implement.yaml +150 -0
  671. package/dist/workflows/defaults/spec-relink.yaml +81 -0
  672. package/dist/workflows/defaults/spec-verify.yaml +51 -0
  673. package/dist/workflows/discovery.d.ts +46 -0
  674. package/dist/workflows/discovery.d.ts.map +1 -0
  675. package/dist/workflows/discovery.js +193 -0
  676. package/dist/workflows/discovery.js.map +1 -0
  677. package/dist/workflows/executor.d.ts +83 -0
  678. package/dist/workflows/executor.d.ts.map +1 -0
  679. package/dist/workflows/executor.js +624 -0
  680. package/dist/workflows/executor.js.map +1 -0
  681. package/dist/workflows/runners/approval.d.ts +18 -0
  682. package/dist/workflows/runners/approval.d.ts.map +1 -0
  683. package/dist/workflows/runners/approval.js +34 -0
  684. package/dist/workflows/runners/approval.js.map +1 -0
  685. package/dist/workflows/runners/bash.d.ts +13 -0
  686. package/dist/workflows/runners/bash.d.ts.map +1 -0
  687. package/dist/workflows/runners/bash.js +143 -0
  688. package/dist/workflows/runners/bash.js.map +1 -0
  689. package/dist/workflows/runners/cancel.d.ts +10 -0
  690. package/dist/workflows/runners/cancel.d.ts.map +1 -0
  691. package/dist/workflows/runners/cancel.js +19 -0
  692. package/dist/workflows/runners/cancel.js.map +1 -0
  693. package/dist/workflows/runners/prompt.d.ts +28 -0
  694. package/dist/workflows/runners/prompt.d.ts.map +1 -0
  695. package/dist/workflows/runners/prompt.js +212 -0
  696. package/dist/workflows/runners/prompt.js.map +1 -0
  697. package/dist/workflows/runners/script.d.ts +17 -0
  698. package/dist/workflows/runners/script.d.ts.map +1 -0
  699. package/dist/workflows/runners/script.js +155 -0
  700. package/dist/workflows/runners/script.js.map +1 -0
  701. package/dist/workflows/runners/types.d.ts +51 -0
  702. package/dist/workflows/runners/types.d.ts.map +1 -0
  703. package/dist/workflows/runners/types.js +13 -0
  704. package/dist/workflows/runners/types.js.map +1 -0
  705. package/dist/workflows/schemas/workflow.d.ts +166 -0
  706. package/dist/workflows/schemas/workflow.d.ts.map +1 -0
  707. package/dist/workflows/schemas/workflow.js +437 -0
  708. package/dist/workflows/schemas/workflow.js.map +1 -0
  709. package/hooks/hooks.json +11 -0
  710. package/package.json +7 -3
  711. package/scripts/offline-install.sh +19 -6
  712. package/selectors.json +41 -0
  713. /package/commands/{cg-explore.md → ss-explore.md} +0 -0
  714. /package/commands/{cg-impact.md → ss-impact.md} +0 -0
  715. /package/commands/{cg-relink.md → ss-relink.md} +0 -0
  716. /package/commands/{cg-spec.md → ss-spec.md} +0 -0
  717. /package/commands/{cg-sync.md → ss-sync.md} +0 -0
  718. /package/commands/{cg-trace.md → ss-trace.md} +0 -0
@@ -0,0 +1,2085 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ /**
4
+ * SpecShip CLI
5
+ *
6
+ * Command-line interface for SpecShip code intelligence.
7
+ *
8
+ * Usage:
9
+ * specship Run interactive installer (when no args)
10
+ * specship install Run interactive installer
11
+ * specship uninstall Remove SpecShip from your agents
12
+ * specship init [path] Initialize SpecShip in a project
13
+ * specship uninit [path] Remove SpecShip from a project
14
+ * specship index [path] Index all files in the project
15
+ * specship sync [path] Sync changes since last index
16
+ * specship status [path] Show index status
17
+ * specship query <search> Search for symbols
18
+ * specship files [options] Show project file structure
19
+ * specship context <task> Build context for a task
20
+ * specship callers <symbol> Find what calls a function/method
21
+ * specship callees <symbol> Find what a function/method calls
22
+ * specship impact <symbol> Analyze what code is affected by changing a symbol
23
+ * specship affected [files] Find test files affected by changes
24
+ */
25
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
26
+ if (k2 === undefined) k2 = k;
27
+ var desc = Object.getOwnPropertyDescriptor(m, k);
28
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
29
+ desc = { enumerable: true, get: function() { return m[k]; } };
30
+ }
31
+ Object.defineProperty(o, k2, desc);
32
+ }) : (function(o, m, k, k2) {
33
+ if (k2 === undefined) k2 = k;
34
+ o[k2] = m[k];
35
+ }));
36
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
37
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
38
+ }) : function(o, v) {
39
+ o["default"] = v;
40
+ });
41
+ var __importStar = (this && this.__importStar) || (function () {
42
+ var ownKeys = function(o) {
43
+ ownKeys = Object.getOwnPropertyNames || function (o) {
44
+ var ar = [];
45
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
46
+ return ar;
47
+ };
48
+ return ownKeys(o);
49
+ };
50
+ return function (mod) {
51
+ if (mod && mod.__esModule) return mod;
52
+ var result = {};
53
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
54
+ __setModuleDefault(result, mod);
55
+ return result;
56
+ };
57
+ })();
58
+ Object.defineProperty(exports, "__esModule", { value: true });
59
+ const commander_1 = require("commander");
60
+ const path = __importStar(require("path"));
61
+ const fs = __importStar(require("fs"));
62
+ const os = __importStar(require("os"));
63
+ const directory_1 = require("../directory");
64
+ const worktree_1 = require("../sync/worktree");
65
+ const shimmer_progress_1 = require("../ui/shimmer-progress");
66
+ const glyphs_1 = require("../ui/glyphs");
67
+ const node_version_check_1 = require("./node-version-check");
68
+ const wasm_runtime_flags_1 = require("../extraction/wasm-runtime-flags");
69
+ // Lazy-load heavy modules (SpecShip, runInstaller) to keep CLI startup fast.
70
+ async function loadSpecShip() {
71
+ try {
72
+ return await Promise.resolve().then(() => __importStar(require('../index')));
73
+ }
74
+ catch (err) {
75
+ const msg = err instanceof Error ? err.message : String(err);
76
+ console.error(`\x1b[31m${(0, glyphs_1.getGlyphs)().err}\x1b[0m Failed to load SpecShip modules.`);
77
+ console.error(`\n Node: ${process.version} Platform: ${process.platform} ${process.arch}`);
78
+ console.error(`\n Error: ${msg}`);
79
+ console.error('\n Try reinstalling with: npm install -g @selvakumaresra/specship\n');
80
+ process.exit(1);
81
+ }
82
+ }
83
+ async function loadServerPackage() {
84
+ // Resolution order:
85
+ // 1. Bundled mode — `dist/server/index.js` next to this CLI. This is
86
+ // what every `npm i -g @selvakumaresra/specship` install hits, since
87
+ // the publish pipeline copies the compiled server into the root's
88
+ // `dist/`.
89
+ // 2. npm dep `@selvakumaresra/specship-server` if some downstream
90
+ // consumer ever wires it as a separate package (kept for forward
91
+ // compatibility — not the shipped path).
92
+ // 3. Dev/workspace sibling: `packages/server/dist/index.js` for
93
+ // running from a checkout without a prior `npm run build`.
94
+ const candidates = [
95
+ path.resolve(__dirname, '..', 'server', 'index.js'),
96
+ '@selvakumaresra/specship-server',
97
+ path.resolve(__dirname, '..', '..', 'packages', 'server', 'dist', 'index.js'),
98
+ path.resolve(__dirname, '..', '..', '..', 'packages', 'server', 'dist', 'index.js'),
99
+ ];
100
+ let lastErr = null;
101
+ for (const c of candidates) {
102
+ try {
103
+ return (await Promise.resolve(`${c}`).then(s => __importStar(require(s))));
104
+ }
105
+ catch (e) {
106
+ lastErr = e;
107
+ }
108
+ }
109
+ console.error(`\x1b[31m${(0, glyphs_1.getGlyphs)().err}\x1b[0m Could not load the bundled HTTP server. Re-run \`npm run build\` (or the bundled npm install is corrupt).`);
110
+ if (lastErr)
111
+ console.error(' ' + (lastErr instanceof Error ? lastErr.message : String(lastErr)));
112
+ process.exit(1);
113
+ }
114
+ /**
115
+ * The JSONL ingest watcher now ships inside `@selvakumaresra/specship-server`
116
+ * itself — `createServer({ ingest: true })` starts it. No separate package.
117
+ */
118
+ /**
119
+ * Auto-pick a default project for `specship serve --ui` when the user
120
+ * didn't pass `-p` and the cwd isn't initialized either. Walks
121
+ * `~/.claude/projects/*` (Claude Code's per-project transcript dirs),
122
+ * decodes each slug back to a real path, and returns the most-recently-
123
+ * touched one that's still on disk AND has been `specship init`'d.
124
+ *
125
+ * Returns null when nothing qualifies — the server boots projectless and
126
+ * the desktop UI prompts the user to pick.
127
+ */
128
+ async function pickRecentInitializedProject() {
129
+ const claudeRoot = path.join(os.homedir(), '.claude', 'projects');
130
+ let entries;
131
+ try {
132
+ entries = fs.readdirSync(claudeRoot, { withFileTypes: true });
133
+ }
134
+ catch {
135
+ return null;
136
+ }
137
+ const candidates = [];
138
+ for (const ent of entries) {
139
+ if (!ent.isDirectory())
140
+ continue;
141
+ const slug = ent.name;
142
+ // Same encoding the server's decodeProjectSlug uses: '-' → '/'.
143
+ const decoded = slug.startsWith('-') ? '/' + slug.slice(1).replace(/-/g, '/') : slug;
144
+ try {
145
+ const st = fs.statSync(decoded);
146
+ if (!st.isDirectory())
147
+ continue;
148
+ }
149
+ catch {
150
+ continue;
151
+ }
152
+ if (!(0, directory_1.isInitialized)(decoded))
153
+ continue;
154
+ // Use the newest .jsonl mtime in the slug dir as the activity signal.
155
+ let lastTouched = 0;
156
+ try {
157
+ const files = fs.readdirSync(path.join(claudeRoot, slug), { withFileTypes: true });
158
+ for (const f of files) {
159
+ if (!f.isFile() || !f.name.toLowerCase().endsWith('.jsonl'))
160
+ continue;
161
+ try {
162
+ const st = fs.statSync(path.join(claudeRoot, slug, f.name));
163
+ if (st.mtimeMs > lastTouched)
164
+ lastTouched = st.mtimeMs;
165
+ }
166
+ catch { /* ignore */ }
167
+ }
168
+ }
169
+ catch { /* ignore */ }
170
+ candidates.push({ decoded, lastTouched });
171
+ }
172
+ candidates.sort((a, b) => b.lastTouched - a.lastTouched);
173
+ return candidates[0]?.decoded ?? null;
174
+ }
175
+ /**
176
+ * Locate the built Angular UI for `specship serve --ui`. Mirrors the
177
+ * lookup order in `packages/server/src/cli.ts:locateWebDir` so both entry
178
+ * points behave identically. Returns null when nothing is found — the
179
+ * server then runs API-only.
180
+ */
181
+ function locateWebDir(explicit) {
182
+ const envDir = process.env.SPECSHIP_WEB_DIR ?? process.env.SPECSHIP_WEB_DIR;
183
+ const candidates = [];
184
+ if (explicit)
185
+ candidates.push(path.resolve(explicit));
186
+ if (envDir)
187
+ candidates.push(path.resolve(envDir));
188
+ // 1. Bundled mode — `dist/web/` next to this CLI. This is what every
189
+ // `npm i -g @selvakumaresra/specship` install hits.
190
+ candidates.push(path.resolve(__dirname, '..', 'web'));
191
+ // 2. Legacy / forward-compat: the old `@selvakumaresra/specship-server`
192
+ // used to ship the SPA at <pkg>/public/web.
193
+ try {
194
+ const pkgJson = require.resolve('@selvakumaresra/specship-server/package.json');
195
+ candidates.push(path.resolve(path.dirname(pkgJson), 'public', 'web'));
196
+ }
197
+ catch { /* not installed as separate package — fall through */ }
198
+ // 3. Dev monorepo layouts (running from a checkout).
199
+ candidates.push(path.resolve(__dirname, '..', '..', 'packages', 'server', 'public', 'web'));
200
+ candidates.push(path.resolve(__dirname, '..', '..', '..', 'packages', 'server', 'public', 'web'));
201
+ candidates.push(path.resolve(__dirname, '..', '..', 'packages', 'web-ng', 'dist', 'web-ng', 'browser'));
202
+ candidates.push(path.resolve(__dirname, '..', '..', '..', 'packages', 'web-ng', 'dist', 'web-ng', 'browser'));
203
+ // 4. Walk up from cwd in case the bin is run inside a checkout.
204
+ let cur = process.cwd();
205
+ for (let depth = 0; depth < 6; depth++) {
206
+ candidates.push(path.join(cur, 'dist', 'web'));
207
+ candidates.push(path.join(cur, 'packages', 'server', 'public', 'web'));
208
+ candidates.push(path.join(cur, 'packages', 'web-ng', 'dist', 'web-ng', 'browser'));
209
+ const parent = path.dirname(cur);
210
+ if (parent === cur)
211
+ break;
212
+ cur = parent;
213
+ }
214
+ for (const c of candidates) {
215
+ try {
216
+ if (fs.existsSync(path.join(c, 'index.html')))
217
+ return c;
218
+ }
219
+ catch { /* ignore */ }
220
+ }
221
+ return null;
222
+ }
223
+ // Dynamic import helper — tsc compiles import() to require() in CJS mode,
224
+ // which fails for ESM-only packages. This bypasses the transformation.
225
+ // eslint-disable-next-line @typescript-eslint/no-implied-eval
226
+ const importESM = new Function('specifier', 'return import(specifier)');
227
+ // Block SpecShip on Node.js 25.x — V8's turboshaft WASM JIT has a Zone
228
+ // allocator bug that reliably crashes when compiling tree-sitter
229
+ // grammars (see #54, #81, #140). The previous behaviour was a soft
230
+ // console.warn that scrolls off-screen before the OOM crash 30 seconds
231
+ // later, leading to a steady stream of "what is this OOM" reports.
232
+ // Hard-exit before any WASM work; allow override via env var for users
233
+ // who patched V8 themselves or want to test a future fix.
234
+ const nodeVersion = process.versions.node;
235
+ const nodeMajor = parseInt(nodeVersion.split('.')[0] ?? '0', 10);
236
+ if (nodeMajor >= 25) {
237
+ process.stderr.write((0, node_version_check_1.buildNode25BlockBanner)(nodeVersion) + '\n');
238
+ if (!process.env.SPECSHIP_ALLOW_UNSAFE_NODE) {
239
+ process.exit(1);
240
+ }
241
+ // Override active — banner shown for visibility, continuing.
242
+ }
243
+ // Enforce the supported Node floor. `engines` in package.json only *warns* on
244
+ // install (unless engine-strict), so hard-block here to actually keep users off
245
+ // unsupported versions. Mirrors the 25+ block above. See package.json `engines`.
246
+ if (nodeMajor < node_version_check_1.MIN_NODE_MAJOR) {
247
+ process.stderr.write((0, node_version_check_1.buildNodeTooOldBanner)(nodeVersion) + '\n');
248
+ if (!process.env.SPECSHIP_ALLOW_UNSAFE_NODE) {
249
+ process.exit(1);
250
+ }
251
+ // Override active — banner shown for visibility, continuing.
252
+ }
253
+ // Re-exec with V8's `--liftoff-only` if it isn't already set, so tree-sitter's
254
+ // large WASM grammars never hit the turboshaft Zone OOM (`Fatal process out of
255
+ // memory: Zone`) on Node >= 22. No-op under the bundled launcher, which already
256
+ // passes the flag. Must run before any grammar (in the parse worker, which
257
+ // inherits this process's flags) is compiled. See ../extraction/wasm-runtime-flags.
258
+ (0, wasm_runtime_flags_1.relaunchWithWasmRuntimeFlagsIfNeeded)(__filename);
259
+ // Check if running with no arguments - run installer
260
+ if (process.argv.length === 2) {
261
+ Promise.resolve().then(() => __importStar(require('../installer'))).then(({ runInstaller }) => runInstaller()).catch((err) => {
262
+ console.error('Installation failed:', err instanceof Error ? err.message : String(err));
263
+ process.exit(1);
264
+ });
265
+ }
266
+ else {
267
+ // Normal CLI flow
268
+ main();
269
+ }
270
+ process.on('uncaughtException', (error) => {
271
+ console.error('[SpecShip] Uncaught exception:', error);
272
+ });
273
+ process.on('unhandledRejection', (reason) => {
274
+ console.error('[SpecShip] Unhandled rejection:', reason);
275
+ });
276
+ function main() {
277
+ const program = new commander_1.Command();
278
+ // Version from package.json
279
+ const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, '..', '..', 'package.json'), 'utf-8'));
280
+ // =============================================================================
281
+ // ANSI Color Helpers (avoid chalk ESM issues)
282
+ // =============================================================================
283
+ const colors = {
284
+ reset: '\x1b[0m',
285
+ bold: '\x1b[1m',
286
+ dim: '\x1b[2m',
287
+ red: '\x1b[31m',
288
+ green: '\x1b[32m',
289
+ yellow: '\x1b[33m',
290
+ blue: '\x1b[34m',
291
+ cyan: '\x1b[36m',
292
+ white: '\x1b[37m',
293
+ gray: '\x1b[90m',
294
+ };
295
+ const chalk = {
296
+ bold: (s) => `${colors.bold}${s}${colors.reset}`,
297
+ dim: (s) => `${colors.dim}${s}${colors.reset}`,
298
+ red: (s) => `${colors.red}${s}${colors.reset}`,
299
+ green: (s) => `${colors.green}${s}${colors.reset}`,
300
+ yellow: (s) => `${colors.yellow}${s}${colors.reset}`,
301
+ blue: (s) => `${colors.blue}${s}${colors.reset}`,
302
+ cyan: (s) => `${colors.cyan}${s}${colors.reset}`,
303
+ white: (s) => `${colors.white}${s}${colors.reset}`,
304
+ gray: (s) => `${colors.gray}${s}${colors.reset}`,
305
+ };
306
+ program
307
+ .name('specship')
308
+ .description('Code intelligence and knowledge graph for any codebase')
309
+ .version(packageJson.version);
310
+ // =============================================================================
311
+ // Helper Functions
312
+ // =============================================================================
313
+ /**
314
+ * Resolve project path from argument or current directory
315
+ * Walks up parent directories to find nearest initialized SpecShip project
316
+ * (must have .specship/specship.db, not just .specship/lessons.db)
317
+ */
318
+ function resolveProjectPath(pathArg) {
319
+ const absolutePath = path.resolve(pathArg || process.cwd());
320
+ // If exact path is initialized (has specship.db), use it
321
+ if ((0, directory_1.isInitialized)(absolutePath)) {
322
+ return absolutePath;
323
+ }
324
+ // Walk up to find nearest parent with SpecShip initialized
325
+ // Note: findNearestSpecShipRoot finds any .specship folder, but we need one with specship.db
326
+ let current = absolutePath;
327
+ const root = path.parse(current).root;
328
+ while (current !== root) {
329
+ const parent = path.dirname(current);
330
+ if (parent === current)
331
+ break;
332
+ current = parent;
333
+ if ((0, directory_1.isInitialized)(current)) {
334
+ return current;
335
+ }
336
+ }
337
+ // Not found - return original path (will fail later with helpful error)
338
+ return absolutePath;
339
+ }
340
+ /**
341
+ * Format a number with commas
342
+ */
343
+ function formatNumber(n) {
344
+ return n.toLocaleString();
345
+ }
346
+ /**
347
+ * Format duration in milliseconds to human readable
348
+ */
349
+ function formatDuration(ms) {
350
+ if (ms < 1000) {
351
+ return `${ms}ms`;
352
+ }
353
+ const seconds = ms / 1000;
354
+ if (seconds < 60) {
355
+ return `${seconds.toFixed(1)}s`;
356
+ }
357
+ const minutes = Math.floor(seconds / 60);
358
+ const remainingSeconds = seconds % 60;
359
+ return `${minutes}m ${remainingSeconds.toFixed(0)}s`;
360
+ }
361
+ // Shimmer progress renderer (runs in a worker thread for smooth animation)
362
+ // Imported at top of file from '../ui/shimmer-progress'
363
+ /**
364
+ * Create a plain-text progress callback for --verbose mode.
365
+ * No animations, no ANSI tricks — just timestamped lines to stdout.
366
+ */
367
+ function createVerboseProgress() {
368
+ let lastPhase = '';
369
+ let lastPct = -1;
370
+ const startTime = Date.now();
371
+ return (progress) => {
372
+ const elapsed = ((Date.now() - startTime) / 1000).toFixed(1);
373
+ if (progress.phase !== lastPhase) {
374
+ lastPhase = progress.phase;
375
+ lastPct = -1;
376
+ console.log(`[${elapsed}s] Phase: ${progress.phase}`);
377
+ }
378
+ if (progress.total > 0) {
379
+ const pct = Math.floor((progress.current / progress.total) * 100);
380
+ // Log every 5% to keep output manageable
381
+ if (pct >= lastPct + 5 || progress.current === progress.total) {
382
+ lastPct = pct;
383
+ console.log(`[${elapsed}s] ${progress.current}/${progress.total} (${pct}%)${progress.currentFile ? ` ${(0, glyphs_1.getGlyphs)().dash} ${progress.currentFile}` : ''}`);
384
+ }
385
+ }
386
+ else if (progress.current > 0) {
387
+ // Scanning phase (no total yet) — log periodically
388
+ if (progress.current % 1000 === 0 || progress.current === 1) {
389
+ console.log(`[${elapsed}s] ${formatNumber(progress.current)} files found`);
390
+ }
391
+ }
392
+ };
393
+ }
394
+ /**
395
+ * Print success message
396
+ */
397
+ function success(message) {
398
+ console.log(chalk.green((0, glyphs_1.getGlyphs)().ok) + ' ' + message);
399
+ }
400
+ /**
401
+ * Print error message
402
+ */
403
+ function error(message) {
404
+ console.error(chalk.red((0, glyphs_1.getGlyphs)().err) + ' ' + message);
405
+ }
406
+ /**
407
+ * Print info message
408
+ */
409
+ function info(message) {
410
+ console.log(chalk.blue((0, glyphs_1.getGlyphs)().info) + ' ' + message);
411
+ }
412
+ /**
413
+ * Print warning message
414
+ */
415
+ function warn(message) {
416
+ console.log(chalk.yellow((0, glyphs_1.getGlyphs)().warn) + ' ' + message);
417
+ }
418
+ /**
419
+ * Print indexing results using clack log methods
420
+ */
421
+ function printIndexResult(clack, result, projectPath) {
422
+ const hasErrors = result.filesErrored > 0;
423
+ // Surface non-file-level failures (e.g. lock-acquisition failure
424
+ // when another indexer is running) before the file-count branches.
425
+ // Without this the CLI falls through to "No files found to index",
426
+ // which is actively misleading — the index DID run, it just couldn't
427
+ // get the lock.
428
+ //
429
+ // If success is false but no severity:'error' entry exists in
430
+ // `result.errors` (degenerate case — shouldn't happen in practice
431
+ // but worth guarding because the result shape is plumbed through
432
+ // multiple call sites), fall back to a generic message rather than
433
+ // continuing to the misleading "No files found" branch or throwing.
434
+ if (!result.success && !hasErrors && result.filesIndexed === 0) {
435
+ const generic = result.errors.find((e) => e.severity === 'error');
436
+ clack.log.error(generic?.message ?? `Indexing failed ${(0, glyphs_1.getGlyphs)().dash} no further details available`);
437
+ return;
438
+ }
439
+ if (result.filesIndexed > 0) {
440
+ if (hasErrors) {
441
+ clack.log.success(`Indexed ${formatNumber(result.filesIndexed)} files (${formatNumber(result.filesErrored)} could not be parsed)`);
442
+ }
443
+ else {
444
+ clack.log.success(`Indexed ${formatNumber(result.filesIndexed)} files`);
445
+ }
446
+ clack.log.info(`${formatNumber(result.nodesCreated)} nodes, ${formatNumber(result.edgesCreated)} edges in ${formatDuration(result.durationMs)}`);
447
+ }
448
+ else if (hasErrors) {
449
+ clack.log.error(`Indexing failed ${(0, glyphs_1.getGlyphs)().dash} all ${formatNumber(result.filesErrored)} files had errors`);
450
+ }
451
+ else {
452
+ clack.log.warn('No files found to index');
453
+ }
454
+ if (hasErrors) {
455
+ const errorsByCode = new Map();
456
+ for (const err of result.errors) {
457
+ if (err.severity === 'error') {
458
+ const code = err.code || 'unknown';
459
+ errorsByCode.set(code, (errorsByCode.get(code) || 0) + 1);
460
+ }
461
+ }
462
+ const codeLabels = {
463
+ parse_error: 'files failed to parse',
464
+ read_error: 'files could not be read',
465
+ size_exceeded: 'files exceeded size limit',
466
+ path_traversal: 'blocked paths',
467
+ unsupported_language: 'unsupported language',
468
+ parser_error: 'parser initialization failures',
469
+ };
470
+ const breakdown = Array.from(errorsByCode)
471
+ .map(([code, count]) => `${formatNumber(count)} ${codeLabels[code] || code}`)
472
+ .join('\n');
473
+ clack.note(breakdown, 'Error breakdown');
474
+ if (projectPath) {
475
+ writeErrorLog(projectPath, result.errors);
476
+ clack.log.info('See .specship/errors.log for details');
477
+ }
478
+ if (result.filesIndexed > 0) {
479
+ clack.log.info(`The index is fully usable ${(0, glyphs_1.getGlyphs)().dash} only the failed files are missing.`);
480
+ }
481
+ }
482
+ else if (projectPath) {
483
+ const logPath = path.join((0, directory_1.getSpecShipDir)(projectPath), 'errors.log');
484
+ if (fs.existsSync(logPath)) {
485
+ fs.unlinkSync(logPath);
486
+ }
487
+ }
488
+ }
489
+ /**
490
+ * Write detailed error log into the project's SpecShip data dir.
491
+ * Path follows whichever layout is active (home folder by default).
492
+ */
493
+ function writeErrorLog(projectPath, errors) {
494
+ const cgDir = (0, directory_1.getSpecShipDir)(projectPath);
495
+ if (!fs.existsSync(cgDir))
496
+ return;
497
+ const logPath = path.join(cgDir, 'errors.log');
498
+ // Group errors by file path
499
+ const errorsByFile = new Map();
500
+ const noFileErrors = [];
501
+ for (const err of errors) {
502
+ if (err.severity !== 'error')
503
+ continue;
504
+ if (err.filePath) {
505
+ let list = errorsByFile.get(err.filePath);
506
+ if (!list) {
507
+ list = [];
508
+ errorsByFile.set(err.filePath, list);
509
+ }
510
+ list.push({ message: err.message, code: err.code });
511
+ }
512
+ else {
513
+ noFileErrors.push({ message: err.message, code: err.code });
514
+ }
515
+ }
516
+ const lines = [
517
+ `SpecShip Error Log - ${new Date().toISOString()}`,
518
+ `${errorsByFile.size} files with errors`,
519
+ '',
520
+ ];
521
+ for (const [filePath, fileErrors] of errorsByFile) {
522
+ for (const err of fileErrors) {
523
+ lines.push(`${filePath}: ${err.message}`);
524
+ }
525
+ }
526
+ for (const err of noFileErrors) {
527
+ lines.push(err.message);
528
+ }
529
+ fs.writeFileSync(logPath, lines.join('\n') + '\n');
530
+ }
531
+ // =============================================================================
532
+ // Commands
533
+ // =============================================================================
534
+ /**
535
+ * specship init [path]
536
+ */
537
+ program
538
+ .command('init [path]')
539
+ .description('Initialize SpecShip in a project directory and build the initial index')
540
+ .option('-i, --index', 'Deprecated: indexing now runs by default; flag accepted for backward compatibility')
541
+ .option('-v, --verbose', 'Show detailed worker lifecycle and memory info')
542
+ .action(async (pathArg, options) => {
543
+ const projectPath = path.resolve(pathArg || process.cwd());
544
+ const clack = await importESM('@clack/prompts');
545
+ clack.intro('Initializing SpecShip');
546
+ try {
547
+ if ((0, directory_1.isInitialized)(projectPath)) {
548
+ clack.log.warn(`Already initialized in ${projectPath}`);
549
+ clack.log.info('Use "specship index" to re-index or "specship sync" to update');
550
+ try {
551
+ const { offerWatchFallback } = await Promise.resolve().then(() => __importStar(require('../installer')));
552
+ await offerWatchFallback(clack, projectPath);
553
+ }
554
+ catch { /* non-fatal */ }
555
+ clack.outro('');
556
+ return;
557
+ }
558
+ const { default: SpecShip } = await loadSpecShip();
559
+ const cg = await SpecShip.init(projectPath, { index: false });
560
+ clack.log.success(`Initialized in ${projectPath}`);
561
+ // Indexing runs by default now. The legacy -i/--index flag is still
562
+ // accepted (so existing muscle memory and scripts don't break) but is a
563
+ // no-op — initializing always builds the initial index.
564
+ let result;
565
+ if (options.verbose) {
566
+ result = await cg.indexAll({
567
+ onProgress: createVerboseProgress(),
568
+ verbose: true,
569
+ });
570
+ }
571
+ else {
572
+ process.stdout.write(`${colors.dim}${(0, glyphs_1.getGlyphs)().rail}${colors.reset}\n`);
573
+ const progress = (0, shimmer_progress_1.createShimmerProgress)();
574
+ result = await cg.indexAll({
575
+ onProgress: progress.onProgress,
576
+ });
577
+ await progress.stop();
578
+ }
579
+ printIndexResult(clack, result, projectPath);
580
+ try {
581
+ const { offerWatchFallback } = await Promise.resolve().then(() => __importStar(require('../installer')));
582
+ await offerWatchFallback(clack, projectPath);
583
+ }
584
+ catch { /* non-fatal */ }
585
+ clack.outro('Done');
586
+ cg.destroy();
587
+ }
588
+ catch (err) {
589
+ clack.log.error(`Failed: ${err instanceof Error ? err.message : String(err)}`);
590
+ process.exit(1);
591
+ }
592
+ });
593
+ /**
594
+ * specship uninit [path]
595
+ */
596
+ program
597
+ .command('uninit [path]')
598
+ .description('Remove SpecShip from a project (deletes .specship/ directory)')
599
+ .option('-f, --force', 'Skip confirmation prompt')
600
+ .action(async (pathArg, options) => {
601
+ const projectPath = resolveProjectPath(pathArg);
602
+ try {
603
+ if (!(0, directory_1.isInitialized)(projectPath)) {
604
+ warn(`SpecShip is not initialized in ${projectPath}`);
605
+ return;
606
+ }
607
+ if (!options.force) {
608
+ // Confirm with user
609
+ const readline = await Promise.resolve().then(() => __importStar(require('readline')));
610
+ const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
611
+ const answer = await new Promise((resolve) => {
612
+ rl.question(chalk.yellow(`${(0, glyphs_1.getGlyphs)().warn} This will permanently delete all SpecShip data. Continue? (y/N) `), resolve);
613
+ });
614
+ rl.close();
615
+ if (answer.toLowerCase() !== 'y') {
616
+ info('Cancelled');
617
+ return;
618
+ }
619
+ }
620
+ const { default: SpecShip } = await loadSpecShip();
621
+ const cg = SpecShip.openSync(projectPath);
622
+ cg.uninitialize();
623
+ // Clean up any git sync hooks we installed (no-op if none / not a repo).
624
+ try {
625
+ const { removeGitSyncHook } = await Promise.resolve().then(() => __importStar(require('../sync/git-hooks')));
626
+ const removed = removeGitSyncHook(projectPath);
627
+ if (removed.installed.length > 0) {
628
+ info(`Removed git ${removed.installed.join(', ')} sync hook${removed.installed.length > 1 ? 's' : ''}`);
629
+ }
630
+ }
631
+ catch { /* non-fatal */ }
632
+ success(`Removed SpecShip from ${projectPath}`);
633
+ }
634
+ catch (err) {
635
+ error(`Failed to uninitialize: ${err instanceof Error ? err.message : String(err)}`);
636
+ process.exit(1);
637
+ }
638
+ });
639
+ /**
640
+ * specship index [path]
641
+ */
642
+ program
643
+ .command('index [path]')
644
+ .description('Index all files in the project')
645
+ .option('-f, --force', 'Force full re-index even if already indexed')
646
+ .option('-q, --quiet', 'Suppress progress output')
647
+ .option('-v, --verbose', 'Show detailed worker lifecycle and memory info')
648
+ .action(async (pathArg, options) => {
649
+ const projectPath = resolveProjectPath(pathArg);
650
+ try {
651
+ if (!(0, directory_1.isInitialized)(projectPath)) {
652
+ error(`SpecShip not initialized in ${projectPath}`);
653
+ info('Run "specship init" first');
654
+ process.exit(1);
655
+ }
656
+ const { default: SpecShip } = await loadSpecShip();
657
+ const cg = await SpecShip.open(projectPath);
658
+ if (options.quiet) {
659
+ // Quiet mode: no UI, just run
660
+ if (options.force)
661
+ cg.clear();
662
+ const result = await cg.indexAll();
663
+ if (!result.success)
664
+ process.exit(1);
665
+ cg.destroy();
666
+ return;
667
+ }
668
+ const clack = await importESM('@clack/prompts');
669
+ clack.intro('Indexing project');
670
+ if (options.force) {
671
+ cg.clear();
672
+ clack.log.info('Cleared existing index');
673
+ }
674
+ let result;
675
+ if (options.verbose) {
676
+ result = await cg.indexAll({
677
+ onProgress: createVerboseProgress(),
678
+ verbose: true,
679
+ });
680
+ }
681
+ else {
682
+ process.stdout.write(`${colors.dim}${(0, glyphs_1.getGlyphs)().rail}${colors.reset}\n`);
683
+ const progress = (0, shimmer_progress_1.createShimmerProgress)();
684
+ result = await cg.indexAll({
685
+ onProgress: progress.onProgress,
686
+ });
687
+ await progress.stop();
688
+ }
689
+ printIndexResult(clack, result, projectPath);
690
+ if (!result.success) {
691
+ process.exit(1);
692
+ }
693
+ clack.outro('Done');
694
+ cg.destroy();
695
+ }
696
+ catch (err) {
697
+ error(`Failed to index: ${err instanceof Error ? err.message : String(err)}`);
698
+ process.exit(1);
699
+ }
700
+ });
701
+ /**
702
+ * specship sync [path]
703
+ */
704
+ program
705
+ .command('sync [path]')
706
+ .description('Sync changes since last index')
707
+ .option('-q, --quiet', 'Suppress output (for git hooks)')
708
+ .action(async (pathArg, options) => {
709
+ const projectPath = resolveProjectPath(pathArg);
710
+ try {
711
+ if (!(0, directory_1.isInitialized)(projectPath)) {
712
+ if (!options.quiet) {
713
+ error(`SpecShip not initialized in ${projectPath}`);
714
+ }
715
+ process.exit(1);
716
+ }
717
+ const { default: SpecShip } = await loadSpecShip();
718
+ const cg = await SpecShip.open(projectPath);
719
+ if (options.quiet) {
720
+ await cg.sync();
721
+ cg.destroy();
722
+ return;
723
+ }
724
+ const clack = await importESM('@clack/prompts');
725
+ clack.intro('Syncing SpecShip');
726
+ process.stdout.write(`${colors.dim}${(0, glyphs_1.getGlyphs)().rail}${colors.reset}\n`);
727
+ const progress = (0, shimmer_progress_1.createShimmerProgress)();
728
+ const result = await cg.sync({
729
+ onProgress: progress.onProgress,
730
+ });
731
+ await progress.stop();
732
+ const totalChanges = result.filesAdded + result.filesModified + result.filesRemoved;
733
+ if (totalChanges === 0) {
734
+ clack.log.info('Already up to date');
735
+ }
736
+ else {
737
+ clack.log.success(`Synced ${formatNumber(totalChanges)} changed files`);
738
+ const details = [];
739
+ if (result.filesAdded > 0)
740
+ details.push(`Added: ${result.filesAdded}`);
741
+ if (result.filesModified > 0)
742
+ details.push(`Modified: ${result.filesModified}`);
743
+ if (result.filesRemoved > 0)
744
+ details.push(`Removed: ${result.filesRemoved}`);
745
+ clack.log.info(`${details.join(', ')} ${(0, glyphs_1.getGlyphs)().dash} ${formatNumber(result.nodesUpdated)} nodes in ${formatDuration(result.durationMs)}`);
746
+ }
747
+ clack.outro('Done');
748
+ cg.destroy();
749
+ }
750
+ catch (err) {
751
+ if (!options.quiet) {
752
+ error(`Failed to sync: ${err instanceof Error ? err.message : String(err)}`);
753
+ }
754
+ process.exit(1);
755
+ }
756
+ });
757
+ /**
758
+ * specship status [path]
759
+ */
760
+ program
761
+ .command('status [path]')
762
+ .description('Show index status and statistics')
763
+ .option('-j, --json', 'Output as JSON')
764
+ .action(async (pathArg, options) => {
765
+ const projectPath = resolveProjectPath(pathArg);
766
+ // The directory the user actually ran from, before walking up to the index
767
+ // root. Used to detect when the resolved index lives in a different git
768
+ // working tree (e.g. a nested worktree borrowing the main checkout's index).
769
+ const startPath = path.resolve(pathArg || process.cwd());
770
+ const worktreeMismatch = (0, worktree_1.detectWorktreeIndexMismatch)(startPath, projectPath);
771
+ try {
772
+ if (!(0, directory_1.isInitialized)(projectPath)) {
773
+ if (options.json) {
774
+ console.log(JSON.stringify({
775
+ initialized: false,
776
+ version: packageJson.version,
777
+ projectPath,
778
+ indexPath: (0, directory_1.getSpecShipDir)(projectPath),
779
+ lastIndexed: null,
780
+ }));
781
+ return;
782
+ }
783
+ console.log(chalk.bold('\nSpecShip Status\n'));
784
+ info(`Project: ${projectPath}`);
785
+ warn('Not initialized');
786
+ info('Run "specship init" to initialize');
787
+ return;
788
+ }
789
+ const { default: SpecShip } = await loadSpecShip();
790
+ const cg = await SpecShip.open(projectPath);
791
+ const stats = cg.getStats();
792
+ const changes = cg.getChangedFiles();
793
+ const backend = cg.getBackend();
794
+ const journalMode = cg.getJournalMode();
795
+ // JSON output mode
796
+ if (options.json) {
797
+ const lastIndexedMs = cg.getLastIndexedAt();
798
+ console.log(JSON.stringify({
799
+ initialized: true,
800
+ version: packageJson.version,
801
+ projectPath,
802
+ indexPath: (0, directory_1.getSpecShipDir)(projectPath),
803
+ lastIndexed: lastIndexedMs != null ? new Date(lastIndexedMs).toISOString() : null,
804
+ fileCount: stats.fileCount,
805
+ nodeCount: stats.nodeCount,
806
+ edgeCount: stats.edgeCount,
807
+ dbSizeBytes: stats.dbSizeBytes,
808
+ backend,
809
+ journalMode,
810
+ nodesByKind: stats.nodesByKind,
811
+ languages: Object.entries(stats.filesByLanguage).filter(([, count]) => count > 0).map(([lang]) => lang),
812
+ pendingChanges: {
813
+ added: changes.added.length,
814
+ modified: changes.modified.length,
815
+ removed: changes.removed.length,
816
+ },
817
+ worktreeMismatch: worktreeMismatch
818
+ ? { worktreeRoot: worktreeMismatch.worktreeRoot, indexRoot: worktreeMismatch.indexRoot }
819
+ : null,
820
+ }));
821
+ cg.destroy();
822
+ return;
823
+ }
824
+ console.log(chalk.bold('\nSpecShip Status\n'));
825
+ // Project info
826
+ console.log(chalk.cyan('Project:'), projectPath);
827
+ if (worktreeMismatch) {
828
+ warn((0, worktree_1.worktreeMismatchWarning)(worktreeMismatch));
829
+ }
830
+ console.log();
831
+ // Index stats
832
+ console.log(chalk.bold('Index Statistics:'));
833
+ console.log(` Files: ${formatNumber(stats.fileCount)}`);
834
+ console.log(` Nodes: ${formatNumber(stats.nodeCount)}`);
835
+ console.log(` Edges: ${formatNumber(stats.edgeCount)}`);
836
+ console.log(` DB Size: ${(stats.dbSizeBytes / 1024 / 1024).toFixed(2)} MB`);
837
+ // Surface the active SQLite backend. Two paths:
838
+ // - 'node-sqlite' → Node's built-in module (production: bundled Node 24 has FTS5).
839
+ // - 'better-sqlite3' → optional devDep that ships its own SQLite with FTS5.
840
+ const backendLabel = backend === 'better-sqlite3'
841
+ ? chalk.green(`better-sqlite3 ${(0, glyphs_1.getGlyphs)().dash} ships its own SQLite (FTS5)`)
842
+ : chalk.green(`node:sqlite ${(0, glyphs_1.getGlyphs)().dash} built-in (full WAL)`);
843
+ console.log(` Backend: ${backendLabel}`);
844
+ // Effective journal mode: 'wal' means concurrent reads never block on a
845
+ // writer; anything else means they can ("database is locked"). node:sqlite
846
+ // supports WAL everywhere, so a non-wal mode means the filesystem can't
847
+ // (network mounts, WSL2 /mnt). See issue #238.
848
+ const journalLabel = journalMode === 'wal'
849
+ ? chalk.green('wal')
850
+ : chalk.yellow(`${journalMode || 'unknown'} ${(0, glyphs_1.getGlyphs)().dash} WAL inactive; reads can block on writes`);
851
+ console.log(` Journal: ${journalLabel}`);
852
+ console.log();
853
+ // Node breakdown
854
+ console.log(chalk.bold('Nodes by Kind:'));
855
+ const nodesByKind = Object.entries(stats.nodesByKind)
856
+ .filter(([, count]) => count > 0)
857
+ .sort((a, b) => b[1] - a[1]);
858
+ for (const [kind, count] of nodesByKind) {
859
+ console.log(` ${kind.padEnd(15)} ${formatNumber(count)}`);
860
+ }
861
+ console.log();
862
+ // Language breakdown
863
+ console.log(chalk.bold('Files by Language:'));
864
+ const filesByLang = Object.entries(stats.filesByLanguage)
865
+ .filter(([, count]) => count > 0)
866
+ .sort((a, b) => b[1] - a[1]);
867
+ for (const [lang, count] of filesByLang) {
868
+ console.log(` ${lang.padEnd(15)} ${formatNumber(count)}`);
869
+ }
870
+ console.log();
871
+ // Pending changes
872
+ const totalChanges = changes.added.length + changes.modified.length + changes.removed.length;
873
+ if (totalChanges > 0) {
874
+ console.log(chalk.bold('Pending Changes:'));
875
+ if (changes.added.length > 0) {
876
+ console.log(` Added: ${changes.added.length} files`);
877
+ }
878
+ if (changes.modified.length > 0) {
879
+ console.log(` Modified: ${changes.modified.length} files`);
880
+ }
881
+ if (changes.removed.length > 0) {
882
+ console.log(` Removed: ${changes.removed.length} files`);
883
+ }
884
+ info('Run "specship sync" to update the index');
885
+ }
886
+ else {
887
+ success('Index is up to date');
888
+ }
889
+ console.log();
890
+ cg.destroy();
891
+ }
892
+ catch (err) {
893
+ error(`Failed to get status: ${err instanceof Error ? err.message : String(err)}`);
894
+ process.exit(1);
895
+ }
896
+ });
897
+ /**
898
+ * specship query <search>
899
+ */
900
+ program
901
+ .command('query <search>')
902
+ .description('Search for symbols in the codebase')
903
+ .option('-p, --path <path>', 'Project path')
904
+ .option('-l, --limit <number>', 'Maximum results', '10')
905
+ .option('-k, --kind <kind>', 'Filter by node kind (function, class, etc.)')
906
+ .option('-j, --json', 'Output as JSON')
907
+ .action(async (search, options) => {
908
+ const projectPath = resolveProjectPath(options.path);
909
+ try {
910
+ if (!(0, directory_1.isInitialized)(projectPath)) {
911
+ error(`SpecShip not initialized in ${projectPath}`);
912
+ process.exit(1);
913
+ }
914
+ const { default: SpecShip } = await loadSpecShip();
915
+ const cg = await SpecShip.open(projectPath);
916
+ const limit = parseInt(options.limit || '10', 10);
917
+ const rawResults = cg.searchNodes(search, {
918
+ limit,
919
+ kinds: options.kind ? [options.kind] : undefined,
920
+ });
921
+ // Mirror the MCP search down-rank so the CLI also surfaces the
922
+ // hand-written implementation before protobuf/gRPC scaffolding
923
+ // when both share a name. See extraction/generated-detection.ts.
924
+ const { isGeneratedFile } = await Promise.resolve().then(() => __importStar(require('../extraction/generated-detection')));
925
+ const results = [...rawResults].sort((a, b) => {
926
+ const aGen = isGeneratedFile(a.node.filePath) ? 1 : 0;
927
+ const bGen = isGeneratedFile(b.node.filePath) ? 1 : 0;
928
+ return aGen - bGen;
929
+ });
930
+ if (options.json) {
931
+ console.log(JSON.stringify(results, null, 2));
932
+ }
933
+ else {
934
+ if (results.length === 0) {
935
+ info(`No results found for "${search}"`);
936
+ }
937
+ else {
938
+ console.log(chalk.bold(`\nSearch Results for "${search}":\n`));
939
+ for (const result of results) {
940
+ const node = result.node;
941
+ const location = `${node.filePath}:${node.startLine}`;
942
+ const score = chalk.dim(`(${(result.score * 100).toFixed(0)}%)`);
943
+ console.log(chalk.cyan(node.kind.padEnd(12)) +
944
+ chalk.white(node.name) +
945
+ ' ' + score);
946
+ console.log(chalk.dim(` ${location}`));
947
+ if (node.signature) {
948
+ console.log(chalk.dim(` ${node.signature}`));
949
+ }
950
+ console.log();
951
+ }
952
+ }
953
+ }
954
+ cg.destroy();
955
+ }
956
+ catch (err) {
957
+ error(`Search failed: ${err instanceof Error ? err.message : String(err)}`);
958
+ process.exit(1);
959
+ }
960
+ });
961
+ /**
962
+ * specship files [path]
963
+ */
964
+ program
965
+ .command('files')
966
+ .description('Show project file structure from the index')
967
+ .option('-p, --path <path>', 'Project path')
968
+ .option('--filter <dir>', 'Filter to files under this directory')
969
+ .option('--pattern <glob>', 'Filter files matching this glob pattern')
970
+ .option('--format <format>', 'Output format (tree, flat, grouped)', 'tree')
971
+ .option('--max-depth <number>', 'Maximum directory depth for tree format')
972
+ .option('--no-metadata', 'Hide file metadata (language, symbol count)')
973
+ .option('-j, --json', 'Output as JSON')
974
+ .action(async (options) => {
975
+ const projectPath = resolveProjectPath(options.path);
976
+ try {
977
+ if (!(0, directory_1.isInitialized)(projectPath)) {
978
+ error(`SpecShip not initialized in ${projectPath}`);
979
+ process.exit(1);
980
+ }
981
+ const { default: SpecShip } = await loadSpecShip();
982
+ const cg = await SpecShip.open(projectPath);
983
+ let files = cg.getFiles();
984
+ if (files.length === 0) {
985
+ info('No files indexed. Run "specship index" first.');
986
+ cg.destroy();
987
+ return;
988
+ }
989
+ // Filter by path prefix
990
+ if (options.filter) {
991
+ const filter = options.filter;
992
+ files = files.filter(f => f.path.startsWith(filter) || f.path.startsWith('./' + filter));
993
+ }
994
+ // Filter by glob pattern
995
+ if (options.pattern) {
996
+ const regex = globToRegex(options.pattern);
997
+ files = files.filter(f => regex.test(f.path));
998
+ }
999
+ if (files.length === 0) {
1000
+ info('No files found matching the criteria.');
1001
+ cg.destroy();
1002
+ return;
1003
+ }
1004
+ // JSON output
1005
+ if (options.json) {
1006
+ const output = files.map(f => ({
1007
+ path: f.path,
1008
+ language: f.language,
1009
+ nodeCount: f.nodeCount,
1010
+ size: f.size,
1011
+ }));
1012
+ console.log(JSON.stringify(output, null, 2));
1013
+ cg.destroy();
1014
+ return;
1015
+ }
1016
+ const includeMetadata = options.metadata !== false;
1017
+ const format = options.format || 'tree';
1018
+ const maxDepth = options.maxDepth ? parseInt(options.maxDepth, 10) : undefined;
1019
+ // Format output
1020
+ switch (format) {
1021
+ case 'flat':
1022
+ console.log(chalk.bold(`\nFiles (${files.length}):\n`));
1023
+ for (const file of files.sort((a, b) => a.path.localeCompare(b.path))) {
1024
+ if (includeMetadata) {
1025
+ console.log(` ${file.path} ${chalk.dim(`(${file.language}, ${file.nodeCount} symbols)`)}`);
1026
+ }
1027
+ else {
1028
+ console.log(` ${file.path}`);
1029
+ }
1030
+ }
1031
+ break;
1032
+ case 'grouped':
1033
+ console.log(chalk.bold(`\nFiles by Language (${files.length} total):\n`));
1034
+ const byLang = new Map();
1035
+ for (const file of files) {
1036
+ const existing = byLang.get(file.language) || [];
1037
+ existing.push(file);
1038
+ byLang.set(file.language, existing);
1039
+ }
1040
+ const sortedLangs = [...byLang.entries()].sort((a, b) => b[1].length - a[1].length);
1041
+ for (const [lang, langFiles] of sortedLangs) {
1042
+ console.log(chalk.cyan(`${lang} (${langFiles.length}):`));
1043
+ for (const file of langFiles.sort((a, b) => a.path.localeCompare(b.path))) {
1044
+ if (includeMetadata) {
1045
+ console.log(` ${file.path} ${chalk.dim(`(${file.nodeCount} symbols)`)}`);
1046
+ }
1047
+ else {
1048
+ console.log(` ${file.path}`);
1049
+ }
1050
+ }
1051
+ console.log();
1052
+ }
1053
+ break;
1054
+ case 'tree':
1055
+ default:
1056
+ console.log(chalk.bold(`\nProject Structure (${files.length} files):\n`));
1057
+ printFileTree(files, includeMetadata, maxDepth, chalk);
1058
+ break;
1059
+ }
1060
+ console.log();
1061
+ cg.destroy();
1062
+ }
1063
+ catch (err) {
1064
+ error(`Failed to list files: ${err instanceof Error ? err.message : String(err)}`);
1065
+ process.exit(1);
1066
+ }
1067
+ });
1068
+ /**
1069
+ * Convert glob pattern to regex
1070
+ */
1071
+ function globToRegex(pattern) {
1072
+ const escaped = pattern
1073
+ .replace(/[.+^${}()|[\]\\]/g, '\\$&')
1074
+ .replace(/\*\*/g, '{{GLOBSTAR}}')
1075
+ .replace(/\*/g, '[^/]*')
1076
+ .replace(/\?/g, '[^/]')
1077
+ .replace(/\{\{GLOBSTAR\}\}/g, '.*');
1078
+ return new RegExp(escaped);
1079
+ }
1080
+ /**
1081
+ * Print files as a tree
1082
+ */
1083
+ function printFileTree(files, includeMetadata, maxDepth, chalk) {
1084
+ const root = { name: '', children: new Map() };
1085
+ for (const file of files) {
1086
+ const parts = file.path.split('/');
1087
+ let current = root;
1088
+ for (let i = 0; i < parts.length; i++) {
1089
+ const part = parts[i];
1090
+ if (!part)
1091
+ continue;
1092
+ if (!current.children.has(part)) {
1093
+ current.children.set(part, { name: part, children: new Map() });
1094
+ }
1095
+ current = current.children.get(part);
1096
+ if (i === parts.length - 1) {
1097
+ current.file = { language: file.language, nodeCount: file.nodeCount };
1098
+ }
1099
+ }
1100
+ }
1101
+ const renderNode = (node, prefix, isLast, depth) => {
1102
+ if (maxDepth !== undefined && depth > maxDepth)
1103
+ return;
1104
+ const glyphs = (0, glyphs_1.getGlyphs)();
1105
+ const connector = isLast ? glyphs.treeLast : glyphs.treeBranch;
1106
+ const childPrefix = isLast ? ' ' : glyphs.treePipe;
1107
+ if (node.name) {
1108
+ let line = prefix + connector + node.name;
1109
+ if (node.file && includeMetadata) {
1110
+ line += chalk.dim(` (${node.file.language}, ${node.file.nodeCount} symbols)`);
1111
+ }
1112
+ console.log(line);
1113
+ }
1114
+ const children = [...node.children.values()];
1115
+ children.sort((a, b) => {
1116
+ const aIsDir = a.children.size > 0 && !a.file;
1117
+ const bIsDir = b.children.size > 0 && !b.file;
1118
+ if (aIsDir !== bIsDir)
1119
+ return aIsDir ? -1 : 1;
1120
+ return a.name.localeCompare(b.name);
1121
+ });
1122
+ for (let i = 0; i < children.length; i++) {
1123
+ const child = children[i];
1124
+ const nextPrefix = node.name ? prefix + childPrefix : prefix;
1125
+ renderNode(child, nextPrefix, i === children.length - 1, depth + 1);
1126
+ }
1127
+ };
1128
+ renderNode(root, '', true, 0);
1129
+ }
1130
+ /**
1131
+ * specship serve
1132
+ */
1133
+ program
1134
+ .command('serve')
1135
+ .description('Start SpecShip as an MCP server for AI assistants, an HTTP API for the desktop UI, or both')
1136
+ .option('-p, --path <path>', 'Project path (optional for MCP mode, uses rootUri from client)')
1137
+ .option('--mcp', 'Run as MCP server (stdio transport)')
1138
+ .option('--ui', 'Run as HTTP API server for the SpecShip Desktop UI (binds 127.0.0.1)')
1139
+ .option('--port <n>', 'HTTP port when --ui is set (default 4242)')
1140
+ .option('--host <h>', 'HTTP bind host when --ui is set (default 127.0.0.1)')
1141
+ .option('--ingest', 'Enable Claude Code JSONL transcript watcher (only when --ui is set)')
1142
+ .option('--web-dir <path>', 'Path to a built Angular UI (index.html lives here); auto-detected by default')
1143
+ .option('--no-web', 'Run --ui headless (API only, no SPA)')
1144
+ .option('--no-watch', 'Disable the file watcher (no auto-sync; useful on slow filesystems like WSL2 /mnt drives)')
1145
+ .action(async (options) => {
1146
+ const projectPath = options.path ? resolveProjectPath(options.path) : undefined;
1147
+ // Commander sets watch=false when --no-watch is passed. Route it through
1148
+ // the same env-var chokepoint the watcher and MCP server already honor.
1149
+ if (options.watch === false) {
1150
+ process.env.SPECSHIP_NO_WATCH = '1';
1151
+ }
1152
+ try {
1153
+ if (options.ui) {
1154
+ // HTTP API mode. Boots the specship server + optional JSONL
1155
+ // ingest watcher. Optionally also starts MCP stdio in parallel.
1156
+ //
1157
+ // Project root resolution:
1158
+ // 1. `-p <path>` if passed.
1159
+ // 2. The current cwd if it has been `specship init`-ed.
1160
+ // 3. Most-recently-touched initialized project under
1161
+ // ~/.claude/projects/ — so a user who runs `specship serve --ui`
1162
+ // from anywhere lands on the project they were last active in.
1163
+ // 4. None — server boots projectless, the desktop picker prompts
1164
+ // the user to choose one (analytics endpoints return 409 until
1165
+ // a primary exists).
1166
+ let root = null;
1167
+ if (projectPath) {
1168
+ root = projectPath;
1169
+ if (!(0, directory_1.isInitialized)(root)) {
1170
+ error(`SpecShip not initialized in ${root}. Run \`specship init -i\` first.`);
1171
+ process.exit(1);
1172
+ }
1173
+ }
1174
+ else if ((0, directory_1.isInitialized)(process.cwd())) {
1175
+ root = process.cwd();
1176
+ }
1177
+ else {
1178
+ root = await pickRecentInitializedProject();
1179
+ }
1180
+ const port = options.port ? parseInt(options.port, 10) : 4242;
1181
+ const host = options.host ?? '127.0.0.1';
1182
+ // Lazy-load the server package via dist path. The npm bin is
1183
+ // packaged with the server already built under
1184
+ // node_modules/@selvakumaresra/specship-server, OR (dev) the
1185
+ // sibling packages/server/dist directory.
1186
+ const { createServer } = await loadServerPackage();
1187
+ // Locate the built Angular UI so the same port serves the SPA at /.
1188
+ // `--no-web` opts out (Commander sets web=false then). Otherwise we
1189
+ // try the explicit --web-dir, then auto-detect.
1190
+ const webDir = options.web === false ? null : locateWebDir(options.webDir ?? null);
1191
+ // The JSONL ingest watcher now starts in-process inside createServer
1192
+ // when `ingest: true`. The server owns its lifecycle; CLI just toggles.
1193
+ const handle = await createServer({
1194
+ projectRoot: root ?? undefined,
1195
+ host,
1196
+ port,
1197
+ ingest: options.ingest !== false,
1198
+ webDir,
1199
+ verbose: false,
1200
+ });
1201
+ console.error(chalk.bold('\nSpecShip Desktop server\n'));
1202
+ console.error(chalk.green((0, glyphs_1.getGlyphs)().ok) + ` HTTP API: ${handle.url}`);
1203
+ if (root) {
1204
+ console.error(chalk.dim(` project: ${root}`));
1205
+ }
1206
+ else {
1207
+ console.error(chalk.yellow((0, glyphs_1.getGlyphs)().warn) + ' no primary project — pick one in the desktop UI');
1208
+ console.error(chalk.dim(' analytics endpoints will return 409 until one is selected'));
1209
+ }
1210
+ if (webDir) {
1211
+ console.error(chalk.green((0, glyphs_1.getGlyphs)().ok) + ` SPA: ${handle.url}/ (from ${webDir})`);
1212
+ }
1213
+ else if (options.web !== false) {
1214
+ console.error(chalk.yellow((0, glyphs_1.getGlyphs)().warn) + ' UI not found — running API-only.');
1215
+ console.error(chalk.dim(' Build it first: cd packages/server && npm run build:all'));
1216
+ }
1217
+ if (options.ingest !== false) {
1218
+ console.error(chalk.dim(' Claude Code transcript ingest watcher active'));
1219
+ }
1220
+ if (options.mcp) {
1221
+ if (!root) {
1222
+ console.error(chalk.yellow((0, glyphs_1.getGlyphs)().warn) + ' --mcp needs an initialized project — skipping MCP stdio');
1223
+ }
1224
+ else {
1225
+ // Also start MCP stdio in this process. The two are unrelated
1226
+ // surfaces hitting the same specship instance, both safe under WAL.
1227
+ const { MCPServer } = await Promise.resolve().then(() => __importStar(require('../mcp/index')));
1228
+ const mcp = new MCPServer(root);
1229
+ void mcp.start();
1230
+ console.error(chalk.green((0, glyphs_1.getGlyphs)().ok) + ' MCP stdio: running');
1231
+ }
1232
+ }
1233
+ const shutdown = async () => {
1234
+ console.error(chalk.dim('shutting down…'));
1235
+ await handle.stop();
1236
+ process.exit(0);
1237
+ };
1238
+ process.on('SIGINT', () => { void shutdown(); });
1239
+ process.on('SIGTERM', () => { void shutdown(); });
1240
+ // Server now runs until terminated.
1241
+ return;
1242
+ }
1243
+ if (options.mcp) {
1244
+ // Start MCP server - it handles initialization lazily based on rootUri from client
1245
+ const { MCPServer } = await Promise.resolve().then(() => __importStar(require('../mcp/index')));
1246
+ const server = new MCPServer(projectPath);
1247
+ await server.start();
1248
+ // Server will run until terminated
1249
+ }
1250
+ else {
1251
+ // Default: show info about MCP mode.
1252
+ // Use stderr so stdout stays clean for any piped/stdio usage.
1253
+ console.error(chalk.bold('\nSpecShip MCP Server\n'));
1254
+ console.error(chalk.blue((0, glyphs_1.getGlyphs)().info) + ' Use --mcp flag to start the MCP server');
1255
+ console.error('\nTo use with Claude Code, add to your MCP configuration:');
1256
+ console.error(chalk.dim(`
1257
+ {
1258
+ "mcpServers": {
1259
+ "specship": {
1260
+ "command": "specship",
1261
+ "args": ["serve", "--mcp"]
1262
+ }
1263
+ }
1264
+ }
1265
+ `));
1266
+ console.error('Available tools:');
1267
+ console.error(chalk.cyan(' specship_explore') + ' - Primary: source of the relevant symbols for any question');
1268
+ console.error(chalk.cyan(' specship_search') + ' - Search for code symbols');
1269
+ console.error(chalk.cyan(' specship_callers') + ' - Find callers of a symbol');
1270
+ console.error(chalk.cyan(' specship_callees') + ' - Find what a symbol calls');
1271
+ console.error(chalk.cyan(' specship_impact') + ' - Analyze impact of changes');
1272
+ console.error(chalk.cyan(' specship_node') + ' - Get symbol details');
1273
+ console.error(chalk.cyan(' specship_files') + ' - Get project file structure');
1274
+ console.error(chalk.cyan(' specship_status') + ' - Get index status');
1275
+ }
1276
+ }
1277
+ catch (err) {
1278
+ error(`Failed to start server: ${err instanceof Error ? err.message : String(err)}`);
1279
+ process.exit(1);
1280
+ }
1281
+ });
1282
+ /**
1283
+ * specship unlock [path]
1284
+ */
1285
+ program
1286
+ .command('unlock [path]')
1287
+ .description('Remove a stale lock file that is blocking indexing')
1288
+ .action(async (pathArg) => {
1289
+ const projectPath = resolveProjectPath(pathArg);
1290
+ try {
1291
+ if (!(0, directory_1.isInitialized)(projectPath)) {
1292
+ error(`SpecShip not initialized in ${projectPath}`);
1293
+ return;
1294
+ }
1295
+ const lockPath = path.join((0, directory_1.getSpecShipDir)(projectPath), 'specship.lock');
1296
+ if (!fs.existsSync(lockPath)) {
1297
+ info(`No lock file found ${(0, glyphs_1.getGlyphs)().dash} nothing to do`);
1298
+ return;
1299
+ }
1300
+ fs.unlinkSync(lockPath);
1301
+ success('Removed lock file. You can now run indexing again.');
1302
+ }
1303
+ catch (err) {
1304
+ error(`Failed to remove lock: ${err instanceof Error ? err.message : String(err)}`);
1305
+ process.exit(1);
1306
+ }
1307
+ });
1308
+ /**
1309
+ * specship callers <symbol>
1310
+ *
1311
+ * CLI parity with the MCP graph tools (specship_callers/callees/impact) so the
1312
+ * traversal queries work in scripts, CI, and git hooks without a running MCP
1313
+ * server.
1314
+ */
1315
+ program
1316
+ .command('callers <symbol>')
1317
+ .description('Find all functions/methods that call a specific symbol')
1318
+ .option('-p, --path <path>', 'Project path')
1319
+ .option('-l, --limit <number>', 'Maximum results', '20')
1320
+ .option('-j, --json', 'Output as JSON')
1321
+ .action(async (symbol, options) => {
1322
+ const projectPath = resolveProjectPath(options.path);
1323
+ try {
1324
+ if (!(0, directory_1.isInitialized)(projectPath)) {
1325
+ error(`SpecShip not initialized in ${projectPath}`);
1326
+ process.exit(1);
1327
+ }
1328
+ const { default: SpecShip } = await loadSpecShip();
1329
+ const cg = await SpecShip.open(projectPath);
1330
+ const limit = parseInt(options.limit || '20', 10);
1331
+ const matches = cg.searchNodes(symbol, { limit: 50 });
1332
+ if (matches.length === 0) {
1333
+ info(`Symbol "${symbol}" not found`);
1334
+ cg.destroy();
1335
+ return;
1336
+ }
1337
+ const seen = new Set();
1338
+ const allCallers = [];
1339
+ for (const match of matches) {
1340
+ const exactMatch = match.node.name === symbol || match.node.name.endsWith(`.${symbol}`) || match.node.name.endsWith(`::${symbol}`);
1341
+ if (!exactMatch && matches.length > 1)
1342
+ continue;
1343
+ for (const c of cg.getCallers(match.node.id)) {
1344
+ if (!seen.has(c.node.id)) {
1345
+ seen.add(c.node.id);
1346
+ allCallers.push({ name: c.node.name, kind: c.node.kind, filePath: c.node.filePath, startLine: c.node.startLine });
1347
+ }
1348
+ }
1349
+ }
1350
+ // Fallback: if exact filter removed everything, use the top match
1351
+ if (allCallers.length === 0 && matches[0]) {
1352
+ for (const c of cg.getCallers(matches[0].node.id)) {
1353
+ if (!seen.has(c.node.id)) {
1354
+ seen.add(c.node.id);
1355
+ allCallers.push({ name: c.node.name, kind: c.node.kind, filePath: c.node.filePath, startLine: c.node.startLine });
1356
+ }
1357
+ }
1358
+ }
1359
+ const limited = allCallers.slice(0, limit);
1360
+ if (options.json) {
1361
+ console.log(JSON.stringify({ symbol, callers: limited }, null, 2));
1362
+ }
1363
+ else if (limited.length === 0) {
1364
+ info(`No callers found for "${symbol}"`);
1365
+ }
1366
+ else {
1367
+ console.log(chalk.bold(`\nCallers of "${symbol}" (${limited.length}):\n`));
1368
+ for (const node of limited) {
1369
+ const loc = node.startLine ? `:${node.startLine}` : '';
1370
+ console.log(chalk.cyan(node.kind.padEnd(12)) +
1371
+ chalk.white(node.name));
1372
+ console.log(chalk.dim(` ${node.filePath}${loc}`));
1373
+ console.log();
1374
+ }
1375
+ }
1376
+ cg.destroy();
1377
+ }
1378
+ catch (err) {
1379
+ error(`callers failed: ${err instanceof Error ? err.message : String(err)}`);
1380
+ process.exit(1);
1381
+ }
1382
+ });
1383
+ /**
1384
+ * specship callees <symbol>
1385
+ */
1386
+ program
1387
+ .command('callees <symbol>')
1388
+ .description('Find all functions/methods that a specific symbol calls')
1389
+ .option('-p, --path <path>', 'Project path')
1390
+ .option('-l, --limit <number>', 'Maximum results', '20')
1391
+ .option('-j, --json', 'Output as JSON')
1392
+ .action(async (symbol, options) => {
1393
+ const projectPath = resolveProjectPath(options.path);
1394
+ try {
1395
+ if (!(0, directory_1.isInitialized)(projectPath)) {
1396
+ error(`SpecShip not initialized in ${projectPath}`);
1397
+ process.exit(1);
1398
+ }
1399
+ const { default: SpecShip } = await loadSpecShip();
1400
+ const cg = await SpecShip.open(projectPath);
1401
+ const limit = parseInt(options.limit || '20', 10);
1402
+ const matches = cg.searchNodes(symbol, { limit: 50 });
1403
+ if (matches.length === 0) {
1404
+ info(`Symbol "${symbol}" not found`);
1405
+ cg.destroy();
1406
+ return;
1407
+ }
1408
+ const seen = new Set();
1409
+ const allCallees = [];
1410
+ for (const match of matches) {
1411
+ const exactMatch = match.node.name === symbol || match.node.name.endsWith(`.${symbol}`) || match.node.name.endsWith(`::${symbol}`);
1412
+ if (!exactMatch && matches.length > 1)
1413
+ continue;
1414
+ for (const c of cg.getCallees(match.node.id)) {
1415
+ if (!seen.has(c.node.id)) {
1416
+ seen.add(c.node.id);
1417
+ allCallees.push({ name: c.node.name, kind: c.node.kind, filePath: c.node.filePath, startLine: c.node.startLine });
1418
+ }
1419
+ }
1420
+ }
1421
+ if (allCallees.length === 0 && matches[0]) {
1422
+ for (const c of cg.getCallees(matches[0].node.id)) {
1423
+ if (!seen.has(c.node.id)) {
1424
+ seen.add(c.node.id);
1425
+ allCallees.push({ name: c.node.name, kind: c.node.kind, filePath: c.node.filePath, startLine: c.node.startLine });
1426
+ }
1427
+ }
1428
+ }
1429
+ const limited = allCallees.slice(0, limit);
1430
+ if (options.json) {
1431
+ console.log(JSON.stringify({ symbol, callees: limited }, null, 2));
1432
+ }
1433
+ else if (limited.length === 0) {
1434
+ info(`No callees found for "${symbol}"`);
1435
+ }
1436
+ else {
1437
+ console.log(chalk.bold(`\nCallees of "${symbol}" (${limited.length}):\n`));
1438
+ for (const node of limited) {
1439
+ const loc = node.startLine ? `:${node.startLine}` : '';
1440
+ console.log(chalk.cyan(node.kind.padEnd(12)) +
1441
+ chalk.white(node.name));
1442
+ console.log(chalk.dim(` ${node.filePath}${loc}`));
1443
+ console.log();
1444
+ }
1445
+ }
1446
+ cg.destroy();
1447
+ }
1448
+ catch (err) {
1449
+ error(`callees failed: ${err instanceof Error ? err.message : String(err)}`);
1450
+ process.exit(1);
1451
+ }
1452
+ });
1453
+ /**
1454
+ * specship impact <symbol>
1455
+ */
1456
+ program
1457
+ .command('impact <symbol>')
1458
+ .description('Analyze what code is affected by changing a symbol')
1459
+ .option('-p, --path <path>', 'Project path')
1460
+ .option('-d, --depth <number>', 'Traversal depth', '2')
1461
+ .option('-j, --json', 'Output as JSON')
1462
+ .action(async (symbol, options) => {
1463
+ const projectPath = resolveProjectPath(options.path);
1464
+ try {
1465
+ if (!(0, directory_1.isInitialized)(projectPath)) {
1466
+ error(`SpecShip not initialized in ${projectPath}`);
1467
+ process.exit(1);
1468
+ }
1469
+ const { default: SpecShip } = await loadSpecShip();
1470
+ const cg = await SpecShip.open(projectPath);
1471
+ const depth = Math.min(Math.max(parseInt(options.depth || '2', 10), 1), 10);
1472
+ const matches = cg.searchNodes(symbol, { limit: 50 });
1473
+ if (matches.length === 0) {
1474
+ info(`Symbol "${symbol}" not found`);
1475
+ cg.destroy();
1476
+ return;
1477
+ }
1478
+ // Merge impact subgraphs across all exact-matching symbols
1479
+ const mergedNodes = new Map();
1480
+ const seenEdges = new Set();
1481
+ let edgeCount = 0;
1482
+ for (const match of matches) {
1483
+ const exactMatch = match.node.name === symbol || match.node.name.endsWith(`.${symbol}`) || match.node.name.endsWith(`::${symbol}`);
1484
+ if (!exactMatch && matches.length > 1)
1485
+ continue;
1486
+ const impact = cg.getImpactRadius(match.node.id, depth);
1487
+ for (const [id, n] of impact.nodes) {
1488
+ mergedNodes.set(id, { name: n.name, kind: n.kind, filePath: n.filePath, startLine: n.startLine });
1489
+ }
1490
+ for (const e of impact.edges) {
1491
+ const key = `${e.source}->${e.target}:${e.kind}`;
1492
+ if (!seenEdges.has(key)) {
1493
+ seenEdges.add(key);
1494
+ edgeCount++;
1495
+ }
1496
+ }
1497
+ }
1498
+ // Fallback to top match if exact filter removed everything
1499
+ if (mergedNodes.size === 0 && matches[0]) {
1500
+ const impact = cg.getImpactRadius(matches[0].node.id, depth);
1501
+ for (const [id, n] of impact.nodes) {
1502
+ mergedNodes.set(id, { name: n.name, kind: n.kind, filePath: n.filePath, startLine: n.startLine });
1503
+ }
1504
+ edgeCount = impact.edges.length;
1505
+ }
1506
+ if (options.json) {
1507
+ console.log(JSON.stringify({
1508
+ symbol,
1509
+ depth,
1510
+ nodeCount: mergedNodes.size,
1511
+ edgeCount,
1512
+ affected: Array.from(mergedNodes.values()),
1513
+ }, null, 2));
1514
+ }
1515
+ else if (mergedNodes.size === 0) {
1516
+ info(`No affected symbols found for "${symbol}"`);
1517
+ }
1518
+ else {
1519
+ console.log(chalk.bold(`\nImpact of changing "${symbol}" — ${mergedNodes.size} affected symbols:\n`));
1520
+ // Group by file
1521
+ const byFile = new Map();
1522
+ for (const node of mergedNodes.values()) {
1523
+ const list = byFile.get(node.filePath) || [];
1524
+ list.push({ name: node.name, kind: node.kind, startLine: node.startLine });
1525
+ byFile.set(node.filePath, list);
1526
+ }
1527
+ for (const [file, nodes] of byFile) {
1528
+ console.log(chalk.cyan(file));
1529
+ for (const node of nodes) {
1530
+ const loc = node.startLine ? `:${node.startLine}` : '';
1531
+ console.log(` ${chalk.dim(node.kind.padEnd(12))}${node.name}${chalk.dim(loc)}`);
1532
+ }
1533
+ console.log();
1534
+ }
1535
+ }
1536
+ cg.destroy();
1537
+ }
1538
+ catch (err) {
1539
+ error(`impact failed: ${err instanceof Error ? err.message : String(err)}`);
1540
+ process.exit(1);
1541
+ }
1542
+ });
1543
+ /**
1544
+ * specship affected [files...]
1545
+ *
1546
+ * Find test files affected by the given source files.
1547
+ * Traces dependency edges transitively to find test files that depend on changed code.
1548
+ *
1549
+ * Usage:
1550
+ * git diff --name-only | specship affected --stdin
1551
+ * specship affected src/lib/components/Editor.svelte src/routes/+page.svelte
1552
+ */
1553
+ program
1554
+ .command('affected [files...]')
1555
+ .description('Find test files affected by changed source files')
1556
+ .option('-p, --path <path>', 'Project path')
1557
+ .option('--stdin', 'Read file list from stdin (one per line)')
1558
+ .option('-d, --depth <number>', 'Max dependency traversal depth', '5')
1559
+ .option('-f, --filter <glob>', 'Custom glob filter for test files (e.g. "e2e/*.spec.ts")')
1560
+ .option('-j, --json', 'Output as JSON')
1561
+ .option('-q, --quiet', 'Only output file paths, no decoration')
1562
+ .action(async (fileArgs, options) => {
1563
+ const projectPath = resolveProjectPath(options.path);
1564
+ try {
1565
+ if (!(0, directory_1.isInitialized)(projectPath)) {
1566
+ error(`SpecShip not initialized in ${projectPath}`);
1567
+ process.exit(1);
1568
+ }
1569
+ // Collect changed files from args or stdin
1570
+ let changedFiles = [...(fileArgs || [])];
1571
+ if (options.stdin) {
1572
+ const stdinData = fs.readFileSync(0, 'utf-8');
1573
+ const stdinFiles = stdinData.split('\n').map(f => f.trim()).filter(Boolean);
1574
+ changedFiles.push(...stdinFiles);
1575
+ }
1576
+ if (changedFiles.length === 0) {
1577
+ if (!options.quiet)
1578
+ info('No files provided. Use file arguments or --stdin.');
1579
+ process.exit(0);
1580
+ }
1581
+ const { default: SpecShip } = await loadSpecShip();
1582
+ const cg = await SpecShip.open(projectPath);
1583
+ const maxDepth = parseInt(options.depth || '5', 10);
1584
+ // Common test file patterns
1585
+ const defaultTestPatterns = [
1586
+ /\.spec\./,
1587
+ /\.test\./,
1588
+ /\/__tests__\//,
1589
+ /\/tests?\//,
1590
+ /\/e2e\//,
1591
+ /\/spec\//,
1592
+ ];
1593
+ // Custom filter pattern
1594
+ let customFilter = null;
1595
+ if (options.filter) {
1596
+ // Convert glob to regex: ** → .+, * → [^/]*, . → \.
1597
+ const regex = options.filter
1598
+ .replace(/[+[\]{}()^$|\\]/g, '\\$&')
1599
+ .replace(/\./g, '\\.')
1600
+ .replace(/\*\*/g, '.+')
1601
+ .replace(/\*/g, '[^/]*');
1602
+ customFilter = new RegExp(regex);
1603
+ }
1604
+ function isTestFile(filePath) {
1605
+ if (customFilter)
1606
+ return customFilter.test(filePath);
1607
+ return defaultTestPatterns.some(p => p.test(filePath));
1608
+ }
1609
+ // BFS to find all transitive dependents of changed files, filtered to test files
1610
+ const affectedTests = new Set();
1611
+ const allDependents = new Set();
1612
+ for (const file of changedFiles) {
1613
+ // If the changed file is itself a test file, include it
1614
+ if (isTestFile(file)) {
1615
+ affectedTests.add(file);
1616
+ continue;
1617
+ }
1618
+ // BFS through dependents
1619
+ const queue = [{ file, depth: 0 }];
1620
+ const visited = new Set();
1621
+ visited.add(file);
1622
+ while (queue.length > 0) {
1623
+ const current = queue.shift();
1624
+ if (current.depth >= maxDepth)
1625
+ continue;
1626
+ const dependents = cg.getFileDependents(current.file);
1627
+ for (const dep of dependents) {
1628
+ if (visited.has(dep))
1629
+ continue;
1630
+ visited.add(dep);
1631
+ allDependents.add(dep);
1632
+ if (isTestFile(dep)) {
1633
+ affectedTests.add(dep);
1634
+ }
1635
+ else {
1636
+ queue.push({ file: dep, depth: current.depth + 1 });
1637
+ }
1638
+ }
1639
+ }
1640
+ }
1641
+ const sortedTests = Array.from(affectedTests).sort();
1642
+ // Output
1643
+ if (options.json) {
1644
+ console.log(JSON.stringify({
1645
+ changedFiles,
1646
+ affectedTests: sortedTests,
1647
+ totalDependentsTraversed: allDependents.size,
1648
+ }, null, 2));
1649
+ }
1650
+ else if (options.quiet) {
1651
+ for (const t of sortedTests)
1652
+ console.log(t);
1653
+ }
1654
+ else {
1655
+ if (sortedTests.length === 0) {
1656
+ info('No test files affected by the changed files.');
1657
+ }
1658
+ else {
1659
+ console.log(chalk.bold(`\nAffected test files (${sortedTests.length}):\n`));
1660
+ for (const t of sortedTests) {
1661
+ console.log(' ' + chalk.cyan(t));
1662
+ }
1663
+ console.log();
1664
+ }
1665
+ }
1666
+ cg.destroy();
1667
+ }
1668
+ catch (err) {
1669
+ error(`Affected analysis failed: ${err instanceof Error ? err.message : String(err)}`);
1670
+ process.exit(1);
1671
+ }
1672
+ });
1673
+ /**
1674
+ * specship install
1675
+ */
1676
+ program
1677
+ .command('install')
1678
+ .description('Install specship MCP server into Claude Code')
1679
+ .option('-l, --location <where>', 'Install location: "global" or "local". Default: prompt')
1680
+ .option('-y, --yes', 'Non-interactive: defaults to --location=global, auto-allow on')
1681
+ .option('--no-permissions', 'Skip writing the auto-allow permissions list')
1682
+ .option('--no-sdd', 'Skip the spec-driven-development steering (CLAUDE.md rule + spec-author nudge hook)')
1683
+ .option('--print-config', 'Print MCP config snippet for Claude Code and exit (no file writes)')
1684
+ // -t/--target is vestigial — kept so existing `--target claude` / `--target auto`
1685
+ // invocations (including our own offline-install scripts) keep working.
1686
+ .option('-t, --target <ids>', '(vestigial) accepted: "claude" | "auto" | "all" | "none"')
1687
+ .action(async (opts) => {
1688
+ if (opts.printConfig) {
1689
+ const { claudeTarget } = await Promise.resolve().then(() => __importStar(require('../installer/targets/claude')));
1690
+ const loc = (opts.location === 'local' ? 'local' : 'global');
1691
+ process.stdout.write(claudeTarget.printConfig(loc));
1692
+ return;
1693
+ }
1694
+ const { runInstallerWithOptions } = await Promise.resolve().then(() => __importStar(require('../installer')));
1695
+ if (opts.location && opts.location !== 'global' && opts.location !== 'local') {
1696
+ error(`--location must be "global" or "local" (got "${opts.location}").`);
1697
+ process.exit(1);
1698
+ }
1699
+ try {
1700
+ // Commander's `--no-permissions` makes `opts.permissions === false`;
1701
+ // omitting the flag leaves it `true` (the positive-form default).
1702
+ // We MUST treat the default-true as "user did not override — let
1703
+ // the orchestrator prompt" and only forward an explicit `false`
1704
+ // (or `true` when --yes implies it). Otherwise the auto-allow
1705
+ // prompt is silently skipped on every interactive run.
1706
+ const explicitNoPermissions = opts.permissions === false;
1707
+ const autoAllow = explicitNoPermissions
1708
+ ? false
1709
+ : opts.yes
1710
+ ? true
1711
+ : undefined;
1712
+ // Commander's `--no-sdd` makes `opts.sdd === false`; omitting it leaves
1713
+ // it `true`. Spec-driven steering is on by default — forward `false`
1714
+ // only when the user explicitly opted out.
1715
+ await runInstallerWithOptions({
1716
+ target: opts.target,
1717
+ location: opts.location,
1718
+ autoAllow,
1719
+ sdd: opts.sdd === false ? false : undefined,
1720
+ yes: opts.yes,
1721
+ });
1722
+ }
1723
+ catch (err) {
1724
+ error(err instanceof Error ? err.message : String(err));
1725
+ process.exit(1);
1726
+ }
1727
+ });
1728
+ /**
1729
+ * specship spec-nudge (internal — installed as a UserPromptSubmit hook)
1730
+ *
1731
+ * Reads the UserPromptSubmit JSON payload from stdin and, when the prompt
1732
+ * looks like feature/bug work, prints a non-blocking reminder (as
1733
+ * `hookSpecificOutput.additionalContext`) to author the spec via spec-author
1734
+ * first. Always exits 0 so the prompt proceeds. Conservative: skips clear
1735
+ * questions / read-only asks so it doesn't nag (SDD-INSTALL-DOC, REQ-SDD-002).
1736
+ */
1737
+ program
1738
+ .command('spec-nudge')
1739
+ .description('Internal hook: nudge toward spec-author on feature/bug intent (UserPromptSubmit)')
1740
+ .action(async () => {
1741
+ const shouldNudge = (prompt) => {
1742
+ const text = (prompt || '').trim();
1743
+ if (text.length < 12)
1744
+ return false;
1745
+ if (/[?]\s*$/.test(text))
1746
+ return false; // a question
1747
+ const lower = text.toLowerCase();
1748
+ // Read-only / interrogative openers — never spec-shaped.
1749
+ if (/^(what|why|how|where|who|when|is|are|does|do|can|could|should|explain|show|list|describe|tell|summar|read|find|search|look|run|why)\b/.test(lower))
1750
+ return false;
1751
+ // Feature / bug-shaped intent verbs.
1752
+ return /\b(add|implement|build|create|introduce|support|enhance|fix|bug|broken|refactor|rewrite|migrate|change|modify|update|wire|integrate|feature|spec out)\b/.test(lower);
1753
+ };
1754
+ const chunks = [];
1755
+ try {
1756
+ for await (const c of process.stdin)
1757
+ chunks.push(c);
1758
+ }
1759
+ catch { /* no stdin — nothing to nudge */ }
1760
+ const raw = Buffer.concat(chunks).toString('utf-8').trim();
1761
+ let prompt = '';
1762
+ if (raw) {
1763
+ try {
1764
+ const parsed = JSON.parse(raw);
1765
+ prompt = typeof parsed?.prompt === 'string' ? parsed.prompt : raw;
1766
+ }
1767
+ catch {
1768
+ prompt = raw; // not JSON — treat as the raw prompt text
1769
+ }
1770
+ }
1771
+ if (shouldNudge(prompt)) {
1772
+ const additionalContext = 'This repo uses spec-driven development (SpecShip). Before any brainstorming or ' +
1773
+ 'planning skill, FIRST invoke spec-author to author the spec under specs/ for this ' +
1774
+ 'work — the spec is the contract; implement from it with /ss-implement.';
1775
+ process.stdout.write(JSON.stringify({ hookSpecificOutput: { hookEventName: 'UserPromptSubmit', additionalContext } }) + '\n');
1776
+ }
1777
+ process.exit(0);
1778
+ });
1779
+ /**
1780
+ * specship uninstall
1781
+ *
1782
+ * Inverse of `install`. Removes the specship MCP server entry and
1783
+ * permissions from Claude Code. Prompts global-vs-local when not
1784
+ * given. Does NOT delete the `.specship/` index — that's
1785
+ * `specship uninit`.
1786
+ */
1787
+ program
1788
+ .command('uninstall')
1789
+ .description('Remove specship from Claude Code')
1790
+ .option('-l, --location <where>', 'Uninstall location: "global" or "local". Default: prompt')
1791
+ .option('-y, --yes', 'Non-interactive: defaults to --location=global')
1792
+ // vestigial — kept so existing `--target claude` invocations keep working.
1793
+ .option('-t, --target <ids>', '(vestigial) accepted: "claude" | "auto" | "all" | "none"')
1794
+ .action(async (opts) => {
1795
+ const { runUninstaller } = await Promise.resolve().then(() => __importStar(require('../installer')));
1796
+ if (opts.location && opts.location !== 'global' && opts.location !== 'local') {
1797
+ error(`--location must be "global" or "local" (got "${opts.location}").`);
1798
+ process.exit(1);
1799
+ }
1800
+ try {
1801
+ await runUninstaller({
1802
+ target: opts.target,
1803
+ location: opts.location,
1804
+ yes: opts.yes,
1805
+ });
1806
+ }
1807
+ catch (err) {
1808
+ error(err instanceof Error ? err.message : String(err));
1809
+ process.exit(1);
1810
+ }
1811
+ });
1812
+ // =============================================================================
1813
+ // Spec layer / Workflow engine commands (v5)
1814
+ // =============================================================================
1815
+ program
1816
+ .command('drifted [path]')
1817
+ .description('List spec links in concerning states (drifted, broken, orphaned).')
1818
+ .option('-s, --state <list>', 'comma-separated states (default: drifted,broken,orphaned)')
1819
+ .option('-l, --limit <n>', 'max links to print (default: 50)')
1820
+ .option('--fail-on <list>', 'comma-separated states that cause non-zero exit (CI gate)')
1821
+ .option('--json', 'emit JSON')
1822
+ .action(async (pathArg, options) => {
1823
+ const projectRoot = path.resolve(pathArg ?? process.cwd());
1824
+ if (!(0, directory_1.isInitialized)(projectRoot)) {
1825
+ error(`SpecShip not initialized in ${projectRoot}. Run \`specship init -i\` first.`);
1826
+ process.exit(1);
1827
+ }
1828
+ const { SpecShip } = await loadSpecShip();
1829
+ const cg = await SpecShip.open(projectRoot);
1830
+ try {
1831
+ const states = (options.state ?? 'drifted,broken,orphaned')
1832
+ .split(',')
1833
+ .map((s) => s.trim())
1834
+ .filter(Boolean);
1835
+ const limit = options.limit ? Math.max(1, parseInt(options.limit, 10) || 50) : 50;
1836
+ const links = cg.getSpecQueries().getLinksByState(states).slice(0, limit);
1837
+ if (options.json) {
1838
+ // eslint-disable-next-line no-console
1839
+ console.log(JSON.stringify({ count: links.length, links }, null, 2));
1840
+ }
1841
+ else if (links.length === 0) {
1842
+ // eslint-disable-next-line no-console
1843
+ console.log(`No links in states: ${states.join(', ')}. ✨ Drift queue is clean.`);
1844
+ }
1845
+ else {
1846
+ for (const link of links) {
1847
+ const drift = link.driftAxis ? ` [drift=${link.driftAxis}]` : '';
1848
+ // eslint-disable-next-line no-console
1849
+ console.log(`#${link.id} [${link.state}${drift}] ${link.specId} → ${link.targetFilePath}:${link.targetQualifiedName} <${link.provenance}>`);
1850
+ }
1851
+ }
1852
+ if (options.failOn) {
1853
+ const failStates = options.failOn.split(',').map((s) => s.trim()).filter(Boolean);
1854
+ const offending = links.filter((l) => failStates.includes(l.state));
1855
+ if (offending.length > 0) {
1856
+ process.exit(1);
1857
+ }
1858
+ }
1859
+ }
1860
+ finally {
1861
+ cg.close();
1862
+ }
1863
+ });
1864
+ program
1865
+ .command('workflow <action> [arg]')
1866
+ .description('Workflow engine: list | run <name> | resume <runId> | cancel <runId> | approve <runId> | reject <runId> | runs')
1867
+ .option('-i, --input <kv...>', 'workflow inputs as KEY=VALUE (repeatable)')
1868
+ .option('--path <projectRoot>', 'project root (default: cwd)')
1869
+ .option('--comment <text>', 'comment for approve/reject')
1870
+ .option('--reason <text>', 'reason for cancel/reject')
1871
+ .option('--json', 'emit JSON where applicable')
1872
+ .action(async (action, arg, options) => {
1873
+ const projectRoot = path.resolve(options.path ?? process.cwd());
1874
+ if (!(0, directory_1.isInitialized)(projectRoot)) {
1875
+ error(`SpecShip not initialized in ${projectRoot}. Run \`specship init -i\` first.`);
1876
+ process.exit(1);
1877
+ }
1878
+ const { SpecShip } = await loadSpecShip();
1879
+ const { discoverWorkflows, loadWorkflowByName } = await Promise.resolve().then(() => __importStar(require('../workflows/discovery')));
1880
+ const { WorkflowExecutor } = await Promise.resolve().then(() => __importStar(require('../workflows/executor')));
1881
+ const { WorktreeProvider } = await Promise.resolve().then(() => __importStar(require('../isolation/worktree')));
1882
+ const cg = await SpecShip.open(projectRoot);
1883
+ try {
1884
+ const specQueries = cg.getSpecQueries();
1885
+ const worktrees = new WorktreeProvider(specQueries);
1886
+ const executor = new WorkflowExecutor(specQueries, worktrees);
1887
+ switch (action) {
1888
+ case 'list': {
1889
+ const result = discoverWorkflows(projectRoot);
1890
+ if (options.json) {
1891
+ // eslint-disable-next-line no-console
1892
+ console.log(JSON.stringify({
1893
+ workflows: result.workflows.map((w) => ({
1894
+ name: w.workflow.name,
1895
+ scope: w.scope,
1896
+ sourcePath: w.sourcePath,
1897
+ description: w.workflow.description,
1898
+ nodes: w.workflow.nodes.length,
1899
+ requires: w.workflow.requires,
1900
+ })),
1901
+ errors: result.errors,
1902
+ }, null, 2));
1903
+ }
1904
+ else {
1905
+ for (const w of result.workflows) {
1906
+ // eslint-disable-next-line no-console
1907
+ console.log(` [${w.scope}] ${w.workflow.name} (${w.workflow.nodes.length} nodes) — ${w.workflow.description ?? ''}`);
1908
+ }
1909
+ if (result.errors.length > 0) {
1910
+ // eslint-disable-next-line no-console
1911
+ console.error(`\n${result.errors.length} workflow file(s) had errors:`);
1912
+ for (const e of result.errors) {
1913
+ // eslint-disable-next-line no-console
1914
+ console.error(` ${e.sourcePath}:`);
1915
+ for (const er of e.errors) {
1916
+ // eslint-disable-next-line no-console
1917
+ console.error(` ${er.path}: ${er.message}`);
1918
+ }
1919
+ }
1920
+ }
1921
+ }
1922
+ break;
1923
+ }
1924
+ case 'run': {
1925
+ if (!arg) {
1926
+ error('workflow run requires a workflow name');
1927
+ process.exit(1);
1928
+ }
1929
+ const loaded = loadWorkflowByName(projectRoot, arg);
1930
+ if (!loaded) {
1931
+ error(`Workflow "${arg}" not found. Use \`specship workflow list\` to see available workflows.`);
1932
+ process.exit(1);
1933
+ }
1934
+ const inputs = {};
1935
+ for (const kv of options.input ?? []) {
1936
+ const eqIdx = kv.indexOf('=');
1937
+ if (eqIdx <= 0) {
1938
+ error(`--input must be KEY=VALUE (got "${kv}")`);
1939
+ process.exit(1);
1940
+ }
1941
+ inputs[kv.slice(0, eqIdx)] = kv.slice(eqIdx + 1);
1942
+ }
1943
+ // Check required inputs.
1944
+ for (const inp of loaded.workflow.inputs ?? []) {
1945
+ if (inp.required && !(inp.name in inputs)) {
1946
+ error(`Required input missing: --input ${inp.name}=...`);
1947
+ process.exit(1);
1948
+ }
1949
+ }
1950
+ // Apply declared defaults for any optional input not passed. This
1951
+ // makes the schema's `default` field actually take effect and means
1952
+ // a `$INPUT.X` reference to a declared-but-omitted optional input
1953
+ // resolves to its default (or "") instead of throwing OutputRefError
1954
+ // mid-run. Required inputs are already enforced above.
1955
+ for (const inp of loaded.workflow.inputs ?? []) {
1956
+ if (!(inp.name in inputs)) {
1957
+ inputs[inp.name] = inp.default ?? '';
1958
+ }
1959
+ }
1960
+ const result = await executor.start(loaded.workflow, {
1961
+ projectRoot,
1962
+ inputs,
1963
+ variables: {
1964
+ ARTIFACTS_DIR: path.join((0, directory_1.getSpecShipDir)(projectRoot), 'artifacts'),
1965
+ CONTEXT: projectRoot,
1966
+ },
1967
+ });
1968
+ if (options.json) {
1969
+ // eslint-disable-next-line no-console
1970
+ console.log(JSON.stringify({
1971
+ runId: result.run.id,
1972
+ status: result.run.status,
1973
+ isolationEnvId: result.run.isolationEnvId,
1974
+ nodeStates: Object.fromEntries(result.nodeStates),
1975
+ }, null, 2));
1976
+ }
1977
+ else {
1978
+ // eslint-disable-next-line no-console
1979
+ console.log(`Run ${result.run.id} → ${result.run.status}`);
1980
+ if (result.run.isolationEnvId) {
1981
+ // eslint-disable-next-line no-console
1982
+ console.log(`Worktree: ${result.run.isolationEnvId}`);
1983
+ }
1984
+ if (result.run.errorMessage) {
1985
+ // eslint-disable-next-line no-console
1986
+ console.log(`Error: ${result.run.errorMessage}`);
1987
+ }
1988
+ }
1989
+ if (result.run.status === 'failed')
1990
+ process.exit(1);
1991
+ break;
1992
+ }
1993
+ case 'resume': {
1994
+ if (!arg) {
1995
+ error('workflow resume requires a runId');
1996
+ process.exit(1);
1997
+ }
1998
+ const run = specQueries.getWorkflowRunById(arg);
1999
+ if (!run) {
2000
+ error(`Run ${arg} not found`);
2001
+ process.exit(1);
2002
+ }
2003
+ const loaded = loadWorkflowByName(projectRoot, run.workflowName);
2004
+ if (!loaded) {
2005
+ error(`Workflow "${run.workflowName}" no longer exists`);
2006
+ process.exit(1);
2007
+ }
2008
+ const result = await executor.resume(loaded.workflow, arg, {
2009
+ projectRoot,
2010
+ inputs: run.inputs,
2011
+ variables: {
2012
+ ARTIFACTS_DIR: path.join((0, directory_1.getSpecShipDir)(projectRoot), 'artifacts'),
2013
+ CONTEXT: projectRoot,
2014
+ },
2015
+ });
2016
+ // eslint-disable-next-line no-console
2017
+ console.log(`Run ${result.run.id} → ${result.run.status}`);
2018
+ if (result.run.status === 'failed')
2019
+ process.exit(1);
2020
+ break;
2021
+ }
2022
+ case 'cancel': {
2023
+ if (!arg) {
2024
+ error('workflow cancel requires a runId');
2025
+ process.exit(1);
2026
+ }
2027
+ executor.cancel(arg, options.reason ?? 'cancelled via CLI');
2028
+ // eslint-disable-next-line no-console
2029
+ console.log(`Run ${arg} cancelled`);
2030
+ break;
2031
+ }
2032
+ case 'approve': {
2033
+ if (!arg) {
2034
+ error('workflow approve requires a runId');
2035
+ process.exit(1);
2036
+ }
2037
+ executor.approve(arg, options.comment);
2038
+ // eslint-disable-next-line no-console
2039
+ console.log(`Run ${arg} approved. Call \`specship workflow resume ${arg}\` to continue.`);
2040
+ break;
2041
+ }
2042
+ case 'reject': {
2043
+ if (!arg) {
2044
+ error('workflow reject requires a runId');
2045
+ process.exit(1);
2046
+ }
2047
+ executor.reject(arg, options.reason);
2048
+ // eslint-disable-next-line no-console
2049
+ console.log(`Run ${arg} rejected`);
2050
+ break;
2051
+ }
2052
+ case 'runs': {
2053
+ const runs = specQueries.getAllWorkflowRuns(50);
2054
+ if (options.json) {
2055
+ // eslint-disable-next-line no-console
2056
+ console.log(JSON.stringify(runs, null, 2));
2057
+ }
2058
+ else if (runs.length === 0) {
2059
+ // eslint-disable-next-line no-console
2060
+ console.log('No runs yet.');
2061
+ }
2062
+ else {
2063
+ for (const r of runs) {
2064
+ const dur = r.completedAt
2065
+ ? `${Math.round((r.completedAt - (r.startedAt ?? r.createdAt)) / 1000)}s`
2066
+ : '—';
2067
+ // eslint-disable-next-line no-console
2068
+ console.log(`${r.id.substring(0, 8)} [${r.status}] ${r.workflowName} (${dur})`);
2069
+ }
2070
+ }
2071
+ break;
2072
+ }
2073
+ default:
2074
+ error(`Unknown workflow action "${action}". Use: list | run | resume | cancel | approve | reject | runs`);
2075
+ process.exit(1);
2076
+ }
2077
+ }
2078
+ finally {
2079
+ cg.close();
2080
+ }
2081
+ });
2082
+ // Parse and run
2083
+ program.parse();
2084
+ } // end main()
2085
+ //# sourceMappingURL=specship.js.map