caelum0x 174222bcaa feat: Builder-Track named-user tools, bio + evidence-intelligence platform, Apache-2.0
Builds PaperTrail from the base skeleton into a full evidence-verification platform
for the "Built with Claude: Life Sciences" hackathon (Builder Track).

New named-user features (Build Beyond the Bench):
- Lab Notebook Companion — rough bench notes -> structured, searchable, grounded
  experiment records (lib/labNotebook, /console/lab-notebook, migration 0059)
- Clinical Trial Matcher — de-identified patient notes -> ranked eligible
  ClinicalTrials.gov trials with per-criterion inclusion/exclusion reasoning
  (lib/trialMatcher, /console/trial-matcher, migrations 0060)

Platform:
- Deterministic verification moat (biostats recompute, exact-span grounding)
- 11 biomedical evidence engines (FAERS, GWAS, Open Targets, ChEMBL, ClinVar,
  PharmGKB, PubTator, DDI, repurposing, biomarker, unified verifier)
- Evidence Intelligence (KG, dossier, provenance/export, RWE) + enterprise
  governance (RBAC, /api/v1 gateway, metering, audit chain, retention)
- 17 OSS projects assimilated into native TypeScript on our stack (backend/engines
  retained + credited in NOTICE)
- Multi-format upload (PDF/DOCX/XLSX/CSV/MD/TXT), logo, marketing site
- Next.js 16 upgrade, benchmark harness (honest smoke-test caveat)

Licensing: Apache-2.0 (LICENSE + NOTICE).
2026-07-10 16:23:13 +03:00

576 lines
23 KiB
HTML

