Skip to content

refactor: structural code organization — EPIC-01 through 06#1966

Merged
bug-ops merged 5 commits intomainfrom
feat/arch-refactor-patterns
Mar 18, 2026
Merged

refactor: structural code organization — EPIC-01 through 06#1966
bug-ops merged 5 commits intomainfrom
feat/arch-refactor-patterns

Conversation

@bug-ops
Copy link
Copy Markdown
Owner

@bug-ops bug-ops commented Mar 18, 2026

Summary

  • EPIC-01: New zeph-common crate (Layer 0) consolidates shared utilities: truncate_to_bytes, is_private_ip, strip_control_chars. Eliminates 3 independent copies of truncation and 2 copies of SSRF-check logic.
  • EPIC-02: Agent<C> struct decomposition — extracts 5 new named sub-structs (InstructionState, ExperimentState, CompressionState, MessageState, SessionState). All sub-struct definitions moved to agent/state/mod.rs.
  • EPIC-03: Agent module file splits — tool_execution/mod.rs (4,502 → 622 lines) and context/mod.rs (4,320 → 94 lines); tests extracted to sibling tests.rs files.
  • EPIC-04: LLM provider consolidation — claude.rs, openai.rs, gemini.rs split into {mod,request,response,tests,cache}.rs; SchemaVisitor trait for OpenAI/Gemini normalization extracted to schema.rs.
  • EPIC-05: Memory module cleanup — graph/store.rs (3,886), graph/resolver.rs (2,021), sqlite/messages.rs (1,559) each split into mod.rs + tests.rs.
  • EPIC-06: Tool module improvements — filter/declarative.rs (2,852) and shell.rs (2,459) each split into mod.rs + tests.rs.

Closes #1741
Closes #1962
Closes #1963
Closes #1964
Closes #1965

Test plan

  • cargo +nightly fmt --check passes
  • cargo clippy --workspace --features full -- -D warnings passes
  • cargo nextest run --workspace --features full --lib --bins — 6161 tests pass
  • Verify no regression in CI matrix (Linux + macOS)

Follow-up issues

bug-ops added 3 commits March 18, 2026 15:40
…lities

- Add new zeph-common crate (Layer 0, no zeph-* deps) with:
  - text: truncate_to_bytes, truncate_to_bytes_ref, truncate_chars, truncate_to_chars
  - net: is_private_ip (canonical SSRF defense, covers IPv4/IPv6/CGNAT/BiDi)
  - sanitize: strip_control_chars, strip_null_bytes
- Consolidate 3 truncate_to_bytes duplicates (zeph-mcp, zeph-memory x2) into zeph-common
- Consolidate 2 is_private_ip duplicates (zeph-tools, zeph-a2a) into zeph-common
  - zeph-tools/src/net.rs re-exports from zeph-common
  - zeph-a2a/src/client.rs uses zeph-common directly
- Remove same-layer violation: zeph-tools no longer depends on zeph-index (#1963)
  - Inline language detection and grammar/query setup in search_code.rs using tree-sitter directly
- Add zeph-common to workspace Cargo.toml
- All 6161 tests pass; clippy clean with --features full

Closes #1962, #1963
…2, 03, 05, 06)

EPIC-02 - Agent Struct Decomposition:
- Extract InstructionState, ExperimentState, CompressionState, MessageState,
  SessionState sub-structs from Agent<C>
- Move all sub-struct definitions to agent/state/mod.rs
- Update all field accesses across 20+ files (msg.messages, session.env_context, etc.)

EPIC-03 - Agent Module File Splits:
- tool_execution/mod.rs: 4,502 → 622 lines; tests → tool_execution/tests.rs
- context/mod.rs: 4,320 → 94 lines; tests → context/tests.rs

EPIC-04 - LLM Provider Consolidation (already included in branch):
- claude.rs, openai.rs, gemini.rs split into mod/request/response/tests/cache

