uro-cli 0.16.0__tar.gz → 0.18.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: uro-cli
3
- Version: 0.16.0
3
+ Version: 0.18.0
4
4
  Summary: Uro Engine reference client — play, dry-run, and dev tools against the engine
5
5
  Project-URL: Homepage, https://github.com/cupskeee/uro
6
6
  Project-URL: Repository, https://github.com/cupskeee/uro
@@ -12,8 +12,8 @@ Requires-Python: >=3.12
12
12
  Requires-Dist: python-dotenv>=1.0
13
13
  Requires-Dist: rich>=13.9
14
14
  Requires-Dist: typer>=0.27.2
15
- Requires-Dist: uro-core[llm,postgres]==0.16.0
16
- Requires-Dist: uro-server==0.16.0
15
+ Requires-Dist: uro-core[llm,postgres]==0.18.0
16
+ Requires-Dist: uro-server==0.18.0
17
17
  Requires-Dist: websockets>=16.1
18
18
  Description-Content-Type: text/markdown
19
19
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "uro-cli"
3
- version = "0.16.0"
3
+ version = "0.18.0"
4
4
  description = "Uro Engine reference client — play, dry-run, and dev tools against the engine"
5
5
  license = "MIT"
6
6
  license-files = ["LICENSE"]
@@ -13,8 +13,8 @@ requires-python = ">=3.12"
13
13
  # pair a new uro-cli with an old uro-core; `just release` bumps all three together, and the
14
14
  # `{workspace = true}` sources make a drifted pin fail `uv sync` locally.
15
15
  dependencies = [
16
- "uro-core[postgres,llm]==0.16.0",
17
- "uro-server==0.16.0",
16
+ "uro-core[postgres,llm]==0.18.0",
17
+ "uro-server==0.18.0",
18
18
  "typer>=0.27.2",
19
19
  "rich>=13.9",
20
20
  "websockets>=16.1",
@@ -180,3 +180,18 @@ def test_token_revoke_by_participant_and_list(monkeypatch) -> None: # type: ign
180
180
  app, ["token", "revoke", "c1", "--participant", "bob", "--target", "t", "--token", "op"]
181
181
  )
182
182
  assert both.exit_code == 1
183
+
184
+
185
+ def test_help_keeps_bracketed_names() -> None:
186
+ # Typer renders help with Rich, which takes `[pacing]` for a markup tag and drops it: the help
187
+ # read "off unless the world's `` turns it on". Escaped, the names survive.
188
+ from typer.testing import CliRunner
189
+ from uro_cli.main import app
190
+
191
+ for args, name in (
192
+ (["campaign", "pacing", "--help"], "[pacing]"),
193
+ (["world", "seed", "--help"], "[history.vocabulary]"),
194
+ (["ruleset", "list", "--help"], "[ruleset.config]"),
195
+ ):
196
+ out = CliRunner().invoke(app, args, env={"COLUMNS": "200"}).output
197
+ assert name in out, (args, out)
@@ -18,13 +18,14 @@ from typing import Any
18
18
  import typer
19
19
  from dotenv import find_dotenv, load_dotenv
20
20
  from uro_core.adapters.postgres.store import PostgresEventStore
21
- from uro_core.pipeline.engine import Engine
21
+ from uro_core.pipeline.engine import BeatMechanics, BeatResult, Engine
22
22
  from uro_core.ports.model_registry import ROLES
23
23
  from uro_core.providers.router import ProviderRouter
24
24
  from uro_core.rulesets import registry
25
25
  from uro_core.rulesets.base import CharSpec, Ruleset
26
26
  from uro_core.rulesets.rng import Rng
27
- from uro_core.timeline.models import FORK_TIME_SKIP, STARTING_GEAR, World
27
+ from uro_core.timeline.gear import starting_gear
28
+ from uro_core.timeline.models import FORK_TIME_SKIP, World
28
29
 
