claude-code-workflow 6.2.2 → 6.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (346) hide show
  1. package/ccw/dist/cli.d.ts +2 -0
  2. package/ccw/dist/cli.d.ts.map +1 -0
  3. package/ccw/dist/cli.js +219 -0
  4. package/ccw/dist/cli.js.map +1 -0
  5. package/ccw/dist/commands/cli.d.ts +32 -0
  6. package/ccw/dist/commands/cli.d.ts.map +1 -0
  7. package/ccw/dist/commands/cli.js +619 -0
  8. package/ccw/dist/commands/cli.js.map +1 -0
  9. package/ccw/dist/commands/core-memory.d.ts +32 -0
  10. package/ccw/dist/commands/core-memory.d.ts.map +1 -0
  11. package/ccw/dist/commands/core-memory.js +640 -0
  12. package/ccw/dist/commands/core-memory.js.map +1 -0
  13. package/ccw/dist/commands/hook.d.ts +16 -0
  14. package/ccw/dist/commands/hook.d.ts.map +1 -0
  15. package/ccw/dist/commands/hook.js +276 -0
  16. package/ccw/dist/commands/hook.js.map +1 -0
  17. package/ccw/dist/commands/install.d.ts +12 -0
  18. package/ccw/dist/commands/install.d.ts.map +1 -0
  19. package/ccw/dist/commands/install.js +443 -0
  20. package/ccw/dist/commands/install.js.map +1 -0
  21. package/ccw/dist/commands/list.d.ts +5 -0
  22. package/ccw/dist/commands/list.d.ts.map +1 -0
  23. package/ccw/dist/commands/list.js +32 -0
  24. package/ccw/dist/commands/list.js.map +1 -0
  25. package/ccw/dist/commands/memory.d.ts +57 -0
  26. package/ccw/dist/commands/memory.d.ts.map +1 -0
  27. package/ccw/dist/commands/memory.js +890 -0
  28. package/ccw/dist/commands/memory.js.map +1 -0
  29. package/ccw/dist/commands/serve.d.ts +12 -0
  30. package/ccw/dist/commands/serve.d.ts.map +1 -0
  31. package/ccw/dist/commands/serve.js +63 -0
  32. package/ccw/dist/commands/serve.js.map +1 -0
  33. package/ccw/dist/commands/session-path-resolver.d.ts +45 -0
  34. package/ccw/dist/commands/session-path-resolver.d.ts.map +1 -0
  35. package/ccw/dist/commands/session-path-resolver.js +302 -0
  36. package/ccw/dist/commands/session-path-resolver.js.map +1 -0
  37. package/ccw/dist/commands/session.d.ts +12 -0
  38. package/ccw/dist/commands/session.d.ts.map +1 -0
  39. package/ccw/dist/commands/session.js +954 -0
  40. package/ccw/dist/commands/session.js.map +1 -0
  41. package/ccw/dist/commands/stop.d.ts +11 -0
  42. package/ccw/dist/commands/stop.d.ts.map +1 -0
  43. package/ccw/dist/commands/stop.js +96 -0
  44. package/ccw/dist/commands/stop.js.map +1 -0
  45. package/ccw/dist/commands/tool.d.ts +29 -0
  46. package/ccw/dist/commands/tool.d.ts.map +1 -0
  47. package/ccw/dist/commands/tool.js +173 -0
  48. package/ccw/dist/commands/tool.js.map +1 -0
  49. package/ccw/dist/commands/uninstall.d.ts +9 -0
  50. package/ccw/dist/commands/uninstall.d.ts.map +1 -0
  51. package/ccw/dist/commands/uninstall.js +239 -0
  52. package/ccw/dist/commands/uninstall.js.map +1 -0
  53. package/ccw/dist/commands/upgrade.d.ts +10 -0
  54. package/ccw/dist/commands/upgrade.d.ts.map +1 -0
  55. package/ccw/dist/commands/upgrade.js +288 -0
  56. package/ccw/dist/commands/upgrade.js.map +1 -0
  57. package/ccw/dist/commands/view.d.ts +14 -0
  58. package/ccw/dist/commands/view.d.ts.map +1 -0
  59. package/ccw/dist/commands/view.js +100 -0
  60. package/ccw/dist/commands/view.js.map +1 -0
  61. package/ccw/dist/config/storage-paths.d.ts +184 -0
  62. package/ccw/dist/config/storage-paths.d.ts.map +1 -0
  63. package/ccw/dist/config/storage-paths.js +536 -0
  64. package/ccw/dist/config/storage-paths.js.map +1 -0
  65. package/ccw/dist/core/cache-manager.d.ts +80 -0
  66. package/ccw/dist/core/cache-manager.d.ts.map +1 -0
  67. package/ccw/dist/core/cache-manager.js +260 -0
  68. package/ccw/dist/core/cache-manager.js.map +1 -0
  69. package/ccw/dist/core/claude-freshness.d.ts +53 -0
  70. package/ccw/dist/core/claude-freshness.d.ts.map +1 -0
  71. package/ccw/dist/core/claude-freshness.js +232 -0
  72. package/ccw/dist/core/claude-freshness.js.map +1 -0
  73. package/ccw/dist/core/core-memory-store.d.ts +320 -0
  74. package/ccw/dist/core/core-memory-store.d.ts.map +1 -0
  75. package/ccw/dist/core/core-memory-store.js +1177 -0
  76. package/ccw/dist/core/core-memory-store.js.map +1 -0
  77. package/ccw/dist/core/dashboard-generator-patch.d.ts +2 -0
  78. package/ccw/dist/core/dashboard-generator-patch.d.ts.map +1 -0
  79. package/ccw/dist/core/dashboard-generator-patch.js +48 -0
  80. package/ccw/dist/core/dashboard-generator-patch.js.map +1 -0
  81. package/ccw/dist/core/dashboard-generator.d.ts +8 -0
  82. package/ccw/dist/core/dashboard-generator.d.ts.map +1 -0
  83. package/ccw/dist/core/dashboard-generator.js +695 -0
  84. package/ccw/dist/core/dashboard-generator.js.map +1 -0
  85. package/ccw/dist/core/data-aggregator.d.ts +145 -0
  86. package/ccw/dist/core/data-aggregator.d.ts.map +1 -0
  87. package/ccw/dist/core/data-aggregator.js +416 -0
  88. package/ccw/dist/core/data-aggregator.js.map +1 -0
  89. package/ccw/dist/core/history-importer.d.ts +102 -0
  90. package/ccw/dist/core/history-importer.d.ts.map +1 -0
  91. package/ccw/dist/core/history-importer.js +493 -0
  92. package/ccw/dist/core/history-importer.js.map +1 -0
  93. package/ccw/dist/core/lite-scanner-complete.d.ts +81 -0
  94. package/ccw/dist/core/lite-scanner-complete.d.ts.map +1 -0
  95. package/ccw/dist/core/lite-scanner-complete.js +368 -0
  96. package/ccw/dist/core/lite-scanner-complete.js.map +1 -0
  97. package/ccw/dist/core/lite-scanner.d.ts +81 -0
  98. package/ccw/dist/core/lite-scanner.d.ts.map +1 -0
  99. package/ccw/dist/core/lite-scanner.js +368 -0
  100. package/ccw/dist/core/lite-scanner.js.map +1 -0
  101. package/ccw/dist/core/manifest.d.ts +88 -0
  102. package/ccw/dist/core/manifest.d.ts.map +1 -0
  103. package/ccw/dist/core/manifest.js +214 -0
  104. package/ccw/dist/core/manifest.js.map +1 -0
  105. package/ccw/dist/core/memory-embedder-bridge.d.ts +83 -0
  106. package/ccw/dist/core/memory-embedder-bridge.d.ts.map +1 -0
  107. package/ccw/dist/core/memory-embedder-bridge.js +181 -0
  108. package/ccw/dist/core/memory-embedder-bridge.js.map +1 -0
  109. package/ccw/dist/core/memory-store.d.ts +249 -0
  110. package/ccw/dist/core/memory-store.d.ts.map +1 -0
  111. package/ccw/dist/core/memory-store.js +781 -0
  112. package/ccw/dist/core/memory-store.js.map +1 -0
  113. package/ccw/dist/core/routes/ccw-routes.d.ts +20 -0
  114. package/ccw/dist/core/routes/ccw-routes.d.ts.map +1 -0
  115. package/ccw/dist/core/routes/ccw-routes.js +70 -0
  116. package/ccw/dist/core/routes/ccw-routes.js.map +1 -0
  117. package/ccw/dist/core/routes/claude-routes.d.ts +19 -0
  118. package/ccw/dist/core/routes/claude-routes.d.ts.map +1 -0
  119. package/ccw/dist/core/routes/claude-routes.js +1017 -0
  120. package/ccw/dist/core/routes/claude-routes.js.map +1 -0
  121. package/ccw/dist/core/routes/cli-routes.d.ts +20 -0
  122. package/ccw/dist/core/routes/cli-routes.d.ts.map +1 -0
  123. package/ccw/dist/core/routes/cli-routes.js +468 -0
  124. package/ccw/dist/core/routes/cli-routes.js.map +1 -0
  125. package/ccw/dist/core/routes/codexlens-routes.d.ts +20 -0
  126. package/ccw/dist/core/routes/codexlens-routes.d.ts.map +1 -0
  127. package/ccw/dist/core/routes/codexlens-routes.js +754 -0
  128. package/ccw/dist/core/routes/codexlens-routes.js.map +1 -0
  129. package/ccw/dist/core/routes/core-memory-routes.d.ts +21 -0
  130. package/ccw/dist/core/routes/core-memory-routes.d.ts.map +1 -0
  131. package/ccw/dist/core/routes/core-memory-routes.js +520 -0
  132. package/ccw/dist/core/routes/core-memory-routes.js.map +1 -0
  133. package/ccw/dist/core/routes/files-routes.d.ts +20 -0
  134. package/ccw/dist/core/routes/files-routes.d.ts.map +1 -0
  135. package/ccw/dist/core/routes/files-routes.js +374 -0
  136. package/ccw/dist/core/routes/files-routes.js.map +1 -0
  137. package/ccw/dist/core/routes/graph-routes.d.ts +20 -0
  138. package/ccw/dist/core/routes/graph-routes.d.ts.map +1 -0
  139. package/ccw/dist/core/routes/graph-routes.js +517 -0
  140. package/ccw/dist/core/routes/graph-routes.js.map +1 -0
  141. package/ccw/dist/core/routes/help-routes.d.ts +20 -0
  142. package/ccw/dist/core/routes/help-routes.d.ts.map +1 -0
  143. package/ccw/dist/core/routes/help-routes.js +250 -0
  144. package/ccw/dist/core/routes/help-routes.js.map +1 -0
  145. package/ccw/dist/core/routes/hooks-routes.d.ts +21 -0
  146. package/ccw/dist/core/routes/hooks-routes.d.ts.map +1 -0
  147. package/ccw/dist/core/routes/hooks-routes.js +346 -0
  148. package/ccw/dist/core/routes/hooks-routes.js.map +1 -0
  149. package/ccw/dist/core/routes/mcp-routes.d.ts +20 -0
  150. package/ccw/dist/core/routes/mcp-routes.d.ts.map +1 -0
  151. package/ccw/dist/core/routes/mcp-routes.js +1129 -0
  152. package/ccw/dist/core/routes/mcp-routes.js.map +1 -0
  153. package/ccw/dist/core/routes/mcp-templates-db.d.ts +54 -0
  154. package/ccw/dist/core/routes/mcp-templates-db.d.ts.map +1 -0
  155. package/ccw/dist/core/routes/mcp-templates-db.js +226 -0
  156. package/ccw/dist/core/routes/mcp-templates-db.js.map +1 -0
  157. package/ccw/dist/core/routes/memory-routes.d.ts +21 -0
  158. package/ccw/dist/core/routes/memory-routes.d.ts.map +1 -0
  159. package/ccw/dist/core/routes/memory-routes.js +1095 -0
  160. package/ccw/dist/core/routes/memory-routes.js.map +1 -0
  161. package/ccw/dist/core/routes/rules-routes.d.ts +20 -0
  162. package/ccw/dist/core/routes/rules-routes.d.ts.map +1 -0
  163. package/ccw/dist/core/routes/rules-routes.js +442 -0
  164. package/ccw/dist/core/routes/rules-routes.js.map +1 -0
  165. package/ccw/dist/core/routes/session-routes.d.ts +20 -0
  166. package/ccw/dist/core/routes/session-routes.d.ts.map +1 -0
  167. package/ccw/dist/core/routes/session-routes.js +423 -0
  168. package/ccw/dist/core/routes/session-routes.js.map +1 -0
  169. package/ccw/dist/core/routes/skills-routes.d.ts +20 -0
  170. package/ccw/dist/core/routes/skills-routes.d.ts.map +1 -0
  171. package/ccw/dist/core/routes/skills-routes.js +533 -0
  172. package/ccw/dist/core/routes/skills-routes.js.map +1 -0
  173. package/ccw/dist/core/routes/status-routes.d.ts +20 -0
  174. package/ccw/dist/core/routes/status-routes.d.ts.map +1 -0
  175. package/ccw/dist/core/routes/status-routes.js +38 -0
  176. package/ccw/dist/core/routes/status-routes.js.map +1 -0
  177. package/ccw/dist/core/routes/system-routes.d.ts +22 -0
  178. package/ccw/dist/core/routes/system-routes.d.ts.map +1 -0
  179. package/ccw/dist/core/routes/system-routes.js +354 -0
  180. package/ccw/dist/core/routes/system-routes.js.map +1 -0
  181. package/ccw/dist/core/server.d.ts +17 -0
  182. package/ccw/dist/core/server.d.ts.map +1 -0
  183. package/ccw/dist/core/server.js +386 -0
  184. package/ccw/dist/core/server.js.map +1 -0
  185. package/ccw/dist/core/session-clustering-service.d.ts +153 -0
  186. package/ccw/dist/core/session-clustering-service.d.ts.map +1 -0
  187. package/ccw/dist/core/session-clustering-service.js +1065 -0
  188. package/ccw/dist/core/session-clustering-service.js.map +1 -0
  189. package/ccw/dist/core/session-scanner.d.ts +32 -0
  190. package/ccw/dist/core/session-scanner.d.ts.map +1 -0
  191. package/ccw/dist/core/session-scanner.js +253 -0
  192. package/ccw/dist/core/session-scanner.js.map +1 -0
  193. package/ccw/dist/core/websocket.d.ts +23 -0
  194. package/ccw/dist/core/websocket.d.ts.map +1 -0
  195. package/ccw/dist/core/websocket.js +168 -0
  196. package/ccw/dist/core/websocket.js.map +1 -0
  197. package/ccw/dist/index.d.ts +10 -0
  198. package/ccw/dist/index.d.ts.map +1 -0
  199. package/ccw/dist/index.js +10 -0
  200. package/ccw/dist/index.js.map +1 -0
  201. package/ccw/dist/mcp-server/index.d.ts +7 -0
  202. package/ccw/dist/mcp-server/index.d.ts.map +1 -0
  203. package/ccw/dist/mcp-server/index.js +157 -0
  204. package/ccw/dist/mcp-server/index.js.map +1 -0
  205. package/ccw/dist/tools/classify-folders.d.ts +26 -0
  206. package/ccw/dist/tools/classify-folders.d.ts.map +1 -0
  207. package/ccw/dist/tools/classify-folders.js +201 -0
  208. package/ccw/dist/tools/classify-folders.js.map +1 -0
  209. package/ccw/dist/tools/cli-config-manager.d.ts +62 -0
  210. package/ccw/dist/tools/cli-config-manager.d.ts.map +1 -0
  211. package/ccw/dist/tools/cli-config-manager.js +221 -0
  212. package/ccw/dist/tools/cli-config-manager.js.map +1 -0
  213. package/ccw/dist/tools/cli-executor.d.ts +373 -0
  214. package/ccw/dist/tools/cli-executor.d.ts.map +1 -0
  215. package/ccw/dist/tools/cli-executor.js +1625 -0
  216. package/ccw/dist/tools/cli-executor.js.map +1 -0
  217. package/ccw/dist/tools/cli-history-store.d.ts +330 -0
  218. package/ccw/dist/tools/cli-history-store.d.ts.map +1 -0
  219. package/ccw/dist/tools/cli-history-store.js +916 -0
  220. package/ccw/dist/tools/cli-history-store.js.map +1 -0
  221. package/ccw/dist/tools/codex-lens.d.ts +118 -0
  222. package/ccw/dist/tools/codex-lens.d.ts.map +1 -0
  223. package/ccw/dist/tools/codex-lens.js +962 -0
  224. package/ccw/dist/tools/codex-lens.js.map +1 -0
  225. package/ccw/dist/tools/convert-tokens-to-css.d.ts +14 -0
  226. package/ccw/dist/tools/convert-tokens-to-css.d.ts.map +1 -0
  227. package/ccw/dist/tools/convert-tokens-to-css.js +244 -0
  228. package/ccw/dist/tools/convert-tokens-to-css.js.map +1 -0
  229. package/ccw/dist/tools/core-memory.d.ts +66 -0
  230. package/ccw/dist/tools/core-memory.d.ts.map +1 -0
  231. package/ccw/dist/tools/core-memory.js +324 -0
  232. package/ccw/dist/tools/core-memory.js.map +1 -0
  233. package/ccw/dist/tools/detect-changed-modules.d.ts +24 -0
  234. package/ccw/dist/tools/detect-changed-modules.d.ts.map +1 -0
  235. package/ccw/dist/tools/detect-changed-modules.js +277 -0
  236. package/ccw/dist/tools/detect-changed-modules.js.map +1 -0
  237. package/ccw/dist/tools/discover-design-files.d.ts +36 -0
  238. package/ccw/dist/tools/discover-design-files.d.ts.map +1 -0
  239. package/ccw/dist/tools/discover-design-files.js +147 -0
  240. package/ccw/dist/tools/discover-design-files.js.map +1 -0
  241. package/ccw/dist/tools/edit-file.d.ts +28 -0
  242. package/ccw/dist/tools/edit-file.d.ts.map +1 -0
  243. package/ccw/dist/tools/edit-file.js +479 -0
  244. package/ccw/dist/tools/edit-file.js.map +1 -0
  245. package/ccw/dist/tools/generate-module-docs.d.ts +22 -0
  246. package/ccw/dist/tools/generate-module-docs.d.ts.map +1 -0
  247. package/ccw/dist/tools/generate-module-docs.js +379 -0
  248. package/ccw/dist/tools/generate-module-docs.js.map +1 -0
  249. package/ccw/dist/tools/get-modules-by-depth.d.ts +15 -0
  250. package/ccw/dist/tools/get-modules-by-depth.d.ts.map +1 -0
  251. package/ccw/dist/tools/get-modules-by-depth.js +296 -0
  252. package/ccw/dist/tools/get-modules-by-depth.js.map +1 -0
  253. package/ccw/dist/tools/index.d.ts +55 -0
  254. package/ccw/dist/tools/index.d.ts.map +1 -0
  255. package/ccw/dist/tools/index.js +304 -0
  256. package/ccw/dist/tools/index.js.map +1 -0
  257. package/ccw/dist/tools/native-session-discovery.d.ts +97 -0
  258. package/ccw/dist/tools/native-session-discovery.d.ts.map +1 -0
  259. package/ccw/dist/tools/native-session-discovery.js +700 -0
  260. package/ccw/dist/tools/native-session-discovery.js.map +1 -0
  261. package/ccw/dist/tools/notifier.d.ts +50 -0
  262. package/ccw/dist/tools/notifier.d.ts.map +1 -0
  263. package/ccw/dist/tools/notifier.js +90 -0
  264. package/ccw/dist/tools/notifier.js.map +1 -0
  265. package/ccw/dist/tools/read-file.d.ts +32 -0
  266. package/ccw/dist/tools/read-file.d.ts.map +1 -0
  267. package/ccw/dist/tools/read-file.js +329 -0
  268. package/ccw/dist/tools/read-file.js.map +1 -0
  269. package/ccw/dist/tools/resume-strategy.d.ts +48 -0
  270. package/ccw/dist/tools/resume-strategy.d.ts.map +1 -0
  271. package/ccw/dist/tools/resume-strategy.js +248 -0
  272. package/ccw/dist/tools/resume-strategy.js.map +1 -0
  273. package/ccw/dist/tools/session-content-parser.d.ts +58 -0
  274. package/ccw/dist/tools/session-content-parser.d.ts.map +1 -0
  275. package/ccw/dist/tools/session-content-parser.js +420 -0
  276. package/ccw/dist/tools/session-content-parser.js.map +1 -0
  277. package/ccw/dist/tools/session-manager.d.ts +9 -0
  278. package/ccw/dist/tools/session-manager.d.ts.map +1 -0
  279. package/ccw/dist/tools/session-manager.js +834 -0
  280. package/ccw/dist/tools/session-manager.js.map +1 -0
  281. package/ccw/dist/tools/smart-context.d.ts +35 -0
  282. package/ccw/dist/tools/smart-context.d.ts.map +1 -0
  283. package/ccw/dist/tools/smart-context.js +182 -0
  284. package/ccw/dist/tools/smart-context.js.map +1 -0
  285. package/ccw/dist/tools/smart-search.d.ts +105 -0
  286. package/ccw/dist/tools/smart-search.d.ts.map +1 -0
  287. package/ccw/dist/tools/smart-search.js +1753 -0
  288. package/ccw/dist/tools/smart-search.js.map +1 -0
  289. package/ccw/dist/tools/storage-manager.d.ts +114 -0
  290. package/ccw/dist/tools/storage-manager.d.ts.map +1 -0
  291. package/ccw/dist/tools/storage-manager.js +392 -0
  292. package/ccw/dist/tools/storage-manager.js.map +1 -0
  293. package/ccw/dist/tools/ui-generate-preview.d.ts +39 -0
  294. package/ccw/dist/tools/ui-generate-preview.d.ts.map +1 -0
  295. package/ccw/dist/tools/ui-generate-preview.js +300 -0
  296. package/ccw/dist/tools/ui-generate-preview.js.map +1 -0
  297. package/ccw/dist/tools/ui-instantiate-prototypes.d.ts +75 -0
  298. package/ccw/dist/tools/ui-instantiate-prototypes.d.ts.map +1 -0
  299. package/ccw/dist/tools/ui-instantiate-prototypes.js +256 -0
  300. package/ccw/dist/tools/ui-instantiate-prototypes.js.map +1 -0
  301. package/ccw/dist/tools/update-module-claude.d.ts +80 -0
  302. package/ccw/dist/tools/update-module-claude.d.ts.map +1 -0
  303. package/ccw/dist/tools/update-module-claude.js +351 -0
  304. package/ccw/dist/tools/update-module-claude.js.map +1 -0
  305. package/ccw/dist/tools/write-file.d.ts +19 -0
  306. package/ccw/dist/tools/write-file.d.ts.map +1 -0
  307. package/ccw/dist/tools/write-file.js +193 -0
  308. package/ccw/dist/tools/write-file.js.map +1 -0
  309. package/ccw/dist/types/config.d.ts +11 -0
  310. package/ccw/dist/types/config.d.ts.map +1 -0
  311. package/ccw/dist/types/config.js +2 -0
  312. package/ccw/dist/types/config.js.map +1 -0
  313. package/ccw/dist/types/index.d.ts +4 -0
  314. package/ccw/dist/types/index.d.ts.map +1 -0
  315. package/ccw/dist/types/index.js +4 -0
  316. package/ccw/dist/types/index.js.map +1 -0
  317. package/ccw/dist/types/session.d.ts +20 -0
  318. package/ccw/dist/types/session.d.ts.map +1 -0
  319. package/ccw/dist/types/session.js +2 -0
  320. package/ccw/dist/types/session.js.map +1 -0
  321. package/ccw/dist/types/tool.d.ts +36 -0
  322. package/ccw/dist/types/tool.d.ts.map +1 -0
  323. package/ccw/dist/types/tool.js +11 -0
  324. package/ccw/dist/types/tool.js.map +1 -0
  325. package/ccw/dist/utils/browser-launcher.d.ts +13 -0
  326. package/ccw/dist/utils/browser-launcher.d.ts.map +1 -0
  327. package/ccw/dist/utils/browser-launcher.js +60 -0
  328. package/ccw/dist/utils/browser-launcher.js.map +1 -0
  329. package/ccw/dist/utils/file-utils.d.ts +25 -0
  330. package/ccw/dist/utils/file-utils.d.ts.map +1 -0
  331. package/ccw/dist/utils/file-utils.js +48 -0
  332. package/ccw/dist/utils/file-utils.js.map +1 -0
  333. package/ccw/dist/utils/path-resolver.d.ts +80 -0
  334. package/ccw/dist/utils/path-resolver.d.ts.map +1 -0
  335. package/ccw/dist/utils/path-resolver.js +260 -0
  336. package/ccw/dist/utils/path-resolver.js.map +1 -0
  337. package/ccw/dist/utils/path-validator.d.ts +49 -0
  338. package/ccw/dist/utils/path-validator.d.ts.map +1 -0
  339. package/ccw/dist/utils/path-validator.js +123 -0
  340. package/ccw/dist/utils/path-validator.js.map +1 -0
  341. package/ccw/dist/utils/ui.d.ts +62 -0
  342. package/ccw/dist/utils/ui.d.ts.map +1 -0
  343. package/ccw/dist/utils/ui.js +129 -0
  344. package/ccw/dist/utils/ui.js.map +1 -0
  345. package/ccw/package.json +1 -1
  346. package/package.json +5 -2
@@ -0,0 +1,834 @@
1
+ /**
2
+ * Session Manager Tool - Workflow session lifecycle management
3
+ * Operations: init, list, read, write, update, archive, mkdir, delete, stats
4
+ * Content routing via content_type + path_params
5
+ */
6
+ import { z } from 'zod';
7
+ import { readFileSync, writeFileSync, existsSync, readdirSync, mkdirSync, renameSync, rmSync, } from 'fs';
8
+ import { resolve, join, dirname } from 'path';
9
+ // Base paths for session storage
10
+ const WORKFLOW_BASE = '.workflow';
11
+ const ACTIVE_BASE = '.workflow/active';
12
+ const ARCHIVE_BASE = '.workflow/archives';
13
+ const LITE_PLAN_BASE = '.workflow/.lite-plan';
14
+ const LITE_FIX_BASE = '.workflow/.lite-fix';
15
+ // Session ID validation pattern (alphanumeric, hyphen, underscore)
16
+ const SESSION_ID_PATTERN = /^[a-zA-Z0-9_-]+$/;
17
+ // Zod schemas - using tuple syntax for z.enum
18
+ const ContentTypeEnum = z.enum([
19
+ 'session', 'plan', 'task', 'summary', 'process', 'chat', 'brainstorm',
20
+ 'review-dim', 'review-iter', 'review-fix', 'todo', 'context',
21
+ // Lite-specific content types
22
+ 'lite-plan', 'lite-fix-plan', 'exploration', 'explorations-manifest',
23
+ 'diagnosis', 'diagnoses-manifest', 'clarifications', 'execution-context', 'session-metadata'
24
+ ]);
25
+ const OperationEnum = z.enum(['init', 'list', 'read', 'write', 'update', 'archive', 'mkdir', 'delete', 'stats']);
26
+ const LocationEnum = z.enum([
27
+ 'active', 'archived', 'both',
28
+ 'lite-plan', 'lite-fix', 'all'
29
+ ]);
30
+ const ParamsSchema = z.object({
31
+ operation: OperationEnum,
32
+ session_id: z.string().optional(),
33
+ content_type: ContentTypeEnum.optional(),
34
+ content: z.union([z.string(), z.record(z.string(), z.any())]).optional(),
35
+ path_params: z.record(z.string(), z.string()).optional(),
36
+ metadata: z.record(z.string(), z.any()).optional(),
37
+ location: LocationEnum.optional(),
38
+ include_metadata: z.boolean().optional(),
39
+ dirs: z.array(z.string()).optional(),
40
+ update_status: z.boolean().optional(),
41
+ file_path: z.string().optional(),
42
+ });
43
+ // Cached workflow root (computed once per execution)
44
+ let cachedWorkflowRoot = null;
45
+ /**
46
+ * Find project root by traversing up looking for .workflow directory
47
+ * Falls back to cwd if not found
48
+ */
49
+ function findWorkflowRoot() {
50
+ if (cachedWorkflowRoot)
51
+ return cachedWorkflowRoot;
52
+ let dir = process.cwd();
53
+ const root = dirname(dir) === dir ? dir : null; // filesystem root
54
+ while (dir && dir !== root) {
55
+ if (existsSync(join(dir, WORKFLOW_BASE))) {
56
+ cachedWorkflowRoot = dir;
57
+ return dir;
58
+ }
59
+ const parent = dirname(dir);
60
+ if (parent === dir)
61
+ break; // reached filesystem root
62
+ dir = parent;
63
+ }
64
+ // Fallback to cwd (for init operation)
65
+ cachedWorkflowRoot = process.cwd();
66
+ return cachedWorkflowRoot;
67
+ }
68
+ /**
69
+ * Validate session ID format
70
+ */
71
+ function validateSessionId(sessionId) {
72
+ if (!sessionId || typeof sessionId !== 'string') {
73
+ throw new Error('session_id must be a non-empty string');
74
+ }
75
+ if (!SESSION_ID_PATTERN.test(sessionId)) {
76
+ throw new Error(`Invalid session_id format: "${sessionId}". Only alphanumeric, hyphen, and underscore allowed.`);
77
+ }
78
+ if (sessionId.length > 100) {
79
+ throw new Error('session_id must be 100 characters or less');
80
+ }
81
+ }
82
+ /**
83
+ * Validate path params to prevent path traversal
84
+ */
85
+ function validatePathParams(pathParams) {
86
+ for (const [key, value] of Object.entries(pathParams)) {
87
+ if (typeof value !== 'string')
88
+ continue;
89
+ if (value.includes('..') || value.includes('/') || value.includes('\\')) {
90
+ throw new Error(`Invalid path_params.${key}: path traversal characters not allowed`);
91
+ }
92
+ }
93
+ }
94
+ /**
95
+ * Content type to file path routing
96
+ * {base} is replaced with session base path
97
+ * Dynamic params: {task_id}, {filename}, {dimension}, {iteration}
98
+ */
99
+ const PATH_ROUTES = {
100
+ // Standard WFS content types
101
+ session: '{base}/workflow-session.json',
102
+ plan: '{base}/IMPL_PLAN.md',
103
+ task: '{base}/.task/{task_id}.json',
104
+ summary: '{base}/.summaries/{task_id}-summary.md',
105
+ process: '{base}/.process/{filename}',
106
+ chat: '{base}/.chat/{filename}',
107
+ brainstorm: '{base}/.brainstorming/{filename}',
108
+ 'review-dim': '{base}/.review/dimensions/{dimension}.json',
109
+ 'review-iter': '{base}/.review/iterations/{iteration}.json',
110
+ 'review-fix': '{base}/.review/fixes/{filename}',
111
+ todo: '{base}/TODO_LIST.md',
112
+ context: '{base}/context-package.json',
113
+ // Lite-specific content types
114
+ 'lite-plan': '{base}/plan.json',
115
+ 'lite-fix-plan': '{base}/fix-plan.json',
116
+ 'exploration': '{base}/exploration-{angle}.json',
117
+ 'explorations-manifest': '{base}/explorations-manifest.json',
118
+ 'diagnosis': '{base}/diagnosis-{angle}.json',
119
+ 'diagnoses-manifest': '{base}/diagnoses-manifest.json',
120
+ 'clarifications': '{base}/clarifications.json',
121
+ 'execution-context': '{base}/execution-context.json',
122
+ 'session-metadata': '{base}/session-metadata.json',
123
+ };
124
+ /**
125
+ * Resolve path with base and parameters
126
+ */
127
+ function resolvePath(base, contentType, pathParams = {}) {
128
+ const template = PATH_ROUTES[contentType];
129
+ if (!template) {
130
+ throw new Error(`Unknown content_type: ${contentType}. Valid types: ${Object.keys(PATH_ROUTES).join(', ')}`);
131
+ }
132
+ let path = template.replace('{base}', base);
133
+ // Replace dynamic parameters
134
+ for (const [key, value] of Object.entries(pathParams)) {
135
+ path = path.replace(`{${key}}`, value);
136
+ }
137
+ // Check for unreplaced placeholders
138
+ const unreplaced = path.match(/\{[^}]+\}/g);
139
+ if (unreplaced) {
140
+ throw new Error(`Missing path_params: ${unreplaced.join(', ')} for content_type "${contentType}"`);
141
+ }
142
+ return resolve(findWorkflowRoot(), path);
143
+ }
144
+ /**
145
+ * Get session base path
146
+ */
147
+ function getSessionBase(sessionId, location = 'active') {
148
+ const locationMap = {
149
+ 'active': ACTIVE_BASE,
150
+ 'archived': ARCHIVE_BASE,
151
+ 'lite-plan': LITE_PLAN_BASE,
152
+ 'lite-fix': LITE_FIX_BASE,
153
+ };
154
+ const basePath = locationMap[location] || ACTIVE_BASE;
155
+ return resolve(findWorkflowRoot(), basePath, sessionId);
156
+ }
157
+ /**
158
+ * Auto-detect session location by searching all known paths
159
+ * Search order: active, archives, lite-plan, lite-fix
160
+ */
161
+ function findSession(sessionId) {
162
+ const root = findWorkflowRoot();
163
+ const searchPaths = [
164
+ { path: resolve(root, ACTIVE_BASE, sessionId), location: 'active' },
165
+ { path: resolve(root, ARCHIVE_BASE, sessionId), location: 'archived' },
166
+ { path: resolve(root, LITE_PLAN_BASE, sessionId), location: 'lite-plan' },
167
+ { path: resolve(root, LITE_FIX_BASE, sessionId), location: 'lite-fix' },
168
+ ];
169
+ for (const { path, location } of searchPaths) {
170
+ if (existsSync(path)) {
171
+ return { path, location };
172
+ }
173
+ }
174
+ return null;
175
+ }
176
+ /**
177
+ * Ensure directory exists
178
+ */
179
+ function ensureDir(dirPath) {
180
+ if (!existsSync(dirPath)) {
181
+ mkdirSync(dirPath, { recursive: true });
182
+ }
183
+ }
184
+ /**
185
+ * Read JSON file safely
186
+ */
187
+ function readJsonFile(filePath) {
188
+ if (!existsSync(filePath)) {
189
+ throw new Error(`File not found: ${filePath}`);
190
+ }
191
+ try {
192
+ const content = readFileSync(filePath, 'utf8');
193
+ return JSON.parse(content);
194
+ }
195
+ catch (error) {
196
+ if (error instanceof SyntaxError) {
197
+ throw new Error(`Invalid JSON in ${filePath}: ${error.message}`);
198
+ }
199
+ throw new Error(`Failed to read ${filePath}: ${error.message}`);
200
+ }
201
+ }
202
+ /**
203
+ * Write JSON file with formatting
204
+ */
205
+ function writeJsonFile(filePath, data) {
206
+ ensureDir(dirname(filePath));
207
+ const content = JSON.stringify(data, null, 2);
208
+ writeFileSync(filePath, content, 'utf8');
209
+ }
210
+ /**
211
+ * Write text file
212
+ */
213
+ function writeTextFile(filePath, content) {
214
+ ensureDir(dirname(filePath));
215
+ writeFileSync(filePath, content, 'utf8');
216
+ }
217
+ // ============================================================
218
+ // Helper Functions
219
+ // ============================================================
220
+ /**
221
+ * List sessions in a specific directory
222
+ * @param dirPath - Directory to scan
223
+ * @param location - Location identifier for returned sessions
224
+ * @param prefix - Optional prefix filter (e.g., 'WFS-'), null means no filter
225
+ * @param includeMetadata - Whether to load metadata for each session
226
+ */
227
+ function listSessionsInDir(dirPath, location, prefix, includeMetadata) {
228
+ if (!existsSync(dirPath))
229
+ return [];
230
+ try {
231
+ const entries = readdirSync(dirPath, { withFileTypes: true });
232
+ return entries
233
+ .filter(e => e.isDirectory() && (prefix === null || e.name.startsWith(prefix)))
234
+ .map(e => {
235
+ const sessionInfo = { session_id: e.name, location };
236
+ if (includeMetadata) {
237
+ // Try multiple metadata file locations
238
+ const metaPaths = [
239
+ join(dirPath, e.name, 'workflow-session.json'),
240
+ join(dirPath, e.name, 'session-metadata.json'),
241
+ join(dirPath, e.name, 'explorations-manifest.json'),
242
+ join(dirPath, e.name, 'diagnoses-manifest.json'),
243
+ ];
244
+ for (const metaPath of metaPaths) {
245
+ if (existsSync(metaPath)) {
246
+ try {
247
+ sessionInfo.metadata = readJsonFile(metaPath);
248
+ break;
249
+ }
250
+ catch { /* continue */ }
251
+ }
252
+ }
253
+ }
254
+ return sessionInfo;
255
+ });
256
+ }
257
+ catch {
258
+ return [];
259
+ }
260
+ }
261
+ // ============================================================
262
+ // Operation Handlers
263
+ // ============================================================
264
+ /**
265
+ * Operation: init
266
+ * Create new session with directory structure
267
+ * Supports both WFS sessions and lite sessions (lite-plan, lite-fix)
268
+ */
269
+ function executeInit(params) {
270
+ const { session_id, metadata, location } = params;
271
+ if (!session_id) {
272
+ throw new Error('Parameter "session_id" is required for init');
273
+ }
274
+ // Validate session_id format
275
+ validateSessionId(session_id);
276
+ // Auto-infer location from metadata.type if location not explicitly provided
277
+ // Priority: explicit location > metadata.type > default 'active'
278
+ const sessionLocation = (location === 'active' || location === 'archived' || location === 'lite-plan' || location === 'lite-fix')
279
+ ? location
280
+ : (metadata?.type === 'lite-plan' ? 'lite-plan' :
281
+ metadata?.type === 'lite-fix' ? 'lite-fix' :
282
+ 'active');
283
+ // Check if session already exists (auto-detect all locations)
284
+ const existing = findSession(session_id);
285
+ if (existing) {
286
+ throw new Error(`Session "${session_id}" already exists in ${existing.location}`);
287
+ }
288
+ const sessionPath = getSessionBase(session_id, sessionLocation);
289
+ // Create session directory structure based on type
290
+ ensureDir(sessionPath);
291
+ let directoriesCreated = [];
292
+ if (sessionLocation === 'lite-plan' || sessionLocation === 'lite-fix') {
293
+ // Lite sessions: minimal structure, files created by workflow
294
+ // No subdirectories needed initially
295
+ directoriesCreated = [];
296
+ }
297
+ else {
298
+ // WFS sessions: standard structure
299
+ ensureDir(join(sessionPath, '.task'));
300
+ ensureDir(join(sessionPath, '.summaries'));
301
+ ensureDir(join(sessionPath, '.process'));
302
+ directoriesCreated = ['.task', '.summaries', '.process'];
303
+ }
304
+ // Create session metadata file if provided
305
+ let sessionMetadata = null;
306
+ if (metadata) {
307
+ const sessionFile = sessionLocation.startsWith('lite-')
308
+ ? join(sessionPath, 'session-metadata.json') // Lite sessions
309
+ : join(sessionPath, 'workflow-session.json'); // WFS sessions
310
+ const sessionData = {
311
+ session_id,
312
+ type: metadata?.type || sessionLocation, // Preserve user-specified type if provided
313
+ status: 'initialized',
314
+ created_at: new Date().toISOString(),
315
+ ...metadata,
316
+ };
317
+ writeJsonFile(sessionFile, sessionData);
318
+ sessionMetadata = sessionData;
319
+ }
320
+ return {
321
+ operation: 'init',
322
+ session_id,
323
+ location: sessionLocation,
324
+ path: sessionPath,
325
+ directories_created: directoriesCreated,
326
+ metadata: sessionMetadata,
327
+ message: `Session "${session_id}" initialized in ${sessionLocation}`,
328
+ };
329
+ }
330
+ /**
331
+ * Operation: list
332
+ * List sessions (active, archived, lite-plan, lite-fix, or all)
333
+ */
334
+ function executeList(params) {
335
+ const { location = 'both', include_metadata = false } = params;
336
+ const result = {
337
+ operation: 'list',
338
+ active: [],
339
+ archived: [],
340
+ litePlan: [],
341
+ liteFix: [],
342
+ total: 0,
343
+ };
344
+ const root = findWorkflowRoot();
345
+ // Helper to check if location should be included
346
+ const shouldInclude = (loc) => location === 'all' || location === 'both' || location === loc;
347
+ // List active sessions (WFS-* prefix)
348
+ if (shouldInclude('active')) {
349
+ result.active = listSessionsInDir(resolve(root, ACTIVE_BASE), 'active', 'WFS-', include_metadata);
350
+ }
351
+ // List archived sessions (WFS-* prefix)
352
+ if (shouldInclude('archived')) {
353
+ result.archived = listSessionsInDir(resolve(root, ARCHIVE_BASE), 'archived', 'WFS-', include_metadata);
354
+ }
355
+ // List lite-plan sessions (no prefix filter)
356
+ if (location === 'all' || location === 'lite-plan') {
357
+ result.litePlan = listSessionsInDir(resolve(root, LITE_PLAN_BASE), 'lite-plan', null, include_metadata);
358
+ }
359
+ // List lite-fix sessions (no prefix filter)
360
+ if (location === 'all' || location === 'lite-fix') {
361
+ result.liteFix = listSessionsInDir(resolve(root, LITE_FIX_BASE), 'lite-fix', null, include_metadata);
362
+ }
363
+ result.total = result.active.length + result.archived.length +
364
+ result.litePlan.length + result.liteFix.length;
365
+ return result;
366
+ }
367
+ /**
368
+ * Operation: read
369
+ * Read file content by content_type
370
+ */
371
+ function executeRead(params) {
372
+ const { session_id, content_type, path_params = {} } = params;
373
+ if (!session_id) {
374
+ throw new Error('Parameter "session_id" is required for read');
375
+ }
376
+ if (!content_type) {
377
+ throw new Error('Parameter "content_type" is required for read');
378
+ }
379
+ // Validate inputs
380
+ validateSessionId(session_id);
381
+ validatePathParams(path_params);
382
+ const session = findSession(session_id);
383
+ if (!session) {
384
+ throw new Error(`Session "${session_id}" not found`);
385
+ }
386
+ const filePath = resolvePath(session.path, content_type, path_params);
387
+ if (!existsSync(filePath)) {
388
+ throw new Error(`File not found: ${filePath}`);
389
+ }
390
+ // Read content
391
+ const rawContent = readFileSync(filePath, 'utf8');
392
+ // Parse JSON for JSON content types
393
+ const isJson = filePath.endsWith('.json');
394
+ const content = isJson ? JSON.parse(rawContent) : rawContent;
395
+ return {
396
+ operation: 'read',
397
+ session_id,
398
+ content_type,
399
+ path: filePath,
400
+ location: session.location,
401
+ content,
402
+ is_json: isJson,
403
+ };
404
+ }
405
+ /**
406
+ * Operation: write
407
+ * Write content to file by content_type
408
+ */
409
+ function executeWrite(params) {
410
+ const { session_id, content_type, content, path_params = {} } = params;
411
+ if (!session_id) {
412
+ throw new Error('Parameter "session_id" is required for write');
413
+ }
414
+ if (!content_type) {
415
+ throw new Error('Parameter "content_type" is required for write');
416
+ }
417
+ if (content === undefined) {
418
+ throw new Error('Parameter "content" is required for write');
419
+ }
420
+ // Validate inputs
421
+ validateSessionId(session_id);
422
+ validatePathParams(path_params);
423
+ const session = findSession(session_id);
424
+ if (!session) {
425
+ throw new Error(`Session "${session_id}" not found. Use init operation first.`);
426
+ }
427
+ const filePath = resolvePath(session.path, content_type, path_params);
428
+ const isJson = filePath.endsWith('.json');
429
+ // Write content
430
+ if (isJson) {
431
+ writeJsonFile(filePath, content);
432
+ }
433
+ else {
434
+ writeTextFile(filePath, typeof content === 'string' ? content : JSON.stringify(content, null, 2));
435
+ }
436
+ // Return written content for task/summary types
437
+ const returnContent = content_type === 'task' || content_type === 'summary' ? content : undefined;
438
+ return {
439
+ operation: 'write',
440
+ session_id,
441
+ content_type,
442
+ written_content: returnContent,
443
+ path: filePath,
444
+ location: session.location,
445
+ message: `File written successfully`,
446
+ };
447
+ }
448
+ /**
449
+ * Operation: update
450
+ * Update existing JSON file with shallow merge
451
+ */
452
+ function executeUpdate(params) {
453
+ const { session_id, content_type, content, path_params = {} } = params;
454
+ if (!session_id) {
455
+ throw new Error('Parameter "session_id" is required for update');
456
+ }
457
+ if (!content_type) {
458
+ throw new Error('Parameter "content_type" is required for update');
459
+ }
460
+ if (!content || typeof content !== 'object') {
461
+ throw new Error('Parameter "content" must be an object for update');
462
+ }
463
+ const session = findSession(session_id);
464
+ if (!session) {
465
+ throw new Error(`Session "${session_id}" not found`);
466
+ }
467
+ const filePath = resolvePath(session.path, content_type, path_params);
468
+ if (!filePath.endsWith('.json')) {
469
+ throw new Error('Update operation only supports JSON files');
470
+ }
471
+ // Read existing content or start with empty object
472
+ let existing = {};
473
+ if (existsSync(filePath)) {
474
+ existing = readJsonFile(filePath);
475
+ }
476
+ // Shallow merge
477
+ const merged = { ...existing, ...content };
478
+ writeJsonFile(filePath, merged);
479
+ return {
480
+ operation: 'update',
481
+ session_id,
482
+ content_type,
483
+ path: filePath,
484
+ location: session.location,
485
+ fields_updated: Object.keys(content),
486
+ merged_data: merged,
487
+ message: `File updated successfully`,
488
+ };
489
+ }
490
+ /**
491
+ * Operation: archive
492
+ * Move session from active to archives
493
+ */
494
+ function executeArchive(params) {
495
+ const { session_id, update_status = true } = params;
496
+ if (!session_id) {
497
+ throw new Error('Parameter "session_id" is required for archive');
498
+ }
499
+ // Find session in any location
500
+ const session = findSession(session_id);
501
+ if (!session) {
502
+ throw new Error(`Session "${session_id}" not found`);
503
+ }
504
+ // Lite sessions do not support archiving
505
+ if (session.location === 'lite-plan' || session.location === 'lite-fix') {
506
+ throw new Error(`Lite sessions (${session.location}) do not support archiving. Use delete operation instead.`);
507
+ }
508
+ // Determine archive destination based on source location
509
+ let archivePath;
510
+ if (session.location === 'active') {
511
+ archivePath = getSessionBase(session_id, 'archived');
512
+ }
513
+ else {
514
+ // Already archived
515
+ return {
516
+ operation: 'archive',
517
+ session_id,
518
+ status: 'already_archived',
519
+ path: session.path,
520
+ location: session.location,
521
+ message: `Session "${session_id}" is already archived`,
522
+ };
523
+ }
524
+ // Update status before archiving
525
+ if (update_status) {
526
+ const metadataFiles = [
527
+ join(session.path, 'workflow-session.json'),
528
+ join(session.path, 'session-metadata.json'),
529
+ join(session.path, 'explorations-manifest.json'),
530
+ ];
531
+ for (const metaFile of metadataFiles) {
532
+ if (existsSync(metaFile)) {
533
+ try {
534
+ const data = readJsonFile(metaFile);
535
+ data.status = 'completed';
536
+ data.archived_at = new Date().toISOString();
537
+ writeJsonFile(metaFile, data);
538
+ break;
539
+ }
540
+ catch { /* continue */ }
541
+ }
542
+ }
543
+ }
544
+ // Ensure archive directory exists
545
+ ensureDir(dirname(archivePath));
546
+ // Move session directory
547
+ renameSync(session.path, archivePath);
548
+ // Read session metadata after archiving
549
+ let sessionMetadata = null;
550
+ const metadataFiles = [
551
+ join(archivePath, 'workflow-session.json'),
552
+ join(archivePath, 'session-metadata.json'),
553
+ join(archivePath, 'explorations-manifest.json'),
554
+ ];
555
+ for (const metaFile of metadataFiles) {
556
+ if (existsSync(metaFile)) {
557
+ try {
558
+ sessionMetadata = readJsonFile(metaFile);
559
+ break;
560
+ }
561
+ catch { /* continue */ }
562
+ }
563
+ }
564
+ return {
565
+ operation: 'archive',
566
+ session_id,
567
+ status: 'archived',
568
+ source: session.path,
569
+ source_location: session.location,
570
+ destination: archivePath,
571
+ metadata: sessionMetadata,
572
+ message: `Session "${session_id}" archived from ${session.location}`,
573
+ };
574
+ }
575
+ /**
576
+ * Operation: mkdir
577
+ * Create directory structure within session
578
+ */
579
+ function executeMkdir(params) {
580
+ const { session_id, dirs } = params;
581
+ if (!session_id) {
582
+ throw new Error('Parameter "session_id" is required for mkdir');
583
+ }
584
+ if (!dirs || !Array.isArray(dirs) || dirs.length === 0) {
585
+ throw new Error('Parameter "dirs" must be a non-empty array');
586
+ }
587
+ const session = findSession(session_id);
588
+ if (!session) {
589
+ throw new Error(`Session "${session_id}" not found`);
590
+ }
591
+ const created = [];
592
+ for (const dir of dirs) {
593
+ const dirPath = join(session.path, dir);
594
+ ensureDir(dirPath);
595
+ created.push(dir);
596
+ }
597
+ return {
598
+ operation: 'mkdir',
599
+ session_id,
600
+ location: session.location,
601
+ directories_created: created,
602
+ message: `Created ${created.length} directories`,
603
+ };
604
+ }
605
+ /**
606
+ * Operation: delete
607
+ * Delete a file within session (security: path traversal prevention)
608
+ */
609
+ function executeDelete(params) {
610
+ const { session_id, file_path } = params;
611
+ if (!session_id) {
612
+ throw new Error('Parameter "session_id" is required for delete');
613
+ }
614
+ if (!file_path) {
615
+ throw new Error('Parameter "file_path" is required for delete');
616
+ }
617
+ // Validate session exists
618
+ const session = findSession(session_id);
619
+ if (!session) {
620
+ throw new Error(`Session "${session_id}" not found`);
621
+ }
622
+ // Security: Prevent path traversal
623
+ if (file_path.includes('..') || file_path.includes('\\')) {
624
+ throw new Error('Invalid file_path: path traversal characters not allowed');
625
+ }
626
+ // Construct absolute path
627
+ const absolutePath = resolve(session.path, file_path);
628
+ // Security: Verify path is within session directory
629
+ if (!absolutePath.startsWith(session.path)) {
630
+ throw new Error('Security error: file_path must be within session directory');
631
+ }
632
+ // Check file exists
633
+ if (!existsSync(absolutePath)) {
634
+ throw new Error(`File not found: ${file_path}`);
635
+ }
636
+ // Delete the file
637
+ rmSync(absolutePath, { force: true });
638
+ return {
639
+ operation: 'delete',
640
+ session_id,
641
+ deleted: file_path,
642
+ absolute_path: absolutePath,
643
+ message: `File deleted successfully`,
644
+ };
645
+ }
646
+ /**
647
+ * Operation: stats
648
+ * Get session statistics (tasks, summaries, plan)
649
+ */
650
+ function executeStats(params) {
651
+ const { session_id } = params;
652
+ if (!session_id) {
653
+ throw new Error('Parameter "session_id" is required for stats');
654
+ }
655
+ // Validate session exists
656
+ const session = findSession(session_id);
657
+ if (!session) {
658
+ throw new Error(`Session "${session_id}" not found`);
659
+ }
660
+ const taskDir = join(session.path, '.task');
661
+ const summariesDir = join(session.path, '.summaries');
662
+ const planFile = join(session.path, 'IMPL_PLAN.md');
663
+ // Count tasks by status
664
+ const taskStats = {
665
+ total: 0,
666
+ pending: 0,
667
+ in_progress: 0,
668
+ completed: 0,
669
+ blocked: 0,
670
+ cancelled: 0,
671
+ };
672
+ if (existsSync(taskDir)) {
673
+ const taskFiles = readdirSync(taskDir).filter((f) => f.endsWith('.json'));
674
+ taskStats.total = taskFiles.length;
675
+ for (const taskFile of taskFiles) {
676
+ try {
677
+ const taskPath = join(taskDir, taskFile);
678
+ const taskData = readJsonFile(taskPath);
679
+ const status = taskData.status || 'unknown';
680
+ if (status in taskStats) {
681
+ taskStats[status]++;
682
+ }
683
+ }
684
+ catch {
685
+ // Skip invalid task files
686
+ }
687
+ }
688
+ }
689
+ // Count summaries
690
+ let summariesCount = 0;
691
+ if (existsSync(summariesDir)) {
692
+ summariesCount = readdirSync(summariesDir).filter((f) => f.endsWith('.md')).length;
693
+ }
694
+ // Check for plan
695
+ const hasPlan = existsSync(planFile);
696
+ return {
697
+ operation: 'stats',
698
+ session_id,
699
+ location: session.location,
700
+ tasks: taskStats,
701
+ summaries: summariesCount,
702
+ has_plan: hasPlan,
703
+ message: `Session statistics retrieved`,
704
+ };
705
+ }
706
+ // ============================================================
707
+ // Main Execute Function
708
+ // ============================================================
709
+ /**
710
+ * Route to appropriate operation handler
711
+ */
712
+ async function execute(params) {
713
+ const { operation } = params;
714
+ if (!operation) {
715
+ throw new Error('Parameter "operation" is required. Valid operations: init, list, read, write, update, archive, mkdir, delete, stats');
716
+ }
717
+ switch (operation) {
718
+ case 'init':
719
+ return executeInit(params);
720
+ case 'list':
721
+ return executeList(params);
722
+ case 'read':
723
+ return executeRead(params);
724
+ case 'write':
725
+ return executeWrite(params);
726
+ case 'update':
727
+ return executeUpdate(params);
728
+ case 'archive':
729
+ return executeArchive(params);
730
+ case 'mkdir':
731
+ return executeMkdir(params);
732
+ case 'delete':
733
+ return executeDelete(params);
734
+ case 'stats':
735
+ return executeStats(params);
736
+ default:
737
+ throw new Error(`Unknown operation: ${operation}. Valid operations: init, list, read, write, update, archive, mkdir, delete, stats`);
738
+ }
739
+ }
740
+ // ============================================================
741
+ // Tool Definition
742
+ // ============================================================
743
+ export const schema = {
744
+ name: 'session_manager',
745
+ description: `Workflow session management.
746
+
747
+ Usage:
748
+ session_manager(operation="init", type="workflow", description="...")
749
+ session_manager(operation="list", location="active|archived|both")
750
+ session_manager(operation="read", sessionId="WFS-xxx", contentType="plan|task|summary")
751
+ session_manager(operation="write", sessionId="WFS-xxx", contentType="plan", content={...})
752
+ session_manager(operation="archive", sessionId="WFS-xxx")
753
+ session_manager(operation="stats", sessionId="WFS-xxx")`,
754
+ inputSchema: {
755
+ type: 'object',
756
+ properties: {
757
+ operation: {
758
+ type: 'string',
759
+ enum: ['init', 'list', 'read', 'write', 'update', 'archive', 'mkdir', 'delete', 'stats'],
760
+ description: 'Operation to perform',
761
+ },
762
+ session_id: {
763
+ type: 'string',
764
+ description: 'Session identifier (e.g., WFS-my-session). Required for all operations except list.',
765
+ },
766
+ content_type: {
767
+ type: 'string',
768
+ enum: [
769
+ 'session',
770
+ 'plan',
771
+ 'task',
772
+ 'summary',
773
+ 'process',
774
+ 'chat',
775
+ 'brainstorm',
776
+ 'review-dim',
777
+ 'review-iter',
778
+ 'review-fix',
779
+ 'todo',
780
+ 'context',
781
+ ],
782
+ description: 'Content type for read/write/update operations',
783
+ },
784
+ content: {
785
+ type: 'object',
786
+ description: 'Content for write/update operations (object for JSON, string for text)',
787
+ },
788
+ path_params: {
789
+ type: 'object',
790
+ description: 'Dynamic path parameters: task_id, filename, dimension, iteration',
791
+ },
792
+ metadata: {
793
+ type: 'object',
794
+ description: 'Session metadata for init operation (project, type, description, etc.)',
795
+ },
796
+ location: {
797
+ type: 'string',
798
+ enum: ['active', 'archived', 'both'],
799
+ description: 'Session location filter for list operation (default: both)',
800
+ },
801
+ include_metadata: {
802
+ type: 'boolean',
803
+ description: 'Include session metadata in list results (default: false)',
804
+ },
805
+ dirs: {
806
+ type: 'array',
807
+ description: 'Directory paths to create for mkdir operation',
808
+ },
809
+ update_status: {
810
+ type: 'boolean',
811
+ description: 'Update session status to completed when archiving (default: true)',
812
+ },
813
+ file_path: {
814
+ type: 'string',
815
+ description: 'Relative file path within session for delete operation',
816
+ },
817
+ },
818
+ required: ['operation'],
819
+ },
820
+ };
821
+ export async function handler(params) {
822
+ const parsed = ParamsSchema.safeParse(params);
823
+ if (!parsed.success) {
824
+ return { success: false, error: `Invalid params: ${parsed.error.message}` };
825
+ }
826
+ try {
827
+ const result = await execute(parsed.data);
828
+ return { success: true, result };
829
+ }
830
+ catch (error) {
831
+ return { success: false, error: error.message };
832
+ }
833
+ }
834
+ //# sourceMappingURL=session-manager.js.map