@crewx/cli 0.9.0-rc.107 → 0.9.0-rc.109
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.
|
@@ -44,9 +44,8 @@ async function createCliCrewx(configPath = process.env.CREWX_CONFIG ?? 'crewx.ya
|
|
|
44
44
|
}
|
|
45
45
|
const skipRoot = yamlPath !== undefined ? (0, path_1.dirname)(absConfigPath) : undefined;
|
|
46
46
|
// Run drizzle migrations once at bootstrap — plugin relies on this guarantee.
|
|
47
|
-
const
|
|
48
|
-
(0, fs_1.mkdirSync)(
|
|
49
|
-
const dbPath = (0, path_1.join)(dbDir, 'crewx.db');
|
|
47
|
+
const dbPath = process.env.CREWX_DB || (0, path_1.join)((0, os_1.homedir)(), '.crewx', 'crewx.db');
|
|
48
|
+
(0, fs_1.mkdirSync)((0, path_1.dirname)(dbPath), { recursive: true });
|
|
50
49
|
const handle = (0, repository_1.openDrizzleDb)(dbPath);
|
|
51
50
|
try {
|
|
52
51
|
(0, repository_1.runMigrations)(handle.db);
|
|
@@ -62,7 +61,7 @@ async function createCliCrewx(configPath = process.env.CREWX_CONFIG ?? 'crewx.ya
|
|
|
62
61
|
(0, register_builtin_tools_1.registerBuiltinToolsIfNeeded)(crewx);
|
|
63
62
|
crewx.registerPromptListProvider(sdk_1.Crewx.createAgentListPromptResolver(yamlPath));
|
|
64
63
|
crewx.registerPromptListProvider((0, list_1.createWorkflowListPromptResolver)(yamlPath));
|
|
65
|
-
await crewx.use(new plugins_1.ConversationPlugin());
|
|
64
|
+
await crewx.use(new plugins_1.ConversationPlugin({ dbPath }));
|
|
66
65
|
await crewx.use(new plugins_1.FileLoggerPlugin({ version: version_1.CLI_VERSION, workspaceRoot }));
|
|
67
66
|
await crewx.use(new plugins_1.SqliteTracingPlugin({
|
|
68
67
|
version: version_1.CLI_VERSION,
|
|
@@ -6,6 +6,20 @@
|
|
|
6
6
|
* trace context and are never repurposed as the runner assignment.
|
|
7
7
|
*/
|
|
8
8
|
import { TaskRepository } from '@crewx/sdk/repository';
|
|
9
|
+
import type { TaskActor } from '@crewx/sdk';
|
|
10
|
+
export type ReceiptActorKind = 'human' | 'agent' | 'system' | 'unknown';
|
|
11
|
+
export interface ReceiptActor {
|
|
12
|
+
kind: ReceiptActorKind;
|
|
13
|
+
id: string | null;
|
|
14
|
+
}
|
|
15
|
+
/** Resolve the CLI actor from metadata and the caller's current environment. */
|
|
16
|
+
export declare function resolveCliTaskActor(metadata: Record<string, unknown>, agentId?: string | undefined): TaskActor;
|
|
17
|
+
/**
|
|
18
|
+
* Resolve the actor at the receipt boundary while the caller's environment is
|
|
19
|
+
* still available. The receipt and synchronous paths share one predicate so
|
|
20
|
+
* cron runners cannot diverge after root context is stripped.
|
|
21
|
+
*/
|
|
22
|
+
export declare function resolveReceiptActor(metadata: Record<string, unknown>, agentId?: string | undefined): ReceiptActor;
|
|
9
23
|
/**
|
|
10
24
|
* Remove receipt-selection flags, respecting the `--` literal-args sentinel.
|
|
11
25
|
*/
|
|
@@ -41,6 +55,8 @@ export type AssignedTaskAdoption = {
|
|
|
41
55
|
* because its receipt would otherwise point at no execution row.
|
|
42
56
|
*/
|
|
43
57
|
export declare function adoptAssignedTask(taskRepo: Pick<TaskRepository, 'adoptPendingTask'>, taskId: string, detachedRunner: boolean): AssignedTaskAdoption;
|
|
58
|
+
/** Read the actor persisted on the receipt after the runner adopts it. */
|
|
59
|
+
export declare function readAssignedTaskActor(taskRepo: Pick<TaskRepository, 'getTask'>, taskId: string): TaskActor | undefined;
|
|
44
60
|
export interface DetachedMiddleHop {
|
|
45
61
|
taskId: string;
|
|
46
62
|
logPath: string;
|
|
@@ -7,9 +7,12 @@
|
|
|
7
7
|
* trace context and are never repurposed as the runner assignment.
|
|
8
8
|
*/
|
|
9
9
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.resolveCliTaskActor = resolveCliTaskActor;
|
|
11
|
+
exports.resolveReceiptActor = resolveReceiptActor;
|
|
10
12
|
exports.extractReceiptFlags = extractReceiptFlags;
|
|
11
13
|
exports.resolveReceiptMode = resolveReceiptMode;
|
|
12
14
|
exports.adoptAssignedTask = adoptAssignedTask;
|
|
15
|
+
exports.readAssignedTaskActor = readAssignedTaskActor;
|
|
13
16
|
exports.readDetachedMiddleHop = readDetachedMiddleHop;
|
|
14
17
|
exports.runDetachedMiddle = runDetachedMiddle;
|
|
15
18
|
exports.runDetached = runDetached;
|
|
@@ -25,6 +28,28 @@ const resolve_prompt_1 = require("./resolve-prompt");
|
|
|
25
28
|
const version_1 = require("../utils/version");
|
|
26
29
|
const inherited_trace_1 = require("../utils/inherited-trace");
|
|
27
30
|
const cal_1 = require("./cal");
|
|
31
|
+
function nonEmptyString(value) {
|
|
32
|
+
return typeof value === 'string' && value.trim().length > 0 ? value.trim() : undefined;
|
|
33
|
+
}
|
|
34
|
+
/** Resolve the CLI actor from metadata and the caller's current environment. */
|
|
35
|
+
function resolveCliTaskActor(metadata, agentId = process.env['CREWX_AGENT_ID']) {
|
|
36
|
+
const scheduleId = nonEmptyString(metadata.schedule_id);
|
|
37
|
+
if (scheduleId)
|
|
38
|
+
return { actorKind: 'system', actorId: `cron:${scheduleId}` };
|
|
39
|
+
const normalizedAgentId = nonEmptyString(agentId);
|
|
40
|
+
if (normalizedAgentId)
|
|
41
|
+
return { actorKind: 'agent', actorId: normalizedAgentId };
|
|
42
|
+
return { actorKind: 'human', actorId: null };
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Resolve the actor at the receipt boundary while the caller's environment is
|
|
46
|
+
* still available. The receipt and synchronous paths share one predicate so
|
|
47
|
+
* cron runners cannot diverge after root context is stripped.
|
|
48
|
+
*/
|
|
49
|
+
function resolveReceiptActor(metadata, agentId = process.env['CREWX_AGENT_ID']) {
|
|
50
|
+
const actor = resolveCliTaskActor(metadata, agentId);
|
|
51
|
+
return { kind: actor.actorKind, id: actor.actorId };
|
|
52
|
+
}
|
|
28
53
|
const DETACHED_RUNNER_POLL_INTERVAL_MS = 200;
|
|
29
54
|
const DETACHED_RUNNER_ADOPTION_TIMEOUT_MS = 30_000;
|
|
30
55
|
const DETACHED_VALUE_FLAGS = [
|
|
@@ -281,6 +306,17 @@ function adoptAssignedTask(taskRepo, taskId, detachedRunner) {
|
|
|
281
306
|
process.stderr.write(`${reason}\n`);
|
|
282
307
|
return { kind: 'stale' };
|
|
283
308
|
}
|
|
309
|
+
/** Read the actor persisted on the receipt after the runner adopts it. */
|
|
310
|
+
function readAssignedTaskActor(taskRepo, taskId) {
|
|
311
|
+
const task = taskRepo.getTask(taskId);
|
|
312
|
+
const actorKind = task?.actor_kind;
|
|
313
|
+
if (actorKind === null || actorKind === undefined)
|
|
314
|
+
return undefined;
|
|
315
|
+
if (actorKind === 'human' || actorKind === 'agent' || actorKind === 'system' || actorKind === 'unknown') {
|
|
316
|
+
return { actorKind, actorId: task?.actor_id ?? null };
|
|
317
|
+
}
|
|
318
|
+
return { actorKind: 'unknown', actorId: task?.actor_id ?? null };
|
|
319
|
+
}
|
|
284
320
|
function buildMiddleEnvironment(token) {
|
|
285
321
|
const env = { ...process.env };
|
|
286
322
|
env[INTERNAL_TOKEN_ENV] = token;
|
|
@@ -393,10 +429,13 @@ async function runDetached(command, filteredArgs, reason) {
|
|
|
393
429
|
const inheritedTrace = (0, inherited_trace_1.readInheritedTrace)();
|
|
394
430
|
const taskTrace = inheritedTrace?.rootTraceId || taskId;
|
|
395
431
|
const taskRepo = new repository_1.TaskRepository();
|
|
432
|
+
const actor = resolveReceiptActor(parsedMetadata);
|
|
396
433
|
try {
|
|
397
434
|
taskRepo.startTask({
|
|
398
435
|
id: taskId,
|
|
399
436
|
agentId: agentRef.replace(/^@/, ''),
|
|
437
|
+
actorKind: actor.kind,
|
|
438
|
+
actorId: actor.id,
|
|
400
439
|
prompt: finalMessage,
|
|
401
440
|
mode: command === 'q' || command === 'query' ? 'query' : 'execute',
|
|
402
441
|
status: 'pending',
|
package/dist/commands/execute.js
CHANGED
|
@@ -158,20 +158,25 @@ async function handleExecute(args, command = 'execute', emitState = (0, emit_tra
|
|
|
158
158
|
process.exit(2);
|
|
159
159
|
return;
|
|
160
160
|
}
|
|
161
|
+
const actor = (0, detached_1.resolveCliTaskActor)(parsedMetadata);
|
|
161
162
|
// Only the detached runner may adopt a pre-issued task row. Trace variables
|
|
162
163
|
// describe the caller chain and are never used as this task's identity.
|
|
163
164
|
const detachedRunner = (0, inherited_trace_1.isDetachedRunner)();
|
|
164
165
|
const assignedTaskId = (0, inherited_trace_1.readRunnerAssignment)();
|
|
165
166
|
let selfTaskId;
|
|
167
|
+
let taskActor;
|
|
166
168
|
if (assignedTaskId !== undefined) {
|
|
167
|
-
const
|
|
169
|
+
const taskRepo = new repository_1.TaskRepository();
|
|
170
|
+
const adoption = (0, detached_1.adoptAssignedTask)(taskRepo, assignedTaskId, detachedRunner);
|
|
168
171
|
if (adoption.kind === 'failed') {
|
|
169
172
|
(0, emit_trailer_1.emitDelegationResult)({ command, trace: inheritedTrace, isError: true, state: emitState });
|
|
170
173
|
process.exit(1);
|
|
171
174
|
return;
|
|
172
175
|
}
|
|
173
|
-
if (adoption.kind === 'adopted')
|
|
176
|
+
if (adoption.kind === 'adopted') {
|
|
174
177
|
selfTaskId = adoption.taskId;
|
|
178
|
+
taskActor = (0, detached_1.readAssignedTaskActor)(taskRepo, adoption.taskId);
|
|
179
|
+
}
|
|
175
180
|
}
|
|
176
181
|
let exitCode = 0;
|
|
177
182
|
let result;
|
|
@@ -183,6 +188,7 @@ async function handleExecute(args, command = 'execute', emitState = (0, emit_tra
|
|
|
183
188
|
overdrive: overdrive || undefined,
|
|
184
189
|
threadId: thread,
|
|
185
190
|
taskId: selfTaskId,
|
|
191
|
+
actor: assignedTaskId === undefined ? actor : taskActor,
|
|
186
192
|
metadata: Object.keys(parsedMetadata).length > 0 ? parsedMetadata : undefined,
|
|
187
193
|
vars: Object.keys(vars).length > 0 ? vars : undefined,
|
|
188
194
|
trace: inheritedTrace,
|
package/dist/commands/query.js
CHANGED
|
@@ -155,20 +155,25 @@ async function handleQuery(args, command = 'query', emitState = (0, emit_trailer
|
|
|
155
155
|
process.exit(2);
|
|
156
156
|
return;
|
|
157
157
|
}
|
|
158
|
+
const actor = (0, detached_1.resolveCliTaskActor)(parsedMetadata);
|
|
158
159
|
// Only the detached runner may adopt a pre-issued task row. Trace variables
|
|
159
160
|
// describe the caller chain and are never used as this task's identity.
|
|
160
161
|
const detachedRunner = (0, inherited_trace_1.isDetachedRunner)();
|
|
161
162
|
const assignedTaskId = (0, inherited_trace_1.readRunnerAssignment)();
|
|
162
163
|
let selfTaskId;
|
|
164
|
+
let taskActor;
|
|
163
165
|
if (assignedTaskId !== undefined) {
|
|
164
|
-
const
|
|
166
|
+
const taskRepo = new repository_1.TaskRepository();
|
|
167
|
+
const adoption = (0, detached_1.adoptAssignedTask)(taskRepo, assignedTaskId, detachedRunner);
|
|
165
168
|
if (adoption.kind === 'failed') {
|
|
166
169
|
(0, emit_trailer_1.emitDelegationResult)({ command, trace: inheritedTrace, isError: true, state: emitState });
|
|
167
170
|
process.exit(1);
|
|
168
171
|
return;
|
|
169
172
|
}
|
|
170
|
-
if (adoption.kind === 'adopted')
|
|
173
|
+
if (adoption.kind === 'adopted') {
|
|
171
174
|
selfTaskId = adoption.taskId;
|
|
175
|
+
taskActor = (0, detached_1.readAssignedTaskActor)(taskRepo, adoption.taskId);
|
|
176
|
+
}
|
|
172
177
|
}
|
|
173
178
|
let exitCode = 0;
|
|
174
179
|
let result;
|
|
@@ -180,6 +185,7 @@ async function handleQuery(args, command = 'query', emitState = (0, emit_trailer
|
|
|
180
185
|
overdrive: overdrive || undefined,
|
|
181
186
|
threadId: thread,
|
|
182
187
|
taskId: selfTaskId,
|
|
188
|
+
actor: assignedTaskId === undefined ? actor : taskActor,
|
|
183
189
|
metadata: Object.keys(parsedMetadata).length > 0 ? parsedMetadata : undefined,
|
|
184
190
|
vars: Object.keys(vars).length > 0 ? vars : undefined,
|
|
185
191
|
trace: inheritedTrace,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crewx/cli",
|
|
3
|
-
"version": "0.9.0-rc.
|
|
3
|
+
"version": "0.9.0-rc.109",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=20.19.0"
|
|
@@ -25,19 +25,19 @@
|
|
|
25
25
|
"better-sqlite3": "*",
|
|
26
26
|
"dotenv": "17.2.3",
|
|
27
27
|
"isomorphic-git": "1.37.1",
|
|
28
|
-
"@crewx/sdk": "0.9.0-rc.
|
|
29
|
-
"@crewx/
|
|
30
|
-
"@crewx/
|
|
31
|
-
"@crewx/doc": "0.1.9-rc.
|
|
32
|
-
"@crewx/
|
|
33
|
-
"@crewx/wbs": "0.1.10-rc.
|
|
34
|
-
"@crewx/cron": "0.1.10-rc.
|
|
35
|
-
"@crewx/workflow": "0.3.22-rc.
|
|
36
|
-
"@crewx/
|
|
37
|
-
"@crewx/
|
|
38
|
-
"@crewx/chromex": "0.1.0-rc.
|
|
39
|
-
"@crewx/
|
|
40
|
-
"@crewx/
|
|
28
|
+
"@crewx/sdk": "0.9.0-rc.109",
|
|
29
|
+
"@crewx/knowledge-core": "0.1.17-rc.119",
|
|
30
|
+
"@crewx/search": "0.1.10-rc.105",
|
|
31
|
+
"@crewx/doc": "0.1.9-rc.102",
|
|
32
|
+
"@crewx/memory": "0.1.23-rc.126",
|
|
33
|
+
"@crewx/wbs": "0.1.10-rc.135",
|
|
34
|
+
"@crewx/cron": "0.1.10-rc.144",
|
|
35
|
+
"@crewx/workflow": "0.3.22-rc.155",
|
|
36
|
+
"@crewx/skill": "0.1.20-rc.3",
|
|
37
|
+
"@crewx/notify": "0.1.0-rc.80",
|
|
38
|
+
"@crewx/chromex": "0.1.0-rc.142",
|
|
39
|
+
"@crewx/shared": "0.0.6-rc.24",
|
|
40
|
+
"@crewx/wi": "0.1.10-rc.129"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@types/better-sqlite3": "*",
|