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: "semver",
42        source: include_str!("stdlib/stdlib_semver.harn"),
43    },
44    StdlibSource {
45        module: "ansi",
46        source: include_str!("stdlib/stdlib_ansi.harn"),
47    },
48    StdlibSource {
49        module: "table",
50        source: include_str!("stdlib/stdlib_table.harn"),
51    },
52    StdlibSource {
53        module: "diff",
54        source: include_str!("stdlib/stdlib_diff.harn"),
55    },
56    StdlibSource {
57        module: "edit",
58        source: include_str!("stdlib/stdlib_edit.harn"),
59    },
60    StdlibSource {
61        module: "ast",
62        source: include_str!("stdlib/stdlib_ast.harn"),
63    },
64    StdlibSource {
65        module: "rules",
66        source: include_str!("stdlib/stdlib_rules.harn"),
67    },
68    StdlibSource {
69        module: "lint",
70        source: include_str!("stdlib/stdlib_lint.harn"),
71    },
72    StdlibSource {
73        module: "artifact/web",
74        source: include_str!("stdlib/artifact/web.harn"),
75    },
76    StdlibSource {
77        module: "collections",
78        source: include_str!("stdlib/stdlib_collections.harn"),
79    },
80    StdlibSource {
81        module: "math",
82        source: include_str!("stdlib/stdlib_math.harn"),
83    },
84    StdlibSource {
85        module: "path",
86        source: include_str!("stdlib/stdlib_path.harn"),
87    },
88    StdlibSource {
89        module: "fs",
90        source: include_str!("stdlib/stdlib_fs.harn"),
91    },
92    StdlibSource {
93        module: "run_artifacts",
94        source: include_str!("stdlib/stdlib_run_artifacts.harn"),
95    },
96    StdlibSource {
97        module: "os",
98        source: include_str!("stdlib/stdlib_os.harn"),
99    },
100    StdlibSource {
101        module: "json",
102        source: include_str!("stdlib/stdlib_json.harn"),
103    },
104    StdlibSource {
105        module: "json/stream",
106        source: include_str!("stdlib/stdlib_json_stream.harn"),
107    },
108    StdlibSource {
109        module: "xml",
110        source: include_str!("stdlib/stdlib_xml.harn"),
111    },
112    StdlibSource {
113        module: "cache",
114        source: include_str!("stdlib/stdlib_cache.harn"),
115    },
116    StdlibSource {
117        module: "observability",
118        source: include_str!("stdlib/stdlib_observability.harn"),
119    },
120    StdlibSource {
121        module: "timing",
122        source: include_str!("stdlib/stdlib_timing.harn"),
123    },
124    StdlibSource {
125        module: "tools",
126        source: include_str!("stdlib/stdlib_tools.harn"),
127    },
128    StdlibSource {
129        module: "composition",
130        source: include_str!("stdlib/stdlib_composition.harn"),
131    },
132    StdlibSource {
133        module: "web",
134        source: include_str!("stdlib/stdlib_web.harn"),
135    },
136    StdlibSource {
137        module: "graphql",
138        source: include_str!("stdlib/stdlib_graphql.harn"),
139    },
140    StdlibSource {
141        module: "code_librarian",
142        source: include_str!("stdlib/stdlib_code_librarian.harn"),
143    },
144    StdlibSource {
145        module: "schema",
146        source: include_str!("stdlib/stdlib_schema.harn"),
147    },
148    StdlibSource {
149        module: "testing",
150        source: include_str!("stdlib/stdlib_testing.harn"),
151    },
152    StdlibSource {
153        module: "files",
154        source: include_str!("stdlib/stdlib_files.harn"),
155    },
156    StdlibSource {
157        module: "mcp",
158        source: include_str!("stdlib/stdlib_mcp.harn"),
159    },
160    StdlibSource {
161        module: "vision",
162        source: include_str!("stdlib/stdlib_vision.harn"),
163    },
164    StdlibSource {
165        module: "context",
166        source: include_str!("stdlib/stdlib_context.harn"),
167    },
168    StdlibSource {
169        module: "context/maintenance",
170        source: include_str!("stdlib/context/maintenance.harn"),
171    },
172    StdlibSource {
173        module: "context/eval",
174        source: include_str!("stdlib/context/eval.harn"),
175    },
176    StdlibSource {
177        module: "runtime",
178        source: include_str!("stdlib/stdlib_runtime.harn"),
179    },
180    StdlibSource {
181        module: "io",
182        source: include_str!("stdlib/stdlib_io.harn"),
183    },
184    StdlibSource {
185        module: "net",
186        source: include_str!("stdlib/stdlib_net.harn"),
187    },
188    StdlibSource {
189        module: "command",
190        source: include_str!("stdlib/stdlib_command.harn"),
191    },
192    StdlibSource {
193        module: "signal",
194        source: include_str!("stdlib/stdlib_signal.harn"),
195    },
196    StdlibSource {
197        module: "net_policy",
198        source: include_str!("stdlib/stdlib_net_policy.harn"),
199    },
200    StdlibSource {
201        module: "review",
202        source: include_str!("stdlib/stdlib_review.harn"),
203    },
204    StdlibSource {
205        module: "experiments",
206        source: include_str!("stdlib/stdlib_experiments.harn"),
207    },
208    StdlibSource {
209        module: "project",
210        source: include_str!("stdlib/stdlib_project.harn"),
211    },
212    StdlibSource {
213        module: "prompt_library",
214        source: include_str!("stdlib/stdlib_prompt_library.harn"),
215    },
216    StdlibSource {
217        module: "async",
218        source: include_str!("stdlib/stdlib_async.harn"),
219    },
220    StdlibSource {
221        module: "poll",
222        source: include_str!("stdlib/stdlib_poll.harn"),
223    },
224    StdlibSource {
225        module: "coerce",
226        source: include_str!("stdlib/stdlib_coerce.harn"),
227    },
228    StdlibSource {
229        module: "settled",
230        source: include_str!("stdlib/stdlib_settled.harn"),
231    },
232    StdlibSource {
233        module: "cli",
234        source: include_str!("stdlib/stdlib_cli.harn"),
235    },
236    StdlibSource {
237        module: "cli/argparse",
238        source: include_str!("stdlib/cli/argparse.harn"),
239    },
240    StdlibSource {
241        module: "cli/render",
242        source: include_str!("stdlib/cli/render.harn"),
243    },
244    StdlibSource {
245        module: "cli/paths",
246        source: include_str!("stdlib/cli/paths.harn"),
247    },
248    StdlibSource {
249        module: "gha",
250        source: include_str!("stdlib/stdlib_gha.harn"),
251    },
252    StdlibSource {
253        module: "tui",
254        source: include_str!("stdlib/stdlib_tui.harn"),
255    },
256    StdlibSource {
257        module: "jsonl",
258        source: include_str!("stdlib/stdlib_jsonl.harn"),
259    },
260    StdlibSource {
261        module: "config",
262        source: include_str!("stdlib/stdlib_config.harn"),
263    },
264    StdlibSource {
265        module: "calendar",
266        source: include_str!("stdlib/stdlib_calendar.harn"),
267    },
268    StdlibSource {
269        module: "agents",
270        source: include_str!("stdlib/stdlib_agents.harn"),
271    },
272    StdlibSource {
273        module: "lifecycle/pool",
274        source: include_str!("stdlib/lifecycle/pool.harn"),
275    },
276    StdlibSource {
277        module: "lifecycle/combinators",
278        source: include_str!("stdlib/lifecycle/combinators.harn"),
279    },
280    StdlibSource {
281        module: "lifecycle/on_budget",
282        source: include_str!("stdlib/lifecycle/on_budget.harn"),
283    },
284    StdlibSource {
285        module: "agent/prompts",
286        source: include_str!("stdlib/agent/prompts.harn"),
287    },
288    StdlibSource {
289        module: "llm/media",
290        source: include_str!("stdlib/llm/media.harn"),
291    },
292    StdlibSource {
293        module: "llm/options",
294        source: include_str!("stdlib/llm/options.harn"),
295    },
296    StdlibSource {
297        module: "llm/catalog",
298        source: include_str!("stdlib/llm/catalog.harn"),
299    },
300    StdlibSource {
301        module: "llm/safe",
302        source: include_str!("stdlib/llm/safe.harn"),
303    },
304    StdlibSource {
305        module: "llm/budget",
306        source: include_str!("stdlib/llm/budget.harn"),
307    },
308    StdlibSource {
309        module: "llm/economics",
310        source: include_str!("stdlib/llm/economics.harn"),
311    },
312    StdlibSource {
313        module: "llm/prompts",
314        source: include_str!("stdlib/llm/prompts.harn"),
315    },
316    StdlibSource {
317        module: "llm/defaults",
318        source: include_str!("stdlib/llm/defaults.harn"),
319    },
320    StdlibSource {
321        module: "llm/handlers",
322        source: include_str!("stdlib/llm/handlers.harn"),
323    },
324    StdlibSource {
325        module: "llm/tool_telemetry",
326        source: include_str!("stdlib/llm/tool_telemetry.harn"),
327    },
328    StdlibSource {
329        module: "llm/tool_middleware",
330        source: include_str!("stdlib/llm/tool_middleware.harn"),
331    },
332    StdlibSource {
333        module: "llm/tool_binder",
334        source: include_str!("stdlib/llm/tool_binder.harn"),
335    },
336    StdlibSource {
337        module: "llm/structural_validator",
338        source: include_str!("stdlib/llm/structural_validator.harn"),
339    },
340    StdlibSource {
341        module: "llm/scope_classifier",
342        source: include_str!("stdlib/llm/scope_classifier.harn"),
343    },
344    StdlibSource {
345        module: "llm/refine",
346        source: include_str!("stdlib/llm/refine.harn"),
347    },
348    StdlibSource {
349        module: "llm/ensemble",
350        source: include_str!("stdlib/llm/ensemble.harn"),
351    },
352    StdlibSource {
353        module: "llm/rerank",
354        source: include_str!("stdlib/llm/rerank.harn"),
355    },
356    StdlibSource {
357        module: "agent/reasoning",
358        source: include_str!("stdlib/agent/reasoning.harn"),
359    },
360    StdlibSource {
361        module: "agent/options",
362        source: include_str!("stdlib/agent/options.harn"),
363    },
364    StdlibSource {
365        module: "llm/judge",
366        source: include_str!("stdlib/llm/judge.harn"),
367    },
368    StdlibSource {
369        module: "llm/optimize",
370        source: include_str!("stdlib/llm/optimize.harn"),
371    },
372    StdlibSource {
373        module: "agent/events",
374        source: include_str!("stdlib/agent/events.harn"),
375    },
376    StdlibSource {
377        module: "agent/primitives",
378        source: include_str!("stdlib/agent/primitives.harn"),
379    },
380    StdlibSource {
381        module: "agent/progress",
382        source: include_str!("stdlib/agent/progress.harn"),
383    },
384    StdlibSource {
385        module: "agent/required_tools",
386        source: include_str!("stdlib/agent/required_tools.harn"),
387    },
388    StdlibSource {
389        module: "agent/stall",
390        source: include_str!("stdlib/agent/stall.harn"),
391    },
392    StdlibSource {
393        module: "agent/control",
394        source: include_str!("stdlib/agent/control.harn"),
395    },
396    StdlibSource {
397        module: "agent/loop",
398        source: include_str!("stdlib/agent/loop.harn"),
399    },
400    StdlibSource {
401        module: "agent/chat",
402        source: include_str!("stdlib/agent/chat.harn"),
403    },
404    StdlibSource {
405        module: "agent/user",
406        source: include_str!("stdlib/agent/user.harn"),
407    },
408    StdlibSource {
409        module: "agent/tool_search",
410        source: include_str!("stdlib/agent/tool_search.harn"),
411    },
412    StdlibSource {
413        module: "agent/turn",
414        source: include_str!("stdlib/agent/turn.harn"),
415    },
416    StdlibSource {
417        module: "agent/workers",
418        source: include_str!("stdlib/agent/workers.harn"),
419    },
420    StdlibSource {
421        module: "agent/introspection",
422        source: include_str!("stdlib/agent/introspection.harn"),
423    },
424    StdlibSource {
425        module: "agent/resume_by",
426        source: include_str!("stdlib/agent/resume_by.harn"),
427    },
428    StdlibSource {
429        module: "agent/state",
430        source: include_str!("stdlib/agent/state.harn"),
431    },
432    StdlibSource {
433        module: "agent/skills",
434        source: include_str!("stdlib/agent/skills.harn"),
435    },
436    StdlibSource {
437        module: "agent/autocompact",
438        source: include_str!("stdlib/agent/autocompact.harn"),
439    },
440    StdlibSource {
441        module: "agent/mcp",
442        source: include_str!("stdlib/agent/mcp.harn"),
443    },
444    StdlibSource {
445        module: "agent/command_capture",
446        source: include_str!("stdlib/agent/command_capture.harn"),
447    },
448    StdlibSource {
449        module: "agent/host_tools",
450        source: include_str!("stdlib/agent/host_tools.harn"),
451    },
452    StdlibSource {
453        module: "agent/budget",
454        source: include_str!("stdlib/agent/budget.harn"),
455    },
456    StdlibSource {
457        module: "agent/daemon",
458        source: include_str!("stdlib/agent/daemon.harn"),
459    },
460    StdlibSource {
461        module: "agent/preflight",
462        source: include_str!("stdlib/agent/preflight.harn"),
463    },
464    StdlibSource {
465        module: "agent/postturn",
466        source: include_str!("stdlib/agent/postturn.harn"),
467    },
468    StdlibSource {
469        module: "agent/sitrep",
470        source: include_str!("stdlib/agent/sitrep.harn"),
471    },
472    StdlibSource {
473        module: "agent/judge_internals",
474        source: include_str!("stdlib/agent/judge_internals.harn"),
475    },
476    StdlibSource {
477        module: "agent/judge",
478        source: include_str!("stdlib/agent/judge.harn"),
479    },
480    StdlibSource {
481        module: "agent/step_judge",
482        source: include_str!("stdlib/agent/step_judge.harn"),
483    },
484    StdlibSource {
485        module: "agent/scratchpad",
486        source: include_str!("stdlib/agent/scratchpad.harn"),
487    },
488    StdlibSource {
489        module: "agent/fact",
490        source: include_str!("stdlib/agent/fact.harn"),
491    },
492    StdlibSource {
493        module: "agent/probe",
494        source: include_str!("stdlib/agent/probe.harn"),
495    },
496    StdlibSource {
497        module: "agent/presets",
498        source: include_str!("stdlib/agent/presets.harn"),
499    },
500    StdlibSource {
501        module: "agent/task_plan",
502        source: include_str!("stdlib/agent/task_plan.harn"),
503    },
504    StdlibSource {
505        module: "agent_state",
506        source: include_str!("stdlib/stdlib_agent_state.harn"),
507    },
508    StdlibSource {
509        module: "memory",
510        source: include_str!("stdlib/stdlib_memory.harn"),
511    },
512    StdlibSource {
513        module: "postgres",
514        source: include_str!("stdlib/stdlib_postgres.harn"),
515    },
516    StdlibSource {
517        module: "checkpoint",
518        source: include_str!("stdlib/stdlib_checkpoint.harn"),
519    },
520    StdlibSource {
521        module: "host",
522        source: include_str!("stdlib/stdlib_host.harn"),
523    },
524    StdlibSource {
525        module: "git",
526        source: include_str!("stdlib/stdlib_git.harn"),
527    },
528    StdlibSource {
529        module: "hitl",
530        source: include_str!("stdlib/stdlib_hitl.harn"),
531    },
532    StdlibSource {
533        module: "trust",
534        source: include_str!("stdlib/stdlib_trust.harn"),
535    },
536    StdlibSource {
537        module: "corrections",
538        source: include_str!("stdlib/stdlib_corrections.harn"),
539    },
540    StdlibSource {
541        module: "plan",
542        source: include_str!("stdlib/stdlib_plan.harn"),
543    },
544    StdlibSource {
545        module: "waitpoints",
546        source: include_str!("stdlib/stdlib_waitpoints.harn"),
547    },
548    StdlibSource {
549        module: "waitpoint",
550        source: include_str!("stdlib/stdlib_waitpoint.harn"),
551    },
552    StdlibSource {
553        module: "monitors",
554        source: include_str!("stdlib/stdlib_monitors.harn"),
555    },
556    StdlibSource {
557        module: "worktree",
558        source: include_str!("stdlib/stdlib_worktree.harn"),
559    },
560    StdlibSource {
561        module: "acp",
562        source: include_str!("stdlib/stdlib_acp.harn"),
563    },
564    StdlibSource {
565        module: "external_agent",
566        source: include_str!("stdlib/stdlib_external_agent.harn"),
567    },
568    StdlibSource {
569        module: "triggers",
570        source: include_str!("stdlib/stdlib_triggers.harn"),
571    },
572    StdlibSource {
573        module: "triage",
574        source: include_str!("stdlib/stdlib_triage.harn"),
575    },
576    StdlibSource {
577        module: "dashboard/jobs",
578        source: include_str!("stdlib/dashboard/jobs.harn"),
579    },
580    StdlibSource {
581        module: "ui_resource",
582        source: include_str!("stdlib/stdlib_ui_resource.harn"),
583    },
584    StdlibSource {
585        module: "handoffs",
586        source: include_str!("stdlib/stdlib_handoffs.harn"),
587    },
588    StdlibSource {
589        module: "lifecycle",
590        source: include_str!("stdlib/stdlib_lifecycle.harn"),
591    },
592    StdlibSource {
593        module: "tool_hooks_catalogues",
594        source: include_str!("stdlib/stdlib_tool_hooks_catalogues.harn"),
595    },
596    StdlibSource {
597        module: "tool_hooks",
598        source: include_str!("stdlib/stdlib_tool_hooks.harn"),
599    },
600    StdlibSource {
601        module: "channel_guardrails",
602        source: include_str!("stdlib/stdlib_channel_guardrails.harn"),
603    },
604    StdlibSource {
605        module: "personas/prelude",
606        source: include_str!("stdlib/stdlib_personas_prelude.harn"),
607    },
608    StdlibSource {
609        module: "personas/bulletins",
610        source: include_str!("stdlib/stdlib_personas_bulletins.harn"),
611    },
612    StdlibSource {
613        module: "connectors/shared",
614        source: include_str!("stdlib/stdlib_connectors_shared.harn"),
615    },
616    StdlibSource {
617        module: "oauth/providers",
618        source: include_str!("stdlib/oauth/providers.harn"),
619    },
620    StdlibSource {
621        module: "oauth/storage",
622        source: include_str!("stdlib/oauth/storage.harn"),
623    },
624    StdlibSource {
625        module: "oauth/client",
626        source: include_str!("stdlib/oauth/client.harn"),
627    },
628    StdlibSource {
629        module: "oauth/device_flow",
630        source: include_str!("stdlib/oauth/device_flow.harn"),
631    },
632    StdlibSource {
633        module: "oauth/redaction",
634        source: include_str!("stdlib/oauth/redaction.harn"),
635    },
636    StdlibSource {
637        module: "oauth/dynamic_registration",
638        source: include_str!("stdlib/oauth/dynamic_registration.harn"),
639    },
640    StdlibSource {
641        module: "connectors/github",
642        source: include_str!("stdlib/stdlib_connectors_github.harn"),
643    },
644    StdlibSource {
645        module: "connectors/linear",
646        source: include_str!("stdlib/stdlib_connectors_linear.harn"),
647    },
648    StdlibSource {
649        module: "connectors/notion",
650        source: include_str!("stdlib/stdlib_connectors_notion.harn"),
651    },
652    StdlibSource {
653        module: "connectors/slack",
654        source: include_str!("stdlib/stdlib_connectors_slack.harn"),
655    },
656    StdlibSource {
657        module: "workflow/prompts",
658        source: include_str!("stdlib/workflow/prompts.harn"),
659    },
660    StdlibSource {
661        module: "workflow/context",
662        source: include_str!("stdlib/workflow/context.harn"),
663    },
664    StdlibSource {
665        module: "workflow/options",
666        source: include_str!("stdlib/workflow/options.harn"),
667    },
668    StdlibSource {
669        module: "workflow/checkpoints",
670        source: include_str!("stdlib/workflow/checkpoints.harn"),
671    },
672    StdlibSource {
673        module: "workflow/stage",
674        source: include_str!("stdlib/workflow/stage.harn"),
675    },
676    StdlibSource {
677        module: "workflow/map",
678        source: include_str!("stdlib/workflow/map.harn"),
679    },
680    StdlibSource {
681        module: "workflow/schedule",
682        source: include_str!("stdlib/workflow/schedule.harn"),
683    },
684    StdlibSource {
685        module: "workflow/execute",
686        source: include_str!("stdlib/workflow/execute.harn"),
687    },
688    StdlibSource {
689        module: "security",
690        source: include_str!("stdlib/stdlib_security.harn"),
691    },
692];
693
694/// Canonical normalized connector event schemas, authored as Harn `type`
695/// declarations. This is the SOURCE OF TRUTH for the Rust event-payload
696/// structs in `crates/harn-vm/src/triggers/event/schemas_generated.rs`, which
697/// are generated from these declarations by `harn connector-schema-codegen`.
698///
699/// It is intentionally NOT registered in [`STDLIB_SOURCES`]: it is a codegen
700/// input (like `spec/openapi.yaml`), not a module loaded into every program.
701/// Exposing it as an embedded string keeps the generator independent of the
702/// current working directory.
703pub const CONNECTOR_EVENT_SCHEMAS_SOURCE: &str = include_str!("stdlib/stdlib_event_schemas.harn");
704
705pub const STDLIB_PROMPT_ASSETS: &[StdlibPromptAsset] = &[
706    StdlibPromptAsset {
707        path: "agent/prompts/tool_contract_text.harn.prompt",
708        source: include_str!("stdlib/agent/prompts/tool_contract_text.harn.prompt"),
709    },
710    StdlibPromptAsset {
711        path: "agent/prompts/tool_contract_native.harn.prompt",
712        source: include_str!("stdlib/agent/prompts/tool_contract_native.harn.prompt"),
713    },
714    StdlibPromptAsset {
715        path: "agent/prompts/tool_contract_text_response_protocol.harn.prompt",
716        source: include_str!(
717            "stdlib/agent/prompts/tool_contract_text_response_protocol.harn.prompt"
718        ),
719    },
720    StdlibPromptAsset {
721        path: "agent/prompts/tool_contract_action_native.harn.prompt",
722        source: include_str!("stdlib/agent/prompts/tool_contract_action_native.harn.prompt"),
723    },
724    StdlibPromptAsset {
725        path: "agent/prompts/tool_contract_action_text.harn.prompt",
726        source: include_str!("stdlib/agent/prompts/tool_contract_action_text.harn.prompt"),
727    },
728    StdlibPromptAsset {
729        path: "agent/prompts/tool_contract_task_ledger.harn.prompt",
730        source: include_str!("stdlib/agent/prompts/tool_contract_task_ledger.harn.prompt"),
731    },
732    StdlibPromptAsset {
733        path: "agent/prompts/tool_contract_deferred_tools.harn.prompt",
734        source: include_str!("stdlib/agent/prompts/tool_contract_deferred_tools.harn.prompt"),
735    },
736    StdlibPromptAsset {
737        path: "agent/prompts/deferred_tool_listing.harn.prompt",
738        source: include_str!("stdlib/agent/prompts/deferred_tool_listing.harn.prompt"),
739    },
740    StdlibPromptAsset {
741        path: "agent/prompts/action_turn_nudge.harn.prompt",
742        source: include_str!("stdlib/agent/prompts/action_turn_nudge.harn.prompt"),
743    },
744    StdlibPromptAsset {
745        path: "agent/prompts/agent_turn_preamble.harn.prompt",
746        source: include_str!("stdlib/agent/prompts/agent_turn_preamble.harn.prompt"),
747    },
748    StdlibPromptAsset {
749        path: "agent/prompts/default_nudge.harn.prompt",
750        source: include_str!("stdlib/agent/prompts/default_nudge.harn.prompt"),
751    },
752    StdlibPromptAsset {
753        path: "agent/prompts/agentic_user_system.harn.prompt",
754        source: include_str!("stdlib/agent/prompts/agentic_user_system.harn.prompt"),
755    },
756    StdlibPromptAsset {
757        path: "agent/prompts/agentic_user_user.harn.prompt",
758        source: include_str!("stdlib/agent/prompts/agentic_user_user.harn.prompt"),
759    },
760    StdlibPromptAsset {
761        path: "agent/prompts/loop_until_done_system.harn.prompt",
762        source: include_str!("stdlib/agent/prompts/loop_until_done_system.harn.prompt"),
763    },
764    StdlibPromptAsset {
765        path: "agent/prompts/completion_judge_default.harn.prompt",
766        source: include_str!("stdlib/agent/prompts/completion_judge_default.harn.prompt"),
767    },
768    StdlibPromptAsset {
769        path: "agent/prompts/completion_judge_feedback_fallback.harn.prompt",
770        source: include_str!("stdlib/agent/prompts/completion_judge_feedback_fallback.harn.prompt"),
771    },
772    StdlibPromptAsset {
773        path: "agent/prompts/completion_judge_user.harn.prompt",
774        source: include_str!("stdlib/agent/prompts/completion_judge_user.harn.prompt"),
775    },
776    StdlibPromptAsset {
777        path: "agent/prompts/step_judge_system_default.harn.prompt",
778        source: include_str!("stdlib/agent/prompts/step_judge_system_default.harn.prompt"),
779    },
780    StdlibPromptAsset {
781        path: "agent/prompts/step_judge_system_adversarial.harn.prompt",
782        source: include_str!("stdlib/agent/prompts/step_judge_system_adversarial.harn.prompt"),
783    },
784    StdlibPromptAsset {
785        path: "agent/prompts/step_judge_user.harn.prompt",
786        source: include_str!("stdlib/agent/prompts/step_judge_user.harn.prompt"),
787    },
788    StdlibPromptAsset {
789        path: "agent/prompts/parse_guidance.harn.prompt",
790        source: include_str!("stdlib/agent/prompts/parse_guidance.harn.prompt"),
791    },
792    StdlibPromptAsset {
793        path: "agent/prompts/protocol_violation_feedback.harn.prompt",
794        source: include_str!("stdlib/agent/prompts/protocol_violation_feedback.harn.prompt"),
795    },
796    StdlibPromptAsset {
797        path: "agent/prompts/native_tool_contract_feedback.harn.prompt",
798        source: include_str!("stdlib/agent/prompts/native_tool_contract_feedback.harn.prompt"),
799    },
800    StdlibPromptAsset {
801        path: "agent/prompts/verification_gate_feedback.harn.prompt",
802        source: include_str!("stdlib/agent/prompts/verification_gate_feedback.harn.prompt"),
803    },
804    StdlibPromptAsset {
805        path: "agent/prompts/action_required_feedback.harn.prompt",
806        source: include_str!("stdlib/agent/prompts/action_required_feedback.harn.prompt"),
807    },
808    StdlibPromptAsset {
809        path: "agent/prompts/daemon_watch_feedback.harn.prompt",
810        source: include_str!("stdlib/agent/prompts/daemon_watch_feedback.harn.prompt"),
811    },
812    StdlibPromptAsset {
813        path: "agent/prompts/daemon_timer_feedback.harn.prompt",
814        source: include_str!("stdlib/agent/prompts/daemon_timer_feedback.harn.prompt"),
815    },
816    StdlibPromptAsset {
817        path: "llm/prompts/completion_fallback_system.harn.prompt",
818        source: include_str!("stdlib/llm/prompts/completion_fallback_system.harn.prompt"),
819    },
820    StdlibPromptAsset {
821        path: "llm/prompts/completion_fallback_user.harn.prompt",
822        source: include_str!("stdlib/llm/prompts/completion_fallback_user.harn.prompt"),
823    },
824    StdlibPromptAsset {
825        path: "llm/prompts/transcript_summarize_user.harn.prompt",
826        source: include_str!("stdlib/llm/prompts/transcript_summarize_user.harn.prompt"),
827    },
828    StdlibPromptAsset {
829        path: "llm/prompts/sitrep_user.harn.prompt",
830        source: include_str!("stdlib/llm/prompts/sitrep_user.harn.prompt"),
831    },
832    StdlibPromptAsset {
833        path: "llm/prompts/structural_chain_of_draft.harn.prompt",
834        source: include_str!("stdlib/llm/prompts/structural_chain_of_draft.harn.prompt"),
835    },
836    StdlibPromptAsset {
837        path: "llm/prompts/schema_recover_repair.harn.prompt",
838        source: include_str!("stdlib/llm/prompts/schema_recover_repair.harn.prompt"),
839    },
840    StdlibPromptAsset {
841        path: "llm/prompts/structured_envelope_schema_contract.harn.prompt",
842        source: include_str!("stdlib/llm/prompts/structured_envelope_schema_contract.harn.prompt"),
843    },
844    StdlibPromptAsset {
845        path: "llm/prompts/structured_envelope_repair.harn.prompt",
846        source: include_str!("stdlib/llm/prompts/structured_envelope_repair.harn.prompt"),
847    },
848    StdlibPromptAsset {
849        path: "llm/prompts/pairwise_rerank_user.harn.prompt",
850        source: include_str!("stdlib/llm/prompts/pairwise_rerank_user.harn.prompt"),
851    },
852    StdlibPromptAsset {
853        path: "llm/prompts/tool_binder_user.harn.prompt",
854        source: include_str!("stdlib/llm/prompts/tool_binder_user.harn.prompt"),
855    },
856    StdlibPromptAsset {
857        path: "workflow/prompts/stage.harn.prompt",
858        source: include_str!("stdlib/workflow/prompts/stage.harn.prompt"),
859    },
860    StdlibPromptAsset {
861        path: "workflow/prompts/verification_context_intro.harn.prompt",
862        source: include_str!("stdlib/workflow/prompts/verification_context_intro.harn.prompt"),
863    },
864    StdlibPromptAsset {
865        path: "orchestration/prompts/compaction_summary.harn.prompt",
866        source: include_str!("stdlib/orchestration/prompts/compaction_summary.harn.prompt"),
867    },
868    StdlibPromptAsset {
869        path: "orchestration/prompts/compaction_policy_replacement.harn.prompt",
870        source: include_str!(
871            "stdlib/orchestration/prompts/compaction_policy_replacement.harn.prompt"
872        ),
873    },
874];
875
876/// Embedded `.harn` script that backs a CLI subcommand. Looked up by
877/// the `harn-cli` dispatch wedge (see harn#2293 epic and harn#2294 G1)
878/// so subcommands can ship in Harn instead of Rust.
879#[derive(Debug, Clone, Copy, PartialEq, Eq)]
880pub struct StdlibCliScript {
881    /// Lookup name. For nested scripts this is the path under
882    /// `stdlib/cli/` without the `.harn` extension (e.g. `"eval/prompt"`
883    /// for `stdlib/cli/eval/prompt.harn`).
884    pub name: &'static str,
885    /// Embedded source. Run via the existing `harn run` codepath by the
886    /// dispatch wedge.
887    pub source: &'static str,
888}
889
890pub const STDLIB_CLI_SCRIPTS: &[StdlibCliScript] = &[
891    StdlibCliScript {
892        name: "codemod",
893        source: include_str!("stdlib/cli/codemod.harn"),
894    },
895    StdlibCliScript {
896        name: "doctor",
897        source: include_str!("stdlib/cli/doctor.harn"),
898    },
899    StdlibCliScript {
900        name: "echo",
901        source: include_str!("stdlib/cli/echo.harn"),
902    },
903    // Helper module for the embedded `eval/*` scripts. Has a stub `main`
904    // that exits non-zero — sibling scripts inline its helpers until the
905    // dispatch wedge gains a cross-script import surface (#2300 / G7).
906    StdlibCliScript {
907        name: "eval/_runner",
908        source: include_str!("stdlib/cli/eval/_runner.harn"),
909    },
910    StdlibCliScript {
911        name: "eval/context",
912        source: include_str!("stdlib/cli/eval/context.harn"),
913    },
914    StdlibCliScript {
915        name: "eval/model_selector",
916        source: include_str!("stdlib/cli/eval/model_selector.harn"),
917    },
918    StdlibCliScript {
919        name: "eval/tool_calls",
920        source: include_str!("stdlib/cli/eval/tool_calls.harn"),
921    },
922    StdlibCliScript {
923        name: "eval/coding_agent",
924        source: include_str!("stdlib/cli/eval/coding_agent.harn"),
925    },
926    StdlibCliScript {
927        name: "eval/scope_triage",
928        source: include_str!("stdlib/cli/eval/scope_triage.harn"),
929    },
930    StdlibCliScript {
931        name: "eval/prompt",
932        source: include_str!("stdlib/cli/eval/prompt.harn"),
933    },
934    StdlibCliScript {
935        name: "explain",
936        source: include_str!("stdlib/cli/explain.harn"),
937    },
938    StdlibCliScript {
939        name: "graph",
940        source: include_str!("stdlib/cli/graph.harn"),
941    },
942    StdlibCliScript {
943        name: "models/list",
944        source: include_str!("stdlib/cli/models/list.harn"),
945    },
946    StdlibCliScript {
947        name: "models/recommend",
948        source: include_str!("stdlib/cli/models/recommend.harn"),
949    },
950    StdlibCliScript {
951        name: "models/test",
952        source: include_str!("stdlib/cli/models/test.harn"),
953    },
954    StdlibCliScript {
955        name: "precompile",
956        source: include_str!("stdlib/cli/precompile.harn"),
957    },
958    StdlibCliScript {
959        name: "providers/catalog",
960        source: include_str!("stdlib/cli/providers/catalog.harn"),
961    },
962    StdlibCliScript {
963        name: "providers/probe",
964        source: include_str!("stdlib/cli/providers/probe.harn"),
965    },
966    StdlibCliScript {
967        name: "providers/recommend",
968        source: include_str!("stdlib/cli/providers/recommend.harn"),
969    },
970    StdlibCliScript {
971        name: "providers/tool_probe",
972        source: include_str!("stdlib/cli/providers/tool_probe.harn"),
973    },
974    StdlibCliScript {
975        name: "routes",
976        source: include_str!("stdlib/cli/routes.harn"),
977    },
978    StdlibCliScript {
979        name: "scan",
980        source: include_str!("stdlib/cli/scan.harn"),
981    },
982    StdlibCliScript {
983        name: "scaffold/init",
984        source: include_str!("stdlib/cli/scaffold/init.harn"),
985    },
986    StdlibCliScript {
987        name: "scaffold/tool_new",
988        source: include_str!("stdlib/cli/scaffold/tool_new.harn"),
989    },
990    StdlibCliScript {
991        name: "trace_import",
992        source: include_str!("stdlib/cli/trace_import.harn"),
993    },
994    StdlibCliScript {
995        name: "try",
996        source: include_str!("stdlib/cli/try.harn"),
997    },
998    StdlibCliScript {
999        name: "version",
1000        source: include_str!("stdlib/cli/version.harn"),
1001    },
1002];
1003
1004pub fn get_stdlib_source(module: &str) -> Option<&'static str> {
1005    STDLIB_SOURCES
1006        .iter()
1007        .find_map(|entry| (entry.module == module).then_some(entry.source))
1008}
1009
1010/// Find an embedded CLI subcommand script by name. Returns the embedded
1011/// source string when present, or `None` if no script with that name is
1012/// registered in [`STDLIB_CLI_SCRIPTS`].
1013pub fn find_cli_script(name: &str) -> Option<&'static str> {
1014    STDLIB_CLI_SCRIPTS
1015        .iter()
1016        .find_map(|entry| (entry.name == name).then_some(entry.source))
1017}
1018
1019pub fn get_stdlib_prompt_asset(path: &str) -> Option<&'static str> {
1020    let path = path.strip_prefix("std/").unwrap_or(path);
1021    STDLIB_PROMPT_ASSETS
1022        .iter()
1023        .find_map(|entry| (entry.path == path).then_some(entry.source))
1024}
1025
1026pub fn public_functions_for_module(module: &str) -> Vec<StdlibPublicFunction> {
1027    let Some(source) = get_stdlib_source(module) else {
1028        return Vec::new();
1029    };
1030    public_functions_from_source(source)
1031}
1032
1033pub fn entrypoint_modules() -> Vec<StdlibEntrypointModule> {
1034    STDLIB_SOURCES
1035        .iter()
1036        .filter_map(|entry| {
1037            entrypoint_category_from_source(entry.source).map(|category| StdlibEntrypointModule {
1038                import_path: format!("std/{}", entry.module),
1039                category,
1040            })
1041        })
1042        .collect()
1043}
1044
1045fn entrypoint_category_from_source(source: &str) -> Option<String> {
1046    for line in source.lines() {
1047        let line = line.trim();
1048        if line.is_empty() {
1049            continue;
1050        }
1051        if let Some(category) = line.strip_prefix("// @harn-entrypoint-category ") {
1052            let category = category.trim();
1053            return (!category.is_empty()).then(|| category.to_string());
1054        }
1055        if !line.starts_with("//") {
1056            return None;
1057        }
1058    }
1059    None
1060}
1061
1062fn public_functions_from_source(source: &str) -> Vec<StdlibPublicFunction> {
1063    let mut out = Vec::new();
1064    let mut doc: Option<String> = None;
1065    let lines = source.lines().collect::<Vec<_>>();
1066    let mut index = 0usize;
1067    while index < lines.len() {
1068        let line = lines[index].trim();
1069        if line.starts_with("/**") {
1070            let (parsed, next) = parse_harndoc(&lines, index);
1071            doc = parsed;
1072            index = next;
1073            continue;
1074        }
1075        if line.starts_with("pub fn ") {
1076            let (signature_line, next) = collect_public_function_signature(&lines, index);
1077            if let Some(function) = parse_public_function_line(&signature_line, doc.take()) {
1078                out.push(function);
1079                index = next;
1080                continue;
1081            }
1082        }
1083        if let Some(function) = parse_public_function_line(line, doc.take()) {
1084            out.push(function);
1085        } else if !line.is_empty() && !line.starts_with("//") {
1086            doc = None;
1087        }
1088        index += 1;
1089    }
1090    out
1091}
1092
1093fn collect_public_function_signature(lines: &[&str], start: usize) -> (String, usize) {
1094    let mut parts = Vec::new();
1095    let mut index = start;
1096    while index < lines.len() {
1097        parts.push(lines[index].trim().to_string());
1098        let candidate = parts.join(" ");
1099        if public_function_signature_complete(&candidate) {
1100            return (candidate, index + 1);
1101        }
1102        index += 1;
1103    }
1104    (parts.join(" "), index)
1105}
1106
1107fn public_function_signature_complete(line: &str) -> bool {
1108    let Some(rest) = line.strip_prefix("pub fn ") else {
1109        return false;
1110    };
1111    let Some(name_end) = rest.find('(') else {
1112        return false;
1113    };
1114    matching_paren_len(&rest[name_end + 1..]).is_some()
1115}
1116
1117fn parse_harndoc(lines: &[&str], start: usize) -> (Option<String>, usize) {
1118    let mut parts = Vec::new();
1119    let mut index = start;
1120    while index < lines.len() {
1121        let mut line = lines[index].trim();
1122        if index == start {
1123            line = line.trim_start_matches("/**").trim();
1124        }
1125        let done = line.ends_with("*/");
1126        line = line.trim_end_matches("*/").trim();
1127        line = line.trim_start_matches('*').trim();
1128        if !line.is_empty() {
1129            parts.push(line.to_string());
1130        }
1131        index += 1;
1132        if done {
1133            break;
1134        }
1135    }
1136    let text = parts.join("\n").trim().to_string();
1137    ((!text.is_empty()).then_some(text), index)
1138}
1139
1140fn parse_public_function_line(line: &str, doc: Option<String>) -> Option<StdlibPublicFunction> {
1141    let rest = line.strip_prefix("pub fn ")?.trim();
1142    let name_end = rest.find('(')?;
1143    let name = rest[..name_end].trim();
1144    if name.is_empty() {
1145        return None;
1146    }
1147    let params_start = name_end + 1;
1148    let params_len = matching_paren_len(&rest[params_start..])?;
1149    let params = &rest[params_start..params_start + params_len];
1150    let after = rest[params_start + params_len + 1..].trim();
1151    let return_type = after
1152        .strip_prefix("->")
1153        .and_then(|tail| tail.split('{').next())
1154        .map(str::trim)
1155        .filter(|value| !value.is_empty());
1156    let signature = match return_type {
1157        Some(ret) => format!("{name}({params}) -> {ret}"),
1158        None => format!("{name}({params})"),
1159    };
1160    let param_parts = split_top_level_params(params);
1161    let total_params = param_parts
1162        .iter()
1163        .filter(|param| !param.trim().is_empty())
1164        .count();
1165    let variadic = param_parts
1166        .iter()
1167        .any(|param| param.trim_start().starts_with("..."));
1168    let required_params = param_parts
1169        .iter()
1170        .filter(|param| {
1171            let param = param.trim();
1172            !param.is_empty() && !param.contains('=') && !param.starts_with("...")
1173        })
1174        .count();
1175    Some(StdlibPublicFunction {
1176        name: name.to_string(),
1177        signature,
1178        required_params,
1179        total_params,
1180        variadic,
1181        doc,
1182    })
1183}
1184
1185fn matching_paren_len(input: &str) -> Option<usize> {
1186    let mut depth = 1usize;
1187    for (offset, ch) in input.char_indices() {
1188        match ch {
1189            '(' | '[' | '{' => depth += 1,
1190            ')' => {
1191                depth = depth.saturating_sub(1);
1192                if depth == 0 {
1193                    return Some(offset);
1194                }
1195            }
1196            ']' | '}' => depth = depth.saturating_sub(1),
1197            _ => {}
1198        }
1199    }
1200    None
1201}
1202
1203fn split_top_level_params(params: &str) -> Vec<&str> {
1204    let mut out = Vec::new();
1205    let mut depth = 0isize;
1206    let mut start = 0usize;
1207    for (offset, ch) in params.char_indices() {
1208        match ch {
1209            '(' | '[' | '{' => depth += 1,
1210            ')' | ']' | '}' => depth -= 1,
1211            ',' if depth == 0 => {
1212                out.push(&params[start..offset]);
1213                start = offset + 1;
1214            }
1215            _ => {}
1216        }
1217    }
1218    out.push(&params[start..]);
1219    out
1220}
1221
1222#[cfg(test)]
1223mod tests {
1224    use std::collections::BTreeSet;
1225
1226    use super::{
1227        entrypoint_modules, find_cli_script, get_stdlib_prompt_asset, get_stdlib_source,
1228        public_functions_for_module, STDLIB_CLI_SCRIPTS, STDLIB_PROMPT_ASSETS, STDLIB_SOURCES,
1229    };
1230
1231    #[test]
1232    fn stdlib_sources_are_non_empty() {
1233        for entry in STDLIB_SOURCES {
1234            assert!(
1235                !entry.source.trim().is_empty(),
1236                "{} should have non-empty source",
1237                entry.module
1238            );
1239        }
1240    }
1241
1242    #[test]
1243    fn cli_scripts_are_non_empty_and_uniquely_named() {
1244        let mut seen = BTreeSet::new();
1245        for entry in STDLIB_CLI_SCRIPTS {
1246            assert!(
1247                !entry.source.trim().is_empty(),
1248                "cli/{} should have non-empty source",
1249                entry.name
1250            );
1251            assert!(
1252                seen.insert(entry.name),
1253                "cli/{} is registered more than once in STDLIB_CLI_SCRIPTS",
1254                entry.name
1255            );
1256        }
1257    }
1258
1259    #[test]
1260    fn find_cli_script_round_trips() {
1261        for entry in STDLIB_CLI_SCRIPTS {
1262            assert_eq!(find_cli_script(entry.name), Some(entry.source));
1263        }
1264        assert!(find_cli_script("not-a-real-script").is_none());
1265    }
1266
1267    #[test]
1268    fn stdlib_source_names_are_unique() {
1269        let mut names = BTreeSet::new();
1270        for entry in STDLIB_SOURCES {
1271            assert!(names.insert(entry.module), "duplicate {}", entry.module);
1272        }
1273    }
1274
1275    #[test]
1276    fn stdlib_prompt_assets_are_non_empty() {
1277        for entry in STDLIB_PROMPT_ASSETS {
1278            assert!(
1279                !entry.source.trim().is_empty(),
1280                "{} should have non-empty prompt asset source",
1281                entry.path
1282            );
1283        }
1284    }
1285
1286    #[test]
1287    fn stdlib_prompt_asset_paths_are_unique() {
1288        let mut paths = BTreeSet::new();
1289        for entry in STDLIB_PROMPT_ASSETS {
1290            assert!(paths.insert(entry.path), "duplicate {}", entry.path);
1291        }
1292    }
1293
1294    #[test]
1295    fn key_stdlib_modules_resolve() {
1296        for module in [
1297            "context",
1298            "context/maintenance",
1299            "context/eval",
1300            "edit",
1301            "artifact/web",
1302            "command",
1303            "waitpoint",
1304            "llm/handlers",
1305            "llm/tool_middleware",
1306            "llm/tool_binder",
1307            "llm/ensemble",
1308            "llm/rerank",
1309            "personas/prelude",
1310            "personas/bulletins",
1311            "agent/host_tools",
1312            "agent/user",
1313            "llm/optimize",
1314            "llm/judge",
1315            "llm/refine",
1316            "connectors/shared",
1317            "connectors/github",
1318            "connectors/linear",
1319            "connectors/notion",
1320            "connectors/slack",
1321            "triage",
1322            "dashboard/jobs",
1323            "ui_resource",
1324        ] {
1325            assert!(
1326                get_stdlib_source(module).is_some(),
1327                "std/{module} should resolve"
1328            );
1329        }
1330    }
1331
1332    #[test]
1333    fn key_stdlib_prompt_assets_resolve() {
1334        for path in [
1335            "std/agent/prompts/tool_contract_text.harn.prompt",
1336            "std/agent/prompts/action_turn_nudge.harn.prompt",
1337            "std/agent/prompts/completion_judge_default.harn.prompt",
1338            "std/workflow/prompts/stage.harn.prompt",
1339            "std/orchestration/prompts/compaction_summary.harn.prompt",
1340            "std/orchestration/prompts/compaction_policy_replacement.harn.prompt",
1341        ] {
1342            assert!(
1343                get_stdlib_prompt_asset(path).is_some(),
1344                "{path} should resolve"
1345            );
1346        }
1347    }
1348
1349    #[test]
1350    fn public_function_catalog_derives_signatures_from_harn_source() {
1351        let exports = public_functions_for_module("workflow/execute");
1352        assert_eq!(exports.len(), 1);
1353        assert_eq!(exports[0].name, "workflow_execute");
1354        assert_eq!(
1355            exports[0].signature,
1356            "workflow_execute(task, graph, artifacts = nil, options = nil)"
1357        );
1358        assert_eq!(exports[0].required_params, 2);
1359        assert_eq!(exports[0].total_params, 4);
1360    }
1361
1362    #[test]
1363    fn command_stdlib_module_exports_step_helpers() {
1364        let exports = public_functions_for_module("command")
1365            .into_iter()
1366            .map(|function| function.name)
1367            .collect::<BTreeSet<_>>();
1368        for name in [
1369            "command_run",
1370            "command_wait",
1371            "command_cancel",
1372            "command_run_streaming",
1373            "command_output_tail",
1374            "command_json",
1375            "command_json_step",
1376            "command_try",
1377            "command_step",
1378            "command_steps_append",
1379            "command_last_failed_step",
1380            "command_step_ref",
1381        ] {
1382            assert!(exports.contains(name), "std/command should export {name}");
1383        }
1384    }
1385
1386    #[test]
1387    fn async_stdlib_exports_predicate_backoff_name_only() {
1388        let exports = public_functions_for_module("async")
1389            .into_iter()
1390            .map(|function| function.name)
1391            .collect::<BTreeSet<_>>();
1392        assert!(
1393            exports.contains("retry_predicate_with_backoff"),
1394            "std/async should export retry_predicate_with_backoff"
1395        );
1396        assert!(
1397            !exports.contains("retry_with_backoff"),
1398            "std/async should not retain the old retry_with_backoff export"
1399        );
1400    }
1401
1402    #[test]
1403    fn signal_stdlib_module_exports_interrupt_helpers() {
1404        let exports = public_functions_for_module("signal")
1405            .into_iter()
1406            .map(|function| function.name)
1407            .collect::<BTreeSet<_>>();
1408        for name in [
1409            "on_interrupt",
1410            "off_interrupt",
1411            "interrupted",
1412            "with_interrupt",
1413        ] {
1414            assert!(exports.contains(name), "std/signal should export {name}");
1415        }
1416    }
1417
1418    #[test]
1419    fn git_stdlib_module_exports_local_wrappers() {
1420        let exports = public_functions_for_module("git")
1421            .into_iter()
1422            .map(|function| function.name)
1423            .collect::<BTreeSet<_>>();
1424        for name in [
1425            "git_run",
1426            "git_status",
1427            "git_current_branch",
1428            "git_log",
1429            "git_switch",
1430            "git_pull_ff_only",
1431            "git_find_tool",
1432            "git_run_tool",
1433            "git_tools",
1434            "git_toolbox_tools",
1435        ] {
1436            assert!(exports.contains(name), "std/git should export {name}");
1437        }
1438    }
1439
1440    #[test]
1441    fn agent_workers_exports_suspend_resume_wrappers() {
1442        let exports = public_functions_for_module("agent/workers");
1443        let suspend = exports
1444            .iter()
1445            .find(|function| function.name == "suspend_agent")
1446            .expect("std/agent/workers should export suspend_agent");
1447        assert_eq!(
1448            suspend.signature,
1449            "suspend_agent(worker, reason = \"\", options = nil)"
1450        );
1451        assert_eq!(suspend.required_params, 1);
1452        assert_eq!(suspend.total_params, 3);
1453
1454        let resume = exports
1455            .iter()
1456            .find(|function| function.name == "resume_agent")
1457            .expect("std/agent/workers should export resume_agent");
1458        assert_eq!(
1459            resume.signature,
1460            "resume_agent(worker_or_snapshot, resume_input = nil, continue_transcript = true)"
1461        );
1462        assert_eq!(resume.required_params, 1);
1463        assert_eq!(resume.total_params, 3);
1464
1465        let stop = exports
1466            .iter()
1467            .find(|function| function.name == "agent_stop")
1468            .expect("std/agent/workers should export agent_stop");
1469        assert_eq!(
1470            stop.signature,
1471            "agent_stop(worker, options: AgentStopOptions = nil)"
1472        );
1473        assert_eq!(stop.required_params, 1);
1474        assert_eq!(stop.total_params, 2);
1475
1476        let parse_resume = exports
1477            .iter()
1478            .find(|function| function.name == "parse_resume_conditions")
1479            .expect("std/agent/workers should export parse_resume_conditions");
1480        assert_eq!(
1481            parse_resume.signature,
1482            "parse_resume_conditions(conditions = nil) -> ResumeConditions?"
1483        );
1484        assert_eq!(parse_resume.required_params, 0);
1485        assert_eq!(parse_resume.total_params, 1);
1486
1487        let lifecycle = exports
1488            .iter()
1489            .find(|function| function.name == "agent_lifecycle_tools")
1490            .expect("std/agent/workers should export agent_lifecycle_tools");
1491        assert_eq!(
1492            lifecycle.signature,
1493            "agent_lifecycle_tools(registry = nil, options = nil)"
1494        );
1495        assert_eq!(lifecycle.required_params, 0);
1496        assert_eq!(lifecycle.total_params, 2);
1497    }
1498
1499    #[test]
1500    fn tui_stdlib_module_exports_terminal_helpers() {
1501        let exports = public_functions_for_module("tui")
1502            .into_iter()
1503            .map(|function| function.name)
1504            .collect::<BTreeSet<_>>();
1505        for name in ["page", "terminal_width", "rule", "clear", "select_from"] {
1506            assert!(exports.contains(name), "std/tui should export {name}");
1507        }
1508    }
1509
1510    #[test]
1511    fn semver_stdlib_module_exports_release_helpers() {
1512        let exports = public_functions_for_module("semver")
1513            .into_iter()
1514            .map(|function| function.name)
1515            .collect::<BTreeSet<_>>();
1516        for name in [
1517            "strip_v",
1518            "add_v",
1519            "is_v_semver",
1520            "parse",
1521            "next",
1522            "bump_type",
1523            "version_from_release_branch",
1524            "version_from_tag",
1525        ] {
1526            assert!(exports.contains(name), "std/semver should export {name}");
1527        }
1528    }
1529
1530    #[test]
1531    fn text_stdlib_module_exports_regex_and_pad_helpers() {
1532        let exports = public_functions_for_module("text")
1533            .into_iter()
1534            .map(|function| function.name)
1535            .collect::<BTreeSet<_>>();
1536        for name in [
1537            "pad_left",
1538            "pad_right",
1539            "repeat_string",
1540            "regex_first_capture",
1541            "regex_capture_groups",
1542            "regex_all_first_captures",
1543        ] {
1544            assert!(exports.contains(name), "std/text should export {name}");
1545        }
1546    }
1547
1548    #[test]
1549    fn harn_entrypoint_catalog_is_declared_by_stdlib_sources() {
1550        let modules = entrypoint_modules();
1551        let entries = modules
1552            .iter()
1553            .map(|module| (module.import_path.as_str(), module.category.as_str()))
1554            .collect::<BTreeSet<_>>();
1555        for entry in [
1556            ("std/agent/loop", "agent.stdlib"),
1557            ("std/agent/turn", "agent.stdlib"),
1558            ("std/agent/primitives", "agent.stdlib"),
1559            ("std/workflow/execute", "workflow.stdlib"),
1560        ] {
1561            assert!(entries.contains(&entry), "{entry:?} should be declared");
1562        }
1563    }
1564}