1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
//! Agent harnesses (clients/runtimes) swarmy reads from disk.
//!
//! A seat is one config/data directory of a harness (for example `~/.claude`, `~/.claude-work`,
//! `~/.gemini/antigravity-cli`, `~/.codex`). Model providers (Anthropic, Google, OpenAI) are separate from
//! harnesses: Antigravity and OpenCode can run models from several providers.
use std::fmt;
use serde::{Deserialize, Serialize};
/// An agent harness whose transcripts and live state swarmy can read offline.
#[derive(
Debug,
Clone,
Copy,
Default,
PartialEq,
Eq,
Hash,
PartialOrd,
Ord,
Serialize,
Deserialize,
clap::ValueEnum,
)]
#[serde(rename_all = "lowercase")]
pub enum Harness {
#[default]
Claude,
Agy,
/// OpenAI's Codex CLI.
Codex,
}
impl Harness {
/// Every harness swarmy knows, in display order.
pub const ALL: [Harness; 3] = [Harness::Claude, Harness::Agy, Harness::Codex];
/// Stable key stored in SQLite (`seats.harness`), JSON output and CLI flags.
pub const TAGS: [&'static str; 3] = ["claude", "agy", "codex"];
pub fn key(self) -> &'static str {
match self {
Harness::Claude => Self::TAGS[0],
Harness::Agy => Self::TAGS[1],
Harness::Codex => Self::TAGS[2],
}
}
/// Compact 2–3 character badge for dense TUI rows when more than one harness is present.
pub fn short(self) -> &'static str {
match self {
Harness::Claude => "cc",
Harness::Agy => "agy",
Harness::Codex => "cdx",
}
}
pub fn display_name(self) -> &'static str {
match self {
Harness::Claude => "Claude Code",
Harness::Agy => "Antigravity",
Harness::Codex => "Codex",
}
}
pub fn from_key(s: &str) -> Option<Harness> {
Harness::ALL
.into_iter()
.find(|h| h.key() == s || h.short() == s || h.aliases().contains(&s))
}
/// Other names a user may type for this harness.
fn aliases(self) -> &'static [&'static str] {
match self {
Harness::Claude => &["claude-code"],
Harness::Agy => &["antigravity"],
Harness::Codex => &["openai-codex", "codex-cli"],
}
}
/// Whether the login vault (`src/vault`) can save and switch logins for seats of this harness.
pub fn supports_vault(self) -> bool {
match self {
Harness::Claude | Harness::Agy | Harness::Codex => true,
}
}
/// Whether one saved login may be in several seats of this harness at once. Codex's refresh
/// tokens are single-use (OpenAI refuses one used before), so two seats would sign each other
/// out.
pub fn shares_logins(self) -> bool {
match self {
Harness::Claude | Harness::Agy => true,
Harness::Codex => false,
}
}
/// Whether this harness caches usage utilization / quota windows on disk.
pub fn supports_limits(self) -> bool {
match self {
Harness::Claude => true,
Harness::Agy | Harness::Codex => false,
}
}
/// Whether `swarmy setup` can install `swarmy statusline` in seats of this harness.
pub fn supports_statusline(self) -> bool {
match self {
Harness::Claude => true,
Harness::Agy | Harness::Codex => false,
}
}
/// Files and dirs that only this harness writes into its config dir. Shared names (Claude
/// Code and Codex both write `sessions/` and `history.jsonl`) are no evidence.
pub fn markers(self) -> &'static [&'static str] {
match self {
Harness::Claude => &["projects", ".credentials.json", ".claude.json"],
Harness::Agy => &[
"conversation_summaries.db",
"presence",
"antigravity-oauth-token",
"jetski_state.pbtxt",
"brain",
],
Harness::Codex => &[
"session_index.jsonl",
"auth.json",
"version.json",
"models_cache.json",
"thread-writer-locks",
],
}
}
/// The harness that wrote a config dir, judged by its [`Harness::markers`] (`has` says
/// whether the dir holds a file or dir of that name). A dir with no marker is a Claude Code
/// seat (what a `[[seat]]` without `harness` meant first); markers of several harnesses are
/// ambiguous, and `Err` names them.
pub fn detect(has: impl Fn(&str) -> bool) -> Result<Harness, Vec<Harness>> {
let found: Vec<Harness> = Harness::ALL
.into_iter()
.filter(|h| h.markers().iter().any(|m| has(m)))
.collect();
match found.as_slice() {
[] => Ok(Harness::Claude),
[h] => Ok(*h),
[_, _, ..] => Err(found),
}
}
/// Whether this harness deletes old transcripts automatically (constraining `keep_raw_days`).
pub fn has_transcript_retention(self) -> bool {
match self {
Harness::Claude => true,
// Codex keeps its rollouts until the user deletes or archives them.
Harness::Agy | Harness::Codex => false,
}
}
}
impl fmt::Display for Harness {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.key())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn keys_and_capabilities() {
for (h, tag) in Harness::ALL.iter().zip(Harness::TAGS) {
assert_eq!(h.key(), tag);
assert_eq!(Harness::from_key(tag), Some(*h));
assert_eq!(Harness::from_key(h.short()), Some(*h));
}
assert_eq!(Harness::from_key("unknown"), None);
assert!(Harness::Claude.supports_vault());
assert!(Harness::Claude.supports_limits());
assert!(Harness::Claude.supports_statusline());
assert!(Harness::Claude.has_transcript_retention());
assert!(Harness::Agy.supports_vault());
assert!(!Harness::Agy.supports_limits());
assert!(!Harness::Agy.supports_statusline());
assert!(!Harness::Agy.has_transcript_retention());
}
fn dir(files: &'static [&'static str]) -> impl Fn(&str) -> bool {
move |f| files.contains(&f)
}
#[test]
fn a_dir_is_judged_by_the_files_only_its_harness_writes() {
// What a used Claude Code config dir holds: `sessions/` and `history.jsonl` too, which
// Codex also writes (review: such a `[[seat]]` was read as a Codex home).
let claude = dir(&["projects", "sessions", "history.jsonl", "settings.json"]);
assert_eq!(Harness::detect(claude), Ok(Harness::Claude));
let codex = dir(&[
"sessions",
"history.jsonl",
"session_index.jsonl",
"auth.json",
]);
assert_eq!(Harness::detect(codex), Ok(Harness::Codex));
let agy = dir(&["brain", "antigravity-oauth-token"]);
assert_eq!(Harness::detect(agy), Ok(Harness::Agy));
// Not used yet: a Claude Code seat, as `[[seat]]` meant before `harness` existed.
assert_eq!(Harness::detect(dir(&[])), Ok(Harness::Claude));
assert_eq!(
Harness::detect(dir(&["sessions", "history.jsonl"])),
Ok(Harness::Claude)
);
assert_eq!(
Harness::detect(dir(&["projects", "auth.json"])),
Err(vec![Harness::Claude, Harness::Codex])
);
}
#[test]
fn markers_belong_to_one_harness() {
for a in Harness::ALL {
for b in Harness::ALL.into_iter().filter(|b| *b != a) {
for m in a.markers() {
assert!(!b.markers().contains(m), "{m} names {a} and {b}");
}
}
}
}
}