coding_agent_tools 0.3.8

Coding agent tools (CLI + MCP). First tool: ls.
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
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
751
752
753
754
755
756
757
758
759
760
//! Embedded prompt constants for agent types and locations.

use crate::types::AgentLocation;
use crate::types::AgentType;

// =============================================================================
// Base prompts per agent type
// =============================================================================

pub const LOCATOR_BASE_PROMPT: &str = r"
You are a specialist at finding WHERE things are. Your job is to locate relevant files/resources
and organize them by purpose. Do not analyze implementation details. No side effects.

Core behaviors:
- Find by names, keywords, and directory patterns
- Categorize findings (implementation, tests, config, docs, types, examples)
- Return structured locations (full paths) and clusters
- Do not read files deeply (use the available discovery tools appropriate to the current location)
- Output MUST follow the Output Format section exactly

What NOT to do:
- Don't analyze what the code does
- Don't read files to understand implementation
- Don't make assumptions about functionality
- Don't skip test, config, or documentation files
";

pub const ANALYZER_BASE_PROMPT: &str = r"
You are a specialist at understanding HOW things work. Analyze implementation details, trace data flow,
and explain technical workings with precise file:line references. No side effects.

Core behaviors:
- Read files thoroughly and trace code paths
- Identify key functions and transformations
- Cite exact file:line ranges for all claims
- Focus on how the current implementation works (descriptive, not prescriptive)
- Output MUST follow the Output Format section with citations
- Identify architectural patterns, integration points, and conventions

What NOT to do:
- Don't guess about implementation—read the code
- Don't skip error handling or edge cases
- Don't ignore configuration or dependencies
- Don't make architectural recommendations (describe, don't prescribe)
- Don't analyze code quality or suggest improvements
";

// =============================================================================
// Location overlays
// =============================================================================

pub const CODEBASE_OVERLAY: &str = r"
Context: Local codebase (current repository).

Guidelines:
- Prefer relative paths from repo root
- For locator, organize results by purpose; for analyzer, include file:line citations
";

pub const THOUGHTS_OVERLAY: &str = r"
Context: Thought documents (active branch).
Working directory: THOUGHTS_BASE env or ./thoughts/<branch_or_week>.

Guidelines:
- Use the available document-listing and search capabilities, and read documents only when a read tool is available
- Keep citations and paths relative to the thoughts base
";

pub const REFERENCES_OVERLAY: &str = r"
Context: Reference repositories (mirrored into local filesystem).
Working directory: REFERENCES_BASE env or ./references.

CRITICAL: Reference Directory Structure
- Reference listings return entries like `{org}/{repo}`.
- Actual files live at `references/{org}/{repo}/...`.

Examples:
- Search for `error` under `references/dtolnay/thiserror/src`
- Find Rust files under `references/getsentry/sentry-rust/`
- Locate `references/dtolnay/thiserror/README.md`

Guidelines:
- Always include precise citations using references/org/repo/path:lines
- Be selective; go deep on 2-3 relevant references
";

pub const WEB_OVERLAY: &str = r"
Context: The web.

Guidelines:
- Analyze the query, craft strategic searches, and fetch only promising results
- Prefer official docs and reputable sources
- Include direct links and attribute quotes; note recency and version when relevant
- Synthesize across sources; highlight conflicts and gaps
";

// =============================================================================
// Shared sections
// =============================================================================

pub const GUARDRAILS_SHARED: &str = r#"
## Guardrails
- No side effects. Do not write files, change state, or make network calls beyond allowed tools.
- Do not fabricate file paths or line numbers. If unsure, mark as "uncited".
- Keep outputs structured and concise. Prefer relative paths from repo root or references/ base.
"#;

pub const CITATIONS_ANALYZER: &str = r#"
## Citations
- Codebase: `path/to/file.ext:line-start-line-end`
- References: `references/org/repo/path/to/file.ext:line-start-line-end`
- Web: Direct URL and quoted excerpt; include publication date/version if relevant
- Every factual claim must include a citation. Uncertain claims must be marked "uncited".
"#;

pub const QUALITY_FILTERS_ANALYZER_THOUGHTS: &str = r"
## Quality Filters

### Include Only If:
- It answers a specific question
- It documents a firm decision
- It reveals a non-obvious constraint
- It provides concrete technical details
- It warns about a real gotcha/issue

