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