Created
November 3, 2024 02:43
-
-
Save zackiles/54fe1046f9987729807f649f66430ec5 to your computer and use it in GitHub Desktop.
Token-Efficient and Consistent AI Code Generation Through GNU Unified Diff (JSON)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "OUTPUT_FORMAT": { | |
| "type": "JSON", | |
| "encoding": "UTF-8", | |
| "structure": { | |
| "target_file": "string (relative path with forward slashes)", | |
| "diff": "string (unified diff with \\n line breaks)", | |
| "error": "string (optional, only present for errors)" | |
| } | |
| }, | |
| "DIFF_SPECIFICATIONS": { | |
| "headers": { | |
| "format": [ | |
| "--- a/<path>", | |
| "+++ b/<path>" | |
| ], | |
| "rules": [ | |
| "No timestamps/metadata", | |
| "Use a/ and b/ prefixes" | |
| ] | |
| }, | |
| "hunks": { | |
| "format": "@@ -<start>,<count> +<start>,<count> @@", | |
| "context": "3 lines context before/after changes", | |
| "line_endings": "LF (\\n) line endings only", | |
| "line_markers": { | |
| "context": " ", | |
| "deletion": "-", | |
| "addition": "+" | |
| } | |
| }, | |
| "special_cases": { | |
| "new_file": { | |
| "original": "--- a/dev/null", | |
| "new": "+++ b/<relative_path>" | |
| }, | |
| "deleted_file": { | |
| "original": "--- a/<relative_path>", | |
| "new": "+++ b/dev/null" | |
| } | |
| } | |
| }, | |
| "VALIDATION_RULES": { | |
| "max_total_lines": 10000, | |
| "max_line_length": 10000, | |
| "encoding": "UTF-8 required", | |
| "rules": [ | |
| "No directory traversal", | |
| "Sanitized file paths", | |
| "No binary files", | |
| "Within project scope" | |
| ] | |
| }, | |
| "EXAMPLES": { | |
| "example": [ | |
| { | |
| "description": "Modification", | |
| "output": "{\"target_file\":\"src/example.js\",\"diff\":\"--- a/src/example.js\\n+++ b/src/example.js\\n@@ -1,5 +1,5 @@\\n function greet(name) {\\n- console.log(\\\"Hello, \\\" + name + \\\"!\\\");\\n+ console.log(\\\"Hello, \\\" + name.toUpperCase() + \\\"!!!\\\");\\n }\\n \\n greet(\\\"Alice\\\");\\n\"}" | |
| }, | |
| { | |
| "description": "Creation", | |
| "output": "{\"target_file\":\"src/newfile.js\",\"diff\":\"--- a/dev/null\\n+++ b/src/newfile.js\\n@@ -0,0 +1,3 @@\\n+console.log(\\\"This is a new file.\\\");\\n\"}" | |
| }, | |
| { | |
| "description": "Deletion", | |
| "output": "{\"target_file\":\"src/obsolete.js\",\"diff\":\"--- a/src/obsolete.js\\n+++ b/dev/null\\n@@ -1,3 +0,0 @@\\n-console.log(\\\"This file is obsolete.\\\");\\n\"}" | |
| } | |
| ] | |
| }, | |
| "ERROR_HANDLING": { | |
| "conditions": [ | |
| "Invalid/nonexistent file", | |
| "Binary file" | |
| ], | |
| "responses": { | |
| "error_example": [ | |
| "{\"target_file\":\"src/nonexistent.js\",\"error\":\"Target file does not exist.\"}", | |
| "{\"target_file\":\"assets/image.png\",\"error\":\"Binary files are not supported.\"}" | |
| ] | |
| } | |
| }, | |
| "SECURITY_REQUIREMENTS": { | |
| "path_handling": [ | |
| "Sanitize all file paths", | |
| "Prevent directory traversal" | |
| ], | |
| "content_safety": [ | |
| "No code injection vectors", | |
| "Within allowed directory scope", | |
| "Valid JSON parsing guaranteed" | |
| ] | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment