witan-code 0.28.0__tar.gz → 0.29.0__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 (111) hide show
  1. {witan_code-0.28.0 → witan_code-0.29.0}/CHANGELOG.md +45 -0
  2. {witan_code-0.28.0 → witan_code-0.29.0}/PKG-INFO +20 -8
  3. {witan_code-0.28.0 → witan_code-0.29.0}/README.md +18 -6
  4. {witan_code-0.28.0 → witan_code-0.29.0}/pyproject.toml +10 -3
  5. {witan_code-0.28.0 → witan_code-0.29.0}/tests/test_chunked_load.py +82 -0
  6. witan_code-0.29.0/tests/test_cli_help_docstrings.py +9 -0
  7. {witan_code-0.28.0 → witan_code-0.29.0}/tests/test_elicit.py +40 -0
  8. {witan_code-0.28.0 → witan_code-0.29.0}/tests/test_hooks.py +33 -0
  9. {witan_code-0.28.0 → witan_code-0.29.0}/tests/test_indexer_scope.py +232 -6
  10. {witan_code-0.28.0 → witan_code-0.29.0}/tests/test_repo.py +66 -0
  11. {witan_code-0.28.0 → witan_code-0.29.0}/tests/test_store.py +9 -6
  12. {witan_code-0.28.0 → witan_code-0.29.0}/witan_code/bridge_extractors.py +8 -2
  13. {witan_code-0.28.0 → witan_code-0.29.0}/witan_code/cli.py +18 -9
  14. {witan_code-0.28.0 → witan_code-0.29.0}/witan_code/hooks.py +5 -3
  15. {witan_code-0.28.0 → witan_code-0.29.0}/witan_code/indexer.py +112 -15
  16. {witan_code-0.28.0 → witan_code-0.29.0}/witan_code/repo.py +122 -0
  17. {witan_code-0.28.0 → witan_code-0.29.0}/witan_code/server.py +23 -3
  18. {witan_code-0.28.0 → witan_code-0.29.0}/.gitignore +0 -0
  19. {witan_code-0.28.0 → witan_code-0.29.0}/changelog.d/README.md +0 -0
  20. {witan_code-0.28.0 → witan_code-0.29.0}/config/claude.json +0 -0
  21. {witan_code-0.28.0 → witan_code-0.29.0}/config/copilot.json +0 -0
  22. {witan_code-0.28.0 → witan_code-0.29.0}/config/pi.json +0 -0
  23. {witan_code-0.28.0 → witan_code-0.29.0}/conftest.py +0 -0
  24. {witan_code-0.28.0 → witan_code-0.29.0}/docs/BRANCH_INDEXING.md +0 -0
  25. {witan_code-0.28.0 → witan_code-0.29.0}/docs/CLI_REFERENCE.md +0 -0
  26. {witan_code-0.28.0 → witan_code-0.29.0}/docs/EDGE_PRECISION_TIERS.md +0 -0
  27. {witan_code-0.28.0 → witan_code-0.29.0}/docs/PACKAGE_MAP.md +0 -0
  28. {witan_code-0.28.0 → witan_code-0.29.0}/docs/STAGE2_STITCHING.md +0 -0
  29. {witan_code-0.28.0 → witan_code-0.29.0}/docs/SYMBOL_FORMAT.md +0 -0
  30. {witan_code-0.28.0 → witan_code-0.29.0}/docs/SYMBOL_TABLE.md +0 -0
  31. {witan_code-0.28.0 → witan_code-0.29.0}/docs/USER_GUIDE.md +0 -0
  32. {witan_code-0.28.0 → witan_code-0.29.0}/install.sh +0 -0
  33. {witan_code-0.28.0 → witan_code-0.29.0}/tests/__init__.py +0 -0
  34. {witan_code-0.28.0 → witan_code-0.29.0}/tests/conftest.py +0 -0
  35. {witan_code-0.28.0 → witan_code-0.29.0}/tests/test_batched_deletes.py +0 -0
  36. {witan_code-0.28.0 → witan_code-0.29.0}/tests/test_branches.py +0 -0
  37. {witan_code-0.28.0 → witan_code-0.29.0}/tests/test_branches_served.py +0 -0
  38. {witan_code-0.28.0 → witan_code-0.29.0}/tests/test_bridge.py +0 -0
  39. {witan_code-0.28.0 → witan_code-0.29.0}/tests/test_cli_dispatch.py +0 -0
  40. {witan_code-0.28.0 → witan_code-0.29.0}/tests/test_cli_hooks.py +0 -0
  41. {witan_code-0.28.0 → witan_code-0.29.0}/tests/test_cli_output_format.py +0 -0
  42. {witan_code-0.28.0 → witan_code-0.29.0}/tests/test_cli_selected_target.py +0 -0
  43. {witan_code-0.28.0 → witan_code-0.29.0}/tests/test_config.py +0 -0
  44. {witan_code-0.28.0 → witan_code-0.29.0}/tests/test_config_targets.py +0 -0
  45. {witan_code-0.28.0 → witan_code-0.29.0}/tests/test_context.py +0 -0
  46. {witan_code-0.28.0 → witan_code-0.29.0}/tests/test_crossrepo.py +0 -0
  47. {witan_code-0.28.0 → witan_code-0.29.0}/tests/test_edges.py +0 -0
  48. {witan_code-0.28.0 → witan_code-0.29.0}/tests/test_enrichment.py +0 -0
  49. {witan_code-0.28.0 → witan_code-0.29.0}/tests/test_github_app.py +0 -0
  50. {witan_code-0.28.0 → witan_code-0.29.0}/tests/test_graph.py +0 -0
  51. {witan_code-0.28.0 → witan_code-0.29.0}/tests/test_identity.py +0 -0
  52. {witan_code-0.28.0 → witan_code-0.29.0}/tests/test_index_failure_diagnostics.py +0 -0
  53. {witan_code-0.28.0 → witan_code-0.29.0}/tests/test_index_reports_its_store.py +0 -0
  54. {witan_code-0.28.0 → witan_code-0.29.0}/tests/test_index_requires_a_repo_key.py +0 -0
  55. {witan_code-0.28.0 → witan_code-0.29.0}/tests/test_indexer.py +0 -0
  56. {witan_code-0.28.0 → witan_code-0.29.0}/tests/test_ingest.py +0 -0
  57. {witan_code-0.28.0 → witan_code-0.29.0}/tests/test_languages.py +0 -0
  58. {witan_code-0.28.0 → witan_code-0.29.0}/tests/test_maintenance.py +0 -0
  59. {witan_code-0.28.0 → witan_code-0.29.0}/tests/test_package_map.py +0 -0
  60. {witan_code-0.28.0 → witan_code-0.29.0}/tests/test_reaper.py +0 -0
  61. {witan_code-0.28.0 → witan_code-0.29.0}/tests/test_rebuild_honours_the_repo_key.py +0 -0
  62. {witan_code-0.28.0 → witan_code-0.29.0}/tests/test_refusal_audit.py +0 -0
  63. {witan_code-0.28.0 → witan_code-0.29.0}/tests/test_remote_proxy.py +0 -0
  64. {witan_code-0.28.0 → witan_code-0.29.0}/tests/test_remote_store.py +0 -0
  65. {witan_code-0.28.0 → witan_code-0.29.0}/tests/test_server.py +0 -0
  66. {witan_code-0.28.0 → witan_code-0.29.0}/tests/test_setup.py +0 -0
  67. {witan_code-0.28.0 → witan_code-0.29.0}/tests/test_stitch.py +0 -0
  68. {witan_code-0.28.0 → witan_code-0.29.0}/tests/test_symbol_table.py +0 -0
  69. {witan_code-0.28.0 → witan_code-0.29.0}/tests/test_tasks.py +0 -0
  70. {witan_code-0.28.0 → witan_code-0.29.0}/tests/test_tool_schema.py +0 -0
  71. {witan_code-0.28.0 → witan_code-0.29.0}/tests/test_views.py +0 -0
  72. {witan_code-0.28.0 → witan_code-0.29.0}/tests/test_visualize.py +0 -0
  73. {witan_code-0.28.0 → witan_code-0.29.0}/witan_code/__init__.py +0 -0
  74. {witan_code-0.28.0 → witan_code-0.29.0}/witan_code/__main__.py +0 -0
  75. {witan_code-0.28.0 → witan_code-0.29.0}/witan_code/bridge.py +0 -0
  76. {witan_code-0.28.0 → witan_code-0.29.0}/witan_code/config.py +0 -0
  77. {witan_code-0.28.0 → witan_code-0.29.0}/witan_code/context.py +0 -0
  78. {witan_code-0.28.0 → witan_code-0.29.0}/witan_code/edges.py +0 -0
  79. {witan_code-0.28.0 → witan_code-0.29.0}/witan_code/elicit.py +0 -0
  80. {witan_code-0.28.0 → witan_code-0.29.0}/witan_code/extensions/pi/codegraph.ts +0 -0
  81. {witan_code-0.28.0 → witan_code-0.29.0}/witan_code/github_app.py +0 -0
  82. {witan_code-0.28.0 → witan_code-0.29.0}/witan_code/graph.py +0 -0
  83. {witan_code-0.28.0 → witan_code-0.29.0}/witan_code/identity.py +0 -0
  84. {witan_code-0.28.0 → witan_code-0.29.0}/witan_code/ingest.py +0 -0
  85. {witan_code-0.28.0 → witan_code-0.29.0}/witan_code/maintenance.py +0 -0
  86. {witan_code-0.28.0 → witan_code-0.29.0}/witan_code/output.py +0 -0
  87. {witan_code-0.28.0 → witan_code-0.29.0}/witan_code/package_map.py +0 -0
  88. {witan_code-0.28.0 → witan_code-0.29.0}/witan_code/queries/bridge.gq +0 -0
  89. {witan_code-0.28.0 → witan_code-0.29.0}/witan_code/queries/code_mutations.gq +0 -0
  90. {witan_code-0.28.0 → witan_code-0.29.0}/witan_code/queries/code_read.gq +0 -0
  91. {witan_code-0.28.0 → witan_code-0.29.0}/witan_code/queries/delete.gq +0 -0
  92. {witan_code-0.28.0 → witan_code-0.29.0}/witan_code/queries_ts/bash.scm +0 -0
  93. {witan_code-0.28.0 → witan_code-0.29.0}/witan_code/queries_ts/hcl.scm +0 -0
  94. {witan_code-0.28.0 → witan_code-0.29.0}/witan_code/queries_ts/python.scm +0 -0
  95. {witan_code-0.28.0 → witan_code-0.29.0}/witan_code/queries_ts/sql.scm +0 -0
  96. {witan_code-0.28.0 → witan_code-0.29.0}/witan_code/queries_ts/typescript.scm +0 -0
  97. {witan_code-0.28.0 → witan_code-0.29.0}/witan_code/queries_ts/yaml.scm +0 -0
  98. {witan_code-0.28.0 → witan_code-0.29.0}/witan_code/reaper.py +0 -0
  99. {witan_code-0.28.0 → witan_code-0.29.0}/witan_code/remote/__init__.py +0 -0
  100. {witan_code-0.28.0 → witan_code-0.29.0}/witan_code/remote/oidc.py +0 -0
  101. {witan_code-0.28.0 → witan_code-0.29.0}/witan_code/remote/proxy.py +0 -0
  102. {witan_code-0.28.0 → witan_code-0.29.0}/witan_code/remote/store.py +0 -0
  103. {witan_code-0.28.0 → witan_code-0.29.0}/witan_code/schema/bridge-schema.pg +0 -0
  104. {witan_code-0.28.0 → witan_code-0.29.0}/witan_code/schema/code-schema.pg +0 -0
  105. {witan_code-0.28.0 → witan_code-0.29.0}/witan_code/selected_target.py +0 -0
  106. {witan_code-0.28.0 → witan_code-0.29.0}/witan_code/setup.py +0 -0
  107. {witan_code-0.28.0 → witan_code-0.29.0}/witan_code/skills/witan-code/SKILL.md +0 -0
  108. {witan_code-0.28.0 → witan_code-0.29.0}/witan_code/stitch.py +0 -0
  109. {witan_code-0.28.0 → witan_code-0.29.0}/witan_code/store.py +0 -0
  110. {witan_code-0.28.0 → witan_code-0.29.0}/witan_code/views.py +0 -0
  111. {witan_code-0.28.0 → witan_code-0.29.0}/witan_code/visualize.py +0 -0
