Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ const root=document.querySelector('#flow-detail'),flowId=root.dataset.flowId;
const esc=v=>{const d=document.createElement('div');d.textContent=v??'';return d.innerHTML};
const time=v=>new Date(v).toLocaleString();
const badge=(value,good)=>'<span class="rounded-full px-2.5 py-1 text-xs font-medium '+(good?'bg-factorize-50 text-factorize-700 dark:bg-factorize-500/20 dark:text-factorize-100':'bg-stone-100 text-slate-600 dark:bg-slate-800 dark:text-slate-300')+'">'+esc(value)+'</span>';
const issueLink=(id,url)=>{if(!id)return '—';const trusted=typeof url==='string'&&(url.startsWith('https://linear.app/')||/^https:\/\/github\.com\/[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+\/pull\/\d+$/.test(url));const href=trusted?url:'https://linear.app/issue/'+encodeURIComponent(id);return '<a class="font-medium text-factorize-700 hover:underline dark:text-factorize-500" href="'+href+'" target="_blank" rel="noreferrer">'+esc(id)+' ↗</a>'};
const issueLink=(id,url)=>{if(!id)return '—';const trusted=typeof url==='string'&&(url.startsWith('https://linear.app/')||/^https:\\/\\/github\\.com\\/[A-Za-z0-9_.-]+\\/[A-Za-z0-9_.-]+\\/pull\\/\\d+$/.test(url));const href=trusted?url:'https://linear.app/issue/'+encodeURIComponent(id);return '<a class="font-medium text-factorize-700 hover:underline dark:text-factorize-500" href="'+href+'" target="_blank" rel="noreferrer">'+esc(id)+' ↗</a>'};
async function load(){const response=await fetch('/api/pipes/'+encodeURIComponent(flowId));if(response.status===401)return location.href='/auth/linear';if(!response.ok){root.innerHTML='<p class="rounded-xl border border-red-200 bg-red-50 p-4 text-sm text-red-700 dark:border-red-900 dark:bg-red-950/50 dark:text-red-200">Could not load this flow.</p>';return}const data=await response.json(),flow=data.flow,events=data.events||[],runs=data.runs||[];const eventRows=events.map(event=>'<tr class="border-t border-stone-200 dark:border-slate-800"><td class="py-3 pr-4 text-slate-500 dark:text-slate-400">'+time(event.received_at)+'</td><td class="py-3 pr-4">'+issueLink(event.issue_id,event.issue_url)+'</td><td class="py-3 pr-4">'+esc(event.event_type)+' · '+esc(event.event_action)+'</td><td class="py-3 pr-4">'+badge(event.outcome,event.outcome==='triggered')+'</td><td class="py-3 text-slate-500 dark:text-slate-400">'+esc(event.detail)+'</td></tr>').join('')||'<tr><td colspan="5" class="py-8 text-slate-500 dark:text-slate-400">No relevant webhooks yet. Update an issue in this flow’s Linear project to see it here.</td></tr>';const runRows=runs.map(run=>'<tr class="border-t border-stone-200 dark:border-slate-800"><td class="py-3 pr-4">'+issueLink(run.issue_id,run.issue_url)+'</td><td class="py-3 pr-4"><span class="font-medium">'+esc(run.agent_kind||flow.agent_kind||'Herdr agent')+'</span><span class="block text-xs text-slate-500 dark:text-slate-400">'+esc(run.agent_name)+'</span></td><td class="py-3 pr-4">'+esc(run.workspace_name||flow.workspace_name||'—')+'</td><td class="py-3 pr-4">'+badge(run.state,['queued','starting','running','done'].includes(run.state))+'</td><td class="py-3 text-slate-500 dark:text-slate-400">'+time(run.updated_at)+'</td></tr>').join('')||'<tr><td colspan="5" class="py-8 text-slate-500 dark:text-slate-400">No agent runs yet.</td></tr>';root.innerHTML='<div class="flex flex-wrap items-start justify-between gap-4"><div><h1 class="text-3xl font-bold tracking-tight">'+esc(flow.name)+'</h1><p class="mt-2 text-slate-600 dark:text-slate-400">'+esc(flow.filter_type)+' trigger · '+esc(flow.max_concurrency)+' concurrent agents · '+esc(flow.agent_kind||'Herdr agent')+' · workspace '+esc(flow.workspace_name||'—')+'</p></div><a href="/flows/'+encodeURIComponent(flow.id)+'/edit" class="rounded-xl bg-slate-950 px-4 py-2.5 text-sm font-semibold text-white hover:bg-slate-800 dark:bg-white dark:text-slate-950 dark:hover:bg-slate-200">Edit Flow</a></div><section class="mt-9 rounded-2xl border border-stone-200 bg-white shadow-sm dark:border-slate-800 dark:bg-slate-900"><div class="border-b border-stone-200 px-6 py-5 dark:border-slate-800"><h2 class="font-semibold">Webhook activity</h2><p class="mt-1 text-sm text-slate-500 dark:text-slate-400">Relevant Linear webhooks and whether they queued an agent.</p></div><div class="overflow-x-auto px-6"><table class="w-full text-left text-sm"><thead class="text-xs uppercase tracking-wide text-slate-500 dark:text-slate-400"><tr><th class="py-3 pr-4">Received</th><th class="py-3 pr-4">Issue</th><th class="py-3 pr-4">Event</th><th class="py-3 pr-4">Result</th><th class="py-3">Details</th></tr></thead><tbody>'+eventRows+'</tbody></table></div></section><section class="mt-6 rounded-2xl border border-stone-200 bg-white shadow-sm dark:border-slate-800 dark:bg-slate-900"><div class="border-b border-stone-200 px-6 py-5 dark:border-slate-800"><h2 class="font-semibold">Agent runs</h2></div><div class="overflow-x-auto px-6"><table class="w-full text-left text-sm"><thead class="text-xs uppercase tracking-wide text-slate-500 dark:text-slate-400"><tr><th class="py-3 pr-4">Issue</th><th class="py-3 pr-4">Herdr agent</th><th class="py-3 pr-4">Workspace</th><th class="py-3 pr-4">State</th><th class="py-3">Updated</th></tr></thead><tbody>'+runRows+'</tbody></table></div></section>'}
const renderActivity=load;
load=async()=>{await renderActivity();const response=await fetch('/api/pipes/'+encodeURIComponent(flowId));if(!response.ok)return;const data=await response.json(),runs=(data.runs||[]).filter(run=>run.state!=='ignored');if(!runs.length)return;const diagnostics=runs.map(run=>'<article class="border-t border-stone-200 px-6 py-5 dark:border-slate-800"><div class="flex items-center justify-between gap-4"><span class="font-medium">'+esc(run.agent_name)+'</span><span class="text-sm text-slate-500">'+(run.exec_status!=null?'HTTP '+esc(String(run.exec_status))+(run.exec_exit_code!=null?' · VM exit '+esc(String(run.exec_exit_code)):'' ):esc(run.state))+'</span></div>'+(run.exec_status!=null?'<div class="mt-4 grid gap-4 lg:grid-cols-2"><div><p class="mb-1 text-xs font-semibold uppercase tracking-wide text-slate-500">Exact command submitted to exe.dev</p><pre class="overflow-x-auto whitespace-pre-wrap rounded-lg bg-slate-950 p-3 text-xs text-slate-100">'+esc(run.exec_request)+'</pre></div><div><p class="mb-1 text-xs font-semibold uppercase tracking-wide text-slate-500">Actual exe.dev response</p><pre class="overflow-x-auto whitespace-pre-wrap rounded-lg bg-slate-950 p-3 text-xs text-slate-100">'+esc(run.exec_response)+'</pre></div></div>':'<p class="mt-4 rounded-lg bg-amber-50 p-3 text-sm text-amber-800 dark:bg-amber-950/40 dark:text-amber-200">No exe.dev request or response was recorded for this run. It did not reach the VM-command step.</p>')+(run.result?'<div class="mt-4"><p class="mb-1 text-xs font-semibold uppercase tracking-wide text-slate-500">Herdr agent output</p><pre class="overflow-x-auto whitespace-pre-wrap rounded-lg bg-slate-950 p-3 text-xs text-slate-100">'+esc(run.result)+'</pre></div>':'')+'</article>').join('');root.insertAdjacentHTML('beforeend','<section class="mt-6 overflow-hidden rounded-2xl border border-stone-200 bg-white shadow-sm dark:border-slate-800 dark:bg-slate-900"><div class="border-b border-stone-200 px-6 py-5 dark:border-slate-800"><h2 class="font-semibold">Actual exe.dev command results</h2><p class="mt-1 text-sm text-slate-500 dark:text-slate-400">Only real agent runs appear here. The bearer token is never shown.</p></div>'+diagnostics+'</section>')};
Expand Down
7 changes: 7 additions & 0 deletions test/ui.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ import { describe, expect, it } from "vitest";
import { flowDetailPage, flowPage, landingPage } from "../src/ui";

describe("pages", () => {
const expectInlineScriptsToParse = (html: string) => {
const scripts = [...html.matchAll(/<script>([\s\S]*?)<\/script>/g)].map((match) => match[1]);
expect(scripts.length).toBeGreaterThan(0);
scripts.forEach((script) => expect(() => new Function(script)).not.toThrow());
};

it("renders the simple landing page and theme control", () => {
const html = landingPage(null);
expect(html).toContain("No-code Software Factories");
Expand Down Expand Up @@ -62,6 +68,7 @@ describe("pages", () => {
expect(html).toContain("Prompt sent to agent");
expect(html).toContain("Full agent output");
expect(html).toContain('max-h-[32rem] overflow-auto');
expectInlineScriptsToParse(html);
});

it("escapes profile data", () => {
Expand Down
Loading