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