Skip to content

Commit ab483c1

Browse files
masreplayclaude
andcommitted
docs: rewrite CLAUDE.md for the generic navigation_devtools architecture
Reflects the merged structure: navigation_devtools core + adapters (auto_route, go_router, Navigator1, RouterDelegate), v2 wire protocol, the shipped bundle living in navigation_devtools, and the pub.dev OIDC publishing setup. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 6e28e86 commit ab483c1

1 file changed

Lines changed: 84 additions & 33 deletions

File tree

‎CLAUDE.md‎

Lines changed: 84 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,70 +4,108 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
44

55
## What this is
66

7-
A standalone, publishable **Flutter DevTools panel extension** for `auto_route` (v11). Inside the DevTools tab of a running app it shows the live backstack, full router tree, per-route args + path/query params, and confirm-gated interactive navigation. (auto_route ships no DevTools extension; `developer_tools_auto_route` is only an in-app overlay — this is a proper DevTools panel.)
7+
A standalone, publishable **Flutter DevTools panel extension** for **navigation** — a generic core
8+
(`navigation_devtools`) with per-router **adapters** (auto_route, go_router, Navigator 1.0, and any
9+
custom `RouterDelegate`). Inside the DevTools tab of a running app it shows, per registered router:
10+
the live backstack, the static route tree (as a list **and** an Android-Studio-style route **graph**),
11+
per-route args + path/query params, and confirm-gated interactive navigation (including `:param` entry).
12+
Multiple routers can be registered and switched between in the panel.
13+
14+
Fills a real gap: none of these routers ship a DevTools extension; `developer_tools_auto_route` is only
15+
an in-app overlay — this is a proper DevTools panel.
816

917
## Environment
1018

1119
- **Always use FVM**: `fvm flutter` / `fvm dart` (Flutter 3.44.0). Plain `flutter`/`dart` may resolve to the wrong SDK.
1220
- **Dart pub workspace** (`resolution: workspace`) with **Melos 8** as the publish handler. Melos config lives in the root `pubspec.yaml` under the `melos:` key (pub-workspace mode) — **NOT** in `melos.yaml`, which is kept only for discoverability.
1321
- freezed **3.x** and build_runner 3.x are forced by auto_route 11's constraints.
1422

15-
## Packages (monorepo, 4 packages)
23+
## Packages (monorepo)
1624

1725
| Package | Role | Published? |
1826
|---|---|---|
19-
| `auto_route_devtools_shared` | freezed/JSON protocol models — the wire contract between runtime and UI | yes |
20-
| `auto_route_devtools` | Runtime companion attached to the consumer app; registers service extensions | yes |
21-
| `auto_route_devtools_extension` | The DevTools web UI (Flutter web) | no (`publish_to: none`) |
22-
| `example` | Runnable auto_route demo + test fixture | no |
23-
24-
The extension UI is **prebuilt** into `packages/auto_route_devtools/extension/devtools/build/` and shipped inside the published `auto_route_devtools` package. That build dir is force-included in `.gitignore` (`!packages/auto_route_devtools/extension/devtools/build/`) — do not delete it; it must exist for the published extension to load.
27+
| `navigation_devtools_shared` | freezed/JSON protocol models — the wire contract (v2) | yes |
28+
| `navigation_devtools` | Generic runtime core: `NavigationAdapter` API, multi-router registry, generic service extensions; ships the **prebuilt extension bundle**. Bundles the Navigator 1.0 + `RouterDelegate` adapters. | yes |
29+
| `navigation_devtools_test` | Adapter conformance test kit (`lib/navigation_devtools_test.dart`) | yes |
30+
| `go_router_devtools` | `GoRouterAdapter` (go_router) | yes |
31+
| `auto_route_devtools` | `AutoRouteAdapter` + `AutoRouteDevTools.init(router)` compatibility shim | yes |
32+
| `navigation_devtools_extension` | The DevTools web UI (Flutter web) | no (`publish_to: none`) |
33+
| `examples/{auto_route,go_router,navigator1,router_delegate}_example` | Runnable demos + test fixtures | no |
34+
35+
The extension UI is **prebuilt** into `packages/navigation_devtools/extension/devtools/build/` and shipped
36+
inside the published `navigation_devtools` package (the adapter packages do **not** ship a bundle). That
37+
build dir is force-included in `.gitignore` (`!packages/navigation_devtools/extension/devtools/build/`) —
38+
do not delete it; it must exist for the published extension to load.
2539

2640
## Architecture — the wire protocol
2741

28-
The runtime and the UI never share Dart objects; they communicate over the VM service using the shared freezed models (`packages/auto_route_devtools_shared/lib/src/models.dart`: `RouterConfigNode`, `StackEntry`, `NavigateRequest`/`NavigateResult`, `NavigateAction`).
29-
30-
**Runtime side** (`auto_route_devtools/lib/src/auto_route_devtools.dart`): `AutoRouteDevTools.init(router)` registers three `dart:developer` service extensions and posts one event:
31-
- `ext.autoRouteDevtools.getRouterConfig` → serialized router tree
32-
- `ext.autoRouteDevtools.getStack` → serialized backstack
33-
- `ext.autoRouteDevtools.navigate` → executes a `NavigateRequest`, returns `NavigateResult`
34-
- `postEvent('auto_route_devtools:stack_changed')` — pushed by the `AutoRouterObserver` on every nav change (this is the live-update mechanism; there is intentionally **no** polling fallback).
35-
36-
Everything is **inert in release** (`kReleaseMode` guards in `init`/`notifyStackChanged`).
37-
38-
**UI side** (`auto_route_devtools_extension/lib/src/data_source.dart`): `AutoRouteDataSource` is the abstraction. `VmServiceDataSource` calls the service extensions above via `serviceManager` and listens to `onExtensionEvent` for `stack_changed`. `FakeAutoRouteDataSource` backs widget tests with in-memory data. Views (`panel.dart`, `backstack_view.dart`, `router_tree_view.dart`, `detail_view.dart`) render off the data source.
39-
40-
When you change any model in `auto_route_devtools_shared`, you are changing the wire contract — update **both** the runtime serializers (`stack_serializer.dart`, `router_config_serializer.dart`) and the UI's decode path, and regenerate code.
42+
The runtime and the UI never share Dart objects; they communicate over the VM service using the shared
43+
freezed models (`packages/navigation_devtools_shared/lib/src/models.dart`, `protocolSchemaVersion = 2`):
44+
`RouterSummary`, `RouteNode`, `StackFrame`, `NavigateRequest`/`NavigateResult`, `NavigateAction`.
45+
46+
**Runtime side** — a `NavigationAdapter` (`navigation_devtools/lib/src/adapter.dart`) is registered with
47+
the multi-router registry via `NavigationDevTools.register(adapter)` / `.unregister(id)`
48+
(`navigation_devtools/lib/src/registry.dart`). The registry exposes four `dart:developer` service
49+
extensions and posts two events:
50+
- `ext.navigationDevtools.getRouters` → list of `RouterSummary` (id, kind, capabilities, schemaVersion)
51+
- `ext.navigationDevtools.getRouterConfig` → serialized route tree for a router
52+
- `ext.navigationDevtools.getStack` → serialized backstack for a router
53+
- `ext.navigationDevtools.navigate` → executes a `NavigateRequest`, returns `NavigateResult`
54+
- `postEvent('navigation_devtools:stack_changed')` — pushed on every nav change (live update; **no** polling fallback)
55+
- `postEvent('navigation_devtools:routers_changed')` — pushed when routers are (un)registered
56+
57+
Adapters advertise **capabilities** (e.g. `staticRouteTree`, `guardInfo`, `navigateToPath`, `pushNamed`,
58+
`pop`) so the UI is capability-aware — a Navigator 1.0 app with no route table hides the tree, etc.
59+
Everything is **inert in release** (`kReleaseMode` guards).
60+
61+
**UI side** (`navigation_devtools_extension/lib/src/`): `NavigationDataSource` is the abstraction;
62+
`VmDataSource` (`vm_data_source.dart`) calls the service extensions above via `serviceManager` and listens
63+
to `onExtensionEvent`; a fake data source backs widget tests. `panel.dart` (`NavigationPanel`) renders the
64+
router selector, backstack (`backstack_view.dart`), a Tree/Graph tab switcher
65+
(`router_tree_view.dart` + `route_graph_view.dart`/`graph_layout.dart`), the detail pane
66+
(`detail_view.dart`), and the param-entry dialog (`path_params_dialog.dart`).
67+
68+
When you change any model in `navigation_devtools_shared`, you are changing the wire contract — update the
69+
adapters' serializers **and** the UI decode path, and regenerate code. Note v2 `RouteNode` exposes only
70+
`hasRedirect` (bool), not a redirect target path.
4171

4272
## Consumer setup (what users write)
4373

4474
```dart
75+
// auto_route (shim keeps the old one-liner):
4576
final router = AppRouter();
4677
AutoRouteDevTools.init(router);
4778
runApp(MaterialApp.router(
4879
routerConfig: router.config(
4980
navigatorObservers: () => [AutoRouteDevTools.navigationObserver()],
5081
),
5182
));
83+
84+
// go_router: NavigationDevTools.register(GoRouterAdapter(router));
85+
// Navigator 1.0: final a = Navigator1Adapter(routes: appRoutes);
86+
// NavigationDevTools.register(a); // + a.observer in navigatorObservers
87+
// custom RouterDelegate: NavigationDevTools.register(RouterDelegateAdapter(delegate, parser: parser));
5288
```
5389

5490
## Commands
5591

