From 8e43650598dce19cab44c03cea4b97b66f6fbafc Mon Sep 17 00:00:00 2001 From: mayor Date: Sat, 30 May 2026 18:14:01 -0700 Subject: [PATCH] fix: use `gt rig list --json` in bead-links endpoint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `/api/bead/:beadId/links` endpoint was the only rig-enumerating endpoint still parsing the pretty-printed text output of `gt rig list`. `/api/rigs` and `/api/setup/status` already prefer `gt rig list --json` with a text fallback; this brings the links endpoint in line. Parsing the structured `--json` output is more robust than scraping display text (which has already drifted once — the legacy two-space indent vs. the current emoji-prefixed format that motivated `parseRigNames`). The text path is retained as a fallback for older `gt` builds that don't support `--json`. No behavior change for current `gt`; verified the endpoint still resolves both rigs end-to-end. Integration suite green (127/127). --- server.js | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/server.js b/server.js index 53737b8..fa3afe6 100644 --- a/server.js +++ b/server.js @@ -850,14 +850,28 @@ app.get('/api/bead/:beadId/links', async (req, res) => { } } - // Get list of rig names - const rigsResult = await executeGT(['rig', 'list']); - if (!rigsResult.success) { - return res.json(links); + // Get list of rig names — prefer --json output, fall back to text parsing + // (consistent with /api/rigs and /api/setup/status). + let rigNames = null; + const rigsJsonResult = await executeGT(['rig', 'list', '--json']); + if (rigsJsonResult.success) { + try { + const parsed = JSON.parse(rigsJsonResult.data); + if (Array.isArray(parsed)) { + rigNames = parsed.map((rig) => rig.name).filter(Boolean); + } + } catch { + // JSON parse failed — fall through to text parsing + } + } + if (rigNames === null) { + const rigsTextResult = await executeGT(['rig', 'list']); + if (!rigsTextResult.success) { + return res.json(links); + } + // Parse rig names from both legacy and emoji-prefixed formats + rigNames = parseRigNames(rigsTextResult.data).map((rig) => rig.name); } - - // Parse rig names from both legacy and emoji-prefixed formats - const rigNames = parseRigNames(rigsResult.data).map((rig) => rig.name); console.log(`[Links] Found rigs: ${rigNames.join(', ')}`);