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,275 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Low-level terminal helpers for archscribe's CLI UI.
|
|
3
|
+
*
|
|
4
|
+
* IMPORTANT (MCP): an MCP stdio server uses STDOUT for JSON-RPC.
|
|
5
|
+
* Everything here writes to STDERR only. Animations only run when both
|
|
6
|
+
* stdin and stderr are real TTYs — i.e. a human typed a command, not
|
|
7
|
+
* an MCP client spawning the server through pipes.
|
|
8
|
+
*
|
|
9
|
+
* SIGINT/exit handlers are registered lazily inside hideCursor() and
|
|
10
|
+
* removed inside showCursor() so they do not interfere with @clack/prompts
|
|
11
|
+
* used in setup/login commands.
|
|
12
|
+
*/
|
|
13
|
+
const env = process.env;
|
|
14
|
+
const on = (k) => Boolean(env[k]);
|
|
15
|
+
export const out = process.stderr;
|
|
16
|
+
// NO_COLOR (https://no-color.org/) must always win, even over ARCHSCRIBE_ANIM=1.
|
|
17
|
+
const noColor = 'NO_COLOR' in env || env.TERM === 'dumb';
|
|
18
|
+
export const caps = {
|
|
19
|
+
// Getter: re-reads ARCHSCRIBE_ANIM at call time so --no-anim (which sets the
|
|
20
|
+
// env var after import) takes effect without a restart.
|
|
21
|
+
// Only checks stderr.isTTY — on Windows the .cmd wrapper from npm link drops
|
|
22
|
+
// stdin.isTTY, and the CLI is never an MCP server so stdin check is unneeded.
|
|
23
|
+
get animate() {
|
|
24
|
+
const a = process.env.ARCHSCRIBE_ANIM;
|
|
25
|
+
if (a === '0')
|
|
26
|
+
return false;
|
|
27
|
+
if (a === '1')
|
|
28
|
+
return true;
|
|
29
|
+
return Boolean(out.isTTY) && !process.env.CI && process.env.TERM !== 'dumb';
|
|
30
|
+
},
|
|
31
|
+
color: !noColor && (env.ARCHSCRIBE_ANIM === '1' || Boolean(out.isTTY)),
|
|
32
|
+
unicode: process.platform !== 'win32' || on('WT_SESSION') || env.TERM_PROGRAM === 'vscode',
|
|
33
|
+
};
|
|
34
|
+
const wrap = (open, close) => (s) => caps.color ? `\x1b[${open}m${s}\x1b[${close}m` : s;
|
|
35
|
+
export const c = {
|
|
36
|
+
bold: wrap(1, 22),
|
|
37
|
+
dim: wrap(2, 22),
|
|
38
|
+
red: wrap(91, 39),
|
|
39
|
+
green: wrap(92, 39),
|
|
40
|
+
yellow: wrap(93, 39),
|
|
41
|
+
blue: wrap(94, 39),
|
|
42
|
+
magenta: wrap(95, 39),
|
|
43
|
+
cyan: wrap(96, 39),
|
|
44
|
+
gray: wrap(90, 39),
|
|
45
|
+
};
|
|
46
|
+
export const SYM = caps.unicode
|
|
47
|
+
? { ok: '✓', fail: '✗', step: '›', pointer: '▸', block: '█', caret: '▌', full: '▰', empty: '▱' }
|
|
48
|
+
: { ok: 'OK', fail: 'X', step: '>', pointer: '>', block: '#', caret: '|', full: '#', empty: '-' };
|
|
49
|
+
const ANSI = /\x1b\[[0-9;]*m/g;
|
|
50
|
+
export const visibleWidth = (s) => [...s.replace(ANSI, '')].length;
|
|
51
|
+
export const padEndV = (s, w) => s + ' '.repeat(Math.max(0, w - visibleWidth(s)));
|
|
52
|
+
/** Place two blocks of lines side-by-side. */
|
|
53
|
+
export function sideBySide(left, right, gap = 2) {
|
|
54
|
+
const lw = Math.max(0, ...left.map(visibleWidth));
|
|
55
|
+
const n = Math.max(left.length, right.length);
|
|
56
|
+
return Array.from({ length: n }, (_, i) => padEndV(left[i] ?? '', lw + gap) + (right[i] ?? ''));
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Clip a string to `maxVisible` visible characters, ANSI-aware.
|
|
60
|
+
*
|
|
61
|
+
* Walks char by char and skips escape sequences to their letter terminator so
|
|
62
|
+
* a cut never lands inside one, then re-closes a still-open colour with
|
|
63
|
+
* `\x1b[0m`. Clipping matters for correctness, not just looks: a line wider
|
|
64
|
+
* than the terminal wraps onto a second row, and LiveArea's `\x1b[{n}F` rewind
|
|
65
|
+
* would then land on the wrong line and smear the frame.
|
|
66
|
+
*/
|
|
67
|
+
export function clip(s, maxVisible) {
|
|
68
|
+
if (maxVisible <= 0)
|
|
69
|
+
return '';
|
|
70
|
+
if (visibleWidth(s) <= maxVisible)
|
|
71
|
+
return s;
|
|
72
|
+
let vw = 0, result = '', openAnsi = false, i = 0;
|
|
73
|
+
while (i < s.length) {
|
|
74
|
+
if (s[i] === '\x1b' && s[i + 1] === '[') {
|
|
75
|
+
let j = i + 2;
|
|
76
|
+
while (j < s.length && !/[A-Za-z]/.test(s[j]))
|
|
77
|
+
j++;
|
|
78
|
+
const seq = s.slice(i, j + 1);
|
|
79
|
+
result += seq;
|
|
80
|
+
if (s[j] === 'm')
|
|
81
|
+
openAnsi = seq !== '\x1b[0m' && seq !== '\x1b[m';
|
|
82
|
+
i = j + 1;
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
if (vw >= maxVisible)
|
|
86
|
+
break;
|
|
87
|
+
result += s[i];
|
|
88
|
+
vw++;
|
|
89
|
+
i++;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return openAnsi ? result + '\x1b[0m' : result;
|
|
93
|
+
}
|
|
94
|
+
export const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
95
|
+
/** Write straight to the terminal, bypassing the live-area guard below. */
|
|
96
|
+
function raw(s) {
|
|
97
|
+
(guard.original ?? out.write.bind(out))(s);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* A region of the terminal that can be redrawn in place.
|
|
101
|
+
*
|
|
102
|
+
* Smoothness notes: each line ends with `\x1b[K` (erase to end of line) so a
|
|
103
|
+
* frame overwrites the previous one in a single pass instead of the
|
|
104
|
+
* erase-everything-then-repaint flash that `\x1b[0J` up front causes. The
|
|
105
|
+
* full clear is only emitted when the new frame is SHORTER than the tallest
|
|
106
|
+
* one drawn so far. Identical frames are skipped entirely — at 40 fps most
|
|
107
|
+
* frames change only a few cells, and skipping no-ops keeps the terminal from
|
|
108
|
+
* doing useless work.
|
|
109
|
+
*
|
|
110
|
+
* Correctness rests on one invariant: `height` is the exact number of physical
|
|
111
|
+
* rows the area occupies, because `render()` rewinds by precisely that many.
|
|
112
|
+
* Two things can break it, and both are handled here rather than at the call
|
|
113
|
+
* sites — every line is clipped to the terminal width so none can wrap onto a
|
|
114
|
+
* second row, and a stderr guard routes writes that bypass the area (see
|
|
115
|
+
* `guard`) instead of letting them push the cursor down uncounted.
|
|
116
|
+
*/
|
|
117
|
+
export class LiveArea {
|
|
118
|
+
height = 0;
|
|
119
|
+
last = '';
|
|
120
|
+
/** Tallest frame drawn since the last commit()/clear(), for the shrink clear. */
|
|
121
|
+
peak = 0;
|
|
122
|
+
render(lines) {
|
|
123
|
+
const safe = lines.map((l) => clip(l, Math.max(1, (out.columns || 80) - 1)));
|
|
124
|
+
const body = safe.map((l) => l + '\x1b[K').join('\n');
|
|
125
|
+
if (body === this.last && this.height === safe.length)
|
|
126
|
+
return;
|
|
127
|
+
guard.install(this);
|
|
128
|
+
const rewind = this.height ? `\x1b[${this.height}F` : '';
|
|
129
|
+
const shrank = safe.length < this.peak;
|
|
130
|
+
raw(rewind + body + '\n' + (shrank ? '\x1b[0J' : ''));
|
|
131
|
+
this.height = safe.length;
|
|
132
|
+
this.peak = shrank ? safe.length : Math.max(this.peak, safe.length);
|
|
133
|
+
this.last = body;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Emit a write that did not come from this area without desyncing the frame.
|
|
137
|
+
*
|
|
138
|
+
* Lifts the frame off screen so `emit` lands on a clean row, then repaints it
|
|
139
|
+
* underneath. `height` stays valid because exactly as many rows go back as
|
|
140
|
+
* came off, and the lift's `\x1b[0J` means nothing survives below the frame.
|
|
141
|
+
*
|
|
142
|
+
* @internal The stderr guard calls this; it is not part of the drawing API.
|
|
143
|
+
*/
|
|
144
|
+
interleave(text, emit) {
|
|
145
|
+
if (!this.height)
|
|
146
|
+
return emit();
|
|
147
|
+
raw(`\x1b[${this.height}F\x1b[0J`);
|
|
148
|
+
const ok = emit();
|
|
149
|
+
if (!text.endsWith('\n'))
|
|
150
|
+
raw('\n');
|
|
151
|
+
raw(this.last + '\n');
|
|
152
|
+
this.peak = this.height;
|
|
153
|
+
return ok;
|
|
154
|
+
}
|
|
155
|
+
/** Keep the last frame on screen; the next render starts below it. */
|
|
156
|
+
commit() {
|
|
157
|
+
guard.release(this);
|
|
158
|
+
this.height = 0;
|
|
159
|
+
this.peak = 0;
|
|
160
|
+
this.last = '';
|
|
161
|
+
}
|
|
162
|
+
clear() {
|
|
163
|
+
if (this.height)
|
|
164
|
+
raw(`\x1b[${this.height}F\x1b[0J`);
|
|
165
|
+
guard.release(this);
|
|
166
|
+
this.height = 0;
|
|
167
|
+
this.peak = 0;
|
|
168
|
+
this.last = '';
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Makes the live area the only writer of stderr while it is on screen.
|
|
173
|
+
*
|
|
174
|
+
* A `LiveArea` rewinds by the exact number of rows it last wrote, so any write
|
|
175
|
+
* that bypasses it — a stray `console.warn` from a fire-and-forget background
|
|
176
|
+
* task, for instance — advances the cursor by rows the area never counted. The
|
|
177
|
+
* next rewind then lands that many rows too low and the top of the frame is
|
|
178
|
+
* orphaned on screen permanently, with the area redrawing below it forever.
|
|
179
|
+
*
|
|
180
|
+
* So while an area is live, `stderr.write` is patched to hand foreign text to
|
|
181
|
+
* `LiveArea.interleave()`, which scrolls it in above the frame the way
|
|
182
|
+
* `stage.log()` does. The patch is removed on commit()/clear(), and it never
|
|
183
|
+
* clobbers a patch someone else installed on top of it (tests capture stderr
|
|
184
|
+
* this way).
|
|
185
|
+
*/
|
|
186
|
+
const guard = {
|
|
187
|
+
area: null,
|
|
188
|
+
patched: null,
|
|
189
|
+
original: null,
|
|
190
|
+
install(area) {
|
|
191
|
+
this.area = area;
|
|
192
|
+
if (this.patched && out.write === this.patched)
|
|
193
|
+
return; // still ours
|
|
194
|
+
const original = out.write.bind(out);
|
|
195
|
+
const patched = ((chunk, enc, cb) => {
|
|
196
|
+
const emit = () => original(chunk, enc, cb);
|
|
197
|
+
const area_ = guard.area;
|
|
198
|
+
if (!area_ || guard.inside)
|
|
199
|
+
return emit();
|
|
200
|
+
const text = typeof chunk === 'string' ? chunk : Buffer.from(chunk).toString();
|
|
201
|
+
// Pure control sequences (cursor show/hide) move nothing vertically.
|
|
202
|
+
if (text.replace(/\x1b\[[0-9;?]*[A-Za-z]/g, '') === '')
|
|
203
|
+
return emit();
|
|
204
|
+
guard.inside = true;
|
|
205
|
+
try {
|
|
206
|
+
return area_.interleave(text, emit);
|
|
207
|
+
}
|
|
208
|
+
finally {
|
|
209
|
+
guard.inside = false;
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
this.original = original;
|
|
213
|
+
this.patched = patched;
|
|
214
|
+
out.write = patched;
|
|
215
|
+
},
|
|
216
|
+
release(area) {
|
|
217
|
+
if (this.area !== area)
|
|
218
|
+
return;
|
|
219
|
+
if (this.patched && this.original && out.write === this.patched)
|
|
220
|
+
out.write = this.original;
|
|
221
|
+
this.area = null;
|
|
222
|
+
this.patched = null;
|
|
223
|
+
this.original = null;
|
|
224
|
+
},
|
|
225
|
+
/** True while `interleave` is emitting, so its own writes are not re-routed. */
|
|
226
|
+
inside: false,
|
|
227
|
+
};
|
|
228
|
+
// ── Cursor management (lazy handler registration) ────────────────────────────
|
|
229
|
+
let cursorHidden = false;
|
|
230
|
+
let exitHandler = null;
|
|
231
|
+
let sigintHandler = null;
|
|
232
|
+
function ensureCleanupHandlers() {
|
|
233
|
+
if (exitHandler)
|
|
234
|
+
return;
|
|
235
|
+
exitHandler = () => { if (cursorHidden)
|
|
236
|
+
out.write('\x1b[?25h'); };
|
|
237
|
+
sigintHandler = () => {
|
|
238
|
+
if (cursorHidden)
|
|
239
|
+
out.write('\x1b[?25h');
|
|
240
|
+
out.write('\n');
|
|
241
|
+
process.exit(130);
|
|
242
|
+
};
|
|
243
|
+
process.on('exit', exitHandler);
|
|
244
|
+
process.once('SIGINT', sigintHandler);
|
|
245
|
+
}
|
|
246
|
+
function removeCleanupHandlers() {
|
|
247
|
+
if (exitHandler) {
|
|
248
|
+
process.off('exit', exitHandler);
|
|
249
|
+
exitHandler = null;
|
|
250
|
+
}
|
|
251
|
+
if (sigintHandler) {
|
|
252
|
+
process.off('SIGINT', sigintHandler);
|
|
253
|
+
sigintHandler = null;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
export function hideCursor() {
|
|
257
|
+
if (caps.animate && !cursorHidden) {
|
|
258
|
+
ensureCleanupHandlers();
|
|
259
|
+
out.write('\x1b[?25l');
|
|
260
|
+
cursorHidden = true;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
export function showCursor() {
|
|
264
|
+
if (cursorHidden) {
|
|
265
|
+
out.write('\x1b[?25h');
|
|
266
|
+
cursorHidden = false;
|
|
267
|
+
removeCleanupHandlers();
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
/** Clear the terminal (home + erase). No-op when stderr is not a TTY (pipes). */
|
|
271
|
+
export function clearScreen() {
|
|
272
|
+
if (out.isTTY)
|
|
273
|
+
out.write("\x1b[2J\x1b[H");
|
|
274
|
+
}
|
|
275
|
+
//# sourceMappingURL=term.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+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I,CAAC,OAAO,IAAI,CAAC,YAAY,EAAE,CAAC;QAClC,qBAAqB,EAAE,CAAC;QACxB,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QACvB,YAAY,GAAG,IAAI,CAAC;IACtB,CAAC;AACH,CAAC;AAED,MAAM,UAAU,UAAU;IACxB,IAAI,YAAY,EAAE,CAAC;QACjB,GAAG,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QACvB,YAAY,GAAG,KAAK,CAAC;QACrB,qBAAqB,EAAE,CAAC;IAC1B,CAAC;AACH,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,WAAW;IACzB,IAAI,GAAG,CAAC,KAAK;QAAE,GAAG,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;AAC5C,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { PermissionRoleMap } from "./role-permissions.js";
|
|
2
|
+
/** Input needed to infer the UC actor for one endpoint. */
|
|
3
|
+
export interface ActorInferenceInput {
|
|
4
|
+
securityExpr?: string | null;
|
|
5
|
+
endpoint: string;
|
|
6
|
+
controller: string;
|
|
7
|
+
}
|
|
8
|
+
/** Title-case a SCREAMING_SNAKE_CASE or snake_case role literal: STAFF_WAREHOUSE -> Staff Warehouse. */
|
|
9
|
+
export declare function humanizeRole(literal: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* Infer the UC actor(s) for an endpoint. Prefers the literal role(s) named in
|
|
12
|
+
* @PreAuthorize/@Secured/@RolesAllowed (the actual authorization source of truth)
|
|
13
|
+
* over guessing from the URL path. hasRole/hasAnyRole/@Secured/@RolesAllowed name
|
|
14
|
+
* role(s) directly and are humanized as-is — an "or" of several roles yields one
|
|
15
|
+
* actor per role, not a merged pseudo-actor. hasAuthority/hasAnyAuthority name a
|
|
16
|
+
* permission string; when `permissionRoleMap` (see role-permissions.ts) resolves it
|
|
17
|
+
* to the role(s) that explicitly list it, those are used. If no role explicitly
|
|
18
|
+
* lists it, the map's wildcard roles (EnumSet.allOf(...), e.g. Admin) are used
|
|
19
|
+
* instead — that permission is real, just implicitly granted. Only when neither
|
|
20
|
+
* resolves (no Role enum was found in the project at all) is the endpoint labeled
|
|
21
|
+
* "Restricted" rather than silently falling back to a public actor. Endpoints with
|
|
22
|
+
* no security annotation fall back to the URL/controller heuristic (actorFromPath).
|
|
23
|
+
* Always returns at least one actor name.
|
|
24
|
+
*/
|
|
25
|
+
export declare function inferActor(input: ActorInferenceInput, permissionRoleMap?: PermissionRoleMap): string[];
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
const ROLE_CALL = /has(?:Any)?Role\s*\(([^)]*)\)/gi;
|
|
2
|
+
const AUTHORITY_CALL = /has(?:Any)?Authority\s*\(([^)]*)\)/gi;
|
|
3
|
+
const STRING_LITERAL = /['"]([^'"]+)['"]/g;
|
|
4
|
+
/** Title-case a SCREAMING_SNAKE_CASE or snake_case role literal: STAFF_WAREHOUSE -> Staff Warehouse. */
|
|
5
|
+
export function humanizeRole(literal) {
|
|
6
|
+
return literal
|
|
7
|
+
.toLowerCase()
|
|
8
|
+
.split(/[_\s]+/)
|
|
9
|
+
.filter(Boolean)
|
|
10
|
+
.map((w) => w[0].toUpperCase() + w.slice(1))
|
|
11
|
+
.join(" ");
|
|
12
|
+
}
|
|
13
|
+
function literalsFromCalls(expr, pattern) {
|
|
14
|
+
const out = [];
|
|
15
|
+
pattern.lastIndex = 0;
|
|
16
|
+
let m;
|
|
17
|
+
while ((m = pattern.exec(expr))) {
|
|
18
|
+
let sm;
|
|
19
|
+
STRING_LITERAL.lastIndex = 0;
|
|
20
|
+
while ((sm = STRING_LITERAL.exec(m[1])))
|
|
21
|
+
out.push(sm[1]);
|
|
22
|
+
}
|
|
23
|
+
return out;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Fallback heuristic when no security annotation is present: URL path / controller name
|
|
27
|
+
* only. The generic bucket is labeled "Customer" rather than "User" — in a customer-facing
|
|
28
|
+
* app these are the same person, and splitting them into two actors was the original
|
|
29
|
+
* complaint this module exists to fix.
|
|
30
|
+
*/
|
|
31
|
+
function actorFromPath(endpoint, controller) {
|
|
32
|
+
const p = (endpoint.split(" ").pop() ?? "").toLowerCase();
|
|
33
|
+
const c = controller.toLowerCase();
|
|
34
|
+
if (/\/admin(\/|$)/.test(p) || /admin/.test(c))
|
|
35
|
+
return "Admin";
|
|
36
|
+
if (/\/(auth|login|register|signup|signin|otp|verify|forgot|reset|public|open)(\/|$)/.test(p) || /\bauth\b|public/.test(c))
|
|
37
|
+
return "Guest";
|
|
38
|
+
return "Customer";
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Infer the UC actor(s) for an endpoint. Prefers the literal role(s) named in
|
|
42
|
+
* @PreAuthorize/@Secured/@RolesAllowed (the actual authorization source of truth)
|
|
43
|
+
* over guessing from the URL path. hasRole/hasAnyRole/@Secured/@RolesAllowed name
|
|
44
|
+
* role(s) directly and are humanized as-is — an "or" of several roles yields one
|
|
45
|
+
* actor per role, not a merged pseudo-actor. hasAuthority/hasAnyAuthority name a
|
|
46
|
+
* permission string; when `permissionRoleMap` (see role-permissions.ts) resolves it
|
|
47
|
+
* to the role(s) that explicitly list it, those are used. If no role explicitly
|
|
48
|
+
* lists it, the map's wildcard roles (EnumSet.allOf(...), e.g. Admin) are used
|
|
49
|
+
* instead — that permission is real, just implicitly granted. Only when neither
|
|
50
|
+
* resolves (no Role enum was found in the project at all) is the endpoint labeled
|
|
51
|
+
* "Restricted" rather than silently falling back to a public actor. Endpoints with
|
|
52
|
+
* no security annotation fall back to the URL/controller heuristic (actorFromPath).
|
|
53
|
+
* Always returns at least one actor name.
|
|
54
|
+
*/
|
|
55
|
+
export function inferActor(input, permissionRoleMap) {
|
|
56
|
+
const expr = input.securityExpr?.trim();
|
|
57
|
+
if (expr) {
|
|
58
|
+
const roles = literalsFromCalls(expr, ROLE_CALL);
|
|
59
|
+
if (roles.length)
|
|
60
|
+
return [...new Set(roles.map(humanizeRole))];
|
|
61
|
+
const authorities = literalsFromCalls(expr, AUTHORITY_CALL);
|
|
62
|
+
if (authorities.length) {
|
|
63
|
+
const resolved = new Set();
|
|
64
|
+
for (const a of authorities)
|
|
65
|
+
for (const r of permissionRoleMap?.explicit.get(a) ?? [])
|
|
66
|
+
resolved.add(r);
|
|
67
|
+
if (!resolved.size)
|
|
68
|
+
for (const r of permissionRoleMap?.wildcardRoles ?? [])
|
|
69
|
+
resolved.add(r);
|
|
70
|
+
return resolved.size ? [...resolved].sort() : ["Restricted"];
|
|
71
|
+
}
|
|
72
|
+
// Plain @Secured/@RolesAllowed value (no function-call wrapper at all): its
|
|
73
|
+
// string literal(s) name role(s) directly, e.g. "ADMIN" or {"A","B"}. If the
|
|
74
|
+
// expression contains a call we don't recognize (isAuthenticated(), permitAll(),
|
|
75
|
+
// arbitrary SpEL), its literal is not a role name — fall through to the path
|
|
76
|
+
// heuristic instead of misreading it as one.
|
|
77
|
+
if (!expr.includes("(")) {
|
|
78
|
+
STRING_LITERAL.lastIndex = 0;
|
|
79
|
+
const literals = [];
|
|
80
|
+
let sm;
|
|
81
|
+
while ((sm = STRING_LITERAL.exec(expr)))
|
|
82
|
+
literals.push(sm[1]);
|
|
83
|
+
if (literals.length)
|
|
84
|
+
return [...new Set(literals.map(humanizeRole))];
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return [actorFromPath(input.endpoint, input.controller)];
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=actor-inference.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"actor-inference.js","sourceRoot":"","sources":["../../src/core/actor-inference.ts"],"names":[],"mappings":"AASA,MAAM,SAAS,GAAG,iCAAiC,CAAC;AACpD,MAAM,cAAc,GAAG,sCAAsC,CAAC;AAC9D,MAAM,cAAc,GAAG,mBAAmB,CAAC;AAE3C,wGAAwG;AACxG,MAAM,UAAU,YAAY,CAAC,OAAe;IAC1C,OAAO,OAAO;SACX,WAAW,EAAE;SACb,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MAAM,QAAQ,GAAa,EAAE,CAAC;YAC9B,IAAI,EAA0B,CAAC;YAC/B,OAAO,CAAC,EAAE,GAAG,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;YAC9D,IAAI,QAAQ,CAAC,MAAM;gBAAE,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;QACvE,CAAC;IACH,CAAC;IACD,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC;AAC3D,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Groups real scanned classes by Spring stereotype for the CLI's Diagram-step
|
|
3
|
+
* preview — pure, terminal-width-aware, and deliberately data-driven: every
|
|
4
|
+
* name shown comes from the scan, nothing is a fixed/sample list, and the
|
|
5
|
+
* same code path runs for any project regardless of its class names.
|
|
6
|
+
*/
|
|
7
|
+
/** Minimal shape this module needs — matches ExtractedClass's name/type fields. */
|
|
8
|
+
export interface ComponentClassInfo {
|
|
9
|
+
name: string;
|
|
10
|
+
type: string;
|
|
11
|
+
}
|
|
12
|
+
export interface ComponentGroup {
|
|
13
|
+
label: string;
|
|
14
|
+
/** Simple names, suffix stripped, in scan order — ALL of them, not a sample. */
|
|
15
|
+
names: string[];
|
|
16
|
+
}
|
|
17
|
+
/** Build one group per stereotype present in `classes`, empty groups omitted. */
|
|
18
|
+
export declare function buildComponentGroups(classes: ComponentClassInfo[]): ComponentGroup[];
|
|
19
|
+
/** Total real component count across all groups — must equal the Diagram step's "N components". */
|
|
20
|
+
export declare function totalComponentCount(groups: ComponentGroup[]): number;
|
|
21
|
+
export interface RenderGroupsOptions {
|
|
22
|
+
/** Terminal width to wrap against. */
|
|
23
|
+
width: number;
|
|
24
|
+
/** A group is truncated once its wrapped names would exceed this many lines. */
|
|
25
|
+
maxLinesPerGroup?: number;
|
|
26
|
+
/** Shown on the truncation line so the rest of the list is still reachable. */
|
|
27
|
+
overflowPath: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Render every group as "Label (n)" followed by its wrapped name lines.
|
|
31
|
+
* A group only gets truncated once it would exceed maxLinesPerGroup lines —
|
|
32
|
+
* never earlier — at which point it shows the first lines, "+N nữa", and
|
|
33
|
+
* where to find the rest.
|
|
34
|
+
*/
|
|
35
|
+
export declare function renderComponentGroups(groups: ComponentGroup[], opts: RenderGroupsOptions): string[];
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Groups real scanned classes by Spring stereotype for the CLI's Diagram-step
|
|
3
|
+
* preview — pure, terminal-width-aware, and deliberately data-driven: every
|
|
4
|
+
* name shown comes from the scan, nothing is a fixed/sample list, and the
|
|
5
|
+
* same code path runs for any project regardless of its class names.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* The 5 domain stereotypes the parser can assign (excludes the generic
|
|
9
|
+
* "class" catch-all — same DOMAIN_STEREOTYPES set used for class-count F1 in
|
|
10
|
+
* generate_report.ts). A group is only shown when the scan actually found at
|
|
11
|
+
* least one class of that stereotype.
|
|
12
|
+
*/
|
|
13
|
+
const GROUP_SPECS = [
|
|
14
|
+
{ stereotype: "controller", label: "Controllers", suffix: "Controller" },
|
|
15
|
+
{ stereotype: "service", label: "Services", suffix: "Service" },
|
|
16
|
+
{ stereotype: "repository", label: "Repositories", suffix: "Repository" },
|
|
17
|
+
{ stereotype: "entity", label: "Entities", suffix: "Entity" },
|
|
18
|
+
{ stereotype: "component", label: "Components", suffix: "Component" },
|
|
19
|
+
];
|
|
20
|
+
/** Strip a trailing suffix, unless the name IS just the suffix word itself. */
|
|
21
|
+
function stripSuffix(name, suffix) {
|
|
22
|
+
if (name.length > suffix.length && name.endsWith(suffix)) {
|
|
23
|
+
return name.slice(0, name.length - suffix.length);
|
|
24
|
+
}
|
|
25
|
+
return name;
|
|
26
|
+
}
|
|
27
|
+
/** Build one group per stereotype present in `classes`, empty groups omitted. */
|
|
28
|
+
export function buildComponentGroups(classes) {
|
|
29
|
+
const groups = [];
|
|
30
|
+
for (const spec of GROUP_SPECS) {
|
|
31
|
+
const names = classes
|
|
32
|
+
.filter((c) => c.type === spec.stereotype)
|
|
33
|
+
.map((c) => stripSuffix(c.name, spec.suffix));
|
|
34
|
+
if (names.length > 0)
|
|
35
|
+
groups.push({ label: spec.label, names });
|
|
36
|
+
}
|
|
37
|
+
return groups;
|
|
38
|
+
}
|
|
39
|
+
/** Total real component count across all groups — must equal the Diagram step's "N components". */
|
|
40
|
+
export function totalComponentCount(groups) {
|
|
41
|
+
return groups.reduce((sum, g) => sum + g.names.length, 0);
|
|
42
|
+
}
|
|
43
|
+
/** Greedily pack names into "name · name · name" lines no wider than `width`. */
|
|
44
|
+
function wrapNames(names, width, indent) {
|
|
45
|
+
const sep = " · ";
|
|
46
|
+
const out = [];
|
|
47
|
+
let cur = "";
|
|
48
|
+
let count = 0;
|
|
49
|
+
for (const name of names) {
|
|
50
|
+
const candidate = cur ? `${cur}${sep}${name}` : name;
|
|
51
|
+
if (cur && (indent + candidate).length > width) {
|
|
52
|
+
out.push({ line: indent + cur, count });
|
|
53
|
+
cur = name;
|
|
54
|
+
count = 1;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
cur = candidate;
|
|
58
|
+
count++;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (cur)
|
|
62
|
+
out.push({ line: indent + cur, count });
|
|
63
|
+
return out;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Render every group as "Label (n)" followed by its wrapped name lines.
|
|
67
|
+
* A group only gets truncated once it would exceed maxLinesPerGroup lines —
|
|
68
|
+
* never earlier — at which point it shows the first lines, "+N nữa", and
|
|
69
|
+
* where to find the rest.
|
|
70
|
+
*/
|
|
71
|
+
export function renderComponentGroups(groups, opts) {
|
|
72
|
+
const { width, overflowPath } = opts;
|
|
73
|
+
const maxLines = opts.maxLinesPerGroup ?? 3;
|
|
74
|
+
const indent = " ";
|
|
75
|
+
const out = [];
|
|
76
|
+
groups.forEach((group, i) => {
|
|
77
|
+
if (i > 0)
|
|
78
|
+
out.push("");
|
|
79
|
+
out.push(`${group.label} (${group.names.length})`);
|
|
80
|
+
const wrapped = wrapNames(group.names, width, indent);
|
|
81
|
+
if (wrapped.length <= maxLines) {
|
|
82
|
+
out.push(...wrapped.map((w) => w.line));
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const shown = wrapped.slice(0, maxLines);
|
|
86
|
+
const shownCount = shown.reduce((sum, w) => sum + w.count, 0);
|
|
87
|
+
const remaining = group.names.length - shownCount;
|
|
88
|
+
out.push(...shown.map((w) => w.line));
|
|
89
|
+
out.push(`${indent}+${remaining} nữa — xem ${overflowPath}`);
|
|
90
|
+
});
|
|
91
|
+
return out;
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=component-groups.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component-groups.js","sourceRoot":"","sources":["../../src/core/component-groups.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAoBH;;;;;GAKG;AACH,MAAM,WAAW,GAAgB;IAC/B,EAAE,UAAU,EAAE,YAAY,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,YAAY,EAAE;IACxE,EAAE,UAAU,EAAE,SAAS,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE;IAC/D,EAAE,UAAU,EAAE,YAAY,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,EAAE,YAAY,EAAE;IACzE,EAAE,UAAU,EAAE,QAAQ,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE;IAC7D,EAAE,UAAU,EAAE,WAAW,EAAE,KAAK,EAAE,YAA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AAG,KAAK,CAAC,KAAK,KAAK,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC;QAEnD,MAAM,OAAO,GAAG,SAAS,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;QACtD,IAAI,OAAO,CAAC,MAAM,IAAI,QAAQ,EAAE,CAAC;YAC/B,GAAG,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;YACxC,OAAO;QACT,CAAC;QAED,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;QACzC,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAC9D,MAAM,SAAS,GAAG,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,UAAU,CAAC;QAClD,GAAG,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;QACtC,GAAG,CAAC,IAAI,CAAC,GAAG,MAAM,IAAI,SAAS,cAAc,YAAY,EAAE,CAAC,CAAC;IAC/D,CAAC,CAAC,CAAC;IAEH,OAAO,GAAG,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Academic report style constants — báo cáo khoa học chuẩn (Vietnam).
|
|
3
|
+
* Source: docs/thesis-requirements-vi.md + academic report conventions.
|
|
4
|
+
*
|
|
5
|
+
* DXA units (twips) = point × 20. 1 cm ≈ 567 twips.
|
|
6
|
+
* Font size in half-points: pt × 2.
|
|
7
|
+
* Paragraph spacing in twentieths of a point (same scale as DXA).
|
|
8
|
+
*/
|
|
9
|
+
export declare const ACADEMIC_STYLES: {
|
|
10
|
+
/** Page margins in DXA (twips). top/bottom 2.5cm, left 3cm, right 2cm. */
|
|
11
|
+
readonly MARGIN: {
|
|
12
|
+
readonly top: 1417;
|
|
13
|
+
readonly bottom: 1417;
|
|
14
|
+
readonly left: 1701;
|
|
15
|
+
readonly right: 1134;
|
|
16
|
+
};
|
|
17
|
+
readonly FONT: "Times New Roman";
|
|
18
|
+
/**
|
|
19
|
+
* Font sizes in half-points (docx convention: value = pt × 2).
|
|
20
|
+
* Heading mapping in report.md: H1=cover, H2=CHƯƠNG, H3=section, H4=subsection.
|
|
21
|
+
*/
|
|
22
|
+
readonly SIZE: {
|
|
23
|
+
readonly COVER: 32;
|
|
24
|
+
readonly CHAPTER: 28;
|
|
25
|
+
readonly SECTION: 26;
|
|
26
|
+
readonly SUBSECTION: 26;
|
|
27
|
+
readonly BODY: 26;
|
|
28
|
+
readonly TABLE_CELL: 24;
|
|
29
|
+
readonly CAPTION: 24;
|
|
30
|
+
};
|
|
31
|
+
/** Line spacing: 1.5 lines = 1.5 × 240 = 360 docx line units. */
|
|
32
|
+
readonly SPACING: {
|
|
33
|
+
readonly LINE: 360;
|
|
34
|
+
readonly LINE_RULE: "auto";
|
|
35
|
+
/** Paragraph space after: 6pt = 6 × 20 = 120 (DXA units). */
|
|
36
|
+
readonly AFTER: 120;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Text area width in pixels at 96 DPI — for ImageRun sizing.
|
|
40
|
+
* A4 = 11906 DXA; left = 1701; right = 1134.
|
|
41
|
+
* Width = (11906 - 1701 - 1134) × (1/1440 inch) × 96 dpi ≈ 605 px.
|
|
42
|
+
*/
|
|
43
|
+
readonly TEXT_WIDTH_PX: 605;
|
|
44
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Academic report style constants — báo cáo khoa học chuẩn (Vietnam).
|
|
3
|
+
* Source: docs/thesis-requirements-vi.md + academic report conventions.
|
|
4
|
+
*
|
|
5
|
+
* DXA units (twips) = point × 20. 1 cm ≈ 567 twips.
|
|
6
|
+
* Font size in half-points: pt × 2.
|
|
7
|
+
* Paragraph spacing in twentieths of a point (same scale as DXA).
|
|
8
|
+
*/
|
|
9
|
+
export const ACADEMIC_STYLES = {
|
|
10
|
+
/** Page margins in DXA (twips). top/bottom 2.5cm, left 3cm, right 2cm. */
|
|
11
|
+
MARGIN: {
|
|
12
|
+
top: 1417, // 2.5 cm
|
|
13
|
+
bottom: 1417, // 2.5 cm
|
|
14
|
+
left: 1701, // 3.0 cm
|
|
15
|
+
right: 1134, // 2.0 cm
|
|
16
|
+
},
|
|
17
|
+
FONT: "Times New Roman",
|
|
18
|
+
/**
|
|
19
|
+
* Font sizes in half-points (docx convention: value = pt × 2).
|
|
20
|
+
* Heading mapping in report.md: H1=cover, H2=CHƯƠNG, H3=section, H4=subsection.
|
|
21
|
+
*/
|
|
22
|
+
SIZE: {
|
|
23
|
+
COVER: 32, // 16pt — cover page titles (H1)
|
|
24
|
+
CHAPTER: 28, // 14pt — chapter headings (H2 "CHƯƠNG X")
|
|
25
|
+
SECTION: 26, // 13pt — section headings (H3 "1.x")
|
|
26
|
+
SUBSECTION: 26, // 13pt — subsection headings (H4 "1.x.x") — was 24 (12pt)
|
|
27
|
+
BODY: 26, // 13pt — body text
|
|
28
|
+
TABLE_CELL: 24, // 12pt — table cells (density)
|
|
29
|
+
CAPTION: 24, // 12pt — figure/table captions
|
|
30
|
+
},
|
|
31
|
+
/** Line spacing: 1.5 lines = 1.5 × 240 = 360 docx line units. */
|
|
32
|
+
SPACING: {
|
|
33
|
+
LINE: 360,
|
|
34
|
+
LINE_RULE: "auto",
|
|
35
|
+
/** Paragraph space after: 6pt = 6 × 20 = 120 (DXA units). */
|
|
36
|
+
AFTER: 120,
|
|
37
|
+
},
|
|
38
|
+
/**
|
|
39
|
+
* Text area width in pixels at 96 DPI — for ImageRun sizing.
|
|
40
|
+
* A4 = 11906 DXA; left = 1701; right = 1134.
|
|
41
|
+
* Width = (11906 - 1701 - 1134) × (1/1440 inch) × 96 dpi ≈ 605 px.
|
|
42
|
+
*/
|
|
43
|
+
TEXT_WIDTH_PX: 605,
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=docx-styles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"docx-styles.js","sourceRoot":"","sources":["../../src/core/docx-styles.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,0EAA0E;IAC1E,MAAM,EAAE;QACN,GAAG,EAAE,IAAI,EAAM,SAAS;QACxB,MAAM,EAAE,IAAI,EAAG,SAAS;QACxB,IAAI,EAAE,IAAI,EAAK,SAAS;QACxB,KAAK,EAAE,IAAI,EAAI,SAAS;KACzB;IAED,IAAI,EAAE,iBAAiB;IAEvB;;;OAGG;IACH,IAAI,EAAE;QACJ,KAAK,EAAE,EAAE,EAAQ,gCAAgC;QACjD,OAAO,EAAE,EAAE,EAAM,0CAA0C;QAC3D,OAAO,EAAE,EAAE,EAAM,qCAAqC;QACtD,UAAU,EAAE,EAAE,EAAG,0DAA0D;QAC3E,IAAI,EAAE,EAAE,EAAS,mBAAmB;QACpC,UAAU,EAAE,EAAE,EAAG,+BAA+B;QAChD,OAAO,EAAE,EAAE,EAAM,+BAA+B;KACjD;IAED,iEAAiE;IACjE,OAAO,EAAE;QACP,IAAI,EAAE,GAAG;QACT,SAAS,EAAE,MAAe;QAC1B,6DAA6D;QAC7D,KAAK,EAAE,GAAG;KACX;IAED;;;;OAIG;IACH,aAAa,EAAE,GAAG;CACV,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ProjectInfo } from "../types/report.js";
|
|
2
|
+
/**
|
|
3
|
+
* Convert a Markdown string to a `.docx` file at `outputPath`.
|
|
4
|
+
* Supports headings (H1–H4), bullet lists, bold/italic runs, GFM tables,
|
|
5
|
+
* `<!-- PAGE_BREAK -->`, `<!-- TOC -->`, `<!-- FIGURE: path "desc" -->`,
|
|
6
|
+
* and `<!-- TABLE: "desc" -->` markers.
|
|
7
|
+
* Format: Times New Roman 13pt body / 14pt chapter, 1.5 line spacing,
|
|
8
|
+
* academic report margins (top/bottom 2.5cm, left 3cm, right 2cm),
|
|
9
|
+
* footer page number, TOC field. See src/core/docx-styles.ts for constants.
|
|
10
|
+
*/
|
|
11
|
+
export declare function renderMarkdownToDocx(markdown: string, outputPath: string, _projectInfo?: ProjectInfo): Promise<void>;
|