«Aggiungi account» ha una sola casella: mentre Alberto scrive compaiono subito i suggerimenti locali, poi i profili di Instagram con la foto, come chiesto in #37. Il browser di Febe scrive nella casella «Cerca» di Instagram con tasti veri da una mappa chiusa (mai Invio, Tab o Esc), controlla prima il fuoco, legge la risposta della pagina e non clicca mai un risultato. La ricerca ha una categoria propria nel Governatore, con tetti larghi che non consumano quelli della raccolta, e si dà il turno con il motore sull'unica pagina; a fine sessione la pagina torna comunque al riposo. Le foto passano dal CDN con un permesso ciascuna e restano solo in memoria. Le risposte di Alberto del 15 novembre (controllo del fuoco, turni, evento requestWillBeSent, niente foto dei seguiti per ora) sono in §6.1 e in docs/decisioni.md. Su Instagram vero la ricerca parte quando i bersagli search-open e search-box saranno raccolti dal vivo. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
127 lines
4.5 KiB
C#
127 lines
4.5 KiB
C#
namespace Febe.Core.Abstractions;
|
|
|
|
/// <summary>
|
|
/// Categories of counted actions toward the site (spec §7.4). Each has an hourly and a daily budget,
|
|
/// except <see cref="DataDownload"/>, which has a daily byte budget.
|
|
/// </summary>
|
|
public enum ActionKind
|
|
{
|
|
/// <summary>Opening the home page (Giro dei seguiti).</summary>
|
|
Home,
|
|
|
|
/// <summary>Opening a profile page.</summary>
|
|
ProfileOpen,
|
|
|
|
/// <summary>One story shown in the viewer (stories and highlight items).</summary>
|
|
StoryView,
|
|
|
|
/// <summary>One page of history loaded by scrolling (Storico, Taggati, Reel).</summary>
|
|
BackfillPage,
|
|
|
|
/// <summary>Opening a single post page.</summary>
|
|
SinglePost,
|
|
|
|
/// <summary>One page of the list of profiles Alberto follows.</summary>
|
|
FollowingListPage,
|
|
|
|
/// <summary>
|
|
/// One step of the profile search toward the site: opening Instagram for the search, opening its «Cerca» panel or
|
|
/// focusing its box, or one burst of typing (issue #37). Outside sessions, with its own wide budget that does not
|
|
/// consume the collection budgets.
|
|
/// </summary>
|
|
ProfileSearch,
|
|
|
|
/// <summary>Bytes downloaded from the CDN (daily byte budget).</summary>
|
|
DataDownload,
|
|
}
|
|
|
|
/// <summary>Why the Governor refused an action. Shown in the interface.</summary>
|
|
public enum DenialReason
|
|
{
|
|
None,
|
|
BreakerOpen,
|
|
OutsideActiveWindow,
|
|
NoSession,
|
|
HourlyBudgetReached,
|
|
DailyBudgetReached,
|
|
MinimumSpacing,
|
|
AccountLimitReached,
|
|
UserIsDriving,
|
|
Paused,
|
|
|
|
/// <summary>The account is «Solo archivio», paused or not reachable: the engine does not contact it (spec §4.2, rule 6).</summary>
|
|
AccountNotContactable,
|
|
}
|
|
|
|
/// <summary>
|
|
/// The Governor's answer to a request: either a permission or a motivated refusal (spec §7.4).
|
|
/// </summary>
|
|
public sealed record Permit(bool Granted, ActionKind Kind, long? AccountId, DenialReason Reason, string? Message, DateTimeOffset? RetryAfter)
|
|
{
|
|
public static Permit Grant(ActionKind kind, long? accountId) =>
|
|
new(true, kind, accountId, DenialReason.None, null, null);
|
|
|
|
public static Permit Deny(ActionKind kind, long? accountId, DenialReason reason, string message, DateTimeOffset? retryAfter = null) =>
|
|
new(false, kind, accountId, reason, message, retryAfter);
|
|
}
|
|
|
|
/// <summary>
|
|
/// The single point through which every engine action toward the site passes (spec §2 rule 7, §7.4).
|
|
/// No code path may load an Instagram page or perform a gesture on it without a granted permit.
|
|
/// </summary>
|
|
public interface IGovernor
|
|
{
|
|
Task<Permit> RequestAsync(ActionKind kind, long? accountId, CancellationToken ct);
|
|
}
|
|
|
|
/// <summary>Severity levels of stop signals (spec §7.6).</summary>
|
|
public enum SignalLevel
|
|
{
|
|
/// <summary>Rallentamento: timed stop (1h, 6h, 24h), then halved budgets for 48 hours.</summary>
|
|
Throttle,
|
|
|
|
/// <summary>Verifica: stops everything until Alberto resumes by hand.</summary>
|
|
Challenge,
|
|
|
|
/// <summary>Disconnessione: as Challenge; never tries to log back in.</summary>
|
|
Disconnect,
|
|
}
|
|
|
|
/// <summary>A stop signal reported by recipes or by the response capture.</summary>
|
|
/// <param name="Level">Severity.</param>
|
|
/// <param name="Code">Stable identifier of the signal, e.g. "http-429" or "challenge-url" (from segnali.json).</param>
|
|
/// <param name="Url">Address where it was seen, without query string (never secrets).</param>
|
|
/// <param name="At">When it was seen.</param>
|
|
public sealed record Signal(SignalLevel Level, string Code, string? Url, DateTimeOffset At);
|
|
|
|
/// <summary>State of the circuit breaker (Interruttore).</summary>
|
|
public enum BreakerStatus
|
|
{
|
|
/// <summary>Normal operation.</summary>
|
|
Closed,
|
|
|
|
/// <summary>Timed stop after a throttle signal; reopens by itself at <see cref="BreakerState.Until"/>.</summary>
|
|
Throttled,
|
|
|
|
/// <summary>Stopped after a challenge: needs Alberto and «Riprendi».</summary>
|
|
Challenge,
|
|
|
|
/// <summary>Stopped after a disconnection: needs Alberto and «Riprendi».</summary>
|
|
Disconnected,
|
|
}
|
|
|
|
public sealed record BreakerState(BreakerStatus Status, DateTimeOffset? Until, Signal? LastSignal, DateTimeOffset? HalvedBudgetsUntil)
|
|
{
|
|
public static readonly BreakerState Normal = new(BreakerStatus.Closed, null, null, null);
|
|
|
|
public bool AllowsSiteActions => Status == BreakerStatus.Closed;
|
|
}
|
|
|
|
/// <summary>The circuit breaker (spec §7.6). Every stop is persisted as an incident.</summary>
|
|
public interface ICircuitBreaker
|
|
{
|
|
BreakerState State { get; }
|
|
|
|
void Report(Signal signal);
|
|
}
|