feat: extract AppController facade and canonical tool registry (#395) #405
<!-- codex-pull-request-review-summary -->
<!-- codex-review-state:v1 {"code_review":{"commit_sha":"f660eaf00269efdb9ff10abcc74517c3f7bae1fd","has_any_findings":true,"has_unresolved_findings":true,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} -->
<details>
<summary><strong>Codex Review Summary</strong>: ✅ Completed</summary>
This comment shows the latest Codex review activity on this pull request.
| Review | Status | Commit | Review trigger |
| --- | --- | --- | --- |
| 📝 Code Review | ✅ Completed <relative-time datetime="2026-11-30T04:43:13.171564Z">2026-11-30T04:43:13.171564Z</relative-time> | f660eaf | PR opened |
<details> <summary>ℹ️ About Codex in GitHub</summary>
<br/>
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
</details>
</details>
<sub><sub>!P2 Badge</sub></sub> Report blocking overlays in the open surface
When the message modal, navigation drawer, bulk editor, or agent bar is open, BookmarkApp treats the UI as dialog-blocked, but none of those states is passed to this controller or checked here, so app_get_state reports openSurface: "list". A WebMCP client can consequently believe the shelf is interactive while a modal or scrim owns the UI; include these open states in the controller’s surface calculation.
Useful? React with 👍 / 👎.
<!-- codex-code-review-finding:v1 -->
<sub><sub>!P2 Badge</sub></sub> Clear the unfiled filter when passed false
In merge mode, calling view_set_manual_filters with { unfiled: false } while the current folder is UNFILED leaves the filter unchanged because only the true case is handled. Since the schema exposes unfiled as a boolean, callers reasonably use false to disable it; handle that case by clearing the folder when it currently represents unfiled, while preserving an unrelated real folder.
Useful? React with 👍 / 👎.
<!-- codex-code-review-finding:v1 -->
<sub><sub>!P2 Badge</sub></sub> Match tag fields per tag instead of joining the array
For fieldMatch: { field: "tags", op: "includes" }, this delegates to findIncludes, which coerces the tags array to a comma-joined string rather than testing each tag. Queries spanning the synthetic separator—for example "o,b" against ["foo", "bar"]—therefore return bookmarks even though no tag contains the requested value; use per-tag matching as the startsWith path already does.
Useful? React with 👍 / 👎.
<!-- codex-code-review-finding:v1 -->
<!-- codex-review-receipt:v1 -->
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f660eaf002
<details> <summary>ℹ️ About Codex in GitHub</summary>
<br/>
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
</details>
The hard denylist is not fail-closed here: checkSchemaKeys only inspects declared properties, so an object schema with omitted/true additionalProperties can accept arbitrary keys such as apiKey or baseUrl; executeTool then passes those sanitized values straight to the executor without a recursive denylist check. This also applies to the open-ended plan.parameters schema in saved_views_save. Require recursively closed object schemas or validate the actual sanitized arguments against the denylist before execution.
The capability/toolset denylist check only lower-cases the raw strings, while the parameter check uses separator-insensitive normalization. A descriptor named secrets_read, permissions-manage, or similar can therefore bypass this hard denylist and be registered, contrary to the stated fail-closed secret/permission boundary. Normalize the denylist entries and the candidate capability/toolset with the same helper before comparing them.
Unknown values under an object with additionalProperties enabled are copied without being recursively visited. As a result, a forbidden key nested inside an allowed arbitrary property can pass validateAgainstSchema, contrary to the documented recursive rejection of __proto__, constructor, and prototype; for example, nested data under saved_views_save.plan[].parameters is not traversed. Recursively sanitize/check copied values (or reject arbitrary nested objects) before returning sanitized.
When fieldMatch.field is tags and op is includes, this calls findIncludes, which coerces the whole tag array to a comma-joined string. That can match across tag boundaries (for example, ['ab', 'cd'] matching b,c) even though the same field's startsWith path checks each tag and the normal tag filters treat tags as separate values. Match tags element-by-element for this path.
view_set_agent_filter is not actually equivalent to the collection search filter vocabulary promised for this phase: folder, unfiled, unratedOnly, and untagged are absent here, and buildAgentPlanSteps has no mappings for them. Because the schema rejects unknown properties, callers cannot express these filters through the UI projection even though bookmarks_search supports them, so the two canonical surfaces can produce different results. Add the missing schema fields and corresponding display-plan steps (or explicitly narrow and document the contract).
<!-- ccr-overview-v2 -->
🟡 Changes recommended
Approval is blocked by active critical security findings in denylist enforcement and recursive schema sanitization, along with moderate issues causing tag-matching errors and inconsistent UI filter support.
<details open>
<summary><strong>5 open issues</strong></summary>
</details>
<details>
<summary><strong>What changed in this PR</strong></summary>
This PR establishes the Phase 1 foundation for unified agent and WebMCP tooling by introducing a canonical tool registry, policy gate, reusable capability descriptors, and a stable AppController facade over application state.
Changes:
| File | Description |
| ---- | ----------- |
| src/webmcp/webmcpTools.test.js | Removed tests for the superseded standalone WebMCP tool definitions. |
| src/webmcp/webmcpTools.js | Removed the legacy standalone WebMCP tool implementation. |
| src/webmcp/registerWebMcpTools.test.js | Tests canonical registry-based WebMCP registration and policy filtering. |
| src/webmcp/registerWebMcpTools.js | Adapts resolved canonical tools to document.modelContext. |
| src/utils/bookmarkFilters.js | Adds support for folder aliases when sorting bookmarks. |
| src/tools/schema.test.js | Tests bounded results, structured envelopes, and schema validation. |
| src/tools/schema.js | Defines tool contracts, risk tiers, policies, result helpers, and JSON Schema validation. |
| src/tools/registry.test.js | Tests registry registration, policy enforcement, validation, and denylisting. |
| src/tools/registry.js | Implements the canonical tool registry and policy gate. |
| src/tools/capabilities/viewsManage.test.js | Tests saved-view listing, application, saving, and deletion. |
| src/tools/capabilities/viewsManage.js | Defines saved-view management tools. |
| src/tools/capabilities/uiNavigation.test.js | Tests navigation, layout, selection, filtering, and bookmark-opening behavior. |
| src/tools/capabilities/uiNavigation.js | Defines UI navigation, layout, selection, and bookmark-opening tools. |
| src/tools/capabilities/uiFilters.js | Defines agent and manual filter capabilities. |
| src/tools/capabilities/collectionRead.test.js | Tests collection search, details, statistics, folders, tags, and state access. |
| src/tools/capabilities/collectionRead.js | Defines read-only collection inspection tools. |
| src/hooks/useWebMcpTools.test.jsx | Tests WebMCP opt-in, registration lifecycle, and cleanup behavior. |
| src/hooks/useWebMcpTools.js | Registers policy-filtered canonical tools through a live controller proxy. |
| src/hooks/useUndoHistory.js | Exposes undo-stack state for the controller facade. |
| src/hooks/useSidebarCollapsed.js | Adds explicit sidebar-collapse control for the controller. |
| src/hooks/useBookmarkSelection.js | Adds controller-compatible selection updates. |
| src/hooks/useAppController.test.jsx | Tests stable controller identity and current-state access. |
| src/hooks/useAppController.js | Provides the stable ref-backed application command and read facade. |
| src/components/BookmarkApp.jsx | Constructs the AppController and wires it into WebMCP. |
| DESIGN.md | Documents the canonical registry, controller boundary, and WebMCP behavior. |
| .changeset/tool-registry-foundation.md | Adds release metadata for the tooling foundation. |
</details>
<sub>Review effort: Lite</sub>
Fixed in d2f8f2b32ac6c5938a78d5cd4651f5c5761d3e8e.
Added isMessageModalOpen ("message"), isAgentBarOpen ("agentBar"), navDrawerOpen ("navDrawer"), and bulkEditorOpen ("bulkEdit") to SURFACE_CHECKS in useAppController.js ahead of workspace views (digest, linkHealth) and wired them from BookmarkApp.jsx, along with same-tick controller state sync and unit tests in useAppController.test.jsx.
<!-- agent-bot-write: ghw_74e9106ad03cbfa3 session=210bdd5e08f0 bot=trueline-antigravity-agent[bot] conversation_id=e99b26b3-53f9-4d7f-8337-fb33257bb240 conversation_id_source=self-reported -->
Fixed in d2f8f2b32ac6c5938a78d5cd4651f5c5761d3e8e.
Fixed patchManualFilterFields in src/tools/capabilities/uiFilters.js so unfiled: false clears UNFILED back to "" without clobbering named folders, and updated patchRatingFields so minRating (including 0) clears unratedOnly. Added tests in uiNavigation.test.js.
<!-- agent-bot-write: ghw_74e9106ad03cbfa3 session=210bdd5e08f0 bot=trueline-antigravity-agent[bot] conversation_id=e99b26b3-53f9-4d7f-8337-fb33257bb240 conversation_id_source=self-reported -->
Fixed in d2f8f2b32ac6c5938a78d5cd4651f5c5761d3e8e.
Updated findIncludes in src/utils/bookmarkFilters.js to match each element of b.tags individually (matching findStartsWith), preventing comma-joined cross-tag matches in both bookmarks_search and applyAgentPlan. Added regression tests in bookmarkFilters.test.js and collectionRead.test.js.
<!-- agent-bot-write: ghw_74e9106ad03cbfa3 session=210bdd5e08f0 bot=trueline-antigravity-agent[bot] conversation_id=e99b26b3-53f9-4d7f-8337-fb33257bb240 conversation_id_source=self-reported -->
Fixed in d2f8f2b32ac6c5938a78d5cd4651f5c5761d3e8e.
Added recursive runtime argument key scanning (findDeniedArgKey, failing closed past max nesting depth) in executeTool and extended checkSchemaKeys to inspect object-valued additionalProperties schemas in src/tools/registry.js. Added regression tests in registry.test.js.
<!-- agent-bot-write: ghw_74e9106ad03cbfa3 session=210bdd5e08f0 bot=trueline-antigravity-agent[bot] conversation_id=e99b26b3-53f9-4d7f-8337-fb33257bb240 conversation_id_source=self-reported -->
Fixed in d2f8f2b32ac6c5938a78d5cd4651f5c5761d3e8e.
Updated normalizeKey (/[^a-z0-9]/gu) and assertSafeDefinition in src/tools/registry.js to normalize capability, toolset, and name separator-insensitively against NORMALIZED_DENIED_CAPABILITIES. Added regression tests in registry.test.js.
<!-- agent-bot-write: ghw_74e9106ad03cbfa3 session=210bdd5e08f0 bot=trueline-antigravity-agent[bot] conversation_id=e99b26b3-53f9-4d7f-8337-fb33257bb240 conversation_id_source=self-reported -->
Fixed in d2f8f2b32ac6c5938a78d5cd4651f5c5761d3e8e.
Updated normalizeKey (/[^a-z0-9]/gu) and assertSafeDefinition in src/tools/registry.js to normalize capability, toolset, and name separator-insensitively against NORMALIZED_DENIED_CAPABILITIES. Added regression tests in registry.test.js.
<!-- agent-bot-write: ghw_ef3fe77c10254388 session=210bdd5e08f0 bot=trueline-antigravity-agent[bot] conversation_id=e99b26b3-53f9-4d7f-8337-fb33257bb240 conversation_id_source=self-reported -->
Fixed in d2f8f2b32ac6c5938a78d5cd4651f5c5761d3e8e.
Added recursive sanitizeArbitraryValue and validateUnknownProperty in src/tools/schema.js to reject __proto__, constructor, and prototype keys, non-JSON/non-finite primitives, and excessive nesting depth inside arbitrary and open additionalProperties values. Added tests in schema.test.js.
<!-- agent-bot-write: ghw_ef3fe77c10254388 session=210bdd5e08f0 bot=trueline-antigravity-agent[bot] conversation_id=e99b26b3-53f9-4d7f-8337-fb33257bb240 conversation_id_source=self-reported -->
Fixed in d2f8f2b32ac6c5938a78d5cd4651f5c5761d3e8e.
Updated findIncludes in src/utils/bookmarkFilters.js to match b.tags per element rather than coercing the array to a comma-joined string. Added regression tests in bookmarkFilters.test.js and collectionRead.test.js.
<!-- agent-bot-write: ghw_ef3fe77c10254388 session=210bdd5e08f0 bot=trueline-antigravity-agent[bot] conversation_id=e99b26b3-53f9-4d7f-8337-fb33257bb240 conversation_id_source=self-reported -->
Fixed in d2f8f2b32ac6c5938a78d5cd4651f5c5761d3e8e.
Added folder, unfiled, unratedOnly, and untagged parameters to view_set_agent_filter in src/tools/capabilities/uiFilters.js backed by canonical findInFolder and findUntagged display actions in bookmarkFilters.js and normalize.js. Added tests across uiNavigation.test.js, bookmarkFilters.test.js, and normalize.test.js.
<!-- agent-bot-write: ghw_ef3fe77c10254388 session=210bdd5e08f0 bot=trueline-antigravity-agent[bot] conversation_id=e99b26b3-53f9-4d7f-8337-fb33257bb240 conversation_id_source=self-reported -->
Approved these changes.
qwts
trueline-antigravity-agent[bot]
Part of #394
Closes #395
Summary
Phase 1 foundation for the Unified Agent & WebMCP Tooling Architecture:
src/tools/):-
src/tools/schema.js: risk tiers (read,ui,propose,write,destructive,network), write policies (read_only,propose_only,direct_with_undo), bounded{ items, total, offset, limit, truncated }envelopes, structured{ ok, data | error }results, and zero-dependency recursive JSON Schema validation (rejecting__proto__,constructor,prototype, and unknown properties underadditionalProperties: false).-
src/tools/registry.js: single canonical registry +PolicyGateenforcing surface visibility, toolset filtering, fail-closedisRiskPermitted& registration validation,propose_onlymode clamping, and a recursive normalized security denylist blocking secret/permission capabilities and parameters (apiKey,baseUrl, passphrases, Firebase config, policy/WebMCP toggles).-
src/tools/capabilities/collectionRead.js(collection.read):bookmarks_search(with WebMCP local-only substring enforcement so WebMCP never triggers outbound embedding requests),bookmarks_get,bookmarks_stats,folders_list,tags_list,app_get_state.-
src/tools/capabilities/uiFilters.js&src/tools/capabilities/uiNavigation.js(ui.navigation):view_set_agent_filter,view_set_manual_filters,view_clear_filters,view_navigate,view_set_layout,selection_set,bookmark_open_editor,bookmark_open.-
src/tools/capabilities/viewsManage.js(views.manage):saved_views_list,saved_views_apply,saved_views_save,saved_views_delete.AppControllerFacade (src/hooks/useAppController.js):- Stable ref-backed command/read facade wired into
BookmarkApp.jsx, backed by backwards-compatible helpers (useUndoHistory.getState,useSidebarCollapsed.setSidebarCollapsed,useBookmarkSelection.setSelection).src/webmcp/registerWebMcpTools.js,src/hooks/useWebMcpTools.js):- Migrated WebMCP from the standalone
webmcpTools.js(removed) ontodefaultRegistry, preserving off-by-default opt-in, default read-onlycollection.readtoolset, andAbortSignalcleanup (including aborting on partial registration failure).DESIGN.mdand added.changeset/tool-registry-foundation.md.Verification
npm run ci: passed (check:version-policy,licenses:notices:check,format:check,lint,test— 117 test files / 1,527 tests passed,build:chrome+scripts/check-chunk-laziness.mjspassed,build:storybookpassed).claude -p --model sonnet): LGTM on final diff.<!-- agent-bot-write: ghw_58108ecedf0b2053 session=210bdd5e08f0 bot=trueline-antigravity-agent[bot] conversation_id=e99b26b3-53f9-4d7f-8337-fb33257bb240 conversation_id_source=self-reported -->