Skip to content

feat(panorama): Repair button installs link hooks from the page; closing a channel uninstalls its own hooks - #84

Merged
LiminCode merged 2 commits into
mainfrom
m4-hooks-repair
Nov 19, 2026
Merged

LiminCode merged 2 commits into
mainfrom
m4-hooks-repair

Conversation

@LiminCode

Copy link
Copy Markdown
Owner

Summary

The config panorama's pending list now carries a Repair button on the "link is on but that side's settings.json has no fish hooks" item (and on the settings.json tile detail). One confirm installs the hooks; the broken edge on the graph turns back into a flowing one right away (Windows side) or after the WSL install finishes. Turning a hooked channel off from the page or the settings process now also uninstalls the fish's own hooks, same as closing it from the right-click menu. Roadmap M4 "Claude Code 联动与 hooks 修复动作" is ticked. Consent discipline (ADR 0006) is unchanged: toggling a channel never writes hooks; the write happens only after the user clicks Repair and confirms.

What changed and why

  • pet/panorama/actions.py (new): page-action handlers. repair_hooks(manager_of, refresh) returns a handler(body) -> dict; it accepts only the two hooked agents (claude→win, claude_wsl→wsl, otherwise ActionError(400, "bad_agent")), 503 no_manager without a manager, calls AgentLinkManager.install_hooks_consented(agent), re-probes the Windows side on installed, and for pending connects install_finished once per manager (WeakSet) to re-probe the WSL side when it lands.
  • pet/panorama/service.py: actions= ctor kwarg; run_action (GUI thread via on_gui, 404 unknown_action, 500 action_failed); refresh(side) re-probes one side in a worker thread without opening the browser (win reruns the Windows probes and carries over the last WSL facts and timing.wsl_s; wsl swaps only that half), skips publishing if a full collection started meanwhile; info log lines for action completion and refresh completion.
  • pet/panorama/routes.py: POST /api/actions/{name} (token-guarded like settings), ActionError → error response, Busy → 503.
  • pet/panorama/model.py: Graph.quest(..., action=None); pet/panorama/sources.py: both quest.link_no_hooks quests carry action={"name":"repair_hooks","agent":…,"side":…}.
  • pet/panorama/page/repair.js (new): actionButton and runAction — confirm() with the same consent text as the Qt dialog, cancel sends nothing, then api.post, result written onto the button (installed / pending / failed re-enabled / connection lost re-enabled). interact.js: quests and the tile detail render the button, click handler checks [data-action] first. boot.js: send(method) factory, api.post. app.css: .btn.mini. render.py: module order (repair.js before interact.js) and the new PAGE_KEYS.
  • pet/agent_link.py: set_enabled split into "ask" (unchanged Qt dialog) and install_hooks_consented(agent_key) -> "installed"|"pending"|"failed" ("install", the only place hooks are written); _uninstall_hooks(agent_key) extracted; apply_config uninstalls the fish's own hooks when a hooked channel goes running→stopped (kept if another instance still uses them); log lines for hook write success/failure.
  • pet/app.py: registers repair_hooks when constructing PanoramaService.
  • pet/locale/zh.json, en.json: panorama.ui.repair*, action_needs_service; agent_link.hooks_missing now mentions the panorama repair.
  • Docs: docs/config-panorama.md new "动作:待处理里的「修复」" section with sequence diagram and updated apply chain; docs/session-fish.md hooks section; docs/adr/0006-writing-hooks-needs-consent.md addendum; docs/roadmap.md M4 item ticked; CHANGELOG.md 11-19 line.
  • Tests: tests/test_panorama_actions.py (new, 5), test_panorama_settings_routes.py (+2), test_panorama_service.py (+2 refresh), test_panorama_sources.py (+1), test_panorama_page.py (+4, QJSEngine harness for repair.js), test_claude_hooks_missing.py (+4 manager split / transition uninstall), test_panorama_entry.py (fake service accepts actions=).
  • Deliberately untouched: the right-click menu repair item still goes through set_enabled (ask → same install); _republish still only re-reads features.

Performance

Measured with PYTHONPATH=. QT_QPA_PLATFORM=offscreen python perf_b.py (Windows 11, this machine, venv Python, fake home dir for the install loop, real home for the probe):

Path Result
repair_hooks(claude) handler, 50 runs, writes settings.json each time median 1.98 ms, max 2.35 ms
probes.windows_side (the body of refresh("win"), real home) 395 ms, in a worker thread
Page payload, hooks ok → both sides missing hooks (2 actions) 59087 → 59406 bytes
repair.js / full bundle 2016 / 50927 bytes
  • Steady state: zero. Nothing runs until the user clicks Repair; the quest action field is the only addition to the payload, and only while hooks are missing.
  • New paths: one POST per click; the Windows install is a single settings.json read+write on the GUI thread (~2 ms); the re-probe is the existing Windows probe set on a worker thread (no browser launch); the WSL path is the existing wsl.exe install worker plus one WSL probe on the signal.
  • New syscalls / threads: one short-lived worker thread per refresh(side) (same _spawn as the full collection); no new network or polling.
  • Memory: a WeakSet of managers whose signal is connected (at most one entry).

Real-machine run

  1. Staged the fault on this machine: ClaudeCodeMonitor.uninstall_hooks() removed the fish's own entries from ~/.claude/settings.json; missing_hooks() listed all 9 events.
  2. Restarted the pet from this branch (pid 43796, 10:25:39). Log: WARNING Claude Code 联动开着,但 settings.json 里缺肥鱼的 hooks(9 个事件)… and INFO Claude Code (WSL) 联动:hooks 都在.
  3. Opened the panorama (service on 127.0.0.1:5138 at 11:54:03, WSL side probed in 8.93 s). The pending list showed the broken-link item with a Repair button; the user clicked it and confirmed.
  4. Result at 11:54:33 (same second): ~/.claude/settings.json rewritten, missing_hook_events(settings) == [], ClaudeCodeMonitor.missing_hooks() == []; the offline snapshot %APPDATA%\big-fat-fish\panorama\panorama.html rewritten and no longer contains the no-hooks quest or any repair_hooks action (re-probe + publish ran). No ERROR / Traceback in pet-43796.log.
  5. Gap found during this run: the action and the re-probe left no log line; the last commit adds three info lines (action done, refresh done, hooks written). Those lines are covered by the unit tests, not re-run on the machine (the running pet predates them).

Tests

Red-first: the new tests failed before the product change (ImportError for pet.panorama.actions, missing route, missing install_hooks_consented). Then the affected families (panorama, agent link / hooks, architecture, PR discipline, i18n, context menus): 1021 passed, 3 failures are the known baselines (compact_semantic_groups, three_column_masonry, compact_ai_provider_controls). After the logging commit: tests/test_panorama_service.py tests/test_panorama_actions.py tests/test_panorama_settings_routes.py tests/test_claude_hooks_missing.py → 79 passed. ruff check and git diff --check clean. The full suite was not run: no config schema / migration, no packaging or platform-dispatch change; the lifecycle change is confined to AgentLinkManager.apply_config and is covered by test_claude_hooks_missing.py.

Docs

  • CHANGELOG.md: one line (user-visible change)
  • Topic doc under docs/ updated (config-panorama.md, session-fish.md, roadmap tick)
  • ADR: addendum to ADR 0006 (no new ADR — the consent decision is unchanged, only the consent dialog moved to the page)

🤖 Generated with Claude Code

LiminCode and others added 2 commits November 19, 2026 10:25
- pet/panorama/actions.py:页面动作的处理器;repair_hooks 只认两条 hooked 通道,调管理器
  「已同意、装」那一半,本机装完重探 Windows 一侧,WSL 后台装、install_finished 到了再重探
- service:actions 登记表、run_action(界面线程)、refresh(side) 只重探一侧不开浏览器
- routes:POST /api/actions/<名字>;model.quest 带 action;sources 给缺 hooks 的待处理项挂动作
- 页面:repair.js(confirm → api.post → 结果写在按钮上)、interact.js 待处理与磁贴详情出按钮、
  boot.js 的 api.post
- AgentLinkManager:set_enabled 拆成「问」和 install_hooks_consented「装」;apply_config 停
  hooked 通道时卸自己的 hooks(_uninstall_hooks,别的实例还在用就留着)
- app:构造 PanoramaService 时登记 repair_hooks
- ADR 0006 补记;docs/config-panorama「动作」一节;session-fish;路线图 M4 第六项打勾;CHANGELOG

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
真机点「修复」后 settings.json 与快照都在同一秒改写、hooks 回来了,但日志里一行没有——排障时找不到这次动作的痕迹。

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@LiminCode
LiminCode merged commit a9c9b57 into main Nov 19, 2026
0 of 3 checks passed
LiminCode added a commit that referenced this pull request Nov 20, 2026
…许碰开发机真实文件 (#91)

2026-11-20 凌晨跑 test_background_service_gates / test_harness_ownership 把本机 ~/.claude/settings.json 里肥鱼的 hooks 清掉了
(#84 起关联动会卸 hooks)。在既有的 autouse 总夹具里把 ClaudeCodeMonitor.get_settings_path 指到 tmp_path,不另加夹具;
加一个回归测试:真管理器把 claude 关掉,真实文件的 mtime 不变。

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
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.

1 participant