@clawplays/ospec-cli 0.1.1
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/.ospec/templates/hooks/post-merge +8 -0
- package/.ospec/templates/hooks/pre-commit +8 -0
- package/LICENSE +21 -0
- package/README.md +549 -0
- package/README.zh-CN.md +549 -0
- package/assets/for-ai/en-US/ai-guide.md +98 -0
- package/assets/for-ai/en-US/execution-protocol.md +64 -0
- package/assets/for-ai/zh-CN/ai-guide.md +102 -0
- package/assets/for-ai/zh-CN/execution-protocol.md +68 -0
- package/assets/git-hooks/post-merge +12 -0
- package/assets/git-hooks/pre-commit +12 -0
- package/assets/global-skills/claude/ospec-change/SKILL.md +116 -0
- package/assets/global-skills/codex/ospec-change/SKILL.md +117 -0
- package/assets/global-skills/codex/ospec-change/agents/openai.yaml +7 -0
- package/assets/global-skills/codex/ospec-change/skill.yaml +19 -0
- package/assets/project-conventions/en-US/development-guide.md +32 -0
- package/assets/project-conventions/en-US/naming-conventions.md +51 -0
- package/assets/project-conventions/en-US/skill-conventions.md +40 -0
- package/assets/project-conventions/en-US/workflow-conventions.md +70 -0
- package/assets/project-conventions/zh-CN/development-guide.md +32 -0
- package/assets/project-conventions/zh-CN/naming-conventions.md +51 -0
- package/assets/project-conventions/zh-CN/skill-conventions.md +40 -0
- package/assets/project-conventions/zh-CN/workflow-conventions.md +74 -0
- package/dist/adapters/codex-stitch-adapter.js +420 -0
- package/dist/adapters/gemini-stitch-adapter.js +408 -0
- package/dist/adapters/playwright-checkpoint-adapter.js +2260 -0
- package/dist/advanced/BatchOperations.d.ts +36 -0
- package/dist/advanced/BatchOperations.js +159 -0
- package/dist/advanced/CachingLayer.d.ts +66 -0
- package/dist/advanced/CachingLayer.js +136 -0
- package/dist/advanced/FeatureUpdater.d.ts +46 -0
- package/dist/advanced/FeatureUpdater.js +151 -0
- package/dist/advanced/PerformanceMonitor.d.ts +52 -0
- package/dist/advanced/PerformanceMonitor.js +129 -0
- package/dist/advanced/StatePersistence.d.ts +61 -0
- package/dist/advanced/StatePersistence.js +168 -0
- package/dist/advanced/index.d.ts +14 -0
- package/dist/advanced/index.js +22 -0
- package/dist/cli/commands/config.d.ts +5 -0
- package/dist/cli/commands/config.js +6 -0
- package/dist/cli/commands/feature.d.ts +5 -0
- package/dist/cli/commands/feature.js +6 -0
- package/dist/cli/commands/index.d.ts +5 -0
- package/dist/cli/commands/index.js +6 -0
- package/dist/cli/commands/project.d.ts +5 -0
- package/dist/cli/commands/project.js +6 -0
- package/dist/cli/commands/validate.d.ts +5 -0
- package/dist/cli/commands/validate.js +6 -0
- package/dist/cli/index.d.ts +5 -0
- package/dist/cli/index.js +6 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.js +1007 -0
- package/dist/commands/ArchiveCommand.d.ts +14 -0
- package/dist/commands/ArchiveCommand.js +241 -0
- package/dist/commands/BaseCommand.d.ts +33 -0
- package/dist/commands/BaseCommand.js +46 -0
- package/dist/commands/BatchCommand.d.ts +5 -0
- package/dist/commands/BatchCommand.js +42 -0
- package/dist/commands/ChangesCommand.d.ts +3 -0
- package/dist/commands/ChangesCommand.js +71 -0
- package/dist/commands/DocsCommand.d.ts +5 -0
- package/dist/commands/DocsCommand.js +118 -0
- package/dist/commands/FinalizeCommand.d.ts +3 -0
- package/dist/commands/FinalizeCommand.js +24 -0
- package/dist/commands/IndexCommand.d.ts +5 -0
- package/dist/commands/IndexCommand.js +57 -0
- package/dist/commands/InitCommand.d.ts +5 -0
- package/dist/commands/InitCommand.js +65 -0
- package/dist/commands/NewCommand.d.ts +11 -0
- package/dist/commands/NewCommand.js +262 -0
- package/dist/commands/PluginsCommand.d.ts +58 -0
- package/dist/commands/PluginsCommand.js +2491 -0
- package/dist/commands/ProgressCommand.d.ts +5 -0
- package/dist/commands/ProgressCommand.js +103 -0
- package/dist/commands/QueueCommand.d.ts +10 -0
- package/dist/commands/QueueCommand.js +147 -0
- package/dist/commands/RunCommand.d.ts +13 -0
- package/dist/commands/RunCommand.js +200 -0
- package/dist/commands/SkillCommand.d.ts +31 -0
- package/dist/commands/SkillCommand.js +1216 -0
- package/dist/commands/SkillsCommand.d.ts +5 -0
- package/dist/commands/SkillsCommand.js +68 -0
- package/dist/commands/StatusCommand.d.ts +6 -0
- package/dist/commands/StatusCommand.js +140 -0
- package/dist/commands/UpdateCommand.d.ts +8 -0
- package/dist/commands/UpdateCommand.js +251 -0
- package/dist/commands/VerifyCommand.d.ts +5 -0
- package/dist/commands/VerifyCommand.js +278 -0
- package/dist/commands/WorkflowCommand.d.ts +12 -0
- package/dist/commands/WorkflowCommand.js +150 -0
- package/dist/commands/index.d.ts +43 -0
- package/dist/commands/index.js +85 -0
- package/dist/core/constants.d.ts +41 -0
- package/dist/core/constants.js +73 -0
- package/dist/core/errors.d.ts +36 -0
- package/dist/core/errors.js +72 -0
- package/dist/core/index.d.ts +7 -0
- package/dist/core/index.js +23 -0
- package/dist/core/types.d.ts +369 -0
- package/dist/core/types.js +3 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +27 -0
- package/dist/presets/ProjectPresets.d.ts +41 -0
- package/dist/presets/ProjectPresets.js +190 -0
- package/dist/scaffolds/ProjectScaffoldPresets.d.ts +20 -0
- package/dist/scaffolds/ProjectScaffoldPresets.js +151 -0
- package/dist/services/ConfigManager.d.ts +14 -0
- package/dist/services/ConfigManager.js +386 -0
- package/dist/services/FeatureManager.d.ts +5 -0
- package/dist/services/FeatureManager.js +6 -0
- package/dist/services/FileService.d.ts +21 -0
- package/dist/services/FileService.js +152 -0
- package/dist/services/IndexBuilder.d.ts +12 -0
- package/dist/services/IndexBuilder.js +130 -0
- package/dist/services/Logger.d.ts +20 -0
- package/dist/services/Logger.js +48 -0
- package/dist/services/ProjectAssetRegistry.d.ts +12 -0
- package/dist/services/ProjectAssetRegistry.js +96 -0
- package/dist/services/ProjectAssetService.d.ts +49 -0
- package/dist/services/ProjectAssetService.js +223 -0
- package/dist/services/ProjectScaffoldCommandService.d.ts +73 -0
- package/dist/services/ProjectScaffoldCommandService.js +159 -0
- package/dist/services/ProjectScaffoldService.d.ts +44 -0
- package/dist/services/ProjectScaffoldService.js +507 -0
- package/dist/services/ProjectService.d.ts +209 -0
- package/dist/services/ProjectService.js +13239 -0
- package/dist/services/QueueService.d.ts +17 -0
- package/dist/services/QueueService.js +142 -0
- package/dist/services/RunService.d.ts +40 -0
- package/dist/services/RunService.js +420 -0
- package/dist/services/SkillParser.d.ts +30 -0
- package/dist/services/SkillParser.js +88 -0
- package/dist/services/StateManager.d.ts +16 -0
- package/dist/services/StateManager.js +127 -0
- package/dist/services/TemplateEngine.d.ts +43 -0
- package/dist/services/TemplateEngine.js +119 -0
- package/dist/services/TemplateGenerator.d.ts +40 -0
- package/dist/services/TemplateGenerator.js +273 -0
- package/dist/services/ValidationService.d.ts +19 -0
- package/dist/services/ValidationService.js +44 -0
- package/dist/services/Validator.d.ts +5 -0
- package/dist/services/Validator.js +6 -0
- package/dist/services/index.d.ts +52 -0
- package/dist/services/index.js +91 -0
- package/dist/services/templates/ExecutionTemplateBuilder.d.ts +12 -0
- package/dist/services/templates/ExecutionTemplateBuilder.js +300 -0
- package/dist/services/templates/ProjectTemplateBuilder.d.ts +38 -0
- package/dist/services/templates/ProjectTemplateBuilder.js +1897 -0
- package/dist/services/templates/TemplateBuilderBase.d.ts +19 -0
- package/dist/services/templates/TemplateBuilderBase.js +60 -0
- package/dist/services/templates/TemplateInputFactory.d.ts +16 -0
- package/dist/services/templates/TemplateInputFactory.js +298 -0
- package/dist/services/templates/templateTypes.d.ts +90 -0
- package/dist/services/templates/templateTypes.js +3 -0
- package/dist/tools/build-index.js +632 -0
- package/dist/utils/DateUtils.d.ts +18 -0
- package/dist/utils/DateUtils.js +40 -0
- package/dist/utils/PathUtils.d.ts +9 -0
- package/dist/utils/PathUtils.js +66 -0
- package/dist/utils/StringUtils.d.ts +26 -0
- package/dist/utils/StringUtils.js +47 -0
- package/dist/utils/helpers.d.ts +5 -0
- package/dist/utils/helpers.js +6 -0
- package/dist/utils/index.d.ts +7 -0
- package/dist/utils/index.js +23 -0
- package/dist/utils/logger.d.ts +5 -0
- package/dist/utils/logger.js +6 -0
- package/dist/utils/path.d.ts +5 -0
- package/dist/utils/path.js +6 -0
- package/dist/utils/subcommandHelp.d.ts +11 -0
- package/dist/utils/subcommandHelp.js +119 -0
- package/dist/workflow/ArchiveGate.d.ts +30 -0
- package/dist/workflow/ArchiveGate.js +93 -0
- package/dist/workflow/ConfigurableWorkflow.d.ts +89 -0
- package/dist/workflow/ConfigurableWorkflow.js +186 -0
- package/dist/workflow/HookSystem.d.ts +38 -0
- package/dist/workflow/HookSystem.js +66 -0
- package/dist/workflow/IndexRegenerator.d.ts +49 -0
- package/dist/workflow/IndexRegenerator.js +147 -0
- package/dist/workflow/PluginWorkflowComposer.d.ts +138 -0
- package/dist/workflow/PluginWorkflowComposer.js +239 -0
- package/dist/workflow/SkillUpdateEngine.d.ts +26 -0
- package/dist/workflow/SkillUpdateEngine.js +113 -0
- package/dist/workflow/VerificationSystem.d.ts +24 -0
- package/dist/workflow/VerificationSystem.js +116 -0
- package/dist/workflow/WorkflowEngine.d.ts +15 -0
- package/dist/workflow/WorkflowEngine.js +57 -0
- package/dist/workflow/index.d.ts +19 -0
- package/dist/workflow/index.js +32 -0
- package/package.json +78 -0
- package/scripts/postinstall.js +43 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* 性能监控系统
|
|
4
|
+
* 跟踪和优化系统性能
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.performanceMonitor = exports.PerformanceMonitor = void 0;
|
|
8
|
+
class PerformanceMonitor {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.metrics = new Map();
|
|
11
|
+
this.startTimes = new Map();
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* 开始计时
|
|
15
|
+
*/
|
|
16
|
+
start(label) {
|
|
17
|
+
this.startTimes.set(label, Date.now());
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* 结束计时并记录
|
|
21
|
+
*/
|
|
22
|
+
end(label, metadata) {
|
|
23
|
+
const startTime = this.startTimes.get(label);
|
|
24
|
+
if (!startTime) {
|
|
25
|
+
console.warn(`Performance timer '${label}' was not started`);
|
|
26
|
+
return 0;
|
|
27
|
+
}
|
|
28
|
+
const duration = Date.now() - startTime;
|
|
29
|
+
this.startTimes.delete(label);
|
|
30
|
+
const metric = {
|
|
31
|
+
name: label,
|
|
32
|
+
duration,
|
|
33
|
+
timestamp: new Date().toISOString(),
|
|
34
|
+
metadata,
|
|
35
|
+
};
|
|
36
|
+
if (!this.metrics.has(label)) {
|
|
37
|
+
this.metrics.set(label, []);
|
|
38
|
+
}
|
|
39
|
+
this.metrics.get(label).push(metric);
|
|
40
|
+
// 限制每个标签最多保存1000条记录
|
|
41
|
+
const metricList = this.metrics.get(label);
|
|
42
|
+
if (metricList.length > 1000) {
|
|
43
|
+
metricList.shift();
|
|
44
|
+
}
|
|
45
|
+
return duration;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* 获取统计信息
|
|
49
|
+
*/
|
|
50
|
+
getSummary(label) {
|
|
51
|
+
if (label) {
|
|
52
|
+
return this.calculateSummary(label);
|
|
53
|
+
}
|
|
54
|
+
const summary = {};
|
|
55
|
+
for (const key of this.metrics.keys()) {
|
|
56
|
+
summary[key] = this.calculateSummary(key);
|
|
57
|
+
}
|
|
58
|
+
return summary;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* 计算统计数据
|
|
62
|
+
*/
|
|
63
|
+
calculateSummary(label) {
|
|
64
|
+
const metricList = this.metrics.get(label) || [];
|
|
65
|
+
if (metricList.length === 0) {
|
|
66
|
+
return {
|
|
67
|
+
totalDuration: 0,
|
|
68
|
+
averageDuration: 0,
|
|
69
|
+
minDuration: 0,
|
|
70
|
+
maxDuration: 0,
|
|
71
|
+
count: 0,
|
|
72
|
+
operationsPerSecond: 0,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
const durations = metricList.map(m => m.duration);
|
|
76
|
+
const totalDuration = durations.reduce((a, b) => a + b, 0);
|
|
77
|
+
const averageDuration = totalDuration / durations.length;
|
|
78
|
+
const minDuration = Math.min(...durations);
|
|
79
|
+
const maxDuration = Math.max(...durations);
|
|
80
|
+
const operationsPerSecond = (durations.length / (totalDuration / 1000)) || 0;
|
|
81
|
+
return {
|
|
82
|
+
totalDuration,
|
|
83
|
+
averageDuration: Math.round(averageDuration * 100) / 100,
|
|
84
|
+
minDuration,
|
|
85
|
+
maxDuration,
|
|
86
|
+
count: durations.length,
|
|
87
|
+
operationsPerSecond: Math.round(operationsPerSecond * 100) / 100,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* 获取原始指标
|
|
92
|
+
*/
|
|
93
|
+
getMetrics(label) {
|
|
94
|
+
if (label) {
|
|
95
|
+
return this.metrics.get(label) || [];
|
|
96
|
+
}
|
|
97
|
+
return Object.fromEntries(this.metrics);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* 清空指标
|
|
101
|
+
*/
|
|
102
|
+
clear(label) {
|
|
103
|
+
if (label) {
|
|
104
|
+
this.metrics.delete(label);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
this.metrics.clear();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* 生成性能报告
|
|
112
|
+
*/
|
|
113
|
+
generateReport() {
|
|
114
|
+
const summary = this.getSummary();
|
|
115
|
+
const lines = ['Performance Report', '==================\n'];
|
|
116
|
+
for (const [label, stats] of Object.entries(summary)) {
|
|
117
|
+
lines.push(`${label}:`);
|
|
118
|
+
lines.push(` Average: ${stats.averageDuration.toFixed(2)}ms`);
|
|
119
|
+
lines.push(` Min/Max: ${stats.minDuration}ms / ${stats.maxDuration}ms`);
|
|
120
|
+
lines.push(` Count: ${stats.count}`);
|
|
121
|
+
lines.push(` Ops/sec: ${stats.operationsPerSecond}`);
|
|
122
|
+
lines.push('');
|
|
123
|
+
}
|
|
124
|
+
return lines.join('\n');
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
exports.PerformanceMonitor = PerformanceMonitor;
|
|
128
|
+
exports.performanceMonitor = new PerformanceMonitor();
|
|
129
|
+
//# sourceMappingURL=PerformanceMonitor.js.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 状态持久化系统
|
|
3
|
+
* 处理状态的保存、加载和版本控制
|
|
4
|
+
*/
|
|
5
|
+
import { FeatureState } from '../core/types';
|
|
6
|
+
export interface StateSnapshot {
|
|
7
|
+
timestamp: string;
|
|
8
|
+
version: string;
|
|
9
|
+
hash: string;
|
|
10
|
+
state: FeatureState;
|
|
11
|
+
}
|
|
12
|
+
export interface StateDiff {
|
|
13
|
+
added: string[];
|
|
14
|
+
removed: string[];
|
|
15
|
+
modified: Record<string, {
|
|
16
|
+
old: any;
|
|
17
|
+
new: any;
|
|
18
|
+
}>;
|
|
19
|
+
}
|
|
20
|
+
export declare class StatePersistence {
|
|
21
|
+
private stateCache;
|
|
22
|
+
private snapshots;
|
|
23
|
+
/**
|
|
24
|
+
* 保存状态快照
|
|
25
|
+
*/
|
|
26
|
+
saveSnapshot(featurePath: string, state: FeatureState): Promise<StateSnapshot>;
|
|
27
|
+
/**
|
|
28
|
+
* 加载状态
|
|
29
|
+
*/
|
|
30
|
+
loadState(featurePath: string): Promise<FeatureState | null>;
|
|
31
|
+
/**
|
|
32
|
+
* 比较两个状态
|
|
33
|
+
*/
|
|
34
|
+
compareStates(oldState: FeatureState, newState: FeatureState): StateDiff;
|
|
35
|
+
/**
|
|
36
|
+
* 生成状态哈希
|
|
37
|
+
*/
|
|
38
|
+
private generateHash;
|
|
39
|
+
/**
|
|
40
|
+
* 获取状态历史
|
|
41
|
+
*/
|
|
42
|
+
getStateHistory(): StateSnapshot[];
|
|
43
|
+
/**
|
|
44
|
+
* 恢复到之前的快照
|
|
45
|
+
*/
|
|
46
|
+
restoreSnapshot(index: number): Promise<FeatureState | null>;
|
|
47
|
+
/**
|
|
48
|
+
* 清空缓存
|
|
49
|
+
*/
|
|
50
|
+
clearCache(): void;
|
|
51
|
+
/**
|
|
52
|
+
* 获取缓存统计
|
|
53
|
+
*/
|
|
54
|
+
getCacheStats(): {
|
|
55
|
+
cachedItems: number;
|
|
56
|
+
snapshots: number;
|
|
57
|
+
memory: string;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
export declare const statePersistence: StatePersistence;
|
|
61
|
+
//# sourceMappingURL=StatePersistence.d.ts.map
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* 状态持久化系统
|
|
4
|
+
* 处理状态的保存、加载和版本控制
|
|
5
|
+
*/
|
|
6
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
+
if (k2 === undefined) k2 = k;
|
|
8
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
+
}
|
|
12
|
+
Object.defineProperty(o, k2, desc);
|
|
13
|
+
}) : (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
o[k2] = m[k];
|
|
16
|
+
}));
|
|
17
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
18
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
19
|
+
}) : function(o, v) {
|
|
20
|
+
o["default"] = v;
|
|
21
|
+
});
|
|
22
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
23
|
+
var ownKeys = function(o) {
|
|
24
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
25
|
+
var ar = [];
|
|
26
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
27
|
+
return ar;
|
|
28
|
+
};
|
|
29
|
+
return ownKeys(o);
|
|
30
|
+
};
|
|
31
|
+
return function (mod) {
|
|
32
|
+
if (mod && mod.__esModule) return mod;
|
|
33
|
+
var result = {};
|
|
34
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
35
|
+
__setModuleDefault(result, mod);
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
})();
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.statePersistence = exports.StatePersistence = void 0;
|
|
41
|
+
const path = __importStar(require("path"));
|
|
42
|
+
const services_1 = require("../services");
|
|
43
|
+
class StatePersistence {
|
|
44
|
+
constructor() {
|
|
45
|
+
this.stateCache = new Map();
|
|
46
|
+
this.snapshots = [];
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* 保存状态快照
|
|
50
|
+
*/
|
|
51
|
+
async saveSnapshot(featurePath, state) {
|
|
52
|
+
const hash = this.generateHash(state);
|
|
53
|
+
const snapshot = {
|
|
54
|
+
timestamp: new Date().toISOString(),
|
|
55
|
+
version: state.version,
|
|
56
|
+
hash,
|
|
57
|
+
state: JSON.parse(JSON.stringify(state)), // Deep copy
|
|
58
|
+
};
|
|
59
|
+
this.snapshots.push(snapshot);
|
|
60
|
+
// 限制保留最后100个快照
|
|
61
|
+
if (this.snapshots.length > 100) {
|
|
62
|
+
this.snapshots = this.snapshots.slice(-100);
|
|
63
|
+
}
|
|
64
|
+
return snapshot;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* 加载状态
|
|
68
|
+
*/
|
|
69
|
+
async loadState(featurePath) {
|
|
70
|
+
const cacheKey = featurePath;
|
|
71
|
+
// 检查缓存
|
|
72
|
+
if (this.stateCache.has(cacheKey)) {
|
|
73
|
+
return this.stateCache.get(cacheKey);
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
const stateFile = path.join(featurePath, 'state.json');
|
|
77
|
+
const state = await services_1.services.fileService.readJSON(stateFile);
|
|
78
|
+
// 缓存状态
|
|
79
|
+
this.stateCache.set(cacheKey, state);
|
|
80
|
+
return state;
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
services_1.services.logger.warn(`Failed to load state from ${featurePath}`);
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* 比较两个状态
|
|
89
|
+
*/
|
|
90
|
+
compareStates(oldState, newState) {
|
|
91
|
+
const diff = {
|
|
92
|
+
added: [],
|
|
93
|
+
removed: [],
|
|
94
|
+
modified: {},
|
|
95
|
+
};
|
|
96
|
+
// 比较基本属性
|
|
97
|
+
const keys = new Set([
|
|
98
|
+
...Object.keys(oldState),
|
|
99
|
+
...Object.keys(newState),
|
|
100
|
+
]);
|
|
101
|
+
for (const key of keys) {
|
|
102
|
+
if (!(key in oldState)) {
|
|
103
|
+
diff.added.push(key);
|
|
104
|
+
}
|
|
105
|
+
else if (!(key in newState)) {
|
|
106
|
+
diff.removed.push(key);
|
|
107
|
+
}
|
|
108
|
+
else if (JSON.stringify(oldState[key]) !==
|
|
109
|
+
JSON.stringify(newState[key])) {
|
|
110
|
+
diff.modified[key] = {
|
|
111
|
+
old: oldState[key],
|
|
112
|
+
new: newState[key],
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return diff;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* 生成状态哈希
|
|
120
|
+
*/
|
|
121
|
+
generateHash(state) {
|
|
122
|
+
const content = JSON.stringify(state);
|
|
123
|
+
let hash = 0;
|
|
124
|
+
for (let i = 0; i < content.length; i++) {
|
|
125
|
+
const char = content.charCodeAt(i);
|
|
126
|
+
hash = (hash << 5) - hash + char;
|
|
127
|
+
hash = hash & hash; // Convert to 32bit integer
|
|
128
|
+
}
|
|
129
|
+
return Math.abs(hash).toString(16);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* 获取状态历史
|
|
133
|
+
*/
|
|
134
|
+
getStateHistory() {
|
|
135
|
+
return this.snapshots;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* 恢复到之前的快照
|
|
139
|
+
*/
|
|
140
|
+
async restoreSnapshot(index) {
|
|
141
|
+
if (index < 0 || index >= this.snapshots.length) {
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
return this.snapshots[index].state;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* 清空缓存
|
|
148
|
+
*/
|
|
149
|
+
clearCache() {
|
|
150
|
+
this.stateCache.clear();
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* 获取缓存统计
|
|
154
|
+
*/
|
|
155
|
+
getCacheStats() {
|
|
156
|
+
const cachedItems = this.stateCache.size;
|
|
157
|
+
const snapshots = this.snapshots.length;
|
|
158
|
+
const memory = `${(JSON.stringify(this.snapshots).length / 1024).toFixed(2)}KB`;
|
|
159
|
+
return {
|
|
160
|
+
cachedItems,
|
|
161
|
+
snapshots,
|
|
162
|
+
memory,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
exports.StatePersistence = StatePersistence;
|
|
167
|
+
exports.statePersistence = new StatePersistence();
|
|
168
|
+
//# sourceMappingURL=StatePersistence.js.map
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 高级功能层导出
|
|
3
|
+
*/
|
|
4
|
+
export { FeatureUpdater, featureUpdater } from './FeatureUpdater';
|
|
5
|
+
export type { UpdateOptions, UpdateLog } from './FeatureUpdater';
|
|
6
|
+
export { StatePersistence, statePersistence } from './StatePersistence';
|
|
7
|
+
export type { StateSnapshot, StateDiff } from './StatePersistence';
|
|
8
|
+
export { BatchOperations, batchOperations } from './BatchOperations';
|
|
9
|
+
export type { BatchOperationResult, BatchQuery } from './BatchOperations';
|
|
10
|
+
export { PerformanceMonitor, performanceMonitor } from './PerformanceMonitor';
|
|
11
|
+
export type { PerformanceMetric, PerformanceSummary } from './PerformanceMonitor';
|
|
12
|
+
export { CachingLayer, cachingLayer } from './CachingLayer';
|
|
13
|
+
export type { CacheEntry } from './CachingLayer';
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* 高级功能层导出
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.cachingLayer = exports.CachingLayer = exports.performanceMonitor = exports.PerformanceMonitor = exports.batchOperations = exports.BatchOperations = exports.statePersistence = exports.StatePersistence = exports.featureUpdater = exports.FeatureUpdater = void 0;
|
|
7
|
+
var FeatureUpdater_1 = require("./FeatureUpdater");
|
|
8
|
+
Object.defineProperty(exports, "FeatureUpdater", { enumerable: true, get: function () { return FeatureUpdater_1.FeatureUpdater; } });
|
|
9
|
+
Object.defineProperty(exports, "featureUpdater", { enumerable: true, get: function () { return FeatureUpdater_1.featureUpdater; } });
|
|
10
|
+
var StatePersistence_1 = require("./StatePersistence");
|
|
11
|
+
Object.defineProperty(exports, "StatePersistence", { enumerable: true, get: function () { return StatePersistence_1.StatePersistence; } });
|
|
12
|
+
Object.defineProperty(exports, "statePersistence", { enumerable: true, get: function () { return StatePersistence_1.statePersistence; } });
|
|
13
|
+
var BatchOperations_1 = require("./BatchOperations");
|
|
14
|
+
Object.defineProperty(exports, "BatchOperations", { enumerable: true, get: function () { return BatchOperations_1.BatchOperations; } });
|
|
15
|
+
Object.defineProperty(exports, "batchOperations", { enumerable: true, get: function () { return BatchOperations_1.batchOperations; } });
|
|
16
|
+
var PerformanceMonitor_1 = require("./PerformanceMonitor");
|
|
17
|
+
Object.defineProperty(exports, "PerformanceMonitor", { enumerable: true, get: function () { return PerformanceMonitor_1.PerformanceMonitor; } });
|
|
18
|
+
Object.defineProperty(exports, "performanceMonitor", { enumerable: true, get: function () { return PerformanceMonitor_1.performanceMonitor; } });
|
|
19
|
+
var CachingLayer_1 = require("./CachingLayer");
|
|
20
|
+
Object.defineProperty(exports, "CachingLayer", { enumerable: true, get: function () { return CachingLayer_1.CachingLayer; } });
|
|
21
|
+
Object.defineProperty(exports, "cachingLayer", { enumerable: true, get: function () { return CachingLayer_1.cachingLayer; } });
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
package/dist/cli.d.ts
ADDED