mycontext-cli 0.4.8 → 0.4.10

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 (70) hide show
  1. package/README.md +113 -97
  2. package/dist/agents/communication/AgentCommunicationManager.d.ts +27 -0
  3. package/dist/agents/communication/AgentCommunicationManager.d.ts.map +1 -0
  4. package/dist/agents/communication/AgentCommunicationManager.js +293 -0
  5. package/dist/agents/communication/AgentCommunicationManager.js.map +1 -0
  6. package/dist/agents/evolution/CodeEvolutionEngine.d.ts +92 -0
  7. package/dist/agents/evolution/CodeEvolutionEngine.d.ts.map +1 -0
  8. package/dist/agents/evolution/CodeEvolutionEngine.js +639 -0
  9. package/dist/agents/evolution/CodeEvolutionEngine.js.map +1 -0
  10. package/dist/agents/implementations/ArchitectAgent.d.ts +39 -0
  11. package/dist/agents/implementations/ArchitectAgent.d.ts.map +1 -0
  12. package/dist/agents/implementations/ArchitectAgent.js +345 -0
  13. package/dist/agents/implementations/ArchitectAgent.js.map +1 -0
  14. package/dist/agents/implementations/CodeGenSubAgent.d.ts +12 -0
  15. package/dist/agents/implementations/CodeGenSubAgent.d.ts.map +1 -1
  16. package/dist/agents/implementations/CodeGenSubAgent.js +296 -43
  17. package/dist/agents/implementations/CodeGenSubAgent.js.map +1 -1
  18. package/dist/agents/implementations/PromptConstructorAgent.d.ts +50 -0
  19. package/dist/agents/implementations/PromptConstructorAgent.d.ts.map +1 -0
  20. package/dist/agents/implementations/PromptConstructorAgent.js +481 -0
  21. package/dist/agents/implementations/PromptConstructorAgent.js.map +1 -0
  22. package/dist/agents/implementations/SecurityAgent.d.ts +31 -0
  23. package/dist/agents/implementations/SecurityAgent.d.ts.map +1 -0
  24. package/dist/agents/implementations/SecurityAgent.js +453 -0
  25. package/dist/agents/implementations/SecurityAgent.js.map +1 -0
  26. package/dist/agents/intelligence/ProjectIntelligence.d.ts +127 -0
  27. package/dist/agents/intelligence/ProjectIntelligence.d.ts.map +1 -0
  28. package/dist/agents/intelligence/ProjectIntelligence.js +456 -0
  29. package/dist/agents/intelligence/ProjectIntelligence.js.map +1 -0
  30. package/dist/agents/interfaces/AgentCommunication.d.ts +65 -0
  31. package/dist/agents/interfaces/AgentCommunication.d.ts.map +1 -0
  32. package/dist/agents/interfaces/AgentCommunication.js +13 -0
  33. package/dist/agents/interfaces/AgentCommunication.js.map +1 -0
  34. package/dist/agents/learning/CrossProjectLearning.d.ts +99 -0
  35. package/dist/agents/learning/CrossProjectLearning.d.ts.map +1 -0
  36. package/dist/agents/learning/CrossProjectLearning.js +517 -0
  37. package/dist/agents/learning/CrossProjectLearning.js.map +1 -0
  38. package/dist/cli.js +47 -0
  39. package/dist/cli.js.map +1 -1
  40. package/dist/commands/agent-flow.d.ts +21 -0
  41. package/dist/commands/agent-flow.d.ts.map +1 -0
  42. package/dist/commands/agent-flow.js +225 -0
  43. package/dist/commands/agent-flow.js.map +1 -0
  44. package/dist/commands/generate-components.d.ts +0 -13
  45. package/dist/commands/generate-components.d.ts.map +1 -1
  46. package/dist/commands/generate-components.js +23 -385
  47. package/dist/commands/generate-components.js.map +1 -1
  48. package/dist/commands/generate.d.ts +4 -1
  49. package/dist/commands/generate.d.ts.map +1 -1
  50. package/dist/commands/generate.js +173 -1
  51. package/dist/commands/generate.js.map +1 -1
  52. package/dist/commands/predict.d.ts +36 -0
  53. package/dist/commands/predict.d.ts.map +1 -0
  54. package/dist/commands/predict.js +539 -0
  55. package/dist/commands/predict.js.map +1 -0
  56. package/dist/utils/clean.d.ts +6 -0
  57. package/dist/utils/clean.d.ts.map +1 -0
  58. package/dist/utils/clean.js +220 -0
  59. package/dist/utils/clean.js.map +1 -0
  60. package/dist/utils/githubModelsClient.d.ts.map +1 -1
  61. package/dist/utils/githubModelsClient.js +11 -12
  62. package/dist/utils/githubModelsClient.js.map +1 -1
  63. package/dist/utils/hybridAIClient.d.ts +1 -0
  64. package/dist/utils/hybridAIClient.d.ts.map +1 -1
  65. package/dist/utils/hybridAIClient.js +23 -9
  66. package/dist/utils/hybridAIClient.js.map +1 -1
  67. package/dist/utils/ollamaClient.d.ts.map +1 -1
  68. package/dist/utils/ollamaClient.js +6 -4
  69. package/dist/utils/ollamaClient.js.map +1 -1
  70. package/package.json +2 -1
@@ -79,7 +79,14 @@ class GenerateComponentsCommand {
79
79
  }
80
80
  getComponentBaseName(component) {
81
81
  const raw = typeof component === "string" ? component : component?.name;
82
- return this.generateComponentName(String(raw || "Component"));
82
+ const name = String(raw || "Component");
83
+ // Simple PascalCase conversion - no template generation
84
+ return name
85
+ .replace(/[_-]+/g, " ")
86
+ .split(/\s+/)
87
+ .map((w) => w ? w.charAt(0).toUpperCase() + w.slice(1).toLowerCase() : "")
88
+ .join("")
89
+ .replace(/[^A-Za-z0-9]/g, "");
83
90
  }
84
91
  getComponentExportName(component) {
85
92
  return this.getComponentBaseName(component);
@@ -628,34 +635,13 @@ class GenerateComponentsCommand {
628
635
  },
629
636
  },
630
637
  }),
631
- new Promise((_, reject) => setTimeout(() => reject(new Error("Code generation timed out after 60 seconds")), 60000)),
638
+ new Promise((_, reject) => setTimeout(() => reject(new Error("Code generation timed out after 30 minutes")), 1800000)),
632
639
  ]));
633
640
  }
634
641
  catch (error) {
635
- if (error.message.includes("timed out")) {
636
- console.log(chalk_1.default.yellow(`⚠️ Code generation timed out for ${component.name}`));
637
- console.log(chalk_1.default.gray("Using fallback generation method..."));
638
- const code = this.generateComponentCode(component, group, options);
639
- const fileBase = this.getComponentBaseName(component);
640
- const componentPath = path.join(groupDir, `${fileBase}.tsx`);
641
- await this.fs.writeFile(componentPath, code);
642
- // Store component with fallback data
643
- await this.storeComponent({
644
- userId,
645
- name: component.name,
646
- code,
647
- metadata: {
648
- prompt: component.description || "",
649
- model: "fallback-timeout",
650
- executionTime: Date.now(),
651
- qualityScore: null,
652
- group: group.name,
653
- },
654
- group: group.name,
655
- qualityScore: null,
656
- });
657
- return;
658
- }
642
+ // No fallbacks - propagate the error for clean failure
643
+ console.log(chalk_1.default.red(`❌ AI generation failed for ${component.name}: ${error.message}`));
644
+ console.log(chalk_1.default.yellow(`💡 No generic templates - retry when AI is available!`));
659
645
  throw error;
660
646
  }
661
647
  const fileBase = this.getComponentBaseName(component);
@@ -1068,363 +1054,10 @@ class GenerateComponentsCommand {
1068
1054
  }
1069
1055
  }
1070
1056
  }
1071
- generateComponentCode(component, group, options) {
1072
- // Handle both string and object inputs
1073
- let name, description, type, userStories, actionFunctions, dependencies, tags;
1074
- if (typeof component === "string") {
1075
- // Simple string input - create a basic component structure
1076
- name = this.generateComponentName(component);
1077
- description = component;
1078
- type = "form"; // Default type
1079
- userStories = [
1080
- `As a user, I want to use ${name} to ${component.toLowerCase()}`,
1081
- ];
1082
- actionFunctions = ["handleSubmit", "handleChange"];
1083
- dependencies = ["react", "tailwindcss"];
1084
- tags = ["ui", "component"];
1085
- }
1086
- else {
1087
- // Structured component object
1088
- const rawName = String(component?.name || "Component");
1089
- name = this.generateComponentName(rawName);
1090
- description = String(component?.description || "");
1091
- type = String(component?.type || "form");
1092
- userStories = Array.isArray(component?.userStories)
1093
- ? component.userStories
1094
- : [];
1095
- actionFunctions = Array.isArray(component?.actionFunctions)
1096
- ? component.actionFunctions
1097
- : [];
1098
- dependencies = Array.isArray(component?.dependencies)
1099
- ? component.dependencies
1100
- : [];
1101
- tags = Array.isArray(component?.tags) ? component.tags : [];
1102
- }
1103
- // Ensure robust defaults for template rendering
1104
- if (!Array.isArray(userStories))
1105
- userStories = [];
1106
- if (!Array.isArray(actionFunctions))
1107
- actionFunctions = [];
1108
- if (!Array.isArray(dependencies))
1109
- dependencies = [];
1110
- if (!Array.isArray(tags))
1111
- tags = [];
1112
- type = String(type || "form");
1113
- // Read branding for styling
1114
- const brandingPath = "context/branding.json";
1115
- let branding = {};
1116
- try {
1117
- if (fs.existsSync(brandingPath)) {
1118
- branding = JSON.parse(fs.readFileSync(brandingPath, "utf8"));
1119
- }
1120
- }
1121
- catch (error) {
1122
- // Use default branding if file doesn't exist
1123
- }
1124
- const planned = this.findComponentPlan(group?.name || "", name) || {};
1125
- const plannedContext = Array.isArray(planned?.acceptanceCriteria)
1126
- ? planned.acceptanceCriteria
1127
- .slice(0, 5)
1128
- .map((s) => ` * - ${String(s)}`)
1129
- .join("\n")
1130
- : "";
1131
- const prdContext = options?.context?.prd || "";
1132
- const typesContext = options?.context?.types || "";
1133
- return `"use client";
1134
-
1135
- import React from "react";
1136
- import { cn } from "@/lib/utils";
1137
- import { Card, CardHeader, CardTitle, CardContent } from "@/components/ui/card";
1138
- import { Button } from "@/components/ui/button";
1139
-
1140
- /**
1141
- * ${name} Component
1142
- *
1143
- * ${description}
1144
- *
1145
- * User Stories:
1146
- ${userStories.map((story) => ` * - ${story}`).join("\n")}
1147
- *
1148
- * Action Functions:
1149
- ${actionFunctions.map((func) => ` * - ${func}`).join("\n")}
1150
- *
1151
- * Dependencies: ${dependencies.join(", ")}
1152
- * Tags: ${tags.join(", ")}
1153
- *
1154
- * Context Snapshot (PRD excerpt):
1155
- * ${prdContext
1156
- .split("\n")
1157
- .slice(0, 5)
1158
- .map((l) => ` * ${l}`)
1159
- .join("\n")}
1160
- *
1161
- * Types Snapshot (excerpt):
1162
- * ${typesContext
1163
- .split("\n")
1164
- .slice(0, 5)
1165
- .map((l) => ` * ${l}`)
1166
- .join("\n")}
1167
- *
1168
- * Planned Acceptance Criteria:
1169
- ${plannedContext || " * - (none)"}
1170
- */
1171
-
1172
- interface ${name}Props {
1173
- className?: string;
1174
- // Add specific props based on component type
1175
- ${this.generatePropsForType(type)}
1176
- }
1177
-
1178
- export function ${name}({
1179
- className,
1180
- ${this.generatePropsDestructuring(type)}
1181
- ...props
1182
- }: ${name}Props) {
1183
- ${this.generateComponentLogic(type, actionFunctions)}
1184
-
1185
- return (
1186
- <Card className={cn("${this.generateBaseClasses(type, branding)}", className)} {...props}>
1187
- <CardHeader>
1188
- <CardTitle>${name}</CardTitle>
1189
- </CardHeader>
1190
- <CardContent>
1191
- ${this.generateComponentJSX(type, name)}
1192
- </CardContent>
1193
- </Card>
1194
- );
1195
- }
1196
-
1197
- ${this.generateActionFunctions(actionFunctions, name)}
1198
-
1199
- export default ${name};
1200
- `;
1201
- }
1202
- generateComponentName(description) {
1203
- // Preserve existing PascalCase names; otherwise convert to PascalCase
1204
- const trimmed = description.trim();
1205
- if (/^[A-Z][A-Za-z0-9]*$/.test(trimmed))
1206
- return trimmed;
1207
- return trimmed
1208
- .replace(/[_-]+/g, " ")
1209
- .split(/\s+/)
1210
- .map((w) => w ? w.charAt(0).toUpperCase() + w.slice(1).toLowerCase() : "")
1211
- .join("")
1212
- .replace(/[^A-Za-z0-9]/g, "");
1213
- }
1214
- generatePropsForType(type) {
1215
- switch (type) {
1216
- case "form":
1217
- return `
1218
- onSubmit?: (data: any) => void;
1219
- loading?: boolean;
1220
- error?: string;`;
1221
- case "layout":
1222
- return `
1223
- children: React.ReactNode;
1224
- sidebar?: React.ReactNode;`;
1225
- case "card":
1226
- return `
1227
- title?: string;
1228
- content?: React.ReactNode;
1229
- actions?: React.ReactNode;`;
1230
- case "button":
1231
- return `
1232
- variant?: "default" | "destructive" | "outline" | "secondary" | "ghost" | "link";
1233
- size?: "default" | "sm" | "lg" | "icon";
1234
- disabled?: boolean;
1235
- onClick?: () => void;`;
1236
- default:
1237
- return `
1238
- // Add component-specific props here`;
1239
- }
1240
- }
1241
- generatePropsDestructuring(type) {
1242
- switch (type) {
1243
- case "form":
1244
- return `
1245
- onSubmit,
1246
- loading = false,
1247
- error,`;
1248
- case "layout":
1249
- return `
1250
- children,
1251
- sidebar,`;
1252
- case "card":
1253
- return `
1254
- title,
1255
- content,
1256
- actions,`;
1257
- case "button":
1258
- return `
1259
- variant = "default",
1260
- size = "default",
1261
- disabled = false,
1262
- onClick,`;
1263
- default:
1264
- return "";
1265
- }
1266
- }
1267
- generateComponentLogic(type, actionFunctions) {
1268
- const logic = [];
1269
- if (type === "form") {
1270
- logic.push(`
1271
- const [formData, setFormData] = React.useState({});
1272
- const [isSubmitting, setIsSubmitting] = React.useState(false);`);
1273
- }
1274
- if (type === "form") {
1275
- logic.push(`
1276
- const handleSubmit = async (e: React.FormEvent) => {
1277
- e.preventDefault();
1278
- setIsSubmitting(true);
1279
- try {
1280
- onSubmit?.(formData);
1281
- } catch (error) {
1282
- console.error("Form submission error:", error);
1283
- } finally {
1284
- setIsSubmitting(false);
1285
- }
1286
- };`);
1287
- }
1288
- return logic.join("\n");
1289
- }
1290
- generateBaseClasses(type, branding) {
1291
- const baseClasses = [];
1292
- // Normalize and sanitize type
1293
- const normalizedType = String(type || "")
1294
- .toLowerCase()
1295
- .replace(/\s+/g, "-");
1296
- switch (normalizedType) {
1297
- case "form":
1298
- baseClasses.push("space-y-4", "w-full", "max-w-md");
1299
- break;
1300
- case "layout":
1301
- baseClasses.push("min-h-screen", "flex", "flex-col");
1302
- break;
1303
- case "card":
1304
- baseClasses.push("rounded-lg", "border", "bg-card", "p-6", "shadow-sm");
1305
- break;
1306
- case "button":
1307
- baseClasses.push("inline-flex", "items-center", "justify-center", "rounded-md", "text-sm", "font-medium", "transition-colors", "focus-visible:outline-none", "focus-visible:ring-2", "focus-visible:ring-ring", "focus-visible:ring-offset-2", "disabled:opacity-50", "disabled:pointer-events-none");
1308
- break;
1309
- default:
1310
- baseClasses.push("w-full");
1311
- }
1312
- return baseClasses.join(" ");
1313
- }
1314
- generateComponentJSX(type, name) {
1315
- const normalizedType = String(type || "")
1316
- .toLowerCase()
1317
- .replace(/\s+/g, "-");
1318
- switch (normalizedType) {
1319
- case "form":
1320
- return `
1321
- {/* Example domain-agnostic form scaffold. Replace fields per component plan. */}
1322
- <form onSubmit={handleSubmit} className="space-y-4">
1323
- <div className="space-y-2">
1324
- <label htmlFor="field1" className="text-sm font-medium">Field 1</label>
1325
- <input id="field1" className="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50" placeholder="Type here" />
1326
- </div>
1327
- {error ? <div className="text-sm text-destructive">{error}</div> : null}
1328
- <button
1329
- type="submit"
1330
- disabled={loading || isSubmitting}
1331
- className="inline-flex h-10 items-center justify-center rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground ring-offset-background transition-colors hover:bg-primary/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50"
1332
- >
1333
- {loading || isSubmitting ? "Submitting..." : "Submit"}
1334
- </button>
1335
- </form>`;
1336
- case "layout":
1337
- return `
1338
- <header className="border-b bg-background">
1339
- <div className="container mx-auto px-4 py-4">
1340
- <h1 className="text-2xl font-bold">${name}</h1>
1341
- </div>
1342
- </header>
1343
- <main className="flex-1">
1344
- <div className="container mx-auto px-4 py-8">
1345
- {children}
1346
- </div>
1347
- </main>
1348
- <footer className="border-t bg-background">
1349
- <div className="container mx-auto px-4 py-4 text-center text-sm text-muted-foreground">
1350
- © 2024 MyContext. All rights reserved.
1351
- </div>
1352
- </footer>`;
1353
- case "card":
1354
- return `
1355
- {title && (
1356
- <h3 className="text-lg font-semibold leading-none tracking-tight">
1357
- {title}
1358
- </h3>
1359
- )}
1360
- {content && (
1361
- <div className="mt-4">
1362
- {content}
1363
- </div>
1364
- )}
1365
- {actions && (
1366
- <div className="mt-4 flex justify-end space-x-2">
1367
- {actions}
1368
- </div>
1369
- )}`;
1370
- case "button":
1371
- return `
1372
- <span className="sr-only">${name}</span>
1373
- <span>${name}</span>`;
1374
- default:
1375
- return `
1376
- <div className="p-4">
1377
- <h3 className="text-lg font-semibold">${name}</h3>
1378
- <p className="text-sm text-muted-foreground">
1379
- This is a ${type} component. Customize it based on your needs.
1380
- </p>
1381
- </div>`;
1382
- }
1383
- }
1384
- generateActionFunctions(actionFunctions, componentName) {
1385
- if (actionFunctions.length === 0)
1386
- return "";
1387
- const functions = actionFunctions.map((func) => {
1388
- switch (func) {
1389
- case "handleSubmit":
1390
- return `// Already implemented in component logic`;
1391
- case "handleLogin":
1392
- return `
1393
- export async function handleLogin(email: string, password: string) {
1394
- // Implement login logic in application layer
1395
- console.log("Logging in with:", { email, password });
1396
- return { success: true };
1397
- }`;
1398
- case "handleSignup":
1399
- return `
1400
- export async function handleSignup(email: string, password: string, name: string) {
1401
- // Implement signup logic in application layer
1402
- console.log("Signing up with:", { email, password, name });
1403
- return { success: true };
1404
- }`;
1405
- case "validateEmail":
1406
- return `
1407
- export function validateEmail(email: string): boolean {
1408
- const emailRegex = /^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$/;
1409
- return emailRegex.test(email);
1410
- }`;
1411
- case "checkUsername":
1412
- return `
1413
- export async function checkUsername(username: string): Promise<boolean> {
1414
- // Implement username availability check in application layer
1415
- console.log("Checking username:", username);
1416
- return true;
1417
- }`;
1418
- default:
1419
- return `
1420
- export function ${func}() {
1421
- // Implement ${func} logic in application layer
1422
- console.log("${func} called");
1423
- }`;
1424
- }
1425
- });
1426
- return functions.join("\n");
1427
- }
1057
+ // REMOVED: All generic template generation
1058
+ // Components are now 100% generated by AI using context files and sub-agents
1059
+ // REMOVED: Template generation methods
1060
+ // All components now generated by AI with context analysis
1428
1061
  async generateGroupIndex(group, groupDir) {
1429
1062
  const components = group.components || [];
1430
1063
  const exports = components.map((comp) => {
@@ -1461,7 +1094,12 @@ ${components
1461
1094
  })
1462
1095
  .join("\n")}
1463
1096
 
1464
- export default function ${this.generateComponentName(String(group.name || "Group"))}Preview() {
1097
+ export default function ${String(group.name || "Group")
1098
+ .replace(/[_-]+/g, " ")
1099
+ .split(/\s+/)
1100
+ .map((w) => w ? w.charAt(0).toUpperCase() + w.slice(1).toLowerCase() : "")
1101
+ .join("")
1102
+ .replace(/[^A-Za-z0-9]/g, "")}Preview() {
1465
1103
  return (
1466
1104
  <div className="container mx-auto p-8 space-y-8">
1467
1105
  <div className="text-center">
@@ -1527,7 +1165,7 @@ import { previewProps } from './preview-props';
1527
1165
 
1528
1166
  export type PreviewRegistryItem = {
1529
1167
  group: string;
1530
- name: string;
1168
+ name: string;
1531
1169
  path: string;
1532
1170
  loader: () => Promise<any>;
1533
1171
  };