shepherd-cli 6.5.0

The canonical shepherd command-line interface over the per-project registry, run artifacts, and sprint pipeline.
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
use std::{
    fs,
    path::{Path, PathBuf},
    process::{Command, Output},
    time::{SystemTime, UNIX_EPOCH},
};

fn binary() -> &'static str {
    env!("CARGO_BIN_EXE_shepherd")
}

fn repository(label: &str) -> PathBuf {
    let nonce = SystemTime::now()
        .duration_since(UNIX_EPOCH)
        .expect("clock is after epoch")
        .as_nanos();
    let root = std::env::temp_dir().join(format!(
        "shepherd-wave-a-models-{label}-{}-{nonce:x}",
        std::process::id()
    ));
    fs::create_dir_all(&root).expect("create fixture root");
    let status = Command::new("git")
        .args(["init", "--quiet"])
        .current_dir(&root)
        .status()
        .expect("initialize fixture repository");
    assert!(status.success());
    root
}

fn run(root: &Path, args: &[&str]) -> Output {
    Command::new(binary())
        .args(args)
        .current_dir(root)
        .env("SHEPHERD_HOME", root.join("isolated-home"))
        .output()
        .expect("run shepherd")
}

/// A bare temporary directory, no git repository -- for commands (like
/// `compile --content-dir`) that never touch project discovery.
fn tmp_dir(label: &str) -> PathBuf {
    let nonce = SystemTime::now()
        .duration_since(UNIX_EPOCH)
        .expect("clock is after epoch")
        .as_nanos();
    let root = std::env::temp_dir().join(format!(
        "shepherd-wave-a-models-{label}-{}-{nonce:x}",
        std::process::id()
    ));
    fs::create_dir_all(&root).expect("create temp root");
    root
}

const ROLES: [&str; 9] = [
    "root",
    "planter",
    "engineer",
    "conductor",
    "critic",
    "discovery",
    "coder",
    "auditor",
    "worker",
];

#[test]
fn models_resolve_and_show_use_portable_default_hints() {
    let root = repository("defaults");

    let resolve = run(&root, &["models", "resolve", "coder"]);
    assert!(
        resolve.status.success(),
        "stderr={}",
        String::from_utf8_lossy(&resolve.stderr)
    );
    assert_eq!(resolve.stdout, b"standard\n");
    assert!(resolve.stderr.is_empty());

    let show = run(&root, &["models", "show", "--json"]);
    assert!(
        show.status.success(),
        "stderr={}",
        String::from_utf8_lossy(&show.stderr)
    );
    assert_eq!(
        show.stdout,
        br#"{
  "root": {"model": "reasoning-high", "source": "default"},
  "planter": {"model": "reasoning-high", "source": "default"},
  "engineer": {"model": "inherit-caller", "source": "default"},
  "conductor": {"model": "inherit-caller", "source": "default"},
  "critic": {"model": "standard", "source": "default"},
  "discovery": {"model": "economy", "source": "default"},
  "coder": {"model": "standard", "source": "default"},
  "auditor": {"model": "standard", "source": "default"},
  "worker": {"model": "standard", "source": "default"}
}
"#
    );
    assert!(show.stderr.is_empty());

    fs::remove_dir_all(root).expect("cleanup fixture");
}

#[test]
fn models_resolve_delegates_harness_translation_to_the_compiler_profiles() {
    let root = repository("harness-profiles");
    // `planter` rather than `engineer`: the leads now inherit the caller, so
    // they are exactly the roles that DO NOT exercise the tier translation this
    // test exists to cover. Planter still pins the reasoning tier and each
    // harness spells it differently, which is the property under test.
    for (harness, expected) in [
        ("claude", b"opus[1m]\n".as_slice()),
        ("codex", b"reasoning-high\n".as_slice()),
        ("pi", b"opus\n".as_slice()),
    ] {
        let output = run(
            &root,
            &["models", "resolve", "planter", "--harness", harness],
        );
        assert!(
            output.status.success(),
            "{harness}: {}",
            String::from_utf8_lossy(&output.stderr)
        );
        assert_eq!(output.stdout, expected, "{harness}");
    }
    // The leads inherit, and each harness spells INHERIT differently too. This
    // is the half a tier-translation test would otherwise stop covering.
    for (harness, expected) in [
        ("claude", b"inherit\n".as_slice()),
        ("codex", b"inherit-caller\n".as_slice()),
        ("pi", b"inherit-caller\n".as_slice()),
    ] {
        for role in ["engineer", "conductor"] {
            let output = run(&root, &["models", "resolve", role, "--harness", harness]);
            assert!(
                output.status.success(),
                "{harness}/{role}: {}",
                String::from_utf8_lossy(&output.stderr)
            );
            assert_eq!(output.stdout, expected, "{harness}/{role}");
        }
    }
    fs::remove_dir_all(root).expect("cleanup fixture");
}

#[test]
fn models_resolve_uses_an_explicit_canonical_config_and_tracks_its_source() {
    let root = repository("config");
    let config_dir = root.join(".shepherd");
    fs::create_dir_all(&config_dir).expect("create native configuration directory");
    fs::write(
        config_dir.join("shepherd.toml"),
        "[models]\ncoder = \"native-coder\"\n",
    )
    .expect("write native configuration");

    let resolve = run(
        &root,
        &[
            "--config",
            ".shepherd/shepherd.toml",
            "models",
            "resolve",
            "coder",
            "--json",
        ],
    );
    assert!(
        resolve.status.success(),
        "stderr={}",
        String::from_utf8_lossy(&resolve.stderr)
    );
    assert_eq!(
        resolve.stdout,
        b"{\n  \"role\": \"coder\",\n  \"model\": \"native-coder\",\n  \"source\": \"config\"\n}\n"
    );
    assert!(resolve.stderr.is_empty());

    fs::remove_dir_all(root).expect("cleanup fixture");
}

#[test]
fn models_negative_inputs_keep_the_oracle_messages_and_exit_code() {
    let root = repository("negative");

    let missing = run(&root, &["models", "resolve"]);
    assert_eq!(missing.status.code(), Some(2));
    assert!(missing.stdout.is_empty());
    assert_eq!(
        missing.stderr,
        b"ERROR: usage: shepherd models resolve <role>\n"
    );

    let unknown = run(&root, &["models", "resolve", "invalid"]);
    assert_eq!(unknown.status.code(), Some(2));
    assert!(unknown.stdout.is_empty());
    assert_eq!(
        unknown.stderr,
        b"ERROR: unknown role: invalid (valid: root planter engineer conductor critic discovery coder auditor worker)\n"
    );

    fs::remove_dir_all(root).expect("cleanup fixture");
}

#[test]
fn models_show_harness_translates_every_role_to_the_harness_native_spelling() {
    let root = repository("show-harness");

    // root/planter are the opus tier; engineer/conductor INHERIT the caller so a
    // lane costs what its run is worth; coder/auditor/worker/critic/discovery
    // are the sonnet tier, which is what makes wide fan-out affordable. Each
    // harness spells all three differently, and root's tier still translates
    // through the ordinary hint table even though its carrier is advisory.
    for (harness, opus_tier, inherit_tier, sonnet_tier, economy_tier) in [
        ("claude", "opus[1m]", "inherit", "sonnet", "haiku"),
        (
            "codex",
            "reasoning-high",
            "inherit-caller",
            "standard",
            "economy",
        ),
        ("pi", "opus", "inherit-caller", "sonnet", "haiku"),
    ] {
        let show = run(&root, &["models", "show", "--harness", harness, "--json"]);
        assert!(
            show.status.success(),
            "{harness}: stderr={}",
            String::from_utf8_lossy(&show.stderr)
        );
        let expected = format!(
            "{{\n  \"root\": {{\"model\": \"{opus_tier}\", \"source\": \"default\"}},\n  \"planter\": {{\"model\": \"{opus_tier}\", \"source\": \"default\"}},\n  \"engineer\": {{\"model\": \"{inherit_tier}\", \"source\": \"default\"}},\n  \"conductor\": {{\"model\": \"{inherit_tier}\", \"source\": \"default\"}},\n  \"critic\": {{\"model\": \"{sonnet_tier}\", \"source\": \"default\"}},\n  \"discovery\": {{\"model\": \"{economy_tier}\", \"source\": \"default\"}},\n  \"coder\": {{\"model\": \"{sonnet_tier}\", \"source\": \"default\"}},\n  \"auditor\": {{\"model\": \"{sonnet_tier}\", \"source\": \"default\"}},\n  \"worker\": {{\"model\": \"{sonnet_tier}\", \"source\": \"default\"}}\n}}\n"
        );
        assert_eq!(String::from_utf8_lossy(&show.stdout), expected, "{harness}");
        assert!(show.stderr.is_empty(), "{harness}");
    }

    // The exact invocation shape the operator names: `--harness` composes
    // with `--md` and reuses the same renderer, byte-identical in shape to
    // the unharnessed table.
    let markdown = run(&root, &["models", "show", "--harness", "claude", "--md"]);
    assert!(
        markdown.status.success(),
        "stderr={}",
        String::from_utf8_lossy(&markdown.stderr)
    );
    let markdown_text = String::from_utf8_lossy(&markdown.stdout);
    assert!(
        markdown_text.starts_with("| role | model | source |\n|---|---|---|\n"),
        "{markdown_text}"
    );
    assert!(
        markdown_text.contains("| root | `opus[1m]` | default |"),
        "{markdown_text}"
    );
    assert!(
        markdown_text.contains("| conductor | `inherit` | default |"),
        "{markdown_text}"
    );
    assert!(
        markdown_text.contains("| engineer | `inherit` | default |"),
        "{markdown_text}"
    );
    assert!(
        markdown_text.contains("| coder | `sonnet` | default |"),
        "{markdown_text}"
    );
    assert!(
        markdown_text.contains("| discovery | `haiku` | default |"),
        "{markdown_text}"
    );

    fs::remove_dir_all(root).expect("cleanup fixture");
}

#[test]
fn models_show_harness_rejects_an_unknown_harness_with_the_resolve_message_shape() {
    let root = repository("show-harness-negative");

    // Before this change, `--harness` was not a recognized flag on `show` at
    // all: `error: unexpected argument '--harness' found`. Now it is
    // recognized and validated exactly like `resolve --harness`.
    let bad = run(&root, &["models", "show", "--harness", "bogus"]);
    assert_eq!(bad.status.code(), Some(2));
    assert!(bad.stdout.is_empty());
    assert_eq!(
        bad.stderr,
        b"ERROR: unknown harness: bogus (valid: claude codex pi)\n"
    );

    fs::remove_dir_all(root).expect("cleanup fixture");
}

#[test]
fn models_show_explicit_default_value_still_reports_source_config() {
    let root = repository("explicit-default-value");
    let config_dir = root.join(".shepherd");
    fs::create_dir_all(&config_dir).expect("create native configuration directory");
    // `coder`'s portable default is exactly `"standard"`. Setting it
    // explicitly to that same value must still report `source: config`.
    // Deriving provenance by comparing the merged value against
    // `ModelsConfig::default()` cannot see this -- the value is identical
    // either way -- and would wrongly render `source: default`. This is the
    // test that distinguishes the exact key-provenance design from the
    // banned default-value-comparison approximation.
    fs::write(
        config_dir.join("shepherd.toml"),
        "[models]\ncoder = \"standard\"\n",
    )
    .expect("write native configuration");

    let show = run(
        &root,
        &[
            "--config",
            ".shepherd/shepherd.toml",
            "models",
            "show",
            "--json",
        ],
    );
    assert!(
        show.status.success(),
        "stderr={}",
        String::from_utf8_lossy(&show.stderr)
    );
    let stdout = String::from_utf8_lossy(&show.stdout);
    assert!(
        stdout.contains("\"coder\": {\"model\": \"standard\", \"source\": \"config\"}"),
        "an explicitly configured role must report source: config even when its \
         value equals the default: {stdout}"
    );
    assert!(
        stdout.contains("\"root\": {\"model\": \"reasoning-high\", \"source\": \"default\"}"),
        "an unconfigured role must still report source: default: {stdout}"
    );

    fs::remove_dir_all(root).expect("cleanup fixture");
}

#[test]
fn models_resolve_all_nine_roles_and_three_harnesses_accept_the_economy_opt_down() {
    let root = repository("economy-opt-down");
    let config_dir = root.join(".shepherd");
    fs::create_dir_all(&config_dir).expect("create native configuration directory");
    let mut body = String::from("[models]\n");
    for role in ROLES {
        body.push_str(&format!("{role} = \"economy\"\n"));
    }
    fs::write(config_dir.join("shepherd.toml"), body).expect("write native configuration");

    for role in ROLES {
        for (harness, expected) in [("claude", "haiku"), ("codex", "economy"), ("pi", "haiku")] {
            let resolve = run(
                &root,
                &[
                    "--config",
                    ".shepherd/shepherd.toml",
                    "models",
                    "resolve",
                    role,
                    "--harness",
                    harness,
                ],
            );
            assert!(
                resolve.status.success(),
                "{role}/{harness}: stderr={}",
                String::from_utf8_lossy(&resolve.stderr)
            );
            assert_eq!(
                resolve.stdout,
                format!("{expected}\n").into_bytes(),
                "{role}/{harness}"
            );
        }
    }

    fs::remove_dir_all(root).expect("cleanup fixture");
}

#[test]
fn codex_agent_types_never_names_an_undispatchable_role() {
    // `[agent_types]` is the set of roles Codex may SPAWN, so it must contain
    // exactly the `dispatchable: true` roles. It used to key on
    // `model_hint == "inherit-caller"`, a proxy that was wrong in both
    // directions: `planter` is `dispatchable: false` and appeared here anyway
    // because its hint is `reasoning-high`, so Codex advertised the
    // operator-escalation role as spawnable; and any role adopting
    // `inherit-caller` -- which `engineer` and `conductor` now do -- would have
    // silently vanished from the table instead.
    //
    // Pinned against the LIVE authored content rather than a snapshot, so it
    // fails the moment an edit changes which roles are dispatchable.
    let content_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
        .ancestors()
        .nth(2)
        .expect("crates/cli has two ancestors up to the repository root")
        .join("content");
    assert!(
        content_dir.join("roles/shepherd.md").is_file(),
        "resolved content dir does not look like the repository's content/: {}",
        content_dir.display()
    );

    let out = tmp_dir("codex-root-exclusion-pin");
    let status = Command::new(binary())
        .arg("compile")
        .args(["--target", "codex"])
        .arg("--content-dir")
        .arg(&content_dir)
        .arg("--out")
        .arg(&out)
        .status()
        .expect("run shepherd compile");
    assert!(status.success());

    let manifest =
        fs::read_to_string(out.join("shepherd.codex.toml")).expect("read generated codex carrier");
    let agent_types = manifest
        .split("[agent_types]\n")
        .nth(1)
        .and_then(|rest| rest.split("\n[models]").next())
        .expect("[agent_types] section exists in the generated codex carrier");
    for undispatchable in ["shepherd", "planter"] {
        assert!(
            !agent_types
                .lines()
                .any(|line| line.trim_start().starts_with(&format!("{undispatchable} "))),
            "`{undispatchable}` is dispatchable: false and must never appear in the \
             codex [agent_types] table:\n{agent_types}"
        );
    }
    // And the leads MUST still be there. They inherit the caller now, which is
    // exactly the shape the old proxy would have excluded.
    for lead in ["engineer", "conductor"] {
        assert!(
            agent_types
                .lines()
                .any(|line| line.trim_start().starts_with(&format!("{lead} "))),
            "`{lead}` is dispatchable and must appear in the codex [agent_types] \
             table:\n{agent_types}"
        );
    }

    fs::remove_dir_all(out).expect("cleanup fixture");
}