@crewx/cli 0.8.4-rc.4 → 0.8.4-rc.5
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/commands/db.d.ts +9 -0
- package/dist/commands/db.js +125 -0
- package/dist/commands/registry.js +1 -0
- package/dist/main.js +10 -0
- package/package.json +5 -5
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* crewx db push handler.
|
|
3
|
+
*
|
|
4
|
+
* Usage:
|
|
5
|
+
* crewx db push Preview changes → confirm → apply
|
|
6
|
+
* crewx db push --force Apply without confirmation + reset migration history
|
|
7
|
+
* crewx db push --dry-run Show preview only, no changes
|
|
8
|
+
*/
|
|
9
|
+
export declare function handleDb(args: string[]): Promise<void>;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* crewx db push handler.
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* crewx db push Preview changes → confirm → apply
|
|
7
|
+
* crewx db push --force Apply without confirmation + reset migration history
|
|
8
|
+
* crewx db push --dry-run Show preview only, no changes
|
|
9
|
+
*/
|
|
10
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
11
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.handleDb = handleDb;
|
|
15
|
+
const path_1 = __importDefault(require("path"));
|
|
16
|
+
const os_1 = __importDefault(require("os"));
|
|
17
|
+
const readline_1 = __importDefault(require("readline"));
|
|
18
|
+
const repository_1 = require("@crewx/sdk/repository");
|
|
19
|
+
const repository_2 = require("@crewx/sdk/repository");
|
|
20
|
+
function defaultDbPath() {
|
|
21
|
+
return path_1.default.join(os_1.default.homedir(), '.crewx', 'crewx.db');
|
|
22
|
+
}
|
|
23
|
+
function formatPreview(result, dbPath) {
|
|
24
|
+
const lines = [];
|
|
25
|
+
lines.push(`[crewx] Database push — comparing schema vs ${dbPath}`);
|
|
26
|
+
lines.push('');
|
|
27
|
+
if (result.created.length > 0) {
|
|
28
|
+
lines.push(` Tables to create:`);
|
|
29
|
+
for (const t of result.created) {
|
|
30
|
+
lines.push(` → ${t}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
lines.push(' Tables to create: (none)');
|
|
35
|
+
}
|
|
36
|
+
if (result.altered.length > 0) {
|
|
37
|
+
lines.push(' Columns to add:');
|
|
38
|
+
for (const { table, column } of result.altered) {
|
|
39
|
+
lines.push(` → ${table}.${column}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
lines.push(' Columns to add: (none)');
|
|
44
|
+
}
|
|
45
|
+
if (result.warnings.length > 0) {
|
|
46
|
+
lines.push(' Warnings:');
|
|
47
|
+
for (const w of result.warnings) {
|
|
48
|
+
lines.push(` ⚠ ${w}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (result.backupPath) {
|
|
52
|
+
lines.push('');
|
|
53
|
+
lines.push(` Backup: ${result.backupPath}`);
|
|
54
|
+
}
|
|
55
|
+
return lines.join('\n');
|
|
56
|
+
}
|
|
57
|
+
function hasChanges(result) {
|
|
58
|
+
return result.created.length > 0 || result.altered.length > 0;
|
|
59
|
+
}
|
|
60
|
+
function prompt(question) {
|
|
61
|
+
const rl = readline_1.default.createInterface({ input: process.stdin, output: process.stdout });
|
|
62
|
+
return new Promise((resolve) => {
|
|
63
|
+
rl.question(question, (answer) => {
|
|
64
|
+
rl.close();
|
|
65
|
+
resolve(answer);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
async function handleDb(args) {
|
|
70
|
+
const subcommand = args[0];
|
|
71
|
+
if (!subcommand || subcommand === 'push') {
|
|
72
|
+
await handleDbPush(args.slice(subcommand === 'push' ? 1 : 0));
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
console.error(`Unknown db subcommand: ${subcommand}`);
|
|
76
|
+
console.error('Usage: crewx db push [--force] [--dry-run]');
|
|
77
|
+
process.exit(1);
|
|
78
|
+
}
|
|
79
|
+
async function handleDbPush(args) {
|
|
80
|
+
const force = args.includes('--force');
|
|
81
|
+
const dryRun = args.includes('--dry-run');
|
|
82
|
+
const dbPath = defaultDbPath();
|
|
83
|
+
const handle = (0, repository_1.openDrizzleDb)(dbPath);
|
|
84
|
+
try {
|
|
85
|
+
// 1. Compute preview (dry-run pass — no changes yet)
|
|
86
|
+
const preview = (0, repository_2.pushSchema)(handle.db, { force, dbPath, dryRun: true });
|
|
87
|
+
console.log(formatPreview(preview, dbPath));
|
|
88
|
+
console.log('');
|
|
89
|
+
if (dryRun) {
|
|
90
|
+
console.log('[crewx] Dry-run mode — no changes applied.');
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (!hasChanges(preview)) {
|
|
94
|
+
console.log('[crewx] No changes needed. Database is up to date.');
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
// 2. Confirm unless --force
|
|
98
|
+
if (!force) {
|
|
99
|
+
const answer = await prompt('Apply changes? (y/N): ');
|
|
100
|
+
if (answer.trim().toLowerCase() !== 'y') {
|
|
101
|
+
console.log('[crewx] Aborted.');
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
// 3. Apply
|
|
106
|
+
const result = (0, repository_2.pushSchema)(handle.db, { force, dbPath });
|
|
107
|
+
console.log('');
|
|
108
|
+
console.log('[crewx] Push complete.');
|
|
109
|
+
if (result.created.length > 0) {
|
|
110
|
+
console.log(` Tables created: ${result.created.join(', ')}`);
|
|
111
|
+
}
|
|
112
|
+
if (result.altered.length > 0) {
|
|
113
|
+
console.log(` Columns added: ${result.altered.map((a) => `${a.table}.${a.column}`).join(', ')}`);
|
|
114
|
+
}
|
|
115
|
+
if (result.backupPath) {
|
|
116
|
+
console.log(` Backup: ${result.backupPath}`);
|
|
117
|
+
}
|
|
118
|
+
if (result.created.length === 0 && result.altered.length === 0) {
|
|
119
|
+
console.log(' No changes applied.');
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
finally {
|
|
123
|
+
handle.close();
|
|
124
|
+
}
|
|
125
|
+
}
|
package/dist/main.js
CHANGED
|
@@ -64,6 +64,7 @@ const install_1 = require("./commands/hook/install");
|
|
|
64
64
|
const uninstall_1 = require("./commands/hook/uninstall");
|
|
65
65
|
const status_1 = require("./commands/hook/status");
|
|
66
66
|
const hook_dispatch_1 = require("./commands/hook-dispatch");
|
|
67
|
+
const db_1 = require("./commands/db");
|
|
67
68
|
const parse_common_flags_1 = require("./commands/parse-common-flags");
|
|
68
69
|
const registry_1 = require("./commands/registry");
|
|
69
70
|
const version_1 = require("./utils/version");
|
|
@@ -164,6 +165,10 @@ async function main() {
|
|
|
164
165
|
}
|
|
165
166
|
return;
|
|
166
167
|
}
|
|
168
|
+
// DB management: crewx db push [--force] [--dry-run]
|
|
169
|
+
case 'db':
|
|
170
|
+
await (0, db_1.handleDb)(args.slice(1));
|
|
171
|
+
return;
|
|
167
172
|
// SDK-009: slack / slack:files
|
|
168
173
|
case 'slack':
|
|
169
174
|
case 'slack:files':
|
|
@@ -273,6 +278,11 @@ Logs & Diagnostics:
|
|
|
273
278
|
doctor [--config <path>] Run system diagnosis
|
|
274
279
|
init [--force] [--config <p>] Initialize crewx.yaml
|
|
275
280
|
|
|
281
|
+
Database:
|
|
282
|
+
db push Sync DB schema to current code (additive only)
|
|
283
|
+
--force Reset migration history + skip confirmation
|
|
284
|
+
--dry-run Preview changes without applying
|
|
285
|
+
|
|
276
286
|
Built-in Tools:
|
|
277
287
|
memory <args> Memory tool
|
|
278
288
|
search <args> Search tool
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crewx/cli",
|
|
3
|
-
"version": "0.8.4-rc.
|
|
3
|
+
"version": "0.8.4-rc.5",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=20.19.0"
|
|
@@ -27,15 +27,15 @@
|
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@crewx/adapter-slack": "^0.1.4",
|
|
29
29
|
"better-sqlite3": "*",
|
|
30
|
+
"@crewx/sdk": "0.8.4-rc.2",
|
|
31
|
+
"@crewx/wbs": "0.1.9",
|
|
30
32
|
"@crewx/memory": "0.1.10",
|
|
31
|
-
"@crewx/sdk": "0.8.4-rc.1",
|
|
32
33
|
"@crewx/search": "0.1.9",
|
|
33
34
|
"@crewx/doc": "0.1.8",
|
|
34
|
-
"@crewx/wbs": "0.1.9",
|
|
35
35
|
"@crewx/cron": "0.1.8",
|
|
36
|
-
"@crewx/
|
|
36
|
+
"@crewx/skill": "0.1.8",
|
|
37
37
|
"@crewx/shared": "0.0.5",
|
|
38
|
-
"@crewx/
|
|
38
|
+
"@crewx/workflow": "0.3.18"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"@types/better-sqlite3": "*",
|