feat(cli): add minimal hook subcommand for Claude Code integration#513
feat(cli): add minimal hook subcommand for Claude Code integration#513dc-tw wants to merge 1 commit intoMemPalace:developfrom
Conversation
web3guru888
left a comment
There was a problem hiding this comment.
Thanks for the targeted fix — the immediate pain of the invalid choice: 'hook' error is a real blocker and it's good to get the subcommand wired up.
A flag on the implementation: the current stub replaces hooks_cli.run_hook() with print statements and exits, which means hook run --hook stop now succeeds without actually persisting anything to the palace. The PR description references #328 — if I'm reading the history right, the concern in #328 was that the hook subcommand was missing, not that run_hook itself was broken.
The effect of this PR is that Claude Code's stop/save hooks will now exit 0 (and show a confirmation message) without writing to MemPalace. That's better than crashing, but it's a silent no-op — users will see success output and assume their session was saved when it wasn't.
Would it make sense to:
- Keep the
try/exceptwrapper (good defensive practice around the import), but fall through to callingrun_hook()when it's available? - Only fall back to the no-op stub if
hooks_cliisn't importable?
Something like:
def cmd_hook(args):
try:
from .hooks_cli import run_hook
run_hook(hook_name=args.hook, harness=args.harness)
except ImportError:
print(f"[MemPalace Hook] hooks_cli not available, hook '{args.hook}' skipped.", file=sys.stderr)
sys.exit(0)
except Exception as e:
print(f"[MemPalace Hook] Error: {e}", file=sys.stderr)
sys.exit(1)That way the subcommand exists (fixes the crash), uses the real implementation when available, and degrades gracefully if it isn't. Happy to be corrected if there's a reason run_hook itself is the problem here.
|
Nice fix — the narrow scope (cmd_hook only) is exactly right here. The We hit this same wall in our multi-agent setup and ended up patching around it locally, so glad to see it land properly. Minimal and mergeable is the right call for a first step. Thanks for tracking this back to #328 and keeping the PR tight, @dc-tw. |
To fix the PR#328 mistake, update as below
Description
Claude Code's stop/save hooks currently call:
python -m mempalace hook run --hook stop --harness claude-codeThis caused
invalid choice: 'hook'error because the subcommand didn't exist.This PR adds a minimal
hook runsubcommand as a first step.Changes (Narrow Scope)
Testing