@crewx/cli 0.9.0-rc.65 → 0.9.0-rc.66

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.
@@ -33,6 +33,19 @@ export declare function escapeTomlBasicString(value: string): string;
33
33
  * Works for both `codex exec` and `codex exec resume` (config-override form).
34
34
  */
35
35
  export declare function buildCodexWritableRootArgs(crewxHome: string): string[];
36
+ /**
37
+ * Create an `AdditionalArgsProvider` that skips Codex's git repository trust
38
+ * check for a resolved workspace.
39
+ *
40
+ * The workspace is resolved by the product layer, so an unavailable workspace
41
+ * must not fall back to the host cwd. The flag is independent of execution
42
+ * mode because it controls repository trust rather than filesystem access.
43
+ */
44
+ export declare function createCodexSkipGitRepoCheckProvider(workspaceRoot: string | undefined): AdditionalArgsProvider;
45
+ /**
46
+ * Compose product-layer argument providers while preserving their order.
47
+ */
48
+ export declare function composeAdditionalArgsProviders(...providers: AdditionalArgsProvider[]): AdditionalArgsProvider;
36
49
  /**
37
50
  * Create an `AdditionalArgsProvider` (SDK extension point, WI-20260703-001)
38
51
  * that injects CrewX home as a Codex writable root for `workspace-write`
@@ -20,6 +20,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
20
20
  exports.resolveCrewxHome = resolveCrewxHome;
21
21
  exports.escapeTomlBasicString = escapeTomlBasicString;
22
22
  exports.buildCodexWritableRootArgs = buildCodexWritableRootArgs;
23
+ exports.createCodexSkipGitRepoCheckProvider = createCodexSkipGitRepoCheckProvider;
24
+ exports.composeAdditionalArgsProviders = composeAdditionalArgsProviders;
23
25
  exports.createCodexWritableRootsProvider = createCodexWritableRootsProvider;
24
26
  const os_1 = require("os");
25
27
  const path_1 = require("path");
@@ -68,6 +70,29 @@ function buildCodexWritableRootArgs(crewxHome) {
68
70
  function isCodexProvider(ctx) {
69
71
  return ctx.providerId === 'codex' || ctx.providerStr === 'cli/codex';
70
72
  }
73
+ /**
74
+ * Create an `AdditionalArgsProvider` that skips Codex's git repository trust
75
+ * check for a resolved workspace.
76
+ *
77
+ * The workspace is resolved by the product layer, so an unavailable workspace
78
+ * must not fall back to the host cwd. The flag is independent of execution
79
+ * mode because it controls repository trust rather than filesystem access.
80
+ */
81
+ function createCodexSkipGitRepoCheckProvider(workspaceRoot) {
82
+ return (ctx) => {
83
+ if (!isCodexProvider(ctx))
84
+ return [];
85
+ if (!workspaceRoot)
86
+ return [];
87
+ return ['--skip-git-repo-check'];
88
+ };
89
+ }
90
+ /**
91
+ * Compose product-layer argument providers while preserving their order.
92
+ */
93
+ function composeAdditionalArgsProviders(...providers) {
94
+ return (ctx) => providers.flatMap((provider) => provider(ctx));
95
+ }
71
96
  /**
72
97
  * Create an `AdditionalArgsProvider` (SDK extension point, WI-20260703-001)
73
98
  * that injects CrewX home as a Codex writable root for `workspace-write`
@@ -40,6 +40,7 @@ async function createCliCrewx(configPath = process.env.CREWX_CONFIG ?? 'crewx.ya
40
40
  else {
41
41
  yamlPath = undefined;
42
42
  }
43
+ const skipRoot = yamlPath !== undefined ? (0, path_1.dirname)(absConfigPath) : undefined;
43
44
  // Run drizzle migrations once at bootstrap — plugin relies on this guarantee.
44
45
  const dbDir = (0, path_1.join)((0, os_1.homedir)(), '.crewx');
45
46
  (0, fs_1.mkdirSync)(dbDir, { recursive: true });
@@ -53,7 +54,7 @@ async function createCliCrewx(configPath = process.env.CREWX_CONFIG ?? 'crewx.ya
53
54
  }
54
55
  const crewx = await sdk_1.Crewx.loadYaml(yamlPath, {
55
56
  remoteFactory: createCliCrewx,
56
- additionalArgsProvider: (0, codex_writable_roots_1.createCodexWritableRootsProvider)(),
57
+ additionalArgsProvider: (0, codex_writable_roots_1.composeAdditionalArgsProviders)((0, codex_writable_roots_1.createCodexWritableRootsProvider)(), (0, codex_writable_roots_1.createCodexSkipGitRepoCheckProvider)(skipRoot)),
57
58
  });
58
59
  (0, register_builtin_tools_1.registerBuiltinToolsIfNeeded)(crewx);
59
60
  await crewx.use(new plugins_1.ConversationPlugin());
@@ -6,4 +6,5 @@
6
6
  * crewx db push --force Apply without confirmation + reset migration history
7
7
  * crewx db push --dry-run Show preview only, no changes
8
8
  */
