Skip to content

armgit / kwant

Public Imported from GitHub
0

Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.

Dev mode style v2: landed card and git rail (IR-2, IR-4, 0.7.1) (#339)

Oleksandr Ivanchenkob6ec85a7ba8b
diff --git a/frontend/src/components/dev/LandedCard.tsx b/frontend/src/components/dev/LandedCard.tsx
index 91741dce..322cebd8 100644
--- a/frontend/src/components/dev/LandedCard.tsx
+++ b/frontend/src/components/dev/LandedCard.tsx
@@ -1,21 +1,22 @@
import React from 'react';
-import { AlertTriangle, Check, ChevronRight, FileText, FlaskConical, GitCommitHorizontal, GitMerge, Minus, ShieldCheck, X } from 'lucide-react';
+import { AlertTriangle, ChevronRight, FileText, FlaskConical, GitCommitHorizontal, GitMerge, ShieldCheck } from 'lucide-react';
import { Sticker } from '../Sticker';
import type { Forge, LandedCard as Landed, LandedListProps, ReviewCard } from '../../dev/types';
-import { byDay, clock, forgeOpen, openFindings, riskReasons, showVerified } from '../../dev/logic';
-import { OutLink, RiskChip, Who, personText } from './parts';
+import { byDay, clock, forgeOpen, landedNode, openFindings, riskReasons, showVerified, testsWords } from '../../dev/logic';
+import { DiffStat, Led, OutLink, RiskChip, Sha, Who, personText } from './parts';
const isTest = (path: string) => /(^|\/)(tests?|__tests__|e2e)\/|\.(test|spec)\.[a-z]+$|_test\.[a-z]+$/.test(path);
-const TESTS_ICON = { passed: Check, failed: X, none: Minus, unknown: Minus } as const;
const TESTS_TONE = { passed: 'text-ok', failed: 'text-bad', none: 'text-zinc-400', unknown: 'text-zinc-400' } as const;
+const TESTS_LED = { passed: 'ok', failed: 'bad', none: 'off', unknown: 'off' } as const;
/** One merge in plain words (design §4). A commit pushed without a PR (`pr: null`) is the same card, named by its commit. */
-export const LandedCard: React.FC<{ card: Landed; reviews?: ReviewCard[]; onOpenReview?: (pr: number) => void; forge?: Forge | null }> = ({
+export const LandedCard: React.FC<{ card: Landed; reviews?: ReviewCard[]; onOpenReview?: (pr: number) => void; forge?: Forge | null; onRail?: boolean }> = ({
card,
reviews = [],
onOpenReview,
forge = null,
+ onRail = false,
}) => {
const verified = showVerified(card, reviews);
const writer = personText(card.written_by);
@@ -28,20 +29,37 @@ export const LandedCard: React.FC<{ card: Landed; reviews?: ReviewCard[]; onOpen
const pr = card.pr;
const findingsOpen = pr === null ? 0 : openFindings(reviews.find((r) => r.pr === pr));
const nothingToDo = openFollowUps.length === 0 && card.tests.state === 'passed' && findingsOpen === 0;
- const TestsIcon = TESTS_ICON[card.tests.state];
- const testsText =
- card.tests.summary ?? (card.tests.state === 'passed' ? 'CI green' : card.tests.state === 'failed' ? 'CI failed' : card.tests.state === 'none' ? 'No CI checks' : 'CI not known');
+ const tests = testsWords(card.tests.state);
const diff = card.links.commit ?? (card.links.pr ? `${card.links.pr}/files` : null);
const headingId = `landed-${card.id || pr || card.sha}-h`;
const MergeIcon = pr === null ? GitCommitHorizontal : GitMerge;
- // Where the card came from: "PR #n", or "Commit abc1234" for a direct commit.
- const source = pr !== null ? { text: `PR #${pr}`, href: card.links.pr } : { text: `Commit ${card.sha}`, href: card.links.commit };
const github = card.links.pr ?? (pr === null ? card.links.commit : null);
+ const node = landedNode(card);
return (
<article data-dev-card="landed" data-pr={pr ?? undefined} data-commit={pr === null ? card.sha : undefined} data-verified={verified || undefined} aria-labelledby={headingId} className="kw-card relative min-w-0 p-4">
+ {onRail && (
+ <>
+ {pr !== null && <span aria-hidden="true" data-rail-arc className="dv-arc" />}
+ <span aria-hidden="true" data-rail-node={node} data-s={node} className="dv-node" />
+ </>
+ )}
<div className="flex flex-wrap items-center gap-1.5">
{card.area && <span className="kw-chip">{card.area}</span>}
+ <Sha sha={card.sha} />
+ {pr !== null ? (
+ card.links.pr ? (
+ <a href={card.links.pr} target="_blank" rel="noreferrer noopener" aria-label={`PR #${pr}`} className="kw-focus kw-hit rounded font-mono text-[11.5px] text-zinc-400 hover:text-sky-300">
+ #{pr}
+ </a>
+ ) : (
+ <span className="font-mono text-[11.5px] text-zinc-400">
+ <span className="sr-only">PR </span>#{pr}
+ </span>
+ )
+ ) : (
+ <span className="kw-chip">Direct push</span>
+ )}
{card.risk && <RiskChip level={card.risk.level} />}
{card.meta && <span className="text-meta text-zinc-400">{card.meta}</span>}
{verified && (
@@ -73,14 +91,6 @@ export const LandedCard: React.FC<{ card: Landed; reviews?: ReviewCard[]; onOpen
{writer.sub && <span>({writer.sub})</span>}
</>
)}
- <span aria-hidden="true">·</span>
- {source.href ? (
- <a href={source.href} target="_blank" rel="noreferrer noopener" className="kw-focus kw-hit rounded text-sky-300 hover:text-sky-200">
- {source.text}
- </a>
- ) : (
- <span>{source.text}</span>
- )}
</div>
{card.status === 'pending' && <p className="mt-3 text-meta text-zinc-400">Writing this change in plain words…</p>}
@@ -101,10 +111,16 @@ export const LandedCard: React.FC<{ card: Landed; reviews?: ReviewCard[]; onOpen
<details className="group mt-3 border-t border-hairline pt-3">
<summary className="kw-focus flex min-h-[44px] cursor-pointer list-none items-center gap-1.5 rounded text-meta text-zinc-400 hover:text-zinc-200 sm:min-h-0 [&::-webkit-details-marker]:hidden">
<ChevronRight size={14} aria-hidden="true" className="shrink-0 transition-transform duration-[160ms] group-open:rotate-90 motion-reduce:transition-none" />
- <span>
- Under the hood
- {files.length > 0 && ` · ${files.length} ${files.length === 1 ? 'file' : 'files'}, +${add} −${del}`}
- </span>
+ <span>Under the hood</span>
+ {files.length > 0 && (
+ <>
+ <span aria-hidden="true">·</span>
+ <span className="font-mono text-[11.5px]">
+ {files.length} {files.length === 1 ? 'file' : 'files'}
+ </span>
+ <DiffStat add={add} del={del} />
+ </>
+ )}
</summary>
{card.under_hood.summary && <p className="mt-2 text-meta text-zinc-300 [overflow-wrap:anywhere]">{card.under_hood.summary}</p>}
{files.length > 0 && (
@@ -112,11 +128,10 @@ export const LandedCard: React.FC<{ card: Landed; reviews?: ReviewCard[]; onOpen
{files.map((f) => {
const Icon = isTest(f.path) ? FlaskConical : FileText;
return (
- <li key={f.path} className="flex min-w-0 items-start gap-1.5 font-mono text-[12px] leading-5">
+ <li key={f.path} className="flex min-w-0 items-start gap-2 font-mono text-[12px] leading-5">
<Icon size={12} className="mt-1 shrink-0 text-zinc-500" aria-hidden="true" />
- <span className="min-w-0 text-zinc-200 [overflow-wrap:anywhere]">{f.path}</span>
- <span className="shrink-0 text-ok" aria-label={`${f.add} lines added`}>+{f.add}</span>
- <span className="shrink-0 text-bad" aria-label={`${f.del} lines removed`}>−{f.del}</span>
+ <span className="min-w-0 flex-1 text-zinc-200 [overflow-wrap:anywhere]">{f.path}</span>
+ <DiffStat add={f.add} del={f.del} className="mt-[5px] shrink-0" />
</li>
);
})}
@@ -149,15 +164,27 @@ export const LandedCard: React.FC<{ card: Landed; reviews?: ReviewCard[]; onOpen
</div>
)}
- <div className="mt-3 flex flex-wrap items-center gap-x-3 gap-y-1 text-meta">
- <span className={`inline-flex items-center gap-1 ${TESTS_TONE[card.tests.state]}`}>
- <TestsIcon size={13} aria-hidden="true" />
- {card.links.ci ? (
+ <div className="mt-3 flex flex-wrap items-center gap-x-3 gap-y-1 border-t border-hairline pt-2.5 text-meta">
+ <span data-tests={card.tests.state} className={`inline-flex items-center gap-[7px] ${TESTS_TONE[card.tests.state]}`}>
+ <Led s={TESTS_LED[card.tests.state]} />
+ {card.tests.state === 'failed' ? (
+ <span>
+ {tests}
+ {card.links.ci && (
+ <>
+ {' · '}
+ <a href={card.links.ci} target="_blank" rel="noreferrer noopener" className="kw-focus kw-hit rounded text-sky-300 hover:underline">
+ see CI
+ </a>
+ </>
+ )}
+ </span>
+ ) : card.links.ci ? (
<a href={card.links.ci} target="_blank" rel="noreferrer noopener" className="kw-focus kw-hit rounded hover:underline">
- {testsText}
+ {tests}
</a>
) : (
- testsText
+ <span>{tests}</span>
)}
</span>
<span className="text-zinc-400">{card.reviewed_by ? `Reviewed by ${card.reviewed_by}` : 'No bot review'}</span>
@@ -201,17 +228,17 @@ export const LandedCard: React.FC<{ card: Landed; reviews?: ReviewCard[]; onOpen
);
};
-/** What landed: the cards under "Today", "Yesterday" and date separators. */
+/** What landed: one git rail down the left (style v2 §5), day labels sitting on it, a node per card. */
export const LandedList: React.FC<LandedListProps> = ({ cards, reviews, now = Date.now(), onOpenReview, forge = null }) => (
- <div data-dev-landed-list className="space-y-3">
+ <div data-dev-landed-list className="dv-rail space-y-3">
{byDay(cards, now).map((day) => (
<section key={day.label} aria-label={day.label} className="space-y-3">
- <h3 className="flex items-center gap-3 pt-2 text-2xs font-semibold uppercase tracking-wider text-zinc-400">
- <span>{day.label}</span>
- <span aria-hidden="true" className="h-px flex-1 bg-hairline" />
+ <h3 className="-ml-[30px] flex items-center gap-2 pt-2 font-mono text-[10.5px] font-semibold uppercase leading-none tracking-[0.06em] text-zinc-400">
+ <span data-rail-day className="relative rounded bg-surface-main py-1 pl-0.5 pr-2">{day.label}</span>
+ <span aria-hidden="true" className="h-px flex-1 bg-[var(--kw-hairline)]" />
</h3>
{day.cards.map((c) => (
- <LandedCard key={c.id || c.pr || c.sha} card={c} reviews={reviews} onOpenReview={onOpenReview} forge={forge} />
+ <LandedCard key={c.id || c.pr || c.sha} card={c} reviews={reviews} onOpenReview={onOpenReview} forge={forge} onRail />
))}
</section>
))}
diff --git a/frontend/src/dev/logic.ts b/frontend/src/dev/logic.ts
index 8a3f779a..ae77dbcf 100644
--- a/frontend/src/dev/logic.ts
+++ b/frontend/src/dev/logic.ts
@@ -503,3 +503,14 @@ export function lgtm(card: {
export const lgtmLabel = (reviewer: string): string => `Looks good to me: ${reviewer} found nothing to fix`;
/** "Rigel is reading the diff" (pending review); no ETA, we don't have one. */
export const readingLine = (reviewer: string | null | undefined): string => `${reviewer || 'A reviewer'} is reading the diff`;
+
+/** The landed card's tests line in words (§5): LED + "Tests passed" / "Tests failed" / "No tests ran". */
+export function testsWords(state: 'passed' | 'failed' | 'none' | 'unknown'): string {
+ return state === 'passed' ? 'Tests passed' : state === 'failed' ? 'Tests failed' : state === 'none' ? 'No tests ran' : 'Tests not known';
+}
+
+/** The git rail node for a landed card (§5): a card still being written pings; else the tests decide. */
+export function landedNode(card: { status: string; tests: { state: 'passed' | 'failed' | 'none' | 'unknown' } }): 'ok' | 'bad' | 'off' | 'run' {
+ if (card.status === 'pending') return 'run';
+ return card.tests.state === 'passed' ? 'ok' : card.tests.state === 'failed' ? 'bad' : 'off';
+}
diff --git a/frontend/tests/devCards.test.mjs b/frontend/tests/devCards.test.mjs
index 147b4c48..e80144ca 100644
--- a/frontend/tests/devCards.test.mjs
+++ b/frontend/tests/devCards.test.mjs
@@ -159,7 +159,10 @@ test('B1: a direct commit (pr null) parses and draws as a normal landed card nam
assert.match(out, /data-dev-card="landed"/);
assert.match(out, /data-commit="c0ffee1"/);
assert.doesNotMatch(out, /data-pr=/);
- assert.match(out, /<a href="https:\/\/github\.com\/alexsergivan\/kwant\/commit\/c0ffee1"[^>]*>Commit c0ffee1<\/a>/);
+ // style v2: the commit is a sha chip plus a "Direct push" chip; the GitHub link goes to the commit.
+ assert.match(out, /class="dv-sha[^"]*"><span class="sr-only">Commit <\/span>c0ffee1<\/span>/);
+ assert.match(out, /class="kw-chip">Direct push</);
+ assert.match(out, /<a href="https:\/\/github\.com\/alexsergivan\/kwant\/commit\/c0ffee1"/);
assert.doesNotMatch(out, /PR #/);
assert.match(out, /Committed 19:02/);
assert.doesNotMatch(out, />Verified</);
@@ -183,8 +186,8 @@ test('B1: a direct commit (pr null) parses and draws as a normal landed card nam
test('N2: the PR chip, the checks line and Diff get the phone tap area (kw-hit); the CSS is phone-only', async () => {
const out = html(m.LandedCard, { card: landed(fx.LANDED_288, { links: { ...fx.LANDED_288.links, ci: 'https://github.com/alexsergivan/kwant/actions/runs/2' } }) });
- assert.match(out, /class="[^"]*kw-hit[^"]*"[^>]*>PR #288</);
- assert.match(out, /class="[^"]*kw-hit[^"]*"[^>]*>3 checks passed</);
+ assert.match(out, /aria-label="PR #288" class="[^"]*kw-hit[^"]*"[^>]*>#288</);
+ assert.match(out, /class="[^"]*kw-hit[^"]*"[^>]*>Tests passed</);
assert.match(out, /class="[^"]*kw-hit[^"]*"[^>]*>Diff</);
const { readFile } = await import('node:fs/promises');
const css = await readFile(new URL('../src/styles/modern.css', import.meta.url), 'utf8');
@@ -199,7 +202,7 @@ test('the landed card: plain words, the details fold, a failed card and day sepa
const c = html(m.LandedCard, { card: landed(fx.LANDED_288) });
assert.match(c, /What changes for you/);
assert.match(c, /<details/);
- assert.match(c, /Under the hood · 4 files, \+249 −15/);
+ assert.match(c, /Under the hood<\/span><span aria-hidden="true">·<\/span><span class="font-mono[^"]*">4 files<\/span><span role="img" aria-label="249 lines added, 15 removed"/);
assert.match(c, /Merged 18:48 by/);
assert.match(c, /Pixel<\/span><\/span><span>\(bot · Claude Sonnet\)/);
const f = html(m.LandedCard, { card: landed(fx.LANDED_NO_TEXT) });
diff --git a/frontend/tests/styleV2Landed.test.mjs b/frontend/tests/styleV2Landed.test.mjs
new file mode 100644
index 00000000..d5d9cca6
--- /dev/null
+++ b/frontend/tests/styleV2Landed.test.mjs
@@ -0,0 +1,101 @@
+// Dev mode style v2 (Mira, style-v2.md §2 and §5): the shared parts (LED, diffstat, sha chip), the landed
+// card's chips, diffstats and tests line, and the git rail on What landed (IR-2, IR-4). Demo data only.
+process.env.TZ = 'UTC';
+
+import assert from 'node:assert/strict';
+import test from 'node:test';
+import { readFileSync } from 'node:fs';
+import { loadBundled } from './bundle.mjs';
+
+const m = await loadBundled(`
+ export * from './src/dev/types';
+ export * from './src/dev/logic';
+ export * as fx from './src/dev/fixtures';
+ export { Led, DiffStat, Sha } from './src/components/dev/parts';
+ export { LandedCard, LandedList } from './src/components/dev/LandedCard';
+ export { renderToStaticMarkup } from 'react-dom/server.browser';
+ export { createElement } from 'react';
+`);
+const { fx } = m;
+const html = (C, props) => m.renderToStaticMarkup(m.createElement(C, props));
+const landed = (raw, over = {}) => ({ ...m.parseLanded(raw), ...over });
+const NOW = fx.FIXTURE_NOW;
+
+test('IR-2 chips row: area · sha chip · #pr (mono link) · Verified; a direct push says so', () => {
+ const pr = html(m.LandedCard, { card: landed(fx.LANDED_289) });
+ const row = pr.slice(0, pr.indexOf('<h3'));
+ assert.match(row, /class="dv-sha"/);
+ assert.match(row, /aria-label="PR #289"[^>]*font-mono[^>]*>#289<\/a>/);
+ assert.match(row, />Verified</);
+ assert.equal([...row.matchAll(/kw-sticker/g)].length > 0, true);
+ assert.doesNotMatch(row, /Direct push/);
+ const direct = html(m.LandedCard, { card: landed(fx.LANDED_DIRECT) });
+ assert.match(direct.slice(0, direct.indexOf('<h3')), /c0ffee1<\/span><span class="kw-chip">Direct push<\/span>/);
+});
+
+test('IR-2 under the hood: total diffstat on the summary and one per file row', () => {
+ const out = html(m.LandedCard, { card: landed(fx.LANDED_288) });
+ const sum = out.slice(out.indexOf('<summary'), out.indexOf('</summary>'));
+ assert.match(sum, /4 files/);
+ assert.match(sum, /aria-label="249 lines added, 15 removed"/);
+ const rows = out.slice(out.indexOf('<ul role="list"'), out.indexOf('</ul>'));
+ assert.equal([...rows.matchAll(/data-diffstat=/g)].length, 4, 'a diffstat per file');
+ assert.doesNotMatch(rows, /aria-label="\d+ lines added"/, 'the old bare +n −n spans are gone');
+});
+
+test('IR-2 tests line: LED + words, "see CI" on a failure, no icon', () => {
+ const ci = 'https://github.com/alexsergivan/kwant/actions/runs/2';
+ const t = (state, links = {}) => {
+ const out = html(m.LandedCard, { card: landed(fx.LANDED_288, { tests: { state, summary: '3 checks passed' }, links: { ...fx.LANDED_288.links, ...links } }) });
+ return out.slice(out.indexOf('data-tests='), out.indexOf('data-tests=') + 600);
+ };
+ assert.match(t('passed'), /data-tests="passed" class="[^"]*text-ok[^"]*"><span aria-hidden="true" data-s="ok" class="dv-led"><\/span>/);
+ assert.match(t('passed'), />Tests passed</);
+ const failed = t('failed', { ci });
+ assert.match(failed, /data-s="bad"/);
+ assert.match(failed, /Tests failed · <a href="https:\/\/github\.com\/alexsergivan\/kwant\/actions\/runs\/2"[^>]*>see CI<\/a>/);
+ assert.match(t('failed', { ci: null }), /<span>Tests failed<\/span>/);
+ assert.match(t('none'), /data-s="off"[^]*No tests ran/);
+ assert.match(t('unknown'), /data-s="off"[^]*Tests not known/);
+ assert.doesNotMatch(t('passed'), /lucide-check|lucide-x|lucide-minus/);
+});
+
+test('IR-2 link words follow the forge, not GitHub by default (one source: the forge prop, QA 0.7.1 F2)', () => {
+ assert.equal(m.forgeName, undefined, 'no second, host-derived source for the link word');
+ const card = landed(fx.LANDED_289, { links: { pr: 'https://gitlab.com/o/r/-/merge_requests/289', commit: null, ci: null } });
+ const gl = html(m.LandedCard, { card, forge: 'gitlab' });
+ assert.match(gl, /Open on GitLab/);
+ assert.doesNotMatch(gl, /GitHub|Open pull request/);
+ assert.match(html(m.LandedCard, { card, forge: 'gitea' }), /Open on Gitea/);
+ assert.match(html(m.LandedCard, { card }), /Open pull request/, 'forge unknown: plain words, never a guessed GitHub');
+ const list = html(m.LandedList, { cards: [card], reviews: [], now: fx.FIXTURE_NOW, forge: 'gitlab' });
+ assert.match(list, /Open on GitLab/, 'the list passes forge down');
+ assert.match(list, /dv-rail/);
+});
+
+test('IR-4 rail node: passed teal, failed rose with the × cut-out, none/unknown hollow, pending pings', () => {
+ assert.equal(m.landedNode({ status: 'ready', tests: { state: 'passed' } }), 'ok');
+ assert.equal(m.landedNode({ status: 'ready', tests: { state: 'failed' } }), 'bad');
+ assert.equal(m.landedNode({ status: 'ready', tests: { state: 'none' } }), 'off');
+ assert.equal(m.landedNode({ status: 'ready', tests: { state: 'unknown' } }), 'off');
+ assert.equal(m.landedNode({ status: 'pending', tests: { state: 'passed' } }), 'run');
+ const css = readFileSync(new URL('../src/styles/modern.css', import.meta.url), 'utf8');
+ assert.match(css, /\.dv-node\[data-s="bad"\]::after \{[^}]*clip-path: polygon/, 'the × cut-out is a shape, not only colour');
+ assert.match(css, /\.dv-node\[data-s="run"\]::before \{[^}]*animation: dv-ping/);
+});
+
+test('IR-4 rail: one node per card, a merge arc only for a PR, day labels on the rail, nothing for a lone card', () => {
+ const cards = [landed(fx.LANDED_303), landed(fx.LANDED_288), landed(fx.LANDED_DIRECT), landed(fx.LANDED_NO_TEXT)];
+ const list = html(m.LandedList, { cards, reviews: [], now: NOW });
+ assert.match(list, /^<div data-dev-landed-list="true" class="dv-rail /);
+ const nodes = [...list.matchAll(/data-rail-node="(\w+)"/g)].map((x) => x[1]);
+ assert.equal(nodes.length, cards.length);
+ assert.equal([...list.matchAll(/data-rail-arc/g)].length, cards.filter((c) => c.pr !== null).length, 'direct push: node only');
+ const direct = list.slice(list.indexOf('data-commit="c0ffee1"'));
+ assert.doesNotMatch(direct.slice(0, direct.indexOf('<div')), /data-rail-arc/);
+ assert.match(list, /aria-hidden="true" data-rail-node="\w+" data-s="\w+" class="dv-node"/, 'the node is decoration; the tests line says it in words');
+ const days = [...list.matchAll(/data-rail-day="true"[^>]*>([^<]+)</g)].map((x) => x[1]);
+ assert.ok(days.includes('Today') && days.includes('Yesterday'), days.join());
+ const lone = html(m.LandedCard, { card: landed(fx.LANDED_288) });
+ assert.doesNotMatch(lone, /dv-node|dv-arc/, 'off the rail, no node');
+});