"anubis soak" reads the bot's records over a time window and says whether the run kept control. It changes nothing, so it can run beside the working bot with docker exec. It exits with 4 when something needs a look. It checks: - the hours covered and silences longer than 15 minutes; - orders or decisions made twice; - unexplained reconciliation differences and each account's last outcome; - absences and guard interventions; - one crypto decision per daily close. ADR 0012 records what the specification leaves open in this phase: the live engine shares the backtest's decision call, run keys, recovery after an absence, the guard and its drill seams, the diary templates, the "senza bot" comparison, Telegram and the heartbeat, the screens and the endurance run. ROADMAP ticks the Phase 6 items and criteria with the tests that prove them, STATE moves on to Phase 7, and SVILUPPO explains the guard and the report. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9ae107000b
commit
3d174931e9
8 files changed
+549
-19
No files matched your search
@@ -18,6 +18,12 @@ if (args.Length >= 1 && args[0] == "backtest")
|
||||
return await BacktestCommand.RunAsync(args[1..]).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
// "anubis soak": the report of the endurance run in real time, read from the bot's records while it works (Phase 6).
|
||||
if (args.Length >= 1 && args[0] == "soak")
|
||||
{
|
||||
return await SoakCommand.RunAsync(args[1..]).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
var app = ServerApp.Build(args);
|
||||
await app.RunAsync().ConfigureAwait(false);
|
||||
return 0;
|
||||
@@ -0,0 +1,77 @@
|
||||
using System.Collections;
|
||||
using System.Globalization;
|
||||
using Anubis.Core;
|
||||
using Anubis.Db;
|
||||
using Anubis.Supervision;
|
||||
|
||||
namespace Anubis.Server;
|
||||
|
||||
/// <summary>
|
||||
/// "anubis soak": the report of an endurance run in real time (SPEC 17, phase 6) from the bot's own records. It only
|
||||
/// reads, so it can run while the bot works: in Docker with <c>docker exec</c>, on desktop from a second terminal.
|
||||
/// </summary>
|
||||
internal static class SoakCommand
|
||||
{
|
||||
private const string Usage =
|
||||
"Uso: anubis soak [--from AAAA-MM-GGTHH:MMZ] [--to AAAA-MM-GGTHH:MMZ] [--hours 48] [--out file.md]\n" +
|
||||
" senza --from la prova è delle ultime --hours ore fino a --to (o adesso).\n" +
|
||||
"Opzioni comuni: [--platform docker|desktop] [--data-dir <cartella>]";
|
||||
|
||||
/// <summary>0 when the run is in order, 4 when something must be looked at, 1 when the report could not be made.</summary>
|
||||
public static async Task<int> RunAsync(string[] args, TextWriter? output = null, IReadOnlyDictionary<string, string?>? environment = null, IClock? clock = null)
|
||||
{
|
||||
output ??= Console.Out;
|
||||
clock ??= new SystemClock();
|
||||
var own = new Dictionary<string, string>(StringComparer.Ordinal);
|
||||
var rest = new List<string>();
|
||||
for (var i = 0; i < args.Length; i++)
|
||||
{
|
||||
if (args[i] is "--from" or "--to" or "--hours" or "--out" && i + 1 < args.Length)
|
||||
{
|
||||
own[args[i]] = args[++i];
|
||||
}
|
||||
else if (args[i] is "--help" or "-h")
|
||||
{
|
||||
await output.WriteLineAsync(Usage).ConfigureAwait(false);
|
||||
return 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
rest.Add(args[i]);
|
||||
}
|
||||
}
|
||||
|
||||
environment ??= Environment.GetEnvironmentVariables().Cast<DictionaryEntry>().ToDictionary(e => (string)e.Key, e => e.Value as string, StringComparer.Ordinal);
|
||||
try
|
||||
{
|
||||
var hours = own.TryGetValue("--hours", out var h) ? double.Parse(h, CultureInfo.InvariantCulture) : 48;
|
||||
var to = own.TryGetValue("--to", out var t) ? DateTimeOffset.Parse(t, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal) : clock.UtcNow;
|
||||
var from = own.TryGetValue("--from", out var f) ? DateTimeOffset.Parse(f, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal) : to - TimeSpan.FromHours(hours);
|
||||
var options = ServerOptions.Parse([.. rest], environment);
|
||||
var config = options.LoadConfig(environment);
|
||||
if (!config.IsComplete)
|
||||
{
|
||||
await output.WriteLineAsync("La configurazione d'avvio non è completa: avvia prima il server una volta.").ConfigureAwait(false);
|
||||
return 1;
|
||||
}
|
||||
|
||||
Redactor.Register(config.Db!.Password);
|
||||
await using var db = Database.Open(config.Db!, allowCreate: false);
|
||||
var report = await SoakReporter.BuildAsync(db, from, to, TimeSpan.FromHours(hours), config.TimeZone, CancellationToken.None).ConfigureAwait(false);
|
||||
var text = report.Markdown(config.TimeZone);
|
||||
if (own.TryGetValue("--out", out var file))
|
||||
{
|
||||
await File.WriteAllTextAsync(Path.GetFullPath(file), text).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
await output.WriteAsync(text).ConfigureAwait(false);
|
||||
return report.Passed ? 0 : 4;
|
||||
}
|
||||
catch (Exception ex) when (ex is IOException or FormatException or ArgumentException or InvalidOperationException or SchemaException
|
||||
or System.Data.Common.DbException or UnauthorizedAccessException or TimeZoneNotFoundException)
|
||||
{
|
||||
await output.WriteLineAsync("Non riuscito: " + Redactor.Redact(ex.Message)).ConfigureAwait(false);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user