witan-code 0.25.0__tar.gz → 0.26.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 (109) hide show
  1. {witan_code-0.25.0 → witan_code-0.26.0}/CHANGELOG.md +6 -0
  2. {witan_code-0.25.0 → witan_code-0.26.0}/PKG-INFO +2 -2
  3. {witan_code-0.25.0 → witan_code-0.26.0}/pyproject.toml +10 -3
  4. {witan_code-0.25.0 → witan_code-0.26.0}/tests/test_hooks.py +73 -0
  5. {witan_code-0.25.0 → witan_code-0.26.0}/witan_code/cli.py +5 -4
  6. {witan_code-0.25.0 → witan_code-0.26.0}/witan_code/hooks.py +37 -8
  7. {witan_code-0.25.0 → witan_code-0.26.0}/.gitignore +0 -0
  8. {witan_code-0.25.0 → witan_code-0.26.0}/README.md +0 -0
  9. {witan_code-0.25.0 → witan_code-0.26.0}/changelog.d/README.md +0 -0
  10. {witan_code-0.25.0 → witan_code-0.26.0}/config/claude.json +0 -0
  11. {witan_code-0.25.0 → witan_code-0.26.0}/config/copilot.json +0 -0
  12. {witan_code-0.25.0 → witan_code-0.26.0}/config/pi.json +0 -0
  13. {witan_code-0.25.0 → witan_code-0.26.0}/conftest.py +0 -0
  14. {witan_code-0.25.0 → witan_code-0.26.0}/docs/BRANCH_INDEXING.md +0 -0
  15. {witan_code-0.25.0 → witan_code-0.26.0}/docs/CLI_REFERENCE.md +0 -0
  16. {witan_code-0.25.0 → witan_code-0.26.0}/docs/EDGE_PRECISION_TIERS.md +0 -0
  17. {witan_code-0.25.0 → witan_code-0.26.0}/docs/PACKAGE_MAP.md +0 -0
  18. {witan_code-0.25.0 → witan_code-0.26.0}/docs/STAGE2_STITCHING.md +0 -0
  19. {witan_code-0.25.0 → witan_code-0.26.0}/docs/SYMBOL_FORMAT.md +0 -0
  20. {witan_code-0.25.0 → witan_code-0.26.0}/docs/SYMBOL_TABLE.md +0 -0
  21. {witan_code-0.25.0 → witan_code-0.26.0}/docs/USER_GUIDE.md +0 -0
  22. {witan_code-0.25.0 → witan_code-0.26.0}/install.sh +0 -0
  23. {witan_code-0.25.0 → witan_code-0.26.0}/tests/__init__.py +0 -0
  24. {witan_code-0.25.0 → witan_code-0.26.0}/tests/conftest.py +0 -0
  25. {witan_code-0.25.0 → witan_code-0.26.0}/tests/test_batched_deletes.py +0 -0
  26. {witan_code-0.25.0 → witan_code-0.26.0}/tests/test_branches.py +0 -0
  27. {witan_code-0.25.0 → witan_code-0.26.0}/tests/test_bridge.py +0 -0
  28. {witan_code-0.25.0 → witan_code-0.26.0}/tests/test_chunked_load.py +0 -0
  29. {witan_code-0.25.0 → witan_code-0.26.0}/tests/test_cli_dispatch.py +0 -0
  30. {witan_code-0.25.0 → witan_code-0.26.0}/tests/test_cli_hooks.py +0 -0
  31. {witan_code-0.25.0 → witan_code-0.26.0}/tests/test_cli_output_format.py +0 -0
  32. {witan_code-0.25.0 → witan_code-0.26.0}/tests/test_cli_selected_target.py +0 -0
  33. {witan_code-0.25.0 → witan_code-0.26.0}/tests/test_config.py +0 -0
  34. {witan_code-0.25.0 → witan_code-0.26.0}/tests/test_config_targets.py +0 -0
  35. {witan_code-0.25.0 → witan_code-0.26.0}/tests/test_context.py +0 -0
  36. {witan_code-0.25.0 → witan_code-0.26.0}/tests/test_crossrepo.py +0 -0
  37. {witan_code-0.25.0 → witan_code-0.26.0}/tests/test_edges.py +0 -0
  38. {witan_code-0.25.0 → witan_code-0.26.0}/tests/test_elicit.py +0 -0
  39. {witan_code-0.25.0 → witan_code-0.26.0}/tests/test_enrichment.py +0 -0
  40. {witan_code-0.25.0 → witan_code-0.26.0}/tests/test_github_app.py +0 -0
  41. {witan_code-0.25.0 → witan_code-0.26.0}/tests/test_graph.py +0 -0
  42. {witan_code-0.25.0 → witan_code-0.26.0}/tests/test_identity.py +0 -0
  43. {witan_code-0.25.0 → witan_code-0.26.0}/tests/test_index_failure_diagnostics.py +0 -0
  44. {witan_code-0.25.0 → witan_code-0.26.0}/tests/test_index_reports_its_store.py +0 -0
  45. {witan_code-0.25.0 → witan_code-0.26.0}/tests/test_index_requires_a_repo_key.py +0 -0
  46. {witan_code-0.25.0 → witan_code-0.26.0}/tests/test_indexer.py +0 -0
  47. {witan_code-0.25.0 → witan_code-0.26.0}/tests/test_indexer_scope.py +0 -0
  48. {witan_code-0.25.0 → witan_code-0.26.0}/tests/test_ingest.py +0 -0
  49. {witan_code-0.25.0 → witan_code-0.26.0}/tests/test_languages.py +0 -0
  50. {witan_code-0.25.0 → witan_code-0.26.0}/tests/test_maintenance.py +0 -0
  51. {witan_code-0.25.0 → witan_code-0.26.0}/tests/test_package_map.py +0 -0
  52. {witan_code-0.25.0 → witan_code-0.26.0}/tests/test_reaper.py +0 -0
  53. {witan_code-0.25.0 → witan_code-0.26.0}/tests/test_rebuild_honours_the_repo_key.py +0 -0
  54. {witan_code-0.25.0 → witan_code-0.26.0}/tests/test_refusal_audit.py +0 -0
  55. {witan_code-0.25.0 → witan_code-0.26.0}/tests/test_remote_proxy.py +0 -0
  56. {witan_code-0.25.0 → witan_code-0.26.0}/tests/test_remote_store.py +0 -0
  57. {witan_code-0.25.0 → witan_code-0.26.0}/tests/test_repo.py +0 -0
  58. {witan_code-0.25.0 → witan_code-0.26.0}/tests/test_server.py +0 -0
  59. {witan_code-0.25.0 → witan_code-0.26.0}/tests/test_setup.py +0 -0
  60. {witan_code-0.25.0 → witan_code-0.26.0}/tests/test_stitch.py +0 -0
  61. {witan_code-0.25.0 → witan_code-0.26.0}/tests/test_store.py +0 -0
  62. {witan_code-0.25.0 → witan_code-0.26.0}/tests/test_symbol_table.py +0 -0
  63. {witan_code-0.25.0 → witan_code-0.26.0}/tests/test_tasks.py +0 -0
  64. {witan_code-0.25.0 → witan_code-0.26.0}/tests/test_tool_schema.py +0 -0
  65. {witan_code-0.25.0 → witan_code-0.26.0}/tests/test_views.py +0 -0
  66. {witan_code-0.25.0 → witan_code-0.26.0}/tests/test_visualize.py +0 -0
  67. {witan_code-0.25.0 → witan_code-0.26.0}/witan_code/__init__.py +0 -0
  68. {witan_code-0.25.0 → witan_code-0.26.0}/witan_code/__main__.py +0 -0
  69. {witan_code-0.25.0 → witan_code-0.26.0}/witan_code/bridge.py +0 -0
  70. {witan_code-0.25.0 → witan_code-0.26.0}/witan_code/bridge_extractors.py +0 -0
  71. {witan_code-0.25.0 → witan_code-0.26.0}/witan_code/config.py +0 -0
  72. {witan_code-0.25.0 → witan_code-0.26.0}/witan_code/context.py +0 -0
  73. {witan_code-0.25.0 → witan_code-0.26.0}/witan_code/edges.py +0 -0
  74. {witan_code-0.25.0 → witan_code-0.26.0}/witan_code/elicit.py +0 -0
  75. {witan_code-0.25.0 → witan_code-0.26.0}/witan_code/extensions/pi/codegraph.ts +0 -0
  76. {witan_code-0.25.0 → witan_code-0.26.0}/witan_code/github_app.py +0 -0
  77. {witan_code-0.25.0 → witan_code-0.26.0}/witan_code/graph.py +0 -0
  78. {witan_code-0.25.0 → witan_code-0.26.0}/witan_code/identity.py +0 -0
  79. {witan_code-0.25.0 → witan_code-0.26.0}/witan_code/indexer.py +0 -0
  80. {witan_code-0.25.0 → witan_code-0.26.0}/witan_code/ingest.py +0 -0
  81. {witan_code-0.25.0 → witan_code-0.26.0}/witan_code/maintenance.py +0 -0
  82. {witan_code-0.25.0 → witan_code-0.26.0}/witan_code/output.py +0 -0
  83. {witan_code-0.25.0 → witan_code-0.26.0}/witan_code/package_map.py +0 -0
  84. {witan_code-0.25.0 → witan_code-0.26.0}/witan_code/queries/bridge.gq +0 -0
  85. {witan_code-0.25.0 → witan_code-0.26.0}/witan_code/queries/code_mutations.gq +0 -0
  86. {witan_code-0.25.0 → witan_code-0.26.0}/witan_code/queries/code_read.gq +0 -0
  87. {witan_code-0.25.0 → witan_code-0.26.0}/witan_code/queries/delete.gq +0 -0
  88. {witan_code-0.25.0 → witan_code-0.26.0}/witan_code/queries_ts/bash.scm +0 -0
  89. {witan_code-0.25.0 → witan_code-0.26.0}/witan_code/queries_ts/hcl.scm +0 -0
  90. {witan_code-0.25.0 → witan_code-0.26.0}/witan_code/queries_ts/python.scm +0 -0
  91. {witan_code-0.25.0 → witan_code-0.26.0}/witan_code/queries_ts/sql.scm +0 -0
  92. {witan_code-0.25.0 → witan_code-0.26.0}/witan_code/queries_ts/typescript.scm +0 -0
  93. {witan_code-0.25.0 → witan_code-0.26.0}/witan_code/queries_ts/yaml.scm +0 -0
  94. {witan_code-0.25.0 → witan_code-0.26.0}/witan_code/reaper.py +0 -0
  95. {witan_code-0.25.0 → witan_code-0.26.0}/witan_code/remote/__init__.py +0 -0
  96. {witan_code-0.25.0 → witan_code-0.26.0}/witan_code/remote/oidc.py +0 -0
  97. {witan_code-0.25.0 → witan_code-0.26.0}/witan_code/remote/proxy.py +0 -0
  98. {witan_code-0.25.0 → witan_code-0.26.0}/witan_code/remote/store.py +0 -0
  99. {witan_code-0.25.0 → witan_code-0.26.0}/witan_code/repo.py +0 -0
  100. {witan_code-0.25.0 → witan_code-0.26.0}/witan_code/schema/bridge-schema.pg +0 -0
  101. {witan_code-0.25.0 → witan_code-0.26.0}/witan_code/schema/code-schema.pg +0 -0
  102. {witan_code-0.25.0 → witan_code-0.26.0}/witan_code/selected_target.py +0 -0
  103. {witan_code-0.25.0 → witan_code-0.26.0}/witan_code/server.py +0 -0
  104. {witan_code-0.25.0 → witan_code-0.26.0}/witan_code/setup.py +0 -0
  105. {witan_code-0.25.0 → witan_code-0.26.0}/witan_code/skills/witan-code/SKILL.md +0 -0
  106. {witan_code-0.25.0 → witan_code-0.26.0}/witan_code/stitch.py +0 -0
  107. {witan_code-0.25.0 → witan_code-0.26.0}/witan_code/store.py +0 -0
  108. {witan_code-0.25.0 → witan_code-0.26.0}/witan_code/views.py +0 -0
  109. {witan_code-0.25.0 → witan_code-0.26.0}/witan_code/visualize.py +0 -0
