Skip to main content

alef_core/config/
languages.rs

1use serde::{Deserialize, Serialize};
2use std::collections::HashMap;
3use std::path::PathBuf;
4
5use super::extras::Language;
6
7/// Configuration for a single capsule type entry in `PythonConfig::capsule_types`.
8///
9/// Supports two TOML forms via `#[serde(untagged)]`:
10///
11/// - String: `Language = "tree_sitter.Language"` → capsule round-trip via `into_raw()`
12/// - Struct: `Parser = { python_type = "tree_sitter.Parser", construct_from = "Language" }` → Python-side construction
13#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
14#[serde(untagged)]
15pub enum CapsuleTypeConfig {
16    /// Capsule round-trip: the Rust type exposes `into_raw()` returning a raw pointer.
17    /// The generated code calls `PyCapsule_New(value.into_raw(), capsule_name, None)` on return,
18    /// and `PyCapsule_GetPointer` + `from_raw()` on input.
19    ///
20    /// Value is the fully-qualified Python capsule name (e.g. `"tree_sitter.Language"`).
21    Capsule(String),
22    /// Python-side construction: the type does not have a direct `into_raw()`.
23    /// Instead, the generated code constructs the Python type by calling a Python factory
24    /// (e.g. `tree_sitter.Parser(language)`) where `language` is a bound capsule argument.
25    ConstructFrom {
26        /// The fully-qualified Python type to import and call (e.g. `"tree_sitter.Parser"`).
27        python_type: String,
28        /// The capsule-type argument name to pass to the Python constructor.
29        /// Must be one of the other capsule-type entries (e.g. `"Language"`).
30        construct_from: String,
31    },
32}
33
34impl CapsuleTypeConfig {
35    /// Returns the Python type string (dotted path) for this config entry.
36    pub fn python_type(&self) -> &str {
37        match self {
38            Self::Capsule(name) => name,
39            Self::ConstructFrom { python_type, .. } => python_type,
40        }
41    }
42
43    /// Returns the `construct_from` dependency type name, if this is a `ConstructFrom` entry.
44    pub fn construct_from(&self) -> Option<&str> {
45        match self {
46            Self::ConstructFrom { construct_from, .. } => Some(construct_from.as_str()),
47            Self::Capsule(_) => None,
48        }
49    }
50
51    /// Returns true when this entry represents a raw capsule round-trip (not Python-side construction).
52    pub fn is_capsule_roundtrip(&self) -> bool {
53        matches!(self, Self::Capsule(_))
54    }
55}
56
57#[derive(Debug, Clone, Serialize, Deserialize)]
58pub struct PythonConfig {
59    pub module_name: Option<String>,
60    pub async_runtime: Option<String>,
61    pub stubs: Option<StubsConfig>,
62    /// PyPI package name (e.g. `"html-to-markdown"`). Used as the `[project] name` in
63    /// `pyproject.toml` and to derive the `python-packages` list for maturin.
64    /// Defaults to the crate name.
65    #[serde(default)]
66    pub pip_name: Option<String>,
67    /// Per-language feature override. When set, these features are used instead of
68    /// `[crate] features` for this language's binding crate.
69    #[serde(default)]
70    pub features: Option<Vec<String>>,
71    /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
72    /// When set, this takes priority over the IR type-level serde_rename_all.
73    #[serde(default)]
74    pub serde_rename_all: Option<String>,
75    /// Map of type name -> capsule config for PyCapsule pass-through.
76    /// Types listed here are emitted as PyCapsule_New / PyCapsule_GetPointer instead of
77    /// opaque `#[pyclass]` wrappers. Use `CapsuleTypeConfig::Capsule` for raw capsule
78    /// round-trips and `CapsuleTypeConfig::ConstructFrom` for Python-side construction.
79    #[serde(default)]
80    pub capsule_types: HashMap<String, CapsuleTypeConfig>,
81    /// When true, wrap blocking function bodies in py.allow_threads() to release the GIL.
82    // TODO: Wire into gen_bindings.rs to emit py.allow_threads(|| { ... }) for non-async functions.
83    #[serde(default)]
84    pub release_gil: bool,
85    /// Functions to exclude from Python binding generation.
86    #[serde(default)]
87    pub exclude_functions: Vec<String>,
88    /// Types to exclude from Python binding generation.
89    #[serde(default)]
90    pub exclude_types: Vec<String>,
91    /// Additional Cargo dependencies for this language's binding crate only.
92    #[serde(default)]
93    pub extra_dependencies: HashMap<String, toml::Value>,
94    /// Override the scaffold output directory for this language's Cargo.toml and package files.
95    #[serde(default)]
96    pub scaffold_output: Option<PathBuf>,
97    /// Per-field name remapping for this language. Key is `TypeName.field_name` (e.g.
98    /// `"LayoutDetection.class"`), value is the desired binding field name. Applied after
99    /// automatic keyword escaping, so an explicit entry takes priority.
100    #[serde(default)]
101    pub rename_fields: HashMap<String, String>,
102    /// Prefix wrapper for default tool invocations. When set, prepends this string to default
103    /// commands across all pipelines (lint, test, build, etc.).
104    /// E.g., `run_wrapper = "uv run --no-sync"` turns `ruff format packages/python` into
105    /// `uv run --no-sync ruff format packages/python`.
106    #[serde(default)]
107    pub run_wrapper: Option<String>,
108    /// Extra paths to append to default lint commands (format, check, typecheck).
109    /// Space-separated paths are appended to the command.
110    #[serde(default)]
111    pub extra_lint_paths: Vec<String>,
112    /// Additional `from <module> import <symbol>` lines to emit in the generated `__init__.py`.
113    /// Key is the relative or absolute Python module path (e.g. `"._supported_languages"`),
114    /// value is the list of symbols to import. The symbols are also added to `__all__`.
115    ///
116    /// Use this to re-export hand-written sibling modules (e.g. generated by a project's own
117    /// build script) without alef's cleanup culling them. The hand-written file must NOT contain
118    /// the substrings `"DO NOT EDIT"`, `"auto-generated by alef"`, or `"AUTO-GENERATED by alef"`
119    /// in its first 5 lines, or alef's cleanup pipeline will treat it as a stale alef artifact.
120    #[serde(default)]
121    pub extra_init_imports: std::collections::BTreeMap<String, Vec<String>>,
122}
123
124#[derive(Debug, Clone, Serialize, Deserialize)]
125pub struct StubsConfig {
126    pub output: PathBuf,
127}
128
129/// Configuration for a single capsule type entry in `NodeConfig::capsule_types`.
130///
131/// When set, the named Rust type is NOT emitted as a `#[napi]` opaque wrapper.
132/// Instead, functions returning this type produce a `JsObject` carrying the raw
133/// pointer in a configurable `Napi::External<T>` property — the layout consumed
134/// by the `tree-sitter` npm package's `Parser.setLanguage()`.
135///
136/// TOML form:
137/// ```toml
138/// [crates.node.capsule_types.Language]
139/// type = "Language"
140/// from_module = "tree-sitter"
141/// property_name = "language"
142/// type_tag = { lower = "0x8AF2E5212AD58ABF", upper = "0xD5006CAD83ABBA16" }
143/// ```
144#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
145pub struct NodeCapsuleTypeConfig {
146    /// User-facing class name in the ecosystem library (e.g. `"Language"`).
147    /// Emitted as the return-type annotation in the generated `index.d.ts`.
148    #[serde(rename = "type")]
149    pub type_name: String,
150    /// npm package to import the type from (e.g. `"tree-sitter"`).
151    /// Emitted as the `from` clause in the generated `import type` line.
152    pub from_module: String,
153    /// Codegen strategy. Currently only `"external_pointer"` is supported.
154    /// Defaults to `"external_pointer"`.
155    #[serde(default = "default_node_capsule_construct")]
156    pub construct: String,
157    /// JS property name to set on the returned object. `node-tree-sitter`
158    /// reads `value["language"]`; other consumers may use different names.
159    /// Defaults to `"__parser"` for back-compat with existing configs.
160    #[serde(default = "default_node_capsule_property_name")]
161    pub property_name: String,
162    /// Optional N-API type tag to apply via `napi_type_tag_object`. Required
163    /// when the consumer library (e.g. `node-tree-sitter`) calls
164    /// `napi_check_object_type_tag` to validate the External before using it.
165    #[serde(default)]
166    pub type_tag: Option<NapiTypeTagConfig>,
167}
168
169/// An N-API `napi_type_tag` value, expressed as two 64-bit hex strings.
170#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
171pub struct NapiTypeTagConfig {
172    /// Lower 64 bits of the tag, hex (e.g. `"0x8AF2E5212AD58ABF"`).
173    pub lower: String,
174    /// Upper 64 bits of the tag, hex (e.g. `"0xD5006CAD83ABBA16"`).
175    pub upper: String,
176}
177
178fn default_node_capsule_construct() -> String {
179    "external_pointer".to_string()
180}
181
182fn default_node_capsule_property_name() -> String {
183    "__parser".to_string()
184}
185
186#[derive(Debug, Clone, Serialize, Deserialize)]
187pub struct NodeConfig {
188    pub package_name: Option<String>,
189    /// Per-language feature override. When set, these features are used instead of
190    /// `[crate] features` for this language's binding crate.
191    #[serde(default)]
192    pub features: Option<Vec<String>>,
193    /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
194    /// When set, this takes priority over the IR type-level serde_rename_all.
195    #[serde(default)]
196    pub serde_rename_all: Option<String>,
197    /// Prefix for generated type names (e.g. "Js" produces `JsConversionOptions`).
198    /// Defaults to `"Js"`.
199    #[serde(default)]
200    pub type_prefix: Option<String>,
201    /// Map of Rust type name -> capsule config for raw-pointer passthrough.
202    /// Types listed here skip the default `#[napi]` opaque-wrapper emission;
203    /// functions returning them produce a `JsObject` with a `__parser`
204    /// `Napi::External<T>` property instead. See [`NodeCapsuleTypeConfig`].
205    #[serde(default)]
206    pub capsule_types: HashMap<String, NodeCapsuleTypeConfig>,
207    /// Functions to exclude from Node binding generation.
208    #[serde(default)]
209    pub exclude_functions: Vec<String>,
210    /// Types to exclude from Node binding generation.
211    #[serde(default)]
212    pub exclude_types: Vec<String>,
213    /// Additional Cargo dependencies for this language's binding crate only.
214    #[serde(default)]
215    pub extra_dependencies: HashMap<String, toml::Value>,
216    /// Override the scaffold output directory for this language's Cargo.toml and package files.
217    #[serde(default)]
218    pub scaffold_output: Option<PathBuf>,
219    /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
220    /// desired binding field name. Applied after automatic keyword escaping.
221    #[serde(default)]
222    pub rename_fields: HashMap<String, String>,
223    /// Prefix wrapper for default tool invocations. When set, prepends this string to default
224    /// commands across all pipelines (lint, test, build, etc.).
225    #[serde(default)]
226    pub run_wrapper: Option<String>,
227    /// Extra paths to append to default lint commands (format, check, typecheck).
228    #[serde(default)]
229    pub extra_lint_paths: Vec<String>,
230}
231
232#[derive(Debug, Clone, Serialize, Deserialize)]
233pub struct RubyConfig {
234    pub gem_name: Option<String>,
235    pub stubs: Option<StubsConfig>,
236    /// Per-language feature override. When set, these features are used instead of
237    /// `[crate] features` for this language's binding crate.
238    #[serde(default)]
239    pub features: Option<Vec<String>>,
240    /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
241    /// When set, this takes priority over the IR type-level serde_rename_all.
242    #[serde(default)]
243    pub serde_rename_all: Option<String>,
244    /// Functions to exclude from Ruby binding generation.
245    #[serde(default)]
246    pub exclude_functions: Vec<String>,
247    /// Types to exclude from Ruby binding generation.
248    #[serde(default)]
249    pub exclude_types: Vec<String>,
250    /// Additional Cargo dependencies for this language's binding crate only.
251    #[serde(default)]
252    pub extra_dependencies: HashMap<String, toml::Value>,
253    /// Override the scaffold output directory for this language's Cargo.toml and package files.
254    #[serde(default)]
255    pub scaffold_output: Option<PathBuf>,
256    /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
257    /// desired binding field name. Applied after automatic keyword escaping.
258    #[serde(default)]
259    pub rename_fields: HashMap<String, String>,
260    /// Prefix wrapper for default tool invocations. When set, prepends this string to default
261    /// commands across all pipelines (lint, test, build, etc.).
262    #[serde(default)]
263    pub run_wrapper: Option<String>,
264    /// Extra paths to append to default lint commands (format, check, typecheck).
265    #[serde(default)]
266    pub extra_lint_paths: Vec<String>,
267}
268
269#[derive(Debug, Clone, Serialize, Deserialize)]
270pub struct PhpConfig {
271    pub extension_name: Option<String>,
272    /// Cargo crate name for the PHP binding (e.g. `"ts-pack-core-php"`).
273    /// Used to derive the shared library filename in the e2e test runner.
274    /// When absent, the lib name is derived from `extension_name` by appending `_php`.
275    #[serde(default)]
276    pub cargo_crate_name: Option<String>,
277    /// Override the PHP namespace used for class registration and PSR-4 autoloading.
278    ///
279    /// When set, this value is used verbatim as the PHP namespace (e.g. `"HtmlToMarkdown"`).
280    /// When absent, the namespace is derived from `extension_name` by splitting on `_` and
281    /// converting each segment to PascalCase (e.g. `html_to_markdown` → `Html\To\Markdown`).
282    #[serde(default)]
283    pub namespace: Option<String>,
284    /// Feature gate for ext-php-rs (default: "extension-module").
285    /// All generated code is wrapped in `#[cfg(feature = "...")]`.
286    #[serde(default)]
287    pub feature_gate: Option<String>,
288    /// Output directory for generated PHP facade / stubs (e.g., `packages/php/src/`).
289    #[serde(default)]
290    pub stubs: Option<StubsConfig>,
291    #[serde(default)]
292    pub features: Option<Vec<String>>,
293    /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
294    /// When set, this takes priority over the IR type-level serde_rename_all.
295    #[serde(default)]
296    pub serde_rename_all: Option<String>,
297    /// Functions to exclude from PHP binding generation.
298    #[serde(default)]
299    pub exclude_functions: Vec<String>,
300    /// Types to exclude from PHP binding generation.
301    #[serde(default)]
302    pub exclude_types: Vec<String>,
303    /// Additional Cargo dependencies for this language's binding crate only.
304    #[serde(default)]
305    pub extra_dependencies: HashMap<String, toml::Value>,
306    /// Override the scaffold output directory for this language's Cargo.toml and package files.
307    #[serde(default)]
308    pub scaffold_output: Option<PathBuf>,
309    /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
310    /// desired binding field name. Applied after automatic keyword escaping.
311    #[serde(default)]
312    pub rename_fields: HashMap<String, String>,
313    /// Prefix wrapper for default tool invocations. When set, prepends this string to default
314    /// commands across all pipelines (lint, test, build, etc.).
315    #[serde(default)]
316    pub run_wrapper: Option<String>,
317    /// Extra paths to append to default lint commands (format, check, typecheck).
318    #[serde(default)]
319    pub extra_lint_paths: Vec<String>,
320}
321
322#[derive(Debug, Clone, Serialize, Deserialize)]
323pub struct ElixirConfig {
324    pub app_name: Option<String>,
325    #[serde(default)]
326    pub features: Option<Vec<String>>,
327    /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
328    /// When set, this takes priority over the IR type-level serde_rename_all.
329    #[serde(default)]
330    pub serde_rename_all: Option<String>,
331    /// Functions to exclude from Elixir NIF generation.
332    #[serde(default)]
333    pub exclude_functions: Vec<String>,
334    /// Types to exclude from Elixir NIF generation.
335    #[serde(default)]
336    pub exclude_types: Vec<String>,
337    /// Additional Cargo dependencies for this language's binding crate only.
338    #[serde(default)]
339    pub extra_dependencies: HashMap<String, toml::Value>,
340    /// Override the scaffold output directory for this language's Cargo.toml and package files.
341    #[serde(default)]
342    pub scaffold_output: Option<PathBuf>,
343    /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
344    /// desired binding field name. Applied after automatic keyword escaping.
345    #[serde(default)]
346    pub rename_fields: HashMap<String, String>,
347    /// Prefix wrapper for default tool invocations. When set, prepends this string to default
348    /// commands across all pipelines (lint, test, build, etc.).
349    #[serde(default)]
350    pub run_wrapper: Option<String>,
351    /// Extra paths to append to default lint commands (format, check, typecheck).
352    #[serde(default)]
353    pub extra_lint_paths: Vec<String>,
354    /// Functions that should be scheduled on the dirty CPU scheduler.
355    /// HTML parsing and other CPU-intensive NIFs should be listed here to avoid
356    /// blocking BEAM scheduler threads.
357    #[serde(default)]
358    pub cpu_bound_functions: Vec<String>,
359}
360
361#[derive(Debug, Clone, Serialize, Deserialize)]
362pub struct WasmConfig {
363    #[serde(default)]
364    pub exclude_functions: Vec<String>,
365    #[serde(default)]
366    pub exclude_types: Vec<String>,
367    #[serde(default)]
368    pub type_overrides: HashMap<String, String>,
369    #[serde(default)]
370    pub features: Option<Vec<String>>,
371    /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
372    /// When set, this takes priority over the IR type-level serde_rename_all.
373    #[serde(default)]
374    pub serde_rename_all: Option<String>,
375    /// Prefix for generated type names (e.g. "Wasm" produces `WasmConversionOptions`).
376    /// Defaults to `"Wasm"`.
377    #[serde(default)]
378    pub type_prefix: Option<String>,
379    /// Functions to exclude from the public TypeScript re-export (index.ts) while still
380    /// generating the Rust binding. Use this when a custom module provides a wrapper.
381    #[serde(default)]
382    pub exclude_reexports: Vec<String>,
383    /// Wide-character C functions to shim for WASM external scanner interop.
384    #[serde(default)]
385    pub env_shims: Vec<String>,
386    /// Additional Cargo dependencies for the WASM binding crate only.
387    #[serde(default)]
388    pub extra_dependencies: HashMap<String, toml::Value>,
389    /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
390    /// desired binding field name. Applied after automatic keyword escaping.
391    #[serde(default)]
392    pub rename_fields: HashMap<String, String>,
393    /// Prefix wrapper for default tool invocations. When set, prepends this string to default
394    /// commands across all pipelines (lint, test, build, etc.).
395    #[serde(default)]
396    pub run_wrapper: Option<String>,
397    /// Extra paths to append to default lint commands (format, check, typecheck).
398    #[serde(default)]
399    pub extra_lint_paths: Vec<String>,
400    /// Override the core Cargo dependency name and path for the WASM binding crate.
401    /// When set, the binding `Cargo.toml` depends on this crate (resolved as
402    /// `../<override>`) instead of the umbrella `[crate.name]`. Use this to point
403    /// the WASM binding at a wasm-safe sub-crate while other languages keep the
404    /// facade. Defaults to unset.
405    #[serde(default)]
406    pub core_crate_override: Option<String>,
407    /// Keys to subtract from the merged `extra_dependencies` set for this
408    /// language only. Useful when `[crate.extra_dependencies]` lists sibling
409    /// crates that the WASM target cannot link.
410    #[serde(default)]
411    pub exclude_extra_dependencies: Vec<String>,
412    /// Hand-written Rust modules to declare in the generated lib.rs with `pub mod <name>;`
413    /// and re-export with `pub use <name>::*;`. Separate from `[custom_modules].wasm` which
414    /// only adds TypeScript `export *` re-exports. Use this for Rust-side dispatch/glue modules.
415    #[serde(default)]
416    pub custom_rust_modules: Vec<String>,
417    /// Per-type field exclusions for the generated From impls and binding struct.
418    /// Key is the type name (e.g. "ServerConfig"), value is a list of field names to skip.
419    /// Use when source fields are gated behind `#[cfg(not(target_arch = "wasm32"))]` and
420    /// therefore don't exist in the wasm32 compilation environment.
421    #[serde(default)]
422    pub exclude_fields: HashMap<String, Vec<String>>,
423    /// Source crate names whose types are re-exported by the `core_crate_override`
424    /// crate. References to `<original_crate>::TypeName` in generated code are
425    /// rewritten to `<override_crate>::TypeName`. Only meaningful when
426    /// `core_crate_override` is set.
427    /// Example: with `core_crate_override = "mylib-http"`, setting
428    /// `source_crate_remaps = ["mylib-core", "mylib"]` rewrites
429    /// `mylib_core::Method` and `mylib::Method` references to
430    /// `mylib_http::Method` (assumes `mylib-http` re-exports them via
431    /// `pub use mylib_core::*`).
432    #[serde(default)]
433    pub source_crate_remaps: Vec<String>,
434}
435
436#[derive(Debug, Clone, Serialize, Deserialize)]
437pub struct FfiConfig {
438    pub prefix: Option<String>,
439    #[serde(default = "default_error_style")]
440    pub error_style: String,
441    pub header_name: Option<String>,
442    /// Native library name for Go cgo/Java Panama/C# P/Invoke (e.g., "ts_pack_ffi").
443    /// Defaults to `{prefix}_ffi`.
444    #[serde(default)]
445    pub lib_name: Option<String>,
446    /// If true, generate visitor/callback FFI support.
447    #[serde(default)]
448    pub visitor_callbacks: bool,
449    #[serde(default)]
450    pub features: Option<Vec<String>>,
451    /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
452    /// When set, this takes priority over the IR type-level serde_rename_all.
453    #[serde(default)]
454    pub serde_rename_all: Option<String>,
455    /// Functions to exclude from FFI binding generation.
456    #[serde(default)]
457    pub exclude_functions: Vec<String>,
458    /// Types to exclude from FFI binding generation.
459    #[serde(default)]
460    pub exclude_types: Vec<String>,
461    /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
462    /// desired binding field name. Applied after automatic keyword escaping.
463    #[serde(default)]
464    pub rename_fields: HashMap<String, String>,
465    /// Rust expression used to construct an error value of this crate's
466    /// `error_type` from a runtime `String` message inside generated FFI
467    /// trait-bridge plugin shims (`plugin_impl_initialize`, `plugin_impl_shutdown`).
468    ///
469    /// The expression has access to a local variable `msg: String` containing
470    /// the underlying error message and is interpolated verbatim. Example
471    /// values:
472    ///
473    /// ```toml
474    /// # downstream whose error type has a struct variant with two fields:
475    /// plugin_error_constructor = """
476    /// kreuzberg::KreuzbergError::Plugin { message: msg, plugin_name: String::new() }
477    /// """
478    ///
479    /// # downstream whose error type implements `From<String>`:
480    /// plugin_error_constructor = "MyError::from(msg)"
481    /// ```
482    ///
483    /// Defaults to `None`. When unset, the plugin shim still emits — backends
484    /// fall back to a `format!("{}: {}", prefix, msg)`-style construction via
485    /// the configured `error_constructor`. Downstreams that don't expose
486    /// trait-bridged plugins can ignore this knob entirely.
487    #[serde(default)]
488    pub plugin_error_constructor: Option<String>,
489}
490
491fn default_error_style() -> String {
492    "last_error".to_string()
493}
494
495#[derive(Debug, Clone, Serialize, Deserialize)]
496pub struct GoConfig {
497    pub module: Option<String>,
498    /// Override the Go package name (default: derived from module path)
499    pub package_name: Option<String>,
500    #[serde(default)]
501    pub features: Option<Vec<String>>,
502    /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
503    /// When set, this takes priority over the IR type-level serde_rename_all.
504    #[serde(default)]
505    pub serde_rename_all: Option<String>,
506    /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
507    /// desired binding field name. Applied after automatic keyword escaping.
508    #[serde(default)]
509    pub rename_fields: HashMap<String, String>,
510    /// Prefix wrapper for default tool invocations. When set, prepends this string to default
511    /// commands across all pipelines (lint, test, build, etc.).
512    #[serde(default)]
513    pub run_wrapper: Option<String>,
514    /// Extra paths to append to default lint commands (format, check, typecheck).
515    #[serde(default)]
516    pub extra_lint_paths: Vec<String>,
517}
518
519#[derive(Debug, Clone, Serialize, Deserialize)]
520pub struct JavaConfig {
521    pub package: Option<String>,
522    /// Override the Maven `<groupId>` emitted by alef-scaffold and alef-e2e. When unset,
523    /// `java_group_id()` falls back to the Java `package` value. Set this when the
524    /// published Maven coords differ from the Java package path (e.g. group
525    /// `dev.kreuzberg`, package `dev.kreuzberg.htmltomarkdown`).
526    #[serde(default)]
527    pub group_id: Option<String>,
528    /// Override the Maven `<artifactId>` emitted by alef-scaffold and alef-e2e. When
529    /// unset, defaults to the crate name (the `[[crates]] name = "..."`). Set this when
530    /// the published artifactId differs from the source crate name (e.g. crate
531    /// `html-to-markdown-rs` published as `html-to-markdown`).
532    #[serde(default)]
533    pub artifact_id: Option<String>,
534    #[serde(default = "default_java_ffi_style")]
535    pub ffi_style: String,
536    #[serde(default)]
537    pub features: Option<Vec<String>>,
538    /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
539    /// When set, this takes priority over the IR type-level serde_rename_all.
540    #[serde(default)]
541    pub serde_rename_all: Option<String>,
542    /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
543    /// desired binding field name. Applied after automatic keyword escaping.
544    #[serde(default)]
545    pub rename_fields: HashMap<String, String>,
546    /// Prefix wrapper for default tool invocations. When set, prepends this string to default
547    /// commands across all pipelines (lint, test, build, etc.).
548    #[serde(default)]
549    pub run_wrapper: Option<String>,
550    /// Extra paths to append to default lint commands (format, check, typecheck).
551    /// Ignored when project_file is set.
552    #[serde(default)]
553    pub extra_lint_paths: Vec<String>,
554    /// Project file for Maven/Gradle (e.g., "pom.xml", "build.gradle"). When set, default
555    /// lint/build/test commands target this file instead of the output directory.
556    #[serde(default)]
557    pub project_file: Option<String>,
558}
559
560fn default_java_ffi_style() -> String {
561    "panama".to_string()
562}
563
564/// Target platform for Kotlin code generation.
565///
566/// - `"jvm"` (default): emits source consuming the Java/Panama FFM facade.
567/// - `"native"`: emits Kotlin/Native source consuming the cbindgen C FFI library.
568/// - `"multiplatform"`: emits Kotlin Multiplatform project scaffolding.
569#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, PartialEq, Eq)]
570#[serde(rename_all = "lowercase")]
571pub enum KotlinTarget {
572    #[default]
573    Jvm,
574    Native,
575    // Multiplatform — Phase 3 KMP stage; placeholder so the enum is forward-compatible.
576    Multiplatform,
577}
578
579#[derive(Debug, Clone, Serialize, Deserialize)]
580pub struct KotlinConfig {
581    pub package: Option<String>,
582    #[serde(default)]
583    pub features: Option<Vec<String>>,
584    /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
585    /// When set, this takes priority over the IR type-level serde_rename_all.
586    #[serde(default)]
587    pub serde_rename_all: Option<String>,
588    /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
589    /// desired binding field name. Applied after automatic keyword escaping.
590    #[serde(default)]
591    pub rename_fields: HashMap<String, String>,
592    /// Functions to exclude from Kotlin binding generation.
593    #[serde(default)]
594    pub exclude_functions: Vec<String>,
595    /// Types to exclude from Kotlin binding generation.
596    #[serde(default)]
597    pub exclude_types: Vec<String>,
598    /// Prefix wrapper for default tool invocations. When set, prepends this string to default
599    /// commands across all pipelines (lint, test, build, etc.).
600    #[serde(default)]
601    pub run_wrapper: Option<String>,
602    /// Extra paths to append to default lint commands (format, check, typecheck).
603    #[serde(default)]
604    pub extra_lint_paths: Vec<String>,
605    /// Target platform for Kotlin output. `"jvm"` (default) emits source consuming
606    /// the Java/Panama FFM facade; `"native"` emits Kotlin/Native source consuming
607    /// the cbindgen C FFI library. `"multiplatform"` emits KMP scaffolding.
608    #[serde(default)]
609    pub target: KotlinTarget,
610    /// Emission mode controlling which Kotlin project layout is generated.
611    ///
612    /// Accepted values:
613    /// - `"jvm"` (default) — standard JVM-only project under `packages/kotlin/`
614    /// - `"kmp"` — Kotlin Multiplatform project under `packages/kotlin-mpp/`
615    /// - `"android"` — Android library project under `packages/kotlin-android/`
616    ///
617    /// When `None`, defaults to `"jvm"`.
618    #[serde(default)]
619    pub mode: Option<String>,
620}
621
622/// Configuration for the dedicated Kotlin/Android backend (`alef-backend-kotlin-android`).
623///
624/// Distinct from [`KotlinConfig`] (Kotlin/JVM). When a crate targets the
625/// `kotlin_android` language slug, this struct controls the emitted
626/// `build.gradle.kts`, `AndroidManifest.xml`, namespace, Maven publish
627/// coordinates, ABI list, and the bundled Java facade emitted into
628/// `src/main/java/` so the AAR is self-contained.
629#[derive(Debug, Clone, Default, Serialize, Deserialize)]
630pub struct KotlinAndroidConfig {
631    /// JVM-style package for Kotlin bindings (e.g. `dev.kreuzberg`).
632    /// Defaults to the crate name.
633    #[serde(default)]
634    pub package: Option<String>,
635    /// Android library manifest `namespace`. Defaults to `package`.
636    #[serde(default)]
637    pub namespace: Option<String>,
638    /// Maven `artifactId` for the generated AAR. Defaults to `{crate}-android`.
639    #[serde(default)]
640    pub artifact_id: Option<String>,
641    /// Maven `groupId` for the generated AAR. No default — when unset the
642    /// emitter falls back to `package`.
643    #[serde(default)]
644    pub group_id: Option<String>,
645    /// Android compile SDK level. Defaults to `template_versions::toolchain::ANDROID_COMPILE_SDK`.
646    #[serde(default)]
647    pub compile_sdk: Option<u32>,
648    /// Android min SDK level. Defaults to `template_versions::toolchain::ANDROID_MIN_SDK`.
649    #[serde(default)]
650    pub min_sdk: Option<u32>,
651    /// JVM bytecode target for Kotlin and Java compilation
652    /// (e.g. `"17"`). Defaults to `template_versions::toolchain::ANDROID_JVM_TARGET`.
653    #[serde(default)]
654    pub jvm_target: Option<String>,
655    /// ABIs to scaffold under `src/main/jniLibs/<abi>/`. Defaults to
656    /// `["arm64-v8a", "x86_64"]`.
657    #[serde(default)]
658    pub abis: Option<Vec<String>>,
659    /// Override the serde rename_all strategy for JSON field names.
660    #[serde(default)]
661    pub serde_rename_all: Option<String>,
662    /// Per-field name remapping for this language. Key is `TypeName.field_name`.
663    #[serde(default)]
664    pub rename_fields: HashMap<String, String>,
665    /// Functions to exclude from generation.
666    #[serde(default)]
667    pub exclude_functions: Vec<String>,
668    /// Types to exclude from generation.
669    #[serde(default)]
670    pub exclude_types: Vec<String>,
671    /// Prefix wrapper for default tool invocations.
672    #[serde(default)]
673    pub run_wrapper: Option<String>,
674    /// Extra paths to append to default lint commands.
675    #[serde(default)]
676    pub extra_lint_paths: Vec<String>,
677    /// Per-language feature override. When set, these features are used instead of
678    /// `[crate] features` for this language's binding crate.
679    #[serde(default)]
680    pub features: Option<Vec<String>>,
681}
682
683/// Dart bridging style: FRB (default) or raw `dart:ffi`.
684#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, PartialEq, Eq)]
685#[serde(rename_all = "lowercase")]
686pub enum DartStyle {
687    /// flutter_rust_bridge — emits a Rust crate plus Dart wrappers using
688    /// FRB-generated bridge symbols. Default.
689    #[default]
690    Frb,
691    /// Raw `dart:ffi` over the cbindgen C ABI — emits Dart-only source that
692    /// loads the shared library at runtime. Cheaper to ship; loses FRB's
693    /// async ergonomics and freezed-style data classes.
694    Ffi,
695}
696
697#[derive(Debug, Clone, Serialize, Deserialize)]
698pub struct GleamConfig {
699    pub app_name: Option<String>,
700    /// Erlang atom name for @external(erlang, "<nif>", ...) lookups (e.g., "my_app_nif").
701    /// Defaults to the app_name.
702    #[serde(default)]
703    pub nif_module: Option<String>,
704    #[serde(default)]
705    pub features: Option<Vec<String>>,
706    /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
707    /// When set, this takes priority over the IR type-level serde_rename_all.
708    #[serde(default)]
709    pub serde_rename_all: Option<String>,
710    /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
711    /// desired binding field name. Applied after automatic keyword escaping.
712    #[serde(default)]
713    pub rename_fields: HashMap<String, String>,
714    /// Functions to exclude from Gleam binding generation.
715    #[serde(default)]
716    pub exclude_functions: Vec<String>,
717    /// Types to exclude from Gleam binding generation.
718    #[serde(default)]
719    pub exclude_types: Vec<String>,
720    /// Prefix wrapper for default tool invocations.
721    #[serde(default)]
722    pub run_wrapper: Option<String>,
723    /// Extra paths to append to default lint commands.
724    #[serde(default)]
725    pub extra_lint_paths: Vec<String>,
726    /// Per-`element_type` Gleam record-constructor recipes used by the e2e
727    /// generator when emitting `json_object` arg literals. Each entry maps a
728    /// fixture-side `element_type` string (e.g. `"BatchFileItem"`) to a
729    /// structured constructor description that the codegen interpolates per
730    /// JSON-array item. Without an entry the codegen falls back to the
731    /// `json_object_wrapper` (or a plain `json_to_gleam`).
732    ///
733    /// Example:
734    ///
735    /// ```toml
736    /// [[crates.gleam.element_constructors]]
737    /// element_type = "BatchFileItem"
738    /// constructor = "kreuzberg.BatchFileItem"
739    /// [[crates.gleam.element_constructors.fields]]
740    /// gleam_field = "path"
741    /// kind = "file_path"
742    /// json_field = "path"
743    /// [[crates.gleam.element_constructors.fields]]
744    /// gleam_field = "config"
745    /// kind = "literal"
746    /// value = "option.None"
747    /// ```
748    #[serde(default)]
749    pub element_constructors: Vec<GleamElementConstructor>,
750    /// Optional Gleam expression template used to wrap `json_object` arg
751    /// values when no `element_type` recipe matches. The placeholder
752    /// `{json}` is replaced with a Gleam string literal containing the JSON
753    /// form of the arg value, allowing the downstream's Gleam binding to do
754    /// its own parsing.
755    ///
756    /// Example:
757    ///
758    /// ```toml
759    /// [crates.gleam]
760    /// json_object_wrapper = "kreuzberg.config_from_json_string({json})"
761    /// ```
762    ///
763    /// When `None`, the codegen emits `{json}` verbatim (a plain Gleam
764    /// string), matching the iter15 default.
765    #[serde(default)]
766    pub json_object_wrapper: Option<String>,
767}
768
769/// One per-`element_type` Gleam record-constructor recipe. Keyed by the
770/// fixture-side `element_type` string and consumed by the e2e Gleam codegen
771/// when building `json_object` arg literals.
772#[derive(Debug, Clone, Serialize, Deserialize)]
773pub struct GleamElementConstructor {
774    /// Fixture-side `element_type` value this recipe applies to (e.g.
775    /// `"BatchFileItem"`).
776    pub element_type: String,
777    /// Fully-qualified Gleam constructor identifier (e.g.
778    /// `"kreuzberg.BatchFileItem"`). Emitted verbatim before the `(...)` field
779    /// list.
780    pub constructor: String,
781    /// Ordered list of fields to emit inside the constructor's `(...)` block,
782    /// in argument-position order. Each field describes how its value is
783    /// derived from the per-item JSON object.
784    pub fields: Vec<GleamElementField>,
785}
786
787/// One field inside a [`GleamElementConstructor`]'s argument list.
788///
789/// `kind` selects the source/encoding strategy:
790/// * `"file_path"` — read `json_field` from the JSON object as a string,
791///   prefix with the configured `test_documents_dir` when the value does not
792///   start with `/`, and emit as a Gleam string literal.
793/// * `"byte_array"` — read `json_field` from the JSON object as a JSON
794///   `Array(Number)` and emit as a Gleam BitArray literal `<<n1, n2, …>>`.
795/// * `"string"` — read `json_field` as a string, emit as a Gleam string
796///   literal; falls back to `default` (or empty) if missing.
797/// * `"literal"` — emit `value` verbatim (no JSON lookup). Use for
798///   constant fields like `config: option.None`.
799#[derive(Debug, Clone, Serialize, Deserialize)]
800pub struct GleamElementField {
801    /// Gleam record field name (e.g. `"path"`, `"config"`).
802    pub gleam_field: String,
803    /// Source/encoding strategy. See struct doc.
804    pub kind: String,
805    /// JSON object key to read, when `kind` is one of the JSON-driven
806    /// strategies. Required for `"file_path"`, `"byte_array"`, `"string"`;
807    /// ignored for `"literal"`.
808    #[serde(default)]
809    pub json_field: Option<String>,
810    /// Default Gleam expression when `json_field` is missing/null. Only
811    /// honoured by the `"string"` strategy today.
812    #[serde(default)]
813    pub default: Option<String>,
814    /// Verbatim Gleam expression to emit when `kind = "literal"`.
815    #[serde(default)]
816    pub value: Option<String>,
817}
818
819#[derive(Debug, Clone, Default, Serialize, Deserialize)]
820pub struct DartConfig {
821    /// Dart pub.dev package name (e.g. `"my_package"`). Used as the `name` in
822    /// `pubspec.yaml`. Defaults to a snake_case derivation of the crate name.
823    #[serde(default)]
824    pub pubspec_name: Option<String>,
825    /// Dart library name (the `library` declaration). Defaults to the pubspec name.
826    #[serde(default)]
827    pub lib_name: Option<String>,
828    /// Dart package name override (e.g. for pub.dev scoped packages).
829    #[serde(default)]
830    pub package_name: Option<String>,
831    /// Bridging style. `"frb"` (default) uses flutter_rust_bridge; `"ffi"` emits
832    /// raw `dart:ffi` source over the cbindgen C library.
833    #[serde(default)]
834    pub style: DartStyle,
835    /// flutter_rust_bridge version to pin in generated pubspec.yaml.
836    /// Defaults to `template_versions::cargo::FLUTTER_RUST_BRIDGE` when unset.
837    #[serde(default)]
838    pub frb_version: Option<String>,
839    /// Cargo features to enable on the binding crate.
840    #[serde(default)]
841    pub features: Option<Vec<String>>,
842    /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
843    #[serde(default)]
844    pub serde_rename_all: Option<String>,
845    /// Per-field name remapping. Key is `TypeName.field_name`, value is the
846    /// desired binding field name. Applied after automatic keyword escaping.
847    #[serde(default)]
848    pub rename_fields: HashMap<String, String>,
849    /// Functions to exclude from Dart binding generation.
850    #[serde(default)]
851    pub exclude_functions: Vec<String>,
852    /// Types to exclude from Dart binding generation.
853    #[serde(default)]
854    pub exclude_types: Vec<String>,
855    /// Prefix wrapper for default tool invocations.
856    #[serde(default)]
857    pub run_wrapper: Option<String>,
858    /// Extra paths to append to default lint commands.
859    #[serde(default)]
860    pub extra_lint_paths: Vec<String>,
861    /// Override the core Cargo dependency name and path for the Dart binding crate.
862    /// When set, the binding `Cargo.toml` depends on this crate (resolved as
863    /// `../../../crates/<override>`) instead of the umbrella `[crate.name]`.
864    /// Defaults to unset.
865    #[serde(default)]
866    pub core_crate_override: Option<String>,
867    /// Keys to subtract from the merged `extra_dependencies` set for this
868    /// language only.
869    #[serde(default)]
870    pub exclude_extra_dependencies: Vec<String>,
871    /// Method names whose Rust bridge body should be emitted as `unimplemented!()`.
872    ///
873    /// Use this when a function's FFI signature (e.g. nested tuples containing
874    /// `Vec<u8>`) cannot be represented across the FRB bridge at all. Consumers must
875    /// list the method names explicitly — this field has no built-in defaults so the
876    /// knob is library-agnostic.
877    ///
878    /// Example (`alef.toml`):
879    /// ```toml
880    /// [crates.dart]
881    /// stub_methods = ["batch_extract_bytes", "batch_extract_bytes_sync"]
882    /// ```
883    #[serde(default)]
884    pub stub_methods: Vec<String>,
885    /// Per-target Cargo dependency overrides for the binding crate.
886    ///
887    /// When set, the emitted `Cargo.toml` wraps the base core dependency in a
888    /// `[target.'cfg(not(<cfg>))'.dependencies]` section and adds a matching
889    /// `[target.'cfg(<cfg>)'.dependencies]` block using `override_features`
890    /// (and `default_features = false` when `override_default_features = false`).
891    /// Required when the binding has to swap the feature set on a specific
892    /// target triple, e.g. Android x86_64 dropping ORT-dependent features.
893    ///
894    /// Example (`alef.toml`):
895    /// ```toml
896    /// [[crates.dart.target_dep_overrides]]
897    /// cfg = "all(target_os = \"android\", target_arch = \"x86_64\")"
898    /// features = ["android-target"]
899    /// default_features = false
900    /// ```
901    #[serde(default)]
902    pub target_dep_overrides: Vec<DartTargetDepOverride>,
903}
904
905#[derive(Debug, Clone, Serialize, Deserialize)]
906pub struct DartTargetDepOverride {
907    /// Cargo `cfg(...)` predicate (without the `cfg(...)` wrapper). Example:
908    /// `all(target_os = "android", target_arch = "x86_64")`.
909    pub cfg: String,
910    /// Features to enable on the core dependency for this target.
911    #[serde(default)]
912    pub features: Vec<String>,
913    /// When false (default), emit `default-features = false` for this target.
914    /// When true, allow the core dep's default features through.
915    #[serde(default)]
916    pub default_features: bool,
917}
918
919#[derive(Debug, Clone, Default, Serialize, Deserialize)]
920pub struct SwiftConfig {
921    /// Swift module name (e.g. `"MyLibrary"`). Defaults to PascalCase of the crate name.
922    #[serde(default)]
923    pub module_name: Option<String>,
924    /// Swift package name. Defaults to the module name.
925    #[serde(default)]
926    pub package_name: Option<String>,
927    /// swift-bridge version. Defaults to `template_versions::cargo::SWIFT_BRIDGE` when unset.
928    #[serde(default)]
929    pub swift_bridge_version: Option<String>,
930    /// Minimum macOS deployment target. Defaults to `template_versions::toolchain::SWIFT_MIN_MACOS` when unset.
931    #[serde(default)]
932    pub min_macos_version: Option<String>,
933    /// Minimum iOS deployment target. Defaults to `template_versions::toolchain::SWIFT_MIN_IOS` when unset.
934    #[serde(default)]
935    pub min_ios_version: Option<String>,
936    /// Cargo features to enable on the binding crate.
937    #[serde(default)]
938    pub features: Option<Vec<String>>,
939    /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
940    #[serde(default)]
941    pub serde_rename_all: Option<String>,
942    /// Per-field name remapping. Key is `TypeName.field_name`, value is the
943    /// desired binding field name. Applied after automatic keyword escaping.
944    #[serde(default)]
945    pub rename_fields: HashMap<String, String>,
946    /// Functions to exclude from Swift binding generation.
947    #[serde(default)]
948    pub exclude_functions: Vec<String>,
949    /// Types to exclude from Swift binding generation.
950    #[serde(default)]
951    pub exclude_types: Vec<String>,
952    /// Fields to exclude from Swift binding generation.
953    /// Format: `"TypeName.field_name"`.
954    #[serde(default)]
955    pub exclude_fields: Vec<String>,
956    /// Prefix wrapper for default tool invocations.
957    #[serde(default)]
958    pub run_wrapper: Option<String>,
959    /// Extra paths to append to default lint commands.
960    #[serde(default)]
961    pub extra_lint_paths: Vec<String>,
962    /// Override the core Cargo dependency name and path for the Swift binding crate.
963    /// When set, the binding `Cargo.toml` depends on this crate (resolved as
964    /// `../../../crates/<override>`) instead of the umbrella `[crate.name]`.
965    /// Defaults to unset.
966    #[serde(default)]
967    pub core_crate_override: Option<String>,
968    /// Keys to subtract from the merged `extra_dependencies` set for this
969    /// language only.
970    #[serde(default)]
971    pub exclude_extra_dependencies: Vec<String>,
972    /// Override the auto-generated `create_<type>(api_key, base_url)` constructor
973    /// body for opaque client types that expose methods. When set, the swift backend
974    /// emits this snippet verbatim as the function body (no implicit `Ok(...)`).
975    ///
976    /// Use this when the source crate's constructor signature differs from the
977    /// default `Type::new(api_key, base_url)` shape — e.g. liter-llm uses
978    /// `DefaultClient::new(ClientConfig, Option<&str>)` and needs to build a
979    /// `ClientConfig` from the bridge inputs first.
980    ///
981    /// The snippet is parameterised by `{type_name}` (the wrapper newtype name)
982    /// and runs in a function body with `api_key: String` and `base_url: Option<String>`
983    /// already in scope. It must return `Result<{type_name}, String>`.
984    #[serde(default)]
985    pub client_constructor_body: HashMap<String, String>,
986}
987
988#[derive(Debug, Clone, Serialize, Deserialize)]
989pub struct ZigConfig {
990    pub module_name: Option<String>,
991    #[serde(default)]
992    pub features: Option<Vec<String>>,
993    /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
994    /// When set, this takes priority over the IR type-level serde_rename_all.
995    #[serde(default)]
996    pub serde_rename_all: Option<String>,
997    /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
998    /// desired binding field name. Applied after automatic keyword escaping.
999    #[serde(default)]
1000    pub rename_fields: HashMap<String, String>,
1001    /// Functions to exclude from Zig binding generation.
1002    #[serde(default)]
1003    pub exclude_functions: Vec<String>,
1004    /// Types to exclude from Zig binding generation.
1005    #[serde(default)]
1006    pub exclude_types: Vec<String>,
1007    /// Prefix wrapper for default tool invocations.
1008    #[serde(default)]
1009    pub run_wrapper: Option<String>,
1010    /// Extra paths to append to default lint commands.
1011    #[serde(default)]
1012    pub extra_lint_paths: Vec<String>,
1013}
1014
1015#[derive(Debug, Clone, Serialize, Deserialize)]
1016pub struct CSharpConfig {
1017    pub namespace: Option<String>,
1018    /// NuGet `<PackageId>` to publish under. When unset, falls back to `namespace`.
1019    /// Use this when the published artifact id must differ from the C# `RootNamespace` —
1020    /// e.g. when the unprefixed name is owned by a third party on nuget.org and
1021    /// you publish under a vendor-prefixed id like `KreuzbergDev.<Lib>`.
1022    #[serde(default)]
1023    pub package_id: Option<String>,
1024    pub target_framework: Option<String>,
1025    #[serde(default)]
1026    pub features: Option<Vec<String>>,
1027    /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
1028    /// When set, this takes priority over the IR type-level serde_rename_all.
1029    #[serde(default)]
1030    pub serde_rename_all: Option<String>,
1031    /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
1032    /// desired binding field name. Applied after automatic keyword escaping.
1033    #[serde(default)]
1034    pub rename_fields: HashMap<String, String>,
1035    /// Prefix wrapper for default tool invocations. When set, prepends this string to default
1036    /// commands across all pipelines (lint, test, build, etc.).
1037    #[serde(default)]
1038    pub run_wrapper: Option<String>,
1039    /// Extra paths to append to default lint commands (format, check, typecheck).
1040    /// Ignored when project_file is set.
1041    #[serde(default)]
1042    pub extra_lint_paths: Vec<String>,
1043    /// Project file for C# (e.g., "MyProject.csproj", "MySolution.sln"). When set, default
1044    /// lint/build/test commands target this file instead of the output directory.
1045    #[serde(default)]
1046    pub project_file: Option<String>,
1047    /// Functions to exclude from C# binding generation (e.g., functions not present in the
1048    /// C FFI layer). Excluded functions are omitted from both NativeMethods.cs and the
1049    /// wrapper class.
1050    #[serde(default)]
1051    pub exclude_functions: Vec<String>,
1052}
1053
1054#[derive(Debug, Clone, Serialize, Deserialize)]
1055pub struct RConfig {
1056    pub package_name: Option<String>,
1057    #[serde(default)]
1058    pub features: Option<Vec<String>>,
1059    /// Override the serde rename_all strategy for JSON field names (e.g. "camelCase", "snake_case").
1060    /// When set, this takes priority over the IR type-level serde_rename_all.
1061    #[serde(default)]
1062    pub serde_rename_all: Option<String>,
1063    /// Per-field name remapping for this language. Key is `TypeName.field_name`, value is the
1064    /// desired binding field name. Applied after automatic keyword escaping.
1065    #[serde(default)]
1066    pub rename_fields: HashMap<String, String>,
1067    /// Prefix wrapper for default tool invocations. When set, prepends this string to default
1068    /// commands across all pipelines (lint, test, build, etc.).
1069    #[serde(default)]
1070    pub run_wrapper: Option<String>,
1071    /// Extra paths to append to default lint commands (format, check, typecheck).
1072    #[serde(default)]
1073    pub extra_lint_paths: Vec<String>,
1074}
1075
1076/// Custom modules that alef should declare (mod X;) but not generate.
1077/// These are hand-written modules imported by the generated lib.rs.
1078#[derive(Debug, Clone, Default, Serialize, Deserialize)]
1079pub struct CustomModulesConfig {
1080    #[serde(default)]
1081    pub python: Vec<String>,
1082    #[serde(default)]
1083    pub node: Vec<String>,
1084    #[serde(default)]
1085    pub ruby: Vec<String>,
1086    #[serde(default)]
1087    pub php: Vec<String>,
1088    #[serde(default)]
1089    pub elixir: Vec<String>,
1090    #[serde(default)]
1091    pub wasm: Vec<String>,
1092    #[serde(default)]
1093    pub ffi: Vec<String>,
1094    #[serde(default)]
1095    pub go: Vec<String>,
1096    #[serde(default)]
1097    pub java: Vec<String>,
1098    #[serde(default)]
1099    pub csharp: Vec<String>,
1100    #[serde(default)]
1101    pub r: Vec<String>,
1102}
1103
1104impl CustomModulesConfig {
1105    pub fn for_language(&self, lang: Language) -> &[String] {
1106        match lang {
1107            Language::Python => &self.python,
1108            Language::Node => &self.node,
1109            Language::Ruby => &self.ruby,
1110            Language::Php => &self.php,
1111            Language::Elixir => &self.elixir,
1112            Language::Wasm => &self.wasm,
1113            Language::Ffi => &self.ffi,
1114            Language::Go => &self.go,
1115            Language::Java => &self.java,
1116            Language::Csharp => &self.csharp,
1117            Language::R => &self.r,
1118            Language::Rust => &[], // Rust doesn't need custom modules (no binding crate)
1119            Language::Kotlin
1120            | Language::KotlinAndroid
1121            | Language::Swift
1122            | Language::Dart
1123            | Language::Gleam
1124            | Language::Zig
1125            | Language::C => &[],
1126        }
1127    }
1128}
1129
1130/// Custom classes/functions from hand-written modules to register in module init.
1131#[derive(Debug, Clone, Default, Serialize, Deserialize)]
1132pub struct CustomRegistration {
1133    #[serde(default)]
1134    pub classes: Vec<String>,
1135    #[serde(default)]
1136    pub functions: Vec<String>,
1137    #[serde(default)]
1138    pub init_calls: Vec<String>,
1139}
1140
1141/// Per-language custom registrations.
1142#[derive(Debug, Clone, Default, Serialize, Deserialize)]
1143pub struct CustomRegistrationsConfig {
1144    #[serde(default)]
1145    pub python: Option<CustomRegistration>,
1146    #[serde(default)]
1147    pub node: Option<CustomRegistration>,
1148    #[serde(default)]
1149    pub ruby: Option<CustomRegistration>,
1150    #[serde(default)]
1151    pub php: Option<CustomRegistration>,
1152    #[serde(default)]
1153    pub elixir: Option<CustomRegistration>,
1154    #[serde(default)]
1155    pub wasm: Option<CustomRegistration>,
1156}
1157
1158impl CustomRegistrationsConfig {
1159    pub fn for_language(&self, lang: Language) -> Option<&CustomRegistration> {
1160        match lang {
1161            Language::Python => self.python.as_ref(),
1162            Language::Node => self.node.as_ref(),
1163            Language::Ruby => self.ruby.as_ref(),
1164            Language::Php => self.php.as_ref(),
1165            Language::Elixir => self.elixir.as_ref(),
1166            Language::Wasm => self.wasm.as_ref(),
1167            _ => None,
1168        }
1169    }
1170}