shepherd-cli 6.6.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
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
use std::{
    fs,
    path::PathBuf,
    time::{SystemTime, UNIX_EPOCH},
};

use shepherd_cli::{
    content_compiler::{embedded_compile_input, load_compile_input},
    shepherd::compiler::{BudgetClass, BudgetLimits, HarnessProfile, compile, measure_text},
};

const CANONICAL_ROLE_STARTUP_SKILLS: [(&str, &str); 9] = [
    ("auditor", "reviewing"),
    ("coder", "implementing"),
    ("conductor", "lane-execution"),
    ("critic", "reviewing"),
    ("discovery", "researching"),
    ("engineer", "planning"),
    ("planter", "planting"),
    ("shepherd", "shepherd"),
    ("worker", "artifact-work"),
];

#[test]
fn embedded_content_is_the_exact_canonical_authored_corpus() {
    let filesystem = load_compile_input(&content_dir()).expect("load live content");
    let embedded = embedded_compile_input().expect("load embedded content");
    assert_eq!(embedded, filesystem);
}

#[test]
fn canonical_roles_expose_exact_startup_bundles_on_every_target() {
    let input = load_compile_input(&content_dir()).expect("load live content");
    for (role_name, expected_skill) in CANONICAL_ROLE_STARTUP_SKILLS {
        let role = input
            .roles
            .iter()
            .find(|role| role.role == role_name)
            .unwrap_or_else(|| panic!("canonical role {role_name}"));
        assert_eq!(
            role.startup_skill, expected_skill,
            "authored startup skill for {role_name}"
        );
    }

    for profile in HarnessProfile::canonical() {
        let tree = compile(&input, &profile).expect("compile canonical target");
        assert_eq!(
            tree.roles.len(),
            CANONICAL_ROLE_STARTUP_SKILLS.len(),
            "{} canonical role contracts",
            profile.target.as_str()
        );
        for (role_name, expected_skill) in CANONICAL_ROLE_STARTUP_SKILLS {
            let role = tree
                .roles
                .iter()
                .find(|role| role.role == role_name)
                .unwrap_or_else(|| panic!("emitted role {role_name}"));
            assert_eq!(
                role.startup_skill.as_deref(),
                Some(expected_skill),
                "{} startup skill for {role_name}",
                profile.target.as_str()
            );
            assert_eq!(
                role.startup_skill_sha256.as_deref().map(str::len),
                Some(64),
                "{} startup bundle digest for {role_name}",
                profile.target.as_str()
            );

            let skill_prefix = if profile.target.as_str() == "codex" {
                ".agents/skills"
            } else {
                "skills"
            };
            assert!(
                tree.files.iter().any(|file| {
                    file.path == format!("{skill_prefix}/{expected_skill}/SKILL.md")
                }),
                "{} packaged startup bundle for {role_name}",
                profile.target.as_str()
            );
            let carrier = tree
                .files
                .iter()
                .find(|file| file.path == role.carrier_path)
                .unwrap_or_else(|| {
                    panic!(
                        "{} carrier {} for {role_name}",
                        profile.target.as_str(),
                        role.carrier_path
                    )
                });
            match profile.target.as_str() {
                "claude" => assert!(
                    carrier
                        .content
                        .contains(&format!("\nskills: [{expected_skill}]\n")),
                    "Claude native startup attachment for {role_name}"
                ),
                "pi" => assert!(
                    carrier
                        .content
                        .contains(&format!("\nskills: {expected_skill}\n")),
                    "Pi native startup attachment for {role_name}"
                ),
                "codex" if role.dispatchable => assert!(
                    carrier.content.contains(&format!("`${expected_skill}`")),
                    "Codex explicit startup invocation for {role_name}"
                ),
                // Root and the temporary root-local Planter lease are not
                // dispatchable Codex custom agents. Their required startup
                // contracts remain target-final in the manifest and bind to
                // the same packaged bundles without inventing a child role.
                "codex" => assert_eq!(role.carrier_path, "shepherd.codex.toml"),
                target => panic!("unexpected canonical target {target}"),
            }

            let stale_digest = role
                .startup_skill_sha256
                .as_deref()
                .expect("complete startup bundle digest");
            let mut changed_input = input.clone();
            changed_input
                .skills
                .iter_mut()
                .find(|skill| skill.name == expected_skill)
                .expect("canonical startup bundle")
                .body
                .push_str("\n!");
            let changed_tree = compile(&changed_input, &profile).unwrap_or_else(|error| {
                panic!("changed {} bundle: {error}", profile.target.as_str())
            });
            let changed_digest = changed_tree
                .roles
                .iter()
                .find(|role| role.role == role_name)
                .and_then(|role| role.startup_skill_sha256.as_deref())
                .expect("changed startup bundle digest");
            assert_ne!(
                stale_digest,
                changed_digest,
                "{} must invalidate a stale {role_name} startup bundle digest",
                profile.target.as_str()
            );
        }
    }
}

fn content_dir() -> PathBuf {
    PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../content")
}

fn fixture(label: &str) -> PathBuf {
    let nonce = SystemTime::now()
        .duration_since(UNIX_EPOCH)
        .expect("clock")
        .as_nanos();
    let root = std::env::temp_dir().join(format!("shepherd-content-{label}-{nonce:x}"));
    fs::create_dir_all(root.join("content/roles")).expect("roles");
    fs::create_dir_all(root.join("content/skills/example")).expect("skills");
    root
}

#[test]
fn filesystem_fixture_emits_target_native_startup_skill_attachments() {
    let root = fixture("startup-skill");
    let content = root.join("content");
    fs::write(
        content.join("roles/example.md"),
        "---\nrole: example\ndescription: \"Example role\"\nsource: agents/example.md\nmodel_hint: standard\nwrite_eligible: true\ndispatchable: true\ncapabilities: [read]\nskill: example\nwrite_scope: \"assigned scope\"\n---\n\n# example\n\nDo the work.\n",
    )
    .expect("role");
    fs::write(
        content.join("skills/example/SKILL.md"),
        "---\nname: example\ndescription: \"Example startup skill\"\nsource: skills/example/SKILL.md\nportability: cross-harness\n---\n\n# example\n\nFollow the contract.\n",
    )
    .expect("skill");

    let input = load_compile_input(&content).expect("typed fixture");
    assert_eq!(input.roles[0].startup_skill, "example");
    let claude = compile(&input, &HarnessProfile::claude()).expect("Claude fixture");
    assert!(claude.files[0].content.contains("\nskills: [example]\n"));
    let codex = compile(&input, &HarnessProfile::codex()).expect("Codex fixture");
    assert!(
        codex
            .files
            .iter()
            .any(|file| file.path == ".codex/agents/example.toml")
    );
    let pi = compile(&input, &HarnessProfile::pi()).expect("Pi fixture");
    assert!(
        pi.files
            .iter()
            .find(|file| file.path == "prompts/example.md")
            .expect("Pi prompt")
            .content
            .contains("\nskills: example\n")
    );
    fs::remove_dir_all(root).expect("cleanup");
}

