{# Patched Logs surface — drop into whilly/api/templates/_logs.html and add an `htmx-route` that returns this fragment for ?fragment=logs. Expected context vars: task_id str | None currently selected task tasks list[Task] candidates for the dropdown log_lines list[LogLine] {ts, level, msg} tokens_used int tokens_budget int cost_usd float status str DONE / FAILED / IN_PROGRESS / … Server-Sent Events: - sse:log.append-{task_id} appends a line via hx-swap="beforeend" - sse:task.status-{task_id} swaps the status + meter region #}
Logs{% if task_id %} · {{ task_id }}{% endif %} {% if status %}{{ status }}{% endif %}
Download .jsonl
{% if task_id %}
Task
{{ task_id }}
Tokens
{% set pct = (tokens_used / tokens_budget) if tokens_budget else 0 %} {% set lvl = 'danger' if pct > 0.9 else ('warn' if pct > 0.6 else '') %}
{{ "{:,}".format(tokens_used) }} / {{ "{:,}".format(tokens_budget) }} tok
Cost
${{ "%.2f"|format(cost_usd) }} USD
{% endif %}
{% if log_lines %} {% for line in log_lines %}
{{ line.ts }} [{{ line.level }}] {{ line.msg }}
{% endfor %} {% else %}
--:--:-- [INFO] No log lines for this task.
{% endif %}