feat: add experimental tree command with agent index - #3005
Draft
kanoru3101 wants to merge 91 commits into
Draft
Conversation
Dynamic imports inside the test body made vitest transform the whole untransformed dependency subtree within the test, exceeding the 5000ms per-test budget when istanbul coverage is enabled. Static top-level imports move that cost to the file-load phase, which has no timeout.
Add the `treeview` language to the example code fences in tree.md (matching eject.md / translate.md house style) to satisfy markdownlint MD040. Stop tracking the internal agentic planning/spec docs under docs/superpowers/: they were accidentally committed into the published documentation and caused all vale and linkcheck failures plus most markdownlint errors. Nothing references them; they remain available locally but are no longer published.
The absolute-ref to node-id rule, the codepoint sort comparator, and the operation-method set each had duplicate copies across build-graph.ts and build-structure.ts. Move them to node-id.ts as the single source so the two graph builders cannot drift. Also fix build-graph's edge-refs sort to use the codepoint comparator (was the default .sort()), matching the determinism the module documents, and drop a redundant narrating comment in build-structure. No behavior change: 58 tree unit tests and 11 e2e snapshots pass unchanged.
…iants, duplicate e2e snapshot)
🦋 Changeset detectedLatest commit: ad2690a The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
Performance Benchmark (Lower is Faster)
|
kanoru3101
force-pushed
the
feat/tree-v2
branch
from
August 3, 2026 09:33
9f86112 to
74e4b8e
Compare
Contributor
kanoru3101
force-pushed
the
feat/tree-v2
branch
from
August 3, 2026 18:06
f4adbd1 to
f5257d1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What/Why/How?
Adds the experimental
treecommand — one command that shows an API description's structure to humans and serves it as a navigable index to LLM agents.Humans get quick orientation and impact analysis in multi-file descriptions ("what breaks if I change this schema?"); agents get a way to work with descriptions too large for a context window, borrowing the retrieval loop from PageIndex: build a small hierarchical index, let the model reason over it, and fetch only what it needs — fully deterministic here, since an API description already carries its structure and summaries (no AI calls, no keys).
Everything is powered by one new
api-graphmodule in@redocly/openapi-core: a single walk of the ORIGINAL resolved files (lint pattern, no bundling) produces a dependency graph plus index metadata, and the CLI renders views over it:Every node carries a stable semantic id (
GET /orders,schemas/Order), a JSON pointer, the definingfile, andstart_line/end_line, so an agent can follow up with plain file reads.Components the root document declares keep their canonical
section/Nameids even when they live in their own file, so--usesinput forms work the same for single-file and multi-file APIs; a component no root entry declares (as inredocly splitoutput) is addressed by its file path.--with-depsreturns a self-contained slice (operation plus everything it transitively references, in dependency order, 64 KB cap with an explicittruncatedmarker).Unresolvable
$refs render as ❌ nodes with stderr warnings; stdout stays clean JSON in machine formats.The dependency graph (stylish/mermaid/dot/
--files/--uses) and the hierarchical index (--format=json/--node) are two projections of the sameanalyzeApipass; raw line slices are the retrieval ground truth, with$refs kept intact and a resolvedrefs[]list as hyperlinks.v1 scope: full OpenAPI 2.0–3.2; AsyncAPI/Arazzo render as a flat referenced-components list.
Architecture note for review: the engine lives in core on purpose — the CLI is one of several planned surfaces; an MCP server and portal-side index generation would consume the same module directly.
Measured end to end on GitHub's own 9.8 MB REST API description (
github/rest-api-description, used unmodified), with a BPE tokenizer over real command output — task: "create a repository for the authenticated user":--level 2→--node repos→--with-depsThis is the case the hierarchy exists for: at 1.9M tokens the file is ten 200k windows, and even the complete index does not fit one — so bounded drill-down is the only way an agent can touch it, and the chain still lands at a quarter of the window with room to work.
Per-step numbers, real JSON output, and the split-layout run (2,842 files) are in the benchmark guide.
Docs
Reference
treedraft (feat(cli): addtreecommand #2869)Testing
api-graphunit tests — graph building, index assembly, retrieval slices, deps closure, outside-cwd path normalization, callback exclusion, split-alias canonical ids.--uses+--format=json, error paths, and the webhooks warning; snapshots pin real output.Screenshots (optional)
Check yourself
Security