uro-cli 0.15.0__tar.gz → 0.17.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.15.0
3
+ Version: 0.17.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.15.0
16
- Requires-Dist: uro-server==0.15.0
15
+ Requires-Dist: uro-core[llm,postgres]==0.17.0
16
+ Requires-Dist: uro-server==0.17.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.15.0"
3
+ version = "0.17.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.15.0",
17
- "uro-server==0.15.0",
16
+ "uro-core[postgres,llm]==0.17.0",
17
+ "uro-server==0.17.0",
18
18
  "typer>=0.27.2",
19
19
  "rich>=13.9",
20
20
  "websockets>=16.1",
@@ -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 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,
@@ -217,6 +218,7 @@ def world_new(
217
218
  ruleset: str = typer.Option(
218
219
  "", "--ruleset", help="a built-in ruleset id (`uro ruleset list`); default uro-basic"
219
220
  ),
221
+ pc: str = typer.Option("Player", "--pc", help="the player character's name"),
220
222
  ) -> None:
221
223
  """Create a world (+ its main branch) and a ready-to-play campaign with a default,
222
224
  sheeted PC. Prints the campaign id."""
@@ -232,15 +234,15 @@ def world_new(
232
234
  world.world_id,
233
235
  world.main_branch_id,
234
236
  participant_id=PARTICIPANT,
235
- new_pc_name="Adventurer",
237
+ new_pc_name=pc,
236
238
  pc_sheet=sheet,
237
- starting_items=list(STARTING_GEAR),
239
+ starting_items=await starting_gear(store, world.main_branch_id),
238
240
  ruleset_id=ruleset_id,
239
241
  )
240
242
  finally:
241
243
  await store.close()
242
244
  typer.echo(f"world: {world.world_id} ({name})")
243
- typer.echo(f"campaign: {campaign.campaign_id} (PC: Adventurer)")
245
+ typer.echo(f"campaign: {campaign.campaign_id} (PC: {pc})")
244
246
  typer.echo(f"\nplay it: uro play {campaign.campaign_id}")
245
247
 
246
248
  _run_async(_run)
@@ -315,7 +317,8 @@ def world_create(
315
317
  typer.echo(f"world: {world.world_id} ({world.name}, grade {result.grade})")
316
318
  for a in result.backfilled:
317
319
  typer.echo(f" backfilled + committed: {a}")
318
- typer.echo(f"seed history: uro world seed {path} --seed 42")
320
+ if pack.manifest.history.vocabulary is not None: # D-97: seeding speaks the pack's words
321
+ typer.echo(f"seed history: uro world seed {path} --seed 42")
319
322
 
320
323
  _run_async(_run)
321
324
 
@@ -328,9 +331,10 @@ def world_seed(
328
331
  None, "--world", help="the world to seed (id or name; default: the pack's name)"
329
332
  ),
330
333
  ) -> 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."""
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."""
334
338
 
335
339
  async def _run() -> None:
336
340
  from uro_core.errors import PackError
@@ -350,7 +354,8 @@ def world_seed(
350
354
  await store.close()
351
355
  typer.echo(f"seeded {target.name!r} with seed {seed} → commit {result.commit_id}")
352
356
  typer.echo(
353
- f" {result.dynasties} dynasties, {result.wars} wars (on the pack's authored geography)"
357
+ f" {result.groups} power groups, {result.wars} conflicts "
358
+ "(on the pack's authored geography)"
354
359
  )
355
360
 
356
361
  _run_async(_run)
@@ -526,6 +531,7 @@ def play(
526
531
  typer.echo(f" > {beat.intent_text}")
527
532
  typer.echo(f" {beat.narration}")
528
533
  typer.echo("—")
534
+ day: int | None = await store.current_world_time(campaign.branch_id)
529
535
 
530
536
  while True:
531
537
  try:
@@ -538,10 +544,17 @@ def play(
538
544
  if not intent:
539
545
  continue
540
546
  try:
541
- async for chunk in engine.run_beat_stream(campaign, PARTICIPANT, intent):
547
+ results: list[BeatResult] = []
548
+ async for chunk in engine.run_beat_stream(
549
+ campaign, PARTICIPANT, intent, on_result=results.append
550
+ ):
542
551
  sys.stdout.write(chunk)
543
552
  sys.stdout.flush()
544
553
  sys.stdout.write("\n")
554
+ for line in beat_detail_lines(_details(results[0]) if results else {}, day):
555
+ typer.echo(line)
556
+ if results:
557
+ day = results[0].world_day
545
558
  except Exception as exc:
546
559
  sys.stdout.write("\n")
547
560
  typer.echo(f"beat failed ({exc}); nothing was saved — try again.", err=True)
@@ -551,6 +564,38 @@ def play(
551
564
  _run_async(_run)
552
565
 
553
566
 
567
+ def _details(result: BeatResult) -> dict[str, Any]:
568
+ """A local beat's details in the shape `beat_committed` carries them (D-98)."""
569
+ return {
570
+ "checks": [c.model_dump() for c in result.outcomes],
571
+ "suggestions": result.suggestions,
572
+ "mode": result.mode,
573
+ "world_day": result.world_day,
574
+ "created": [c.model_dump() for c in result.created],
575
+ }
576
+
577
+
578
+ def beat_detail_lines(
579
+ details: dict[str, Any], previous_day: int | None, *, mine: bool = True
580
+ ) -> list[str]:
581
+ """What `uro play` and `uro connect` show under a beat (D-98): each check's outcome, a
582
+ fight, the day (when it moved, or first seen), what the beat made, and — under the player's
583
+ 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")
587
+ day = details.get("world_day")
588
+ if day is not None and day != previous_day:
589
+ lines.append(f" · day {day}")
590
+ created = details.get("created") or []
591
+ if created:
592
+ lines.append(" + new: " + ", ".join(f"{c['name']} ({c['kind']})" for c in created))
593
+ suggestions = details.get("suggestions") or []
594
+ if suggestions and mine:
595
+ lines.append(" ? you could: " + "; ".join(suggestions))
596
+ return lines
597
+
598
+
554
599
  @app.command()
555
600
  def serve(
556
601
  host: str = typer.Option("127.0.0.1", help="bind address"),
@@ -592,14 +637,14 @@ def serve(
592
637
  None,
593
638
  "--cors-origin",
594
639
  help="allow a browser origin to call this server, e.g. --cors-origin http://localhost:5173 "
595
- "(repeatable). REQUIRED for the uro-loom web console (a cross-origin SPA); the browser "
640
+ "(repeatable). REQUIRED for a web console (a cross-origin SPA); the browser "
596
641
  "blocks calls with no CORS header. Pass '*' to allow any origin (dev only; disables "
597
642
  "credentials). Omit for CLI/embedded use.",
598
643
  ),
599
644
  ) -> None:
600
645
  """Run the Uro server (docs/08): a thin FastAPI shell over the engine. Each --token maps to
601
- a participant; with no --token, a single 'local' token binds player-1 (the solo dev loop, on
602
- 127.0.0.1 only: binding any other host needs --token).
646
+ a participant; with no --token and no --admin-token, a single 'local' token binds player-1 (the
647
+ solo dev loop, on 127.0.0.1 only: binding any other host needs --token).
603
648
 
604
649
  Each campaign plays under the ruleset it pinned, as with `uro play`: one server hosts d20,
605
650
  PbtA and Uro Pool campaigns side by side. `--ruleset` sets the default for unpinned ones."""
@@ -610,13 +655,16 @@ def serve(
610
655
 
611
656
  # The default 'local' token is a guessable name, fine on loopback (the solo dev loop) and
612
657
  # nowhere else: anyone who can reach a public bind could play as player-1 with it (D-94 review).
613
- if not token and host not in ("127.0.0.1", "localhost", "::1"):
658
+ if not token and not admin_token and host not in ("127.0.0.1", "localhost", "::1"):
614
659
  typer.echo(
615
- f"error: binding {host} needs --token: the default 'local' token is only for 127.0.0.1",
660
+ f"error: binding {host} needs --token or --admin-token: the default 'local' token is "
661
+ "only for 127.0.0.1",
616
662
  err=True,
617
663
  )
618
664
  raise typer.Exit(2)
619
- toks = token or ["local"]
665
+ # the default 'local' token is for a bare `uro serve` only: with an --admin-token given, adding
666
+ # it would quietly open a second, guessable credential beside the one asked for
667
+ toks = token or ([] if admin_token else ["local"])
620
668
  # `TOK=participant` names the participant explicitly (gap G-16 — token order was load-bearing
621
669
  # config); a bare `TOK` falls back to positional player-1..N.
622
670
  tokens: dict[str, str] = {}
@@ -653,7 +701,8 @@ def serve(
653
701
  "vote": VoteArbiter,
654
702
  }
655
703
  if arbiter_kind is None:
656
- arbiter: TurnArbiter | None = PartyArbiter() if len(tokens) > 1 else None
704
+ # a party is several PARTICIPANTS, not several tokens (two tokens for one player is solo)
705
+ arbiter: TurnArbiter | None = PartyArbiter() if len(set(tokens.values())) > 1 else None
657
706
  elif arbiter_kind not in shapes:
658
707
  raise typer.BadParameter(
659
708
  f"--arbiter must be one of {', '.join(shapes)} (got {arbiter_kind!r})"
@@ -745,6 +794,7 @@ def connect(
745
794
  # without an id is another client's.
746
795
  pending: dict[str, tuple[str, asyncio.Event]] = {}
747
796
  echoes = False
797
+ seen_day: int | None = None # the day the last beat_committed showed
748
798
 
749
799
  def settle(msg: dict[str, Any]) -> None:
750
800
  if "intent_id" in msg:
@@ -759,17 +809,27 @@ def connect(
759
809
  hit[1].set()
760
810
 
761
811
  async def receive() -> None:
762
- nonlocal echoes
812
+ nonlocal echoes, seen_day
763
813
  async for raw in ws:
764
814
  msg = json.loads(raw)
765
815
  kind = msg.get("type")
766
816
  echoes = echoes or "intent_id" in msg
817
+ # one of OUR intents? (decided before settle() pops it)
818
+ ours = (
819
+ str(msg["intent_id"]) in pending
820
+ if "intent_id" in msg
821
+ else any(t == msg.get("intent") for t, _ in pending.values())
822
+ )
767
823
  if kind in settles:
768
824
  settle(msg)
769
825
  if kind == "narration_chunk":
770
826
  typer.echo(msg["text"], nl=False)
771
827
  elif kind == "beat_committed":
772
- typer.echo(f"\n ✓ [{msg['participant_id']}] {msg['intent']!r}\n")
828
+ typer.echo(f"\n ✓ [{msg['participant_id']}] {msg['intent']!r}")
829
+ for line in beat_detail_lines(msg, seen_day, mine=ours):
830
+ typer.echo(line)
831
+ seen_day = msg.get("world_day", seen_day)
832
+ typer.echo("")
773
833
  elif kind == "not_your_turn":
774
834
  typer.echo(" · not your turn — another player holds it (round-robin)")
775
835
  elif kind == "proposal_opened":
@@ -1482,6 +1542,129 @@ def campaign_show(campaign_id: str) -> None:
1482
1542
  _run_async(_run)
1483
1543
 
1484
1544
 
1545
+ def _print_removed(removed: dict[str, int]) -> None:
1546
+ kept = {k: v for k, v in removed.items() if v}
1547
+ typer.echo("removed: " + (", ".join(f"{v} {k}" for k, v in kept.items()) or "nothing"))
1548
+
1549
+
1550
+ def _confirm_or_exit(yes: bool, what: str) -> None:
1551
+ if not yes:
1552
+ typer.echo(
1553
+ f"this permanently deletes {what}; nothing can bring it back. Pass --yes.", err=True
1554
+ )
1555
+ raise typer.Exit(1)
1556
+
1557
+
1558
+ @world_app.command("delete")
1559
+ def world_delete(
1560
+ world: str,
1561
+ yes: bool = typer.Option(False, "--yes", help="confirm: the world is gone for good"),
1562
+ ) -> None:
1563
+ """Remove a world and everything it holds, for good (D-99): campaigns, branches, history,
1564
+ memories, its players' notes for it, and the model calls metered for it. A privacy wipe."""
1565
+
1566
+ async def _run() -> None:
1567
+ store = build_store()
1568
+ await connect_store(store)
1569
+ try:
1570
+ w = await _world_or_exit(store, world)
1571
+ _confirm_or_exit(yes, f"the world {w.name!r} ({w.world_id})")
1572
+ removed = await store.delete_world(w.world_id)
1573
+ finally:
1574
+ await store.close()
1575
+ _print_removed(removed)
1576
+
1577
+ _run_async(_run)
1578
+
1579
+
1580
+ @branch_app.command("delete")
1581
+ def branch_delete(
1582
+ world: str,
1583
+ branch: str,
1584
+ yes: bool = typer.Option(False, "--yes", help="confirm: the branch is gone for good"),
1585
+ ) -> None:
1586
+ """Remove a branch, its campaigns and the commits only it reaches (D-99); history it shares
1587
+ with other branches stays. A world's main branch can't be removed (remove the world)."""
1588
+
1589
+ async def _run() -> None:
1590
+ store = build_store()
1591
+ await connect_store(store)
1592
+ try:
1593
+ w = await _world_or_exit(store, world)
1594
+ b = await _branch_or_exit(store, w, branch)
1595
+ _confirm_or_exit(yes, f"the branch {b.name!r} of {w.name!r}")
1596
+ try:
1597
+ removed = await store.delete_branch(b.branch_id)
1598
+ except ValueError as exc:
1599
+ typer.echo(f"error: {exc}", err=True)
1600
+ raise typer.Exit(1) from exc
1601
+ finally:
1602
+ await store.close()
1603
+ _print_removed(removed)
1604
+
1605
+ _run_async(_run)
1606
+
1607
+
1608
+ @campaign_app.command("delete")
1609
+ def campaign_delete(
1610
+ campaign_id: str,
1611
+ yes: bool = typer.Option(False, "--yes", help="confirm: the campaign is gone for good"),
1612
+ ) -> None:
1613
+ """Remove a campaign and its branch (D-99). Refused for a campaign on its world's main branch
1614
+ (remove the world) or on a branch other campaigns share (remove the branch)."""
1615
+
1616
+ async def _run() -> None:
1617
+ from uro_core.timeline.removal import delete_campaign
1618
+
1619
+ store = build_store()
1620
+ await connect_store(store)
1621
+ try:
1622
+ c = await _campaign_or_exit(store, campaign_id)
1623
+ _confirm_or_exit(yes, f"the campaign {c.campaign_id} and its branch")
1624
+ try:
1625
+ removed = await delete_campaign(store, c.campaign_id)
1626
+ except ValueError as exc:
1627
+ typer.echo(f"error: {exc}", err=True)
1628
+ raise typer.Exit(1) from exc
1629
+ finally:
1630
+ await store.close()
1631
+ _print_removed(removed)
1632
+
1633
+ _run_async(_run)
1634
+
1635
+
1636
+ @campaign_app.command("pacing")
1637
+ def campaign_pacing(campaign_id: str) -> None:
1638
+ """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)."""
1640
+
1641
+ async def _run() -> None:
1642
+ from uro_core.pipeline.pacing import pacing_report
1643
+
1644
+ store = build_store()
1645
+ await connect_store(store)
1646
+ try:
1647
+ c = await _campaign_or_exit(store, campaign_id)
1648
+ report = await pacing_report(store, c.branch_id)
1649
+ finally:
1650
+ await store.close()
1651
+ st = report.settings
1652
+ when = (
1653
+ "off (the world's [pacing] quiet_after turns it on)"
1654
+ if st.quiet_after == 0
1655
+ else f"names a plot quiet {st.quiet_after}+ beats, at most once every {st.every}"
1656
+ )
1657
+ typer.echo(f"pacing: {when} (over the last {report.beats_read} beats)")
1658
+ if not report.threads:
1659
+ typer.echo(" (no live threads)")
1660
+ for t in sorted(report.threads, key=lambda t: (-t.quiet_beats, t.thread_id)):
1661
+ quiet = f"{t.quiet_beats}{'+' if t.at_least else ''}"
1662
+ mark = " ← next" if t.thread_id == report.next_paced else ""
1663
+ typer.echo(f" {quiet:>4} beats quiet [{t.thread_id}] {t.stakes}{mark}")
1664
+
1665
+ _run_async(_run)
1666
+
1667
+
1485
1668
  @branch_app.command("diff")
1486
1669
  def branch_diff(
1487
1670
  world: str,
@@ -1562,7 +1745,7 @@ def campaign_new(
1562
1745
  adopt_actor_id=adopt,
1563
1746
  new_pc_name=pc,
1564
1747
  pc_sheet=pc_sheet,
1565
- starting_items=list(STARTING_GEAR) if pc is not None else None,
1748
+ starting_items=await starting_gear(store, b.branch_id) if pc is not None else None,
1566
1749
  ruleset_id=ruleset_id,
1567
1750
  ruleset_version=pin.version,
1568
1751
  seed=seed,
@@ -1701,7 +1884,9 @@ def campaign_join(
1701
1884
  adopt_actor_id=adopt,
1702
1885
  new_pc_name=pc,
1703
1886
  pc_sheet=pc_sheet,
1704
- starting_items=list(STARTING_GEAR) if pc is not None else None,
1887
+ starting_items=(
1888
+ await starting_gear(store, campaign.branch_id) if pc is not None else None
1889
+ ),
1705
1890
  ruleset_id=campaign.ruleset_id,
1706
1891
  )
1707
1892
  finally:
@@ -1851,7 +2036,7 @@ def codex_list(
1851
2036
 
1852
2037
 
1853
2038
  # --- Model-connection registry (D-47, docs/20) — direct-DB config of the LLM provider registry.
1854
- # A server API mirror (for uro-loom / remote clients) lands in the next slice; today these edit the
2039
+ # A server API mirror (for remote clients) lands in the next slice; today these edit the
1855
2040
  # instance's DB directly (operator with DB access), like `uro world`/`uro campaign`.
1856
2041
 
1857
2042
 
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes