Skip to content

Resolve alias and metadata-moved routes without reading every command header - #15041

Merged
dhh merged 4 commits into
quattrofrom
router-alias-fast-path
Oct 12, 2026
Merged

dhh merged 4 commits into
quattrofrom
router-alias-fast-path

Conversation

@dhh

@dhh dhh commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

omarchy screenshot, omarchy reboot, omarchy shutdown, omarchy logout, omarchy background, omarchy share and other alias or metadata-moved routes have no matching filename. The router therefore parsed the metadata header of every command (~530 files) before dispatching, about 195ms per invocation. Filename routes like omarchy theme current already took ~5ms.

The router now first loads only the commands that could own a route under the first word: files named omarchy-<word>-*, and files whose header names <word> as their group or in an alias. It registers them in the same order a full load would. If that resolves a route that runs its command, it dispatches straight away. Help output (which lists related commands from the whole table), a bare route that needs arguments, and anything unresolved reset the registry and take the existing full-load path unchanged.

Verified:

  • Speed: omarchy screenshot dispatch went from 196ms to 12ms.
  • Help output: every one of the 548 registered routes gives byte-identical --help output under the old and new router.
  • Dispatch: in a copy of bin/ where every command is a stub that keeps its metadata header and prints its own name, 1,644 dispatches (each route with no arguments, one and two) pick the same command with the same arguments under both routers. Unknown words, group names, bare omarchy and omarchy commands match too.
  • Tests: ./test/cli passes, with new cases for an alias route, the longest alias winning, a metadata-moved route and help on an alias route.

docs/cli-router.md describes the new path.

🤖 Generated with Claude Code

… header

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the latest change fixes the root-only test failure without changing command behavior.

Summary

The PR speeds up alias and metadata-moved routes by loading likely commands first. Help and unresolved routes still load the full command table.

  • Alias and moved routes load only likely command headers.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[No filename route matches] --> B{Help requested?}
  B -->|No| C[Load likely commands]
  C --> D{Route can run?}
  D -->|Yes| E[Run command]
  D -->|No| F[Reset and load all commands]
  B -->|Yes| F
  F --> G[Resolve route and show help or run]
Loading

Reviews (3) · Last reviewed commit: "Skip the unreadable-header router check ..." · Reviewed by Greptile

Comment thread bin/omarchy Resolved
Comment thread test/cli Resolved
dhh and others added 2 commits October 11, 2026 16:22
…ter's fast path

Addresses Codex review: tab-separated aliases were missed, and a C-locale sort could pick a different winner for colliding routes than the locale-sorted full load.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Addresses Greptile review: the earlier tests passed through the full load too, so losing the fast path would have gone unnoticed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread test/cli Resolved
Addresses Greptile review: root reads through chmod 111, so the check failed for a correct router.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dhh
dhh merged commit 17704ac into quattro Oct 12, 2026
1 check passed
@dhh
dhh deleted the router-alias-fast-path branch October 12, 2026 13:51
omarchybot added a commit to WhiskeyTuesday/omarchy that referenced this pull request Oct 12, 2026
quattro's router now resolves alias and metadata-moved routes by loading only the commands that can own a route under its first word (omacom#15041). Those candidates came from the primary directory alone, so a sibling package's alias could lose to a shorter primary route on the fast path while the full load would have picked it. The candidates now include secondary binaries the primary directory does not shadow, in the full load's order, and reset_commands clears COMMAND_ORIGIN with the rest of the table.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@emirb emirb added this to the 4.5 milestone Oct 17, 2026
Sebo1411 added a commit to Sebo1411/omarchy that referenced this pull request Nov 1, 2026
omacom#15041 introduced candidate loading to avoid parsing every command header
on alias dispatches, but grep scanning ~530 files in bin/ on each invocation
still costs ~60-80ms.

Write candidate prefixes to an index file under ~/.cache/omarchy/ keyed by
a hash of OMARCHY_BIN_DIR. On subsequent dispatches, load matching
candidates directly from the index in ~1-2ms. Validate index freshness
against file mtimes in OMARCHY_BIN_DIR using a fast find check to invalidate
the cache on in-place edits. Handle pipe-separated, tabbed, indented, and
CRLF alias metadata.
Sebo1411 added a commit to Sebo1411/omarchy that referenced this pull request Nov 1, 2026
Follow-up to omacom#15041. Candidate loading avoids parsing every command header
on alias dispatches, but grep scanning ~530 files in bin/ on each invocation
still costs ~60-80ms.

Write candidate prefixes to an index file under ~/.cache/omarchy/ keyed by
a hash of OMARCHY_BIN_DIR. On subsequent dispatches, load matching
candidates directly from the index in ~1-2ms. Validate index freshness
against file mtimes in OMARCHY_BIN_DIR using a fast find check to invalidate
the cache on in-place edits. Handle pipe-separated, tabbed, indented, and
CRLF alias metadata.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants