codewhale-tui 0.9.8

Terminal UI for open-source and open-weight coding models
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
use super::*;
use tempfile::TempDir;

fn skill_file(tmp: &TempDir, name: &str) -> std::path::PathBuf {
    tmp.path().join(name).join("SKILL.md")
}

fn skill_dir(tmp: &TempDir, name: &str) -> std::path::PathBuf {
    tmp.path().join(name)
}

fn marker_file(tmp: &TempDir) -> std::path::PathBuf {
    tmp.path().join(".system-installed-version")
}

// ── fresh install ─────────────────────────────────────────────────────────

#[test]
fn fresh_install_creates_bundled_skills_and_marker() {
    let tmp = TempDir::new().unwrap();
    install_system_skills(tmp.path()).unwrap();

    for skill in BUNDLED_SKILLS {
        assert!(
            skill_file(&tmp, skill.name).exists(),
            "{} SKILL.md should be created",
            skill.name
        );
    }
    assert!(marker_file(&tmp).exists(), "marker should be created");

    let ver = fs::read_to_string(marker_file(&tmp)).unwrap();
    assert_eq!(ver.trim(), BUNDLED_SKILL_VERSION);
}

#[test]
fn bundled_integration_skills_use_current_codewhale_commands_and_paths() {
    for (name, body) in [("mcp-builder", MCP_BUILDER_BODY), ("feishu", FEISHU_BODY)] {
        assert!(
            body.contains("codewhale mcp"),
            "{name} must use the current CLI"
        );
        assert!(
            !body.contains("deepseek mcp"),
            "{name} must not recommend the retired CLI name"
        );
    }
    assert!(SKILL_CREATOR_BODY.contains("<workspace>/.codewhale/skills"));
    assert!(SKILL_CREATOR_BODY.contains("~/.codewhale/skills"));
    assert!(SKILL_INSTALLER_BODY.contains("~/.codewhale/skills"));
    // Bundled skills must name live tools. `read_file` is retired and cannot
    // dispatch (crates/tui/src/tools/registry.rs:2067).
    assert!(PDF_BODY.contains("built-in `File` tool (`action: \"read\"`)"));
    for (name, body) in [
        ("pdf", PDF_BODY),
        ("help", HELP_BODY),
        ("delegate", DELEGATE_BODY),
        ("best-of-n", BEST_OF_N_BODY),
    ] {
        assert!(
            !body.contains("read_file") && !body.contains("exec_shell"),
            "{name} must not teach a retired tool name"
        );
    }
}

/// #4227 (requested by @JayBeest): the contributor sync/gate/digest skill
/// ships in generation 8, and its two load-bearing refusals — never move a
/// contributor's HEAD, never touch a dirty tree — must survive any later
/// edit to the body.
#[test]
fn contributor_onboarding_ships_at_generation_8_and_keeps_its_refusals() {
    let skill = BUNDLED_SKILLS
        .iter()
        .find(|skill| skill.name == "contributor-onboarding")
        .expect("contributor-onboarding must be bundled");
    assert_eq!(skill.introduced_in, 8);
    // The pin tracks the current catalog generation: 9 added handoff,
    // 10 added mcp-discovery (#5238).
    assert_eq!(BUNDLED_SKILL_VERSION, "10");

    let body = skill.body;
    assert!(body.contains("invocation: explicit-only"));
    // Read-only by default: sync is proposed, never performed.
    assert!(body.contains("Do not run `git fetch`, `git pull`, `git rebase`"));
    assert!(body.contains("Do not stash, discard, reset, or commit a dirty tree"));
    // The gate is quoted from CI rather than paraphrased, and the digest is
    // built from files rather than generated.
    assert!(body.contains("cargo clippy --workspace --all-features --locked"));
    assert!(body.contains(".github/workflows/ci.yml"));
    assert!(body.contains("Do not call a model provider"));
    // Provider neutrality: the dogfood step sends nothing anywhere.
    assert!(body.contains("./target/release/codewhale exec --help"));
    assert!(body.contains("Never select a provider for them"));
    // Contributor credit is part of the skill's own contract.
    assert!(body.contains("@JayBeest"));
}

#[test]
fn fresh_install_skills_parse_for_discovery() {
    let tmp = TempDir::new().unwrap();
    install_system_skills(tmp.path()).unwrap();

    let registry = crate::skills::SkillRegistry::discover(tmp.path());
    assert!(
        registry.warnings().is_empty(),
        "bundled skills should parse cleanly: {:?}",
        registry.warnings()
    );

    for skill in BUNDLED_SKILLS {
        let parsed = registry
            .get(skill.name)
            .unwrap_or_else(|| panic!("{} should be discoverable", skill.name));
        assert!(
            !parsed.description.is_empty(),
            "{} should include model-visible description",
            skill.name
        );
    }
}

