Skip to content

Commit 4d19378

Browse files
committed
Add filter option to import_external_skills
1 parent 1c5db3f commit 4d19378

1 file changed

Lines changed: 38 additions & 1 deletion

File tree

.github/scripts/import_external_skills.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
Usage:
3131
uv run .github/scripts/import_external_skills.py # write changes
3232
uv run .github/scripts/import_external_skills.py --dry-run # report only
33+
uv run .github/scripts/import_external_skills.py --only magpie # one skill
34+
35+
The `--only` flag (repeatable) restricts the run to the named skill
36+
folder(s): other skills in the catalog are skipped and pruning is limited
37+
to the named skills, so unrelated federated skills are never removed.
3338
3439
The companion GitHub Actions workflow `import-external-skills` calls this
3540
script on manual dispatch and opens a pull request with the result.
@@ -553,9 +558,33 @@ def main(argv: list[str] | None = None) -> int:
553558
default=CATALOG_FILE,
554559
help=f"Path to the catalog file (default: {CATALOG_FILE}).",
555560
)
561+
parser.add_argument(
562+
"--only",
563+
action="append",
564+
metavar="SKILL",
565+
help=(
566+
"Import only the named skill folder (repeatable). When set, "
567+
"skills not named here are left untouched and pruning is "
568+
"restricted to the named skills, so other federated skills are "
569+
"never removed."
570+
),
571+
)
556572
args = parser.parse_args(argv)
557573

558574
sources = parse_sources(args.catalog)
575+
576+
only = set(args.only or [])
577+
if only:
578+
known = {spec.folder for source in sources for spec in source.skills}
579+
unknown = only - known
580+
if unknown:
581+
raise ValueError(
582+
"--only names skill(s) not present in the catalog: "
583+
+ ", ".join(sorted(unknown))
584+
)
585+
for source in sources:
586+
source.skills = [s for s in source.skills if s.folder in only]
587+
sources = [source for source in sources if source.skills]
559588
log: list[str] = []
560589
declared: set[str] = set()
561590
all_results: list[ImportResult] = []
@@ -573,7 +602,15 @@ def main(argv: list[str] | None = None) -> int:
573602
declared.add(spec.folder)
574603
all_results.extend(import_source(source, args.dry_run, log))
575604

576-
pruned = prune_orphans(declared, existing_federated, args.dry_run, log)
605+
# With --only we deliberately ignore skills the user didn't name, so
606+
# restrict orphan pruning to just those skills. Otherwise every other
607+
# federated skill would look like an orphan and be deleted.
608+
prunable = (
609+
{name: marker for name, marker in existing_federated.items() if name in only}
610+
if only
611+
else existing_federated
612+
)
613+
pruned = prune_orphans(declared, prunable, args.dry_run, log)
577614
marketplace_changed = update_marketplace(all_results, args.dry_run)
578615

579616
for line in log:

0 commit comments

Comments
 (0)