| 1 | package eventwire |
| 2 | |
| 3 | import "reasonix/internal/event" |
| 4 | |
| 5 | // Approval is the JSON form of an event.Approval. |
| 6 | type Approval struct { |
| 7 | ID string `json:"id"` |
| 8 | Tool string `json:"tool"` |
| 9 | Subject string `json:"subject" externalizable:"true"` |
| 10 | Reason string `json:"reason,omitempty" externalizable:"true"` |
| 11 | Fresh bool `json:"fresh,omitempty"` |
| 12 | Kind string `json:"kind,omitempty"` // tool | plan | recovery | write_access |
| 13 | Recovery *RecoveryApproval `json:"recovery,omitempty"` |
| 14 | WriteAccess *WriteAccessApproval `json:"write_access,omitempty"` |
| 15 | TurnID string `json:"turnId,omitempty"` |
| 16 | Generation uint64 `json:"generation,omitempty"` |
| 17 | PermissionRevision uint64 `json:"permissionRevision,omitempty"` |
| 18 | } |
| 19 | |
| 20 | type WriteAccessApproval struct { |
| 21 | Directories []string `json:"directories"` |
| 22 | DisplayDirectories []string `json:"display_directories"` |
| 23 | Justification string `json:"justification,omitempty"` |
| 24 | BroadHomeAccess bool `json:"broad_home_access,omitempty"` |
| 25 | OrdinaryPermissionNeeded bool `json:"ordinary_permission_needed,omitempty"` |
| 26 | PersistAllowed bool `json:"persist_allowed,omitempty"` |
| 27 | } |
| 28 | |
| 29 | type RecoveryApproval struct { |
| 30 | SourceAgent string `json:"source_agent,omitempty"` |
| 31 | FailedTool string `json:"failed_tool,omitempty"` |
| 32 | FailedSummary string `json:"failed_summary,omitempty"` |
| 33 | Diagnosis string `json:"diagnosis,omitempty"` |
| 34 | NextTool string `json:"next_tool,omitempty"` |
| 35 | NextAction string `json:"next_action,omitempty"` |
| 36 | ChangeKind string `json:"change_kind,omitempty"` |
| 37 | ChangeRationale string `json:"change_rationale,omitempty"` |
| 38 | ReviewRationale string `json:"review_rationale,omitempty"` |
| 39 | PlanBefore string `json:"plan_before,omitempty"` |
| 40 | PlanAfter string `json:"plan_after,omitempty"` |
| 41 | CanGrantTask bool `json:"can_grant_task,omitempty"` |
| 42 | TaskGrantScope string `json:"task_grant_scope,omitempty"` |
| 43 | } |
| 44 | |
| 45 | func toWireApproval(a event.Approval) *Approval { |
| 46 | w := &Approval{ID: a.ID, Tool: a.Tool, Subject: a.Subject, Reason: a.Reason, Fresh: a.Fresh, Kind: a.Kind, TurnID: a.TurnID, Generation: a.Generation, PermissionRevision: a.PermissionRevision} |
| 47 | if wa := event.NormalizeWriteAccessApproval(a.WriteAccess); wa != nil { |
| 48 | w.WriteAccess = &WriteAccessApproval{ |
| 49 | Directories: append([]string{}, wa.Directories...), DisplayDirectories: append([]string{}, wa.DisplayDirectories...), |
| 50 | Justification: wa.Justification, BroadHomeAccess: wa.BroadHomeAccess, |
| 51 | OrdinaryPermissionNeeded: wa.OrdinaryPermissionNeeded, PersistAllowed: wa.PersistAllowed, |
| 52 | } |
| 53 | } |
| 54 | if r := a.Recovery; r != nil { |
| 55 | w.Recovery = &RecoveryApproval{ |
| 56 | SourceAgent: r.SourceAgent, FailedTool: r.FailedTool, FailedSummary: r.FailedSummary, Diagnosis: r.Diagnosis, |
| 57 | NextTool: r.NextTool, NextAction: r.NextAction, ChangeKind: r.ChangeKind, ChangeRationale: r.ChangeRationale, |
| 58 | ReviewRationale: r.ReviewRationale, PlanBefore: r.PlanBefore, PlanAfter: r.PlanAfter, |
| 59 | CanGrantTask: r.CanGrantTask, TaskGrantScope: r.TaskGrantScope, |
| 60 | } |
| 61 | } |
| 62 | return w |
| 63 | } |
| 64 |