archscribe 0.0.0-stage → 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.
- package/README.md +266 -2
- package/dist/cli/archscribe.d.ts +11 -0
- package/dist/cli/archscribe.js +340 -0
- package/dist/cli/archscribe.js.map +1 -0
- package/dist/cli/check.d.ts +17 -0
- package/dist/cli/check.js +67 -0
- package/dist/cli/check.js.map +1 -0
- package/dist/cli/clean.d.ts +2 -0
- package/dist/cli/clean.js +46 -0
- package/dist/cli/clean.js.map +1 -0
- package/dist/cli/commands.d.ts +4 -0
- package/dist/cli/commands.js +21 -0
- package/dist/cli/commands.js.map +1 -0
- package/dist/cli/compare.d.ts +2 -0
- package/dist/cli/compare.js +125 -0
- package/dist/cli/compare.js.map +1 -0
- package/dist/cli/config.d.ts +2 -0
- package/dist/cli/config.js +40 -0
- package/dist/cli/config.js.map +1 -0
- package/dist/cli/dashboard.d.ts +1 -0
- package/dist/cli/dashboard.js +16 -0
- package/dist/cli/dashboard.js.map +1 -0
- package/dist/cli/doctor.d.ts +20 -0
- package/dist/cli/doctor.js +169 -0
- package/dist/cli/doctor.js.map +1 -0
- package/dist/cli/evaluate.d.ts +9 -0
- package/dist/cli/evaluate.js +78 -0
- package/dist/cli/evaluate.js.map +1 -0
- package/dist/cli/history.d.ts +31 -0
- package/dist/cli/history.js +167 -0
- package/dist/cli/history.js.map +1 -0
- package/dist/cli/login.d.ts +5 -0
- package/dist/cli/login.js +49 -0
- package/dist/cli/login.js.map +1 -0
- package/dist/cli/logout.d.ts +5 -0
- package/dist/cli/logout.js +36 -0
- package/dist/cli/logout.js.map +1 -0
- package/dist/cli/menu/screens.d.ts +31 -0
- package/dist/cli/menu/screens.js +230 -0
- package/dist/cli/menu/screens.js.map +1 -0
- package/dist/cli/open.d.ts +2 -0
- package/dist/cli/open.js +28 -0
- package/dist/cli/open.js.map +1 -0
- package/dist/cli/rag.d.ts +4 -0
- package/dist/cli/rag.js +20 -0
- package/dist/cli/rag.js.map +1 -0
- package/dist/cli/run.d.ts +21 -0
- package/dist/cli/run.js +163 -0
- package/dist/cli/run.js.map +1 -0
- package/dist/cli/run_pipeline.d.ts +2 -0
- package/dist/cli/run_pipeline.js +103 -0
- package/dist/cli/run_pipeline.js.map +1 -0
- package/dist/cli/shell.d.ts +8 -0
- package/dist/cli/shell.js +38 -0
- package/dist/cli/shell.js.map +1 -0
- package/dist/cli/state.d.ts +42 -0
- package/dist/cli/state.js +99 -0
- package/dist/cli/state.js.map +1 -0
- package/dist/cli/status.d.ts +2 -0
- package/dist/cli/status.js +59 -0
- package/dist/cli/status.js.map +1 -0
- package/dist/cli/ui/animations.d.ts +19 -0
- package/dist/cli/ui/animations.js +161 -0
- package/dist/cli/ui/animations.js.map +1 -0
- package/dist/cli/ui/index.d.ts +4 -0
- package/dist/cli/ui/index.js +5 -0
- package/dist/cli/ui/index.js.map +1 -0
- package/dist/cli/ui/keys.d.ts +25 -0
- package/dist/cli/ui/keys.js +47 -0
- package/dist/cli/ui/keys.js.map +1 -0
- package/dist/cli/ui/mascot.d.ts +4 -0
- package/dist/cli/ui/mascot.js +53 -0
- package/dist/cli/ui/mascot.js.map +1 -0
- package/dist/cli/ui/menu.d.ts +86 -0
- package/dist/cli/ui/menu.js +268 -0
- package/dist/cli/ui/menu.js.map +1 -0
- package/dist/cli/ui/motions.d.ts +22 -0
- package/dist/cli/ui/motions.js +112 -0
- package/dist/cli/ui/motions.js.map +1 -0
- package/dist/cli/ui/stage.d.ts +25 -0
- package/dist/cli/ui/stage.js +296 -0
- package/dist/cli/ui/stage.js.map +1 -0
- package/dist/cli/ui/term.d.ts +98 -0
- package/dist/cli/ui/term.js +275 -0
- package/dist/cli/ui/term.js.map +1 -0
- package/dist/core/actor-inference.d.ts +25 -0
- package/dist/core/actor-inference.js +89 -0
- package/dist/core/actor-inference.js.map +1 -0
- package/dist/core/component-groups.d.ts +35 -0
- package/dist/core/component-groups.js +93 -0
- package/dist/core/component-groups.js.map +1 -0
- package/dist/core/docx-styles.d.ts +44 -0
- package/dist/core/docx-styles.js +45 -0
- package/dist/core/docx-styles.js.map +1 -0
- package/dist/core/docx.d.ts +11 -0
- package/dist/core/docx.js +310 -0
- package/dist/core/docx.js.map +1 -0
- package/dist/core/flow-steps-uc.d.ts +10 -0
- package/dist/core/flow-steps-uc.js +109 -0
- package/dist/core/flow-steps-uc.js.map +1 -0
- package/dist/core/flow-steps.d.ts +66 -0
- package/dist/core/flow-steps.js +814 -0
- package/dist/core/flow-steps.js.map +1 -0
- package/dist/core/flow-trace.d.ts +45 -0
- package/dist/core/flow-trace.js +131 -0
- package/dist/core/flow-trace.js.map +1 -0
- package/dist/core/flow.d.ts +13 -0
- package/dist/core/flow.js +379 -0
- package/dist/core/flow.js.map +1 -0
- package/dist/core/freshness.d.ts +22 -0
- package/dist/core/freshness.js +66 -0
- package/dist/core/freshness.js.map +1 -0
- package/dist/core/manifest.d.ts +35 -0
- package/dist/core/manifest.js +99 -0
- package/dist/core/manifest.js.map +1 -0
- package/dist/core/markdown.d.ts +21 -0
- package/dist/core/markdown.js +233 -0
- package/dist/core/markdown.js.map +1 -0
- package/dist/core/parser.d.ts +22 -0
- package/dist/core/parser.js +86 -0
- package/dist/core/parser.js.map +1 -0
- package/dist/core/project-config.d.ts +18 -0
- package/dist/core/project-config.js +30 -0
- package/dist/core/project-config.js.map +1 -0
- package/dist/core/review-ledger.d.ts +36 -0
- package/dist/core/review-ledger.js +104 -0
- package/dist/core/review-ledger.js.map +1 -0
- package/dist/core/review-rerun.d.ts +16 -0
- package/dist/core/review-rerun.js +31 -0
- package/dist/core/review-rerun.js.map +1 -0
- package/dist/core/role-permissions.d.ts +21 -0
- package/dist/core/role-permissions.js +60 -0
- package/dist/core/role-permissions.js.map +1 -0
- package/dist/core/run-result.d.ts +24 -0
- package/dist/core/run-result.js +21 -0
- package/dist/core/run-result.js.map +1 -0
- package/dist/core/run-summary.d.ts +47 -0
- package/dist/core/run-summary.js +22 -0
- package/dist/core/run-summary.js.map +1 -0
- package/dist/core/uc-context-builder.d.ts +7 -0
- package/dist/core/uc-context-builder.js +30 -0
- package/dist/core/uc-context-builder.js.map +1 -0
- package/dist/core/uc-proposal.d.ts +11 -0
- package/dist/core/uc-proposal.js +49 -0
- package/dist/core/uc-proposal.js.map +1 -0
- package/dist/diagrams/activity.d.ts +21 -0
- package/dist/diagrams/activity.js +362 -0
- package/dist/diagrams/activity.js.map +1 -0
- package/dist/diagrams/architecture.d.ts +42 -0
- package/dist/diagrams/architecture.js +165 -0
- package/dist/diagrams/architecture.js.map +1 -0
- package/dist/diagrams/class.d.ts +9 -0
- package/dist/diagrams/class.js +222 -0
- package/dist/diagrams/class.js.map +1 -0
- package/dist/diagrams/class_relations.d.ts +19 -0
- package/dist/diagrams/class_relations.js +165 -0
- package/dist/diagrams/class_relations.js.map +1 -0
- package/dist/diagrams/layout/elk.d.ts +9 -0
- package/dist/diagrams/layout/elk.js +57 -0
- package/dist/diagrams/layout/elk.js.map +1 -0
- package/dist/diagrams/layout/postprocess.d.ts +17 -0
- package/dist/diagrams/layout/postprocess.js +81 -0
- package/dist/diagrams/layout/postprocess.js.map +1 -0
- package/dist/diagrams/layout/radial.d.ts +65 -0
- package/dist/diagrams/layout/radial.js +275 -0
- package/dist/diagrams/layout/radial.js.map +1 -0
- package/dist/diagrams/layout/types.d.ts +37 -0
- package/dist/diagrams/layout/types.js +2 -0
- package/dist/diagrams/layout/types.js.map +1 -0
- package/dist/diagrams/sequence-header.d.ts +58 -0
- package/dist/diagrams/sequence-header.js +102 -0
- package/dist/diagrams/sequence-header.js.map +1 -0
- package/dist/diagrams/sequence-model.d.ts +21 -0
- package/dist/diagrams/sequence-model.js +298 -0
- package/dist/diagrams/sequence-model.js.map +1 -0
- package/dist/diagrams/sequence-parts.d.ts +83 -0
- package/dist/diagrams/sequence-parts.js +239 -0
- package/dist/diagrams/sequence-parts.js.map +1 -0
- package/dist/diagrams/sequence-take.d.ts +22 -0
- package/dist/diagrams/sequence-take.js +221 -0
- package/dist/diagrams/sequence-take.js.map +1 -0
- package/dist/diagrams/sequence.d.ts +27 -0
- package/dist/diagrams/sequence.js +339 -0
- package/dist/diagrams/sequence.js.map +1 -0
- package/dist/diagrams/usecase.d.ts +9 -0
- package/dist/diagrams/usecase.js +160 -0
- package/dist/diagrams/usecase.js.map +1 -0
- package/dist/diagrams/usecase_layout.d.ts +54 -0
- package/dist/diagrams/usecase_layout.js +160 -0
- package/dist/diagrams/usecase_layout.js.map +1 -0
- package/dist/evaluation/accuracy.d.ts +23 -0
- package/dist/evaluation/accuracy.js +140 -0
- package/dist/evaluation/accuracy.js.map +1 -0
- package/dist/evaluation/collector.d.ts +32 -0
- package/dist/evaluation/collector.js +40 -0
- package/dist/evaluation/collector.js.map +1 -0
- package/dist/evaluation/completeness.d.ts +3 -0
- package/dist/evaluation/completeness.js +51 -0
- package/dist/evaluation/completeness.js.map +1 -0
- package/dist/evaluation/consistency.d.ts +12 -0
- package/dist/evaluation/consistency.js +26 -0
- package/dist/evaluation/consistency.js.map +1 -0
- package/dist/evaluation/dashboard-compare.d.ts +4 -0
- package/dist/evaluation/dashboard-compare.js +108 -0
- package/dist/evaluation/dashboard-compare.js.map +1 -0
- package/dist/evaluation/dashboard-review.d.ts +4 -0
- package/dist/evaluation/dashboard-review.js +189 -0
- package/dist/evaluation/dashboard-review.js.map +1 -0
- package/dist/evaluation/dashboard.d.ts +3 -0
- package/dist/evaluation/dashboard.js +334 -0
- package/dist/evaluation/dashboard.js.map +1 -0
- package/dist/evaluation/human-eval.d.ts +7 -0
- package/dist/evaluation/human-eval.js +34 -0
- package/dist/evaluation/human-eval.js.map +1 -0
- package/dist/evaluation/timing.d.ts +14 -0
- package/dist/evaluation/timing.js +35 -0
- package/dist/evaluation/timing.js.map +1 -0
- package/dist/evaluation/token-cost.d.ts +16 -0
- package/dist/evaluation/token-cost.js +44 -0
- package/dist/evaluation/token-cost.js.map +1 -0
- package/dist/evaluation/token-savings.d.ts +12 -0
- package/dist/evaluation/token-savings.js +60 -0
- package/dist/evaluation/token-savings.js.map +1 -0
- package/dist/knowledge/hub-grouping.d.ts +8 -0
- package/dist/knowledge/hub-grouping.js +66 -0
- package/dist/knowledge/hub-grouping.js.map +1 -0
- package/dist/knowledge/local-kb.d.ts +4 -0
- package/dist/knowledge/local-kb.js +82 -0
- package/dist/knowledge/local-kb.js.map +1 -0
- package/dist/knowledge/rag-augment.d.ts +9 -0
- package/dist/knowledge/rag-augment.js +45 -0
- package/dist/knowledge/rag-augment.js.map +1 -0
- package/dist/knowledge/rag-client.d.ts +11 -0
- package/dist/knowledge/rag-client.js +60 -0
- package/dist/knowledge/rag-client.js.map +1 -0
- package/dist/knowledge/retriever.d.ts +15 -0
- package/dist/knowledge/retriever.js +43 -0
- package/dist/knowledge/retriever.js.map +1 -0
- package/dist/knowledge/rules.d.ts +2 -0
- package/dist/knowledge/rules.js +10 -0
- package/dist/knowledge/rules.js.map +1 -0
- package/dist/knowledge/types.d.ts +28 -0
- package/dist/knowledge/types.js +2 -0
- package/dist/knowledge/types.js.map +1 -0
- package/dist/license/banner.d.ts +5 -0
- package/dist/license/banner.js +7 -0
- package/dist/license/banner.js.map +1 -0
- package/dist/license/client.d.ts +116 -0
- package/dist/license/client.js +195 -0
- package/dist/license/client.js.map +1 -0
- package/dist/license/gate.d.ts +22 -0
- package/dist/license/gate.js +50 -0
- package/dist/license/gate.js.map +1 -0
- package/dist/license/keys.d.ts +6 -0
- package/dist/license/keys.js +7 -0
- package/dist/license/keys.js.map +1 -0
- package/dist/license/login-flow.d.ts +39 -0
- package/dist/license/login-flow.js +61 -0
- package/dist/license/login-flow.js.map +1 -0
- package/dist/license/logout-flow.d.ts +18 -0
- package/dist/license/logout-flow.js +55 -0
- package/dist/license/logout-flow.js.map +1 -0
- package/dist/license/rollback.d.ts +9 -0
- package/dist/license/rollback.js +57 -0
- package/dist/license/rollback.js.map +1 -0
- package/dist/license/run-license.d.ts +24 -0
- package/dist/license/run-license.js +28 -0
- package/dist/license/run-license.js.map +1 -0
- package/dist/license/session.d.ts +62 -0
- package/dist/license/session.js +101 -0
- package/dist/license/session.js.map +1 -0
- package/dist/license/status-line.d.ts +8 -0
- package/dist/license/status-line.js +42 -0
- package/dist/license/status-line.js.map +1 -0
- package/dist/license/telemetry.d.ts +15 -0
- package/dist/license/telemetry.js +53 -0
- package/dist/license/telemetry.js.map +1 -0
- package/dist/license/verify.d.ts +11 -0
- package/dist/license/verify.js +214 -0
- package/dist/license/verify.js.map +1 -0
- package/dist/parser.jar +0 -0
- package/dist/server.d.ts +2 -0
- package/dist/server.js +443 -0
- package/dist/server.js.map +1 -0
- package/dist/theory/domains.d.ts +10 -0
- package/dist/theory/domains.js +53 -0
- package/dist/theory/domains.js.map +1 -0
- package/dist/theory/facts.d.ts +8 -0
- package/dist/theory/facts.js +98 -0
- package/dist/theory/facts.js.map +1 -0
- package/dist/theory/fill.d.ts +18 -0
- package/dist/theory/fill.js +157 -0
- package/dist/theory/fill.js.map +1 -0
- package/dist/theory/references.d.ts +33 -0
- package/dist/theory/references.js +227 -0
- package/dist/theory/references.js.map +1 -0
- package/dist/theory/requirements.d.ts +21 -0
- package/dist/theory/requirements.js +100 -0
- package/dist/theory/requirements.js.map +1 -0
- package/dist/theory/scaffold.d.ts +13 -0
- package/dist/theory/scaffold.js +261 -0
- package/dist/theory/scaffold.js.map +1 -0
- package/dist/tools/analyze_project.d.ts +28 -0
- package/dist/tools/analyze_project.js +50 -0
- package/dist/tools/analyze_project.js.map +1 -0
- package/dist/tools/environment.d.ts +29 -0
- package/dist/tools/environment.js +101 -0
- package/dist/tools/environment.js.map +1 -0
- package/dist/tools/generate_report.d.ts +40 -0
- package/dist/tools/generate_report.js +490 -0
- package/dist/tools/generate_report.js.map +1 -0
- package/dist/tools/learn_usecase.d.ts +11 -0
- package/dist/tools/learn_usecase.js +58 -0
- package/dist/tools/learn_usecase.js.map +1 -0
- package/dist/tools/propose_uc_groupings.d.ts +16 -0
- package/dist/tools/propose_uc_groupings.js +94 -0
- package/dist/tools/propose_uc_groupings.js.map +1 -0
- package/dist/tools/review-tasks.d.ts +28 -0
- package/dist/tools/review-tasks.js +168 -0
- package/dist/tools/review-tasks.js.map +1 -0
- package/dist/tools/review.d.ts +28 -0
- package/dist/tools/review.js +160 -0
- package/dist/tools/review.js.map +1 -0
- package/dist/tools/scaffold.d.ts +21 -0
- package/dist/tools/scaffold.js +149 -0
- package/dist/tools/scaffold.js.map +1 -0
- package/dist/tools/scan_repo.d.ts +33 -0
- package/dist/tools/scan_repo.js +140 -0
- package/dist/tools/scan_repo.js.map +1 -0
- package/dist/types/diagram.d.ts +98 -0
- package/dist/types/diagram.js +2 -0
- package/dist/types/diagram.js.map +1 -0
- package/dist/types/evaluation.d.ts +114 -0
- package/dist/types/evaluation.js +2 -0
- package/dist/types/evaluation.js.map +1 -0
- package/dist/types/ir.d.ts +112 -0
- package/dist/types/ir.js +2 -0
- package/dist/types/ir.js.map +1 -0
- package/dist/types/license.d.ts +66 -0
- package/dist/types/license.js +3 -0
- package/dist/types/license.js.map +1 -0
- package/dist/types/report.d.ts +176 -0
- package/dist/types/report.js +2 -0
- package/dist/types/report.js.map +1 -0
- package/dist/types/theory.d.ts +110 -0
- package/dist/types/theory.js +3 -0
- package/dist/types/theory.js.map +1 -0
- package/dist/types/uc-grouping.d.ts +49 -0
- package/dist/types/uc-grouping.js +2 -0
- package/dist/types/uc-grouping.js.map +1 -0
- package/dist/utils/approval.d.ts +37 -0
- package/dist/utils/approval.js +173 -0
- package/dist/utils/approval.js.map +1 -0
- package/dist/utils/dashboard-launcher.d.ts +28 -0
- package/dist/utils/dashboard-launcher.js +215 -0
- package/dist/utils/dashboard-launcher.js.map +1 -0
- package/dist/utils/diagram-dir.d.ts +5 -0
- package/dist/utils/diagram-dir.js +33 -0
- package/dist/utils/diagram-dir.js.map +1 -0
- package/dist/utils/file.d.ts +35 -0
- package/dist/utils/file.js +76 -0
- package/dist/utils/file.js.map +1 -0
- package/dist/utils/ir-minify.d.ts +15 -0
- package/dist/utils/ir-minify.js +114 -0
- package/dist/utils/ir-minify.js.map +1 -0
- package/dist/utils/mcp-launch.d.ts +24 -0
- package/dist/utils/mcp-launch.js +37 -0
- package/dist/utils/mcp-launch.js.map +1 -0
- package/dist/utils/open.d.ts +10 -0
- package/dist/utils/open.js +24 -0
- package/dist/utils/open.js.map +1 -0
- package/dist/utils/run-history.d.ts +29 -0
- package/dist/utils/run-history.js +62 -0
- package/dist/utils/run-history.js.map +1 -0
- package/dist/utils/version.d.ts +6 -0
- package/dist/utils/version.js +25 -0
- package/dist/utils/version.js.map +1 -0
- package/dist/utils/xml.d.ts +17 -0
- package/dist/utils/xml.js +30 -0
- package/dist/utils/xml.js.map +1 -0
- package/package.json +61 -6
|
@@ -0,0 +1,814 @@
|
|
|
1
|
+
import { flattenTraces, INTERNAL_HELPERS, NOISE_TARGETS } from "./flow-trace.js";
|
|
2
|
+
import { inferUcAlternateFlow, ucSuccessPostcond, ucFailureReason, ucActorStep1 } from "./flow-steps-uc.js";
|
|
3
|
+
// ── Actor label ────────────────────────────────────────────────────────────
|
|
4
|
+
/**
|
|
5
|
+
* Derive the UC actor label from controller name / endpoint heuristics.
|
|
6
|
+
* Never returns "Người dùng" — returns English actor labels per spec.
|
|
7
|
+
*/
|
|
8
|
+
export function buildActorLabel(candidate) {
|
|
9
|
+
const v = `${candidate.controller.name} ${candidate.endpoint}`.toLowerCase();
|
|
10
|
+
if (v.includes("analytics") || v.includes("admin"))
|
|
11
|
+
return "Admin";
|
|
12
|
+
if (v.includes("signin") || v.includes("signup") || v.includes("register") ||
|
|
13
|
+
v.includes("login") || v.includes("forgot-password") || v.includes("qr-login"))
|
|
14
|
+
return "Guest/User";
|
|
15
|
+
if (/\bai\b/.test(v))
|
|
16
|
+
return "User, AI Bot";
|
|
17
|
+
return "User";
|
|
18
|
+
}
|
|
19
|
+
// ── Purpose / pre / post ───────────────────────────────────────────────────
|
|
20
|
+
/** Build a one-sentence purpose string for the UC spec header. */
|
|
21
|
+
export function buildPurpose(candidate, title) {
|
|
22
|
+
const actor = buildActorLabel(candidate);
|
|
23
|
+
const phrase = actor.toLowerCase().includes("admin") ? "quản trị viên" : actor.toLowerCase().includes("ai bot") ? "người dùng tương tác với AI Bot" : "người dùng";
|
|
24
|
+
const v = `${title} ${candidate.method.name} ${candidate.endpoint}`.toLowerCase();
|
|
25
|
+
if (/generateqrsession|qr.login.generate/.test(v))
|
|
26
|
+
return `Cho phép ${phrase} khởi tạo phiên đăng nhập bằng mã QR.`;
|
|
27
|
+
if (/signup|register/.test(v))
|
|
28
|
+
return `Cho phép ${phrase} đăng ký tài khoản vào hệ thống.`;
|
|
29
|
+
if (/signin|login|authenticate/.test(v))
|
|
30
|
+
return `Cho phép ${phrase} đăng nhập vào hệ thống.`;
|
|
31
|
+
const action = title.replace(/[.。]+$/g, "").trim().replace(/^./u, (c) => c.toLocaleLowerCase("vi-VN"));
|
|
32
|
+
return `Cho phép ${phrase} ${action}.`;
|
|
33
|
+
}
|
|
34
|
+
/** Build precondition list for a UC spec. */
|
|
35
|
+
export function buildPreconditions(candidate, title, traces) {
|
|
36
|
+
const result = ["Ứng dụng có thể kết nối đến hệ thống."];
|
|
37
|
+
const v = `${title} ${candidate.method.name} ${candidate.endpoint}`.toLowerCase();
|
|
38
|
+
const isQr = /generateqrsession|qr.login.generate/.test(v);
|
|
39
|
+
const isReg = /signup|register/.test(v), isLogin = !isQr && /signin|login|authenticate/.test(v);
|
|
40
|
+
if (isQr) {
|
|
41
|
+
result.push("Người dùng đang ở màn hình đăng nhập.");
|
|
42
|
+
}
|
|
43
|
+
else if (isReg) {
|
|
44
|
+
if (!usesPrincipal(candidate.method))
|
|
45
|
+
result.push("Người dùng chưa đăng nhập.");
|
|
46
|
+
if (hasTraceKw(traces, /exists/i))
|
|
47
|
+
result.push("Thông tin định danh đăng ký chưa tồn tại trong hệ thống.");
|
|
48
|
+
}
|
|
49
|
+
else if (isLogin) {
|
|
50
|
+
if (!usesPrincipal(candidate.method))
|
|
51
|
+
result.push("Người dùng đang ở màn hình đăng nhập.");
|
|
52
|
+
if (hasTraceKw(traces, /findBy/i))
|
|
53
|
+
result.push("Tài khoản tương ứng với thông tin đăng nhập tồn tại trong hệ thống.");
|
|
54
|
+
}
|
|
55
|
+
else if (!/signin|signup|register|login|forgot-password|send-otp/.test(v)) {
|
|
56
|
+
result.push("Người dùng đã đăng nhập và token/session còn hợp lệ.");
|
|
57
|
+
}
|
|
58
|
+
return uniq(result);
|
|
59
|
+
}
|
|
60
|
+
/** Build success postconditions for a UC spec. */
|
|
61
|
+
export function buildSuccessPostconditions(candidate, title, traces) {
|
|
62
|
+
const v = `${title} ${candidate.method.name} ${candidate.endpoint}`.toLowerCase();
|
|
63
|
+
const hasToken = hasTraceKw(traces, /generateToken|TokenPair|JwtTokenProvider/i);
|
|
64
|
+
const specific = ucSuccessPostcond(v, hasToken);
|
|
65
|
+
if (specific.length)
|
|
66
|
+
return uniq(specific);
|
|
67
|
+
const result = ["Ứng dụng nhận kết quả thành công từ hệ thống."];
|
|
68
|
+
if (collectPersistenceCalls(traces).some((c) => /save|delete/.test(c.method)))
|
|
69
|
+
result.unshift("Dữ liệu liên quan được lưu hoặc cập nhật trong hệ thống.");
|
|
70
|
+
if (hasToken)
|
|
71
|
+
result.push("Token hoặc phiên đăng nhập được trả về cho ứng dụng.");
|
|
72
|
+
if (collectSideEffectCalls(traces).length)
|
|
73
|
+
result.push("Thông báo hoặc cập nhật thời gian thực được gửi đến các bên liên quan khi cần.");
|
|
74
|
+
return uniq(result);
|
|
75
|
+
}
|
|
76
|
+
/** Build failure postconditions for a UC spec. */
|
|
77
|
+
export function buildFailurePostconditions(candidate, title, traces) {
|
|
78
|
+
const result = [];
|
|
79
|
+
const v = `${title} ${candidate.method.name} ${candidate.endpoint}`.toLowerCase();
|
|
80
|
+
const ucReason = ucFailureReason(v);
|
|
81
|
+
if (ucReason) {
|
|
82
|
+
result.push(ucReason);
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
if (hasValidation(candidate.method))
|
|
86
|
+
result.push("Yêu cầu không hợp lệ bị từ chối trước khi hoàn tất xử lý nghiệp vụ.");
|
|
87
|
+
if (collectConditions(candidate.method, traces).length)
|
|
88
|
+
result.push("Hệ thống trả lỗi tương ứng khi điều kiện nghiệp vụ không thỏa.");
|
|
89
|
+
}
|
|
90
|
+
return result.length ? uniq(result) : ["Yêu cầu không được ghi nhận hoặc không tạo thay đổi dữ liệu khi điều kiện xử lý không đáp ứng."];
|
|
91
|
+
}
|
|
92
|
+
// ── Main steps ─────────────────────────────────────────────────────────────
|
|
93
|
+
/** Build numbered FlowStep[] (main flow) for a UC from its call trace. */
|
|
94
|
+
export function buildMainSteps(candidate, traces, title, tier = "baseline") {
|
|
95
|
+
if (tier === "pro")
|
|
96
|
+
return buildMainStepsPro(candidate, traces, title);
|
|
97
|
+
const conditions = collectConditions(candidate.method, traces);
|
|
98
|
+
const persistence = uniqTraces(collectPersistenceCalls(traces));
|
|
99
|
+
const persistKeys = new Set(persistence.map((t) => `${t.target}.${t.method}`));
|
|
100
|
+
const sideEffects = uniqTraces(collectSideEffectCalls(traces).filter((t) => !persistKeys.has(`${t.target}.${t.method}`)));
|
|
101
|
+
const label = (title ?? humanize(candidate.method.name)).replace(/[.。]+$/, "");
|
|
102
|
+
const v = `${title ?? ""} ${candidate.method.name} ${candidate.endpoint}`.toLowerCase();
|
|
103
|
+
const draft = [
|
|
104
|
+
{ actor: ucActorStep1(v, label), system: "" },
|
|
105
|
+
{ actor: "", system: `(FE) Ứng dụng gửi yêu cầu đến ${candidate.endpoint}.` },
|
|
106
|
+
{ actor: "", system: validationText(conditions, v) },
|
|
107
|
+
{ actor: "", system: businessActionText(candidate, label, traces) }
|
|
108
|
+
];
|
|
109
|
+
const bizAlreadyDescribesReads = /summarizechat|ai.summarize|sendmessagerest|chat\.send|recallmessage|messages\.recall/.test(v);
|
|
110
|
+
draft.push(...persistenceTexts(persistence, bizAlreadyDescribesReads).slice(0, 2).map((sys) => ({ actor: "", system: sys })));
|
|
111
|
+
draft.push(...sideEffectTexts(sideEffects).slice(0, 1).map((sys) => ({ actor: "", system: sys })));
|
|
112
|
+
draft.push({ actor: "", system: responseText(sideEffects) }, { actor: "", system: "(FE) Ứng dụng cập nhật giao diện theo response nhận được." });
|
|
113
|
+
return draft.map((s, i) => ({ step: String(i + 1), ...s }));
|
|
114
|
+
}
|
|
115
|
+
// ── Alternate flows ────────────────────────────────────────────────────────
|
|
116
|
+
/** Build AlternateFlow[] extracted from conditions and exceptions in the call trace. */
|
|
117
|
+
export function buildAlternateFlows(method, traces, candidate, title, tier = "baseline") {
|
|
118
|
+
if (tier === "pro")
|
|
119
|
+
return buildAlternateFlowsPro(method, traces, candidate, title);
|
|
120
|
+
const ucAlt = candidate && title ? inferUcAlternateFlow(candidate, title) : undefined;
|
|
121
|
+
if (ucAlt)
|
|
122
|
+
return [ucAlt];
|
|
123
|
+
const conditions = collectConditions(method, traces);
|
|
124
|
+
const summaries = uniq(conditions.map(conditionSummary).filter(Boolean));
|
|
125
|
+
if (conditions.length)
|
|
126
|
+
return [{
|
|
127
|
+
code: "A1", title: altTitle(summaries),
|
|
128
|
+
guardCondition: toGuardConditionQuestion(summaries[0] ?? altTitle(summaries)),
|
|
129
|
+
steps: [
|
|
130
|
+
{ step: "3a", actor: "", system: altReason(summaries) },
|
|
131
|
+
{ step: "4a", actor: "", system: "(BE) Hệ thống dừng luồng chính và trả phản hồi lỗi phù hợp cho client." },
|
|
132
|
+
{ step: "5a", actor: "", system: "(FE) Ứng dụng hiển thị thông báo lỗi. Use case kết thúc." }
|
|
133
|
+
]
|
|
134
|
+
}];
|
|
135
|
+
return [{
|
|
136
|
+
code: "A1", title: "Validation hoặc quyền truy cập không hợp lệ",
|
|
137
|
+
guardCondition: "Dữ liệu và quyền truy cập hợp lệ?",
|
|
138
|
+
steps: [
|
|
139
|
+
{ step: "3a", actor: "", system: "(BE) Hệ thống phát hiện request thiếu dữ liệu, sai định dạng hoặc người dùng không có quyền." },
|
|
140
|
+
{ step: "3b", actor: "", system: "(FE) Ứng dụng nhận response lỗi và giữ nguyên trạng thái dữ liệu hiện tại." }
|
|
141
|
+
]
|
|
142
|
+
}];
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Classify raw condition strings into semantic categories.
|
|
146
|
+
* Auth → token/principal checks. Validation → @Valid / format checks.
|
|
147
|
+
* Business → domain state checks. Exception → try/catch throws.
|
|
148
|
+
*/
|
|
149
|
+
export function classifyConditions(method, traces) {
|
|
150
|
+
const all = collectConditions(method, traces);
|
|
151
|
+
const thrownEx = flattenTraces(traces).flatMap((t) => t.thrownExceptions ?? []);
|
|
152
|
+
const hasTryCatch = method.hasTryCatch || flattenTraces(traces).some((t) => t.hasTryCatch);
|
|
153
|
+
const auth = [];
|
|
154
|
+
const validation = [];
|
|
155
|
+
const business = [];
|
|
156
|
+
const exception = [];
|
|
157
|
+
for (const c of all) {
|
|
158
|
+
if (/principal\s*==\s*null|authentication\s*==\s*null|UsernamePasswordAuthenticationToken|instanceof.*[Aa]uth|getAuthentication|token|jwt|session/i.test(c)) {
|
|
159
|
+
auth.push(c);
|
|
160
|
+
}
|
|
161
|
+
else if (/isBlank|isEmpty|@Valid|format|length|pattern|email.*valid|phone.*valid/i.test(c)) {
|
|
162
|
+
validation.push(c);
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
business.push(c);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (hasTryCatch || thrownEx.length)
|
|
169
|
+
exception.push("system");
|
|
170
|
+
// If no explicit auth conditions but endpoint needs auth, infer one
|
|
171
|
+
const v = `${method.name ?? ""} ${(method.params ?? []).map((p) => p.type).join(" ")}`.toLowerCase();
|
|
172
|
+
if (!auth.length && /principal|userdetails|authentication/i.test(v)) {
|
|
173
|
+
auth.push("authentication != null");
|
|
174
|
+
}
|
|
175
|
+
return { auth, validation, business, exception };
|
|
176
|
+
}
|
|
177
|
+
/** Pro-tier main steps: separate step per condition category. */
|
|
178
|
+
function buildMainStepsPro(candidate, traces, title) {
|
|
179
|
+
const cats = classifyConditions(candidate.method, traces);
|
|
180
|
+
const persistence = uniqTraces(collectPersistenceCalls(traces));
|
|
181
|
+
const persistKeys = new Set(persistence.map((t) => `${t.target}.${t.method}`));
|
|
182
|
+
const sideEffects = uniqTraces(collectSideEffectCalls(traces).filter((t) => !persistKeys.has(`${t.target}.${t.method}`)));
|
|
183
|
+
const label = (title ?? humanize(candidate.method.name)).replace(/[.。]+$/, "");
|
|
184
|
+
const v = `${title ?? ""} ${candidate.method.name} ${candidate.endpoint}`.toLowerCase();
|
|
185
|
+
const draft = [
|
|
186
|
+
{ actor: ucActorStep1(v, label), system: "" },
|
|
187
|
+
{ actor: "", system: `(FE) Ứng dụng gửi yêu cầu đến ${candidate.endpoint}.` },
|
|
188
|
+
];
|
|
189
|
+
// Auth step — only if auth conditions detected
|
|
190
|
+
if (cats.auth.length) {
|
|
191
|
+
draft.push({ actor: "", system: "(BE) Hệ thống xác thực token/session và quyền truy cập của người dùng." });
|
|
192
|
+
}
|
|
193
|
+
// Validation step — only if @Valid / DTO params present
|
|
194
|
+
if (cats.validation.length || hasValidation(candidate.method)) {
|
|
195
|
+
draft.push({ actor: "", system: "(BE) Hệ thống kiểm tra tính hợp lệ của dữ liệu đầu vào (định dạng, bắt buộc)." });
|
|
196
|
+
}
|
|
197
|
+
// Business rule steps — one per distinct business condition (max 3)
|
|
198
|
+
const bizSummaries = uniq(cats.business.map(conditionSummary).filter(Boolean)).slice(0, 3);
|
|
199
|
+
for (const s of bizSummaries) {
|
|
200
|
+
draft.push({ actor: "", system: `(BE) Hệ thống kiểm tra ${s}.` });
|
|
201
|
+
}
|
|
202
|
+
// Core business action
|
|
203
|
+
draft.push({ actor: "", system: businessActionText(candidate, label, traces) });
|
|
204
|
+
// Persistence
|
|
205
|
+
const bizAlreadyDescribesReads = /summarizechat|ai.summarize|sendmessagerest|chat\.send|recallmessage|messages\.recall/.test(v);
|
|
206
|
+
draft.push(...persistenceTexts(persistence, bizAlreadyDescribesReads).slice(0, 2).map((sys) => ({ actor: "", system: sys })));
|
|
207
|
+
// Side effects
|
|
208
|
+
draft.push(...sideEffectTexts(sideEffects).slice(0, 2).map((sys) => ({ actor: "", system: sys })));
|
|
209
|
+
draft.push({ actor: "", system: responseText(sideEffects) }, { actor: "", system: "(FE) Ứng dụng cập nhật giao diện theo response nhận được." });
|
|
210
|
+
return draft.map((s, i) => ({ step: String(i + 1), ...s }));
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Compute which main-flow step number each condition category is checked at in pro tier.
|
|
214
|
+
* Steps 1 (actor) and 2 (FE request) are always present; subsequent steps depend on what
|
|
215
|
+
* categories are non-empty, matching the order in buildMainStepsPro.
|
|
216
|
+
*/
|
|
217
|
+
function computeAltStepOffsets(method, cats) {
|
|
218
|
+
let step = 2;
|
|
219
|
+
const authStep = cats.auth.length ? ++step : undefined;
|
|
220
|
+
const hasValidCond = cats.validation.length > 0 || hasValidation(method);
|
|
221
|
+
const validStep = hasValidCond ? ++step : undefined;
|
|
222
|
+
const bizSummaries = uniq(cats.business.map(conditionSummary).filter(Boolean)).slice(0, 3);
|
|
223
|
+
const bizSteps = bizSummaries.map(() => ++step);
|
|
224
|
+
return { authStep, validStep, bizSteps };
|
|
225
|
+
}
|
|
226
|
+
/** Pro-tier alternate flows: one AlternateFlow per condition category. */
|
|
227
|
+
function buildAlternateFlowsPro(method, traces, candidate, title) {
|
|
228
|
+
// Bug 3 fix: do NOT short-circuit via inferUcAlternateFlow here — known UC patterns must
|
|
229
|
+
// also get full pro-tier multi-flow treatment (inferUcAlternateFlow is baseline-only).
|
|
230
|
+
void candidate;
|
|
231
|
+
void title;
|
|
232
|
+
const cats = classifyConditions(method, traces);
|
|
233
|
+
const offsets = computeAltStepOffsets(method, cats);
|
|
234
|
+
const flows = [];
|
|
235
|
+
let code = 1;
|
|
236
|
+
if (cats.auth.length) {
|
|
237
|
+
const n = offsets.authStep;
|
|
238
|
+
const L = String.fromCharCode('a'.charCodeAt(0) + flows.length); // flow index → letter
|
|
239
|
+
flows.push({
|
|
240
|
+
code: `A${code++}`,
|
|
241
|
+
title: "Xác thực thất bại — token hoặc phiên không hợp lệ",
|
|
242
|
+
guardCondition: "Token / phiên đăng nhập hợp lệ?",
|
|
243
|
+
steps: [
|
|
244
|
+
{ step: `${n}${L}`, actor: "", system: "(BE) Hệ thống phát hiện token hoặc phiên đăng nhập không tồn tại hoặc đã hết hạn." },
|
|
245
|
+
{ step: `${n + 1}${L}`, actor: "", system: "(BE) Hệ thống trả phản hồi 401 Unauthorized cho client." },
|
|
246
|
+
{ step: `${n + 2}${L}`, actor: "", system: "(FE) Ứng dụng hiển thị thông báo lỗi xác thực. Use case kết thúc." },
|
|
247
|
+
],
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
const hasValidationCond = cats.validation.length > 0 || hasValidation(method);
|
|
251
|
+
if (hasValidationCond) {
|
|
252
|
+
const n = offsets.validStep;
|
|
253
|
+
const L = String.fromCharCode('a'.charCodeAt(0) + flows.length);
|
|
254
|
+
flows.push({
|
|
255
|
+
code: `A${code++}`,
|
|
256
|
+
title: "Dữ liệu đầu vào không hợp lệ",
|
|
257
|
+
guardCondition: "Dữ liệu đầu vào hợp lệ?",
|
|
258
|
+
steps: [
|
|
259
|
+
{ step: `${n}${L}`, actor: "", system: "(BE) Hệ thống phát hiện dữ liệu đầu vào thiếu trường bắt buộc, sai định dạng hoặc vượt giới hạn cho phép." },
|
|
260
|
+
{ step: `${n + 1}${L}`, actor: "", system: "(BE) Hệ thống trả phản hồi 400 Bad Request kèm danh sách lỗi validation." },
|
|
261
|
+
{ step: `${n + 2}${L}`, actor: "", system: "(FE) Ứng dụng hiển thị thông báo lỗi tương ứng trên giao diện. Use case kết thúc." },
|
|
262
|
+
],
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
// One flow per distinct business condition (max 3)
|
|
266
|
+
const bizSummaries = uniq(cats.business.map(conditionSummary).filter(Boolean)).slice(0, 3);
|
|
267
|
+
for (let bi = 0; bi < bizSummaries.length; bi++) {
|
|
268
|
+
const s = bizSummaries[bi];
|
|
269
|
+
const n = offsets.bizSteps[bi];
|
|
270
|
+
const L = String.fromCharCode('a'.charCodeAt(0) + flows.length);
|
|
271
|
+
flows.push({
|
|
272
|
+
code: `A${code++}`,
|
|
273
|
+
title: `Điều kiện nghiệp vụ không thỏa — ${s}`,
|
|
274
|
+
guardCondition: toGuardConditionQuestion(s),
|
|
275
|
+
steps: [
|
|
276
|
+
{ step: `${n}${L}`, actor: "", system: `(BE) Hệ thống xác định ${s} không đáp ứng yêu cầu nghiệp vụ.` },
|
|
277
|
+
{ step: `${n + 1}${L}`, actor: "", system: "(BE) Hệ thống dừng luồng chính và trả phản hồi lỗi nghiệp vụ tương ứng cho client." },
|
|
278
|
+
{ step: `${n + 2}${L}`, actor: "", system: "(FE) Ứng dụng hiển thị thông báo lỗi. Use case kết thúc." },
|
|
279
|
+
],
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
// Fallback if no conditions detected at all
|
|
283
|
+
if (!flows.length) {
|
|
284
|
+
flows.push({
|
|
285
|
+
code: "A1", title: "Validation hoặc quyền truy cập không hợp lệ",
|
|
286
|
+
guardCondition: "Dữ liệu và quyền truy cập hợp lệ?",
|
|
287
|
+
steps: [
|
|
288
|
+
{ step: "3a", actor: "", system: "(BE) Hệ thống phát hiện request thiếu dữ liệu, sai định dạng hoặc người dùng không có quyền." },
|
|
289
|
+
{ step: "4a", actor: "", system: "(FE) Ứng dụng nhận response lỗi và giữ nguyên trạng thái dữ liệu hiện tại." },
|
|
290
|
+
],
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
return flows;
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Pro-tier exception flows — infrastructure/system failures, separate from alternate flows.
|
|
297
|
+
* E1: database/system error (detected via try/catch in traces).
|
|
298
|
+
* E2: external service failure (detected via external service calls).
|
|
299
|
+
*/
|
|
300
|
+
export function buildExceptionFlows(method, traces) {
|
|
301
|
+
const hasTryCatch = method.hasTryCatch || flattenTraces(traces).some((t) => t.hasTryCatch);
|
|
302
|
+
const flat = flattenTraces(traces);
|
|
303
|
+
const hasExternal = flat.some((t) => /RestTemplate|WebClient|HttpClient|FeignClient|Retrofit|OkHttp/i.test(t.target));
|
|
304
|
+
const hasAi = flat.some((t) => /Gemini|OpenAI|Claude|AiService|LlmService/i.test(t.target));
|
|
305
|
+
const flows = [];
|
|
306
|
+
if (hasTryCatch) {
|
|
307
|
+
flows.push({
|
|
308
|
+
code: "E1",
|
|
309
|
+
title: "Lỗi hệ thống hoặc cơ sở dữ liệu",
|
|
310
|
+
trigger: "Timeout hoặc lỗi nội bộ trong quá trình xử lý",
|
|
311
|
+
steps: [
|
|
312
|
+
{ step: "E1.1", actor: "", system: "(BE) Hệ thống phát sinh ngoại lệ nội bộ (database timeout, I/O error, v.v.)." },
|
|
313
|
+
{ step: "E1.2", actor: "", system: "(BE) Hệ thống ghi nhật ký lỗi và rollback transaction nếu cần." },
|
|
314
|
+
{ step: "E1.3", actor: "", system: "(BE) Hệ thống trả phản hồi 500 Internal Server Error cho client." },
|
|
315
|
+
{ step: "E1.4", actor: "", system: "(FE) Ứng dụng hiển thị thông báo lỗi hệ thống. Use case kết thúc." },
|
|
316
|
+
],
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
if (hasExternal || hasAi) {
|
|
320
|
+
const trigger = hasAi ? "AI service không phản hồi hoặc trả lỗi" : "External service không phản hồi hoặc quá tải";
|
|
321
|
+
flows.push({
|
|
322
|
+
code: "E2",
|
|
323
|
+
title: "Dịch vụ ngoài không phản hồi",
|
|
324
|
+
trigger,
|
|
325
|
+
steps: [
|
|
326
|
+
{ step: "E2.1", actor: "", system: `(BE) ${trigger} trong thời gian timeout quy định.` },
|
|
327
|
+
{ step: "E2.2", actor: "", system: "(BE) Hệ thống ghi nhật ký lỗi và dừng xử lý nghiệp vụ." },
|
|
328
|
+
{ step: "E2.3", actor: "", system: "(BE) Hệ thống trả phản hồi lỗi phù hợp (503/504) cho client." },
|
|
329
|
+
{ step: "E2.4", actor: "", system: "(FE) Ứng dụng hiển thị thông báo dịch vụ tạm thời không khả dụng. Use case kết thúc." },
|
|
330
|
+
],
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
return flows;
|
|
334
|
+
}
|
|
335
|
+
// ── Sequence steps ─────────────────────────────────────────────────────────
|
|
336
|
+
function seqEntityEn(text) {
|
|
337
|
+
const t = text.toLowerCase();
|
|
338
|
+
if (/message|dynamo|chat/.test(t))
|
|
339
|
+
return "message";
|
|
340
|
+
if (/user|account|member/.test(t))
|
|
341
|
+
return "user";
|
|
342
|
+
if (/room|group/.test(t))
|
|
343
|
+
return "room";
|
|
344
|
+
if (/token|session|refresh/.test(t))
|
|
345
|
+
return "token";
|
|
346
|
+
if (/friend|block|relationship/.test(t))
|
|
347
|
+
return "relationship";
|
|
348
|
+
if (/media|file|minio|s3|storage|upload/.test(t))
|
|
349
|
+
return "file";
|
|
350
|
+
if (/notification|notify/.test(t))
|
|
351
|
+
return "notification";
|
|
352
|
+
if (/role|permission/.test(t))
|
|
353
|
+
return "role";
|
|
354
|
+
return "";
|
|
355
|
+
}
|
|
356
|
+
function seqVerbEn(method) {
|
|
357
|
+
if (/^(process|handle)/.test(method))
|
|
358
|
+
return "Process";
|
|
359
|
+
if (/^send/.test(method))
|
|
360
|
+
return "Send";
|
|
361
|
+
if (/^(find.*by|get.*by|load.*by)/.test(method))
|
|
362
|
+
return "Find";
|
|
363
|
+
if (/^(find|get|load|fetch|retrieve|read|list|query)/.test(method))
|
|
364
|
+
return "Get";
|
|
365
|
+
if (/^(save|create|add|insert|register|put)/.test(method))
|
|
366
|
+
return "Save";
|
|
367
|
+
if (/^update/.test(method))
|
|
368
|
+
return "Update";
|
|
369
|
+
if (/^(delete|remove)/.test(method))
|
|
370
|
+
return "Delete";
|
|
371
|
+
if (/^(validate|verify|check|is|has|can|assert)/.test(method))
|
|
372
|
+
return "Validate";
|
|
373
|
+
if (/^(exists|count)/.test(method))
|
|
374
|
+
return "Check";
|
|
375
|
+
if (/^upload/.test(method))
|
|
376
|
+
return "Upload";
|
|
377
|
+
if (/^download/.test(method))
|
|
378
|
+
return "Download";
|
|
379
|
+
if (/^(notify|alert)/.test(method))
|
|
380
|
+
return "Notify";
|
|
381
|
+
if (/^(emit|publish|broadcast)/.test(method))
|
|
382
|
+
return "Publish";
|
|
383
|
+
if (/^(build|generate)/.test(method))
|
|
384
|
+
return "Generate";
|
|
385
|
+
if (/^(parse|convert|transform|map|execute)/.test(method))
|
|
386
|
+
return "Convert";
|
|
387
|
+
return "Execute";
|
|
388
|
+
}
|
|
389
|
+
function humanizeMethodCall(expression, target) {
|
|
390
|
+
const m = /(?:^|\.)\s*([a-zA-Z][a-zA-Z0-9]*)(?:\s*\(|$)/.exec(expression);
|
|
391
|
+
if (!m)
|
|
392
|
+
return expression.length <= 58 ? expression : `${expression.slice(0, 55)}...`;
|
|
393
|
+
const method = m[1];
|
|
394
|
+
const entity = seqEntityEn(`${method} ${target}`);
|
|
395
|
+
const verb = seqVerbEn(method.toLowerCase());
|
|
396
|
+
return entity ? `${verb} ${entity}` : verb;
|
|
397
|
+
}
|
|
398
|
+
function buildReturnLabel(returnType, callMessage, target) {
|
|
399
|
+
if (!returnType) {
|
|
400
|
+
const entity = seqEntityEn(`${callMessage} ${target}`);
|
|
401
|
+
const m = callMessage.toLowerCase();
|
|
402
|
+
if (/save|create|insert|add/.test(m))
|
|
403
|
+
return entity ? `Saved ${entity}` : "Save result";
|
|
404
|
+
if (/delete|remove/.test(m))
|
|
405
|
+
return "Delete result";
|
|
406
|
+
if (/update/.test(m))
|
|
407
|
+
return entity ? `Updated ${entity}` : "Update result";
|
|
408
|
+
if (/exists|count|check|validate|verify/.test(m))
|
|
409
|
+
return "Boolean result";
|
|
410
|
+
return entity || "Result";
|
|
411
|
+
}
|
|
412
|
+
const genericMatch = /^(?:Optional|List|Page|Flux|Mono|ResponseEntity|CompletableFuture|Collection|Set|Slice)<(.+)>/.exec(returnType.trim());
|
|
413
|
+
const inner = genericMatch ? genericMatch[1].replace(/<.*>/, "").trim() : returnType.replace(/<.*>/, "").trim();
|
|
414
|
+
if (!inner || inner === "Void" || inner === "void")
|
|
415
|
+
return seqEntityEn(`${callMessage} ${target}`) || "Result";
|
|
416
|
+
if (inner === "boolean" || inner === "Boolean")
|
|
417
|
+
return "Boolean result";
|
|
418
|
+
if (/^(long|int|Long|Integer|double|Double|BigDecimal)$/.test(inner))
|
|
419
|
+
return "Count";
|
|
420
|
+
if (inner === "String")
|
|
421
|
+
return seqEntityEn(`${callMessage} ${target}`) || "String result";
|
|
422
|
+
const stripped = inner.toLowerCase().replace(/(response|dto|model|entity|vo|request|info|result)$/, "");
|
|
423
|
+
const entity = seqEntityEn(stripped);
|
|
424
|
+
return entity || `return: ${inner}`;
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Baseline: semantically grouped SequenceStep[] (free/baseline tier).
|
|
428
|
+
* Groups all persistence reads into one step, writes into one step, and
|
|
429
|
+
* side effects into one step — instead of a 1:1 code-line mapping.
|
|
430
|
+
*/
|
|
431
|
+
export function buildStepsBaseline(candidate, traces, actor) {
|
|
432
|
+
const filtered = traces.filter((t) => !NOISE_TARGETS.has(t.target));
|
|
433
|
+
const ctlName = candidate.controller.name;
|
|
434
|
+
const steps = [{ from: actor, to: ctlName, message: candidate.endpoint }];
|
|
435
|
+
// Primary service call: prefer a non-repository trace to represent the main business action
|
|
436
|
+
const primarySvc = filtered.find((t) => !/Repository$|DynamoRepository|Storage|Minio|S3/i.test(t.target) && !INTERNAL_HELPERS.has(t.method)) ?? filtered[0];
|
|
437
|
+
if (!primarySvc) {
|
|
438
|
+
steps.push({ from: ctlName, to: actor, message: "response", dashed: true });
|
|
439
|
+
return steps;
|
|
440
|
+
}
|
|
441
|
+
const svcName = primarySvc.target;
|
|
442
|
+
const primaryKey = `${primarySvc.target}.${primarySvc.method}`;
|
|
443
|
+
// CTL → SVC: primary business call
|
|
444
|
+
steps.push({ from: ctlName, to: svcName, message: humanizeMethodCall(primarySvc.expression ?? primarySvc.method, svcName) });
|
|
445
|
+
// Group persistence reads into one SVC → Repo → SVC step
|
|
446
|
+
const readCalls = uniqTraces(collectPersistenceCalls(filtered).filter(isRead).filter((t) => `${t.target}.${t.method}` !== primaryKey));
|
|
447
|
+
if (readCalls.length) {
|
|
448
|
+
const firstRepo = readCalls[0].target;
|
|
449
|
+
steps.push({ from: svcName, to: firstRepo, message: humanizeMethodCall(readCalls[0].method, firstRepo) });
|
|
450
|
+
steps.push({ from: firstRepo, to: svcName, message: buildReturnLabel(readCalls[0].returnType, readCalls[0].method, firstRepo), dashed: true });
|
|
451
|
+
}
|
|
452
|
+
// Group persistence writes into one SVC → Repo → SVC step
|
|
453
|
+
const writeCalls = uniqTraces(collectPersistenceCalls(filtered).filter((t) => !isRead(t)).filter((t) => `${t.target}.${t.method}` !== primaryKey));
|
|
454
|
+
if (writeCalls.length) {
|
|
455
|
+
const firstRepo = writeCalls[0].target;
|
|
456
|
+
steps.push({ from: svcName, to: firstRepo, message: humanizeMethodCall(writeCalls[0].method, firstRepo) });
|
|
457
|
+
steps.push({ from: firstRepo, to: svcName, message: buildReturnLabel(writeCalls[0].returnType, writeCalls[0].method, firstRepo), dashed: true });
|
|
458
|
+
}
|
|
459
|
+
// Group side effects — fire-and-forget; one forward arrow, no return
|
|
460
|
+
const seCalls = uniqTraces(collectSideEffectCalls(filtered));
|
|
461
|
+
if (seCalls.length) {
|
|
462
|
+
const firstSe = seCalls[0];
|
|
463
|
+
steps.push({ from: svcName, to: firstSe.target, message: humanizeMethodCall(firstSe.expression ?? firstSe.method, firstSe.target) });
|
|
464
|
+
}
|
|
465
|
+
// SVC → CTL: return value
|
|
466
|
+
steps.push({ from: svcName, to: ctlName, message: buildReturnLabel(primarySvc.returnType, primarySvc.expression ?? primarySvc.method, svcName), dashed: true });
|
|
467
|
+
// CTL → Actor: HTTP response
|
|
468
|
+
steps.push({ from: ctlName, to: actor, message: "response", dashed: true });
|
|
469
|
+
return steps;
|
|
470
|
+
}
|
|
471
|
+
const DETAIL_DEPTH = 12;
|
|
472
|
+
/**
|
|
473
|
+
* Pro-tier: enriched SequenceStep[] with branchId-based alt/loop fragment markers,
|
|
474
|
+
* expression labels, and typed return labels. Max depth 12, max messages 30.
|
|
475
|
+
*/
|
|
476
|
+
export function buildStepsDetailed(candidate, traces, actor) {
|
|
477
|
+
const steps = [{ from: actor, to: candidate.controller.name, message: candidate.endpoint }];
|
|
478
|
+
let emitted = 0;
|
|
479
|
+
// Track open branch stack: each entry is { branchId, isLoop }
|
|
480
|
+
const branchStack = [];
|
|
481
|
+
const fragStep = (fragment, label = "") => {
|
|
482
|
+
steps.push({ from: "", to: "", message: label, fragment, ...(label ? { fragmentLabel: label } : {}) });
|
|
483
|
+
};
|
|
484
|
+
const openBranch = (branchId, trace) => {
|
|
485
|
+
const isLoop = branchId.startsWith("loop:");
|
|
486
|
+
const isElseCatch = /-else$|-catch$|-finally$/.test(branchId);
|
|
487
|
+
if (isLoop) {
|
|
488
|
+
branchStack.push({ id: branchId, isLoop: true });
|
|
489
|
+
fragStep("loop-open", "loop");
|
|
490
|
+
}
|
|
491
|
+
else if (!isElseCatch) {
|
|
492
|
+
branchStack.push({ id: branchId, isLoop: false });
|
|
493
|
+
const rawCond = trace.conditions[0];
|
|
494
|
+
const guard = rawCond
|
|
495
|
+
? conditionSummary(rawCond).slice(0, 58)
|
|
496
|
+
: (branchId.startsWith("try:") ? "try" : "if");
|
|
497
|
+
fragStep("alt-open", guard);
|
|
498
|
+
}
|
|
499
|
+
else {
|
|
500
|
+
// else/catch/finally sub-branch: separator inside the existing alt frame
|
|
501
|
+
fragStep("alt-branch-sep", branchId.endsWith("-catch") ? "catch" : branchId.endsWith("-finally") ? "finally" : "else");
|
|
502
|
+
}
|
|
503
|
+
};
|
|
504
|
+
const closeBranch = () => {
|
|
505
|
+
const top = branchStack.pop();
|
|
506
|
+
if (!top)
|
|
507
|
+
return;
|
|
508
|
+
fragStep(top.isLoop ? "loop-close" : "alt-close");
|
|
509
|
+
};
|
|
510
|
+
const emit = (trace, caller, parentBranch) => {
|
|
511
|
+
if (INTERNAL_HELPERS.has(trace.method) || emitted >= 30 || NOISE_TARGETS.has(trace.target))
|
|
512
|
+
return;
|
|
513
|
+
if (trace.target === caller) {
|
|
514
|
+
for (const n of trace.nested.slice(0, DETAIL_DEPTH))
|
|
515
|
+
emit(n, caller, parentBranch);
|
|
516
|
+
return;
|
|
517
|
+
}
|
|
518
|
+
const curBranch = trace.branchId ?? null;
|
|
519
|
+
if (curBranch !== parentBranch) {
|
|
520
|
+
// Closing any open branch whose root differs from the new branchId's root
|
|
521
|
+
const newRoot = curBranch?.replace(/-else$|-catch$|-finally$/, "") ?? null;
|
|
522
|
+
const stackTop = branchStack.at(-1);
|
|
523
|
+
if (stackTop) {
|
|
524
|
+
const topRoot = stackTop.id.replace(/-else$|-catch$|-finally$/, "");
|
|
525
|
+
if (topRoot !== newRoot)
|
|
526
|
+
closeBranch();
|
|
527
|
+
}
|
|
528
|
+
if (curBranch !== null && (!branchStack.at(-1) || branchStack.at(-1).id.replace(/-else$|-catch$|-finally$/, "") !== newRoot)) {
|
|
529
|
+
openBranch(curBranch, trace);
|
|
530
|
+
}
|
|
531
|
+
else if (curBranch !== null && curBranch !== (branchStack.at(-1)?.id ?? null)) {
|
|
532
|
+
// Same root, different sub-branch (else/catch/finally)
|
|
533
|
+
fragStep("alt-branch-sep", curBranch.endsWith("-catch") ? "catch" : curBranch.endsWith("-finally") ? "finally" : "else");
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
emitted++;
|
|
537
|
+
const rawExpression = trace.expression ?? `${trace.method}()`;
|
|
538
|
+
const label = humanizeMethodCall(rawExpression, trace.target);
|
|
539
|
+
steps.push({ from: caller, to: trace.target, message: label });
|
|
540
|
+
for (const n of trace.nested.slice(0, DETAIL_DEPTH))
|
|
541
|
+
emit(n, trace.target, null);
|
|
542
|
+
steps.push({ from: trace.target, to: caller, message: buildReturnLabel(trace.returnType, rawExpression, trace.target), dashed: true });
|
|
543
|
+
};
|
|
544
|
+
const selected = traces.filter((t) => !NOISE_TARGETS.has(t.target)).slice(0, DETAIL_DEPTH);
|
|
545
|
+
for (const t of selected)
|
|
546
|
+
emit(t, candidate.controller.name, undefined);
|
|
547
|
+
// Close any still-open branches
|
|
548
|
+
while (branchStack.length > 0)
|
|
549
|
+
closeBranch();
|
|
550
|
+
steps.push({ from: candidate.controller.name, to: actor, message: "response", dashed: true });
|
|
551
|
+
return steps;
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Dispatcher: Pro tier → `buildStepsDetailed`; baseline tier → `buildStepsBaseline`.
|
|
555
|
+
* The `tier` param drives the decision; ARCHSCRIBE_RESEARCH_MODE sets tier="pro" in verify.ts.
|
|
556
|
+
*/
|
|
557
|
+
export function buildSequenceSteps(candidate, traces, actor, tier = "baseline") {
|
|
558
|
+
return tier === "pro" ? buildStepsDetailed(candidate, traces, actor) : buildStepsBaseline(candidate, traces, actor);
|
|
559
|
+
}
|
|
560
|
+
// ── Private helpers ────────────────────────────────────────────────────────
|
|
561
|
+
function validationText(conditions, v = "") {
|
|
562
|
+
const pub = /signup|register|signin|login|authenticate|generateqrsession|qr\.login/.test(v);
|
|
563
|
+
const s = uniq(conditions.map(conditionSummary).filter(Boolean)).slice(0, 4);
|
|
564
|
+
if (pub)
|
|
565
|
+
return "(BE) Hệ thống tiếp nhận yêu cầu và xác minh tính hợp lệ của dữ liệu đầu vào.";
|
|
566
|
+
if (!s.length)
|
|
567
|
+
return "(BE) Hệ thống tiếp nhận yêu cầu, xác thực phiên/quyền truy cập và kiểm tra dữ liệu đầu vào.";
|
|
568
|
+
if (s.some((x) => /người lạ|stranger/i.test(x)))
|
|
569
|
+
return "(BE) Hệ thống tiếp nhận yêu cầu, xác thực phiên và kiểm tra quyền gửi tin nhắn theo chính sách của người nhận.";
|
|
570
|
+
if (s.some((x) => /phiên đăng nhập|xác thực|token|session/i.test(x)))
|
|
571
|
+
return "(BE) Hệ thống tiếp nhận yêu cầu, xác thực phiên/quyền truy cập và kiểm tra dữ liệu đầu vào.";
|
|
572
|
+
return `(BE) Hệ thống tiếp nhận yêu cầu, xác thực phiên và kiểm tra ${joinList(s.slice(0, 2))}.`;
|
|
573
|
+
}
|
|
574
|
+
function responseText(fx) {
|
|
575
|
+
return fx.some((c) => /Messaging|WebSocket|convertAndSend|STOMP/i.test(`${c.target}.${c.method}`))
|
|
576
|
+
? "(BE) Hệ thống xác nhận kết quả xử lý hoặc gửi phản hồi trạng thái cho client."
|
|
577
|
+
: "(BE) Hệ thống trả kết quả xử lý cho client.";
|
|
578
|
+
}
|
|
579
|
+
function persistenceTexts(calls, skipReads = false) {
|
|
580
|
+
const reads = skipReads ? [] : uniq(calls.filter(isRead).map(persistTarget)).slice(0, 3);
|
|
581
|
+
const writes = uniq(calls.filter((c) => !isRead(c)).map(persistTarget)).slice(0, 3);
|
|
582
|
+
const r = [];
|
|
583
|
+
if (reads.length)
|
|
584
|
+
r.push(`(BE) Hệ thống truy xuất/kiểm tra ${joinList(reads)} cần thiết cho nghiệp vụ.`);
|
|
585
|
+
if (writes.length)
|
|
586
|
+
r.push(`(BE) Hệ thống ghi nhận/cập nhật ${joinList(writes)} theo kết quả xử lý.`);
|
|
587
|
+
return r;
|
|
588
|
+
}
|
|
589
|
+
function sideEffectTexts(calls) {
|
|
590
|
+
const s = uniq(calls.map(sideEffectLabel)).slice(0, 3);
|
|
591
|
+
if (!s.length)
|
|
592
|
+
return [];
|
|
593
|
+
const v = s.slice(0, 2), rest = s.length - v.length;
|
|
594
|
+
return [`(BE) Hệ thống ${joinList(v)}${rest > 0 ? ` và ${rest} tác vụ phụ trợ khác` : ""}.`];
|
|
595
|
+
}
|
|
596
|
+
/** Convert a condition summary (Vietnamese noun phrase) to a guard-condition question. */
|
|
597
|
+
function toGuardConditionQuestion(summary) {
|
|
598
|
+
const s = summary.toLowerCase();
|
|
599
|
+
if (s.includes("mật khẩu") || s.includes("xác thực"))
|
|
600
|
+
return "Mật khẩu / xác thực hợp lệ?";
|
|
601
|
+
if (s.includes("phiên đăng nhập") || s.includes("token"))
|
|
602
|
+
return "Phiên đăng nhập hợp lệ?";
|
|
603
|
+
if (s.includes("tài khoản"))
|
|
604
|
+
return "Tài khoản đang hoạt động?";
|
|
605
|
+
if (s.includes("tồn kho") || s.includes("số lượng"))
|
|
606
|
+
return "Số lượng đủ?";
|
|
607
|
+
if (s.includes("quyền thành viên") || s.includes("thành viên"))
|
|
608
|
+
return "Người dùng là thành viên?";
|
|
609
|
+
if (s.includes("bạn bè") || s.includes("lời mời kết bạn"))
|
|
610
|
+
return "Lời mời / quan hệ hợp lệ?";
|
|
611
|
+
if (s.includes("phòng chat") || s.includes("chat"))
|
|
612
|
+
return "Phòng chat còn hoạt động?";
|
|
613
|
+
if (s.includes("tin nhắn từ người lạ") || s.includes("stranger"))
|
|
614
|
+
return "Cho phép nhận tin từ người lạ?";
|
|
615
|
+
if (s.includes("thu hồi") || s.includes("thời gian cho phép"))
|
|
616
|
+
return "Còn trong thời gian cho phép?";
|
|
617
|
+
if (s.includes("định danh") || s.includes("email") || s.includes("username"))
|
|
618
|
+
return "Thông tin định danh hợp lệ?";
|
|
619
|
+
if (s.includes("trạng thái"))
|
|
620
|
+
return "Trạng thái nghiệp vụ đúng?";
|
|
621
|
+
if (s.includes("dữ liệu bắt buộc"))
|
|
622
|
+
return "Dữ liệu đầu vào đầy đủ?";
|
|
623
|
+
const cap = summary.charAt(0).toUpperCase() + summary.slice(1);
|
|
624
|
+
return `${cap} hợp lệ?`;
|
|
625
|
+
}
|
|
626
|
+
function conditionSummary(c) {
|
|
627
|
+
const n = c.trim();
|
|
628
|
+
if (/STRANGER_MESSAGES_NOT_ALLOWED|stranger/i.test(n))
|
|
629
|
+
return "chính sách nhận tin nhắn từ người lạ của người nhận";
|
|
630
|
+
if (/principal\s*==\s*null|authentication\s*==\s*null/i.test(n))
|
|
631
|
+
return "phiên đăng nhập còn hợp lệ";
|
|
632
|
+
if (/UsernamePasswordAuthenticationToken|instanceof/i.test(n) && /principal|authentication/i.test(n))
|
|
633
|
+
return "thông tin xác thực trong phiên đăng nhập";
|
|
634
|
+
if (/stock|quantity/i.test(n))
|
|
635
|
+
return "số lượng tồn kho hoặc số lượng yêu cầu";
|
|
636
|
+
if (/email|phone|username/i.test(n))
|
|
637
|
+
return "thông tin định danh người dùng";
|
|
638
|
+
if (/room|chat/i.test(n))
|
|
639
|
+
return "trạng thái phòng chat liên quan";
|
|
640
|
+
if (/token|otp|verification|session/i.test(n))
|
|
641
|
+
return "token hoặc phiên xác thực";
|
|
642
|
+
if (/locked|disabled|enabled|active/i.test(n))
|
|
643
|
+
return "trạng thái hoạt động của tài khoản";
|
|
644
|
+
if (/password|matches/i.test(n))
|
|
645
|
+
return "mật khẩu hoặc thông tin xác thực";
|
|
646
|
+
if (/revoke|existing.*type|sameType/i.test(n))
|
|
647
|
+
return "phiên đăng nhập cùng loại đang hoạt động";
|
|
648
|
+
if (/isOnline|online/i.test(n))
|
|
649
|
+
return "trạng thái online của người dùng";
|
|
650
|
+
if (/friend.*request|request.*friend/i.test(n))
|
|
651
|
+
return "quyền sở hữu hoặc trạng thái của lời mời kết bạn";
|
|
652
|
+
if (/recall.*time|time.*recall|expire/i.test(n))
|
|
653
|
+
return "thời gian cho phép thu hồi tin nhắn";
|
|
654
|
+
if (/Instant\.|LocalDateTime|ZonedDateTime|Duration\.|ChronoUnit|isAfter\(|isBefore\(|\.plus\(\d|\.minus\(\d/i.test(n))
|
|
655
|
+
return "thời gian cho phép thực hiện thao tác còn hiệu lực";
|
|
656
|
+
if (/member.*room|room.*member|participant/i.test(n))
|
|
657
|
+
return "quyền thành viên trong phòng chat";
|
|
658
|
+
if (/isPresent|isEmpty|null/i.test(n))
|
|
659
|
+
return "dữ liệu bắt buộc hợp lệ";
|
|
660
|
+
if (/status/i.test(n))
|
|
661
|
+
return "trạng thái nghiệp vụ hiện tại";
|
|
662
|
+
if (/[.()\[\]!]/.test(n) || /\b(get|set|is|has|equals|instanceof)\w/i.test(n))
|
|
663
|
+
return "điều kiện nghiệp vụ liên quan";
|
|
664
|
+
return n.replace(/([a-z])([A-Z])/g, "$1 $2").replace(/_/g, " ").toLowerCase().slice(0, 60) || "điều kiện nghiệp vụ liên quan";
|
|
665
|
+
}
|
|
666
|
+
function persistTarget(t) {
|
|
667
|
+
const v = `${t.target} ${t.method}`;
|
|
668
|
+
if (/MessageRepository|MessageDynamo|ChatDynamo/i.test(v))
|
|
669
|
+
return "dữ liệu tin nhắn";
|
|
670
|
+
if (/User|Account|Profile/i.test(v))
|
|
671
|
+
return "thông tin người dùng";
|
|
672
|
+
if (/Role|Permission|Privilege/i.test(v))
|
|
673
|
+
return "quyền và vai trò người dùng";
|
|
674
|
+
if (/Friend|Block|Relationship/i.test(v))
|
|
675
|
+
return "quan hệ bạn bè";
|
|
676
|
+
if (/Room|Group/i.test(v))
|
|
677
|
+
return "phòng chat hoặc nhóm chat";
|
|
678
|
+
if (/File|Media|Minio|S3|Storage/i.test(v))
|
|
679
|
+
return "tệp đính kèm hoặc media";
|
|
680
|
+
if (/Token|Otp|Session/i.test(v))
|
|
681
|
+
return "token hoặc phiên xác thực";
|
|
682
|
+
if (/Analytics|Activity|Log|Audit/i.test(v))
|
|
683
|
+
return "nhật ký hoạt động hệ thống";
|
|
684
|
+
if (/Notification|Alert/i.test(v))
|
|
685
|
+
return "thông báo";
|
|
686
|
+
if (/Message|Chat/i.test(v))
|
|
687
|
+
return "dữ liệu tin nhắn";
|
|
688
|
+
return "dữ liệu nghiệp vụ liên quan";
|
|
689
|
+
}
|
|
690
|
+
function sideEffectLabel(t) {
|
|
691
|
+
const v = `${t.target} ${t.method}`;
|
|
692
|
+
if (/Messaging|WebSocket|convertAndSend|sendMessage|STOMP/i.test(v))
|
|
693
|
+
return "gửi sự kiện realtime qua WebSocket";
|
|
694
|
+
if (/Firebase|FCM|FcmService|FirebaseMessaging/i.test(v))
|
|
695
|
+
return "gửi push notification đến thiết bị người dùng";
|
|
696
|
+
if (/Notification|notify/i.test(v))
|
|
697
|
+
return "gửi thông báo đến người dùng liên quan";
|
|
698
|
+
if (/Email|Mail/i.test(v))
|
|
699
|
+
return "gửi email thông báo hoặc xác thực";
|
|
700
|
+
if (/Publisher|publish|Event/i.test(v))
|
|
701
|
+
return "phát sự kiện nghiệp vụ nội bộ";
|
|
702
|
+
if (/Minio|S3|Storage|upload/i.test(v))
|
|
703
|
+
return "xử lý tệp hoặc media trên storage";
|
|
704
|
+
if (/updateOnlineStatus|setOnlineStatus/i.test(v))
|
|
705
|
+
return "cập nhật trạng thái online của người dùng";
|
|
706
|
+
if (/initCloudRoom|initRoom/i.test(v))
|
|
707
|
+
return "khởi tạo phòng lưu trữ cá nhân cho tài khoản mới";
|
|
708
|
+
if (/createDirectChat/i.test(v))
|
|
709
|
+
return "tạo phòng chat trực tiếp giữa hai người dùng";
|
|
710
|
+
return "thực hiện tác vụ phụ trợ sau xử lý chính";
|
|
711
|
+
}
|
|
712
|
+
function altTitle(s) {
|
|
713
|
+
if (s.some((x) => /người lạ|stranger/i.test(x)))
|
|
714
|
+
return "Người nhận không cho phép tin nhắn từ người lạ";
|
|
715
|
+
if (s.some((x) => /phiên đăng nhập|xác thực|token|session/i.test(x)))
|
|
716
|
+
return "Phiên hoặc thông tin xác thực không hợp lệ";
|
|
717
|
+
if (s.some((x) => /tồn kho|số lượng/i.test(x)))
|
|
718
|
+
return "Số lượng hoặc tồn kho không đáp ứng";
|
|
719
|
+
return "Điều kiện nghiệp vụ không thỏa";
|
|
720
|
+
}
|
|
721
|
+
function altReason(s) {
|
|
722
|
+
if (s.some((x) => /người lạ|stranger/i.test(x)))
|
|
723
|
+
return "(BE) Hệ thống xác định người nhận không cho phép tin nhắn từ người lạ hoặc người gửi không đủ điều kiện gửi tin.";
|
|
724
|
+
if (s.some((x) => /phiên đăng nhập|xác thực|token|session/i.test(x)))
|
|
725
|
+
return "(BE) Hệ thống xác định phiên đăng nhập hoặc thông tin xác thực không hợp lệ.";
|
|
726
|
+
if (s.some((x) => /tồn kho|số lượng/i.test(x)))
|
|
727
|
+
return "(BE) Hệ thống xác định số lượng yêu cầu không đáp ứng điều kiện xử lý.";
|
|
728
|
+
return "(BE) Hệ thống xác định dữ liệu đầu vào hoặc điều kiện nghiệp vụ chưa đáp ứng.";
|
|
729
|
+
}
|
|
730
|
+
function isRead(t) {
|
|
731
|
+
return /find|get|query|scan|search|exists|count|load|check|verify/i.test(t.method) &&
|
|
732
|
+
!/save|insert|update|delete|remove|flush|upload|put|create/i.test(t.method);
|
|
733
|
+
}
|
|
734
|
+
function collectConditions(method, traces) {
|
|
735
|
+
return Array.from(new Set([...(method.conditions ?? []), ...flattenTraces(traces).flatMap((t) => t.conditions)]))
|
|
736
|
+
.filter((c) => {
|
|
737
|
+
if (/^\w*Exception\s+\w+$/.test(c))
|
|
738
|
+
return false; // "IOException ex"
|
|
739
|
+
if (/^[a-z_]\w*\s+instanceof\s/i.test(c) &&
|
|
740
|
+
!/principal|authentication|userdetails/i.test(c))
|
|
741
|
+
return false; // "e instanceof X" (keep auth instanceof)
|
|
742
|
+
if (/^[a-z]{1,2}$/.test(c.trim()))
|
|
743
|
+
return false; // single/double char var ("e", "ex")
|
|
744
|
+
if (/^catch\s*\(/.test(c.trim()))
|
|
745
|
+
return false; // "catch (Exception e)"
|
|
746
|
+
return true;
|
|
747
|
+
})
|
|
748
|
+
.slice(0, 8);
|
|
749
|
+
}
|
|
750
|
+
function collectPersistenceCalls(traces) {
|
|
751
|
+
return flattenTraces(traces).filter((t) => t.stereotype === "repository" || /Repository$/i.test(t.target) || /DynamoRepository|Storage|Minio|S3/i.test(t.target));
|
|
752
|
+
}
|
|
753
|
+
function collectSideEffectCalls(traces) {
|
|
754
|
+
return flattenTraces(traces).filter((t) => /Notification|Messaging|Email|Otp|Minio|S3|WebSocket|Template|Firebase|FCM|FcmService|FirebaseMessaging/i.test(t.target) ||
|
|
755
|
+
/send(?:Message|Notification|Email|Push|To|Otp|Alert|Event|Invite)|^publish|^notify|^upload|convert.*[Ss]end/i.test(t.method) ||
|
|
756
|
+
/updateOnlineStatus|setOnlineStatus|initCloudRoom|initRoom/i.test(t.method) ||
|
|
757
|
+
// createDirectChat as side effect (called after a primary operation, not as the main action)
|
|
758
|
+
/createDirectChat/i.test(t.method));
|
|
759
|
+
}
|
|
760
|
+
function uniqTraces(calls) {
|
|
761
|
+
const seen = new Set();
|
|
762
|
+
// Use expression when available — this lets getUserById(senderId) and getUserById(receiverId) both appear
|
|
763
|
+
return calls.filter((c) => { const k = c.expression ?? `${c.target}.${c.method}`; if (seen.has(k))
|
|
764
|
+
return false; seen.add(k); return true; });
|
|
765
|
+
}
|
|
766
|
+
function hasTraceKw(traces, re) { return flattenTraces(traces).some((t) => re.test(`${t.target} ${t.method}`)); }
|
|
767
|
+
function hasValidation(m) {
|
|
768
|
+
return (m.params ?? []).some((p) => /Request|Dto|DTO/i.test(p.type)) || (m.annotations ?? []).some((a) => /Valid|Validated/i.test(a));
|
|
769
|
+
}
|
|
770
|
+
function usesPrincipal(m) {
|
|
771
|
+
return (m.params ?? []).some((p) => /Principal|UserDetails|Authentication/i.test(p.type)) || (m.invocations ?? []).some((inv) => inv.method === "getUserIdFromPrincipal");
|
|
772
|
+
}
|
|
773
|
+
function uniq(values) { return Array.from(new Set(values.map((v) => v.trim()).filter(Boolean))); }
|
|
774
|
+
function joinList(items) {
|
|
775
|
+
if (items.length <= 1)
|
|
776
|
+
return items[0] ?? "";
|
|
777
|
+
if (items.length === 2)
|
|
778
|
+
return items.some((i) => i.includes(" và ")) ? `${items[0]}, ${items[1]}` : `${items[0]} và ${items[1]}`;
|
|
779
|
+
return `${items.slice(0, -1).join(", ")} và ${items.at(-1)}`;
|
|
780
|
+
}
|
|
781
|
+
function humanize(v) {
|
|
782
|
+
return v.replace(/[^\p{L}\p{N}_$]+$/gu, "").replace(/([a-z])([A-Z])/g, "$1 $2").replace(/[-_]/g, " ").trim().toLowerCase().replace(/^./, (c) => c.toUpperCase());
|
|
783
|
+
}
|
|
784
|
+
function businessActionText(candidate, label, traces) {
|
|
785
|
+
const v = `${label} ${candidate.method.name} ${candidate.endpoint}`.toLowerCase();
|
|
786
|
+
if (/generateqrsession|qr.login.generate/.test(v))
|
|
787
|
+
return "(BE) Hệ thống tạo phiên đăng nhập QR với mã định danh ngẫu nhiên và lưu trạng thái chờ xác nhận.";
|
|
788
|
+
if (/signup|register/.test(v))
|
|
789
|
+
return "(BE) Hệ thống tạo tài khoản mới và lưu thông tin người dùng vào cơ sở dữ liệu.";
|
|
790
|
+
if (/signin|login|authenticate/.test(v))
|
|
791
|
+
return "(BE) Hệ thống xác thực thông tin đăng nhập và cập nhật trạng thái hoạt động của người dùng.";
|
|
792
|
+
if (/changepassword|change.password/.test(v))
|
|
793
|
+
return "(BE) Hệ thống xác minh mật khẩu hiện tại và cập nhật mật khẩu mới cho tài khoản.";
|
|
794
|
+
if (/sendfriendrequest|friends.request/.test(v))
|
|
795
|
+
return "(BE) Hệ thống kiểm tra quan hệ giữa hai người dùng và gửi lời mời kết bạn đến người nhận.";
|
|
796
|
+
if (/acceptfriendrequest|friends.accept/.test(v))
|
|
797
|
+
return "(BE) Hệ thống xác nhận lời mời kết bạn và thiết lập quan hệ bạn bè giữa hai người dùng.";
|
|
798
|
+
if (/recallmessage|messages.recall/.test(v))
|
|
799
|
+
return "(BE) Hệ thống cập nhật trạng thái tin nhắn thành đã thu hồi và thông báo đến các bên trong phòng chat.";
|
|
800
|
+
if (/sendmessagerest|chat.send/.test(v))
|
|
801
|
+
return "(BE) Hệ thống kiểm tra quyền gửi tin nhắn, lưu tin nhắn vào cơ sở dữ liệu và chuẩn bị thông báo đến các thành viên.";
|
|
802
|
+
if (/createdirectchat|rooms.private/.test(v))
|
|
803
|
+
return "(BE) Hệ thống kiểm tra quan hệ giữa hai người dùng và tạo phòng chat riêng tư nếu chưa tồn tại.";
|
|
804
|
+
if (/summarizechat|ai.summarize/.test(v))
|
|
805
|
+
return "(BE) Hệ thống truy xuất lịch sử trò chuyện và gọi AI service để tạo bản tóm tắt nội dung.";
|
|
806
|
+
const writes = uniqTraces(collectPersistenceCalls(traces).filter((c) => !isRead(c)));
|
|
807
|
+
const reads = uniqTraces(collectPersistenceCalls(traces).filter(isRead));
|
|
808
|
+
if (writes.length)
|
|
809
|
+
return `(BE) Hệ thống xử lý nghiệp vụ và cập nhật ${joinList(writes.map(persistTarget))} trong cơ sở dữ liệu.`;
|
|
810
|
+
if (reads.length)
|
|
811
|
+
return `(BE) Hệ thống truy xuất ${joinList(reads.map(persistTarget))} và thực thi nghiệp vụ theo yêu cầu.`;
|
|
812
|
+
return `(BE) Hệ thống thực thi nghiệp vụ "${label}" và chuẩn bị kết quả phản hồi.`;
|
|
813
|
+
}
|
|
814
|
+
//# sourceMappingURL=flow-steps.js.map
|