Skip to content

Commit 34f0543

Browse files
piero-dev25claude
andcommitted
feat(web): game-harness UI renders only for game projects
Owner request (2026-08-08, two screenshots): a non-game project showed a "No engine" chip in the chat header, and a t3code-fork thread's composer displayed the Mafia Game Unity editor's "Directional Light" selection chip. Core design -- the three-state engine signal (resolveEngineChipState): "unknown" (project entity not loaded, or engineType absent on an older server) / "none" (detection ran, no marker matched) / a concrete engine. Every new gate keys off this, never a collapsed `?? null` -- the collapse would have unmounted the composer's presence socket on every project switch (re-minted DPoP tickets + a "connecting..." flash) and blanked all engine UI on older backends. - EngineToolbar renders NOTHING for a null engine, as its own contract (single engine source: the resolvedEngineType prop is deleted, the view is the one input; the old "still renders 'No engine'" test flipped red-first with the fixture disagreement corrected). - The composer chip row is now game-gated AND project-scoped through one pure seam (resolveEditorPresenceChipsView): hidden for "none", chips filtered by workspaceRoot via the same selectEditorPresenceChipsForProject the send path uses. The container publishes the RENDERED list, so see-what-you-send is structural; the send path keeps its own identical filter as defense in depth. - Ruling supersession recorded in place (store.ts, EngineToolbar.logic.ts, EditorPresenceChips.tsx, unity-header-cleanup.md, plan-engine-header-redesign.md): task pingdotgg#71's "row shows every editor by owner ruling" display half is overturned by the 2026-08-08 report; both rulings carried with dates. Process: 4-lane research workflow -> spec -> fresh Opus critique (14 findings incl. 1 blocker, all incorporated; rev 1's last-good retention DROPPED as masking a real 60s+ server state, replaced by the three-state signal) -> Sonnet implementation -> orchestrator diff review. Verification: typecheck exit 0 all packages; web 2410/2410 (10 new tests: 4 resolveEngineChipState branches, 6+1 chip-view gate/scoping, toolbar null-case flip red-proven by old-file restore, "none"-gate red-proven by line deletion); server 2197 green (untouched, sanity); /usr/bin/grep "No engine" in apps/*/src: zero. E2E pass on the packaged build still OPEN (tracked in task pingdotgg#135): t3code-fork bare header/composer + Mafia Game unchanged + the cross-project screenshot scenario re-run. Spec: docs/specs/no-engine-ui-for-non-game-projects.md (rev 2) Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent edd7b5d commit 34f0543

14 files changed

Lines changed: 570 additions & 77 deletions

‎apps/web/src/components/ChatView.logic.test.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
isBranchMismatchDismissedForSession,
2828
reconcileMountedTerminalThreadIds,
2929
reconcileRetainedMountedThreadIds,
30+
resolveEngineChipState,
3031
resolveThreadMetadataUpdateForNextTurn,
3132
resolveSendEnvMode,
3233
scheduleEnvironmentReconnectWarning,
@@ -66,6 +67,25 @@ describe("tryBeginUnityRaise", () => {
6667
});
6768
});
6869

