supercode-harness 0.4.13

The optional native Supercode agent and tool harness
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
//! §4.6 "Preset validation" (`docs/composable-harness/COMPOSABLE-HARNESS-
//! DESIGN.md`) — golden tests for the six reserved presets, P2 of the
//! composable-harness migration (design §5.2 phase **P2**, item 3: "Golden
//! tests per preset").
//!
//! Each test resolves `extends = "<preset>"` through
//! [`supercode_harness::configfile::resolve`] and asserts (a) load-bearing resolved
//! [`Config`] fields, (b) the module activation set, and (c) §4.6's own
//! per-preset verdict — which warnings fire and which don't, matched
//! against the design doc's mechanical re-validation table.

use std::collections::BTreeMap;

use supercode_harness::configfile::{resolve, ResolveOptions};
use supercode_harness::{ApprovalPolicy, SandboxPolicy};

fn resolve_preset(name: &str) -> supercode_harness::configfile::Resolved {
    let top = format!("extends = \"{name}\"\n");
    resolve(&top, None, &ResolveOptions::default())
        .unwrap_or_else(|e| panic!("preset `{name}` failed to resolve: {e}"))
}

fn assert_modules(modules: &BTreeMap<String, bool>, on: &[&str], off: &[&str]) {
    for name in on {
        assert_eq!(
            modules.get(*name),
            Some(&true),
            "expected module `{name}` ON"
        );
    }
    for name in off {
        assert_ne!(
            modules.get(*name),
            Some(&true),
            "expected module `{name}` OFF"
        );
    }
}

// ---------------------------------------------------------------------------
// pi-core — §4.1. §4.6 verdict: PASS, one named residual (C3 mandatory,
// fires by design — "pi ships no popups/sandbox").
// ---------------------------------------------------------------------------
#[test]
fn pi_core_resolves_with_only_the_c3_mandatory_warning() {
    let r = resolve_preset("pi-core");

    // (a) load-bearing Config fields.
    assert_eq!(r.config.effort.as_deref(), Some("medium"));
    assert_eq!(r.config.max_tool_output_bytes, Some(51200));
    assert!(r.config.load_project_context);
    assert_eq!(
        r.config.tool_schema_tier,
        supercode_harness::SchemaTier::Full
    );
    assert_eq!(r.config.compact_after_messages, Some(0));

    // (b) module activation set — pi's kept-list ON, first-party omissions OFF.
    assert_modules(
        &r.modules,
        &[
            "trust",
            "session_tree",
            "session_share",
            "server",
            "plugins",
            "tui",
        ],
        &[
            "tools_search",
            "mcp",
            "subagents",
            "permissions",
            "plan_mode",
            "todos",
            "tools_background",
            "tools_web",
            "checkpoint",
            "memory",
            "hooks",
            "deferred_tools",
            "cache",
            "reduction",
            "model_catalog",
            "model_oauth",
            "tools_apply_patch",
            "tools_persistent_shell",
            "tools_question",
            "lsp",
            "formatters",
            "structured_output",
            "telemetry",
            "integrations",
        ],
    );

    // (c) §4.6 verdict: exactly the C3 mandatory warning, nothing else.
    assert_eq!(
        r.warnings.len(),
        1,
        "pi-core should carry exactly the C3 mandatory warning: {:?}",
        r.warnings
    );
    assert!(r.warnings[0].contains("C3"));
    assert_eq!(r.config.sandbox, SandboxPolicy::DangerFullAccess);
    assert_eq!(r.config.approval, ApprovalPolicy::Never);
}

// ---------------------------------------------------------------------------
// cc-parity — §4.2. §4.6 verdict: PASS, C6 resolved via
// background_prompts="parent" (schema key, not prose); no C3 (approval !=
// never); no other conflicts fire.
// ---------------------------------------------------------------------------
#[test]
fn cc_parity_resolves_with_zero_warnings_c6_satisfied_via_parent() {
    let r = resolve_preset("cc-parity");

    assert_eq!(r.config.model, "anthropic/claude-opus-4-8");
    assert_eq!(r.config.effort.as_deref(), Some("medium"));
    assert_eq!(r.config.approval, ApprovalPolicy::Untrusted);
    assert!(r.config.auto_approved_tools.contains("read_file"));

    assert_modules(
        &r.modules,
        &[
            "tools_search",
            "tools_web",
            "tools_question",
            "todos",
            "plan_mode",
            "subagents",
            "tools_background",
            "permissions",
            "permissions.rules",
            "permissions.protected_paths",
            "trust",
            "mcp",
            "deferred_tools",
            "hooks",
            "memory",
            "checkpoint",
            "session_tree",
            "model_catalog",
            "tui",
        ],
        &[
            "tools_apply_patch",
            "tools_persistent_shell",
            "lsp",
            "formatters",
            "session_share",
            "server",
            "reduction",
            "cache",
            "structured_output",
            "model_oauth",
            "permissions.sandbox", // module 12 (OS enforcement) explicitly off
        ],
    );

    // No C3 (approval=untrusted != never), no C1 (apply_patch off), no D-7
    // (read_file active), no D-9 (small_model set), C6 satisfied literally
    // via background_prompts="parent" — zero warnings.
    assert!(
        r.warnings.is_empty(),
        "cc-parity should resolve with zero warnings: {:?}",
        r.warnings
    );
}

// ---------------------------------------------------------------------------
// cx-parity — §4.3. §4.6 verdict: PASS. D-7 degrades to a warning (only
// `bash` active, no `read_file`); no C3; C6 satisfied only via the S8
// judgment-call (approval=model_requested), which this resolver records as
// an explicit warning rather than silent pass.
// ---------------------------------------------------------------------------
#[test]
fn cx_parity_resolves_with_d7_and_c6_s8_warnings_only() {
    let r = resolve_preset("cx-parity");

    assert_eq!(
        r.harness.core.tools.enabled.as_deref(),
        Some(&["bash".to_string(), "view_image".to_string()][..])
    );
    assert_eq!(r.harness.core.shell_env_snapshot, Some(true));
    // P5-1: approval="model_requested" is now a real ApprovalPolicy variant
    // (design §3.2 S8, built this unit) — cx-parity resolves to its
    // INTENDED posture (ModelRequested) instead of the pre-P5-1 fail-safe
    // to Untrusted.
    assert_eq!(r.config.approval, ApprovalPolicy::ModelRequested);
    assert_eq!(r.config.sandbox, SandboxPolicy::WorkspaceWrite);

    assert_modules(
        &r.modules,
        &[
            "tools_persistent_shell",
            "tools_apply_patch",
            "todos",
            "tools_web",
            "tools_background",
            "subagents",
            "deferred_tools",
            "structured_output",
            "permissions",
            "permissions.rules",
            "permissions.protected_paths",
            "trust",
            "mcp",
            "hooks",
            "model_catalog",
            "tui",
        ],
        &[
            "tools_search",
            "tools_question",
            "plan_mode",
            "memory",
            "checkpoint",
            "session_tree",
            "session_share",
            "lsp",
            "formatters",
            "server",
            "reduction",
            "cache",
            "model_oauth",
        ],
    );

    // C1 does NOT fire: edit_file/write_file simply aren't in
    // core.tools.enabled, so nothing co-advertises with apply_patch.
    assert!(!r.warnings.iter().any(|w| w.contains("C1")));
    // C3 does NOT fire (sandbox=workspace_write, approval=model_requested).
    assert!(!r.warnings.iter().any(|w| w.contains("C3")));
    // D-7 fires (bash-only read pathway).
    let d7: Vec<_> = r.warnings.iter().filter(|w| w.contains("D-7")).collect();
    assert_eq!(
        d7.len(),
        1,
        "expected exactly one D-7 warning: {:?}",
        r.warnings
    );
    // C6 fires as the S8 judgment-call warning (not a silent pass, not an error).
    let c6: Vec<_> = r.warnings.iter().filter(|w| w.contains("C6")).collect();
    assert_eq!(
        c6.len(),
        1,
        "expected exactly one C6 warning: {:?}",
        r.warnings
    );
    assert!(c6[0].contains("S8"));
    assert_eq!(
        r.warnings.len(),
        2,
        "expected exactly D-7 + C6, nothing else: {:?}",
        r.warnings
    );
}

// ---------------------------------------------------------------------------
// oc-parity — §4.4. §4.6 verdict: PASS. C1 resolved via per_model +
// model_catalog bits; trust ON as a deliberate safety deviation (oc itself
// lacks a trust gate, D-10 forces it here); no C3 (approval != never). The
// four narrative residuals §4.6 names (trust-on, 3 C5 rule-translation
// deviations, plan_mode-off rationale, checkpoint partial-coverage) are
// design-document-level notes, not resolver-emitted warnings in P2's
// implemented scope (C5 rule translation and checkpoint sandbox-coverage
// are not resolver-checked — see validate_modules's doc comment) — so this
// resolver's own warnings list is empty, which is the correct outcome for
// what P2 actually checks.
// ---------------------------------------------------------------------------
#[test]
fn oc_parity_resolves_with_zero_warnings_trust_on_as_deviation() {
    let r = resolve_preset("oc-parity");

    assert_eq!(r.config.approval, ApprovalPolicy::OnRequest);
    assert_eq!(r.config.sandbox, SandboxPolicy::DangerFullAccess);

    assert_modules(
        &r.modules,
        &[
            "tools_search",
            "todos",
            "tools_web",
            "subagents",
            "tools_apply_patch",
            "permissions",
            "permissions.rules",
            "trust", // deliberate deviation (N7): oc lacks this, D-10 forces it on
            "mcp",
            "plugins",
            "lsp",
            "formatters",
            "checkpoint",
            "session_share",
            "server",
            "model_catalog",
            "tui",
        ],
        &[
            "plan_mode", // S18: opencode's plan_enter/plan_exit are deny-by-default
            "tools_question",
            "tools_background",
            "session_tree",
            "memory",
            "hooks",
            "deferred_tools",
            "cache",
            "reduction",
            "structured_output",
            "model_oauth",
            "permissions.protected_paths", // oc does .env protection via rules, not this module
        ],
    );

    assert!(
        r.warnings.is_empty(),
        "oc-parity should resolve with zero resolver-checked warnings: {:?}",
        r.warnings
    );
}

// ---------------------------------------------------------------------------
// token-saver — §4.5. §4.6 verdict: PASS, inherits pi-core's chain (D-10
// plugins→trust still met) and its one C3 residual; D-9 met directly
// (small_model set); no new conflict from the reduction/deferred/cache
// stack (that's what the `cache` module is the referee for).
// ---------------------------------------------------------------------------
#[test]
fn token_saver_extends_pi_core_chain_and_inherits_only_c3() {
    let r = resolve_preset("token-saver");

    // extends chain resolves root-first.
    assert_eq!(
        r.preset_chain,
        vec!["pi-core".to_string(), "token-saver".to_string()]
    );

    // C9: global minimal tier, edit_file pinned back to full.
    assert_eq!(
        r.config.tool_schema_tier,
        supercode_harness::SchemaTier::Minimal
    );
    assert_eq!(
        r.config.schema_tier_for("edit_file"),
        supercode_harness::SchemaTier::Full
    );
    let reduction = &r.config.reduction_policy;
    assert_eq!(reduction.stale_reads, Some(true));
    assert_eq!(reduction.diff_reads, Some(true));
    assert_eq!(reduction.tool_input_elision, Some(true));
    assert_eq!(reduction.supersede, Some(true));
    assert_eq!(reduction.normalize_output, Some(true));
    assert_eq!(reduction.image_redaction, Some(true));
    assert_eq!(reduction.span_summaries, Some(true));

    // D-9 met via small_model — no fallback warning.
    assert_modules(
        &r.modules,
        &["reduction", "deferred_tools", "cache", "model_catalog"],
        &[],
    );
    assert!(!r.warnings.iter().any(|w| w.contains("D-9")));

    // C3 inherited unchanged from pi-core (permissions untouched by
    // token-saver's own overrides).
    assert_eq!(
        r.warnings.len(),
        1,
        "token-saver should inherit exactly pi-core's C3 warning: {:?}",
        r.warnings
    );
    assert!(r.warnings[0].contains("C3"));

    // token-saver inherits pi-core's kept-list ON (trust/session_tree/
    // session_share/server/plugins, tui) and its first-party-omission OFFs
    // (mcp/permissions/subagents/todos/...) unchanged — only the reduction/
    // deferred_tools/cache/model_catalog stack differs (asserted above).
    assert_modules(
        &r.modules,
        &[
            "trust",
            "session_tree",
            "session_share",
            "server",
            "plugins",
            "tui",
        ],
        &[
            "mcp",
            "permissions",
            "subagents",
            "todos",
            "tools_background",
            "tools_web",
        ],
    );
}

#[test]
fn direct_reduction_gate_overrides_token_saver_preset() {
    let r = resolve(
        "extends = \"token-saver\"\n[capabilities.reduction]\nstale_reads = false\n",
        None,
        &ResolveOptions::default(),
    )
    .expect("direct reduction override resolves");
    assert_eq!(r.config.reduction_policy.stale_reads, Some(false));
    assert_eq!(r.config.reduction_policy.diff_reads, Some(true));
    assert_eq!(r.config.reduction_policy.duplicates, Some(true));
    assert!(r.config.handoff_enabled);
}

#[test]
fn reduction_master_false_disables_the_separate_handoff_consumer() {
    let r = resolve(
        "extends = \"token-saver\"\n[capabilities.reduction]\nenabled = false\n",
        None,
        &ResolveOptions::default(),
    )
    .expect("token-saver with reduction master disabled must resolve");
    assert!(!r.config.handoff_enabled);
}

// ---------------------------------------------------------------------------
// supercode-default — §4 intro (S10 fix). §4.6 verdict: PASS, two named
// residuals: C1 (apply_patch co-advertised with edit_file/write_file, no
// model_catalog bits — "faithful to today's actual unfiltered default
// stack") AND C3 (mandatory, same as pi-core). No plugins→trust edge at all
// (both off, S10's whole point).
// ---------------------------------------------------------------------------
#[test]
fn supercode_default_resolves_with_c1_and_c3_no_plugins_trust_edge() {
    let r = resolve_preset("supercode-default");

    // Core knobs identical to pi-core, unchanged.
    assert_eq!(r.config.effort.as_deref(), Some("medium"));
    assert_eq!(r.config.max_tool_output_bytes, Some(51200));

    assert_modules(
        &r.modules,
        &[
            "tools_search",
            "tools_apply_patch",
            "tools_persistent_shell",
            "todos",
            "notify",
        ],
        &[
            "trust",
            "session_tree",
            "session_share",
            "server",
            "plugins",
            "reduction",
            "permissions",
        ],
    );
    // tui stays on (§1.9 deviation, inherited from pi-core).
    assert_modules(&r.modules, &["tui"], &[]);

    assert_eq!(
        r.warnings.len(),
        2,
        "supercode-default should carry exactly C1 + C3: {:?}",
        r.warnings
    );
    assert!(r.warnings.iter().any(|w| w.contains("C1")));
    assert!(r.warnings.iter().any(|w| w.contains("C3")));

    // No plugins→trust dependency edge is even evaluated (S10: both off) —
    // resolution must not error, and no D-10 message should appear.
    assert!(!r.warnings.iter().any(|w| w.contains("D-10")));
}

/// A no-config-file resolution must land on `supercode-default` semantics
/// (design §4 intro: "supercode with no config file resolves to this
/// preset ... the current default stack's C3 exposure is named and warned
/// about rather than implicit"). This proves the PRESET's own shape matches
/// today's actual `Config::default()`/`with_builtins()` posture — CLI
/// wiring of "no file -> extends=supercode-default" is a separate, later
/// step (see this crate's tests/composable_resolver.rs for the note on
/// what's left to P3).
#[test]
fn supercode_default_matches_todays_actual_default_posture() {
    let r = resolve_preset("supercode-default");
    // Today's literal Config::default() / tools/mod.rs defaults.
    assert_eq!(r.config.sandbox, SandboxPolicy::DangerFullAccess);
    assert_eq!(r.config.approval, ApprovalPolicy::Never);
}