0agent 1.0.34 → 1.0.35
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/bin/chat.js +47 -48
- package/package.json +1 -1
package/bin/chat.js
CHANGED
|
@@ -773,62 +773,61 @@ async function _safeJsonFetch(url, opts) {
|
|
|
773
773
|
console.log(` ${fmt(C.yellow, '⚠')} LLM check failed: ${e.message}\n`);
|
|
774
774
|
}
|
|
775
775
|
|
|
776
|
-
// ──
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
776
|
+
// ── Auto-update: check npm, update silently, restart ─────────────────────
|
|
777
|
+
// Runs in background after prompt — never blocks startup.
|
|
778
|
+
// If update found: counts down 3s (press any key to skip), then auto-installs.
|
|
779
|
+
(async () => {
|
|
780
|
+
try {
|
|
781
|
+
const pkgPath = resolve(new URL(import.meta.url).pathname, '..', '..', 'package.json');
|
|
782
|
+
const currentVersion = existsSync(pkgPath)
|
|
783
|
+
? JSON.parse(readFileSync(pkgPath, 'utf8')).version
|
|
784
|
+
: null;
|
|
785
|
+
if (!currentVersion) return;
|
|
782
786
|
|
|
783
|
-
if (currentVersion) {
|
|
784
787
|
const reg = await fetch('https://registry.npmjs.org/0agent/latest', {
|
|
785
|
-
signal: AbortSignal.timeout(
|
|
788
|
+
signal: AbortSignal.timeout(5000),
|
|
786
789
|
}).then(r => r.json()).catch(() => null);
|
|
787
790
|
|
|
788
791
|
const latest = reg?.version;
|
|
789
|
-
if (latest
|
|
790
|
-
console.log(`\n ${fmt(C.yellow, '↑')} Update available: ${fmt(C.dim, currentVersion)} → ${fmt(C.bold + C.green, latest)}`);
|
|
791
|
-
process.stdout.write(` Update now? ${fmt(C.bold, '[y/N]')} `);
|
|
792
|
-
|
|
793
|
-
await new Promise((res) => {
|
|
794
|
-
const handler = async (buf) => {
|
|
795
|
-
const answer = buf.toString().trim().toLowerCase();
|
|
796
|
-
process.stdout.write(answer + '\n');
|
|
797
|
-
if (answer === 'y') {
|
|
798
|
-
process.stdout.write(`\n ${fmt(C.dim, 'Installing 0agent@latest...')}\n`);
|
|
799
|
-
try {
|
|
800
|
-
const { execSync: exs } = await import('node:child_process');
|
|
801
|
-
exs('npm install -g 0agent@latest', { stdio: 'inherit', timeout: 120_000 });
|
|
802
|
-
process.stdout.write(`\n ${fmt(C.green, '✓')} Updated to ${latest} — restarting...\n\n`);
|
|
803
|
-
// Restart: spawn new instance, exit current
|
|
804
|
-
const { spawn: sp } = await import('node:child_process');
|
|
805
|
-
const child = sp(process.argv[0], process.argv.slice(1), { stdio: 'inherit' });
|
|
806
|
-
child.on('close', (code) => process.exit(code ?? 0));
|
|
807
|
-
process.stdin.pause();
|
|
808
|
-
} catch (e) {
|
|
809
|
-
process.stdout.write(`\n ${fmt(C.red, '✗')} Update failed: ${e.message}\n Try manually: npm install -g 0agent@latest\n\n`);
|
|
810
|
-
rl.prompt();
|
|
811
|
-
}
|
|
812
|
-
} else {
|
|
813
|
-
process.stdout.write(` ${fmt(C.dim, `Skipping — run: npm install -g 0agent@${latest} to update later`)}\n\n`);
|
|
814
|
-
rl.prompt();
|
|
815
|
-
}
|
|
816
|
-
res();
|
|
817
|
-
};
|
|
792
|
+
if (!latest || !isNewerVersion(latest, currentVersion)) return;
|
|
818
793
|
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
794
|
+
// Show banner immediately above current prompt line
|
|
795
|
+
process.stdout.write(`\n ${fmt(C.yellow, '↑')} New version ${fmt(C.bold, latest)} available (you have ${currentVersion})\n`);
|
|
796
|
+
|
|
797
|
+
// 3-second countdown — press any key to skip, otherwise auto-updates
|
|
798
|
+
let skipped = false;
|
|
799
|
+
const skipHandler = () => { skipped = true; };
|
|
800
|
+
process.stdin.once('data', skipHandler);
|
|
801
|
+
|
|
802
|
+
for (let i = 3; i > 0; i--) {
|
|
803
|
+
if (skipped) break;
|
|
804
|
+
process.stdout.write(`\r ${fmt(C.dim, `Auto-updating in ${i}s — press any key to skip... `)}`);
|
|
805
|
+
await new Promise(r => setTimeout(r, 1000));
|
|
806
|
+
}
|
|
807
|
+
process.stdin.removeListener('data', skipHandler);
|
|
808
|
+
process.stdout.write('\r\x1b[2K'); // clear countdown line
|
|
809
|
+
|
|
810
|
+
if (skipped) {
|
|
811
|
+
console.log(` ${fmt(C.dim, `Skipped. Run: npm install -g 0agent@${latest}`)}`);
|
|
812
|
+
rl.prompt(true);
|
|
813
|
+
return;
|
|
827
814
|
}
|
|
815
|
+
|
|
816
|
+
// Auto-install
|
|
817
|
+
console.log(` ${fmt(C.cyan, '↑')} Updating to ${latest}...`);
|
|
818
|
+
const { execSync: exs } = await import('node:child_process');
|
|
819
|
+
exs('npm install -g 0agent@latest --silent', { stdio: 'ignore', timeout: 120_000 });
|
|
820
|
+
process.stdout.write(` ${fmt(C.green, '✓')} Updated to ${latest} — restarting...\n\n`);
|
|
821
|
+
|
|
822
|
+
// Restart cleanly
|
|
823
|
+
const { spawn: sp } = await import('node:child_process');
|
|
824
|
+
const child = sp(process.argv[0], process.argv.slice(1), { stdio: 'inherit' });
|
|
825
|
+
child.on('close', (code) => process.exit(code ?? 0));
|
|
826
|
+
process.stdin.pause();
|
|
827
|
+
} catch {
|
|
828
|
+
// Non-fatal — update failure never crashes the agent
|
|
828
829
|
}
|
|
829
|
-
}
|
|
830
|
-
// Version check is non-fatal — never block startup
|
|
831
|
-
}
|
|
830
|
+
})();
|
|
832
831
|
|
|
833
832
|
rl.prompt();
|
|
834
833
|
})();
|