A complete AI agency at your fingertips - From frontend wizards to Reddit community ninjas, from whimsy injectors to reality checkers. Each agent is a specialized expert with personality, processes, and proven deliverables.
Shell
fix(hermes): match config items with inline comments (#1030)
ordinary being58a6884db74e
diff --git a/scripts/check-hermes-config-rewrite.py b/scripts/check-hermes-config-rewrite.pyindex 1d89cb0f..f38d9d5d 100644--- a/scripts/check-hermes-config-rewrite.py+++ b/scripts/check-hermes-config-rewrite.py@@ -73,6 +73,26 @@ def check_case(heredoc: str, name: str, cfg_text: str) -> list[str]:return failuresif PLUGIN not in enabled:failures.append(f"{name}: plugin missing from enabled")+ # A healthy result holds the plugin exactly once. A duplicated entry means+ # the writer failed to recognize an existing one.+ if enabled.count(PLUGIN) != 1:+ failures.append(f"{name}: plugin appears {enabled.count(PLUGIN)}x in enabled")+ # Comments are not list content: the writer may add the plugin, but it must+ # not turn other text into entries or drop what the user had. The repair of+ # a legacy glued scalar ("a - b - c" in one quoted item) is the documented+ # exception: there, splitting one item into several is the whole point.+ try:+ before = (yaml.safe_load(cfg_text) or {}).get("plugins", {}).get("enabled")+ except yaml.YAMLError:+ before = None+ if isinstance(before, list):+ repaired = any(" - " in str(item) for item in before)+ gained = [item for item in enabled if item not in before and item != PLUGIN]+ lost = [item for item in before if item not in enabled]+ if gained and not repaired:+ failures.append(f"{name}: enabled gained unrelated entries: {gained!r}")+ if lost and not repaired:+ failures.append(f"{name}: enabled lost entries: {lost!r}")disabled = (parsed or {}).get("plugins", {}).get("disabled")if isinstance(disabled, list) and PLUGIN in disabled:failures.append(f"{name}: plugin still in disabled")@@ -281,6 +301,59 @@ def main() -> int:- basic"""),),+ (+ # YAML ends an item at " #", so these entries are the plugin, not+ # free text. The writer must match them and must not let the+ # comment's own text reach the list.+ "Enabled item with an inline comment (already enabled)",+ textwrap.dedent("""\+ plugins:+ enabled:+ - chronos+ - agency-agents-router # our router+ disabled:+ - browser/firecrawl+ """),+ ),+ (+ "Disabled item with an inline comment (stale entry)",+ textwrap.dedent("""\+ plugins:+ enabled:+ - chronos+ disabled:+ - agency-agents-router # temporarily off+ """),+ ),+ (+ "Inline comment containing ' - ' on an enabled item",+ textwrap.dedent("""\+ plugins:+ enabled:+ - chronos # keep - rotate this one first+ disabled:+ - browser/firecrawl+ """),+ ),+ (+ "Corrupted glue with a quoted plugin (post-#879 recovery)",+ textwrap.dedent("""\+ plugins:+ enabled:+ - basic - "agency-agents-router"+ """),+ ),+ (+ # Reviewer-verified shape (phant0um): quotes and an inline comment+ # on an existing entry must still match, and must not be re-added.+ "Quoted enabled item with an inline comment (already enabled)",+ textwrap.dedent("""\+ plugins:+ enabled:+ - chronos+ - "agency-agents-router" # quoted and commented+ """),+ ),]if HERMES_BACKUP.exists():diff --git a/scripts/install.sh b/scripts/install.shindex 2bf82c52..3c3923e8 100755--- a/scripts/install.sh+++ b/scripts/install.sh@@ -1328,6 +1328,16 @@ if has_enabled and not enabled_empty and not inline_flow:item_indent = lines[idx][: len(lines[idx]) - len(stripped)]break+# A trailing YAML comment is not part of an item's value: "#" starts a comment+# only after whitespace, so strip it before matching. The earlier raw compare+# missed an existing entry that carried a comment (adding a duplicate) and let+# a comment containing " - " trip the corrupted-glue repair below.+def strip_comment(text):+ return re.sub(r"\s+#.*$", "", text).strip()++def item_value(text):+ return strip_comment(text).strip("\"'")+# Detect "already enabled" + corrupted-scalar form (glued "- " from old 2-space bug); repair splits to one per line.corrupted_lines = []has_plugin_already = False@@ -1339,13 +1349,11 @@ elif has_enabled and not enabled_empty:stripped = l.strip()if not stripped.startswith("-"):continue- # >1 "- " in stripped line = corrupted glue (strict match won't work: names contain dashes).- if stripped.count("- ") > 1:+ # Any "- " inside the comment-stripped value = corrupted glue (strict match won't work: names contain dashes).+ if strip_comment(stripped[1:]).count("- ") > 0:corrupted_lines.append(idx)- else:- value = stripped[1:].strip().strip("\"'")- if value == plugin_strip:- has_plugin_already = True+ elif item_value(stripped[1:]) == plugin_strip:+ has_plugin_already = True# Repair in reverse to keep indices. Splice grows the block — sync enabled_end with end_line or the stale sweep eats the new plugin (#879).for idx in sorted(corrupted_lines, reverse=True):@@ -1353,7 +1361,7 @@ for idx in sorted(corrupted_lines, reverse=True):stripped = l.strip()if not item_indent:item_indent = l[: len(l) - len(stripped)] or (enabled_indent + " ")- content = stripped[1:].strip()+ content = strip_comment(stripped[1:])parts = re.split(r"\s+-\s+", content)new_lines = [f"{item_indent}- {parts[0]}"]for p in parts[1:]:@@ -1364,7 +1372,8 @@ for idx in sorted(corrupted_lines, reverse=True):# Re-check presence after rewrite.has_plugin_already = Falsefor nl in lines[enabled_idx + 1 : enabled_end]:- if nl.strip().startswith("-") and nl[len(item_indent) :].strip() == f"- {plugin_strip}":+ ns = nl.strip()+ if ns.startswith("-") and item_value(ns[1:]) == plugin_strip:has_plugin_already = Truebreak@@ -1382,8 +1391,7 @@ if plugin_start is not None:for idx in rng:stripped = lines[idx].strip()if stripped.startswith("-"):- value = stripped[1:].strip().strip("\"'")- if value == plugin_strip:+ if item_value(stripped[1:]) == plugin_strip:stale.append(idx)for idx in sorted(stale, reverse=True):del lines[idx]