Skip to content

Add --with-wiki flag to 'graphify hook install' (#549)#673

Open
azizur100389 wants to merge 1 commit intosafishamsi:v6from
azizur100389:feat/issue-549-hook-with-wiki
Open

Add --with-wiki flag to 'graphify hook install' (#549)#673
azizur100389 wants to merge 1 commit intosafishamsi:v6from
azizur100389:feat/issue-549-hook-with-wiki

Conversation

@azizur100389
Copy link
Copy Markdown
Contributor

Summary

Issue #549 reports that the post-commit hook rebuilds graph.json / graph.html / GRAPH_REPORT.md but skips the wiki, so agents following the integration guidance (reading graphify-out/wiki/index.md) navigate stale community articles after every code change. The reporter's workaround was either running graphify <path> --wiki manually or hand-editing the hook (clobbered by the next graphify hook install).

This adds an opt-in --with-wiki flag:

graphify hook install               # unchanged - no wiki rebuild
graphify hook install --with-wiki   # post-commit hook now also rebuilds graphify-out/wiki/

Implementation matches the design in #549: no LLM cost, reuses the freshly-written graph.json plus .graphify_labels.json to call wiki.to_wiki().

Diff

  • graphify/hooks.py — extracted _HOOK_SCRIPT into a _build_hook_script(with_wiki: bool) factory; install() takes a with_wiki=False kwarg
  • graphify/__main__.py — parse --with-wiki for hook install; updated help text
  • tests/test_hooks.py — 4 new tests

Backward compatibility

Default behavior unchanged: graphify hook install produces the same script as before. A regression test (test_build_hook_script_wiki_block_only_when_requested) asserts byte-for-byte equivalence with the legacy _HOOK_SCRIPT constant when with_wiki=False. Existing installations don't need any action.

Closes #549

Test plan

4 new tests:

  • test_install_default_omits_wiki_rebuild — without flag, hook script doesn't import to_wiki
  • test_install_with_wiki_injects_wiki_rebuild — with flag, hook contains the wiki block + AST rebuild + --with-wiki marker
  • test_install_with_wiki_then_uninstall_clean — uninstall removes the entire graphify section, no wiki residue
  • test_build_hook_script_wiki_block_only_when_requested_build_hook_script(with_wiki=False) == _HOOK_SCRIPT byte-for-byte

All existing tests pass; no behavior change for non-opt-in users.

The current post-commit hook rebuilds graph.json / graph.html /
GRAPH_REPORT.md but skips the wiki, so agents that follow the integration
guidance and read graphify-out/wiki/index.md get stale community articles
on every code change. Today users either run 'graphify <path> --wiki'
manually on a cadence or extend the hook by hand (clobbered on the next
'graphify hook install').

This adds an opt-in --with-wiki flag that injects a wiki rebuild block
into the post-commit hook after the AST rebuild. No LLM cost - it
reuses the freshly-written graph.json plus the existing
.graphify_labels.json (when available) to call wiki.to_wiki().

Default behavior is unchanged: 'graphify hook install' produces the
same script as before. The wiki rebuild only runs when the user
explicitly opts in via 'graphify hook install --with-wiki'.

Implementation:
- hooks.py: extract _HOOK_SCRIPT into a _build_hook_script(with_wiki)
  factory; install() takes a with_wiki kwarg
- __main__.py: parse --with-wiki for the 'hook install' subcommand and
  thread it through; update help text
- tests: 4 new tests covering default vs --with-wiki vs uninstall round
  trip, plus an equivalence check that with_wiki=False matches the
  previously-shipped _HOOK_SCRIPT byte-for-byte
@Qodo-Free-For-OSS
Copy link
Copy Markdown

Hi, graphify hook install --with-wiki does not take effect if the hook is already installed because _install_hook() returns "already installed" when it sees the marker and never rewrites the hook body. This makes it impossible to upgrade/downgrade an existing hook’s wiki behavior via reinstall.

Severity: action required | Category: correctness

How to fix: Rewrite existing marked hook

Agent prompt to fix - you can give this to your LLM of choice:

Issue description

Reinstalling hooks with a different with_wiki value does not update the already-installed hook because _install_hook() returns early when it finds the marker.

Issue Context

Users will expect graphify hook install --with-wiki to enable wiki rebuild even if they previously installed hooks without it.

Fix Focus Areas

  • graphify/hooks.py[211-222]
  • graphify/hooks.py[246-265]

Implementation notes

  • Update _install_hook() to replace the existing graphify section between # graphify-hook-start and # graphify-hook-end when the marker exists (instead of returning early).
  • Alternatively, add a force/overwrite option and use it for hook install --with-wiki upgrades, but the best UX is: marker present => update in-place.
  • Ensure uninstall still removes the section correctly afterward.

We noticed a couple of other issues in this PR as well - happy to share if helpful.


Spotted by Qodo code review - free for open-source projects.

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.

Feature request: post-commit hook should optionally rebuild the wiki

2 participants