@crewx/cli 0.8.0-rc.66 → 0.8.0-rc.82

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 (281) hide show
  1. package/bin/crewx +2 -0
  2. package/dist/bootstrap/crewx-cli.d.ts +11 -0
  3. package/dist/bootstrap/crewx-cli.js +31 -0
  4. package/dist/builtin.d.ts +15 -0
  5. package/dist/{cli/builtin.handler.js → builtin.js} +21 -7
  6. package/dist/commands/agent.d.ts +12 -0
  7. package/dist/commands/agent.js +246 -0
  8. package/dist/commands/doctor.d.ts +12 -0
  9. package/dist/commands/doctor.js +190 -0
  10. package/dist/commands/execute.d.ts +21 -0
  11. package/dist/commands/execute.js +117 -0
  12. package/dist/commands/hook/install.d.ts +21 -0
  13. package/dist/commands/hook/install.js +175 -0
  14. package/dist/commands/hook/paths.d.ts +19 -0
  15. package/dist/commands/hook/paths.js +94 -0
  16. package/dist/commands/hook/status.d.ts +7 -0
  17. package/dist/commands/hook/status.js +86 -0
  18. package/dist/commands/hook/uninstall.d.ts +8 -0
  19. package/dist/commands/hook/uninstall.js +71 -0
  20. package/dist/commands/hook-dispatch.d.ts +15 -0
  21. package/dist/commands/hook-dispatch.js +180 -0
  22. package/dist/commands/init.d.ts +24 -0
  23. package/dist/commands/init.js +133 -0
  24. package/dist/commands/kill.d.ts +12 -0
  25. package/dist/commands/kill.js +49 -0
  26. package/dist/commands/log.d.ts +13 -0
  27. package/dist/commands/log.js +97 -0
  28. package/dist/commands/parse-agent-message.d.ts +31 -0
  29. package/dist/commands/parse-agent-message.js +52 -0
  30. package/dist/commands/parse-common-flags.d.ts +36 -0
  31. package/dist/commands/parse-common-flags.js +105 -0
  32. package/dist/commands/ps.d.ts +12 -0
  33. package/dist/commands/ps.js +71 -0
  34. package/dist/commands/query.d.ts +21 -0
  35. package/dist/commands/query.js +117 -0
  36. package/dist/commands/result.d.ts +13 -0
  37. package/dist/commands/result.js +73 -0
  38. package/dist/commands/slack.d.ts +12 -0
  39. package/dist/commands/slack.js +559 -0
  40. package/dist/commands/task-db.d.ts +33 -0
  41. package/dist/commands/task-db.js +107 -0
  42. package/dist/examples/deny-secrets-plugin.d.ts +22 -0
  43. package/dist/examples/deny-secrets-plugin.js +40 -0
  44. package/dist/index.d.ts +1 -0
  45. package/dist/index.js +5 -0
  46. package/dist/logging.d.ts +21 -0
  47. package/dist/logging.js +86 -0
  48. package/dist/main.d.ts +10 -0
  49. package/dist/main.js +246 -256
  50. package/dist/plugins/examples/echo-hook.d.ts +24 -0
  51. package/dist/plugins/examples/echo-hook.js +60 -0
  52. package/dist/plugins/examples/verify-echo-hook.d.ts +8 -0
  53. package/dist/plugins/examples/verify-echo-hook.js +47 -0
  54. package/dist/plugins/sqlite-tracing.d.ts +13 -0
  55. package/dist/plugins/sqlite-tracing.js +20 -0
  56. package/dist/register-builtin-tools.d.ts +5 -0
  57. package/dist/register-builtin-tools.js +9 -0
  58. package/dist/slack/file-download.d.ts +17 -0
  59. package/dist/slack/file-download.js +134 -0
  60. package/dist/slack/markdown.d.ts +5 -0
  61. package/dist/slack/markdown.js +33 -0
  62. package/dist/utils/env-defaults.d.ts +5 -0
  63. package/dist/utils/env-defaults.js +10 -0
  64. package/dist/utils/version.d.ts +1 -0
  65. package/dist/utils/version.js +28 -0
  66. package/package.json +32 -115
  67. package/README.md +0 -663
  68. package/dist/ai-provider.service.d.ts +0 -36
  69. package/dist/ai-provider.service.js +0 -315
  70. package/dist/ai-provider.service.js.map +0 -1
  71. package/dist/ai.service.d.ts +0 -17
  72. package/dist/ai.service.js +0 -51
  73. package/dist/ai.service.js.map +0 -1
  74. package/dist/app.module.d.ts +0 -5
  75. package/dist/app.module.js +0 -165
  76. package/dist/app.module.js.map +0 -1
  77. package/dist/cli/agent.handler.d.ts +0 -2
  78. package/dist/cli/agent.handler.js +0 -186
  79. package/dist/cli/agent.handler.js.map +0 -1
  80. package/dist/cli/builtin.handler.d.ts +0 -3
  81. package/dist/cli/builtin.handler.js.map +0 -1
  82. package/dist/cli/chat.handler.d.ts +0 -20
  83. package/dist/cli/chat.handler.js +0 -446
  84. package/dist/cli/chat.handler.js.map +0 -1
  85. package/dist/cli/cli.handler.d.ts +0 -4
  86. package/dist/cli/cli.handler.js +0 -119
  87. package/dist/cli/cli.handler.js.map +0 -1
  88. package/dist/cli/doctor.handler.d.ts +0 -38
  89. package/dist/cli/doctor.handler.js +0 -495
  90. package/dist/cli/doctor.handler.js.map +0 -1
  91. package/dist/cli/execute.handler.d.ts +0 -2
  92. package/dist/cli/execute.handler.js +0 -376
  93. package/dist/cli/execute.handler.js.map +0 -1
  94. package/dist/cli/help.handler.d.ts +0 -2
  95. package/dist/cli/help.handler.js +0 -10
  96. package/dist/cli/help.handler.js.map +0 -1
  97. package/dist/cli/init.handler.d.ts +0 -26
  98. package/dist/cli/init.handler.js +0 -450
  99. package/dist/cli/init.handler.js.map +0 -1
  100. package/dist/cli/log.handler.d.ts +0 -2
  101. package/dist/cli/log.handler.js +0 -69
  102. package/dist/cli/log.handler.js.map +0 -1
  103. package/dist/cli/mcp.handler.d.ts +0 -3
  104. package/dist/cli/mcp.handler.js +0 -121
  105. package/dist/cli/mcp.handler.js.map +0 -1
  106. package/dist/cli/query.handler.d.ts +0 -2
  107. package/dist/cli/query.handler.js +0 -392
  108. package/dist/cli/query.handler.js.map +0 -1
  109. package/dist/cli/skill.handler.d.ts +0 -2
  110. package/dist/cli/skill.handler.js +0 -252
  111. package/dist/cli/skill.handler.js.map +0 -1
  112. package/dist/cli/slack-files.handler.d.ts +0 -2
  113. package/dist/cli/slack-files.handler.js +0 -291
  114. package/dist/cli/slack-files.handler.js.map +0 -1
  115. package/dist/cli/template.handler.d.ts +0 -2
  116. package/dist/cli/template.handler.js +0 -188
  117. package/dist/cli/template.handler.js.map +0 -1
  118. package/dist/cli/templates.handler.d.ts +0 -2
  119. package/dist/cli/templates.handler.js +0 -100
  120. package/dist/cli/templates.handler.js.map +0 -1
  121. package/dist/cli-options.d.ts +0 -40
  122. package/dist/cli-options.js +0 -371
  123. package/dist/cli-options.js.map +0 -1
  124. package/dist/config/timeout.config.d.ts +0 -14
  125. package/dist/config/timeout.config.js +0 -34
  126. package/dist/config/timeout.config.js.map +0 -1
  127. package/dist/conversation/base-conversation-history.provider.d.ts +0 -12
  128. package/dist/conversation/base-conversation-history.provider.js +0 -45
  129. package/dist/conversation/base-conversation-history.provider.js.map +0 -1
  130. package/dist/conversation/cli-box-reader.adapter.d.ts +0 -6
  131. package/dist/conversation/cli-box-reader.adapter.js +0 -10
  132. package/dist/conversation/cli-box-reader.adapter.js.map +0 -1
  133. package/dist/conversation/cli-conversation-history.provider.d.ts +0 -16
  134. package/dist/conversation/cli-conversation-history.provider.js +0 -112
  135. package/dist/conversation/cli-conversation-history.provider.js.map +0 -1
  136. package/dist/conversation/cli-task-reader.adapter.d.ts +0 -6
  137. package/dist/conversation/cli-task-reader.adapter.js +0 -25
  138. package/dist/conversation/cli-task-reader.adapter.js.map +0 -1
  139. package/dist/conversation/conversation-provider.factory.d.ts +0 -10
  140. package/dist/conversation/conversation-provider.factory.js +0 -50
  141. package/dist/conversation/conversation-provider.factory.js.map +0 -1
  142. package/dist/conversation/index.d.ts +0 -8
  143. package/dist/conversation/index.js +0 -29
  144. package/dist/conversation/index.js.map +0 -1
  145. package/dist/conversation/slack-conversation-history.provider.d.ts +0 -29
  146. package/dist/conversation/slack-conversation-history.provider.js +0 -302
  147. package/dist/conversation/slack-conversation-history.provider.js.map +0 -1
  148. package/dist/crewx.tool.d.ts +0 -360
  149. package/dist/crewx.tool.js +0 -2531
  150. package/dist/crewx.tool.js.map +0 -1
  151. package/dist/crewx.tool.spec.d.ts +0 -1
  152. package/dist/crewx.tool.spec.js +0 -222
  153. package/dist/crewx.tool.spec.js.map +0 -1
  154. package/dist/guards/bearer-auth.guard.d.ts +0 -7
  155. package/dist/guards/bearer-auth.guard.js +0 -44
  156. package/dist/guards/bearer-auth.guard.js.map +0 -1
  157. package/dist/health.controller.d.ts +0 -6
  158. package/dist/health.controller.js +0 -32
  159. package/dist/health.controller.js.map +0 -1
  160. package/dist/main.js.map +0 -1
  161. package/dist/mcp.controller.d.ts +0 -8
  162. package/dist/mcp.controller.js +0 -62
  163. package/dist/mcp.controller.js.map +0 -1
  164. package/dist/package.json +0 -3
  165. package/dist/providers/dynamic-provider.factory.d.ts +0 -17
  166. package/dist/providers/dynamic-provider.factory.js +0 -138
  167. package/dist/providers/dynamic-provider.factory.js.map +0 -1
  168. package/dist/providers/logger.adapter.d.ts +0 -7
  169. package/dist/providers/logger.adapter.js +0 -107
  170. package/dist/providers/logger.adapter.js.map +0 -1
  171. package/dist/services/agent-loader.service.d.ts +0 -35
  172. package/dist/services/agent-loader.service.js +0 -623
  173. package/dist/services/agent-loader.service.js.map +0 -1
  174. package/dist/services/auth.service.d.ts +0 -9
  175. package/dist/services/auth.service.js +0 -47
  176. package/dist/services/auth.service.js.map +0 -1
  177. package/dist/services/config-validator.service.d.ts +0 -29
  178. package/dist/services/config-validator.service.js +0 -483
  179. package/dist/services/config-validator.service.js.map +0 -1
  180. package/dist/services/config.service.d.ts +0 -45
  181. package/dist/services/config.service.js +0 -352
  182. package/dist/services/config.service.js.map +0 -1
  183. package/dist/services/document-loader.service.d.ts +0 -26
  184. package/dist/services/document-loader.service.js +0 -186
  185. package/dist/services/document-loader.service.js.map +0 -1
  186. package/dist/services/help.service.d.ts +0 -5
  187. package/dist/services/help.service.js +0 -139
  188. package/dist/services/help.service.js.map +0 -1
  189. package/dist/services/intelligent-compression.service.d.ts +0 -20
  190. package/dist/services/intelligent-compression.service.js +0 -179
  191. package/dist/services/intelligent-compression.service.js.map +0 -1
  192. package/dist/services/mcp-client.service.d.ts +0 -26
  193. package/dist/services/mcp-client.service.js +0 -81
  194. package/dist/services/mcp-client.service.js.map +0 -1
  195. package/dist/services/parallel-processing.service.d.ts +0 -108
  196. package/dist/services/parallel-processing.service.js +0 -333
  197. package/dist/services/parallel-processing.service.js.map +0 -1
  198. package/dist/services/provider-bridge.service.d.ts +0 -35
  199. package/dist/services/provider-bridge.service.js +0 -224
  200. package/dist/services/provider-bridge.service.js.map +0 -1
  201. package/dist/services/remote-agent.service.d.ts +0 -50
  202. package/dist/services/remote-agent.service.js +0 -171
  203. package/dist/services/remote-agent.service.js.map +0 -1
  204. package/dist/services/result-formatter.service.d.ts +0 -27
  205. package/dist/services/result-formatter.service.js +0 -126
  206. package/dist/services/result-formatter.service.js.map +0 -1
  207. package/dist/services/skill-loader.service.d.ts +0 -15
  208. package/dist/services/skill-loader.service.js +0 -278
  209. package/dist/services/skill-loader.service.js.map +0 -1
  210. package/dist/services/skill.service.d.ts +0 -69
  211. package/dist/services/skill.service.js +0 -779
  212. package/dist/services/skill.service.js.map +0 -1
  213. package/dist/services/skill.service.spec.d.ts +0 -1
  214. package/dist/services/skill.service.spec.js +0 -168
  215. package/dist/services/skill.service.spec.js.map +0 -1
  216. package/dist/services/task-management.service.d.ts +0 -71
  217. package/dist/services/task-management.service.js +0 -324
  218. package/dist/services/task-management.service.js.map +0 -1
  219. package/dist/services/template.service.d.ts +0 -61
  220. package/dist/services/template.service.js +0 -416
  221. package/dist/services/template.service.js.map +0 -1
  222. package/dist/services/tool-call.service.d.ts +0 -16
  223. package/dist/services/tool-call.service.js +0 -302
  224. package/dist/services/tool-call.service.js.map +0 -1
  225. package/dist/services/tracing.service.d.ts +0 -197
  226. package/dist/services/tracing.service.js +0 -1267
  227. package/dist/services/tracing.service.js.map +0 -1
  228. package/dist/slack/formatters/message.formatter.d.ts +0 -43
  229. package/dist/slack/formatters/message.formatter.js +0 -505
  230. package/dist/slack/formatters/message.formatter.js.map +0 -1
  231. package/dist/slack/services/slack-file-download.service.d.ts +0 -58
  232. package/dist/slack/services/slack-file-download.service.js +0 -558
  233. package/dist/slack/services/slack-file-download.service.js.map +0 -1
  234. package/dist/slack/slack-bot.d.ts +0 -33
  235. package/dist/slack/slack-bot.js +0 -568
  236. package/dist/slack/slack-bot.js.map +0 -1
  237. package/dist/stderr.logger.d.ts +0 -8
  238. package/dist/stderr.logger.js +0 -26
  239. package/dist/stderr.logger.js.map +0 -1
  240. package/dist/types/usage.types.d.ts +0 -107
  241. package/dist/types/usage.types.js +0 -3
  242. package/dist/types/usage.types.js.map +0 -1
  243. package/dist/utils/config-utils.d.ts +0 -15
  244. package/dist/utils/config-utils.js +0 -69
  245. package/dist/utils/config-utils.js.map +0 -1
  246. package/dist/utils/extract-text.d.ts +0 -1
  247. package/dist/utils/extract-text.js +0 -15
  248. package/dist/utils/extract-text.js.map +0 -1
  249. package/dist/utils/mcp-installer.d.ts +0 -20
  250. package/dist/utils/mcp-installer.js +0 -199
  251. package/dist/utils/mcp-installer.js.map +0 -1
  252. package/dist/utils/project-hash.d.ts +0 -6
  253. package/dist/utils/project-hash.js +0 -70
  254. package/dist/utils/project-hash.js.map +0 -1
  255. package/dist/utils/simple-security.d.ts +0 -3
  256. package/dist/utils/simple-security.js +0 -20
  257. package/dist/utils/simple-security.js.map +0 -1
  258. package/dist/utils/stdin-utils.d.ts +0 -6
  259. package/dist/utils/stdin-utils.js +0 -109
  260. package/dist/utils/stdin-utils.js.map +0 -1
  261. package/dist/utils/template-processor.d.ts +0 -27
  262. package/dist/utils/template-processor.js +0 -395
  263. package/dist/utils/template-processor.js.map +0 -1
  264. package/dist/utils/terminal-message-formatter.d.ts +0 -23
  265. package/dist/utils/terminal-message-formatter.js +0 -136
  266. package/dist/utils/terminal-message-formatter.js.map +0 -1
  267. package/dist/version.d.ts +0 -1
  268. package/dist/version.js +0 -17
  269. package/dist/version.js.map +0 -1
  270. package/dist/workspace.service.d.ts +0 -44
  271. package/dist/workspace.service.js +0 -299
  272. package/dist/workspace.service.js.map +0 -1
  273. package/scripts/backfill-tokens.js +0 -218
  274. package/scripts/postbuild-cli.mjs +0 -88
  275. package/scripts/postinstall-cli.mjs +0 -30
  276. package/templates/agents/default.yaml +0 -490
  277. package/templates/agents/minimal.yaml +0 -16
  278. package/templates/documents/conversation-history-default.hbs +0 -17
  279. package/templates/documents/crewx-manual.md +0 -2278
  280. package/templates/documents/crewx-quick-guide.md +0 -147
  281. package/templates/versions.json +0 -19
@@ -1,779 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
19
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
20
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
21
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
22
- return c > 3 && r && Object.defineProperty(target, key, r), r;
23
- };
24
- var __importStar = (this && this.__importStar) || (function () {
25
- var ownKeys = function(o) {
26
- ownKeys = Object.getOwnPropertyNames || function (o) {
27
- var ar = [];
28
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
29
- return ar;
30
- };
31
- return ownKeys(o);
32
- };
33
- return function (mod) {
34
- if (mod && mod.__esModule) return mod;
35
- var result = {};
36
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
37
- __setModuleDefault(result, mod);
38
- return result;
39
- };
40
- })();
41
- var __metadata = (this && this.__metadata) || function (k, v) {
42
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
43
- };
44
- var SkillService_1;
45
- Object.defineProperty(exports, "__esModule", { value: true });
46
- exports.SkillService = void 0;
47
- const common_1 = require("@nestjs/common");
48
- const fs = __importStar(require("fs"));
49
- const path = __importStar(require("path"));
50
- const yaml = __importStar(require("js-yaml"));
51
- const sdk_1 = require("@crewx/sdk");
52
- const child_process_1 = require("child_process");
53
- const tracing_service_1 = require("./tracing.service");
54
- let SkillService = SkillService_1 = class SkillService {
55
- constructor() {
56
- this.logger = new common_1.Logger(SkillService_1.name);
57
- this.tracingService = null;
58
- this.crewxDir = path.join(process.cwd(), '.crewx');
59
- this.installedSkillsDir = path.join(this.crewxDir, 'skills');
60
- this.skillsDirs = [
61
- path.join(process.cwd(), 'skills'),
62
- this.installedSkillsDir
63
- ];
64
- this.initTracing();
65
- }
66
- initTracing() {
67
- try {
68
- this.tracingService = new tracing_service_1.TracingService();
69
- this.tracingService.onModuleInit();
70
- }
71
- catch (error) {
72
- this.logger.warn(`Failed to initialize TracingService for skill tracking: ${error}`);
73
- this.tracingService = null;
74
- }
75
- }
76
- loadCrewxConfig() {
77
- try {
78
- const configPath = path.join(process.cwd(), 'crewx.yaml');
79
- if (!fs.existsSync(configPath))
80
- return null;
81
- const content = fs.readFileSync(configPath, 'utf-8');
82
- return yaml.load(content);
83
- }
84
- catch (e) {
85
- this.logger.warn(`Failed to parse crewx.yaml: ${e}`);
86
- return null;
87
- }
88
- }
89
- getRegistries() {
90
- try {
91
- const config = this.loadCrewxConfig();
92
- const registries = config?.skills?.registries;
93
- if (!Array.isArray(registries))
94
- return [];
95
- return registries.filter((r) => r && typeof r === 'object' && typeof r.id === 'string');
96
- }
97
- catch {
98
- return [];
99
- }
100
- }
101
- ensureCrewxDir() {
102
- if (!fs.existsSync(this.crewxDir)) {
103
- fs.mkdirSync(this.crewxDir, { recursive: true });
104
- }
105
- }
106
- ensureInstalledSkillsDir() {
107
- this.ensureCrewxDir();
108
- if (!fs.existsSync(this.installedSkillsDir)) {
109
- fs.mkdirSync(this.installedSkillsDir, { recursive: true });
110
- }
111
- }
112
- parseSource(source) {
113
- if (source.startsWith('npm:')) {
114
- return { type: 'npm', package: source.slice(4) };
115
- }
116
- if (source.startsWith('template:')) {
117
- return { type: 'template', name: source.slice(9) };
118
- }
119
- if (source.startsWith('github:')) {
120
- const rest = source.slice(7);
121
- const atIndex = rest.lastIndexOf('@');
122
- if (atIndex > 0 && !rest.slice(0, atIndex).includes('/')) {
123
- return null;
124
- }
125
- if (atIndex > 0) {
126
- return { type: 'github', repo: rest.slice(0, atIndex), version: rest.slice(atIndex + 1) };
127
- }
128
- return { type: 'github', repo: rest };
129
- }
130
- return null;
131
- }
132
- async discover() {
133
- const skills = [];
134
- const seen = new Set();
135
- for (const dirPath of this.skillsDirs) {
136
- if (!fs.existsSync(dirPath))
137
- continue;
138
- try {
139
- const dirs = fs.readdirSync(dirPath, { withFileTypes: true })
140
- .filter(d => d.isDirectory());
141
- for (const dir of dirs) {
142
- const skillPath = path.join(dirPath, dir.name);
143
- const skillMdPath = path.join(skillPath, 'SKILL.md');
144
- if (fs.existsSync(skillMdPath)) {
145
- try {
146
- const manifest = (0, sdk_1.parseSkillManifestFromFile)(skillMdPath, {
147
- loadContent: false,
148
- validationMode: 'lenient'
149
- });
150
- const entryPoint = this.detectEntryPoint(skillPath, dir.name);
151
- const source = dirPath === this.installedSkillsDir ? 'installed' : 'custom';
152
- const skillName = manifest.metadata.name || dir.name;
153
- seen.add(skillName);
154
- skills.push({
155
- name: skillName,
156
- description: manifest.metadata.description || '',
157
- version: manifest.metadata.version || '0.0.0',
158
- entryPoint: entryPoint || null,
159
- path: skillPath,
160
- source,
161
- });
162
- }
163
- catch (e) {
164
- this.logger.debug(`Failed to parse SKILL.md in ${skillPath}: ${e}`);
165
- }
166
- }
167
- }
168
- }
169
- catch (e) {
170
- this.logger.warn(`Failed to read skills directory ${dirPath}: ${e}`);
171
- }
172
- }
173
- this.discoverBuiltInSkills(skills, seen);
174
- return skills;
175
- }
176
- findSkillMd(skillPath) {
177
- const candidates = [
178
- path.join(skillPath, 'SKILL.md'),
179
- path.join(skillPath, 'skill', 'SKILL.md'),
180
- ];
181
- for (const candidate of candidates) {
182
- if (fs.existsSync(candidate))
183
- return candidate;
184
- }
185
- return null;
186
- }
187
- discoverBuiltInSkills(skills, seen) {
188
- const crewxModulesDir = path.join(process.cwd(), 'node_modules', '@crewx');
189
- if (!fs.existsSync(crewxModulesDir))
190
- return;
191
- try {
192
- const entries = fs.readdirSync(crewxModulesDir, { withFileTypes: true });
193
- for (const entry of entries) {
194
- if (!entry.isDirectory() && !entry.isSymbolicLink())
195
- continue;
196
- const pkgDir = path.join(crewxModulesDir, entry.name);
197
- const candidates = [
198
- path.join(pkgDir, 'SKILL.md'),
199
- path.join(pkgDir, 'skill', 'SKILL.md'),
200
- ];
201
- for (const skillMdPath of candidates) {
202
- if (!fs.existsSync(skillMdPath))
203
- continue;
204
- try {
205
- const manifest = (0, sdk_1.parseSkillManifestFromFile)(skillMdPath, {
206
- loadContent: false,
207
- validationMode: 'lenient',
208
- });
209
- const skillName = manifest.metadata.name || `crewx/${entry.name}`;
210
- if (seen.has(skillName))
211
- break;
212
- const shorthand = skillName.startsWith('crewx/') ? skillName.slice('crewx/'.length) : null;
213
- if (shorthand && seen.has(shorthand))
214
- break;
215
- seen.add(skillName);
216
- const entryPoint = this.detectEntryPoint(pkgDir, entry.name);
217
- skills.push({
218
- name: skillName,
219
- description: manifest.metadata.description || '',
220
- version: manifest.metadata.version || '0.0.0',
221
- entryPoint: entryPoint || null,
222
- path: pkgDir,
223
- source: 'built-in',
224
- });
225
- }
226
- catch (e) {
227
- this.logger.debug(`Failed to parse SKILL.md in ${pkgDir}: ${e}`);
228
- }
229
- break;
230
- }
231
- }
232
- }
233
- catch (e) {
234
- this.logger.warn(`Failed to scan node_modules/@crewx: ${e}`);
235
- }
236
- }
237
- async getSkill(name) {
238
- const skills = await this.discover();
239
- const exact = skills.find(s => s.name === name);
240
- if (exact)
241
- return exact;
242
- if (!name.includes('/')) {
243
- const scoped = skills.find(s => s.name === `crewx/${name}`);
244
- if (scoped)
245
- return scoped;
246
- }
247
- return null;
248
- }
249
- detectEntryPoint(skillPath, skillName) {
250
- const pkgJsonPath = path.join(skillPath, 'package.json');
251
- if (fs.existsSync(pkgJsonPath)) {
252
- try {
253
- const pkg = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf-8'));
254
- if (pkg.bin) {
255
- const binValue = typeof pkg.bin === 'string'
256
- ? pkg.bin
257
- : Object.values(pkg.bin)[0];
258
- if (binValue) {
259
- const resolved = path.resolve(skillPath, binValue);
260
- if (fs.existsSync(resolved))
261
- return resolved;
262
- }
263
- }
264
- if (pkg.main) {
265
- const resolved = path.resolve(skillPath, pkg.main);
266
- if (fs.existsSync(resolved))
267
- return resolved;
268
- }
269
- }
270
- catch {
271
- }
272
- }
273
- const candidates = [
274
- `${skillName}.js`,
275
- `${skillName}.sh`,
276
- `${skillName}.py`,
277
- 'index.js',
278
- 'main.js',
279
- ];
280
- for (const candidate of candidates) {
281
- const fullPath = path.join(skillPath, candidate);
282
- if (fs.existsSync(fullPath)) {
283
- return candidate;
284
- }
285
- }
286
- return null;
287
- }
288
- async execute(name, args) {
289
- const skill = await this.getSkill(name);
290
- if (!skill) {
291
- throw new Error(`Skill '${name}' not found`);
292
- }
293
- if (!skill.entryPoint) {
294
- const skillMdPath = this.findSkillMd(skill.path);
295
- if (!skillMdPath)
296
- throw new Error(`SKILL.md not found for '${name}'`);
297
- const content = fs.readFileSync(skillMdPath, 'utf-8');
298
- console.log(content);
299
- return { code: 0, output: content };
300
- }
301
- const entryPoint = skill.entryPoint;
302
- const entryPath = path.isAbsolute(entryPoint) ? entryPoint : path.join(skill.path, entryPoint);
303
- const taskId = process.env.CREWX_TASK_ID;
304
- const spanAlreadyCreated = process.env.CREWX_SKILL_SPAN_CREATED === 'true';
305
- let spanId = null;
306
- const startTime = Date.now();
307
- if (taskId && this.tracingService?.isEnabled() && !spanAlreadyCreated) {
308
- spanId = this.tracingService.createSpan({
309
- task_id: taskId,
310
- name: `skill:${name}`,
311
- kind: tracing_service_1.SpanKind.INTERNAL,
312
- input: JSON.stringify({ skill: name, args }),
313
- });
314
- }
315
- return new Promise((resolve, reject) => {
316
- let command;
317
- let cmdArgs;
318
- if (entryPoint.endsWith('.js')) {
319
- command = 'node';
320
- cmdArgs = [entryPath, ...args];
321
- }
322
- else if (entryPoint.endsWith('.sh')) {
323
- command = 'sh';
324
- cmdArgs = [entryPath, ...args];
325
- }
326
- else if (entryPoint.endsWith('.py')) {
327
- command = 'python3';
328
- cmdArgs = [entryPath, ...args];
329
- }
330
- else {
331
- if (spanId && this.tracingService) {
332
- this.tracingService.failSpan(spanId, `Unsupported entry point: ${entryPoint}`);
333
- }
334
- reject(new Error(`Unsupported entry point: ${entryPoint}`));
335
- return;
336
- }
337
- const child = (0, child_process_1.spawn)(command, cmdArgs, {
338
- cwd: skill.path,
339
- stdio: 'inherit',
340
- env: {
341
- ...process.env,
342
- CREWX_WORKSPACE: process.env.CREWX_WORKSPACE || process.cwd(),
343
- },
344
- });
345
- child.on('close', (code) => {
346
- const durationMs = Date.now() - startTime;
347
- if (spanId && this.tracingService) {
348
- if (code === 0) {
349
- this.tracingService.completeSpan(spanId, JSON.stringify({
350
- code,
351
- duration_ms: durationMs
352
- }));
353
- }
354
- else {
355
- this.tracingService.failSpan(spanId, `Skill exited with code ${code}`);
356
- }
357
- }
358
- resolve({ code: code || 0, output: '' });
359
- });
360
- child.on('error', (err) => {
361
- if (spanId && this.tracingService) {
362
- this.tracingService.failSpan(spanId, err.message);
363
- }
364
- reject(err);
365
- });
366
- });
367
- }
368
- async executeShell(name, commandString) {
369
- const skill = await this.getSkill(name);
370
- if (!skill) {
371
- throw new Error(`Skill '${name}' not found`);
372
- }
373
- const taskId = process.env.CREWX_TASK_ID;
374
- const env = {
375
- ...process.env,
376
- SKILL_DIR: skill.path,
377
- CREWX_TASK_ID: taskId || '',
378
- CREWX_WORKSPACE: process.env.CREWX_WORKSPACE || process.cwd(),
379
- };
380
- const spanAlreadyCreated = process.env.CREWX_SKILL_SPAN_CREATED === 'true';
381
- let spanId = null;
382
- const startTime = Date.now();
383
- if (taskId && this.tracingService?.isEnabled() && !spanAlreadyCreated) {
384
- spanId = this.tracingService.createSpan({
385
- task_id: taskId,
386
- name: `skill:exec:${name}`,
387
- kind: tracing_service_1.SpanKind.INTERNAL,
388
- input: JSON.stringify({ skill: name, command: commandString }),
389
- });
390
- }
391
- return new Promise((resolve, reject) => {
392
- const child = (0, child_process_1.spawn)(commandString, {
393
- cwd: process.cwd(),
394
- shell: true,
395
- env: env,
396
- stdio: 'inherit',
397
- });
398
- child.on('close', (code) => {
399
- const durationMs = Date.now() - startTime;
400
- if (spanId && this.tracingService) {
401
- if (code === 0) {
402
- this.tracingService.completeSpan(spanId, JSON.stringify({ code, duration_ms: durationMs }));
403
- }
404
- else {
405
- this.tracingService.failSpan(spanId, `Skill shell exited with code ${code}`);
406
- }
407
- }
408
- resolve({ code: code || 0 });
409
- });
410
- child.on('error', (err) => {
411
- if (spanId && this.tracingService) {
412
- this.tracingService.failSpan(spanId, err.message);
413
- }
414
- reject(err);
415
- });
416
- });
417
- }
418
- async add(sourceStr) {
419
- const source = this.parseSource(sourceStr);
420
- if (!source) {
421
- return {
422
- success: false,
423
- name: '',
424
- message: `Invalid source format: ${sourceStr}. Use npm:<package>, template:<name>, or github:<owner/repo>`
425
- };
426
- }
427
- switch (source.type) {
428
- case 'npm':
429
- return this.addFromNpm(source.package);
430
- case 'template':
431
- return this.addFromTemplate(source.name);
432
- case 'github':
433
- return {
434
- success: false,
435
- name: '',
436
- message: 'GitHub source is planned for Phase 1.5 (v0.8.1+). Use npm: or template: for now.'
437
- };
438
- default:
439
- return { success: false, name: '', message: `Unknown source type` };
440
- }
441
- }
442
- validatePackageName(packageName) {
443
- if (packageName.startsWith('-')) {
444
- return false;
445
- }
446
- const validNpmPackagePattern = /^(@[a-z0-9-~][a-z0-9-._~]*\/)?[a-z0-9-~][a-z0-9-._~]*(@[a-z0-9-._~]+)?$/i;
447
- return validNpmPackagePattern.test(packageName);
448
- }
449
- async addFromNpm(packageName) {
450
- this.ensureInstalledSkillsDir();
451
- if (!this.validatePackageName(packageName)) {
452
- return {
453
- success: false,
454
- name: '',
455
- message: `Invalid package name: ${packageName}. Package name contains invalid characters.`
456
- };
457
- }
458
- try {
459
- const tempDir = path.join(this.crewxDir, '.tmp-install');
460
- if (fs.existsSync(tempDir)) {
461
- fs.rmSync(tempDir, { recursive: true });
462
- }
463
- fs.mkdirSync(tempDir, { recursive: true });
464
- fs.writeFileSync(path.join(tempDir, 'package.json'), JSON.stringify({ name: 'temp', private: true }));
465
- this.logger.log(`Installing ${packageName} from npm...`);
466
- (0, child_process_1.execSync)(`npm install ${packageName} --prefix "${tempDir}"`, {
467
- stdio: 'inherit'
468
- });
469
- const nodeModulesPath = path.join(tempDir, 'node_modules');
470
- const installedPkgPath = this.findInstalledPackage(nodeModulesPath, packageName);
471
- if (!installedPkgPath) {
472
- fs.rmSync(tempDir, { recursive: true });
473
- return { success: false, name: '', message: `Failed to locate installed package: ${packageName}` };
474
- }
475
- const skillMdPath = path.join(installedPkgPath, 'SKILL.md');
476
- if (!fs.existsSync(skillMdPath)) {
477
- fs.rmSync(tempDir, { recursive: true });
478
- return { success: false, name: '', message: `Package ${packageName} does not contain a SKILL.md file` };
479
- }
480
- const manifest = (0, sdk_1.parseSkillManifestFromFile)(skillMdPath, {
481
- loadContent: false,
482
- validationMode: 'lenient'
483
- });
484
- const skillName = manifest.metadata.name || path.basename(installedPkgPath);
485
- const skillVersion = manifest.metadata.version || '0.0.0';
486
- const customSkillPath = path.join(process.cwd(), 'skills', skillName);
487
- if (fs.existsSync(customSkillPath)) {
488
- fs.rmSync(tempDir, { recursive: true });
489
- return {
490
- success: false,
491
- name: skillName,
492
- message: `Skill '${skillName}' already exists in skills/ directory (custom skills take priority)`
493
- };
494
- }
495
- const targetPath = path.join(this.installedSkillsDir, skillName);
496
- if (fs.existsSync(targetPath)) {
497
- fs.rmSync(targetPath, { recursive: true });
498
- }
499
- this.copyDir(installedPkgPath, targetPath);
500
- fs.rmSync(tempDir, { recursive: true });
501
- return {
502
- success: true,
503
- name: skillName,
504
- message: `Successfully installed ${skillName}@${skillVersion} from npm:${packageName}`
505
- };
506
- }
507
- catch (e) {
508
- return { success: false, name: '', message: `Failed to install from npm: ${e}` };
509
- }
510
- }
511
- findInstalledPackage(nodeModulesPath, packageName) {
512
- if (packageName.startsWith('@')) {
513
- const parts = packageName.split('/');
514
- const scope = parts[0];
515
- const name = parts[1];
516
- if (scope && name) {
517
- const scopedPath = path.join(nodeModulesPath, scope, name);
518
- if (fs.existsSync(scopedPath)) {
519
- return scopedPath;
520
- }
521
- }
522
- }
523
- else {
524
- const directPath = path.join(nodeModulesPath, packageName);
525
- if (fs.existsSync(directPath)) {
526
- return directPath;
527
- }
528
- }
529
- return null;
530
- }
531
- copyDir(src, dest) {
532
- fs.mkdirSync(dest, { recursive: true });
533
- const entries = fs.readdirSync(src, { withFileTypes: true });
534
- for (const entry of entries) {
535
- const srcPath = path.join(src, entry.name);
536
- const destPath = path.join(dest, entry.name);
537
- if (entry.isDirectory()) {
538
- if (entry.name === 'node_modules')
539
- continue;
540
- this.copyDir(srcPath, destPath);
541
- }
542
- else {
543
- fs.copyFileSync(srcPath, destPath);
544
- }
545
- }
546
- }
547
- async addFromTemplate(templateName) {
548
- this.ensureInstalledSkillsDir();
549
- const builtInTemplates = {
550
- hello: {
551
- description: 'Simple greeting demo skill',
552
- files: {
553
- 'SKILL.md': `---
554
- name: {{name}}
555
- description: A simple greeting skill
556
- version: 0.0.1
557
- ---
558
-
559
- # {{name}} Skill
560
-
561
- A simple greeting skill created from template.
562
-
563
- ## Usage
564
- \`\`\`bash
565
- node skills/{{name}}/{{name}}.js [name]
566
- \`\`\`
567
- `,
568
- '{{name}}.js': `#!/usr/bin/env node
569
-
570
- const args = process.argv.slice(2);
571
-
572
- if (args.includes('--help') || args.includes('-h')) {
573
- console.log('Usage: node {{name}}.js [name]');
574
- process.exit(0);
575
- }
576
-
577
- const name = args[0] || 'World';
578
- console.log(\`Hello, \${name}! (from {{name}} skill)\`);
579
- `
580
- }
581
- },
582
- memory: {
583
- description: 'Key-value memory storage skill',
584
- files: {
585
- 'SKILL.md': `---
586
- name: {{name}}
587
- description: Simple key-value memory storage
588
- version: 0.0.1
589
- ---
590
-
591
- # {{name}} Skill
592
-
593
- A simple key-value memory storage skill.
594
-
595
- ## Commands
596
- - \`save <key> <value>\` - Save a value
597
- - \`load <key>\` - Load a value
598
- - \`list\` - List all keys
599
- - \`delete <key>\` - Delete a key
600
- `,
601
- '{{name}}.js': `#!/usr/bin/env node
602
-
603
- const fs = require('fs');
604
- const path = require('path');
605
-
606
- const dataFile = path.join(__dirname, 'data.json');
607
-
608
- function loadData() {
609
- try {
610
- return JSON.parse(fs.readFileSync(dataFile, 'utf-8'));
611
- } catch {
612
- return {};
613
- }
614
- }
615
-
616
- function saveData(data) {
617
- fs.writeFileSync(dataFile, JSON.stringify(data, null, 2));
618
- }
619
-
620
- const [command, ...args] = process.argv.slice(2);
621
-
622
- switch (command) {
623
- case 'save':
624
- const data = loadData();
625
- data[args[0]] = args.slice(1).join(' ');
626
- saveData(data);
627
- console.log(\`Saved: \${args[0]}\`);
628
- break;
629
- case 'load':
630
- const stored = loadData();
631
- console.log(stored[args[0]] || '(not found)');
632
- break;
633
- case 'list':
634
- console.log(Object.keys(loadData()).join('\\n') || '(empty)');
635
- break;
636
- case 'delete':
637
- const d = loadData();
638
- delete d[args[0]];
639
- saveData(d);
640
- console.log(\`Deleted: \${args[0]}\`);
641
- break;
642
- default:
643
- console.log('Usage: {{name}}.js <save|load|list|delete> [args]');
644
- }
645
- `
646
- }
647
- },
648
- api: {
649
- description: 'HTTP API client skill',
650
- files: {
651
- 'SKILL.md': `---
652
- name: {{name}}
653
- description: HTTP API client skill
654
- version: 0.0.1
655
- ---
656
-
657
- # {{name}} Skill
658
-
659
- An HTTP API client skill for making REST requests.
660
-
661
- ## Commands
662
- - \`get <url>\` - GET request
663
- - \`post <url> <data>\` - POST request with JSON data
664
- `,
665
- '{{name}}.js': `#!/usr/bin/env node
666
-
667
- const https = require('https');
668
- const http = require('http');
669
-
670
- const [method, url, ...rest] = process.argv.slice(2);
671
-
672
- if (!method || !url) {
673
- console.log('Usage: {{name}}.js <get|post> <url> [data]');
674
- process.exit(1);
675
- }
676
-
677
- const client = url.startsWith('https') ? https : http;
678
-
679
- const req = client.request(url, { method: method.toUpperCase() }, (res) => {
680
- let data = '';
681
- res.on('data', chunk => data += chunk);
682
- res.on('end', () => console.log(data));
683
- });
684
-
685
- if (method.toLowerCase() === 'post' && rest.length) {
686
- req.setHeader('Content-Type', 'application/json');
687
- req.write(rest.join(' '));
688
- }
689
-
690
- req.end();
691
- `
692
- }
693
- }
694
- };
695
- const template = builtInTemplates[templateName];
696
- if (!template) {
697
- const available = Object.keys(builtInTemplates).join(', ');
698
- return {
699
- success: false,
700
- name: '',
701
- message: `Template '${templateName}' not found. Available: ${available}`
702
- };
703
- }
704
- let skillName = templateName;
705
- let counter = 1;
706
- while (fs.existsSync(path.join(this.installedSkillsDir, skillName)) ||
707
- fs.existsSync(path.join(process.cwd(), 'skills', skillName))) {
708
- skillName = `${templateName}-${counter}`;
709
- counter++;
710
- }
711
- const targetPath = path.join(this.installedSkillsDir, skillName);
712
- fs.mkdirSync(targetPath, { recursive: true });
713
- for (const [fileNameTemplate, contentTemplate] of Object.entries(template.files)) {
714
- const fileName = fileNameTemplate.replace(/\{\{name\}\}/g, skillName);
715
- const content = contentTemplate.replace(/\{\{name\}\}/g, skillName);
716
- const filePath = path.join(targetPath, fileName);
717
- fs.writeFileSync(filePath, content);
718
- if (fileName.endsWith('.js')) {
719
- fs.chmodSync(filePath, '755');
720
- }
721
- }
722
- return {
723
- success: true,
724
- name: skillName,
725
- message: `Successfully created skill '${skillName}' from template '${templateName}' at .crewx/skills/${skillName}/`
726
- };
727
- }
728
- validateSkillName(name) {
729
- if (name === '.' || name === '..')
730
- return false;
731
- if (name.includes('\\') || name.includes('..'))
732
- return false;
733
- const SCOPED = /^[a-z][a-z0-9-]*\/[a-z][a-z0-9-]+$/;
734
- const FLAT = /^[a-z0-9][a-z0-9-._~]*$/i;
735
- return SCOPED.test(name) || FLAT.test(name);
736
- }
737
- async remove(name) {
738
- if (!this.validateSkillName(name)) {
739
- return {
740
- success: false,
741
- message: `Invalid skill name: '${name}'. Skill name cannot contain path separators (/, \\, ..).`
742
- };
743
- }
744
- const skill = await this.getSkill(name);
745
- if (skill?.source === 'built-in') {
746
- return {
747
- success: false,
748
- message: `Built-in skill '${name}' cannot be removed via crewx. Use npm uninstall instead.`,
749
- };
750
- }
751
- const installedPath = path.join(this.installedSkillsDir, name);
752
- if (!fs.existsSync(installedPath)) {
753
- const customPath = path.join(process.cwd(), 'skills', name);
754
- if (fs.existsSync(customPath)) {
755
- return {
756
- success: false,
757
- message: `'${name}' is a custom skill in skills/ directory. Remove it manually if intended.`
758
- };
759
- }
760
- return { success: false, message: `Skill '${name}' not found in installed skills.` };
761
- }
762
- try {
763
- fs.rmSync(installedPath, { recursive: true });
764
- return { success: true, message: `Successfully removed skill '${name}'` };
765
- }
766
- catch (e) {
767
- return { success: false, message: `Failed to remove skill '${name}': ${e}` };
768
- }
769
- }
770
- getAvailableTemplates() {
771
- return ['hello', 'memory', 'api'];
772
- }
773
- };
774
- exports.SkillService = SkillService;
775
- exports.SkillService = SkillService = SkillService_1 = __decorate([
776
- (0, common_1.Injectable)(),
777
- __metadata("design:paramtypes", [])
778
- ], SkillService);
779
- //# sourceMappingURL=skill.service.js.map