@code-sentinel-cli/code-sentinel-cli 3.0.3 → 3.0.4

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 (129) hide show
  1. package/README.md +1 -1
  2. package/dist/bin.js +1184 -809
  3. package/dist/builtin-rules/ai/angular/api-service-contract-risk.prompt.md +71 -0
  4. package/dist/builtin-rules/ai/angular/api-service-contract-risk.rule.yaml +22 -0
  5. package/dist/builtin-rules/ai/angular/component-state-flow.prompt.md +79 -0
  6. package/dist/builtin-rules/ai/angular/component-state-flow.rule.yaml +26 -0
  7. package/dist/builtin-rules/ai/angular/cross-feature-api-drift.prompt.md +70 -0
  8. package/dist/builtin-rules/ai/angular/cross-feature-api-drift.rule.yaml +42 -0
  9. package/dist/builtin-rules/ai/angular/cross-feature-route-permission-drift.prompt.md +73 -0
  10. package/dist/builtin-rules/ai/angular/cross-feature-route-permission-drift.rule.yaml +50 -0
  11. package/dist/builtin-rules/ai/angular/reactive-form-flow.prompt.md +82 -0
  12. package/dist/builtin-rules/ai/angular/reactive-form-flow.rule.yaml +23 -0
  13. package/dist/builtin-rules/ai/angular/route-permission-flow.prompt.md +80 -0
  14. package/dist/builtin-rules/ai/angular/route-permission-flow.rule.yaml +23 -0
  15. package/dist/builtin-rules/ai/angular/rxjs-flow-risk.prompt.md +82 -0
  16. package/dist/builtin-rules/ai/angular/rxjs-flow-risk.rule.yaml +24 -0
  17. package/dist/builtin-rules/ai/angular/template-contract-risk.prompt.md +80 -0
  18. package/dist/builtin-rules/ai/angular/template-contract-risk.rule.yaml +25 -0
  19. package/dist/builtin-rules/ai/flutter/dynamic-content-risk.prompt.md +55 -0
  20. package/dist/builtin-rules/ai/flutter/dynamic-content-risk.rule.yaml +18 -0
  21. package/dist/builtin-rules/ai/flutter/feature-state-flow-risk.prompt.md +58 -0
  22. package/dist/builtin-rules/ai/flutter/feature-state-flow-risk.rule.yaml +18 -0
  23. package/dist/builtin-rules/ai/flutter/native-platform-consistency-risk.prompt.md +56 -0
  24. package/dist/builtin-rules/ai/flutter/native-platform-consistency-risk.rule.yaml +18 -0
  25. package/dist/builtin-rules/ai/flutter/network-auth-flow-risk.prompt.md +57 -0
  26. package/dist/builtin-rules/ai/flutter/network-auth-flow-risk.rule.yaml +19 -0
  27. package/dist/builtin-rules/ai/flutter/ui-responsive-accessibility-risk.prompt.md +60 -0
  28. package/dist/builtin-rules/ai/flutter/ui-responsive-accessibility-risk.rule.yaml +18 -0
  29. package/dist/builtin-rules/ai/general/code-clarity.prompt.md +57 -0
  30. package/dist/builtin-rules/ai/general/code-clarity.rule.yaml +20 -0
  31. package/dist/builtin-rules/ai/spring-boot/business-invariant-risk.prompt.md +86 -0
  32. package/dist/builtin-rules/ai/spring-boot/business-invariant-risk.rule.yaml +25 -0
  33. package/dist/builtin-rules/ai/spring-boot/cache-consistency-risk.prompt.md +80 -0
  34. package/dist/builtin-rules/ai/spring-boot/cache-consistency-risk.rule.yaml +25 -0
  35. package/dist/builtin-rules/ai/spring-boot/cross-feature-error-handling-drift.prompt.md +76 -0
  36. package/dist/builtin-rules/ai/spring-boot/cross-feature-error-handling-drift.rule.yaml +63 -0
  37. package/dist/builtin-rules/ai/spring-boot/cross-feature-transaction-boundary-drift.prompt.md +85 -0
  38. package/dist/builtin-rules/ai/spring-boot/cross-feature-transaction-boundary-drift.rule.yaml +68 -0
  39. package/dist/builtin-rules/ai/spring-boot/error-handling-completeness.prompt.md +121 -0
  40. package/dist/builtin-rules/ai/spring-boot/error-handling-completeness.rule.yaml +84 -0
  41. package/dist/builtin-rules/ai/spring-boot/event-publishing-risk.prompt.md +80 -0
  42. package/dist/builtin-rules/ai/spring-boot/event-publishing-risk.rule.yaml +25 -0
  43. package/dist/builtin-rules/ai/spring-boot/io-boundary-risk.prompt.md +78 -0
  44. package/dist/builtin-rules/ai/spring-boot/io-boundary-risk.rule.yaml +25 -0
  45. package/dist/builtin-rules/ai/spring-boot/ownership-scope-risk.prompt.md +83 -0
  46. package/dist/builtin-rules/ai/spring-boot/ownership-scope-risk.rule.yaml +25 -0
  47. package/dist/builtin-rules/ai/spring-boot/pagination-risk.prompt.md +81 -0
  48. package/dist/builtin-rules/ai/spring-boot/pagination-risk.rule.yaml +25 -0
  49. package/dist/builtin-rules/ai/spring-boot/security-authorization-risk.prompt.md +75 -0
  50. package/dist/builtin-rules/ai/spring-boot/security-authorization-risk.rule.yaml +26 -0
  51. package/dist/builtin-rules/ai/spring-boot/security-mass-assignment-risk.prompt.md +75 -0
  52. package/dist/builtin-rules/ai/spring-boot/security-mass-assignment-risk.rule.yaml +24 -0
  53. package/dist/builtin-rules/ai/spring-boot/security-redirect-risk.prompt.md +74 -0
  54. package/dist/builtin-rules/ai/spring-boot/security-redirect-risk.rule.yaml +24 -0
  55. package/dist/builtin-rules/ai/spring-boot/security-sensitive-data-risk.prompt.md +75 -0
  56. package/dist/builtin-rules/ai/spring-boot/security-sensitive-data-risk.rule.yaml +25 -0
  57. package/dist/builtin-rules/ai/spring-boot/transaction-loop-risk.prompt.md +78 -0
  58. package/dist/builtin-rules/ai/spring-boot/transaction-loop-risk.rule.yaml +25 -0
  59. package/dist/builtin-rules/static/angular/component-prefix.rule.js +78 -0
  60. package/dist/builtin-rules/static/angular/image-control-alt-required.rule.js +105 -0
  61. package/dist/builtin-rules/static/angular/img-alt-required.rule.js +96 -0
  62. package/dist/builtin-rules/static/angular/inject-pattern.rule.js +47 -0
  63. package/dist/builtin-rules/static/angular/lifecycle-method-required.rule.js +59 -0
  64. package/dist/builtin-rules/static/angular/no-any-type.rule.yaml +55 -0
  65. package/dist/builtin-rules/static/angular/no-direct-dom-access.rule.js +191 -0
  66. package/dist/builtin-rules/static/angular/no-dom-xss.rule.js +48 -0
  67. package/dist/builtin-rules/static/angular/no-leaky-subscription.rule.js +197 -0
  68. package/dist/builtin-rules/static/angular/no-ngmodule.rule.yaml +44 -0
  69. package/dist/builtin-rules/static/angular/no-non-null-asserted-optional-chain.rule.js +53 -0
  70. package/dist/builtin-rules/static/angular/no-uncalled-signal-in-condition.rule.js +112 -0
  71. package/dist/builtin-rules/static/angular/observable-naming.rule.js +85 -0
  72. package/dist/builtin-rules/static/angular/onpush-required.rule.js +70 -0
  73. package/dist/builtin-rules/static/angular/standalone-component-required.rule.js +65 -0
  74. package/dist/builtin-rules/static/angular/template-dom-xss.rule.js +112 -0
  75. package/dist/builtin-rules/static/angular/template-syntax-modern.rule.js +154 -0
  76. package/dist/builtin-rules/static/angular/trackby-required.rule.js +66 -0
  77. package/dist/builtin-rules/static/flutter/android-exported-component.rule.js +75 -0
  78. package/dist/builtin-rules/static/flutter/android-manifest-hardening.rule.js +117 -0
  79. package/dist/builtin-rules/static/flutter/android-sensitive-permissions.rule.js +87 -0
  80. package/dist/builtin-rules/static/flutter/debug-tooling-release-risk.rule.js +90 -0
  81. package/dist/builtin-rules/static/flutter/dynamic-archive-risk.rule.js +96 -0
  82. package/dist/builtin-rules/static/flutter/hive-sensitive-storage.rule.js +77 -0
  83. package/dist/builtin-rules/static/flutter/ios-privacy-hardening.rule.js +119 -0
  84. package/dist/builtin-rules/static/flutter/packaged-env-risk.rule.js +95 -0
  85. package/dist/builtin-rules/static/flutter/sensitive-log-leak.rule.js +94 -0
  86. package/dist/builtin-rules/static/flutter/webview-bridge-guard.rule.js +102 -0
  87. package/dist/builtin-rules/static/general/file-too-long.rule.js +41 -0
  88. package/dist/builtin-rules/static/general/function-too-long.rule.js +72 -0
  89. package/dist/builtin-rules/static/general/no-circular-import.rule.js +39 -0
  90. package/dist/builtin-rules/static/general/no-code-injection.rule.js +48 -0
  91. package/dist/builtin-rules/static/general/no-console-log.rule.js +110 -0
  92. package/dist/builtin-rules/static/general/no-empty-catch.rule.yaml +56 -0
  93. package/dist/builtin-rules/static/general/no-hardcoded-secret.rule.js +517 -0
  94. package/dist/builtin-rules/static/general/no-magic-number.rule.js +78 -0
  95. package/dist/builtin-rules/static/general/no-open-redirect.rule.js +46 -0
  96. package/dist/builtin-rules/static/general/no-todo-comment.rule.yaml +30 -0
  97. package/dist/builtin-rules/static/general/no-unresolved-import-symbol.rule.js +80 -0
  98. package/dist/builtin-rules/static/general/no-unused-export.rule.js +140 -0
  99. package/dist/builtin-rules/static/spring-boot/no-autowired-field.rule.js +162 -0
  100. package/dist/builtin-rules/static/spring-boot/no-business-logic-in-controller.rule.js +94 -0
  101. package/dist/builtin-rules/static/spring-boot/no-command-injection.rule.js +47 -0
  102. package/dist/builtin-rules/static/spring-boot/no-entity-in-controller.rule.yaml +52 -0
  103. package/dist/builtin-rules/static/spring-boot/no-nplus1-query-in-loop.rule.js +106 -0
  104. package/dist/builtin-rules/static/spring-boot/no-path-traversal.rule.js +47 -0
  105. package/dist/builtin-rules/static/spring-boot/no-spel-injection.rule.js +41 -0
  106. package/dist/builtin-rules/static/spring-boot/no-sql-string-concat.rule.js +194 -0
  107. package/dist/builtin-rules/static/spring-boot/no-ssrf.rule.js +49 -0
  108. package/dist/builtin-rules/static/spring-boot/no-transactional-self-invocation.rule.js +142 -0
  109. package/dist/builtin-rules/static/spring-boot/no-unclosed-resource.rule.js +108 -0
  110. package/dist/builtin-rules/static/spring-boot/no-unsafe-shared-formatter.rule.js +118 -0
  111. package/dist/builtin-rules/static/spring-boot/repository-naming.rule.yaml +42 -0
  112. package/dist/builtin-rules/static/spring-boot/restful-naming.rule.yaml +39 -0
  113. package/dist/builtin-rules/static/spring-boot/transaction-on-service.rule.yaml +58 -0
  114. package/dist/builtin-rules/static/spring-boot/validate-input.rule.js +123 -0
  115. package/dist/builtin-rules/vauthz/static/spring-boot/require-authz-check.rule.js +101 -0
  116. package/dist/index.d.ts +224 -47
  117. package/dist/index.js +1183 -808
  118. package/package.json +3 -2
  119. package/src/migrations/0000_initial.sql +62 -0
  120. package/src/migrations/0001_add_confidence.sql +7 -0
  121. package/src/migrations/0002_add_ai_stats.sql +21 -0
  122. package/src/migrations/0003_add_fix_recipe.sql +29 -0
  123. package/src/migrations/0004_add_ast_graph.sql +61 -0
  124. package/src/migrations/0005_add_project_id.sql +1 -0
  125. package/src/migrations/0006_add_ai_model.sql +5 -0
  126. package/src/migrations/0006_add_rule_results.sql +1 -0
  127. package/src/migrations/0007_add_finding_metadata.sql +4 -0
  128. package/src/migrations/0008_add_coverage.sql +2 -0
  129. package/src/migrations/0009_run_provenance.sql +5 -0
@@ -0,0 +1,71 @@
1
+ Bạn là senior Angular reviewer. Đánh giá Angular review unit dưới đây về **API service contract, interceptor context, response/error shape**.
2
+
3
+ ## CRITICAL RULES
4
+
5
+ 1. **CHỈ report lỗi có bằng chứng cụ thể** trong primary hoặc support files. Không đoán convention ngoài cluster.
6
+ 2. **`line` BẮT BUỘC trỏ về PRIMARY file**.
7
+ 3. **Confidence `<50` → KHÔNG emit**.
8
+
9
+ ## Chỉ flag khi có bug contract cụ thể
10
+
11
+ - Component/service catch error theo shape khác với API wrapper support file đang throw (`err.error.message` khi wrapper throw `ApiError.message`, hoặc ngược lại).
12
+ - User input/token/filter được nối trực tiếp vào URL query/path khi support API wrapper có params encoder hoặc `HttpParams` pattern.
13
+ - Endpoint login/captcha/refresh/reset password thiếu public/no-auth context, hoặc endpoint protected bị đánh dấu no-auth.
14
+ - Caller assume response shape (`res.content`, `res.data`, `res.url`, headers) không khớp với service method/wrapper trong cluster.
15
+ - Service expose raw `HttpClient`/baseUrl hoặc deprecated wrapper theo cách bypass interceptor/error/loading contract.
16
+
17
+ ## KHÔNG flag
18
+
19
+ - Wrapper/service đã normalize lỗi và caller đọc đúng shape.
20
+ - String endpoint cố định không chứa user input.
21
+ - Deprecated API được dùng trong wrapper chính với compatibility comment, nhưng caller bên ngoài không bypass contract.
22
+ - Không đủ evidence về service/wrapper/caller contract trong cluster.
23
+
24
+ ## Primary file
25
+
26
+ Additional non-violations:
27
+
28
+ - Building a typed request DTO/object literal in a component and passing it to a store/service method is NOT URL query/path concatenation.
29
+ - Do not report URL/path concatenation on a component line unless the primary code itself concatenates a URL/path/query string, or the support service line is the intended reported location.
30
+ - A service method returning `Observable<ArticleResponse>` (or equivalent typed response) and a store `tapResponse({ next: ({ article }) => ... })` are compatible; do not claim response-shape mismatch when the destructured property exists in the declared response type.
31
+ - String path segments such as `'/articles/' + slug` are not query-encoding bugs unless the cluster shows the value can contain unsafe path delimiters and an existing wrapper/encoder should be used instead.
32
+
33
+ File: {{file}}
34
+ Language: {{language}}
35
+
36
+ ```{{language}}
37
+ {{code}}
38
+ ```
39
+
40
+ ## Support files cùng cluster
41
+
42
+ {{cluster_summary}}
43
+
44
+ ## Output yêu cầu
45
+
46
+ Trả về **JSON HỢP LỆ DUY NHẤT** (không markdown fence, không text khác) theo schema:
47
+
48
+ ```
49
+ {
50
+ "violations": [
51
+ {
52
+ "line": <số nguyên dương, 1-based>,
53
+ "endLine": <số nguyên dương | null>,
54
+ "message": "<≤200 ký tự, tiếng Việt>",
55
+ "suggestion": "<gợi ý fix | null>",
56
+ "confidence": <số nguyên 0-100>
57
+ }
58
+ ]
59
+ }
60
+ ```
61
+
62
+ Nếu không có vấn đề rõ ràng: `{"violations": []}`.
63
+
64
+ ## REPEAT CRITICAL RULES
65
+
66
+ - `line` phải trỏ về PRIMARY file, không dùng line từ support file.
67
+ - Không duplicate static built-in rules.
68
+ - Chỉ report khi có bằng chứng cụ thể trong cluster.
69
+ - Confidence `<50` → KHÔNG emit.
70
+
71
+ Đừng giải thích. JSON thuần.
@@ -0,0 +1,22 @@
1
+ id: angular/api-service-contract-risk
2
+ version: 2
3
+ kind: ai
4
+ title: "Angular API service/error contract có rủi ro không?"
5
+ description: |
6
+ Per-cluster AI rule cho component/service/API wrapper contract:
7
+ - Caller đọc sai error shape (`err.error.message` vs `ApiError.message`) so
8
+ với wrapper/interceptor đang throw.
9
+ - Query string nối tay từ user input/token thay vì dùng params encoder.
10
+ - Endpoint public/auth dùng sai auth context hoặc service dùng deprecated/raw
11
+ HTTP surface làm bypass interceptor.
12
+ - Response body được assume shape khác service/API wrapper mô tả.
13
+ severity: warning
14
+ category: angular-api
15
+ languages: [typescript]
16
+ scope: angular
17
+ baseConfidence: 60
18
+ prompt: ./api-service-contract-risk.prompt.md
19
+ contextScope: per-cluster
20
+ maxTokens: 1600
21
+ aiConfig:
22
+ tier: regular
@@ -0,0 +1,79 @@
1
+ Bạn là senior Angular reviewer. Đánh giá Angular review unit dưới đây về **state flow và change detection**.
2
+
3
+ ## CRITICAL RULES
4
+
5
+ CRITICAL NON-VIOLATIONS:
6
+
7
+ - NEVER report `form.patchValue(...)`, `form.reset()`, `form.getRawValue()`, or `form.controls.x.value` as an OnPush/change-detection issue by itself.
8
+ - NEVER report an object literal/DTO built from form values as "mutating state" or "missing immutable update".
9
+ - NEVER require `ChangeDetectorRef` for normal Reactive Form patch/reset/submit code unless an existing shared state object, `@Input`, signal state, or service-owned mutable object is mutated in-place.
10
+
11
+ 1. **CHỈ report lỗi có bằng chứng cụ thể** trong primary hoặc support files. Không đoán convention ngoài cluster.
12
+ 2. **`line` BẮT BUỘC trỏ về PRIMARY file**.
13
+ 3. **Confidence `<50` → KHÔNG emit**.
14
+
15
+ ## Chỉ flag khi có bằng chứng cụ thể
16
+
17
+ - Component `ChangeDetectionStrategy.OnPush` nhưng mutate array/object state hoặc `@Input()` trực tiếp (`push`, `splice`, gán field con, sort in-place, v.v.) khiến UI hoặc parent state dễ stale.
18
+ - Callback async ngoài Angular pattern an toàn (`setTimeout`, browser event listener, third-party callback, Promise callback thủ công) cập nhật state nhưng không dùng signal/observable async pipe/`ChangeDetectorRef`/`NgZone` hợp lý.
19
+ - Derived state được cache thủ công từ input/source data nhưng không được recompute rõ ràng khi source đổi.
20
+ - Shared mutable state được expose từ service/component rồi bị caller mutate trực tiếp.
21
+ - Component gọi service/shared store theo cách expose mutable subject/array/object khiến consumer khác có thể phá invariant.
22
+
23
+ ## KHÔNG flag
24
+
25
+ - Chỉ thiếu `OnPush` hoặc thiếu `standalone` (đã có static rules).
26
+ - Direct DOM access thuần túy nếu không có state/change-detection consequence (đã có static rule).
27
+ - Immutable update rõ ràng (`items = [...items, x]`, `map`, `filter`, signal `.update`, RxJS stream + async pipe).
28
+ - Test/spec/generated files.
29
+ - Vấn đề style hoặc preference không tạo bug UI/state rõ ràng.
30
+
31
+ ## Code cần review
32
+
33
+ Additional non-violations:
34
+
35
+ - Reactive Form operations (`form.patchValue`, `form.reset`, `form.getRawValue`, `form.controls.x.value`) are NOT state/change-detection bugs by themselves. Do not require `ChangeDetectorRef` for normal form patch/reset/submit flows unless the code also mutates shared state, `@Input`, signal state, or service-owned mutable data in-place.
36
+ - Building a request DTO/object literal from form values is NOT an immutable-update issue. Only flag object/array mutation when an existing component/service state object is mutated in-place and reused.
37
+ - `effect(() => form.patchValue(...))` that copies signal/store data into a Reactive Form is not stale derived state if the effect reads the source signals directly.
38
+
39
+ Primary file: {{file}}
40
+ Language: {{language}}
41
+
42
+ ```{{language}}
43
+ {{code}}
44
+ ```
45
+
46
+ ## Support files cùng cluster
47
+
48
+ Các file dưới đây có thể gồm external template, service, model, pipe/directive/module cùng feature. Chỉ dùng làm bằng chứng nếu liên quan tới primary file.
49
+
50
+ {{cluster_summary}}
51
+
52
+ ## Output yêu cầu
53
+
54
+ Trả về **JSON HỢP LỆ DUY NHẤT** (không markdown fence, không text khác) theo schema:
55
+
56
+ ```
57
+ {
58
+ "violations": [
59
+ {
60
+ "line": <số nguyên dương, 1-based>,
61
+ "endLine": <số nguyên dương | null>,
62
+ "message": "<≤200 ký tự, tiếng Việt>",
63
+ "suggestion": "<gợi ý fix | null>",
64
+ "confidence": <số nguyên 0-100>
65
+ }
66
+ ]
67
+ }
68
+ ```
69
+
70
+ Nếu không có vấn đề rõ ràng: `{"violations": []}`.
71
+
72
+ ## REPEAT CRITICAL RULES
73
+
74
+ - `line` phải trỏ về PRIMARY file, không dùng line từ support file.
75
+ - Không duplicate static rules (`onpush-required`, `no-direct-dom-access`, `no-leaky-subscription`).
76
+ - Chỉ report khi có flow cụ thể dẫn tới UI stale hoặc state corruption.
77
+ - Confidence `<50` → KHÔNG emit.
78
+
79
+ Đừng giải thích. JSON thuần.
@@ -0,0 +1,26 @@
1
+ id: angular/component-state-flow
2
+ version: 3
3
+ kind: ai
4
+ title: "Angular component state/change detection flow có rủi ro không?"
5
+ description: |
6
+ Dùng LLM để review các lỗi Angular khó bắt bằng pattern đơn lẻ trong
7
+ component TypeScript:
8
+ - Component OnPush mutate array/object state hoặc @Input trực tiếp thay vì
9
+ immutable update.
10
+ - Async callback / DOM listener / third-party callback cập nhật state nhưng
11
+ không qua Angular signal/async pipe/ChangeDetectorRef hợp lý.
12
+ - Derived state bị cache thủ công và dễ stale so với input/source state.
13
+
14
+ Không thay thế static rule `angular/onpush-required` hoặc
15
+ `angular/no-direct-dom-access`; chỉ flag khi có flow cụ thể dẫn tới UI stale,
16
+ state shared bị mutate, hoặc update khó trigger change detection.
17
+ severity: warning
18
+ category: angular-state
19
+ languages: [typescript]
20
+ scope: angular
21
+ baseConfidence: 60
22
+ prompt: ./component-state-flow.prompt.md
23
+ contextScope: per-cluster
24
+ maxTokens: 1200
25
+ aiConfig:
26
+ tier: regular
@@ -0,0 +1,70 @@
1
+ Bạn là senior Angular architecture reviewer. Đánh giá **một module Angular** (tập hợp feature) về **inconsistent API consumption / cross-feature drift** dựa trên pass-1 findings + danh sách feature trong module.
2
+
3
+ ## CRITICAL RULES
4
+
5
+ 1. **CHỈ report drift xuất hiện ≥ 2 feature** trong module. Single-feature issue → để leaf rule `angular/api-service-contract-risk` xử lý.
6
+ 2. **MỖI drift pattern = ĐÚNG MỘT finding.** Nếu cùng một pattern (vd. "err.message thay vì err.error.message") xuất hiện ở nhiều file, GỘP thành **một** finding duy nhất — `file`/`line` trỏ vào file ĐẠI DIỆN rõ nhất, và liệt kê TÊN tất cả feature liên quan trong `message`. TUYỆT ĐỐI KHÔNG emit cùng pattern lặp lại một lần cho mỗi file.
7
+ 3. **`line` BẮT BUỘC là số nguyên dương** (≥ 1), trỏ vào một dòng cụ thể trong file đã chọn nơi pattern lộ rõ nhất. Nếu không chắc dòng nào → dùng `line: 1`. KHÔNG để trống, KHÔNG dùng `null`, KHÔNG dùng `0`.
8
+ 4. **`file` phải là posix path** xuất hiện trong `Module summary` bên dưới — KHÔNG fabricate path mới.
9
+ 5. **Confidence `<50` → KHÔNG emit.** Ngưỡng noise thấp (`numMaxFindings: 5`).
10
+
11
+ ## Chỉ flag khi có pattern lặp lại ≥ 2 feature
12
+
13
+ - Hai feature gọi cùng endpoint `/api/<resource>/...` nhưng:
14
+ - request body wrapper khác nhau (một bên gửi raw payload, một bên gửi `{ data: payload }`), HOẶC
15
+ - response shape assumption khác nhau (một bên đọc `res.data`, một bên đọc `res.content` cùng resource), HOẶC
16
+ - error shape khác nhau (`err.error.message` vs `err.message`).
17
+ - Một feature gọi endpoint trực tiếp qua `HttpClient` trong khi các feature khác trong cùng module đã chuẩn hóa qua một service/wrapper (pass-1 finding `api-service-contract-risk` lặp lại 2+ feature là indicator mạnh).
18
+ - Hard-coded path string lặp lại ≥ 3 lần ngang qua các feature — gợi ý cần `API_ROUTES` constants.
19
+ - Auth gating khác nhau giữa các route component cùng truy cập 1 resource — flag khả năng authorization bypass.
20
+
21
+ ## KHÔNG flag
22
+
23
+ - Bug chỉ xuất hiện trong 1 feature (đã thuộc per-feature rule).
24
+ - Mỗi feature dùng wrapper/service riêng nhưng đều normalize đúng → không drift.
25
+ - Pass-1 findings rỗng và không có signal nào trong module summary.
26
+ - Naming-only difference (vd. hai biến local cùng response nhưng tên khác) — không phải contract drift.
27
+
28
+ ## Module summary
29
+
30
+ {{module_summary}}
31
+
32
+ ## Features trong module
33
+
34
+ {{module_features}}
35
+
36
+ ## Pass-1 findings (đã có từ per-file + per-cluster rules — synthesize, KHÔNG redo)
37
+
38
+ {{module_findings}}
39
+
40
+ ## Output yêu cầu
41
+
42
+ Trả về **JSON HỢP LỆ DUY NHẤT** (không markdown fence, không text khác) theo schema:
43
+
44
+ ```
45
+ {
46
+ "violations": [
47
+ {
48
+ "file": "<posix path trong members[]>",
49
+ "line": <số nguyên dương, 1-based>,
50
+ "endLine": <số nguyên dương | null>,
51
+ "message": "<≤200 ký tự, tiếng Việt, mô tả pattern + tên ≥ 2 feature liên quan>",
52
+ "suggestion": "<gợi ý refactor (vd. tạo wrapper service, dùng API_ROUTES) | null>",
53
+ "confidence": <số nguyên 0-100>
54
+ }
55
+ ]
56
+ }
57
+ ```
58
+
59
+ Nếu không có drift rõ ràng: `{"violations": []}`.
60
+
61
+ ## REPEAT CRITICAL RULES
62
+
63
+ - Pattern phải xuất hiện trong ≥ 2 feature của module.
64
+ - **MỖI pattern = MỘT finding.** Gộp cùng pattern ngang nhiều file thành một finding; liệt kê tên feature trong `message`. KHÔNG lặp một pattern theo từng file.
65
+ - `file` phải nằm trong `members[]` của module summary trên.
66
+ - `line` phải là số nguyên ≥ 1 trỏ vào file đã chọn — KHÔNG để trống / `null` / `0`.
67
+ - KHÔNG duplicate findings đã có ở pass-1 (chúng đã được report ở leaf rule).
68
+ - Confidence `<50` → KHÔNG emit.
69
+
70
+ Đừng giải thích. JSON thuần.
@@ -0,0 +1,42 @@
1
+ id: angular/cross-feature-api-drift
2
+ # v2 (Phase 15.5.2): POC gate PASS (5/5 = 100% precision on ctdv/periodic-report
3
+ # Viettel dogfood). Prompt v2 adds (a) one-finding-per-pattern de-dup instruction
4
+ # — v1 emitted the same drift once per file (5 findings = 2 real patterns); and
5
+ # (b) stronger `line` requirement (v1 returned null/undefined line). Version bump
6
+ # invalidates v1 cached findings.
7
+ version: 2
8
+ kind: ai
9
+ title: "Angular features trong cùng module gọi /api/* không nhất quán?"
10
+ description: |
11
+ Per-module AI rule (Phase 15.5.1, ADR-0016) — đầu tiên trong family
12
+ `contextScope: 'per-module'`. Nhận vào pass-1 findings + danh sách
13
+ feature primary của một module Angular và tìm các bug **synthesis**
14
+ CHỈ lộ ra ở cấp độ module:
15
+ - Hai feature cùng module gọi cùng endpoint `/api/<resource>/...`
16
+ nhưng dùng request/response shape khác nhau (params encoder, body
17
+ wrapper, error shape) → drift sẽ break khi BE đổi contract.
18
+ - Một feature gọi endpoint `/api/<resource>` không qua wrapper /
19
+ service mà phần lớn các feature khác trong module đã chuẩn hóa.
20
+ - Trùng lặp endpoint hard-code (cùng path string lặp lại 3+ feature)
21
+ khi module đã có constants/service nên dùng.
22
+ - Auth/permission gating khác nhau giữa các feature gọi cùng resource
23
+ (một feature dùng guard X, feature khác bỏ qua) → indicator của
24
+ authorization bypass tiềm tàng.
25
+
26
+ KHÔNG redo per-feature work — leaf rule
27
+ `angular/api-service-contract-risk` đã phụ trách contract trong 1
28
+ cluster. Per-module rule chỉ flag khi pattern xuất hiện **ngang qua
29
+ ≥ 2 feature** của module.
30
+ severity: warning
31
+ category: angular-architecture
32
+ languages: [typescript]
33
+ scope: angular
34
+ baseConfidence: 55
35
+ prompt: ./cross-feature-api-drift.prompt.md
36
+ contextScope: per-module
37
+ maxTokens: 1800
38
+ aiConfig:
39
+ tier: regular
40
+ # Cap findings để v1 ngưỡng noise thấp; nâng lên sau khi POC gate đạt
41
+ # ≥ 80% precision theo ADR-0016 §"Implementation phase".
42
+ numMaxFindings: 5
@@ -0,0 +1,73 @@
1
+ Bạn là senior Angular security reviewer. Đánh giá **một module Angular** (tập hợp feature) về **inconsistent authorization / route-permission drift** — tức cùng một resource được bảo vệ KHÁC NHAU giữa các feature — dựa trên pass-1 findings + danh sách feature trong module.
2
+
3
+ ## CRITICAL RULES
4
+
5
+ 1. **CHỈ report drift xuất hiện ≥ 2 feature** trong module. Single-feature issue (vd. một route quên guard, không so với feature khác) → để leaf rule `angular/route-permission-flow` xử lý.
6
+ 2. **MỖI drift pattern = ĐÚNG MỘT finding.** Nếu cùng một pattern (vd. "route X có guard, route Y truy cập cùng resource thì không") trải trên nhiều file, GỘP thành **một** finding duy nhất — `file`/`line` trỏ vào file ĐẠI DIỆN rõ nhất (thường là route/component KÉM bảo vệ hơn), và liệt kê TÊN tất cả feature liên quan trong `message`. TUYỆT ĐỐI KHÔNG emit cùng pattern lặp lại một lần cho mỗi file.
7
+ - **NHIỀU hành động cùng CHUNG một kiểu drift = MỘT finding.** Vd. nếu cả Delete, Export, Approve... đều "chỉ ẩn UI bằng `*hasPermission` mà thiếu code/route check" trong khi nav actions có guard → đó là **MỘT** pattern duy nhất ("in-component sensitive actions gated UI-only vs guarded nav"). Liệt kê tất cả hành động (Delete, Export, ...) trong `message`, **KHÔNG** tách mỗi hành động thành một finding riêng.
8
+ 3. **`line` BẮT BUỘC là số nguyên dương** (≥ 1), trỏ vào một dòng cụ thể trong file đã chọn nơi pattern lộ rõ nhất (vd. dòng khai báo route thiếu guard, dòng gọi action destructive không check). Nếu không chắc dòng nào → dùng `line: 1`. KHÔNG để trống, KHÔNG dùng `null`, KHÔNG dùng `0`.
9
+ 4. **`file` phải là posix path** xuất hiện trong `Module summary` bên dưới — KHÔNG fabricate path mới.
10
+ 5. **Confidence `<50` → KHÔNG emit.** Ngưỡng noise thấp (`numMaxFindings: 5`).
11
+
12
+ ## Chỉ flag khi có pattern lặp lại ≥ 2 feature
13
+
14
+ - Hai route component cùng thao tác một resource (suy ra từ endpoint `/api/<resource>`, tên service, hoặc tên domain) nhưng:
15
+ - một route khai báo `canActivate: [guard]` + `data.permissions` / `data.roles`, route kia KHÔNG có guard nào, HOẶC
16
+ - dùng guard khác mức (`AuthGuard` chỉ check login vs `permissionGuard` check role) cho cùng resource, HOẶC
17
+ - `data.permissions` / `data.roles` lệch nhau cho cùng hành động (feature A yêu cầu `*_DELETE`, feature B chỉ `*_VIEW` cho cùng nút xóa).
18
+ - Cùng một destructive action (delete / edit / approve / reject) được gate bằng permission check (route guard hoặc check code-level như `permissions.hasAny(...)`) ở feature này, nhưng feature khác CHỈ ẩn UI bằng template directive (`*hasPermission`, `[hidden]`, `*ngIf="canX"`) mà KHÔNG có check ở route/code → bypass được qua gọi method trực tiếp.
19
+ - Pass-1 finding `route-permission-flow` lặp lại ở ≥ 2 feature cùng resource là indicator mạnh của drift module-level.
20
+
21
+ ## KHÔNG flag
22
+
23
+ - Bug chỉ xuất hiện trong 1 feature (đã thuộc per-feature rule).
24
+ - Mỗi feature đều enforce nhất quán (cùng guard, cùng permission key) → không drift.
25
+ - Các feature truy cập resource KHÁC NHAU — mức permission khác nhau là hợp lý, không phải drift.
26
+ - Template directive ẩn UI ĐỒNG THỜI có route guard / code check tương ứng → bảo vệ đủ tầng, không phải bypass.
27
+ - Pass-1 findings rỗng và không có signal nào về guard/permission trong module summary.
28
+
29
+ ## Module summary
30
+
31
+ {{module_summary}}
32
+
33
+ ## Features trong module
34
+
35
+ {{module_features}}
36
+
37
+ ## Pass-1 findings (đã có từ per-file + per-cluster rules — synthesize, KHÔNG redo)
38
+
39
+ {{module_findings}}
40
+
41
+ ## Output yêu cầu
42
+
43
+ Trả về **JSON HỢP LỆ DUY NHẤT** (không markdown fence, không text khác) theo schema:
44
+
45
+ ```
46
+ {
47
+ "violations": [
48
+ {
49
+ "file": "<posix path trong members[]>",
50
+ "line": <số nguyên dương, 1-based>,
51
+ "endLine": <số nguyên dương | null>,
52
+ "message": "<≤200 ký tự, tiếng Việt, mô tả pattern drift + tên ≥ 2 feature liên quan>",
53
+ "suggestion": "<gợi ý refactor (vd. áp cùng guard, chuẩn hóa data.permissions, thêm code-level check) | null>",
54
+ "confidence": <số nguyên 0-100>
55
+ }
56
+ ]
57
+ }
58
+ ```
59
+
60
+ Nếu không có drift rõ ràng: `{"violations": []}`.
61
+
62
+ ## REPEAT CRITICAL RULES
63
+
64
+ - Pattern phải xuất hiện trong ≥ 2 feature của module và CÙNG resource.
65
+ - **MỖI pattern = MỘT finding.** Gộp cùng pattern ngang nhiều file thành một finding; liệt kê tên feature trong `message`. KHÔNG lặp một pattern theo từng file.
66
+ - **Nhiều hành động (Delete/Export/Approve...) cùng kiểu drift "chỉ ẩn UI vs có guard" = MỘT finding** — liệt kê hết action trong `message`, KHÔNG tách mỗi action một finding.
67
+ - `file` phải nằm trong `members[]` của module summary trên.
68
+ - `line` phải là số nguyên ≥ 1 trỏ vào file đã chọn — KHÔNG để trống / `null` / `0`.
69
+ - KHÔNG duplicate findings đã có ở pass-1 (chúng đã được report ở leaf rule).
70
+ - Template directive ẩn UI + có route/code check tương ứng → KHÔNG phải bypass, đừng flag.
71
+ - Confidence `<50` → KHÔNG emit.
72
+
73
+ Đừng giải thích. JSON thuần.
@@ -0,0 +1,50 @@
1
+ id: angular/cross-feature-route-permission-drift
2
+ # v2 (Phase 15.5.3): POC gate PASSED on ctdv/periodic-report (GLM-4.7) —
3
+ # 2/2 findings TP = 100% precision (>= 80% ADR-0016 bar). The finding (route
4
+ # guard on add/edit/detail vs UI-only `*hasPermission` for delete/export on
5
+ # the same resource) was code-verified. Prompt v2 fixes the one nit from the
6
+ # gate: v1 emitted the SAME drift pattern twice (once for delete, once for
7
+ # export) — v2 CRITICAL RULE: multiple actions sharing one drift mechanism =
8
+ # ONE finding (list all actions in the message). Version bump invalidates v1
9
+ # cached findings.
10
+ # Second rule in the per-module family (ADR-0016); same POC discipline as
11
+ # cross-feature-api-drift (small numMaxFindings + sandwich prompt).
12
+ version: 2
13
+ kind: ai
14
+ title: "Angular features trong cùng module bảo vệ route / permission không nhất quán?"
15
+ description: |
16
+ Per-module AI rule (Phase 15.5.3, ADR-0016) — phát hiện **drift trong
17
+ cách enforce authorization** giữa nhiều feature CỦA CÙNG MỘT module mà
18
+ cùng truy cập một resource được bảo vệ. Đây là bug **synthesis** chỉ lộ
19
+ ra khi nhìn ngang nhiều feature, không phải vấn đề trong 1 cluster:
20
+ - Hai route component cùng thao tác trên một resource (vd. `users`,
21
+ `orders`) nhưng một route có `canActivate: [guard]` + `data.permissions`,
22
+ route kia không có guard nào → authorization bypass tiềm tàng.
23
+ - Cùng một destructive action (delete/edit/approve) được gate bằng
24
+ permission check ở feature này nhưng feature khác chỉ ẩn nút bằng
25
+ template directive (`*hasPermission`, `[hidden]`) mà không có check
26
+ ở code-level / route guard.
27
+ - Các feature dùng guard KHÁC NHAU (vd. `AuthGuard` chỉ check đăng nhập
28
+ vs `permissionGuard` check role) cho cùng resource → mức bảo vệ không
29
+ đồng đều.
30
+ - `data.permissions` / `data.roles` khai báo lệch nhau giữa các route
31
+ cùng resource (feature A yêu cầu `USER_DELETE`, feature B chỉ
32
+ `USER_VIEW` cho cùng hành động xóa).
33
+
34
+ KHÔNG redo per-feature work — leaf rule `angular/route-permission-flow`
35
+ đã phụ trách permission completeness TRONG một cluster. Per-module rule
36
+ chỉ flag khi sự KHÔNG NHẤT QUÁN xuất hiện **ngang qua ≥ 2 feature** của
37
+ module.
38
+ severity: warning
39
+ category: angular-architecture
40
+ languages: [typescript]
41
+ scope: angular
42
+ baseConfidence: 55
43
+ prompt: ./cross-feature-route-permission-drift.prompt.md
44
+ contextScope: per-module
45
+ maxTokens: 1800
46
+ aiConfig:
47
+ tier: regular
48
+ # Cap findings để v1 ngưỡng noise thấp; nâng lên sau khi POC gate đạt
49
+ # ≥ 80% precision theo ADR-0016 §"Implementation phase".
50
+ numMaxFindings: 5
@@ -0,0 +1,82 @@
1
+ Bạn là senior Angular reviewer. Đánh giá Angular review unit dưới đây về **Reactive Forms, submit flow, validation, và template contract**.
2
+
3
+ ## CRITICAL RULES
4
+
5
+ CRITICAL NON-VIOLATIONS:
6
+
7
+ - NEVER report a required-validator issue when the external template renders a reusable error component bound to that control, such as `[control]="form.controls.title"`.
8
+ - NEVER report missing submit validation when the template disables submit with `[disabled]="form.invalid || form.pending"`.
9
+ - NEVER report `getRawValue()` as a problem by itself; it is the correct API when disabled controls might matter.
10
+ - NEVER require `Validators.required` for optional free-text fields such as comma-separated `tagList` unless support API/model proves the field is required.
11
+ - NEVER report a Reactive Forms issue when the primary component has no `FormGroup`, `FormBuilder`, `formControlName`, `form.value`, `getRawValue()`, `disable()`, or Reactive Forms template evidence.
12
+ - NEVER infer a form serialization bug from a method named `submit(...)` by itself. For example, `submit(comment: string)` that forwards a child comment output is not a Reactive Forms flow.
13
+
14
+ 1. **CHỈ report lỗi có bằng chứng cụ thể** trong primary hoặc support files. Không đoán convention ngoài cluster.
15
+ 2. **`line` BẮT BUỘC trỏ về PRIMARY file**.
16
+ 3. **Confidence `<50` → KHÔNG emit**.
17
+
18
+ ## Chỉ flag khi có rủi ro bug cụ thể
19
+
20
+ - Template hiển thị required/error nhưng `FormGroup` không có validator tương ứng, hoặc validator có nhưng template không surface lỗi quan trọng.
21
+ - Submit đọc `form.value` trong khi control bị `disable()` nhưng vẫn cần gửi lên API; trường hợp này thường phải dùng `getRawValue()`.
22
+ - `ViewChildren`/child form components được đọc lúc submit nhưng có thể chưa init, stale sau structural directive, hoặc không được mark touched/validated.
23
+ - `ngModel` được trộn trong form reactive mà không standalone, hoặc state ngoài form ảnh hưởng request nhưng không được validate.
24
+ - Control value được trim/normalize sau validation làm request khác với giá trị user thấy, hoặc không normalize field mà API/validator kỳ vọng.
25
+
26
+ ## KHÔNG flag
27
+
28
+ - Form đơn giản có validators và template error rõ ràng.
29
+ - `ngModelOptions="{ standalone: true }"` dùng cho UI-only selector/connector và không gửi API trực tiếp.
30
+ - Disabled control chỉ là display-only và không được gửi trong request.
31
+ - Vấn đề style hoặc naming thuần túy.
32
+
33
+ ## Primary file
34
+
35
+ Additional non-violations:
36
+
37
+ - A required control is considered surfaced when the external template renders a reusable error component bound to that control, for example `<app-input-errors [control]="form.controls.name">` or project-specific equivalents.
38
+ - A submit button disabled by `form.invalid` or `form.pending` is valid submit gating. Do not also require `onSubmit()` to repeat the same invalid check unless the template allows submit while invalid.
39
+ - `getRawValue()` is the correct API when disabled controls might matter; do not flag its use unless a disabled/display-only field is demonstrably sent to an API incorrectly.
40
+ - Optional free-text controls such as comma-separated `tagList` do not need `Validators.required` or an error message unless the API/model in the cluster proves they are required.
41
+ - If the reviewed primary is a container component and a child component owns the actual form, do not report a Reactive Forms finding on the container unless the container reads or serializes the child's form state incorrectly.
42
+ - A method named `submit(comment: string)` is not form evidence by itself; require explicit Reactive Forms symbols or template bindings before reporting.
43
+
44
+ File: {{file}}
45
+ Language: {{language}}
46
+
47
+ ```{{language}}
48
+ {{code}}
49
+ ```
50
+
51
+ ## Support files cùng cluster
52
+
53
+ {{cluster_summary}}
54
+
55
+ ## Output yêu cầu
56
+
57
+ Trả về **JSON HỢP LỆ DUY NHẤT** (không markdown fence, không text khác) theo schema:
58
+
59
+ ```
60
+ {
61
+ "violations": [
62
+ {
63
+ "line": <số nguyên dương, 1-based>,
64
+ "endLine": <số nguyên dương | null>,
65
+ "message": "<≤200 ký tự, tiếng Việt>",
66
+ "suggestion": "<gợi ý fix | null>",
67
+ "confidence": <số nguyên 0-100>
68
+ }
69
+ ]
70
+ }
71
+ ```
72
+
73
+ Nếu không có vấn đề rõ ràng: `{"violations": []}`.
74
+
75
+ ## REPEAT CRITICAL RULES
76
+
77
+ - `line` phải trỏ về PRIMARY file, không dùng line từ support file.
78
+ - Chỉ report khi có rủi ro submit/validation cụ thể, không report style/naming.
79
+ - Do not infer a form issue from a `submit(...)` method name without explicit Reactive Forms evidence in the primary/support cluster.
80
+ - Confidence `<50` → KHÔNG emit.
81
+
82
+ Đừng giải thích. JSON thuần.
@@ -0,0 +1,23 @@
1
+ id: angular/reactive-form-flow
2
+ version: 4
3
+ kind: ai
4
+ title: "Angular reactive form flow có rủi ro submit/validation không?"
5
+ description: |
6
+ Per-cluster AI rule cho reactive forms trong Angular component + template:
7
+ - Template required/error state lệch với FormGroup validators.
8
+ - Submit dùng `form.value` làm mất disabled controls cần gửi, hoặc không dùng
9
+ `getRawValue()` khi control bị disable.
10
+ - Dynamic child form/condition components được đọc qua ViewChildren nhưng
11
+ lifecycle/validity/serialization có thể stale hoặc chưa sẵn sàng.
12
+ - `ngModel` trộn với reactive form không standalone hoặc state ngoài form
13
+ không được validate trước khi submit.
14
+ severity: warning
15
+ category: angular-form
16
+ languages: [typescript]
17
+ scope: angular
18
+ baseConfidence: 60
19
+ prompt: ./reactive-form-flow.prompt.md
20
+ contextScope: per-cluster
21
+ maxTokens: 1600
22
+ aiConfig:
23
+ tier: regular
@@ -0,0 +1,80 @@
1
+ Bạn là senior Angular security reviewer. Đánh giá Angular review unit dưới đây về **route guard, permission data, và UI action authorization**.
2
+
3
+ ## CRITICAL RULES
4
+
5
+ 1. **CHỈ report lỗi có bằng chứng cụ thể** trong primary hoặc support files. Không đoán convention ngoài cluster.
6
+ 2. **`line` BẮT BUỘC trỏ về PRIMARY file**.
7
+ 3. **Confidence `<50` → KHÔNG emit**.
8
+
9
+ CRITICAL NON-VIOLATIONS:
10
+
11
+ - NEVER report a delete/edit action as missing permission when the template or child component gates the action by record ownership, for example `[canModify]`, `currentUser().username === author.username`, or `[hidden]="currentUser().username !== comment().author.username"`.
12
+ - NEVER require an inline permission check inside the primary component method when the support template/component only exposes the action through an ownership-gated child output.
13
+ - NEVER flag a primary delete method when the support path is: primary template passes `[canModify]="$canModify()"` into a child component, the child template hides the delete button with `[hidden]="!canModify()"`, and the child emits a typed delete output.
14
+ - NEVER flag a primary comment delete method when the child comment template hides the delete control with `[hidden]="currentUser().username !== comment().author.username"` and emits `{ commentId, slug }`.
15
+
16
+ ## Chỉ flag khi có evidence cụ thể
17
+
18
+ - Route/support file cho thấy màn hình protected nhưng route thiếu guard hoặc thiếu `data.role`/permission cần thiết.
19
+ - Template hiển thị action nhạy cảm (create/edit/delete/send/export/approve/lock/unlock) chỉ dựa trên status/visibility flag mà không dựa trên permission/role.
20
+ - Component method gọi API destructive hoặc điều hướng tới action nhạy cảm mà không có guard/permission check trong route hoặc code.
21
+ - Guard đọc key khác với route data đang khai báo (`role` vs `roles`/`permissions`) khiến quyền không bao giờ được kiểm.
22
+ - Forbidden redirect hoặc login redirect làm mất URL ban đầu trong flow auth.
23
+
24
+ ## KHÔNG flag
25
+
26
+ - Public auth/login/forgot-password routes có `NO_AUTH`/public slot rõ ràng.
27
+ - Action chỉ thay đổi UI local, không gọi API/route nhạy cảm.
28
+ - Permission check nằm trong shared directive/component support file và template dùng directive đó rõ ràng.
29
+ - Không có route/permission/action evidence trong cluster.
30
+
31
+ ## Primary file
32
+
33
+ Additional non-violations:
34
+
35
+ - If the route support file shows `canActivate: [AuthGuard]` (or equivalent auth guard) for the route tree that renders the primary component, do not report a generic missing-auth/permission issue for normal create/edit/publish actions.
36
+ - Only require role/permission-specific route data when the cluster shows a role/permission model, guard, directive, or policy convention that the action is expected to use.
37
+ - Do not flag authenticated CRUD actions just because the component method lacks an inline permission check when route-level auth/guard evidence exists in the same cluster.
38
+ - Resolver/store load methods are not permission checks by themselves; use them only as context, not as proof of missing authorization.
39
+
40
+ File: {{file}}
41
+ Language: {{language}}
42
+
43
+ ```{{language}}
44
+ {{code}}
45
+ ```
46
+
47
+ ## Support files cùng cluster
48
+
49
+ {{cluster_summary}}
50
+
51
+ ## Output yêu cầu
52
+
53
+ Trả về **JSON HỢP LỆ DUY NHẤT** (không markdown fence, không text khác) theo schema:
54
+
55
+ ```
56
+ {
57
+ "violations": [
58
+ {
59
+ "line": <số nguyên dương, 1-based>,
60
+ "endLine": <số nguyên dương | null>,
61
+ "message": "<≤200 ký tự, tiếng Việt>",
62
+ "suggestion": "<gợi ý fix | null>",
63
+ "confidence": <số nguyên 0-100>
64
+ }
65
+ ]
66
+ }
67
+ ```
68
+
69
+ Nếu không có vấn đề rõ ràng: `{"violations": []}`.
70
+
71
+ ## REPEAT CRITICAL RULES
72
+
73
+ - `line` phải trỏ về PRIMARY file, không dùng line từ support file.
74
+ - Không flag action chỉ thay đổi UI local, không gọi API nhạy cảm.
75
+ - Chỉ report khi có evidence route/permission/action cụ thể trong cluster.
76
+ - Do not flag ownership-gated edit/delete UI actions as missing route permission unless the cluster proves a separate role/permission policy is required.
77
+ - Do not require duplicate inline checks inside primary delete handlers when the only UI path to those handlers is an ownership-gated child output.
78
+ - Confidence `<50` → KHÔNG emit.
79
+
80
+ Đừng giải thích. JSON thuần.
@@ -0,0 +1,23 @@
1
+ id: angular/route-permission-flow
2
+ version: 4
3
+ kind: ai
4
+ title: "Angular route/permission/UI action flow có rủi ro phân quyền không?"
5
+ description: |
6
+ Per-cluster AI rule cho route guard, route data, permission service và UI
7
+ actions trong Angular:
8
+ - Protected route/action không có guard hoặc thiếu `data.role`/permission
9
+ trong khi màn hình thao tác dữ liệu nhạy cảm.
10
+ - Template chỉ ẩn/hiện nút theo status nhưng không theo permission, hoặc
11
+ method vẫn gọi API destructive khi user không đủ quyền.
12
+ - Redirect/forbidden flow làm mất `redirect` hoặc dùng fallback sai module.
13
+ - Route contribution/lazy import lệch với component/action permission.
14
+ severity: warning
15
+ category: angular-security
16
+ languages: [typescript]
17
+ scope: angular
18
+ baseConfidence: 60
19
+ prompt: ./route-permission-flow.prompt.md
20
+ contextScope: per-cluster
21
+ maxTokens: 1600
22
+ aiConfig:
23
+ tier: regular