@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.
Files changed (101) hide show
  1. package/.agents/plugins/marketplace.json +21 -0
  2. package/.cursor-plugin/plugin.json +8 -0
  3. package/LICENSE +21 -0
  4. package/README.md +255 -2
  5. package/README.zh-CN.md +256 -0
  6. package/bin/uiscope.js +8 -0
  7. package/package.json +89 -3
  8. package/plugin.json +17 -0
  9. package/presets/README.md +11 -0
  10. package/presets/ocpui/index.ts +107 -0
  11. package/skills/README.md +7 -0
  12. package/skills/uiscope-ux-optimize/SKILL.md +267 -0
  13. package/skills/uiscope-ux-optimize/scripts/uiscope.mjs +43 -0
  14. package/src/__tests__/cli-parity.spec.ts +59 -0
  15. package/src/__tests__/cli-read.spec.ts +141 -0
  16. package/src/__tests__/component-tree.spec.ts +72 -0
  17. package/src/__tests__/enhance-core-ux.spec.ts +72 -0
  18. package/src/__tests__/enhance-feedback-states.spec.ts +104 -0
  19. package/src/__tests__/facet-analyze.spec.ts +55 -0
  20. package/src/__tests__/fixtures/exmarket-integration.config.ts +19 -0
  21. package/src/__tests__/format-scan-stats.spec.ts +32 -0
  22. package/src/__tests__/install-skill.spec.ts +41 -0
  23. package/src/__tests__/merge-cli-config.spec.ts +56 -0
  24. package/src/__tests__/react-tree.spec.ts +29 -0
  25. package/src/__tests__/read-scan-report-boundaries.spec.ts +139 -0
  26. package/src/__tests__/read-scan-report.spec.ts +91 -0
  27. package/src/__tests__/resolve-enhancements.spec.ts +21 -0
  28. package/src/__tests__/resolve-presets.spec.ts +51 -0
  29. package/src/__tests__/resolve-scan-scope.spec.ts +28 -0
  30. package/src/__tests__/run-scan-ux.spec.ts +51 -0
  31. package/src/__tests__/scan-progress.spec.ts +52 -0
  32. package/src/__tests__/skill-forwarder.spec.ts +53 -0
  33. package/src/__tests__/style-path.spec.ts +11 -0
  34. package/src/__tests__/style-rules.spec.ts +25 -0
  35. package/src/__tests__/template-hints.spec.ts +19 -0
  36. package/src/__tests__/wrapper-roles.spec.ts +31 -0
  37. package/src/adapters/react/collect-react-files.ts +17 -0
  38. package/src/adapters/react/component-tree.tsx.ts +79 -0
  39. package/src/adapters/react/index.ts +3 -0
  40. package/src/adapters/react/parse-jsx-imports.ts +38 -0
  41. package/src/adapters/vue/index.ts +4 -0
  42. package/src/cli/brand.ts +35 -0
  43. package/src/cli/install-skill.ts +90 -0
  44. package/src/cli/main.ts +578 -0
  45. package/src/cli/merge-cli-config.ts +86 -0
  46. package/src/config/defaults.ts +65 -0
  47. package/src/config/frameworks.ts +20 -0
  48. package/src/config/load-config.ts +81 -0
  49. package/src/config/normalize-legacy-config.ts +39 -0
  50. package/src/config/preset-types.ts +16 -0
  51. package/src/config/resolve-preset-library-roots.ts +49 -0
  52. package/src/config/resolve-presets.ts +142 -0
  53. package/src/config/resolve-scan-scope.ts +12 -0
  54. package/src/config/resolve-thresholds.ts +12 -0
  55. package/src/enhance/dir-utils.ts +25 -0
  56. package/src/enhance/registry.ts +107 -0
  57. package/src/enhance/resolve-enhancements.ts +56 -0
  58. package/src/enhance/rules/action-semantics.ts +60 -0
  59. package/src/enhance/rules/core-ux.ts +139 -0
  60. package/src/enhance/rules/facet-hygiene.ts +44 -0
  61. package/src/enhance/rules/feedback-states.ts +39 -0
  62. package/src/enhance/rules/form-a11y.ts +62 -0
  63. package/src/enhance/rules/hollow-shell.ts +39 -0
  64. package/src/enhance/rules/i18n-hints.ts +29 -0
  65. package/src/enhance/rules/list-templating.ts +38 -0
  66. package/src/enhance/rules/page-rollup.ts +82 -0
  67. package/src/enhance/tree-walk.ts +29 -0
  68. package/src/enhance/types.ts +48 -0
  69. package/src/enhance/ux-rule-pack.ts +40 -0
  70. package/src/enhance/workbench-defaults.ts +28 -0
  71. package/src/index.ts +80 -0
  72. package/src/manifest/consumer-wrapper-roles.ts +34 -0
  73. package/src/manifest/library-components.ts +46 -0
  74. package/src/manifest/library-style-classes.ts +31 -0
  75. package/src/manifest/library-style-whitelist.ts +82 -0
  76. package/src/manifest/library-ux-taxonomy.ts +103 -0
  77. package/src/paths/monorepo-root.ts +13 -0
  78. package/src/report/facet-output-limits.ts +56 -0
  79. package/src/report/format-scan-stats.ts +18 -0
  80. package/src/report/format-ux-scan-report.ts +59 -0
  81. package/src/report/markdown-report.ts +108 -0
  82. package/src/report/print-facets.ts +129 -0
  83. package/src/report/print-styles.ts +20 -0
  84. package/src/report/print-tree.ts +70 -0
  85. package/src/report/print-ux-findings.ts +53 -0
  86. package/src/report/read-scan-report.ts +201 -0
  87. package/src/report/run-report-scenarios.ts +139 -0
  88. package/src/run-scan.ts +341 -0
  89. package/src/scan/collect-source-files.ts +36 -0
  90. package/src/scan/component-tree.ts +155 -0
  91. package/src/scan/extract-node-attrs.ts +49 -0
  92. package/src/scan/facet-analyze.ts +318 -0
  93. package/src/scan/file-uses-library.ts +37 -0
  94. package/src/scan/library-meta.ts +71 -0
  95. package/src/scan/parse-imports.ts +88 -0
  96. package/src/scan/scan-progress.ts +89 -0
  97. package/src/scan/style-path.ts +26 -0
  98. package/src/scan/style-rules.ts +127 -0
  99. package/src/scan/style-trace.ts +181 -0
  100. package/src/scan/template-hints.ts +70 -0
  101. package/src/types.ts +274 -0
