fix: add --all to cargo fmt in script/test and autoformat codebase

cargo fmt without --all fails with "Failed to find targets" in
workspace repos. This was blocking every story's gates. Also ran
cargo fmt --all to fix all existing formatting issues.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
dave
2026-04-13 14:07:08 +00:00
parent ed2526ce41
commit 845b85e7a7
128 changed files with 3566 additions and 2395 deletions
+45 -58
View File
@@ -6,7 +6,6 @@ use std::fs::{self, File, OpenOptions};
use std::io::{BufRead, BufReader, Write};
use std::path::{Path, PathBuf};
/// A single line in the agent log file (JSONL format).
#[derive(Debug, Serialize, Deserialize)]
pub struct LogEntry {
@@ -72,10 +71,7 @@ impl AgentLogWriter {
/// Return the log directory for a story.
fn log_dir(project_root: &Path, story_id: &str) -> PathBuf {
project_root
.join(".huskies")
.join("logs")
.join(story_id)
project_root.join(".huskies").join("logs").join(story_id)
}
/// Return the path to a specific log file.
@@ -102,8 +98,8 @@ pub fn read_log(path: &Path) -> Result<Vec<LogEntry>, String> {
if trimmed.is_empty() {
continue;
}
let entry: LogEntry = serde_json::from_str(trimmed)
.map_err(|e| format!("Failed to parse log entry: {e}"))?;
let entry: LogEntry =
serde_json::from_str(trimmed).map_err(|e| format!("Failed to parse log entry: {e}"))?;
entries.push(entry);
}
@@ -197,10 +193,7 @@ pub fn format_log_entry_as_text(timestamp: &str, event: &serde_json::Value) -> O
Some("done") => Some(format!("{pfx} DONE")),
Some("status") => {
// Skip trivial running/started noise
let status = event
.get("status")
.and_then(|v| v.as_str())
.unwrap_or("?");
let status = event.get("status").and_then(|v| v.as_str()).unwrap_or("?");
match status {
"running" | "started" => None,
_ => Some(format!("{pfx} STATUS: {status}")),
@@ -211,10 +204,7 @@ pub fn format_log_entry_as_text(timestamp: &str, event: &serde_json::Value) -> O
match data.get("type").and_then(|v| v.as_str()) {
Some("assistant") => {
let mut parts: Vec<String> = Vec::new();
if let Some(arr) = data
.pointer("/message/content")
.and_then(|v| v.as_array())
{
if let Some(arr) = data.pointer("/message/content").and_then(|v| v.as_array()) {
for item in arr {
match item.get("type").and_then(|v| v.as_str()) {
Some("text") => {
@@ -228,15 +218,11 @@ pub fn format_log_entry_as_text(timestamp: &str, event: &serde_json::Value) -> O
}
}
Some("tool_use") => {
let name = item
.get("name")
.and_then(|v| v.as_str())
.unwrap_or("?");
let name =
item.get("name").and_then(|v| v.as_str()).unwrap_or("?");
let input = item
.get("input")
.map(|v| {
serde_json::to_string(v).unwrap_or_default()
})
.map(|v| serde_json::to_string(v).unwrap_or_default())
.unwrap_or_default();
let display = if input.len() > 200 {
format!("{}...", &input[..200])
@@ -257,14 +243,9 @@ pub fn format_log_entry_as_text(timestamp: &str, event: &serde_json::Value) -> O
}
Some("user") => {
let mut parts: Vec<String> = Vec::new();
if let Some(arr) = data
.pointer("/message/content")
.and_then(|v| v.as_array())
{
if let Some(arr) = data.pointer("/message/content").and_then(|v| v.as_array()) {
for item in arr {
if item.get("type").and_then(|v| v.as_str())
!= Some("tool_result")
{
if item.get("type").and_then(|v| v.as_str()) != Some("tool_result") {
continue;
}
let content_str = match item.get("content") {
@@ -316,11 +297,7 @@ pub fn read_log_as_readable_lines(path: &Path) -> Result<Vec<String>, String> {
///
/// Scans `.huskies/logs/{story_id}/` for files matching `{agent_name}-*.log`
/// and returns the one with the most recent modification time.
pub fn find_latest_log(
project_root: &Path,
story_id: &str,
agent_name: &str,
) -> Option<PathBuf> {
pub fn find_latest_log(project_root: &Path, story_id: &str, agent_name: &str) -> Option<PathBuf> {
let dir = log_dir(project_root, story_id);
if !dir.is_dir() {
return None;
@@ -362,8 +339,7 @@ mod tests {
let tmp = tempdir().unwrap();
let root = tmp.path();
let _writer =
AgentLogWriter::new(root, "42_story_foo", "coder-1", "sess-abc123").unwrap();
let _writer = AgentLogWriter::new(root, "42_story_foo", "coder-1", "sess-abc123").unwrap();
let expected_path = root
.join(".huskies")
@@ -378,8 +354,7 @@ mod tests {
let tmp = tempdir().unwrap();
let root = tmp.path();
let mut writer =
AgentLogWriter::new(root, "42_story_foo", "coder-1", "sess-001").unwrap();
let mut writer = AgentLogWriter::new(root, "42_story_foo", "coder-1", "sess-001").unwrap();
let event = AgentEvent::Status {
story_id: "42_story_foo".to_string(),
@@ -426,8 +401,7 @@ mod tests {
let tmp = tempdir().unwrap();
let root = tmp.path();
let mut writer =
AgentLogWriter::new(root, "42_story_foo", "coder-1", "sess-002").unwrap();
let mut writer = AgentLogWriter::new(root, "42_story_foo", "coder-1", "sess-002").unwrap();
let events = vec![
AgentEvent::Status {
@@ -472,10 +446,8 @@ mod tests {
let tmp = tempdir().unwrap();
let root = tmp.path();
let mut writer1 =
AgentLogWriter::new(root, "42_story_foo", "coder-1", "sess-aaa").unwrap();
let mut writer2 =
AgentLogWriter::new(root, "42_story_foo", "coder-1", "sess-bbb").unwrap();
let mut writer1 = AgentLogWriter::new(root, "42_story_foo", "coder-1", "sess-aaa").unwrap();
let mut writer2 = AgentLogWriter::new(root, "42_story_foo", "coder-1", "sess-bbb").unwrap();
writer1
.write_event(&AgentEvent::Output {
@@ -496,7 +468,10 @@ mod tests {
let path1 = log_file_path(root, "42_story_foo", "coder-1", "sess-aaa");
let path2 = log_file_path(root, "42_story_foo", "coder-1", "sess-bbb");
assert_ne!(path1, path2, "Different sessions should use different files");
assert_ne!(
path1, path2,
"Different sessions should use different files"
);
let entries1 = read_log(&path1).unwrap();
let entries2 = read_log(&path2).unwrap();
@@ -513,8 +488,7 @@ mod tests {
let root = tmp.path();
// Create two log files with a small delay
let mut writer1 =
AgentLogWriter::new(root, "42_story_foo", "coder-1", "sess-old").unwrap();
let mut writer1 = AgentLogWriter::new(root, "42_story_foo", "coder-1", "sess-old").unwrap();
writer1
.write_event(&AgentEvent::Output {
story_id: "42_story_foo".to_string(),
@@ -527,8 +501,7 @@ mod tests {
// Touch the second file to ensure it's newer
std::thread::sleep(std::time::Duration::from_millis(50));
let mut writer2 =
AgentLogWriter::new(root, "42_story_foo", "coder-1", "sess-new").unwrap();
let mut writer2 = AgentLogWriter::new(root, "42_story_foo", "coder-1", "sess-new").unwrap();
writer2
.write_event(&AgentEvent::Output {
story_id: "42_story_foo".to_string(),
@@ -568,8 +541,7 @@ mod tests {
drop(w1);
std::thread::sleep(std::time::Duration::from_millis(10));
let mut w2 =
AgentLogWriter::new(root, "42_story_foo", "mergemaster", "sess-bbb").unwrap();
let mut w2 = AgentLogWriter::new(root, "42_story_foo", "mergemaster", "sess-bbb").unwrap();
w2.write_event(&AgentEvent::Output {
story_id: "42_story_foo".to_string(),
agent_name: "mergemaster".to_string(),
@@ -601,8 +573,7 @@ mod tests {
.unwrap();
drop(w1);
let mut w2 =
AgentLogWriter::new(root, "42_story_foo", "mergemaster", "sess-b").unwrap();
let mut w2 = AgentLogWriter::new(root, "42_story_foo", "mergemaster", "sess-b").unwrap();
w2.write_event(&AgentEvent::Output {
story_id: "42_story_foo".to_string(),
agent_name: "mergemaster".to_string(),
@@ -704,7 +675,10 @@ mod tests {
}
});
let result = format_log_entry_as_text(ts, &event).unwrap();
assert!(result.contains("TOOL: Read"), "should show tool call: {result}");
assert!(
result.contains("TOOL: Read"),
"should show tool call: {result}"
);
assert!(result.contains("file_path"), "should show input: {result}");
}
@@ -728,7 +702,10 @@ mod tests {
}
});
let result = format_log_entry_as_text(ts, &event).unwrap();
assert!(result.contains("Now I will read the file."), "should show text: {result}");
assert!(
result.contains("Now I will read the file."),
"should show text: {result}"
);
}
#[test]
@@ -743,7 +720,10 @@ mod tests {
"event": {"type": "content_block_delta", "delta": {"type": "text_delta", "text": "chunk"}}
}
});
assert!(format_log_entry_as_text(ts, &event).is_none(), "stream events should be skipped");
assert!(
format_log_entry_as_text(ts, &event).is_none(),
"stream events should be skipped"
);
}
#[test]
@@ -771,7 +751,11 @@ mod tests {
let path = log_file_path(root, "42_story_foo", "coder-1", "sess-readable");
let lines = read_log_as_readable_lines(&path).unwrap();
assert_eq!(lines.len(), 2, "Should produce 2 readable lines");
assert!(lines[0].contains("Let me read the file"), "first line: {}", lines[0]);
assert!(
lines[0].contains("Let me read the file"),
"first line: {}",
lines[0]
);
assert!(lines[1].contains("DONE"), "second line: {}", lines[1]);
}
@@ -802,7 +786,10 @@ mod tests {
};
// File should still exist and be readable
assert!(path.exists(), "Log file should persist after writer is dropped");
assert!(
path.exists(),
"Log file should persist after writer is dropped"
);
let entries = read_log(&path).unwrap();
assert_eq!(entries.len(), 1);
assert_eq!(entries[0].event["type"], "status");