Skip to content

feat(hooks): deterministic TELOS injection + SystemFileGuard#727

Closed
jlacour-git wants to merge 1 commit intodanielmiessler:mainfrom
jlacour-git:feat/deterministic-hooks
Closed

feat(hooks): deterministic TELOS injection + SystemFileGuard#727
jlacour-git wants to merge 1 commit intodanielmiessler:mainfrom
jlacour-git:feat/deterministic-hooks

Conversation

@jlacour-git
Copy link

Summary

Two hooks that replace unreliable text instructions with deterministic code, as proposed in #695.

  • TELOS/PROJECTS.md injection in LoadContext.hook.ts — programmatically injects project context at session start instead of relying on text instructions the model can ignore. Addresses Why do we rely on the model to inject `USER/TELOS/*.md` instead of injecting them programmatically? #479. Only loads PROJECTS.md (~1KB), not all 20 TELOS files (33KB).
  • SystemFileGuard.hook.ts — new PreToolUse guard for Edit/Write that checks LOCAL_PATCHES.md before allowing edits to locally-patched SYSTEM files. Prevents accidental overwrite of local patches. Fail-open, <5ms.

Both hooks follow existing patterns: use lib/paths.ts, fail gracefully, and are documented in the hooks README.

Test plan

  • Verify LoadContext loads TELOS/PROJECTS.md when the file exists and is non-empty
  • Verify LoadContext gracefully skips when TELOS/PROJECTS.md doesn't exist
  • Verify SystemFileGuard prompts when editing a file tracked in LOCAL_PATCHES.md
  • Verify SystemFileGuard passes silently for non-patched files
  • Verify SystemFileGuard passes silently when LOCAL_PATCHES.md doesn't exist (fail-open)
  • Verify no performance regression on session start (<50ms total for both)

Refs: #695, #479

🤖 Generated with Claude Code

Two hooks that replace unreliable text instructions with deterministic code:

1. LoadContext: Inject USER/TELOS/PROJECTS.md at session start (~1KB).
   Addresses danielmiessler#479 where the model was told to read TELOS files via text
   instruction but often didn't. Only PROJECTS.md (not all 20 TELOS files).

2. SystemFileGuard: PreToolUse guard for Edit/Write that checks
   LOCAL_PATCHES.md before allowing edits to locally-patched SYSTEM files.
   Prevents accidental overwrite of local patches.

Both follow the existing hook patterns (fail-open, <5ms, uses lib/paths).

Refs: danielmiessler#695, danielmiessler#479

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@danielmiessler
Copy link
Owner

Thanks for this contribution! PAI v4.0 significantly restructured the architecture — new directory layout, Algorithm v3.6.0 (up from v1.x), hooks/lib/paths.ts for path resolution, and many of the underlying systems this PR targets have been rewritten.

This PR targets the v3.0 architecture and can't be cleanly applied to v4.0.x. Closing as superseded.

The latest release is v4.0.2. We're actively working on platform compatibility and other bigger items. If there's still a gap not covered by the new releases, we'd welcome a fresh PR against the current codebase. Thanks again!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants