Skip to content

Commit 63d4e6b

Browse files
committed
style: cargo fmt
1 parent 11b25ad commit 63d4e6b

2 files changed

Lines changed: 71 additions & 102 deletions

File tree

src/cli/loop_cmd.rs

Lines changed: 28 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,7 @@ fn migrate_legacy_install(claude_dir: &std::path::Path) -> Result<MigrationResul
317317
remove_hooks_from_settings(&settings_path)?;
318318
}
319319

320-
output::success(&format!(
321-
"Removed {} legacy files/directories",
322-
removed
323-
));
320+
output::success(&format!("Removed {} legacy files/directories", removed));
324321

325322
Ok(MigrationResult {
326323
migrated: true,
@@ -334,8 +331,8 @@ fn remove_hooks_from_settings(settings_path: &std::path::Path) -> Result<bool> {
334331
return Ok(false);
335332
}
336333

337-
let contents = std::fs::read_to_string(settings_path)
338-
.context("failed to read settings.json")?;
334+
let contents =
335+
std::fs::read_to_string(settings_path).context("failed to read settings.json")?;
339336
let mut val: serde_json::Value = match serde_json::from_str(&contents) {
340337
Ok(v) => v,
341338
Err(_) => return Ok(false),
@@ -381,10 +378,9 @@ fn remove_hooks_from_settings(settings_path: &std::path::Path) -> Result<bool> {
381378
}
382379

383380
if modified {
384-
let formatted = serde_json::to_string_pretty(&val)
385-
.context("failed to serialize settings.json")?;
386-
std::fs::write(settings_path, formatted)
387-
.context("failed to write settings.json")?;
381+
let formatted =
382+
serde_json::to_string_pretty(&val).context("failed to serialize settings.json")?;
383+
std::fs::write(settings_path, formatted).context("failed to write settings.json")?;
388384
}
389385
}
390386

@@ -398,8 +394,8 @@ fn migrate_claude_md(claude_dir: &std::path::Path) -> Result<()> {
398394
return Ok(());
399395
}
400396

401-
let contents = std::fs::read_to_string(&claude_md_path)
402-
.context("failed to read ~/.claude/CLAUDE.md")?;
397+
let contents =
398+
std::fs::read_to_string(&claude_md_path).context("failed to read ~/.claude/CLAUDE.md")?;
403399

404400
if contents.trim() == LEGACY_CLAUDE_MD.trim() {
405401
std::fs::remove_file(&claude_md_path)
@@ -440,10 +436,7 @@ fn collect_existing_paths(claude_dir: &std::path::Path) -> Vec<std::path::PathBu
440436

441437
// Check skill files in plugin dir
442438
for skill in SKILLS {
443-
let path = plugin_dir
444-
.join("skills")
445-
.join(skill.name)
446-
.join("SKILL.md");
439+
let path = plugin_dir.join("skills").join(skill.name).join("SKILL.md");
447440
if path.exists() {
448441
existing.push(path);
449442
}
@@ -587,8 +580,7 @@ fn run_install(project: bool, force: bool, non_interactive: bool) -> Result<()>
587580

588581
// Write plugin manifest
589582
let manifest_path = plugin_manifest_dir.join("plugin.json");
590-
std::fs::write(&manifest_path, PLUGIN_MANIFEST)
591-
.context("failed to write plugin.json")?;
583+
std::fs::write(&manifest_path, PLUGIN_MANIFEST).context("failed to write plugin.json")?;
592584
output::success("Plugin manifest -> ~/.claude/plugins/great/.claude-plugin/plugin.json");
593585

594586
// Write agent files
@@ -604,10 +596,7 @@ fn run_install(project: bool, force: bool, non_interactive: bool) -> Result<()>
604596

605597
// Write skill files
606598
for skill in SKILLS {
607-
let path = plugin_dir
608-
.join("skills")
609-
.join(skill.name)
610-
.join("SKILL.md");
599+
let path = plugin_dir.join("skills").join(skill.name).join("SKILL.md");
611600
std::fs::write(&path, skill.content)
612601
.with_context(|| format!("failed to write skill file: {}", path.display()))?;
613602
}
@@ -618,14 +607,12 @@ fn run_install(project: bool, force: bool, non_interactive: bool) -> Result<()>
618607

619608
// Write hooks.json
620609
let hooks_json_path = plugin_hooks_dir.join("hooks.json");
621-
std::fs::write(&hooks_json_path, HOOKS_JSON)
622-
.context("failed to write hooks.json")?;
610+
std::fs::write(&hooks_json_path, HOOKS_JSON).context("failed to write hooks.json")?;
623611
output::success("Hooks config -> ~/.claude/plugins/great/hooks/hooks.json");
624612

625613
// Write hook handler script
626614
let hook_script_path = plugin_scripts_dir.join("update-state.sh");
627-
std::fs::write(&hook_script_path, HOOK_UPDATE_STATE)
628-
.context("failed to write hook script")?;
615+
std::fs::write(&hook_script_path, HOOK_UPDATE_STATE).context("failed to write hook script")?;
629616

630617
// Make executable (Unix only)
631618
#[cfg(unix)]
@@ -646,8 +633,7 @@ fn run_install(project: bool, force: bool, non_interactive: bool) -> Result<()>
646633
.context("failed to write observer-template.md")?;
647634

648635
let teams_cfg_path = plugin_dir.join("teams-config.json");
649-
std::fs::write(&teams_cfg_path, TEAMS_CONFIG)
650-
.context("failed to write teams-config.json")?;
636+
std::fs::write(&teams_cfg_path, TEAMS_CONFIG).context("failed to write teams-config.json")?;
651637

652638
// --- Phase 3: Side-effects outside plugin ---
653639

@@ -762,9 +748,7 @@ fn run_install(project: bool, force: bool, non_interactive: bool) -> Result<()>
762748
// No hooks key at all — just handle statusLine
763749
let needs_statusline = if !obj.contains_key("statusLine") {
764750
true
765-
} else if let Some(sl) =
766-
obj.get("statusLine").and_then(|v| v.as_object())
767-
{
751+
} else if let Some(sl) = obj.get("statusLine").and_then(|v| v.as_object()) {
768752
!sl.contains_key("type")
769753
} else {
770754
false
@@ -818,9 +802,7 @@ fn run_install(project: bool, force: bool, non_interactive: bool) -> Result<()>
818802
.context("failed to serialize default settings")?;
819803
std::fs::write(&settings_path, formatted)
820804
.context("failed to write ~/.claude/settings.json")?;
821-
output::success(
822-
"Settings with Agent Teams and statusLine -> ~/.claude/settings.json",
823-
);
805+
output::success("Settings with Agent Teams and statusLine -> ~/.claude/settings.json");
824806
}
825807

826808
// Project working state
@@ -891,7 +873,10 @@ fn run_status() -> Result<()> {
891873
println!();
892874

893875
// Check plugin manifest
894-
let plugin_ok = plugin_dir.join(".claude-plugin").join("plugin.json").exists();
876+
let plugin_ok = plugin_dir
877+
.join(".claude-plugin")
878+
.join("plugin.json")
879+
.exists();
895880
if plugin_ok {
896881
output::success("Plugin manifest: installed");
897882
} else {
@@ -907,7 +892,11 @@ fn run_status() -> Result<()> {
907892
}
908893

909894
// Check key skill file in plugin dir
910-
let skills_ok = plugin_dir.join("skills").join("loop").join("SKILL.md").exists();
895+
let skills_ok = plugin_dir
896+
.join("skills")
897+
.join("loop")
898+
.join("SKILL.md")
899+
.exists();
911900
if skills_ok {
912901
output::success("Plugin skills: installed");
913902
} else {
@@ -1059,8 +1048,8 @@ fn run_uninstall() -> Result<()> {
10591048
// Clean settings.json (remove env var, statusLine, and any leftover hooks)
10601049
let settings_path = claude_dir.join("settings.json");
10611050
if settings_path.exists() {
1062-
let contents = std::fs::read_to_string(&settings_path)
1063-
.context("failed to read settings.json")?;
1051+
let contents =
1052+
std::fs::read_to_string(&settings_path).context("failed to read settings.json")?;
10641053
if let Ok(mut val) = serde_json::from_str::<serde_json::Value>(&contents) {
10651054
if let Some(obj) = val.as_object_mut() {
10661055
let mut modified = false;
@@ -1467,8 +1456,7 @@ mod tests {
14671456

14681457
#[test]
14691458
fn test_hooks_json_has_all_events() {
1470-
let parsed: serde_json::Value =
1471-
serde_json::from_str(HOOKS_JSON).expect("valid JSON");
1459+
let parsed: serde_json::Value = serde_json::from_str(HOOKS_JSON).expect("valid JSON");
14721460
let obj = parsed.as_object().expect("hooks.json must be an object");
14731461
let expected = [
14741462
"SubagentStart",

src/cli/statusline.rs

Lines changed: 43 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -290,19 +290,13 @@ fn parse_session_info_bytes(input: &[u8]) -> SessionInfo {
290290
.or_else(|| root.get("cost_usd").and_then(json_f64));
291291

292292
// total_duration_ms: /cost/total_duration_ms
293-
let total_duration_ms = root
294-
.pointer("/cost/total_duration_ms")
295-
.and_then(json_u64);
293+
let total_duration_ms = root.pointer("/cost/total_duration_ms").and_then(json_u64);
296294

297295
// lines_added: /cost/total_lines_added
298-
let lines_added = root
299-
.pointer("/cost/total_lines_added")
300-
.and_then(json_u64);
296+
let lines_added = root.pointer("/cost/total_lines_added").and_then(json_u64);
301297

302298
// lines_removed: /cost/total_lines_removed
303-
let lines_removed = root
304-
.pointer("/cost/total_lines_removed")
305-
.and_then(json_u64);
299+
let lines_removed = root.pointer("/cost/total_lines_removed").and_then(json_u64);
306300

307301
// context_tokens: sum /context_window/total_input_tokens + total_output_tokens
308302
// -> /context_tokens (flat)
@@ -321,7 +315,10 @@ fn parse_session_info_bytes(input: &[u8]) -> SessionInfo {
321315
(None, None) => root
322316
.get("context_tokens")
323317
.and_then(json_u64)
324-
.or_else(|| root.pointer("/context_window/used_tokens").and_then(json_u64))
318+
.or_else(|| {
319+
root.pointer("/context_window/used_tokens")
320+
.and_then(json_u64)
321+
})
325322
.or_else(|| root.pointer("/context_window/used").and_then(json_u64)),
326323
}
327324
};
@@ -334,7 +331,10 @@ fn parse_session_info_bytes(input: &[u8]) -> SessionInfo {
334331
.pointer("/context_window/context_window_size")
335332
.and_then(json_u64)
336333
.or_else(|| root.get("context_window").and_then(json_u64))
337-
.or_else(|| root.pointer("/context_window/max_tokens").and_then(json_u64))
334+
.or_else(|| {
335+
root.pointer("/context_window/max_tokens")
336+
.and_then(json_u64)
337+
})
338338
.or_else(|| root.pointer("/context_window/max").and_then(json_u64));
339339

340340
// used_percentage: /context_window/used_percentage
@@ -343,9 +343,7 @@ fn parse_session_info_bytes(input: &[u8]) -> SessionInfo {
343343
.and_then(json_f64);
344344

345345
// exceeds_200k: /exceeds_200k_tokens
346-
let exceeds_200k = root
347-
.get("exceeds_200k_tokens")
348-
.and_then(|v| v.as_bool());
346+
let exceeds_200k = root.get("exceeds_200k_tokens").and_then(|v| v.as_bool());
349347

350348
// session_id: /session_id
351349
let session_id = root.get("session_id").and_then(json_string);
@@ -616,16 +614,14 @@ fn render_cost(session: &SessionInfo) -> Option<String> {
616614
/// Medium/narrow: 42%
617615
fn render_context_bar(session: &SessionInfo, width: u16, use_unicode: bool) -> Option<String> {
618616
// Get percentage: prefer used_percentage, fallback to calculation
619-
let pct = session
620-
.used_percentage
621-
.or_else(|| {
622-
let tokens = session.context_tokens? as f64;
623-
let window = session.context_window? as f64;
624-
if window == 0.0 {
625-
return None;
626-
}
627-
Some((tokens / window) * 100.0)
628-
})?;
617+
let pct = session.used_percentage.or_else(|| {
618+
let tokens = session.context_tokens? as f64;
619+
let window = session.context_window? as f64;
620+
if window == 0.0 {
621+
return None;
622+
}
623+
Some((tokens / window) * 100.0)
624+
})?;
629625

630626
let pct_clamped = pct.clamp(0.0, 100.0);
631627

@@ -665,10 +661,7 @@ fn render_context_bar(session: &SessionInfo, width: u16, use_unicode: bool) -> O
665661

666662
/// Render the model display name, dimmed.
667663
fn render_model(session: &SessionInfo) -> Option<String> {
668-
session
669-
.model_name
670-
.as_ref()
671-
.map(|m| m.dimmed().to_string())
664+
session.model_name.as_ref().map(|m| m.dimmed().to_string())
672665
}
673666

674667
/// Render lines changed segment (e.g. "+12 -3").
@@ -837,9 +830,12 @@ fn has_loop(state: &LoopState) -> bool {
837830

838831
/// Returns true if any agent is in an active state (Running, Queued, or Error).
839832
fn is_loop_active(agents: &[AgentState]) -> bool {
840-
agents
841-
.iter()
842-
.any(|a| matches!(a.status, AgentStatus::Running | AgentStatus::Queued | AgentStatus::Error))
833+
agents.iter().any(|a| {
834+
matches!(
835+
a.status,
836+
AgentStatus::Running | AgentStatus::Queued | AgentStatus::Error
837+
)
838+
})
843839
}
844840

845841
// ---------------------------------------------------------------------------
@@ -1386,7 +1382,11 @@ session_timeout_secs = 60
13861382
};
13871383
let config = StatuslineConfig::default();
13881384
let line = render(&session, &state, &config, 150, true, false, false);
1389-
assert!(line.contains("loop"), "active loop should show 'loop': {}", line);
1385+
assert!(
1386+
line.contains("loop"),
1387+
"active loop should show 'loop': {}",
1388+
line
1389+
);
13901390
assert!(line.contains("$0.14"), "should show cost: {}", line);
13911391
assert!(line.contains("22%"), "should show context %: {}", line);
13921392
}
@@ -1571,14 +1571,12 @@ session_timeout_secs = 60
15711571
};
15721572
let state = LoopState {
15731573
started_at: Some(0),
1574-
agents: vec![
1575-
AgentState {
1576-
id: 1,
1577-
name: "a".into(),
1578-
status: AgentStatus::Running,
1579-
updated_at: 0,
1580-
},
1581-
],
1574+
agents: vec![AgentState {
1575+
id: 1,
1576+
name: "a".into(),
1577+
status: AgentStatus::Running,
1578+
updated_at: 0,
1579+
}],
15821580
..Default::default()
15831581
};
15841582
let config = StatuslineConfig::default();
@@ -1788,11 +1786,7 @@ session_timeout_secs = 60
17881786
assert!(result.is_some());
17891787
let r = result.unwrap();
17901788
assert!(r.contains("30%"), "should contain 30%: {}", r);
1791-
assert!(
1792-
r.contains('\u{2588}'),
1793-
"wide mode should have bar: {}",
1794-
r
1795-
);
1789+
assert!(r.contains('\u{2588}'), "wide mode should have bar: {}", r);
17961790
}
17971791

17981792
#[test]
@@ -1827,11 +1821,7 @@ session_timeout_secs = 60
18271821
let result = render_context_bar(&session, 150, false);
18281822
let r = result.unwrap();
18291823
assert!(r.contains('#'), "ASCII mode should use # for filled: {}", r);
1830-
assert!(
1831-
r.contains('-'),
1832-
"ASCII mode should use - for empty: {}",
1833-
r
1834-
);
1824+
assert!(r.contains('-'), "ASCII mode should use - for empty: {}", r);
18351825
}
18361826

18371827
#[test]
@@ -1899,11 +1889,7 @@ session_timeout_secs = 60
18991889
"State A should not contain 'loop': {}",
19001890
line
19011891
);
1902-
assert!(
1903-
line.contains("$0.14"),
1904-
"State A should show cost: {}",
1905-
line
1906-
);
1892+
assert!(line.contains("$0.14"), "State A should show cost: {}", line);
19071893
assert!(
19081894
line.contains("42%"),
19091895
"State A should show context %: {}",
@@ -2009,17 +1995,12 @@ session_timeout_secs = 60
20091995
"State C should contain 'loop': {}",
20101996
line
20111997
);
2012-
assert!(
2013-
line.contains("$0.14"),
2014-
"State C should show cost: {}",
2015-
line
2016-
);
1998+
assert!(line.contains("$0.14"), "State C should show cost: {}", line);
20171999
}
20182000

20192001
#[test]
20202002
fn test_used_percentage_direct() {
2021-
let json =
2022-
r#"{"context_window":{"used_percentage":42.5,"context_window_size":200000}}"#;
2003+
let json = r#"{"context_window":{"used_percentage":42.5,"context_window_size":200000}}"#;
20232004
let info = parse_session_info_bytes(json.as_bytes());
20242005
assert!((info.used_percentage.unwrap() - 42.5).abs() < f64::EPSILON);
20252006
assert_eq!(info.context_window, Some(200000));

0 commit comments

Comments
 (0)