8000 always-on hook keeps an empty frontmatter block in the injected ruleset (Node and OpenCode paths; sh/PowerShell strip it) · Issue #263 · ayghri/i-have-adhd · GitHub
[go: up one dir, main page]

Skip to content
7FFF
  • always-on hook keeps an empty frontmatter block in the injected ruleset (Node and OpenCode paths; sh/PowerShell strip it) #263

    Open

    Description

    @SU-AN-coder

    Summary

    hooks/always-on.mjs strips a leading YAML frontmatter block with a pattern that requires at least one line between the delimiters. A block with no keys — --- on the first two lines — is still frontmatter, and the hook leaves both fences in the ruleset it injects at SessionStart. hooks/always-on.sh and hooks/always-on.ps1 strip the same file correctly, so the runtimes disagree about the same SKILL.md — exactly the divergence tests/test_always_on_hooks.py exists to catch.

    Repro

    skills/i-have-adhd/SKILL.md:

    ---
    ---
    Fixture body.
    
    $ CLAUDE_CONFIG_DIR=<dir with .i-have-adhd-always> node hooks/always-on.mjs
    ADHD MODE ACTIVE (always-on). ... delete <dir>/.i-have-adhd-always to turn always-on off for good.
    
    ---
    ---          <- the fences reach the model
    Fixture body.

    Measured on main (1ecea19), one run per runtime, same plugin root (a path with spaces) and same config dir:

    runtime text after the banner
    node hooks/always-on.mjs ---\n---\nFixture body.\n
    sh hooks/always-on.sh Fixture body.\n
    pwsh hooks/always-on.ps1 Fixture body.\n

    .opencode/plugins/i-have-adhd.mjs carries the same pattern in rulesetBody(), so OpenCode's always-on injection has the same shape on both the V1 (experimental.chat.system.transform) and V2 (context hook) paths.

    Expected

    An empty block is frontmatter like any other: both fences go, the body stays.

    Impact

    Small but visible: a SKILL.md that opens with an empty block gets two stray --- lines at the top of every session, and the three runtimes stop agreeing with each other. The shipped skills/i-have-adhd/SKILL.md has keys, so it is unaffected.

    Fix

    Making the body between the delimiters optional ((?:[\s\S]*?\r?\n)?) fixes it in the Node hook and the OpenCode plugin copy; both copies have unit-test seams, so the change is pinned by two new tests. PR to follow.

    Activity

    1. SU-AN-coder commented on Oct 18, 2026

      @SU-AN-coder
      Author

      Fix is written and verified on a branch: SU-AN-coder:fix/hooks-empty-frontmatter (head 24eb4af), one commit on top of main.

      Change — make the body between the delimiters optional in the two copies that have unit-test seams:

      -  /^---[^\S\r\n]*\r?\n[\s\S]*?\r?\n---[^\S\r\n]*(?:\r?\n|$)/
      +  /^---[^\S\r\n]*\r?\n(?:[\s\S]*?\r?\n)?---[^\S\r\n]*(?:\r?\n|$)/

      Files: hooks/always-on.mjs, .opencode/plugins/i-have-adhd.mjs (+42 −3 total with two new tests).

      Verification on the branch

      • python3 -m unittest discover -s tests -v — 80 tests, OK (78 before, +2).
      • The two new tests fail on the base ref with only the source change reverted: FAILED (failures=3) — runtime='node', mode='context', mode='v1-context', all 'Fixture body.' != '---\n---\nFixture body.'. The sh and pwsh subtests already passed, which is the same divergence reported above.
      • The shipped skills/i-have-adhd/SKILL.md still injects a byte-identical body before and after (sha256 prefix 07613106189edb3f), so nothing users receive today moves.
      • pwsh was run locally (PowerShell 7) alongside node and sh over 19 frontmatter shapes; the empty block is the only shape this change touches. The remaining PowerShell trailing-blank-line divergences are the pre-existing ones from hooks: PowerShell always-on fallback keeps trailing blank lines, so it disagrees with the Node and sh hooks #172 and are left alone.
      • python3 scripts/run_evals.py validate — valid.

      extensions/i-have-adhd.ts carries the same pattern in stripFrontmatter() and is deliberately not in this diff: it has no unit-test seam, so the change would not be pinned by anything. Same one-line change applies if you want it in the same PR.

      Opening the PR is currently refused for this account (CreatePullRequest FORBIDDEN via GraphQL; POST /repos/ayghri/i-have-adhd/pulls → 404) even though the token has repo, the fork's parent is this repo, and the API rate limit is healthy — so the branch is pushed and ready to open from here:

      https://github.com/ayghri/i-have-adhd/compare/main...SU-AN-coder:fix/hooks-empty-frontmatter?expand=1

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      No labels
      No labels

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions

      • 0