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