tandem-plan-compiler 0.5.5

Mission and plan compiler boundary for Tandem
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
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
// Copyright (c) 2026 Frumu LTD
// Licensed under the Business Source License 1.1

use serde::{Deserialize, Serialize};
use serde_json::{json, Value};
use std::collections::BTreeSet;

use crate::workflow_plan::{
    workflow_plan_mentions_connector_backed_sources, workflow_plan_mentions_web_research_tools,
};

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum WorkflowDecompositionTier {
    Simple,
    Moderate,
    Complex,
    VeryComplex,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct WorkflowDecompositionProfile {
    pub complexity_score: u8,
    pub tier: WorkflowDecompositionTier,
    pub recommended_min_leaf_tasks: u8,
    pub recommended_max_leaf_tasks: u8,
    pub recommended_phase_count: u8,
    pub requires_phased_dag: bool,
    #[serde(default)]
    pub signals: Vec<String>,
    #[serde(default)]
    pub guidance: Vec<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct WorkflowStepDecompositionHints {
    pub phase_id: String,
    pub task_class: String,
    pub task_family: String,
    pub retry_class: String,
    #[serde(default, skip_serializing_if = "Option::is_none")]
    pub parent_step_id: Option<String>,
}

fn push_signal(signals: &mut Vec<String>, signal: impl Into<String>) {
    let signal = signal.into();
    if !signal.trim().is_empty() && !signals.iter().any(|existing| existing == &signal) {
        signals.push(signal);
    }
}

fn has_any(text: &str, needles: &[&str]) -> bool {
    needles.iter().any(|needle| text.contains(needle))
}

fn score_text_signals(lowered: &str, score: &mut u16, signals: &mut Vec<String>) {
    let word_count = lowered.split_whitespace().count();
    if word_count >= 20 {
        *score += 4;
        push_signal(signals, format!("prompt_word_count>=20:{word_count}"));
    }
    if word_count >= 40 {
        *score += 6;
        push_signal(signals, format!("prompt_word_count>=40:{word_count}"));
    }
    if word_count >= 80 {
        *score += 10;
        push_signal(signals, format!("prompt_word_count>=80:{word_count}"));
    }

    let conjunction_count = [
        " and ", " then ", " after ", " before ", " while ", " plus ", " also ",
    ]
    .iter()
    .map(|needle| lowered.matches(needle).count())
    .sum::<usize>();
    if conjunction_count >= 3 {
        *score += 4;
        push_signal(signals, format!("multi_clause_prompt={conjunction_count}"));
    }
}

fn classify_task_class(lowered: &str, output_contract_kind: Option<&str>) -> String {
    let output_contract_kind = output_contract_kind
        .map(|value| value.trim().to_ascii_lowercase())
        .filter(|value| !value.is_empty());

    if output_contract_kind.as_deref() == Some("code_patch")
        || has_any(
            lowered,
            &[
                "code",
                "patch",
                "implement",
                "implementation",
                "refactor",
                "edit source",
                "bug fix",
                "repo fix",
                "fix the code",
            ],
        )
    {
        return "code_change".to_string();
    }

    if has_any(
        lowered,
        &[
            "send ",
            "send the ",
            "email",
            "publish",
            "post ",
            "deliver",
            "notify",
            "share ",
            "submit ",
        ],
    ) {
        return "delivery".to_string();
    }

    if has_any(
        lowered,
        &[
            "repair", "retry", "recover", "restore", "debug", "fix ", "failure", "blocked",
        ],
    ) {
        return "repair".to_string();
    }

    if has_any(
        lowered,
        &[
            "verify", "validate", "test", "review", "check", "qa", "approval", "gate",
        ],
    ) {
        return "validation".to_string();
    }

    if has_any(
        lowered,
        &[
            "research", "search", "collect", "inspect", "gather", "discover", "source",
        ],
    ) {
        return "research".to_string();
    }

    if output_contract_kind.as_deref().is_some_and(|kind| {
        matches!(
            kind,
            "brief" | "citations" | "report_markdown" | "text_summary"
        )
    }) || has_any(
        lowered,
        &[
            "synthes",
            "summar",
            "compare",
            "analy",
            "consolidat",
            "brief",
            "report",
            "recap",
            "digest",
        ],
    ) {
        return "synthesis".to_string();
    }

    if has_any(lowered, &["triage", "assess", "intake", "classify"]) {
        return "triage".to_string();
    }

    "general".to_string()
}

fn task_family_for_task_class(task_class: &str) -> String {
    match task_class {
        "code_change" => "code",
        "research" | "synthesis" => "research",
        "validation" => "verification",
        "delivery" | "repair" | "triage" => "ops",
        _ => "planning",
    }
    .to_string()
}

fn phase_label_for_profile(
    step_index: usize,
    step_count: usize,
    profile: &WorkflowDecompositionProfile,
) -> String {
    if profile.recommended_phase_count <= 1 || step_count <= 1 {
        return "phase_1_main".to_string();
    }

    let phase_count = usize::from(profile.recommended_phase_count.max(1));
    let bucket = ((step_index * phase_count) / step_count).min(phase_count.saturating_sub(1));
    let label = match phase_count {
        1 => "main",
        2 => match bucket {
            0 => "discover",
            _ => "deliver",
        },
        3 => match bucket {
            0 => "discover",
            1 => "synthesize",
            _ => "deliver",
        },
        4 => match bucket {
            0 => "discover",
            1 => "synthesize",
            2 => "validate",
            _ => "deliver",
        },
        _ => "phase",
    };
    format!("phase_{}_{}", bucket + 1, label)
}

fn retry_class_for_task_class(task_class: &str, output_contract_kind: Option<&str>) -> String {
    if output_contract_kind
        .map(|value| value.trim().eq_ignore_ascii_case("code_patch"))
        .unwrap_or(false)
        || task_class == "code_change"
    {
        return "inspect_patch_test_repair".to_string();
    }
    match task_class {
        "research" | "synthesis" => "artifact_write".to_string(),
        "validation" => "verification_loop".to_string(),
        "delivery" => "delivery_only".to_string(),
        "repair" => "repair_only".to_string(),
        "triage" => "triage_gate".to_string(),
        _ => "standard".to_string(),
    }
}

fn score_output_targets(target_count: usize, score: &mut u16, signals: &mut Vec<String>) {
    if target_count >= 1 {
        *score += 4;
        push_signal(signals, format!("output_targets={target_count}"));
    }
    if target_count >= 2 {
        *score += 6;
    }
    if target_count >= 3 {
        *score += 4;
    }
}

fn score_connector_signals(
    prompt: &str,
    allowed_mcp_servers: &[String],
    score: &mut u16,
    signals: &mut Vec<String>,
) {
    if !allowed_mcp_servers.is_empty() {
        *score += 6;
        push_signal(
            signals,
            format!("allowed_mcp_servers={}", allowed_mcp_servers.len()),
        );
        if allowed_mcp_servers.len() > 1 {
            *score += 3;
        }
    }
    if workflow_plan_mentions_connector_backed_sources(prompt) {
        *score += 6;
        push_signal(signals, "connector_backed_sources");
    }
    if workflow_plan_mentions_web_research_tools(prompt) {
        *score += 6;
        push_signal(signals, "web_research_tools");
    }
}

fn score_workflow_terms(lowered: &str, score: &mut u16, signals: &mut Vec<String>) {
    let categories = [
        (
            "research",
            has_any(
                lowered,
                &[
                    "research", "search", "collect", "inspect", "source", "evidence",
                ],
            ),
        ),
        (
            "synthesis",
            has_any(
                lowered,
                &[
                    "synthes", "summar", "compare", "analy", "brief", "report", "recap",
                ],
            ),
        ),
        (
            "delivery",
            has_any(
                lowered,
                &[
                    "send", "publish", "post ", "deliver", "notify", "share", "submit",
                ],
            ),
        ),
        (
            "validation",
            has_any(
                lowered,
                &[
                    "verify", "validate", "test", "review", "check", "approval", "gate",
                ],
            ),
        ),
        (
            "repair",
            has_any(
                lowered,
                &["repair", "retry", "fix", "recover", "debug", "blocked"],
            ),
        ),
        (
            "implementation",
            has_any(
                lowered,
                &["code", "patch", "implement", "refactor", "edit source"],
            ),
        ),
    ];

    let mut active = BTreeSet::new();
    for (name, matched) in categories {
        if matched {
            active.insert(name);
        }
    }
    if active.len() >= 2 {
        *score += 8;
        push_signal(signals, format!("task_categories={}", active.len()));
    }
    if active.len() >= 3 {
        *score += 8;
    }
    if active.contains("repair") && active.contains("validation") {
        *score += 4;
    }
    if active.contains("delivery") && active.contains("synthesis") {
        *score += 4;
    }
}

fn is_compact_research_delivery_prompt(lowered: &str) -> bool {
    let asks_for_research = has_any(
        lowered,
        &[
            "research",
            "search",
            "collect",
            "gather",
            "market signal",
            "market signals",
        ],
    );
    let asks_for_concise_deliverable = has_any(
        lowered,
        &[
            "concise brief",
            "concise market brief",
            "market brief",
            "brief",
            "report",
            "summary",
        ],
    ) && has_any(lowered, &["concise", "short", "brief"]);
    let asks_for_external_save = has_any(
        lowered,
        &[
            "notion",
            "database",
            "collection://",
            "save the completed report",
            "create a page",
            "create one page",
        ],
    );
    let asks_for_large_work_program = has_any(
        lowered,
        &[
            "comprehensive",
            "exhaustive",
            "deep dive",
            "all sources",
            "every source",
            "multi-week",
            "many deliverables",
            "approval before",
            "require approval",
            "human approval",
        ],
    );

    asks_for_research
        && asks_for_concise_deliverable
        && asks_for_external_save
        && !asks_for_large_work_program
}

pub fn derive_workflow_decomposition_profile(
    prompt: &str,
    allowed_mcp_servers: &[String],
    explicit_output_targets: &[String],
    has_explicit_schedule: bool,
) -> WorkflowDecompositionProfile {
    let lowered = prompt.trim().to_ascii_lowercase();
    let mut score: u16 = 0;
    let mut signals = Vec::new();

    score_text_signals(&lowered, &mut score, &mut signals);
    score_output_targets(explicit_output_targets.len(), &mut score, &mut signals);
    score_connector_signals(prompt, allowed_mcp_servers, &mut score, &mut signals);
    score_workflow_terms(&lowered, &mut score, &mut signals);

    if has_explicit_schedule {
        score += 4;
        push_signal(&mut signals, "scheduled_workflow");
    }

    let compact_research_delivery = is_compact_research_delivery_prompt(&lowered);
    if compact_research_delivery {
        score = score.min(39);
        push_signal(&mut signals, "compact_research_delivery");
    }

    let complexity_score = score.min(100) as u8;
    let (tier, recommended_min_leaf_tasks, recommended_max_leaf_tasks, recommended_phase_count) =
        if compact_research_delivery {
            (WorkflowDecompositionTier::Moderate, 5, 8, 2)
        } else {
            match complexity_score {
                0..=24 => (WorkflowDecompositionTier::Simple, 1, 4, 1),
                25..=44 => (WorkflowDecompositionTier::Moderate, 4, 8, 2),
                45..=69 => (WorkflowDecompositionTier::Complex, 6, 8, 3),
                _ => (WorkflowDecompositionTier::VeryComplex, 6, 8, 4),
            }
        };
    let requires_phased_dag = recommended_phase_count > 1;
    let mut guidance = match tier {
        WorkflowDecompositionTier::Simple => vec![
            "Keep generated plans at 1-4 leaf tasks unless the user explicitly asks for manual detailed decomposition.".to_string(),
            "A single phase is acceptable when the work has one evidence source and one output.".to_string(),
        ],
        WorkflowDecompositionTier::Moderate => vec![
            "Target 4-8 generated leaf tasks.".to_string(),
            "Split discovery from synthesis or delivery when they are separate responsibilities.".to_string(),
        ],
        WorkflowDecompositionTier::Complex => vec![
            "Use at most 8 generated leaf tasks; compact detailed work into phase-level macro steps.".to_string(),
            "Use explicit phases for discover, synthesize, validate, and deliver/repair leaves.".to_string(),
            "Do not create one task per section, source subtype, or repair branch unless the user explicitly authored that structure.".to_string(),
        ],
        WorkflowDecompositionTier::VeryComplex => vec![
            "Generated workflows still have an 8-task ceiling; larger DAGs require manual Studio authoring or explicit import.".to_string(),
            "Keep each leaf to one primary objective, one output contract, and one validation path.".to_string(),
            "Use parent_step_id and phase_id hints so the runtime can narrow retries instead of reopening the whole graph.".to_string(),
        ],
    };
    if compact_research_delivery {
        guidance = vec![
            "Target 5-6 leaf tasks for this compact research-delivery workflow.".to_string(),
            "Bundle related web, MCP, and community research by evidence source or phase; do not create one task per report section.".to_string(),
            "Use one synthesis task to draft the requested brief sections together.".to_string(),
            "Use one destination-write task for Notion/database creation and one lightweight verification task when needed.".to_string(),
            "Do not add a human approval gate unless the user explicitly asked for approval before publishing.".to_string(),
        ];
    }

    WorkflowDecompositionProfile {
        complexity_score,
        tier,
        recommended_min_leaf_tasks,
        recommended_max_leaf_tasks,
        recommended_phase_count,
        requires_phased_dag,
        signals,
        guidance,
    }
}

pub fn workflow_plan_decomposition_sections(profile: &WorkflowDecompositionProfile) -> String {
    let signals = if profile.signals.is_empty() {
        "none".to_string()
    } else {
        profile.signals.join(", ")
    };
    let tier = match &profile.tier {
        WorkflowDecompositionTier::Simple => "simple",
        WorkflowDecompositionTier::Moderate => "moderate",
        WorkflowDecompositionTier::Complex => "complex",
        WorkflowDecompositionTier::VeryComplex => "very_complex",
    };
    let guidance = if profile.guidance.is_empty() {
        "- keep each leaf task narrow".to_string()
    } else {
        profile
            .guidance
            .iter()
            .map(|line| format!("- {line}"))
            .collect::<Vec<_>>()
            .join("\n")
    };
    format!(
        concat!(
            "Decomposition profile:\n",
            "- complexity_score: {}\n",
            "- tier: {}\n",
            "- recommended_leaf_tasks: {}-{}\n",
            "- recommended_phase_count: {}\n",
            "- requires_phased_dag: {}\n",
            "- signals: {}\n",
            "Decomposition rules:\n",
            "{}\n",
            "- use phase_id, task_class, retry_class, and parent_step_id metadata when they help preserve the hierarchy\n",
            "- keep one primary objective, one primary output contract, and one validation path per leaf task\n",
        ),
        profile.complexity_score,
        tier,
        profile.recommended_min_leaf_tasks,
        profile.recommended_max_leaf_tasks,
        profile.recommended_phase_count,
        profile.requires_phased_dag,
        signals,
        guidance,
    )
}

pub fn workflow_plan_decomposition_observation(
    profile: &WorkflowDecompositionProfile,
    generated_step_count: usize,
) -> Value {
    let budget_status = if generated_step_count < profile.recommended_min_leaf_tasks as usize {
        "below_recommended"
    } else if generated_step_count > profile.recommended_max_leaf_tasks as usize {
        "above_recommended"
    } else {
        "within_recommended"
    };
    json!({
        "decomposition_profile": profile,
        "generated_step_count": generated_step_count,
        "budget_status": budget_status,
    })
}

pub fn derive_step_decomposition_hints(
    step_id: &str,
    kind: &str,
    objective: &str,
    output_contract_kind: Option<&str>,
    depends_on: &[String],
    step_index: usize,
    step_count: usize,
    profile: &WorkflowDecompositionProfile,
) -> WorkflowStepDecompositionHints {
    let lowered = format!("{step_id} {kind} {objective}").to_ascii_lowercase();
    let task_class = classify_task_class(&lowered, output_contract_kind);
    let phase_id = phase_label_for_profile(step_index, step_count, profile);
    let retry_class = retry_class_for_task_class(&task_class, output_contract_kind);
    let task_family = task_family_for_task_class(&task_class);
    let parent_step_id = depends_on
        .first()
        .map(|value| value.trim().to_string())
        .filter(|value| !value.is_empty());

    WorkflowStepDecompositionHints {
        phase_id,
        task_class,
        task_family,
        retry_class,
        parent_step_id,
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn decomposition_profile_scales_with_task_breadth_and_connectors() {
        let simple =
            derive_workflow_decomposition_profile("Write a quick summary", &[], &[], false);
        let complex = derive_workflow_decomposition_profile(
            "Research Reddit, compare findings, draft a report, and email it to the team",
            &["github".to_string(), "tandem-mcp".to_string()],
            &[
                "reports/summary.md".to_string(),
                "docs/standups/2026-04-15.md".to_string(),
            ],
            true,
        );

        assert_eq!(simple.tier, WorkflowDecompositionTier::Simple);
        assert!(simple.complexity_score < complex.complexity_score);
        assert!(complex.requires_phased_dag);
        assert!(complex.recommended_min_leaf_tasks >= 4);
        assert!(complex.recommended_max_leaf_tasks <= 8);
        assert!(complex.recommended_phase_count >= 2);
        assert!(complex
            .signals
            .iter()
            .any(|signal| signal.contains("output_targets")));
        assert!(complex
            .signals
            .iter()
            .any(|signal| signal == "connector_backed_sources"));
    }

    #[test]
    fn step_hints_prefer_explicit_task_classes_and_dependency_parents() {
        let profile = WorkflowDecompositionProfile {
            complexity_score: 72,
            tier: WorkflowDecompositionTier::VeryComplex,
            recommended_min_leaf_tasks: 30,
            recommended_max_leaf_tasks: 50,
            recommended_phase_count: 4,
            requires_phased_dag: true,
            signals: vec!["manual_profile".to_string()],
            guidance: vec!["Split the work across explicit phases.".to_string()],
        };
        let hints = derive_step_decomposition_hints(
            "repair_code",
            "repair",
            "Patch the code and verify it with tests",
            Some("code_patch"),
            &["inspect".to_string()],
            2,
            4,
            &profile,
        );

        assert_eq!(hints.task_class, "code_change");
        assert_eq!(hints.phase_id, "phase_3_validate");
        assert_eq!(hints.task_family, "code");
        assert_eq!(hints.retry_class, "inspect_patch_test_repair");
        assert_eq!(hints.parent_step_id.as_deref(), Some("inspect"));
    }

    #[test]
    fn decomposition_sections_include_budget_guidance() {
        let profile = derive_workflow_decomposition_profile(
            "Research, compare, and deliver an email report",
            &["gmail".to_string()],
            &["reports/report.md".to_string()],
            true,
        );
        let sections = workflow_plan_decomposition_sections(&profile);

        assert!(sections.contains("Decomposition profile:"));
        assert!(sections.contains("recommended_leaf_tasks"));
        assert!(sections.contains("phase_id"));
        assert!(sections.contains("one primary objective"));
    }

    #[test]
    fn decomposition_profile_caps_compact_research_delivery_workflows() {
        let prompt = r#"research this topic:

"What are the current approaches to making AI agents reliable for business workflows?"

Use the connected Tandem MCP docs as reference if needed, and use the connected Reddit MCP plus web research to gather current market signals, discussions, examples, and source links.

Then create a concise market brief and save the completed report into the Notion database:

Operational Workflow Results
collection://892d3e9b-2bf8-4b3e-a541-dc725f77295d

The Notion page should include:
- Summary
- Key Findings
- Market Notes
- Reddit Signals
- Sources
- Tandem Run details"#;

        let profile = derive_workflow_decomposition_profile(
            prompt,
            &[
                "tandem_mcp".to_string(),
                "reddit".to_string(),
                "notion".to_string(),
            ],
            &[],
            false,
        );

        assert_eq!(profile.tier, WorkflowDecompositionTier::Moderate);
        assert_eq!(profile.recommended_min_leaf_tasks, 5);
        assert_eq!(profile.recommended_max_leaf_tasks, 8);
        assert_eq!(profile.recommended_phase_count, 2);
        assert!(profile.requires_phased_dag);
        assert!(profile
            .signals
            .iter()
            .any(|signal| signal == "compact_research_delivery"));
        assert!(profile
            .guidance
            .iter()
            .any(|line| line.contains("do not create one task per report section")));
        assert!(profile
            .guidance
            .iter()
            .any(|line| line.contains("Do not add a human approval gate")));
    }

    #[test]
    fn decomposition_profile_requires_phases_for_resume_job_search_prompt() {
        let prompt = "Analyze the local `RESUME.md` file and use it as the source of truth for skills, role targets, seniority, technologies, and geography preferences.

This workflow must stay simple and deterministic.

## Core rules

- Never edit, rewrite, rename, move, or delete `RESUME.md`
- Only read from `RESUME.md`
- If `resume_overview.md` does not exist, create it
- If `resume_overview.md` already exists, reuse it and do not regenerate it unless it is missing
- Use the `websearch` tool to find relevant job boards and recruitment sites in Europe where jobs are posted for the skills found in `RESUME.md`
- Save all results to a daily timestamped results file
- This workflow may run many times in one day, so it must append new findings to the same daily file instead of creating many separate files for the same date";

        let explicit_output_targets = crate::workflow_plan::infer_explicit_output_targets(prompt);
        let profile =
            derive_workflow_decomposition_profile(prompt, &[], &explicit_output_targets, true);

        assert!(profile.requires_phased_dag);
        assert!(profile.recommended_phase_count >= 2);
        assert!(profile.complexity_score >= 25);
        assert!(profile
            .signals
            .iter()
            .any(|signal| signal.contains("output_targets")));
        assert!(profile
            .signals
            .iter()
            .any(|signal| signal == "web_research_tools"));
    }
}