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