From b69d7e5386bb46702f715160f1e314da9d650d3d Mon Sep 17 00:00:00 2001 From: OpenClaw Bot Date: Wed, 27 May 2026 01:08:27 +0200 Subject: [PATCH] Expose bridge handoff status in Ranker results --- public/app.js | 69 ++++++++++++++++++++++++++++++++++++++++++++--- public/styles.css | 1 + 2 files changed, 67 insertions(+), 3 deletions(-) diff --git a/public/app.js b/public/app.js index 9944379..04e6ecd 100644 --- a/public/app.js +++ b/public/app.js @@ -52,10 +52,14 @@ function laneClass(lane) { } function parsePastedJsonPayload(value) { - const text = String(value || '').trim(); - if (!text.startsWith('{') || !text.endsWith('}')) return null; + const text = String(value || '').trim() + .replace(/^```(?:json)?\s*/i, '') + .replace(/```$/i, '') + .trim(); + const jsonText = text.startsWith('{') && text.endsWith('}') ? text : extractFirstJsonObject(text); + if (!jsonText) return null; try { - const parsed = JSON.parse(text); + const parsed = JSON.parse(jsonText); const looksLikeBridgePayload = parsed && typeof parsed === 'object' && !Array.isArray(parsed) && ( parsed.schema || parsed.featureSet || parsed.conceptMap || parsed.lenses || parsed.reference_code || parsed.referenceCode || parsed.artifactId || parsed.ideaText ); @@ -65,6 +69,36 @@ function parsePastedJsonPayload(value) { } } +function extractFirstJsonObject(text = '') { + const start = text.indexOf('{'); + if (start < 0) return ''; + let depth = 0; + let inString = false; + let escaped = false; + for (let index = start; index < text.length; index += 1) { + const char = text[index]; + if (escaped) { + escaped = false; + continue; + } + if (char === '\\' && inString) { + escaped = true; + continue; + } + if (char === '"') { + inString = !inString; + continue; + } + if (inString) continue; + if (char === '{') depth += 1; + if (char === '}') { + depth -= 1; + if (depth === 0) return text.slice(start, index + 1); + } + } + return ''; +} + function payloadFromForm(formPayload) { const ideaJson = parsePastedJsonPayload(formPayload.idea); const optionsJson = parsePastedJsonPayload(formPayload.optionsText); @@ -94,6 +128,33 @@ function renderPills(items = []) { return `
${items.map((item) => `${escapeHtml(item)}`).join('')}
`; } +function renderSourceTrace(sourceTrace = {}) { + const hasTrace = sourceTrace.sourceSection || sourceTrace.sourceId || sourceTrace.sourceQuote; + if (!hasTrace) return ''; + const label = [sourceTrace.sourceTitle, sourceTrace.sourceId || sourceTrace.sourceSection].filter(Boolean).join(' ยท '); + return ` +
+ Source trace + ${label ? `${escapeHtml(label)}` : ''} + ${sourceTrace.sourceQuote ? `

${escapeHtml(sourceTrace.sourceQuote)}

` : ''} +
+ `; +} + +function renderHandoffStatus(handoff = {}) { + const readiness = handoff.readiness || {}; + if (!readiness.status) return ''; + const warnings = handoff.warnings || []; + return ` +
+ Bridge handoff readiness +

${escapeHtml(readiness.label || readiness.status)} โ€” ${escapeHtml(readiness.summary || '')}

+ ${(readiness.nextChecks || []).length ? `
    ${readiness.nextChecks.map((step) => `
  1. ${escapeHtml(step)}
  2. `).join('')}
` : ''} + ${warnings.length ? `
${warnings.map((warning) => `${escapeHtml(warning)}`).join('')}
` : ''} +
+ `; +} + function renderRankCard(item) { return `
@@ -198,6 +259,7 @@ function renderResults(data) {
Proof to collect

${escapeHtml(glance.evidenceQuestion || 'Name the evidence that would change the ranking.')}

Trap to avoid

${escapeHtml(glance.biggestTrap || brief.caution || 'Do not treat first-pass judgement as final truth.')}

+ ${renderSourceTrace(glance.sourceTrace || {})}
@@ -218,6 +280,7 @@ function renderResults(data) { Rank confidence

${escapeHtml(data.rankConfidence?.level || 'First pass')} โ€” ${escapeHtml(data.rankConfidence?.reason || brief.caution || '')}

+ ${renderHandoffStatus(data.handoff || {})} ${(brief.whatWouldChangeRanking || []).length ? `
What would change the order diff --git a/public/styles.css b/public/styles.css index 4e55cf8..5392175 100644 --- a/public/styles.css +++ b/public/styles.css @@ -39,3 +39,4 @@ button,input,textarea{font:inherit} button{cursor:pointer} a{color:inherit;text- .lane-column .rank-card{box-shadow:none;margin:0;border-width:1.5px}.lane-column .rank-card h3{font-size:clamp(20px,2vw,28px)}.lane-column .metrics{grid-template-columns:1fr}.signal-pills{margin:10px 0}.signal-pills span{background:#f0e8d9;font-size:10px;padding:5px 8px}.action-strip{display:grid;grid-template-columns:repeat(3,1fr);gap:8px;margin:14px 0}.action-strip>div{border:1.5px solid var(--hair);background:#fff6e6;padding:10px}.action-strip span{color:var(--blue2);font-size:10px}.action-strip p{margin:0;font-size:13px;line-height:1.35}.reflection-room{margin-top:24px}.expert-card{position:relative}.expert-card::before{content:"โ€œ";position:absolute;right:14px;top:0;font-size:72px;line-height:1;color:rgba(36,92,255,.16);font-weight:1000} @media (max-width:1100px){.lane-board{grid-template-columns:repeat(2,minmax(0,1fr))}.quick-glance{grid-template-columns:repeat(2,minmax(0,1fr))}.action-strip{grid-template-columns:1fr}} @media (max-width:700px){.lane-board,.quick-glance{grid-template-columns:1fr}.memo-head::after{position:static;display:inline-block;margin-top:14px;transform:none}.result-actions .button{width:100%;justify-content:center}.quick-glance{box-shadow:6px 6px 0 var(--ink)}.quick-glance>div{min-height:auto}} +.source-trace{margin:-4px 0 22px;padding:14px 16px;border:2px dashed var(--ink);background:#fff6e5;color:var(--ink2);box-shadow:5px 5px 0 rgba(21,19,15,.16)}.source-trace span,.handoff-card>span{display:block;margin-bottom:8px;color:var(--blue2);text-transform:uppercase;letter-spacing:.12em;font-size:11px;font-weight:1000}.source-trace b{display:block;margin-bottom:6px;font-size:14px}.source-trace p{margin:0;color:var(--muted);line-height:1.45}.handoff-card{border-left:8px solid var(--green)}.handoff-card.status-usable-with-warnings{border-left-color:var(--amber)}.handoff-card.status-needs-source-context,.handoff-card.status-blocked{border-left-color:var(--red)}.handoff-warnings{display:grid;gap:6px;margin-top:12px}.handoff-warnings code{display:block;white-space:normal;border:1px solid var(--hair);background:#f3eee4;padding:7px 9px;font-size:12px;color:var(--ink2)}