Skip to content

fix(hook): nudge when wiki/ predates graph.json#2024

Open
Job28703 wants to merge 2 commits into
Graphify-Labs:v8from
Job28703:docs/2006-wiki-staleness-signal
Open

fix(hook): nudge when wiki/ predates graph.json#2024
Job28703 wants to merge 2 commits into
Graphify-Labs:v8from
Job28703:docs/2006-wiki-staleness-signal

Conversation

@Job28703

Copy link
Copy Markdown

Fixes #2006

Problem

to_wiki has exactly one call site (export wiki subcommand). It's never reached from update, watch, or the rebuild hook path, so graphify-out/wiki/ freezes the moment it's generated. Meanwhile AGENTS.md and the always_on/ prose variants tell agents to navigate the wiki unconditionally instead of reading source — an agent can silently answer architecture questions from a wiki that's months stale, with no signal anywhere in the loop.

graph.json already has this kind of staleness handling: the PreToolUse hook in cli.py compares graph.json's mtime against the target file's mtime (plus a needs_update sentinel) and softens to a nudge instead of blocking. wiki/ had no equivalent.

Fix

  • Extend the existing _run_hook_guard("read", ...) staleness check: when the read target is under wiki/, compare wiki/index.md's mtime against graph.json's. If wiki is older, emit a new _READ_NUDGE_WIKI_STALE nudge pointing the agent back to graphify query/source, and to graphify export wiki to refresh it.
  • Update AGENTS.md, always_on/agents-md.md, and always_on/antigravity-rules.md — all three told agents to trust the wiki unconditionally — to reference this new signal instead.

Docs-only fix, no change to when/how wiki/ is generated (that's the bigger option the issue also names — wiring to_wiki into update/watch — left for a separate PR if wanted).

Test plan

  • Added 3 tests to tests/test_hook_guard.py: nudges when wiki predates graph.json, silent when wiki is fresh, silent (fail-open) when graph.json doesn't exist
  • Reproduced fail-then-pass by hand: reverted just the cli.py change (keeping the new tests) — test_read_wiki_nudges_when_stale fails as expected (assert 'predates the current graph.json' in ''). Restored the fix — passes.
  • pytest tests/test_hook_guard.py tests/test_hook_strict.py -q — 89 passed, no regressions
  • pytest tests/ -q — full suite: 3239 passed, 167 skipped, 13 pre-existing failures unrelated to this change (tree_sitter_hcl not installed, ollama SDK version mismatch, wheel-packaging test — all in test_terraform.py/test_ollama_retry_cap.py/test_manifest_ingest.py/test_install_references.py, none touching cli.py or hook logic)

wiki/ is only ever written by the explicit `export wiki` subcommand —
never by `update` or watch — so it can silently go stale relative to
graph.json with no signal anywhere in the loop. Extend the existing
PreToolUse staleness check (which already compares graph.json's mtime
against the target file) to also compare wiki/index.md's mtime against
graph.json's when a wiki file is read, and nudge back to source/query
when wiki is the older of the two.

Also updates AGENTS.md and the always_on/ prose variants that
unconditionally told agents to trust the wiki, so they point at this
new signal instead of assuming wiki/ is always current.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a “stale wiki” signal to the existing hook-guard read path so agents don’t silently rely on an out-of-date graphify-out/wiki/ when it predates graphify-out/graph.json, and updates agent-facing instructions to reference that signal.

Changes:

  • Extend _run_hook_guard("read", ...) to emit a new PreToolUse nudge when wiki/index.md is older than graph.json.
  • Add focused tests covering stale wiki, fresh wiki, and missing graph.json behaviors.
  • Update AGENTS.md and always-on agent instruction variants to conditionally trust the wiki unless the nudge indicates staleness.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
graphify/cli.py Adds wiki-vs-graph.json mtime check and emits a new read nudge when wiki is stale.
tests/test_hook_guard.py Adds regression tests for stale/fresh/missing-graph wiki read behavior.
AGENTS.md Updates agent guidance to fall back when the hook flags wiki as stale.
graphify/always_on/agents-md.md Same guidance update for always-on agents instructions.
graphify/always_on/antigravity-rules.md Same guidance update for always-on antigravity rules.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread graphify/cli.py Outdated
"hookSpecificOutput": {
"hookEventName": "PreToolUse",
"additionalContext": (
'graphify-out/wiki/ predates the current graph.json. Unlike graph.json, '
…en fragment drift

Two fixes on top of the wiki-staleness nudge:

1. Both _READ_NUDGE_STALE and the new _READ_NUDGE_WIKI_STALE hardcoded
   'graphify-out/' in their message text, even though the hook-guard's
   detection logic already honors a custom GRAPHIFY_OUT_NAME. A project
   using a custom output dir would get a nudge pointing at a path that
   doesn't exist. Both are now functions parameterized by the actual
   configured out_name (flagged by Copilot's PR review on Graphify-Labs#2024).

2. The previous commit hand-edited the *generated* graphify/always_on/
   agents-md.md and antigravity-rules.md directly instead of their
   fragment sources under tools/skillgen/fragments/always-on/, which
   test_always_on_files_are_guarded_by_check (correctly) flagged as
   drift. Fixed by editing the fragments and regenerating, then
   registering the wording change in gen.ALWAYS_ON_SANCTIONED_EDITS
   (alongside the existing Graphify-Labs#1530 entry) so the byte-for-byte roundtrip
   guard treats it as an intentional, reviewable edit rather than
   silent baseline drift.

Adds 2 tests for the dynamic output-dir naming and updates
test_always_on_roundtrip_is_byte_faithful's fixed expectations to
cover both new sanctioned edits.
@Job28703

Copy link
Copy Markdown
Author

Pushed a follow-up commit addressing the review comment above: both _READ_NUDGE_STALE and _READ_NUDGE_WIKI_STALE are now functions parameterized by the actual configured output dir name instead of hardcoding graphify-out/. Added 2 tests covering a custom GRAPHIFY_OUT_NAME.

Also caught and fixed a self-inflicted issue while doing that: my first commit hand-edited the generated always_on/agents-md.md and antigravity-rules.md directly instead of their fragment sources under tools/skillgen/fragments/, which test_always_on_files_are_guarded_by_check correctly flags as drift. Fixed by editing the fragments, regenerating, and registering the wording change in gen.ALWAYS_ON_SANCTIONED_EDITS (same mechanism as the existing #1530 entry) so the byte-for-byte roundtrip guard treats it as an intentional edit.

Full suite is back to the same 13 pre-existing, unrelated failures (tree_sitter_hcl/ollama/manifest/wheel-packaging) with all 3241 other tests passing.

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.

wiki/ is only ever written by the explicit export wiki subcommand, yet AGENTS.md tells agents to navigate it instead of reading source

2 participants