#[test]
fn corrupt_marker_is_repaired_without_overwriting_user_skill_body() {
    let tmp = TempDir::new().unwrap();
    install_system_skills(tmp.path()).unwrap();

    let user_body = "user-edited body";
    fs::write(skill_file(&tmp, "delegate"), user_body).unwrap();
    fs::remove_dir_all(skill_dir(&tmp, "skill-creator")).unwrap();
    fs::write(marker_file(&tmp), "not-a-version").unwrap();

    install_system_skills(tmp.path()).unwrap();

    assert_eq!(
        fs::read_to_string(skill_file(&tmp, "delegate")).unwrap(),
        user_body
    );
    assert!(skill_file(&tmp, "skill-creator").exists());
    assert_eq!(
        fs::read_to_string(marker_file(&tmp)).unwrap().trim(),
        BUNDLED_SKILL_VERSION
    );
}

#[test]
fn directory_marker_is_replaced_and_user_skills_are_preserved() {
    let tmp = TempDir::new().unwrap();
    install_system_skills(tmp.path()).unwrap();

    let user_body = "user-edited body";
    fs::write(skill_file(&tmp, "delegate"), user_body).unwrap();
    fs::remove_dir_all(skill_dir(&tmp, "skill-creator")).unwrap();
    fs::remove_file(marker_file(&tmp)).unwrap();
    fs::create_dir(marker_file(&tmp)).unwrap();
    fs::write(marker_file(&tmp).join("stale-entry"), "stale").unwrap();

    install_system_skills(tmp.path()).unwrap();

    assert_eq!(
        fs::read_to_string(skill_file(&tmp, "delegate")).unwrap(),
        user_body
    );
    assert!(skill_file(&tmp, "skill-creator").exists());
    assert!(marker_file(&tmp).is_file());
    assert_eq!(
        fs::read_to_string(marker_file(&tmp)).unwrap().trim(),
        BUNDLED_SKILL_VERSION
    );
}

#[test]
fn invalid_marker_is_repaired_even_when_no_skill_body_changes() {
    let tmp = TempDir::new().unwrap();
    install_system_skills(tmp.path()).unwrap();
    fs::write(marker_file(&tmp), "").unwrap();

    install_system_skills(tmp.path()).unwrap();

    assert_eq!(
        fs::read_to_string(marker_file(&tmp)).unwrap().trim(),
        BUNDLED_SKILL_VERSION
    );
}

#[test]
fn bundled_catalog_has_two_complete_truthful_tiers() {
    for skill in BUNDLED_SKILLS {
        assert!(
            bundled_skill_tier(skill.name).is_some(),
            "{} must have a picker tier",
            skill.name
        );
    }
    assert_eq!(
        bundled_skill_tier("best-of-n"),
        Some(BundledSkillTier::CoreAgentic)
    );
    assert_eq!(
        bundled_skill_tier("pdf"),
        Some(BundledSkillTier::FormatTooling)
    );
    assert_eq!(bundled_skill_tier("user-created"), None);
    assert!(
        !is_bundled_skill_name("imagine"),
        "do not advertise image generation without an image-generation tool"
    );
}

// ── idempotence ───────────────────────────────────────────────────────────

#[test]
fn calling_twice_is_idempotent() {
    let tmp = TempDir::new().unwrap();
    install_system_skills(tmp.path()).unwrap();

    for skill in BUNDLED_SKILLS {
        fs::write(
            skill_file(&tmp, skill.name),
            format!("{}-sentinel", skill.name),
        )
        .unwrap();
    }

    install_system_skills(tmp.path()).unwrap();

    for skill in BUNDLED_SKILLS {
        let body = fs::read_to_string(skill_file(&tmp, skill.name)).unwrap();
        assert_eq!(
            body,
            format!("{}-sentinel", skill.name),
            "second install should not overwrite {}",
            skill.name
        );
    }
}

// ── user deleted a directory ──────────────────────────────────────────────

#[test]
fn user_deleted_dir_is_not_recreated() {
    let tmp = TempDir::new().unwrap();
    install_system_skills(tmp.path()).unwrap();

    // Simulate user deliberately removing one skill directory.
    fs::remove_dir_all(skill_dir(&tmp, "delegate")).unwrap();

    // Re-launch must NOT recreate the deleted directory.
    install_system_skills(tmp.path()).unwrap();

    assert!(
        !skill_file(&tmp, "delegate").exists(),
        "delegate must not be recreated after user deleted it"
    );
    assert!(
        skill_file(&tmp, "skill-creator").exists(),
        "skill-creator should still be present (not deleted by user)"
    );
}

#[test]
fn user_deleted_all_dirs_are_not_recreated() {
    let tmp = TempDir::new().unwrap();
    install_system_skills(tmp.path()).unwrap();

    for skill in BUNDLED_SKILLS {
        fs::remove_dir_all(skill_dir(&tmp, skill.name)).unwrap();
    }

    install_system_skills(tmp.path()).unwrap();

    for skill in BUNDLED_SKILLS {
        assert!(
            !skill_file(&tmp, skill.name).exists(),
            "{} must not be recreated after user deletion",
            skill.name
        );
    }
}

// ── version bump re-installs ──────────────────────────────────────────────

#[test]
fn outdated_marker_triggers_reinstall_of_existing_skills() {
    let tmp = TempDir::new().unwrap();
    // Exact shipped bodies present with old marker: refresh is allowed and
    // newer skills are added. Non-matching user content is preserved
    // elsewhere (see upgrade_preserves_user_modified_bundled_skill_body).
    for skill in BUNDLED_SKILLS.iter().filter(|s| s.introduced_in <= 4) {
        fs::create_dir_all(skill_dir(&tmp, skill.name)).unwrap();
        fs::write(skill_file(&tmp, skill.name), skill.body).unwrap();
    }
    fs::write(marker_file(&tmp), "0").unwrap();

    install_system_skills(tmp.path()).unwrap();

    for skill in BUNDLED_SKILLS {
        assert!(
            skill_file(&tmp, skill.name).exists(),
            "{} should be installed after marker upgrade",
            skill.name
        );
        let content = fs::read_to_string(skill_file(&tmp, skill.name)).unwrap();
        assert_eq!(
            content, skill.body,
            "{} body should match shipped",
            skill.name
        );
    }
    let ver = fs::read_to_string(marker_file(&tmp)).unwrap();
    assert_eq!(ver.trim(), BUNDLED_SKILL_VERSION);
}

// ── partial previous install ─────────────────────────────────────────────

#[test]
fn version_bump_adds_skills_introduced_after_marker() {
    let tmp = TempDir::new().unwrap();
    // Pre-v5 install: only skills introduced through v4, with exact bodies.
    for skill in BUNDLED_SKILLS.iter().filter(|s| s.introduced_in <= 4) {
        fs::create_dir_all(skill_dir(&tmp, skill.name)).unwrap();
        fs::write(skill_file(&tmp, skill.name), skill.body).unwrap();
    }
    fs::write(marker_file(&tmp), "4").unwrap();

    install_system_skills(tmp.path()).unwrap();

    for skill in BUNDLED_SKILLS.iter().filter(|s| s.introduced_in == 5) {
        assert!(
            skill_file(&tmp, skill.name).exists(),
            "v5 skill {} should be installed on upgrade",
            skill.name
        );
    }
    // Unchanged exact bodies remain current.
    for skill in BUNDLED_SKILLS.iter().filter(|s| s.introduced_in <= 4) {
        let content = fs::read_to_string(skill_file(&tmp, skill.name)).unwrap();
        assert_eq!(content, skill.body);
    }
    let ver = fs::read_to_string(marker_file(&tmp)).unwrap();
    assert_eq!(ver.trim(), BUNDLED_SKILL_VERSION);
}

#[test]
fn version_bump_from_v8_adds_handoff_without_recreating_deleted_skills() {
    let tmp = TempDir::new().unwrap();
    fs::write(marker_file(&tmp), "8").unwrap();

    install_system_skills(tmp.path()).unwrap();

    assert!(skill_file(&tmp, "handoff").is_file());
    assert!(
        !skill_file(&tmp, "delegate").exists(),
        "an intentionally absent older skill must stay absent"
    );
    assert_eq!(
        fs::read_to_string(marker_file(&tmp)).unwrap().trim(),
        BUNDLED_SKILL_VERSION
    );
}

#[test]
fn version_bump_from_v5_adds_best_of_n_without_recreating_deleted_skills() {
    let tmp = TempDir::new().unwrap();
    fs::write(marker_file(&tmp), "5").unwrap();

    install_system_skills(tmp.path()).unwrap();

    assert!(skill_file(&tmp, "best-of-n").is_file());
    assert!(
        !skill_file(&tmp, "delegate").exists(),
        "an intentionally absent older skill must stay absent"
    );
    assert_eq!(
        fs::read_to_string(marker_file(&tmp)).unwrap().trim(),
        BUNDLED_SKILL_VERSION
    );
}

#[test]
fn version_bump_respects_deleted_existing_skill_while_adding_new_skill() {
    let tmp = TempDir::new().unwrap();

    // Simulate v2 where older bundled skills had been deliberately removed
    // before later versions introduced more system skills.
    fs::write(marker_file(&tmp), "2").unwrap();

    install_system_skills(tmp.path()).unwrap();

    assert!(
        !skill_file(&tmp, "skill-creator").exists(),
        "version bump should not recreate deleted skill-creator"
    );
    assert!(
        !skill_file(&tmp, "delegate").exists(),
        "version bump should not recreate deleted delegate"
    );
    for skill in BUNDLED_SKILLS
        .iter()
        .filter(|skill| skill.introduced_in > 2)
    {
        assert!(
            skill_file(&tmp, skill.name).exists(),
            "version bump should install newly introduced {}",
            skill.name
        );
    }
    let ver = fs::read_to_string(marker_file(&tmp)).unwrap();
    assert_eq!(ver.trim(), BUNDLED_SKILL_VERSION);
}

// ── upgrade ───────────────────────────────────────────────────────────────

#[test]
fn upgrade_from_v4_installs_pack_and_retires_unchanged_v4_best_practices() {
    let tmp = TempDir::new().unwrap();
    // Simulate a v4 install: marker + legacy skill bodies.
    fs::create_dir_all(skill_dir(&tmp, "v4-best-practices")).unwrap();
    fs::write(
        skill_file(&tmp, "v4-best-practices"),
        V4_BEST_PRACTICES_BODY,
    )
    .unwrap();
    fs::write(marker_file(&tmp), "4").unwrap();

    install_system_skills(tmp.path()).unwrap();

    assert!(
        !skill_dir(&tmp, "v4-best-practices").exists(),
        "unchanged v4-best-practices must be retired"
    );
    assert!(skill_file(&tmp, "debug").exists());
    assert!(skill_file(&tmp, "docx").exists());
    assert!(skill_file(&tmp, "release").exists());
    // Feishu is optional — not auto-installed by the default pack.
    assert!(
        !skill_dir(&tmp, "feishu").exists(),
        "feishu must not be universally installed"
    );
    let ver = fs::read_to_string(marker_file(&tmp)).unwrap();
    assert_eq!(ver.trim(), BUNDLED_SKILL_VERSION);
}

#[test]
fn upgrade_preserves_modified_v4_best_practices() {
    let tmp = TempDir::new().unwrap();
    fs::create_dir_all(skill_dir(&tmp, "v4-best-practices")).unwrap();
    fs::write(
        skill_file(&tmp, "v4-best-practices"),
        "---\nname: v4-best-practices\ndescription: user-owned\n---\n\n# mine\n",
    )
    .unwrap();
    fs::write(marker_file(&tmp), "4").unwrap();

    install_system_skills(tmp.path()).unwrap();

    assert!(skill_dir(&tmp, "v4-best-practices").exists());
    let body = fs::read_to_string(skill_file(&tmp, "v4-best-practices")).unwrap();
    assert!(
        body.contains("user-owned"),
        "modified body must be preserved"
    );
}

#[test]
fn upgrade_preserves_user_modified_bundled_skill_body() {
    let tmp = TempDir::new().unwrap();
    install_system_skills(tmp.path()).unwrap();
    let path = skill_file(&tmp, "debug");
    fs::write(
        &path,
        "---\nname: debug\ndescription: customized\n---\n\n# custom\n",
    )
    .unwrap();
    // Force version bump attempt
    fs::write(marker_file(&tmp), "4").unwrap();
    install_system_skills(tmp.path()).unwrap();
    let body = fs::read_to_string(path).unwrap();
    assert!(
        body.contains("customized"),
        "user edit must not be overwritten by name alone"
    );
}

#[test]
fn end_user_pack_skills_parse_for_discovery() {
    let tmp = TempDir::new().unwrap();
    install_system_skills(tmp.path()).unwrap();
    let registry = crate::skills::SkillRegistry::discover(tmp.path());
    assert!(
        registry.warnings().is_empty(),
        "bundled skills should parse cleanly: {:?}",
        registry.warnings()
    );
    for name in [
        "debug", "test", "review", "document", "docx", "release", "plan", "verify",
    ] {
        assert!(registry.get(name).is_some(), "{name} must be discoverable");
    }
}

#[test]
fn procedural_skill_homes_remain_bundled_and_lazy() {
    for name in ["debug", "best-of-n", "simplify", "verify", "test", "review"] {
        assert!(
            is_bundled_skill_name(name),
            "procedural skill home must remain available on demand: {name}"
        );
    }
}