#[test]
fn live_content_matches_the_frozen_target_final_oracle() {
    let input = load_compile_input(&content_dir()).expect("load live content");
    assert_eq!(input.roles.len(), 9);
    for lead in ["engineer", "conductor"] {
        let role = input
            .roles
            .iter()
            .find(|role| role.role == lead)
            .expect("canonical reasoning lead exists");
        assert_eq!(role.model_hint, "reasoning-high", "{lead}");
    }
    // The live authored corpus has 19 skills, including the distinct plant
    // command entry and planting behavior. Confirm the count from the
    // compiler input, not a derived filesystem walk, so a missing embedded
    // skill remains visible in this gate.
    let conductor = input
        .roles
        .iter()
        .find(|role| role.role == "conductor")
        .expect("canonical conductor exists");
    assert!(conductor.body.contains("independent Auditor review"));
    assert!(conductor.body.contains("Require each result artifact"));
    assert!(conductor.body.contains("is not acceptance;"));
    assert!(conductor.body.contains("digest-bound handoff"));
    assert!(
        !conductor
            .body
            .contains("never dispatches a plan-authoring or gating role directly")
    );
    assert_eq!(input.skills.len(), 19);
    for name in ["plant", "planting"] {
        assert!(
            input.skills.iter().any(|skill| skill.name == name),
            "{name}"
        );
    }
    let oracle: serde_json::Value = serde_json::from_str(include_str!(
        "../../../conformance/content-target-final.json"
    ))
    .expect("target-final oracle is valid JSON");
    assert_eq!(oracle["schema"], "shepherd.content-target-final/1");

    for profile in HarnessProfile::canonical() {
        let tree = compile(&input, &profile).expect("compile live content");
        let target = profile.target.as_str();
        let expected = &oracle["targets"][target];
        let expected_files = expected["files"].as_object().expect("oracle files");
        assert_eq!(tree.roles.len(), 9);
        assert_eq!(tree.files.len(), expected_files.len());
        assert_eq!(
            tree.digest,
            expected["tree_digest"].as_str().unwrap(),
            "{target}"
        );
        for file in &tree.files {
            let frozen = expected_files
                .get(&file.path)
                .unwrap_or_else(|| panic!("{target}: missing frozen path {}", file.path))
                .as_array()
                .expect("[bytes, sha256]");
            assert_eq!(
                file.content.len(),
                usize::try_from(frozen[0].as_u64().expect("byte count"))
                    .expect("byte count fits usize"),
                "{target}: {} byte count",
                file.path
            );
            assert_eq!(
                file.content_sha256,
                frozen[1].as_str().expect("content digest"),
                "{target}: {} digest",
                file.path
            );
        }

        for (role_name, expected_role) in oracle["roles"].as_object().expect("oracle roles") {
            let role = tree
                .roles
                .iter()
                .find(|role| &role.role == role_name)
                .unwrap_or_else(|| panic!("{target}: missing role {role_name}"));
            assert_eq!(
                role.model_hint,
                expected_role["model_hint"]
                    .as_str()
                    .expect("oracle model_hint"),
                "portable model hint for {role_name}"
            );
            match target {
                "claude" => assert_eq!(
                    role.model.as_deref(),
                    expected_role["claude_model"].as_str(),
                    "Claude model for {role_name}"
                ),
                "codex" => {
                    assert_eq!(
                        role.model.as_deref(),
                        expected_role["codex_model"].as_str(),
                        "Codex model for {role_name}"
                    );
                    assert_eq!(
                        role.profile.as_deref(),
                        expected_role["codex_profile"].as_str(),
                        "Codex profile for {role_name}"
                    );
                    assert_eq!(
                        role.reasoning_effort.as_deref(),
                        expected_role["codex_effort"].as_str(),
                        "Codex effort for {role_name}"
                    );
                }
                "pi" => {
                    assert_eq!(
                        role.model.as_deref(),
                        expected_role["pi_model"].as_str(),
                        "Pi model for {role_name}"
                    );
                    assert_eq!(
                        serde_json::to_value(&role.tools).expect("Pi tools JSON"),
                        expected_role["pi_tools"],
                        "Pi tools for {role_name}"
                    );
                    assert_eq!(
                        serde_json::to_value(&role.unsupported_capabilities)
                            .expect("Pi unsupported JSON"),
                        expected_role["pi_unsupported"],
                        "Pi unsupported capabilities for {role_name}"
                    );
                }
                _ => unreachable!("canonical target"),
            }
        }
    }
}

#[test]
fn codex_target_final_config_bytes_are_frozen() {
    // Two properties are frozen here, and both were wrong before.
    //
    // `[agent_types]` lists only `dispatchable` roles. It used to key on
    // `model_hint == "inherit-caller"`, a proxy that got `planter` wrong in the
    // dangerous direction: planter is `dispatchable: false` and Codex advertised
    // it as spawnable anyway, exposing the operator-escalation role. Root was
    // excluded only because its hint happened to match.
    //
    // `[models]` pins engineer and conductor to compiler-owned reasoning-high.
    // A fresh lead must not inherit an ambient parent model or effort.
    const EXPECTED: &str = "# Generated by the canonical Rust shepherd compiler. Source: content/roles/*.md.\n\
# Do not hand-edit; regenerate via `shepherd compile --target codex --out <directory>`.\n\n\
max_concurrent_children = 3\n\n\
[agent_types]\n\
auditor = \"explorer\"\n\
coder = \"worker\"\n\
conductor = \"worker\"\n\
critic = \"explorer\"\n\
discovery = \"explorer\"\n\
engineer = \"worker\"\n\
worker = \"worker\"\n\n\
[models]\n\
auditor = \"standard\"\n\
coder = \"standard\"\n\
conductor = \"reasoning-high\"\n\
critic = \"standard\"\n\
discovery = \"economy\"\n\
engineer = \"reasoning-high\"\n\
planter = \"reasoning-high\"\n\
worker = \"standard\"\n\n\
[profiles.\"economy\"]\n\
reasoning_effort = \"low\"\n\n\
[profiles.\"reasoning-high\"]\n\
reasoning_effort = \"high\"\n\n\
[profiles.\"standard\"]\n\
reasoning_effort = \"medium\"\n";

    let input = load_compile_input(&content_dir()).expect("load live content");
    let tree = compile(&input, &HarnessProfile::codex()).expect("compile Codex");
    let config = tree
        .files
        .iter()
        .find(|file| file.path == "shepherd.codex.toml")
        .expect("Codex config");
    assert_eq!(config.content, EXPECTED);
}

#[test]
fn live_authored_entrypoints_respect_every_file_budget() {
    let input = load_compile_input(&content_dir()).expect("load live content");
    let mut violations = Vec::new();
    for (name, class, source) in input
        .roles
        .iter()
        .map(|role| {
            (
                role.source_path.as_str(),
                BudgetClass::Role,
                role.source_content.as_str(),
            )
        })
        .chain(input.skills.iter().map(|skill| {
            (
                skill.source_path.as_str(),
                BudgetClass::Skill,
                skill.source_content.as_str(),
            )
        }))
    {
        let measured = measure_text(source);
        let (lines, words, bytes) = BudgetLimits::for_class(class);
        eprintln!(
            "{name}: {} lines, {} words, {} bytes, {} prompt tokens",
            measured.lines, measured.words, measured.utf8_bytes, measured.prompt_tokens
        );
        if measured.lines > lines || measured.words > words || measured.utf8_bytes > bytes {
            violations.push(format!(
                "{name}: {}/{lines} lines, {}/{words} words, {}/{bytes} bytes",
                measured.lines, measured.words, measured.utf8_bytes
            ));
        }
    }
    assert!(violations.is_empty(), "{}", violations.join("\n"));
}

#[test]
fn malformed_metadata_and_symlinks_fail_closed_without_echoing_content() {
    let root = fixture("invalid");
    let content = root.join("content");
    fs::write(
        content.join("roles/coder.md"),
        "---\nrole: coder\ndescription: [secret]\nsource: agents/coder.md\nmodel_hint: standard\nwrite_eligible: true\ndispatchable: true\ncapabilities: [read]\nwrite_scope: scope\n---\nbody\n",
    )
    .expect("role");
    fs::write(
        content.join("skills/example/SKILL.md"),
        "---\nname: example\ndescription: ok\nsource: x\nportability: cross-harness\n---\nbody\n",
    )
    .expect("skill");
    let error = load_compile_input(&content).expect_err("typed description");
    let message = error.message_text().expect("message");
    assert!(message.contains("invalid role frontmatter"));
    assert!(!message.contains("secret"));

    fs::remove_file(content.join("roles/coder.md")).expect("remove invalid role");
    // The symlink refusal is asserted on every platform that can BUILD a
    // symlink. Windows needs Developer Mode or elevation, so the check is
    // skipped there rather than asserted against a file that was never created
    // -- and it says so, because a silent skip reads exactly like a pass.
    let target = content.join("skills/example/SKILL.md");
    let link = content.join("roles/coder.md");
    #[cfg(unix)]
    let linked = std::os::unix::fs::symlink(&target, &link).is_ok();
    #[cfg(windows)]
    let linked = std::os::windows::fs::symlink_file(&target, &link).is_ok();
    #[cfg(not(any(unix, windows)))]
    let linked = false;

    if linked {
        let error = load_compile_input(&content).expect_err("symlink");
        assert!(error.message_text().expect("message").contains("symlink"));
    } else {
        eprintln!("skipped the symlink refusal: this environment cannot create a symlink");
    }

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