70+
describe("resolveEngineChipState", () => {
71+
it("is 'unknown' when no project has resolved yet", () => {
72+
expect(resolveEngineChipState(null)).toBe("unknown");
73+
});
74+
75+
it("is 'unknown' when the project loaded but engineType is absent (an older server)", () => {
76+
expect(resolveEngineChipState({})).toBe("unknown");
77+
});
78+
79+
it("is 'none' when detection ran and matched no marker", () => {
80+
expect(resolveEngineChipState({ engineType: null })).toBe("none");
81+
});
82+
83+
it("returns the concrete engine type for a game project", () => {
84+
expect(resolveEngineChipState({ engineType: "unity" })).toBe("unity");
85+
expect(resolveEngineChipState({ engineType: "threejs" })).toBe("threejs");
86+
});
87+
});
88+
6989
describe("environment reconnect warning grace", () => {
7090
afterEach(() => vi.useRealTimers());
7191

‎apps/web/src/components/ChatView.logic.ts‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
type EngineType,
23
type EnvironmentId,
34
isProviderDriverKind,
45
ProjectId,
@@ -29,6 +30,51 @@ export const ENVIRONMENT_RECONNECT_WARNING_GRACE_MS = 2_000;
2930

3031
export const LastInvokedScriptByProjectSchema = Schema.Record(ProjectId, Schema.String);
3132

33+
/**
34+
* The subset of a project `resolveEngineChipState` needs — structural,
35+
* matching the `EditorPresenceProjectRef`-style refs already used in
36+
* `editorPresence/store.ts` for the same reason: a test should not have to
37+
* build an `EnvironmentProject`'s many unrelated required fields to
38+
* exercise this.
39+
*/
40+
export interface EngineChipStateProjectRef {
41+
// `| undefined` explicit (not just the `?` modifier) — `exactOptionalPropertyTypes`
42+
// distinguishes "absent" from "present and undefined," and the Effect Schema
43+
// `Schema.optional(...)` field this mirrors (`OrchestrationProject.engineType`)
44+
// decodes to the latter, not the former.
45+
readonly engineType?: EngineType | null | undefined;
46+
}
47+
48+
/**
49+
* The three-state engine signal (no-engine-ui-for-non-game-projects spec,
50+
* rev 2, "core design"): `engineType` on the wire means three DIFFERENT
51+
* things and every UI gate that hides/shows game-harness chrome must key
52+
* off this, never off a collapsed `activeProject?.engineType ?? null` —
53+
* that collapse is exactly what would unmount the composer's live presence
54+
* socket on every project switch (the "unknown" window every thread-open
55+
* and project-switch passes through) and blank all engine UI on an older
56+
* backend that predates the field entirely (both states decode to
57+
* `undefined`/absent, indistinguishable from "detection hasn't run yet"
58+
* without this function).
59+
*
60+
* - `"unknown"` — `activeProject` is `null` (nothing loaded yet), or the
61+
* project loaded but `engineType` is `undefined` (an older server, or a
62+
* fixture predating the field — optional-for-decode per the contract's
63+
* own comment). We cannot say whether this is a game.
64+
* - `"none"` — the project loaded and `engineType` decoded to `null`:
65+
* detection RAN against the workspace and matched no marker. This is
66+
* "not a game," a settled answer, not an in-flight one.
67+
* - a concrete `EngineType` — a game project.
68+
*/
69+
export function resolveEngineChipState(
70+
activeProject: EngineChipStateProjectRef | null,
71+
): "unknown" | "none" | EngineType {
72+
if (activeProject === null) return "unknown";
73+
if (activeProject.engineType === undefined) return "unknown";
74+
if (activeProject.engineType === null) return "none";
75+
return activeProject.engineType;
76+
}
77+
3278
/**
3379
* Stale-while-revalidate for the Unity setup probe (owner report,
3480
* 2026-08-05: "a very quick 'checking for unity state' flash when I come to

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ import {
331331
deriveLockedProvider,
332332
readFileAsDataUrl,
333333
reconcileMountedTerminalThreadIds,
334+
resolveEngineChipState,
334335
resolveThreadMetadataUpdateForNextTurn,
335336
resolveSendEnvMode,
336337
revokeBlobPreviewUrl,
@@ -1567,6 +1568,20 @@ function ChatViewContent(props: ChatViewProps) {
15671568
// client-side value can ever disagree with the server's own detection
15681569
// again.
15691570
const resolvedEngineType: EngineType | null = activeProject?.engineType ?? null;
1571+
// no-engine-ui-for-non-game-projects spec (rev 2): the THREE-state signal
1572+
// every game-harness UI gate must key off — never `resolvedEngineType`
1573+
// above, whose `?? null` collapse conflates "not a game" with "haven't
1574+
// loaded the project yet" (see `resolveEngineChipState`'s own doc comment
1575+
// for why that collapse is safe for the toolbar's badge but not here).
1576+
// Drives the composer's editor-presence mount gate and the send-path
1577+
// prompt-content gate (Scope B/C); `resolvedEngineType` above stays as
1578+
// EngineToolbar's own input, unchanged.
1579+
const engineChipState = resolveEngineChipState(activeProject);
1580+
// Same expression `activeProjectCwd` (this file, further down) computes
1581+
// for git/"open in" purposes — recomputed here under its own name so a
1582+
// reader sees why the composer's chip row is scoped this way without
1583+
// tracing an unrelated git/cwd variable.
1584+
const presenceWorkspaceRoot: string | null = activeProject?.workspaceRoot ?? null;
15701585
const connectedProjectEditor = resolveConnectedEditorForProject(
15711586
engineToolbarEditorPresence.editors,
15721587
activeProject,
@@ -6329,7 +6344,6 @@ function ChatViewContent(props: ChatViewProps) {
63296344
onAddProjectScript={saveProjectScript}
63306345
onUpdateProjectScript={updateProjectScript}
63316346
onDeleteProjectScript={deleteProjectScript}
6332-
resolvedEngineType={resolvedEngineType}
63336347
engineToolbarView={engineToolbarView}
63346348
onEngineAction={handleEngineAction}
63356349
{...(threeJsUnavailableReason
@@ -6484,6 +6498,8 @@ function ChatViewContent(props: ChatViewProps) {
64846498
routeKind={routeKind}
64856499
routeThreadRef={routeThreadRef}
64866500
draftId={draftId}
6501+
engineChipState={engineChipState}
6502+
presenceWorkspaceRoot={presenceWorkspaceRoot}
64876503
activeThreadId={activeThreadId}
64886504
activeThreadEnvironmentId={activeThread?.environmentId}
64896505
activeThread={activeThread}

‎apps/web/src/components/EngineToolbar.logic.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,15 @@ export interface EngineToolbarView {
255255
/** The engine this toolbar targets — the project's server-DETECTED engine
256256
* type (`activeProject.engineType` in `ChatView.tsx`), never a user
257257
* choice — owner ruling: engine identity is detection, not a picker.
258-
* `null` means no engine is known for the project at all: the toolbar
259-
* still renders (as "No engine"), but with no control cluster. */
258+
* `null` means no engine is known for the project at all.
259+
*
260+
* Superseded ruling (no-engine-ui-for-non-game-projects spec, rev 2,
261+
* 2026-08-08): a `null` engine used to still render the toolbar, as a
262+
* placeholder undetected-engine badge with no control cluster. The
263+
* owner's screenshot report ("just not show the no engine chip … and
264+
* any other chip that is game harness specific") replaced that:
265+
* `EngineToolbar.tsx` now renders NOTHING for this view — see its own
266+
* early-return doc comment. */
260267
readonly engineType: EngineType | null;
261268
/** `null` exactly when `engineType` is `null` — see `resolveEngineDispatchBackend`. */
262269
readonly backend: EngineDispatchBackend | null;

‎apps/web/src/components/EngineToolbar.test.tsx‎

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,33 @@ const THREEJS_VIEW: EngineToolbarView = {
2525
unitySetupResolved: true,
2626
};
2727

28+
// The exact shape `resolveEngineToolbarView({ engineType: null,
29+
// connectedEditor: null })` returns (EngineToolbar.logic.ts) — used below to
30+
// prove the component's own null-engine contract without hand-typing a
31+
// second, potentially-drifting literal.
32+
const NULL_ENGINE_VIEW: EngineToolbarView = {
33+
engineType: null,
34+
backend: null,
35+
requiresPresenceCommandScope: false,
36+
hasConnectedEditor: false,
37+
availableActions: [],
38+
playState: null,
39+
disabledReason: null,
40+
unitySetupCheckFailed: false,
41+
unityInstallOffered: false,
42+
unitySetupPending: false,
43+
unitySetupResolved: false,
44+
};
45+
46+
// no-engine-ui-for-non-game-projects spec (rev 2), critique F4: `view` is
47+
// now the toolbar's ONLY engine input (the deleted `resolvedEngineType`
48+
// prop used to let a caller pass a DISAGREEING engine — see the flipped
49+
// null-case test below, and the `NULL_ENGINE_VIEW` fixture it needs to be
50+
// a true anchor rather than a coincidence of two inputs happening to
51+
// agree).
2852
function renderToolbar(overrides: Partial<EngineToolbarProps> = {}) {
2953
return renderToStaticMarkup(
3054
<EngineToolbar
31-
resolvedEngineType="threejs"
3255
view={THREEJS_VIEW}
3356
onAction={() => {}}
3457
hasPresenceCommandScope={false}
@@ -170,10 +193,21 @@ describe("EngineToolbar engine label is a static badge, not a picker", () => {
170193
expect(isInsideButton(html, "three.js")).toBe(false);
171194
});
172195

173-
it("still renders 'No engine' for the null case", () => {
174-
const html = renderToolbar({ resolvedEngineType: null });
175-
176-
expect(hasExactText(html, "No engine")).toBe(true);
196+
// Flipped (no-engine-ui-for-non-game-projects spec, rev 2, Scope A): this
197+
// used to prove the placeholder undetected-engine badge rendered for the
198+
// null case; the owner's 2026-08-08 screenshot report ("just not show the
199+
// no engine chip … and any other chip that is game harness specific")
200+
// replaced that badge with nothing at all. `NULL_ENGINE_VIEW` matches exactly
201+
// what `resolveEngineToolbarView({ engineType: null, connectedEditor:
202+
// null })` produces (EngineToolbar.logic.ts) — the fixture correction
203+
// critique F4 called for: with `resolvedEngineType` deleted, `view` is
204+
// this test's ONLY engine input, so a red run here is a true anchor
205+
// rather than an artifact of two disagreeing props (the OLD fixture
206+
// passed `resolvedEngineType: null` while `view` stayed `THREEJS_VIEW`).
207+
it("renders nothing for the null-engine case", () => {
208+
const html = renderToolbar({ view: NULL_ENGINE_VIEW });
209+
210+
expect(html).toBe("");
177211
});
178212
});
179213

@@ -241,13 +275,7 @@ const UNITY_READY_VIEW: EngineToolbarView = {
241275

242276
function renderUnityToolbar(view: EngineToolbarView, overrides: Partial<EngineToolbarProps> = {}) {
243277
return renderToStaticMarkup(
244-
<EngineToolbar
245-
resolvedEngineType="unity"
246-
view={view}
247-
onAction={() => {}}
248-
hasPresenceCommandScope
249-
{...overrides}
250-
/>,
278+
<EngineToolbar view={view} onAction={() => {}} hasPresenceCommandScope {...overrides} />,
251279
);
252280
}
253281

@@ -554,12 +582,7 @@ describe("EngineToolbar — non-Unity editor-presence toolbar is untouched", ()
554582

555583
it("still renders the full Play/Pause/Stop cluster and play-target chevron for Godot", () => {
556584
const html = renderToStaticMarkup(
557-
<EngineToolbar
558-
resolvedEngineType="godot"
559-
view={GODOT_READY_VIEW}
560-
onAction={() => {}}
561-
hasPresenceCommandScope
562-
/>,
585+
<EngineToolbar view={GODOT_READY_VIEW} onAction={() => {}} hasPresenceCommandScope />,
563586
);
564587

565588
expect(hasAriaLabel(html, "Play")).toBe(true);
@@ -604,12 +627,7 @@ describe("EngineToolbar — disabled Unity controls' accessible names (#107)", (
604627
unitySetupPending: false,
605628
};
606629
const html = renderToStaticMarkup(
607-
<EngineToolbar
608-
resolvedEngineType="godot"
609-
view={godotNotConnected}
610-
onAction={() => {}}
611-
hasPresenceCommandScope
612-
/>,
630+
<EngineToolbar view={godotNotConnected} onAction={() => {}} hasPresenceCommandScope />,
613631
);
614632

615633
expect(hasAriaLabel(html, "No editor connected")).toBe(false);

‎apps/web/src/components/EngineToolbar.tsx‎

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,6 @@ const ACTION_LABEL: Readonly<Record<EngineToolbarAction, string>> = {
6161
};
6262

6363
export interface EngineToolbarProps {
64-
/**
65-
* The DETECTED engine — never a user choice (owner ruling: "it's not a
66-
* 'pick your project', it's just detection of project type, so we should
67-
* not have it selectable"). `null` when nothing's been detected for this
68-
* project yet — the label still renders (as "No engine"), the control
69-
* cluster does not.
70-
*/
71-
readonly resolvedEngineType: EngineType | null;
7264
readonly view: EngineToolbarView;
7365
/** One callback for every control button — the caller switches on the
7466
* action rather than this component exposing four separate props. */
@@ -129,9 +121,17 @@ export interface EngineToolbarProps {
129121

130122
export function EngineToolbar(props: EngineToolbarProps) {
131123
const { view } = props;
132-
const engineLabel = props.resolvedEngineType
133-
? ENGINE_LABELS[props.resolvedEngineType]
134-
: "No engine";
124+
// no-engine-ui-for-non-game-projects spec (rev 2), Scope A: a null engine
125+
// renders NOTHING — the placeholder engine-label badge this used to show
126+
// for an undetected project is gone entirely. The rule lives HERE, in
127+
// the component's own contract, rather than at each call site's gate, so
128+
// no future caller of `EngineToolbar` can resurrect the chip by
129+
// forgetting an outer condition. `view.engineType` (not a second,
130+
// separately-passed prop — see the deleted `resolvedEngineType`,
131+
// critique F4) is the single source `resolveEngineToolbarView` already
132+
// resolves a null/unknown engine down to.
133+
if (view.engineType === null) return null;
134+
const engineLabel = ENGINE_LABELS[view.engineType];
135135

136136
return (
137137
<div className="flex shrink-0 items-center gap-2" data-engine-toolbar="true">
@@ -144,7 +144,8 @@ export function EngineToolbar(props: EngineToolbarProps) {
144144
closest `Badge` size to the removed button's height (`Button`'s
145145
`xs`), so this control's neighbours in the header row don't visibly
146146
reflow. Unity replaces this badge with its merged icon-led control;
147-
every other engine and the no-engine case retain it.
147+
every other detected engine retains it (the no-engine case never
148+
reaches this JSX at all any more — see the early return above).
148149
*/}
149150
{view.backend !== "unity-cli" ? (
150151
<Badge variant="outline" size="lg" className="max-w-24 truncate px-2 font-medium">

‎apps/web/src/components/chat/ChatComposer.tsx‎

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type {
22
ApprovalRequestId,
3+
EngineType,
34
EnvironmentId,
45
ModelSelection,
56
PreviewAnnotationPayload,
@@ -498,6 +499,21 @@ export interface ChatComposerProps {
498499
routeThreadRef: ScopedThreadRef;
499500
draftId: DraftId | null;
500501

502+
/**
503+
* The three-state engine signal (`resolveEngineChipState`,
504+
* `ChatView.logic.ts`) — MEMO-SAFE primitives, not an `EnvironmentProject`
505+
* object, since this component is `memo`'d (critique F8). Gates the
506+
* editor-presence chip row's mount at this file's `EditorPresenceChips`
507+
* call site: `"none"` unmounts it (a fourth condition alongside the
508+
* existing mobile-collapsed/approval/pending-input three); `"unknown"`
509+
* keeps it mounted so a project switch never re-mints the presence
510+
* socket or flashes "connecting…" (spec critique F1).
511+
*/
512+
engineChipState: "unknown" | "none" | EngineType;
513+
/** `activeProject?.workspaceRoot ?? null` — threaded straight into
514+
* `EditorPresenceChips` for its own project scoping. */
515+
presenceWorkspaceRoot: string | null;
516+
501517
// Thread context
502518
activeThreadId: ThreadId | null;
503519
activeThreadEnvironmentId: EnvironmentId | undefined;
@@ -608,6 +624,8 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
608624
routeKind,
609625
routeThreadRef,
610626
draftId,
627+
engineChipState,
628+
presenceWorkspaceRoot,
611629
activeThreadId,
612630
activeThreadEnvironmentId: _activeThreadEnvironmentId,
613631
activeThread,
@@ -2895,10 +2913,23 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
28952913
</ComposerCommandMenuLayer>
28962914
)}
28972915

2916+
{/* no-engine-ui-for-non-game-projects spec (rev 2), Scope B: ONE
2917+
new condition beyond the pre-existing three below —
2918+
`engineChipState === "none"` unmounts this row for a
2919+
non-game project. `"unknown"` deliberately stays mounted
2920+
(never added here) so a project switch's in-flight window
2921+
never re-mints the presence socket or flashes
2922+
"connecting…" (critique F1). */}
28982923
{!isComposerCollapsedMobile &&
28992924
!isComposerApprovalState &&
2900-
pendingUserInputs.length === 0 && (
2901-
<EditorPresenceChips environmentId={environmentId} className="mb-3" />
2925+
pendingUserInputs.length === 0 &&
2926+
engineChipState !== "none" && (
2927+
<EditorPresenceChips
2928+
environmentId={environmentId}
2929+
workspaceRoot={presenceWorkspaceRoot}
2930+
engineChipState={engineChipState}
2931+
className="mb-3"
2932+
/>
29022933
)}
29032934

29042935
{!isComposerCollapsedMobile &&

0 commit comments

Comments
 (0)