@crewx/cli 0.9.0-rc.12 ā 0.9.0-rc.120
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.js +2 -0
- 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 +2 -0
- package/dist/commands/db.js +381 -1
- package/dist/commands/detached.d.ts +89 -0
- package/dist/commands/detached.js +580 -0
- package/dist/commands/doctor.d.ts +77 -0
- package/dist/commands/doctor.js +474 -21
- package/dist/commands/emit-trailer.d.ts +25 -0
- package/dist/commands/emit-trailer.js +33 -0
- package/dist/commands/execute.d.ts +7 -4
- package/dist/commands/execute.js +171 -41
- 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 +130 -57
- 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 +6 -2
- 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 +5 -1
- package/dist/commands/query.js +165 -37
- package/dist/commands/registry.js +4 -2
- package/dist/commands/result.d.ts +8 -3
- package/dist/commands/result.js +139 -7
- 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/commands/write-output.d.ts +3 -0
- package/dist/commands/write-output.js +24 -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 +84 -18
- 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/sdk-compat.d.ts +24 -0
- package/dist/utils/sdk-compat.js +120 -0
- package/package.json +16 -12
|
@@ -0,0 +1,303 @@
|
|
|
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 __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.handlePublish = handlePublish;
|
|
37
|
+
/**
|
|
38
|
+
* crewx publish handler ā thin CLI wrapper over @crewx/sdk/publish.
|
|
39
|
+
*
|
|
40
|
+
* Usage:
|
|
41
|
+
* crewx publish [dir] [--dry-run] [--version <semver>] [--json] [--upload]
|
|
42
|
+
*
|
|
43
|
+
* All scanning, exclusion-rule judgment, secret detection, hashing, and
|
|
44
|
+
* tar.gz packing lives in @crewx/sdk/publish (planPublish / packTemplate).
|
|
45
|
+
* Submit+upload (WI-SHR-20260806-013) lives in the same package
|
|
46
|
+
* (uploadToMarketplace) for the same reason ā see that module's header.
|
|
47
|
+
* This command only parses argv, forwards options, asks the SDK SessionManager
|
|
48
|
+
* for a valid account bearer when upload is requested, and renders the result.
|
|
49
|
+
*/
|
|
50
|
+
const fs = __importStar(require("fs"));
|
|
51
|
+
const account_1 = require("@crewx/sdk/account");
|
|
52
|
+
const publish_1 = require("@crewx/sdk/publish");
|
|
53
|
+
const parse_common_flags_1 = require("./parse-common-flags");
|
|
54
|
+
function parsePublishFlags(args) {
|
|
55
|
+
const flags = { dryRun: false, json: false, help: false, upload: false };
|
|
56
|
+
for (let i = 0; i < args.length; i++) {
|
|
57
|
+
const arg = args[i];
|
|
58
|
+
if (arg === '--help' || arg === '-h') {
|
|
59
|
+
flags.help = true;
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (arg === '--dry-run') {
|
|
63
|
+
flags.dryRun = true;
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if (arg === '--json') {
|
|
67
|
+
flags.json = true;
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (arg === '--upload') {
|
|
71
|
+
flags.upload = true;
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (arg === '--version') {
|
|
75
|
+
const value = args[i + 1];
|
|
76
|
+
if (value === undefined)
|
|
77
|
+
throw new parse_common_flags_1.UnknownOptionError('--version requires a value');
|
|
78
|
+
flags.version = value;
|
|
79
|
+
i++;
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
if (arg.startsWith('--version=')) {
|
|
83
|
+
flags.version = arg.slice('--version='.length);
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (arg.startsWith('-')) {
|
|
87
|
+
throw new parse_common_flags_1.UnknownOptionError(`Unknown option: ${arg}`);
|
|
88
|
+
}
|
|
89
|
+
if (flags.dir === undefined) {
|
|
90
|
+
flags.dir = arg;
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
throw new parse_common_flags_1.UnknownOptionError(`Unknown option: ${arg}`);
|
|
94
|
+
}
|
|
95
|
+
return flags;
|
|
96
|
+
}
|
|
97
|
+
function resolveWorkspaceDir(flags) {
|
|
98
|
+
return flags.dir ?? process.env['CREWX_WORKSPACE'] ?? process.cwd();
|
|
99
|
+
}
|
|
100
|
+
function printJson(payload) {
|
|
101
|
+
console.log(JSON.stringify(payload));
|
|
102
|
+
}
|
|
103
|
+
/** Prints the error and exits 1. Never returns (matches `process.exit`'s `never` type). */
|
|
104
|
+
function failWithError(err, json) {
|
|
105
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
106
|
+
if (json) {
|
|
107
|
+
printJson({ success: false, error: message });
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
console.error(`ā ${message}`);
|
|
111
|
+
}
|
|
112
|
+
process.exit(1);
|
|
113
|
+
}
|
|
114
|
+
function printHelp() {
|
|
115
|
+
console.log(`
|
|
116
|
+
crewx publish ā package a workspace as a distributable template archive
|
|
117
|
+
|
|
118
|
+
Usage:
|
|
119
|
+
crewx publish [dir] [--dry-run] [--version <semver>] [--json] [--upload]
|
|
120
|
+
|
|
121
|
+
Arguments:
|
|
122
|
+
dir Workspace to publish (default: $CREWX_WORKSPACE or cwd)
|
|
123
|
+
|
|
124
|
+
Options:
|
|
125
|
+
--dry-run Scan + build manifest only; do not write a .tgz
|
|
126
|
+
--version <ver> Override manifest version (semver, e.g. 1.0.0)
|
|
127
|
+
--json Print machine-readable JSON to stdout
|
|
128
|
+
--upload Submit + upload the packed archive to marketplace
|
|
129
|
+
(uses the configured account target and a prior login;
|
|
130
|
+
ignored when combined with --dry-run)
|
|
131
|
+
--help, -h Show this help
|
|
132
|
+
|
|
133
|
+
Notes:
|
|
134
|
+
Without --upload, this command only scans the workspace, applies
|
|
135
|
+
exclusion rules, checks for secrets, and packs a local
|
|
136
|
+
.crewx/publish/<name>-<version>.tgz archive.
|
|
137
|
+
`.trim());
|
|
138
|
+
}
|
|
139
|
+
/** Resolve and validate the Marketplace target immediately before an upload. */
|
|
140
|
+
function requireMarketplaceUrl() {
|
|
141
|
+
try {
|
|
142
|
+
const url = (0, account_1.resolveMarketplaceUrl)();
|
|
143
|
+
(0, account_1.assertAccountTargetNotMixed)();
|
|
144
|
+
return url;
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
const code = typeof error === 'object' && error !== null && 'code' in error
|
|
148
|
+
? error.code
|
|
149
|
+
: undefined;
|
|
150
|
+
if (code === 'ACCOUNT_TARGET_INVALID' ||
|
|
151
|
+
code === 'ACCOUNT_TARGET_MIXED' ||
|
|
152
|
+
code === 'MARKETPLACE_DISABLED' ||
|
|
153
|
+
code === 'MARKETPLACE_URL_INVALID') {
|
|
154
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
155
|
+
throw new Error(`publish: [${code}] ${message}`);
|
|
156
|
+
}
|
|
157
|
+
throw error;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
function isMarketplaceUnauthorized(err) {
|
|
161
|
+
return err instanceof Error
|
|
162
|
+
&& err.message.includes('publish: [E_AUTH_EXPIRED]')
|
|
163
|
+
&& /HTTP 401\b/.test(err.message);
|
|
164
|
+
}
|
|
165
|
+
async function uploadWithSessionRefresh(sessionManager, options, accessToken) {
|
|
166
|
+
try {
|
|
167
|
+
return await (0, publish_1.uploadToMarketplace)({ ...options, accessToken });
|
|
168
|
+
}
|
|
169
|
+
catch (err) {
|
|
170
|
+
if (!isMarketplaceUnauthorized(err))
|
|
171
|
+
throw err;
|
|
172
|
+
const refreshedSession = await sessionManager.refresh();
|
|
173
|
+
return (0, publish_1.uploadToMarketplace)({ ...options, accessToken: refreshedSession.access_token });
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
async function handlePublish(args) {
|
|
177
|
+
const flags = parsePublishFlags(args);
|
|
178
|
+
if (flags.help) {
|
|
179
|
+
printHelp();
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
const dir = resolveWorkspaceDir(flags);
|
|
183
|
+
process.stderr.write(`[publish] scanning ${dir}...\n`);
|
|
184
|
+
let plan;
|
|
185
|
+
try {
|
|
186
|
+
plan = await (0, publish_1.planPublish)(dir, { version: flags.version });
|
|
187
|
+
}
|
|
188
|
+
catch (err) {
|
|
189
|
+
failWithError(err, flags.json);
|
|
190
|
+
}
|
|
191
|
+
if (plan.secretFindings.length > 0) {
|
|
192
|
+
if (flags.json) {
|
|
193
|
+
printJson({ success: false, error: 'secret findings detected', findings: plan.secretFindings });
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
console.error('ā secret findings detected ā publish aborted');
|
|
197
|
+
for (const f of plan.secretFindings) {
|
|
198
|
+
console.error(` ${f.path}:${f.line} (${f.rule})`);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
process.exit(1);
|
|
202
|
+
}
|
|
203
|
+
if (flags.dryRun) {
|
|
204
|
+
if (flags.json) {
|
|
205
|
+
printJson({
|
|
206
|
+
success: true,
|
|
207
|
+
dryRun: true,
|
|
208
|
+
workspace: dir,
|
|
209
|
+
manifest: plan.manifest,
|
|
210
|
+
included: plan.included,
|
|
211
|
+
excluded: plan.excluded,
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
console.log('ā dry-run ā no archive written');
|
|
216
|
+
console.log(` workspace: ${dir}`);
|
|
217
|
+
console.log(` name: ${plan.manifest.name} version: ${plan.manifest.version}`);
|
|
218
|
+
console.log(` included: ${plan.included.length} files`);
|
|
219
|
+
console.log(` excluded: ${plan.excluded.length} entries`);
|
|
220
|
+
for (const e of plan.excluded) {
|
|
221
|
+
console.log(` ${e.path} (${e.rule})`);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
// Resolved before packing (not after) so a doomed --upload run (no
|
|
227
|
+
// marketplace url / no session) never writes a stray .tgz to the
|
|
228
|
+
// workspace ā WI-SHR-20260806-013 AC-U5.
|
|
229
|
+
let marketplaceUrl = '';
|
|
230
|
+
let accessToken = '';
|
|
231
|
+
let sessionManager;
|
|
232
|
+
if (flags.upload) {
|
|
233
|
+
try {
|
|
234
|
+
marketplaceUrl = requireMarketplaceUrl();
|
|
235
|
+
sessionManager = new account_1.SessionManager({ authClient: new account_1.AuthClient() });
|
|
236
|
+
accessToken = await sessionManager.getAccessToken();
|
|
237
|
+
}
|
|
238
|
+
catch (err) {
|
|
239
|
+
if (err instanceof Error && !err.message.startsWith('publish: [')) {
|
|
240
|
+
failWithError(new Error(`publish: [E_AUTH_EXPIRED] Authentication is missing or expired ā please log in again ā ${err.message}`), flags.json);
|
|
241
|
+
}
|
|
242
|
+
failWithError(err, flags.json);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
process.stderr.write(`[publish] packing ${plan.manifest.name}@${plan.manifest.version}...\n`);
|
|
246
|
+
let packed;
|
|
247
|
+
try {
|
|
248
|
+
packed = await (0, publish_1.packTemplate)(dir, { version: flags.version });
|
|
249
|
+
}
|
|
250
|
+
catch (err) {
|
|
251
|
+
failWithError(err, flags.json);
|
|
252
|
+
}
|
|
253
|
+
const fileCount = packed.manifest.files.length;
|
|
254
|
+
const totalBytes = fs.statSync(packed.tgzPath).size;
|
|
255
|
+
let uploadResult;
|
|
256
|
+
if (flags.upload) {
|
|
257
|
+
process.stderr.write(`[publish] uploading ${packed.manifest.name}@${packed.manifest.version} to ${marketplaceUrl}...\n`);
|
|
258
|
+
try {
|
|
259
|
+
if (!sessionManager)
|
|
260
|
+
throw new Error('publish: [E_AUTH_EXPIRED] Account session is unavailable');
|
|
261
|
+
uploadResult = await uploadWithSessionRefresh(sessionManager, {
|
|
262
|
+
tgzPath: packed.tgzPath,
|
|
263
|
+
manifest: packed.manifest,
|
|
264
|
+
baseUrl: marketplaceUrl,
|
|
265
|
+
}, accessToken);
|
|
266
|
+
}
|
|
267
|
+
catch (err) {
|
|
268
|
+
failWithError(err, flags.json);
|
|
269
|
+
}
|
|
270
|
+
process.stderr.write(`[publish] submit -> ${uploadResult.submitOutcome}\n`);
|
|
271
|
+
}
|
|
272
|
+
if (flags.json) {
|
|
273
|
+
printJson({
|
|
274
|
+
success: true,
|
|
275
|
+
tgzPath: packed.tgzPath,
|
|
276
|
+
fileCount,
|
|
277
|
+
totalBytes,
|
|
278
|
+
manifest: packed.manifest,
|
|
279
|
+
...(uploadResult
|
|
280
|
+
? {
|
|
281
|
+
slug: uploadResult.slug,
|
|
282
|
+
version: uploadResult.version,
|
|
283
|
+
artifactChecksum: uploadResult.artifactChecksum,
|
|
284
|
+
artifactSizeBytes: uploadResult.artifactSizeBytes,
|
|
285
|
+
submitOutcome: uploadResult.submitOutcome,
|
|
286
|
+
versionUpdate: uploadResult.versionUpdate,
|
|
287
|
+
serverVersionBefore: uploadResult.serverVersionBefore,
|
|
288
|
+
}
|
|
289
|
+
: {}),
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
console.log(`ā packed: ${packed.tgzPath}`);
|
|
294
|
+
console.log(` files: ${fileCount} bytes: ${totalBytes}`);
|
|
295
|
+
if (uploadResult) {
|
|
296
|
+
console.log(`ā uploaded: ${uploadResult.slug}@${uploadResult.version} (${uploadResult.submitOutcome})`);
|
|
297
|
+
console.log(` artifactChecksum: ${uploadResult.artifactChecksum} artifactSizeBytes: ${uploadResult.artifactSizeBytes}`);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
if (!flags.upload) {
|
|
301
|
+
console.error('ā To upload, use --upload ā check the generated file path');
|
|
302
|
+
}
|
|
303
|
+
}
|
package/dist/commands/query.d.ts
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* Flags:
|
|
6
6
|
* --thread <name> Conversation thread name
|
|
7
7
|
* --provider <cli/xxx> Provider override
|
|
8
|
+
* --model <name> Model override (e.g. claude-sonnet-5)
|
|
8
9
|
* --metadata <json> Extra metadata JSON (double-quoted object). Propagated to events/hooks/tracing.
|
|
9
10
|
* e.g. --metadata='{"workflow_id":"wf-1"}'
|
|
10
11
|
* --verbose Debug output mode (default: raw agent response only)
|
|
@@ -12,16 +13,19 @@
|
|
|
12
13
|
* --output-format <fmt> Output format (json|text|stream-json)
|
|
13
14
|
* --effort <level> Model effort (high|medium|low)
|
|
14
15
|
* -f/--prompt-file <path> Read prompt body from file (bypasses cmd.exe argv truncation)
|
|
16
|
+
* --detach/--async Persist a receipt and launch a detached runner
|
|
17
|
+
* --wait Force synchronous execution
|
|
15
18
|
*
|
|
16
19
|
* Stdin support:
|
|
17
20
|
* Pipe or redirect content into crewx q to supply the prompt body via stdin.
|
|
18
21
|
* e.g. cat brief.md | crewx q "@agent label"
|
|
19
22
|
* Stdin is ignored when running in an interactive TTY.
|
|
20
23
|
*/
|
|
24
|
+
import { type DelegationEmitState } from './emit-trailer';
|
|
21
25
|
/**
|
|
22
26
|
* Handle `crewx query <agentRef> <message>` command.
|
|
23
27
|
*
|
|
24
28
|
* Default output: raw agent response only (stdout).
|
|
25
29
|
* --verbose: debug info written to stderr, response to stdout.
|
|
26
30
|
*/
|
|
27
|
-
export declare function handleQuery(args: string[]): Promise<void>;
|
|
31
|
+
export declare function handleQuery(args: string[], command?: string, emitState?: DelegationEmitState): Promise<void>;
|
package/dist/commands/query.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* Flags:
|
|
7
7
|
* --thread <name> Conversation thread name
|
|
8
8
|
* --provider <cli/xxx> Provider override
|
|
9
|
+
* --model <name> Model override (e.g. claude-sonnet-5)
|
|
9
10
|
* --metadata <json> Extra metadata JSON (double-quoted object). Propagated to events/hooks/tracing.
|
|
10
11
|
* e.g. --metadata='{"workflow_id":"wf-1"}'
|
|
11
12
|
* --verbose Debug output mode (default: raw agent response only)
|
|
@@ -13,6 +14,8 @@
|
|
|
13
14
|
* --output-format <fmt> Output format (json|text|stream-json)
|
|
14
15
|
* --effort <level> Model effort (high|medium|low)
|
|
15
16
|
* -f/--prompt-file <path> Read prompt body from file (bypasses cmd.exe argv truncation)
|
|
17
|
+
* --detach/--async Persist a receipt and launch a detached runner
|
|
18
|
+
* --wait Force synchronous execution
|
|
16
19
|
*
|
|
17
20
|
* Stdin support:
|
|
18
21
|
* Pipe or redirect content into crewx q to supply the prompt body via stdin.
|
|
@@ -22,24 +25,63 @@
|
|
|
22
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
26
|
exports.handleQuery = handleQuery;
|
|
24
27
|
const sdk_1 = require("@crewx/sdk");
|
|
28
|
+
const repository_1 = require("@crewx/sdk/repository");
|
|
25
29
|
const parse_agent_message_1 = require("./parse-agent-message");
|
|
26
30
|
const parse_common_flags_1 = require("./parse-common-flags");
|
|
27
31
|
const resolve_prompt_1 = require("./resolve-prompt");
|
|
28
32
|
const crewx_cli_1 = require("../bootstrap/crewx-cli");
|
|
29
33
|
const inherited_trace_1 = require("../utils/inherited-trace");
|
|
34
|
+
const write_output_1 = require("./write-output");
|
|
35
|
+
const detached_1 = require("./detached");
|
|
36
|
+
const emit_trailer_1 = require("./emit-trailer");
|
|
30
37
|
/**
|
|
31
38
|
* Handle `crewx query <agentRef> <message>` command.
|
|
32
39
|
*
|
|
33
40
|
* Default output: raw agent response only (stdout).
|
|
34
41
|
* --verbose: debug info written to stderr, response to stdout.
|
|
35
42
|
*/
|
|
36
|
-
async function handleQuery(args) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
43
|
+
async function handleQuery(args, command = 'query', emitState = (0, emit_trailer_1.createDelegationEmitState)()) {
|
|
44
|
+
// The private middle-hop marker is consumed before public flag parsing. An
|
|
45
|
+
// invalid direct use remains an unknown option and is rejected normally.
|
|
46
|
+
const middleHop = (0, detached_1.readDetachedMiddleHop)(args);
|
|
47
|
+
if (middleHop) {
|
|
48
|
+
await (0, detached_1.runDetachedMiddle)(command, middleHop);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const receiptFlags = (0, detached_1.extractReceiptFlags)(args);
|
|
52
|
+
const receiptMode = (0, detached_1.resolveReceiptMode)({
|
|
53
|
+
detach: receiptFlags.detach,
|
|
54
|
+
wait: receiptFlags.wait,
|
|
55
|
+
detachedRunner: (0, inherited_trace_1.isDetachedRunner)(),
|
|
56
|
+
agentContext: Boolean(process.env['CREWX_AGENT_ID']),
|
|
57
|
+
});
|
|
58
|
+
if (receiptMode.receipt) {
|
|
59
|
+
await (0, detached_1.runDetached)(command, receiptFlags.rest, receiptMode.reason);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
let parsedFlags;
|
|
63
|
+
try {
|
|
64
|
+
parsedFlags = (0, parse_common_flags_1.parseCommonFlags)(receiptFlags.rest);
|
|
65
|
+
}
|
|
66
|
+
catch (err) {
|
|
67
|
+
(0, emit_trailer_1.emitDelegationResult)({ command, isError: true, state: emitState });
|
|
68
|
+
throw err;
|
|
69
|
+
}
|
|
70
|
+
const { thread, provider, model, metadata, verbose, config, outputFormat, effort, promptFile, overdrive, vars, out, rest } = parsedFlags;
|
|
71
|
+
const inheritedTrace = (0, inherited_trace_1.readInheritedTrace)();
|
|
72
|
+
let parsedAgentRef;
|
|
73
|
+
let message;
|
|
74
|
+
let finalMessage;
|
|
75
|
+
try {
|
|
76
|
+
({ agentRef: parsedAgentRef, message } = (0, parse_agent_message_1.parseAgentMessage)(rest));
|
|
77
|
+
// Resolve final prompt: argv | stdin pipe | --prompt-file (or combination)
|
|
78
|
+
finalMessage = await (0, resolve_prompt_1.resolvePrompt)(message, promptFile);
|
|
79
|
+
}
|
|
80
|
+
catch (err) {
|
|
81
|
+
(0, emit_trailer_1.emitDelegationResult)({ command, trace: inheritedTrace, isError: true, state: emitState });
|
|
82
|
+
throw err;
|
|
83
|
+
}
|
|
40
84
|
const agentRef = parsedAgentRef || '@crewx';
|
|
41
|
-
// Resolve final prompt: argv | stdin pipe | --prompt-file (or combination)
|
|
42
|
-
const finalMessage = await (0, resolve_prompt_1.resolvePrompt)(message, promptFile);
|
|
43
85
|
if (!finalMessage) {
|
|
44
86
|
console.error('Usage: crewx query [@agent] <message> [options]');
|
|
45
87
|
console.error(' crewx q [@agent] <message> [options]');
|
|
@@ -55,6 +97,7 @@ async function handleQuery(args) {
|
|
|
55
97
|
console.error('Options:');
|
|
56
98
|
console.error(' --thread <name> Conversation thread name');
|
|
57
99
|
console.error(' --provider <cli/xxx> Provider override');
|
|
100
|
+
console.error(' --model <name> Model override (e.g. claude-sonnet-5)');
|
|
58
101
|
console.error(' --metadata <json> Extra metadata (JSON object, double-quoted).');
|
|
59
102
|
console.error(' Propagated to events/hooks/tracing.');
|
|
60
103
|
console.error(' Invalid JSON aborts with exit code 2.');
|
|
@@ -62,24 +105,37 @@ async function handleQuery(args) {
|
|
|
62
105
|
console.error(' --verbose Debug output mode');
|
|
63
106
|
console.error(' --config/-c <path> Config file path');
|
|
64
107
|
console.error(' --output-format <fmt> Output format (json|text|stream-json)');
|
|
108
|
+
console.error(' --out/-o <path> Save result to file (stdout suppressed)');
|
|
65
109
|
console.error(' --effort <level> Model effort (high|medium|low)');
|
|
66
110
|
console.error(' -f/--prompt-file <path> Read prompt body from file');
|
|
67
111
|
console.error(' --var key=value Template variable (repeatable)');
|
|
68
112
|
console.error(' --overdrive Activate overdrive (boost) profile for this request');
|
|
113
|
+
(0, emit_trailer_1.emitDelegationResult)({ command, trace: inheritedTrace, isError: true, state: emitState });
|
|
69
114
|
process.exit(1);
|
|
115
|
+
return;
|
|
70
116
|
}
|
|
71
117
|
const configPath = config ?? process.env.CREWX_CONFIG ?? 'crewx.yaml';
|
|
72
118
|
// Only show exec audit span JSON in verbose mode
|
|
73
119
|
(0, sdk_1.setAuditVerbose)(verbose);
|
|
74
|
-
|
|
120
|
+
let crewx;
|
|
121
|
+
try {
|
|
122
|
+
crewx = await (0, crewx_cli_1.createCliCrewx)(configPath);
|
|
123
|
+
}
|
|
124
|
+
catch (err) {
|
|
125
|
+
(0, emit_trailer_1.emitDelegationResult)({ command, trace: inheritedTrace, isError: true, state: emitState });
|
|
126
|
+
throw err;
|
|
127
|
+
}
|
|
75
128
|
// file:// remote agent delegation is handled transparently inside Crewx.query/execute.
|
|
76
129
|
if (verbose) {
|
|
130
|
+
process.stderr.write(`mode=sync reason=${receiptMode.reason}\n`);
|
|
77
131
|
process.stderr.write(`š Task: ${finalMessage}\n`);
|
|
78
132
|
process.stderr.write(`š¤ Agent: ${agentRef}\n`);
|
|
79
133
|
if (thread)
|
|
80
134
|
process.stderr.write(`š Thread: ${thread}\n`);
|
|
81
135
|
if (provider)
|
|
82
136
|
process.stderr.write(`š Provider: ${provider}\n`);
|
|
137
|
+
if (model)
|
|
138
|
+
process.stderr.write(`š§ Model: ${model}\n`);
|
|
83
139
|
if (outputFormat)
|
|
84
140
|
process.stderr.write(`š Output-format: ${outputFormat}\n`);
|
|
85
141
|
if (effort)
|
|
@@ -95,48 +151,120 @@ async function handleQuery(args) {
|
|
|
95
151
|
catch (err) {
|
|
96
152
|
const msg = err instanceof Error ? err.message : String(err);
|
|
97
153
|
process.stderr.write(`Error: ${msg}\n`);
|
|
154
|
+
(0, emit_trailer_1.emitDelegationResult)({ command, trace: inheritedTrace, isError: true, state: emitState });
|
|
98
155
|
process.exit(2);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
const actor = (0, detached_1.resolveCliTaskActor)(parsedMetadata);
|
|
159
|
+
// Only the detached runner may adopt a pre-issued task row. Trace variables
|
|
160
|
+
// describe the caller chain and are never used as this task's identity.
|
|
161
|
+
const detachedRunner = (0, inherited_trace_1.isDetachedRunner)();
|
|
162
|
+
const assignedTaskId = (0, inherited_trace_1.readRunnerAssignment)();
|
|
163
|
+
let selfTaskId;
|
|
164
|
+
let taskActor;
|
|
165
|
+
if (assignedTaskId !== undefined) {
|
|
166
|
+
const taskRepo = new repository_1.TaskRepository();
|
|
167
|
+
const adoption = (0, detached_1.adoptAssignedTask)(taskRepo, assignedTaskId, detachedRunner);
|
|
168
|
+
if (adoption.kind === 'failed') {
|
|
169
|
+
(0, emit_trailer_1.emitDelegationResult)({ command, trace: inheritedTrace, isError: true, state: emitState });
|
|
170
|
+
process.exit(1);
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
if (adoption.kind === 'adopted') {
|
|
174
|
+
selfTaskId = adoption.taskId;
|
|
175
|
+
taskActor = (0, detached_1.readAssignedTaskActor)(taskRepo, adoption.taskId);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
// A synchronous `crewx q` runs in this same process, but this process is
|
|
179
|
+
// still separate from the embedded server and never sees its in-memory
|
|
180
|
+
// UpdateGateService (WI-CTO-20260919-004 R2 finding #1) ā only the durable
|
|
181
|
+
// marker it writes. Reserve-then-check before calling into the SDK below,
|
|
182
|
+
// not after; see admitDurableTask()'s own doc comment. Never checked for
|
|
183
|
+
// an adopted receipt (selfTaskId set): that work was already admitted by
|
|
184
|
+
// whichever process first created its pending DB row.
|
|
185
|
+
let admission;
|
|
186
|
+
if (selfTaskId === undefined) {
|
|
187
|
+
admission = (0, sdk_1.admitDurableTask)(`direct-cli:${command}`);
|
|
188
|
+
if (!admission.ok) {
|
|
189
|
+
(0, detached_1.reportAdmissionBlocked)(admission);
|
|
190
|
+
(0, emit_trailer_1.emitDelegationResult)({ command, trace: inheritedTrace, isError: true, state: emitState });
|
|
191
|
+
process.exit(1);
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
99
194
|
}
|
|
100
195
|
let exitCode = 0;
|
|
196
|
+
let result;
|
|
101
197
|
try {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
198
|
+
try {
|
|
199
|
+
result = await crewx.query(agentRef, finalMessage, {
|
|
200
|
+
provider,
|
|
201
|
+
model,
|
|
202
|
+
effort: effort || undefined,
|
|
203
|
+
overdrive: overdrive || undefined,
|
|
204
|
+
threadId: thread,
|
|
205
|
+
taskId: selfTaskId,
|
|
206
|
+
actor: assignedTaskId === undefined ? actor : taskActor,
|
|
207
|
+
metadata: Object.keys(parsedMetadata).length > 0 ? parsedMetadata : undefined,
|
|
208
|
+
vars: Object.keys(vars).length > 0 ? vars : undefined,
|
|
209
|
+
trace: inheritedTrace,
|
|
210
|
+
});
|
|
211
|
+
if (!result.ok) {
|
|
212
|
+
const errMsg = result.error?.message ?? 'Query failed';
|
|
213
|
+
console.error(errMsg);
|
|
214
|
+
(0, write_output_1.appendError)(out, errMsg);
|
|
215
|
+
exitCode = 1;
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
if (verbose) {
|
|
219
|
+
process.stderr.write(`\nš Results from ${agentRef}:\n`);
|
|
220
|
+
process.stderr.write('ā'.repeat(60) + '\n');
|
|
221
|
+
process.stderr.write('š¢ Status: Success\n');
|
|
222
|
+
process.stderr.write(`š¤ Provider: ${result.meta.provider}\n`);
|
|
223
|
+
process.stderr.write(`ā±ļø Duration: ${result.meta.durationMs}ms\n`);
|
|
224
|
+
process.stderr.write('\nš Response:\n');
|
|
225
|
+
process.stderr.write('ā'.repeat(40) + '\n');
|
|
226
|
+
}
|
|
227
|
+
(0, write_output_1.writeResult)(out, result.data);
|
|
228
|
+
if (verbose) {
|
|
229
|
+
process.stderr.write('\nā
Query completed successfully\n');
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
catch (err) {
|
|
234
|
+
const errMsg = err instanceof Error ? err.message : String(err);
|
|
235
|
+
console.error(`Error: ${errMsg}`);
|
|
236
|
+
(0, write_output_1.appendError)(out, `Error: ${errMsg}`);
|
|
114
237
|
exitCode = 1;
|
|
115
238
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
process.stderr.write('ā'.repeat(60) + '\n');
|
|
120
|
-
process.stderr.write('š¢ Status: Success\n');
|
|
121
|
-
process.stderr.write(`š¤ Provider: ${result.meta.provider}\n`);
|
|
122
|
-
process.stderr.write(`ā±ļø Duration: ${result.meta.durationMs}ms\n`);
|
|
123
|
-
process.stderr.write('\nš Response:\n');
|
|
124
|
-
process.stderr.write('ā'.repeat(40) + '\n');
|
|
239
|
+
finally {
|
|
240
|
+
try {
|
|
241
|
+
await crewx.close();
|
|
125
242
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
243
|
+
catch (err) {
|
|
244
|
+
(0, emit_trailer_1.emitDelegationResult)({
|
|
245
|
+
command,
|
|
246
|
+
trace: inheritedTrace,
|
|
247
|
+
taskId: result?.meta.taskId,
|
|
248
|
+
agentId: result?.meta.agentId,
|
|
249
|
+
isError: true,
|
|
250
|
+
state: emitState,
|
|
251
|
+
});
|
|
252
|
+
throw err;
|
|
129
253
|
}
|
|
130
254
|
}
|
|
131
255
|
}
|
|
132
|
-
catch (err) {
|
|
133
|
-
const errMsg = err instanceof Error ? err.message : String(err);
|
|
134
|
-
console.error(`Error: ${errMsg}`);
|
|
135
|
-
exitCode = 1;
|
|
136
|
-
}
|
|
137
256
|
finally {
|
|
138
|
-
|
|
257
|
+
if (admission?.ok)
|
|
258
|
+
admission.release();
|
|
139
259
|
}
|
|
260
|
+
(0, emit_trailer_1.emitDelegationResult)({
|
|
261
|
+
command,
|
|
262
|
+
trace: inheritedTrace,
|
|
263
|
+
taskId: result?.meta.taskId,
|
|
264
|
+
agentId: result?.meta.agentId,
|
|
265
|
+
isError: exitCode !== 0 || result?.ok === false,
|
|
266
|
+
state: emitState,
|
|
267
|
+
});
|
|
140
268
|
if (exitCode !== 0)
|
|
141
269
|
process.exit(exitCode);
|
|
142
270
|
}
|
|
@@ -13,17 +13,19 @@ exports.KNOWN_COMMANDS = new Set([
|
|
|
13
13
|
'q', 'query',
|
|
14
14
|
'x', 'execute',
|
|
15
15
|
'agent',
|
|
16
|
-
'ps', 'kill', 'result', 'log', 'restart',
|
|
16
|
+
'ps', 'stop', 'kill', 'result', 'log', 'restart',
|
|
17
17
|
'doctor', 'init',
|
|
18
18
|
'db',
|
|
19
19
|
'help',
|
|
20
|
+
'shortcut',
|
|
21
|
+
'publish',
|
|
20
22
|
'slack', 'slack:files',
|
|
21
23
|
'hook', 'hook-dispatch',
|
|
22
24
|
]);
|
|
23
25
|
/** Built-in tool commands routed via handleBuiltin(). */
|
|
24
26
|
exports.BUILTIN_COMMAND_NAMES = new Set([
|
|
25
27
|
'memory', 'search', 'doc', 'wbs', 'cron', 'workflow', 'skill', 'dreaming',
|
|
26
|
-
'wi', 'chromex',
|
|
28
|
+
'wi', 'chromex', 'notify', 'app',
|
|
27
29
|
]);
|
|
28
30
|
/** Commands not yet migrated from cli-bak ā show a migration message. */
|
|
29
31
|
exports.NOT_YET_MIGRATED = new Set([
|
|
@@ -3,8 +3,13 @@
|
|
|
3
3
|
* Retrieves the result of a completed task by its ID.
|
|
4
4
|
*
|
|
5
5
|
* Usage:
|
|
6
|
-
* crewx result <task-id>
|
|
7
|
-
* crewx result <task-id> --json
|
|
8
|
-
* crewx result
|
|
6
|
+
* crewx result <task-id> Print raw result
|
|
7
|
+
* crewx result <task-id> --json Print full task record as JSON
|
|
8
|
+
* crewx result <task-id> --wait=<seconds> Poll (1s interval) up to the given
|
|
9
|
+
* number of seconds for
|
|
10
|
+
* the task to leave 'pending'/'running'. Exit 124 on
|
|
11
|
+
* timeout. --wait=0 behaves like no --wait
|
|
12
|
+
* (single immediate check).
|
|
13
|
+
* crewx result List recent tasks (latest 10)
|
|
9
14
|
*/
|
|
10
15
|
export declare function handleResult(args: string[]): Promise<void>;
|