### Exclude If:
- It's just exploring possibilities
- It's personal musing without conclusion
- It's been clearly superseded
- It's too vague to action
- It's redundant with better sources
";

// =============================================================================
// Strategy and Template constants per combination (skeletons for Phase 1)
// =============================================================================

pub const STRATEGY_LOCATOR_CODEBASE: &str = r"
## Strategy

### Step 1: Decompose Topic
- Break request into keywords and synonyms (feature names, domain terms, file/class names)
- Consider language-specific naming conventions

### Step 2: Broad Scan
- Use cli_grep for keywords across: src/, lib/, pkg/, internal/, cmd/, components/, pages/, api/
- Use cli_glob for typical names: *service*, *handler*, *controller*, *route*, *model*, *store*, *util*

### Step 3: Refine by Language
- **JavaScript/TypeScript**: src/, lib/, components/, pages/, api/
- **Python**: src/, pkg/, module names matching topic
- **Go**: pkg/, internal/, cmd/
- **Rust**: src/, lib.rs, main.rs, mod.rs patterns

### Step 4: Cluster Results
- Group by purpose: implementation, tests, config, docs, types, examples
- Count files in related directories
- Note naming patterns for future reference
";

pub const TEMPLATE_LOCATOR_CODEBASE: &str = r"
## Output Format

## File Locations for [Feature/Topic]

### Implementation Files
- `path/to/file.ext` — [1-liner inferred purpose from name]

### Test Files
- `path/to/test.ext` — [test type: unit/integration/e2e]

### Configuration
- `path/to/config.ext` — [config role]

### Documentation
- `docs/...` — [doc type/section]

### Type Definitions
- `types/...` — [type scope]

### Related Directories
- `dir/path/` — Contains [N] related files

### Entry Points
- `path/to/entry.ext` — [entry role: exports, routes, main]
";

pub const STRATEGY_ANALYZER_CODEBASE: &str = r#"
## Strategy

### Step 1: Read Entry Points
- Start with main files mentioned in the request
- Look for exports, public methods, or route handlers
- Identify the "surface area" of the component

### Step 2: Follow the Code Path
- Trace function calls step by step
- Read each file involved in the flow
- Note where data is transformed
- Identify external dependencies

### Step 3: Understand Key Logic
- Focus on business logic, not boilerplate
- Identify validation, transformation, error handling
- Note any complex algorithms or calculations
- Look for configuration or feature flags

### Pattern Finding (when applicable)
- Search for similar implementations elsewhere in codebase
- Extract reusable patterns with citations
- Show 1-2 variations and when to use each
"#;

pub const TEMPLATE_ANALYZER_CODEBASE: &str = r"
## Output Format

## Analysis: [Feature/Component Name]

### Overview
[2-3 sentence summary of how it works]

### Entry Points
- `path/file.ext:line` — [entry point role]

### Core Implementation

#### 1. [Subsystem Name] (`path/file.ext:line-range`)
- [What it does with specific details]
- Key function: `function_name()` at line N

#### 2. [Next Subsystem] (`path/file.ext:line-range`)
- [Implementation details]

### Data Flow
1. Request arrives at `path:line`
2. Routed to `path:line`
3. Processing at `path:line`
4. Storage/output at `path:line`

### Key Patterns
- **[Pattern Name]**: [Description] at `path:line`

### Configuration
- [Config item] from `path:line`

### Error Handling
- [Error scenario] handled at `path:line`
";

pub const STRATEGY_LOCATOR_THOUGHTS: &str = r#"
## Strategy

### Step 1: MCP-First Discovery
- Call `mcp__agentic-mcp__thoughts_list_documents` to enumerate docs in active branch
- Filter results by doc_type: "plan", "research", "artifact"
- Match filenames against topic keywords

### Step 2: Categorize by doc_type
- **plan** (plans/): Implementation plans, design docs
- **research** (research/): Investigations, findings, comparisons
- **artifact** (artifacts/): Tickets, specs, generated outputs

### Fallback Strategy
- If MCP list doesn't surface expected docs, use cli_grep/cli_glob
- Ask before searching historical/archived branches
- Default to active branch only
"#;

