1pub use harn_stdlib_catalog::{
13 builtin_reexports, StdlibCatalog, StdlibCliScript, StdlibPromptAsset, StdlibSource,
14};
15
16macro_rules! embedded_catalog {
17 ($entry:ident, $key:ident, [$($name:literal => $path:literal),* $(,)?]) => {
18 &[
19 $($entry {
20 $key: $name,
21 source: include_str!($path),
22 },)*
23 ]
24 };
25}
26
27#[derive(Debug, Clone, PartialEq, Eq)]
28pub struct StdlibPublicFunction {
29 pub name: String,
30 pub signature: String,
31 pub required_params: usize,
32 pub total_params: usize,
33 pub variadic: bool,
34 pub doc: Option<String>,
35}
36
37#[derive(Debug, Clone, PartialEq, Eq)]
38pub struct StdlibEntrypointModule {
39 pub import_path: String,
40 pub category: String,
41}
42
43pub const STDLIB_SOURCES: &[StdlibSource] = embedded_catalog!(StdlibSource, module, [
44 "text" => "stdlib/stdlib_text.harn",
45 "semver" => "stdlib/stdlib_semver.harn",
46 "changelog" => "stdlib/stdlib_changelog.harn",
47 "ansi" => "stdlib/stdlib_ansi.harn",
48 "table" => "stdlib/stdlib_table.harn",
49 "diff" => "stdlib/stdlib_diff.harn",
50 "edit" => "stdlib/stdlib_edit.harn",
51 "edit/capabilities" => "stdlib/edit/capabilities.harn",
52 "edit/internal" => "stdlib/edit/internal.harn",
53 "edit/patch" => "stdlib/edit/patch.harn",
54 "edit/anchors" => "stdlib/edit/anchors.harn",
55 "edit/guards" => "stdlib/edit/guards.harn",
56 "edit/function_body" => "stdlib/edit/function_body.harn",
57 "edit/refactor_runtime" => "stdlib/edit/refactor_runtime.harn",
58 "edit/safe_patch" => "stdlib/edit/safe_patch.harn",
59 "edit/fast_apply" => "stdlib/edit/fast_apply.harn",
60 "ast" => "stdlib/stdlib_ast.harn",
61 "ast/parse" => "stdlib/ast/parse.harn",
62 "ast/parse_delta" => "stdlib/ast/parse_delta.harn",
63 "diagnostics" => "stdlib/stdlib_diagnostics.harn",
64 "dev/agent_gates" => "stdlib/dev/agent_gates.harn",
65 "dev/agent_gate_bindings" => "stdlib/dev/agent_gate_bindings.harn",
66 "rules" => "stdlib/stdlib_rules.harn",
67 "lint" => "stdlib/stdlib_lint.harn",
68 "artifact/web" => "stdlib/artifact/web.harn",
69 "collections" => "stdlib/stdlib_collections.harn",
70 "math" => "stdlib/stdlib_math.harn",
71 "slug" => "stdlib/stdlib_slug.harn",
72 "path" => "stdlib/stdlib_path.harn",
73 "fs" => "stdlib/stdlib_fs.harn",
74 "run_artifacts" => "stdlib/stdlib_run_artifacts.harn",
75 "artifacts/typed" => "stdlib/artifacts/typed.harn",
76 "os" => "stdlib/stdlib_os.harn",
77 "json" => "stdlib/stdlib_json.harn",
78 "json/stream" => "stdlib/stdlib_json_stream.harn",
79 "xml" => "stdlib/stdlib_xml.harn",
80 "cache" => "stdlib/stdlib_cache.harn",
81 "predicate" => "stdlib/stdlib_predicate.harn",
82 "observability" => "stdlib/stdlib_observability.harn",
83 "timing" => "stdlib/stdlib_timing.harn",
84 "verification" => "stdlib/stdlib_verification.harn",
85 "tools" => "stdlib/stdlib_tools.harn",
86 "composition" => "stdlib/stdlib_composition.harn",
87 "web" => "stdlib/stdlib_web.harn",
88 "graphql" => "stdlib/stdlib_graphql.harn",
89 "code_librarian" => "stdlib/stdlib_code_librarian.harn",
90 "schema" => "stdlib/stdlib_schema.harn",
91 "schema/contracts" => "stdlib/schema/contracts.harn",
92 "identity" => "stdlib/stdlib_identity.harn",
93 "disclosure" => "stdlib/stdlib_disclosure.harn",
94 "testing" => "stdlib/stdlib_testing.harn",
95 "files" => "stdlib/stdlib_files.harn",
96 "document" => "stdlib/stdlib_document.harn",
97 "vision" => "stdlib/stdlib_vision.harn",
98 "context" => "stdlib/stdlib_context.harn",
99 "context/artifact_types" => "stdlib/context/artifact_types.harn",
100 "context/maintenance" => "stdlib/context/maintenance.harn",
101 "context/eval" => "stdlib/context/eval.harn",
102 "context/disclosure" => "stdlib/context/disclosure.harn",
103 "eval/stats" => "stdlib/stdlib_eval_stats.harn",
104 "eval/remote_fanout" => "stdlib/eval/remote_fanout.harn",
105 "eval/sequential" => "stdlib/eval/sequential.harn",
106 "eval/calibration" => "stdlib/eval/calibration.harn",
107 "eval/selective_risk" => "stdlib/eval/selective_risk.harn",
108 "eval/experiment" => "stdlib/eval/experiment.harn",
109 "eval/experiment/contracts" => "stdlib/eval/experiment/contracts.harn",
110 "eval/experiment/assignment" => "stdlib/eval/experiment/assignment.harn",
111 "eval/experiment/decision" => "stdlib/eval/experiment/decision.harn",
112 "eval/hypothesis" => "stdlib/eval/hypothesis.harn",
113 "eval/hypothesis/capabilities" => "stdlib/eval/hypothesis/capabilities.harn",
114 "eval/hypothesis/contracts" => "stdlib/eval/hypothesis/contracts.harn",
115 "eval/hypothesis/compiler" => "stdlib/eval/hypothesis/compiler.harn",
116 "eval/hypothesis/intent_boundary" => "stdlib/eval/hypothesis/intent_boundary.harn",
117 "eval/hypothesis/json_identity" => "stdlib/eval/hypothesis/json_identity.harn",
118 "eval/hypothesis/ledger_contracts" => "stdlib/eval/hypothesis/ledger_contracts.harn",
119 "eval/hypothesis/ledger" => "stdlib/eval/hypothesis/ledger.harn",
120 "eval/hypothesis/planner" => "stdlib/eval/hypothesis/planner.harn",
121 "eval/hypothesis/report" => "stdlib/eval/hypothesis/report.harn",
122 "eval/hypothesis/policies" => "stdlib/eval/hypothesis/policies.harn",
123 "eval/hypothesis/workflow_contracts" => "stdlib/eval/hypothesis/workflow_contracts.harn",
124 "eval/hypothesis/workflow" => "stdlib/eval/hypothesis/workflow.harn",
125 "eval/agreement" => "stdlib/stdlib_eval_agreement.harn",
126 "runtime" => "stdlib/stdlib_runtime.harn",
127 "runtime/content_fingerprint" => "stdlib/runtime/content_fingerprint.harn",
128 "runtime/install" => "stdlib/runtime/install.harn",
129 "runtime/bootstrap" => "stdlib/runtime/bootstrap.harn",
130 "io" => "stdlib/stdlib_io.harn",
131 "net" => "stdlib/stdlib_net.harn",
132 "command" => "stdlib/stdlib_command.harn",
133 "command/foundation" => "stdlib/command/foundation.harn",
134 "command/output" => "stdlib/command/output.harn",
135 "command/results" => "stdlib/command/results.harn",
136 "command/shell" => "stdlib/command/shell.harn",
137 "command/step_ref" => "stdlib/command/step_ref.harn",
138 "runner_pool" => "stdlib/stdlib_runner_pool.harn",
139 "verification_types" => "stdlib/verification_types.harn",
140 "verification_core" => "stdlib/verification_core.harn",
141 "verification_targets" => "stdlib/verification_targets.harn",
142 "verification_ladder" => "stdlib/verification_ladder.harn",
143 "verification_public" => "stdlib/verification_public.harn",
144 "signal" => "stdlib/stdlib_signal.harn",
145 "net_policy" => "stdlib/stdlib_net_policy.harn",
146 "review" => "stdlib/stdlib_review.harn",
147 "experiments" => "stdlib/stdlib_experiments.harn",
148 "project" => "stdlib/stdlib_project.harn",
149 "prompt_library" => "stdlib/stdlib_prompt_library.harn",
150 "async" => "stdlib/stdlib_async.harn",
151 "poll" => "stdlib/stdlib_poll.harn",
152 "coerce" => "stdlib/stdlib_coerce.harn",
153 "settled" => "stdlib/stdlib_settled.harn",
154 "abort" => "stdlib/stdlib_abort.harn",
155 "cli" => "stdlib/stdlib_cli.harn",
156 "cli/argparse" => "stdlib/cli/argparse.harn",
157 "cli/envelope" => "stdlib/cli/envelope.harn",
158 "cli/render" => "stdlib/cli/render.harn",
159 "cli/models/batch_artifacts" => "stdlib/cli/models/batch_artifacts.harn",
160 "cli/models/batch_cancel" => "stdlib/cli/models/batch_cancel.harn",
161 "cli/models/batch_download" => "stdlib/cli/models/batch_download.harn",
162 "cli/models/batch_lifecycle" => "stdlib/cli/models/batch_lifecycle.harn",
163 "cli/models/batch_rejoin" => "stdlib/cli/models/batch_rejoin.harn",
164 "cli/models/batch_status" => "stdlib/cli/models/batch_status.harn",
165 "cli/models/batch_submit" => "stdlib/cli/models/batch_submit.harn",
166 "cli/models/batch_transport" => "stdlib/cli/models/batch_transport.harn",
167 "cli/models/lora_render" => "stdlib/cli/models/lora_render.harn",
168 "cli/paths" => "stdlib/cli/paths.harn",
169 "cli/providers/contracts" => "stdlib/cli/providers/contracts.harn",
170 "gha" => "stdlib/stdlib_gha.harn",
171 "tui" => "stdlib/stdlib_tui.harn",
172 "jsonl" => "stdlib/stdlib_jsonl.harn",
173 "config" => "stdlib/stdlib_config.harn",
174 "calendar" => "stdlib/stdlib_calendar.harn",
175 "activity/vocabulary" => "stdlib/activity/vocabulary.harn",
176 "activity/tool_permission" => "stdlib/activity/tool_permission.harn",
177 "external_action" => "stdlib/stdlib_external_action.harn",
178 "external_action/vocabulary" => "stdlib/external_action/vocabulary.harn",
179 "external_action/contracts" => "stdlib/external_action/contracts.harn",
180 "external_action/disclosure" => "stdlib/external_action/disclosure.harn",
181 "external_action/activity" => "stdlib/external_action/activity.harn",
182 "external_action/policy" => "stdlib/external_action/policy.harn",
183 "external_action/runtime" => "stdlib/external_action/runtime.harn",
184 "external_action/testing" => "stdlib/external_action/testing.harn",
185 "agents" => "stdlib/stdlib_agents.harn",
186 "lifecycle/pool" => "stdlib/lifecycle/pool.harn",
187 "lifecycle/combinators" => "stdlib/lifecycle/combinators.harn",
188 "lifecycle/on_budget" => "stdlib/lifecycle/on_budget.harn",
189 "lifecycle/progress" => "stdlib/lifecycle/progress.harn",
190 "agent/prompts" => "stdlib/agent/prompts.harn",
191 "llm/media" => "stdlib/llm/media.harn",
192 "media/asset" => "stdlib/media/asset.harn",
193 "media/composition" => "stdlib/media/composition.harn",
194 "model_job" => "stdlib/stdlib_model_job.harn",
195 "model_job/contracts" => "stdlib/model_job/contracts.harn",
196 "model_job/runtime" => "stdlib/model_job/runtime.harn",
197 "model_job/testing" => "stdlib/model_job/testing.harn",
198 "model_job/comfyui" => "stdlib/model_job/comfyui.harn",
199 "model_job/openai" => "stdlib/model_job/openai.harn",
200 "portable" => "stdlib/stdlib_portable.harn",
201 "ui" => "stdlib/stdlib_ui.harn",
202 "ui/contracts" => "stdlib/ui/contracts.harn",
203 "ui/renderer" => "stdlib/ui/renderer.harn",
204 "ui/testing" => "stdlib/ui/testing.harn",
205 "llm/options" => "stdlib/llm/options.harn",
206 "llm/provider_names" => "stdlib/llm/provider_names.harn",
207 "llm/catalog" => "stdlib/llm/catalog.harn",
208 "llm/cache_conformance" => "stdlib/llm/cache_conformance.harn",
209 "llm/safe" => "stdlib/llm/safe.harn",
210 "llm/envelope" => "stdlib/llm/envelope.harn",
211 "llm/speed" => "stdlib/llm/speed.harn",
212 "llm/chat_session" => "stdlib/llm/chat_session.harn",
213 "llm/caller" => "stdlib/llm/caller.harn",
214 "harness/policy" => "stdlib/harness/policy.harn",
215 "llm/budget" => "stdlib/llm/budget.harn",
216 "llm/tokenizer" => "stdlib/llm/tokenizer.harn",
217 "llm/economics" => "stdlib/llm/economics.harn",
218 "llm/prompts" => "stdlib/llm/prompts.harn",
219 "llm/defaults" => "stdlib/llm/defaults.harn",
220 "llm/handlers" => "stdlib/llm/handlers.harn",
221 "llm/handler_cache_events" => "stdlib/llm/handler_cache_events.harn",
222 "llm/resilience" => "stdlib/llm/resilience.harn",
223 "llm/tool_telemetry" => "stdlib/llm/tool_telemetry.harn",
224 "llm/tool_middleware" => "stdlib/llm/tool_middleware.harn",
225 "llm/tool_binder" => "stdlib/llm/tool_binder.harn",
226 "llm/structural_validator" => "stdlib/llm/structural_validator.harn",
227 "llm/missing_tool_call" => "stdlib/llm/missing_tool_call.harn",
228 "llm/call_shape" => "stdlib/llm/call_shape.harn",
229 "llm/tool_shape" => "stdlib/llm/tool_shape.harn",
230 "llm/dialects" => "stdlib/llm/dialects.harn",
231 "llm/tool_parse" => "stdlib/llm/tool_parse.harn",
232 "llm/tool_parse_body" => "stdlib/llm/tool_parse_body.harn",
233 "llm/tool_parse_envelope" => "stdlib/llm/tool_parse_envelope.harn",
234 "llm/tool_parse_json_support" => "stdlib/llm/tool_parse_json_support.harn",
235 "llm/tool_parse_protocol" => "stdlib/llm/tool_parse_protocol.harn",
236 "llm/tool_parse_provider" => "stdlib/llm/tool_parse_provider.harn",
237 "llm/tool_parse_result" => "stdlib/llm/tool_parse_result.harn",
238 "llm/tool_parse_scan_spec" => "stdlib/llm/tool_parse_scan_spec.harn",
239 "llm/scope_classifier" => "stdlib/llm/scope_classifier.harn",
240 "llm/refine" => "stdlib/llm/refine.harn",
241 "llm/ensemble" => "stdlib/llm/ensemble.harn",
242 "llm/rerank" => "stdlib/llm/rerank.harn",
243 "agent/reasoning" => "stdlib/agent/reasoning.harn",
244 "agent/caller_transport" => "stdlib/agent/caller_transport.harn",
245 "agent/options" => "stdlib/agent/options.harn",
246 "agent/options_types" => "stdlib/agent/options_types.harn",
247 "agent/failure_types" => "stdlib/agent/failure_types.harn",
248 "agent/options_formats" => "stdlib/agent/options_formats.harn",
249 "agent/options_surface" => "stdlib/agent/options_surface.harn",
250 "agent/options_validation" => "stdlib/agent/options_validation.harn",
251 "agent/options_public" => "stdlib/agent/options_public.harn",
252 "agent/llm_dispatch" => "stdlib/agent/llm_dispatch.harn",
253 "agent/prefill" => "stdlib/agent/prefill.harn",
254 "agent/retry" => "stdlib/agent/retry.harn",
255 "llm/judge" => "stdlib/llm/judge.harn",
256 "llm/faithfulness" => "stdlib/llm/faithfulness.harn",
257 "llm/optimize" => "stdlib/llm/optimize.harn",
258 "agent/events" => "stdlib/agent/events.harn",
259 "agent/feedback" => "stdlib/agent/feedback.harn",
260 "agent/transcript" => "stdlib/agent/transcript.harn",
261 "agent/artifacts" => "stdlib/agent/artifacts.harn",
262 "agent/primitives" => "stdlib/agent/primitives.harn",
263 "agent/compaction_classify" => "stdlib/agent/compaction_classify.harn",
264 "agent/progress" => "stdlib/agent/progress.harn",
265 "agent/required_tools" => "stdlib/agent/required_tools.harn",
266 "agent/required_artifacts" => "stdlib/agent/required_artifacts.harn",
267 "agent/loop_turn_setup" => "stdlib/agent/loop_turn_setup.harn",
268 "agent/purpose_labels" => "stdlib/agent/purpose_labels.harn",
269 "agent/loop_purpose_labels" => "stdlib/agent/loop_purpose_labels.harn",
270 "agent/monologue_actuation" => "stdlib/agent/monologue_actuation.harn",
271 "agent/monologue_actuation_types" => "stdlib/agent/monologue_actuation_types.harn",
272 "agent/stall_types" => "stdlib/agent/stall_types.harn",
273 "agent/stall" => "stdlib/agent/stall.harn",
274 "agent/recurring_diagnostic" => "stdlib/agent/recurring_diagnostic.harn",
275 "agent/stall_config" => "stdlib/agent/stall_config.harn",
276 "agent/stall_checkpoint" => "stdlib/agent/stall_checkpoint.harn",
277 "agent/stall_feedback" => "stdlib/agent/stall_feedback.harn",
278 "agent/stall_action_observation" => "stdlib/agent/stall_action_observation.harn",
279 "agent/stall_observation" => "stdlib/agent/stall_observation.harn",
280 "agent/stall_verification" => "stdlib/agent/stall_verification.harn",
281 "agent/stall_detectors" => "stdlib/agent/stall_detectors.harn",
282 "agent/run_meter" => "stdlib/agent/run_meter.harn",
283 "agent/cut_landing" => "stdlib/agent/cut_landing.harn",
284 "agent/cut_rules" => "stdlib/agent/cut_rules.harn",
285 "agent/governors" => "stdlib/agent/governors.harn",
286 "agent/control" => "stdlib/agent/control.harn",
287 "agent/action_graph" => "stdlib/agent/action_graph.harn",
288 "agent/result_text" => "stdlib/agent/result_text.harn",
289 "agent/best_of_n" => "stdlib/agent/best_of_n.harn",
290 "agent/loop" => "stdlib/agent/loop.harn",
291 "agent/loop_support" => "stdlib/agent/loop_support.harn",
292 "agent/loop_call_budget" => "stdlib/agent/loop_call_budget.harn",
293 "agent/loop_call_resolution" => "stdlib/agent/loop_call_resolution.harn",
294 "agent/loop_await" => "stdlib/agent/loop_await.harn",
295 "agent/loop_denial_cutoff" => "stdlib/agent/loop_denial_cutoff.harn",
296 "agent/loop_result_status" => "stdlib/agent/loop_result_status.harn",
297 "agent/loop_foundation" => "stdlib/agent/loop_foundation.harn",
298 "agent/loop_lifecycle" => "stdlib/agent/loop_lifecycle.harn",
299 "agent/loop_provider_failure" => "stdlib/agent/loop_provider_failure.harn",
300 "agent/loop_audit_flushes" => "stdlib/agent/loop_audit_flushes.harn",
301 "agent/loop_tool_calls" => "stdlib/agent/loop_tool_calls.harn",
302 "agent/loop_resource_dispatch" => "stdlib/agent/loop_resource_dispatch.harn",
303 "agent/loop_dispatch_options" => "stdlib/agent/loop_dispatch_options.harn",
304 "agent/loop_turn_options" => "stdlib/agent/loop_turn_options.harn",
305 "agent/session_health" => "stdlib/agent/session_health.harn",
306 "agent/loop_turn_scope" => "stdlib/agent/loop_turn_scope.harn",
307 "agent/loop_turn_projection" => "stdlib/agent/loop_turn_projection.harn",
308 "agent/loop_internal" => "stdlib/agent/loop_internal.harn",
309 "agent/loop_run" => "stdlib/agent/loop_run.harn",
310 "agent/loop_post_turn" => "stdlib/agent/loop_post_turn.harn",
311 "agent/loop_finalize" => "stdlib/agent/loop_finalize.harn",
312 "agent/loop_terminal" => "stdlib/agent/loop_terminal.harn",
313 "agent/user" => "stdlib/agent/user.harn",
314 "agent/tool_search" => "stdlib/agent/tool_search.harn",
315 "agent/tool_annotations" => "stdlib/agent/tool_annotations.harn",
316 "agent/tool_lifecycle" => "stdlib/agent/tool_lifecycle.harn",
317 "agent/workers" => "stdlib/agent/workers.harn",
318 "agent/introspection" => "stdlib/agent/introspection.harn",
319 "agent/resume_by" => "stdlib/agent/resume_by.harn",
320 "agent/state" => "stdlib/agent/state.harn",
321 "agent/truncation" => "stdlib/agent/truncation.harn",
322 "agent/canon" => "stdlib/agent/canon.harn",
323 "agent/skills" => "stdlib/agent/skills.harn",
324 "agent/workspace_guidance" => "stdlib/agent/workspace_guidance.harn",
325 "agent/autocompact" => "stdlib/agent/autocompact.harn",
326 "agent/response_compaction" => "stdlib/agent/response_compaction.harn",
327 "agent/mcp" => "stdlib/agent/mcp.harn",
328 "agent/command_capture" => "stdlib/agent/command_capture.harn",
329 "agent/host_read_budget" => "stdlib/agent/host_read_budget.harn",
330 "agent/host_command_result" => "stdlib/agent/host_command_result.harn",
331 "agent/contracts" => "stdlib/agent/contracts.harn",
332 "agent/command_ledger" => "stdlib/agent/command_ledger.harn",
333 "agent/host_tools" => "stdlib/agent/host_tools.harn",
334 "agent/host_injection" => "stdlib/agent/host_injection.harn",
335 "agent/budget" => "stdlib/agent/budget.harn",
336 "agent/daemon" => "stdlib/agent/daemon.harn",
337 "agent/preflight" => "stdlib/agent/preflight.harn",
338 "agent/postturn" => "stdlib/agent/postturn.harn",
339 "agent/turn_end" => "stdlib/agent/turn_end.harn",
340 "agent/tool_surface" => "stdlib/agent/tool_surface.harn",
341 "agent/stance" => "stdlib/agent/stance.harn",
342 "agent/lanes" => "stdlib/agent/lanes.harn",
343 "agent/overlays" => "stdlib/agent/overlays.harn",
344 "agent/sitrep" => "stdlib/agent/sitrep.harn",
345 "agent/verdict" => "stdlib/agent/verdict.harn",
346 "agent/judge_internals" => "stdlib/agent/judge_internals.harn",
347 "agent/judge_itemization" => "stdlib/agent/judge_itemization.harn",
348 "agent/judge_contradiction" => "stdlib/agent/judge_contradiction.harn",
349 "agent/judge_arbitration" => "stdlib/agent/judge_arbitration.harn",
350 "agent/judge_evidence" => "stdlib/agent/judge_evidence.harn",
351 "agent/loop_await_turn" => "stdlib/agent/loop_await_turn.harn",
352 "agent/loop_structural_veto" => "stdlib/agent/loop_structural_veto.harn",
353 "agent/loop_skipped_dispatch" => "stdlib/agent/loop_skipped_dispatch.harn",
354 "agent/judge_verdict" => "stdlib/agent/judge_verdict.harn",
355 "agent/completion_gate" => "stdlib/agent/completion_gate.harn",
356 "agent/completion_review" => "stdlib/agent/completion_review.harn",
357 "agent/completion_requirements" => "stdlib/agent/completion_requirements.harn",
358 "agent/completion_claim" => "stdlib/agent/completion_claim.harn",
359 "agent/completion_evidence" => "stdlib/agent/completion_evidence.harn",
360 "agent/completion_precheck" => "stdlib/agent/completion_precheck.harn",
361 "agent/completion_verification" => "stdlib/agent/completion_verification.harn",
362 "agent/judge_precheck" => "stdlib/agent/judge_precheck.harn",
363 "agent/obligations" => "stdlib/agent/obligations.harn",
364 "agent/judge" => "stdlib/agent/judge.harn",
365 "agent/approval_review" => "stdlib/agent/approval_review.harn",
366 "agent/approval_review_policy_types" => "stdlib/agent/approval_review_policy_types.harn",
367 "agent/approval_review_calibration" => "stdlib/agent/approval_review_calibration.harn",
368 "agent/guardrails" => "stdlib/agent/guardrails.harn",
369 "agent/step_judge" => "stdlib/agent/step_judge.harn",
370 "agent/scratchpad" => "stdlib/agent/scratchpad.harn",
371 "agent/fact" => "stdlib/agent/fact.harn",
372 "agent/hypothesis" => "stdlib/agent/hypothesis.harn",
373 "agent/pattern_knowledge_values" => "stdlib/agent/pattern_knowledge_values.harn",
374 "agent/pattern_knowledge_curated" => "stdlib/agent/pattern_knowledge_curated.harn",
375 "agent/pattern_knowledge_persistence" => "stdlib/agent/pattern_knowledge_persistence.harn",
376 "agent/pattern_knowledge_matching" => "stdlib/agent/pattern_knowledge_matching.harn",
377 "agent/pattern_knowledge" => "stdlib/agent/pattern_knowledge.harn",
378 "agent/crystallization_curator" => "stdlib/agent/crystallization_curator.harn",
379 "agent/probe" => "stdlib/agent/probe.harn",
380 "agent/stream" => "stdlib/agent/stream.harn",
381 "agent/presets" => "stdlib/agent/presets.harn",
382 "agent/pins" => "stdlib/agent/pins.harn",
383 "agent/goal" => "stdlib/agent/goal.harn",
384 "agent/goal_contract" => "stdlib/agent/goal_contract.harn",
385 "agent/goal_projection" => "stdlib/agent/goal_projection.harn",
386 "agent/task_plan" => "stdlib/agent/task_plan.harn",
387 "personas/compiler" => "stdlib/personas/compiler.harn",
388 "personas/prompt_compiler" => "stdlib/personas/prompt_compiler.harn",
389 "agent_state" => "stdlib/stdlib_agent_state.harn",
390 "memory" => "stdlib/stdlib_memory.harn",
391 "session-store" => "stdlib/stdlib_session_store.harn",
392 "coordination" => "stdlib/stdlib_coordination.harn",
393 "coordination/append_metadata" => "stdlib/coordination/append_metadata.harn",
394 "coordination/schema" => "stdlib/coordination/schema.harn",
395 "execution" => "stdlib/stdlib_execution.harn",
396 "fleet/coordination" => "stdlib/fleet/coordination.harn",
397 "postgres" => "stdlib/stdlib_postgres.harn",
398 "postgres/query" => "stdlib/postgres/query.harn",
399 "sqlite" => "stdlib/stdlib_sqlite.harn",
400 "checkpoint" => "stdlib/stdlib_checkpoint.harn",
401 "host" => "stdlib/stdlib_host.harn",
402 "host_conditions" => "stdlib/stdlib_host_conditions.harn",
403 "host_lease" => "stdlib/stdlib_host_lease.harn",
404 "git" => "stdlib/stdlib_git.harn",
405 "git/checkout" => "stdlib/git/checkout.harn",
406 "git/contracts" => "stdlib/git/contracts.harn",
407 "git/command_plan" => "stdlib/git/command_plan.harn",
408 "hitl" => "stdlib/stdlib_hitl.harn",
409 "trust" => "stdlib/stdlib_trust.harn",
410 "corrections" => "stdlib/stdlib_corrections.harn",
411 "plan" => "stdlib/stdlib_plan.harn",
412 "waitpoint" => "stdlib/stdlib_waitpoint.harn",
413 "monitors" => "stdlib/stdlib_monitors.harn",
414 "worktree" => "stdlib/stdlib_worktree.harn",
415 "acp" => "stdlib/stdlib_acp.harn",
416 "external_agent" => "stdlib/stdlib_external_agent.harn",
417 "triggers" => "stdlib/stdlib_triggers.harn",
418 "triage" => "stdlib/stdlib_triage.harn",
419 "dashboard/jobs" => "stdlib/dashboard/jobs.harn",
420 "ui_resource" => "stdlib/stdlib_ui_resource.harn",
421 "handoffs" => "stdlib/stdlib_handoffs.harn",
422 "lifecycle" => "stdlib/stdlib_lifecycle.harn",
423 "tool_hooks_catalogues" => "stdlib/stdlib_tool_hooks_catalogues.harn",
424 "tool_hooks" => "stdlib/stdlib_tool_hooks.harn",
425 "channel_guardrails" => "stdlib/stdlib_channel_guardrails.harn",
426 "personas/prelude" => "stdlib/stdlib_personas_prelude.harn",
427 "personas/bulletins" => "stdlib/stdlib_personas_bulletins.harn",
428 "connectors/shared" => "stdlib/stdlib_connectors_shared.harn",
429 "connectors/http" => "stdlib/connectors/http.harn",
430 "connectors/setup" => "stdlib/connectors/setup.harn",
431 "oauth/providers" => "stdlib/oauth/providers.harn",
432 "oauth/token_exchange_catalog" => "stdlib/oauth/token_exchange_catalog.harn",
433 "oauth/token_exchange" => "stdlib/oauth/token_exchange.harn",
434 "oauth/storage" => "stdlib/oauth/storage.harn",
435 "oauth/client" => "stdlib/oauth/client.harn",
436 "oauth/device_flow" => "stdlib/oauth/device_flow.harn",
437 "oauth/redaction" => "stdlib/oauth/redaction.harn",
438 "oauth/dynamic_registration" => "stdlib/oauth/dynamic_registration.harn",
439 "connectors/github" => "stdlib/stdlib_connectors_github.harn",
440 "connectors/github/repository" => "stdlib/connectors/github/repository.harn",
441 "connectors/linear" => "stdlib/stdlib_connectors_linear.harn",
442 "connectors/slack" => "stdlib/stdlib_connectors_slack.harn",
443 "workflow/prompts" => "stdlib/workflow/prompts.harn",
444 "workflow/context" => "stdlib/workflow/context.harn",
445 "workflow/options" => "stdlib/workflow/options.harn",
446 "workflow/checkpoints" => "stdlib/workflow/checkpoints.harn",
447 "workflow/patterns" => "stdlib/workflow/patterns.harn",
448 "workflow/stage" => "stdlib/workflow/stage.harn",
449 "workflow/map" => "stdlib/workflow/map.harn",
450 "workflow/schedule" => "stdlib/workflow/schedule.harn",
451 "workflow/execute" => "stdlib/workflow/execute.harn",
452 "workflow/repair" => "stdlib/workflow/repair.harn",
453 "security" => "stdlib/stdlib_security.harn",
454 "pii" => "stdlib/stdlib_pii.harn",
455 "bump/runtime" => "stdlib/bump/runtime.harn",
456 "bump/repairs" => "stdlib/bump/repairs.harn",
457 "bump/live" => "stdlib/bump/live.harn",
458]);
459
460pub const CONNECTOR_EVENT_SCHEMAS_SOURCE: &str = include_str!("stdlib/stdlib_event_schemas.harn");
471
472pub const STDLIB_PROMPT_ASSETS: &[StdlibPromptAsset] = embedded_catalog!(StdlibPromptAsset, path, [
473 "eval/hypothesis/prompts/intake.harn.prompt" => "stdlib/eval/hypothesis/prompts/intake.harn.prompt",
474 "agent/prompts/tool_contract_text.harn.prompt" => "stdlib/agent/prompts/tool_contract_text.harn.prompt",
475 "agent/prompts/tool_contract_json.harn.prompt" => "stdlib/agent/prompts/tool_contract_json.harn.prompt",
476 "agent/prompts/tool_contract_native.harn.prompt" => "stdlib/agent/prompts/tool_contract_native.harn.prompt",
477 "agent/prompts/tool_contract_text_response_protocol.harn.prompt" => "stdlib/agent/prompts/tool_contract_text_response_protocol.harn.prompt",
478 "agent/prompts/tool_contract_action_native.harn.prompt" => "stdlib/agent/prompts/tool_contract_action_native.harn.prompt",
479 "agent/prompts/tool_contract_action_text.harn.prompt" => "stdlib/agent/prompts/tool_contract_action_text.harn.prompt",
480 "agent/prompts/tool_contract_task_ledger.harn.prompt" => "stdlib/agent/prompts/tool_contract_task_ledger.harn.prompt",
481 "agent/prompts/tool_contract_deferred_tools.harn.prompt" => "stdlib/agent/prompts/tool_contract_deferred_tools.harn.prompt",
482 "agent/prompts/deferred_tool_listing.harn.prompt" => "stdlib/agent/prompts/deferred_tool_listing.harn.prompt",
483 "agent/prompts/default_nudge.harn.prompt" => "stdlib/agent/prompts/default_nudge.harn.prompt",
484 "agent/prompts/agentic_user_system.harn.prompt" => "stdlib/agent/prompts/agentic_user_system.harn.prompt",
485 "agent/prompts/agentic_user_user.harn.prompt" => "stdlib/agent/prompts/agentic_user_user.harn.prompt",
486 "agent/prompts/loop_until_done_system.harn.prompt" => "stdlib/agent/prompts/loop_until_done_system.harn.prompt",
487 "agent/prompts/completion_judge_default.harn.prompt" => "stdlib/agent/prompts/completion_judge_default.harn.prompt",
488 "agent/prompts/completion_judge_feedback_fallback.harn.prompt" => "stdlib/agent/prompts/completion_judge_feedback_fallback.harn.prompt",
489 "agent/prompts/completion_judge_user.harn.prompt" => "stdlib/agent/prompts/completion_judge_user.harn.prompt",
490 "agent/prompts/step_judge_system_default.harn.prompt" => "stdlib/agent/prompts/step_judge_system_default.harn.prompt",
491 "agent/prompts/step_judge_system_adversarial.harn.prompt" => "stdlib/agent/prompts/step_judge_system_adversarial.harn.prompt",
492 "agent/prompts/step_judge_user.harn.prompt" => "stdlib/agent/prompts/step_judge_user.harn.prompt",
493 "agent/prompts/parse_guidance.harn.prompt" => "stdlib/agent/prompts/parse_guidance.harn.prompt",
494 "agent/prompts/native_tool_contract_feedback.harn.prompt" => "stdlib/agent/prompts/native_tool_contract_feedback.harn.prompt",
495 "agent/prompts/verification_gate_feedback.harn.prompt" => "stdlib/agent/prompts/verification_gate_feedback.harn.prompt",
496 "agent/prompts/daemon_watch_feedback.harn.prompt" => "stdlib/agent/prompts/daemon_watch_feedback.harn.prompt",
497 "agent/prompts/daemon_timer_feedback.harn.prompt" => "stdlib/agent/prompts/daemon_timer_feedback.harn.prompt",
498 "llm/prompts/completion_fallback_system.harn.prompt" => "stdlib/llm/prompts/completion_fallback_system.harn.prompt",
499 "llm/prompts/completion_fallback_user.harn.prompt" => "stdlib/llm/prompts/completion_fallback_user.harn.prompt",
500 "llm/prompts/transcript_summarize_user.harn.prompt" => "stdlib/llm/prompts/transcript_summarize_user.harn.prompt",
501 "llm/prompts/sitrep_user.harn.prompt" => "stdlib/llm/prompts/sitrep_user.harn.prompt",
502 "llm/prompts/structural_chain_of_draft.harn.prompt" => "stdlib/llm/prompts/structural_chain_of_draft.harn.prompt",
503 "llm/prompts/schema_recover_repair.harn.prompt" => "stdlib/llm/prompts/schema_recover_repair.harn.prompt",
504 "llm/prompts/structured_envelope_schema_contract.harn.prompt" => "stdlib/llm/prompts/structured_envelope_schema_contract.harn.prompt",
505 "llm/prompts/structured_envelope_repair.harn.prompt" => "stdlib/llm/prompts/structured_envelope_repair.harn.prompt",
506 "llm/prompts/directive_envelope_instructions.harn.prompt" => "stdlib/llm/prompts/directive_envelope_instructions.harn.prompt",
507 "llm/prompts/directive_nonce_authority.harn.prompt" => "stdlib/llm/prompts/directive_nonce_authority.harn.prompt",
508 "llm/prompts/pairwise_rerank_user.harn.prompt" => "stdlib/llm/prompts/pairwise_rerank_user.harn.prompt",
509 "llm/prompts/tool_binder_user.harn.prompt" => "stdlib/llm/prompts/tool_binder_user.harn.prompt",
510 "llm/prompts/missing_tool_call_intent.harn.prompt" => "stdlib/llm/prompts/missing_tool_call_intent.harn.prompt",
511 "llm/prompts/missing_tool_call_target.harn.prompt" => "stdlib/llm/prompts/missing_tool_call_target.harn.prompt",
512 "llm/prompts/evaluation_questions.harn.prompt" => "stdlib/llm/prompts/evaluation_questions.harn.prompt",
513 "agent/prompts/compaction_classify.harn.prompt" => "stdlib/agent/prompts/compaction_classify.harn.prompt",
514 "agent/prompts/compaction_rewrite.harn.prompt" => "stdlib/agent/prompts/compaction_rewrite.harn.prompt",
515 "workflow/prompts/stage.harn.prompt" => "stdlib/workflow/prompts/stage.harn.prompt",
516 "workflow/prompts/verification_context_intro.harn.prompt" => "stdlib/workflow/prompts/verification_context_intro.harn.prompt",
517 "orchestration/prompts/compaction_summary.harn.prompt" => "stdlib/orchestration/prompts/compaction_summary.harn.prompt",
518 "orchestration/prompts/compaction_policy_extension.harn.prompt" => "stdlib/orchestration/prompts/compaction_policy_extension.harn.prompt",
519 "orchestration/prompts/compaction_policy_replacement.harn.prompt" => "stdlib/orchestration/prompts/compaction_policy_replacement.harn.prompt",
520 "orchestration/prompts/compaction_state_grounding.harn.prompt" => "stdlib/orchestration/prompts/compaction_state_grounding.harn.prompt",
521]);
522
523pub const STDLIB_CLI_SCRIPTS: &[StdlibCliScript] = embedded_catalog!(StdlibCliScript, name, [
524 "codemod" => "stdlib/cli/codemod.harn",
525 "canon/check" => "stdlib/cli/canon/check.harn",
526 "chat" => "stdlib/cli/chat.harn",
527 "doctor" => "stdlib/cli/doctor.harn",
528 "echo" => "stdlib/cli/echo.harn",
529 "eval/_runner" => "stdlib/cli/eval/_runner.harn",
533 "eval/context" => "stdlib/cli/eval/context.harn",
534 "eval/model_selector" => "stdlib/cli/eval/model_selector.harn",
535 "eval/tool_calls" => "stdlib/cli/eval/tool_calls.harn",
536 "eval/coding_agent" => "stdlib/cli/eval/coding_agent.harn",
537 "eval/scope_triage" => "stdlib/cli/eval/scope_triage.harn",
538 "eval/calibrate" => "stdlib/cli/eval/calibrate.harn",
539 "eval/prompt" => "stdlib/cli/eval/prompt.harn",
540 "explain" => "stdlib/cli/explain.harn",
541 "graph" => "stdlib/cli/graph.harn",
542 "personas/compile_prompt" => "stdlib/cli/personas/compile_prompt.harn",
543 "personas/materialize" => "stdlib/cli/personas/materialize.harn",
544 "models/batch_plan" => "stdlib/cli/models/batch_plan.harn",
545 "models/list" => "stdlib/cli/models/list.harn",
546 "models/lora_inspect" => "stdlib/cli/models/lora_inspect.harn",
547 "models/lora_export" => "stdlib/cli/models/lora_export.harn",
548 "models/lora_manifest" => "stdlib/cli/models/lora_manifest.harn",
549 "models/lora_preflight" => "stdlib/cli/models/lora_preflight.harn",
550 "models/lora_promote" => "stdlib/cli/models/lora_promote.harn",
551 "models/lora_plan" => "stdlib/cli/models/lora_plan.harn",
552 "models/lora_train" => "stdlib/cli/models/lora_train.harn",
553 "models/recommend" => "stdlib/cli/models/recommend.harn",
554 "models/test" => "stdlib/cli/models/test.harn",
555 "precompile" => "stdlib/cli/precompile.harn",
556 "providers/cache_probe" => "stdlib/cli/providers/cache_probe.harn",
557 "providers/catalog" => "stdlib/cli/providers/catalog.harn",
558 "providers/effort_probe" => "stdlib/cli/providers/effort_probe.harn",
559 "providers/option_probe" => "stdlib/cli/providers/option_probe.harn",
560 "providers/probe" => "stdlib/cli/providers/probe.harn",
561 "providers/recommend" => "stdlib/cli/providers/recommend.harn",
562 "providers/tool_probe" => "stdlib/cli/providers/tool_probe.harn",
563 "providers/tool_scorecard" => "stdlib/cli/providers/tool_scorecard.harn",
564 "routes" => "stdlib/cli/routes.harn",
565 "runs/export_training" => "stdlib/cli/runs/export_training.harn",
566 "scan" => "stdlib/cli/scan.harn",
567 "scaffold/init" => "stdlib/cli/scaffold/init.harn",
568 "scaffold/tool_new" => "stdlib/cli/scaffold/tool_new.harn",
569 "trace_import" => "stdlib/cli/trace_import.harn",
570 "try" => "stdlib/cli/try.harn",
571 "version" => "stdlib/cli/version.harn",
572]);
573
574pub static CATALOG: StdlibCatalog = StdlibCatalog {
577 sources: STDLIB_SOURCES,
578 prompt_assets: STDLIB_PROMPT_ASSETS,
579 cli_scripts: STDLIB_CLI_SCRIPTS,
580};
581
582pub fn install() -> Result<(), harn_stdlib_catalog::CatalogAlreadyInstalled> {
589 harn_stdlib_catalog::install(&CATALOG)
590}
591
592pub fn get_stdlib_source(module: &str) -> Option<&'static str> {
593 CATALOG.source(module)
594}
595
596pub fn find_cli_script(name: &str) -> Option<&'static str> {
600 CATALOG.cli_script(name)
601}
602
603pub fn get_stdlib_prompt_asset(path: &str) -> Option<&'static str> {
604 CATALOG.prompt_asset(path)
605}
606
607pub fn public_functions_for_module(module: &str) -> Vec<StdlibPublicFunction> {
608 let Some(source) = get_stdlib_source(module) else {
609 return Vec::new();
610 };
611 public_functions_from_source(source)
612}
613
614pub fn entrypoint_modules() -> Vec<StdlibEntrypointModule> {
615 STDLIB_SOURCES
616 .iter()
617 .filter_map(|entry| {
618 entrypoint_category_from_source(entry.source).map(|category| StdlibEntrypointModule {
619 import_path: format!("std/{}", entry.module),
620 category,
621 })
622 })
623 .collect()
624}
625
626fn entrypoint_category_from_source(source: &str) -> Option<String> {
627 for line in source.lines() {
628 let line = line.trim();
629 if line.is_empty() {
630 continue;
631 }
632 if let Some(category) = line.strip_prefix("// @harn-entrypoint-category ") {
633 let category = category.trim();
634 return (!category.is_empty()).then(|| category.to_string());
635 }
636 if !line.starts_with("//") {
637 return None;
638 }
639 }
640 None
641}
642
643fn public_functions_from_source(source: &str) -> Vec<StdlibPublicFunction> {
644 let mut out = Vec::new();
645 let mut doc: Option<String> = None;
646 let lines = source.lines().collect::<Vec<_>>();
647 let mut index = 0usize;
648 while index < lines.len() {
649 let line = lines[index].trim();
650 if line.starts_with("/**") {
651 let (parsed, next) = parse_harndoc(&lines, index);
652 doc = parsed;
653 index = next;
654 continue;
655 }
656 if line.starts_with("pub fn ") {
657 let (signature_line, next) = collect_public_function_signature(&lines, index);
658 if let Some(function) = parse_public_function_line(&signature_line, doc.take()) {
659 out.push(function);
660 index = next;
661 continue;
662 }
663 }
664 if let Some(function) = parse_public_function_line(line, doc.take()) {
665 out.push(function);
666 } else if !line.is_empty() && !line.starts_with("//") {
667 doc = None;
668 }
669 index += 1;
670 }
671 out
672}
673
674fn collect_public_function_signature(lines: &[&str], start: usize) -> (String, usize) {
675 let mut parts = Vec::new();
676 let mut index = start;
677 while index < lines.len() {
678 parts.push(lines[index].trim().to_string());
679 let candidate = parts.join(" ");
680 if public_function_signature_complete(&candidate) {
681 return (candidate, index + 1);
682 }
683 index += 1;
684 }
685 (parts.join(" "), index)
686}
687
688fn public_function_signature_complete(line: &str) -> bool {
689 let Some(rest) = line.strip_prefix("pub fn ") else {
690 return false;
691 };
692 let Some((_, after_paren)) = rest.split_once('(') else {
693 return false;
694 };
695 matching_paren_len(after_paren).is_some()
696}
697
698fn parse_harndoc(lines: &[&str], start: usize) -> (Option<String>, usize) {
699 let mut parts = Vec::new();
700 let mut index = start;
701 while index < lines.len() {
702 let mut line = lines[index].trim();
703 if index == start {
704 line = line.trim_start_matches("/**").trim();
705 }
706 let done = line.ends_with("*/");
707 line = line.trim_end_matches("*/").trim();
708 line = line.trim_start_matches('*').trim();
709 if !line.is_empty() {
710 parts.push(line.to_string());
711 }
712 index += 1;
713 if done {
714 break;
715 }
716 }
717 let text = parts.join("\n").trim().to_string();
718 ((!text.is_empty()).then_some(text), index)
719}
720
721#[expect(
722 clippy::string_slice,
723 reason = "bounds come from str::find and char_indices"
724)]
725fn parse_public_function_line(line: &str, doc: Option<String>) -> Option<StdlibPublicFunction> {
726 let rest = line.strip_prefix("pub fn ")?.trim();
727 let name_end = rest.find('(')?;
728 let declaration_name = rest[..name_end].trim();
729 let name = declaration_name
730 .split_once('<')
731 .map_or(declaration_name, |(name, _)| name.trim());
732 if name.is_empty() {
733 return None;
734 }
735 let params_start = name_end + 1;
736 let params_len = matching_paren_len(&rest[params_start..])?;
737 let params = &rest[params_start..params_start + params_len];
738 let after = rest[params_start + params_len + 1..].trim();
739 let return_type = after
740 .strip_prefix("->")
741 .and_then(|tail| tail.split('{').next())
742 .map(str::trim)
743 .filter(|value| !value.is_empty());
744 let signature = match return_type {
745 Some(ret) => format!("{declaration_name}({params}) -> {ret}"),
746 None => format!("{declaration_name}({params})"),
747 };
748 let param_parts = split_top_level_params(params);
749 let total_params = param_parts
750 .iter()
751 .filter(|param| !param.trim().is_empty())
752 .count();
753 let variadic = param_parts
754 .iter()
755 .any(|param| param.trim_start().starts_with("..."));
756 let required_params = param_parts
757 .iter()
758 .filter(|param| {
759 let param = param.trim();
760 !param.is_empty() && !param.contains('=') && !param.starts_with("...")
761 })
762 .count();
763 Some(StdlibPublicFunction {
764 name: name.to_string(),
765 signature,
766 required_params,
767 total_params,
768 variadic,
769 doc,
770 })
771}
772
773fn matching_paren_len(input: &str) -> Option<usize> {
774 let mut depth = 1usize;
775 for (offset, ch) in input.char_indices() {
776 match ch {
777 '(' | '[' | '{' => depth += 1,
778 ')' | ']' | '}' => {
779 depth = depth.saturating_sub(1);
780 if depth == 0 {
781 return Some(offset);
782 }
783 }
784 _ => {}
785 }
786 }
787 None
788}
789
790#[expect(
791 clippy::string_slice,
792 reason = "offsets come from char_indices and 1-byte ','"
793)]
794fn split_top_level_params(params: &str) -> Vec<&str> {
795 let mut out = Vec::new();
796 let mut depth = 0isize;
797 let mut start = 0usize;
798 for (offset, ch) in params.char_indices() {
799 match ch {
800 '(' | '[' | '{' => depth += 1,
801 ')' | ']' | '}' => depth -= 1,
802 ',' if depth == 0 => {
803 out.push(¶ms[start..offset]);
804 start = offset + 1;
805 }
806 _ => {}
807 }
808 }
809 out.push(¶ms[start..]);
810 out
811}
812
813#[cfg(test)]
814mod tests {
815 use std::collections::BTreeSet;
816
817 use super::{
818 entrypoint_modules, get_stdlib_prompt_asset, matching_paren_len,
819 parse_public_function_line, public_functions_for_module, STDLIB_CLI_SCRIPTS,
820 STDLIB_PROMPT_ASSETS, STDLIB_SOURCES,
821 };
822
823 #[test]
824 fn stdlib_sources_are_non_empty() {
825 for entry in STDLIB_SOURCES {
826 assert!(
827 !entry.source.trim().is_empty(),
828 "{} should have non-empty source",
829 entry.module
830 );
831 }
832 }
833
834 #[test]
835 fn cli_scripts_are_non_empty_and_uniquely_named() {
836 let mut seen = BTreeSet::new();
837 for entry in STDLIB_CLI_SCRIPTS {
838 assert!(
839 !entry.source.trim().is_empty(),
840 "cli/{} should have non-empty source",
841 entry.name
842 );
843 assert!(
844 seen.insert(entry.name),
845 "cli/{} is registered more than once in STDLIB_CLI_SCRIPTS",
846 entry.name
847 );
848 }
849 }
850
851 #[test]
852 fn stdlib_source_names_are_unique() {
853 let mut names = BTreeSet::new();
854 for entry in STDLIB_SOURCES {
855 assert!(names.insert(entry.module), "duplicate {}", entry.module);
856 }
857 }
858
859 #[test]
860 fn stdlib_prompt_assets_are_non_empty() {
861 for entry in STDLIB_PROMPT_ASSETS {
862 assert!(
863 !entry.source.trim().is_empty(),
864 "{} should have non-empty prompt asset source",
865 entry.path
866 );
867 }
868 }
869
870 #[test]
871 fn stdlib_prompt_asset_paths_are_unique() {
872 let mut paths = BTreeSet::new();
873 for entry in STDLIB_PROMPT_ASSETS {
874 assert!(paths.insert(entry.path), "duplicate {}", entry.path);
875 }
876 }
877
878 #[test]
879 fn key_stdlib_prompt_assets_resolve() {
880 for path in [
881 "std/agent/prompts/tool_contract_text.harn.prompt",
882 "std/agent/prompts/default_nudge.harn.prompt",
883 "std/agent/prompts/completion_judge_default.harn.prompt",
884 "std/llm/prompts/directive_envelope_instructions.harn.prompt",
885 "std/llm/prompts/directive_nonce_authority.harn.prompt",
886 "std/workflow/prompts/stage.harn.prompt",
887 "std/orchestration/prompts/compaction_summary.harn.prompt",
888 "std/orchestration/prompts/compaction_policy_extension.harn.prompt",
889 "std/orchestration/prompts/compaction_policy_replacement.harn.prompt",
890 "std/orchestration/prompts/compaction_state_grounding.harn.prompt",
891 ] {
892 assert!(
893 get_stdlib_prompt_asset(path).is_some(),
894 "{path} should resolve"
895 );
896 }
897 }
898
899 #[test]
900 fn public_function_catalog_derives_signatures_from_harn_source() {
901 let exports = public_functions_for_module("workflow/execute");
902 assert_eq!(exports.len(), 1);
903 assert_eq!(exports[0].name, "workflow_execute");
904 assert_eq!(
905 exports[0].signature,
906 "workflow_execute( harness: Harness, task: string, graph: dict, artifacts: list<unknown>? = nil, options: dict? = nil, )"
907 );
908 assert_eq!(exports[0].required_params, 3);
909 assert_eq!(exports[0].total_params, 5);
910 }
911
912 #[test]
913 fn tool_registry_from_catalog_includes_cli_metadata_parameter() {
914 let function = public_functions_for_module("tools")
915 .into_iter()
916 .find(|function| function.name == "tool_registry_from")
917 .expect("std/tools should export tool_registry_from");
918 assert_eq!(function.required_params, 1);
919 assert_eq!(function.total_params, 2);
920 assert!(function
921 .signature
922 .contains("options: ToolRegistryOptions? = nil"));
923 }
924
925 #[test]
926 fn soft_landing_modules_own_their_public_surface() {
927 for (module, expected) in [
931 (
932 "agent/run_meter",
933 &[
934 "meter_observation_lower",
935 "meter_observation_render",
936 "meter_observation_upper",
937 "run_meter_bounded",
938 "run_meter_charge",
939 "run_meter_digest",
940 "run_meter_exact",
941 "run_meter_field_registered",
942 "run_meter_field_spec",
943 "run_meter_fields",
944 "run_meter_new",
945 "run_meter_observe",
946 "run_meter_project_next_call",
947 "run_meter_read",
948 "run_meter_registry_digest",
949 "run_meter_unavailable",
950 ][..],
951 ),
952 (
953 "agent/cut_landing",
954 &[
955 "cut_action_allowed",
956 "cut_predicate_evaluate",
957 "cut_predicate_render",
958 "cut_predicate_validate",
959 "cut_rules_digest",
960 "cut_rules_tick",
961 "cut_rules_validate",
962 "cut_state_complete",
963 "cut_state_new",
964 "cut_state_record_admission",
965 "cut_state_record_terminal_emit",
966 "cut_terminal_emit_due",
967 "cut_terminal_evidence",
968 ][..],
969 ),
970 ] {
971 let exports = public_functions_for_module(module)
972 .into_iter()
973 .map(|function| function.name)
974 .collect::<BTreeSet<_>>();
975 for name in expected {
976 assert!(exports.contains(*name), "std/{module} should export {name}");
977 }
978 }
979 }
980
981 #[test]
982 fn pace_cut_rule_module_owns_public_functions() {
983 let cut_rule_exports = public_functions_for_module("agent/cut_rules")
984 .into_iter()
985 .map(|function| function.name)
986 .collect::<BTreeSet<_>>();
987 for name in [
988 "pace_cut_rule_action_of",
989 "pace_cut_rule_check_max_injections",
990 "pace_cut_rule_decision",
991 "pace_cut_rule_extend_max",
992 ] {
993 assert!(
994 cut_rule_exports.contains(name),
995 "std/agent/cut_rules should export {name}"
996 );
997 }
998
999 let governor_exports = public_functions_for_module("agent/governors")
1000 .into_iter()
1001 .map(|function| function.name)
1002 .collect::<BTreeSet<_>>();
1003 for removed in [
1004 "governor_pace_check_max_injections",
1005 "governor_pace_decision",
1006 "governor_pace_extend_max",
1007 "pace_action_of",
1008 ] {
1009 assert!(
1010 !governor_exports.contains(removed),
1011 "std/agent/governors must not retain removed export {removed}"
1012 );
1013 }
1014 }
1015
1016 #[test]
1017 fn command_stdlib_module_exports_step_helpers() {
1018 let exports = public_functions_for_module("command")
1019 .into_iter()
1020 .map(|function| function.name)
1021 .collect::<BTreeSet<_>>();
1022 for name in [
1023 "command_run",
1024 "command_wait",
1025 "command_wait_for_output",
1026 "command_cancel",
1027 "command_run_streaming",
1028 "command_output_tail",
1029 "command_json",
1030 "command_json_step",
1031 "command_try",
1032 "command_step",
1033 "command_steps_append",
1034 "command_last_failed_step",
1035 "command_step_ref",
1036 "command_output_text",
1037 "argv_label",
1038 "shell_command_from_argv",
1039 "shell_command_from_value",
1040 ] {
1041 assert!(exports.contains(name), "std/command should export {name}");
1042 }
1043 }
1044
1045 #[test]
1046 fn disclosure_stdlib_module_exports_render_helpers() {
1047 let exports = public_functions_for_module("disclosure")
1048 .into_iter()
1049 .map(|function| function.name)
1050 .collect::<BTreeSet<_>>();
1051 assert!(
1052 exports.contains("render"),
1053 "std/disclosure should export render"
1054 );
1055 assert!(
1056 exports.contains("git_trailers"),
1057 "std/disclosure should export git_trailers"
1058 );
1059 assert!(
1060 exports.contains("slack_message_disclosure"),
1061 "std/disclosure should export slack_message_disclosure"
1062 );
1063 assert!(
1064 exports.contains("append_git_trailers"),
1065 "std/disclosure should export append_git_trailers"
1066 );
1067 }
1068
1069 #[test]
1070 fn async_stdlib_exports_predicate_backoff_name_only() {
1071 let exports = public_functions_for_module("async")
1072 .into_iter()
1073 .map(|function| function.name)
1074 .collect::<BTreeSet<_>>();
1075 assert!(
1076 exports.contains("retry_predicate_with_backoff"),
1077 "std/async should export retry_predicate_with_backoff"
1078 );
1079 assert!(
1080 !exports.contains("retry_with_backoff"),
1081 "std/async should not retain the old retry_with_backoff export"
1082 );
1083 }
1084
1085 #[test]
1086 fn signal_stdlib_module_exports_interrupt_helpers() {
1087 let exports = public_functions_for_module("signal")
1088 .into_iter()
1089 .map(|function| function.name)
1090 .collect::<BTreeSet<_>>();
1091 for name in [
1092 "on_interrupt",
1093 "off_interrupt",
1094 "interrupted",
1095 "with_interrupt",
1096 ] {
1097 assert!(exports.contains(name), "std/signal should export {name}");
1098 }
1099 }
1100
1101 #[test]
1102 fn git_stdlib_module_exports_local_wrappers() {
1103 let exports = public_functions_for_module("git")
1104 .into_iter()
1105 .map(|function| function.name)
1106 .collect::<BTreeSet<_>>();
1107 for name in [
1108 "git_run",
1109 "git_status",
1110 "git_current_branch",
1111 "git_log",
1112 "git_switch",
1113 "git_pull_ff_only",
1114 "git_find_tool",
1115 "git_run_tool",
1116 "git_tools",
1117 "git_toolbox_tools",
1118 ] {
1119 assert!(exports.contains(name), "std/git should export {name}");
1120 }
1121 }
1122
1123 #[test]
1124 fn agent_workers_exports_suspend_resume_wrappers() {
1125 let exports = public_functions_for_module("agent/workers");
1126 let suspend = exports
1127 .iter()
1128 .find(|function| function.name == "suspend_agent")
1129 .expect("std/agent/workers should export suspend_agent");
1130 assert_eq!(
1131 suspend.signature,
1132 "suspend_agent( agents: HarnessAgent, worker: unknown, reason: string = \"\", options: dict? = nil, ) -> unknown"
1133 );
1134 assert_eq!(suspend.required_params, 2);
1135 assert_eq!(suspend.total_params, 4);
1136
1137 let resume = exports
1138 .iter()
1139 .find(|function| function.name == "resume_agent")
1140 .expect("std/agent/workers should export resume_agent");
1141 assert_eq!(
1142 resume.signature,
1143 "resume_agent( agents: HarnessAgent, worker_or_snapshot: unknown, resume_input: unknown = nil, continue_transcript: bool = true, ) -> unknown"
1144 );
1145 assert_eq!(resume.required_params, 2);
1146 assert_eq!(resume.total_params, 4);
1147
1148 let stop = exports
1149 .iter()
1150 .find(|function| function.name == "agent_stop")
1151 .expect("std/agent/workers should export agent_stop");
1152 assert_eq!(
1153 stop.signature,
1154 "agent_stop( agents: HarnessAgent, worker: unknown, options: AgentStopOptions? = nil, ) -> unknown"
1155 );
1156 assert_eq!(stop.required_params, 2);
1157 assert_eq!(stop.total_params, 3);
1158
1159 let parse_resume = exports
1160 .iter()
1161 .find(|function| function.name == "parse_resume_conditions")
1162 .expect("std/agent/workers should export parse_resume_conditions");
1163 assert_eq!(
1164 parse_resume.signature,
1165 "parse_resume_conditions( agents: HarnessAgent, conditions: ResumeConditions? = nil, ) -> ResumeConditions?"
1166 );
1167 assert_eq!(parse_resume.required_params, 1);
1168 assert_eq!(parse_resume.total_params, 2);
1169
1170 let lifecycle = exports
1171 .iter()
1172 .find(|function| function.name == "agent_lifecycle_tools")
1173 .expect("std/agent/workers should export agent_lifecycle_tools");
1174 assert_eq!(
1175 lifecycle.signature,
1176 "agent_lifecycle_tools( agents: HarnessAgent, registry: ToolRegistry? = nil, options: AgentLifecycleToolsOptions? = nil, ) -> ToolRegistry"
1177 );
1178 assert_eq!(lifecycle.required_params, 1);
1179 assert_eq!(lifecycle.total_params, 3);
1180 }
1181
1182 #[test]
1183 fn tui_stdlib_module_exports_terminal_helpers() {
1184 let exports = public_functions_for_module("tui")
1185 .into_iter()
1186 .map(|function| function.name)
1187 .collect::<BTreeSet<_>>();
1188 for name in ["page", "terminal_width", "rule", "clear", "select_from"] {
1189 assert!(exports.contains(name), "std/tui should export {name}");
1190 }
1191 }
1192
1193 #[test]
1194 fn semver_stdlib_module_exports_release_helpers() {
1195 let exports = public_functions_for_module("semver")
1196 .into_iter()
1197 .map(|function| function.name)
1198 .collect::<BTreeSet<_>>();
1199 for name in [
1200 "strip_v",
1201 "add_v",
1202 "is_v_semver",
1203 "is_v_release_semver",
1204 "parse",
1205 "parse_release",
1206 "is_prerelease_identifier",
1207 "is_prerelease",
1208 "compare_release",
1209 "max_canonical_tag",
1210 "next",
1211 "bump_type",
1212 "version_from_release_branch",
1213 "version_from_tag",
1214 ] {
1215 assert!(exports.contains(name), "std/semver should export {name}");
1216 }
1217 }
1218
1219 #[test]
1220 fn changelog_stdlib_module_exports_typed_primitives() {
1221 let exports = public_functions_for_module("changelog")
1222 .into_iter()
1223 .map(|function| function.name)
1224 .collect::<BTreeSet<_>>();
1225 for name in [
1226 "changelog_validate_categories",
1227 "changelog_parse_fragment",
1228 "changelog_order_fragments",
1229 "changelog_normalize_fragment_body",
1230 "changelog_assemble_fragments",
1231 "changelog_parse_sections",
1232 "changelog_find_section",
1233 "changelog_merge_unreleased",
1234 ] {
1235 assert!(exports.contains(name), "std/changelog should export {name}");
1236 }
1237 }
1238
1239 #[test]
1240 fn text_stdlib_module_exports_regex_and_pad_helpers() {
1241 let exports = public_functions_for_module("text")
1242 .into_iter()
1243 .map(|function| function.name)
1244 .collect::<BTreeSet<_>>();
1245 for name in [
1246 "pad_left",
1247 "pad_right",
1248 "repeat_string",
1249 "regex_first_capture",
1250 "regex_capture_groups",
1251 "regex_all_first_captures",
1252 ] {
1253 assert!(exports.contains(name), "std/text should export {name}");
1254 }
1255 }
1256
1257 #[test]
1258 fn harn_entrypoint_catalog_is_declared_by_stdlib_sources() {
1259 let modules = entrypoint_modules();
1260 let entries = modules
1261 .iter()
1262 .map(|module| (module.import_path.as_str(), module.category.as_str()))
1263 .collect::<BTreeSet<_>>();
1264 for entry in [
1265 ("std/agent/loop", "agent.stdlib"),
1266 ("std/agent/primitives", "agent.stdlib"),
1267 ("std/workflow/execute", "workflow.stdlib"),
1268 ] {
1269 assert!(entries.contains(&entry), "{entry:?} should be declared");
1270 }
1271 }
1272
1273 #[test]
1274 fn matching_paren_len_closes_on_every_bracket_kind() {
1275 assert_eq!(matching_paren_len("a, b)"), Some(4));
1278 assert_eq!(matching_paren_len("x: [int])"), Some(8));
1279 assert_eq!(matching_paren_len("x: {a: int})"), Some(11));
1280 assert_eq!(matching_paren_len("x]"), Some(1));
1283 assert_eq!(matching_paren_len("x}"), Some(1));
1284 assert_eq!(matching_paren_len("unterminated"), None);
1285 }
1286
1287 #[test]
1288 fn parse_public_function_line_handles_record_typed_params() {
1289 let parsed =
1290 parse_public_function_line("pub fn configure(opts: {retries: int}) -> bool", None)
1291 .expect("signature with a record-typed parameter should parse");
1292 assert_eq!(parsed.name, "configure");
1293 assert_eq!(parsed.signature, "configure(opts: {retries: int}) -> bool");
1294 assert_eq!(parsed.total_params, 1);
1295 assert_eq!(parsed.required_params, 1);
1296 }
1297
1298 #[test]
1299 fn parse_public_function_line_indexes_generic_functions_by_base_name() {
1300 let parsed = parse_public_function_line(
1301 "pub fn map<T, U>(items: list<T>, project: fn(T) -> U) -> list<U>",
1302 None,
1303 )
1304 .expect("generic public function should parse");
1305 assert_eq!(parsed.name, "map");
1306 assert_eq!(
1307 parsed.signature,
1308 "map<T, U>(items: list<T>, project: fn(T) -> U) -> list<U>"
1309 );
1310 assert_eq!(parsed.total_params, 2);
1311 assert_eq!(parsed.required_params, 2);
1312 }
1313}