knowledgevault 0.17.1__tar.gz → 0.17.3__tar.gz

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.
Files changed (96) hide show
  1. {knowledgevault-0.17.1/knowledgevault.egg-info → knowledgevault-0.17.3}/PKG-INFO +1 -1
  2. {knowledgevault-0.17.1 → knowledgevault-0.17.3/knowledgevault.egg-info}/PKG-INFO +1 -1
  3. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/kvault/_version.py +1 -1
  4. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/kvault/core/search.py +40 -27
  5. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/pyproject.toml +1 -1
  6. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/tests/test_search_precision.py +51 -0
  7. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/LICENSE +0 -0
  8. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/MANIFEST.in +0 -0
  9. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/README.md +0 -0
  10. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/knowledgevault.egg-info/SOURCES.txt +0 -0
  11. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/knowledgevault.egg-info/dependency_links.txt +0 -0
  12. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/knowledgevault.egg-info/entry_points.txt +0 -0
  13. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/knowledgevault.egg-info/requires.txt +0 -0
  14. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/knowledgevault.egg-info/top_level.txt +0 -0
  15. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/kvault/__init__.py +0 -0
  16. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/kvault/cli/__init__.py +0 -0
  17. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/kvault/cli/_helpers.py +0 -0
  18. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/kvault/cli/check.py +0 -0
  19. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/kvault/cli/doctor.py +0 -0
  20. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/kvault/cli/entity.py +0 -0
  21. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/kvault/cli/events.py +0 -0
  22. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/kvault/cli/journal.py +0 -0
  23. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/kvault/cli/main.py +0 -0
  24. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/kvault/cli/plan.py +0 -0
  25. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/kvault/cli/render.py +0 -0
  26. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/kvault/cli/search.py +0 -0
  27. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/kvault/cli/summary.py +0 -0
  28. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/kvault/cli/validate.py +0 -0
  29. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/kvault/core/__init__.py +0 -0
  30. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/kvault/core/check.py +0 -0
  31. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/kvault/core/conventions.py +0 -0
  32. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/kvault/core/daily_artifacts.py +0 -0
  33. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/kvault/core/decisions.py +0 -0
  34. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/kvault/core/duplicates.py +0 -0
  35. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/kvault/core/events.py +0 -0
  36. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/kvault/core/frontmatter.py +0 -0
  37. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/kvault/core/locks.py +0 -0
  38. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/kvault/core/notes.py +0 -0
  39. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/kvault/core/observability.py +0 -0
  40. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/kvault/core/operations.py +0 -0
  41. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/kvault/core/oplog.py +0 -0
  42. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/kvault/core/paths.py +0 -0
  43. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/kvault/core/plan.py +0 -0
  44. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/kvault/core/references.py +0 -0
  45. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/kvault/core/research.py +0 -0
  46. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/kvault/core/storage.py +0 -0
  47. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/kvault/core/structure.py +0 -0
  48. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/kvault/core/summary_quality.py +0 -0
  49. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/kvault/core/validation.py +0 -0
  50. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/kvault/mcp/__init__.py +0 -0
  51. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/kvault/mcp/server.py +0 -0
  52. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/kvault/py.typed +0 -0
  53. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/kvault/templates/AGENTS.md +0 -0
  54. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/kvault/templates/__init__.py +0 -0
  55. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/kvault/templates/category_summary.md +0 -0
  56. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/kvault/templates/journal_entry.md +0 -0
  57. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/kvault/templates/root_summary.md +0 -0
  58. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/setup.cfg +0 -0
  59. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/tests/test_api_exports.py +0 -0
  60. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/tests/test_bounded_reads.py +0 -0
  61. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/tests/test_check.py +0 -0
  62. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/tests/test_check_filters.py +0 -0
  63. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/tests/test_check_structure.py +0 -0
  64. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/tests/test_cli_commands.py +0 -0
  65. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/tests/test_cli_write_workflow.py +0 -0
  66. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/tests/test_confirm_destructive.py +0 -0
  67. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/tests/test_daily_artifacts.py +0 -0
  68. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/tests/test_decisions.py +0 -0
  69. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/tests/test_duplicates.py +0 -0
  70. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/tests/test_e2e_workflows.py +0 -0
  71. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/tests/test_events.py +0 -0
  72. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/tests/test_frontmatter.py +0 -0
  73. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/tests/test_log_cli.py +0 -0
  74. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/tests/test_loose_visibility.py +0 -0
  75. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/tests/test_mcp_server.py +0 -0
  76. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/tests/test_mcp_structure.py +0 -0
  77. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/tests/test_mcp_surface.py +0 -0
  78. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/tests/test_move_batch.py +0 -0
  79. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/tests/test_naming_and_validate_kb.py +0 -0
  80. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/tests/test_notes.py +0 -0
  81. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/tests/test_operations.py +0 -0
  82. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/tests/test_oplog.py +0 -0
  83. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/tests/test_output_channels.py +0 -0
  84. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/tests/test_patches.py +0 -0
  85. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/tests/test_path_safety_and_locks.py +0 -0
  86. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/tests/test_paths_and_digest_guards.py +0 -0
  87. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/tests/test_plan.py +0 -0
  88. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/tests/test_references.py +0 -0
  89. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/tests/test_research.py +0 -0
  90. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/tests/test_stale.py +0 -0
  91. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/tests/test_storage.py +0 -0
  92. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/tests/test_structure.py +0 -0
  93. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/tests/test_summary_quality.py +0 -0
  94. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/tests/test_work_reporting.py +0 -0
  95. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/tests/test_write_guards.py +0 -0
  96. {knowledgevault-0.17.1 → knowledgevault-0.17.3}/tests/test_write_integrity.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: knowledgevault
