agentic-factory-bridge 1.3.0 → 1.3.1

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/bridge.js +155 -1
  2. package/package.json +1 -1
package/bridge.js CHANGED
@@ -1220,7 +1220,161 @@ app.post(
1220
1220
  );
1221
1221
 
1222
1222
  // ---------------------------------------------------------------------------
1223
- // Auto-Update
1223
+ // OpenCode CLI Update
1224
+ // ---------------------------------------------------------------------------
1225
+
1226
+ /**
1227
+ * Check the latest version of opencode-ai on npm registry.
1228
+ * Compares with the locally installed version.
1229
+ * Returns { current, latest, updateAvailable }.
1230
+ */
1231
+ function checkOpencodeNpmVersion() {
1232
+ return new Promise((resolve) => {
1233
+ // First get the installed version
1234
+ const installedProc = spawn(OPENCODE_PATH, ['--version'], {
1235
+ stdio: ['pipe', 'pipe', 'pipe'],
1236
+ timeout: 10000,
1237
+ shell: true,
1238
+ });
1239
+ let installedStdout = '';
1240
+ installedProc.stdout.on('data', (data) => {
1241
+ installedStdout += data.toString();
1242
+ });
1243
+ installedProc.on('close', (installedCode) => {
1244
+ const currentVersion = installedCode === 0 ? installedStdout.trim() : null;
1245
+
1246
+ // Then get the latest version from npm
1247
+ const npmProc = spawn('npm', ['view', 'opencode-ai', 'version'], {
1248
+ stdio: ['pipe', 'pipe', 'pipe'],
1249
+ timeout: 15000,
1250
+ shell: true,
1251
+ });
1252
+ let npmStdout = '';
1253
+ let npmStderr = '';
1254
+ npmProc.stdout.on('data', (data) => {
1255
+ npmStdout += data.toString();
1256
+ });
1257
+ npmProc.stderr.on('data', (data) => {
1258
+ npmStderr += data.toString();
1259
+ });
1260
+ npmProc.on('close', (code) => {
1261
+ if (code === 0 && npmStdout.trim()) {
1262
+ const latest = npmStdout.trim();
1263
+ const updateAvailable = currentVersion != null && latest !== currentVersion;
1264
+ resolve({ current: currentVersion, latest, updateAvailable });
1265
+ } else {
1266
+ resolve({
1267
+ current: currentVersion,
1268
+ latest: null,
1269
+ updateAvailable: false,
1270
+ error: npmStderr.trim() || 'Failed to query npm registry',
1271
+ });
1272
+ }
1273
+ });
1274
+ npmProc.on('error', (err) => {
1275
+ resolve({
1276
+ current: currentVersion,
1277
+ latest: null,
1278
+ updateAvailable: false,
1279
+ error: err.message,
1280
+ });
1281
+ });
1282
+ });
1283
+ installedProc.on('error', (err) => {
1284
+ resolve({
1285
+ current: null,
1286
+ latest: null,
1287
+ updateAvailable: false,
1288
+ error: `OpenCode CLI not found: ${err.message}`,
1289
+ });
1290
+ });
1291
+ });
1292
+ }
1293
+
1294
+ /**
1295
+ * GET /check-opencode-update — Check if a newer version of OpenCode CLI is available on npm.
1296
+ */
1297
+ app.get('/check-opencode-update', async (_req, res) => {
1298
+ try {
1299
+ const result = await checkOpencodeNpmVersion();
1300
+ console.log(
1301
+ `[bridge] OpenCode CLI update check: current=${result.current}, latest=${result.latest}, updateAvailable=${result.updateAvailable}`,
1302
+ );
1303
+ res.json(result);
1304
+ } catch (err) {
1305
+ res.json({
1306
+ current: null,
1307
+ latest: null,
1308
+ updateAvailable: false,
1309
+ error: err.message,
1310
+ });
1311
+ }
1312
+ });
1313
+
1314
+ /**
1315
+ * POST /update-opencode — Update OpenCode CLI to the latest version via npm install -g opencode-ai@latest.
1316
+ * SECURITY: Rate-limited, auth required, fixed command (no user input in spawn args).
1317
+ */
1318
+ app.post(
1319
+ '/update-opencode',
1320
+ requireBridgeAuth,
1321
+ rateLimit('install', RATE_LIMITS.install),
1322
+ async (_req, res) => {
1323
+ console.log('[bridge] Updating OpenCode CLI via npm install -g opencode-ai@latest...');
1324
+ try {
1325
+ await new Promise((resolve, reject) => {
1326
+ const proc = spawn('npm', ['install', '-g', 'opencode-ai@latest'], {
1327
+ stdio: ['pipe', 'pipe', 'pipe'],
1328
+ timeout: 120000,
1329
+ shell: true,
1330
+ });
1331
+ let stdout = '';
1332
+ let stderr = '';
1333
+ proc.stdout.on('data', (data) => {
1334
+ stdout += data.toString();
1335
+ console.log(`[bridge] npm update opencode stdout: ${data.toString().trim()}`);
1336
+ });
1337
+ proc.stderr.on('data', (data) => {
1338
+ stderr += data.toString();
1339
+ });
1340
+ proc.on('close', (code) => {
1341
+ if (code === 0) resolve({ success: true, stdout, stderr });
1342
+ else
1343
+ reject(
1344
+ new Error(
1345
+ `npm install -g opencode-ai@latest failed with code ${code}: ${stderr || stdout}`,
1346
+ ),
1347
+ );
1348
+ });
1349
+ proc.on('error', (err) => {
1350
+ reject(new Error(`Failed to spawn npm: ${err.message}`));
1351
+ });
1352
+ });
1353
+
1354
+ // Check new version after update
1355
+ const versionCheck = await checkOpencodeNpmVersion();
1356
+
1357
+ res.json({
1358
+ success: true,
1359
+ message: 'OpenCode CLI updated successfully.',
1360
+ previousVersion: versionCheck.current, // This is now the new version after install
1361
+ newVersion: versionCheck.latest || versionCheck.current || 'unknown',
1362
+ version: versionCheck.current,
1363
+ path: OPENCODE_PATH,
1364
+ });
1365
+ } catch (err) {
1366
+ console.error(`[bridge] OpenCode CLI update error: ${err.message}`);
1367
+ res.status(500).json({
1368
+ success: false,
1369
+ message: `Update failed: ${err.message}`,
1370
+ version: null,
1371
+ });
1372
+ }
1373
+ },
1374
+ );
1375
+
1376
+ // ---------------------------------------------------------------------------
1377
+ // Bridge Auto-Update
1224
1378
  // ---------------------------------------------------------------------------
1225
1379
 
1226
1380
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agentic-factory-bridge",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "Local bridge for Atos Agentic Factory — connects the marketplace to OpenCode CLI on your machine",
5
5
  "main": "bridge.js",
6
6
  "bin": {