@code-sentinel-cli/code-sentinel-cli 3.0.3 → 3.0.5
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/README.md +1 -1
- package/dist/bin.js +1191 -816
- package/dist/builtin-rules/ai/angular/api-service-contract-risk.prompt.md +71 -0
- package/dist/builtin-rules/ai/angular/api-service-contract-risk.rule.yaml +22 -0
- package/dist/builtin-rules/ai/angular/component-state-flow.prompt.md +79 -0
- package/dist/builtin-rules/ai/angular/component-state-flow.rule.yaml +26 -0
- package/dist/builtin-rules/ai/angular/cross-feature-api-drift.prompt.md +70 -0
- package/dist/builtin-rules/ai/angular/cross-feature-api-drift.rule.yaml +42 -0
- package/dist/builtin-rules/ai/angular/cross-feature-route-permission-drift.prompt.md +73 -0
- package/dist/builtin-rules/ai/angular/cross-feature-route-permission-drift.rule.yaml +50 -0
- package/dist/builtin-rules/ai/angular/reactive-form-flow.prompt.md +82 -0
- package/dist/builtin-rules/ai/angular/reactive-form-flow.rule.yaml +23 -0
- package/dist/builtin-rules/ai/angular/route-permission-flow.prompt.md +80 -0
- package/dist/builtin-rules/ai/angular/route-permission-flow.rule.yaml +23 -0
- package/dist/builtin-rules/ai/angular/rxjs-flow-risk.prompt.md +82 -0
- package/dist/builtin-rules/ai/angular/rxjs-flow-risk.rule.yaml +24 -0
- package/dist/builtin-rules/ai/angular/template-contract-risk.prompt.md +80 -0
- package/dist/builtin-rules/ai/angular/template-contract-risk.rule.yaml +25 -0
- package/dist/builtin-rules/ai/flutter/dynamic-content-risk.prompt.md +55 -0
- package/dist/builtin-rules/ai/flutter/dynamic-content-risk.rule.yaml +18 -0
- package/dist/builtin-rules/ai/flutter/feature-state-flow-risk.prompt.md +58 -0
- package/dist/builtin-rules/ai/flutter/feature-state-flow-risk.rule.yaml +18 -0
- package/dist/builtin-rules/ai/flutter/native-platform-consistency-risk.prompt.md +56 -0
- package/dist/builtin-rules/ai/flutter/native-platform-consistency-risk.rule.yaml +18 -0
- package/dist/builtin-rules/ai/flutter/network-auth-flow-risk.prompt.md +57 -0
- package/dist/builtin-rules/ai/flutter/network-auth-flow-risk.rule.yaml +19 -0
- package/dist/builtin-rules/ai/flutter/ui-responsive-accessibility-risk.prompt.md +60 -0
- package/dist/builtin-rules/ai/flutter/ui-responsive-accessibility-risk.rule.yaml +18 -0
- package/dist/builtin-rules/ai/general/code-clarity.prompt.md +57 -0
- package/dist/builtin-rules/ai/general/code-clarity.rule.yaml +20 -0
- package/dist/builtin-rules/ai/spring-boot/business-invariant-risk.prompt.md +86 -0
- package/dist/builtin-rules/ai/spring-boot/business-invariant-risk.rule.yaml +25 -0
- package/dist/builtin-rules/ai/spring-boot/cache-consistency-risk.prompt.md +80 -0
- package/dist/builtin-rules/ai/spring-boot/cache-consistency-risk.rule.yaml +25 -0
- package/dist/builtin-rules/ai/spring-boot/cross-feature-error-handling-drift.prompt.md +76 -0
- package/dist/builtin-rules/ai/spring-boot/cross-feature-error-handling-drift.rule.yaml +63 -0
- package/dist/builtin-rules/ai/spring-boot/cross-feature-transaction-boundary-drift.prompt.md +85 -0
- package/dist/builtin-rules/ai/spring-boot/cross-feature-transaction-boundary-drift.rule.yaml +68 -0
- package/dist/builtin-rules/ai/spring-boot/error-handling-completeness.prompt.md +121 -0
- package/dist/builtin-rules/ai/spring-boot/error-handling-completeness.rule.yaml +84 -0
- package/dist/builtin-rules/ai/spring-boot/event-publishing-risk.prompt.md +80 -0
- package/dist/builtin-rules/ai/spring-boot/event-publishing-risk.rule.yaml +25 -0
- package/dist/builtin-rules/ai/spring-boot/io-boundary-risk.prompt.md +78 -0
- package/dist/builtin-rules/ai/spring-boot/io-boundary-risk.rule.yaml +25 -0
- package/dist/builtin-rules/ai/spring-boot/ownership-scope-risk.prompt.md +83 -0
- package/dist/builtin-rules/ai/spring-boot/ownership-scope-risk.rule.yaml +25 -0
- package/dist/builtin-rules/ai/spring-boot/pagination-risk.prompt.md +81 -0
- package/dist/builtin-rules/ai/spring-boot/pagination-risk.rule.yaml +25 -0
- package/dist/builtin-rules/ai/spring-boot/security-authorization-risk.prompt.md +75 -0
- package/dist/builtin-rules/ai/spring-boot/security-authorization-risk.rule.yaml +26 -0
- package/dist/builtin-rules/ai/spring-boot/security-mass-assignment-risk.prompt.md +75 -0
- package/dist/builtin-rules/ai/spring-boot/security-mass-assignment-risk.rule.yaml +24 -0
- package/dist/builtin-rules/ai/spring-boot/security-redirect-risk.prompt.md +74 -0
- package/dist/builtin-rules/ai/spring-boot/security-redirect-risk.rule.yaml +24 -0
- package/dist/builtin-rules/ai/spring-boot/security-sensitive-data-risk.prompt.md +75 -0
- package/dist/builtin-rules/ai/spring-boot/security-sensitive-data-risk.rule.yaml +25 -0
- package/dist/builtin-rules/ai/spring-boot/transaction-loop-risk.prompt.md +78 -0
- package/dist/builtin-rules/ai/spring-boot/transaction-loop-risk.rule.yaml +25 -0
- package/dist/builtin-rules/static/angular/component-prefix.rule.js +78 -0
- package/dist/builtin-rules/static/angular/image-control-alt-required.rule.js +105 -0
- package/dist/builtin-rules/static/angular/img-alt-required.rule.js +96 -0
- package/dist/builtin-rules/static/angular/inject-pattern.rule.js +47 -0
- package/dist/builtin-rules/static/angular/lifecycle-method-required.rule.js +59 -0
- package/dist/builtin-rules/static/angular/no-any-type.rule.yaml +55 -0
- package/dist/builtin-rules/static/angular/no-direct-dom-access.rule.js +191 -0
- package/dist/builtin-rules/static/angular/no-dom-xss.rule.js +48 -0
- package/dist/builtin-rules/static/angular/no-leaky-subscription.rule.js +197 -0
- package/dist/builtin-rules/static/angular/no-ngmodule.rule.yaml +44 -0
- package/dist/builtin-rules/static/angular/no-non-null-asserted-optional-chain.rule.js +53 -0
- package/dist/builtin-rules/static/angular/no-uncalled-signal-in-condition.rule.js +112 -0
- package/dist/builtin-rules/static/angular/observable-naming.rule.js +85 -0
- package/dist/builtin-rules/static/angular/onpush-required.rule.js +70 -0
- package/dist/builtin-rules/static/angular/standalone-component-required.rule.js +65 -0
- package/dist/builtin-rules/static/angular/template-dom-xss.rule.js +112 -0
- package/dist/builtin-rules/static/angular/template-syntax-modern.rule.js +154 -0
- package/dist/builtin-rules/static/angular/trackby-required.rule.js +66 -0
- package/dist/builtin-rules/static/flutter/android-exported-component.rule.js +75 -0
- package/dist/builtin-rules/static/flutter/android-manifest-hardening.rule.js +117 -0
- package/dist/builtin-rules/static/flutter/android-sensitive-permissions.rule.js +87 -0
- package/dist/builtin-rules/static/flutter/debug-tooling-release-risk.rule.js +90 -0
- package/dist/builtin-rules/static/flutter/dynamic-archive-risk.rule.js +96 -0
- package/dist/builtin-rules/static/flutter/hive-sensitive-storage.rule.js +77 -0
- package/dist/builtin-rules/static/flutter/ios-privacy-hardening.rule.js +119 -0
- package/dist/builtin-rules/static/flutter/packaged-env-risk.rule.js +95 -0
- package/dist/builtin-rules/static/flutter/sensitive-log-leak.rule.js +94 -0
- package/dist/builtin-rules/static/flutter/webview-bridge-guard.rule.js +102 -0
- package/dist/builtin-rules/static/general/file-too-long.rule.js +41 -0
- package/dist/builtin-rules/static/general/function-too-long.rule.js +72 -0
- package/dist/builtin-rules/static/general/no-circular-import.rule.js +39 -0
- package/dist/builtin-rules/static/general/no-code-injection.rule.js +48 -0
- package/dist/builtin-rules/static/general/no-console-log.rule.js +110 -0
- package/dist/builtin-rules/static/general/no-empty-catch.rule.yaml +56 -0
- package/dist/builtin-rules/static/general/no-hardcoded-secret.rule.js +517 -0
- package/dist/builtin-rules/static/general/no-magic-number.rule.js +78 -0
- package/dist/builtin-rules/static/general/no-open-redirect.rule.js +46 -0
- package/dist/builtin-rules/static/general/no-todo-comment.rule.yaml +30 -0
- package/dist/builtin-rules/static/general/no-unresolved-import-symbol.rule.js +80 -0
- package/dist/builtin-rules/static/general/no-unused-export.rule.js +140 -0
- package/dist/builtin-rules/static/spring-boot/no-autowired-field.rule.js +162 -0
- package/dist/builtin-rules/static/spring-boot/no-business-logic-in-controller.rule.js +94 -0
- package/dist/builtin-rules/static/spring-boot/no-command-injection.rule.js +47 -0
- package/dist/builtin-rules/static/spring-boot/no-entity-in-controller.rule.yaml +52 -0
- package/dist/builtin-rules/static/spring-boot/no-nplus1-query-in-loop.rule.js +106 -0
- package/dist/builtin-rules/static/spring-boot/no-path-traversal.rule.js +47 -0
- package/dist/builtin-rules/static/spring-boot/no-spel-injection.rule.js +41 -0
- package/dist/builtin-rules/static/spring-boot/no-sql-string-concat.rule.js +194 -0
- package/dist/builtin-rules/static/spring-boot/no-ssrf.rule.js +49 -0
- package/dist/builtin-rules/static/spring-boot/no-transactional-self-invocation.rule.js +142 -0
- package/dist/builtin-rules/static/spring-boot/no-unclosed-resource.rule.js +108 -0
- package/dist/builtin-rules/static/spring-boot/no-unsafe-shared-formatter.rule.js +118 -0
- package/dist/builtin-rules/static/spring-boot/repository-naming.rule.yaml +42 -0
- package/dist/builtin-rules/static/spring-boot/restful-naming.rule.yaml +39 -0
- package/dist/builtin-rules/static/spring-boot/transaction-on-service.rule.yaml +58 -0
- package/dist/builtin-rules/static/spring-boot/validate-input.rule.js +123 -0
- package/dist/builtin-rules/vauthz/static/spring-boot/require-authz-check.rule.js +101 -0
- package/dist/index.d.ts +225 -48
- package/dist/index.js +1190 -815
- package/node_modules/@code-sentinel/core/index.js +55 -0
- package/node_modules/@code-sentinel/core/package.json +6 -0
- package/node_modules/@code-sentinel/parsers/index.js +13 -0
- package/node_modules/@code-sentinel/parsers/package.json +6 -0
- package/package.json +34 -29
- package/src/migrations/0000_initial.sql +62 -0
- package/src/migrations/0001_add_confidence.sql +7 -0
- package/src/migrations/0002_add_ai_stats.sql +21 -0
- package/src/migrations/0003_add_fix_recipe.sql +29 -0
- package/src/migrations/0004_add_ast_graph.sql +61 -0
- package/src/migrations/0005_add_project_id.sql +1 -0
- package/src/migrations/0006_add_ai_model.sql +5 -0
- package/src/migrations/0006_add_rule_results.sql +1 -0
- package/src/migrations/0007_add_finding_metadata.sql +4 -0
- package/src/migrations/0008_add_coverage.sql +2 -0
- package/src/migrations/0009_run_provenance.sql +5 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
Bạn là senior Angular/RxJS reviewer. Đánh giá Angular review unit dưới đây về **async flow, cancellation, và error state**.
|
|
2
|
+
|
|
3
|
+
## CRITICAL RULES
|
|
4
|
+
|
|
5
|
+
CRITICAL NON-VIOLATIONS:
|
|
6
|
+
|
|
7
|
+
- NEVER report a component call to an injected signal store / NgRx signal-store `rxMethod` as a direct Observable subscription.
|
|
8
|
+
- NEVER report missing component-level `catchError`, `finalize`, or unsubscribe when the support store/service method owns the Observable pipeline with `tapResponse`, `catchError`, `finalize`, `withCallState`, or equivalent error/loading handling.
|
|
9
|
+
- NEVER report `ngOnDestroy()` containing only `form.reset()` as an RxJS leak or cancellation issue.
|
|
10
|
+
- NEVER report plain component calls like `this.articleStore.getArticle(...)` / `this.articleStore.getComments(...)` as missing unsubscribe when support evidence shows those methods are NgRx signal-store `rxMethod` pipelines.
|
|
11
|
+
|
|
12
|
+
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.
|
|
13
|
+
2. **`line` BẮT BUỘC trỏ về PRIMARY file**.
|
|
14
|
+
3. **Confidence `<50` → KHÔNG emit**.
|
|
15
|
+
|
|
16
|
+
## Chỉ flag khi có rủi ro bug cụ thể
|
|
17
|
+
|
|
18
|
+
- Nested `subscribe` hoặc subscribe bên trong callback async tạo race/duplicate side effects/khó cancel.
|
|
19
|
+
- Search/filter/autocomplete/load-latest flow dùng `mergeMap`, subscribe thủ công, hoặc Promise mà không cancel request cũ; nên dùng `switchMap`, `takeUntilDestroyed`, hoặc stream composition.
|
|
20
|
+
- Loading/saving flag được set `true` nhưng không reset trong error/cancel path (`finalize` thiếu).
|
|
21
|
+
- Error bị swallow trong Observable/Promise chain khiến UI giữ trạng thái success/loading sai.
|
|
22
|
+
- Side effect phụ thuộc order response nhưng code không bảo vệ out-of-order response.
|
|
23
|
+
- Component gọi service Observable/Subject theo flow làm mất cancellation/error propagation/loading consistency.
|
|
24
|
+
|
|
25
|
+
## KHÔNG flag
|
|
26
|
+
|
|
27
|
+
- `.subscribe()` chỉ vì thiếu unsubscribe nếu static `angular/no-leaky-subscription` đã bắt và không có bug flow khác.
|
|
28
|
+
- Stream đơn giản dùng `async` pipe, `take(1)`, `firstValueFrom` có `try/catch`, hoặc `switchMap` đúng chỗ.
|
|
29
|
+
- Vấn đề naming/style thuần túy.
|
|
30
|
+
- Test/spec/generated files.
|
|
31
|
+
|
|
32
|
+
## Code cần review
|
|
33
|
+
|
|
34
|
+
Additional non-violations:
|
|
35
|
+
|
|
36
|
+
- Calling an injected signal store method / NgRx signal-store `rxMethod` from a component is NOT a direct Observable subscription. Do not flag missing `catchError`, `finalize`, or unsubscribe in the component when the support store method owns the Observable pipeline.
|
|
37
|
+
- If the support store/service uses `tapResponse`, `catchError`, `finalize`, `withCallState`, or an equivalent error/loading handler for the invoked method, do not report the component call site as missing error handling.
|
|
38
|
+
- `ngOnDestroy()` with only `form.reset()` or other Reactive Form cleanup is NOT an RxJS subscription leak.
|
|
39
|
+
- A resolver or component that triggers a store load method is not a race/cancellation bug unless there are multiple competing requests or stale response ordering shown in the cluster.
|
|
40
|
+
|
|
41
|
+
Primary file: {{file}}
|
|
42
|
+
Language: {{language}}
|
|
43
|
+
|
|
44
|
+
```{{language}}
|
|
45
|
+
{{code}}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Support files cùng cluster
|
|
49
|
+
|
|
50
|
+
Các file dưới đây có thể gồm service, external template, 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.
|
|
51
|
+
|
|
52
|
+
{{cluster_summary}}
|
|
53
|
+
|
|
54
|
+
## Output yêu cầu
|
|
55
|
+
|
|
56
|
+
Trả về **JSON HỢP LỆ DUY NHẤT** (không markdown fence, không text khác) theo schema:
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
{
|
|
60
|
+
"violations": [
|
|
61
|
+
{
|
|
62
|
+
"line": <số nguyên dương, 1-based>,
|
|
63
|
+
"endLine": <số nguyên dương | null>,
|
|
64
|
+
"message": "<≤200 ký tự, tiếng Việt>",
|
|
65
|
+
"suggestion": "<gợi ý fix | null>",
|
|
66
|
+
"confidence": <số nguyên 0-100>
|
|
67
|
+
}
|
|
68
|
+
]
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Nếu không có vấn đề rõ ràng: `{"violations": []}`.
|
|
73
|
+
|
|
74
|
+
## REPEAT CRITICAL RULES
|
|
75
|
+
|
|
76
|
+
- `line` phải trỏ về PRIMARY file, không dùng line từ support file.
|
|
77
|
+
- Không duplicate static rule `no-leaky-subscription`; chỉ flag khi có flow bug.
|
|
78
|
+
- Chỉ report khi có race/cancel/error-state cụ thể.
|
|
79
|
+
- Do not flag component calls into signal-store `rxMethod` methods as subscription leaks or uncancelled requests.
|
|
80
|
+
- Confidence `<50` → KHÔNG emit.
|
|
81
|
+
|
|
82
|
+
Đừng giải thích. JSON thuần.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
id: angular/rxjs-flow-risk
|
|
2
|
+
version: 4
|
|
3
|
+
kind: ai
|
|
4
|
+
title: "Angular RxJS async flow có rủi ro không?"
|
|
5
|
+
description: |
|
|
6
|
+
Dùng LLM để phát hiện lỗi flow RxJS/async trong Angular mà static rule
|
|
7
|
+
`no-leaky-subscription` không đủ ngữ cảnh để kết luận:
|
|
8
|
+
- Nested subscribe / subscribe-in-subscribe gây race, callback pyramid, hoặc
|
|
9
|
+
thiếu cancellation.
|
|
10
|
+
- Request/search flow không cancel request cũ (`mergeMap`/manual subscribe)
|
|
11
|
+
khi hành vi cần latest-only (`switchMap`).
|
|
12
|
+
- Missing error handling khiến loading flag kẹt hoặc UI báo success sai.
|
|
13
|
+
- Mixing Promise/Observable thủ công làm mất cancellation hoặc duplicate side
|
|
14
|
+
effects.
|
|
15
|
+
severity: warning
|
|
16
|
+
category: async-flow
|
|
17
|
+
languages: [typescript]
|
|
18
|
+
scope: angular
|
|
19
|
+
baseConfidence: 60
|
|
20
|
+
prompt: ./rxjs-flow-risk.prompt.md
|
|
21
|
+
contextScope: per-cluster
|
|
22
|
+
maxTokens: 1200
|
|
23
|
+
aiConfig:
|
|
24
|
+
tier: regular
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
Bạn là senior Angular reviewer. Đánh giá Angular review unit dưới đây về **contract giữa template và component class**.
|
|
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 nullable-template issue when support model evidence shows the nested field is non-null/required, for example `Article.author: Profile` and `Profile.username: string`.
|
|
12
|
+
- NEVER report a required Angular signal input (`input.required<T>()`) as nullable by itself. Treat it as a component API contract unless the template passes a proven nullable value.
|
|
13
|
+
- NEVER report a typed output payload property such as `{ commentId: number; slug: string }` as nullable/missing when the event source declares that exact payload shape.
|
|
14
|
+
- NEVER infer nullability only from a signal/store-selector field name such as `$article`, `$isAuthenticated`, `$currentUser`, or `$comments`. Require explicit nullable/optional type, nullable initializer, or unguarded nullable support evidence.
|
|
15
|
+
- NEVER report a template value guarded by Angular control flow such as `@if ($article(); as article)` or an authenticated branch such as `@if ($isAuthenticated())` unless the guarded branch still passes a proven nullable value.
|
|
16
|
+
- NEVER report component class signal/store/computed field declarations as template-contract problems by themselves, for example `$authorUsername = this.articleStore.data.author.username`, `$isAuthenticated = this.authStore.loggedIn`, `$currentUser = this.authStore.user`, or `$canModify = computed(...)`.
|
|
17
|
+
- NEVER report a primary class line unless the issue is that a template binding/call does not match the class API. This rule is about template-to-class contract, not internal class field initialization style.
|
|
18
|
+
|
|
19
|
+
## Chỉ flag khi có bằng chứng rõ trong file
|
|
20
|
+
|
|
21
|
+
- Inline template tham chiếu property/method không tồn tại trong component class.
|
|
22
|
+
- External template trong cluster tham chiếu property/method không tồn tại trong component class.
|
|
23
|
+
- Template gọi method với số lượng/thứ tự/kiểu tham số rõ ràng không khớp signature.
|
|
24
|
+
- Template truy cập nested property có thể `undefined` mà không guard (`?.`, `@if`, `*ngIf`) trong khi class khởi tạo nullable/optional.
|
|
25
|
+
- `*ngFor` hoặc `@for` render collection có thể undefined/null mà không fallback/guard.
|
|
26
|
+
- Two-way binding trỏ vào object path có thể undefined.
|
|
27
|
+
|
|
28
|
+
## KHÔNG flag
|
|
29
|
+
|
|
30
|
+
- `templateUrl` chỉ được review khi support files có template body tương ứng trong cluster.
|
|
31
|
+
- Binding hợp lệ với Angular built-ins, pipes, local template variables, `$event`, `index`, `track`, `let`.
|
|
32
|
+
- Các lỗi đã chắc chắn được Angular compiler bắt nếu không có thêm context runtime; ưu tiên bug user-facing có thể lọt khi template checking yếu.
|
|
33
|
+
- Test/spec/generated files.
|
|
34
|
+
|
|
35
|
+
## Code cần review
|
|
36
|
+
|
|
37
|
+
Primary file: {{file}}
|
|
38
|
+
Language: {{language}}
|
|
39
|
+
|
|
40
|
+
```{{language}}
|
|
41
|
+
{{code}}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Support files cùng cluster
|
|
45
|
+
|
|
46
|
+
Các file dưới đây có thể gồm external template, service, model, pipe/directive/module cùng feature. Với rule này, ưu tiên đối chiếu template trong support files với class ở primary file.
|
|
47
|
+
|
|
48
|
+
{{cluster_summary}}
|
|
49
|
+
|
|
50
|
+
## Output yêu cầu
|
|
51
|
+
|
|
52
|
+
Trả về **JSON HỢP LỆ DUY NHẤT** (không markdown fence, không text khác) theo schema:
|
|
53
|
+
|
|
54
|
+
```
|
|
55
|
+
{
|
|
56
|
+
"violations": [
|
|
57
|
+
{
|
|
58
|
+
"line": <số nguyên dương, 1-based>,
|
|
59
|
+
"endLine": <số nguyên dương | null>,
|
|
60
|
+
"message": "<≤200 ký tự, tiếng Việt>",
|
|
61
|
+
"suggestion": "<gợi ý fix | null>",
|
|
62
|
+
"confidence": <số nguyên 0-100>
|
|
63
|
+
}
|
|
64
|
+
]
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Nếu không có vấn đề rõ ràng: `{"violations": []}`.
|
|
69
|
+
|
|
70
|
+
## REPEAT CRITICAL RULES
|
|
71
|
+
|
|
72
|
+
- `line` phải trỏ về PRIMARY file, không dùng line từ support file.
|
|
73
|
+
- Không thay thế Angular compiler; chỉ flag bug contract user-facing.
|
|
74
|
+
- Chỉ report khi có bằng chứng rõ trong file.
|
|
75
|
+
- Do not flag `input.required<T>()`, typed event payload fields, or nested properties whose support model types prove they are non-null.
|
|
76
|
+
- Do not infer nullability from `$` signal/store selector names; require explicit nullable/optional evidence.
|
|
77
|
+
- Do not flag class field declarations such as `$authorUsername`, `$isAuthenticated`, `$currentUser`, or `$canModify` unless a template binding has a proven contract mismatch.
|
|
78
|
+
- Confidence `<50` → KHÔNG emit.
|
|
79
|
+
|
|
80
|
+
Đừng giải thích. JSON thuần.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
id: angular/template-contract-risk
|
|
2
|
+
version: 4
|
|
3
|
+
kind: ai
|
|
4
|
+
title: "Angular template/component contract có rủi ro runtime không?"
|
|
5
|
+
description: |
|
|
6
|
+
Dùng LLM để review contract giữa inline template và component class trong
|
|
7
|
+
cùng file:
|
|
8
|
+
- Template bind tới property/method không tồn tại hoặc sai nullability rõ ràng.
|
|
9
|
+
- Event handler trong template gọi method với tham số/order dễ sai so với
|
|
10
|
+
signature trong class.
|
|
11
|
+
- `*ngFor`/`@for` render collection có thể undefined mà template không guard.
|
|
12
|
+
- Form binding / two-way binding trỏ vào nested property có thể undefined.
|
|
13
|
+
|
|
14
|
+
Không thay thế Angular compiler; rule này tìm các bug contract có thể thấy
|
|
15
|
+
trong một file khi project chưa chạy typecheck/template-check đầy đủ.
|
|
16
|
+
severity: warning
|
|
17
|
+
category: angular-template
|
|
18
|
+
languages: [typescript]
|
|
19
|
+
scope: angular
|
|
20
|
+
baseConfidence: 60
|
|
21
|
+
prompt: ./template-contract-risk.prompt.md
|
|
22
|
+
contextScope: per-cluster
|
|
23
|
+
maxTokens: 1200
|
|
24
|
+
aiConfig:
|
|
25
|
+
tier: regular
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
Bạn là senior Flutter security reviewer. Đánh giá review unit dưới đây về **dynamic content/file flow**.
|
|
2
|
+
|
|
3
|
+
## CRITICAL RULES
|
|
4
|
+
|
|
5
|
+
1. Chỉ report khi có luồng cụ thể trong primary/support files.
|
|
6
|
+
2. `line` phải trỏ về PRIMARY file.
|
|
7
|
+
3. Không duplicate static rules về WebView JS guard hoặc ZIP extraction hardening nếu chỉ cùng bằng chứng pattern.
|
|
8
|
+
4. Confidence `<50` thì không emit.
|
|
9
|
+
|
|
10
|
+
## Chỉ flag khi có rủi ro ngữ cảnh
|
|
11
|
+
|
|
12
|
+
- Remote URL/WebView/content source được điều khiển bởi API/user mà thiếu trust boundary rõ ràng.
|
|
13
|
+
- Downloaded asset/ZIP/theme/config có thể thay đổi UI/logic quan trọng mà thiếu versioning/rollback/validation theo flow.
|
|
14
|
+
- File/image picker upload hoặc import file thiếu kiểm tra MIME/size/extension/content.
|
|
15
|
+
- `url_launcher`/deep link mở URL từ API/user thiếu scheme/host allowlist.
|
|
16
|
+
- Dynamic content cache không invalidation, dùng nhầm tenant/user/environment.
|
|
17
|
+
|
|
18
|
+
## Không flag
|
|
19
|
+
|
|
20
|
+
- Chỉ thấy WebView unrestricted hoặc ZIP extraction pattern đã đủ cho static rule.
|
|
21
|
+
- File picker dùng rõ MIME/size guard và upload endpoint kiểm soát.
|
|
22
|
+
- Remote image/icon public không ảnh hưởng logic/security.
|
|
23
|
+
|
|
24
|
+
Primary file: {{file}}
|
|
25
|
+
Language: {{language}}
|
|
26
|
+
|
|
27
|
+
```{{language}}
|
|
28
|
+
{{code}}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Support files cùng cluster
|
|
32
|
+
|
|
33
|
+
{{cluster_summary}}
|
|
34
|
+
|
|
35
|
+
## Output yêu cầu
|
|
36
|
+
|
|
37
|
+
Trả về JSON hợp lệ duy nhất:
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
{
|
|
41
|
+
"violations": [
|
|
42
|
+
{
|
|
43
|
+
"line": 1,
|
|
44
|
+
"endLine": null,
|
|
45
|
+
"message": "<≤200 ký tự, tiếng Việt>",
|
|
46
|
+
"suggestion": "<gợi ý fix | null>",
|
|
47
|
+
"confidence": 0
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Nếu không có vấn đề rõ: `{"violations": []}`.
|
|
54
|
+
|
|
55
|
+
Đừng giải thích. JSON thuần.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
id: flutter/dynamic-content-risk
|
|
2
|
+
version: 1
|
|
3
|
+
kind: ai
|
|
4
|
+
title: "Flutter dynamic content/file flow có rủi ro không?"
|
|
5
|
+
description: |
|
|
6
|
+
Review WebView, remote URL, downloaded assets/ZIP, file/image picker và
|
|
7
|
+
dynamic content flows vượt ngoài khả năng static pattern đơn lẻ.
|
|
8
|
+
severity: warning
|
|
9
|
+
category: flutter-security
|
|
10
|
+
languages: [dart]
|
|
11
|
+
scope: flutter
|
|
12
|
+
baseConfidence: 60
|
|
13
|
+
prompt: ./dynamic-content-risk.prompt.md
|
|
14
|
+
contextScope: per-cluster
|
|
15
|
+
maxTokens: 1400
|
|
16
|
+
aiConfig:
|
|
17
|
+
tier: regular
|
|
18
|
+
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
Bạn là senior Flutter reviewer. Đánh giá review unit dưới đây về **feature state flow**.
|
|
2
|
+
|
|
3
|
+
## CRITICAL RULES
|
|
4
|
+
|
|
5
|
+
1. Chỉ report bug có bằng chứng cụ thể, không đoán convention ngoài cluster.
|
|
6
|
+
2. `line` phải trỏ về PRIMARY file.
|
|
7
|
+
3. Không duplicate static rules bảo mật.
|
|
8
|
+
4. Confidence `<50` thì không emit.
|
|
9
|
+
5. Không emit nếu không chỉ ra được async branch/caller/state transition cụ thể gây lỗi.
|
|
10
|
+
|
|
11
|
+
## Chỉ flag khi có flow cụ thể
|
|
12
|
+
|
|
13
|
+
- Loading/error/empty/success state thiếu nhánh làm UI treo hoặc hiển thị dữ liệu cũ.
|
|
14
|
+
- Cubit/Bloc/ChangeNotifier emit state sau dispose/close hoặc sau request đã bị cancel.
|
|
15
|
+
- Submit/tap/action có thể chạy trùng do không khóa loading hoặc debounce.
|
|
16
|
+
- Repository/API trả lỗi/null nhưng caller coi là success.
|
|
17
|
+
- Auth/permission failure không đưa user về flow phù hợp.
|
|
18
|
+
- State cache bị stale khi route param/input/filter đổi.
|
|
19
|
+
|
|
20
|
+
## Không flag
|
|
21
|
+
|
|
22
|
+
- Chỉ thiếu test hoặc style naming.
|
|
23
|
+
- Một màn hình đơn giản có state rõ và không có async flow.
|
|
24
|
+
- Vấn đề UI responsive/accessibility thuần túy, hãy để rule UI xử lý.
|
|
25
|
+
- Nhận xét chung chung kiểu “nên xử lý lỗi/loading” nhưng không có branch/caller cụ thể.
|
|
26
|
+
|
|
27
|
+
Primary file: {{file}}
|
|
28
|
+
Language: {{language}}
|
|
29
|
+
|
|
30
|
+
```{{language}}
|
|
31
|
+
{{code}}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Support files cùng cluster
|
|
35
|
+
|
|
36
|
+
{{cluster_summary}}
|
|
37
|
+
|
|
38
|
+
## Output yêu cầu
|
|
39
|
+
|
|
40
|
+
Trả về JSON hợp lệ duy nhất:
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
{
|
|
44
|
+
"violations": [
|
|
45
|
+
{
|
|
46
|
+
"line": 1,
|
|
47
|
+
"endLine": null,
|
|
48
|
+
"message": "<≤200 ký tự, tiếng Việt>",
|
|
49
|
+
"suggestion": "<gợi ý fix | null>",
|
|
50
|
+
"confidence": 0
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Nếu không có vấn đề rõ: `{"violations": []}`.
|
|
57
|
+
|
|
58
|
+
Đừng giải thích. JSON thuần.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
id: flutter/feature-state-flow-risk
|
|
2
|
+
version: 1
|
|
3
|
+
kind: ai
|
|
4
|
+
title: "Flutter feature state/API flow có rủi ro không?"
|
|
5
|
+
description: |
|
|
6
|
+
Review page/cubit/bloc/state/repository/API flow về loading/error/empty/auth,
|
|
7
|
+
stale state, duplicate submit và xử lý lifecycle khó bắt bằng static rules.
|
|
8
|
+
severity: warning
|
|
9
|
+
category: flutter-flow
|
|
10
|
+
languages: [dart]
|
|
11
|
+
scope: flutter
|
|
12
|
+
baseConfidence: 60
|
|
13
|
+
prompt: ./feature-state-flow-risk.prompt.md
|
|
14
|
+
contextScope: per-cluster
|
|
15
|
+
maxTokens: 1400
|
|
16
|
+
aiConfig:
|
|
17
|
+
tier: regular
|
|
18
|
+
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
Bạn là senior Flutter/native mobile reviewer. Đánh giá review unit dưới đây về **consistency giữa Dart và native Android/iOS config**.
|
|
2
|
+
|
|
3
|
+
## CRITICAL RULES
|
|
4
|
+
|
|
5
|
+
1. Chỉ report khi có bằng chứng trong primary hoặc support files.
|
|
6
|
+
2. `line` phải trỏ về PRIMARY file.
|
|
7
|
+
3. Không duplicate static findings về từng permission/key; chỉ report khi thấy lệch giữa Dart usage và native config.
|
|
8
|
+
4. Confidence `<50` thì không emit.
|
|
9
|
+
|
|
10
|
+
## Chỉ flag khi có lệch cụ thể
|
|
11
|
+
|
|
12
|
+
- Dart dùng camera/location/photos/files/biometric/url_launcher/webview nhưng AndroidManifest/Info.plist thiếu hoặc thừa config liên quan.
|
|
13
|
+
- Native permission/privacy key tồn tại nhưng Dart usage trong feature không cần, gây over-permission.
|
|
14
|
+
- URL scheme/query scheme/deep link cấu hình lệch với code gọi.
|
|
15
|
+
- Android/iOS behavior khác nhau vì chỉ một platform được cấu hình.
|
|
16
|
+
- File sharing/document opening bật nhưng Dart lưu file nhạy cảm vào Documents/cache không kiểm soát.
|
|
17
|
+
|
|
18
|
+
## Không flag
|
|
19
|
+
|
|
20
|
+
- Chỉ thấy permission/key đơn lẻ mà không có Dart usage liên quan.
|
|
21
|
+
- Thiếu bằng chứng native support files trong cluster.
|
|
22
|
+
- Static manifest/plist hardening đã report cùng vấn đề.
|
|
23
|
+
|
|
24
|
+
Primary file: {{file}}
|
|
25
|
+
Language: {{language}}
|
|
26
|
+
|
|
27
|
+
```{{language}}
|
|
28
|
+
{{code}}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Support files cùng cluster
|
|
32
|
+
|
|
33
|
+
{{cluster_summary}}
|
|
34
|
+
|
|
35
|
+
## Output yêu cầu
|
|
36
|
+
|
|
37
|
+
Trả về JSON hợp lệ duy nhất:
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
{
|
|
41
|
+
"violations": [
|
|
42
|
+
{
|
|
43
|
+
"line": 1,
|
|
44
|
+
"endLine": null,
|
|
45
|
+
"message": "<≤200 ký tự, tiếng Việt>",
|
|
46
|
+
"suggestion": "<gợi ý fix | null>",
|
|
47
|
+
"confidence": 0
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Nếu không có vấn đề rõ: `{"violations": []}`.
|
|
54
|
+
|
|
55
|
+
Đừng giải thích. JSON thuần.
|
|
56
|
+
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
id: flutter/native-platform-consistency-risk
|
|
2
|
+
version: 1
|
|
3
|
+
kind: ai
|
|
4
|
+
title: "Flutter Dart/native permission config có lệch nhau không?"
|
|
5
|
+
description: |
|
|
6
|
+
So sánh Dart usage với AndroidManifest/Info.plist/support files để phát hiện
|
|
7
|
+
permission, privacy key, URL scheme, file sharing hoặc platform config lệch.
|
|
8
|
+
severity: warning
|
|
9
|
+
category: flutter-native
|
|
10
|
+
languages: [dart]
|
|
11
|
+
scope: flutter
|
|
12
|
+
baseConfidence: 58
|
|
13
|
+
prompt: ./native-platform-consistency-risk.prompt.md
|
|
14
|
+
contextScope: per-cluster
|
|
15
|
+
maxTokens: 1500
|
|
16
|
+
aiConfig:
|
|
17
|
+
tier: regular
|
|
18
|
+
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
Bạn là senior Flutter mobile reviewer. Đánh giá review unit dưới đây về **network/auth flow**.
|
|
2
|
+
|
|
3
|
+
## CRITICAL RULES
|
|
4
|
+
|
|
5
|
+
1. Chỉ report lỗi có bằng chứng cụ thể trong primary/support files.
|
|
6
|
+
2. `line` phải trỏ về PRIMARY file.
|
|
7
|
+
3. Không duplicate static rules về manifest, plist, log leak, WebView, Hive, env.
|
|
8
|
+
4. Confidence `<50` thì không emit.
|
|
9
|
+
5. Không emit nếu không chỉ ra được network/auth branch, caller hoặc sink cụ thể.
|
|
10
|
+
|
|
11
|
+
## Chỉ flag khi có flow cụ thể
|
|
12
|
+
|
|
13
|
+
- Dio interceptor refresh token retry sai: retry loop vô hạn, mất request body, refresh song song race, không đồng bộ logout/session expiry.
|
|
14
|
+
- Base URL/environment switching có thể gọi nhầm dev/staging/prod hoặc đổi runtime không kiểm soát.
|
|
15
|
+
- CancelToken/error handling khiến UI treo loading, nuốt lỗi auth/network, hoặc retry sau khi user đã rời màn.
|
|
16
|
+
- Token/header được thêm/bỏ không nhất quán giữa request thường, refresh, upload/download.
|
|
17
|
+
- Mapping lỗi API thiếu phân loại auth/permission/validation/network làm caller xử lý sai.
|
|
18
|
+
|
|
19
|
+
## Không flag
|
|
20
|
+
|
|
21
|
+
- Chỉ thấy Dio/Retrofit usage bình thường không có flow lỗi.
|
|
22
|
+
- Vấn đề log/token storage/WebView đã thuộc static rules.
|
|
23
|
+
- Preference style không tạo bug runtime.
|
|
24
|
+
- Nhận xét chung chung về retry/error/auth mà không nêu request path/caller/interceptor cụ thể.
|
|
25
|
+
|
|
26
|
+
Primary file: {{file}}
|
|
27
|
+
Language: {{language}}
|
|
28
|
+
|
|
29
|
+
```{{language}}
|
|
30
|
+
{{code}}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Support files cùng cluster
|
|
34
|
+
|
|
35
|
+
{{cluster_summary}}
|
|
36
|
+
|
|
37
|
+
## Output yêu cầu
|
|
38
|
+
|
|
39
|
+
Trả về JSON hợp lệ duy nhất:
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
{
|
|
43
|
+
"violations": [
|
|
44
|
+
{
|
|
45
|
+
"line": 1,
|
|
46
|
+
"endLine": null,
|
|
47
|
+
"message": "<≤200 ký tự, tiếng Việt>",
|
|
48
|
+
"suggestion": "<gợi ý fix | null>",
|
|
49
|
+
"confidence": 0
|
|
50
|
+
}
|
|
51
|
+
]
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Nếu không có vấn đề rõ: `{"violations": []}`.
|
|
56
|
+
|
|
57
|
+
Đừng giải thích. JSON thuần.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
id: flutter/network-auth-flow-risk
|
|
2
|
+
version: 1
|
|
3
|
+
kind: ai
|
|
4
|
+
title: "Flutter network/auth flow có rủi ro không?"
|
|
5
|
+
description: |
|
|
6
|
+
Review Dio/interceptor/auth flow mà static pattern khó kết luận:
|
|
7
|
+
refresh token, retry, cancel token, baseUrl switching, error handling,
|
|
8
|
+
logout/session expiry và masking dữ liệu nhạy cảm theo luồng.
|
|
9
|
+
severity: warning
|
|
10
|
+
category: flutter-flow
|
|
11
|
+
languages: [dart]
|
|
12
|
+
scope: flutter
|
|
13
|
+
baseConfidence: 60
|
|
14
|
+
prompt: ./network-auth-flow-risk.prompt.md
|
|
15
|
+
contextScope: per-cluster
|
|
16
|
+
maxTokens: 1400
|
|
17
|
+
aiConfig:
|
|
18
|
+
tier: regular
|
|
19
|
+
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
Bạn là senior Flutter UI reviewer. Đánh giá review unit dưới đây về **responsive UI và accessibility**.
|
|
2
|
+
|
|
3
|
+
## CRITICAL RULES
|
|
4
|
+
|
|
5
|
+
1. Chỉ report khi có bằng chứng cụ thể trong widget tree.
|
|
6
|
+
2. `line` phải trỏ về PRIMARY file.
|
|
7
|
+
3. Không yêu cầu screenshot/render app thật.
|
|
8
|
+
4. Confidence `<70` thì không emit.
|
|
9
|
+
5. Tối đa 3 violations; ưu tiên lỗi có bằng chứng widget/pattern rõ nhất.
|
|
10
|
+
|
|
11
|
+
## Chỉ flag khi có rủi ro rõ
|
|
12
|
+
|
|
13
|
+
- Row/Column/Stack với text/dynamic content dễ overflow vì thiếu Expanded/Flexible/scroll/constraint.
|
|
14
|
+
- Hard-coded width/height/padding/font làm vỡ iPad, màn nhỏ hoặc textScaleFactor lớn.
|
|
15
|
+
- Empty/error/loading state thiếu trong list/page async dẫn tới blank screen.
|
|
16
|
+
- Touch target quá nhỏ hoặc icon-only action quan trọng thiếu label/tooltip/semantics.
|
|
17
|
+
- Form field/error text không có accessibility/validation feedback đủ rõ.
|
|
18
|
+
- Dialog/bottom sheet không xử lý keyboard/safe area/scroll.
|
|
19
|
+
|
|
20
|
+
## Không flag
|
|
21
|
+
|
|
22
|
+
- Preference màu sắc/style nếu không tạo lỗi UX cụ thể.
|
|
23
|
+
- Layout đã có Expanded/Flexible/ListView/SingleChildScrollView hợp lý.
|
|
24
|
+
- Vấn đề business flow không thuộc UI.
|
|
25
|
+
- Rủi ro “có thể overflow” chung chung nhưng không nêu widget cụ thể, text/dynamic content cụ thể và constraint thiếu.
|
|
26
|
+
|
|
27
|
+
Primary file: {{file}}
|
|
28
|
+
Language: {{language}}
|
|
29
|
+
|
|
30
|
+
```{{language}}
|
|
31
|
+
{{code}}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Support files cùng cluster
|
|
35
|
+
|
|
36
|
+
{{cluster_summary}}
|
|
37
|
+
|
|
38
|
+
## Output yêu cầu
|
|
39
|
+
|
|
40
|
+
Trả về JSON hợp lệ duy nhất:
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
{
|
|
44
|
+
"violations": [
|
|
45
|
+
{
|
|
46
|
+
"line": 1,
|
|
47
|
+
"endLine": null,
|
|
48
|
+
"message": "<≤200 ký tự, tiếng Việt>",
|
|
49
|
+
"suggestion": "<gợi ý fix | null>",
|
|
50
|
+
"confidence": 0,
|
|
51
|
+
"rootCauseKey": "<kebab-case pattern, optional>",
|
|
52
|
+
"tags": ["flutter-ui"]
|
|
53
|
+
}
|
|
54
|
+
]
|
|
55
|
+
}
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Nếu không có vấn đề rõ: `{"violations": []}`.
|
|
59
|
+
|
|
60
|
+
Đừng giải thích. JSON thuần.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
id: flutter/ui-responsive-accessibility-risk
|
|
2
|
+
version: 1
|
|
3
|
+
kind: ai
|
|
4
|
+
title: "Flutter UI responsive/accessibility có rủi ro không?"
|
|
5
|
+
description: |
|
|
6
|
+
Review UI Flutter về mobile/iPad responsive, overflow, empty/error state,
|
|
7
|
+
text scaling, touch target và semantics khi cần hiểu widget tree/ngữ cảnh.
|
|
8
|
+
severity: warning
|
|
9
|
+
category: flutter-ui
|
|
10
|
+
languages: [dart]
|
|
11
|
+
scope: flutter
|
|
12
|
+
baseConfidence: 70
|
|
13
|
+
prompt: ./ui-responsive-accessibility-risk.prompt.md
|
|
14
|
+
contextScope: per-cluster
|
|
15
|
+
maxTokens: 1400
|
|
16
|
+
aiConfig:
|
|
17
|
+
tier: regular
|
|
18
|
+
numMaxFindings: 3
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
Bạn là senior code reviewer. Đánh giá đoạn TypeScript/JavaScript dưới đây về **tính rõ ràng (clarity)**.
|
|
2
|
+
|
|
3
|
+
## Tiêu chí flag (chỉ flag khi RÕ RÀNG có vấn đề)
|
|
4
|
+
|
|
5
|
+
- Tên hàm hoặc biến không nói lên ý nghĩa (1-2 ký tự không phải `i`/`j`/`k` trong loop, hoặc `tmp` / `data` / `result` không có ngữ cảnh).
|
|
6
|
+
- Logic lồng quá sâu (≥4 cấp if/for/try).
|
|
7
|
+
- Comment giải thích cái đã rõ trong code (kiểu `// increment i`), hoặc comment lệch hành vi.
|
|
8
|
+
- String literal bí ẩn làm code khó hiểu khi **không** phải route path, event name, i18n key, enum-like value, test fixture, hoặc message hiển thị.
|
|
9
|
+
|
|
10
|
+
## KHÔNG flag
|
|
11
|
+
|
|
12
|
+
- Function nội bộ tầm thường (helper 1-2 dòng).
|
|
13
|
+
- Test/spec files (*.test.ts, *.spec.ts, __tests__).
|
|
14
|
+
- Generated code.
|
|
15
|
+
- Tên ngắn nhưng theo convention rộng rãi (`i` trong loop, `e` trong catch).
|
|
16
|
+
|
|
17
|
+
## Code cần review
|
|
18
|
+
|
|
19
|
+
File: {{file}}
|
|
20
|
+
Language: {{language}}
|
|
21
|
+
|
|
22
|
+
```{{language}}
|
|
23
|
+
{{code}}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Output yêu cầu
|
|
27
|
+
|
|
28
|
+
Trả về **JSON HỢP LỆ DUY NHẤT** (không markdown fence, không text khác) theo schema:
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
{
|
|
32
|
+
"violations": [
|
|
33
|
+
{
|
|
34
|
+
"line": <số nguyên dương, 1-based>,
|
|
35
|
+
"endLine": <số nguyên dương | null>,
|
|
36
|
+
"message": "<≤200 ký tự, tiếng Việt>",
|
|
37
|
+
"suggestion": "<gợi ý fix | null>",
|
|
38
|
+
"confidence": <số nguyên 0-100>
|
|
39
|
+
}
|
|
40
|
+
]
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
### Hướng dẫn cho `confidence`
|
|
45
|
+
|
|
46
|
+
Đánh giá KHÁCH QUAN, calibrated:
|
|
47
|
+
|
|
48
|
+
- **90-100**: gần như chắc chắn là vấn đề (tên `x`, `tmp`, `data` đơn lẻ không có context; string bí ẩn lặp lại không có tên; comment đối lập với code).
|
|
49
|
+
- **70-89**: pattern rõ là smell nhưng có thể là intentional (lồng 4 cấp trong một state machine; tên 2 ký tự trong toán học vector).
|
|
50
|
+
- **50-69**: borderline — cần human review (tên `result` ở một function rất ngắn; comment "obvious" nhưng có lý do giáo dục).
|
|
51
|
+
- **<50**: KHÔNG flag (đừng trả về). Nếu bạn không chắc chắn, đừng add vào violations.
|
|
52
|
+
|
|
53
|
+
KHÔNG inflate confidence. Một finding `confidence: 100` phải là vấn đề mà bất kỳ senior reviewer nào cũng đồng ý cần fix. Nếu có chỗ đáng review nhưng có thể là intentional → confidence 50-70.
|
|
54
|
+
|
|
55
|
+
Nếu code đã rõ ràng và không có vi phạm: `{"violations": []}`.
|
|
56
|
+
|
|
57
|
+
Đừng giải thích. JSON thuần.
|