kaish_kernel/tools/mod.rs
1//! Tool system for kaish.
2//!
3//! Tools are the primary way to perform actions in kaish. Every command
4//! is a tool — builtins and user-defined tools all implement
5//! the same `Tool` trait.
6//!
7//! # Architecture
8//!
9//! ```text
10//! ToolRegistry
11//! ├── Builtins (echo, ls, cat, ...)
12//! └── User Tools (defined via `tool` statements)
13//! ```
14
15mod builtin;
16mod clap_schema;
17mod context;
18mod global_flags;
19mod registry;
20mod traits;
21
22pub use builtin::register_builtins;
23#[cfg(feature = "subprocess")]
24pub use builtin::{resolve_in_path, virtual_cwd_error};
25pub use clap_schema::{params_from_clap, schema_from_clap, schema_tree_from_clap};
26pub use context::{
27 external_commands_unavailable_error, ExecContext, ExternalCommandsUnavailable,
28 GateExpectations, OutputContext, OverwriteExpectation,
29};
30pub(crate) use context::{cas_overwrite, is_trash_excluded, ExternalCommandOutcome};
31pub use global_flags::GlobalFlags;
32pub use registry::ToolRegistry;
33pub use traits::{ArgBinding, global_flag_value_is_truthy, is_global_output_flag, validate_against_schema, Tool, ToolArgs, ToolCtx, ToolSchema, ParamSchema};
34
35/// Commands that consume bareword `key=value` argv (Arg::WordAssign) as
36/// shell-assignment pairs and route them through `tool_args.named`. For every
37/// other command, `key=value` lands as a positional `"key=value"` string —
38/// matching bash (`cat foo=bar` opens a file named `foo=bar`).
39///
40/// Add to this list only for builtins that have a documented shell-assignment
41/// argv contract (`export FOO=bar`, `alias greet='echo hi'`). Long-flag
42/// `--key=value` is a separate AST node (`Arg::Named`) and routes through
43/// `tool_args.named` regardless — except past `--`, where both spellings
44/// become literal positionals.
45pub const WORD_ASSIGN_BUILTINS: &[&str] = &["export", "alias", "unalias"];
46
47pub fn accepts_word_assign(name: &str) -> bool {
48 WORD_ASSIGN_BUILTINS.contains(&name)
49}