Skip to content

A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.

sim: the timeline helper, the alternate-card release gate and --timeline-report (R-ALT-011, refs #953) (#1003)

Berid330c50c376a
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a73f464ef..bdc581aa9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -28,6 +28,9 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIB
short, at most 2 starts a turn; `CancelProject(id)` returns no Money. The kinds are labelled design values in the new
`content/projects.yaml` (Q-PROJ-1 to Q-PROJ-5, Q-HOUSE-3; R-PROJ-001 to R-PROJ-003; refs #735). The reference player
starts a housing project, one at a time, where the overflow is largest, so `hash1950`, `hash1952` and `mvp-end` move.
+- Release gate: consequence cards and variants need a person's sign-off (`reviewed_by`) before a build is shared;
+ `Statecraft.Cli --timeline-report` lists each road not taken and what follows it, and `Timeline.Entries` /
+ `Timeline.Origin` give the timeline screen its rows (R-ALT-011; refs #939, #953).
### Changed
- The population-tier badge on the twelve city and town pills keeps the values it shipped with, now owner-approved: tiers 1
diff --git a/docs/WRITING_EVENTS.md b/docs/WRITING_EVENTS.md
index 87332e5e1..a9987aaf6 100644
--- a/docs/WRITING_EVENTS.md
+++ b/docs/WRITING_EVENTS.md
@@ -412,6 +412,14 @@ gate by hand:
dotnet run --project sim/Statecraft.Cli -- --release-gate
```
+To see every road not taken (each non-historical option of an event that has a historical one), with who proposed it
+(`basis`, `-` when the option has no `alternative` record), the consequence cards that follow it, the events whose
+variants name it, and the record's cards it suppresses (`breaks`, the events that require the historical option):
+
+```
+dotnet run --project sim/Statecraft.Cli -- --timeline-report
+```
+
The Python checks (`uv run --with pytest==9.1.1 --with pyyaml==6.0.3 pytest scripts/oss/tests -q`, and
`uv run scripts/oss/check_repo.py`) cover repository policy. They include a test that keeps this guide's field table
in line with the loader.
diff --git a/docs/m3-release.md b/docs/m3-release.md
index 81cd98e70..347b6867b 100644
--- a/docs/m3-release.md
+++ b/docs/m3-release.md
@@ -245,6 +245,11 @@ war-casualties). The owner's sign-off for all seven events below is recorded in
sensitive event photograph (`docs/event-images.md`). Use `-shareable` and the script for every build
that leaves this machine, including the M4 private Draft once it is shared with anyone. Local dev builds (no flag)
are not gated, because web_check and the golden checks need them.
+- **Alternate-timeline content (R-ALT-011, Q-ALT-9):** `Statecraft.Cli --release-gate`, and so
+ `tools/package_release.py` and `scripts/oss/release_gate.sh`, also refuse while any consequence card (`kind:
+ consequence`) or any event with `variants` has no `reviewed_by`, naming them on a `RELEASE GATE REFUSED` line
+ (`Statecraft.Sim.ReleaseGate.AlternateUnsigned`; the CLI also prints each as `unsigned alternate card: <id>`). The
+ sign-off is a person's `reviewed_by`, written only by that person. The Unity `-shareable` build flag checks the sensitive events only.
- **Pinned set:** `FinalWaveTests.TheSensitiveEventsArePinned` lists the seven ids, and
`TheOwnerTableListsEverySensitiveEvent` fails if a sensitive event is missing from this table, so a new one cannot
skip the review.
diff --git a/docs/rules/mvp.md b/docs/rules/mvp.md
index 92a6db925..b66e8f96e 100644
--- a/docs/rules/mvp.md
+++ b/docs/rules/mvp.md
@@ -212,4 +212,6 @@ R-ALT-009: An option of a consequence card may `rejoin` an event whose road the
R-ALT-010: An event of `kind: reconvergence` has a historical option and may carry `variants`. The first variant whose every `when` entry holds supplies the card's title (if it gives one) and text; options and effects never vary. Each variant follows a road not taken, carries sources, has its placeholders checked over the event's window, and names only roads whose windows close on or before the event's `from` (for a road's historical option, also every consequence card that can `rejoin` it, R-ALT-009). Only a reconvergence event carries variants.
+R-ALT-011: A shareable build refuses while any consequence card, or any event with variants, has no `reviewed_by` (a person's sign-off), alongside the sensitivity gate (Q-ALT-9). `Timeline.Entries` lists each resolved event, in window order, with the player's option beside the record's, and `Timeline.Origin` names the road a consequence card follows.
+
R-ALT-012: The historical run (the reference player's orders from 15 May 1948 to 15 January 1952) raises no consequence card and diverges nowhere.
diff --git a/sim/Statecraft.Cli/Program.cs b/sim/Statecraft.Cli/Program.cs
index b380d0fb6..ff1cf697a 100644
--- a/sim/Statecraft.Cli/Program.cs
+++ b/sim/Statecraft.Cli/Program.cs
@@ -7,6 +7,7 @@ using Statecraft.Sim;
// dotnet run --project Statecraft.Cli -- --preview [--until YYYY-MM-DD] [--set key=value]... [--show id,id] [--every N]
// writer preview: the historical run with some rules.yaml values changed in memory, against the real content
// dotnet run --project Statecraft.Cli -- --release-gate [--content DIR] (exit 0 when shareable, 3 when not)
+// dotnet run --project Statecraft.Cli -- --timeline-report [--content DIR] (each road not taken and what follows it)
// Interactive commands: c EVENT OPTION | p POLICY LEVEL | m LEVEL | s DELTA | n (end turn) | q
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture;
CultureInfo.CurrentCulture = CultureInfo.InvariantCulture;
@@ -60,16 +61,47 @@ catch (DirectoryNotFoundException) { Console.Error.WriteLine("Content error: con
catch (ContentException e) { Console.Error.WriteLine($"Content error: {e.Message}"); return 2; }
// --release-gate: the sensitivity gate before a build is shared (spec 5.5; tools/package_release.py, Build -shareable).
-// Exit 0 and "RELEASE GATE OK" when every sensitive event is sensitivity-reviewed, else exit 3 naming them.
+// Exit 0 and "RELEASE GATE OK" when every sensitive event is sensitivity-reviewed and (R-ALT-011, Q-ALT-9) every
+// consequence card and every event with variants has a person's reviewed_by; else exit 3 naming them.
if (Array.IndexOf(args, "--release-gate") >= 0)
{
var open = ReleaseGate.SensitiveUnreviewed(content);
- if (open.Count == 0) { Console.WriteLine("RELEASE GATE OK"); return 0; }
- Console.WriteLine("RELEASE GATE REFUSED: the owner's sensitivity review is missing for: " + string.Join(", ", open)
- + " (set status: sensitivity-reviewed in each event's YAML; see docs/m3-release.md)");
+ var unsigned = ReleaseGate.AlternateUnsigned(content);
+ if (open.Count == 0 && unsigned.Count == 0) { Console.WriteLine("RELEASE GATE OK"); return 0; }
+ if (open.Count > 0)
+ Console.WriteLine("RELEASE GATE REFUSED: the owner's sensitivity review is missing for: " + string.Join(", ", open)
+ + " (set status: sensitivity-reviewed in each event's YAML; see docs/m3-release.md)");
+ // Its own REFUSED line too: tools/package_release.py keeps only lines containing "RELEASE GATE".
+ if (unsigned.Count > 0)
+ Console.WriteLine("RELEASE GATE REFUSED: no person has signed off (reviewed_by) these alternate cards: " + string.Join(", ", unsigned)
+ + " (see docs/m3-release.md)");
+ foreach (var id in unsigned) Console.WriteLine(" unsigned alternate card: " + id);
return 3;
}
+// --timeline-report (R-ALT-011): one line per road not taken, in window order: who proposed it (basis), the consequence
+// cards that follow it, the events whose variants name it, and the record's cards it suppresses (they require the
+// historical option). A writer's coverage view; "-" for none.
+if (Array.IndexOf(args, "--timeline-report") >= 0)
+{
+ static bool Names(EventRequirement r, GameEvent e, EventOption o) => r.Event == e.Id && (r.Diverged || r.Option == o.Id);
+ static string Ids(IEnumerable<GameEvent> es)
+ {
+ var ids = es.Select(x => x.Id).OrderBy(x => x, StringComparer.Ordinal).ToList();
+ return ids.Count == 0 ? "-" : string.Join(",", ids);
+ }
+ foreach (var e in content.Events.Where(x => Timeline.HistoricalOption(x) != null).OrderBy(x => x.From).ThenBy(x => x.Id, StringComparer.Ordinal))
+ {
+ var record = Timeline.HistoricalOption(e)!.Id;
+ foreach (var o in e.Options.Where(x => !x.Historical))
+ Console.WriteLine($"{e.Id}/{o.Id} basis={(o.Alternative?.Basis is { Length: > 0 } b ? b : "-")}"
+ + $" cards={Ids(content.Events.Where(k => k.Kind == EventKinds.Consequence && k.Requires.Any(r => Names(r, e, o))))}"
+ + $" variants={Ids(content.Events.Where(k => k.Variants.Any(v => v.When.Any(r => Names(r, e, o)))))}"
+ + $" breaks={Ids(content.Events.Where(k => k.Requires.Any(r => r.Event == e.Id && !r.Diverged && r.Option == record)))}");
+ }
+ return 0;
+}
+
ulong seed = 1948;
int turns = 1000;
var seedText = Arg("--seed");
diff --git a/sim/Statecraft.Sim.Tests/AlternateTimelineTests.cs b/sim/Statecraft.Sim.Tests/AlternateTimelineTests.cs
index d31dec200..dde0b5de3 100644
--- a/sim/Statecraft.Sim.Tests/AlternateTimelineTests.cs
+++ b/sim/Statecraft.Sim.Tests/AlternateTimelineTests.cs
@@ -635,4 +635,31 @@ variants:
Assert.True(Timeline.Diverged(Real, end, "first_truce"));
Assert.Equal(new[] { "first_truce" }, end.ChosenOptions.Keys.Where(k => Timeline.Diverged(Real, end, k)).ToArray());
}
+
+ // ---- Task 8 (#953): the timeline helper ----------------------------------------------------------------------
+
+ [Fact]
+ // R-ALT-011
+ public void TheTimelineListsEachResolvedEventInWindowOrder()
+ {
+ var c = Load(("parent.yaml", Parent), ("after_road.yaml", WithRejoin), ("outside.yaml", Outside));
+ var s = NewState(c);
+ s.ChosenOptions["outside"] = "record"; s.ChosenOptions["parent"] = "road"; s.ChosenOptions["after_road"] = "hold";
+ var rows = Timeline.Entries(c, s);
+ Assert.Equal(new[] { "parent", "after_road", "outside" }, rows.Select(r => r.Event));
+ var p = rows[0];
+ Assert.Equal(("road", "record", true, "after_road"), (p.Chosen, p.Historical, p.Diverged, p.RejoinedBy));
+ Assert.Equal(("hold", "", false), (rows[1].Chosen, rows[1].Historical, rows[1].Diverged));
+ }
+
+ [Fact]
+ // R-ALT-011
+ public void TheOriginNamesTheRoadTheCardFollows()
+ {
+ var c = Load(("parent.yaml", Parent), ("after_road.yaml", Consequence));
+ var s = NewState(c);
+ s.ChosenOptions["parent"] = "road";
+ Assert.Equal(("parent", "road"), Timeline.Origin(c, s, c.Events.Single(x => x.Id == "after_road"))!.Value);
+ Assert.Null(Timeline.Origin(c, s, c.Events.Single(x => x.Id == "parent")));
+ }
}
diff --git a/sim/Statecraft.Sim.Tests/FinalWaveTests.cs b/sim/Statecraft.Sim.Tests/FinalWaveTests.cs
index a7d8a45e9..621917c13 100644
--- a/sim/Statecraft.Sim.Tests/FinalWaveTests.cs
+++ b/sim/Statecraft.Sim.Tests/FinalWaveTests.cs
@@ -76,6 +76,18 @@ public class FinalWaveTests
Assert.Equal(new[] { "b" }, ReleaseGate.SensitiveUnreviewed(ContentLoader.Load(reviewed)));
}
+ /// <summary>R-ALT-011: a consequence card or a variant needs a person's sign-off before a shareable build.</summary>
+ [Fact]
+ public void AShareableBuildNeedsEveryAlternateCardSignedOff()
+ {
+ Assert.Empty(ReleaseGate.AlternateUnsigned(Real));
+ var c = AlternateTimelineTests.Load(("parent.yaml", AlternateTimelineTests.Parent), ("after_road.yaml", AlternateTimelineTests.Consequence), ("outside.yaml", AlternateTimelineTests.Outside));
+ Assert.Equal(new[] { "after_road", "outside" }, ReleaseGate.AlternateUnsigned(c));
+ var signed = AlternateTimelineTests.Consequence + "status: fact-checked\nreviewed_by: a-reviewer\nreviewed_on: 2026-10-20\n";
+ var c2 = AlternateTimelineTests.Load(("parent.yaml", AlternateTimelineTests.Parent), ("after_road.yaml", signed));
+ Assert.Empty(ReleaseGate.AlternateUnsigned(c2));
+ }
+
// ---- M2: Cause text is derived output, deterministic ----
[Fact]
diff --git a/sim/Statecraft.Sim/ReleaseGate.cs b/sim/Statecraft.Sim/ReleaseGate.cs
index df8e2f405..64ed667b3 100644
--- a/sim/Statecraft.Sim/ReleaseGate.cs
+++ b/sim/Statecraft.Sim/ReleaseGate.cs
@@ -20,5 +20,11 @@ namespace Statecraft.Sim
public static IReadOnlyList<string> SensitiveUnreviewed(Content c) =>
c.Events.Where(e => e.Tags.Any(EventRules.SensitiveTags.Contains) && e.Status != ReviewedStatus)
.Select(e => e.Id).OrderBy(x => x, StringComparer.Ordinal).ToList();
+
+ /// <summary>R-ALT-011 (Q-ALT-9): every consequence card and every event with variants that no person has signed off
+ /// (no reviewed_by), in id order. A shareable build refuses while it is not empty.</summary>
+ public static IReadOnlyList<string> AlternateUnsigned(Content c) =>
+ c.Events.Where(e => (e.Kind == EventKinds.Consequence || e.Variants.Count > 0) && e.ReviewedBy == "")
+ .Select(e => e.Id).OrderBy(x => x, StringComparer.Ordinal).ToList();
}
}
diff --git a/sim/Statecraft.Sim/Timeline.cs b/sim/Statecraft.Sim/Timeline.cs
index 8a08fb98e..99350d3c6 100644
--- a/sim/Statecraft.Sim/Timeline.cs
+++ b/sim/Statecraft.Sim/Timeline.cs
@@ -1,3 +1,5 @@
+using System;
+using System.Collections.Generic;
using System.Linq;
namespace Statecraft.Sim
@@ -40,5 +42,34 @@ namespace Statecraft.Sim
/// <summary>R-ALT-010: the first variant, in file order, whose every `when` entry holds; null for the event's own text.</summary>
public static EventVariant? Variant(Content c, GameState s, GameEvent e) =>
e.Variants.FirstOrDefault(v => v.When.All(r => Met(c, s, r)));
+
+ /// <summary>One row of the timeline screen: the player's answer beside the record's.</summary>
+ public sealed class TimelineEntry
+ {
+ public TimelineEntry(string ev, string chosen, string historical, bool diverged, string rejoinedBy)
+ { Event = ev; Chosen = chosen; Historical = historical; Diverged = diverged; RejoinedBy = rejoinedBy; }
+ public string Event { get; } public string Chosen { get; } public string Historical { get; }
+ public bool Diverged { get; } public string RejoinedBy { get; }
+ }
+
+ /// <summary>R-ALT-011: every resolved event, by window start then ordinal id. <c>Historical</c> is empty for an event
+ /// with no historical option; <c>RejoinedBy</c> is the consequence card whose option rejoined it, or empty.</summary>
+ public static IReadOnlyList<TimelineEntry> Entries(Content c, GameState s) =>
+ c.Events.Where(e => s.ChosenOptions.ContainsKey(e.Id))
+ .OrderBy(e => e.From).ThenBy(e => e.Id, StringComparer.Ordinal)
+ .Select(e => new TimelineEntry(e.Id, s.ChosenOptions[e.Id], HistoricalOption(e)?.Id ?? "", Diverged(c, s, e.Id),
+ c.Events.Where(k => k.Kind == EventKinds.Consequence && s.ChosenOptions.TryGetValue(k.Id, out var o)
+ && k.Options.Any(x => x.Id == o && x.Rejoin == e.Id))
+ .Select(k => k.Id).OrderBy(x => x, StringComparer.Ordinal).FirstOrDefault() ?? ""))
+ .ToList();
+
+ /// <summary>R-ALT-011: the road a consequence card follows, as the player took it: the first requirement that names a
+ /// road not taken, with the option chosen there. Null for any other event.</summary>
+ public static (string Event, string Option)? Origin(Content c, GameState s, GameEvent card)
+ {
+ if (card.Kind != EventKinds.Consequence) return null;
+ var r = card.Requires.First(x => EventRules.IsAlternativeRoad(c, x));
+ return (r.Event, s.ChosenOptions.TryGetValue(r.Event, out var o) ? o : r.Option);
+ }
}
}