Overview
Concrete tool for writing and querying platform audit logs provided by the internal/database and internal/audit packages.
Description
The AuditLog struct captures a platform operation: level, category, action, result, actor, session hint, client IP, user agent, resource type/ID, message, and detail map. SaveAuditLog writes a row; ListAuditLogs with a ListAuditLogsFilter (actor/level/category/action/result/resource/related user/time window/limit/offset) builds a parameterized WHERE clause and returns paginated rows. The audit.Service wires audit hooks (e.g. RegisterConversationCreateHook) so implicit events (conversation creation) are audited automatically. HITL interrupt logs have their own retention helpers (PurgeHitlInterruptLogsBefore, DeleteHitlInterruptLogsByIDs).
Usage
- Deployment step 6 / HITL step 5: audit events are written for tool executions, HITL decisions, and conversation lifecycle.
- Multi-agent step 6 (engagement review):
ListAuditLogs reconstructs what happened.
Code Reference
Source Location
- Repository: CyberStrikeAI
- File: internal/database/audit.go
- Lines: AuditLog L11-27, ListAuditLogsFilter L30-44, buildAuditLogsWhere L46+; HITL logs internal/database/hitl_logs.go L12-75; audit service internal/audit/, hooks wired internal/app/app.go L126-129
Signature
type AuditLog struct {
ID, Level, Category, Action, Result, Actor string
SessionHint, ClientIP, UserAgent string
ResourceType, ResourceID string
Message string
Detail map[string]interface{}
CreatedAt time.Time
}
type ListAuditLogsFilter struct {
Actor, Level, Category, Action, Result string
ResourceType, ResourceID, RelatedUserID string
Since, Until *time.Time
Limit, Offset int
}
func (db *DB) SaveAuditLog(log *AuditLog) error
func (db *DB) ListAuditLogs(filter ListAuditLogsFilter) ([]*AuditLog, error)
// HITL log retention
func (db *DB) DeleteHitlInterruptLogsByIDs(ids []string) error
func (db *DB) PurgeHitlInterruptLogsBefore(cutoff time.Time) error
Import
import "cyberstrike-ai/internal/database"
import "cyberstrike-ai/internal/audit"
I/O Contract
Inputs
| Name |
Type |
Required |
Description
|
| log |
*AuditLog |
Yes (Save) |
Audit event
|
| filter |
ListAuditLogsFilter |
Yes (List) |
Query filter + pagination
|
Outputs
| Name |
Type |
Description
|
| Save returns |
error |
Nil on success
|
| List returns |
[]*AuditLog, error |
Paginated audit rows
|
Usage Examples
Write and Query an Audit Event
db.SaveAuditLog(&database.AuditLog{
Category: "hitl", Action: "approve", Result: "success",
Actor: "operator-1", ResourceType: "tool", ResourceID: "webshell_exec",
Message: "approved webshell exec on conn-123",
})
logs, _ := db.ListAuditLogs(database.ListAuditLogsFilter{
Category: "hitl", Actor: "operator-1", Limit: 50,
})
Related Pages
Implements Principle
Requires Environment