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 .github/scripts/integration-governance.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const MAX_COMMITS = 1000;
const MAX_AUTHOR_BATCH = 50;
// This literal is inside the enrolled .github closure. A caller-supplied
// preparedBy.sourceSHA must never choose a new executable verifier tree.
const TRUSTED_SCRIPTS_TREE = 'ff53044755a6b1a79a28925df7a4dd61d71462bb';
const TRUSTED_SCRIPTS_TREE = '109f0f1af9f90cbdf4a7b433b22a0765bdb41d74';
const SOURCE = 'https://github.com/kubernetes-sigs/kubebuilder-release-tools/tree/012269a88fa4c034a0acf1ba84c26b195c0dbab4';
const sha = value => crypto.createHash('sha256').update(value).digest('hex');
const git = (args, cwd = process.cwd()) =>
Expand Down
1 change: 1 addition & 0 deletions changelog.d/added-kick-outcomes-ui.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- The dashboard agent detail panel now shows recent kick outcomes, with trigger, timing, PR, commit and refusal evidence for read-write users and owners, and only the latest one-line summary for read-only users ([#19032](https://github.com/hivecommons/hive/issues/19032)).
90 changes: 90 additions & 0 deletions src/pkg/dashboard/kick_outcomes.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
const test = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const path = require('node:path');
const source = fs.readFileSync(path.join(__dirname, 'static-src/js/kick-outcomes.js'), 'utf8');
const esc = value => String(value).replace(/[&<>"']/g, c => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c]));
function build(document = {}, fetch = () => {}, formatDashboardDateTime = date => date.toISOString()) {
return new Function('esc', 'document', 'fetch', '_inceptionAuthHeaders', 'formatDashboardDateTime', source + '\nreturn {kickOutcomesHtml, refreshKickOutcomes};')(esc, document, fetch, () => ({Authorization: 'Bearer fixture'}), formatDashboardDateTime);
}
const fixture = JSON.parse(fs.readFileSync(path.join(__dirname, '../../scripts/fixtures/render-evidence/api/kick-outcomes.json'), 'utf8'));

test('shipped dashboard wires outcomes into both full render and status refresh', () => {
const html = fs.readFileSync(path.join(__dirname, 'static/index.html'), 'utf8');
assert.ok(html.includes('function kickOutcomesHtml(data)'));
assert.ok(html.includes('aria-label="Recent kick outcomes"'));
assert.equal((html.match(/refreshKickOutcomes\(a\.name\);/g) || []).length, 2);
assert.ok(html.includes('overflow-wrap: anywhere'));
});

test('all seven outcome kinds and real evidence render', () => {
const html = build().kickOutcomesHtml(fixture);
for (const label of ['Opened PR', 'Pushed commit', 'Commented', 'Stood down', 'Refused', 'Still running', 'Ended — no visible action']) assert.ok(html.includes(label), label);
for (const field of ['fixture-operator', 'PR #42', '0123456789abcdef', 'paused', 'No eligible work.']) assert.ok(html.includes(field), field);
assert.ok(html.includes('&lt;This is untrusted agent text.&gt;'));
});

test('timestamps use the shared dashboard formatter and preserve unknown-time fallbacks', () => {
const timestamps = [];
const {kickOutcomesHtml} = build({}, () => {}, date => {
timestamps.push(date.toISOString());
return '<selected timezone & clock>';
});
const kick = {kind: 'stood_down', at: '2026-11-18T12:00:00Z', started_at: '2026-11-18T11:00:00Z', ended_at: '2026-11-18T12:01:00Z'};
const html = kickOutcomesHtml({detail: true, kicks: [kick]});
assert.deepEqual(timestamps.sort(), [kick.at, kick.started_at, kick.ended_at].map(value => new Date(value).toISOString()).sort());
assert.equal((html.match(/&lt;selected timezone &amp; clock&gt;/g) || []).length, 3);
timestamps.length = 0;
const unknown = kickOutcomesHtml({detail: true, kicks: [{kind: 'stood_down', at: 'invalid', ended_at: 'invalid'}]});
assert.equal((unknown.match(/Unknown time/g) || []).length, 3);
assert.equal(timestamps.length, 0);
});

test('read-only response renders only its latest summary, even with stray detail fields', () => {
const html = build().kickOutcomesHtml({detail: false, latest: {...fixture.kicks[0], summary: 'Latest summary'}, kicks: fixture.kicks});
assert.ok(html.includes('Latest summary'));
for (const hidden of ['fixture-operator', 'href=', 'Trigger:', 'Started:', 'blockquote', 'Branch:']) assert.ok(!html.includes(hidden), hidden);
assert.equal((html.match(/<li>/g) || []).length, 1);
});

test('empty history, malicious quotes, summaries and link protocols are safe', () => {
assert.match(build().kickOutcomesHtml({detail: true, kicks: null}), /No recorded kicks/);
assert.match(build().kickOutcomesHtml({detail: false}), /No recorded kicks/);
const html = build().kickOutcomesHtml({detail: true, kicks: [{kind: 'refused', summary: '<img onerror=x>', quote: '<script>bad()</script>', pr_url: 'javascript:alert(1)', branch: '<b>branch</b>', refusal_code: '<x>'}]});
assert.ok(!html.includes('<script>') && !html.includes('<img') && !html.includes('href='));
assert.ok(html.includes('&lt;script&gt;') && html.includes('&lt;b&gt;'));
});

function panel(agent) {
const body = {innerHTML: ''};
return {dataset: {agent}, isConnected: true, querySelector: () => body, body};
}

test('refresh authenticates, encodes agent, throttles and uses server detail flag', async () => {
const p = panel('a/b');
let calls = 0;
const {refreshKickOutcomes} = build({querySelector: () => p}, async (url, opts) => {
calls++;
assert.equal(url, '/api/kick-outcomes?agent=a%2Fb');
assert.equal(opts.headers.Authorization, 'Bearer fixture');
return {ok: true, json: async () => ({detail: false, latest: fixture.kicks[0]})};
});
await refreshKickOutcomes('a/b');
await refreshKickOutcomes('a/b');
assert.equal(calls, 1);
assert.ok(!p.body.innerHTML.includes('href='));
});

test('error clears stale evidence and disconnected panels ignore late responses', async () => {
const p = panel('agent');
p.body.innerHTML = 'old evidence';
await build({querySelector: () => p}, async () => ({ok: false})).refreshKickOutcomes('agent');
assert.match(p.body.innerHTML, /unavailable/);
p.dataset.fetchedAt = '0';
p.body.innerHTML = 'unchanged';
await build({querySelector: () => p}, async () => {
p.isConnected = false;
return {ok: true, json: async () => fixture};
}).refreshKickOutcomes('agent');
assert.equal(p.body.innerHTML, 'unchanged');
});
6 changes: 6 additions & 0 deletions src/pkg/dashboard/static-src/css/agent-detail.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.oc-agent-detail.active { display: block; }
.kick-outcomes { min-width: 0; margin-block: var(--sp-5); font-size: var(--fs-sm); }
.kick-outcomes h3 { font-size: var(--fs-sm); margin-bottom: var(--sp-3); }
.kick-outcome-list { list-style: none; padding: 0; margin: 0; max-height: 24rem; overflow-y: auto; }
.kick-outcome-list li { border-top: 1px solid var(--border); padding-block: var(--sp-3); overflow-wrap: anywhere; }
.kick-outcome-list blockquote { margin: var(--sp-2) 0; padding-inline-start: var(--sp-3); border-inline-start: 2px solid var(--line); white-space: pre-wrap; }
.kick-outcome-list code { white-space: normal; overflow-wrap: anywhere; }
.oc-agent-detail.state-running, .oc-agent-detail[data-status="ok"] { border-color: var(--status-ok); }
.oc-agent-detail.state-idle { border-color: var(--status-ok); }
.oc-agent-detail.state-paused, .oc-agent-detail[data-status="warn"] { border-color: var(--status-warn); }
Expand Down
6 changes: 6 additions & 0 deletions src/pkg/dashboard/static-src/js/agent-detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,7 @@
// The fingerprint guards the fields only the full template renders
// (method/model/pins): without it a CLI or model switch stayed stale
// in the focused panel until a hard refresh.
refreshKickOutcomes(a.name);
const cfgSig = [a.cli || '', a.model || '', a.pinnedCli ? 1 : 0, a.pinnedModel ? 1 : 0, a.pinnedBoth ? 1 : 0, a.displayName || '', a.emoji || '', a.color || '', JSON.stringify(a.subAgentModels || []), agentToggleGateReason()].join('|');
if (existingSummary && detail.dataset.agent === a.name && detail.dataset.cfgSig === cfgSig) {
if (a.detailSummary) {
Expand Down Expand Up @@ -872,6 +873,10 @@
${ocDetailFieldsHtml(a, isPaused, isOff, isOnDemand)}
${subAgentModelsHtml(a)}
<div class="oc-detail-indicators">${agentIndicators(a.name)}</div>
<section class="kick-outcomes" data-agent="${esc(a.name)}" aria-label="Recent kick outcomes">
<h3>Recent kick outcomes</h3>
<div class="kick-outcomes-body"><p class="text-muted">Loading kick outcomes…</p></div>
</section>
<div class="oc-detail-summary-wrap">
<div class="oc-detail-summary" id="oc-summary-scroll">${(a.detailSummary || a.liveSummary) ? escBlock(a.detailSummary || a.liveSummary) : '<span class="text-muted">No activity summary</span>'}</div>
<button class="oc-summary-follow-btn" id="oc-summary-follow" title="Follow new output" data-action="ocSummaryResumeTail">⬇</button>
Expand All @@ -882,6 +887,7 @@
</div>
`;

refreshKickOutcomes(a.name);
const summaryEl = document.getElementById('oc-summary-scroll');
const followBtn = document.getElementById('oc-summary-follow');
if (summaryEl) {
Expand Down
46 changes: 46 additions & 0 deletions src/pkg/dashboard/static-src/js/kick-outcomes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// The API, not the browser's role hint, decides whether evidence is visible.
function kickOutcomesHtml(data) {
const labels = { opened_pr: 'Opened PR', pushed_commit: 'Pushed commit', commented: 'Commented', stood_down: 'Stood down', refused: 'Refused', still_running: 'Still running', ended_no_visible_action: 'Ended — no visible action' };
const detailed = data.detail === true;
const kicks = detailed ? (Array.isArray(data.kicks) ? data.kicks : []) : (data.latest ? [data.latest] : []);
if (!kicks.length) return '<p class="text-muted">No recorded kicks yet.</p>';
const time = value => {
const date = new Date(value);
return value && !isNaN(date.getTime()) ? esc(formatDashboardDateTime(date)) : 'Unknown time';
};
return '<ol class="kick-outcome-list">' + kicks.map(k => {
let evidence = '';
if (detailed) {
const trigger = [k.trigger_kind, k.trigger_actor].filter(Boolean).join(' · ');
evidence += '<div class="text-muted">Trigger: ' + esc(trigger || 'unknown') + '</div>';
evidence += '<div class="text-muted">Started: ' + time(k.started_at) + (k.ended_at ? ' · Ended: ' + time(k.ended_at) : '') + '</div>';
// Quotes and every other API string are untrusted. Restrict link protocols too.
let prURL = '';
try { const url = new URL(k.pr_url); if (url.protocol === 'https:' || url.protocol === 'http:') prURL = url.href; } catch (_) { /* no valid PR link */ }
if (prURL) evidence += '<a href="' + esc(prURL) + '" target="_blank" rel="noopener noreferrer">PR ' + esc(k.pr_number ? '#' + k.pr_number : k.pr_url) + '</a>';
if (k.branch) evidence += '<div>Branch: <code>' + esc(k.branch) + '</code></div>';
if (k.sha) evidence += '<div>Commit: <code>' + esc(k.sha) + '</code></div>';
if (k.refusal_code) evidence += '<div>Refusal: <code>' + esc(k.refusal_code) + '</code></div>';
if (k.quote) evidence += '<blockquote>' + esc(k.quote) + '</blockquote>';
}
return '<li><strong>' + esc(labels[k.kind] || 'Unknown outcome') + '</strong> <span class="text-muted">' + time(k.at) + '</span><div>' + esc(k.summary || '') + '</div>' + evidence + '</li>';
}).join('') + '</ol>';
}

async function refreshKickOutcomes(agent) {
const panel = document.querySelector('#oc-agent-detail .kick-outcomes');
if (!panel || panel.dataset.agent !== agent) return;
if (panel.dataset.pending === 'true' || Date.now() - Number(panel.dataset.fetchedAt || 0) < 10000) return;
panel.dataset.pending = 'true';
try {
const response = await fetch('/api/kick-outcomes?agent=' + encodeURIComponent(agent), { headers: _inceptionAuthHeaders() });
if (!response.ok) throw new Error('unavailable');
const data = await response.json();
if (panel.isConnected && panel.dataset.agent === agent) panel.querySelector('.kick-outcomes-body').innerHTML = kickOutcomesHtml(data);
} catch (_) {
if (panel.isConnected) panel.querySelector('.kick-outcomes-body').innerHTML = '<p class="text-muted">Kick outcomes unavailable. Retrying on the next refresh.</p>';
} finally {
panel.dataset.pending = 'false';
panel.dataset.fetchedAt = String(Date.now());
}
}
1 change: 1 addition & 0 deletions src/pkg/dashboard/static-src/manifest.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ js/progressive.js
js/feedback.js
js/sections.js
js/layout.js
js/kick-outcomes.js
js/agent-detail.js
js/sidebar.js
js/history-sparklines.js
Expand Down
58 changes: 58 additions & 0 deletions src/pkg/dashboard/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,12 @@
box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.oc-agent-detail.active { display: block; }
.kick-outcomes { min-width: 0; margin-block: var(--sp-5); font-size: var(--fs-sm); }
.kick-outcomes h3 { font-size: var(--fs-sm); margin-bottom: var(--sp-3); }
.kick-outcome-list { list-style: none; padding: 0; margin: 0; max-height: 24rem; overflow-y: auto; }
.kick-outcome-list li { border-top: 1px solid var(--border); padding-block: var(--sp-3); overflow-wrap: anywhere; }
.kick-outcome-list blockquote { margin: var(--sp-2) 0; padding-inline-start: var(--sp-3); border-inline-start: 2px solid var(--line); white-space: pre-wrap; }
.kick-outcome-list code { white-space: normal; overflow-wrap: anywhere; }
.oc-agent-detail.state-running, .oc-agent-detail[data-status="ok"] { border-color: var(--status-ok); }
.oc-agent-detail.state-idle { border-color: var(--status-ok); }
.oc-agent-detail.state-paused, .oc-agent-detail[data-status="warn"] { border-color: var(--status-warn); }
Expand Down Expand Up @@ -13094,6 +13100,52 @@ <h3 class="faq-group-title">Where to get help</h3>
})();

const OC_TOPBAR_HEIGHT = 64;
// The API, not the browser's role hint, decides whether evidence is visible.
function kickOutcomesHtml(data) {
const labels = { opened_pr: 'Opened PR', pushed_commit: 'Pushed commit', commented: 'Commented', stood_down: 'Stood down', refused: 'Refused', still_running: 'Still running', ended_no_visible_action: 'Ended — no visible action' };
const detailed = data.detail === true;
const kicks = detailed ? (Array.isArray(data.kicks) ? data.kicks : []) : (data.latest ? [data.latest] : []);
if (!kicks.length) return '<p class="text-muted">No recorded kicks yet.</p>';
const time = value => {
const date = new Date(value);
return value && !isNaN(date.getTime()) ? esc(formatDashboardDateTime(date)) : 'Unknown time';
};
return '<ol class="kick-outcome-list">' + kicks.map(k => {
let evidence = '';
if (detailed) {
const trigger = [k.trigger_kind, k.trigger_actor].filter(Boolean).join(' · ');
evidence += '<div class="text-muted">Trigger: ' + esc(trigger || 'unknown') + '</div>';
evidence += '<div class="text-muted">Started: ' + time(k.started_at) + (k.ended_at ? ' · Ended: ' + time(k.ended_at) : '') + '</div>';
// Quotes and every other API string are untrusted. Restrict link protocols too.
let prURL = '';
try { const url = new URL(k.pr_url); if (url.protocol === 'https:' || url.protocol === 'http:') prURL = url.href; } catch (_) { /* no valid PR link */ }
if (prURL) evidence += '<a href="' + esc(prURL) + '" target="_blank" rel="noopener noreferrer">PR ' + esc(k.pr_number ? '#' + k.pr_number : k.pr_url) + '</a>';
if (k.branch) evidence += '<div>Branch: <code>' + esc(k.branch) + '</code></div>';
if (k.sha) evidence += '<div>Commit: <code>' + esc(k.sha) + '</code></div>';
if (k.refusal_code) evidence += '<div>Refusal: <code>' + esc(k.refusal_code) + '</code></div>';
if (k.quote) evidence += '<blockquote>' + esc(k.quote) + '</blockquote>';
}
return '<li><strong>' + esc(labels[k.kind] || 'Unknown outcome') + '</strong> <span class="text-muted">' + time(k.at) + '</span><div>' + esc(k.summary || '') + '</div>' + evidence + '</li>';
}).join('') + '</ol>';
}

async function refreshKickOutcomes(agent) {
const panel = document.querySelector('#oc-agent-detail .kick-outcomes');
if (!panel || panel.dataset.agent !== agent) return;
if (panel.dataset.pending === 'true' || Date.now() - Number(panel.dataset.fetchedAt || 0) < 10000) return;
panel.dataset.pending = 'true';
try {
const response = await fetch('/api/kick-outcomes?agent=' + encodeURIComponent(agent), { headers: _inceptionAuthHeaders() });
if (!response.ok) throw new Error('unavailable');
const data = await response.json();
if (panel.isConnected && panel.dataset.agent === agent) panel.querySelector('.kick-outcomes-body').innerHTML = kickOutcomesHtml(data);
} catch (_) {
if (panel.isConnected) panel.querySelector('.kick-outcomes-body').innerHTML = '<p class="text-muted">Kick outcomes unavailable. Retrying on the next refresh.</p>';
} finally {
panel.dataset.pending = 'false';
panel.dataset.fetchedAt = String(Date.now());
}
}
function _ocAgentFromHash() {
const h = location.hash.replace('#', '');
if (!h || h === 'throughput' || h.startsWith('section-')) return null;
Expand Down Expand Up @@ -13771,6 +13823,7 @@ <h3 class="faq-group-title">Where to get help</h3>
// The fingerprint guards the fields only the full template renders
// (method/model/pins): without it a CLI or model switch stayed stale
// in the focused panel until a hard refresh.
refreshKickOutcomes(a.name);
const cfgSig = [a.cli || '', a.model || '', a.pinnedCli ? 1 : 0, a.pinnedModel ? 1 : 0, a.pinnedBoth ? 1 : 0, a.displayName || '', a.emoji || '', a.color || '', JSON.stringify(a.subAgentModels || []), agentToggleGateReason()].join('|');
if (existingSummary && detail.dataset.agent === a.name && detail.dataset.cfgSig === cfgSig) {
if (a.detailSummary) {
Expand Down Expand Up @@ -13968,6 +14021,10 @@ <h3 class="faq-group-title">Where to get help</h3>
${ocDetailFieldsHtml(a, isPaused, isOff, isOnDemand)}
${subAgentModelsHtml(a)}
<div class="oc-detail-indicators">${agentIndicators(a.name)}</div>
<section class="kick-outcomes" data-agent="${esc(a.name)}" aria-label="Recent kick outcomes">
<h3>Recent kick outcomes</h3>
<div class="kick-outcomes-body"><p class="text-muted">Loading kick outcomes…</p></div>
</section>
<div class="oc-detail-summary-wrap">
<div class="oc-detail-summary" id="oc-summary-scroll">${(a.detailSummary || a.liveSummary) ? escBlock(a.detailSummary || a.liveSummary) : '<span class="text-muted">No activity summary</span>'}</div>
<button class="oc-summary-follow-btn" id="oc-summary-follow" title="Follow new output" data-action="ocSummaryResumeTail">⬇</button>
Expand All @@ -13978,6 +14035,7 @@ <h3 class="faq-group-title">Where to get help</h3>
</div>
`;

refreshKickOutcomes(a.name);
const summaryEl = document.getElementById('oc-summary-scroll');
const followBtn = document.getElementById('oc-summary-follow');
if (summaryEl) {
Expand Down
12 changes: 11 additions & 1 deletion src/scripts/dashboard-render-evidence.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,17 @@ const collapseAllJS = `(() => {
window.scrollTo(0, 0);
return ids;
})()`;
const expandOneJS = (sid) => `(() => {
const expandOneJS = (sid) => `(async () => {
if (${JSON.stringify(sid)} === 'kick-outcomes') {
// Isolated component evidence using the same API response and production renderer.
const data = await (await fetch('/api/kick-outcomes?agent=fixture-agent')).json();
const panel = document.getElementById('oc-agent-detail');
if (!panel || typeof kickOutcomesHtml !== 'function') return false;
panel.className = 'oc-agent-detail active';
panel.innerHTML = '<section class="kick-outcomes"><h3>Recent kick outcomes — fixture agent</h3><div class="kick-outcomes-body">' + kickOutcomesHtml(data) + '</div></section>';
panel.scrollIntoView();
return true;
}
try { toggleSection(${JSON.stringify(sid)}, { collapsed: false, persist: false, animate: false }); } catch (_) { return false; }
const el = document.getElementById(${JSON.stringify(sid)});
if (!el) return false;
Expand Down
Loading
Loading