/klayoutclaw:nanodevice_flakedetect_samfrom klayoutclaw
Assists flake detection by wrapping four standard detectors, generating SAM2 prompt candidate images, and optionally refining selections with local SAM2. Useful for graphene/graphite flake detection tasks.
Ships in klayoutclaw. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Use this skill as the default graphite/backgate and graphene detect flow for
flake-detect tasks, prompt candidate images, manual point selection, or a SAM
rerun of the normal nanodevice_flakedetect_detect flow. Baseline detector
passes remain part of this flow for source grids and candidate 09 fallback.
Before taking an action, read the matching reference first. This is a hard gate, not background advice.
You MUST read the full matching reference file before the action it governs,
using a command that prints the file contents such as cat, sed -n '1,240p',
or Get-Content. Keyword search, rg, file listings, partial excerpts, or
memory of a previous run do not satisfy this requirement.
After reading references for a stage, write or append a short sidecar note under
the detect output directory, for example <detect_dir>/reference_reads.md, with
the stage name and exact reference paths read. Do not continue to the governed
action until that note exists.
| Before you... | Read this reference |
|---|---|
| Run any SAM wrapper script, use batch-runner SAM mode, handle stale outputs, or interpret candidate sidecars | references/contract-and-runtime.md |
Create or rewrite graphite_manual_prompts.json | references/graphite-prompts.md |
| Generate graphite SAM candidates after manual prompts | references/contract-and-runtime.md and references/graphite-prompts.md |
| Choose or freeze a graphite prompt rank | references/graphite-prompts.md and references/visual-review.md |
Generate graphite_on_top_mask.png or prepare graphene with a graphite prior | references/contract-and-runtime.md and references/graphene-prompts.md |
Create or rewrite graphene_manual_prompts.json | references/graphene-prompts.md |
| Generate graphene SAM candidates after manual prompts | references/contract-and-runtime.md and references/graphene-prompts.md |
| Choose or freeze a graphene prompt rank, including zero-overlap retries | references/graphene-prompts.md and references/visual-review.md |
Continue to detections.json, combine, gdsalign, output GDS, or score | references/contract-and-runtime.md, references/visual-review.md, and the material prompt references for any material whose selection changed |
If a required reference was not read immediately before the governed stage, stop and read it before proceeding. If you are unsure whether it was read, treat it as unread.
If the user asks for a fresh rerun, fresh point selection, or says not to reuse old selections, old prompt JSON, visual selection JSON, candidate images, candidate mask caches, and prompt sidecars are invalid evidence. Alignment products may still be reused only when the user explicitly allows align reuse.
graphite_source_grid_80px.png.graphite_manual_prompts.json.--manual-prompts-json ... --use-sam2 (batch runners should pass this
internally; users should not need a separate --use-sam mode flag).graphite_candidate_montage.png and individual candidates.graphite_visual_selection.json with one frozen rank and reason.graphite_mask.png exists.graphite_on_top_mask.png only after final graphite is frozen.<detect_dir>/../align/footprint_mask.png in code.graphene_manual_prompts.json.--manual-prompts-json ... --use-sam2; the wrapper injects the required footprint
internally, and users should not need a separate --use-sam mode flag.graphite_on_top_mask.png; if overlap is zero, replace prompts and rerun.detections.json, combine, gdsalign, output, and score only
after both material visual selections are frozen.*_prompt_candidates.json exist. For graphene, every baseline/grid pass,
SAM candidate generation, and final --prompt-rank rerun must use the wrapper-forced
<detect_dir>/../align/footprint_mask.png; do not rely on a manual --footprint-mask argument. SAM2 score and automatic rank are hints only.--prompt-rank is zero-based.
candidate_01 means rank 0; candidate_09 means rank 8.detections.json, combine, gdsalign, or score while graphite
or graphene still needs manual prompts or visual rank selection.graphite_on_top_mask.png is available. Rewrite prompts and regenerate
candidates until the selected graphene mask intersects the graphite prior.graphene_mask.png; the prior is an input cue, never graphene output.Use the four wrapper scripts with the same output contract as the baseline material detectors:
scripts/graphite.pyscripts/graphene.pyscripts/bottom_hbn.pyscripts/top_hbn.pyTop hBN and bottom hBN delegate to baseline behavior. They do not create SAM prompt candidates.
Use the Python environment requested by the user. If not specified, use
instrMCPdev.
In PowerShell, set UTF-8 I/O before detector scripts:
$env:PYTHONIOENCODING='utf-8'
When writing manual prompt JSON on Windows, write UTF-8 without BOM. The wrapper
loads prompt JSON with strict utf-8.
conda run -n instrMCPdev python skills\nanodevice_flakedetect_sam\scripts\graphite.py `
--image <bottom_part.jpg> --pixel-size <um/px> --output-dir <detect_dir>
conda run -n instrMCPdev python skills\nanodevice_flakedetect_sam\scripts\graphite.py `
--image <bottom_part.jpg> --pixel-size <um/px> --output-dir <detect_dir> `
--manual-prompts-json <detect_dir>\graphite_manual_prompts.json --use-sam2 `
--prompt-rank <rank>
conda run -n instrMCPdev python skills\nanodevice_flakedetect_sam\scripts\graphene.py `
--image <top_part.jpg> --pixel-size <um/px> --mirror `
--output-dir <detect_dir> --manual-prompts-json <detect_dir>\graphene_manual_prompts.json `
--use-sam2 --sam-target-frac 0.4 --prompt-rank <rank>
Normal detector output names are unchanged:
graphite_mask.png, graphite_contour.npy, graphite_result.jsongraphene_mask.png, graphene_contour.npy, graphene_result.jsonbottom_hbn_mask.png, bottom_hbn_contour.npy, bottom_hbn_result.jsontop_hbn_mask.png, top_hbn_contour.npy, top_hbn_result.jsondetections.jsonCandidate diagnostics:
<material>_source_grid_80px.png<material>_candidate_01_on_grid.png ... <material>_candidate_09_on_grid.png<material>_candidate_montage.png<material>_prompt_candidates.json<material>_candidate_masks.npz<material>_visual_selection.jsonreferences/contract-and-runtime.md (opens in a new tab)references/graphene-prompts.md (opens in a new tab)references/graphite-prompts.md (opens in a new tab)references/visual-review.md (opens in a new tab)scripts/bottom_hbn.py (opens in a new tab)scripts/contrast_enhance.py (opens in a new tab)scripts/graphene.py (opens in a new tab)scripts/graphite.py (opens in a new tab)scripts/sam_common.py (opens in a new tab)scripts/top_hbn.py (opens in a new tab)tests/test_contrast_enhance.py (opens in a new tab)tests/test_graphite_graphene_containment.py (opens in a new tab)tests/test_sam_device.py (opens in a new tab)tests/test_skill_graphite_prior_contract.py (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
flake-detection, sam2, prompt-assisted, nanodevice, graphene
npx claudepluginhub caidish/klayoutclaw --plugin klayoutclaw18 skills in this plugin
/autocadEdit and export layout geometry in the optional AutoCAD for Mac backend when the user selects AutoCAD or requests native DWG editing through its MCP server./displayklayoutclaw:displayToggle KLayout layer visibility on and off for better visualization. Use this skill when the user wants to show/hide layers, toggle layer display, change layer visibility, or focus on specific layers in KLayout. Also trigger when the user says things like "hide the metal layer", "show only mesa", "turn off layer 3", or wants to isolate layers for inspection./e2e-judgeklayoutclaw:e2e-judgeOther plugins' skills for the same job