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