29
30
  from uro_cli.wiring import (
30
31
  build_router,
@@ -211,12 +212,38 @@ def db_migrate() -> None:
211
212
  _run_async(_run)
212
213
 
213
214
 
215
+ @db_app.command("rebuild-projections")
216
+ def db_rebuild_projections(
217
+ world: str = typer.Option(None, "--world", help="one world (name or id); default: every world"),
218
+ ) -> None:
219
+ """Rebuild projections from history (D-102): after `uro db migrate` adds a projection column
220
+ (027: each thread's development and beat counts), so campaigns played before it count their
221
+ whole past. Drops the world's snapshots (a cache) and replays each branch. Run it while the
222
+ world isn't being played."""
223
+
224
+ async def _run() -> None:
225
+ store = build_store()
226
+ await connect_store(store)
227
+ try:
228
+ world_id = (await _world_or_exit(store, world)).world_id if world else None
229
+ done = await store.rebuild_projections(world_id)
230
+ finally:
231
+ await store.close()
232
+ typer.echo(
233
+ f"rebuilt {done['branches']} branches in {done['worlds']} worlds "
234
+ f"({done['snapshots_dropped']} snapshots dropped; new ones form as play goes on)"
235
+ )
236
+
237
+ _run_async(_run)
238
+
239
+
214
240
  @world_app.command("new")
215
241
  def world_new(
216
242
  name: str,
217
243
  ruleset: str = typer.Option(
218
244
  "", "--ruleset", help="a built-in ruleset id (`uro ruleset list`); default uro-basic"
219
245
  ),
246
+ pc: str = typer.Option("Player", "--pc", help="the player character's name"),
220
247
  ) -> None:
221
248
  """Create a world (+ its main branch) and a ready-to-play campaign with a default,
222
249
  sheeted PC. Prints the campaign id."""
@@ -232,15 +259,15 @@ def world_new(
232
259
  world.world_id,
233
260
  world.main_branch_id,
234
261
  participant_id=PARTICIPANT,
235
- new_pc_name="Adventurer",
262
+ new_pc_name=pc,
236
263
  pc_sheet=sheet,
237
- starting_items=list(STARTING_GEAR),
264
+ starting_items=await starting_gear(store, world.main_branch_id),
238
265
  ruleset_id=ruleset_id,
239
266
  )
240
267
  finally:
241
268
  await store.close()
242
269
  typer.echo(f"world: {world.world_id} ({name})")
243
- typer.echo(f"campaign: {campaign.campaign_id} (PC: Adventurer)")
270
+ typer.echo(f"campaign: {campaign.campaign_id} (PC: {pc})")
244
271
  typer.echo(f"\nplay it: uro play {campaign.campaign_id}")
245
272
 
246
273
  _run_async(_run)
@@ -315,7 +342,8 @@ def world_create(
315
342
  typer.echo(f"world: {world.world_id} ({world.name}, grade {result.grade})")
316
343
  for a in result.backfilled:
317
344
  typer.echo(f" backfilled + committed: {a}")
318
- typer.echo(f"seed history: uro world seed {path} --seed 42")
345
+ if pack.manifest.history.vocabulary is not None: # D-97: seeding speaks the pack's words
346
+ typer.echo(f"seed history: uro world seed {path} --seed 42")
319
347
 
320
348
  _run_async(_run)
321
349
 
@@ -328,9 +356,10 @@ def world_seed(
328
356
  None, "--world", help="the world to seed (id or name; default: the pack's name)"
329
357
  ),
330
358
  ) -> None:
331
- """Run History seeding on the world imported from <path>: layer seed-dependent dynasties and
332
- wars on top of the authored geography (docs/09). Same pack + a different seed → a different
333
- history on identical geography."""
359
+ """Run History seeding on the world imported from <path>: layer a seed-dependent past
360
+ (power groups, their leaders and conflicts, in the pack's \\[history.vocabulary]) on top of
361
+ the authored geography (docs/09). Same pack + a different seed → a different history on
362
+ identical geography."""
334
363
 
335
364
  async def _run() -> None:
336
365
  from uro_core.errors import PackError
@@ -350,7 +379,8 @@ def world_seed(
350
379
  await store.close()
351
380
  typer.echo(f"seeded {target.name!r} with seed {seed} → commit {result.commit_id}")
352
381
  typer.echo(
353
- f" {result.dynasties} dynasties, {result.wars} wars (on the pack's authored geography)"
382
+ f" {result.groups} power groups, {result.wars} conflicts "
383
+ "(on the pack's authored geography)"
354
384
  )
355
385
 
356
386
  _run_async(_run)
@@ -526,6 +556,7 @@ def play(
526
556
  typer.echo(f" > {beat.intent_text}")
527
557
  typer.echo(f" {beat.narration}")
528
558
  typer.echo("—")
559
+ day: int | None = await store.current_world_time(campaign.branch_id)
529
560
 
530
561
  while True:
531
562
  try:
@@ -538,10 +569,29 @@ def play(
538
569
  if not intent:
539
570
  continue
540
571
  try:
541
- async for chunk in engine.run_beat_stream(campaign, PARTICIPANT, intent):
572
+ results: list[BeatResult] = []
573
+ mechanics: list[BeatMechanics] = []
574
+ async for chunk in engine.run_beat_stream(
575
+ campaign,
576
+ PARTICIPANT,
577
+ intent,
578
+ on_result=results.append,
579
+ on_mechanics=mechanics.append,
580
+ ):
581
+ if mechanics: # the rules' answer, before the story (D-100)
582
+ m = mechanics.pop()
583
+ checks = [c.model_dump() for c in m.outcomes]
584
+ for line in mechanics_lines({"checks": checks, "mode": m.mode}):
585
+ typer.echo(line)
542
586
  sys.stdout.write(chunk)
543
587
  sys.stdout.flush()
544
588
  sys.stdout.write("\n")
589
+ for line in beat_detail_lines(
590
+ _details(results[0]) if results else {}, day, mechanics_shown=True
591
+ ):
592
+ typer.echo(line)
593
+ if results:
594
+ day = results[0].world_day
545
595
  except Exception as exc:
546
596
  sys.stdout.write("\n")
547
597
  typer.echo(f"beat failed ({exc}); nothing was saved — try again.", err=True)
@@ -551,6 +601,53 @@ def play(
551
601
  _run_async(_run)
552
602
 
553
603
 
604
+ def _details(result: BeatResult) -> dict[str, Any]:
605
+ """A local beat's details in the shape `beat_committed` carries them (D-98)."""
606
+ return {
607
+ "checks": [c.model_dump() for c in result.outcomes],
608
+ "suggestions": result.suggestions,
609
+ "mode": result.mode,
610
+ "world_day": result.world_day,
611
+ "created": [c.model_dump() for c in result.created],
612
+ "threads_changed": [t.model_dump() for t in result.threads_changed],
613
+ }
614
+
615
+
616
+ def mechanics_lines(details: dict[str, Any]) -> list[str]:
617
+ """Each check's outcome and a fight — what the rules decided (shown before the narration
618
+ when the server sends `beat_checks`, D-100)."""
619
+ lines = [f" · {c['affordance']}: {c['outcome']}" for c in details.get("checks") or []]
620
+ if details.get("mode") == "encounter":
621
+ lines.append(" · a fight was resolved")
622
+ return lines
623
+
624
+
625
+ def beat_detail_lines(
626
+ details: dict[str, Any],
627
+ previous_day: int | None,
628
+ *,
629
+ mine: bool = True,
630
+ mechanics_shown: bool = False,
631
+ ) -> list[str]:
632
+ """What `uro play` and `uro connect` show under a beat (D-98): each check's outcome, a
633
+ fight, the day (when it moved, or first seen), what the beat made, and — under the player's
634
+ OWN beat only — the planner's suggestions (in a party they belong to whoever acted)."""
635
+ lines = [] if mechanics_shown else mechanics_lines(details)
636
+ day = details.get("world_day")
637
+ if day is not None and day != previous_day:
638
+ lines.append(f" · day {day}")
639
+ for t in details.get("threads_changed") or []: # D-103: any plot whose state moved
640
+ moved = f"{t['from_state']} → {t['to_state']}" if t["from_state"] else t["to_state"]
641
+ lines.append(f" ~ plot {moved}: {t['stakes']}")
642
+ created = details.get("created") or []
643
+ if created:
644
+ lines.append(" + new: " + ", ".join(f"{c['name']} ({c['kind']})" for c in created))
645
+ suggestions = details.get("suggestions") or []
646
+ if suggestions and mine:
647
+ lines.append(" ? you could: " + "; ".join(suggestions))
648
+ return lines
649
+
650
+
554
651
  @app.command()
555
652
  def serve(
556
653
  host: str = typer.Option("127.0.0.1", help="bind address"),
@@ -749,6 +846,8 @@ def connect(
749
846
  # without an id is another client's.
750
847
  pending: dict[str, tuple[str, asyncio.Event]] = {}
751
848
  echoes = False
849
+ seen_day: int | None = None # the day the last beat_committed showed
850
+ checked: set[str] = set() # intents whose beat_checks were already printed
752
851
 
753
852
  def settle(msg: dict[str, Any]) -> None:
754
853
  if "intent_id" in msg:
@@ -763,17 +862,36 @@ def connect(
763
862
  hit[1].set()
764
863
 
765
864
  async def receive() -> None:
766
- nonlocal echoes
865
+ nonlocal echoes, seen_day
767
866
  async for raw in ws:
768
867
  msg = json.loads(raw)
769
868
  kind = msg.get("type")
770
869
  echoes = echoes or "intent_id" in msg
870
+ # one of OUR intents? (decided before settle() pops it)
871
+ ours = (
872
+ str(msg["intent_id"]) in pending
873
+ if "intent_id" in msg
874
+ else any(t == msg.get("intent") for t, _ in pending.values())
875
+ )
771
876
  if kind in settles:
772
877
  settle(msg)
773
878
  if kind == "narration_chunk":
774
879
  typer.echo(msg["text"], nl=False)
880
+ elif kind == "beat_checks": # what the rules decided, first (D-100)
881
+ checked.add(str(msg.get("intent_id", msg.get("intent"))))
882
+ for line in mechanics_lines(msg):
883
+ typer.echo(line)
775
884
  elif kind == "beat_committed":
776
- typer.echo(f"\n ✓ [{msg['participant_id']}] {msg['intent']!r}\n")
885
+ typer.echo(f"\n ✓ [{msg['participant_id']}] {msg['intent']!r}")
886
+ key = str(msg.get("intent_id", msg.get("intent")))
887
+ shown = key in checked
888
+ checked.discard(key)
889
+ for line in beat_detail_lines(
890
+ msg, seen_day, mine=ours, mechanics_shown=shown
891
+ ):
892
+ typer.echo(line)
893
+ seen_day = msg.get("world_day", seen_day)
894
+ typer.echo("")
777
895
  elif kind == "not_your_turn":
778
896
  typer.echo(" · not your turn — another player holds it (round-robin)")
779
897
  elif kind == "proposal_opened":
@@ -1406,9 +1524,10 @@ def calls(
1406
1524
 
1407
1525
  @ruleset_app.command("list")
1408
1526
  def ruleset_list() -> None:
1409
- """The rulesets a world can declare (`[ruleset] id` in world.toml): the built-ins and installed
1410
- plugins (D-65), each with the settings a game may give it under `[ruleset.config]` and their
1411
- defaults (D-62). A plugin that can't be used is listed with the reason."""
1527
+ """The rulesets a world can declare (`\\[ruleset] id` in world.toml): the built-ins and
1528
+ installed plugins (D-65), each with the settings a game may give it under
1529
+ `\\[ruleset.config]` and their defaults (D-62). A plugin that can't be used is listed with
1530
+ the reason."""
1412
1531
  for rid in registry.available():
1413
1532
  try: # one plugin's fault (e.g. a setting with no default) must not hide the rest
1414
1533
  rs = registry.resolve(rid)
@@ -1486,10 +1605,134 @@ def campaign_show(campaign_id: str) -> None:
1486
1605
  _run_async(_run)
1487
1606
 
1488
1607
 
1608
+ def _print_removed(removed: dict[str, int]) -> None:
1609
+ kept = {k: v for k, v in removed.items() if v}
1610
+ typer.echo("removed: " + (", ".join(f"{v} {k}" for k, v in kept.items()) or "nothing"))
1611
+
1612
+
1613
+ def _confirm_or_exit(yes: bool, what: str) -> None:
1614
+ if not yes:
1615
+ typer.echo(
1616
+ f"this permanently deletes {what}; nothing can bring it back. Pass --yes.", err=True
1617
+ )
1618
+ raise typer.Exit(1)
1619
+
1620
+
1621
+ @world_app.command("delete")
1622
+ def world_delete(
1623
+ world: str,
1624
+ yes: bool = typer.Option(False, "--yes", help="confirm: the world is gone for good"),
1625
+ ) -> None:
1626
+ """Remove a world and everything it holds, for good (D-99): campaigns, branches, history,
1627
+ memories, its players' notes for it, and the model calls metered for it. A privacy wipe."""
1628
+
1629
+ async def _run() -> None:
1630
+ store = build_store()
1631
+ await connect_store(store)
1632
+ try:
1633
+ w = await _world_or_exit(store, world)
1634
+ _confirm_or_exit(yes, f"the world {w.name!r} ({w.world_id})")
1635
+ removed = await store.delete_world(w.world_id)
1636
+ finally:
1637
+ await store.close()
1638
+ _print_removed(removed)
1639
+
1640
+ _run_async(_run)
1641
+
1642
+
1643
+ @branch_app.command("delete")
1644
+ def branch_delete(
1645
+ world: str,
1646
+ branch: str,
1647
+ yes: bool = typer.Option(False, "--yes", help="confirm: the branch is gone for good"),
1648
+ ) -> None:
1649
+ """Remove a branch, its campaigns and the commits only it reaches (D-99); history it shares
1650
+ with other branches stays. A world's main branch can't be removed (remove the world)."""
1651
+
1652
+ async def _run() -> None:
1653
+ store = build_store()
1654
+ await connect_store(store)
1655
+ try:
1656
+ w = await _world_or_exit(store, world)
1657
+ b = await _branch_or_exit(store, w, branch)
1658
+ _confirm_or_exit(yes, f"the branch {b.name!r} of {w.name!r}")
1659
+ try:
1660
+ removed = await store.delete_branch(b.branch_id)
1661
+ except ValueError as exc:
1662
+ typer.echo(f"error: {exc}", err=True)
1663
+ raise typer.Exit(1) from exc
1664
+ finally:
1665
+ await store.close()
1666
+ _print_removed(removed)
1667
+
1668
+ _run_async(_run)
1669
+
1670
+
1671
+ @campaign_app.command("delete")
1672
+ def campaign_delete(
1673
+ campaign_id: str,
1674
+ yes: bool = typer.Option(False, "--yes", help="confirm: the campaign is gone for good"),
1675
+ ) -> None:
1676
+ """Remove a campaign and its branch (D-99). Refused for a campaign on its world's main branch
1677
+ (remove the world) or on a branch other campaigns share (remove the branch)."""
1678
+
1679
+ async def _run() -> None:
1680
+ from uro_core.timeline.removal import delete_campaign
1681
+
1682
+ store = build_store()
1683
+ await connect_store(store)
1684
+ try:
1685
+ c = await _campaign_or_exit(store, campaign_id)
1686
+ _confirm_or_exit(yes, f"the campaign {c.campaign_id} and its branch")
1687
+ try:
1688
+ removed = await delete_campaign(store, c.campaign_id)
1689
+ except ValueError as exc:
1690
+ typer.echo(f"error: {exc}", err=True)
1691
+ raise typer.Exit(1) from exc
1692
+ finally:
1693
+ await store.close()
1694
+ _print_removed(removed)
1695
+
1696
+ _run_async(_run)
1697
+
1698
+
1699
+ @campaign_app.command("thread-state")
1700
+ def campaign_thread_state(
1701
+ campaign_id: str,
1702
+ thread_id: str,
1703
+ state: str = typer.Argument(..., help="dormant | offered | active | resolved | dead"),
1704
+ ) -> None:
1705
+ """Move a plot through its lifecycle (D-102): one commit, then the world's rules react. Any
1706
+ thread, authored or made in play: when a plot opens, sleeps or ends is the game's call."""
1707
+
1708
+ async def _run() -> None:
1709
+ store = build_store()
1710
+ await connect_store(store)
1711
+ try:
1712
+ c = await _campaign_or_exit(store, campaign_id)
1713
+ # the world's rules need no LLM, so a stub router suffices (like `campaign time-skip`);
1714
+ # and no ruleset either: one that can't be built doesn't block moving a plot (review)
1715
+ ruleset = await _time_skip_ruleset(registry.resolve_for_campaign(store, c))
1716
+ engine = Engine(store, build_router("stub", None), ruleset=ruleset)
1717
+ try:
1718
+ commit = await engine.set_thread_state(c, thread_id, state)
1719
+ except KeyError as exc:
1720
+ typer.echo(f"no such thread on this campaign: {thread_id}", err=True)
1721
+ raise typer.Exit(1) from exc
1722
+ except ValueError as exc:
1723
+ typer.echo(f"error: {exc}", err=True)
1724
+ raise typer.Exit(1) from exc
1725
+ finally:
1726
+ await store.close()
1727
+ typer.echo(f"thread {thread_id} → {state} (commit {commit.commit_id})")
1728
+
1729
+ _run_async(_run)
1730
+
1731
+
1489
1732
  @campaign_app.command("pacing")
1490
1733
  def campaign_pacing(campaign_id: str) -> None:
1491
1734
  """Which live plots have gone quiet, and the one the next beat would name to the narrator
1492
- (the pacing director, D-95: off unless the world's `[pacing]` turns it on, D-96)."""
1735
+ (the pacing director, D-95: off unless the world's `\\[pacing]` turns it on, D-96)."""
1493
1736
 
1494
1737
  async def _run() -> None:
1495
1738
  from uro_core.pipeline.pacing import pacing_report
@@ -1513,7 +1756,8 @@ def campaign_pacing(campaign_id: str) -> None:
1513
1756
  for t in sorted(report.threads, key=lambda t: (-t.quiet_beats, t.thread_id)):
1514
1757
  quiet = f"{t.quiet_beats}{'+' if t.at_least else ''}"
1515
1758
  mark = " ← next" if t.thread_id == report.next_paced else ""
1516
- typer.echo(f" {quiet:>4} beats quiet [{t.thread_id}] {t.stakes}{mark}")
1759
+ life = f"developed {t.developments}, live {t.beats_live}" # D-102
1760
+ typer.echo(f" {quiet:>4} beats quiet [{t.thread_id}] {t.stakes} ({life}){mark}")
1517
1761
 
1518
1762
  _run_async(_run)
1519
1763
 
@@ -1564,8 +1808,18 @@ def campaign_new(
1564
1808
  seed: int = typer.Option(
1565
1809
  0, "--seed", help="mechanics RNG seed (docs/18 G-3) — pin it for reproducible combat"
1566
1810
  ),
1811
+ own_branch: bool = typer.Option(
1812
+ False, "--own-branch", help="a playthrough of its own: fork --branch and play there (D-100)"
1813
+ ),
1814
+ from_ref: str = typer.Option(
1815
+ None, "--from", help="with --own-branch: fork at this marker or commit, not the head"
1816
+ ),
1817
+ branch_name: str = typer.Option(
1818
+ None, "--branch-name", help="with --own-branch: the new branch's name (default play-…)"
1819
+ ),
1567
1820
  ) -> None:
1568
- """Start a campaign on a branch, binding a PC (adopt an existing actor, or create one)."""
1821
+ """Start a campaign on a branch, binding a PC (adopt an existing actor, or create one).
1822
+ With --own-branch it gets a branch of its own, so it can later be removed alone (D-99)."""
1569
1823
 
1570
1824
  async def _run() -> None:
1571
1825
  if (adopt is None) == (pc is None):
@@ -1579,34 +1833,55 @@ def campaign_new(
1579
1833
  if b is None:
1580
1834
  typer.echo(f"no such branch: {branch}", err=True)
1581
1835
  raise typer.Exit(1)
1582
- # Bind the WORLD's declared ruleset (docs/06, D-30): a PbtA world's campaign is
1583
- # played under uro_pbta, not the hard-coded default. ('' → registry default.)
1584
- pin = await store.world_ruleset(b.branch_id)
1585
- rs = await registry.resolve_for_branch(store, b.branch_id) # with the world's settings
1586
- # Every PC needs a sheet so the mechanics gate can check it. A fresh PC gets one; an
1587
- # adopted actor is sheeted only if it lacks one (a re-adopted PC keeps its sheet).
1588
- pc_sheet = None
1589
- if pc is not None or (
1590
- adopt is not None and await store.get_sheet(b.branch_id, adopt) is None
1591
- ):
1592
- pc_sheet = _build_pc_sheet(rs)
1593
- ruleset_id = rs.id
1594
- campaign = await store.start_campaign(
1595
- w.world_id,
1596
- b.branch_id,
1597
- participant_id=participant,
1598
- adopt_actor_id=adopt,
1599
- new_pc_name=pc,
1600
- pc_sheet=pc_sheet,
1601
- starting_items=list(STARTING_GEAR) if pc is not None else None,
1602
- ruleset_id=ruleset_id,
1603
- ruleset_version=pin.version,
1604
- seed=seed,
1605
- )
1836
+ if (from_ref is not None or branch_name is not None) and not own_branch:
1837
+ typer.echo("--from and --branch-name go with --own-branch", err=True)
1838
+ raise typer.Exit(1)
1839
+ if own_branch:
1840
+ from uro_core.timeline.playthrough import playthrough_branch
1841
+
1842
+ try:
1843
+ b = await playthrough_branch(
1844
+ store, w.world_id, b, from_ref=from_ref, name=branch_name
1845
+ )
1846
+ except (ValueError, KeyError) as exc:
1847
+ typer.echo(f"error: {exc}", err=True)
1848
+ raise typer.Exit(1) from exc
1849
+ try: # from here on, a failure removes the playthrough's fork (D-100 review)
1850
+ # Bind the WORLD's declared ruleset (docs/06, D-30): a PbtA world's campaign is
1851
+ # played under uro_pbta, not the hard-coded default. ('' → registry default.)
1852
+ pin = await store.world_ruleset(b.branch_id)
1853
+ # with the world's settings
1854
+ rs = await registry.resolve_for_branch(store, b.branch_id)
1855
+ # Every PC needs a sheet so the mechanics gate can check it. A fresh PC gets one; an
1856
+ # adopted actor is sheeted only if it lacks one (a re-adopted PC keeps its sheet).
1857
+ pc_sheet = None
1858
+ if pc is not None or (
1859
+ adopt is not None and await store.get_sheet(b.branch_id, adopt) is None
1860
+ ):
1861
+ pc_sheet = _build_pc_sheet(rs)
1862
+ ruleset_id = rs.id
1863
+ campaign = await store.start_campaign(
1864
+ w.world_id,
1865
+ b.branch_id,
1866
+ participant_id=participant,
1867
+ adopt_actor_id=adopt,
1868
+ new_pc_name=pc,
1869
+ pc_sheet=pc_sheet,
1870
+ starting_items=(
1871
+ await starting_gear(store, b.branch_id) if pc is not None else None
1872
+ ),
1873
+ ruleset_id=ruleset_id,
1874
+ ruleset_version=pin.version,
1875
+ seed=seed,
1876
+ )
1877
+ except BaseException:
1878
+ if own_branch: # nothing half-made: the playthrough's fork goes too
1879
+ await store.delete_branch(b.branch_id)
1880
+ raise
1606
1881
  finally:
1607
1882
  await store.close()
1608
1883
  who = f"adopted {adopt}" if adopt else f"new PC {pc!r}"
1609
- typer.echo(f"campaign: {campaign.campaign_id} (branch {branch!r}, {who})")
1884
+ typer.echo(f"campaign: {campaign.campaign_id} (branch {b.name!r}, {who})")
1610
1885
  typer.echo(f"play it: uro play {campaign.campaign_id}")
1611
1886
 
1612
1887
  _run_async(_run)
@@ -1737,7 +2012,9 @@ def campaign_join(
1737
2012
  adopt_actor_id=adopt,
1738
2013
  new_pc_name=pc,
1739
2014
  pc_sheet=pc_sheet,
1740
- starting_items=list(STARTING_GEAR) if pc is not None else None,
2015
+ starting_items=(
2016
+ await starting_gear(store, campaign.branch_id) if pc is not None else None
2017
+ ),
1741
2018
  ruleset_id=campaign.ruleset_id,
1742
2019
  )
1743
2020
  finally:
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes