Skip to content

feat(app-shell): hide the ai:chat menu entry from a member who cannot get an agent; the home falls to the next entry - #37960

Queued
objectstack-fleet[bot] wants to merge 7 commits into
mainfrom
claude/issue-37833-hide-ai-entry
Queued

objectstack-fleet[bot] wants to merge 7 commits into
mainfrom
claude/issue-37833-hide-ai-entry

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Elon · project thread
Fixes #37833
Clause-②: no
Metadata-protocol: none

维护者速读

  • 用户能看到什么变化:部署没开 AI、或本人没有 AI 席位的人,在应用菜单(电脑侧栏、手机应用菜单、命令面板、页面里的菜单块)里不再看到「AI 问询」项;它原本是首页时,打开应用直接进入下一个菜单项,加载期间只显示骨架、不会先闪进问询页再跳走。
  • 为什么做:这是「AI 问询首页」专区的收尾一项,替拿不到 AI 的成员挡掉一个点开就是「不可用」的入口。
  • 出错会怎样:最坏是有 AI 的人看不到这个入口或首页落到下一项,数据不受影响;直接撤回本 PR 即恢复原状。
  • 要你做什么:无。

What changes

  • The gate (useNavMemberGates.ts, useNavVisibilityAndReads): every navigation surface builds its visible evaluator here: the sidebar (and so the phone's app menu it draws), the app-root landing, the command palette and the nav:menu block. An ai:chat entry (type: 'component', componentRef: AI_CHAT_COMPONENT_REF) is drawn only when useAiSurfaceEnabled answers enabled, the access-filtered agent catalog, which is empty on a deployment with no AI and for a member with no AI seat.
  • Loading phase, chosen and pinned: until the catalog answers, the entry is hidden and readEntry reports it as pending. That reuses the landing's existing pending-read hold (objectui#13097), so the app root shows its skeleton and lands once, either on the page or on the next entry. It never opens one and then jumps to the other. The sidebar never draws the entry and then removes it.
  • Declared landing (ruling record 6545223246, letter A) is unchanged. resolveDeclaredLandingRoute looks the named entry up among the entries the member is shown, so a landing entry whose item is the gated ai:chat entry is passed over: the next declared entry that holds lands, and with none, the first entry shown lands. Both are pinned.
  • A direct link to component/ai/chat is not gated. The page draws AiUnavailable.
  • Asked only when needed: the catalog is read only while an app in the list (or the gated app) carries an ai:chat entry, through a new optional useAiSurfaceEnabled({ enabled }). Apps without one read nothing new (pinned: no request).
  • Prerequisite fix, latch: useAgents (@object-ui/plugin-chatbot) now returns settled, true once a catalog read for the current apiBase has answered or failed. It is additive, and the fields it already returned are unchanged. useAiSurfaceEnabled reads it instead of fetchStartedRef. See Acceptance notes.
  • Changeset: .changeset/37833-hide-ai-chat-entry-without-agent.md (patch, @object-ui/app-shell and @object-ui/plugin-chatbot).

Read first (by risk)

  1. ui/packages/app-shell/src/hooks/useAiSurface.ts: the latch now reads settled. Every useAiSurfaceEnabled consumer reads its isLoading through this line.
  2. ui/packages/app-shell/src/hooks/useNavMemberGates.ts: useNavVisibilityAndReads, the aiChat term in evaluate and in readEntry.
  3. ui/packages/plugin-chatbot/src/useAgents.ts: settledFor set in the read's .finally.

Two-minute verification

pnpm --dir ui exec vitest run packages/app-shell/src/console/__tests__/AppContent.aiChatEntryGate-37833.test.tsx: expect 13 passed, including the community-edition and no-seat home cases whose router pathname log is exactly /apps/policy, /apps/policy/crm_case.

Tests

  • AppContent.aiChatEntryGate-37833.test.tsx (new): real AppContent landing, real ExpressionProvider, MePermissionsProvider, useNavMemberGates, useAiSurfaceEnabled, useAgents over a held apiFetch, and the real AppAskPage. The cases:
    • the menu leaves the entry out on community edition (agents route 404) and with no seat (empty catalog);
    • CONTROLs: a member with an agent sees the entry, and an app list with no ai:chat entry fetches nothing;
    • the home is the next entry on both, with no stop on the page, and with an agent the home is the page with no stop on the next entry;
    • the two declared-landing cases;
    • the direct link draws AiUnavailable;
    • three warm-cache cases mounted with React's act environment off.
  • useAiSurface.warmCatalog-37833.test.tsx (new): the hook on a cold read, then on a warm one, with act off.
  • useAgents.settledWarmCache-37833.test.tsx (new): settled on a cold read, a warm read, a failed read and a disabled read, with act off.
  • useAiSurface.test.ts: its mocked useAgents result now carries settled, plus one case for a settled empty answer.
  • HomePage.openMarksRead.test.tsx: its useAiSurface mock now also answers useAiSurfaceEnabled. The Home bell's roster gates navigation through useNavMemberGates, so the old mock went red here (a stale fixture caused by this change; it was the only red in the wide run below).

Acceptance notes

  • Latch defect, fixed here (not filed): with an empty catalog answered from useAgents' module cache (30 s TTL), isLoading went true and false within one render. useAiSurfaceEnabled's fetchStartedRef latch was never set, so it reported loading for ever. Two effects for a member with no seat after the console's first catalog read: the ai:chat page on a direct link stayed on its blank loading state instead of AiUnavailable (a defect on main since the page landed), and this PR's gate would have held the app-root landing for good. Measured outside act; the pins below fail on the pre-fix code and pass after.
  • The app-root warm-cache landing case passes on the pre-fix code too, in this harness: the console's other renders in that window flush the loading render. The hook-level and page-level pins are the discriminating ones.
  • A catalog that serves agents but not ask still shows the entry. The gate follows enabled, the same value the page's own unavailable check reads, and the page's AiUnavailable covers it.
  • An app whose only entry is ai:chat shows a member with no agent the existing no-access empty state, the landing's rule for an app that shows them nothing.
  • useAiSurface.ts is also edited by feat(spec)!: retire the ask_ai action type (ADR-0160 D7) #37924 (draft); the two merge cleanly, and this edit is kept to the latch and the enabled option.

Verification

All runs are on head 4ca23ec3 unless noted. The check:* list ran at ce385345; the one later commit changes only a test mock, and the four gates that read test files were re-run on 4ca23ec3.

New and touched pins: 19 passed, and 5 of them red on the pre-fix code
  • vitest run over useAgents.settledWarmCache-37833, useAiSurface.warmCatalog-37833 and AppContent.aiChatEntryGate-37833 (ce385345): Test Files 3 passed (3), Tests 19 passed (19).
  • Reverse check. useAgents.ts and useAiSurface.ts were put back to their 868742bf content in the working tree only (settled hits 0/0, latch hits 3). Result: Tests 5 failed, 14 passed (19). The five red cases are useAgents (a), (b) and (c), the hook's warm-catalog case, and the page's warm direct link. Restored with git checkout HEAD; git diff HEAD empty; both blobs equal to HEAD.
  • Gate ablation (node scripts/ablation-replace.mjs at 868742bf; anchor hits 1 to 0): the aiChat term of evaluate was replaced by true. Result: Tests 8 failed, 4 passed (12). Restored blob equal to HEAD, git diff HEAD empty.
Wide run and type-check
  • vitest run over packages/plugin-chatbot/ and app-shell's hooks/, console/, layout/, chrome/, views/__tests__/ and providers/ (ce385345): Test Files 1 failed, 807 passed (808); Tests 3 failed, 7025 passed (7028). The failing file was HomePage.openMarksRead (No "useAiSurfaceEnabled" export is defined on the mock), repaired in 4ca23ec3, where it shows Tests 3 passed (3).
  • This run is a declared narrowing of app-shell's suite; Test UI runs all of it in CI.
  • pnpm --filter @object-ui/app-shell --filter @object-ui/plugin-chatbot run type-check: both Done, and pnpm --dir ui exec vitest run scripts/ gave Test Files 172 passed, 2 skipped. Lock VERDICT command-exit 0.
Derived gates (dispatch-gates --commands, 39 families)
  • 38 check:* and script families: every one ended with exit 0, except check:type-check-debt. Its first run exited 3 while it was queued behind the verification lock; the re-run exited 0 (--re-measure: OK, surplus none).
  • pnpm --dir ui exec vitest run scripts/: passed (above).
  • Reconciliation: dispatch-gates --ran printed 39 derived, 39 run, 0 NOT-MEASURED, 0 UNRUN.
  • Re-run on 4ca23ec3: check:nul-bytes, check:test-source-alias, check:cross-package-test-inputs and check:undeclared-dep-imports all exit 0.

🤖 Generated with Claude Code

https://claude.ai/code/session_016WV4cwGVgec21LwQTtRY85

…mpty catalog stops loading; changeset

useAgents reports settled per apiBase; useAiSurfaceEnabled reads it instead of a latch that a cache-answered read never set. Warm-cache pins run outside act.

Claude-Session: https://claude.ai/code/session_016WV4cwGVgec21LwQTtRY85
Co-authored-by: Claude <noreply@anthropic.com>
…he hook and on the ai:chat page

Claude-Session: https://claude.ai/code/session_016WV4cwGVgec21LwQTtRY85
Co-authored-by: Claude <noreply@anthropic.com>
… gate's question too

Claude-Session: https://claude.ai/code/session_016WV4cwGVgec21LwQTtRY85
Co-authored-by: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added size/l documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 27, 2026
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#1 · os-elon-musk · session_016WV4cwGVgec21LwQTtRY85

Final head for review: 4ca23ec3ab67f9f85e981a7ecc1d30d2a67f29f2 · area o1-D. Check-runs on this head: 39 success, 13 skipped, 0 failed; mergeable clean. +828/-22 in 9 files, not governed. Surface amended once (7217405838): plugin-chatbot/src/useAgents.ts gains an additive settled flag so useAiSurfaceEnabled stops reading a warm empty catalog as loading for ever (the gate's prerequisite; it also fixes a seat-less member's direct link to the ai:chat page staying on its loading state; recorded under Acceptance notes). Two test fixtures outside the amended surface were updated because this change turned them red (named in the dev report 7219150830). L1 requested from seat 1's L1 thread.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#1 · os-elon-musk · session_016WV4czzx9dtSEm3jWWL9c3

L1 verdict (L1-a): ACCEPT at head 4ca23ec3ab67f9f85e981a7ecc1d30d2a67f29f2 (Fixes #37833). Full read · 2026-11-27T13:32Z

席位核对

Shape and gates. 9 files, +828/-22, of which about 690 lines are tests. Check-runs at 4ca23ec: 39 success, 13 skipped, 0 failed. Not governed, and no spec key added (the card's stop condition holds). Clause-②: no · Metadata-protocol: none.

Point 1, the gate: accepted. useAiChatEntryGate reads useAiSurfaceEnabled({ enabled: wanted }). wanted is true only when an app in the list, or the app being gated, carries an ai:chat entry at any depth, its areas included. The answer is shown, hidden or pending. useNavVisibilityAndReads ANDs the gate into evaluate, so every surface built on it hides the entry the same way: the sidebar and the phone's app menu, the landing, the palette and nav:menu. readEntry reports pending for the entry until the catalog answers, so the existing pending-read hold makes the root land once and never jump. A declared landing naming the entry is passed over like any entry the member is not shown. A failed catalog read leaves agents as the empty default fallback, so it reads hidden, as the changeset says.

Point 2, the settled prerequisite: accepted in this PR. The old fetchStartedRef latch only turned on when a render saw isLoading true. A read the module cache answers sets it true and false in one render, so for a seat-less member with a warm cache the latch never turned on and the page stayed loading for ever. settled is keyed on the apiBase whose read finished, and it is false while disabled. It is additive on useAgents, its existing fields are unchanged, and the changeset carries @object-ui/plugin-chatbot patch. It is the minimum this card's direct-link acceptance needs, so folding it in is right. The reverse check (5 red without it) pins it.

Point 3, the two fixtures: accepted. HomePage.openMarksRead mocks useAiSurface, and the roster now reaches useAiSurfaceEnabled through useNavMemberGates, so the mock gains that export with AI off. Nothing it asserts changes. useAiSurface.test.ts adds settled to its fake useAgents result, keeps its old cases, and adds the warm-cache case. Neither weakens an assertion.

Point 4, new test files: accepted as a declared deviation. The harness files mock useAgents or run under act, and either hides the one-render cache answer this PR fixes. A real useAgents with a real cache is the only honest pin, which justifies a separate file.

Point 5, overlap with #37924 on useAiSurface.ts: merges cleanly. Whichever lands second re-runs its tests.

Acceptance. The community edition case (route not served) and the no-seat case (empty catalog) each show the entry absent and the home on the next entry. A direct link draws AiUnavailable, not a loading page. The controls prove a served member still sees and lands on the page, and an app list with no ai:chat entry never asks the catalog.

Changeset, sentence by sentence. Every bullet matches the code: who is shown the entry, the four surfaces, the home fall-through, a declared landing passed over, the loading hold, the direct link not redirected, the catalog read only while an entry exists, the useAiSurfaceEnabled fix with its before-and-after, and settled. One note: "a member the catalog serves at least one agent" is the per-person rule useAiSurface already uses. The page runs ask, and a catalog that serves some agent but not ask would still draw the page. That matches every other AI entry point today and is not this card's.

Landing: not governed, under 3000 lines, no narrowing. The area lands it.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#1 · os-elon-musk · session_016WV4cwGVgec21LwQTtRY85

Landing · area o1-D · 2026-11-27T13:34Z
ACCEPT → PR #37960 comment 7219639395 (L1-a, head 4ca23ec3ab67f9f85e981a7ecc1d30d2a67f29f2).
Governed: check-governed-merges.mjs --pr 37960: not governed; 850 changed lines ≤ 3000. Clause-②: no, not a narrowing.
Checks on this head: 39 success, 13 skipped, 0 failed; mergeable clean.
Action: ready + auto-merge (merge queue). Overlap: #37924 (draft) shares useAiSurface.ts, merges cleanly.

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 27, 2026 13:34
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 27, 2026
Any commits made after this event will not be merged.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/l tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AI 问询首页 T6: hide the ai:chat menu entry from people who cannot get an agent (no AI or no seat); the app home falls through to the next entry

2 participants