a3s-code-core 5.2.7

A3S Code Core - Embeddable AI agent library with tool execution
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
use super::*;

#[test]
fn test_all_prompts_loaded() {
    // Verify all prompts are non-empty at compile time
    assert!(!SYSTEM_DEFAULT.is_empty());
    assert!(!CONTINUATION.is_empty());
    assert!(!BOUNDARIES.is_empty());
    assert!(!AGENT_EXPLORE.is_empty());
    assert!(!AGENT_PLAN.is_empty());
    assert!(!AGENT_CODE_REVIEW.is_empty());
    assert!(!CONTEXT_COMPACT.is_empty());
    assert!(!LLM_PLAN_SYSTEM.is_empty());
    assert!(!LLM_GOAL_EXTRACT_SYSTEM.is_empty());
    assert!(!LLM_GOAL_CHECK_SYSTEM.is_empty());
    assert!(!SKILLS_CATALOG_HEADER.is_empty());
    assert!(!PLAN_EXECUTE_GOAL.is_empty());
    assert!(!PLAN_EXECUTE_STEP.is_empty());
    assert!(!PLAN_FALLBACK_STEP.is_empty());
}

#[test]
fn test_render_template() {
    let result = render(
        PLAN_EXECUTE_GOAL,
        &[("goal", "Build app"), ("steps", "1. Init")],
    );
    assert!(result.contains("Build app"));
    assert!(!result.contains("{goal}"));
}

#[test]
fn test_render_multiple_placeholders() {
    let template = "Goal: {goal}\nCriteria: {criteria}\nState: {current_state}";
    let result = render(
        template,
        &[
            ("goal", "Build a REST API"),
            ("criteria", "- Endpoint works\n- Tests pass"),
            ("current_state", "API is deployed"),
        ],
    );
    assert!(result.contains("Build a REST API"));
    assert!(result.contains("Endpoint works"));
    assert!(result.contains("API is deployed"));
}

#[test]
fn test_delegated_agent_prompts_contain_guidelines() {
    assert!(AGENT_EXPLORE.contains("Guidelines"));
    assert!(AGENT_EXPLORE.contains("read-only"));
    assert!(AGENT_PLAN.contains("Guidelines"));
    assert!(AGENT_PLAN.contains("read-only"));
}

#[test]
fn test_context_summary_prefix() {
    assert!(CONTEXT_SUMMARY_PREFIX.contains("Context Summary"));
}

// ── SystemPromptSlots tests ──

#[test]
fn test_slots_default_builds_system_default() {
    let slots = SystemPromptSlots::default();
    let built = slots.build();
    assert!(built.contains("Core Behaviour"));
    assert!(built.contains("Tool Usage Strategy"));
    assert!(built.contains("Completion Criteria"));
    assert!(built.contains("Response Format"));
    assert!(built.contains("A3S Code"));
    // Safety boundaries are injected even though they no longer live inline
    // in system_default.md.
    assert!(built.contains("## Boundaries"));
    assert!(built.contains("untrusted data"));
}

#[test]
fn test_boundaries_injected_for_every_style() {
    for style in [
        AgentStyle::GeneralPurpose,
        AgentStyle::Plan,
        AgentStyle::Verification,
        AgentStyle::Explore,
        AgentStyle::CodeReview,
    ] {
        let built = SystemPromptSlots::default().with_style(style).build();
        assert!(
            built.contains("## Boundaries"),
            "style {style:?} missing Boundaries section"
        );
    }
}

#[test]
fn test_boundaries_not_duplicated_in_general_purpose() {
    // system_default.md must NOT carry an inline copy (single source of truth
    // is boundaries.md, injected by build_with_style).
    assert!(!SYSTEM_DEFAULT.contains("## Boundaries"));
    let built = SystemPromptSlots::default().build();
    assert_eq!(built.matches("## Boundaries").count(), 1);
}

#[test]
fn test_slots_custom_role_replaces_default() {
    let slots = SystemPromptSlots {
        role: Some("You are a senior Python developer".to_string()),
        ..Default::default()
    };
    let built = slots.build();
    assert!(built.contains("You are a senior Python developer"));
    assert!(!built.contains("You are A3S Code"));
    // Core sections still present
    assert!(built.contains("Core Behaviour"));
    assert!(built.contains("Tool Usage Strategy"));
}

#[test]
fn test_slots_custom_guidelines_appended() {
    let slots = SystemPromptSlots {
        guidelines: Some("Always use type hints. Follow PEP 8.".to_string()),
        ..Default::default()
    };
    let built = slots.build();
    assert!(built.contains("## Guidelines"));
    assert!(built.contains("Always use type hints"));
    assert!(built.contains("Core Behaviour"));
}

#[test]
fn test_slots_custom_response_style_replaces_default() {
    let slots = SystemPromptSlots {
        response_style: Some("Be concise. Use bullet points.".to_string()),
        ..Default::default()
    };
    let built = slots.build();
    assert!(built.contains("Be concise. Use bullet points."));
    // Default response format content should be gone
    assert!(!built.contains("keep progress notes brief and useful"));
    // But core is still there
    assert!(built.contains("Core Behaviour"));
}

#[test]
fn test_slots_extra_appended() {
    let slots = SystemPromptSlots {
        extra: Some("Remember: always write tests first.".to_string()),
        ..Default::default()
    };
    let built = slots.build();
    assert!(built.contains("Remember: always write tests first."));
    assert!(built.contains("Core Behaviour"));
}

#[test]
fn test_slots_with_extra() {
    let slots = SystemPromptSlots::default().with_extra("You are a helpful assistant.");
    let built = slots.build();
    assert!(built.contains("You are a helpful assistant."));
    assert!(built.contains("Core Behaviour"));
    assert!(built.contains("Tool Usage Strategy"));
}

#[test]
fn test_slots_all_slots_combined() {
    let slots = SystemPromptSlots {
        style: None,
        role: Some("You are a Rust expert".to_string()),
        guidelines: Some("Use clippy. No unwrap.".to_string()),
        response_style: Some("Short answers only.".to_string()),
        extra: Some("Project uses tokio.".to_string()),
    };
    let built = slots.build();
    assert!(built.contains("You are a Rust expert"));
    assert!(built.contains("Core Behaviour"));
    assert!(built.contains("## Guidelines"));
    assert!(built.contains("Use clippy"));
    assert!(built.contains("Short answers only"));
    assert!(built.contains("Project uses tokio"));
    // Default response format replaced
    assert!(!built.contains("keep progress notes brief and useful"));
}

#[test]
fn test_slots_is_empty() {
    assert!(SystemPromptSlots::default().is_empty());
    assert!(!SystemPromptSlots {
        role: Some("test".to_string()),
        ..Default::default()
    }
    .is_empty());
    assert!(!SystemPromptSlots {
        style: Some(AgentStyle::Plan),
        ..Default::default()
    }
    .is_empty());
}

// ── AgentStyle tests ──

#[test]
fn test_agent_style_default_is_general_purpose() {
    assert_eq!(AgentStyle::default(), AgentStyle::GeneralPurpose);
}

#[test]
fn test_agent_style_base_prompt() {
    assert_eq!(AgentStyle::GeneralPurpose.base_prompt(), SYSTEM_DEFAULT);
    assert_eq!(AgentStyle::Plan.base_prompt(), AGENT_PLAN);
    assert_eq!(AgentStyle::Explore.base_prompt(), AGENT_EXPLORE);
    assert_eq!(AgentStyle::Verification.base_prompt(), AGENT_VERIFICATION);
    assert_eq!(AgentStyle::CodeReview.base_prompt(), AGENT_CODE_REVIEW);
}

#[test]
fn test_agent_style_guidelines() {
    assert!(AgentStyle::GeneralPurpose.guidelines().is_none());
    assert!(AgentStyle::Plan.guidelines().is_none()); // embedded in prompt
    assert!(AgentStyle::Explore.guidelines().is_none());
    assert!(AgentStyle::Verification.guidelines().is_none());
    assert!(AgentStyle::CodeReview.guidelines().is_none());
}

#[test]
fn test_agent_style_builtin_agent_name_mapping() {
    assert_eq!(AgentStyle::GeneralPurpose.builtin_agent_name(), "general");
    assert_eq!(AgentStyle::Plan.builtin_agent_name(), "plan");
    assert_eq!(AgentStyle::Explore.builtin_agent_name(), "explore");
    assert_eq!(
        AgentStyle::Verification.builtin_agent_name(),
        "verification"
    );
    assert_eq!(AgentStyle::CodeReview.builtin_agent_name(), "review");
}

#[test]
fn test_agent_style_runtime_mode_mapping() {
    assert_eq!(AgentStyle::GeneralPurpose.runtime_mode(), "general");
    assert_eq!(AgentStyle::Plan.runtime_mode(), "planning");
    assert_eq!(AgentStyle::Explore.runtime_mode(), "explore");
    assert_eq!(AgentStyle::Verification.runtime_mode(), "verification");
    assert_eq!(AgentStyle::CodeReview.runtime_mode(), "code_review");
}

#[test]
fn test_agent_style_detect_plan() {
    assert_eq!(
        AgentStyle::detect_from_message("Help me plan a new feature"),
        AgentStyle::Plan
    );
    assert_eq!(
        AgentStyle::detect_from_message("Design the architecture for this"),
        AgentStyle::Plan
    );
    assert_eq!(
        AgentStyle::detect_from_message("What's the implementation approach?"),
        AgentStyle::Plan
    );
}

#[test]
fn test_agent_style_detect_verification() {
    assert_eq!(
        AgentStyle::detect_from_message("Verify that this works correctly"),
        AgentStyle::Verification
    );
    assert_eq!(
        AgentStyle::detect_from_message("Test the login flow"),
        AgentStyle::Verification
    );
    assert_eq!(
        AgentStyle::detect_from_message("Check if the API handles edge cases"),
        AgentStyle::Verification
    );
}

#[test]
fn test_agent_style_detect_explore() {
    assert_eq!(
        AgentStyle::detect_from_message("Find all files related to auth"),
        AgentStyle::Explore
    );
    assert_eq!(
        AgentStyle::detect_from_message("Where is the user model defined?"),
        AgentStyle::Explore
    );
    assert_eq!(
        AgentStyle::detect_from_message("Search for password hashing code"),
        AgentStyle::Explore
    );
}

#[test]
fn test_agent_style_detect_code_review() {
    assert_eq!(
        AgentStyle::detect_from_message("Review the PR changes"),
        AgentStyle::CodeReview
    );
    assert_eq!(
        AgentStyle::detect_from_message("Analyze this code for best practices"),
        AgentStyle::CodeReview
    );
    assert_eq!(
        AgentStyle::detect_from_message("Assess code quality"),
        AgentStyle::CodeReview
    );
}

#[test]
fn test_agent_style_detect_default_is_general_purpose() {
    // "Implement" was removed from Plan keywords as too generic
    assert_eq!(
        AgentStyle::detect_from_message("Implement the new feature"),
        AgentStyle::GeneralPurpose
    );
    // "Write tests" contains "test" so it's detected as Verification
    assert_eq!(
        AgentStyle::detect_from_message("Write code for the API"),
        AgentStyle::GeneralPurpose
    );
}

#[test]
fn test_build_with_message_auto_detects_style() {
    let slots = SystemPromptSlots::default();
    let built = slots.build_with_message("Help me plan a new feature");
    // Should use Plan style
    assert!(built.contains("planning agent") || built.contains("READ-ONLY"));
}

#[test]
fn test_build_with_message_explicit_style_overrides() {
    let slots = SystemPromptSlots {
        style: Some(AgentStyle::Verification),
        ..Default::default()
    };
    let built = slots.build_with_message("Help me plan a new feature");
    // Should use Verification style, not Plan
    assert!(built.contains("adversarial verification specialist"));
}

#[test]
fn test_build_with_message_plan_style() {
    let slots = SystemPromptSlots::default();
    let built = slots.build_with_message("Design the system architecture");
    assert!(built.contains("planning agent") || built.contains("READ-ONLY"));
}

#[test]
fn test_build_with_message_explore_style() {
    let slots = SystemPromptSlots::default();
    let built = slots.build_with_message("Find all authentication files");
    assert!(built.contains("exploration agent") || built.contains("explore"));
}

#[test]
fn test_build_with_message_code_review_style() {
    let slots = SystemPromptSlots::default();
    let built = slots.build_with_message("Review this code");
    assert!(built.contains("code review agent"));
    assert!(built.contains("regressions"));
}

#[test]
fn test_builder_methods() {
    let slots = SystemPromptSlots::default()
        .with_style(AgentStyle::Plan)
        .with_role("You are a Python expert")
        .with_guidelines("Use type hints")
        .with_response_style("Be brief")
        .with_extra("Additional instructions");

    assert_eq!(slots.style, Some(AgentStyle::Plan));
    assert_eq!(slots.role, Some("You are a Python expert".to_string()));
    assert_eq!(slots.guidelines, Some("Use type hints".to_string()));
    assert_eq!(slots.response_style, Some("Be brief".to_string()));
    assert_eq!(slots.extra, Some("Additional instructions".to_string()));

    let built = slots.build();
    assert!(built.contains("Python expert"));
    assert!(built.contains("Use type hints"));
    assert!(built.contains("Be brief"));
    assert!(built.contains("Additional instructions"));
}

#[test]
fn test_code_review_guidelines_appended() {
    let slots = SystemPromptSlots {
        style: Some(AgentStyle::CodeReview),
        ..Default::default()
    };
    let built = slots.build();
    assert!(built.contains("code review agent"));
    assert!(built.contains("correctness"));
    assert!(built.contains("regressions"));
    assert!(built.contains("security"));
}

#[test]
fn test_prompts_do_not_reference_removed_surfaces() {
    let prompts = [
        SYSTEM_DEFAULT,
        AGENT_VERIFICATION,
        PRE_ANALYSIS_SYSTEM,
        AGENT_EXPLORE,
        AGENT_PLAN,
        AGENT_CODE_REVIEW,
        SKILLS_CATALOG_HEADER,
        CONTINUATION,
    ]
    .join("\n")
    .to_lowercase();

    for removed in [
        "orchestrator",
        "plugin",
        "agentic_search",
        "agentic_parse",
        "agentic-search",
        "agentic-parse",
        "manage_skill",
        "claude.md",
    ] {
        assert!(
            !prompts.contains(removed),
            "prompt still references removed surface: {removed}"
        );
    }

    assert!(SYSTEM_DEFAULT.contains("program"));
    assert!(SYSTEM_DEFAULT.contains("task"));
    assert!(SYSTEM_DEFAULT.contains("parallel_task"));
}