oneie 1.3.2 → 1.3.4
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/.claude/agents/engineering-architect.md +39 -56
- package/.claude/agents/engineering-developer.md +37 -57
- package/.claude/agents/engineering-director.md +37 -144
- package/.claude/agents/engineering-ingestor.md +229 -0
- package/.claude/agents/engineering-quality-assurance.md +40 -206
- package/.claude/agents/engineering-user-experience.md +36 -207
- package/.claude/agents/improver.md +454 -0
- package/.claude/agents/marketing-brand-identity.md +37 -48
- package/.claude/agents/marketing-director.md +9 -0
- package/.claude/agents/one-orchestrator.md +50 -136
- package/.claude/agents/story-teller.md +10 -0
- package/.claude/agents/task-master.md +10 -0
- package/.claude/agents/turbo-repo-builder.md +51 -0
- package/.claude/claude-code-hooks.json +20 -233
- package/.claude/commands/agent-balance +111 -0
- package/.claude/commands/agent.md +24 -7
- package/.claude/commands/cascade-status.md +128 -0
- package/.claude/commands/ingest.md +290 -0
- package/.claude/commands/ingestor.md +136 -0
- package/.claude/commands/mission.md +26 -8
- package/.claude/commands/one.md +351 -14
- package/.claude/commands/quality-check.md +204 -0
- package/.claude/commands/smart-route.md +220 -0
- package/.claude/commands/start.md +9 -8
- package/.claude/commands/story.md +18 -3
- package/.claude/commands/task.md +22 -1
- package/.claude/settings.local.json +19 -3
- package/.obsidian/core-plugins.json +3 -1
- package/.one/checklists/agent-quality-checklist.md +24 -15
- package/.one/checklists/story-quality-checklist.md +24 -15
- package/.one/checklists/task-quality-checklist.md +24 -15
- package/.one/templates/bun-workspace-guide-template.md +188 -0
- package/.one/templates/bunfig-template.toml +95 -0
- package/.one/templates/root-package-template.json +37 -21
- package/.one/templates/turbo-config-template.json +18 -3
- package/.one/tools/bump-core-version.js +0 -0
- package/.one/tools/bump-expansion-version.js +0 -0
- package/.one/tools/code-generators.js +0 -0
- package/.one/tools/compression-engine.js +638 -0
- package/.one/tools/content-deduplicator.js +336 -0
- package/.one/tools/convert-wav-to-mp3.js +0 -0
- package/.one/tools/foundation-wizard.js +0 -0
- package/.one/tools/generate-toc.js +0 -0
- package/.one/tools/ingestor/cascade-integration.js +523 -0
- package/.one/tools/ingestor/cli.ts +234 -0
- package/.one/tools/ingestor/context-mapper.ts +604 -0
- package/.one/tools/ingestor/error-handling-monitor.js +742 -0
- package/.one/tools/ingestor/file-discovery.ts +484 -0
- package/.one/tools/ingestor/file-transformer.ts +524 -0
- package/.one/tools/ingestor/ingestor-orchestrator.ts +416 -0
- package/.one/tools/ingestor/package.json +47 -0
- package/.one/tools/ingestor/usage-examples.md +458 -0
- package/.one/tools/lazy-loader.js +489 -0
- package/.one/tools/minimal-generators.js +0 -0
- package/.one/tools/performance-benchmark.js +300 -0
- package/.one/tools/premium-manager.js +0 -0
- package/.one/tools/semantic-release-sync-installer.js +0 -0
- package/.one/tools/size-memory-optimizer.js +475 -0
- package/.one/tools/sync-installer-version.js +0 -0
- package/.one/tools/text-to-speech.js +0 -0
- package/.one/tools/transformative-ai-engine.js +0 -0
- package/.one/workflows/safe-improvement-deployment.yaml +420 -0
- package/CLAUDE.md +30 -0
- package/README.md +43 -12
- package/bin/oneie/index.js +4 -4
- package/one/cache/benchmark-results.json +43 -0
- package/one/cache/file-index.json +12480 -0
- package/one/config/agent-routing.yaml +124 -0
- package/one/config/agent-skills.yaml +451 -0
- package/one/config/cache-config.yaml +304 -0
- package/one/config/feedback-templates.yaml +152 -0
- package/one/config/performance-config.yaml +281 -0
- package/one/config/quality-automation.yaml +405 -0
- package/one/config/routing-logic.yaml +292 -0
- package/one/data/task-registry.yaml +224 -0
- package/one/stories/story-1.10-parallel-task-execution-orchestration.md +119 -0
- package/one/stories/story-3.1-external-repository-foundation.md +374 -0
- package/one/stories/story-3.2-3-levels-architecture-integration.md +449 -0
- package/one/stories/story-3.3-multi-platform-application-development.md +677 -0
- package/one/stories/story-3.4-shared-package-system-ui-components.md +854 -0
- package/one/stories/story-3.5-backend-integration-production-deployment.md +1034 -0
- package/one/tasks/task-1.10.1-design-parallel-execution-architecture.md +108 -0
- package/one/tasks/task-1.10.2-create-task-dependency-mapping-system.md +82 -0
- package/one/tasks/task-1.10.3-build-agent-spawning-orchestration-engine.md +120 -0
- package/one/tasks/task-1.10.4-implement-task-queue-dependency-resolution.md +125 -0
- package/one/tasks/task-1.10.5-create-task-numbering-convention-system.md +542 -0
- package/one/tasks/task-3.1.1-external-repository-creation.md +303 -0
- package/one/tasks/task-3.1.2-turborepo-configuration-optimization.md +402 -0
- package/one/tasks/task-3.1.3-shared-configuration-packages.md +571 -0
- package/one/tasks/task-3.1.4-bun-package-management-optimization.md +627 -0
- package/one/tools/task-numbering-validator.js +429 -0
- package/package.json +1 -1
- package/quality-gate-optimization-analysis.md +260 -0
- package/turbo-benchmark.js +268 -0
- package/turbo-optimization-guide.md +163 -0
- package/turbo-workspace-template.json +83 -0
- package/turbo.json +178 -0
- package/.claude/commands/analyst.md +0 -70
- package/.claude/commands/architect.md +0 -67
- package/.claude/commands/commander.md +0 -78
- package/.claude/commands/deploy.md +0 -68
- package/.claude/commands/dev.md +0 -60
- package/.claude/commands/playbook.md +0 -81
- package/.claude/commands/pm.md +0 -64
- package/.claude/commands/po.md +0 -68
- package/.claude/commands/qa.md +0 -59
- package/.claude/commands/taskmaster.md +0 -85
- package/.claude/commands/ux-expert.md +0 -58
- package/.one/stories/bullstamp-attract-module-complete.md +0 -255
- package/.one/stories/bullstamp-deployment-master-plan.md +0 -518
- package/.one/stories/bullstamp-executive-implementation-summary.md +0 -254
- package/.one/stories/bullstamp-project-status-complete.md +0 -257
- package/.one/stories/obsidian-pandoc-config.md +0 -159
- package/.one/stories/story-1.1-perfect-filesystem-organization.md +0 -270
- package/.one/stories/story-1.1.1.md +0 -136
- package/.one/stories/story-1.1.md +0 -131
- package/.one/stories/story-1.2.md +0 -420
- package/.one/stories/story-1.3.md +0 -177
- package/.one/stories/story-1.4.md +0 -356
- package/.one/stories/story-1.5.md +0 -572
- package/.one/stories/story-1.6.md +0 -481
- package/.one/stories/story-1.7.md +0 -923
- package/.one/stories/story-1.8.md +0 -404
- package/.one/stories/story-2.0.md +0 -132
- package/.one/stories/story-2.1.md +0 -110
- package/.one/stories/story-2.2.md +0 -110
- package/.one/stories/story-2.3.md +0 -112
- package/.one/stories/story-2.4.md +0 -116
- package/.one/stories/story-2.5.md +0 -114
- package/.one/stories/story-3.1.md +0 -298
- package/.one/stories/story-3.10.md +0 -302
- package/.one/stories/story-3.11.md +0 -167
- package/.one/stories/story-3.12.md +0 -235
- package/.one/stories/story-3.13.md +0 -235
- package/.one/stories/story-3.14.md +0 -225
- package/.one/stories/story-3.15.md +0 -238
- package/.one/stories/story-3.16.md +0 -244
- package/.one/stories/story-3.17.md +0 -245
- package/.one/stories/story-3.18.md +0 -248
- package/.one/stories/story-3.2.md +0 -226
- package/.one/stories/story-3.3.md +0 -226
- package/.one/stories/story-3.4.md +0 -226
- package/.one/stories/story-3.5.md +0 -167
- package/.one/stories/story-3.6.md +0 -167
- package/.one/stories/story-3.7.md +0 -181
- package/.one/stories/story-3.8.md +0 -198
- package/.one/stories/story-3.9.md +0 -169
- package/.one/stories/story-4.1.md +0 -245
- package/.one/stories/story-4.2.md +0 -314
- package/.one/stories/story-4.3.md +0 -610
- package/.one/stories/story-4.4.md +0 -931
- package/.one/stories/story-4.5.md +0 -727
- package/.one/stories/story-4.6-consistency.md +0 -175
- package/.one/stories/story-5.1.md +0 -508
- package/.one/stories/story-5.2.md +0 -451
- package/.one/stories/story-5.3.md +0 -405
- package/.one/stories/story-5.4.md +0 -447
- package/.one/stories/story-5.5.md +0 -349
- package/.one/stories/story-5.6.md +0 -445
- package/.one/stories/story-6.1-text-content-engine.md +0 -144
- package/.one/stories/story-6.2-audio-content-engine.md +0 -145
- package/.one/stories/story-6.3-video-content-engine.md +0 -145
- package/.one/stories/story-6.4-visual-content-engine.md +0 -177
- package/.one/stories/story-6.5-cross-platform-distribution.md +0 -188
- package/.one/stories/story-6.6.ai-content-generation-pipeline.md +0 -196
- package/.one/stories/story-6.7-character-consistency-quality-control.md +0 -216
- package/.one/stories/story-6.8-claude-code-content-integration.md +0 -181
- package/.one/stories/story-6.8-content-production-workflows.md +0 -247
- package/.one/stories/story-7.1-implementation.md +0 -128
- package/.one/stories/story-7.1.md +0 -203
- package/.one/stories/story-7.2-implementation.md +0 -147
- package/.one/stories/story-7.2.md +0 -415
- package/.one/stories/story-7.3-implementation.md +0 -159
- package/.one/stories/story-7.3.md +0 -463
- package/.one/stories/story-7.4-implementation.md +0 -154
- package/.one/stories/story-7.4.md +0 -500
- package/.one/stories/story-validation-report.md +0 -169
- package/one/archive-index.json +0 -91
- /package/one/stories/{story-3.1-npx-oneie-turbo-enhancement.md → story-2.1.1-npx-oneie-turbo-enhancement.md} +0 -0
- /package/one/stories/{story-3.2-npx-connection-implementation.md → story-2.21-npx-connection-implementation.md} +0 -0
|
@@ -0,0 +1,489 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Lazy Loading System - ONE Framework
|
|
5
|
+
*
|
|
6
|
+
* Reduces startup time from 30+ seconds to <10 seconds by:
|
|
7
|
+
* 1. Loading only critical path items immediately (<3 seconds)
|
|
8
|
+
* 2. Indexing and caching 2,639+ markdown files efficiently
|
|
9
|
+
* 3. Background loading non-critical components
|
|
10
|
+
* 4. Optimizing module resolution for 206M node_modules
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { promises as fs } from 'fs';
|
|
14
|
+
import path from 'path';
|
|
15
|
+
import crypto from 'crypto';
|
|
16
|
+
import { fileURLToPath } from 'url';
|
|
17
|
+
|
|
18
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
19
|
+
const __dirname = path.dirname(__filename);
|
|
20
|
+
|
|
21
|
+
class LazyLoader {
|
|
22
|
+
constructor() {
|
|
23
|
+
this.cache = new Map();
|
|
24
|
+
this.loadingPromises = new Map();
|
|
25
|
+
this.criticalPaths = [
|
|
26
|
+
'.claude/agents/mission-commander.md',
|
|
27
|
+
'.claude/agents/story-teller.md',
|
|
28
|
+
'.claude/agents/task-master.md',
|
|
29
|
+
'.claude/commands/one.md',
|
|
30
|
+
'one/config/core-config.yaml',
|
|
31
|
+
'.one/workflows/cascade-workflow-implementation.yaml'
|
|
32
|
+
];
|
|
33
|
+
this.fileIndex = null;
|
|
34
|
+
this.indexCache = path.join(__dirname, '../../one/cache/file-index.json');
|
|
35
|
+
this.backgroundLoading = false;
|
|
36
|
+
this.startTime = Date.now();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Phase 1: Critical Path Loading (<3 seconds)
|
|
41
|
+
* Load only essential files for basic functionality
|
|
42
|
+
*/
|
|
43
|
+
async loadCriticalPath() {
|
|
44
|
+
console.log('🚀 Loading critical path...');
|
|
45
|
+
const startTime = Date.now();
|
|
46
|
+
|
|
47
|
+
const criticalPromises = this.criticalPaths.map(async (filePath) => {
|
|
48
|
+
try {
|
|
49
|
+
const fullPath = path.resolve(filePath);
|
|
50
|
+
const content = await fs.readFile(fullPath, 'utf8');
|
|
51
|
+
this.cache.set(filePath, {
|
|
52
|
+
content,
|
|
53
|
+
loaded: Date.now(),
|
|
54
|
+
size: content.length,
|
|
55
|
+
critical: true
|
|
56
|
+
});
|
|
57
|
+
return { path: filePath, status: 'loaded', size: content.length };
|
|
58
|
+
} catch (error) {
|
|
59
|
+
console.warn(`⚠️ Critical file not found: ${filePath}`);
|
|
60
|
+
return { path: filePath, status: 'missing', error: error.message };
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const results = await Promise.all(criticalPromises);
|
|
65
|
+
const loadTime = Date.now() - startTime;
|
|
66
|
+
|
|
67
|
+
console.log(`✅ Critical path loaded in ${loadTime}ms`);
|
|
68
|
+
console.log(`📄 ${results.filter(r => r.status === 'loaded').length}/${results.length} critical files loaded`);
|
|
69
|
+
|
|
70
|
+
return results;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Phase 2: File System Index (<7 seconds total)
|
|
75
|
+
* Create searchable index of all markdown files without loading content
|
|
76
|
+
*/
|
|
77
|
+
async buildFileIndex() {
|
|
78
|
+
console.log('📇 Building file index...');
|
|
79
|
+
const indexStartTime = Date.now();
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
// Try to load existing index first
|
|
83
|
+
const cachedIndex = await this.loadCachedIndex();
|
|
84
|
+
if (cachedIndex && this.isIndexFresh(cachedIndex)) {
|
|
85
|
+
this.fileIndex = cachedIndex;
|
|
86
|
+
console.log(`✅ Loaded cached index with ${Object.keys(cachedIndex.files).length} files in ${Date.now() - indexStartTime}ms`);
|
|
87
|
+
return cachedIndex;
|
|
88
|
+
}
|
|
89
|
+
} catch (error) {
|
|
90
|
+
console.log('📇 Building fresh index...');
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Build fresh index
|
|
94
|
+
const files = {};
|
|
95
|
+
const directories = ['.claude', '.one', 'one', 'book'];
|
|
96
|
+
|
|
97
|
+
const indexPromises = directories.map(async (dir) => {
|
|
98
|
+
try {
|
|
99
|
+
return await this.indexDirectory(dir, files);
|
|
100
|
+
} catch (error) {
|
|
101
|
+
console.warn(`⚠️ Could not index directory: ${dir}`);
|
|
102
|
+
return 0;
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
const fileCounts = await Promise.all(indexPromises);
|
|
107
|
+
const totalFiles = fileCounts.reduce((sum, count) => sum + count, 0);
|
|
108
|
+
|
|
109
|
+
this.fileIndex = {
|
|
110
|
+
files,
|
|
111
|
+
buildTime: Date.now(),
|
|
112
|
+
totalFiles,
|
|
113
|
+
version: '1.0.0',
|
|
114
|
+
checksum: this.generateIndexChecksum(files)
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
// Cache the index
|
|
118
|
+
await this.cacheIndex(this.fileIndex);
|
|
119
|
+
|
|
120
|
+
const indexTime = Date.now() - indexStartTime;
|
|
121
|
+
console.log(`✅ File index built: ${totalFiles} files in ${indexTime}ms`);
|
|
122
|
+
|
|
123
|
+
return this.fileIndex;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Recursively index a directory for markdown files
|
|
128
|
+
*/
|
|
129
|
+
async indexDirectory(dirPath, files) {
|
|
130
|
+
let count = 0;
|
|
131
|
+
|
|
132
|
+
try {
|
|
133
|
+
const items = await fs.readdir(dirPath, { withFileTypes: true });
|
|
134
|
+
|
|
135
|
+
const promises = items.map(async (item) => {
|
|
136
|
+
const fullPath = path.join(dirPath, item.name);
|
|
137
|
+
|
|
138
|
+
if (item.isDirectory() && !item.name.startsWith('.') && item.name !== 'node_modules') {
|
|
139
|
+
return await this.indexDirectory(fullPath, files);
|
|
140
|
+
} else if (item.isFile() && item.name.endsWith('.md')) {
|
|
141
|
+
try {
|
|
142
|
+
const stats = await fs.stat(fullPath);
|
|
143
|
+
files[fullPath] = {
|
|
144
|
+
name: item.name,
|
|
145
|
+
path: fullPath,
|
|
146
|
+
size: stats.size,
|
|
147
|
+
modified: stats.mtime.getTime(),
|
|
148
|
+
type: this.getFileType(fullPath),
|
|
149
|
+
priority: this.getFilePriority(fullPath)
|
|
150
|
+
};
|
|
151
|
+
count++;
|
|
152
|
+
} catch (error) {
|
|
153
|
+
// Skip files we can't stat
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return 0;
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
const subcounts = await Promise.all(promises);
|
|
160
|
+
count += subcounts.reduce((sum, subcount) => sum + subcount, 0);
|
|
161
|
+
|
|
162
|
+
} catch (error) {
|
|
163
|
+
console.warn(`⚠️ Error indexing ${dirPath}: ${error.message}`);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return count;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Phase 3: Background Loading (<10 seconds total)
|
|
171
|
+
* Load remaining files in background based on priority
|
|
172
|
+
*/
|
|
173
|
+
async startBackgroundLoading() {
|
|
174
|
+
if (this.backgroundLoading || !this.fileIndex) {
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
this.backgroundLoading = true;
|
|
179
|
+
console.log('🔄 Starting background loading...');
|
|
180
|
+
|
|
181
|
+
// Sort files by priority (high priority first)
|
|
182
|
+
const files = Object.values(this.fileIndex.files)
|
|
183
|
+
.sort((a, b) => b.priority - a.priority);
|
|
184
|
+
|
|
185
|
+
// Load in batches to avoid overwhelming the system
|
|
186
|
+
const batchSize = 10;
|
|
187
|
+
let loadedCount = 0;
|
|
188
|
+
let totalTime = 0;
|
|
189
|
+
|
|
190
|
+
for (let i = 0; i < files.length; i += batchSize) {
|
|
191
|
+
const batch = files.slice(i, i + batchSize);
|
|
192
|
+
const batchStart = Date.now();
|
|
193
|
+
|
|
194
|
+
const batchPromises = batch.map(async (fileInfo) => {
|
|
195
|
+
try {
|
|
196
|
+
if (!this.cache.has(fileInfo.path)) {
|
|
197
|
+
const content = await fs.readFile(fileInfo.path, 'utf8');
|
|
198
|
+
this.cache.set(fileInfo.path, {
|
|
199
|
+
content,
|
|
200
|
+
loaded: Date.now(),
|
|
201
|
+
size: content.length,
|
|
202
|
+
fileInfo
|
|
203
|
+
});
|
|
204
|
+
return true;
|
|
205
|
+
}
|
|
206
|
+
} catch (error) {
|
|
207
|
+
console.warn(`⚠️ Failed to load ${fileInfo.path}: ${error.message}`);
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
return false;
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
const results = await Promise.all(batchPromises);
|
|
214
|
+
const batchTime = Date.now() - batchStart;
|
|
215
|
+
totalTime += batchTime;
|
|
216
|
+
loadedCount += results.filter(Boolean).length;
|
|
217
|
+
|
|
218
|
+
// Log progress every 50 files
|
|
219
|
+
if (loadedCount % 50 === 0) {
|
|
220
|
+
console.log(`📄 Background loaded: ${loadedCount}/${files.length} files (${Math.round(totalTime/1000)}s)`);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// Yield control to prevent blocking
|
|
224
|
+
await new Promise(resolve => setTimeout(resolve, 1));
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
console.log(`✅ Background loading complete: ${loadedCount} files in ${Math.round(totalTime/1000)}s`);
|
|
228
|
+
|
|
229
|
+
const totalStartupTime = Date.now() - this.startTime;
|
|
230
|
+
console.log(`🎉 Total startup time: ${Math.round(totalStartupTime/1000)}s`);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Smart file retrieval with lazy loading
|
|
235
|
+
*/
|
|
236
|
+
async getFile(filePath) {
|
|
237
|
+
// Check cache first
|
|
238
|
+
if (this.cache.has(filePath)) {
|
|
239
|
+
return this.cache.get(filePath);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
// Check if already loading
|
|
243
|
+
if (this.loadingPromises.has(filePath)) {
|
|
244
|
+
return await this.loadingPromises.get(filePath);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// Load the file
|
|
248
|
+
const loadPromise = this.loadFile(filePath);
|
|
249
|
+
this.loadingPromises.set(filePath, loadPromise);
|
|
250
|
+
|
|
251
|
+
try {
|
|
252
|
+
const result = await loadPromise;
|
|
253
|
+
this.loadingPromises.delete(filePath);
|
|
254
|
+
return result;
|
|
255
|
+
} catch (error) {
|
|
256
|
+
this.loadingPromises.delete(filePath);
|
|
257
|
+
throw error;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Load a single file and cache it
|
|
263
|
+
*/
|
|
264
|
+
async loadFile(filePath) {
|
|
265
|
+
try {
|
|
266
|
+
const content = await fs.readFile(filePath, 'utf8');
|
|
267
|
+
const cached = {
|
|
268
|
+
content,
|
|
269
|
+
loaded: Date.now(),
|
|
270
|
+
size: content.length,
|
|
271
|
+
fileInfo: this.fileIndex?.files[filePath]
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
this.cache.set(filePath, cached);
|
|
275
|
+
return cached;
|
|
276
|
+
} catch (error) {
|
|
277
|
+
console.warn(`⚠️ Failed to load file ${filePath}: ${error.message}`);
|
|
278
|
+
throw error;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Search files efficiently using the index
|
|
284
|
+
*/
|
|
285
|
+
searchFiles(query, options = {}) {
|
|
286
|
+
if (!this.fileIndex) {
|
|
287
|
+
return [];
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
const {
|
|
291
|
+
type = null,
|
|
292
|
+
minPriority = 0,
|
|
293
|
+
limit = 50,
|
|
294
|
+
sortBy = 'priority'
|
|
295
|
+
} = options;
|
|
296
|
+
|
|
297
|
+
const results = Object.values(this.fileIndex.files)
|
|
298
|
+
.filter(file => {
|
|
299
|
+
// Basic text search
|
|
300
|
+
if (query && !file.name.toLowerCase().includes(query.toLowerCase()) &&
|
|
301
|
+
!file.path.toLowerCase().includes(query.toLowerCase())) {
|
|
302
|
+
return false;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// Type filter
|
|
306
|
+
if (type && file.type !== type) {
|
|
307
|
+
return false;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// Priority filter
|
|
311
|
+
if (file.priority < minPriority) {
|
|
312
|
+
return false;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
return true;
|
|
316
|
+
})
|
|
317
|
+
.sort((a, b) => {
|
|
318
|
+
if (sortBy === 'priority') return b.priority - a.priority;
|
|
319
|
+
if (sortBy === 'modified') return b.modified - a.modified;
|
|
320
|
+
if (sortBy === 'name') return a.name.localeCompare(b.name);
|
|
321
|
+
return 0;
|
|
322
|
+
})
|
|
323
|
+
.slice(0, limit);
|
|
324
|
+
|
|
325
|
+
return results;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Get file type based on path
|
|
330
|
+
*/
|
|
331
|
+
getFileType(filePath) {
|
|
332
|
+
if (filePath.includes('/.claude/agents/')) return 'agent';
|
|
333
|
+
if (filePath.includes('/.claude/commands/')) return 'command';
|
|
334
|
+
if (filePath.includes('/.one/workflows/')) return 'workflow';
|
|
335
|
+
if (filePath.includes('/.one/templates/')) return 'template';
|
|
336
|
+
if (filePath.includes('/one/missions/')) return 'mission';
|
|
337
|
+
if (filePath.includes('/one/stories/')) return 'story';
|
|
338
|
+
if (filePath.includes('/one/tasks/')) return 'task';
|
|
339
|
+
if (filePath.includes('/one/playbooks/')) return 'playbook';
|
|
340
|
+
if (filePath.includes('/book/')) return 'documentation';
|
|
341
|
+
return 'content';
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Get file priority for loading order
|
|
346
|
+
*/
|
|
347
|
+
getFilePriority(filePath) {
|
|
348
|
+
// Critical system files
|
|
349
|
+
if (this.criticalPaths.includes(filePath)) return 100;
|
|
350
|
+
|
|
351
|
+
// Core agents and commands
|
|
352
|
+
if (filePath.includes('/.claude/agents/') || filePath.includes('/.claude/commands/')) return 90;
|
|
353
|
+
|
|
354
|
+
// Workflows and templates
|
|
355
|
+
if (filePath.includes('/.one/workflows/') || filePath.includes('/.one/templates/')) return 80;
|
|
356
|
+
|
|
357
|
+
// Active missions and stories
|
|
358
|
+
if (filePath.includes('/one/missions/') || filePath.includes('/one/stories/')) return 70;
|
|
359
|
+
|
|
360
|
+
// Configuration files
|
|
361
|
+
if (filePath.includes('config') || filePath.includes('.yaml') || filePath.includes('.yml')) return 60;
|
|
362
|
+
|
|
363
|
+
// Tasks and playbooks
|
|
364
|
+
if (filePath.includes('/one/tasks/') || filePath.includes('/one/playbooks/')) return 50;
|
|
365
|
+
|
|
366
|
+
// Documentation
|
|
367
|
+
if (filePath.includes('/book/') || filePath.includes('README')) return 40;
|
|
368
|
+
|
|
369
|
+
// Everything else
|
|
370
|
+
return 30;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* Cache management
|
|
375
|
+
*/
|
|
376
|
+
async loadCachedIndex() {
|
|
377
|
+
try {
|
|
378
|
+
await fs.mkdir(path.dirname(this.indexCache), { recursive: true });
|
|
379
|
+
const data = await fs.readFile(this.indexCache, 'utf8');
|
|
380
|
+
return JSON.parse(data);
|
|
381
|
+
} catch (error) {
|
|
382
|
+
return null;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
async cacheIndex(index) {
|
|
387
|
+
try {
|
|
388
|
+
await fs.mkdir(path.dirname(this.indexCache), { recursive: true });
|
|
389
|
+
await fs.writeFile(this.indexCache, JSON.stringify(index, null, 2));
|
|
390
|
+
} catch (error) {
|
|
391
|
+
console.warn(`⚠️ Could not cache index: ${error.message}`);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
isIndexFresh(cachedIndex, maxAgeMs = 3600000) { // 1 hour default
|
|
396
|
+
return cachedIndex.buildTime && (Date.now() - cachedIndex.buildTime) < maxAgeMs;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
generateIndexChecksum(files) {
|
|
400
|
+
const hash = crypto.createHash('md5');
|
|
401
|
+
const keys = Object.keys(files).sort();
|
|
402
|
+
for (const key of keys) {
|
|
403
|
+
hash.update(`${key}:${files[key].modified}:${files[key].size}`);
|
|
404
|
+
}
|
|
405
|
+
return hash.digest('hex');
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* Performance monitoring and stats
|
|
410
|
+
*/
|
|
411
|
+
getStats() {
|
|
412
|
+
const totalFiles = this.fileIndex ? this.fileIndex.totalFiles : 0;
|
|
413
|
+
const loadedFiles = this.cache.size;
|
|
414
|
+
const cacheSize = Array.from(this.cache.values())
|
|
415
|
+
.reduce((sum, item) => sum + item.size, 0);
|
|
416
|
+
|
|
417
|
+
return {
|
|
418
|
+
totalFiles,
|
|
419
|
+
loadedFiles,
|
|
420
|
+
cacheHitRate: loadedFiles / Math.max(totalFiles, 1),
|
|
421
|
+
cacheSize: Math.round(cacheSize / 1024) + 'KB',
|
|
422
|
+
uptime: Date.now() - this.startTime,
|
|
423
|
+
backgroundLoading: this.backgroundLoading
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* Memory management
|
|
429
|
+
*/
|
|
430
|
+
clearCache(type = null) {
|
|
431
|
+
if (!type) {
|
|
432
|
+
this.cache.clear();
|
|
433
|
+
console.log('🧹 Cache cleared');
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
let cleared = 0;
|
|
438
|
+
for (const [key, value] of this.cache.entries()) {
|
|
439
|
+
if (value.fileInfo && value.fileInfo.type === type) {
|
|
440
|
+
this.cache.delete(key);
|
|
441
|
+
cleared++;
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
console.log(`🧹 Cleared ${cleared} ${type} files from cache`);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* Main initialization method
|
|
449
|
+
*/
|
|
450
|
+
async initialize() {
|
|
451
|
+
console.log('🚀 Initializing Lazy Loader...');
|
|
452
|
+
|
|
453
|
+
try {
|
|
454
|
+
// Phase 1: Critical path (target: <3 seconds)
|
|
455
|
+
await this.loadCriticalPath();
|
|
456
|
+
|
|
457
|
+
// Phase 2: File index (target: <7 seconds total)
|
|
458
|
+
await this.buildFileIndex();
|
|
459
|
+
|
|
460
|
+
// Phase 3: Background loading (target: <10 seconds total)
|
|
461
|
+
this.startBackgroundLoading(); // Don't await - runs in background
|
|
462
|
+
|
|
463
|
+
const initTime = Date.now() - this.startTime;
|
|
464
|
+
console.log(`✅ Lazy Loader initialized in ${initTime}ms`);
|
|
465
|
+
|
|
466
|
+
return true;
|
|
467
|
+
} catch (error) {
|
|
468
|
+
console.error('❌ Lazy Loader initialization failed:', error);
|
|
469
|
+
return false;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// Export for module usage
|
|
475
|
+
export default LazyLoader;
|
|
476
|
+
|
|
477
|
+
// CLI usage
|
|
478
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
479
|
+
const loader = new LazyLoader();
|
|
480
|
+
|
|
481
|
+
loader.initialize().then(success => {
|
|
482
|
+
if (success) {
|
|
483
|
+
console.log('\n📊 Startup Complete!');
|
|
484
|
+
console.log(JSON.stringify(loader.getStats(), null, 2));
|
|
485
|
+
} else {
|
|
486
|
+
process.exit(1);
|
|
487
|
+
}
|
|
488
|
+
});
|
|
489
|
+
}
|
|
File without changes
|