Skip to content

refactor(terraphim_agent): extract cli_schema module (issue #211 step 2) - #16

Open
AlexMikhalev wants to merge 3 commits into
release/1.21.14-automata-bumpfrom
fix/de-monolith-issue-211-step2
Open

AlexMikhalev wants to merge 3 commits into
release/1.21.14-automata-bumpfrom
fix/de-monolith-issue-211-step2

Conversation

@AlexMikhalev

Copy link
Copy Markdown
Contributor

refactor(terraphim_agent): extract cli_schema module (issue #211 step 2)

Step 2 of #211. Builds on the cli_helpers extraction from #212.

Summary

Moves the entire CLI schema out of crates/terraphim_agent/src/main.rs
into a new sibling module crates/terraphim_agent/src/cli_schema.rs:

  • HookType, BoundaryMode, OutputFormat, CommandOutputMode,
    LogicalOperatorCli (with From<LogicalOperatorCli> for LogicalOperator)
  • struct Cli (with pub(crate) fields so the dispatch in main.rs
    can still read them)
  • enum Command and all 22 of its variants (Search, Roles, Config,
    Graph, Kg, Chat, Extract, Replace, Validate, Suggest,
    Hook, Guard, Interactive, Repl, Setup, CheckUpdate, Update,
    Learn, Sessions, Listen, Cache, Robot, Memory)
  • All subcommand enums: CacheSub, LearnSub, CorrectionSub,
    SharedLearningSub, SuggestSub, ProcedureSub, RolesSub,
    ConfigSub, KgSub, SessionsSub, RobotSub, MemorySub

Seam notes

  • Clean seam — all references to the schema items in main.rs are
    pattern matches (e.g. Command::Search { query, terms, .. }); no
    command variants are constructed outside their own definitions.
    No dispatch code needed to move.
  • RobotFormat, CommandOutputConfig, resolve_output_config, and
    print_json_output stay in main.rs because they are output-rendering
    helpers coupled to robot::output::RobotFormatter, not to the schema.
    RobotSub (moved) references them as super::RobotFormat.
  • get_session_cache_path is a path helper used by the dispatch (not
    the schema), so it stays in main.rs.
  • CommandOutputMode moved to cli_schema while CommandOutputConfig
    stays in main.rs; the latter references cli_schema::CommandOutputMode
    via the use cli_schema::*; glob import.

Verification (on bigbox)

  • cargo build -p terraphim_agent --features server — OK
  • cargo clippy -p terraphim_agent --features server -- -D warnings — OK
  • cargo test -p terraphim_agent --features server — passes; the only
    failing tests are the pre-existing cross_mode_consistency_test ones
    that need TERRAPHIM_SERVER_BIN (a known environmental requirement,
    not related to this refactor)

Line-count delta

  • main.rs: 6610 → 5732 LOC (−878)
  • cli_schema.rs (new): 898 LOC (includes module docs and use lines)

Ref #211

alex and others added 3 commits September 9, 2026 20:19
Step 1 of #211. Moves the formatting/word-boundary/UI-building helpers
out of main.rs (which was 6 842 LOC, the only file over the soft
threshold across the entire Terraphim polyrepo family per the
2026-09-09 de-monolithize census).

No behaviour change. Same signatures, same callers. Helpers are
pub(crate) so main.rs can still reference them via the existing
call-site names (truncate_snippet, format_auto_route_line,
is_word_boundary_char, is_at_word_boundary, format_replacement_link,
transparent_style, create_block); all call sites were updated
implicitly via a single 'use cli_helpers::*;' import. The 7 unit
tests for is_word_boundary_* and the 4 tests for truncate_snippet and
the 1 test for format_auto_route_line move with their functions into
cli_helpers.rs.

main.rs: 6 842 -> 6 610 LOC (-232).
cli_helpers.rs: 0 -> 251 LOC (new).

Verified locally:
  cargo build -p terraphim_agent --features server       OK
  cargo clippy -p terraphim_agent --features server         -- -D warnings                                    OK
  cargo test  -p terraphim_agent --features server         --lib --bin terraphim-agent                       582 passed, 0 failed
…dule (issue #211 step 1)' (#212) from fix/de-monolith-issue-211 into release/1.21.14-automata-bump
Step 2 of #211. Moves the entire CLI schema (Cli struct, Command enum
with all variants, all subcommand enums, and helper enums for
format/operator/boundary/hook types) into cli_schema.rs.

Following the Phase 2 evidence in
terraphim/demonolith-workspaces/per-repo/terraphim-clients/phase2_findings_main_rs.md
which identified the schema as the next cluster after cli_helpers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant