refactor: rename llm worker crate to engine

This commit is contained in:
2026-06-25 22:46:26 +09:00
parent 22598710fd
commit 292fc4ea5d
202 changed files with 1129 additions and 1125 deletions
+1 -1
View File
@@ -7,7 +7,7 @@
//!
//! Disabled by default. Enable via `SessionConfig::record_event_trace`.
use llm_worker::llm_client::event::Event;
use llm_engine::llm_client::event::Event;
use serde::{Deserialize, Serialize};
use serde_json::Value;
+4 -4
View File
@@ -6,12 +6,12 @@
//! belonging to the same logical conversation. Each Segment is recorded
//! as a sequence of [`LogEntry`] values, one per line in a `.jsonl`
//! file. Reading a segment log and collecting entries reconstructs the
//! Worker state at that segment — no separate snapshots or checkpoints
//! Engine state at that segment — no separate snapshots or checkpoints
//! needed. Compaction and fork operations mint a fresh Segment within
//! the same Session.
//!
//! This crate provides free functions for persistence operations.
//! The caller (typically Pod) holds the Worker directly and calls these
//! The caller (typically Pod) holds the Engine directly and calls these
//! functions after state-mutating operations.
//!
//! Debug-mode [`TraceEntry`] records capture raw stream events in a separate
@@ -40,8 +40,8 @@ pub mod system_item;
pub use event_trace::{TraceEntry, TracePayload};
pub use fs_store::FsStore;
pub use llm_worker::UsageRecord;
pub use llm_worker::llm_client::types::{ContentPart, Item, Role};
pub use llm_engine::UsageRecord;
pub use llm_engine::llm_client::types::{ContentPart, Item, Role};
pub use logged_item::{LoggedContentPart, LoggedItem, LoggedRole, from_logged, to_logged};
pub use segment::{
SegmentStartState, append_entry, append_system_item, classify_history_item,
+2 -2
View File
@@ -1,4 +1,4 @@
//! Persistence-stable mirror of `llm_worker::Item`.
//! Persistence-stable mirror of `llm_engine::Item`.
//!
//! `LogEntry` does not embed `Item` directly because that couples the on-disk
//! schema to the LLM worker's internal type — a field rename or addition there
@@ -12,7 +12,7 @@
//! `Reasoning::encrypted_content` is preserved because OpenAI Responses ZDR
//! requires it on stateless re-send.
use llm_worker::llm_client::types::{ContentPart, Item, Role};
use llm_engine::llm_client::types::{ContentPart, Item, Role};
use serde::{Deserialize, Serialize};
fn is_false(value: &bool) -> bool {
+10 -10
View File
@@ -1,7 +1,7 @@
//! Free functions for segment persistence operations.
//!
//! These functions record and restore segment state without owning a Worker.
//! The caller (typically Pod) holds the Worker directly and calls these
//! These functions record and restore segment state without owning a Engine.
//! The caller (typically Pod) holds the Engine directly and calls these
//! functions after state-mutating operations.
use crate::logged_item::{LoggedItem, to_logged};
@@ -9,9 +9,9 @@ use crate::segment_log::{self, LogEntry, SegmentOrigin};
use crate::store::{Store, StoreError};
use crate::system_item::SystemItem;
use crate::{SegmentId, SessionId};
use llm_worker::WorkerResult;
use llm_worker::llm_client::RequestConfig;
use llm_worker::llm_client::types::Item;
use llm_engine::EngineResult;
use llm_engine::llm_client::RequestConfig;
use llm_engine::llm_client::types::Item;
use protocol::Segment;
/// State snapshot for creating a SegmentStart entry.
@@ -89,7 +89,7 @@ pub fn create_compacted_segment(
/// Restore segment state from a stored log.
///
/// Returns the reconstructed state. The caller is responsible for
/// applying it to a Worker.
/// applying it to a Engine.
pub fn restore(
store: &impl Store,
session_id: SessionId,
@@ -287,12 +287,12 @@ pub fn save_turn_end(
)
}
/// Log a `RunCompleted` entry — `run()` / `resume()` returned `Ok(WorkerResult)`.
/// Log a `RunCompleted` entry — `run()` / `resume()` returned `Ok(EngineResult)`.
pub fn save_run_completed(
store: &impl Store,
session_id: SessionId,
segment_id: SegmentId,
result: WorkerResult,
result: EngineResult,
interrupted: bool,
) -> Result<(), StoreError> {
append_entry(
@@ -307,9 +307,9 @@ pub fn save_run_completed(
)
}
/// Log a `RunErrored` entry — `run()` / `resume()` returned `Err(WorkerError)`.
/// Log a `RunErrored` entry — `run()` / `resume()` returned `Err(EngineError)`.
///
/// `WorkerError` is not `Serialize`, so the caller passes a lossy
/// `EngineError` is not `Serialize`, so the caller passes a lossy
/// `to_string()` rendering as `message`.
pub fn save_run_errored(
store: &impl Store,
+13 -13
View File
@@ -3,14 +3,14 @@
//! Each [`LogEntry`] represents a single state transition within one
//! segment, serialized as one line in a `.jsonl` file. Reading all
//! entries and collecting them via [`collect_state`] reconstructs the
//! full [`Worker`] state at that segment.
//! full [`Engine`] state at that segment.
//!
//! The on-disk format is one `LogEntry` per line — entries are positionally
//! ordered. Fork lineage references between segments use turn-number indices
//! (`SegmentOrigin.at_turn_index`) rather than per-entry hashes.
use llm_worker::llm_client::types::{Item, RequestConfig};
use llm_worker::{UsageRecord, WorkerResult};
use llm_engine::llm_client::types::{Item, RequestConfig};
use llm_engine::{EngineResult, UsageRecord};
use protocol::{InvokeKind, Segment};
use serde::{Deserialize, Serialize};
@@ -19,7 +19,7 @@ use crate::system_item::SystemItem;
/// A single segment log entry, serialized as one JSONL line.
///
/// Variants correspond to specific mutation points in `Worker`:
/// Variants correspond to specific mutation points in `Engine`:
/// - `SegmentStart` — always the first entry; captures initial state
/// - `Invoke` — IDLE → active marker (start of a new self-driving cycle)
/// - `UserInput` / `AssistantItem` / `ToolResult` / `SystemItem` — history appends
@@ -98,16 +98,16 @@ pub enum LogEntry {
/// Turn boundary. Records the turn count after increment.
TurnEnd { ts: u64, turn_count: usize },
/// `run()` / `resume()` が `WorkerResult` で正常終了した。
/// `run()` / `resume()` が `EngineResult` で正常終了した。
/// Audit-only metadata: replay は `interrupted` のみ反映する。
RunCompleted {
ts: u64,
interrupted: bool,
result: WorkerResult,
result: EngineResult,
},
/// `run()` / `resume()` が `WorkerError` で終了した。
/// `WorkerError` は `Serialize` 不可なので `message` のみ lossy 保持する。
/// `run()` / `resume()` が `EngineError` で終了した。
/// `EngineError` は `Serialize` 不可なので `message` のみ lossy 保持する。
/// Audit-only metadata: replay は `interrupted` のみ反映する。
RunErrored {
ts: u64,
@@ -360,7 +360,7 @@ mod tests {
LogEntry::RunCompleted {
ts: 3200,
interrupted: false,
result: WorkerResult::Finished,
result: EngineResult::Finished,
},
]);
assert_eq!(state.history.len(), 2);
@@ -593,7 +593,7 @@ mod tests {
LogEntry::RunCompleted {
ts: 100,
interrupted: true,
result: WorkerResult::Paused,
result: EngineResult::Paused,
},
LogEntry::PausedTurnAbandoned { ts: 200 },
]);
@@ -711,14 +711,14 @@ mod tests {
},
parsed,
]);
// Worker history gets a flattened user_message item.
// Engine history gets a flattened user_message item.
assert_eq!(state.history.len(), 1);
match &state.history[0] {
Item::Message { role, content, .. } => {
assert!(matches!(role, llm_worker::Role::User));
assert!(matches!(role, llm_engine::Role::User));
assert_eq!(content.len(), 1);
match &content[0] {
llm_worker::ContentPart::Text { text } => {
llm_engine::ContentPart::Text { text } => {
assert_eq!(text, "see line1\nline2@src/main.rs");
}
other => panic!("unexpected content: {other:?}"),
+1 -1
View File
@@ -6,7 +6,7 @@
//!
//! Sync (rather than async) is intentional: a segment log append is a single
//! `< 1 KiB` line on local fs and completes well below a millisecond. Going
//! through `tokio::fs` would force every caller — including `Worker`'s sync
//! through `tokio::fs` would force every caller — including `Engine`'s sync
//! `on_history_append` callback — to bridge sync → async via a channel +
//! drain task. Keeping the store sync lets the worker callback, Pod commit
//! paths, and `PodInterceptor` all share one direct `append_entry` call.
+1 -1
View File
@@ -18,7 +18,7 @@
//! preserved only on the log/wire side; the LLM still sees plain
//! system-message text.
use llm_worker::llm_client::types::Item;
use llm_engine::llm_client::types::Item;
use protocol::PodEvent;
use serde::{Deserialize, Serialize};