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 @@
|
||||
//! `web_fetch` (URL -> text) and `web_search` (Brave or SearXNG). Both return untrusted text.
|
||||
|
||||
use crate::spec;
|
||||
use async_trait::async_trait;
|
||||
use hx_ai::ToolSpec;
|
||||
@@ -16,15 +14,11 @@ const MAX_REDIRECTS: usize = 5;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum Search {
|
||||
/// API key.
|
||||
Brave(String),
|
||||
/// Base URL of the instance (needs `json` in its `search.formats`).
|
||||
Searx(String),
|
||||
}
|
||||
|
||||
impl Search {
|
||||
/// `kind` = config `web.search` ("brave" default | "searxng"). Brave without key falls back to
|
||||
/// SearXNG when a URL is set; None = no `web_search` tool.
|
||||
pub fn pick(
|
||||
kind: Option<&str>,
|
||||
brave_key: Option<String>,
|
||||
@@ -42,7 +36,6 @@ impl Search {
|
||||
|
||||
struct Web {
|
||||
http: reqwest::Client,
|
||||
/// tests only: allow loopback/private targets
|
||||
private_ok: bool,
|
||||
}
|
||||
|
||||
@@ -74,7 +67,7 @@ fn private(ip: IpAddr) -> bool {
|
||||
|| v.is_unspecified()
|
||||
|| v.is_broadcast()
|
||||
|| v.octets()[0] == 0
|
||||
|| (v.octets()[0] == 100 && v.octets()[1] & 0xc0 == 64) // CGNAT
|
||||
|| (v.octets()[0] == 100 && v.octets()[1] & 0xc0 == 64)
|
||||
}
|
||||
IpAddr::V6(v) => {
|
||||
if let Some(m) = v.to_ipv4_mapped() {
|
||||
@@ -82,15 +75,12 @@ fn private(ip: IpAddr) -> bool {
|
||||
}
|
||||
v.is_loopback()
|
||||
|| v.is_unspecified()
|
||||
|| v.segments()[0] & 0xfe00 == 0xfc00 // unique local
|
||||
|| v.segments()[0] & 0xffc0 == 0xfe80 // link local
|
||||
|| v.segments()[0] & 0xfe00 == 0xfc00
|
||||
|| v.segments()[0] & 0xffc0 == 0xfe80
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Reject non-http(s) and hosts resolving to private ranges.
|
||||
// ponytail: resolve-then-connect leaves a DNS-rebinding gap; pin the resolved IP via
|
||||
// `ClientBuilder::resolve` if that matters.
|
||||
async fn check(w: &Web, u: &Url) -> Result<(), String> {
|
||||
if !matches!(u.scheme(), "http" | "https") {
|
||||
return Err(format!(
|
||||
@@ -117,7 +107,6 @@ async fn check(w: &Web, u: &Url) -> Result<(), String> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// GET with manual redirects (each hop checked) and a body cap.
|
||||
async fn get(
|
||||
w: &Web,
|
||||
url: &str,
|
||||
@@ -337,7 +326,6 @@ mod tests {
|
||||
use super::*;
|
||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||
|
||||
/// Serves `routes` (path -> (status line, headers, body)); returns base URL.
|
||||
async fn serve(routes: Vec<(&'static str, String)>) -> String {
|
||||
let l = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
|
||||
let port = l.local_addr().unwrap().port();
|
||||
@@ -402,7 +390,6 @@ mod tests {
|
||||
)
|
||||
.await;
|
||||
assert!(r.content.contains("truncated"));
|
||||
// guard on: loopback and bad scheme refused
|
||||
let g = Fetch(Arc::new(Web::new(false)));
|
||||
let r = g.call(json!({"url": format!("{base}/page")}), &cx()).await;
|
||||
assert!(r.is_error && r.content.contains("private"), "{}", r.content);
|
||||
@@ -414,7 +401,6 @@ mod tests {
|
||||
|
||||
#[tokio::test]
|
||||
async fn redirect_to_private_blocked() {
|
||||
// public-looking first hop is impossible offline, so test `private()` directly
|
||||
for ip in [
|
||||
"127.0.0.1",
|
||||
"10.1.2.3",
|
||||
|
||||
Reference in new issue
Block a user