56-
Codegen (after editing any freezed/JSON model, only `_shared` has generated code):
92+
Codegen (after editing any freezed/JSON model; only `_shared` has generated code):
5793
```bash
58-
cd packages/auto_route_devtools_shared && fvm dart run build_runner build --delete-conflicting-outputs
94+
cd packages/navigation_devtools_shared && fvm dart run build_runner build --delete-conflicting-outputs
5995
```
6096

6197
Analyze (clean is required):
6298
```bash
6399
fvm flutter analyze
64100
```
65101

66-
Tests — **the extension package must run on Chrome** (it uses `dart:js_interop`); the other two run on the Dart VM:
102+
Tests — **the extension package must run on Chrome** (it uses `dart:js_interop`); the rest run on the Dart VM:
67103
```bash
68-
cd packages/auto_route_devtools_shared && fvm flutter test
104+
cd packages/navigation_devtools_shared && fvm flutter test
105+
cd packages/navigation_devtools && fvm flutter test
69106
cd packages/auto_route_devtools && fvm flutter test
70-
cd packages/auto_route_devtools_extension && fvm flutter test --platform chrome
107+
cd packages/go_router_devtools && fvm flutter test
108+
cd packages/navigation_devtools_extension && fvm flutter test --platform chrome
71109
```
72110

73111
Single test file / single test:
@@ -76,27 +114,40 @@ fvm flutter test test/panel_test.dart --platform chrome
76114
fvm flutter test test/panel_test.dart --plain-name "renders backstack"
77115
```
78116

79-
Rebuild the shipped extension bundle (from the extension package) — needed whenever the UI changes, so the prebuilt bundle in the published package stays current:
117+
Rebuild the shipped extension bundle (from the extension package) — needed whenever the UI changes, so the
118+
prebuilt bundle in the published `navigation_devtools` package stays current (a CI job fails on drift):
80119
```bash
81-
cd packages/auto_route_devtools_extension && fvm dart run devtools_extensions build_and_copy \
82-
--source=. --dest=../auto_route_devtools/extension/devtools
120+
cd packages/navigation_devtools_extension && fvm dart run devtools_extensions build_and_copy \
121+
--source=. --dest=../navigation_devtools/extension/devtools
83122
```
84123

85-
Run the demo app to verify live DevTools behavior end-to-end:
124+
Run a demo app to verify live DevTools behavior end-to-end:
86125
```bash
87-
cd example && fvm flutter run # then open DevTools and enable the auto_route_devtools tab
126+
cd examples/auto_route_example && fvm flutter run # then open DevTools and enable the navigation_devtools tab
88127
```
89128

90-
Publish dry-run (Melos publishes in dependency order: `_shared` before `auto_route_devtools`; `publish_to: none` packages are skipped):
129+
Publish dry-run (Melos publishes in dependency order: `_shared` first, then core and adapters; `publish_to: none` packages are skipped):
91130
```bash
92131
fvm dart run melos publish --dry-run
93132
```
94133

134+
## Release / CI-CD
135+
136+
- `.github/workflows/ci.yaml` — analyze + test + publish dry-runs + extension-bundle-drift check (on push to `main` / PRs).
137+
- `.github/workflows/publish.yml` — **pub.dev automated publishing via GitHub Actions OIDC**, triggered by
138+
tags of the form `<package>-v<version>` (glob `<package>-v*`). Each publishable package must be configured
139+
once on pub.dev (Admin → Automated publishing: repo `masreplay/auto_route_devtools`, tag pattern
140+
`<package>-v{{version}}`). A brand-new package's **first** version must be published manually with
141+
`fvm dart pub publish` — pub.dev does not allow automated first-publish.
142+
95143
## Conventions
96144

97145
- `analysis_options.yaml`: `flutter_lints` + `prefer_single_quotes`. Generated files (`*.g.dart`, `*.freezed.dart`, `*.gr.dart`) are excluded from analysis — never hand-edit them.
98146
- Design/plan docs live in `docs/superpowers/`; the SDD progress ledger is `.superpowers/sdd/progress.md`.
99147

100148
## Known gaps (deferred by design)
101149

102-
Live DevTools click-through has been unverified in headless sessions — verify manually via the `example` app. Not yet implemented: redirect-route filtering in the tree, a guarded-route fixture (the guards→name mapping is untested), and a `_defaultConfirm` dialog test.
150+
Live DevTools click-through has been unverified in headless sessions — verify manually via an `examples/*` app.
151+
Not yet ported from the old auto_route-only UI: nested-route `fullPath` navigation (the v2 `RouteNode` has no
152+
`fullPath` field) and redirect **target** edges in the graph (v2 exposes only a `hasRedirect` badge). Also
153+
deferred: redirect-route filtering in the tree, a guarded-route fixture (guards→name mapping untested).

0 commit comments

Comments
 (0)