arisa 2.2.9 → 2.2.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.
Files changed (2) hide show
  1. package/bin/arisa.js +105 -13
  2. package/package.json +1 -1
package/bin/arisa.js CHANGED
@@ -448,9 +448,46 @@ function runAsInherit(cmd) {
448
448
  });
449
449
  }
450
450
 
451
+ function ensureSwap() {
452
+ // Check if swap already exists
453
+ const swapon = spawnSync("swapon", ["--show"], { stdio: "pipe" });
454
+ const swapOutput = (swapon.stdout || "").toString().trim();
455
+ if (swapOutput.includes("/")) return; // swap already active
456
+
457
+ // Create 512MB swap file (essential on 1GB VPS for bun add)
458
+ process.stdout.write(" Creating swap file (512MB)...\n");
459
+ const cmds = [
460
+ ["fallocate", ["-l", "512M", "/swapfile"]],
461
+ ["chmod", ["600", "/swapfile"]],
462
+ ["mkswap", ["/swapfile"]],
463
+ ["swapon", ["/swapfile"]],
464
+ ];
465
+ for (const [cmd, cmdArgs] of cmds) {
466
+ const result = spawnSync(cmd, cmdArgs, { stdio: "pipe" });
467
+ if (result.status !== 0) {
468
+ step(false, "Failed to create swap file");
469
+ return;
470
+ }
471
+ }
472
+
473
+ // Make persistent across reboots
474
+ const fstabPath = "/etc/fstab";
475
+ if (existsSync(fstabPath)) {
476
+ const fstab = readFileSync(fstabPath, "utf8");
477
+ if (!fstab.includes("/swapfile")) {
478
+ writeFileSync(fstabPath, fstab.trimEnd() + "\n/swapfile none swap sw 0 0\n");
479
+ }
480
+ }
481
+
482
+ step(true, "Swap file created (512MB)");
483
+ }
484
+
451
485
  function provisionArisaUser() {
452
486
  process.stdout.write("Running as root \u2014 creating dedicated user 'arisa'...\n");
453
487
 
488
+ // 0. Ensure swap exists (prevents OOM on 1GB VPS during CLI installs)
489
+ ensureSwap();
490
+
454
491
  // 1. Create user
455
492
  const useradd = spawnSync("useradd", ["-m", "-s", "/bin/bash", "arisa"], {
456
493
  stdio: "pipe",
@@ -586,6 +623,59 @@ function runArisaForeground() {
586
623
  return result.status ?? 1;
587
624
  }
588
625
 
626
+ // ── Minimal setup (runs as root, no second bun process) ─────────────
627
+
628
+ function askLine(promptText) {
629
+ process.stdout.write(promptText);
630
+ const result = spawnSync("bash", ["-c", "read -r line; echo \"$line\""], {
631
+ stdio: ["inherit", "pipe", "inherit"],
632
+ });
633
+ return (result.stdout || "").toString().trim();
634
+ }
635
+
636
+ function runMinimalSetup() {
637
+ const arisaDataDir = "/home/arisa/.arisa";
638
+ const envPath = join(arisaDataDir, ".env");
639
+
640
+ // Load existing .env if any
641
+ const vars = {};
642
+ if (existsSync(envPath)) {
643
+ for (const line of readFileSync(envPath, "utf8").split("\n")) {
644
+ const match = line.match(/^([A-Z_][A-Z0-9_]*)=(.+)$/);
645
+ if (match) vars[match[1]] = match[2].trim();
646
+ }
647
+ }
648
+
649
+ if (!vars.TELEGRAM_BOT_TOKEN) {
650
+ process.stdout.write("\nArisa Setup\n\n");
651
+ const token = askLine("Telegram Bot Token (from https://t.me/BotFather): ");
652
+ if (!token) {
653
+ process.stdout.write("No token provided. Cannot start without Telegram Bot Token.\n");
654
+ process.exit(1);
655
+ }
656
+ vars.TELEGRAM_BOT_TOKEN = token;
657
+ process.stdout.write(" Token saved.\n");
658
+ }
659
+
660
+ if (!vars.OPENAI_API_KEY) {
661
+ const key = askLine("OpenAI API Key (optional, enter to skip): ");
662
+ if (key) {
663
+ vars.OPENAI_API_KEY = key;
664
+ process.stdout.write(" Key saved.\n");
665
+ }
666
+ }
667
+
668
+ vars.ARISA_SETUP_COMPLETE = "1";
669
+
670
+ // Write .env
671
+ mkdirSync(arisaDataDir, { recursive: true });
672
+ const content = Object.entries(vars).map(([k, v]) => `${k}=${v}`).join("\n") + "\n";
673
+ writeFileSync(envPath, content, "utf8");
674
+ spawnSync("chown", ["-R", "arisa:arisa", arisaDataDir], { stdio: "ignore" });
675
+
676
+ process.stdout.write(`\nConfig saved to ${envPath}\n`);
677
+ }
678
+
589
679
  // ── Root guard ──────────────────────────────────────────────────────
590
680
 
591
681
  if (isRoot()) {
@@ -597,12 +687,14 @@ if (isRoot()) {
597
687
  spawnSync("systemctl", ["enable", "arisa"], { stdio: "inherit" });
598
688
  step(true, "Systemd service enabled (auto-starts on reboot)");
599
689
  }
690
+ }
600
691
 
601
- process.stdout.write("\nStarting interactive setup as user arisa...\n\n");
602
- process.exit(runArisaForeground());
692
+ // Minimal setup: collect tokens here (no second bun process)
693
+ if (!isArisaConfigured()) {
694
+ runMinimalSetup();
603
695
  }
604
696
 
605
- // Already provisioned — route commands
697
+ // Already provisioned + configured — route commands
606
698
  if (command === "help" || command === "--help" || command === "-h") {
607
699
  printHelp();
608
700
  process.exit(0);
@@ -614,20 +706,20 @@ if (isRoot()) {
614
706
 
615
707
  const hasSystemd = canUseSystemdSystem();
616
708
 
617
- // No args → setup if needed, then systemd or foreground
618
709
  if (isDefaultInvocation) {
619
- if (!isArisaConfigured()) {
620
- process.stdout.write("Arisa is not configured yet. Starting interactive setup...\n\n");
621
- process.exit(runArisaForeground());
622
- }
623
710
  if (hasSystemd) {
624
- if (isSystemdActive()) {
625
- process.exit(statusSystemdSystem());
626
- } else {
627
- process.exit(startSystemdSystem());
711
+ if (!isSystemdActive()) {
712
+ const start = startSystemdSystem();
713
+ if (start !== 0) process.exit(start);
628
714
  }
715
+ process.stdout.write("\nArisa is running. Management commands:\n");
716
+ process.stdout.write(" Status: systemctl status arisa\n");
717
+ process.stdout.write(" Logs: journalctl -u arisa -f\n");
718
+ process.stdout.write(" Restart: systemctl restart arisa\n");
719
+ process.stdout.write(" Stop: systemctl stop arisa\n\n");
720
+ process.exit(0);
629
721
  }
630
- // No systemd → foreground
722
+ // No systemd → foreground (two bun processes, but no other option)
631
723
  process.exit(runArisaForeground());
632
724
  }
633
725
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arisa",
3
- "version": "2.2.9",
3
+ "version": "2.2.11",
4
4
  "description": "Arisa - dynamic agent runtime with daemon/core architecture that evolves through user interaction",
5
5
  "preferGlobal": true,
6
6
  "bin": {