@nebutra/next-unicorn-skill 1.0.7 → 1.0.8

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/CHANGELOG.md CHANGED
@@ -5,6 +5,24 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.0.8] - 2026-02-09
9
+
10
+ ### Added
11
+
12
+ - **Human-in-the-loop Gate Protocol** — 4 explicit decision gates at irreversible, preference-driven, or costly decision points:
13
+ - Gate 1: Triage detections before Context7 verification (saves quota)
14
+ - Gate 2: Code organization preferences with SWOT analysis (team preferences)
15
+ - Gate 3: Accept/reject/defer recommendations (migration cost decisions)
16
+ - Gate 4: Confirm before PR creation and file migration (irreversible actions)
17
+ - New `references/code-organization-workflow.md` — progressive disclosure reference with Gate examples, Phase A/B decision tree, and worked examples
18
+
19
+ ### Changed
20
+
21
+ - SKILL.md refactored from 400 to 188 lines — verbose Gate/code-org examples extracted to references/ per progressive disclosure spec
22
+ - Removed stale `org-mixed-export-style` reference from Phase A (pattern was moved to structural analyzer)
23
+ - Gate Protocol compressed from 35 lines to 8 lines (meta-info)
24
+ - All instructions converted to imperative voice per skill spec
25
+
8
26
  ## [1.0.7] - 2026-02-09
9
27
 
10
28
  ### Added
package/SKILL.md CHANGED
@@ -25,6 +25,17 @@ Scanner (deterministic) → AI Agent (generative) → Pipel
25
25
  **Design constraints**:
26
26
  - No hardcoded library recommendations — evaluate project context dynamically
27
27
  - Two analysis modes: **replacement** (hand-rolled code found) and **gap** (capability missing entirely)
28
+ - **Human-in-the-loop**: 4 gates at irreversible, preference-driven, or costly decision points
29
+
30
+ ## Gate Protocol
31
+
32
+ Present structured choices at gates. NEVER skip or proceed without user response.
33
+
34
+ **Format** — table of findings/options + lettered choices + your recommendation with 1-sentence rationale. For high-impact gates, add a SWOT table. See `references/code-organization-workflow.md` for full Gate examples.
35
+
36
+ **Rules**:
37
+ - If user says "do it all automatically", ask "confirm skip ALL gates?" first
38
+ - After user decides, execute automatically and report results with rollback instructions
28
39
 
29
40
  ## Standard Operating Procedure
30
41
 
@@ -39,138 +50,81 @@ Run `scanCodebase(input)`. The scanner:
39
50
  1. Detect workspace roots for monorepo support
40
51
  2. Match code against 30+ domain patterns (i18n, auth, state-management, code-organization, etc.)
41
52
  3. Run structural analysis: design system layers (monorepo), code organization (all projects)
42
- 4. Record each detection with: file path, line range, pattern category, confidence score, domain
43
- 5. Return `ScanResult` with:
53
+ 4. Return `ScanResult` with:
44
54
  - `detections` — hand-rolled code patterns found
45
55
  - `structuralFindings` — architectural + code organization issues
46
56
  - `codeOrganizationStats` — project-wide metrics (file counts, naming conventions, circular dep count)
47
57
  - `workspaces` — monorepo workspace info
48
58
 
49
- Detections and findings contain no recommendations — only facts. The AI agent interprets them.
50
-
51
- ### Step 2.5: Gap Analysis (AI Agent)
52
-
53
- Beyond scanner detections, analyze what the project is **missing entirely**. Inspect:
59
+ Detections and findings contain no recommendations — only facts.
54
60
 
55
- 1. **Installed dependencies** identify low-level tools that should be upgraded to platform-level solutions
56
- 2. **Monorepo structure** — identify missing architectural layers (e.g., shared token package, shared config preset)
57
- 3. **Cross-cutting concerns** — identify absent capabilities: structured logging, error monitoring, rate limiting, event-driven workflows, transactional email, type-safe API layer
58
- 4. **Architecture patterns** — identify opportunities for multi-package solutions (e.g., design-tokens → tailwind-config → ui three-layer architecture for design systems)
61
+ ### GATE 1: Triage Detections
59
62
 
60
- Analyze at three levels of depth:
61
- - **Single library gap**: missing one tool (e.g., no form validation library)
62
- - **Ecosystem gap**: missing a coordinated set of tools (e.g., no observability stack)
63
- - **Architecture gap**: missing an entire structural layer (e.g., no design system, no shared config)
63
+ **Why**: Each accepted detection costs a Context7 verification call. False positives waste quota.
64
64
 
65
- Provide each gap as a `GapRecommendation`. Read `src/index.ts` for the interface. Pass gaps via the `gaps` option in `analyze()`.
65
+ Present scan results as a triage table with columns: #, Domain, Pattern, File, Confidence, Action. Offer options: (A) accept all, (B) skip specific numbers, (C) high-confidence only. See `references/code-organization-workflow.md#gate-1-triage-example` for format.
66
66
 
67
- **Design system gaps** Two paths depending on project maturity:
68
- - **No existing frontend**: Scaffold from reference repos. Read `references/design-system-sources.md` for curated sources and sparse-checkout workflow.
69
- - **Existing frontend without formal design system**: First extract the spec (audit → tokens → classify → document) via `references/design-system-extraction.md`, then implement the architecture via `references/design-system-sources.md`.
67
+ Wait for user response. Proceed with accepted detections only.
70
68
 
71
- ### Step 2.7: Code Organization Analysis
72
-
73
- #### Phase A — Deterministic: Collect facts (MUST use tools, DO NOT estimate)
69
+ ### Step 2.5: Gap Analysis (AI Agent)
74
70
 
75
- You cannot infer file counts, naming conventions, or import cycles from knowledge. You MUST read the filesystem.
71
+ Analyze what the project is **missing entirely**:
76
72
 
77
- **If using the npm library** — `scanResult.structuralFindings` and `scanResult.codeOrganizationStats` already contain all findings. Skip to Phase B.
73
+ 1. **Installed dependencies** — low-level tools that should be upgraded to platform-level solutions
74
+ 2. **Monorepo structure** — missing architectural layers (e.g., shared token package, shared config preset)
75
+ 3. **Cross-cutting concerns** — absent capabilities: structured logging, error monitoring, rate limiting, transactional email, type-safe API layer
76
+ 4. **Architecture patterns** — opportunities for multi-package solutions (e.g., design-tokens → tailwind-config → ui)
78
77
 
79
- **If not using the npm library** run these shell commands to collect facts:
78
+ Analyze at three levels: **single library gap**, **ecosystem gap**, **architecture gap**.
80
79
 
81
- ```bash
82
- # 1. God directories: find directories with >15 source files
83
- find src -type d -exec sh -c 'count=$(find "$1" -maxdepth 1 -type f \( -name "*.ts" -o -name "*.tsx" -o -name "*.js" -o -name "*.jsx" \) | wc -l); [ "$count" -gt 15 ] && echo "$1: $count files"' _ {} \;
80
+ Provide each gap as a `GapRecommendation`. Read `src/index.ts` for the interface.
84
81
 
85
- # 2. Mixed naming: list filenames per directory for manual inspection
86
- ls -1 src/components/ # check if kebab-case and camelCase are mixed
82
+ **Design system gaps** two paths:
83
+ - **No existing frontend**: Read `references/design-system-sources.md` for curated repos and sparse-checkout workflow.
84
+ - **Existing frontend**: Read `references/design-system-extraction.md` for extraction workflow, then `references/design-system-sources.md` for implementation.
87
85
 
88
- # 3. Deep nesting: find directories >5 levels deep from src/
89
- find src -mindepth 6 -type d
86
+ ### Step 2.7: Code Organization Analysis
90
87
 
91
- # 4. Barrel bloat: count re-exports in index files
92
- grep -c "export.*from" src/**/index.ts
88
+ #### Phase A Collect facts (MUST use tools, DO NOT estimate)
93
89
 
94
- # 5. Catch-all directories: count files in utils/helpers/shared
95
- find src/utils src/helpers src/shared src/common src/lib -maxdepth 1 -type f 2>/dev/null | wc -l
90
+ You cannot infer file counts, naming conventions, or import cycles from knowledge. You MUST read the filesystem.
96
91
 
97
- # 6. Circular dependencies: use npx if madge is not installed
98
- npx madge --circular --extensions ts,tsx src/
92
+ **If using the npm library** — `scanResult.structuralFindings` and `scanResult.codeOrganizationStats` already contain all findings. Skip to Phase B.
99
93
 
100
- # 7. Deep relative imports: find ../../../ patterns
101
- grep -rn "from ['\"]\.\.\/\.\.\/\.\.\/" src/ --include="*.ts" --include="*.tsx"
102
- ```
94
+ **If not** run the shell commands in `references/code-organization-workflow.md#phase-a-shell-commands-for-collecting-facts`.
103
95
 
104
96
  Record each finding with: **directory/file path, count, type**. These are facts.
105
97
 
106
- #### Phase B — Generative: Recommend solutions (use your knowledge + Context7)
107
-
108
- For each finding from Phase A, apply the decision tree below. **Do NOT recommend tools without Context7 verification.**
109
-
110
- | Finding type | You MUST do | You MUST NOT do |
111
- |---|---|---|
112
- | `god-directory` | Read the files in that dir, group by domain, recommend split. Reference: Next.js App Router colocation, Linear feature-packages. | Guess file count. Say "probably too many files." |
113
- | `mixed-naming-convention` | Check project framework → pick ONE convention. Next.js pages=kebab, React components=PascalCase, utils=camelCase. | Recommend "both are fine." Must pick one. |
114
- | `deep-nesting` | Recommend `@/` path aliases. Read `tsconfig.json` to check if paths already exist. Generate the config change. | Say "consider flattening" without generating the actual config. |
115
- | `barrel-bloat` | Recommend direct imports or namespace imports. Context7 verify `knip` for dead export detection. | Ignore it. Barrel bloat causes tree-shaking failures. |
116
- | `catch-all-directory` | Read the actual files, group by domain (date, string, validation, etc.), recommend specific directory structure. | Say "split by concern" without reading what's actually in the files. |
117
- | `circular-dependency` | Read the files in the cycle, understand WHY they import each other, recommend dependency inversion or extract shared module. Context7 verify `eslint-plugin-import`. | Just say "remove circular deps." Must explain the refactoring. |
118
- | `org-deep-relative-import` | Same as `deep-nesting` — recommend path aliases. | Skip it. |
119
- | `org-barrel-reexport-wildcard` | Recommend named re-exports `export { X } from` instead of `export *`. Explain namespace pollution risk. | Ignore it. |
120
- | `org-catch-all-utils-import` | Same as `catch-all-directory` — recommend domain-specific modules. | Skip it. |
121
-
122
- #### Phase B examples
123
-
124
- **Example 1 — god-directory finding**:
125
- ```
126
- Fact: src/components/ has 23 source files
127
- ```
128
- Read those 23 files. You find: Button, Card, Modal, Table, Form, Input, Select, Checkbox...
98
+ #### Phase B — Recommend solutions (use your knowledge + Context7)
129
99
 
130
- Recommend:
131
- ```
132
- src/components/
133
- ├── ui/ ← primitives (Button, Input, Select, Checkbox)
134
- ├── data/ ← data display (Table, Card, DataGrid)
135
- ├── overlay/ ← overlays (Modal, Dialog, Drawer, Tooltip)
136
- └── form/ ← form elements (Form, FormField, FormError)
137
- ```
138
- Reference: shadcn/ui organizes by interaction type. Radix UI uses similar grouping.
100
+ For each finding, apply the MUST do / MUST NOT do decision tree in `references/code-organization-workflow.md#phase-b-decision-tree`. Do NOT recommend tools without Context7 verification.
139
101
 
140
- **Example 2 circular-dependency finding**:
141
- ```
142
- Fact: src/auth/session.ts → src/db/user.ts → src/auth/session.ts
143
- ```
144
- Read both files. You find: `session.ts` imports `getUserById`, `user.ts` imports `getSession` for auth checks.
102
+ For worked examples showing the full Fact → Read → Recommend flow, see `references/code-organization-workflow.md#phase-b-worked-examples`.
145
103
 
146
- Recommend: Extract `src/auth/types.ts` with shared interfaces. Both files import from types instead of each other. Context7 verify `eslint-plugin-import/no-cycle`.
104
+ **Skip rules** skip a finding if:
105
+ - Directory is in `tests/`, `__tests__/`, `__mocks__/`, `fixtures/`, `generated/`, `.storybook/`
106
+ - File is auto-generated (has `// @generated` or `/* eslint-disable */` at top)
107
+ - Directory has <3 files (too few to judge)
147
108
 
148
- **Example 3 mixed-naming finding**:
149
- ```
150
- Fact: src/utils/ has kebab-case (5 files) + camelCase (3 files)
151
- ```
152
- Check package.json → framework is Next.js → convention is kebab-case for files.
109
+ ### GATE 2: Code Organization Preferences
153
110
 
154
- Recommend: Rename the 3 camelCase files. Context7 verify `eslint-plugin-unicorn/filename-case` for CI enforcement.
111
+ **Why**: Organization pattern and naming convention are team preferences, not technical correctness.
155
112
 
156
- #### Skip rules
113
+ Present only if structural findings exist. For each preference, present a SWOT comparison with lettered options. See `references/code-organization-workflow.md#gate-2-swot-examples` for format.
157
114
 
158
- Skip a code organization finding if:
159
- - Directory is in `tests/`, `__tests__/`, `__mocks__/`, `fixtures/`, `generated/`, `.storybook/`
160
- - File is auto-generated (has `// @generated` or `/* eslint-disable */` at top)
161
- - Directory has <3 files (too few to judge naming convention)
115
+ Wait for user response on each preference. Proceed to Step 3 with confirmed choices.
162
116
 
163
117
  ### Step 3: Recommend Solutions (AI Agent)
164
118
 
165
- For each scanner detection, recommend a **solution**. Consider:
119
+ For each accepted detection, recommend a **solution**:
166
120
 
167
- 1. **Stack coherence** — don't recommend libraries in isolation; consider how they fit the project's overall stack (e.g., recommending Stripe should trigger consideration of Resend for transactional email and PostHog for payment funnel analytics)
121
+ 1. **Stack coherence** — consider how libraries fit the project's overall stack
168
122
  2. **Ecosystem composition** — recommend companion libraries that work together
169
123
  3. **Rationale** — explain WHY this choice fits this project's framework, runtime, and scale
170
124
  4. **Anti-patterns** — what NOT to use and why
171
125
  5. **Alternatives** — different solutions for different architectural contexts
172
- 6. **Migration snippet** — for each recommendation, read the detected code (file path + line range from scanner) and generate a concrete before/after code example showing the migration
173
- 7. **Context7 verification** — call `resolve-library-id` + `query-docs` to confirm the library exists and get latest version/docs
126
+ 6. **Migration snippet** — read the detected code (file path + line range) and generate before/after examples
127
+ 7. **Context7 verification** — call `resolve-library-id` + `query-docs` to confirm existence and get latest docs
174
128
 
175
129
  Read `src/index.ts` for the `LibraryRecommendation` interface. Return `null` to skip a detection.
176
130
 
@@ -180,12 +134,20 @@ Read `src/index.ts` for the `LibraryRecommendation` interface. Return `null` to
180
134
  - Library is already in project dependencies (suggest version update instead)
181
135
  - Hand-rolled code is simpler than the library (3-line utility vs 50KB dep)
182
136
 
137
+ ### GATE 3: Accept/Reject Recommendations
138
+
139
+ **Why**: Each recommendation has real migration cost. User may have business, timeline, or architectural reasons to defer or reject.
140
+
141
+ Present ALL recommendations (replacements + gaps + code org tooling) as a decision table with columns: #, Domain, Replace what, With what, Risk, Effort, Context7, Decision. Offer options: (A) accept all, (B) accept specific, (C) low-risk only, (D) defer all. See `references/code-organization-workflow.md#gate-3-recommendation-table-example` for format.
142
+
143
+ Wait for user response. Rejected items are excluded from migration plan, scoring, and PRs.
144
+
183
145
  ### Step 4–7: Score, Plan, Audit, Serialize
184
146
 
185
147
  The pipeline handles these automatically:
186
- - **Scoring**: confidence-based dimension scores (overridable by AI agent via `dimensionHints`)
148
+ - **Scoring**: confidence-based dimension scores (overridable via `dimensionHints`)
187
149
  - **Migration plan**: auto-grouped by risk (low/medium/high), sorted by file co-location
188
- - **UX audit**: provide via `uxAudit` option in `analyze()`. Evaluate 8 categories: accessibility, error/empty/loading states, form validation, performance feel, copy consistency, design system alignment. For each, assess status (present/partial/missing) based on project code and `currentLibraries`.
150
+ - **UX audit**: provide via `uxAudit` option. Evaluate 8 categories (accessibility, error/empty/loading states, form validation, performance feel, copy consistency, design system alignment)
189
151
  - **Constraints**: license allowlist filtering, dependency conflict detection, JSON serialization
190
152
 
191
153
  ### Optional Steps
@@ -194,6 +156,14 @@ The pipeline handles these automatically:
194
156
  - **Step 9**: Auto-update existing dependencies (`registryClient`)
195
157
  - **Step 10**: PR auto-creation via GitHub/GitLab (`platformClient` + `gitOps`)
196
158
 
159
+ ### GATE 4: Before Irreversible Actions
160
+
161
+ **Why**: Creating PRs pushes branches to remote and notifies team members. File migrations modify the codebase. Both are irreversible.
162
+
163
+ Present only if Step 10 or file migration is about to execute. Show PR table and file migration table with rollback commands. Offer options: (A) execute all, (B) PRs only, (C) migration only, (D) dry run, (E) abort. See `references/code-organization-workflow.md#gate-4-execution-confirmation-example` for format.
164
+
165
+ Wait for user response. After execution, report results with rollback instructions.
166
+
197
167
  ## MCP Integration
198
168
 
199
169
  Prefer MCP tools when available; fall back to shell commands if not.
package/dist/index.d.ts CHANGED
@@ -23,7 +23,7 @@ import type { VulnerabilityClient } from './security/osv-client.js';
23
23
  import type { RegistryClient } from './updater/registry-client.js';
24
24
  import type { PlatformClient } from './pr-creator/platform-client.js';
25
25
  import type { GitOperations } from './pr-creator/git-operations.js';
26
- export declare const VERSION = "1.0.7";
26
+ export declare const VERSION = "1.0.8";
27
27
  /**
28
28
  * A library recommendation provided by the AI agent (or caller).
29
29
  */
package/dist/index.js CHANGED
@@ -27,7 +27,7 @@ import { executePRPlans } from './pr-creator/pr-executor.js';
27
27
  // ---------------------------------------------------------------------------
28
28
  // Version
29
29
  // ---------------------------------------------------------------------------
30
- export const VERSION = '1.0.7';
30
+ export const VERSION = '1.0.8';
31
31
  export { scanCodebase } from './analyzer/scanner.js';
32
32
  export { analyzeStructure } from './analyzer/structure-analyzer.js';
33
33
  export { analyzeCodeOrganization } from './analyzer/code-organization-analyzer.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nebutra/next-unicorn-skill",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "Stop Vibe Coding debt: audit your codebase, replace reinvented wheels with unicorn-grade libraries, scan vulnerabilities, auto-update deps, and auto-create PRs — all verified via Context7 MCP.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",