@autobe/agent 0.5.1 → 0.5.2

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.
@@ -13,6 +13,14 @@ export function orchestratePrismaCorrect<Model extends ILlmSchema.Model>(
13
13
  application: AutoBePrisma.IApplication,
14
14
  retry: number = 8,
15
15
  ): Promise<IAutoBePrismaValidation> {
16
+ const unique: Set<string> = new Set();
17
+ for (const file of application.files)
18
+ file.models = file.models.filter((model) => {
19
+ if (unique.has(model.name)) return false;
20
+ unique.add(model.name);
21
+ return true;
22
+ });
23
+ application.files = application.files.filter((f) => f.models.length !== 0);
16
24
  return step(ctx, application, retry);
17
25
  }
18
26
 
@@ -76,12 +84,20 @@ async function step<Model extends ILlmSchema.Model>(
76
84
  return result; // unreachable
77
85
  }
78
86
 
87
+ const correction: AutoBePrisma.IApplication = {
88
+ files: application.files.map((file) => ({
89
+ filename: file.filename,
90
+ namespace: file.namespace,
91
+ models: file.models.map((model) => {
92
+ const newbie = pointer.value!.models.find((m) => m.name === model.name);
93
+ return newbie ?? model;
94
+ }),
95
+ })),
96
+ };
79
97
  ctx.dispatch({
80
98
  type: "prismaCorrect",
81
99
  failure: result,
82
- correction: {
83
- files: pointer.value.files,
84
- },
100
+ correction,
85
101
  planning: pointer.value.planning,
86
102
  step: ctx.state().analyze?.step ?? 0,
87
103
  created_at: new Date().toISOString(),
@@ -89,7 +105,7 @@ async function step<Model extends ILlmSchema.Model>(
89
105
  return step(
90
106
  ctx,
91
107
  {
92
- files: pointer.value.files,
108
+ files: correction.files,
93
109
  },
94
110
  life - 1,
95
111
  );
@@ -135,124 +151,141 @@ const collection = {
135
151
 
136
152
  interface IApplication {
137
153
  /**
138
- * Fixes validation errors in AutoBePrisma.IApplication structure while
139
- * preserving ALL existing business logic and model descriptions.
154
+ * Fixes validation errors in specific AutoBePrisma models while preserving
155
+ * ALL existing business logic and model descriptions.
140
156
  *
141
157
  * ## Core Rules
142
158
  *
143
- * 1. Fix ONLY validation errors - never remove business descriptions
144
- * 2. Apply minimal changes - preserve original design intent
145
- * 3. Return COMPLETE corrected structure - no data loss allowed
146
- * 4. Maintain referential integrity across all models
159
+ * 1. Fix ONLY validation errors in provided models - never remove business
160
+ * descriptions
161
+ * 2. Apply minimal changes to error models only - preserve original design
162
+ * intent
163
+ * 3. Return ONLY corrected models - unchanged models remain in original schema
164
+ * 4. Maintain referential integrity with unchanged models
147
165
  *
148
- * ## Preservation Requirements
166
+ * ## Targeted Scope
149
167
  *
150
- * - Keep ALL model and field descriptions
151
- * - Keep business logic and architectural patterns
152
- * - Maintain relationship semantics and cardinality
153
- * - Remove descriptions only when removing duplicate elements
168
+ * - Process ONLY models with validation errors from IError[] array
169
+ * - Exclude models without errors from processing and output
170
+ * - Minimize context usage by returning corrected models only
171
+ * - Preserve unchanged models in their original state
154
172
  *
155
173
  * ## Fix Strategy
156
174
  *
157
- * - Resolve structural validation errors without changing business intent
158
- * - Remove duplicate fields/relations while preserving most appropriate ones
159
- * - Fix invalid references and type mismatches
160
- * - Ensure naming conventions and index rules compliance
175
+ * - Resolve validation errors within specific models only
176
+ * - Fix field duplications, invalid references, and type mismatches
177
+ * - Update cross-model references without modifying target models
178
+ * - Ensure naming conventions and index rules compliance in corrected models
161
179
  */
162
180
  correctPrismaSchemaFiles(props: IModifyPrismaSchemaFilesProps): void;
163
181
  }
164
182
 
165
183
  interface IModifyPrismaSchemaFilesProps {
166
184
  /**
167
- * Detailed execution plan for fixing AutoBePrisma validation errors.
185
+ * Detailed execution plan for fixing `AutoBePrisma` validation errors in
186
+ * specific models.
168
187
  *
169
188
  * 🎯 Purpose: Enable systematic reasoning and step-by-step error resolution
170
- * approach for structured schema validation issues
189
+ * approach for targeted model validation issues
171
190
  *
172
191
  * 📋 Required Planning Content:
173
192
  *
174
- * 1. **Error Analysis Summary**
193
+ * 1. **Error Scope Analysis**
175
194
  *
176
195
  * - List all validation errors from IAutoBePrismaValidation.IError[] array
177
- * - Categorize errors by type (duplications, references, types, indexes)
178
- * - Identify root causes and error interdependencies
179
- * 2. **Fix Strategy Overview**
196
+ * - Extract unique table names from errors to identify affected models
197
+ * - Categorize errors by type (field duplications, references, types, indexes)
198
+ * - Identify which models need correction vs. which remain unchanged
199
+ * 2. **Targeted Fix Strategy**
180
200
  *
181
- * - Prioritize fixes based on dependencies (fix duplications first)
182
- * - Outline minimal changes needed for each validation error
183
- * - Identify potential impact on other models/relationships
184
- * 3. **Step-by-Step Fix Plan**
201
+ * - Focus ONLY on models mentioned in validation errors
202
+ * - Outline minimal changes needed for each affected model
203
+ * - Plan cross-model reference updates (if any) without modifying non-error
204
+ * models
205
+ * - Ensure unchanged models maintain valid references to corrected models
206
+ * 3. **Model-Specific Fix Plan**
185
207
  *
186
- * - Model-by-model modification plan with specific changes
187
- * - Exact field additions, removals, or renames required
188
- * - Reference updates needed for renamed elements
189
- * - Index corrections to comply with validation rules
190
- * 4. **Preservation Checklist**
208
+ * - Model-by-model modification plan for ONLY affected models
209
+ * - Exact field additions, renames, or type corrections required
210
+ * - Reference updates within corrected models only
211
+ * - Index corrections limited to affected models
212
+ * 4. **Minimal Scope Validation**
191
213
  *
192
- * - Confirm which descriptions and business logic must be preserved
193
- * - List relationships and constraints to maintain unchanged
194
- * - Identify cross-model dependencies that must remain intact
195
- * 5. **Risk Assessment**
214
+ * - Confirm which models will be included in output (error models only)
215
+ * - List models that will remain unchanged in original schema
216
+ * - Identify cross-model dependencies without including unchanged models
217
+ * - Preserve all business logic within corrected models
218
+ * 5. **Targeted Impact Assessment**
196
219
  *
197
- * - Potential side effects of each planned fix
198
- * - Validation points to check after applying corrections
199
- * - Ensure no new validation errors are introduced
220
+ * - Potential effects of fixes on unchanged models (reference validation)
221
+ * - Verification points for corrected models only
222
+ * - Ensure no new validation errors in targeted models
223
+ * - Confirm minimal output scope compliance
200
224
  *
201
225
  * 💡 Example Planning Structure:
202
226
  *
203
- * ## Error Analysis
204
- * - Error 1: Duplicate field 'name' in shopping_customers model
205
- * - Error 2: Invalid targetModel 'shopping_customer' should be 'shopping_customers'
227
+ * ## Error Scope
228
+ * - Target Models: shopping_customers, shopping_orders (2 models only)
229
+ * - Unchanged Models: All others remain in original schema
206
230
  *
207
- * ## Fix Strategy
208
- * 1. Remove duplicate 'name' field (keep the more detailed one)
209
- * 2. Update foreign key references to use correct plural model name
231
+ * ## Targeted Fixes
232
+ * - shopping_customers: Remove duplicate 'email' field
233
+ * - shopping_orders: Update targetModel reference to 'shopping_customers'
210
234
  *
211
- * ## Detailed Steps
212
- * 1. shopping_customers model: Remove second 'name' field from plainFields
213
- * 2. shopping_orders model: Update targetModel from 'shopping_customer' to 'shopping_customers'
235
+ * ## Output Scope
236
+ * - Return: Only shopping_customers and shopping_orders models
237
+ * - Preserve: All other models unchanged in original schema
214
238
  *
215
- * ## Preservation Notes
216
- * - Keep business descriptions for remaining 'name' field
217
- * - Maintain all relationship semantics
218
- * - Preserve all indexes and constraints
239
+ * ## Cross-Model Impact
240
+ * - Verify: shopping_orders still references shopping_customers correctly
241
+ * - No changes needed in other models referencing these
219
242
  */
220
243
  planning: string;
221
244
 
222
245
  /**
223
- * Original AutoBePrisma.IApplication structure that contains validation
224
- * errors and needs correction.
246
+ * ONLY the specific models that contain validation errors and need
247
+ * correction.
225
248
  *
226
249
  * 📥 Input Structure:
227
250
  *
228
- * - Complete IApplication with files array containing validation errors
229
- * - Each file contains models with potential structural issues
230
- * - Errors may include duplications, invalid references, or constraint
231
- * violations
251
+ * - Contains ONLY models mentioned in IAutoBePrismaValidation.IError[] array
252
+ * - Each model has specific validation errors that need targeted correction
253
+ * - Models not mentioned in errors are excluded from this input
254
+ * - Represents minimal scope for error correction
255
+ *
256
+ * 🔍 Expected Validation Issues (Model-Specific):
257
+ *
258
+ * - Duplicate field/relation names within these specific models
259
+ * - Invalid foreign key references from these models to other models
260
+ * - Single foreign key fields in index arrays within these models
261
+ * - Invalid naming conventions within these specific models
262
+ * - Type validation errors in fields of these models
232
263
  *
233
- * 🔍 Expected Validation Issues:
264
+ * 📝 Model Content Analysis (Targeted Scope):
234
265
  *
235
- * - Duplicate model names across files
236
- * - Duplicate field/relation names within models
237
- * - Invalid foreign key references to non-existent models
238
- * - Single foreign key fields in index arrays
239
- * - Non-plural model names or invalid naming conventions
266
+ * - Complete field definitions for each error model only
267
+ * - Relationships from these models (may reference unchanged models)
268
+ * - Indexes within these models that need correction
269
+ * - Business descriptions specific to these models
270
+ * - Cross-model references that need validation (read-only for targets)
240
271
  *
241
- * 📝 Application Content Analysis:
272
+ * ⚠️ Processing Notes (Focused Approach):
242
273
  *
243
- * - All models with their complete field definitions
244
- * - All relationships with targetModel and targetfield configurations
245
- * - All indexes (unique, plain, GIN) with field references
246
- * - All business descriptions and requirement mappings
247
- * - Cross-file model references and dependencies
274
+ * - Input contains ONLY models with validation errors
275
+ * - May reference other models not included in this input
276
+ * - Cross-model references must be validated but target models won't be
277
+ * modified
278
+ * - Output should return corrected versions of ONLY these input models
279
+ * - All business logic and descriptions within these models must be preserved
280
+ * - Corrections must not break references from unchanged models
248
281
  *
249
- * ⚠️ Processing Notes:
282
+ * 🎯 Correction Scope:
250
283
  *
251
- * - Structure may contain validation errors that prevent code generation
252
- * - Some models might reference non-existent targets
253
- * - Field names might violate naming conventions
254
- * - Index configurations might include forbidden single foreign keys
255
- * - Business logic and descriptions must be preserved during fixes
284
+ * - Fix validation errors within these specific models
285
+ * - Update internal model structure (fields, relations, indexes)
286
+ * - Correct references to external models (without modifying targets)
287
+ * - Maintain compatibility with unchanged models in the full schema
288
+ * - Return corrected versions of ONLY these models
256
289
  */
257
- files: AutoBePrisma.IFile[];
290
+ models: AutoBePrisma.IModel[];
258
291
  }