feat(#61): named leaders — assassination / death / appointment with succession (v0.38.0)
CI / build + unit + e2e (pull_request) Successful in 2m33s
CI / build + unit + e2e (pull_request) Successful in 2m33s
Per-nation named leaders (Nation.leader) and a required TurnResult.leaders
lever ({ changes: [{ target, name, cause }] }). Each change sets the target
nation's leader and applies a deterministic stability dip by cause
(assassination -15, death -3, appointed 0) mirrored to its regions and
re-derived into its stats, plus a narration event (military for an
assassination, political for a death/appointment). An assassination/death
requires the target to already have a leader (a leaderless target is
dropped); an appointment always creates/sets one. Unknown/ambiguous targets
are dropped, never thrown.
- shared/types.ts: optional Nation.leader
- shared/protocol.ts: LeaderCause/LeaderChange/LeaderOps, LEADER_STABILITY_EFFECT,
TurnResult.leaders (required, between nuclear and markers), leader in nationForPrompt
- server/engine.ts: validateLeaderOps, applyLeaderChange, the applyTurnResult
leader block (after nuclear, before markers), isMeaningful, system-prompt
contract + constraint, validateTurnResult + runTurn fallback
- server/stub.ts: leaders always { changes: [] } (e2e unaffected)
- tests: 15 engine.test.ts leader tests + 2 db.test.ts round-trips
- version 0.37.0 -> 0.38.0, CHANGELOG entry
This commit is contained in:
@@ -468,6 +468,48 @@ export interface NuclearOps {
|
||||
strikes: NuclearStrike[];
|
||||
}
|
||||
|
||||
// --- Named leaders (v0.38, #61) -----------------------------------------------
|
||||
//
|
||||
// Each nation may have a single named leader (`Nation.leader`). The LLM changes
|
||||
// it each turn via `TurnResult.leaders`. A change names a target nation (id or
|
||||
// name) and the outcome: an `assassination` (a leader killed — a dramatic,
|
||||
// destabilizing blow), a `death` (a leader dies of natural causes — a quieter
|
||||
// succession), or an `appointed` leader (a neutral succession / new head of
|
||||
// state). The engine sets the nation's leader to the new name and applies a
|
||||
// DETERMINISTIC stability dip (see `LEADER_STABILITY_EFFECT` below) — no hidden
|
||||
// randomness. A change whose target has no current leader may only *appoint*
|
||||
// one (an assassination/death of a leaderless nation is dropped, not thrown).
|
||||
|
||||
/** How a nation's leader changed this turn (v0.38, #61). */
|
||||
export type LeaderCause = 'assassination' | 'death' | 'appointed';
|
||||
|
||||
/** A single leader change: the target nation, the new leader's name, the cause. */
|
||||
export interface LeaderChange {
|
||||
/** The target nation, by id or name (resolved by the shared resolver). */
|
||||
target: string;
|
||||
/** The new leader's name (the incoming / successor head of state). */
|
||||
name: string;
|
||||
/** What happened to the leader this turn. */
|
||||
cause: LeaderCause;
|
||||
}
|
||||
|
||||
/** The leader-ops block of a `TurnResult`. Required; default `{ changes: [] }`. */
|
||||
export interface LeaderOps {
|
||||
changes: LeaderChange[];
|
||||
}
|
||||
|
||||
/**
|
||||
* The deterministic stability effect of each leader-cause (v0.38, #61).
|
||||
* Assassination is the most destabilizing, a natural death a minor wobble, an
|
||||
* appointment is neutral. Applied to the target's `stability` (clamped 0–100),
|
||||
* mirrored to its `regionStats`, and its derived stats re-derived afterwards.
|
||||
*/
|
||||
export const LEADER_STABILITY_EFFECT: Record<LeaderCause, number> = {
|
||||
assassination: -15,
|
||||
death: -3,
|
||||
appointed: 0,
|
||||
};
|
||||
|
||||
// --- Nuclear / WMD effect math (v0.37, #60) ----------------------------------
|
||||
//
|
||||
// A nuclear strike is a DETERMINISTIC, devastating stat collapse — there is no
|
||||
@@ -637,6 +679,21 @@ export interface TurnResult {
|
||||
* never queued. Required; default `{ arm: [], strikes: [] }`.
|
||||
*/
|
||||
nuclear: NuclearOps;
|
||||
/**
|
||||
* (v0.38, #61) Leader changes this turn. Each change names a target nation
|
||||
* (id or name) and sets its leader to the new name, applying a deterministic
|
||||
* stability effect by cause: `assassination` (leader killed — a dramatic
|
||||
* −15 to the target's stability, a `military` event), `death` (natural
|
||||
* causes — a quieter −3 succession, a `political` event), or `appointed`
|
||||
* (a neutral 0 succession, a `political` event). An assassination/death
|
||||
* requires the target to already have a leader (a leaderless target is
|
||||
* dropped, never thrown); an appointment is always valid (it creates the
|
||||
* first leader). At most 1–2 per turn, each narrated in `events`. This is
|
||||
* the *leader* lever — heavier and more destabilizing than the lighter
|
||||
* `hybrid.assassinate` op (a −5 stability dip on a nation or region, with
|
||||
* no leader replacement). Required; default `{ changes: [] }`.
|
||||
*/
|
||||
leaders: LeaderOps;
|
||||
/**
|
||||
* (v0.27, #44) Map-marker ops this turn. `add` places new named markers
|
||||
* (the engine positions each at its region's centroid + a small
|
||||
@@ -949,6 +1006,7 @@ export function nationForPrompt(n: Nation) {
|
||||
stats: n.stats,
|
||||
territory: n.territory,
|
||||
relations: n.relations,
|
||||
leader: n.leader,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -80,6 +80,14 @@ export interface Nation {
|
||||
* `isNuclearCapable` in `protocol.ts`).
|
||||
*/
|
||||
nuclear?: boolean;
|
||||
/**
|
||||
* The nation's current named leader (v0.38, #61). Optional — a legacy game
|
||||
* (or a nation the LLM has never given a leader to) has none, which is the
|
||||
* "no leader" baseline. The LLM changes it via `TurnResult.leaders`
|
||||
* (assassination / death / appointment, see `LeaderChange` in `protocol.ts`);
|
||||
* each change carries a deterministic stability effect + a narration event.
|
||||
*/
|
||||
leader?: { name: string };
|
||||
}
|
||||
|
||||
/** Categories a narrative event can take. */
|
||||
|
||||
Reference in New Issue
Block a user