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