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