Raccolta (M0/M2): sito di prova completo, lettori per forma, ricette su browser vero, coda degli scaricamenti, sonda con ripulitura e verifica; documenti delle ipotesi e delle prove dal vivo

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 17:32:35 +00:00
1 parent e2c987873b
commit 4fc5a6c0d4
74 files changed
+12689 -13

No files matched your search

@@ -0,0 +1,126 @@
using Febe.Core.Abstractions;
using Febe.Core.Collection.Readers;
using Febe.Core.Domain;
using Febe.Core.Engine;
namespace Febe.Core.Collection.Recipes;
public sealed partial class RecipeRunner
{
/// <summary>
/// Giro dei seguiti (spec §6.3): opens the home (1 counted action), reads the stories bar, and scrolls the recent
/// posts of followed profiles until it meets known content, with at most 8 bursts. Posts that arrive with complete
/// data are saved at once; incomplete series are saved with what arrived and completed by «Post singolo».
/// </summary>
private async Task<RecipeStatus> FollowingSweepAsync(RecipeRun run)
{
await run.PermitAsync(ActionKind.Home, null).ConfigureAwait(false);
var mark = Env.Capture.Mark();
await run.OpenAsync(SitePages.Home).ConfigureAwait(false);
var reads = await run.WaitForDataAsync(mark, r => r.Contents.Count > 0 || r.Profiles.Count > 0).ConfigureAwait(false);
run.Judge(reads, r => r.Contents.Count > 0 || r.Profiles.Count > 0, Env.SiteMap.BuildPath(SitePages.Home));
var processed = 0;
var sawKnown = await ProcessSweepReadsAsync(run, reads, ref processed).ConfigureAwait(false);
var hasMore = reads.Select(r => r.Result.Page).LastOrDefault(p => p is not null)?.HasMore ?? true;
for (var burst = 0; burst < Env.Options.SweepMaxBursts && !sawKnown && hasMore; burst++)
{
var before = Env.Capture.Mark();
await Env.Driver.ScrollBurstAsync(run.Ct).ConfigureAwait(false);
run.ThrowIfSignal();
await run.SettleAsync().ConfigureAwait(false);
var more = Env.Capture.Since(before);
if (more.Count == 0)
{
continue;
}
reads = [.. reads, .. more];
sawKnown = await ProcessSweepReadsAsync(run, reads, ref processed).ConfigureAwait(false);
hasMore = more.Select(r => r.Result.Page).LastOrDefault(p => p is not null)?.HasMore ?? hasMore;
}
await Env.Driver.MaybeDistractionAsync(run.Ct).ConfigureAwait(false);
return RecipeStatus.Completed;
}
/// <summary>Saves the posts not processed yet; returns true once known content has been met.</summary>
private Task<bool> ProcessSweepReadsAsync(RecipeRun run, IReadOnlyList<CapturedRead> reads, ref int processed)
{
var items = Contents(reads);
var fresh = items.Skip(processed).ToList();
processed = items.Count;
return ProcessSweepItemsAsync(run, reads, fresh);
}
private async Task<bool> ProcessSweepItemsAsync(RecipeRun run, IReadOnlyList<CapturedRead> reads, IReadOnlyList<ContentItem> items)
{
await EnsureMineAsync(reads, run).ConfigureAwait(false);
// Stories bar (H2): followed accounts whose latest story is newer than their last stories check.
foreach (var profile in reads.SelectMany(r => r.Result.Profiles).Where(p => p.LatestStoryAt is not null))
{
var account = await Writer.ObserveProfileAsync(profile, run.Session.SessionId, run.Ct).ConfigureAwait(false);
if (account is { State: not (AccountState.ArchiveOnly or AccountState.Unreachable) }
&& account.ContentTypes.HasFlag(ContentTypes.Stories)
&& profile.LatestStoryAt > (account.LastStoriesCheckAt ?? DateTimeOffset.MinValue))
{
run.AccountsWithStories.Add(account.Id);
}
}
var sawKnown = false;
foreach (var item in items)
{
if (item.Owner is null)
{
continue;
}
var account = await Writer.ObserveProfileAsync(item.Owner, run.Session.SessionId, run.Ct).ConfigureAwait(false);
if (account is null || account.State is AccountState.ArchiveOnly or AccountState.Unreachable || account.Id == 0)
{
continue; // not an account Febe keeps
}
var saved = await Writer.SaveAsync(account, item, EntryKind.Post, run.Session.SessionId, run.Ct).ConfigureAwait(false);
switch (saved.Outcome)
{
case SaveOutcome.Created:
run.NewEntries++;
run.AccountsWithNewPosts.Add(account.Id);
break;
case SaveOutcome.Known when !item.Pinned:
sawKnown = true;
break;
}
}
return sawKnown;
}
/// <summary>
/// Alberto's own profile («Tu») from the data the page receives (H10), the first time it is seen.
/// </summary>
private async Task EnsureMineAsync(IReadOnlyList<CapturedRead> reads, RecipeRun run)
{
if (reads.Select(r => r.Result.Viewer).FirstOrDefault(v => v is not null) is not { } viewer)
{
return;
}
var mine = await Env.Storage.Accounts.GetMineAsync(run.Ct).ConfigureAwait(false);
if (mine is not null || await Env.Storage.Accounts.FindByInstagramIdAsync(viewer.Id, run.Ct).ConfigureAwait(false) is not null)
{
return;
}
var account = Account.Create(viewer.Username, StartingPoint.EverythingAndKeepUpdated, Env.Clock.Now, Env.Clock.LocalZone, isMine: true) with
{
InstagramId = viewer.Id,
};
await Env.Storage.Accounts.AddAsync(account, run.Ct).ConfigureAwait(false);
await Writer.EventAsync("account-collegato", $"Account collegato riconosciuto dai dati della pagina: {viewer.Username} («Tu»).", EventSeverity.Info, null, run.Session.SessionId, run.Ct).ConfigureAwait(false);
}
}