@cortex-context/cli 0.0.14 → 0.0.16
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.js
CHANGED
|
@@ -18227,94 +18227,65 @@ var import_child_process = require("child_process");
|
|
|
18227
18227
|
var import_fs5 = require("fs");
|
|
18228
18228
|
var import_path5 = require("path");
|
|
18229
18229
|
var import_os3 = require("os");
|
|
18230
|
-
function
|
|
18230
|
+
function isLxcEnvironment() {
|
|
18231
|
+
if ((0, import_os3.platform)() !== "linux") return false;
|
|
18231
18232
|
try {
|
|
18232
|
-
(0,
|
|
18233
|
-
|
|
18234
|
-
});
|
|
18235
|
-
return { applied: true };
|
|
18233
|
+
const environ = (0, import_fs5.readFileSync)("/proc/1/environ", "utf-8");
|
|
18234
|
+
if (environ.includes("container=lxc")) return true;
|
|
18236
18235
|
} catch {
|
|
18237
|
-
return { applied: false };
|
|
18238
18236
|
}
|
|
18239
|
-
}
|
|
18240
|
-
function tryConfigureCrunRuntime() {
|
|
18241
|
-
const result = {
|
|
18242
|
-
attempted: false,
|
|
18243
|
-
crunInstalled: false,
|
|
18244
|
-
daemonUpdated: false,
|
|
18245
|
-
dockerRestarted: false
|
|
18246
|
-
};
|
|
18247
|
-
if ((0, import_os3.platform)() !== "linux") return result;
|
|
18248
|
-
result.attempted = true;
|
|
18249
|
-
const hasCrun = (() => {
|
|
18250
|
-
try {
|
|
18251
|
-
(0, import_child_process.execSync)("which crun", { stdio: "ignore" });
|
|
18252
|
-
return true;
|
|
18253
|
-
} catch {
|
|
18254
|
-
return false;
|
|
18255
|
-
}
|
|
18256
|
-
})();
|
|
18257
|
-
if (hasCrun) {
|
|
18258
|
-
result.crunInstalled = true;
|
|
18259
|
-
} else {
|
|
18260
|
-
try {
|
|
18261
|
-
(0, import_child_process.execSync)("apt-get install -y crun", { stdio: "ignore" });
|
|
18262
|
-
result.crunInstalled = true;
|
|
18263
|
-
} catch (e) {
|
|
18264
|
-
result.error = `crun install: ${e instanceof Error ? e.message : String(e)}`;
|
|
18265
|
-
return result;
|
|
18266
|
-
}
|
|
18267
|
-
}
|
|
18268
|
-
const daemonPath = "/etc/docker/daemon.json";
|
|
18269
|
-
let cfg = {};
|
|
18270
18237
|
try {
|
|
18271
|
-
|
|
18272
|
-
|
|
18273
|
-
|
|
18238
|
+
const virt = (0, import_child_process.execSync)("systemd-detect-virt 2>/dev/null", {
|
|
18239
|
+
encoding: "utf-8",
|
|
18240
|
+
stdio: ["pipe", "pipe", "ignore"],
|
|
18241
|
+
timeout: 1e3
|
|
18242
|
+
}).trim();
|
|
18243
|
+
if (virt === "lxc" || virt === "lxc-libvirt") return true;
|
|
18274
18244
|
} catch {
|
|
18275
|
-
cfg = {};
|
|
18276
|
-
}
|
|
18277
|
-
if (cfg["default-runtime"] === "crun") {
|
|
18278
|
-
result.daemonUpdated = true;
|
|
18279
|
-
result.dockerRestarted = true;
|
|
18280
|
-
return result;
|
|
18281
18245
|
}
|
|
18282
|
-
const runtimes = cfg["runtimes"] ?? {};
|
|
18283
|
-
runtimes["crun"] = { path: "/usr/bin/crun" };
|
|
18284
|
-
cfg["runtimes"] = runtimes;
|
|
18285
|
-
cfg["default-runtime"] = "crun";
|
|
18286
18246
|
try {
|
|
18287
|
-
(0, import_fs5.
|
|
18288
|
-
|
|
18289
|
-
} catch
|
|
18290
|
-
result.error = `daemon.json: ${e instanceof Error ? e.message : String(e)}`;
|
|
18291
|
-
return result;
|
|
18292
|
-
}
|
|
18293
|
-
try {
|
|
18294
|
-
(0, import_child_process.execSync)("systemctl restart docker", { stdio: "ignore" });
|
|
18295
|
-
result.dockerRestarted = true;
|
|
18296
|
-
} catch (e) {
|
|
18297
|
-
result.error = `docker restart: ${e instanceof Error ? e.message : String(e)}`;
|
|
18247
|
+
const cgroup = (0, import_fs5.readFileSync)("/proc/1/cgroup", "utf-8");
|
|
18248
|
+
if (/\/lxc\//.test(cgroup)) return true;
|
|
18249
|
+
} catch {
|
|
18298
18250
|
}
|
|
18299
|
-
return
|
|
18251
|
+
return false;
|
|
18300
18252
|
}
|
|
18301
18253
|
async function deployLocalStack(workspacePath, opts = {}) {
|
|
18302
|
-
const
|
|
18303
|
-
|
|
18304
|
-
|
|
18305
|
-
"local",
|
|
18306
|
-
"docker-compose.local.yml"
|
|
18307
|
-
);
|
|
18254
|
+
const lxc = isLxcEnvironment();
|
|
18255
|
+
const templateFile = lxc ? "docker-compose.host-network.yml" : "docker-compose.local.yml";
|
|
18256
|
+
const templatePath = (0, import_path5.join)(__dirname, "templates", "local", templateFile);
|
|
18308
18257
|
const destPath = (0, import_path5.join)(workspacePath, "docker-compose.local.yml");
|
|
18309
18258
|
if (!(0, import_fs5.existsSync)(templatePath)) {
|
|
18310
18259
|
return { started: false, error: `Template not found: ${templatePath}` };
|
|
18311
18260
|
}
|
|
18312
|
-
|
|
18313
|
-
|
|
18314
|
-
|
|
18261
|
+
(0, import_fs5.cpSync)(templatePath, destPath);
|
|
18262
|
+
const specsSample = (0, import_path5.join)(workspacePath, "specs-sample");
|
|
18263
|
+
const reposSample = (0, import_path5.join)(workspacePath, "repos-sample");
|
|
18264
|
+
(0, import_fs5.mkdirSync)(specsSample, { recursive: true });
|
|
18265
|
+
(0, import_fs5.mkdirSync)(reposSample, { recursive: true });
|
|
18315
18266
|
const envPath = (0, import_path5.join)(workspacePath, ".env");
|
|
18316
|
-
|
|
18317
|
-
|
|
18267
|
+
let existingEnv = "";
|
|
18268
|
+
if ((0, import_fs5.existsSync)(envPath)) {
|
|
18269
|
+
existingEnv = (0, import_fs5.readFileSync)(envPath, "utf-8");
|
|
18270
|
+
}
|
|
18271
|
+
const setEnvVar = (content, key, value) => {
|
|
18272
|
+
const re = new RegExp(`^${key}=.*$`, "m");
|
|
18273
|
+
const line = `${key}=${value}`;
|
|
18274
|
+
return re.test(content) ? content.replace(re, line) : content + (content.endsWith("\n") || !content ? "" : "\n") + line + "\n";
|
|
18275
|
+
};
|
|
18276
|
+
let envContent = existingEnv;
|
|
18277
|
+
envContent = setEnvVar(envContent, "CORTEX_API_TOKEN", opts.token ?? "");
|
|
18278
|
+
envContent = setEnvVar(
|
|
18279
|
+
envContent,
|
|
18280
|
+
"SPECS_DIR_HOST",
|
|
18281
|
+
opts.specsDir ?? "./specs-sample"
|
|
18282
|
+
);
|
|
18283
|
+
envContent = setEnvVar(
|
|
18284
|
+
envContent,
|
|
18285
|
+
"REPOS_DIR_HOST",
|
|
18286
|
+
opts.reposDir ?? "./repos-sample"
|
|
18287
|
+
);
|
|
18288
|
+
if (!envContent.endsWith("\n")) envContent += "\n";
|
|
18318
18289
|
(0, import_fs5.writeFileSync)(envPath, envContent, { encoding: "utf-8" });
|
|
18319
18290
|
const imageTag = opts.embeddings ? "latest-embeddings" : "latest";
|
|
18320
18291
|
const cortexImage = `ghcr.io/rodrigoroldan/cortex-context:${imageTag}`;
|
|
@@ -18328,7 +18299,7 @@ async function deployLocalStack(workspacePath, opts = {}) {
|
|
|
18328
18299
|
env: { ...process.env, CORTEX_IMAGE: cortexImage }
|
|
18329
18300
|
}
|
|
18330
18301
|
);
|
|
18331
|
-
return { started: true };
|
|
18302
|
+
return { started: true, usedHostNetwork: lxc };
|
|
18332
18303
|
} catch (err) {
|
|
18333
18304
|
const stderr = err instanceof Error && "stderr" in err ? err.stderr?.toString() ?? "" : "";
|
|
18334
18305
|
const msg = err instanceof Error ? err.message : String(err);
|
|
@@ -18369,7 +18340,7 @@ ${stderr.trim()}` : ""}`
|
|
|
18369
18340
|
};
|
|
18370
18341
|
}
|
|
18371
18342
|
try {
|
|
18372
|
-
(0, import_child_process.execSync)(`${composeCmd} up -d --force-recreate cortex-api`, {
|
|
18343
|
+
(0, import_child_process.execSync)(`${composeCmd} up -d --no-deps --force-recreate cortex-api`, {
|
|
18373
18344
|
cwd: workspacePath,
|
|
18374
18345
|
stdio: ["inherit", "inherit", "pipe"],
|
|
18375
18346
|
env: { ...process.env, CORTEX_IMAGE: cortexImage }
|
|
@@ -18679,7 +18650,9 @@ async function initCommand(options) {
|
|
|
18679
18650
|
const spinner2 = ora(
|
|
18680
18651
|
" Starting Cortex stack with Docker Compose..."
|
|
18681
18652
|
).start();
|
|
18682
|
-
const dockerResult = await deployLocalStack(workspacePath
|
|
18653
|
+
const dockerResult = await deployLocalStack(workspacePath, {
|
|
18654
|
+
token: cortexToken
|
|
18655
|
+
});
|
|
18683
18656
|
if (!dockerResult.started) {
|
|
18684
18657
|
spinner2.fail(
|
|
18685
18658
|
source_default.red(` \u2717 Docker deploy failed: ${dockerResult.error}`)
|
|
@@ -28383,26 +28356,13 @@ async function serverCommand(options) {
|
|
|
28383
28356
|
writeConfig({ url: CORTEX_URL2, token: serverToken });
|
|
28384
28357
|
console.log("");
|
|
28385
28358
|
console.log(source_default.bold(" Step 4: Starting Cortex stack"));
|
|
28386
|
-
|
|
28387
|
-
if (sysctlFix.applied) {
|
|
28359
|
+
if (isLxcEnvironment()) {
|
|
28388
28360
|
console.log(
|
|
28389
28361
|
source_default.dim(
|
|
28390
|
-
" (
|
|
28362
|
+
" (Proxmox LXC detected \u2014 using host network mode automatically)"
|
|
28391
28363
|
)
|
|
28392
28364
|
);
|
|
28393
28365
|
}
|
|
28394
|
-
const crunSetup = tryConfigureCrunRuntime();
|
|
28395
|
-
if (crunSetup.attempted) {
|
|
28396
|
-
if (crunSetup.dockerRestarted) {
|
|
28397
|
-
console.log(
|
|
28398
|
-
source_default.dim(
|
|
28399
|
-
" (configured crun as Docker runtime for LXC compatibility \u2014 daemon restarted)"
|
|
28400
|
-
)
|
|
28401
|
-
);
|
|
28402
|
-
} else if (crunSetup.error) {
|
|
28403
|
-
console.log(source_default.dim(` (crun setup skipped: ${crunSetup.error})`));
|
|
28404
|
-
}
|
|
28405
|
-
}
|
|
28406
28366
|
console.log(source_default.dim(" $ docker compose up -d"));
|
|
28407
28367
|
console.log("");
|
|
28408
28368
|
const startResult = await deployLocalStack(workDir, {
|
|
@@ -28412,46 +28372,7 @@ async function serverCommand(options) {
|
|
|
28412
28372
|
console.log("");
|
|
28413
28373
|
if (!startResult.started) {
|
|
28414
28374
|
console.log(source_default.red(" \u2717 Docker Compose failed"));
|
|
28415
|
-
|
|
28416
|
-
console.log("");
|
|
28417
|
-
console.log(
|
|
28418
|
-
source_default.bold.yellow(" \u26A0 Proxmox LXC sysctl restriction detected")
|
|
28419
|
-
);
|
|
28420
|
-
console.log("");
|
|
28421
|
-
console.log(
|
|
28422
|
-
source_default.dim(
|
|
28423
|
-
" runc >= 1.1 writes net.ipv4.ip_unprivileged_port_start in each new"
|
|
28424
|
-
)
|
|
28425
|
-
);
|
|
28426
|
-
console.log(
|
|
28427
|
-
source_default.dim(
|
|
28428
|
-
" Docker network namespace. Unprivileged Proxmox LXC blocks this write."
|
|
28429
|
-
)
|
|
28430
|
-
);
|
|
28431
|
-
console.log("");
|
|
28432
|
-
console.log(
|
|
28433
|
-
source_default.dim(" Attempted automatic fix (crun) \u2014 but it was not enough.")
|
|
28434
|
-
);
|
|
28435
|
-
console.log(
|
|
28436
|
-
source_default.dim(
|
|
28437
|
-
" Manual fix: install crun and configure Docker daemon on this LXC:"
|
|
28438
|
-
)
|
|
28439
|
-
);
|
|
28440
|
-
console.log("");
|
|
28441
|
-
console.log(source_default.cyan(" apt-get install -y crun"));
|
|
28442
|
-
console.log(source_default.cyan(" cat > /etc/docker/daemon.json << 'EOF'"));
|
|
28443
|
-
console.log(
|
|
28444
|
-
source_default.cyan(
|
|
28445
|
-
' {"default-runtime":"crun","runtimes":{"crun":{"path":"/usr/bin/crun"}}}'
|
|
28446
|
-
)
|
|
28447
|
-
);
|
|
28448
|
-
console.log(source_default.cyan(" EOF"));
|
|
28449
|
-
console.log(source_default.cyan(" systemctl restart docker"));
|
|
28450
|
-
console.log("");
|
|
28451
|
-
console.log(source_default.dim(" Then run cortex-context server again."));
|
|
28452
|
-
} else {
|
|
28453
|
-
console.log(source_default.dim(` ${startResult.error}`));
|
|
28454
|
-
}
|
|
28375
|
+
console.log(source_default.dim(` ${startResult.error}`));
|
|
28455
28376
|
process.exit(1);
|
|
28456
28377
|
}
|
|
28457
28378
|
console.log(source_default.green(" \u2713 Containers started"));
|