uro-cli 0.17.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.17.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.17.0
16
- Requires-Dist: uro-server==0.17.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.17.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.17.0",
17
- "uro-server==0.17.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,7 +18,7 @@ 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 BeatResult, 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
@@ -212,6 +212,31 @@ def db_migrate() -> None:
212
212
  _run_async(_run)
213
213
 
214
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
+
215
240
  @world_app.command("new")
216
241
  def world_new(
217
242
  name: str,
@@ -331,10 +356,10 @@ def world_seed(
331
356
  None, "--world", help="the world to seed (id or name; default: the pack's name)"
332
357
  ),
333
358
  ) -> None:
334
- """Run History seeding on the world imported from <path>: layer a seed-dependent past (power
335
- groups, their leaders and conflicts, in the pack's [history.vocabulary]) on top of the authored
336
- geography (docs/09). Same pack + a different seed → a different history on identical
337
- 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."""
338
363
 
339
364
  async def _run() -> None:
340
365
  from uro_core.errors import PackError
@@ -545,13 +570,25 @@ def play(
545
570
  continue
546
571
  try:
547
572
  results: list[BeatResult] = []
573
+ mechanics: list[BeatMechanics] = []
548
574
  async for chunk in engine.run_beat_stream(
549
- campaign, PARTICIPANT, intent, on_result=results.append
575
+ campaign,
576
+ PARTICIPANT,
577
+ intent,
578
+ on_result=results.append,
579
+ on_mechanics=mechanics.append,
550
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)
551
586
  sys.stdout.write(chunk)
552
587
  sys.stdout.flush()
553
588
  sys.stdout.write("\n")
554
- for line in beat_detail_lines(_details(results[0]) if results else {}, day):
589
+ for line in beat_detail_lines(
590
+ _details(results[0]) if results else {}, day, mechanics_shown=True
591
+ ):
555
592
  typer.echo(line)
556
593
  if results:
557
594
  day = results[0].world_day
@@ -572,21 +609,36 @@ def _details(result: BeatResult) -> dict[str, Any]:
572
609
  "mode": result.mode,
573
610
  "world_day": result.world_day,
574
611
  "created": [c.model_dump() for c in result.created],
612
+ "threads_changed": [t.model_dump() for t in result.threads_changed],
575
613
  }
576
614
 
577
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
+
578
625
  def beat_detail_lines(
579
- details: dict[str, Any], previous_day: int | None, *, mine: bool = True
626
+ details: dict[str, Any],
627
+ previous_day: int | None,
628
+ *,
629
+ mine: bool = True,
630
+ mechanics_shown: bool = False,
580
631
  ) -> list[str]:
581
632
  """What `uro play` and `uro connect` show under a beat (D-98): each check's outcome, a
582
633
  fight, the day (when it moved, or first seen), what the beat made, and — under the player's
583
634
  OWN beat only — the planner's suggestions (in a party they belong to whoever acted)."""
584
- lines = [f" · {c['affordance']}: {c['outcome']}" for c in details.get("checks") or []]
585
- if details.get("mode") == "encounter":
586
- lines.append(" · a fight was resolved")
635
+ lines = [] if mechanics_shown else mechanics_lines(details)
587
636
  day = details.get("world_day")
588
637
  if day is not None and day != previous_day:
589
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']}")
590
642
  created = details.get("created") or []
591
643
  if created:
592
644
  lines.append(" + new: " + ", ".join(f"{c['name']} ({c['kind']})" for c in created))
@@ -795,6 +847,7 @@ def connect(
795
847
  pending: dict[str, tuple[str, asyncio.Event]] = {}
796
848
  echoes = False
797
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
798
851
 
799
852
  def settle(msg: dict[str, Any]) -> None:
800
853
  if "intent_id" in msg:
@@ -824,9 +877,18 @@ def connect(
824
877
  settle(msg)
825
878
  if kind == "narration_chunk":
826
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)
827
884
  elif kind == "beat_committed":
828
885
  typer.echo(f"\n ✓ [{msg['participant_id']}] {msg['intent']!r}")
829
- for line in beat_detail_lines(msg, seen_day, mine=ours):
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
+ ):
830
892
  typer.echo(line)
