From 2b0cb39746315919d062993463151642ab1e95f7 Mon Sep 17 00:00:00 2001 From: AI Bot Date: Sat, 18 Apr 2026 13:44:48 +0200 Subject: [PATCH] Update operation logging spec to use single timestamp per tool call --- .../design.md | 44 +++++-------------- .../2026-04-17-add-operation-logging/tasks.md | 14 +++--- 2 files changed, 17 insertions(+), 41 deletions(-) diff --git a/openspec/changes/archive/2026-04-17-add-operation-logging/design.md b/openspec/changes/archive/2026-04-17-add-operation-logging/design.md index 98801a8..40717d0 100644 --- a/openspec/changes/archive/2026-04-17-add-operation-logging/design.md +++ b/openspec/changes/archive/2026-04-17-add-operation-logging/design.md @@ -19,47 +19,27 @@ | Pattern | Functions | How | |---------|------------|-----| -| Streaming | MarkAllAsDeps, MarkAsExplicit, InstallAUR | `io.MultiWriter` to tee to both terminal and log | -| Captured | SyncPackages, CleanupOrphans | capture with `CombinedOutput()`, write to log, write to terminal | +| Captured | All state-modifying functions | capture output, write to log with single timestamp at start, write to terminal | + +### One Timestamp Per Tool Call +Instead of streaming with MultiWriter (multiple timestamps), each state-modifying function: +1. Writes timestamp + operation name to log +2. Runs command, captures output +3. Writes captured output to log +4. Writes output to terminal + +This ensures exactly 1 timestamp print per tool call. ### Error Handling - Write error to log BEFORE returning from function - Print error to stderr so user sees it ### Dependencies -- Add to imports: `io`, `os`, `path/filepath` - -### Structure - -```go -// pkg/state/state.go -var logFile *os.File - -func OpenLog() error { - logPath := filepath.Join("/var/log", "declpac.log") - f, err := os.OpenFile(logPath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) - if err != nil { - return err - } - logFile = f - return nil -} - -func GetLogWriter() io.Writer { - return logFile -} - -func Close() error { - if logFile == nil { - return nil - } - return logFile.Close() -} -``` +- Add to imports: `os`, `path/filepath` ### Flow in Sync() or main entrypoint 1. Call `OpenLog()` at program start, defer close -2. Each state-modifying function uses `state.GetLogWriter()` via MultiWriter +2. Each state-modifying function calls `state.Write()` with timestamp prefix ### Wire into main.go - Open log at start of `run()` diff --git a/openspec/changes/archive/2026-04-17-add-operation-logging/tasks.md b/openspec/changes/archive/2026-04-17-add-operation-logging/tasks.md index ed98aad..c953f9d 100644 --- a/openspec/changes/archive/2026-04-17-add-operation-logging/tasks.md +++ b/openspec/changes/archive/2026-04-17-add-operation-logging/tasks.md @@ -18,15 +18,11 @@ In `cmd/declpac/main.go` `run()`: Modify `pkg/pacman/pacman.go`: -All state-modifying functions use `state.Write()` instead of `state.GetLogWriter().Write()`: - -``` -// OLD -state.GetLogWriter().Write(output) - -// NEW -state.Write(output) // auto-prepends timestamp -``` +Each state-modifying function writes timestamp ONCE at start, then captures output: +- Write `timestamp - operation name` to log +- Run command, capture output +- Write captured output to log +- Write output to terminal **Functions updated:** - `SyncPackages()` - write output with timestamp