@@ -189,22 +189,66 @@ def get_async_reproduction_prompt(spec: str, fmt: str, file_name: str, with_test
189189
190190def get_token_reproduction_prompt (spec : str , fmt : str , file_name : str , language : str = "python" ) -> str :
191191 format_hints = {
192- "json" : "Parse the JSON structure and implement all classes and functions with exact signatures." ,
192+ "json" : """Parse the JSON structure carefully:
193+ - 'modules' array contains file-level info with 'classes' and 'functions'
194+ - Each class has 'name', 'bases', 'methods' with full signatures
195+ - Each function has 'name', 'params', 'returns', 'doc'
196+ - Implement ALL classes with their methods and ALL standalone functions
197+ - Use the 'doc' field to implement actual logic, not just stubs
198+ CRITICAL: Match every class/function name and signature exactly.""" ,
193199 "json_compact" : "Parse the compact JSON and implement all elements with exact signatures." ,
194- "yaml" : "Parse the YAML structure and implement all classes and functions with exact signatures." ,
195- "gherkin" : """Parse Gherkin/BDD scenarios and implement them as working code:
196- - Each Feature maps to a class or module
197- - Each Scenario maps to a function
198- - Given/When/Then steps describe the logic flow
199- - Implement actual logic, not just stubs
200- Focus on the described behavior and implement it directly.""" ,
201- "markdown" : "Parse embedded Gherkin (behaviors) and YAML (structures). Implement all described classes and functions." ,
202- "logicml" : """Parse LogicML and generate VALID code:
203- - 'sig:' lines describe function signatures (translate to the target language)
204- - 'type: re-export' means this module primarily re-exports symbols
205- - 'attrs:' = instance attributes to set in constructor
200+ "yaml" : """Parse the YAML structure carefully:
201+ - Top-level keys describe modules with classes and functions
202+ - Each class has 'bases', 'properties', 'methods' with signatures
203+ - Each function has params, return type, and docstring/intent
204+ - Implement ALL classes, methods, and standalone functions
205+ - Use intent/docstring to write actual logic, not placeholders
206+ CRITICAL: Match every name and signature exactly as specified.""" ,
207+ "gherkin" : """Parse Gherkin/BDD specification and reconstruct the ORIGINAL source code:
208+ - 'Feature:' = a class or module (use the name after Feature)
209+ - 'Scenario:' = a function or method to implement
210+ - 'Given' steps = setup / preconditions / imports needed
211+ - 'When' steps = the core action / logic to implement
212+ - 'Then' steps = expected outcomes / return values / assertions
213+ - 'And' continues the previous step type
214+ - '@tag' annotations may indicate decorators or categories
215+
216+ IMPORTANT RULES:
217+ 1. Each Scenario becomes a real function with actual logic (NOT test code)
218+ 2. Given/When/Then describe behavior, translate them to implementation
219+ 3. Include all imports mentioned in Given steps
220+ 4. Use type hints based on parameter descriptions
221+ 5. Implement real logic based on When/Then steps, not just stubs
222+ 6. If a Feature has multiple Scenarios, they are methods of the same class""" ,
223+ "markdown" : """Parse the Markdown specification to reconstruct source code:
224+ - '## Module' or '### Class' headings define code structure
225+ - Embedded YAML blocks describe attributes, methods, signatures
226+ - Embedded Gherkin blocks describe behaviors to implement
227+ - Code blocks show example usage or signatures
228+ - Tables may list functions with their parameters and return types
229+
230+ IMPORTANT RULES:
231+ 1. Extract class names, method signatures, and function signatures from headings and YAML
232+ 2. Implement all listed methods with actual logic based on descriptions
233+ 3. Include all imports mentioned anywhere in the document
234+ 4. Use type hints from signatures or parameter descriptions
235+ 5. Docstrings should come from the description text""" ,
236+ "logicml" : """Parse LogicML and generate VALID, complete code:
237+ - 'module:' = file to generate
238+ - 'sig:' lines = EXACT function signatures (translate to target language)
239+ - 'does:' = function intent/docstring — use this to implement real logic
240+ - 'type: re-export' = module primarily re-exports symbols from imports
241+ - 'attrs:' = instance attributes to initialize in __init__/constructor
206242- 'bases:' = parent classes to inherit from
207- CRITICAL: Ensure valid syntax - balanced brackets, proper indentation, no undefined variables.""" ,
243+ - 'decorators:' = decorators to apply
244+ - 'calls:' = other functions this function calls (implement the call chain)
245+ - 'raises:' = exceptions this function may raise
246+
247+ CRITICAL RULES:
248+ 1. Translate EVERY 'sig:' line into a real function with actual logic
249+ 2. Use 'does:' text to implement meaningful function bodies
250+ 3. Ensure valid syntax - balanced brackets, proper indentation
251+ 4. Include ALL imports listed in the module""" ,
208252 "toon" : """Parse TOON (Token-Oriented Object Notation) format carefully:
209253
210254STRUCTURE:
@@ -222,19 +266,43 @@ def get_token_reproduction_prompt(spec: str, fmt: str, file_name: str, language:
222266- 'decorators: @property' = add @property decorator
223267- 'decorators: @staticmethod|@cache' = multiple decorators
224268
225- CRITICAL: Use imports[], function_docs, and exact signatures to reproduce code accurately.""" ,
226- "csv" : """Parse the CSV table where each row describes a code element:
227- - Columns: path, type (class/method/function), name, signature, language, intent, category, domain, imports
228- - 'method' rows belong to the class in the preceding 'class' row
229- - Implement all elements with the exact signatures shown
230- Generate complete code with all classes, methods, and functions.""" ,
231- "function.toon" : """Parse the function-logic TOON format:
232- - 'modules[N]{path,lang,items}:' lists files
233- - 'function_details:' contains per-module function listings
234- - Each function has: line number, name, signature, description
235- - 'ClassName.method_name' = method of that class
236- - 'cc:N' after name = cyclomatic complexity
237- Implement all listed functions with matching signatures and described behavior.""" ,
269+ CRITICAL RULES:
270+ 1. Use imports[] to generate all import statements
271+ 2. Use function_docs to write real function bodies (not stubs)
272+ 3. Match exact signatures from sig: fields
273+ 4. Include ALL classes with their methods and ALL standalone functions
274+ 5. Preserve async functions (marked with 'async: true')""" ,
275+ "csv" : """Parse the CSV table to reconstruct source code:
276+ - Columns: path, type, name, signature, language, intent, category, domain, imports
277+ - 'type=class' rows define classes (look at 'bases' if present)
278+ - 'type=method' rows are methods of the preceding class
279+ - 'type=function' rows are standalone functions
280+ - 'signature' column has the exact function signature to use
281+ - 'intent' column describes what the function does — use it to implement real logic
282+ - 'imports' column lists required imports
283+
284+ IMPORTANT RULES:
285+ 1. Group methods under their parent class
286+ 2. Include all imports from the 'imports' column
287+ 3. Match signatures exactly as shown
288+ 4. Use 'intent' to implement actual logic, not just stubs
289+ 5. Add type hints based on signature information""" ,
290+ "function.toon" : """Parse the function-logic TOON format to reconstruct source code:
291+ - 'modules[N]{path,lang,items}:' lists source files and their function count
292+ - 'function_details:' contains per-module function listings as tables
293+ - Table columns: line, name, sig[, does, decorators, calls, raises]
294+ - 'ClassName.method_name' = this is a method of ClassName (create the class)
295+ - '~function_name' = async function (add async keyword)
296+ - 'cc:N' suffix on name = cyclomatic complexity hint (more complex logic needed)
297+ - 'sig' column has exact signature: (params)->ReturnType
298+
299+ CRITICAL RULES:
300+ 1. Create classes for any ClassName that appears as prefix in 'ClassName.method'
301+ 2. Translate EVERY listed function into real code with actual logic
302+ 3. Use 'does' column text to implement meaningful function bodies
303+ 4. Match signatures EXACTLY from the 'sig' column
304+ 5. Include imports needed for the types and calls referenced
305+ 6. Preserve method grouping under their classes""" ,
238306 }
239307
240308 # Language-specific guidance appended to prompt
@@ -248,7 +316,7 @@ def get_token_reproduction_prompt(spec: str, fmt: str, file_name: str, language:
248316 "sql" : "Use standard SQL: CREATE TABLE/VIEW/FUNCTION, proper column types, constraints." ,
249317 }
250318
251- max_spec = 8000
319+ max_spec = 12000
252320 spec_truncated = spec [:max_spec ] if len (spec ) > max_spec else spec
253321
254322 language_norm = (language or "python" ).strip ().lower ()
@@ -267,15 +335,20 @@ def get_token_reproduction_prompt(spec: str, fmt: str, file_name: str, language:
267335 lang_hint = lang_hints .get (language_norm , '' )
268336 lang_hint_line = f"\n { lang_hint } " if lang_hint else ''
269337
270- prompt = f"""Generate { lang_label } code from this { fmt .upper ()} specification.
338+ prompt = f"""Generate complete { lang_label } source code from this { fmt .upper ()} specification.
271339{ format_hints .get (fmt , '' )} { lang_hint_line }
272340
341+ SPECIFICATION:
273342{ spec_truncated }
274343
275- Requirements:
276- - Complete, working { lang_label } code for { file_name }
277- - Include imports and type hints
278- - Implement all functions with actual logic
344+ REQUIREMENTS:
345+ - Output complete, working { lang_label } code for { file_name }
346+ - Include ALL imports at the top
347+ - Implement ALL classes, methods, and functions listed in the specification
348+ - Use type hints throughout
349+ - Write real logic based on descriptions/intents, NOT placeholder stubs
350+ - Match function signatures EXACTLY as specified
351+ - Output ONLY the code, no explanations
279352
280353```{ language_norm }
281354"""
0 commit comments