skillfile 1.4.2

Tool-agnostic AI skill & agent manager - the Brewfile for your AI tooling
Documentation
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
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
use std::collections::HashMap;
use std::path::Path;

use skillfile_core::error::SkillfileError;
use skillfile_core::lock::{lock_key, read_lock};
use skillfile_core::models::{short_sha, Entry, LockEntry, Manifest, SourceFields};
use skillfile_core::parser::MANIFEST_NAME;
use skillfile_core::patch::{has_dir_patch, has_patch, walkdir};
use skillfile_deploy::paths::{installed_dir_files, installed_path};
use skillfile_sources::strategy::{content_file, is_dir_entry, meta_sha};
use skillfile_sources::sync::vendor_dir_for;

fn is_cache_file_modified(
    cache_file: &std::path::PathBuf,
    vdir: &std::path::PathBuf,
    installed: &HashMap<String, std::path::PathBuf>,
) -> Result<bool, ()> {
    let filename = cache_file
        .strip_prefix(vdir)
        .map_err(|_| ())?
        .to_string_lossy()
        .to_string();
    let inst_path = match installed.get(&filename) {
        Some(p) if p.exists() => p,
        _ => return Ok(false),
    };
    let cache_text = std::fs::read_to_string(cache_file).map_err(|_| ())?;
    let installed_text = std::fs::read_to_string(inst_path).map_err(|_| ())?;
    Ok(installed_text != cache_text)
}

fn check_dir_files_modified(
    entry: &Entry,
    manifest: &Manifest,
    repo_root: &Path,
) -> Result<bool, ()> {
    let installed = installed_dir_files(entry, manifest, repo_root).map_err(|_| ())?;
    if installed.is_empty() {
        return Ok(false);
    }
    // If pinned, the installed files are expected to differ from cache
    if has_dir_patch(entry, repo_root) {
        return Ok(false);
    }
    let vdir = vendor_dir_for(entry, repo_root);
    if !vdir.is_dir() {
        return Ok(false);
    }
    for cache_file in walkdir(&vdir) {
        if cache_file.file_name().is_none_or(|n| n == ".meta") {
            continue;
        }
        if is_cache_file_modified(&cache_file, &vdir, &installed)? {
            return Ok(true);
        }
    }
    Ok(false)
}

fn is_dir_modified_local(entry: &Entry, manifest: &Manifest, repo_root: &Path) -> bool {
    check_dir_files_modified(entry, manifest, repo_root).unwrap_or(false)
}

fn check_single_file_modified(
    entry: &Entry,
    manifest: &Manifest,
    repo_root: &Path,
) -> Result<bool, ()> {
    let dest = installed_path(entry, manifest, repo_root).map_err(|_| ())?;
    if !dest.exists() {
        return Ok(false);
    }
    let vdir = vendor_dir_for(entry, repo_root);
    let cf = content_file(entry);
    if cf.is_empty() {
        return Ok(false);
    }
    let cache_file = vdir.join(&cf);
    if !cache_file.exists() {
        return Ok(false);
    }
    // If pinned, the installed file is expected to differ from cache
    if has_patch(entry, repo_root) {
        return Ok(false);
    }
    let cache_text = std::fs::read_to_string(&cache_file).map_err(|_| ())?;
    let installed_text = std::fs::read_to_string(&dest).map_err(|_| ())?;
    Ok(installed_text != cache_text)
}

/// Check if an installed file differs from cache (local only, no network).
fn is_modified_local(entry: &Entry, manifest: &Manifest, repo_root: &Path) -> bool {
    if matches!(entry.source, SourceFields::Local { .. }) {
        return false;
    }
    if is_dir_entry(entry) {
        return is_dir_modified_local(entry, manifest, repo_root);
    }
    check_single_file_modified(entry, manifest, repo_root).unwrap_or(false)
}

struct StatusContext<'a> {
    manifest: &'a Manifest,
    repo_root: &'a Path,
    locked: &'a std::collections::BTreeMap<String, LockEntry>,
    check_upstream: bool,
    sha_cache: &'a mut HashMap<(String, String), String>,
    col_w: usize,
}

fn resolve_upstream_sha(
    ctx: &mut StatusContext<'_>,
    owner_repo: &str,
    ref_: &str,
) -> Result<String, SkillfileError> {
    let cache_key = (owner_repo.to_string(), ref_.to_string());
    if let Some(cached) = ctx.sha_cache.get(&cache_key) {
        return Ok(cached.clone());
    }
    let client = skillfile_sources::http::UreqClient::new();
    let resolved = skillfile_sources::resolver::resolve_github_sha(&client, owner_repo, ref_)?;
    ctx.sha_cache.insert(cache_key, resolved.clone());
    Ok(resolved)
}

fn upstream_status_for_github(
    ctx: &mut StatusContext<'_>,
    entry: &Entry,
    sha: &str,
) -> Result<String, SkillfileError> {
    let SourceFields::Github {
        owner_repo, ref_, ..
    } = &entry.source
    else {
        return Ok(format!("locked    sha={}", short_sha(sha)));
    };
    let owner_repo = owner_repo.clone();
    let ref_ = ref_.clone();
    let upstream_sha = resolve_upstream_sha(ctx, &owner_repo, &ref_)?;
    let sha_short = short_sha(sha);
    if upstream_sha == sha {
        Ok(format!("up to date  sha={sha_short}"))
    } else {
        let upstream_short = short_sha(&upstream_sha);
        Ok(format!(
            "outdated    locked={sha_short}  upstream={upstream_short}"
        ))
    }
}

fn build_annotation(entry: &Entry, ctx: &StatusContext<'_>) -> String {
    let mut parts = Vec::new();
    if has_patch(entry, ctx.repo_root) || has_dir_patch(entry, ctx.repo_root) {
        parts.push("[pinned]");
    }
    if is_modified_local(entry, ctx.manifest, ctx.repo_root) {
        parts.push("[modified]");
    }
    if parts.is_empty() {
        String::new()
    } else {
        format!("  {}", parts.join("  "))
    }
}

fn format_entry_status(
    entry: &Entry,
    ctx: &mut StatusContext<'_>,
) -> Result<String, SkillfileError> {
    let key = lock_key(entry);
    let name = &entry.name;
    let col_w = ctx.col_w;

    if let SourceFields::Local { path } = &entry.source {
        let status = if ctx.repo_root.join(path).exists() {
            "local".to_string()
        } else {
            format!("local  \u{2717} path missing: {path}")
        };
        return Ok(format!("{name:<col_w$} {status}"));
    }

    let Some(locked_info) = ctx.locked.get(&key) else {
        return Ok(format!("{name:<col_w$} unlocked"));
    };

    let sha = &locked_info.sha;
    let vdir = vendor_dir_for(entry, ctx.repo_root);
    let meta = meta_sha(&vdir);
    let sha_short = short_sha(sha);

    let base_status = if meta.as_deref() != Some(sha.as_str()) {
        format!("locked    sha={sha_short}  (missing or stale)")
    } else if ctx.check_upstream {
        upstream_status_for_github(ctx, entry, sha)?
    } else {
        format!("locked    sha={sha_short}")
    };

    let annotation = build_annotation(entry, ctx);
    Ok(format!("{name:<col_w$} {base_status}{annotation}"))
}

pub fn cmd_status(repo_root: &Path, check_upstream: bool) -> Result<(), SkillfileError> {
    let manifest_path = repo_root.join(MANIFEST_NAME);
    if !manifest_path.exists() {
        return Err(SkillfileError::Manifest(format!(
            "{MANIFEST_NAME} not found in {}. Create one and run `skillfile init`.",
            repo_root.display()
        )));
    }

    let manifest = crate::config::parse_and_resolve(&manifest_path)?;
    let locked = read_lock(repo_root)?;

    let col_w = manifest
        .entries
        .iter()
        .map(|e| e.name.len())
        .max()
        .unwrap_or(10)
        + 2;

    let mut ctx = StatusContext {
        manifest: &manifest,
        repo_root,
        locked: &locked,
        check_upstream,
        sha_cache: &mut HashMap::new(),
        col_w,
    };

    for entry in &manifest.entries {
        let line = format_entry_status(entry, &mut ctx)?;
        println!("{line}");
    }

    Ok(())
}

#[cfg(test)]
mod tests {
    use super::*;
    use skillfile_core::models::{EntityType, InstallTarget, Scope, SourceFields};

    fn write_manifest(dir: &Path, content: &str) {
        std::fs::write(dir.join(MANIFEST_NAME), content).unwrap();
    }

    fn write_lock(dir: &Path, data: &serde_json::Value) {
        std::fs::write(
            dir.join("Skillfile.lock"),
            serde_json::to_string_pretty(data).unwrap(),
        )
        .unwrap();
    }

    struct VendorEntry<'a> {
        entity_type: &'a str,
        name: &'a str,
    }

    fn write_meta(dir: &Path, ve: &VendorEntry<'_>, sha: &str) {
        let vdir = dir
            .join(".skillfile/cache")
            .join(format!("{}s", ve.entity_type))
            .join(ve.name);
        std::fs::create_dir_all(&vdir).unwrap();
        std::fs::write(
            vdir.join(".meta"),
            serde_json::json!({"sha": sha}).to_string(),
        )
        .unwrap();
    }

    struct VendorFile<'a> {
        entry: &'a VendorEntry<'a>,
        filename: &'a str,
    }

    fn write_vendor_content(dir: &Path, vf: &VendorFile<'_>, content: &str) {
        let vdir = dir
            .join(".skillfile/cache")
            .join(format!("{}s", vf.entry.entity_type))
            .join(vf.entry.name);
        std::fs::create_dir_all(&vdir).unwrap();
        std::fs::write(vdir.join(vf.filename), content).unwrap();
    }

    const SHA: &str = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
    const ORIGINAL: &str = "# Agent\n\nUpstream content.\n";
    const MODIFIED: &str = "# Agent\n\nUpstream content.\n\n## Custom Section\n\nAdded by user.\n";
    const VE_AGENT: VendorEntry<'_> = VendorEntry {
        entity_type: "agent",
        name: "my-agent",
    };

    fn local_entry(name: &str, path: &str) -> Entry {
        Entry {
            entity_type: EntityType::Skill,
            name: name.into(),
            source: SourceFields::Local { path: path.into() },
        }
    }

    fn claude_local_target() -> InstallTarget {
        InstallTarget {
            adapter: "claude-code".into(),
            scope: Scope::Local,
        }
    }

    fn agent_manifest() -> Manifest {
        Manifest {
            entries: vec![Entry {
                entity_type: EntityType::Agent,
                name: "my-agent".into(),
                source: SourceFields::Github {
                    owner_repo: "owner/repo".into(),
                    path_in_repo: "agents/agent.md".into(),
                    ref_: "main".into(),
                },
            }],
            install_targets: vec![claude_local_target()],
        }
    }

    fn dir_skill_manifest() -> Manifest {
        Manifest {
            entries: vec![Entry {
                entity_type: EntityType::Skill,
                name: "my-dir".into(),
                source: SourceFields::Github {
                    owner_repo: "owner/repo".into(),
                    path_in_repo: "skills/my-dir".into(),
                    ref_: "main".into(),
                },
            }],
            install_targets: vec![claude_local_target()],
        }
    }

    #[test]
    fn no_manifest() {
        let dir = tempfile::tempdir().unwrap();
        let result = cmd_status(dir.path(), false);
        assert!(result.is_err());
        assert!(result.unwrap_err().to_string().contains("not found"));
    }

    #[test]
    fn local_entry_path_exists_shows_local() {
        let dir = tempfile::tempdir().unwrap();
        let source = dir.path().join("skills/foo.md");
        std::fs::create_dir_all(source.parent().unwrap()).unwrap();
        std::fs::write(&source, "# Foo").unwrap();
        write_manifest(dir.path(), "local  skill  foo  skills/foo.md\n");
        cmd_status(dir.path(), false).unwrap();
    }

    #[test]
    fn local_entry_path_missing_shows_status_without_error() {
        let dir = tempfile::tempdir().unwrap();
        write_manifest(dir.path(), "local  skill  foo  skills/foo.md\n");
        // Missing path should not cause an error — status reports it inline
        cmd_status(dir.path(), false).unwrap();
    }

    #[test]
    fn github_entry_unlocked() {
        let dir = tempfile::tempdir().unwrap();
        write_manifest(
            dir.path(),
            "github  agent  my-agent  owner/repo  agents/agent.md  main\n",
        );
        cmd_status(dir.path(), false).unwrap();
    }

    #[test]
    fn github_entry_locked_vendor_matches() {
        let dir = tempfile::tempdir().unwrap();
        let sha = "87321636a1c666283d8f17398b45c2644395044b";
        write_manifest(
            dir.path(),
            "github  agent  my-agent  owner/repo  agents/agent.md  main\n",
        );
        write_lock(
            dir.path(),
            &serde_json::json!({"github/agent/my-agent": {"sha": sha, "raw_url": "https://example.com"}}),
        );
        write_meta(dir.path(), &VE_AGENT, sha);
        cmd_status(dir.path(), false).unwrap();
    }

    #[test]
    fn github_entry_locked_vendor_missing() {
        let dir = tempfile::tempdir().unwrap();
        let sha = "87321636a1c666283d8f17398b45c2644395044b";
        write_manifest(
            dir.path(),
            "github  agent  my-agent  owner/repo  agents/agent.md  main\n",
        );
        write_lock(
            dir.path(),
            &serde_json::json!({"github/agent/my-agent": {"sha": sha, "raw_url": "https://example.com"}}),
        );
        // No .meta written
        cmd_status(dir.path(), false).unwrap();
    }

    #[test]
    fn modified_shows_for_changed_installed_file() {
        let dir = tempfile::tempdir().unwrap();
        write_lock(
            dir.path(),
            &serde_json::json!({"github/agent/my-agent": {"sha": SHA, "raw_url": "https://example.com"}}),
        );
        write_meta(dir.path(), &VE_AGENT, SHA);
        write_vendor_content(
            dir.path(),
            &VendorFile {
                entry: &VE_AGENT,
                filename: "agent.md",
            },
            ORIGINAL,
        );
        let installed = dir.path().join(".claude/agents");
        std::fs::create_dir_all(&installed).unwrap();
        std::fs::write(installed.join("my-agent.md"), MODIFIED).unwrap();

        // is_modified_local should return true
        let manifest = agent_manifest();
        let entry = &manifest.entries[0];
        assert!(is_modified_local(entry, &manifest, dir.path()));
    }

    #[test]
    fn modified_not_shown_for_clean_entry() {
        let dir = tempfile::tempdir().unwrap();
        write_lock(
            dir.path(),
            &serde_json::json!({"github/agent/my-agent": {"sha": SHA, "raw_url": "https://example.com"}}),
        );
        write_meta(dir.path(), &VE_AGENT, SHA);
        write_vendor_content(
            dir.path(),
            &VendorFile {
                entry: &VE_AGENT,
                filename: "agent.md",
            },
            ORIGINAL,
        );
        let installed = dir.path().join(".claude/agents");
        std::fs::create_dir_all(&installed).unwrap();
        std::fs::write(installed.join("my-agent.md"), ORIGINAL).unwrap();

        let manifest = agent_manifest();
        let entry = &manifest.entries[0];
        assert!(!is_modified_local(entry, &manifest, dir.path()));
    }

    #[test]
    fn modified_not_shown_when_not_installed() {
        let dir = tempfile::tempdir().unwrap();
        write_lock(
            dir.path(),
            &serde_json::json!({"github/agent/my-agent": {"sha": SHA, "raw_url": "https://example.com"}}),
        );
        write_meta(dir.path(), &VE_AGENT, SHA);
        write_vendor_content(
            dir.path(),
            &VendorFile {
                entry: &VE_AGENT,
                filename: "agent.md",
            },
            ORIGINAL,
        );
        // No installed file

        let manifest = agent_manifest();
        let entry = &manifest.entries[0];
        assert!(!is_modified_local(entry, &manifest, dir.path()));
    }

    #[test]
    fn modified_not_shown_without_vendor_cache() {
        let dir = tempfile::tempdir().unwrap();
        write_lock(
            dir.path(),
            &serde_json::json!({"github/agent/my-agent": {"sha": SHA, "raw_url": "https://example.com"}}),
        );
        write_meta(dir.path(), &VE_AGENT, SHA);
        // No vendor cache content file
        let installed = dir.path().join(".claude/agents");
        std::fs::create_dir_all(&installed).unwrap();
        std::fs::write(installed.join("my-agent.md"), MODIFIED).unwrap();

        let manifest = agent_manifest();
        let entry = &manifest.entries[0];
        assert!(!is_modified_local(entry, &manifest, dir.path()));
    }

    // Dir-entry tests: claude-code skills use Nested dir mode (.claude/skills/<name>/)

    /// Build a manifest with a github skill dir entry (path_in_repo without .md).
    /// claude-code skills are Nested, so installed files live under .claude/skills/<name>/.
    fn setup_dir_entry(dir: &Path, installed_content: Option<&str>, cache_content: &str) {
        write_lock(
            dir,
            &serde_json::json!({"github/skill/my-dir": {"sha": SHA, "raw_url": "https://example.com"}}),
        );

        // Write the cache vendor dir with a file
        let vdir = dir.join(".skillfile/cache").join("skills").join("my-dir");
        std::fs::create_dir_all(&vdir).unwrap();
        std::fs::write(vdir.join("tool.md"), cache_content).unwrap();
        std::fs::write(
            vdir.join(".meta"),
            serde_json::json!({"sha": SHA}).to_string(),
        )
        .unwrap();

        // Write the installed nested dir if content is provided
        if let Some(content) = installed_content {
            let installed_dir = dir.join(".claude/skills/my-dir");
            std::fs::create_dir_all(&installed_dir).unwrap();
            std::fs::write(installed_dir.join("tool.md"), content).unwrap();
        }
    }

    #[test]
    fn dir_entry_modified_shows_modified() {
        let dir = tempfile::tempdir().unwrap();
        setup_dir_entry(dir.path(), Some(MODIFIED), ORIGINAL);

        let manifest = dir_skill_manifest();
        let entry = &manifest.entries[0];
        assert!(
            is_dir_entry(entry),
            "expected entry to be recognised as a dir entry"
        );
        assert!(
            is_modified_local(entry, &manifest, dir.path()),
            "expected modified=true when installed content differs from cache"
        );
    }

    #[test]
    fn dir_entry_clean_shows_not_modified() {
        let dir = tempfile::tempdir().unwrap();
        setup_dir_entry(dir.path(), Some(ORIGINAL), ORIGINAL);

        let manifest = dir_skill_manifest();
        let entry = &manifest.entries[0];
        assert!(
            is_dir_entry(entry),
            "expected entry to be recognised as a dir entry"
        );
        assert!(
            !is_modified_local(entry, &manifest, dir.path()),
            "expected modified=false when installed content matches cache"
        );
    }

    #[test]
    fn dir_entry_missing_vendor_dir_not_modified() {
        let dir = tempfile::tempdir().unwrap();
        // Write lock but no vendor cache dir at all
        write_lock(
            dir.path(),
            &serde_json::json!({"github/skill/my-dir": {"sha": SHA, "raw_url": "https://example.com"}}),
        );
        // No .skillfile/cache/skills/my-dir/ written

        let manifest = dir_skill_manifest();
        let entry = &manifest.entries[0];
        assert!(
            is_dir_entry(entry),
            "expected entry to be recognised as a dir entry"
        );
        assert!(
            !is_modified_local(entry, &manifest, dir.path()),
            "expected modified=false when vendor cache dir is absent"
        );
    }

    #[test]
    fn local_entry_always_not_modified() {
        let dir = tempfile::tempdir().unwrap();

        let manifest = Manifest {
            entries: vec![local_entry("foo", "skills/foo.md")],
            ..Manifest::default()
        };
        let entry = &manifest.entries[0];
        assert!(
            !is_modified_local(entry, &manifest, dir.path()),
            "local entries must always report modified=false"
        );
    }

    #[test]
    fn pinned_entry_not_modified() {
        let dir = tempfile::tempdir().unwrap();
        write_lock(
            dir.path(),
            &serde_json::json!({"github/agent/my-agent": {"sha": SHA, "raw_url": "https://example.com"}}),
        );
        write_meta(dir.path(), &VE_AGENT, SHA);
        write_vendor_content(
            dir.path(),
            &VendorFile {
                entry: &VE_AGENT,
                filename: "agent.md",
            },
            ORIGINAL,
        );
        let installed = dir.path().join(".claude/agents");
        std::fs::create_dir_all(&installed).unwrap();
        std::fs::write(installed.join("my-agent.md"), MODIFIED).unwrap();

        // Write a patch file — entry is pinned
        let patches_dir = dir.path().join(".skillfile/patches/agents");
        std::fs::create_dir_all(&patches_dir).unwrap();
        std::fs::write(patches_dir.join("my-agent.patch"), "patch content").unwrap();

        let manifest = agent_manifest();
        let entry = &manifest.entries[0];
        assert!(
            !is_modified_local(entry, &manifest, dir.path()),
            "pinned entries must not report as modified"
        );
    }

    #[test]
    fn dir_entry_pinned_not_modified() {
        let dir = tempfile::tempdir().unwrap();
        setup_dir_entry(dir.path(), Some(MODIFIED), ORIGINAL);

        // Write a dir patch — entry is pinned
        let patches_dir = dir.path().join(".skillfile/patches/skills/my-dir");
        std::fs::create_dir_all(&patches_dir).unwrap();
        std::fs::write(patches_dir.join("tool.md.patch"), "patch content").unwrap();

        let manifest = dir_skill_manifest();
        let entry = &manifest.entries[0];
        assert!(
            !is_modified_local(entry, &manifest, dir.path()),
            "pinned dir entries must not report as modified"
        );
    }

    // -- format_entry_status: local path drift --

    #[test]
    fn local_entry_existing_path_formats_as_local() {
        let dir = tempfile::tempdir().unwrap();
        let source = dir.path().join("skills/foo.md");
        std::fs::create_dir_all(source.parent().unwrap()).unwrap();
        std::fs::write(&source, "# Foo").unwrap();

        let manifest = Manifest {
            entries: vec![local_entry("foo", "skills/foo.md")],
            ..Manifest::default()
        };
        let locked = std::collections::BTreeMap::new();
        let mut sha_cache = HashMap::new();
        let mut ctx = StatusContext {
            manifest: &manifest,
            repo_root: dir.path(),
            locked: &locked,
            check_upstream: false,
            sha_cache: &mut sha_cache,
            col_w: 12,
        };
        let line = format_entry_status(&manifest.entries[0], &mut ctx).unwrap();
        assert!(
            line.contains("local") && !line.contains("path missing"),
            "existing path should show 'local' without warning, got: {line}"
        );
    }

    #[test]
    fn local_entry_missing_path_formats_with_warning() {
        let dir = tempfile::tempdir().unwrap();

        let manifest = Manifest {
            entries: vec![local_entry("foo", "skills/foo.md")],
            ..Manifest::default()
        };
        let locked = std::collections::BTreeMap::new();
        let mut sha_cache = HashMap::new();
        let mut ctx = StatusContext {
            manifest: &manifest,
            repo_root: dir.path(),
            locked: &locked,
            check_upstream: false,
            sha_cache: &mut sha_cache,
            col_w: 12,
        };
        let line = format_entry_status(&manifest.entries[0], &mut ctx).unwrap();
        assert!(
            line.contains("path missing"),
            "missing path should show warning, got: {line}"
        );
        assert!(
            line.contains("skills/foo.md"),
            "warning should include the path, got: {line}"
        );
    }
}