Skip to content

Commit 32c3fda

Browse files
committed
Bump to v2.10.39: Allow YAML files with Home Assistant custom tags in ha_write_file (reported by @ghzgod)
1 parent b9c1595 commit 32c3fda

6 files changed

Lines changed: 46 additions & 9 deletions

File tree

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
## [2.10.39] - 2026-02-18
6+
7+
### 🔧 Allow YAML files with Home Assistant custom tags in `ha_write_file` (reported by @ghzgod)
8+
9+
- **Issue**: The file write endpoint rejected valid YAML that uses HA custom tags such as `!include`, `!include_dir_merge_named`, etc., with an error like: *"Invalid YAML in configuration.yaml: could not determine a constructor for the tag '!include'"*. Users had to fall back to SSH to edit `configuration.yaml` and other files that rely on these directives.
10+
- **Cause**: Validation used `yaml.safe_load()`, which only supports standard YAML types and does not handle custom tags. Home Assistant uses `!include` and related tags throughout configs, so such files were incorrectly treated as invalid.
11+
- **Fix**: Introduced a custom SafeLoader that treats unknown `!…` tags as opaque placeholders during validation. The document is only checked for parseability; includes are not resolved. File content is written as-is. Both `write` and `append` now accept YAML containing `!include`, `!include_dir_merge_named`, and other HA tags.
12+
- **Thanks**: Bug reported by [@ghzgod](https://github.com/ghzgod). Thank you for the clear description and steps to reproduce.
13+
514
## [2.10.38] - 2026-02-18
615

716
### 🔧 Accept plural automation fields (thanks to @CrazyCoder, PR #26)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# HA Vibecode Agent - Home Assistant Add-on
22

3-
[![Version](https://img.shields.io/badge/version-2.10.38-blue.svg)](https://github.com/Coolver/home-assistant-vibecode-agent)
3+
[![Version](https://img.shields.io/badge/version-2.10.39-blue.svg)](https://github.com/Coolver/home-assistant-vibecode-agent)
44
[![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
55
[![MCP Package](https://img.shields.io/npm/v/@coolver/home-assistant-mcp?label=MCP%20Package)](https://www.npmjs.com/package/@coolver/home-assistant-mcp)
66

app/api/files.py

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,47 @@ def _is_yaml_path(path: str) -> bool:
1919
return lower.endswith(".yaml") or lower.endswith(".yml")
2020

2121

22+
class _HAAllowTagLoader(yaml.SafeLoader):
23+
"""SafeLoader that treats unknown !tags (e.g. !include) as placeholders."""
24+
25+
pass
26+
27+
28+
def _unknown_tag_constructor(loader, tag_suffix, node):
29+
if isinstance(node, yaml.ScalarNode):
30+
return node.value or ""
31+
return None
32+
33+
34+
_HAAllowTagLoader.add_multi_constructor("!", _unknown_tag_constructor)
35+
36+
37+
def _safe_load_yaml_allow_ha_tags(content: str):
38+
"""
39+
Load YAML like safe_load but allow Home Assistant custom tags (!include,
40+
!include_dir_merge_named, etc.) by treating them as opaque placeholders.
41+
We only validate that the document is parseable; we do not resolve includes.
42+
"""
43+
return yaml.load(content or "", Loader=_HAAllowTagLoader)
44+
45+
2246
def _validate_yaml_syntax(path: str, content: str) -> None:
2347
"""
2448
Basic YAML syntax validation.
2549
2650
Prevents writing obviously invalid YAML that would break Home Assistant.
51+
Accepts HA custom tags (!include, !include_dir_merge_named, etc.) without
52+
resolving them; only checks that the document is parseable.
2753
"""
2854
if not _is_yaml_path(path):
2955
return
3056

3157
try:
32-
# We don't care about structure here, only that YAML parses
33-
yaml.safe_load(content or "") # empty file is valid YAML (None)
34-
except Exception as e: # yaml.YAMLError and others
58+
_safe_load_yaml_allow_ha_tags(content or "")
59+
except yaml.YAMLError as e:
60+
logger.error(f"Invalid YAML when writing {path}: {e}")
61+
raise HTTPException(status_code=400, detail=f"Invalid YAML in {path}: {e}")
62+
except Exception as e:
3563
logger.error(f"Invalid YAML when writing {path}: {e}")
3664
raise HTTPException(status_code=400, detail=f"Invalid YAML in {path}: {e}")
3765

@@ -53,7 +81,7 @@ def _validate_automations_structure(path: str, content: str) -> None:
5381
return
5482

5583
try:
56-
data = yaml.safe_load(content or "")
84+
data = _safe_load_yaml_allow_ha_tags(content or "")
5785
except Exception as e:
5886
# Syntax errors are handled separately in _validate_yaml_syntax
5987
logger.debug(f"Skipping automations structure check for {path} due to YAML error: {e}")

app/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
logger = setup_logger('ha_cursor_agent', LOG_LEVEL)
2727

2828
# Agent version
29-
AGENT_VERSION = "2.10.38"
29+
AGENT_VERSION = "2.10.39"
3030

3131
# FastAPI app
3232
app = FastAPI(

config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Home Assistant Add-on Configuration
22
name: HA Vibecode Agent
3-
version: "2.10.38"
3+
version: "2.10.39"
44
slug: home_assistant_cursor_agent
55
description: "Enable Cursor, VS Code, Claude Code, or any MCP-enabled IDE to help you vibe-code and manage Home Assistant: create and debug automations, design dashboards, tweak themes, modify configs, and deploy changes using natural language"
66
url: https://github.com/Coolver/home-assistant-cursor-agent

tests/HA_AGENT_TEST_SUITE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 🧪 Home Assistant Agent - Comprehensive Test Suite
22

3-
**Version:** 2.10.38
3+
**Version:** 2.10.39
44
**Purpose:** Complete testing of all HA Cursor Agent MCP functions
55
**Usage:** Say "run Home Assistant Agent test suite" to run full suite
66

@@ -1140,5 +1140,5 @@ HA_AGENT_KEY=<your-token>
11401140

11411141
**Last Updated:** 2026-01-27
11421142
**Test Suite Version:** 1.2.0
1143-
**Compatible with:** HA Cursor Agent v2.10.38+
1143+
**Compatible with:** HA Cursor Agent v2.10.39+
11441144

0 commit comments

Comments
 (0)