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