@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.
Files changed (191) hide show
  1. package/.ospec/templates/hooks/post-merge +8 -0
  2. package/.ospec/templates/hooks/pre-commit +8 -0
  3. package/LICENSE +21 -0
  4. package/README.md +549 -0
  5. package/README.zh-CN.md +549 -0
  6. package/assets/for-ai/en-US/ai-guide.md +98 -0
  7. package/assets/for-ai/en-US/execution-protocol.md +64 -0
  8. package/assets/for-ai/zh-CN/ai-guide.md +102 -0
  9. package/assets/for-ai/zh-CN/execution-protocol.md +68 -0
  10. package/assets/git-hooks/post-merge +12 -0
  11. package/assets/git-hooks/pre-commit +12 -0
  12. package/assets/global-skills/claude/ospec-change/SKILL.md +116 -0
  13. package/assets/global-skills/codex/ospec-change/SKILL.md +117 -0
  14. package/assets/global-skills/codex/ospec-change/agents/openai.yaml +7 -0
  15. package/assets/global-skills/codex/ospec-change/skill.yaml +19 -0
  16. package/assets/project-conventions/en-US/development-guide.md +32 -0
  17. package/assets/project-conventions/en-US/naming-conventions.md +51 -0
  18. package/assets/project-conventions/en-US/skill-conventions.md +40 -0
  19. package/assets/project-conventions/en-US/workflow-conventions.md +70 -0
  20. package/assets/project-conventions/zh-CN/development-guide.md +32 -0
  21. package/assets/project-conventions/zh-CN/naming-conventions.md +51 -0
  22. package/assets/project-conventions/zh-CN/skill-conventions.md +40 -0
  23. package/assets/project-conventions/zh-CN/workflow-conventions.md +74 -0
  24. package/dist/adapters/codex-stitch-adapter.js +420 -0
  25. package/dist/adapters/gemini-stitch-adapter.js +408 -0
  26. package/dist/adapters/playwright-checkpoint-adapter.js +2260 -0
  27. package/dist/advanced/BatchOperations.d.ts +36 -0
  28. package/dist/advanced/BatchOperations.js +159 -0
  29. package/dist/advanced/CachingLayer.d.ts +66 -0
  30. package/dist/advanced/CachingLayer.js +136 -0
  31. package/dist/advanced/FeatureUpdater.d.ts +46 -0
  32. package/dist/advanced/FeatureUpdater.js +151 -0
  33. package/dist/advanced/PerformanceMonitor.d.ts +52 -0
  34. package/dist/advanced/PerformanceMonitor.js +129 -0
  35. package/dist/advanced/StatePersistence.d.ts +61 -0
  36. package/dist/advanced/StatePersistence.js +168 -0
  37. package/dist/advanced/index.d.ts +14 -0
  38. package/dist/advanced/index.js +22 -0
  39. package/dist/cli/commands/config.d.ts +5 -0
  40. package/dist/cli/commands/config.js +6 -0
  41. package/dist/cli/commands/feature.d.ts +5 -0
  42. package/dist/cli/commands/feature.js +6 -0
  43. package/dist/cli/commands/index.d.ts +5 -0
  44. package/dist/cli/commands/index.js +6 -0
  45. package/dist/cli/commands/project.d.ts +5 -0
  46. package/dist/cli/commands/project.js +6 -0
  47. package/dist/cli/commands/validate.d.ts +5 -0
  48. package/dist/cli/commands/validate.js +6 -0
  49. package/dist/cli/index.d.ts +5 -0
  50. package/dist/cli/index.js +6 -0
  51. package/dist/cli.d.ts +3 -0
  52. package/dist/cli.js +1007 -0
  53. package/dist/commands/ArchiveCommand.d.ts +14 -0
  54. package/dist/commands/ArchiveCommand.js +241 -0
  55. package/dist/commands/BaseCommand.d.ts +33 -0
  56. package/dist/commands/BaseCommand.js +46 -0
  57. package/dist/commands/BatchCommand.d.ts +5 -0
  58. package/dist/commands/BatchCommand.js +42 -0
  59. package/dist/commands/ChangesCommand.d.ts +3 -0
  60. package/dist/commands/ChangesCommand.js +71 -0
  61. package/dist/commands/DocsCommand.d.ts +5 -0
  62. package/dist/commands/DocsCommand.js +118 -0
  63. package/dist/commands/FinalizeCommand.d.ts +3 -0
  64. package/dist/commands/FinalizeCommand.js +24 -0
  65. package/dist/commands/IndexCommand.d.ts +5 -0
  66. package/dist/commands/IndexCommand.js +57 -0
  67. package/dist/commands/InitCommand.d.ts +5 -0
  68. package/dist/commands/InitCommand.js +65 -0
  69. package/dist/commands/NewCommand.d.ts +11 -0
  70. package/dist/commands/NewCommand.js +262 -0
  71. package/dist/commands/PluginsCommand.d.ts +58 -0
  72. package/dist/commands/PluginsCommand.js +2491 -0
  73. package/dist/commands/ProgressCommand.d.ts +5 -0
  74. package/dist/commands/ProgressCommand.js +103 -0
  75. package/dist/commands/QueueCommand.d.ts +10 -0
  76. package/dist/commands/QueueCommand.js +147 -0
  77. package/dist/commands/RunCommand.d.ts +13 -0
  78. package/dist/commands/RunCommand.js +200 -0
  79. package/dist/commands/SkillCommand.d.ts +31 -0
  80. package/dist/commands/SkillCommand.js +1216 -0
  81. package/dist/commands/SkillsCommand.d.ts +5 -0
  82. package/dist/commands/SkillsCommand.js +68 -0
  83. package/dist/commands/StatusCommand.d.ts +6 -0
  84. package/dist/commands/StatusCommand.js +140 -0
  85. package/dist/commands/UpdateCommand.d.ts +8 -0
  86. package/dist/commands/UpdateCommand.js +251 -0
  87. package/dist/commands/VerifyCommand.d.ts +5 -0
  88. package/dist/commands/VerifyCommand.js +278 -0
  89. package/dist/commands/WorkflowCommand.d.ts +12 -0
  90. package/dist/commands/WorkflowCommand.js +150 -0
  91. package/dist/commands/index.d.ts +43 -0
  92. package/dist/commands/index.js +85 -0
  93. package/dist/core/constants.d.ts +41 -0
  94. package/dist/core/constants.js +73 -0
  95. package/dist/core/errors.d.ts +36 -0
  96. package/dist/core/errors.js +72 -0
  97. package/dist/core/index.d.ts +7 -0
  98. package/dist/core/index.js +23 -0
  99. package/dist/core/types.d.ts +369 -0
  100. package/dist/core/types.js +3 -0
  101. package/dist/index.d.ts +11 -0
  102. package/dist/index.js +27 -0
  103. package/dist/presets/ProjectPresets.d.ts +41 -0
  104. package/dist/presets/ProjectPresets.js +190 -0
  105. package/dist/scaffolds/ProjectScaffoldPresets.d.ts +20 -0
  106. package/dist/scaffolds/ProjectScaffoldPresets.js +151 -0
  107. package/dist/services/ConfigManager.d.ts +14 -0
  108. package/dist/services/ConfigManager.js +386 -0
  109. package/dist/services/FeatureManager.d.ts +5 -0
  110. package/dist/services/FeatureManager.js +6 -0
  111. package/dist/services/FileService.d.ts +21 -0
  112. package/dist/services/FileService.js +152 -0
  113. package/dist/services/IndexBuilder.d.ts +12 -0
  114. package/dist/services/IndexBuilder.js +130 -0
  115. package/dist/services/Logger.d.ts +20 -0
  116. package/dist/services/Logger.js +48 -0
  117. package/dist/services/ProjectAssetRegistry.d.ts +12 -0
  118. package/dist/services/ProjectAssetRegistry.js +96 -0
  119. package/dist/services/ProjectAssetService.d.ts +49 -0
  120. package/dist/services/ProjectAssetService.js +223 -0
  121. package/dist/services/ProjectScaffoldCommandService.d.ts +73 -0
  122. package/dist/services/ProjectScaffoldCommandService.js +159 -0
  123. package/dist/services/ProjectScaffoldService.d.ts +44 -0
  124. package/dist/services/ProjectScaffoldService.js +507 -0
  125. package/dist/services/ProjectService.d.ts +209 -0
  126. package/dist/services/ProjectService.js +13239 -0
  127. package/dist/services/QueueService.d.ts +17 -0
  128. package/dist/services/QueueService.js +142 -0
  129. package/dist/services/RunService.d.ts +40 -0
  130. package/dist/services/RunService.js +420 -0
  131. package/dist/services/SkillParser.d.ts +30 -0
  132. package/dist/services/SkillParser.js +88 -0
  133. package/dist/services/StateManager.d.ts +16 -0
  134. package/dist/services/StateManager.js +127 -0
  135. package/dist/services/TemplateEngine.d.ts +43 -0
  136. package/dist/services/TemplateEngine.js +119 -0
  137. package/dist/services/TemplateGenerator.d.ts +40 -0
  138. package/dist/services/TemplateGenerator.js +273 -0
  139. package/dist/services/ValidationService.d.ts +19 -0
  140. package/dist/services/ValidationService.js +44 -0
  141. package/dist/services/Validator.d.ts +5 -0
  142. package/dist/services/Validator.js +6 -0
  143. package/dist/services/index.d.ts +52 -0
  144. package/dist/services/index.js +91 -0
  145. package/dist/services/templates/ExecutionTemplateBuilder.d.ts +12 -0
  146. package/dist/services/templates/ExecutionTemplateBuilder.js +300 -0
  147. package/dist/services/templates/ProjectTemplateBuilder.d.ts +38 -0
  148. package/dist/services/templates/ProjectTemplateBuilder.js +1897 -0
  149. package/dist/services/templates/TemplateBuilderBase.d.ts +19 -0
  150. package/dist/services/templates/TemplateBuilderBase.js +60 -0
  151. package/dist/services/templates/TemplateInputFactory.d.ts +16 -0
  152. package/dist/services/templates/TemplateInputFactory.js +298 -0
  153. package/dist/services/templates/templateTypes.d.ts +90 -0
  154. package/dist/services/templates/templateTypes.js +3 -0
  155. package/dist/tools/build-index.js +632 -0
  156. package/dist/utils/DateUtils.d.ts +18 -0
  157. package/dist/utils/DateUtils.js +40 -0
  158. package/dist/utils/PathUtils.d.ts +9 -0
  159. package/dist/utils/PathUtils.js +66 -0
  160. package/dist/utils/StringUtils.d.ts +26 -0
  161. package/dist/utils/StringUtils.js +47 -0
  162. package/dist/utils/helpers.d.ts +5 -0
  163. package/dist/utils/helpers.js +6 -0
  164. package/dist/utils/index.d.ts +7 -0
  165. package/dist/utils/index.js +23 -0
  166. package/dist/utils/logger.d.ts +5 -0
  167. package/dist/utils/logger.js +6 -0
  168. package/dist/utils/path.d.ts +5 -0
  169. package/dist/utils/path.js +6 -0
  170. package/dist/utils/subcommandHelp.d.ts +11 -0
  171. package/dist/utils/subcommandHelp.js +119 -0
  172. package/dist/workflow/ArchiveGate.d.ts +30 -0
  173. package/dist/workflow/ArchiveGate.js +93 -0
  174. package/dist/workflow/ConfigurableWorkflow.d.ts +89 -0
  175. package/dist/workflow/ConfigurableWorkflow.js +186 -0
  176. package/dist/workflow/HookSystem.d.ts +38 -0
  177. package/dist/workflow/HookSystem.js +66 -0
  178. package/dist/workflow/IndexRegenerator.d.ts +49 -0
  179. package/dist/workflow/IndexRegenerator.js +147 -0
  180. package/dist/workflow/PluginWorkflowComposer.d.ts +138 -0
  181. package/dist/workflow/PluginWorkflowComposer.js +239 -0
  182. package/dist/workflow/SkillUpdateEngine.d.ts +26 -0
  183. package/dist/workflow/SkillUpdateEngine.js +113 -0
  184. package/dist/workflow/VerificationSystem.d.ts +24 -0
  185. package/dist/workflow/VerificationSystem.js +116 -0
  186. package/dist/workflow/WorkflowEngine.d.ts +15 -0
  187. package/dist/workflow/WorkflowEngine.js +57 -0
  188. package/dist/workflow/index.d.ts +19 -0
  189. package/dist/workflow/index.js +32 -0
  190. package/package.json +78 -0
  191. package/scripts/postinstall.js +43 -0
@@ -0,0 +1,36 @@
1
+ import { FeatureState } from '../core/types';
2
+ export interface BatchOperationResult {
3
+ successful: number;
4
+ failed: number;
5
+ skipped: number;
6
+ errors: Array<{
7
+ feature: string;
8
+ error: string;
9
+ }>;
10
+ }
11
+ export interface BatchQuery {
12
+ status?: string;
13
+ tags?: string[];
14
+ minProgress?: number;
15
+ maxProgress?: number;
16
+ createdAfter?: string;
17
+ createdBefore?: string;
18
+ }
19
+ export declare class BatchOperations {
20
+ queryFeatures(projectDir: string, query: BatchQuery): Promise<FeatureState[]>;
21
+ batchOperation(projectDir: string, query: BatchQuery, operation: (state: FeatureState, featurePath: string) => Promise<void>): Promise<BatchOperationResult>;
22
+ exportFeatures(projectDir: string, query: BatchQuery): Promise<{
23
+ count: number;
24
+ features: FeatureState[];
25
+ timestamp: string;
26
+ }>;
27
+ importFeatures(projectDir: string, features: FeatureState[]): Promise<BatchOperationResult>;
28
+ getStatistics(projectDir: string): Promise<{
29
+ total: number;
30
+ byStatus: Record<string, number>;
31
+ byMode: Record<string, number>;
32
+ }>;
33
+ private matchesQuery;
34
+ }
35
+ export declare const batchOperations: BatchOperations;
36
+ //# sourceMappingURL=BatchOperations.d.ts.map
@@ -0,0 +1,159 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.batchOperations = exports.BatchOperations = void 0;
37
+ const path = __importStar(require("path"));
38
+ const constants_1 = require("../core/constants");
39
+ const services_1 = require("../services");
40
+ class BatchOperations {
41
+ async queryFeatures(projectDir, query) {
42
+ const featuresDir = path.join(projectDir, constants_1.DIR_NAMES.CHANGES, constants_1.DIR_NAMES.ACTIVE);
43
+ const results = [];
44
+ try {
45
+ const featureFolders = await services_1.services.fileService.readDir(featuresDir);
46
+ for (const featureName of featureFolders) {
47
+ const featurePath = path.join(featuresDir, featureName);
48
+ const statePath = path.join(featurePath, constants_1.FILE_NAMES.STATE);
49
+ if (!(await services_1.services.fileService.exists(statePath))) {
50
+ continue;
51
+ }
52
+ const state = await services_1.services.fileService.readJSON(statePath);
53
+ if (this.matchesQuery(state, query)) {
54
+ results.push(state);
55
+ }
56
+ }
57
+ }
58
+ catch (error) {
59
+ services_1.services.logger.warn(`Query failed: ${error}`);
60
+ }
61
+ return results;
62
+ }
63
+ async batchOperation(projectDir, query, operation) {
64
+ const result = {
65
+ successful: 0,
66
+ failed: 0,
67
+ skipped: 0,
68
+ errors: [],
69
+ };
70
+ const features = await this.queryFeatures(projectDir, query);
71
+ const featuresDir = path.join(projectDir, constants_1.DIR_NAMES.CHANGES, constants_1.DIR_NAMES.ACTIVE);
72
+ for (const feature of features) {
73
+ try {
74
+ await operation(feature, path.join(featuresDir, feature.feature));
75
+ result.successful++;
76
+ }
77
+ catch (error) {
78
+ result.failed++;
79
+ result.errors.push({
80
+ feature: feature.feature,
81
+ error: String(error),
82
+ });
83
+ }
84
+ }
85
+ return result;
86
+ }
87
+ async exportFeatures(projectDir, query) {
88
+ const features = await this.queryFeatures(projectDir, query);
89
+ return {
90
+ count: features.length,
91
+ features,
92
+ timestamp: new Date().toISOString(),
93
+ };
94
+ }
95
+ async importFeatures(projectDir, features) {
96
+ const result = {
97
+ successful: 0,
98
+ failed: 0,
99
+ skipped: 0,
100
+ errors: [],
101
+ };
102
+ const featuresDir = path.join(projectDir, constants_1.DIR_NAMES.CHANGES, constants_1.DIR_NAMES.ACTIVE);
103
+ for (const feature of features) {
104
+ try {
105
+ const featurePath = path.join(featuresDir, feature.feature);
106
+ const statePath = path.join(featurePath, constants_1.FILE_NAMES.STATE);
107
+ if (await services_1.services.fileService.exists(statePath)) {
108
+ result.skipped++;
109
+ continue;
110
+ }
111
+ await services_1.services.fileService.ensureDir(featurePath);
112
+ await services_1.services.fileService.writeJSON(statePath, feature);
113
+ result.successful++;
114
+ }
115
+ catch (error) {
116
+ result.failed++;
117
+ result.errors.push({
118
+ feature: feature.feature,
119
+ error: String(error),
120
+ });
121
+ }
122
+ }
123
+ return result;
124
+ }
125
+ async getStatistics(projectDir) {
126
+ const features = await this.queryFeatures(projectDir, {});
127
+ const stats = {
128
+ total: features.length,
129
+ byStatus: {},
130
+ byMode: {},
131
+ };
132
+ for (const feature of features) {
133
+ if (!stats.byStatus[feature.status]) {
134
+ stats.byStatus[feature.status] = 0;
135
+ }
136
+ stats.byStatus[feature.status]++;
137
+ if (!stats.byMode[feature.mode]) {
138
+ stats.byMode[feature.mode] = 0;
139
+ }
140
+ stats.byMode[feature.mode]++;
141
+ }
142
+ return stats;
143
+ }
144
+ matchesQuery(state, query) {
145
+ if (query.status && state.status !== query.status) {
146
+ return false;
147
+ }
148
+ if (query.tags && query.tags.length > 0) {
149
+ const hasMatchingTag = query.tags.some(tag => (state.pending || []).includes(tag));
150
+ if (!hasMatchingTag) {
151
+ return false;
152
+ }
153
+ }
154
+ return true;
155
+ }
156
+ }
157
+ exports.BatchOperations = BatchOperations;
158
+ exports.batchOperations = new BatchOperations();
159
+ //# sourceMappingURL=BatchOperations.js.map
@@ -0,0 +1,66 @@
1
+ /**
2
+ * 缓存层系统
3
+ * 优化性能和减少磁盘访问
4
+ */
5
+ export interface CacheEntry<T> {
6
+ key: string;
7
+ value: T;
8
+ timestamp: number;
9
+ ttl?: number;
10
+ }
11
+ export declare class CachingLayer<T = any> {
12
+ private cache;
13
+ private stats;
14
+ private maxSize;
15
+ private cleanupInterval?;
16
+ constructor(maxSize?: number);
17
+ /**
18
+ * 设置缓存值
19
+ */
20
+ set(key: string, value: T, ttl?: number): void;
21
+ /**
22
+ * 获取缓存值
23
+ */
24
+ get(key: string): T | null;
25
+ /**
26
+ * 检查键是否存在
27
+ */
28
+ has(key: string): boolean;
29
+ /**
30
+ * 删除缓存
31
+ */
32
+ delete(key: string): boolean;
33
+ /**
34
+ * 清空缓存
35
+ */
36
+ clear(): void;
37
+ /**
38
+ * 获取缓存大小
39
+ */
40
+ size(): number;
41
+ /**
42
+ * 获取统计信息
43
+ */
44
+ getStats(): {
45
+ hits: number;
46
+ misses: number;
47
+ evictions: number;
48
+ hitRate: number;
49
+ currentSize: number;
50
+ maxSize: number;
51
+ };
52
+ /**
53
+ * 启动清理过期条目
54
+ */
55
+ private startCleanup;
56
+ /**
57
+ * 停止清理
58
+ */
59
+ stopCleanup(): void;
60
+ /**
61
+ * 销毁缓存
62
+ */
63
+ destroy(): void;
64
+ }
65
+ export declare const cachingLayer: CachingLayer<any>;
66
+ //# sourceMappingURL=CachingLayer.d.ts.map
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ /**
3
+ * 缓存层系统
4
+ * 优化性能和减少磁盘访问
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.cachingLayer = exports.CachingLayer = void 0;
8
+ class CachingLayer {
9
+ constructor(maxSize = 1000) {
10
+ this.cache = new Map();
11
+ this.stats = {
12
+ hits: 0,
13
+ misses: 0,
14
+ evictions: 0,
15
+ };
16
+ this.maxSize = 1000;
17
+ this.maxSize = maxSize;
18
+ this.startCleanup();
19
+ }
20
+ /**
21
+ * 设置缓存值
22
+ */
23
+ set(key, value, ttl) {
24
+ // 如果超过最大大小,移除最旧的条目
25
+ if (this.cache.size >= this.maxSize) {
26
+ const oldestKey = Array.from(this.cache.entries()).sort((a, b) => a[1].timestamp - b[1].timestamp)[0]?.[0];
27
+ if (oldestKey) {
28
+ this.cache.delete(oldestKey);
29
+ this.stats.evictions++;
30
+ }
31
+ }
32
+ const entry = {
33
+ key,
34
+ value,
35
+ timestamp: Date.now(),
36
+ ttl,
37
+ };
38
+ this.cache.set(key, entry);
39
+ }
40
+ /**
41
+ * 获取缓存值
42
+ */
43
+ get(key) {
44
+ const entry = this.cache.get(key);
45
+ if (!entry) {
46
+ this.stats.misses++;
47
+ return null;
48
+ }
49
+ // 检查是否过期
50
+ if (entry.ttl && Date.now() - entry.timestamp > entry.ttl) {
51
+ this.cache.delete(key);
52
+ this.stats.misses++;
53
+ return null;
54
+ }
55
+ this.stats.hits++;
56
+ return entry.value;
57
+ }
58
+ /**
59
+ * 检查键是否存在
60
+ */
61
+ has(key) {
62
+ return this.get(key) !== null;
63
+ }
64
+ /**
65
+ * 删除缓存
66
+ */
67
+ delete(key) {
68
+ return this.cache.delete(key);
69
+ }
70
+ /**
71
+ * 清空缓存
72
+ */
73
+ clear() {
74
+ this.cache.clear();
75
+ }
76
+ /**
77
+ * 获取缓存大小
78
+ */
79
+ size() {
80
+ return this.cache.size;
81
+ }
82
+ /**
83
+ * 获取统计信息
84
+ */
85
+ getStats() {
86
+ const total = this.stats.hits + this.stats.misses;
87
+ const hitRate = total > 0 ? (this.stats.hits / total * 100).toFixed(2) : '0';
88
+ return {
89
+ hits: this.stats.hits,
90
+ misses: this.stats.misses,
91
+ evictions: this.stats.evictions,
92
+ hitRate: parseFloat(hitRate),
93
+ currentSize: this.cache.size,
94
+ maxSize: this.maxSize,
95
+ };
96
+ }
97
+ /**
98
+ * 启动清理过期条目
99
+ */
100
+ startCleanup() {
101
+ this.cleanupInterval = setInterval(() => {
102
+ const now = Date.now();
103
+ let removed = 0;
104
+ for (const [key, entry] of this.cache.entries()) {
105
+ if (entry.ttl && now - entry.timestamp > entry.ttl) {
106
+ this.cache.delete(key);
107
+ removed++;
108
+ }
109
+ }
110
+ if (removed > 0) {
111
+ this.stats.evictions += removed;
112
+ }
113
+ }, 60000); // 每分钟检查一次
114
+ // Do not keep unrelated CLI commands alive just because the cache module was imported.
115
+ this.cleanupInterval.unref?.();
116
+ }
117
+ /**
118
+ * 停止清理
119
+ */
120
+ stopCleanup() {
121
+ if (this.cleanupInterval) {
122
+ clearInterval(this.cleanupInterval);
123
+ this.cleanupInterval = undefined;
124
+ }
125
+ }
126
+ /**
127
+ * 销毁缓存
128
+ */
129
+ destroy() {
130
+ this.stopCleanup();
131
+ this.clear();
132
+ }
133
+ }
134
+ exports.CachingLayer = CachingLayer;
135
+ exports.cachingLayer = new CachingLayer();
136
+ //# sourceMappingURL=CachingLayer.js.map
@@ -0,0 +1,46 @@
1
+ /**
2
+ * 特性更新系统
3
+ * 处理特性的更新和迁移
4
+ */
5
+ import { FeatureState, FeatureStatus } from '../core/types';
6
+ export interface UpdateOptions {
7
+ status?: FeatureStatus;
8
+ description?: string;
9
+ tags?: string[];
10
+ affects?: string[];
11
+ }
12
+ export interface UpdateLog {
13
+ timestamp: string;
14
+ type: 'status' | 'property' | 'metadata';
15
+ changes: Record<string, any>;
16
+ author?: string;
17
+ }
18
+ export declare class FeatureUpdater {
19
+ private updateLogs;
20
+ /**
21
+ * 更新特性属性
22
+ */
23
+ updateFeature(featurePath: string, options: UpdateOptions): Promise<FeatureState>;
24
+ /**
25
+ * 批量更新特性
26
+ */
27
+ batchUpdateFeatures(projectDir: string, filter: (state: FeatureState) => boolean, updates: UpdateOptions): Promise<FeatureState[]>;
28
+ /**
29
+ * 迁移特性版本
30
+ */
31
+ migrateFeature(featurePath: string, targetVersion: string): Promise<void>;
32
+ /**
33
+ * 记录更新日志
34
+ */
35
+ private logUpdate;
36
+ /**
37
+ * 获取更新日志
38
+ */
39
+ getUpdateLogs(): UpdateLog[];
40
+ /**
41
+ * 清空日志
42
+ */
43
+ clearLogs(): void;
44
+ }
45
+ export declare const featureUpdater: FeatureUpdater;
46
+ //# sourceMappingURL=FeatureUpdater.d.ts.map
@@ -0,0 +1,151 @@
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.featureUpdater = exports.FeatureUpdater = void 0;
41
+ const path = __importStar(require("path"));
42
+ const services_1 = require("../services");
43
+ const constants_1 = require("../core/constants");
44
+ class FeatureUpdater {
45
+ constructor() {
46
+ this.updateLogs = [];
47
+ }
48
+ /**
49
+ * 更新特性属性
50
+ */
51
+ async updateFeature(featurePath, options) {
52
+ const statePath = path.join(featurePath, constants_1.FILE_NAMES.STATE);
53
+ const state = await services_1.services.fileService.readJSON(statePath);
54
+ const changes = {};
55
+ // 更新状态
56
+ if (options.status && options.status !== state.status) {
57
+ changes.status = options.status;
58
+ state.status = options.status;
59
+ }
60
+ // 更新描述(存在proposal中)
61
+ if (options.description) {
62
+ const proposalPath = path.join(featurePath, 'proposal', 'PROPOSAL.md');
63
+ const proposalExists = await services_1.services.fileService.exists(proposalPath);
64
+ if (proposalExists) {
65
+ changes.description = options.description;
66
+ }
67
+ }
68
+ // 更新标签
69
+ if (options.tags && JSON.stringify(options.tags) !== JSON.stringify(state.pending)) {
70
+ changes.tags = options.tags;
71
+ }
72
+ // 更新受影响模块
73
+ if (options.affects && JSON.stringify(options.affects) !== JSON.stringify(state.affects)) {
74
+ changes.affects = options.affects;
75
+ state.affects = options.affects;
76
+ }
77
+ // 记录更新日志
78
+ if (Object.keys(changes).length > 0) {
79
+ this.logUpdate('property', changes);
80
+ state.last_updated = new Date().toISOString();
81
+ await services_1.services.fileService.writeJSON(statePath, state);
82
+ }
83
+ return state;
84
+ }
85
+ /**
86
+ * 批量更新特性
87
+ */
88
+ async batchUpdateFeatures(projectDir, filter, updates) {
89
+ const featuresDir = path.join(projectDir, 'features');
90
+ const features = [];
91
+ try {
92
+ const featureFolders = await services_1.services.fileService.readDir(featuresDir);
93
+ for (const featureName of featureFolders) {
94
+ const featurePath = path.join(featuresDir, featureName);
95
+ const statePath = path.join(featurePath, constants_1.FILE_NAMES.STATE);
96
+ const exists = await services_1.services.fileService.exists(statePath);
97
+ if (!exists)
98
+ continue;
99
+ const state = await services_1.services.fileService.readJSON(statePath);
100
+ if (filter(state)) {
101
+ const updated = await this.updateFeature(featurePath, updates);
102
+ features.push(updated);
103
+ }
104
+ }
105
+ }
106
+ catch (error) {
107
+ services_1.services.logger.warn(`Failed to batch update: ${error}`);
108
+ }
109
+ return features;
110
+ }
111
+ /**
112
+ * 迁移特性版本
113
+ */
114
+ async migrateFeature(featurePath, targetVersion) {
115
+ const statePath = path.join(featurePath, constants_1.FILE_NAMES.STATE);
116
+ const state = await services_1.services.fileService.readJSON(statePath);
117
+ const oldVersion = state.version;
118
+ state.version = targetVersion;
119
+ state.last_updated = new Date().toISOString();
120
+ await services_1.services.fileService.writeJSON(statePath, state);
121
+ this.logUpdate('metadata', {
122
+ versionMigration: { from: oldVersion, to: targetVersion },
123
+ });
124
+ }
125
+ /**
126
+ * 记录更新日志
127
+ */
128
+ logUpdate(type, changes) {
129
+ const log = {
130
+ timestamp: new Date().toISOString(),
131
+ type,
132
+ changes,
133
+ };
134
+ this.updateLogs.push(log);
135
+ }
136
+ /**
137
+ * 获取更新日志
138
+ */
139
+ getUpdateLogs() {
140
+ return this.updateLogs;
141
+ }
142
+ /**
143
+ * 清空日志
144
+ */
145
+ clearLogs() {
146
+ this.updateLogs = [];
147
+ }
148
+ }
149
+ exports.FeatureUpdater = FeatureUpdater;
150
+ exports.featureUpdater = new FeatureUpdater();
151
+ //# sourceMappingURL=FeatureUpdater.js.map
@@ -0,0 +1,52 @@
1
+ /**
2
+ * 性能监控系统
3
+ * 跟踪和优化系统性能
4
+ */
5
+ export interface PerformanceMetric {
6
+ name: string;
7
+ duration: number;
8
+ timestamp: string;
9
+ metadata?: Record<string, any>;
10
+ }
11
+ export interface PerformanceSummary {
12
+ totalDuration: number;
13
+ averageDuration: number;
14
+ minDuration: number;
15
+ maxDuration: number;
16
+ count: number;
17
+ operationsPerSecond: number;
18
+ }
19
+ export declare class PerformanceMonitor {
20
+ private metrics;
21
+ private startTimes;
22
+ /**
23
+ * 开始计时
24
+ */
25
+ start(label: string): void;
26
+ /**
27
+ * 结束计时并记录
28
+ */
29
+ end(label: string, metadata?: Record<string, any>): number;
30
+ /**
31
+ * 获取统计信息
32
+ */
33
+ getSummary(label?: string): PerformanceSummary | Record<string, PerformanceSummary>;
34
+ /**
35
+ * 计算统计数据
36
+ */
37
+ private calculateSummary;
38
+ /**
39
+ * 获取原始指标
40
+ */
41
+ getMetrics(label?: string): PerformanceMetric[] | Record<string, PerformanceMetric[]>;
42
+ /**
43
+ * 清空指标
44
+ */
45
+ clear(label?: string): void;
46
+ /**
47
+ * 生成性能报告
48
+ */
49
+ generateReport(): string;
50
+ }
51
+ export declare const performanceMonitor: PerformanceMonitor;
52
+ //# sourceMappingURL=PerformanceMonitor.d.ts.map