一键导入
sync-wb-nb
Propagate a change made in a Wolfbook .wb notebook into the paired .nb notebook so the two stay identical. Use immediately after every .wb edit.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Propagate a change made in a Wolfbook .wb notebook into the paired .nb notebook so the two stay identical. Use immediately after every .wb edit.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
The write-side inverse of /check-pipeline and the pipeline-auditor — read a Pipeline/ doc (and/or an audit report) and EDIT the code accordingly: apply an optimization the pipeline describes, correct code the pipeline (backed by your authoritative notes) shows is wrong, or bring the code in line with the documented behavior. Use when the user wants the code changed based on the pipeline. High-stakes: bakes in live-editor editing, mirror sync, ground-truth protection, and control-gating. Proposes a diff and gets approval before any risky edit.
Check that a code and its Pipeline/ .md are still compatible — that every symbol, cell number, data file, and data-flow claim in the pipeline doc still matches the current code (drift detection). Use after editing a documented notebook/engine/script, before trusting a pipeline doc, or on request ("does the pipeline still match the code?"). Reports mismatches (missing symbols, wrong cell numbers, renamed functions, changed I/O) and can update the doc. Companion to /write-pipeline.
Write (or refresh) a Pipeline/ .md that documents the calculation-and-code pipeline of ANY large code in the project — a notebook (.wb/.nb/.ipynb), an engine, or a script. Use when a load-bearing code has no pipeline doc yet, when a new main code is added, or when the user asks to "write the pipeline" for a file. Produces the standard Purpose / data-flow diagram / key-symbols table / gotchas / inputs-outputs format used across Pipeline/, cross-referenced to the project's authoritative notes (workbook.tex).
Playbook for the Wolfbook MCP tools — driving the LIVE Wolfram kernel and a .wb/.nb notebook in VS Code from Claude Code (read/search/edit/run cells, evaluate expressions, checkpoint/restore kernel state, step-debug, look up symbols, find paclets, search INSPIRE/arXiv papers). Use whenever working through the Wolfbook MCP (mcp__wolfbook__*) instead of headless wolframscript: pick the right tool, avoid the multi-statement reparse and runCell bridge bugs, and use kernel checkpoints for safe rollbacks. Complements the wolfram-headless skill (which covers headless .wls runs).
Run heavy Wolfram Language (wolframscript) computations from Claude Code reliably, and diagnose the misleading "The product exited because of a license error". Use whenever invoking wolframscript on a non-trivial computation, when a wolframscript job dies with a "license error" despite a valid license, or when Wolfram numerics give silently wrong results in headless runs.
Convert Mathematica .nb or .m files to Wolfbook .wb format so they open and run in VS Code. Use when bringing existing .nb/.m files into Wolfbook, or to make an existing .wb bridge-safe.
| name | sync-wb-nb |
| description | Propagate a change made in a Wolfbook .wb notebook into the paired .nb notebook so the two stay identical. Use immediately after every .wb edit. |
Keep a .wb and its paired .nb mirror in sync. We edit/test in the .wb (Wolfbook MCP);
the .nb is the mirror we cannot run but the user opens in desktop Mathematica. Direction is
always .wb → .nb (the .wb is authoritative; /nb-to-wolfbook handles the initial
reverse conversion). Set the default pair via defaultWb/defaultNb at the top of
sync-wb-nb.wls, or pass absolute paths as trailing args.
Two operations, one helper script (sync-wb-nb.wls, in this skill's directory):
replace/insert/verify/stability) — propagate ONE edited cell,
preserving the rest of a hand-crafted .nb (its outputs, manual tweaks). This is the
standing-rule after editing the main notebook.regenerate — rebuild the WHOLE .nb from the .wb so it opens in Mathematica
looking normal: syntax-coloured code, styled headings. Use it to create a fresh .nb
(e.g. a new generated/*.wb) or after a wholesale rewrite. It overwrites the .nb,
so never use it to patch one cell of a hand-crafted notebook..wb: snippet sync, immediately. Add to your
CLAUDE.md:
Always run
/sync-wb-nbimmediately after editing or adding cells in any.wb.
.nb: regenerate.WLS=".claude/skills/sync-wb-nb/sync-wb-nb.wls" # path from project root
wolframscript -file "$WLS" regenerate "<abs wbPath>" "<abs nbPath>"
What it produces, cell by cell from the .wb:
Cell[BoxData[…], "Input"] parsed by the front-end parser
(FrontEndUndocumentedTestFEParserPacket), which is what makes Mathematica colour them (blue user symbols, green pattern vars, black built-ins). A plain Cell["string","Input"]`
shows up all black — that was the bug this mode fixes.Title/Section/Subsection/Subsubsection (by #/##/###/####)
and Text styles, with **bold**/`code`/[t](l) markup stripped.(* … *) comments → lifted into an adjacent Text cell (the box parser drops
comments, same as the snippet engine).Hard-won rules baked into the mode (don't undo them):
Export["generated/x.nb"] lands in wolframscript's own
cwd, not the project — the file silently doesn't change and you debug a ghost. The mode
re-reads the exact path and asserts the file is a Notebook, contains BoxData, and has
one coloured cell per code cell.MakeBoxes. The FE parser preserves the source line breaks and the
literal expression; MakeBoxes reassociates Times in product-numerator fractions (the
stability hazard below) and would risk changing the maths on a whole-file rewrite..nb is open in Mathematica, the stale in-memory copy
must be closed WITHOUT saving (or File ▸ Revert) — otherwise a save overwrites the rebuild.regenerate is not /sync-wb-nb-incremental: it is the same skill's bulk path. Re-run it
whenever the .wb changes (there is no cheaper incremental update for a generated/ notebook).
For the main hand-crafted .nb: backup, box conversion, stability gate, unique-target
assertions, post-write verification with automatic restore — all in sync-wb-nb.wls. One
Bash call per operation:
WLS=".claude/skills/sync-wb-nb/sync-wb-nb.wls" # path from project root
wolframscript -file "$WLS" stability "<snippet>" # is the .wb cell box-stable?
wolframscript -file "$WLS" replace "<wbSnippet>" ["<nbOldSnippet>"] # sync an edited cell
wolframscript -file "$WLS" insert "<wbSnippet>" "<nbAnchorSnippet>" # sync a new cell
wolframscript -file "$WLS" verify "<snippet>" # check a cell is in sync
<snippet> selects the cell and must be a single token (a symbol name defined in the
cell, e.g. "myFunction"): in box structures myFunc[x_ never matches — myFunc, [,
x_ are separate strings.replace takes a second snippet when the OLD .nb cell doesn't contain the new token
(e.g. new code introduces newSymbol; locate the old cell by one of its own existing tokens).insert needs a snippet of the .nb cell the new cell goes AFTER.<wbPath> <nbPath> (absolute paths) as trailing args.PASS: … = success. Exit 1 + FAIL: … = nothing (or a restored backup) on disk.Workflow per synced cell: stability → fix source if it fails → replace/insert →
done (verification is built in). Report the PASS lines.
(* … *)
comments, so a commented cell would differ between the two files. Notes go in a separate
text cell or the workbook.a*b/c)
reassociates Times through FractionBox and breaks ===; atomic-numerator fractions
are stable. Fix by assigning the numerator to a local (c2 = a*b; … c2/c), re-validate
the maths numerically, then sync. The script refuses to write unstable code./tmp/sync-wb-nb-backup-*.nb)..nb cell must parse === the .wb code.Only the Wolfram kernel can convert code text to Input boxes (MakeBoxes or the front-end
parser) and parse .nb box structures back; a Python splice would also leave the .nb's
internal byte-offset cache stale. Import→modify→Export regenerates it correctly and
preserves outputs.
Snippet modes:
ToString[boxes, InputForm, PageWidth -> Infinity] — default
ToString line-wraps and can split a token across a \ continuation, silently breaking
StringContainsQ.Position+Select(SameQ)+ReplacePart, never nb /. oldCell -> new: a literal Cell as a /. LHS can silently fail to fire. UUID-anchored /. rules
are fine for insertion (the anchor cell is matched by its UUID option, not its body)..wb cells (kind 1) are NOT touched by the snippet modes; mirror them manually as
Cell[text, "Subsection"/"Text"] matching neighbouring styles. (regenerate DOES handle
them — it rebuilds the whole file.)regenerate mode:
{BoxData[…], …}; take [[1]]. It yields the multi-line list-form
BoxData[{box, "\n", box, …}] (the FE's native typed-input shape — it colours correctly);
Import later normalises that to a single RowBox. So the faithfulness check must NOT
compare held expressions of the two shapes — it just asserts every stored cell re-parses
without $Failed.(* *) comments (with the True flag too — tested), so comments are
lifted to a Text cell.General:
regenerate the absolute output path is load-bearing, not just convenient.