Class: RosettAi::Workflow::AuditLog

Inherits:
Object
  • Object
show all
Defined in:
lib/rosett_ai/workflow/audit_log.rb

Overview

Structured audit log for workflow execution.

Records each step execution with timestamp, status, and duration. Supports resume by identifying completed steps from the log.

Author:

  • hugo

  • claude

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(log_path: nil) ⇒ AuditLog

Returns a new instance of AuditLog.

Parameters:

  • log_path (Pathname, nil) (defaults to: nil)

    path to audit log file



21
22
23
24
# File 'lib/rosett_ai/workflow/audit_log.rb', line 21

def initialize(log_path: nil)
  @log_path = log_path
  @entries = load_entries
end

Instance Attribute Details

#entriesObject (readonly)

Returns the value of attribute entries.



18
19
20
# File 'lib/rosett_ai/workflow/audit_log.rb', line 18

def entries
  @entries
end

Instance Method Details

#completed_steps(workflow_name) ⇒ Array<String>

Returns step names that completed successfully for a workflow.

Parameters:

  • workflow_name (String)

Returns:

  • (Array<String>)

    completed step names



50
51
52
53
54
# File 'lib/rosett_ai/workflow/audit_log.rb', line 50

def completed_steps(workflow_name)
  @entries
    .select { |e| e['workflow'] == workflow_name && e['status'] == 'pass' }
    .map { |e| e['step'] }
end

#record(workflow_name:, step_name:, status:, duration_ms: 0.0, details: nil) ⇒ Object

Records a step execution result.

Parameters:

  • workflow_name (String)
  • step_name (String)
  • status (String)

    'pass', 'fail', or 'skip'

  • duration_ms (Float) (defaults to: 0.0)
  • details (String, nil) (defaults to: nil)


33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rosett_ai/workflow/audit_log.rb', line 33

def record(workflow_name:, step_name:, status:, duration_ms: 0.0, details: nil)
  entry = {
    'workflow' => workflow_name,
    'step' => step_name,
    'status' => status,
    'timestamp' => Time.now.utc.iso8601,
    'duration_ms' => duration_ms.round(1)
  }
  entry['details'] = details if details
  @entries << entry
  persist_entry(entry)
end

#to_hHash

Returns serializable summary.

Returns:

  • (Hash)

    serializable summary



57
58
59
60
61
62
63
64
# File 'lib/rosett_ai/workflow/audit_log.rb', line 57

def to_h
  {
    'entries' => @entries,
    'total' => @entries.size,
    'pass' => @entries.count { |e| e['status'] == 'pass' },
    'fail' => @entries.count { |e| e['status'] == 'fail' }
  }
end