refactor: decompose cadis-core/lib.rs by extracting helper modules#59
refactor: decompose cadis-core/lib.rs by extracting helper modules#59DeryFerd wants to merge 14 commits into
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: eed4462039
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| use cadis_protocol::{ | ||
| WorkerCommandFailure, WorkerCommandReport, WorkerEventPayload, WorkerLifecycleEventKind, | ||
| WorkerState, WorkerWorktreeCleanupPolicy, WorkerWorktreeState, |
There was a problem hiding this comment.
Keep worker helper types in cadis-core
This refactor moves worker helpers into a child module but imports WorkerCommandFailure, WorkerCommandReport, and WorkerLifecycleEventKind from cadis_protocol; these were not protocol exports (the command structs are still private in lib.rs, and the lifecycle enum was removed from there). With worker_helpers now included by lib.rs, cadis-core cannot resolve these imports, so the crate fails to compile before any worker functionality can run.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7a8254ba3c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| self.debug_events.push_back(DebugEvent { | ||
| timestamp: Instant::now(), | ||
| label, | ||
| detail: String::new(), | ||
| }); |
There was a problem hiding this comment.
Restore DebugEvent detail initialization
When the HUD compiles this event path, this struct literal is now missing the required detail field that is still defined on DebugEvent in crates/cadis-hud/src/types.rs. Since there is no Default update or struct change in this commit, building cadis-hud fails as soon as this literal is type-checked.
Useful? React with 👍 / 👎.
| "stdout": report.stdout, | ||
| "stderr": report.stderr, | ||
| "timed_out": report.timed_out, | ||
| "duration_ms": report.duration_ms, |
There was a problem hiding this comment.
Preserve worker command report metadata
The extracted JSON helper no longer matches the original report artifact schema: the previous implementation included status, stdout_truncated, stderr_truncated, and timeout_ms, but this replacement swaps in duration_ms and omits the fields that tell consumers whether validation passed, timed out, or had truncated output. For workers that run validation commands, the generated validation_command artifact will lose the status and truncation metadata needed to interpret the captured stdout/stderr.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c8b1dfebd6
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } | ||
|
|
||
| #[derive(Clone, Debug, Eq, PartialEq)] | ||
| struct WorkerRecord { |
There was a problem hiding this comment.
Reuse the existing worker record type
This helper module declares a new private WorkerRecord instead of using the WorkerRecord that lib.rs still stores and passes into helpers. In the current diff, calls such as worker_terminal_worktree_state(worker, status) and plan_worker_terminal_worktree(worker, ...) pass lib.rs's WorkerRecord, so the extracted helper signatures now expect a different nominal type and cadis-core cannot type-check until these helpers operate on the original record type (or stay in the same module).
Useful? React with 👍 / 👎.
| if !report.stdout.is_empty() { | ||
| logs.push(format!("STDOUT:\n{}", report.stdout)); |
There was a problem hiding this comment.
Preserve bounded worker command logs
When a validation command produces stdout/stderr, this replacement pushes the entire captured output with a new STDOUT:/STDERR: prefix instead of using the previous bounded command stdout:/command stderr: log format with truncation markers. For long validation output, worker log deltas can now exceed WORKER_COMMAND_LOG_LIMIT_BYTES and lose the truncation signal that the existing worker log path/tests in lib.rs expect.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 83cf4be8e0
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let mut summary = String::new(); | ||
| summary.push_str(&format!("**Command**: `{}`\n\n", report.command)); | ||
| summary.push_str(&format!( | ||
| "**Exit Code**: {}\n\n", | ||
| report.exit_code.map(|c| c.to_string()).unwrap_or_else(|| "None".to_string()) | ||
| )); | ||
| if report.timed_out { | ||
| summary.push_str("**Status**: Timed out\n\n"); |
There was a problem hiding this comment.
Preserve validation summary status
For workers that run a validation command, write_worker_artifacts appends this markdown into the summary artifact. This rewrite starts directly with the command/exit code and only emits a status for timeouts, so normal passed/failed validation summaries no longer contain the ## Daemon Validation section or an unconditional Status: passed/failed line that existing summary consumers/tests use to identify the validation result. Restore the old section header and status line for all command outcomes.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9554fafa09
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if !report.stderr.is_empty() { | ||
| logs.push(format!("STDERR:\n{}", report.stderr)); | ||
| } | ||
| logs |
There was a problem hiding this comment.
Restore worker command completion logs
When the validation command produces no stdout or stderr, this now returns an empty log list, so execute_worker_command emits only the earlier “command started” delta and never the completion/status delta. This is the normal path for a clean default git status --short worker command, and the existing worker lifecycle test in crates/cadis-core/src/lib.rs expects command finished: status=passed exit_code=Some(0) to be present so clients can observe that daemon validation finished successfully.
Useful? React with 👍 / 👎.
Problem Statement
The cadis-core/src/lib.rs file has grown to over 14,500 lines, making it increasingly difficult to navigate and maintain. The file contains a mix of high-level orchestration logic alongside numerous helper functions for worker lifecycle management, approval workflows, and session handling. This monolithic structure creates several issues:
Solution Architecture
This PR extracts three groups of helper functions into dedicated modules, each focused on a specific domain:
Module Structure
Domain Separation
worker_helpers.rs - Encapsulates worker-related concerns:
approval_helpers.rs - Encapsulates approval workflow concerns:
session_helpers.rs - Encapsulates agent session lifecycle concerns:
Implementation Details
Extraction Strategy
The extraction was performed as a pure code move operation:
pubto maintain accessibility from lib.rsusestatements were added to lib.rsNo Functional Changes
This is a zero-functional-change refactor:
cadis-coreis unaffectedLine Count Impact
Benefits
Migration Notes
No migration is required. This is an internal refactoring that does not affect:
All existing code continues to work without modification.
Next Steps
Future refactoring opportunities (not included in this PR):