@crewx/cli 0.9.0-rc.145 → 0.9.0-rc.147

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 (45) hide show
  1. package/dist/bootstrap/codex-writable-roots.js +1 -113
  2. package/dist/bootstrap/crewx-cli.js +1 -84
  3. package/dist/builtin.js +5 -132
  4. package/dist/commands/agent.js +4 -118
  5. package/dist/commands/cal.js +2 -44
  6. package/dist/commands/db.js +4 -602
  7. package/dist/commands/detached.js +15 -620
  8. package/dist/commands/doctor.js +4 -649
  9. package/dist/commands/emit-trailer.js +2 -33
  10. package/dist/commands/execute.js +15 -294
  11. package/dist/commands/hook/command-marker.js +1 -5
  12. package/dist/commands/hook/install.js +8 -189
  13. package/dist/commands/hook/paths.js +1 -94
  14. package/dist/commands/hook/status.js +1 -86
  15. package/dist/commands/hook/uninstall.js +1 -71
  16. package/dist/commands/hook-dispatch.js +2 -180
  17. package/dist/commands/init.js +31 -437
  18. package/dist/commands/kill.js +1 -11
  19. package/dist/commands/log.js +3 -96
  20. package/dist/commands/parse-agent-message.js +1 -52
  21. package/dist/commands/parse-common-flags.js +3 -212
  22. package/dist/commands/ps.js +2 -117
  23. package/dist/commands/publish.js +7 -283
  24. package/dist/commands/query.js +16 -292
  25. package/dist/commands/registry.js +1 -33
  26. package/dist/commands/resolve-prompt.js +3 -76
  27. package/dist/commands/resolve-recipient.js +3 -47
  28. package/dist/commands/restart.js +18 -172
  29. package/dist/commands/result.js +1 -209
  30. package/dist/commands/shortcut.js +4 -253
  31. package/dist/commands/slack.js +16 -560
  32. package/dist/commands/stop.js +8 -119
  33. package/dist/commands/write-output.js +1 -24
  34. package/dist/index.js +1 -8
  35. package/dist/logging.js +10 -87
  36. package/dist/main.js +6 -289
  37. package/dist/register-builtin-tools.js +1 -9
  38. package/dist/slack/file-download.js +1 -134
  39. package/dist/slack/markdown.js +1 -33
  40. package/dist/utils/env-defaults.js +1 -15
  41. package/dist/utils/inherited-trace.js +1 -65
  42. package/dist/utils/product-package-root.js +1 -39
  43. package/dist/utils/sdk-compat.js +1 -120
  44. package/dist/utils/version.js +1 -28
  45. package/package.json +15 -15
@@ -1,119 +1,8 @@
1
- "use strict";
2
- /**
3
- * Stop a running task through the SDK's cooperative-stop pipeline.
4
- *
5
- * `kill` is kept as a compatibility alias; both entry points use this same
6
- * handler so server, CLI, and future adapters share one stop contract.
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.handleStop = handleStop;
10
- const sdk_1 = require("@crewx/sdk");
11
- const repository_1 = require("@crewx/sdk/repository");
12
- const cal_1 = require("./cal");
13
- function parseGrace(args) {
14
- const flag = args.find((arg) => arg === '--grace' || arg.startsWith('--grace='));
15
- if (!flag)
16
- return { graceMs: 5_000 };
17
- const raw = flag === '--grace'
18
- ? args[args.indexOf(flag) + 1]
19
- : flag.slice('--grace='.length);
20
- const value = Number(raw);
21
- if (!raw || !Number.isFinite(value) || value < 0) {
22
- return { graceMs: 5_000, error: `Invalid --grace value: ${raw ?? '(missing)'}` };
23
- }
24
- return { graceMs: Math.trunc(value) };
25
- }
26
- function taskIdFromArgs(args) {
27
- return args.find((arg, index) => {
28
- if (arg === '--grace')
29
- return false;
30
- if (index > 0 && args[index - 1] === '--grace')
31
- return false;
32
- return !arg.startsWith('--');
33
- });
34
- }
35
- function writeUsage() {
36
- process.stderr.write('Error: Please provide a task ID or use --all to stop all running tasks.\n');
37
- process.stderr.write('\nUsage:\n');
38
- process.stderr.write(' crewx stop <task-id> Stop a running task\n');
39
- process.stderr.write(' crewx stop --all Stop all running tasks\n');
40
- process.stderr.write(' crewx stop <task-id> --grace=<ms>\n');
41
- }
42
- function formatGrace(graceMs) {
43
- return `${graceMs / 1000}s`;
44
- }
45
- function reportResult(taskId, result, elapsedMs, graceMs) {
46
- if (result.status === 'stopped') {
47
- if (result.method === 'forced') {
48
- process.stdout.write(`Stopped ${taskId} (forced after ${formatGrace(graceMs)} grace)\n`);
49
- }
50
- else {
51
- process.stdout.write(`Stopped ${taskId} (cooperative, ${(elapsedMs / 1000).toFixed(1)}s)\n`);
52
- }
53
- return 0;
54
- }
55
- if (result.status === 'not_running') {
56
- process.stdout.write(`Task ${taskId} is not running (${result.finalStatus ?? 'unknown'})\n`);
57
- return 0;
58
- }
59
- if (result.status === 'already_requested') {
60
- process.stderr.write(`Task ${taskId} already has a stop request; it remains ${result.finalStatus ?? 'running'}.\n`);
61
- return 2;
62
- }
63
- if (result.status === 'ownership_unverified') {
64
- const pid = result.pid ? ` (pid ${result.pid})` : '';
65
- process.stderr.write(`Could not verify the process owner of ${taskId}; not terminated${pid}. ` +
66
- 'Row stays running — the reaper will settle it.\n');
67
- return 2;
68
- }
69
- process.stderr.write(`Could not stop ${taskId}: ${result.error ?? 'unknown error'}\n`);
70
- return 1;
71
- }
72
- /** Handle `crewx stop` and the compatibility `crewx kill` alias. */
73
- async function handleStop(args, invokedAs = 'stop') {
74
- if (invokedAs === 'kill')
75
- process.stderr.write('kill is an alias of stop\n');
76
- const stopAll = args.includes('--all');
77
- const { graceMs, error } = parseGrace(args);
78
- if (error) {
79
- process.stderr.write(`Error: ${error}\n`);
80
- process.exitCode = 1;
81
- return;
82
- }
83
- const taskId = taskIdFromArgs(args);
84
- if (!taskId && !stopAll) {
85
- writeUsage();
86
- process.exitCode = 1;
87
- return;
88
- }
89
- const repo = new repository_1.TaskRepository();
90
- const stopOne = async (id, withFooter) => {
91
- const startedAt = Date.now();
92
- const result = await (0, sdk_1.stopTask)(repo, id, { graceMs, origin: 'cli' });
93
- const exitCode = reportResult(id, result, Date.now() - startedAt, graceMs);
94
- if (withFooter && (result.status === 'stopped' || result.status === 'not_running')) {
95
- (0, cal_1.writeCalFooter)({
96
- commandId: 'crewx.stop.done',
97
- params: { taskId: id },
98
- });
99
- }
100
- return exitCode;
101
- };
102
- if (stopAll) {
103
- const running = repo.getRunningTasks();
104
- if (running.length === 0) {
105
- process.stdout.write('No running tasks found.\n');
106
- return;
107
- }
108
- let exitCode = 0;
109
- for (const task of running) {
110
- exitCode = Math.max(exitCode, await stopOne(task.id, false));
111
- }
112
- if (exitCode > 0)
113
- process.exitCode = exitCode;
114
- return;
115
- }
116
- const exitCode = await stopOne(taskId, true);
117
- if (exitCode > 0)
118
- process.exitCode = exitCode;
119
- }
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.handleStop=C;const w=require("@crewx/sdk");const g=require("@crewx/sdk/repository");const k=require("./cal");function $(r){const e=r.find(n=>n==="--grace"||n.startsWith("--grace="));if(!e)return{graceMs:5e3};const t=e==="--grace"?r[r.indexOf(e)+1]:e.slice("--grace=".length);const s=Number(t);if(!t||!Number.isFinite(s)||s<0){return{graceMs:5e3,error:`Invalid --grace value: ${t??"(missing)"}`}}return{graceMs:Math.trunc(s)}}function h(r){return r.find((e,t)=>{if(e==="--grace")return false;if(t>0&&r[t-1]==="--grace")return false;return!e.startsWith("--")})}function m(){process.stderr.write("Error: Please provide a task ID or use --all to stop all running tasks.\n");process.stderr.write("\nUsage:\n");process.stderr.write(" crewx stop <task-id> Stop a running task\n");process.stderr.write(" crewx stop --all Stop all running tasks\n");process.stderr.write(" crewx stop <task-id> --grace=<ms>\n")}function x(r){return`${r/1e3}s`}function _(r,e,t,s){if(e.status==="stopped"){if(e.method==="forced"){process.stdout.write(`Stopped ${r} (forced after ${x(s)} grace)
2
+ `)}else{process.stdout.write(`Stopped ${r} (cooperative, ${(t/1e3).toFixed(1)}s)
3
+ `)}return 0}if(e.status==="not_running"){process.stdout.write(`Task ${r} is not running (${e.finalStatus??"unknown"})
4
+ `);return 0}if(e.status==="already_requested"){process.stderr.write(`Task ${r} already has a stop request; it remains ${e.finalStatus??"running"}.
5
+ `);return 2}if(e.status==="ownership_unverified"){const n=e.pid?` (pid ${e.pid})`:"";process.stderr.write(`Could not verify the process owner of ${r}; not terminated${n}. Row stays running \u2014 the reaper will settle it.
6
+ `);return 2}process.stderr.write(`Could not stop ${r}: ${e.error??"unknown error"}
7
+ `);return 1}async function C(r,e="stop"){if(e==="kill")process.stderr.write("kill is an alias of stop\n");const t=r.includes("--all");const{graceMs:s,error:n}=$(r);if(n){process.stderr.write(`Error: ${n}
8
+ `);process.exitCode=1;return}const u=h(r);if(!u&&!t){m();process.exitCode=1;return}const p=new g.TaskRepository;const d=async(o,i)=>{const a=Date.now();const c=await(0,w.stopTask)(p,o,{graceMs:s,origin:"cli"});const l=_(o,c,Date.now()-a,s);if(i&&(c.status==="stopped"||c.status==="not_running")){(0,k.writeCalFooter)({commandId:"crewx.stop.done",params:{taskId:o}})}return l};if(t){const o=p.getRunningTasks();if(o.length===0){process.stdout.write("No running tasks found.\n");return}let i=0;for(const a of o){i=Math.max(i,await d(a.id,false))}if(i>0)process.exitCode=i;return}const f=await d(u,true);if(f>0)process.exitCode=f}
@@ -1,24 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.writeResult = writeResult;
4
- exports.appendError = appendError;
5
- /**
6
- * EPIPE-safe result output.
7
- * - out specified: write success result to file (sync, no stream EPIPE)
8
- * - out not specified: fall back to existing stdout (console.log)
9
- */
10
- const fs_1 = require("fs");
11
- function writeResult(out, data) {
12
- if (out) {
13
- (0, fs_1.writeFileSync)(out, data, 'utf8');
14
- }
15
- else {
16
- console.log(data);
17
- }
18
- }
19
- /** On failure: if out is specified, append to file (avoid empty file). stderr is kept by the caller. */
20
- function appendError(out, message) {
21
- if (out) {
22
- (0, fs_1.appendFileSync)(out, message.endsWith('\n') ? message : message + '\n', 'utf8');
23
- }
24
- }
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.writeResult=i;exports.appendError=t;const r=require("fs");function i(n,e){if(n){(0,r.writeFileSync)(n,e,"utf8")}else{console.log(e)}}function t(n,e){if(n){(0,r.appendFileSync)(n,e.endsWith("\n")?e:e+"\n","utf8")}}
package/dist/index.js CHANGED
@@ -1,8 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolveInitProvider = exports.parseInitProvider = exports.handleInit = exports.buildDefaultAgents = void 0;
4
- var init_1 = require("./commands/init");
5
- Object.defineProperty(exports, "buildDefaultAgents", { enumerable: true, get: function () { return init_1.buildDefaultAgents; } });
6
- Object.defineProperty(exports, "handleInit", { enumerable: true, get: function () { return init_1.handleInit; } });
7
- Object.defineProperty(exports, "parseInitProvider", { enumerable: true, get: function () { return init_1.parseInitProvider; } });
8
- Object.defineProperty(exports, "resolveInitProvider", { enumerable: true, get: function () { return init_1.resolveInitProvider; } });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.resolveInitProvider=exports.parseInitProvider=exports.handleInit=exports.buildDefaultAgents=void 0;var e=require("./commands/init");Object.defineProperty(exports,"buildDefaultAgents",{enumerable:true,get:function(){return e.buildDefaultAgents}});Object.defineProperty(exports,"handleInit",{enumerable:true,get:function(){return e.handleInit}});Object.defineProperty(exports,"parseInitProvider",{enumerable:true,get:function(){return e.parseInitProvider}});Object.defineProperty(exports,"resolveInitProvider",{enumerable:true,get:function(){return e.resolveInitProvider}});
package/dist/logging.js CHANGED
@@ -1,87 +1,10 @@
1
- "use strict";
2
- /**
3
- * CLI file-based logging for CrewX SDK events.
4
- *
5
- * Subscribe to task:start / task:end events from a Crewx instance
6
- * and write structured log files to .crewx/logs/ in the workspace root.
7
- *
8
- * File name format: {YYYYMMDDTHHmmss}_{traceId}.log
9
- * e.g. 20260412T145044_tsk_AbCdEfGh.log
10
- *
11
- * Format mirrors cli-bak TaskManagementService for backward compatibility.
12
- */
13
- Object.defineProperty(exports, "__esModule", { value: true });
14
- exports.attachFileLogger = attachFileLogger;
15
- const fs_1 = require("fs");
16
- const path_1 = require("path");
17
- const sdk_1 = require("@crewx/sdk");
18
- const CREWX_VERSION = '0.9.0-alpha.1';
19
- /** Format Date as YYYYMMDDTHHmmss (local time) */
20
- function formatTimestamp(date) {
21
- const pad = (n) => String(n).padStart(2, '0');
22
- return (`${date.getFullYear()}` +
23
- `${pad(date.getMonth() + 1)}` +
24
- `${pad(date.getDate())}` +
25
- `T${pad(date.getHours())}` +
26
- `${pad(date.getMinutes())}` +
27
- `${pad(date.getSeconds())}`);
28
- }
29
- function ensureLogsDir(logsDir) {
30
- if (!(0, fs_1.existsSync)(logsDir)) {
31
- (0, fs_1.mkdirSync)(logsDir, { recursive: true });
32
- }
33
- }
34
- /**
35
- * Attach file-based logging to a Crewx instance.
36
- * Subscribes to task:start and task:end events and writes log files.
37
- *
38
- * @param crewx - The Crewx instance to attach logging to
39
- * @param workspaceRoot - Root directory for .crewx/logs/ (default: process.cwd())
40
- * @returns Cleanup function that removes all event listeners
41
- */
42
- function attachFileLogger(crewx, workspaceRoot) {
43
- const logsDir = (0, path_1.join)(workspaceRoot ?? process.cwd(), '.crewx', 'logs');
44
- // traceId → absolute log file path (in-memory map for the process lifetime)
45
- const logFiles = new Map();
46
- const unsubStart = crewx.on('task:start', (event) => {
47
- try {
48
- ensureLogsDir(logsDir);
49
- const ts = formatTimestamp(event.timestamp);
50
- const logFile = (0, path_1.join)(logsDir, `${ts}_${event.traceId}.log`);
51
- logFiles.set(event.traceId, logFile);
52
- const header = `=== TASK LOG: ${event.traceId} ===\n` +
53
- `CrewX Version: ${CREWX_VERSION}\n` +
54
- `Mode: ${event.mode}\n` +
55
- `Agent: ${event.agentRef}\n` +
56
- `Started: ${(0, sdk_1.formatDisplayTimestamp)(event.timestamp)}\n` +
57
- `Message: ${event.message}\n` +
58
- `\n`;
59
- (0, fs_1.writeFileSync)(logFile, header, { encoding: 'utf8', mode: 0o600 });
60
- }
61
- catch {
62
- // Non-fatal: CLI logging must never crash the main process
63
- }
64
- });
65
- const unsubEnd = crewx.on('task:end', (event) => {
66
- try {
67
- const logFile = logFiles.get(event.traceId);
68
- if (!logFile)
69
- return;
70
- const ts = (0, sdk_1.formatDisplayTimestamp)(new Date());
71
- const status = event.error
72
- ? `failed: ${event.error.message}`
73
- : 'completed successfully';
74
- const completion = `[${ts}] INFO: Task ${status} in ${event.durationMs}ms\n` +
75
- `[${ts}] INFO: Process closed with exit code: ${event.error ? 1 : 0}\n`;
76
- (0, fs_1.appendFileSync)(logFile, completion, 'utf8');
77
- logFiles.delete(event.traceId);
78
- }
79
- catch {
80
- // Non-fatal
81
- }
82
- });
83
- return () => {
84
- unsubStart();
85
- unsubEnd();
86
- };
87
- }
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.attachFileLogger=S;const c=require("fs");const u=require("path");const l=require("@crewx/sdk");const $="0.9.0-alpha.1";function p(e){const s=o=>String(o).padStart(2,"0");return`${e.getFullYear()}${s(e.getMonth()+1)}${s(e.getDate())}T${s(e.getHours())}${s(e.getMinutes())}${s(e.getSeconds())}`}function f(e){if(!(0,c.existsSync)(e)){(0,c.mkdirSync)(e,{recursive:true})}}function S(e,s){const o=(0,u.join)(s??process.cwd(),".crewx","logs");const a=new Map;const g=e.on("task:start",t=>{try{f(o);const n=p(t.timestamp);const r=(0,u.join)(o,`${n}_${t.traceId}.log`);a.set(t.traceId,r);const i=`=== TASK LOG: ${t.traceId} ===
2
+ CrewX Version: ${$}
3
+ Mode: ${t.mode}
4
+ Agent: ${t.agentRef}
5
+ Started: ${(0,l.formatDisplayTimestamp)(t.timestamp)}
6
+ Message: ${t.message}
7
+
8
+ `;(0,c.writeFileSync)(r,i,{encoding:"utf8",mode:384})}catch{}});const d=e.on("task:end",t=>{try{const n=a.get(t.traceId);if(!n)return;const r=(0,l.formatDisplayTimestamp)(new Date);const i=t.error?`failed: ${t.error.message}`:"completed successfully";const m=`[${r}] INFO: Task ${i} in ${t.durationMs}ms
9
+ [${r}] INFO: Process closed with exit code: ${t.error?1:0}
10
+ `;(0,c.appendFileSync)(n,m,"utf8");a.delete(t.traceId)}catch{}});return()=>{g();d()}}
package/dist/main.js CHANGED
@@ -1,274 +1,8 @@
1
1
  #!/usr/bin/env node