831
893
  seen_day = msg.get("world_day", seen_day)
832
894
  typer.echo("")
@@ -1462,9 +1524,10 @@ def calls(
1462
1524
 
1463
1525
  @ruleset_app.command("list")
1464
1526
  def ruleset_list() -> None:
1465
- """The rulesets a world can declare (`[ruleset] id` in world.toml): the built-ins and installed
1466
- plugins (D-65), each with the settings a game may give it under `[ruleset.config]` and their
1467
- 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."""
1468
1531
  for rid in registry.available():
1469
1532
  try: # one plugin's fault (e.g. a setting with no default) must not hide the rest
1470
1533
  rs = registry.resolve(rid)
@@ -1633,10 +1696,43 @@ def campaign_delete(
1633
1696
  _run_async(_run)
1634
1697
 
1635
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
+
1636
1732
  @campaign_app.command("pacing")
1637
1733
  def campaign_pacing(campaign_id: str) -> None:
1638
1734
  """Which live plots have gone quiet, and the one the next beat would name to the narrator
1639
- (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)."""
1640
1736
 
1641
1737
  async def _run() -> None:
1642
1738
  from uro_core.pipeline.pacing import pacing_report
@@ -1660,7 +1756,8 @@ def campaign_pacing(campaign_id: str) -> None:
1660
1756
  for t in sorted(report.threads, key=lambda t: (-t.quiet_beats, t.thread_id)):
1661
1757
  quiet = f"{t.quiet_beats}{'+' if t.at_least else ''}"
1662
1758
  mark = " ← next" if t.thread_id == report.next_paced else ""
1663
- 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}")
1664
1761
 
1665
1762
  _run_async(_run)
1666
1763
 
@@ -1711,8 +1808,18 @@ def campaign_new(
1711
1808
  seed: int = typer.Option(
1712
1809
  0, "--seed", help="mechanics RNG seed (docs/18 G-3) — pin it for reproducible combat"
1713
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
+ ),
1714
1820
  ) -> None:
1715
- """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)."""
1716
1823
 
1717
1824
  async def _run() -> None:
1718
1825
  if (adopt is None) == (pc is None):
@@ -1726,34 +1833,55 @@ def campaign_new(
1726
1833
  if b is None:
1727
1834
  typer.echo(f"no such branch: {branch}", err=True)
1728
1835
  raise typer.Exit(1)
1729
- # Bind the WORLD's declared ruleset (docs/06, D-30): a PbtA world's campaign is
1730
- # played under uro_pbta, not the hard-coded default. ('' → registry default.)
1731
- pin = await store.world_ruleset(b.branch_id)
1732
- rs = await registry.resolve_for_branch(store, b.branch_id) # with the world's settings
1733
- # Every PC needs a sheet so the mechanics gate can check it. A fresh PC gets one; an
1734
- # adopted actor is sheeted only if it lacks one (a re-adopted PC keeps its sheet).
1735
- pc_sheet = None
1736
- if pc is not None or (
1737
- adopt is not None and await store.get_sheet(b.branch_id, adopt) is None
1738
- ):
1739
- pc_sheet = _build_pc_sheet(rs)
1740
- ruleset_id = rs.id
1741
- campaign = await store.start_campaign(
1742
- w.world_id,
1743
- b.branch_id,
1744
- participant_id=participant,
1745
- adopt_actor_id=adopt,
1746
- new_pc_name=pc,
1747
- pc_sheet=pc_sheet,
1748
- starting_items=await starting_gear(store, b.branch_id) if pc is not None else None,
1749
- ruleset_id=ruleset_id,
1750
- ruleset_version=pin.version,
1751
- seed=seed,
1752
- )
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
1753
1881
  finally:
1754
1882
  await store.close()
1755
1883
  who = f"adopted {adopt}" if adopt else f"new PC {pc!r}"
1756
- typer.echo(f"campaign: {campaign.campaign_id} (branch {branch!r}, {who})")
1884
+ typer.echo(f"campaign: {campaign.campaign_id} (branch {b.name!r}, {who})")
1757
1885
  typer.echo(f"play it: uro play {campaign.campaign_id}")
1758
1886
 
1759
1887
  _run_async(_run)
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes