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 desk: every team's repo (0.7.2) (#356)

Oleksandr Ivanchenkob81d1ee5b697
diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx
index 000b6a89..8dfdc01c 100644
--- a/frontend/src/App.tsx
+++ b/frontend/src/App.tsx
@@ -3494,7 +3494,7 @@ export const SpaceApp: React.FC<SpaceAppProps> = ({
}}
/>
);
- const devDeskPage = <DevDeskView key={space.id} spaceId={space.id} spaceName={space.name} onBack={backToList} onOpenLooseEnds={connectDevGitHub} />;
+ const devDeskPage = <DevDeskView key={space.id} spaceId={space.id} spaceName={space.name} onBack={backToList} onOpenLooseEnds={connectDevGitHub} teams={teams.map((t) => ({ id: t.id, name: t.name }))} />;
const mainPane = needsSetup ? setupChecklist : page === 'parallel' ? parallel : page === 'board' && missionBoard ? missionsPage : page === 'dev' && devOn ? devDeskPage : page === 'jar' ? jarPage : page === 'inbox' ? inbox : !loaded ? (
<main className="flex-1 flex items-center justify-center text-xs text-zinc-500">
<Loader2 size={14} className="mr-2 animate-spin motion-reduce:animate-none" aria-hidden="true" /> Opening {space.name}…
diff --git a/frontend/src/components/DevDesk.tsx b/frontend/src/components/DevDesk.tsx
index e2c537f1..e5588116 100644
--- a/frontend/src/components/DevDesk.tsx
+++ b/frontend/src/components/DevDesk.tsx
@@ -4,7 +4,7 @@
import React, { useCallback, useEffect, useId, useRef, useState, useSyncExternalStore } from 'react';
import { ChevronLeft, Code, RefreshCw } from 'lucide-react';
-import { DevModeState, devApi, devStore, deskStatus, firstRun, statusLine } from '../devMode';
+import { DEV_OFF, DevModeState, checkedLabel, DevTeamRef, cardRepoLabel, cardsOfRepo, devApi, devStore, deskStatus, firstRun, repoFilters, reposSummary, statusLine } from '../devMode';
import { FindingAction, LandedPage, ShellCard, asCard, parseCards, parseLandedPage } from '../dev/shellTypes';
import { LandedList, ReleaseNotesSheet, ReviewCard, Rollup } from './DevDeskSlots';
import { useDevMode } from './DevModeSwitch';
@@ -35,6 +35,8 @@ export interface DeskData {
const EMPTY: DeskData = { landed: null, reviews: null, loading: false, error: null, checkedAt: null };
const desks = new Map<string, DeskData>();
+/** The cache key: the space, or the space and one repo (0.7.2 `?repo=`). The row reads the space's. */
+const deskKey = (space: string, repo: string | null = null) => (repo ? `${space}\u0000${repo}` : space);
const deskListeners = new Set<() => void>();
const inflight = new Map<string, Promise<void>>();
@@ -44,49 +46,58 @@ function setDesk(space: string, patch: Partial<DeskData>) {
}
export const deskStore = {
- get: (space: string): DeskData => desks.get(space) ?? EMPTY,
+ get: (space: string, repo: string | null = null): DeskData => desks.get(deskKey(space, repo)) ?? EMPTY,
subscribe(l: () => void) {
deskListeners.add(l);
return () => void deskListeners.delete(l);
},
- /** Loads both lists; concurrent calls share one request. */
- load(space: string): Promise<void> {
- const running = inflight.get(space);
+ /** Loads both lists, of the whole space or of one repo; concurrent calls share one request. */
+ load(space: string, repo: string | null = null): Promise<void> {
+ const key = deskKey(space, repo);
+ const running = inflight.get(key);
if (running) return running;
- setDesk(space, { loading: true });
- const p = Promise.all([devApi.landed(space), devApi.reviews(space)])
- .then(([l, r]) => setDesk(space, { landed: parseLandedPage(l), reviews: parseCards(r), loading: false, error: null, checkedAt: Date.now() }))
- .catch((e: unknown) => setDesk(space, { loading: false, error: e instanceof Error ? e.message : 'The Dev desk couldn’t load.' }))
- .finally(() => inflight.delete(space));
- inflight.set(space, p);
+ setDesk(key, { loading: true });
+ const p = Promise.all([devApi.landed(space, undefined, repo), devApi.reviews(space, repo)])
+ .then(([l, r]) => {
+ const page = parseLandedPage(l);
+ setDesk(key, { landed: { ...page, cards: cardsOfRepo(page.cards, repo) }, reviews: cardsOfRepo(parseCards(r), repo), loading: false, error: null, checkedAt: Date.now() });
+ })
+ .catch((e: unknown) => setDesk(key, { loading: false, error: e instanceof Error ? e.message : 'The Dev desk couldn’t load.' }))
+ .finally(() => inflight.delete(key));
+ inflight.set(key, p);
return p;
},
- /** Tests and shots. */
- _set: setDesk,
+ /** Tests and shots: `space`, or `space` and a repo key. */
+ _set: (space: string, patch: Partial<DeskData>, repo: string | null = null) => setDesk(deskKey(space, repo), patch),
_reset() {
desks.clear();
inflight.clear();
},
};
-/** "14:32", 24-hour local time. */
-export function checkedLabel(ms: number): string {
- const d = new Date(ms);
- return `${String(d.getHours()).padStart(2, '0')}:${String(d.getMinutes()).padStart(2, '0')}`;
+/** A finding or post changed a review card: the space's list and the filtered one both show it. */
+function patchReview(space: string, repo: string | null, card: ShellCard) {
+ for (const r of repo ? [null, repo] : [null]) {
+ const list = deskStore.get(space, r).reviews;
+ if (list) deskStore._set(space, { reviews: list.map((c) => (c.id === card.id ? card : c)) }, r);
+ }
}
-export function useDesk(space: string, on: boolean): DeskData {
- const data = useSyncExternalStore(deskStore.subscribe, () => deskStore.get(space), () => EMPTY);
+/** "14:32", 24-hour local time (now in devMode.ts, shared with the repo rows). */
+export { checkedLabel };
+
+export function useDesk(space: string, on: boolean, repo: string | null = null): DeskData {
+ const data = useSyncExternalStore(deskStore.subscribe, () => deskStore.get(space, repo), () => EMPTY);
useEffect(() => {
if (!on) return undefined;
- void deskStore.load(space);
+ void deskStore.load(space, repo);
const onCard = (e: Event) => {
const d = (e as CustomEvent<DevCardEvent>).detail;
- if (d?.space_id === space && d.kind !== 'release_notes') void deskStore.load(space);
+ if (d?.space_id === space && d.kind !== 'release_notes') void deskStore.load(space, repo);
};
window.addEventListener(DEV_CARD_EVENT, onCard);
return () => window.removeEventListener(DEV_CARD_EVENT, onCard);
- }, [space, on]);
+ }, [space, on, repo]);
return data;
}
@@ -97,7 +108,7 @@ export const rowBadge = (dev: DevModeState | null, openReviewCount: number): num
/** Flow F4: while the first poll reads the last merges, the desk shows still placeholder cards. */
export const firstPolling = (dev: DevModeState | null, landedCount: number): boolean =>
- !!dev?.on && dev.status === 'watching' && !dev.polled_at && landedCount === 0;
+ !!dev?.on && dev.status === 'watching' && !dev.polled_at && !dev.repos.some((r) => r.polled_at) && landedCount === 0;
// ---------------------------------------------------------------------------
// The sidebar row
@@ -178,11 +189,18 @@ export interface DevDeskViewProps {
now?: number;
/** Opens Loose ends, for the status line's Connect. */
onOpenLooseEnds?: () => void;
+ /** The space's teams, so a team with no repo gets "Link a repo" in the repo list. */
+ teams?: DevTeamRef[];
}
-export const DevDeskView: React.FC<DevDeskViewProps> = ({ spaceId, onBack, onSaveToNotion, initialTab = 'landed', now, onOpenLooseEnds }) => {
- const desk = useDesk(spaceId, true);
+export const DevDeskView: React.FC<DevDeskViewProps> = ({ spaceId, onBack, onSaveToNotion, initialTab = 'landed', now, onOpenLooseEnds, teams }) => {
const dev = useDevMode(spaceId);
+ // 0.7.2: with several repos, both lists filter by one (All · app · site) through `?repo=`.
+ const filters = repoFilters(dev);
+ const [repoPick, setRepoPick] = useState<string | null>(null);
+ const repo = repoPick && filters.some((f) => f.key === repoPick) ? repoPick : null;
+ const desk = useDesk(spaceId, true, repo);
+ const repoLabel = useCallback((key: string | null, name?: string | null) => cardRepoLabel(dev, key, name), [dev]);
const [tab, setTab] = useState<Tab>(initialTab);
// Flow F6: opening the desk clears the row badge on every device.
useEffect(() => {
@@ -207,17 +225,20 @@ export const DevDeskView: React.FC<DevDeskViewProps> = ({ spaceId, onBack, onSav
const notesId = notes?.id ?? null;
// "Open review" on a landed card: the PR whose review card gets scrolled to and focused once the
// Reviews tab has rendered.
- const [openPr, setOpenPr] = useState<number | null>(null);
+ const [openPr, setOpenPr] = useState<{ pr: number; repo: string | null } | null>(null);
- const openReview = useCallback((pr: number) => {
+ const openReview = useCallback((pr: number, repoKey: string | null = null) => {
setTab('reviews');
- setOpenPr(pr);
+ setOpenPr({ pr, repo: repoKey });
}, []);
useEffect(() => {
if (openPr === null || tab !== 'reviews') return;
const panel = panelRef.current;
- const card = panel?.querySelector<HTMLElement>(`[data-dev-card="review"][data-pr="${openPr}"]`);
+ // The same PR number can be open in two repos: the landed card's repo picks which.
+ const card =
+ (openPr.repo ? panel?.querySelector<HTMLElement>(`[data-dev-card="review"][data-pr="${openPr.pr}"][data-repo="${openPr.repo.replace(/["\\]/g, '')}"]`) : null) ??
+ panel?.querySelector<HTMLElement>(`[data-dev-card="review"][data-pr="${openPr.pr}"]`);
const heading = card?.querySelector<HTMLElement>('h3');
setOpenPr(null);
if (!card || !heading) {
@@ -263,15 +284,15 @@ export const DevDeskView: React.FC<DevDeskViewProps> = ({ spaceId, onBack, onSav
setActionError(null);
devApi
.seen(spaceId)
- .then(() => deskStore.load(spaceId))
+ .then(() => Promise.all([deskStore.load(spaceId), repo ? deskStore.load(spaceId, repo) : undefined]))
.catch((e: unknown) => setActionError(e instanceof Error ? e.message : 'Couldn’t mark them seen.'))
.finally(() => setMarking(false));
- }, [spaceId, marking]);
+ }, [spaceId, marking, repo]);
const draftNotes = useCallback(() => {
setActionError(null);
setNotesError(null);
- devApi.releaseNotes(spaceId).then(
+ devApi.releaseNotes(spaceId, repo).then(
(raw) => {
const c = asCard(raw);
if (c) setNotes(c);
@@ -279,28 +300,26 @@ export const DevDeskView: React.FC<DevDeskViewProps> = ({ spaceId, onBack, onSav
},
(e: unknown) => setActionError(e instanceof Error ? e.message : 'Couldn’t start the draft.'),
);
- }, [spaceId]);
+ }, [spaceId, repo]);
const onFinding = useCallback(
async (cardId: string, findingId: string, action: FindingAction): Promise<ShellCard> => {
const card = asCard(await devApi.finding(cardId, findingId, action));
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)) });
+ patchReview(spaceId, repo, card);
return card;
},
- [spaceId],
+ [spaceId, repo],
);
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)) });
+ patchReview(spaceId, repo, card);
return card;
},
- [spaceId],
+ [spaceId, repo],
);
const landed = desk.landed;
@@ -347,7 +366,9 @@ export const DevDeskView: React.FC<DevDeskViewProps> = ({ spaceId, onBack, onSav
</span>
<div className="min-w-0 flex-1">
<h2 className="text-[17px] leading-6 font-semibold text-zinc-50 truncate">Dev desk</h2>
- <p className="hidden sm:block text-meta text-zinc-400 truncate">What landed and what needs a look</p>
+ <p className="hidden sm:block text-meta text-zinc-400 truncate" data-dev-desk-sub>
+ {dev && !dev.on ? DEV_OFF : 'What landed and what needs a look'}
+ </p>
</div>
{dev?.repo && !dev.status && (
<span className="hidden sm:inline-flex shrink-0 font-mono text-[11px] text-zinc-300 px-2 py-0.5 rounded-md bg-white/[0.04] border border-zinc-700/60" data-dev-repo-chip>
@@ -362,7 +383,7 @@ export const DevDeskView: React.FC<DevDeskViewProps> = ({ spaceId, onBack, onSav
)}
<button
type="button"
- onClick={() => void deskStore.load(spaceId)}
+ onClick={() => void deskStore.load(spaceId, repo)}
disabled={desk.loading}
aria-label="Refresh"
data-dev-refresh
@@ -375,6 +396,7 @@ export const DevDeskView: React.FC<DevDeskViewProps> = ({ spaceId, onBack, onSav
<DevStatusLine
spaceId={spaceId}
state={dev}
+ teams={teams}
onConnect={onOpenLooseEnds}
checked={desk.checkedAt != null ? checkedLabel(desk.checkedAt) : null}
checkedAt={desk.checkedAt ?? null}
@@ -383,7 +405,7 @@ export const DevDeskView: React.FC<DevDeskViewProps> = ({ spaceId, onBack, onSav
<div className="flex-1 overflow-y-auto overflow-x-hidden p-4 sm:p-6" aria-busy={desk.loading}>
<div className="max-w-[760px] mx-auto space-y-4">
{intro && dev?.on && (
- <DevIntro cmd="kwant dev --on" repo={(dev.status ?? (dev.repo ? 'watching' : 'no_repo')) === 'watching' ? dev.repo : null} onClose={() => setIntro(false)} />
+ <DevIntro cmd="kwant dev --on" repo={(dev.status ?? (dev.repo ? 'watching' : 'no_repo')) !== 'watching' ? null : dev.repos.length > 1 ? reposSummary(dev).replace(/^Watching /, '') : dev.repos[0]?.repo ?? dev.repo} onClose={() => setIntro(false)} />
)}
<div role="tablist" aria-label="Dev desk" className="kw-dv-tabs">
{tabs.map((t, i) => {
@@ -410,11 +432,29 @@ export const DevDeskView: React.FC<DevDeskViewProps> = ({ spaceId, onBack, onSav
})}
</div>
+ {filters.length > 1 && (
+ <div role="group" aria-label="Show cards from" className="kw-dv-filters" data-dev-repo-filters>
+ {[{ key: null as string | null, label: 'All', repo: 'All repos' }, ...filters].map((f) => (
+ <button
+ key={f.key ?? 'all'}
+ type="button"
+ aria-pressed={repo === f.key}
+ title={f.key ? f.repo : undefined}
+ onClick={() => setRepoPick(f.key)}
+ data-dev-repo-filter={f.key ?? 'all'}
+ className={`kw-dv-filter ${focusRing}`}
+ >
+ {f.label}
+ </button>
+ ))}
+ </div>
+ )}
+
{(desk.error || actionError) && (
<div role="alert" className="px-3 py-2 rounded-lg border border-rose-400/30 bg-rose-500/10 flex flex-wrap items-center gap-2 text-xs text-rose-100">
<span className="min-w-0 flex-1">{actionError ?? desk.error}</span>
{desk.error && !actionError && (
- <button type="button" onClick={() => void deskStore.load(spaceId)} className={`px-2 py-0.5 rounded border border-rose-400/40 hover:bg-rose-500/10 min-h-[32px] ${focusRing}`}>
+ <button type="button" onClick={() => void deskStore.load(spaceId, repo)} className={`px-2 py-0.5 rounded border border-rose-400/40 hover:bg-rose-500/10 min-h-[32px] ${focusRing}`}>
Try again
</button>
)}
@@ -438,7 +478,7 @@ export const DevDeskView: React.FC<DevDeskViewProps> = ({ spaceId, onBack, onSav
last_tag={landed.last_tag}
last_merge={lastMerge}
cards={landedCards}
- branch={dev?.branch || 'main'}
+ branch={(repo ? dev?.repos.find((r) => r.key === repo)?.branch : null) || dev?.branch || dev?.repos[0]?.branch || 'main'}
onMarkSeen={markSeen}
onDraftNotes={draftNotes}
drafting={!!notes && notes.status === 'pending'}
@@ -446,7 +486,7 @@ export const DevDeskView: React.FC<DevDeskViewProps> = ({ spaceId, onBack, onSav
/>
)}
{landedCards.length ? (
- <LandedList cards={landedCards} reviews={reviews} now={now} onOpenReview={openReview} forge={dev?.forge ?? null} />
+ <LandedList cards={landedCards} reviews={reviews} now={now} onOpenReview={openReview} forge={dev?.forge ?? null} repoLabel={repoLabel} />
) : dev?.status === 'not_connected' ? (
<TermEmpty out="(needs a GitHub connection)" title="Connect GitHub to see what landed." line="The last 5 merges show up here right after." />
) : dev?.status === 'no_repo' ? (
@@ -467,7 +507,7 @@ export const DevDeskView: React.FC<DevDeskViewProps> = ({ spaceId, onBack, onSav
)}
</>
) : reviews.length ? (
- reviews.map((c) => <ReviewCard key={c.id} card={c} onFinding={onFinding} onPost={onPost} forge={dev?.forge ?? null} forgeLogin={dev?.forge_login ?? null} 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} repoLabel={repoLabel} />)
) : (
desk.reviews && (
<TermEmpty
diff --git a/frontend/src/components/DevDeskSlots.tsx b/frontend/src/components/DevDeskSlots.tsx
index 2c440f57..64e0b7ba 100644
--- a/frontend/src/components/DevDeskSlots.tsx
+++ b/frontend/src/components/DevDeskSlots.tsx
@@ -30,9 +30,11 @@ export interface LandedListProps {
cards: ShellCard[];
reviews: ShellCard[];
now?: number;
- onOpenReview?: (pr: number) => void;
+ onOpenReview?: (pr: number, repo?: string | null) => void;
/** `forge` from GET dev_mode: names the "Open on {Forge}" link. */
forge?: Forge | null;
+ /** 0.7.2: the card's repo chip text, or null with one repo in the space (`cardRepoLabel`). */
+ repoLabel?: (repo: string | null, name?: string | null) => string | null;
}
export interface ReviewCardProps {
@@ -45,6 +47,8 @@ export interface ReviewCardProps {
forgeLogin?: string | null;
sample?: boolean;
now?: number;
+ /** 0.7.2: the card's repo chip text, or null with one repo in the space (`cardRepoLabel`). */
+ repoLabel?: (repo: string | null, name?: string | null) => string | null;
}
export interface ReleaseNotesSheetProps {
@@ -63,14 +67,14 @@ export const Rollup: React.FC<RollupProps> = ({ cards = [], ...rest }) => {
return <IrisRollup {...rest} needsYouAreas={needs} />;
};
-export const LandedList: React.FC<LandedListProps> = ({ cards, reviews, now, onOpenReview, forge = null }) => {
+export const LandedList: React.FC<LandedListProps> = ({ cards, reviews, now, onOpenReview, forge = null, repoLabel }) => {
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} forge={forge} />}
+ {parsed.length > 0 && <IrisLandedList cards={parsed} reviews={parsedReviews} now={now} onOpenReview={onOpenReview} forge={forge} repoLabel={repoLabel} />}
{refused.map((c) => (
<CardFallback key={c.id} raw={c} />
))}
@@ -78,7 +82,7 @@ export const LandedList: React.FC<LandedListProps> = ({ cards, reviews, now, onO
);
};
-export const ReviewCard: React.FC<ReviewCardProps> = ({ card, onFinding, onPost, forge, forgeLogin, sample, now }) => {
+export const ReviewCard: React.FC<ReviewCardProps> = ({ card, onFinding, onPost, forge, forgeLogin, sample, now, repoLabel }) => {
const parsed = useMemo(() => parseReview(card), [card]);
if (!parsed) return <CardFallback raw={card} />;
const send = async (cardId: string, findingId: string, action: FindingAction): Promise<Review> => {
@@ -93,7 +97,7 @@ export const ReviewCard: React.FC<ReviewCardProps> = ({ card, onFinding, onPost,
return next;
}
: undefined;
- return <IrisReviewCard card={parsed} onFinding={send} onPost={post} forge={forge} forgeLogin={forgeLogin} sample={sample} now={now} />;
+ return <IrisReviewCard card={parsed} onFinding={send} onPost={post} forge={forge} forgeLogin={forgeLogin} sample={sample} now={now} repoLabel={repoLabel} />;
};
export const ReleaseNotesSheet: React.FC<ReleaseNotesSheetProps> = ({ card, onSaveToNotion, onDiscard, onClose }) => {
diff --git a/frontend/src/components/DevStatusLine.tsx b/frontend/src/components/DevStatusLine.tsx
index 0199b1e0..c3354c1b 100644
--- a/frontend/src/components/DevStatusLine.tsx
+++ b/frontend/src/components/DevStatusLine.tsx
@@ -1,249 +1,463 @@
-// The Dev desk's one status line (0.7.1, any-git S5). Dev mode turns on with no question asked; the
-// server finds the repo in the space's teams and says what it can read. This line says it back, with
-// at most one action: Switch (several repos found), Connect GitHub, or Type a repo (none found). Nothing here
-// blocks anything: the production floor and the command guards are on in every status.
+// The Dev desk's status (0.7.2, team repos; copy: dev-mode-explainer/spec.md §6 and §9b). The repo belongs
+// to the team, not the space: Dev mode watches every team's repo. One repo reads as one line, as in 0.7.1.
+// Several repos are a list, one row per repo (team · owner/name · branch · status, then where it comes
+// from), each with at most one action: Connect GitHub, Link a repo (a team with none), or Remove (a repo
+// added by you). A team's repo has no Remove: an info note says where to change it. More than three rows
+// fold behind "Watching N repos" with Show repos / Hide repos. Teams with no repo get rows only while no
+// repo is watched; otherwise they are one quiet last line. Nothing here blocks anything: the production
+// floor and the command guards are on in every status.
import React, { useEffect, useId, useRef, useState } from 'react';
-import { Check, ChevronDown, FolderGit2, Link2, Loader2 } from 'lucide-react';
-import { DevModeState, DevSource, StatusLine, deskIntent, devApi, devStore, statusLine, typedRepo, watchedSource } from '../devMode';
+import { ChevronDown, Info } from 'lucide-react';
+import {
+ DevModeError,
+ DevModeState,
+ DevTeamRef,
+ LINK_ERROR,
+ LINK_HELP,
+ LINK_HELP_HAND,
+ LINK_PLACEHOLDER,
+ READY,
+ READY_TITLE,
+ UNDO_TOAST_MS,
+ clearedText,
+ RemovedRepo,
+ RepoRow,
+ RowAction,
+ StatusLine,
+ deskIntent,
+ devApi,
+ devStore,
+ noRepoTeamsText,
+ removedText,
+ statusLine,
+ teamNoteText,
+ typedRepo,
+ undoBody,
+} from '../devMode';
const focusRing = 'focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-sky-400';
/** style-v2 §4: the LED mirrors the status. ok only while a remote repo is really watched. */
-export function statusLed(line: StatusLine, state: DevModeState): 'ok' | 'warn' | 'off' {
- if (line.status === 'not_connected') return 'warn';
- if (line.status === 'watching') return watchedSource(state)?.from === 'local' ? 'off' : 'ok';
- return 'off';
-}
+export const statusLed = (line: StatusLine): StatusLine['led'] => line.led;
-export const sourceWhere = (s: DevSource): string => (s.from === 'repo' ? `${s.team}’s repo link` : s.from === 'local' ? `${s.team}’s folder, no remote` : `${s.team}’s folder`);
+const ACTION_TEXT: Record<RowAction, string> = { connect: 'Connect GitHub', link: 'Link a repo', remove: 'Remove' };
export interface DevStatusLineProps {
spaceId: string;
state: DevModeState | null;
+ /** The space's teams, so a team with no repo gets "Link a repo". */
+ teams?: DevTeamRef[];
/** Opens Loose ends (Connect GitHub). Connect hides without it. */
onConnect?: () => void;
/** "Checked 19:58" at the right (style-v2 §4); the LED pings once each time it changes. */
checked?: string | null;
checkedAt?: number | null;
- /** Test hook. */
- save?: typeof devApi.putRepo;
+ /** Test hooks. */
+ save?: typeof devApi.linkRepo;
+ remove?: typeof devApi.removeRepo;
}
-export const DevStatusLine: React.FC<DevStatusLineProps> = ({ spaceId, state, onConnect, checked = null, checkedAt = null, save = devApi.putRepo }) => {
- const line = statusLine(state);
- // The toast's "Type a repo" lands here with the list open and its input focused.
- const [open, setOpen] = useState<false | 'list' | 'type'>(() => (deskIntent.take(spaceId) ? 'type' : false));
- const switchBtn = useRef<HTMLButtonElement>(null);
+/** Where the Link form is open: a team row (`team:{id}`), the quiet no-repo line (`norepo`), or the single line (`line`). */
+type Linking = string | null;
+
+/** A refused or unknown repo reads as Mira's one error; anything else keeps the server's plain sentence. */
+const linkError = (e: unknown): string => {
+ if (e instanceof DevModeError && e.code && e.code !== 'bad_repo' && e.code !== 'no_branch') return e.message;
+ if (e instanceof DevModeError && !e.code && e.status === 0) return e.message;
+ return LINK_ERROR;
+};
+
+export const DevStatusLine: React.FC<DevStatusLineProps> = ({ spaceId, state, teams = [], onConnect, checked = null, checkedAt = null, save = devApi.linkRepo, remove = devApi.removeRepo }) => {
+ const line = statusLine(state, teams);
+ const listId = useId();
+ // The header's "Link a repo" / the toast's "Type a repo" open the first Link form, focused; "See repos"
+ // opens the list and scrolls to it.
+ const [intent] = useState(() => deskIntent.take(spaceId));
+ const [linking, setLinking] = useState<Linking>(() => (intent === 'type' ? 'intent' : null));
+ const [busy, setBusy] = useState<string | null>(null);
+ const [error, setError] = useState<{ id: string; text: string } | null>(null);
+ const [expanded, setExpanded] = useState(intent === 'repos');
+ const [note, setNote] = useState<string | null>(null);
+ const [removed, setRemoved] = useState<(RemovedRepo & { busy: boolean; error: string | null }) | null>(null);
+ const wrap = useRef<HTMLDivElement>(null);
// One 200 ms ping when a check lands, not on first paint.
const firstCheck = useRef(checkedAt);
const ping = checkedAt != null && checkedAt !== firstCheck.current;
+ useEffect(() => {
+ if (intent === 'repos') requestAnimationFrame(() => wrap.current?.scrollIntoView?.({ block: 'start' }));
+ }, [intent]);
+ // The Remove / Clear toast leaves after UNDO_TOAST_MS unless the person is on it.
+ useEffect(() => {
+ if (!removed || removed.busy || removed.error) return;
+ const t = setTimeout(() => setRemoved(null), UNDO_TOAST_MS);
+ return () => clearTimeout(t);
+ }, [removed]);
if (!line || !state) return null;
- const led = statusLed(line, state);
- const action =
- line.action === 'switch' || line.action === 'type' ? (
+
+ const rows = line.rows;
+ const noRepo = line.noRepoTeams;
+ // The intent opens on the first team with no repo (a row, or the quiet line), or on the single line.
+ const linkingId = linking === 'intent' ? rows.find((r) => r.action === 'link')?.id ?? (noRepo.length ? 'norepo' : 'line') : linking;
+ const open = !line.collapsed || expanded || (linkingId !== null && linkingId !== 'line' && linkingId !== 'norepo');
+ const single = rows.length === 0;
+ const singleRow: RepoRow | null =
+ single && state.repos.length === 1
+ ? { id: state.repos[0].key, team: state.repos[0].team, teamId: null, repo: state.repos[0], state: '', origin: null, teamNote: null, title: null, led: line.led, action: line.action }
+ : null;
+ // The single line's Link: the one team with none, if there is exactly one; else a repo added by hand.
+ const loneTeam = single && line.action === 'link' ? teams.find((t) => !state.repos.some((r) => r.team === t.name)) ?? null : null;
+
+ const focusAfter = (id: string) => {
+ requestAnimationFrame(() => {
+ const el = [...(wrap.current?.querySelectorAll<HTMLElement>('[data-dv-row-action], [data-dv-status-action], [data-dv-norepo-action]') ?? [])].find(
+ (b) => b.dataset.dvRowAction === id || (id === 'line' && b.dataset.dvStatusAction) || (id === 'norepo' && b.dataset.dvNorepoAction !== undefined),
+ );
+ el?.focus();
+ });
+ };
+
+ const doRemove = (row: RepoRow) => {
+ if (!row.repo || busy) return;
+ const repo = row.repo;
+ setBusy(row.id);
+ setError(null);
+ remove(spaceId, repo.key).then(
+ (s) => {
+ devStore.set(spaceId, s);
+ setBusy(null);
+ // A team's repo link comes back as that team's link; a hand row as a hand row (answer 5).
+ const team = repo.added_by === 'team' && repo.from === 'repo' ? row.teamId : null;
+ setRemoved({ repo: repo.repo, team, teamName: team ? row.team : null, busy: false, error: null });
+ requestAnimationFrame(() => wrap.current?.querySelector<HTMLElement>('[data-dv-undo]')?.focus());
+ },
+ (e: unknown) => {
+ setBusy(null);
+ // 409 team_repo: the row comes from a team; say where to change it (spec §6).
+ const text = e instanceof DevModeError && e.code === 'team_repo' ? teamNoteText(row.team ?? 'this team', repo.from) : e instanceof Error ? e.message : 'Couldn’t remove the repo.';
+ setError({ id: row.id, text });
+ },
+ );
+ };
+
+ const undo = () => {
+ if (!removed || removed.busy) return;
+ setRemoved({ ...removed, busy: true, error: null });
+ save(spaceId, { ...undoBody(removed), on: state?.on ?? null }).then(
+ ({ state: s, refused }) => {
+ devStore.set(spaceId, s);
+ setRemoved(refused ? { ...removed, busy: false, error: refused } : null);
+ },
+ (e: unknown) => setRemoved({ ...removed, busy: false, error: e instanceof Error ? e.message : 'Couldn’t add it back.' }),
+ );
+ };
+
+ const act = (row: RepoRow | null, action: RowAction, id: string) => {
+ if (action === 'connect') return onConnect?.();
+ if (action === 'link') {
+ setError(null);
+ return setLinking((l) => (l === id || (l === 'intent' && linkingId === id) ? null : id));
+ }
+ if (row) doRemove(row);
+ };
+
+ const actionButton = (row: RepoRow | null, action: RowAction | null, id: string, label: string, isLine: boolean) => {
+ if (!action || (action === 'connect' && !onConnect)) return null;
+ const expandedAttr = action === 'link' ? linkingId === id : undefined;
+ return (
<button
- ref={switchBtn}
type="button"
- onClick={() => setOpen((o) => (o ? false : line.action === 'type' ? 'type' : 'list'))}
- aria-expanded={!!open}
- aria-haspopup="true"
- data-dv-status-action={line.action}
+ onClick={() => act(row, action, id)}
+ disabled={busy === id}
+ aria-expanded={expandedAttr}
+ aria-label={action === 'remove' ? `Stop watching ${label}` : action === 'link' && row?.team ? `Link a repo for ${row.team}` : undefined}
+ {...(isLine ? { 'data-dv-status-action': action } : { 'data-dv-row-action': id, 'data-action': action })}
className={`act kw-dv-status-act ${focusRing}`}
>
- {line.action === 'type' ? 'Type a repo' : 'Switch'}
- {line.action === 'switch' && <ChevronDown size={12} aria-hidden="true" className={open ? 'rotate-180' : ''} />}
+ {busy === id && action === 'remove' ? 'Removing…' : ACTION_TEXT[action]}
</button>
- ) : line.action === 'connect' && onConnect ? (
- <button type="button" onClick={onConnect} data-dv-status-action="connect" className={`act kw-dv-status-act ${focusRing}`}>
- Connect GitHub
- </button>
- ) : null;
+ );
+ };
+
+ const linkForm = (id: string, team: DevTeamRef | null, after: string, pick?: DevTeamRef[]) => (
+ <LinkForm
+ key={id}
+ team={team}
+ pick={pick}
+ onCancel={() => {
+ setLinking(null);
+ focusAfter(after);
+ }}
+ onSubmit={async (repo, t) => {
+ const { state: s, refused } = await save(spaceId, { repo, team: t?.id ?? null, on: state?.on ?? null });
+ devStore.set(spaceId, s);
+ if (refused) return LINK_ERROR;
+ setLinking(null);
+ return null;
+ }}
+ />
+ );
+
return (
- <div className="relative" data-dv-status-wrap>
- <div role="status" className="dv-statusline kw-dv-statusline" data-dv-status={line.status}>
+ <div ref={wrap} className="relative" data-dv-status-wrap>
+ <div role="status" className="dv-statusline kw-dv-statusline" data-dv-status={line.status} data-dv-repos={state.repos.length}>
<p className="txt" data-dv-status-text>
- <span key={checkedAt ?? 0} className="dv-led" data-s={led} data-ping={ping || undefined} data-dv-led={led} aria-hidden="true" />
- <span>
+ <span key={checkedAt ?? 0} className="dv-led" data-s={line.led} data-ping={ping || undefined} data-dv-led={line.led} aria-hidden="true" />
+ <span className="min-w-0">
{line.parts.map((p, i) =>
- p.mono ? (
- // The branch follows " on "; the repo and host read as names.
- /\bon $/.test(line.parts[i - 1]?.text ?? '') ? (
- <code key={i} className="dv-code">
- {p.text}
- </code>
- ) : (
- <b key={i} className="font-mono text-[12px] break-all">
- {p.text}
- </b>
- )
+ p.branch ? (
+ <code key={i} className="dv-code">
+ {p.text}
+ </code>
+ ) : p.mono ? (
+ <b key={i} className="font-mono text-[12px] break-all">
+ {p.text}
+ </b>
) : (
<React.Fragment key={i}>{p.text}</React.Fragment>
),
)}
</span>
+ {line.collapsed && (
+ <button
+ type="button"
+ aria-expanded={open}
+ aria-controls={listId}
+ onClick={() => {
+ if (open) setLinking(null);
+ setExpanded(!open);
+ }}
+ data-dv-disclosure
+ className={`kw-dv-disclosure ${focusRing}`}
+ >
+ <span>{open ? 'Hide repos' : 'Show repos'}</span>
+ <ChevronDown size={13} aria-hidden="true" className={open ? 'rotate-180' : ''} />
+ </button>
+ )}
</p>
- {action}
+ {single && actionButton(singleRow, line.action, singleRow?.id ?? 'line', singleRow?.repo?.repo ?? '', true)}
{checked && (
<span className="checked" data-dev-checked>
Checked {checked}
</span>
)}
</div>
- {open && (
- <SourcePicker
- spaceId={spaceId}
- state={state}
- save={save}
- focusInput={open === 'type'}
- onClose={(refocus) => {
- setOpen(false);
- if (refocus) switchBtn.current?.focus();
- }}
- />
+ {single && linkingId === 'line' && line.action === 'link' && <div className="kw-dv-repo-form-wrap">{linkForm('line', loneTeam, 'line')}</div>}
+ {single && error && (
+ <p className="kw-dv-repo-err" role="alert">
+ {error.text}
+ </p>
+ )}
+ {!single && open && (
+ <ul id={listId} className="kw-dv-repos" aria-label="Repos Dev mode watches" data-dv-repos-list>
+ {rows.map((r) => (
+ <li key={r.id} className="kw-dv-repo" data-dv-repo-row={r.id} data-s={r.repo?.status ?? 'no_repo'}>
+ <div className="kw-dv-repo-line">
+ <span className="dv-led" data-s={r.led} aria-hidden="true" />
+ <span className="kw-dv-repo-cells">
+ {r.team && <span className="kw-dv-repo-team">{r.team}</span>}
+ {r.repo ? (
+ <>
+ {r.team && (
+ <span className="kw-dv-repo-sep" aria-hidden="true">
+ ·
+ </span>
+ )}
+ <b className="kw-dv-repo-name">{r.repo.repo}</b>
+ {r.repo.branch && r.repo.status !== 'other_host' && r.repo.status !== 'too_many' && (
+ <>
+ <span className="kw-dv-repo-sep" aria-hidden="true">
+ ·
+ </span>
+ <code className="dv-code">{r.repo.branch}</code>
+ </>
+ )}
+ </>
+ ) : null}
+ <span className="kw-dv-repo-sep" aria-hidden="true">
+ ·
+ </span>
+ <span
+ className="kw-dv-repo-state"
+ data-dv-repo-state
+ data-tone={r.state === READY ? 'neutral' : undefined}
+ title={r.state === READY ? READY_TITLE : r.title ?? undefined}
+ aria-label={r.state === READY ? READY_TITLE : undefined}
+ >
+ {r.state}
+ </span>
+ </span>
+ {r.teamNote && (
+ <button
+ type="button"
+ aria-label={r.teamNote}
+ aria-expanded={note === r.id}
+ title={r.teamNote}
+ onClick={() => setNote((n) => (n === r.id ? null : r.id))}
+ data-dv-team-note={r.id}
+ className={`kw-dv-info ${focusRing}`}
+ >
+ <Info size={14} aria-hidden="true" />
+ </button>
+ )}
+ {actionButton(r, r.action, r.id, r.repo?.repo ?? r.team ?? '', false)}
+ </div>
+ {r.origin && (
+ <p className="kw-dv-repo-origin" data-dv-repo-origin>
+ {r.origin}
+ </p>
+ )}
+ {note === r.id && r.teamNote && (
+ <p className="kw-dv-repo-origin" data-dv-team-note-text>
+ {r.teamNote}
+ </p>
+ )}
+ {r.action === 'link' && linkingId === r.id && linkForm(r.id, r.teamId && r.team ? { id: r.teamId, name: r.team } : null, r.id)}
+ {error?.id === r.id && (
+ <p className="kw-dv-repo-err" role="alert">
+ {error.text}
+ </p>
+ )}
+ </li>
+ ))}
+ </ul>
+ )}
+ {noRepo.length > 0 && (
+ <div className="kw-dv-norepo" data-dv-norepo={noRepo.length}>
+ <p className="kw-dv-norepo-line">
+ <span>{noRepoTeamsText(noRepo.length)}</span>
+ <span className="kw-dv-repo-sep" aria-hidden="true">
+ ·
+ </span>
+ <button
+ type="button"
+ aria-expanded={linkingId === 'norepo'}
+ onClick={() => setLinking((l) => (l === 'norepo' || (l === 'intent' && linkingId === 'norepo') ? null : 'norepo'))}
+ data-dv-norepo-action
+ className={`kw-dv-norepo-act ${focusRing}`}
+ >
+ Link a repo
+ </button>
+ </p>
+ {linkingId === 'norepo' && linkForm('norepo', noRepo.length === 1 ? noRepo[0] : null, 'norepo', noRepo.length > 1 ? noRepo : undefined)}
+ </div>
+ )}
+ {removed && (
+ <div role="status" className="kw-dv-removed" data-dv-removed>
+ <span>{removed.error ?? (removed.team ? clearedText(removed.teamName || 'the team') : removedText(removed.repo))}</span>
+ {!removed.error && (
+ <button type="button" onClick={undo} disabled={removed.busy} data-dv-undo className={`kw-dv-norepo-act ${focusRing}`}>
+ {removed.busy ? 'Adding back…' : 'Undo'}
+ </button>
+ )}
+ </div>
)}
</div>
);
};
// ---------------------------------------------------------------------------
-// Switch: a one-tap list of the detected repos, and a typed repo below it.
-
-const SourcePicker: React.FC<{ spaceId: string; state: DevModeState; save: typeof devApi.putRepo; focusInput?: boolean; onClose: (refocus: boolean) => void }> = ({
- spaceId,
- state,
- save,
- focusInput = false,
- onClose,
+// Link a repo (spec §6): one field. With a team it becomes that team's repo link (PUT {repo, team});
+// with several teams to choose from (the quiet "N teams have no repo" line) a team picker comes first;
+// with none it is added by hand (PUT {repo}).
+
+const LinkForm: React.FC<{ team: DevTeamRef | null; pick?: DevTeamRef[]; onSubmit: (repo: string, team: DevTeamRef | null) => Promise<string | null>; onCancel: () => void }> = ({
+ team,
+ pick,
+ onSubmit,
+ onCancel,
}) => {
const id = useId();
- const box = useRef<HTMLDivElement>(null);
- const [busy, setBusy] = useState<string | null>(null);
- const [error, setError] = useState<string | null>(null);
+ const first = useRef<HTMLSelectElement & HTMLInputElement>(null);
+ const [picked, setPicked] = useState<DevTeamRef | null>(team ?? pick?.[0] ?? null);
const [typed, setTyped] = useState('');
- const current = watchedSource(state)?.repo ?? state.repo;
-
- useEffect(() => {
- if (focusInput) box.current?.querySelector<HTMLInputElement>('input')?.focus();
- else box.current?.querySelector<HTMLButtonElement>('[aria-checked="true"]')?.focus() ?? box.current?.querySelector<HTMLButtonElement>('button')?.focus();
- const away = (e: MouseEvent) => {
- if (box.current && !box.current.contains(e.target as Node) && !(e.target as Element).closest?.('[data-dv-status-action]')) onClose(false);
- };
- document.addEventListener('mousedown', away);
- return () => document.removeEventListener('mousedown', away);
- }, [onClose]);
-
- const pick = (repo: string) => {
- if (busy) return;
- if (repo === current) return onClose(true);
- setBusy(repo);
- setError(null);
- save(spaceId, { on: true, repo }).then(
- ({ state: s, refused }) => {
- devStore.set(spaceId, s);
- // Dev mode is on either way; a repo it can't read keeps the list open with why (Juno's check).
- if (refused) {
- setBusy(null);
- setError(refused);
- return;
- }
- onClose(true);
- },
- (e: unknown) => {
- setBusy(null);
- setError(e instanceof Error ? e.message : 'Couldn’t switch the repo.');
- },
- );
- };
-
- const typedOk = typed.trim() ? typedRepo(typed) : null;
- const typedErr = typed.trim() && !typedOk ? 'Paste a repo URL, or owner/name for GitHub.' : null;
-
+ const [busy, setBusy] = useState(false);
+ const [error, setError] = useState<string | null>(null);
+ useEffect(() => first.current?.focus(), []);
+ const ok = typed.trim() ? typedRepo(typed) : null;
+ const typedErr = typed.trim() && !ok ? LINK_ERROR : null;
+ const shown = error ?? typedErr;
return (
- <div
- ref={box}
- role="dialog"
- aria-label="Which repo to watch"
- data-dv-picker
+ <form
+ className="kw-dv-repo-form"
+ data-dv-link-form={picked?.id ?? 'hand'}
onKeyDown={(e) => {
if (e.key === 'Escape') {
e.stopPropagation();
- onClose(true);
+ onCancel();
}
}}
- className="kw-dv-picker"
+ onSubmit={(e) => {
+ e.preventDefault();
+ if (!ok || busy) return;
+ setBusy(true);
+ setError(null);
+ onSubmit(ok, picked).then(
+ (refused) => {
+ setBusy(false);
+ if (refused) setError(refused);
+ },
+ (err: unknown) => {
+ setBusy(false);
+ setError(linkError(err));
+ },
+ );
+ }}
>
- {state.sources.length > 0 && (
- <p id={`${id}-h`} className="px-1 pb-1.5 text-2xs font-semibold uppercase tracking-wider text-zinc-400">
- Found in this space
- </p>
+ {pick && pick.length > 1 && (
+ <div className="kw-dv-repo-form-pick">
+ <label htmlFor={`${id}-team`} className="kw-dv-repo-form-label">
+ Team
+ </label>
+ <select
+ ref={first}
+ id={`${id}-team`}
+ value={picked?.id ?? ''}
+ onChange={(e) => setPicked(pick.find((t) => t.id === e.target.value) ?? null)}
+ className="kw-dv-picker-input kw-dv-team-pick"
+ data-dv-team-pick
+ >
+ {pick.map((t) => (
+ <option key={t.id} value={t.id}>
+ {t.name}
+ </option>
+ ))}
+ </select>
+ </div>
)}
- {state.sources.length > 0 && (
- <div role="radiogroup" aria-labelledby={`${id}-h`} className="flex flex-col gap-1">
- {state.sources.map((s) => {
- const on = s.repo === current;
- return (
- <button
- key={s.repo}
- type="button"
- role="radio"
- aria-checked={on}
- disabled={!!busy}
- onClick={() => pick(s.repo)}
- data-dv-pick={s.repo}
- className={`kw-dv-pick ${focusRing}`}
- >
- <span className="kw-dv-pick-icon" aria-hidden="true">
- {s.from === 'repo' ? <Link2 size={13} /> : <FolderGit2 size={13} />}
- </span>
- <span className="min-w-0 flex-1 text-left">
- <span className="block font-mono text-[12px] text-zinc-100 truncate">{s.repo}</span>
- <span className="block text-2xs text-zinc-400 truncate">{sourceWhere(s)}</span>
- </span>
- {busy === s.repo ? (
- <Loader2 size={13} className="shrink-0 animate-spin motion-reduce:animate-none text-zinc-300" aria-hidden="true" />
- ) : on ? (
- <Check size={14} className="shrink-0 text-sky-300" aria-hidden="true" />
- ) : null}
- </button>
- );
- })}
+ <label htmlFor={`${id}-repo`} className="kw-dv-repo-form-label">
+ {picked ? `Repo for ${picked.name}` : 'Repo to watch'}
+ </label>
+ <div className="kw-dv-repo-form-row">
+ <input
+ ref={pick && pick.length > 1 ? undefined : first}
+ id={`${id}-repo`}
+ value={typed}
+ onChange={(e) => {
+ setTyped(e.target.value);
+ setError(null);
+ }}
+ placeholder={LINK_PLACEHOLDER}
+ spellCheck={false}
+ autoCapitalize="off"
+ autoComplete="off"
+ aria-invalid={!!shown || undefined}
+ aria-describedby={`${id}-help ${id}-err`}
+ className="kw-dv-picker-input"
+ />
+ <button type="submit" disabled={!ok || busy} className={`kw-dv-status-btn kw-dv-status-btn-primary ${focusRing}`}>
+ {busy ? 'Saving…' : 'Save'}
+ </button>
+ <button type="button" onClick={onCancel} className={`kw-dv-status-btn ${focusRing}`}>
+ Cancel
+ </button>
</div>
- )}
- <form
- className={state.sources.length ? 'mt-2 border-t border-white/10 pt-2.5 px-1' : 'px-1'}
- onSubmit={(e) => {
- e.preventDefault();
- if (typedOk) pick(typedOk);
- }}
- >
- <label htmlFor={`${id}-typed`} className="block text-2xs font-medium text-zinc-400 mb-1">
- Type a repo
- </label>
- <div className="flex gap-1.5">
- <input
- id={`${id}-typed`}
- value={typed}
- onChange={(e) => {
- setTyped(e.target.value);
- setError(null);
- }}
- placeholder="owner/repo or a git URL"
- spellCheck={false}
- autoCapitalize="off"
- autoComplete="off"
- aria-invalid={!!typedErr || undefined}
- aria-describedby={`${id}-err`}
- className="kw-dv-picker-input"
- />
- <button type="submit" disabled={!typedOk || !!busy} className={`kw-dv-status-btn kw-dv-status-btn-primary ${focusRing}`}>
- Watch
- </button>
- </div>
- <p id={`${id}-err`} className="mt-1 min-h-[1em] text-2xs text-rose-300" aria-live="polite">
- {error ?? typedErr}
- </p>
- </form>
- </div>
+ <p id={`${id}-help`} className="kw-dv-repo-form-help">
+ {picked ? LINK_HELP : LINK_HELP_HAND}
+ </p>
+ <p id={`${id}-err`} className="kw-dv-repo-form-err" aria-live="polite">
+ {shown}
+ </p>
+ </form>
);
};
diff --git a/frontend/src/components/dev/LandedCard.tsx b/frontend/src/components/dev/LandedCard.tsx
index 322cebd8..5487c961 100644
--- a/frontend/src/components/dev/LandedCard.tsx
+++ b/frontend/src/components/dev/LandedCard.tsx
@@ -11,13 +11,15 @@ const TESTS_TONE = { passed: 'text-ok', failed: 'text-bad', none: 'text-zinc-400
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; onRail?: boolean }> = ({
+export const LandedCard: React.FC<{ card: Landed; reviews?: ReviewCard[]; onOpenReview?: (pr: number, repo?: string | null) => void; forge?: Forge | null; onRail?: boolean; repoLabel?: (repo: string | null, name?: string | null) => string | null }> = ({
card,
reviews = [],
onOpenReview,
forge = null,
onRail = false,
+ repoLabel,
}) => {
+ const repoChip = repoLabel ? repoLabel(card.repo, card.repo_name) : null;
const verified = showVerified(card, reviews);
const writer = personText(card.written_by);
const merged = clock(card.merged_at);
@@ -27,7 +29,7 @@ export const LandedCard: React.FC<{ card: Landed; reviews?: ReviewCard[]; onOpen
const openFollowUps = card.follow_ups;
// S1: a finding still open in this PR's review is something to do, even when CI and follow-ups are clear.
const pr = card.pr;
- const findingsOpen = pr === null ? 0 : openFindings(reviews.find((r) => r.pr === pr));
+ const findingsOpen = pr === null ? 0 : openFindings(reviews.find((r) => r.pr === pr && (!card.repo || !r.repo || r.repo === card.repo)));
const nothingToDo = openFollowUps.length === 0 && card.tests.state === 'passed' && findingsOpen === 0;
const tests = testsWords(card.tests.state);
const diff = card.links.commit ?? (card.links.pr ? `${card.links.pr}/files` : null);
@@ -37,7 +39,7 @@ export const LandedCard: React.FC<{ card: Landed; reviews?: ReviewCard[]; onOpen
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">
+ <article data-dev-card="landed" data-repo={card.repo ?? undefined} 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" />}
@@ -46,6 +48,12 @@ export const LandedCard: React.FC<{ card: Landed; reviews?: ReviewCard[]; onOpen
)}
<div className="flex flex-wrap items-center gap-1.5">
{card.area && <span className="kw-chip">{card.area}</span>}
+ {repoChip && (
+ <span data-dev-card-repo className="kw-chip font-mono [overflow-wrap:anywhere]" title={repoChip}>
+ <span className="sr-only">Repo {repoChip}</span>
+ <span aria-hidden="true">{repoChip.replace(/\/+$/, '').split('/').pop() || repoChip}</span>
+ </span>
+ )}
<Sha sha={card.sha} />
{pr !== null ? (
card.links.pr ? (
@@ -202,7 +210,7 @@ export const LandedCard: React.FC<{ card: Landed; reviews?: ReviewCard[]; onOpen
</span>
<button
type="button"
- onClick={() => onOpenReview(pr)}
+ onClick={() => onOpenReview(pr, card.repo)}
className="kw-focus inline-flex min-h-[44px] items-center rounded text-sky-300 hover:text-sky-200 hover:underline sm:min-h-0"
>
Open review
@@ -229,7 +237,7 @@ export const LandedCard: React.FC<{ card: Landed; reviews?: ReviewCard[]; onOpen
};
/** 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 }) => (
+export const LandedList: React.FC<LandedListProps> = ({ cards, reviews, now = Date.now(), onOpenReview, forge = null, repoLabel }) => (
<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">
@@ -238,7 +246,7 @@ export const LandedList: React.FC<LandedListProps> = ({ cards, reviews, now = Da
<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} onRail />
+ <LandedCard key={c.id || c.pr || c.sha} card={c} reviews={reviews} onOpenReview={onOpenReview} forge={forge} repoLabel={repoLabel} onRail />
))}
</section>
))}
diff --git a/frontend/src/components/dev/ReviewCard.tsx b/frontend/src/components/dev/ReviewCard.tsx
index c6407d37..5f9eb3b3 100644
--- a/frontend/src/components/dev/ReviewCard.tsx
+++ b/frontend/src/components/dev/ReviewCard.tsx
@@ -449,7 +449,7 @@ const Stamp: React.FC<{ id: string; reviewer: string }> = ({ id, reviewer }) =>
};
/** 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, onPost, forge = null, forgeLogin = null }) => {
+export const ReviewCard: React.FC<ReviewCardProps> = ({ card: given, onFinding, sample = false, now: fixedNow, onPost, forge = null, forgeLogin = null, repoLabel }) => {
const [card, setCard] = useState<Review>(given);
const [busy, setBusy] = useState<string | null>(null);
const [tick, setTick] = useState(() => Date.now());
@@ -505,9 +505,10 @@ export const ReviewCard: React.FC<ReviewCardProps> = ({ card: given, onFinding,
const summary = findingsSummary(card.findings);
const sec = card.security as Review['security'] & { osv?: unknown; semgrep?: unknown };
const stamp = lgtm(card) && card.reviewer ? card.reviewer.name : null;
+ const repoChip = repoLabel ? repoLabel(card.repo, card.repo_name) : null;
return (
- <article data-dev-card="review" data-pr={card.pr} aria-labelledby={headingId} className="kw-card relative min-w-0 scroll-mt-3 p-4">
+ <article data-dev-card="review" data-repo={card.repo ?? undefined} data-pr={card.pr} aria-labelledby={headingId} className="kw-card relative min-w-0 scroll-mt-3 p-4">
{stamp && <Stamp id={card.id || `pr-${card.pr}`} reviewer={stamp} />}
{/* 1. Header */}
<header className={`flex items-start gap-3 ${stamp ? 'sm:pr-32' : ''}`}>
@@ -521,6 +522,12 @@ export const ReviewCard: React.FC<ReviewCardProps> = ({ card: given, onFinding,
</h3>
{card.draft && <span className="kw-chip">Draft</span>}
{sample && <span className="kw-chip kw-chip-info">Sample PR</span>}
+ {repoChip && (
+ <span data-dev-card-repo className="kw-chip font-mono [overflow-wrap:anywhere]" title={repoChip}>
+ <span className="sr-only">Repo {repoChip}</span>
+ <span aria-hidden="true">{repoChip.replace(/\/+$/, '').split('/').pop() || repoChip}</span>
+ </span>
+ )}
</div>
<div className="mt-1 flex flex-wrap items-center gap-x-1.5 gap-y-1 text-meta text-zinc-400">
{card.branch && (
diff --git a/frontend/src/dev/types.ts b/frontend/src/dev/types.ts
index 5fa5ce34..d7aebe31 100644
--- a/frontend/src/dev/types.ts
+++ b/frontend/src/dev/types.ts
@@ -35,6 +35,10 @@ interface CardBase {
created_at: string | null;
/** §3.6 item 9: a failed card says why and keeps its rule-based parts. */
error: string | null;
+ /** 0.7.2: the repo key (`host/owner/name`, lowercased) the card came from; null from an older server. */
+ repo: string | null;
+ /** `owner/name` for the repo chip, from the card's own facts. */
+ repo_name: string | null;
}
export interface LandedCard extends CardBase {
@@ -224,9 +228,11 @@ export interface LandedListProps {
/** Epoch ms; tests and shots pass a fixed clock. */
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;
+ onOpenReview?: (pr: number, repo?: string | null) => void;
/** `forge` from GET dev_mode: names the link ("Open on GitHub"). */
forge?: Forge | null;
+ /** 0.7.2: the card's repo chip text, or null with one repo in the space (`cardRepoLabel`). */
+ repoLabel?: (repo: string | null, name?: string | null) => string | null;
}
export interface ReviewCardProps {
@@ -243,6 +249,8 @@ export interface ReviewCardProps {
forge?: Forge | null;
/** `forge_login` from GET dev_mode, for "Posts as {login}." */
forgeLogin?: string | null;
+ /** 0.7.2: the card's repo chip text, or null with one repo in the space (`cardRepoLabel`). */
+ repoLabel?: (repo: string | null, name?: string | null) => string | null;
}
export interface ReleaseNotesSheetProps {
@@ -270,6 +278,8 @@ function base(raw: Record<string, unknown>): CardBase {
status: oneOf(raw.status, STATUSES, 'ready'),
created_at: str(raw.created_at, 64),
error: str(raw.error, 400),
+ repo: str(raw.repo, 300),
+ repo_name: str(raw.repo_name, 300),
};
}
diff --git a/frontend/src/devMode.ts b/frontend/src/devMode.ts
index dd8c7301..ee3e9fd1 100644
--- a/frontend/src/devMode.ts
+++ b/frontend/src/devMode.ts
@@ -31,6 +31,33 @@ export interface DevModeState {
status: DevStatus | null;
/** 0.7.1 (flow F6): review cards new since the person last opened the Dev desk. null on an older server. */
new_reviews: number | null;
+ /** 0.7.2 (team repos, T8): every repo Dev mode watches or found, in team order. On an older server it is
+ * built from the deprecated `repo`/`branch` (and `sources`), so the desk reads one shape. */
+ repos: DevRepo[];
+}
+
+/** 0.7.2: one repo of the space, from a team (its repo link or folder) or added by hand. */
+export type RepoStatus = 'watching' | 'not_connected' | 'other_host' | 'error' | 'too_many';
+
+export interface DevRepo {
+ /** The dedupe key, `host/owner/name` lowercased. Cards carry it as `repo`; `?repo=` filters by it. */
+ key: string;
+ /** What the person reads: `owner/name` on GitHub, else the URL without userinfo. */
+ repo: string;
+ host: string | null;
+ /** The team it came from; null for a hand-added repo. */
+ team: string | null;
+ /** That team's id (api.md `team_id`), for matching the space's teams; null on an older server. */
+ team_id: string | null;
+ /** The team's repo link, its folder's remote, a folder with no remote, or typed by the person. */
+ from: SourceFrom | 'hand' | null;
+ branch: string | null;
+ status: RepoStatus;
+ poll_error: string | null;
+ polled_at: string | null;
+ last_tag: string | null;
+ /** Only `hand` rows can be removed. null: no row (other_host, too_many). */
+ added_by: 'team' | 'hand' | null;
}
/** Where a space's repo was found: a team's repo link, a git folder with a remote, or a folder with no remote. */
@@ -80,12 +107,89 @@ export function parseSources(v: unknown): DevSource[] {
return out;
}
+const REPO_STATUSES: readonly RepoStatus[] = ['watching', 'not_connected', 'other_host', 'error', 'too_many'];
+
+/** A key for a repo the server sent no key for (an older server): `host/owner/name`, lowercased. */
+export const repoKey = (repo: string, host: string | null = 'github.com'): string => {
+ const r = stripUserinfo(repo)
+ .replace(/^[a-z][a-z0-9+.-]*:\/\//i, '')
+ .replace(/^[\w.-]+@([\w.-]+):/, '$1/')
+ .replace(/\.git$/i, '')
+ .replace(/\/+$/, '');
+ return (/^[^/]+\.[^/]+\//.test(r) ? r : `${host ?? 'local'}/${r}`).toLowerCase();
+};
+
+export function parseRepos(v: unknown): DevRepo[] {
+ if (!Array.isArray(v)) return [];
+ const out: DevRepo[] = [];
+ const seen = new Set<string>();
+ for (const x of v) {
+ if (!x || typeof x !== 'object') continue;
+ const o = x as Record<string, unknown>;
+ const repoRaw = str(o.repo);
+ const status = REPO_STATUSES.includes(o.status as RepoStatus) ? (o.status as RepoStatus) : null;
+ if (!repoRaw || !status) continue;
+ const repo = stripUserinfo(repoRaw);
+ const host = str(o.host);
+ const key = (str(o.key) ?? repoKey(repo, host)).toLowerCase();
+ if (seen.has(key)) continue;
+ seen.add(key);
+ const from = o.from === 'repo' || o.from === 'folder' || o.from === 'local' || o.from === 'hand' ? o.from : null;
+ const team = str(o.team);
+ out.push({
+ key,
+ repo,
+ host,
+ team,
+ team_id: str(o.team_id),
+ from,
+ branch: str(o.branch),
+ status,
+ poll_error: str(o.poll_error),
+ polled_at: str(o.polled_at),
+ last_tag: str(o.last_tag),
+ // A 0.7.1 row migrated without a team reads as hand (api.md T2).
+ added_by: o.added_by === 'hand' || o.added_by === 'migrated' || (from === 'hand' && o.added_by !== 'team') ? 'hand' : o.added_by === 'team' ? 'team' : null,
+ });
+ }
+ return out;
+}
+
+/** An older server (0.7.1) has no `repos`: one row from the deprecated `repo`/`branch`, or the found source. */
+function legacyRepos(o: Record<string, unknown>, sources: DevSource[], status: DevStatus | null): DevRepo[] {
+ const r = str(o.repo);
+ const repo = r ? stripUserinfo(r) : null;
+ const src = repo ? sources.find((x) => x.repo.toLowerCase() === repo.toLowerCase()) ?? null : status === 'not_connected' || status === 'other_host' ? sources.find((x) => status !== 'other_host' || (x.host && x.host !== 'github.com')) ?? sources[0] ?? null : null;
+ const name = repo ?? src?.repo ?? null;
+ if (!name) return [];
+ const st: RepoStatus = status === 'not_connected' || status === 'other_host' ? status : src?.from === 'local' ? 'other_host' : 'watching';
+ return [
+ {
+ key: repoKey(name, src?.host ?? 'github.com'),
+ repo: name,
+ host: src?.host ?? null,
+ team: src?.team ?? null,
+ team_id: null,
+ from: src?.from ?? null,
+ branch: str(o.branch),
+ status: st,
+ poll_error: str(o.poll_error),
+ polled_at: str(o.polled_at),
+ last_tag: null,
+ // An older server has no DELETE route: its typed repo has no Remove.
+ added_by: src ? 'team' : null,
+ },
+ ];
+}
+
const hint = (v: unknown): DeployHint => (v === 'docker' || v === 'cloudflare_pages' || v === 'fly' ? v : null);
export function parseDevMode(raw: unknown): DevModeState | null {
if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return null;
const o = raw as Record<string, unknown>;
if (typeof o.on !== 'boolean') return null;
+ const sources = parseSources(o.sources);
+ const status = STATUSES.includes(o.status as DevStatus) ? (o.status as DevStatus) : null;
return {
on: o.on,
repo: (() => {
@@ -102,12 +206,13 @@ export function parseDevMode(raw: unknown): DevModeState | null {
calls_cap: num(o.calls_cap),
forge: forgeOf(o.forge),
forge_login: str(o.forge_login),
- sources: parseSources(o.sources),
- status: STATUSES.includes(o.status as DevStatus) ? (o.status as DevStatus) : null,
+ sources,
+ status,
new_reviews: (() => {
const n = num(o.new_reviews);
return n === null ? null : Math.max(0, Math.floor(n));
})(),
+ repos: Array.isArray(o.repos) ? parseRepos(o.repos) : legacyRepos(o, sources, status),
};
}
@@ -125,51 +230,211 @@ export function parseCheck(raw: unknown): RepoCheck | null {
return { state: o.state, repo: str(o.repo), branch: str(o.branch), deploy_hint: hint(o.deploy_hint) };
}
-/** The source Dev mode is watching: the one whose repo is the space's repo. */
-export const watchedSource = (s: DevModeState): DevSource | null => (s.repo ? s.sources.find((x) => x.repo.toLowerCase() === s.repo!.toLowerCase()) ?? null : null);
+/** A team of the space, for "Link a repo" on a team that has none. */
+export interface DevTeamRef {
+ id: string;
+ name: string;
+}
-export interface StatusLine {
- status: DevStatus;
- /** Plain text for the line; `{repo}` parts are marked so the view can set them in mono. */
- parts: Array<{ text: string; mono?: boolean }>;
- /** The one action on the line, if any: Switch (several repos), Connect GitHub, or Type a repo. */
- action: 'switch' | 'connect' | 'type' | null;
+export type RowAction = 'connect' | 'link' | 'remove';
+export type Led = 'ok' | 'warn' | 'bad' | 'off';
+
+/**
+ * What Undo sends after a repo left the list (Ada's answer 5): a team's link comes back as that team's
+ * link (`{repo, team}`), never as a hand row; a hand row comes back as `{repo}`.
+ */
+export interface RemovedRepo {
+ /** The repo as it was: a team's link URL, or the hand row's repo. */
+ repo: string;
+ /** The team whose link was cleared (its id, for the PUT); null for a hand row. */
+ team: string | null;
+ /** That team's name, for the toast. */
+ teamName?: string | null;
+}
+export const undoBody = (r: RemovedRepo): { repo: string; team: string | null } => ({ repo: r.repo, team: r.team });
+
+/** One row of the Dev desk's repo list: a repo, or a team with no repo yet. */
+export interface RepoRow {
+ /** The repo key, or `team:{id}` for a team with none. */
+ id: string;
+ team: string | null;
+ teamId: string | null;
+ repo: DevRepo | null;
+ /** The row's status words (Mira's spec §6). */
+ state: string;
+ /** The row's second line: "From {team}'s repo link", "From {team}'s folder" or "Added by you". */
+ origin: string | null;
+ /** A team's repo can't be removed here: the info note says where to change it. */
+ teamNote: string | null;
+ /** Tooltip for an error row: the poll error, URLs without their userinfo. */
+ title: string | null;
+ led: Led;
+ /** The row's one action, or null. */
+ action: RowAction | null;
}
-/** The Dev desk header's one status line: Mira's signed-off copy (style-v2 §4). null on an older server. */
-export function statusLine(s: DevModeState | null): StatusLine | null {
- if (!s || !s.status) return null;
- const many = s.sources.length > 1;
- switch (s.status) {
+/** "14:32", 24-hour local time: the desk header's "Checked" format, shared by the repo rows. */
+export function checkedLabel(ms: number): string {
+ const d = new Date(ms);
+ return `${String(d.getHours()).padStart(2, '0')}:${String(d.getMinutes()).padStart(2, '0')}`;
+}
+
+/** A repo row's poll time in the header's format ("15:30"), or null. */
+export const checkedTime = (iso: string | null): string | null => {
+ const t = iso ? Date.parse(iso) : NaN;
+ return Number.isFinite(t) ? checkedLabel(t) : null;
+};
+
+/** A poll error for a tooltip: never a URL with a token in it. */
+export const safeError = (e: string | null): string | null => (e ? e.replace(/([a-z][a-z0-9+.-]*:\/\/)[^\s/@]+@/gi, '$1') : null);
+
+export const TOO_MANY = 'Not watched: 10 repos is the limit';
+export const NEEDS_GITHUB = 'Needs your GitHub connection';
+export const CANT_READ = 'Can’t read it right now. Trying again.';
+export const LOCAL_ONLY = 'Local folder, no remote';
+export const hostNotRead = (host: string | null) => `${host ?? 'This host'} isn’t read yet`;
+export const teamNoteText = (team: string, from: DevRepo['from']) =>
+ from === 'folder' ? `Comes from ${team}’s folder. Change it in the team’s settings.` : `Comes from ${team}’s repo link. Change it in the team’s settings.`;
+export const removedText = (repo: string) => `Stopped watching ${repo}. Its cards stay.`;
+/** Mira's copy (0.7.2): the toast after a team's repo link was cleared, with Undo. */
+export const clearedText = (team: string) => `Cleared ${team}’s repo link.`;
+/** The Remove and Clear toasts stay this long unless the person is on them (Ada's addendum: 5 s). */
+export const UNDO_TOAST_MS = 5000;
+export const LINK_HELP = 'Saved as this team’s repo link. Bots only read it.';
+export const LINK_HELP_HAND = 'Added by you. Bots only read it.';
+export const LINK_ERROR = 'Couldn’t find that repo. Check the name, or connect GitHub first.';
+export const LINK_PLACEHOLDER = 'owner/name or its URL';
+/** Ada's answer 2 with Mira's copy (0.7.2): with Dev mode off a `watching` repo isn't watched yet: a neutral chip. */
+export const READY = 'Will watch';
+export const READY_TITLE = 'Will watch when Dev mode is on';
+export const DEV_OFF = 'Dev mode is off';
+
+const rowState = (r: DevRepo, on = true): { state: string; led: Led } => {
+ if (r.from === 'local') return { state: LOCAL_ONLY, led: 'off' };
+ switch (r.status) {
case 'watching': {
- const src = watchedSource(s);
- if (src?.from === 'local')
- return {
- status: 'watching',
- parts: [{ text: `${src.team}’s folder has a local repo with no remote. It’s read from the next update. The floor and guards are on now.` }],
- action: many ? 'switch' : null,
- };
- const parts: StatusLine['parts'] = [{ text: 'Watching ' }, { text: s.repo ?? '', mono: true }, { text: ' on ' }, { text: s.branch || 'main', mono: true }];
- if (many) parts.push({ text: ` · 1 of ${s.sources.length} repos found` });
- else if (src) parts.push({ text: src.from === 'repo' ? ` · from ${src.team}’s repo link` : ` · from ${src.team}’s folder` });
- return { status: 'watching', parts, action: many ? 'switch' : null };
- }
- case 'not_connected': {
- const repo = s.repo || s.sources[0]?.repo;
- const parts: StatusLine['parts'] = repo ? [{ text: 'Found ' }, { text: repo, mono: true }, { text: '. Reviews need your GitHub connection.' }] : [{ text: 'Reviews need your GitHub connection.' }];
- return { status: 'not_connected', parts, action: 'connect' };
- }
- case 'other_host': {
- const src = watchedSource(s) ?? s.sources.find((x) => x.host && x.host !== 'github.com') ?? null;
- const repo = s.repo || src?.repo;
- const host = src?.host ?? null;
- const parts: StatusLine['parts'] = repo ? [{ text: 'Found ' }, { text: repo, mono: true }, { text: '. ' }] : [];
- parts.push(...(host ? [{ text: 'Repos on ' }, { text: host, mono: true }, { text: ' are read from the next update. The floor and guards are on now.' }] : [{ text: 'Repos on this host are read from the next update. The floor and guards are on now.' }]));
- return { status: 'other_host', parts, action: many ? 'switch' : null };
+ if (!on) return { state: READY, led: 'off' };
+ const t = checkedTime(r.polled_at);
+ return { state: t ? `Watching · checked ${t}` : 'Watching', led: 'ok' };
}
+ case 'not_connected':
+ return { state: NEEDS_GITHUB, led: 'warn' };
+ case 'other_host':
+ return { state: hostNotRead(r.host), led: 'off' };
+ case 'error':
+ return { state: CANT_READ, led: 'bad' };
default:
- return { status: 'no_repo', parts: [{ text: 'No git repo in this space’s folders yet. The floor and guards are on.' }], action: 'type' };
+ return { state: TOO_MANY, led: 'off' };
}
+};
+
+const rowOrigin = (r: DevRepo): string | null =>
+ r.added_by === 'hand' ? 'Added by you' : r.team && r.from === 'repo' ? `From ${r.team}’s repo link` : r.team && r.from === 'folder' ? `From ${r.team}’s folder` : null;
+
+/** A row's one action: Connect GitHub when the repo needs it, else Remove for a hand-added repo. */
+const rowAction = (r: DevRepo): RowAction | null => (r.status === 'not_connected' ? 'connect' : r.added_by === 'hand' ? 'remove' : null);
+
+/** Does this team bring a repo (a watched one, or one found in its folder)? */
+const teamHasRepo = (s: DevModeState, t: DevTeamRef) => s.repos.some((r) => r.team_id === t.id || r.team === t.name) || s.sources.some((x) => x.team === t.name);
+
+/** The space's teams with no repo at all. */
+export const teamsWithoutRepo = (s: DevModeState | null, teams: DevTeamRef[] = []): DevTeamRef[] => (s ? teams.filter((t) => !teamHasRepo(s, t)) : []);
+
+const repoRow = (r: DevRepo, teams: DevTeamRef[], on = true): RepoRow => ({
+ id: r.key,
+ team: r.team,
+ teamId: r.team_id ?? teams.find((t) => t.name === r.team)?.id ?? null,
+ repo: r,
+ ...rowState(r, on),
+ origin: rowOrigin(r),
+ teamNote: r.added_by !== 'hand' && r.team && (r.from === 'repo' || r.from === 'folder') ? teamNoteText(r.team, r.from) : null,
+ title: r.status === 'error' ? safeError(r.poll_error) : null,
+ action: rowAction(r),
+});
+
+const noRepoRow = (t: DevTeamRef): RepoRow => ({ id: `team:${t.id}`, team: t.name, teamId: t.id, repo: null, state: 'No repo', origin: null, teamNote: null, title: null, led: 'off', action: 'link' });
+
+/**
+ * The Dev desk's repo list (0.7.2, spec §6 and §9b): one row per repo in team order. Teams with no repo
+ * get their own "No repo" row only while no repo is watched at all; otherwise they fold into one quiet line.
+ */
+export function repoRows(s: DevModeState | null, teams: DevTeamRef[] = []): RepoRow[] {
+ if (!s) return [];
+ const rows = s.repos.map((r) => repoRow(r, teams, s.on));
+ if (!s.repos.some((r) => r.status === 'watching')) rows.push(...teamsWithoutRepo(s, teams).map(noRepoRow));
+ return rows;
+}
+
+/** Past this many rows the list folds behind "Watching N repos". */
+export const LIST_OPEN_MAX = 3;
+
+export interface StatusLine {
+ status: DevStatus | RepoStatus;
+ /** Plain text for the line; `{repo}` parts are marked so the view can set them in mono. */
+ parts: Array<{ text: string; mono?: boolean; branch?: boolean }>;
+ /** The line's one action (a single row): Connect GitHub, Link a repo, or Remove. */
+ action: RowAction | null;
+ led: Led;
+ /** Two rows or more: the list under the line. */
+ rows: RepoRow[];
+ /** More than LIST_OPEN_MAX rows: the list starts folded behind the line. */
+ collapsed: boolean;
+ /** §9b: teams with no repo while some repo is watched, folded into one quiet last line. */
+ noRepoTeams: DevTeamRef[];
+}
+
+const NO_REPO = 'No git repo in this space’s folders yet. The floor and guards are on.';
+
+/** Repos that need the person: not connected or failing (spec §9b: teams with no repo never count). */
+export const needsYouCount = (s: DevModeState) => s.repos.filter((r) => r.status === 'not_connected' || r.status === 'error').length;
+
+/** The summary over several repos: "Watching 4 repos", or "Watching 3 of 4 repos · 1 needs you". */
+export function reposSummary(s: DevModeState): string {
+ const total = s.repos.length;
+ const n = s.repos.filter((r) => r.status === 'watching' && r.from !== 'local').length;
+ if (!total) return 'No repos yet';
+ const need = needsYouCount(s);
+ // Off (answer 2): the same count reads as ready, never as watched.
+ const head = !s.on
+ ? n === total
+ ? `Will watch ${n} ${n === 1 ? 'repo' : 'repos'}`
+ : `Will watch ${n} of ${total} repos`
+ : n === total
+ ? `Watching ${n} ${n === 1 ? 'repo' : 'repos'}`
+ : `Watching ${n} of ${total} repos`;
+ return need ? `${head} · ${need} ${need === 1 ? 'needs' : 'need'} you` : head;
+}
+
+/** "1 team has no repo", "3 teams have no repo". */
+export const noRepoTeamsText = (n: number) => (n === 1 ? '1 team has no repo' : `${n} teams have no repo`);
+
+/** One repo as a single line, as in 0.7.1: "Watching demo-org/app · main". */
+function singleLine(r: DevRepo, on = true): Omit<StatusLine, 'rows' | 'collapsed' | 'noRepoTeams'> {
+ const { state, led } = rowState(r, on);
+ const action = rowAction(r);
+ if (r.status === 'watching' && r.from !== 'local' && !on)
+ return { status: 'watching', led, action, parts: [{ text: r.repo, mono: true }, { text: ' · ' }, { text: r.branch || 'main', mono: true, branch: true }, { text: ` · ${READY}` }] };
+ if (r.status === 'watching' && r.from !== 'local')
+ return { status: 'watching', led, action, parts: [{ text: 'Watching ' }, { text: r.repo, mono: true }, { text: ' · ' }, { text: r.branch || 'main', mono: true, branch: true }] };
+ return { status: r.status, led, action, parts: [{ text: r.repo, mono: true }, { text: ` · ${state}` }] };
+}
+
+/** The Dev desk's status: one line for one repo (as in 0.7.1), a list for several. null on a server older than 0.7.1. */
+export function statusLine(s: DevModeState | null, teams: DevTeamRef[] = []): StatusLine | null {
+ if (!s || !s.status) return null;
+ const rows = repoRows(s, teams);
+ const noRepoTeams = s.repos.some((r) => r.status === 'watching') ? teamsWithoutRepo(s, teams) : [];
+ // GitHub isn't connected and no repo was read yet: Connect first, as in 0.7.1.
+ if (rows.length === 0 && s.status === 'not_connected')
+ return { status: 'not_connected', parts: [{ text: 'Reviews need your GitHub connection.' }], action: 'connect', led: 'warn', rows: [], collapsed: false, noRepoTeams };
+ if (rows.length === 0) return { status: 'no_repo', parts: [{ text: NO_REPO }], action: 'link', led: 'off', rows: [], collapsed: false, noRepoTeams };
+ if (rows.length === 1) {
+ const r = rows[0];
+ if (!r.repo) return { status: 'no_repo', parts: [{ text: NO_REPO }], action: 'link', led: 'off', rows: [], collapsed: false, noRepoTeams };
+ return { ...singleLine(r.repo, s.on), rows: [], collapsed: false, noRepoTeams };
+ }
+ const led: Led = rows.some((r) => r.led === 'bad') ? 'bad' : rows.some((r) => r.led === 'warn') ? 'warn' : rows.some((r) => r.led === 'ok') ? 'ok' : 'off';
+ return { status: s.status, parts: [{ text: reposSummary(s) }], action: null, led, rows, collapsed: rows.length > LIST_OPEN_MAX, noRepoTeams };
}
/** The toast after the switch turns Dev mode on (flow F3, Mira's flow copy §3). `action` is the
@@ -189,19 +454,22 @@ const GUARDS = 'Dev mode on · guards are up';
export function onToast(s: DevModeState | null): OnToast {
if (!s?.status) return { title: ON, body: [{ text: 'Looking for a git repo in your teams’ folders…' }], action: 'open', checking: true };
- const src = watchedSource(s);
switch (s.status) {
- case 'watching':
- if (src?.from === 'local')
- return { title: GUARDS, body: [{ text: `${src.team}’s folder has a local repo with no remote. The floor works now.` }], action: 'open', checking: false };
+ case 'watching': {
+ const watched = s.repos.filter((r) => r.status === 'watching');
+ const first = watched[0] ?? s.repos.find((r) => r.from === 'local') ?? null;
+ if (watched.length > 1) return { title: ON, body: [{ text: `${reposSummary(s)}.` }], action: 'open', checking: false };
+ if (first?.from === 'local')
+ return { title: GUARDS, body: [{ text: `${first.team ?? 'This team'}’s folder has a local repo with no remote. The floor works now.` }], action: 'open', checking: false };
return {
title: ON,
- body: [{ text: 'Watching ' }, { text: s.repo ?? '', mono: true }, { text: ' on ' }, { text: s.branch || 'main', mono: true }, { text: '.' }],
+ body: [{ text: 'Watching ' }, { text: first?.repo ?? s.repo ?? '', mono: true }, { text: ' on ' }, { text: first?.branch || s.branch || 'main', mono: true }, { text: '.' }],
action: 'open',
checking: false,
};
+ }
case 'not_connected': {
- const repo = s.repo || s.sources[0]?.repo;
+ const repo = s.repos.find((r) => r.status === 'not_connected')?.repo ?? s.repo ?? s.sources[0]?.repo;
return {
title: GUARDS,
body: repo ? [{ text: 'Found ' }, { text: repo, mono: true }, { text: '. Connect GitHub to get reviews.' }] : [{ text: 'Connect GitHub to get reviews.' }],
@@ -210,7 +478,7 @@ export function onToast(s: DevModeState | null): OnToast {
};
}
case 'other_host': {
- const host = (src ?? s.sources.find((x) => x.host && x.host !== 'github.com'))?.host;
+ const host = s.repos.find((r) => r.status === 'other_host' && r.host)?.host ?? s.sources.find((x) => x.host && x.host !== 'github.com')?.host;
return {
title: GUARDS,
body: host ? [{ text: host, mono: true }, { text: ' repos are read from the next update. The floor works now.' }] : [{ text: 'Repos on this host are read from the next update. The floor works now.' }],
@@ -223,9 +491,51 @@ export function onToast(s: DevModeState | null): OnToast {
}
}
+// ---------------------------------------------------------------------------
+// Repo chips and filters on the cards (0.7.2)
+
+/** The short name on a filter chip: the repo's last part ("app"), or owner/name when two share it. */
+export function repoFilters(s: DevModeState | null): Array<{ key: string; label: string; repo: string }> {
+ const list = (s?.repos ?? []).filter((r) => r.status !== 'too_many' && r.status !== 'other_host');
+ if (list.length < 2) return [];
+ const short = (r: DevRepo) => r.repo.replace(/\/+$/, '').split('/').pop() || r.repo;
+ const counts = new Map<string, number>();
+ for (const r of list) counts.set(short(r).toLowerCase(), (counts.get(short(r).toLowerCase()) ?? 0) + 1);
+ return list.map((r) => ({ key: r.key, repo: r.repo, label: (counts.get(short(r).toLowerCase()) ?? 0) > 1 ? r.repo.replace(/^[a-z][a-z0-9+.-]*:\/\/[^/]+\//i, '') : short(r) }));
+}
+
+/** The chip on a card: its repo's `owner/name`, only when the space has more than one repo.
+ * The card's own `repo_name` wins (api.md: a removed repo keeps its label). */
+export function cardRepoLabel(s: DevModeState | null, key: unknown, name?: unknown): string | null {
+ if (!s || s.repos.length < 2 || typeof key !== 'string' || !key.trim()) return null;
+ if (typeof name === 'string' && name.trim()) return stripUserinfo(name.trim());
+ return cardRepoFull(s, key);
+}
+
+/** spec §6: the chip says the repo name only ("app"); its title is owner/name. */
+export const shortRepo = (full: string) => full.replace(/\/+$/, '').split('/').pop() || full;
+
+function cardRepoFull(s: DevModeState, key: string): string {
+ const k = key.toLowerCase();
+ const r = s.repos.find((x) => x.key === k);
+ if (r) return r.repo;
+ // A card from a repo no team points at any more keeps its label: the key without its host.
+ const parts = stripUserinfo(key).split('/');
+ return parts.length > 2 && parts[0].includes('.') ? parts.slice(1).join('/') : key;
+}
+
+/** Cards of one repo; an older server that ignores `?repo=` still shows only that repo's cards. */
+export const cardsOfRepo = <T extends object>(cards: T[], key: string | null): T[] =>
+ key
+ ? cards.filter((c) => {
+ const r = (c as { repo?: unknown }).repo;
+ return typeof r !== 'string' || r.toLowerCase() === key;
+ })
+ : cards;
+
export const onToastText = (t: OnToast) => `${t.title}. ${t.body.map((p) => p.text).join('')}`;
-/** The typed repo in the Switch list: a GitHub `owner/name` or URL, or any git URL with its userinfo dropped. */
+/** A typed repo (Link a repo): a GitHub `owner/name` or URL, or any git URL with its userinfo dropped. */
export function typedRepo(input: string): string | null {
const gh = normaliseRepo(input);
if (gh) return gh;
@@ -526,7 +836,7 @@ export const approvalsWord = (a: string | undefined) => (a === 'off' ? 'Off' : a
// API
export class DevModeError extends Error {
- constructor(message: string, public status: number) {
+ constructor(message: string, public status: number, public code: string | null = null) {
super(message);
}
}
@@ -548,7 +858,8 @@ async function call<T>(url: string, method = 'GET', body?: unknown, send: typeof
const err = data && typeof data === 'object' ? (data as Record<string, unknown>).error : null;
if (res.status === 403) throw new DevModeError('Only the space owner can change Dev mode.', 403);
if (res.status === 404 && !err) throw new DevModeError('This server doesn’t have Dev mode yet. Update the app.', 404);
- throw new DevModeError(typeof err === 'string' && err.trim() ? err : `Something went wrong (HTTP ${res.status}).`, res.status);
+ const code = data && typeof data === 'object' && typeof (data as Record<string, unknown>).code === 'string' ? ((data as Record<string, unknown>).code as string) : null;
+ throw new DevModeError(typeof err === 'string' && err.trim() ? err : `Something went wrong (HTTP ${res.status}).`, res.status, code);
}
const enc = encodeURIComponent;
@@ -567,15 +878,25 @@ export const devApi = {
return s;
},
/**
- * PUT with a typed repo (Juno, 0.7.1): a repo that can't be read still turns Dev mode on, with no
- * repo, and the reply's `check` says why. Returns the state and that reason (null when it's watched).
+ * 0.7.2 (T8): `PUT {repo, team}` sets that team's repo link; `PUT {repo}` with no team adds a repo by
+ * hand. A repo that can't be read still keeps Dev mode on, and the reply's `check` says why.
+ * Linking never changes Dev mode: it sends the space's current `on` (Ada, 0.7.2). The server defaults a
+ * missing `on` to the current value, so with no known state it is left out.
*/
- async putRepo(space: string, body: { on: true; repo: string; branch?: string | null }): Promise<{ state: DevModeState; refused: string | null }> {
- const r = await call<unknown>(`/api/spaces/${enc(space)}/dev_mode`, 'PUT', body);
+ async linkRepo(space: string, body: { repo: string; team?: string | null; on?: boolean | null }): Promise<{ state: DevModeState; refused: string | null }> {
+ const on = body.on ?? devStore.get(space)?.on;
+ const r = await call<unknown>(`/api/spaces/${enc(space)}/dev_mode`, 'PUT', { ...(on != null ? { on } : {}), repo: body.repo, ...(body.team ? { team: body.team } : {}) });
const s = parseDevMode(r.data);
if (!s) throw new DevModeError('The server sent Dev mode in a shape this app doesn’t know.', 500);
const c = parseCheck((r.data as Record<string, unknown>).check);
- return { state: s, refused: s.repo ? null : putRefusal(c, body.repo) };
+ return { state: s, refused: c && c.state !== 'found' ? putRefusal(c, body.repo) : null };
+ },
+ /** 0.7.2 (T8): removes a hand-added repo (409 for a team's repo: change the team instead). Returns the new state. */
+ async removeRepo(space: string, key: string): Promise<DevModeState> {
+ const r = await call<unknown>(`/api/spaces/${enc(space)}/dev_mode/repos/${enc(key)}`, 'DELETE');
+ const s = parseDevMode(r.data);
+ if (s) return s;
+ return devApi.get(space);
},
async check(space: string, repo: string): Promise<RepoCheck> {
const r = await call<unknown>(`/api/spaces/${enc(space)}/dev_mode/check`, 'POST', { repo });
@@ -583,19 +904,20 @@ export const devApi = {
if (!c) throw new DevModeError('The server sent a repo check this app doesn’t know.', 500);
return c;
},
- landed: (space: string, before?: string) =>
- call<unknown>(`/api/spaces/${enc(space)}/dev/landed?limit=30${before ? `&before=${enc(before)}` : ''}`).then((r) => r.data),
+ landed: (space: string, before?: string, repo?: string | null) =>
+ call<unknown>(`/api/spaces/${enc(space)}/dev/landed?limit=30${before ? `&before=${enc(before)}` : ''}${repo ? `&repo=${enc(repo)}` : ''}`).then((r) => r.data),
seen: (space: string) => call<{ seen_at: string }>(`/api/spaces/${enc(space)}/dev/landed/seen`, 'POST').then((r) => r.data),
/** Flow F6 (Juno): the person opened the Dev desk, so new_reviews goes back to 0 on every device. */
deskSeen: (space: string) => call<unknown>(`/api/spaces/${enc(space)}/dev_mode/seen`, 'POST').then((r) => r.data),
- reviews: (space: string) => call<unknown>(`/api/spaces/${enc(space)}/dev/reviews`).then((r) => r.data),
+ reviews: (space: string, repo?: string | null) => call<unknown>(`/api/spaces/${enc(space)}/dev/reviews${repo ? `?repo=${enc(repo)}` : ''}`).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),
+ /** 0.7.2: `repo` drafts that repo's notes (since its newest tag); without it, the first watched repo's. */
+ releaseNotes: (space: string, repo?: string | null) => call<unknown>(`/api/spaces/${enc(space)}/dev/release_notes${repo ? `?repo=${enc(repo)}` : ''}`, 'POST').then((r) => r.data),
production: (connection: string, space: string, production: boolean) =>
call<{ id: string; production: boolean }>(`/api/connections/${enc(connection)}/production?space=${enc(space)}`, 'PUT', { production }).then((r) => r.data),
};
@@ -610,11 +932,13 @@ export async function turnDevMode(space: string, on: boolean, put: typeof devApi
return s;
}
-/** What the desk should open with once it mounts: the Switch list with "Type a repo" focused. */
-const deskIntents = new Map<string, 'type'>();
+/** What the desk should open with once it mounts: the Link a repo field, focused (the toast's "Type a repo",
+ * the header's "Link a repo"), or the repo list expanded and in view (the header's "See repos"). */
+export type DeskIntent = 'type' | 'repos';
+const deskIntents = new Map<string, DeskIntent>();
export const deskIntent = {
- set: (space: string, what: 'type') => void deskIntents.set(space, what),
- take(space: string): 'type' | null {
+ set: (space: string, what: DeskIntent) => void deskIntents.set(space, what),
+ take(space: string): DeskIntent | null {
const v = deskIntents.get(space) ?? null;
deskIntents.delete(space);
return v;
@@ -717,6 +1041,7 @@ export const emptyState = (): DevModeState => ({
sources: [],
status: null,
new_reviews: null,
+ repos: [],
});
// ---------------------------------------------------------------------------
diff --git a/frontend/src/styles/devStatus.css b/frontend/src/styles/devStatus.css
index a07a13f8..e7a4cb98 100644
--- a/frontend/src/styles/devStatus.css
+++ b/frontend/src/styles/devStatus.css
@@ -1,4 +1,4 @@
-/* Dev desk status line, Switch list and first-run intro (0.7.1, any-git S5, Pixel).
+/* Dev desk status line, repo list (0.7.2) and first-run intro (0.7.1, any-git S5, Pixel).
Calm by default: one soft radar ping while watching, a caret that blinks four times, both gone
under reduced motion. Colours by status: watching teal (ok), not connected amber (warn, it needs you),
next update and no repo violet/zinc (nothing to do). Text is zinc-300 or brighter on the raised
@@ -34,47 +34,6 @@
.kw-dv-status-btn-primary { color: #fff; border-color: transparent; background-image: linear-gradient(135deg, #7a62f0 0%, #5b47d6 100%); }
.kw-dv-status-btn-primary:hover:not(:disabled) { filter: brightness(1.08); }
-.kw-dv-picker {
- position: absolute;
- right: 16px;
- top: calc(100% + 6px);
- z-index: 30;
- width: min(340px, calc(100vw - 32px));
- padding: 10px 8px 6px;
- border-radius: 16px;
- border: 1px solid rgb(255 255 255 / 0.14);
- background: var(--kw-surface-overlay);
- box-shadow: 0 12px 32px rgb(6 3 20 / 0.55);
- animation: kw-dv-picker-in 150ms var(--kw-ease) both;
-}
-@keyframes kw-dv-picker-in {
- from { opacity: 0; transform: translateY(-4px); }
- to { opacity: 1; transform: none; }
-}
-.kw-dv-pick {
- display: flex;
- align-items: center;
- gap: 10px;
- width: 100%;
- min-height: 44px;
- padding: 6px 8px;
- border-radius: 11px;
- border: 1px solid transparent;
- transition: background-color 140ms var(--kw-ease), border-color 140ms var(--kw-ease);
-}
-.kw-dv-pick:hover:not(:disabled) { background: rgb(255 255 255 / 0.05); }
-.kw-dv-pick[aria-checked='true'] { background: linear-gradient(135deg, rgb(122 98 240 / 0.22) 0%, rgb(91 71 214 / 0.10) 100%); border-color: rgb(184 173 255 / 0.25); }
-@media (max-width: 639px) { .kw-dv-picker { left: 12px; right: 12px; width: auto; } }
-.kw-dv-pick-icon {
- flex: none;
- width: 26px;
- height: 26px;
- display: grid;
- place-items: center;
- border-radius: 8px;
- color: rgb(196 189 255);
- background: rgb(157 143 255 / 0.12);
-}
.kw-dv-picker-input {
min-width: 0;
flex: 1;
@@ -92,6 +51,47 @@
.kw-dv-picker-input:focus { border-color: rgb(56 189 248 / 0.7); }
.kw-dv-picker-input[aria-invalid='true'] { border-color: rgb(253 164 175 / 0.6); }
+/* 0.7.2 team repos: one row per repo under the status line. Rows wrap at 390 px: the cells take the
+ line, the action drops below them at 44 px. Status words are --t3 or brighter (AA on the side surface). */
+.kw-dv-disclosure {
+ display: inline-flex; align-items: center; gap: 4px; min-height: 28px; padding: 0 6px; margin-left: -6px;
+ border-radius: 7px; color: var(--t1); font-weight: 600; background: transparent; cursor: pointer;
+}
+.kw-dv-disclosure:hover { background: rgb(157 143 255 / 0.1); }
+.kw-dv-disclosure svg { transition: transform 140ms var(--kw-ease); }
+.kw-dv-repos {
+ margin: 0; padding: 4px 24px 8px; list-style: none; 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);
+}
+.kw-dv-repo + .kw-dv-repo { border-top: 1px solid var(--kw-hairline); }
+.kw-dv-repo-line { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; min-height: 40px; padding: 4px 0; }
+.kw-dv-repo-cells { flex: 1 1 240px; min-width: 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 6px; }
+.kw-dv-repo-team { color: var(--t2); font-weight: 500; }
+.kw-dv-repo-name { color: var(--t1); font-weight: 600; font-family: 'JetBrains Mono', ui-monospace, monospace; font-size: 12px; overflow-wrap: anywhere; min-width: 0; }
+.kw-dv-repo-sep { color: var(--t5); }
+.kw-dv-repo[data-s='not_connected'] .kw-dv-repo-state,
+.kw-dv-repo[data-s='error'] .kw-dv-repo-state { color: var(--dv-led-warn); }
+.kw-dv-repos .act, .kw-dv-statusline .act { flex: none; }
+.kw-dv-repos .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; }
+.kw-dv-repos .act:hover { background: rgb(157 143 255 / 0.1); }
+.kw-dv-repos .act:disabled { opacity: 0.6; cursor: progress; }
+.kw-dv-repo-form-wrap { padding: 4px 24px 8px; border-bottom: 1px solid var(--kw-hairline); }
+.kw-dv-repo-form { padding: 2px 0 6px 18px; }
+.kw-dv-repo-form-label { display: block; margin-bottom: 4px; font-size: 11.5px; font-weight: 500; color: var(--t3); }
+.kw-dv-repo-form-row { display: flex; flex-wrap: wrap; gap: 6px; }
+.kw-dv-repo-form-row .kw-dv-picker-input { flex: 1 1 200px; }
+.kw-dv-repo-form-err { min-height: 1em; margin-top: 4px; font-size: 11.5px; color: rgb(253 164 175); }
+.kw-dv-repo-err { margin: 0; padding: 0 0 6px 18px; font-size: 11.5px; color: rgb(253 164 175); }
+@media (max-width: 639px) {
+ .kw-dv-repos, .kw-dv-repo-form-wrap { padding-left: 12px; padding-right: 12px; }
+ .kw-dv-repos .act { min-height: 44px; padding: 0 12px; margin-left: 18px; }
+ .kw-dv-disclosure { min-height: 44px; }
+ .kw-dv-repo-form { padding-left: 0; }
+ .kw-dv-repo-form-row .kw-dv-status-btn { margin-left: 0; }
+}
+@media (prefers-reduced-motion: reduce) { .kw-dv-disclosure svg { transition: none; } }
+
.kw-dv-intro {
border-radius: 18px;
border: 1px dashed rgb(255 255 255 / 0.16);
@@ -163,15 +163,14 @@
.kw-dv-status { flex-wrap: wrap; }
.kw-dv-status > p { flex-basis: calc(100% - 40px); }
.kw-dv-status-btn { min-height: 44px; margin-left: 36px; }
- .kw-dv-picker { position: fixed; left: 16px; right: 16px; top: auto; bottom: calc(16px + env(safe-area-inset-bottom)); width: auto; }
}
@media (prefers-reduced-motion: reduce) {
- .kw-dv-intro-caret, .kw-dv-picker, .kw-dv-ontoast, .kw-dv-row-badge-pop { animation: none; }
+ .kw-dv-intro-caret, .kw-dv-ontoast, .kw-dv-row-badge-pop { animation: none; }
/* Reduced motion: the highlight shows for 2.8 s with no fades. */
.kw-dv-row-fresh { animation: kw-dv-row-fresh-rm 2800ms steps(1, end) 1; }
@keyframes kw-dv-row-fresh-rm { 0% { background-color: var(--kw-accent-soft, rgb(157 143 255 / 0.14)); } 100% { background-color: transparent; } }
- .kw-dv-status-btn, .kw-dv-pick { transition: none; }
+ .kw-dv-status-btn { transition: none; }
}
/* style-v2 §3: the desk header's `</>` chip (mono 12, accent on accent-soft, radius 6). */
@@ -228,3 +227,68 @@
background: var(--kw-surface-overlay);
}
@media (max-width: 639px) { .kw-dv-tab { min-height: 44px; } }
+
+/* 0.7.2: repo filter chips over both lists (All · app · site). */
+.kw-dv-filters {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 6px;
+ margin: 0 0 12px;
+}
+.kw-dv-filter {
+ min-height: 28px;
+ max-width: 100%;
+ padding: 2px 10px;
+ border: 1px solid var(--kw-hairline);
+ border-radius: 999px;
+ background: transparent;
+ color: var(--t3);
+ font-family: var(--font-mono, ui-monospace, monospace);
+ font-size: 12px;
+ overflow-wrap: anywhere;
+ cursor: pointer;
+}
+.kw-dv-filter:hover { color: var(--t1); }
+.kw-dv-filter[aria-pressed='true'] {
+ border-color: var(--accent);
+ color: var(--t1);
+ background: color-mix(in srgb, var(--accent) 14%, transparent);
+}
+@media (max-width: 639px) {
+ .kw-dv-filter { min-height: 44px; padding: 2px 14px; }
+}
+
+/* 0.7.2 final copy (dev-mode-explainer/spec.md §6, §9b): second line, team note, the quiet no-repo line
+ and the Remove toast. Muted text is --t3 (AA on the side surface); actions are --accent. */
+.kw-dv-repo-origin { margin: -4px 0 6px 18px; font-size: 12px; line-height: 18px; color: var(--t3); overflow-wrap: anywhere; }
+.kw-dv-repo-state { overflow-wrap: anywhere; }
+.kw-dv-repo[data-s='error'] .kw-dv-repo-state { color: var(--dv-led-bad); }
+/* Ada's answer 2: Dev mode off, a `watching` repo is ready, not watched. A neutral chip, never green. */
+.kw-dv-repo-state[data-tone='neutral'] {
+ display: inline-flex; align-items: center; min-height: 18px; padding: 0 7px; border-radius: 999px;
+ color: var(--t2); border: 1px solid var(--kw-hairline-strong); background: transparent; font-size: 11.5px;
+}
+.kw-dv-info {
+ flex: none; display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 7px;
+ color: var(--t4); background: transparent; cursor: pointer;
+}
+.kw-dv-info:hover, .kw-dv-info[aria-expanded='true'] { color: var(--t2); background: rgb(157 143 255 / 0.1); }
+.kw-dv-norepo, .kw-dv-removed { padding: 6px 24px 8px; border-bottom: 1px solid var(--kw-hairline); font-size: 12px; line-height: 18px; color: var(--t3); }
+.kw-dv-norepo-line { margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; }
+.kw-dv-norepo .kw-dv-repo-form { padding-left: 0; margin-top: 6px; }
+.kw-dv-norepo-act {
+ display: inline-flex; align-items: center; min-height: 24px; padding: 0 4px; margin: 0 -4px; border-radius: 6px;
+ color: var(--accent); font-weight: 600; background: transparent; cursor: pointer;
+}
+.kw-dv-norepo-act:hover { background: rgb(157 143 255 / 0.1); }
+.kw-dv-norepo-act:disabled { opacity: 0.6; cursor: progress; }
+.kw-dv-removed { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; color: var(--t2); }
+.kw-dv-repo-form-help { margin-top: 4px; font-size: 11.5px; color: var(--t3); }
+.kw-dv-repo-form-pick { margin-bottom: 8px; }
+.kw-dv-team-pick { width: 100%; max-width: 280px; font-family: inherit; }
+@media (max-width: 639px) {
+ .kw-dv-norepo, .kw-dv-removed { padding-left: 12px; padding-right: 12px; }
+ .kw-dv-info { width: 44px; height: 44px; }
+ .kw-dv-norepo-act { min-height: 44px; padding: 0 8px; }
+ .kw-dv-disclosure { min-height: 44px; }
+}
diff --git a/frontend/tests/devAutodetect.test.mjs b/frontend/tests/devAutodetect.test.mjs
index f5c12bd5..957b844e 100644
--- a/frontend/tests/devAutodetect.test.mjs
+++ b/frontend/tests/devAutodetect.test.mjs
@@ -138,39 +138,33 @@ test('typedRepo: GitHub owner/name and URLs normalise; any git URL is kept witho
const text = (l) => l.parts.map((p) => p.text).join('');
-test('watching: Mira’s copy, "Watching {repo} on {branch} · from {team}’s folder" or "’s repo link"; Switch only with several sources', () => {
+test('watching: one repo is one line, "Watching {repo} · {branch}" (spec §6); no Switch (0.7.2 watches every repo)', () => {
const one = m.statusLine(state({ status: 'watching', repo: 'demo-org/demo-web', branch: 'main', sources: [SOURCES[0]] }));
- assert.equal(text(one), 'Watching demo-org/demo-web on main · from Web’s folder');
+ assert.equal(text(one), 'Watching demo-org/demo-web · main');
assert.equal(one.action, null);
assert.deepEqual(one.parts.filter((p) => p.mono).map((p) => p.text), ['demo-org/demo-web', 'main']);
- const link = m.statusLine(state({ status: 'watching', repo: 'demo-org/demo-api', branch: 'trunk', sources: [SOURCES[1]] }));
- assert.equal(text(link), 'Watching demo-org/demo-api on trunk · from API’s repo link');
const many = m.statusLine(state({ status: 'watching', repo: 'demo-org/demo-api', branch: 'trunk', sources: SOURCES }));
- assert.equal(text(many), 'Watching demo-org/demo-api on trunk · 1 of 3 repos found');
- assert.equal(many.action, 'switch');
- const local = m.statusLine(state({ status: 'watching', repo: 'demo-docs', sources: [SOURCES[2]] }));
- assert.equal(text(local), 'Docs’s folder has a local repo with no remote. It’s read from the next update. The floor and guards are on now.');
- const typed = m.statusLine(state({ status: 'watching', repo: 'demo-org/elsewhere', branch: null, sources: [] }));
- assert.equal(text(typed), 'Watching demo-org/elsewhere on main', 'a typed repo names no team');
+ // An older server with several sources still watches its one repo: one line, no picker.
+ assert.equal(text(many), 'Watching demo-org/demo-api · trunk');
+ assert.equal(many.action, null);
});
-test('not_connected: "Found {repo}. Reviews need your GitHub connection." with Connect GitHub', () => {
+test('not_connected: "{repo} · Needs your GitHub connection" with Connect GitHub', () => {
const l = m.statusLine(state({ status: 'not_connected', repo: 'demo-org/demo-web', sources: [SOURCES[0]] }));
- assert.equal(text(l), 'Found demo-org/demo-web. Reviews need your GitHub connection.');
+ assert.equal(text(l), 'demo-org/demo-web · Needs your GitHub connection');
assert.equal(l.action, 'connect');
});
-test('other_host: "Found {repo}. Repos on {host} are read from the next update. The floor and guards are on now."', () => {
+test('other_host: "{repo} · {host} isn’t read yet", no action', () => {
const l = m.statusLine(state({ status: 'other_host', repo: 'https://gitlab.example.test/demo/app', sources: [{ team: 'Web', repo: 'https://gitlab.example.test/demo/app', host: 'gitlab.example.test', from: 'folder' }] }));
- assert.equal(text(l), 'Found https://gitlab.example.test/demo/app. Repos on gitlab.example.test are read from the next update. The floor and guards are on now.');
- assert.deepEqual(l.parts.filter((p) => p.mono).map((p) => p.text), ['https://gitlab.example.test/demo/app', 'gitlab.example.test']);
+ assert.equal(text(l), 'https://gitlab.example.test/demo/app · gitlab.example.test isn’t read yet');
assert.equal(l.action, null);
});
-test('no_repo: "No git repo in this space’s folders yet. The floor and guards are on." with Type a repo', () => {
+test('no_repo: "No git repo in this space’s folders yet. The floor and guards are on." with Link a repo', () => {
const l = m.statusLine(state({ status: 'no_repo', sources: [] }));
assert.equal(text(l), 'No git repo in this space’s folders yet. The floor and guards are on.');
- assert.equal(l.action, 'type');
+ assert.equal(l.action, 'link');
});
test('flow F3: the switch-on toast by status (Mira’s flow copy §3), with its one action', () => {
@@ -275,86 +269,74 @@ test('DOM: Connect opens Loose ends; it hides when the app gives no way there',
again.root.unmount();
});
-test('DOM: Switch opens a one-tap list; a tap sends PUT {on: true, repo} and the line follows', async () => {
- const { root } = await desk({ status: 'watching', repo: 'demo-org/demo-web', branch: 'main', sources: SOURCES });
- const sw = document.querySelector('[data-dv-status-action="switch"]');
- assert.equal(sw.getAttribute('aria-expanded'), 'false');
- await click(sw);
- assert.equal(sw.getAttribute('aria-expanded'), 'true');
- const picks = [...document.querySelectorAll('[data-dv-pick]')];
- assert.deepEqual(picks.map((p) => p.dataset.dvPick), ['demo-org/demo-web', 'demo-org/demo-api', 'demo-docs']);
- assert.equal(picks[0].getAttribute('aria-checked'), 'true');
- assert.equal(document.activeElement, picks[0], 'focus starts on the watched repo');
- assert.match(picks[1].textContent, /API’s repo link/);
- assert.match(picks[2].textContent, /Docs’s folder, no remote/);
- await click(picks[1]);
+const typeInto = async (input, v) => {
+ Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value').set.call(input, v);
+ input.dispatchEvent(new window.Event('input', { bubbles: true }));
await settle();
- assert.deepEqual(server.calls.filter(([meth]) => meth === 'PUT').map(([, , b]) => b), [{ on: true, repo: 'demo-org/demo-api' }]);
- assert.equal(document.querySelector('[data-dv-picker]'), null, 'the list closes');
- assert.equal(document.activeElement, sw, 'focus goes back to Switch');
- assert.match(document.querySelector('[data-dv-status-text]').textContent, /Watching demo-org\/demo-api on main · 1 of 3 repos found/);
- root.unmount();
-});
+};
+const submitForm = async (form) => {
+ form.dispatchEvent(new window.Event('submit', { bubbles: true, cancelable: true }));
+ await settle();
+};
-test('DOM: tapping the watched repo just closes; Esc closes; a typed git URL is watched without its userinfo', async () => {
+test('0.7.2: no repo picker. An older server with several sources shows one line and no Switch', async () => {
const { root } = await desk({ status: 'watching', repo: 'demo-org/demo-web', branch: 'main', sources: SOURCES });
- const sw = document.querySelector('[data-dv-status-action="switch"]');
- await click(sw);
- await click(document.querySelector('[data-dv-pick="demo-org/demo-web"]'));
+ assert.equal(document.querySelector('[data-dv-status-action="switch"]'), null);
assert.equal(document.querySelector('[data-dv-picker]'), null);
- assert.equal(server.calls.filter(([meth]) => meth === 'PUT').length, 0);
- await click(sw);
- document.querySelector('[data-dv-picker]').dispatchEvent(new window.KeyboardEvent('keydown', { key: 'Escape', bubbles: true }));
+ assert.equal(document.querySelectorAll('[data-dv-status]').length, 1);
+ root.unmount();
+});
+
+test('DOM: Link a repo opens a field; Esc closes it; a typed git URL is linked without its userinfo', async () => {
+ const { root } = await desk({ status: 'no_repo', sources: [] });
+ const link = document.querySelector('[data-dv-status-action="link"]');
+ assert.equal(link.textContent.trim(), 'Link a repo');
+ assert.equal(link.getAttribute('aria-expanded'), 'false');
+ await click(link);
+ assert.equal(link.getAttribute('aria-expanded'), 'true');
+ const form = document.querySelector('[data-dv-link-form="hand"]');
+ assert.equal(document.activeElement, form.querySelector('input'));
+ form.dispatchEvent(new window.KeyboardEvent('keydown', { key: 'Escape', bubbles: true }));
await settle();
- assert.equal(document.querySelector('[data-dv-picker]'), null);
- assert.equal(document.activeElement, sw);
- await click(sw);
- const input = document.querySelector('[data-dv-picker] input');
- const submit = document.querySelector('[data-dv-picker] button[type="submit"]');
- const type = async (v) => {
- Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value').set.call(input, v);
- input.dispatchEvent(new window.Event('input', { bubbles: true }));
- await settle();
- };
- await type('not a repo');
+ assert.equal(document.querySelector('[data-dv-link-form]'), null);
+ await click(link);
+ const input = document.querySelector('[data-dv-link-form] input');
+ const submit = document.querySelector('[data-dv-link-form] button[type="submit"]');
+ await typeInto(input, 'not a repo');
assert.equal(submit.disabled, true);
assert.equal(input.getAttribute('aria-invalid'), 'true');
- await type('https://demo:[email protected]/demo/app.git');
+ await typeInto(input, 'https://demo:[email protected]/demo/app.git');
assert.equal(submit.disabled, false);
- input.form.dispatchEvent(new window.Event('submit', { bubbles: true, cancelable: true }));
- await settle();
- assert.deepEqual(server.calls.filter(([meth]) => meth === 'PUT').map(([, , b]) => b), [{ on: true, repo: 'https://gitea.example.test/demo/app.git' }]);
+ await submitForm(input.form);
+ assert.deepEqual(server.calls.filter(([x]) => x === 'PUT').map(([, , b]) => b), [{ on: true, repo: 'https://gitea.example.test/demo/app.git' }]);
+ assert.ok(!document.body.textContent.includes('not-a-real-token'));
root.unmount();
});
-test('DOM: a failed switch keeps the list open with the reason', async () => {
- const { root } = await desk({ status: 'watching', repo: 'demo-org/demo-web', branch: 'main', sources: SOURCES });
+test('DOM: a failed link keeps the field open with the reason', async () => {
+ const { root } = await desk({ status: 'no_repo', sources: [] });
server.fail = 'Bots can’t read that repo.';
- await click(document.querySelector('[data-dv-status-action="switch"]'));
- await click(document.querySelector('[data-dv-pick="demo-org/demo-api"]'));
- await settle();
- assert.ok(document.querySelector('[data-dv-picker]'));
- assert.match(document.querySelector('[data-dv-picker]').textContent, /Bots can’t read that repo\./);
+ await click(document.querySelector('[data-dv-status-action="link"]'));
+ const input = document.querySelector('[data-dv-link-form] input');
+ await typeInto(input, 'demo-org/demo-api');
+ await submitForm(input.form);
+ assert.ok(document.querySelector('[data-dv-link-form]'));
+ assert.match(document.querySelector('[data-dv-link-form]').textContent, /Couldn’t find that repo\. Check the name, or connect GitHub first\./);
root.unmount();
});
-test('DOM: a typed repo the server can’t read (200, repo null, check) keeps the list open with why; Dev mode stays on', async () => {
- for (const [why, re] of [['not_found', /Couldn’t read demo-org\/nope\. .*Dev mode is on/], ['not_connected', /Connect GitHub so bots can read demo-org\/nope\./]]) {
- const { root } = await desk({ status: 'watching', repo: 'demo-org/demo-web', branch: 'main', sources: SOURCES });
+test('DOM: a typed repo the server can’t read (200, repo null, check) keeps the field open with why; Dev mode stays on', async () => {
+ for (const [why, re] of [['not_found', /Couldn’t find that repo\. Check the name, or connect GitHub first\./], ['not_connected', /Couldn’t find that repo\. Check the name, or connect GitHub first\./]]) {
+ const { root } = await desk({ status: 'no_repo', sources: [] });
server.unreadable = why;
- await click(document.querySelector('[data-dv-status-action="switch"]'));
- const input = document.querySelector('[data-dv-picker] input');
- const set = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value').set;
- set.call(input, 'demo-org/nope');
- input.dispatchEvent(new window.Event('input', { bubbles: true }));
- await settle();
- input.form.dispatchEvent(new window.Event('submit', { bubbles: true, cancelable: true }));
- await settle();
+ await click(document.querySelector('[data-dv-status-action="link"]'));
+ const input = document.querySelector('[data-dv-link-form] input');
+ await typeInto(input, 'demo-org/nope');
+ await submitForm(input.form);
assert.deepEqual(server.calls.filter(([x]) => x === 'PUT').at(-1)[2], { on: true, repo: 'demo-org/nope' });
- assert.ok(document.querySelector('[data-dv-picker]'), why);
- assert.match(document.querySelector('[data-dv-picker]').textContent, re);
+ assert.ok(document.querySelector('[data-dv-link-form]'), why);
+ assert.match(document.querySelector('[data-dv-link-form]').textContent, re);
assert.equal(m.devStore.get('spc_demo').on, true);
- assert.equal(m.devStore.get('spc_demo').repo, null);
root.unmount();
}
});
@@ -599,21 +581,14 @@ test('F4 DOM: first-visit empty states speak git and never say "Nothing has land
row.root.unmount();
});
-test('F5 DOM: no_repo’s Type a repo opens the list straight at the field; the toast’s Type a repo lands there too', async () => {
- const { root } = await desk({ status: 'no_repo', sources: [] });
- const t = document.querySelector('[data-dv-status-action="type"]');
- assert.equal(t.textContent.trim(), 'Type a repo');
- await click(t);
- const input = document.querySelector('[data-dv-picker] input');
- assert.ok(input);
- assert.equal(document.activeElement, input);
- assert.equal(document.querySelectorAll('[data-dv-pick]').length, 0);
- root.unmount();
+test('F5 DOM: the toast’s Type a repo lands on the Link a repo field, open and focused, once', async () => {
reset({ status: 'no_repo', sources: [] });
m.devStore.set('spc_demo', m.parseDevMode(server.state));
m.deskIntent.set('spc_demo', 'type');
const again = await mount(h(m.DevDeskView, { spaceId: 'spc_demo', spaceName: 'Demo' }));
- assert.ok(document.querySelector('[data-dv-picker] input'), 'opened from the toast');
+ const input = document.querySelector('[data-dv-link-form] input');
+ assert.ok(input, 'opened from the toast');
+ assert.equal(document.activeElement, input);
assert.equal(m.deskIntent.take('spc_demo'), null, 'used once');
again.root.unmount();
});
diff --git a/frontend/tests/devMode.test.mjs b/frontend/tests/devMode.test.mjs
index 5fbcbcf2..505c6ab1 100644
--- a/frontend/tests/devMode.test.mjs
+++ b/frontend/tests/devMode.test.mjs
@@ -313,6 +313,8 @@ test('DOM: on → off with two presses saves PUT {on:false}, announces, and call
assert.ok(host.querySelector('[data-dv-hint]'));
await click(b);
await click(b); // the double-click's third press: ignored while settling
+ // The save resolves on the event loop; a busy CI runner can take more than a few ticks, so wait for it
+ for (let i = 0; i < 100 && (turnedOff === 0 || !/Dev mode off for Demo/.test(host.querySelector('[data-dv-live]').textContent)); i++) await wait(20);
assert.deepEqual(
server.calls.filter(([meth]) => meth === 'PUT').map(([, , body]) => body),
[{ on: false }],
diff --git a/frontend/tests/devTeamRepos.test.mjs b/frontend/tests/devTeamRepos.test.mjs
new file mode 100644
index 00000000..12cdb4b2
--- /dev/null
+++ b/frontend/tests/devTeamRepos.test.mjs
@@ -0,0 +1,618 @@
+// 0.7.2 team repos (plan: dev-mode/plan/team-repos.md, Frontend; T8): Dev mode watches every
+// team's repo. The status line becomes a repo list, cards get a repo chip, and both lists filter
+// by repo through `?repo=`. Demo data only: demo-org/app and demo-org/site, no real repos or tokens.
+import assert from 'node:assert/strict';
+import test 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/s/spc_demo', pretendToBeVisual: true });
+const g = globalThis;
+for (const k of ['window', 'document', 'navigator', 'HTMLElement', 'HTMLInputElement', 'Element', 'Node', 'Event', 'MouseEvent', 'KeyboardEvent', 'FocusEvent', 'requestAnimationFrame', 'cancelAnimationFrame', 'getComputedStyle', 'localStorage', 'sessionStorage']) {
+ if (!(k in dom.window)) continue;
+ Object.defineProperty(g, k, { value: dom.window[k], configurable: true, writable: true });
+}
+g.IS_REACT_ACT_ENVIRONMENT = false;
+
+const APP = { key: 'github.com/demo-org/app', repo: 'demo-org/app', host: 'github.com', team: 'App', team_id: 'tm_app', from: 'folder', branch: 'main', status: 'watching', poll_error: null, polled_at: '2026-11-06T09:00:00Z', last_tag: 'v1.2.0', added_by: 'team' };
+const SITE = { key: 'github.com/demo-org/site', repo: 'demo-org/site', host: 'github.com', team: 'Site', team_id: 'tm_site', from: 'repo', branch: 'trunk', status: 'watching', poll_error: null, polled_at: '2026-11-06T09:00:00Z', last_tag: null, added_by: 'team' };
+const DOCS = { key: 'github.com/demo-org/docs', repo: 'demo-org/docs', host: 'github.com', team: null, team_id: null, from: 'hand', branch: 'main', status: 'watching', poll_error: null, polled_at: null, last_tag: null, added_by: 'hand' };
+const LAB = { key: 'gitlab.example.test/demo/lab', repo: 'https://gitlab.example.test/demo/lab', host: 'gitlab.example.test', team: 'Lab', team_id: 'tm_lab', from: 'folder', branch: null, status: 'other_host', poll_error: null, polled_at: null, last_tag: null, added_by: null };
+const base = { on: true, repo: null, branch: null, deploy_hint: null, backup_command: null, last_seen_sha: null, polled_at: null, poll_error: null, calls_today: null, calls_cap: null, sources: [], status: 'watching' };
+const TEAMS = [
+ { id: 'tm_app', name: 'App' },
+ { id: 'tm_site', name: 'Site' },
+];
+
+let server;
+g.fetch = g.window.fetch = async (url, init = {}) => {
+ const u = String(url);
+ const method = init.method ?? 'GET';
+ const body = init.body ? JSON.parse(init.body) : undefined;
+ server.calls.push([method, u, body]);
+ const json = (b, status = 200) => new Response(JSON.stringify(b), { status, headers: { 'Content-Type': 'application/json' } });
+ const path = u.split('?')[0];
+ const repoQ = new URL(u, 'http://localhost').searchParams.get('repo');
+ if (method === 'DELETE' && /\/dev_mode\/repos\//.test(path)) {
+ const key = decodeURIComponent(path.split('/dev_mode/repos/')[1]);
+ const row = server.state.repos.find((r) => r.key === key);
+ if (!row || row.added_by !== 'hand') return json({ error: 'That repo comes from a team. Change the team’s repo instead.' }, 409);
+ server.state = { ...server.state, repos: server.state.repos.filter((r) => r.key !== key) };
+ return json(server.state);
+ }
+ if (path.endsWith('/dev_mode') && method === 'PUT') {
+ if (server.fail) return json({ error: server.fail }, 422);
+ const repo = body.repo;
+ const team = [...TEAMS, { id: 'tm_mkt', name: 'Marketing' }].find((t) => t.id === body.team);
+ const row = { ...APP, key: `github.com/${repo}`.toLowerCase(), repo, team: team?.name ?? null, team_id: team?.id ?? null, from: team ? 'repo' : 'hand', added_by: team ? 'team' : 'hand', polled_at: null };
+ server.state = { ...server.state, ...(typeof body.on === 'boolean' ? { on: body.on } : {}), repos: [...server.state.repos, row] };
+ return json(server.state);
+ }
+ if (path.endsWith('/dev_mode')) return json(server.state);
+ const of = (cards) => (repoQ ? cards.filter((c) => c.repo === repoQ) : cards);
+ if (path.endsWith('/dev/landed')) return json({ cards: of(server.landed), rollup: { count: 0, areas: [] }, last_tag: null, last_merge: null });
+ if (path.endsWith('/dev/reviews')) return json({ cards: of(server.reviews) });
+ return json({});
+};
+
+const m = await loadBundled(`
+ export { default as React } from 'react';
+ export { createRoot } from 'react-dom/client';
+ export * from './src/devMode';
+ export { DevDeskView, deskStore } from './src/components/DevDesk';
+ export { DevStatusLine } from './src/components/DevStatusLine';
+ export { useDevMode } from './src/components/DevModeSwitch';
+ export * as fx from './src/dev/fixtures';
+`);
+const { React, createRoot } = m;
+const h = React.createElement;
+const settle = async (n = 10) => {
+ for (let i = 0; i < n; i++) await new Promise((r) => setTimeout(r, 0));
+};
+const click = async (el) => {
+ el.dispatchEvent(new window.MouseEvent('click', { bubbles: true }));
+ await settle();
+};
+const mount = async (el) => {
+ const host = document.createElement('div');
+ document.body.appendChild(host);
+ const root = createRoot(host);
+ root.render(el);
+ await settle();
+ return { host, root };
+};
+const state = (over) => m.parseDevMode({ ...base, ...over });
+const text = (l) => l.parts.map((p) => p.text).join('');
+const reset = (over = {}) => {
+ server = { state: { ...base, ...over }, calls: [], landed: [], reviews: [] };
+ m.devStore._reset();
+ m.deskStore._reset();
+ localStorage.clear();
+ localStorage.setItem('kwnt.dev.intro.spc_demo', '1');
+ document.body.innerHTML = '';
+};
+const line = async (over, teams = []) => {
+ reset(over);
+ const st = m.parseDevMode(server.state);
+ m.devStore.set('spc_demo', st);
+ // Live, as in the desk: the line follows the store after Link and Remove.
+ const Live = () => h(m.DevStatusLine, { spaceId: 'spc_demo', state: m.useDevMode('spc_demo') ?? st, teams, onConnect() {} });
+ return mount(h(Live));
+};
+const frame = () => new Promise((r) => setTimeout(r, 50));
+const typeInto = async (input, v) => {
+ Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value').set.call(input, v);
+ input.dispatchEvent(new window.Event('input', { bubbles: true }));
+ await settle();
+};
+// An assertion on a DOM node prints the whole tree when it fails: compare booleans and strings.
+const has = (sel) => document.querySelector(sel) !== null;
+
+// ---------------------------------------------------------------------------
+// Parsing
+
+test('parseDevMode: repos[] keep key, team, branch and status; bad rows, unknown statuses and duplicate keys drop', () => {
+ const s = state({ repos: [APP, SITE, { ...APP }, { repo: 'demo-org/x', status: 'nope' }, { status: 'watching' }, 'junk', null] });
+ assert.deepEqual(s.repos.map((r) => [r.key, r.team, r.branch, r.status, r.added_by]), [
+ ['github.com/demo-org/app', 'App', 'main', 'watching', 'team'],
+ ['github.com/demo-org/site', 'Site', 'trunk', 'watching', 'team'],
+ ]);
+});
+
+test('parseDevMode: no URL token reaches the screen from repos[]; only hand (or migrated) rows read as hand', () => {
+ const s = state({ repos: [{ repo: 'https://demo:[email protected]/demo/app.git', host: 'gitea.example.test', status: 'other_host', added_by: null }] });
+ assert.equal(s.repos[0].repo, 'https://gitea.example.test/demo/app.git');
+ assert.equal(s.repos[0].key, 'gitea.example.test/demo/app');
+ assert.equal(s.repos[0].added_by, null, 'no row: nothing to remove');
+ assert.equal(state({ repos: [{ ...DOCS, added_by: 'migrated' }] }).repos[0].added_by, 'hand');
+ assert.equal(state({ repos: [{ ...DOCS, from: 'hand' }] }).repos[0].from, 'hand');
+ assert.ok(!JSON.stringify(s).includes('not-a-real-token'));
+});
+
+test('parseDevMode: an older server (no repos[]) falls back to one row from the deprecated repo and branch', () => {
+ const s = state({ repo: 'demo-org/app', branch: 'main', sources: [{ team: 'App', repo: 'demo-org/app', host: 'github.com', from: 'folder' }] });
+ assert.equal(s.repos.length, 1);
+ assert.deepEqual([s.repos[0].key, s.repos[0].team, s.repos[0].branch, s.repos[0].status], ['github.com/demo-org/app', 'App', 'main', 'watching']);
+ assert.equal(state({ repo: 'demo-org/typed', sources: [] }).repos[0].added_by, null, 'an older server has no DELETE: no Remove');
+ assert.deepEqual(state({ status: 'no_repo' }).repos, []);
+ assert.equal(state({ repo: 'demo-org/app', repos: [] }).repos.length, 0, 'an empty repos[] wins over the old field');
+});
+
+// ---------------------------------------------------------------------------
+// The list states
+
+test('one repo: today’s single line, no list', () => {
+ const l = m.statusLine(state({ repos: [APP] }));
+ assert.equal(text(l), 'Watching demo-org/app · main');
+ assert.deepEqual(l.rows, []);
+ assert.equal(l.action, null);
+ assert.equal(l.led, 'ok');
+});
+
+test('two repos: "Watching 2 repos" over two rows, open', () => {
+ const l = m.statusLine(state({ repos: [APP, SITE] }), TEAMS);
+ assert.equal(text(l), 'Watching 2 repos');
+ assert.equal(l.collapsed, false);
+ assert.deepEqual(l.rows.map((r) => [r.team, r.repo.repo, r.repo.branch, r.state.replace(/\d\d:\d\d( [AP]M)?/, 'HH:MM'), r.origin, r.action]), [
+ ['App', 'demo-org/app', 'main', 'Watching · checked HH:MM', 'From App’s folder', null],
+ ['Site', 'demo-org/site', 'trunk', 'Watching · checked HH:MM', 'From Site’s repo link', null],
+ ]);
+ assert.equal(l.rows[0].teamNote, 'Comes from App’s folder. Change it in the team’s settings.');
+ assert.equal(l.rows[1].teamNote, 'Comes from Site’s repo link. Change it in the team’s settings.');
+ assert.equal(m.statusLine(state({ repos: [APP, DOCS] })).rows[1].origin, 'Added by you');
+ assert.equal(m.statusLine(state({ repos: [APP, DOCS] })).rows[1].teamNote, null, 'a hand row has Remove, not the team note');
+});
+
+test('four rows fold behind the summary; each status has its words, LED and at most one action', () => {
+ const s = state({ repos: [APP, { ...SITE, status: 'not_connected' }, { ...DOCS, status: 'error', poll_error: 'rate limited' }, LAB, { ...APP, key: 'github.com/demo-org/eleven', repo: 'demo-org/eleven', team: 'Extra', status: 'too_many' }] });
+ const l = m.statusLine(s);
+ assert.equal(l.collapsed, true);
+ assert.equal(text(l), 'Watching 1 of 5 repos · 2 need you', 'needs you = not_connected + error');
+ assert.equal(l.led, 'bad', 'a failing repo lights the line red');
+ assert.deepEqual(l.rows.map((r) => [r.state.replace(/\d\d:\d\d( [AP]M)?/, 'HH:MM'), r.led, r.action]), [
+ ['Watching · checked HH:MM', 'ok', null],
+ ['Needs your GitHub connection', 'warn', 'connect'],
+ ['Can’t read it right now. Trying again.', 'bad', 'remove'],
+ ['gitlab.example.test isn’t read yet', 'off', null],
+ ['Not watched: 10 repos is the limit', 'off', null],
+ ]);
+ assert.equal(l.rows[2].title, 'rate limited', 'the poll error is the tooltip');
+ assert.equal(m.statusLine(state({ repos: [{ ...LAB, from: 'local', host: null }, APP] })).rows[0].state, 'Local folder, no remote');
+ assert.equal(m.reposSummary(state({ repos: [APP, SITE, DOCS, { ...APP, key: 'github.com/demo-org/api' }] })), 'Watching 4 repos');
+ assert.equal(m.reposSummary(state({ repos: [APP, SITE, DOCS, { ...APP, key: 'github.com/demo-org/api', status: 'error' }] })), 'Watching 3 of 4 repos · 1 needs you');
+ assert.equal(m.reposSummary(state({ repos: [APP, SITE, DOCS, { ...APP, key: 'github.com/demo-org/api', status: 'too_many' }] })), 'Watching 3 of 4 repos', 'too_many does not need you');
+});
+
+test('poll errors never show a URL with its token', () => {
+ const l = m.statusLine(state({ repos: [APP, { ...SITE, status: 'error', poll_error: 'fetch https://demo:[email protected]/demo-org/site failed' }] }));
+ assert.equal(l.rows[1].title, 'fetch https://github.com/demo-org/site failed');
+});
+
+test('single-line copy for error and too_many; not_connected with no repo still offers Connect', () => {
+ assert.equal(text(m.statusLine(state({ repos: [{ ...APP, status: 'error', poll_error: 'rate limited' }] }))), 'demo-org/app · Can’t read it right now. Trying again.');
+ assert.equal(text(m.statusLine(state({ repos: [{ ...APP, status: 'too_many' }] }))), 'demo-org/app · Not watched: 10 repos is the limit');
+ assert.equal(text(m.statusLine(state({ repos: [{ ...APP, status: 'not_connected' }] }))), 'demo-org/app · Needs your GitHub connection');
+ const nc = m.statusLine(state({ status: 'not_connected', repos: [] }));
+ assert.equal(nc.action, 'connect');
+ assert.equal(m.statusLine(state({ status: 'no_repo', repos: [] })).action, 'link');
+});
+
+test('team_id matches a row to its team even after a rename; only a team with no repo gets Link a repo', () => {
+ const l2 = m.statusLine(state({ repos: [{ ...APP, team: 'App (old name)', team_id: 'tm_app', status: 'not_connected' }] }), TEAMS);
+ assert.deepEqual(l2.rows.map((r) => r.id), [APP.key, 'team:tm_site']);
+ assert.equal(l2.rows[0].teamId, 'tm_app');
+});
+
+test('§9b: no repo watched at all, every team with none gets a "No repo" row with Link a repo', () => {
+ const l = m.statusLine(state({ repos: [{ ...APP, status: 'not_connected' }] }), TEAMS);
+ assert.equal(l.rows.length, 2);
+ assert.deepEqual([l.rows[1].id, l.rows[1].team, l.rows[1].state, l.rows[1].action], ['team:tm_site', 'Site', 'No repo', 'link']);
+ assert.deepEqual(l.noRepoTeams, []);
+});
+
+test('§9b: with a repo watched, teams with no repo fold into one quiet line and never count as needing you', () => {
+ const teams = [...TEAMS, { id: 'tm_mkt', name: 'Marketing' }, { id: 'tm_ops', name: 'Ops' }];
+ const l = m.statusLine(state({ repos: [APP] }), teams);
+ assert.deepEqual(l.rows, [], 'one repo stays a single line');
+ assert.deepEqual(l.noRepoTeams.map((t) => t.name), ['Site', 'Marketing', 'Ops']);
+ assert.equal(m.noRepoTeamsText(3), '3 teams have no repo');
+ assert.equal(m.noRepoTeamsText(1), '1 team has no repo');
+ assert.equal(text(m.statusLine(state({ repos: [APP, SITE, DOCS, { ...APP, key: 'github.com/demo-org/api' }] }), teams)), 'Watching 4 repos');
+});
+
+// ---------------------------------------------------------------------------
+// DOM: the list
+
+test('DOM 1 repo: one role=status line, no list, no disclosure', async () => {
+ const { root } = await line({ repos: [APP] });
+ assert.equal(document.querySelectorAll('[data-dv-status]').length, 1);
+ assert.equal(document.querySelector('[data-dv-status]').getAttribute('role'), 'status');
+ assert.equal(has('[data-dv-repos-list]'), false);
+ assert.equal(has('[data-dv-disclosure]'), false);
+ root.unmount();
+});
+
+test('DOM 2 repos: a labelled list, one row each: team · owner/name · branch · status', async () => {
+ const { root } = await line({ repos: [APP, SITE] });
+ const list = document.querySelector('[data-dv-repos-list]');
+ assert.equal(list.tagName, 'UL');
+ assert.equal(list.getAttribute('aria-label'), 'Repos Dev mode watches');
+ const rows = [...list.querySelectorAll('[data-dv-repo-row]')];
+ assert.equal(rows.length, 2);
+ assert.match(rows[0].textContent, /App.*demo-org\/app.*main.*Watching.*From App’s folder/);
+ assert.match(rows[1].textContent, /Site.*demo-org\/site.*trunk.*Watching.*From Site’s repo link/);
+ assert.equal(rows[0].querySelector('code.dv-code').textContent, 'main');
+ assert.equal(rows[0].querySelectorAll('[data-action]').length, 0, 'a watched team row has no action');
+ const info = rows[1].querySelector('[data-dv-team-note]');
+ assert.equal(info.getAttribute('aria-label'), 'Comes from Site’s repo link. Change it in the team’s settings.');
+ assert.equal(info.getAttribute('aria-expanded'), 'false');
+ await click(info);
+ assert.equal(info.getAttribute('aria-expanded'), 'true');
+ assert.match(rows[1].querySelector('[data-dv-team-note-text]').textContent, /Change it in the team’s settings/);
+ assert.equal(has('[data-dv-disclosure]'), false, 'two rows stay open');
+ root.unmount();
+});
+
+test('DOM 4 repos: folded behind "Watching N repos"; the disclosure works by keyboard and names its list', async () => {
+ const four = [APP, SITE, DOCS, { ...APP, key: 'github.com/demo-org/api', repo: 'demo-org/api', team: 'API' }];
+ const { root } = await line({ repos: four });
+ const d = document.querySelector('[data-dv-disclosure]');
+ assert.equal(d.tagName, 'BUTTON', 'a real button: Enter and Space work');
+ assert.equal(d.getAttribute('aria-expanded'), 'false');
+ assert.equal(has('[data-dv-repos-list]'), false);
+ assert.match(document.querySelector('[data-dv-status-text]').textContent, /Watching 4 repos/);
+ assert.equal(d.textContent, 'Show repos');
+ await click(d);
+ assert.equal(d.getAttribute('aria-expanded'), 'true');
+ const list = document.querySelector('[data-dv-repos-list]');
+ assert.equal(d.getAttribute('aria-controls'), list.id);
+ assert.equal(list.querySelectorAll('[data-dv-repo-row]').length, 4);
+ assert.equal(d.textContent, 'Hide repos');
+ await click(d);
+ assert.equal(has('[data-dv-repos-list]'), false);
+ root.unmount();
+});
+
+test('DOM states: not_connected rows offer Connect GitHub, error shows why, other_host and too_many have no action', async () => {
+ let connected = 0;
+ reset({ repos: [{ ...APP, status: 'not_connected' }, { ...SITE, status: 'error', poll_error: 'rate limited' }, LAB] });
+ const st = m.parseDevMode(server.state);
+ m.devStore.set('spc_demo', st);
+ const { root } = await mount(h(m.DevStatusLine, { spaceId: 'spc_demo', state: st, onConnect: () => connected++ }));
+ const row = (k) => document.querySelector(`[data-dv-repo-row="${k}"]`);
+ assert.equal(row(APP.key).querySelector('[data-action]').textContent.trim(), 'Connect GitHub');
+ await click(row(APP.key).querySelector('[data-action]'));
+ assert.equal(connected, 1);
+ assert.match(row(SITE.key).textContent, /Can’t read it right now\. Trying again\./);
+ assert.equal(row(SITE.key).querySelector('[data-dv-repo-state]').getAttribute('title'), 'rate limited');
+ assert.equal(row(SITE.key).querySelectorAll('[data-action]').length, 0);
+ // A team folder row has no action and no Remove: only the info note (spec §6).
+ assert.equal(row(LAB.key).querySelectorAll('[data-action]').length, 0);
+ assert.equal(row(LAB.key).querySelectorAll('button').length, 1);
+ assert.equal(row(LAB.key).querySelectorAll('[data-dv-team-note]').length, 1);
+ assert.match(row(LAB.key).textContent, /gitlab\.example\.test isn’t read yet/);
+ root.unmount();
+});
+
+test('DOM: Link a repo for a team PUTs {on, repo, team}; the new row appears', async () => {
+ const { root } = await line({ repos: [{ ...APP, status: 'not_connected' }] }, TEAMS);
+ const btn = document.querySelector('[data-dv-row-action="team:tm_site"]');
+ assert.equal(btn.textContent.trim(), 'Link a repo');
+ assert.equal(btn.getAttribute('aria-label'), 'Link a repo for Site');
+ assert.equal(btn.getAttribute('aria-expanded'), 'false');
+ await click(btn);
+ const form = document.querySelector('[data-dv-link-form="tm_site"]');
+ assert.match(form.textContent, /Repo for Site/);
+ assert.match(form.textContent, /Saved as this team’s repo link\. Bots only read it\./);
+ assert.match(form.textContent, /Save.*Cancel/);
+ const input = form.querySelector('input');
+ assert.equal(input.getAttribute('placeholder'), 'owner/name or its URL');
+ assert.equal(document.activeElement === input, true, 'focus goes to the field');
+ await typeInto(input, 'demo-org/site');
+ input.form.dispatchEvent(new window.Event('submit', { bubbles: true, cancelable: true }));
+ await settle();
+ const puts = server.calls.filter(([x]) => x === 'PUT').map(([, , b]) => b);
+ assert.deepEqual(puts, [{ on: true, repo: 'demo-org/site', team: 'tm_site' }]);
+ assert.equal(m.devStore.get('spc_demo').repos.length, 2);
+ root.unmount();
+});
+
+test('Ada (0.7.2): linking a repo while Dev mode is off sends on: false, and the space stays off', async () => {
+ const { root } = await line({ on: false, repos: [{ ...APP, status: 'not_connected' }] }, TEAMS);
+ await click(document.querySelector('[data-dv-row-action="team:tm_site"]'));
+ const input = document.querySelector('[data-dv-link-form="tm_site"] input');
+ await typeInto(input, 'demo-org/site');
+ input.form.dispatchEvent(new window.Event('submit', { bubbles: true, cancelable: true }));
+ await settle();
+ const puts = server.calls.filter(([x]) => x === 'PUT').map(([, , b]) => b);
+ assert.deepEqual(puts, [{ on: false, repo: 'demo-org/site', team: 'tm_site' }]);
+ assert.equal(server.state.on, false);
+ assert.equal(m.devStore.get('spc_demo').on, false);
+ root.unmount();
+ // With no known state, `on` is left out (the server keeps its current value), never forced on.
+ reset({ on: false, repos: [APP] });
+ await m.devApi.linkRepo('spc_demo', { repo: 'demo-org/docs' });
+ assert.deepEqual(server.calls.filter(([x]) => x === 'PUT').map(([, , b]) => b), [{ repo: 'demo-org/docs' }]);
+ assert.equal(server.state.on, false);
+});
+
+test('Ada (0.7.2): repo rows say "checked 15:30" in the desk header’s 24-hour format', () => {
+ const at = new Date(2026, 10, 6, 15, 30).toISOString();
+ const l = m.statusLine(state({ repos: [{ ...APP, polled_at: at }, SITE] }), TEAMS);
+ assert.equal(l.rows[0].state, 'Watching · checked 15:30');
+ assert.equal(m.checkedTime(at), m.checkedLabel(Date.parse(at)));
+ assert.equal(m.checkedTime(new Date(2026, 10, 6, 9, 5).toISOString()), '09:05');
+});
+
+test('DOM: Esc closes the Link field and puts focus back on its button', async () => {
+ const { root } = await line({ repos: [{ ...APP, status: 'not_connected' }] }, TEAMS);
+ const btn = document.querySelector('[data-dv-row-action="team:tm_site"]');
+ await click(btn);
+ document.querySelector('[data-dv-link-form] input').dispatchEvent(new window.KeyboardEvent('keydown', { key: 'Escape', bubbles: true }));
+ await settle();
+ await frame();
+ assert.equal(has('[data-dv-link-form]'), false);
+ assert.equal(document.activeElement === document.querySelector('[data-dv-row-action="team:tm_site"]'), true);
+ root.unmount();
+});
+
+test('DOM: Remove on a hand row sends DELETE …/dev_mode/repos/:key; team rows have no Remove', async () => {
+ const { root } = await line({ repos: [APP, SITE, DOCS] });
+ assert.equal(document.querySelectorAll('[data-action="remove"]').length, 1);
+ const rm = document.querySelector(`[data-dv-row-action="${DOCS.key}"]`);
+ assert.equal(rm.getAttribute('aria-label'), 'Stop watching demo-org/docs');
+ await click(rm);
+ await frame();
+ assert.equal(document.querySelector('[data-dv-removed]').getAttribute('role'), 'status');
+ assert.match(document.querySelector('[data-dv-removed]').textContent, /^Stopped watching demo-org\/docs\. Its cards stay\.Undo$/);
+ assert.equal(document.activeElement === document.querySelector('[data-dv-undo]'), true, 'focus lands on Undo');
+ const del = server.calls.filter(([x]) => x === 'DELETE');
+ assert.equal(del.length, 1);
+ assert.equal(new URL(del[0][1], 'http://localhost').pathname, `/api/spaces/spc_demo/dev_mode/repos/${encodeURIComponent(DOCS.key)}`);
+ assert.equal(m.devStore.get('spc_demo').repos.length, 2);
+ assert.equal(document.querySelectorAll('[data-dv-repo-row]').length, 2);
+ // Undo puts it back by hand (PUT {repo}, no team).
+ await click(document.querySelector('[data-dv-undo]'));
+ const puts = server.calls.filter(([x]) => x === 'PUT').map(([, , b]) => b);
+ assert.deepEqual(puts, [{ on: true, repo: 'demo-org/docs' }]);
+ assert.equal(has('[data-dv-removed]'), false);
+ assert.equal(document.querySelectorAll('[data-dv-repo-row]').length, 3);
+ root.unmount();
+});
+
+test('DOM: a 409 team_repo on Remove shows the team note as the error', async () => {
+ const { root } = await line({ repos: [APP, SITE, DOCS] });
+ server.state = { ...server.state, repos: server.state.repos.map((r) => (r.key === DOCS.key ? { ...r, added_by: 'team', team: 'Docs' } : r)) };
+ const realFetch = g.fetch;
+ g.fetch = g.window.fetch = async (url, init = {}) =>
+ init.method === 'DELETE' ? new Response(JSON.stringify({ error: 'That repo comes from a team.', code: 'team_repo' }), { status: 409, headers: { 'Content-Type': 'application/json' } }) : realFetch(url, init);
+ await click(document.querySelector(`[data-dv-row-action="${DOCS.key}"]`));
+ await frame();
+ g.fetch = g.window.fetch = realFetch;
+ assert.match(document.querySelector('[role="alert"]').textContent, /Comes from .*’s repo link\. Change it in the team’s settings\./);
+ root.unmount();
+});
+
+test('DOM §9b: the quiet line "2 teams have no repo · Link a repo" opens a team picker, then the repo field', async () => {
+ const teams = [...TEAMS, { id: 'tm_mkt', name: 'Marketing' }];
+ const { root } = await line({ repos: [APP] }, teams);
+ const q = document.querySelector('[data-dv-norepo]');
+ assert.match(q.textContent, /^2 teams have no repo·Link a repo$/);
+ const b = q.querySelector('[data-dv-norepo-action]');
+ await click(b);
+ assert.equal(b.getAttribute('aria-expanded'), 'true');
+ const pick = q.querySelector('[data-dv-team-pick]');
+ assert.deepEqual([...pick.options].map((o) => o.textContent), ['Site', 'Marketing']);
+ await frame();
+ assert.equal(document.activeElement === pick, true, 'the picker comes first');
+ pick.value = 'tm_mkt';
+ pick.dispatchEvent(new window.Event('change', { bubbles: true }));
+ await settle();
+ assert.match(q.textContent, /Repo for Marketing/);
+ await typeInto(q.querySelector('input'), 'demo-org/brand');
+ q.querySelector('form').dispatchEvent(new window.Event('submit', { bubbles: true, cancelable: true }));
+ await settle();
+ assert.deepEqual(server.calls.filter(([x]) => x === 'PUT').map(([, , b2]) => b2), [{ on: true, repo: 'demo-org/brand', team: 'tm_mkt' }]);
+ root.unmount();
+});
+
+test('§9b (Mira, final): one team says "1 team has no repo"; the line is neutral; Link a repo is 44 px on phone; counts are repos, never teams', async () => {
+ const { root } = await line({ repos: [APP] }, TEAMS);
+ const q = document.querySelector('[data-dv-norepo]');
+ assert.match(q.textContent, /^1 team has no repo·Link a repo$/);
+ assert.equal(!!q.querySelector('.dv-led, [data-s]'), false, 'no dot');
+ root.unmount();
+ const { readFile } = await import('node:fs/promises');
+ const css = await readFile(new URL('../src/styles/devStatus.css', import.meta.url), 'utf8');
+ const rule = css.match(/\.kw-dv-norepo, \.kw-dv-removed \{([^}]*)\}/)[1];
+ assert.match(rule, /color: var\(--t3\)/, 'text-tertiary');
+ assert.doesNotMatch(rule, /warn|amber|#f59e0b/);
+ assert.match(css, /@media \(max-width: 639px\) \{[^@]*\.kw-dv-norepo-act \{ min-height: 44px;/);
+ const teams3 = [...TEAMS, { id: 'tm_mkt', name: 'Marketing' }, { id: 'tm_ops', name: 'Ops' }];
+ assert.equal(m.reposSummary(state({ repos: [APP, SITE] })), 'Watching 2 repos', 'teams without a repo do not change the count');
+ assert.equal(m.teamsWithoutRepo(state({ repos: [APP, SITE] }), teams3).length, 2);
+});
+
+// ---------------------------------------------------------------------------
+// Chips and filters
+
+test('repoFilters: short names, owner/name when two share one; none below 2 readable repos', () => {
+ assert.deepEqual(m.repoFilters(state({ repos: [APP, SITE] })).map((f) => [f.key, f.label]), [
+ ['github.com/demo-org/app', 'app'],
+ ['github.com/demo-org/site', 'site'],
+ ]);
+ const twin = { ...SITE, key: 'github.com/other-org/app', repo: 'other-org/app' };
+ assert.deepEqual(m.repoFilters(state({ repos: [APP, twin] })).map((f) => f.label), ['demo-org/app', 'other-org/app']);
+ assert.deepEqual(m.repoFilters(state({ repos: [APP] })), []);
+ assert.deepEqual(m.repoFilters(state({ repos: [APP, LAB] })), [], 'other_host has no cards to filter');
+});
+
+test('cardRepoLabel: only with more than one repo; unknown keys drop their host', () => {
+ assert.equal(m.cardRepoLabel(state({ repos: [APP] }), APP.key), null);
+ assert.equal(m.cardRepoLabel(state({ repos: [APP, SITE] }), 'GitHub.com/Demo-Org/Site'), 'demo-org/site');
+ assert.equal(m.cardRepoLabel(state({ repos: [APP, SITE] }), 'github.com/demo-org/gone'), 'demo-org/gone');
+ assert.equal(m.cardRepoLabel(state({ repos: [APP, SITE] }), null), null);
+ assert.equal(m.cardRepoLabel(state({ repos: [APP, SITE] }), 'github.com/demo-org/gone', 'demo-org/gone-renamed'), 'demo-org/gone-renamed', 'the card’s repo_name wins');
+});
+
+test('cardsOfRepo: keeps that repo’s cards and cards with no repo (an older server); null keeps all', () => {
+ const cards = [{ id: 'a', repo: APP.key }, { id: 's', repo: SITE.key }, { id: 'old' }];
+ assert.deepEqual(m.cardsOfRepo(cards, APP.key).map((c) => c.id), ['a', 'old']);
+ assert.equal(m.cardsOfRepo(cards, null).length, 3);
+});
+
+const withRepo = (card, repo) => ({ ...card, repo, repo_name: repo.split('/').slice(1).join('/') });
+
+test('DOM desk, 2 repos: All · app · site filter chips; a pick loads both lists with ?repo= and shows only that repo', async () => {
+ reset({ repos: [APP, SITE] });
+ server.landed = [withRepo(m.fx.LANDED_288, APP.key), withRepo(m.fx.LANDED_289, SITE.key)];
+ server.reviews = [withRepo(m.fx.REVIEW_290, APP.key), withRepo(m.fx.REVIEW_301, SITE.key)];
+ m.devStore.set('spc_demo', m.parseDevMode(server.state));
+ const { root } = await mount(h(m.DevDeskView, { spaceId: 'spc_demo', spaceName: 'Demo', teams: TEAMS, now: m.fx.FIXTURE_NOW }));
+ const group = document.querySelector('[data-dev-repo-filters]');
+ assert.equal(group.getAttribute('role'), 'group');
+ assert.equal(group.getAttribute('aria-label'), 'Show cards from');
+ const chips = [...group.querySelectorAll('button')];
+ assert.deepEqual(chips.map((c) => c.textContent), ['All', 'app', 'site']);
+ assert.deepEqual(chips.map((c) => c.getAttribute('aria-pressed')), ['true', 'false', 'false']);
+ assert.equal(document.querySelectorAll('[data-dev-card="landed"]').length, 2);
+ // Each card names its repo.
+ assert.deepEqual([...document.querySelectorAll('[data-dev-card="landed"] [data-dev-card-repo]')].map((c) => [c.textContent, c.title]).sort(), [
+ ['Repo demo-org/appapp', 'demo-org/app'],
+ ['Repo demo-org/sitesite', 'demo-org/site'],
+ ], 'the chip says the repo name; screen readers and the title get owner/name');
+ assert.equal(document.querySelectorAll('[data-dev-card="review"] [data-dev-card-repo]').length, 0, 'reviews are on the other tab');
+ server.calls = [];
+ await click(chips[2]);
+ await settle();
+ assert.equal(chips[2].getAttribute('aria-pressed'), 'true');
+ const gets = server.calls.filter(([x, u]) => x === 'GET' && /\/dev\/(landed|reviews)/.test(u)).map(([, u]) => new URL(u, 'http://localhost').searchParams.get('repo'));
+ assert.deepEqual(gets, [SITE.key, SITE.key]);
+ const landed = [...document.querySelectorAll('[data-dev-card="landed"]')];
+ assert.deepEqual(landed.map((c) => c.dataset.repo), [SITE.key]);
+ await click(chips[0]);
+ assert.equal(document.querySelectorAll('[data-dev-card="landed"]').length, 2, 'All shows the space again');
+ root.unmount();
+});
+
+test('DOM desk, 1 repo: no filter chips and no repo chip on cards', async () => {
+ reset({ repos: [APP] });
+ server.landed = [withRepo(m.fx.LANDED_288, APP.key)];
+ m.devStore.set('spc_demo', m.parseDevMode(server.state));
+ const { root } = await mount(h(m.DevDeskView, { spaceId: 'spc_demo', spaceName: 'Demo', now: m.fx.FIXTURE_NOW }));
+ assert.equal(document.querySelectorAll('[data-dev-card="landed"]').length, 1);
+ assert.equal(has('[data-dev-repo-filters]'), false);
+ assert.equal(has('[data-dev-card-repo]'), false);
+ assert.equal(server.calls.some(([, u]) => u.includes('repo=')), false);
+ root.unmount();
+});
+
+test('devApi: Draft release notes, landed and reviews send ?repo= when a repo is picked, nothing otherwise', async () => {
+ reset({ repos: [APP, SITE] });
+ await m.devApi.releaseNotes('spc_demo', SITE.key).catch(() => null);
+ await m.devApi.releaseNotes('spc_demo').catch(() => null);
+ await m.devApi.landed('spc_demo', undefined, SITE.key);
+ await m.devApi.reviews('spc_demo', null);
+ const qs = server.calls.map(([meth, u]) => `${meth} ${new URL(u, 'http://localhost').pathname.split('/').pop()} ${new URL(u, 'http://localhost').searchParams.get('repo')}`);
+ assert.deepEqual(qs, [`POST release_notes ${SITE.key}`, 'POST release_notes null', `GET landed ${SITE.key}`, 'GET reviews null']);
+});
+
+// ---------------------------------------------------------------------------
+// Ada's answers (2026-11-06): 2, Dev mode off reads "Will watch" (Mira's copy), never watched; 5, Undo brings a repo back
+// the way it came.
+
+test('answer 2: Dev mode off, a watching repo is a neutral "Will watch" (no green); other statuses stay', () => {
+ const off = (repos) => m.statusLine(state({ on: false, repos }), TEAMS);
+ const l = off([APP, SITE, { ...DOCS, status: 'not_connected' }, { ...DOCS, key: 'github.com/demo-org/err', repo: 'demo-org/err', status: 'error' }]);
+ assert.deepEqual(l.rows.map((r) => [r.state, r.led]), [
+ ['Will watch', 'off'],
+ ['Will watch', 'off'],
+ ['Needs your GitHub connection', 'warn'],
+ ['Can’t read it right now. Trying again.', 'bad'],
+ ]);
+ assert.equal(text(l), 'Will watch 2 of 4 repos · 2 need you');
+ assert.equal(text(off([APP, SITE])), 'Will watch 2 repos');
+ assert.equal(off([APP, SITE]).led, 'off', 'no green LED while off');
+ const one = off([APP]);
+ assert.deepEqual([text(one), one.led], ['demo-org/app · main · Will watch', 'off']);
+ const tooMany = m.statusLine(state({ on: false, repos: [{ ...APP, status: 'too_many' }] }));
+ assert.deepEqual([text(tooMany), tooMany.led], ['demo-org/app · Not watched: 10 repos is the limit', 'off']);
+ // On, nothing changes.
+ assert.equal(text(m.statusLine(state({ repos: [APP, SITE] }), TEAMS)), 'Watching 2 repos');
+});
+
+test('DOM answer 2: off, the Will watch chip is neutral and the desk header says "Dev mode is off"', async () => {
+ const { root } = await line({ on: false, repos: [APP, SITE] });
+ const chips = [...document.querySelectorAll('[data-dv-repo-state]')];
+ assert.deepEqual(chips.map((c) => [c.textContent, c.dataset.tone]), [
+ ['Will watch', 'neutral'],
+ ['Will watch', 'neutral'],
+ ]);
+ for (const c of chips) {
+ assert.equal(c.getAttribute('title'), 'Will watch when Dev mode is on');
+ assert.equal(c.getAttribute('aria-label'), 'Will watch when Dev mode is on');
+ }
+ assert.deepEqual([...document.querySelectorAll('[data-dv-repo-row] .dv-led')].map((d) => d.dataset.s), ['off', 'off']);
+ root.unmount();
+ const { readFile } = await import('node:fs/promises');
+ const css = await readFile(new URL('../src/styles/devStatus.css', import.meta.url), 'utf8');
+ const rule = css.match(/\.kw-dv-repo-state\[data-tone='neutral'\] \{([^}]*)\}/)[1];
+ assert.doesNotMatch(rule, /ok|green/, 'the Will watch chip is never green');
+
+ reset({ on: false, repos: [APP] });
+ m.devStore.set('spc_demo', m.parseDevMode(server.state));
+ const desk = await mount(h(m.DevDeskView, { spaceId: 'spc_demo', spaceName: 'Demo', now: m.fx.FIXTURE_NOW }));
+ assert.equal(document.querySelector('[data-dev-desk-sub]').textContent, 'Dev mode is off');
+ desk.root.unmount();
+ reset({ repos: [APP] });
+ m.devStore.set('spc_demo', m.parseDevMode(server.state));
+ const onDesk = await mount(h(m.DevDeskView, { spaceId: 'spc_demo', spaceName: 'Demo', now: m.fx.FIXTURE_NOW }));
+ assert.equal(document.querySelector('[data-dev-desk-sub]').textContent, 'What landed and what needs a look');
+ onDesk.root.unmount();
+});
+
+test('answer 5: Undo after clearing a team’s repo sends PUT {repo: the previous link, team: its id}', async () => {
+ assert.deepEqual(m.undoBody({ repo: 'https://github.com/demo-org/site', team: 'tm_site' }), { repo: 'https://github.com/demo-org/site', team: 'tm_site' });
+ reset({ repos: [APP] });
+ m.devStore.set('spc_demo', m.parseDevMode(server.state));
+ await m.devApi.linkRepo('spc_demo', m.undoBody({ repo: 'https://github.com/demo-org/site', team: 'tm_site' }));
+ const puts = server.calls.filter(([x]) => x === 'PUT').map(([, , b]) => b);
+ assert.deepEqual(puts, [{ on: true, repo: 'https://github.com/demo-org/site', team: 'tm_site' }], 'the team link comes back, never a hand add');
+ assert.equal(server.state.repos.at(-1).added_by, 'team');
+});
+
+test('answer 5: Undo for a hand row stays PUT {repo}, with no team', async () => {
+ assert.deepEqual(m.undoBody({ repo: 'demo-org/docs', team: null }), { repo: 'demo-org/docs', team: null });
+ reset({ repos: [APP] });
+ m.devStore.set('spc_demo', m.parseDevMode(server.state));
+ await m.devApi.linkRepo('spc_demo', m.undoBody({ repo: 'demo-org/docs', team: null }));
+ const puts = server.calls.filter(([x]) => x === 'PUT').map(([, , b]) => b);
+ assert.deepEqual(puts, [{ on: true, repo: 'demo-org/docs' }]);
+ assert.equal(server.state.repos.at(-1).added_by, 'hand');
+});
+
+test('answer 5: the desk’s Undo goes through undoBody, and a removed team link keeps its team id', async () => {
+ const { readFile } = await import('node:fs/promises');
+ const src = await readFile(new URL('../src/components/DevStatusLine.tsx', import.meta.url), 'utf8');
+ assert.match(src, /save\(spaceId, \{ \.\.\.undoBody\(removed\), on: state\?\.on \?\? null \}\)/);
+ assert.doesNotMatch(src, /repo: removed\.repo, team: null/);
+ assert.match(src, /added_by === 'team' && repo\.from === 'repo' \? row\.teamId : null/);
+});
+
+test('addendum 4: clearing a team’s link toasts "Cleared {team}’s repo link." with Undo; both toasts last 5 s', async () => {
+ assert.equal(m.clearedText('Site'), 'Cleared Site’s repo link.');
+ assert.equal(m.UNDO_TOAST_MS, 5000);
+ const { readFile } = await import('node:fs/promises');
+ const src = await readFile(new URL('../src/components/DevStatusLine.tsx', import.meta.url), 'utf8');
+ assert.match(src, /removed\.team \? clearedText\(removed\.teamName/);
+ assert.match(src, /setTimeout\(\(\) => setRemoved\(null\), UNDO_TOAST_MS\)/);
+ // The hand Remove toast goes after 5 s.
+ const { root } = await line({ repos: [APP, SITE, DOCS] });
+ await click(document.querySelector(`[data-dv-row-action="${DOCS.key}"]`));
+ await frame();
+ assert.ok(document.querySelector('[data-dv-removed]'));
+ await new Promise((r) => setTimeout(r, m.UNDO_TOAST_MS + 50));
+ await settle();
+ assert.equal(!!document.querySelector('[data-dv-removed]'), false);
+ root.unmount();
+});