From 46314405df61a24a32cfa0cecd49dfb2ce624167 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?n=CE=B9c=D0=BDola=D1=95=20w=CE=B9lde?= Date: Wed, 5 Aug 2026 12:42:15 -0700 Subject: [PATCH] feat: add script and skill to deduplicate zensical.toml --- .agents/skills/dedupe-zensical.md | 18 ++++++++++++ Taskfile.yaml | 6 +++- scripts/dedupe_zensical.py | 47 +++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 .agents/skills/dedupe-zensical.md create mode 100755 scripts/dedupe_zensical.py diff --git a/.agents/skills/dedupe-zensical.md b/.agents/skills/dedupe-zensical.md new file mode 100644 index 00000000..6849f33a --- /dev/null +++ b/.agents/skills/dedupe-zensical.md @@ -0,0 +1,18 @@ +--- +name: dedupe-zensical +description: Remove duplicate array entries in the zensical.toml configuration file. +--- + +# Dedupe Zensical Skill + +This skill removes duplicate array entries in `zensical.toml` (such as duplicate recipe links under menu categories like `Sides = [...]`). + +## Usage + +When a user requests to deduplicate or remove duplicates from `zensical.toml`, you should simply run the following task: + +```bash +task dedupe-zensical +``` + +This task executes the `scripts/dedupe_zensical.py` Python script, which parses `zensical.toml`, finds exact string duplicates within any array blocks (lines between `[` and `]`), removes them, and overwrites the file in place. It prints the number of duplicates removed. diff --git a/Taskfile.yaml b/Taskfile.yaml index bf1c6aeb..8e8fbc13 100644 --- a/Taskfile.yaml +++ b/Taskfile.yaml @@ -260,8 +260,12 @@ tasks: sops --decrypt --input-type json --output-type json --output settings.json settings.json.enc fi + dedupe-zensical: + desc: Remove duplicate array entries in zensical.toml + cmds: + - uv run python3 scripts/dedupe_zensical.py + default: cmds: - task -a silent: true - diff --git a/scripts/dedupe_zensical.py b/scripts/dedupe_zensical.py new file mode 100755 index 00000000..65059c0c --- /dev/null +++ b/scripts/dedupe_zensical.py @@ -0,0 +1,47 @@ +#!/usr/bin/env python3 + +import os + +def dedupe_zensical(filepath="zensical.toml"): + if not os.path.exists(filepath): + print(f"Error: {filepath} not found.") + return + + with open(filepath, "r") as f: + lines = f.readlines() + + new_lines = [] + seen_in_section = set() + in_array = False + removed_count = 0 + + for line in lines: + # Detect the start of an array section (e.g., `Sides = [`) + if "=" in line and "[" in line and "]" not in line: + in_array = True + seen_in_section = set() + new_lines.append(line) + continue + elif "]" in line and in_array: + in_array = False + new_lines.append(line) + continue + + if in_array and "{" in line and "}" in line: + trimmed = line.strip() + if trimmed in seen_in_section: + removed_count += 1 + continue + seen_in_section.add(trimmed) + + new_lines.append(line) + + if removed_count > 0: + with open(filepath, "w") as f: + f.writelines(new_lines) + print(f"Successfully removed {removed_count} duplicate entries from {filepath}.") + else: + print(f"No duplicate entries found in {filepath}.") + +if __name__ == "__main__": + dedupe_zensical()