This repository was archived by the owner on May 26, 2026. It is now read-only.
feat(kora): KR-PLUGIN-EXTRACTIONS-BATCH-2 — audit + caching + short-circuit + state-holders#188
Merged
rafe-walker merged 1 commit intoMay 24, 2026
Conversation
…ircuit + state-holders Four sub-plugin extractions in one PR, following the PR #185 KR-PLUGIN-COST-LADDER template (constants + <logic> + plugin file shape; backward-compat shim with identity-against-canonical drift guard). # Canonical locations created kora_cli/reasoning/kora_hermes_plugin/ audit/ — Deliverable A; _emit_tool_called_audit writer (moved from anthropic_engine); post_tool_call + post_llm_call handlers caching/ — Deliverable B; _wrap_system/tools_as_cacheable markers (moved from anthropic_engine); standalone caching_hook (not registered; bundled with cost-ladder hook in v1) short_circuit/ — Deliverable C; PhrasebookEntry + ShortCircuitMatch + load_phrasebook + match_message + render_reply + try_short_circuit (moved from kora_cli/short_circuit/dm_phrasebook.py) state_holders/ — Deliverable D; on_session_start handler + STATE_HOLDER_ACCESSORS registry + holder_liveness probe # Backward-compat shims kora_cli/reasoning/anthropic_engine.py Re-imports _emit_tool_called_audit (Deliverable A) + _wrap_system/tools_as_cacheable (Deliverable B) from their canonical sub-plugin locations. The 3 in-file callers of the audit helper + the engine's _make_request_kwargs caching wrap keep resolving the symbols. kora_cli/short_circuit/dm_phrasebook.py (333 → 62 lines) Re-exports the full public surface from the canonical matcher module. slack_dm_handler + web_server + phrasebook editor (PR #177) keep working unchanged. Bundled YAML phrasebook stays at default_slack_dm_phrasebook.yml in this package — phrasebook editor reads/writes it through importlib.resources.files("kora_cli.short_circuit"). # Cross-dep cleanup (Deliverable B's stated value) The cost-ladder plugin's hook handler (added in PR #185) previously imported the caching wrap helpers from kora_cli.reasoning.anthropic_engine. This PR cuts that cross-dep — cost_ladder/plugin.py now imports _wrap_system/tools_as_cacheable from kora_hermes_plugin.caching.markers (the canonical sub-plugin location). Verified by grep: zero remaining anthropic_engine imports in cost_ladder/plugin.py. # Orchestrator topology (post-batch) KoraHermesPlugin.register walks 5 sub-registers in order (cost_ladder, audit, caching, short_circuit, state_holders) then attaches 3 remaining orchestrator-resident handlers (pre_tool_list_finalized + pre_tool_call + the ST2B tool bridge). 7 total hooks wired against KORA_ROUTES. # Tests tests/kora_cli/reasoning/kora_hermes_plugin/audit/test_writer.py 7 tests: identity-against-canonical (engine shim, orchestrator re-export, discovery shim re-export) + writer end-to-end JSONL emit + dual-write log preservation + register-wires-2-hooks + handler-noop-on-non-Kora-routes. tests/kora_cli/reasoning/kora_hermes_plugin/caching/test_markers.py 8 tests: engine shim identity + cost-ladder hook proves it imports from canonical location (via patched-canonical sentinel) + marker shape + last-tool-only + empty input + register-is-noop + standalone caching_hook end-to-end. tests/kora_cli/reasoning/kora_hermes_plugin/short_circuit/test_matcher.py Moved 1:1 from tests/kora_cli/short_circuit/test_dm_ phrasebook.py with import path updated to canonical. tests/kora_cli/reasoning/kora_hermes_plugin/state_holders/test_plugin.py 7 tests: orchestrator + discovery shim identity + handler no-op gate + register-wires-on-session-start + accessors- registry-shape + holder_liveness-returns-bool-per-accessor. tests/kora_cli/short_circuit/test_dm_phrasebook.py Converted to 3-test shim-verification suite (identity- against-canonical for public + private re-exports + package-level resolves + canonical-module attribution). tests/kora_cli/test_phrasebook_endpoints.py test_placeholder_regex_matches_dm_phrasebook_source updated to source-grep the canonical matcher.py location (the regex moved with the module; the drift-guard intent preserved). # Scoped regression (xdist) tests/kora_cli/reasoning/kora_hermes_plugin/ passing tests/kora_cli/short_circuit/ passing tests/kora_cli/reasoning/test_anthropic_engine_caching.py passing tests/kora_cli/audit/test_jsonl_sink.py passing tests/plugins/test_kora_hermes_plugin*.py passing tests/kora_cli/handlers/test_slack_dm_short_circuit.py passing tests/kora_cli/test_phrasebook_{editor,endpoints}.py passing tests/kora_cli/reasoning/test_anthropic_engine_router.py passing tests/kora_cli/snapshot/test_state_snapshot.py passing Total directly-affected surface: 337/337 passing. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Merged
13 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Four sub-plugin extractions in one PR — Deliverables A/B/C/D of the KR-PLUGIN-EXTRACTIONS-BATCH-2 bucket. Each follows the PR #185 KR-PLUGIN-COST-LADDER template (constants +
<logic>+ plugin file shape; backward-compat shim with identity-against-canonical drift guard).After this lands: 5 of 7 plugin extractions complete (cost-ladder + audit + caching + short-circuit + state-holders). Remaining: KR-PLUGIN-IDENTITY (deferred per Lock R3-2) and KR-HAIKU-ROUTER-PLUGIN (waits on KR-HERMES-LOCAL-EXT-REISSUE).
Behavior: unchanged. No hook handler that wasn't firing before fires now; no wire-shape changes.
File-tree diagram (post-batch)
Per-extraction LOC migration
__init__36 +constants25 +writer93 +plugin88)_emit_tool_called_auditmoved out ofanthropic_engine.pyanthropic_engine.py__init__48 +constants30 +markers69 +plugin101)_wrap_system/tools_as_cacheablemoved out ofanthropic_engine.pyanthropic_engine.py__init__50 +constants31 +matcher346 +plugin120)kora_cli/short_circuit/dm_phrasebook.pydm_phrasebook.py__init__33 +registry75 +plugin66)_on_session_startmoved out ofkora_hermes_plugin/plugin.pyTotal: 30 files changed, +2417 / -927.
Cross-dep cleanup confirmation
Deliverable B's stated value: cost-ladder plugin no longer imports from
anthropic_engine.py.Before this PR,
cost_ladder/plugin.py:135-138had:After this PR (
cost_ladder/plugin.py:135-141):Verified by grep:
The cross-dep cleanup is also asserted at runtime by
tests/kora_cli/reasoning/kora_hermes_plugin/caching/test_markers.py::test_cost_ladder_plugin_imports_markers_from_canonical_location— it patches the canonical marker location and confirms the cost-ladder hook honors the patched version (would fail if the hook still imported from the engine).Hook ownership decisions (no-ops by design)
Two of the new sub-plugins have intentional no-op
register()functions:caching/plugin.register(): would otherwise double-fire the cache marker wrap that the bundled cost-ladder hook already does. Standalonecaching_hookexists at the canonical location for a future split.short_circuit/plugin.register(): would otherwise double-fire the matcher thatslack_dm_handler.pyalready calls directly. Standaloneshort_circuit_hookstub exists for a futuretransform_inputwiring.Both no-ops are explicitly tested (
test_register_is_intentional_noopfor caching) and documented in their module docstrings — the canonical boundary + future-ready API is the value extraction.STOP-ASK conditions encountered
None — no cross-dependency surprises, no circular-import breaks, no phrasebook-editor regression. The bundled YAML stayed at
kora_cli/short_circuit/default_slack_dm_phrasebook.ymlso the editor (PR #177) continues reading/writing through the sameimportlib.resources.files("kora_cli.short_circuit")path.Test plan
test_kora_hermes_plugin{,_st2,_st2b}.pytests stay green — discovery shim re-exports + orchestrator re-exports preserved every name they importtest_anthropic_engine_caching.py+test_jsonl_sink.pystay green — shim ensures the engine's existing use sites resolve the same callablestest_slack_dm_short_circuit.py+test_phrasebook_editor.py+test_phrasebook_endpoints.pystay green — phrasebook shim + drift-guard source-path updateRecommendation for next dispatch
Batched pair: KR-HERMES-LOCAL-EXT-REISSUE + KR-HAIKU-ROUTER-PLUGIN. They're tightly coupled — REISSUE adds the Hermes-side hook surface needed for the haiku-router post-call escalation, and HAIKU-ROUTER-PLUGIN consumes that surface to wire
should_escalate_post_call(which exists atcost_ladder/selector.pysince PR #185 but has no caller). Once both land, KR-HAIKU-ROUTER-PLUGIN becomes the 6th of 7 extractions.KR-PLUGIN-IDENTITY remains deferred per Lock R3-2; that's the 7th and final extraction.
🤖 Generated with Claude Code