@crewx/sdk 0.8.0-rc.73 → 0.8.0-rc.75

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 (548) hide show
  1. package/README.md +380 -818
  2. package/dist/adapter/context-builder.d.ts +35 -0
  3. package/dist/adapter/context-builder.js +87 -0
  4. package/dist/adapter/index.d.ts +5 -0
  5. package/dist/{core/remote → adapter}/index.js +3 -2
  6. package/dist/adapter/plugin-helper.d.ts +19 -0
  7. package/dist/adapter/plugin-helper.js +45 -0
  8. package/dist/adapter/scoped-store.d.ts +12 -0
  9. package/dist/adapter/scoped-store.js +43 -0
  10. package/dist/adapter/types.d.ts +264 -0
  11. package/dist/adapter/types.js +23 -0
  12. package/dist/agent/resolver.d.ts +18 -0
  13. package/dist/agent/resolver.js +46 -0
  14. package/dist/boxing/box-storage.interface.d.ts +12 -0
  15. package/dist/boxing/box-storage.interface.js +3 -0
  16. package/dist/boxing/box.service.d.ts +4 -0
  17. package/dist/boxing/box.service.js +5 -1
  18. package/dist/boxing/box.types.d.ts +4 -0
  19. package/dist/boxing/box.types.js +3 -0
  20. package/dist/boxing/context-builder.d.ts +6 -7
  21. package/dist/boxing/context-builder.js +3 -0
  22. package/dist/client/CrewxClient.d.ts +65 -0
  23. package/dist/client/CrewxClient.js +86 -0
  24. package/dist/client/index.d.ts +3 -0
  25. package/dist/client/index.js +6 -0
  26. package/dist/config/loader.browser.d.ts +14 -0
  27. package/dist/config/loader.browser.js +59 -0
  28. package/dist/config/loader.d.ts +19 -0
  29. package/dist/config/loader.js +95 -0
  30. package/dist/conversation/index.d.ts +5 -3
  31. package/dist/conversation/index.js +8 -3
  32. package/dist/conversation/sqlite-provider.d.ts +21 -0
  33. package/dist/conversation/sqlite-provider.js +178 -0
  34. package/dist/conversation/to-task-reader.d.ts +14 -0
  35. package/dist/conversation/to-task-reader.js +28 -0
  36. package/dist/conversation/to-template-messages.d.ts +15 -0
  37. package/dist/conversation/to-template-messages.js +34 -0
  38. package/dist/conversation/types.d.ts +101 -0
  39. package/dist/conversation/types.js +10 -0
  40. package/dist/esm/agent/resolver.js +41 -0
  41. package/dist/esm/boxing/box-storage.interface.js +5 -0
  42. package/dist/esm/boxing/box.service.js +69 -0
  43. package/dist/esm/boxing/box.types.js +5 -0
  44. package/dist/esm/boxing/context-builder.js +76 -0
  45. package/dist/esm/client/CrewxClient.js +82 -0
  46. package/dist/esm/client/index.js +2 -0
  47. package/dist/esm/config/loader.browser.js +54 -0
  48. package/dist/esm/config/loader.js +77 -0
  49. package/dist/esm/events/TypedEventEmitter.js +61 -0
  50. package/dist/esm/events/types.js +8 -0
  51. package/dist/esm/facade/Crewx.browser.js +310 -0
  52. package/dist/esm/facade/Crewx.js +941 -0
  53. package/dist/esm/hooks/define.js +10 -0
  54. package/dist/esm/hooks/dispatch.js +76 -0
  55. package/dist/esm/hooks/index.js +6 -0
  56. package/dist/esm/hooks/observer.js +56 -0
  57. package/dist/esm/hooks/plugin.js +12 -0
  58. package/dist/esm/hooks/types.js +9 -0
  59. package/dist/esm/index.browser.js +15 -0
  60. package/dist/esm/index.js +60 -0
  61. package/dist/esm/layout/loader.js +268 -0
  62. package/dist/esm/layout/props-validator.js +297 -0
  63. package/dist/esm/layout/renderer.js +180 -0
  64. package/dist/esm/layout/types.js +31 -0
  65. package/dist/esm/parallel/agent-runtime.js +21 -0
  66. package/dist/esm/parallel/helpers.js +214 -0
  67. package/dist/esm/parallel/index.js +5 -0
  68. package/dist/esm/parallel/parallel-runner.js +221 -0
  69. package/dist/esm/parallel/types.js +5 -0
  70. package/dist/esm/parsers/agent-call.util.js +15 -0
  71. package/dist/esm/parsers/claude.parser.js +64 -0
  72. package/dist/esm/parsers/codex.parser.js +97 -0
  73. package/dist/esm/parsers/copilot.parser.js +63 -0
  74. package/dist/esm/parsers/gemini.parser.js +43 -0
  75. package/dist/esm/parsers/opencode.parser.js +73 -0
  76. package/dist/esm/parsers/router.js +53 -0
  77. package/dist/esm/platform/BrowserFsAdapter.js +80 -0
  78. package/dist/esm/platform/IFsAdapter.js +2 -0
  79. package/dist/esm/platform/NodeFsAdapter.js +34 -0
  80. package/dist/esm/plugin/plugin-provider.js +202 -0
  81. package/dist/esm/plugin/types.js +8 -0
  82. package/dist/esm/plugin.js +25 -0
  83. package/dist/esm/provider/bridge.browser.js +43 -0
  84. package/dist/esm/provider/bridge.js +373 -0
  85. package/dist/esm/provider/parse-usage.js +80 -0
  86. package/dist/esm/provider/register-api.js +21 -0
  87. package/dist/esm/provider/vercel-runtime.js +310 -0
  88. package/dist/esm/remote/index.js +10 -0
  89. package/dist/esm/remote/remote-agent-manager.js +194 -0
  90. package/dist/esm/remote/remote-provider.js +98 -0
  91. package/dist/esm/remote/remote-transport.js +79 -0
  92. package/dist/esm/remote/types.js +8 -0
  93. package/dist/esm/server/auth.js +31 -0
  94. package/dist/esm/server/handler.js +72 -0
  95. package/dist/esm/server/index.js +5 -0
  96. package/dist/esm/server/tool-adapter.js +92 -0
  97. package/dist/esm/template/engine.js +100 -0
  98. package/dist/esm/template/helpers/exec.browser.js +31 -0
  99. package/dist/esm/template/helpers/exec.js +220 -0
  100. package/dist/esm/template/helpers/fenced_code.js +17 -0
  101. package/dist/esm/template/helpers/include.js +20 -0
  102. package/dist/esm/template/helpers/p1p2.js +83 -0
  103. package/dist/esm/template/loader/DocumentLoader.js +124 -0
  104. package/dist/esm/template/types.js +5 -0
  105. package/dist/esm/tools/delegate.js +57 -0
  106. package/dist/esm/tools/index.js +5 -0
  107. package/dist/esm/tools/node/builtin.js +541 -0
  108. package/dist/esm/tools/node/index.js +54 -0
  109. package/dist/esm/types/index.js +27 -0
  110. package/dist/esm/types/task-log.types.js +5 -0
  111. package/dist/esm/utils/env-defaults.js +23 -0
  112. package/dist/esm/utils/glob-match.js +38 -0
  113. package/dist/esm/utils/id.js +46 -0
  114. package/dist/esm/utils/workspace.js +21 -0
  115. package/dist/events/TypedEventEmitter.d.ts +31 -0
  116. package/dist/events/TypedEventEmitter.js +65 -0
  117. package/dist/events/types.d.ts +139 -0
  118. package/dist/events/types.js +9 -0
  119. package/dist/facade/Crewx.browser.d.ts +73 -0
  120. package/dist/facade/Crewx.browser.js +314 -0
  121. package/dist/facade/Crewx.d.ts +267 -0
  122. package/dist/facade/Crewx.js +1299 -0
  123. package/dist/hooks/define.d.ts +10 -0
  124. package/dist/hooks/define.js +13 -0
  125. package/dist/hooks/dispatch.d.ts +61 -0
  126. package/dist/hooks/dispatch.js +147 -0
  127. package/dist/hooks/index.d.ts +13 -0
  128. package/dist/hooks/index.js +24 -0
  129. package/dist/hooks/observer.d.ts +20 -0
  130. package/dist/hooks/observer.js +60 -0
  131. package/dist/hooks/plugin.d.ts +19 -0
  132. package/dist/hooks/plugin.js +17 -0
  133. package/dist/hooks/tool-normalize.d.ts +29 -0
  134. package/dist/hooks/tool-normalize.js +110 -0
  135. package/dist/hooks/types.d.ts +79 -0
  136. package/dist/hooks/types.js +12 -0
  137. package/dist/hooks/yaml-plugin.d.ts +29 -0
  138. package/dist/hooks/yaml-plugin.js +356 -0
  139. package/dist/index.browser.d.ts +15 -0
  140. package/dist/index.browser.js +25 -0
  141. package/dist/index.d.ts +70 -58
  142. package/dist/index.js +144 -133
  143. package/dist/{services/layout-loader.service.d.ts → layout/loader.d.ts} +24 -4
  144. package/dist/{services/layout-loader.service.js → layout/loader.js} +103 -73
  145. package/dist/{services/props-validator.service.d.ts → layout/props-validator.d.ts} +7 -1
  146. package/dist/{services/props-validator.service.js → layout/props-validator.js} +28 -59
  147. package/dist/{services/layout-renderer.service.d.ts → layout/renderer.d.ts} +28 -14
  148. package/dist/layout/renderer.js +193 -0
  149. package/dist/{types/layout.types.d.ts → layout/types.d.ts} +47 -1
  150. package/dist/{types/layout.types.js → layout/types.js} +15 -1
  151. package/dist/parallel/agent-runtime.d.ts +31 -0
  152. package/dist/parallel/agent-runtime.js +25 -0
  153. package/dist/{core/parallel → parallel}/helpers.d.ts +2 -1
  154. package/dist/{core/parallel → parallel}/helpers.js +55 -88
  155. package/dist/parallel/index.d.ts +8 -0
  156. package/dist/{core/parallel → parallel}/index.js +5 -3
  157. package/dist/{core/parallel → parallel}/parallel-runner.d.ts +8 -1
  158. package/dist/{core/parallel → parallel}/parallel-runner.js +53 -57
  159. package/dist/parallel/types.d.ts +65 -0
  160. package/dist/parallel/types.js +6 -0
  161. package/dist/parsers/agent-call.util.d.ts +3 -0
  162. package/dist/parsers/agent-call.util.js +2 -0
  163. package/dist/parsers/api.parser.d.ts +10 -0
  164. package/dist/parsers/api.parser.js +26 -0
  165. package/dist/parsers/claude.parser.d.ts +8 -0
  166. package/dist/parsers/claude.parser.js +22 -1
  167. package/dist/parsers/codex.parser.d.ts +8 -0
  168. package/dist/parsers/codex.parser.js +11 -0
  169. package/dist/parsers/copilot.parser.d.ts +9 -0
  170. package/dist/parsers/copilot.parser.js +8 -0
  171. package/dist/parsers/gemini.parser.d.ts +10 -0
  172. package/dist/parsers/gemini.parser.js +10 -0
  173. package/dist/parsers/opencode.parser.d.ts +12 -0
  174. package/dist/parsers/opencode.parser.js +76 -0
  175. package/dist/parsers/router.d.ts +7 -0
  176. package/dist/parsers/router.js +56 -0
  177. package/dist/platform/BrowserFsAdapter.d.ts +37 -0
  178. package/dist/platform/BrowserFsAdapter.js +84 -0
  179. package/dist/platform/IFsAdapter.d.ts +29 -0
  180. package/dist/{core/remote/types.js → platform/IFsAdapter.js} +1 -1
  181. package/dist/platform/NodeFsAdapter.d.ts +16 -0
  182. package/dist/platform/NodeFsAdapter.js +38 -0
  183. package/dist/plugin/plugin-provider.d.ts +33 -0
  184. package/dist/plugin/plugin-provider.js +207 -0
  185. package/dist/plugin/types.d.ts +53 -0
  186. package/dist/plugin/types.js +9 -0
  187. package/dist/plugin.d.ts +33 -0
  188. package/dist/plugin.js +29 -0
  189. package/dist/plugins/conversation.d.ts +18 -0
  190. package/dist/plugins/conversation.js +59 -0
  191. package/dist/plugins/file-logger.d.ts +29 -0
  192. package/dist/plugins/file-logger.js +87 -0
  193. package/dist/plugins/index.d.ts +16 -0
  194. package/dist/plugins/index.js +19 -0
  195. package/dist/plugins/sqlite-tracing.d.ts +29 -0
  196. package/dist/plugins/sqlite-tracing.js +112 -0
  197. package/dist/provider/bridge.browser.d.ts +49 -0
  198. package/dist/provider/bridge.browser.js +49 -0
  199. package/dist/provider/bridge.d.ts +106 -0
  200. package/dist/provider/bridge.js +380 -0
  201. package/dist/provider/mastra-runtime.d.ts +45 -0
  202. package/dist/provider/mastra-runtime.js +208 -0
  203. package/dist/provider/parse-usage.d.ts +20 -0
  204. package/dist/provider/parse-usage.js +83 -0
  205. package/dist/provider/register-api.d.ts +14 -0
  206. package/dist/provider/register-api.js +24 -0
  207. package/dist/provider/vercel-runtime.d.ts +54 -0
  208. package/dist/provider/vercel-runtime.js +347 -0
  209. package/dist/remote/index.d.ts +13 -0
  210. package/dist/remote/index.js +32 -0
  211. package/dist/remote/remote-agent-manager.d.ts +54 -0
  212. package/dist/{core/remote → remote}/remote-agent-manager.js +100 -97
  213. package/dist/remote/remote-provider.d.ts +47 -0
  214. package/dist/remote/remote-provider.js +141 -0
  215. package/dist/remote/remote-transport.d.ts +32 -0
  216. package/dist/remote/remote-transport.js +83 -0
  217. package/dist/remote/types.d.ts +147 -0
  218. package/dist/remote/types.js +9 -0
  219. package/dist/server/auth.d.ts +21 -0
  220. package/dist/server/auth.js +35 -0
  221. package/dist/server/handler.d.ts +24 -0
  222. package/dist/server/handler.js +75 -0
  223. package/dist/server/index.d.ts +7 -0
  224. package/dist/server/index.js +9 -0
  225. package/dist/server/tool-adapter.d.ts +19 -0
  226. package/dist/server/tool-adapter.js +95 -0
  227. package/dist/template/engine.d.ts +28 -0
  228. package/dist/template/engine.js +137 -0
  229. package/dist/template/helpers/exec.browser.d.ts +22 -0
  230. package/dist/template/helpers/exec.browser.js +41 -0
  231. package/dist/template/helpers/exec.d.ts +60 -0
  232. package/dist/template/helpers/exec.js +230 -0
  233. package/dist/template/helpers/fenced_code.d.ts +22 -0
  234. package/dist/template/helpers/fenced_code.js +20 -0
  235. package/dist/template/helpers/format-conversation.d.ts +30 -0
  236. package/dist/template/helpers/format-conversation.js +53 -0
  237. package/dist/template/helpers/include.d.ts +16 -0
  238. package/dist/template/helpers/include.js +23 -0
  239. package/dist/template/helpers/p1p2.d.ts +37 -0
  240. package/dist/template/helpers/p1p2.js +90 -0
  241. package/dist/template/loader/DocumentLoader.d.ts +48 -0
  242. package/dist/template/loader/DocumentLoader.js +128 -0
  243. package/dist/template/types.d.ts +51 -0
  244. package/dist/template/types.js +6 -0
  245. package/dist/testing/index.d.ts +12 -0
  246. package/dist/testing/index.js +16 -0
  247. package/dist/testing/mock-audit.d.ts +10 -0
  248. package/dist/testing/mock-audit.js +13 -0
  249. package/dist/testing/mock-context.d.ts +27 -0
  250. package/dist/testing/mock-context.js +68 -0
  251. package/dist/testing/mock-logger.d.ts +15 -0
  252. package/dist/testing/mock-logger.js +27 -0
  253. package/dist/testing/mock-router.d.ts +16 -0
  254. package/dist/testing/mock-router.js +67 -0
  255. package/dist/testing/mock-storage.d.ts +9 -0
  256. package/dist/testing/mock-storage.js +21 -0
  257. package/dist/testing/mock-store.d.ts +3 -0
  258. package/dist/testing/mock-store.js +8 -0
  259. package/dist/tools/delegate.d.ts +10 -0
  260. package/dist/tools/delegate.js +60 -0
  261. package/dist/tools/index.d.ts +5 -12
  262. package/dist/tools/index.js +6 -37
  263. package/dist/tools/node/builtin.d.ts +23 -0
  264. package/dist/tools/node/builtin.js +547 -0
  265. package/dist/tools/node/index.d.ts +23 -0
  266. package/dist/tools/node/index.js +59 -0
  267. package/dist/types/index.d.ts +804 -6
  268. package/dist/types/index.js +29 -20
  269. package/dist/types/task-log.types.d.ts +4 -0
  270. package/dist/types/task-log.types.js +3 -0
  271. package/dist/utils/env-defaults.d.ts +18 -0
  272. package/dist/utils/env-defaults.js +27 -0
  273. package/dist/utils/glob-match.d.ts +18 -0
  274. package/dist/utils/glob-match.js +42 -0
  275. package/dist/{core → utils}/id.d.ts +15 -0
  276. package/dist/utils/id.js +50 -0
  277. package/dist/utils/timestamp.d.ts +2 -0
  278. package/dist/utils/timestamp.js +13 -0
  279. package/dist/{core → utils}/workspace.d.ts +4 -0
  280. package/dist/{core → utils}/workspace.js +3 -0
  281. package/package.json +68 -103
  282. package/src/schemas/hooks.schema.json +59 -0
  283. package/templates/agents/default.yaml +490 -0
  284. package/templates/agents/minimal.yaml +16 -0
  285. package/LICENSE +0 -201
  286. package/dist/adapters/MastraToolAdapter.d.ts +0 -9
  287. package/dist/adapters/MastraToolAdapter.js +0 -66
  288. package/dist/adapters/MastraToolAdapter.js.map +0 -1
  289. package/dist/api/index.d.ts +0 -2
  290. package/dist/api/index.js +0 -8
  291. package/dist/api/index.js.map +0 -1
  292. package/dist/boxing/box-storage.interface.js.map +0 -1
  293. package/dist/boxing/box.service.js.map +0 -1
  294. package/dist/boxing/box.types.js.map +0 -1
  295. package/dist/boxing/context-builder.js.map +0 -1
  296. package/dist/boxing/index.d.ts +0 -6
  297. package/dist/boxing/index.js +0 -11
  298. package/dist/boxing/index.js.map +0 -1
  299. package/dist/boxing/tokenizer.d.ts +0 -3
  300. package/dist/boxing/tokenizer.js +0 -11
  301. package/dist/boxing/tokenizer.js.map +0 -1
  302. package/dist/config/api-provider-parser.d.ts +0 -58
  303. package/dist/config/api-provider-parser.js +0 -212
  304. package/dist/config/api-provider-parser.js.map +0 -1
  305. package/dist/config/index.d.ts +0 -3
  306. package/dist/config/index.js +0 -20
  307. package/dist/config/index.js.map +0 -1
  308. package/dist/config/log.config.d.ts +0 -7
  309. package/dist/config/log.config.js +0 -20
  310. package/dist/config/log.config.js.map +0 -1
  311. package/dist/config/pricing.d.ts +0 -11
  312. package/dist/config/pricing.js +0 -53
  313. package/dist/config/pricing.js.map +0 -1
  314. package/dist/config/timeout.config.d.ts +0 -14
  315. package/dist/config/timeout.config.js +0 -34
  316. package/dist/config/timeout.config.js.map +0 -1
  317. package/dist/config/yaml-loader.d.ts +0 -8
  318. package/dist/config/yaml-loader.js +0 -155
  319. package/dist/config/yaml-loader.js.map +0 -1
  320. package/dist/constants/index.d.ts +0 -4
  321. package/dist/constants/index.js +0 -8
  322. package/dist/constants/index.js.map +0 -1
  323. package/dist/constants.d.ts +0 -1
  324. package/dist/constants.js +0 -18
  325. package/dist/constants.js.map +0 -1
  326. package/dist/conversation/conversation-config.d.ts +0 -9
  327. package/dist/conversation/conversation-config.js +0 -22
  328. package/dist/conversation/conversation-config.js.map +0 -1
  329. package/dist/conversation/conversation-history.interface.d.ts +0 -36
  330. package/dist/conversation/conversation-history.interface.js +0 -3
  331. package/dist/conversation/conversation-history.interface.js.map +0 -1
  332. package/dist/conversation/conversation-storage.service.d.ts +0 -16
  333. package/dist/conversation/conversation-storage.service.js +0 -213
  334. package/dist/conversation/conversation-storage.service.js.map +0 -1
  335. package/dist/conversation/index.js.map +0 -1
  336. package/dist/core/__tests__/id.test.d.ts +0 -1
  337. package/dist/core/__tests__/id.test.js +0 -115
  338. package/dist/core/__tests__/id.test.js.map +0 -1
  339. package/dist/core/agent/agent-factory.d.ts +0 -37
  340. package/dist/core/agent/agent-factory.js +0 -68
  341. package/dist/core/agent/agent-factory.js.map +0 -1
  342. package/dist/core/agent/agent-runtime.d.ts +0 -52
  343. package/dist/core/agent/agent-runtime.js +0 -206
  344. package/dist/core/agent/agent-runtime.js.map +0 -1
  345. package/dist/core/agent/event-bus.d.ts +0 -44
  346. package/dist/core/agent/event-bus.js +0 -43
  347. package/dist/core/agent/event-bus.js.map +0 -1
  348. package/dist/core/agent/index.d.ts +0 -3
  349. package/dist/core/agent/index.js +0 -13
  350. package/dist/core/agent/index.js.map +0 -1
  351. package/dist/core/env-defaults.d.ts +0 -1
  352. package/dist/core/env-defaults.js +0 -7
  353. package/dist/core/env-defaults.js.map +0 -1
  354. package/dist/core/id.js +0 -27
  355. package/dist/core/id.js.map +0 -1
  356. package/dist/core/parallel/helpers.js.map +0 -1
  357. package/dist/core/parallel/index.d.ts +0 -4
  358. package/dist/core/parallel/index.js.map +0 -1
  359. package/dist/core/parallel/parallel-runner.js.map +0 -1
  360. package/dist/core/parallel/types.d.ts +0 -41
  361. package/dist/core/parallel/types.js +0 -3
  362. package/dist/core/parallel/types.js.map +0 -1
  363. package/dist/core/providers/MastraAPIProvider.d.ts +0 -31
  364. package/dist/core/providers/MastraAPIProvider.js +0 -365
  365. package/dist/core/providers/MastraAPIProvider.js.map +0 -1
  366. package/dist/core/providers/ai-provider.interface.d.ts +0 -79
  367. package/dist/core/providers/ai-provider.interface.js +0 -23
  368. package/dist/core/providers/ai-provider.interface.js.map +0 -1
  369. package/dist/core/providers/base-ai.provider.d.ts +0 -84
  370. package/dist/core/providers/base-ai.provider.js +0 -1237
  371. package/dist/core/providers/base-ai.provider.js.map +0 -1
  372. package/dist/core/providers/base-ai.types.d.ts +0 -26
  373. package/dist/core/providers/base-ai.types.js +0 -3
  374. package/dist/core/providers/base-ai.types.js.map +0 -1
  375. package/dist/core/providers/claude.provider.d.ts +0 -19
  376. package/dist/core/providers/claude.provider.js +0 -170
  377. package/dist/core/providers/claude.provider.js.map +0 -1
  378. package/dist/core/providers/codex.provider.d.ts +0 -21
  379. package/dist/core/providers/codex.provider.js +0 -134
  380. package/dist/core/providers/codex.provider.js.map +0 -1
  381. package/dist/core/providers/copilot.provider.d.ts +0 -25
  382. package/dist/core/providers/copilot.provider.js +0 -146
  383. package/dist/core/providers/copilot.provider.js.map +0 -1
  384. package/dist/core/providers/dynamic-provider.factory.d.ts +0 -74
  385. package/dist/core/providers/dynamic-provider.factory.js +0 -645
  386. package/dist/core/providers/dynamic-provider.factory.js.map +0 -1
  387. package/dist/core/providers/gemini.provider.d.ts +0 -16
  388. package/dist/core/providers/gemini.provider.js +0 -101
  389. package/dist/core/providers/gemini.provider.js.map +0 -1
  390. package/dist/core/providers/index.d.ts +0 -8
  391. package/dist/core/providers/index.js +0 -20
  392. package/dist/core/providers/index.js.map +0 -1
  393. package/dist/core/providers/mock.provider.d.ts +0 -13
  394. package/dist/core/providers/mock.provider.js +0 -55
  395. package/dist/core/providers/mock.provider.js.map +0 -1
  396. package/dist/core/providers/provider-factory.d.ts +0 -3
  397. package/dist/core/providers/provider-factory.js +0 -65
  398. package/dist/core/providers/provider-factory.js.map +0 -1
  399. package/dist/core/providers/tool-call.types.d.ts +0 -39
  400. package/dist/core/providers/tool-call.types.js +0 -3
  401. package/dist/core/providers/tool-call.types.js.map +0 -1
  402. package/dist/core/remote/index.d.ts +0 -3
  403. package/dist/core/remote/index.js.map +0 -1
  404. package/dist/core/remote/remote-agent-manager.d.ts +0 -24
  405. package/dist/core/remote/remote-agent-manager.js.map +0 -1
  406. package/dist/core/remote/remote-transport.d.ts +0 -15
  407. package/dist/core/remote/remote-transport.js +0 -70
  408. package/dist/core/remote/remote-transport.js.map +0 -1
  409. package/dist/core/remote/types.d.ts +0 -79
  410. package/dist/core/remote/types.js.map +0 -1
  411. package/dist/core/workspace.js.map +0 -1
  412. package/dist/index.js.map +0 -1
  413. package/dist/internal/index.d.ts +0 -1
  414. package/dist/internal/index.js +0 -6
  415. package/dist/internal/index.js.map +0 -1
  416. package/dist/knowledge/DocumentManager.d.ts +0 -4
  417. package/dist/knowledge/DocumentManager.js +0 -119
  418. package/dist/knowledge/DocumentManager.js.map +0 -1
  419. package/dist/knowledge/index.d.ts +0 -1
  420. package/dist/knowledge/index.js +0 -18
  421. package/dist/knowledge/index.js.map +0 -1
  422. package/dist/parsers/agent-call.util.js.map +0 -1
  423. package/dist/parsers/claude.parser.js.map +0 -1
  424. package/dist/parsers/codex.parser.js.map +0 -1
  425. package/dist/parsers/copilot.parser.js.map +0 -1
  426. package/dist/parsers/gemini.parser.js.map +0 -1
  427. package/dist/parsers/index.d.ts +0 -7
  428. package/dist/parsers/index.js +0 -45
  429. package/dist/parsers/index.js.map +0 -1
  430. package/dist/schema/skills-parser.d.ts +0 -8
  431. package/dist/schema/skills-parser.js +0 -438
  432. package/dist/schema/skills-parser.js.map +0 -1
  433. package/dist/schema/skills.types.d.ts +0 -158
  434. package/dist/schema/skills.types.js +0 -41
  435. package/dist/schema/skills.types.js.map +0 -1
  436. package/dist/schemas/api-provider.schema.d.ts +0 -432
  437. package/dist/schemas/api-provider.schema.js +0 -50
  438. package/dist/schemas/api-provider.schema.js.map +0 -1
  439. package/dist/services/index.d.ts +0 -2
  440. package/dist/services/index.js +0 -19
  441. package/dist/services/index.js.map +0 -1
  442. package/dist/services/layout-loader.service.js.map +0 -1
  443. package/dist/services/layout-renderer.service.js +0 -325
  444. package/dist/services/layout-renderer.service.js.map +0 -1
  445. package/dist/services/props-validator.service.js.map +0 -1
  446. package/dist/skills/adapter/claude-skill-adapter.d.ts +0 -11
  447. package/dist/skills/adapter/claude-skill-adapter.js +0 -222
  448. package/dist/skills/adapter/claude-skill-adapter.js.map +0 -1
  449. package/dist/skills/index.d.ts +0 -6
  450. package/dist/skills/index.js +0 -31
  451. package/dist/skills/index.js.map +0 -1
  452. package/dist/skills/runtime/progressive-loader.d.ts +0 -27
  453. package/dist/skills/runtime/progressive-loader.js +0 -186
  454. package/dist/skills/runtime/progressive-loader.js.map +0 -1
  455. package/dist/skills/runtime/runtime-requirements-validator.d.ts +0 -23
  456. package/dist/skills/runtime/runtime-requirements-validator.js +0 -248
  457. package/dist/skills/runtime/runtime-requirements-validator.js.map +0 -1
  458. package/dist/skills/runtime/skill-runtime.service.d.ts +0 -42
  459. package/dist/skills/runtime/skill-runtime.service.js +0 -434
  460. package/dist/skills/runtime/skill-runtime.service.js.map +0 -1
  461. package/dist/tools/file-system.service.d.ts +0 -10
  462. package/dist/tools/file-system.service.js +0 -33
  463. package/dist/tools/file-system.service.js.map +0 -1
  464. package/dist/tools/find.tool.d.ts +0 -21
  465. package/dist/tools/find.tool.js +0 -139
  466. package/dist/tools/find.tool.js.map +0 -1
  467. package/dist/tools/glob.tool.d.ts +0 -24
  468. package/dist/tools/glob.tool.js +0 -153
  469. package/dist/tools/glob.tool.js.map +0 -1
  470. package/dist/tools/grep.tool.d.ts +0 -1
  471. package/dist/tools/grep.tool.js +0 -137
  472. package/dist/tools/grep.tool.js.map +0 -1
  473. package/dist/tools/index.js.map +0 -1
  474. package/dist/tools/ls.tool.d.ts +0 -1
  475. package/dist/tools/ls.tool.js +0 -94
  476. package/dist/tools/ls.tool.js.map +0 -1
  477. package/dist/tools/read-file.tool.d.ts +0 -1
  478. package/dist/tools/read-file.tool.js +0 -69
  479. package/dist/tools/read-file.tool.js.map +0 -1
  480. package/dist/tools/replace.tool.d.ts +0 -1
  481. package/dist/tools/replace.tool.js +0 -68
  482. package/dist/tools/replace.tool.js.map +0 -1
  483. package/dist/tools/run-shell-command.tool.d.ts +0 -1
  484. package/dist/tools/run-shell-command.tool.js +0 -64
  485. package/dist/tools/run-shell-command.tool.js.map +0 -1
  486. package/dist/tools/tree.tool.d.ts +0 -1
  487. package/dist/tools/tree.tool.js +0 -109
  488. package/dist/tools/tree.tool.js.map +0 -1
  489. package/dist/tools/types.d.ts +0 -42
  490. package/dist/tools/types.js +0 -13
  491. package/dist/tools/types.js.map +0 -1
  492. package/dist/tools/utils/file-utils.d.ts +0 -5
  493. package/dist/tools/utils/file-utils.js +0 -221
  494. package/dist/tools/utils/file-utils.js.map +0 -1
  495. package/dist/tools/write-file.tool.d.ts +0 -1
  496. package/dist/tools/write-file.tool.js +0 -55
  497. package/dist/tools/write-file.tool.js.map +0 -1
  498. package/dist/types/agent.types.d.ts +0 -134
  499. package/dist/types/agent.types.js +0 -16
  500. package/dist/types/agent.types.js.map +0 -1
  501. package/dist/types/api-provider.types.d.ts +0 -85
  502. package/dist/types/api-provider.types.js +0 -65
  503. package/dist/types/api-provider.types.js.map +0 -1
  504. package/dist/types/index.js.map +0 -1
  505. package/dist/types/layout.types.js.map +0 -1
  506. package/dist/types/provider.types.d.ts +0 -12
  507. package/dist/types/provider.types.js +0 -3
  508. package/dist/types/provider.types.js.map +0 -1
  509. package/dist/types/skill-runtime.types.d.ts +0 -244
  510. package/dist/types/skill-runtime.types.js +0 -44
  511. package/dist/types/skill-runtime.types.js.map +0 -1
  512. package/dist/types/structured-payload.types.d.ts +0 -46
  513. package/dist/types/structured-payload.types.js +0 -65
  514. package/dist/types/structured-payload.types.js.map +0 -1
  515. package/dist/types/task-log.types.js.map +0 -1
  516. package/dist/types/template.types.d.ts +0 -38
  517. package/dist/types/template.types.js +0 -3
  518. package/dist/types/template.types.js.map +0 -1
  519. package/dist/types.d.ts +0 -1
  520. package/dist/types.js +0 -18
  521. package/dist/types.js.map +0 -1
  522. package/dist/utils/api-provider-normalizer.d.ts +0 -16
  523. package/dist/utils/api-provider-normalizer.js +0 -135
  524. package/dist/utils/api-provider-normalizer.js.map +0 -1
  525. package/dist/utils/base-message-formatter.d.ts +0 -32
  526. package/dist/utils/base-message-formatter.js +0 -170
  527. package/dist/utils/base-message-formatter.js.map +0 -1
  528. package/dist/utils/error-utils.d.ts +0 -3
  529. package/dist/utils/error-utils.js +0 -27
  530. package/dist/utils/error-utils.js.map +0 -1
  531. package/dist/utils/index.d.ts +0 -4
  532. package/dist/utils/index.js +0 -21
  533. package/dist/utils/index.js.map +0 -1
  534. package/dist/utils/math-utils.d.ts +0 -3
  535. package/dist/utils/math-utils.js +0 -10
  536. package/dist/utils/math-utils.js.map +0 -1
  537. package/dist/utils/mention-parser.d.ts +0 -18
  538. package/dist/utils/mention-parser.js +0 -136
  539. package/dist/utils/mention-parser.js.map +0 -1
  540. package/dist/utils/string-utils.d.ts +0 -1
  541. package/dist/utils/string-utils.js +0 -10
  542. package/dist/utils/string-utils.js.map +0 -1
  543. package/dist/utils.d.ts +0 -3
  544. package/dist/utils.js +0 -20
  545. package/dist/utils.js.map +0 -1
  546. package/schema/api-provider-config.json +0 -138
  547. package/schema/crewx-config.json +0 -224
  548. package/schema/skills-config.json +0 -306
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Remote Agent Module — Type Definitions
3
+ *
4
+ * Types for remote agent communication via MCP (Model Context Protocol).
5
+ * Migrated from sdk-bak/src/core/remote/types.ts and adapted to SDK conventions.
6
+ */
7
+ export {};
8
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1,31 @@
1
+ /**
2
+ * MCP Server authentication & Origin validation.
3
+ *
4
+ * - Origin header 검증 (DNS rebinding 방어, MCP 스펙 필수)
5
+ * - 커스텀 auth 콜백 래퍼
6
+ */
7
+ /**
8
+ * Validate the Origin header is present (MCP spec requirement).
9
+ * Returns a 403 Response if validation fails, or null if ok.
10
+ */
11
+ export function validateOrigin(req) {
12
+ const origin = req.headers.get('Origin');
13
+ if (!origin) {
14
+ return new Response(JSON.stringify({ error: 'Forbidden: Origin header required' }), { status: 403, headers: { 'Content-Type': 'application/json' } });
15
+ }
16
+ return null;
17
+ }
18
+ /**
19
+ * Run the custom auth callback if provided.
20
+ * Returns a 401 Response if auth fails, or null if ok.
21
+ */
22
+ export async function runAuthCallback(req, auth) {
23
+ if (!auth)
24
+ return null;
25
+ const allowed = await auth(req);
26
+ if (!allowed) {
27
+ return new Response(JSON.stringify({ error: 'Unauthorized' }), { status: 401, headers: { 'Content-Type': 'application/json' } });
28
+ }
29
+ return null;
30
+ }
31
+ //# sourceMappingURL=auth.js.map
@@ -0,0 +1,72 @@
1
+ /**
2
+ * crewx.handler() — Framework-independent MCP HTTP handler.
3
+ *
4
+ * Returns a Web Standard `(req: Request) => Promise<Response>` handler
5
+ * that can be mounted on Express, Next.js, Hono, Bun, etc.
6
+ */
7
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
8
+ import { WebStandardStreamableHTTPServerTransport, } from '@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js';
9
+ import { registerCrewxTools } from './tool-adapter';
10
+ import { validateOrigin, runAuthCallback } from './auth';
11
+ /**
12
+ * Create a fresh McpServer with tools registered.
13
+ */
14
+ function createMcpServer(crewx, allowedAgents) {
15
+ const mcpServer = new McpServer({
16
+ name: 'crewx-mcp-server',
17
+ version: '1.0.0',
18
+ }, {
19
+ capabilities: {
20
+ tools: {},
21
+ },
22
+ });
23
+ registerCrewxTools(mcpServer, crewx, allowedAgents);
24
+ return mcpServer;
25
+ }
26
+ /**
27
+ * Create an MCP handler bound to the given Crewx instance.
28
+ *
29
+ * @param crewx - Crewx facade instance
30
+ * @param options - Handler configuration (agents list required)
31
+ * @returns Web Standard request handler
32
+ */
33
+ export function createHandler(crewx, options) {
34
+ if (!options.agents || options.agents.length === 0) {
35
+ throw new Error('crewx.handler() requires at least one agent in the agents option');
36
+ }
37
+ const allowedAgents = new Set(options.agents);
38
+ // Per-session transport + server map
39
+ const sessions = new Map();
40
+ return async (req) => {
41
+ // ── Security: Origin validation ──────────────────────────────────────
42
+ const originError = validateOrigin(req);
43
+ if (originError)
44
+ return originError;
45
+ // ── Security: Custom auth callback ───────────────────────────────────
46
+ const authError = await runAuthCallback(req, options.auth);
47
+ if (authError)
48
+ return authError;
49
+ // ── Route to transport ───────────────────────────────────────────────
50
+ const sessionId = req.headers.get('mcp-session-id');
51
+ if (sessionId && sessions.has(sessionId)) {
52
+ // Existing session — reuse transport
53
+ const session = sessions.get(sessionId);
54
+ return session.transport.handleRequest(req);
55
+ }
56
+ // New session: create McpServer + transport pair
57
+ const mcpServer = createMcpServer(crewx, allowedAgents);
58
+ const transport = new WebStandardStreamableHTTPServerTransport({
59
+ sessionIdGenerator: () => crypto.randomUUID(),
60
+ onsessioninitialized: (sid) => {
61
+ sessions.set(sid, { transport, server: mcpServer });
62
+ },
63
+ onsessionclosed: (sid) => {
64
+ sessions.delete(sid);
65
+ },
66
+ enableJsonResponse: true,
67
+ });
68
+ await mcpServer.connect(transport);
69
+ return transport.handleRequest(req);
70
+ };
71
+ }
72
+ //# sourceMappingURL=handler.js.map
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @crewx/sdk server module — MCP HTTP handler for exposing agents.
3
+ */
4
+ export { createHandler } from './handler';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,92 @@
1
+ /**
2
+ * MCP tool adapter — 범용 MCP 도구 3개를 McpServer에 등록한다.
3
+ *
4
+ * 도구:
5
+ * crewx_queryAgent(agentId, query, context?, thread?)
6
+ * crewx_executeAgent(agentId, task, context?, thread?)
7
+ * crewx_listAgents()
8
+ */
9
+ import { z } from 'zod';
10
+ const querySchema = {
11
+ agentId: z.string().describe('The agent ID to query'),
12
+ query: z.string().describe('The query message to send'),
13
+ context: z.string().optional().describe('Additional context'),
14
+ thread: z.string().optional().describe('Thread ID for conversation continuity'),
15
+ };
16
+ const executeSchema = {
17
+ agentId: z.string().describe('The agent ID to execute'),
18
+ task: z.string().describe('The task description to execute'),
19
+ context: z.string().optional().describe('Additional context'),
20
+ thread: z.string().optional().describe('Thread ID for conversation continuity'),
21
+ };
22
+ /**
23
+ * Register the 3 universal tools on the given McpServer.
24
+ *
25
+ * @param server - McpServer instance
26
+ * @param crewx - Crewx facade instance
27
+ * @param allowedAgents - Set of agent IDs exposed via handler
28
+ */
29
+ export function registerCrewxTools(server, crewx, allowedAgents) {
30
+ // ── crewx_listAgents (no schema — zero-arg tool) ────────────────────────
31
+ server.tool('crewx_listAgents', 'List available CrewX agents exposed by this server', async () => {
32
+ const agents = [];
33
+ for (const agentId of allowedAgents) {
34
+ const agent = crewx.agents.get(agentId);
35
+ if (agent) {
36
+ agents.push({
37
+ id: agent.id,
38
+ name: agent.name ?? agent.id,
39
+ description: agent.description ?? '',
40
+ });
41
+ }
42
+ }
43
+ return {
44
+ content: [{ type: 'text', text: JSON.stringify(agents, null, 2) }],
45
+ };
46
+ });
47
+ // ── crewx_queryAgent ────────────────────────────────────────────────────
48
+ server.tool('crewx_queryAgent', 'Query a CrewX agent with a read-only question', querySchema, async ({ agentId, query, context, thread }) => {
49
+ if (!allowedAgents.has(agentId)) {
50
+ return {
51
+ content: [{ type: 'text', text: `Agent '${agentId}' is not exposed by this server` }],
52
+ isError: true,
53
+ };
54
+ }
55
+ const result = await crewx.query(agentId, query, {
56
+ context,
57
+ threadId: thread,
58
+ });
59
+ if (!result.ok) {
60
+ return {
61
+ content: [{ type: 'text', text: result.error?.message ?? 'Query failed' }],
62
+ isError: true,
63
+ };
64
+ }
65
+ return {
66
+ content: [{ type: 'text', text: result.data }],
67
+ };
68
+ });
69
+ // ── crewx_executeAgent ──────────────────────────────────────────────────
70
+ server.tool('crewx_executeAgent', 'Execute a task on a CrewX agent (may modify state)', executeSchema, async ({ agentId, task, context, thread }) => {
71
+ if (!allowedAgents.has(agentId)) {
72
+ return {
73
+ content: [{ type: 'text', text: `Agent '${agentId}' is not exposed by this server` }],
74
+ isError: true,
75
+ };
76
+ }
77
+ const result = await crewx.execute(agentId, task, {
78
+ context,
79
+ threadId: thread,
80
+ });
81
+ if (!result.ok) {
82
+ return {
83
+ content: [{ type: 'text', text: result.error?.message ?? 'Execute failed' }],
84
+ isError: true,
85
+ };
86
+ }
87
+ return {
88
+ content: [{ type: 'text', text: result.data }],
89
+ };
90
+ });
91
+ }
92
+ //# sourceMappingURL=tool-adapter.js.map
@@ -0,0 +1,100 @@
1
+ /**
2
+ * CrewX template engine — Handlebars-based rendering with P0 helpers.
3
+ *
4
+ * P0 helpers implemented here:
5
+ * - exec : shell command execution (5-stage security)
6
+ * - include : inline string content passthrough
7
+ * - fenced_code : Markdown fenced code block wrapper
8
+ * - eq, ne, and, or, not, json (condition helpers)
9
+ */
10
+ import * as Handlebars from 'handlebars';
11
+ import { executeCommand } from './helpers/exec';
12
+ import { includeHelper } from './helpers/include';
13
+ import { fencedCodeHelper } from './helpers/fenced_code';
14
+ import { truncateHelper, lengthHelper, escapeHandlebarsHelper, formatFileSizeHelper, formatTimestampHelper, } from './helpers/p1p2';
15
+ export class TemplateEngine {
16
+ hbs;
17
+ execPolicy;
18
+ execEnabled;
19
+ constructor(options = {}) {
20
+ // Create an isolated Handlebars environment to avoid global state conflicts
21
+ this.hbs = Handlebars.create();
22
+ this.execPolicy = options.execPolicy ?? { allow: [], deny: [] };
23
+ this.execEnabled = options.execEnabled ?? true;
24
+ this.registerHelpers();
25
+ }
26
+ /**
27
+ * Register all P0 helpers onto this engine's Handlebars instance.
28
+ */
29
+ registerHelpers() {
30
+ const hbs = this.hbs;
31
+ const policy = this.execPolicy;
32
+ // ── exec: shell command execution ────────────────────────────────────────
33
+ const execEnabled = this.execEnabled;
34
+ hbs.registerHelper('exec', function (command) {
35
+ if (typeof command !== 'string')
36
+ return '';
37
+ if (!execEnabled)
38
+ return '(exec disabled)';
39
+ return new hbs.SafeString(executeCommand(command, policy));
40
+ });
41
+ // ── include: inline string passthrough ───────────────────────────────────
42
+ hbs.registerHelper('include', function (content) {
43
+ return new hbs.SafeString(includeHelper(content));
44
+ });
45
+ // ── fenced_code: Markdown code block wrapper ──────────────────────────────
46
+ hbs.registerHelper('fenced_code', function (content, options) {
47
+ return new hbs.SafeString(fencedCodeHelper(content, options));
48
+ });
49
+ // ── Condition helpers ─────────────────────────────────────────────────────
50
+ hbs.registerHelper('eq', function (a, b) {
51
+ return a === b;
52
+ });
53
+ hbs.registerHelper('ne', function (a, b) {
54
+ return a !== b;
55
+ });
56
+ hbs.registerHelper('and', function (a, b) {
57
+ return a && b;
58
+ });
59
+ hbs.registerHelper('or', function (a, b) {
60
+ return a || b;
61
+ });
62
+ hbs.registerHelper('not', function (a) {
63
+ return !a;
64
+ });
65
+ hbs.registerHelper('contains', function (array, value) {
66
+ return Array.isArray(array) && array.includes(value);
67
+ });
68
+ hbs.registerHelper('json', function (context) {
69
+ return JSON.stringify(context, null, 2);
70
+ });
71
+ // ── P1 helpers ────────────────────────────────────────────────────────────
72
+ hbs.registerHelper('truncate', function (text, maxLength) {
73
+ return truncateHelper(text, maxLength);
74
+ });
75
+ hbs.registerHelper('length', function (value) {
76
+ return lengthHelper(value);
77
+ });
78
+ hbs.registerHelper('escapeHandlebars', function (text) {
79
+ return new hbs.SafeString(escapeHandlebarsHelper(text));
80
+ });
81
+ // ── P2 helpers ────────────────────────────────────────────────────────────
82
+ hbs.registerHelper('formatFileSize', function (bytes) {
83
+ return formatFileSizeHelper(bytes);
84
+ });
85
+ hbs.registerHelper('formatTimestamp', function (timestamp) {
86
+ return formatTimestampHelper(timestamp);
87
+ });
88
+ }
89
+ /**
90
+ * Render a Handlebars template string with the given context.
91
+ * @param template - Handlebars template string
92
+ * @param context - Template context (documents, env, agent, etc.)
93
+ * @returns Rendered string
94
+ */
95
+ async render(template, context = {}) {
96
+ const compiled = this.hbs.compile(template, { noEscape: true });
97
+ return compiled(context);
98
+ }
99
+ }
100
+ //# sourceMappingURL=engine.js.map
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Browser stub for the exec helper.
3
+ *
4
+ * Replaces the Node.js exec helper in browser bundles (via package.json "browser" field).
5
+ * All functions are no-ops or return safe defaults — child_process is not available in browsers.
6
+ */
7
+ export function getSanitizedEnv() {
8
+ return {};
9
+ }
10
+ export function validateCommand(_command) {
11
+ // noop in browser
12
+ }
13
+ export function isBuiltinAllowed(_command) {
14
+ return false;
15
+ }
16
+ export function validateAllowPattern(_pattern) {
17
+ // noop in browser
18
+ }
19
+ export function isAllowed(_command, _policy) {
20
+ return false;
21
+ }
22
+ export function setAuditVerbose(_enabled) {
23
+ // noop in browser
24
+ }
25
+ export function logExecAudit(_entry) {
26
+ // noop in browser
27
+ }
28
+ export function executeCommand(_command, _policy) {
29
+ return '(exec disabled: browser environment)';
30
+ }
31
+ //# sourceMappingURL=exec.browser.js.map
@@ -0,0 +1,220 @@
1
+ /**
2
+ * exec Handlebars helper — 5-stage security implementation.
3
+ *
4
+ * Ports the security logic from packages/cli-bak/src/utils/template-processor.ts
5
+ * without using shell-quote or minimatch (not in allowed library list).
6
+ *
7
+ * Stages:
8
+ * 1. Recursion depth check (fail-closed on NaN)
9
+ * 2. Shell metacharacter validation
10
+ * 3. Allow-list enforcement (deny > builtin > allow > reject)
11
+ * 4. Environment isolation (strip sensitive keys)
12
+ * 5. Result capture (execFileSync with timeout + maxBuffer, wrapped in tags)
13
+ */
14
+ import { execFileSync } from 'child_process';
15
+ import { matchesPattern } from '../../utils/glob-match';
16
+ // Sensitive env key patterns — removed from exec child processes
17
+ const SENSITIVE_ENV_PATTERNS = [
18
+ /^ANTHROPIC_/i, /^OPENAI_/i, /^AWS_SECRET/i, /^SLACK_/i,
19
+ /^GITHUB_TOKEN$/i, /^CREWX_MCP_KEY$/i, /^DATABASE_/i,
20
+ /^AWS_ACCESS_KEY/i, /^AWS_SESSION_TOKEN$/i,
21
+ /^GH_TOKEN$/i, /^GH_APP_/i,
22
+ /^NPM_TOKEN$/i, /^NPM_AUTH/i,
23
+ /^GOOGLE_APPLICATION/i, /^GCLOUD_/i,
24
+ /^AZURE_/i, /^ARM_/i,
25
+ /^DOCKER_PASSWORD$/i, /^DOCKER_AUTH/i,
26
+ /^SSH_PRIVATE/i, /^SSH_AUTH_SOCK$/i,
27
+ /^CI_JOB_TOKEN$/i, /^ACTIONS_RUNTIME_TOKEN$/i,
28
+ /^VAULT_TOKEN$/i, /^SONAR_TOKEN$/i, /^CODECOV_TOKEN$/i,
29
+ /TOKEN$/i, /SECRET$/i, /PASSWORD$/i, /API_KEY$/i,
30
+ ];
31
+ // Shell metacharacter pattern — blocks command injection
32
+ const SHELL_METACHAR = /[;|&`$(){}!><\n\r]/;
33
+ // Max recursion depth for exec helper
34
+ const MAX_EXEC_DEPTH = 2;
35
+ // Overly broad patterns that must be rejected in allow/deny lists
36
+ const DANGEROUS_PATTERNS = ['*', '**', '*:*', '* *', '**/*'];
37
+ // ─────────────────────────────────────────────────────────────────────────────
38
+ // Stage 4: Environment isolation
39
+ // ─────────────────────────────────────────────────────────────────────────────
40
+ /**
41
+ * Returns a copy of process.env with all sensitive keys removed.
42
+ */
43
+ export function getSanitizedEnv() {
44
+ const env = {};
45
+ for (const [key, value] of Object.entries(process.env)) {
46
+ if (value === undefined)
47
+ continue;
48
+ if (SENSITIVE_ENV_PATTERNS.some(p => p.test(key)))
49
+ continue;
50
+ env[key] = value;
51
+ }
52
+ return env;
53
+ }
54
+ // ─────────────────────────────────────────────────────────────────────────────
55
+ // Stage 1: Shell metacharacter validation
56
+ // ─────────────────────────────────────────────────────────────────────────────
57
+ /**
58
+ * Validates a command string for shell metacharacter injection.
59
+ * @throws Error if shell metacharacters are detected.
60
+ */
61
+ export function validateCommand(command) {
62
+ if (SHELL_METACHAR.test(command)) {
63
+ throw new Error(`exec blocked: shell metacharacter detected in "${command}"`);
64
+ }
65
+ }
66
+ // ─────────────────────────────────────────────────────────────────────────────
67
+ // Stage 2: Allow-list enforcement
68
+ // ─────────────────────────────────────────────────────────────────────────────
69
+ /**
70
+ * Checks if a command matches the builtin allowed pattern.
71
+ * Only npx @crewx/<package> scope is allowed by default.
72
+ */
73
+ export function isBuiltinAllowed(command) {
74
+ return /^npx\s+@crewx\/[\w-]+/.test(command);
75
+ }
76
+ /**
77
+ * Validates allow/deny patterns — rejects overly broad wildcards.
78
+ * @throws Error if pattern is too broad or malformed.
79
+ */
80
+ export function validateAllowPattern(pattern) {
81
+ // Trim only for dangerous-pattern check (exact match list)
82
+ if (DANGEROUS_PATTERNS.includes(pattern.trim())) {
83
+ throw new Error(`exec config error: overly broad pattern "${pattern}" is not allowed`);
84
+ }
85
+ // Start-character check uses original pattern (space prefix → rejected)
86
+ if (!/^[\w./@-]/.test(pattern)) {
87
+ throw new Error(`exec config error: pattern must start with a command name`);
88
+ }
89
+ }
90
+ /**
91
+ * Checks if a command is allowed by the exec policy.
92
+ * Priority: deny > builtin(@crewx) > allow > reject
93
+ */
94
+ export function isAllowed(command, policy) {
95
+ const allow = policy.allow ?? [];
96
+ const deny = policy.deny ?? [];
97
+ // Validate patterns
98
+ for (const p of [...allow, ...deny]) {
99
+ validateAllowPattern(p);
100
+ }
101
+ // Step 1: deny takes highest priority
102
+ if (deny.some(pattern => matchesPattern(command, pattern)))
103
+ return false;
104
+ // Step 2: builtin allowed (@crewx/* scope only)
105
+ if (isBuiltinAllowed(command))
106
+ return true;
107
+ // Step 3: explicit allow patterns
108
+ return allow.some(pattern => matchesPattern(command, pattern));
109
+ }
110
+ // ─────────────────────────────────────────────────────────────────────────────
111
+ // Audit log
112
+ // ─────────────────────────────────────────────────────────────────────────────
113
+ /** When false (default), audit logs are suppressed. Set true via setAuditVerbose(). */
114
+ let _verboseAudit = false;
115
+ /**
116
+ * Enable or disable exec audit log output to stderr.
117
+ * Call with true to show span JSON (verbose mode); false to suppress (default).
118
+ */
119
+ export function setAuditVerbose(enabled) {
120
+ _verboseAudit = enabled;
121
+ }
122
+ /**
123
+ * Emits a structured audit log entry to stderr.
124
+ * Only writes when verbose audit mode is enabled via setAuditVerbose(true).
125
+ */
126
+ export function logExecAudit(entry) {
127
+ if (!_verboseAudit)
128
+ return;
129
+ const log = JSON.stringify({ span: 'template_exec', ...entry, timestamp: new Date().toISOString() });
130
+ console.error(log);
131
+ }
132
+ // ─────────────────────────────────────────────────────────────────────────────
133
+ // Simple shell argument parser (replaces shell-quote)
134
+ // ─────────────────────────────────────────────────────────────────────────────
135
+ /**
136
+ * Parses a command string into an array of arguments.
137
+ * Handles single and double quoted strings.
138
+ */
139
+ function parseShellArgs(command) {
140
+ const tokens = [];
141
+ let current = '';
142
+ let inSingle = false;
143
+ let inDouble = false;
144
+ for (let i = 0; i < command.length; i++) {
145
+ const ch = command[i];
146
+ if (ch === "'" && !inDouble) {
147
+ inSingle = !inSingle;
148
+ }
149
+ else if (ch === '"' && !inSingle) {
150
+ inDouble = !inDouble;
151
+ }
152
+ else if (ch === ' ' && !inSingle && !inDouble) {
153
+ if (current.length > 0) {
154
+ tokens.push(current);
155
+ current = '';
156
+ }
157
+ }
158
+ else {
159
+ current += ch;
160
+ }
161
+ }
162
+ if (current.length > 0)
163
+ tokens.push(current);
164
+ return tokens;
165
+ }
166
+ // ─────────────────────────────────────────────────────────────────────────────
167
+ // Stage 3 + 5: Execute command with timeout and result capture
168
+ // ─────────────────────────────────────────────────────────────────────────────
169
+ /**
170
+ * Executes a command and returns the output wrapped in exec-output tags.
171
+ * Implements all 5 security stages.
172
+ */
173
+ export function executeCommand(command, policy) {
174
+ const startMs = Date.now();
175
+ // Stage 1: Recursion depth check (NaN fail-closed)
176
+ const execDepth = parseInt(process.env.CREWX_EXEC_DEPTH ?? '0', 10);
177
+ if (isNaN(execDepth) || execDepth >= MAX_EXEC_DEPTH) {
178
+ logExecAudit({ command, status: 'denied', reason: 'invalid or max recursion depth' });
179
+ return '(exec blocked: max recursion depth reached)';
180
+ }
181
+ // Stage 2a: Shell metacharacter validation
182
+ try {
183
+ validateCommand(command);
184
+ }
185
+ catch {
186
+ logExecAudit({ command, status: 'denied', reason: 'shell metacharacter detected' });
187
+ return `(exec blocked: shell metacharacter detected in "${command}")`;
188
+ }
189
+ // Stage 2b/c: Allow-list enforcement (deny > builtin > allow > reject)
190
+ if (!isAllowed(command, policy)) {
191
+ logExecAudit({ command, status: 'denied', reason: 'not in allow list' });
192
+ return `(exec blocked: ${command})`;
193
+ }
194
+ // Stage 3 + 4 + 5: Execute with timeout, env isolation, and result capture
195
+ try {
196
+ const parsed = parseShellArgs(command);
197
+ const [bin, ...args] = parsed;
198
+ if (!bin)
199
+ return `(exec failed: ${command})`;
200
+ // Stage 4: Environment isolation
201
+ const sanitizedEnv = getSanitizedEnv();
202
+ // Stage 3: Timeout + Stage 5: Result capture
203
+ const result = execFileSync(bin, args, {
204
+ timeout: policy.timeout ?? 5000,
205
+ maxBuffer: 64 * 1024, // 64KB — OOM prevention
206
+ encoding: 'utf-8',
207
+ env: { ...sanitizedEnv, CREWX_EXEC_DEPTH: String(execDepth + 1) },
208
+ stdio: ['pipe', 'pipe', 'pipe'],
209
+ });
210
+ const durationMs = Date.now() - startMs;
211
+ logExecAudit({ command, status: 'allowed', allowed_by: 'policy', duration_ms: durationMs });
212
+ // Stage 5: Wrap result in structured tags
213
+ return `<exec-output cmd="${command}">\n${result.trim()}\n</exec-output>`;
214
+ }
215
+ catch {
216
+ logExecAudit({ command, status: 'error', reason: 'execution failed' });
217
+ return `(exec failed: ${command})`;
218
+ }
219
+ }
220
+ //# sourceMappingURL=exec.js.map
@@ -0,0 +1,17 @@
1
+ /**
2
+ * fenced_code Handlebars helper — wraps content in a Markdown fenced code block.
3
+ *
4
+ * Usage in templates:
5
+ * {{fenced_code myCode lang="typescript"}}
6
+ * {{fenced_code myCode}} ← no language specified
7
+ */
8
+ /**
9
+ * Wraps content in a Markdown fenced code block.
10
+ * @param content - The code content to wrap.
11
+ * @param options - Handlebars options object (may contain hash.lang).
12
+ */
13
+ export function fencedCodeHelper(content, options) {
14
+ const lang = options?.hash?.lang ?? '';
15
+ return `\`\`\`${lang}\n${content ?? ''}\n\`\`\``;
16
+ }
17
+ //# sourceMappingURL=fenced_code.js.map
@@ -0,0 +1,20 @@
1
+ /**
2
+ * include Handlebars helper — returns inline string content as-is.
3
+ *
4
+ * Usage in templates:
5
+ * {{{include someVariable}}}
6
+ * {{{include "literal string"}}}
7
+ *
8
+ * Note: File-path based document loading is handled in SDK-006 (DocumentLoader).
9
+ * This helper supports only inline string content (already in context).
10
+ */
11
+ /**
12
+ * Returns the given string content unchanged.
13
+ * Returns empty string for null/undefined.
14
+ */
15
+ export function includeHelper(content) {
16
+ if (content === null || content === undefined)
17
+ return '';
18
+ return String(content);
19
+ }
20
+ //# sourceMappingURL=include.js.map