chore: delete code comments, add ratchet lint and ADRs
Classify every comment as tautology, stale, excuse or decision record. Tautology/stale/excuse comments are deleted (excuses filed as issues #196-#236), decisions moved to docs/adr/0001-0034. - scripts/lint-comments.sh + .comment-baseline: per-file comment count may only go down; wired into tests/all.sh - .claude/skills/delete-comment: repeatable audit workflow - cargo fmt applied to touched crates Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0545702fe0
commit
a94632ea3d
131 files changed
+1051
-1746
No files matched your search
@@ -1,5 +1,3 @@
|
||||
//! Event bus and hooks. Lens, MCP and extensions all plug in here.
|
||||
|
||||
use async_trait::async_trait;
|
||||
use hx_ai::{Message, StreamEvent};
|
||||
use serde_json::Value;
|
||||
@@ -9,7 +7,6 @@ use std::sync::Arc;
|
||||
pub enum Event {
|
||||
SessionStart,
|
||||
TurnStart,
|
||||
/// Before a tool runs. `Block` or `Mutate` apply.
|
||||
ToolCall {
|
||||
id: String,
|
||||
name: String,
|
||||
@@ -22,27 +19,19 @@ pub enum Event {
|
||||
content: String,
|
||||
is_error: bool,
|
||||
},
|
||||
/// After all tools of a turn ran. `Inject` adds a user message before the next request.
|
||||
TurnEnd,
|
||||
/// Model finished without tool calls. `Inject` makes the agent continue.
|
||||
AgentEnd,
|
||||
/// A run ended for any reason (done, error, abort). Fires after the last turn.
|
||||
RunEnd {
|
||||
aborted: bool,
|
||||
},
|
||||
/// Streaming output from the model (UI).
|
||||
Stream(StreamEvent),
|
||||
Message(Message),
|
||||
/// Human-readable notice for the UI (compaction etc).
|
||||
Info(String),
|
||||
/// Text hooks injected at turn/agent end (lens reports etc), for display.
|
||||
Injected(Vec<String>),
|
||||
/// Tokens spent by subagents (`task` tool) in the tools just run; already added to `Agent::usage`.
|
||||
SubUsage(hx_ai::Usage),
|
||||
}
|
||||
|
||||
impl Event {
|
||||
/// Stable JSON form (NDJSON mode, RPC notifications, extensions). Schema: README "Event stream".
|
||||
pub fn to_json(&self) -> Value {
|
||||
use serde_json::json;
|
||||
match self {
|
||||
@@ -70,7 +59,6 @@ impl Event {
|
||||
}
|
||||
}
|
||||
|
||||
/// `type` of `to_json`, for subscriptions.
|
||||
pub fn kind(&self) -> &'static str {
|
||||
match self {
|
||||
Event::SessionStart => "session_start",
|
||||
@@ -100,19 +88,16 @@ pub enum HookAction {
|
||||
#[async_trait]
|
||||
pub trait Hook: Send + Sync {
|
||||
async fn on(&self, ev: &Event) -> HookAction;
|
||||
/// `Some(alive)` if this hook guards `tool_call` (extensions subscribed to it).
|
||||
fn guard(&self) -> Option<bool> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// Clones share the hook list (the permission bridge emits on the agent's bus).
|
||||
#[derive(Default, Clone)]
|
||||
pub struct Bus {
|
||||
hooks: Arc<std::sync::RwLock<Vec<Arc<dyn Hook>>>>,
|
||||
}
|
||||
|
||||
/// Aggregate outcome of dispatching one event to all hooks.
|
||||
#[derive(Debug, Default, PartialEq)]
|
||||
pub struct Outcome {
|
||||
pub blocked: Option<String>,
|
||||
@@ -132,14 +117,12 @@ impl Bus {
|
||||
self.add_arc(Arc::new(h))
|
||||
}
|
||||
|
||||
/// (number of `tool_call` guards, all of them alive).
|
||||
pub fn guards(&self) -> (usize, bool) {
|
||||
let hooks = self.hooks.read().unwrap_or_else(|e| e.into_inner());
|
||||
let g: Vec<bool> = hooks.iter().filter_map(|h| h.guard()).collect();
|
||||
(g.len(), g.iter().all(|a| *a))
|
||||
}
|
||||
|
||||
/// Hooks run in registration order. First `Block` wins; `Mutate` is visible to later hooks.
|
||||
pub async fn emit(&self, ev: Event) -> Outcome {
|
||||
let mut ev = ev;
|
||||
let mut o = Outcome::default();
|
||||
|
||||
Reference in new issue
Block a user