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