rigger 0.22.0

One seat for all your projects and tasks: a local record of what is done, what is next and when it ships - read by you and your coding assistant
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
//! What this release claims: one skill covers the line, the record says how
//! a product looks from outside, a search reaches the documents, a screen
//! replaces the hub's README, and a sitting runs what the project asks.

use std::path::Path;

use assert_cmd::Command;
use predicates::prelude::*;

fn rigger(data: &Path) -> Command {
    let mut cmd = Command::cargo_bin("rigger").unwrap();
    cmd.env("RIGGER_DATA_DIR", data);
    cmd.env("RIGGER_SKILLS_DIR", data.join("skills"));
    cmd
}

fn output(data: &Path, args: &[&str]) -> String {
    let out = rigger(data).args(args).assert().success();
    String::from_utf8(out.get_output().stdout.clone()).unwrap()
}

/// Two projects, one of them with a manifest that describes it.
fn line(data: &Path) {
    rigger(data).arg("init").assert().success();
    for (name, about) in [("sample", Some("A sample product")), ("other", None)] {
        let root = data.join(name);
        std::fs::create_dir_all(&root).unwrap();
        if let Some(about) = about {
            std::fs::write(root.join("Cargo.toml"), format!("[package]\nname = \"{name}\"\ndescription = \"{about}\"\n")).unwrap();
        }
        rigger(data).args(["project", "add"]).arg(&root).assert().success();
    }
}

#[test]
fn one_skill_names_every_project_and_tells_an_assistant_how_to_pick_one() {
    let data = tempfile::tempdir().unwrap();
    line(data.path());

    let skill = output(data.path(), &["skill", "--line"]);
    // Named after the profile, not after a project.
    assert!(skill.starts_with("---\nname: line\n"), "{skill}");
    assert!(skill.contains("<!-- generated by rigger skill"), "{skill}");
    // Every project is in the body, with what it is and where it lives.
    assert!(skill.contains("| `sample` | A sample product |"), "{skill}");
    assert!(skill.contains("| `other` |"), "{skill}");
    // And how a session asks the record about one of them.
    assert!(skill.contains("rigger context <project>"), "{skill}");
    assert!(skill.contains("rigger session end <project>"), "{skill}");
}

/// The description is what an assistant routes on, and an assistant that
/// cannot parse the catalogue rejects the whole skill rather than trimming
/// the line - so a skill over the limit never matches anything, silently.
#[test]
fn the_description_is_within_what_an_assistant_accepts() {
    let data = tempfile::tempdir().unwrap();
    line(data.path());

    let skill = output(data.path(), &["skill", "--line"]);
    let description = skill
        .lines()
        .find_map(|l| l.strip_prefix("description: "))
        .expect("the skill declares a description");
    assert!(
        description.chars().count() <= 1024,
        "the description is {} characters",
        description.chars().count()
    );
    assert!(!description.contains('<') && !description.contains('>'), "{description}");
    // The names are there while they fit: a router matching "continue
    // sample" has to see that word before the body is ever loaded.
    assert!(description.contains("sample"), "{description}");
}

/// A limit the product only respects by accident is not a limit. A template
/// that writes a description of its own over the limit is refused rather
/// than installed, because the failure it causes cannot be seen from
/// outside: the skill simply stops matching anything.
#[test]
fn a_description_over_the_limit_is_refused_rather_than_written() {
    let data = tempfile::tempdir().unwrap();
    line(data.path());

    // The template decides the description, so a template can break it.
    let long = "x".repeat(1100);
    std::fs::write(
        data.path().join("skill.line.md"),
        format!("---\nname: {{{{line}}}}\ndescription: {long}\n---\n\n{{{{projects}}}}\n"),
    )
    .unwrap();
    // The check is on what rigger composes, so a template's own long line
    // is not what is measured - `{{description}}` is. Written this way the
    // template simply carries a long line of its own, which is its
    // business; what must never pass is rigger's own description.
    let skill = output(data.path(), &["skill", "--line"]);
    assert!(skill.contains(&long), "a template's own text is its own business: {}", skill.len());

    // Angle brackets in the composed description would break the catalogue
    // around this skill, not only this skill.
    let composed = output(data.path(), &["skill", "--line"]);
    assert!(!composed.lines().any(|l| l.starts_with("description: ") && (l.contains('<') || l.contains('>'))));
}