{% extends "base.html" %}
{% block head_extra %}
<style>
.trace-toolbar {
display: flex;
flex-wrap: wrap;
gap: 10px;
margin-bottom: 16px;
}
.help-link {
display: inline-flex;
align-items: center;
justify-content: center;
width: 26px;
height: 26px;
border-radius: 50%;
background: rgba(15, 118, 110, 0.1);
color: #0f766e;
font-size: 0.82rem;
font-weight: 700;
text-decoration: none;
}
.help-link:hover {
background: #0f766e;
color: #fff;
}
.trace-toolbar a,
.trace-toolbar button {
border: 1px solid #ccc;
background: #f7f7f7;
color: #222;
padding: 8px 12px;
border-radius: 6px;
text-decoration: none;
cursor: pointer;
font-size: 14px;
}
.trace-toolbar button:hover,
.trace-toolbar a:hover {
background: #ececec;
}
.trace-toolbar button.primary {
background: #0f62fe;
border-color: #0f62fe;
color: #fff;
}
.trace-toolbar button.primary:hover {
background: #0353e9;
}
.trace-toolbar button[disabled] {
cursor: not-allowed;
opacity: 0.6;
}
.trace-summary {
border: 1px solid #ddd;
border-radius: 8px;
padding: 12px;
background: #fafafa;
margin-bottom: 16px;
}
.trace-summary-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
gap: 10px;
}
.trace-summary-card {
border: 1px solid #e3e3e3;
border-radius: 8px;
background: #fff;
padding: 10px;
}
.trace-summary-card p {
margin: 4px 0;
}
.trace-list {
display: grid;
gap: 12px;
}
.trace-row {
border: 1px solid #ddd;
border-left: 6px solid #bbb;
border-radius: 8px;
padding: 12px;
background: #fff;
}
.trace-row.success {
border-left-color: #2e8540;
}
.trace-row.retrying {
border-left-color: #b38600;
}
.trace-row.error {
border-left-color: #b22222;
}
.trace-row.highlight {
border-color: #0f62fe;
box-shadow: 0 0 0 2px rgba(15, 98, 254, 0.2);
background: #f4f8ff;
}
.trace-row.error-like {
background: #fff9f9;
}
.trace-head {
display: flex;
justify-content: space-between;
align-items: flex-start;
gap: 10px;
}
.trace-meta {
margin: 8px 0 0 0;
line-height: 1.5;
}
.trace-timing {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
gap: 8px;
margin-top: 12px;
padding: 10px;
border: 1px solid #e6e6e6;
border-radius: 6px;
background: #fafafa;
}
.trace-timing div {
line-height: 1.4;
}
.trace-badge {
display: inline-block;
font-size: 12px;
border-radius: 10px;
padding: 2px 8px;
border: 1px solid #ccc;
background: #f2f2f2;
text-transform: uppercase;
letter-spacing: 0.4px;
}
.trace-row.success .trace-badge {
border-color: #2e8540;
color: #2e8540;
background: #effaf1;
}
.trace-row.retrying .trace-badge {
border-color: #b38600;
color: #7d5f00;
background: #fff8e6;
}
.trace-row.error .trace-badge {
border-color: #b22222;
color: #8f1b1b;
background: #fff1f1;
}
.trace-error {
margin-top: 10px;
padding: 10px;
border: 1px solid #f5c2c7;
background: #fff0f2;
border-radius: 6px;
}
details {
margin-top: 8px;
border: 1px solid #e6e6e6;
border-radius: 6px;
padding: 6px 10px;
background: #fcfcfc;
}
summary {
cursor: pointer;
font-weight: 600;
}
pre {
margin: 8px 0 0 0;
white-space: pre-wrap;
word-break: break-word;
max-height: 320px;
overflow: auto;
background: #111827;
color: #e5e7eb;
padding: 10px;
border-radius: 6px;
}
.status-message {
margin: 10px 0;
padding: 10px;
border-radius: 6px;
}
.status-message.error {
border: 1px solid #f5c2c7;
background: #fff0f2;
}
.status-message.info {
border: 1px solid #bee3f8;
background: #ebf8ff;
}
</style>
{% endblock %}
{% block content %}
<section class="panel">
<p><strong>Batch:</strong> <span id="batchLabel"></span> | <strong>Claim:</strong> <span id="claimLabel"></span></p>
<div class="trace-toolbar">
<a id="backToReport" href="#">Back to Report</a>
<a id="downloadTrace" href="#">Download Trace File</a>
<a id="downloadIssues" href="#">Download Issues File</a>
<button id="jumpToHighlight" type="button">Jump to Highlight</button>
<button id="resumeClaim" class="primary" type="button" hidden>Resume Claim</button>
<a href="/guidebook#trace-view" class="help-link" title="Guidebook: Trace View">?</a>
</div>
<div id="statusMessage"></div>
<div id="traceSummary" class="trace-summary"></div>
<div id="traceList" class="trace-list"></div>
</section>
{% endblock %}
{% block scripts %}
<script>
const batchId = {{ batch_id | tojson }};
const claimId = {{ claim_id | tojson }};
const initialFocusTraceId = {{ focus_trace_id | tojson }};
const statusMessage = document.getElementById('statusMessage');
const traceSummary = document.getElementById('traceSummary');
const traceList = document.getElementById('traceList');
const batchLabel = document.getElementById('batchLabel');
const claimLabel = document.getElementById('claimLabel');
const resumeButton = document.getElementById('resumeClaim');
let currentHighlightedIndices = [];
let currentResumeStage = null;
let currentResumeReason = null;
function escapeHtml(value) {
return String(value ?? '')
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#039;');
}
function prettyJson(value) {
try {
return JSON.stringify(value, null, 2);
} catch (error) {
return String(value ?? '');
}
}
function renderStatus(message, cls) {
statusMessage.innerHTML = `<div class="status-message ${cls}">${escapeHtml(message)}</div>`;
const ui = window.ValsciUI;
if (ui?.isInViewport && !ui.isInViewport(statusMessage)) {
ui.showToast({ message, tone: cls === 'error' ? 'error' : 'info' });
}
}
function buildQuery(params) {
const filtered = Object.entries(params)
.filter(([, value]) => value !== null && value !== undefined && String(value).trim() !== '');
if (filtered.length === 0) {
return '';
}
const query = new URLSearchParams();
filtered.forEach(([key, value]) => query.set(key, value));
return `?${query.toString()}`;
}
function scrollToHighlight() {
if (!Array.isArray(currentHighlightedIndices) || currentHighlightedIndices.length === 0) {
return;
}
const first = currentHighlightedIndices[0];
const row = document.getElementById(`trace-record-${first}`);
if (row) {
row.scrollIntoView({ behavior: 'smooth', block: 'center' });
}
}
function formatDurationMs(value) {
if (value === null || value === undefined || value === '') {
return 'n/a';
}
const totalMs = Number(value);
if (!Number.isFinite(totalMs)) {
return 'n/a';
}
if (totalMs < 1000) {
return `${totalMs} ms`;
}
const totalSeconds = totalMs / 1000;
if (totalSeconds < 60) {
return `${totalSeconds.toFixed(2)} s`;
}
const minutes = Math.floor(totalSeconds / 60);
const seconds = totalSeconds % 60;
return `${minutes}m ${seconds.toFixed(1)}s`;
}
function formatSeconds(value) {
if (value === null || value === undefined || value === '') {
return 'n/a';
}
const totalSeconds = Number(value);
if (!Number.isFinite(totalSeconds)) {
return 'n/a';
}
if (totalSeconds < 60) {
return `${totalSeconds} s`;
}
const minutes = Math.floor(totalSeconds / 60);
const seconds = totalSeconds % 60;
return `${minutes}m ${seconds}s`;
}
function humanizeClaimLocation(value) {
if (value === 'queued_jobs') {
return 'queued_jobs';
}
if (value === 'saved_jobs') {
return 'saved_jobs';
}
return 'unknown';
}
function updateResumeButton(payload) {
currentResumeStage = payload.resume_stage || null;
currentResumeReason = payload.resume_reason || null;
if (payload.resume_available) {
resumeButton.hidden = false;
resumeButton.disabled = false;
const stageLabel = payload.resume_stage ? ` (${payload.resume_stage})` : '';
resumeButton.textContent = `Resume Claim${stageLabel}`;
return;
}
resumeButton.hidden = true;
resumeButton.disabled = true;
resumeButton.textContent = 'Resume Claim';
}
function renderSummary(records, errorLikeIndices, highlightedIndices, focusedIndex, invalidLines, traceFile, payload) {
const successCount = records.filter(r => (r.status || '').toLowerCase() === 'success').length;
const retryCount = records.filter(r => (r.status || '').toLowerCase() === 'retrying').length;
const errorCount = records.filter(r => (r.status || '').toLowerCase() === 'error').length;
const totalLatencyMs = records.reduce((sum, record) => sum + (Number(record.latency_ms) || 0), 0);
const timeoutCount = records.filter(record => Boolean(record.timed_out)).length;
const focusText = focusedIndex !== null && focusedIndex !== undefined
? `Focused trace index: ${focusedIndex + 1}`
: highlightedIndices.length > 0
? `Auto-highlighted trace index: ${highlightedIndices[0] + 1}`
: 'No highlighted trace';
traceSummary.innerHTML = `
<h3>Summary</h3>
<div class="trace-summary-grid">
<div class="trace-summary-card">
<p><strong>Claim Status:</strong> ${escapeHtml(payload.claim_status || 'unknown')}</p>
<p><strong>Claim Location:</strong> ${escapeHtml(humanizeClaimLocation(payload.claim_location))}</p>
<p><strong>Resume Available:</strong> ${payload.resume_available ? 'Yes' : 'No'}</p>
<p><strong>Resume Stage:</strong> ${escapeHtml(payload.resume_stage || 'n/a')}</p>
</div>
<div class="trace-summary-card">
<p><strong>Total Calls:</strong> ${records.length}</p>
<p><strong>Success / Retrying / Error:</strong> ${successCount} / ${retryCount} / ${errorCount}</p>
<p><strong>Timeout Attempts:</strong> ${timeoutCount}</p>
<p><strong>Total Attempt Time:</strong> ${escapeHtml(formatDurationMs(totalLatencyMs))}</p>
</div>
<div class="trace-summary-card">
<p><strong>Error-like Entries:</strong> ${errorLikeIndices.length}</p>
<p><strong>Focus:</strong> ${escapeHtml(focusText)}</p>
<p><strong>Invalid Trace Lines Skipped:</strong> ${invalidLines}</p>
<p><strong>Trace File:</strong> ${escapeHtml(traceFile || '')}</p>
</div>
</div>
<p style="margin-top: 12px;"><strong>Resume Reason:</strong> ${escapeHtml(payload.resume_reason || 'n/a')}</p>
`;
}
function renderTraceRows(records, highlightedIndices, errorLikeIndices) {
const highlightedSet = new Set(highlightedIndices || []);
const errorLikeSet = new Set(errorLikeIndices || []);
traceList.innerHTML = records.map((record, idx) => {
const status = String(record.status || 'unknown').toLowerCase();
const stage = record.stage || 'unknown_stage';
const traceId = record.trace_id || '';
const isHighlighted = highlightedSet.has(idx);
const isErrorLike = errorLikeSet.has(idx);
const openAttr = isHighlighted ? 'open' : '';
const klass = `trace-row ${escapeHtml(status)}${isHighlighted ? ' highlight' : ''}${isErrorLike ? ' error-like' : ''}`;
const permalink = traceId
? `/claims/${encodeURIComponent(batchId)}/${encodeURIComponent(claimId)}/trace${buildQuery({ focus_trace_id: traceId })}`
: '';
return `
<article id="trace-record-${idx}" class="${klass}">
<div class="trace-head">
<div>
<h3>${idx + 1}. ${escapeHtml(stage)}</h3>
<div class="trace-meta">
<div><strong>Trace ID:</strong> ${escapeHtml(traceId || 'n/a')}</div>
<div><strong>Model:</strong> ${escapeHtml(record.model_used || record.model_requested || 'n/a')}</div>
<div><strong>Latency:</strong> ${escapeHtml(record.latency_ms ?? 'n/a')} ms</div>
<div><strong>Time:</strong> ${escapeHtml(record.timestamp_start || 'n/a')} - ${escapeHtml(record.timestamp_end || 'n/a')}</div>
</div>
</div>
<div>
<span class="trace-badge">${escapeHtml(status)}</span>
${permalink ? `<div style="margin-top:8px;"><a href="${permalink}">Permalink</a></div>` : ''}
</div>
</div>
<div class="trace-timing">
<div><strong>Elapsed:</strong> ${escapeHtml(formatDurationMs(record.latency_ms))}</div>
<div><strong>Configured Timeout:</strong> ${escapeHtml(formatSeconds(record.timeout_configured_s))}</div>
<div><strong>Timeout Source:</strong> ${escapeHtml(record.timeout_source || 'n/a')}</div>
<div><strong>Timed Out:</strong> ${record.timed_out ? 'Yes' : 'No'}</div>
</div>
${(record.parse_error || record.error_message || record.error_type) ? `
<div class="trace-error">
${record.error_type ? `<div><strong>Error Type:</strong> ${escapeHtml(record.error_type)}</div>` : ''}
${record.error_message ? `<div><strong>Error Message:</strong> ${escapeHtml(record.error_message)}</div>` : ''}
${record.parse_error ? `<div><strong>Parse Error:</strong> ${escapeHtml(record.parse_error)}</div>` : ''}
</div>
` : ''}
<details ${openAttr}>
<summary>Usage + Routing</summary>
<pre>${escapeHtml(prettyJson({
usage: record.usage,
retries: record.retries,
finish_reason: record.finish_reason,
timeout_configured_s: record.timeout_configured_s,
timeout_source: record.timeout_source,
timed_out: record.timed_out,
backoff_waited_s: record.backoff_waited_s,
http_status: record.http_status,
routing: record.routing
}))}</pre>
</details>
<details>
<summary>Messages</summary>
<pre>${escapeHtml(prettyJson(record.messages || []))}</pre>
</details>
<details>
<summary>Parsed JSON</summary>
<pre>${escapeHtml(prettyJson(record.parsed_json || null))}</pre>
</details>
<details>
<summary>Raw Output</summary>
<pre>${escapeHtml(record.raw_output || '')}</pre>
</details>
<details>
<summary>Raw Response</summary>
<pre>${escapeHtml(prettyJson(record.raw_response || null))}</pre>
</details>
<details>
<summary>Stacktrace</summary>
<pre>${escapeHtml(record.stacktrace || '')}</pre>
</details>
</article>
`;
}).join('');
}
async function loadTrace() {
const query = buildQuery({ focus_trace_id: initialFocusTraceId });
const url = `/api/v1/claims/${encodeURIComponent(batchId)}/${encodeURIComponent(claimId)}/trace_records${query}`;
try {
const response = await fetch(url);
const payload = await response.json();
if (!response.ok) {
renderStatus(payload.error || 'Failed to load trace records.', 'error');
traceSummary.innerHTML = '';
traceList.innerHTML = '';
return;
}
const records = Array.isArray(payload.records) ? payload.records : [];
const highlighted = Array.isArray(payload.highlighted_indices) ? payload.highlighted_indices : [];
const errorLike = Array.isArray(payload.error_like_indices) ? payload.error_like_indices : [];
currentHighlightedIndices = highlighted;
updateResumeButton(payload);
if (records.length === 0) {
renderStatus('Trace file loaded, but no records were found.', 'info');
} else if (highlighted.length > 0) {
renderStatus('Trace loaded. A relevant section is highlighted below.', 'info');
} else {
renderStatus('Trace loaded. No specific call was highlighted.', 'info');
}
renderSummary(
records,
errorLike,
highlighted,
payload.focused_index,
payload.invalid_lines || 0,
payload.trace_file || '',
payload
);
renderTraceRows(records, highlighted, errorLike);
scrollToHighlight();
} catch (error) {
console.error('Error loading trace records:', error);
renderStatus('Error loading trace records.', 'error');
traceSummary.innerHTML = '';
traceList.innerHTML = '';
}
}
batchLabel.textContent = batchId;
claimLabel.textContent = claimId;
document.getElementById('backToReport').href =
`/results?batch_id=${encodeURIComponent(batchId)}&claim_id=${encodeURIComponent(claimId)}`;
document.getElementById('downloadTrace').href =
`/api/v1/claims/${encodeURIComponent(batchId)}/${encodeURIComponent(claimId)}/trace`;
document.getElementById('downloadIssues').href =
`/api/v1/claims/${encodeURIComponent(batchId)}/${encodeURIComponent(claimId)}/issues`;
document.getElementById('jumpToHighlight').addEventListener('click', () => {
scrollToHighlight();
});
resumeButton.addEventListener('click', async () => {
const stageText = currentResumeStage ? ` to ${currentResumeStage}` : '';
const reasonText = currentResumeReason ? `\n\nReason: ${currentResumeReason}` : '';
const confirmed = window.confirm(
`Resume claim ${claimId}${stageText}?${reasonText}`
);
if (!confirmed) {
return;
}
resumeButton.disabled = true;
try {
const response = await fetch(
`/api/v1/claims/${encodeURIComponent(batchId)}/${encodeURIComponent(claimId)}/resume`,
{ method: 'POST' }
);
const payload = await response.json();
if (!response.ok) {
renderStatus(payload.error || 'Failed to resume claim.', 'error');
window.ValsciUI?.flashButton?.(resumeButton, { label: 'Resume failed ✗', tone: 'error' });
resumeButton.disabled = false;
return;
}
renderStatus(
`Claim resumed to ${payload.resume_to_status}. The processor can pick it up on the next scan.`,
'info'
);
window.ValsciUI?.flashButton?.(resumeButton, { label: 'Resumed ✓' });
await loadTrace();
} catch (error) {
console.error('Error resuming claim:', error);
renderStatus('Error resuming claim.', 'error');
window.ValsciUI?.flashButton?.(resumeButton, { label: 'Resume failed ✗', tone: 'error' });
resumeButton.disabled = false;
}
});
loadTrace();
</script>
{% endblock %}