File size: 3,074 Bytes
391c43e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
 * Python Domain Prompt
 *
 * Per-project .PROMPT.md content for Python projects.
 * Guides the AI to write Python scripts for the Pyodide environment.
 */

export const PYTHON_DOMAIN_PROMPT = `PROJECT TYPE: Python (Pyodide β€” browser-based CPython)

This project runs Python scripts in the browser via Pyodide. Scripts execute in a Web Worker and output to a terminal panel.

ENVIRONMENT:
- Python 3.11+ (CPython compiled to WebAssembly)
- Standard library available (math, json, re, collections, itertools, functools, etc.)
- Entry point: /main.py

INSTALLING PACKAGES (REQUIRED for any non-stdlib module):
- ALL third-party packages must be installed via micropip BEFORE importing:
  import micropip
  await micropip.install("numpy")
  await micropip.install("matplotlib")
  import numpy as np
  import matplotlib.pyplot as plt
- This includes numpy, pandas, scipy, matplotlib, etc. β€” none are pre-loaded
- Always put micropip.install() calls at the top of the script, before any imports of those packages

VISUAL OUTPUT (matplotlib, etc.):
- Save figures to /output/ directory β€” they appear in the Preview panel:
  import matplotlib.pyplot as plt
  plt.plot([1, 2, 3], [1, 4, 9])
  plt.savefig("/output/plot.png")
  plt.close()
- The /output/ directory is scanned after execution
- Supported formats: .png, .jpg, .svg, .html
- You can also write .html files to /output/ β€” they will be rendered in the Preview panel

FILE I/O:
- Read/write files using standard open():
  with open("/data.txt", "w") as f:
      f.write("Hello")
  with open("/data.txt", "r") as f:
      content = f.read()
- Files persist within the project's virtual filesystem
- Use /output/ for files you want visible in Preview

PRINT OUTPUT:
- print() writes to the Terminal panel (stdout)
- Errors and tracebacks appear in red (stderr)
- Use print() for all text output β€” there is no GUI/tkinter

FILE STRUCTURE EXAMPLE:
/main.py          β€” Entry point (auto-executed)
/utils.py         β€” Helper modules
/data.csv         β€” Data files
/output/plot.png  β€” Visual output (shown in Preview)
/output/index.html β€” HTML output (rendered in Preview)

CONSTRAINTS:
- No network access (no urllib, no requests to external URLs)
- No subprocess or os.system()
- No threading (single-threaded WebAssembly)
- No input() β€” scripts are non-interactive
- No tkinter or GUI libraries (use matplotlib savefig for visuals)
- Scripts are terminated after 30 seconds

DO NOT:
- Use input() or interactive prompts
- Try to access the network or spawn processes
- Create build configs or package.json

EXECUTION:
- Run scripts with: python main.py (or python3 main.py)
- Output appears in the Terminal panel and is returned to you
- Scripts timeout after 30 seconds

PREVIEW:
- Use 'preview /path' to show a file in the Preview panel
- Files written to /output/ (e.g., .html, .png) can be previewed
- Example: python main.py && preview /output/chart.html

IMPORTANT:
- Use print() for all text output β€” it appears in the Terminal
- For visual output, save to /output/ and it shows in Preview`;