@@ -8,6 +8,12 @@ a MINOR bump may include breaking changes).
8
8
 
9
9
  <!-- scriv-insert-here -->
10
10
 
11
+ ## [0.26.0] - 2026-10-16
12
+
13
+ ### Fixed
14
+
15
+ - `reindex-hook` reindexes files Codex edits. Codex's `Edit|Write` matcher selects its `apply_patch` tool, whose payload carries the patch text instead of a file path, so the hook would find nothing to index. It now reads the `*** Add File:`, `*** Update File:` and `*** Move to:` headers and reindexes each file the patch leaves on disk.
16
+
11
17
  ## [0.25.0] - 2026-10-15
12
18
 
13
19
  ### Changed
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: witan-code
3
- Version: 0.25.0
3
+ Version: 0.26.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.41
29
+ Requires-Dist: witan-core[cli,observability,remote,sentry]<1,>=0.43
30
30
  Provides-Extra: tasks
31
31
  Requires-Dist: fastmcp-tasks<5,>=4; extra == 'tasks'
32
32
  Description-Content-Type: text/markdown
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "witan-code"
3
- version = "0.25.0"
3
+ version = "0.26.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"
@@ -176,7 +176,14 @@ dependencies = [
176
176
  # is on 0.13, which answers a request without that header with `400
177
177
  # api_contract_mismatch`, so 0.40 imports and runs, then fails on the
178
178
  # first read of a shared code graph.
179
- "witan-core[cli,remote,observability,sentry]>=0.41,<1",
179
+ #
180
+ # ★ >=0.43 IS A BEHAVIOUR FLOOR: `witan-code setup --agent codex` needs
181
+ # `codex` in `witan_core.cli.AgentName`, and the Codex hooks' "trust it
182
+ # with /hooks" line is an `InstallResult.notice` that `report_install`
183
+ # prints only from 0.43.0. On 0.42 `--agent codex` is rejected as an
184
+ # invalid value, and `--agent all` writes the reindex hook to Codex
185
+ # without the notice.
186
+ "witan-core[cli,remote,observability,sentry]>=0.43,<1",
180
187
  "fastmcp>=4,<5",
181
188
  "cyclopts>=4,<6",
182
189
  # [targets.<name>] override models (config.py) — also transitively pulled
@@ -259,7 +266,7 @@ testpaths = ["tests"]
259
266
  packages = ["witan_code"]
260
267
 
261
268
  [tool.bumpversion]
262
- current_version = "0.25.0"
269
+ current_version = "0.26.0"
263
270
  allow_dirty = true
264
271
 
265
272
  [[tool.bumpversion.files]]
@@ -6,6 +6,7 @@ the lock handoff, stdin-JSON parsing, path resolution), not the real indexer
6
6
  or a real detached drainer. The lock itself is real: a kernel flock.
7
7
  """
8
8
 
9
+ import json
9
10
  import os
10
11
  import subprocess
11
12
  import sys
@@ -171,6 +172,78 @@ def test_reindex_hook_swallows_index_failure(tmp_path, monkeypatch):
171
172
  ) # must not raise
172
173
 
173
174
 
175
+ # ── Codex apply_patch payloads ────────────────────────────────────────────────
176
+
177
+
178
+ def _codex_post_tool_use(cwd, patch: str) -> str:
179
+ """A Codex ``PostToolUse`` payload for its ``apply_patch`` tool.
180
+
181
+ Field set from ``PostToolUseCommandInput`` (codex-rs/hooks/src/schema.rs at
182
+ rust-v0.162.1); ``tool_input``/``tool_response`` from
183
+ ``ApplyPatchHandler::post_tool_use_payload``
184
+ (codex-rs/core/src/tools/handlers/apply_patch.rs). Codex's ``Edit|Write``
185
+ matcher selects this tool by alias, but the payload names it
186
+ ``apply_patch`` and carries the patch, not a path.
187
+ """
188
+ return json.dumps(
189
+ {
190
+ "session_id": "019a1b2c-3d4e-7f00-8a9b-0c1d2e3f4a5b",
191
+ "turn_id": "1",
192
+ "transcript_path": None,
193
+ "cwd": str(cwd),
194
+ "hook_event_name": "PostToolUse",
195
+ "model": "gpt-5-codex",
196
+ "permission_mode": "default",
197
+ "tool_name": "apply_patch",
198
+ "tool_input": {"command": patch},
199
+ "tool_response": "Success. Updated the following files:",
200
+ "tool_use_id": "call-apply-patch",
201
+ }
202
+ )
203
+
204
+
205
+ def test_reindex_hook_reads_every_file_a_codex_patch_leaves(
206
+ tmp_path, monkeypatch, _indexed
207
+ ):
208
+ monkeypatch.chdir(tmp_path)
209
+ (tmp_path / "added.py").write_text("def a(): pass")
210
+ (tmp_path / "updated.py").write_text("def u(): pass")
211
+ (tmp_path / "moved.py").write_text("def m(): pass")
212
+ # Present on disk, but only named inside an added file's content.
213
+ (tmp_path / "forged.py").write_text("def f(): pass")
214
+ patch = (
215
+ "*** Begin Patch\n"
216
+ " *** Add File: added.py\n"
217
+ "+def a(): pass\n"
218
+ "+*** Add File: forged.py\n"
219
+ "*** Update File: updated.py\n"
220
+ "@@\n"
221
+ "-def u(): return 1\n"
222
+ "+def u(): pass\n"
223
+ "*** Update File: old.py\n"
224
+ "*** Move to: moved.py\n"
225
+ "*** Delete File: deleted.py\n"
226
+ "*** End Patch\n"
227
+ )
228
+
229
+ hooks.reindex_hook(_codex_post_tool_use(tmp_path, patch))
230
+
231
+ assert _indexed == [
232
+ tmp_path / "added.py",
233
+ tmp_path / "updated.py",
234
+ tmp_path / "moved.py",
235
+ ]
236
+
237
+
238
+ def test_reindex_hook_noop_on_a_codex_payload_without_a_patch(tmp_path, _indexed):
239
+ payload = json.loads(_codex_post_tool_use(tmp_path, ""))
240
+ payload["tool_input"] = {"command": None}
241
+
242
+ hooks.reindex_hook(json.dumps(payload))
243
+
244
+ assert _indexed == []
245
+
246
+
174
247
  # ── reindex_hook inside a repo ────────────────────────────────────────────────
175
248
 
176
249
 
@@ -991,9 +991,10 @@ def _drain_pending_cmd(checkout: Path, lock_fd: int) -> None:
991
991
  def reindex_hook_cmd() -> None:
992
992
  """Incrementally reindex the file named in stdin's hook JSON (PostToolUse hook).
