Ossatura del progetto: soluzione, contratti, specifica, mockup, carattere e icone

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Mzbb6zeFTjT6Rp8b92AVkA
This commit is contained in:
Claude committed 2026-10-13 14:47:06 +00:00
1 parent 10a9ed3ec3
commit db3d9f1aa4
123 files changed
+3763 -1

No files matched your search

+48
View File
@@ -0,0 +1,48 @@
using System.Text.Json;
namespace Febe.Core.Abstractions;
/// <summary>Options for starting the browser that visits the site.</summary>
/// <param name="ProfileDirectory">Browser profile folder (Dati/browser): holds the Instagram session.</param>
/// <param name="WindowWidth">Fixed window width, always the same.</param>
/// <param name="WindowHeight">Fixed window height, always the same.</param>
/// <param name="DebugPort">Fixed remote-debugging port, bound to 127.0.0.1 only (Docker). Never 0.</param>
/// <param name="ExecutablePath">Browser executable (Docker: the distribution's Chromium). Null means autodetect.</param>
/// <param name="Display">X display for Xvfb (Docker), e.g. ":99". Null means the current display.</param>
public sealed record BrowserOptions(
string ProfileDirectory,
int WindowWidth = 1280,
int WindowHeight = 900,
int DebugPort = 9222,
string? ExecutablePath = null,
string? Display = null);
/// <summary>
/// The browser host (spec §5): Chromium on Xvfb in Docker, WebView2 on Windows.
/// Everything above this interface is identical on both platforms.
/// </summary>
public interface IBrowserHost : IAsyncDisposable
{
Task StartAsync(BrowserOptions options, CancellationToken ct);
ICdpSession Cdp { get; }
/// <summary>Windows: brings the browser window to the foreground.</summary>
Task ShowToUserAsync();
Task HideFromUserAsync();
/// <summary>True while Alberto uses the browser: the engine does not act.</summary>
bool UserIsDriving { get; }
}
/// <summary>
/// A Chrome DevTools Protocol session on the page target. Only the commands listed in spec §6.1 may be sent;
/// implementations log command and event names only, never parameters or results.
/// </summary>
public interface ICdpSession
{
Task<JsonElement> SendAsync(string method, object? parameters = null, CancellationToken ct = default);
IDisposable On(string eventName, Action<JsonElement> handler);
}
+116
View File
@@ -0,0 +1,116 @@
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>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 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);
}
+54
View File
@@ -0,0 +1,54 @@
namespace Febe.Core.Abstractions;
/// <summary>
/// The only source of time for the engine (spec §5). Engine code never uses
/// DateTime.Now, DateTimeOffset.Now or Task.Delay directly, so it can run under a virtual clock.
/// </summary>
public interface IClock
{
DateTimeOffset Now { get; }
/// <summary>The user's time zone (Alberto's): daily budgets and file names use it.</summary>
TimeZoneInfo LocalZone { get; }
Task Delay(TimeSpan time, CancellationToken ct);
}
/// <summary>The only source of randomness for the engine (spec §5).</summary>
public interface IRandomSource
{
/// <summary>Uniform value in [0, 1).</summary>
double NextDouble();
}
/// <summary>Real wall clock, used outside tests and simulation.</summary>
public sealed class SystemClock(TimeZoneInfo? zone = null) : IClock
{
public DateTimeOffset Now => DateTimeOffset.UtcNow;
public TimeZoneInfo LocalZone { get; } = zone ?? TimeZoneInfo.Local;
public Task Delay(TimeSpan time, CancellationToken ct) =>
time <= TimeSpan.Zero ? Task.CompletedTask : Task.Delay(time, ct);
}
/// <summary>Process-wide random source for production use.</summary>
public sealed class SystemRandom : IRandomSource
{
public double NextDouble() => Random.Shared.NextDouble();
}
/// <summary>Deterministic random source for tests and simulation (fixed seed).</summary>
public sealed class SeededRandom(int seed) : IRandomSource
{
private readonly Random _random = new(seed);
private readonly Lock _gate = new();
public double NextDouble()
{
lock (_gate)
{
return _random.NextDouble();
}
}
}