@shaik_munawar/doc-verify 1.0.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.
Files changed (43) hide show
  1. package/.github/workflows/test-action.yml +20 -0
  2. package/.github/workflows/verify.yml +43 -0
  3. package/README.md +265 -0
  4. package/action.yml +42 -0
  5. package/dist/ai/cache.js +42 -0
  6. package/dist/ai/prompt.js +483 -0
  7. package/dist/ai/repair.js +131 -0
  8. package/dist/auth.proto +54 -0
  9. package/dist/engine/mocks/network-shim.js +29 -0
  10. package/dist/engine/runner.js +15 -0
  11. package/dist/index.js +110198 -0
  12. package/dist/licenses.txt +4049 -0
  13. package/dist/pagent.exe +0 -0
  14. package/dist/parser/extracts.js +39 -0
  15. package/dist/proto/channelz.proto +564 -0
  16. package/dist/proto/protoc-gen-validate/LICENSE +202 -0
  17. package/dist/proto/protoc-gen-validate/validate/validate.proto +797 -0
  18. package/dist/proto/xds/LICENSE +201 -0
  19. package/dist/proto/xds/xds/data/orca/v3/orca_load_report.proto +58 -0
  20. package/dist/proto/xds/xds/service/orca/v3/orca.proto +36 -0
  21. package/dist/protoc-gen-validate/LICENSE +202 -0
  22. package/dist/protoc-gen-validate/validate/validate.proto +797 -0
  23. package/dist/runners/base-runner.js +96 -0
  24. package/dist/runners/bash-runner.js +12 -0
  25. package/dist/runners/c-runner.js +12 -0
  26. package/dist/runners/cpp-runner.js +12 -0
  27. package/dist/runners/go-runner.js +12 -0
  28. package/dist/runners/index.js +96 -0
  29. package/dist/runners/java-runner.js +12 -0
  30. package/dist/runners/javascript-runner.js +16 -0
  31. package/dist/runners/lua-runner.js +12 -0
  32. package/dist/runners/perl-runner.js +12 -0
  33. package/dist/runners/php-runner.js +12 -0
  34. package/dist/runners/python-runner.js +12 -0
  35. package/dist/runners/ruby-runner.js +12 -0
  36. package/dist/runners/rust-runner.js +12 -0
  37. package/dist/runners/typescript-runner.js +16 -0
  38. package/dist/utils/badge.js +27 -0
  39. package/dist/utils/patcher.js +23 -0
  40. package/dist/xds/LICENSE +201 -0
  41. package/dist/xds/xds/data/orca/v3/orca_load_report.proto +58 -0
  42. package/dist/xds/xds/service/orca/v3/orca.proto +36 -0
  43. package/package.json +42 -0
