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
19macro_rules! embedded_catalog {
20 ($entry:ident, $key:ident, [$($name:literal => $path:literal),* $(,)?]) => {
21 &[
22 $($entry {
23 $key: $name,
24 source: include_str!($path),
25 },)*
26 ]
27 };
28}
29
30#[derive(Debug, Clone, PartialEq, Eq)]
31pub struct StdlibPublicFunction {
32 pub name: String,
33 pub signature: String,
34 pub required_params: usize,
35 pub total_params: usize,
36 pub variadic: bool,
37 pub doc: Option<String>,
38}
39
40#[derive(Debug, Clone, PartialEq, Eq)]
41pub struct StdlibEntrypointModule {
42 pub import_path: String,
43 pub category: String,
44}
45
46pub const STDLIB_SOURCES: &[StdlibSource] = embedded_catalog!(StdlibSource, module, [
47 "text" => "stdlib/stdlib_text.harn",
48 "semver" => "stdlib/stdlib_semver.harn",
49 "changelog" => "stdlib/stdlib_changelog.harn",
50 "ansi" => "stdlib/stdlib_ansi.harn",
51 "table" => "stdlib/stdlib_table.harn",
52 "diff" => "stdlib/stdlib_diff.harn",
53 "edit" => "stdlib/stdlib_edit.harn",
54 "edit/capabilities" => "stdlib/edit/capabilities.harn",
55 "edit/internal" => "stdlib/edit/internal.harn",
56 "edit/patch" => "stdlib/edit/patch.harn",
57 "edit/safe_patch" => "stdlib/edit/safe_patch.harn",
58 "edit/fast_apply" => "stdlib/edit/fast_apply.harn",
59 "ast" => "stdlib/stdlib_ast.harn",
60 "rules" => "stdlib/stdlib_rules.harn",
61 "lint" => "stdlib/stdlib_lint.harn",
62 "artifact/web" => "stdlib/artifact/web.harn",
63 "collections" => "stdlib/stdlib_collections.harn",
64 "math" => "stdlib/stdlib_math.harn",
65 "slug" => "stdlib/stdlib_slug.harn",
66 "path" => "stdlib/stdlib_path.harn",
67 "fs" => "stdlib/stdlib_fs.harn",
68 "run_artifacts" => "stdlib/stdlib_run_artifacts.harn",
69 "os" => "stdlib/stdlib_os.harn",
70 "json" => "stdlib/stdlib_json.harn",
71 "json/stream" => "stdlib/stdlib_json_stream.harn",
72 "xml" => "stdlib/stdlib_xml.harn",
73 "cache" => "stdlib/stdlib_cache.harn",
74 "observability" => "stdlib/stdlib_observability.harn",
75 "timing" => "stdlib/stdlib_timing.harn",
76 "verification" => "stdlib/stdlib_verification.harn",
77 "tools" => "stdlib/stdlib_tools.harn",
78 "composition" => "stdlib/stdlib_composition.harn",
79 "web" => "stdlib/stdlib_web.harn",
80 "graphql" => "stdlib/stdlib_graphql.harn",
81 "code_librarian" => "stdlib/stdlib_code_librarian.harn",
82 "schema" => "stdlib/stdlib_schema.harn",
83 "identity" => "stdlib/stdlib_identity.harn",
84 "disclosure" => "stdlib/stdlib_disclosure.harn",
85 "testing" => "stdlib/stdlib_testing.harn",
86 "files" => "stdlib/stdlib_files.harn",
87 "document" => "stdlib/stdlib_document.harn",
88 "mcp" => "stdlib/stdlib_mcp.harn",
89 "vision" => "stdlib/stdlib_vision.harn",
90 "context" => "stdlib/stdlib_context.harn",
91 "context/maintenance" => "stdlib/context/maintenance.harn",
92 "context/eval" => "stdlib/context/eval.harn",
93 "eval/stats" => "stdlib/stdlib_eval_stats.harn",
94 "eval/agreement" => "stdlib/stdlib_eval_agreement.harn",
95 "runtime" => "stdlib/stdlib_runtime.harn",
96 "io" => "stdlib/stdlib_io.harn",
97 "net" => "stdlib/stdlib_net.harn",
98 "command" => "stdlib/stdlib_command.harn",
99 "verification_types" => "stdlib/verification_types.harn",
100 "verification_core" => "stdlib/verification_core.harn",
101 "verification_targets" => "stdlib/verification_targets.harn",
102 "verification_ladder" => "stdlib/verification_ladder.harn",
103 "verification_public" => "stdlib/verification_public.harn",
104 "signal" => "stdlib/stdlib_signal.harn",
105 "net_policy" => "stdlib/stdlib_net_policy.harn",
106 "review" => "stdlib/stdlib_review.harn",
107 "experiments" => "stdlib/stdlib_experiments.harn",
108 "project" => "stdlib/stdlib_project.harn",
109 "prompt_library" => "stdlib/stdlib_prompt_library.harn",
110 "async" => "stdlib/stdlib_async.harn",
111 "poll" => "stdlib/stdlib_poll.harn",
112 "coerce" => "stdlib/stdlib_coerce.harn",
113 "settled" => "stdlib/stdlib_settled.harn",
114 "cli" => "stdlib/stdlib_cli.harn",
115 "cli/argparse" => "stdlib/cli/argparse.harn",
116 "cli/render" => "stdlib/cli/render.harn",
117 "cli/models/batch_artifacts" => "stdlib/cli/models/batch_artifacts.harn",
118 "cli/models/batch_cancel" => "stdlib/cli/models/batch_cancel.harn",
119 "cli/models/batch_download" => "stdlib/cli/models/batch_download.harn",
120 "cli/models/batch_lifecycle" => "stdlib/cli/models/batch_lifecycle.harn",
121 "cli/models/batch_status" => "stdlib/cli/models/batch_status.harn",
122 "cli/models/batch_submit" => "stdlib/cli/models/batch_submit.harn",
123 "cli/models/batch_transport" => "stdlib/cli/models/batch_transport.harn",
124 "cli/models/lora_render" => "stdlib/cli/models/lora_render.harn",
125 "cli/paths" => "stdlib/cli/paths.harn",
126 "gha" => "stdlib/stdlib_gha.harn",
127 "tui" => "stdlib/stdlib_tui.harn",
128 "jsonl" => "stdlib/stdlib_jsonl.harn",
129 "config" => "stdlib/stdlib_config.harn",
130 "calendar" => "stdlib/stdlib_calendar.harn",
131 "agents" => "stdlib/stdlib_agents.harn",
132 "lifecycle/pool" => "stdlib/lifecycle/pool.harn",
133 "lifecycle/combinators" => "stdlib/lifecycle/combinators.harn",
134 "lifecycle/on_budget" => "stdlib/lifecycle/on_budget.harn",
135 "agent/prompts" => "stdlib/agent/prompts.harn",
136 "llm/media" => "stdlib/llm/media.harn",
137 "llm/options" => "stdlib/llm/options.harn",
138 "llm/catalog" => "stdlib/llm/catalog.harn",
139 "llm/safe" => "stdlib/llm/safe.harn",
140 "harness/policy" => "stdlib/harness/policy.harn",
141 "llm/budget" => "stdlib/llm/budget.harn",
142 "llm/economics" => "stdlib/llm/economics.harn",
143 "llm/prompts" => "stdlib/llm/prompts.harn",
144 "llm/defaults" => "stdlib/llm/defaults.harn",
145 "llm/handlers" => "stdlib/llm/handlers.harn",
146 "llm/tool_telemetry" => "stdlib/llm/tool_telemetry.harn",
147 "llm/tool_middleware" => "stdlib/llm/tool_middleware.harn",
148 "llm/tool_binder" => "stdlib/llm/tool_binder.harn",
149 "llm/structural_validator" => "stdlib/llm/structural_validator.harn",
150 "llm/missing_tool_call" => "stdlib/llm/missing_tool_call.harn",
151 "llm/scope_classifier" => "stdlib/llm/scope_classifier.harn",
152 "llm/refine" => "stdlib/llm/refine.harn",
153 "llm/ensemble" => "stdlib/llm/ensemble.harn",
154 "llm/rerank" => "stdlib/llm/rerank.harn",
155 "agent/reasoning" => "stdlib/agent/reasoning.harn",
156 "agent/caller_transport" => "stdlib/agent/caller_transport.harn",
157 "agent/options" => "stdlib/agent/options.harn",
158 "agent/options_types" => "stdlib/agent/options_types.harn",
159 "agent/options_formats" => "stdlib/agent/options_formats.harn",
160 "agent/options_validation" => "stdlib/agent/options_validation.harn",
161 "agent/options_public" => "stdlib/agent/options_public.harn",
162 "agent/llm_dispatch" => "stdlib/agent/llm_dispatch.harn",
163 "agent/prefill" => "stdlib/agent/prefill.harn",
164 "agent/retry" => "stdlib/agent/retry.harn",
165 "llm/judge" => "stdlib/llm/judge.harn",
166 "llm/faithfulness" => "stdlib/llm/faithfulness.harn",
167 "llm/optimize" => "stdlib/llm/optimize.harn",
168 "agent/events" => "stdlib/agent/events.harn",
169 "agent/completions" => "stdlib/agent/completions.harn",
170 "agent/transcript" => "stdlib/agent/transcript.harn",
171 "agent/primitives" => "stdlib/agent/primitives.harn",
172 "agent/progress" => "stdlib/agent/progress.harn",
173 "agent/required_tools" => "stdlib/agent/required_tools.harn",
174 "agent/monologue_actuation" => "stdlib/agent/monologue_actuation.harn",
175 "agent/monologue_actuation_types" => "stdlib/agent/monologue_actuation_types.harn",
176 "agent/stall_types" => "stdlib/agent/stall_types.harn",
177 "agent/stall" => "stdlib/agent/stall.harn",
178 "agent/stall_config" => "stdlib/agent/stall_config.harn",
179 "agent/stall_observation" => "stdlib/agent/stall_observation.harn",
180 "agent/stall_verification" => "stdlib/agent/stall_verification.harn",
181 "agent/stall_detectors" => "stdlib/agent/stall_detectors.harn",
182 "agent/governors" => "stdlib/agent/governors.harn",
183 "agent/control" => "stdlib/agent/control.harn",
184 "agent/action_graph" => "stdlib/agent/action_graph.harn",
185 "agent/result_text" => "stdlib/agent/result_text.harn",
186 "agent/best_of_n" => "stdlib/agent/best_of_n.harn",
187 "agent/loop" => "stdlib/agent/loop.harn",
188 "agent/loop_support" => "stdlib/agent/loop_support.harn",
189 "agent/loop_call_resolution" => "stdlib/agent/loop_call_resolution.harn",
190 "agent/loop_result_status" => "stdlib/agent/loop_result_status.harn",
191 "agent/loop_foundation" => "stdlib/agent/loop_foundation.harn",
192 "agent/loop_tool_calls" => "stdlib/agent/loop_tool_calls.harn",
193 "agent/loop_resource_dispatch" => "stdlib/agent/loop_resource_dispatch.harn",
194 "agent/loop_turn_options" => "stdlib/agent/loop_turn_options.harn",
195 "agent/loop_turn_scope" => "stdlib/agent/loop_turn_scope.harn",
196 "agent/loop_internal" => "stdlib/agent/loop_internal.harn",
197 "agent/loop_run" => "stdlib/agent/loop_run.harn",
198 "agent/loop_finalize" => "stdlib/agent/loop_finalize.harn",
199 "agent/loop_terminal" => "stdlib/agent/loop_terminal.harn",
200 "agent/chat" => "stdlib/agent/chat.harn",
201 "agent/user" => "stdlib/agent/user.harn",
202 "agent/tool_search" => "stdlib/agent/tool_search.harn",
203 "agent/tool_annotations" => "stdlib/agent/tool_annotations.harn",
204 "agent/tool_lifecycle" => "stdlib/agent/tool_lifecycle.harn",
205 "agent/turn" => "stdlib/agent/turn.harn",
206 "agent/workers" => "stdlib/agent/workers.harn",
207 "agent/introspection" => "stdlib/agent/introspection.harn",
208 "agent/resume_by" => "stdlib/agent/resume_by.harn",
209 "agent/state" => "stdlib/agent/state.harn",
210 "agent/canon" => "stdlib/agent/canon.harn",
211 "agent/skills" => "stdlib/agent/skills.harn",
212 "agent/autocompact" => "stdlib/agent/autocompact.harn",
213 "agent/mcp" => "stdlib/agent/mcp.harn",
214 "agent/command_capture" => "stdlib/agent/command_capture.harn",
215 "agent/host_tools" => "stdlib/agent/host_tools.harn",
216 "agent/host_injection" => "stdlib/agent/host_injection.harn",
217 "agent/budget" => "stdlib/agent/budget.harn",
218 "agent/daemon" => "stdlib/agent/daemon.harn",
219 "agent/preflight" => "stdlib/agent/preflight.harn",
220 "agent/postturn" => "stdlib/agent/postturn.harn",
221 "agent/stance" => "stdlib/agent/stance.harn",
222 "agent/lanes" => "stdlib/agent/lanes.harn",
223 "agent/overlays" => "stdlib/agent/overlays.harn",
224 "agent/sitrep" => "stdlib/agent/sitrep.harn",
225 "agent/verdict" => "stdlib/agent/verdict.harn",
226 "agent/judge_internals" => "stdlib/agent/judge_internals.harn",
227 "agent/judge" => "stdlib/agent/judge.harn",
228 "agent/guardrails" => "stdlib/agent/guardrails.harn",
229 "agent/step_judge" => "stdlib/agent/step_judge.harn",
230 "agent/scratchpad" => "stdlib/agent/scratchpad.harn",
231 "agent/fact" => "stdlib/agent/fact.harn",
232 "agent/hypothesis" => "stdlib/agent/hypothesis.harn",
233 "agent/pattern_knowledge" => "stdlib/agent/pattern_knowledge.harn",
234 "agent/probe" => "stdlib/agent/probe.harn",
235 "agent/stream" => "stdlib/agent/stream.harn",
236 "agent/presets" => "stdlib/agent/presets.harn",
237 "agent/pins" => "stdlib/agent/pins.harn",
238 "agent/goal" => "stdlib/agent/goal.harn",
239 "agent/task_plan" => "stdlib/agent/task_plan.harn",
240 "personas/compiler" => "stdlib/personas/compiler.harn",
241 "personas/prompt_compiler" => "stdlib/personas/prompt_compiler.harn",
242 "agent_state" => "stdlib/stdlib_agent_state.harn",
243 "memory" => "stdlib/stdlib_memory.harn",
244 "session-store" => "stdlib/stdlib_session_store.harn",
245 "coordination" => "stdlib/stdlib_coordination.harn",
246 "fleet/coordination" => "stdlib/fleet/coordination.harn",
247 "postgres" => "stdlib/stdlib_postgres.harn",
248 "postgres/query" => "stdlib/postgres/query.harn",
249 "sqlite" => "stdlib/stdlib_sqlite.harn",
250 "checkpoint" => "stdlib/stdlib_checkpoint.harn",
251 "host" => "stdlib/stdlib_host.harn",
252 "host_lease" => "stdlib/stdlib_host_lease.harn",
253 "git" => "stdlib/stdlib_git.harn",
254 "git/checkout" => "stdlib/git/checkout.harn",
255 "hitl" => "stdlib/stdlib_hitl.harn",
256 "trust" => "stdlib/stdlib_trust.harn",
257 "corrections" => "stdlib/stdlib_corrections.harn",
258 "plan" => "stdlib/stdlib_plan.harn",
259 "waitpoints" => "stdlib/stdlib_waitpoints.harn",
260 "waitpoint" => "stdlib/stdlib_waitpoint.harn",
261 "monitors" => "stdlib/stdlib_monitors.harn",
262 "worktree" => "stdlib/stdlib_worktree.harn",
263 "acp" => "stdlib/stdlib_acp.harn",
264 "external_agent" => "stdlib/stdlib_external_agent.harn",
265 "triggers" => "stdlib/stdlib_triggers.harn",
266 "triage" => "stdlib/stdlib_triage.harn",
267 "dashboard/jobs" => "stdlib/dashboard/jobs.harn",
268 "ui_resource" => "stdlib/stdlib_ui_resource.harn",
269 "handoffs" => "stdlib/stdlib_handoffs.harn",
270 "lifecycle" => "stdlib/stdlib_lifecycle.harn",
271 "tool_hooks_catalogues" => "stdlib/stdlib_tool_hooks_catalogues.harn",
272 "tool_hooks" => "stdlib/stdlib_tool_hooks.harn",
273 "channel_guardrails" => "stdlib/stdlib_channel_guardrails.harn",
274 "personas/prelude" => "stdlib/stdlib_personas_prelude.harn",
275 "personas/bulletins" => "stdlib/stdlib_personas_bulletins.harn",
276 "connectors/shared" => "stdlib/stdlib_connectors_shared.harn",
277 "oauth/providers" => "stdlib/oauth/providers.harn",
278 "oauth/token_exchange_catalog" => "stdlib/oauth/token_exchange_catalog.harn",
279 "oauth/token_exchange" => "stdlib/oauth/token_exchange.harn",
280 "oauth/storage" => "stdlib/oauth/storage.harn",
281 "oauth/client" => "stdlib/oauth/client.harn",
282 "oauth/device_flow" => "stdlib/oauth/device_flow.harn",
283 "oauth/redaction" => "stdlib/oauth/redaction.harn",
284 "oauth/dynamic_registration" => "stdlib/oauth/dynamic_registration.harn",
285 "connectors/github" => "stdlib/stdlib_connectors_github.harn",
286 "connectors/linear" => "stdlib/stdlib_connectors_linear.harn",
287 "connectors/notion" => "stdlib/stdlib_connectors_notion.harn",
288 "connectors/slack" => "stdlib/stdlib_connectors_slack.harn",
289 "workflow/prompts" => "stdlib/workflow/prompts.harn",
290 "workflow/context" => "stdlib/workflow/context.harn",
291 "workflow/options" => "stdlib/workflow/options.harn",
292 "workflow/checkpoints" => "stdlib/workflow/checkpoints.harn",
293 "workflow/patterns" => "stdlib/workflow/patterns.harn",
294 "workflow/stage" => "stdlib/workflow/stage.harn",
295 "workflow/map" => "stdlib/workflow/map.harn",
296 "workflow/schedule" => "stdlib/workflow/schedule.harn",
297 "workflow/execute" => "stdlib/workflow/execute.harn",
298 "workflow/repair" => "stdlib/workflow/repair.harn",
299 "security" => "stdlib/stdlib_security.harn",
300 "pii" => "stdlib/stdlib_pii.harn",
301]);
302
303pub const CONNECTOR_EVENT_SCHEMAS_SOURCE: &str = include_str!("stdlib/stdlib_event_schemas.harn");
313
314pub const STDLIB_PROMPT_ASSETS: &[StdlibPromptAsset] = embedded_catalog!(StdlibPromptAsset, path, [
315 "agent/prompts/tool_contract_text.harn.prompt" => "stdlib/agent/prompts/tool_contract_text.harn.prompt",
316 "agent/prompts/tool_contract_json.harn.prompt" => "stdlib/agent/prompts/tool_contract_json.harn.prompt",
317 "agent/prompts/tool_contract_native.harn.prompt" => "stdlib/agent/prompts/tool_contract_native.harn.prompt",
318 "agent/prompts/tool_contract_text_response_protocol.harn.prompt" => "stdlib/agent/prompts/tool_contract_text_response_protocol.harn.prompt",
319 "agent/prompts/tool_contract_action_native.harn.prompt" => "stdlib/agent/prompts/tool_contract_action_native.harn.prompt",
320 "agent/prompts/tool_contract_action_text.harn.prompt" => "stdlib/agent/prompts/tool_contract_action_text.harn.prompt",
321 "agent/prompts/tool_contract_task_ledger.harn.prompt" => "stdlib/agent/prompts/tool_contract_task_ledger.harn.prompt",
322 "agent/prompts/tool_contract_deferred_tools.harn.prompt" => "stdlib/agent/prompts/tool_contract_deferred_tools.harn.prompt",
323 "agent/prompts/deferred_tool_listing.harn.prompt" => "stdlib/agent/prompts/deferred_tool_listing.harn.prompt",
324 "agent/prompts/agent_turn_preamble.harn.prompt" => "stdlib/agent/prompts/agent_turn_preamble.harn.prompt",
325 "agent/prompts/default_nudge.harn.prompt" => "stdlib/agent/prompts/default_nudge.harn.prompt",
326 "agent/prompts/agentic_user_system.harn.prompt" => "stdlib/agent/prompts/agentic_user_system.harn.prompt",
327 "agent/prompts/agentic_user_user.harn.prompt" => "stdlib/agent/prompts/agentic_user_user.harn.prompt",
328 "agent/prompts/loop_until_done_system.harn.prompt" => "stdlib/agent/prompts/loop_until_done_system.harn.prompt",
329 "agent/prompts/completion_judge_default.harn.prompt" => "stdlib/agent/prompts/completion_judge_default.harn.prompt",
330 "agent/prompts/completion_judge_feedback_fallback.harn.prompt" => "stdlib/agent/prompts/completion_judge_feedback_fallback.harn.prompt",
331 "agent/prompts/completion_judge_user.harn.prompt" => "stdlib/agent/prompts/completion_judge_user.harn.prompt",
332 "agent/prompts/step_judge_system_default.harn.prompt" => "stdlib/agent/prompts/step_judge_system_default.harn.prompt",
333 "agent/prompts/step_judge_system_adversarial.harn.prompt" => "stdlib/agent/prompts/step_judge_system_adversarial.harn.prompt",
334 "agent/prompts/step_judge_user.harn.prompt" => "stdlib/agent/prompts/step_judge_user.harn.prompt",
335 "agent/prompts/parse_guidance.harn.prompt" => "stdlib/agent/prompts/parse_guidance.harn.prompt",
336 "agent/prompts/native_tool_contract_feedback.harn.prompt" => "stdlib/agent/prompts/native_tool_contract_feedback.harn.prompt",
337 "agent/prompts/verification_gate_feedback.harn.prompt" => "stdlib/agent/prompts/verification_gate_feedback.harn.prompt",
338 "agent/prompts/daemon_watch_feedback.harn.prompt" => "stdlib/agent/prompts/daemon_watch_feedback.harn.prompt",
339 "agent/prompts/daemon_timer_feedback.harn.prompt" => "stdlib/agent/prompts/daemon_timer_feedback.harn.prompt",
340 "llm/prompts/completion_fallback_system.harn.prompt" => "stdlib/llm/prompts/completion_fallback_system.harn.prompt",
341 "llm/prompts/completion_fallback_user.harn.prompt" => "stdlib/llm/prompts/completion_fallback_user.harn.prompt",
342 "llm/prompts/transcript_summarize_user.harn.prompt" => "stdlib/llm/prompts/transcript_summarize_user.harn.prompt",
343 "llm/prompts/sitrep_user.harn.prompt" => "stdlib/llm/prompts/sitrep_user.harn.prompt",
344 "llm/prompts/structural_chain_of_draft.harn.prompt" => "stdlib/llm/prompts/structural_chain_of_draft.harn.prompt",
345 "llm/prompts/schema_recover_repair.harn.prompt" => "stdlib/llm/prompts/schema_recover_repair.harn.prompt",
346 "llm/prompts/structured_envelope_schema_contract.harn.prompt" => "stdlib/llm/prompts/structured_envelope_schema_contract.harn.prompt",
347 "llm/prompts/structured_envelope_repair.harn.prompt" => "stdlib/llm/prompts/structured_envelope_repair.harn.prompt",
348 "llm/prompts/pairwise_rerank_user.harn.prompt" => "stdlib/llm/prompts/pairwise_rerank_user.harn.prompt",
349 "llm/prompts/tool_binder_user.harn.prompt" => "stdlib/llm/prompts/tool_binder_user.harn.prompt",
350 "workflow/prompts/stage.harn.prompt" => "stdlib/workflow/prompts/stage.harn.prompt",
351 "workflow/prompts/verification_context_intro.harn.prompt" => "stdlib/workflow/prompts/verification_context_intro.harn.prompt",
352 "orchestration/prompts/compaction_summary.harn.prompt" => "stdlib/orchestration/prompts/compaction_summary.harn.prompt",
353 "orchestration/prompts/compaction_policy_replacement.harn.prompt" => "stdlib/orchestration/prompts/compaction_policy_replacement.harn.prompt",
354]);
355
356#[derive(Debug, Clone, Copy, PartialEq, Eq)]
360pub struct StdlibCliScript {
361 pub name: &'static str,
365 pub source: &'static str,
368}
369
370pub const STDLIB_CLI_SCRIPTS: &[StdlibCliScript] = embedded_catalog!(StdlibCliScript, name, [
371 "codemod" => "stdlib/cli/codemod.harn",
372 "canon/check" => "stdlib/cli/canon/check.harn",
373 "doctor" => "stdlib/cli/doctor.harn",
374 "echo" => "stdlib/cli/echo.harn",
375 "eval/_runner" => "stdlib/cli/eval/_runner.harn",
379 "eval/context" => "stdlib/cli/eval/context.harn",
380 "eval/model_selector" => "stdlib/cli/eval/model_selector.harn",
381 "eval/tool_calls" => "stdlib/cli/eval/tool_calls.harn",
382 "eval/coding_agent" => "stdlib/cli/eval/coding_agent.harn",
383 "eval/scope_triage" => "stdlib/cli/eval/scope_triage.harn",
384 "eval/prompt" => "stdlib/cli/eval/prompt.harn",
385 "explain" => "stdlib/cli/explain.harn",
386 "graph" => "stdlib/cli/graph.harn",
387 "personas/compile_prompt" => "stdlib/cli/personas/compile_prompt.harn",
388 "personas/materialize" => "stdlib/cli/personas/materialize.harn",
389 "models/batch_plan" => "stdlib/cli/models/batch_plan.harn",
390 "models/list" => "stdlib/cli/models/list.harn",
391 "models/lora_inspect" => "stdlib/cli/models/lora_inspect.harn",
392 "models/lora_export" => "stdlib/cli/models/lora_export.harn",
393 "models/lora_manifest" => "stdlib/cli/models/lora_manifest.harn",
394 "models/lora_preflight" => "stdlib/cli/models/lora_preflight.harn",
395 "models/lora_promote" => "stdlib/cli/models/lora_promote.harn",
396 "models/lora_plan" => "stdlib/cli/models/lora_plan.harn",
397 "models/lora_train" => "stdlib/cli/models/lora_train.harn",
398 "models/recommend" => "stdlib/cli/models/recommend.harn",
399 "models/test" => "stdlib/cli/models/test.harn",
400 "precompile" => "stdlib/cli/precompile.harn",
401 "providers/cache_probe" => "stdlib/cli/providers/cache_probe.harn",
402 "providers/catalog" => "stdlib/cli/providers/catalog.harn",
403 "providers/probe" => "stdlib/cli/providers/probe.harn",
404 "providers/recommend" => "stdlib/cli/providers/recommend.harn",
405 "providers/tool_probe" => "stdlib/cli/providers/tool_probe.harn",
406 "providers/tool_scorecard" => "stdlib/cli/providers/tool_scorecard.harn",
407 "routes" => "stdlib/cli/routes.harn",
408 "scan" => "stdlib/cli/scan.harn",
409 "scaffold/init" => "stdlib/cli/scaffold/init.harn",
410 "scaffold/tool_new" => "stdlib/cli/scaffold/tool_new.harn",
411 "trace_import" => "stdlib/cli/trace_import.harn",
412 "try" => "stdlib/cli/try.harn",
413 "version" => "stdlib/cli/version.harn",
414]);
415
416pub fn get_stdlib_source(module: &str) -> Option<&'static str> {
417 STDLIB_SOURCES
418 .iter()
419 .find_map(|entry| (entry.module == module).then_some(entry.source))
420}
421
422pub fn builtin_reexports(module: &str) -> &'static [&'static str] {
442 match module {
443 "testing" => &[
444 "assert",
445 "assert_approx",
446 "assert_eq",
447 "assert_matches",
448 "assert_ne",
449 "value_diff",
450 ],
451 _ => &[],
452 }
453}
454
455pub fn find_cli_script(name: &str) -> Option<&'static str> {
459 STDLIB_CLI_SCRIPTS
460 .iter()
461 .find_map(|entry| (entry.name == name).then_some(entry.source))
462}
463
464pub fn get_stdlib_prompt_asset(path: &str) -> Option<&'static str> {
465 let path = path.strip_prefix("std/").unwrap_or(path);
466 STDLIB_PROMPT_ASSETS
467 .iter()
468 .find_map(|entry| (entry.path == path).then_some(entry.source))
469}
470
471pub fn public_functions_for_module(module: &str) -> Vec<StdlibPublicFunction> {
472 let Some(source) = get_stdlib_source(module) else {
473 return Vec::new();
474 };
475 public_functions_from_source(source)
476}
477
478pub fn entrypoint_modules() -> Vec<StdlibEntrypointModule> {
479 STDLIB_SOURCES
480 .iter()
481 .filter_map(|entry| {
482 entrypoint_category_from_source(entry.source).map(|category| StdlibEntrypointModule {
483 import_path: format!("std/{}", entry.module),
484 category,
485 })
486 })
487 .collect()
488}
489
490fn entrypoint_category_from_source(source: &str) -> Option<String> {
491 for line in source.lines() {
492 let line = line.trim();
493 if line.is_empty() {
494 continue;
495 }
496 if let Some(category) = line.strip_prefix("// @harn-entrypoint-category ") {
497 let category = category.trim();
498 return (!category.is_empty()).then(|| category.to_string());
499 }
500 if !line.starts_with("//") {
501 return None;
502 }
503 }
504 None
505}
506
507fn public_functions_from_source(source: &str) -> Vec<StdlibPublicFunction> {
508 let mut out = Vec::new();
509 let mut doc: Option<String> = None;
510 let lines = source.lines().collect::<Vec<_>>();
511 let mut index = 0usize;
512 while index < lines.len() {
513 let line = lines[index].trim();
514 if line.starts_with("/**") {
515 let (parsed, next) = parse_harndoc(&lines, index);
516 doc = parsed;
517 index = next;
518 continue;
519 }
520 if line.starts_with("pub fn ") {
521 let (signature_line, next) = collect_public_function_signature(&lines, index);
522 if let Some(function) = parse_public_function_line(&signature_line, doc.take()) {
523 out.push(function);
524 index = next;
525 continue;
526 }
527 }
528 if let Some(function) = parse_public_function_line(line, doc.take()) {
529 out.push(function);
530 } else if !line.is_empty() && !line.starts_with("//") {
531 doc = None;
532 }
533 index += 1;
534 }
535 out
536}
537
538fn collect_public_function_signature(lines: &[&str], start: usize) -> (String, usize) {
539 let mut parts = Vec::new();
540 let mut index = start;
541 while index < lines.len() {
542 parts.push(lines[index].trim().to_string());
543 let candidate = parts.join(" ");
544 if public_function_signature_complete(&candidate) {
545 return (candidate, index + 1);
546 }
547 index += 1;
548 }
549 (parts.join(" "), index)
550}
551
552fn public_function_signature_complete(line: &str) -> bool {
553 let Some(rest) = line.strip_prefix("pub fn ") else {
554 return false;
555 };
556 let Some(name_end) = rest.find('(') else {
557 return false;
558 };
559 matching_paren_len(&rest[name_end + 1..]).is_some()
560}
561
562fn parse_harndoc(lines: &[&str], start: usize) -> (Option<String>, usize) {
563 let mut parts = Vec::new();
564 let mut index = start;
565 while index < lines.len() {
566 let mut line = lines[index].trim();
567 if index == start {
568 line = line.trim_start_matches("/**").trim();
569 }
570 let done = line.ends_with("*/");
571 line = line.trim_end_matches("*/").trim();
572 line = line.trim_start_matches('*').trim();
573 if !line.is_empty() {
574 parts.push(line.to_string());
575 }
576 index += 1;
577 if done {
578 break;
579 }
580 }
581 let text = parts.join("\n").trim().to_string();
582 ((!text.is_empty()).then_some(text), index)
583}
584
585fn parse_public_function_line(line: &str, doc: Option<String>) -> Option<StdlibPublicFunction> {
586 let rest = line.strip_prefix("pub fn ")?.trim();
587 let name_end = rest.find('(')?;
588 let name = rest[..name_end].trim();
589 if name.is_empty() {
590 return None;
591 }
592 let params_start = name_end + 1;
593 let params_len = matching_paren_len(&rest[params_start..])?;
594 let params = &rest[params_start..params_start + params_len];
595 let after = rest[params_start + params_len + 1..].trim();
596 let return_type = after
597 .strip_prefix("->")
598 .and_then(|tail| tail.split('{').next())
599 .map(str::trim)
600 .filter(|value| !value.is_empty());
601 let signature = match return_type {
602 Some(ret) => format!("{name}({params}) -> {ret}"),
603 None => format!("{name}({params})"),
604 };
605 let param_parts = split_top_level_params(params);
606 let total_params = param_parts
607 .iter()
608 .filter(|param| !param.trim().is_empty())
609 .count();
610 let variadic = param_parts
611 .iter()
612 .any(|param| param.trim_start().starts_with("..."));
613 let required_params = param_parts
614 .iter()
615 .filter(|param| {
616 let param = param.trim();
617 !param.is_empty() && !param.contains('=') && !param.starts_with("...")
618 })
619 .count();
620 Some(StdlibPublicFunction {
621 name: name.to_string(),
622 signature,
623 required_params,
624 total_params,
625 variadic,
626 doc,
627 })
628}
629
630fn matching_paren_len(input: &str) -> Option<usize> {
631 let mut depth = 1usize;
632 for (offset, ch) in input.char_indices() {
633 match ch {
634 '(' | '[' | '{' => depth += 1,
635 ')' | ']' | '}' => {
636 depth = depth.saturating_sub(1);
637 if depth == 0 {
638 return Some(offset);
639 }
640 }
641 _ => {}
642 }
643 }
644 None
645}
646
647fn split_top_level_params(params: &str) -> Vec<&str> {
648 let mut out = Vec::new();
649 let mut depth = 0isize;
650 let mut start = 0usize;
651 for (offset, ch) in params.char_indices() {
652 match ch {
653 '(' | '[' | '{' => depth += 1,
654 ')' | ']' | '}' => depth -= 1,
655 ',' if depth == 0 => {
656 out.push(¶ms[start..offset]);
657 start = offset + 1;
658 }
659 _ => {}
660 }
661 }
662 out.push(¶ms[start..]);
663 out
664}
665
666#[cfg(test)]
667mod tests {
668 use std::collections::BTreeSet;
669
670 use super::{
671 entrypoint_modules, find_cli_script, get_stdlib_prompt_asset, get_stdlib_source,
672 matching_paren_len, parse_public_function_line, public_functions_for_module,
673 STDLIB_CLI_SCRIPTS, STDLIB_PROMPT_ASSETS, STDLIB_SOURCES,
674 };
675
676 #[test]
677 fn stdlib_sources_are_non_empty() {
678 for entry in STDLIB_SOURCES {
679 assert!(
680 !entry.source.trim().is_empty(),
681 "{} should have non-empty source",
682 entry.module
683 );
684 }
685 }
686
687 #[test]
688 fn cli_scripts_are_non_empty_and_uniquely_named() {
689 let mut seen = BTreeSet::new();
690 for entry in STDLIB_CLI_SCRIPTS {
691 assert!(
692 !entry.source.trim().is_empty(),
693 "cli/{} should have non-empty source",
694 entry.name
695 );
696 assert!(
697 seen.insert(entry.name),
698 "cli/{} is registered more than once in STDLIB_CLI_SCRIPTS",
699 entry.name
700 );
701 }
702 }
703
704 #[test]
705 fn find_cli_script_round_trips() {
706 for entry in STDLIB_CLI_SCRIPTS {
707 assert_eq!(find_cli_script(entry.name), Some(entry.source));
708 }
709 assert!(find_cli_script("not-a-real-script").is_none());
710 }
711
712 #[test]
713 fn stdlib_source_names_are_unique() {
714 let mut names = BTreeSet::new();
715 for entry in STDLIB_SOURCES {
716 assert!(names.insert(entry.module), "duplicate {}", entry.module);
717 }
718 }
719
720 #[test]
721 fn stdlib_prompt_assets_are_non_empty() {
722 for entry in STDLIB_PROMPT_ASSETS {
723 assert!(
724 !entry.source.trim().is_empty(),
725 "{} should have non-empty prompt asset source",
726 entry.path
727 );
728 }
729 }
730
731 #[test]
732 fn stdlib_prompt_asset_paths_are_unique() {
733 let mut paths = BTreeSet::new();
734 for entry in STDLIB_PROMPT_ASSETS {
735 assert!(paths.insert(entry.path), "duplicate {}", entry.path);
736 }
737 }
738
739 #[test]
740 fn key_stdlib_modules_resolve() {
741 for module in [
742 "context",
743 "context/maintenance",
744 "context/eval",
745 "eval/stats",
746 "eval/agreement",
747 "edit",
748 "verification",
749 "disclosure",
750 "artifact/web",
751 "command",
752 "waitpoint",
753 "llm/handlers",
754 "llm/tool_middleware",
755 "llm/tool_binder",
756 "llm/missing_tool_call",
757 "llm/ensemble",
758 "llm/rerank",
759 "personas/prelude",
760 "personas/bulletins",
761 "agent/host_tools",
762 "agent/host_injection",
763 "agent/tool_lifecycle",
764 "agent/user",
765 "agent/governors",
766 "agent/guardrails",
767 "cli",
768 "cli/models/batch_artifacts",
769 "cli/models/batch_cancel",
770 "cli/models/batch_download",
771 "cli/models/batch_lifecycle",
772 "cli/models/batch_status",
773 "cli/models/batch_submit",
774 "cli/models/batch_transport",
775 "cli/models/lora_render",
776 "llm/optimize",
777 "llm/judge",
778 "llm/faithfulness",
779 "llm/refine",
780 "connectors/shared",
781 "connectors/github",
782 "connectors/linear",
783 "connectors/notion",
784 "connectors/slack",
785 "triage",
786 "dashboard/jobs",
787 "ui_resource",
788 "host_lease",
789 ] {
790 assert!(
791 get_stdlib_source(module).is_some(),
792 "std/{module} should resolve"
793 );
794 }
795 }
796
797 #[test]
798 fn key_stdlib_prompt_assets_resolve() {
799 for path in [
800 "std/agent/prompts/tool_contract_text.harn.prompt",
801 "std/agent/prompts/default_nudge.harn.prompt",
802 "std/agent/prompts/completion_judge_default.harn.prompt",
803 "std/workflow/prompts/stage.harn.prompt",
804 "std/orchestration/prompts/compaction_summary.harn.prompt",
805 "std/orchestration/prompts/compaction_policy_replacement.harn.prompt",
806 ] {
807 assert!(
808 get_stdlib_prompt_asset(path).is_some(),
809 "{path} should resolve"
810 );
811 }
812 }
813
814 #[test]
815 fn public_function_catalog_derives_signatures_from_harn_source() {
816 let exports = public_functions_for_module("workflow/execute");
817 assert_eq!(exports.len(), 1);
818 assert_eq!(exports[0].name, "workflow_execute");
819 assert_eq!(
820 exports[0].signature,
821 "workflow_execute(task, graph, artifacts = nil, options = nil)"
822 );
823 assert_eq!(exports[0].required_params, 2);
824 assert_eq!(exports[0].total_params, 4);
825 }
826
827 #[test]
828 fn command_stdlib_module_exports_step_helpers() {
829 let exports = public_functions_for_module("command")
830 .into_iter()
831 .map(|function| function.name)
832 .collect::<BTreeSet<_>>();
833 for name in [
834 "command_run",
835 "command_wait",
836 "command_cancel",
837 "command_run_streaming",
838 "command_output_tail",
839 "command_json",
840 "command_json_step",
841 "command_try",
842 "command_step",
843 "command_steps_append",
844 "command_last_failed_step",
845 "command_step_ref",
846 ] {
847 assert!(exports.contains(name), "std/command should export {name}");
848 }
849 }
850
851 #[test]
852 fn disclosure_stdlib_module_exports_render_helpers() {
853 let exports = public_functions_for_module("disclosure")
854 .into_iter()
855 .map(|function| function.name)
856 .collect::<BTreeSet<_>>();
857 assert!(
858 exports.contains("render"),
859 "std/disclosure should export render"
860 );
861 assert!(
862 exports.contains("git_trailers"),
863 "std/disclosure should export git_trailers"
864 );
865 assert!(
866 exports.contains("slack_message_disclosure"),
867 "std/disclosure should export slack_message_disclosure"
868 );
869 assert!(
870 exports.contains("append_git_trailers"),
871 "std/disclosure should export append_git_trailers"
872 );
873 }
874
875 #[test]
876 fn async_stdlib_exports_predicate_backoff_name_only() {
877 let exports = public_functions_for_module("async")
878 .into_iter()
879 .map(|function| function.name)
880 .collect::<BTreeSet<_>>();
881 assert!(
882 exports.contains("retry_predicate_with_backoff"),
883 "std/async should export retry_predicate_with_backoff"
884 );
885 assert!(
886 !exports.contains("retry_with_backoff"),
887 "std/async should not retain the old retry_with_backoff export"
888 );
889 }
890
891 #[test]
892 fn signal_stdlib_module_exports_interrupt_helpers() {
893 let exports = public_functions_for_module("signal")
894 .into_iter()
895 .map(|function| function.name)
896 .collect::<BTreeSet<_>>();
897 for name in [
898 "on_interrupt",
899 "off_interrupt",
900 "interrupted",
901 "with_interrupt",
902 ] {
903 assert!(exports.contains(name), "std/signal should export {name}");
904 }
905 }
906
907 #[test]
908 fn git_stdlib_module_exports_local_wrappers() {
909 let exports = public_functions_for_module("git")
910 .into_iter()
911 .map(|function| function.name)
912 .collect::<BTreeSet<_>>();
913 for name in [
914 "git_run",
915 "git_status",
916 "git_current_branch",
917 "git_log",
918 "git_switch",
919 "git_pull_ff_only",
920 "git_find_tool",
921 "git_run_tool",
922 "git_tools",
923 "git_toolbox_tools",
924 ] {
925 assert!(exports.contains(name), "std/git should export {name}");
926 }
927 }
928
929 #[test]
930 fn agent_workers_exports_suspend_resume_wrappers() {
931 let exports = public_functions_for_module("agent/workers");
932 let suspend = exports
933 .iter()
934 .find(|function| function.name == "suspend_agent")
935 .expect("std/agent/workers should export suspend_agent");
936 assert_eq!(
937 suspend.signature,
938 "suspend_agent(worker, reason = \"\", options = nil)"
939 );
940 assert_eq!(suspend.required_params, 1);
941 assert_eq!(suspend.total_params, 3);
942
943 let resume = exports
944 .iter()
945 .find(|function| function.name == "resume_agent")
946 .expect("std/agent/workers should export resume_agent");
947 assert_eq!(
948 resume.signature,
949 "resume_agent(worker_or_snapshot, resume_input = nil, continue_transcript = true)"
950 );
951 assert_eq!(resume.required_params, 1);
952 assert_eq!(resume.total_params, 3);
953
954 let stop = exports
955 .iter()
956 .find(|function| function.name == "agent_stop")
957 .expect("std/agent/workers should export agent_stop");
958 assert_eq!(
959 stop.signature,
960 "agent_stop(worker, options: AgentStopOptions = nil)"
961 );
962 assert_eq!(stop.required_params, 1);
963 assert_eq!(stop.total_params, 2);
964
965 let parse_resume = exports
966 .iter()
967 .find(|function| function.name == "parse_resume_conditions")
968 .expect("std/agent/workers should export parse_resume_conditions");
969 assert_eq!(
970 parse_resume.signature,
971 "parse_resume_conditions(conditions = nil) -> ResumeConditions?"
972 );
973 assert_eq!(parse_resume.required_params, 0);
974 assert_eq!(parse_resume.total_params, 1);
975
976 let lifecycle = exports
977 .iter()
978 .find(|function| function.name == "agent_lifecycle_tools")
979 .expect("std/agent/workers should export agent_lifecycle_tools");
980 assert_eq!(
981 lifecycle.signature,
982 "agent_lifecycle_tools(registry = nil, options = nil)"
983 );
984 assert_eq!(lifecycle.required_params, 0);
985 assert_eq!(lifecycle.total_params, 2);
986 }
987
988 #[test]
989 fn tui_stdlib_module_exports_terminal_helpers() {
990 let exports = public_functions_for_module("tui")
991 .into_iter()
992 .map(|function| function.name)
993 .collect::<BTreeSet<_>>();
994 for name in ["page", "terminal_width", "rule", "clear", "select_from"] {
995 assert!(exports.contains(name), "std/tui should export {name}");
996 }
997 }
998
999 #[test]
1000 fn semver_stdlib_module_exports_release_helpers() {
1001 let exports = public_functions_for_module("semver")
1002 .into_iter()
1003 .map(|function| function.name)
1004 .collect::<BTreeSet<_>>();
1005 for name in [
1006 "strip_v",
1007 "add_v",
1008 "is_v_semver",
1009 "parse",
1010 "max_canonical_tag",
1011 "next",
1012 "bump_type",
1013 "version_from_release_branch",
1014 "version_from_tag",
1015 ] {
1016 assert!(exports.contains(name), "std/semver should export {name}");
1017 }
1018 }
1019
1020 #[test]
1021 fn changelog_stdlib_module_exports_typed_primitives() {
1022 let exports = public_functions_for_module("changelog")
1023 .into_iter()
1024 .map(|function| function.name)
1025 .collect::<BTreeSet<_>>();
1026 for name in [
1027 "changelog_validate_categories",
1028 "changelog_parse_fragment",
1029 "changelog_order_fragments",
1030 "changelog_normalize_fragment_body",
1031 "changelog_assemble_fragments",
1032 "changelog_parse_sections",
1033 "changelog_find_section",
1034 "changelog_merge_unreleased",
1035 ] {
1036 assert!(exports.contains(name), "std/changelog should export {name}");
1037 }
1038 }
1039
1040 #[test]
1041 fn text_stdlib_module_exports_regex_and_pad_helpers() {
1042 let exports = public_functions_for_module("text")
1043 .into_iter()
1044 .map(|function| function.name)
1045 .collect::<BTreeSet<_>>();
1046 for name in [
1047 "pad_left",
1048 "pad_right",
1049 "repeat_string",
1050 "regex_first_capture",
1051 "regex_capture_groups",
1052 "regex_all_first_captures",
1053 ] {
1054 assert!(exports.contains(name), "std/text should export {name}");
1055 }
1056 }
1057
1058 #[test]
1059 fn harn_entrypoint_catalog_is_declared_by_stdlib_sources() {
1060 let modules = entrypoint_modules();
1061 let entries = modules
1062 .iter()
1063 .map(|module| (module.import_path.as_str(), module.category.as_str()))
1064 .collect::<BTreeSet<_>>();
1065 for entry in [
1066 ("std/agent/loop", "agent.stdlib"),
1067 ("std/agent/turn", "agent.stdlib"),
1068 ("std/agent/primitives", "agent.stdlib"),
1069 ("std/workflow/execute", "workflow.stdlib"),
1070 ] {
1071 assert!(entries.contains(&entry), "{entry:?} should be declared");
1072 }
1073 }
1074
1075 #[test]
1076 fn matching_paren_len_closes_on_every_bracket_kind() {
1077 assert_eq!(matching_paren_len("a, b)"), Some(4));
1080 assert_eq!(matching_paren_len("x: [int])"), Some(8));
1081 assert_eq!(matching_paren_len("x: {a: int})"), Some(11));
1082 assert_eq!(matching_paren_len("x]"), Some(1));
1085 assert_eq!(matching_paren_len("x}"), Some(1));
1086 assert_eq!(matching_paren_len("unterminated"), None);
1087 }
1088
1089 #[test]
1090 fn parse_public_function_line_handles_record_typed_params() {
1091 let parsed =
1092 parse_public_function_line("pub fn configure(opts: {retries: int}) -> bool", None)
1093 .expect("signature with a record-typed parameter should parse");
1094 assert_eq!(parsed.name, "configure");
1095 assert_eq!(parsed.signature, "configure(opts: {retries: int}) -> bool");
1096 assert_eq!(parsed.total_params, 1);
1097 assert_eq!(parsed.required_params, 1);
1098 }
1099}