linkgravity 1.0.2 → 1.1.0

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/cli.js +58 -0
  2. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -222,6 +222,58 @@ if (cmd === 'start') {
222
222
  runSetup().catch((err) => {
223
223
  console.error('Setup wizard crashed:', err.message);
224
224
  });
225
+ } else if (cmd === 'update') {
226
+ const pkg = require('../package.json');
227
+ const currentVersion = pkg.version;
228
+
229
+ info('Checking npm for the latest version...');
230
+ const viewResult = spawnSync('npm', ['view', 'linkgravity', 'version'], { stdio: 'pipe' });
231
+ if (viewResult.error || viewResult.status !== 0) {
232
+ console.error(
233
+ (viewResult.stderr || '').toString().trim() ||
234
+ 'Failed to check the latest version on npm.',
235
+ );
236
+ process.exit(1);
237
+ }
238
+ const latestVersion = viewResult.stdout.toString().trim();
239
+
240
+ if (latestVersion === currentVersion) {
241
+ success(`Already up to date (v${currentVersion}).\n`);
242
+ process.exit(0);
243
+ }
244
+
245
+ info(`Updating: v${currentVersion} -> v${latestVersion}...`);
246
+ const installResult = spawnSync('npm', ['install', '-g', 'linkgravity@latest'], {
247
+ stdio: 'inherit',
248
+ });
249
+ if (installResult.status !== 0) {
250
+ console.error('npm install failed - update aborted, still on the old version.');
251
+ process.exit(1);
252
+ }
253
+ success(`Installed v${latestVersion}.`);
254
+
255
+ info('Restarting daemon to apply the update...');
256
+ const restartResult = spawnSync('npx', ['-y', 'pm2', 'restart', 'lgy', '--update-env'], {
257
+ stdio: 'pipe',
258
+ cwd: path.join(__dirname, '..'),
259
+ env: { ...process.env, PYTHONUNBUFFERED: '1' },
260
+ });
261
+
262
+ if (restartResult.status === 0) {
263
+ verifyStartup();
264
+ } else if ((restartResult.stderr || '').toString().includes('not found')) {
265
+ // Daemon wasn't running before the update - start it fresh instead
266
+ // of reporting a restart that never had anything to restart.
267
+ info("Daemon wasn't running - starting it fresh...");
268
+ runPm2(['start', botPath, '--interpreter', pythonExe, '--name', 'lgy']);
269
+ verifyStartup();
270
+ } else {
271
+ console.error((restartResult.stderr || '').toString().trim());
272
+ console.error(
273
+ `\n${color.yellow}⚠${color.reset} Update installed, but restarting the daemon failed - run 'lgy restart' manually.`,
274
+ );
275
+ process.exit(1);
276
+ }
225
277
  } else if (cmd === 'help') {
226
278
  console.log(
227
279
  [
@@ -238,6 +290,7 @@ if (cmd === 'start') {
238
290
  ' enable Register bot to start automatically on system boot',
239
291
  ' disable Remove bot from system boot',
240
292
  ' setup Run the configuration wizard (init)',
293
+ ' update Check npm for a newer version and install + restart if found',
241
294
  ' help Show this help message',
242
295
  '',
243
296
  ].join('\n'),
@@ -256,6 +309,11 @@ if (cmd === 'start') {
256
309
  { label: 'Restart', value: 'restart', hint: 'Restart the running daemon' },
257
310
  { label: 'Logs', value: 'logs', hint: 'View the live console logs' },
258
311
  { label: 'Setup', value: 'setup', hint: 'Configure bot tokens and settings' },
312
+ {
313
+ label: 'Update',
314
+ value: 'update',
315
+ hint: 'Check npm for a newer version and install it',
316
+ },
259
317
  {
260
318
  label: 'Enable Auto-start',
261
319
  value: 'enable',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "linkgravity",
3
- "version": "1.0.2",
3
+ "version": "1.1.0",
4
4
  "description": "Discord bot bridge for the Antigravity (agy) CLI, with voice interaction support",
5
5
  "scripts": {
6
6
  "postinstall": "node npm-scripts/postinstall.js",