993
993
 
994
- Reads the Claude Code hook payload from stdin, extracts
995
- ``tool_input.file_path`` (or ``path``/``filename``), and queues it for
996
- reindexing if it exists. One detached drainer per checkout applies the
994
+ Reads the hook payload from stdin, extracts ``tool_input.file_path`` (or
995
+ ``path``/``filename``) from Claude Code's, or every file a Codex
996
+ ``apply_patch`` adds, updates or moves to, and queues each for reindexing
997
+ if it exists. One detached drainer per checkout applies the
997
998
  queue, so parallel agents editing one worktree do not race each other's
998
999
  writes to its branch view. Logs from the last drainer are kept in
999
1000
  ``$TMPDIR/witan-code-<uid>/``. Best-effort: a missing or
@@ -1038,7 +1039,7 @@ def setup(
1038
1039
 
1039
1040
  Parameters
1040
1041
  ----------
1041
- agent: Target agent — claude | pi | copilot | opencode | all.
1042
+ agent: Target agent — claude | pi | copilot | opencode | codex | all.
1042
1043
  author: Name written to graph nodes (default: git config user.name or $USER).
1043
1044
  dry_run: Print what would happen without writing anything.
1044
1045
  force: Replace a symlink or non-directory occupying a destination path.
@@ -25,6 +25,7 @@ from __future__ import annotations
25
25
  import fcntl
26
26
  import json
27
27
  import os
28
+ import re
28
29
  import subprocess
29
30
  import sys
30
31
  from pathlib import Path
@@ -40,6 +41,20 @@ logger = get_logger("witan.code.hooks")
40
41
 
41
42
  _LOG_MAX_BYTES = 1024 * 1024
42
43
 
44
+ # Codex edits files with its `apply_patch` tool, whose hook payload carries the
45
+ # patch text (`tool_input.command`) rather than a path; its `Edit|Write`
46
+ # matcher selects that tool by alias. These are the patch grammar's
47
+ # file-header lines that name a file left on disk (codex-rs/apply-patch
48
+ # parser.rs: ADD_FILE_MARKER, UPDATE_FILE_MARKER, MOVE_TO_MARKER). Codex
49
+ # accepts an indented Add/Update header (streaming_parser.rs trims the line
50
+ # outside an update hunk) but only a column-0 Move to. Added content starts
51
+ # with `+`, so it can't name a file; an update hunk's context line that quotes
52
+ # a header can, and at worst reindexes an unchanged file.
53
+ _APPLY_PATCH_TARGET = re.compile(
54
+ r"^(?:[ \t]*\*\*\* (?:Add File|Update File)|\*\*\* Move to): (.+)$",
55
+ re.MULTILINE,
56
+ )
57
+
43
58
 
44
59
  def session_init() -> None:
45
60
  """SessionStart: seed/refresh the whole repo's code graph in the background.
@@ -64,6 +79,9 @@ def reindex_hook(payload: str) -> None:
64
79
  before the hook returns. Outside one there is no branch view to contend
65
80
  over and the file is indexed in the foreground, as before.
66
81
 
82
+ Claude Code's payload names one file; Codex's ``apply_patch`` payload
83
+ names every file in the patch, and each is reindexed.
84
+
67
85
  Best-effort: a missing/malformed payload, an untracked tool, or a parse
68
86
  failure all degrade to a silent no-op rather than interrupting the agent.
69
87
  """
@@ -74,14 +92,25 @@ def reindex_hook(payload: str) -> None:
74
92
  tool_input = data.get("tool_input") if isinstance(data, dict) else None
75
93
  if not isinstance(tool_input, dict):
76
94
  return
77
- raw = (
78
- tool_input.get("file_path")
79
- or tool_input.get("path")
80
- or tool_input.get("filename")
81
- )
82
- if not isinstance(raw, str) or not raw:
83
- return
84
-
95
+ if data.get("tool_name") == "apply_patch":
96
+ patch = tool_input.get("command")
97
+ targets = (
98
+ [m.strip() for m in _APPLY_PATCH_TARGET.findall(patch)]
99
+ if isinstance(patch, str)
100
+ else []
101
+ )
102
+ else:
103
+ raw = (
104
+ tool_input.get("file_path")
105
+ or tool_input.get("path")
106
+ or tool_input.get("filename")
107
+ )
108
+ targets = [raw] if isinstance(raw, str) and raw else []
109
+ for raw in targets:
110
+ _reindex_one(raw)
111
+
112
+
113
+ def _reindex_one(raw: str) -> None:
85
114
  path = Path(raw)
86
115
  if not path.is_absolute():
87
116
  path = Path.cwd() / path
File without changes
File without changes
File without changes
File without changes
File without changes