1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//! Koda Core — the engine library for the Koda AI coding agent.
//!
//! This crate contains the pure engine logic with zero terminal dependencies.
//! It communicates exclusively through `EngineEvent` (output) and
//! `EngineCommand` (input) enums.
//!
//! See `DESIGN.md` in the repository root for the full architectural rationale.
/// Sub-agent configuration, discovery, and invocation.
/// Tool approval modes, safety gates, and shared mode state.
/// Heuristic path-escape detection for bash commands.
/// Bash command safety classification (destructive, mutating, read-only).
/// Context compaction — summarise old messages to reclaim token budget.
/// Global configuration: provider, model, model settings, CLI flags.
/// Context window management and token budgeting.
/// SQLite persistence layer — sessions, messages, usage tracking.
/// Engine protocol: `EngineEvent` / `EngineCommand` enums.
/// File lifecycle tracker — tracks files created by Koda per session (#465).
/// Git helpers — status, diff, blame, log.
/// The main inference loop — send messages, stream responses, dispatch tools.
/// Shared helpers used by the inference loop.
/// Credential storage (OS keychain via `keyring`).
/// Guardrail against runaway tool-call loops.
/// Project memory — `MEMORY.md` / `CLAUDE.md` read/write.
/// Hardcoded context-window lookup table (fallback when API doesn't report).
/// Context-scaled output caps for tool results.
/// `Persistence` trait — the database contract.
/// Diff preview generation for file mutations.
/// Progress reporting helpers for long operations.
/// System prompt construction.
/// LLM provider abstraction — Anthropic, Gemini, OpenAI-compatible.
/// Environment variable access (mockable for tests).
/// Session lifecycle — create, resume, list, delete.
/// User settings persistence (`~/.config/koda/settings.json`).
/// Skill discovery and activation (project, user, built-in).
/// Cache for sub-agent provider/model config across invocations.
/// Tool dispatch — routes tool calls from inference to the registry.
/// Tool registry, definitions, execution, and path safety.
/// Token-safe output truncation.
/// Undo stack for file mutations.
/// Version string and update-check helpers.