0agent 1.0.32 → 1.0.33
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 +67 -0
- package/package.json +1 -1
package/bin/chat.js
CHANGED
|
@@ -758,9 +758,76 @@ async function _safeJsonFetch(url, opts) {
|
|
|
758
758
|
console.log(` ${fmt(C.yellow, '⚠')} LLM check failed: ${e.message}\n`);
|
|
759
759
|
}
|
|
760
760
|
|
|
761
|
+
// ── Version check — ask to update if newer version is on npm ──────────────
|
|
762
|
+
try {
|
|
763
|
+
const pkgPath = resolve(new URL(import.meta.url).pathname, '..', '..', 'package.json');
|
|
764
|
+
const currentVersion = existsSync(pkgPath)
|
|
765
|
+
? JSON.parse(readFileSync(pkgPath, 'utf8')).version
|
|
766
|
+
: null;
|
|
767
|
+
|
|
768
|
+
if (currentVersion) {
|
|
769
|
+
const reg = await fetch('https://registry.npmjs.org/0agent/latest', {
|
|
770
|
+
signal: AbortSignal.timeout(4000),
|
|
771
|
+
}).then(r => r.json()).catch(() => null);
|
|
772
|
+
|
|
773
|
+
const latest = reg?.version;
|
|
774
|
+
if (latest && latest !== currentVersion && isNewerVersion(latest, currentVersion)) {
|
|
775
|
+
console.log(`\n ${fmt(C.yellow, '↑')} Update available: ${fmt(C.dim, currentVersion)} → ${fmt(C.bold + C.green, latest)}`);
|
|
776
|
+
process.stdout.write(` Update now? ${fmt(C.bold, '[y/N]')} `);
|
|
777
|
+
|
|
778
|
+
await new Promise((res) => {
|
|
779
|
+
const handler = async (buf) => {
|
|
780
|
+
const answer = buf.toString().trim().toLowerCase();
|
|
781
|
+
process.stdout.write(answer + '\n');
|
|
782
|
+
if (answer === 'y') {
|
|
783
|
+
process.stdout.write(`\n ${fmt(C.dim, 'Installing 0agent@latest...')}\n`);
|
|
784
|
+
try {
|
|
785
|
+
const { execSync: exs } = await import('node:child_process');
|
|
786
|
+
exs('npm install -g 0agent@latest', { stdio: 'inherit', timeout: 120_000 });
|
|
787
|
+
process.stdout.write(`\n ${fmt(C.green, '✓')} Updated to ${latest} — restarting...\n\n`);
|
|
788
|
+
// Restart: spawn new instance, exit current
|
|
789
|
+
const { spawn: sp } = await import('node:child_process');
|
|
790
|
+
const child = sp(process.argv[0], process.argv.slice(1), { stdio: 'inherit' });
|
|
791
|
+
child.on('close', (code) => process.exit(code ?? 0));
|
|
792
|
+
process.stdin.pause();
|
|
793
|
+
} catch (e) {
|
|
794
|
+
process.stdout.write(`\n ${fmt(C.red, '✗')} Update failed: ${e.message}\n Try manually: npm install -g 0agent@latest\n\n`);
|
|
795
|
+
rl.prompt();
|
|
796
|
+
}
|
|
797
|
+
} else {
|
|
798
|
+
process.stdout.write(` ${fmt(C.dim, `Skipping — run: npm install -g 0agent@${latest} to update later`)}\n\n`);
|
|
799
|
+
rl.prompt();
|
|
800
|
+
}
|
|
801
|
+
res();
|
|
802
|
+
};
|
|
803
|
+
|
|
804
|
+
// Single keypress if TTY, line otherwise
|
|
805
|
+
if (process.stdin.isTTY) {
|
|
806
|
+
process.stdin.once('data', handler);
|
|
807
|
+
} else {
|
|
808
|
+
rl.once('line', (line) => handler(Buffer.from(line)));
|
|
809
|
+
}
|
|
810
|
+
});
|
|
811
|
+
return; // rl.prompt() already called in handler
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
} catch {
|
|
815
|
+
// Version check is non-fatal — never block startup
|
|
816
|
+
}
|
|
817
|
+
|
|
761
818
|
rl.prompt();
|
|
762
819
|
})();
|
|
763
820
|
|
|
821
|
+
function isNewerVersion(a, b) {
|
|
822
|
+
const pa = a.split('.').map(Number);
|
|
823
|
+
const pb = b.split('.').map(Number);
|
|
824
|
+
for (let i = 0; i < 3; i++) {
|
|
825
|
+
if ((pa[i] ?? 0) > (pb[i] ?? 0)) return true;
|
|
826
|
+
if ((pa[i] ?? 0) < (pb[i] ?? 0)) return false;
|
|
827
|
+
}
|
|
828
|
+
return false;
|
|
829
|
+
}
|
|
830
|
+
|
|
764
831
|
|
|
765
832
|
rl.on('line', async (input) => {
|
|
766
833
|
const line = input.trim();
|