@learnrudi/cli 1.9.12 → 1.10.1
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/LICENSE +21 -0
- package/README.md +194 -137
- package/dist/index.cjs +764 -14
- package/dist/packages-manifest.json +1 -1
- package/package.json +22 -21
package/dist/index.cjs
CHANGED
|
@@ -1016,8 +1016,7 @@ async function resolvePackage(id) {
|
|
|
1016
1016
|
if (id.startsWith("npm:")) {
|
|
1017
1017
|
return resolveDynamicNpm(id);
|
|
1018
1018
|
}
|
|
1019
|
-
const
|
|
1020
|
-
const pkg = await getPackage(normalizedId);
|
|
1019
|
+
const pkg = await getPackage(id);
|
|
1021
1020
|
if (!pkg) {
|
|
1022
1021
|
throw new Error(`Package not found: ${id}`);
|
|
1023
1022
|
}
|
|
@@ -17303,6 +17302,7 @@ __export(sqlite_exports, {
|
|
|
17303
17302
|
clearEmbeddings: () => clearEmbeddings,
|
|
17304
17303
|
deleteEmbedding: () => deleteEmbedding,
|
|
17305
17304
|
ensureEmbeddingsSchema: () => ensureEmbeddingsSchema,
|
|
17305
|
+
getAllEmbeddingStats: () => getAllEmbeddingStats,
|
|
17306
17306
|
getEmbeddingStats: () => getEmbeddingStats,
|
|
17307
17307
|
getErrorTurns: () => getErrorTurns,
|
|
17308
17308
|
getMissingTurns: () => getMissingTurns,
|
|
@@ -17472,6 +17472,38 @@ function getEmbeddingStats(model) {
|
|
|
17472
17472
|
}
|
|
17473
17473
|
return stats;
|
|
17474
17474
|
}
|
|
17475
|
+
function getAllEmbeddingStats() {
|
|
17476
|
+
const db3 = getDb2();
|
|
17477
|
+
const totalStmt = db3.prepare(`
|
|
17478
|
+
SELECT COUNT(*) as count
|
|
17479
|
+
FROM turns
|
|
17480
|
+
WHERE (user_message IS NOT NULL AND length(trim(user_message)) > 0)
|
|
17481
|
+
OR (assistant_response IS NOT NULL AND length(trim(assistant_response)) > 0)
|
|
17482
|
+
`);
|
|
17483
|
+
const total = totalStmt.get().count;
|
|
17484
|
+
const statsStmt = db3.prepare(`
|
|
17485
|
+
SELECT
|
|
17486
|
+
status,
|
|
17487
|
+
COUNT(*) as count
|
|
17488
|
+
FROM turn_embeddings
|
|
17489
|
+
GROUP BY status
|
|
17490
|
+
`);
|
|
17491
|
+
const stats = { total, done: 0, queued: 0, error: 0 };
|
|
17492
|
+
for (const row of statsStmt.all()) {
|
|
17493
|
+
stats[row.status] = row.count;
|
|
17494
|
+
}
|
|
17495
|
+
const modelsStmt = db3.prepare(`
|
|
17496
|
+
SELECT model, dimensions, COUNT(*) as count
|
|
17497
|
+
FROM turn_embeddings
|
|
17498
|
+
WHERE status = 'done'
|
|
17499
|
+
GROUP BY model, dimensions
|
|
17500
|
+
`);
|
|
17501
|
+
stats.models = {};
|
|
17502
|
+
for (const row of modelsStmt.all()) {
|
|
17503
|
+
stats.models[row.model] = { dimensions: row.dimensions, count: row.count };
|
|
17504
|
+
}
|
|
17505
|
+
return stats;
|
|
17506
|
+
}
|
|
17475
17507
|
function deleteEmbedding(turnId) {
|
|
17476
17508
|
const db3 = getDb2();
|
|
17477
17509
|
db3.prepare("DELETE FROM turn_embeddings WHERE turn_id = ?").run(turnId);
|
|
@@ -35517,6 +35549,7 @@ function dbTables(flags) {
|
|
|
35517
35549
|
}
|
|
35518
35550
|
|
|
35519
35551
|
// src/commands/session.js
|
|
35552
|
+
var import_readline2 = require("readline");
|
|
35520
35553
|
var embeddingsModule = null;
|
|
35521
35554
|
async function getEmbeddings() {
|
|
35522
35555
|
if (!embeddingsModule) {
|
|
@@ -35524,6 +35557,92 @@ async function getEmbeddings() {
|
|
|
35524
35557
|
}
|
|
35525
35558
|
return embeddingsModule;
|
|
35526
35559
|
}
|
|
35560
|
+
async function confirm(message) {
|
|
35561
|
+
const rl = (0, import_readline2.createInterface)({ input: process.stdin, output: process.stdout });
|
|
35562
|
+
return new Promise((resolve) => {
|
|
35563
|
+
rl.question(`${message} [Y/n] `, (answer) => {
|
|
35564
|
+
rl.close();
|
|
35565
|
+
resolve(answer.toLowerCase() !== "n");
|
|
35566
|
+
});
|
|
35567
|
+
});
|
|
35568
|
+
}
|
|
35569
|
+
async function ensureEmbeddingProvider(preferredProvider = "auto", options = {}) {
|
|
35570
|
+
const { checkProviderStatus: checkProviderStatus2, getProvider: getProvider2 } = await getEmbeddings();
|
|
35571
|
+
const status = await checkProviderStatus2();
|
|
35572
|
+
if (preferredProvider === "openai") {
|
|
35573
|
+
if (status.openai.configured) {
|
|
35574
|
+
return await getProvider2("openai");
|
|
35575
|
+
}
|
|
35576
|
+
console.log("OpenAI not configured. Set OPENAI_API_KEY environment variable.");
|
|
35577
|
+
return null;
|
|
35578
|
+
}
|
|
35579
|
+
try {
|
|
35580
|
+
return await getProvider2("auto");
|
|
35581
|
+
} catch {
|
|
35582
|
+
}
|
|
35583
|
+
if (status.openai.configured) {
|
|
35584
|
+
console.log("\nOllama not available. OpenAI is configured.");
|
|
35585
|
+
const useOpenAI = await confirm("Use OpenAI for embeddings? (costs ~$0.02/1M tokens)");
|
|
35586
|
+
if (useOpenAI) {
|
|
35587
|
+
return await getProvider2("openai");
|
|
35588
|
+
}
|
|
35589
|
+
}
|
|
35590
|
+
console.log("\nNo embedding provider available.\n");
|
|
35591
|
+
console.log("Options:");
|
|
35592
|
+
console.log(" [1] Install Ollama (recommended - free, local, works offline)");
|
|
35593
|
+
console.log(" [2] Use OpenAI (requires OPENAI_API_KEY)");
|
|
35594
|
+
console.log(" [3] Cancel\n");
|
|
35595
|
+
const rl = (0, import_readline2.createInterface)({ input: process.stdin, output: process.stdout });
|
|
35596
|
+
const choice = await new Promise((resolve) => {
|
|
35597
|
+
rl.question("Choice [1]: ", (answer) => {
|
|
35598
|
+
rl.close();
|
|
35599
|
+
resolve(answer || "1");
|
|
35600
|
+
});
|
|
35601
|
+
});
|
|
35602
|
+
if (choice === "3" || choice.toLowerCase() === "cancel") {
|
|
35603
|
+
return null;
|
|
35604
|
+
}
|
|
35605
|
+
if (choice === "2") {
|
|
35606
|
+
if (!status.openai.configured) {
|
|
35607
|
+
console.log("\nOpenAI not configured.");
|
|
35608
|
+
console.log("Set: export OPENAI_API_KEY=your-key");
|
|
35609
|
+
return null;
|
|
35610
|
+
}
|
|
35611
|
+
return await getProvider2("openai");
|
|
35612
|
+
}
|
|
35613
|
+
console.log("\nInstalling Ollama...");
|
|
35614
|
+
try {
|
|
35615
|
+
const { installPackage: installPackage2 } = await Promise.resolve().then(() => (init_src4(), src_exports2));
|
|
35616
|
+
await installPackage2("runtime:ollama", {
|
|
35617
|
+
onProgress: (p2) => {
|
|
35618
|
+
if (p2.phase === "downloading") process.stdout.write("\r Downloading...");
|
|
35619
|
+
if (p2.phase === "extracting") process.stdout.write("\r Installing... ");
|
|
35620
|
+
}
|
|
35621
|
+
});
|
|
35622
|
+
console.log("\r \u2713 Ollama installed ");
|
|
35623
|
+
console.log(" Starting ollama serve...");
|
|
35624
|
+
const { spawn: spawn4 } = await import("child_process");
|
|
35625
|
+
const server = spawn4("ollama", ["serve"], {
|
|
35626
|
+
detached: true,
|
|
35627
|
+
stdio: "ignore",
|
|
35628
|
+
env: { ...process.env, HOME: process.env.HOME }
|
|
35629
|
+
});
|
|
35630
|
+
server.unref();
|
|
35631
|
+
await new Promise((r2) => setTimeout(r2, 2e3));
|
|
35632
|
+
console.log(" Pulling nomic-embed-text model (274MB)...");
|
|
35633
|
+
const { execSync: execSync10 } = await import("child_process");
|
|
35634
|
+
execSync10("ollama pull nomic-embed-text", { stdio: "inherit" });
|
|
35635
|
+
console.log(" \u2713 Model ready\n");
|
|
35636
|
+
return await getProvider2("ollama");
|
|
35637
|
+
} catch (err) {
|
|
35638
|
+
console.error("\nSetup failed:", err.message);
|
|
35639
|
+
console.log("\nManual setup:");
|
|
35640
|
+
console.log(" rudi install ollama");
|
|
35641
|
+
console.log(" ollama serve");
|
|
35642
|
+
console.log(" ollama pull nomic-embed-text");
|
|
35643
|
+
return null;
|
|
35644
|
+
}
|
|
35645
|
+
}
|
|
35527
35646
|
async function cmdSession(args, flags) {
|
|
35528
35647
|
const subcommand = args[0];
|
|
35529
35648
|
switch (subcommand) {
|
|
@@ -35560,6 +35679,9 @@ async function cmdSession(args, flags) {
|
|
|
35560
35679
|
case "setup":
|
|
35561
35680
|
await sessionSetup(flags);
|
|
35562
35681
|
break;
|
|
35682
|
+
case "organize":
|
|
35683
|
+
await sessionOrganize(flags);
|
|
35684
|
+
break;
|
|
35563
35685
|
default:
|
|
35564
35686
|
console.log(`
|
|
35565
35687
|
rudi session - Manage RUDI sessions
|
|
@@ -35579,6 +35701,9 @@ SEMANTIC SEARCH
|
|
|
35579
35701
|
index [--embeddings] [--provider X] Index sessions for semantic search
|
|
35580
35702
|
similar <id> [--limit] Find similar sessions
|
|
35581
35703
|
|
|
35704
|
+
ORGANIZATION (batch operations)
|
|
35705
|
+
organize [--dry-run] [--out plan.json] Auto-organize sessions into projects
|
|
35706
|
+
|
|
35582
35707
|
OPTIONS
|
|
35583
35708
|
--provider <name> Filter by provider (claude, codex, gemini)
|
|
35584
35709
|
--project <name> Filter by project name
|
|
@@ -35926,8 +36051,12 @@ Found ${results.length} result(s) for "${query}":
|
|
|
35926
36051
|
async function semanticSearch(query, options) {
|
|
35927
36052
|
const { limit: limit2, format } = options;
|
|
35928
36053
|
try {
|
|
35929
|
-
const { createClient: createClient2
|
|
35930
|
-
const
|
|
36054
|
+
const { createClient: createClient2 } = await getEmbeddings();
|
|
36055
|
+
const result = await ensureEmbeddingProvider("auto");
|
|
36056
|
+
if (!result) {
|
|
36057
|
+
return;
|
|
36058
|
+
}
|
|
36059
|
+
const { provider, model } = result;
|
|
35931
36060
|
console.log(`Using ${provider.id} with ${model.name}`);
|
|
35932
36061
|
const client = createClient2({ provider, model });
|
|
35933
36062
|
const stats = client.getStats();
|
|
@@ -35976,18 +36105,25 @@ async function sessionIndex(flags) {
|
|
|
35976
36105
|
const providerName = flags.provider || "auto";
|
|
35977
36106
|
if (!flags.embeddings) {
|
|
35978
36107
|
try {
|
|
35979
|
-
const {
|
|
35980
|
-
const
|
|
35981
|
-
const stats = store.getEmbeddingStats(model);
|
|
36108
|
+
const { store } = await getEmbeddings();
|
|
36109
|
+
const stats = store.getAllEmbeddingStats();
|
|
35982
36110
|
const pct = stats.total > 0 ? (stats.done / stats.total * 100).toFixed(1) : 0;
|
|
35983
36111
|
console.log("\nEmbedding Index Status:");
|
|
35984
36112
|
console.log(` Total turns: ${stats.total}`);
|
|
35985
36113
|
console.log(` Indexed: ${stats.done} (${pct}%)`);
|
|
35986
36114
|
console.log(` Queued: ${stats.queued}`);
|
|
35987
36115
|
console.log(` Errors: ${stats.error}`);
|
|
35988
|
-
|
|
35989
|
-
|
|
35990
|
-
|
|
36116
|
+
if (Object.keys(stats.models).length > 0) {
|
|
36117
|
+
console.log("\nIndexed by model:");
|
|
36118
|
+
for (const [model, info] of Object.entries(stats.models)) {
|
|
36119
|
+
console.log(` ${model} (${info.dimensions}d): ${info.count} turns`);
|
|
36120
|
+
}
|
|
36121
|
+
}
|
|
36122
|
+
if (stats.done < stats.total) {
|
|
36123
|
+
console.log("\nTo index missing turns:");
|
|
36124
|
+
console.log(" rudi session index --embeddings");
|
|
36125
|
+
console.log(" rudi session index --embeddings --provider ollama");
|
|
36126
|
+
}
|
|
35991
36127
|
} catch (err) {
|
|
35992
36128
|
console.log("Embedding status unavailable:", err.message);
|
|
35993
36129
|
}
|
|
@@ -35995,8 +36131,12 @@ async function sessionIndex(flags) {
|
|
|
35995
36131
|
}
|
|
35996
36132
|
console.log("Indexing sessions for semantic search...\n");
|
|
35997
36133
|
try {
|
|
35998
|
-
const { createClient: createClient2
|
|
35999
|
-
const
|
|
36134
|
+
const { createClient: createClient2 } = await getEmbeddings();
|
|
36135
|
+
const providerResult = await ensureEmbeddingProvider(providerName);
|
|
36136
|
+
if (!providerResult) {
|
|
36137
|
+
return;
|
|
36138
|
+
}
|
|
36139
|
+
const { provider, model } = providerResult;
|
|
36000
36140
|
console.log(`Provider: ${provider.id}`);
|
|
36001
36141
|
console.log(`Model: ${model.name} (${model.dimensions}d)
|
|
36002
36142
|
`);
|
|
@@ -36057,8 +36197,12 @@ async function sessionSimilar(args, flags) {
|
|
|
36057
36197
|
const format = flags.format || "table";
|
|
36058
36198
|
const providerName = flags.provider || "auto";
|
|
36059
36199
|
try {
|
|
36060
|
-
const { createClient: createClient2
|
|
36061
|
-
const
|
|
36200
|
+
const { createClient: createClient2 } = await getEmbeddings();
|
|
36201
|
+
const result = await ensureEmbeddingProvider(providerName);
|
|
36202
|
+
if (!result) {
|
|
36203
|
+
return;
|
|
36204
|
+
}
|
|
36205
|
+
const { provider, model } = result;
|
|
36062
36206
|
const client = createClient2({ provider, model });
|
|
36063
36207
|
const results = await client.findSimilar(turnId, { limit: limit2 });
|
|
36064
36208
|
if (format === "json") {
|
|
@@ -36107,6 +36251,223 @@ async function sessionSetup(flags) {
|
|
|
36107
36251
|
console.error("Setup error:", err.message);
|
|
36108
36252
|
}
|
|
36109
36253
|
}
|
|
36254
|
+
async function sessionOrganize(flags) {
|
|
36255
|
+
if (!isDatabaseInitialized()) {
|
|
36256
|
+
console.log("Database not initialized.");
|
|
36257
|
+
return;
|
|
36258
|
+
}
|
|
36259
|
+
const dryRun = flags["dry-run"] || flags.dryRun || true;
|
|
36260
|
+
const outputFile = flags.out || flags.output || "organize-plan.json";
|
|
36261
|
+
const threshold = parseFloat(flags.threshold) || 0.65;
|
|
36262
|
+
const db3 = getDb();
|
|
36263
|
+
console.log("\u2550".repeat(60));
|
|
36264
|
+
console.log("Session Organization");
|
|
36265
|
+
console.log("\u2550".repeat(60));
|
|
36266
|
+
console.log(`Mode: ${dryRun ? "Dry run (preview only)" : "LIVE - will apply changes"}`);
|
|
36267
|
+
console.log(`Output: ${outputFile}`);
|
|
36268
|
+
console.log(`Similarity threshold: ${(threshold * 100).toFixed(0)}%`);
|
|
36269
|
+
console.log("\u2550".repeat(60));
|
|
36270
|
+
const sessions = db3.prepare(`
|
|
36271
|
+
SELECT
|
|
36272
|
+
s.id, s.provider, s.title, s.title_override, s.project_id, s.cwd,
|
|
36273
|
+
s.turn_count, s.total_cost, s.created_at, s.last_active_at,
|
|
36274
|
+
p.name as project_name
|
|
36275
|
+
FROM sessions s
|
|
36276
|
+
LEFT JOIN projects p ON s.project_id = p.id
|
|
36277
|
+
WHERE s.status = 'active'
|
|
36278
|
+
ORDER BY s.total_cost DESC
|
|
36279
|
+
`).all();
|
|
36280
|
+
console.log(`
|
|
36281
|
+
Analyzing ${sessions.length} sessions...
|
|
36282
|
+
`);
|
|
36283
|
+
const projects = db3.prepare("SELECT id, name FROM projects").all();
|
|
36284
|
+
const projectMap = new Map(projects.map((p2) => [p2.name.toLowerCase(), p2]));
|
|
36285
|
+
console.log(`Existing projects: ${projects.map((p2) => p2.name).join(", ") || "(none)"}
|
|
36286
|
+
`);
|
|
36287
|
+
const cwdGroups = /* @__PURE__ */ new Map();
|
|
36288
|
+
for (const s2 of sessions) {
|
|
36289
|
+
if (!s2.cwd) continue;
|
|
36290
|
+
const match = s2.cwd.match(/\/([^/]+)$/);
|
|
36291
|
+
const projectKey = match ? match[1] : "other";
|
|
36292
|
+
if (!cwdGroups.has(projectKey)) {
|
|
36293
|
+
cwdGroups.set(projectKey, []);
|
|
36294
|
+
}
|
|
36295
|
+
cwdGroups.get(projectKey).push(s2);
|
|
36296
|
+
}
|
|
36297
|
+
const genericTitlePatterns = [
|
|
36298
|
+
/^(Imported|Agent|New|Untitled|Chat) Session$/i,
|
|
36299
|
+
/^Session \d+$/i,
|
|
36300
|
+
/^Untitled$/i,
|
|
36301
|
+
/^[A-Z][a-z]+ [A-Z][a-z]+ [A-Z][a-z]+$/
|
|
36302
|
+
// "Adjective Verb Noun" (Claude auto-generated)
|
|
36303
|
+
];
|
|
36304
|
+
const sessionsNeedingTitles = sessions.filter((s2) => {
|
|
36305
|
+
if (s2.title_override && s2.title_override !== s2.title) {
|
|
36306
|
+
return false;
|
|
36307
|
+
}
|
|
36308
|
+
const title = s2.title || "";
|
|
36309
|
+
return !title || genericTitlePatterns.some((p2) => p2.test(title));
|
|
36310
|
+
});
|
|
36311
|
+
console.log(`Sessions with generic titles: ${sessionsNeedingTitles.length}`);
|
|
36312
|
+
const titleSuggestions = [];
|
|
36313
|
+
for (const s2 of sessionsNeedingTitles.slice(0, 100)) {
|
|
36314
|
+
const firstTurn = db3.prepare(`
|
|
36315
|
+
SELECT user_message
|
|
36316
|
+
FROM turns
|
|
36317
|
+
WHERE session_id = ? AND user_message IS NOT NULL AND length(trim(user_message)) > 10
|
|
36318
|
+
ORDER BY turn_number
|
|
36319
|
+
LIMIT 1
|
|
36320
|
+
`).get(s2.id);
|
|
36321
|
+
if (firstTurn && firstTurn.user_message) {
|
|
36322
|
+
const msg = firstTurn.user_message.trim();
|
|
36323
|
+
let suggestedTitle = msg.split("\n")[0].slice(0, 60).trim();
|
|
36324
|
+
const skipPatterns = [
|
|
36325
|
+
/^\/[A-Za-z]/,
|
|
36326
|
+
// Unix paths
|
|
36327
|
+
/^<[a-z-]+>/,
|
|
36328
|
+
// XML tags
|
|
36329
|
+
/^[A-Z]:\\[A-Za-z]/,
|
|
36330
|
+
// Windows paths
|
|
36331
|
+
/^(cd|ls|cat|npm|node|git|rudi|pnpm|yarn)\s/i,
|
|
36332
|
+
// Commands
|
|
36333
|
+
/^[a-f0-9-]{8,}/i,
|
|
36334
|
+
// UUIDs or hashes
|
|
36335
|
+
/^https?:\/\//i,
|
|
36336
|
+
// URLs
|
|
36337
|
+
/^[>\*\-#\d\.]\s/,
|
|
36338
|
+
// Markdown list/quote starts
|
|
36339
|
+
/^(yes|no|ok|sure|y|n)$/i,
|
|
36340
|
+
// Single word responses
|
|
36341
|
+
/^[^a-zA-Z]*$/,
|
|
36342
|
+
// No letters at all
|
|
36343
|
+
/^\s*\[/,
|
|
36344
|
+
// JSON/array starts
|
|
36345
|
+
/^\s*\{/
|
|
36346
|
+
// Object starts
|
|
36347
|
+
];
|
|
36348
|
+
if (skipPatterns.some((p2) => p2.test(suggestedTitle))) {
|
|
36349
|
+
continue;
|
|
36350
|
+
}
|
|
36351
|
+
const wordCount = suggestedTitle.split(/\s+/).length;
|
|
36352
|
+
if (wordCount < 3) {
|
|
36353
|
+
continue;
|
|
36354
|
+
}
|
|
36355
|
+
if (suggestedTitle.length > 50) {
|
|
36356
|
+
suggestedTitle = suggestedTitle.slice(0, 47) + "...";
|
|
36357
|
+
}
|
|
36358
|
+
if (suggestedTitle && suggestedTitle.length > 10) {
|
|
36359
|
+
titleSuggestions.push({
|
|
36360
|
+
sessionId: s2.id,
|
|
36361
|
+
currentTitle: s2.title || "(none)",
|
|
36362
|
+
suggestedTitle,
|
|
36363
|
+
cost: s2.total_cost,
|
|
36364
|
+
confidence: "medium"
|
|
36365
|
+
// Could add scoring later
|
|
36366
|
+
});
|
|
36367
|
+
}
|
|
36368
|
+
}
|
|
36369
|
+
}
|
|
36370
|
+
const projectSuggestions = [];
|
|
36371
|
+
const moveSuggestions = [];
|
|
36372
|
+
const knownProjects = {
|
|
36373
|
+
"studio": "Prompt Stack Studio",
|
|
36374
|
+
"prompt-stack": "Prompt Stack Studio",
|
|
36375
|
+
"RUDI": "RUDI",
|
|
36376
|
+
"rudi": "RUDI",
|
|
36377
|
+
"cli": "RUDI",
|
|
36378
|
+
"registry": "RUDI",
|
|
36379
|
+
"resonance": "Resonance",
|
|
36380
|
+
"cloud": "Cloud"
|
|
36381
|
+
};
|
|
36382
|
+
for (const [cwdKey, cwdSessions] of cwdGroups) {
|
|
36383
|
+
const projectName = knownProjects[cwdKey];
|
|
36384
|
+
if (projectName && cwdSessions.length >= 2) {
|
|
36385
|
+
const existingProject = projectMap.get(projectName.toLowerCase());
|
|
36386
|
+
for (const s2 of cwdSessions) {
|
|
36387
|
+
if (!s2.project_id || existingProject && s2.project_id !== existingProject.id) {
|
|
36388
|
+
moveSuggestions.push({
|
|
36389
|
+
sessionId: s2.id,
|
|
36390
|
+
sessionTitle: s2.title_override || s2.title,
|
|
36391
|
+
currentProject: s2.project_name || null,
|
|
36392
|
+
suggestedProject: projectName,
|
|
36393
|
+
reason: `Working directory: ${cwdKey}`,
|
|
36394
|
+
cost: s2.total_cost
|
|
36395
|
+
});
|
|
36396
|
+
}
|
|
36397
|
+
}
|
|
36398
|
+
if (!existingProject && cwdSessions.length >= 3) {
|
|
36399
|
+
projectSuggestions.push({
|
|
36400
|
+
name: projectName,
|
|
36401
|
+
sessionCount: cwdSessions.length,
|
|
36402
|
+
totalCost: cwdSessions.reduce((sum, s2) => sum + (s2.total_cost || 0), 0)
|
|
36403
|
+
});
|
|
36404
|
+
}
|
|
36405
|
+
}
|
|
36406
|
+
}
|
|
36407
|
+
const plan = {
|
|
36408
|
+
version: "1.0",
|
|
36409
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
36410
|
+
dryRun,
|
|
36411
|
+
threshold,
|
|
36412
|
+
summary: {
|
|
36413
|
+
totalSessions: sessions.length,
|
|
36414
|
+
sessionsWithProjects: sessions.filter((s2) => s2.project_id).length,
|
|
36415
|
+
sessionsNeedingTitles: sessionsNeedingTitles.length,
|
|
36416
|
+
projectsToCreate: projectSuggestions.length,
|
|
36417
|
+
movesToApply: moveSuggestions.length,
|
|
36418
|
+
titlesToUpdate: titleSuggestions.length
|
|
36419
|
+
},
|
|
36420
|
+
actions: {
|
|
36421
|
+
createProjects: projectSuggestions,
|
|
36422
|
+
moveSessions: moveSuggestions.slice(0, 200),
|
|
36423
|
+
// Limit batch size
|
|
36424
|
+
updateTitles: titleSuggestions.slice(0, 100)
|
|
36425
|
+
// Limit batch size
|
|
36426
|
+
}
|
|
36427
|
+
};
|
|
36428
|
+
console.log("\n" + "\u2500".repeat(60));
|
|
36429
|
+
console.log("PLAN SUMMARY");
|
|
36430
|
+
console.log("\u2500".repeat(60));
|
|
36431
|
+
console.log(`Sessions analyzed: ${plan.summary.totalSessions}`);
|
|
36432
|
+
console.log(`Already in projects: ${plan.summary.sessionsWithProjects}`);
|
|
36433
|
+
console.log(`
|
|
36434
|
+
Proposed actions:`);
|
|
36435
|
+
console.log(` Create projects: ${plan.summary.projectsToCreate}`);
|
|
36436
|
+
console.log(` Move sessions: ${plan.summary.movesToApply}`);
|
|
36437
|
+
console.log(` Update titles: ${plan.summary.titlesToUpdate}`);
|
|
36438
|
+
if (projectSuggestions.length > 0) {
|
|
36439
|
+
console.log("\nProjects to create:");
|
|
36440
|
+
for (const p2 of projectSuggestions) {
|
|
36441
|
+
console.log(` \u2022 ${p2.name} (${p2.sessionCount} sessions, $${p2.totalCost.toFixed(2)})`);
|
|
36442
|
+
}
|
|
36443
|
+
}
|
|
36444
|
+
if (moveSuggestions.length > 0) {
|
|
36445
|
+
console.log("\nTop session moves:");
|
|
36446
|
+
for (const m2 of moveSuggestions.slice(0, 10)) {
|
|
36447
|
+
console.log(` \u2022 "${m2.sessionTitle?.slice(0, 30) || m2.sessionId.slice(0, 8)}..." \u2192 ${m2.suggestedProject}`);
|
|
36448
|
+
}
|
|
36449
|
+
if (moveSuggestions.length > 10) {
|
|
36450
|
+
console.log(` ... and ${moveSuggestions.length - 10} more`);
|
|
36451
|
+
}
|
|
36452
|
+
}
|
|
36453
|
+
if (titleSuggestions.length > 0) {
|
|
36454
|
+
console.log("\nTop title updates:");
|
|
36455
|
+
for (const t2 of titleSuggestions.slice(0, 5)) {
|
|
36456
|
+
console.log(` \u2022 "${t2.currentTitle?.slice(0, 20) || "(none)"}..." \u2192 "${t2.suggestedTitle.slice(0, 30)}..."`);
|
|
36457
|
+
}
|
|
36458
|
+
if (titleSuggestions.length > 5) {
|
|
36459
|
+
console.log(` ... and ${titleSuggestions.length - 5} more`);
|
|
36460
|
+
}
|
|
36461
|
+
}
|
|
36462
|
+
const { writeFileSync: writeFileSync7 } = await import("fs");
|
|
36463
|
+
writeFileSync7(outputFile, JSON.stringify(plan, null, 2));
|
|
36464
|
+
console.log(`
|
|
36465
|
+
\u2713 Plan saved to: ${outputFile}`);
|
|
36466
|
+
console.log("\nTo apply this plan:");
|
|
36467
|
+
console.log(` rudi apply ${outputFile}`);
|
|
36468
|
+
console.log("\nTo review the full plan:");
|
|
36469
|
+
console.log(` cat ${outputFile} | jq .`);
|
|
36470
|
+
}
|
|
36110
36471
|
|
|
36111
36472
|
// src/commands/import.js
|
|
36112
36473
|
var import_fs17 = require("fs");
|
|
@@ -37902,9 +38263,26 @@ ${agentConfig.name}:`);
|
|
|
37902
38263
|
config[key] = {};
|
|
37903
38264
|
}
|
|
37904
38265
|
const rudiMcpShimPath = path29.join(PATHS.home, "shims", "rudi-mcp");
|
|
38266
|
+
const rudiStacksPath = path29.join(PATHS.home, "stacks");
|
|
37905
38267
|
const removedEntries = [];
|
|
37906
38268
|
for (const [serverName, serverConfig] of Object.entries(config[key])) {
|
|
38269
|
+
if (serverName === "rudi") continue;
|
|
38270
|
+
let shouldRemove = false;
|
|
37907
38271
|
if (serverConfig.command === rudiMcpShimPath) {
|
|
38272
|
+
shouldRemove = true;
|
|
38273
|
+
}
|
|
38274
|
+
if (serverConfig.cwd && serverConfig.cwd.startsWith(rudiStacksPath)) {
|
|
38275
|
+
shouldRemove = true;
|
|
38276
|
+
}
|
|
38277
|
+
if (serverConfig.args && Array.isArray(serverConfig.args)) {
|
|
38278
|
+
for (const arg of serverConfig.args) {
|
|
38279
|
+
if (typeof arg === "string" && arg.startsWith(rudiStacksPath)) {
|
|
38280
|
+
shouldRemove = true;
|
|
38281
|
+
break;
|
|
38282
|
+
}
|
|
38283
|
+
}
|
|
38284
|
+
}
|
|
38285
|
+
if (shouldRemove) {
|
|
37908
38286
|
delete config[key][serverName];
|
|
37909
38287
|
removedEntries.push(serverName);
|
|
37910
38288
|
}
|
|
@@ -39256,6 +39634,371 @@ Lockfile: ${lockPath}`);
|
|
|
39256
39634
|
}
|
|
39257
39635
|
}
|
|
39258
39636
|
|
|
39637
|
+
// src/commands/apply.js
|
|
39638
|
+
var import_fs28 = require("fs");
|
|
39639
|
+
var import_path26 = require("path");
|
|
39640
|
+
var import_os10 = require("os");
|
|
39641
|
+
var import_crypto3 = require("crypto");
|
|
39642
|
+
async function cmdApply(args, flags) {
|
|
39643
|
+
const planFile = args[0];
|
|
39644
|
+
const force = flags.force;
|
|
39645
|
+
const undoPlanId = flags.undo;
|
|
39646
|
+
const only = flags.only;
|
|
39647
|
+
if (undoPlanId) {
|
|
39648
|
+
return undoPlan(undoPlanId);
|
|
39649
|
+
}
|
|
39650
|
+
if (!planFile) {
|
|
39651
|
+
console.log(`
|
|
39652
|
+
rudi apply - Execute organization plans
|
|
39653
|
+
|
|
39654
|
+
USAGE
|
|
39655
|
+
rudi apply <plan.json> Apply a plan file
|
|
39656
|
+
rudi apply --undo <id> Undo a previously applied plan
|
|
39657
|
+
|
|
39658
|
+
OPTIONS
|
|
39659
|
+
--force Skip confirmation prompts
|
|
39660
|
+
--only <type> Apply only specific operations:
|
|
39661
|
+
move - session moves only
|
|
39662
|
+
rename - title updates only
|
|
39663
|
+
project - project creation only
|
|
39664
|
+
|
|
39665
|
+
EXAMPLES
|
|
39666
|
+
rudi session organize --dry-run --out plan.json
|
|
39667
|
+
rudi apply plan.json
|
|
39668
|
+
rudi apply plan.json --only move # Moves first (low regret)
|
|
39669
|
+
rudi apply plan.json --only rename # Renames second
|
|
39670
|
+
rudi apply --undo plan-20260109-abc123
|
|
39671
|
+
`);
|
|
39672
|
+
return;
|
|
39673
|
+
}
|
|
39674
|
+
if (!(0, import_fs28.existsSync)(planFile)) {
|
|
39675
|
+
console.error(`Plan file not found: ${planFile}`);
|
|
39676
|
+
process.exit(1);
|
|
39677
|
+
}
|
|
39678
|
+
if (!isDatabaseInitialized()) {
|
|
39679
|
+
console.error("Database not initialized. Run: rudi db init");
|
|
39680
|
+
process.exit(1);
|
|
39681
|
+
}
|
|
39682
|
+
let plan;
|
|
39683
|
+
try {
|
|
39684
|
+
plan = JSON.parse((0, import_fs28.readFileSync)(planFile, "utf-8"));
|
|
39685
|
+
} catch (err) {
|
|
39686
|
+
console.error(`Invalid plan file: ${err.message}`);
|
|
39687
|
+
process.exit(1);
|
|
39688
|
+
}
|
|
39689
|
+
if (!plan.version || !plan.actions) {
|
|
39690
|
+
console.error("Invalid plan format: missing version or actions");
|
|
39691
|
+
process.exit(1);
|
|
39692
|
+
}
|
|
39693
|
+
console.log("\u2550".repeat(60));
|
|
39694
|
+
console.log("Apply Organization Plan");
|
|
39695
|
+
console.log("\u2550".repeat(60));
|
|
39696
|
+
console.log(`Plan file: ${planFile}`);
|
|
39697
|
+
console.log(`Created: ${plan.createdAt}`);
|
|
39698
|
+
console.log("\u2550".repeat(60));
|
|
39699
|
+
let { createProjects = [], moveSessions = [], updateTitles = [] } = plan.actions;
|
|
39700
|
+
if (only) {
|
|
39701
|
+
console.log(`
|
|
39702
|
+
Filter: --only ${only}`);
|
|
39703
|
+
if (only === "move") {
|
|
39704
|
+
createProjects = [];
|
|
39705
|
+
updateTitles = [];
|
|
39706
|
+
} else if (only === "rename") {
|
|
39707
|
+
createProjects = [];
|
|
39708
|
+
moveSessions = [];
|
|
39709
|
+
} else if (only === "project") {
|
|
39710
|
+
moveSessions = [];
|
|
39711
|
+
updateTitles = [];
|
|
39712
|
+
} else {
|
|
39713
|
+
console.error(`Unknown filter: ${only}. Use: move, rename, project`);
|
|
39714
|
+
process.exit(1);
|
|
39715
|
+
}
|
|
39716
|
+
}
|
|
39717
|
+
console.log("\nActions to apply:");
|
|
39718
|
+
console.log(` Create projects: ${createProjects.length}`);
|
|
39719
|
+
console.log(` Move sessions: ${moveSessions.length}`);
|
|
39720
|
+
console.log(` Update titles: ${updateTitles.length}`);
|
|
39721
|
+
const totalActions = createProjects.length + moveSessions.length + updateTitles.length;
|
|
39722
|
+
if (totalActions === 0) {
|
|
39723
|
+
console.log("\nNo actions to apply (filtered out or empty).");
|
|
39724
|
+
return;
|
|
39725
|
+
}
|
|
39726
|
+
if (!force) {
|
|
39727
|
+
console.log("\nThis will modify your database.");
|
|
39728
|
+
console.log("Add --force to skip this confirmation.\n");
|
|
39729
|
+
const readline3 = await import("readline");
|
|
39730
|
+
const rl = readline3.createInterface({
|
|
39731
|
+
input: process.stdin,
|
|
39732
|
+
output: process.stdout
|
|
39733
|
+
});
|
|
39734
|
+
const answer = await new Promise((resolve) => {
|
|
39735
|
+
rl.question("Apply this plan? (y/N): ", resolve);
|
|
39736
|
+
});
|
|
39737
|
+
rl.close();
|
|
39738
|
+
if (answer.toLowerCase() !== "y") {
|
|
39739
|
+
console.log("Cancelled.");
|
|
39740
|
+
return;
|
|
39741
|
+
}
|
|
39742
|
+
}
|
|
39743
|
+
const db3 = getDb();
|
|
39744
|
+
const planId = `plan-${(/* @__PURE__ */ new Date()).toISOString().slice(0, 10).replace(/-/g, "")}-${(0, import_crypto3.randomUUID)().slice(0, 6)}`;
|
|
39745
|
+
const undoActions = [];
|
|
39746
|
+
console.log(`
|
|
39747
|
+
Applying plan ${planId}...
|
|
39748
|
+
`);
|
|
39749
|
+
if (createProjects.length > 0) {
|
|
39750
|
+
console.log("Creating projects...");
|
|
39751
|
+
const insertProject = db3.prepare(`
|
|
39752
|
+
INSERT OR IGNORE INTO projects (id, provider, name, created_at)
|
|
39753
|
+
VALUES (?, 'claude', ?, datetime('now'))
|
|
39754
|
+
`);
|
|
39755
|
+
for (const p2 of createProjects) {
|
|
39756
|
+
const projectId = `proj-${p2.name.toLowerCase().replace(/\s+/g, "-")}`;
|
|
39757
|
+
try {
|
|
39758
|
+
insertProject.run(projectId, p2.name);
|
|
39759
|
+
console.log(` \u2713 Created: ${p2.name}`);
|
|
39760
|
+
undoActions.push({ type: "deleteProject", projectId, name: p2.name });
|
|
39761
|
+
} catch (err) {
|
|
39762
|
+
console.log(` \u26A0 Skipped (exists): ${p2.name}`);
|
|
39763
|
+
}
|
|
39764
|
+
}
|
|
39765
|
+
}
|
|
39766
|
+
if (moveSessions.length > 0) {
|
|
39767
|
+
console.log("\nMoving sessions...");
|
|
39768
|
+
const projectIds = /* @__PURE__ */ new Map();
|
|
39769
|
+
const projects = db3.prepare("SELECT id, name FROM projects").all();
|
|
39770
|
+
for (const p2 of projects) {
|
|
39771
|
+
projectIds.set(p2.name.toLowerCase(), p2.id);
|
|
39772
|
+
}
|
|
39773
|
+
const updateSession = db3.prepare(`
|
|
39774
|
+
UPDATE sessions SET project_id = ? WHERE id = ?
|
|
39775
|
+
`);
|
|
39776
|
+
let moved = 0;
|
|
39777
|
+
for (const m2 of moveSessions) {
|
|
39778
|
+
const projectId = projectIds.get(m2.suggestedProject.toLowerCase());
|
|
39779
|
+
if (!projectId) {
|
|
39780
|
+
console.log(` \u26A0 Project not found: ${m2.suggestedProject}`);
|
|
39781
|
+
continue;
|
|
39782
|
+
}
|
|
39783
|
+
const current = db3.prepare("SELECT project_id FROM sessions WHERE id = ?").get(m2.sessionId);
|
|
39784
|
+
try {
|
|
39785
|
+
updateSession.run(projectId, m2.sessionId);
|
|
39786
|
+
moved++;
|
|
39787
|
+
undoActions.push({
|
|
39788
|
+
type: "moveSession",
|
|
39789
|
+
sessionId: m2.sessionId,
|
|
39790
|
+
fromProject: current?.project_id,
|
|
39791
|
+
toProject: projectId
|
|
39792
|
+
});
|
|
39793
|
+
} catch (err) {
|
|
39794
|
+
console.log(` \u26A0 Failed: ${m2.sessionId} - ${err.message}`);
|
|
39795
|
+
}
|
|
39796
|
+
}
|
|
39797
|
+
console.log(` \u2713 Moved ${moved} sessions`);
|
|
39798
|
+
}
|
|
39799
|
+
if (updateTitles.length > 0) {
|
|
39800
|
+
console.log("\nUpdating titles...");
|
|
39801
|
+
const updateTitle = db3.prepare(`
|
|
39802
|
+
UPDATE sessions SET title = ?, title_override = ? WHERE id = ?
|
|
39803
|
+
`);
|
|
39804
|
+
let updated = 0;
|
|
39805
|
+
for (const t2 of updateTitles) {
|
|
39806
|
+
const current = db3.prepare("SELECT title, title_override FROM sessions WHERE id = ?").get(t2.sessionId);
|
|
39807
|
+
try {
|
|
39808
|
+
updateTitle.run(t2.suggestedTitle, t2.suggestedTitle, t2.sessionId);
|
|
39809
|
+
updated++;
|
|
39810
|
+
undoActions.push({
|
|
39811
|
+
type: "updateTitle",
|
|
39812
|
+
sessionId: t2.sessionId,
|
|
39813
|
+
fromTitle: current?.title,
|
|
39814
|
+
fromTitleOverride: current?.title_override,
|
|
39815
|
+
toTitle: t2.suggestedTitle
|
|
39816
|
+
});
|
|
39817
|
+
} catch (err) {
|
|
39818
|
+
console.log(` \u26A0 Failed: ${t2.sessionId} - ${err.message}`);
|
|
39819
|
+
}
|
|
39820
|
+
}
|
|
39821
|
+
console.log(` \u2713 Updated ${updated} titles`);
|
|
39822
|
+
}
|
|
39823
|
+
const undoDir = (0, import_path26.join)((0, import_os10.homedir)(), ".rudi", "plans");
|
|
39824
|
+
const { mkdirSync: mkdirSync5 } = await import("fs");
|
|
39825
|
+
try {
|
|
39826
|
+
mkdirSync5(undoDir, { recursive: true });
|
|
39827
|
+
} catch (e2) {
|
|
39828
|
+
}
|
|
39829
|
+
const undoFile = (0, import_path26.join)(undoDir, `${planId}.undo.json`);
|
|
39830
|
+
const undoPlan = {
|
|
39831
|
+
planId,
|
|
39832
|
+
appliedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
39833
|
+
sourceFile: planFile,
|
|
39834
|
+
actions: undoActions
|
|
39835
|
+
};
|
|
39836
|
+
(0, import_fs28.writeFileSync)(undoFile, JSON.stringify(undoPlan, null, 2));
|
|
39837
|
+
console.log("\n" + "\u2550".repeat(60));
|
|
39838
|
+
console.log("Plan applied successfully!");
|
|
39839
|
+
console.log("\u2550".repeat(60));
|
|
39840
|
+
console.log(`Plan ID: ${planId}`);
|
|
39841
|
+
console.log(`Undo file: ${undoFile}`);
|
|
39842
|
+
console.log(`
|
|
39843
|
+
To undo: rudi apply --undo ${planId}`);
|
|
39844
|
+
}
|
|
39845
|
+
|
|
39846
|
+
// src/commands/project.js
|
|
39847
|
+
async function cmdProject(args, flags) {
|
|
39848
|
+
const subcommand = args[0];
|
|
39849
|
+
switch (subcommand) {
|
|
39850
|
+
case "list":
|
|
39851
|
+
case "ls":
|
|
39852
|
+
projectList(flags);
|
|
39853
|
+
break;
|
|
39854
|
+
case "create":
|
|
39855
|
+
case "add":
|
|
39856
|
+
projectCreate(args.slice(1), flags);
|
|
39857
|
+
break;
|
|
39858
|
+
case "rename":
|
|
39859
|
+
projectRename(args.slice(1), flags);
|
|
39860
|
+
break;
|
|
39861
|
+
case "delete":
|
|
39862
|
+
case "rm":
|
|
39863
|
+
projectDelete(args.slice(1), flags);
|
|
39864
|
+
break;
|
|
39865
|
+
default:
|
|
39866
|
+
console.log(`
|
|
39867
|
+
rudi project - Manage session projects
|
|
39868
|
+
|
|
39869
|
+
COMMANDS
|
|
39870
|
+
list List all projects
|
|
39871
|
+
create <name> Create a new project
|
|
39872
|
+
rename <id> <new-name> Rename a project
|
|
39873
|
+
delete <id> Delete a project (sessions become unassigned)
|
|
39874
|
+
|
|
39875
|
+
OPTIONS
|
|
39876
|
+
--provider <name> Provider (claude, codex, gemini). Default: claude
|
|
39877
|
+
|
|
39878
|
+
EXAMPLES
|
|
39879
|
+
rudi project list
|
|
39880
|
+
rudi project create "RUDI CLI"
|
|
39881
|
+
rudi project rename proj-rudi "RUDI Tooling"
|
|
39882
|
+
rudi project delete proj-old
|
|
39883
|
+
`);
|
|
39884
|
+
}
|
|
39885
|
+
}
|
|
39886
|
+
function projectList(flags) {
|
|
39887
|
+
if (!isDatabaseInitialized()) {
|
|
39888
|
+
console.log("Database not initialized. Run: rudi db init");
|
|
39889
|
+
return;
|
|
39890
|
+
}
|
|
39891
|
+
const db3 = getDb();
|
|
39892
|
+
const provider = flags.provider;
|
|
39893
|
+
let query = `
|
|
39894
|
+
SELECT
|
|
39895
|
+
p.id, p.provider, p.name, p.color, p.created_at,
|
|
39896
|
+
COUNT(s.id) as session_count,
|
|
39897
|
+
ROUND(SUM(s.total_cost), 2) as total_cost
|
|
39898
|
+
FROM projects p
|
|
39899
|
+
LEFT JOIN sessions s ON s.project_id = p.id
|
|
39900
|
+
`;
|
|
39901
|
+
if (provider) {
|
|
39902
|
+
query += ` WHERE p.provider = '${provider}'`;
|
|
39903
|
+
}
|
|
39904
|
+
query += ` GROUP BY p.id ORDER BY total_cost DESC`;
|
|
39905
|
+
const projects = db3.prepare(query).all();
|
|
39906
|
+
if (projects.length === 0) {
|
|
39907
|
+
console.log("No projects found.");
|
|
39908
|
+
console.log('\nCreate one with: rudi project create "My Project"');
|
|
39909
|
+
return;
|
|
39910
|
+
}
|
|
39911
|
+
console.log(`
|
|
39912
|
+
Projects (${projects.length}):
|
|
39913
|
+
`);
|
|
39914
|
+
for (const p2 of projects) {
|
|
39915
|
+
console.log(`${p2.name}`);
|
|
39916
|
+
console.log(` ID: ${p2.id}`);
|
|
39917
|
+
console.log(` Provider: ${p2.provider}`);
|
|
39918
|
+
console.log(` Sessions: ${p2.session_count || 0}`);
|
|
39919
|
+
console.log(` Total cost: $${p2.total_cost || 0}`);
|
|
39920
|
+
console.log("");
|
|
39921
|
+
}
|
|
39922
|
+
}
|
|
39923
|
+
function projectCreate(args, flags) {
|
|
39924
|
+
if (!isDatabaseInitialized()) {
|
|
39925
|
+
console.log("Database not initialized. Run: rudi db init");
|
|
39926
|
+
return;
|
|
39927
|
+
}
|
|
39928
|
+
const name = args.join(" ");
|
|
39929
|
+
if (!name) {
|
|
39930
|
+
console.log("Error: Project name required");
|
|
39931
|
+
console.log('Usage: rudi project create "Project Name"');
|
|
39932
|
+
return;
|
|
39933
|
+
}
|
|
39934
|
+
const provider = flags.provider || "claude";
|
|
39935
|
+
const id = `proj-${name.toLowerCase().replace(/\s+/g, "-").replace(/[^a-z0-9-]/g, "")}`;
|
|
39936
|
+
const db3 = getDb();
|
|
39937
|
+
try {
|
|
39938
|
+
db3.prepare(`
|
|
39939
|
+
INSERT INTO projects (id, provider, name, created_at)
|
|
39940
|
+
VALUES (?, ?, ?, datetime('now'))
|
|
39941
|
+
`).run(id, provider, name);
|
|
39942
|
+
console.log(`
|
|
39943
|
+
Project created:`);
|
|
39944
|
+
console.log(` ID: ${id}`);
|
|
39945
|
+
console.log(` Name: ${name}`);
|
|
39946
|
+
console.log(` Provider: ${provider}`);
|
|
39947
|
+
} catch (err) {
|
|
39948
|
+
if (err.message.includes("UNIQUE")) {
|
|
39949
|
+
console.log(`Error: Project "${name}" already exists for ${provider}`);
|
|
39950
|
+
} else {
|
|
39951
|
+
console.log(`Error: ${err.message}`);
|
|
39952
|
+
}
|
|
39953
|
+
}
|
|
39954
|
+
}
|
|
39955
|
+
function projectRename(args, flags) {
|
|
39956
|
+
if (!isDatabaseInitialized()) {
|
|
39957
|
+
console.log("Database not initialized.");
|
|
39958
|
+
return;
|
|
39959
|
+
}
|
|
39960
|
+
const [id, ...nameParts] = args;
|
|
39961
|
+
const newName = nameParts.join(" ");
|
|
39962
|
+
if (!id || !newName) {
|
|
39963
|
+
console.log("Error: Project ID and new name required");
|
|
39964
|
+
console.log('Usage: rudi project rename <id> "New Name"');
|
|
39965
|
+
return;
|
|
39966
|
+
}
|
|
39967
|
+
const db3 = getDb();
|
|
39968
|
+
const result = db3.prepare("UPDATE projects SET name = ? WHERE id = ?").run(newName, id);
|
|
39969
|
+
if (result.changes === 0) {
|
|
39970
|
+
console.log(`Project not found: ${id}`);
|
|
39971
|
+
return;
|
|
39972
|
+
}
|
|
39973
|
+
console.log(`
|
|
39974
|
+
Project renamed to: ${newName}`);
|
|
39975
|
+
}
|
|
39976
|
+
function projectDelete(args, flags) {
|
|
39977
|
+
if (!isDatabaseInitialized()) {
|
|
39978
|
+
console.log("Database not initialized.");
|
|
39979
|
+
return;
|
|
39980
|
+
}
|
|
39981
|
+
const id = args[0];
|
|
39982
|
+
if (!id) {
|
|
39983
|
+
console.log("Error: Project ID required");
|
|
39984
|
+
console.log("Usage: rudi project delete <id>");
|
|
39985
|
+
return;
|
|
39986
|
+
}
|
|
39987
|
+
const db3 = getDb();
|
|
39988
|
+
const project = db3.prepare("SELECT name FROM projects WHERE id = ?").get(id);
|
|
39989
|
+
if (!project) {
|
|
39990
|
+
console.log(`Project not found: ${id}`);
|
|
39991
|
+
return;
|
|
39992
|
+
}
|
|
39993
|
+
const sessionsResult = db3.prepare("UPDATE sessions SET project_id = NULL WHERE project_id = ?").run(id);
|
|
39994
|
+
db3.prepare("DELETE FROM projects WHERE id = ?").run(id);
|
|
39995
|
+
console.log(`
|
|
39996
|
+
Project deleted: ${project.name}`);
|
|
39997
|
+
if (sessionsResult.changes > 0) {
|
|
39998
|
+
console.log(`Unassigned ${sessionsResult.changes} sessions`);
|
|
39999
|
+
}
|
|
40000
|
+
}
|
|
40001
|
+
|
|
39259
40002
|
// src/index.js
|
|
39260
40003
|
var VERSION2 = "2.0.0";
|
|
39261
40004
|
async function main() {
|
|
@@ -39306,6 +40049,13 @@ async function main() {
|
|
|
39306
40049
|
case "import":
|
|
39307
40050
|
await cmdImport(args, flags);
|
|
39308
40051
|
break;
|
|
40052
|
+
case "apply":
|
|
40053
|
+
await cmdApply(args, flags);
|
|
40054
|
+
break;
|
|
40055
|
+
case "project":
|
|
40056
|
+
case "projects":
|
|
40057
|
+
await cmdProject(args, flags);
|
|
40058
|
+
break;
|
|
39309
40059
|
case "doctor":
|
|
39310
40060
|
await cmdDoctor(args, flags);
|
|
39311
40061
|
break;
|