//! LOG.md: the one-screen history Koh keeps at the repo root for people (and //! agents) who want the last few saves without running a command. module history import os import time import src.storage const log_marker = '' const log_shown = 20 pub fn write_log_md(store &storage.Store, root string) ! { path := os.join_path(root, 'LOG.md') if os.is_file(path) { existing := os.read_file(path)! if !existing.starts_with(log_marker) { // Someone else's log file; leave it alone. return } } saves := line(store)! shown := if saves.len < log_shown { saves.len } else { log_shown } mut text := '${log_marker}\n\n# Koh Log\n\n' for save in saves[..shown] { text += '✦ [${save.id}] ${save.message} · ${clock(save.created_at)}\n' } if saves.len > shown { text += '\n… ${saves.len - shown} older saves\n' } text += '\n*full history: koh log*\n' os.write_file(path, text)! } fn clock(unix_seconds i64) string { return time.unix(unix_seconds).local().format_ss() }