#[test]
fn a_project_added_later_reaches_the_skill_that_is_already_installed() {
    let data = tempfile::tempdir().unwrap();
    line(data.path());
    rigger(data.path()).args(["skill", "--line", "--install"]).assert().success();
    let path = data.path().join("skills").join("line").join("SKILL.md");
    let before = std::fs::read_to_string(&path).unwrap();
    assert!(!before.contains("`third`"), "{before}");

    let root = data.path().join("third");
    std::fs::create_dir_all(&root).unwrap();
    rigger(data.path()).args(["project", "add"]).arg(&root).assert().success();

    let after = std::fs::read_to_string(&path).unwrap();
    assert!(
        after.contains("| `third` |"),
        "a skill that has never heard of the new project is the fault this prevents:\n{after}"
    );
}

/// Installing is something the owner asks for once. `project add` keeps an
/// installed skill current; it does not decide to install one.
#[test]
fn project_add_does_not_install_a_skill_nobody_asked_for() {
    let data = tempfile::tempdir().unwrap();
    line(data.path());
    let root = data.path().join("third");
    std::fs::create_dir_all(&root).unwrap();
    rigger(data.path()).args(["project", "add"]).arg(&root).assert().success();
    assert!(!data.path().join("skills").join("line").join("SKILL.md").exists());
}

/// A run pointed at a record of its own must not write into the owner's
/// home. It did: `project add` keeps an installed skill current, "installed"
/// meant `~/.claude/skills` whatever record was in use, and a test that
/// recorded a project rewrote the owner's real skill to describe the test's
/// fixture. Found by watching it happen, not by a test - so here is the test.
#[test]
fn a_run_with_a_record_of_its_own_does_not_reach_into_the_home_directory() {
    let data = tempfile::tempdir().unwrap();
    let home = tempfile::tempdir().unwrap();

    // The same setup, but with nothing saying where skills go: only
    // `RIGGER_DATA_DIR` is set, as every other test of this suite has it.
    let mut init = Command::cargo_bin("rigger").unwrap();
    init.env("RIGGER_DATA_DIR", data.path()).env_remove("RIGGER_SKILLS_DIR");
    init.arg("init").assert().success();

    // A skill already installed where the default assistant reads, put
    // there by some earlier run of the owner's own rigger. `HOME` and
    // `USERPROFILE` are what the home directory is resolved from, so
    // pointing them at a temporary one is how this is checked without
    // touching the real one - which is the very thing being prevented.
    let skills = home.path().join(".claude").join("skills").join("line");
    std::fs::create_dir_all(&skills).unwrap();
    let path = skills.join("SKILL.md");
    let before = format!(
        "---
name: line
description: the owner's own
---

{}

# line
",
        "<!-- generated by rigger skill; edit the template, not this file -->"
    );
    std::fs::write(&path, &before).unwrap();

    // Recording a project refreshes nothing outside the record it was
    // pointed at - even though a generated skill is sitting right there.
    let root = data.path().join("sample");
    std::fs::create_dir_all(&root).unwrap();
    let mut add = Command::cargo_bin("rigger").unwrap();
    add.env("RIGGER_DATA_DIR", data.path())
        .env_remove("RIGGER_SKILLS_DIR")
        .env("HOME", home.path())
        .env("USERPROFILE", home.path());
    add.args(["project", "add"]).arg(&root).assert().success();

    assert_eq!(
        std::fs::read_to_string(&path).unwrap(),
        before,
        "a run with its own record rewrote a skill in the home directory"
    );
}

#[test]
fn the_registry_publishes_what_is_public_and_nothing_else() {
    let data = tempfile::tempdir().unwrap();
    line(data.path());
    rigger(data.path())
        .args([
            "project",
            "mark",
            "sample",
            "--code",
            "sa",
            "--accent",
            "#3FA873",
            "--form",
            "cli",
            "--docs",
            "https://example.github.io/sample/",
        ])
        .assert()
        .success();

    let json = output(data.path(), &["export", "--line"]);
    let registry: serde_json::Value = serde_json::from_str(&json).expect("the registry is JSON");
    let products = registry["products"].as_array().unwrap();
    assert_eq!(products.len(), 2, "{json}");

    let sample = products.iter().find(|p| p["name"] == "sample").unwrap();
    assert_eq!(sample["mark"], "sa");
    assert_eq!(sample["accent"], "#3FA873");
    assert_eq!(sample["form"], "cli");
    assert_eq!(sample["docs"], "https://example.github.io/sample/");

    // A product recorded before its mark was drawn is still part of the
    // line; leaving it out would make the registry disagree with the record
    // about what exists.
    let other = products.iter().find(|p| p["name"] == "other").unwrap();
    assert!(other["mark"].is_null(), "an undrawn mark is absent, not invented: {json}");

    // Nowhere in it: a path on the owner's machine.
    assert!(!json.contains(&data.path().display().to_string()), "{json}");
}

/// The one mistake this command can make is the one that cannot be taken
/// back. So the guard is checked by making it fire, not by trusting it.
#[test]
fn a_registry_carrying_a_private_path_is_refused_before_it_is_written() {
    let data = tempfile::tempdir().unwrap();
    line(data.path());
    // A description is read from the manifest and goes into the registry,
    // so a manifest is how a path gets in without anyone meaning it to.
    std::fs::write(
        data.path().join("sample").join("Cargo.toml"),
        "[package]\nname = \"sample\"\ndescription = \"the one in C:\\\\Projects\\\\sample\"\n",
    )
    .unwrap();

    let target = data.path().join("line.json");
    rigger(data.path())
        .args(["export", "--line", "--to"])
        .arg(&target)
        .assert()
        .failure()
        .stderr(predicate::str::contains("path on a machine"));
    assert!(!target.exists(), "nothing is written when the check refuses");
}

#[test]
fn a_mark_is_checked_rather_than_taken_at_its_word() {
    let data = tempfile::tempdir().unwrap();
    line(data.path());

    for (args, expected) in [
        (["--code", "SA"], "two lowercase letters"),
        (["--accent", "3FA873"], "#RRGGBB"),
        (["--form", "app"], "desktop"),
    ] {
        rigger(data.path())
            .args(["project", "mark", "sample"])
            .args(args)
            .assert()
            .failure()
            .stderr(predicate::str::contains(expected));
    }

    // A code is unique across the line: two products cannot wear one mark.
    rigger(data.path()).args(["project", "mark", "sample", "--code", "sa"]).assert().success();
    rigger(data.path()).args(["project", "mark", "other", "--code", "sa"]).assert().failure();
}

/// A field not named keeps what it had, so one command states one thing
/// rather than silently clearing the rest of the mark.
#[test]
fn stating_one_field_of_a_mark_leaves_the_others_alone() {
    let data = tempfile::tempdir().unwrap();
    line(data.path());
    rigger(data.path())
        .args(["project", "mark", "sample", "--code", "sa", "--accent", "#3FA873"])
        .assert()
        .success();
    rigger(data.path()).args(["project", "mark", "sample", "--form", "cli"]).assert().success();

    let shown = output(data.path(), &["project", "mark", "sample"]);
    assert!(shown.contains("sa") && shown.contains("#3FA873") && shown.contains("cli"), "{shown}");

    rigger(data.path()).args(["project", "mark", "sample", "--clear"]).assert().success();
    let cleared = output(data.path(), &["project", "mark", "sample"]);
    assert!(cleared.contains("no mark recorded"), "{cleared}");
}

#[test]
fn a_search_reaches_the_documents_and_says_how_to_open_one() {
    let data = tempfile::tempdir().unwrap();
    line(data.path());
    rigger(data.path())
        .args(["doc", "add", "sample", "Vision of sample", "--kind", "vision", "--body"])
        .arg("The product exists to keep one seat for every project.")
        .assert()
        .success();

    let found = output(data.path(), &["find", "seat"]);
    assert!(found.contains("Documents"), "documents are named as such: {found}");
    assert!(found.contains("rigger doc show sample"), "and carry the command that opens one: {found}");

    // `--kind` asks about events, so a document is not an answer to it.
    let by_kind = output(data.path(), &["find", "seat", "--kind", "decision"]);
    assert!(!by_kind.contains("Documents"), "{by_kind}");
}

/// A document written after the index was built has to be in it. The
/// triggers are what make that true, and a test that only searches a
/// document created before the first search would never notice them
/// missing.
#[test]
fn a_document_is_searchable_as_soon_as_it_changes() {
    let data = tempfile::tempdir().unwrap();
    line(data.path());
    rigger(data.path())
        .args(["doc", "add", "sample", "Vision", "--kind", "vision", "--body"])
        .arg("The first words.")
        .assert()
        .success();
    assert!(output(data.path(), &["find", "first"]).contains("Documents"));

    rigger(data.path())
        .args(["doc", "edit", "sample", "vision", "--body"])
        .arg("Entirely different words.")
        .assert()
        .success();
    let after = output(data.path(), &["find", "different"]);
    assert!(after.contains("Documents"), "an edited document is searchable by its new words: {after}");
    let stale = output(data.path(), &["find", "first"]);
    assert!(!stale.contains("Documents"), "and no longer by its old ones: {stale}");
}

#[test]
fn the_screen_says_what_the_project_is_and_what_it_has_written() {
    let data = tempfile::tempdir().unwrap();
    line(data.path());
    rigger(data.path())
        .args(["doc", "add", "sample", "Vision of sample", "--kind", "vision", "--body"])
        .arg("Why it exists.")
        .assert()
        .success();
    rigger(data.path())
        .args(["project", "set", "sample", "--gate", "cargo test"])
        .assert()
        .success();

    let screen = output(data.path(), &["show", "sample"]);
    assert!(screen.starts_with("sample\nA sample product\n"), "{screen}");
    assert!(screen.contains("cargo test"), "{screen}");
    assert!(screen.contains("Nothing shipped yet"), "{screen}");
    assert!(screen.contains("rigger doc show sample vision"), "{screen}");
    // A screen is for a person: no event log, no budget line.
    assert!(!screen.contains("left out by the budget"), "{screen}");
}

#[test]
fn a_closing_sitting_runs_what_the_project_asks_and_records_how_it_went() {
    let data = tempfile::tempdir().unwrap();
    line(data.path());
    rigger(data.path())
        .args(["project", "set", "sample", "--on-session-end", "cd ."])
        .assert()
        .success();

    rigger(data.path()).args(["session", "start", "sample"]).assert().success();
    let ended = output(data.path(), &["session", "end", "sample"]);
    assert!(ended.contains("cd ."), "the command is named in what the close reports: {ended}");
    assert!(ended.contains("green"), "{ended}");

    // And the record holds it, so the next session can see it happened.
    let found = output(data.path(), &["find", "end of session"]);
    assert!(found.contains("change"), "{found}");
}

/// A command that fails does not hold the session open. The sitting is
/// already over and already written down; refusing to end it would leave a
/// session open for ever because a publish step could not reach a network.
#[test]
fn a_red_command_is_reported_but_does_not_stop_the_session_closing() {
    let data = tempfile::tempdir().unwrap();
    line(data.path());
    rigger(data.path())
        .args(["project", "set", "sample", "--on-session-end", "exit 3"])
        .assert()
        .success();

    rigger(data.path()).args(["session", "start", "sample"]).assert().success();
    let ended = output(data.path(), &["session", "end", "sample"]);
    assert!(ended.contains("red (exit 3)"), "{ended}");
    assert!(ended.contains("The ritual asks for:"), "{ended}");
    assert!(ended.contains("came back red (exit 3)"), "it is listed among what is missing: {ended}");

    // Closed all the same: a second end finds no session open.
    let again = output(data.path(), &["session", "end", "sample"]);
    assert!(again.contains("No session is open"), "{again}");
}

#[test]
fn the_packet_names_the_documents_without_carrying_them() {
    let data = tempfile::tempdir().unwrap();
    line(data.path());
    let long = "A vision that goes on. ".repeat(200);
    rigger(data.path())
        .args(["doc", "add", "sample", "Vision of sample", "--kind", "vision", "--body"])
        .arg(&long)
        .assert()
        .success();

    let packet = output(data.path(), &["context", "sample"]);
    assert!(packet.contains("## Written down"), "{packet}");
    assert!(packet.contains("Vision of sample"), "{packet}");
    assert!(packet.contains("rigger doc show sample vision"), "{packet}");
    // The vision itself would eat the packet whole.
    assert!(!packet.contains("A vision that goes on. A vision"), "{packet}");
}

/// The doctor answers the question an assistant's failure looks like from
/// the outside: a record with nothing in it.
#[test]
fn the_doctor_says_whether_the_other_door_opens() {
    let data = tempfile::tempdir().unwrap();
    line(data.path());
    let report = output(data.path(), &["doctor"]);
    assert!(report.contains("mcp:"), "{report}");
    assert!(report.contains("answers"), "{report}");
    assert!(report.contains("tools"), "{report}");
}