3
- Version: 0.17.1
3
+ Version: 0.17.3
4
4
  Summary: CLI-first personal knowledge base for AI agents — structured, navigable, zero extra cost
5
5
  Author: Eddie Landesberg
6
6
  License-Expression: MIT
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: knowledgevault
3
- Version: 0.17.1
3
+ Version: 0.17.3
4
4
  Summary: CLI-first personal knowledge base for AI agents — structured, navigable, zero extra cost
5
5
  Author: Eddie Landesberg
6
6
  License-Expression: MIT
@@ -13,6 +13,6 @@ try:
13
13
  __version__ = _distribution_version("knowledgevault")
14
14
  except PackageNotFoundError:
15
15
  # Uninstalled source tree only; keep in sync with pyproject.toml.
16
- __version__ = "0.17.1"
16
+ __version__ = "0.17.3"
17
17
 
18
18
  __all__ = ["__version__"]
@@ -226,7 +226,7 @@ def search_nodes(
226
226
  title=doc.title,
227
227
  score=round(score, 3),
228
228
  matched_fields=sorted(matched_fields),
229
- snippet=_snippet(doc, query, query_tokens, max_chars=snippet_max),
229
+ snippet=_snippet(doc, query_tokens, max_chars=snippet_max),
230
230
  summary_path=doc.summary_path,
231
231
  last_updated=doc.last_updated,
232
232
  content=content,
@@ -651,39 +651,52 @@ def _idf(documents: Sequence[SearchDocument], query_tokens: Sequence[str]) -> Di
651
651
 
652
652
  def _snippet(
653
653
  doc: SearchDocument,
654
- query: str,
655
654
  query_tokens: Sequence[str],
656
655
  max_chars: int = _SNIPPET_MAX_CHARS,
657
656
  ) -> str:
658
- text = re.sub(r"\s+", " ", doc.content).strip()
659
657
  if max_chars <= 0:
660
658
  return ""
661
- if not text:
662
- return doc.title[:max_chars]
663
- haystack = text.lower()
664
- needle = query.lower().strip()
665
- idx = haystack.find(needle) if needle else -1
666
- if idx < 0:
667
- token_positions = [
668
- haystack.find(token) for token in query_tokens if haystack.find(token) >= 0
669
- ]
670
- idx = min(token_positions) if token_positions else 0
671
-
659
+ text = re.sub(r"\s+", " ", doc.content.strip() or doc.title).strip()
672
660
  if len(text) <= max_chars:
673
661
  return text
674
- if max_chars < 8:
675
- return text[:max_chars]
676
- # The "..." markers count toward max_chars: a 120-character snippet is 120.
677
- width = max_chars - 6
678
- start = max(0, idx - width // 3)
679
- end = min(len(text), start + width)
680
- start = max(0, end - width)
681
- snippet = text[start:end].strip()
682
- if start > 0:
683
- snippet = "..." + snippet
684
- if end < len(text):
685
- snippet += "..."
686
- return snippet
662
+ marker = "..."
663
+ if max_chars <= len(marker):
664
+ return marker[:max_chars]
665
+
666
+ # Match the same ASCII tokens and intervening punctuation as the scorer.
667
+ # A raw substring would anchor "paid invoice" inside "unpaid invoice".
668
+ def match_tokens(pattern: str) -> Optional[re.Match[str]]:
669
+ return re.search(r"(?<![a-z0-9])(?:" + pattern + r")(?![a-z0-9])", text, re.I | re.ASCII)
670
+
671
+ match = match_tokens(r"[^a-z0-9]+".join(query_tokens))
672
+ if match is None and len(query_tokens) > 1:
673
+ match = match_tokens("|".join(query_tokens))
674
+ first, last = match.span() if match else (0, 0)
675
+ if match:
676
+ # Keep punctuation attached to the final matching word in the budget.
677
+ after_word = text.find(" ", last)
678
+ last = len(text) if after_word < 0 else after_word
679
+
680
+ # Start around a third of a window before the match. Keep whole source
681
+ # words, including a hyphen or sign attached to them, at both cut edges.
682
+ width = max(1, max_chars - 2 * len(marker))
683
+ preferred = max(0, min(first - width // 3, len(text) - width))
684
+ start = text.rfind(" ", 0, preferred + 1) + 1
685
+ # A long preceding word or phrase may otherwise push the match offscreen.
686
+ earliest = max(0, min(first, last - width))
687
+ if start < earliest:
688
+ boundary = text.find(" ", earliest - 1, first)
689
+ if boundary >= 0:
690
+ start = boundary + 1
691
+ prefix = marker if start else ""
692
+ end = start + max_chars - len(prefix)
693
+ if end >= len(text):
694
+ return prefix + text[start:]
695
+ end -= len(marker)
696
+ end = text.rfind(" ", start, end + 1)
697
+ if end <= start:
698
+ return marker
699
+ return prefix + text[start:end] + marker
687
700
 
688
701
 
689
702
  def _truncate(text: str, max_chars: int) -> Tuple[str, bool]:
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "knowledgevault"
7
- version = "0.17.1"
7
+ version = "0.17.3"
8
8
  description = "CLI-first personal knowledge base for AI agents — structured, navigable, zero extra cost"
9
9
  readme = "README.md"
10
10
  license = "MIT"
@@ -11,6 +11,8 @@
11
11
 
12
12
  from pathlib import Path
13
13
 
14
+ import pytest
15
+
14
16
  from kvault.core import operations as ops
15
17
 
16
18
 
@@ -44,6 +46,55 @@ def test_short_queries_match_whole_words_only(tmp_path):
44
46
  assert not email or not {"title", "path"} & set(email[0]["matched_fields"])
45
47
 
46
48
 
49
+ def test_compact_snippet_keeps_the_source_invoice_status(tmp_path):
50
+ kb = _kb(tmp_path)
51
+ _node(
52
+ kb,
53
+ "accounts",
54
+ "# Accounts\n\nThe handoff contains one outstanding item for accounting. "
55
+ "The unpaid invoice still requires approval. Follow-up is scheduled for next Thursday "
56
+ "after the review committee meets to review the supporting details and attachments. "
57
+ "Keep the original note with the ledger.",
58
+ )
59
+ hit = ops.search_nodes(kb, "follow-up", compact=True)["results"][0]
60
+ assert hit["snippet"].startswith("...unpaid invoice still requires approval. Follow-up")
61
+ assert len(hit["snippet"]) <= 120
62
+
63
+
64
+ def test_snippet_ends_before_a_partial_approval_status(tmp_path):
65
+ kb = _kb(tmp_path)
66
+ _node(
67
+ kb,
68
+ "reviews",
69
+ "# Desk\n\nLaunch notice: release is approved-pending-review and awaits signoff.",
70
+ )
71
+ budget = len("# Desk Launch notice: release is approved") + 6
72
+ hit = ops.search_nodes(kb, "launch", snippet_chars=budget)["results"][0]
73
+ assert hit["snippet"] == "# Desk Launch notice: release is..."
74
+
75
+
76
+ @pytest.mark.parametrize(
77
+ ("query", "opening", "evidence"),
78
+ [
79
+ ("paid invoice", "That unpaid invoice remains open.", "The PAID / invoice is separate."),
80
+ ("AI decision", "Read the email with the details.", "The AI review starts tomorrow."),
81
+ ],
82
+ )
83
+ def test_snippet_anchors_the_same_whole_tokens_as_ranking(tmp_path, query, opening, evidence):
84
+ kb = _kb(tmp_path)
85
+ _node(kb, "reviews", "# Desk\n\n" + opening + " Some background." * 20 + " " + evidence)
86
+ hit = ops.search_nodes(kb, query, compact=True)["results"][0]
87
+ assert evidence in hit["snippet"]
88
+
89
+
90
+ def test_snippet_omits_an_overlong_word_instead_of_making_a_new_label(tmp_path):
91
+ kb = _kb(tmp_path)
92
+ _node(kb, "approvals", "unapproved")
93
+ for budget in range(10):
94
+ hit = ops.search_nodes(kb, "unapproved", snippet_chars=budget)["results"][0]
95
+ assert hit["snippet"] == "..."[:budget]
96
+
97
+
47
98
  def test_parked_copies_are_background(tmp_path):
48
99
  kb = _kb(tmp_path)
49
100
  _node(kb, "projects/keeper", "# Keeper\n\nThe zebra protocol owner.\n")
File without changes