Documentation
¶
Index ¶
- Constants
- Variables
- func DBPathFor(configPath string) string
- func DefaultDBPath() string
- func SortBySendPriority[T any](items []T, lastSent func(T) time.Time)
- type ActionItems
- type AutomationAttempt
- type BatchApproval
- type BrokerResponse
- type BrokerStatus
- type FormWithStatus
- type NoDataClassifier
- type PendingTask
- type PipelineStatus
- type Record
- type ResponseQuery
- type Status
- type Store
- func (s *Store) Add(record *Record) error
- func (s *Store) AddBrokerResponse(resp *BrokerResponse) error
- func (s *Store) AddBrokerResponseIfNew(resp *BrokerResponse) (inserted bool, err error)
- func (s *Store) AddPendingTask(task *PendingTask) error
- func (s *Store) ApproveBatch(planID, approver string) error
- func (s *Store) ClaimAutomationAction(profileID, key, subject string) error
- func (s *Store) ClearBrokerResponses() error
- func (s *Store) Close() error
- func (s *Store) CompletePendingTask(id int64, profileID string, status string) error
- func (s *Store) ConsumeBatchApproval(planID, digest string) error
- func (s *Store) CountSentSince(profileID string, since time.Time) (int, error)
- func (s *Store) CreateBatchApproval(a BatchApproval) error
- func (s *Store) DeleteAllHistory(profileID string) (int64, error)
- func (s *Store) DeleteByStatus(profileID string, status Status) (int64, error)
- func (s *Store) EnsureAutomationTask(profileID, brokerID, brokerName string, kind TaskType, rawURL, actor string) (*PendingTask, error)
- func (s *Store) FindBrokerResponseBySubject(profileID, brokerID, subject string) (*BrokerResponse, error)
- func (s *Store) FinishAutomationAction(profileID, key, state, note string) error
- func (s *Store) GetActionItems(profileID string) (ActionItems, error)
- func (s *Store) GetAllBrokerResponses() ([]BrokerResponse, error)
- func (s *Store) GetAllBrokerStatuses(profileID string) (map[string]BrokerStatus, error)
- func (s *Store) GetAllRequests(profileID string) ([]Record, error)
- func (s *Store) GetAutomationAttempts(profileID, subject string) ([]AutomationAttempt, error)
- func (s *Store) GetBrokerResponseByID(id int64, profileID string) (*BrokerResponse, error)
- func (s *Store) GetBrokerResponses(profileID, responseType string, needsReview bool, limit int) ([]BrokerResponse, error)
- func (s *Store) GetBrokerResponsesForExport(profileID string) ([]BrokerResponse, error)
- func (s *Store) GetBrokerStatus(profileID, brokerID string) (BrokerStatus, error)
- func (s *Store) GetFormStats(profileID string) (pending, filled, captcha, failed, skipped int, err error)
- func (s *Store) GetFormsWithStatus(profileID string) ([]FormWithStatus, error)
- func (s *Store) GetMonthlyStats(profileID string) (sent, failed int, err error)
- func (s *Store) GetPendingTaskByID(id int64, profileID string) (*PendingTask, error)
- func (s *Store) GetPendingTaskStats(profileID string) (pending, completed, skipped int, err error)
- func (s *Store) GetPendingTasks(profileID string, taskType TaskType, status string) ([]PendingTask, error)
- func (s *Store) GetPipelineStats(profileID string) (map[PipelineStatus]int, error)
- func (s *Store) GetRecentRequests(profileID string, limit int) ([]Record, error)
- func (s *Store) GetResponseStats(profileID string) (map[string]int, error)
- func (s *Store) GetStats(profileID string) (total, sent, failed int, err error)
- func (s *Store) LastSuccessfulSendTimes(profileID string) (map[string]time.Time, error)
- func (s *Store) LatestRequests(profileID string) ([]Record, error)
- func (s *Store) MarkBrokerResponseReviewed(id int64, profileID string) error
- func (s *Store) MarkFailed(profileID, brokerID, note string) (int64, error)
- func (s *Store) MarkTaskOpened(id int64, profileID string) error
- func (s *Store) MatchingResponseIDs(profileID, search string) (map[int64]bool, error)
- func (s *Store) MigrateNoData(classify NoDataClassifier) error
- func (s *Store) OverridePipelineStatus(profileID, brokerID string, status PipelineStatus) error
- func (s *Store) PendingBatchApprovals() ([]BatchApproval, error)
- func (s *Store) QueryBrokerResponses(profileID string, q ResponseQuery) ([]BrokerResponse, int, error)
- func (s *Store) ResolveNoData(profileID, brokerID string, reclassified bool) error
- func (s *Store) ResolveProfileForBroker(brokerID string) (string, error)
- func (s *Store) RetryAutomationAction(profileID, key string) error
- func (s *Store) UpdateAutomationTask(profileID string, id int64, actor, reviewReason, note, screenshot string, ...) error
- func (s *Store) UpdateBrokerResponseBody(id int64, profileID string, body string) error
- func (s *Store) UpdateBrokerResponseClassification(id int64, profileID string, responseType string, formURL, confirmURL string, ...) error
- func (s *Store) UpdatePipelineStatus(profileID, brokerID string, status PipelineStatus) error
- func (s *Store) UpdatePipelineStatusBy(profileID, brokerID string, status PipelineStatus, actor string) error
- type TaskType
Constants ¶
const DefaultProfileID = "default"
DefaultProfileID mirrors config.DefaultProfileID (importing config would cycle). Pre-multi-profile rows are migrated to it.
const ResendCooldown = 25 * 24 * time.Hour
ResendCooldown: long enough that resuming a backlog across the daily cap skips yesterday's brokers, short enough for the monthly re-run.
Variables ¶
var ErrNoPendingApproval = errors.New("no pending approval for this batch")
ErrNoPendingApproval: unknown, expired, already approved or already spent.
Functions ¶
func DBPathFor ¶
DBPathFor returns history.db next to configPath, so an alternate --config gets isolated data. DefaultDBPath() when configPath is empty.
func DefaultDBPath ¶
func DefaultDBPath() string
func SortBySendPriority ¶ added in v0.8.5
SortBySendPriority orders items never-sent first, then by oldest last send, keeping the original order among ties. Senders truncate to the daily cap after this, so runs spaced a cooldown or more apart still reach the tail of the list instead of re-sending its head every time.
Types ¶
type ActionItems ¶ added in v1.3.0
type ActionItems struct {
Forms []FormWithStatus
Tasks []PendingTask
Reviews []BrokerResponse
}
ActionItems feeds the action rows and counters on both web pages. A form that has a task shows once; reviews stand alone and aren't limited to type "unknown".
func (ActionItems) FormsToFill ¶ added in v1.3.0
func (a ActionItems) FormsToFill() int
func (ActionItems) NeedsReview ¶ added in v1.3.0
func (a ActionItems) NeedsReview() int
func (ActionItems) Total ¶ added in v1.3.0
func (a ActionItems) Total() int
type AutomationAttempt ¶ added in v1.3.0
type AutomationAttempt struct {
Key string `json:"key"`
Subject string `json:"subject"`
State string `json:"state"`
Note string `json:"note"`
}
AutomationAttempt is logged before the action reaches a broker; an interrupted one needs review, never a blind replay.
type BatchApproval ¶ added in v1.3.0
type BatchApproval struct {
PlanID string
ProfileID string
Digest string
Preview string
ExpiresAt time.Time
}
BatchApproval is an MCP batch preview waiting for a person. It's stored so the approver sees what the digest covers.
type BrokerResponse ¶
type BrokerResponse struct {
ID int64
ProfileID string
BrokerID string
BrokerName string
ResponseType string // form_required, confirmation_required, success, no_data_held, rejected, pending, bounced, unknown
EmailFrom string
EmailSubject string
EmailBody string // Stored for reclassification
FormURL string // Extracted form URL (if any)
ConfirmURL string // Extracted confirmation URL (if any)
Confidence float64
NeedsReview bool
ReceivedAt time.Time
ProcessedAt time.Time
CreatedAt time.Time
}
BrokerResponse stores a classified response from a broker
type BrokerStatus ¶
type FormWithStatus ¶
type FormWithStatus struct {
ResponseID int64
BrokerID string
BrokerName string
FormURL string
EmailSubject string
DetectedAt time.Time
Status string // pending, filled, captcha, failed, skipped
TaskID int64 // If there's a pending task
PipelineStatus PipelineStatus
}
FormWithStatus represents a form detected from email with its current fill status
type NoDataClassifier ¶ added in v1.3.0
type NoDataClassifier func(BrokerResponse) (bool, float64, bool)
NoDataClassifier keeps database migrations independent of the inbox package. It returns whether the saved reply says no data, its confidence, and whether that conclusion still needs a person's review.
type PendingTask ¶
type PendingTask struct {
ID int64
ProfileID string
BrokerID string
BrokerName string
TaskType TaskType
FormURL string
ScreenshotPath string
BrowserState string // JSON serialized browser state (profile data for helper page)
Notes string
Status string // pending, completed, skipped
CreatedAt time.Time
OpenedAt sql.NullTime // When user first opened the helper page
CompletedAt sql.NullTime
// Actor is "human", or "mcp:<client>" for work an agent recorded.
Actor string
// ReviewReason is set when an automated step needs a person to decide.
ReviewReason string
}
PendingTask represents a task that needs human intervention
func (PendingTask) ActorLabel ¶ added in v1.3.0
func (t PendingTask) ActorLabel() string
ActorLabel names the AI agent that recorded a task. Tasks you made are unlabelled.
func (PendingTask) NeedsReview ¶ added in v1.3.0
func (t PendingTask) NeedsReview() bool
NeedsReview: review tasks, plus automation outcomes the agent couldn't settle (they stay pending until a person looks).
type PipelineStatus ¶
type PipelineStatus string
PipelineStatus represents the current stage in the removal pipeline
const ( PipelineEmailSent PipelineStatus = "email_sent" PipelineAwaitingResponse PipelineStatus = "awaiting_response" PipelineFormRequired PipelineStatus = "form_required" PipelineFormFilled PipelineStatus = "form_filled" PipelineAwaitingCaptcha PipelineStatus = "awaiting_captcha" PipelineCaptchaSolved PipelineStatus = "captcha_solved" PipelineAwaitingConfirmation PipelineStatus = "awaiting_confirmation" PipelineConfirmed PipelineStatus = "confirmed" PipelineNoData PipelineStatus = "no_data_held" PipelineFailed PipelineStatus = "failed" PipelineRejected PipelineStatus = "rejected" )
type Record ¶
type Record struct {
ID int64
ProfileID string
BrokerID string
BrokerName string
Email string
Template string
Status Status
MessageID string
Error string
SentAt time.Time
CreatedAt time.Time
PipelineStatus PipelineStatus // Current stage in pipeline
PipelineActor string // "human", "mcp:<client>", or empty for automated updates
SentMethod string // "smtp" (Eraser sent it) or "manual" (user did)
}
type ResponseQuery ¶ added in v1.3.0
ResponseQuery searches the entire active profile before applying pagination.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
func (*Store) AddBrokerResponse ¶
func (s *Store) AddBrokerResponse(resp *BrokerResponse) error
AddBrokerResponse stores a classified response from a broker
func (*Store) AddBrokerResponseIfNew ¶ added in v0.9.0
func (s *Store) AddBrokerResponseIfNew(resp *BrokerResponse) (inserted bool, err error)
FindBrokerResponseBySubject finds an existing response by profile, broker_id and email_subject AddBrokerResponseIfNew stores resp unless the same reply (profile, broker, subject and received time) is already recorded, so repeated or scheduled inbox scans over an overlapping window don't pile up duplicates. inserted is false for a reply seen before.
func (*Store) AddPendingTask ¶
func (s *Store) AddPendingTask(task *PendingTask) error
AddPendingTask creates a new pending task for human intervention
func (*Store) ApproveBatch ¶ added in v1.3.0
ApproveBatch is the web UI / `eraser mcp approve` side: pending and unexpired only, once.
func (*Store) ClaimAutomationAction ¶ added in v1.3.0
ClaimAutomationAction is atomic across MCP processes. A crash leaves the attempt unknown, so a possible submission is never retried automatically.
func (*Store) ClearBrokerResponses ¶
ClearBrokerResponses removes all broker responses (for full re-scan)
func (*Store) CompletePendingTask ¶
CompletePendingTask marks a task as completed, scoped to the given profile - a task belonging to a different profile is left untouched.
func (*Store) ConsumeBatchApproval ¶ added in v1.3.0
ConsumeBatchApproval spends an approval for the exact digest. Atomic: one approval, one batch.
func (*Store) CountSentSince ¶
CountSentSince returns how many successful sends have happened since the given time - used to enforce a rolling daily send cap (e.g. staying under a provider's per-day sending limit).
func (*Store) CreateBatchApproval ¶ added in v1.3.0
func (s *Store) CreateBatchApproval(a BatchApproval) error
func (*Store) DeleteAllHistory ¶
DeleteAllHistory removes one profile's removal_requests (Settings > Danger Zone). broker_responses is untouched; see ClearBrokerResponses.
func (*Store) DeleteByStatus ¶
DeleteByStatus deletes all records with the given status for one profile
func (*Store) EnsureAutomationTask ¶ added in v1.3.0
func (s *Store) EnsureAutomationTask(profileID, brokerID, brokerName string, kind TaskType, rawURL, actor string) (*PendingTask, error)
EnsureAutomationTask shows email-derived and catalog forms in the Tasks UI, one task per form however often an agent resumes.
func (*Store) FindBrokerResponseBySubject ¶
func (s *Store) FindBrokerResponseBySubject(profileID, brokerID, subject string) (*BrokerResponse, error)
func (*Store) FinishAutomationAction ¶ added in v1.3.0
func (*Store) GetActionItems ¶ added in v1.3.0
func (s *Store) GetActionItems(profileID string) (ActionItems, error)
func (*Store) GetAllBrokerResponses ¶
func (s *Store) GetAllBrokerResponses() ([]BrokerResponse, error)
GetAllBrokerResponses retrieves all broker responses across every profile (for reclassification - a full re-scan processes the whole shared inbox regardless of which profile is active in the caller's session)
func (*Store) GetAllBrokerStatuses ¶
func (s *Store) GetAllBrokerStatuses(profileID string) (map[string]BrokerStatus, error)
func (*Store) GetAllRequests ¶
GetAllRequests returns every removal request for one profile, oldest first, with pipeline_status included (unlike GetRecentRequests, which caps at a limit and omits it). Used by `eraser export` to build the evidence report.
func (*Store) GetAutomationAttempts ¶ added in v1.3.0
func (s *Store) GetAutomationAttempts(profileID, subject string) ([]AutomationAttempt, error)
func (*Store) GetBrokerResponseByID ¶ added in v0.6.1
func (s *Store) GetBrokerResponseByID(id int64, profileID string) (*BrokerResponse, error)
func (*Store) GetBrokerResponses ¶
func (s *Store) GetBrokerResponses(profileID, responseType string, needsReview bool, limit int) ([]BrokerResponse, error)
GetBrokerResponses retrieves broker responses for one profile, with optional filtering
func (*Store) GetBrokerResponsesForExport ¶
func (s *Store) GetBrokerResponsesForExport(profileID string) ([]BrokerResponse, error)
GetBrokerResponsesForExport returns one profile's responses, oldest first, including email_body. Used by `eraser export`.
func (*Store) GetBrokerStatus ¶
func (s *Store) GetBrokerStatus(profileID, brokerID string) (BrokerStatus, error)
GetBrokerStatus is GetAllBrokerStatuses for one broker, so the web UI can refresh a single row while a send is polling.
func (*Store) GetFormStats ¶
func (s *Store) GetFormStats(profileID string) (pending, filled, captcha, failed, skipped int, err error)
GetFormStats returns counts of forms by status for one profile
func (*Store) GetFormsWithStatus ¶
func (s *Store) GetFormsWithStatus(profileID string) ([]FormWithStatus, error)
GetFormsWithStatus returns all detected forms with their current status for one profile.
func (*Store) GetMonthlyStats ¶
func (*Store) GetPendingTaskByID ¶
func (s *Store) GetPendingTaskByID(id int64, profileID string) (*PendingTask, error)
GetPendingTaskByID retrieves a specific pending task by its numeric ID, scoped to the given profile - a task belonging to a different profile returns nil, nil, the same as a task that doesn't exist at all.
func (*Store) GetPendingTaskStats ¶
GetPendingTaskStats returns counts of pending tasks by type and status for one profile
func (*Store) GetPendingTasks ¶
func (s *Store) GetPendingTasks(profileID string, taskType TaskType, status string) ([]PendingTask, error)
GetPendingTasks retrieves pending tasks for one profile, with optional filtering
func (*Store) GetPipelineStats ¶
func (s *Store) GetPipelineStats(profileID string) (map[PipelineStatus]int, error)
UpdatePipelineStatus sets a broker's pipeline status for one profile. For inbox replies, resolve the profile via ResolveProfileForBroker first. GetPipelineStats returns counts by pipeline status for one profile
func (*Store) GetRecentRequests ¶
func (*Store) GetResponseStats ¶
GetResponseStats returns counts of response types for one profile
func (*Store) LastSuccessfulSendTimes ¶
LastSuccessfulSendTimes returns each broker's latest successful send, in one query.
func (*Store) LatestRequests ¶ added in v1.3.0
LatestRequests uses the same most-recent-send ordering as status updates. Historical sends do not inflate stage counters or their drill-down lists.
func (*Store) MarkBrokerResponseReviewed ¶ added in v0.6.1
func (*Store) MarkFailed ¶
MarkFailed flips a broker's latest "sent" record to "failed" with a note. SMTP acceptance isn't delivery, and without inbox monitoring nothing fixes a later bounce; this lets the resend cooldown stop counting that broker as contacted. Returns rows updated (0 = nothing to fix).
func (*Store) MarkTaskOpened ¶
MarkTaskOpened sets the opened_at timestamp (only if not already set), scoped to the given profile - a task belonging to a different profile is left untouched.
func (*Store) MatchingResponseIDs ¶ added in v1.3.0
MatchingResponseIDs lets action searches include a form/review's underlying email text without loading every body into the web response.
func (*Store) MigrateNoData ¶ added in v1.3.0
func (s *Store) MigrateNoData(classify NoDataClassifier) error
MigrateNoData reclassifies saved replies once, atomically across profiles. It only relabels replies; resolving requests is left to ResolveNoData and the reclassify action. Claiming the version inside the write transaction also serializes two app processes upgrading the same database. A failed migration is retryable.
func (*Store) OverridePipelineStatus ¶ added in v1.3.0
func (s *Store) OverridePipelineStatus(profileID, brokerID string, status PipelineStatus) error
OverridePipelineStatus is for a person's explicit decision in the UI.
func (*Store) PendingBatchApprovals ¶ added in v1.3.0
func (s *Store) PendingBatchApprovals() ([]BatchApproval, error)
func (*Store) QueryBrokerResponses ¶ added in v1.3.0
func (s *Store) QueryBrokerResponses(profileID string, q ResponseQuery) ([]BrokerResponse, int, error)
func (*Store) ResolveNoData ¶ added in v1.3.0
ResolveNoData reconciles only a confident, latest no-data reply. Call after inserting or reclassifying a reply; repeated calls are safe.
func (*Store) ResolveProfileForBroker ¶
ResolveProfileForBroker returns the profile that most recently emailed brokerID, so replies in a shared inbox go to the right profile rather than the active one. DefaultProfileID if none did.
func (*Store) RetryAutomationAction ¶ added in v1.3.0
RetryAutomationAction is only for an explicitly reviewed failed attempt.
func (*Store) UpdateAutomationTask ¶ added in v1.3.0
func (s *Store) UpdateAutomationTask(profileID string, id int64, actor, reviewReason, note, screenshot string, completed bool) error
UpdateAutomationTask writes notes, evidence and completion in one update. A missing, other-profile, completed or skipped task is an error.
func (*Store) UpdateBrokerResponseBody ¶
UpdateBrokerResponseBody updates the email body for an existing response, scoped to the given profile - a response belonging to a different profile is left untouched.
func (*Store) UpdateBrokerResponseClassification ¶
func (s *Store) UpdateBrokerResponseClassification(id int64, profileID string, responseType string, formURL, confirmURL string, confidence float64, needsReview bool) error
UpdateBrokerResponseClassification updates the classification fields of a response, scoped to the given profile - a response belonging to a different profile is left untouched.
func (*Store) UpdatePipelineStatus ¶
func (s *Store) UpdatePipelineStatus(profileID, brokerID string, status PipelineStatus) error
UpdatePipelineStatus moves the latest request forward only; earlier or unknown stages are ignored.
func (*Store) UpdatePipelineStatusBy ¶ added in v1.3.0
func (s *Store) UpdatePipelineStatusBy(profileID, brokerID string, status PipelineStatus, actor string) error
UpdatePipelineStatusBy records which agent client moved the stage, so the export can say who did it.