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/caller" => "stdlib/llm/caller.harn",
198 "harness/policy" => "stdlib/harness/policy.harn",
199 "llm/budget" => "stdlib/llm/budget.harn",
200 "llm/tokenizer" => "stdlib/llm/tokenizer.harn",
201 "llm/economics" => "stdlib/llm/economics.harn",
202 "llm/prompts" => "stdlib/llm/prompts.harn",
203 "llm/defaults" => "stdlib/llm/defaults.harn",
204 "llm/handlers" => "stdlib/llm/handlers.harn",
205 "llm/handler_cache_events" => "stdlib/llm/handler_cache_events.harn",
206 "llm/resilience" => "stdlib/llm/resilience.harn",
207 "llm/tool_telemetry" => "stdlib/llm/tool_telemetry.harn",
208 "llm/tool_middleware" => "stdlib/llm/tool_middleware.harn",
209 "llm/tool_binder" => "stdlib/llm/tool_binder.harn",
210 "llm/structural_validator" => "stdlib/llm/structural_validator.harn",
211 "llm/missing_tool_call" => "stdlib/llm/missing_tool_call.harn",
212 "llm/call_shape" => "stdlib/llm/call_shape.harn",
213 "llm/tool_shape" => "stdlib/llm/tool_shape.harn",
214 "llm/dialects" => "stdlib/llm/dialects.harn",
215 "llm/tool_parse" => "stdlib/llm/tool_parse.harn",
216 "llm/tool_parse_body" => "stdlib/llm/tool_parse_body.harn",
217 "llm/tool_parse_envelope" => "stdlib/llm/tool_parse_envelope.harn",
218 "llm/tool_parse_json_support" => "stdlib/llm/tool_parse_json_support.harn",
219 "llm/tool_parse_protocol" => "stdlib/llm/tool_parse_protocol.harn",
220 "llm/tool_parse_provider" => "stdlib/llm/tool_parse_provider.harn",
221 "llm/tool_parse_result" => "stdlib/llm/tool_parse_result.harn",
222 "llm/tool_parse_scan_spec" => "stdlib/llm/tool_parse_scan_spec.harn",
223 "llm/scope_classifier" => "stdlib/llm/scope_classifier.harn",
224 "llm/refine" => "stdlib/llm/refine.harn",
225 "llm/ensemble" => "stdlib/llm/ensemble.harn",
226 "llm/rerank" => "stdlib/llm/rerank.harn",
227 "agent/reasoning" => "stdlib/agent/reasoning.harn",
228 "agent/caller_transport" => "stdlib/agent/caller_transport.harn",
229 "agent/options" => "stdlib/agent/options.harn",
230 "agent/options_types" => "stdlib/agent/options_types.harn",
231 "agent/options_formats" => "stdlib/agent/options_formats.harn",
232 "agent/options_validation" => "stdlib/agent/options_validation.harn",
233 "agent/options_public" => "stdlib/agent/options_public.harn",
234 "agent/llm_dispatch" => "stdlib/agent/llm_dispatch.harn",
235 "agent/prefill" => "stdlib/agent/prefill.harn",
236 "agent/retry" => "stdlib/agent/retry.harn",
237 "llm/judge" => "stdlib/llm/judge.harn",
238 "llm/faithfulness" => "stdlib/llm/faithfulness.harn",
239 "llm/optimize" => "stdlib/llm/optimize.harn",
240 "agent/events" => "stdlib/agent/events.harn",
241 "agent/feedback" => "stdlib/agent/feedback.harn",
242 "agent/transcript" => "stdlib/agent/transcript.harn",
243 "agent/artifacts" => "stdlib/agent/artifacts.harn",
244 "agent/primitives" => "stdlib/agent/primitives.harn",
245 "agent/progress" => "stdlib/agent/progress.harn",
246 "agent/required_tools" => "stdlib/agent/required_tools.harn",
247 "agent/monologue_actuation" => "stdlib/agent/monologue_actuation.harn",
248 "agent/monologue_actuation_types" => "stdlib/agent/monologue_actuation_types.harn",
249 "agent/stall_types" => "stdlib/agent/stall_types.harn",
250 "agent/stall" => "stdlib/agent/stall.harn",
251 "agent/recurring_diagnostic" => "stdlib/agent/recurring_diagnostic.harn",
252 "agent/stall_config" => "stdlib/agent/stall_config.harn",
253 "agent/stall_feedback" => "stdlib/agent/stall_feedback.harn",
254 "agent/stall_action_observation" => "stdlib/agent/stall_action_observation.harn",
255 "agent/stall_observation" => "stdlib/agent/stall_observation.harn",
256 "agent/stall_verification" => "stdlib/agent/stall_verification.harn",
257 "agent/stall_detectors" => "stdlib/agent/stall_detectors.harn",
258 "agent/cut_rules" => "stdlib/agent/cut_rules.harn",
259 "agent/governors" => "stdlib/agent/governors.harn",
260 "agent/control" => "stdlib/agent/control.harn",
261 "agent/action_graph" => "stdlib/agent/action_graph.harn",
262 "agent/result_text" => "stdlib/agent/result_text.harn",
263 "agent/best_of_n" => "stdlib/agent/best_of_n.harn",
264 "agent/loop" => "stdlib/agent/loop.harn",
265 "agent/loop_support" => "stdlib/agent/loop_support.harn",
266 "agent/loop_call_resolution" => "stdlib/agent/loop_call_resolution.harn",
267 "agent/loop_await" => "stdlib/agent/loop_await.harn",
268 "agent/loop_denial_cutoff" => "stdlib/agent/loop_denial_cutoff.harn",
269 "agent/loop_result_status" => "stdlib/agent/loop_result_status.harn",
270 "agent/loop_foundation" => "stdlib/agent/loop_foundation.harn",
271 "agent/loop_lifecycle" => "stdlib/agent/loop_lifecycle.harn",
272 "agent/loop_provider_failure" => "stdlib/agent/loop_provider_failure.harn",
273 "agent/loop_audit_flushes" => "stdlib/agent/loop_audit_flushes.harn",
274 "agent/loop_tool_calls" => "stdlib/agent/loop_tool_calls.harn",
275 "agent/loop_resource_dispatch" => "stdlib/agent/loop_resource_dispatch.harn",
276 "agent/loop_turn_options" => "stdlib/agent/loop_turn_options.harn",
277 "agent/loop_turn_scope" => "stdlib/agent/loop_turn_scope.harn",
278 "agent/loop_turn_projection" => "stdlib/agent/loop_turn_projection.harn",
279 "agent/loop_internal" => "stdlib/agent/loop_internal.harn",
280 "agent/loop_run" => "stdlib/agent/loop_run.harn",
281 "agent/loop_post_turn" => "stdlib/agent/loop_post_turn.harn",
282 "agent/loop_finalize" => "stdlib/agent/loop_finalize.harn",
283 "agent/loop_terminal" => "stdlib/agent/loop_terminal.harn",
284 "agent/user" => "stdlib/agent/user.harn",
285 "agent/tool_search" => "stdlib/agent/tool_search.harn",
286 "agent/tool_annotations" => "stdlib/agent/tool_annotations.harn",
287 "agent/tool_lifecycle" => "stdlib/agent/tool_lifecycle.harn",
288 "agent/workers" => "stdlib/agent/workers.harn",
289 "agent/introspection" => "stdlib/agent/introspection.harn",
290 "agent/resume_by" => "stdlib/agent/resume_by.harn",
291 "agent/state" => "stdlib/agent/state.harn",
292 "agent/truncation" => "stdlib/agent/truncation.harn",
293 "agent/canon" => "stdlib/agent/canon.harn",
294 "agent/skills" => "stdlib/agent/skills.harn",
295 "agent/autocompact" => "stdlib/agent/autocompact.harn",
296 "agent/mcp" => "stdlib/agent/mcp.harn",
297 "agent/command_capture" => "stdlib/agent/command_capture.harn",
298 "agent/contracts" => "stdlib/agent/contracts.harn",
299 "agent/command_ledger" => "stdlib/agent/command_ledger.harn",
300 "agent/host_tools" => "stdlib/agent/host_tools.harn",
301 "agent/host_injection" => "stdlib/agent/host_injection.harn",
302 "agent/budget" => "stdlib/agent/budget.harn",
303 "agent/daemon" => "stdlib/agent/daemon.harn",
304 "agent/preflight" => "stdlib/agent/preflight.harn",
305 "agent/postturn" => "stdlib/agent/postturn.harn",
306 "agent/tool_surface" => "stdlib/agent/tool_surface.harn",
307 "agent/stance" => "stdlib/agent/stance.harn",
308 "agent/lanes" => "stdlib/agent/lanes.harn",
309 "agent/overlays" => "stdlib/agent/overlays.harn",
310 "agent/sitrep" => "stdlib/agent/sitrep.harn",
311 "agent/verdict" => "stdlib/agent/verdict.harn",
312 "agent/judge_internals" => "stdlib/agent/judge_internals.harn",
313 "agent/completion_gate" => "stdlib/agent/completion_gate.harn",
314 "agent/completion_review" => "stdlib/agent/completion_review.harn",
315 "agent/completion_requirements" => "stdlib/agent/completion_requirements.harn",
316 "agent/completion_evidence" => "stdlib/agent/completion_evidence.harn",
317 "agent/judge" => "stdlib/agent/judge.harn",
318 "agent/guardrails" => "stdlib/agent/guardrails.harn",
319 "agent/step_judge" => "stdlib/agent/step_judge.harn",
320 "agent/scratchpad" => "stdlib/agent/scratchpad.harn",
321 "agent/fact" => "stdlib/agent/fact.harn",
322 "agent/hypothesis" => "stdlib/agent/hypothesis.harn",
323 "agent/pattern_knowledge_values" => "stdlib/agent/pattern_knowledge_values.harn",
324 "agent/pattern_knowledge_curated" => "stdlib/agent/pattern_knowledge_curated.harn",
325 "agent/pattern_knowledge_persistence" => "stdlib/agent/pattern_knowledge_persistence.harn",
326 "agent/pattern_knowledge" => "stdlib/agent/pattern_knowledge.harn",
327 "agent/crystallization_curator" => "stdlib/agent/crystallization_curator.harn",
328 "agent/probe" => "stdlib/agent/probe.harn",
329 "agent/stream" => "stdlib/agent/stream.harn",
330 "agent/presets" => "stdlib/agent/presets.harn",
331 "agent/pins" => "stdlib/agent/pins.harn",
332 "agent/goal" => "stdlib/agent/goal.harn",
333 "agent/task_plan" => "stdlib/agent/task_plan.harn",
334 "personas/compiler" => "stdlib/personas/compiler.harn",
335 "personas/prompt_compiler" => "stdlib/personas/prompt_compiler.harn",
336 "agent_state" => "stdlib/stdlib_agent_state.harn",
337 "memory" => "stdlib/stdlib_memory.harn",
338 "session-store" => "stdlib/stdlib_session_store.harn",
339 "coordination" => "stdlib/stdlib_coordination.harn",
340 "coordination/append_metadata" => "stdlib/coordination/append_metadata.harn",
341 "coordination/schema" => "stdlib/coordination/schema.harn",
342 "fleet/coordination" => "stdlib/fleet/coordination.harn",
343 "postgres" => "stdlib/stdlib_postgres.harn",
344 "postgres/query" => "stdlib/postgres/query.harn",
345 "sqlite" => "stdlib/stdlib_sqlite.harn",
346 "checkpoint" => "stdlib/stdlib_checkpoint.harn",
347 "host" => "stdlib/stdlib_host.harn",
348 "host_conditions" => "stdlib/stdlib_host_conditions.harn",
349 "host_lease" => "stdlib/stdlib_host_lease.harn",
350 "git" => "stdlib/stdlib_git.harn",
351 "git/checkout" => "stdlib/git/checkout.harn",
352 "git/contracts" => "stdlib/git/contracts.harn",
353 "hitl" => "stdlib/stdlib_hitl.harn",
354 "trust" => "stdlib/stdlib_trust.harn",
355 "corrections" => "stdlib/stdlib_corrections.harn",
356 "plan" => "stdlib/stdlib_plan.harn",
357 "waitpoint" => "stdlib/stdlib_waitpoint.harn",
358 "monitors" => "stdlib/stdlib_monitors.harn",
359 "worktree" => "stdlib/stdlib_worktree.harn",
360 "acp" => "stdlib/stdlib_acp.harn",
361 "external_agent" => "stdlib/stdlib_external_agent.harn",
362 "triggers" => "stdlib/stdlib_triggers.harn",
363 "triage" => "stdlib/stdlib_triage.harn",
364 "dashboard/jobs" => "stdlib/dashboard/jobs.harn",
365 "ui_resource" => "stdlib/stdlib_ui_resource.harn",
366 "handoffs" => "stdlib/stdlib_handoffs.harn",
367 "lifecycle" => "stdlib/stdlib_lifecycle.harn",
368 "tool_hooks_catalogues" => "stdlib/stdlib_tool_hooks_catalogues.harn",
369 "tool_hooks" => "stdlib/stdlib_tool_hooks.harn",
370 "channel_guardrails" => "stdlib/stdlib_channel_guardrails.harn",
371 "personas/prelude" => "stdlib/stdlib_personas_prelude.harn",
372 "personas/bulletins" => "stdlib/stdlib_personas_bulletins.harn",
373 "connectors/shared" => "stdlib/stdlib_connectors_shared.harn",
374 "connectors/http" => "stdlib/connectors/http.harn",
375 "connectors/setup" => "stdlib/connectors/setup.harn",
376 "oauth/providers" => "stdlib/oauth/providers.harn",
377 "oauth/token_exchange_catalog" => "stdlib/oauth/token_exchange_catalog.harn",
378 "oauth/token_exchange" => "stdlib/oauth/token_exchange.harn",
379 "oauth/storage" => "stdlib/oauth/storage.harn",
380 "oauth/client" => "stdlib/oauth/client.harn",
381 "oauth/device_flow" => "stdlib/oauth/device_flow.harn",
382 "oauth/redaction" => "stdlib/oauth/redaction.harn",
383 "oauth/dynamic_registration" => "stdlib/oauth/dynamic_registration.harn",
384 "connectors/github" => "stdlib/stdlib_connectors_github.harn",
385 "connectors/github/repository" => "stdlib/connectors/github/repository.harn",
386 "connectors/linear" => "stdlib/stdlib_connectors_linear.harn",
387 "connectors/notion" => "stdlib/stdlib_connectors_notion.harn",
388 "connectors/slack" => "stdlib/stdlib_connectors_slack.harn",
389 "workflow/prompts" => "stdlib/workflow/prompts.harn",
390 "workflow/context" => "stdlib/workflow/context.harn",
391 "workflow/options" => "stdlib/workflow/options.harn",
392 "workflow/checkpoints" => "stdlib/workflow/checkpoints.harn",
393 "workflow/patterns" => "stdlib/workflow/patterns.harn",
394 "workflow/stage" => "stdlib/workflow/stage.harn",
395 "workflow/map" => "stdlib/workflow/map.harn",
396 "workflow/schedule" => "stdlib/workflow/schedule.harn",
397 "workflow/execute" => "stdlib/workflow/execute.harn",
398 "workflow/repair" => "stdlib/workflow/repair.harn",
399 "security" => "stdlib/stdlib_security.harn",
400 "pii" => "stdlib/stdlib_pii.harn",
401 "bump/runtime" => "stdlib/bump/runtime.harn",
402 "bump/live" => "stdlib/bump/live.harn",
403]);
404
405pub const CONNECTOR_EVENT_SCHEMAS_SOURCE: &str = include_str!("stdlib/stdlib_event_schemas.harn");
415
416pub const STDLIB_PROMPT_ASSETS: &[StdlibPromptAsset] = embedded_catalog!(StdlibPromptAsset, path, [
417 "eval/hypothesis/prompts/intake.harn.prompt" => "stdlib/eval/hypothesis/prompts/intake.harn.prompt",
418 "agent/prompts/tool_contract_text.harn.prompt" => "stdlib/agent/prompts/tool_contract_text.harn.prompt",
419 "agent/prompts/tool_contract_json.harn.prompt" => "stdlib/agent/prompts/tool_contract_json.harn.prompt",
420 "agent/prompts/tool_contract_native.harn.prompt" => "stdlib/agent/prompts/tool_contract_native.harn.prompt",
421 "agent/prompts/tool_contract_text_response_protocol.harn.prompt" => "stdlib/agent/prompts/tool_contract_text_response_protocol.harn.prompt",
422 "agent/prompts/tool_contract_action_native.harn.prompt" => "stdlib/agent/prompts/tool_contract_action_native.harn.prompt",
423 "agent/prompts/tool_contract_action_text.harn.prompt" => "stdlib/agent/prompts/tool_contract_action_text.harn.prompt",
424 "agent/prompts/tool_contract_task_ledger.harn.prompt" => "stdlib/agent/prompts/tool_contract_task_ledger.harn.prompt",
425 "agent/prompts/tool_contract_deferred_tools.harn.prompt" => "stdlib/agent/prompts/tool_contract_deferred_tools.harn.prompt",
426 "agent/prompts/deferred_tool_listing.harn.prompt" => "stdlib/agent/prompts/deferred_tool_listing.harn.prompt",
427 "agent/prompts/default_nudge.harn.prompt" => "stdlib/agent/prompts/default_nudge.harn.prompt",
428 "agent/prompts/agentic_user_system.harn.prompt" => "stdlib/agent/prompts/agentic_user_system.harn.prompt",
429 "agent/prompts/agentic_user_user.harn.prompt" => "stdlib/agent/prompts/agentic_user_user.harn.prompt",
430 "agent/prompts/loop_until_done_system.harn.prompt" => "stdlib/agent/prompts/loop_until_done_system.harn.prompt",
431 "agent/prompts/completion_judge_default.harn.prompt" => "stdlib/agent/prompts/completion_judge_default.harn.prompt",
432 "agent/prompts/completion_judge_feedback_fallback.harn.prompt" => "stdlib/agent/prompts/completion_judge_feedback_fallback.harn.prompt",
433 "agent/prompts/completion_judge_user.harn.prompt" => "stdlib/agent/prompts/completion_judge_user.harn.prompt",
434 "agent/prompts/step_judge_system_default.harn.prompt" => "stdlib/agent/prompts/step_judge_system_default.harn.prompt",
435 "agent/prompts/step_judge_system_adversarial.harn.prompt" => "stdlib/agent/prompts/step_judge_system_adversarial.harn.prompt",
436 "agent/prompts/step_judge_user.harn.prompt" => "stdlib/agent/prompts/step_judge_user.harn.prompt",
437 "agent/prompts/parse_guidance.harn.prompt" => "stdlib/agent/prompts/parse_guidance.harn.prompt",
438 "agent/prompts/native_tool_contract_feedback.harn.prompt" => "stdlib/agent/prompts/native_tool_contract_feedback.harn.prompt",
439 "agent/prompts/verification_gate_feedback.harn.prompt" => "stdlib/agent/prompts/verification_gate_feedback.harn.prompt",
440 "agent/prompts/daemon_watch_feedback.harn.prompt" => "stdlib/agent/prompts/daemon_watch_feedback.harn.prompt",
441 "agent/prompts/daemon_timer_feedback.harn.prompt" => "stdlib/agent/prompts/daemon_timer_feedback.harn.prompt",
442 "llm/prompts/completion_fallback_system.harn.prompt" => "stdlib/llm/prompts/completion_fallback_system.harn.prompt",
443 "llm/prompts/completion_fallback_user.harn.prompt" => "stdlib/llm/prompts/completion_fallback_user.harn.prompt",
444 "llm/prompts/transcript_summarize_user.harn.prompt" => "stdlib/llm/prompts/transcript_summarize_user.harn.prompt",
445 "llm/prompts/sitrep_user.harn.prompt" => "stdlib/llm/prompts/sitrep_user.harn.prompt",
446 "llm/prompts/structural_chain_of_draft.harn.prompt" => "stdlib/llm/prompts/structural_chain_of_draft.harn.prompt",
447 "llm/prompts/schema_recover_repair.harn.prompt" => "stdlib/llm/prompts/schema_recover_repair.harn.prompt",
448 "llm/prompts/structured_envelope_schema_contract.harn.prompt" => "stdlib/llm/prompts/structured_envelope_schema_contract.harn.prompt",
449 "llm/prompts/structured_envelope_repair.harn.prompt" => "stdlib/llm/prompts/structured_envelope_repair.harn.prompt",
450 "llm/prompts/directive_envelope_instructions.harn.prompt" => "stdlib/llm/prompts/directive_envelope_instructions.harn.prompt",
451 "llm/prompts/pairwise_rerank_user.harn.prompt" => "stdlib/llm/prompts/pairwise_rerank_user.harn.prompt",
452 "llm/prompts/tool_binder_user.harn.prompt" => "stdlib/llm/prompts/tool_binder_user.harn.prompt",
453 "llm/prompts/missing_tool_call_classifier.harn.prompt" => "stdlib/llm/prompts/missing_tool_call_classifier.harn.prompt",
454 "workflow/prompts/stage.harn.prompt" => "stdlib/workflow/prompts/stage.harn.prompt",
455 "workflow/prompts/verification_context_intro.harn.prompt" => "stdlib/workflow/prompts/verification_context_intro.harn.prompt",
456 "orchestration/prompts/compaction_summary.harn.prompt" => "stdlib/orchestration/prompts/compaction_summary.harn.prompt",
457 "orchestration/prompts/compaction_policy_extension.harn.prompt" => "stdlib/orchestration/prompts/compaction_policy_extension.harn.prompt",
458 "orchestration/prompts/compaction_policy_replacement.harn.prompt" => "stdlib/orchestration/prompts/compaction_policy_replacement.harn.prompt",
459 "orchestration/prompts/compaction_state_grounding.harn.prompt" => "stdlib/orchestration/prompts/compaction_state_grounding.harn.prompt",
460]);
461
462#[derive(Debug, Clone, Copy, PartialEq, Eq)]
466pub struct StdlibCliScript {
467 pub name: &'static str,
471 pub source: &'static str,
474}
475
476pub const STDLIB_CLI_SCRIPTS: &[StdlibCliScript] = embedded_catalog!(StdlibCliScript, name, [
477 "codemod" => "stdlib/cli/codemod.harn",
478 "canon/check" => "stdlib/cli/canon/check.harn",
479 "doctor" => "stdlib/cli/doctor.harn",
480 "echo" => "stdlib/cli/echo.harn",
481 "eval/_runner" => "stdlib/cli/eval/_runner.harn",
485 "eval/context" => "stdlib/cli/eval/context.harn",
486 "eval/model_selector" => "stdlib/cli/eval/model_selector.harn",
487 "eval/tool_calls" => "stdlib/cli/eval/tool_calls.harn",
488 "eval/coding_agent" => "stdlib/cli/eval/coding_agent.harn",
489 "eval/scope_triage" => "stdlib/cli/eval/scope_triage.harn",
490 "eval/prompt" => "stdlib/cli/eval/prompt.harn",
491 "explain" => "stdlib/cli/explain.harn",
492 "graph" => "stdlib/cli/graph.harn",
493 "personas/compile_prompt" => "stdlib/cli/personas/compile_prompt.harn",
494 "personas/materialize" => "stdlib/cli/personas/materialize.harn",
495 "models/batch_plan" => "stdlib/cli/models/batch_plan.harn",
496 "models/list" => "stdlib/cli/models/list.harn",
497 "models/lora_inspect" => "stdlib/cli/models/lora_inspect.harn",
498 "models/lora_export" => "stdlib/cli/models/lora_export.harn",
499 "models/lora_manifest" => "stdlib/cli/models/lora_manifest.harn",
500 "models/lora_preflight" => "stdlib/cli/models/lora_preflight.harn",
501 "models/lora_promote" => "stdlib/cli/models/lora_promote.harn",
502 "models/lora_plan" => "stdlib/cli/models/lora_plan.harn",
503 "models/lora_train" => "stdlib/cli/models/lora_train.harn",
504 "models/recommend" => "stdlib/cli/models/recommend.harn",
505 "models/test" => "stdlib/cli/models/test.harn",
506 "precompile" => "stdlib/cli/precompile.harn",
507 "providers/cache_probe" => "stdlib/cli/providers/cache_probe.harn",
508 "providers/catalog" => "stdlib/cli/providers/catalog.harn",
509 "providers/effort_probe" => "stdlib/cli/providers/effort_probe.harn",
510 "providers/probe" => "stdlib/cli/providers/probe.harn",
511 "providers/recommend" => "stdlib/cli/providers/recommend.harn",
512 "providers/tool_probe" => "stdlib/cli/providers/tool_probe.harn",
513 "providers/tool_scorecard" => "stdlib/cli/providers/tool_scorecard.harn",
514 "routes" => "stdlib/cli/routes.harn",
515 "runs/export_training" => "stdlib/cli/runs/export_training.harn",
516 "scan" => "stdlib/cli/scan.harn",
517 "scaffold/init" => "stdlib/cli/scaffold/init.harn",
518 "scaffold/tool_new" => "stdlib/cli/scaffold/tool_new.harn",
519 "trace_import" => "stdlib/cli/trace_import.harn",
520 "try" => "stdlib/cli/try.harn",
521 "version" => "stdlib/cli/version.harn",
522]);
523
524pub fn get_stdlib_source(module: &str) -> Option<&'static str> {
525 STDLIB_SOURCES
526 .iter()
527 .find_map(|entry| (entry.module == module).then_some(entry.source))
528}
529
530pub fn builtin_reexports(module: &str) -> &'static [&'static str] {
550 match module {
551 "testing" => &[
552 "assert",
553 "assert_approx",
554 "assert_eq",
555 "assert_matches",
556 "assert_ne",
557 "value_diff",
558 ],
559 _ => &[],
560 }
561}
562
563pub fn find_cli_script(name: &str) -> Option<&'static str> {
567 STDLIB_CLI_SCRIPTS
568 .iter()
569 .find_map(|entry| (entry.name == name).then_some(entry.source))
570}
571
572pub fn get_stdlib_prompt_asset(path: &str) -> Option<&'static str> {
573 let path = path.strip_prefix("std/").unwrap_or(path);
574 STDLIB_PROMPT_ASSETS
575 .iter()
576 .find_map(|entry| (entry.path == path).then_some(entry.source))
577}
578
579pub fn public_functions_for_module(module: &str) -> Vec<StdlibPublicFunction> {
580 let Some(source) = get_stdlib_source(module) else {
581 return Vec::new();
582 };
583 public_functions_from_source(source)
584}
585
586pub fn entrypoint_modules() -> Vec<StdlibEntrypointModule> {
587 STDLIB_SOURCES
588 .iter()
589 .filter_map(|entry| {
590 entrypoint_category_from_source(entry.source).map(|category| StdlibEntrypointModule {
591 import_path: format!("std/{}", entry.module),
592 category,
593 })
594 })
595 .collect()
596}
597
598fn entrypoint_category_from_source(source: &str) -> Option<String> {
599 for line in source.lines() {
600 let line = line.trim();
601 if line.is_empty() {
602 continue;
603 }
604 if let Some(category) = line.strip_prefix("// @harn-entrypoint-category ") {
605 let category = category.trim();
606 return (!category.is_empty()).then(|| category.to_string());
607 }
608 if !line.starts_with("//") {
609 return None;
610 }
611 }
612 None
613}
614
615fn public_functions_from_source(source: &str) -> Vec<StdlibPublicFunction> {
616 let mut out = Vec::new();
617 let mut doc: Option<String> = None;
618 let lines = source.lines().collect::<Vec<_>>();
619 let mut index = 0usize;
620 while index < lines.len() {
621 let line = lines[index].trim();
622 if line.starts_with("/**") {
623 let (parsed, next) = parse_harndoc(&lines, index);
624 doc = parsed;
625 index = next;
626 continue;
627 }
628 if line.starts_with("pub fn ") {
629 let (signature_line, next) = collect_public_function_signature(&lines, index);
630 if let Some(function) = parse_public_function_line(&signature_line, doc.take()) {
631 out.push(function);
632 index = next;
633 continue;
634 }
635 }
636 if let Some(function) = parse_public_function_line(line, doc.take()) {
637 out.push(function);
638 } else if !line.is_empty() && !line.starts_with("//") {
639 doc = None;
640 }
641 index += 1;
642 }
643 out
644}
645
646fn collect_public_function_signature(lines: &[&str], start: usize) -> (String, usize) {
647 let mut parts = Vec::new();
648 let mut index = start;
649 while index < lines.len() {
650 parts.push(lines[index].trim().to_string());
651 let candidate = parts.join(" ");
652 if public_function_signature_complete(&candidate) {
653 return (candidate, index + 1);
654 }
655 index += 1;
656 }
657 (parts.join(" "), index)
658}
659
660fn public_function_signature_complete(line: &str) -> bool {
661 let Some(rest) = line.strip_prefix("pub fn ") else {
662 return false;
663 };
664 let Some((_, after_paren)) = rest.split_once('(') else {
665 return false;
666 };
667 matching_paren_len(after_paren).is_some()
668}
669
670fn parse_harndoc(lines: &[&str], start: usize) -> (Option<String>, usize) {
671 let mut parts = Vec::new();
672 let mut index = start;
673 while index < lines.len() {
674 let mut line = lines[index].trim();
675 if index == start {
676 line = line.trim_start_matches("/**").trim();
677 }
678 let done = line.ends_with("*/");
679 line = line.trim_end_matches("*/").trim();
680 line = line.trim_start_matches('*').trim();
681 if !line.is_empty() {
682 parts.push(line.to_string());
683 }
684 index += 1;
685 if done {
686 break;
687 }
688 }
689 let text = parts.join("\n").trim().to_string();
690 ((!text.is_empty()).then_some(text), index)
691}
692
693#[expect(
694 clippy::string_slice,
695 reason = "bounds come from str::find and char_indices"
696)]
697fn parse_public_function_line(line: &str, doc: Option<String>) -> Option<StdlibPublicFunction> {
698 let rest = line.strip_prefix("pub fn ")?.trim();
699 let name_end = rest.find('(')?;
700 let declaration_name = rest[..name_end].trim();
701 let name = declaration_name
702 .split_once('<')
703 .map_or(declaration_name, |(name, _)| name.trim());
704 if name.is_empty() {
705 return None;
706 }
707 let params_start = name_end + 1;
708 let params_len = matching_paren_len(&rest[params_start..])?;
709 let params = &rest[params_start..params_start + params_len];
710 let after = rest[params_start + params_len + 1..].trim();
711 let return_type = after
712 .strip_prefix("->")
713 .and_then(|tail| tail.split('{').next())
714 .map(str::trim)
715 .filter(|value| !value.is_empty());
716 let signature = match return_type {
717 Some(ret) => format!("{declaration_name}({params}) -> {ret}"),
718 None => format!("{declaration_name}({params})"),
719 };
720 let param_parts = split_top_level_params(params);
721 let total_params = param_parts
722 .iter()
723 .filter(|param| !param.trim().is_empty())
724 .count();
725 let variadic = param_parts
726 .iter()
727 .any(|param| param.trim_start().starts_with("..."));
728 let required_params = param_parts
729 .iter()
730 .filter(|param| {
731 let param = param.trim();
732 !param.is_empty() && !param.contains('=') && !param.starts_with("...")
733 })
734 .count();
735 Some(StdlibPublicFunction {
736 name: name.to_string(),
737 signature,
738 required_params,
739 total_params,
740 variadic,
741 doc,
742 })
743}
744
745fn matching_paren_len(input: &str) -> Option<usize> {
746 let mut depth = 1usize;
747 for (offset, ch) in input.char_indices() {
748 match ch {
749 '(' | '[' | '{' => depth += 1,
750 ')' | ']' | '}' => {
751 depth = depth.saturating_sub(1);
752 if depth == 0 {
753 return Some(offset);
754 }
755 }
756 _ => {}
757 }
758 }
759 None
760}
761
762#[expect(
763 clippy::string_slice,
764 reason = "offsets come from char_indices and 1-byte ','"
765)]
766fn split_top_level_params(params: &str) -> Vec<&str> {
767 let mut out = Vec::new();
768 let mut depth = 0isize;
769 let mut start = 0usize;
770 for (offset, ch) in params.char_indices() {
771 match ch {
772 '(' | '[' | '{' => depth += 1,
773 ')' | ']' | '}' => depth -= 1,
774 ',' if depth == 0 => {
775 out.push(¶ms[start..offset]);
776 start = offset + 1;
777 }
778 _ => {}
779 }
780 }
781 out.push(¶ms[start..]);
782 out
783}
784
785#[cfg(test)]
786mod tests {
787 use std::collections::BTreeSet;
788
789 use super::{
790 entrypoint_modules, find_cli_script, get_stdlib_prompt_asset, get_stdlib_source,
791 matching_paren_len, parse_public_function_line, public_functions_for_module,
792 STDLIB_CLI_SCRIPTS, STDLIB_PROMPT_ASSETS, STDLIB_SOURCES,
793 };
794
795 #[test]
796 fn stdlib_sources_are_non_empty() {
797 for entry in STDLIB_SOURCES {
798 assert!(
799 !entry.source.trim().is_empty(),
800 "{} should have non-empty source",
801 entry.module
802 );
803 }
804 }
805
806 #[test]
807 fn cli_scripts_are_non_empty_and_uniquely_named() {
808 let mut seen = BTreeSet::new();
809 for entry in STDLIB_CLI_SCRIPTS {
810 assert!(
811 !entry.source.trim().is_empty(),
812 "cli/{} should have non-empty source",
813 entry.name
814 );
815 assert!(
816 seen.insert(entry.name),
817 "cli/{} is registered more than once in STDLIB_CLI_SCRIPTS",
818 entry.name
819 );
820 }
821 }
822
823 #[test]
824 fn find_cli_script_round_trips() {
825 for entry in STDLIB_CLI_SCRIPTS {
826 assert_eq!(find_cli_script(entry.name), Some(entry.source));
827 }
828 assert!(find_cli_script("not-a-real-script").is_none());
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_modules_resolve() {
860 for module in [
861 "context",
862 "context/maintenance",
863 "context/eval",
864 "eval/stats",
865 "eval/remote_fanout",
866 "eval/agreement",
867 "edit",
868 "verification",
869 "disclosure",
870 "artifact/web",
871 "command",
872 "waitpoint",
873 "llm/handlers",
874 "media/asset",
875 "media/composition",
876 "model_job",
877 "model_job/contracts",
878 "model_job/runtime",
879 "model_job/testing",
880 "model_job/comfyui",
881 "model_job/openai",
882 "ui",
883 "ui/contracts",
884 "ui/renderer",
885 "ui/testing",
886 "llm/tool_middleware",
887 "llm/tool_binder",
888 "llm/missing_tool_call",
889 "llm/tool_shape",
890 "llm/dialects",
891 "llm/ensemble",
892 "llm/rerank",
893 "personas/prelude",
894 "personas/bulletins",
895 "agent/host_tools",
896 "agent/host_injection",
897 "agent/tool_lifecycle",
898 "agent/user",
899 "agent/cut_rules",
900 "agent/governors",
901 "agent/loop_post_turn",
902 "agent/completion_gate",
903 "agent/guardrails",
904 "cli",
905 "cli/envelope",
906 "cli/models/batch_artifacts",
907 "cli/models/batch_cancel",
908 "cli/models/batch_download",
909 "cli/models/batch_lifecycle",
910 "cli/models/batch_rejoin",
911 "cli/models/batch_status",
912 "cli/models/batch_submit",
913 "cli/models/batch_transport",
914 "cli/models/lora_render",
915 "llm/optimize",
916 "llm/judge",
917 "llm/faithfulness",
918 "llm/refine",
919 "connectors/shared",
920 "connectors/github",
921 "connectors/linear",
922 "connectors/notion",
923 "connectors/slack",
924 "triage",
925 "dashboard/jobs",
926 "ui_resource",
927 "host_conditions",
928 "host_lease",
929 ] {
930 assert!(
931 get_stdlib_source(module).is_some(),
932 "std/{module} should resolve"
933 );
934 }
935 }
936
937 #[test]
938 fn key_stdlib_prompt_assets_resolve() {
939 for path in [
940 "std/agent/prompts/tool_contract_text.harn.prompt",
941 "std/agent/prompts/default_nudge.harn.prompt",
942 "std/agent/prompts/completion_judge_default.harn.prompt",
943 "std/llm/prompts/directive_envelope_instructions.harn.prompt",
944 "std/workflow/prompts/stage.harn.prompt",
945 "std/orchestration/prompts/compaction_summary.harn.prompt",
946 "std/orchestration/prompts/compaction_policy_extension.harn.prompt",
947 "std/orchestration/prompts/compaction_policy_replacement.harn.prompt",
948 "std/orchestration/prompts/compaction_state_grounding.harn.prompt",
949 ] {
950 assert!(
951 get_stdlib_prompt_asset(path).is_some(),
952 "{path} should resolve"
953 );
954 }
955 }
956
957 #[test]
958 fn public_function_catalog_derives_signatures_from_harn_source() {
959 let exports = public_functions_for_module("workflow/execute");
960 assert_eq!(exports.len(), 1);
961 assert_eq!(exports[0].name, "workflow_execute");
962 assert_eq!(
963 exports[0].signature,
964 "workflow_execute( harness: Harness, task: string, graph: dict, artifacts: list<unknown>? = nil, options: dict? = nil, )"
965 );
966 assert_eq!(exports[0].required_params, 3);
967 assert_eq!(exports[0].total_params, 5);
968 }
969
970 #[test]
971 fn pace_cut_rule_module_owns_public_functions() {
972 let cut_rule_exports = public_functions_for_module("agent/cut_rules")
973 .into_iter()
974 .map(|function| function.name)
975 .collect::<BTreeSet<_>>();
976 for name in [
977 "pace_cut_rule_action_of",
978 "pace_cut_rule_check_max_injections",
979 "pace_cut_rule_decision",
980 "pace_cut_rule_extend_max",
981 ] {
982 assert!(
983 cut_rule_exports.contains(name),
984 "std/agent/cut_rules should export {name}"
985 );
986 }
987
988 let governor_exports = public_functions_for_module("agent/governors")
989 .into_iter()
990 .map(|function| function.name)
991 .collect::<BTreeSet<_>>();
992 for removed in [
993 "governor_pace_check_max_injections",
994 "governor_pace_decision",
995 "governor_pace_extend_max",
996 "pace_action_of",
997 ] {
998 assert!(
999 !governor_exports.contains(removed),
1000 "std/agent/governors must not retain removed export {removed}"
1001 );
1002 }
1003 }
1004
1005 #[test]
1006 fn command_stdlib_module_exports_step_helpers() {
1007 let exports = public_functions_for_module("command")
1008 .into_iter()
1009 .map(|function| function.name)
1010 .collect::<BTreeSet<_>>();
1011 for name in [
1012 "command_run",
1013 "command_wait",
1014 "command_wait_for_output",
1015 "command_cancel",
1016 "command_run_streaming",
1017 "command_output_tail",
1018 "command_json",
1019 "command_json_step",
1020 "command_try",
1021 "command_step",
1022 "command_steps_append",
1023 "command_last_failed_step",
1024 "command_step_ref",
1025 "command_output_text",
1026 "argv_label",
1027 "shell_command_from_argv",
1028 "shell_command_from_value",
1029 ] {
1030 assert!(exports.contains(name), "std/command should export {name}");
1031 }
1032 }
1033
1034 #[test]
1035 fn disclosure_stdlib_module_exports_render_helpers() {
1036 let exports = public_functions_for_module("disclosure")
1037 .into_iter()
1038 .map(|function| function.name)
1039 .collect::<BTreeSet<_>>();
1040 assert!(
1041 exports.contains("render"),
1042 "std/disclosure should export render"
1043 );
1044 assert!(
1045 exports.contains("git_trailers"),
1046 "std/disclosure should export git_trailers"
1047 );
1048 assert!(
1049 exports.contains("slack_message_disclosure"),
1050 "std/disclosure should export slack_message_disclosure"
1051 );
1052 assert!(
1053 exports.contains("append_git_trailers"),
1054 "std/disclosure should export append_git_trailers"
1055 );
1056 }
1057
1058 #[test]
1059 fn async_stdlib_exports_predicate_backoff_name_only() {
1060 let exports = public_functions_for_module("async")
1061 .into_iter()
1062 .map(|function| function.name)
1063 .collect::<BTreeSet<_>>();
1064 assert!(
1065 exports.contains("retry_predicate_with_backoff"),
1066 "std/async should export retry_predicate_with_backoff"
1067 );
1068 assert!(
1069 !exports.contains("retry_with_backoff"),
1070 "std/async should not retain the old retry_with_backoff export"
1071 );
1072 }
1073
1074 #[test]
1075 fn signal_stdlib_module_exports_interrupt_helpers() {
1076 let exports = public_functions_for_module("signal")
1077 .into_iter()
1078 .map(|function| function.name)
1079 .collect::<BTreeSet<_>>();
1080 for name in [
1081 "on_interrupt",
1082 "off_interrupt",
1083 "interrupted",
1084 "with_interrupt",
1085 ] {
1086 assert!(exports.contains(name), "std/signal should export {name}");
1087 }
1088 }
1089
1090 #[test]
1091 fn git_stdlib_module_exports_local_wrappers() {
1092 let exports = public_functions_for_module("git")
1093 .into_iter()
1094 .map(|function| function.name)
1095 .collect::<BTreeSet<_>>();
1096 for name in [
1097 "git_run",
1098 "git_status",
1099 "git_current_branch",
1100 "git_log",
1101 "git_switch",
1102 "git_pull_ff_only",
1103 "git_find_tool",
1104 "git_run_tool",
1105 "git_tools",
1106 "git_toolbox_tools",
1107 ] {
1108 assert!(exports.contains(name), "std/git should export {name}");
1109 }
1110 }
1111
1112 #[test]
1113 fn agent_workers_exports_suspend_resume_wrappers() {
1114 let exports = public_functions_for_module("agent/workers");
1115 let suspend = exports
1116 .iter()
1117 .find(|function| function.name == "suspend_agent")
1118 .expect("std/agent/workers should export suspend_agent");
1119 assert_eq!(
1120 suspend.signature,
1121 "suspend_agent( agents: HarnessAgent, worker: unknown, reason: string = \"\", options: dict? = nil, ) -> unknown"
1122 );
1123 assert_eq!(suspend.required_params, 2);
1124 assert_eq!(suspend.total_params, 4);
1125
1126 let resume = exports
1127 .iter()
1128 .find(|function| function.name == "resume_agent")
1129 .expect("std/agent/workers should export resume_agent");
1130 assert_eq!(
1131 resume.signature,
1132 "resume_agent( agents: HarnessAgent, worker_or_snapshot: unknown, resume_input: unknown = nil, continue_transcript: bool = true, ) -> unknown"
1133 );
1134 assert_eq!(resume.required_params, 2);
1135 assert_eq!(resume.total_params, 4);
1136
1137 let stop = exports
1138 .iter()
1139 .find(|function| function.name == "agent_stop")
1140 .expect("std/agent/workers should export agent_stop");
1141 assert_eq!(
1142 stop.signature,
1143 "agent_stop( agents: HarnessAgent, worker: unknown, options: AgentStopOptions? = nil, ) -> unknown"
1144 );
1145 assert_eq!(stop.required_params, 2);
1146 assert_eq!(stop.total_params, 3);
1147
1148 let parse_resume = exports
1149 .iter()
1150 .find(|function| function.name == "parse_resume_conditions")
1151 .expect("std/agent/workers should export parse_resume_conditions");
1152 assert_eq!(
1153 parse_resume.signature,
1154 "parse_resume_conditions( agents: HarnessAgent, conditions: ResumeConditions? = nil, ) -> ResumeConditions?"
1155 );
1156 assert_eq!(parse_resume.required_params, 1);
1157 assert_eq!(parse_resume.total_params, 2);
1158
1159 let lifecycle = exports
1160 .iter()
1161 .find(|function| function.name == "agent_lifecycle_tools")
1162 .expect("std/agent/workers should export agent_lifecycle_tools");
1163 assert_eq!(
1164 lifecycle.signature,
1165 "agent_lifecycle_tools( agents: HarnessAgent, registry: ToolRegistry? = nil, options: AgentLifecycleToolsOptions? = nil, ) -> ToolRegistry"
1166 );
1167 assert_eq!(lifecycle.required_params, 1);
1168 assert_eq!(lifecycle.total_params, 3);
1169 }
1170
1171 #[test]
1172 fn tui_stdlib_module_exports_terminal_helpers() {
1173 let exports = public_functions_for_module("tui")
1174 .into_iter()
1175 .map(|function| function.name)
1176 .collect::<BTreeSet<_>>();
1177 for name in ["page", "terminal_width", "rule", "clear", "select_from"] {
1178 assert!(exports.contains(name), "std/tui should export {name}");
1179 }
1180 }
1181
1182 #[test]
1183 fn semver_stdlib_module_exports_release_helpers() {
1184 let exports = public_functions_for_module("semver")
1185 .into_iter()
1186 .map(|function| function.name)
1187 .collect::<BTreeSet<_>>();
1188 for name in [
1189 "strip_v",
1190 "add_v",
1191 "is_v_semver",
1192 "is_v_release_semver",
1193 "parse",
1194 "parse_release",
1195 "is_prerelease_identifier",
1196 "is_prerelease",
1197 "compare_release",
1198 "max_canonical_tag",
1199 "next",
1200 "bump_type",
1201 "version_from_release_branch",
1202 "version_from_tag",
1203 ] {
1204 assert!(exports.contains(name), "std/semver should export {name}");
1205 }
1206 }
1207
1208 #[test]
1209 fn changelog_stdlib_module_exports_typed_primitives() {
1210 let exports = public_functions_for_module("changelog")
1211 .into_iter()
1212 .map(|function| function.name)
1213 .collect::<BTreeSet<_>>();
1214 for name in [
1215 "changelog_validate_categories",
1216 "changelog_parse_fragment",
1217 "changelog_order_fragments",
1218 "changelog_normalize_fragment_body",
1219 "changelog_assemble_fragments",
1220 "changelog_parse_sections",
1221 "changelog_find_section",
1222 "changelog_merge_unreleased",
1223 ] {
1224 assert!(exports.contains(name), "std/changelog should export {name}");
1225 }
1226 }
1227
1228 #[test]
1229 fn text_stdlib_module_exports_regex_and_pad_helpers() {
1230 let exports = public_functions_for_module("text")
1231 .into_iter()
1232 .map(|function| function.name)
1233 .collect::<BTreeSet<_>>();
1234 for name in [
1235 "pad_left",
1236 "pad_right",
1237 "repeat_string",
1238 "regex_first_capture",
1239 "regex_capture_groups",
1240 "regex_all_first_captures",
1241 ] {
1242 assert!(exports.contains(name), "std/text should export {name}");
1243 }
1244 }
1245
1246 #[test]
1247 fn harn_entrypoint_catalog_is_declared_by_stdlib_sources() {
1248 let modules = entrypoint_modules();
1249 let entries = modules
1250 .iter()
1251 .map(|module| (module.import_path.as_str(), module.category.as_str()))
1252 .collect::<BTreeSet<_>>();
1253 for entry in [
1254 ("std/agent/loop", "agent.stdlib"),
1255 ("std/agent/primitives", "agent.stdlib"),
1256 ("std/workflow/execute", "workflow.stdlib"),
1257 ] {
1258 assert!(entries.contains(&entry), "{entry:?} should be declared");
1259 }
1260 }
1261
1262 #[test]
1263 fn matching_paren_len_closes_on_every_bracket_kind() {
1264 assert_eq!(matching_paren_len("a, b)"), Some(4));
1267 assert_eq!(matching_paren_len("x: [int])"), Some(8));
1268 assert_eq!(matching_paren_len("x: {a: int})"), Some(11));
1269 assert_eq!(matching_paren_len("x]"), Some(1));
1272 assert_eq!(matching_paren_len("x}"), Some(1));
1273 assert_eq!(matching_paren_len("unterminated"), None);
1274 }
1275
1276 #[test]
1277 fn parse_public_function_line_handles_record_typed_params() {
1278 let parsed =
1279 parse_public_function_line("pub fn configure(opts: {retries: int}) -> bool", None)
1280 .expect("signature with a record-typed parameter should parse");
1281 assert_eq!(parsed.name, "configure");
1282 assert_eq!(parsed.signature, "configure(opts: {retries: int}) -> bool");
1283 assert_eq!(parsed.total_params, 1);
1284 assert_eq!(parsed.required_params, 1);
1285 }
1286
1287 #[test]
1288 fn parse_public_function_line_indexes_generic_functions_by_base_name() {
1289 let parsed = parse_public_function_line(
1290 "pub fn map<T, U>(items: list<T>, project: fn(T) -> U) -> list<U>",
1291 None,
1292 )
1293 .expect("generic public function should parse");
1294 assert_eq!(parsed.name, "map");
1295 assert_eq!(
1296 parsed.signature,
1297 "map<T, U>(items: list<T>, project: fn(T) -> U) -> list<U>"
1298 );
1299 assert_eq!(parsed.total_params, 2);
1300 assert_eq!(parsed.required_params, 2);
1301 }
1302}