@bleedingdev/modern-js-create 3.2.0-ultramodern.6 → 3.2.0-ultramodern.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (23) hide show
  1. package/dist/index.js +23 -0
  2. package/package.json +1 -1
  3. package/template-workspace/.agents/rstackjs-agent-skills-LICENSE +21 -0
  4. package/template-workspace/.agents/skills/rsbuild-best-practices/SKILL.md +57 -0
  5. package/template-workspace/.agents/skills/rsdoctor-analysis/SKILL.md +96 -0
  6. package/template-workspace/.agents/skills/rsdoctor-analysis/references/command-map.md +113 -0
  7. package/template-workspace/.agents/skills/rsdoctor-analysis/references/common-analysis-patterns.md +190 -0
  8. package/template-workspace/.agents/skills/rsdoctor-analysis/references/install-rsdoctor-common.md +88 -0
  9. package/template-workspace/.agents/skills/rsdoctor-analysis/references/install-rsdoctor-rspack.md +138 -0
  10. package/template-workspace/.agents/skills/rsdoctor-analysis/references/install-rsdoctor-webpack.md +71 -0
  11. package/template-workspace/.agents/skills/rsdoctor-analysis/references/install-rsdoctor.md +39 -0
  12. package/template-workspace/.agents/skills/rsdoctor-analysis/references/rsdoctor-data-types.md +103 -0
  13. package/template-workspace/.agents/skills/rslib-best-practices/SKILL.md +58 -0
  14. package/template-workspace/.agents/skills/rslib-modern-package/SKILL.md +173 -0
  15. package/template-workspace/.agents/skills/rspack-best-practices/SKILL.md +70 -0
  16. package/template-workspace/.agents/skills/rspack-tracing/SKILL.md +75 -0
  17. package/template-workspace/.agents/skills/rspack-tracing/references/bottlenecks.md +47 -0
  18. package/template-workspace/.agents/skills/rspack-tracing/references/tracing-guide.md +38 -0
  19. package/template-workspace/.agents/skills/rspack-tracing/scripts/analyze_trace.js +184 -0
  20. package/template-workspace/.agents/skills/rstest-best-practices/SKILL.md +133 -0
  21. package/template-workspace/.agents/skills-lock.json +56 -0
  22. package/template-workspace/AGENTS.md +28 -0
  23. package/template-workspace/scripts/validate-ultramodern-workspace.mjs.handlebars +67 -0
package/dist/index.js CHANGED
@@ -560,6 +560,16 @@ const TYPESCRIPT_VERSION = '6.0.3';
560
560
  const REACT_VERSION = '^19.2.6';
561
561
  const REACT_DOM_VERSION = '^19.2.6';
562
562
  const WORKSPACE_PACKAGE_VERSION = 'workspace:*';