2
- "use strict";
3
- /**
4
- * CrewX CLI entry point.
5
- * Dispatches commands to the appropriate handler.
6
- *
7
- * Boot sequence:
8
- * 1. Inject CREWX_CLI / CREWX_WORKSPACE env defaults (must be first)
9
- * 2. Load workspace and ~/.crewx .env files (does not override process.env)
10
- * 3. Parse command
11
- * 4. Dispatch to handler
12
- */
13
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
- if (k2 === undefined) k2 = k;
15
- var desc = Object.getOwnPropertyDescriptor(m, k);
16
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
17
- desc = { enumerable: true, get: function() { return m[k]; } };
18
- }
19
- Object.defineProperty(o, k2, desc);
20
- }) : (function(o, m, k, k2) {
21
- if (k2 === undefined) k2 = k;
22
- o[k2] = m[k];
23
- }));
24
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
25
- Object.defineProperty(o, "default", { enumerable: true, value: v });
26
- }) : function(o, v) {
27
- o["default"] = v;
28
- });
29
- var __importStar = (this && this.__importStar) || (function () {
30
- var ownKeys = function(o) {
31
- ownKeys = Object.getOwnPropertyNames || function (o) {
32
- var ar = [];
33
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
34
- return ar;
35
- };
36
- return ownKeys(o);
37
- };
38
- return function (mod) {
39
- if (mod && mod.__esModule) return mod;
40
- var result = {};
41
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
42
- __setModuleDefault(result, mod);
43
- return result;
44
- };
45
- })();
46
- Object.defineProperty(exports, "__esModule", { value: true });
47
- // ─── P0-1: Env Bootstrap ─────────────────────────────────────────────────────
48
- // Must run before any other code that might use process.env.CREWX_CLI.
49
- const sdk_compat_1 = require("./utils/sdk-compat");
50
- const account_1 = require("@crewx/sdk/account");
51
- const sdk_1 = require("@crewx/sdk");
52
- const inherited_trace_1 = require("./utils/inherited-trace");
53
- process.env.CREWX_CLI ??= sdk_compat_1.sdkCompat.resolveCrewxCli();
54
- process.env.CREWX_WORKSPACE ??= sdk_compat_1.sdkCompat.resolveCrewxWorkspace();
55
- // Load workspace .env before ~/.crewx/.env. The SDK-owned loader keeps CLI and
56
- // server bootstrap on the same process > workspace > home precedence contract.
57
- (0, account_1.loadCrewxEnvFiles)();
58
- // Receipt runner identity is a one-hop capability. Consume it before any
59
- // command/provider code can spawn a child process.
60
- (0, inherited_trace_1.consumeInheritedRunnerIdentity)();
61
- // ─── Pricing remote override (WI-20260701-002) ───────────────────────────────
62
- // Best-effort, non-blocking: fetch remote model registry so new models get
63
- // accurate pricing without a CLI republish. Falls back to bundled table on
64
- // failure / offline. Browser entry does not call this automatically.
65
- sdk_compat_1.sdkCompat.initPricingRemote();
66
- // ─── Command Imports ──────────────────────────────────────────────────────────
67
- const query_1 = require("./commands/query");
68
- const execute_1 = require("./commands/execute");
69
- const agent_1 = require("./commands/agent");
70
- const ps_1 = require("./commands/ps");
71
- const stop_1 = require("./commands/stop");
72
- const result_1 = require("./commands/result");
73
- const restart_1 = require("./commands/restart");
74
- const log_1 = require("./commands/log");
75
- const doctor_1 = require("./commands/doctor");
76
- const init_1 = require("./commands/init");
77
- const shortcut_1 = require("./commands/shortcut");
78
- const publish_1 = require("./commands/publish");
79
- const builtin_1 = require("./builtin");
80
- const slack_1 = require("./commands/slack");
81
- const install_1 = require("./commands/hook/install");
82
- const uninstall_1 = require("./commands/hook/uninstall");
83
- const status_1 = require("./commands/hook/status");
84
- const hook_dispatch_1 = require("./commands/hook-dispatch");
85
- const db_1 = require("./commands/db");
86
- const parse_common_flags_1 = require("./commands/parse-common-flags");
87
- const registry_1 = require("./commands/registry");
88
- const version_1 = require("./utils/version");
89
- const product_package_root_1 = require("./utils/product-package-root");
90
- const emit_trailer_1 = require("./commands/emit-trailer");
91
- /**
92
- * Dev-only SSOT assertion: bin/cli-commands.js must be the exact union of
93
- * KNOWN_COMMANDS ∪ BUILTIN_COMMAND_NAMES ∪ NOT_YET_MIGRATED from registry.ts.
94
- * Throws on drift so the discrepancy is caught immediately during development.
95
- */
96
- async function assertSsotParity() {
97
- const { join } = await Promise.resolve().then(() => __importStar(require('path')));
98
- // eslint-disable-next-line @typescript-eslint/no-require-imports
99
- const { createRequire } = require('module');
100
- // Use createRequire(__filename) + plain path to avoid TypeScript compiling import() → require()
101
- // in the CJS dist. Node.js 22.12+ supports require(esm), so this loads ESM cli-commands.js fine.
102
- const req = createRequire(__filename);
103
- const cliCommandsPath = join(__dirname, '../../../bin/cli-commands.js');
104
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
105
- const { CLI_SUBCOMMANDS } = req(cliCommandsPath);
106
- const union = new Set([...registry_1.KNOWN_COMMANDS, ...registry_1.BUILTIN_COMMAND_NAMES, ...registry_1.NOT_YET_MIGRATED]);
107
- const missing = [...union].filter((c) => !CLI_SUBCOMMANDS.has(c));
108
- const extra = [...CLI_SUBCOMMANDS].filter((c) => !union.has(c));
109
- if (missing.length > 0 || extra.length > 0) {
110
- throw new Error(`[crewx dev] SSOT drift detected!\n` +
111
- (missing.length ? ` registry has, CLI_SUBCOMMANDS missing: ${missing.join(', ')}\n` : '') +
112
- (extra.length ? ` CLI_SUBCOMMANDS has, registry missing: ${extra.join(', ')}` : ''));
113
- }
114
- }
115
- async function main(emitState) {
116
- if (process.env['NODE_ENV'] === 'development') {
117
- await assertSsotParity();
118
- }
119
- const args = process.argv.slice(2);
120
- const command = args[0];
121
- if (!command) {
122
- printHelp();
123
- process.exit(0);
124
- }
125
- // Built-in tools: memory, search, doc, wbs, cron, workflow, skill
126
- if (builtin_1.BUILTIN_COMMANDS.has(command)) {
127
- const productPackageRoot = command === 'skill'
128
- ? (0, product_package_root_1.resolveProductRootFromCliEntry)(process.argv[1])
129
- : undefined;
130
- await (0, builtin_1.handleBuiltin)(command, args.slice(1), productPackageRoot);
131
- return;
132
- }
133
- // Core commands
134
- switch (command) {
135
- // P0-2: q/x aliases
136
- case 'q':
137
- case 'query':
138
- await (0, query_1.handleQuery)(args.slice(1), command, emitState);
139
- return;
140
- case 'x':
141
- case 'execute':
142
- await (0, execute_1.handleExecute)(args.slice(1), command, emitState);
143
- return;
144
- case 'agent':
145
- await (0, agent_1.handleAgent)(args.slice(1));
146
- return;
147
- // P0-4: ps
148
- case 'ps':
149
- await (0, ps_1.handlePs)(args.slice(1));
150
- return;
151
- // Task stop (kill is a compatibility alias)
152
- case 'stop':
153
- await (0, stop_1.handleStop)(args.slice(1), 'stop');
154
- return;
155
- case 'kill':
156
- await (0, stop_1.handleStop)(args.slice(1), 'kill');
157
- return;
158
- // P0-6: result
159
- case 'result':
160
- await (0, result_1.handleResult)(args.slice(1));
161
- return;
162
- // CLI Task Lifecycle 2단계: restart a failed task as a new task
163
- case 'restart':
164
- await (0, restart_1.handleRestart)(args.slice(1));
165
- return;
166
- // P1-1: log
167
- case 'log':
168
- await (0, log_1.handleLog)(args.slice(1));
169
- return;
170
- // P1-1: doctor
171
- case 'doctor':
172
- await (0, doctor_1.handleDoctor)(args.slice(1));
173
- return;
174
- // P1-1: init
175
- case 'init': {
176
- const initArgs = args.slice(1);
177
- const force = initArgs.includes('--force') || initArgs.includes('-f');
178
- try {
179
- const provider = (0, init_1.parseInitProvider)(initArgs);
180
- const r = await (0, init_1.handleInit)({ path: process.cwd(), force, provider });
181
- if (r.skippedReason === 'yaml-exists') {
182
- console.log('✓ crewx.yaml already exists (use --force to overwrite)');
183
- }
184
- else {
185
- console.log(r.yamlCreated ? '✓ crewx.yaml created' : '✓ yaml skipped');
186
- console.log(r.hookInstalled ? '✓ hook installed' : '⚠ hook skipped');
187
- if (r.errors.length > 0)
188
- console.warn('Warnings:', r.errors.join('; '));
189
- }
190
- const profile = (0, sdk_1.getDefaultAgentProfile)(r.provider);
191
- if (profile) {
192
- console.log(`✓ default agents: ${r.provider} (${profile.planner.model} / ${profile.worker.model})`);
193
- }
194
- if (r.workspaceId)
195
- console.log(`✓ workspace registered (id=${r.workspaceId}, slug=${r.slug})`);
196
- console.log('✓ done');
197
- }
198
- catch (e) {
199
- console.error('✗ init failed:', e.message);
200
- process.exit(1);
201
- }
202
- return;
203
- }
204
- // DB management: crewx db push [--force] [--dry-run]
205
- case 'db':
206
- await (0, db_1.handleDb)(args.slice(1));
207
- return;
208
- // Windows Desktop shortcut: crewx shortcut status|install|uninstall
209
- case 'shortcut':
210
- await (0, shortcut_1.handleShortcut)(args.slice(1));
211
- return;
212
- // crewx publish [dir] [--dry-run] [--version <semver>] [--json] [--upload]
213
- case 'publish':
214
- await (0, publish_1.handlePublish)(args.slice(1));
215
- return;
216
- // SDK-009: slack / slack:files
217
- case 'slack':
218
- case 'slack:files':
219
- await (0, slack_1.handleSlack)(args.slice(1));
220
- return;
221
- // Hook Platform (Phase 0)
222
- case 'hook-dispatch':
223
- await (0, hook_dispatch_1.handleHookDispatch)(args.slice(1));
224
- return;
225
- case 'help':
226
- case '--help':
227
- case '-h':
228
- printHelp();
229
- return;
230
- case '--version':
231
- case '-v': {
232
- // eslint-disable-next-line @typescript-eslint/no-require-imports
233
- const pkg = require('../package.json');
234
- console.log(pkg.version);
235
- return;
236
- }
237
- }
238
- // Not yet migrated commands (SDK-009)
239
- if (registry_1.NOT_YET_MIGRATED.has(command)) {
240
- console.error(`Command '${command}' is not yet migrated in SDK refactor round. ` +
241
- 'See packages/cli-bak for reference.');
242
- process.exit(1);
243
- }
244
- // Hook subcommands: crewx hook install/uninstall/status
245
- if (command === 'hook') {
246
- const subcommand = args[1];
247
- const subArgs = args.slice(2);
248
- switch (subcommand) {
249
- case 'install':
250
- await (0, install_1.handleHookInstall)(subArgs);
251
- return;
252
- case 'uninstall':
253
- await (0, uninstall_1.handleHookUninstall)(subArgs);
254
- return;
255
- case 'status':
256
- await (0, status_1.handleHookStatus)(subArgs);
257
- return;
258
- default:
259
- console.error(`Unknown hook subcommand: ${subcommand ?? '(none)'}`);
260
- console.error('Usage: crewx hook install|uninstall|status');
261
- process.exit(1);
262
- }
263
- }
264
- // Unknown command
265
- console.error(`Unknown command: ${command}`);
266
- console.error('Run `crewx --help` for usage.');
267
- process.exit(1);
268
- }
269
- function printHelp() {
270
- console.log(`
271
- CrewX CLI v${version_1.CLI_VERSION}
2
+ "use strict";var w=exports&&exports.__createBinding||(Object.create?(function(r,e,o,t){if(t===void 0)t=o;var s=Object.getOwnPropertyDescriptor(e,o);if(!s||("get"in s?!e.__esModule:s.writable||s.configurable)){s={enumerable:true,get:function(){return e[o]}}}Object.defineProperty(r,t,s)}):(function(r,e,o,t){if(t===void 0)t=o;r[t]=e[o]}));var k=exports&&exports.__setModuleDefault||(Object.create?(function(r,e){Object.defineProperty(r,"default",{enumerable:true,value:e})}):function(r,e){r["default"]=e});var v=exports&&exports.__importStar||(function(){var r=function(e){r=Object.getOwnPropertyNames||function(o){var t=[];for(var s in o)if(Object.prototype.hasOwnProperty.call(o,s))t[t.length]=s;return t};return r(e)};return function(e){if(e&&e.__esModule)return e;var o={};if(e!=null){for(var t=r(e),s=0;s<t.length;s++)if(t[s]!=="default")w(o,e,t[s])}k(o,e);return o}})();Object.defineProperty(exports,"__esModule",{value:true});const u=require("./utils/sdk-compat");const _=require("@crewx/sdk/account");const y=require("@crewx/sdk");const b=require("./utils/inherited-trace");process.env.CREWX_CLI??=u.sdkCompat.resolveCrewxCli();process.env.CREWX_WORKSPACE??=u.sdkCompat.resolveCrewxWorkspace();(0,_.loadCrewxEnvFiles)();(0,b.consumeInheritedRunnerIdentity)();u.sdkCompat.initPricingRemote();const x=require("./commands/query");const q=require("./commands/execute");const S=require("./commands/agent");const C=require("./commands/ps");const d=require("./commands/stop");const O=require("./commands/result");const P=require("./commands/restart");const I=require("./commands/log");const D=require("./commands/doctor");const h=require("./commands/init");const E=require("./commands/shortcut");const R=require("./commands/publish");const p=require("./builtin");const M=require("./commands/slack");const j=require("./commands/hook/install");const N=require("./commands/hook/uninstall");const A=require("./commands/hook/status");const L=require("./commands/hook-dispatch");const T=require("./commands/db");const U=require("./commands/parse-common-flags");const c=require("./commands/registry");const B=require("./utils/version");const W=require("./utils/product-package-root");const g=require("./commands/emit-trailer");async function $(){const{join:r}=await Promise.resolve().then(()=>v(require("path")));const{createRequire:e}=require("module");const o=e(__filename);const t=r(__dirname,"../../../bin/cli-commands.js");const{CLI_SUBCOMMANDS:s}=o(t);const i=new Set([...c.KNOWN_COMMANDS,...c.BUILTIN_COMMAND_NAMES,...c.NOT_YET_MIGRATED]);const a=[...i].filter(l=>!s.has(l));const n=[...s].filter(l=>!i.has(l));if(a.length>0||n.length>0){throw new Error(`[crewx dev] SSOT drift detected!
3
+ `+(a.length?` registry has, CLI_SUBCOMMANDS missing: ${a.join(", ")}
4
+ `:"")+(n.length?` CLI_SUBCOMMANDS has, registry missing: ${n.join(", ")}`:""))}}async function F(r){if(process.env["NODE_ENV"]==="development"){await $()}const e=process.argv.slice(2);const o=e[0];if(!o){f();process.exit(0)}if(p.BUILTIN_COMMANDS.has(o)){const t=o==="skill"?(0,W.resolveProductRootFromCliEntry)(process.argv[1]):void 0;await(0,p.handleBuiltin)(o,e.slice(1),t);return}switch(o){case"q":case"query":await(0,x.handleQuery)(e.slice(1),o,r);return;case"x":case"execute":await(0,q.handleExecute)(e.slice(1),o,r);return;case"agent":await(0,S.handleAgent)(e.slice(1));return;case"ps":await(0,C.handlePs)(e.slice(1));return;case"stop":await(0,d.handleStop)(e.slice(1),"stop");return;case"kill":await(0,d.handleStop)(e.slice(1),"kill");return;case"result":await(0,O.handleResult)(e.slice(1));return;case"restart":await(0,P.handleRestart)(e.slice(1));return;case"log":await(0,I.handleLog)(e.slice(1));return;case"doctor":await(0,D.handleDoctor)(e.slice(1));return;case"init":{const t=e.slice(1);const s=t.includes("--force")||t.includes("-f");try{const i=(0,h.parseInitProvider)(t);const a=await(0,h.handleInit)({path:process.cwd(),force:s,provider:i});if(a.skippedReason==="yaml-exists"){console.log("\u2713 crewx.yaml already exists (use --force to overwrite)")}else{console.log(a.yamlCreated?"\u2713 crewx.yaml created":"\u2713 yaml skipped");console.log(a.hookInstalled?"\u2713 hook installed":"\u26A0 hook skipped");if(a.errors.length>0)console.warn("Warnings:",a.errors.join("; "))}const n=(0,y.getDefaultAgentProfile)(a.provider);if(n){console.log(`\u2713 default agents: ${a.provider} (${n.planner.model} / ${n.worker.model})`)}if(a.workspaceId)console.log(`\u2713 workspace registered (id=${a.workspaceId}, slug=${a.slug})`);console.log("\u2713 done")}catch(i){console.error("\u2717 init failed:",i.message);process.exit(1)}return}case"db":await(0,T.handleDb)(e.slice(1));return;case"shortcut":await(0,E.handleShortcut)(e.slice(1));return;case"publish":await(0,R.handlePublish)(e.slice(1));return;case"slack":case"slack:files":await(0,M.handleSlack)(e.slice(1));return;case"hook-dispatch":await(0,L.handleHookDispatch)(e.slice(1));return;case"help":case"--help":case"-h":f();return;case"--version":case"-v":{const t=require("../package.json");console.log(t.version);return}}if(c.NOT_YET_MIGRATED.has(o)){console.error(`Command '${o}' is not yet migrated in SDK refactor round. See packages/cli-bak for reference.`);process.exit(1)}if(o==="hook"){const t=e[1];const s=e.slice(2);switch(t){case"install":await(0,j.handleHookInstall)(s);return;case"uninstall":await(0,N.handleHookUninstall)(s);return;case"status":await(0,A.handleHookStatus)(s);return;default:console.error(`Unknown hook subcommand: ${t??"(none)"}`);console.error("Usage: crewx hook install|uninstall|status");process.exit(1)}}console.error(`Unknown command: ${o}`);console.error("Run `crewx --help` for usage.");process.exit(1)}function f(){console.log(`
5
+ CrewX CLI v${B.CLI_VERSION}
272
6
 
273
7
  Usage:
274
8
  crewx Launch web dashboard + open browser (default)
@@ -368,26 +102,9 @@ Hook Platform:
368
102
  hook install [--yes] Install PreToolUse hook in .claude/settings.json
369
103
  hook uninstall Remove crewx hook from .claude/settings.json
370
104
  hook status Show hook installation status and plugins
371
- hook-dispatch Internal: IPC router called by Claude (stdin→stdout)
105
+ hook-dispatch Internal: IPC router called by Claude (stdin\u2192stdout)
372
106
 
373
107
  Global Options:
374
108
  --help, -h Show this help
375
109
  --version, -v Show version
376
- `.trim());
377
- }
378
- function getProcessExitCode(error) {
379
- if (error instanceof parse_common_flags_1.UnknownOptionError)
380
- return 2;
381
- if (typeof error === 'object' && error !== null && 'exitCode' in error) {
382
- const exitCode = error.exitCode;
383
- if (typeof exitCode === 'number')
384
- return exitCode;
385
- }
386
- return 1;
387
- }
388
- const emitState = (0, emit_trailer_1.createDelegationEmitState)();
389
- main(emitState).catch((err) => {
390
- console.error(err instanceof Error ? err.message : String(err));
391
- (0, emit_trailer_1.emitDelegationResult)({ command: process.argv[2], isError: true, state: emitState });
392
- process.exit(getProcessExitCode(err));
393
- });
110
+ `.trim())}function H(r){if(r instanceof U.UnknownOptionError)return 2;if(typeof r==="object"&&r!==null&&"exitCode"in r){const e=r.exitCode;if(typeof e==="number")return e}return 1}const m=(0,g.createDelegationEmitState)();F(m).catch(r=>{console.error(r instanceof Error?r.message:String(r));(0,g.emitDelegationResult)({command:process.argv[2],isError:true,state:m});process.exit(H(r))});
@@ -1,9 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.registerBuiltinToolsIfNeeded = void 0;
4
- /**
5
- * Register built-in Node.js tools for api/* provider agents.
6
- * Delegates to @crewx/sdk/tools/node.
7
- */
8
- var node_1 = require("@crewx/sdk/tools/node");
9
- Object.defineProperty(exports, "registerBuiltinToolsIfNeeded", { enumerable: true, get: function () { return node_1.registerBuiltinTools; } });
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.registerBuiltinToolsIfNeeded=void 0;var e=require("@crewx/sdk/tools/node");Object.defineProperty(exports,"registerBuiltinToolsIfNeeded",{enumerable:true,get:function(){return e.registerBuiltinTools}});