warble-cli 0.19.0

Warble CLI — compile profiles, dispatch to the Claude Code or Vercel target, render dashboards, emit manifests, run eval.
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
//! Author workflow contracts: exact native surfaces, honest origins, no vendor execution.
use serde_json::Value;
use std::{
    fs,
    path::Path,
    process::{Command, Output},
};

fn write(root: &Path, name: &str, value: &str) {
    let path = root.join(name);
    fs::create_dir_all(path.parent().unwrap()).unwrap();
    fs::write(path, value).unwrap();
}
fn run(args: &[&str]) -> Output {
    Command::new(env!("CARGO_BIN_EXE_warble"))
        .args(args)
        .env("ANTHROPIC_API_KEY", "AMBIENT_SECRET_MUST_NOT_APPEAR")
        .env("OPENAI_API_KEY", "ANOTHER_AMBIENT_SECRET")
        .output()
        .unwrap()
}
fn success(out: Output) -> String {
    assert!(
        out.status.success(),
        "{}",
        String::from_utf8_lossy(&out.stderr)
    );
    String::from_utf8(out.stdout).unwrap()
}
fn failed(out: Output, expected: &[&str]) {
    assert!(!out.status.success());
    let text = String::from_utf8_lossy(&out.stderr);
    for item in expected {
        assert!(text.contains(item), "missing {item}: {text}");
    }
    assert!(!text.contains("SECRET_MUST_NOT_APPEAR"));
}
fn simple(root: &Path) {
    write(root,"profile.yml","profile: helper\ncomponents:\n  - id: summarize\n    prompt: Summarize the supplied text.\n");
}
fn composed(root: &Path) {
    write(
        root,
        "profile.yml",
        r#"profile: helper
system_prompt: COMMON {{ slot.style }}
slots:
  - name: style
    variants: {short: style/short.md, long: style/long.md}
    default: short
components:
  - use: summarize
    brief: MOUNT_BRIEF
"#,
    );
    write(root, "style/short.md", "SHORT_STYLE");
    write(root, "style/long.md", "UNUSED_PROFILE_TEXT");
    write(
        root,
        "components/summarize/component.yml",
        r#"id: summarize
verb: summarize
type: analytical
realization_kind: skill
binding_mode: runtime_selected
brief: REPLACED_COMPONENT_TEXT
llm_steps:
  - name: respond
    tier: cheap
    prompt_ref: steps/respond.md
slots:
  - name: tone
    variants: {polite: polite.md, brisk: brisk.md}
    default: polite
trigger: {kind: one_shot}
guardrails: [{name: read_only_execution, locked: true}]
required_capabilities: [llm:cheap]
effect: {render_blocks: [], outcome: {kind: none}}
"#,
    );
    write(
        root,
        "components/summarize/steps/respond.md",
        "STEP {{ slot.tone }}",
    );
    write(root, "components/summarize/polite.md", "TONE_POLITE");
    write(
        root,
        "components/summarize/brisk.md",
        "UNUSED_COMPONENT_TEXT",
    );
}

#[test]
fn preview_is_the_exact_native_emit_for_both_targets_with_sources_and_model_choices() {
    for target in ["claude-code:headless", "claude-code:interactive"] {
        let d = tempfile::tempdir().unwrap();
        composed(d.path());
        let project = d.path().to_str().unwrap();
        let text = success(run(&[
            "preview", project, "--target", target, "--cheap", "sonnet", "--json",
        ]));
        for hidden in [
            "REPLACED_COMPONENT_TEXT",
            "UNUSED_PROFILE_TEXT",
            "UNUSED_COMPONENT_TEXT",
            "AMBIENT_SECRET",
            "ANOTHER_AMBIENT",
        ] {
            assert!(!text.contains(hidden), "{hidden}");
        }
        let preview: Value = serde_json::from_str(&text).unwrap();
        let output = d.path().join("built");
        success(run(&[
            "build",
            project,
            "--target",
            target,
            "--cheap",
            "sonnet",
            "--out",
            output.to_str().unwrap(),
        ]));
        let ir = d.path().join("ordinary.json");
        let ordinary = d.path().join("ordinary");
        success(run(&["compile", project, "-o", ir.to_str().unwrap()]));
        success(run(&[
            "dispatch",
            ir.to_str().unwrap(),
            "--target",
            target,
            "--cheap",
            "sonnet",
            "--out",
            ordinary.to_str().unwrap(),
        ]));
        for surface in preview["surfaces"].as_array().unwrap() {
            let path = surface["path"].as_str().unwrap();
            let actual = fs::read_to_string(output.join(path)).unwrap();
            assert_eq!(surface["content"], actual);
            assert_eq!(actual, fs::read_to_string(ordinary.join(path)).unwrap());
        }
        assert_eq!(
            preview["permissions"],
            serde_json::from_slice::<Value>(
                &fs::read(output.join(".claude/settings.json")).unwrap()
            )
            .unwrap()
        );
        assert_eq!(
            preview["capabilities"],
            serde_json::from_slice::<Value>(
                &fs::read(output.join("capability-report.json")).unwrap()
            )
            .unwrap()
        );
        let agent = fs::read_to_string(output.join(".claude/agents/summarize.md")).unwrap();
        for expected in [
            "COMMON SHORT_STYLE",
            "MOUNT_BRIEF",
            "STEP TONE_POLITE",
            "model: sonnet",
        ] {
            assert!(agent.contains(expected), "{agent}");
        }
        let sources = preview["sources"].as_array().unwrap();
        assert!(sources.iter().any(|s| s["role"] == "component brief"
            && s["status"].as_str().unwrap().starts_with("replaced")));
        assert!(sources
            .iter()
            .any(|s| s["field"] == "components[0].brief" && s["role"] == "mount brief"));
        assert!(sources.iter().any(
            |s| s["file"].as_str().unwrap().ends_with("steps/respond.md")
                && s["field"] == "llm_steps[0].prompt_ref"
        ));
        assert!(sources
            .iter()
            .any(|s| s["variant"] == "brisk" && s["status"] == "unselected; not emitted"));
        assert!(preview["runtime_boundary"]
            .as_array()
            .unwrap()
            .iter()
            .any(|s| s.as_str().unwrap().contains("not a captured conversation")));
    }
}

#[test]
fn check_and_preview_leave_no_ir_or_runtime_state_and_shorthand_origin_is_real() {
    let d = tempfile::tempdir().unwrap();
    simple(d.path());
    let p = d.path().to_str().unwrap();
    success(run(&["check", p]));
    let preview: Value = serde_json::from_str(&success(run(&["preview", p, "--json"]))).unwrap();
    assert_eq!(fs::read_dir(d.path()).unwrap().count(), 1);
    assert!(preview["sources"]
        .as_array()
        .unwrap()
        .iter()
        .any(|s| s["field"] == "components[0].prompt" && s["role"] == "step prompt"));
    let human = success(run(&["preview", p]));
    assert!(
        human.contains("Author sources:")
            && human.contains("Native permissions:")
            && human.contains(".claude/agents/summarize.md")
    );
}

#[test]
fn slot_selection_and_omission_change_actual_surfaces_and_sources() {
    let d = tempfile::tempdir().unwrap();
    composed(d.path());
    let p = d.path().to_str().unwrap();
    let component = d.path().join("components/summarize/component.yml");
    fs::write(
        &component,
        fs::read_to_string(&component).unwrap().replace(
            "default: polite",
            "default: polite\n    present_when: approved",
        ),
    )
    .unwrap();
    failed(
        run(&["preview", p]),
        &["slot", "tone", "component.yml", "--slot"],
    );
    let chosen: Value = serde_json::from_str(&success(run(&[
        "preview",
        p,
        "--slot",
        "tone=brisk",
        "--json",
    ])))
    .unwrap();
    assert!(chosen["surfaces"]
        .to_string()
        .contains("UNUSED_COMPONENT_TEXT"));
    assert!(!chosen["surfaces"].to_string().contains("TONE_POLITE"));
    let omitted: Value =
        serde_json::from_str(&success(run(&["preview", p, "--slot", "tone=", "--json"]))).unwrap();
    assert_ne!(chosen["surfaces"], omitted["surfaces"]);
    assert!(!omitted["surfaces"]
        .to_string()
        .contains("UNUSED_COMPONENT_TEXT"));
    assert!(omitted["sources"]
        .as_array()
        .unwrap()
        .iter()
        .filter(|s| s["slot"] == "tone")
        .all(|s| s["status"] == "omitted by --slot; not emitted"));
    let out = d.path().join("chosen");
    success(run(&[
        "build",
        p,
        "--slot",
        "tone=brisk",
        "--out",
        out.to_str().unwrap(),
    ]));
    for s in chosen["surfaces"].as_array().unwrap() {
        assert_eq!(
            s["content"],
            fs::read_to_string(out.join(s["path"].as_str().unwrap())).unwrap()
        );
    }
}

#[test]
fn validation_errors_name_sources_and_preserve_outputs() {
    for change in [
        "context_precondition: [{predicate: has_metric}]\n",
        "required_capabilities: [llm:cheap, human_approval]\n",
    ] {
        let d = tempfile::tempdir().unwrap();
        composed(d.path());
        let p = d.path().to_str().unwrap();
        let file = d.path().join("components/summarize/component.yml");
        let text = fs::read_to_string(&file).unwrap();
        fs::write(
            &file,
            if change.starts_with("required") {
                text.replace("required_capabilities: [llm:cheap]\n", change)
            } else {
                text + change
            },
        )
        .unwrap();
        let out = d.path().join("out");
        failed(
            run(&["build", p, "--out", out.to_str().unwrap()]),
            &["summarize", "component.yml"],
        );
        assert!(!out.exists());
    }
    let d = tempfile::tempdir().unwrap();
    simple(d.path());
    let p = d.path().to_str().unwrap();
    let out = d.path().join("out");
    fs::create_dir(&out).unwrap();
    write(&out, "canary", "preserve");
    failed(
        run(&["build", p, "--out", out.to_str().unwrap()]),
        &["already exists"],
    );
    assert_eq!(fs::read_to_string(out.join("canary")).unwrap(), "preserve");
    #[cfg(unix)]
    {
        let link = d.path().join("link");
        std::os::unix::fs::symlink(&out, &link).unwrap();
        failed(
            run(&["build", p, "--out", link.to_str().unwrap()]),
            &["already exists"],
        );
        assert_eq!(fs::read_to_string(out.join("canary")).unwrap(), "preserve");
    }

    failed(
        run(&["preview", p, "--target", "codex:interactive"]),
        &["currently support", "compile/dispatch"],
    );
    failed(
        run(&["preview", p, "--native-mcp", "secret.json"]),
        &["unexpected argument"],
    );
}

// The temporary preflight has a short path and succeeds; only delivery at --out fails.
#[cfg(any(target_os = "macos", target_os = "linux"))]
#[test]
fn failed_delivery_removes_new_output_for_both_targets() {
    let d = tempfile::tempdir().unwrap();
    simple(d.path());
    let path_max = if cfg!(target_os = "macos") {
        1024
    } else {
        4096
    };
    let mut parent = d.path().canonicalize().unwrap();
    while parent.as_os_str().len() + 181 + 20 < path_max - 20 {
        parent.push("d".repeat(180));
    }
    let out = parent.join("o".repeat(path_max - 20 - parent.as_os_str().len() - 1));
    for target in ["claude-code:headless", "claude-code:interactive"] {
        for _ in 0..2 {
            failed(
                run(&[
                    "build",
                    d.path().to_str().unwrap(),
                    "--target",
                    target,
                    "--out",
                    out.to_str().unwrap(),
                ]),
                &["output for", "failed"],
            );
            assert!(
                out.symlink_metadata().is_err(),
                "failed output must be removed"
            );
        }
    }
}

#[test]
fn unknown_fields_and_invalid_scalars_do_not_echo_secret_values() {
    let d = tempfile::tempdir().unwrap();
    simple(d.path());
    let p = d.path().to_str().unwrap();
    let file = d.path().join("profile.yml");
    let original = fs::read_to_string(&file).unwrap();
    fs::write(
        &file,
        format!("{original}api_key: SECRET_MUST_NOT_APPEAR\n"),
    )
    .unwrap();
    failed(
        run(&["preview", p]),
        &["profile.yml", "unknown profile field api_key"],
    );
    fs::write(
        &file,
        format!("{original}config: {{token: SECRET_MUST_NOT_APPEAR}}\n"),
    )
    .unwrap();
    failed(
        run(&["check", p]),
        &["profile.yml#config", "unknown field token"],
    );
    fs::write(
        &file,
        original.replace(
            "prompt: Summarize the supplied text.",
            "prompt: {token: SECRET_MUST_NOT_APPEAR}",
        ),
    )
    .unwrap();
    failed(
        run(&["preview", p]),
        &["profile.yml#components[0]", "invalid YAML"],
    );
    fs::write(
        &file,
        original.replace(
            "    prompt: Summarize the supplied text.",
            "    tier: strong\n    promt: SECRET_MUST_NOT_APPEAR",
        ),
    )
    .unwrap();
    failed(
        run(&["check", p]),
        &[
            "profile.yml#components[0]",
            "top-level tier requires a top-level prompt",
            "check the prompt field spelling",
        ],
    );
}

#[cfg(unix)]
#[test]
fn author_commands_never_start_a_vendor_or_tool_process() {
    use std::os::unix::fs::PermissionsExt;
    let d = tempfile::tempdir().unwrap();
    let project = d.path().join("project");
    simple(&project);
    let bins = d.path().join("bin");
    for name in ["claude", "codex", "wren", "node"] {
        write(
            &bins,
            name,
            "#!/bin/sh\nprintf invoked >> \"$INVOCATION_CANARY\"\nexit 99\n",
        );
        fs::set_permissions(bins.join(name), fs::Permissions::from_mode(0o755)).unwrap();
    }
    let canary = d.path().join("invoked");
    for name in ["check", "preview", "build"] {
        let mut cmd = Command::new(env!("CARGO_BIN_EXE_warble"));
        cmd.arg(name)
            .arg(&project)
            .env("PATH", &bins)
            .env("INVOCATION_CANARY", &canary);
        if name == "build" {
            cmd.arg("--out").arg(d.path().join("built"));
        }
        success(cmd.output().unwrap());
    }
    assert!(!canary.exists());
}

#[test]
fn data_profile_preview_includes_every_emitted_subagent_surface() {
    let project = Path::new(env!("CARGO_MANIFEST_DIR")).join("../examples/demo-agent");
    let p = project.to_str().unwrap();
    let preview: Value = serde_json::from_str(&success(run(&["preview", p, "--json"]))).unwrap();
    let d = tempfile::tempdir().unwrap();
    let out = d.path().join("native");
    success(run(&["build", p, "--out", out.to_str().unwrap()]));
    let agent_count = fs::read_dir(out.join(".claude/agents")).unwrap().count();
    assert!(agent_count > 1, "exercise the multi-tier subagent path");
    assert_eq!(
        preview["surfaces"].as_array().unwrap().len(),
        agent_count + 1
    );
    for s in preview["surfaces"].as_array().unwrap() {
        assert_eq!(
            s["content"],
            fs::read_to_string(out.join(s["path"].as_str().unwrap())).unwrap()
        );
    }
    assert!(preview["sources"]
        .as_array()
        .unwrap()
        .iter()
        .any(|s| s["file"]
            .as_str()
            .unwrap()
            .contains("examples/demo-agent/components/generate_dashboard")));
}