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.

0.7.1: Dev mode switch is the Branch switch (one press on, two presses off) (#343)

Oleksandr Ivanchenkoa37b6f81525a
diff --git a/frontend/src/components/DevModeSwitch.tsx b/frontend/src/components/DevModeSwitch.tsx
index 473a2674..8aad5d43 100644
--- a/frontend/src/components/DevModeSwitch.tsx
+++ b/frontend/src/components/DevModeSwitch.tsx
@@ -1,10 +1,11 @@
-// The Dev mode switch in the sidebar space header: a safety cover over a launch switch (design §1).
-// Press 1 lifts the cover, press 2 flips (or opens the setup sheet the first time). A lifted cover
-// drops back after 5 s, on Esc or when focus leaves. Presses are ignored while a flip settles.
-// It's a <button>, not role="switch": a switch promises one press.
+// The Dev mode switch in the sidebar space header (style v2 §10, flow F1/F2/F9): the Branch switch.
+// Off has no cover: one press turns it on (F1). On is covered by a 1 px violet ring and a lock; turning
+// it off takes two presses (F2): press 1 arms (2 px amber ring, open lock, `off?`), press 2 within 5 s
+// turns it off. Armed drops back after 5 s, on Esc or when focus leaves. Presses are ignored while a
+// flip settles (450 ms), so a double-click on Off can't turn it on and arm it.
-import React, { useCallback, useEffect, useRef, useState, useSyncExternalStore } from 'react';
-import { Code, Lock, LockOpen, X } from 'lucide-react';
+import React, { useCallback, useEffect, useId, useRef, useState, useSyncExternalStore } from 'react';
+import { Lock, LockOpen, X } from 'lucide-react';
import {
DROP_MS,
RECOVER_MS,
@@ -52,12 +53,14 @@ export interface DevModeSwitchProps {
phone?: boolean;
/** Dev mode went off: the sidebar shows the turned-off note. */
onTurnedOff?: () => void;
+ /** Dev mode went on: the sidebar shows the HEAD → dev note. */
+ onTurnedOn?: () => void;
/** Test hooks: start in a given state, and a clock. */
initial?: Partial<SwitchState>;
now?: () => number;
}
-export const DevModeSwitch: React.FC<DevModeSwitchProps> = ({ space, phone = false, onTurnedOff, initial, now = Date.now }) => {
+export const DevModeSwitch: React.FC<DevModeSwitchProps> = ({ space, phone = false, onTurnedOff, onTurnedOn, initial, now = Date.now }) => {
const reduced = useReducedMotion();
const known = useDevMode(space.id);
const [state, setState] = useState<SwitchState>(() =>
@@ -124,11 +127,12 @@ export const DevModeSwitch: React.FC<DevModeSwitchProps> = ({ space, phone = fal
devStore.set(space.id, s);
dispatch({ type: 'saved', on: s.on });
if (!s.on && was?.on) onTurnedOff?.();
+ if (s.on && !was?.on) onTurnedOn?.();
},
(e: unknown) => dispatch({ type: 'save_failed', error: e instanceof Error ? e.message : 'Dev mode couldn’t be changed.' }),
);
},
- [space.id, dispatch, onTurnedOff],
+ [space.id, dispatch, onTurnedOff, onTurnedOn],
);
const press = () => {
@@ -138,18 +142,20 @@ export const DevModeSwitch: React.FC<DevModeSwitchProps> = ({ space, phone = fal
};
const look = switchLook(state);
+ const descId = useId();
const hint = look.hint && (
<span
role="presentation"
className={
phone
? 'kw-dv-hint fixed inset-x-4 mx-auto w-fit max-w-[calc(100vw-32px)] text-center leading-snug bottom-[calc(56px+env(safe-area-inset-bottom)+12px)] z-40 rounded-lg border border-white/14 bg-surface-overlay px-2.5 py-1.5 text-meta text-zinc-100 shadow-raised'
- : 'kw-dv-hint absolute -right-9 top-full mt-1.5 z-30 whitespace-nowrap rounded-lg border border-white/14 bg-surface-overlay px-2.5 py-1.5 text-meta text-zinc-100 shadow-raised'
+ : 'kw-dv-hint absolute -left-[52px] top-full mt-1.5 z-30 whitespace-nowrap rounded-lg border border-white/14 bg-surface-overlay px-2 py-1.5 text-meta text-zinc-100 shadow-raised'
}
aria-hidden="true"
data-dv-hint
>
{look.hint}
+ {!phone && <kbd className="dv-kbd ml-1.5">Esc</kbd>}
</span>
);
@@ -165,9 +171,13 @@ export const DevModeSwitch: React.FC<DevModeSwitchProps> = ({ space, phone = fal
},
onBlur: () => dispatch({ type: 'blur' }),
disabled: state.disabled,
+ role: 'switch' as const,
+ 'aria-checked': state.on,
'aria-label': look.label,
+ 'aria-describedby': descId,
title: look.tooltip,
'data-dev-switch': state.phase,
+ 'data-look': look.look,
'data-on': state.on || undefined,
'data-ring': look.ring || undefined,
'data-knob': look.knobRight ? 'right' : 'left',
@@ -175,33 +185,33 @@ export const DevModeSwitch: React.FC<DevModeSwitchProps> = ({ space, phone = fal
style: { ['--kw-dv-fill' as string]: String(look.fill) } as React.CSSProperties,
};
- const button = state.reduced ? (
- <button {...common} className="kw-dv-rm focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-sky-400">
- <span className="text-meta font-semibold text-zinc-300" aria-hidden="true">
- Dev
- </span>
- <span className="kw-dv-track" aria-hidden="true">
- <span className="kw-dv-fill" />
- <span className="kw-dv-knob">
- {state.phase === 'lifted' || state.phase === 'pending' ? (
- <LockOpen size={8} strokeWidth={2.6} className="text-sky-600" data-dv-glyph="unlocked" />
- ) : (
- <Lock size={8} strokeWidth={2.6} className="text-sky-600" data-dv-glyph="locked" />
- )}
- </span>
- </span>
- </button>
- ) : (
- <button {...common} className="kw-dv focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-sky-400">
- <span className="kw-dv-track" aria-hidden="true">
- <span className="kw-dv-fill" />
- <span className="kw-dv-ring" />
- <span className="kw-dv-knob" />
- </span>
- <span className="kw-dv-cover" aria-hidden="true">
- &lt;/&gt;
+ // The Branch switch (style v2 §10): a mono label and a tiny git graph. The node sits on the line
+ // when off and hops onto the fork when on; then the cover (a 1 px violet ring, ::after) closes and a
+ // lock shows. Armed (only ever while on) lifts it: 2 px amber ring, open lock, the fork dashed amber
+ // with a halo on the node, `off?`. Reduced motion keeps the same shapes, instantly (kw-dv-rm).
+ const armed = look.look === 'armed';
+ const word = armed ? 'off?' : 'dev';
+ const button = (
+ <button
+ {...common}
+ data-armed={armed || undefined}
+ data-covered={(look.ring && !armed) || undefined}
+ className={`kw-dv${state.reduced ? ' kw-dv-rm' : ''}${phone ? ' h-11' : ''} focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-sky-400`}
+ >
+ {look.glyph === 'locked' && <Lock size={10} strokeWidth={2.5} className="kw-dv-lock" aria-hidden="true" data-dv-glyph="locked" />}
+ {look.glyph === 'unlocked' && <LockOpen size={10} strokeWidth={2.5} className="kw-dv-lock" aria-hidden="true" data-dv-glyph="unlocked" />}
+ <span className="kw-dv-lbl" aria-hidden="true" data-dv-word>
+ {word}
</span>
- <span className="kw-dv-hinge" aria-hidden="true" />
+ <svg className="kw-dv-graph" viewBox="0 0 44 24" aria-hidden="true" data-dv-graph>
+ <path className="kw-dv-base" d="M2 17H42" />
+ <path className="kw-dv-fork" d="M12 17C19 17 18 7 26 7H42" />
+ <g className="kw-dv-node">
+ <circle className="kw-dv-halo" cx="12" cy="17" r="5" />
+ <circle className="kw-dv-dot" cx="12" cy="17" r="5" />
+ <circle className="kw-dv-pip" cx="12" cy="17" r="1.6" />
+ </g>
+ </svg>
</button>
);
@@ -209,6 +219,9 @@ export const DevModeSwitch: React.FC<DevModeSwitchProps> = ({ space, phone = fal
<span className={`relative inline-flex shrink-0 items-center justify-center ${phone ? 'min-w-[44px] min-h-[44px]' : ''}`} data-dev-switch-wrap>
{button}
{hint}
+ <span id={descId} className="sr-only" data-dv-describe>
+ {look.describe}
+ </span>
<span className="sr-only" aria-live="polite" data-dv-live>
{state.announce ? <span key={state.announce.seq}>{state.announce.text}</span> : null}
</span>
@@ -230,6 +243,7 @@ export const DevModeSwitch: React.FC<DevModeSwitchProps> = ({ space, phone = fal
devStore.set(space.id, s);
dispatch({ type: 'setup_done', now: now() });
dispatch({ type: 'saved', on: s.on });
+ if (s.on) onTurnedOn?.();
btn.current?.focus();
}}
/>
@@ -238,18 +252,22 @@ export const DevModeSwitch: React.FC<DevModeSwitchProps> = ({ space, phone = fal
);
};
-/** "Dev mode is off." under the space header: role=status, 10 s or until dismissed. */
-export const DevOffNote: React.FC<{ approvals?: string; onDismiss: () => void; ms?: number }> = ({ approvals, onDismiss, ms = 10_000 }) => {
+/**
+ * The flip note under the space header (style v2 §10): on reads `HEAD → dev` + "Dev mode is on for
+ * {space}." with one caret blink; off reads `merged into main` + "Dev mode is off. Approvals stay on
+ * {approvals}." role=status, 10 s or until dismissed.
+ */
+export const DevFlipNote: React.FC<{ on: boolean; space?: string; approvals?: string; onDismiss: () => void; ms?: number }> = ({ on, space, approvals, onDismiss, ms = 10_000 }) => {
useEffect(() => {
const t = setTimeout(onDismiss, ms);
return () => clearTimeout(t);
}, [onDismiss, ms]);
return (
- <div role="status" data-dev-off-note className="mt-1.5 flex items-start gap-2 rounded-xl border border-white/14 bg-surface-raised px-2.5 py-2 text-meta text-zinc-300">
- <Code size={13} className="mt-px shrink-0 text-zinc-400" aria-hidden="true" />
- <p className="min-w-0 flex-1">
- <strong className="font-semibold text-zinc-100">Dev mode is off.</strong> Reviews, the ship gate and the production floor stopped. Approvals stay on {approvalsWord(approvals)}. What
- landed keeps its history.
+ <div role="status" data-dev-flip-note={on ? 'on' : 'off'} {...(on ? {} : { 'data-dev-off-note': '' })} className="kw-dv-note mt-1.5 flex items-start gap-2 rounded-xl border border-white/14 bg-surface-overlay px-2.5 py-2 text-meta text-zinc-200 shadow-raised">
+ <p className="min-w-0 flex-1 leading-snug">
+ <span className="font-mono font-semibold text-sky-300 whitespace-nowrap">{on ? 'HEAD → dev' : 'merged into main'}</span>
+ {on && <span className="dv-caret" aria-hidden="true" />}{' '}
+ {on ? `Dev mode is on for ${space ?? 'this space'}.` : `Dev mode is off. Approvals stay on ${approvalsWord(approvals)}.`}
</p>
<button type="button" onClick={onDismiss} aria-label="Dismiss" className="-m-1 p-1 shrink-0 rounded text-zinc-400 hover:text-zinc-100 focus-visible:outline focus-visible:outline-2 focus-visible:outline-sky-400">
<X size={13} aria-hidden="true" />
@@ -258,6 +276,9 @@ export const DevOffNote: React.FC<{ approvals?: string; onDismiss: () => void; m
);
};
+/** The turned-off note (kept for callers): the flip note's off side. */
+export const DevOffNote: React.FC<{ approvals?: string; onDismiss: () => void; ms?: number }> = (p) => <DevFlipNote on={false} {...p} />;
+
/** The </> badge with its caret on a space tile; `behind` is the surface it sits on. */
export const DevBadge: React.FC<{ behind?: string }> = ({ behind }) => (
<span className="kw-dev-badge" aria-hidden="true" data-dev-badge style={behind ? ({ ['--kw-dev-behind' as string]: behind } as React.CSSProperties) : undefined}>
diff --git a/frontend/src/components/Sidebar.tsx b/frontend/src/components/Sidebar.tsx
index 9172960a..d1d977bb 100644
--- a/frontend/src/components/Sidebar.tsx
+++ b/frontend/src/components/Sidebar.tsx
@@ -17,7 +17,7 @@ import { layaRoutes } from '../channels';
import { InstallAppButton } from './InstallAppButton';
import { trapFocusTarget } from '../imports';
import { type NeedsYouRow, workingIds, directIds } from '../chatsTab';
-import { DevModeSwitch, DevOffNote, useDevMode } from './DevModeSwitch';
+import { DevModeSwitch, DevFlipNote, useDevMode } from './DevModeSwitch';
import { DevDeskRow } from './DevDesk';
import { IdeaJarRow } from './IdeaJarRow';
@@ -373,13 +373,16 @@ export const Sidebar: React.FC<SidebarProps> = ({
};
const offLine = spaceOffLine(space.approvals, kwants);
- // Dev mode: the switch sits between the name and the gear; on, the meta line says the branch.
+ // Dev mode: on phones the switch sits after the name; on desktop it has its own row under it; on, the meta line says the branch.
const dev = useDevMode(space.id);
const devOn = !!dev?.on;
- const [devOffNote, setDevOffNote] = useState(false);
- const dismissDevOff = useCallback(() => setDevOffNote(false), []);
- useEffect(() => setDevOffNote(false), [space.id]);
- const devSwitch = <DevModeSwitch key={space.id} space={space} phone={phone} onTurnedOff={() => setDevOffNote(true)} />;
+ // The flip note under the header: 'on' (HEAD → dev) or 'off' (merged into main), or none.
+ const [devNote, setDevNote] = useState<'on' | 'off' | null>(null);
+ const dismissDevNote = useCallback(() => setDevNote(null), []);
+ useEffect(() => setDevNote(null), [space.id]);
+ const devSwitch = (
+ <DevModeSwitch key={space.id} space={space} phone={phone} onTurnedOff={() => setDevNote('off')} onTurnedOn={() => setDevNote('on')} />
+ );
const devMeta = devOn ? (
<span className="block text-meta text-zinc-400 truncate" data-dev-meta>
Dev · <span className="font-mono text-sky-300">{dev?.branch ?? 'main'}</span>
@@ -735,7 +738,6 @@ export const Sidebar: React.FC<SidebarProps> = ({
<h1 className="text-body font-semibold text-zinc-50 truncate">{space.name}</h1>
{devMeta ?? <span className="block text-meta text-zinc-400 truncate" title={spaceSummaryTitle(space.counts)}>{spaceSummary(space.counts)}</span>}
</span>
- {devSwitch}
<button
type="button"
onClick={() => {
@@ -751,7 +753,14 @@ export const Sidebar: React.FC<SidebarProps> = ({
</button>
</div>
)}
- {devOffNote && <DevOffNote approvals={space.approvals} onDismiss={dismissDevOff} />}
+ {/* Desktop: the switch has its own 32 px row under the name, starting where the name text
+ starts (6 px pad + 32 px tile + 10 px gap), so it never squeezes the name or subtitle. */}
+ {!phone && (
+ <div className="h-8 flex items-center pl-12" data-dev-switch-row>
+ {devSwitch}
+ </div>
+ )}
+ {devNote && <DevFlipNote key={devNote} on={devNote === 'on'} space={space.name} approvals={space.approvals} onDismiss={dismissDevNote} />}
{offLine && (
<button
type="button"
diff --git a/frontend/src/devMode.ts b/frontend/src/devMode.ts
index d3a4948b..04bf2cfa 100644
--- a/frontend/src/devMode.ts
+++ b/frontend/src/devMode.ts
@@ -154,7 +154,12 @@ const say = (s: SwitchState, text: string) => ({ text, seq: (s.announce?.seq ??
export const onText = (space: string) => `Dev mode on for ${space}.`;
export const offText = (space: string) => `Dev mode off for ${space}. Reviews, the ship gate and the production floor stopped.`;
-export const liftText = (on: boolean) => `Unlocked. Press again to turn Dev mode ${on ? 'off' : 'on'}.`;
+/** Flow copy §2: the armed line, announced politely when the cover lifts. Only "on" can arm (F2). */
+export const ARMED_TEXT = 'Press again to turn Dev mode off, or Escape to keep it on.';
+/** Flow copy §2: the 5 s run out, Esc, or focus left. */
+export const STAYS_ON_TEXT = 'Dev mode stays on.';
+/** @deprecated kept for callers; arming only happens while on. */
+export const liftText = (_on: boolean) => ARMED_TEXT;
/**
* The switch's state machine. Pure: time comes in on the actions, and the component runs the timers
@@ -167,18 +172,23 @@ export function switchReducer(s: SwitchState, a: SwitchAction, space = 'this spa
if (s.phase === 'pending') return s;
// A fast double-click: the second press lands while the cover settles, and is ignored.
if (s.phase === 'settling' || a.now < s.settleUntil) return s;
- if (s.phase === 'covered') return { ...s, phase: 'lifted', liftedAt: a.now, error: null, announce: say(s, liftText(s.on)) };
- // phase lifted: the second press flips, or opens the setup the first time
- if (!s.on && s.setup) return { ...s, phase: 'pending', liftedAt: null, announce: say(s, 'Dev mode, setting up.') };
- return flip(s, !s.on, a.now, space);
+ // Flow F1: on only adds guards, so off has no cover and one press turns it on (or opens the
+ // setup the first time, on a server that still needs it).
+ if (!s.on) {
+ if (s.setup) return { ...s, phase: 'pending', liftedAt: null, error: null, announce: say(s, 'Dev mode, setting up.') };
+ return flip(s, true, a.now, space);
+ }
+ // F2: off removes the guards, so it takes two presses: arm, then confirm within 5 s.
+ if (s.phase === 'covered') return { ...s, phase: 'lifted', liftedAt: a.now, error: null, announce: say(s, ARMED_TEXT) };
+ return flip(s, false, a.now, space);
}
case 'recover':
if (s.phase !== 'lifted' || s.liftedAt === null || a.now - s.liftedAt < RECOVER_MS) return s;
- return { ...s, phase: 'covered', liftedAt: null, announce: say(s, 'Locked.') };
+ return { ...s, phase: 'covered', liftedAt: null, announce: say(s, STAYS_ON_TEXT) };
case 'escape':
case 'blur':
if (s.phase !== 'lifted') return s;
- return { ...s, phase: 'covered', liftedAt: null, announce: say(s, 'Locked.') };
+ return { ...s, phase: 'covered', liftedAt: null, announce: say(s, STAYS_ON_TEXT) };
case 'settled':
if (s.phase !== 'settling' || a.now < s.settleUntil) return s;
return { ...s, phase: 'covered' };
@@ -187,7 +197,7 @@ export function switchReducer(s: SwitchState, a: SwitchAction, space = 'this spa
return flip({ ...s, setup: false }, true, a.now, space);
case 'setup_cancel':
if (s.phase !== 'pending') return s;
- return { ...s, phase: 'covered', liftedAt: null, announce: say(s, 'Locked.') };
+ return { ...s, phase: 'covered', liftedAt: null, announce: null };
case 'saved':
return { ...s, saving: false, on: a.on, setup: a.on ? false : s.setup };
case 'save_failed':
@@ -220,37 +230,55 @@ function flip(s: SwitchState, on: boolean, now: number, space: string): SwitchSt
}
/** What the switch looks like: cover open or closed, knob side, fill opacity, ring and hint. */
+/** The visual state the switch draws: off, armed (first press), on, pending (setup sheet open),
+ * disabled. Styles key off this (data-look), so a new look is CSS plus the glyph map. */
+export type SwitchLookName = 'off' | 'armed' | 'on' | 'pending' | 'disabled';
+/** The icon in the knob: the code mark at rest, an open lock when armed, a closed lock when disabled. */
+export type SwitchGlyph = 'code' | 'unlocked' | 'locked';
+
export interface SwitchLook {
+ look: SwitchLookName;
+ glyph: SwitchGlyph;
coverOpen: boolean;
knobRight: boolean;
fill: number;
ring: boolean;
hint: string | null;
+ /** aria-label: role="switch" carries on/off in aria-checked, so this is just the name. */
label: string;
+ /** aria-describedby text (flow copy §1). */
+ describe: string;
tooltip: string;
}
+export const OFF_TOOLTIP = 'Dev mode: plain-words merges, code reviews, production floor';
+export const ON_TOOLTIP = 'Dev mode is on. Press twice to turn it off.';
+export const OWNER_TOOLTIP = 'Only the space owner can change Dev mode.';
+export const OFF_DESCRIBE = 'Turns on reviews, the ship gate and the production floor.';
+export const ON_DESCRIBE = 'Press twice to turn off.';
+export const ARMED_HINT = 'Press again to turn Dev mode off';
+
export function switchLook(s: SwitchState): SwitchLook {
- const unavailable = s.disabled ? ', unavailable' : '';
- const tooltip = s.disabled ? 'Only the space owner can change Dev mode' : `Dev mode is ${s.on ? 'on' : 'off'}. Press to unlock.`;
+ const base = switchParts(s);
+ const look: SwitchLookName = s.disabled ? 'disabled' : s.phase === 'pending' ? 'pending' : s.phase === 'lifted' ? 'armed' : s.on ? 'on' : 'off';
+ // The lock: shut while on and covered (guards locked in) or not the owner, open while armed.
+ const glyph: SwitchGlyph = s.disabled ? 'locked' : s.phase === 'lifted' ? 'unlocked' : s.on ? 'locked' : 'code';
+ return { look, glyph, ...base };
+}
+
+function switchParts(s: SwitchState): Omit<SwitchLook, 'look' | 'glyph'> {
+ const tooltip = s.disabled ? OWNER_TOOLTIP : s.on ? ON_TOOLTIP : OFF_TOOLTIP;
+ const describe = s.disabled ? OWNER_TOOLTIP : s.on ? ON_DESCRIBE : OFF_DESCRIBE;
+ const common = { label: 'Dev mode', describe, tooltip };
switch (s.phase) {
case 'lifted':
- return {
- coverOpen: true,
- knobRight: s.on,
- fill: s.on ? 1 : 0,
- ring: true,
- hint: `Press again to turn Dev mode ${s.on ? 'off' : 'on'}`,
- label: `Dev mode, ${s.on ? 'on' : 'off'}. Unlocked. Press again to turn it ${s.on ? 'off' : 'on'}`,
- tooltip,
- };
+ return { coverOpen: true, knobRight: true, fill: 1, ring: true, hint: ARMED_HINT, ...common };
case 'pending':
- return { coverOpen: true, knobRight: true, fill: 0.45, ring: true, hint: null, label: 'Dev mode, setting up.', tooltip };
+ return { coverOpen: true, knobRight: true, fill: 0.45, ring: false, hint: null, ...common, describe: 'Setting up.' };
case 'settling':
- // Open while it settles, then it drops; the label is already the final state.
- return { coverOpen: true, knobRight: s.on, fill: s.on ? 1 : 0, ring: false, hint: null, label: `Dev mode, ${s.on ? 'on' : 'off'}. Press to unlock`, tooltip };
+ return { coverOpen: !s.on, knobRight: s.on, fill: s.on ? 1 : 0, ring: false, hint: null, ...common };
default:
- return { coverOpen: false, knobRight: s.on, fill: s.on ? 1 : 0, ring: false, hint: null, label: `Dev mode, ${s.on ? 'on' : 'off'}. Press to unlock${unavailable}`, tooltip };
+ return { coverOpen: false, knobRight: s.on, fill: s.on ? 1 : 0, ring: s.on && !s.disabled, hint: null, ...common };
}
}
diff --git a/frontend/src/styles/modern.css b/frontend/src/styles/modern.css
index 0707d2da..a9efafa7 100644
--- a/frontend/src/styles/modern.css
+++ b/frontend/src/styles/modern.css
@@ -575,56 +575,63 @@ a.kw-sticker:hover { transform: rotate(var(--kw-tilt)) scale(1.04); box-shadow:
animation: none;
}
}
-/* ---- Dev mode (0.7): the switch's safety cover, the </> badge, the hard hat and the blueprint grid.
- design.md §1–§2. Motion is transform and opacity only; under reduced motion nothing animates and
- the switch is a plain labelled track with a lock glyph (DevModeSwitch renders that variant). */
-.kw-dv { position: relative; width: 44px; height: 32px; border-radius: 10px; flex-shrink: 0; }
-.kw-dv:disabled { opacity: 0.5; cursor: not-allowed; }
-.kw-dv-track {
- position: absolute; left: 5px; top: 7px; width: 34px; height: 18px; border-radius: 9999px;
- background: #2c2552; box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.14);
-}
-.kw-dv-fill {
- position: absolute; inset: 0; border-radius: 9999px;
- background: linear-gradient(135deg, #7a62f0 0%, #5b47d6 100%);
- opacity: var(--kw-dv-fill, 0); transition: opacity 160ms var(--kw-ease);
-}
-.kw-dv-ring {
- position: absolute; inset: -3px; border-radius: 12px; pointer-events: none; opacity: 0;
- box-shadow: 0 0 0 1.5px rgb(157 143 255 / 0.7), 0 0 10px rgb(157 143 255 / 0.35);
- transition: opacity 150ms var(--kw-ease);
-}
-.kw-dv[data-ring] .kw-dv-ring { opacity: 1; }
-.kw-dv-knob {
- position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 9999px;
- display: flex; align-items: center; justify-content: center;
- background: #ecebfa; box-shadow: 0 1px 2px rgb(6 3 20 / 0.5);
- transition: transform 160ms var(--kw-ease);
-}
-.kw-dv[data-knob='right'] .kw-dv-knob { transform: translateX(16px); }
-.kw-dv-cover {
- position: absolute; left: 1px; top: 3px; width: 42px; height: 26px; border-radius: 9px;
- display: flex; align-items: center; justify-content: center;
- background: rgb(236 235 250 / 0.11); border: 1px solid rgb(255 255 255 / 0.24);
- -webkit-backdrop-filter: blur(1.6px) saturate(1.2); backdrop-filter: blur(1.6px) saturate(1.2);
- box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.22), 0 2px 6px rgb(6 3 20 / 0.35);
- font: 700 9px/1 'JetBrains Mono', ui-monospace, monospace; color: rgb(154 148 196 / 0.85);
- transform-origin: top; transition: transform 150ms var(--kw-ease), opacity 150ms var(--kw-ease), background-color 150ms var(--kw-ease);
-}
-.kw-dv:not(:disabled):hover[data-cover='closed'] .kw-dv-cover { background: rgb(255 255 255 / 0.16); }
-.kw-dv[data-cover='open'] .kw-dv-cover { transform: perspective(220px) rotateX(112deg); opacity: 0.9; }
-.kw-dv-hinge { position: absolute; left: 12px; top: 1px; width: 20px; height: 3px; pointer-events: none; }
-.kw-dv-hinge::before, .kw-dv-hinge::after { content: ''; position: absolute; top: 0; width: 5px; height: 3px; border-radius: 1px; background: #8d87b8; }
-.kw-dv-hinge::before { left: 0; }
-.kw-dv-hinge::after { right: 0; }
-/* Reduced motion: "Dev" label, track, lock glyph in the knob; every change instant */
-.kw-dv-rm { position: relative; display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 4px; border-radius: 10px; flex-shrink: 0; }
-.kw-dv-rm:disabled { opacity: 0.5; cursor: not-allowed; }
-.kw-dv-rm .kw-dv-track { position: relative; left: auto; top: auto; display: block; }
-.kw-dv-rm[data-ring] .kw-dv-track { box-shadow: inset 0 0 0 1px rgb(255 255 255 / 0.14), 0 0 0 1.5px rgb(157 143 255 / 0.7), 0 0 10px rgb(157 143 255 / 0.35); }
-.kw-dv-rm[data-knob='right'] .kw-dv-knob { transform: translateX(16px); }
+/* ---- Dev mode (0.7): the switch, the </> badge, the hard hat and the blueprint grid. design.md §1–§2.
+ Under reduced motion nothing animates. */
+/* The switch (style v2 §10, the Branch switch): a tiny git line. The knob is a commit node.
+ Off: a hollow node on the line, no cover. One press: the node hops onto a solid violet fork, then
+ a 1 px violet cover closes. Off takes two: armed is a dashed amber fork, a halo and `off?`. 32 px tall
+ (44 on phones), mono label + a 44×24 graph. Not colour alone: node position, fork drawn/dashed/
+ absent and the label word all change. */
+.kw-dv {
+ position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 4px;
+ height: 32px; min-width: 44px; padding: 0 6px; border-radius: 10px; flex-shrink: 0; cursor: pointer;
+ background: transparent; transition: background-color 120ms var(--kw-ease);
+}
+.kw-dv.h-11 { height: 44px; } /* phone: a 44 px target */
+.kw-dv:not(:disabled):hover { background: rgb(247 246 255 / 0.06); }
+.kw-dv:disabled { opacity: 0.4; cursor: not-allowed; }
+.kw-dv-lbl {
+ font: 600 11px/1 'JetBrains Mono', ui-monospace, monospace; color: theme('colors.zinc.400');
+ min-width: 4ch; text-align: right; transition: color 120ms var(--kw-ease);
+}
+.kw-dv[data-on] .kw-dv-lbl { color: theme('colors.sky.300'); }
+.kw-dv[data-armed] .kw-dv-lbl { color: var(--dv-armed); }
+.kw-dv-lock { color: theme('colors.zinc.400'); flex-shrink: 0; }
+.kw-dv[data-on]:not(:disabled) .kw-dv-lock { color: theme('colors.sky.300'); }
+.kw-dv[data-armed] .kw-dv-lock { color: var(--dv-armed); }
+/* The cover (flow F1/F2): only while on. A 1 px violet ring closes 160 ms after the node lands
+ (guards locked in); armed lifts it to a 2 px amber ring at once. Off and not-the-owner: none. */
+.kw-dv::after {
+ content: ''; position: absolute; inset: 0; border-radius: 10px; pointer-events: none; opacity: 0;
+ box-shadow: inset 0 0 0 1px rgb(157 143 255 / 0.45); transition: opacity 160ms var(--kw-ease);
+}
+.kw-dv[data-covered]::after { opacity: 1; transition-delay: 160ms; }
+.kw-dv[data-armed]::after { opacity: 1; box-shadow: inset 0 0 0 2px var(--dv-armed); transition-delay: 0s; }
+.kw-dv:disabled::after { opacity: 0; }
+.kw-dv-graph { display: block; width: 44px; height: 24px; overflow: visible; }
+.kw-dv-base { fill: none; stroke: theme('colors.zinc.500'); stroke-width: 2; stroke-linecap: round; transition: opacity 160ms var(--kw-ease); }
+.kw-dv[data-on] .kw-dv-base { opacity: 0.55; }
+.kw-dv-fork { fill: none; stroke: theme('colors.sky.400'); stroke-width: 2; stroke-linecap: round; opacity: 0; transition: opacity 160ms var(--kw-ease); }
+.kw-dv[data-on] .kw-dv-fork { opacity: 1; }
+.kw-dv[data-armed] .kw-dv-fork { opacity: 1; stroke: var(--dv-armed); stroke-dasharray: 2.5 3; }
+.kw-dv-node { transition: transform 160ms var(--kw-ease); }
+.kw-dv[data-on] .kw-dv-node { transform: translate(22px, -10px); }
+.kw-dv-dot { fill: var(--kw-surface-side); stroke: theme('colors.zinc.300'); stroke-width: 2; transition: fill 160ms var(--kw-ease), stroke 160ms var(--kw-ease); }
+.kw-dv[data-on] .kw-dv-dot { fill: theme('colors.sky.400'); stroke: theme('colors.sky.400'); }
+.kw-dv[data-armed] .kw-dv-dot { stroke: var(--dv-armed); fill: color-mix(in srgb, var(--dv-armed) 25%, var(--kw-surface-side)); }
+.kw-dv-pip { fill: var(--kw-surface-side); opacity: 0; transition: opacity 160ms var(--kw-ease); }
+.kw-dv[data-on] .kw-dv-pip { opacity: 1; }
+.kw-dv-halo { fill: none; stroke: var(--dv-armed); stroke-width: 1.5; opacity: 0; transform-box: fill-box; transform-origin: center; }
+.kw-dv[data-armed] .kw-dv-halo { animation: kw-dv-halo 900ms var(--kw-ease) infinite; }
+@keyframes kw-dv-halo { from { opacity: 0.9; transform: scale(1); } to { opacity: 0; transform: scale(2); } }
+/* Reduced motion: the same shapes, instant, no halo */
+.kw-dv-rm, .kw-dv-rm *, .kw-dv-rm::after { transition: none !important; }
+.kw-dv-rm .kw-dv-halo { animation: none !important; opacity: 0 !important; }
.kw-dv-hint { animation: kw-dv-hint 150ms var(--kw-ease) both; }
@keyframes kw-dv-hint { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: none; } }
+/* The flip note under the space header: HEAD → dev / merged into main, one caret blink */
+.kw-dv-note { animation: kw-dv-hint 150ms var(--kw-ease) both; }
+.kw-dv-note .dv-caret { animation-iteration-count: 1; }
/* The </> badge on a space tile: bottom-right, mirroring the unread badge top-right */
.kw-dev-badge {
@@ -665,8 +672,9 @@ a.kw-sticker:hover { transform: rotate(var(--kw-tilt)) scale(1.04); box-shadow:
@keyframes kw-dv-grid { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
- .kw-dv-fill, .kw-dv-ring, .kw-dv-knob, .kw-dv-cover { transition: none; }
- .kw-dv-hint, .kw-dev-badge, .kw-dev-hat, .kw-blueprint::before { animation: none; }
+ .kw-dv, .kw-dv *, .kw-dv::after { transition: none !important; }
+ .kw-dv-halo { animation: none !important; opacity: 0 !important; }
+ .kw-dv-hint, .kw-dv-note, .kw-dev-badge, .kw-dev-hat, .kw-blueprint::before { animation: none; }
.kw-dev-caret { animation: none; }
}
@@ -687,6 +695,9 @@ a.kw-sticker:hover { transform: rotate(var(--kw-tilt)) scale(1.04); box-shadow:
--accent-fill: #6c58e0; /* sky-600: toggles on */
--accent-gradient: linear-gradient(135deg, #7a62f0 0%, #5b47d6 100%);
--accent-soft: linear-gradient(135deg, rgb(122 98 240 / .22) 0%, rgb(91 71 214 / .10) 100%);
+ /* Pixel's names for the same shades (PX-* classes use --dv-t*, --dv-accent*) */
+ --dv-t1: var(--t1); --dv-t2: var(--t2); --dv-t3: var(--t3); --dv-t4: var(--t4); --dv-t5: var(--t5);
+ --dv-accent: var(--accent); --dv-accent-strong: var(--accent-strong);
/* new Dev tokens (style v2) */
--dv-code-bg: rgb(10 7 25 / .72); /* command boxes, diff excerpts, sha chips */
--dv-add: #5eead4; --dv-add-bg: rgb(94 234 212 / .10);
@@ -799,3 +810,5 @@ button.dv-sha { cursor: copy; } button.dv-sha:hover { color: var(--accent); bord
.dv-led::after, .dv-led[data-ping]::after, .dv-node::before, .dv-caret, .dv-stamp { animation: none !important; }
.dv-led[data-s="run"]::after { opacity: .5; transform: scale(1.6); }
}
+/* §2.4 kbd chips are desktop only */
+@media (max-width: 639px) { .dv-kbd { display: none; } }
diff --git a/frontend/tests/devMode.test.mjs b/frontend/tests/devMode.test.mjs
index 6cbf5e18..caaf70f6 100644
--- a/frontend/tests/devMode.test.mjs
+++ b/frontend/tests/devMode.test.mjs
@@ -41,7 +41,7 @@ const m = await loadBundled(`
export { createRoot } from 'react-dom/client';
export { renderToStaticMarkup } from 'react-dom/server.browser';
export * from './src/devMode';
- export { DevModeSwitch, DevOffNote, DevBadge, HardHat } from './src/components/DevModeSwitch';
+ export { DevModeSwitch, DevOffNote, DevFlipNote, DevBadge, HardHat } from './src/components/DevModeSwitch';
export { DevModeSetup } from './src/components/DevModeSetup';
export { DevModeSettings } from './src/components/DevModeSettings';
export { ConnectionRow } from './src/components/ConnectionsView';
@@ -77,77 +77,95 @@ const mount = async (el) => {
const R = (s, a) => m.switchReducer(s, a, 'Demo');
-test('two presses: the first lifts the cover, the second flips (set up already)', () => {
+test('flow F1: off → on is one press (set up already); no cover while off', () => {
let s = m.initialSwitch({ setup: false });
+ assert.equal(m.switchLook(s).ring, false, 'off: no cover');
+ assert.equal(m.switchLook(s).glyph, 'code');
s = R(s, { type: 'press', now: 1000 });
- assert.equal(s.phase, 'lifted');
- assert.equal(s.on, false);
- assert.equal(s.announce.text, 'Unlocked. Press again to turn Dev mode on.');
- assert.equal(m.switchLook(s).hint, 'Press again to turn Dev mode on');
- s = R(s, { type: 'press', now: 1200 });
assert.equal(s.on, true);
assert.equal(s.saving, true);
assert.equal(s.phase, 'settling');
- assert.equal(s.settleUntil, 1200 + m.SETTLE_MS);
+ assert.equal(s.settleUntil, 1000 + m.SETTLE_MS);
assert.equal(s.announce.text, 'Dev mode on for Demo.');
- assert.equal(m.switchLook(s).label, 'Dev mode, on. Press to unlock');
+ s = R({ ...s, saving: false }, { type: 'settled', now: 1000 + m.SETTLE_MS });
+ const look = m.switchLook(s);
+ assert.equal(look.look, 'on');
+ assert.equal(look.ring, true, 'on: the 1 px cover');
+ assert.equal(look.glyph, 'locked', 'on: lock shut');
+ assert.equal(look.label, 'Dev mode');
+ assert.equal(look.describe, 'Press twice to turn off.');
+ assert.equal(look.tooltip, 'Dev mode is on. Press twice to turn it off.');
+ assert.equal(m.switchLook(m.initialSwitch()).describe, 'Turns on reviews, the ship gate and the production floor.');
+ assert.equal(m.switchLook(m.initialSwitch()).tooltip, 'Dev mode: plain-words merges, code reviews, production floor');
});
-test('a double-click while it settles is ignored, and so is a press while saving', () => {
- let s = m.initialSwitch({ setup: false });
- s = R(R(s, { type: 'press', now: 0 }), { type: 'press', now: 100 });
- const settling = s;
- assert.equal(R(settling, { type: 'press', now: 150 }), settling, 'third press inside the settle');
- s = R({ ...settling, saving: false }, { type: 'press', now: 300 });
- assert.equal(s.phase, 'settling', 'still settling at 300 ms');
- s = R({ ...settling, saving: false }, { type: 'settled', now: 100 + m.SETTLE_MS });
+test('flow F2: on → off is two presses: arm (amber, open lock, the armed line), then off', () => {
+ let s = m.initialSwitch({ on: true, setup: false });
+ s = R(s, { type: 'press', now: 1000 });
+ assert.equal(s.phase, 'lifted');
+ assert.equal(s.on, true);
+ assert.equal(s.announce.text, 'Press again to turn Dev mode off, or Escape to keep it on.');
+ const look = m.switchLook(s);
+ assert.equal(look.look, 'armed');
+ assert.equal(look.glyph, 'unlocked');
+ assert.equal(look.hint, 'Press again to turn Dev mode off');
+ s = R(s, { type: 'press', now: 1200 });
+ assert.equal(s.on, false);
+ assert.equal(s.phase, 'settling');
+ assert.match(s.announce.text, /^Dev mode off for Demo\./);
+});
+
+test('a double-click on Off turns it on once and never arms it; a press while saving is eaten', () => {
+ let s = R(m.initialSwitch({ setup: false }), { type: 'press', now: 0 });
+ const settling = { ...s, saving: false };
+ assert.equal(R(settling, { type: 'press', now: 100 }), settling, 'second click inside the settle');
+ assert.equal(R(settling, { type: 'press', now: m.SETTLE_MS - 1 }).phase, 'settling');
+ s = R(settling, { type: 'settled', now: m.SETTLE_MS });
assert.equal(s.phase, 'covered');
assert.equal(R({ ...s, saving: true }, { type: 'press', now: 9999 }).phase, 'covered', 'a save in flight eats the press');
- assert.equal(R({ ...s, saving: false }, { type: 'press', now: 9999 }).phase, 'lifted');
+ assert.equal(R(s, { type: 'press', now: 9999 }).phase, 'lifted', 'after the settle, a press arms');
});
-test('a lifted cover drops back after 5 s with nothing changed, not before', () => {
+test('armed drops back after 5 s with nothing changed, not before: "Dev mode stays on."', () => {
let s = R(m.initialSwitch({ on: true, setup: false }), { type: 'press', now: 1000 });
assert.equal(R(s, { type: 'recover', now: 1000 + m.RECOVER_MS - 1 }).phase, 'lifted');
s = R(s, { type: 'recover', now: 1000 + m.RECOVER_MS });
assert.equal(s.phase, 'covered');
assert.equal(s.on, true);
- assert.equal(s.announce.text, 'Locked.');
+ assert.equal(s.announce.text, 'Dev mode stays on.');
});
-test('Esc and blur drop a lifted cover; they do nothing when covered', () => {
- const lifted = R(m.initialSwitch({ setup: false }), { type: 'press', now: 0 });
+test('Esc and blur re-cover an armed switch; they do nothing when covered', () => {
+ const lifted = R(m.initialSwitch({ on: true, setup: false }), { type: 'press', now: 0 });
for (const type of ['escape', 'blur']) {
const s = R(lifted, { type });
assert.equal(s.phase, 'covered', type);
- assert.equal(s.on, false, type);
+ assert.equal(s.on, true, type);
+ assert.equal(s.announce.text, 'Dev mode stays on.', type);
}
const covered = m.initialSwitch();
assert.equal(R(covered, { type: 'escape' }), covered);
assert.equal(R(covered, { type: 'blur' }), covered);
});
-test('reduced motion: still two presses, but nothing to settle, so the next press lifts at once', () => {
+test('reduced motion: nothing to settle; on is one press, off still two', () => {
let s = m.initialSwitch({ setup: false, reduced: true });
s = R(s, { type: 'press', now: 0 });
- assert.equal(s.phase, 'lifted');
- s = R(s, { type: 'press', now: 10 });
assert.equal(s.on, true);
assert.equal(s.phase, 'covered');
assert.equal(s.settleUntil, 0);
s = R({ ...s, saving: false }, { type: 'press', now: 20 });
- assert.equal(s.phase, 'lifted', 'one press lifts, never flips');
+ assert.equal(s.phase, 'lifted', 'one press arms, never flips');
assert.equal(s.on, true);
});
-test('first time: the second press opens the setup (pending, half-flipped); cancel covers, done flips on', () => {
- let s = R(R(m.initialSwitch(), { type: 'press', now: 0 }), { type: 'press', now: 100 });
+test('first time (older server): one press opens the setup (pending); cancel covers, done flips on', () => {
+ let s = R(m.initialSwitch(), { type: 'press', now: 0 });
assert.equal(s.phase, 'pending');
assert.equal(s.on, false);
const look = m.switchLook(s);
assert.equal(look.fill, 0.45);
assert.equal(look.knobRight, true);
- assert.equal(look.coverOpen, true);
assert.equal(R(s, { type: 'press', now: 200 }), s, 'presses wait for the sheet');
assert.equal(R(s, { type: 'setup_cancel' }).phase, 'covered');
assert.equal(R(s, { type: 'setup_cancel' }).on, false);
@@ -169,14 +187,16 @@ test('a failed save puts the switch back, covered, with the reason announced', (
});
test('the server changing Dev mode closes a held-open cover; a disabled switch says so', () => {
- const lifted = R(m.initialSwitch({ setup: false }), { type: 'press', now: 0 });
- const s = R(lifted, { type: 'server', state: { ...off, on: true, repo: 'demo-org/demo-app', polled_at: 'x' } });
- assert.equal(s.on, true);
+ const lifted = R(m.initialSwitch({ on: true, setup: false }), { type: 'press', now: 0 });
+ const s = R(lifted, { type: 'server', state: { ...off, on: false, repo: 'demo-org/demo-app', polled_at: 'x' } });
+ assert.equal(s.on, false);
assert.equal(s.phase, 'covered');
- const d = R(m.initialSwitch(), { type: 'server', state: null, disabled: true });
+ const d = R(m.initialSwitch({ on: true }), { type: 'server', state: null, disabled: true });
assert.equal(R(d, { type: 'press', now: 0 }), d);
- assert.match(m.switchLook(d).label, /unavailable$/);
- assert.equal(m.switchLook(d).tooltip, 'Only the space owner can change Dev mode');
+ const look = m.switchLook(d);
+ assert.equal(look.tooltip, 'Only the space owner can change Dev mode.');
+ assert.equal(look.ring, false, 'not the owner: no ring');
+ assert.equal(look.glyph, 'locked');
});
// ---------------------------------------------------------------------------
@@ -274,6 +294,11 @@ test('the checker: empty and invalid answer at once without asking; a stale repl
// In a DOM
const switchEl = (host) => host.querySelector('[data-dev-switch]');
+const desc = (host, b) => {
+ const d = host.querySelector('[data-dv-describe]');
+ assert.equal(d.id, b.getAttribute('aria-describedby'));
+ return d.textContent;
+};
const click = async (el) => {
el.dispatchEvent(new MouseEvent('click', { bubbles: true }));
await settle();
@@ -285,14 +310,20 @@ test('DOM: on → off with two presses saves PUT {on:false}, announces, and call
const { host, root } = await mount(h(m.DevModeSwitch, { space: { id: 'spc_demo', name: 'Demo' }, onTurnedOff: () => turnedOff++ }));
const b = switchEl(host);
assert.equal(b.tagName, 'BUTTON');
- assert.equal(b.getAttribute('role'), null, 'a button, not role=switch');
+ assert.equal(b.getAttribute('role'), 'switch');
+ assert.equal(b.getAttribute('aria-checked'), 'true');
assert.equal(b.dataset.on, 'true');
- assert.equal(b.getAttribute('aria-label'), 'Dev mode, on. Press to unlock');
+ assert.equal(b.dataset.covered, 'true', 'on: the cover is closed');
+ assert.equal(b.getAttribute('aria-label'), 'Dev mode');
+ assert.equal(desc(host, b), 'Press twice to turn off.');
+ assert.equal(b.title, 'Dev mode is on. Press twice to turn it off.');
+ assert.ok(b.querySelector('[data-dv-glyph="locked"]'), 'on: lock shut');
await click(b);
assert.equal(b.dataset.devSwitch, 'lifted');
- assert.equal(b.dataset.cover, 'open');
- assert.equal(b.dataset.ring, 'true');
- assert.match(host.querySelector('[data-dv-live]').textContent, /Unlocked\. Press again to turn Dev mode off\./);
+ assert.equal(b.dataset.armed, 'true');
+ assert.equal(b.dataset.covered, undefined);
+ assert.ok(b.querySelector('[data-dv-glyph="unlocked"]'), 'armed: lock open');
+ assert.match(host.querySelector('[data-dv-live]').textContent, /Press again to turn Dev mode off, or Escape to keep it on\./);
assert.ok(host.querySelector('[data-dv-hint]'));
await click(b);
await click(b); // the double-click's third press: ignored while settling
@@ -307,8 +338,28 @@ test('DOM: on → off with two presses saves PUT {on:false}, announces, and call
for (let i = 0; i < 100 && b.dataset.devSwitch !== 'covered'; i++) await wait(20);
assert.equal(b.dataset.devSwitch, 'covered');
assert.equal(b.dataset.on, undefined);
- await click(b); // a render mid-save once left the switch stuck; the next press still lifts
- assert.equal(b.dataset.devSwitch, 'lifted');
+ assert.equal(b.getAttribute('aria-checked'), 'false');
+ assert.equal(desc(host, b), 'Turns on reviews, the ship gate and the production floor.');
+ await click(b); // a render mid-save once left the switch stuck; the next press still turns it on (one press)
+ assert.equal(b.dataset.on, 'true');
+ assert.deepEqual(server.calls.filter(([meth]) => meth === 'PUT').map(([, , body]) => body), [{ on: false }, { on: true }]);
+ root.unmount();
+});
+
+test('DOM: off → on is one press: PUT {on:true}, onTurnedOn, and a double-click never arms it', async () => {
+ reset({ ...off, on: false, repo: 'demo-org/demo-app', polled_at: 'x' });
+ let turnedOn = 0;
+ const { host, root } = await mount(h(m.DevModeSwitch, { space: { id: 'spc_demo', name: 'Demo' }, onTurnedOn: () => turnedOn++ }));
+ const b = switchEl(host);
+ assert.equal(b.dataset.covered, undefined, 'off: no cover');
+ assert.equal(b.querySelector('[data-dv-glyph]'), null, 'off: no lock');
+ assert.equal(b.title, 'Dev mode: plain-words merges, code reviews, production floor');
+ await click(b);
+ await click(b);
+ assert.deepEqual(server.calls.filter(([meth]) => meth === 'PUT').map(([, , body]) => body), [{ on: true }]);
+ assert.equal(b.dataset.on, 'true');
+ assert.equal(b.dataset.armed, undefined, 'the double-click’s second press lands in the settle');
+ assert.equal(turnedOn, 1);
root.unmount();
});
@@ -325,6 +376,7 @@ test('DOM: Escape and blur drop a lifted cover without saving', async () => {
b.blur();
await settle();
assert.equal(b.dataset.devSwitch, 'covered');
+ assert.match(host.querySelector('[data-dv-live]').textContent, /Dev mode stays on\./);
assert.equal(server.calls.filter(([meth]) => meth === 'PUT').length, 0);
root.unmount();
});
@@ -334,37 +386,93 @@ test('DOM: a 403 on load shows the switch disabled', async () => {
server.fail = { method: 'GET', path: '/dev_mode', status: 403, error: 'only the person' };
const { host, root } = await mount(h(m.DevModeSwitch, { space: { id: 'spc_demo', name: 'Demo' } }));
assert.equal(switchEl(host).disabled, true);
+ assert.ok(switchEl(host).querySelector('[data-dv-glyph="locked"]'), 'disabled shows a closed lock');
root.unmount();
});
-test('DOM: reduced motion shows the Dev label and the lock glyph, and opens with no settle', async () => {
+test('DOM: reduced motion shows the same switch, turns on in one press and arms with no settle', async () => {
reset({ ...off, on: false, repo: 'demo-org/demo-app', polled_at: 'x' });
window.matchMedia = (q) => ({ matches: q.includes('reduce'), media: q, addEventListener() {}, removeEventListener() {} });
const { host, root } = await mount(h(m.DevModeSwitch, { space: { id: 'spc_demo', name: 'Demo' } }));
const b = switchEl(host);
assert.ok(b.classList.contains('kw-dv-rm'));
- assert.ok(b.querySelector('[data-dv-glyph="locked"]'));
- await click(b);
- assert.ok(b.querySelector('[data-dv-glyph="unlocked"]'));
+ assert.ok(b.querySelector('[data-dv-graph] .kw-dv-node'), 'the same branch graph');
+ assert.equal(b.textContent.trim(), 'dev', 'the reduced-motion variant keeps its dev label');
await click(b);
assert.equal(b.dataset.devSwitch, 'covered');
assert.equal(b.dataset.on, 'true');
await wait(30); // the save comes back; presses wait for it, motion or not
await settle();
await click(b);
- assert.equal(b.dataset.devSwitch, 'lifted', 'the next press lifts at once: nothing to settle');
+ assert.equal(b.dataset.devSwitch, 'lifted', 'the next press arms at once: nothing to settle');
+ assert.equal(b.querySelector('[data-dv-word]').textContent, 'off?');
root.unmount();
delete window.matchMedia;
});
+test('switchLook names the visual state and the knob glyph: off, armed, on, pending, disabled', () => {
+ const st = (o) => ({ ...m.initialSwitch({ reduced: false }), ...o });
+ const pick = (o) => { const l = m.switchLook(st(o)); return [l.look, l.glyph]; };
+ assert.deepEqual(pick({ on: false }), ['off', 'code']);
+ assert.deepEqual(pick({ on: true }), ['on', 'locked']);
+ assert.deepEqual(pick({ on: true, phase: 'lifted', liftedAt: 0 }), ['armed', 'unlocked']);
+ assert.deepEqual(pick({ phase: 'pending' }), ['pending', 'code']);
+ assert.deepEqual(pick({ disabled: true, on: true }), ['disabled', 'locked']);
+});
+
+test('0.7.1 look (style v2 §10): the Branch switch; label dev → (one press) dev → off?; 44 px tall on phone; no knob or track', async () => {
+ reset({ ...off, on: false, repo: 'demo-org/demo-app', polled_at: 'x' });
+ const { host, root } = await mount(h(m.DevModeSwitch, { space: { id: 'spc_demo', name: 'Demo' }, phone: true }));
+ const b = switchEl(host);
+ const word = () => b.querySelector('[data-dv-word]').textContent;
+ assert.ok(b.classList.contains('kw-dv') && !b.classList.contains('kw-dv-rm'));
+ assert.ok(b.classList.contains('h-11'), 'the phone target is 44 px tall');
+ assert.ok(host.querySelector('[data-dev-switch-wrap]').className.includes('min-w-[44px]'));
+ for (const gone of ['.kw-dv-cover', '.kw-dv-hinge', '.kw-dv-ring', '.kw-dv-knob', '.kw-dv-track']) assert.equal(b.querySelector(gone), null, gone);
+ const svg = b.querySelector('svg[data-dv-graph]');
+ assert.equal(svg.getAttribute('viewBox'), '0 0 44 24');
+ assert.equal(svg.querySelector('.kw-dv-base').getAttribute('d'), 'M2 17H42');
+ assert.equal(svg.querySelector('.kw-dv-fork').getAttribute('d'), 'M12 17C19 17 18 7 26 7H42');
+ assert.equal(svg.querySelector('.kw-dv-dot').getAttribute('r'), '5');
+ assert.equal(svg.querySelector('.kw-dv-pip').getAttribute('r'), '1.6');
+ assert.equal(word(), 'dev');
+ assert.equal(b.dataset.armed, undefined);
+ await click(b);
+ assert.equal(b.dataset.on, 'true', 'one press: on');
+ assert.equal(b.dataset.armed, undefined, 'never armed on the way on');
+ assert.equal(word(), 'dev');
+ root.unmount();
+ reset({ ...off, on: true, repo: 'demo-org/demo-app', polled_at: 'x' });
+ const on = await mount(h(m.DevModeSwitch, { space: { id: 'spc_demo', name: 'Demo' } }));
+ const b2 = switchEl(on.host);
+ assert.equal(b2.dataset.on, 'true');
+ assert.equal(b2.querySelector('[data-dv-word]').textContent, 'dev');
+ await click(b2);
+ assert.equal(b2.querySelector('[data-dv-word]').textContent, 'off?', 'armed to turn off asks off?');
+ assert.equal(b2.dataset.on, 'true', 'the node stays on the fork while armed to turn off');
+ on.root.unmount();
+});
+
+test('flip notes: HEAD → dev with one caret, and merged into main', () => {
+ const onNote = m.renderToStaticMarkup(h(m.DevFlipNote, { on: true, space: 'Trailhead', onDismiss: () => {} }));
+ assert.match(onNote, /role="status"/);
+ assert.match(onNote, /HEAD → dev/);
+ assert.match(onNote, /class="dv-caret"/);
+ assert.match(onNote, /Dev mode is on for Trailhead\./);
+ const offNote = m.renderToStaticMarkup(h(m.DevFlipNote, { on: false, approvals: 'smart', onDismiss: () => {} }));
+ assert.match(offNote, /merged into main/);
+ assert.match(offNote, /Dev mode is off\. Approvals stay on Smart\./);
+ assert.doesNotMatch(offNote, /dv-caret/);
+});
+
test('DOM: first switch-on opens the setup sheet; typing checks after 400 ms; Turn on sends repo and branch', async () => {
reset();
server.check = { state: 'found', repo: 'demo-org/demo-app', branch: 'trunk', deploy_hint: null };
const { host, root } = await mount(h(m.DevModeSwitch, { space: { id: 'spc_demo', name: 'Demo' } }));
const b = switchEl(host);
await click(b);
- await click(b);
- assert.equal(b.dataset.devSwitch, 'pending');
+ assert.equal(b.dataset.devSwitch, 'pending', 'one press opens the setup on an older server');
+ assert.equal(b.dataset.armed, undefined, 'pending is not armed');
const dialog = document.querySelector('[role="dialog"]');
assert.equal(dialog.getAttribute('aria-modal'), 'true');
assert.match(dialog.textContent, /Which repo is this space about\?/);
diff --git a/frontend/tests/ia.test.mjs b/frontend/tests/ia.test.mjs
index 36f615a7..daac391d 100644
--- a/frontend/tests/ia.test.mjs
+++ b/frontend/tests/ia.test.mjs
@@ -271,3 +271,14 @@ test('QA d: nothing tells the person to look in Settings → Profiles any more',
assert.doesNotMatch(src(f), /Settings (?:→|›|>) Profiles/, f);
}
});
+
+test('desktop header: the Dev switch has its own row under the name; phones keep it in the name row', () => {
+ const html = ui.sidebar(base);
+ const header = html.slice(html.indexOf('data-space-header'), html.indexOf('data-dev-switch-row'));
+ assert.doesNotMatch(header, /data-dev-switch[ =>]/, 'no switch in the desktop name row');
+ assert.match(html, /class="h-8 flex items-center pl-12" data-dev-switch-row/);
+ assert.match(html.slice(html.indexOf('data-dev-switch-row')), /data-dev-switch/);
+ const phone = ui.sidebar({ ...base, phone: true, section: 'chats' });
+ assert.doesNotMatch(phone, /data-dev-switch-row/);
+ assert.match(phone, /data-dev-switch/);
+});