EPIC-05 - Memory Module Cleanup:
- graph/store.rs (3,886 lines) → graph/store/{mod,tests}.rs
- graph/resolver.rs (2,021 lines) → graph/resolver/{mod,tests}.rs
- sqlite/messages.rs (1,559 lines) → sqlite/messages/{mod,tests}.rs

EPIC-06 - Tool Module Improvements:
- filter/declarative.rs (2,852 lines) → filter/declarative/{mod,tests,default-filters.toml}
- shell.rs (2,459 lines) → shell/{mod,tests}.rs
- Update snapshot source paths for insta tests

All 6161 tests pass. No behavioral changes.
@github-actions github-actions bot added documentation Improvements or additions to documentation llm zeph-llm crate (Ollama, Claude) memory zeph-memory crate (SQLite) rust Rust code changes core zeph-core crate refactor Code refactoring without functional changes dependencies Dependency updates size/XL Extra large PR (500+ lines) labels Mar 18, 2026
@bug-ops bug-ops enabled auto-merge (squash) March 18, 2026 17:08
@bug-ops bug-ops disabled auto-merge March 18, 2026 17:08
bug-ops added 2 commits March 18, 2026 18:21
Bundle check CI jobs (chat/ide/server) compile without context-compression
feature, causing dead_code error on the compression field. Gate the struct
definition, field declaration, initialization, and import with
#[cfg(feature = "context-compression")] to match the original per-field
gating pattern.
@bug-ops bug-ops enabled auto-merge (squash) March 18, 2026 17:33
@bug-ops bug-ops disabled auto-merge March 18, 2026 17:36
@bug-ops bug-ops enabled auto-merge (squash) March 18, 2026 17:39
@bug-ops bug-ops merged commit d8c6c41 into main Mar 18, 2026
30 checks passed
@bug-ops bug-ops deleted the feat/arch-refactor-patterns branch March 18, 2026 17:40
bug-ops added a commit that referenced this pull request Mar 18, 2026
…E, group Agent fields, add state tests (#1972)

* docs(zeph-common): add README.md — closes #1969

* refactor(zeph-core): consolidate text module into zeph-common — closes #1967

Add zeph-common as zeph-core dependency, delete duplicate text.rs,
re-export via pub use zeph_common::text so existing crate::text:: paths
remain valid.

* refactor(zeph-common): extract shared tree-sitter queries behind 'treesitter' feature — closes #1968

Add zeph-common::treesitter module with 5 shared symbol query constants
(RUST/PYTHON/JS/TS/GO_SYM_Q), compile_query helper, and lang_for_ext.
Feature-gated behind 'treesitter'. zeph-tools and zeph-index now import
from zeph-common::treesitter instead of maintaining their own copies.
Lang enum and method queries remain in zeph-index.

* refactor(zeph-core): group loose Agent fields into FeedbackState, move rate_limiter into RuntimeConfig — closes #1971

Add FeedbackState { detector, judge } grouping feedback_detector and
judge_detector. Move rate_limiter into RuntimeConfig alongside other
runtime policy fields. Update all ~30 call sites across mod.rs,
builder.rs, and tool_execution/native.rs.

* test(zeph-core): add unit tests for agent state sub-structs — closes #1970

Add agent/state/tests.rs with construction and field access tests for
InstructionState, ExperimentState, MessageState, SessionState,
RuntimeConfig (including rate_limiter), FeedbackState, and
CompressionState (#[cfg(feature = "context-compression")]).
ExperimentState has cfg-gated field tests behind #[cfg(feature = "experiments")].
Tests pass both without extra features (1940 tests) and with
experiments,context-compression (2098 tests).

* style: fix nightly fmt and clippy must_use on treesitter::compile_query

* chore: update CHANGELOG for batch #1967-#1971
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core zeph-core crate dependencies Dependency updates documentation Improvements or additions to documentation llm zeph-llm crate (Ollama, Claude) memory zeph-memory crate (SQLite) refactor Code refactoring without functional changes rust Rust code changes size/XL Extra large PR (500+ lines)

Projects

None yet

1 participant