Commit 09d2ca6
fix(hooks): route mining through daemon when PALACE_DAEMON_URL is set (#2)
* fix(hooks): route mining through daemon when PALACE_DAEMON_URL is set
Daemon-strict mode (introduced 2026-04-24 in commits 8c90c0f + 0e97b19
to fix the HNSW drift incident) skipped all three local mining paths
when PALACE_DAEMON_URL was set, on the assumption a daemon-side writer
would do the work instead. The diary checkpoint half got that writer
via /silent-save, but the transcript-ingest half did not — so for ~11
days every Claude Code session left a checkpoint summary in the
recovery collection and zero verbatim transcript drawers in
mempalace_drawers. mempalace_search lost visibility into recent
sessions even though MCP, daemon, and HNSW were all healthy.
Replace the three skip-and-bail branches with POSTs to the daemon's
existing /mine endpoint via a new _post_daemon_mine() helper:
* _maybe_auto_ingest (background project mine on Stop)
* _mine_sync (synchronous project mine on PreCompact)
* _ingest_transcript (transcript convo mine on Stop / PreCompact)
The daemon already has /mine; this PR just wires the hook to call it.
Path translation (so the daemon can find client-side paths in its own
filesystem) is handled daemon-side via PALACE_DAEMON_PATH_MAP — see
the companion palace-daemon PR.
Behavior change: transcript ingest now routes to the project wing
derived via _wing_from_transcript_path(), matching the diary
checkpoint behavior at hook_stop:740. Previously hardcoded "sessions";
now produces e.g. "wing_memorypalace" / "wing_realmwatch" per
transcript. The "sessions" wing remains as the fallback for paths
that don't match the Claude Code project layout (now spelled
"wing_sessions" by the existing helper).
Tests:
* 5 existing tests now use clear=True on patch.dict so PALACE_DAEMON_URL
in the developer env stops leaking into local-spawn assertions.
* 6 new tests cover _post_daemon_mine (URL/body/api-key/error-paths)
and the daemon-routed branches in all three mining functions.
* Full suite green: 1552 passed, 1 skipped.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* fix(hooks): address Copilot review on #2
Three findings from Copilot's review pass plus one CI lint fix:
1. **Wing derivation parity** (Copilot L330, L354). _maybe_auto_ingest
and _mine_sync hardcoded wing="general" in the daemon-routed
branch, but the local-spawn fallback omits --wing so convo_miner
derives from Path(mine_dir).name. The two paths produced
different wings for identical input. Add _wing_from_mine_dir()
that mirrors normalize_wing_name(Path(mine_dir).name) and use it
in both daemon-routed branches.
2. **Reuse transcript validator** (Copilot L597). _ingest_transcript
bypassed _validate_transcript_path, accepting any harness-supplied
.jsonl path including ".." traversal sequences. _count_human_messages
already validates; mirror that here so the same traversal/extension
guards apply on the ingest path.
3. **Timeout adequacy**. Daemon /mine awaits proc.communicate() (blocks
until subprocess finishes). 10s was too short for typical mines;
bump to 30s. The hook-side timeout is cosmetic — even on timeout
the daemon-side mine completes since the subprocess is independent
of the HTTP connection — but a misleading log entry still reads
like a failure.
4. **Ruff format**. CI's `ruff format --check .` flagged blank-line
gaps inside the new test class _FakeResp. Auto-formatted.
New tests:
- test_ingest_transcript_rejects_traversal — closes the security finding
- test_ingest_transcript_rejects_wrong_extension — same guard family
- test_wing_from_mine_dir_normalizes — covers the new helper
- test_maybe_auto_ingest_routes_through_daemon updated to assert wing
derivation (project dirname "my-project" → "my_project")
- test_mine_sync_routes_through_daemon updated likewise
82 passed, 1 skipped. Ruff format + lint clean.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 5b8e867 commit 09d2ca6
2 files changed
Lines changed: 260 additions & 20 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
278 | 278 | | |
279 | 279 | | |
280 | 280 | | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
281 | 332 | | |
282 | 333 | | |
283 | 334 | | |
| |||
286 | 337 | | |
287 | 338 | | |
288 | 339 | | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | 340 | | |
293 | 341 | | |
294 | 342 | | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
295 | 347 | | |
296 | 348 | | |
297 | 349 | | |
| |||
309 | 361 | | |
310 | 362 | | |
311 | 363 | | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | 364 | | |
316 | 365 | | |
317 | 366 | | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
318 | 371 | | |
319 | 372 | | |
320 | 373 | | |
| |||
543 | 596 | | |
544 | 597 | | |
545 | 598 | | |
546 | | - | |
547 | | - | |
548 | | - | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
549 | 613 | | |
550 | | - | |
551 | 614 | | |
552 | 615 | | |
553 | 616 | | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
554 | 623 | | |
555 | 624 | | |
556 | 625 | | |
| |||
572 | 641 | | |
573 | 642 | | |
574 | 643 | | |
575 | | - | |
| 644 | + | |
576 | 645 | | |
577 | 646 | | |
578 | 647 | | |
| |||
0 commit comments