@crewx/cli 0.9.0-rc.14 → 0.9.0-rc.141
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.
- package/dist/bootstrap/codex-writable-roots.d.ts +13 -0
- package/dist/bootstrap/codex-writable-roots.js +25 -0
- package/dist/bootstrap/crewx-cli.js +27 -6
- package/dist/builtin.d.ts +1 -1
- package/dist/builtin.js +7 -2
- package/dist/commands/agent.js +1 -107
- package/dist/commands/cal.d.ts +15 -0
- package/dist/commands/cal.js +44 -0
- package/dist/commands/db.d.ts +3 -0
- package/dist/commands/db.js +533 -1
- package/dist/commands/detached.d.ts +95 -0
- package/dist/commands/detached.js +620 -0
- package/dist/commands/doctor.d.ts +77 -0
- package/dist/commands/doctor.js +475 -22
- package/dist/commands/emit-trailer.d.ts +25 -0
- package/dist/commands/emit-trailer.js +33 -0
- package/dist/commands/execute.d.ts +8 -4
- package/dist/commands/execute.js +200 -51
- package/dist/commands/hook/command-marker.d.ts +2 -0
- package/dist/commands/hook/command-marker.js +5 -0
- package/dist/commands/hook/install.d.ts +0 -1
- package/dist/commands/hook/install.js +75 -61
- package/dist/commands/hook/status.js +3 -3
- package/dist/commands/hook/uninstall.js +2 -2
- package/dist/commands/init.d.ts +34 -0
- package/dist/commands/init.js +132 -59
- package/dist/commands/kill.d.ts +2 -8
- package/dist/commands/kill.js +6 -47
- package/dist/commands/log.js +4 -3
- package/dist/commands/parse-common-flags.d.ts +5 -1
- package/dist/commands/parse-common-flags.js +35 -4
- package/dist/commands/ps.d.ts +2 -2
- package/dist/commands/ps.js +25 -15
- package/dist/commands/publish.d.ts +1 -0
- package/dist/commands/publish.js +303 -0
- package/dist/commands/query.d.ts +7 -2
- package/dist/commands/query.js +195 -48
- package/dist/commands/registry.js +4 -2
- package/dist/commands/resolve-prompt.js +23 -1
- package/dist/commands/resolve-recipient.d.ts +14 -0
- package/dist/commands/resolve-recipient.js +47 -0
- package/dist/commands/restart.d.ts +3 -1
- package/dist/commands/restart.js +14 -4
- package/dist/commands/result.d.ts +8 -3
- package/dist/commands/result.js +149 -10
- package/dist/commands/shortcut.d.ts +1 -0
- package/dist/commands/shortcut.js +267 -0
- package/dist/commands/slack.js +2 -1
- package/dist/commands/stop.d.ts +8 -0
- package/dist/commands/stop.js +119 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -1
- package/dist/logging.d.ts +1 -1
- package/dist/logging.js +3 -2
- package/dist/main.d.ts +3 -2
- package/dist/main.js +99 -24
- package/dist/utils/env-defaults.d.ts +2 -5
- package/dist/utils/env-defaults.js +10 -5
- package/dist/utils/inherited-trace.d.ts +24 -0
- package/dist/utils/inherited-trace.js +40 -0
- package/dist/utils/product-package-root.d.ts +6 -0
- package/dist/utils/product-package-root.js +39 -0
- package/dist/utils/sdk-compat.d.ts +24 -0
- package/dist/utils/sdk-compat.js +120 -0
- package/package.json +16 -12
package/dist/commands/slack.js
CHANGED
|
@@ -44,6 +44,7 @@ exports.handleSlack = handleSlack;
|
|
|
44
44
|
const fs = __importStar(require("fs"));
|
|
45
45
|
const path = __importStar(require("path"));
|
|
46
46
|
const https = __importStar(require("https"));
|
|
47
|
+
const sdk_1 = require("@crewx/sdk");
|
|
47
48
|
const adapter_slack_1 = require("@crewx/adapter-slack");
|
|
48
49
|
const crewx_cli_1 = require("../bootstrap/crewx-cli");
|
|
49
50
|
const markdown_1 = require("../slack/markdown");
|
|
@@ -186,7 +187,7 @@ async function handleListFiles(threadId) {
|
|
|
186
187
|
console.log(` 📎 ${file.fileName}`);
|
|
187
188
|
console.log(` Size: ${formatFileSize(file.fileSize)}`);
|
|
188
189
|
console.log(` Path: ${file.filePath}`);
|
|
189
|
-
console.log(` Downloaded: ${file.downloadedAt
|
|
190
|
+
console.log(` Downloaded: ${(0, sdk_1.formatDisplayTimestamp)(file.downloadedAt)}`);
|
|
190
191
|
console.log('');
|
|
191
192
|
}
|
|
192
193
|
console.log(`Total: ${files.length} file${files.length > 1 ? 's' : ''}\n`);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stop a running task through the SDK's cooperative-stop pipeline.
|
|
3
|
+
*
|
|
4
|
+
* `kill` is kept as a compatibility alias; both entry points use this same
|
|
5
|
+
* handler so server, CLI, and future adapters share one stop contract.
|
|
6
|
+
*/
|
|
7
|
+
/** Handle `crewx stop` and the compatibility `crewx kill` alias. */
|
|
8
|
+
export declare function handleStop(args: string[], invokedAs?: 'stop' | 'kill'): Promise<void>;
|
|
@@ -0,0 +1,119 @@
|
|
|
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
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { handleInit, type InitResult } from './commands/init';
|
|
1
|
+
export { buildDefaultAgents, handleInit, parseInitProvider, resolveInitProvider, type InitProvider, type InitResult, } from './commands/init';
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.handleInit = void 0;
|
|
3
|
+
exports.resolveInitProvider = exports.parseInitProvider = exports.handleInit = exports.buildDefaultAgents = void 0;
|
|
4
4
|
var init_1 = require("./commands/init");
|
|
5
|
+
Object.defineProperty(exports, "buildDefaultAgents", { enumerable: true, get: function () { return init_1.buildDefaultAgents; } });
|
|
5
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; } });
|
package/dist/logging.d.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*
|
|
10
10
|
* Format mirrors cli-bak TaskManagementService for backward compatibility.
|
|
11
11
|
*/
|
|
12
|
-
import type
|
|
12
|
+
import { type Crewx } from '@crewx/sdk';
|
|
13
13
|
/**
|
|
14
14
|
* Attach file-based logging to a Crewx instance.
|
|
15
15
|
* Subscribes to task:start and task:end events and writes log files.
|
package/dist/logging.js
CHANGED
|
@@ -14,6 +14,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
14
14
|
exports.attachFileLogger = attachFileLogger;
|
|
15
15
|
const fs_1 = require("fs");
|
|
16
16
|
const path_1 = require("path");
|
|
17
|
+
const sdk_1 = require("@crewx/sdk");
|
|
17
18
|
const CREWX_VERSION = '0.9.0-alpha.1';
|
|
18
19
|
/** Format Date as YYYYMMDDTHHmmss (local time) */
|
|
19
20
|
function formatTimestamp(date) {
|
|
@@ -52,7 +53,7 @@ function attachFileLogger(crewx, workspaceRoot) {
|
|
|
52
53
|
`CrewX Version: ${CREWX_VERSION}\n` +
|
|
53
54
|
`Mode: ${event.mode}\n` +
|
|
54
55
|
`Agent: ${event.agentRef}\n` +
|
|
55
|
-
`Started: ${event.timestamp
|
|
56
|
+
`Started: ${(0, sdk_1.formatDisplayTimestamp)(event.timestamp)}\n` +
|
|
56
57
|
`Message: ${event.message}\n` +
|
|
57
58
|
`\n`;
|
|
58
59
|
(0, fs_1.writeFileSync)(logFile, header, { encoding: 'utf8', mode: 0o600 });
|
|
@@ -66,7 +67,7 @@ function attachFileLogger(crewx, workspaceRoot) {
|
|
|
66
67
|
const logFile = logFiles.get(event.traceId);
|
|
67
68
|
if (!logFile)
|
|
68
69
|
return;
|
|
69
|
-
const ts = new Date()
|
|
70
|
+
const ts = (0, sdk_1.formatDisplayTimestamp)(new Date());
|
|
70
71
|
const status = event.error
|
|
71
72
|
? `failed: ${event.error.message}`
|
|
72
73
|
: 'completed successfully';
|
package/dist/main.d.ts
CHANGED
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
*
|
|
6
6
|
* Boot sequence:
|
|
7
7
|
* 1. Inject CREWX_CLI / CREWX_WORKSPACE env defaults (must be first)
|
|
8
|
-
* 2.
|
|
9
|
-
* 3.
|
|
8
|
+
* 2. Load workspace and ~/.crewx .env files (does not override process.env)
|
|
9
|
+
* 3. Parse command
|
|
10
|
+
* 4. Dispatch to handler
|
|
10
11
|
*/
|
|
11
12
|
export {};
|
package/dist/main.js
CHANGED
|
@@ -6,8 +6,9 @@
|
|
|
6
6
|
*
|
|
7
7
|
* Boot sequence:
|
|
8
8
|
* 1. Inject CREWX_CLI / CREWX_WORKSPACE env defaults (must be first)
|
|
9
|
-
* 2.
|
|
10
|
-
* 3.
|
|
9
|
+
* 2. Load workspace and ~/.crewx .env files (does not override process.env)
|
|
10
|
+
* 3. Parse command
|
|
11
|
+
* 4. Dispatch to handler
|
|
11
12
|
*/
|
|
12
13
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
13
14
|
if (k2 === undefined) k2 = k;
|
|
@@ -45,26 +46,36 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
45
46
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
47
|
// ─── P0-1: Env Bootstrap ─────────────────────────────────────────────────────
|
|
47
48
|
// Must run before any other code that might use process.env.CREWX_CLI.
|
|
48
|
-
const
|
|
49
|
+
const sdk_compat_1 = require("./utils/sdk-compat");
|
|
50
|
+
const account_1 = require("@crewx/sdk/account");
|
|
49
51
|
const sdk_1 = require("@crewx/sdk");
|
|
50
|
-
|
|
51
|
-
process.env.
|
|
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)();
|
|
52
61
|
// ─── Pricing remote override (WI-20260701-002) ───────────────────────────────
|
|
53
62
|
// Best-effort, non-blocking: fetch remote model registry so new models get
|
|
54
63
|
// accurate pricing without a CLI republish. Falls back to bundled table on
|
|
55
64
|
// failure / offline. Browser entry does not call this automatically.
|
|
56
|
-
|
|
65
|
+
sdk_compat_1.sdkCompat.initPricingRemote();
|
|
57
66
|
// ─── Command Imports ──────────────────────────────────────────────────────────
|
|
58
67
|
const query_1 = require("./commands/query");
|
|
59
68
|
const execute_1 = require("./commands/execute");
|
|
60
69
|
const agent_1 = require("./commands/agent");
|
|
61
70
|
const ps_1 = require("./commands/ps");
|
|
62
|
-
const
|
|
71
|
+
const stop_1 = require("./commands/stop");
|
|
63
72
|
const result_1 = require("./commands/result");
|
|
64
73
|
const restart_1 = require("./commands/restart");
|
|
65
74
|
const log_1 = require("./commands/log");
|
|
66
75
|
const doctor_1 = require("./commands/doctor");
|
|
67
76
|
const init_1 = require("./commands/init");
|
|
77
|
+
const shortcut_1 = require("./commands/shortcut");
|
|
78
|
+
const publish_1 = require("./commands/publish");
|
|
68
79
|
const builtin_1 = require("./builtin");
|
|
69
80
|
const slack_1 = require("./commands/slack");
|
|
70
81
|
const install_1 = require("./commands/hook/install");
|
|
@@ -75,6 +86,8 @@ const db_1 = require("./commands/db");
|
|
|
75
86
|
const parse_common_flags_1 = require("./commands/parse-common-flags");
|
|
76
87
|
const registry_1 = require("./commands/registry");
|
|
77
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");
|
|
78
91
|
/**
|
|
79
92
|
* Dev-only SSOT assertion: bin/cli-commands.js must be the exact union of
|
|
80
93
|
* KNOWN_COMMANDS ∪ BUILTIN_COMMAND_NAMES ∪ NOT_YET_MIGRATED from registry.ts.
|
|
@@ -99,7 +112,7 @@ async function assertSsotParity() {
|
|
|
99
112
|
(extra.length ? ` CLI_SUBCOMMANDS has, registry missing: ${extra.join(', ')}` : ''));
|
|
100
113
|
}
|
|
101
114
|
}
|
|
102
|
-
async function main() {
|
|
115
|
+
async function main(emitState) {
|
|
103
116
|
if (process.env['NODE_ENV'] === 'development') {
|
|
104
117
|
await assertSsotParity();
|
|
105
118
|
}
|
|
@@ -111,7 +124,10 @@ async function main() {
|
|
|
111
124
|
}
|
|
112
125
|
// Built-in tools: memory, search, doc, wbs, cron, workflow, skill
|
|
113
126
|
if (builtin_1.BUILTIN_COMMANDS.has(command)) {
|
|
114
|
-
|
|
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);
|
|
115
131
|
return;
|
|
116
132
|
}
|
|
117
133
|
// Core commands
|
|
@@ -119,11 +135,11 @@ async function main() {
|
|
|
119
135
|
// P0-2: q/x aliases
|
|
120
136
|
case 'q':
|
|
121
137
|
case 'query':
|
|
122
|
-
await (0, query_1.handleQuery)(args.slice(1));
|
|
138
|
+
await (0, query_1.handleQuery)(args.slice(1), command, emitState);
|
|
123
139
|
return;
|
|
124
140
|
case 'x':
|
|
125
141
|
case 'execute':
|
|
126
|
-
await (0, execute_1.handleExecute)(args.slice(1));
|
|
142
|
+
await (0, execute_1.handleExecute)(args.slice(1), command, emitState);
|
|
127
143
|
return;
|
|
128
144
|
case 'agent':
|
|
129
145
|
await (0, agent_1.handleAgent)(args.slice(1));
|
|
@@ -132,9 +148,12 @@ async function main() {
|
|
|
132
148
|
case 'ps':
|
|
133
149
|
await (0, ps_1.handlePs)(args.slice(1));
|
|
134
150
|
return;
|
|
135
|
-
//
|
|
151
|
+
// Task stop (kill is a compatibility alias)
|
|
152
|
+
case 'stop':
|
|
153
|
+
await (0, stop_1.handleStop)(args.slice(1), 'stop');
|
|
154
|
+
return;
|
|
136
155
|
case 'kill':
|
|
137
|
-
await (0,
|
|
156
|
+
await (0, stop_1.handleStop)(args.slice(1), 'kill');
|
|
138
157
|
return;
|
|
139
158
|
// P0-6: result
|
|
140
159
|
case 'result':
|
|
@@ -157,7 +176,8 @@ async function main() {
|
|
|
157
176
|
const initArgs = args.slice(1);
|
|
158
177
|
const force = initArgs.includes('--force') || initArgs.includes('-f');
|
|
159
178
|
try {
|
|
160
|
-
const
|
|
179
|
+
const provider = (0, init_1.parseInitProvider)(initArgs);
|
|
180
|
+
const r = await (0, init_1.handleInit)({ path: process.cwd(), force, provider });
|
|
161
181
|
if (r.skippedReason === 'yaml-exists') {
|
|
162
182
|
console.log('✓ crewx.yaml already exists (use --force to overwrite)');
|
|
163
183
|
}
|
|
@@ -167,6 +187,10 @@ async function main() {
|
|
|
167
187
|
if (r.errors.length > 0)
|
|
168
188
|
console.warn('Warnings:', r.errors.join('; '));
|
|
169
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
|
+
}
|
|
170
194
|
if (r.workspaceId)
|
|
171
195
|
console.log(`✓ workspace registered (id=${r.workspaceId}, slug=${r.slug})`);
|
|
172
196
|
console.log('✓ done');
|
|
@@ -181,6 +205,14 @@ async function main() {
|
|
|
181
205
|
case 'db':
|
|
182
206
|
await (0, db_1.handleDb)(args.slice(1));
|
|
183
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;
|
|
184
216
|
// SDK-009: slack / slack:files
|
|
185
217
|
case 'slack':
|
|
186
218
|
case 'slack:files':
|
|
@@ -248,12 +280,14 @@ UI Modes:
|
|
|
248
280
|
crewx electron [--overlay] Launch Electron (desktop or overlay window)
|
|
249
281
|
|
|
250
282
|
Query / Execute:
|
|
251
|
-
q|query
|
|
252
|
-
x|execute
|
|
283
|
+
q|query --to <agent> <message> Query an agent
|
|
284
|
+
x|execute --to <agent> <task> Execute a task with an agent
|
|
253
285
|
|
|
254
|
-
@agent is
|
|
286
|
+
Positional @agent <message> is shorthand for selecting a recipient.
|
|
287
|
+
Agent calls require a recipient; human terminal and cron calls default to @crewx.
|
|
255
288
|
|
|
256
289
|
Common flags:
|
|
290
|
+
--to <agent> Explicit agent recipient
|
|
257
291
|
--thread <name> Conversation thread
|
|
258
292
|
--provider <cli/xxx> Provider override
|
|
259
293
|
--metadata <json> Extra metadata (JSON object, double-quoted). Propagated to events/hooks/tracing.
|
|
@@ -262,11 +296,18 @@ Query / Execute:
|
|
|
262
296
|
--verbose Debug output mode (default: raw response only)
|
|
263
297
|
--config/-c <path> Config file path (default: CREWX_CONFIG or crewx.yaml)
|
|
264
298
|
--output-format <fmt> Output format (json|text|stream-json)
|
|
299
|
+
--out/-o <path> Save result to file (stdout suppressed)
|
|
265
300
|
--effort <level> Model effort (high|medium|low)
|
|
266
|
-
-f/--prompt-file <path> Read
|
|
301
|
+
-f/--prompt-file <path> Read body only from file; set recipient with --to (bypasses argv length limits)
|
|
267
302
|
--var key=value Template variable (repeatable). Accessible as {{key}} in agent prompt.
|
|
268
303
|
-- End of flags; remaining tokens treated as message text
|
|
269
|
-
e.g. crewx q
|
|
304
|
+
e.g. crewx q --to agent "label" -- --flag-in-message
|
|
305
|
+
|
|
306
|
+
q/query/x/execute:
|
|
307
|
+
--detach/--async Persist a receipt, launch a detached runner, and print task-id
|
|
308
|
+
(automatic inside an agent process; q/x stay synchronous elsewhere).
|
|
309
|
+
--wait Force synchronous execution, including inside an agent process.
|
|
310
|
+
e.g. crewx x --to agent "label" --detach
|
|
270
311
|
|
|
271
312
|
Agent Management:
|
|
272
313
|
agent ls [options] List configured agents
|
|
@@ -277,20 +318,42 @@ Agent Management:
|
|
|
277
318
|
|
|
278
319
|
Task Management:
|
|
279
320
|
ps List running tasks
|
|
280
|
-
|
|
281
|
-
|
|
321
|
+
stop <task-id> Stop a running task (cooperative, then forced)
|
|
322
|
+
stop --all Stop all running tasks
|
|
323
|
+
kill <task-id> Alias for stop
|
|
282
324
|
result [task-id] Get task result (or list recent tasks)
|
|
325
|
+
--wait=N Poll (1s interval) up to N seconds for the task to
|
|
326
|
+
finish. Exit 124 on timeout. --wait=0 = single check.
|
|
283
327
|
restart <task-id> Restart a failed task as a new task
|
|
284
328
|
|
|
285
329
|
Logs & Diagnostics:
|
|
286
330
|
log [ls|<task-id>] View task logs
|
|
287
331
|
doctor [--config <path>] Run system diagnosis
|
|
288
|
-
init [--force] [--
|
|
332
|
+
init [--force] [--provider cli/claude|cli/codex] Initialize crewx.yaml
|
|
289
333
|
|
|
290
334
|
Database:
|
|
291
335
|
db push Sync DB schema to current code (additive only)
|
|
292
336
|
--force Reset migration history + skip confirmation
|
|
293
337
|
--dry-run Preview changes without applying
|
|
338
|
+
db migrate-task-logs Backfill legacy tasks.logs into task_log_events
|
|
339
|
+
--dry-run Validate and estimate without writing
|
|
340
|
+
--apply Consistent backup + resumable task-by-task apply
|
|
341
|
+
--verify Check event/source invariants and parity
|
|
342
|
+
db migrate-request-logs Move request logs from crewx.db into logs.db (bodies stored once)
|
|
343
|
+
--batch N Rows per batch (default 250)
|
|
344
|
+
--dry-run Count rows and distinct bodies without writing
|
|
345
|
+
|
|
346
|
+
Desktop Shortcut (Windows only):
|
|
347
|
+
shortcut status [--json] Show current shortcut status
|
|
348
|
+
shortcut install [--force] [--json] Install/repair the Desktop shortcut
|
|
349
|
+
shortcut uninstall [--json] Remove the Desktop shortcut
|
|
350
|
+
|
|
351
|
+
Publish:
|
|
352
|
+
publish [dir] [options] Package a workspace as a distributable template archive
|
|
353
|
+
--dry-run Scan + build manifest only; do not write a .tgz
|
|
354
|
+
--version <ver> Override manifest version (semver)
|
|
355
|
+
--json Print machine-readable JSON to stdout
|
|
356
|
+
--upload Submit + upload using the SDK account session
|
|
294
357
|
|
|
295
358
|
Built-in Tools:
|
|
296
359
|
memory <args> Memory tool
|
|
@@ -312,7 +375,19 @@ Global Options:
|
|
|
312
375
|
--version, -v Show version
|
|
313
376
|
`.trim());
|
|
314
377
|
}
|
|
315
|
-
|
|
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) => {
|
|
316
390
|
console.error(err instanceof Error ? err.message : String(err));
|
|
317
|
-
|
|
391
|
+
(0, emit_trailer_1.emitDelegationResult)({ command: process.argv[2], isError: true, state: emitState });
|
|
392
|
+
process.exit(getProcessExitCode(err));
|
|
318
393
|
});
|
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* Re-exported from @crewx/sdk for convenience.
|
|
4
|
-
*/
|
|
5
|
-
export { resolveCrewxCli, resolveCrewxWorkspace } from '@crewx/sdk';
|
|
1
|
+
export declare function resolveCrewxCli(): string;
|
|
2
|
+
export declare function resolveCrewxWorkspace(): string;
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.resolveCrewxCli = resolveCrewxCli;
|
|
4
|
+
exports.resolveCrewxWorkspace = resolveCrewxWorkspace;
|
|
4
5
|
/**
|
|
5
6
|
* CREWX_* environment variable defaults for CLI bootstrap.
|
|
6
|
-
*
|
|
7
|
+
* Routed through the SDK compatibility accessor for older SDK installations.
|
|
7
8
|
*/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
const sdk_compat_1 = require("./sdk-compat");
|
|
10
|
+
function resolveCrewxCli() {
|
|
11
|
+
return sdk_compat_1.sdkCompat.resolveCrewxCli();
|
|
12
|
+
}
|
|
13
|
+
function resolveCrewxWorkspace() {
|
|
14
|
+
return sdk_compat_1.sdkCompat.resolveCrewxWorkspace();
|
|
15
|
+
}
|
|
@@ -1,4 +1,19 @@
|
|
|
1
1
|
import type { TraceContext } from '@crewx/sdk';
|
|
2
|
+
export interface InheritedRunnerIdentity {
|
|
3
|
+
assignedTaskId?: string;
|
|
4
|
+
detachedRunner: boolean;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Consume the runner-only identity exactly once.
|
|
8
|
+
*
|
|
9
|
+
* These variables are a one-hop capability, not trace context. Keeping the
|
|
10
|
+
* values in this module lets the current CLI process use them while deleting
|
|
11
|
+
* them from process.env prevents later child processes from inheriting the
|
|
12
|
+
* receipt runner identity.
|
|
13
|
+
*/
|
|
14
|
+
export declare function consumeInheritedRunnerIdentity(): InheritedRunnerIdentity;
|
|
15
|
+
/** Test-only reset for the module-level one-shot cache. */
|
|
16
|
+
export declare function resetInheritedRunnerIdentityForTests(): void;
|
|
2
17
|
/**
|
|
3
18
|
* Read cross-process trace context from inherited environment variables.
|
|
4
19
|
*
|
|
@@ -10,3 +25,12 @@ import type { TraceContext } from '@crewx/sdk';
|
|
|
10
25
|
* Returns undefined when none of the three vars are set (root invocation).
|
|
11
26
|
*/
|
|
12
27
|
export declare function readInheritedTrace(): TraceContext | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Read the pre-assigned task id carried only by a detached runner.
|
|
30
|
+
*
|
|
31
|
+
* This is deliberately separate from readInheritedTrace(): trace variables
|
|
32
|
+
* describe the caller's chain and must not be used as this task's identity.
|
|
33
|
+
*/
|
|
34
|
+
export declare function readRunnerAssignment(): string | undefined;
|
|
35
|
+
/** Return true only for the final detached runner process. */
|
|
36
|
+
export declare function isDetachedRunner(): boolean;
|
|
@@ -1,6 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.consumeInheritedRunnerIdentity = consumeInheritedRunnerIdentity;
|
|
4
|
+
exports.resetInheritedRunnerIdentityForTests = resetInheritedRunnerIdentityForTests;
|
|
3
5
|
exports.readInheritedTrace = readInheritedTrace;
|
|
6
|
+
exports.readRunnerAssignment = readRunnerAssignment;
|
|
7
|
+
exports.isDetachedRunner = isDetachedRunner;
|
|
8
|
+
let inheritedRunnerIdentity;
|
|
9
|
+
/**
|
|
10
|
+
* Consume the runner-only identity exactly once.
|
|
11
|
+
*
|
|
12
|
+
* These variables are a one-hop capability, not trace context. Keeping the
|
|
13
|
+
* values in this module lets the current CLI process use them while deleting
|
|
14
|
+
* them from process.env prevents later child processes from inheriting the
|
|
15
|
+
* receipt runner identity.
|
|
16
|
+
*/
|
|
17
|
+
function consumeInheritedRunnerIdentity() {
|
|
18
|
+
if (inheritedRunnerIdentity !== undefined)
|
|
19
|
+
return inheritedRunnerIdentity;
|
|
20
|
+
const assignedTaskId = process.env['CREWX_ASSIGNED_TASK_ID']?.trim() || undefined;
|
|
21
|
+
const detachedRunner = process.env['CREWX_DETACHED_RUNNER'] === '1';
|
|
22
|
+
delete process.env['CREWX_ASSIGNED_TASK_ID'];
|
|
23
|
+
delete process.env['CREWX_DETACHED_RUNNER'];
|
|
24
|
+
inheritedRunnerIdentity = { assignedTaskId, detachedRunner };
|
|
25
|
+
return inheritedRunnerIdentity;
|
|
26
|
+
}
|
|
27
|
+
/** Test-only reset for the module-level one-shot cache. */
|
|
28
|
+
function resetInheritedRunnerIdentityForTests() {
|
|
29
|
+
inheritedRunnerIdentity = undefined;
|
|
30
|
+
}
|
|
4
31
|
/**
|
|
5
32
|
* Read cross-process trace context from inherited environment variables.
|
|
6
33
|
*
|
|
@@ -23,3 +50,16 @@ function readInheritedTrace() {
|
|
|
23
50
|
callerAgentId,
|
|
24
51
|
};
|
|
25
52
|
}
|
|
53
|
+
/**
|
|
54
|
+
* Read the pre-assigned task id carried only by a detached runner.
|
|
55
|
+
*
|
|
56
|
+
* This is deliberately separate from readInheritedTrace(): trace variables
|
|
57
|
+
* describe the caller's chain and must not be used as this task's identity.
|
|
58
|
+
*/
|
|
59
|
+
function readRunnerAssignment() {
|
|
60
|
+
return consumeInheritedRunnerIdentity().assignedTaskId;
|
|
61
|
+
}
|
|
62
|
+
/** Return true only for the final detached runner process. */
|
|
63
|
+
function isDetachedRunner() {
|
|
64
|
+
return consumeInheritedRunnerIdentity().detachedRunner;
|
|
65
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Finds the installed product root from the CLI entry file that is running.
|
|
3
|
+
* The real CLI path is walked to the first package named `crewx`, which must
|
|
4
|
+
* contain the compiled bundle helper. cwd and environment are deliberately ignored.
|
|
5
|
+
*/
|
|
6
|
+
export declare function resolveProductRootFromCliEntry(cliEntryPath: string | undefined): string | undefined;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveProductRootFromCliEntry = resolveProductRootFromCliEntry;
|
|
4
|
+
const node_fs_1 = require("node:fs");
|
|
5
|
+
const node_path_1 = require("node:path");
|
|
6
|
+
const PRODUCT_BUNDLE_HELPER = (0, node_path_1.join)('dist-server', 'common', 'product-app-bundle.js');
|
|
7
|
+
/**
|
|
8
|
+
* Finds the installed product root from the CLI entry file that is running.
|
|
9
|
+
* The real CLI path is walked to the first package named `crewx`, which must
|
|
10
|
+
* contain the compiled bundle helper. cwd and environment are deliberately ignored.
|
|
11
|
+
*/
|
|
12
|
+
function resolveProductRootFromCliEntry(cliEntryPath) {
|
|
13
|
+
if (typeof cliEntryPath !== 'string' || cliEntryPath.trim().length === 0)
|
|
14
|
+
return undefined;
|
|
15
|
+
let realCliEntryPath;
|
|
16
|
+
try {
|
|
17
|
+
realCliEntryPath = (0, node_fs_1.realpathSync)(cliEntryPath);
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
let current = (0, node_path_1.dirname)(realCliEntryPath);
|
|
23
|
+
while (true) {
|
|
24
|
+
try {
|
|
25
|
+
const packageJson = JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.join)(current, 'package.json'), 'utf8'));
|
|
26
|
+
if (packageJson.name === 'crewx') {
|
|
27
|
+
return (0, node_fs_1.existsSync)((0, node_path_1.join)(current, PRODUCT_BUNDLE_HELPER)) ? current : undefined;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
// Continue to the next ancestor when this directory has no valid package manifest.
|
|
32
|
+
}
|
|
33
|
+
const parent = (0, node_path_1.dirname)(current);
|
|
34
|
+
if (parent === current)
|
|
35
|
+
return undefined;
|
|
36
|
+
current = parent;
|
|
37
|
+
}
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { CrewxExecutableResolution } from '@crewx/sdk';
|
|
2
|
+
type PricingInitializer = () => Promise<unknown> | unknown;
|
|
3
|
+
export interface SdkLike {
|
|
4
|
+
resolveCrewxCli?: () => string;
|
|
5
|
+
resolveCrewxCliArgv?: () => CrewxExecutableResolution;
|
|
6
|
+
resolveCrewxWorkspace?: () => string;
|
|
7
|
+
initPricingRemote?: PricingInitializer;
|
|
8
|
+
}
|
|
9
|
+
export interface SdkCompat {
|
|
10
|
+
resolveCrewxCli(): string;
|
|
11
|
+
resolveCrewxCliArgv(): CrewxExecutableResolution;
|
|
12
|
+
resolveCrewxWorkspace(): string;
|
|
13
|
+
initPricingRemote(): void;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Create the CLI bootstrap capability accessor for the installed SDK.
|
|
17
|
+
*
|
|
18
|
+
* SDK exports are additive across compatible majors, so an older SDK may not
|
|
19
|
+
* expose every capability that a newer CLI knows about. Optional capabilities
|
|
20
|
+
* are checked here rather than at each bootstrap call site.
|
|
21
|
+
*/
|
|
22
|
+
export declare function createSdkCompat(sdkLike?: SdkLike): SdkCompat;
|
|
23
|
+
export declare const sdkCompat: SdkCompat;
|
|
24
|
+
export {};
|