mycontext-cli 1.0.94 → 2.0.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.
- package/README.md +446 -130
- package/dist/agents/implementations/ClaudeAgentWorkflow.d.ts +110 -0
- package/dist/agents/implementations/ClaudeAgentWorkflow.d.ts.map +1 -0
- package/dist/agents/implementations/ClaudeAgentWorkflow.js +590 -0
- package/dist/agents/implementations/ClaudeAgentWorkflow.js.map +1 -0
- package/dist/agents/implementations/WorkflowAgent.d.ts +5 -0
- package/dist/agents/implementations/WorkflowAgent.d.ts.map +1 -1
- package/dist/agents/implementations/WorkflowAgent.js +98 -10
- package/dist/agents/implementations/WorkflowAgent.js.map +1 -1
- package/dist/agents/interfaces/SubAgent.d.ts +5 -0
- package/dist/agents/interfaces/SubAgent.d.ts.map +1 -1
- package/dist/commands/build-app.d.ts +5 -0
- package/dist/commands/build-app.d.ts.map +1 -1
- package/dist/commands/build-app.js +127 -4
- package/dist/commands/build-app.js.map +1 -1
- package/dist/commands/compile-prd.d.ts.map +1 -1
- package/dist/commands/compile-prd.js +18 -54
- package/dist/commands/compile-prd.js.map +1 -1
- package/dist/commands/enhance.d.ts +21 -0
- package/dist/commands/enhance.d.ts.map +1 -1
- package/dist/commands/enhance.js +155 -12
- package/dist/commands/enhance.js.map +1 -1
- package/dist/commands/generate-components.d.ts +43 -0
- package/dist/commands/generate-components.d.ts.map +1 -1
- package/dist/commands/generate-components.js +270 -0
- package/dist/commands/generate-components.js.map +1 -1
- package/dist/constants/fileNames.d.ts +68 -0
- package/dist/constants/fileNames.d.ts.map +1 -0
- package/dist/constants/fileNames.js +102 -0
- package/dist/constants/fileNames.js.map +1 -0
- package/dist/interfaces/AIClient.d.ts +198 -0
- package/dist/interfaces/AIClient.d.ts.map +1 -0
- package/dist/interfaces/AIClient.js +40 -0
- package/dist/interfaces/AIClient.js.map +1 -0
- package/dist/package.json +5 -3
- package/dist/types/index.d.ts +423 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/agentDefinitions.d.ts +60 -0
- package/dist/utils/agentDefinitions.d.ts.map +1 -0
- package/dist/utils/agentDefinitions.js +344 -0
- package/dist/utils/agentDefinitions.js.map +1 -0
- package/dist/utils/aiClientFactory.d.ts +93 -0
- package/dist/utils/aiClientFactory.d.ts.map +1 -0
- package/dist/utils/aiClientFactory.js +290 -0
- package/dist/utils/aiClientFactory.js.map +1 -0
- package/dist/utils/aiClientRouter.d.ts +121 -0
- package/dist/utils/aiClientRouter.d.ts.map +1 -0
- package/dist/utils/aiClientRouter.js +401 -0
- package/dist/utils/aiClientRouter.js.map +1 -0
- package/dist/utils/claudeAgentClient.d.ts +166 -0
- package/dist/utils/claudeAgentClient.d.ts.map +1 -0
- package/dist/utils/claudeAgentClient.js +714 -0
- package/dist/utils/claudeAgentClient.js.map +1 -0
- package/dist/utils/claudeClient.d.ts +7 -3
- package/dist/utils/claudeClient.d.ts.map +1 -1
- package/dist/utils/claudeClient.js +28 -5
- package/dist/utils/claudeClient.js.map +1 -1
- package/dist/utils/completeArchitectureEngine.d.ts +67 -0
- package/dist/utils/completeArchitectureEngine.d.ts.map +1 -0
- package/dist/utils/completeArchitectureEngine.js +329 -0
- package/dist/utils/completeArchitectureEngine.js.map +1 -0
- package/dist/utils/contextLoader.d.ts +1 -12
- package/dist/utils/contextLoader.d.ts.map +1 -1
- package/dist/utils/contextLoader.js +29 -150
- package/dist/utils/contextLoader.js.map +1 -1
- package/dist/utils/contextManager.d.ts +76 -0
- package/dist/utils/contextManager.d.ts.map +1 -0
- package/dist/utils/contextManager.js +327 -0
- package/dist/utils/contextManager.js.map +1 -0
- package/dist/utils/hybridAIClient.d.ts +25 -1
- package/dist/utils/hybridAIClient.d.ts.map +1 -1
- package/dist/utils/hybridAIClient.js +69 -2
- package/dist/utils/hybridAIClient.js.map +1 -1
- package/dist/utils/mcpAgentIntegration.d.ts +104 -0
- package/dist/utils/mcpAgentIntegration.d.ts.map +1 -0
- package/dist/utils/mcpAgentIntegration.js +382 -0
- package/dist/utils/mcpAgentIntegration.js.map +1 -0
- package/dist/utils/mcpTools.d.ts +164 -0
- package/dist/utils/mcpTools.d.ts.map +1 -0
- package/dist/utils/mcpTools.js +385 -0
- package/dist/utils/mcpTools.js.map +1 -0
- package/dist/utils/routeGenerator.d.ts +56 -0
- package/dist/utils/routeGenerator.d.ts.map +1 -0
- package/dist/utils/routeGenerator.js +231 -0
- package/dist/utils/routeGenerator.js.map +1 -0
- package/dist/utils/serverActionGenerator.d.ts +56 -0
- package/dist/utils/serverActionGenerator.d.ts.map +1 -0
- package/dist/utils/serverActionGenerator.js +258 -0
- package/dist/utils/serverActionGenerator.js.map +1 -0
- package/dist/utils/streamingHandler.d.ts +98 -0
- package/dist/utils/streamingHandler.d.ts.map +1 -0
- package/dist/utils/streamingHandler.js +259 -0
- package/dist/utils/streamingHandler.js.map +1 -0
- package/dist/utils/toolPermissions.d.ts +105 -0
- package/dist/utils/toolPermissions.d.ts.map +1 -0
- package/dist/utils/toolPermissions.js +408 -0
- package/dist/utils/toolPermissions.js.map +1 -0
- package/package.json +5 -3
|
@@ -42,6 +42,7 @@ exports.getDescriptionFromContext = getDescriptionFromContext;
|
|
|
42
42
|
const fs = __importStar(require("fs-extra"));
|
|
43
43
|
const path = __importStar(require("path"));
|
|
44
44
|
const chalk_1 = __importDefault(require("chalk"));
|
|
45
|
+
const fileNames_1 = require("../constants/fileNames");
|
|
45
46
|
/**
|
|
46
47
|
* Loads project context from .mycontext directory
|
|
47
48
|
* Provides fallback to context/ directory for backward compatibility
|
|
@@ -95,175 +96,53 @@ class ContextLoader {
|
|
|
95
96
|
* Load context from a specific directory
|
|
96
97
|
*/
|
|
97
98
|
async loadFromDirectory(dir, context, verbose) {
|
|
98
|
-
//
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
99
|
+
// Helper function to load a file with variants
|
|
100
|
+
const loadFileWithVariants = async (canonicalName, contextKey, displayName) => {
|
|
101
|
+
const variants = (0, fileNames_1.getAllFileNameVariants)(canonicalName);
|
|
102
|
+
for (const variant of variants) {
|
|
103
|
+
const filePath = path.join(dir, variant);
|
|
104
|
+
if (await fs.pathExists(filePath)) {
|
|
105
|
+
const content = await fs.readFile(filePath, "utf8");
|
|
106
|
+
context[contextKey] = content;
|
|
107
|
+
if (verbose) {
|
|
108
|
+
console.log(chalk_1.default.gray(` 📄 ${displayName}: ${variant}`));
|
|
109
|
+
}
|
|
110
|
+
break;
|
|
106
111
|
}
|
|
107
|
-
break;
|
|
108
112
|
}
|
|
109
|
-
}
|
|
113
|
+
};
|
|
114
|
+
// Load PRD
|
|
115
|
+
await loadFileWithVariants(fileNames_1.CONTEXT_FILES.PRD, "prd", "PRD");
|
|
110
116
|
// Load Types
|
|
111
|
-
|
|
112
|
-
"02-types.ts",
|
|
113
|
-
"types.ts",
|
|
114
|
-
"02_types.ts",
|
|
115
|
-
"types/index.ts",
|
|
116
|
-
];
|
|
117
|
-
for (const candidate of typesCandidates) {
|
|
118
|
-
const typesPath = path.join(dir, candidate);
|
|
119
|
-
if (await fs.pathExists(typesPath)) {
|
|
120
|
-
context.types = await fs.readFile(typesPath, "utf8");
|
|
121
|
-
if (verbose) {
|
|
122
|
-
console.log(chalk_1.default.gray(` 📄 Types: ${candidate}`));
|
|
123
|
-
}
|
|
124
|
-
break;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
117
|
+
await loadFileWithVariants(fileNames_1.CONTEXT_FILES.TYPES, "types", "Types");
|
|
127
118
|
// Load Brand
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
"brand/branding.md",
|
|
134
|
-
];
|
|
135
|
-
for (const candidate of brandCandidates) {
|
|
136
|
-
const brandPath = path.join(dir, candidate);
|
|
137
|
-
if (await fs.pathExists(brandPath)) {
|
|
138
|
-
context.brand = await fs.readFile(brandPath, "utf8");
|
|
139
|
-
if (verbose) {
|
|
140
|
-
console.log(chalk_1.default.gray(` 📄 Brand: ${candidate}`));
|
|
141
|
-
}
|
|
142
|
-
break;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
// Load Component List
|
|
146
|
-
const compListCandidates = [
|
|
147
|
-
"04-component-list.json",
|
|
148
|
-
"component-list.json",
|
|
149
|
-
"04_component_list.json",
|
|
150
|
-
"components-list.json",
|
|
151
|
-
];
|
|
152
|
-
for (const candidate of compListCandidates) {
|
|
153
|
-
const compListPath = path.join(dir, candidate);
|
|
119
|
+
await loadFileWithVariants(fileNames_1.CONTEXT_FILES.BRANDING, "brand", "Brand");
|
|
120
|
+
// Load Component List (JSON)
|
|
121
|
+
const compListVariants = (0, fileNames_1.getAllFileNameVariants)(fileNames_1.CONTEXT_FILES.COMPONENT_LIST);
|
|
122
|
+
for (const variant of compListVariants) {
|
|
123
|
+
const compListPath = path.join(dir, variant);
|
|
154
124
|
if (await fs.pathExists(compListPath)) {
|
|
155
125
|
try {
|
|
156
126
|
const compListRaw = await fs.readFile(compListPath, "utf8");
|
|
157
127
|
context.componentList = JSON.parse(compListRaw);
|
|
158
128
|
if (verbose) {
|
|
159
|
-
console.log(chalk_1.default.gray(` 📄 Component List: ${
|
|
129
|
+
console.log(chalk_1.default.gray(` 📄 Component List: ${variant}`));
|
|
160
130
|
}
|
|
161
131
|
break;
|
|
162
132
|
}
|
|
163
133
|
catch (error) {
|
|
164
|
-
// Invalid JSON, try next
|
|
134
|
+
// Invalid JSON, try next variant
|
|
165
135
|
continue;
|
|
166
136
|
}
|
|
167
137
|
}
|
|
168
138
|
}
|
|
169
|
-
// Load User Stories
|
|
170
|
-
const userStoriesCandidates = [
|
|
171
|
-
"02_user_stories.md",
|
|
172
|
-
"user_stories.md",
|
|
173
|
-
"01a-brief.md",
|
|
174
|
-
"01b-requirements.md",
|
|
175
|
-
];
|
|
176
|
-
for (const candidate of userStoriesCandidates) {
|
|
177
|
-
const userStoriesPath = path.join(dir, candidate);
|
|
178
|
-
if (await fs.pathExists(userStoriesPath)) {
|
|
179
|
-
context.userStories = await fs.readFile(userStoriesPath, "utf8");
|
|
180
|
-
if (verbose) {
|
|
181
|
-
console.log(chalk_1.default.gray(` 📄 User Stories: ${candidate}`));
|
|
182
|
-
}
|
|
183
|
-
break;
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
// Load Technical Specs
|
|
187
|
-
const techSpecsCandidates = [
|
|
188
|
-
"03_technical_specs.md",
|
|
189
|
-
"technical_specs.md",
|
|
190
|
-
"01c-flows.md",
|
|
191
|
-
];
|
|
192
|
-
for (const candidate of techSpecsCandidates) {
|
|
193
|
-
const techSpecsPath = path.join(dir, candidate);
|
|
194
|
-
if (await fs.pathExists(techSpecsPath)) {
|
|
195
|
-
context.technicalSpecs = await fs.readFile(techSpecsPath, "utf8");
|
|
196
|
-
if (verbose) {
|
|
197
|
-
console.log(chalk_1.default.gray(` 📄 Technical Specs: ${candidate}`));
|
|
198
|
-
}
|
|
199
|
-
break;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
139
|
// Load A/B/C/D Context Files
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
"01a_features.md",
|
|
208
|
-
];
|
|
209
|
-
for (const candidate of featuresCandidates) {
|
|
210
|
-
const featuresPath = path.join(dir, candidate);
|
|
211
|
-
if (await fs.pathExists(featuresPath)) {
|
|
212
|
-
context.features = await fs.readFile(featuresPath, "utf8");
|
|
213
|
-
if (verbose) {
|
|
214
|
-
console.log(chalk_1.default.gray(` 📄 Features: ${candidate}`));
|
|
215
|
-
}
|
|
216
|
-
break;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
// Load User Flows (01b-user-flows.md)
|
|
220
|
-
const userFlowsCandidates = [
|
|
221
|
-
"01b-user-flows.md",
|
|
222
|
-
"user-flows.md",
|
|
223
|
-
"01b_user_flows.md",
|
|
224
|
-
];
|
|
225
|
-
for (const candidate of userFlowsCandidates) {
|
|
226
|
-
const userFlowsPath = path.join(dir, candidate);
|
|
227
|
-
if (await fs.pathExists(userFlowsPath)) {
|
|
228
|
-
context.userFlows = await fs.readFile(userFlowsPath, "utf8");
|
|
229
|
-
if (verbose) {
|
|
230
|
-
console.log(chalk_1.default.gray(` 📄 User Flows: ${candidate}`));
|
|
231
|
-
}
|
|
232
|
-
break;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
// Load Edge Cases (01c-edge-cases.md)
|
|
236
|
-
const edgeCasesCandidates = [
|
|
237
|
-
"01c-edge-cases.md",
|
|
238
|
-
"edge-cases.md",
|
|
239
|
-
"01c_edge_cases.md",
|
|
240
|
-
];
|
|
241
|
-
for (const candidate of edgeCasesCandidates) {
|
|
242
|
-
const edgeCasesPath = path.join(dir, candidate);
|
|
243
|
-
if (await fs.pathExists(edgeCasesPath)) {
|
|
244
|
-
context.edgeCases = await fs.readFile(edgeCasesPath, "utf8");
|
|
245
|
-
if (verbose) {
|
|
246
|
-
console.log(chalk_1.default.gray(` 📄 Edge Cases: ${candidate}`));
|
|
247
|
-
}
|
|
248
|
-
break;
|
|
249
|
-
}
|
|
250
|
-
}
|
|
140
|
+
await loadFileWithVariants(fileNames_1.CONTEXT_FILES.FEATURES, "features", "Features");
|
|
141
|
+
await loadFileWithVariants(fileNames_1.CONTEXT_FILES.USER_FLOWS, "userFlows", "User Flows");
|
|
142
|
+
await loadFileWithVariants(fileNames_1.CONTEXT_FILES.EDGE_CASES, "edgeCases", "Edge Cases");
|
|
143
|
+
await loadFileWithVariants(fileNames_1.CONTEXT_FILES.TECHNICAL_SPECS, "technicalSpecs", "Technical Specs");
|
|
251
144
|
// Load Project Structure
|
|
252
|
-
|
|
253
|
-
"05-project-structure.md",
|
|
254
|
-
"project-structure.md",
|
|
255
|
-
"05_project_structure.md",
|
|
256
|
-
];
|
|
257
|
-
for (const candidate of structureCandidates) {
|
|
258
|
-
const structurePath = path.join(dir, candidate);
|
|
259
|
-
if (await fs.pathExists(structurePath)) {
|
|
260
|
-
context.projectStructure = await fs.readFile(structurePath, "utf8");
|
|
261
|
-
if (verbose) {
|
|
262
|
-
console.log(chalk_1.default.gray(` 📄 Project Structure: ${candidate}`));
|
|
263
|
-
}
|
|
264
|
-
break;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
145
|
+
await loadFileWithVariants(fileNames_1.CONTEXT_FILES.PROJECT_STRUCTURE, "projectStructure", "Project Structure");
|
|
267
146
|
}
|
|
268
147
|
/**
|
|
269
148
|
* Get a description from context files, with fallback priority
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"contextLoader.js","sourceRoot":"","sources":["../../src/utils/contextLoader.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"contextLoader.js","sourceRoot":"","sources":["../../src/utils/contextLoader.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiMA,gDAMC;AAKD,8DAMC;AAlND,6CAA+B;AAC/B,2CAA6B;AAC7B,kDAA0B;AAE1B,sDAA+E;AAO/E;;;GAGG;AACH,MAAa,aAAa;IAGxB,YAAY,cAAsB,OAAO,CAAC,GAAG,EAAE;QAC7C,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IACjC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,kBAAkB,CACtB,UAA8B,EAAE;QAEhC,MAAM,OAAO,GAAmB,EAAE,CAAC;QACnC,MAAM,EAAE,OAAO,GAAG,KAAK,EAAE,QAAQ,GAAG,KAAK,EAAE,GAAG,OAAO,CAAC;QAEtD,IAAI,CAAC;YACH,iDAAiD;YACjD,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;YAC/D,IAAI,MAAM,EAAE,CAAC,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;gBACtC,MAAM,IAAI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;QACpD,IAAI,OAAO,CAAC,cAAc;YAAE,KAAK,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;QAC1D,IAAI,OAAO,CAAC,gBAAgB;YAAE,KAAK,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;QAE9D,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,kBAAkB,CAAC;IAClE,CAAC;CACF;AA7KD,sCA6KC;AAED;;GAEG;AACI,KAAK,UAAU,kBAAkB,CACtC,WAAoB,EACpB,OAA4B;IAE5B,MAAM,MAAM,GAAG,IAAI,aAAa,CAAC,WAAW,CAAC,CAAC;IAC9C,OAAO,MAAM,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;AAC5C,CAAC;AAED;;GAEG;AACI,KAAK,UAAU,yBAAyB,CAC7C,WAAoB,EACpB,OAA4B;IAE5B,MAAM,MAAM,GAAG,IAAI,aAAa,CAAC,WAAW,CAAC,CAAC;IAC9C,OAAO,MAAM,CAAC,yBAAyB,CAAC,OAAO,CAAC,CAAC;AACnD,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { ProjectContext } from '../types';
|
|
2
|
+
export type { ProjectContext };
|
|
3
|
+
export interface ContextCompactionOptions {
|
|
4
|
+
maxContextSize?: number;
|
|
5
|
+
preserveRecent?: boolean;
|
|
6
|
+
compressionLevel?: 'low' | 'medium' | 'high';
|
|
7
|
+
}
|
|
8
|
+
export declare class ContextManager {
|
|
9
|
+
private contextDir;
|
|
10
|
+
private contextFile;
|
|
11
|
+
private maxContextSize;
|
|
12
|
+
private compressionLevel;
|
|
13
|
+
constructor(workingDirectory?: string);
|
|
14
|
+
/**
|
|
15
|
+
* Load project context from files and memory
|
|
16
|
+
*/
|
|
17
|
+
loadContext(): Promise<ProjectContext>;
|
|
18
|
+
/**
|
|
19
|
+
* Save context to memory for persistence
|
|
20
|
+
*/
|
|
21
|
+
saveContext(context: ProjectContext): Promise<void>;
|
|
22
|
+
/**
|
|
23
|
+
* Compact context to reduce size while preserving important information
|
|
24
|
+
*/
|
|
25
|
+
compactContext(context: ProjectContext, options?: ContextCompactionOptions): Promise<ProjectContext>;
|
|
26
|
+
/**
|
|
27
|
+
* Merge new context with existing context
|
|
28
|
+
*/
|
|
29
|
+
mergeContext(existingContext: ProjectContext, newContext: Partial<ProjectContext>): Promise<ProjectContext>;
|
|
30
|
+
/**
|
|
31
|
+
* Get context summary for debugging
|
|
32
|
+
*/
|
|
33
|
+
getContextSummary(context: ProjectContext): string;
|
|
34
|
+
/**
|
|
35
|
+
* Clear context memory
|
|
36
|
+
*/
|
|
37
|
+
clearContext(): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Load context from individual files
|
|
40
|
+
*/
|
|
41
|
+
private loadContextFiles;
|
|
42
|
+
/**
|
|
43
|
+
* Load context from memory file
|
|
44
|
+
*/
|
|
45
|
+
private loadMemoryContext;
|
|
46
|
+
/**
|
|
47
|
+
* Calculate context size in bytes
|
|
48
|
+
*/
|
|
49
|
+
private calculateContextSize;
|
|
50
|
+
/**
|
|
51
|
+
* Compress text by removing unnecessary whitespace and comments
|
|
52
|
+
*/
|
|
53
|
+
private compressText;
|
|
54
|
+
/**
|
|
55
|
+
* Preserve only recent outputs
|
|
56
|
+
*/
|
|
57
|
+
private preserveRecentOutputs;
|
|
58
|
+
/**
|
|
59
|
+
* Set context size limits
|
|
60
|
+
*/
|
|
61
|
+
setContextLimits(maxSize: number, compressionLevel: 'low' | 'medium' | 'high'): void;
|
|
62
|
+
/**
|
|
63
|
+
* Get context statistics
|
|
64
|
+
*/
|
|
65
|
+
getContextStats(context: ProjectContext): {
|
|
66
|
+
totalSize: number;
|
|
67
|
+
fileCount: number;
|
|
68
|
+
lastUpdated: string;
|
|
69
|
+
compressionRatio: number;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Calculate original size before compression
|
|
73
|
+
*/
|
|
74
|
+
private calculateOriginalSize;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=contextManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contextManager.d.ts","sourceRoot":"","sources":["../../src/utils/contextManager.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAI1C,YAAY,EAAE,cAAc,EAAE,CAAC;AAE/B,MAAM,WAAW,wBAAwB;IACvC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,gBAAgB,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,CAAC;CAC9C;AAED,qBAAa,cAAc;IACzB,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,gBAAgB,CAA4B;gBAExC,gBAAgB,CAAC,EAAE,MAAM;IAOrC;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,cAAc,CAAC;IAsB5C;;OAEG;IACG,WAAW,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAoBzD;;OAEG;IACG,cAAc,CAClB,OAAO,EAAE,cAAc,EACvB,OAAO,GAAE,wBAA6B,GACrC,OAAO,CAAC,cAAc,CAAC;IA0D1B;;OAEG;IACG,YAAY,CAChB,eAAe,EAAE,cAAc,EAC/B,UAAU,EAAE,OAAO,CAAC,cAAc,CAAC,GAClC,OAAO,CAAC,cAAc,CAAC;IAyB1B;;OAEG;IACH,iBAAiB,CAAC,OAAO,EAAE,cAAc,GAAG,MAAM;IAelD;;OAEG;IACG,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAWnC;;OAEG;YACW,gBAAgB;IAoC9B;;OAEG;YACW,iBAAiB;IAc/B;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAI5B;;OAEG;IACH,OAAO,CAAC,YAAY;IAqBpB;;OAEG;IACH,OAAO,CAAC,qBAAqB;IAY7B;;OAEG;IACH,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,IAAI;IAKpF;;OAEG;IACH,eAAe,CAAC,OAAO,EAAE,cAAc,GAAG;QACxC,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,EAAE,MAAM,CAAC;QAClB,WAAW,EAAE,MAAM,CAAC;QACpB,gBAAgB,EAAE,MAAM,CAAC;KAC1B;IAqBD;;OAEG;IACH,OAAO,CAAC,qBAAqB;CAI9B"}
|
|
@@ -0,0 +1,327 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.ContextManager = void 0;
|
|
40
|
+
const fs = __importStar(require("fs"));
|
|
41
|
+
const path = __importStar(require("path"));
|
|
42
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
43
|
+
const fileNames_1 = require("../constants/fileNames");
|
|
44
|
+
class ContextManager {
|
|
45
|
+
constructor(workingDirectory) {
|
|
46
|
+
this.contextDir = path.join(workingDirectory || process.cwd(), '.mycontext');
|
|
47
|
+
this.contextFile = path.join(this.contextDir, fileNames_1.CONTEXT_FILES.CONTEXT_MEMORY);
|
|
48
|
+
this.maxContextSize = 50000; // Default 50KB context limit
|
|
49
|
+
this.compressionLevel = 'medium';
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Load project context from files and memory
|
|
53
|
+
*/
|
|
54
|
+
async loadContext() {
|
|
55
|
+
const context = {
|
|
56
|
+
workingDirectory: this.contextDir.replace('/.mycontext', ''),
|
|
57
|
+
contextVersion: '1.0',
|
|
58
|
+
lastUpdated: new Date().toISOString(),
|
|
59
|
+
};
|
|
60
|
+
try {
|
|
61
|
+
// Load from context files
|
|
62
|
+
await this.loadContextFiles(context);
|
|
63
|
+
// Load from memory file if exists
|
|
64
|
+
await this.loadMemoryContext(context);
|
|
65
|
+
console.log(chalk_1.default.green('✅ Context loaded successfully'));
|
|
66
|
+
return context;
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
console.log(chalk_1.default.yellow(`⚠️ Context loading warning: ${error.message}`));
|
|
70
|
+
return context;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Save context to memory for persistence
|
|
75
|
+
*/
|
|
76
|
+
async saveContext(context) {
|
|
77
|
+
try {
|
|
78
|
+
// Ensure context directory exists
|
|
79
|
+
if (!fs.existsSync(this.contextDir)) {
|
|
80
|
+
fs.mkdirSync(this.contextDir, { recursive: true });
|
|
81
|
+
}
|
|
82
|
+
// Update metadata
|
|
83
|
+
context.lastUpdated = new Date().toISOString();
|
|
84
|
+
context.contextVersion = context.contextVersion || '1.0';
|
|
85
|
+
// Save to memory file
|
|
86
|
+
fs.writeFileSync(this.contextFile, JSON.stringify(context, null, 2));
|
|
87
|
+
console.log(chalk_1.default.green('✅ Context saved successfully'));
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
console.log(chalk_1.default.red(`❌ Context save failed: ${error.message}`));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Compact context to reduce size while preserving important information
|
|
95
|
+
*/
|
|
96
|
+
async compactContext(context, options = {}) {
|
|
97
|
+
const maxSize = options.maxContextSize || this.maxContextSize;
|
|
98
|
+
const preserveRecent = options.preserveRecent !== false;
|
|
99
|
+
const compressionLevel = options.compressionLevel || this.compressionLevel;
|
|
100
|
+
const compactedContext = { ...context };
|
|
101
|
+
try {
|
|
102
|
+
// Calculate current context size
|
|
103
|
+
const currentSize = this.calculateContextSize(context);
|
|
104
|
+
if (currentSize <= maxSize) {
|
|
105
|
+
console.log(chalk_1.default.green('✅ Context size is within limits'));
|
|
106
|
+
return context;
|
|
107
|
+
}
|
|
108
|
+
console.log(chalk_1.default.yellow(`⚠️ Context size (${currentSize} bytes) exceeds limit (${maxSize} bytes). Compacting...`));
|
|
109
|
+
// Apply compression based on level
|
|
110
|
+
switch (compressionLevel) {
|
|
111
|
+
case 'low':
|
|
112
|
+
compactedContext.prd = this.compressText(context.prd || '', 0.8);
|
|
113
|
+
compactedContext.brand = this.compressText(context.brand || '', 0.8);
|
|
114
|
+
break;
|
|
115
|
+
case 'medium':
|
|
116
|
+
compactedContext.prd = this.compressText(context.prd || '', 0.6);
|
|
117
|
+
compactedContext.brand = this.compressText(context.brand || '', 0.6);
|
|
118
|
+
compactedContext.projectStructure = this.compressText(context.projectStructure || '', 0.7);
|
|
119
|
+
break;
|
|
120
|
+
case 'high':
|
|
121
|
+
compactedContext.prd = this.compressText(context.prd || '', 0.4);
|
|
122
|
+
compactedContext.brand = this.compressText(context.brand || '', 0.4);
|
|
123
|
+
compactedContext.projectStructure = this.compressText(context.projectStructure || '', 0.5);
|
|
124
|
+
compactedContext.types = this.compressText(context.types || '', 0.6);
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
// Preserve recent outputs if requested
|
|
128
|
+
if (preserveRecent && context.previousOutputs) {
|
|
129
|
+
compactedContext.previousOutputs = this.preserveRecentOutputs(context.previousOutputs);
|
|
130
|
+
}
|
|
131
|
+
// Update metadata
|
|
132
|
+
compactedContext.lastUpdated = new Date().toISOString();
|
|
133
|
+
compactedContext.contextVersion = '1.0-compacted';
|
|
134
|
+
const newSize = this.calculateContextSize(compactedContext);
|
|
135
|
+
console.log(chalk_1.default.green(`✅ Context compacted: ${currentSize} → ${newSize} bytes`));
|
|
136
|
+
return compactedContext;
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
console.log(chalk_1.default.red(`❌ Context compaction failed: ${error.message}`));
|
|
140
|
+
return context;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Merge new context with existing context
|
|
145
|
+
*/
|
|
146
|
+
async mergeContext(existingContext, newContext) {
|
|
147
|
+
const mergedContext = {
|
|
148
|
+
...existingContext,
|
|
149
|
+
...newContext,
|
|
150
|
+
lastUpdated: new Date().toISOString(),
|
|
151
|
+
};
|
|
152
|
+
// Merge previous outputs intelligently
|
|
153
|
+
if (existingContext.previousOutputs && newContext.previousOutputs) {
|
|
154
|
+
mergedContext.previousOutputs = {
|
|
155
|
+
...existingContext.previousOutputs,
|
|
156
|
+
...newContext.previousOutputs,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
// Check if compaction is needed
|
|
160
|
+
const size = this.calculateContextSize(mergedContext);
|
|
161
|
+
if (size > this.maxContextSize) {
|
|
162
|
+
console.log(chalk_1.default.yellow('⚠️ Merged context exceeds size limit, compacting...'));
|
|
163
|
+
return await this.compactContext(mergedContext);
|
|
164
|
+
}
|
|
165
|
+
return mergedContext;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Get context summary for debugging
|
|
169
|
+
*/
|
|
170
|
+
getContextSummary(context) {
|
|
171
|
+
const summary = {
|
|
172
|
+
prd: context.prd ? `${context.prd.length} chars` : 'Not loaded',
|
|
173
|
+
types: context.types ? `${context.types.length} chars` : 'Not loaded',
|
|
174
|
+
brand: context.brand ? `${context.brand.length} chars` : 'Not loaded',
|
|
175
|
+
componentList: context.componentList ? `${Object.keys(context.componentList).length} components` : 'Not loaded',
|
|
176
|
+
projectStructure: context.projectStructure ? `${context.projectStructure.length} chars` : 'Not loaded',
|
|
177
|
+
previousOutputs: context.previousOutputs ? `${Object.keys(context.previousOutputs).length} outputs` : 'None',
|
|
178
|
+
totalSize: `${this.calculateContextSize(context)} bytes`,
|
|
179
|
+
lastUpdated: context.lastUpdated || 'Unknown',
|
|
180
|
+
};
|
|
181
|
+
return JSON.stringify(summary, null, 2);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Clear context memory
|
|
185
|
+
*/
|
|
186
|
+
async clearContext() {
|
|
187
|
+
try {
|
|
188
|
+
if (fs.existsSync(this.contextFile)) {
|
|
189
|
+
fs.unlinkSync(this.contextFile);
|
|
190
|
+
console.log(chalk_1.default.green('✅ Context memory cleared'));
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
catch (error) {
|
|
194
|
+
console.log(chalk_1.default.red(`❌ Context clear failed: ${error.message}`));
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Load context from individual files
|
|
199
|
+
*/
|
|
200
|
+
async loadContextFiles(context) {
|
|
201
|
+
const files = [
|
|
202
|
+
{ key: 'prd', file: fileNames_1.CONTEXT_FILES.PRD },
|
|
203
|
+
{ key: 'types', file: fileNames_1.CONTEXT_FILES.TYPES },
|
|
204
|
+
{ key: 'brand', file: fileNames_1.CONTEXT_FILES.BRANDING },
|
|
205
|
+
{ key: 'projectStructure', file: fileNames_1.CONTEXT_FILES.PROJECT_STRUCTURE },
|
|
206
|
+
{ key: 'features', file: fileNames_1.CONTEXT_FILES.FEATURES },
|
|
207
|
+
{ key: 'userFlows', file: fileNames_1.CONTEXT_FILES.USER_FLOWS },
|
|
208
|
+
{ key: 'edgeCases', file: fileNames_1.CONTEXT_FILES.EDGE_CASES },
|
|
209
|
+
{ key: 'technicalSpecs', file: fileNames_1.CONTEXT_FILES.TECHNICAL_SPECS },
|
|
210
|
+
];
|
|
211
|
+
for (const { key, file } of files) {
|
|
212
|
+
const filePath = path.join(this.contextDir, file);
|
|
213
|
+
if (fs.existsSync(filePath)) {
|
|
214
|
+
try {
|
|
215
|
+
const content = fs.readFileSync(filePath, 'utf8');
|
|
216
|
+
context[key] = content;
|
|
217
|
+
}
|
|
218
|
+
catch (error) {
|
|
219
|
+
console.log(chalk_1.default.yellow(`⚠️ Could not load ${file}`));
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
// Load component list
|
|
224
|
+
const componentListPath = path.join(this.contextDir, fileNames_1.CONTEXT_FILES.COMPONENT_LIST);
|
|
225
|
+
if (fs.existsSync(componentListPath)) {
|
|
226
|
+
try {
|
|
227
|
+
const content = fs.readFileSync(componentListPath, 'utf8');
|
|
228
|
+
context.componentList = JSON.parse(content);
|
|
229
|
+
}
|
|
230
|
+
catch (error) {
|
|
231
|
+
console.log(chalk_1.default.yellow('⚠️ Could not load component list'));
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Load context from memory file
|
|
237
|
+
*/
|
|
238
|
+
async loadMemoryContext(context) {
|
|
239
|
+
if (fs.existsSync(this.contextFile)) {
|
|
240
|
+
try {
|
|
241
|
+
const content = fs.readFileSync(this.contextFile, 'utf8');
|
|
242
|
+
const memoryContext = JSON.parse(content);
|
|
243
|
+
// Merge memory context with file context
|
|
244
|
+
Object.assign(context, memoryContext);
|
|
245
|
+
}
|
|
246
|
+
catch (error) {
|
|
247
|
+
console.log(chalk_1.default.yellow('⚠️ Could not load memory context'));
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Calculate context size in bytes
|
|
253
|
+
*/
|
|
254
|
+
calculateContextSize(context) {
|
|
255
|
+
return JSON.stringify(context).length;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Compress text by removing unnecessary whitespace and comments
|
|
259
|
+
*/
|
|
260
|
+
compressText(text, compressionRatio) {
|
|
261
|
+
if (!text)
|
|
262
|
+
return '';
|
|
263
|
+
// Remove excessive whitespace
|
|
264
|
+
let compressed = text.replace(/\s+/g, ' ').trim();
|
|
265
|
+
// Remove comments if compression ratio is high
|
|
266
|
+
if (compressionRatio < 0.7) {
|
|
267
|
+
compressed = compressed.replace(/\/\*[\s\S]*?\*\//g, '');
|
|
268
|
+
compressed = compressed.replace(/\/\/.*$/gm, '');
|
|
269
|
+
}
|
|
270
|
+
// Truncate if still too long
|
|
271
|
+
const targetLength = Math.floor(text.length * compressionRatio);
|
|
272
|
+
if (compressed.length > targetLength) {
|
|
273
|
+
compressed = compressed.substring(0, targetLength) + '...';
|
|
274
|
+
}
|
|
275
|
+
return compressed;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Preserve only recent outputs
|
|
279
|
+
*/
|
|
280
|
+
preserveRecentOutputs(outputs) {
|
|
281
|
+
const sortedEntries = Object.entries(outputs)
|
|
282
|
+
.sort(([, a], [, b]) => {
|
|
283
|
+
const timestampA = a.timestamp || '0';
|
|
284
|
+
const timestampB = b.timestamp || '0';
|
|
285
|
+
return new Date(timestampB).getTime() - new Date(timestampA).getTime();
|
|
286
|
+
})
|
|
287
|
+
.slice(0, 10); // Keep only 10 most recent
|
|
288
|
+
return Object.fromEntries(sortedEntries);
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Set context size limits
|
|
292
|
+
*/
|
|
293
|
+
setContextLimits(maxSize, compressionLevel) {
|
|
294
|
+
this.maxContextSize = maxSize;
|
|
295
|
+
this.compressionLevel = compressionLevel;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Get context statistics
|
|
299
|
+
*/
|
|
300
|
+
getContextStats(context) {
|
|
301
|
+
const totalSize = this.calculateContextSize(context);
|
|
302
|
+
const fileCount = [
|
|
303
|
+
context.prd,
|
|
304
|
+
context.types,
|
|
305
|
+
context.brand,
|
|
306
|
+
context.componentList,
|
|
307
|
+
context.projectStructure,
|
|
308
|
+
].filter(Boolean).length;
|
|
309
|
+
const originalSize = this.calculateOriginalSize(context);
|
|
310
|
+
const compressionRatio = originalSize > 0 ? totalSize / originalSize : 1;
|
|
311
|
+
return {
|
|
312
|
+
totalSize,
|
|
313
|
+
fileCount,
|
|
314
|
+
lastUpdated: context.lastUpdated || 'Unknown',
|
|
315
|
+
compressionRatio,
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Calculate original size before compression
|
|
320
|
+
*/
|
|
321
|
+
calculateOriginalSize(context) {
|
|
322
|
+
// This is an approximation - in a real implementation, you'd track original sizes
|
|
323
|
+
return this.calculateContextSize(context) * 1.5;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
exports.ContextManager = ContextManager;
|
|
327
|
+
//# sourceMappingURL=contextManager.js.map
|