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