@smartsoft001/pro-claude-plugins 0.2.0

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 (198) hide show
  1. package/.claude-plugin/marketplace.json +26 -0
  2. package/README.md +56 -0
  3. package/package.json +14 -0
  4. package/plugins/flow/.claude-plugin/README.md +91 -0
  5. package/plugins/flow/.claude-plugin/merge-permissions.js +115 -0
  6. package/plugins/flow/.claude-plugin/plugin.json +5 -0
  7. package/plugins/flow/.claude-plugin/settings.template.json +86 -0
  8. package/plugins/flow/agents/angular-component-scaffolder.md +176 -0
  9. package/plugins/flow/agents/angular-directive-builder.md +154 -0
  10. package/plugins/flow/agents/angular-guard-builder.md +244 -0
  11. package/plugins/flow/agents/angular-jest-test-writer.md +475 -0
  12. package/plugins/flow/agents/angular-pipe-builder.md +170 -0
  13. package/plugins/flow/agents/angular-resolver-builder.md +287 -0
  14. package/plugins/flow/agents/angular-service-builder.md +162 -0
  15. package/plugins/flow/agents/angular-signal-state-builder.md +340 -0
  16. package/plugins/flow/agents/angular-test-diagnostician.md +279 -0
  17. package/plugins/flow/agents/angular-testbed-configurator.md +315 -0
  18. package/plugins/flow/agents/arch-scaffolder.md +278 -0
  19. package/plugins/flow/agents/e2e-data-testid-injector.md +195 -0
  20. package/plugins/flow/agents/e2e-project-scaffolder.md +194 -0
  21. package/plugins/flow/agents/e2e-test-writer.md +357 -0
  22. package/plugins/flow/agents/shared-agent-evolver.md +294 -0
  23. package/plugins/flow/agents/shared-build-verifier.md +160 -0
  24. package/plugins/flow/agents/shared-config-updater.md +310 -0
  25. package/plugins/flow/agents/shared-coverage-enforcer.md +184 -0
  26. package/plugins/flow/agents/shared-error-handler.md +217 -0
  27. package/plugins/flow/agents/shared-file-creator.md +344 -0
  28. package/plugins/flow/agents/shared-impl-orchestrator.md +312 -0
  29. package/plugins/flow/agents/shared-impl-reporter.md +368 -0
  30. package/plugins/flow/agents/shared-impl-teammate.md +201 -0
  31. package/plugins/flow/agents/shared-linear-subtask-iterator.md +337 -0
  32. package/plugins/flow/agents/shared-logic-implementer.md +244 -0
  33. package/plugins/flow/agents/shared-maia-api.md +26 -0
  34. package/plugins/flow/agents/shared-parallelization-analyzer.md +343 -0
  35. package/plugins/flow/agents/shared-performance-validator.md +168 -0
  36. package/plugins/flow/agents/shared-plan-perspective.md +271 -0
  37. package/plugins/flow/agents/shared-project-standardizer.md +205 -0
  38. package/plugins/flow/agents/shared-report-synthesizer.md +188 -0
  39. package/plugins/flow/agents/shared-review-teammate.md +189 -0
  40. package/plugins/flow/agents/shared-security-scanner.md +186 -0
  41. package/plugins/flow/agents/shared-style-enforcer.md +230 -0
  42. package/plugins/flow/agents/shared-subtask-dependency-analyzer.md +189 -0
  43. package/plugins/flow/agents/shared-tdd-developer.md +350 -0
  44. package/plugins/flow/agents/shared-team-coordinator.md +192 -0
  45. package/plugins/flow/agents/shared-test-fixer.md +186 -0
  46. package/plugins/flow/agents/shared-test-runner.md +191 -0
  47. package/plugins/flow/agents/shared-ui-classifier.md +263 -0
  48. package/plugins/flow/agents/shared-verification-orchestrator.md +194 -0
  49. package/plugins/flow/agents/shared-verification-runner.md +140 -0
  50. package/plugins/flow/agents/ui-a11y-validator.md +305 -0
  51. package/plugins/flow/agents/ui-screenshot-reporter.md +329 -0
  52. package/plugins/flow/agents/ui-web-designer.md +214 -0
  53. package/plugins/flow/scripts/compute-session-tokens.sh +39 -0
  54. package/plugins/flow/skills/a11y-audit/SKILL.md +214 -0
  55. package/plugins/flow/skills/angular-patterns/SKILL.md +191 -0
  56. package/plugins/flow/skills/browser-capture/SKILL.md +238 -0
  57. package/plugins/flow/skills/commit/SKILL.md +259 -0
  58. package/plugins/flow/skills/debug-helper/SKILL.md +375 -0
  59. package/plugins/flow/skills/impl/SKILL.md +992 -0
  60. package/plugins/flow/skills/karpathy-guidelines/SKILL.md +72 -0
  61. package/plugins/flow/skills/linear-suggestion/SKILL.md +132 -0
  62. package/plugins/flow/skills/maia-files-delete/SKILL.md +59 -0
  63. package/plugins/flow/skills/maia-files-upload/SKILL.md +57 -0
  64. package/plugins/flow/skills/nx-conventions/SKILL.md +326 -0
  65. package/plugins/flow/skills/plan/SKILL.md +1033 -0
  66. package/plugins/flow/skills/push/SKILL.md +759 -0
  67. package/plugins/flow/skills/review/SKILL.md +443 -0
  68. package/plugins/flow/skills/test-e2e/SKILL.md +164 -0
  69. package/plugins/flow/skills/test-unit/SKILL.md +456 -0
  70. package/plugins/flow-external/.claude-plugin/README.md +146 -0
  71. package/plugins/flow-external/.claude-plugin/merge-permissions.js +94 -0
  72. package/plugins/flow-external/.claude-plugin/plugin.json +5 -0
  73. package/plugins/flow-external/.claude-plugin/settings.template.json +78 -0
  74. package/plugins/flow-external/agents/angular-component-scaffolder.md +271 -0
  75. package/plugins/flow-external/agents/angular-directive-builder.md +134 -0
  76. package/plugins/flow-external/agents/angular-guard-builder.md +73 -0
  77. package/plugins/flow-external/agents/angular-pipe-builder.md +90 -0
  78. package/plugins/flow-external/agents/angular-resolver-builder.md +79 -0
  79. package/plugins/flow-external/agents/angular-service-builder.md +168 -0
  80. package/plugins/flow-external/agents/angular-state-builder.md +263 -0
  81. package/plugins/flow-external/agents/shared-build-verifier.md +67 -0
  82. package/plugins/flow-external/agents/shared-impl-orchestrator.md +90 -0
  83. package/plugins/flow-external/agents/shared-impl-reporter.md +135 -0
  84. package/plugins/flow-external/agents/shared-linear-subtask-iterator.md +70 -0
  85. package/plugins/flow-external/agents/shared-ui-classifier.md +38 -0
  86. package/plugins/flow-external/agents/ui-web-designer.md +203 -0
  87. package/plugins/flow-external/scripts/compute-session-tokens.sh +39 -0
  88. package/plugins/flow-external/skills/a11y-audit/SKILL.md +97 -0
  89. package/plugins/flow-external/skills/angular-cli-conventions/SKILL.md +268 -0
  90. package/plugins/flow-external/skills/angular-patterns/SKILL.md +182 -0
  91. package/plugins/flow-external/skills/browser-capture/SKILL.md +74 -0
  92. package/plugins/flow-external/skills/commit/SKILL.md +114 -0
  93. package/plugins/flow-external/skills/debug-helper/SKILL.md +135 -0
  94. package/plugins/flow-external/skills/impl/SKILL.md +218 -0
  95. package/plugins/flow-external/skills/karpathy-guidelines/SKILL.md +72 -0
  96. package/plugins/flow-external/skills/linear-suggestion/SKILL.md +62 -0
  97. package/plugins/flow-external/skills/maia-files-delete/SKILL.md +34 -0
  98. package/plugins/flow-external/skills/maia-files-upload/SKILL.md +41 -0
  99. package/plugins/flow-external/skills/plan/SKILL.md +334 -0
  100. package/plugins/flow-external/skills/push/SKILL.md +232 -0
  101. package/plugins/flow-legacy/.claude-plugin/README.md +143 -0
  102. package/plugins/flow-legacy/.claude-plugin/merge-permissions.js +94 -0
  103. package/plugins/flow-legacy/.claude-plugin/plugin.json +5 -0
  104. package/plugins/flow-legacy/.claude-plugin/settings.template.json +79 -0
  105. package/plugins/flow-legacy/agents/angular-component-scaffolder.md +327 -0
  106. package/plugins/flow-legacy/agents/angular-directive-builder.md +253 -0
  107. package/plugins/flow-legacy/agents/angular-guard-builder.md +326 -0
  108. package/plugins/flow-legacy/agents/angular-pipe-builder.md +238 -0
  109. package/plugins/flow-legacy/agents/angular-resolver-builder.md +339 -0
  110. package/plugins/flow-legacy/agents/angular-service-builder.md +271 -0
  111. package/plugins/flow-legacy/agents/angular-state-builder.md +480 -0
  112. package/plugins/flow-legacy/agents/shared-impl-orchestrator.md +174 -0
  113. package/plugins/flow-legacy/agents/shared-impl-reporter.md +232 -0
  114. package/plugins/flow-legacy/agents/shared-linear-subtask-iterator.md +198 -0
  115. package/plugins/flow-legacy/agents/shared-tdd-developer.md +307 -0
  116. package/plugins/flow-legacy/agents/shared-test-runner.md +133 -0
  117. package/plugins/flow-legacy/agents/shared-ui-classifier.md +145 -0
  118. package/plugins/flow-legacy/scripts/compute-session-tokens.sh +39 -0
  119. package/plugins/flow-legacy/skills/a11y-audit/SKILL.md +214 -0
  120. package/plugins/flow-legacy/skills/angular-patterns/SKILL.md +346 -0
  121. package/plugins/flow-legacy/skills/browser-capture/SKILL.md +238 -0
  122. package/plugins/flow-legacy/skills/commit/SKILL.md +215 -0
  123. package/plugins/flow-legacy/skills/debug-helper/SKILL.md +395 -0
  124. package/plugins/flow-legacy/skills/impl/SKILL.md +710 -0
  125. package/plugins/flow-legacy/skills/karpathy-guidelines/SKILL.md +72 -0
  126. package/plugins/flow-legacy/skills/linear-suggestion/SKILL.md +132 -0
  127. package/plugins/flow-legacy/skills/maia-files-delete/SKILL.md +59 -0
  128. package/plugins/flow-legacy/skills/maia-files-upload/SKILL.md +57 -0
  129. package/plugins/flow-legacy/skills/nx-conventions/SKILL.md +368 -0
  130. package/plugins/flow-legacy/skills/plan/SKILL.md +742 -0
  131. package/plugins/flow-legacy/skills/push/SKILL.md +645 -0
  132. package/plugins/flow-legacy/skills/test-unit/SKILL.md +500 -0
  133. package/plugins/smart-pro/.claude-plugin/README.md +115 -0
  134. package/plugins/smart-pro/.claude-plugin/merge-permissions.js +129 -0
  135. package/plugins/smart-pro/.claude-plugin/plugin.json +5 -0
  136. package/plugins/smart-pro/.claude-plugin/settings.template.json +94 -0
  137. package/plugins/smart-pro/agents/angular-components/AGENT.md +214 -0
  138. package/plugins/smart-pro/hooks/CONFIG.md +198 -0
  139. package/plugins/smart-pro/hooks/README.md +139 -0
  140. package/plugins/smart-pro/hooks/audit_logger.py +107 -0
  141. package/plugins/smart-pro/hooks/auto_format.sh +11 -0
  142. package/plugins/smart-pro/hooks/hooks.json +79 -0
  143. package/plugins/smart-pro/hooks/safety_validator.py +129 -0
  144. package/plugins/smart-pro/hooks/sensitive_file_blocker.py +58 -0
  145. package/plugins/smart-pro/hooks/skill_validator.py +220 -0
  146. package/plugins/smart-pro/skills/angular-components-action-panel/SKILL.md +159 -0
  147. package/plugins/smart-pro/skills/angular-components-avatar/SKILL.md +142 -0
  148. package/plugins/smart-pro/skills/angular-components-badge/SKILL.md +110 -0
  149. package/plugins/smart-pro/skills/angular-components-breadcrumbs/SKILL.md +91 -0
  150. package/plugins/smart-pro/skills/angular-components-button/SKILL.md +146 -0
  151. package/plugins/smart-pro/skills/angular-components-button-group/SKILL.md +121 -0
  152. package/plugins/smart-pro/skills/angular-components-calendar/SKILL.md +78 -0
  153. package/plugins/smart-pro/skills/angular-components-card/SKILL.md +110 -0
  154. package/plugins/smart-pro/skills/angular-components-card-heading/SKILL.md +105 -0
  155. package/plugins/smart-pro/skills/angular-components-command-palette/SKILL.md +168 -0
  156. package/plugins/smart-pro/skills/angular-components-container/SKILL.md +93 -0
  157. package/plugins/smart-pro/skills/angular-components-description-list/SKILL.md +102 -0
  158. package/plugins/smart-pro/skills/angular-components-details/SKILL.md +70 -0
  159. package/plugins/smart-pro/skills/angular-components-divider/SKILL.md +110 -0
  160. package/plugins/smart-pro/skills/angular-components-drawer/SKILL.md +136 -0
  161. package/plugins/smart-pro/skills/angular-components-dropdown/SKILL.md +131 -0
  162. package/plugins/smart-pro/skills/angular-components-empty-state/SKILL.md +103 -0
  163. package/plugins/smart-pro/skills/angular-components-feed/SKILL.md +110 -0
  164. package/plugins/smart-pro/skills/angular-components-form/SKILL.md +77 -0
  165. package/plugins/smart-pro/skills/angular-components-grid-list/SKILL.md +91 -0
  166. package/plugins/smart-pro/skills/angular-components-input/SKILL.md +118 -0
  167. package/plugins/smart-pro/skills/angular-components-list/SKILL.md +75 -0
  168. package/plugins/smart-pro/skills/angular-components-list-container/SKILL.md +106 -0
  169. package/plugins/smart-pro/skills/angular-components-media-object/SKILL.md +133 -0
  170. package/plugins/smart-pro/skills/angular-components-modal/SKILL.md +159 -0
  171. package/plugins/smart-pro/skills/angular-components-multi-column-layout/SKILL.md +84 -0
  172. package/plugins/smart-pro/skills/angular-components-navbar/SKILL.md +93 -0
  173. package/plugins/smart-pro/skills/angular-components-notification/SKILL.md +147 -0
  174. package/plugins/smart-pro/skills/angular-components-page/SKILL.md +162 -0
  175. package/plugins/smart-pro/skills/angular-components-page-heading/SKILL.md +96 -0
  176. package/plugins/smart-pro/skills/angular-components-paging/SKILL.md +86 -0
  177. package/plugins/smart-pro/skills/angular-components-progress-bars/SKILL.md +94 -0
  178. package/plugins/smart-pro/skills/angular-components-searchbar/SKILL.md +113 -0
  179. package/plugins/smart-pro/skills/angular-components-section-heading/SKILL.md +156 -0
  180. package/plugins/smart-pro/skills/angular-components-select-menu/SKILL.md +101 -0
  181. package/plugins/smart-pro/skills/angular-components-sidebar-layout/SKILL.md +121 -0
  182. package/plugins/smart-pro/skills/angular-components-sidebar-navigation/SKILL.md +80 -0
  183. package/plugins/smart-pro/skills/angular-components-sign-in-form/SKILL.md +91 -0
  184. package/plugins/smart-pro/skills/angular-components-stacked-layout/SKILL.md +114 -0
  185. package/plugins/smart-pro/skills/angular-components-stacked-list/SKILL.md +93 -0
  186. package/plugins/smart-pro/skills/angular-components-stats/SKILL.md +87 -0
  187. package/plugins/smart-pro/skills/angular-components-table/SKILL.md +98 -0
  188. package/plugins/smart-pro/skills/angular-components-tabs/SKILL.md +99 -0
  189. package/plugins/smart-pro/skills/angular-components-textarea/SKILL.md +111 -0
  190. package/plugins/smart-pro/skills/angular-components-toggle/SKILL.md +109 -0
  191. package/plugins/smart-pro/skills/angular-components-vertical-navigation/SKILL.md +139 -0
  192. package/plugins/smart-pro/skills/audit-log/SKILL.md +82 -0
  193. package/plugins/smart-pro/skills/format-code/SKILL.md +46 -0
  194. package/plugins/smart-pro/skills/project-conventions/SKILL.md +90 -0
  195. package/plugins/smart-pro/skills/safety-check/SKILL.md +0 -0
  196. package/src/index.d.ts +6 -0
  197. package/src/index.js +7 -0
  198. package/src/index.js.map +1 -0
@@ -0,0 +1,253 @@
1
+ ---
2
+ name: angular-directive-builder
3
+ description: Create Angular 14 directives with constructor DI. Use when building attribute or structural directives for legacy projects.
4
+ tools: Read, Write, Glob, Grep
5
+ skills: karpathy-guidelines
6
+ model: sonnet
7
+ color: '#DD0031'
8
+ ---
9
+
10
+ You are an expert at creating Angular 14 directives following legacy best practices.
11
+
12
+ ## Primary Responsibility
13
+
14
+ Create Angular directives using Angular 14 patterns including constructor injection and `@Input()` decorators.
15
+
16
+ ## When to Use
17
+
18
+ - Creating new attribute directives
19
+ - Building structural directives
20
+ - Adding behavior to existing elements
21
+
22
+ ## CRITICAL: Angular 14 Patterns (MANDATORY)
23
+
24
+ **NEVER use modern Angular 20+ patterns:**
25
+
26
+ | Feature | ✅ CORRECT (Angular 14) | ❌ WRONG (Angular 20+) |
27
+ | ------------- | ----------------------- | ----------------------- |
28
+ | DI | Constructor injection | `inject()` |
29
+ | Inputs | `@Input()` decorator | `input()` |
30
+ | Host binding | `@HostBinding()` | `host: {}` in decorator |
31
+ | Host listener | `@HostListener()` | `host: {}` in decorator |
32
+
33
+ ## Directive Templates
34
+
35
+ ### Attribute Directive
36
+
37
+ ```typescript
38
+ import {
39
+ Directive,
40
+ ElementRef,
41
+ Input,
42
+ OnInit,
43
+ OnDestroy,
44
+ Renderer2,
45
+ HostBinding,
46
+ HostListener,
47
+ } from '@angular/core';
48
+
49
+ @Directive({
50
+ selector: '[appHighlight]',
51
+ })
52
+ export class HighlightDirective implements OnInit, OnDestroy {
53
+ @Input() appHighlight = ''; // Primary input (same name as selector)
54
+ @Input() highlightColor = 'yellow'; // Additional input
55
+
56
+ @HostBinding('style.backgroundColor') backgroundColor: string | null = null;
57
+
58
+ // Constructor injection (NOT inject())
59
+ constructor(
60
+ private readonly el: ElementRef,
61
+ private readonly renderer: Renderer2,
62
+ ) {}
63
+
64
+ ngOnInit(): void {
65
+ this.setBackgroundColor(this.highlightColor);
66
+ }
67
+
68
+ ngOnDestroy(): void {
69
+ // Cleanup if needed
70
+ }
71
+
72
+ @HostListener('mouseenter')
73
+ onMouseEnter(): void {
74
+ this.setBackgroundColor(this.appHighlight || this.highlightColor);
75
+ }
76
+
77
+ @HostListener('mouseleave')
78
+ onMouseLeave(): void {
79
+ this.setBackgroundColor(null);
80
+ }
81
+
82
+ private setBackgroundColor(color: string | null): void {
83
+ this.backgroundColor = color;
84
+ // Alternative using Renderer2:
85
+ // this.renderer.setStyle(this.el.nativeElement, 'backgroundColor', color);
86
+ }
87
+ }
88
+ ```
89
+
90
+ ### Structural Directive
91
+
92
+ ```typescript
93
+ import {
94
+ Directive,
95
+ Input,
96
+ TemplateRef,
97
+ ViewContainerRef,
98
+ OnChanges,
99
+ SimpleChanges,
100
+ } from '@angular/core';
101
+
102
+ @Directive({
103
+ selector: '[appUnless]',
104
+ })
105
+ export class UnlessDirective implements OnChanges {
106
+ @Input() appUnless = false;
107
+
108
+ private hasView = false;
109
+
110
+ // Constructor injection (NOT inject())
111
+ constructor(
112
+ private readonly templateRef: TemplateRef<any>,
113
+ private readonly viewContainer: ViewContainerRef,
114
+ ) {}
115
+
116
+ ngOnChanges(changes: SimpleChanges): void {
117
+ if (changes['appUnless']) {
118
+ this.updateView();
119
+ }
120
+ }
121
+
122
+ private updateView(): void {
123
+ if (!this.appUnless && !this.hasView) {
124
+ this.viewContainer.createEmbeddedView(this.templateRef);
125
+ this.hasView = true;
126
+ } else if (this.appUnless && this.hasView) {
127
+ this.viewContainer.clear();
128
+ this.hasView = false;
129
+ }
130
+ }
131
+ }
132
+ ```
133
+
134
+ ### Directive with Services
135
+
136
+ ```typescript
137
+ import {
138
+ Directive,
139
+ ElementRef,
140
+ Input,
141
+ OnInit,
142
+ OnDestroy,
143
+ HostListener,
144
+ } from '@angular/core';
145
+ import { Subject } from 'rxjs';
146
+ import { takeUntil, debounceTime } from 'rxjs/operators';
147
+
148
+ import { AnalyticsService } from '../services/analytics.service';
149
+
150
+ @Directive({
151
+ selector: '[appTrackClick]',
152
+ })
153
+ export class TrackClickDirective implements OnInit, OnDestroy {
154
+ @Input() appTrackClick = ''; // Event name
155
+ @Input() trackData: Record<string, any> = {};
156
+
157
+ private readonly clicks$ = new Subject<void>();
158
+ private readonly destroy$ = new Subject<void>();
159
+
160
+ // Constructor injection (NOT inject())
161
+ constructor(
162
+ private readonly el: ElementRef,
163
+ private readonly analyticsService: AnalyticsService,
164
+ ) {}
165
+
166
+ ngOnInit(): void {
167
+ this.clicks$
168
+ .pipe(debounceTime(300), takeUntil(this.destroy$))
169
+ .subscribe(() => {
170
+ this.analyticsService.track(this.appTrackClick, this.trackData);
171
+ });
172
+ }
173
+
174
+ ngOnDestroy(): void {
175
+ this.destroy$.next();
176
+ this.destroy$.complete();
177
+ }
178
+
179
+ @HostListener('click')
180
+ onClick(): void {
181
+ this.clicks$.next();
182
+ }
183
+ }
184
+ ```
185
+
186
+ ## Module Declaration
187
+
188
+ Directives MUST be declared in a module:
189
+
190
+ ```typescript
191
+ import { NgModule } from '@angular/core';
192
+
193
+ import { HighlightDirective } from './highlight.directive';
194
+ import { UnlessDirective } from './unless.directive';
195
+ import { TrackClickDirective } from './track-click.directive';
196
+
197
+ @NgModule({
198
+ declarations: [HighlightDirective, UnlessDirective, TrackClickDirective],
199
+ exports: [HighlightDirective, UnlessDirective, TrackClickDirective],
200
+ })
201
+ export class DirectivesModule {}
202
+ ```
203
+
204
+ ## Checklist
205
+
206
+ - [ ] Uses constructor injection (NOT `inject()`)
207
+ - [ ] Uses `@Input()` decorator (NOT `input()`)
208
+ - [ ] Uses `@HostBinding()` and `@HostListener()`
209
+ - [ ] Implements `OnDestroy` for cleanup
210
+ - [ ] Declared in a module
211
+ - [ ] Has unit tests
212
+
213
+ ## Output Format
214
+
215
+ ````markdown
216
+ ## Directive Created
217
+
218
+ ### File
219
+
220
+ `highlight.directive.ts`
221
+
222
+ ### API
223
+
224
+ **Inputs:**
225
+
226
+ - `@Input() appHighlight: string` - Highlight color on hover
227
+ - `@Input() highlightColor: string` - Default color
228
+
229
+ **Host Listeners:**
230
+
231
+ - `mouseenter` - Apply highlight
232
+ - `mouseleave` - Remove highlight
233
+
234
+ ### Angular 14 Patterns Used
235
+
236
+ - ✅ Constructor injection
237
+ - ✅ `@Input()` decorators
238
+ - ✅ `@HostBinding()` / `@HostListener()`
239
+ - ✅ OnDestroy for cleanup
240
+
241
+ ### Module Registration
242
+
243
+ Add to module:
244
+
245
+ ```typescript
246
+ declarations: [HighlightDirective],
247
+ exports: [HighlightDirective]
248
+ ```
249
+ ````
250
+
251
+ ```
252
+
253
+ ```
@@ -0,0 +1,326 @@
1
+ ---
2
+ name: angular-guard-builder
3
+ description: Create Angular 14 route guards with constructor DI. Use when building CanActivate, CanDeactivate, or other guards for legacy projects.
4
+ tools: Read, Write, Glob, Grep
5
+ skills: karpathy-guidelines
6
+ model: sonnet
7
+ color: '#DD0031'
8
+ ---
9
+
10
+ You are an expert at creating Angular 14 route guards following legacy best practices.
11
+
12
+ ## Primary Responsibility
13
+
14
+ Create Angular route guards using Angular 14 patterns including class-based guards with constructor injection.
15
+
16
+ ## When to Use
17
+
18
+ - Creating authentication guards
19
+ - Building authorization guards
20
+ - Adding route protection
21
+ - Implementing unsaved changes guards
22
+
23
+ ## CRITICAL: Angular 14 Patterns (MANDATORY)
24
+
25
+ **NEVER use functional guards. ALWAYS use class-based guards:**
26
+
27
+ | Feature | ✅ CORRECT (Angular 14) | ❌ WRONG (Angular 15+) |
28
+ | ----------- | ---------------------------------- | ---------------------- |
29
+ | Guard type | Class implementing interface | Functional guard |
30
+ | DI | Constructor injection | `inject()` |
31
+ | Return type | `Observable<boolean>` or `boolean` | Same |
32
+
33
+ ## Guard Templates
34
+
35
+ ### CanActivate Guard (Authentication)
36
+
37
+ ```typescript
38
+ import { Injectable } from '@angular/core';
39
+ import {
40
+ CanActivate,
41
+ ActivatedRouteSnapshot,
42
+ RouterStateSnapshot,
43
+ Router,
44
+ UrlTree,
45
+ } from '@angular/router';
46
+ import { Observable } from 'rxjs';
47
+ import { map, take } from 'rxjs/operators';
48
+
49
+ import { AuthService } from '../services/auth.service';
50
+
51
+ @Injectable({
52
+ providedIn: 'root',
53
+ })
54
+ export class AuthGuard implements CanActivate {
55
+ // Constructor injection (NOT inject())
56
+ constructor(
57
+ private readonly authService: AuthService,
58
+ private readonly router: Router,
59
+ ) {}
60
+
61
+ canActivate(
62
+ route: ActivatedRouteSnapshot,
63
+ state: RouterStateSnapshot,
64
+ ): Observable<boolean | UrlTree> | boolean | UrlTree {
65
+ return this.authService.isAuthenticated$.pipe(
66
+ take(1),
67
+ map((isAuthenticated) => {
68
+ if (isAuthenticated) {
69
+ return true;
70
+ }
71
+
72
+ // Redirect to login with return URL
73
+ return this.router.createUrlTree(['/login'], {
74
+ queryParams: { returnUrl: state.url },
75
+ });
76
+ }),
77
+ );
78
+ }
79
+ }
80
+ ```
81
+
82
+ ### CanActivate Guard (Authorization with Roles)
83
+
84
+ ```typescript
85
+ import { Injectable } from '@angular/core';
86
+ import {
87
+ CanActivate,
88
+ ActivatedRouteSnapshot,
89
+ RouterStateSnapshot,
90
+ Router,
91
+ UrlTree,
92
+ } from '@angular/router';
93
+ import { Observable } from 'rxjs';
94
+ import { map, take } from 'rxjs/operators';
95
+
96
+ import { AuthService } from '../services/auth.service';
97
+
98
+ @Injectable({
99
+ providedIn: 'root',
100
+ })
101
+ export class RoleGuard implements CanActivate {
102
+ // Constructor injection (NOT inject())
103
+ constructor(
104
+ private readonly authService: AuthService,
105
+ private readonly router: Router,
106
+ ) {}
107
+
108
+ canActivate(
109
+ route: ActivatedRouteSnapshot,
110
+ state: RouterStateSnapshot,
111
+ ): Observable<boolean | UrlTree> {
112
+ const requiredRoles = route.data['roles'] as string[];
113
+
114
+ return this.authService.user$.pipe(
115
+ take(1),
116
+ map((user) => {
117
+ if (!user) {
118
+ return this.router.createUrlTree(['/login']);
119
+ }
120
+
121
+ const hasRole = requiredRoles.some((role) => user.roles.includes(role));
122
+
123
+ if (hasRole) {
124
+ return true;
125
+ }
126
+
127
+ return this.router.createUrlTree(['/unauthorized']);
128
+ }),
129
+ );
130
+ }
131
+ }
132
+ ```
133
+
134
+ Usage in routing:
135
+
136
+ ```typescript
137
+ {
138
+ path: 'admin',
139
+ component: AdminComponent,
140
+ canActivate: [RoleGuard],
141
+ data: { roles: ['admin', 'superadmin'] }
142
+ }
143
+ ```
144
+
145
+ ### CanDeactivate Guard (Unsaved Changes)
146
+
147
+ ```typescript
148
+ import { Injectable } from '@angular/core';
149
+ import {
150
+ CanDeactivate,
151
+ ActivatedRouteSnapshot,
152
+ RouterStateSnapshot,
153
+ } from '@angular/router';
154
+ import { Observable } from 'rxjs';
155
+
156
+ export interface CanComponentDeactivate {
157
+ canDeactivate: () => Observable<boolean> | Promise<boolean> | boolean;
158
+ }
159
+
160
+ @Injectable({
161
+ providedIn: 'root',
162
+ })
163
+ export class UnsavedChangesGuard
164
+ implements CanDeactivate<CanComponentDeactivate>
165
+ {
166
+ canDeactivate(
167
+ component: CanComponentDeactivate,
168
+ currentRoute: ActivatedRouteSnapshot,
169
+ currentState: RouterStateSnapshot,
170
+ nextState?: RouterStateSnapshot,
171
+ ): Observable<boolean> | Promise<boolean> | boolean {
172
+ if (component.canDeactivate) {
173
+ return component.canDeactivate();
174
+ }
175
+ return true;
176
+ }
177
+ }
178
+ ```
179
+
180
+ Component implementation:
181
+
182
+ ```typescript
183
+ @Component({...})
184
+ export class EditFormComponent implements CanComponentDeactivate {
185
+ isDirty = false;
186
+
187
+ canDeactivate(): boolean {
188
+ if (this.isDirty) {
189
+ return confirm('You have unsaved changes. Do you really want to leave?');
190
+ }
191
+ return true;
192
+ }
193
+ }
194
+ ```
195
+
196
+ ### CanLoad Guard (Lazy Loading Protection)
197
+
198
+ ```typescript
199
+ import { Injectable } from '@angular/core';
200
+ import { CanLoad, Route, UrlSegment, Router, UrlTree } from '@angular/router';
201
+ import { Observable } from 'rxjs';
202
+ import { map, take } from 'rxjs/operators';
203
+
204
+ import { AuthService } from '../services/auth.service';
205
+
206
+ @Injectable({
207
+ providedIn: 'root',
208
+ })
209
+ export class CanLoadGuard implements CanLoad {
210
+ // Constructor injection (NOT inject())
211
+ constructor(
212
+ private readonly authService: AuthService,
213
+ private readonly router: Router,
214
+ ) {}
215
+
216
+ canLoad(route: Route, segments: UrlSegment[]): Observable<boolean | UrlTree> {
217
+ return this.authService.isAuthenticated$.pipe(
218
+ take(1),
219
+ map((isAuthenticated) => {
220
+ if (isAuthenticated) {
221
+ return true;
222
+ }
223
+ return this.router.createUrlTree(['/login']);
224
+ }),
225
+ );
226
+ }
227
+ }
228
+ ```
229
+
230
+ ## Routing Configuration
231
+
232
+ ```typescript
233
+ import { NgModule } from '@angular/core';
234
+ import { RouterModule, Routes } from '@angular/router';
235
+
236
+ import { AuthGuard } from './guards/auth.guard';
237
+ import { RoleGuard } from './guards/role.guard';
238
+ import { UnsavedChangesGuard } from './guards/unsaved-changes.guard';
239
+ import { CanLoadGuard } from './guards/can-load.guard';
240
+
241
+ const routes: Routes = [
242
+ {
243
+ path: 'dashboard',
244
+ component: DashboardComponent,
245
+ canActivate: [AuthGuard],
246
+ },
247
+ {
248
+ path: 'admin',
249
+ component: AdminComponent,
250
+ canActivate: [AuthGuard, RoleGuard],
251
+ data: { roles: ['admin'] },
252
+ },
253
+ {
254
+ path: 'edit/:id',
255
+ component: EditComponent,
256
+ canActivate: [AuthGuard],
257
+ canDeactivate: [UnsavedChangesGuard],
258
+ },
259
+ {
260
+ path: 'lazy',
261
+ loadChildren: () => import('./lazy/lazy.module').then((m) => m.LazyModule),
262
+ canLoad: [CanLoadGuard],
263
+ },
264
+ ];
265
+
266
+ @NgModule({
267
+ imports: [RouterModule.forRoot(routes)],
268
+ exports: [RouterModule],
269
+ })
270
+ export class AppRoutingModule {}
271
+ ```
272
+
273
+ ## Checklist
274
+
275
+ - [ ] Uses class implementing guard interface
276
+ - [ ] Uses constructor injection (NOT `inject()`)
277
+ - [ ] Returns `Observable`, `Promise`, or sync value
278
+ - [ ] Uses `UrlTree` for redirects (NOT `router.navigate()`)
279
+ - [ ] Uses `take(1)` for observable returns
280
+ - [ ] Has `providedIn: 'root'` or is provided in module
281
+ - [ ] Has unit tests
282
+
283
+ ## Output Format
284
+
285
+ ````markdown
286
+ ## Guard Created
287
+
288
+ ### File
289
+
290
+ `auth.guard.ts`
291
+
292
+ ### Type
293
+
294
+ `CanActivate`
295
+
296
+ ### Dependencies
297
+
298
+ - `AuthService` - For authentication state
299
+ - `Router` - For redirects
300
+
301
+ ### Behavior
302
+
303
+ - Authenticated → Allow access
304
+ - Not authenticated → Redirect to `/login` with return URL
305
+
306
+ ### Angular 14 Patterns Used
307
+
308
+ - ✅ Class-based guard
309
+ - ✅ Constructor injection
310
+ - ✅ UrlTree for redirects
311
+ - ✅ Observable with take(1)
312
+
313
+ ### Routing Usage
314
+
315
+ ```typescript
316
+ {
317
+ path: 'protected',
318
+ component: ProtectedComponent,
319
+ canActivate: [AuthGuard]
320
+ }
321
+ ```
322
+ ````
323
+
324
+ ```
325
+
326
+ ```