@learnrudi/cli 1.8.7 → 1.9.0
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/index.cjs +180 -2
- package/package.json +1 -1
- package/scripts/postinstall.js +243 -13
package/dist/index.cjs
CHANGED
|
@@ -245,10 +245,29 @@ function validateStackEntryPoint(stackPath, manifest) {
|
|
|
245
245
|
if (!command || command.length === 0) {
|
|
246
246
|
return { valid: false, error: "No command defined in manifest" };
|
|
247
247
|
}
|
|
248
|
-
const
|
|
248
|
+
const skipCommands = [
|
|
249
|
+
"node",
|
|
250
|
+
"python",
|
|
251
|
+
"python3",
|
|
252
|
+
"npx",
|
|
253
|
+
"deno",
|
|
254
|
+
"bun",
|
|
255
|
+
"tsx",
|
|
256
|
+
"ts-node",
|
|
257
|
+
"tsm",
|
|
258
|
+
"esno",
|
|
259
|
+
"esbuild-register",
|
|
260
|
+
// TypeScript runners
|
|
261
|
+
"-y",
|
|
262
|
+
"--yes"
|
|
263
|
+
// npx flags
|
|
264
|
+
];
|
|
265
|
+
const fileExtensions = [".js", ".ts", ".mjs", ".cjs", ".py", ".mts", ".cts"];
|
|
249
266
|
for (const arg of command) {
|
|
250
|
-
if (
|
|
267
|
+
if (skipCommands.includes(arg)) continue;
|
|
251
268
|
if (arg.startsWith("-")) continue;
|
|
269
|
+
const looksLikeFile = fileExtensions.some((ext) => arg.endsWith(ext)) || arg.includes("/");
|
|
270
|
+
if (!looksLikeFile) continue;
|
|
252
271
|
const entryPath = require("path").join(stackPath, arg);
|
|
253
272
|
if (!require("fs").existsSync(entryPath)) {
|
|
254
273
|
return { valid: false, error: `Entry point not found: ${arg}` };
|
|
@@ -403,6 +422,18 @@ Installing...`);
|
|
|
403
422
|
console.error(` rudi install ${result.id}`);
|
|
404
423
|
process.exit(1);
|
|
405
424
|
}
|
|
425
|
+
try {
|
|
426
|
+
(0, import_core2.addStack)(result.id, {
|
|
427
|
+
path: result.path,
|
|
428
|
+
runtime: manifest.runtime || manifest.mcp?.runtime || "node",
|
|
429
|
+
command: manifest.command || (manifest.mcp?.command ? [manifest.mcp.command, ...manifest.mcp.args || []] : null),
|
|
430
|
+
secrets: getManifestSecrets(manifest),
|
|
431
|
+
version: manifest.version
|
|
432
|
+
});
|
|
433
|
+
console.log(` \u2713 Updated rudi.json`);
|
|
434
|
+
} catch (err) {
|
|
435
|
+
console.log(` \u26A0 Failed to update rudi.json: ${err.message}`);
|
|
436
|
+
}
|
|
406
437
|
const { found, missing } = await checkSecrets(manifest);
|
|
407
438
|
const envExampleKeys = await parseEnvExample(result.path);
|
|
408
439
|
for (const key of envExampleKeys) {
|
|
@@ -421,6 +452,16 @@ Installing...`);
|
|
|
421
452
|
if (existing === null) {
|
|
422
453
|
await (0, import_secrets.setSecret)(key, "");
|
|
423
454
|
}
|
|
455
|
+
try {
|
|
456
|
+
(0, import_core2.updateSecretStatus)(key, false);
|
|
457
|
+
} catch {
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
for (const key of found) {
|
|
462
|
+
try {
|
|
463
|
+
(0, import_core2.updateSecretStatus)(key, true);
|
|
464
|
+
} catch {
|
|
424
465
|
}
|
|
425
466
|
}
|
|
426
467
|
console.log(`
|
|
@@ -3672,6 +3713,140 @@ async function migrateConfigs(flags) {
|
|
|
3672
3713
|
console.log("Restart your agents to use the updated configs.");
|
|
3673
3714
|
}
|
|
3674
3715
|
|
|
3716
|
+
// src/commands/index-tools.js
|
|
3717
|
+
var import_core10 = require("@learnrudi/core");
|
|
3718
|
+
var import_core11 = require("@learnrudi/core");
|
|
3719
|
+
async function cmdIndex(args, flags) {
|
|
3720
|
+
const stackFilter = args.length > 0 ? args : null;
|
|
3721
|
+
const forceReindex = flags.force || false;
|
|
3722
|
+
const jsonOutput = flags.json || false;
|
|
3723
|
+
const config = (0, import_core11.readRudiConfig)();
|
|
3724
|
+
if (!config) {
|
|
3725
|
+
console.error("Error: rudi.json not found. Run `rudi doctor` to check setup.");
|
|
3726
|
+
process.exit(1);
|
|
3727
|
+
}
|
|
3728
|
+
const installedStacks = Object.keys(config.stacks || {}).filter(
|
|
3729
|
+
(id) => config.stacks[id].installed
|
|
3730
|
+
);
|
|
3731
|
+
if (installedStacks.length === 0) {
|
|
3732
|
+
if (jsonOutput) {
|
|
3733
|
+
console.log(JSON.stringify({ indexed: 0, failed: 0, stacks: [] }));
|
|
3734
|
+
} else {
|
|
3735
|
+
console.log("No installed stacks to index.");
|
|
3736
|
+
console.log("\nInstall stacks with: rudi install <stack>");
|
|
3737
|
+
}
|
|
3738
|
+
return;
|
|
3739
|
+
}
|
|
3740
|
+
const stacksToIndex = stackFilter ? stackFilter.filter((id) => {
|
|
3741
|
+
if (!installedStacks.includes(id)) {
|
|
3742
|
+
if (!jsonOutput) {
|
|
3743
|
+
console.log(`\u26A0 Stack not installed: ${id}`);
|
|
3744
|
+
}
|
|
3745
|
+
return false;
|
|
3746
|
+
}
|
|
3747
|
+
return true;
|
|
3748
|
+
}) : installedStacks;
|
|
3749
|
+
if (stacksToIndex.length === 0) {
|
|
3750
|
+
if (jsonOutput) {
|
|
3751
|
+
console.log(JSON.stringify({ indexed: 0, failed: 0, stacks: [] }));
|
|
3752
|
+
} else {
|
|
3753
|
+
console.log("No valid stacks to index.");
|
|
3754
|
+
}
|
|
3755
|
+
return;
|
|
3756
|
+
}
|
|
3757
|
+
const existingIndex = (0, import_core10.readToolIndex)();
|
|
3758
|
+
if (existingIndex && !forceReindex && !stackFilter) {
|
|
3759
|
+
const allCached = stacksToIndex.every((id) => {
|
|
3760
|
+
const entry = existingIndex.byStack?.[id];
|
|
3761
|
+
return entry && entry.tools && entry.tools.length > 0 && !entry.error;
|
|
3762
|
+
});
|
|
3763
|
+
if (allCached) {
|
|
3764
|
+
const totalTools = stacksToIndex.reduce((sum, id) => {
|
|
3765
|
+
return sum + (existingIndex.byStack[id]?.tools?.length || 0);
|
|
3766
|
+
}, 0);
|
|
3767
|
+
if (jsonOutput) {
|
|
3768
|
+
console.log(JSON.stringify({
|
|
3769
|
+
indexed: stacksToIndex.length,
|
|
3770
|
+
failed: 0,
|
|
3771
|
+
cached: true,
|
|
3772
|
+
totalTools,
|
|
3773
|
+
stacks: stacksToIndex.map((id) => ({
|
|
3774
|
+
id,
|
|
3775
|
+
tools: existingIndex.byStack[id]?.tools?.length || 0,
|
|
3776
|
+
indexedAt: existingIndex.byStack[id]?.indexedAt
|
|
3777
|
+
}))
|
|
3778
|
+
}));
|
|
3779
|
+
} else {
|
|
3780
|
+
console.log(`Tool index is up to date (${totalTools} tools from ${stacksToIndex.length} stacks)`);
|
|
3781
|
+
console.log(`Last updated: ${existingIndex.updatedAt}`);
|
|
3782
|
+
console.log(`
|
|
3783
|
+
Use --force to re-index.`);
|
|
3784
|
+
}
|
|
3785
|
+
return;
|
|
3786
|
+
}
|
|
3787
|
+
}
|
|
3788
|
+
if (!jsonOutput) {
|
|
3789
|
+
console.log(`Indexing ${stacksToIndex.length} stack(s)...
|
|
3790
|
+
`);
|
|
3791
|
+
}
|
|
3792
|
+
const log = jsonOutput ? () => {
|
|
3793
|
+
} : console.log;
|
|
3794
|
+
try {
|
|
3795
|
+
const result = await (0, import_core10.indexAllStacks)({
|
|
3796
|
+
stacks: stacksToIndex,
|
|
3797
|
+
log,
|
|
3798
|
+
timeout: 2e4
|
|
3799
|
+
// 20s per stack
|
|
3800
|
+
});
|
|
3801
|
+
const totalTools = Object.values(result.index.byStack).reduce(
|
|
3802
|
+
(sum, entry) => sum + (entry.tools?.length || 0),
|
|
3803
|
+
0
|
|
3804
|
+
);
|
|
3805
|
+
if (jsonOutput) {
|
|
3806
|
+
console.log(JSON.stringify({
|
|
3807
|
+
indexed: result.indexed,
|
|
3808
|
+
failed: result.failed,
|
|
3809
|
+
totalTools,
|
|
3810
|
+
stacks: stacksToIndex.map((id) => ({
|
|
3811
|
+
id,
|
|
3812
|
+
tools: result.index.byStack[id]?.tools?.length || 0,
|
|
3813
|
+
error: result.index.byStack[id]?.error || null,
|
|
3814
|
+
missingSecrets: result.index.byStack[id]?.missingSecrets || null
|
|
3815
|
+
}))
|
|
3816
|
+
}, null, 2));
|
|
3817
|
+
} else {
|
|
3818
|
+
console.log(`
|
|
3819
|
+
${"\u2500".repeat(50)}`);
|
|
3820
|
+
console.log(`Indexed: ${result.indexed}/${stacksToIndex.length} stacks`);
|
|
3821
|
+
console.log(`Tools discovered: ${totalTools}`);
|
|
3822
|
+
console.log(`Cache: ${import_core10.TOOL_INDEX_PATH}`);
|
|
3823
|
+
if (result.failed > 0) {
|
|
3824
|
+
console.log(`
|
|
3825
|
+
\u26A0 ${result.failed} stack(s) failed to index.`);
|
|
3826
|
+
const missingSecretStacks = Object.entries(result.index.byStack).filter(([_, entry]) => entry.missingSecrets?.length > 0);
|
|
3827
|
+
if (missingSecretStacks.length > 0) {
|
|
3828
|
+
console.log(`
|
|
3829
|
+
Missing secrets:`);
|
|
3830
|
+
for (const [stackId, entry] of missingSecretStacks) {
|
|
3831
|
+
for (const secret of entry.missingSecrets) {
|
|
3832
|
+
console.log(` rudi secrets set ${secret}`);
|
|
3833
|
+
}
|
|
3834
|
+
}
|
|
3835
|
+
console.log(`
|
|
3836
|
+
After configuring secrets, run: rudi index`);
|
|
3837
|
+
}
|
|
3838
|
+
}
|
|
3839
|
+
}
|
|
3840
|
+
} catch (error) {
|
|
3841
|
+
if (jsonOutput) {
|
|
3842
|
+
console.log(JSON.stringify({ error: error.message }));
|
|
3843
|
+
} else {
|
|
3844
|
+
console.error(`Index failed: ${error.message}`);
|
|
3845
|
+
}
|
|
3846
|
+
process.exit(1);
|
|
3847
|
+
}
|
|
3848
|
+
}
|
|
3849
|
+
|
|
3675
3850
|
// src/index.js
|
|
3676
3851
|
var VERSION = "2.0.0";
|
|
3677
3852
|
async function main() {
|
|
@@ -3753,6 +3928,9 @@ async function main() {
|
|
|
3753
3928
|
case "migrate":
|
|
3754
3929
|
await cmdMigrate(args, flags);
|
|
3755
3930
|
break;
|
|
3931
|
+
case "index":
|
|
3932
|
+
await cmdIndex(args, flags);
|
|
3933
|
+
break;
|
|
3756
3934
|
case "home":
|
|
3757
3935
|
case "status":
|
|
3758
3936
|
await cmdHome(args, flags);
|
package/package.json
CHANGED
package/scripts/postinstall.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* 1. Node.js runtime → ~/.rudi/runtimes/node/
|
|
7
7
|
* 2. Python runtime → ~/.rudi/runtimes/python/
|
|
8
8
|
* 3. Creates shims → ~/.rudi/shims/
|
|
9
|
+
* 4. Initializes rudi.json → ~/.rudi/rudi.json
|
|
9
10
|
*/
|
|
10
11
|
|
|
11
12
|
import { execSync } from 'child_process';
|
|
@@ -14,8 +15,131 @@ import * as path from 'path';
|
|
|
14
15
|
import * as os from 'os';
|
|
15
16
|
|
|
16
17
|
const RUDI_HOME = path.join(os.homedir(), '.rudi');
|
|
18
|
+
const RUDI_JSON_PATH = path.join(RUDI_HOME, 'rudi.json');
|
|
19
|
+
const RUDI_JSON_TMP = path.join(RUDI_HOME, 'rudi.json.tmp');
|
|
17
20
|
const REGISTRY_BASE = 'https://raw.githubusercontent.com/learn-rudi/registry/main';
|
|
18
21
|
|
|
22
|
+
// =============================================================================
|
|
23
|
+
// RUDI.JSON CONFIG MANAGEMENT
|
|
24
|
+
// =============================================================================
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Create a new empty RudiConfig
|
|
28
|
+
*/
|
|
29
|
+
function createRudiConfig() {
|
|
30
|
+
const now = new Date().toISOString();
|
|
31
|
+
return {
|
|
32
|
+
version: '1.0.0',
|
|
33
|
+
schemaVersion: 1,
|
|
34
|
+
installed: false,
|
|
35
|
+
installedAt: now,
|
|
36
|
+
updatedAt: now,
|
|
37
|
+
runtimes: {},
|
|
38
|
+
stacks: {},
|
|
39
|
+
binaries: {},
|
|
40
|
+
secrets: {}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Read rudi.json
|
|
46
|
+
*/
|
|
47
|
+
function readRudiConfig() {
|
|
48
|
+
try {
|
|
49
|
+
const content = fs.readFileSync(RUDI_JSON_PATH, 'utf-8');
|
|
50
|
+
return JSON.parse(content);
|
|
51
|
+
} catch (err) {
|
|
52
|
+
if (err.code === 'ENOENT') {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
console.log(` ⚠ Failed to read rudi.json: ${err.message}`);
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Write rudi.json atomically with secure permissions
|
|
62
|
+
*/
|
|
63
|
+
function writeRudiConfig(config) {
|
|
64
|
+
config.updatedAt = new Date().toISOString();
|
|
65
|
+
const content = JSON.stringify(config, null, 2);
|
|
66
|
+
|
|
67
|
+
// Write to temp file
|
|
68
|
+
fs.writeFileSync(RUDI_JSON_TMP, content, { mode: 0o600 });
|
|
69
|
+
|
|
70
|
+
// Atomic rename
|
|
71
|
+
fs.renameSync(RUDI_JSON_TMP, RUDI_JSON_PATH);
|
|
72
|
+
|
|
73
|
+
// Ensure permissions (rename may not preserve them)
|
|
74
|
+
fs.chmodSync(RUDI_JSON_PATH, 0o600);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Initialize rudi.json if it doesn't exist
|
|
79
|
+
*/
|
|
80
|
+
function initRudiConfig() {
|
|
81
|
+
if (fs.existsSync(RUDI_JSON_PATH)) {
|
|
82
|
+
console.log(` ✓ rudi.json already exists`);
|
|
83
|
+
return readRudiConfig();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const config = createRudiConfig();
|
|
87
|
+
writeRudiConfig(config);
|
|
88
|
+
console.log(` ✓ Created rudi.json`);
|
|
89
|
+
return config;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Update rudi.json with runtime info after successful download
|
|
94
|
+
*/
|
|
95
|
+
function updateRudiConfigRuntime(runtimeId, runtimePath, version) {
|
|
96
|
+
const config = readRudiConfig() || createRudiConfig();
|
|
97
|
+
const platform = process.platform;
|
|
98
|
+
|
|
99
|
+
let bin;
|
|
100
|
+
if (runtimeId === 'node') {
|
|
101
|
+
bin = platform === 'win32' ? 'node.exe' : 'bin/node';
|
|
102
|
+
} else if (runtimeId === 'python') {
|
|
103
|
+
bin = platform === 'win32' ? 'python.exe' : 'bin/python3';
|
|
104
|
+
} else {
|
|
105
|
+
bin = runtimeId;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
config.runtimes[runtimeId] = {
|
|
109
|
+
path: runtimePath,
|
|
110
|
+
bin: path.join(runtimePath, bin),
|
|
111
|
+
version: version
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
writeRudiConfig(config);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Update rudi.json with binary info after successful download
|
|
119
|
+
*/
|
|
120
|
+
function updateRudiConfigBinary(binaryName, binaryPath, version) {
|
|
121
|
+
const config = readRudiConfig() || createRudiConfig();
|
|
122
|
+
|
|
123
|
+
config.binaries[binaryName] = {
|
|
124
|
+
path: binaryPath,
|
|
125
|
+
bin: path.join(binaryPath, binaryName),
|
|
126
|
+
version: version,
|
|
127
|
+
installed: true,
|
|
128
|
+
installedAt: new Date().toISOString()
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
writeRudiConfig(config);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Mark rudi.json as fully installed
|
|
136
|
+
*/
|
|
137
|
+
function markRudiConfigInstalled() {
|
|
138
|
+
const config = readRudiConfig() || createRudiConfig();
|
|
139
|
+
config.installed = true;
|
|
140
|
+
writeRudiConfig(config);
|
|
141
|
+
}
|
|
142
|
+
|
|
19
143
|
// Detect platform
|
|
20
144
|
function getPlatformArch() {
|
|
21
145
|
const platform = process.platform;
|
|
@@ -110,29 +234,115 @@ async function downloadRuntime(runtimeId, platformArch) {
|
|
|
110
234
|
// Skip if already installed
|
|
111
235
|
if (fs.existsSync(binaryPath)) {
|
|
112
236
|
console.log(` ✓ ${manifest.name} already installed`);
|
|
237
|
+
// Still update rudi.json in case it's missing this runtime
|
|
238
|
+
updateRudiConfigRuntime(runtimeId, destDir, manifest.version);
|
|
113
239
|
return true;
|
|
114
240
|
}
|
|
115
241
|
|
|
116
|
-
|
|
242
|
+
const success = await downloadAndExtract(downloadUrl, destDir, manifest.name);
|
|
243
|
+
if (success) {
|
|
244
|
+
// Update rudi.json with runtime info
|
|
245
|
+
updateRudiConfigRuntime(runtimeId, destDir, manifest.version);
|
|
246
|
+
}
|
|
247
|
+
return success;
|
|
117
248
|
} catch (error) {
|
|
118
249
|
console.log(` ⚠ Failed to fetch ${runtimeId} manifest: ${error.message}`);
|
|
119
250
|
return false;
|
|
120
251
|
}
|
|
121
252
|
}
|
|
122
253
|
|
|
123
|
-
// Create
|
|
124
|
-
function
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
const
|
|
254
|
+
// Create all shims
|
|
255
|
+
function createShims() {
|
|
256
|
+
// Legacy shim for direct stack access: rudi-mcp <stack>
|
|
257
|
+
const mcpShimPath = path.join(RUDI_HOME, 'shims', 'rudi-mcp');
|
|
258
|
+
const mcpShimContent = `#!/bin/bash
|
|
128
259
|
# RUDI MCP Shim - Routes agent calls to rudi mcp command
|
|
129
260
|
# Usage: rudi-mcp <stack-name>
|
|
130
261
|
exec rudi mcp "$@"
|
|
262
|
+
`;
|
|
263
|
+
fs.writeFileSync(mcpShimPath, mcpShimContent);
|
|
264
|
+
fs.chmodSync(mcpShimPath, 0o755);
|
|
265
|
+
console.log(` ✓ Created rudi-mcp shim`);
|
|
266
|
+
|
|
267
|
+
// New router shim: Master MCP server that aggregates all stacks
|
|
268
|
+
const routerShimPath = path.join(RUDI_HOME, 'shims', 'rudi-router');
|
|
269
|
+
const routerShimContent = `#!/bin/bash
|
|
270
|
+
# RUDI Router - Master MCP server for all installed stacks
|
|
271
|
+
# Reads ~/.rudi/rudi.json and proxies tool calls to correct stack
|
|
272
|
+
# Usage: Point agent config to this shim (no args needed)
|
|
273
|
+
|
|
274
|
+
RUDI_HOME="$HOME/.rudi"
|
|
275
|
+
|
|
276
|
+
# Use bundled Node if available
|
|
277
|
+
if [ -x "$RUDI_HOME/runtimes/node/bin/node" ]; then
|
|
278
|
+
exec "$RUDI_HOME/runtimes/node/bin/node" "$RUDI_HOME/router/router-mcp.js" "$@"
|
|
279
|
+
else
|
|
280
|
+
exec node "$RUDI_HOME/router/router-mcp.js" "$@"
|
|
281
|
+
fi
|
|
282
|
+
`;
|
|
283
|
+
fs.writeFileSync(routerShimPath, routerShimContent);
|
|
284
|
+
fs.chmodSync(routerShimPath, 0o755);
|
|
285
|
+
console.log(` ✓ Created rudi-router shim`);
|
|
286
|
+
|
|
287
|
+
// Create router directory for the router-mcp.js file
|
|
288
|
+
const routerDir = path.join(RUDI_HOME, 'router');
|
|
289
|
+
if (!fs.existsSync(routerDir)) {
|
|
290
|
+
fs.mkdirSync(routerDir, { recursive: true });
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// Create package.json for ES module support
|
|
294
|
+
const routerPackageJson = path.join(routerDir, 'package.json');
|
|
295
|
+
fs.writeFileSync(routerPackageJson, JSON.stringify({
|
|
296
|
+
name: 'rudi-router',
|
|
297
|
+
type: 'module',
|
|
298
|
+
private: true
|
|
299
|
+
}, null, 2));
|
|
300
|
+
|
|
301
|
+
// Copy router-mcp.js to ~/.rudi/router/
|
|
302
|
+
copyRouterMcp();
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Copy router-mcp.js to ~/.rudi/router/
|
|
307
|
+
* Looks for the file relative to this script's location
|
|
308
|
+
*/
|
|
309
|
+
function copyRouterMcp() {
|
|
310
|
+
const routerDir = path.join(RUDI_HOME, 'router');
|
|
311
|
+
const destPath = path.join(routerDir, 'router-mcp.js');
|
|
312
|
+
|
|
313
|
+
// Try multiple possible source locations
|
|
314
|
+
const possibleSources = [
|
|
315
|
+
// When running from npm install (scripts dir)
|
|
316
|
+
path.join(path.dirname(process.argv[1]), '..', 'src', 'router-mcp.js'),
|
|
317
|
+
// When running from npm link or local dev
|
|
318
|
+
path.join(path.dirname(process.argv[1]), '..', 'dist', 'router-mcp.js'),
|
|
319
|
+
// Relative to this script
|
|
320
|
+
path.resolve(import.meta.url.replace('file://', '').replace('/scripts/postinstall.js', ''), 'src', 'router-mcp.js'),
|
|
321
|
+
];
|
|
322
|
+
|
|
323
|
+
for (const srcPath of possibleSources) {
|
|
324
|
+
try {
|
|
325
|
+
if (fs.existsSync(srcPath)) {
|
|
326
|
+
fs.copyFileSync(srcPath, destPath);
|
|
327
|
+
console.log(` ✓ Installed router-mcp.js`);
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
} catch {
|
|
331
|
+
// Try next path
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
// Create a minimal placeholder if source not found
|
|
336
|
+
// This will be updated on next CLI update
|
|
337
|
+
const placeholderContent = `#!/usr/bin/env node
|
|
338
|
+
// RUDI Router MCP Server - Placeholder
|
|
339
|
+
// This file should be replaced by the actual router-mcp.js from @learnrudi/cli
|
|
340
|
+
console.error('[rudi-router] Router not properly installed. Run: npm update -g @learnrudi/cli');
|
|
341
|
+
process.exit(1);
|
|
131
342
|
`;
|
|
132
343
|
|
|
133
|
-
fs.writeFileSync(
|
|
134
|
-
|
|
135
|
-
console.log(` ✓ Created shim at ${shimPath}`);
|
|
344
|
+
fs.writeFileSync(destPath, placeholderContent, { mode: 0o755 });
|
|
345
|
+
console.log(` ⚠ Created router placeholder (will be updated on next CLI install)`);
|
|
136
346
|
}
|
|
137
347
|
|
|
138
348
|
// Initialize secrets file with secure permissions
|
|
@@ -185,10 +395,17 @@ async function downloadBinary(binaryName, platformArch) {
|
|
|
185
395
|
// Skip if already installed
|
|
186
396
|
if (fs.existsSync(binaryPath)) {
|
|
187
397
|
console.log(` ✓ ${manifest.name || binaryName} already installed`);
|
|
398
|
+
// Still update rudi.json in case it's missing this binary
|
|
399
|
+
updateRudiConfigBinary(binaryName, destDir, manifest.version);
|
|
188
400
|
return true;
|
|
189
401
|
}
|
|
190
402
|
|
|
191
|
-
|
|
403
|
+
const success = await downloadAndExtract(upstream, destDir, manifest.name || binaryName);
|
|
404
|
+
if (success) {
|
|
405
|
+
// Update rudi.json with binary info
|
|
406
|
+
updateRudiConfigBinary(binaryName, destDir, manifest.version);
|
|
407
|
+
}
|
|
408
|
+
return success;
|
|
192
409
|
} catch (error) {
|
|
193
410
|
console.log(` ⚠ Failed to fetch ${binaryName} manifest: ${error.message}`);
|
|
194
411
|
return false;
|
|
@@ -220,6 +437,12 @@ async function setup() {
|
|
|
220
437
|
// Check if already initialized (by Studio or previous install)
|
|
221
438
|
if (isRudiInitialized()) {
|
|
222
439
|
console.log('✓ RUDI already initialized');
|
|
440
|
+
// Still init rudi.json in case it's missing (migration from older version)
|
|
441
|
+
console.log('\nUpdating configuration...');
|
|
442
|
+
initRudiConfig();
|
|
443
|
+
// Ensure shims are up to date
|
|
444
|
+
console.log('\nUpdating shims...');
|
|
445
|
+
createShims();
|
|
223
446
|
console.log(' Skipping runtime and binary downloads\n');
|
|
224
447
|
console.log('Run `rudi doctor` to check system health\n');
|
|
225
448
|
return;
|
|
@@ -229,8 +452,12 @@ async function setup() {
|
|
|
229
452
|
ensureDirectories();
|
|
230
453
|
console.log('✓ Created ~/.rudi directory structure\n');
|
|
231
454
|
|
|
455
|
+
// Initialize rudi.json (single source of truth)
|
|
456
|
+
console.log('Initializing configuration...');
|
|
457
|
+
initRudiConfig();
|
|
458
|
+
|
|
232
459
|
// Download runtimes from registry manifests
|
|
233
|
-
console.log('
|
|
460
|
+
console.log('\nInstalling runtimes...');
|
|
234
461
|
await downloadRuntime('node', platformArch);
|
|
235
462
|
await downloadRuntime('python', platformArch);
|
|
236
463
|
|
|
@@ -239,9 +466,9 @@ async function setup() {
|
|
|
239
466
|
await downloadBinary('sqlite', platformArch);
|
|
240
467
|
await downloadBinary('ripgrep', platformArch);
|
|
241
468
|
|
|
242
|
-
// Create
|
|
469
|
+
// Create shims (rudi-mcp for direct access, rudi-router for aggregated MCP)
|
|
243
470
|
console.log('\nSetting up shims...');
|
|
244
|
-
|
|
471
|
+
createShims();
|
|
245
472
|
|
|
246
473
|
// Initialize secrets
|
|
247
474
|
initSecrets();
|
|
@@ -250,6 +477,9 @@ async function setup() {
|
|
|
250
477
|
console.log('\nInitializing database...');
|
|
251
478
|
initDatabase();
|
|
252
479
|
|
|
480
|
+
// Mark config as fully installed
|
|
481
|
+
markRudiConfigInstalled();
|
|
482
|
+
|
|
253
483
|
console.log('\n✓ RUDI setup complete!\n');
|
|
254
484
|
console.log('Get started:');
|
|
255
485
|
console.log(' rudi search --all # See available stacks');
|