progmune-runtime 2.1.5 → 3.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 +108 -468
- package/dist/ablation-study.js +144 -0
- package/dist/ablation-study.test.js +18 -0
- package/dist/action-runtime.js +3 -1
- package/dist/active-learning.js +211 -0
- package/dist/analytics.js +139 -0
- package/dist/asset-factory.js +309 -0
- package/dist/asset-growth.js +244 -0
- package/dist/asset-promotion.js +382 -0
- package/dist/asset-quality.js +550 -0
- package/dist/audit/business-translator.js +285 -0
- package/dist/audit/cli.js +66 -0
- package/dist/audit/formatters/html.js +379 -0
- package/dist/audit/formatters/json.js +11 -0
- package/dist/audit/formatters/markdown.js +192 -0
- package/dist/audit/formatters/terminal.js +189 -0
- package/dist/audit/index.js +25 -0
- package/dist/audit/report-builder.js +318 -0
- package/dist/audit/types.js +8 -0
- package/dist/audit.js +3 -3
- package/dist/auto-benchmark-generator.js +137 -0
- package/dist/auto-benchmark-generator.test.js +45 -0
- package/dist/auto-protocol-synthesizer.js +362 -0
- package/dist/auto-protocol-synthesizer.test.js +82 -0
- package/dist/autonomous-patch.js +175 -0
- package/dist/autonomous-patch.test.js +128 -0
- package/dist/badge/badge-server.js +98 -0
- package/dist/behavior-miner.js +442 -0
- package/dist/belief-layer.js +475 -0
- package/dist/benchmark-count.js +5 -0
- package/dist/benchmark-generator.js +211 -0
- package/dist/benchmark-harness.js +201 -0
- package/dist/benchmark-pass-rate.js +7 -0
- package/dist/benchmark-report.js +8 -3
- package/dist/benchmark-save.js +14 -1
- package/dist/bootstrap-validation.js +197 -0
- package/dist/bootstrap-validation.test.js +51 -0
- package/dist/branch-ledger.js +1 -1
- package/dist/capability-gap.js +130 -0
- package/dist/certify-html.js +351 -0
- package/dist/certify.js +326 -0
- package/dist/check.js +4 -4
- package/dist/compliance-miner.js +447 -0
- package/dist/continuous-benchmark.js +194 -0
- package/dist/continuous-benchmark.test.js +116 -0
- package/dist/corpus-stats.js +173 -0
- package/dist/counterfactual-engine.js +288 -0
- package/dist/coverage-dashboard.js +109 -0
- package/dist/coverage-system.test.js +205 -0
- package/dist/cross-repo-precision.js +352 -0
- package/dist/cve-benchmark.js +180 -0
- package/dist/cve-benchmark.test.js +28 -0
- package/dist/cve-collector.js +73 -0
- package/dist/data-quality.js +141 -0
- package/dist/decision-engine.js +388 -0
- package/dist/derive-metadata.js +250 -0
- package/dist/difficulty-active.test.js +198 -0
- package/dist/difficulty-map.js +244 -0
- package/dist/discovery-analytics.js +125 -0
- package/dist/discovery-model.js +149 -0
- package/dist/discovery-optimize.test.js +199 -0
- package/dist/discovery-trace.js +276 -0
- package/dist/discovery-trace.test.js +97 -0
- package/dist/emitter.js +83 -1
- package/dist/enterprise-dashboard.js +405 -0
- package/dist/eval-hardening.js +297 -0
- package/dist/eval-hardening.test.js +85 -0
- package/dist/evaluation-campaign.js +359 -0
- package/dist/evaluation-campaign.test.js +181 -0
- package/dist/evidence-growth.js +143 -0
- package/dist/evidence-repository.js +209 -0
- package/dist/evidence-system.js +441 -0
- package/dist/execute.js +15 -7
- package/dist/experimental/software-physics.js +291 -0
- package/dist/experimental/state-inference.js +516 -0
- package/dist/experimental/unsupervised-physics.js +230 -0
- package/dist/extract-ir-python.js +54 -7
- package/dist/extract-ir.js +376 -12
- package/dist/failure-collector.js +2 -2
- package/dist/failure-corpus.js +322 -9
- package/dist/feedback.js +16 -5
- package/dist/feedback.test.js +49 -0
- package/dist/file-lock.js +1 -1
- package/dist/flywheel-batch.js +292 -0
- package/dist/frameworks/express-cli.js +237 -0
- package/dist/frameworks/express-detector.js +445 -0
- package/dist/frameworks/express-detector.test.js +206 -0
- package/dist/frameworks/index.js +30 -0
- package/dist/frameworks/nestjs-detector.js +302 -0
- package/dist/frameworks/trpc-detector.js +161 -0
- package/dist/frameworks/version-awareness.js +179 -0
- package/dist/function-synonyms.js +164 -0
- package/dist/function-synonyms.test.js +68 -0
- package/dist/generalization.test.js +352 -0
- package/dist/goal-annotator.js +113 -0
- package/dist/goal-planner.js +563 -0
- package/dist/gold-cve.js +164 -0
- package/dist/gold-cve.test.js +104 -0
- package/dist/gold-quality.js +206 -0
- package/dist/gold-tiers.js +241 -0
- package/dist/governance-dashboard.js +327 -0
- package/dist/graph-viz.js +240 -0
- package/dist/guided-frontier.js +195 -0
- package/dist/hierarchical-planner.js +148 -0
- package/dist/identifier-parser.js +260 -0
- package/dist/immune-metrics.js +93 -0
- package/dist/immune-receiver.js +158 -0
- package/dist/immune-reporter.js +1 -1
- package/dist/improvement-orchestrator.js +206 -0
- package/dist/inject-p0-vocabulary.js +300 -0
- package/dist/intent-parser.js +218 -0
- package/dist/invariant-algebra.js +476 -0
- package/dist/invariant-calculus.js +533 -0
- package/dist/ir-utils.js +70 -0
- package/dist/ir-utils.test.js +50 -0
- package/dist/knowledge-api.js +312 -0
- package/dist/knowledge-evolution.js +452 -0
- package/dist/knowledge-explorer.js +506 -0
- package/dist/knowledge-flywheel.js +274 -0
- package/dist/knowledge-governance.js +338 -0
- package/dist/knowledge-governance.test.js +150 -0
- package/dist/knowledge-graph.js +181 -0
- package/dist/knowledge-guided-synth.js +246 -0
- package/dist/knowledge-loop.test.js +77 -0
- package/dist/knowledge-object.js +316 -0
- package/dist/knowledge-package.js +98 -0
- package/dist/kpi-dashboard.js +561 -0
- package/dist/l3-cross-function.js +280 -0
- package/dist/learning-ranker.js +148 -0
- package/dist/learning-ranker.test.js +291 -0
- package/dist/ledger/accountability.js +322 -0
- package/dist/ledger/chain-builder.js +185 -0
- package/dist/ledger/cli.js +222 -0
- package/dist/ledger/index.js +13 -0
- package/dist/ledger/signatures.js +193 -0
- package/dist/ledger/types.js +9 -0
- package/dist/llm.js +74 -3
- package/dist/load-benchmarks.js +8 -3
- package/dist/logger.js +66 -0
- package/dist/logger.test.js +37 -0
- package/dist/logistic-reward.js +339 -0
- package/dist/logistic-reward.test.js +180 -0
- package/dist/macro-graph.js +193 -0
- package/dist/macro-repair.js +183 -0
- package/dist/mcp-server.mjs +1202 -483
- package/dist/memory-layer.js +42 -5
- package/dist/multi-repo-precision.js +422 -0
- package/dist/name-free-protocol.js +425 -0
- package/dist/name-free-protocol.test.js +170 -0
- package/dist/name-scrambling.js +138 -0
- package/dist/name-scrambling.test.js +16 -0
- package/dist/p3-observability.test.js +281 -0
- package/dist/p5-orchestrator.test.js +225 -0
- package/dist/pairwise-preference.js +294 -0
- package/dist/pairwise-preference.test.js +140 -0
- package/dist/planner-constraints.js +104 -0
- package/dist/planner-prompts.js +155 -0
- package/dist/planner-telemetry.js +415 -0
- package/dist/planner-trace.js +214 -0
- package/dist/planner.js +162 -167
- package/dist/plsb/artifact.js +116 -0
- package/dist/plsb/cli.js +71 -0
- package/dist/plsb/index.js +19 -0
- package/dist/plsb/leaderboard.js +249 -0
- package/dist/plsb/report-md.js +156 -0
- package/dist/plsb/schema.js +179 -0
- package/dist/plsb-benchmark.js +284 -0
- package/dist/plsb-benchmark.test.js +119 -0
- package/dist/policy/cli.js +134 -0
- package/dist/policy/engine.js +333 -0
- package/dist/policy/index.js +12 -0
- package/dist/policy/types.js +59 -0
- package/dist/policy-miner.js +505 -0
- package/dist/precision-analyze.js +229 -0
- package/dist/precision-benchmark.js +147 -0
- package/dist/precision-label-c.js +134 -0
- package/dist/precision-label.js +193 -0
- package/dist/precision-report-c.js +149 -0
- package/dist/precision-report.js +246 -0
- package/dist/progmune-status.js +108 -0
- package/dist/proof-engine.js +479 -0
- package/dist/proof-provenance.js +315 -0
- package/dist/protocol-coverage.js +294 -0
- package/dist/protocol-detector.js +1189 -0
- package/dist/protocol-embedding-expanded.js +297 -0
- package/dist/protocol-embedding-expanded.test.js +97 -0
- package/dist/protocol-embedding.js +195 -0
- package/dist/protocol-embedding.test.js +82 -0
- package/dist/protocol-extractor-v2.js +354 -0
- package/dist/protocol-extractor-v2.test.js +140 -0
- package/dist/protocol-extractor.js +310 -0
- package/dist/protocol-extractor.test.js +113 -0
- package/dist/protocol-foundation.js +322 -0
- package/dist/protocol-foundation.test.js +163 -0
- package/dist/protocol-frontier.js +243 -0
- package/dist/protocol-frontier.test.js +92 -0
- package/dist/protocol-gap-analyzer.js +228 -0
- package/dist/protocol-gap-analyzer.test.js +49 -0
- package/dist/protocol-invariants.js +276 -0
- package/dist/protocol-invariants.test.js +111 -0
- package/dist/protocol-knowledge.js +464 -0
- package/dist/protocol-miner.js +343 -0
- package/dist/protocol-mining.js +207 -0
- package/dist/protocol-mining.test.js +37 -0
- package/dist/protocol-registry.js +1 -1
- package/dist/protocol-security-benchmark.js +222 -0
- package/dist/protocol-vulnerability.js +257 -0
- package/dist/protocol-vulnerability.test.js +60 -0
- package/dist/python-benchmark.js +120 -0
- package/dist/python-emitter.js +163 -45
- package/dist/python-protocol-extractor.js +187 -0
- package/dist/python-protocol-extractor.test.js +116 -0
- package/dist/realworld-benchmark.js +646 -0
- package/dist/realworld-benchmark.test.js +36 -0
- package/dist/repair-arch.test.js +411 -0
- package/dist/repair-evolution.test.js +454 -0
- package/dist/repair-executor.js +719 -0
- package/dist/repair-proposal.js +4 -4
- package/dist/repair-ranker.js +141 -0
- package/dist/repair-strategies.js +419 -0
- package/dist/repair-taxonomy.js +234 -0
- package/dist/repair-types.js +12 -0
- package/dist/repo-evaluator.js +250 -0
- package/dist/repo-evaluator.test.js +128 -0
- package/dist/resource-abstraction.js +242 -0
- package/dist/resource-detector.js +211 -0
- package/dist/result.test.js +43 -0
- package/dist/reward-system.js +411 -0
- package/dist/reward-system.test.js +175 -0
- package/dist/risk-model.js +215 -0
- package/dist/rule-miner.js +234 -7
- package/dist/rule-specificity.js +254 -0
- package/dist/runtime-types.js +27 -0
- package/dist/scaffold.js +208 -0
- package/dist/scale-collector.test.js +101 -0
- package/dist/scale-trajectory-collector.js +128 -0
- package/dist/sdk.js +250 -0
- package/dist/search-planner.js +4 -41
- package/dist/semantic-snapshot.js +1 -1
- package/dist/semantic-topology.js +121 -0
- package/dist/semantic-trace.js +310 -317
- package/dist/sequence-extractor.js +343 -0
- package/dist/skill-library.js +245 -0
- package/dist/skill-planner.test.js +189 -0
- package/dist/software-physics.js +291 -0
- package/dist/software-physics.test.js +81 -0
- package/dist/ssg-precision.js +478 -0
- package/dist/ssg-validator.js +71 -21
- package/dist/state-inference-doubleblind.test.js +160 -0
- package/dist/state-inference.js +516 -0
- package/dist/state-inference.test.js +115 -0
- package/dist/state-machine-fingerprint.js +345 -0
- package/dist/state-machine-fingerprint.test.js +120 -0
- package/dist/state-miner.js +386 -0
- package/dist/state-name-inference.js +213 -0
- package/dist/state-name-inference.test.js +69 -0
- package/dist/strategy-planner.js +326 -59
- package/dist/strategy-planner.test.js +135 -0
- package/dist/telemetry-analytics.test.js +402 -0
- package/dist/terminal-format.js +68 -0
- package/dist/terminal-format.test.js +83 -0
- package/dist/topology-factory.js +196 -0
- package/dist/topology-representation.js +242 -0
- package/dist/topology-representation.test.js +27 -0
- package/dist/trajectory-augmentation.js +254 -0
- package/dist/trajectory-augmentation.test.js +63 -0
- package/dist/trajectory-corpus.js +440 -0
- package/dist/trajectory-corpus.test.js +32 -0
- package/dist/trajectory-feedback.test.js +116 -0
- package/dist/transition-synthesizer.js +286 -0
- package/dist/transition-synthesizer.test.js +123 -0
- package/dist/trust/api-semantic-mapper.js +809 -0
- package/dist/trust/call-graph-propagator.js +225 -0
- package/dist/trust/cli.js +122 -0
- package/dist/trust/compliance-scorer.js +283 -0
- package/dist/trust/confidence-calculator.js +261 -0
- package/dist/trust/engine.js +1145 -0
- package/dist/trust/explainability.js +85 -0
- package/dist/trust/formatters/ci.js +42 -0
- package/dist/trust/formatters/json.js +11 -0
- package/dist/trust/formatters/terminal.js +152 -0
- package/dist/trust/index.js +39 -0
- package/dist/trust/phase1-verify.js +171 -0
- package/dist/trust/protocol-domain-validator.js +697 -0
- package/dist/trust/score-calculator.js +282 -0
- package/dist/trust/ssg-bridge.js +641 -0
- package/dist/trust/ssg-bridge.test.js +269 -0
- package/dist/trust/types.js +67 -0
- package/dist/trust/violation-trace.js +335 -0
- package/dist/trust-api.js +179 -0
- package/dist/trust-calibration.js +279 -0
- package/dist/unknown-protocol-discovery.js +339 -0
- package/dist/unknown-protocol-discovery.test.js +102 -0
- package/dist/unsupervised-physics.js +230 -0
- package/dist/unsupervised-physics.test.js +95 -0
- package/dist/utils.test.js +37 -0
- package/dist/validator.js +187 -10
- package/dist/verification-intelligence.js +475 -0
- package/dist/verify-api.js +432 -0
- package/dist/vi-impact-report.js +293 -0
- package/dist/wl-fingerprint.js +162 -0
- package/dist/wl-fingerprint.test.js +130 -0
- package/dist/zeroshot-strategy.js +139 -0
- package/docs/Progmune_/346/212/225/350/265/204/344/272/272/347/231/275/347/232/256/344/271/246_v2.0.html +576 -0
- package/docs/Progmune_/351/241/271/347/233/256/345/205/250/350/247/243.html +710 -0
- package/package.json +74 -7
- package/protocols.json +1956 -50
- package/.dockerignore +0 -14
- package/.mcp.json +0 -11
- package/.progmune_allowlist +0 -50
- package/.test_report/test_report.md +0 -87
- package/Dockerfile +0 -9
- package/FAQ.md +0 -167
- package/WHITEPAPER.md +0 -540
- package/demo-project/auth.ts +0 -55
- package/demo-project/tsconfig.json +0 -8
- package/dist/acl-breakdown.js +0 -13
- package/dist/all-sessions.js +0 -11
- package/dist/antibody-stats.js +0 -11
- package/dist/branch-tree-count.js +0 -14
- package/dist/common-fixpath.js +0 -12
- package/dist/constraint-types.js +0 -12
- package/dist/exec-metrics.js +0 -11
- package/dist/failure-report.js +0 -11
- package/dist/fast-path-hits.js +0 -13
- package/dist/fingerprint-list.js +0 -15
- package/dist/gen-history-log.js +0 -13
- package/dist/heatmap-data.js +0 -11
- package/dist/recent-session.js +0 -12
- package/dist/svl-distribution.js +0 -11
- package/dist/terminal-status.js +0 -11
- package/dist/token-savings.js +0 -11
- package/dist/total-repairs.js +0 -12
- package/dist/unresolved-count.js +0 -12
- package/dist/valid-fingerprints.js +0 -13
- package/dist/verify-ledgers.js +0 -11
- package/docs/whitepaper-style.css +0 -77
- package/docs/whitepaper-v2.1.md +0 -609
- package/docs/whitepaper-v2.2.md +0 -1064
- package/docs/whitepaper-v2.2.pdf +0 -0
- package/fly.toml +0 -31
- package/public/dashboard.html +0 -119
- package/server/hub.js +0 -116
- package/test/replay-golden/sess_1780063202050_mgeld.json +0 -9
- package/test/replay-golden/sess_1780064032560_gocld.json +0 -354
- package/test/replay-golden/sess_1780064413331_s2709.json +0 -606
- package/test/replay-golden/sess_1780064792710_y3avo.json +0 -614
- package/test/replay-golden.ts +0 -84
- package/test_benchmark.js +0 -165
- package/test_comprehensive.mjs +0 -638
- package/test_concurrency.js +0 -129
- package/test_ir_robustness.js +0 -85
- package/test_semantic_contracts.js +0 -269
- package/test_ssg_stress.js +0 -156
- package/test_svl3.js +0 -58
- package/tsconfig.json +0 -17
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Phase 10: Business Translation Layer
|
|
4
|
+
*
|
|
5
|
+
* Translates Progmune kernel governance data into CTO-readable
|
|
6
|
+
* trust report language — protocol security becomes business risk,
|
|
7
|
+
* PLSB categories become knowledge domains, session transitions
|
|
8
|
+
* become business protocol graphs.
|
|
9
|
+
*
|
|
10
|
+
* "Not a single AI-generated code path violated a business protocol edge."
|
|
11
|
+
*
|
|
12
|
+
* Project types are auto-detected from package.json dependencies,
|
|
13
|
+
* Prisma schema models, and framework config files.
|
|
14
|
+
* Falls back to generic domains for unknown project types.
|
|
15
|
+
*/
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.detectProjectType = detectProjectType;
|
|
18
|
+
exports.translateToBusinessRisks = translateToBusinessRisks;
|
|
19
|
+
exports.getKnowledgeCoverage = getKnowledgeCoverage;
|
|
20
|
+
exports.getProtocolGraph = getProtocolGraph;
|
|
21
|
+
exports.buildBusinessSummary = buildBusinessSummary;
|
|
22
|
+
// ── PLSB 类别 -> 业务风险映射 ──
|
|
23
|
+
const PLSB_TO_BUSINESS_RISK = {
|
|
24
|
+
"PLS-001": { category: "认证与授权", risk: "未认证访问:未登录用户可能访问受保护数据" },
|
|
25
|
+
"PLS-002": { category: "认证与授权", risk: "权限提升:低权限用户可能执行管理操作" },
|
|
26
|
+
"PLS-003": { category: "认证与授权", risk: "会话劫持:令牌可能被窃取和重放" },
|
|
27
|
+
"PLS-004": { category: "数据完整性", risk: "数据泄露:跨租户数据可能被非授权访问" },
|
|
28
|
+
"PLS-005": { category: "数据完整性", risk: "数据篡改:未授权用户可能修改他人数据" },
|
|
29
|
+
"PLS-006": { category: "数据完整性", risk: "数据丢失:删除操作无审计追踪" },
|
|
30
|
+
"PLS-007": { category: "业务协议合规", risk: "状态机违规:业务对象跳过必要状态" },
|
|
31
|
+
"PLS-008": { category: "业务协议合规", risk: "关联完整性:孤立数据导致业务逻辑断裂" },
|
|
32
|
+
"PLS-009": { category: "API 合约", risk: "API 合约漂移:接口行为与声明不一致" },
|
|
33
|
+
"PLS-010": { category: "API 合约", risk: "输入验证缺失:恶意输入可能绕过业务逻辑" },
|
|
34
|
+
"PLS-011": { category: "密码安全", risk: "密码明文存储或弱哈希" },
|
|
35
|
+
"PLS-012": { category: "密码安全", risk: "令牌管理不当:令牌生命周期不受控" },
|
|
36
|
+
"PLS-013": { category: "代码溯源", risk: "AI 生成代码无法追溯来源和修改历史" },
|
|
37
|
+
};
|
|
38
|
+
// ── Generic / Fallback Knowledge Domains ──
|
|
39
|
+
const GENERIC_KNOWLEDGE_DOMAINS = [
|
|
40
|
+
{
|
|
41
|
+
domain: "认证与授权",
|
|
42
|
+
coverage: "full",
|
|
43
|
+
protocols: ["PLS-001", "PLS-002", "PLS-003"],
|
|
44
|
+
entities: ["User", "Role", "Session"],
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
domain: "数据完整性",
|
|
48
|
+
coverage: "full",
|
|
49
|
+
protocols: ["PLS-004", "PLS-005", "PLS-006"],
|
|
50
|
+
entities: [],
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
domain: "API 合约",
|
|
54
|
+
coverage: "full",
|
|
55
|
+
protocols: ["PLS-009", "PLS-010"],
|
|
56
|
+
entities: [],
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
domain: "密码安全",
|
|
60
|
+
coverage: "full",
|
|
61
|
+
protocols: ["PLS-011", "PLS-012"],
|
|
62
|
+
entities: [],
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
domain: "代码溯源",
|
|
66
|
+
coverage: "full",
|
|
67
|
+
protocols: ["PLS-013"],
|
|
68
|
+
entities: [],
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
domain: "业务协议合规",
|
|
72
|
+
coverage: "partial",
|
|
73
|
+
protocols: ["PLS-007", "PLS-008"],
|
|
74
|
+
entities: [],
|
|
75
|
+
},
|
|
76
|
+
];
|
|
77
|
+
const GENERIC_PROTOCOL_GRAPH = [
|
|
78
|
+
{ from: "请求", to: "认证", label: "身份验证", verified: true },
|
|
79
|
+
{ from: "认证", to: "授权", label: "权限检查", verified: true },
|
|
80
|
+
{ from: "授权", to: "处理", label: "业务逻辑", verified: true },
|
|
81
|
+
{ from: "处理", to: "响应", label: "返回结果", verified: true },
|
|
82
|
+
{ from: "处理", to: "审计", label: "日志记录", verified: true },
|
|
83
|
+
];
|
|
84
|
+
// ── CRM Knowledge Domains ──
|
|
85
|
+
const CRM_KNOWLEDGE_DOMAINS = [
|
|
86
|
+
{
|
|
87
|
+
domain: "客户管理",
|
|
88
|
+
coverage: "full",
|
|
89
|
+
protocols: ["PLS-004", "PLS-008"],
|
|
90
|
+
entities: ["Contact", "Company"],
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
domain: "线索管理",
|
|
94
|
+
coverage: "full",
|
|
95
|
+
protocols: ["PLS-007", "PLS-008"],
|
|
96
|
+
entities: ["Lead"],
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
domain: "交易管道",
|
|
100
|
+
coverage: "full",
|
|
101
|
+
protocols: ["PLS-007", "PLS-005"],
|
|
102
|
+
entities: ["Deal", "DealStage"],
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
domain: "角色权限",
|
|
106
|
+
coverage: "full",
|
|
107
|
+
protocols: ["PLS-001", "PLS-002", "PLS-003"],
|
|
108
|
+
entities: ["User", "Role"],
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
domain: "活动追踪",
|
|
112
|
+
coverage: "full",
|
|
113
|
+
protocols: ["PLS-006", "PLS-008"],
|
|
114
|
+
entities: ["Activity", "AuditLog"],
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
domain: "AI 辅助决策",
|
|
118
|
+
coverage: "full",
|
|
119
|
+
protocols: ["PLS-009", "PLS-010"],
|
|
120
|
+
entities: ["AIAnalysis"],
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
domain: "合同管理",
|
|
124
|
+
coverage: "none",
|
|
125
|
+
protocols: [],
|
|
126
|
+
entities: [],
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
domain: "发票管理",
|
|
130
|
+
coverage: "none",
|
|
131
|
+
protocols: [],
|
|
132
|
+
entities: [],
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
domain: "邮件通信",
|
|
136
|
+
coverage: "partial",
|
|
137
|
+
protocols: ["PLS-009"],
|
|
138
|
+
entities: ["Email"],
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
domain: "任务管理",
|
|
142
|
+
coverage: "full",
|
|
143
|
+
protocols: ["PLS-007", "PLS-005"],
|
|
144
|
+
entities: ["Task"],
|
|
145
|
+
},
|
|
146
|
+
];
|
|
147
|
+
const CRM_PROTOCOL_GRAPH = [
|
|
148
|
+
{ from: "新线索", to: "已联系", label: "首次触达", verified: true },
|
|
149
|
+
{ from: "已联系", to: "已合格", label: "需求确认", verified: true },
|
|
150
|
+
{ from: "已合格", to: "提案中", label: "方案提交", verified: true },
|
|
151
|
+
{ from: "提案中", to: "赢单", label: "签约", verified: true, description: "生成关联交易" },
|
|
152
|
+
{ from: "提案中", to: "丢单", label: "关闭", verified: true, description: "记录丢单原因" },
|
|
153
|
+
{ from: "已合格", to: "丢单", label: "放弃", verified: true },
|
|
154
|
+
{ from: "交易创建", to: "阶段流转", label: "管道推进", verified: true },
|
|
155
|
+
{ from: "阶段流转", to: "赢单", label: "成交", verified: true },
|
|
156
|
+
{ from: "阶段流转", to: "丢单", label: "失败", verified: true },
|
|
157
|
+
{ from: "联系人", to: "线索", label: "关联", verified: true },
|
|
158
|
+
{ from: "联系人", to: "交易", label: "关联", verified: true },
|
|
159
|
+
{ from: "公司", to: "联系人", label: "所属", verified: true },
|
|
160
|
+
{ from: "公司", to: "线索", label: "关联", verified: true },
|
|
161
|
+
{ from: "公司", to: "交易", label: "关联", verified: true },
|
|
162
|
+
];
|
|
163
|
+
// ── Knowledge domains by project type (defined AFTER their const values) ──
|
|
164
|
+
const KNOWLEDGE_DOMAINS_BY_TYPE = {
|
|
165
|
+
crm: CRM_KNOWLEDGE_DOMAINS,
|
|
166
|
+
};
|
|
167
|
+
const PROTOCOL_GRAPHS_BY_TYPE = {
|
|
168
|
+
crm: CRM_PROTOCOL_GRAPH,
|
|
169
|
+
};
|
|
170
|
+
// ── Project type auto-detection ──
|
|
171
|
+
/**
|
|
172
|
+
* Detect project type from common project indicators.
|
|
173
|
+
* Checks package.json dependencies, Prisma schema models, framework configs.
|
|
174
|
+
*/
|
|
175
|
+
function detectProjectType(projectPath) {
|
|
176
|
+
try {
|
|
177
|
+
const fs = require("fs");
|
|
178
|
+
const path = require("path");
|
|
179
|
+
// Check package.json dependencies
|
|
180
|
+
const pkgPath = path.join(projectPath, "package.json");
|
|
181
|
+
if (fs.existsSync(pkgPath)) {
|
|
182
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
|
183
|
+
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
184
|
+
const depNames = Object.keys(deps).map((d) => d.toLowerCase());
|
|
185
|
+
// CRM indicators
|
|
186
|
+
if (depNames.some((d) => ["hubspot", "salesforce", "zoho", "crm"].some((kw) => d.includes(kw)))) {
|
|
187
|
+
return "crm";
|
|
188
|
+
}
|
|
189
|
+
// E-commerce indicators
|
|
190
|
+
if (depNames.some((d) => ["stripe", "shopify", "woocommerce", "commerce", "payment"].some((kw) => d.includes(kw)))) {
|
|
191
|
+
return "ecommerce";
|
|
192
|
+
}
|
|
193
|
+
// SaaS indicators
|
|
194
|
+
if (depNames.some((d) => ["@saas", "billing", "subscription", "multi-tenant"].some((kw) => d.includes(kw)))) {
|
|
195
|
+
return "saas";
|
|
196
|
+
}
|
|
197
|
+
// API/Backend indicators
|
|
198
|
+
if (depNames.some((d) => ["express", "fastify", "koa", "hono", "graphql", "trpc"].some((kw) => d.includes(kw)))) {
|
|
199
|
+
return "api";
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
// Check for Prisma schema (CRM, ecommerce, SaaS detection)
|
|
203
|
+
const prismaPath = path.join(projectPath, "prisma", "schema.prisma");
|
|
204
|
+
if (fs.existsSync(prismaPath)) {
|
|
205
|
+
const schema = fs.readFileSync(prismaPath, "utf-8");
|
|
206
|
+
const modelMatches = schema.match(/model\s+(\w+)/g) || [];
|
|
207
|
+
const models = modelMatches.map((m) => m.replace("model ", ""));
|
|
208
|
+
const crmModels = ["Contact", "Lead", "Deal", "Account", "Opportunity"];
|
|
209
|
+
const ecomModels = ["Product", "Order", "Cart", "Inventory", "Payment"];
|
|
210
|
+
const saasModels = ["Tenant", "Subscription", "Plan", "Workspace"];
|
|
211
|
+
if (crmModels.some((m) => models.includes(m)))
|
|
212
|
+
return "crm";
|
|
213
|
+
if (ecomModels.some((m) => models.includes(m)))
|
|
214
|
+
return "ecommerce";
|
|
215
|
+
if (saasModels.some((m) => models.includes(m)))
|
|
216
|
+
return "saas";
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
catch { /* best-effort */ }
|
|
220
|
+
return "generic";
|
|
221
|
+
}
|
|
222
|
+
// ── Translation Functions ──
|
|
223
|
+
function translateToBusinessRisks(plsbCovered, plsbUncovered, violationsByCategory) {
|
|
224
|
+
const categories = new Map();
|
|
225
|
+
// Initialize from all known mappings
|
|
226
|
+
for (const [plsId, mapping] of Object.entries(PLSB_TO_BUSINESS_RISK)) {
|
|
227
|
+
const cat = mapping.category;
|
|
228
|
+
if (!categories.has(cat)) {
|
|
229
|
+
categories.set(cat, {
|
|
230
|
+
category: cat,
|
|
231
|
+
description: "",
|
|
232
|
+
protocolsCovered: 0,
|
|
233
|
+
violationsPrevented: violationsByCategory[cat] || 0,
|
|
234
|
+
status: "exposed",
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
const entry = categories.get(cat);
|
|
238
|
+
if (plsbCovered.includes(plsId)) {
|
|
239
|
+
entry.protocolsCovered++;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
// Set status based on coverage
|
|
243
|
+
for (const entry of categories.values()) {
|
|
244
|
+
if (entry.protocolsCovered >= 2)
|
|
245
|
+
entry.status = "protected";
|
|
246
|
+
else if (entry.protocolsCovered === 1)
|
|
247
|
+
entry.status = "partial";
|
|
248
|
+
else
|
|
249
|
+
entry.status = "exposed";
|
|
250
|
+
entry.description = getCategoryDescription(entry.category);
|
|
251
|
+
}
|
|
252
|
+
return Array.from(categories.values());
|
|
253
|
+
}
|
|
254
|
+
function getCategoryDescription(cat) {
|
|
255
|
+
const descs = {
|
|
256
|
+
"认证与授权": "保护系统免受未授权访问,确保每个API调用都经过身份和权限验证",
|
|
257
|
+
"数据完整性": "防止数据泄露、篡改和未经审计的删除操作",
|
|
258
|
+
"业务协议合规": "确保AI生成的业务流程严格遵守定义的状态机和业务规则",
|
|
259
|
+
"API 合约": "保障API接口的行为与声明一致,防止合约漂移",
|
|
260
|
+
"密码安全": "确保密码和令牌的存储、传输、生命周期符合安全标准",
|
|
261
|
+
"代码溯源": "维护从AI生成到人工修改的完整治理链,确保代码可追溯",
|
|
262
|
+
};
|
|
263
|
+
return descs[cat] || "";
|
|
264
|
+
}
|
|
265
|
+
function getKnowledgeCoverage(projectType = "crm") {
|
|
266
|
+
const typeSpecific = KNOWLEDGE_DOMAINS_BY_TYPE[projectType];
|
|
267
|
+
if (typeSpecific)
|
|
268
|
+
return typeSpecific;
|
|
269
|
+
return GENERIC_KNOWLEDGE_DOMAINS;
|
|
270
|
+
}
|
|
271
|
+
function getProtocolGraph(projectType = "crm") {
|
|
272
|
+
const typeSpecific = PROTOCOL_GRAPHS_BY_TYPE[projectType];
|
|
273
|
+
if (typeSpecific)
|
|
274
|
+
return typeSpecific;
|
|
275
|
+
return GENERIC_PROTOCOL_GRAPH;
|
|
276
|
+
}
|
|
277
|
+
function buildBusinessSummary(risks, knowledge, violationsByCategory, projectType = "generic") {
|
|
278
|
+
const protocolGraph = getProtocolGraph(projectType);
|
|
279
|
+
return {
|
|
280
|
+
totalRisksMitigated: risks.filter(r => r.status === "protected").length,
|
|
281
|
+
knowledgeDomainsCovered: knowledge.filter(k => k.coverage === "full").length,
|
|
282
|
+
businessProtocolsIntact: protocolGraph.filter(e => e.verified).length,
|
|
283
|
+
preventedViolationsByCategory: violationsByCategory,
|
|
284
|
+
};
|
|
285
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Phase 9: Governance Report CLI
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* npx ts-node src/audit/cli.ts --all full report
|
|
7
|
+
* npx ts-node src/audit/cli.ts <sessionId> single session
|
|
8
|
+
* npx ts-node src/audit/cli.ts --json JSON output
|
|
9
|
+
* npx ts-node src/audit/cli.ts --markdown markdown output
|
|
10
|
+
* npx ts-node src/audit/cli.ts --help this message
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
const report_builder_1 = require("./report-builder");
|
|
14
|
+
const terminal_1 = require("./formatters/terminal");
|
|
15
|
+
const json_1 = require("./formatters/json");
|
|
16
|
+
const markdown_1 = require("./formatters/markdown");
|
|
17
|
+
const html_1 = require("./formatters/html");
|
|
18
|
+
const args = process.argv.slice(2);
|
|
19
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
20
|
+
console.log(`
|
|
21
|
+
Progmune Governance Report CLI
|
|
22
|
+
|
|
23
|
+
Usage:
|
|
24
|
+
npx ts-node src/audit/cli.ts [options] [sessionId]
|
|
25
|
+
|
|
26
|
+
Options:
|
|
27
|
+
--all Generate report for all sessions (default)
|
|
28
|
+
--json Output as JSON
|
|
29
|
+
--markdown Output as Markdown
|
|
30
|
+
--html Output as HTML (standalone, with CSS)
|
|
31
|
+
--terminal Output for terminal (default)
|
|
32
|
+
--fast Skip PLSB benchmark (faster)
|
|
33
|
+
--no-business Skip business translation (default: enabled)
|
|
34
|
+
--help, -h Show this help
|
|
35
|
+
|
|
36
|
+
Examples:
|
|
37
|
+
npx ts-node src/audit/cli.ts --all
|
|
38
|
+
npx ts-node src/audit/cli.ts sess_abc123
|
|
39
|
+
npx ts-node src/audit/cli.ts --json --fast
|
|
40
|
+
npx ts-node src/audit/cli.ts --markdown > governance-report.md
|
|
41
|
+
`);
|
|
42
|
+
process.exit(0);
|
|
43
|
+
}
|
|
44
|
+
const projectPath = process.env.PROGMUNE_PROJECT_DIR || process.cwd();
|
|
45
|
+
const useJson = args.includes("--json");
|
|
46
|
+
const useMarkdown = args.includes("--markdown");
|
|
47
|
+
const useHTML = args.includes("--html");
|
|
48
|
+
const fast = args.includes("--fast");
|
|
49
|
+
const useBusiness = !args.includes("--no-business"); // default ON, --no-business to disable
|
|
50
|
+
// sessionId: first non-flag argument
|
|
51
|
+
const sessionId = args.find((a) => !a.startsWith("--"));
|
|
52
|
+
const report = (0, report_builder_1.buildGovernanceReport)(projectPath, { fast, sessionId, business: useBusiness });
|
|
53
|
+
let output;
|
|
54
|
+
if (useJson) {
|
|
55
|
+
output = (0, json_1.formatAsJSON)(report);
|
|
56
|
+
}
|
|
57
|
+
else if (useMarkdown) {
|
|
58
|
+
output = (0, markdown_1.formatAsMarkdown)(report);
|
|
59
|
+
}
|
|
60
|
+
else if (useHTML) {
|
|
61
|
+
output = (0, html_1.formatAsHTML)(report);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
output = (0, terminal_1.formatAsTerminal)(report);
|
|
65
|
+
}
|
|
66
|
+
console.log(output);
|