@cortex-context/cli 0.0.15 → 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,84 +18227,33 @@ 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 tryFixLxcSysctl() {
18230
+ function isLxcEnvironment() {
18231
+ if ((0, import_os3.platform)() !== "linux") return false;
18231
18232
  try {
18232
- (0, import_child_process.execSync)("sysctl -w net.ipv4.ip_unprivileged_port_start=0", {
18233
- stdio: "ignore"
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
- }
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
18236
  }
18268
- const daemonPath = "/etc/docker/daemon.json";
18269
- let cfg = {};
18270
18237
  try {
18271
- if ((0, import_fs5.existsSync)(daemonPath)) {
18272
- cfg = JSON.parse((0, import_fs5.readFileSync)(daemonPath, "utf-8"));
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
- }
18282
- const runtimes = cfg["runtimes"] ?? {};
18283
- runtimes["crun"] = { path: "/usr/bin/crun" };
18284
- cfg["runtimes"] = runtimes;
18285
- cfg["default-runtime"] = "crun";
18286
- try {
18287
- (0, import_fs5.writeFileSync)(daemonPath, JSON.stringify(cfg, null, 2) + "\n", "utf-8");
18288
- result.daemonUpdated = true;
18289
- } catch (e) {
18290
- result.error = `daemon.json: ${e instanceof Error ? e.message : String(e)}`;
18291
- return result;
18292
18245
  }
18293
18246
  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 result;
18251
+ return false;
18300
18252
  }
18301
18253
  async function deployLocalStack(workspacePath, opts = {}) {
18302
- const templatePath = (0, import_path5.join)(
18303
- __dirname,
18304
- "templates",
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}` };
@@ -18326,8 +18275,16 @@ async function deployLocalStack(workspacePath, opts = {}) {
18326
18275
  };
18327
18276
  let envContent = existingEnv;
18328
18277
  envContent = setEnvVar(envContent, "CORTEX_API_TOKEN", opts.token ?? "");
18329
- envContent = setEnvVar(envContent, "SPECS_DIR_HOST", opts.specsDir ?? "./specs-sample");
18330
- envContent = setEnvVar(envContent, "REPOS_DIR_HOST", opts.reposDir ?? "./repos-sample");
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
+ );
18331
18288
  if (!envContent.endsWith("\n")) envContent += "\n";
18332
18289
  (0, import_fs5.writeFileSync)(envPath, envContent, { encoding: "utf-8" });
18333
18290
  const imageTag = opts.embeddings ? "latest-embeddings" : "latest";
@@ -18342,7 +18299,7 @@ async function deployLocalStack(workspacePath, opts = {}) {
18342
18299
  env: { ...process.env, CORTEX_IMAGE: cortexImage }
18343
18300
  }
18344
18301
  );
18345
- return { started: true };
18302
+ return { started: true, usedHostNetwork: lxc };
18346
18303
  } catch (err) {
18347
18304
  const stderr = err instanceof Error && "stderr" in err ? err.stderr?.toString() ?? "" : "";
18348
18305
  const msg = err instanceof Error ? err.message : String(err);
@@ -18693,7 +18650,9 @@ async function initCommand(options) {
18693
18650
  const spinner2 = ora(
18694
18651
  " Starting Cortex stack with Docker Compose..."
18695
18652
  ).start();
18696
- const dockerResult = await deployLocalStack(workspacePath, { token: cortexToken });
18653
+ const dockerResult = await deployLocalStack(workspacePath, {
18654
+ token: cortexToken
18655
+ });
18697
18656
  if (!dockerResult.started) {
18698
18657
  spinner2.fail(
18699
18658
  source_default.red(` \u2717 Docker deploy failed: ${dockerResult.error}`)
@@ -28397,26 +28356,13 @@ async function serverCommand(options) {
28397
28356
  writeConfig({ url: CORTEX_URL2, token: serverToken });
28398
28357
  console.log("");
28399
28358
  console.log(source_default.bold(" Step 4: Starting Cortex stack"));
28400
- const sysctlFix = tryFixLxcSysctl();
28401
- if (sysctlFix.applied) {
28359
+ if (isLxcEnvironment()) {
28402
28360
  console.log(
28403
28361
  source_default.dim(
28404
- " (applied net.ipv4.ip_unprivileged_port_start=0 for LXC compatibility)"
28362
+ " (Proxmox LXC detected \u2014 using host network mode automatically)"
28405
28363
  )
28406
28364
  );
28407
28365
  }
28408
- const crunSetup = tryConfigureCrunRuntime();
28409
- if (crunSetup.attempted) {
28410
- if (crunSetup.dockerRestarted) {
28411
- console.log(
28412
- source_default.dim(
28413
- " (configured crun as Docker runtime for LXC compatibility \u2014 daemon restarted)"
28414
- )
28415
- );
28416
- } else if (crunSetup.error) {
28417
- console.log(source_default.dim(` (crun setup skipped: ${crunSetup.error})`));
28418
- }
28419
- }
28420
28366
  console.log(source_default.dim(" $ docker compose up -d"));
28421
28367
  console.log("");
28422
28368
  const startResult = await deployLocalStack(workDir, {
@@ -28426,46 +28372,7 @@ async function serverCommand(options) {
28426
28372
  console.log("");
28427
28373
  if (!startResult.started) {
28428
28374
  console.log(source_default.red(" \u2717 Docker Compose failed"));
28429
- if (startResult.isLxcSysctlError) {
28430
- console.log("");
28431
- console.log(
28432
- source_default.bold.yellow(" \u26A0 Proxmox LXC sysctl restriction detected")
28433
- );
28434
- console.log("");
28435
- console.log(
28436
- source_default.dim(
28437
- " runc >= 1.1 writes net.ipv4.ip_unprivileged_port_start in each new"
28438
- )
28439
- );
28440
- console.log(
28441
- source_default.dim(
28442
- " Docker network namespace. Unprivileged Proxmox LXC blocks this write."
28443
- )
28444
- );
28445
- console.log("");
28446
- console.log(
28447
- source_default.dim(" Attempted automatic fix (crun) \u2014 but it was not enough.")
28448
- );
28449
- console.log(
28450
- source_default.dim(
28451
- " Manual fix: install crun and configure Docker daemon on this LXC:"
28452
- )
28453
- );
28454
- console.log("");
28455
- console.log(source_default.cyan(" apt-get install -y crun"));
28456
- console.log(source_default.cyan(" cat > /etc/docker/daemon.json << 'EOF'"));
28457
- console.log(
28458
- source_default.cyan(
28459
- ' {"default-runtime":"crun","runtimes":{"crun":{"path":"/usr/bin/crun"}}}'
28460
- )
28461
- );
28462
- console.log(source_default.cyan(" EOF"));
28463
- console.log(source_default.cyan(" systemctl restart docker"));
28464
- console.log("");
28465
- console.log(source_default.dim(" Then run cortex-context server again."));
28466
- } else {
28467
- console.log(source_default.dim(` ${startResult.error}`));
28468
- }
28375
+ console.log(source_default.dim(` ${startResult.error}`));
28469
28376
  process.exit(1);
28470
28377
  }
28471
28378
  console.log(source_default.green(" \u2713 Containers started"));