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