@@ -8,6 +8,51 @@ a MINOR bump may include breaking changes).
8
8
 
9
9
  <!-- scriv-insert-here -->
10
10
 
11
+ ## [0.29.0] - 2026-11-10
12
+
13
+ ### Changed
14
+
15
+ - With witan-core's packed `chunk_records`, an index whose records fit one
16
+ load batch sends its nodes and edges as one `code_store_load` instead of
17
+ two, so a paced PostToolUse flush to a deployed graph is three commits on
18
+ the branch view (delete, load, content-hash load) instead of four.
19
+ - Through an `OmnigraphClient` (a local store, omnigraph over HTTP, or an
20
+ in-cluster index), a load that fits one batch carries the files' content
21
+ hashes in the same commit instead of a second load, so the flush is two
22
+ commits. One batch commits atomically, so a failed load still leaves the
23
+ files without a hash and the next run re-indexes them. A
24
+ `RemoteStoreClient` keeps the content-hash load, because the store tier
25
+ re-chunks what it receives, and one running an older witan-core splits
26
+ nodes from edges into separate commits.
27
+ - Requires `witan-core>=0.51.1`, the release with the packed
28
+ `chunk_records`. 0.51.0 still works, but adds a commit per flush.
29
+
30
+ ### Fixed
31
+
32
+ - `--help` for `reap-views`, `setup` and the global options shows each
33
+ parameter's description. They were documented as `name: text` on one
34
+ line, which cyclopts' numpydoc parser reads as a parameter type.
35
+ - Indexing inside a git work tree collects git's listing (`git ls-files
36
+ --cached --others --exclude-standard`) instead of walking the disk, so
37
+ files git ignores no longer reach the code graph. The fixed skip list
38
+ only caught a virtualenv named `.venv` or `venv`: a dry estimate of
39
+ open-edx-plugins with `uv sync` into `env/` came to 703,408 records in
40
+ 108 2 MiB loads, against 14,661 records in 5 loads now. The skip list,
41
+ nested-checkout exclusion and extension filter still apply on top. The
42
+ PostToolUse hook holds the files it names to the same rule with one
43
+ `git check-ignore` per batch, and the repo-level bridge extractors read
44
+ the same listing. Outside a work tree, or without a `git` binary, the
45
+ disk is walked as before. A full-repo index purges rows already stored
46
+ for files that are now ignored, wherever the run is allowed to purge, and
47
+ an edit to an ignored file drops that file's existing rows. A repository
48
+ git cannot list (a corrupt index, dubious ownership) is reported and
49
+ indexes nothing rather than falling back to the walk, and a listed path
50
+ under a symlinked directory is skipped.
51
+
52
+ ### Security
53
+
54
+ - The "no code graph yet, index it now?" offer is no longer made to a token-authenticated remote caller. It indexed the server's own checkout, so a remote caller (including the web UI, whose token is limited to read tools) could turn a read such as `code_interface_consumers` into a write by accepting the prompt. A local stdio server still makes the offer.
55
+
11
56
  ## [0.28.0] - 2026-11-09
12
57
 
13
58
  ### Changed
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: witan-code
3
- Version: 0.28.0
3
+ Version: 0.29.0
4
4
  Summary: witan-code — tree-sitter code graph + cross-repo bridge (mounts under `witan code`)
5
5
  Project-URL: Homepage, https://github.com/mitodl/agent-kit/tree/main/mcp/servers/witan-code
6
6
  Project-URL: Repository, https://github.com/mitodl/agent-kit
@@ -26,7 +26,7 @@ Requires-Dist: tree-sitter-sql<0.4,>=0.3
26
26
  Requires-Dist: tree-sitter-typescript<0.24,>=0.23
27
27
  Requires-Dist: tree-sitter-yaml<0.8,>=0.7
28
28
  Requires-Dist: tree-sitter<0.26,>=0.25
29
- Requires-Dist: witan-core[cli,observability,remote,sentry]<1,>=0.51
29
+ Requires-Dist: witan-core[cli,observability,remote,sentry]<1,>=0.51.1
30
30
  Provides-Extra: tasks
31
31
  Requires-Dist: fastmcp-tasks<5,>=4; extra == 'tasks'
32
32
  Description-Content-Type: text/markdown
@@ -700,9 +700,9 @@ symlink or copy the directory into the equivalent path for your agent.
700
700
 
701
701
  ## Hooks
702
702
 
703
- Four hooks — all bare CLI commands, no wrapper scripts, so they're portable
704
- to any platform witan-code installs on (Windows included — no bash/setsid
705
- dependency). Named `witan-code <command>` below (standalone install via
703
+ Four hooks — all bare CLI commands, no wrapper scripts, so they need no
704
+ bash or setsid. They do not run on Windows yet: the hook commands' queue
705
+ lock and state directory still use POSIX-only calls. Named `witan-code <command>` below (standalone install via
706
706
  `witan-code setup`); when `witan setup` folds this bundle in instead (see
707
707
  [Install](#install)), they register as `witan code <command>` so only
708
708
  `witan` needs to be on `PATH`. Register manually per
@@ -757,14 +757,26 @@ scripts to symlink.
757
757
 
758
758
  ## What gets indexed
759
759
 
760
- The walk skips the usual noise directories (`.git`, `node_modules`, `.venv`,
761
- `__pycache__`, `dist`, `build`, the various caches) and — importantly — does
760
+ Inside a git work tree the file set is git's own listing (`git ls-files
761
+ --cached --others --exclude-standard`): tracked files plus untracked files
762
+ that are not ignored. Anything `.gitignore`, `.git/info/exclude` or your
763
+ `core.excludesFile` ignores stays out of the graph, including a virtualenv
764
+ under any name (uv and `python -m venv` write a `*` `.gitignore` into the
765
+ environment they create). The edit hooks apply the same rule: an edit to an
766
+ ignored file is not indexed. Outside a git work tree, or without a `git`
767
+ binary, the indexer walks the directory instead, and only the rules below
768
+ apply.
769
+
770
+ On top of either, the indexer skips the usual noise directories (`.git`,
771
+ `node_modules`, `.venv`, `__pycache__`, `dist`, `build`, the various caches),
772
+ even where git tracks them, and — importantly — does
762
773
  not descend into a **nested checkout**: any subdirectory containing a `.git`
763
774
  entry belongs to a different repository. That covers linked worktrees
764
775
  (`.claude/worktrees/<name>/`, where `.git` is a *file*, not a directory),
765
776
  submodules, and plain clones dropped inside the tree. Their files are that
766
777
  repo's; indexing them here would attribute them to this one and leave the
767
- store serving stale copies of itself under a second set of paths.
778
+ store serving stale copies of itself under a second set of paths. A
779
+ submodule's files belong in its own repo's graph, not this one's.
768
780
 
769
781
  Indexing *from inside* a worktree still works normally — only descending into
770
782
  one from the parent is refused — so the hooks keep indexing while an agent
@@ -667,9 +667,9 @@ symlink or copy the directory into the equivalent path for your agent.
667
667
 
668
668
  ## Hooks
669
669
 
670
- Four hooks — all bare CLI commands, no wrapper scripts, so they're portable
671
- to any platform witan-code installs on (Windows included — no bash/setsid
672
- dependency). Named `witan-code <command>` below (standalone install via
670
+ Four hooks — all bare CLI commands, no wrapper scripts, so they need no
671
+ bash or setsid. They do not run on Windows yet: the hook commands' queue
672
+ lock and state directory still use POSIX-only calls. Named `witan-code <command>` below (standalone install via
673
673
  `witan-code setup`); when `witan setup` folds this bundle in instead (see
674
674
  [Install](#install)), they register as `witan code <command>` so only
675
675
  `witan` needs to be on `PATH`. Register manually per
@@ -724,14 +724,26 @@ scripts to symlink.
724
724
 
725
725
  ## What gets indexed
726
726
 
727
- The walk skips the usual noise directories (`.git`, `node_modules`, `.venv`,
728
- `__pycache__`, `dist`, `build`, the various caches) and — importantly — does
727
+ Inside a git work tree the file set is git's own listing (`git ls-files
728
+ --cached --others --exclude-standard`): tracked files plus untracked files
729
+ that are not ignored. Anything `.gitignore`, `.git/info/exclude` or your
730
+ `core.excludesFile` ignores stays out of the graph, including a virtualenv
731
+ under any name (uv and `python -m venv` write a `*` `.gitignore` into the
732
+ environment they create). The edit hooks apply the same rule: an edit to an
733
+ ignored file is not indexed. Outside a git work tree, or without a `git`
734
+ binary, the indexer walks the directory instead, and only the rules below
735
+ apply.
736
+
737
+ On top of either, the indexer skips the usual noise directories (`.git`,
738
+ `node_modules`, `.venv`, `__pycache__`, `dist`, `build`, the various caches),
739
+ even where git tracks them, and — importantly — does
729
740
  not descend into a **nested checkout**: any subdirectory containing a `.git`
730
741
  entry belongs to a different repository. That covers linked worktrees
731
742
  (`.claude/worktrees/<name>/`, where `.git` is a *file*, not a directory),
732
743
  submodules, and plain clones dropped inside the tree. Their files are that
733
744
  repo's; indexing them here would attribute them to this one and leave the
734
- store serving stale copies of itself under a second set of paths.
745
+ store serving stale copies of itself under a second set of paths. A
746
+ submodule's files belong in its own repo's graph, not this one's.
735
747
 
736
748
  Indexing *from inside* a worktree still works normally — only descending into
737
749
  one from the parent is refused — so the hooks keep indexing while an agent
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "witan-code"
3
- version = "0.28.0"
3
+ version = "0.29.0"
4
4
  description = "witan-code — tree-sitter code graph + cross-repo bridge (mounts under `witan code`)"
5
5
  readme = "README.md"
6
6
  license = "BSD-3-Clause"
@@ -211,7 +211,14 @@ dependencies = [
211
211
  # passes `actor=` to witan-core's `OmnigraphClient`, a keyword added in
212
212
  # witan-core 0.51.0 in the same change (Omnigraph-If-Actor). 0.50 imports
213
213
  # fine, then a deployed ingest raises TypeError.
214
- "witan-core[cli,remote,observability,sentry]>=0.51,<1",
214
+ #
215
+ # ★ >=0.51.1 IS A BEHAVIOURAL FLOOR, like >=0.22: 0.51.1's
216
+ # `chunking.chunk_records` packs nodes and edges into shared batches, so an
217
+ # edit-hook flush that fits one batch is one load and one commit. 0.51.0
218
+ # imports and runs, but batches nodes and edges apart, so every flush adds
219
+ # a commit to the user's code branch. `_hashes_need_deferring` calls the
220
+ # same `chunk_records`, so 0.51.0 stays correct, only slower on the graph.
221
+ "witan-core[cli,remote,observability,sentry]>=0.51.1,<1",
215
222
  "fastmcp>=4,<5",
216
223
  "cyclopts>=4,<6",
217
224
  # [targets.<name>] override models (config.py) — also transitively pulled
@@ -294,7 +301,7 @@ testpaths = ["tests"]
294
301
  packages = ["witan_code"]
295
302
 
296
303
  [tool.bumpversion]
297
- current_version = "0.28.0"
304
+ current_version = "0.29.0"
298
305
  allow_dirty = true
299
306
 
300
307
  [[tool.bumpversion.files]]
@@ -112,6 +112,37 @@ def test_defer_swaps_in_a_sentinel_and_returns_the_real_rows():
112
112
  ]
113
113
 
114
114
 
115
+ def test_one_batch_through_omnigraph_needs_no_deferred_hashes(monkeypatch):
116
+ records = [_node("a"), _edge("Calls", "a", "b"), _node("b")]
117
+ client = object()
118
+ assert not indexer._hashes_need_deferring(client, records)
119
+
120
+ one_record = len(json.dumps(records[0]).encode()) + 1
121
+ monkeypatch.setattr(indexer, "_ONE_LOAD_MAX_BYTES", one_record)
122
+ assert indexer._hashes_need_deferring(client, records)
123
+
124
+
125
+ def test_the_one_load_budget_is_no_larger_than_omnigraph_clients_chunk_at():
126
+ """`_hashes_need_deferring` calls a load one commit when it fits this
127
+ budget, which holds only while the client splits at no less."""
128
+ import inspect
129
+
130
+ from witan_code.graph import OmnigraphClient
131
+
132
+ default = inspect.signature(OmnigraphClient.load).parameters["max_bytes"].default
133
+ assert default >= indexer._ONE_LOAD_MAX_BYTES
134
+
135
+
136
+ def test_a_remote_store_client_always_defers_hashes():
137
+ """The store tier re-chunks a received load, and an older one splits
138
+ nodes from edges, so one client-side batch is not one commit there."""
139
+ from witan_code.remote.store import RemoteStoreClient, StoreSession
140
+
141
+ session = StoreSession("http://x/mcp", lambda: "jwt", lambda _t: None)
142
+ client = RemoteStoreClient("https://github.com/x/y", session)
143
+ assert indexer._hashes_need_deferring(client, [_node("a")])
144
+
145
+
115
146
  def test_sentinel_can_never_collide_with_a_real_hash():
116
147
  """The skip check is `stored == sha256(file)`; the sentinel must never match."""
117
148
  digest = hashlib.sha256(b"anything").hexdigest()
@@ -169,6 +200,9 @@ def test_a_failed_load_leaves_the_file_reindexable(sample_repo, monkeypatch):
169
200
  from witan_code import config as cfg_mod
170
201
  from witan_code import graph as graph_mod
171
202
 
203
+ # The sample repo fits one batch, which loads hashes and all in one atomic
204
+ # commit; a budget of one byte puts it on the deferred two-load path.
205
+ monkeypatch.setattr(indexer, "_ONE_LOAD_MAX_BYTES", 1)
172
206
  real_load = graph_mod.OmnigraphClient.load
173
207
  calls = {"n": 0}
174
208
 
@@ -188,3 +222,51 @@ def test_a_failed_load_leaves_the_file_reindexable(sample_repo, monkeypatch):
188
222
  stats = indexer.index_path(sample_repo, config=cfg_mod.load())
189
223
  assert stats.indexed >= 1, "the file must be re-indexed, not skipped"
190
224
  assert stats.skipped == 0
225
+
226
+
227
+ @requires_stack
228
+ def test_a_load_that_fits_one_batch_commits_hashes_with_it(sample_repo, monkeypatch):
229
+ """No sentinel and no second load when the whole write is one batch: the
230
+ hash lands in the same atomic commit as the file's symbols and edges."""
231
+ from witan_code import config as cfg_mod
232
+ from witan_code import graph as graph_mod
233
+
234
+ real_load = graph_mod.OmnigraphClient.load
235
+ loaded: list[list[dict]] = []
236
+
237
+ def _recorded(self, records, mode="merge", **kwargs):
238
+ loaded.append(records)
239
+ return real_load(self, records, mode, **kwargs)
240
+
241
+ monkeypatch.setattr(graph_mod.OmnigraphClient, "load", _recorded)
242
+ indexer.index_path(sample_repo, config=cfg_mod.load())
243
+
244
+ code_loads = [r for r in loaded if any(x.get("type") == "CodeFile" for x in r)]
245
+ assert len(code_loads) == 1
246
+ hashes = [
247
+ x["data"]["content_hash"] for x in code_loads[0] if x.get("type") == "CodeFile"
248
+ ]
249
+ assert hashes and indexer._PENDING_CONTENT_HASH not in hashes
250
+
251
+
252
+ @requires_stack
253
+ def test_a_failed_single_load_leaves_the_file_reindexable(sample_repo, monkeypatch):
254
+ """The sentinel's guarantee holds without it when the load is one commit:
255
+ a failed load writes no CodeFile row, so there is no hash to skip on."""
256
+ from witan_code import config as cfg_mod
257
+ from witan_code import graph as graph_mod
258
+
259
+ real_load = graph_mod.OmnigraphClient.load
260
+
261
+ def _fail(self, records, mode="merge", **kwargs):
262
+ msg = "simulated load failure"
263
+ raise RuntimeError(msg)
264
+
265
+ monkeypatch.setattr(graph_mod.OmnigraphClient, "load", _fail)
266
+ with pytest.raises(RuntimeError, match="simulated load failure"):
267
+ indexer.index_path(sample_repo, config=cfg_mod.load())
268
+
269
+ monkeypatch.setattr(graph_mod.OmnigraphClient, "load", real_load)
270
+ stats = indexer.index_path(sample_repo, config=cfg_mod.load())
271
+ assert stats.indexed >= 1, "the file must be re-indexed, not skipped"
272
+ assert stats.skipped == 0
@@ -0,0 +1,9 @@
1
+ """Every witan-code command's parameter docs reach ``--help``."""
2
+
3
+ from testsupport.cli_docstrings import one_line_param_docs
4
+
5
+ from witan_code.cli import app
6
+
7
+
8
+ def test_no_command_documents_a_parameter_on_one_line():
9
+ assert one_line_param_docs(app, "witan_code") == []
@@ -322,6 +322,46 @@ def test_reindex_offer_degrades_on_indexing_failure(tmp_path, monkeypatch):
322
322
  assert _fn(srv.code_interface_consumers)("env_var", "X", ctx=_AcceptCtx(True)) == []
323
323
 
324
324
 
325
+ @requires_stack
326
+ def test_reindex_offer_is_never_made_to_a_remote_caller(tmp_path, monkeypatch):
327
+ """A token-authenticated caller never gets the index-now offer, even with an
328
+ accepting ctx: it would index the SERVER's checkout, and the web UI's
329
+ read-only token could otherwise reach a write through a bound read tool
330
+ (code_interface_*, code_repo_dependencies)."""
331
+ import fastmcp.server.dependencies as deps
332
+ from fastmcp.server.auth import AccessToken
333
+
334
+ from witan_code import config as cfg_mod
335
+ from witan_code import indexer
336
+ from witan_code import server as srv
337
+
338
+ repo = "https://github.com/test/cg-remote-caller"
339
+ monkeypatch.setenv("WITAN_REPO", repo)
340
+ monkeypatch.setenv("WITAN_CODE_DIR", str(tmp_path / "code"))
341
+ monkeypatch.setattr(srv, "cfg", cfg_mod.load())
342
+ srv._clients.clear()
343
+
344
+ src = tmp_path / "src"
345
+ src.mkdir()
346
+ (src / "svc.py").write_text(SAMPLE)
347
+ monkeypatch.chdir(src)
348
+ srv._git_context.clear()
349
+
350
+ indexed = []
351
+ monkeypatch.setattr(indexer, "index_path", lambda *a, **kw: indexed.append(a))
352
+ ui_token = AccessToken(
353
+ token="t", client_id="witan-ui", scopes=[], claims={"azp": "witan-ui"}
354
+ )
355
+ monkeypatch.setattr(deps, "get_access_token", lambda: ui_token)
356
+
357
+ accept = _AcceptCtx(True)
358
+ assert _fn(srv.code_interface_providers)("env_var", "X", ctx=accept) == []
359
+ assert _fn(srv.code_interface_consumers)("env_var", "X", ctx=accept) == []
360
+ assert _fn(srv.code_repo_dependencies)(ctx=accept) == {"repos": [], "edges": []}
361
+ assert _fn(srv.code_find_references)(f"{repo}#svc.py::helper", ctx=accept) == []
362
+ assert indexed == []
363
+
364
+
325
365
  # ── Opportunity 3: code_find_definition disambiguates multi-repo matches ─────
326
366
 
327
367
  RA = "https://github.com/test/def-repo-a"
@@ -747,3 +747,36 @@ def test_a_codex_patch_that_deletes_and_renames_leaves_neither_old_path(
747
747
  renamed = client.read("code_read.gq", "find_by_name", {"name": "renamed"})
748
748
  assert [r["file_id"].split("#", 1)[1] for r in renamed] == ["new.py"]
749
749
  assert client.read("code_read.gq", "find_by_name", {"name": "deleted"}) == []
750
+
751
+
752
+ @requires_stack
753
+ def test_an_edit_to_a_git_ignored_file_is_not_indexed(
754
+ tmp_path, monkeypatch, _state, _spawned
755
+ ):
756
+ """An agent editing inside a virtualenv or build tree: the drainer drops
757
+ the ignored file and indexes the rest of the batch."""
758
+ from witan_code import config as cfg_mod
759
+ from witan_code import store as store_mod
760
+ from witan_code.graph import OmnigraphClient
761
+
762
+ monkeypatch.setenv("WITAN_REPO", "https://github.com/test/cg")
763
+ monkeypatch.setenv("WITAN_CODE_DIR", str(tmp_path / "code"))
764
+ src = tmp_path / "repo"
765
+ (src / "env" / "lib").mkdir(parents=True)
766
+ subprocess.run(["git", "init", "-q", "-b", "main"], cwd=src, check=True)
767
+ (src / "env" / ".gitignore").write_text("*\n")
768
+ (src / "env" / "lib" / "dep.py").write_text("def dep():\n return 1\n")
769
+ (src / "mine.py").write_text("def mine():\n return 1\n")
770
+
771
+ hooks.reindex_hook(_payload(src / "env" / "lib" / "dep.py"))
772
+ hooks.reindex_hook(_payload(src / "mine.py"))
773
+ checkout = hooks.repo_module.root(src)
774
+ hooks.drain_pending(checkout, hooks._try_lock(checkout))
775
+
776
+ cfg = cfg_mod.load()
777
+ client = OmnigraphClient(
778
+ str(store_mod.store_for_repo("https://github.com/test/cg", cfg)),
779
+ cfg.queries_dir,
780
+ )
781
+ rows = client.read("code_read.gq", "all_file_hashes", {})
782
+ assert {r["slug"].split("#", 1)[1] for r in rows} == {"mine.py"}
@@ -100,6 +100,132 @@ def test_collection_order_is_deterministic(tmp_path):
100
100
  assert indexer._collect_files(tmp_path) == sorted(indexer._collect_files(tmp_path))
101
101
 
102
102
 
103
+ # ── _collect_files in a git work tree: git's ignore rules apply ──────────────
104
+
105
+
106
+ def _git(cwd: Path, *args: str) -> None:
107
+ subprocess.run(["git", *args], cwd=cwd, check=True, capture_output=True)
108
+
109
+
110
+ def _work_tree(tmp_path: Path) -> Path:
111
+ src = tmp_path / "repo"
112
+ src.mkdir()
113
+ _git(src, "init", "-q", "-b", "main")
114
+ return src
115
+
116
+
117
+ def test_a_git_ignored_directory_is_not_collected(tmp_path):
118
+ """A virtualenv under a name `_SKIP_DIRS` does not know. uv and
119
+ `python -m venv` both write a `*` .gitignore into the environment, so git
120
+ ignores it under any name, with nothing in the repo's own .gitignore."""
121
+ src = _work_tree(tmp_path)
122
+ (src / "a.py").write_text("x = 1\n")
123
+ site = src / "env" / "lib" / "python3.12" / "site-packages" / "dep"
124
+ site.mkdir(parents=True)
125
+ (site / "mod.py").write_text("x = 1\n")
126
+ (src / "env" / ".gitignore").write_text("*\n")
127
+ (src / ".gitignore").write_text("out/\n")
128
+ (src / "out").mkdir()
129
+ (src / "out" / "gen.js").write_text("var x = 1;\n")
130
+
131
+ assert indexer._collect_files(src) == [src / "a.py"]
132
+
133
+
134
+ def test_untracked_files_that_are_not_ignored_are_collected(tmp_path):
135
+ """A new file nobody has `git add`ed yet is part of the work in progress
136
+ and has to be indexed; so does a tracked file a pattern happens to match,
137
+ which git keeps tracking."""
138
+ src = _work_tree(tmp_path)
139
+ (src / ".gitignore").write_text("generated/\n")
140
+ (src / "tracked.py").write_text("x = 1\n")
141
+ (src / "generated").mkdir()
142
+ (src / "generated" / "kept.py").write_text("x = 1\n")
143
+ _git(src, "add", "-f", "tracked.py", "generated/kept.py")
144
+ (src / "pkg").mkdir()
145
+ (src / "pkg" / "new.py").write_text("x = 1\n")
146
+ (src / "pkg" / "with space.py").write_text("x = 1\n")
147
+ (src / "pkg" / "new\nline.py").write_text("x = 1\n")
148
+
149
+ assert indexer._collect_files(src) == sorted(
150
+ [
151
+ src / "generated" / "kept.py",
152
+ src / "pkg" / "new.py",
153
+ src / "pkg" / "new\nline.py",
154
+ src / "pkg" / "with space.py",
155
+ src / "tracked.py",
156
+ ]
157
+ )
158
+
159
+
160
+ def test_git_listing_keeps_the_walk_s_exclusions(tmp_path):
161
+ """git's listing is narrowed, never widened: a tracked file under a
162
+ `_SKIP_DIRS` name, a nested repository (real or not), and a tracked file
163
+ deleted from the work tree all stay out."""
164
+ src = _work_tree(tmp_path)
165
+ (src / "a.py").write_text("x = 1\n")
166
+ (src / "build").mkdir()
167
+ (src / "build" / "b.py").write_text("x = 1\n")
168
+ (src / "gone.py").write_text("x = 1\n")
169
+ _git(src, "add", "build/b.py", "gone.py")
170
+ (src / "gone.py").unlink()
171
+ nested = src / "vendored"
172
+ nested.mkdir()
173
+ _git(nested, "init", "-q")
174
+ (nested / "dep.py").write_text("x = 1\n")
175
+ wt = src / ".claude" / "worktrees" / "feature-x"
176
+ wt.mkdir(parents=True)
177
+ (wt / ".git").write_text("gitdir: /somewhere/.git/worktrees/feature-x\n")
178
+ (wt / "copy.py").write_text("x = 1\n")
179
+
180
+ assert indexer._collect_files(src) == [src / "a.py"]
181
+
182
+
183
+ def test_outside_a_work_tree_the_disk_is_walked(tmp_path):
184
+ """No git checkout, so no ignore rules: a .gitignore is just a file."""
185
+ (tmp_path / ".gitignore").write_text("env/\n")
186
+ (tmp_path / "env").mkdir()
187
+ (tmp_path / "env" / "e.py").write_text("x = 1\n")
188
+ (tmp_path / "a.py").write_text("x = 1\n")
189
+
190
+ assert indexer._collect_files(tmp_path) == [
191
+ tmp_path / "a.py",
192
+ tmp_path / "env" / "e.py",
193
+ ]
194
+
195
+
196
+ def test_without_a_git_binary_the_disk_is_walked(tmp_path, monkeypatch):
197
+ src = _work_tree(tmp_path)
198
+ (src / ".gitignore").write_text("env/\n")
199
+ (src / "env").mkdir()
200
+ (src / "env" / "e.py").write_text("x = 1\n")
201
+ (src / "a.py").write_text("x = 1\n")
202
+ empty = tmp_path / "empty-bin"
203
+ empty.mkdir()
204
+ monkeypatch.setenv("PATH", str(empty))
205
+
206
+ assert indexer._collect_files(src) == [src / "a.py", src / "env" / "e.py"]
207
+
208
+
209
+ @pytest.mark.skipif(os.geteuid() == 0, reason="root reads a mode-000 directory")
210
+ def test_a_directory_git_cannot_open_is_reported(tmp_path):
211
+ """git warns about it and still exits 0 with the directory's untracked
212
+ files missing, which the purge would read as deleted."""
213
+ src = _work_tree(tmp_path)
214
+ (src / "a.py").write_text("x = 1\n")
215
+ locked = src / "locked"
216
+ locked.mkdir()
217
+ (locked / "b.py").write_text("x = 1\n")
218
+ locked.chmod(0)
219
+ errors: list[OSError] = []
220
+ try:
221
+ collected = indexer._collect_files(src, on_error=errors.append)
222
+ finally:
223
+ locked.chmod(0o755)
224
+
225
+ assert collected == [src / "a.py"]
226
+ assert errors
227
+
228
+
103
229
  # ── Purging rows that are no longer this repo's ──────────────────────────────
104
230
 
105
231
 
@@ -189,10 +315,12 @@ def test_purge_survives_a_forced_reindex(tmp_path, monkeypatch):
189
315
 
190
316
 
191
317
  @requires_stack
192
- def test_a_batch_of_edits_is_one_delete_and_two_loads(tmp_path, monkeypatch):
318
+ def test_a_batch_of_edits_is_one_delete_and_one_load(tmp_path, monkeypatch):
193
319
  """What the PostToolUse drainer relies on to bound its writes: edited,
194
- created and deleted files land together, in the same three commits on
195
- the repo's store that one edited file costs."""
320
+ created and deleted files land together, in the same two commits on the
321
+ repo's store that one edited file costs. Counted at `load_batch`, the
322
+ call that commits, so a load split into node and edge batches (or
323
+ followed by a content-hash load) shows up as the extra commit it is."""
196
324
  from witan_code import config as cfg_mod
197
325
  from witan_code import store as store_mod
198
326
  from witan_code.graph import OmnigraphClient
@@ -205,7 +333,7 @@ def test_a_batch_of_edits_is_one_delete_and_two_loads(tmp_path, monkeypatch):
205
333
  store = store_mod.store_for_repo("https://github.com/test/cg", cfg)
206
334
 
207
335
  writes: list[str] = []
208
- for method in ("change_many", "load"):
336
+ for method in ("change_many", "load_batch"):
209
337
  real = getattr(OmnigraphClient, method)
210
338
 
211
339
  def _counted(self, *args, _real=real, _method=method, **kwargs):
@@ -223,7 +351,7 @@ def test_a_batch_of_edits_is_one_delete_and_two_loads(tmp_path, monkeypatch):
223
351
  [src / "a.py", src / "b.py", src / "gone.py", src / "new.py"], config=cfg
224
352
  )
225
353
 
226
- assert writes == ["change_many", "load", "load"]
354
+ assert writes == ["change_many", "load_batch"]
227
355
  assert (stats.indexed, stats.purged) == (3, 1)
228
356
  assert _files(store, cfg) == {"a.py", "b.py", "c.py", "new.py"}
229
357
 
@@ -317,7 +445,10 @@ def test_unreadable_directory_suppresses_the_purge(tmp_path, monkeypatch):
317
445
  assert _files(store, cfg) == {"a.py", "sub/b.py"}
318
446
 
319
447
  # Simulate `sub/` becoming unreadable: os.walk yields the root only and
320
- # hands the failure to onerror, exactly as a PermissionError does.
448
+ # hands the failure to onerror, exactly as a PermissionError does. The
449
+ # walk runs when git cannot list the tree; the git listing's own case is
450
+ # the test below.
451
+ monkeypatch.setattr(indexer.repo_module, "unignored_files", lambda *a, **k: None)
321
452
  real_walk = indexer.os.walk
322
453
 
323
454
  def _walk(top, *args, onerror=None, **kwargs):
@@ -337,6 +468,101 @@ def test_unreadable_directory_suppresses_the_purge(tmp_path, monkeypatch):
337
468
  assert _files(store, cfg) == {"a.py", "sub/b.py"}
338
469
 
339
470
 
471
+ @requires_stack
472
+ @pytest.mark.skipif(os.geteuid() == 0, reason="root reads a mode-000 directory")
473
+ def test_a_directory_git_cannot_open_suppresses_the_purge(tmp_path, monkeypatch):
474
+ """The same guard as above, for the git listing: git leaves an unreadable
475
+ directory's untracked files out and still exits 0."""
476
+ from witan_code import config as cfg_mod
477
+ from witan_code import store as store_mod
478
+
479
+ src = _repo(tmp_path, monkeypatch)
480
+ (src / "sub").mkdir()
481
+ (src / "sub" / "b.py").write_text("def b():\n return 1\n")
482
+ cfg = cfg_mod.load()
483
+ indexer.index_path(src, config=cfg)
484
+ store = store_mod.store_for_repo("https://github.com/test/cg", cfg)
485
+
486
+ (src / "sub").chmod(0)
487
+ try:
488
+ stats = indexer.index_path(src, config=cfg)
489
+ finally:
490
+ (src / "sub").chmod(0o755)
491
+
492
+ assert stats.errors >= 1
493
+ assert stats.purged == 0
494
+ assert _files(store, cfg) == {"a.py", "sub/b.py"}
495
+
496
+
497
+ @requires_stack
498
+ def test_full_index_purges_rows_for_files_that_became_ignored(tmp_path, monkeypatch):
499
+ """How a store indexed before this rule existed sheds its virtualenv: the
500
+ next full index collects without it, and the purge takes its rows."""
501
+ from witan_code import config as cfg_mod
502
+ from witan_code import store as store_mod
503
+
504
+ src = _repo(tmp_path, monkeypatch)
505
+ (src / "env").mkdir()
506
+ (src / "env" / "dep.py").write_text("def dep():\n return 1\n")
507
+ cfg = cfg_mod.load()
508
+ indexer.index_path(src, config=cfg)
509
+ store = store_mod.store_for_repo("https://github.com/test/cg", cfg)
510
+ assert _files(store, cfg) == {"a.py", "env/dep.py"}
511
+
512
+ (src / "env" / ".gitignore").write_text("*\n")
513
+ stats = indexer.index_path(src, config=cfg)
514
+
515
+ assert stats.purged == 1
516
+ assert _files(store, cfg) == {"a.py"}
517
+
518
+
519
+ @requires_stack
520
+ def test_an_ignored_file_named_directly_is_not_indexed(tmp_path, monkeypatch):
521
+ """The edit hook names files, not directories, so the listing never sees
522
+ them; the batch is held to the same rule in one `git check-ignore`."""
523
+ from witan_code import config as cfg_mod
524
+ from witan_code import store as store_mod
525
+
526
+ src = _repo(tmp_path, monkeypatch)
527
+ (src / ".gitignore").write_text("scratch/\n")
528
+ (src / "scratch").mkdir()
529
+ (src / "scratch" / "s.py").write_text("def s():\n return 1\n")
530
+ (src / "b.py").write_text("def b():\n return 1\n")
531
+ cfg = cfg_mod.load()
532
+
533
+ stats = indexer.index_paths(
534
+ [src / "scratch" / "s.py", src / "b.py", src / "a.py"], config=cfg
535
+ )
536
+
537
+ store = store_mod.store_for_repo("https://github.com/test/cg", cfg)
538
+ assert stats.indexed == 2
539
+ assert _files(store, cfg) == {"a.py", "b.py"}
540
+
541
+
542
+ @requires_stack
543
+ def test_an_ignored_file_named_directly_drops_rows_it_already_has(
544
+ tmp_path, monkeypatch
545
+ ):
546
+ """Rows written before the file was ignored go on its next edit, without
547
+ waiting for a full run that may never be allowed to purge the view."""
548
+ from witan_code import config as cfg_mod
549
+ from witan_code import store as store_mod
550
+
551
+ src = _repo(tmp_path, monkeypatch)
552
+ (src / "env").mkdir()
553
+ (src / "env" / "dep.py").write_text("def dep():\n return 1\n")
554
+ cfg = cfg_mod.load()
555
+ indexer.index_path(src, config=cfg)
556
+ store = store_mod.store_for_repo("https://github.com/test/cg", cfg)
557
+ assert _files(store, cfg) == {"a.py", "env/dep.py"}
558
+
559
+ (src / "env" / ".gitignore").write_text("*\n")
560
+ stats = indexer.index_paths([src / "env" / "dep.py"], config=cfg)
561
+
562
+ assert (stats.indexed, stats.purged) == (0, 1)
563
+ assert _files(store, cfg) == {"a.py"}
564
+
565
+
340
566
  # ── _may_purge: the gate on the one destructive step ─────────────────────────
341
567
 
342
568