method-notebook-edit
Edits existing Jupyter .ipynb notebooks with cell anchors, backups, and metadata-preserving writes. Use when the user asks to patch an existing .ipynb.
- License 许可
- MIT
- 最近更新
- 2026-11-01
- Stars
- ★ 6
- Forks
- 0
01 前言 Front Matter
- name
- method-notebook-edit
- description
- Edits existing Jupyter .ipynb notebooks with cell anchors, backups, and metadata-preserving writes. Use when the user asks to patch an existing .ipynb.
- argument-hint
- <notebook.ipynb> --tag <anchor-tag> --source <file> [--markdown-source <file>] [--cell-type markdown|code]
02 资源文件 2
- 参考文档references/notebook-edit-policy.md1.0 KB
- 脚本scripts/notebook_edit.py9.4 KB
03 SKILL.md 正文
Guarded Notebook Editing
Run the script from the user's project root.
$SKILL_DIRanchors the script path;--notebook,--source, and--markdown-sourceresolve against--project-root(default: the current directory) and must stay project-relative.
Skill Value
- Problem it solves: Notebook edits can silently reorder cells, corrupt metadata, or break outputs when treated as plain text.
- Use when: The user asks to update, patch, or extend an existing notebook rather than generate a new one.
- Output: A backed-up notebook edit plus an anchor/change summary and validation notes.
- Ask only if: Only when target notebook, edit anchor, or desired insertion point is unclear.
- Do not do: Do not rewrite whole notebooks or discard metadata without explicit scope.
- Interaction: Check repo/config/chat evidence first. Ask one decision-changing question at a time; use the current harness's blocking question UI when available, otherwise present numbered choices and wait.
Existing notebooks are fragile because cell order, metadata, outputs, and JSON structure can drift silently. This skill edits them only through explicit anchors and always leaves a backup.
When This Skill Activates
- The user asks to modify an existing
.ipynbrather than generate a new script, Quarto file, or marimo notebook. - A SAP amendment, sensitivity analysis, Table 1 note, or figure-generation cell must be inserted into a notebook that already exists.
- A reviewer asks for a small notebook change and preserving execution history matters.
Workflow
- Prefer text-native formats for new work. If the user is starting fresh, route to the
method-workskill scaffolding instead of creating a new.ipynb. - Inspect the notebook structure and identify a unique anchor tag in
cell.metadata.tags. - Load the
method-notebook-standardsskill before adding or materially changing executable cells. Put the explanatory Markdown and new code body in small project files, then run:
SKILL_DIR="<absolute path of the directory containing this SKILL.md>";
python3 "$SKILL_DIR/scripts/notebook_edit.py" --notebook analysis/notebook.ipynb --tag sap-5-1 --markdown-source analysis/notebook-edits/new-cell.md --source analysis/notebook-edits/new-cell.py --cell-type code
- Review the generated backup, modified notebook diff, and
.edit-report.mdfile. - Run the notebook top-to-bottom with the project's normal runner if available. If no runner exists, surface that as a verification gap.
When an edit adds or changes code that reads, creates, transforms, validates, or renders analytical data or output, use the declared restricted data root for file-backed data (or the registered verified data connection). Synthetic, mock, sample, and fake-study data are allowed only when the user explicitly requests a clearly labeled test or demonstration; do not produce a synthetic study result. If the real source or QA provenance is unavailable, do not run the notebook and do not persist output. Record the real source location or registered extract ID/hash and validation evidence with each persisted study result. An explicitly requested synthetic test/demo may persist only as a clearly labeled non-study artifact with synthetic fixture or generator provenance, never in a study-output location.
Guarantees
- The script refuses absolute paths and paths outside the project root.
- The script requires exactly one matching anchor tag.
- The original notebook is copied to
<notebook>.bakbefore writing. - A code-cell insertion requires
--markdown-source; the tool inserts the explanatory Markdown directly before the code cell. - If
nbformatis installed, the script validates the notebook schema before and after editing. If it is missing, the script still performs structural JSON checks and prints install guidance.
What This Skill Does Not Do
- Does not rewrite or reorder existing cells.
- Does not execute notebooks inside the edit script; step 5 runs them only through the project's normal runner.
- Does not edit notebooks without a unique metadata tag anchor.
- Does not hide manual review;
.ipynbdiffs must be inspected before treating the change as complete.
References
@./references/notebook-edit-policy.md
04 同仓库更多 Skills
skill-one
Sample skill
disabled-skill
A skill with model invocation disabled
claude-only-skill
A skill restricted to Claude Code only
default-skill
暂无简介
custom-skill
暂无简介
method-write
Drafts, revises, and audits evidence-bound manuscripts, sections, abstracts, and reviewer responses with claim provenance. Use when scientific prose must be written or revised (entry point).