@@ -0,0 +1,11 @@
1
+ # Presets
2
+
3
+ Design-system extensions live here, isolated from `src/`. A preset loads only with CLI `--preset <id>` or config `presets: ['<id>']`.
4
+
5
+ Put import sources, whitelist, roles, and default thresholds in the preset’s `configPatch` so the app repo does not need a full `uiscope.config.ts` for library defaults.
6
+
7
+ | Directory | id | Notes |
8
+ | --- | --- | --- |
9
+ | `ocpui/` | `ocpui` | Builtin optional preset (Vue consumer narrowing, whitelist, auto `libraryRoots` when available) |
10
+
11
+ To add a library: copy a folder, implement `UiscopePreset` (`src/config/preset-types.ts`). Site wrappers and skin globs stay in CLI flags or optional app config—not in generic core.
@@ -0,0 +1,107 @@
1
+ import type { UiscopePreset } from '../../src/config/preset-types.js';
2
+ import type { LibraryStyleWhitelistEntry } from '../../src/manifest/library-style-whitelist.js';
3
+ import type { UxComponentRole } from '../../src/manifest/library-ux-taxonomy.js';
4
+
5
+ const OCPUI_STYLE_WHITELIST: readonly LibraryStyleWhitelistEntry[] = [
6
+ { className: 'ocp-form', category: 'form', surface: 'public', owner: 'Form', note: '表单根' },
7
+ { className: 'ocp-form-action-bar', category: 'form', surface: 'public', owner: 'Form', note: '操作条组合' },
8
+ { className: 'ocp-input', category: 'form', surface: 'public', owner: 'Input', note: '输入框根' },
9
+ { className: 'ocp-select', category: 'form', surface: 'public', owner: 'Select', note: '选择器根' },
10
+ { className: 'ocp-checkbox', category: 'form', surface: 'public', owner: 'Checkbox', note: '复选框' },
11
+ { className: 'ocp-radio', category: 'form', surface: 'public', owner: 'Radio', note: '单选框' },
12
+ { className: 'ocp-switch', category: 'form', surface: 'public', owner: 'Switch', note: '开关' },
13
+ { className: 'ocp-table', category: 'data-display', surface: 'public', owner: 'Table', note: '表格' },
14
+ { className: 'ocp-tabs', category: 'navigation', surface: 'public', owner: 'Tabs', note: '选项卡' },
15
+ { className: 'ocp-modal', category: 'feedback', surface: 'public', owner: 'Modal', note: '对话框' },
16
+ { className: 'ocp-drawer', category: 'feedback', surface: 'public', owner: 'Drawer', note: '抽屉' },
17
+ { className: 'ocp-tag', category: 'data-display', surface: 'public', owner: 'Tag', note: '标签' },
18
+ { className: 'ocp-card', category: 'layout', surface: 'public', owner: 'Card', note: '卡片' },
19
+ ];
20
+
21
+ const OCPUI_COMPONENT_ROLES: Record<string, UxComponentRole> = {
22
+ Flex: 'container',
23
+ Grid: 'container',
24
+ GridItem: 'container',
25
+ Card: 'container',
26
+ Drawer: 'container',
27
+ Tabs: 'container',
28
+ TabPane: 'container',
29
+ Form: 'container',
30
+ FormItem: 'container',
31
+ Space: 'container',
32
+ Collapse: 'container',
33
+ CollapsePanel: 'container',
34
+ Split: 'container',
35
+ ResponsiveLayout: 'container',
36
+ UiScenarioScope: 'container',
37
+ AsyncContentShell: 'container',
38
+ ConfigActionBar: 'container',
39
+ SkeletonScene: 'container',
40
+ Search: 'filter',
41
+ SearchTrigger: 'filter',
42
+ SegmentedControl: 'filter',
43
+ TreeSelect: 'filter',
44
+ TimePicker: 'filter',
45
+ TimezoneSelect: 'filter',
46
+ Cascader: 'filter',
47
+ Transfer: 'filter',
48
+ NavTrack: 'navigation',
49
+ VirtualList: 'list',
50
+ SimpleVirtualList: 'list',
51
+ Timeline: 'list',
52
+ ListTransition: 'list',
53
+ Pagination: 'list',
54
+ IconButton: 'form-control',
55
+ Textarea: 'form-control',
56
+ Switch: 'form-control',
57
+ Radio: 'form-control',
58
+ Checkbox: 'form-control',
59
+ Rate: 'form-control',
60
+ Upload: 'form-control',
61
+ Typography: 'text',
62
+ GradientText: 'display',
63
+ Tag: 'display',
64
+ Badge: 'display',
65
+ Avatar: 'display',
66
+ Image: 'media',
67
+ Icon: 'display',
68
+ Breadcrumb: 'navigation',
69
+ Menu: 'navigation',
70
+ Navbar: 'navigation',
71
+ Steps: 'navigation',
72
+ Dropdown: 'navigation',
73
+ Tooltip: 'feedback',
74
+ Spin: 'feedback',
75
+ Toast: 'feedback',
76
+ ContentLoading: 'feedback',
77
+ };
78
+
79
+ const OCPUI_CONFIG_PATCH = {
80
+ frameworks: ['vue'] as const,
81
+ onlyLibraryConsumers: true,
82
+ ignore: ['**/ocpui-components.d.ts'],
83
+ defaultEnhancements: ['feedback-states'] as const,
84
+ thresholds: {
85
+ style: {
86
+ overrideRuleCount: 5,
87
+ warnOrphanOverrides: true,
88
+ },
89
+ tree: {
90
+ maxLibraryNestDepth: 5,
91
+ },
92
+ facet: {
93
+ templateWarnRate: 0.65,
94
+ multiFacetWarnCount: 4,
95
+ },
96
+ },
97
+ } satisfies Partial<import('../../src/types.js').UiscopeConfig>;
98
+
99
+ const preset: UiscopePreset = {
100
+ id: 'ocpui',
101
+ libraryImportSources: ['@ocpui/vue', '@ocpui/vue/', '~/components/ui/ocp'],
102
+ styleWhitelist: OCPUI_STYLE_WHITELIST,
103
+ componentRoles: OCPUI_COMPONENT_ROLES,
104
+ configPatch: OCPUI_CONFIG_PATCH,
105
+ };
106
+
107
+ export default preset;
@@ -0,0 +1,7 @@
1
+ # Agent Skills
2
+
3
+ | 路径 | 说明 |
4
+ | --- | --- |
5
+ | `uiscope-ux-optimize/` | UX 诊断与架构轮优化(通用、库无关) |
6
+
7
+ 每个技能目录含 `SKILL.md`;`uiscope-ux-optimize` 另含 `scripts/uiscope.mjs`,将 argv 转发至包内 `bin/uiscope.js`。包根 `package.json` 的 `contributes.chatSkills` 与 `pi.skills` 指向本目录,形态对齐 [Modern Web Guidance](https://github.com/googlechrome/modern-web-guidance)。
@@ -0,0 +1,267 @@
1
+ ---
2
+ name: uiscope-ux-optimize
3
+ description: >-
4
+ Runs @algotao/uiscope UX + style/nest architecture audit, reads ScanResult and facet/tree
5
+ signals, then implements an agreed architecture round (style override convergence, nesting
6
+ splits, facet extraction) when the user authorizes execution without re-stating steps;
7
+ otherwise presents grouped options via AskQuestion. Use for Vue/React UI layout, interaction,
8
+ redundancy, styling, nesting, or structural review via uiscope.
9
+ ---
10
+
11
+ # UIScope UX 诊断与优化
12
+
13
+ 排版、交互效率、冗余与「流程遗漏」等目标中:**一部分可由静态扫描启发式提示,一部分依赖产品规则、设计规范与人工走查**。Agent 负责读工具输出、核对源码、向用户澄清,不把扫描结果当唯一真理。
14
+
15
+ 下文表格、流程图与「信号→追问」是**已知透镜的示例**,不是穷举清单。未出现在文中的问题(动效、路由、权限、加载策略、业务状态机等)仍可能构成优化空间;**不得**因某行未列出或 `uxFindings` 为空即认定「无优化可做」。
16
+ 允许创新性优化建议,为用户提供美丽的外观和优秀的用户体验,以及富有节奏的交互动效(不多余的)
17
+
18
+ ## 安装本技能
19
+
20
+ 在**应用仓库根目录**:
21
+
22
+ ```bash
23
+ npx -y @algotao/uiscope install
24
+ ```
25
+
26
+ 用户级:`npx -y @algotao/uiscope install --global`。亦可 `npx skills add AlgoTao-dev/uiscope`。
27
+
28
+ ## CLI 与执行入口
29
+
30
+ 扫描须通过 **`@algotao/uiscope` 发布的 CLI**;禁止臆造子命令或跳过可执行体。
31
+
32
+ 在**应用根目录**(`cwd`)按优先级选用:
33
+
34
+ 1. 已声明 `devDependency`:`uiscope <子命令> …`
35
+ 2. 本地已装未上 PATH:`npx uiscope …`(或 `npm exec -- uiscope …`)
36
+ 3. 未安装:`npx -y @algotao/uiscope <子命令> …`
37
+ 4. 从本技能目录调用且整包在磁盘上:`node scripts/uiscope.mjs <子命令> …`(与 `uiscope` 等价,供 Agent Skill / pi-package 解析)
38
+
39
+ 沙箱或需审批环境:**预先**申请可执行 `uiscope` 或 `npx -y @algotao/uiscope *`。
40
+
41
+ ## 通用规则
42
+
43
+ 0. **非侵入**:不要求业务仓库新增配置文件;优先 `uiscope … --config <外部路径>` 或一次性 CLI 参数;报告写入 `.local/` 或用户指定 `--out`,不改动业务源码。
44
+ 1. **先扫描、后改动**:本轮范围内须有 `ScanResult` 或报告 JSON,再改视图/CSS。
45
+ 2. **用户批准**:`optimization.selectable === true` 的项用 **AskQuestion** 勾选(含「暂不处理」);**仅当用户明确授权「按清单/架构轮执行」时**可跳过逐项勾选,且清单须来自用户或仓库文档,不得默认套用某扩展组件库专有条目。
46
+ 3. **方案来源**:用户本轮目标 + 读码 + 扫描结果共同推导;工具 finding 是子集,不是全集。以 `evidence` 核实工具项,**自发现议题**须写明依据(文件/行为/与参照差异)。
47
+ 4. **扫描模式**:默认 `uiscope ux`;同一 `--root` 不重复跑 `all`,除非需要样式(`--with-styles` / `all`)。
48
+ 5. **报告输出**:写入仓库 `.local/`(`uiscope ux --out` 或 `uiscope all --json`);不写 `@algotao/uiscope` 包目录;**不**经 monorepo filter 或间接 npm 脚本调用。
49
+ 6. **改后复扫**:同一 `--root` 再跑 `ux`(或本轮所用模式),核对 `ruleId` 与 severity。
50
+ 7. **误报**:先读 `message`、`evidence` 与源码;再考虑 `uiscope.config.ts`、`presets` 或 `rulePack.disabledRules`。
51
+ 8. **抛光护栏**(与规则 2 并行,抛光轮也适用):遵守下文「抛光护栏」;**不因**「创新/观感」绕过壳层绘面契约(契约细节以**当前项目所用 UI 库文档**为准,非本技能内置)。
52
+
53
+ ## 获取报告
54
+
55
+ ```bash
56
+ cd <应用根目录>
57
+ uiscope ux --root <dir> --enhance-all --out <repo>/.local/<name>.md
58
+ uiscope all --config <path-to-style-audit.config.ts> --json > .local/uiscope-style-audit.json
59
+ ```
60
+
61
+ `--out` 生成同名 `.json`。**跨文件对比**优先 JSON 或完整 Markdown;**单目录快览**可用终端摘要。参数与配置见 npm 包内 `README.md`、`uiscope -h`。若项目通过 **`presets: ['<id>']`**(包内 `presets/<id>/` 或外置模块)接入设计库,在配置或 CLI 中声明即可,本技能不假定具体库名。
62
+
63
+ 大报告勿整文件读入上下文:先 `uiscope read --file <.json>` 看条数,再 `--section uxFindings --offset <n> --limit <m>`;或对 `.md` 用 `--lines start-end`。程序化 API 见 README「程序化 API」。
64
+
65
+ ---
66
+
67
+ ## 扫描字段:能问什么、工具局限
68
+
69
+ 阅读本表后仍须:**打开该 `--root` 内关键 SFC/TSX/composable/路由**,按用户目标做开放式走查;表中未列字段(如 `stats`、`importSources`、未触发规则的数据流)同样可能有用。
70
+
71
+ | 信息源 | 可追问的问题 | 判断时注意 |
72
+ | --- | --- | --- |
73
+ | 切面 `kind` + `layoutHints` | 筛选区、列表区、表单区还是壳层?单文件是否多区并存? | 由库组件角色映射 + class 关键词推断;自动导入封装常为 `unknown`,需结合 class、`consumerWrapperTags` / `wrapperRoles` 配置理解。 |
74
+ | `stats.roles` / `interactiveControls` | 筛选/操作密度是否异常? | `interactiveControls` 仅计 filter + form-control;不含分页、纯展示等。`ctrl=0` 可能是漏交互或识别失败。 |
75
+ | `templateSignals` + `templatingRate` | 是否重复块、宜拆分? | 高模板化可进 facet `warnings`(`templateWarnRate`)。`v-for` 不展开时列表场景可能偏保守。 |
76
+ | facet 相关 `warnings` | 单文件切面是否过多、模板化是否过高? | 多切面不一定是错误,但提示信息密度与拆分可能。 |
77
+ | 组件树 `tree` | 嵌套与关键**静态**属性? | 仅静态绑定;动态 i18n/绑定常不在 `attrs` 中。 |
78
+ | `libraryDoc` / `fileDoc` | 库组件注释、文件头注释是否被忽略? | `libraryDoc` 仅设计库组件节点;业务头注释需直接读源文件。 |
79
+ | `styleChains`、样式告警 | 重载散布、孤儿规则? | 偏维护与一致性,不直接回答「控件该不该存在」。样式议题需 `ux --with-styles` 或 `all` 才有完整 `styleOverrides` / `styleChains`。 |
80
+ | 库嵌套深度告警 | 交互是否过深? | 超过 `maxLibraryNestDepth`(或配置等价项)时提示;须结合树判断「语义必要」vs「可扁平包装」。 |
81
+ | `uxFindings` | 契约类启发式是否成立? | `core-ux` 与可选增强;含 `duplicate-facet-kind`、`hollow-shell`、`list-templating`、`page-rollup` 等可带 `optimization.selectable`。 |
82
+ | 跨文件 `facetReports` + `trees` | 是否存在可抽取的**通用组件/布局 primitive**? | 工具只见单文件;**目录级或模块级重复**须 Agent 读码、`--root` 对比、JSON 切片后归纳,再作为自发现项供选。 |
83
+
84
+ ### 静态扫描盲区(壳层 / 绘面,须自发现)
85
+
86
+ 下列问题**通常不会**进 `styleChains` / facet 告警,抛光或改 overlay 时须读码核对:
87
+
88
+ - **flush 式模态/抽屉**:库提供的反馈类壳层(Modal/Drawer 等)的内容区与槽内**首子节点**是否同时具整幅 `background` 或 `backdrop-filter`。
89
+ - **面色归属**:默认由**壳**绘面时,槽内根节点仅布局/分区;自定义玻璃/半透明由壳 **或** 显式「槽内自负绘面」约定(以库文档/API 名为准)二选一,不得双轨。
90
+ - **delegated surface**:若库支持「壳透明、内容由槽绘制」,槽内根是否自备描边/阴影,避免「无边无影」浮动块。
91
+ - **对称参照**:同场景若另有已收敛实现(命令面板、检索浮层等),对比 DOM 层级与绘面层数,勿只对单侧抛光。
92
+
93
+ ---
94
+
95
+ ## 判断顺序(先结构,后样式)
96
+
97
+ 顺序可打乱;节点可增删。完成流程图**不等于**完成诊断。
98
+
99
+ ```mermaid
100
+ flowchart TD
101
+ A[划定范围 --root] --> B[读 facetReports:kind 组合]
102
+ B --> C[任务闭环:输入/动作/结果/空错态]
103
+ C --> D[uxFindings + 树:核实或否定]
104
+ D --> E[可选:与参照模块 diff JSON]
105
+ E --> F[warnings 与模板化]
106
+ F --> G{样式/架构目标?}
107
+ G -->|收敛 CSS| H[all 或 ux --with-styles]
108
+ G -->|组件化/嵌套| I[facet + 树 + 跨文件读码]
109
+ H --> J[归纳可选优化议题]
110
+ I --> J
111
+ J --> K[AskQuestion 用户勾选]
112
+ ```
113
+
114
+ **范围与对标**
115
+ 在用户指定的参照路径下,用相同 `roots` 与模式各跑一次,对比切面种类、数量、`roles`、锚点差异;工具不给分数,给**差异事实**供你解释。
116
+
117
+ **任务闭环(启发式)**
118
+ 静态规则不能替代走查。读信号时自问:
119
+
120
+ - 筛选区:`roles.filter` 与 `interactiveControls`、树上是否有动作类节点;仅有输入无按钮时 ctrl 仍可能 ≥1,需看树。
121
+ - 列表区:数据组件或 list 线索与反馈态(含同目录拆分文件)是否在结构与行为上闭合;部分缺口工具未必告警。
122
+ - 表单区:多 form-control 时提交/确认是否在树或行为中存在。
123
+
124
+ **复杂度与排版**
125
+ `facetCount` 高、facet warnings、`composite-chrome` 内多切面 → 是否拆文件、减壳层、弹层减负。
126
+
127
+ **重复与冗余**
128
+ `repeated-sibling`、`head-tail-mirror`、并列同 kind 切面 → 是否组件化或减包装;对照树确认哪一层可合并。
129
+
130
+ **无障碍与文案**
131
+ 切面 `aria`、form-a11y / i18n-hints 仅为静态线索;无静态 label 不等于运行时无 a11y。
132
+
133
+ **样式**
134
+ 放在结构与人机闭环之后;重载/孤儿链指向 CSS 维护点,而非直接改交互结构。
135
+
136
+ ---
137
+
138
+ ## 扩展优化透镜(须用户批准)
139
+
140
+ 下列为**建议方向**,不是默认改码清单。每条须有扫描或读码依据,经 **AskQuestion** 勾选后再实现;架构类项默认 **只建议、不自动重构**。
141
+
142
+ ### 1. 减少 CSS 重载
143
+
144
+ | 信号 | 归纳方式 | 可向用户提供的选项示例 |
145
+ | --- | --- | --- |
146
+ | `styleOverrides` 超阈、`warnings` 样式类 | `all` / `ux --with-styles` 后读链路与阈值 | 收敛到 token/主题层;删除重复选择器;用库提供的变体/size 等 API 替代业务层叠类 |
147
+ | `styleChains` 孤儿锚点 | 对照模板是否仍引用该类 | 删无效规则;把样式下沉到设计库或单点全局皮肤文件(路径由项目约定) |
148
+ | 多文件同类重载 | JSON 切片 `styleOverrides` / 人工对比目录 | 抽共享样式模块,避免在业务视图文件继续复制 |
149
+
150
+ 实施前确认:是否允许动全局 CSS、是否影响其他 `roots`。
151
+
152
+ ### 2. 减少不必要嵌套
153
+
154
+ | 信号 | 归纳方式 | 可向用户提供的选项示例 |
155
+ | --- | --- | --- |
156
+ | 树深度告警、`hollow-shell` | 读 `tree`:空壳 div / 单子女包装 | 去掉无样式/无布局意义的包装层;用库布局/容器组件一次到位 |
157
+ | `composite-chrome` 内多层 unknown/html | 对照 `layoutHints` | 壳层合并为单一布局组件或页面 layout slot |
158
+ | 深层库组件套库组件 | 核对交互是否真需组合 | 扁平为 props/slot,或上提到页面级编排 |
159
+
160
+ ### 3. 可合并为通用组件的切面
161
+
162
+ | 信号 | 归纳方式 | 可向用户提供的选项示例 |
163
+ | --- | --- | --- |
164
+ | 同文件 `duplicate-facet-kind`(`facet-hygiene`) | 读 `optimization` + 两切面锚点 | 合并为单一 FilterBar/ListShell 等封装(命名对齐项目惯例) |
165
+ | 高 `templatingRate`、`repeated-sibling`(`list-templating`) | `templateSignals.signature` | 抽列表项/卡片行组件;数据驱动单模板 |
166
+ | 多文件相似 `kind` + `layoutHints` + 树结构 | 跨文件读码、`uiscope read` 分页对比 | 提议 `shared/` 下通用切面组件(命名对齐邻近模块) |
167
+ | `page-rollup` 目录期望 | 与 workbench 参照 diff | 统一页面骨架(filter+list+empty 组合件) |
168
+
169
+ 每项选项应写清:**候选组件名/落盘路径(提议)**、**覆盖哪些源文件**、**不合并时的理由(若用户跳过)**。
170
+
171
+ ### 4. 设计与架构性问题
172
+
173
+ 从 findings + 读码归纳**结构性**议题(非单点样式修补),例如:
174
+
175
+ - 同一业务域内职责重复(两个 FilterBar 语义、双空态、并列列表区)
176
+ - 壳层与内容耦合(浮层内塞进整页逻辑,难以复用与测试)
177
+ - 消费方绕过设计库契约大量原生标签 + 本地 class,长期维护成本高
178
+ - 模块边界不清(`--root` 外隐含依赖、composable 与 UI 缠绕)
179
+
180
+ **做法**:单独列为「架构 / 设计」类 AskQuestion 选项(可与 UX 契约项分组展示);描述现象与风险,**不写死重构方案**;用户选中后再出分步实施计划(可能跨多 PR)。
181
+
182
+ ---
183
+
184
+ ## 信号 → 追问(非固定改法)
185
+
186
+ | 信号类型 | Agent 应追问什么 |
187
+ | --- | --- |
188
+ | 高模板化、重复 signature | 重复 UI 是否应抽组件/单数据源? |
189
+ | 多切面、深嵌套 | 是否应分文件或扁平化壳层? |
190
+ | unknown + layout hint | 识别是否需 preset/角色映射配置,还是业务 class 语义问题? |
191
+ | roles/ctrl 与参照不一致 | 差异是故意还是遗漏?用户定的规格是什么? |
192
+ | 样式超阈、孤儿链 | 是否收敛 token/皮肤,而非在业务层继续叠类? |
193
+ | `duplicate-facet-kind` / 高模板化 | 是否抽通用切面组件?合并后 API(props/events)如何定? |
194
+ | 深嵌套、hollow-shell | 扁平后是否仍满足布局/a11y?删的是哪一层? |
195
+ | 跨文件重复结构 | 通用组件放哪一层(业务 shared vs 应用级)?谁拥有样式? |
196
+ | 架构类自发现 | 用户愿否接受边界调整(拆模块、上移状态、统一壳层)?范围与风险? |
197
+ | flush 浮层 + 玻璃/动效抛光 | 面色在壳还是在槽?有无内外双绘?**当前 UI 库**文档中的 flush / delegated surface 是否匹配? |
198
+
199
+ `optimization` 文案可辅助提问,**实施方案由用户批准后结合仓库惯例自行设计**。样式/组件化/架构类选项可**分组**呈现,避免与交互契约修补混为一谈。
200
+
201
+ ---
202
+
203
+ ## 抛光轮与架构轮
204
+
205
+ 两类目标**勿混在同一 diff 里默认推进**;用户未说清时,先判断属于哪一轮,再选工作流。
206
+
207
+ | 轮次 | 典型用户意图 | 扫描前置 | 改码侧重 | 默认约束 |
208
+ | --- | --- | --- | --- | --- |
209
+ | **架构轮** | 重载收敛、嵌套拆分、样式契约、按用户给定清单执行 | `ux` + 样式审计(`all` / `--with-styles` 或项目 style-audit 配置) | token/皮肤单点、组件化、库 API 对齐 | 不大规模动效与观感抛光 |
210
+ | **抛光轮** | 观感、玻璃、节奏动效、空态气质 | 同上;并读**所用 UI 库**壳层注释与同场景参照源文件 | 微交互、入场节奏、单层壳上的动画 | 遵守「抛光护栏」;多 `--root` 时各消费方对称自检 |
211
+
212
+ ### 抛光护栏
213
+
214
+ 1. **flush 式反馈壳层**:默认壳绘面 → 槽内根**不**再叠整幅 `background` / `backdrop-filter`。槽内需要自定义面色时 → 使用库文档规定的 **delegated surface**(或等价 API),并由槽内根承担圆角内绘面及必要描边/阴影。
215
+ 2. **禁止双绘**:同一视知觉「一块面板」上,壳层与槽内根不得各画一整层不透明/玻璃底。
216
+ 3. **动效附着**:入场/缩放动画优先打在**已确定单色层**的节点上;避免「动画层 + 另加整底」叠加。
217
+ 4. **库优先**:壳层契约以项目 UI 库反馈类组件文档为准;消费方不重复发明第二层壳。
218
+
219
+ ---
220
+
221
+ ## 架构轮授权与清单(项目本地化)
222
+
223
+ 用户出现下列表述时,可**在用户已提供或仓库内已存在的架构清单/ADR/维护文档**前提下直接实施,仍须先跑扫描、改后复扫:
224
+
225
+ - 「执行 / 全部完成 / 按架构轮 / 样式嵌套优化」
226
+ - 或任务本身即「CSS 重载、嵌套、样式架构」且未要求「仅方案」
227
+
228
+ **本技能不内置任何具体组件名、CSS 文件名或应用路径。** Agent 应:
229
+
230
+ 1. 向用户索取或读取仓库中的清单(如 `docs/*-architecture-round.md`、团队 runbook、或本轮对话中用户粘贴的步骤表)。
231
+ 2. 将清单步骤与 `uxFindings`、`styleChains`、`warnings`、树深度告警逐条对齐。
232
+ 3. 验收以清单中的可观测条件为准(告警下降、grep 边界、目视 overlay 单层壳等),而非技能内硬编码示例。
233
+
234
+ 未命中授权或无可执行清单时:仍走 **AskQuestion**(含架构类默认只建议)。
235
+
236
+ ## Agent 工作流
237
+
238
+ 1. 扫描:`ux` 或 `all`(视是否需要样式)+ 可选 `--enhance all`;读 `.local` JSON(`read` 切片)。
239
+ 2. **补全**:读范围内源码与用户描述;列出**工具 findings + 自发现议题**(两类分开标注来源)。
240
+ 3. **分支**:若用户授权且存在**项目架构清单** → 按清单实施;若为**抛光轮** → 先对照「抛光护栏」与同场景参照,再 AskQuestion 或按用户授权范围改码;否则 AskQuestion(分组:交互契约 / CSS / 嵌套 / 组件抽取 / 架构 / 抛光),必含「暂不处理」。
241
+ 4. 写法对齐邻近模块与仓库约定;架构超 scope 只交付分步计划。
242
+ 5. 复扫:与本轮扫描方式一致;**涉及 overlay / 模态 / 命令面板类**时加轻量目视或 DevTools 确认单层壳(复扫不能替代);交付命令、diff 摘要、残留 warnings。
243
+
244
+ ## 约束
245
+
246
+ - 未扫描不得改 UI
247
+ - 不得未经批准批量处理全部 suggest
248
+ - 不得将技能内列举维度当作唯一检查项;不得以 findings 为空代替读码
249
+ - 不在扫描工具包目录存放报告(用 `.local/` 或用户 `--out`)
250
+ - 不得把某一 **preset / 扩展包** 的约定当作未配置仓库的默认事实
251
+
252
+ ## 与其它技能的分工
253
+
254
+ | 技能域 | 职责边界 |
255
+ | --- | --- |
256
+ | 界面质感 / 动效类技能 | 微交互、动效节奏、hover/enter;**不**决定 Modal/Drawer 等壳层面色归属 |
257
+ | UI 设计类技能 | 方向、层级、风格关键词;落地改码仍须经过本技能扫描与抛光护栏 |
258
+ | 本技能 | 结构、重载、嵌套、壳层契约;抛光轮在护栏内执行 |
259
+
260
+ ## 技能副本维护
261
+
262
+ 若仓库内存在**多份同名技能正文**(例如独立包副本与某 preset/扩展包副本),**`@algotao/uiscope` 内 `skills/uiscope-ux-optimize/` 须保持库无关的通用正文**;扩展库专用步骤、组件名与命令应写在对应 preset 包或应用仓文档中,勿反向写入通用副本。
263
+
264
+ ## 参考
265
+
266
+ - `@algotao/uiscope` 包根 `README.md`
267
+ - `@algotao/uiscope` → `src/enhance/registry.ts`
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env node
2
+ import { spawnSync } from 'node:child_process';
3
+ import { createRequire } from 'node:module';
4
+ import fs from 'node:fs';
5
+ import path from 'node:path';
6
+ import { fileURLToPath } from 'node:url';
7
+
8
+ const scriptDir = path.dirname(fileURLToPath(import.meta.url));
9
+
10
+ function resolveCliPath() {
11
+ const require = createRequire(import.meta.url);
12
+ try {
13
+ return require.resolve('@algotao/uiscope/bin/uiscope.js');
14
+ } catch {
15
+ const fromPkgSkill = path.resolve(scriptDir, '../../../..');
16
+ const nested = path.join(fromPkgSkill, 'bin/uiscope.js');
17
+ if (fs.existsSync(nested)) return nested;
18
+ const fromSkillLayout = path.resolve(scriptDir, '../../..');
19
+ if (fs.existsSync(path.join(fromSkillLayout, 'bin/uiscope.js'))) {
20
+ return path.join(fromSkillLayout, 'bin/uiscope.js');
21
+ }
22
+ throw new Error(
23
+ [
24
+ '未找到 @algotao/uiscope CLI。',
25
+ '请在该应用仓安装:npm install -D @algotao/uiscope,然后使用 `uiscope`;',
26
+ '或一次性:npx -y @algotao/uiscope <子命令> …。',
27
+ ].join(' '),
28
+ );
29
+ }
30
+ }
31
+
32
+ const cli = resolveCliPath();
33
+ const child = spawnSync(process.execPath, [cli, ...process.argv.slice(2)], {
34
+ stdio: 'inherit',
35
+ cwd: process.cwd(),
36
+ env: process.env,
37
+ });
38
+
39
+ if (child.error) {
40
+ console.error(child.error.message);
41
+ process.exit(1);
42
+ }
43
+ process.exit(child.status ?? (child.signal ? 1 : 0));
@@ -0,0 +1,59 @@
1
+ import { spawnSync } from 'node:child_process';
2
+ import path from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+ import { describe, expect, it } from 'vitest';
5
+
6
+ const EXPECTED_FLAGS = [
7
+ '--root',
8
+ '--fail-on-warn',
9
+ '--all-files',
10
+ '--include-non-ocp',
11
+ '--json',
12
+ '--threshold',
13
+ '--config',
14
+ '--style-exclude',
15
+ '--out',
16
+ '--facet-limit',
17
+ '--enhance',
18
+ '--enhance-all',
19
+ '--with-styles',
20
+ '--quiet',
21
+ '--file',
22
+ '--section',
23
+ '--offset',
24
+ '--limit',
25
+ '--lines',
26
+ '--framework',
27
+ '--preset',
28
+ '--library-consumers-only',
29
+ '--no-config',
30
+ '--library-root',
31
+ '--library-import',
32
+ '--consumer-wrapper',
33
+ '--ignore',
34
+ '--nest-depth',
35
+ '--no-warn-orphan-styles',
36
+ ];
37
+
38
+ const scanPkg = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..');
39
+ const cli = path.join(scanPkg, 'bin/uiscope.js');
40
+
41
+ describe('CLI parity vs @ocpui/scan', () => {
42
+ it('help lists all legacy-compatible flags', () => {
43
+ const r = spawnSync(process.execPath, [cli, '-h'], { encoding: 'utf8' });
44
+ expect(r.status).toBe(0);
45
+ for (const flag of EXPECTED_FLAGS) {
46
+ expect(r.stdout).toContain(flag);
47
+ }
48
+ });
49
+
50
+ it('--include-non-ocp behaves like --all-files', () => {
51
+ const r = spawnSync(process.execPath, [cli, 'tree', '--root', 'src', '--include-non-ocp', '--json'], {
52
+ cwd: scanPkg,
53
+ encoding: 'utf8',
54
+ });
55
+ expect(r.status).toBe(0);
56
+ const body = JSON.parse(r.stdout);
57
+ expect(body.stats).toBeDefined();
58
+ });
59
+ });
@@ -0,0 +1,141 @@
1
+ import { spawnSync } from 'node:child_process';
2
+ import fs from 'node:fs';
3
+ import os from 'node:os';
4
+ import path from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+ import { describe, expect, it } from 'vitest';
7
+
8
+ const scanPkg = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..');
9
+ const webRoot = path.resolve(scanPkg, '../../apps/web');
10
+ const hasWebFixture = fs.existsSync(path.join(webRoot, 'package.json'));
11
+ const cli = path.join(scanPkg, 'bin/uiscope.js');
12
+ const integrationConfig = path.join(scanPkg, 'src/__tests__/fixtures/exmarket-integration.config.ts');
13
+ const jsonReport = path.resolve(scanPkg, '../../../../.local/uiscope-ux-exmarket-report.json');
14
+ const mdReport = path.resolve(scanPkg, '../../../../.local/uiscope-ux-exmarket-report.md');
15
+
16
+ function run(args: string[], cwd = scanPkg) {
17
+ const argv = args.map((arg, i) => {
18
+ if (i > 0 && args[i - 1] === '--config' && path.isAbsolute(arg)) {
19
+ return path.relative(cwd, arg).replace(/\\/g, '/');
20
+ }
21
+ return arg;
22
+ });
23
+ return spawnSync(process.execPath, [cli, ...argv], {
24
+ cwd,
25
+ encoding: 'utf8',
26
+ env: { ...process.env, FORCE_COLOR: '0' },
27
+ maxBuffer: 20 * 1024 * 1024,
28
+ });
29
+ }
30
+
31
+ describe('cli read + flags', () => {
32
+ it('read without --file exits 1', () => {
33
+ const r = run(['read']);
34
+ expect(r.status).toBe(1);
35
+ expect(r.stderr).toMatch(/需要 --file/);
36
+ });
37
+
38
+ it('read missing file exits 1', () => {
39
+ const r = run(['read', '--file', 'nope.json']);
40
+ expect(r.status).toBe(1);
41
+ expect(r.stderr).toMatch(/不存在/);
42
+ });
43
+
44
+ it('read invalid ScanResult json exits 1', () => {
45
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'uiscope-cli-read-'));
46
+ try {
47
+ const bad = path.join(dir, 'bad.json');
48
+ fs.writeFileSync(bad, '{"trees":[]}');
49
+ const r = run(['read', '--file', bad]);
50
+ expect(r.status).toBe(1);
51
+ expect(r.stderr).toMatch(/非 ScanResult/);
52
+ } finally {
53
+ fs.rmSync(dir, { recursive: true, force: true });
54
+ }
55
+ });
56
+
57
+ it('read md without --lines exits 1', () => {
58
+ if (!fs.existsSync(mdReport)) return;
59
+ const r = run(['read', '--file', mdReport]);
60
+ expect(r.status).toBe(1);
61
+ expect(r.stderr).toMatch(/Markdown/);
62
+ });
63
+
64
+ it('read bad --lines format exits 1', () => {
65
+ if (!fs.existsSync(mdReport)) return;
66
+ const r = run(['read', '--file', mdReport, '--lines', 'abc']);
67
+ expect(r.status).toBe(1);
68
+ expect(r.stderr).toMatch(/start-end/);
69
+ });
70
+
71
+ it('read section on md exits 1', () => {
72
+ if (!fs.existsSync(mdReport)) return;
73
+ const r = run(['read', '--file', mdReport, '--section', 'uxFindings']);
74
+ expect(r.status).toBe(1);
75
+ expect(r.stderr).toMatch(/仅用于/);
76
+ });
77
+
78
+ it('read json counts when report exists', () => {
79
+ if (!fs.existsSync(jsonReport)) return;
80
+ const r = run(['read', '--file', jsonReport]);
81
+ expect(r.status).toBe(0);
82
+ const body = JSON.parse(r.stdout);
83
+ expect(typeof body.uxFindings).toBe('number');
84
+ expect(body.stats).toBeTruthy();
85
+ });
86
+
87
+ it('read json section slice', () => {
88
+ if (!fs.existsSync(jsonReport)) return;
89
+ const r = run(['read', '--file', jsonReport, '--section', 'uxFindings', '--offset', '0', '--limit', '2']);
90
+ expect(r.status).toBe(0);
91
+ const body = JSON.parse(r.stdout);
92
+ expect(body.section).toBe('uxFindings');
93
+ expect(body.items.length).toBeLessThanOrEqual(2);
94
+ expect(body.total).toBeGreaterThanOrEqual(body.items.length);
95
+ });
96
+
97
+ it('read md lines', () => {
98
+ if (!fs.existsSync(mdReport)) return;
99
+ const r = run(['read', '--file', mdReport, '--lines', '1-5']);
100
+ expect(r.status).toBe(0);
101
+ expect(r.stdout).toMatch(/lines 1-5/);
102
+ });
103
+
104
+ it.skipIf(!hasWebFixture)('ux scan --quiet suppresses progress on stderr', () => {
105
+ const r = run(
106
+ [
107
+ 'ux',
108
+ '--root',
109
+ 'app/components/exmarket',
110
+ '--config',
111
+ integrationConfig,
112
+ '-q',
113
+ '--json',
114
+ ],
115
+ webRoot,
116
+ );
117
+ expect(r.status).toBe(0);
118
+ expect(r.stderr).not.toMatch(/解析 Vue/);
119
+ expect(() => JSON.parse(r.stdout)).not.toThrow();
120
+ });
121
+
122
+ it.skipIf(!hasWebFixture)('runScan onProgress receives done phase', async () => {
123
+ const { runScan } = await import('../run-scan.js');
124
+ const { loadScanConfig } = await import('../config/load-config.js');
125
+ const { applyPresets } = await import('../config/resolve-presets.js');
126
+ let config = await loadScanConfig(webRoot, integrationConfig);
127
+ config = await applyPresets(webRoot, config);
128
+ const events: string[] = [];
129
+ await runScan({
130
+ cwd: webRoot,
131
+ config: { ...config, roots: ['app/components/exmarket'] },
132
+ mode: 'ux',
133
+ onlyLibraryTrees: true,
134
+ enhance: ['feedback-states'],
135
+ onProgress: (e) => events.push(e.phase),
136
+ });
137
+ expect(events).toContain('collect');
138
+ expect(events).toContain('vue');
139
+ expect(events).toContain('done');
140
+ });
141
+ });