diff --git a/mempalace/hooks_cli.py b/mempalace/hooks_cli.py index 1ab806eb36..b50be8f020 100644 --- a/mempalace/hooks_cli.py +++ b/mempalace/hooks_cli.py @@ -522,10 +522,14 @@ def _wing_from_transcript_path(transcript_path: str) -> str: ~/.claude/projects/-home--dev--/session.jsonl ~/.claude/projects/-Users---/session.jsonl - The project directory name is the final dash-separated token of the - encoded folder. Returns ``wing_`` (lowercased, spaces → ``_``). - Falls back to ``wing_sessions`` if the path does not match a Claude Code - project-folder layout. + Returns the project directory's basename, lowercased, with spaces + collapsed to underscores. Falls back to ``"sessions"`` for paths + that don't match the standard Claude Code projects layout. + + The earlier shape returned ``wing_``, which silently split + content between hook-derived ``wing_`` wings and + operator-mined bare-name wings. The bare project name converges + them. """ # Normalize path separators for cross-platform (Windows backslashes) normalized = transcript_path.replace("\\", "/") @@ -536,14 +540,13 @@ def _wing_from_transcript_path(transcript_path: str) -> str: encoded = match.group(1) project = encoded.rsplit("-", 1)[-1] if project: - return f"wing_{project.lower().replace(' ', '_')}" + return project.lower().replace(" ", "_") # Legacy fallback: explicit ``-Projects-`` segment, useful for # transcripts not under the standard Claude Code projects dir. match = re.search(r"-Projects-([^/]+?)(?:/|$)", normalized) if match: - project = match.group(1).lower().replace(" ", "_") - return f"wing_{project}" - return "wing_sessions" + return match.group(1).lower().replace(" ", "_") + return "sessions" def hook_stop(data: dict, harness: str): diff --git a/tests/test_hooks_cli.py b/tests/test_hooks_cli.py index ed1f26cf6e..280721dafc 100644 --- a/tests/test_hooks_cli.py +++ b/tests/test_hooks_cli.py @@ -236,8 +236,8 @@ def test_stop_hook_saves_silently_at_interval(tmp_path): ) # Verbatim-only: systemMessage tells the user the ingest fired; no count or themes. assert result["systemMessage"].startswith("\u2726 Transcript ingest triggered") - # tmp_path has no "-Projects-" segment, so _wing_from_transcript_path falls back to "wing_sessions" - assert "wing=wing_sessions" in result["systemMessage"] + # tmp_path has no "-Projects-" segment, so _wing_from_transcript_path falls back to "sessions" + assert "wing=sessions" in result["systemMessage"] mock_ingest.assert_called_once_with(str(transcript)) @@ -257,7 +257,7 @@ def test_stop_hook_derives_wing_from_transcript_path(tmp_path): {"session_id": "test", "stop_hook_active": False, "transcript_path": str(transcript)}, state_dir=tmp_path, ) - assert "wing=wing_myproject" in result["systemMessage"] + assert "wing=myproject" in result["systemMessage"] mock_ingest.assert_called_once_with(str(transcript)) @@ -312,39 +312,39 @@ def test_precompact_allows(tmp_path): def test_wing_from_transcript_path_extracts_project(): path = "/home/jp/.claude/projects/-home-jp-Projects-memorypalace/session.jsonl" - assert _wing_from_transcript_path(path) == "wing_memorypalace" + assert _wing_from_transcript_path(path) == "memorypalace" def test_wing_from_transcript_path_fallback(): - assert _wing_from_transcript_path("/some/random/path.jsonl") == "wing_sessions" + assert _wing_from_transcript_path("/some/random/path.jsonl") == "sessions" def test_wing_from_transcript_path_windows_backslashes(): path = "C:\\Users\\jp\\.claude\\projects\\-home-jp-Projects-myapp\\session.jsonl" - assert _wing_from_transcript_path(path) == "wing_myapp" + assert _wing_from_transcript_path(path) == "myapp" def test_wing_from_transcript_path_lowercases(): path = "/home/jp/.claude/projects/-home-jp-Projects-MyProject/session.jsonl" - assert _wing_from_transcript_path(path) == "wing_myproject" + assert _wing_from_transcript_path(path) == "myproject" def test_wing_from_transcript_path_non_projects_layout(): # Linux users with code under ~/dev/, ~/src/, ~/code/ — no -Projects- segment. # Project name is the final dash-separated token of the encoded folder. path = "/home/igor/.claude/projects/-home-igor-dev-MemPalace-mempalace/session.jsonl" - assert _wing_from_transcript_path(path) == "wing_mempalace" + assert _wing_from_transcript_path(path) == "mempalace" def test_wing_from_transcript_path_macos_users_layout(): # macOS ~/ layout without a Projects/ segment. path = "/Users/alice/.claude/projects/-Users-alice-code-MyApp/session.jsonl" - assert _wing_from_transcript_path(path) == "wing_myapp" + assert _wing_from_transcript_path(path) == "myapp" def test_wing_from_transcript_path_nested_deep(): path = "/home/bob/.claude/projects/-home-bob-work-clients-acme-frontend/session.jsonl" - assert _wing_from_transcript_path(path) == "wing_frontend" + assert _wing_from_transcript_path(path) == "frontend" # --- _log --- @@ -611,7 +611,7 @@ def test_ingest_transcript_routes_through_daemon(tmp_path): mock_post.assert_called_once() args, kwargs = mock_post.call_args assert args[0] == str(convo_dir) - assert kwargs["wing"] == "wing_myapp" + assert kwargs["wing"] == "myapp" assert kwargs["mode"] == "convos" @@ -978,10 +978,10 @@ def test_precompact_mines_transcript_dir(tmp_path, monkeypatch): cmd = mock_popen.call_args[0][0] # Mines the transcript's parent dir as convos. Wing is derived per-transcript; # for a path outside the standard Claude Code projects layout, _wing_from_transcript_path - # falls back to "wing_sessions". + # falls back to "sessions". assert str(tmp_path) in cmd assert cmd[cmd.index("--mode") + 1] == "convos" - assert cmd[cmd.index("--wing") + 1] == "wing_sessions" + assert cmd[cmd.index("--wing") + 1] == "sessions" # --- run_hook ---