Skip to content

feat(cli): experimental exportIconIndex() and rankIconIndex() - #12128

Merged
josephfarina merged 4 commits into
mainfrom
cli/icon-index-api
Nov 16, 2026
Merged

josephfarina merged 4 commits into
mainfrom
cli/icon-index-api

Conversation

@josephfarina

@josephfarina josephfarina commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

User need

A catalog web page that lists icon-set packages must answer an icon search exactly as astryx experimental icon <words> does, so every improvement to the CLI's icon ranking reaches the page with no second copy of the ranking. Such a page must not load package code, and reading a folder's icon sets loads each integration's manifest module. Today icon() only reads installed sets, so the page has no way to call the CLI's own ranking.

Problem and solution fit

Same split as exportSearchIndex() / rankSearchIndex():

  • exportIconIndex({cwd, package?}) reads the icon sets icon() would search in cwd and returns {version, sets, withdrawn} as plain JSON. It runs where loading packages is safe.
  • rankIconIndex(query, indexes, {set?, limit?}) ranks stored indexes and returns the same icon.search envelope as icon() for a word search; it shares icon()'s query, limit and default checks, and refuses a <set>/<id> query, which icon() reads as one icon.
  • icon() search and rankIconIndex() call one shared function (rankIconSets in api/icon/search/search.mjs), which wraps rankIcons and answeringMatches unchanged. No scoring code changes.

Current specification

Experimental API (AST-017 FR27), alongside the experimental search-index pair (AST-033). No new command.

Public delta and caller burden

  • Two new experimental exports in @astryxdesign/cli/api, two new experimental types (IconIndex, IconIndexSet).
  • icon() output is unchanged.
  • An index is ranked only by the CLI version that made it (clear ERR_INVALID_ARGUMENT otherwise). Equal scores keep the order of the indexes given, as icon() keeps a project's set order; an index holds no project choice.
// where packages may load
const index = await exportIconIndex({cwd, package: '@acme/icons'});
// anywhere, later
const r = await rankIconIndex('delete', index, {limit: 20});

Design and alternatives

  • Calling icon() in the catalog was rejected: it needs the packages installed and runs their manifests.
  • Exporting the internal rankIcons was rejected: callers would rebuild set loading, the set filter, the answering cut and the envelope, and could drift.
  • The index keeps withdrawn sets (name, package, reason) so a set that names one gives the same error as icon().

