Skip to content

A skill to stop your coding agent from burying the answer. ADHD-friendly output.

hooks: keep the skill body when frontmatter is never closed

Souptik Chakraborty43e427dc611f
diff --git a/hooks/always-on.ps1 b/hooks/always-on.ps1
index 1c58480..cac27bd 100644
--- a/hooks/always-on.ps1
+++ b/hooks/always-on.ps1
@@ -25,7 +25,8 @@ try {
$bodyStart = 0
if ($lines.Length -gt 0 -and $lines[0] -match '^---\s*$') {
- $bodyStart = $lines.Length
+ # Only treat the block as frontmatter when the closing delimiter exists;
+ # an unterminated fence is not frontmatter, so keep the whole file.
for ($i = 1; $i -lt $lines.Length; $i++) {
if ($lines[$i] -match '^---\s*$') {
$bodyStart = $i + 1
diff --git a/hooks/always-on.sh b/hooks/always-on.sh
index 2eee28c..f433bd0 100755
--- a/hooks/always-on.sh
+++ b/hooks/always-on.sh
@@ -19,11 +19,19 @@ skill_path="$script_dir/../skills/i-have-adhd/SKILL.md"
[ -f "$skill_path" ] || exit 0
# Strip a leading YAML frontmatter block (--- ... --- at the very top of file).
+# An unterminated fence is not frontmatter, so the whole file is kept unless the
+# closing delimiter exists (two passes; matches the Node and PowerShell hooks).
body=$(awk '
- NR == 1 && $0 ~ /^---[[:space:]]*$/ { in_fm = 1; next }
- in_fm && $0 ~ /^---[[:space:]]*$/ { in_fm = 0; next }
- !in_fm { print }
-' "$skill_path") || exit 0
+ NR == FNR {
+ if (NR == 1 && $0 ~ /^---[[:space:]]*$/) { in_fm = 1; next }
+ if (in_fm && $0 ~ /^---[[:space:]]*$/) { in_fm = 0; closed = 1 }
+ next
+ }
+ FNR == 1 { strip = closed }
+ strip && FNR == 1 && $0 ~ /^---[[:space:]]*$/ { skipping = 1; next }
+ skipping && $0 ~ /^---[[:space:]]*$/ { skipping = 0; next }
+ !skipping { print }
+' "$skill_path" "$skill_path") || exit 0
printf 'ADHD MODE ACTIVE (always-on). The ruleset below applies to every response. "stop adhd mode" turns it off for this session; delete %s to turn always-on off for good.\n\n%s\n' \
"$flag_path" "$body"
diff --git a/tests/test_always_on_hooks.py b/tests/test_always_on_hooks.py
index f18a5e1..d3cbbef 100644
--- a/tests/test_always_on_hooks.py
+++ b/tests/test_always_on_hooks.py
@@ -81,6 +81,26 @@ class AlwaysOnHookTest(unittest.TestCase):
self.assertEqual(1, len(set(outputs.values())))
+ def test_runtimes_keep_content_when_frontmatter_is_unclosed(self):
+ # An opening --- with no closing delimiter is not frontmatter. Keeping
+ # the whole file beats injecting a banner that promises "the ruleset
+ # below" followed by nothing.
+ skill_path = self.plugin_root / "skills" / "i-have-adhd" / "SKILL.md"
+ skill_path.write_text("---\nname: fixture\nFixture body, fence never closed.\n")
+ (self.config_dir / ".i-have-adhd-always").touch()
+ outputs = {}
+
+ for name, command in self.runtimes():
+ with self.subTest(runtime=name):
+ result = self.run_hook(command)
+ self.assertEqual(0, result.returncode)
+ self.assertEqual("", result.stderr)
+ normalized = result.stdout.replace("\r\n", "\n")
+ self.assertIn("Fixture body, fence never closed.", normalized)
+ outputs[name] = normalized
+
+ self.assertEqual(1, len(set(outputs.values())))
+
def test_hook_uses_shell_free_node_exec_form(self):
config = json.loads((ROOT / "hooks" / "hooks.json").read_text())
hook = config["hooks"]["SessionStart"][0]["hooks"][0]