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