witan-code 0.27.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.
- {witan_code-0.27.0 → witan_code-0.27.1}/CHANGELOG.md +29 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/PKG-INFO +7 -3
- {witan_code-0.27.0 → witan_code-0.27.1}/README.md +5 -1
- witan_code-0.27.1/changelog.d/20261023_162839_blarghmatey_witan_code_codex_hooks.md +3 -0
- witan_code-0.27.1/changelog.d/20261023_163336_blarghmatey_witan_code_codex_hooks.md +3 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/pyproject.toml +8 -3
- {witan_code-0.27.0 → witan_code-0.27.1}/tests/conftest.py +24 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/tests/test_cli_hooks.py +60 -2
- {witan_code-0.27.0 → witan_code-0.27.1}/tests/test_context.py +35 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/tests/test_hooks.py +100 -5
- {witan_code-0.27.0 → witan_code-0.27.1}/tests/test_indexer_scope.py +55 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/witan_code/cli.py +30 -8
- {witan_code-0.27.0 → witan_code-0.27.1}/witan_code/context.py +50 -10
- {witan_code-0.27.0 → witan_code-0.27.1}/witan_code/hooks.py +25 -11
- {witan_code-0.27.0 → witan_code-0.27.1}/witan_code/indexer.py +40 -6
- witan_code-0.27.0/changelog.d/20261021_142050_blarghmatey_witan_code_drop_bridge_repo_file.md +0 -14
- witan_code-0.27.0/changelog.d/20261021_143525_blarghmatey_witan_coalesce_hot_writes.md +0 -6
- {witan_code-0.27.0 → witan_code-0.27.1}/.gitignore +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/changelog.d/README.md +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/config/claude.json +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/config/copilot.json +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/config/pi.json +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/conftest.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/docs/BRANCH_INDEXING.md +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/docs/CLI_REFERENCE.md +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/docs/EDGE_PRECISION_TIERS.md +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/docs/PACKAGE_MAP.md +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/docs/STAGE2_STITCHING.md +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/docs/SYMBOL_FORMAT.md +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/docs/SYMBOL_TABLE.md +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/docs/USER_GUIDE.md +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/install.sh +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/tests/__init__.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/tests/test_batched_deletes.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/tests/test_branches.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/tests/test_bridge.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/tests/test_chunked_load.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/tests/test_cli_dispatch.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/tests/test_cli_output_format.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/tests/test_cli_selected_target.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/tests/test_config.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/tests/test_config_targets.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/tests/test_crossrepo.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/tests/test_edges.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/tests/test_elicit.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/tests/test_enrichment.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/tests/test_github_app.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/tests/test_graph.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/tests/test_identity.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/tests/test_index_failure_diagnostics.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/tests/test_index_reports_its_store.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/tests/test_index_requires_a_repo_key.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/tests/test_indexer.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/tests/test_ingest.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/tests/test_languages.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/tests/test_maintenance.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/tests/test_package_map.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/tests/test_reaper.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/tests/test_rebuild_honours_the_repo_key.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/tests/test_refusal_audit.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/tests/test_remote_proxy.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/tests/test_remote_store.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/tests/test_repo.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/tests/test_server.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/tests/test_setup.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/tests/test_stitch.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/tests/test_store.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/tests/test_symbol_table.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/tests/test_tasks.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/tests/test_tool_schema.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/tests/test_views.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/tests/test_visualize.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/witan_code/__init__.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/witan_code/__main__.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/witan_code/bridge.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/witan_code/bridge_extractors.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/witan_code/config.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/witan_code/edges.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/witan_code/elicit.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/witan_code/extensions/pi/codegraph.ts +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/witan_code/github_app.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/witan_code/graph.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/witan_code/identity.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/witan_code/ingest.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/witan_code/maintenance.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/witan_code/output.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/witan_code/package_map.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/witan_code/queries/bridge.gq +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/witan_code/queries/code_mutations.gq +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/witan_code/queries/code_read.gq +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/witan_code/queries/delete.gq +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/witan_code/queries_ts/bash.scm +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/witan_code/queries_ts/hcl.scm +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/witan_code/queries_ts/python.scm +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/witan_code/queries_ts/sql.scm +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/witan_code/queries_ts/typescript.scm +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/witan_code/queries_ts/yaml.scm +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/witan_code/reaper.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/witan_code/remote/__init__.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/witan_code/remote/oidc.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/witan_code/remote/proxy.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/witan_code/remote/store.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/witan_code/repo.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/witan_code/schema/bridge-schema.pg +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/witan_code/schema/code-schema.pg +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/witan_code/selected_target.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/witan_code/server.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/witan_code/setup.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/witan_code/skills/witan-code/SKILL.md +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/witan_code/stitch.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/witan_code/store.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/witan_code/views.py +0 -0
- {witan_code-0.27.0 → witan_code-0.27.1}/witan_code/visualize.py +0 -0
|
@@ -8,6 +8,14 @@ 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
|
+
|
|
11
19
|
## [0.27.0] - 2026-10-21
|
|
12
20
|
|
|
13
21
|
### Changed
|
|
@@ -19,6 +27,27 @@ a MINOR bump may include breaking changes).
|
|
|
19
27
|
- `witan-code cleanup --yes` with neither `--keep` nor `--older-than` now keeps 2 days
|
|
20
28
|
as well, since it shares the default. Pass `--older-than 30d` to keep the
|
|
21
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.)
|
|
22
51
|
|
|
23
52
|
## [0.26.0] - 2026-10-16
|
|
24
53
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: witan-code
|
|
3
|
-
Version: 0.27.
|
|
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.
|
|
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
|
|
@@ -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: {...} })`).
|
|
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.
|
|
@@ -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: {...} })`).
|
|
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.27.
|
|
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
|
-
|
|
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.27.
|
|
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
|
+
}
|
|
@@ -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
|
-
|
|
68
|
-
|
|
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
|
|
136
|
-
hooks.reindex_hook(_payload(tmp_path / "does-not-exist.
|
|
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
|
|
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
|
|
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"}
|
|
@@ -592,7 +592,7 @@ def stitch(repo: str | None = None, *, unresolved: bool = False) -> None:
|
|
|
592
592
|
|
|
593
593
|
@app.command(name="inject-context")
|
|
594
594
|
def inject_context_cmd(
|
|
595
|
-
*, client: Literal["claude", "pi", "pi-builtin"] =
|
|
595
|
+
*, client: Literal["claude", "codex", "pi", "pi-builtin"] | None = None
|
|
596
596
|
) -> None:
|
|
597
597
|
"""Print a short code-graph status block for the UserPromptSubmit hook.
|
|
598
598
|
|
|
@@ -604,18 +604,22 @@ def inject_context_cmd(
|
|
|
604
604
|
----------
|
|
605
605
|
client
|
|
606
606
|
Which agent the block's tool-discovery instructions are written for:
|
|
607
|
-
``claude`` (``ToolSearch
|
|
608
|
-
``codemode`` script, for Pi's built-in MCP), or
|
|
609
|
-
(pi-mcp-adapter's ``mcp`` proxy). The Pi extension passes
|
|
607
|
+
``claude`` (``ToolSearch``), ``codex`` (``tool_search``),
|
|
608
|
+
``pi-builtin`` (a ``codemode`` script, for Pi's built-in MCP), or
|
|
609
|
+
``pi`` (pi-mcp-adapter's ``mcp`` proxy). The Pi extension passes
|
|
610
610
|
``--client pi`` when the adapter's ``mcp`` tool is registered and
|
|
611
|
-
``--client pi-builtin`` otherwise
|
|
612
|
-
|
|
611
|
+
``--client pi-builtin`` otherwise. Omitted, as in the hook Claude
|
|
612
|
+
Code and Codex share, it is read off the hook's stdin payload:
|
|
613
|
+
``codex`` for a Codex payload, ``claude`` for anything else. Nothing
|
|
614
|
+
is inferred from the environment.
|
|
613
615
|
"""
|
|
614
616
|
import sys
|
|
615
617
|
|
|
616
618
|
from . import context as context_module
|
|
617
619
|
|
|
618
620
|
try:
|
|
621
|
+
if client is None:
|
|
622
|
+
client = context_module.client_from_payload(_hook_stdin())
|
|
619
623
|
text = context_module.inject_context(client=client)
|
|
620
624
|
except Exception: # noqa: BLE001 — must never fail the hook
|
|
621
625
|
return
|
|
@@ -623,6 +627,23 @@ def inject_context_cmd(
|
|
|
623
627
|
sys.stdout.write(text) # inject_context() already ends with "\n"
|
|
624
628
|
|
|
625
629
|
|
|
630
|
+
def _hook_stdin() -> str:
|
|
631
|
+
"""The hook's stdin payload, or "" when there isn't one to read.
|
|
632
|
+
|
|
633
|
+
Empty for a terminal (the command run by hand) and for a stdin that
|
|
634
|
+
cannot be read, so the block falls back to Claude's rather than going
|
|
635
|
+
blank. Claude Code and Codex write the payload and close the pipe, so the
|
|
636
|
+
read can't block.
|
|
637
|
+
"""
|
|
638
|
+
stdin = sys.stdin
|
|
639
|
+
if stdin is None:
|
|
640
|
+
return ""
|
|
641
|
+
try:
|
|
642
|
+
return "" if stdin.isatty() else stdin.read()
|
|
643
|
+
except (OSError, ValueError):
|
|
644
|
+
return ""
|
|
645
|
+
|
|
646
|
+
|
|
626
647
|
@app.command
|
|
627
648
|
def serve() -> None:
|
|
628
649
|
"""Run the code-graph MCP server standalone (code_* tools only).
|
|
@@ -993,8 +1014,9 @@ def reindex_hook_cmd() -> None:
|
|
|
993
1014
|
|
|
994
1015
|
Reads the hook payload from stdin, extracts ``tool_input.file_path`` (or
|
|
995
1016
|
``path``/``filename``) from Claude Code's, or every file a Codex
|
|
996
|
-
``apply_patch``
|
|
997
|
-
|
|
1017
|
+
``apply_patch`` names, and queues each: one still on disk is reindexed,
|
|
1018
|
+
and one the patch deleted or moved away has its rows purged. One detached
|
|
1019
|
+
drainer per checkout applies the
|
|
998
1020
|
queue, so parallel agents editing one worktree do not race each other's
|
|
999
1021
|
writes to its branch view. Logs from the last drainer are kept in
|
|
1000
1022
|
``$TMPDIR/witan-code-<uid>/``. Best-effort: a missing or
|