Install
$ agentstack add skill-milind220-ki-stack-ki-stack-file-surgery ✓ scanned · ✓ verified — works with Claude Code, Cursor, and more.
Security review
✓ PassedNo issues found. Passed automated security review. · v0.1.0 How review works →
- ✓ Prompt-injection patterns
- ✓ Secret / credential exfiltration
- ✓ Dangerous shell & filesystem operations
- ✓ Untrusted network calls
- ✓ Known-malicious package signatures
What it can access
- ✓ Network access No
- ✓ Filesystem access No
- ✓ Shell / process execution No
- ✓ Environment & secrets No
- ✓ Dynamic code execution No
From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.
About
ki-stack-file-surgery
Purpose
This skill teaches the agent how to use kiutils-rs for structural KiCad file edits.
It is the canonical ki-stack skill for:
- offline KiCad file mutation
- lossless read/modify/write flows
- project, library table, design rule, and board metadata edits
- structural transforms where preserving unknown syntax matters
When to use it
Use this skill when:
- no live KiCad session is needed
- the edit is inherently file-structural
- preserving formatting and unknown tokens matters
- the task is deterministic enough to justify a small Rust transform
Do not use this skill when:
- the task is naturally a live board automation workflow
- the task is just rendering or verification
- the agent only needs a tiny text patch that is not semantically structural
Shared assumptions
- Prefer
kiutils-rsfor offline structural changes. - Default to lossless output.
- Inspect before writing custom Rust when possible.
- Use typed setter/upsert/remove APIs for writeable edits.
Phase 1: Orient
- Find the relevant KiCad files:
``bash skills/ki-stack/bin/kicad-project-find ``
- Identify the file type before writing code:
.kicad_pcb.kicad_mod.kicad_dru.kicad_profp-lib-tablesym-lib-table
- If the file type is supported by the stable public
kiutils-rsAPI, continue.
- If the task actually wants live state or selection-aware behavior, route to
ki-stack-liveinstead.
Phase 2: Inspect
Before writing custom Rust, inspect the file shape.
Preferred command:
skills/ki-stack/bin/kiutils-inspect path/to/file.kicad_pcb --show-unknown --show-diagnostics --show-canonical
Useful flags:
--json--show-cst--show-canonical--show-unknown--show-diagnostics
Inspection should tell you whether:
- the file parses cleanly
- unknown tokens exist and should be preserved
- the change should target typed APIs rather than low-level internals
Phase 3: Execute
Write the smallest Rust program that performs the structural edit.
Canonical safe pattern:
use kiutils_rs::{PcbFile, WriteMode};
fn main() -> Result> {
let mut doc = PcbFile::read("input.kicad_pcb")?;
doc.upsert_property("EditedBy", "ki-stack");
doc.write_mode("output.kicad_pcb", WriteMode::Lossless)?;
Ok(())
}
Preferred edit style:
set_*upsert_*remove_*
Avoid this pattern for writeable mutations:
- mutate through
ast_mut()and then callwrite()
That is explicitly a guardrail in the library docs.
Phase 4: Verify
Structural file surgery is not done when the program compiles. It is done when the output is checked.
Preferred verification loop:
- inspect the output file again
- render the relevant artifact with
ki-stack-renderif visual output matters - run DRC/ERC if the file type and change warrant it
- report lossless vs canonical write mode explicitly
For boards, it is often reasonable to follow with:
skills/ki-stack/bin/kicad-drc-json output.kicad_pcb drc.json
Phase 5: Report
Always report:
- input file
- output file
- file type
- whether lossless or canonical write mode was used
- the exact Rust program or command used
- any render or check artifacts produced
Good transform shape
Write short single-purpose transforms.
Preferred shape:
- read one document type explicitly
- apply a small number of typed mutations
- write in lossless mode unless normalization is requested
- exit with a clear error if parsing or writing fails
Helper assets
References:
skills/ki-stack/references/kiutils-recipes.md
Helpers:
skills/ki-stack/bin/kicad-project-findskills/ki-stack/bin/kiutils-inspect
Templates:
skills/ki-stack/templates/rust-kiutils-main.rs
Guardrails
- If the task wants live editor context, do not force a file-surgery path.
- If the file type is unsupported by the stable public API, say so clearly.
- Default to lossless output.
- Do not mutate through
ast_mut()and then write. - If the change is electrically meaningful, follow with CLI checks instead of trusting the transform alone.
Completion states
DONE: transform completed and output verifiedDONE_WITH_CONCERNS: transform completed but verification is partial or a file-type caveat existsBLOCKED: parse, write, or toolchain setup failed irrecoverablyNEEDS_CONTEXT: target files, desired mutation, or input/output paths are unclear
Source & license
This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.
- Author: Milind220
- Source: Milind220/Ki-Stack
- License: MIT
Install and usage instructions live in the source repository linked above.
Reviews
No reviews yet — be the first.
Write a review
Versions
- v0.1.0 Imported from the upstream source.