563
+ const RSTACK_AGENT_SKILLS_COMMIT = '61c948b42512e223bad44b83af4080eba48b2677';
564
+ const baselineAgentSkills = [
565
+ 'rsbuild-best-practices',
566
+ 'rspack-best-practices',
567
+ 'rspack-tracing',
568
+ 'rsdoctor-analysis',
569
+ 'rslib-best-practices',
570
+ 'rslib-modern-package',
571
+ 'rstest-best-practices'
572
+ ];
563
573
  const modernPackageNames = [
564
574
  '@modern-js/app-tools',
565
575
  '@modern-js/plugin-bff',
@@ -1533,7 +1543,9 @@ function createTemplateManifest(modernVersion, packageSource) {
1533
1543
  materialization: {
1534
1544
  targetRoot: 'generated-project-root',
1535
1545
  allowedPaths: [
1546
+ '.agents/**',
1536
1547
  '.modernjs/**',
1548
+ 'AGENTS.md',
1537
1549
  'README.md',
1538
1550
  'apps/**',
1539
1551
  'packages/**',
@@ -1562,6 +1574,17 @@ function createTemplateManifest(modernVersion, packageSource) {
1562
1574
  modernPackageSpecifier: modernPackageVersion(packageSource),
1563
1575
  generatedWorkspacePackageSpecifier: WORKSPACE_PACKAGE_VERSION
1564
1576
  },
1577
+ agentSkills: {
1578
+ installDir: '.agents/skills',
1579
+ source: {
1580
+ repository: 'https://github.com/rstackjs/agent-skills',
1581
+ commit: RSTACK_AGENT_SKILLS_COMMIT,
1582
+ license: 'MIT',
1583
+ licensePath: '.agents/rstackjs-agent-skills-LICENSE'
1584
+ },
1585
+ baseline: baselineAgentSkills,
1586
+ lockFile: '.agents/skills-lock.json'
1587
+ },
1565
1588
  validation: {
1566
1589
  schemaValidation: true,
1567
1590
  sourceValidation: [
package/package.json CHANGED
@@ -21,7 +21,7 @@
21
21
  "engines": {
22
22
  "node": ">=20"
23
23
  },
24
- "version": "3.2.0-ultramodern.6",
24
+ "version": "3.2.0-ultramodern.7",
25
25
  "types": "./dist/types/index.d.ts",
26
26
  "main": "./dist/index.js",
27
27
  "bin": {
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 RstackJS Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,57 @@
1
+ ---
2
+ name: rsbuild-best-practices
3
+ description: Rsbuild best practices for config, CLI workflow, type checking, bundle optimization, assets, and debugging. Use when writing, reviewing, or troubleshooting Rsbuild projects.
4
+ ---
5
+
6
+ # Rsbuild Best Practices
7
+
8
+ Apply these rules when writing or reviewing Rsbuild projects.
9
+
10
+ ## Configuration
11
+
12
+ - Use `rsbuild.config.ts` and `defineConfig`
13
+ - Use `tools.rspack` or `tools.bundlerChain` only when no first-class Rsbuild option exists
14
+ - Define explicit `source.entry` values for multi-page applications
15
+ - In TypeScript projects, prefer `tsconfig.json` path aliases first
16
+
17
+ ## CLI
18
+
19
+ - Use `rsbuild` for local development
20
+ - Use `rsbuild build` for production build
21
+ - Use `rsbuild preview` only for local production preview
22
+ - Use `rsbuild inspect` to inspect final Rsbuild/Rspack configs
23
+
24
+ ## Type checking
25
+
26
+ - Use `@rsbuild/plugin-type-check` for integrated dev/build type checks
27
+ - Or run `tsc --noEmit`/`vue-tsc --noEmit` as an explicit script step
28
+
29
+ ## Bundle size optimization
30
+
31
+ - Prefer dynamic `import()` for non-critical code paths
32
+ - Prefer lightweight libraries where possible
33
+ - Keep browserslist aligned with real compatibility requirements
34
+
35
+ ## Asset management
36
+
37
+ - Import source-managed assets from project source directories, not from `public`
38
+ - Reference `public` files by absolute URL path
39
+
40
+ ## Security
41
+
42
+ - Do not publish `.map` files to public servers/CDNs when production source maps are enabled
43
+
44
+ ## Debugging
45
+
46
+ - Run with `DEBUG=rsbuild` when diagnosing config resolution or plugin behavior
47
+ - Read generated files in `dist/.rsbuild` to confirm final config, not assumed config
48
+
49
+ ## Profiling
50
+
51
+ - Use Node CPU profiling (`--cpu-prof`) when JavaScript-side overhead is suspected
52
+ - Use `RSPACK_PROFILE=OVERVIEW` and analyze trace output for compiler-phase bottlenecks
53
+
54
+ ## Documentation
55
+
56
+ - For the latest (v2) docs, read http://rsbuild.rs/llms.txt
57
+ - For Rsbuild v1 docs, read http://v1.rsbuild.rs/llms.txt
@@ -0,0 +1,96 @@
1
+ ---
2
+ name: rsdoctor-analysis
3
+ description: Use when analyzing Rspack/Webpack bundles from local `rsdoctor-data.json` and producing evidence-based optimization recommendations.
4
+ ---
5
+
6
+ # Rsdoctor Analysis Assistant Skill
7
+
8
+ Use the globally installed `rsdoctor-agent` CLI from `@rsdoctor/agent-cli` only after a real `rsdoctor-data.json` path exists. Keep analysis read-only unless the user explicitly asks for install/config setup.
9
+
10
+ Response order (required): High-Priority Issues -> Proposed Solutions -> Optional Reference-Chain Follow-up Choices -> Next Deep-Dive Issue Categories (Not commands).
11
+
12
+ ## Core Workflow
13
+
14
+ 1. Reuse current-session results and valid `.rsdoctor-analysis-cache.json` entries before doing new work.
15
+ 2. Locate `rsdoctor-data.json` fast: user-provided path, then `dist/rsdoctor-data.json`, `output/rsdoctor-data.json`, `static/rsdoctor-data.json`, `.rsdoctor/rsdoctor-data.json`, then one bounded `rg --files` search excluding `node_modules` and `.git`. Treat `manifest.json` only as an index.
16
+ 3. If data exists, skip all plugin version/config/build generation logic. Update cache when useful.
17
+ 4. If data is missing, stop analysis: do not run `rsdoctor-agent` analysis commands, do not run the Analysis Gate, and either ask for the data path or run the Generation Gate below only when setup/generation is required.
18
+ 5. After a real data file exists, run Analysis Gate at most once before the first `rsdoctor-agent` data-fetch command: verify global `@rsdoctor/agent-cli` with `npm view @rsdoctor/agent-cli version` and `rsdoctor-agent --version`; install latest only if missing/outdated, a version-related error occurs, or the user asks to refresh.
19
+ 6. Fetch only the Default Evidence Set first; run independent fetches in parallel when possible; synthesize findings in the required response order.
20
+
21
+ Performance rules: parallelize independent checks, cache only derived facts (`dataFile`, `dataFileMtime`, `pluginName`, `pluginVersion`, dependency/config/plugin modification times), and invalidate cache when paths disappear, modification times change, the user asks to refresh, or cached values fail. Speculative plugin checks must not trigger generation; use them only after confirming the data file is missing.
22
+
23
+ ## Generation Gate
24
+
25
+ Identify `pluginName` (`@rsdoctor/rspack-plugin` or `@rsdoctor/webpack-plugin`) and determine `pluginVersion` from local files first: `package.json`, lockfile, then `node_modules/<plugin>/package.json`; use `pnpm why` / `npm ls` only as fallback.
26
+
27
+ Use this exact if/else decision tree; do not merge branches:
28
+
29
+ ```text
30
+ if pluginName is missing:
31
+ install/register the matching Rsdoctor plugin, then configure output.mode='brief' and output.options.type=['json']; build with RSDOCTOR=true only
32
+ else if pluginVersion is unknown:
33
+ resolve pluginVersion first; if still unknown, configure output.mode='brief' and output.options.type=['json']; build with RSDOCTOR=true only
34
+ else if pluginVersion >= 1.5.11:
35
+ do not edit plugin config just for JSON; build with RSDOCTOR_OUTPUT=json and RSDOCTOR=true if needed
36
+ else: # pluginVersion < 1.5.11
37
+ MUST configure output.mode='brief' and output.options.type=['json']; build with RSDOCTOR=true only
38
+ ```
39
+
40
+ Preflight every build command: `RSDOCTOR_OUTPUT=json` is allowed only in the `pluginVersion >= 1.5.11` branch. For missing, unknown, or `< 1.5.11`, it is forbidden. For `< 1.5.11`, generating `rsdoctor-data.json` requires the plugin config below:
41
+
42
+ ```ts
43
+ output: {
44
+ mode: 'brief',
45
+ options: {
46
+ type: ['json'],
47
+ },
48
+ }
49
+ ```
50
+
51
+ ## Evidence and Command Bounds
52
+
53
+ Default Evidence Set:
54
+
55
+ | Summary key | Evidence source | Bounds |
56
+ | -------------------- | ------------------------------------------ | --------------------------------------------- |
57
+ | `buildCost` | `build summary` | filtered fields only |
58
+ | `assetsTop` | top assets by raw/gzip size | fixed Top-N |
59
+ | `packagesTop` | top packages by gzip size | fixed Top-N; avoid full `packages list` pages |
60
+ | `duplicatePackages` | E1001 duplicate package summary | first-pass summary only |
61
+ | `crossChunkPackages` | E1002 cross-chunk duplication summary | first-pass summary only |
62
+ | `retainedModulesTop` | `tree-shaking retained-modules --limit 10` | filtered fields only; no `--compact` |
63
+
64
+ Scope rules:
65
+
66
+ - Use `rsdoctor-agent` for bundle data access only after `rsdoctor-data.json` exists; prefer parallel independent fetches; bound output with `--filter`, pagination, and `--limit`.
67
+ - Default analysis stays within the Default Evidence Set. For non-default analysis, choose minimal fields from [references/rsdoctor-data-types.md](references/rsdoctor-data-types.md) and patterns from [references/common-analysis-patterns.md](references/common-analysis-patterns.md).
68
+ - Treat chain tracing, broad commands, optimization edits, splitChunks experiments, and build re-runs as opt-in follow-ups that require user confirmation.
69
+ - For duplicate packages and tree-shaking issues, identify issues first; trace reference/import chains only after user confirmation.
70
+ - Prefer `tree-shaking retained-modules --emitted-only --category side-effects --limit 10` with narrow `--filter` for side-effects investigations.
71
+ - For retained emitted modules, use `tree-shaking retained-modules` with `--emitted-only`, bounded `--category`, `--sort gzipSize`, `--limit`, and narrow `--filter`; do not pass `--compact`.
72
+ - Use `tree-shaking summary` only as fallback for missing fields or aggregate context. Treat `tree-shaking bailout-reasons` as high-volume; run it only when explicitly requested and pass target `--modules` (max 100).
73
+ - If any command exceeds `5k` tokens, `500 KB` raw output, or a few hundred transcript lines, stop broad fetching and switch to targeted compact queries.
74
+
75
+ ## Output and Recovery
76
+
77
+ Output format:
78
+
79
+ 1. Issues found in the current build and recommended fixes:
80
+ - Group each issue with its fix recommendation.
81
+ - Include concrete evidence (size/time/count/path/rule code) and priority.
82
+ - For duplicate packages and tree-shaking issues, include a short "continue tracing vs stop here" choice.
83
+ 2. Whether deeper analysis is still needed:
84
+ - List remaining issue categories only, not commands.
85
+
86
+ For Top-N insights, prefer a table: `Name | Volume/Time | Count | Recommendation`.
87
+
88
+ Recovery rules:
89
+
90
+ - `rsdoctor-data.json` missing: do not run `rsdoctor-agent`; ask for the data path or run Generation Gate, then use the matching install reference if setup is needed.
91
+ - Command not found: run Analysis Gate, then retry with `rsdoctor-agent`.
92
+ - `query` reports unknown tool: run `list` and use a catalog tool name, or switch to direct `<group> <subcommand>` mode.
93
+ - JSON read error: verify file path, JSON validity, and permissions.
94
+ - In Codex, do not run `install`, `build`, global CLI installation, version checks, or `rsdoctor-agent...` inside sandbox. Run Rsdoctor CLI setup and data-fetch commands outside sandbox so they can access project files and dependencies normally.
95
+
96
+ References: commands/options [references/command-map.md](references/command-map.md); install/config/data location [references/install-rsdoctor.md](references/install-rsdoctor.md), [references/install-rsdoctor-rspack.md](references/install-rsdoctor-rspack.md), [references/install-rsdoctor-webpack.md](references/install-rsdoctor-webpack.md), [references/install-rsdoctor-common.md](references/install-rsdoctor-common.md); raw data fields [references/rsdoctor-data-types.md](references/rsdoctor-data-types.md); common patterns [references/common-analysis-patterns.md](references/common-analysis-patterns.md).
@@ -0,0 +1,113 @@
1
+ # Rsdoctor Skill Command Map
2
+
3
+ Stable CLI entry:
4
+
5
+ - Install and verify the global CLI first:
6
+ - `npm view @rsdoctor/agent-cli version`
7
+ - `rsdoctor-agent --version`
8
+ - If missing or outdated: `npm install -g @rsdoctor/agent-cli@latest`
9
+ - Run data-fetch commands directly with `rsdoctor-agent <group> <subcommand> [options]`.
10
+
11
+ Top-level command mode:
12
+
13
+ - `list`
14
+ - `query <tool-name> --data-file <path> [--input <json>]`
15
+
16
+ `query` catalog (current):
17
+
18
+ - `chunks_list`
19
+ - `packages_direct_dependencies`
20
+ - `packages_duplicates`
21
+ - `packages_similar`
22
+ - `build_summary`
23
+ - `bundle_optimize`
24
+ - `errors_list`
25
+ - `tree_shaking_summary`
26
+
27
+ Option scopes:
28
+
29
+ - `--data-file <path>`:
30
+ - required for `query`, direct `<group> <subcommand>`, and `ai <group> <subcommand>`
31
+ - not required for `list`, `ai --describe`, `ai --schema`
32
+ - `--input <json>`: optional for `query`
33
+ - `--filter <...>`: supported by every data-fetch function; use it to return only required fields selected from `@rsdoctor/types` / [rsdoctor-data-types.md](rsdoctor-data-types.md)
34
+ - `--compact`: add whenever possible to keep CLI JSON compact. Do not use it with `tree-shaking retained-modules`; use `--filter` and `--limit` instead.
35
+
36
+ ## Chunks
37
+
38
+ - `chunks list` -> List all chunks. Pagination: `--page-number`, `--page-size`
39
+ - `chunks by-id --id <n>` -> Get chunk detail by numeric id
40
+ - `chunks large` -> Find oversized chunks. High-noise in default analysis; avoid unless the user asks for chunk deep dive.
41
+
42
+ ## Modules
43
+
44
+ - `modules by-id --id <id>` -> Module detail by id
45
+ - `modules by-path --path "<path>"` -> Module lookup by path
46
+ - `modules issuer --id <id>` -> Issuer/import chain (recommended as second-pass, after user confirms chain tracing)
47
+ - `modules exports` -> Module exports info
48
+ - `modules side-effects` -> Non-tree-shakeable modules. Fallback only for side-effects analysis; use `--page-size 10`, narrow filters, and stop if output exceeds `5k` tokens or `500 KB`.
49
+
50
+ ## Packages
51
+
52
+ - `packages list` -> Package list with size/duplication info. Do not read full pages in default analysis; use fixed Top-N package summaries or narrowly filtered/package-targeted queries.
53
+ - `packages by-name --name <pkg>` -> Package lookup by name
54
+ - `packages dependencies` -> Dependency graph. Pagination: `--page-number`, `--page-size`
55
+ - `packages direct-dependencies` -> Direct third-party package dependencies imported by project/local packages. Tool name: `packages_direct_dependencies`
56
+ - `packages duplicates` -> Duplicate package detection (first-pass summary before optional chain tracing)
57
+ - `packages similar` -> Similar package detection
58
+
59
+ ## Assets
60
+
61
+ - `assets list` -> Asset list with size info
62
+ - `assets diff --baseline <path> --current <path>` -> Compare two builds
63
+ - `assets media` -> Media optimization guidance
64
+
65
+ ## Loaders
66
+
67
+ - `loaders hot-files` -> Slowest loader/file pairs. Options: `--page-number`, `--page-size`, `--min-costs`
68
+ - `loaders directories` -> Loader times by directory. Options: `--page-number`, `--page-size`, `--min-total-costs`
69
+
70
+ ## Build
71
+
72
+ - `build summary` -> Build summary and costs
73
+ - `build entrypoints` -> Entrypoints
74
+ - `build config` -> Build config snapshot
75
+ - `build optimize` -> Bundle optimization inputs. High-noise in default analysis; avoid unless the user asks for bundle optimization deep dive or default evidence is insufficient. Options: `--step`, `--side-effects-page-number`, `--side-effects-page-size` (recommend `--side-effects-page-size 10`).
76
+
77
+ ## Bundle
78
+
79
+ - `bundle optimize` -> Alias of `build optimize`
80
+
81
+ ## Errors
82
+
83
+ - `errors list` -> All errors and warnings
84
+ - `errors by-code --code <code>` -> Filter by code. For default E1001/E1002 summaries, prefer local JSON summarization.
85
+ - `errors by-level --level <level>` -> Filter by level
86
+
87
+ ## Rules
88
+
89
+ - `rules list` -> Rule scan results
90
+
91
+ ## Server
92
+
93
+ - `server port` -> Current JSON data file path
94
+
95
+ ## Tree-Shaking
96
+
97
+ - `tree-shaking summary` -> Overall tree-shaking health summary (can be very large; filter with fields from `rsdoctor-data-types`, compact where useful, and use aggregated results)
98
+ - `tree-shaking retained-modules` -> Retained emitted modules by category for tree-shaking diagnosis. Useful options: `--emitted-only`, `--category cjs,barrel,side-effects`, `--sort gzipSize`, `--limit <n>`, and `--filter id,path,packageName,version,category,size,chunks,bailoutReason,recommendation`. Does not support `--compact`.
99
+ - `tree-shaking bailout-reasons --modules <module-list>` -> Non-tree-shakeable modules by bailout reason for the provided modules. High-volume; only run when explicitly requested, always pass `--modules`, and include at most 100 modules per command.
100
+ - `tree-shaking exports-analysis` -> Export-level tree-shaking opportunities
101
+
102
+ `tree-shaking retained-modules` returns retained module rows with:
103
+
104
+ | Field | Meaning |
105
+ | ------------------------- | --------------------------------------------- |
106
+ | `id` | Module id |
107
+ | `path` | Module path |
108
+ | `packageName` / `version` | Owning package |
109
+ | `category` | `cjs`, `barrel`, `side-effects`, or `unknown` |
110
+ | `size` | Source, parsed, and gzip sizes when available |
111
+ | `chunks` | Chunk id/name/assets |
112
+ | `bailoutReason` | Original bailout/retention reason |
113
+ | `recommendation` | Optional short recommendation |
@@ -0,0 +1,190 @@
1
+ # Common Analysis Patterns
2
+
3
+ Use this reference for common Rspack/Webpack bundle analysis questions after locating `rsdoctor-data.json`.
4
+
5
+ ## Similar Packages
6
+
7
+ Use direct dependency package data to inspect similar packages. Start with `packages direct-dependencies` or `query packages_direct_dependencies`, then check known package families and other potentially similar packages.
8
+
9
+ Suggested flow:
10
+
11
+ 1. Fetch direct dependency package data with `packages direct-dependencies` or `query packages_direct_dependencies`. Use `--filter` fields for package name, version, issuer/dependency relation, and size when available.
12
+ 2. Treat this direct dependency list as the replacement-candidate set. Do not make replacement recommendations from indirect package-only evidence.
13
+ 3. Check the known families below. The presence of one package from a family is fine; only consider replacement when multiple packages from the same family are present.
14
+ 4. After known-family checks, inspect the direct dependency list for other potentially similar packages not listed below. Treat these as candidates only when package purpose overlaps clearly; avoid speculative replacement advice.
15
+ 5. Use `packages similar` or `query packages_similar` as an additional signal, not the only source of evidence.
16
+
17
+ Similar package families:
18
+
19
+ 1. `lodash`, `lodash-es`
20
+ - Consider migrating from `lodash` to `lodash-es` for better tree-shaking support when both are present.
21
+ 2. `dayjs`, `moment`, `date-fns`, `js-joda`
22
+ - Consider replacing `moment` with `dayjs` for smaller bundle size when both are present and project requirements allow it.
23
+ 3. `antd`, `material-ui`, `semantic-ui-react`, `arco-design`
24
+ 4. `axios`, `node-fetch`
25
+ 5. `redux`, `mobx`, `zustand`, `recoil`, `jotai`
26
+ 6. `chalk`, `colors`, `picocolors`, `kleur`
27
+ 7. `fs-extra`, `graceful-fs`
28
+
29
+ If there are no similar packages, simply say there are no similar packages. Do not list packages that merely exist in the project.
30
+
31
+ Keep the response simple: name only coexisting known-family packages or other direct-dependency candidates with clear overlap, explain why coexistence is worth reviewing, and give one replacement direction if the evidence supports it.
32
+
33
+ ## Media Asset Analysis
34
+
35
+ Use `assets media` or `bundle optimize` when checking oversized image, font, or video assets. Return recommendations only for assets that are actually oversized or relevant to the user's question.
36
+
37
+ Image thresholds:
38
+
39
+ - Mobile: one image file should ideally be under `60 KB`; Base64 SVG should ideally be under `7 KB`.
40
+ - PC: one image file should ideally be under `200 KB`; Base64 SVG should ideally be under `20 KB`.
41
+
42
+ Image recommendations:
43
+
44
+ - Compress large images with image compression tools such as `@rsbuild/plugin-image-compress` (`svgo` for SVG and `@napi-rs/image` for other images).
45
+ - Optimize SVG paths with tools such as SVGO.
46
+ - Consider whether SVG is necessary for the asset.
47
+ - Choose formats by compression characteristics:
48
+ - PNG works best for images with few colors and sharp boundaries, such as text or simple patterns.
49
+ - JPG works best for natural images with gradients and irregular transitions, such as landscapes and portraits.
50
+ - Base64 is suitable for important small images that should avoid extra requests and render immediately. Base64 increases binary size by about one third, but after gzip the increase is usually no more than about 10%.
51
+
52
+ Font thresholds:
53
+
54
+ - Prefer `.woff2`.
55
+ - Keep a single font file under `100 KB` when possible.
56
+ - Keep total font size under `300 KB` for the page, and under `200 KB` for mobile when possible.
57
+ - Avoid font formats other than `ttf`, `woff`, and `woff2` unless there is a compatibility requirement.
58
+
59
+ Font recommendations:
60
+
61
+ - Prefer system fonts when custom fonts are not required.
62
+ - Use `font-display: swap` or `@font-face unicode-range` for more efficient loading.
63
+ - Ensure server-side Gzip or Brotli compression is enabled.
64
+ - Consider variable fonts when they replace multiple weight or width files.
65
+
66
+ Video thresholds:
67
+
68
+ - Keep a single video file under `500 KB` when possible.
69
+ - Keep total video resources loaded on a page under `1 MB` when possible.
70
+
71
+ Video recommendations:
72
+
73
+ - Compress video files with tools such as HandBrake or FFmpeg.
74
+ - Use MP4 (H.264) as the compatibility default.
75
+ - Use WebM (VP9) when modern-browser compression benefits justify it.
76
+ - Lazy-load non-critical videos.
77
+ - Use HLS or DASH for long videos.
78
+ - Remove unused videos.
79
+ - Tune `preload`:
80
+ - `none`: do not download until playback starts; useful for videos unlikely to be played.
81
+ - `metadata`: downloads metadata only, often around 3% of file size.
82
+ - `auto`: downloads the full video; use only when playback is very likely.
83
+
84
+ ## Bundle Optimize
85
+
86
+ Use `bundle optimize` / `build optimize` as an aggregate optimization pass. It can combine evidence from:
87
+
88
+ - Duplicate package rules (`getRuleInfo` / `errors list` / rule details).
89
+ - Similar package checks (`packages similar` / `query packages_similar`).
90
+ - Media asset checks (`assets media`).
91
+ - Chunk checks (`chunks list`, `chunks large`, or chunk details) for oversized resources and `splitChunks` recommendations.
92
+
93
+ Do not run `bundle optimize` / `build optimize` in the default analysis path. Use it only for a user-requested optimization deep dive or when the compact default evidence set is missing required fields.
94
+
95
+ When using it, keep output compact with `--compact`, narrow `--filter` fields, and pagination options such as `--side-effects-page-size 10`. If the command still returns thousands of lines, stop and switch to narrower supporting commands.
96
+
97
+ Do not treat aggregate output as enough by itself when the recommendation needs concrete evidence. Fetch the narrow supporting data before recommending a config or dependency change.
98
+
99
+ ## Build Performance
100
+
101
+ Use these as short recommendation candidates when Rsdoctor evidence points to build-time cost, loader cost, too many modules, or slow dev rebuilds. Source: [Rsbuild build performance guide](https://rsbuild.rs/zh/guide/optimization/build-performance).
102
+
103
+ - Start with build performance analysis. Use measured bottlenecks before recommending config changes. Use Rsdoctor loader costs data.
104
+ - General improvements: upgrade Rsbuild, enable `performance.buildCache` for faster rebuilds, reduce module count, and keep Tailwind CSS v3 `content` narrow and correct.
105
+ - Tooling choices: prefer SWC over Babel transforms, avoid Less-heavy pipelines when possible, and prefer faster minification such as Rsbuild/Rspack SWC minification over Terser when compatible.
106
+ - Sass handling: do not send already-built `node_modules/**/*.css` through `sass-loader`; prefer third-party `dist/*.css` outputs when available. Compile third-party `.scss` / `.sass` only when Sass source features are required, such as variables, mixins, functions, or theme customization, and use an allowlist for those packages instead of all `node_modules`.
107
+ - Less projects: if many Less files are present, consider `@rsbuild/plugin-less` parallel compilation.
108
+ - Development mode: consider `dev.lazyCompilation`, Rspack `experiments.nativeWatcher`, cheaper or disabled dev source maps, and a narrower development Browserslist.
109
+ - Rsdoctor loader evidence: if `sass-loader` time is concentrated in third-party package directories and those packages ship CSS artifacts, recommend importing the CSS artifact or narrowing Sass rule `include` to app source plus specific allowlisted theme packages.
110
+ - Call out tradeoffs: development Browserslist and source map changes can make dev output differ from production or reduce debugging detail.
111
+
112
+ ## Retained Module Tree-shaking Analysis
113
+
114
+ Use `tree-shaking retained-modules` for first-pass tree-shaking evidence when the goal is to find retained emitted modules by reason category. Prefer it over broad `tree-shaking summary` when the user asks for top retained modules, CommonJS retention, barrel imports, side effects, or gzip-size priority.
115
+
116
+ Recommended first-pass command shape:
117
+
118
+ ```bash
119
+ rsdoctor-agent tree-shaking retained-modules \
120
+ --data-file dist/rsdoctor-data.json \
121
+ --emitted-only \
122
+ --category cjs,barrel,side-effects \
123
+ --sort gzipSize \
124
+ --limit 10 \
125
+ --filter id,path,packageName,version,category,size,chunks,bailoutReason,recommendation
126
+ ```
127
+
128
+ Guidance:
129
+
130
+ 1. Keep `--emitted-only` by default so findings map to shipped bundle impact.
131
+ 2. Use `--category cjs,barrel,side-effects` for optimization scans; narrow `--category` when the user asks about one class.
132
+ 3. Sort by `gzipSize` for bundle impact, unless the user asks for source or parsed size.
133
+ 4. Keep `--limit` bounded. Use `--limit 10` for default analysis. Increase to `50` only for user-requested deep dives.
134
+ 5. Do not add `--compact`; `tree-shaking retained-modules` output size is controlled with `--limit` and `--filter`.
135
+ 6. Report rows as `Path | Package | Category | Gzip/Parsed Size | Chunks | Bailout | Recommendation`.
136
+ 7. Treat results as first-pass evidence. Use `modules issuer` only after the user asks to trace who imported a retained module.
137
+
138
+ ## Common Questions
139
+
140
+ ### Why is a module not tree-shaken?
141
+
142
+ Example: "Why is `node_modules/rc-tree/lib/util.js` not tree-shaken?"
143
+
144
+ - Start with `tree-shaking retained-modules` filtered to id, path, package, category, size, chunks, bailout reason, and recommendation when the module appears in emitted output.
145
+ - Use `tree-shaking summary` only when retained modules do not include the needed field or the question needs broader aggregate context.
146
+ - Return the module's `bailoutReason`.
147
+ - Explain the bailout in plain language.
148
+ - Show `issuerPath` only when the user asks for chain tracing or when it is necessary to explain the issue.
149
+
150
+ ### Who imported a module?
151
+
152
+ Example: "Who imported `lodash-es/constant.js`?"
153
+
154
+ - Use module lookup by path, then issuer/import-chain data.
155
+ - Show the dependency chain using arrow notation or a tree.
156
+
157
+ ### Show modules with side effects
158
+
159
+ Example: "Show all modules with side effects."
160
+
161
+ - Prefer `tree-shaking retained-modules --emitted-only --category side-effects` for emitted side-effect modules.
162
+ - Fall back to `tree-shaking summary` or the relevant module-side-effects command only when retained-module output is insufficient.
163
+ - Filter to module id, path, package, size, chunks, bailout reason, and recommendation.
164
+ - List modules with non-empty `bailoutReason` containing `side_effects`.
165
+ - Use `--limit 10` for default output. Increase only after user confirmation.
166
+ - If falling back to `tree-shaking summary` or `modules side-effects`, use `--page-size 10` or `--side-effects-page-size 10`, keep the same narrow fields, and stop expanding when one command exceeds `5k` tokens or `500 KB` raw output.
167
+ - Sort by size, give priority to the largest emitted modules.
168
+
169
+ ### Why is a package duplicated?
170
+
171
+ Example: "Why is package X duplicated?"
172
+
173
+ - Use duplicate package rule data (`E1001` / `E1002`) and package graph fields.
174
+ - Show which chunks and modules contain the duplicate versions.
175
+ - Explain the dependency path if the user asks to continue chain tracing.
176
+
177
+ ### Which modules are not tree-shaken because of side effects?
178
+
179
+ - Use the E1007 rule results directly to identify modules that are not tree-shaken due to side effects. By `tree-shaking summary`.
180
+ - If further details are needed, you may also use `tree-shaking retained-modules --emitted-only --category side-effects` and filter to module id, path, package, size, chunks, bailout reason, and recommendation.
181
+ - List modules with `bailoutReason` containing `side_effects`.
182
+ - Use `--limit 10` by default and the same `5k` token / `500 KB` raw-output stop rule for fallback commands.
183
+ - Show `issuerPath` when needed to identify the import source.
184
+
185
+ ## Output Style
186
+
187
+ - For dependency chains, use a tree or arrow notation.
188
+ - For module details, use a table or key-value list.
189
+ - For explanations, use concise, plain language.
190
+ - Avoid listing all packages or assets when the finding is empty.
@@ -0,0 +1,88 @@
1
+ # Common Steps for Rsdoctor Installation
2
+
3
+ This document contains common steps that apply to both Rspack and Webpack projects.
4
+
5
+ ## Step 3: Locate the rsdoctor-data.json
6
+
7
+ First, use the fast path to check whether `rsdoctor-data.json` already exists. If the user provided a path, check that path first. Otherwise check common build artifact/output locations before any package-manager, install, config, or build command:
8
+
9
+ - `dist/rsdoctor-data.json` (most common)
10
+ - `output/rsdoctor-data.json`
11
+ - `static/rsdoctor-data.json`
12
+ - `.rsdoctor/rsdoctor-data.json` (if using custom reportDir)
13
+
14
+ If common paths do not contain the file, run one bounded local file search that excludes expensive directories, for example `rg --files -g 'rsdoctor-data.json' -g '!node_modules' -g '!**/.git/**'`. If `rsdoctor-data.json` is found, skip the generation/version gate and go directly to JSON analysis. If it is not found, do not run any `rsdoctor-agent` analysis command; ask for the data path or generate the file first.
15
+
16
+ For repeated analysis in the same repository, use a lightweight project-local cache such as `.rsdoctor-analysis-cache.json`. Reuse it only when the cached data-file path still exists and cached modification times match the current `rsdoctor-data.json`, dependency files (`package.json`, lock files), relevant build config files, and plugin `package.json` if recorded. Refresh the cache after locating a new data file or confirming a plugin version.
17
+
18
+ When the runtime supports parallel execution, run independent local initialization checks concurrently: common path checks, bounded `rg --files` lookup, and local plugin-version file reads. Do not run `rsdoctor-agent` CLI checks until a real `rsdoctor-data.json` path exists. Treat plugin-version results as speculative until the data file is confirmed missing; never let parallel plugin checks trigger generation by themselves.
19
+
20
+ If you cannot find the file, ask the user to provide the path to `rsdoctor-data.json`. If the file truly does not exist and generation/setup is required, check the installed `@rsdoctor/rspack-plugin` or `@rsdoctor/webpack-plugin` version before changing config or running a build. The `@rsdoctor/agent-cli` version does not prove plugin support for `RSDOCTOR_OUTPUT=json`.
21
+
22
+ Required version gate (use exactly this if/else order):
23
+
24
+ 1. Identify `pluginName`: `@rsdoctor/rspack-plugin` or `@rsdoctor/webpack-plugin`.
25
+ 2. Determine `pluginVersion` from local files first: dependency declarations in `package.json`, lockfile entries, then installed `node_modules/<plugin>/package.json`. Use package-manager output such as `pnpm why @rsdoctor/rspack-plugin` / `npm ls @rsdoctor/rspack-plugin` only as a fallback.
26
+ 3. Choose one branch; do not merge branches:
27
+
28
+ ```text
29
+ if pluginName is missing:
30
+ install/register the matching Rsdoctor plugin, then MUST configure output.mode='brief' and output.options.type=['json']; build with RSDOCTOR=true only
31
+ else if pluginVersion is unknown:
32
+ resolve pluginVersion first; if still unknown, MUST configure output.mode='brief' and output.options.type=['json']; build with RSDOCTOR=true only
33
+ else if pluginVersion >= 1.5.11:
34
+ do not modify plugin config just for JSON; build with RSDOCTOR_OUTPUT=json and RSDOCTOR=true if needed
35
+ else: # pluginVersion < 1.5.11
36
+ MUST configure output.mode='brief' and output.options.type=['json']; build with RSDOCTOR=true only
37
+ ```
38
+
39
+ Preflight every build command: `RSDOCTOR_OUTPUT=json` is allowed only in the `pluginVersion >= 1.5.11` branch. For missing, unknown, or `< 1.5.11` versions, a command such as `RSDOCTOR_OUTPUT=json RSDOCTOR=true pnpm run build:rspack` is incorrect.
40
+
41
+ The file is typically generated in the same directory as your build output (e.g., `dist`, `output`, `static`). For plugin versions < `1.5.11`, configure a custom output directory using the `output.reportDir` option:
42
+
43
+ ```js
44
+ // Example for Rspack: use RsdoctorRspackPlugin
45
+ // Example for Webpack: use RsdoctorWebpackPlugin
46
+ new RsdoctorRspackPlugin({
47
+ // or RsdoctorWebpackPlugin
48
+ disableClientServer: true,
49
+ output: {
50
+ mode: 'brief',
51
+ options: {
52
+ type: ['json'],
53
+ },
54
+ reportDir: './dist', // Custom output directory (defaults to build output directory)
55
+ },
56
+ });
57
+ ```
58
+
59
+ ---
60
+
61
+ ## Step 4: Use JSON file for analysis
62
+
63
+ Once you have the `rsdoctor-data.json` file, you can use it for analysis. This JSON file contains all the build analysis data and can be used without starting the Rsdoctor server.
64
+
65
+ Analyze the JSON file with the `rsdoctor-agent` CLI from the repository root or another directory that can access the JSON file:
66
+
67
+ ```bash
68
+ rsdoctor-agent build summary --data-file ./dist/rsdoctor-data.json --filter "<fields>"
69
+ ```
70
+
71
+ Keep analysis output small:
72
+
73
+ - Reuse already returned results from context/history first, then run only missing queries.
74
+ - Use `--filter` on data-fetch commands to return only fields required for the current question.
75
+ - Use first-pass summaries for duplicate packages and tree-shaking issues; ask before continuing reference-chain tracing.
76
+ - Stop broad commands when one response exceeds `5k` tokens (o200k_base) or `500 KB` raw output, then switch to filtered or targeted queries.
77
+
78
+ For command names, option scopes, tree-shaking command selection, and `--filter` guidance, use [command-map.md](command-map.md). For raw data field names, use [rsdoctor-data-types.md](rsdoctor-data-types.md).
79
+
80
+ **Benefits of JSON Mode:**
81
+
82
+ - ✅ No need to keep the build process running
83
+ - ✅ Works in CI/CD environments
84
+ - ✅ Can be shared and version controlled
85
+ - ✅ Faster analysis for large projects
86
+ - ✅ No server connection required
87
+
88
+ Note: `rsdoctor-data.json` can be large in complex projects. Add it to `.gitignore` if you do not want to commit it.