@algotao/uiscope 0.0.0-stage → 0.1.1
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.
- package/.agents/plugins/marketplace.json +21 -0
- package/.cursor-plugin/plugin.json +8 -0
- package/LICENSE +21 -0
- package/README.md +255 -2
- package/README.zh-CN.md +256 -0
- package/bin/uiscope.js +8 -0
- package/package.json +89 -3
- package/plugin.json +17 -0
- package/presets/README.md +11 -0
- package/presets/ocpui/index.ts +107 -0
- package/skills/README.md +7 -0
- package/skills/uiscope-ux-optimize/SKILL.md +267 -0
- package/skills/uiscope-ux-optimize/scripts/uiscope.mjs +43 -0
- package/src/__tests__/cli-parity.spec.ts +59 -0
- package/src/__tests__/cli-read.spec.ts +141 -0
- package/src/__tests__/component-tree.spec.ts +72 -0
- package/src/__tests__/enhance-core-ux.spec.ts +72 -0
- package/src/__tests__/enhance-feedback-states.spec.ts +104 -0
- package/src/__tests__/facet-analyze.spec.ts +55 -0
- package/src/__tests__/fixtures/exmarket-integration.config.ts +19 -0
- package/src/__tests__/format-scan-stats.spec.ts +32 -0
- package/src/__tests__/install-skill.spec.ts +41 -0
- package/src/__tests__/merge-cli-config.spec.ts +56 -0
- package/src/__tests__/react-tree.spec.ts +29 -0
- package/src/__tests__/read-scan-report-boundaries.spec.ts +139 -0
- package/src/__tests__/read-scan-report.spec.ts +91 -0
- package/src/__tests__/resolve-enhancements.spec.ts +21 -0
- package/src/__tests__/resolve-presets.spec.ts +51 -0
- package/src/__tests__/resolve-scan-scope.spec.ts +28 -0
- package/src/__tests__/run-scan-ux.spec.ts +51 -0
- package/src/__tests__/scan-progress.spec.ts +52 -0
- package/src/__tests__/skill-forwarder.spec.ts +53 -0
- package/src/__tests__/style-path.spec.ts +11 -0
- package/src/__tests__/style-rules.spec.ts +25 -0
- package/src/__tests__/template-hints.spec.ts +19 -0
- package/src/__tests__/wrapper-roles.spec.ts +31 -0
- package/src/adapters/react/collect-react-files.ts +17 -0
- package/src/adapters/react/component-tree.tsx.ts +79 -0
- package/src/adapters/react/index.ts +3 -0
- package/src/adapters/react/parse-jsx-imports.ts +38 -0
- package/src/adapters/vue/index.ts +4 -0
- package/src/cli/brand.ts +35 -0
- package/src/cli/install-skill.ts +90 -0
- package/src/cli/main.ts +578 -0
- package/src/cli/merge-cli-config.ts +86 -0
- package/src/config/defaults.ts +65 -0
- package/src/config/frameworks.ts +20 -0
- package/src/config/load-config.ts +81 -0
- package/src/config/normalize-legacy-config.ts +39 -0
- package/src/config/preset-types.ts +16 -0
- package/src/config/resolve-preset-library-roots.ts +49 -0
- package/src/config/resolve-presets.ts +142 -0
- package/src/config/resolve-scan-scope.ts +12 -0
- package/src/config/resolve-thresholds.ts +12 -0
- package/src/enhance/dir-utils.ts +25 -0
- package/src/enhance/registry.ts +107 -0
- package/src/enhance/resolve-enhancements.ts +56 -0
- package/src/enhance/rules/action-semantics.ts +60 -0
- package/src/enhance/rules/core-ux.ts +139 -0
- package/src/enhance/rules/facet-hygiene.ts +44 -0
- package/src/enhance/rules/feedback-states.ts +39 -0
- package/src/enhance/rules/form-a11y.ts +62 -0
- package/src/enhance/rules/hollow-shell.ts +39 -0
- package/src/enhance/rules/i18n-hints.ts +29 -0
- package/src/enhance/rules/list-templating.ts +38 -0
- package/src/enhance/rules/page-rollup.ts +82 -0
- package/src/enhance/tree-walk.ts +29 -0
- package/src/enhance/types.ts +48 -0
- package/src/enhance/ux-rule-pack.ts +40 -0
- package/src/enhance/workbench-defaults.ts +28 -0
- package/src/index.ts +80 -0
- package/src/manifest/consumer-wrapper-roles.ts +34 -0
- package/src/manifest/library-components.ts +46 -0
- package/src/manifest/library-style-classes.ts +31 -0
- package/src/manifest/library-style-whitelist.ts +82 -0
- package/src/manifest/library-ux-taxonomy.ts +103 -0
- package/src/paths/monorepo-root.ts +13 -0
- package/src/report/facet-output-limits.ts +56 -0
- package/src/report/format-scan-stats.ts +18 -0
- package/src/report/format-ux-scan-report.ts +59 -0
- package/src/report/markdown-report.ts +108 -0
- package/src/report/print-facets.ts +129 -0
- package/src/report/print-styles.ts +20 -0
- package/src/report/print-tree.ts +70 -0
- package/src/report/print-ux-findings.ts +53 -0
- package/src/report/read-scan-report.ts +201 -0
- package/src/report/run-report-scenarios.ts +139 -0
- package/src/run-scan.ts +341 -0
- package/src/scan/collect-source-files.ts +36 -0
- package/src/scan/component-tree.ts +155 -0
- package/src/scan/extract-node-attrs.ts +49 -0
- package/src/scan/facet-analyze.ts +318 -0
- package/src/scan/file-uses-library.ts +37 -0
- package/src/scan/library-meta.ts +71 -0
- package/src/scan/parse-imports.ts +88 -0
- package/src/scan/scan-progress.ts +89 -0
- package/src/scan/style-path.ts +26 -0
- package/src/scan/style-rules.ts +127 -0
- package/src/scan/style-trace.ts +181 -0
- package/src/scan/template-hints.ts +70 -0
- package/src/types.ts +274 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "uiscope",
|
|
3
|
+
"interface": {
|
|
4
|
+
"displayName": "UIScope"
|
|
5
|
+
},
|
|
6
|
+
"plugins": [
|
|
7
|
+
{
|
|
8
|
+
"name": "uiscope-ux-optimize",
|
|
9
|
+
"source": {
|
|
10
|
+
"source": "local",
|
|
11
|
+
"path": "./"
|
|
12
|
+
},
|
|
13
|
+
"policy": {
|
|
14
|
+
"installation": "AVAILABLE",
|
|
15
|
+
"authentication": "ON_INSTALL"
|
|
16
|
+
},
|
|
17
|
+
"category": "Developer Tools",
|
|
18
|
+
"version": "0.1.0"
|
|
19
|
+
}
|
|
20
|
+
]
|
|
21
|
+
}
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 AlgoTao-dev and UIScope 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.
|
package/README.md
CHANGED
|
@@ -1,3 +1,256 @@
|
|
|
1
|
-
#
|
|
1
|
+
# UIScope
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**UIScope** statically analyzes **Vue 3** and **React** UI source and produces a **`ScanResult`** (JSON or Markdown): component trees, design-token style overrides with traces, screen **facets**, and UX contract findings.
|
|
4
|
+
|
|
5
|
+
Use it in **CI**, maintainer reports, and **coding-agent** workflows. Install the bundled skill with **`npx -y @algotao/uiscope install`** (see [Quick start](#quick-start)); package layout follows the [Modern Web Guidance](https://github.com/googlechrome/modern-web-guidance) pi-package pattern. Attach a design system with **`--preset <id>`**—the scanner core stays vendor-neutral.
|
|
6
|
+
|
|
7
|
+
[Quick start](#quick-start) · [Why](#why) · [What you get](#what-you-get) · [Key capabilities](#key-capabilities) · [Who it's for](#who-its-for) · [CLI](#cli-reference) · [API](#programmatic-api)
|
|
8
|
+
|
|
9
|
+
[](package.json)
|
|
10
|
+
[](LICENSE)
|
|
11
|
+
[](https://www.npmjs.com/package/@algotao/uiscope)
|
|
12
|
+
|
|
13
|
+
English | [简体中文](README.zh-CN.md) · [Repository](https://github.com/AlgoTao-dev/uiscope)
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Why
|
|
18
|
+
|
|
19
|
+
Front-end quality work often splits across tools that do not share one model of the UI:
|
|
20
|
+
|
|
21
|
+
| Signal | Typical source | Gap |
|
|
22
|
+
| --- | --- | --- |
|
|
23
|
+
| Syntax & imports | ESLint, TypeScript | Little about composition depth or design-system usage |
|
|
24
|
+
| Visual review | Screenshots, Storybook | Manual, hard to gate in CI |
|
|
25
|
+
| Styles | Design tokens in Figma | No automatic map from **token → overrides in repo** |
|
|
26
|
+
| UX structure | Product specs | Rarely checked against **actual component trees** |
|
|
27
|
+
|
|
28
|
+
Teams then answer architecture questions in ad-hoc ways: “How deep is our library nesting?” “Is this page three regions or one giant template?” “Are we overriding the same class in forty files?” UIScope **parses SFC, CSS, and JSX once** and emits comparable output for humans, pipelines, and agents—same command shape locally and in CI.
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## What you get
|
|
33
|
+
|
|
34
|
+
| Output | What it answers |
|
|
35
|
+
| --- | --- |
|
|
36
|
+
| **Component tree** | Library vs site wrapper vs DOM; nesting depth and import sources |
|
|
37
|
+
| **Style overrides** | Whitelist class repetition in consumer CSS, with **trace chains** back to templates |
|
|
38
|
+
| **Facets** | Interactive regions (kinds like `filter-bar`, `list-region`), templating and layout hints |
|
|
39
|
+
| **UX findings** | **core-ux** contract rules plus optional enhancements (`--enhance`) |
|
|
40
|
+
| **`ScanResult`** | One JSON schema: `trees`, `facetReports`, `uxFindings`, `warnings`, `stats`, … |
|
|
41
|
+
|
|
42
|
+
Presets (see [presets/README.md](presets/README.md)) supply library import prefixes, style whitelists, and component **roles** when you scan a specific design system.
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## Key capabilities
|
|
47
|
+
|
|
48
|
+
| Capability | Description |
|
|
49
|
+
| --- | --- |
|
|
50
|
+
| **Vue + React in one run** | Adapters under `@algotao/uiscope/vue` and `/react`; default scans both under `--root` |
|
|
51
|
+
| **Modes for speed vs depth** | `ux` for fast facet + rules; `all` for tree, styles, facets, and core-ux |
|
|
52
|
+
| **CI-friendly exit codes** | `--fail-on-warn` → exit `1` when warnings exist |
|
|
53
|
+
| **Agent-sized reports** | `--json`, `--out` (+ sidecar `.json`); `read` for counts and section slices |
|
|
54
|
+
| **Presets, not hard-coded vendors** | `--preset <id>` loads `presets/<id>/` or an npm preset package |
|
|
55
|
+
| **Skill + CLI** | `uiscope` bin and `uiscope-ux-optimize` for skill runners |
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## Who it's for
|
|
60
|
+
|
|
61
|
+
| Audience | Use |
|
|
62
|
+
| --- | --- |
|
|
63
|
+
| **Design-system teams** | Track consumer overrides and deep library nesting before refactors |
|
|
64
|
+
| **Product / platform engineers** | Gate merges on facet and UX contract warnings |
|
|
65
|
+
| **Maintainers** | `report` and Markdown outputs for whitelist and scenario comparisons |
|
|
66
|
+
| **Agent workflows** | Feed `ScanResult` or sliced sections into review and refactor skills |
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## Quick start
|
|
71
|
+
|
|
72
|
+
**Requirements:** Node.js `>= 18`, npm 7+. Scans `.vue`, `.tsx`, `.jsx`, and related styles under `--root`.
|
|
73
|
+
|
|
74
|
+
### Coding agents (recommended)
|
|
75
|
+
|
|
76
|
+
From your **application repo** root:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
npx -y @algotao/uiscope install
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Copies the [`uiscope-ux-optimize`](skills/uiscope-ux-optimize/SKILL.md) skill to `.cursor/skills/`. User-wide install: `npx -y @algotao/uiscope install --global` (`~/.cursor/skills`).
|
|
83
|
+
|
|
84
|
+
Other marketplaces:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
npx skills add AlgoTao-dev/uiscope
|
|
88
|
+
pi install git:github.com/AlgoTao-dev/uiscope
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
List options: `npx -y @algotao/uiscope install --help`.
|
|
92
|
+
|
|
93
|
+
### Scan without adding a devDependency
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
npx -y @algotao/uiscope ux --root src --json
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### CLI as a project devDependency
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
npm install --save-dev @algotao/uiscope
|
|
103
|
+
uiscope all --root app --fail-on-warn
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
| Goal | Command |
|
|
107
|
+
| --- | --- |
|
|
108
|
+
| Fast UX + facets | `uiscope ux --root <dir>` |
|
|
109
|
+
| Full gate | `uiscope all --root <dir> --fail-on-warn` |
|
|
110
|
+
| Design-system defaults | `uiscope all --preset <id> --root <dir>` |
|
|
111
|
+
| CLI flags only | append `--no-config` |
|
|
112
|
+
|
|
113
|
+
Example fragment from `--json` (shape only):
|
|
114
|
+
|
|
115
|
+
```json
|
|
116
|
+
{
|
|
117
|
+
"stats": {
|
|
118
|
+
"vueFilesScanned": 24,
|
|
119
|
+
"reactFilesScanned": 6,
|
|
120
|
+
"facetRegions": 11,
|
|
121
|
+
"warnings": 2
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### CI
|
|
127
|
+
|
|
128
|
+
```yaml
|
|
129
|
+
- uses: actions/setup-node@v4
|
|
130
|
+
with:
|
|
131
|
+
node-version: '20'
|
|
132
|
+
- run: npm ci
|
|
133
|
+
- run: npx uiscope all --root app --fail-on-warn
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## CLI reference
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
uiscope [subcommand] [options]
|
|
142
|
+
uiscope -h
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
After install use `uiscope …`; otherwise `npx -y @algotao/uiscope …` with the same arguments.
|
|
146
|
+
|
|
147
|
+
### Subcommands
|
|
148
|
+
|
|
149
|
+
| Subcommand | Description |
|
|
150
|
+
| --- | --- |
|
|
151
|
+
| `install` | Install Agent skill to `.cursor/skills` (`--global` for home dir) |
|
|
152
|
+
| `tree` | Component nesting (library / wrapper / HTML) |
|
|
153
|
+
| `styles` | Whitelist class override counts and trace chains |
|
|
154
|
+
| `facets` | Facets + **core-ux** contract checks |
|
|
155
|
+
| `ux` | Facets + UX rules; **styles off by default** |
|
|
156
|
+
| `all` | tree + styles + facets + core-ux (**default**) |
|
|
157
|
+
| `report` | Maintenance Markdown (multi-scenario) |
|
|
158
|
+
| `read` | Slice saved `.json` / `.md` reports |
|
|
159
|
+
|
|
160
|
+
### Common options
|
|
161
|
+
|
|
162
|
+
| Option | Notes |
|
|
163
|
+
| --- | --- |
|
|
164
|
+
| `--root <dir>` | Scan root (repeatable), relative to `cwd` |
|
|
165
|
+
| `--fail-on-warn` | Exit `1` when warnings exist (CI) |
|
|
166
|
+
| `--preset <id\|@pkg>` | Builtin `presets/<id>/` or npm preset (repeatable) |
|
|
167
|
+
| `--no-config` | Do not auto-load discovered config files |
|
|
168
|
+
| `--config <file>` | Explicit config path |
|
|
169
|
+
| `--framework vue\|react` | Repeatable; default both |
|
|
170
|
+
| `--json` | Full `ScanResult` on stdout |
|
|
171
|
+
| `--all-files` | Ignore library-consumer narrowing |
|
|
172
|
+
| `--enhance <id>` / `--enhance-all` | Optional UX enhancements |
|
|
173
|
+
| `--with-styles` | Include styles in `ux` mode |
|
|
174
|
+
| `--out <file>` | Write Markdown (+ sidecar `.json` for `ux` / `facets`) |
|
|
175
|
+
| `--facet-limit <n>` | Terminal facet file list cap (`0` = all) |
|
|
176
|
+
| `--quiet`, `-q` | No progress on stderr |
|
|
177
|
+
|
|
178
|
+
Full flag list: `uiscope -h`. Legacy alias `--include-non-ocp` equals `--all-files`.
|
|
179
|
+
|
|
180
|
+
### Examples
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
uiscope all --root app --fail-on-warn
|
|
184
|
+
uiscope styles --style-exclude '**/assets/css/site-layout.css' --threshold 6
|
|
185
|
+
uiscope ux --enhance-all --out .local/uiscope-ux-report.md
|
|
186
|
+
uiscope read --file .local/uiscope-ux-report.json --section uxFindings --offset 0 --limit 40
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### Optional config
|
|
190
|
+
|
|
191
|
+
```ts
|
|
192
|
+
import type { UiscopeConfig } from '@algotao/uiscope';
|
|
193
|
+
|
|
194
|
+
export default {
|
|
195
|
+
roots: ['app', 'src'],
|
|
196
|
+
frameworks: ['vue'],
|
|
197
|
+
presets: ['my-ui'],
|
|
198
|
+
libraryImportSources: ['@acme/ui-vue'],
|
|
199
|
+
onlyLibraryConsumers: true,
|
|
200
|
+
consumerWrapperTags: ['AppButton'],
|
|
201
|
+
thresholds: {
|
|
202
|
+
style: { overrideRuleCount: 6 },
|
|
203
|
+
tree: { maxLibraryNestDepth: 5 },
|
|
204
|
+
},
|
|
205
|
+
} satisfies Partial<UiscopeConfig>;
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
Preset load order: `presetModules` → `presets/<id>/` in package → npm `@algotao/preset-<id>`.
|
|
209
|
+
|
|
210
|
+
**Limits:** Auto-imported tags may show as `unknown`; `v-for` / some list JSX are partial; style traces favor Vue template anchors.
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
## Programmatic API
|
|
215
|
+
|
|
216
|
+
```ts
|
|
217
|
+
import {
|
|
218
|
+
runScan,
|
|
219
|
+
loadScanConfig,
|
|
220
|
+
applyPresets,
|
|
221
|
+
createTerminalProgressReporter,
|
|
222
|
+
getScanReportCountsFromFile,
|
|
223
|
+
readScanReportSectionFromFile,
|
|
224
|
+
readTextReportLines,
|
|
225
|
+
sliceScanReportSection,
|
|
226
|
+
} from '@algotao/uiscope';
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
`runScan({ cwd, config, mode, … })` returns `ScanResult`.
|
|
230
|
+
|
|
231
|
+
---
|
|
232
|
+
|
|
233
|
+
## Agent skill
|
|
234
|
+
|
|
235
|
+
Install: `npx -y @algotao/uiscope install`. Skill definition: [skills/uiscope-ux-optimize/SKILL.md](skills/uiscope-ux-optimize/SKILL.md); runners may call bin `uiscope-ux-optimize`. Plugin metadata: `plugin.json`, `.cursor-plugin/`, `.agents/plugins/` (same pattern as [Modern Web Guidance](https://github.com/googlechrome/modern-web-guidance)).
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
239
|
+
## Package layout
|
|
240
|
+
|
|
241
|
+
| Path | Role |
|
|
242
|
+
| --- | --- |
|
|
243
|
+
| `src/` | Core, CLI, enhancements, reports |
|
|
244
|
+
| `src/adapters/vue` · `react` | Framework adapters |
|
|
245
|
+
| `presets/<id>/` | Optional design-system presets |
|
|
246
|
+
| `skills/` | Agent skill bundle |
|
|
247
|
+
|
|
248
|
+
Exports: `@algotao/uiscope`, `@algotao/uiscope/vue`, `@algotao/uiscope/react`.
|
|
249
|
+
|
|
250
|
+
## Development
|
|
251
|
+
|
|
252
|
+
```bash
|
|
253
|
+
npm run check
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
Contract: this document and `uiscope -h`.
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
# UIScope
|
|
2
|
+
|
|
3
|
+
**UIScope** 对 **Vue 3** 与 **React** 界面源码做静态分析,输出标准结构 **`ScanResult`**(JSON / Markdown),包括组件嵌套、设计类样式覆盖与溯源、界面 **切面**(如筛选区、列表区、表单区)以及 UX 契约项。
|
|
4
|
+
|
|
5
|
+
适用于 **CI 门禁**、维护报告与 **编码 Agent** 工作流。推荐先执行 **`npx -y @algotao/uiscope install`** 安装技能(见[快速上手](#快速上手));包形态对齐 [Modern Web Guidance](https://github.com/googlechrome/modern-web-guidance) pi-package。设计库通过 **`--preset <id>`** 接入,扫描内核不写死厂商实现。
|
|
6
|
+
|
|
7
|
+
[快速上手](#快速上手) · [为何需要](#为何需要) · [你能得到什么](#你能得到什么) · [关键特性](#关键特性) · [适合谁](#适合谁) · [CLI](#cli-参考) · [API](#程序化-api)
|
|
8
|
+
|
|
9
|
+
[](package.json)
|
|
10
|
+
[](LICENSE)
|
|
11
|
+
[](https://www.npmjs.com/package/@algotao/uiscope)
|
|
12
|
+
|
|
13
|
+
[English](README.md) | 简体中文 · [仓库](https://github.com/AlgoTao-dev/uiscope)
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## 为何需要
|
|
18
|
+
|
|
19
|
+
前端质量信号常常分散在**互不打通**的工具里:
|
|
20
|
+
|
|
21
|
+
| 信号 | 常见来源 | 空缺 |
|
|
22
|
+
| --- | --- | --- |
|
|
23
|
+
| 语法与依赖 | ESLint、TypeScript | 很少反映组合深度与设计库用法 |
|
|
24
|
+
| 视觉 | 截图、Storybook | 难进 CI,难做可比对结论 |
|
|
25
|
+
| 样式 | 设计稿 token | 缺少 **token → 仓库内覆盖点** 的自动映射 |
|
|
26
|
+
| 结构 / UX | 产品文档 | 很少对照**真实组件树**做契约检查 |
|
|
27
|
+
|
|
28
|
+
于是架构类问题往往靠人工碎片回答:「库组件嵌了多深?」「这页是三个区域还是一整块模板?」「同一个 class 是否在几十个文件里被覆盖?」UIScope **一次解析** SFC、CSS、JSX,为人、流水线和 Agent 产出**同一套结构化结果**,本地与 CI 命令形态一致。
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## 你能得到什么
|
|
33
|
+
|
|
34
|
+
| 产出 | 回答的问题 |
|
|
35
|
+
| --- | --- |
|
|
36
|
+
| **组件树** | 库 / 站点封装 / DOM;嵌套深度与 import 来源 |
|
|
37
|
+
| **样式重载** | 白名单 class 在消费方 CSS 中的重复与 **溯源链** |
|
|
38
|
+
| **切面(Facet)** | 可交互区域类型(如 `filter-bar`、`list-region`)、模板化与布局线索 |
|
|
39
|
+
| **UX 结论** | **core-ux** 契约规则 + 可选增强(`--enhance`) |
|
|
40
|
+
| **`ScanResult`** | 统一 JSON:`trees`、`facetReports`、`uxFindings`、`warnings`、`stats` 等 |
|
|
41
|
+
|
|
42
|
+
设计库相关配置见 [presets/README.md](presets/README.md)(英文):import 前缀、样式白名单、组件 **角色** 由 preset 注入。
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## 关键特性
|
|
47
|
+
|
|
48
|
+
| 特性 | 说明 |
|
|
49
|
+
| --- | --- |
|
|
50
|
+
| **Vue + React 一次跑完** | `@algotao/uiscope/vue`、`/react`;默认在 `--root` 下同时扫描 |
|
|
51
|
+
| **按深度选模式** | `ux` 偏快(切面 + 规则);`all` 含树、样式、切面与 core-ux |
|
|
52
|
+
| **CI 可门禁** | `--fail-on-warn` 有告警时退出码 `1` |
|
|
53
|
+
| **Agent 友好体量** | `--json`、`--out`(附同名 `.json`);`read` 先计数再按区段读取 |
|
|
54
|
+
| **Preset 扩展** | `--preset <id>` 加载包内或 npm preset,core 不写死库名 |
|
|
55
|
+
| **Skill + CLI** | `uiscope` 与 `uiscope-ux-optimize` 双入口 |
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## 适合谁
|
|
60
|
+
|
|
61
|
+
| 角色 | 典型用法 |
|
|
62
|
+
| --- | --- |
|
|
63
|
+
| **设计体系 / 组件库团队** | 重构前看清消费方覆盖与库嵌套深度 |
|
|
64
|
+
| **平台 / 业务工程** | 合并前用切面与 UX 契约做门禁 |
|
|
65
|
+
| **维护者** | `report` 与 Markdown 做白名单、场景对比 |
|
|
66
|
+
| **Agent 工作流** | 将 `ScanResult` 或切片喂给评审与重构技能 |
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## 快速上手
|
|
71
|
+
|
|
72
|
+
**环境:** Node.js `>= 18`,npm 7+。扫描 `--root` 下的 `.vue`、`.tsx`、`.jsx` 及相关样式。
|
|
73
|
+
|
|
74
|
+
### 编码 Agent(推荐)
|
|
75
|
+
|
|
76
|
+
在**应用仓库根目录**执行:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
npx -y @algotao/uiscope install
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
将 [`uiscope-ux-optimize`](skills/uiscope-ux-optimize/SKILL.md) 安装到 `.cursor/skills/`。用户级:`npx -y @algotao/uiscope install --global`(`~/.cursor/skills`)。
|
|
83
|
+
|
|
84
|
+
其他来源:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
npx skills add AlgoTao-dev/uiscope
|
|
88
|
+
pi install git:github.com/AlgoTao-dev/uiscope
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
说明:`npx -y @algotao/uiscope install --help`。
|
|
92
|
+
|
|
93
|
+
### 不添加 devDependency 的扫描
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
npx -y @algotao/uiscope ux --root src --json
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### 将 CLI 装进项目
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
npm install --save-dev @algotao/uiscope
|
|
103
|
+
uiscope all --root app --fail-on-warn
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
| 场景 | 命令 |
|
|
107
|
+
| --- | --- |
|
|
108
|
+
| 快速 UX + 切面 | `uiscope ux --root <dir>` |
|
|
109
|
+
| 全量门禁 | `uiscope all --root <dir> --fail-on-warn` |
|
|
110
|
+
| 设计库默认项 | `uiscope all --preset <id> --root <dir>` |
|
|
111
|
+
| 仅用 CLI 旗标 | 追加 `--no-config` |
|
|
112
|
+
|
|
113
|
+
`--json` 输出中的 `stats` 片段示例(仅示意结构):
|
|
114
|
+
|
|
115
|
+
```json
|
|
116
|
+
{
|
|
117
|
+
"stats": {
|
|
118
|
+
"vueFilesScanned": 24,
|
|
119
|
+
"reactFilesScanned": 6,
|
|
120
|
+
"facetRegions": 11,
|
|
121
|
+
"warnings": 2
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### CI
|
|
127
|
+
|
|
128
|
+
```yaml
|
|
129
|
+
- uses: actions/setup-node@v4
|
|
130
|
+
with:
|
|
131
|
+
node-version: '20'
|
|
132
|
+
- run: npm ci
|
|
133
|
+
- run: npx uiscope all --root app --fail-on-warn
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## CLI 参考
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
uiscope [子命令] [选项]
|
|
142
|
+
uiscope -h
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
安装后用 `uiscope …`;未安装时用 `npx -y @algotao/uiscope …`,参数相同。
|
|
146
|
+
|
|
147
|
+
### 子命令
|
|
148
|
+
|
|
149
|
+
| 子命令 | 说明 |
|
|
150
|
+
| --- | --- |
|
|
151
|
+
| `install` | 安装 Agent 技能到 `.cursor/skills`(`--global` 为用户目录) |
|
|
152
|
+
| `tree` | 组件嵌套(库 / 封装 / HTML) |
|
|
153
|
+
| `styles` | 白名单 class 重载统计与溯源链 |
|
|
154
|
+
| `facets` | 切面 + **core-ux** 契约 |
|
|
155
|
+
| `ux` | 切面 + UX 规则;**默认不扫样式** |
|
|
156
|
+
| `all` | 树 + 样式 + 切面 + core-ux(**默认**) |
|
|
157
|
+
| `report` | 维护向多场景 Markdown |
|
|
158
|
+
| `read` | 已落盘 `.json` / `.md` 报告切片 |
|
|
159
|
+
|
|
160
|
+
### 常用选项
|
|
161
|
+
|
|
162
|
+
| 选项 | 说明 |
|
|
163
|
+
| --- | --- |
|
|
164
|
+
| `--root <dir>` | 扫描根(可重复),相对 `cwd` |
|
|
165
|
+
| `--fail-on-warn` | 有告警时退出码 `1`(CI) |
|
|
166
|
+
| `--preset <id\|@pkg>` | 包内 `presets/<id>/` 或 npm preset(可重复) |
|
|
167
|
+
| `--no-config` | 不自动加载已发现配置文件 |
|
|
168
|
+
| `--config <file>` | 显式配置路径 |
|
|
169
|
+
| `--framework vue\|react` | 可重复;默认两者 |
|
|
170
|
+
| `--json` | 标准输出完整 `ScanResult` |
|
|
171
|
+
| `--all-files` | 忽略「仅库消费方」收窄 |
|
|
172
|
+
| `--enhance <id>` / `--enhance-all` | 可选 UX 增强 |
|
|
173
|
+
| `--with-styles` | `ux` 模式下包含样式 |
|
|
174
|
+
| `--out <file>` | 写 Markdown(`ux` / `facets` 另生成同名 `.json`) |
|
|
175
|
+
| `--facet-limit <n>` | 终端切面文件列表上限(`0` 为全量) |
|
|
176
|
+
| `--quiet`, `-q` | 不输出 stderr 进度 |
|
|
177
|
+
|
|
178
|
+
完整选项:`uiscope -h`。历史别名 `--include-non-ocp` 等同 `--all-files`。
|
|
179
|
+
|
|
180
|
+
### 示例
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
uiscope all --root app --fail-on-warn
|
|
184
|
+
uiscope styles --style-exclude '**/assets/css/site-layout.css' --threshold 6
|
|
185
|
+
uiscope ux --enhance-all --out .local/uiscope-ux-report.md
|
|
186
|
+
uiscope read --file .local/uiscope-ux-report.json --section uxFindings --offset 0 --limit 40
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### 可选配置
|
|
190
|
+
|
|
191
|
+
```ts
|
|
192
|
+
import type { UiscopeConfig } from '@algotao/uiscope';
|
|
193
|
+
|
|
194
|
+
export default {
|
|
195
|
+
roots: ['app', 'src'],
|
|
196
|
+
frameworks: ['vue'],
|
|
197
|
+
presets: ['my-ui'],
|
|
198
|
+
libraryImportSources: ['@acme/ui-vue'],
|
|
199
|
+
onlyLibraryConsumers: true,
|
|
200
|
+
consumerWrapperTags: ['AppButton'],
|
|
201
|
+
thresholds: {
|
|
202
|
+
style: { overrideRuleCount: 6 },
|
|
203
|
+
tree: { maxLibraryNestDepth: 5 },
|
|
204
|
+
},
|
|
205
|
+
} satisfies Partial<UiscopeConfig>;
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
Preset 加载顺序:`presetModules` → 包内 `presets/<id>/` → npm `@algotao/preset-<id>`。
|
|
209
|
+
|
|
210
|
+
**局限:** 自动导入标签可能为 `unknown`;`v-for` / 部分列表 JSX 覆盖不完整;样式溯源偏 Vue 模板锚点。
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
## 程序化 API
|
|
215
|
+
|
|
216
|
+
```ts
|
|
217
|
+
import {
|
|
218
|
+
runScan,
|
|
219
|
+
loadScanConfig,
|
|
220
|
+
applyPresets,
|
|
221
|
+
createTerminalProgressReporter,
|
|
222
|
+
getScanReportCountsFromFile,
|
|
223
|
+
readScanReportSectionFromFile,
|
|
224
|
+
readTextReportLines,
|
|
225
|
+
sliceScanReportSection,
|
|
226
|
+
} from '@algotao/uiscope';
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
`runScan({ cwd, config, mode, … })` 返回 `ScanResult`。
|
|
230
|
+
|
|
231
|
+
---
|
|
232
|
+
|
|
233
|
+
## Agent 技能
|
|
234
|
+
|
|
235
|
+
安装:`npx -y @algotao/uiscope install`。技能定义:[skills/uiscope-ux-optimize/SKILL.md](skills/uiscope-ux-optimize/SKILL.md);运行器可用 bin `uiscope-ux-optimize`。插件清单见 `plugin.json`、`.cursor-plugin/`、`.agents/plugins/`(形态同 [Modern Web Guidance](https://github.com/googlechrome/modern-web-guidance))。
|
|
236
|
+
|
|
237
|
+
---
|
|
238
|
+
|
|
239
|
+
## 目录结构
|
|
240
|
+
|
|
241
|
+
| 路径 | 职责 |
|
|
242
|
+
| --- | --- |
|
|
243
|
+
| `src/` | 内核、CLI、增强、报告 |
|
|
244
|
+
| `src/adapters/vue` · `react` | 框架适配 |
|
|
245
|
+
| `presets/<id>/` | 可选设计库 preset |
|
|
246
|
+
| `skills/` | Agent 技能包 |
|
|
247
|
+
|
|
248
|
+
导出:`@algotao/uiscope`、`@algotao/uiscope/vue`、`@algotao/uiscope/react`。
|
|
249
|
+
|
|
250
|
+
## 开发
|
|
251
|
+
|
|
252
|
+
```bash
|
|
253
|
+
npm run check
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
对外约定:本文与 `uiscope -h`。
|
package/bin/uiscope.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
4
|
+
import { register } from 'tsx/esm/api';
|
|
5
|
+
|
|
6
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
7
|
+
register();
|
|
8
|
+
await import(pathToFileURL(path.resolve(__dirname, '../src/cli/main.ts')).href);
|
package/package.json
CHANGED
|
@@ -1,6 +1,92 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@algotao/uiscope",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"displayName": "UIScope",
|
|
5
|
+
"description": "Static Vue/React UI scan: component trees, style overrides, UX facets, and agent skill install.",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"engines": {
|
|
9
|
+
"node": ">=18"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/AlgoTao-dev/UIScope.git"
|
|
14
|
+
},
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"bin": {
|
|
19
|
+
"uiscope": "./bin/uiscope.js",
|
|
20
|
+
"uiscope-ux-optimize": "./skills/uiscope-ux-optimize/scripts/uiscope.mjs"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"pi-package",
|
|
24
|
+
"agent-skill",
|
|
25
|
+
"uiscope",
|
|
26
|
+
"vue",
|
|
27
|
+
"react",
|
|
28
|
+
"ux",
|
|
29
|
+
"static-analysis"
|
|
30
|
+
],
|
|
31
|
+
"contributes": {
|
|
32
|
+
"chatSkills": [
|
|
33
|
+
{
|
|
34
|
+
"path": "./skills/uiscope-ux-optimize/SKILL.md"
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
},
|
|
38
|
+
"pi": {
|
|
39
|
+
"skills": [
|
|
40
|
+
"./skills"
|
|
41
|
+
]
|
|
42
|
+
},
|
|
43
|
+
"exports": {
|
|
44
|
+
".": {
|
|
45
|
+
"types": "./src/index.ts",
|
|
46
|
+
"default": "./src/index.ts"
|
|
47
|
+
},
|
|
48
|
+
"./bin/uiscope.js": "./bin/uiscope.js",
|
|
49
|
+
"./vue": {
|
|
50
|
+
"types": "./src/adapters/vue/index.ts",
|
|
51
|
+
"default": "./src/adapters/vue/index.ts"
|
|
52
|
+
},
|
|
53
|
+
"./react": {
|
|
54
|
+
"types": "./src/adapters/react/index.ts",
|
|
55
|
+
"default": "./src/adapters/react/index.ts"
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"scripts": {
|
|
59
|
+
"typecheck": "tsc --noEmit",
|
|
60
|
+
"test": "vitest",
|
|
61
|
+
"test:run": "vitest run",
|
|
62
|
+
"check": "npm run typecheck && npm run test:run",
|
|
63
|
+
"test:integration": "npm run test:run -- src/__tests__/run-scan-ux.spec.ts",
|
|
64
|
+
"prepublishOnly": "npm run check"
|
|
65
|
+
},
|
|
66
|
+
"dependencies": {
|
|
67
|
+
"@vue/compiler-dom": "^3.5.13",
|
|
68
|
+
"@vue/compiler-sfc": "^3.5.13",
|
|
69
|
+
"fast-glob": "^3.3.3",
|
|
70
|
+
"jiti": "^2.4.2",
|
|
71
|
+
"postcss": "^8.5.6",
|
|
72
|
+
"postcss-safe-parser": "^7.0.1",
|
|
73
|
+
"tsx": "^4.22.4"
|
|
74
|
+
},
|
|
75
|
+
"devDependencies": {
|
|
76
|
+
"@types/node": "^22.10.5",
|
|
77
|
+
"typescript": "~5.6.3",
|
|
78
|
+
"vitest": "^3.0.0"
|
|
79
|
+
},
|
|
80
|
+
"files": [
|
|
81
|
+
".agents",
|
|
82
|
+
".cursor-plugin",
|
|
83
|
+
"bin",
|
|
84
|
+
"LICENSE",
|
|
85
|
+
"README.md",
|
|
86
|
+
"README.zh-CN.md",
|
|
87
|
+
"plugin.json",
|
|
88
|
+
"presets",
|
|
89
|
+
"skills",
|
|
90
|
+
"src"
|
|
91
|
+
]
|
|
6
92
|
}
|
package/plugin.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://agent-plugins.org/schemas/1.0.0/plugin.schema.json",
|
|
3
|
+
"name": "uiscope-ux-optimize",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"description": "UIScope — static Vue/React UI scan plus agent skill for UX and architecture optimization",
|
|
6
|
+
"homepage": "https://github.com/AlgoTao-dev/UIScope",
|
|
7
|
+
"repository": "https://github.com/AlgoTao-dev/UIScope",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"keywords": [
|
|
10
|
+
"uiscope",
|
|
11
|
+
"vue",
|
|
12
|
+
"react",
|
|
13
|
+
"ux",
|
|
14
|
+
"agent-skill",
|
|
15
|
+
"static-analysis"
|
|
16
|
+
]
|
|
17
|
+
}
|