Evidence

  • New icon-index.test.mjs: for every query in a generated list (ids, words, parts, prefixes, infixes, plurals, phrases, misses), with and without a project set, rankIconIndex(q, JSON round-tripped exportIconIndex()) deep-equals icon(q); same for set, limit and every error; package filter; several indexes keep the given order; no folder paths in the index; version refusal.
  • Replay, before vs after this change, over a fixture of three sets (about 2,000 icons from a public icon library's tags), 351 queries x 3 option sets, with and without a project set: icon() output is byte-identical, and rankIconIndex over the exported index is byte-identical to icon().
  • Every existing icon test passes unchanged.

Scope

Components: cli/api/icon

  • One capability is added.
  • Unrelated fixes, cleanup, and policy changes were removed or split.
  • Consumer docs, focused tests, and migration evidence ship with the feature.
  • Public text and artifacts contain no internal Meta context.

Testing

  • vitest run --project node packages/cli/api/icon packages/cli/test/lazy-dependencies.test.mjs (291 pass); pnpm check:knowledge passes
  • pnpm -F @astryxdesign/cli sync:api-types, typecheck:json-api, node .github/scripts/cli-api-types-verify.mjs pass. typecheck:strict reports only two pre-existing errors for an unbuilt theme package in page templates, unrelated.

Record line

docs/specs/AST-033/spec.md FR2a records the experimental pair: the index shape {version, sets, withdrawn}, the same-CLI-version refusal naming both versions, and equal scores keeping the order the indexes were given.

Writing rubric results

  • R1 state the system: FR2a describes what the two functions do, in the present tense. Pass.
  • R2 research is an artifact: no research in the record. Pass.
  • R3 evidence cites facts: no evidence section added. Pass.
  • R4 rejected alternatives: none in the record. Pass.
  • R5 no pull request or issue as standing content: none cited. Pass.
  • R6 open questions: none. Pass.
  • R7 no project status: none. Pass.

The icon counterpart of exportSearchIndex() and rankSearchIndex(). A
catalog that must not load package code stores each package's icon index
once, where loading is safe, and ranks the stored indexes per query.

icon() search and rankIconIndex() share one ranking function, so icon()
answers exactly as before.
@vercel

vercel Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Nov 16, 2026 8:27pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 16, 2026
@astracat-bot

astracat-bot Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 16, 2026, 8:36 PM UTC

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · caff77c

Storybook · Sandbox · built from this PR's head

Package size: @astryxdesign/cli 5.21 MB packed (+3.9 kB); no new dependencies.

API changes: cli +2 · ~0 · −0

2 API changes (advisory)
Package Where Signature Usage
+ cli ./api · Functions · function exportIconIndex function exportIconIndex @experimental: (options?: { cwd?: string | undefined; package?: string | undefined }) => Promise<IconIndex> import {exportIconIndex} from '@astryxdesign/cli/api'; exportIconIndex(…)
+ cli ./api · Functions · function rankIconIndex function rankIconIndex @experimental: (query: string, indexes: IconIndex | IconIndex[], options?: { set?: string | undefined; limit?: number | undefined }) => Promise<IconSearchResponse> import {rankIconIndex} from '@astryxdesign/cli/api'; rankIconIndex(…)

Not run on this PR: add ci:run-visual for Visual, ci:run-a11y for Accessibility, ci:run-rtl for RTL.


Generated by PR Enrichment workflow | View full report

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes are needed, and the new API needs an owner decision before it can be approved.

exportIconIndex() and rankIconIndex() are a new experimental API that no current record admits yet: spec:AST-084 FR0 and spec:AST-017 FR27 decide only how icon-set APIs are marked experimental, and spec:AST-033 FR2 covers only exportSearchIndex()/rankSearchIndex(). Approval needs an engineering owner to identify a current claim that covers the pair, or to approve one this pull request adds (the index shape, the same-CLI-version refusal, and that equal scores keep the order the indexes are given) by commenting /approve-spec <full head SHA>; the author may do so as an engineering owner.

Blocking, whatever that decision is:

  • rankIconIndex() copies icon()'s default limit and its query and limit checks (icon-index.mjs:21 and :92-113) instead of sharing them the way search() and rankSearchIndex() share checkSearchArgs, and the copies already differ: {limit: null} throws where icon() uses 10, and a missing query gives ERR_INVALID_ARGUMENT where icon() gives ERR_MISSING_ARGUMENT.
  • .changeset/icon-index-api.md credits no contributor, so check:changesets fails the required Lint job; add @josephfarina on its own line after the body.

Not blocking: the rankIconIndex() doc says an index ranks exactly as icon(query) does, but glyphs/trash answers icon.detail from icon() and an empty search from rankIconIndex(), so scope that sentence to word searches or refuse such a query.

Claims and files checked

Review mode: full; reason: no-earlier-review

  • Claim: two new experimental functions in @astryxdesign/cli/api: verified (api/index.mjs:52).
  • Claim: exportIconIndex() returns the sets icon() searches as plain JSON with no folder paths: verified (icon-index.mjs:30-72, test).
  • Claim: rankIconIndex() answers icon searches exactly as icon() does: verified for word searches by the parity test; <set>/<id> lookups differ (note above).
  • Claim: icon() ranks through the same function and its answers are unchanged: verified (search.mjs:59-97; existing icon tests pass unchanged).
  • Claim: an index ranks only under the CLI version that made it: verified (icon-index.mjs:128-134, test).
  • Claim: equal scores keep the order of the indexes given: verified (test).
  • Claim: withdrawn sets are kept so set gives icon()'s error: verified (test).
  • Claim: no scoring code changes: verified (the ranking module is untouched).
  • Claim: the named test run, the API type sync, the JSON API typecheck and the published-types check pass: verified.
  • Claim: a replay over a three-set icon fixture is byte-identical: not verified, since the fixture is not in the pull request; the in-repo parity test supports it.
  • File .changeset/icon-index-api.md: finding (contributor line).
  • File packages/cli/api/icon/search/icon-index.mjs: finding (copied default and checks).
  • File packages/cli/api/icon/rankIconIndex.doc.mjs: note (parity sentence).
  • File packages/cli/api/icon/exportIconIndex.doc.mjs: clear.
  • File packages/cli/api/icon/icon.type.mjs: clear.
  • File packages/cli/api/icon/search/search.mjs: clear.
  • File packages/cli/api/icon/search/icon-index.test.mjs: clear.
  • File packages/cli/api/icon/experimental-markers.test.mjs: clear.
  • File packages/cli/api/index.mjs: clear.
  • File packages/cli/test/lazy-dependencies.test.mjs: clear.

Automated review (maintainer link)

Comment thread .changeset/icon-index-api.md Resolved
rankIconIndex() and icon() now share one query, limit and default check.
A <set>/<id> query, which icon() reads as one icon, is refused by
rankIconIndex(). AST-033 FR2a records the experimental pair: the index
shape, the same-CLI-version rule and the equal-score order.
@github-actions github-actions Bot added needs:spec-owner-review Current knowledge records await owner approval and removed needs:spec-owner-review Current knowledge records await owner approval labels Nov 16, 2026

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes are needed for one CI fix; the API's direction is settled, since an engineering owner approved the new record clause at this head.

  • Miss: the required Lint check fails at pnpm check:cli-structure because packages/cli/api/icon/search/search.mjs:67 writes the sets type as Array<import('../../../foundation/discovery/icon-set-discovery.mjs').DiscoveredIconSet | …>, which the check reads as a discovery import, so declare DiscoveredIconSet and IconIndexSet with @typedef {import(…)} at the top of the file and write @param {Array<DiscoveredIconSet | IconIndexSet>} sets (the last review missed this because Lint stopped earlier, at the Changeset check).

The earlier blockers are fixed: rankIconIndex() shares icon()'s default and argument checks, the Changeset credits its author, and a <set>/<id> query is refused with a pointer to icon().

Not blocking: the new FR2a clause does not mention exportIconIndex()'s package option, so one clause there would make the record cover per-package indexes.

Claims and files checked

Review mode: full; reason: spec-record

  • Claim: two new experimental functions and two experimental types in the CLI's programmatic API: verified (packages/cli/api/index.mjs:52, icon.type.mjs:393-416).
  • Claim: exportIconIndex() returns the sets icon() searches as plain JSON {version, sets, withdrawn} with no folder paths, and package keeps one package's sets: verified (icon-index.mjs:57-76, tests).
  • Claim: rankIconIndex() answers a word search as icon() does, shares its query, limit and default checks, and refuses a <set>/<id> query: verified (icon-index.mjs:96-134, _options.mjs:79-131, parity test).
  • Claim: icon() and rankIconIndex() share one ranking function and no scoring code changes: verified (search.mjs:59-97; the ranking module is untouched).
  • Claim: icon() output is unchanged and every existing icon test passes unchanged: verified (local run).
  • Claim: an index ranks only under the CLI version that made it, with an error naming both versions: verified (icon-index.mjs:124-129, test).
  • Claim: equal scores keep the order the indexes are given: verified (test).
  • Claim: withdrawn sets are kept so a set that names one gives icon()'s error: verified (test).
  • Claim: no new command: verified (no command doc changes).
  • Claim: the record clause states the index shape, the version refusal and index-order ties: verified (docs/specs/AST-033/spec.md:104-112).
  • Claim: the named test run (291 tests) and the knowledge check pass: verified (local run).
  • Claim: the API type sync, the JSON API typecheck and the published-types check pass, and the strict typecheck reports only two unbuilt-theme errors in page templates: verified (local run).
  • Claim: a replay over a three-set icon fixture is byte-identical: not verified, since the fixture is not in the pull request; the in-repo parity test supports it.
  • Claim: public text carries no internal context: verified.
  • Claim: the writing rubric results for the record clause: verified (present tense; no research, references or status).
  • Changeset: an experimental patch adding the two functions as the icon counterpart of the search index pair, with icon()'s answers unchanged and same-version ranking, crediting the author: verified (check:changesets passes).
  • File packages/cli/api/icon/search/search.mjs: finding (the type at line 67 fails the required Lint check).
  • File docs/specs/AST-033/spec.md: note (the clause does not name the package option).
  • File .changeset/icon-index-api.md: clear.
  • File packages/cli/api/icon/_options.mjs: clear.
  • File packages/cli/api/icon/icon.mjs: clear.
  • File packages/cli/api/icon/icon.type.mjs: clear.
  • File packages/cli/api/icon/search/icon-index.mjs: clear.
  • File packages/cli/api/icon/exportIconIndex.doc.mjs: clear.
  • File packages/cli/api/icon/rankIconIndex.doc.mjs: clear.
  • File packages/cli/api/icon/search/icon-index.test.mjs: clear.
  • File packages/cli/api/icon/experimental-markers.test.mjs: clear.
  • File packages/cli/api/index.mjs: clear.
  • File packages/cli/test/lazy-dependencies.test.mjs: clear.

Automated review (maintainer link)

Comment thread packages/cli/api/icon/search/search.mjs Resolved
- **FR2a — Icon search has a stored index too.** `exportIconIndex()` and
`rankIconIndex()` in `@astryxdesign/cli/api` are experimental, the icon
counterpart of the search index pair. `exportIconIndex()` returns the icon
sets `icon()` searches in a folder as plain JSON, `{version, sets,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: this clause does not mention the package option of exportIconIndex(), which is how a catalog makes one index per package for the multi-index ranking below. One clause here would make the record cover it.

search.mjs no longer imports a discovery type (INV21): the shared ranking
takes the type rankIcons reads.
@josephfarina

Copy link
Copy Markdown
Contributor Author

/approve-spec caff77c

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved pending CI: the CI workflow's test and build jobs have not finished on this head yet. An engineering owner approved the new record clause for the experimental exportIconIndex() and rankIconIndex() pair at this head, and the last review's blocker is fixed: search.mjs no longer trips the CLI structure check, and Lint passes.

Not blocking: the new record clause still does not mention exportIconIndex()'s package option; one sentence there would make the record cover per-package indexes.

Claims and files checked

Review mode: incremental; reason: none

  • Claim: two new experimental functions and two experimental types in the CLI's programmatic API: verified (packages/cli/api/index.mjs:52, icon.type.mjs:393-415).
  • Claim: exportIconIndex() returns the sets icon() searches as plain JSON {version, sets, withdrawn} with no folder paths, and package keeps one package's sets: verified (icon-index.mjs:57-76, tests).
  • Claim: rankIconIndex() answers a word search as icon() does, shares its query, limit and default checks, and refuses a <set>/<id> query: verified (icon-index.mjs:96-139, _options.mjs:79-131, parity test).
  • Claim: icon() and rankIconIndex() share one ranking function that wraps the existing ranking unchanged, with no scoring change: verified (search.mjs:59-92; the ranking module is untouched).
  • Claim: icon() output is unchanged and every existing icon test passes unchanged: verified (local run, 342 tests).
  • Claim: an index ranks only under the CLI version that made it, with an error naming both versions: verified (icon-index.mjs:124-130, test).
  • Claim: equal scores keep the order the indexes are given: verified (test; ties sort by set position after score).
  • Claim: withdrawn sets are kept so a set that names one gives icon()'s error: verified (test).
  • Claim: no new command: verified (no command doc changes).
  • Claim: the record clause states the index shape, the version refusal and index-order ties: verified (docs/specs/AST-033/spec.md:104-112).
  • Claim: the named test run and the knowledge check pass: verified (local run).
  • Claim: the API type sync, the JSON API typecheck and the published-types check pass, and the strict typecheck reports only two unbuilt-theme errors in page templates: verified (local run).
  • Claim: a replay over a three-set icon fixture is byte-identical: not verified, since the fixture is not in the pull request; the in-repo parity test covers the same property.
  • Claim: public text carries no internal context: verified.
  • Claim: the writing rubric results for the record clause: verified (present tense; no research, references or status).
  • Changeset: an experimental patch adding the two functions as the icon counterpart of the search index pair, with icon()'s answers unchanged and same-version ranking, crediting the author: verified (check:changesets passes).
  • File docs/specs/AST-033/spec.md: note (the clause does not name the package option).
  • File packages/cli/api/icon/search/search.mjs: clear (the structure check passes).
  • File packages/cli/api/icon/search/icon-index.mjs: clear.
  • File .changeset/icon-index-api.md: clear.
  • File packages/cli/api/icon/_options.mjs: clear.
  • File packages/cli/api/icon/icon.mjs: clear.
  • File packages/cli/api/icon/icon.type.mjs: clear.
  • File packages/cli/api/icon/exportIconIndex.doc.mjs: clear.
  • File packages/cli/api/icon/rankIconIndex.doc.mjs: clear.
  • File packages/cli/api/icon/search/icon-index.test.mjs: clear.
  • File packages/cli/api/icon/experimental-markers.test.mjs: clear.
  • File packages/cli/api/index.mjs: clear.
  • File packages/cli/test/lazy-dependencies.test.mjs: clear.

Automated review (maintainer link)

@josephfarina
josephfarina merged commit 6cfda3f into main Nov 16, 2026
79 checks passed
@github-actions
github-actions Bot deleted the cli/icon-index-api branch November 17, 2026 06:03

This branch was successfully deployed

1 active deployment
Preview — caff77c0 Deployed Nov 16, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant