Skip to content

Commit 3500ed4

Browse files
committed
fix(integrations): include Pi checkpoint excerpts in briefs
Signed-off-by: phernandez <paul@basicmachines.co>
1 parent 489cd50 commit 3500ed4

2 files changed

Lines changed: 49 additions & 1 deletion

File tree

src/basic_memory/cli/commands/hook.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,16 @@ def _label(result: dict[str, Any]) -> str:
679679
return f"- {name}" + (f" — {ref}" if ref else "")
680680

681681

682+
def _session_label(result: dict[str, Any], include_excerpt: bool) -> list[str]:
683+
lines = [_label(result)]
684+
if not include_excerpt:
685+
return lines
686+
excerpt = result.get("matched_chunk") or result.get("content")
687+
if isinstance(excerpt, str) and excerpt.strip():
688+
lines.append(f" {_clip(excerpt, 500)}")
689+
return lines
690+
691+
682692
def _readable(ref: str) -> str:
683693
from basic_memory.hooks.project_ref import UUID_RE
684694

@@ -772,10 +782,17 @@ def _build_brief(
772782
if decision_rows:
773783
data_lines += ["", f"## Open decisions ({len(decision_rows)})", *map(_label, decision_rows)]
774784
if session_rows:
785+
session_lines = [
786+
line
787+
for row in session_rows
788+
for line in _session_label(
789+
row, include_excerpt=profile.session_note_type == "pi_session"
790+
)
791+
]
775792
data_lines += [
776793
"",
777794
f"## Recent sessions ({len(session_rows)}) — where you left off",
778-
*map(_label, session_rows),
795+
*session_lines,
779796
]
780797
if not (task_rows or decision_rows or session_rows):
781798
data_lines += ["", "_No active tasks, open decisions, or recent sessions in this project._"]

tests/cli/test_pi_hook_regressions.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,37 @@ def test_pi_checkpoint_reuses_identity_and_separates_branches(tmp_path: Path) ->
5959
assert all(call["project"] == "explicit-project" for call in calls)
6060

6161

62+
def test_pi_hook_brief_includes_checkpoint_excerpts(tmp_path: Path) -> None:
63+
config = tmp_path / ".pi" / "basic-memory.json"
64+
config.parent.mkdir()
65+
config.write_text(json.dumps({"project": "explicit-project"}), encoding="utf-8")
66+
search = AsyncMock(
67+
side_effect=[
68+
{"results": []},
69+
{"results": []},
70+
{
71+
"results": [
72+
{
73+
"title": "Pi session hashed-title",
74+
"permalink": "pi/sessions/pi-session-hashed-title",
75+
"content": "Decision: keep bmCommand as an argv override.",
76+
}
77+
]
78+
},
79+
]
80+
)
81+
with patch("basic_memory.mcp.tools.search_notes", search):
82+
result = runner.invoke(
83+
app,
84+
["hook", "session-start", "--harness", "pi", "--project-dir", str(tmp_path)],
85+
input=json.dumps({"session_id": "session-a", "cwd": str(tmp_path)}),
86+
)
87+
88+
assert result.exit_code == 0
89+
assert "Pi session hashed-title" in result.stdout
90+
assert "Decision: keep bmCommand as an argv override." in result.stdout
91+
92+
6293
def test_pi_hook_settings_preserve_canonical_key_precedence(tmp_path: Path) -> None:
6394
config = tmp_path / ".pi" / "basic-memory.json"
6495
config.parent.mkdir()

0 commit comments

Comments
 (0)