Skip to main content

kaish_kernel/
lib.rs

1//! kaish-kernel (核): The core of 会sh.
2//!
3//! This crate provides:
4//!
5//! - **Lexer**: Tokenizes kaish source code using logos
6//! - **Parser**: Builds AST from tokens using chumsky
7//! - **AST**: Type definitions for the abstract syntax tree
8//! - **Interpreter**: Expression evaluation, scopes, and the `$?` result type
9//! - **VFS**: Virtual filesystem with mount points
10//! - **Tools**: Tool trait, registry, and builtin commands
11//! - **Scheduler**: Pipeline execution and background job management
12//! - **Paths**: XDG-compliant path helpers
13
14pub mod arithmetic;
15pub mod ast;
16pub mod backend;
17pub(crate) mod backend_walker_fs;
18pub mod dispatch;
19pub mod duration;
20pub mod error;
21pub mod fragment;
22pub mod help;
23pub mod ignore_config;
24pub mod interpreter;
25pub mod output_limit;
26pub mod kernel;
27pub mod lexer;
28pub mod name;
29pub mod operation;
30pub mod parser;
31pub mod paths;
32#[cfg(all(unix, feature = "subprocess"))]
33pub mod pidfd;
34pub mod scheduler;
35#[cfg(feature = "subprocess")]
36pub(crate) mod spawn;
37pub(crate) mod telemetry;
38pub mod tools;
39pub mod trash;
40#[cfg(feature = "os-integration")]
41pub mod trash_system;
42pub mod validator;
43pub mod vfs;
44pub mod watchdog;
45#[cfg(all(unix, feature = "subprocess"))]
46pub mod terminal;
47
48// Re-export kaish_glob as our glob/walker modules for backwards compatibility
49pub use kaish_glob as glob_crate;
50
51/// Glob pattern matching (re-exported from kaish-glob).
52pub mod glob {
53    pub use kaish_glob::glob::{contains_glob, expand_braces, glob_match};
54}
55
56/// Recursive file walking infrastructure (re-exported from kaish-glob).
57pub mod walker {
58    pub use kaish_glob::{
59        build_file_types, list_file_types, EntryTypes, FileTypeError, FileWalker, FilterResult,
60        GlobPath, IgnoreFilter, IncludeExclude, PathSegment, PatternError, WalkOptions,
61        WalkerDirEntry, WalkerError, WalkerFs,
62    };
63    pub use crate::backend_walker_fs::BackendWalkerFs;
64}
65
66pub use backend::{
67    BackendError, BackendResult, KernelBackend, LocalBackend, PatchOp, ReadRange,
68    ToolInfo, ToolResult, VirtualOverlayBackend, WriteMode,
69};
70pub use dispatch::{CommandDispatcher, PipelinePosition};
71pub use error::KernelError;
72pub use ignore_config::{IgnoreConfig, IgnoreScope};
73pub use kernel::{
74    CommandKind, ExecuteOptions, Kernel, KernelConfig, VfsMountMode, MAX_RECURSION_DEPTH,
75    RECOMMENDED_STACK_SIZE,
76};
77pub use output_limit::OutputLimitConfig;
78
79// ═══════════════════════════════════════════════════════════════════════════
80// Embedding Conveniences
81// ═══════════════════════════════════════════════════════════════════════════
82
83// Backend with /v/* support for embedders
84//
85// Use `Kernel::with_backend()` to provide a custom backend with automatic
86// `/v/*` path support (job observability, blob storage):
87//
88// ```ignore
89// let kernel = Kernel::with_backend(my_backend, config, |vfs| {
90//     vfs.mount_arc("/v/docs", docs_fs);
91// }, |_| {})?;
92// ```
93
94// Job observability (for embedders capturing command output)
95pub use scheduler::{BoundedStream, StreamStats, DEFAULT_STREAM_MAX_SIZE, drain_to_stream};
96// Streaming stdin seam: a frontend (REPL `-c`/script) hands the kernel a lazy
97// `PipeReader` via `Kernel::execute_with_pipe_stdin`, so a command that never
98// reads stdin never blocks on an open pipe. See `execute_pipe_stdin_tests`.
99pub use scheduler::{pipe_stream, pipe_stream_default, PipeReader, PipeWriter, PIPE_BUFFER_SIZE};
100pub use vfs::JobFs;
101
102// XDG path primitives (embedders compose their own paths)
103pub use paths::{home_dir, xdg_cache_home, xdg_config_home, xdg_data_home, xdg_runtime_dir};
104
105// Tilde expansion utility
106pub use interpreter::expand_tilde;
107
108// Tool registration (for embedders registering custom tools)
109pub use tools::{Tool, ToolRegistry, ExecContext};
110
111// Statement metadata without execution (embedders compose their own
112// approval machinery over it — see docs/EMBEDDING.md)
113pub use ast::plan::{
114    plan_program, PlannedStatement, KAISH_BUILD_DATE, KAISH_GIT_HASH, KAISH_VERSION,
115};
116pub use fragment::{expand_fragment, FragmentError};
117pub use kaish_types::plan::{Expansion, FragmentAddr, Hole, PlannedHeredoc};