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