Skip to content

armgit / kwant

Public Imported from GitHub
0

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

Dev mode: first in Settings › General, and a suggestion in #general when the space has code (#629)

Oleksandr Ivanchenko80cc0089f419
diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx
index 9f3ba23b..cdc3bfe3 100644
--- a/frontend/src/App.tsx
+++ b/frontend/src/App.tsx
@@ -9,7 +9,7 @@ import { PHONE_QUERY } from './layout';
import { useSettingsCover } from './settingsFocus';
import { WhatsNewHost } from './components/WhatsNewSheet';
import { GetStarted, GetStartedBanner } from './components/GetStarted';
-import { markMovedSeen, movedPointerShows, movedSeen, ringDevSettings } from './firstScreen';
+import { focusDevSettings, markMovedSeen, movedPointerShows, movedSeen, ringDevSettings } from './firstScreen';
import { dismiss as dismissGetStarted, isDismissed as getStartedDismissed, showCard as showGetStarted, wasStarted as getStartedWasStarted, whatsNewEstablished as decideWhatsNewEstablished } from './gettingStarted';
import { useStartVersion } from './gettingStartedInstall';
import { SpaceTile } from './components/Spaces';
@@ -169,7 +169,9 @@ import { NeedsYouPill } from './components/NeedsYouPill';
import { DevModeError, devApi, devStore, devTeamRefs } from './devMode';
import { GitHubConnectHost, connectedToast, openGitHubConnect } from './components/GitHubConnect';
import { JiraSetupHost } from './components/JiraSetup';
-import { useDevModeOn } from './components/DevModeSwitch';
+import { useDevMode, useDevModeOn } from './components/DevModeSwitch';
+import { DevModeSuggestion, SUGGEST_HIDDEN } from './components/DevModeSuggestion';
+import { dismissSuggest, ensureDevState, suggestDismissed, suggestShows } from './devSuggest';
import { DEV_CARD_EVENT, DevDeskView, type DevCardEvent } from './components/DevDesk';
import { DEV_TICKET_EVENT, DEV_TICKET_PROGRESS_EVENT } from './components/dev/TicketsTab';
import { PrepushNeedsYou, PrepushThread, threadCards, usePrepushCards, type PrepushEventDetail } from './components/dev/PrepushThread';
@@ -382,6 +384,12 @@ export const SpaceApp: React.FC<SpaceAppProps> = ({
markMovedSeen();
setMovedHidden(true);
};
+ // The suggestion's Turn on: Settings › This space › General, the Dev mode card (first there) in view and
+ // focused. It doesn't switch Dev mode on: the person presses the button on the card.
+ const openDevSuggest = () => {
+ openSpaceSettings('general');
+ focusDevSettings();
+ };
const openMoved = () => {
openSpaceSettings('general');
ringDevSettings();
@@ -582,6 +590,11 @@ export const SpaceApp: React.FC<SpaceAppProps> = ({
// Dev mode (0.7): the open space's state, read by the switch, the hats and the grid.
useEffect(() => devStore.setCurrent(space.id), [space.id]);
const devOn = useDevModeOn(space.id);
+ // Dev mode visibility: the "this space has code" suggestion in #general reads the same cached state.
+ const devState = useDevMode(space.id);
+ useEffect(() => ensureDevState(space.id), [space.id]);
+ // Not now: the space it was hidden in, for the one out-of-sight "Hidden." line.
+ const [suggestHiddenIn, setSuggestHiddenIn] = useState<string | null>(null);
// 0.8.0 B3: the space's pre-push cards (Dev mode only): the bot's thread and the Inbox read them.
const prepush = usePrepushCards(space.id, devOn);
const prepushWaiting = prepushNeedsYou(prepush.cards, prepush.acted).length;
@@ -3919,6 +3932,24 @@ export const SpaceApp: React.FC<SpaceAppProps> = ({
teams={teams}
/>
) : null;
+ const devSuggest = suggestShows({ inGeneral: isGeneral, state: devState, dismissed: suggestDismissed(space.id), gettingStarted: !!setupBanner || !!getStartedCard, canRun }) && devState ? (
+ <DevModeSuggestion
+ spaceName={space.name}
+ state={devState}
+ onOpen={openDevSuggest}
+ onDismiss={() => {
+ dismissSuggest(space.id);
+ setSuggestHiddenIn(space.id);
+ document.querySelector<HTMLTextAreaElement>('[data-composer-form] textarea')?.focus();
+ }}
+ />
+ ) : null;
+ // Mounted (empty) in #general before Not now fills it, so a screen reader hears the line.
+ const devSuggestStatus = isGeneral ? (
+ <p role="status" className="sr-only" data-dev-suggestion-status>
+ {suggestHiddenIn === space.id ? SUGGEST_HIDDEN : ''}
+ </p>
+ ) : null;
const setupChecklist = (
<SpaceReadyCard
spaceName={space.name}
@@ -4287,7 +4318,14 @@ export const SpaceApp: React.FC<SpaceAppProps> = ({
onHighlightDone={() => setHighlightMessageId(null)}
subHeader={subHeader}
threadLine={isPhone && threadBarProps ? <ThreadPicker {...threadBarProps} /> : undefined}
- notice={setupBanner}
+ notice={
+ setupBanner ?? (
+ <>
+ {devSuggest}
+ {devSuggestStatus}
+ </>
+ )
+ }
topCard={
isChannel && currentTeam ? (
<TeamNeedsTop
diff --git a/frontend/src/components/DevModeSettings.tsx b/frontend/src/components/DevModeSettings.tsx
index 36965213..f3c08abc 100644
--- a/frontend/src/components/DevModeSettings.tsx
+++ b/frontend/src/components/DevModeSettings.tsx
@@ -1,17 +1,45 @@
// Settings › This space › Dev mode: the repo, the branch to watch, the optional backup command
// (plan D9) and Turn off. Off keeps the settings and What landed's history.
+// Dev mode visibility (autonomy/dev-mode-visibility, design.md §1): the card is first in General. Off sells
+// (what you gain and one primary Turn on; an accent card naming the found repo, its fields behind Details),
+// On configures (today's form).
-import React, { useEffect, useState } from 'react';
-import { Check, Code } from 'lucide-react';
+import React, { useEffect, useRef, useState } from 'react';
+import { Check, ChevronDown, Code, Loader2 } from 'lucide-react';
import { DevModeState, DevTeamRef, devApi, devStore, normaliseRepo } from '../devMode';
+import { foundRepo, hasFoundCode, readableRepos } from '../devSuggest';
import { JiraSettings } from './JiraSettings';
import { useDevMode } from './DevModeSwitch';
const card = 'rounded-xl border border-zinc-800 bg-zinc-950/60';
+/** Off with a repo found: the accent family of the primary buttons (no shadow, no glow, no holo). */
+const accentCard = 'rounded-xl border border-sky-500/40 bg-accent-soft';
const rowBtn =
'flex items-center gap-1.5 px-2.5 py-1.5 rounded-lg text-xs font-medium text-zinc-300 border border-zinc-700/60 bg-zinc-800/60 hover:bg-zinc-700/70 hover:text-zinc-100 transition-colors disabled:opacity-50';
const primaryBtn = 'flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-xs font-medium text-white bg-sky-600 hover:bg-sky-500 transition-colors disabled:opacity-50';
+const turnOnBtn =
+ 'inline-flex items-center justify-center gap-1.5 h-9 max-md:h-11 max-md:w-full px-3.5 rounded-lg text-[13px] font-semibold text-white bg-sky-600 hover:bg-sky-500 transition-colors disabled:opacity-50 kw-focus';
const input = 'w-full bg-zinc-950 border rounded-lg px-3 py-2 text-sm font-mono text-zinc-100 focus:outline-none border-zinc-800 focus:border-sky-500';
+/** What turning it on gives you, the same words in the card and the #general suggestion. */
+export const DEV_GAIN = 'your bots review pull requests, show what landed and guard deploys.';
+
+/** "Found owner/name in Team and 2 more. Turn it on and …", the repo in mono, the team in medium. */
+const FoundLine: React.FC<{ state: DevModeState }> = ({ state }) => {
+ const r = foundRepo(state);
+ if (!r) return null;
+ const more = readableRepos(state).length - 1;
+ return (
+ <>
+ Found <span className="font-mono text-zinc-100">{r.repo}</span>
+ {r.team ? (
+ <>
+ {' '}in <span className="font-medium text-zinc-100">{r.team}</span>
+ </>
+ ) : null}
+ {more > 0 ? ` and ${more} more` : ''}. Turn it on and {DEV_GAIN}
+ </>
+ );
+};
export const DevModeSettings: React.FC<{ spaceId: string; spaceName: string; approvals?: string; save?: typeof devApi.put; teams?: DevTeamRef[] }> = ({ spaceId, spaceName, save = devApi.put, teams }) => {
const state = useDevMode(spaceId);
@@ -21,15 +49,24 @@ export const DevModeSettings: React.FC<{ spaceId: string; spaceName: string; app
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
const [saved, setSaved] = useState(false);
+ const [details, setDetails] = useState(false);
+ const [emptyErr, setEmptyErr] = useState(false);
+ const repoInput = useRef<HTMLInputElement>(null);
+
+ // Off with a found GitHub repo: the fields start from it, so Details shows what Turn on will watch.
+ const found = hasFoundCode(state) ? foundRepo(state) : null;
+ const prefill = found ? normaliseRepo(found.repo) : null;
+ const baseRepo = state?.repo ?? prefill ?? '';
+ const baseBranch = state?.branch ?? (prefill ? found?.branch ?? '' : '');
useEffect(() => {
if (!state) devApi.get(spaceId).then((s) => devStore.set(spaceId, s), (e: unknown) => setError(e instanceof Error ? e.message : 'Dev mode couldn’t load.'));
}, [spaceId, state]);
useEffect(() => {
- setRepo(state?.repo ?? '');
- setBranch(state?.branch ?? '');
+ setRepo(baseRepo);
+ setBranch(baseBranch);
setBackup(state?.backup_command ?? '');
- }, [state?.repo, state?.branch, state?.backup_command]);
+ }, [baseRepo, baseBranch, state?.backup_command]);
// 0.9.8 (first-screen A): the header switch is gone, so this card is where Dev mode is turned on, the
// first time too. It shows as soon as the space's state has loaded.
@@ -37,7 +74,8 @@ export const DevModeSettings: React.FC<{ spaceId: string; spaceName: string; app
const normal = repo.trim() ? normaliseRepo(repo) : null;
const repoErr = repo.trim() && !normal ? 'Paste a GitHub repo, like owner/name or its URL.' : null;
- const dirty = (normal ?? '') !== (state.repo ?? '') || branch.trim() !== (state.branch ?? '') || backup.trim() !== (state.backup_command ?? '');
+ const dirty = (normal ?? '') !== baseRepo || branch.trim() !== baseBranch || backup.trim() !== (state.backup_command ?? '');
+ const accent = !!found;
const put = (body: Partial<Pick<DevModeState, 'repo' | 'branch' | 'backup_command'>> & { on: boolean }) => {
setBusy(true);
@@ -48,6 +86,7 @@ export const DevModeSettings: React.FC<{ spaceId: string; spaceName: string; app
devStore.set(spaceId, s);
setSaved(true);
setBusy(false);
+ setDetails(false);
},
(e: unknown) => {
setError(e instanceof Error ? e.message : 'Couldn’t save Dev mode.');
@@ -56,85 +95,177 @@ export const DevModeSettings: React.FC<{ spaceId: string; spaceName: string; app
);
};
+ // Turn on sends only what the person changed: an untouched prefill isn't sent, or it would add a hand
+ // row next to the team's own (the server watches the team repos it found by itself).
+ const turnOn = () => {
+ if (repoErr) {
+ setDetails(true);
+ setTimeout(() => repoInput.current?.focus(), 0);
+ return;
+ }
+ if (!accent && !normal) {
+ setEmptyErr(true);
+ repoInput.current?.focus();
+ return;
+ }
+ const body: Parameters<typeof put>[0] = { on: true };
+ if ((normal ?? '') !== baseRepo) body.repo = normal;
+ if (branch.trim() !== baseBranch) body.branch = branch.trim() || null;
+ if (backup.trim() !== (state.backup_command ?? '')) body.backup_command = backup.trim();
+ put(body);
+ };
+ const shownRepoErr = repoErr ?? (emptyErr && !state.on && !repo.trim() ? 'Add a repo first.' : null);
+
+ const repoField = (
+ <div>
+ <label htmlFor="dv-set-repo" className="block text-xs font-medium text-zinc-300 mb-1">
+ Repository
+ </label>
+ <input
+ ref={repoInput}
+ id="dv-set-repo"
+ value={repo}
+ onChange={(e) => {
+ setRepo(e.target.value);
+ setEmptyErr(false);
+ }}
+ placeholder={state.on ? 'owner/repo' : 'owner/name'}
+ spellCheck={false}
+ autoCapitalize="off"
+ className={input}
+ aria-invalid={!!shownRepoErr}
+ aria-describedby={!state.on && !accent ? 'dv-set-repo-err dv-set-repo-help' : 'dv-set-repo-err'}
+ />
+ <p id="dv-set-repo-err" className="mt-1 text-[11px] text-rose-300 min-h-[1em]">
+ {shownRepoErr}
+ </p>
+ {!state.on && !accent && (
+ <p id="dv-set-repo-help" className="text-[11px] text-zinc-500">
+ Paste owner/name or its URL. A repo set on a team (Team settings › Git Repo) shows up here by itself.
+ </p>
+ )}
+ </div>
+ );
+ const branchField = (
+ <div>
+ <label htmlFor="dv-set-branch" className="block text-xs font-medium text-zinc-300 mb-1">
+ Branch to watch
+ </label>
+ <input id="dv-set-branch" value={branch} onChange={(e) => setBranch(e.target.value)} placeholder="main" spellCheck={false} autoCapitalize="off" className={input} />
+ </div>
+ );
+ const backupField = (
+ <div>
+ <label htmlFor="dv-set-backup" className="block text-xs font-medium text-zinc-300 mb-1">
+ Backup command <span className="text-zinc-500 font-normal">(optional)</span>
+ </label>
+ <input
+ id="dv-set-backup"
+ value={backup}
+ maxLength={2000}
+ onChange={(e) => setBackup(e.target.value)}
+ placeholder="./scripts/backup.sh"
+ spellCheck={false}
+ autoCapitalize="off"
+ className={input}
+ aria-describedby="dv-set-backup-help"
+ />
+ <p id="dv-set-backup-help" className="mt-1 text-[11px] text-zinc-500">
+ Runs in the bot’s folder when you press Back up first on a production step. It should print the backup file’s path.
+ </p>
+ </div>
+ );
+
+ const errorLine = error && (
+ <p role="alert" className="text-[11px] text-rose-300">
+ {error}
+ </p>
+ );
+ const tile = accent ? 'bg-sky-500/15 text-sky-300' : state.on ? 'bg-white/[.04] text-sky-300' : 'bg-white/[.04] text-zinc-400';
+
return (
<>
<form
- className={`${card} p-4 space-y-3`}
+ className={`${accent ? accentCard : card} p-4 scroll-mt-4 focus:outline-none`}
data-dev-settings
+ data-dev-off={state.on ? undefined : accent ? 'found' : 'none'}
+ // The #general suggestion lands here (focus goes to Turn on, or to the card itself when it's on).
+ tabIndex={-1}
+ aria-labelledby="dv-title"
onSubmit={(e) => {
e.preventDefault();
+ if (!state.on) return turnOn();
if (!dirty || repoErr || busy) return;
put({ on: state.on, repo: normal, branch: branch.trim() || null, backup_command: backup.trim() });
}}
>
- <p className="flex items-center gap-2 text-xs font-medium text-zinc-200">
- <Code size={14} className="text-zinc-400" aria-hidden="true" /> Dev mode
+ <div className="flex items-center gap-2.5">
+ <span className={`w-8 h-8 shrink-0 rounded-lg grid place-items-center ${tile}`}>
+ <Code size={16} aria-hidden="true" />
+ </span>
+ <h3 id="dv-title" className="text-sm font-semibold text-zinc-100">
+ Dev mode
+ </h3>
<span className={`ml-auto kw-chip ${state.on ? 'kw-chip-accent' : ''}`}>{state.on ? 'On' : 'Off'}</span>
- </p>
- <p className="text-[11px] text-zinc-500">
- {state.on
- ? `${spaceName} reads this repo to show what landed, review PRs and guard deploys. Only you can change it.`
- : 'Off. Reviews, the ship gate and the production floor are stopped. Approvals stay as you set them above.'}
- </p>
- <div>
- <label htmlFor="dv-set-repo" className="block text-xs font-medium text-zinc-300 mb-1">
- Repository
- </label>
- <input id="dv-set-repo" value={repo} onChange={(e) => setRepo(e.target.value)} placeholder="owner/repo" spellCheck={false} autoCapitalize="off" className={input} aria-invalid={!!repoErr} aria-describedby="dv-set-repo-err" />
- <p id="dv-set-repo-err" className="mt-1 text-[11px] text-rose-300 min-h-[1em]">
- {repoErr}
- </p>
- </div>
- <div>
- <label htmlFor="dv-set-branch" className="block text-xs font-medium text-zinc-300 mb-1">
- Branch to watch
- </label>
- <input id="dv-set-branch" value={branch} onChange={(e) => setBranch(e.target.value)} placeholder="main" spellCheck={false} autoCapitalize="off" className={input} />
- </div>
- <div>
- <label htmlFor="dv-set-backup" className="block text-xs font-medium text-zinc-300 mb-1">
- Backup command <span className="text-zinc-500 font-normal">(optional)</span>
- </label>
- <input
- id="dv-set-backup"
- value={backup}
- maxLength={2000}
- onChange={(e) => setBackup(e.target.value)}
- placeholder="./scripts/backup.sh"
- spellCheck={false}
- autoCapitalize="off"
- className={input}
- aria-describedby="dv-set-backup-help"
- />
- <p id="dv-set-backup-help" className="mt-1 text-[11px] text-zinc-500">
- Runs in the bot’s folder when you press Back up first on a production step. It should print the backup file’s path.
- </p>
</div>
- {error && (
- <p role="alert" className="text-[11px] text-rose-300">
- {error}
- </p>
+ {state.on ? (
+ <div className="mt-3 space-y-3">
+ <p id="dv-value" className="text-[11px] text-zinc-500">
+ {spaceName} reads this repo to show what landed, review PRs and guard deploys. Only you can change it.
+ </p>
+ {repoField}
+ {branchField}
+ {backupField}
+ {errorLine}
+ <div className="flex items-center gap-2">
+ <button type="button" className={rowBtn} disabled={busy} onClick={() => put({ on: false })} data-dev-turn-off>
+ Turn off Dev mode
+ </button>
+ <span className="flex-1" />
+ {saved && !dirty && (
+ <span className="flex items-center gap-1 text-xs text-emerald-400" role="status">
+ <Check size={13} aria-hidden="true" /> Saved
+ </span>
+ )}
+ <button type="submit" disabled={!dirty || !!repoErr || busy} className={primaryBtn}>
+ {busy ? 'Saving…' : 'Save'}
+ </button>
+ </div>
+ </div>
+ ) : (
+ <>
+ <p id="dv-value" className="mt-2 text-xs leading-5 text-zinc-300" data-dev-gain>
+ {accent ? <FoundLine state={state} /> : `Link your project's repo and ${DEV_GAIN}`}
+ </p>
+ {!accent && <div className="mt-3">{repoField}</div>}
+ <div className="mt-3 flex flex-wrap items-center gap-x-3 max-md:gap-y-1">
+ <button type="submit" className={turnOnBtn} disabled={busy} aria-describedby="dv-value" data-dev-turn-on>
+ {busy && <Loader2 size={13} aria-hidden="true" className="animate-spin motion-reduce:animate-none" />}
+ {busy ? 'Turning on…' : 'Turn on Dev mode'}
+ </button>
+ <button
+ type="button"
+ className="inline-flex items-center gap-1 min-h-8 max-md:min-h-11 px-1 text-xs text-sky-300 hover:text-sky-200 kw-focus rounded"
+ aria-expanded={details}
+ aria-controls="dv-details"
+ onClick={() => setDetails((d) => !d)}
+ data-dev-details
+ >
+ Details
+ <ChevronDown size={13} aria-hidden="true" className={`transition-transform duration-150 motion-reduce:transition-none ${details ? 'rotate-180' : ''}`} />
+ </button>
+ <span className="md:ml-auto max-md:w-full text-[11px] text-zinc-500">You can turn it off any time.</span>
+ </div>
+ {details && (
+ <div id="dv-details" className="mt-3 pt-3 border-t border-white/[.08] space-y-3">
+ {accent && repoField}
+ {branchField}
+ {backupField}
+ </div>
+ )}
+ {error && <div className="mt-3">{errorLine}</div>}
+ </>
)}
- <div className="flex items-center gap-2">
- {state.on ? (
- <button type="button" className={rowBtn} disabled={busy} onClick={() => put({ on: false })} data-dev-turn-off>
- Turn off Dev mode
- </button>
- ) : (
- <button type="button" className={rowBtn} disabled={busy} onClick={() => put({ on: true })} data-dev-turn-on>
- Turn on Dev mode
- </button>
- )}
- <span className="flex-1" />
- {saved && !dirty && (
- <span className="flex items-center gap-1 text-xs text-emerald-400" role="status">
- <Check size={13} aria-hidden="true" /> Saved
- </span>
- )}
- <button type="submit" disabled={!dirty || !!repoErr || busy} className={primaryBtn}>
- {busy ? 'Saving…' : 'Save'}
- </button>
- </div>
</form>
{/* 0.7.6: "Work from Jira · Off · Set up" (or the On box); nothing on a server without the Jira routes. */}
{state.on && <JiraSettings space={spaceId} teams={teams} />}
diff --git a/frontend/src/components/DevModeSuggestion.tsx b/frontend/src/components/DevModeSuggestion.tsx
new file mode 100644
index 00000000..bb62cf82
--- /dev/null
+++ b/frontend/src/components/DevModeSuggestion.tsx
@@ -0,0 +1,53 @@
+// Dev mode visibility (design.md §2): the slim "this space has code" strip above #general, in the
+// getting-started banner's slot and style. Turn on opens Settings › General at the Dev mode card (it never
+// switches Dev mode on by itself: that changes approvals and the production floor); Not now hides it for
+// this space for good. An offer, not news: an <aside> labelled by its title, never announced on load.
+
+import React from 'react';
+import { Code } from 'lucide-react';
+import type { DevModeState } from '../devMode';
+import { foundRepo, readableRepos } from '../devSuggest';
+import { useMedia } from '../useMedia';
+import { PHONE_QUERY } from '../layout';
+import { Btn } from './GetStarted';
+
+export const SUGGEST_SUB = 'Dev mode lets your bots review pull requests, show what landed and guard deploys.';
+export const SUGGEST_SUB_PHONE = 'Dev mode lets your bots review PRs and guard deploys.';
+/** Said once, out of sight, after Not now. */
+export const SUGGEST_HIDDEN = 'Hidden. Dev mode stays in Space settings › General.';
+
+export const DevModeSuggestion: React.FC<{ spaceName: string; state: DevModeState; onOpen: () => void; onDismiss: () => void }> = ({ spaceName, state, onOpen, onDismiss }) => {
+ const phone = useMedia(PHONE_QUERY);
+ const r = foundRepo(state);
+ if (!r) return null;
+ const more = readableRepos(state).length - 1;
+ const title = `${spaceName} has code: ${r.repo}${more > 0 ? ` and ${more} more` : ''}`;
+ return (
+ <aside
+ aria-labelledby="dv-sug-title"
+ data-dev-suggestion
+ className={`kw-fade-in border-b border-sky-500/20 bg-sky-500/[.06] ${phone ? 'px-3 py-2.5' : 'flex items-center gap-3 px-6 py-2.5'}`}
+ >
+ <div className="flex items-center gap-3 min-w-0 flex-1">
+ <span className="w-7 h-7 shrink-0 rounded-md bg-sky-500/15 text-sky-300 grid place-items-center">
+ <Code size={15} aria-hidden="true" />
+ </span>
+ <div className="min-w-0 flex-1">
+ <p id="dv-sug-title" className="text-xs font-medium text-zinc-100 truncate" title={title}>
+ {spaceName} has code: <span className="font-mono">{r.repo}</span>
+ {more > 0 ? ` and ${more} more` : ''}
+ </p>
+ <p className="text-[11.5px] text-zinc-400 truncate">{phone ? SUGGEST_SUB_PHONE : SUGGEST_SUB}</p>
+ </div>
+ </div>
+ <div className={`flex items-center gap-2 ${phone ? 'mt-2 justify-end' : ''}`}>
+ <Btn phone={phone} kind="secondary" className={phone ? '' : '!h-8'} onClick={onDismiss} data-dev-suggestion-dismiss>
+ Not now
+ </Btn>
+ <Btn phone={phone} kind="primary" className={phone ? '' : '!h-8'} onClick={onOpen} data-dev-suggestion-open>
+ Turn on Dev mode
+ </Btn>
+ </div>
+ </aside>
+ );
+};
diff --git a/frontend/src/components/GetStarted.tsx b/frontend/src/components/GetStarted.tsx
index 064f90c5..99e520a1 100644
--- a/frontend/src/components/GetStarted.tsx
+++ b/frontend/src/components/GetStarted.tsx
@@ -105,7 +105,7 @@ const Spinner: React.FC = () => (
/>
);
-const Btn: React.FC<React.ButtonHTMLAttributes<HTMLButtonElement> & { kind?: 'primary' | 'secondary' | 'link'; phone: boolean }> = ({
+export const Btn: React.FC<React.ButtonHTMLAttributes<HTMLButtonElement> & { kind?: 'primary' | 'secondary' | 'link'; phone: boolean }> = ({
kind = 'secondary',
phone,
className = '',
diff --git a/frontend/src/components/SpaceSettings.tsx b/frontend/src/components/SpaceSettings.tsx
index dbbed41b..2bfb6d24 100644
--- a/frontend/src/components/SpaceSettings.tsx
+++ b/frontend/src/components/SpaceSettings.tsx
@@ -424,6 +424,9 @@ const GeneralTab: React.FC<Props> = ({ space, spaces, kwants, teams, onSpaceSave
return (
<>
+ {/* First: the one setting here that changes what the bots do (name and icon are set once). */}
+ <DevModeSettings key={`dev-${space.id}`} spaceId={space.id} spaceName={space.name} approvals={space.approvals} teams={devTeamRefs(teams, kwants)} />
+
<form onSubmit={save} {...editorProps(dirty)} className={`${card} p-4 space-y-4`}>
<div className="flex items-center gap-3">
<SpaceTile space={{ id: space.id, icon, color: color || null }} size={44} />
@@ -505,8 +508,6 @@ const GeneralTab: React.FC<Props> = ({ space, spaces, kwants, teams, onSpaceSave
onChanged={() => onApprovalsChanged?.()}
/>
- <DevModeSettings key={`dev-${space.id}`} spaceId={space.id} spaceName={space.name} approvals={space.approvals} teams={devTeamRefs(teams, kwants)} />
-
<div className={`${card} p-4 space-y-3`}>
<p className="flex items-center gap-2 text-xs font-medium text-zinc-200">
<Archive size={14} className="text-zinc-400" /> Archive space
diff --git a/frontend/src/devSuggest.ts b/frontend/src/devSuggest.ts
new file mode 100644
index 00000000..cc829727
--- /dev/null
+++ b/frontend/src/devSuggest.ts
@@ -0,0 +1,82 @@
+// Dev mode visibility (autonomy/dev-mode-visibility/plan.md): the pure parts of the "this space has code"
+// suggestion in #general and of the Off card in Settings › General, so tests can check the gating and the
+// words without a DOM. Detection is the server's: GET /dev_mode sends `repos` even while Off.
+
+import { devApi, devStore, type DevModeState, type DevRepo } from './devMode';
+
+/** "Not now" for one space, for good, in this browser (the same pattern as the getting-started dismiss). */
+export const suggestKey = (space: string) => `kwnt:dev-suggest:${space}`;
+
+const store = (): Storage | null => {
+ try {
+ return typeof localStorage === 'undefined' ? null : localStorage;
+ } catch {
+ return null;
+ }
+};
+
+export const suggestDismissed = (space: string): boolean => {
+ try {
+ return store()?.getItem(suggestKey(space)) === 'dismissed';
+ } catch {
+ return false;
+ }
+};
+
+export function dismissSuggest(space: string): void {
+ try {
+ store()?.setItem(suggestKey(space), 'dismissed');
+ } catch {
+ /* private mode: it shows again next time, which is harmless */
+ }
+}
+
+/**
+ * Repos Dev mode can read after Turn on. `no_git` (the server has no git) and `no_repo` (a source with no
+ * fetch URL) leave nothing to watch, so "has code, turn it on" would be a dead end: they never count here,
+ * and a space with only those gets the quiet card, whose status lines explain the problem.
+ */
+export const readableRepos = (state: DevModeState | null | undefined): DevRepo[] =>
+ state ? state.repos.filter((r) => r.status !== 'no_git' && r.status !== 'no_repo') : [];
+
+/** The repo to name: the first readable one a team brought (team order), else the first readable one found. */
+export function foundRepo(state: DevModeState | null | undefined): DevRepo | null {
+ const repos = readableRepos(state);
+ if (!repos.length) return null;
+ return repos.find((r) => r.team) ?? repos[0];
+}
+
+/** Off and the server found a readable repo in one of the space's teams (or a hand-added one): the space has code. */
+export const hasFoundCode = (state: DevModeState | null | undefined): boolean => !!state && !state.on && readableRepos(state).length > 0;
+
+export interface SuggestGate {
+ /** The person is looking at the space's #general. */
+ inGeneral: boolean;
+ /** The space's Dev mode state; null while loading, after a failed GET or on a bot's 403. */
+ state: DevModeState | null;
+ dismissed: boolean;
+ /** The getting-started card or the setup banner is up: getting started wins. */
+ gettingStarted: boolean;
+ /**
+ * An AI account can run (canRunNow). false = nothing can run, so "Connect an AI account" is the one step
+ * that matters; null = still checking. Only true shows the suggestion.
+ */
+ canRun: boolean | null;
+}
+
+export const suggestShows = (g: SuggestGate): boolean =>
+ g.canRun === true && g.inGeneral && !g.dismissed && !g.gettingStarted && hasFoundCode(g.state);
+
+const asked = new Set<string>();
+/**
+ * The suggestion needs the open space's state, which the desktop rail asks for but a phone may not: ask once
+ * per space per page load when nothing is cached. A failed GET (or a bot's 403) leaves the store empty, so
+ * nothing shows.
+ */
+export function ensureDevState(space: string, get: (s: string) => Promise<DevModeState> = devApi.get): void {
+ if (devStore.get(space) || asked.has(space)) return;
+ asked.add(space);
+ get(space).then((st) => devStore.set(space, st), () => undefined);
+}
+/** Tests only. */
+export const _resetAsked = () => asked.clear();
diff --git a/frontend/src/firstScreen.ts b/frontend/src/firstScreen.ts
index f4686abf..0d276e6a 100644
--- a/frontend/src/firstScreen.ts
+++ b/frontend/src/firstScreen.ts
@@ -230,3 +230,30 @@ export function ringDevSettings(doc: Document = document, tries = 20): void {
}, reduce ? 0 : 160);
}, 1200);
}
+
+/** The static arrival outline on the Dev mode card (design.md §3); Tailwind sees the classes here. */
+const ARRIVED = ['outline', 'outline-2', 'outline-offset-2', 'outline-sky-400/60'];
+
+/**
+ * From the #general suggestion (dev-mode-visibility design.md §3): once the Dev mode card has mounted in
+ * Settings › General, bring it into view and focus its Turn on button (the card itself when Dev mode is
+ * already on), with a static outline on the card until focus first leaves it. No animation.
+ */
+export function focusDevSettings(doc: Document = document, tries = 40): void {
+ const el = doc.querySelector<HTMLElement>('[data-dev-settings]');
+ if (!el) {
+ if (tries > 0) setTimeout(() => focusDevSettings(doc, tries - 1), 50);
+ return;
+ }
+ el.scrollIntoView?.({ block: 'start', behavior: 'auto' });
+ (el.querySelector<HTMLElement>('[data-dev-turn-on]') ?? el).focus({ preventScroll: true });
+ el.classList.add(...ARRIVED);
+ el.setAttribute('data-dev-arrived', '');
+ const off = (e: FocusEvent) => {
+ if (e.relatedTarget instanceof Node && el.contains(e.relatedTarget)) return;
+ el.classList.remove(...ARRIVED);
+ el.removeAttribute('data-dev-arrived');
+ el.removeEventListener('focusout', off);
+ };
+ el.addEventListener('focusout', off);
+}
diff --git a/frontend/tests/devMode.test.mjs b/frontend/tests/devMode.test.mjs
index e4c707a3..4cf7e665 100644
--- a/frontend/tests/devMode.test.mjs
+++ b/frontend/tests/devMode.test.mjs
@@ -626,8 +626,12 @@ test('Settings › Dev mode: shown before the first switch-on with Turn on (0.9.
assert.ok(first, 'the header switch is gone, so the card must be there to turn it on the first time');
assert.doesNotMatch(first.textContent, /switch next to/);
assert.equal(first.querySelector('[data-dev-turn-off]'), null);
+ const setV = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value').set;
+ setV.call(first.querySelector('#dv-set-repo'), 'demo-org/demo-app');
+ first.querySelector('#dv-set-repo').dispatchEvent(new window.Event('input', { bubbles: true }));
+ await settle();
await click(first.querySelector('[data-dev-turn-on]'));
- assert.deepEqual(server.calls.filter(([meth]) => meth === 'PUT').at(-1)[2], { on: true });
+ assert.deepEqual(server.calls.filter(([meth]) => meth === 'PUT').at(-1)[2], { on: true, repo: 'demo-org/demo-app' });
assert.equal(m.devStore.isOn('spc_demo'), true);
v.root.unmount();
@@ -651,7 +655,8 @@ test('Settings › Dev mode: shown before the first switch-on with Turn on (0.9.
await click(form.querySelector('[data-dev-turn-off]'));
assert.deepEqual(server.calls.filter(([meth]) => meth === 'PUT').at(-1)[2], { on: false });
assert.equal(m.devStore.isOn('spc_demo'), false);
- assert.match(form.textContent, /Off\. Reviews, the ship gate and the production floor are stopped\. Approvals stay as you set them above\./);
+ assert.match(form.textContent, /Found demo-org\/demo-app\. Turn it on and your bots review pull requests/, 'back to the Off card, the repo kept');
+ assert.match(form.textContent, /You can turn it off any time\./);
assert.doesNotMatch(form.textContent, /approvals stay on/);
v.root.unmount();
});
diff --git a/frontend/tests/devModeVisibility.test.mjs b/frontend/tests/devModeVisibility.test.mjs
new file mode 100644
index 00000000..767c5384
--- /dev/null
+++ b/frontend/tests/devModeVisibility.test.mjs
@@ -0,0 +1,307 @@
+// Dev mode visibility (autonomy/dev-mode-visibility/plan.md, Pixel): the Dev mode card is first in
+// Settings › This space › General; Off sells (an accent card naming the found repo, its fields behind
+// Details; a quiet card with a primary Turn on when nothing was found), On is unchanged; the "this space
+// has code" suggestion in #general, its gating, Not now for good, and Turn on landing focused on the card.
+import assert from 'node:assert/strict';
+import test from 'node:test';
+import { readFileSync } from 'node:fs';
+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.window.matchMedia = g.window.matchMedia || ((q) => ({ matches: false, media: q, addEventListener() {}, removeEventListener() {} }));
+g.IS_REACT_ACT_ENVIRONMENT = false;
+
+const repo = (over = {}) => ({
+ key: 'github.com/demo-org/demo-app', repo: 'demo-org/demo-app', host: 'github.com', team: 'Dev team', team_id: 't1', from: 'repo', branch: 'main',
+ status: 'not_connected', poll_error: null, poll_code: null, polled_at: null, last_tag: null, added_by: 'team', provider: 'github', forge: 'github',
+ forge_connected: false, fresh_days: null, old_reviews_skipped: null, ...over,
+});
+const off = { on: false, 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 };
+const offFound = { ...off, repos: [repo()] };
+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.split('?')[0], body]);
+ const json = (b, status = 200) => new Response(JSON.stringify(b), { status, headers: { 'Content-Type': 'application/json' } });
+ if (server.status !== 200) return json({ error: 'Only the person can do that.' }, server.status);
+ if (u.includes('/dev_mode')) {
+ if (method === 'PUT') server.state = { ...server.state, ...body, polled_at: body.on ? '2026-11-14T09:00:00Z' : server.state.polled_at };
+ return json(server.state);
+ }
+ return json({});
+};
+
+const m = await loadBundled(`
+ export { default as React } from 'react';
+ export { createRoot } from 'react-dom/client';
+ export { devStore, devApi, parseDevMode } from './src/devMode';
+ export { DevModeSettings } from './src/components/DevModeSettings';
+ export { DevModeSuggestion } from './src/components/DevModeSuggestion';
+ export * from './src/devSuggest';
+ export { ringDevSettings, focusDevSettings } from './src/firstScreen';
+`);
+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 reset = (state = off, status = 200) => {
+ server = { state: { ...state }, status, calls: [] };
+ m.devStore._reset();
+ m._resetAsked();
+ localStorage.clear();
+ document.body.innerHTML = '';
+};
+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 click = async (el) => {
+ el.dispatchEvent(new MouseEvent('click', { bubbles: true }));
+ await settle();
+};
+const puts = () => server.calls.filter(([meth]) => meth === 'PUT').map(([, , b]) => b);
+const src = (f) => readFileSync(new URL(`../src/${f}`, import.meta.url), 'utf8');
+const state = (s) => m.parseDevMode(s);
+
+// ------------------------------------------------------------------ Settings › General
+
+test('General: the Dev mode card is first, above the name/icon/colour form and Approvals', () => {
+ const s = src('components/SpaceSettings.tsx');
+ const general = s.slice(s.indexOf('const GeneralTab'));
+ const dev = general.indexOf('<DevModeSettings');
+ assert.ok(dev > 0);
+ assert.ok(dev < general.indexOf('<form onSubmit={save}'), 'above the name form');
+ assert.ok(dev < general.indexOf('<SpaceApprovalsSetting'), 'above approvals');
+ assert.equal(general.split('<DevModeSettings').length, 2, 'once');
+});
+
+test('Off + repo found: accent card naming the repo and team, primary Turn on, fields behind Details and prefilled', async () => {
+ reset(offFound);
+ const v = await mount(h(m.DevModeSettings, { spaceId: 'spc_demo', spaceName: 'Demo' }));
+ const card = v.host.querySelector('[data-dev-settings]');
+ assert.equal(card.getAttribute('data-dev-off'), 'found');
+ assert.match(card.className, /border-sky-500\/40/);
+ assert.match(card.querySelector('[data-dev-gain]').textContent, /^Found demo-org\/demo-app in Dev team\. Turn it on and your bots review pull requests, show what landed and guard deploys\.$/);
+ const on = card.querySelector('[data-dev-turn-on]');
+ assert.match(on.className, /bg-sky-600/, 'primary');
+ assert.equal(on.textContent, 'Turn on Dev mode');
+ assert.equal(card.querySelector('#dv-set-repo'), null, 'fields are behind Details');
+ const details = card.querySelector('[data-dev-details]');
+ assert.equal(details.getAttribute('aria-expanded'), 'false');
+ assert.equal(details.getAttribute('aria-controls'), 'dv-details');
+ await click(details);
+ assert.equal(details.getAttribute('aria-expanded'), 'true');
+ assert.equal(card.querySelector('#dv-set-repo').value, 'demo-org/demo-app', 'prefilled from the found repo');
+ assert.equal(card.querySelector('#dv-set-branch').value, 'main');
+ assert.equal(on.getAttribute('type'), 'submit', 'Enter in a field turns it on');
+ assert.equal(card.querySelectorAll('button[type="submit"]').length, 1, 'no Save while Off');
+ await click(on);
+ assert.deepEqual(puts(), [{ on: true }], 'untouched prefill: just on');
+ assert.equal(m.devStore.isOn('spc_demo'), true);
+ assert.equal(v.host.querySelector('[data-dev-settings]').hasAttribute('data-dev-off'), false, 'now the On form');
+ v.root.unmount();
+});
+
+test('Off + repo found: a changed field in Details goes with Turn on', async () => {
+ reset(offFound);
+ const v = await mount(h(m.DevModeSettings, { spaceId: 'spc_demo', spaceName: 'Demo' }));
+ await click(v.host.querySelector('[data-dev-details]'));
+ const set = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value').set;
+ const b = v.host.querySelector('#dv-set-branch');
+ set.call(b, 'release');
+ b.dispatchEvent(new window.Event('input', { bubbles: true }));
+ await settle();
+ await click(v.host.querySelector('[data-dev-turn-on]'));
+ assert.deepEqual(puts(), [{ on: true, branch: 'release' }], 'only the changed field: the team repo stays watched as the team\'s');
+ v.root.unmount();
+});
+
+test('Off + nothing found: quiet card, a value line, the repo field with help, primary Turn on, an empty repo is refused', async () => {
+ reset({ ...off, repos: [] });
+ const v = await mount(h(m.DevModeSettings, { spaceId: 'spc_demo', spaceName: 'Demo' }));
+ const card = v.host.querySelector('[data-dev-settings]');
+ assert.equal(card.getAttribute('data-dev-off'), 'none');
+ assert.match(card.className, /border-zinc-800/);
+ assert.doesNotMatch(card.className, /border-sky/);
+ assert.match(card.querySelector('[data-dev-gain]').textContent, /^Link your project's repo and your bots review pull requests, show what landed and guard deploys\.$/);
+ assert.equal(card.querySelector('[data-dev-details]').getAttribute('aria-expanded'), 'false', 'Details holds branch and backup');
+ assert.equal(card.querySelector('#dv-set-branch'), null);
+ assert.ok(card.querySelector('#dv-set-repo'), 'the repo field is shown, not behind Details');
+ assert.equal(card.querySelector('#dv-set-repo').value, '');
+ assert.match(card.querySelector('#dv-set-repo-help').textContent, /Team settings › Git Repo/);
+ const on = card.querySelector('[data-dev-turn-on]');
+ assert.match(on.className, /bg-sky-600/);
+ assert.equal(card.querySelectorAll('button[type="submit"]').length, 1, 'no Save while Off');
+ await click(on);
+ assert.deepEqual(puts(), [], 'nothing to read yet: not turned on');
+ assert.match(card.querySelector('#dv-set-repo-err').textContent, /Add a repo first\./);
+ assert.equal(document.activeElement, card.querySelector('#dv-set-repo'));
+ const set = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value').set;
+ set.call(card.querySelector('#dv-set-repo'), 'demo-org/demo-app');
+ card.querySelector('#dv-set-repo').dispatchEvent(new window.Event('input', { bubbles: true }));
+ await settle();
+ await click(on);
+ assert.deepEqual(puts(), [{ on: true, repo: 'demo-org/demo-app' }]);
+ v.root.unmount();
+});
+
+test('On: unchanged form (repo, branch, backup, Turn off, primary Save), no accent, no Details', async () => {
+ reset({ ...off, on: true, repo: 'demo-org/demo-app', branch: 'main', polled_at: 'x', repos: [repo({ status: 'watching' })] });
+ const v = await mount(h(m.DevModeSettings, { spaceId: 'spc_demo', spaceName: 'Demo' }));
+ const card = v.host.querySelector('[data-dev-settings]');
+ assert.equal(card.hasAttribute('data-dev-off'), false);
+ assert.doesNotMatch(card.className, /border-sky/);
+ assert.equal(card.querySelector('[data-dev-details]'), null);
+ assert.equal(card.querySelector('[data-dev-turn-on]'), null);
+ assert.ok(card.querySelector('[data-dev-turn-off]'));
+ assert.equal(card.querySelector('#dv-set-repo').value, 'demo-org/demo-app');
+ assert.match(card.querySelector('button[type="submit"]').className, /bg-sky-600/);
+ assert.match(card.textContent, /Demo reads this repo to show what landed, review PRs and guard deploys\./);
+ v.root.unmount();
+});
+
+// ------------------------------------------------------------------ The suggestion
+
+test('Suggestion: shows only in #general, Off, a repo found, not dismissed, no getting started, and a loaded state', () => {
+ const s = state(offFound);
+ const base = { inGeneral: true, state: s, dismissed: false, gettingStarted: false, canRun: true };
+ assert.equal(m.suggestShows(base), true);
+ assert.equal(m.suggestShows({ ...base, inGeneral: false }), false, 'other chats');
+ assert.equal(m.suggestShows({ ...base, dismissed: true }), false, 'Not now');
+ assert.equal(m.suggestShows({ ...base, gettingStarted: true }), false, 'getting started wins');
+ assert.equal(m.suggestShows({ ...base, state: null }), false, 'loading, a failed GET or a 403');
+ assert.equal(m.suggestShows({ ...base, state: state({ ...offFound, on: true }) }), false, 'Dev mode on');
+ assert.equal(m.suggestShows({ ...base, state: state({ ...off, repos: [] }) }), false, 'no repo found');
+ const app = src('App.tsx');
+ assert.match(app, /suggestShows\(\{ inGeneral: isGeneral, state: devState, dismissed: suggestDismissed\(space\.id\), gettingStarted: !!setupBanner \|\| !!getStartedCard, canRun \}\)/);
+ assert.match(app, /setupBanner \?\? \(\s*<>\s*\{devSuggest\}\s*\{devSuggestStatus\}/);
+ assert.match(app, /data-dev-suggestion-status>\s*\{suggestHiddenIn === space\.id \? SUGGEST_HIDDEN : ''\}/, 'the live region is there before Not now fills it');
+});
+
+test('Round 2: no AI account (canRun false) or still checking (null) hides the suggestion', () => {
+ const base = { inGeneral: true, state: state(offFound), dismissed: false, gettingStarted: false, canRun: true };
+ assert.equal(m.suggestShows(base), true);
+ assert.equal(m.suggestShows({ ...base, canRun: false }), false, 'no account: "Connect an AI account" is the one step');
+ assert.equal(m.suggestShows({ ...base, canRun: null }), false, 'still checking');
+});
+
+test('Round 2: only no_git / no_repo repos: no suggestion, and the Off card is the quiet grey one', async () => {
+ const dead = { ...off, repos: [repo({ status: 'no_git' }), repo({ key: 'x/y', repo: 'demo-org/no-url', status: 'no_repo', team: 'Ops', team_id: 't2' })] };
+ const s = state(dead);
+ assert.equal(s.repos.length, 2);
+ assert.deepEqual(m.readableRepos(s), []);
+ assert.equal(m.hasFoundCode(s), false);
+ assert.equal(m.foundRepo(s), null);
+ assert.equal(m.suggestShows({ inGeneral: true, state: s, dismissed: false, gettingStarted: false, canRun: true }), false);
+ reset(dead);
+ const v = await mount(h(m.DevModeSettings, { spaceId: 'spc_demo', spaceName: 'Demo' }));
+ const card = v.host.querySelector('[data-dev-settings]');
+ assert.equal(card.getAttribute('data-dev-off'), 'none', 'quiet card');
+ assert.doesNotMatch(card.className, /border-sky-500\/40/, 'no accent');
+ assert.doesNotMatch(card.textContent, /Found /);
+ v.root.unmount();
+});
+
+test('Round 2: one readable repo among no_git / no_repo ones: shown and named, "and N more" counts readable only', async () => {
+ const mixed = {
+ ...off,
+ repos: [
+ repo({ key: 'a', repo: 'demo-org/no-git', status: 'no_git' }),
+ repo({ key: 'b', repo: 'demo-org/no-url', status: 'no_repo' }),
+ repo({ key: 'c', repo: 'demo-org/web', status: 'watching', team: 'Web team', team_id: 't3' }),
+ ],
+ };
+ const s = state(mixed);
+ assert.equal(m.foundRepo(s).repo, 'demo-org/web');
+ assert.equal(m.suggestShows({ inGeneral: true, state: s, dismissed: false, gettingStarted: false, canRun: true }), true);
+ reset(mixed);
+ const sug = await mount(h(m.DevModeSuggestion, { spaceName: 'Demo', state: s, onOpen() {}, onDismiss() {} }));
+ const title = sug.host.querySelector('#dv-sug-title').textContent;
+ assert.equal(title, 'Demo has code: demo-org/web', 'named, and no "and 2 more"');
+ sug.root.unmount();
+ const v = await mount(h(m.DevModeSettings, { spaceId: 'spc_demo', spaceName: 'Demo' }));
+ const card = v.host.querySelector('[data-dev-settings]');
+ assert.equal(card.getAttribute('data-dev-off'), 'found');
+ assert.match(card.querySelector('[data-dev-gain]').textContent, /^Found demo-org\/web in Web team\. Turn it on/);
+ v.root.unmount();
+});
+
+test('Suggestion: a failed or 403 GET leaves nothing to show, and the state is asked for once per space', async () => {
+ reset(offFound, 403);
+ m.ensureDevState('spc_demo');
+ m.ensureDevState('spc_demo');
+ await settle();
+ assert.equal(server.calls.length, 1, 'once, not per render');
+ assert.equal(m.devStore.get('spc_demo'), null);
+ assert.equal(m.suggestShows({ inGeneral: true, state: m.devStore.get('spc_demo'), dismissed: false, gettingStarted: false, canRun: true }), false);
+ reset(offFound);
+ m.ensureDevState('spc_demo');
+ await settle();
+ assert.equal(m.suggestShows({ inGeneral: true, state: m.devStore.get('spc_demo'), dismissed: false, gettingStarted: false, canRun: true }), true);
+ m.ensureDevState('spc_demo');
+ await settle();
+ assert.equal(server.calls.length, 1, 'cached: no second GET');
+});
+
+test('Suggestion: names the space and repo; Not now persists for that space across a reload; other spaces unaffected', async () => {
+ reset(offFound);
+ let opened = 0;
+ let hidden = 0;
+ const v = await mount(h(m.DevModeSuggestion, { spaceName: 'Demo', state: state(offFound), onOpen: () => opened++, onDismiss: () => { m.dismissSuggest('spc_demo'); hidden++; } }));
+ const el = v.host.querySelector('[data-dev-suggestion]');
+ assert.equal(el.tagName, 'ASIDE');
+ assert.equal(el.getAttribute('aria-labelledby'), 'dv-sug-title');
+ assert.equal(el.getAttribute('role'), null, 'an offer, not announced on load');
+ assert.match(el.textContent, /Demo has code: demo-org\/demo-app/);
+ assert.match(el.textContent, /Dev mode lets your bots review pull requests, show what landed and guard deploys\./);
+ const [notNow, turnOn] = [el.querySelector('[data-dev-suggestion-dismiss]'), el.querySelector('[data-dev-suggestion-open]')];
+ assert.equal(notNow.textContent, 'Not now');
+ assert.equal(turnOn.textContent, 'Turn on Dev mode');
+ await click(turnOn);
+ assert.equal(opened, 1);
+ assert.deepEqual(puts(), [], 'Turn on here never switches Dev mode on by itself');
+ await click(notNow);
+ assert.equal(hidden, 1);
+ assert.equal(localStorage.getItem('kwnt:dev-suggest:spc_demo'), 'dismissed');
+ // A reload: a fresh copy of the module (no state in memory) reads the same storage.
+ const fresh = await loadBundled(`export * from './src/devSuggest';`);
+ assert.equal(fresh.suggestDismissed('spc_demo'), true);
+ assert.equal(fresh.suggestDismissed('spc_other'), false, 'per space');
+ assert.equal(fresh.suggestShows({ inGeneral: true, state: state(offFound), dismissed: fresh.suggestDismissed('spc_demo'), gettingStarted: false, canRun: true }), false);
+ v.root.unmount();
+});
+
+test('Suggestion → Settings: Turn on opens General and focuses the Dev mode card (scrolled into view)', async () => {
+ reset(offFound);
+ // The card mounts after Settings opens: focusDevSettings waits for it.
+ m.focusDevSettings(document, 20);
+ const v = await mount(h(m.DevModeSettings, { spaceId: 'spc_demo', spaceName: 'Demo' }));
+ await settle();
+ const card = v.host.querySelector('[data-dev-settings]');
+ let scrolled = 0;
+ card.scrollIntoView = () => scrolled++;
+ await new Promise((r) => setTimeout(r, 120));
+ assert.equal(document.activeElement, card.querySelector('[data-dev-turn-on]'), 'focus lands on the card\'s Turn on');
+ assert.ok(card.contains(document.activeElement));
+ assert.equal(card.hasAttribute('data-dev-arrived'), true, 'outlined');
+ assert.equal(card.getAttribute('tabindex'), '-1');
+ assert.equal(card.getAttribute('aria-labelledby'), 'dv-title');
+ assert.equal(scrolled, 1);
+ assert.equal(card.getAttribute('data-dev-off'), 'found', 'the repo is there to turn on');
+ const app = src('App.tsx');
+ assert.match(app, /const openDevSuggest = \(\) => \{\s*openSpaceSettings\('general'\);\s*focusDevSettings\(\);/);
+ v.root.unmount();
+});