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