システムプロンプトの実装

This commit is contained in:
2026-04-15 02:44:42 +09:00
parent 309dba7203
commit 66c6edec3e
12 changed files with 977 additions and 42 deletions
+3 -3
View File
@@ -35,9 +35,9 @@ pub mod store;
pub use event_trace::TraceEntry;
pub use fs_store::FsStore;
pub use session::{
SessionStartState, create_compacted_session, create_session, ensure_head_or_fork, fork,
fork_at, restore, save_cache_locked, save_cache_unlocked, save_config_changed, save_delta,
save_outcome, save_turn_end, save_usage,
SessionStartState, create_compacted_session, create_session, create_session_with_id,
ensure_head_or_fork, fork, fork_at, restore, save_cache_locked, save_cache_unlocked,
save_config_changed, save_delta, save_outcome, save_turn_end, save_usage,
};
pub use session_log::{
EntryHash, HashedEntry, LogEntry, Outcome, RestoredState, SessionOrigin, UsageRecord,
+15 -1
View File
@@ -25,6 +25,20 @@ pub async fn create_session(
state: SessionStartState<'_>,
) -> Result<(SessionId, EntryHash), StoreError> {
let session_id = crate::new_session_id();
let hash = create_session_with_id(store, session_id, state).await?;
Ok((session_id, hash))
}
/// Write a fresh `SessionStart` entry using a pre-generated session ID.
///
/// Used by callers that need to reserve a session ID synchronously but
/// defer the initial log append (e.g. Pod, which resolves a templated
/// system prompt only at first turn). Returns the resulting head hash.
pub async fn create_session_with_id(
store: &impl Store,
session_id: SessionId,
state: SessionStartState<'_>,
) -> Result<EntryHash, StoreError> {
let entry = LogEntry::SessionStart {
ts: session_log::now_millis(),
system_prompt: state.system_prompt.map(String::from),
@@ -40,7 +54,7 @@ pub async fn create_session(
entry,
};
store.append(session_id, &hashed_entry).await?;
Ok((session_id, hash))
Ok(hash)
}
/// Create a compacted session from an existing one.