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: Post to GitHub footer on review cards (0.7.1) (#338)

Oleksandr Ivanchenko66c794cff25f
diff --git a/frontend/src/components/DevDesk.tsx b/frontend/src/components/DevDesk.tsx
index 86e63e22..5762ee69 100644
--- a/frontend/src/components/DevDesk.tsx
+++ b/frontend/src/components/DevDesk.tsx
@@ -242,6 +242,17 @@ export const DevDeskView: React.FC<DevDeskViewProps> = ({ spaceId, spaceName, on
[spaceId],
);
+ const onPost = useCallback(
+ async (cardId: string): Promise<ShellCard> => {
+ const card = asCard(await devApi.post(cardId));
+ if (!card) throw new Error('The review came back in a shape this app doesn’t know.');
+ const reviews = deskStore.get(spaceId).reviews ?? [];
+ deskStore._set(spaceId, { reviews: reviews.map((c) => (c.id === card.id ? card : c)) });
+ return card;
+ },
+ [spaceId],
+ );
+
const landed = desk.landed;
const reviews = desk.reviews ?? [];
const landedCards = (landed?.cards ?? []).filter((c) => c.kind === 'landed');
@@ -360,7 +371,7 @@ export const DevDeskView: React.FC<DevDeskViewProps> = ({ spaceId, spaceName, on
/>
)}
{landedCards.length ? (
- <LandedList cards={landedCards} reviews={reviews} now={now} onOpenReview={openReview} />
+ <LandedList cards={landedCards} reviews={reviews} now={now} onOpenReview={openReview} forge={dev?.forge ?? null} />
) : (
landed && (
<Empty title="Nothing has landed yet" line="Each merge to main shows up here as a short card in plain words. kwant checks every 5 minutes." />
@@ -368,7 +379,7 @@ export const DevDeskView: React.FC<DevDeskViewProps> = ({ spaceId, spaceName, on
)}
</>
) : reviews.length ? (
- reviews.map((c) => <ReviewCard key={c.id} card={c} onFinding={onFinding} now={now} />)
+ reviews.map((c) => <ReviewCard key={c.id} card={c} onFinding={onFinding} onPost={onPost} forge={dev?.forge ?? null} forgeLogin={dev?.forge_login ?? null} now={now} />)
) : (
desk.reviews && <Empty title="No open pull requests" line="Each open PR gets a review here from a bot that didn’t write it." />
)}
diff --git a/frontend/src/components/DevDeskSlots.tsx b/frontend/src/components/DevDeskSlots.tsx
index d7e4dcad..2c440f57 100644
--- a/frontend/src/components/DevDeskSlots.tsx
+++ b/frontend/src/components/DevDeskSlots.tsx
@@ -5,7 +5,7 @@
import React, { useMemo } from 'react';
import type { FindingAction, LandedRollup, ShellCard } from '../dev/shellTypes';
import { parseLanded, parseReleaseNotes, parseReview } from '../dev/types';
-import type { LandedCard as Landed, ReviewCard as Review } from '../dev/types';
+import type { Forge, LandedCard as Landed, ReviewCard as Review } from '../dev/types';
import { needsYouAreas } from '../dev/logic';
import { CardFallback } from './dev/parts';
import { LandedList as IrisLandedList } from './dev/LandedCard';
@@ -31,11 +31,18 @@ export interface LandedListProps {
reviews: ShellCard[];
now?: number;
onOpenReview?: (pr: number) => void;
+ /** `forge` from GET dev_mode: names the "Open on {Forge}" link. */
+ forge?: Forge | null;
}
export interface ReviewCardProps {
card: ShellCard;
onFinding: (cardId: string, findingId: string, action: FindingAction) => Promise<ShellCard>;
+ /** 0.7.1 Post to {Forge} (`POST /api/dev/cards/:id/post`). */
+ onPost?: (cardId: string) => Promise<ShellCard>;
+ /** `forge` and `forge_login` from GET dev_mode; no forge, no Post button. */
+ forge?: Forge | null;
+ forgeLogin?: string | null;
sample?: boolean;
now?: number;
}
@@ -56,14 +63,14 @@ export const Rollup: React.FC<RollupProps> = ({ cards = [], ...rest }) => {
return <IrisRollup {...rest} needsYouAreas={needs} />;
};
-export const LandedList: React.FC<LandedListProps> = ({ cards, reviews, now, onOpenReview }) => {
+export const LandedList: React.FC<LandedListProps> = ({ cards, reviews, now, onOpenReview, forge = null }) => {
const parsed = useMemo(() => parseLandedCards(cards), [cards]);
const parsedReviews = useMemo(() => parseReviewCards(reviews), [reviews]);
// Cards Iris's parser refuses (no PR number and no commit, wrong kind) still show, as the plain fallback row.
const refused = useMemo(() => cards.filter((c) => parseLanded(c) === null), [cards]);
return (
<>
- {parsed.length > 0 && <IrisLandedList cards={parsed} reviews={parsedReviews} now={now} onOpenReview={onOpenReview} />}
+ {parsed.length > 0 && <IrisLandedList cards={parsed} reviews={parsedReviews} now={now} onOpenReview={onOpenReview} forge={forge} />}
{refused.map((c) => (
<CardFallback key={c.id} raw={c} />
))}
@@ -71,7 +78,7 @@ export const LandedList: React.FC<LandedListProps> = ({ cards, reviews, now, onO
);
};
-export const ReviewCard: React.FC<ReviewCardProps> = ({ card, onFinding, sample, now }) => {
+export const ReviewCard: React.FC<ReviewCardProps> = ({ card, onFinding, onPost, forge, forgeLogin, sample, now }) => {
const parsed = useMemo(() => parseReview(card), [card]);
if (!parsed) return <CardFallback raw={card} />;
const send = async (cardId: string, findingId: string, action: FindingAction): Promise<Review> => {
@@ -79,7 +86,14 @@ export const ReviewCard: React.FC<ReviewCardProps> = ({ card, onFinding, sample,
if (!next) throw new Error('The review came back in a shape this app doesn’t know.');
return next;
};
- return <IrisReviewCard card={parsed} onFinding={send} sample={sample} now={now} />;
+ const post = onPost
+ ? async (cardId: string): Promise<Review> => {
+ const next = parseReview(await onPost(cardId));
+ if (!next) throw new Error('The review came back in a shape this app doesn’t know.');
+ return next;
+ }
+ : undefined;
+ return <IrisReviewCard card={parsed} onFinding={send} onPost={post} forge={forge} forgeLogin={forgeLogin} sample={sample} now={now} />;
};
export const ReleaseNotesSheet: React.FC<ReleaseNotesSheetProps> = ({ card, onSaveToNotion, onDiscard, onClose }) => {
diff --git a/frontend/src/components/DevModeSetup.tsx b/frontend/src/components/DevModeSetup.tsx
index 55ee4e52..8fd1db30 100644
--- a/frontend/src/components/DevModeSetup.tsx
+++ b/frontend/src/components/DevModeSetup.tsx
@@ -222,7 +222,7 @@ export const DevModeSetup: React.FC<DevModeSetupProps> = ({ space, initial, onCa
<footer className="sticky bottom-0 -mx-6 px-6 bg-[#120e26] border-t border-white/[0.07] pt-3 pb-[max(16px,env(safe-area-inset-bottom))] flex flex-col sm:flex-row sm:items-center gap-3" data-dv-setup-footer>
<p className="flex-1 flex items-start gap-1.5 text-meta text-zinc-500">
<Lock size={12} className="mt-0.5 shrink-0" aria-hidden="true" />
- Only you can turn this on or off. Nothing is posted to GitHub.
+ Only you can turn this on or off. Nothing is posted to GitHub unless you press Post.
</p>
<div className="flex gap-2 justify-end">
<button
diff --git a/frontend/src/components/LooseEndsView.tsx b/frontend/src/components/LooseEndsView.tsx
index 604a4d34..3d9b7e44 100644
--- a/frontend/src/components/LooseEndsView.tsx
+++ b/frontend/src/components/LooseEndsView.tsx
@@ -467,8 +467,11 @@ export const AddSourceForm: React.FC<{ onAdded: (s: LooseSource) => void; onCanc
) : (
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3">
<div className="sm:col-span-2">
- {label(`${id}-tok`, 'Token (read-only access to issues and pull requests is enough)')}
- <input id={`${id}-tok`} ref={secretRef} type="password" className={field} autoComplete="new-password" />
+ {label(`${id}-tok`, 'Token')}
+ <input id={`${id}-tok`} ref={secretRef} type="password" className={field} autoComplete="new-password" aria-describedby={`${id}-tok-hint`} />
+ <p id={`${id}-tok-hint`} className="mt-1 text-[11px] text-zinc-400">
+ Read-only access to issues and pull requests is enough. To post reviews from Dev mode, give it Pull requests: Read and write.
+ </p>
</div>
<div>
{label(`${id}-glabel`, 'Name (optional)')}
diff --git a/frontend/src/components/dev/LandedCard.tsx b/frontend/src/components/dev/LandedCard.tsx
index c4718a74..91741dce 100644
--- a/frontend/src/components/dev/LandedCard.tsx
+++ b/frontend/src/components/dev/LandedCard.tsx
@@ -1,8 +1,8 @@
import React from 'react';
import { AlertTriangle, Check, ChevronRight, FileText, FlaskConical, GitCommitHorizontal, GitMerge, Minus, ShieldCheck, X } from 'lucide-react';
import { Sticker } from '../Sticker';
-import type { LandedCard as Landed, LandedListProps, ReviewCard } from '../../dev/types';
-import { byDay, clock, openFindings, riskReasons, showVerified } from '../../dev/logic';
+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';
const isTest = (path: string) => /(^|\/)(tests?|__tests__|e2e)\/|\.(test|spec)\.[a-z]+$|_test\.[a-z]+$/.test(path);
@@ -11,7 +11,12 @@ const TESTS_ICON = { passed: Check, failed: X, none: Minus, unknown: Minus } as
const TESTS_TONE = { passed: 'text-ok', failed: 'text-bad', none: 'text-zinc-400', unknown: 'text-zinc-400' } 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 }> = ({ card, reviews = [], onOpenReview }) => {
+export const LandedCard: React.FC<{ card: Landed; reviews?: ReviewCard[]; onOpenReview?: (pr: number) => void; forge?: Forge | null }> = ({
+ card,
+ reviews = [],
+ onOpenReview,
+ forge = null,
+}) => {
const verified = showVerified(card, reviews);
const writer = personText(card.written_by);
const merged = clock(card.merged_at);
@@ -187,7 +192,7 @@ export const LandedCard: React.FC<{ card: Landed; reviews?: ReviewCard[]; onOpen
)}
{github && (
<OutLink href={github} className="min-h-[44px] sm:min-h-0">
- Open on GitHub
+ {forgeOpen(forge, card.links.pr ? 'pr' : 'commit')}
</OutLink>
)}
</span>
@@ -197,7 +202,7 @@ export const LandedCard: React.FC<{ card: Landed; reviews?: ReviewCard[]; onOpen
};
/** What landed: the cards under "Today", "Yesterday" and date separators. */
-export const LandedList: React.FC<LandedListProps> = ({ cards, reviews, now = Date.now(), onOpenReview }) => (
+export const LandedList: React.FC<LandedListProps> = ({ cards, reviews, now = Date.now(), onOpenReview, forge = null }) => (
<div data-dev-landed-list className="space-y-3">
{byDay(cards, now).map((day) => (
<section key={day.label} aria-label={day.label} className="space-y-3">
@@ -206,7 +211,7 @@ export const LandedList: React.FC<LandedListProps> = ({ cards, reviews, now = Da
<span aria-hidden="true" className="h-px flex-1 bg-hairline" />
</h3>
{day.cards.map((c) => (
- <LandedCard key={c.id || c.pr || c.sha} card={c} reviews={reviews} onOpenReview={onOpenReview} />
+ <LandedCard key={c.id || c.pr || c.sha} card={c} reviews={reviews} onOpenReview={onOpenReview} forge={forge} />
))}
</section>
))}
diff --git a/frontend/src/components/dev/ReviewCard.tsx b/frontend/src/components/dev/ReviewCard.tsx
index d1f12d55..c2cc40ad 100644
--- a/frontend/src/components/dev/ReviewCard.tsx
+++ b/frontend/src/components/dev/ReviewCard.tsx
@@ -5,7 +5,7 @@ import {
FlaskConical,
GitPullRequest,
KeyRound,
- Lock,
+ Loader2,
Package,
ShieldAlert,
ShieldCheck,
@@ -15,7 +15,7 @@ import {
Bug,
Code2,
} from 'lucide-react';
-import type { DevFinding, FindingAction, ReviewCard as Review, ReviewCardProps, Severity, TamperFlag } from '../../dev/types';
+import type { DevFinding, FindingAction, Forge, ReviewCard as Review, ReviewCardProps, Severity, TamperFlag } from '../../dev/types';
import {
DISMISS_REASONS,
clock,
@@ -23,10 +23,20 @@ import {
dismissReducer,
dismissedLine,
findingsSummary,
+ FORGE_NAME,
+ readOnlyFix,
+ commentsWord,
+ readOnlyTip,
+ STALE_LINE,
+ postCount,
+ postLabel,
+ postState,
+ postedLine,
riskReasons,
undoLeft,
} from '../../dev/logic';
-import { OutLink, SectionHead, Who, modelLabel, personText } from './parts';
+import type { LedState, PostState } from '../../dev/logic';
+import { Led, OutLink, SectionHead, Who, modelLabel, personText } from './parts';
// Severity styling copied from results/Findings.tsx (design §5.6: "reuse as is").
const DOT: Record<Severity, string> = { critical: 'bg-rose-500', high: 'bg-orange-500', medium: 'bg-amber-500', low: 'bg-sky-500' };
@@ -248,8 +258,160 @@ const FindingRow: React.FC<FindingRowProps> = ({ f, author, now, busy, act }) =>
// ---------------------------------------------------------------------------------------------------
+// ---------------------------------------------------------------------------------------------------
+// 7. Footer: Post to {Forge} (0.7.1, design §5.7, plan/post-to-github.md + amendment). With no forge there is
+// no Post button and no lock line.
+
+const PostFooter: React.FC<{
+ id: string;
+ state: PostState;
+ forge: Forge | null;
+ count: number;
+ login: string | null;
+ prLink: string | null;
+ onPost: () => void;
+}> = ({ id, state, forge, count, login, prLink, onPost }) => {
+ // Style v2 §7: forge null means no footer at all (nothing to post, nowhere named to open).
+ if (!forge) return null;
+ const name = FORGE_NAME[forge];
+ const label = postLabel(count, forge);
+ const lineId = `${id}-post-line`;
+ const At = ({ who }: { who: string }) => <span className="font-mono text-zinc-100">@{who}</span>;
+ const withLed = (s: LedState, body: React.ReactNode, attr: Record<string, string>) => (
+ <span {...attr} className="inline-flex min-w-0 items-start gap-[7px]">
+ <Led s={s} className="mt-[5px] shrink-0" />
+ <span className="min-w-0 [overflow-wrap:anywhere]">{body}</span>
+ </span>
+ );
+ // Phone: the button gets its own full-width row at 44 px; from 640 px it sits on the right of the line.
+ const btn = 'min-h-[44px] w-full justify-center px-3 py-1 text-xs sm:min-h-[32px] sm:w-auto';
+ let line: React.ReactNode;
+ let action: React.ReactNode = null;
+ const lockLine = (who: string | null) => (
+ <span>
+ Nothing is posted until you press it.
+ {who && (
+ <>
+ {' '}Posts as <At who={who} />.
+ </>
+ )}
+ </span>
+ );
+ // A disabled Post button (read only, stale): aria-disabled so it stays focusable and its title is reachable.
+ const off = (title?: string) => (
+ <button
+ type="button"
+ aria-disabled="true"
+ aria-describedby={lineId}
+ title={title}
+ data-post-disabled
+ onClick={(e) => e.preventDefault()}
+ className={`kw-btn-ghost ${btn} cursor-not-allowed opacity-60 hover:bg-white/[0.03] hover:text-zinc-200`}
+ >
+ {label}
+ </button>
+ );
+ switch (state.kind) {
+ case 'none':
+ line = lockLine(null);
+ break;
+ case 'posted':
+ line = withLed(
+ 'ok',
+ <>
+ Posted{clock(state.at) ? ` ${clock(state.at)}` : ''}
+ {state.login && (
+ <>
+ {' '}as <At who={state.login} />
+ </>
+ )}
+ {commentsWord(state.comments) && <> · {commentsWord(state.comments)}</>}
+ </>,
+ { 'data-post-done': '' },
+ );
+ if (state.url) action = <OutLink href={state.url} className="min-h-[44px] sm:min-h-0">{`View on ${name}`}</OutLink>;
+ break;
+ case 'read_only':
+ line = withLed(
+ 'warn',
+ <>
+ {readOnlyTip(forge)}. Give the token <code className="dv-code">{readOnlyFix(forge)}</code> to post.
+ </>,
+ { 'data-post-read-only': '' },
+ );
+ // F1 (QA 0.7.1): read_only is cleared only by a post, so the press must reach the server once the token is fixed.
+ action = (
+ <button type="button" onClick={onPost} aria-describedby={lineId} data-post-retry className={`kw-btn-ghost ${btn}`}>
+ Try again
+ </button>
+ );
+ break;
+ case 'stale':
+ line = withLed('run', STALE_LINE, { 'data-post-stale': '' });
+ action = off();
+ break;
+ case 'failed':
+ line = withLed('bad', <>Couldn’t post: {state.message}</>, { 'data-post-failed': '' });
+ action = state.retry ? (
+ <button type="button" onClick={onPost} data-post-retry className={`kw-btn-ghost ${btn}`}>
+ Try again
+ </button>
+ ) : null;
+ break;
+ default: {
+ const busy = state.kind === 'posting';
+ line = lockLine(login);
+ action = (
+ <button type="button" disabled={busy} aria-busy={busy || undefined} onClick={onPost} data-post-button className={`kw-btn-primary ${btn} disabled:cursor-wait`}>
+ {busy ? (
+ <>
+ <Loader2 size={12} aria-hidden="true" className="motion-safe:animate-spin" />
+ Posting…
+ </>
+ ) : (
+ label
+ )}
+ </button>
+ );
+ }
+ }
+ // F7 (user-flow.md): Post first, then "Open on {Forge}". Not after posting: View on {Forge} replaces it.
+ const link = !!prLink && state.kind !== 'posted';
+ // F4: no review, no Post footer; the card keeps only its link to the PR.
+ if (state.kind === 'no_review')
+ return link ? (
+ <footer data-review-footer data-post-state="no_review" className="mt-4 flex flex-wrap items-center gap-x-3 gap-y-2 border-t border-hairline pt-3 text-[12.5px] text-zinc-400">
+ <span data-forge-link className="text-meta">
+ <OutLink href={prLink!} className="min-h-[44px] sm:min-h-0">{`Open on ${name}`}</OutLink>
+ </span>
+ </footer>
+ ) : null;
+ return (
+ <footer data-review-footer data-post-state={state.kind} className="mt-4 flex flex-wrap items-center gap-x-3 gap-y-2 border-t border-hairline pt-3 text-[12.5px] text-zinc-400">
+ <div id={lineId} className="min-w-0 flex-1 basis-full sm:basis-0">{line}</div>
+ {action && <div className="flex basis-full sm:basis-auto">{action}</div>}
+ {link && (
+ <span data-forge-link className="text-meta">
+ <OutLink href={prLink!} className="min-h-[44px] sm:min-h-0">{`Open on ${name}`}</OutLink>
+ </span>
+ )}
+ <span role="status" aria-live="polite" className="sr-only">
+ {state.kind === 'posted'
+ ? postedLine(state.at, state.login, state.comments)
+ : state.kind === 'failed'
+ ? `Couldn’t post: ${state.message}`
+ : state.kind === 'stale'
+ ? STALE_LINE
+ : state.kind === 'posting'
+ ? 'Posting…'
+ : ''}
+ </span>
+ </footer>
+ );
+};
+
/** One PR in review: risk, intent, tests, security and findings (design §5, parts 1–7). */
-export const ReviewCard: React.FC<ReviewCardProps> = ({ card: given, onFinding, sample = false, now: fixedNow }) => {
+export const ReviewCard: React.FC<ReviewCardProps> = ({ card: given, onFinding, sample = false, now: fixedNow, onPost, forge = null, forgeLogin = null }) => {
const [card, setCard] = useState<Review>(given);
const [busy, setBusy] = useState<string | null>(null);
const [tick, setTick] = useState(() => Date.now());
@@ -279,6 +441,24 @@ export const ReviewCard: React.FC<ReviewCardProps> = ({ card: given, onFinding,
}
};
+ const [posting, setPosting] = useState(false);
+ // F4: the server answers 409 when the card has no review; that press is final, no Try again.
+ const [noReview, setNoReview] = useState(false);
+ const post = async () => {
+ if (!onPost || posting || noReview || card.posted) return;
+ setPosting(true);
+ try {
+ setCard(await onPost(card.id));
+ } catch (err) {
+ // The route answers 200 with post_error for the forge's refusals; a throw is the network or a 4xx from kwant.
+ const message = err instanceof Error && err.message ? err.message : 'it didn’t go through';
+ if ((err as { status?: unknown } | null)?.status === 409) setNoReview(true);
+ setCard((c) => ({ ...c, post_error: { kind: 'failed', message } }));
+ } finally {
+ setPosting(false);
+ }
+ };
+
const author = personText(card.author);
const authorModel = card.author ? modelLabel(card.author.engine, card.author.model) : null;
const reviewerModel = card.reviewer ? modelLabel(card.reviewer.engine, card.reviewer.model) : null;
@@ -445,18 +625,16 @@ export const ReviewCard: React.FC<ReviewCardProps> = ({ card: given, onFinding,
{card.cut && <p className="mt-3 text-2xs text-zinc-400">{card.cut}</p>}
- {/* 7. Footer: 0.7.0 is read only (D4), so there is no Post to GitHub button. */}
- <footer data-review-footer className="mt-4 flex flex-wrap items-center gap-x-3 gap-y-2 border-t border-hairline pt-3">
- <span className="inline-flex min-w-0 items-center gap-1.5 text-xs text-zinc-400">
- <Lock size={13} aria-hidden="true" className="shrink-0" />
- Read only: nothing is posted to GitHub in this version.
- </span>
- {card.links.pr && (
- <span className="text-meta sm:ml-auto">
- <OutLink href={card.links.pr}>Open on GitHub</OutLink>
- </span>
- )}
- </footer>
+ {/* 7. Footer: Post to {Forge} (design §5.7) */}
+ <PostFooter
+ id={headingId}
+ state={postState(card, { canPost: !!onPost && !sample, posting, forge, noReview })}
+ forge={card.posted?.forge ?? forge}
+ count={postCount(card.findings)}
+ login={forgeLogin}
+ prLink={card.links.pr}
+ onPost={() => void post()}
+ />
</article>
);
};
diff --git a/frontend/src/components/dev/parts.tsx b/frontend/src/components/dev/parts.tsx
index 210d0828..37da6bd4 100644
--- a/frontend/src/components/dev/parts.tsx
+++ b/frontend/src/components/dev/parts.tsx
@@ -2,7 +2,8 @@ import React from 'react';
import { ExternalLink } from 'lucide-react';
import { ModernAvatar } from '../ModernAvatar';
import type { DevPerson, RiskLevel } from '../../dev/types';
-import { RISK_WORD } from '../../dev/logic';
+import { RISK_WORD, diffBar, diffLabel, shortSha } from '../../dev/logic';
+import type { LedState } from '../../dev/logic';
/** "Claude Opus" from a label, or a model id like claude-opus-5-5, else the engine's name. */
export function modelLabel(engine: string | null, model: string | null): string | null {
@@ -79,3 +80,36 @@ export const CardFallback: React.FC<{ raw: unknown }> = ({ raw }) => {
</div>
);
};
+
+// ---------------------------------------------------------------------------------------------------
+// Style v2 parts (style-v2.md §2). Classes live in styles/modern.css (the shared .dv-* block).
+
+/** An 8 px status light. Decoration: it always sits next to words that say the same thing. `run` pings
+ * only while something is running; reduced motion keeps a static ring. */
+export const Led: React.FC<{ s: LedState; className?: string }> = ({ s, className = '' }) => (
+ <span aria-hidden="true" data-s={s} className={className ? `dv-led ${className}` : 'dv-led'} />
+);
+
+/** `+157 −15` in mono with the 32×4 split bar; read as "157 lines added, 15 removed". */
+export const DiffStat: React.FC<{ add: number; del: number; className?: string }> = ({ add, del, className = '' }) => {
+ const bar = diffBar(add, del);
+ return (
+ <span role="img" aria-label={diffLabel(add, del)} data-diffstat={`${add},${del}`} className={className ? `dv-stat ${className}` : 'dv-stat'}>
+ <span aria-hidden="true">
+ <span className="a">+{add}</span> <span className="d">−{del}</span>
+ </span>
+ <span aria-hidden="true" className="dv-bar">
+ {bar.add > 0 && <i className="a" style={{ width: bar.add }} />}
+ {bar.del > 0 && <i className="d" style={{ width: bar.del }} />}
+ </span>
+ </span>
+ );
+};
+
+/** A 7-character commit sha chip in mono. */
+export const Sha: React.FC<{ sha: string; className?: string }> = ({ sha, className = '' }) => (
+ <span data-sha className={className ? `dv-sha ${className}` : 'dv-sha'}>
+ <span className="sr-only">Commit </span>
+ {shortSha(sha)}
+ </span>
+);
diff --git a/frontend/src/dev/logic.ts b/frontend/src/dev/logic.ts
index bae06a3f..73b04a66 100644
--- a/frontend/src/dev/logic.ts
+++ b/frontend/src/dev/logic.ts
@@ -6,6 +6,7 @@ import type {
BackupResult,
DevFinding,
DismissReason,
+ Forge,
FloorBackup,
LandedCard,
ProdFloor,
@@ -356,3 +357,105 @@ export function findingsSummary(findings: DevFinding[]): string {
.map(([s, n]) => `${n} ${s}`)
.join(', ');
}
+
+// ---------------------------------------------------------------------------------------------------
+// Post to {Forge} (0.7.1, plan/post-to-github.md + amendment): the review card footer's one state
+
+/** Findings the post turns into comments: every one not dismissed (design §5.7 "N = open findings"). */
+export const postCount = (findings: Pick<DevFinding, 'state'>[]): number => findings.filter((f) => f.state !== 'dismissed').length;
+
+/** Display names for `forge` (amendment, 21:50): posting is GitHub-only in 0.7.1, GitLab and Gitea come in 0.7.2. */
+export const FORGE_NAME: Record<Forge, string> = { github: 'GitHub', gitlab: 'GitLab', gitea: 'Gitea' };
+
+/** "Post to GitHub · 3 findings"; no count when nothing is open (the review is then its body only). F6: findings, not
+ * comments, because a finding outside the diff goes in the review body; the posted line counts inline comments. */
+/** The link to the PR (or a direct commit) on its forge: "Open on GitHub". Landed cards keep the link with no
+ * forge (the URL is in the card), named plainly; the review footer hides it instead (user-flow.md F7). */
+export const forgeOpen = (forge: Forge | null, what: 'pr' | 'commit' = 'pr'): string =>
+ forge ? `Open on ${FORGE_NAME[forge]}` : what === 'pr' ? 'Open pull request' : 'Open commit';
+
+export function postLabel(n: number, forge: Forge): string {
+ const to = `Post to ${FORGE_NAME[forge]}`;
+ return n === 0 ? to : `${to} · ${n} ${n === 1 ? 'finding' : 'findings'}`;
+}
+
+/** "Nothing is posted until you press it. Posts as octocat." (the second sentence only with a login). */
+export function postLine(login: string | null | undefined): string {
+ return login ? `Nothing is posted until you press it. Posts as @${login}.` : 'Nothing is posted until you press it.';
+}
+
+/** "3 inline comments", "1 inline comment", or null for none or unknown (the line then drops it). `posted.comments`
+ * counts only the comments on diff lines (F6, QA 0.7.1). */
+export const commentsWord = (n: number | null | undefined): string | null => (n ? `${n} inline ${n === 1 ? 'comment' : 'comments'}` : null);
+
+export const readOnlyTip = (forge: Forge): string => `Your ${FORGE_NAME[forge]} connection is read only`;
+/** Style v2 §7: what to give the token. The scope name is GitHub's; other forges get plain words. */
+export const readOnlyFix = (forge: Forge): string => (forge === 'github' ? 'pull_requests: write' : 'write access');
+/** The whole read-only line, for screen readers and tests: "Your GitHub connection is read only. Give the token pull_requests: write to post." */
+export const readOnlyLine = (forge: Forge): string => `${readOnlyTip(forge)}. Give the token ${readOnlyFix(forge)} to post.`;
+export const STALE_LINE = 'This PR has new commits. A new review is on its way.';
+
+export type PostState =
+ | { kind: 'none' } // no Post button: the sample PR, or a card still being written
+ | { kind: 'no_review' } // F4: the review failed to generate, so there is nothing to post (no lock line, no button)
+ | { kind: 'ready' }
+ | { kind: 'posting' }
+ | { kind: 'posted'; at: string | null; url: string | null; login: string | null; comments: number | null }
+ | { kind: 'read_only' }
+ | { kind: 'stale' }
+ | { kind: 'failed'; message: string; retry: boolean };
+
+/**
+ * Which footer to draw. `posted` wins over everything (the server never posts twice, P6); then the
+ * in-flight press; then the last error; a pending card has no review to post yet.
+ */
+export function postState(
+ card: { status: string; posted: { at: string | null; url: string | null; login?: string | null; comments?: number | null } | null; post_error: { kind: string; message: string | null } | null },
+ opts: { canPost: boolean; posting: boolean; forge: Forge | null; noReview?: boolean },
+): PostState {
+ if (card.posted) return { kind: 'posted', at: card.posted.at, url: card.posted.url, login: card.posted.login ?? null, comments: card.posted.comments ?? null };
+ if (!opts.canPost || !opts.forge || card.status === 'pending') return { kind: 'none' };
+ // F4: a card whose review didn't finish has nothing to post.
+ if (card.status === 'failed') return { kind: 'no_review' };
+ if (opts.posting) return { kind: 'posting' };
+ const e = card.post_error;
+ if (e?.kind === 'read_only') return { kind: 'read_only' };
+ if (e?.kind === 'stale') return { kind: 'stale' };
+ // noReview: the server answered 409 (no review on this card): say why, but offer no repost.
+ if (e) return { kind: 'failed', message: e.message ?? `${FORGE_NAME[opts.forge]} didn’t say why.`, retry: !opts.noReview };
+ return { kind: 'ready' };
+}
+
+/** "Posted 19:58 as @oleks-i · 3 comments"; the time, login and count each drop out when unknown. */
+export const postedLine = (at: string | null, login: string | null = null, comments: number | null = null): string => {
+ const t = clock(at);
+ const n = commentsWord(comments);
+ return `Posted${t ? ` ${t}` : ''}${login ? ` as @${login}` : ''}${n ? ` · ${n}` : ''}`;
+};
+// Style v2 parts (Mira, style-v2.md §2): pure helpers behind <Led>, <DiffStat> and <Sha>
+
+export type LedState = 'ok' | 'run' | 'warn' | 'bad' | 'off';
+
+/**
+ * The 32×4 split bar: px for the add part and the del part (1 px gap between them when both show).
+ * Add share = round(31·a/(a+d)), at least 3 px when a > 0 and at least 3 px left for del when d > 0.
+ */
+export function diffBar(add: number, del: number): { add: number; del: number } {
+ const a = Math.max(0, add);
+ const d = Math.max(0, del);
+ if (a + d === 0) return { add: 0, del: 0 };
+ if (d === 0) return { add: 32, del: 0 };
+ if (a === 0) return { add: 0, del: 32 };
+ const ap = Math.min(28, Math.max(3, Math.round((31 * a) / (a + d))));
+ return { add: ap, del: 31 - ap };
+}
+
+/** "157 lines added, 15 removed" (one line / no lines read right). */
+export function diffLabel(add: number, del: number): string {
+ const l = (n: number) => (n === 1 ? 'line' : 'lines');
+ return `${add} ${l(add)} added, ${del} removed`;
+}
+
+/** The first 7 characters of a commit sha. */
+export const shortSha = (sha: string): string => sha.trim().slice(0, 7);
+
diff --git a/frontend/src/dev/types.ts b/frontend/src/dev/types.ts
index c16f6f76..5fa5ce34 100644
--- a/frontend/src/dev/types.ts
+++ b/frontend/src/dev/types.ts
@@ -119,6 +119,28 @@ export interface ReviewCard extends CardBase {
findings: DevFinding[];
cut: string | null;
links: DevLinks;
+ /** 0.7.1 Post to GitHub (plan/post-to-github.md): set once the person posted this card as a PR review. */
+ posted: ReviewPosted | null;
+ /** Why the last post didn't go through; a successful post clears it. */
+ post_error: PostError | null;
+}
+
+export type Forge = 'github' | 'gitlab' | 'gitea';
+
+export interface ReviewPosted {
+ /** Where it was posted; "github" in 0.7.1. */
+ forge: Forge | null;
+ at: string | null;
+ login: string | null;
+ /** https only, or null (then there is no "View on {Forge}" link). */
+ url: string | null;
+ comments: number | null;
+}
+
+export type PostErrorKind = 'read_only' | 'stale' | 'failed';
+export interface PostError {
+ kind: PostErrorKind;
+ message: string | null;
}
export interface ReleaseNotesCard extends CardBase {
@@ -203,6 +225,8 @@ export interface LandedListProps {
now?: number;
/** Opens the PR's review card ("1 finding open in the review · Open review"); the link hides without it. */
onOpenReview?: (pr: number) => void;
+ /** `forge` from GET dev_mode: names the link ("Open on GitHub"). */
+ forge?: Forge | null;
}
export interface ReviewCardProps {
@@ -212,6 +236,13 @@ export interface ReviewCardProps {
/** Shows the "Sample PR" chip (design §5: the #294 sample). */
sample?: boolean;
now?: number;
+ /** Posts the card as a PR review (`POST /api/dev/cards/:id/post`) and resolves with the new card, or throws.
+ * Without it the footer has no Post button (the sample PR). */
+ onPost?: (cardId: string) => Promise<ReviewCard>;
+ /** `forge` from GET dev_mode: names the button ("Post to GitHub"). Null: no Post button and no lock line. */
+ forge?: Forge | null;
+ /** `forge_login` from GET dev_mode, for "Posts as {login}." */
+ forgeLogin?: string | null;
}
export interface ReleaseNotesSheetProps {
@@ -385,9 +416,24 @@ export function parseReview(raw: unknown): ReviewCard | null {
findings: arr(raw.findings).map(finding).filter((f): f is DevFinding => !!f),
cut: str(raw.cut, 120),
links: links(raw.links),
+ posted: posted(raw.posted),
+ post_error: postError(raw.post_error),
};
}
+function posted(v: unknown): ReviewPosted | null {
+ if (!isObj(v)) return null;
+ const url = str(v.url, 1000);
+ const n = num(v.comments);
+ const fg = v.forge;
+ return { forge: fg === 'github' || fg === 'gitlab' || fg === 'gitea' ? fg : null, at: str(v.at, 64), login: str(v.login, 80), url: url && /^https:\/\//.test(url) ? url : null, comments: n !== null && n >= 0 ? Math.floor(n) : null };
+}
+
+function postError(v: unknown): PostError | null {
+ if (!isObj(v)) return null;
+ return { kind: oneOf(v.kind, ['read_only', 'stale', 'failed'] as const, 'failed'), message: str(v.message, 300) };
+}
+
export function parseReleaseNotes(raw: unknown): ReleaseNotesCard | null {
if (!isObj(raw) || raw.kind !== 'release_notes') return null;
return { ...base(raw), kind: 'release_notes', since_tag: str(raw.since_tag, 80), markdown: str(raw.markdown, 20000), whats_new: str(raw.whats_new, 2000) };
diff --git a/frontend/src/devMode.ts b/frontend/src/devMode.ts
index 1ef18d4c..d3a4948b 100644
--- a/frontend/src/devMode.ts
+++ b/frontend/src/devMode.ts
@@ -21,6 +21,10 @@ export interface DevModeState {
poll_error: string | null;
calls_today: number | null;
calls_cap: number | null;
+ /** 0.7.1: which forge reads the repo ("github" in 0.7.1; gitlab and gitea from 0.7.2), or null: no Post button. */
+ forge: Forge | null;
+ /** 0.7.1: that forge connection's login, for "Posts as {login}." on review cards. */
+ forge_login: string | null;
}
export type CheckState = 'found' | 'not_found' | 'not_connected';
@@ -34,6 +38,8 @@ export interface RepoCheck {
}
const str = (v: unknown): string | null => (typeof v === 'string' && v.trim() ? v : null);
+export type Forge = 'github' | 'gitlab' | 'gitea';
+export const forgeOf = (v: unknown): Forge | null => (v === 'github' || v === 'gitlab' || v === 'gitea' ? v : null);
const num = (v: unknown): number | null => (typeof v === 'number' && Number.isFinite(v) ? v : null);
const hint = (v: unknown): DeployHint => (v === 'docker' || v === 'cloudflare_pages' || v === 'fly' ? v : null);
@@ -52,6 +58,8 @@ export function parseDevMode(raw: unknown): DevModeState | null {
poll_error: str(o.poll_error),
calls_today: num(o.calls_today),
calls_cap: num(o.calls_cap),
+ forge: forgeOf(o.forge),
+ forge_login: str(o.forge_login),
};
}
@@ -400,6 +408,8 @@ export const devApi = {
reviews: (space: string) => call<unknown>(`/api/spaces/${enc(space)}/dev/reviews`).then((r) => r.data),
finding: (card: string, fid: string, body: { action: string; reason?: string; note?: string }) =>
call<unknown>(`/api/dev/cards/${enc(card)}/findings/${enc(fid)}`, 'POST', body).then((r) => r.data),
+ /** 0.7.1 Post to {Forge}: one PR review from this card. 200 with the card, `post_error` set when the forge refused. */
+ post: (card: string) => call<unknown>(`/api/dev/cards/${enc(card)}/post`, 'POST', {}).then((r) => r.data),
/** Not in lin-dev-core 492019f yet (asked Lin): the ready release-notes card after its SSE. */
card: (id: string) => call<unknown>(`/api/dev/cards/${enc(id)}`).then((r) => r.data),
releaseNotes: (space: string) => call<unknown>(`/api/spaces/${enc(space)}/dev/release_notes`, 'POST').then((r) => r.data),
@@ -459,6 +469,8 @@ export const emptyState = (): DevModeState => ({
poll_error: null,
calls_today: null,
calls_cap: null,
+ forge: null,
+ forge_login: null,
});
// ---------------------------------------------------------------------------
diff --git a/frontend/src/looseEnds.ts b/frontend/src/looseEnds.ts
index ae496108..fe8d74f3 100644
--- a/frontend/src/looseEnds.ts
+++ b/frontend/src/looseEnds.ts
@@ -341,7 +341,7 @@ export function imapSource(f: ImapFields, secret: string): NewSource | { error:
}
export function githubSource(label: string, apiBase: string, token: string): NewSource | { error: string } {
- if (!token) return { error: 'Enter a GitHub token. It only needs to read issues and pull requests.' };
+ if (!token) return { error: 'Enter a GitHub token. Read-only access to issues and pull requests is enough. To post reviews from Dev mode, give it Pull requests: Read and write.' };
const base = apiBase.trim() || 'https://api.github.com';
return { kind: 'github', label: label.trim() || 'GitHub', config: { api_base: base }, secret: token };
}
diff --git a/frontend/src/styles/modern.css b/frontend/src/styles/modern.css
index de8780dd..0707d2da 100644
--- a/frontend/src/styles/modern.css
+++ b/frontend/src/styles/modern.css
@@ -674,3 +674,128 @@ a.kw-sticker:hover { transform: rotate(var(--kw-tilt)) scale(1.04); box-shadow:
.kw-dv-sheet { animation: kw-dv-sheet-in 180ms var(--kw-ease) both; }
@keyframes kw-dv-sheet-in { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .kw-dv-sheet { animation: none; } }
+
+/* =================================================================================================
+ Dev mode style v2 (Mira, dev-mode/design/style-v2/tokens.css, dark only). Verbatim from tokens.css:
+ the --t1..--t5 and --accent aliases the classes use, the new --dv-* tokens, and the .dv-* component classes.
+ Shared by Pixel (PX-*) and Iris (IR-*); keep this block identical on every branch.
+ ================================================================================================= */
+:root {
+ --t1: #f7f6ff; --t2: #ecebfa; --t3: #bcb7de; --t4: #9a94c4; --t5: #8d87b8;
+ --accent: #b8adff; /* sky-300: accent text */
+ --accent-strong: #9d8fff; /* sky-400: working / accent strokes */
+ --accent-fill: #6c58e0; /* sky-600: toggles on */
+ --accent-gradient: linear-gradient(135deg, #7a62f0 0%, #5b47d6 100%);
+ --accent-soft: linear-gradient(135deg, rgb(122 98 240 / .22) 0%, rgb(91 71 214 / .10) 100%);
+ /* new Dev tokens (style v2) */
+ --dv-code-bg: rgb(10 7 25 / .72); /* command boxes, diff excerpts, sha chips */
+ --dv-add: #5eead4; --dv-add-bg: rgb(94 234 212 / .10);
+ --dv-del: #fda4af; --dv-del-bg: rgb(253 164 175 / .12);
+ --dv-led-ok: #5eead4; --dv-led-run: #9d8fff; --dv-led-warn: #fcd34d; --dv-led-bad: #fda4af; --dv-led-off: #8d87b8;
+ --dv-rail: rgb(157 143 255 / .38); /* git rail line */
+ --dv-hazard: #fbbf24; /* production floor edge only */
+ --dv-stamp: #5eead4; /* LGTM ink */
+ --dv-kbd-bg: #231d4b; --dv-kbd-bd: rgb(255 255 255 / .18);
+ --dv-caret: #b8adff;
+ --dv-armed: #fcd34d; /* the switch's armed state (amber = "press again") */
+ --dv-warn-bd: rgb(252 211 77 / .35); --dv-warn-bg: rgb(252 211 77 / .10);
+ --dv-bad-bd: rgb(253 164 175 / .35); --dv-bad-bg: rgb(253 164 175 / .10);
+ --dv-ok-bd: rgb(94 234 212 / .30); --dv-ok-bg: rgb(94 234 212 / .08);
+ --dv-floor-bd: rgb(245 158 11 / .30); --dv-floor-bg: rgb(69 26 3 / .20);
+ --dv-allow: #d97706;
+}
+
+/* §2.1 LED: an 8 px dot with a crisp 2 px ring in its own colour at 28 %. Never a glow blob.
+ off is hollow, so off vs on is shape as well as colour. Always next to words. */
+.dv-led { position: relative; display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
+ background: var(--c); box-shadow: 0 0 0 2px color-mix(in srgb, var(--c) 28%, transparent); --c: var(--dv-led-off); }
+.dv-led[data-s="ok"] { --c: var(--dv-led-ok); }
+.dv-led[data-s="run"] { --c: var(--dv-led-run); }
+.dv-led[data-s="warn"] { --c: var(--dv-led-warn); }
+.dv-led[data-s="bad"] { --c: var(--dv-led-bad); }
+.dv-led[data-s="off"] { background: transparent; box-shadow: inset 0 0 0 1.5px var(--c); }
+/* run: a ring that grows and fades, 1.2 s, only while the thing is actually running */
+.dv-led[data-s="run"]::after { content: ''; position: absolute; inset: 0; border-radius: 50%; border: 1.5px solid var(--c);
+ animation: dv-ping 1.2s var(--kw-ease) infinite; }
+/* ping: one 200 ms pop when a check finishes (the "Checked 14:32" moment) */
+.dv-led[data-ping]::after { content: ''; position: absolute; inset: 0; border-radius: 50%; border: 1.5px solid var(--c); animation: dv-ping 200ms var(--kw-ease) 1 both; }
+@keyframes dv-ping { from { transform: scale(1); opacity: .9; } to { transform: scale(2.4); opacity: 0; } }
+
+/* §2.2 Diff stat: mono numbers plus a 32x4 split bar (add | del). Our own shape, not a block meter. */
+.dv-stat { display: inline-flex; align-items: center; gap: 6px; font: 500 11.5px/1 'JetBrains Mono', monospace; white-space: nowrap; }
+.dv-stat .a { color: var(--dv-add); } .dv-stat .d { color: var(--dv-del); }
+.dv-bar { display: inline-flex; gap: 1px; width: 32px; height: 4px; border-radius: 2px; overflow: hidden; background: var(--kw-hairline-strong); }
+.dv-bar i { display: block; height: 100%; }
+.dv-bar i.a { background: var(--dv-add); } .dv-bar i.d { background: var(--dv-del); }
+
+/* §2.3 Mono chips: sha, branch flow, path, login */
+.dv-sha { display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 0 6px; border-radius: 6px; border: 1px solid var(--kw-hairline); background: var(--dv-code-bg);
+ font: 500 11px/1 'JetBrains Mono', monospace; color: var(--t3); white-space: nowrap; }
+button.dv-sha { cursor: copy; } button.dv-sha:hover { color: var(--accent); border-color: var(--kw-hairline-strong); }
+.dv-branch { display: inline-flex; align-items: center; gap: 5px; max-width: 100%; height: 22px; padding: 0 7px; border-radius: 6px; border: 1px solid var(--kw-hairline); background: var(--dv-code-bg);
+ font: 500 11px/1 'JetBrains Mono', monospace; color: var(--t3); min-width: 0; }
+.dv-branch .h { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--t2); }
+.dv-branch .arr { color: var(--t5); }
+.dv-branch svg.i { width: 11px; height: 11px; color: var(--accent); }
+.dv-code { font: 500 0.92em/1 'JetBrains Mono', monospace; color: var(--accent); }
+
+/* §2.4 kbd */
+.dv-kbd { display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 5px;
+ background: var(--dv-kbd-bg); border: 1px solid var(--dv-kbd-bd); border-bottom-width: 2px; font: 600 10.5px/1 'JetBrains Mono', monospace; color: var(--t2); vertical-align: middle; }
+
+/* §2.5 Caret: blinks 4 times (900 ms steps) then stays solid. Static under reduced motion. */
+.dv-caret { display: inline-block; width: 7px; height: 14px; margin-left: 2px; vertical-align: -2px; background: var(--dv-caret); border-radius: 1px; animation: dv-blink 900ms steps(1) 4; }
+@keyframes dv-blink { 50% { opacity: 0; } }
+
+/* §3 Status line (S5) */
+.dv-statusline { display: flex; align-items: center; gap: 8px 10px; flex-wrap: wrap; min-height: 40px; padding: 8px 24px; border-bottom: 1px solid var(--kw-hairline);
+ background: color-mix(in srgb, var(--kw-surface-side) 70%, transparent); font-size: 12.5px; line-height: 18px; color: var(--t3); }
+.dv-statusline .txt { flex: 1 1 260px; min-width: 0; display: flex; align-items: center; gap: 8px; }
+.dv-statusline .txt > span { min-width: 0; }
+.dv-statusline b { color: var(--t1); font-weight: 600; }
+.dv-statusline .act { display: inline-flex; align-items: center; gap: 4px; min-height: 28px; padding: 0 8px; border-radius: 7px; color: var(--accent); font-weight: 500; border: 1px solid var(--kw-hairline-strong); background: transparent; font-size: 12px; cursor: pointer; }
+.dv-statusline .checked { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--t5); font-variant-numeric: tabular-nums; }
+
+/* §4 git rail: a line down the left of What landed, one node per card */
+.dv-rail { position: relative; padding-left: 30px; }
+.dv-rail::before { content: ''; position: absolute; left: 11px; top: 4px; bottom: 4px; width: 2px; border-radius: 1px; background: var(--dv-rail); }
+.dv-node { position: absolute; left: -25px; top: 22px; width: 12px; height: 12px; border-radius: 50%; background: var(--kw-surface-main); box-shadow: inset 0 0 0 2px var(--c); --c: var(--dv-led-off); }
+.dv-node[data-s="ok"] { --c: var(--dv-led-ok); background: var(--c); box-shadow: 0 0 0 3px var(--kw-surface-main); }
+.dv-node[data-s="bad"] { --c: var(--dv-led-bad); background: var(--c); box-shadow: 0 0 0 3px var(--kw-surface-main); }
+.dv-node[data-s="bad"]::after { content: ''; position: absolute; inset: 3px; background: var(--kw-surface-main); clip-path: polygon(20% 0,50% 30%,80% 0,100% 20%,70% 50%,100% 80%,80% 100%,50% 70%,20% 100%,0 80%,30% 50%,0 20%); }
+.dv-node[data-s="run"] { --c: var(--dv-led-run); }
+.dv-node[data-s="run"]::before { content: ''; position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--c); animation: dv-ping 1.2s var(--kw-ease) infinite; }
+/* merge arc: the PR's branch joining the line. Direct pushes have no arc. */
+.dv-arc { position: absolute; left: -19px; top: 6px; width: 14px; height: 20px; border: 2px solid var(--dv-rail); border-left: 0; border-bottom: 0; border-top-right-radius: 12px; }
+.dv-arc::after { content: ''; position: absolute; right: -5px; top: -5px; width: 8px; height: 8px; border-radius: 50%; background: var(--kw-surface-main); box-shadow: inset 0 0 0 2px var(--dv-rail); }
+
+/* §5 LGTM stamp: ink, not foil. Teal, double rule, -6deg, one 180 ms stamp-in. Not a sticker. */
+.dv-stamp { display: inline-flex; flex-direction: column; align-items: center; padding: 3px 9px 2px; border: 2px solid var(--dv-stamp); border-radius: 7px; color: var(--dv-stamp);
+ transform: rotate(-6deg); outline: 1px solid var(--dv-stamp); outline-offset: -5px; line-height: 1; user-select: none;
+ -webkit-mask-image: radial-gradient(circle at 30% 40%, #000 0 58%, rgb(0 0 0 / .82) 59% 61%, #000 62%), repeating-linear-gradient(115deg, #000 0 3px, rgb(0 0 0 / .86) 3px 4px);
+ -webkit-mask-composite: source-in; mask-composite: intersect;
+ animation: dv-stamp 180ms var(--kw-ease) 1 both; }
+.dv-stamp b { font: 800 13px/1 'JetBrains Mono', monospace; letter-spacing: .14em; padding: 3px 0 1px; }
+.dv-stamp small { font: 600 8.5px/1 'JetBrains Mono', monospace; letter-spacing: .06em; text-transform: uppercase; padding-bottom: 2px; opacity: .9; }
+@keyframes dv-stamp { from { transform: rotate(-6deg) scale(1.3); opacity: 0; } to { transform: rotate(-6deg) scale(1); opacity: 1; } }
+
+/* §6 terminal empty state */
+.dv-term { border: 1px dashed var(--kw-hairline-strong); border-radius: 12px; padding: 18px 20px 20px; }
+.dv-term pre { margin: 0 0 12px; font: 500 12px/20px 'JetBrains Mono', monospace; color: var(--t4); white-space: pre-wrap; overflow-wrap: anywhere; }
+.dv-term .ps { color: var(--accent); }
+.dv-term .out { color: var(--t3); }
+.dv-term h4 { margin: 0; font-size: 14px; font-weight: 600; color: var(--t1); }
+.dv-term p { margin: 2px 0 0; font-size: 12.5px; color: var(--t4); }
+
+/* §7 production floor edge: 4 px hazard tape across the top of the floor card. Only on the floor. */
+.dv-floor { position: relative; overflow: hidden; border: 1px solid var(--dv-floor-bd); background: var(--dv-floor-bg); border-radius: 10px; }
+.dv-floor::before { content: ''; display: block; height: 4px; background: repeating-linear-gradient(-45deg, var(--dv-hazard) 0 6px, transparent 6px 12px); opacity: .8; }
+.dv-cmd { border: 1px solid var(--kw-hairline); background: var(--dv-code-bg); border-radius: 8px; overflow: hidden; }
+.dv-cmd .bar { display: flex; align-items: center; gap: 6px; padding: 5px 10px; border-bottom: 1px solid var(--kw-hairline); font: 500 11px/1 'JetBrains Mono', monospace; color: var(--t5); }
+.dv-cmd pre { margin: 0; padding: 9px 10px; font: 500 12px/19px 'JetBrains Mono', monospace; color: var(--t1); white-space: pre-wrap; word-break: break-all; }
+.dv-cmd pre .ps { color: var(--accent); user-select: none; }
+
+@media (prefers-reduced-motion: reduce) {
+ .dv-led::after, .dv-led[data-ping]::after, .dv-node::before, .dv-caret, .dv-stamp { animation: none !important; }
+ .dv-led[data-s="run"]::after { opacity: .5; transform: scale(1.6); }
+}
diff --git a/frontend/tests/devCards.test.mjs b/frontend/tests/devCards.test.mjs
index d913a92e..1b319c1d 100644
--- a/frontend/tests/devCards.test.mjs
+++ b/frontend/tests/devCards.test.mjs
@@ -155,7 +155,7 @@ test('B1: a direct commit (pr null) parses and draws as a normal landed card nam
assert.equal(c.verified, false, 'no PR review, so never verified, whatever the server says');
assert.equal(m.showVerified({ ...c, verified: true }), false, 'the sticker rule refuses a pr-less card too');
assert.equal(m.parseLanded({ ...fx.LANDED_DIRECT, headline: null }).headline, 'Commit c0ffee1', 'headline falls back to the commit');
- const out = html(m.LandedCard, { card: c, reviews: [{ ...m.parseReview(fx.REVIEW_289), pr: 0 }], onOpenReview: () => {} });
+ const out = html(m.LandedCard, { card: c, reviews: [{ ...m.parseReview(fx.REVIEW_289), pr: 0 }], onOpenReview: () => {}, forge: 'github' });
assert.match(out, /data-dev-card="landed"/);
assert.match(out, /data-commit="c0ffee1"/);
assert.doesNotMatch(out, /data-pr=/);
@@ -169,6 +169,12 @@ test('B1: a direct commit (pr null) parses and draws as a normal landed card nam
assert.match(out, /Fix typo in README/);
assert.match(out, /What changes for you/);
assert.match(out, /Open on GitHub/, 'GitHub link goes to the commit');
+ assert.match(html(m.LandedCard, { card: c, forge: 'gitlab' }), /Open on GitLab/, 'F7: named from forge');
+ const bare = html(m.LandedCard, { card: c, forge: null });
+ assert.doesNotMatch(bare, /Open on/, 'no forge: no forge name');
+ assert.match(bare, /Open commit/, 'the commit link stays, named plainly');
+ assert.match(html(m.LandedCard, { card: landed(fx.LANDED_289) }), /Open pull request/);
+ assert.match(html(m.LandedList, { cards: [landed(fx.LANDED_289)], reviews: [], now: NOW, forge: 'gitea' }), /Open on Gitea/, 'the list passes forge on');
assert.doesNotMatch(out, />Diff</, 'no second link to the same commit');
assert.doesNotMatch(out, /This card couldn/);
const list = html(m.LandedList, { cards: [landed(fx.LANDED_DIRECT), landed(fx.LANDED_288)], reviews: [], now: NOW });
@@ -515,8 +521,8 @@ test('Fix it sends the finding and offers Undo for 10 s', async () => {
assert.deepEqual(actions, [['f1', 'fix'], ['f1', 'undo_fix']]);
});
-test('the review card: sample chip, tamper, security tiles in 0.7.x, read-only footer', () => {
- const out = html(m.ReviewCard, { card: review(fx.REVIEW_294), onFinding: async () => review(fx.REVIEW_294), sample: true, now: NOW });
+test('the review card: sample chip, tamper, security tiles in 0.7.x, no Post button on the sample', () => {
+ const out = html(m.ReviewCard, { card: review(fx.REVIEW_294), onFinding: async () => review(fx.REVIEW_294), sample: true, forge: 'github', now: NOW });
assert.match(out, /Sample PR/);
assert.match(out, /A test was made easier to pass/);
assert.match(out, /Different engine from the author/);
@@ -524,7 +530,8 @@ test('the review card: sample chip, tamper, security tiles in 0.7.x, read-only f
assert.match(out, /data-sec="Semgrep" data-state="later"/);
assert.equal((out.match(/in 0\.7\.x/g) ?? []).length >= 2, true);
assert.doesNotMatch(out, /Post to GitHub/, 'S2: no button that can never be pressed');
- assert.match(out, /Read only: nothing is posted to GitHub in this version\./);
+ assert.match(out, /Nothing is posted until you press it\./);
+ assert.match(out, /data-post-state="none"/);
assert.match(out, /<footer data-review-footer[^>]*>[\s\S]*Open on GitHub[\s\S]*<\/footer>/);
assert.match(out, /Did less than asked/);
assert.match(out, /Did more than asked/);
@@ -620,7 +627,7 @@ test('B2: a backup started from the secondary Back up first puts focus on the ma
assert.notEqual(secondary, host.querySelector('[data-floor-main]'));
secondary.focus();
await click(secondary);
- assert.equal(button(host, 'Back up first'), undefined, 'the secondary button is gone');
+ assert.equal(!!button(host, 'Back up first'), false, 'the secondary button is gone');
assert.equal(document.activeElement, host.querySelector('[data-floor-main]'), 'focus is on the main button, not <body>');
});
diff --git a/frontend/tests/devMode.test.mjs b/frontend/tests/devMode.test.mjs
index 5c20ccb7..6cbf5e18 100644
--- a/frontend/tests/devMode.test.mjs
+++ b/frontend/tests/devMode.test.mjs
@@ -553,7 +553,7 @@ test('round 2: the setup footer is sticky, says nothing is posted, and its butto
const footer = document.querySelector('[data-dv-setup-footer]');
assert.ok(footer.classList.contains('sticky') && footer.classList.contains('bottom-0'));
assert.ok(footer.classList.contains('pb-[max(16px,env(safe-area-inset-bottom))]'));
- assert.match(footer.textContent, /Only you can turn this on or off\. Nothing is posted to GitHub\./);
+ assert.match(footer.textContent, /Only you can turn this on or off\. Nothing is posted to GitHub unless you press Post\./);
assert.doesNotMatch(document.body.textContent, /without asking/);
for (const btn of footer.querySelectorAll('button')) assert.ok(btn.classList.contains('min-h-[44px]'), btn.textContent);
root.unmount();
diff --git a/frontend/tests/postGithub.test.mjs b/frontend/tests/postGithub.test.mjs
new file mode 100644
index 00000000..d9b73618
--- /dev/null
+++ b/frontend/tests/postGithub.test.mjs
@@ -0,0 +1,428 @@
+// Post to GitHub (0.7.1, Iris): the review card footer in every state of plan/post-to-github.md, the
+// parse of `posted` / `post_error`, the copy changes, and the desk call. Mock data only: nothing posts.
+process.env.TZ = 'UTC';
+
+import assert from 'node:assert/strict';
+import test, { afterEach } from 'node:test';
+import { JSDOM } from 'jsdom';
+import { loadBundled } from './bundle.mjs';
+
+const dom = new JSDOM('<!doctype html><html><body></body></html>', { url: 'http://localhost/', pretendToBeVisual: true });
+const g = globalThis;
+for (const k of ['window', 'document', 'navigator', 'HTMLElement', 'Element', 'Node', 'Event', 'MouseEvent', 'KeyboardEvent', 'requestAnimationFrame', 'cancelAnimationFrame', 'getComputedStyle', 'localStorage', 'sessionStorage']) {
+ if (!(k in dom.window)) continue;
+ Object.defineProperty(g, k, { value: dom.window[k], configurable: true, writable: true });
+}
+g.window.matchMedia ??= () => ({ matches: false, addEventListener() {}, removeEventListener() {} });
+
+const m = await loadBundled(`
+ export * from './src/dev/types';
+ export * from './src/dev/logic';
+ export * as fx from './src/dev/fixtures';
+ export { LandedCard, LandedList } from './src/components/dev/LandedCard';
+ export { Rollup, rollupTitle, rollupTiles } from './src/components/dev/Rollup';
+ export { ReviewCard } from './src/components/dev/ReviewCard';
+ export { ReleaseNotesSheet } from './src/components/dev/ReleaseNotesSheet';
+ export { ProdFloorCard } from './src/components/dev/ProdFloorCard';
+ export { ModernApprovalCard } from './src/components/ModernApprovalCard';
+ export { renderToStaticMarkup } from 'react-dom/server.browser';
+ export { createRoot } from 'react-dom/client';
+ export { createElement } from 'react';
+`);
+const { fx } = m;
+const h = m.createElement;
+const html = (C, props) => m.renderToStaticMarkup(h(C, props));
+const NOW = fx.FIXTURE_NOW;
+
+const landed = (raw, over = {}) => ({ ...m.parseLanded(raw), ...over });
+const review = (raw, over = {}) => ({ ...m.parseReview(raw), ...over });
+
+// ---------------------------------------------------------------------------------------------------
+// DOM helpers
+
+const mounted = new Set();
+afterEach(() => {
+ for (const u of mounted) u();
+ document.body.replaceChildren();
+});
+const settle = async () => {
+ for (let i = 0; i < 20; i++) await new Promise((r) => setTimeout(r, 0));
+};
+const mount = async (C, props) => {
+ const host = document.createElement('div');
+ document.body.appendChild(host);
+ const root = m.createRoot(host);
+ root.render(h(C, props));
+ await settle();
+ const u = () => {
+ if (!mounted.delete(u)) return;
+ root.unmount();
+ host.remove();
+ };
+ mounted.add(u);
+ return host;
+};
+const button = (host, text) => [...host.querySelectorAll('button')].find((b) => b.textContent.replace(/\s+/g, ' ').trim().startsWith(text));
+const click = async (el) => {
+ el.dispatchEvent(new window.MouseEvent('click', { bubbles: true }));
+ await settle();
+};
+
+const base = () => review(fx.REVIEW_294);
+const LOGIN = 'oleks-i';
+const footer = (host) => host.querySelector('[data-review-footer]');
+const flat = (el) => el.textContent.replace(/\s+/g, ' ').trim();
+const POSTED = { forge: 'github', at: '2026-11-05T19:58:00Z', login: LOGIN, url: 'https://github.com/o/r/pull/294#pullrequestreview-1', comments: 3 };
+
+// ---------------------------------------------------------------------------------------------------
+// Parse
+
+test('parseReview keeps posted and post_error, https links only, unknown kinds as failed', () => {
+ const c = m.parseReview({ ...fx.REVIEW_294, posted: POSTED, post_error: null });
+ assert.deepEqual(c.posted, POSTED);
+ assert.equal(c.post_error, null);
+ assert.equal(m.parseReview(fx.REVIEW_294).posted, null, 'a 0.7.0 card without the field');
+ assert.equal(m.parseReview({ ...fx.REVIEW_294, posted: { ...POSTED, url: 'javascript:alert(1)' } }).posted.url, null);
+ assert.equal(m.parseReview({ ...fx.REVIEW_294, posted: { ...POSTED, url: 'http://github.com/x' } }).posted.url, null);
+ assert.deepEqual(m.parseReview({ ...fx.REVIEW_294, post_error: { kind: 'read_only', message: 'Resource not accessible' } }).post_error, { kind: 'read_only', message: 'Resource not accessible' });
+ assert.equal(m.parseReview({ ...fx.REVIEW_294, post_error: { kind: 'weird' } }).post_error.kind, 'failed');
+ assert.equal(m.parseReview({ ...fx.REVIEW_294, post_error: 'nope' }).post_error, null);
+});
+
+test('the dev_mode parse reads forge and forge_login; unknown forge and a stray github_login are ignored', () => {
+ // devMode.ts is bundled separately: it imports auth.
+ return loadBundled(`export { parseDevMode, emptyState } from './src/devMode';`).then(({ parseDevMode, emptyState }) => {
+ const d = parseDevMode({ on: true, forge: 'github', forge_login: 'octocat' });
+ assert.equal(d.forge, 'github');
+ assert.equal(d.forge_login, 'octocat');
+ assert.equal(parseDevMode({ on: true, forge: 'gitlab' }).forge, 'gitlab');
+ assert.equal(parseDevMode({ on: true, forge: 'gitea' }).forge, 'gitea');
+ assert.equal(parseDevMode({ on: true, forge: 'bitbucket' }).forge, null);
+ assert.equal(parseDevMode({ on: true }).forge, null);
+ assert.equal(parseDevMode({ on: true }).forge_login, null);
+ assert.equal(parseDevMode({ on: true, forge_login: '' }).forge_login, null);
+ const old = parseDevMode({ on: true, github_login: 'octocat' });
+ assert.equal(old.forge_login, null, 'github_login is gone from the contract');
+ assert.ok(!('github_login' in old));
+ assert.equal(emptyState().forge, null);
+ assert.equal(emptyState().forge_login, null);
+ });
+});
+
+// ---------------------------------------------------------------------------------------------------
+// The rules
+
+test('N counts every finding not dismissed; the label pluralises and drops a zero count', () => {
+ assert.equal(m.postCount([{ state: 'open' }, { state: 'sent' }, { state: 'dismissed' }]), 2);
+ assert.equal(m.postLabel(3, 'github'), 'Post to GitHub · 3 findings');
+ assert.equal(m.postLabel(1, 'github'), 'Post to GitHub · 1 finding');
+ assert.equal(m.postLabel(0, 'github'), 'Post to GitHub');
+ assert.equal(m.postLine('octocat'), 'Nothing is posted until you press it. Posts as @octocat.');
+ assert.equal(m.postLine(null), 'Nothing is posted until you press it.');
+});
+
+test('postState: posted wins, then posting, then the error; pending and the sample have no button', () => {
+ const c = (o = {}) => ({ status: 'ready', posted: null, post_error: null, ...o });
+ const on = { canPost: true, posting: false, forge: 'github' };
+ assert.equal(m.postState(c(), on).kind, 'ready');
+ assert.equal(m.postState(c(), { canPost: true, posting: true, forge: 'github' }).kind, 'posting');
+ assert.equal(m.postState(c({ posted: POSTED, post_error: { kind: 'failed', message: 'x' } }), { canPost: true, posting: true, forge: 'github' }).kind, 'posted');
+ assert.equal(m.postState(c({ posted: POSTED }), { canPost: false, posting: false, forge: 'github' }).kind, 'posted', 'a posted card says so even without the call');
+ assert.equal(m.postState(c({ post_error: { kind: 'read_only', message: null } }), on).kind, 'read_only');
+ assert.equal(m.postState(c({ post_error: { kind: 'stale', message: null } }), on).kind, 'stale');
+ assert.deepEqual(m.postState(c({ post_error: { kind: 'failed', message: 'GitHub said 502' } }), on), { kind: 'failed', message: 'GitHub said 502', retry: true });
+ assert.deepEqual(m.postState(c({ post_error: { kind: 'failed', message: 'no review' } }), { ...on, noReview: true }), { kind: 'failed', message: 'no review', retry: false }, 'F4: a 409 is final');
+ assert.equal(m.postState(c({ status: 'failed' }), on).kind, 'no_review', 'F4: a review that failed to generate has nothing to post');
+ assert.equal(m.postState(c({ status: 'failed', posted: POSTED }), on).kind, 'posted');
+ assert.equal(m.postState(c({ status: 'pending' }), on).kind, 'none');
+ assert.equal(m.postState(c(), { canPost: false, posting: false, forge: 'github' }).kind, 'none');
+});
+
+// ---------------------------------------------------------------------------------------------------
+// Every footer state, rendered
+
+test('ready: the line with @login in mono, primary Post to GitHub · N comments, Open on GitHub', async () => {
+ const card = { ...base(), findings: [...base().findings, { ...base().findings[0], id: 'f9', state: 'dismissed' }] };
+ const host = await mount(m.ReviewCard, { card, onFinding: async () => card, onPost: async () => card, forge: 'github', forgeLogin: LOGIN, now: NOW });
+ const f = footer(host);
+ assert.equal(f.dataset.postState, 'ready');
+ assert.match(flat(f), /Nothing is posted until you press it\. Posts as @oleks-i\./);
+ assert.match(f.innerHTML, /<span class="font-mono text-zinc-100">@oleks-i<\/span>/, 'login in mono');
+ assert.equal(!!f.querySelector('svg.lucide-lock'), false, 'v2: no lock icon');
+ const b = button(f, 'Post to GitHub');
+ assert.equal(flat(b), 'Post to GitHub · 3 findings', 'the dismissed fourth finding is not counted');
+ assert.equal(b.disabled, false);
+ assert.match(b.className, /kw-btn-primary/, 'the primary button');
+ assert.match(f.innerHTML, /Open on GitHub/);
+ assert.ok(/min-h-\[44px\]/.test(b.className) && /w-full/.test(b.className) && /sm:w-auto/.test(b.className), 'phone: full-width 44 px target under the text');
+});
+
+test('ready without a login: no "Posts as"', async () => {
+ const host = await mount(m.ReviewCard, { card: base(), onFinding: async () => base(), onPost: async () => base(), forge: 'github', forgeLogin: null, now: NOW });
+ assert.match(flat(footer(host)), /Nothing is posted until you press it\./);
+ assert.doesNotMatch(flat(footer(host)), /Posts as/);
+});
+
+test('posting: spinner, button disabled and busy, a second press sends nothing; then posted from the reply', async () => {
+ let release;
+ const calls = [];
+ const onPost = (id) => {
+ calls.push(id);
+ return new Promise((r) => (release = () => r({ ...base(), posted: POSTED })));
+ };
+ const host = await mount(m.ReviewCard, { card: base(), onFinding: async () => base(), onPost, forge: 'github', forgeLogin: LOGIN, now: NOW });
+ await click(button(footer(host), 'Post to GitHub'));
+ let f = footer(host);
+ assert.equal(f.dataset.postState, 'posting');
+ const b = f.querySelector('[data-post-button]');
+ assert.equal(flat(b), 'Posting…');
+ assert.equal(b.disabled, true);
+ assert.equal(b.getAttribute('aria-busy'), 'true');
+ assert.ok(b.querySelector('svg.lucide-loader-circle, svg.lucide-loader2, svg.lucide-loader'), 'spinner');
+ assert.match(b.querySelector('svg').getAttribute('class'), /motion-safe:animate-spin/, 'static under reduced motion');
+ await click(b);
+ assert.deepEqual(calls, ['dvr_294'], 'one request only');
+ release();
+ await settle();
+ f = footer(host);
+ assert.equal(f.dataset.postState, 'posted');
+ assert.match(flat(f), /^Posted 19:58 as @oleks-i · 3 inline comments\s*View on GitHub/);
+ assert.equal(f.querySelector('.dv-led').dataset.s, 'ok', 'ok LED');
+ const a = f.querySelector('a[href="https://github.com/o/r/pull/294#pullrequestreview-1"]');
+ assert.ok(a, 'View on GitHub links to the review');
+ assert.equal(a.getAttribute('target'), '_blank');
+ assert.equal(!!button(f, 'Post to GitHub'), false, 'no button once posted');
+ assert.equal(f.querySelector('[role="status"]').textContent, 'Posted 19:58 as @oleks-i · 3 inline comments');
+});
+
+test('posted from the server (SSE refetch): the card prop alone switches the footer', async () => {
+ const host = document.createElement('div');
+ document.body.appendChild(host);
+ const root = m.createRoot(host);
+ const props = { onFinding: async () => base(), onPost: async () => base(), forge: 'github', forgeLogin: LOGIN, now: NOW };
+ root.render(h(m.ReviewCard, { ...props, card: base() }));
+ await settle();
+ assert.equal(footer(host).dataset.postState, 'ready');
+ root.render(h(m.ReviewCard, { ...props, card: { ...base(), posted: POSTED } }));
+ await settle();
+ assert.equal(footer(host).dataset.postState, 'posted');
+ root.unmount();
+});
+
+test('posted without a url: "Posted 19:58" and no link', () => {
+ const out = html(m.ReviewCard, { card: { ...base(), posted: { ...POSTED, url: null } }, onFinding: async () => base(), onPost: async () => base(), now: NOW });
+ assert.match(out, /Posted 19:58/);
+ assert.doesNotMatch(out, /View on GitHub/);
+});
+
+test('read_only (F1): warn LED line naming the scope, and Try again, which reaches the server once the token is fixed', async () => {
+ const calls = [];
+ const card = { ...base(), post_error: { kind: 'read_only', message: 'Resource not accessible by personal access token' } };
+ const onPost = async (id) => (calls.push(id), { ...base(), posted: POSTED, post_error: null });
+ const host = await mount(m.ReviewCard, { card, onFinding: async () => card, onPost, forge: 'github', forgeLogin: LOGIN, now: NOW });
+ let f = footer(host);
+ assert.equal(f.dataset.postState, 'read_only');
+ const b = button(f, 'Try again');
+ assert.ok(b, 'Try again');
+ assert.equal(b.getAttribute('aria-disabled'), null, 'not sticky: the press is live');
+ assert.equal(!!f.querySelector('[data-post-disabled]'), false);
+ const why = f.querySelector(`#${b.getAttribute('aria-describedby').replace(/([:.])/g, '\\$1')}`);
+ assert.equal(flat(why), m.readOnlyLine('github'), 'screen readers hear why');
+ assert.equal(flat(why), 'Your GitHub connection is read only. Give the token pull_requests: write to post.');
+ assert.match(why.innerHTML, /<code class="dv-code">pull_requests: write<\/code>/);
+ assert.equal(f.querySelector('.dv-led').dataset.s, 'warn');
+ await click(b);
+ assert.deepEqual(calls, ['dvr_294'], 'the press reaches the API');
+ f = footer(host);
+ assert.equal(f.dataset.postState, 'posted');
+});
+
+test('read_only that is still read only: the press comes back read_only, the line stays', async () => {
+ const card = { ...base(), post_error: { kind: 'read_only', message: null } };
+ const host = await mount(m.ReviewCard, { card, onFinding: async () => card, onPost: async () => card, forge: 'github', forgeLogin: LOGIN, now: NOW });
+ await click(button(footer(host), 'Try again'));
+ assert.equal(footer(host).dataset.postState, 'read_only');
+ assert.match(flat(footer(host)), /Your GitHub connection is read only/);
+});
+
+test('F4: a review that failed to generate has no Post footer, only its link', async () => {
+ const card = { ...base(), status: 'failed', error: 'Ann couldn’t write the card’s text.' };
+ const host = await mount(m.ReviewCard, { card, onFinding: async () => card, onPost: async () => card, forge: 'github', forgeLogin: LOGIN, now: NOW });
+ const f = footer(host);
+ assert.equal(f.dataset.postState, 'no_review');
+ assert.equal(!!host.querySelector('[data-post-button], [data-post-disabled], [data-post-retry]'), false, 'no Post, no Try again');
+ assert.doesNotMatch(flat(f), /Nothing is posted|Posts as|Post to/);
+ assert.match(flat(f), /^Open on GitHub/);
+ const bare = await mount(m.ReviewCard, { card: { ...card, links: { ...card.links, pr: null } }, onFinding: async () => card, onPost: async () => card, forge: 'github', now: NOW });
+ assert.equal(footer(bare), null, 'no link either: no footer at all');
+});
+
+test('F4: a 409 from kwant is "Couldn’t post" with no Try again', async () => {
+ const calls = [];
+ const err = Object.assign(new Error('This card has no review to post.'), { status: 409 });
+ const host = await mount(m.ReviewCard, {
+ card: base(),
+ onFinding: async () => base(),
+ onPost: async (id) => {
+ calls.push(id);
+ throw err;
+ },
+ forge: 'github', forgeLogin: LOGIN, now: NOW,
+ });
+ await click(button(footer(host), 'Post to GitHub'));
+ const f = footer(host);
+ assert.equal(f.dataset.postState, 'failed');
+ assert.match(flat(f), /Couldn’t post: This card has no review to post\./);
+ assert.equal(!!button(f, 'Try again'), false);
+ assert.equal(!!button(f, 'Post to GitHub'), false);
+ assert.deepEqual(calls, ['dvr_294']);
+});
+
+test('stale: run LED line and a disabled button', async () => {
+ const card = { ...base(), post_error: { kind: 'stale', message: 'head moved' } };
+ const host = await mount(m.ReviewCard, { card, onFinding: async () => card, onPost: async () => card, forge: 'github', forgeLogin: LOGIN, now: NOW });
+ const f = footer(host);
+ assert.equal(f.dataset.postState, 'stale');
+ assert.match(flat(f), /This PR has new commits\. A new review is on its way\./);
+ const b = button(f, 'Post to GitHub');
+ assert.equal(b.getAttribute('aria-disabled'), 'true');
+ assert.equal(f.querySelector('.dv-led').dataset.s, 'run');
+ assert.equal(!!button(f, 'Try again'), false);
+});
+
+test('failed: "Couldn’t post: {message}" and Try again, which posts again and clears the error', async () => {
+ const calls = [];
+ const card = { ...base(), post_error: { kind: 'failed', message: 'GitHub answered 502' } };
+ const onPost = async (id) => (calls.push(id), { ...base(), posted: POSTED, post_error: null });
+ const host = await mount(m.ReviewCard, { card, onFinding: async () => card, onPost, forge: 'github', forgeLogin: LOGIN, now: NOW });
+ let f = footer(host);
+ assert.equal(f.dataset.postState, 'failed');
+ assert.match(flat(f), /Couldn’t post: GitHub answered 502/);
+ assert.equal(f.querySelector('.dv-led').dataset.s, 'bad');
+ assert.match(button(f, 'Try again').className, /kw-btn-ghost/);
+ assert.equal(!!button(f, 'Post to GitHub'), false);
+ await click(button(f, 'Try again'));
+ assert.deepEqual(calls, ['dvr_294']);
+ f = footer(host);
+ assert.equal(f.dataset.postState, 'posted');
+});
+
+test('failed from the network: a throw becomes "Couldn’t post: {message}"', async () => {
+ const host = await mount(m.ReviewCard, {
+ card: base(),
+ onFinding: async () => base(),
+ onPost: async () => {
+ throw new Error('kwant is not reachable');
+ },
+ forge: 'github', forgeLogin: LOGIN,
+ now: NOW,
+ });
+ await click(button(footer(host), 'Post to GitHub'));
+ const f = footer(host);
+ assert.equal(f.dataset.postState, 'failed');
+ assert.match(flat(f), /Couldn’t post: kwant is not reachable/);
+ assert.ok(button(f, 'Try again'));
+});
+
+test('a message is text, never HTML', () => {
+ const out = html(m.ReviewCard, { card: { ...base(), post_error: { kind: 'failed', message: '<img src=x onerror=alert(1)>' } }, onFinding: async () => base(), onPost: async () => base(), forge: 'github', now: NOW });
+ assert.doesNotMatch(out, /<img/);
+ assert.match(out, /&lt;img/);
+});
+
+test('pending card: no Post button yet', () => {
+ const out = html(m.ReviewCard, { card: { ...base(), status: 'pending' }, onFinding: async () => base(), onPost: async () => base(), forge: 'github', forgeLogin: LOGIN, now: NOW });
+ assert.match(out, /data-post-state="none"/);
+ assert.doesNotMatch(out, /Post to GitHub/);
+});
+
+// ---------------------------------------------------------------------------------------------------
+// Copy changes and the desk wiring (source checks: these files need the whole app to mount)
+
+import { readFileSync } from 'node:fs';
+const src = (p) => readFileSync(new URL(`../${p}`, import.meta.url), 'utf8');
+
+test('copy: Dev mode setup, Loose ends label and the token error say what posting needs', async () => {
+ assert.match(src('src/components/DevModeSetup.tsx'), /Only you can turn this on or off\. Nothing is posted to GitHub unless you press Post\./);
+ const le = 'Read-only access to issues and pull requests is enough. To post reviews from Dev mode, give it Pull requests: Read and write.';
+ assert.ok(src('src/components/LooseEndsView.tsx').includes(le));
+ const { githubSource } = await loadBundled(`export { githubSource } from './src/looseEnds';`);
+ assert.equal(githubSource('', '', '').error, `Enter a GitHub token. ${le}`);
+ assert.doesNotMatch(src('src/components/dev/ReviewCard.tsx'), /nothing is posted to GitHub in this version/);
+});
+
+test('the desk posts to /api/dev/cards/:id/post and passes forge and forge_login', () => {
+ assert.match(src('src/devMode.ts'), /post: \(card: string\) => call<unknown>\(`\/api\/dev\/cards\/\$\{enc\(card\)\}\/post`, 'POST'/);
+ const desk = src('src/components/DevDesk.tsx');
+ assert.match(desk, /devApi\.post\(cardId\)/);
+ assert.match(desk, /onPost=\{onPost\} forge=\{dev\?\.forge \?\? null\} forgeLogin=\{dev\?\.forge_login \?\? null\}/);
+});
+
+// ---------------------------------------------------------------------------------------------------
+// Any forge (amendment, 21:50): the contract names the forge; posting is GitHub-only in 0.7.1
+
+test('F7: forge null shows neither the Post button nor the Open link, in every state that would have one', async () => {
+ for (const over of [{}, { post_error: { kind: 'read_only', message: null } }, { post_error: { kind: 'failed', message: 'x' } }]) {
+ const card = { ...base(), ...over };
+ const host = await mount(m.ReviewCard, { card, onFinding: async () => card, onPost: async () => card, forge: null, forgeLogin: LOGIN, now: NOW });
+ assert.equal(!!host.querySelector('[data-post-button], [data-post-disabled], [data-forge-link]'), false, 'no Post button, no link');
+ assert.equal(!!button(host, 'Post to'), false);
+ assert.equal(!!button(host, 'Try again'), false);
+ assert.equal(!!host.querySelector('a[href="' + card.links.pr + '"]'), false, 'the PR link is not drawn anywhere on the card');
+ assert.doesNotMatch(host.textContent, /Nothing is posted|Posts as|Open on|Open pull request|GitHub/, 'no lock line, no forge wording');
+ assert.equal(!!host.querySelector('[data-review-footer]'), false, 'nothing to show: no empty footer rule');
+ }
+ // Leaving forge out is the same as null.
+ const out = html(m.ReviewCard, { card: base(), onFinding: async () => base(), onPost: async () => base(), now: NOW });
+ assert.doesNotMatch(out, /data-review-footer|Post to|Nothing is posted|Open on/);
+ assert.equal(m.postState({ status: 'ready', posted: null, post_error: null }, { canPost: true, posting: false, forge: null }).kind, 'none');
+});
+
+test('forge null but already posted: still says Posted, with the forge from posted', () => {
+ const out = html(m.ReviewCard, { card: { ...base(), posted: POSTED }, onFinding: async () => base(), now: NOW });
+ assert.match(out, /Posted 19:58/);
+ assert.match(out, /View on GitHub/);
+});
+
+test('the label, tooltip and links come from a map on forge (GitLab, Gitea)', async () => {
+ assert.equal(m.FORGE_NAME.github, 'GitHub');
+ assert.equal(m.postLabel(2, 'gitlab'), 'Post to GitLab · 2 findings');
+ assert.equal(m.postLabel(0, 'gitea'), 'Post to Gitea');
+ assert.equal(m.readOnlyTip('github'), 'Your GitHub connection is read only');
+ assert.equal(m.readOnlyTip('gitlab'), 'Your GitLab connection is read only');
+ assert.equal(m.readOnlyLine('gitea'), 'Your Gitea connection is read only. Give the token write access to post.', 'GitHub scope words only for github');
+ const card = { ...base(), post_error: { kind: 'read_only', message: null } };
+ const host = await mount(m.ReviewCard, { card, onFinding: async () => card, onPost: async () => card, forge: 'gitlab', forgeLogin: LOGIN, now: NOW });
+ const f = footer(host);
+ assert.ok(button(f, 'Try again'), 'read only: Try again (F1)');
+ assert.match(flat(f), /Your GitLab connection is read only/);
+ assert.match(f.innerHTML, /Open on GitLab/);
+ assert.doesNotMatch(flat(f), /GitHub/);
+});
+
+test('F7: the footer reads Post to {Forge} first, then the link Open on {Forge}', async () => {
+ for (const [forge, name] of [['github', 'GitHub'], ['gitlab', 'GitLab'], ['gitea', 'Gitea']]) {
+ for (const over of [{}]) {
+ const card = { ...base(), ...over };
+ const host = await mount(m.ReviewCard, { card, onFinding: async () => card, onPost: async () => card, forge, forgeLogin: LOGIN, now: NOW });
+ const f = footer(host);
+ const b = button(f, `Post to ${name}`);
+ const a = f.querySelector('[data-forge-link] a');
+ assert.ok(b, `Post to ${name}`);
+ assert.ok(a, 'Open link');
+ assert.equal(a.getAttribute('href'), card.links.pr);
+ assert.match(flat(a), new RegExp(`^Open on ${name}`));
+ assert.ok(b.compareDocumentPosition(a) & 4, 'Post comes before Open, in DOM (and so Tab) order');
+ }
+ }
+ assert.equal(m.forgeOpen('gitea'), 'Open on Gitea');
+ assert.equal(m.forgeOpen(null, 'commit'), 'Open commit');
+});
+
+test('no github_login or githubLogin is left in the frontend source', async () => {
+ const { readdirSync, statSync } = await import('node:fs');
+ const walk = (d) => readdirSync(d).flatMap((n) => (statSync(`${d}/${n}`).isDirectory() ? walk(`${d}/${n}`) : [`${d}/${n}`]));
+ const root = new URL('../src', import.meta.url).pathname;
+ const hits = walk(root).filter((f) => /\.(ts|tsx)$/.test(f) && /github_login|githubLogin/.test(readFileSync(f, 'utf8')));
+ assert.deepEqual(hits, []);
+});
diff --git a/frontend/tests/styleV2Parts.test.mjs b/frontend/tests/styleV2Parts.test.mjs
new file mode 100644
index 00000000..0dfd766e
--- /dev/null
+++ b/frontend/tests/styleV2Parts.test.mjs
@@ -0,0 +1,49 @@
+// Dev mode style v2 (Mira, style-v2.md §2): the shared parts every Dev card uses (LED, diffstat, sha chip)
+// and the shared .dv-* block in modern.css. Demo data only.
+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/logic';
+ export { Led, DiffStat, Sha } from './src/components/dev/parts';
+ export { renderToStaticMarkup } from 'react-dom/server.browser';
+ export { createElement } from 'react';
+`);
+const html = (C, props) => m.renderToStaticMarkup(m.createElement(C, props));
+
+test('diffBar: 31 px split by share, 3 px floor either side, whole bar when one side is zero', () => {
+ assert.deepEqual(m.diffBar(157, 15), { add: 28, del: 3 });
+ assert.deepEqual(m.diffBar(10, 10), { add: 16, del: 15 });
+ assert.deepEqual(m.diffBar(1, 500), { add: 3, del: 28 }, 'a > 0 keeps 3 px');
+ assert.deepEqual(m.diffBar(52, 0), { add: 32, del: 0 });
+ assert.deepEqual(m.diffBar(0, 4), { add: 0, del: 32 });
+ assert.deepEqual(m.diffBar(0, 0), { add: 0, del: 0 });
+ for (const [a, d] of [[3, 7], [64, 12], [1, 1], [999, 1]]) {
+ const b = m.diffBar(a, d);
+ assert.equal(b.add + b.del, 31, `${a}/${d}: 31 px plus the 1 px gap`);
+ }
+});
+
+test('DiffStat: mono numbers with U+2212, the bar, and one label for screen readers', () => {
+ const out = html(m.DiffStat, { add: 157, del: 15 });
+ assert.match(out, /^<span role="img" aria-label="157 lines added, 15 removed"/);
+ assert.match(out, /<span class="a">\+157<\/span> <span class="d">−15<\/span>/);
+ assert.match(out, /<span aria-hidden="true" class="dv-bar"><i class="a" style="width:28px"><\/i><i class="d" style="width:3px"><\/i><\/span>/);
+ assert.equal(m.diffLabel(1, 0), '1 line added, 0 removed');
+});
+
+test('Led is decoration with a state; Sha is 7 chars and says Commit to screen readers', () => {
+ assert.equal(html(m.Led, { s: 'run' }), '<span aria-hidden="true" data-s="run" class="dv-led"></span>');
+ assert.equal(html(m.Sha, { sha: '9f3c2a1e44b0' }), '<span data-sha="true" class="dv-sha"><span class="sr-only">Commit </span>9f3c2a1</span>');
+});
+
+test('the shared .dv-* block is in modern.css: tokens, LED, stat, sha, rail, stamp, and a reduced-motion rule', () => {
+ const css = readFileSync(new URL('../src/styles/modern.css', import.meta.url), 'utf8');
+ for (const sel of ['--dv-code-bg', '--dv-led-run', '--dv-rail', '--dv-stamp', '.dv-led[data-s="run"]::after', '.dv-stat', '.dv-bar', '.dv-sha', '.dv-branch', '.dv-node[data-s="bad"]::after', '.dv-arc', '.dv-stamp', '@keyframes dv-ping']) {
+ assert.ok(css.includes(sel), sel);
+ }
+ const rm = css.slice(css.lastIndexOf('@media (prefers-reduced-motion: reduce)'));
+ assert.match(rm, /\.dv-led::after, \.dv-led\[data-ping\]::after, \.dv-node::before, \.dv-caret, \.dv-stamp \{ animation: none !important; \}/);
+});