kyp-mem 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
1
  """KYP-MEM — Know Your Project Memory. Headless knowledge base for AI agents."""
2
2
 
3
- __version__ = "0.3.0"
3
+ __version__ = "0.4.1"
package/kyp_mem/server.py CHANGED
@@ -11,6 +11,61 @@ vault = Vault(get_vault_path())
11
11
  mcp = FastMCP("kyp-mem")
12
12
 
13
13
 
14
+ @mcp.tool()
15
+ def ____kyp_instructions() -> str:
16
+ """## KYP-MEM — Know Your Project Memory
17
+
18
+ YOU MUST FOLLOW THESE INSTRUCTIONS when kyp-mem tools are available.
19
+
20
+ ### AT SESSION START (MANDATORY)
21
+ 1. Identify the project you are working on from the user's working directory or question.
22
+ 2. Call `kyp_project_context(project)` to load the project's knowledge base, notes, and recent session summaries.
23
+ 3. If no project exists yet, call `kyp_project_context` anyway — if it returns empty, ask the user if you should create one.
24
+ 4. Use the returned context to ground yourself: understand architecture, known bugs, past decisions, and what was done in recent sessions. Do NOT ask the user questions that are already answered in the project context.
25
+
26
+ ### DURING WORK — WHEN TO SEARCH SESSIONS
27
+ Call `kyp_session_search(query)` when:
28
+ - You encounter a bug or error — search for it to see if it was investigated before.
29
+ - You are about to make an architectural decision — check if a prior session already made this decision.
30
+ - The user asks "did we already...", "what happened with...", "last time we..." — search sessions semantically.
31
+ - You are unsure about project-specific behavior — sessions contain investigation logs.
32
+
33
+ ### DURING WORK — WHEN TO UPDATE KNOWLEDGE
34
+ Call `kyp_write` to update the project's Knowledge.md when you:
35
+ - Fix a bug → add it under ## Bugs > ### Fixed
36
+ - Discover a new bug → add it under ## Bugs > ### Known
37
+ - Make an architectural decision → add it under ## Key Decisions
38
+ - Learn something important about the project → add it under ## Notes
39
+ - Complete an improvement → move it from ## Improvements > ### Planned to ### Completed
40
+
41
+ Also use `kyp_write` to create new project notes for substantial topics (API docs, setup guides, component deep-dives). Use [[wikilinks]] to connect notes.
42
+
43
+ ### DURING WORK — WHEN TO USE OTHER TOOLS
44
+ - `kyp_search(query)` — keyword search across ALL notes (not just sessions). Use for finding specific content.
45
+ - `kyp_read(path)` — read a specific note. Default is brief mode; use full=True for complete content.
46
+ - `kyp_related(path)` — find notes connected by backlinks, tags, or folder proximity.
47
+ - `kyp_tags(tag)` — browse by tag or list all tags.
48
+
49
+ ### SESSION CAPTURE
50
+ Sessions are captured automatically by hooks — you do not need to create session notes manually. If the user explicitly asks to log a session, use `kyp_session_create`.
51
+
52
+ ### IMPORTANT RULES
53
+ - NEVER hallucinate project details. If it's not in the knowledge base or sessions, say you don't know.
54
+ - ALWAYS check knowledge base before making assumptions about project architecture.
55
+ - Keep Knowledge.md updated as you work — it is the source of truth for future sessions.
56
+ - Use [[wikilinks]] in notes to build the knowledge graph.
57
+ - Tag notes consistently: use project name, topic tags, and type tags (bug, decision, guide, etc.).
58
+
59
+ Call this tool to acknowledge these instructions. It returns a confirmation."""
60
+ projects = []
61
+ for path in vault.index.notes:
62
+ parts = path.split("/")
63
+ if len(parts) > 1:
64
+ projects.append(parts[0])
65
+ unique = sorted(set(projects))
66
+ return f"KYP-MEM active. Available projects: {', '.join(unique) if unique else '(none)'}. Call kyp_project_context(project) to load context."
67
+
68
+
14
69
  @mcp.tool()
15
70
  def kyp_list(path: str = "") -> str:
16
71
  """List notes and folders in the vault. Shows inline tags for quick navigation. Pass a folder path or empty for root."""
@@ -96,7 +151,7 @@ def kyp_read(path: str, full: bool = False) -> str:
96
151
 
97
152
  @mcp.tool()
98
153
  def kyp_write(path: str, content: str, tags: str = "", properties: str = "") -> str:
99
- """Create or update a note. Path like 'Project/Note.md'. Tags: comma-separated. Properties: JSON string."""
154
+ """Create or update a note. Use this to persist knowledge: bug fixes, architectural decisions, setup guides, API contracts. Path like 'Project/Note.md'. Use [[wikilinks]] in content to connect notes. Tags: comma-separated. Properties: JSON string."""
100
155
  if not path.endswith(".md"):
101
156
  path += ".md"
102
157
 
@@ -194,6 +249,25 @@ def kyp_stats() -> str:
194
249
  )
195
250
 
196
251
 
252
+ @mcp.tool()
253
+ def kyp_session_search(query: str, project: str = None) -> str:
254
+ """Semantic search across past session logs using vector embeddings. Use this to recall: what was investigated, bugs encountered, decisions made, and next steps from prior sessions. Search before re-investigating known issues or making decisions that may have been made before."""
255
+ from .vector import get_session_memory
256
+ results = get_session_memory().search_sessions(query, project=project, n_results=5)
257
+
258
+ if not results or not results.get("ids") or not results["ids"][0]:
259
+ return "No relevant past sessions found."
260
+
261
+ lines = ["Semantic Session Search Results:", ""]
262
+ for i, path in enumerate(results["ids"][0]):
263
+ doc = results["documents"][0][i]
264
+ score = results["distances"][0][i]
265
+ lines.append(f"--- Session: {path} (Distance: {score:.2f}) ---")
266
+ lines.append(doc)
267
+ lines.append("")
268
+ return "\n".join(lines)
269
+
270
+
197
271
  @mcp.tool()
198
272
  def kyp_session_create(project: str, summary: str = "", investigated: str = "", learned: str = "", completed: str = "", next_steps: str = "") -> str:
199
273
  """Create a structured session note. Project is required. Sections accept markdown text."""
@@ -247,7 +321,7 @@ def kyp_sessions(project: str = "", limit: int = 10) -> str:
247
321
 
248
322
  @mcp.tool()
249
323
  def kyp_project_context(project: str) -> str:
250
- """Get full project context: knowledge base + recent session summaries. Call this at session start to understand project history, avoid repeating past work, and prevent hallucination."""
324
+ """CALL THIS AT SESSION START. Returns the project's full context: Knowledge.md (ground truth), project notes, and recent session summaries. Use this to understand architecture, known bugs, past decisions, and what was done recently. This prevents hallucination and avoids repeating past work."""
251
325
  parts = []
252
326
 
253
327
  knowledge_path = f"{project}/Knowledge.md"