0agent 1.0.37 → 1.0.38

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/chat.js +31 -9
  2. package/package.json +1 -1
package/bin/chat.js CHANGED
@@ -563,10 +563,7 @@ async function handleCommand(input) {
563
563
  const { execSync: exs } = await import('node:child_process');
564
564
  exs('npm install -g 0agent@latest --silent', { stdio: 'ignore', timeout: 120_000 });
565
565
  process.stdout.write(` ${fmt(C.green, '✓')} Updated to ${latest} — restarting...\n\n`);
566
- const { spawn: sp } = await import('node:child_process');
567
- const child = sp(process.argv[0], process.argv.slice(1), { stdio: 'inherit' });
568
- child.on('close', (code) => process.exit(code ?? 0));
569
- process.stdin.pause();
566
+ await restartWithLatest();
570
567
  } catch (e) {
571
568
  console.log(` ${fmt(C.red, '✗')} Update failed: ${e.message}\n`);
572
569
  }
@@ -887,11 +884,7 @@ async function _safeJsonFetch(url, opts) {
887
884
  exs('npm install -g 0agent@latest --silent', { stdio: 'ignore', timeout: 120_000 });
888
885
  process.stdout.write(` ${fmt(C.green, '✓')} Updated to ${latest} — restarting...\n\n`);
889
886
 
890
- // Restart cleanly
891
- const { spawn: sp } = await import('node:child_process');
892
- const child = sp(process.argv[0], process.argv.slice(1), { stdio: 'inherit' });
893
- child.on('close', (code) => process.exit(code ?? 0));
894
- process.stdin.pause();
887
+ await restartWithLatest();
895
888
  } catch {
896
889
  // Non-fatal — update failure never crashes the agent
897
890
  }
@@ -900,6 +893,35 @@ async function _safeJsonFetch(url, opts) {
900
893
  rl.prompt();
901
894
  })();
902
895
 
896
+ // Restart using the GLOBAL install, not the npx cache that's currently running.
897
+ // After `npm install -g 0agent@latest`, the new binary is in npm's global bin dir.
898
+ // Using process.argv would re-run the OLD npx-cached file → infinite loop.
899
+ async function restartWithLatest() {
900
+ try {
901
+ const { execSync: ex } = await import('node:child_process');
902
+ const { resolve: res } = await import('node:path');
903
+ const { existsSync: ef } = await import('node:fs');
904
+ const { spawn: sp } = await import('node:child_process');
905
+
906
+ // Find the global npm bin directory (e.g. ~/.nvm/.../bin or /usr/local/bin)
907
+ const globalBin = ex('npm bin -g 2>/dev/null || true', { encoding: 'utf8' }).trim().split('\n')[0];
908
+ const newBin = globalBin ? res(globalBin, '0agent') : null;
909
+
910
+ let child;
911
+ if (newBin && ef(newBin)) {
912
+ // Run the freshly installed global script
913
+ child = sp(process.execPath, [newBin], { stdio: 'inherit' });
914
+ } else {
915
+ // Fallback: let the shell find 0agent in PATH
916
+ child = sp('0agent', [], { stdio: 'inherit', shell: true });
917
+ }
918
+ child.on('close', (code) => process.exit(code ?? 0));
919
+ process.stdin.pause();
920
+ } catch {
921
+ process.exit(0); // just exit; user can re-open
922
+ }
923
+ }
924
+
903
925
  function isNewerVersion(a, b) {
904
926
  const pa = a.split('.').map(Number);
905
927
  const pb = b.split('.').map(Number);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "0agent",
3
- "version": "1.0.37",
3
+ "version": "1.0.38",
4
4
  "description": "A persistent, learning AI agent that runs on your machine. An agent that learns.",
5
5
  "private": false,
6
6
  "license": "Apache-2.0",