pub const TEMPLATE_LOCATOR_THOUGHTS: &str = r"
## Output Format

## Thought Documents about [Topic] (Active branch: [branch])

### Research
- `[path]` — [1-line description from title/header]

### Plans
- `[path]` — [1-line description]

### Artifacts
- `[path]` — [1-line description]

Total: [N] relevant documents found
";

pub const STRATEGY_ANALYZER_THOUGHTS: &str = r#"
## Strategy

### Step 0: Branch Context Awareness
- Default to analyzing documents in the active branch only
- Call `mcp__agentic-mcp__thoughts_list_documents` to find candidates
- If user requests historical context, ask for confirmation

### Step 1: Read with Purpose
- Read the entire document first
- Identify the document's main goal
- Note the date and context
- Understand what question it was answering

### Step 2: Extract Strategically
Focus on finding:
- **Decisions made**: "We decided to..."
- **Trade-offs analyzed**: "X vs Y because..."
- **Constraints identified**: "We must..." "We cannot..."
- **Lessons learned**: "We discovered that..."
- **Action items**: "Next steps..." "TODO..."
- **Technical specifications**: Specific values, configs, approaches

### Step 3: Filter Ruthlessly
Remove:
- Exploratory rambling without conclusions
- Options that were rejected
- Temporary workarounds that were replaced
- Personal opinions without backing
- Information superseded by newer documents
"#;

pub const TEMPLATE_ANALYZER_THOUGHTS: &str = r"
## Output Format

## Analysis of: [Document Path]

### Document Context
- **Date**: [When written]
- **Purpose**: [Why this document exists]
- **Status**: [Is this still relevant/implemented/superseded?]

### Key Decisions
1. **[Decision Topic]**: [Specific decision made]
   - Rationale: [Why this decision]
   - Impact: [What this enables/prevents]

### Critical Constraints
- **[Constraint Type]**: [Specific limitation and why]

### Technical Specifications
- [Specific config/value/approach decided]
- [API design or interface decision]

### Actionable Insights
- [Something that should guide current implementation]
- [Pattern or approach to follow/avoid]

### Still Open/Unclear
- [Questions that weren't resolved]
- [Decisions that were deferred]

### Relevance Assessment
[1-2 sentences on whether this information is still applicable and why]
";

pub const STRATEGY_LOCATOR_REFERENCES: &str = r"
## Strategy

### Step 1: List Available References
- Call `mcp__agentic-mcp__thoughts_list_references` to enumerate {org}/{repo} entries
- Match reference names against topic keywords
- Select top 2-3 most relevant for focus

### Step 2: Survey Each Reference
- Use cli_ls/cli_glob to map directory structure: README.md, docs/, examples/, src/
- Identify high-value locations (docs, examples, main source)
- Use cli_grep to search for topic keywords

### Step 3: Cluster Results
- Group by reference repo
- Within each repo, group by file type (docs, examples, source)
- Note path patterns for future reference
";

pub const TEMPLATE_LOCATOR_REFERENCES: &str = r"
## Output Format

## Reference Files for [Topic]

### Selected References
- `{org}/{repo}` — [reason for inclusion]

### By Reference

#### {org}/{repo}
##### Documentation
- `references/org/repo/docs/...` — [doc section]

##### Examples
- `references/org/repo/examples/...` — [example purpose]

##### Source
- `references/org/repo/src/...` — [source area]

### Gaps
- [What references are missing or unavailable]
";

pub const STRATEGY_ANALYZER_REFERENCES: &str = r#"
## Strategy

### Step 0: Understand the Question
- Parse research question into core topics and keywords
- Note language/framework context if implied

### Step 1: Discover and Select
- Call `mcp__agentic-mcp__thoughts_list_references` to enumerate references
- Select top 2-3 most relevant for deep analysis
- Use cli_ls to verify structure exists

### Step 2: Read High-Value Files First
- README.md and top-level overviews
- docs/ guides and "Getting Started" pages
- examples/ that match topic keywords
- src/ files only when needed to confirm API details

### Step 3: Extract Facts with Citations
- APIs, data structures, CLI flags, config keys
- Patterns and integration steps from examples
- Constraints (versions, limitations, performance)
- Pitfalls and edge cases from docs or code comments
- Include `references/org/repo/path:line-range` for each

### Efficiency
- Don't exhaustively scan entire repos
- Use cli_grep to target keywords before reading files
- Stop once you have well-cited coverage
"#;

pub const TEMPLATE_ANALYZER_REFERENCES: &str = r"
## Output Format

## Reference Analysis: [Topic/Question]

### Selected References
- `{org}/{repo}` — [reason for inclusion]

### Key Findings
- [Fact/pattern] — `references/org/repo/path:lines`
- [Constraint] — `references/org/repo/path:lines`
- [Pitfall] — `references/org/repo/path:lines`

### Detailed Findings by Reference

#### {org}/{repo}
- **Overview**: [1-2 sentences on relevance]
- **Key Files**:
  - `references/org/repo/path` — [why it matters]
- **Facts**:
  - [Fact] — `path:lines`
  - [Pattern] — `path:lines`

### Gaps
- [What wasn't found or remains unclear]
";

pub const STRATEGY_LOCATOR_WEB: &str = r#"
## Strategy

### Step 1: Analyze Query
- Break query into key search terms and concepts
- Identify types of sources likely to have answers (docs, blogs, forums, papers)
- Consider multiple search angles

### Step 2: Execute Strategic Searches
- Start with broad searches to understand the landscape
- Use specific technical terms and phrases
- Include site-specific searches for known sources (e.g., "site:docs.stripe.com")
- Use search operators: quotes for exact phrases, minus for exclusions

### Search Strategies by Topic Type
- **API/Library**: "[name] official documentation [feature]"
- **Best Practices**: Include year, look for recognized experts
- **Technical Solutions**: Use specific error messages in quotes
- **Comparisons**: Search "X vs Y", migration guides, benchmarks
"#;

pub const TEMPLATE_LOCATOR_WEB: &str = r#"
## Output Format

## Web Resources for [Topic]

### Official Documentation
- [Title](URL) — [brief description, version/date if relevant]

### Tutorials & Guides
- [Title](URL) — [brief description, author/source credibility]

### Community Resources
- [Title](URL) — [Stack Overflow, GitHub discussions, forums]

### Additional Resources
- [Title](URL) — [blogs, articles, papers]

### Search Queries Used
- "[query 1]" — [N results, key findings]
- "[query 2]" — [N results, key findings]
"#;

pub const STRATEGY_ANALYZER_WEB: &str = r"
## Strategy

### Step 1: Analyze Query
- Break request into key search terms and concepts
- Identify types of sources likely to have answers
- Plan multiple search angles for comprehensive coverage

### Step 2: Execute Strategic Searches
- Start with 2-3 well-crafted searches
- Use specific technical terms and site operators
- Refine based on initial results

### Step 3: Fetch and Analyze Content
- Use web_fetch to retrieve full content from promising results
- Prioritize official documentation and authoritative sources
- Extract specific quotes and relevant sections
- Note publication dates to ensure currency

### Step 4: Synthesize Findings
- Organize information by relevance and authority
- Include exact quotes with proper attribution
- Highlight conflicting information or version-specific details
- Note any gaps in available information

### Quality Guidelines
- **Accuracy**: Quote sources accurately, provide direct links
- **Relevance**: Focus on information that directly addresses the query
- **Currency**: Note publication dates and version information
- **Authority**: Prioritize official sources and recognized experts
";

pub const TEMPLATE_ANALYZER_WEB: &str = r"
## Output Format

## Summary
[Brief overview of key findings]

## Detailed Findings

### [Topic/Source 1]
**Source**: [Name with URL]
**Relevance**: [Why this source is authoritative/useful]
**Key Information**:
- [Direct quote or finding with link to specific section]
- [Another relevant point]

### [Topic/Source 2]
[Continue pattern...]

## Additional Resources
- [Relevant link 1](URL) — Brief description
- [Relevant link 2](URL) — Brief description

## Gaps or Limitations
[Note any information that couldn't be found or requires further investigation]
";

// =============================================================================
// Composition
// =============================================================================

/// Compose final system prompt: base + overlay + strategy + template + guardrails + citations.
pub fn compose_prompt_impl(agent_type: AgentType, location: AgentLocation) -> String {
    let base = match agent_type {
        AgentType::Analyzer => ANALYZER_BASE_PROMPT,
        AgentType::Locator => LOCATOR_BASE_PROMPT,
    };
    let overlay = match location {
        AgentLocation::Codebase => CODEBASE_OVERLAY,
        AgentLocation::Thoughts => THOUGHTS_OVERLAY,
        AgentLocation::References => REFERENCES_OVERLAY,
        AgentLocation::Web => WEB_OVERLAY,
    };
    let strategy = match (agent_type, location) {
        (AgentType::Locator, AgentLocation::Codebase) => STRATEGY_LOCATOR_CODEBASE,
        (AgentType::Locator, AgentLocation::Thoughts) => STRATEGY_LOCATOR_THOUGHTS,
        (AgentType::Locator, AgentLocation::References) => STRATEGY_LOCATOR_REFERENCES,
        (AgentType::Locator, AgentLocation::Web) => STRATEGY_LOCATOR_WEB,
        (AgentType::Analyzer, AgentLocation::Codebase) => STRATEGY_ANALYZER_CODEBASE,
        (AgentType::Analyzer, AgentLocation::Thoughts) => STRATEGY_ANALYZER_THOUGHTS,
        (AgentType::Analyzer, AgentLocation::References) => STRATEGY_ANALYZER_REFERENCES,
        (AgentType::Analyzer, AgentLocation::Web) => STRATEGY_ANALYZER_WEB,
    };
    let template = match (agent_type, location) {
        (AgentType::Locator, AgentLocation::Codebase) => TEMPLATE_LOCATOR_CODEBASE,
        (AgentType::Locator, AgentLocation::Thoughts) => TEMPLATE_LOCATOR_THOUGHTS,
        (AgentType::Locator, AgentLocation::References) => TEMPLATE_LOCATOR_REFERENCES,
        (AgentType::Locator, AgentLocation::Web) => TEMPLATE_LOCATOR_WEB,
        (AgentType::Analyzer, AgentLocation::Codebase) => TEMPLATE_ANALYZER_CODEBASE,
        (AgentType::Analyzer, AgentLocation::Thoughts) => TEMPLATE_ANALYZER_THOUGHTS,
        (AgentType::Analyzer, AgentLocation::References) => TEMPLATE_ANALYZER_REFERENCES,
        (AgentType::Analyzer, AgentLocation::Web) => TEMPLATE_ANALYZER_WEB,
    };

    let mut parts = vec![base, overlay, strategy, template, GUARDRAILS_SHARED];
    if matches!(agent_type, AgentType::Analyzer) {
        parts.push(CITATIONS_ANALYZER);
        if matches!(location, AgentLocation::Thoughts) {
            parts.push(QUALITY_FILTERS_ANALYZER_THOUGHTS);
        }
    }
    parts.join("\n\n")
}

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

    #[test]
    fn test_locator_base_prompt_content() {
        assert!(LOCATOR_BASE_PROMPT.len() > 50);
        assert!(LOCATOR_BASE_PROMPT.contains("finding WHERE"));
    }

    #[test]
    fn test_analyzer_base_prompt_content() {
        assert!(ANALYZER_BASE_PROMPT.len() > 50);
        assert!(ANALYZER_BASE_PROMPT.contains("understanding HOW"));
    }

    #[test]
    fn test_compose_prompt_locator() {
        let prompt = compose_prompt_impl(AgentType::Locator, AgentLocation::Codebase);
        assert!(prompt.contains(LOCATOR_BASE_PROMPT.trim()));
        assert!(prompt.contains("Local codebase"));
    }

    #[test]
    fn test_compose_prompt_analyzer() {
        let prompt = compose_prompt_impl(AgentType::Analyzer, AgentLocation::Web);
        assert!(prompt.contains(ANALYZER_BASE_PROMPT.trim()));
        assert!(prompt.contains("web_fetch"));
    }

    #[test]
    fn test_overlays_do_not_list_tools_by_type() {
        // Overlays should not redundantly list tools; tool exposure comes from schema
        assert!(!CODEBASE_OVERLAY.contains("Tools to use by type"));
        assert!(!THOUGHTS_OVERLAY.contains("Tools to use by type"));
        assert!(!REFERENCES_OVERLAY.contains("Tools to use by type"));
        assert!(!WEB_OVERLAY.contains("Tools to use by type"));

        // Still provide contextual guidance
        assert!(CODEBASE_OVERLAY.contains("Context: Local codebase"));
        assert!(THOUGHTS_OVERLAY.contains("Context: Thought documents"));
        assert!(REFERENCES_OVERLAY.contains("Context: Reference repositories"));
        assert!(WEB_OVERLAY.contains("Context: The web"));
    }

    #[test]
    fn test_shared_sections_use_capability_based_language() {
        assert!(!LOCATOR_BASE_PROMPT.contains("cli_grep/cli_glob/cli_ls/web_search"));
        assert!(!THOUGHTS_OVERLAY.contains("thoughts_list_documents"));
        assert!(!THOUGHTS_OVERLAY.contains("Read within the base"));
        assert!(!REFERENCES_OVERLAY.contains("thoughts_list_references"));
        assert!(!REFERENCES_OVERLAY.contains("cli_grep pattern"));
        assert!(!REFERENCES_OVERLAY.contains("Read file_path"));
        assert!(!REFERENCES_OVERLAY.contains("Read `references/"));

        assert!(LOCATOR_BASE_PROMPT.contains("available discovery tools"));
        assert!(THOUGHTS_OVERLAY.contains("read documents only when a read tool is available"));
        assert!(REFERENCES_OVERLAY.contains("Reference listings return entries"));
        assert!(REFERENCES_OVERLAY.contains("Locate `references/dtolnay/thiserror/README.md`"));
    }

    #[test]
    fn test_compose_prompt_includes_sections() {
        use AgentLocation::*;
        use AgentType::*;
        let cases = [
            (Locator, Codebase),
            (Locator, Thoughts),
            (Locator, References),
            (Locator, Web),
            (Analyzer, Codebase),
            (Analyzer, Thoughts),
            (Analyzer, References),
            (Analyzer, Web),
        ];
        for (t, l) in cases {
            let prompt = compose_prompt_impl(t, l);
            assert!(
                prompt.contains("Strategy"),
                "Missing Strategy for {t:?}×{l:?}"
            );
            assert!(
                prompt.contains("Output Format"),
                "Missing Output Format for {t:?}×{l:?}"
            );
            assert!(
                prompt.contains("Guardrails"),
                "Missing Guardrails for {t:?}×{l:?}"
            );
            if matches!(t, Analyzer) {
                assert!(
                    prompt.contains("Citations"),
                    "Missing Citations for Analyzer×{l:?}"
                );
            }
        }
    }

    #[test]
    fn test_thoughts_analyzer_has_quality_filters() {
        let prompt = compose_prompt_impl(AgentType::Analyzer, AgentLocation::Thoughts);
        assert!(prompt.contains("Quality Filters"));
        assert!(prompt.contains("Include Only If"));
        assert!(prompt.contains("Exclude If"));
    }

    #[test]
    fn test_citation_guidance_varies_by_location() {
        use AgentLocation::*;
        use AgentType::Analyzer;

        let web = compose_prompt_impl(Analyzer, Web);
        assert!(
            web.contains("Direct URL"),
            "Web Analyzer should mention Direct URL citation format"
        );

        let refs = compose_prompt_impl(Analyzer, References);
        assert!(
            refs.contains("references/"),
            "References Analyzer should mention references/ path format"
        );
        assert!(
            refs.contains("org/repo"),
            "References Analyzer should mention org/repo path format"
        );

        let code = compose_prompt_impl(Analyzer, Codebase);
        assert!(
            code.contains("path") && code.contains("line"),
            "Codebase Analyzer should mention file:line citation format"
        );
    }

    #[test]
    fn test_prompt_length_thresholds() {
        use AgentLocation::*;
        use AgentType::*;
        let cases = [
            (Locator, Codebase),
            (Locator, Thoughts),
            (Locator, References),
            (Locator, Web),
            (Analyzer, Codebase),
            (Analyzer, Thoughts),
            (Analyzer, References),
            (Analyzer, Web),
        ];
        for (t, l) in cases {
            let prompt = compose_prompt_impl(t, l);
            assert!(
                prompt.len() > 800,
                "Prompt too short for {:?}×{:?}: {} chars",
                t,
                l,
                prompt.len()
            );
        }
    }
}