feat: Add LICENSE file and refactor MITM response handling and tracing.

This commit is contained in:
Nikketryhard
2026-02-18 02:43:05 -06:00
parent c0c12de83c
commit ad0aa1556c
26 changed files with 1132 additions and 569 deletions

View File

@@ -336,8 +336,6 @@ impl MitmStore {
}
}
/// Update a request context in-place. Returns false if not found.
pub async fn update_request<F>(&self, cascade_id: &str, updater: F) -> bool
where
@@ -354,13 +352,17 @@ impl MitmStore {
/// Remove a request context (cleanup after response is complete).
pub async fn remove_request(&self, cascade_id: &str) {
if self.pending_requests.write().await.remove(cascade_id).is_some() {
if self
.pending_requests
.write()
.await
.remove(cascade_id)
.is_some()
{
debug!(cascade = %cascade_id, "Removed request context");
}
}
// ── Cascade cache (turn 0 context for re-injection on turn 1+) ──────
/// Cache the essential context from turn 0 so it can be re-used on
@@ -369,7 +371,10 @@ impl MitmStore {
debug!(cascade = %cascade_id, user_text_len = cache.user_text.len(),
has_tools = cache.tools.is_some(),
"Cached cascade context for subsequent turns");
self.cascade_cache.write().await.insert(cascade_id.to_string(), cache);
self.cascade_cache
.write()
.await
.insert(cascade_id.to_string(), cache);
}
/// Get cached context for a cascade (non-consuming — needed on every turn).
@@ -382,8 +387,6 @@ impl MitmStore {
self.cascade_cache.read().await.contains_key(cascade_id)
}
// ── Usage recording ──────────────────────────────────────────────────
/// Record a completed API exchange with usage data.
@@ -596,9 +599,11 @@ impl MitmStore {
/// consumes the context via `take_request`, but the handler needs to re-install
/// a channel for the LS's follow-up request.
pub async fn set_channel(&self, cascade_id: &str, tx: mpsc::Sender<MitmEvent>) {
let updated = self.update_request(cascade_id, |ctx| {
ctx.event_channel = tx.clone();
}).await;
let updated = self
.update_request(cascade_id, |ctx| {
ctx.event_channel = tx.clone();
})
.await;
if !updated {
// Context was already consumed — re-register a minimal one
// so the MITM proxy can match the follow-up request.
@@ -619,7 +624,8 @@ impl MitmStore {
gate,
trace_handle: None,
trace_turn: 0,
}).await;
})
.await;
tracing::debug!(
cascade = cascade_id,
"set_channel: re-registered minimal context (original was consumed)"
@@ -644,8 +650,7 @@ impl MitmStore {
pub async fn register_call_id(&self, cascade_id: &str, call_id: String, name: String) {
self.update_request(cascade_id, |ctx| {
ctx.call_id_to_name.insert(call_id, name);
}).await;
})
.await;
}
}