oneie 3.4.2 โ†’ 3.6.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.
Files changed (143) hide show
  1. package/.claude/agents/agent-director.md +902 -22
  2. package/.claude/agents/agent-onboard-example-output.md +600 -0
  3. package/.claude/agents/agent-onboard.md +576 -0
  4. package/.claude/commands/ONBOARDING_ENHANCEMENT_SUMMARY.md +266 -0
  5. package/.claude/commands/one.md +411 -10
  6. package/.claude/commands/release.md +64 -3
  7. package/CLAUDE.md +55 -69
  8. package/dist/commands/init.d.ts +5 -6
  9. package/dist/commands/init.d.ts.map +1 -1
  10. package/dist/commands/init.js +101 -101
  11. package/dist/commands/init.js.map +1 -1
  12. package/dist/index.js +6 -5
  13. package/dist/index.js.map +1 -1
  14. package/dist/utils/installation-setup.d.ts +24 -1
  15. package/dist/utils/installation-setup.d.ts.map +1 -1
  16. package/dist/utils/installation-setup.js +85 -1
  17. package/dist/utils/installation-setup.js.map +1 -1
  18. package/dist/utils/launch-claude.d.ts +6 -0
  19. package/dist/utils/launch-claude.d.ts.map +1 -0
  20. package/dist/utils/launch-claude.js +51 -0
  21. package/dist/utils/launch-claude.js.map +1 -0
  22. package/dist/utils/validation.d.ts +48 -0
  23. package/dist/utils/validation.d.ts.map +1 -0
  24. package/dist/utils/validation.js +73 -0
  25. package/dist/utils/validation.js.map +1 -0
  26. package/folders.yaml +1 -1
  27. package/one/.obsidian/app.json +8 -0
  28. package/one/.obsidian/appearance.json +1 -0
  29. package/one/.obsidian/community-plugins.json +3 -0
  30. package/one/.obsidian/core-plugins.json +33 -0
  31. package/one/.obsidian/plugins/easy-bake/main.js +361 -0
  32. package/one/.obsidian/plugins/easy-bake/manifest.json +11 -0
  33. package/one/.obsidian/plugins/easy-bake/styles.css +10 -0
  34. package/one/.obsidian/workspace.json +240 -0
  35. package/one/connections/workflow-onboarding.md +683 -0
  36. package/one/events/CART-DRAWER-INTEGRATION-GUIDE.md +354 -0
  37. package/one/events/CRITICAL-FIXES-COMPLETE.md +504 -0
  38. package/one/events/DEPLOYMENT.md +178 -0
  39. package/one/events/ECOMMERCE-DEMO-PLAN.md +225 -0
  40. package/one/events/ECOMMERCE-LIVE-DEMO.md +363 -0
  41. package/one/events/ECOMMERCE-TEMPLATE-COMPLETE.md +735 -0
  42. package/one/events/ECOMMERCE-TEMPLATES-SUMMARY.md +923 -0
  43. package/one/events/GRADIENT-TEXT-PERMANENT-FIX.md +223 -0
  44. package/one/events/HANDOFF.md +313 -0
  45. package/one/events/IMPLEMENTATION-SUMMARY-FINAL.md +503 -0
  46. package/one/events/IMPLEMENTATION_SUMMARY.md +529 -0
  47. package/one/events/LANDING-PAGE-EXAMPLE-OUTPUT.md +666 -0
  48. package/one/events/LANDING-PAGE-IMPLEMENTATION.md +642 -0
  49. package/one/events/LANDING-PAGE-QUICKSTART.md +407 -0
  50. package/one/events/MULTI-ONTOLOGY-COMPLETE-GUIDE.md +1627 -0
  51. package/one/events/MULTI-ONTOLOGY-IMPLEMENTATION-COMPLETE.md +573 -0
  52. package/one/events/ONBOARDING-IMPLEMENTATION-COMPLETE copy.md +398 -0
  53. package/one/events/ONTOLOGY-TUTORIALS-SUMMARY.md +525 -0
  54. package/one/events/ONTOLOGY-TYPE-GENERATOR-SUMMARY.md +455 -0
  55. package/one/events/ONTOLOGY_DISCOVERY_IMPLEMENTATION.md +486 -0
  56. package/one/events/ONTOLOGY_DISCOVERY_QUICKSTART.md +203 -0
  57. package/one/events/SECURITY-AUDIT-FIXES.md +376 -0
  58. package/one/events/SECURITY-SCAN-COMPLETE.md +281 -0
  59. package/one/events/SHOP-BUILD-STATUS.md +114 -0
  60. package/one/events/SHOP-PREMIUM-UPDATE.md +149 -0
  61. package/one/events/SITE-WIDE-GRADIENT-FIX.md +299 -0
  62. package/one/events/STORE-PRODUCTION-READY-STATUS.md +359 -0
  63. package/one/events/STRIPE-PAYMENT-METHODS-GUIDE.md +429 -0
  64. package/one/events/agent-director-enhancement-summary.md +386 -0
  65. package/one/events/agent-onboard-implementation-summary.md +457 -0
  66. package/one/events/clean-agent-ontology-cleanup-report.md +353 -0
  67. package/one/events/landing-page-generator.md +458 -0
  68. package/one/events/onboarding-implementation-complete.md +505 -0
  69. package/one/events/release.md +254 -0
  70. package/one/events/separate-implementation-status.md +537 -0
  71. package/one/groups/nine-padle-contents.baked.md +1252 -0
  72. package/one/groups/nine-padle-contents.md +6 -0
  73. package/one/knowledge/100-inference-quick-reference.md +431 -0
  74. package/one/knowledge/agent-onboard-usage.md +612 -0
  75. package/one/knowledge/cli-claude-handoff.md +718 -0
  76. package/one/knowledge/installation-folders.md +45 -1
  77. package/one/knowledge/ontology-blog.yaml +31 -0
  78. package/one/knowledge/ontology-cheatsheet.md +591 -0
  79. package/one/knowledge/ontology-community.yaml +42 -0
  80. package/one/knowledge/ontology-core-universal.md +722 -0
  81. package/one/knowledge/ontology-core.yaml +50 -0
  82. package/one/knowledge/ontology-courses.yaml +53 -0
  83. package/one/knowledge/ontology-creator.md +376 -0
  84. package/one/knowledge/ontology-developer-guide.md +789 -0
  85. package/one/knowledge/ontology-education.md +920 -0
  86. package/one/knowledge/ontology-index.md +354 -0
  87. package/one/knowledge/ontology-migration-guide.md +811 -0
  88. package/one/knowledge/ontology-minimal.yaml +1 -1
  89. package/one/knowledge/ontology-portfolio.yaml +31 -0
  90. package/one/knowledge/ontology-quickstart.md +576 -0
  91. package/one/knowledge/ontology-shop.yaml +121 -0
  92. package/one/knowledge/ontology-tokens.yaml +32 -0
  93. package/one/knowledge/ontology-tutorial.md +434 -0
  94. package/one/knowledge/ontology-video-script.md +890 -0
  95. package/one/things/docs/ecommerce/ARCHITECTURE-DIAGRAM.md +467 -0
  96. package/one/things/docs/ecommerce/CONVERSION-ELEMENTS-IMPLEMENTATION.md +408 -0
  97. package/one/things/docs/ecommerce/CONVERSION-ELEMENTS-SUMMARY.md +369 -0
  98. package/one/things/docs/ecommerce/CONVERSION-UX-IMPLEMENTATION-SUMMARY.md +396 -0
  99. package/one/things/docs/ecommerce/FEATURE-SUMMARY.md +468 -0
  100. package/one/things/docs/ecommerce/IMPLEMENTATION-NOTES.md +582 -0
  101. package/one/things/docs/ecommerce/INTEGRATION-EXAMPLE.md +449 -0
  102. package/one/things/docs/ecommerce/QUICK-START.md +368 -0
  103. package/one/things/docs/ecommerce/URGENCY-IMPLEMENTATION-SUMMARY.md +498 -0
  104. package/one/things/docs/ecommerce/URGENCY-QUICK-REFERENCE.md +237 -0
  105. package/one/things/docs/ecommerce/USAGE-EXAMPLE.astro +171 -0
  106. package/one/things/docs/ecommerce/demo.astro +309 -0
  107. package/one/things/plans/agent-director-100-inference-plans.md +410 -0
  108. package/one/things/plans/dual-website-strategy.md +612 -0
  109. package/one/things/plans/feature-based-sites.md +821 -0
  110. package/one/things/plans/multi-ontology-architecture.md +836 -0
  111. package/one/things/plans/onboarding.md +32 -0
  112. package/one/things/plans/separate.md +15 -17
  113. package/one/things/plans/start-new.md +738 -0
  114. package/one/things/templates.md +254 -0
  115. package/one/things/todo.md +23 -5
  116. package/package.json +2 -2
  117. package/one/things/claude/hooks/agent-hook-manager.js +0 -525
  118. package/one/things/claude/hooks/agent-load-balancer.js +0 -271
  119. package/one/things/claude/hooks/agent-request-interceptor.js +0 -70
  120. package/one/things/claude/hooks/cascade-feedback.js +0 -297
  121. package/one/things/claude/hooks/cascade-integration-hooks.js +0 -648
  122. package/one/things/claude/hooks/continuous-improvement-monitor.js +0 -510
  123. package/one/things/claude/hooks/file-organization-engine.js +0 -427
  124. package/one/things/claude/hooks/file-organization-monitor.js +0 -269
  125. package/one/things/claude/hooks/hook-config-manager.js +0 -202
  126. package/one/things/claude/hooks/hook-orchestrator.js +0 -662
  127. package/one/things/claude/hooks/hook-performance-report.js +0 -120
  128. package/one/things/claude/hooks/mcp-cascade-integration.js +0 -816
  129. package/one/things/claude/hooks/memory-optimizer.js +0 -510
  130. package/one/things/claude/hooks/ontology-compliance.js +0 -394
  131. package/one/things/claude/hooks/ontology-hook-manager.js +0 -316
  132. package/one/things/claude/hooks/ontology-validation-engine.js +0 -317
  133. package/one/things/claude/hooks/performance-monitoring-hook.js +0 -422
  134. package/one/things/claude/hooks/quality-scoring-engine.js +0 -834
  135. package/one/things/claude/hooks/simple-load-balancer.js +0 -238
  136. package/one/things/claude/hooks/startup-optimizer.js +0 -625
  137. package/one/things/claude/hooks/story-scoring-system.js +0 -445
  138. package/one/things/claude/hooks/story-validation-engine.js +0 -473
  139. package/one/things/claude/hooks/structure-synchronizer.js +0 -194
  140. package/one/things/claude/hooks/sub-agent-output-validator.js +0 -647
  141. package/one/things/claude/hooks/sub-agent-validation-hook.js +0 -343
  142. package/one/things/claude/hooks/trinity-validation-system.js +0 -392
  143. package/one/things/plans/organizations-to-groups.md +0 -705
@@ -1,510 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * Memory Optimizer Hook
5
- *
6
- * Reduces 500MB+ peak usage to <150MB through intelligent memory management
7
- * Implements real-time memory monitoring and optimization strategies
8
- */
9
-
10
- import fs from 'fs/promises';
11
- import path from 'path';
12
- import zlib from 'zlib';
13
-
14
- class MemoryOptimizer {
15
- constructor(options = {}) {
16
- this.options = {
17
- maxMemoryMB: 150,
18
- warningThresholdMB: 120,
19
- gcIntervalMs: 30000,
20
- cacheMaxItems: 1000,
21
- cacheMaxSizeMB: 50,
22
- enableStreaming: true,
23
- compressionLevel: 6,
24
- ...options
25
- };
26
-
27
- this.memoryCache = new Map();
28
- this.cacheStats = {
29
- hits: 0,
30
- misses: 0,
31
- evictions: 0,
32
- totalSize: 0
33
- };
34
-
35
- this.gcTimer = null;
36
- this.memoryMonitorTimer = null;
37
- this.isOptimizing = false;
38
-
39
- this.init();
40
- }
41
-
42
- /**
43
- * Initialize memory optimizer
44
- */
45
- init() {
46
- // Start periodic garbage collection
47
- this.startGarbageCollection();
48
-
49
- // Start memory monitoring
50
- this.startMemoryMonitoring();
51
-
52
- // Handle process events
53
- process.on('exit', () => this.cleanup());
54
- process.on('SIGINT', () => this.cleanup());
55
- process.on('SIGTERM', () => this.cleanup());
56
-
57
- console.log('๐Ÿง  Memory Optimizer initialized');
58
- }
59
-
60
- /**
61
- * Get current memory usage
62
- */
63
- getMemoryUsage() {
64
- const usage = process.memoryUsage();
65
- return {
66
- rss: Math.round(usage.rss / 1024 / 1024), // MB
67
- heapUsed: Math.round(usage.heapUsed / 1024 / 1024), // MB
68
- heapTotal: Math.round(usage.heapTotal / 1024 / 1024), // MB
69
- external: Math.round(usage.external / 1024 / 1024), // MB
70
- arrayBuffers: Math.round(usage.arrayBuffers / 1024 / 1024) // MB
71
- };
72
- }
73
-
74
- /**
75
- * Check if memory optimization is needed
76
- */
77
- needsOptimization() {
78
- const usage = this.getMemoryUsage();
79
- return usage.heapUsed > this.options.warningThresholdMB;
80
- }
81
-
82
- /**
83
- * Start periodic memory monitoring
84
- */
85
- startMemoryMonitoring() {
86
- this.memoryMonitorTimer = setInterval(() => {
87
- const usage = this.getMemoryUsage();
88
-
89
- if (usage.heapUsed > this.options.maxMemoryMB) {
90
- console.warn(`๐Ÿšจ Memory limit exceeded: ${usage.heapUsed}MB > ${this.options.maxMemoryMB}MB`);
91
- this.emergencyOptimization();
92
- } else if (usage.heapUsed > this.options.warningThresholdMB) {
93
- console.warn(`โš ๏ธ Memory warning: ${usage.heapUsed}MB (threshold: ${this.options.warningThresholdMB}MB)`);
94
- this.optimizeMemory();
95
- }
96
-
97
- // Log memory stats periodically
98
- if (Math.random() < 0.1) { // 10% chance
99
- this.logMemoryStats();
100
- }
101
-
102
- }, 10000); // Check every 10 seconds
103
- }
104
-
105
- /**
106
- * Start periodic garbage collection
107
- */
108
- startGarbageCollection() {
109
- this.gcTimer = setInterval(() => {
110
- if (global.gc && this.needsOptimization()) {
111
- const before = this.getMemoryUsage();
112
- global.gc();
113
- const after = this.getMemoryUsage();
114
-
115
- const freed = before.heapUsed - after.heapUsed;
116
- if (freed > 10) {
117
- console.log(`๐Ÿ—‘๏ธ Garbage collection freed ${freed}MB`);
118
- }
119
- }
120
- }, this.options.gcIntervalMs);
121
- }
122
-
123
- /**
124
- * Emergency memory optimization when limits are exceeded
125
- */
126
- async emergencyOptimization() {
127
- if (this.isOptimizing) return;
128
-
129
- this.isOptimizing = true;
130
- console.log('๐Ÿšจ Starting emergency memory optimization...');
131
-
132
- try {
133
- // Clear all caches immediately
134
- await this.clearAllCaches();
135
-
136
- // Force garbage collection
137
- if (global.gc) {
138
- global.gc();
139
- global.gc(); // Run twice for better cleanup
140
- }
141
-
142
- // Clear large variables if possible
143
- this.clearLargeVariables();
144
-
145
- console.log('โœ… Emergency optimization completed');
146
-
147
- } catch (error) {
148
- console.error('โŒ Emergency optimization failed:', error);
149
- } finally {
150
- this.isOptimizing = false;
151
- }
152
- }
153
-
154
- /**
155
- * Regular memory optimization
156
- */
157
- async optimizeMemory() {
158
- if (this.isOptimizing) return;
159
-
160
- this.isOptimizing = true;
161
-
162
- try {
163
- // Clean expired cache entries
164
- await this.cleanExpiredCache();
165
-
166
- // Compress large objects in memory
167
- await this.compressLargeObjects();
168
-
169
- // Trigger garbage collection if available
170
- if (global.gc && Math.random() < 0.3) {
171
- global.gc();
172
- }
173
-
174
- } catch (error) {
175
- console.warn('โš ๏ธ Memory optimization error:', error.message);
176
- } finally {
177
- this.isOptimizing = false;
178
- }
179
- }
180
-
181
- /**
182
- * Intelligent caching with size limits
183
- */
184
- async cacheContent(key, content, options = {}) {
185
- const {
186
- ttl = 300000, // 5 minutes default
187
- compress = true,
188
- priority = 'normal'
189
- } = options;
190
-
191
- // Check cache size limits
192
- if (this.cacheStats.totalSize > this.options.cacheMaxSizeMB * 1024 * 1024) {
193
- await this.evictLeastRecentlyUsed();
194
- }
195
-
196
- if (this.memoryCache.size >= this.options.cacheMaxItems) {
197
- await this.evictLeastRecentlyUsed();
198
- }
199
-
200
- const entry = {
201
- content: compress ? this.compressString(content) : content,
202
- timestamp: Date.now(),
203
- ttl,
204
- priority,
205
- compressed: compress,
206
- size: Buffer.byteLength(content, 'utf8'),
207
- accessCount: 0,
208
- lastAccessed: Date.now()
209
- };
210
-
211
- this.memoryCache.set(key, entry);
212
- this.cacheStats.totalSize += entry.size;
213
-
214
- return entry;
215
- }
216
-
217
- /**
218
- * Retrieve from cache with optimization
219
- */
220
- async getCachedContent(key) {
221
- const entry = this.memoryCache.get(key);
222
-
223
- if (!entry) {
224
- this.cacheStats.misses++;
225
- return null;
226
- }
227
-
228
- // Check TTL
229
- if (Date.now() - entry.timestamp > entry.ttl) {
230
- this.memoryCache.delete(key);
231
- this.cacheStats.totalSize -= entry.size;
232
- this.cacheStats.misses++;
233
- return null;
234
- }
235
-
236
- // Update access stats
237
- entry.accessCount++;
238
- entry.lastAccessed = Date.now();
239
- this.cacheStats.hits++;
240
-
241
- // Decompress if needed
242
- const content = entry.compressed ?
243
- this.decompressString(entry.content) :
244
- entry.content;
245
-
246
- return content;
247
- }
248
-
249
- /**
250
- * Evict least recently used cache entries
251
- */
252
- async evictLeastRecentlyUsed() {
253
- const entries = Array.from(this.memoryCache.entries())
254
- .map(([key, value]) => ({ key, ...value }))
255
- .sort((a, b) => {
256
- // Sort by priority first, then by last accessed
257
- if (a.priority !== b.priority) {
258
- const priorities = { low: 0, normal: 1, high: 2 };
259
- return priorities[a.priority] - priorities[b.priority];
260
- }
261
- return a.lastAccessed - b.lastAccessed;
262
- });
263
-
264
- // Remove bottom 20% of entries
265
- const toRemove = Math.max(1, Math.floor(entries.length * 0.2));
266
-
267
- for (let i = 0; i < toRemove && entries.length > 0; i++) {
268
- const entry = entries[i];
269
- this.memoryCache.delete(entry.key);
270
- this.cacheStats.totalSize -= entry.size;
271
- this.cacheStats.evictions++;
272
- }
273
-
274
- console.log(`๐Ÿงน Evicted ${toRemove} cache entries`);
275
- }
276
-
277
- /**
278
- * Clear expired cache entries
279
- */
280
- async cleanExpiredCache() {
281
- const now = Date.now();
282
- const expired = [];
283
-
284
- for (const [key, entry] of this.memoryCache) {
285
- if (now - entry.timestamp > entry.ttl) {
286
- expired.push(key);
287
- }
288
- }
289
-
290
- for (const key of expired) {
291
- const entry = this.memoryCache.get(key);
292
- this.memoryCache.delete(key);
293
- this.cacheStats.totalSize -= entry.size;
294
- }
295
-
296
- if (expired.length > 0) {
297
- console.log(`๐Ÿงน Cleaned ${expired.length} expired cache entries`);
298
- }
299
- }
300
-
301
- /**
302
- * Clear all caches for emergency optimization
303
- */
304
- async clearAllCaches() {
305
- const size = this.memoryCache.size;
306
- this.memoryCache.clear();
307
- this.cacheStats.totalSize = 0;
308
- this.cacheStats.evictions += size;
309
-
310
- console.log(`๐Ÿงน Cleared all ${size} cache entries`);
311
- }
312
-
313
- /**
314
- * Compress large objects in memory
315
- */
316
- async compressLargeObjects() {
317
- let compressed = 0;
318
-
319
- for (const [key, entry] of this.memoryCache) {
320
- if (!entry.compressed && entry.size > 10000) { // 10KB threshold
321
- try {
322
- const compressedContent = this.compressString(entry.content);
323
- const originalSize = entry.size;
324
- const newSize = Buffer.byteLength(compressedContent, 'utf8');
325
-
326
- if (newSize < originalSize * 0.8) { // Only if 20%+ compression
327
- entry.content = compressedContent;
328
- entry.compressed = true;
329
- entry.size = newSize;
330
-
331
- this.cacheStats.totalSize -= (originalSize - newSize);
332
- compressed++;
333
- }
334
- } catch (error) {
335
- console.warn(`โš ๏ธ Cannot compress cache entry ${key}:`, error.message);
336
- }
337
- }
338
- }
339
-
340
- if (compressed > 0) {
341
- console.log(`๐Ÿ—œ๏ธ Compressed ${compressed} large cache objects`);
342
- }
343
- }
344
-
345
- /**
346
- * Clear large variables (placeholder for app-specific cleanup)
347
- */
348
- clearLargeVariables() {
349
- // Clear any global variables that might be holding large amounts of data
350
- if (global.ONE_LARGE_DATA) {
351
- global.ONE_LARGE_DATA = null;
352
- }
353
-
354
- // Clear any module-level caches
355
- if (require.cache) {
356
- const largeModules = Object.keys(require.cache).filter(key =>
357
- key.includes('large-') || key.includes('cache-')
358
- );
359
-
360
- largeModules.forEach(key => {
361
- delete require.cache[key];
362
- });
363
-
364
- if (largeModules.length > 0) {
365
- console.log(`๐Ÿงน Cleared ${largeModules.length} large modules from require cache`);
366
- }
367
- }
368
- }
369
-
370
- /**
371
- * Simple string compression using gzip
372
- */
373
- compressString(str) {
374
- return zlib.gzipSync(str, { level: this.options.compressionLevel }).toString('base64');
375
- }
376
-
377
- /**
378
- * String decompression
379
- */
380
- decompressString(compressed) {
381
- const buffer = Buffer.from(compressed, 'base64');
382
- return zlib.gunzipSync(buffer).toString('utf8');
383
- }
384
-
385
- /**
386
- * Log memory statistics
387
- */
388
- logMemoryStats() {
389
- const usage = this.getMemoryUsage();
390
- const cacheEfficiency = this.cacheStats.hits / (this.cacheStats.hits + this.cacheStats.misses) * 100;
391
-
392
- console.log(`๐Ÿ“Š Memory Stats:`);
393
- console.log(` Heap: ${usage.heapUsed}MB / ${usage.heapTotal}MB`);
394
- console.log(` RSS: ${usage.rss}MB`);
395
- console.log(` Cache: ${this.memoryCache.size} items, ${Math.round(this.cacheStats.totalSize / 1024 / 1024)}MB`);
396
- console.log(` Cache Efficiency: ${cacheEfficiency.toFixed(1)}%`);
397
- }
398
-
399
- /**
400
- * Stream large files instead of loading into memory
401
- */
402
- async streamLargeFile(filePath, processor) {
403
- const { createReadStream } = await import('fs');
404
- const readline = await import('readline');
405
-
406
- const stream = createReadStream(filePath, { encoding: 'utf8' });
407
- const rl = readline.createInterface({
408
- input: stream,
409
- crlfDelay: Infinity
410
- });
411
-
412
- let lineCount = 0;
413
- for await (const line of rl) {
414
- await processor(line, lineCount++);
415
-
416
- // Check memory periodically during streaming
417
- if (lineCount % 1000 === 0 && this.needsOptimization()) {
418
- await this.optimizeMemory();
419
- }
420
- }
421
-
422
- return lineCount;
423
- }
424
-
425
- /**
426
- * Memory-efficient file processing
427
- */
428
- async processFileMemoryEfficient(filePath, chunkSize = 64 * 1024) {
429
- const chunks = [];
430
- const fsModule = await import('fs');
431
- const stream = fsModule.createReadStream(filePath, {
432
- encoding: 'utf8',
433
- highWaterMark: chunkSize
434
- });
435
-
436
- return new Promise((resolve, reject) => {
437
- stream.on('data', (chunk) => {
438
- chunks.push(chunk);
439
-
440
- // Check memory usage during processing
441
- if (chunks.length % 10 === 0 && this.needsOptimization()) {
442
- this.optimizeMemory();
443
- }
444
- });
445
-
446
- stream.on('end', () => {
447
- resolve(chunks.join(''));
448
- });
449
-
450
- stream.on('error', reject);
451
- });
452
- }
453
-
454
- /**
455
- * Hook integration for Claude Code
456
- */
457
- async onFileChange(event, filePath) {
458
- // Optimize memory when large files are processed
459
- const stats = await fs.stat(filePath).catch(() => null);
460
-
461
- if (stats && stats.size > 1024 * 1024) { // 1MB+
462
- console.log(`๐Ÿง  Large file detected (${Math.round(stats.size / 1024 / 1024)}MB): ${filePath}`);
463
-
464
- if (this.needsOptimization()) {
465
- await this.optimizeMemory();
466
- }
467
- }
468
- }
469
-
470
- /**
471
- * Hook integration for before command execution
472
- */
473
- async beforeCommand(command) {
474
- const usage = this.getMemoryUsage();
475
-
476
- if (usage.heapUsed > this.options.warningThresholdMB) {
477
- console.log(`๐Ÿง  Pre-command memory optimization (${usage.heapUsed}MB)`);
478
- await this.optimizeMemory();
479
- }
480
- }
481
-
482
- /**
483
- * Cleanup method
484
- */
485
- cleanup() {
486
- if (this.gcTimer) {
487
- clearInterval(this.gcTimer);
488
- }
489
-
490
- if (this.memoryMonitorTimer) {
491
- clearInterval(this.memoryMonitorTimer);
492
- }
493
-
494
- console.log('๐Ÿง  Memory Optimizer cleaned up');
495
- }
496
- }
497
-
498
- // Export for Claude Code hook integration
499
- export default MemoryOptimizer;
500
-
501
- // CLI execution
502
- if (process.argv[1] === new URL(import.meta.url).pathname) {
503
- const optimizer = new MemoryOptimizer();
504
-
505
- console.log('๐Ÿง  Memory Optimizer running...');
506
- console.log('Press Ctrl+C to exit');
507
-
508
- // Keep process alive for monitoring
509
- process.stdin.resume();
510
- }