Skip to main content

harn_stdlib/
lib.rs

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