knowledgevault 0.17.1__tar.gz → 0.17.4__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 (107) hide show
  1. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/MANIFEST.in +1 -0
  2. {knowledgevault-0.17.1/knowledgevault.egg-info → knowledgevault-0.17.4}/PKG-INFO +14 -1
  3. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/README.md +13 -0
  4. knowledgevault-0.17.4/docs/reviewing-changes.md +21 -0
  5. {knowledgevault-0.17.1 → knowledgevault-0.17.4/knowledgevault.egg-info}/PKG-INFO +14 -1
  6. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/knowledgevault.egg-info/SOURCES.txt +10 -1
  7. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/kvault/_version.py +1 -1
  8. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/kvault/cli/entity.py +49 -1
  9. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/kvault/cli/events.py +99 -0
  10. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/kvault/cli/main.py +25 -0
  11. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/kvault/cli/summary.py +6 -3
  12. knowledgevault-0.17.4/kvault/core/_changed_passages.py +348 -0
  13. knowledgevault-0.17.4/kvault/core/event_changes.py +374 -0
  14. knowledgevault-0.17.4/kvault/core/json_pages.py +90 -0
  15. knowledgevault-0.17.4/kvault/core/literal_reference.py +37 -0
  16. knowledgevault-0.17.4/kvault/core/locks.py +308 -0
  17. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/kvault/core/operations.py +159 -21
  18. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/kvault/core/search.py +77 -51
  19. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/kvault/mcp/server.py +119 -10
  20. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/kvault/templates/AGENTS.md +10 -0
  21. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/pyproject.toml +1 -1
  22. knowledgevault-0.17.4/tests/test_event_changes.py +687 -0
  23. knowledgevault-0.17.4/tests/test_guarded_source_edits.py +206 -0
  24. knowledgevault-0.17.4/tests/test_search_precision.py +300 -0
  25. knowledgevault-0.17.4/tests/test_source_pages.py +94 -0
  26. knowledgevault-0.17.4/tests/test_write_lock_ownership.py +252 -0
  27. knowledgevault-0.17.1/kvault/core/locks.py +0 -194
  28. knowledgevault-0.17.1/tests/test_search_precision.py +0 -122
  29. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/LICENSE +0 -0
  30. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/knowledgevault.egg-info/dependency_links.txt +0 -0
  31. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/knowledgevault.egg-info/entry_points.txt +0 -0
  32. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/knowledgevault.egg-info/requires.txt +0 -0
  33. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/knowledgevault.egg-info/top_level.txt +0 -0
  34. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/kvault/__init__.py +0 -0
  35. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/kvault/cli/__init__.py +0 -0
  36. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/kvault/cli/_helpers.py +0 -0
  37. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/kvault/cli/check.py +0 -0
  38. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/kvault/cli/doctor.py +0 -0
  39. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/kvault/cli/journal.py +0 -0
  40. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/kvault/cli/plan.py +0 -0
  41. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/kvault/cli/render.py +0 -0
  42. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/kvault/cli/search.py +0 -0
  43. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/kvault/cli/validate.py +0 -0
  44. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/kvault/core/__init__.py +0 -0
  45. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/kvault/core/check.py +0 -0
  46. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/kvault/core/conventions.py +0 -0
  47. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/kvault/core/daily_artifacts.py +0 -0
  48. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/kvault/core/decisions.py +0 -0
  49. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/kvault/core/duplicates.py +0 -0
  50. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/kvault/core/events.py +0 -0
  51. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/kvault/core/frontmatter.py +0 -0
  52. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/kvault/core/notes.py +0 -0
  53. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/kvault/core/observability.py +0 -0
  54. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/kvault/core/oplog.py +0 -0
  55. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/kvault/core/paths.py +0 -0
  56. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/kvault/core/plan.py +0 -0
  57. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/kvault/core/references.py +0 -0
  58. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/kvault/core/research.py +0 -0
  59. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/kvault/core/storage.py +0 -0
  60. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/kvault/core/structure.py +0 -0
  61. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/kvault/core/summary_quality.py +0 -0
  62. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/kvault/core/validation.py +0 -0
  63. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/kvault/mcp/__init__.py +0 -0
  64. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/kvault/py.typed +0 -0
  65. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/kvault/templates/__init__.py +0 -0
  66. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/kvault/templates/category_summary.md +0 -0
  67. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/kvault/templates/journal_entry.md +0 -0
  68. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/kvault/templates/root_summary.md +0 -0
  69. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/setup.cfg +0 -0
  70. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/tests/test_api_exports.py +0 -0
  71. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/tests/test_bounded_reads.py +0 -0
  72. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/tests/test_check.py +0 -0
  73. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/tests/test_check_filters.py +0 -0
  74. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/tests/test_check_structure.py +0 -0
  75. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/tests/test_cli_commands.py +0 -0
  76. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/tests/test_cli_write_workflow.py +0 -0
  77. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/tests/test_confirm_destructive.py +0 -0
  78. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/tests/test_daily_artifacts.py +0 -0
  79. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/tests/test_decisions.py +0 -0
  80. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/tests/test_duplicates.py +0 -0
  81. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/tests/test_e2e_workflows.py +0 -0
  82. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/tests/test_events.py +0 -0
  83. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/tests/test_frontmatter.py +0 -0
  84. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/tests/test_log_cli.py +0 -0
  85. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/tests/test_loose_visibility.py +0 -0
  86. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/tests/test_mcp_server.py +0 -0
  87. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/tests/test_mcp_structure.py +0 -0
  88. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/tests/test_mcp_surface.py +0 -0
  89. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/tests/test_move_batch.py +0 -0
  90. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/tests/test_naming_and_validate_kb.py +0 -0
  91. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/tests/test_notes.py +0 -0
  92. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/tests/test_operations.py +0 -0
  93. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/tests/test_oplog.py +0 -0
  94. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/tests/test_output_channels.py +0 -0
  95. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/tests/test_patches.py +0 -0
  96. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/tests/test_path_safety_and_locks.py +0 -0
  97. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/tests/test_paths_and_digest_guards.py +0 -0
  98. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/tests/test_plan.py +0 -0
  99. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/tests/test_references.py +0 -0
  100. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/tests/test_research.py +0 -0
  101. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/tests/test_stale.py +0 -0
  102. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/tests/test_storage.py +0 -0
  103. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/tests/test_structure.py +0 -0
  104. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/tests/test_summary_quality.py +0 -0
  105. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/tests/test_work_reporting.py +0 -0
  106. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/tests/test_write_guards.py +0 -0
  107. {knowledgevault-0.17.1 → knowledgevault-0.17.4}/tests/test_write_integrity.py +0 -0
@@ -1,3 +1,4 @@
1
1
  global-exclude *.py[cod]
2
+ include docs/reviewing-changes.md
2
3
  global-exclude __pycache__
3
4
  prune kvault/templates/__pycache__
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: knowledgevault
3
- Version: 0.17.1
3
+ Version: 0.17.4
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
@@ -72,6 +72,8 @@ sessions — contacts, projects, meeting notes, research — in a structured, na
72
72
  kvault needs no API keys, no hosted service, no database: any agent that can run shell
73
73
  commands can use it.
74
74
 
75
+ A Git-backed vault can report new and corrected captures since a previous review. [Review committed changes](https://github.com/cimo-labs/kvault/blob/main/docs/reviewing-changes.md)
76
+
75
77
  ## How it works
76
78
 
77
79
  - **A node is a directory** containing a single `_summary.md` — YAML frontmatter plus
@@ -160,6 +162,17 @@ summary unwritten (the batch reports it in `errors` and continues). `kvault writ
160
162
  --patches` edits one node the same way. `update-summaries`
161
163
  rewrites only summaries that exist, and an item's `meta` merges onto the frontmatter.
162
164
 
165
+ To edit a large note, `kvault source <path> --max-bytes 16000` returns a page of its
166
+ stored Markdown, including frontmatter, and the SHA-256 of the complete file.
167
+ Continue with `--offset` set to `next_offset` and `--expected-sha256` set to that
168
+ digest. Pass the same digest to `kvault write <path> --patches --expected-sha256
169
+ <digest> --compact` to check the revision while holding the vault write lock.
170
+ For ancestor edits, put `expected_sha256` on each update item. The batch checks all
171
+ supplied revisions before writing. A stale revision calls for a fresh read. Other
172
+ per-item errors still appear in the ordinary batch receipt. The stock MCP equivalents
173
+ are `kvault_read_node(source=true)`, `kvault_write_node` and `kvault_update_summaries`.
174
+ Patch anchors use the parsed Markdown body, with line endings normalized to LF.
175
+
163
176
  In human mode the same write narrates its decisions under the receipt:
164
177
 
165
178
  ```text
@@ -35,6 +35,8 @@ sessions — contacts, projects, meeting notes, research — in a structured, na
35
35
  kvault needs no API keys, no hosted service, no database: any agent that can run shell
36
36
  commands can use it.
37
37
 
38
+ A Git-backed vault can report new and corrected captures since a previous review. [Review committed changes](https://github.com/cimo-labs/kvault/blob/main/docs/reviewing-changes.md)
39
+
38
40
  ## How it works
39
41
 
40
42
  - **A node is a directory** containing a single `_summary.md` — YAML frontmatter plus
@@ -123,6 +125,17 @@ summary unwritten (the batch reports it in `errors` and continues). `kvault writ
123
125
  --patches` edits one node the same way. `update-summaries`
124
126
  rewrites only summaries that exist, and an item's `meta` merges onto the frontmatter.
125
127
 
128
+ To edit a large note, `kvault source <path> --max-bytes 16000` returns a page of its
129
+ stored Markdown, including frontmatter, and the SHA-256 of the complete file.
130
+ Continue with `--offset` set to `next_offset` and `--expected-sha256` set to that
131
+ digest. Pass the same digest to `kvault write <path> --patches --expected-sha256
132
+ <digest> --compact` to check the revision while holding the vault write lock.
133
+ For ancestor edits, put `expected_sha256` on each update item. The batch checks all
134
+ supplied revisions before writing. A stale revision calls for a fresh read. Other
135
+ per-item errors still appear in the ordinary batch receipt. The stock MCP equivalents
136
+ are `kvault_read_node(source=true)`, `kvault_write_node` and `kvault_update_summaries`.
137
+ Patch anchors use the parsed Markdown body, with line endings normalized to LF.
138
+
126
139
  In human mode the same write narrates its decisions under the receipt:
127
140
 
128
141
  ```text
@@ -0,0 +1,21 @@
1
+ # Review captures that arrived since a commit
2
+
3
+ A supplier can send a drawing on Monday and the importer can file it on Thursday. To follow an open question across imports, save the committed revision at the end of each review. This works with a local Git checkout, including a vault stored in a subdirectory of a larger repository.
4
+
5
+ ```sh
6
+ kvault --json events checkpoint
7
+ kvault --json events changes --after-commit "$previous_commit" \
8
+ --match 'Q-71' --match 'pad dimensions' --passage-chars 650
9
+ ```
10
+
11
+ Use the full commit ID from a successful checkpoint. Each phrase must occur in the same capture. Add `--together` to require all phrases within one bounded passage. Without it, `match_outside_passage` lists the zero-based positions of query phrases matched elsewhere in the source. A passage can mention two orders, or quote a previous email. Check whether the evidence actually attributes the update to the requested order. Matching is case-insensitive and allows whitespace across line breaks. A hyphenated part number containing a digit matches as a whole identifier. For example, Q-71 and Q-71-B are distinct. Phrase matching covers the entire saved body, including any quoted correspondence. Open the complete capture with `kvault --json events show ID` to check who said what, about which item and when.
12
+
13
+ Without `--match`, the result lists added, updated and removed event IDs and their Git blob IDs. This is the net difference between two snapshots. If a capture was added and removed between those endpoints, it has no net difference. A file with a different month and identical ID and blob represents the same capture. Use adjacent commits to inspect every recorded transition. Uncommitted captures appear after the next commit.
14
+
15
+ With `--match`, each result provides a passage from the current eligible capture version, with offsets into the decoded body returned by `events show`, and a SHA-256 digest of its UTF-8 bytes. A new or corrected attribution can also produce a match. Filing an existing capture into a node does not by itself introduce new source text. Quotes refer to text stored by the importer, which may be a human message or a summary. The capture date, source date, and date of admission to the vault can differ.
16
+
17
+ Pending captures and captures filed as promoted or journal-only are eligible. Removed, retracted, rejected, duplicate and no-op captures are withheld from passage results. A change to the body or its source metadata, a local edit or an unreadable record also prevents quoting the older version. If only the filing disposition changed, the response can still quote the historical capture and reports its current disposition when it differs. The reader checks the currently materialized file before returning a passage, including Git checkout conversions. Read `matched_source_exclusions`, `skipped` and `complete` before interpreting an empty result. A new field can still arrive through a different source, and matching text alone does not establish that a condition has been fulfilled.
18
+
19
+ The default JSON document fits 4,000 bytes. If a passage cannot fit, its pointer carries `passage_omitted`. Increase the byte budget or open the source. To continue a page, pass the original `through_commit`, the returned `next_offset`, and the same query. With phrases, also pass `match_sha256` as `--expected-match-sha256`. If the available matches change between pages, start again at offset zero. Matched pages recheck the whole interval for source changes. For broad backfills, use a larger page and byte budget. Small, frequent review intervals reduce scanning. An interrupted or incomplete review keeps its previous checkpoint for retry. After a complete review, persist the returned `through_commit` as the next starting point.
20
+
21
+ The stock MCP tool exposes the same results through `kvault_events` with `action="checkpoint"` or `action="changes"`. `after_commit`, `through_commit`, `match`, `together`, `limit`, `offset`, `passage_chars`, `max_bytes` and `expected_match_sha256` correspond to the CLI options. The caller owns its checkpoint so independent reviews can proceed at different rates.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: knowledgevault
3
- Version: 0.17.1
3
+ Version: 0.17.4
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
@@ -72,6 +72,8 @@ sessions — contacts, projects, meeting notes, research — in a structured, na
72
72
  kvault needs no API keys, no hosted service, no database: any agent that can run shell
73
73
  commands can use it.
74
74
 
75
+ A Git-backed vault can report new and corrected captures since a previous review. [Review committed changes](https://github.com/cimo-labs/kvault/blob/main/docs/reviewing-changes.md)
76
+
75
77
  ## How it works
76
78
 
77
79
  - **A node is a directory** containing a single `_summary.md` — YAML frontmatter plus
@@ -160,6 +162,17 @@ summary unwritten (the batch reports it in `errors` and continues). `kvault writ
160
162
  --patches` edits one node the same way. `update-summaries`
161
163
  rewrites only summaries that exist, and an item's `meta` merges onto the frontmatter.
162
164
 
165
+ To edit a large note, `kvault source <path> --max-bytes 16000` returns a page of its
166
+ stored Markdown, including frontmatter, and the SHA-256 of the complete file.
167
+ Continue with `--offset` set to `next_offset` and `--expected-sha256` set to that
168
+ digest. Pass the same digest to `kvault write <path> --patches --expected-sha256
169
+ <digest> --compact` to check the revision while holding the vault write lock.
170
+ For ancestor edits, put `expected_sha256` on each update item. The batch checks all
171
+ supplied revisions before writing. A stale revision calls for a fresh read. Other
172
+ per-item errors still appear in the ordinary batch receipt. The stock MCP equivalents
173
+ are `kvault_read_node(source=true)`, `kvault_write_node` and `kvault_update_summaries`.
174
+ Patch anchors use the parsed Markdown body, with line endings normalized to LF.
175
+
163
176
  In human mode the same write narrates its decisions under the receipt:
164
177
 
165
178
  ```text
@@ -2,6 +2,7 @@ LICENSE
2
2
  MANIFEST.in
3
3
  README.md
4
4
  pyproject.toml
5
+ docs/reviewing-changes.md
5
6
  knowledgevault.egg-info/PKG-INFO
6
7
  knowledgevault.egg-info/SOURCES.txt
7
8
  knowledgevault.egg-info/dependency_links.txt
@@ -25,13 +26,17 @@ kvault/cli/search.py
25
26
  kvault/cli/summary.py
26
27
  kvault/cli/validate.py
27
28
  kvault/core/__init__.py
29
+ kvault/core/_changed_passages.py
28
30
  kvault/core/check.py
29
31
  kvault/core/conventions.py
30
32
  kvault/core/daily_artifacts.py
31
33
  kvault/core/decisions.py
32
34
  kvault/core/duplicates.py
35
+ kvault/core/event_changes.py
33
36
  kvault/core/events.py
34
37
  kvault/core/frontmatter.py
38
+ kvault/core/json_pages.py
39
+ kvault/core/literal_reference.py
35
40
  kvault/core/locks.py
36
41
  kvault/core/notes.py
37
42
  kvault/core/observability.py
@@ -65,8 +70,10 @@ tests/test_daily_artifacts.py
65
70
  tests/test_decisions.py
66
71
  tests/test_duplicates.py
67
72
  tests/test_e2e_workflows.py
73
+ tests/test_event_changes.py
68
74
  tests/test_events.py
69
75
  tests/test_frontmatter.py
76
+ tests/test_guarded_source_edits.py
70
77
  tests/test_log_cli.py
71
78
  tests/test_loose_visibility.py
72
79
  tests/test_mcp_server.py
@@ -85,10 +92,12 @@ tests/test_plan.py
85
92
  tests/test_references.py
86
93
  tests/test_research.py
87
94
  tests/test_search_precision.py
95
+ tests/test_source_pages.py
88
96
  tests/test_stale.py
89
97
  tests/test_storage.py
90
98
  tests/test_structure.py
91
99
  tests/test_summary_quality.py
92
100
  tests/test_work_reporting.py
93
101
  tests/test_write_guards.py
94
- tests/test_write_integrity.py
102
+ tests/test_write_integrity.py
103
+ tests/test_write_lock_ownership.py
@@ -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.4"
17
17
 
18
18
  __all__ = ["__version__"]
@@ -21,6 +21,7 @@ from kvault.cli._helpers import (
21
21
  verbosity_options,
22
22
  )
23
23
  from kvault.cli.render import render_notes
24
+ from kvault.core.json_pages import DEFAULT_BYTES
24
25
  from kvault.core import operations as ops
25
26
 
26
27
 
@@ -134,9 +135,49 @@ def read_entity(
134
135
  click.echo(result.get("content", ""))
135
136
 
136
137
 
138
+ @click.command("source")
139
+ @click.argument("path")
140
+ @click.option(
141
+ "--offset",
142
+ type=int,
143
+ default=0,
144
+ show_default=True,
145
+ help="Unicode character offset in the raw Markdown.",
146
+ )
147
+ @click.option("--max-bytes", type=int, default=DEFAULT_BYTES, show_default=True)
148
+ @click.option(
149
+ "--expected-sha256", help="The exact file revision returned by the first source page."
150
+ )
151
+ @common_options
152
+ @click.pass_context
153
+ def read_source(
154
+ ctx: click.Context,
155
+ path: str,
156
+ offset: int,
157
+ max_bytes: int,
158
+ expected_sha256: Optional[str],
159
+ kb_root: Optional[Path],
160
+ as_json: bool,
161
+ ) -> None:
162
+ """Read stored frontmatter and body in bounded, revision-checked JSON pages."""
163
+ apply_common_options(ctx, kb_root=kb_root, as_json=as_json)
164
+ result = ops.read_source_page(
165
+ resolve_kb_root(ctx),
166
+ path,
167
+ offset=offset,
168
+ max_bytes=max_bytes,
169
+ expected_sha256=expected_sha256,
170
+ )
171
+ output_json(result)
172
+ if not result["success"]:
173
+ ctx.exit(1)
174
+
175
+
137
176
  @click.command("write")
138
177
  @click.argument("path")
139
178
  @click.option("--create", is_flag=True, help="Create new entity (fail if exists)")
179
+ @click.option("--expected-sha256", help="Require the exact stored Markdown revision from source")
180
+ @click.option("--compact", is_flag=True, help="Omit ancestor documents; keep paths and decisions")
140
181
  @click.option("--reasoning", default=None, help="Reasoning for auto-journal logging")
141
182
  @click.option("--journal-source", default=None, help="Override source for journal entry")
142
183
  @click.option(
@@ -170,6 +211,8 @@ def write_entity(
170
211
  ctx: click.Context,
171
212
  path: str,
172
213
  create: bool,
214
+ expected_sha256: Optional[str],
215
+ compact: bool,
173
216
  reasoning: Optional[str],
174
217
  journal_source: Optional[str],
175
218
  event_ids: tuple,
@@ -219,10 +262,15 @@ def write_entity(
219
262
  new_root=new_root,
220
263
  allow_similar=allow_similar,
221
264
  patches=patches,
265
+ expected_sha256=expected_sha256,
222
266
  )
223
267
  record_op(kb_root, "write", result, started)
224
- if ctx.obj.get("as_json"):
268
+ if compact:
269
+ result.pop("ancestors", None)
270
+ if compact or ctx.obj.get("as_json"):
225
271
  output_json(result)
272
+ if not result.get("success") and (compact or expected_sha256 is not None):
273
+ ctx.exit(1)
226
274
  else:
227
275
  if result.get("success"):
228
276
  if result.get("created"):
@@ -87,6 +87,105 @@ def events_group() -> None:
87
87
  """Inspect and resolve captured events."""
88
88
 
89
89
 
90
+ @events_group.command("checkpoint")
91
+ @common_options
92
+ @click.pass_context
93
+ def event_checkpoint_cmd(ctx: click.Context, kb_root: Optional[Path], as_json: bool) -> None:
94
+ """Get the current committed revision for the next journal review."""
95
+ from kvault.core.event_changes import event_checkpoint
96
+
97
+ apply_common_options(ctx, kb_root=kb_root, as_json=as_json)
98
+ result = event_checkpoint(resolve_kb_root(ctx))
99
+ if ctx.obj.get("as_json"):
100
+ output_json(result)
101
+ if not result["success"]:
102
+ ctx.exit(1)
103
+ elif result["success"]:
104
+ click.echo(result["commit"])
105
+ else:
106
+ raise click.ClickException(result["error"])
107
+
108
+
109
+ @events_group.command("changes")
110
+ @click.option("--after-commit", required=True, help="Full Git commit ID of the last review")
111
+ @click.option("--through-commit", help="Full commit ID to review through (default: checkout HEAD)")
112
+ @click.option("--expected-match-sha256", help="The match_sha256 returned by the preceding page")
113
+ @click.option(
114
+ "--match",
115
+ multiple=True,
116
+ help="Require this literal word or phrase in new evidence (repeatable)",
117
+ )
118
+ @click.option(
119
+ "--together", is_flag=True, help="Match only when all phrases fit in a single passage"
120
+ )
121
+ @click.option("--passage-chars", type=click.IntRange(80, 2400), default=360, show_default=True)
122
+ @click.option("--max-bytes", type=click.IntRange(1024, 128000), default=4000, show_default=True)
123
+ @click.option("--limit", type=click.IntRange(1, 50), default=10, show_default=True)
124
+ @click.option("--offset", type=click.IntRange(0), default=0, show_default=True)
125
+ @common_options
126
+ @click.pass_context
127
+ def event_changes_cmd(
128
+ ctx: click.Context,
129
+ after_commit: str,
130
+ through_commit: Optional[str],
131
+ expected_match_sha256: Optional[str],
132
+ match: Tuple[str, ...],
133
+ together: bool,
134
+ passage_chars: int,
135
+ max_bytes: int,
136
+ limit: int,
137
+ offset: int,
138
+ kb_root: Optional[Path],
139
+ as_json: bool,
140
+ ) -> None:
141
+ """List captures added, updated or removed between two committed snapshots."""
142
+ from kvault.core.event_changes import event_changes
143
+
144
+ apply_common_options(ctx, kb_root=kb_root, as_json=as_json)
145
+ result = event_changes(
146
+ resolve_kb_root(ctx),
147
+ after_commit,
148
+ through_commit=through_commit,
149
+ expected_match_sha256=expected_match_sha256,
150
+ match=list(match),
151
+ together=together,
152
+ passage_chars=passage_chars,
153
+ max_bytes=max_bytes,
154
+ limit=limit,
155
+ offset=offset,
156
+ )
157
+ if ctx.obj.get("as_json"):
158
+ output_json(result)
159
+ if not result["success"]:
160
+ ctx.exit(1)
161
+ elif not result["success"]:
162
+ raise click.ClickException(result["error"])
163
+ else:
164
+ click.echo(f"{result['total_changes']} changed captures through {result['through_commit']}")
165
+ if "total_matches" in result:
166
+ click.echo(f"{result['total_matches']} matching sources")
167
+ for row in result["changes"]:
168
+ click.echo(f" {row['change']:7} {row['event_id']}")
169
+ if row.get("passage"):
170
+ left = "… " if row["start"] else ""
171
+ right = " …" if row["end"] < row["body_chars"] else ""
172
+ click.echo(f" {left}{row['passage']}{right}")
173
+ if row.get("match_outside_passage"):
174
+ omitted = ", ".join(str(i + 1) for i in row["match_outside_passage"])
175
+ click.echo(f" Query phrases outside this passage: {omitted}")
176
+ if row.get("passage_omitted"):
177
+ click.echo(f" Passage omitted ({row['passage_omitted']})")
178
+ if result["next_offset"] is not None:
179
+ flags = f"--through-commit {result['through_commit']} --offset {result['next_offset']}"
180
+ if "match_sha256" in result:
181
+ flags += f" --expected-match-sha256 {result['match_sha256']}"
182
+ click.echo(f"Continue the same query with {flags}")
183
+ if not result["complete"]:
184
+ click.echo(f"Some archive entries were unavailable: {result['skipped']}")
185
+ if result.get("matched_source_exclusions"):
186
+ click.echo(f"Source exclusions: {result['matched_source_exclusions']}")
187
+
188
+
90
189
  @events_group.command("list")
91
190
  @click.option(
92
191
  "--status",
@@ -14,6 +14,7 @@ from kvault.cli.plan import plan
14
14
  from kvault.cli.doctor import doctor
15
15
  from kvault.cli.entity import (
16
16
  read_entity,
17
+ read_source,
17
18
  write_entity,
18
19
  list_entities,
19
20
  delete_entity,
@@ -89,6 +90,7 @@ cli.add_command(check_kb)
89
90
  cli.add_command(plan)
90
91
  cli.add_command(doctor)
91
92
  cli.add_command(read_entity)
93
+ cli.add_command(read_source)
92
94
  cli.add_command(write_entity)
93
95
  cli.add_command(list_entities, "list")
94
96
  cli.add_command(search_nodes)
@@ -105,6 +107,29 @@ cli.add_command(capture)
105
107
  cli.add_command(events_group)
106
108
 
107
109
 
110
+ @cli.command("capabilities")
111
+ @common_options
112
+ @click.pass_context
113
+ def capabilities(ctx: click.Context, kb_root: Optional[Path], as_json: bool) -> None:
114
+ """List optional CLI features. Works outside a vault without reading its files."""
115
+ apply_common_options(ctx, kb_root=kb_root, as_json=as_json)
116
+ features = (
117
+ "events.checkpoint",
118
+ "events.changes",
119
+ "events.changes.together",
120
+ "read.source",
121
+ "write.compact",
122
+ "write.expected_sha256",
123
+ "write.patches",
124
+ "update-summaries.expected_sha256",
125
+ "update-summaries.patches",
126
+ )
127
+ if ctx.obj.get("as_json"):
128
+ output_json({"version": __version__, "features": features})
129
+ else:
130
+ click.echo("\n".join(features))
131
+
132
+
108
133
  @cli.command("init")
109
134
  @click.argument("path", type=click.Path(path_type=Path), default=".")
110
135
  @click.option("--name", default="My", help="Owner name for the knowledge base")
@@ -117,6 +117,10 @@ def update_summaries(
117
117
  record_op(kb_root, "update-summaries", result, started)
118
118
  if ctx.obj.get("as_json"):
119
119
  output_json(result)
120
+ if not result.get("success") and any(
121
+ isinstance(item, dict) and "expected_sha256" in item for item in updates
122
+ ):
123
+ ctx.exit(1)
120
124
  else:
121
125
  if result.get("success"):
122
126
  click.echo(
@@ -125,9 +129,8 @@ def update_summaries(
125
129
  render_notes(result, get_tier(ctx))
126
130
  else:
127
131
  failures = "; ".join(f"{e['path']}: {e['error']}" for e in result.get("errors", []))
128
- raise click.ClickException(
129
- f"Update failed: {failures}" if failures else "Update failed"
130
- )
132
+ detail = failures or result.get("error")
133
+ raise click.ClickException(f"Update failed: {detail}" if detail else "Update failed")
131
134
  if result.get("errors"):
132
135
  for err in result["errors"]:
133
136
  click.echo(f" Error: {err['path']}: {err['error']}", err=True)