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: "ansi",
42        source: include_str!("stdlib/stdlib_ansi.harn"),
43    },
44    StdlibSource {
45        module: "table",
46        source: include_str!("stdlib/stdlib_table.harn"),
47    },
48    StdlibSource {
49        module: "diff",
50        source: include_str!("stdlib/stdlib_diff.harn"),
51    },
52    StdlibSource {
53        module: "edit",
54        source: include_str!("stdlib/stdlib_edit.harn"),
55    },
56    StdlibSource {
57        module: "artifact/web",
58        source: include_str!("stdlib/artifact/web.harn"),
59    },
60    StdlibSource {
61        module: "collections",
62        source: include_str!("stdlib/stdlib_collections.harn"),
63    },
64    StdlibSource {
65        module: "math",
66        source: include_str!("stdlib/stdlib_math.harn"),
67    },
68    StdlibSource {
69        module: "path",
70        source: include_str!("stdlib/stdlib_path.harn"),
71    },
72    StdlibSource {
73        module: "fs",
74        source: include_str!("stdlib/stdlib_fs.harn"),
75    },
76    StdlibSource {
77        module: "os",
78        source: include_str!("stdlib/stdlib_os.harn"),
79    },
80    StdlibSource {
81        module: "json",
82        source: include_str!("stdlib/stdlib_json.harn"),
83    },
84    StdlibSource {
85        module: "json/stream",
86        source: include_str!("stdlib/stdlib_json_stream.harn"),
87    },
88    StdlibSource {
89        module: "cache",
90        source: include_str!("stdlib/stdlib_cache.harn"),
91    },
92    StdlibSource {
93        module: "tools",
94        source: include_str!("stdlib/stdlib_tools.harn"),
95    },
96    StdlibSource {
97        module: "composition",
98        source: include_str!("stdlib/stdlib_composition.harn"),
99    },
100    StdlibSource {
101        module: "web",
102        source: include_str!("stdlib/stdlib_web.harn"),
103    },
104    StdlibSource {
105        module: "graphql",
106        source: include_str!("stdlib/stdlib_graphql.harn"),
107    },
108    StdlibSource {
109        module: "schema",
110        source: include_str!("stdlib/stdlib_schema.harn"),
111    },
112    StdlibSource {
113        module: "testing",
114        source: include_str!("stdlib/stdlib_testing.harn"),
115    },
116    StdlibSource {
117        module: "files",
118        source: include_str!("stdlib/stdlib_files.harn"),
119    },
120    StdlibSource {
121        module: "vision",
122        source: include_str!("stdlib/stdlib_vision.harn"),
123    },
124    StdlibSource {
125        module: "context",
126        source: include_str!("stdlib/stdlib_context.harn"),
127    },
128    StdlibSource {
129        module: "context/maintenance",
130        source: include_str!("stdlib/context/maintenance.harn"),
131    },
132    StdlibSource {
133        module: "runtime",
134        source: include_str!("stdlib/stdlib_runtime.harn"),
135    },
136    StdlibSource {
137        module: "io",
138        source: include_str!("stdlib/stdlib_io.harn"),
139    },
140    StdlibSource {
141        module: "command",
142        source: include_str!("stdlib/stdlib_command.harn"),
143    },
144    StdlibSource {
145        module: "signal",
146        source: include_str!("stdlib/stdlib_signal.harn"),
147    },
148    StdlibSource {
149        module: "review",
150        source: include_str!("stdlib/stdlib_review.harn"),
151    },
152    StdlibSource {
153        module: "experiments",
154        source: include_str!("stdlib/stdlib_experiments.harn"),
155    },
156    StdlibSource {
157        module: "project",
158        source: include_str!("stdlib/stdlib_project.harn"),
159    },
160    StdlibSource {
161        module: "prompt_library",
162        source: include_str!("stdlib/stdlib_prompt_library.harn"),
163    },
164    StdlibSource {
165        module: "async",
166        source: include_str!("stdlib/stdlib_async.harn"),
167    },
168    StdlibSource {
169        module: "poll",
170        source: include_str!("stdlib/stdlib_poll.harn"),
171    },
172    StdlibSource {
173        module: "coerce",
174        source: include_str!("stdlib/stdlib_coerce.harn"),
175    },
176    StdlibSource {
177        module: "settled",
178        source: include_str!("stdlib/stdlib_settled.harn"),
179    },
180    StdlibSource {
181        module: "cli",
182        source: include_str!("stdlib/stdlib_cli.harn"),
183    },
184    StdlibSource {
185        module: "gha",
186        source: include_str!("stdlib/stdlib_gha.harn"),
187    },
188    StdlibSource {
189        module: "tui",
190        source: include_str!("stdlib/stdlib_tui.harn"),
191    },
192    StdlibSource {
193        module: "jsonl",
194        source: include_str!("stdlib/stdlib_jsonl.harn"),
195    },
196    StdlibSource {
197        module: "config",
198        source: include_str!("stdlib/stdlib_config.harn"),
199    },
200    StdlibSource {
201        module: "calendar",
202        source: include_str!("stdlib/stdlib_calendar.harn"),
203    },
204    StdlibSource {
205        module: "agents",
206        source: include_str!("stdlib/stdlib_agents.harn"),
207    },
208    StdlibSource {
209        module: "lifecycle/pool",
210        source: include_str!("stdlib/lifecycle/pool.harn"),
211    },
212    StdlibSource {
213        module: "lifecycle/combinators",
214        source: include_str!("stdlib/lifecycle/combinators.harn"),
215    },
216    StdlibSource {
217        module: "lifecycle/on_budget",
218        source: include_str!("stdlib/lifecycle/on_budget.harn"),
219    },
220    StdlibSource {
221        module: "agent/prompts",
222        source: include_str!("stdlib/agent/prompts.harn"),
223    },
224    StdlibSource {
225        module: "llm/media",
226        source: include_str!("stdlib/llm/media.harn"),
227    },
228    StdlibSource {
229        module: "llm/options",
230        source: include_str!("stdlib/llm/options.harn"),
231    },
232    StdlibSource {
233        module: "llm/catalog",
234        source: include_str!("stdlib/llm/catalog.harn"),
235    },
236    StdlibSource {
237        module: "llm/safe",
238        source: include_str!("stdlib/llm/safe.harn"),
239    },
240    StdlibSource {
241        module: "llm/budget",
242        source: include_str!("stdlib/llm/budget.harn"),
243    },
244    StdlibSource {
245        module: "llm/economics",
246        source: include_str!("stdlib/llm/economics.harn"),
247    },
248    StdlibSource {
249        module: "llm/prompts",
250        source: include_str!("stdlib/llm/prompts.harn"),
251    },
252    StdlibSource {
253        module: "llm/defaults",
254        source: include_str!("stdlib/llm/defaults.harn"),
255    },
256    StdlibSource {
257        module: "llm/handlers",
258        source: include_str!("stdlib/llm/handlers.harn"),
259    },
260    StdlibSource {
261        module: "llm/tool_telemetry",
262        source: include_str!("stdlib/llm/tool_telemetry.harn"),
263    },
264    StdlibSource {
265        module: "llm/tool_middleware",
266        source: include_str!("stdlib/llm/tool_middleware.harn"),
267    },
268    StdlibSource {
269        module: "llm/tool_binder",
270        source: include_str!("stdlib/llm/tool_binder.harn"),
271    },
272    StdlibSource {
273        module: "llm/refine",
274        source: include_str!("stdlib/llm/refine.harn"),
275    },
276    StdlibSource {
277        module: "llm/ensemble",
278        source: include_str!("stdlib/llm/ensemble.harn"),
279    },
280    StdlibSource {
281        module: "llm/rerank",
282        source: include_str!("stdlib/llm/rerank.harn"),
283    },
284    StdlibSource {
285        module: "agent/reasoning",
286        source: include_str!("stdlib/agent/reasoning.harn"),
287    },
288    StdlibSource {
289        module: "agent/options",
290        source: include_str!("stdlib/agent/options.harn"),
291    },
292    StdlibSource {
293        module: "llm/judge",
294        source: include_str!("stdlib/llm/judge.harn"),
295    },
296    StdlibSource {
297        module: "llm/optimize",
298        source: include_str!("stdlib/llm/optimize.harn"),
299    },
300    StdlibSource {
301        module: "agent/events",
302        source: include_str!("stdlib/agent/events.harn"),
303    },
304    StdlibSource {
305        module: "agent/primitives",
306        source: include_str!("stdlib/agent/primitives.harn"),
307    },
308    StdlibSource {
309        module: "agent/progress",
310        source: include_str!("stdlib/agent/progress.harn"),
311    },
312    StdlibSource {
313        module: "agent/loop",
314        source: include_str!("stdlib/agent/loop.harn"),
315    },
316    StdlibSource {
317        module: "agent/chat",
318        source: include_str!("stdlib/agent/chat.harn"),
319    },
320    StdlibSource {
321        module: "agent/user",
322        source: include_str!("stdlib/agent/user.harn"),
323    },
324    StdlibSource {
325        module: "agent/tool_search",
326        source: include_str!("stdlib/agent/tool_search.harn"),
327    },
328    StdlibSource {
329        module: "agent/turn",
330        source: include_str!("stdlib/agent/turn.harn"),
331    },
332    StdlibSource {
333        module: "agent/workers",
334        source: include_str!("stdlib/agent/workers.harn"),
335    },
336    StdlibSource {
337        module: "agent/resume_by",
338        source: include_str!("stdlib/agent/resume_by.harn"),
339    },
340    StdlibSource {
341        module: "agent/state",
342        source: include_str!("stdlib/agent/state.harn"),
343    },
344    StdlibSource {
345        module: "agent/skills",
346        source: include_str!("stdlib/agent/skills.harn"),
347    },
348    StdlibSource {
349        module: "agent/autocompact",
350        source: include_str!("stdlib/agent/autocompact.harn"),
351    },
352    StdlibSource {
353        module: "agent/mcp",
354        source: include_str!("stdlib/agent/mcp.harn"),
355    },
356    StdlibSource {
357        module: "agent/host_tools",
358        source: include_str!("stdlib/agent/host_tools.harn"),
359    },
360    StdlibSource {
361        module: "agent/budget",
362        source: include_str!("stdlib/agent/budget.harn"),
363    },
364    StdlibSource {
365        module: "agent/daemon",
366        source: include_str!("stdlib/agent/daemon.harn"),
367    },
368    StdlibSource {
369        module: "agent/preflight",
370        source: include_str!("stdlib/agent/preflight.harn"),
371    },
372    StdlibSource {
373        module: "agent/postturn",
374        source: include_str!("stdlib/agent/postturn.harn"),
375    },
376    StdlibSource {
377        module: "agent/judge",
378        source: include_str!("stdlib/agent/judge.harn"),
379    },
380    StdlibSource {
381        module: "agent/presets",
382        source: include_str!("stdlib/agent/presets.harn"),
383    },
384    StdlibSource {
385        module: "agent_state",
386        source: include_str!("stdlib/stdlib_agent_state.harn"),
387    },
388    StdlibSource {
389        module: "memory",
390        source: include_str!("stdlib/stdlib_memory.harn"),
391    },
392    StdlibSource {
393        module: "postgres",
394        source: include_str!("stdlib/stdlib_postgres.harn"),
395    },
396    StdlibSource {
397        module: "checkpoint",
398        source: include_str!("stdlib/stdlib_checkpoint.harn"),
399    },
400    StdlibSource {
401        module: "host",
402        source: include_str!("stdlib/stdlib_host.harn"),
403    },
404    StdlibSource {
405        module: "git",
406        source: include_str!("stdlib/stdlib_git.harn"),
407    },
408    StdlibSource {
409        module: "hitl",
410        source: include_str!("stdlib/stdlib_hitl.harn"),
411    },
412    StdlibSource {
413        module: "trust",
414        source: include_str!("stdlib/stdlib_trust.harn"),
415    },
416    StdlibSource {
417        module: "corrections",
418        source: include_str!("stdlib/stdlib_corrections.harn"),
419    },
420    StdlibSource {
421        module: "plan",
422        source: include_str!("stdlib/stdlib_plan.harn"),
423    },
424    StdlibSource {
425        module: "waitpoints",
426        source: include_str!("stdlib/stdlib_waitpoints.harn"),
427    },
428    StdlibSource {
429        module: "waitpoint",
430        source: include_str!("stdlib/stdlib_waitpoint.harn"),
431    },
432    StdlibSource {
433        module: "monitors",
434        source: include_str!("stdlib/stdlib_monitors.harn"),
435    },
436    StdlibSource {
437        module: "worktree",
438        source: include_str!("stdlib/stdlib_worktree.harn"),
439    },
440    StdlibSource {
441        module: "acp",
442        source: include_str!("stdlib/stdlib_acp.harn"),
443    },
444    StdlibSource {
445        module: "triggers",
446        source: include_str!("stdlib/stdlib_triggers.harn"),
447    },
448    StdlibSource {
449        module: "triage",
450        source: include_str!("stdlib/stdlib_triage.harn"),
451    },
452    StdlibSource {
453        module: "dashboard/jobs",
454        source: include_str!("stdlib/dashboard/jobs.harn"),
455    },
456    StdlibSource {
457        module: "ui_resource",
458        source: include_str!("stdlib/stdlib_ui_resource.harn"),
459    },
460    StdlibSource {
461        module: "handoffs",
462        source: include_str!("stdlib/stdlib_handoffs.harn"),
463    },
464    StdlibSource {
465        module: "lifecycle",
466        source: include_str!("stdlib/stdlib_lifecycle.harn"),
467    },
468    StdlibSource {
469        module: "tool_hooks_catalogues",
470        source: include_str!("stdlib/stdlib_tool_hooks_catalogues.harn"),
471    },
472    StdlibSource {
473        module: "tool_hooks",
474        source: include_str!("stdlib/stdlib_tool_hooks.harn"),
475    },
476    StdlibSource {
477        module: "channel_guardrails",
478        source: include_str!("stdlib/stdlib_channel_guardrails.harn"),
479    },
480    StdlibSource {
481        module: "personas/prelude",
482        source: include_str!("stdlib/stdlib_personas_prelude.harn"),
483    },
484    StdlibSource {
485        module: "personas/bulletins",
486        source: include_str!("stdlib/stdlib_personas_bulletins.harn"),
487    },
488    StdlibSource {
489        module: "connectors/shared",
490        source: include_str!("stdlib/stdlib_connectors_shared.harn"),
491    },
492    StdlibSource {
493        module: "oauth/providers",
494        source: include_str!("stdlib/oauth/providers.harn"),
495    },
496    StdlibSource {
497        module: "oauth/storage",
498        source: include_str!("stdlib/oauth/storage.harn"),
499    },
500    StdlibSource {
501        module: "oauth/client",
502        source: include_str!("stdlib/oauth/client.harn"),
503    },
504    StdlibSource {
505        module: "oauth/device_flow",
506        source: include_str!("stdlib/oauth/device_flow.harn"),
507    },
508    StdlibSource {
509        module: "oauth/redaction",
510        source: include_str!("stdlib/oauth/redaction.harn"),
511    },
512    StdlibSource {
513        module: "oauth/dynamic_registration",
514        source: include_str!("stdlib/oauth/dynamic_registration.harn"),
515    },
516    StdlibSource {
517        module: "connectors/github",
518        source: include_str!("stdlib/stdlib_connectors_github.harn"),
519    },
520    StdlibSource {
521        module: "connectors/linear",
522        source: include_str!("stdlib/stdlib_connectors_linear.harn"),
523    },
524    StdlibSource {
525        module: "connectors/notion",
526        source: include_str!("stdlib/stdlib_connectors_notion.harn"),
527    },
528    StdlibSource {
529        module: "connectors/slack",
530        source: include_str!("stdlib/stdlib_connectors_slack.harn"),
531    },
532    StdlibSource {
533        module: "workflow/prompts",
534        source: include_str!("stdlib/workflow/prompts.harn"),
535    },
536    StdlibSource {
537        module: "workflow/context",
538        source: include_str!("stdlib/workflow/context.harn"),
539    },
540    StdlibSource {
541        module: "workflow/options",
542        source: include_str!("stdlib/workflow/options.harn"),
543    },
544    StdlibSource {
545        module: "workflow/checkpoints",
546        source: include_str!("stdlib/workflow/checkpoints.harn"),
547    },
548    StdlibSource {
549        module: "workflow/stage",
550        source: include_str!("stdlib/workflow/stage.harn"),
551    },
552    StdlibSource {
553        module: "workflow/map",
554        source: include_str!("stdlib/workflow/map.harn"),
555    },
556    StdlibSource {
557        module: "workflow/schedule",
558        source: include_str!("stdlib/workflow/schedule.harn"),
559    },
560    StdlibSource {
561        module: "workflow/execute",
562        source: include_str!("stdlib/workflow/execute.harn"),
563    },
564];
565
566pub const STDLIB_PROMPT_ASSETS: &[StdlibPromptAsset] = &[
567    StdlibPromptAsset {
568        path: "agent/prompts/tool_contract_text.harn.prompt",
569        source: include_str!("stdlib/agent/prompts/tool_contract_text.harn.prompt"),
570    },
571    StdlibPromptAsset {
572        path: "agent/prompts/tool_contract_native.harn.prompt",
573        source: include_str!("stdlib/agent/prompts/tool_contract_native.harn.prompt"),
574    },
575    StdlibPromptAsset {
576        path: "agent/prompts/tool_contract_text_response_protocol.harn.prompt",
577        source: include_str!(
578            "stdlib/agent/prompts/tool_contract_text_response_protocol.harn.prompt"
579        ),
580    },
581    StdlibPromptAsset {
582        path: "agent/prompts/tool_contract_action_native.harn.prompt",
583        source: include_str!("stdlib/agent/prompts/tool_contract_action_native.harn.prompt"),
584    },
585    StdlibPromptAsset {
586        path: "agent/prompts/tool_contract_action_text.harn.prompt",
587        source: include_str!("stdlib/agent/prompts/tool_contract_action_text.harn.prompt"),
588    },
589    StdlibPromptAsset {
590        path: "agent/prompts/tool_contract_task_ledger.harn.prompt",
591        source: include_str!("stdlib/agent/prompts/tool_contract_task_ledger.harn.prompt"),
592    },
593    StdlibPromptAsset {
594        path: "agent/prompts/tool_contract_deferred_tools.harn.prompt",
595        source: include_str!("stdlib/agent/prompts/tool_contract_deferred_tools.harn.prompt"),
596    },
597    StdlibPromptAsset {
598        path: "agent/prompts/deferred_tool_listing.harn.prompt",
599        source: include_str!("stdlib/agent/prompts/deferred_tool_listing.harn.prompt"),
600    },
601    StdlibPromptAsset {
602        path: "agent/prompts/action_turn_nudge.harn.prompt",
603        source: include_str!("stdlib/agent/prompts/action_turn_nudge.harn.prompt"),
604    },
605    StdlibPromptAsset {
606        path: "agent/prompts/agent_turn_preamble.harn.prompt",
607        source: include_str!("stdlib/agent/prompts/agent_turn_preamble.harn.prompt"),
608    },
609    StdlibPromptAsset {
610        path: "agent/prompts/default_nudge.harn.prompt",
611        source: include_str!("stdlib/agent/prompts/default_nudge.harn.prompt"),
612    },
613    StdlibPromptAsset {
614        path: "agent/prompts/agentic_user_system.harn.prompt",
615        source: include_str!("stdlib/agent/prompts/agentic_user_system.harn.prompt"),
616    },
617    StdlibPromptAsset {
618        path: "agent/prompts/agentic_user_user.harn.prompt",
619        source: include_str!("stdlib/agent/prompts/agentic_user_user.harn.prompt"),
620    },
621    StdlibPromptAsset {
622        path: "agent/prompts/loop_until_done_system.harn.prompt",
623        source: include_str!("stdlib/agent/prompts/loop_until_done_system.harn.prompt"),
624    },
625    StdlibPromptAsset {
626        path: "agent/prompts/completion_judge_default.harn.prompt",
627        source: include_str!("stdlib/agent/prompts/completion_judge_default.harn.prompt"),
628    },
629    StdlibPromptAsset {
630        path: "agent/prompts/completion_judge_feedback_fallback.harn.prompt",
631        source: include_str!("stdlib/agent/prompts/completion_judge_feedback_fallback.harn.prompt"),
632    },
633    StdlibPromptAsset {
634        path: "agent/prompts/completion_judge_user.harn.prompt",
635        source: include_str!("stdlib/agent/prompts/completion_judge_user.harn.prompt"),
636    },
637    StdlibPromptAsset {
638        path: "agent/prompts/parse_guidance.harn.prompt",
639        source: include_str!("stdlib/agent/prompts/parse_guidance.harn.prompt"),
640    },
641    StdlibPromptAsset {
642        path: "agent/prompts/protocol_violation_feedback.harn.prompt",
643        source: include_str!("stdlib/agent/prompts/protocol_violation_feedback.harn.prompt"),
644    },
645    StdlibPromptAsset {
646        path: "agent/prompts/native_tool_contract_feedback.harn.prompt",
647        source: include_str!("stdlib/agent/prompts/native_tool_contract_feedback.harn.prompt"),
648    },
649    StdlibPromptAsset {
650        path: "agent/prompts/verification_gate_feedback.harn.prompt",
651        source: include_str!("stdlib/agent/prompts/verification_gate_feedback.harn.prompt"),
652    },
653    StdlibPromptAsset {
654        path: "agent/prompts/action_required_feedback.harn.prompt",
655        source: include_str!("stdlib/agent/prompts/action_required_feedback.harn.prompt"),
656    },
657    StdlibPromptAsset {
658        path: "agent/prompts/daemon_watch_feedback.harn.prompt",
659        source: include_str!("stdlib/agent/prompts/daemon_watch_feedback.harn.prompt"),
660    },
661    StdlibPromptAsset {
662        path: "agent/prompts/daemon_timer_feedback.harn.prompt",
663        source: include_str!("stdlib/agent/prompts/daemon_timer_feedback.harn.prompt"),
664    },
665    StdlibPromptAsset {
666        path: "llm/prompts/completion_fallback_system.harn.prompt",
667        source: include_str!("stdlib/llm/prompts/completion_fallback_system.harn.prompt"),
668    },
669    StdlibPromptAsset {
670        path: "llm/prompts/completion_fallback_user.harn.prompt",
671        source: include_str!("stdlib/llm/prompts/completion_fallback_user.harn.prompt"),
672    },
673    StdlibPromptAsset {
674        path: "llm/prompts/transcript_summarize_user.harn.prompt",
675        source: include_str!("stdlib/llm/prompts/transcript_summarize_user.harn.prompt"),
676    },
677    StdlibPromptAsset {
678        path: "llm/prompts/structural_chain_of_draft.harn.prompt",
679        source: include_str!("stdlib/llm/prompts/structural_chain_of_draft.harn.prompt"),
680    },
681    StdlibPromptAsset {
682        path: "llm/prompts/schema_recover_repair.harn.prompt",
683        source: include_str!("stdlib/llm/prompts/schema_recover_repair.harn.prompt"),
684    },
685    StdlibPromptAsset {
686        path: "llm/prompts/structured_envelope_schema_contract.harn.prompt",
687        source: include_str!("stdlib/llm/prompts/structured_envelope_schema_contract.harn.prompt"),
688    },
689    StdlibPromptAsset {
690        path: "llm/prompts/structured_envelope_repair.harn.prompt",
691        source: include_str!("stdlib/llm/prompts/structured_envelope_repair.harn.prompt"),
692    },
693    StdlibPromptAsset {
694        path: "llm/prompts/pairwise_rerank_user.harn.prompt",
695        source: include_str!("stdlib/llm/prompts/pairwise_rerank_user.harn.prompt"),
696    },
697    StdlibPromptAsset {
698        path: "llm/prompts/tool_binder_user.harn.prompt",
699        source: include_str!("stdlib/llm/prompts/tool_binder_user.harn.prompt"),
700    },
701    StdlibPromptAsset {
702        path: "workflow/prompts/stage.harn.prompt",
703        source: include_str!("stdlib/workflow/prompts/stage.harn.prompt"),
704    },
705    StdlibPromptAsset {
706        path: "workflow/prompts/verification_context_intro.harn.prompt",
707        source: include_str!("stdlib/workflow/prompts/verification_context_intro.harn.prompt"),
708    },
709    StdlibPromptAsset {
710        path: "orchestration/prompts/compaction_summary.harn.prompt",
711        source: include_str!("stdlib/orchestration/prompts/compaction_summary.harn.prompt"),
712    },
713];
714
715pub fn get_stdlib_source(module: &str) -> Option<&'static str> {
716    STDLIB_SOURCES
717        .iter()
718        .find_map(|entry| (entry.module == module).then_some(entry.source))
719}
720
721pub fn get_stdlib_prompt_asset(path: &str) -> Option<&'static str> {
722    let path = path.strip_prefix("std/").unwrap_or(path);
723    STDLIB_PROMPT_ASSETS
724        .iter()
725        .find_map(|entry| (entry.path == path).then_some(entry.source))
726}
727
728pub fn public_functions_for_module(module: &str) -> Vec<StdlibPublicFunction> {
729    let Some(source) = get_stdlib_source(module) else {
730        return Vec::new();
731    };
732    public_functions_from_source(source)
733}
734
735pub fn entrypoint_modules() -> Vec<StdlibEntrypointModule> {
736    STDLIB_SOURCES
737        .iter()
738        .filter_map(|entry| {
739            entrypoint_category_from_source(entry.source).map(|category| StdlibEntrypointModule {
740                import_path: format!("std/{}", entry.module),
741                category,
742            })
743        })
744        .collect()
745}
746
747fn entrypoint_category_from_source(source: &str) -> Option<String> {
748    for line in source.lines() {
749        let line = line.trim();
750        if line.is_empty() {
751            continue;
752        }
753        if let Some(category) = line.strip_prefix("// @harn-entrypoint-category ") {
754            let category = category.trim();
755            return (!category.is_empty()).then(|| category.to_string());
756        }
757        if !line.starts_with("//") {
758            return None;
759        }
760    }
761    None
762}
763
764fn public_functions_from_source(source: &str) -> Vec<StdlibPublicFunction> {
765    let mut out = Vec::new();
766    let mut doc: Option<String> = None;
767    let lines = source.lines().collect::<Vec<_>>();
768    let mut index = 0usize;
769    while index < lines.len() {
770        let line = lines[index].trim();
771        if line.starts_with("/**") {
772            let (parsed, next) = parse_harndoc(&lines, index);
773            doc = parsed;
774            index = next;
775            continue;
776        }
777        if line.starts_with("pub fn ") {
778            let (signature_line, next) = collect_public_function_signature(&lines, index);
779            if let Some(function) = parse_public_function_line(&signature_line, doc.take()) {
780                out.push(function);
781                index = next;
782                continue;
783            }
784        }
785        if let Some(function) = parse_public_function_line(line, doc.take()) {
786            out.push(function);
787        } else if !line.is_empty() && !line.starts_with("//") {
788            doc = None;
789        }
790        index += 1;
791    }
792    out
793}
794
795fn collect_public_function_signature(lines: &[&str], start: usize) -> (String, usize) {
796    let mut parts = Vec::new();
797    let mut index = start;
798    while index < lines.len() {
799        parts.push(lines[index].trim().to_string());
800        let candidate = parts.join(" ");
801        if public_function_signature_complete(&candidate) {
802            return (candidate, index + 1);
803        }
804        index += 1;
805    }
806    (parts.join(" "), index)
807}
808
809fn public_function_signature_complete(line: &str) -> bool {
810    let Some(rest) = line.strip_prefix("pub fn ") else {
811        return false;
812    };
813    let Some(name_end) = rest.find('(') else {
814        return false;
815    };
816    matching_paren_len(&rest[name_end + 1..]).is_some()
817}
818
819fn parse_harndoc(lines: &[&str], start: usize) -> (Option<String>, usize) {
820    let mut parts = Vec::new();
821    let mut index = start;
822    while index < lines.len() {
823        let mut line = lines[index].trim();
824        if index == start {
825            line = line.trim_start_matches("/**").trim();
826        }
827        let done = line.ends_with("*/");
828        line = line.trim_end_matches("*/").trim();
829        line = line.trim_start_matches('*').trim();
830        if !line.is_empty() {
831            parts.push(line.to_string());
832        }
833        index += 1;
834        if done {
835            break;
836        }
837    }
838    let text = parts.join("\n").trim().to_string();
839    ((!text.is_empty()).then_some(text), index)
840}
841
842fn parse_public_function_line(line: &str, doc: Option<String>) -> Option<StdlibPublicFunction> {
843    let rest = line.strip_prefix("pub fn ")?.trim();
844    let name_end = rest.find('(')?;
845    let name = rest[..name_end].trim();
846    if name.is_empty() {
847        return None;
848    }
849    let params_start = name_end + 1;
850    let params_len = matching_paren_len(&rest[params_start..])?;
851    let params = &rest[params_start..params_start + params_len];
852    let after = rest[params_start + params_len + 1..].trim();
853    let return_type = after
854        .strip_prefix("->")
855        .and_then(|tail| tail.split('{').next())
856        .map(str::trim)
857        .filter(|value| !value.is_empty());
858    let signature = match return_type {
859        Some(ret) => format!("{name}({params}) -> {ret}"),
860        None => format!("{name}({params})"),
861    };
862    let param_parts = split_top_level_params(params);
863    let total_params = param_parts
864        .iter()
865        .filter(|param| !param.trim().is_empty())
866        .count();
867    let variadic = param_parts
868        .iter()
869        .any(|param| param.trim_start().starts_with("..."));
870    let required_params = param_parts
871        .iter()
872        .filter(|param| {
873            let param = param.trim();
874            !param.is_empty() && !param.contains('=') && !param.starts_with("...")
875        })
876        .count();
877    Some(StdlibPublicFunction {
878        name: name.to_string(),
879        signature,
880        required_params,
881        total_params,
882        variadic,
883        doc,
884    })
885}
886
887fn matching_paren_len(input: &str) -> Option<usize> {
888    let mut depth = 1usize;
889    for (offset, ch) in input.char_indices() {
890        match ch {
891            '(' | '[' | '{' => depth += 1,
892            ')' => {
893                depth = depth.saturating_sub(1);
894                if depth == 0 {
895                    return Some(offset);
896                }
897            }
898            ']' | '}' => depth = depth.saturating_sub(1),
899            _ => {}
900        }
901    }
902    None
903}
904
905fn split_top_level_params(params: &str) -> Vec<&str> {
906    let mut out = Vec::new();
907    let mut depth = 0isize;
908    let mut start = 0usize;
909    for (offset, ch) in params.char_indices() {
910        match ch {
911            '(' | '[' | '{' => depth += 1,
912            ')' | ']' | '}' => depth -= 1,
913            ',' if depth == 0 => {
914                out.push(&params[start..offset]);
915                start = offset + 1;
916            }
917            _ => {}
918        }
919    }
920    out.push(&params[start..]);
921    out
922}
923
924#[cfg(test)]
925mod tests {
926    use std::collections::BTreeSet;
927
928    use super::{
929        entrypoint_modules, get_stdlib_prompt_asset, get_stdlib_source,
930        public_functions_for_module, STDLIB_PROMPT_ASSETS, STDLIB_SOURCES,
931    };
932
933    #[test]
934    fn stdlib_sources_are_non_empty() {
935        for entry in STDLIB_SOURCES {
936            assert!(
937                !entry.source.trim().is_empty(),
938                "{} should have non-empty source",
939                entry.module
940            );
941        }
942    }
943
944    #[test]
945    fn stdlib_source_names_are_unique() {
946        let mut names = BTreeSet::new();
947        for entry in STDLIB_SOURCES {
948            assert!(names.insert(entry.module), "duplicate {}", entry.module);
949        }
950    }
951
952    #[test]
953    fn stdlib_prompt_assets_are_non_empty() {
954        for entry in STDLIB_PROMPT_ASSETS {
955            assert!(
956                !entry.source.trim().is_empty(),
957                "{} should have non-empty prompt asset source",
958                entry.path
959            );
960        }
961    }
962
963    #[test]
964    fn stdlib_prompt_asset_paths_are_unique() {
965        let mut paths = BTreeSet::new();
966        for entry in STDLIB_PROMPT_ASSETS {
967            assert!(paths.insert(entry.path), "duplicate {}", entry.path);
968        }
969    }
970
971    #[test]
972    fn key_stdlib_modules_resolve() {
973        for module in [
974            "context",
975            "context/maintenance",
976            "edit",
977            "artifact/web",
978            "command",
979            "waitpoint",
980            "llm/handlers",
981            "llm/tool_middleware",
982            "llm/tool_binder",
983            "llm/ensemble",
984            "llm/rerank",
985            "personas/prelude",
986            "personas/bulletins",
987            "agent/host_tools",
988            "agent/user",
989            "llm/optimize",
990            "llm/judge",
991            "llm/refine",
992            "connectors/shared",
993            "connectors/github",
994            "connectors/linear",
995            "connectors/notion",
996            "connectors/slack",
997            "triage",
998            "dashboard/jobs",
999            "ui_resource",
1000        ] {
1001            assert!(
1002                get_stdlib_source(module).is_some(),
1003                "std/{module} should resolve"
1004            );
1005        }
1006    }
1007
1008    #[test]
1009    fn key_stdlib_prompt_assets_resolve() {
1010        for path in [
1011            "std/agent/prompts/tool_contract_text.harn.prompt",
1012            "std/agent/prompts/action_turn_nudge.harn.prompt",
1013            "std/agent/prompts/completion_judge_default.harn.prompt",
1014            "std/workflow/prompts/stage.harn.prompt",
1015            "std/orchestration/prompts/compaction_summary.harn.prompt",
1016        ] {
1017            assert!(
1018                get_stdlib_prompt_asset(path).is_some(),
1019                "{path} should resolve"
1020            );
1021        }
1022    }
1023
1024    #[test]
1025    fn public_function_catalog_derives_signatures_from_harn_source() {
1026        let exports = public_functions_for_module("workflow/execute");
1027        assert_eq!(exports.len(), 1);
1028        assert_eq!(exports[0].name, "workflow_execute");
1029        assert_eq!(
1030            exports[0].signature,
1031            "workflow_execute(task, graph, artifacts = nil, options = nil)"
1032        );
1033        assert_eq!(exports[0].required_params, 2);
1034        assert_eq!(exports[0].total_params, 4);
1035    }
1036
1037    #[test]
1038    fn command_stdlib_module_exports_step_helpers() {
1039        let exports = public_functions_for_module("command")
1040            .into_iter()
1041            .map(|function| function.name)
1042            .collect::<BTreeSet<_>>();
1043        for name in [
1044            "command_run",
1045            "command_output_tail",
1046            "command_step",
1047            "command_steps_append",
1048            "command_last_failed_step",
1049            "command_step_ref",
1050        ] {
1051            assert!(exports.contains(name), "std/command should export {name}");
1052        }
1053    }
1054
1055    #[test]
1056    fn async_stdlib_exports_predicate_backoff_name_only() {
1057        let exports = public_functions_for_module("async")
1058            .into_iter()
1059            .map(|function| function.name)
1060            .collect::<BTreeSet<_>>();
1061        assert!(
1062            exports.contains("retry_predicate_with_backoff"),
1063            "std/async should export retry_predicate_with_backoff"
1064        );
1065        assert!(
1066            !exports.contains("retry_with_backoff"),
1067            "std/async should not retain the old retry_with_backoff export"
1068        );
1069    }
1070
1071    #[test]
1072    fn signal_stdlib_module_exports_interrupt_helpers() {
1073        let exports = public_functions_for_module("signal")
1074            .into_iter()
1075            .map(|function| function.name)
1076            .collect::<BTreeSet<_>>();
1077        for name in [
1078            "on_interrupt",
1079            "off_interrupt",
1080            "interrupted",
1081            "with_interrupt",
1082        ] {
1083            assert!(exports.contains(name), "std/signal should export {name}");
1084        }
1085    }
1086
1087    #[test]
1088    fn git_stdlib_module_exports_local_wrappers() {
1089        let exports = public_functions_for_module("git")
1090            .into_iter()
1091            .map(|function| function.name)
1092            .collect::<BTreeSet<_>>();
1093        for name in [
1094            "git_run",
1095            "git_status",
1096            "git_current_branch",
1097            "git_log",
1098            "git_switch",
1099            "git_pull_ff_only",
1100            "git_find_tool",
1101            "git_run_tool",
1102            "git_tools",
1103            "git_toolbox_tools",
1104        ] {
1105            assert!(exports.contains(name), "std/git should export {name}");
1106        }
1107    }
1108
1109    #[test]
1110    fn agent_workers_exports_suspend_resume_wrappers() {
1111        let exports = public_functions_for_module("agent/workers");
1112        let suspend = exports
1113            .iter()
1114            .find(|function| function.name == "suspend_agent")
1115            .expect("std/agent/workers should export suspend_agent");
1116        assert_eq!(
1117            suspend.signature,
1118            "suspend_agent(worker, reason = \"\", options = nil)"
1119        );
1120        assert_eq!(suspend.required_params, 1);
1121        assert_eq!(suspend.total_params, 3);
1122
1123        let resume = exports
1124            .iter()
1125            .find(|function| function.name == "resume_agent")
1126            .expect("std/agent/workers should export resume_agent");
1127        assert_eq!(
1128            resume.signature,
1129            "resume_agent(worker_or_snapshot, resume_input = nil, continue_transcript = true)"
1130        );
1131        assert_eq!(resume.required_params, 1);
1132        assert_eq!(resume.total_params, 3);
1133
1134        let parse_resume = exports
1135            .iter()
1136            .find(|function| function.name == "parse_resume_conditions")
1137            .expect("std/agent/workers should export parse_resume_conditions");
1138        assert_eq!(
1139            parse_resume.signature,
1140            "parse_resume_conditions(conditions = nil) -> ResumeConditions?"
1141        );
1142        assert_eq!(parse_resume.required_params, 0);
1143        assert_eq!(parse_resume.total_params, 1);
1144
1145        let lifecycle = exports
1146            .iter()
1147            .find(|function| function.name == "agent_lifecycle_tools")
1148            .expect("std/agent/workers should export agent_lifecycle_tools");
1149        assert_eq!(
1150            lifecycle.signature,
1151            "agent_lifecycle_tools(registry = nil, options = nil)"
1152        );
1153        assert_eq!(lifecycle.required_params, 0);
1154        assert_eq!(lifecycle.total_params, 2);
1155    }
1156
1157    #[test]
1158    fn tui_stdlib_module_exports_terminal_helpers() {
1159        let exports = public_functions_for_module("tui")
1160            .into_iter()
1161            .map(|function| function.name)
1162            .collect::<BTreeSet<_>>();
1163        for name in ["page", "terminal_width", "rule", "clear", "select_from"] {
1164            assert!(exports.contains(name), "std/tui should export {name}");
1165        }
1166    }
1167
1168    #[test]
1169    fn harn_entrypoint_catalog_is_declared_by_stdlib_sources() {
1170        let modules = entrypoint_modules();
1171        let entries = modules
1172            .iter()
1173            .map(|module| (module.import_path.as_str(), module.category.as_str()))
1174            .collect::<BTreeSet<_>>();
1175        for entry in [
1176            ("std/agent/loop", "agent.stdlib"),
1177            ("std/agent/turn", "agent.stdlib"),
1178            ("std/agent/primitives", "agent.stdlib"),
1179            ("std/workflow/execute", "workflow.stdlib"),
1180        ] {
1181            assert!(entries.contains(&entry), "{entry:?} should be declared");
1182        }
1183    }
1184}