by barrett-land
Install ADOM'S OWN machine pin/contact library into the user's EDA — KiCad, Altium Designer, OR Fusion 360. Fetches the six machine components from the wiki, converts them with adom-lbr into 'Adom Machine Symbols' + 'Adom Machine Footprints' (one combined .lbr for Fusion), and pushes them into the chosen EDA over adom-desktop. Asks which EDA first. Supersedes adom-altium-library-importer (its Altium path is folded in). Not a general component-adder.
← Commit history
Publish 1.0.0
10 files changed
+616
SKILL.mdadded+16@@ -0,0 +1,16 @@+---+name: adom-library-importer+description: Install Adom's machine pin/contact library into KiCad, Altium, or Fusion 360.+---++# adom-library-importer++This wiki page ships the `adom-library-importer` skill. On install it is linked into+`~/.claude/skills/adom-library-importer/`; the real skill body Claude reads lives at+`skills/adom-library-importer/SKILL.md`.++Ask which EDA the user runs (KiCad / Altium / Fusion), then:++```bash+python ~/.claude/skills/adom-library-importer/import_library.py --eda kicad|altium|fusion+```
docs/hero.pngadded⋯ 1 unchanged line ⋯
install.shadded+8@@ -0,0 +1,8 @@+#!/bin/bash+# install.sh for adom-library-importer (skill).+# Runs from the extracted module directory (~/project/adom_modules/adom-library-importer/).+set -euo pipefail+source "$(adompkg sh-helpers)"++# Skill install: symlink skills/adom-library-importer/ into ~/.claude/skills/adom-library-importer/.+adompkg-link-skill adom-library-importer
release.shadded+11@@ -0,0 +1,11 @@+#!/bin/bash+# release.sh: bump + publish adom-library-importer.+# Usage: ./release.sh [--bump patch|minor|major]+set -euo pipefail+DIR="$(cd "$(dirname "$0")" && pwd)"+cd "$DIR"+case "${1:-}" in+ --bump) adom-wiki pkg version "${2:-patch}" ;;+ --bump=patch|--bump=minor|--bump=major) adom-wiki pkg version "${1#--bump=}" ;;+esac+adom-wiki pkg publish
skills/adom-library-importer/SKILL.mdadded+114@@ -0,0 +1,114 @@+---+name: adom-library-importer+description: >+ Install ADOM'S OWN machine pin/contact library into the user's EDA — KiCad,+ Altium Designer, OR Fusion 360. Installs the wiki library page+ adom/adom-machine-parts-library (which links the six machine components —+ MachineContactMedium, MachineContactLarge, MachinePinLargeShort,+ MachinePinLargeStandard, MachinePinMediumShort, MachinePinMediumStandard — as+ dependencies and hosts the assembled libraries), then registers "Adom Machine+ Symbols" + "Adom Machine Footprints" into the chosen EDA over adom-desktop.+ FIRST ask which EDA the user runs, then import. Use when the user wants Adom's+ machine pins/contacts in their EDA ("add the Adom machine library", "get Adom's+ machine pins into KiCad/Altium/Fusion", "install the Adom pin library").+ Supersedes adom-altium-library-importer (its Altium path is folded in). NOT a+ general component-adder — for arbitrary catalog parts use altium-part-importer /+ the chip-fetcher flow.+---++# adom-library-importer++One skill to get **Adom's standard machine pins and contacts** into whichever EDA the+user runs. The parts live on the wiki as the **`adom/adom-machine-parts-library`** page —+a `library` that declares the six machine components as **dependencies** and hosts the+**assembled** libraries. This skill installs that page (pulling the component deps) and+registers the right files into the user's **KiCad**, **Altium**, or **Fusion 360**:++| Deliverable | KiCad | Altium | Fusion 360 |+|---|---|---|---|+| **Adom Machine Symbols** | `.kicad_sym` (6 symbols) | native `.SchLib` (6 symbols) | folded into the one `.lbr` |+| **Adom Machine Footprints** | `.pretty/` (6 `.kicad_mod`) | `.PcbLib` (built at install, 6 fp + 3D) | folded into the one `.lbr` |++> The library page hosts the KiCad libs, the Altium `.SchLib`, and the Fusion `.lbr`+> pre-built. The Altium `.PcbLib` is assembled **at install** from the component deps+> (`adom-lbr` has no offline multi-part `.PcbLib` merge). Fusion keeps symbols + footprints+> in **one** `Adom Machine Library.lbr`.++## Step 0 — ASK which EDA (do this first)++The user must pick **KiCad**, **Altium**, or **Fusion**. Don't assume. Then confirm+**Adom Desktop is connected** with that EDA open:++```bash+adom-desktop ping # must be connected+```++## Step 1 — run the importer++```bash+python ~/.claude/skills/adom-library-importer/import_library.py --eda kicad # or: altium | fusion+# [--dest-folder AdomLibs] # relative subfolder on the desktop (default AdomLibs)+# [--lib-dir DIR] # reuse an already-installed library dir+```++`import_library.py`:+1. `adom-wiki pkg install adom/adom-machine-parts-library` — installs the library **and its+ six component dependencies** (into `~/project/adom_modules/adom/…`),+2. registers the assembled libraries it hosts into the chosen EDA over `adom-desktop`.++## How each EDA is registered++- **KiCad** — send the hosted `Adom Machine Symbols.kicad_sym` + `Adom Machine Footprints.pretty/`,+ `kicad_lint_library` both, then `kicad_install_library` (`libraryType:"symbol"` /+ `libraryType:"footprint"`) into the newest KiCad's sym-/fp-lib-table.+- **Altium** — needs the **`altium` bridge** (auto-installed if missing) and Altium open.+ Symbols: send + register the hosted native `.SchLib`. Footprints: append each component's+ footprint (+ STEP 3D body) into one `.PcbLib` via `altium_build_footprint` (the folded-in+ old-skill logic), reading geometry from the installed component deps, then+ `altium_install_library`. **Keep symbol + footprint libs registered together** — the+ symbol→footprint link resolves by footprint name.+- **Fusion 360** — send the hosted `Adom Machine Library.lbr` and `fusion_open_lbr` it into the+ Electronics Library editor. **2D only** — real 3D bodies bind per Fusion account (`wip_urn`);+ run the per-pin `fusion_make_3d_package` rebind from the **`adom-machine-pin-fusion-library`**+ skill if you need the 3D pins.++## Requirements++1. **Adom Desktop** connected (`adom-desktop ping`) with the target EDA open.+2. **`adom-lbr`** + **`adom-wiki`** on PATH (ship with the Adom core).+3. Altium only: the **`altium` bridge** (the script installs it from the wiki if absent).++## Regenerating the library page (when a component changes)++The hosted libraries are built from each component's canonical `adom-lbr` JSON. `lib_build.py`+is the regeneration tool: clone the six component pages, then++```bash+python -c "import import_library as il, lib_build; \+ p=il.fetch_pages('<pages_dir>'); \+ lib_build.build_kicad(p,'libs/kicad'); \+ lib_build.build_altium_symbols(p,'libs/altium'); \+ lib_build.build_fusion(p,'libs/fusion')"+```++then re-publish `adom/adom-machine-parts-library`. (`fetch_pages` clones the six pages when no+dir is passed.)++## Files in this skill++- `import_library.py` — orchestrator: install library → register into the EDA (entry point).+- `lib_build.py` — offline builders that ASSEMBLE the library page's hosted files+ (KiCad merge, Altium `.SchLib` merge, Fusion `.lbr` merge) + the shared library-name constants.+- `altium_footprints.py` — desktop-side `.PcbLib` append (ported from the old convert.py).+- `bridge.py` — adom-desktop envelope helper + altium-bridge auto-install.++## Gotchas++- **Ask the EDA first.** The three paths differ; guessing wastes a run.+- **Altium bridge is single-threaded; saves often report "Request timed out" but the work+ PERSISTED.** Verify with `altium_list_symbols`; fire one bridge call at a time. Build bridge+ args with `json.dumps`, never bash interpolation (bash mangles Windows `\`).+- **Keep Altium symbol + footprint libs registered together** (link resolves by footprint name).+- **Fusion 3D is a separate, per-account rebind step** — a fresh import shows 2D; expected.+- **This is Adom's OWN machine pins/contacts only.** For arbitrary catalog parts use+ `altium-part-importer` or the chip-fetcher flow, not this skill.
skills/adom-library-importer/altium_footprints.pyadded+63@@ -0,0 +1,63 @@+#!/usr/bin/env python3+"""Assemble the merged 'Adom Machine Footprints.PcbLib' on the desktop.++adom-lbr has no offline multi-part .PcbLib merge (it does for .SchLib via+add-to-schlib), so the ONE Altium step that needs Altium open is building the+footprint library: for each part we parse its .kicad_mod pads, push its .step,+and drive the altium bridge `altium_build_footprint` in APPEND mode so all six+land pattern + 3D body pairs accumulate into a single .PcbLib. Ported from the+old adom-altium-library-importer convert.py."""+import os, re+from bridge import ad, send_file++MM_PER_MIL = 0.0254+def _mm2mil(mm): return int(round(float(mm) / MM_PER_MIL))+++def _parse_pads(kicad_mod_path):+ txt = open(kicad_mod_path, encoding="utf-8").read()+ pads = []+ for ch in re.split(r'\(pad\s+', txt)[1:]:+ m = re.match(r'"([^"]*)"\s+(\S+)\s+(\S+)', ch)+ if not m:+ continue+ name, ptype, shape = m.group(1), m.group(2), m.group(3)+ at = re.search(r'\(at\s+(-?[\d.]+)\s+(-?[\d.]+)', ch)+ size = re.search(r'\(size\s+([\d.]+)\s+([\d.]+)', ch)+ drill = re.search(r'\(drill\s+([\d.]+)', ch)+ pads.append((+ 1 if 'smd' in ptype else 0,+ _mm2mil(at.group(1)) if at else 0,+ _mm2mil(at.group(2)) if at else 0,+ _mm2mil(size.group(1)) if size else 50,+ _mm2mil(size.group(2)) if size else 50,+ _mm2mil(drill.group(1)) if drill else 0,+ name or str(len(pads) + 1),+ shape,+ ))+ return pads+++def build_pcblib(parts, pcblib_win, dest_folder):+ """parts: [{name, kicad_mod, step}]. Appends each footprint (+STEP 3D body)+ into pcblib_win (a Windows path). Returns list of (name, ok, err)."""+ results = []+ for p in parts:+ pads = _parse_pads(p["kicad_mod"])+ step_desk = send_file(p["step"], dest_folder) if os.path.exists(p["step"]) else None+ payload = {+ "footprint": p["name"],+ "pcblib": pcblib_win,+ "step": (step_desk or ""),+ "padcount": str(len(pads)),+ "timeout": 150,+ }+ for i, pad in enumerate(pads):+ payload["pad%d" % i] = ",".join(str(x) for x in pad)+ r = ad("altium_build_footprint", payload)+ ok = bool(r.get("ok"))+ results.append((p["name"], ok, None if ok else (r.get("error") or r)))+ print(f" {'OK ' if ok else 'FAIL'} footprint {p['name']} "+ f"(pads={len(pads)}, 3d={r.get('step_body')})"+ + ("" if ok else f" ERR={r.get('error')}"))+ return results
skills/adom-library-importer/bridge.pyadded+67@@ -0,0 +1,67 @@+#!/usr/bin/env python3+"""adom-desktop helpers shared by the importer: envelope-unwrapping call, desktop+reachability, and one-time altium-bridge install. Adapted from the old+adom-altium-library-importer install.py."""+import json, subprocess, time++ALTIUM_BRIDGE_MANIFEST = ("https://wiki.adom.inc/download/barrett-land/"+ "adom-desktop-altium-bridge/latest/altium-bridge-manifest.json")+++def ad(verb, payload=None):+ """Call an adom-desktop verb; unwrap the bridge's {success,output} envelope.++ Always pass args as json.dumps — bash interpolation mangles Windows backslashes.+ """+ p = subprocess.run(["adom-desktop", verb, json.dumps(payload or {})],+ capture_output=True, text=True)+ try:+ d = json.loads(p.stdout)+ except ValueError:+ return {"ok": False, "error": (p.stdout or p.stderr or "no output")[:300]}+ if d.get("success") and isinstance(d.get("output"), str):+ try:+ return json.loads(d["output"])+ except ValueError:+ return d+ return d+++def desktop_connected():+ r = ad("ping")+ return (r.get("status") == "connected") or bool(r.get("echo")) or r.get("ok") is True+++def send_file(local_path, dest_folder):+ """send_files one local file; return its desktop path (Windows-slashed) or None."""+ r = ad("send_files", {"filePaths": [local_path], "targetApp": "general",+ "destinationFolder": dest_folder})+ dest = (r.get("destinationPaths") or [None])[0]+ return dest.replace("/", "\\") if dest else None+++# --------------------------------------------------------------- Altium bridge+def altium_ready():+ r = ad("altium_ping")+ return (bool(r.get("version")) and r.get("altiumInstalled", True)), r+++def ensure_altium_bridge():+ ready, r = altium_ready()+ if ready:+ print(f"altium bridge present (v{r.get('version')}), Altium {r.get('altiumVersion')}")+ return True+ print("altium bridge not installed — installing from the wiki…")+ ir = ad("bridge_install", {"manifestUrl": ALTIUM_BRIDGE_MANIFEST})+ if not ir.get("ok"):+ print(f" bridge_install failed: {ir.get('error') or ir}")+ print(f" install manually:\n adom-desktop bridge_install "+ f"'{{\"manifestUrl\":\"{ALTIUM_BRIDGE_MANIFEST}\"}}'")+ return False+ time.sleep(1.5)+ ready, r = altium_ready()+ if not ready:+ print(" bridge installed but Altium not detected. Open Altium Designer, then re-run.")+ return False+ print(f" bridge installed (v{r.get('version')}), Altium {r.get('altiumVersion')}")+ return True
skills/adom-library-importer/import_library.pyadded+177@@ -0,0 +1,177 @@+#!/usr/bin/env python3+"""adom-library-importer — install Adom's machine pin/contact library into the+user's EDA (KiCad, Altium, or Fusion 360).++Installs the wiki library package `adom/adom-machine-parts-library` (which+resolves its six component dependencies), then registers the assembled libraries+it hosts into the chosen EDA over adom-desktop:++ Adom Machine Symbols Adom Machine Footprints+ (schematic symbols) (PCB land patterns)++ python import_library.py --eda kicad|altium|fusion [--dest-folder AdomLibs]+ [--lib-dir DIR] # use an already-installed/cloned library dir++The library page hosts pre-built KiCad (.kicad_sym + .pretty), Altium symbols+(.SchLib) and Fusion (.lbr). Altium FOOTPRINTS have no offline multi-part merge,+so the .PcbLib is assembled here from the component dependencies (kicad_mod ++STEP) via the altium bridge on the user's machine.+"""+import argparse, glob, os, subprocess, sys, tempfile++import lib_build+from bridge import ad, desktop_connected, send_file, ensure_altium_bridge++LIBRARY_REF = "adom/adom-machine-parts-library"+MODULES_DIR = os.path.expanduser("~/project/adom_modules/adom/adom-machine-parts-library")+COMPONENTS = [+ "MachineContactMedium", "MachineContactLarge",+ "MachinePinLargeShort", "MachinePinLargeStandard",+ "MachinePinMediumShort", "MachinePinMediumStandard",+]+++def install_library_package(lib_dir=None):+ """pkg install the library (+ its 6 component deps) and return the dir that+ holds its libs/. Falls back to a repo clone if the install dir isn't found."""+ if lib_dir:+ return lib_dir+ print(f"installing {LIBRARY_REF} (+ its component dependencies)…")+ r = subprocess.run(["adom-wiki", "pkg", "install", LIBRARY_REF],+ capture_output=True, text=True)+ if r.returncode != 0:+ print(f" pkg install warning: {(r.stderr or r.stdout).strip()[:200]}")+ if os.path.isdir(os.path.join(MODULES_DIR, "libs")):+ return MODULES_DIR+ # fallback: clone the page repo directly+ tmp = tempfile.mkdtemp(prefix="adom_machine_lib_")+ subprocess.run(["adom-wiki", "repo", "clone", LIBRARY_REF], cwd=tmp,+ capture_output=True, text=True)+ cloned = os.path.join(tmp, "adom-machine-parts-library")+ if os.path.isdir(os.path.join(cloned, "libs")):+ return cloned+ sys.exit(f"could not locate the installed library (looked in {MODULES_DIR}).")+++def _component_dirs():+ """Installed component dependency dirs (for the Altium PcbLib build)."""+ base = os.path.expanduser("~/project/adom_modules/adom")+ dirs = {}+ for name in COMPONENTS:+ slug = name.lower()+ d = os.path.join(base, slug)+ if os.path.isdir(d):+ dirs[name] = d+ return dirs+++# ------------------------------------------------------------------- KiCad ----+def install_kicad(lib_dir, dest_folder):+ kdir = os.path.join(lib_dir, "libs", "kicad")+ sym = os.path.join(kdir, lib_build.SYM_LIB + ".kicad_sym")+ pretty = os.path.join(kdir, lib_build.FP_LIB + ".pretty")+ sym_desk = send_file(sym, dest_folder)+ pretty_folder = f"{dest_folder}/{lib_build.FP_LIB}.pretty"+ mod_desk = None+ for f in sorted(glob.glob(os.path.join(pretty, "*.kicad_mod"))):+ mod_desk = send_file(f, pretty_folder)+ if not sym_desk or not mod_desk:+ sys.exit("failed to send KiCad libraries to the desktop")+ pretty_desk = mod_desk.rsplit("\\", 1)[0]+ for path in (sym_desk, pretty_desk):+ lr = ad("kicad_lint_library", {"libraryPath": path})+ s = (lr.get("data") or {}).get("summary") or {}+ print(f" lint {os.path.basename(path)}: symbols={s.get('symbolCount')} "+ f"footprints={s.get('footprintCount')}")+ ok = True+ r1 = ad("kicad_install_library", {"libraryType": "symbol",+ "libraryName": lib_build.SYM_LIB, "libraryPath": sym_desk})+ print(f" {'OK ' if r1.get('success', r1.get('ok')) else 'FAIL'} symbol lib -> {sym_desk}")+ ok = ok and bool(r1.get("success", r1.get("ok")))+ r2 = ad("kicad_install_library", {"libraryType": "footprint",+ "libraryName": lib_build.FP_LIB, "libraryPath": pretty_desk})+ print(f" {'OK ' if r2.get('success', r2.get('ok')) else 'FAIL'} footprint lib -> {pretty_desk}")+ return ok and bool(r2.get("success", r2.get("ok")))+++# ------------------------------------------------------------------ Altium ----+def install_altium(lib_dir, dest_folder):+ if not ensure_altium_bridge():+ sys.exit("altium bridge / Altium not ready.")+ # Symbols: hosted native merged .SchLib (built offline on the library page).+ schlib = os.path.join(lib_dir, "libs", "altium", lib_build.SYM_LIB + ".SchLib")+ sch_desk = send_file(schlib, dest_folder)+ if not sch_desk:+ sys.exit("failed to send the SchLib to the desktop")+ r = ad("altium_install_library", {"path": sch_desk})+ ok_sym = bool(r.get("ok"))+ print(f" {'OK ' if ok_sym else 'FAIL'} symbol lib -> {sch_desk}"+ + ("" if ok_sym else f" ({r.get('error')})"))++ # Footprints: assemble Adom Machine Footprints.PcbLib on the desktop from the+ # component dependencies (kicad_mod + STEP), append mode.+ import altium_footprints+ comp_dirs = _component_dirs()+ if len(comp_dirs) < len(COMPONENTS):+ print(f" WARN only {len(comp_dirs)}/{len(COMPONENTS)} component deps found under "+ f"adom_modules/adom — run `adom-wiki pkg install {LIBRARY_REF}` first.")+ parts = [{"name": n, "kicad_mod": os.path.join(d, n + ".kicad_mod"),+ "step": os.path.join(d, n + ".step")}+ for n, d in comp_dirs.items()]+ pcblib_desk = f"{sch_desk.rsplit(chr(92), 1)[0]}\\{lib_build.FP_LIB}.PcbLib"+ print(f"building {lib_build.FP_LIB}.PcbLib on the desktop (append mode)…")+ fp_results = altium_footprints.build_pcblib(parts, pcblib_desk, dest_folder)+ ok_fp = bool(parts) and all(ok for _, ok, _ in fp_results)+ if ok_fp:+ r = ad("altium_install_library", {"path": pcblib_desk})+ ok_fp = bool(r.get("ok"))+ print(f" {'OK ' if ok_fp else 'FAIL'} footprint lib -> {pcblib_desk}"+ + ("" if ok_fp else f" ({r.get('error')})"))+ # keep symbol + footprint libs registered together (link resolves by footprint name).+ return ok_sym and ok_fp+++# ------------------------------------------------------------------ Fusion ----+def install_fusion(lib_dir, dest_folder):+ lbr = os.path.join(lib_dir, "libs", "fusion", lib_build.FUSION_LIB + ".lbr")+ lbr_desk = send_file(lbr, dest_folder)+ if not lbr_desk:+ sys.exit("failed to send the .lbr to the desktop")+ r = ad("fusion_open_lbr", {"filePath": lbr_desk})+ ok = bool(r.get("success", r.get("ok")))+ print(f" {'OK ' if ok else 'FAIL'} opened in Fusion Electronics Library editor -> {lbr_desk}")+ print(" NOTE: symbols + footprints import in 2D. Real 3D bodies bind per Fusion\n"+ " account (wip_urn) — run the fusion_make_3d_package rebind from the\n"+ " adom-machine-pin-fusion-library skill if you need the 3D pins.")+ return ok+++def main():+ ap = argparse.ArgumentParser(description="Install Adom's machine pin/contact library into your EDA.")+ ap.add_argument("--eda", required=True, choices=["kicad", "altium", "fusion"])+ ap.add_argument("--dest-folder", default="AdomLibs",+ help="relative subfolder on the desktop (default: AdomLibs)")+ ap.add_argument("--lib-dir", default=None,+ help="use an already-installed/cloned adom-machine-parts-library dir")+ a = ap.parse_args()++ if not desktop_connected():+ sys.exit("Adom Desktop not connected. Open Adom Desktop on the user's machine "+ "and connect, then: adom-desktop ping")++ lib_dir = install_library_package(a.lib_dir)+ print(f"library ready at {lib_dir}")++ handler = {"kicad": install_kicad, "altium": install_altium, "fusion": install_fusion}[a.eda]+ ok = handler(lib_dir, a.dest_folder)++ if ok:+ print(f"\nDone. Adom's machine pins/contacts are now in {a.eda.title()} as "+ f"'{lib_build.SYM_LIB}' + '{lib_build.FP_LIB}'"+ + (" (one .lbr)" if a.eda == "fusion" else "") + ".")+ else:+ sys.exit("\nOne or more steps failed (see above).")+++if __name__ == "__main__":+ main()
skills/adom-library-importer/lib_build.pyadded+153@@ -0,0 +1,153 @@+#!/usr/bin/env python3+"""Offline builders that assemble the Adom machine library for each EDA.++Everything here runs in the container with `adom-lbr` and needs NO desktop / EDA+app. The canonical hub format is each component's `<Name>.adom-lbr.json` (cloned+from its wiki page); `adom-lbr export-*` / `generate` fan it out per EDA, and the+functions below MERGE the per-part outputs into the two named libraries:++ Adom Machine Symbols (schematic symbols)+ Adom Machine Footprints (PCB footprints / land patterns)++KiCad and Fusion are fully offline here. Altium symbols are offline (native+.SchLib via `add-to-schlib`); Altium *footprints* have no offline multi-part+merge in adom-lbr, so they are assembled on the desktop by the altium bridge —+see altium_footprints.py.+"""+import json, os, re, shutil, subprocess, tempfile++SYM_LIB = "Adom Machine Symbols"+FP_LIB = "Adom Machine Footprints"+FUSION_LIB = "Adom Machine Library" # Fusion/EAGLE keep symbols+footprints in ONE .lbr+++def run(cmd):+ p = subprocess.run(cmd, capture_output=True, text=True)+ if p.returncode != 0:+ raise RuntimeError("cmd failed: %s\n%s" % (" ".join(cmd), p.stderr or p.stdout))+ return p.stdout+++# ---------------------------------------------------------------- KiCad -------+def _extract_symbol_blocks(kicad_sym_text):+ """Yield each top-level (symbol "..." ...) block from a .kicad_sym file."""+ i = kicad_sym_text.find('(symbol "')+ while i != -1:+ depth, j = 0, i+ while j < len(kicad_sym_text):+ c = kicad_sym_text[j]+ if c == '(':+ depth += 1+ elif c == ')':+ depth -= 1+ if depth == 0:+ yield kicad_sym_text[i:j + 1]+ break+ j += 1+ i = kicad_sym_text.find('(symbol "', j + 1)+++def build_kicad(parts, out_dir):+ """parts: list of dicts {name, json, kicad_mod}. Returns (sym_path, pretty_dir)."""+ os.makedirs(out_dir, exist_ok=True)+ work = tempfile.mkdtemp(prefix="klib_")+ blocks = []+ pretty = os.path.join(out_dir, FP_LIB + ".pretty")+ os.makedirs(pretty, exist_ok=True)+ for p in parts:+ run(["adom-lbr", "export-kicad", p["json"], "--out-dir", work])+ ks = os.path.join(work, p["name"] + ".kicad_sym")+ km = os.path.join(work, p["name"] + ".kicad_mod")+ blocks.extend(_extract_symbol_blocks(open(ks, encoding="utf-8").read()))+ shutil.copy(km, os.path.join(pretty, p["name"] + ".kicad_mod"))+ sym_path = os.path.join(out_dir, SYM_LIB + ".kicad_sym")+ with open(sym_path, "w", encoding="utf-8") as f:+ f.write('(kicad_symbol_lib\n\t(version 20231120)\n\t(generator "adom-library-importer")\n')+ for b in blocks:+ f.write("\t" + b.replace("\n", "\n\t") + "\n")+ f.write(")\n")+ return sym_path, pretty+++# ---------------------------------------------------------------- Altium ------+def build_altium_symbols(parts, out_dir):+ """Merge every part's symbol into one native Adom Machine Symbols.SchLib (offline)."""+ os.makedirs(out_dir, exist_ok=True)+ work = tempfile.mkdtemp(prefix="alib_")+ # seed the SchLib from the first part, then non-destructively merge the rest+ run(["adom-lbr", "export-altium", parts[0]["json"], "--out-dir", work])+ seed = os.path.join(work, parts[0]["name"] + ".SchLib")+ cur = seed+ for p in parts[1:]:+ nxt = os.path.join(work, "merge_after_%s.SchLib" % p["name"])+ run(["adom-lbr", "add-to-schlib", cur, p["json"], "--out", nxt])+ cur = nxt+ dest = os.path.join(out_dir, SYM_LIB + ".SchLib")+ shutil.copy(cur, dest)+ return dest+++# ---------------------------------------------------------------- Fusion ------+_LAYERS_RE = re.compile(r"<layers>.*?</layers>", re.S)+_PACKAGES_RE = re.compile(r"<packages>(.*?)</packages>", re.S)+_SYMBOLS_RE = re.compile(r"<symbols>(.*?)</symbols>", re.S)+_DEVICES_RE = re.compile(r"<devicesets>(.*?)</devicesets>", re.S)+++def build_fusion(parts, out_dir):+ """Generate a .lbr per part and merge into one Adom Machine Library.lbr.++ Merge = shared <layers> skeleton + concatenated packages/symbols/devicesets+ (the recipe from adom-machine-pin-fusion-library). 2D only; 3D bodies bind+ per-account on the desktop and are handled separately by the orchestrator.+ """+ os.makedirs(out_dir, exist_ok=True)+ work = tempfile.mkdtemp(prefix="flib_")+ layers = None+ packages, symbols, devicesets = [], [], []+ for p in parts:+ lbr = os.path.join(work, p["name"] + ".lbr")+ cmd = ["adom-lbr", "generate", "--sym", p["kicad_sym"], "--fp", p["kicad_mod"], "-o", lbr]+ run(cmd)+ run(["adom-lbr", "lint", lbr]) # empty pin-name / round-pad guard+ xml = open(lbr, encoding="utf-8").read()+ if layers is None:+ m = _LAYERS_RE.search(xml)+ layers = m.group(0) if m else "<layers></layers>"+ for src, sink in ((_PACKAGES_RE, packages), (_SYMBOLS_RE, symbols), (_DEVICES_RE, devicesets)):+ m = src.search(xml)+ if m:+ sink.append(m.group(1).strip())+ dest = os.path.join(out_dir, FUSION_LIB + ".lbr")+ with open(dest, "w", encoding="utf-8") as f:+ f.write('<?xml version="1.0" encoding="utf-8"?>\n')+ f.write('<!DOCTYPE eagle SYSTEM "eagle.dtd">\n<eagle version="9.0.0">\n<drawing>\n')+ f.write('<library>\n<description>Adom machine pins & contacts</description>\n')+ f.write(layers + "\n")+ f.write("<packages>\n" + "\n".join(packages) + "\n</packages>\n")+ f.write("<symbols>\n" + "\n".join(symbols) + "\n</symbols>\n")+ f.write("<devicesets>\n" + "\n".join(devicesets) + "\n</devicesets>\n")+ f.write("</library>\n</drawing>\n</eagle>\n")+ return dest+++if __name__ == "__main__":+ # smoke test against a cloned pages/ dir: python lib_build.py <pages_dir> <eda> <out>+ import sys+ pages_dir, eda, out = sys.argv[1], sys.argv[2], sys.argv[3]+ parts = []+ for d in sorted(os.listdir(pages_dir)):+ pd = os.path.join(pages_dir, d)+ js = [f for f in os.listdir(pd) if f.endswith(".adom-lbr.json")]+ if not js:+ continue+ name = js[0][:-len(".adom-lbr.json")]+ parts.append({"name": name, "json": os.path.join(pd, js[0]),+ "kicad_mod": os.path.join(pd, name + ".kicad_mod"),+ "kicad_sym": os.path.join(pd, name + ".kicad_sym")})+ if eda == "kicad":+ print(build_kicad(parts, out))+ elif eda == "altium":+ print(build_altium_symbols(parts, out))+ elif eda == "fusion":+ print(build_fusion(parts, out))
uninstall.shadded+7@@ -0,0 +1,7 @@+#!/bin/bash+# uninstall.sh for adom-library-importer (skill).+set -euo pipefail++# Remove only the symlink at ~/.claude/skills/adom-library-importer/.+rm -rf "${HOME}/.claude/skills/adom-library-importer"+echo "Uninstalled skill adom-library-importer"