@cortex-context/cli 0.0.9 → 0.0.11

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
@@ -18220,6 +18220,67 @@ function tryFixLxcSysctl() {
18220
18220
  return { applied: false };
18221
18221
  }
18222
18222
  }
18223
+ function tryConfigureCrunRuntime() {
18224
+ const result = {
18225
+ attempted: false,
18226
+ crunInstalled: false,
18227
+ daemonUpdated: false,
18228
+ dockerRestarted: false
18229
+ };
18230
+ if ((0, import_os3.platform)() !== "linux") return result;
18231
+ result.attempted = true;
18232
+ const hasCrun = (() => {
18233
+ try {
18234
+ (0, import_child_process.execSync)("which crun", { stdio: "ignore" });
18235
+ return true;
18236
+ } catch {
18237
+ return false;
18238
+ }
18239
+ })();
18240
+ if (hasCrun) {
18241
+ result.crunInstalled = true;
18242
+ } else {
18243
+ try {
18244
+ (0, import_child_process.execSync)("apt-get install -y crun", { stdio: "ignore" });
18245
+ result.crunInstalled = true;
18246
+ } catch (e) {
18247
+ result.error = `crun install: ${e instanceof Error ? e.message : String(e)}`;
18248
+ return result;
18249
+ }
18250
+ }
18251
+ const daemonPath = "/etc/docker/daemon.json";
18252
+ let cfg = {};
18253
+ try {
18254
+ if ((0, import_fs5.existsSync)(daemonPath)) {
18255
+ cfg = JSON.parse((0, import_fs5.readFileSync)(daemonPath, "utf-8"));
18256
+ }
18257
+ } catch {
18258
+ cfg = {};
18259
+ }
18260
+ if (cfg["default-runtime"] === "crun") {
18261
+ result.daemonUpdated = true;
18262
+ result.dockerRestarted = true;
18263
+ return result;
18264
+ }
18265
+ const runtimes = cfg["runtimes"] ?? {};
18266
+ runtimes["crun"] = { path: "/usr/bin/crun" };
18267
+ cfg["runtimes"] = runtimes;
18268
+ cfg["default-runtime"] = "crun";
18269
+ try {
18270
+ (0, import_fs5.writeFileSync)(daemonPath, JSON.stringify(cfg, null, 2) + "\n", "utf-8");
18271
+ result.daemonUpdated = true;
18272
+ } catch (e) {
18273
+ result.error = `daemon.json: ${e instanceof Error ? e.message : String(e)}`;
18274
+ return result;
18275
+ }
18276
+ try {
18277
+ (0, import_child_process.execSync)("systemctl restart docker", { stdio: "ignore" });
18278
+ result.dockerRestarted = true;
18279
+ } catch (e) {
18280
+ result.error = `docker restart: ${e instanceof Error ? e.message : String(e)}`;
18281
+ }
18282
+ return result;
18283
+ }
18223
18284
  async function deployLocalStack(workspacePath, opts = {}) {
18224
18285
  const templatePath = (0, import_path5.join)(
18225
18286
  __dirname,
@@ -28181,12 +28242,26 @@ async function serverCommand(options) {
28181
28242
  )
28182
28243
  );
28183
28244
  }
28184
- const startSpinner = ora(" Running docker compose up -d...").start();
28245
+ const crunSetup = tryConfigureCrunRuntime();
28246
+ if (crunSetup.attempted) {
28247
+ if (crunSetup.dockerRestarted) {
28248
+ console.log(
28249
+ source_default.dim(
28250
+ " (configured crun as Docker runtime for LXC compatibility \u2014 daemon restarted)"
28251
+ )
28252
+ );
28253
+ } else if (crunSetup.error) {
28254
+ console.log(source_default.dim(` (crun setup skipped: ${crunSetup.error})`));
28255
+ }
28256
+ }
28257
+ console.log(source_default.dim(" $ docker compose up -d"));
28258
+ console.log("");
28185
28259
  const startResult = await deployLocalStack(workDir, {
28186
28260
  embeddings: options.embeddings ?? false
28187
28261
  });
28262
+ console.log("");
28188
28263
  if (!startResult.started) {
28189
- startSpinner.fail(source_default.red(" \u2717 Docker Compose failed"));
28264
+ console.log(source_default.red(" \u2717 Docker Compose failed"));
28190
28265
  if (startResult.isLxcSysctlError) {
28191
28266
  console.log("");
28192
28267
  console.log(
@@ -28195,40 +28270,41 @@ async function serverCommand(options) {
28195
28270
  console.log("");
28196
28271
  console.log(
28197
28272
  source_default.dim(
28198
- " runc >= 1.1 tries to configure net.ipv4.ip_unprivileged_port_start"
28273
+ " runc >= 1.1 writes net.ipv4.ip_unprivileged_port_start in each new"
28199
28274
  )
28200
28275
  );
28201
28276
  console.log(
28202
28277
  source_default.dim(
28203
- " inside each container's network namespace. Proxmox LXC containers"
28278
+ " Docker network namespace. Unprivileged Proxmox LXC blocks this write."
28204
28279
  )
28205
28280
  );
28281
+ console.log("");
28282
+ console.log(
28283
+ source_default.dim(" Attempted automatic fix (crun) \u2014 but it was not enough.")
28284
+ );
28206
28285
  console.log(
28207
28286
  source_default.dim(
28208
- " block this unless the sysctl is explicitly allowed in the LXC config."
28287
+ " Manual fix: install crun and configure Docker daemon on this LXC:"
28209
28288
  )
28210
28289
  );
28211
28290
  console.log("");
28212
- console.log(source_default.bold(" Fix (run on the Proxmox host):"));
28213
- console.log("");
28214
- console.log(source_default.cyan(" CTID=<your-container-id>"));
28291
+ console.log(source_default.cyan(" apt-get install -y crun"));
28292
+ console.log(source_default.cyan(" cat > /etc/docker/daemon.json << 'EOF'"));
28215
28293
  console.log(
28216
28294
  source_default.cyan(
28217
- ' echo "lxc.sysctl.net.ipv4.ip_unprivileged_port_start = 0" \\'
28295
+ ' {"default-runtime":"crun","runtimes":{"crun":{"path":"/usr/bin/crun"}}}'
28218
28296
  )
28219
28297
  );
28220
- console.log(source_default.cyan(" >> /etc/pve/lxc/${CTID}.conf"));
28221
- console.log(source_default.cyan(" pct restart ${CTID}"));
28298
+ console.log(source_default.cyan(" EOF"));
28299
+ console.log(source_default.cyan(" systemctl restart docker"));
28222
28300
  console.log("");
28223
- console.log(
28224
- source_default.dim(" Then run cortex-context server again inside the LXC.")
28225
- );
28301
+ console.log(source_default.dim(" Then run cortex-context server again."));
28226
28302
  } else {
28227
28303
  console.log(source_default.dim(` ${startResult.error}`));
28228
28304
  }
28229
28305
  process.exit(1);
28230
28306
  }
28231
- startSpinner.succeed(source_default.green(" \u2713 Containers started"));
28307
+ console.log(source_default.green(" \u2713 Containers started"));
28232
28308
  console.log("");
28233
28309
  console.log(source_default.bold(" Step 4: Waiting for Cortex API..."));
28234
28310
  const healthSpinner = ora(
@@ -28412,8 +28488,8 @@ async function uninstallCommand(options) {
28412
28488
  if (!options.keepHook && hasHook) {
28413
28489
  const hookPath = (0, import_path14.join)(workspacePath, ".git", "hooks", "post-commit");
28414
28490
  try {
28415
- const { readFileSync: readFileSync7 } = await import("fs");
28416
- const hookContent = readFileSync7(hookPath, "utf-8");
28491
+ const { readFileSync: readFileSync8 } = await import("fs");
28492
+ const hookContent = readFileSync8(hookPath, "utf-8");
28417
28493
  if (hookContent.includes("cortex-context")) {
28418
28494
  (0, import_fs13.unlinkSync)(hookPath);
28419
28495
  console.log(source_default.green(" \u2713 .git/hooks/post-commit \u2014 removed"));