Skip to content

Implement Fractal Documentation Standard across codebase - #2

Merged
cixzhang merged 1 commit into
mainfrom
recursive-doc
Jan 10, 2026
Merged

cixzhang merged 1 commit into
mainfrom
recursive-doc

Conversation

@liyalabubu

Copy link
Copy Markdown
Contributor

Summary

Implements a Fractal Documentation Standard — a self-referential documentation pattern that creates consistent, navigable documentation at every level of the codebase. This supports both AI-assisted development and human onboarding.

Motivation

As XDS grows, we need documentation that:

  • Helps AI agents understand code context quickly
  • Reduces onboarding friction for new contributors
  • Makes documentation maintenance part of the development workflow
  • Provides consistent structure across all directories

What's Changed

Level 1: Project Root

  • Added SYNC CONTRACT directive to root README.md
  • Added Project Structure table documenting top-level directories

Level 2: Directory Documentation (12 READMEs)

Every directory now contains a README.md with:

  • One-line architecture summary
  • File/directory manifest table (Name, Role, Purpose)
  • <!-- SYNC: ... --> update reminder
apps/README.md
apps/docs/README.md
apps/sandbox/README.md
apps/storybook/README.md
e2e/README.md
internal/README.md
internal/test-utils/README.md
internal/test-utils/src/README.md
packages/README.md
packages/core/README.md
packages/core/src/README.md
packages/core/src/Button/README.md

Level 3: File Headers (11 source files)

All source and config files now include structured JSDoc headers:

/**
 * @file {filename}
 * @input {dependencies}
 * @output {exports}
 * @position {role in system}
 *
 * SYNC: When modified, update this header and directory README.
 */

