1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub struct StdlibSource {
9 pub module: &'static str,
10 pub source: &'static str,
11}
12
13#[derive(Debug, Clone, Copy, PartialEq, Eq)]
14pub struct StdlibPromptAsset {
15 pub path: &'static str,
16 pub source: &'static str,
17}
18
19#[derive(Debug, Clone, PartialEq, Eq)]
20pub struct StdlibPublicFunction {
21 pub name: String,
22 pub signature: String,
23 pub required_params: usize,
24 pub total_params: usize,
25 pub variadic: bool,
26 pub doc: Option<String>,
27}
28
29#[derive(Debug, Clone, PartialEq, Eq)]
30pub struct StdlibEntrypointModule {
31 pub import_path: String,
32 pub category: String,
33}
34
35pub const STDLIB_SOURCES: &[StdlibSource] = &[
36 StdlibSource {
37 module: "text",
38 source: include_str!("stdlib/stdlib_text.harn"),
39 },
40 StdlibSource {
41 module: "collections",
42 source: include_str!("stdlib/stdlib_collections.harn"),
43 },
44 StdlibSource {
45 module: "math",
46 source: include_str!("stdlib/stdlib_math.harn"),
47 },
48 StdlibSource {
49 module: "path",
50 source: include_str!("stdlib/stdlib_path.harn"),
51 },
52 StdlibSource {
53 module: "json",
54 source: include_str!("stdlib/stdlib_json.harn"),
55 },
56 StdlibSource {
57 module: "cache",
58 source: include_str!("stdlib/stdlib_cache.harn"),
59 },
60 StdlibSource {
61 module: "tools",
62 source: include_str!("stdlib/stdlib_tools.harn"),
63 },
64 StdlibSource {
65 module: "graphql",
66 source: include_str!("stdlib/stdlib_graphql.harn"),
67 },
68 StdlibSource {
69 module: "schema",
70 source: include_str!("stdlib/stdlib_schema.harn"),
71 },
72 StdlibSource {
73 module: "testing",
74 source: include_str!("stdlib/stdlib_testing.harn"),
75 },
76 StdlibSource {
77 module: "files",
78 source: include_str!("stdlib/stdlib_files.harn"),
79 },
80 StdlibSource {
81 module: "vision",
82 source: include_str!("stdlib/stdlib_vision.harn"),
83 },
84 StdlibSource {
85 module: "context",
86 source: include_str!("stdlib/stdlib_context.harn"),
87 },
88 StdlibSource {
89 module: "runtime",
90 source: include_str!("stdlib/stdlib_runtime.harn"),
91 },
92 StdlibSource {
93 module: "command",
94 source: include_str!("stdlib/stdlib_command.harn"),
95 },
96 StdlibSource {
97 module: "review",
98 source: include_str!("stdlib/stdlib_review.harn"),
99 },
100 StdlibSource {
101 module: "experiments",
102 source: include_str!("stdlib/stdlib_experiments.harn"),
103 },
104 StdlibSource {
105 module: "project",
106 source: include_str!("stdlib/stdlib_project.harn"),
107 },
108 StdlibSource {
109 module: "prompt_library",
110 source: include_str!("stdlib/stdlib_prompt_library.harn"),
111 },
112 StdlibSource {
113 module: "async",
114 source: include_str!("stdlib/stdlib_async.harn"),
115 },
116 StdlibSource {
117 module: "agents",
118 source: include_str!("stdlib/stdlib_agents.harn"),
119 },
120 StdlibSource {
121 module: "agent/prompts",
122 source: include_str!("stdlib/agent/prompts.harn"),
123 },
124 StdlibSource {
125 module: "llm/media",
126 source: include_str!("stdlib/llm/media.harn"),
127 },
128 StdlibSource {
129 module: "llm/handlers",
130 source: include_str!("stdlib/llm/handlers.harn"),
131 },
132 StdlibSource {
133 module: "llm/ensemble",
134 source: include_str!("stdlib/llm/ensemble.harn"),
135 },
136 StdlibSource {
137 module: "llm/rerank",
138 source: include_str!("stdlib/llm/rerank.harn"),
139 },
140 StdlibSource {
141 module: "agent/options",
142 source: include_str!("stdlib/agent/options.harn"),
143 },
144 StdlibSource {
145 module: "llm/judge",
146 source: include_str!("stdlib/llm/judge.harn"),
147 },
148 StdlibSource {
149 module: "llm/refine",
150 source: include_str!("stdlib/llm/refine.harn"),
151 },
152 StdlibSource {
153 module: "llm/optimize",
154 source: include_str!("stdlib/llm/optimize.harn"),
155 },
156 StdlibSource {
157 module: "agent/events",
158 source: include_str!("stdlib/agent/events.harn"),
159 },
160 StdlibSource {
161 module: "agent/primitives",
162 source: include_str!("stdlib/agent/primitives.harn"),
163 },
164 StdlibSource {
165 module: "agent/loop",
166 source: include_str!("stdlib/agent/loop.harn"),
167 },
168 StdlibSource {
169 module: "agent/tool_search",
170 source: include_str!("stdlib/agent/tool_search.harn"),
171 },
172 StdlibSource {
173 module: "agent/turn",
174 source: include_str!("stdlib/agent/turn.harn"),
175 },
176 StdlibSource {
177 module: "agent/workers",
178 source: include_str!("stdlib/agent/workers.harn"),
179 },
180 StdlibSource {
181 module: "agent/state",
182 source: include_str!("stdlib/agent/state.harn"),
183 },
184 StdlibSource {
185 module: "agent/skills",
186 source: include_str!("stdlib/agent/skills.harn"),
187 },
188 StdlibSource {
189 module: "agent/autocompact",
190 source: include_str!("stdlib/agent/autocompact.harn"),
191 },
192 StdlibSource {
193 module: "agent/mcp",
194 source: include_str!("stdlib/agent/mcp.harn"),
195 },
196 StdlibSource {
197 module: "agent/host_tools",
198 source: include_str!("stdlib/agent/host_tools.harn"),
199 },
200 StdlibSource {
201 module: "agent/budget",
202 source: include_str!("stdlib/agent/budget.harn"),
203 },
204 StdlibSource {
205 module: "agent/daemon",
206 source: include_str!("stdlib/agent/daemon.harn"),
207 },
208 StdlibSource {
209 module: "agent/preflight",
210 source: include_str!("stdlib/agent/preflight.harn"),
211 },
212 StdlibSource {
213 module: "agent/postturn",
214 source: include_str!("stdlib/agent/postturn.harn"),
215 },
216 StdlibSource {
217 module: "agent/judge",
218 source: include_str!("stdlib/agent/judge.harn"),
219 },
220 StdlibSource {
221 module: "agent/presets",
222 source: include_str!("stdlib/agent/presets.harn"),
223 },
224 StdlibSource {
225 module: "agent_state",
226 source: include_str!("stdlib/stdlib_agent_state.harn"),
227 },
228 StdlibSource {
229 module: "memory",
230 source: include_str!("stdlib/stdlib_memory.harn"),
231 },
232 StdlibSource {
233 module: "postgres",
234 source: include_str!("stdlib/stdlib_postgres.harn"),
235 },
236 StdlibSource {
237 module: "checkpoint",
238 source: include_str!("stdlib/stdlib_checkpoint.harn"),
239 },
240 StdlibSource {
241 module: "host",
242 source: include_str!("stdlib/stdlib_host.harn"),
243 },
244 StdlibSource {
245 module: "git",
246 source: include_str!("stdlib/stdlib_git.harn"),
247 },
248 StdlibSource {
249 module: "hitl",
250 source: include_str!("stdlib/stdlib_hitl.harn"),
251 },
252 StdlibSource {
253 module: "trust",
254 source: include_str!("stdlib/stdlib_trust.harn"),
255 },
256 StdlibSource {
257 module: "corrections",
258 source: include_str!("stdlib/stdlib_corrections.harn"),
259 },
260 StdlibSource {
261 module: "plan",
262 source: include_str!("stdlib/stdlib_plan.harn"),
263 },
264 StdlibSource {
265 module: "waitpoints",
266 source: include_str!("stdlib/stdlib_waitpoints.harn"),
267 },
268 StdlibSource {
269 module: "waitpoint",
270 source: include_str!("stdlib/stdlib_waitpoint.harn"),
271 },
272 StdlibSource {
273 module: "monitors",
274 source: include_str!("stdlib/stdlib_monitors.harn"),
275 },
276 StdlibSource {
277 module: "worktree",
278 source: include_str!("stdlib/stdlib_worktree.harn"),
279 },
280 StdlibSource {
281 module: "acp",
282 source: include_str!("stdlib/stdlib_acp.harn"),
283 },
284 StdlibSource {
285 module: "triggers",
286 source: include_str!("stdlib/stdlib_triggers.harn"),
287 },
288 StdlibSource {
289 module: "handoffs",
290 source: include_str!("stdlib/stdlib_handoffs.harn"),
291 },
292 StdlibSource {
293 module: "personas/prelude",
294 source: include_str!("stdlib/stdlib_personas_prelude.harn"),
295 },
296 StdlibSource {
297 module: "connectors/shared",
298 source: include_str!("stdlib/stdlib_connectors_shared.harn"),
299 },
300 StdlibSource {
301 module: "connectors/github",
302 source: include_str!("stdlib/stdlib_connectors_github.harn"),
303 },
304 StdlibSource {
305 module: "connectors/linear",
306 source: include_str!("stdlib/stdlib_connectors_linear.harn"),
307 },
308 StdlibSource {
309 module: "connectors/notion",
310 source: include_str!("stdlib/stdlib_connectors_notion.harn"),
311 },
312 StdlibSource {
313 module: "connectors/slack",
314 source: include_str!("stdlib/stdlib_connectors_slack.harn"),
315 },
316 StdlibSource {
317 module: "workflow/prompts",
318 source: include_str!("stdlib/workflow/prompts.harn"),
319 },
320 StdlibSource {
321 module: "workflow/context",
322 source: include_str!("stdlib/workflow/context.harn"),
323 },
324 StdlibSource {
325 module: "workflow/options",
326 source: include_str!("stdlib/workflow/options.harn"),
327 },
328 StdlibSource {
329 module: "workflow/checkpoints",
330 source: include_str!("stdlib/workflow/checkpoints.harn"),
331 },
332 StdlibSource {
333 module: "workflow/stage",
334 source: include_str!("stdlib/workflow/stage.harn"),
335 },
336 StdlibSource {
337 module: "workflow/map",
338 source: include_str!("stdlib/workflow/map.harn"),
339 },
340 StdlibSource {
341 module: "workflow/schedule",
342 source: include_str!("stdlib/workflow/schedule.harn"),
343 },
344 StdlibSource {
345 module: "workflow/execute",
346 source: include_str!("stdlib/workflow/execute.harn"),
347 },
348];
349
350pub const STDLIB_PROMPT_ASSETS: &[StdlibPromptAsset] = &[
351 StdlibPromptAsset {
352 path: "agent/prompts/tool_contract_text.harn.prompt",
353 source: include_str!("stdlib/agent/prompts/tool_contract_text.harn.prompt"),
354 },
355 StdlibPromptAsset {
356 path: "agent/prompts/tool_contract_native.harn.prompt",
357 source: include_str!("stdlib/agent/prompts/tool_contract_native.harn.prompt"),
358 },
359 StdlibPromptAsset {
360 path: "agent/prompts/tool_contract_text_response_protocol.harn.prompt",
361 source: include_str!(
362 "stdlib/agent/prompts/tool_contract_text_response_protocol.harn.prompt"
363 ),
364 },
365 StdlibPromptAsset {
366 path: "agent/prompts/tool_contract_action_native.harn.prompt",
367 source: include_str!("stdlib/agent/prompts/tool_contract_action_native.harn.prompt"),
368 },
369 StdlibPromptAsset {
370 path: "agent/prompts/tool_contract_action_text.harn.prompt",
371 source: include_str!("stdlib/agent/prompts/tool_contract_action_text.harn.prompt"),
372 },
373 StdlibPromptAsset {
374 path: "agent/prompts/tool_contract_task_ledger.harn.prompt",
375 source: include_str!("stdlib/agent/prompts/tool_contract_task_ledger.harn.prompt"),
376 },
377 StdlibPromptAsset {
378 path: "agent/prompts/tool_contract_deferred_tools.harn.prompt",
379 source: include_str!("stdlib/agent/prompts/tool_contract_deferred_tools.harn.prompt"),
380 },
381 StdlibPromptAsset {
382 path: "agent/prompts/deferred_tool_listing.harn.prompt",
383 source: include_str!("stdlib/agent/prompts/deferred_tool_listing.harn.prompt"),
384 },
385 StdlibPromptAsset {
386 path: "agent/prompts/action_turn_nudge.harn.prompt",
387 source: include_str!("stdlib/agent/prompts/action_turn_nudge.harn.prompt"),
388 },
389 StdlibPromptAsset {
390 path: "agent/prompts/agent_turn_preamble.harn.prompt",
391 source: include_str!("stdlib/agent/prompts/agent_turn_preamble.harn.prompt"),
392 },
393 StdlibPromptAsset {
394 path: "agent/prompts/default_nudge.harn.prompt",
395 source: include_str!("stdlib/agent/prompts/default_nudge.harn.prompt"),
396 },
397 StdlibPromptAsset {
398 path: "agent/prompts/loop_until_done_system.harn.prompt",
399 source: include_str!("stdlib/agent/prompts/loop_until_done_system.harn.prompt"),
400 },
401 StdlibPromptAsset {
402 path: "agent/prompts/completion_judge_default.harn.prompt",
403 source: include_str!("stdlib/agent/prompts/completion_judge_default.harn.prompt"),
404 },
405 StdlibPromptAsset {
406 path: "agent/prompts/completion_judge_feedback_fallback.harn.prompt",
407 source: include_str!("stdlib/agent/prompts/completion_judge_feedback_fallback.harn.prompt"),
408 },
409 StdlibPromptAsset {
410 path: "agent/prompts/completion_judge_user.harn.prompt",
411 source: include_str!("stdlib/agent/prompts/completion_judge_user.harn.prompt"),
412 },
413 StdlibPromptAsset {
414 path: "agent/prompts/parse_guidance.harn.prompt",
415 source: include_str!("stdlib/agent/prompts/parse_guidance.harn.prompt"),
416 },
417 StdlibPromptAsset {
418 path: "agent/prompts/protocol_violation_feedback.harn.prompt",
419 source: include_str!("stdlib/agent/prompts/protocol_violation_feedback.harn.prompt"),
420 },
421 StdlibPromptAsset {
422 path: "agent/prompts/native_tool_contract_feedback.harn.prompt",
423 source: include_str!("stdlib/agent/prompts/native_tool_contract_feedback.harn.prompt"),
424 },
425 StdlibPromptAsset {
426 path: "agent/prompts/verification_gate_feedback.harn.prompt",
427 source: include_str!("stdlib/agent/prompts/verification_gate_feedback.harn.prompt"),
428 },
429 StdlibPromptAsset {
430 path: "agent/prompts/action_required_feedback.harn.prompt",
431 source: include_str!("stdlib/agent/prompts/action_required_feedback.harn.prompt"),
432 },
433 StdlibPromptAsset {
434 path: "agent/prompts/daemon_watch_feedback.harn.prompt",
435 source: include_str!("stdlib/agent/prompts/daemon_watch_feedback.harn.prompt"),
436 },
437 StdlibPromptAsset {
438 path: "agent/prompts/daemon_timer_feedback.harn.prompt",
439 source: include_str!("stdlib/agent/prompts/daemon_timer_feedback.harn.prompt"),
440 },
441 StdlibPromptAsset {
442 path: "llm/prompts/completion_fallback_system.harn.prompt",
443 source: include_str!("stdlib/llm/prompts/completion_fallback_system.harn.prompt"),
444 },
445 StdlibPromptAsset {
446 path: "llm/prompts/completion_fallback_user.harn.prompt",
447 source: include_str!("stdlib/llm/prompts/completion_fallback_user.harn.prompt"),
448 },
449 StdlibPromptAsset {
450 path: "llm/prompts/transcript_summarize_user.harn.prompt",
451 source: include_str!("stdlib/llm/prompts/transcript_summarize_user.harn.prompt"),
452 },
453 StdlibPromptAsset {
454 path: "llm/prompts/structural_chain_of_draft.harn.prompt",
455 source: include_str!("stdlib/llm/prompts/structural_chain_of_draft.harn.prompt"),
456 },
457 StdlibPromptAsset {
458 path: "llm/prompts/schema_recover_repair.harn.prompt",
459 source: include_str!("stdlib/llm/prompts/schema_recover_repair.harn.prompt"),
460 },
461 StdlibPromptAsset {
462 path: "llm/prompts/structured_envelope_schema_contract.harn.prompt",
463 source: include_str!("stdlib/llm/prompts/structured_envelope_schema_contract.harn.prompt"),
464 },
465 StdlibPromptAsset {
466 path: "llm/prompts/structured_envelope_repair.harn.prompt",
467 source: include_str!("stdlib/llm/prompts/structured_envelope_repair.harn.prompt"),
468 },
469 StdlibPromptAsset {
470 path: "llm/prompts/pairwise_rerank_user.harn.prompt",
471 source: include_str!("stdlib/llm/prompts/pairwise_rerank_user.harn.prompt"),
472 },
473 StdlibPromptAsset {
474 path: "workflow/prompts/stage.harn.prompt",
475 source: include_str!("stdlib/workflow/prompts/stage.harn.prompt"),
476 },
477 StdlibPromptAsset {
478 path: "workflow/prompts/verification_context_intro.harn.prompt",
479 source: include_str!("stdlib/workflow/prompts/verification_context_intro.harn.prompt"),
480 },
481 StdlibPromptAsset {
482 path: "orchestration/prompts/compaction_summary.harn.prompt",
483 source: include_str!("stdlib/orchestration/prompts/compaction_summary.harn.prompt"),
484 },
485];
486
487pub fn get_stdlib_source(module: &str) -> Option<&'static str> {
488 STDLIB_SOURCES
489 .iter()
490 .find_map(|entry| (entry.module == module).then_some(entry.source))
491}
492
493pub fn get_stdlib_prompt_asset(path: &str) -> Option<&'static str> {
494 let path = path.strip_prefix("std/").unwrap_or(path);
495 STDLIB_PROMPT_ASSETS
496 .iter()
497 .find_map(|entry| (entry.path == path).then_some(entry.source))
498}
499
500pub fn public_functions_for_module(module: &str) -> Vec<StdlibPublicFunction> {
501 let Some(source) = get_stdlib_source(module) else {
502 return Vec::new();
503 };
504 public_functions_from_source(source)
505}
506
507pub fn entrypoint_modules() -> Vec<StdlibEntrypointModule> {
508 STDLIB_SOURCES
509 .iter()
510 .filter_map(|entry| {
511 entrypoint_category_from_source(entry.source).map(|category| StdlibEntrypointModule {
512 import_path: format!("std/{}", entry.module),
513 category,
514 })
515 })
516 .collect()
517}
518
519fn entrypoint_category_from_source(source: &str) -> Option<String> {
520 for line in source.lines() {
521 let line = line.trim();
522 if line.is_empty() {
523 continue;
524 }
525 if let Some(category) = line.strip_prefix("// @harn-entrypoint-category ") {
526 let category = category.trim();
527 return (!category.is_empty()).then(|| category.to_string());
528 }
529 if !line.starts_with("//") {
530 return None;
531 }
532 }
533 None
534}
535
536fn public_functions_from_source(source: &str) -> Vec<StdlibPublicFunction> {
537 let mut out = Vec::new();
538 let mut doc: Option<String> = None;
539 let lines = source.lines().collect::<Vec<_>>();
540 let mut index = 0usize;
541 while index < lines.len() {
542 let line = lines[index].trim();
543 if line.starts_with("/**") {
544 let (parsed, next) = parse_harndoc(&lines, index);
545 doc = parsed;
546 index = next;
547 continue;
548 }
549 if let Some(function) = parse_public_function_line(line, doc.take()) {
550 out.push(function);
551 } else if !line.is_empty() && !line.starts_with("//") {
552 doc = None;
553 }
554 index += 1;
555 }
556 out
557}
558
559fn parse_harndoc(lines: &[&str], start: usize) -> (Option<String>, usize) {
560 let mut parts = Vec::new();
561 let mut index = start;
562 while index < lines.len() {
563 let mut line = lines[index].trim();
564 if index == start {
565 line = line.trim_start_matches("/**").trim();
566 }
567 let done = line.ends_with("*/");
568 line = line.trim_end_matches("*/").trim();
569 line = line.trim_start_matches('*').trim();
570 if !line.is_empty() {
571 parts.push(line.to_string());
572 }
573 index += 1;
574 if done {
575 break;
576 }
577 }
578 let text = parts.join("\n").trim().to_string();
579 ((!text.is_empty()).then_some(text), index)
580}
581
582fn parse_public_function_line(line: &str, doc: Option<String>) -> Option<StdlibPublicFunction> {
583 let rest = line.strip_prefix("pub fn ")?.trim();
584 let name_end = rest.find('(')?;
585 let name = rest[..name_end].trim();
586 if name.is_empty() {
587 return None;
588 }
589 let params_start = name_end + 1;
590 let params_len = matching_paren_len(&rest[params_start..])?;
591 let params = &rest[params_start..params_start + params_len];
592 let after = rest[params_start + params_len + 1..].trim();
593 let return_type = after
594 .strip_prefix("->")
595 .and_then(|tail| tail.split('{').next())
596 .map(str::trim)
597 .filter(|value| !value.is_empty());
598 let signature = match return_type {
599 Some(ret) => format!("{name}({params}) -> {ret}"),
600 None => format!("{name}({params})"),
601 };
602 let param_parts = split_top_level_params(params);
603 let total_params = param_parts
604 .iter()
605 .filter(|param| !param.trim().is_empty())
606 .count();
607 let variadic = param_parts
608 .iter()
609 .any(|param| param.trim_start().starts_with("..."));
610 let required_params = param_parts
611 .iter()
612 .filter(|param| {
613 let param = param.trim();
614 !param.is_empty() && !param.contains('=') && !param.starts_with("...")
615 })
616 .count();
617 Some(StdlibPublicFunction {
618 name: name.to_string(),
619 signature,
620 required_params,
621 total_params,
622 variadic,
623 doc,
624 })
625}
626
627fn matching_paren_len(input: &str) -> Option<usize> {
628 let mut depth = 1usize;
629 for (offset, ch) in input.char_indices() {
630 match ch {
631 '(' | '[' | '{' => depth += 1,
632 ')' => {
633 depth = depth.saturating_sub(1);
634 if depth == 0 {
635 return Some(offset);
636 }
637 }
638 ']' | '}' => depth = depth.saturating_sub(1),
639 _ => {}
640 }
641 }
642 None
643}
644
645fn split_top_level_params(params: &str) -> Vec<&str> {
646 let mut out = Vec::new();
647 let mut depth = 0isize;
648 let mut start = 0usize;
649 for (offset, ch) in params.char_indices() {
650 match ch {
651 '(' | '[' | '{' => depth += 1,
652 ')' | ']' | '}' => depth -= 1,
653 ',' if depth == 0 => {
654 out.push(¶ms[start..offset]);
655 start = offset + 1;
656 }
657 _ => {}
658 }
659 }
660 out.push(¶ms[start..]);
661 out
662}
663
664#[cfg(test)]
665mod tests {
666 use std::collections::BTreeSet;
667
668 use super::{
669 entrypoint_modules, get_stdlib_prompt_asset, get_stdlib_source,
670 public_functions_for_module, STDLIB_PROMPT_ASSETS, STDLIB_SOURCES,
671 };
672
673 #[test]
674 fn stdlib_sources_are_non_empty() {
675 for entry in STDLIB_SOURCES {
676 assert!(
677 !entry.source.trim().is_empty(),
678 "{} should have non-empty source",
679 entry.module
680 );
681 }
682 }
683
684 #[test]
685 fn stdlib_source_names_are_unique() {
686 let mut names = BTreeSet::new();
687 for entry in STDLIB_SOURCES {
688 assert!(names.insert(entry.module), "duplicate {}", entry.module);
689 }
690 }
691
692 #[test]
693 fn stdlib_prompt_assets_are_non_empty() {
694 for entry in STDLIB_PROMPT_ASSETS {
695 assert!(
696 !entry.source.trim().is_empty(),
697 "{} should have non-empty prompt asset source",
698 entry.path
699 );
700 }
701 }
702
703 #[test]
704 fn stdlib_prompt_asset_paths_are_unique() {
705 let mut paths = BTreeSet::new();
706 for entry in STDLIB_PROMPT_ASSETS {
707 assert!(paths.insert(entry.path), "duplicate {}", entry.path);
708 }
709 }
710
711 #[test]
712 fn key_stdlib_modules_resolve() {
713 for module in [
714 "context",
715 "command",
716 "waitpoint",
717 "llm/handlers",
718 "llm/ensemble",
719 "llm/rerank",
720 "personas/prelude",
721 "agent/host_tools",
722 "llm/optimize",
723 "llm/judge",
724 "llm/refine",
725 "connectors/shared",
726 "connectors/github",
727 "connectors/linear",
728 "connectors/notion",
729 "connectors/slack",
730 ] {
731 assert!(
732 get_stdlib_source(module).is_some(),
733 "std/{module} should resolve"
734 );
735 }
736 }
737
738 #[test]
739 fn key_stdlib_prompt_assets_resolve() {
740 for path in [
741 "std/agent/prompts/tool_contract_text.harn.prompt",
742 "std/agent/prompts/action_turn_nudge.harn.prompt",
743 "std/agent/prompts/completion_judge_default.harn.prompt",
744 "std/workflow/prompts/stage.harn.prompt",
745 "std/orchestration/prompts/compaction_summary.harn.prompt",
746 ] {
747 assert!(
748 get_stdlib_prompt_asset(path).is_some(),
749 "{path} should resolve"
750 );
751 }
752 }
753
754 #[test]
755 fn public_function_catalog_derives_signatures_from_harn_source() {
756 let exports = public_functions_for_module("workflow/execute");
757 assert_eq!(exports.len(), 1);
758 assert_eq!(exports[0].name, "workflow_execute");
759 assert_eq!(
760 exports[0].signature,
761 "workflow_execute(task, graph, artifacts = nil, options = nil)"
762 );
763 assert_eq!(exports[0].required_params, 2);
764 assert_eq!(exports[0].total_params, 4);
765 }
766
767 #[test]
768 fn command_stdlib_module_exports_step_helpers() {
769 let exports = public_functions_for_module("command")
770 .into_iter()
771 .map(|function| function.name)
772 .collect::<BTreeSet<_>>();
773 for name in [
774 "command_run",
775 "command_output_tail",
776 "command_step",
777 "command_steps_append",
778 "command_last_failed_step",
779 "command_step_ref",
780 ] {
781 assert!(exports.contains(name), "std/command should export {name}");
782 }
783 }
784
785 #[test]
786 fn harn_entrypoint_catalog_is_declared_by_stdlib_sources() {
787 let modules = entrypoint_modules();
788 let entries = modules
789 .iter()
790 .map(|module| (module.import_path.as_str(), module.category.as_str()))
791 .collect::<BTreeSet<_>>();
792 for entry in [
793 ("std/agent/loop", "agent.stdlib"),
794 ("std/agent/turn", "agent.stdlib"),
795 ("std/agent/primitives", "agent.stdlib"),
796 ("std/workflow/execute", "workflow.stdlib"),
797 ] {
798 assert!(entries.contains(&entry), "{entry:?} should be declared");
799 }
800 }
801}