open-design/packages
Sid 05461c64fd
fix(connectors): show stable curated tool count in connector card badge (#748) (#767)
* fix(connectors): show stable curated tool count in connector card badge (#748)

The connector card's "N tools" badge in `apps/web/src/components/
EntryView.tsx` rendered `connector.tools.length` for both pre- and
post-Composio-hydration states, so the displayed count lurched
without explanation:

- Before configuring a Composio API key, GitHub showed "2 tools"
  (the static fallback catalog at `composio.ts:21-53`).
- After hydration, the daemon merged in the full Composio provider
  inventory (`composio.ts:725-778`, ~868 GitHub tools), and the
  same badge jumped to "868 tools".

Same field name, two different concepts — `connector.tools` is
"everything the provider ships" while the agent-callable subset
is `definition.allowedToolNames` (read-only auto-approval tools
that pass `isAgentPreviewListableTool()`).

Fix: surface `allowedToolNames` on the wire `ConnectorDetail` and
have the badge use that count instead. The detail drawer below
the card still iterates over `connector.tools` to enumerate the
full inventory — the count and the list are intentionally
different surfaces.

The badge now stays close to "tools the agent can actually
invoke" (≈2-30 for GitHub, depending on auto-allowed read tools)
instead of the raw provider inventory (~868). No 800x jump on
hydration.

Wire format change:
- packages/contracts/src/api/connectors.ts: add
  `allowedToolNames: string[]` to ConnectorDetail
- apps/daemon/src/connectors/catalog.ts: same field on the
  daemon-internal type, populated in `connectorDefinitionToDetail()`
  as a defensive copy of `definition.allowedToolNames`
- packages/contracts/src/examples.ts: extend the example fixture
- apps/web/src/components/EntryView.tsx: badge call sites switch
  to `connector.allowedToolNames?.length ?? connector.tools.length`
  (the `??` keeps the badge alive against any older daemon build
  that hasn't shipped the field yet)

Tests:
- 4 new daemon tests in connectors-service.test.ts pin the
  contract: getConnector() emits the field, the array is a
  defensive copy, and the #748 regression guard simulates the
  Composio post-hydration shape (tools.length=801,
  allowedToolNames.length=1) to prove the badge invariant
- web EntryView.test.ts fixtures updated to satisfy the new
  required field

Verified locally:
- daemon vitest: 925/925
- web vitest: 332/332
- daemon/web/contracts typecheck clean
- i18n-check passes
- Live `/api/connectors/discovery` returns the new field; pre-
  hydration GitHub/Notion/Google Drive badges all read "2 tools"
  (no regression vs before this change)

Fixes #748

* fix(connectors): split drawer badge vs inventory counts; fix daemon test typecheck (#767 review)

Two follow-ups for @mrcfps's review on PR #767.

1) **P1: Drawer empty-state regression.** The previous commit reused
the curated `toolCount` for both the header badge AND the inventory
section's loading gate / empty-state branch / section count. The
inventory section renders `connector.tools` directly, so a hydrated
connector with raw provider tools but an empty allowlist (e.g. a
write-only Composio surface) would render "no tools available" and
hide the actual inventory list — exactly the contradiction my own
PR description warned against.

Fix splits the two surfaces:
  - `badgeToolCount` (curated, via the new exported helper
    `getConnectorBadgeToolCount`) feeds the card and drawer header
    badge — the summary count, where the #748 stability matters.
  - `inventoryToolCount = connector.tools.length` (inline) drives the
    drawer's loading gate, section count, and empty-state branch —
    the surfaces describing the actual rendered list.

The card has no inventory section so it stays on the badge helper
unchanged.

2) **CI: daemon test typecheck failed.** The connectors-service test's
`provisionedTools[0].safety` index access tripped daemon
`tsconfig.tests.json`'s `noUncheckedIndexedAccess` strict setting,
even though my local `tsc -p tsconfig.json --noEmit` was clean —
that config is a separate compilation. Bind through a defined-checked
local before reading `.safety`, per @mrcfps's exact suggestion.

Tests:
  - 4 new web tests in `EntryView.test.ts` pin the
    `getConnectorBadgeToolCount` contract, including the explicit
    regression: a connector with `allowedToolNames=[]` and
    `tools.length=800` returns badge=0 but the inventory length
    stays at 800 — the drawer's empty-state branch must use the
    inventory count, never the badge count.
  - Existing daemon test fixed without losing assertion coverage.

Verified locally:
  - daemon vitest: 921/921
  - web vitest: 336/336 (was 332, +4)
  - daemon `tsc -p tsconfig.json` and `tsc -p tsconfig.tests.json` (the CI killer): both clean
  - web `tsc -b --noEmit` clean
  - i18n-check passes

Process learning baked into this PR: from now on I'll always run the
`tsconfig.tests.json` separately before pushing, since the workspace
typecheck script chains both and the second one is what CI fails on.

* fix(connectors): pin badge to curated catalog count, not the dynamic execution allowlist (#767 review v2)

@lefarcen and @mrcfps both flagged that the previous iteration of
this PR (commit 447a270) used `allowedToolNames` as the badge
source. That field isn't actually stable across Composio hydration:
`apps/daemon/src/connectors/composio.ts:758-761` extends it with
every provider-discovered tool whose classified safety is
read+auto, so a connector like GitHub goes from 2 → ≈52 on
hydration — better than 2 → 868, but still a 26x jump and still
the kind of unexplained number-lurch the issue is about. My
regression test only covered write-classified tools so this
read-path inflation slipped through.

Fix: introduce `curatedToolNames` as a separate field that is
locked to the static catalog and never extended by discovery.

- `packages/contracts/src/api/connectors.ts` and
  `apps/daemon/src/connectors/catalog.ts`: add
  `curatedToolNames: string[]` to `ConnectorDetail` (required on
  the wire) and as an optional field on
  `ConnectorCatalogDefinition` (defaults to allowedToolNames at
  serialize time).
- `apps/daemon/src/connectors/composio.ts`:
  `definitionFromToolkit()` now sets
  `curatedToolNames = [...staticDefinition.allowedToolNames]` —
  the catalog set, no extension. The runtime `allowedToolNames`
  keeps its dynamic auto-allow behavior so the execution gate is
  unchanged end-to-end.
- `apps/daemon/src/connectors/catalog.ts`:
  `connectorDefinitionToDetail()` populates
  `curatedToolNames: [...(definition.curatedToolNames ?? definition.allowedToolNames)]`,
  so non-Composio connectors (no discovery layer) trivially mirror
  the two fields.
- `apps/web/src/components/EntryView.tsx`:
  `getConnectorBadgeToolCount` becomes a 3-tier fallback —
  `curatedToolNames` first, then `allowedToolNames`, then
  `tools.length`. The order means a half-deployed daemon (allowed
  but not curated) still produces a more meaningful number than
  the raw inventory; only when both are missing do we fall back
  to the original buggy behavior.

Tests added:
- daemon `connectors-service.test.ts`: 3 new tests pin the
  contract — wire shape, hydration stability (catalog stays at 1
  while allowedToolNames grows to 51), and defensive copy.
- web `EntryView.test.ts`: 5 tests on `getConnectorBadgeToolCount`
  including the @lefarcen scenario explicitly: tools=800,
  allowedToolNames=52, curatedToolNames=2 → badge=2.

Verified locally:
- daemon vitest: 924/924 (was 921, +3)
- web vitest: 337/337 (was 332, +5 net)
- daemon `tsconfig.json` and `tsconfig.tests.json` (the CI
  killer): both clean
- web `tsc -b --noEmit` clean
- contracts typecheck clean
- i18n-check passes
- Live wire format: `/api/connectors/discovery` ships
  `curatedToolNames: ['github.github_search_repositories', 'github.github_get_issue']`
  for GitHub (length 2)

* fix: make ConnectorDetail.{allowed,curated}ToolNames optional in shape

After merging main, several existing test fixtures (EntryView,
SettingsDialog.orbit, ConnectorsBrowser) declared `ConnectorDetail`
inline without the new `allowedToolNames` / `curatedToolNames` keys
the PR introduced. Daemon-built payloads always populate both fields
(see `connectorDefinitionToDetail` and the Composio normalization
path), so making the wire shape `?`-optional is safe for runtime
consumers and avoids touching every fixture. Updates the daemon-side
mirror type to match and adds non-null assertions in the daemon tests
that read these fields directly.

---------

Co-authored-by: lefarcen <935902669@qq.com>
2026-05-08 23:42:52 +08:00
..
contracts fix(connectors): show stable curated tool count in connector card badge (#748) (#767) 2026-05-08 23:42:52 +08:00
platform add support for VP_HOME environment variable in agent resolution (#859) 2026-05-08 15:14:37 +08:00
sidecar release: Open Design 0.5.0 (#820) 2026-05-08 00:41:01 +08:00
sidecar-proto feat(desktop): export artifacts directly to PDF (#532) 2026-05-08 23:42:12 +08:00
AGENTS.md fix(daemon, packaged): unbreak GUI-launched agent detection on minimal PATHs (#442) (#614) 2026-05-06 20:35:19 +08:00