@dommaker/harness 0.7.3 → 0.7.6
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 +239 -2
- package/dist/architecture/constraint-engine.d.ts +49 -0
- package/dist/architecture/constraint-engine.d.ts.map +1 -0
- package/dist/architecture/constraint-engine.js +207 -0
- package/dist/architecture/constraint-engine.js.map +1 -0
- package/dist/architecture/cross-project-checker.d.ts +34 -0
- package/dist/architecture/cross-project-checker.d.ts.map +1 -0
- package/dist/architecture/cross-project-checker.js +260 -0
- package/dist/architecture/cross-project-checker.js.map +1 -0
- package/dist/context/progressive-loader.d.ts +110 -0
- package/dist/context/progressive-loader.d.ts.map +1 -0
- package/dist/context/progressive-loader.js +183 -0
- package/dist/context/progressive-loader.js.map +1 -0
- package/dist/context/token-budget.d.ts +144 -0
- package/dist/context/token-budget.d.ts.map +1 -0
- package/dist/context/token-budget.js +264 -0
- package/dist/context/token-budget.js.map +1 -0
- package/dist/core/constraints/definitions.d.ts.map +1 -1
- package/dist/core/constraints/definitions.js +33 -0
- package/dist/core/constraints/definitions.js.map +1 -1
- package/dist/core/index.d.ts +2 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +4 -0
- package/dist/core/index.js.map +1 -1
- package/dist/failure/classifier.d.ts +63 -0
- package/dist/failure/classifier.d.ts.map +1 -0
- package/dist/failure/classifier.js +123 -0
- package/dist/failure/classifier.js.map +1 -0
- package/dist/failure/index.d.ts +10 -0
- package/dist/failure/index.d.ts.map +1 -0
- package/dist/failure/index.js +36 -0
- package/dist/failure/index.js.map +1 -0
- package/dist/failure/recorder.d.ts +78 -0
- package/dist/failure/recorder.d.ts.map +1 -0
- package/dist/failure/recorder.js +193 -0
- package/dist/failure/recorder.js.map +1 -0
- package/dist/failure/types.d.ts +89 -0
- package/dist/failure/types.d.ts.map +1 -0
- package/dist/failure/types.js +121 -0
- package/dist/failure/types.js.map +1 -0
- package/dist/gates/acceptance.d.ts +159 -0
- package/dist/gates/acceptance.d.ts.map +1 -0
- package/dist/gates/acceptance.js +368 -0
- package/dist/gates/acceptance.js.map +1 -0
- package/dist/gates/index.d.ts +5 -2
- package/dist/gates/index.d.ts.map +1 -1
- package/dist/gates/index.js +8 -1
- package/dist/gates/index.js.map +1 -1
- package/dist/gates/types.d.ts +33 -0
- package/dist/gates/types.d.ts.map +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -5
- package/dist/index.js.map +1 -1
- package/dist/monitoring/index.d.ts +6 -0
- package/dist/monitoring/index.d.ts.map +1 -1
- package/dist/monitoring/index.js +6 -0
- package/dist/monitoring/index.js.map +1 -1
- package/dist/monitoring/performance-analyzer.d.ts +104 -0
- package/dist/monitoring/performance-analyzer.d.ts.map +1 -0
- package/dist/monitoring/performance-analyzer.js +417 -0
- package/dist/monitoring/performance-analyzer.js.map +1 -0
- package/dist/monitoring/performance-collector.d.ts +111 -0
- package/dist/monitoring/performance-collector.d.ts.map +1 -0
- package/dist/monitoring/performance-collector.js +319 -0
- package/dist/monitoring/performance-collector.js.map +1 -0
- package/dist/monitoring/trace-analyzer.js +1 -1
- package/dist/monitoring/trace-analyzer.js.map +1 -1
- package/dist/monitoring/traces.js +1 -1
- package/dist/monitoring/traces.js.map +1 -1
- package/dist/presets/index.d.ts +0 -1
- package/dist/presets/index.d.ts.map +1 -1
- package/dist/presets/index.js +1 -6
- package/dist/presets/index.js.map +1 -1
- package/dist/spec/annotation-checker.d.ts +47 -0
- package/dist/spec/annotation-checker.d.ts.map +1 -0
- package/dist/spec/annotation-checker.js +299 -0
- package/dist/spec/annotation-checker.js.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +9 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/performance.d.ts +204 -0
- package/dist/types/performance.d.ts.map +1 -0
- package/dist/types/performance.js +12 -0
- package/dist/types/performance.js.map +1 -0
- package/package.json +3 -1
- package/dist/extensions/long-running/constraints.d.ts +0 -38
- package/dist/extensions/long-running/constraints.d.ts.map +0 -1
- package/dist/extensions/long-running/constraints.js +0 -153
- package/dist/extensions/long-running/constraints.js.map +0 -1
- package/dist/extensions/long-running/index.d.ts +0 -30
- package/dist/extensions/long-running/index.d.ts.map +0 -1
- package/dist/extensions/long-running/index.js +0 -50
- package/dist/extensions/long-running/index.js.map +0 -1
- package/dist/extensions/long-running/types.d.ts +0 -154
- package/dist/extensions/long-running/types.d.ts.map +0 -1
- package/dist/extensions/long-running/types.js +0 -9
- package/dist/extensions/long-running/types.js.map +0 -1
- package/dist/presets/long-running.d.ts +0 -33
- package/dist/presets/long-running.d.ts.map +0 -1
- package/dist/presets/long-running.js +0 -52
- package/dist/presets/long-running.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/gates/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IAGpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IAGrB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,cAAc,CAAC,EAAE,OAAO,CAAC;IAGzB,qBAAqB,CAAC,EAAE,qB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AAC;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,QAAQ,GAAG,WAAW,GAAG,MAAM,CAAC;IACtC,QAAQ,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -20,8 +20,13 @@ export * from './types';
|
|
|
20
20
|
export * from './core';
|
|
21
21
|
export * from './gates';
|
|
22
22
|
export * from './monitoring';
|
|
23
|
+
export * from './failure';
|
|
24
|
+
export * from './architecture/constraint-engine';
|
|
25
|
+
export * from './architecture/cross-project-checker';
|
|
26
|
+
export * from './spec/annotation-checker';
|
|
27
|
+
export * from './context/progressive-loader';
|
|
28
|
+
export * from './context/token-budget';
|
|
23
29
|
export * from './presets';
|
|
24
|
-
export * from './extensions/long-running';
|
|
25
30
|
import type { ConstraintContext, ConstraintCheckResult, ConstraintTrigger } from './types/constraint';
|
|
26
31
|
import type { IronLawContext, IronLawResult } from './types/constraint';
|
|
27
32
|
import type { EnforcementExecutor, EnforcementId, InterceptionResult } from './types/enforcement';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAKH,cAAc,SAAS,CAAC;AAKxB,cAAc,QAAQ,CAAC;AAKvB,cAAc,SAAS,CAAC;AAKxB,cAAc,cAAc,CAAC;AAK7B,cAAc,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAKH,cAAc,SAAS,CAAC;AAKxB,cAAc,QAAQ,CAAC;AAKvB,cAAc,SAAS,CAAC;AAKxB,cAAc,cAAc,CAAC;AAK7B,cAAc,WAAW,CAAC;AAK1B,cAAc,kCAAkC,CAAC;AACjD,cAAc,sCAAsC,CAAC;AAKrD,cAAc,2BAA2B,CAAC;AAK1C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,wBAAwB,CAAC;AAKvC,cAAc,WAAW,CAAC;AAO1B,OAAO,KAAK,EAAE,iBAAiB,EAAE,qBAAqB,EAAoB,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAExH,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExE,OAAO,KAAK,EAAE,mBAAmB,EAAyC,aAAa,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAEzI,eAAO,MAAM,WAAW,wCAAwB,CAAC;AAEjD,wBAAsB,kBAAkB,CACtC,OAAO,EAAE,iBAAiB,EAC1B,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,kBAAkB,CAAC,CAE7B;AAED,wBAAsB,cAAc,CAClC,OAAO,EAAE,iBAAiB,EAC1B,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,IAAI,CAAC,CAEf;AAED,wBAAgB,gBAAgB,CAC9B,aAAa,EAAE,aAAa,EAC5B,QAAQ,EAAE,mBAAmB,EAC7B,MAAM,CAAC,EAAE,MAAM,GACd,IAAI,CAEN;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,qBAAqB,CAAC,CAEhC;AAED;;GAEG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,IAAI,CAAC,CAEf;AAMD;;GAEG;AACH,wBAAsB,aAAa,CACjC,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,aAAa,EAAE,CAAC,CAG1B"}
|
package/dist/index.js
CHANGED
|
@@ -56,14 +56,27 @@ __exportStar(require("./gates"), exports);
|
|
|
56
56
|
// ========================================
|
|
57
57
|
__exportStar(require("./monitoring"), exports);
|
|
58
58
|
// ========================================
|
|
59
|
-
//
|
|
59
|
+
// 失败处理导出
|
|
60
60
|
// ========================================
|
|
61
|
-
__exportStar(require("./
|
|
61
|
+
__exportStar(require("./failure"), exports);
|
|
62
|
+
// ========================================
|
|
63
|
+
// 架构约束导出
|
|
64
|
+
// ========================================
|
|
65
|
+
__exportStar(require("./architecture/constraint-engine"), exports);
|
|
66
|
+
__exportStar(require("./architecture/cross-project-checker"), exports);
|
|
67
|
+
// ========================================
|
|
68
|
+
// Spec 检查导出
|
|
62
69
|
// ========================================
|
|
63
|
-
|
|
70
|
+
__exportStar(require("./spec/annotation-checker"), exports);
|
|
64
71
|
// ========================================
|
|
65
|
-
//
|
|
66
|
-
|
|
72
|
+
// 上下文加载导出 (HZ-002)
|
|
73
|
+
// ========================================
|
|
74
|
+
__exportStar(require("./context/progressive-loader"), exports);
|
|
75
|
+
__exportStar(require("./context/token-budget"), exports);
|
|
76
|
+
// ========================================
|
|
77
|
+
// 预设导出
|
|
78
|
+
// ========================================
|
|
79
|
+
__exportStar(require("./presets"), exports);
|
|
67
80
|
// ========================================
|
|
68
81
|
// 便捷 API
|
|
69
82
|
// ========================================
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;;;;;;;;;;;;;;;AA8DH,gDAKC;AAED,wCAKC;AAED,4CAMC;AAKD,4CAIC;AAKD,oDAIC;AASD,sCAKC;AAhHD,2CAA2C;AAC3C,OAAO;AACP,2CAA2C;AAC3C,0CAAwB;AAExB,2CAA2C;AAC3C,SAAS;AACT,2CAA2C;AAC3C,yCAAuB;AAEvB,2CAA2C;AAC3C,SAAS;AACT,2CAA2C;AAC3C,0CAAwB;AAExB,2CA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OAAuB;IAEvB,MAAM,MAAM,GAAG,MAAM,2BAAiB,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;IACjE,OAAO,CAAC,GAAG,MAAM,CAAC,QAAQ,EAAE,GAAG,MAAM,CAAC,UAAU,EAAE,GAAG,MAAM,CAAC,IAAI,CAAoB,CAAC;AACvF,CAAC"}
|
|
@@ -6,9 +6,15 @@
|
|
|
6
6
|
* - TraceAnalyzer:统计汇总,异常检测
|
|
7
7
|
* - ConstraintDoctor:Agent 诊断接口
|
|
8
8
|
* - ConstraintEvolver:约束提案流程
|
|
9
|
+
*
|
|
10
|
+
* Performance Trace 系统:
|
|
11
|
+
* - PerformanceCollector:性能日志收集,零 Token
|
|
12
|
+
* - PerformanceAnalyzer:统计汇总,异常检测
|
|
9
13
|
*/
|
|
10
14
|
export * from './traces';
|
|
11
15
|
export * from './trace-analyzer';
|
|
12
16
|
export * from './constraint-doctor';
|
|
13
17
|
export * from './constraint-evolver';
|
|
18
|
+
export * from './performance-collector';
|
|
19
|
+
export * from './performance-analyzer';
|
|
14
20
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/monitoring/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/monitoring/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,cAAc,UAAU,CAAC;AACzB,cAAc,kBAAkB,CAAC;AACjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AACxC,cAAc,wBAAwB,CAAC"}
|
package/dist/monitoring/index.js
CHANGED
|
@@ -7,6 +7,10 @@
|
|
|
7
7
|
* - TraceAnalyzer:统计汇总,异常检测
|
|
8
8
|
* - ConstraintDoctor:Agent 诊断接口
|
|
9
9
|
* - ConstraintEvolver:约束提案流程
|
|
10
|
+
*
|
|
11
|
+
* Performance Trace 系统:
|
|
12
|
+
* - PerformanceCollector:性能日志收集,零 Token
|
|
13
|
+
* - PerformanceAnalyzer:统计汇总,异常检测
|
|
10
14
|
*/
|
|
11
15
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
12
16
|
if (k2 === undefined) k2 = k;
|
|
@@ -27,4 +31,6 @@ __exportStar(require("./traces"), exports);
|
|
|
27
31
|
__exportStar(require("./trace-analyzer"), exports);
|
|
28
32
|
__exportStar(require("./constraint-doctor"), exports);
|
|
29
33
|
__exportStar(require("./constraint-evolver"), exports);
|
|
34
|
+
__exportStar(require("./performance-collector"), exports);
|
|
35
|
+
__exportStar(require("./performance-analyzer"), exports);
|
|
30
36
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/monitoring/index.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/monitoring/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;GAYG;;;;;;;;;;;;;;;;AAEH,2CAAyB;AACzB,mDAAiC;AACjC,sDAAoC;AACpC,uDAAqC;AACrC,0DAAwC;AACxC,yDAAuC"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Performance Analyzer
|
|
3
|
+
*
|
|
4
|
+
* 纯计算,零 Token 成本
|
|
5
|
+
*
|
|
6
|
+
* 功能:
|
|
7
|
+
* - 统计汇总(每小时自动执行)
|
|
8
|
+
* - 异常检测(每日检查)
|
|
9
|
+
* - 趋势分析(对比上一周期)
|
|
10
|
+
*
|
|
11
|
+
* 与 TraceAnalyzer 的区别:
|
|
12
|
+
* - TraceAnalyzer: 分析约束检查结果
|
|
13
|
+
* - PerformanceAnalyzer: 分析操作耗时
|
|
14
|
+
*/
|
|
15
|
+
import type { PerformanceTrace, PerformanceSummary, PerformanceAnomaly, PerformanceAnalyzerConfig } from '../types/performance';
|
|
16
|
+
import { PerformanceCollector } from './performance-collector';
|
|
17
|
+
/**
|
|
18
|
+
* Performance Analyzer
|
|
19
|
+
*
|
|
20
|
+
* 使用方式:
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const analyzer = new PerformanceAnalyzer(collector);
|
|
23
|
+
* const summaries = analyzer.summarize(traces);
|
|
24
|
+
* const anomalies = analyzer.detectAnomalies(summaries);
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare class PerformanceAnalyzer {
|
|
28
|
+
private config;
|
|
29
|
+
private collector;
|
|
30
|
+
constructor(collector: PerformanceCollector, config?: Partial<PerformanceAnalyzerConfig>);
|
|
31
|
+
/**
|
|
32
|
+
* 生成统计汇总
|
|
33
|
+
*
|
|
34
|
+
* 纯计算,零 Token 成本
|
|
35
|
+
*/
|
|
36
|
+
summarize(traces: PerformanceTrace[]): PerformanceSummary[];
|
|
37
|
+
/**
|
|
38
|
+
* 分析最近 N 小时的 traces
|
|
39
|
+
*/
|
|
40
|
+
analyzeRecent(hours: number): PerformanceSummary[];
|
|
41
|
+
/**
|
|
42
|
+
* 分析特定操作
|
|
43
|
+
*/
|
|
44
|
+
analyzeOperation(operation: string): PerformanceSummary[];
|
|
45
|
+
/**
|
|
46
|
+
* 检测异常
|
|
47
|
+
*
|
|
48
|
+
* 基于阈值检测异常模式
|
|
49
|
+
*/
|
|
50
|
+
detectAnomalies(summaries: PerformanceSummary[]): PerformanceAnomaly[];
|
|
51
|
+
/**
|
|
52
|
+
* 对比上一周期
|
|
53
|
+
*
|
|
54
|
+
* 计算各指标的环比变化
|
|
55
|
+
*/
|
|
56
|
+
compareWithPrevious(current: PerformanceSummary[], previous: PerformanceSummary[]): PerformanceSummary[];
|
|
57
|
+
/**
|
|
58
|
+
* 按操作类型分组
|
|
59
|
+
*/
|
|
60
|
+
private groupByOperation;
|
|
61
|
+
/**
|
|
62
|
+
* 计算趋势
|
|
63
|
+
*
|
|
64
|
+
* 对比前半段和后半段的平均耗时
|
|
65
|
+
*/
|
|
66
|
+
private calculateTrend;
|
|
67
|
+
/**
|
|
68
|
+
* 计算平均值
|
|
69
|
+
*/
|
|
70
|
+
private calcAverage;
|
|
71
|
+
/**
|
|
72
|
+
* 计算百分位数
|
|
73
|
+
*/
|
|
74
|
+
private calcPercentile;
|
|
75
|
+
/**
|
|
76
|
+
* 保存汇总结果
|
|
77
|
+
*/
|
|
78
|
+
saveSummary(summaries: PerformanceSummary[]): void;
|
|
79
|
+
/**
|
|
80
|
+
* 加载上次汇总结果
|
|
81
|
+
*/
|
|
82
|
+
loadSummary(): PerformanceSummary[] | null;
|
|
83
|
+
/**
|
|
84
|
+
* 运行每小时汇总
|
|
85
|
+
*
|
|
86
|
+
* 自动执行,零 Token 成本
|
|
87
|
+
*/
|
|
88
|
+
runHourlySummary(): PerformanceSummary[];
|
|
89
|
+
/**
|
|
90
|
+
* 运行每日异常检测
|
|
91
|
+
*
|
|
92
|
+
* 返回异常列表,用于触发优化
|
|
93
|
+
*/
|
|
94
|
+
runDailyAnomalyCheck(): PerformanceAnomaly[];
|
|
95
|
+
/**
|
|
96
|
+
* 生成报告(文本格式)
|
|
97
|
+
*/
|
|
98
|
+
generateReport(summaries: PerformanceSummary[], anomalies: PerformanceAnomaly[]): string;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* 创建分析器(使用全局收集器)
|
|
102
|
+
*/
|
|
103
|
+
export declare function createPerformanceAnalyzer(config?: Partial<PerformanceAnalyzerConfig>): PerformanceAnalyzer;
|
|
104
|
+
//# sourceMappingURL=performance-analyzer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"performance-analyzer.d.ts","sourceRoot":"","sources":["../../src/monitoring/performance-analyzer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,OAAO,KAAK,EACV,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,EAClB,yBAAy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AM,CAAC,EAAE,OAAO,CAAC,yBAAyB,CAAC,GAAG,mBAAmB,CAG1G"}
|
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Performance Analyzer
|
|
4
|
+
*
|
|
5
|
+
* 纯计算,零 Token 成本
|
|
6
|
+
*
|
|
7
|
+
* 功能:
|
|
8
|
+
* - 统计汇总(每小时自动执行)
|
|
9
|
+
* - 异常检测(每日检查)
|
|
10
|
+
* - 趋势分析(对比上一周期)
|
|
11
|
+
*
|
|
12
|
+
* 与 TraceAnalyzer 的区别:
|
|
13
|
+
* - TraceAnalyzer: 分析约束检查结果
|
|
14
|
+
* - PerformanceAnalyzer: 分析操作耗时
|
|
15
|
+
*/
|
|
16
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
19
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
20
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
21
|
+
}
|
|
22
|
+
Object.defineProperty(o, k2, desc);
|
|
23
|
+
}) : (function(o, m, k, k2) {
|
|
24
|
+
if (k2 === undefined) k2 = k;
|
|
25
|
+
o[k2] = m[k];
|
|
26
|
+
}));
|
|
27
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
28
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
29
|
+
}) : function(o, v) {
|
|
30
|
+
o["default"] = v;
|
|
31
|
+
});
|
|
32
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
33
|
+
var ownKeys = function(o) {
|
|
34
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
35
|
+
var ar = [];
|
|
36
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
37
|
+
return ar;
|
|
38
|
+
};
|
|
39
|
+
return ownKeys(o);
|
|
40
|
+
};
|
|
41
|
+
return function (mod) {
|
|
42
|
+
if (mod && mod.__esModule) return mod;
|
|
43
|
+
var result = {};
|
|
44
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
45
|
+
__setModuleDefault(result, mod);
|
|
46
|
+
return result;
|
|
47
|
+
};
|
|
48
|
+
})();
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
exports.PerformanceAnalyzer = void 0;
|
|
51
|
+
exports.createPerformanceAnalyzer = createPerformanceAnalyzer;
|
|
52
|
+
const fs = __importStar(require("fs"));
|
|
53
|
+
const path = __importStar(require("path"));
|
|
54
|
+
const performance_collector_1 = require("./performance-collector");
|
|
55
|
+
/**
|
|
56
|
+
* 默认配置
|
|
57
|
+
*/
|
|
58
|
+
const DEFAULT_CONFIG = {
|
|
59
|
+
summaryFile: '.harness/logs/performance-summary.json',
|
|
60
|
+
periodMs: 3600 * 1000, // 1 小时
|
|
61
|
+
thresholds: {
|
|
62
|
+
avgDuration: 5000, // 平均耗时 > 5s 视为异常
|
|
63
|
+
exceededRate: 0.3, // 超阈值率 > 30% 视为异常
|
|
64
|
+
errorRate: 0.1, // 错误率 > 10% 视为异常
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Performance Analyzer
|
|
69
|
+
*
|
|
70
|
+
* 使用方式:
|
|
71
|
+
* ```typescript
|
|
72
|
+
* const analyzer = new PerformanceAnalyzer(collector);
|
|
73
|
+
* const summaries = analyzer.summarize(traces);
|
|
74
|
+
* const anomalies = analyzer.detectAnomalies(summaries);
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
class PerformanceAnalyzer {
|
|
78
|
+
config;
|
|
79
|
+
collector;
|
|
80
|
+
constructor(collector, config) {
|
|
81
|
+
this.collector = collector;
|
|
82
|
+
this.config = { ...DEFAULT_CONFIG, ...config };
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* 生成统计汇总
|
|
86
|
+
*
|
|
87
|
+
* 纯计算,零 Token 成本
|
|
88
|
+
*/
|
|
89
|
+
summarize(traces) {
|
|
90
|
+
// 按操作类型分组
|
|
91
|
+
const grouped = this.groupByOperation(traces);
|
|
92
|
+
const summaries = [];
|
|
93
|
+
for (const [operation, group] of grouped) {
|
|
94
|
+
// 计算时间范围
|
|
95
|
+
const timestamps = group.map(t => t.timestamp);
|
|
96
|
+
const timeRange = {
|
|
97
|
+
start: Math.min(...timestamps),
|
|
98
|
+
end: Math.max(...timestamps),
|
|
99
|
+
};
|
|
100
|
+
// 计算核心统计
|
|
101
|
+
const totalCalls = group.length;
|
|
102
|
+
const okCount = group.filter(t => t.result === 'ok').length;
|
|
103
|
+
const exceededCount = group.filter(t => t.result === 'exceeded').length;
|
|
104
|
+
const errorCount = group.filter(t => t.result === 'error').length;
|
|
105
|
+
// 计算比率
|
|
106
|
+
const okRate = totalCalls > 0 ? okCount / totalCalls : 0;
|
|
107
|
+
const exceededRate = totalCalls > 0 ? exceededCount / totalCalls : 0;
|
|
108
|
+
const errorRate = totalCalls > 0 ? errorCount / totalCalls : 0;
|
|
109
|
+
// 计算耗时统计
|
|
110
|
+
const durations = group.map(t => t.duration);
|
|
111
|
+
const avgDuration = this.calcAverage(durations);
|
|
112
|
+
const maxDuration = Math.max(...durations);
|
|
113
|
+
const minDuration = Math.min(...durations);
|
|
114
|
+
const p95Duration = this.calcPercentile(durations, 95);
|
|
115
|
+
const p99Duration = this.calcPercentile(durations, 99);
|
|
116
|
+
// 计算趋势
|
|
117
|
+
const recentTrend = this.calculateTrend(group);
|
|
118
|
+
summaries.push({
|
|
119
|
+
operation,
|
|
120
|
+
timeRange,
|
|
121
|
+
totalCalls,
|
|
122
|
+
okCount,
|
|
123
|
+
exceededCount,
|
|
124
|
+
errorCount,
|
|
125
|
+
avgDuration,
|
|
126
|
+
maxDuration,
|
|
127
|
+
minDuration,
|
|
128
|
+
p95Duration,
|
|
129
|
+
p99Duration,
|
|
130
|
+
okRate,
|
|
131
|
+
exceededRate,
|
|
132
|
+
errorRate,
|
|
133
|
+
recentTrend,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
return summaries;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* 分析最近 N 小时的 traces
|
|
140
|
+
*/
|
|
141
|
+
analyzeRecent(hours) {
|
|
142
|
+
const traces = this.collector.readRecent(hours);
|
|
143
|
+
return this.summarize(traces);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* 分析特定操作
|
|
147
|
+
*/
|
|
148
|
+
analyzeOperation(operation) {
|
|
149
|
+
const traces = this.collector.readByOperation(operation);
|
|
150
|
+
return this.summarize(traces);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* 检测异常
|
|
154
|
+
*
|
|
155
|
+
* 基于阈值检测异常模式
|
|
156
|
+
*/
|
|
157
|
+
detectAnomalies(summaries) {
|
|
158
|
+
const anomalies = [];
|
|
159
|
+
const thresholds = this.config.thresholds;
|
|
160
|
+
for (const summary of summaries) {
|
|
161
|
+
// 检测高平均耗时
|
|
162
|
+
if (summary.avgDuration > thresholds.avgDuration) {
|
|
163
|
+
anomalies.push({
|
|
164
|
+
type: 'high_avg_duration',
|
|
165
|
+
operation: summary.operation,
|
|
166
|
+
message: `操作 ${summary.operation} 平均耗时 ${Math.round(summary.avgDuration)}ms,超过阈值 ${thresholds.avgDuration}ms`,
|
|
167
|
+
data: {
|
|
168
|
+
currentValue: summary.avgDuration,
|
|
169
|
+
threshold: thresholds.avgDuration,
|
|
170
|
+
},
|
|
171
|
+
detectedAt: Date.now(),
|
|
172
|
+
suggestedAction: 'optimize',
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
// 检测耗时趋势上升
|
|
176
|
+
if (summary.recentTrend === 'rising') {
|
|
177
|
+
anomalies.push({
|
|
178
|
+
type: 'rising_duration',
|
|
179
|
+
operation: summary.operation,
|
|
180
|
+
message: `操作 ${summary.operation} 耗时趋势上升`,
|
|
181
|
+
data: {
|
|
182
|
+
currentValue: summary.avgDuration,
|
|
183
|
+
threshold: 0,
|
|
184
|
+
trend: 'rising',
|
|
185
|
+
},
|
|
186
|
+
detectedAt: Date.now(),
|
|
187
|
+
suggestedAction: 'optimize',
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
// 检测高超阈值率
|
|
191
|
+
if (summary.exceededRate > thresholds.exceededRate) {
|
|
192
|
+
anomalies.push({
|
|
193
|
+
type: 'high_exceeded_rate',
|
|
194
|
+
operation: summary.operation,
|
|
195
|
+
message: `操作 ${summary.operation} 超阈值率 ${Math.round(summary.exceededRate * 100)}%,超过阈值 ${thresholds.exceededRate * 100}%`,
|
|
196
|
+
data: {
|
|
197
|
+
currentValue: summary.exceededRate,
|
|
198
|
+
threshold: thresholds.exceededRate,
|
|
199
|
+
},
|
|
200
|
+
detectedAt: Date.now(),
|
|
201
|
+
suggestedAction: 'adjust_threshold',
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
// 检测超阈值率上升
|
|
205
|
+
if (summary.exceededRate > 0.1 && summary.recentTrend === 'rising') {
|
|
206
|
+
anomalies.push({
|
|
207
|
+
type: 'rising_exceeded_rate',
|
|
208
|
+
operation: summary.operation,
|
|
209
|
+
message: `操作 ${summary.operation} 超阈值率 ${Math.round(summary.exceededRate * 100)}% 且趋势上升`,
|
|
210
|
+
data: {
|
|
211
|
+
currentValue: summary.exceededRate,
|
|
212
|
+
threshold: 0.1,
|
|
213
|
+
trend: 'rising',
|
|
214
|
+
},
|
|
215
|
+
detectedAt: Date.now(),
|
|
216
|
+
suggestedAction: 'optimize',
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
// 检测高错误率
|
|
220
|
+
if (summary.errorRate > thresholds.errorRate) {
|
|
221
|
+
anomalies.push({
|
|
222
|
+
type: 'high_error_rate',
|
|
223
|
+
operation: summary.operation,
|
|
224
|
+
message: `操作 ${summary.operation} 错误率 ${Math.round(summary.errorRate * 100)}%,超过阈值 ${thresholds.errorRate * 100}%`,
|
|
225
|
+
data: {
|
|
226
|
+
currentValue: summary.errorRate,
|
|
227
|
+
threshold: thresholds.errorRate,
|
|
228
|
+
},
|
|
229
|
+
detectedAt: Date.now(),
|
|
230
|
+
suggestedAction: 'notify_user',
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
return anomalies;
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* 对比上一周期
|
|
238
|
+
*
|
|
239
|
+
* 计算各指标的环比变化
|
|
240
|
+
*/
|
|
241
|
+
compareWithPrevious(current, previous) {
|
|
242
|
+
const previousMap = new Map(previous.map(s => [s.operation, s]));
|
|
243
|
+
return current.map(summary => {
|
|
244
|
+
const prev = previousMap.get(summary.operation);
|
|
245
|
+
if (prev) {
|
|
246
|
+
summary.changeFromLastPeriod = {
|
|
247
|
+
avgDurationDelta: summary.avgDuration - prev.avgDuration,
|
|
248
|
+
exceededRateDelta: summary.exceededRate - prev.exceededRate,
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
return summary;
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* 按操作类型分组
|
|
256
|
+
*/
|
|
257
|
+
groupByOperation(traces) {
|
|
258
|
+
const grouped = new Map();
|
|
259
|
+
for (const trace of traces) {
|
|
260
|
+
const existing = grouped.get(trace.operation) || [];
|
|
261
|
+
existing.push(trace);
|
|
262
|
+
grouped.set(trace.operation, existing);
|
|
263
|
+
}
|
|
264
|
+
return grouped;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* 计算趋势
|
|
268
|
+
*
|
|
269
|
+
* 对比前半段和后半段的平均耗时
|
|
270
|
+
*/
|
|
271
|
+
calculateTrend(traces) {
|
|
272
|
+
if (traces.length < 10) {
|
|
273
|
+
return 'stable';
|
|
274
|
+
}
|
|
275
|
+
// 按时间排序
|
|
276
|
+
const sorted = [...traces].sort((a, b) => a.timestamp - b.timestamp);
|
|
277
|
+
// 分成前后两半
|
|
278
|
+
const half = Math.floor(sorted.length / 2);
|
|
279
|
+
const firstHalf = sorted.slice(0, half);
|
|
280
|
+
const secondHalf = sorted.slice(half);
|
|
281
|
+
// 计算前半段和后半段的平均耗时
|
|
282
|
+
const firstAvg = this.calcAverage(firstHalf.map(t => t.duration));
|
|
283
|
+
const secondAvg = this.calcAverage(secondHalf.map(t => t.duration));
|
|
284
|
+
// 计算变化率
|
|
285
|
+
const delta = secondAvg - firstAvg;
|
|
286
|
+
const changeRate = firstAvg > 0 ? delta / firstAvg : 0;
|
|
287
|
+
// 判断趋势(变化 > 10% 才算显著)
|
|
288
|
+
if (changeRate > 0.1) {
|
|
289
|
+
return 'rising';
|
|
290
|
+
}
|
|
291
|
+
else if (changeRate < -0.1) {
|
|
292
|
+
return 'falling';
|
|
293
|
+
}
|
|
294
|
+
else {
|
|
295
|
+
return 'stable';
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* 计算平均值
|
|
300
|
+
*/
|
|
301
|
+
calcAverage(values) {
|
|
302
|
+
if (values.length === 0)
|
|
303
|
+
return 0;
|
|
304
|
+
return values.reduce((sum, v) => sum + v, 0) / values.length;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* 计算百分位数
|
|
308
|
+
*/
|
|
309
|
+
calcPercentile(values, percentile) {
|
|
310
|
+
if (values.length === 0)
|
|
311
|
+
return 0;
|
|
312
|
+
const sorted = [...values].sort((a, b) => a - b);
|
|
313
|
+
const index = Math.ceil((percentile / 100) * sorted.length) - 1;
|
|
314
|
+
return sorted[Math.max(0, index)];
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* 保存汇总结果
|
|
318
|
+
*/
|
|
319
|
+
saveSummary(summaries) {
|
|
320
|
+
const dir = path.dirname(this.config.summaryFile);
|
|
321
|
+
if (!fs.existsSync(dir)) {
|
|
322
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
323
|
+
}
|
|
324
|
+
fs.writeFileSync(this.config.summaryFile, JSON.stringify(summaries, null, 2), 'utf-8');
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* 加载上次汇总结果
|
|
328
|
+
*/
|
|
329
|
+
loadSummary() {
|
|
330
|
+
if (!fs.existsSync(this.config.summaryFile)) {
|
|
331
|
+
return null;
|
|
332
|
+
}
|
|
333
|
+
const content = fs.readFileSync(this.config.summaryFile, 'utf-8');
|
|
334
|
+
return JSON.parse(content);
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* 运行每小时汇总
|
|
338
|
+
*
|
|
339
|
+
* 自动执行,零 Token 成本
|
|
340
|
+
*/
|
|
341
|
+
runHourlySummary() {
|
|
342
|
+
// 分析最近 1 小时
|
|
343
|
+
const current = this.analyzeRecent(1);
|
|
344
|
+
// 加载上次汇总,对比趋势
|
|
345
|
+
const previous = this.loadSummary();
|
|
346
|
+
if (previous) {
|
|
347
|
+
this.compareWithPrevious(current, previous);
|
|
348
|
+
}
|
|
349
|
+
// 保存当前汇总
|
|
350
|
+
this.saveSummary(current);
|
|
351
|
+
return current;
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* 运行每日异常检测
|
|
355
|
+
*
|
|
356
|
+
* 返回异常列表,用于触发优化
|
|
357
|
+
*/
|
|
358
|
+
runDailyAnomalyCheck() {
|
|
359
|
+
// 分析最近 24 小时
|
|
360
|
+
const summaries = this.analyzeRecent(24);
|
|
361
|
+
// 检测异常
|
|
362
|
+
const anomalies = this.detectAnomalies(summaries);
|
|
363
|
+
return anomalies;
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* 生成报告(文本格式)
|
|
367
|
+
*/
|
|
368
|
+
generateReport(summaries, anomalies) {
|
|
369
|
+
const lines = [];
|
|
370
|
+
lines.push('# Performance Report');
|
|
371
|
+
lines.push(`Generated: ${new Date().toISOString()}`);
|
|
372
|
+
lines.push('');
|
|
373
|
+
// 汇总部分
|
|
374
|
+
lines.push('## Operation Summaries');
|
|
375
|
+
lines.push('');
|
|
376
|
+
for (const summary of summaries) {
|
|
377
|
+
const trendEmoji = {
|
|
378
|
+
rising: '📈',
|
|
379
|
+
falling: '📉',
|
|
380
|
+
stable: '➡️',
|
|
381
|
+
}[summary.recentTrend];
|
|
382
|
+
lines.push(`**${summary.operation}** ${trendEmoji}`);
|
|
383
|
+
lines.push(` - Calls: ${summary.totalCalls}`);
|
|
384
|
+
lines.push(` - Avg: ${Math.round(summary.avgDuration)}ms`);
|
|
385
|
+
lines.push(` - P95: ${Math.round(summary.p95Duration)}ms`);
|
|
386
|
+
lines.push(` - P99: ${Math.round(summary.p99Duration)}ms`);
|
|
387
|
+
lines.push(` - OK: ${Math.round(summary.okRate * 100)}%`);
|
|
388
|
+
lines.push(` - Exceeded: ${Math.round(summary.exceededRate * 100)}%`);
|
|
389
|
+
lines.push(` - Errors: ${Math.round(summary.errorRate * 100)}%`);
|
|
390
|
+
lines.push('');
|
|
391
|
+
}
|
|
392
|
+
// 异常部分
|
|
393
|
+
if (anomalies.length > 0) {
|
|
394
|
+
lines.push('## Anomalies Detected');
|
|
395
|
+
lines.push('');
|
|
396
|
+
for (const anomaly of anomalies) {
|
|
397
|
+
lines.push(`⚠️ **${anomaly.type}**: ${anomaly.operation}`);
|
|
398
|
+
lines.push(` - ${anomaly.message}`);
|
|
399
|
+
lines.push(` - Suggested: ${anomaly.suggestedAction}`);
|
|
400
|
+
lines.push('');
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
else {
|
|
404
|
+
lines.push('## No Anomalies Detected ✅');
|
|
405
|
+
}
|
|
406
|
+
return lines.join('\n');
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
exports.PerformanceAnalyzer = PerformanceAnalyzer;
|
|
410
|
+
/**
|
|
411
|
+
* 创建分析器(使用全局收集器)
|
|
412
|
+
*/
|
|
413
|
+
function createPerformanceAnalyzer(config) {
|
|
414
|
+
const collector = new performance_collector_1.PerformanceCollector();
|
|
415
|
+
return new PerformanceAnalyzer(collector, config);
|
|
416
|
+
}
|
|
417
|
+
//# sourceMappingURL=performance-analyzer.js.map
|