Files updated:

  • vitest.config.ts
  • packages/core/tsup.config.ts
  • packages/core/src/index.ts
  • packages/core/src/Button/*.{ts,tsx}
  • apps/storybook/vite.config.ts
  • e2e/playwright.config.ts
  • internal/test-utils/src/*.ts

AI Context

  • Updated CLAUDE.md with documentation standard guidelines

The Pattern

Project README (SYNC CONTRACT)
├── lists directories with purposes
│
└── Directory README (SYNC directive)
    ├── lists files with purposes
    │
    └── File Header (SYNC reminder)
        └── describes @input/@output/@position

Update Protocol

When modifying code, contributors should:

  1. Update the file's header comment
  2. Update the directory's README.md
  3. Update parent documentation if architecture changes

Testing

  • All existing tests pass
  • Documentation renders correctly in GitHub/GitLab
  • No linting errors introduced

Adoption Notes

For new code:

  • New files: Add the header template before writing code
  • New directories: Create README.md with file manifest
  • Code review: Include documentation updates as part of review

Related: This aligns with XDS's AI-First philosophy documented in the root README.

…oject. Introduced Fractal Documentation structure in CLAUDE.md, added sync reminders in various config and source files, and expanded project structure details in README.md.
@liyalabubu
liyalabubu requested a review from cixzhang January 10, 2026 01:36
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jan 10, 2026
@cixzhang
cixzhang merged commit b4b5242 into main Jan 10, 2026
1 check passed
@liyalabubu
liyalabubu deleted the recursive-doc branch January 10, 2026 19:03
saivazian added a commit that referenced this pull request Apr 17, 2026
cixzhang added a commit that referenced this pull request Apr 26, 2026
Implement Fractal Documentation Standard across codebase
laulpogan added a commit to laulpogan/astryx that referenced this pull request Jul 3, 2026
…-through tracker

4 lens analysts (39 trends) -> synthesizer -> 5-persona gate (2 re-run after schema-cap deaths) -> all 17 fixes applied (mistral-ai zero-JS miscite corrected, evidence tags added, differentiators/table-stakes split, peer-set denominator recounted).

Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019e2CsWWS77gkfk2fyZE3km
humbertovirtudes added a commit to humbertovirtudes/astryx that referenced this pull request Jul 12, 2026
Address review feedback (cixzhang, ernestt) and self-review findings:

- Rename result field getRowKey -> idKey for parallelism with the Table prop
  (cixzhang): <Table idKey={grouped.idKey} />. Config input stays `getRowKey`.
- Fix O(n^2) row keying (self-review): the positional fallback used
  flattened.indexOf(item) per row. Prebuild an item->index Map once per
  flattened array so key lookup is O(1) — O(n^2) -> O(n) for the whole table.
- Chevron alignment (ernestt meta#1): the chevron is a standalone, chrome-less
  button flush with the table's leading edge (no heavy button background),
  still keyboard-operable; the whole header row remains a click convenience.
- Divider (ernestt meta#2): add a bottom border beneath each group header row.
- Typography (ernestt meta#3): the group label uses emphasized body (semibold at
  body size), not a larger text size; count is regular weight.
- Tests (10, all green): add renderGroupHeader coverage, empty-data,
  collapse-persistence-across-data-change (count updates, stays collapsed),
  toggle-and-back, aria-expanded on the header row, and a named keyboard-
  operable toggle button.

Tags: ai-generated

This diff was generated with AI assistance (Navi). The implementation and
tests were produced by an AI agent; the human author reviewed and approved
the changes.
humbertovirtudes added a commit that referenced this pull request Jul 14, 2026
* feat(core): add useTableGroupedRows plugin

Groups a flat data array into collapsible section rows. Each distinct
groupBy value becomes a full-width section-header row with a chevron
toggle, group label, and member count; collapsing hides that group's rows
while keeping the header visible.

- Mirrors useTableRowExpansionState: consumer owns the collapsedGroups set;
  the hook returns {data, plugin, getRowKey} — pass to Table data/plugins/idKey.
- Supports renderGroupHeader (custom header content) and groupOrder.
- Synthetic header rows are Proxy-wrapped so user cell renderers can't throw
  on them before transformBodyRow replaces the row with a full-width cell.
- Storybook stories (default, initially-collapsed, custom order/header),
  docsite hook doc + example block, unit tests, and a Table Lab toggle.

* feat(core): idKey output, O(n) keying, UI polish for useTableGroupedRows

Address review feedback (cixzhang, ernestt) and self-review findings:

- Rename result field getRowKey -> idKey for parallelism with the Table prop
  (cixzhang): <Table idKey={grouped.idKey} />. Config input stays `getRowKey`.
- Fix O(n^2) row keying (self-review): the positional fallback used
  flattened.indexOf(item) per row. Prebuild an item->index Map once per
  flattened array so key lookup is O(1) — O(n^2) -> O(n) for the whole table.
- Chevron alignment (ernestt #1): the chevron is a standalone, chrome-less
  button flush with the table's leading edge (no heavy button background),
  still keyboard-operable; the whole header row remains a click convenience.
- Divider (ernestt #2): add a bottom border beneath each group header row.
- Typography (ernestt #3): the group label uses emphasized body (semibold at
  body size), not a larger text size; count is regular weight.
- Tests (10, all green): add renderGroupHeader coverage, empty-data,
  collapse-persistence-across-data-change (count updates, stays collapsed),
  toggle-and-back, aria-expanded on the header row, and a named keyboard-
  operable toggle button.

Tags: ai-generated

This diff was generated with AI assistance (Navi). The implementation and
tests were produced by an AI agent; the human author reviewed and approved
the changes.
josephfarina added a commit that referenced this pull request Aug 4, 2026
The rule now forbids humanLog/humanWarn inside clients/cli/commands (Ban #2),
but its test still asserted humanLog was valid in a command file. Move the
valid humanLog example outside commands (the formatter sink) and add invalid
cases for humanLog/humanWarn in command files.

Co-authored-by: Cursor <[email protected]>
josephfarina added a commit that referenced this pull request Aug 4, 2026
* feat(cli): render human output through a shared formatter kit

JSON stays the source of truth; the plain-text output is now a consistent,
greppable projection of it. Adds clients/cli/formatters with an opaque Block
type and a small renderer set — emit (the single stdout sink), title, section,
text, list, record/records (JSON object -> aligned key: value), table, code,
markdown. Output is deterministic plain ASCII (no color, no TTY, no width
detection); errors/warnings stay on stderr via cliError.

Migrates every command's human branch onto emit + renderers (search, build,
component, docs, hook, template, discover, doctor, swizzle, layout, theme,
validate-integration, blog). Enforces the funnel by extending
@astryx/no-raw-console-cli to ban humanLog/humanWarn in command files (emit is
now the only path); humanLog stays internal to the logger and formatters.

JSON envelopes are unchanged. CLI test suite (895 tests) passes.

Co-authored-by: Cursor <[email protected]>

* feat(cli): lead build output with a kit legend (what it is + section order)

Replace the status-like "Building \"<q>\"" header with a titled "Build kit for
\"<q>\"" plus a short legend: what the output is, how to use it (run START, then
pull from the sections; each item has a `command:`), and the exact order of the
sections that follow (computed from the ones actually present) so it reads
clearly and parses predictably.

Co-authored-by: Cursor <[email protected]>

* feat(cli): clarify build's recommended start (reasoning + fallback)

Rename the build kit's "START" section to "RECOMMENDED START" and explain why:
the closest page template is called out as the recommendation ("this template
appears closest ... we recommend starting here"), with an explicit fallback
("otherwise browse PAGE TEMPLATES, then BLOCKS and DOMAIN COMPONENTS"). Keeps the
top legend in sync.

Co-authored-by: Cursor <[email protected]>

* fix(cli): use a <path> placeholder in build's recommended start

The recommended scaffold command hardcoded `./src/App.tsx`, which wrongly assumes
the consumer's project layout. Use a `<path>` placeholder instead and explain in
the note that it's the file (or folder) to write the template to. The
non-direct-match case now points at the printed `--skeleton` layout as the
reference rather than implying a scaffold path.

Co-authored-by: Cursor <[email protected]>

* feat(cli): normalize non-ASCII typography to ASCII in rendered output

Human output is meant to be plain ASCII, but data (e.g. template display names
like "Avatar — Group") and prose carried em/en dashes, curly quotes, and
ellipses. The prose/data renderers (title, section, text, list, record, table)
now normalize these to ASCII (— -> -, curly quotes -> straight, … -> ...); the
verbatim renderers (code, markdown) and --json are untouched. Table cells are
normalized before width calc so alignment stays correct.

Co-authored-by: Cursor <[email protected]>

* fix(cli): keep --help on one line per option/command

Commander wraps each help description to a column width (80 when captured
non-TTY), splitting long descriptions like --json across several indented lines.
Override Help.wrap to a no-op via configureHelp so every option/command renders
on a single line — deterministic and width-independent, matching the rest of the
CLI. Set before subcommands register so they inherit it (copyInheritedSettings).

Co-authored-by: Cursor <[email protected]>

* fix(cli): render `component --list` as one uniform table

The names view interleaved headerless standalone components with "(group)"
family sections and ragged blank lines, which read as choppy/weird. Render a
single sorted table of Component + Import instead (the import column already
conveys families); package-qualify external/colliding names. Also drop the
"(group)" suffix from the --detail compact headers.

Co-authored-by: Cursor <[email protected]>

* fix(cli): render manifest human view as a greppable table

The manifest summary used a nested 2/4-space indent (command on one line,
description indented under it) plus a raw em-dash, which was hard to grep and
inconsistent. Render it through the formatter as a single Command | JSON |
Description table instead (one row per command, ASCII-normalized).

Co-authored-by: Cursor <[email protected]>

* docs(cli): document the text output format contract in --help

Add an "Output format" section to `astryx --help` describing the plain-text
contract so agents can parse/grep it reliably: records are blocks of aligned
"key: value" lines separated by a single blank line (RFC-822 / recfile style),
sections are a header line + optional subtitle, and --json is the stable
structured surface. Formalizes the convention rather than adding per-item
divider lines (a blank line is the standard record separator).

Co-authored-by: Cursor <[email protected]>

* refactor(cli): reduce output vocabulary to a documented canonical set

Consolidate the formatter kit to one small, formalized set and document it in
--help so every current and future command conforms and agents can rely on it:

- Data is always records (key: value blocks, blank-line separated) — dropped
  `table`; `component --list` and `manifest` are now records too.
- Merged `title` into `section` (a heading with no subtitle) and `markdown` into
  `code` (one verbatim block: source, skeleton, or doc).
- Final vocabulary: section, record/records, list, text, code, emit.
- `astryx --help` now documents the block types (Record/Section/List/Text/Code),
  the blank-line record separator, how to grep a field, and that --json is the
  structured surface.

Net -75 lines. All CLI tests pass; tsc strict + lint clean.

Co-authored-by: Cursor <[email protected]>

* docs(cli): make the --help output-format spec self-demonstrating

Render the "Output format" help through the formatter itself — a section heading,
one record per block type (block/shape), and a text footer — so the spec is
written in the very format it documents (records separated by blank lines).

Co-authored-by: Cursor <[email protected]>

* chore: add changeset for the CLI output formatter work

@astryxdesign/cli patch — human output now renders through the documented
formatter kit; --json unchanged.

Co-authored-by: Cursor <[email protected]>

* fix(cli): emit blog post body verbatim

The blog detail body was rendered via text(), which ASCII-normalizes content
(em/en dashes, curly quotes, ellipses) — silently altering the article. Use
code() so the post body is emitted byte-for-byte, and render the feed URL as a
record. Caught by Bugbot.

Co-authored-by: Cursor <[email protected]>

* test(cli): update search --verbose assertion for records output

Post-merge, main's new `--verbose` regression test asserted the old combined
`match:` line. The formatter renders ranking detail as separate `score:` /
`reason:` record fields (mirroring --json), so assert those instead.

Co-authored-by: Cursor <[email protected]>

* fix(cli): align build/search render with main's --verbose flag rename

Co-authored-by: Cursor <[email protected]>

* fix(cli): discover smoke-test targets from --json, not human text

The formatter refactor reprojects `component --list` and `docs` as records,
so scraping their human output (indented names, `(group)` headers, aligned
topic columns) discovered 0 components and aborted. Read the `--json`
envelope (the source of truth) instead: component names + `--category`
keys from `component --list --json`, topics from `docs --json`.

Co-authored-by: Cursor <[email protected]>

* test(cli): update no-raw-console-cli for the humanLog-in-commands ban

The rule now forbids humanLog/humanWarn inside clients/cli/commands (Ban #2),
but its test still asserted humanLog was valid in a command file. Move the
valid humanLog example outside commands (the formatter sink) and add invalid
cases for humanLog/humanWarn in command files.

Co-authored-by: Cursor <[email protected]>

---------

Co-authored-by: Cursor <[email protected]>
imdreamrunner added a commit that referenced this pull request Aug 18, 2026
… iOS (#5178)

Below the tallest detent, a pull up inside the sheet's content did nothing on a
real device while the grab handle worked fine.

iOS Safari raises PointerEvents for a finger under the SAME numeric id it puts
in `Touch.identifier`. The touch path builds its pointer-shaped event out of
that identifier, so the drag it starts is keyed to a live pointer: `beginDrag`
captures it, WebKit takes the capture straight back for its own gesture
handling, and the `lostpointercapture` that follows a millisecond later cancels
the drag one event after it began. Measured on iOS 26.5, one gesture:

  touchmove #1 -> promote, beginDrag
    gotpointercapture   pointerId=-1239851261   (= the Touch.identifier)
    lostpointercapture  pointerId=-1239851261   willCancel=true
    cancelDrag
  touchmove #2..#50     drag gone; the sheet ignores the rest of the pull

Chromium keeps the two id spaces apart, so emulated touch never reproduces it;
the unit tests stub `setPointerCapture`, so jsdom never fires the cancelling
event. The handle keeps working because it runs on real pointer events, which
legitimately hold the capture. The mid-gesture content-end handoff (#5172)
usually survives only by timing: it promotes after WebKit has already given up
that pointer at scroll commit.

Touch-driven drags are now marked as such. They take no pointer capture, and
`lostpointercapture`, `pointercancel` and `pointermove` for the same finger no
longer cancel, end, or double-drive them.

Test Plan:
- Two new cases in useSheetGestures.test.ts dispatch onLostPointerCapture and
  onPointerCancel with a pointerId equal to the touch identifier. Both fail on
  main ("expected false to be true") and pass here.
- packages/core/src/BottomSheet suite: 163/163.
- On an iPhone 17 Simulator (iOS 26.5), one continuous touch per case, sheet
  at the 0.5 detent; numbers are the scrolling body's height, 309 = mid detent,
  395 = fully open:

  | case                                     | before      | after     |
  |------------------------------------------|-------------|-----------|
  | fresh touch at the content end, pull up  | 309 (inert) | 309 -> 395|
  | scroll to the end mid-gesture, keep pull | 309 -> 395  | unchanged |
  | top-edge pull-down in the body           | 395 -> 309  | unchanged |
  | ordinary mid-content scroll              | scroll only | unchanged |
  | grab-handle drag                         | works       | works     |

- tsc --noEmit clean; lint:strict 0 errors.
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.

2 participants