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 help;
21pub mod ignore_config;
22pub mod interpreter;
23pub mod output_limit;
24pub mod kernel;
25pub mod lexer;
26pub mod operation;
27pub mod parser;
28pub mod paths;
29#[cfg(all(unix, feature = "subprocess"))]
30pub mod pidfd;
31pub mod scheduler;
32pub(crate) mod telemetry;
33pub mod tools;
34pub mod trash;
35#[cfg(feature = "os-integration")]
36pub mod trash_system;
37pub mod validator;
38pub mod vfs;
39pub mod watchdog;
40#[cfg(all(unix, feature = "subprocess"))]
41pub mod terminal;
42
43// Re-export kaish_glob as our glob/walker modules for backwards compatibility
44pub use kaish_glob as glob_crate;
45
46/// Glob pattern matching (re-exported from kaish-glob).
47pub mod glob {
48    pub use kaish_glob::glob::{contains_glob, expand_braces, glob_match};
49}
50
51/// Recursive file walking infrastructure (re-exported from kaish-glob).
52pub mod walker {
53    pub use kaish_glob::{
54        build_file_types, list_file_types, EntryTypes, FileTypeError, FileWalker, FilterResult,
55        GlobPath, IgnoreFilter, IncludeExclude, PathSegment, PatternError, WalkOptions,
56        WalkerDirEntry, WalkerError, WalkerFs,
57    };
58    pub use crate::backend_walker_fs::BackendWalkerFs;
59}
60
61pub use backend::{
62    BackendError, BackendResult, KernelBackend, LocalBackend, PatchOp, ReadRange,
63    ToolInfo, ToolResult, VirtualOverlayBackend, WriteMode,
64};
65pub use dispatch::{CommandDispatcher, PipelinePosition};
66pub use ignore_config::{IgnoreConfig, IgnoreScope};
67pub use kernel::{
68    CommandKind, ExecuteOptions, Kernel, KernelConfig, VfsMountMode, MAX_RECURSION_DEPTH,
69    RECOMMENDED_STACK_SIZE,
70};
71pub use output_limit::OutputLimitConfig;
72
73// ═══════════════════════════════════════════════════════════════════════════
74// Embedding Conveniences
75// ═══════════════════════════════════════════════════════════════════════════
76
77// Backend with /v/* support for embedders
78//
79// Use `Kernel::with_backend()` to provide a custom backend with automatic
80// `/v/*` path support (job observability, blob storage):
81//
82// ```ignore
83// let kernel = Kernel::with_backend(my_backend, config, |vfs| {
84//     vfs.mount_arc("/v/docs", docs_fs);
85// }, |_| {})?;
86// ```
87
88// Job observability (for embedders capturing command output)
89pub use scheduler::{BoundedStream, StreamStats, DEFAULT_STREAM_MAX_SIZE, drain_to_stream};
90// Streaming stdin seam: a frontend (REPL `-c`/script) hands the kernel a lazy
91// `PipeReader` via `Kernel::execute_with_pipe_stdin`, so a command that never
92// reads stdin never blocks on an open pipe. See `execute_pipe_stdin_tests`.
93pub use scheduler::{pipe_stream, pipe_stream_default, PipeReader, PipeWriter, PIPE_BUFFER_SIZE};
94pub use vfs::JobFs;
95
96// XDG path primitives (embedders compose their own paths)
97pub use paths::{home_dir, xdg_cache_home, xdg_config_home, xdg_data_home, xdg_runtime_dir};
98
99// Tilde expansion utility
100pub use interpreter::expand_tilde;
101
102// Tool registration (for embedders registering custom tools)
103pub use tools::{Tool, ToolRegistry, ExecContext};
104
105// Statement metadata without execution (embedders compose their own
106// approval machinery over it — see docs/EMBEDDING.md)
107pub use ast::plan::{plan_program, PlannedStatement};