witan-code 0.26.0__tar.gz → 0.27.1__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.26.0 → witan_code-0.27.1}/.gitignore +3 -0
  2. {witan_code-0.26.0 → witan_code-0.27.1}/CHANGELOG.md +41 -0
  3. {witan_code-0.26.0 → witan_code-0.27.1}/PKG-INFO +10 -6
  4. {witan_code-0.26.0 → witan_code-0.27.1}/README.md +8 -4
  5. witan_code-0.27.1/changelog.d/20261023_162839_blarghmatey_witan_code_codex_hooks.md +3 -0
  6. witan_code-0.27.1/changelog.d/20261023_163336_blarghmatey_witan_code_codex_hooks.md +3 -0
  7. {witan_code-0.26.0 → witan_code-0.27.1}/pyproject.toml +8 -3
  8. {witan_code-0.26.0 → witan_code-0.27.1}/tests/conftest.py +24 -0
  9. {witan_code-0.26.0 → witan_code-0.27.1}/tests/test_bridge.py +83 -0
  10. {witan_code-0.26.0 → witan_code-0.27.1}/tests/test_cli_hooks.py +60 -2
  11. {witan_code-0.26.0 → witan_code-0.27.1}/tests/test_context.py +35 -0
  12. {witan_code-0.26.0 → witan_code-0.27.1}/tests/test_hooks.py +100 -5
  13. {witan_code-0.26.0 → witan_code-0.27.1}/tests/test_indexer_scope.py +55 -0
  14. {witan_code-0.26.0 → witan_code-0.27.1}/tests/test_store.py +93 -0
  15. {witan_code-0.26.0 → witan_code-0.27.1}/witan_code/bridge.py +12 -4
  16. {witan_code-0.26.0 → witan_code-0.27.1}/witan_code/cli.py +31 -9
  17. {witan_code-0.26.0 → witan_code-0.27.1}/witan_code/context.py +50 -10
  18. {witan_code-0.26.0 → witan_code-0.27.1}/witan_code/hooks.py +25 -11
  19. {witan_code-0.26.0 → witan_code-0.27.1}/witan_code/indexer.py +40 -6
  20. {witan_code-0.26.0 → witan_code-0.27.1}/witan_code/ingest.py +1 -1
  21. {witan_code-0.26.0 → witan_code-0.27.1}/witan_code/maintenance.py +10 -8
  22. {witan_code-0.26.0 → witan_code-0.27.1}/witan_code/queries/bridge.gq +3 -5
  23. {witan_code-0.26.0 → witan_code-0.27.1}/witan_code/schema/bridge-schema.pg +0 -2
  24. {witan_code-0.26.0 → witan_code-0.27.1}/witan_code/store.py +74 -12
  25. {witan_code-0.26.0 → witan_code-0.27.1}/changelog.d/README.md +0 -0
  26. {witan_code-0.26.0 → witan_code-0.27.1}/config/claude.json +0 -0
  27. {witan_code-0.26.0 → witan_code-0.27.1}/config/copilot.json +0 -0
  28. {witan_code-0.26.0 → witan_code-0.27.1}/config/pi.json +0 -0
  29. {witan_code-0.26.0 → witan_code-0.27.1}/conftest.py +0 -0
  30. {witan_code-0.26.0 → witan_code-0.27.1}/docs/BRANCH_INDEXING.md +0 -0
  31. {witan_code-0.26.0 → witan_code-0.27.1}/docs/CLI_REFERENCE.md +0 -0
  32. {witan_code-0.26.0 → witan_code-0.27.1}/docs/EDGE_PRECISION_TIERS.md +0 -0
  33. {witan_code-0.26.0 → witan_code-0.27.1}/docs/PACKAGE_MAP.md +0 -0
  34. {witan_code-0.26.0 → witan_code-0.27.1}/docs/STAGE2_STITCHING.md +0 -0
  35. {witan_code-0.26.0 → witan_code-0.27.1}/docs/SYMBOL_FORMAT.md +0 -0
  36. {witan_code-0.26.0 → witan_code-0.27.1}/docs/SYMBOL_TABLE.md +0 -0
  37. {witan_code-0.26.0 → witan_code-0.27.1}/docs/USER_GUIDE.md +0 -0
  38. {witan_code-0.26.0 → witan_code-0.27.1}/install.sh +0 -0
  39. {witan_code-0.26.0 → witan_code-0.27.1}/tests/__init__.py +0 -0
  40. {witan_code-0.26.0 → witan_code-0.27.1}/tests/test_batched_deletes.py +0 -0
  41. {witan_code-0.26.0 → witan_code-0.27.1}/tests/test_branches.py +0 -0
  42. {witan_code-0.26.0 → witan_code-0.27.1}/tests/test_chunked_load.py +0 -0
  43. {witan_code-0.26.0 → witan_code-0.27.1}/tests/test_cli_dispatch.py +0 -0
  44. {witan_code-0.26.0 → witan_code-0.27.1}/tests/test_cli_output_format.py +0 -0
  45. {witan_code-0.26.0 → witan_code-0.27.1}/tests/test_cli_selected_target.py +0 -0
  46. {witan_code-0.26.0 → witan_code-0.27.1}/tests/test_config.py +0 -0
  47. {witan_code-0.26.0 → witan_code-0.27.1}/tests/test_config_targets.py +0 -0
  48. {witan_code-0.26.0 → witan_code-0.27.1}/tests/test_crossrepo.py +0 -0
  49. {witan_code-0.26.0 → witan_code-0.27.1}/tests/test_edges.py +0 -0
  50. {witan_code-0.26.0 → witan_code-0.27.1}/tests/test_elicit.py +0 -0
  51. {witan_code-0.26.0 → witan_code-0.27.1}/tests/test_enrichment.py +0 -0
  52. {witan_code-0.26.0 → witan_code-0.27.1}/tests/test_github_app.py +0 -0
  53. {witan_code-0.26.0 → witan_code-0.27.1}/tests/test_graph.py +0 -0
  54. {witan_code-0.26.0 → witan_code-0.27.1}/tests/test_identity.py +0 -0
  55. {witan_code-0.26.0 → witan_code-0.27.1}/tests/test_index_failure_diagnostics.py +0 -0
  56. {witan_code-0.26.0 → witan_code-0.27.1}/tests/test_index_reports_its_store.py +0 -0
  57. {witan_code-0.26.0 → witan_code-0.27.1}/tests/test_index_requires_a_repo_key.py +0 -0
  58. {witan_code-0.26.0 → witan_code-0.27.1}/tests/test_indexer.py +0 -0
  59. {witan_code-0.26.0 → witan_code-0.27.1}/tests/test_ingest.py +0 -0
  60. {witan_code-0.26.0 → witan_code-0.27.1}/tests/test_languages.py +0 -0
  61. {witan_code-0.26.0 → witan_code-0.27.1}/tests/test_maintenance.py +0 -0
  62. {witan_code-0.26.0 → witan_code-0.27.1}/tests/test_package_map.py +0 -0
  63. {witan_code-0.26.0 → witan_code-0.27.1}/tests/test_reaper.py +0 -0
  64. {witan_code-0.26.0 → witan_code-0.27.1}/tests/test_rebuild_honours_the_repo_key.py +0 -0
  65. {witan_code-0.26.0 → witan_code-0.27.1}/tests/test_refusal_audit.py +0 -0
  66. {witan_code-0.26.0 → witan_code-0.27.1}/tests/test_remote_proxy.py +0 -0
  67. {witan_code-0.26.0 → witan_code-0.27.1}/tests/test_remote_store.py +0 -0
  68. {witan_code-0.26.0 → witan_code-0.27.1}/tests/test_repo.py +0 -0
  69. {witan_code-0.26.0 → witan_code-0.27.1}/tests/test_server.py +0 -0
  70. {witan_code-0.26.0 → witan_code-0.27.1}/tests/test_setup.py +0 -0
  71. {witan_code-0.26.0 → witan_code-0.27.1}/tests/test_stitch.py +0 -0
  72. {witan_code-0.26.0 → witan_code-0.27.1}/tests/test_symbol_table.py +0 -0
  73. {witan_code-0.26.0 → witan_code-0.27.1}/tests/test_tasks.py +0 -0
  74. {witan_code-0.26.0 → witan_code-0.27.1}/tests/test_tool_schema.py +0 -0
  75. {witan_code-0.26.0 → witan_code-0.27.1}/tests/test_views.py +0 -0
  76. {witan_code-0.26.0 → witan_code-0.27.1}/tests/test_visualize.py +0 -0
  77. {witan_code-0.26.0 → witan_code-0.27.1}/witan_code/__init__.py +0 -0
  78. {witan_code-0.26.0 → witan_code-0.27.1}/witan_code/__main__.py +0 -0
  79. {witan_code-0.26.0 → witan_code-0.27.1}/witan_code/bridge_extractors.py +0 -0
  80. {witan_code-0.26.0 → witan_code-0.27.1}/witan_code/config.py +0 -0
  81. {witan_code-0.26.0 → witan_code-0.27.1}/witan_code/edges.py +0 -0
  82. {witan_code-0.26.0 → witan_code-0.27.1}/witan_code/elicit.py +0 -0
  83. {witan_code-0.26.0 → witan_code-0.27.1}/witan_code/extensions/pi/codegraph.ts +0 -0
  84. {witan_code-0.26.0 → witan_code-0.27.1}/witan_code/github_app.py +0 -0
  85. {witan_code-0.26.0 → witan_code-0.27.1}/witan_code/graph.py +0 -0
  86. {witan_code-0.26.0 → witan_code-0.27.1}/witan_code/identity.py +0 -0
  87. {witan_code-0.26.0 → witan_code-0.27.1}/witan_code/output.py +0 -0
  88. {witan_code-0.26.0 → witan_code-0.27.1}/witan_code/package_map.py +0 -0
  89. {witan_code-0.26.0 → witan_code-0.27.1}/witan_code/queries/code_mutations.gq +0 -0
  90. {witan_code-0.26.0 → witan_code-0.27.1}/witan_code/queries/code_read.gq +0 -0
  91. {witan_code-0.26.0 → witan_code-0.27.1}/witan_code/queries/delete.gq +0 -0
  92. {witan_code-0.26.0 → witan_code-0.27.1}/witan_code/queries_ts/bash.scm +0 -0
  93. {witan_code-0.26.0 → witan_code-0.27.1}/witan_code/queries_ts/hcl.scm +0 -0
  94. {witan_code-0.26.0 → witan_code-0.27.1}/witan_code/queries_ts/python.scm +0 -0
  95. {witan_code-0.26.0 → witan_code-0.27.1}/witan_code/queries_ts/sql.scm +0 -0
  96. {witan_code-0.26.0 → witan_code-0.27.1}/witan_code/queries_ts/typescript.scm +0 -0
  97. {witan_code-0.26.0 → witan_code-0.27.1}/witan_code/queries_ts/yaml.scm +0 -0
  98. {witan_code-0.26.0 → witan_code-0.27.1}/witan_code/reaper.py +0 -0
  99. {witan_code-0.26.0 → witan_code-0.27.1}/witan_code/remote/__init__.py +0 -0
  100. {witan_code-0.26.0 → witan_code-0.27.1}/witan_code/remote/oidc.py +0 -0
  101. {witan_code-0.26.0 → witan_code-0.27.1}/witan_code/remote/proxy.py +0 -0
  102. {witan_code-0.26.0 → witan_code-0.27.1}/witan_code/remote/store.py +0 -0
  103. {witan_code-0.26.0 → witan_code-0.27.1}/witan_code/repo.py +0 -0
  104. {witan_code-0.26.0 → witan_code-0.27.1}/witan_code/schema/code-schema.pg +0 -0
  105. {witan_code-0.26.0 → witan_code-0.27.1}/witan_code/selected_target.py +0 -0
  106. {witan_code-0.26.0 → witan_code-0.27.1}/witan_code/server.py +0 -0
  107. {witan_code-0.26.0 → witan_code-0.27.1}/witan_code/setup.py +0 -0
  108. {witan_code-0.26.0 → witan_code-0.27.1}/witan_code/skills/witan-code/SKILL.md +0 -0
  109. {witan_code-0.26.0 → witan_code-0.27.1}/witan_code/stitch.py +0 -0
  110. {witan_code-0.26.0 → witan_code-0.27.1}/witan_code/views.py +0 -0
  111. {witan_code-0.26.0 → witan_code-0.27.1}/witan_code/visualize.py +0 -0
@@ -43,3 +43,6 @@ mcp-server.log
43
43
 
44
44
  # Zensical build output for the witan-context docs site.
45
45
  site/
46
+
47
+ # You get this with every apply run.
48
+ agent-config.toml.applied.json
@@ -8,6 +8,47 @@ a MINOR bump may include breaking changes).
8
8
 
9
9
  <!-- scriv-insert-here -->
10
10
 
11
+ ## [0.27.1] - 2026-10-26
12
+
13
+ ### Changed
14
+
15
+ - Requires witan-core 0.46.0, whose device login sends PKCE (`S256`). The
16
+ `witan-cli` Keycloak client will require PKCE, and `witan-code login` on an older
17
+ witan-core will then fail.
18
+
19
+ ## [0.27.0] - 2026-10-21
20
+
21
+ ### Changed
22
+
23
+ - The cleanup that rides a background optimize now keeps 2 days of versions
24
+ instead of 30, matching the deployed nightly cleanup. Nothing reads older
25
+ history, and on omnigraph 0.13 a cleanup's cost grows with every version
26
+ still present ([ModernRelay/omnigraph#1095](https://github.com/ModernRelay/omnigraph/issues/1095)).
27
+ - `witan-code cleanup --yes` with neither `--keep` nor `--older-than` now keeps 2 days
28
+ as well, since it shares the default. Pass `--older-than 30d` to keep the
29
+ old window.
30
+ - A local `_bridge.omni` whose schema omnigraph reports it cannot migrate in
31
+ place (`schema plan` answers `supported: false`) is now deleted and recreated
32
+ instead of failing every apply. It comes back empty. Run
33
+ `witan-code reindex <repo root>` in each indexed repo to restore its
34
+ cross-repo bindings. A local bridge created by 0.26.x hits this on the
35
+ first index after upgrading, because of the schema change under Removed.
36
+ (Shipped in 0.27.0, left out at release.)
37
+ - A bridge write clears the repo's symbol table in the same commit as its
38
+ per-file bindings purge, instead of a separate one. Every index that writes
39
+ bindings now costs the bridge one commit fewer, on a graph whose main branch
40
+ every repo shares and whose commits serialize. (Shipped in 0.27.0, left out
41
+ at release.)
42
+
43
+ ### Removed
44
+
45
+ - `InterfaceBinding.repo_file` is gone from the bridge schema. The per-file
46
+ purge deletes on `repo` and `file` directly, which GQ 2.1 allows. omnigraph
47
+ 0.13 cannot drop the column in place, so a deployed `code-bridge` graph has
48
+ to be recreated and every repo reindexed. Until then, this release's bridge
49
+ writes to that graph fail, because its schema still requires `repo_file`.
50
+ (Shipped in 0.27.0, left out at release.)
51
+
11
52
  ## [0.26.0] - 2026-10-16
12
53
 
13
54
  ### Fixed
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: witan-code
3
- Version: 0.26.0
3
+ Version: 0.27.1
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.43
29
+ Requires-Dist: witan-core[cli,observability,remote,sentry]<1,>=0.46
30
30
  Provides-Extra: tasks
31
31
  Requires-Dist: fastmcp-tasks<5,>=4; extra == 'tasks'
32
32
  Description-Content-Type: text/markdown
@@ -355,7 +355,7 @@ symlink alternative:
355
355
  | `WITAN_AUTHOR` / `USER` | `unknown` | attribution string |
356
356
  | `WITAN_REPO` | — | override the detected repo slug |
357
357
  | `WITAN_CODE_OPTIMIZE_INTERVAL` | `86400` (daily) | throttle window (seconds) for `checkpoint`'s opportunistic store compaction; `0` disables it |
358
- | `WITAN_CODE_CLEANUP_INTERVAL` | `604800` (weekly) | throttle window (seconds) for the `cleanup --older-than 30d` that rides a `checkpoint` compaction; `0` disables it |
358
+ | `WITAN_CODE_CLEANUP_INTERVAL` | `604800` (weekly) | throttle window (seconds) for the `cleanup --older-than 2d` that rides a `checkpoint` compaction; `0` disables it |
359
359
  | `WITAN_CODE_INDEX_ROLE` | `client` | `ci` designates this process the writer of a shared graph's default-branch view. Only meaningful against a shared cluster graph; local stores are unaffected. See [Branch indexing](docs/BRANCH_INDEXING.md#who-may-write-the-shared-default-branch-view) |
360
360
  | `WITAN_ACTOR` | derived from the `witan login` session | the identity that owns the branch views this process writes; an `act-…` id or a raw OIDC `sub`. For a non-interactive writer (CI, a maintenance job). See [Branch indexing](docs/BRANCH_INDEXING.md#per-writer-branch-views) |
361
361
  | `WITAN_CONFIG` | `~/.config/witan/config.toml` | config file path (see below) |
@@ -586,7 +586,7 @@ graph):
586
586
  reclaim disk by GC'ing old Lance versions (**destructive**; requires
587
587
  `--yes`). `--keep N` retains the newest N graph commits of every live
588
588
  branch (omnigraph 0.12+; versions per table on 0.11); with neither bound it
589
- keeps the last 30 days.
589
+ keeps the last 2 days.
590
590
  - `checkpoint` — opportunistically compact the current repo's store and the
591
591
  bridge store if due (see [Hooks](#hooks)); registered as the `Stop` hook,
592
592
  not usually run by hand.
@@ -646,7 +646,7 @@ mechanisms keep this in check, mirroring that module (deliberately duplicated
646
646
  the shared bridge store, at most once per `WITAN_CODE_OPTIMIZE_INTERVAL`
647
647
  (default daily; `0` disables) each — see [Hooks](#hooks). At most once per
648
648
  `WITAN_CODE_CLEANUP_INTERVAL` (default weekly) the run also cleans up
649
- versions older than 30 days. On omnigraph 0.11 that is the only thing that
649
+ versions older than 2 days. On omnigraph 0.11 that is the only thing that
650
650
  reclaims the storage of branches deleted by `branches --prune` or
651
651
  `reap-views --apply`; `optimize` no longer does.
652
652
  - **Scheduled**: `witan-code optimize [--store PATH | --bridge]
@@ -737,7 +737,11 @@ A Pi equivalent of all four lives in one extension,
737
737
  exact `mcp__<server>__` name, then `tools.<name>({...})`), and
738
738
  `--client pi`, which it passes when pi-mcp-adapter's `mcp` tool is
739
739
  registered, gives the adapter's proxy (`mcp({ search: ... })`, then
740
- `mcp({ tool: ..., args: {...} })`). The default stays Claude's.
740
+ `mcp({ tool: ..., args: {...} })`). Codex runs the same bare hook command
741
+ as Claude Code, so without `--client` the block is chosen from the hook's
742
+ stdin payload: a Codex payload (it carries `turn_id`) gets Codex's
743
+ `tool_search` and the `witan-code` skill instead of `ToolSearch` and
744
+ `/witan-code`, and anything else gets Claude's.
741
745
  Independent of `witan`'s own `inject-context` hook (no cross-package
742
746
  coupling) — register it alone for a witan-code-only install. Prints
743
747
  nothing when the repo has neither a store nor an index in flight.
@@ -322,7 +322,7 @@ symlink alternative:
322
322
  | `WITAN_AUTHOR` / `USER` | `unknown` | attribution string |
323
323
  | `WITAN_REPO` | — | override the detected repo slug |
324
324
  | `WITAN_CODE_OPTIMIZE_INTERVAL` | `86400` (daily) | throttle window (seconds) for `checkpoint`'s opportunistic store compaction; `0` disables it |
325
- | `WITAN_CODE_CLEANUP_INTERVAL` | `604800` (weekly) | throttle window (seconds) for the `cleanup --older-than 30d` that rides a `checkpoint` compaction; `0` disables it |
325
+ | `WITAN_CODE_CLEANUP_INTERVAL` | `604800` (weekly) | throttle window (seconds) for the `cleanup --older-than 2d` that rides a `checkpoint` compaction; `0` disables it |
326
326
  | `WITAN_CODE_INDEX_ROLE` | `client` | `ci` designates this process the writer of a shared graph's default-branch view. Only meaningful against a shared cluster graph; local stores are unaffected. See [Branch indexing](docs/BRANCH_INDEXING.md#who-may-write-the-shared-default-branch-view) |
327
327
  | `WITAN_ACTOR` | derived from the `witan login` session | the identity that owns the branch views this process writes; an `act-…` id or a raw OIDC `sub`. For a non-interactive writer (CI, a maintenance job). See [Branch indexing](docs/BRANCH_INDEXING.md#per-writer-branch-views) |
328
328
  | `WITAN_CONFIG` | `~/.config/witan/config.toml` | config file path (see below) |
@@ -553,7 +553,7 @@ graph):
553
553
  reclaim disk by GC'ing old Lance versions (**destructive**; requires
554
554
  `--yes`). `--keep N` retains the newest N graph commits of every live
555
555
  branch (omnigraph 0.12+; versions per table on 0.11); with neither bound it
556
- keeps the last 30 days.
556
+ keeps the last 2 days.
557
557
  - `checkpoint` — opportunistically compact the current repo's store and the
558
558
  bridge store if due (see [Hooks](#hooks)); registered as the `Stop` hook,
559
559
  not usually run by hand.
@@ -613,7 +613,7 @@ mechanisms keep this in check, mirroring that module (deliberately duplicated
613
613
  the shared bridge store, at most once per `WITAN_CODE_OPTIMIZE_INTERVAL`
614
614
  (default daily; `0` disables) each — see [Hooks](#hooks). At most once per
615
615
  `WITAN_CODE_CLEANUP_INTERVAL` (default weekly) the run also cleans up
616
- versions older than 30 days. On omnigraph 0.11 that is the only thing that
616
+ versions older than 2 days. On omnigraph 0.11 that is the only thing that
617
617
  reclaims the storage of branches deleted by `branches --prune` or
618
618
  `reap-views --apply`; `optimize` no longer does.
619
619
  - **Scheduled**: `witan-code optimize [--store PATH | --bridge]
@@ -704,7 +704,11 @@ A Pi equivalent of all four lives in one extension,
704
704
  exact `mcp__<server>__` name, then `tools.<name>({...})`), and
705
705
  `--client pi`, which it passes when pi-mcp-adapter's `mcp` tool is
706
706
  registered, gives the adapter's proxy (`mcp({ search: ... })`, then
707
- `mcp({ tool: ..., args: {...} })`). The default stays Claude's.
707
+ `mcp({ tool: ..., args: {...} })`). Codex runs the same bare hook command
708
+ as Claude Code, so without `--client` the block is chosen from the hook's
709
+ stdin payload: a Codex payload (it carries `turn_id`) gets Codex's
710
+ `tool_search` and the `witan-code` skill instead of `ToolSearch` and
711
+ `/witan-code`, and anything else gets Claude's.
708
712
  Independent of `witan`'s own `inject-context` hook (no cross-package
709
713
  coupling) — register it alone for a witan-code-only install. Prints
710
714
  nothing when the repo has neither a store nor an index in flight.
@@ -0,0 +1,3 @@
1
+ ### Fixed
2
+
3
+ - `reindex-hook` purges files a Codex `apply_patch` deletes or renames away. It read only the headers naming a file left on disk, so a `*** Delete File:` path and the `*** Update File:` source of a `*** Move to:` kept their symbols in the graph until the next SessionStart full refresh, and `code_find_definition` went on returning the old path. The hook now queues those paths too, and indexing a file that is no longer on disk (`index_path`, which the hook's drainer calls) drops its rows and its cross-repo bindings. The drainer used to skip a queued file deleted before it ran; it now purges it the same way.
@@ -0,0 +1,3 @@
1
+ ### Fixed
2
+
3
+ - `inject-context` gives Codex guidance for tools Codex has. `witan-code setup` registers one bare `UserPromptSubmit` hook for Claude Code and Codex, so Codex got Claude's block, which says to load the `code_*` tools with `ToolSearch` and to run `/witan-code`; Codex has neither. Without `--client`, the command now reads the hook's stdin payload, and a Codex payload (it carries `turn_id`) gets Codex's `tool_search` call and a pointer to the `witan-code` skill. Any other payload, or none, gets the Claude block as before. `--client codex` selects the Codex block explicitly.
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "witan-code"
3
- version = "0.26.0"
3
+ version = "0.27.1"
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"
@@ -183,7 +183,12 @@ dependencies = [
183
183
  # prints only from 0.43.0. On 0.42 `--agent codex` is rejected as an
184
184
  # invalid value, and `--agent all` writes the reindex hook to Codex
185
185
  # without the notice.
186
- "witan-core[cli,remote,observability,sentry]>=0.43,<1",
186
+ #
187
+ # ★ >=0.46 IS A BEHAVIOUR FLOOR: the device login in `witan_core.remote.oidc`
188
+ # sends PKCE (`S256`) only from 0.46.0, and the `witan-cli` Keycloak client
189
+ # is switched to require it once that is out. 0.45 imports and runs, then
190
+ # every `witan-code login` is refused by Keycloak.
191
+ "witan-core[cli,remote,observability,sentry]>=0.46,<1",
187
192
  "fastmcp>=4,<5",
188
193
  "cyclopts>=4,<6",
189
194
  # [targets.<name>] override models (config.py) — also transitively pulled
@@ -266,7 +271,7 @@ testpaths = ["tests"]
266
271
  packages = ["witan_code"]
267
272
 
268
273
  [tool.bumpversion]
269
- current_version = "0.26.0"
274
+ current_version = "0.27.1"
270
275
  allow_dirty = true
271
276
 
272
277
  [[tool.bumpversion.files]]
@@ -127,3 +127,27 @@ def sample_repo(tmp_path, monkeypatch):
127
127
  src.mkdir()
128
128
  (src / "svc.py").write_text(SAMPLE)
129
129
  return src
130
+
131
+
132
+ # Field sets of each agent's UserPromptSubmit stdin payload: Codex's from
133
+ # `UserPromptSubmitCommandInput` (codex-rs/hooks/src/schema.rs at
134
+ # rust-v0.162.1), Claude Code's from its hooks reference. `turn_id` is the
135
+ # Codex extension that tells them apart.
136
+ CODEX_PROMPT_PAYLOAD = {
137
+ "session_id": "019a1b2c-3d4e-7f00-8a9b-0c1d2e3f4a5b",
138
+ "turn_id": "1",
139
+ "transcript_path": None,
140
+ "cwd": "/work/repo",
141
+ "hook_event_name": "UserPromptSubmit",
142
+ "model": "gpt-5-codex",
143
+ "permission_mode": "default",
144
+ "prompt": "where is helper defined?",
145
+ }
146
+ CLAUDE_PROMPT_PAYLOAD = {
147
+ "session_id": "abc123",
148
+ "transcript_path": "/home/u/.claude/projects/x/abc123.jsonl",
149
+ "cwd": "/work/repo",
150
+ "permission_mode": "default",
151
+ "hook_event_name": "UserPromptSubmit",
152
+ "prompt": "where is helper defined?",
153
+ }
@@ -737,3 +737,86 @@ def test_incremental_index_preserves_unchanged_file_bindings(tmp_path, monkeypat
737
737
  (base / "b.ts").unlink()
738
738
  indexer.index_path(base, config=cfg)
739
739
  assert binding_files() == {"a.ts"}
740
+
741
+
742
+ @requires_stack
743
+ def test_bridge_purge_and_symbol_reset_are_one_commit(tmp_path, monkeypatch):
744
+ """The bindings purge and the repo's symbol-table reset used to be two
745
+ bridge commits on every index. Bridge main is one serialized commit lane
746
+ shared by every repo, so they now land as one; the load is the other."""
747
+ from witan_code import config as cfg_mod
748
+ from witan_code import indexer
749
+ from witan_code.graph import OmnigraphClient
750
+
751
+ monkeypatch.setenv("WITAN_REPO", "https://github.com/test/commits")
752
+ monkeypatch.setenv("WITAN_CODE_DIR", str(tmp_path / "code"))
753
+ cfg = cfg_mod.load()
754
+ base = tmp_path / "repo"
755
+ base.mkdir()
756
+ (base / "a.ts").write_text('const a = fetch("/api/v0/aaa/");\n')
757
+ indexer.index_path(base, config=cfg)
758
+
759
+ commits: list[str] = []
760
+ inside = {"batch": 0}
761
+ real_change = OmnigraphClient.change
762
+ real_change_many = OmnigraphClient.change_many
763
+
764
+ # Depth-guarded like witan's `commits` fixture: a one-step `change_many`
765
+ # delegates to `change`, which must not count twice.
766
+ def change(self, query_file, query_name, *args, **kwargs):
767
+ if query_file == "bridge.gq" and not inside["batch"]:
768
+ commits.append(query_name)
769
+ return real_change(self, query_file, query_name, *args, **kwargs)
770
+
771
+ def change_many(self, steps, *args, **kwargs):
772
+ if steps and steps[0][0] == "bridge.gq" and not inside["batch"]:
773
+ commits.append("+".join(sorted({name for _f, name, _p in steps})))
774
+ inside["batch"] += 1
775
+ try:
776
+ return real_change_many(self, steps, *args, **kwargs)
777
+ finally:
778
+ inside["batch"] -= 1
779
+
780
+ monkeypatch.setattr(OmnigraphClient, "change", change)
781
+ monkeypatch.setattr(OmnigraphClient, "change_many", change_many)
782
+
783
+ (base / "a.ts").write_text('const a = fetch("/api/v0/aaa2/");\n')
784
+ indexer.index_path(base, config=cfg)
785
+
786
+ assert commits == ["delete_bindings_in_file+delete_repo_symbols"], commits
787
+
788
+
789
+ @requires_stack
790
+ def test_the_per_file_purge_is_scoped_to_its_repo(tmp_path, monkeypatch):
791
+ """The purge deletes on repo AND file. Two repos share a path here, so a
792
+ delete on the file alone would take the other repo's binding with it."""
793
+ from witan_code import config as cfg_mod
794
+ from witan_code import indexer
795
+ from witan_code.graph import OmnigraphClient
796
+
797
+ monkeypatch.setenv("WITAN_CODE_DIR", str(tmp_path / "code"))
798
+ cfg = cfg_mod.load()
799
+ repo_a = "https://github.com/test/repo-a"
800
+ repos = {repo_a: tmp_path / "a", "https://github.com/test/repo-b": tmp_path / "b"}
801
+ for uri, base in repos.items():
802
+ base.mkdir()
803
+ (base / "client.ts").write_text('const a = fetch("/api/v0/shared/");\n')
804
+ (base / "other.ts").write_text('const b = fetch("/api/v0/other/");\n')
805
+ indexer.index_path(base, repo_override=uri, config=cfg)
806
+
807
+ def client_ts_repos():
808
+ client = OmnigraphClient(
809
+ str(cfg_mod.bridge_store_path(cfg.code_dir)), cfg.queries_dir
810
+ )
811
+ return {
812
+ r["repo"]
813
+ for r in client.read("bridge.gq", "all_bindings", {})
814
+ if r["file"] == "client.ts"
815
+ }
816
+
817
+ assert client_ts_repos() == set(repos)
818
+
819
+ (repos[repo_a] / "client.ts").unlink()
820
+ indexer.index_path(repos[repo_a], repo_override=repo_a, config=cfg)
821
+
822
+ assert client_ts_repos() == {"https://github.com/test/repo-b"}
@@ -5,6 +5,10 @@ exception escape (the hooks are documented as "always exits 0"), and must
5
5
  not print an extra trailing newline beyond what the backend already returns.
6
6
  """
7
7
 
8
+ import io
9
+ import json
10
+ import sys
11
+
8
12
  import pytest
9
13
 
10
14
  from witan_code import cli
@@ -64,8 +68,62 @@ def test_inject_context_cmd_defaults_to_the_claude_client(monkeypatch, capsys):
64
68
  assert seen == ["claude"]
65
69
 
66
70
 
67
- @pytest.mark.parametrize("client", ["pi", "pi-builtin"])
68
- def test_inject_context_cmd_passes_an_explicit_pi_client_through(monkeypatch, client):
71
+ def _stdin(monkeypatch, payload: dict) -> None:
72
+ """Hand the command a hook payload on a closed, non-tty stdin."""
73
+ monkeypatch.setattr(sys, "stdin", io.StringIO(json.dumps(payload)))
74
+
75
+
76
+ def _run_bare(monkeypatch) -> list[str]:
77
+ import witan_code.context as context_module
78
+
79
+ seen = []
80
+ monkeypatch.setattr(
81
+ context_module, "inject_context", lambda client: seen.append(client) or ""
82
+ )
83
+ command, bound, _ = cli.app.parse_args(["inject-context"])
84
+ command(*bound.args, **bound.kwargs)
85
+ return seen
86
+
87
+
88
+ def test_the_bare_command_renders_for_codex_from_a_codex_payload(monkeypatch):
89
+ """One hook command is registered for Claude Code and Codex alike, so the
90
+ payload is what picks the block."""
91
+ from .conftest import CODEX_PROMPT_PAYLOAD
92
+
93
+ _stdin(monkeypatch, CODEX_PROMPT_PAYLOAD)
94
+
95
+ assert _run_bare(monkeypatch) == ["codex"]
96
+
97
+
98
+ def test_the_bare_command_stays_claude_for_a_claude_payload(monkeypatch):
99
+ from .conftest import CLAUDE_PROMPT_PAYLOAD
100
+
101
+ _stdin(monkeypatch, CLAUDE_PROMPT_PAYLOAD)
102
+
103
+ assert _run_bare(monkeypatch) == ["claude"]
104
+
105
+
106
+ def test_an_explicit_client_does_not_read_stdin(monkeypatch):
107
+ """The Pi extension passes `--client`; its stdin is not a hook payload."""
108
+ import witan_code.context as context_module
109
+
110
+ from .conftest import CODEX_PROMPT_PAYLOAD
111
+
112
+ _stdin(monkeypatch, CODEX_PROMPT_PAYLOAD)
113
+ seen = []
114
+ monkeypatch.setattr(
115
+ context_module, "inject_context", lambda client: seen.append(client) or ""
116
+ )
117
+
118
+ command, bound, _ = cli.app.parse_args(["inject-context", "--client", "pi"])
119
+ command(*bound.args, **bound.kwargs)
120
+
121
+ assert seen == ["pi"]
122
+ assert sys.stdin.read() != "" # left unread
123
+
124
+
125
+ @pytest.mark.parametrize("client", ["codex", "pi", "pi-builtin"])
126
+ def test_inject_context_cmd_passes_an_explicit_client_through(monkeypatch, client):
69
127
  import witan_code.context as context_module
70
128
 
71
129
  seen = []
@@ -5,6 +5,7 @@ tests exercise context.py's own orchestration (repo detection, lock-file
5
5
  check, store-exists branching), not the underlying query.
6
6
  """
7
7
 
8
+ import json
8
9
  import os
9
10
  import shutil
10
11
  import subprocess
@@ -16,6 +17,8 @@ import pytest
16
17
 
17
18
  from witan_code import context
18
19
 
20
+ from .conftest import CLAUDE_PROMPT_PAYLOAD, CODEX_PROMPT_PAYLOAD
21
+
19
22
 
20
23
  def _lock(tmp_path, monkeypatch, project_dir):
21
24
  """The busy marker `indexing_in_progress` reads; create it to fake a run."""
@@ -463,3 +466,35 @@ def test_inject_context_for_pi_names_the_mcp_proxy_not_toolsearch(
463
466
  assert "https://github.com/test/cg" in text
464
467
  assert "3 files" in text
465
468
  assert "No other repo is indexed" in text
469
+
470
+
471
+ # ── Codex ─────────────────────────────────────────────────────────────────────
472
+
473
+
474
+ def test_a_codex_payload_selects_the_codex_client():
475
+ assert context.client_from_payload(json.dumps(CODEX_PROMPT_PAYLOAD)) == "codex"
476
+
477
+
478
+ @pytest.mark.parametrize(
479
+ "payload", [json.dumps(CLAUDE_PROMPT_PAYLOAD), "", "not json", "[1]"]
480
+ )
481
+ def test_anything_but_a_codex_payload_selects_claude(payload):
482
+ assert context.client_from_payload(payload) == "claude"
483
+
484
+
485
+ def test_inject_context_for_codex_names_tools_codex_has(tmp_path, monkeypatch):
486
+ """Codex has no `ToolSearch` and no `/witan-code` command. It defers MCP
487
+ tools behind `tool_search` when the model supports one, and lists them
488
+ directly otherwise, so the search is the fallback for unlisted tools."""
489
+ _indexed(tmp_path, monkeypatch)
490
+
491
+ text = context.inject_context(client="codex")
492
+
493
+ assert "ToolSearch" not in text
494
+ assert "/witan-code" not in text
495
+ assert 'tool_search(query="code_find_definition callers impact")' in text
496
+ assert "`witan-code` skill" in text
497
+ # The status lines above the discovery line are client-neutral.
498
+ assert "https://github.com/test/cg" in text
499
+ assert "3 files" in text
500
+ assert len(text) < 600 # same budget as the Claude block
@@ -8,6 +8,7 @@ or a real detached drainer. The lock itself is real: a kernel flock.
8
8
 
9
9
  import json
10
10
  import os
11
+ import shutil
11
12
  import subprocess
12
13
  import sys
13
14
  import tempfile
@@ -16,6 +17,8 @@ import pytest
16
17
 
17
18
  from witan_code import context, hooks
18
19
 
20
+ from .conftest import requires_stack
21
+
19
22
 
20
23
  @pytest.fixture
21
24
  def _state(tmp_path, monkeypatch):
@@ -132,11 +135,20 @@ def test_reindex_hook_noop_without_tool_input(_indexed):
132
135
  assert _indexed == []
133
136
 
134
137
 
135
- def test_reindex_hook_noop_when_file_missing(tmp_path, _indexed):
136
- hooks.reindex_hook(_payload(tmp_path / "does-not-exist.py"))
138
+ def test_reindex_hook_noop_when_a_file_it_never_indexed_is_missing(tmp_path, _indexed):
139
+ hooks.reindex_hook(_payload(tmp_path / "does-not-exist.md"))
137
140
  assert _indexed == []
138
141
 
139
142
 
143
+ def test_reindex_hook_purges_a_missing_source_file(tmp_path, _indexed):
144
+ """Gone from disk, so indexing it as it is now drops its rows."""
145
+ gone = tmp_path / "does-not-exist.py"
146
+
147
+ hooks.reindex_hook(_payload(gone))
148
+
149
+ assert _indexed == [gone]
150
+
151
+
140
152
  def test_reindex_hook_outside_a_repo_indexes_in_the_foreground(tmp_path, _indexed):
141
153
  target = tmp_path / "a.py"
142
154
  target.write_text("def f(): pass")
@@ -202,7 +214,7 @@ def _codex_post_tool_use(cwd, patch: str) -> str:
202
214
  )
203
215
 
204
216
 
205
- def test_reindex_hook_reads_every_file_a_codex_patch_leaves(
217
+ def test_reindex_hook_reads_every_file_a_codex_patch_names(
206
218
  tmp_path, monkeypatch, _indexed
207
219
  ):
208
220
  monkeypatch.chdir(tmp_path)
@@ -228,10 +240,13 @@ def test_reindex_hook_reads_every_file_a_codex_patch_leaves(
228
240
 
229
241
  hooks.reindex_hook(_codex_post_tool_use(tmp_path, patch))
230
242
 
243
+ # old.py and deleted.py are gone, so these two calls purge them.
231
244
  assert _indexed == [
232
245
  tmp_path / "added.py",
233
246
  tmp_path / "updated.py",
247
+ tmp_path / "old.py",
234
248
  tmp_path / "moved.py",
249
+ tmp_path / "deleted.py",
235
250
  ]
236
251
 
237
252
 
@@ -333,15 +348,34 @@ def test_drain_pending_marks_the_checkout_busy_while_it_works(_repo, monkeypatch
333
348
  assert context.indexing_in_progress() is False
334
349
 
335
350
 
336
- def test_drain_pending_skips_a_target_deleted_since_it_was_queued(_repo, _indexed):
351
+ def test_drain_pending_purges_a_target_deleted_since_it_was_queued(_repo, _indexed):
337
352
  hooks._enqueue(_repo, _repo / "gone.py")
338
353
 
339
354
  hooks.drain_pending(_repo, hooks._try_lock(_repo))
340
355
 
341
- assert _indexed == []
356
+ assert _indexed == [_repo / "gone.py"]
342
357
  assert not hooks._has_pending(_repo)
343
358
 
344
359
 
360
+ def test_drain_pending_skips_a_deleted_target_it_never_indexed(_repo, _indexed):
361
+ hooks._enqueue(_repo, _repo / "gone.md")
362
+
363
+ hooks.drain_pending(_repo, hooks._try_lock(_repo))
364
+
365
+ assert _indexed == []
366
+
367
+
368
+ def test_drain_pending_skips_targets_of_a_removed_checkout(_repo, _indexed):
369
+ """git would resolve them against whatever repo encloses the old path."""
370
+ hooks._enqueue(_repo, _repo / "gone.py")
371
+ lock_fd = hooks._try_lock(_repo)
372
+ shutil.rmtree(_repo)
373
+
374
+ hooks.drain_pending(_repo, lock_fd)
375
+
376
+ assert _indexed == []
377
+
378
+
345
379
  def test_drain_pending_continues_past_a_failing_target(_repo, monkeypatch):
346
380
  a, b = _repo / "a.py", _repo / "b.py"
347
381
  for path in (a, b):
@@ -441,3 +475,64 @@ def test_a_path_with_a_newline_is_not_queued(_repo):
441
475
  hooks._enqueue(_repo, _repo / "a\nb.py")
442
476
 
443
477
  assert not hooks._has_pending(_repo)
478
+
479
+
480
+ # ── End to end: a Codex patch that deletes and renames ───────────────────────
481
+
482
+
483
+ @requires_stack
484
+ def test_a_codex_patch_that_deletes_and_renames_leaves_neither_old_path(
485
+ tmp_path, monkeypatch, _state, _spawned
486
+ ):
487
+ """The hook queues, the drainer applies, and the graph ends up matching
488
+ the disk: nothing left at the deleted path or at the rename's source."""
489
+ from witan_code import config as cfg_mod
490
+ from witan_code import indexer
491
+ from witan_code import store as store_mod
492
+ from witan_code.graph import OmnigraphClient
493
+
494
+ monkeypatch.setenv("WITAN_REPO", "https://github.com/test/cg")
495
+ monkeypatch.setenv("WITAN_CODE_DIR", str(tmp_path / "code"))
496
+ src = tmp_path / "repo"
497
+ (src / "pkg").mkdir(parents=True)
498
+ subprocess.run(["git", "init", "-q", "-b", "main"], cwd=src, check=True)
499
+ (src / "keep.py").write_text("def keep():\n return 1\n")
500
+ (src / "deleted.py").write_text("def deleted():\n return 1\n")
501
+ (src / "pkg" / "old.py").write_text("def renamed():\n return 1\n")
502
+ cfg = cfg_mod.load()
503
+ indexer.index_path(src, config=cfg)
504
+ client = OmnigraphClient(
505
+ str(store_mod.store_for_repo("https://github.com/test/cg", cfg)),
506
+ cfg.queries_dir,
507
+ )
508
+
509
+ def _files() -> set[str]:
510
+ rows = client.read("code_read.gq", "all_file_hashes", {})
511
+ return {r["slug"].split("#", 1)[1] for r in rows}
512
+
513
+ assert _files() == {"keep.py", "deleted.py", "pkg/old.py"}
514
+
515
+ # What Codex's apply_patch leaves on disk; the hook runs after it. The
516
+ # rename empties pkg/, so the directory goes too.
517
+ (src / "deleted.py").unlink()
518
+ (src / "new.py").write_text((src / "pkg" / "old.py").read_text())
519
+ (src / "pkg" / "old.py").unlink()
520
+ (src / "pkg").rmdir()
521
+ monkeypatch.chdir(src)
522
+ patch = (
523
+ "*** Begin Patch\n"
524
+ "*** Delete File: deleted.py\n"
525
+ "*** Update File: pkg/old.py\n"
526
+ "*** Move to: new.py\n"
527
+ "*** End Patch\n"
528
+ )
529
+
530
+ hooks.reindex_hook(_codex_post_tool_use(src, patch))
531
+ assert _spawned # stubbed, so the drainer runs in-process below
532
+ checkout = hooks.repo_module.root(src)
533
+ hooks.drain_pending(checkout, hooks._try_lock(checkout))
534
+
535
+ assert _files() == {"keep.py", "new.py"}
536
+ renamed = client.read("code_read.gq", "find_by_name", {"name": "renamed"})
537
+ assert [r["file_id"].split("#", 1)[1] for r in renamed] == ["new.py"]
538
+ assert client.read("code_read.gq", "find_by_name", {"name": "deleted"}) == []
@@ -532,3 +532,58 @@ def test_index_path_passes_the_view_it_wrote_to_the_purge_gate(tmp_path, monkeyp
532
532
 
533
533
  assert seen["branch"] == "act-alice/feature_x"
534
534
  assert seen["actor"] == "act-alice"
535
+
536
+
537
+ # ── A single file that is gone from disk ─────────────────────────────────────
538
+
539
+
540
+ @requires_stack
541
+ def test_indexing_a_deleted_file_clears_its_bridge_bindings(tmp_path, monkeypatch):
542
+ """The per-edit hook indexes a file an agent deleted. Its cross-repo
543
+ bindings must go with its rows, or the bridge keeps reporting a consumer
544
+ that no longer exists."""
545
+ from witan_code import config as cfg_mod
546
+ from witan_code.graph import OmnigraphClient
547
+
548
+ src = _repo(tmp_path, monkeypatch)
549
+ (src / "settings.py").write_text(
550
+ 'import os\nVALUE = os.getenv("WITAN_CODE_GONE_VAR")\n'
551
+ )
552
+ cfg = cfg_mod.load()
553
+ indexer.index_path(src, config=cfg)
554
+ bridge = OmnigraphClient(
555
+ str(cfg_mod.bridge_store_path(cfg.code_dir)), cfg.queries_dir
556
+ )
557
+
558
+ def _binding_files() -> set[str]:
559
+ rows = bridge.read("bridge.gq", "all_bindings", {})
560
+ return {r["file"] for r in rows if r["key_norm"] == "WITAN_CODE_GONE_VAR"}
561
+
562
+ assert _binding_files() == {"settings.py"}
563
+
564
+ (src / "settings.py").unlink()
565
+ stats = indexer.index_path(src / "settings.py", config=cfg)
566
+
567
+ assert stats.purged == 1
568
+ assert _binding_files() == set()
569
+
570
+
571
+ @requires_stack
572
+ def test_a_deleted_file_outside_a_git_root_purges_nothing(tmp_path, monkeypatch):
573
+ """`_may_purge`'s guard, for the single-file case: with no git root the
574
+ path is relative to whatever directory is nearest, so under a WITAN_REPO
575
+ override it can name a different file that is still in the repo."""
576
+ from witan_code import config as cfg_mod
577
+ from witan_code import store as store_mod
578
+
579
+ src = _repo(tmp_path, monkeypatch)
580
+ cfg = cfg_mod.load()
581
+ indexer.index_path(src, config=cfg)
582
+ store = store_mod.store_for_repo("https://github.com/test/cg", cfg)
583
+ elsewhere = tmp_path / "scratch" # not a git checkout
584
+ elsewhere.mkdir()
585
+
586
+ stats = indexer.index_path(elsewhere / "a.py", config=cfg)
587
+
588
+ assert stats.purged == 0
589
+ assert _files(store, cfg) == {"a.py"}