SKILL.md
4.1 KB查看排版效果| 1 | --- |
| 2 | name: "jupyter-notebook" |
| 3 | description: "Use when the user asks to create, scaffold, or edit Jupyter notebooks (`.ipynb`) for experiments, explorations, or tutorials; prefer the bundled templates and run the helper script `new_notebook.py` to generate a clean starting notebook." |
| 4 | --- |
| 5 | |
| 6 | |
| 7 | # Jupyter Notebook Skill |
| 8 | |
| 9 | Create clean, reproducible Jupyter notebooks for two primary modes: |
| 10 | |
| 11 | - Experiments and exploratory analysis |
| 12 | - Tutorials and teaching-oriented walkthroughs |
| 13 | |
| 14 | Prefer the bundled templates and the helper script for consistent structure and fewer JSON mistakes. |
| 15 | |
| 16 | ## When to use |
| 17 | - Create a new `.ipynb` notebook from scratch. |
| 18 | - Convert rough notes or scripts into a structured notebook. |
| 19 | - Refactor an existing notebook to be more reproducible and skimmable. |
| 20 | - Build experiments or tutorials that will be read or re-run by other people. |
| 21 | |
| 22 | ## Decision tree |
| 23 | - If the request is exploratory, analytical, or hypothesis-driven, choose `experiment`. |
| 24 | - If the request is instructional, step-by-step, or audience-specific, choose `tutorial`. |
| 25 | - If editing an existing notebook, treat it as a refactor: preserve intent and improve structure. |
| 26 | |
| 27 | ## Skill path (set once) |
| 28 | |
| 29 | ```bash |
| 30 | export CODEX_HOME="${CODEX_HOME:-$HOME/.codex}" |
| 31 | export JUPYTER_NOTEBOOK_CLI="$CODEX_HOME/skills/jupyter-notebook/scripts/new_notebook.py" |
| 32 | ``` |
| 33 | |
| 34 | User-scoped skills install under `$CODEX_HOME/skills` (default: `~/.codex/skills`). |
| 35 | |
| 36 | ## Workflow |
| 37 | 1. Lock the intent. |
| 38 | Identify the notebook kind: `experiment` or `tutorial`. |
| 39 | Capture the objective, audience, and what "done" looks like. |
| 40 | |
| 41 | 2. Scaffold from the template. |
| 42 | Use the helper script to avoid hand-authoring raw notebook JSON. |
| 43 | |
| 44 | ```bash |
| 45 | uv run --python 3.12 python "$JUPYTER_NOTEBOOK_CLI" \ |
| 46 | --kind experiment \ |
| 47 | --title "Compare prompt variants" \ |
| 48 | --out output/jupyter-notebook/compare-prompt-variants.ipynb |
| 49 | ``` |
| 50 | |
| 51 | ```bash |
| 52 | uv run --python 3.12 python "$JUPYTER_NOTEBOOK_CLI" \ |
| 53 | --kind tutorial \ |
| 54 | --title "Intro to embeddings" \ |
| 55 | --out output/jupyter-notebook/intro-to-embeddings.ipynb |
| 56 | ``` |
| 57 | |
| 58 | 3. Fill the notebook with small, runnable steps. |
| 59 | Keep each code cell focused on one step. |
| 60 | Add short markdown cells that explain the purpose and expected result. |
| 61 | Avoid large, noisy outputs when a short summary works. |
| 62 | |
| 63 | 4. Apply the right pattern. |
| 64 | For experiments, follow `references/experiment-patterns.md`. |
| 65 | For tutorials, follow `references/tutorial-patterns.md`. |
| 66 | |
| 67 | 5. Edit safely when working with existing notebooks. |
| 68 | Preserve the notebook structure; avoid reordering cells unless it improves the top-to-bottom story. |
| 69 | Prefer targeted edits over full rewrites. |
| 70 | If you must edit raw JSON, review `references/notebook-structure.md` first. |
| 71 | |
| 72 | 6. Validate the result. |
| 73 | Run the notebook top-to-bottom when the environment allows. |
| 74 | If execution is not possible, say so explicitly and call out how to validate locally. |
| 75 | Use the final pass checklist in `references/quality-checklist.md`. |
| 76 | |
| 77 | ## Templates and helper script |
| 78 | - Templates live in `assets/experiment-template.ipynb` and `assets/tutorial-template.ipynb`. |
| 79 | - The helper script loads a template, updates the title cell, and writes a notebook. |
| 80 | |
| 81 | Script path: |
| 82 | - `$JUPYTER_NOTEBOOK_CLI` (installed default: `$CODEX_HOME/skills/jupyter-notebook/scripts/new_notebook.py`) |
| 83 | |
| 84 | ## Temp and output conventions |
| 85 | - Use `tmp/jupyter-notebook/` for intermediate files; delete when done. |
| 86 | - Write final artifacts under `output/jupyter-notebook/` when working in this repo. |
| 87 | - Use stable, descriptive filenames (for example, `ablation-temperature.ipynb`). |
| 88 | |
| 89 | ## Dependencies (install only when needed) |
| 90 | Prefer `uv` for dependency management. |
| 91 | |
| 92 | Optional Python packages for local notebook execution: |
| 93 | |
| 94 | ```bash |
| 95 | uv pip install jupyterlab ipykernel |
| 96 | ``` |
| 97 | |
| 98 | The bundled scaffold script uses only the Python standard library and does not require extra dependencies. |
| 99 | |
| 100 | ## Environment |
| 101 | No required environment variables. |
| 102 | |
| 103 | ## Reference map |
| 104 | - `references/experiment-patterns.md`: experiment structure and heuristics. |
| 105 | - `references/tutorial-patterns.md`: tutorial structure and teaching flow. |
| 106 | - `references/notebook-structure.md`: notebook JSON shape and safe editing rules. |
| 107 | - `references/quality-checklist.md`: final validation checklist. |
文件内容是平台检查时读出的文本,只供查看。平台不会运行包里的任何脚本或程序。

