Skip to content

Commit 3a10eaa

Browse files
bb-connorclaude
andauthored
refactor(policy-event): fold agent edr/dto.rs into wire submodule (#341)
Move ~2,900 lines of EDR wire DTOs from `apps/agent/src-tauri/src/edr/dto.rs` (3,011 lines, 186 DTOs) into a new `clawdstrike_policy_event::wire` module, split across 21 files by functional cluster (health, findings, policy_events, developer_activity, package_manager, endpoint_security, network_extension, policy_event_history{,_causal}, privacy, causal_graph, secret_touches, control_upload, simulation, policy_delta, daemon, response_actions, evidence_bundles, receipts, protection_state, deception). Each file stays under 500 lines; visibility widens from `pub(crate)` to `pub` so control-api and SDKs can share a single source of truth. The agent's `edr/dto.rs` shrinks to 216 lines: re-exports `clawdstrike_policy_event::wire::*` and keeps only the 5 DTOs that reference agent-private types (NetworkExtensionReloadRequestProof, ControlResponseAckPostbackRoute, DaemonStatus, ProviderStatus, StoredEndpointEvidenceBundle): - EdrPolicyDeltaApplyResponse - EdrPolicyDeltaApplyEnforcementProof - EdrNetworkExtensionEgressPolicyProofResponse - EdrControlAckPostbackRetryResponse - EdrControlAckPostbackRetryAttemptRecord Extension impls (`matches_index_entry`, `hydrate_attribution`, `from_stored`) that hung off wire types and called agent-private helpers become plain functions in the agent's `edr/dto.rs` to satisfy Rust's orphan rule. Call sites are updated in `api_server.rs`, `api_server/policy_history.rs`, `api_server/evidence_archives.rs`, `edr/handlers/causal.rs`, `edr/handlers/response.rs`, and the test fixtures. `cargo build --workspace` and `cargo test -p clawdstrike-policy-event` both pass clean; agent test count is unchanged (475 pass / 29 fail), and the 29 failures pre-exist on `main` (verified via `git stash` before applying this change). Co-authored-by: bb-connor <bb-connor@users.noreply.github.com> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 82ed6b3 commit 3a10eaa

30 files changed

Lines changed: 3429 additions & 2910 deletions

apps/agent/src-tauri/src/api_server.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2338,7 +2338,12 @@ async fn hydrate_response_execution_record_attribution(
23382338
for record in records {
23392339
let bundle_id = record.execution.evidence_bundle.bundle_id.as_str();
23402340
match store.load(bundle_id) {
2341-
Ok(Some(stored)) => record.hydrate_attribution(&stored.graph),
2341+
Ok(Some(stored)) => {
2342+
crate::edr::dto::hydrate_response_execution_record_attribution(
2343+
record,
2344+
&stored.graph,
2345+
);
2346+
}
23422347
Ok(None) => {}
23432348
Err(err) => {
23442349
tracing::warn!(

apps/agent/src-tauri/src/api_server/evidence_archives.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub(crate) async fn evidence_bundle_archive_response(
2727
let receipts = evidence_bundle_archive_receipts(state, &stored).await?;
2828
let archive = EdrEvidenceBundleArchive {
2929
bundle: stored.bundle.clone(),
30-
artifact: EdrEvidenceBundleArtifact::from_stored(&stored),
30+
artifact: crate::edr::dto::evidence_bundle_artifact_from_stored(&stored),
3131
graph: stored.graph,
3232
receipts,
3333
};

apps/agent/src-tauri/src/api_server/policy_history.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,21 @@ pub(crate) async fn select_policy_event_history_from_flight_recorder(
8686
};
8787
let event_kind_matches =
8888
event_kinds.is_empty() || event_kinds.contains(entry.event_kind.as_str());
89-
let identity_matches = identity_filters.matches_index_entry(entry);
90-
let process_matches = process_filters.matches_index_entry(entry);
91-
let target_matches = target_filters.matches_index_entry(entry);
89+
let identity_matches =
90+
crate::edr::dto::edr_policy_event_history_identity_filters_matches_index_entry(
91+
&identity_filters,
92+
entry,
93+
);
94+
let process_matches =
95+
crate::edr::dto::edr_policy_event_history_process_filters_matches_index_entry(
96+
&process_filters,
97+
entry,
98+
);
99+
let target_matches =
100+
crate::edr::dto::edr_policy_event_history_target_filters_matches_index_entry(
101+
&target_filters,
102+
entry,
103+
);
92104
time_matches
93105
&& event_kind_matches
94106
&& identity_matches

apps/agent/src-tauri/src/api_server/tests/policy_events/part_2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,7 +1503,7 @@
15031503
});
15041504

15051505
let mut artifact_value =
1506-
serde_json::to_value(EdrEvidenceBundleArtifact::from_stored(&restored))
1506+
serde_json::to_value(crate::edr::dto::evidence_bundle_artifact_from_stored(&restored))
15071507
.unwrap_or_else(|err| panic!("failed to encode evidence bundle artifact: {err}"));
15081508
artifact_value["shadowArtifactHash"] =
15091509
serde_json::Value::String("must not be ignored".to_string());
@@ -1514,7 +1514,7 @@
15141514

15151515
let mut archive_value = serde_json::to_value(EdrEvidenceBundleArchive {
15161516
bundle: restored.bundle.clone(),
1517-
artifact: EdrEvidenceBundleArtifact::from_stored(&restored),
1517+
artifact: crate::edr::dto::evidence_bundle_artifact_from_stored(&restored),
15181518
graph: restored.graph.clone(),
15191519
receipts: Vec::new(),
15201520
})

0 commit comments

Comments
 (0)