@@ -0,0 +1,483 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fixPrompt = exports.debugPrompt = exports.codeRepairSystemPrompt = void 0;
4
+ const codeRepairSystemPrompt = (language) => `
5
+ You are a Code Completion Agent for a documentation verification tool.
6
+ Your goal is to make a code snippet RUNNABLE in a standalone, sandboxed Docker environment.
7
+
8
+ ═══════════════════════════════════════════════════════════════════════════════
9
+ CRITICAL RULES
10
+ ═══════════════════════════════════════════════════════════════════════════════
11
+
12
+ 1. OUTPUT FORMAT:
13
+ - Output ONLY raw, executable code
14
+ - NO markdown formatting (no \`\`\` blocks)
15
+ - NO explanations, comments about changes, or preamble
16
+ - NO "Here is the fixed code:" type messages
17
+
18
+ 2. CODE INTEGRITY - NEVER CORRECT BUGS:
19
+ - PRESERVE the original code EXACTLY as written
20
+ - DO NOT fix typos (e.g., console.logg stays as console.logg)
21
+ - DO NOT fix syntax errors in the original code
22
+ - DO NOT fix logical errors
23
+ - DO NOT rename misspelled functions/variables
24
+ - The goal is to TEST if the documentation code works, not FIX it
25
+
26
+ 3. WHAT YOU CAN ADD:
27
+ - Mock undefined variables/imports that are EXTERNAL dependencies
28
+ - Add required boilerplate (package main, fn main, etc.)
29
+ - Wrap async code in appropriate patterns
30
+ - Add missing imports for STANDARD LIBRARY only
31
+
32
+ 4. MOCKING STRATEGY:
33
+ - Mock ONLY external dependencies (APIs, databases, third-party libs)
34
+ - Mock external libraries with minimal fake implementations
35
+ - DO NOT mock or fix code that the user wrote incorrectly
36
+
37
+ 5. ASYNC HANDLING:
38
+ - ONLY wrap in async patterns if code contains 'await' keyword
39
+ - Simple code WITHOUT 'await' should NEVER be wrapped
40
+ - Each language has its own async pattern (see below)
41
+
42
+ 6. COMPLETENESS:
43
+ - Code must be ready to execute with NO modifications
44
+ - All external imports/requires must be mocked or removed
45
+ - Keep all original code errors intact for verification
46
+
47
+ ═══════════════════════════════════════════════════════════════════════════════
48
+ LANGUAGE-SPECIFIC RULES
49
+ ═══════════════════════════════════════════════════════════════════════════════
50
+
51
+ ${getLanguageRules(language)}
52
+
53
+ ═══════════════════════════════════════════════════════════════════════════════
54
+ COMMON PATTERNS
55
+ ═══════════════════════════════════════════════════════════════════════════════
56
+
57
+ HTTP/API Mocking:
58
+ • Return realistic JSON structures
59
+ • Include common fields (id, status, data, message)
60
+ • Mock both success and the expected response type
61
+
62
+ Database Mocking:
63
+ • Return arrays/lists for queries
64
+ • Return objects for single-record fetches
65
+ • Include realistic field names
66
+
67
+ Environment Variables:
68
+ • Hardcode mock values instead of process.env/os.environ
69
+ • Use realistic-looking but fake values
70
+
71
+ File System:
72
+ • Mock fs/file operations to return sample strings
73
+ • Don't actually read/write files
74
+
75
+ ═══════════════════════════════════════════════════════════════════════════════
76
+ REMEMBER
77
+ ═══════════════════════════════════════════════════════════════════════════════
78
+
79
+ ✓ Output ONLY executable code
80
+ ✓ PRESERVE original code exactly (including typos/bugs)
81
+ ✓ Mock only EXTERNAL dependencies
82
+ ✓ Add boilerplate if needed (main function, imports)
83
+ ✓ Simple code = no wrapping
84
+ ✗ NEVER fix typos (console.logg stays console.logg)
85
+ ✗ NEVER fix syntax errors in user's code
86
+ ✗ NEVER fix logical errors
87
+ ✗ NO markdown, NO explanations
88
+ `;
89
+ exports.codeRepairSystemPrompt = codeRepairSystemPrompt;
90
+ // ═══════════════════════════════════════════════════════════════════════════════
91
+ // LANGUAGE-SPECIFIC RULES (injected dynamically)
92
+ // ═══════════════════════════════════════════════════════════════════════════════
93
+ function getLanguageRules(language) {
94
+ const lang = language.toLowerCase();
95
+ switch (lang) {
96
+ case 'js':
97
+ case 'javascript':
98
+ case 'ts':
99
+ case 'typescript':
100
+ return javaScriptRules;
101
+ case 'py':
102
+ case 'python':
103
+ return pythonRules;
104
+ case 'go':
105
+ case 'golang':
106
+ return goRules;
107
+ case 'java':
108
+ return javaRules;
109
+ case 'rust':
110
+ case 'rs':
111
+ return rustRules;
112
+ case 'ruby':
113
+ case 'rb':
114
+ return rubyRules;
115
+ case 'php':
116
+ return phpRules;
117
+ case 'bash':
118
+ case 'sh':
119
+ case 'shell':
120
+ return bashRules;
121
+ case 'c':
122
+ return cRules;
123
+ case 'cpp':
124
+ case 'c++':
125
+ return cppRules;
126
+ case 'perl':
127
+ case 'pl':
128
+ return perlRules;
129
+ case 'lua':
130
+ return luaRules;
131
+ default:
132
+ return javaScriptRules;
133
+ }
134
+ }
135
+ const javaScriptRules = `▸ JAVASCRIPT / TYPESCRIPT
136
+ ─────────────────────────
137
+ Runtime: Node.js / Deno
138
+
139
+ • Simple code (no await): Return as-is
140
+ • Code with 'await': Wrap in async IIFE: (async () => { ... })();
141
+ • Mock imports:
142
+ - Instead of: import stripe from 'stripe'
143
+ - Use: const stripe = { /* mock implementation */ }
144
+ • Mock require:
145
+ - Instead of: const fs = require('fs')
146
+ - Use: const fs = { readFileSync: () => 'mock data' }
147
+
148
+ Example (simple - NO wrapping):
149
+ Input: console.log('Hello')
150
+ Output: console.log('Hello')
151
+
152
+ Example (with await - needs IIFE):
153
+ Input: const data = await fetch('/api'); console.log(data);
154
+ Output:
155
+ (async () => {
156
+ const fetch = async (url) => ({ json: async () => ({ message: 'mock' }) });
157
+ const data = await fetch('/api');
158
+ console.log(data);
159
+ })();
160
+
161
+ Example (mocking library):
162
+ Input: const payment = await stripe.charges.create({ amount: 100 });
163
+ Output:
164
+ (async () => {
165
+ const stripe = {
166
+ charges: {
167
+ create: async (opts) => ({ id: 'ch_mock', ...opts })
168
+ }
169
+ };
170
+ const payment = await stripe.charges.create({ amount: 100 });
171
+ console.log(payment);
172
+ })();`;
173
+ const pythonRules = `▸ PYTHON
174
+ ──────
175
+ Runtime: Python 3.11
176
+
177
+ • Simple code: Return as-is
178
+ • Code with 'await': Use asyncio.run()
179
+ • Mock imports at top of code
180
+ • Use classes, dicts, or namedtuples for mocks
181
+
182
+ Example (simple - NO wrapping):
183
+ Input: print('Hello')
184
+ Output: print('Hello')
185
+
186
+ Example (with missing variable):
187
+ Input: print(user.name)
188
+ Output:
189
+ class User:
190
+ def __init__(self):
191
+ self.name = "Test User"
192
+ user = User()
193
+ print(user.name)
194
+
195
+ Example (with await):
196
+ Input: data = await fetch_data()
197
+ Output:
198
+ import asyncio
199
+ async def fetch_data():
200
+ return {"result": "mock"}
201
+ async def main():
202
+ data = await fetch_data()
203
+ print(data)
204
+ asyncio.run(main())
205
+
206
+ Example (mocking library):
207
+ Input: import requests; r = requests.get('http://api.com')
208
+ Output:
209
+ class MockResponse:
210
+ status_code = 200
211
+ text = '{"data": "mock"}'
212
+ def json(self):
213
+ return {"data": "mock"}
214
+ class requests:
215
+ @staticmethod
216
+ def get(url):
217
+ return MockResponse()
218
+ r = requests.get('http://api.com')
219
+ print(r.json())`;
220
+ const goRules = `▸ GO
221
+ ──
222
+ Runtime: Go 1.20
223
+
224
+ • Must have: package main, import "fmt", func main()
225
+ • If code is just statements, wrap in func main()
226
+ • If code already has package/func main, return as-is
227
+
228
+ Example (needs wrapping):
229
+ Input: fmt.Println("Hello")
230
+ Output:
231
+ package main
232
+ import "fmt"
233
+ func main() {
234
+ fmt.Println("Hello")
235
+ }
236
+
237
+ Example (already complete):
238
+ Input: package main; import "fmt"; func main() { fmt.Println("Hi") }
239
+ Output: package main
240
+ import "fmt"
241
+ func main() { fmt.Println("Hi") }`;
242
+ const javaRules = `▸ JAVA
243
+ ────
244
+ Runtime: JDK 17
245
+
246
+ • Must have: public class Main with public static void main(String[] args)
247
+ • If code is statements only, wrap in Main class
248
+ • If code has class definition, ensure class is named 'Main'
249
+
250
+ Example (needs wrapping):
251
+ Input: System.out.println("Hello");
252
+ Output:
253
+ public class Main {
254
+ public static void main(String[] args) {
255
+ System.out.println("Hello");
256
+ }
257
+ }
258
+
259
+ Example (already has class):
260
+ Input: public class Example { public static void main(String[] args) { System.out.println("Hi"); } }
261
+ Output:
262
+ public class Main {
263
+ public static void main(String[] args) {
264
+ System.out.println("Hi");
265
+ }
266
+ }`;
267
+ const rustRules = `▸ RUST
268
+ ────
269
+ Runtime: Rust 1.75
270
+
271
+ • Must have: fn main() { }
272
+ • Use println! macro for output
273
+ • If code is statements, wrap in fn main()
274
+
275
+ Example:
276
+ Input: println!("Hello");
277
+ Output:
278
+ fn main() {
279
+ println!("Hello");
280
+ }`;
281
+ const rubyRules = `▸ RUBY
282
+ ────
283
+ Runtime: Ruby 3.2
284
+
285
+ • Executable as-is (no main function needed)
286
+ • Use puts/print for output
287
+ • Mock requires with class/module definitions
288
+
289
+ Example:
290
+ Input: puts 'Hello'
291
+ Output: puts 'Hello'
292
+
293
+ Example (with missing class):
294
+ Input: puts user.name
295
+ Output:
296
+ class User
297
+ attr_accessor :name
298
+ def initialize
299
+ @name = "Test User"
300
+ end
301
+ end
302
+ user = User.new
303
+ puts user.name`;
304
+ const phpRules = `▸ PHP
305
+ ───
306
+ Runtime: PHP 8.2
307
+
308
+ • Must start with <?php
309
+ • Use echo for output
310
+ • Mock classes inline
311
+
312
+ Example:
313
+ Input: echo "Hello";
314
+ Output:
315
+ <?php
316
+ echo "Hello";
317
+ ?>
318
+
319
+ Example (with class):
320
+ Input: echo $user->name;
321
+ Output:
322
+ <?php
323
+ class User {
324
+ public $name = "Test User";
325
+ }
326
+ $user = new User();
327
+ echo $user->name;
328
+ ?>`;
329
+ const bashRules = `▸ BASH / SHELL
330
+ ────────────
331
+ Runtime: Alpine sh
332
+
333
+ • Executable as-is
334
+ • Use echo for output
335
+ • Mock commands with functions
336
+
337
+ Example:
338
+ Input: echo "Hello"
339
+ Output: echo "Hello"
340
+
341
+ Example (with command):
342
+ Input: result=$(curl http://api.com); echo $result
343
+ Output:
344
+ curl() { echo '{"data": "mock"}'; }
345
+ result=$(curl http://api.com)
346
+ echo $result`;
347
+ const cRules = `▸ C
348
+
349
+ Runtime: GCC 13
350
+
351
+ • Must have: #include <stdio.h> and int main()
352
+ • Use printf for output
353
+
354
+ Example:
355
+ Input: printf("Hello\\n");
356
+ Output:
357
+ #include <stdio.h>
358
+ int main() {
359
+ printf("Hello\\n");
360
+ return 0;
361
+ }`;
362
+ const cppRules = `▸ C++
363
+ ───
364
+ Runtime: G++ 13
365
+
366
+ • Must have: #include <iostream> and int main()
367
+ • Use std::cout for output
368
+
369
+ Example:
370
+ Input: std::cout << "Hello" << std::endl;
371
+ Output:
372
+ #include <iostream>
373
+ int main() {
374
+ std::cout << "Hello" << std::endl;
375
+ return 0;
376
+ }`;
377
+ const perlRules = `▸ PERL
378
+ ────
379
+ Runtime: Perl 5.38
380
+
381
+ • Executable as-is
382
+ • Use print for output
383
+
384
+ Example:
385
+ Input: print "Hello\\n";
386
+ Output: print "Hello\\n";`;
387
+ const luaRules = `▸ LUA
388
+ ───
389
+ Runtime: Lua 5.4
390
+
391
+ • Executable as-is
392
+ • Use print() for output
393
+
394
+ Example:
395
+ Input: print("Hello")
396
+ Output: print("Hello")`;
397
+ const debugPrompt = (originalCode, repairedCode, errorOutput, language = 'javascript') => `
398
+ You are a Code Debugging Agent. Analyze why repaired code failed to execute.
399
+
400
+ ═══════════════════════════════════════════════════════════════════════════════
401
+ YOUR TASK
402
+ ═══════════════════════════════════════════════════════════════════════════════
403
+
404
+ 1. Compare the ORIGINAL code with the REPAIRED code
405
+ 2. Identify what changes were made by the AI repair
406
+ 3. Explain WHY the repaired code still failed
407
+ 4. Suggest specific fixes
408
+
409
+ ═══════════════════════════════════════════════════════════════════════════════
410
+ CONTEXT
411
+ ═══════════════════════════════════════════════════════════════════════════════
412
+
413
+ LANGUAGE: ${language}
414
+
415
+ ▸ ORIGINAL CODE (from documentation):
416
+ \`\`\`${language}
417
+ ${originalCode}
418
+ \`\`\`
419
+
420
+ ▸ REPAIRED CODE (AI attempted fix):
421
+ \`\`\`${language}
422
+ ${repairedCode}
423
+ \`\`\`
424
+
425
+ ▸ ERROR OUTPUT:
426
+ \`\`\`
427
+ ${errorOutput}
428
+ \`\`\`
429
+
430
+ ═══════════════════════════════════════════════════════════════════════════════
431
+ RESPONSE FORMAT
432
+ ═══════════════════════════════════════════════════════════════════════════════
433
+
434
+ Respond with:
435
+
436
+ ## 🔄 Changes Made by AI
437
+ - List each modification the AI made to the original code
438
+
439
+ ## ❌ Why It Failed
440
+ - Explain the root cause of the error based on the error output
441
+
442
+ ## ✅ Suggested Fix
443
+ - Provide the corrected code that should work
444
+
445
+ ## 💡 Explanation
446
+ - Brief explanation of what went wrong and how the fix addresses it
447
+ `;
448
+ exports.debugPrompt = debugPrompt;
449
+ const fixPrompt = (brokenCode, errorMsg) => `
450
+ You are a Code Fixing Agent. A code snippet failed to run. Your task is to fix the code.
451
+
452
+ ═══════════════════════════════════════════════════════════════════════════════
453
+ CONTEXT
454
+ ═══════════════════════════════════════════════════════════════════════════════
455
+
456
+ ▸ BROKEN CODE:
457
+ \`\`\`
458
+ ${brokenCode}
459
+ \`\`\`
460
+
461
+ ▸ ERROR MESSAGE:
462
+ \`\`\`
463
+ ${errorMsg}
464
+ \`\`\`
465
+
466
+ ═══════════════════════════════════════════════════════════════════════════════
467
+ YOUR TASK
468
+ ═══════════════════════════════════════════════════════════════════════════════
469
+
470
+ 1. Analyze the broken code and error message
471
+ 2. Identify the root cause of the failure
472
+ 3. Provide a corrected version of the code that will run successfully
473
+
474
+ ═══════════════════════════════════════════════════════════════════════════════
475
+ RESPONSE FORMAT
476
+ ═══════════════════════════════════════════════════════════════════════════════
477
+
478
+ 1. Fix the error in the snippet (e.g., fix typos, syntax errors, missing commas).
479
+ 2. DO NOT add mocks or fake data. Keep it looking like a documentation example.
480
+ 3. DO NOT wrap it in async/await or IIFE functions.
481
+ 4. Return ONLY the raw code. No markdown.
482
+ `;
483
+ exports.fixPrompt = fixPrompt;
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.repairSnippet = repairSnippet;
7
+ exports.debug = debug;
8
+ exports.generateCleanFix = generateCleanFix;
9
+ const openai_1 = __importDefault(require("openai"));
10
+ const cache_js_1 = require("@/ai/cache.js");
11
+ const prompt_js_1 = require("@/ai/prompt.js");
12
+ // Lazy-initialized OpenAI client
13
+ let _openai = null;
14
+ function getOpenAI() {
15
+ if (!_openai) {
16
+ _openai = new openai_1.default({
17
+ baseURL: `${process.env.OPENAI_BASE_URL}/v1`,
18
+ apiKey: process.env.OPENAI_API_KEY,
19
+ });
20
+ }
21
+ return _openai;
22
+ }
23
+ // Language-specific code start patterns (ordered by priority within each language)
24
+ const languagePatterns = {
25
+ javascript: [/\(async\s*\(/, /async\s+(?:function|\()/, /const\s+\w/, /let\s+\w/, /var\s+\w/, /function\s+\w/, /import\s+/, /export\s+/, /module\./, /require\s*\(/],
26
+ typescript: [/\(async\s*\(/, /async\s+(?:function|\()/, /const\s+\w/, /let\s+\w/, /var\s+\w/, /function\s+\w/, /import\s+/, /export\s+/, /interface\s+/, /type\s+\w/],
27
+ python: [/^import\s+/m, /^from\s+\w+\s+import/m, /^class\s+\w/m, /^def\s+\w/m, /^async\s+def/m, /^print\s*\(/m, /^if\s+__name__/m],
28
+ go: [/^package\s+\w/m, /^import\s+/m, /^func\s+\w/m, /^type\s+\w/m],
29
+ java: [/^package\s+/m, /^import\s+/m, /^public\s+class/m, /^class\s+\w/m],
30
+ rust: [/^use\s+/m, /^fn\s+main/m, /^fn\s+\w/m, /^struct\s+/m, /^impl\s+/m],
31
+ ruby: [/^require\s+['"]/m, /^class\s+\w/m, /^def\s+\w/m, /^puts\s+/m, /^print\s+/m],
32
+ php: [/<\?php/, /^class\s+\w/m, /^function\s+\w/m, /^\$\w+\s*=/m],
33
+ bash: [/^#!/m, /^echo\s+/m, /^export\s+\w/m, /^\w+\s*\(\)\s*\{/m],
34
+ shell: [/^#!/m, /^echo\s+/m, /^export\s+\w/m],
35
+ c: [/^#include\s*</m, /^int\s+main/m, /^void\s+\w/m],
36
+ cpp: [/^#include\s*</m, /^int\s+main/m, /^class\s+\w/m, /^namespace\s+/m],
37
+ perl: [/^use\s+/m, /^my\s+/m, /^sub\s+\w/m, /^print\s+/m],
38
+ lua: [/^local\s+/m, /^function\s+\w/m, /^print\s*\(/m],
39
+ };
40
+ // Fallback patterns if language not found
41
+ const genericPatterns = [/^\/\//m, /^\/\*/m, /^#[^!]/m];
42
+ /**
43
+ * Extract clean code from AI response by finding the earliest code pattern
44
+ */
45
+ function extractCode(code, language) {
46
+ const lang = language.toLowerCase();
47
+ const patterns = languagePatterns[lang] || languagePatterns['javascript'] || genericPatterns;
48
+ // Find the earliest match across all patterns
49
+ let earliestIndex = -1;
50
+ for (const pattern of patterns) {
51
+ const match = code.search(pattern);
52
+ if (match >= 0 && (earliestIndex === -1 || match < earliestIndex)) {
53
+ earliestIndex = match;
54
+ }
55
+ }
56
+ // Only trim if we found a match AND it's not at the start
57
+ if (earliestIndex > 0) {
58
+ return code.substring(earliestIndex);
59
+ }
60
+ return code;
61
+ }
62
+ async function repairSnippet(index, originalCode, language = 'javascript') {
63
+ // Generate prompt with only the relevant language rules injected
64
+ const systemPrompt = (0, prompt_js_1.codeRepairSystemPrompt)(language);
65
+ const OPENAI_MODEL_NAME = process.env.OPENAI_MODEL_NAME;
66
+ try {
67
+ // Check cache first
68
+ const cached = (0, cache_js_1.getCachedRepair)(originalCode);
69
+ if (cached) {
70
+ return cached;
71
+ }
72
+ const response = await getOpenAI().chat.completions.create({
73
+ model: OPENAI_MODEL_NAME,
74
+ messages: [
75
+ { role: "system", content: systemPrompt },
76
+ { role: "user", content: originalCode }
77
+ ],
78
+ temperature: 0.1,
79
+ });
80
+ let repairedCode = response.choices[0].message.content || originalCode;
81
+ // Cleanup: remove markdown code blocks if the AI added them
82
+ const codeBlockMatch = repairedCode.match(/```(?:\w+)?\n?([\s\S]*?)```/);
83
+ if (codeBlockMatch) {
84
+ repairedCode = codeBlockMatch[1];
85
+ }
86
+ else {
87
+ // Remove any leading explanatory text before the actual code
88
+ repairedCode = extractCode(repairedCode, language);
89
+ }
90
+ repairedCode = repairedCode.trim();
91
+ (0, cache_js_1.saveCachedRepair)(originalCode, repairedCode);
92
+ return repairedCode;
93
+ }
94
+ catch (error) {
95
+ return originalCode; // Fallback to original
96
+ }
97
+ }
98
+ async function debug(originalCode, repairedCode, errorOutput, language = 'javascript') {
99
+ const prompt = (0, prompt_js_1.debugPrompt)(originalCode, repairedCode, errorOutput, language);
100
+ const response = await getOpenAI().chat.completions.create({
101
+ model: process.env.OPENAI_MODEL_NAME,
102
+ messages: [
103
+ { role: "system", content: prompt },
104
+ { role: "user", content: "Analyze the failure and provide debugging insights." }
105
+ ],
106
+ temperature: 0.3,
107
+ });
108
+ return response.choices[0].message.content || "No debug information available.";
109
+ }
110
+ async function generateCleanFix(brokenCode, errorMsg, language = 'javascript') {
111
+ const prompt = (0, prompt_js_1.fixPrompt)(errorMsg, brokenCode);
112
+ const response = await getOpenAI().chat.completions.create({
113
+ model: `${process.env.OPENAI_MODEL_NAME}`,
114
+ messages: [
115
+ { role: "system", content: prompt },
116
+ { role: "user", content: brokenCode }
117
+ ],
118
+ temperature: 0.1,
119
+ });
120
+ let fixed = response.choices[0].message.content || brokenCode;
121
+ // Strip markdown code blocks if present
122
+ const codeBlockMatch = fixed.match(/```(?:\w+)?\n?([\s\S]*?)```/);
123
+ if (codeBlockMatch) {
124
+ fixed = codeBlockMatch[1];
125
+ }
126
+ else {
127
+ // Use language-aware extraction to remove explanatory text
128
+ fixed = extractCode(fixed, language);
129
+ }
130
+ return fixed.trim();
131
+ }
@@ -0,0 +1,54 @@
1
+ syntax = "proto3";
2
+
3
+ package moby.filesync.v1;
4
+
5
+ option go_package = "auth";
6
+
7
+ service Auth{
8
+ rpc Credentials(CredentialsRequest) returns (CredentialsResponse);
9
+ rpc FetchToken(FetchTokenRequest) returns (FetchTokenResponse);
10
+ rpc GetTokenAuthority(GetTokenAuthorityRequest) returns (GetTokenAuthorityResponse);
11
+ rpc VerifyTokenAuthority(VerifyTokenAuthorityRequest) returns (VerifyTokenAuthorityResponse);
12
+ }
13
+
14
+ message CredentialsRequest {
15
+ string Host = 1;
16
+ }
17
+
18
+ message CredentialsResponse {
19
+ string Username = 1;
20
+ string Secret = 2;
21
+ }
22
+
23
+ message FetchTokenRequest {
24
+ string ClientID = 1;
25
+ string Host = 2;
26
+ string Realm = 3;
27
+ string Service = 4;
28
+ repeated string Scopes = 5;
29
+ }
30
+
31
+ message FetchTokenResponse {
32
+ string Token = 1;
33
+ int64 ExpiresIn = 2; // seconds
34
+ int64 IssuedAt = 3; // timestamp
35
+ }
36
+
37
+ message GetTokenAuthorityRequest {
38
+ string Host = 1;
39
+ bytes Salt = 2;
40
+ }
41
+
42
+ message GetTokenAuthorityResponse {
43
+ bytes PublicKey = 1;
44
+ }
45
+
46
+ message VerifyTokenAuthorityRequest {
47
+ string Host = 1;
48
+ bytes Payload = 2;
49
+ bytes Salt = 3;
50
+ }
51
+
52
+ message VerifyTokenAuthorityResponse {
53
+ bytes Signed = 1;
54
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NETWORK_SHIM = void 0;
4
+ exports.NETWORK_SHIM = `
5
+ // --- DOC-VERIFY NETWORK SHIM ---
6
+ (function() {
7
+ const log = (url) => console.log(\`[Network Mock] 200 OK -> \${url}\`);
8
+
9
+ // 1. Mock global fetch
10
+ global.fetch = async function(url, options) {
11
+ log(url);
12
+ return {
13
+ ok: true,
14
+ status: 200,
15
+ statusText: 'OK',
16
+ json: async () => ({ message: "Mocked Response", id: 1, success: true }),
17
+ text: async () => "Mocked Response",
18
+ headers: new Map(),
19
+ };
20
+ };
21
+
22
+ // 2. Mock 'https' and 'http' modules if imported via require
23
+ // Note: We can't easily mock 'require' modules in a running script without a loader,
24
+ // but we can mock the global implementations if they rely on globals.
25
+ // For a robust solution, we rely on the AI to see "require('https')" and replace it,
26
+ // OR we use the fetch shim which covers 90% of modern docs.
27
+ })();
28
+ // --- END SHIM ---
29
+ `;