9
+ export declare const TASK_LOG_MIGRATION_HELP = "Usage:\n crewx db migrate-task-logs --dry-run [--db PATH]\n crewx db migrate-task-logs --apply [--db PATH] [--batch-tasks N]\n crewx db migrate-task-logs --verify [--db PATH]\n\nModes:\n --dry-run Read and validate legacy blobs without writing or creating a backup.\n --apply Create a consistent SQLite backup, then migrate one task per transaction.\n --verify Check source invariants, event sequences, counts, and orphan rows.\n\nApply policy:\n Only blob tasks with status success, failed, or completed are migrated.\n pending, running, paused, and unknown statuses are deferred for a later run.\n There is no --force or --include-active option. Apply requires the estimated\n database/event growth plus a 10 GiB free-space reserve.\n\nExit codes:\n 0 Completed with no malformed rows or invariant failures.\n 1 Safe tasks completed but a row/invariant failed, or apply was blocked.\n 2 Invalid command-line arguments.\n\nThe command never runs automatically at server startup and never runs VACUUM.";
9
10
  export declare function handleDb(args: string[]): Promise<void>;
@@ -11,12 +11,36 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
11
11
  return (mod && mod.__esModule) ? mod : { "default": mod };
12
12
  };
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.TASK_LOG_MIGRATION_HELP = void 0;
14
15
  exports.handleDb = handleDb;
15
16
  const path_1 = __importDefault(require("path"));
16
17
  const os_1 = __importDefault(require("os"));
17
18
  const readline_1 = __importDefault(require("readline"));
18
19
  const repository_1 = require("@crewx/sdk/repository");
19
20
  const repository_2 = require("@crewx/sdk/repository");
21
+ const repository_3 = require("@crewx/sdk/repository");
22
+ exports.TASK_LOG_MIGRATION_HELP = `Usage:
23
+ crewx db migrate-task-logs --dry-run [--db PATH]
24
+ crewx db migrate-task-logs --apply [--db PATH] [--batch-tasks N]
25
+ crewx db migrate-task-logs --verify [--db PATH]
26
+
27
+ Modes:
28
+ --dry-run Read and validate legacy blobs without writing or creating a backup.
29
+ --apply Create a consistent SQLite backup, then migrate one task per transaction.
30
+ --verify Check source invariants, event sequences, counts, and orphan rows.
31
+
32
+ Apply policy:
33
+ Only blob tasks with status success, failed, or completed are migrated.
34
+ pending, running, paused, and unknown statuses are deferred for a later run.
35
+ There is no --force or --include-active option. Apply requires the estimated
36
+ database/event growth plus a 10 GiB free-space reserve.
37
+
38
+ Exit codes:
39
+ 0 Completed with no malformed rows or invariant failures.
40
+ 1 Safe tasks completed but a row/invariant failed, or apply was blocked.
41
+ 2 Invalid command-line arguments.
42
+
43
+ The command never runs automatically at server startup and never runs VACUUM.`;
20
44
  function defaultDbPath() {
21
45
  return path_1.default.join(os_1.default.homedir(), '.crewx', 'crewx.db');
22
46
  }
@@ -57,6 +81,12 @@ function formatPreview(result, dbPath) {
57
81
  function hasChanges(result) {
58
82
  return result.created.length > 0 || result.altered.length > 0;
59
83
  }
84
+ function formatStatusCounts(counts) {
85
+ const entries = Object.entries(counts ?? {});
86
+ return entries.length > 0
87
+ ? entries.map(([status, count]) => `${status}=${count}`).join(', ')
88
+ : '(none)';
89
+ }
60
90
  function prompt(question) {
61
91
  const rl = readline_1.default.createInterface({ input: process.stdin, output: process.stdout });
62
92
  return new Promise((resolve) => {
@@ -68,13 +98,173 @@ function prompt(question) {
68
98
  }
69
99
  async function handleDb(args) {
70
100
  const subcommand = args[0];
101
+ if (subcommand === 'migrate-task-logs') {
102
+ await handleTaskLogMigration(args.slice(1));
103
+ return;
104
+ }
105
+ if (subcommand === '--help' || subcommand === '-h') {
106
+ console.log('Usage: crewx db push [--force] [--dry-run]');
107
+ console.log(exports.TASK_LOG_MIGRATION_HELP);
108
+ return;
109
+ }
71
110
  if (!subcommand || subcommand === 'push') {
72
111
  await handleDbPush(args.slice(subcommand === 'push' ? 1 : 0));
73
112
  return;
74
113
  }
75
114
  console.error(`Unknown db subcommand: ${subcommand}`);
76
115
  console.error('Usage: crewx db push [--force] [--dry-run]');
77
- process.exit(1);
116
+ console.error(exports.TASK_LOG_MIGRATION_HELP);
117
+ process.exitCode = 2;
118
+ }
119
+ class TaskLogMigrationUsageError extends Error {
120
+ }
121
+ function parseTaskLogMigrationArgs(args) {
122
+ let mode;
123
+ let dbPath;
124
+ let batchTasks;
125
+ const setMode = (next) => {
126
+ if (mode)
127
+ throw new TaskLogMigrationUsageError('Choose exactly one of --dry-run, --apply, or --verify.');
128
+ mode = next;
129
+ };
130
+ const requireValue = (args, index, flag) => {
131
+ const value = args[index + 1];
132
+ if (!value || value.startsWith('--'))
133
+ throw new TaskLogMigrationUsageError(`${flag} requires a value.`);
134
+ return value;
135
+ };
136
+ for (let index = 0; index < args.length; index += 1) {
137
+ const arg = args[index];
138
+ if (arg === '--help' || arg === '-h') {
139
+ throw new TaskLogMigrationUsageError(exports.TASK_LOG_MIGRATION_HELP);
140
+ }
141
+ if (arg === '--dry-run') {
142
+ setMode('dry-run');
143
+ continue;
144
+ }
145
+ if (arg === '--apply') {
146
+ setMode('apply');
147
+ continue;
148
+ }
149
+ if (arg === '--verify') {
150
+ setMode('verify');
151
+ continue;
152
+ }
153
+ if (arg === '--db') {
154
+ dbPath = requireValue(args, index, '--db');
155
+ index += 1;
156
+ continue;
157
+ }
158
+ if (arg.startsWith('--db=')) {
159
+ dbPath = arg.slice('--db='.length);
160
+ if (!dbPath)
161
+ throw new TaskLogMigrationUsageError('--db requires a value.');
162
+ continue;
163
+ }
164
+ if (arg === '--batch-tasks') {
165
+ const value = requireValue(args, index, '--batch-tasks');
166
+ const parsed = Number(value);
167
+ if (!Number.isSafeInteger(parsed) || parsed < 1) {
168
+ throw new TaskLogMigrationUsageError('--batch-tasks must be a positive integer.');
169
+ }
170
+ batchTasks = parsed;
171
+ index += 1;
172
+ continue;
173
+ }
174
+ if (arg.startsWith('--batch-tasks=')) {
175
+ const value = arg.slice('--batch-tasks='.length);
176
+ const parsed = Number(value);
177
+ if (!Number.isSafeInteger(parsed) || parsed < 1) {
178
+ throw new TaskLogMigrationUsageError('--batch-tasks must be a positive integer.');
179
+ }
180
+ batchTasks = parsed;
181
+ continue;
182
+ }
183
+ throw new TaskLogMigrationUsageError(`Unknown option: ${arg}`);
184
+ }
185
+ if (!mode)
186
+ throw new TaskLogMigrationUsageError('Choose one of --dry-run, --apply, or --verify.');
187
+ if (batchTasks !== undefined && mode !== 'apply') {
188
+ throw new TaskLogMigrationUsageError('--batch-tasks is only valid with --apply.');
189
+ }
190
+ return { mode, dbPath, batchTasks };
191
+ }
192
+ function formatMigrationReport(report) {
193
+ const modeLabel = report.mode === 'dry-run' ? 'Dry-run' : report.mode === 'apply' ? 'Apply' : 'Verify';
194
+ const lines = [
195
+ `[crewx] Task-log migration — ${modeLabel}`,
196
+ ` Database: ${report.dbPath}`,
197
+ ` Tasks scanned: ${report.taskCount}`,
198
+ ` Blob candidates: ${report.candidateTaskCount}`,
199
+ ` Eligible terminal blobs: ${report.eligibleTaskCount}`,
200
+ ` Status counts: ${formatStatusCounts(report.statusCounts)}`,
201
+ ` Deferred blob tasks: ${report.deferredTaskCount}`,
202
+ ` Deferred statuses: ${formatStatusCounts(report.deferredStatusCounts)}`,
203
+ ` Entries: ${report.entryCount}`,
204
+ ` Source bytes: ${report.sourceBytes}`,
205
+ ` Estimated free-space need: ${report.estimatedFreeSpaceBytes}`,
206
+ ` Required free space (with reserve): ${report.requiredFreeSpaceBytes}`,
207
+ ` Available free space: ${report.availableFreeSpaceBytes}`,
208
+ ` Free-space gate: ${report.freeSpaceGatePassed ? 'PASS' : 'FAIL'}`,
209
+ ` Migrated: ${report.migratedTasks} task(s), ${report.migratedEntries} entr${report.migratedEntries === 1 ? 'y' : 'ies'}`,
210
+ ` Skipped event-source tasks: ${report.skippedTasks}`,
211
+ ` Failed tasks: ${report.failedTasks}`,
212
+ ` Logical source bytes removed: ${report.logicalSourceBytesRemoved}`,
213
+ ];
214
+ if (report.remainingTaskCount !== undefined)
215
+ lines.push(` Remaining blob tasks: ${report.remainingTaskCount}`);
216
+ if (report.backupPath) {
217
+ lines.push(` Backup: ${report.backupPath}`);
218
+ if (report.backupMethod)
219
+ lines.push(` Backup method: ${report.backupMethod}`);
220
+ }
221
+ if (report.verification) {
222
+ lines.push(` Event rows checked: ${report.verification.eventCount}`);
223
+ lines.push(` Verification issues: ${report.verification.issues.length}`);
224
+ }
225
+ if (report.blockedReason)
226
+ lines.push(` Blocked: ${report.blockedReason}`);
227
+ for (const warning of report.warnings ?? [])
228
+ lines.push(` Warning: ${warning}`);
229
+ return lines.join('\n');
230
+ }
231
+ async function handleTaskLogMigration(args) {
232
+ let parsed;
233
+ try {
234
+ parsed = parseTaskLogMigrationArgs(args);
235
+ }
236
+ catch (error) {
237
+ const message = error instanceof Error ? error.message : String(error);
238
+ if (message === exports.TASK_LOG_MIGRATION_HELP) {
239
+ console.log(message);
240
+ }
241
+ else {
242
+ console.error(message);
243
+ console.error(exports.TASK_LOG_MIGRATION_HELP);
244
+ process.exitCode = 2;
245
+ }
246
+ return;
247
+ }
248
+ try {
249
+ const report = await (0, repository_3.runTaskLogMigration)(parsed);
250
+ console.log(formatMigrationReport(report));
251
+ if (!report.ok) {
252
+ if (report.blockedReason)
253
+ console.error(report.blockedReason);
254
+ const failures = report.failures ?? report.malformedRows ?? [];
255
+ for (const failure of failures) {
256
+ console.error(` ${failure.taskId}: ${failure.reason}`);
257
+ }
258
+ process.exitCode = 1;
259
+ }
260
+ else {
261
+ process.exitCode = 0;
262
+ }
263
+ }
264
+ catch (error) {
265
+ console.error(error instanceof Error ? error.message : String(error));
266
+ process.exitCode = 1;
267
+ }
78
268
  }
79
269
  async function handleDbPush(args) {
80
270
  const force = args.includes('--force');
@@ -34,9 +34,9 @@ function isAgyCommand(codingAgentCommand) {
34
34
  const base = firstToken.split('/').pop() ?? firstToken;
35
35
  return base.startsWith('agy');
36
36
  }
37
- function getLastActive(task) {
37
+ function getLastActive(task, taskRepo) {
38
38
  try {
39
- const entries = task.logs ? JSON.parse(task.logs) : [];
39
+ const entries = taskRepo.readLogsTail(task.id, 1)?.entries ?? [];
40
40
  if (Array.isArray(entries) && entries.length > 0) {
41
41
  const lastEntry = entries[entries.length - 1];
42
42
  const ts = lastEntry?.timestamp;
@@ -59,9 +59,9 @@ function getLastActive(task) {
59
59
  }
60
60
  return { display: '—', isoTimestamp: null, logCapable: true };
61
61
  }
62
- function taskToRow(task) {
62
+ function taskToRow(task, taskRepo) {
63
63
  const elapsed = formatElapsed(Date.now() - new Date(task.started_at).getTime());
64
- const lastActive = getLastActive(task);
64
+ const lastActive = getLastActive(task, taskRepo);
65
65
  return [
66
66
  task.id,
67
67
  task.agent_id ?? '—',
@@ -91,7 +91,7 @@ async function handlePs(args) {
91
91
  }
92
92
  if (args.includes('--json')) {
93
93
  const withLastActive = tasks.map((task) => {
94
- const lastActive = getLastActive(task);
94
+ const lastActive = getLastActive(task, repo);
95
95
  return {
96
96
  ...task,
97
97
  last_active_at: lastActive.isoTimestamp,
@@ -102,7 +102,7 @@ async function handlePs(args) {
102
102
  return;
103
103
  }
104
104
  const headers = ['TASK ID', 'AGENT', 'PID', 'ELAPSED', 'MODE', 'LAST ACTIVE'];
105
- const rows = tasks.map(taskToRow);
105
+ const rows = tasks.map((task) => taskToRow(task, repo));
106
106
  renderTable(headers, rows);
107
107
  console.log(`\n ${tasks.length} running task(s)`);
108
108
  }
package/dist/main.js CHANGED
@@ -317,6 +317,10 @@ Database:
317
317
  db push Sync DB schema to current code (additive only)
318
318
  --force Reset migration history + skip confirmation
319
319
  --dry-run Preview changes without applying
320
+ db migrate-task-logs Backfill legacy tasks.logs into task_log_events
321
+ --dry-run Validate and estimate without writing
322
+ --apply Consistent backup + resumable task-by-task apply
323
+ --verify Check event/source invariants and parity
320
324
 
321
325
  Desktop Shortcut (Windows only):
322
326
  shortcut status [--json] Show current shortcut status
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crewx/cli",
3
- "version": "0.9.0-rc.65",
3
+ "version": "0.9.0-rc.66",
4
4
  "license": "UNLICENSED",
5
5
  "engines": {
6
6
  "node": ">=20.19.0"
@@ -25,18 +25,18 @@
25
25
  "better-sqlite3": "*",
26
26
  "dotenv": "17.2.3",
27
27
  "isomorphic-git": "1.37.1",
28
- "@crewx/sdk": "0.9.0-rc.65",
29
- "@crewx/memory": "0.1.23-rc.81",
30
- "@crewx/search": "0.1.10-rc.60",
31
- "@crewx/doc": "0.1.9-rc.57",
32
- "@crewx/wbs": "0.1.10-rc.90",
33
- "@crewx/cron": "0.1.10-rc.99",
34
- "@crewx/wi": "0.1.10-rc.85",
28
+ "@crewx/sdk": "0.9.0-rc.66",
29
+ "@crewx/memory": "0.1.23-rc.82",
30
+ "@crewx/search": "0.1.10-rc.61",
31
+ "@crewx/doc": "0.1.9-rc.58",
32
+ "@crewx/wbs": "0.1.10-rc.91",
33
+ "@crewx/cron": "0.1.10-rc.100",
34
+ "@crewx/workflow": "0.3.22-rc.112",
35
35
  "@crewx/skill": "0.1.20",
36
- "@crewx/notify": "0.1.0-rc.35",
37
- "@crewx/workflow": "0.3.22-rc.111",
38
- "@crewx/shared": "0.0.6",
39
- "@crewx/chromex": "0.1.0-rc.97"
36
+ "@crewx/wi": "0.1.10-rc.86",
37
+ "@crewx/chromex": "0.1.0-rc.98",
38
+ "@crewx/notify": "0.1.0-rc.36",
39
+ "@crewx/shared": "0.0.6"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@types/better-sqlite3": "*",