@zergai/ztc 0.26.6-dev.202611240947 → 0.27.0-beta.1

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.
Files changed (268) hide show
  1. package/README.md +629 -167
  2. package/RUST_THIRD_PARTY_LICENSES.txt +5 -5
  3. package/bin/zmux-darwin-arm64 +0 -0
  4. package/bin/zmux-linux-x64 +0 -0
  5. package/bin/ztc-audio-darwin-arm64 +0 -0
  6. package/bin/ztc-capture-darwin-arm64 +0 -0
  7. package/bin/ztc-computer-darwin-arm64 +0 -0
  8. package/bin/ztc-llm-darwin-arm64 +0 -0
  9. package/bin/ztc-tts-darwin-arm64 +0 -0
  10. package/bin/ztc-tui-darwin-arm64 +0 -0
  11. package/bin/ztc-tui-linux-x64 +0 -0
  12. package/bin/zterm-darwin-arm64 +2 -2
  13. package/dist/App.js +6 -1
  14. package/dist/agent/agent.d.ts +21 -15
  15. package/dist/agent/agent.js +389 -163
  16. package/dist/agent/backends/codex_app_server.d.ts +7 -1
  17. package/dist/agent/backends/codex_app_server.js +11 -1
  18. package/dist/agent/backends/gemini.js +22 -8
  19. package/dist/agent/commands/batch.js +8 -0
  20. package/dist/agent/commands/config.js +10 -0
  21. package/dist/agent/commands/environment.js +5 -5
  22. package/dist/agent/commands/goal.d.ts +1 -0
  23. package/dist/agent/commands/goal.js +2 -1
  24. package/dist/agent/commands/index.js +2 -1
  25. package/dist/agent/commands/manifest.js +4 -0
  26. package/dist/agent/commands/optimize.js +5 -2
  27. package/dist/agent/commands/pane_cli.d.ts +29 -0
  28. package/dist/agent/commands/pane_cli.js +303 -0
  29. package/dist/agent/commands/settings.js +13 -3
  30. package/dist/agent/commands/shannon.js +8 -0
  31. package/dist/agent/commands/update.js +15 -3
  32. package/dist/agent/commands/zerg.js +31 -1
  33. package/dist/agent/commands/ztc_pane.js +3 -1
  34. package/dist/agent/factory.d.ts +4 -0
  35. package/dist/agent/factory.js +11 -1
  36. package/dist/agent/loop_policy.d.ts +42 -5
  37. package/dist/agent/loop_policy.js +206 -3
  38. package/dist/agent/runtime/command_jobs.d.ts +5 -0
  39. package/dist/agent/runtime/command_jobs.js +241 -31
  40. package/dist/agent/runtime/command_wait.d.ts +2 -0
  41. package/dist/agent/runtime/command_wait.js +1 -0
  42. package/dist/agent/runtime/done_report.d.ts +18 -0
  43. package/dist/agent/runtime/done_report.js +130 -0
  44. package/dist/agent/runtime/execution_context.js +4 -1
  45. package/dist/agent/runtime/failure_cause.d.ts +2 -0
  46. package/dist/agent/runtime/failure_cause.js +35 -0
  47. package/dist/agent/runtime/policy.d.ts +14 -2
  48. package/dist/agent/runtime/policy.js +104 -12
  49. package/dist/agent/runtime/quiet_job.d.ts +18 -0
  50. package/dist/agent/runtime/quiet_job.js +48 -0
  51. package/dist/agent/runtime/recovery.d.ts +1 -5
  52. package/dist/agent/runtime/recovery.js +2 -44
  53. package/dist/agent/runtime/tool_runtime.d.ts +1 -0
  54. package/dist/agent/runtime/tool_runtime.js +2 -0
  55. package/dist/agent/subagent.js +6 -1
  56. package/dist/agent/tools/deferred.js +1 -0
  57. package/dist/agent/tools/index.d.ts +2 -0
  58. package/dist/agent/tools/index.js +1 -0
  59. package/dist/agent/tools/outcome.d.ts +15 -0
  60. package/dist/agent/tools/outcome.js +107 -0
  61. package/dist/agent/tools/pane.d.ts +2 -1
  62. package/dist/agent/tools/pane.js +21 -3
  63. package/dist/agent/tools/registry.js +2 -0
  64. package/dist/agent/tools/shell.d.ts +1 -0
  65. package/dist/agent/tools/shell.js +128 -17
  66. package/dist/agent/tools/sim_domain_tools.js +4 -2
  67. package/dist/agent/tools/supervision.js +4 -2
  68. package/dist/agent/tools/types.d.ts +3 -0
  69. package/dist/app/command_context.js +5 -9
  70. package/dist/app/conversation_compaction.d.ts +4 -2
  71. package/dist/app/conversation_compaction.js +16 -5
  72. package/dist/app/headless_shell_mode.d.ts +14 -0
  73. package/dist/app/headless_shell_mode.js +7 -0
  74. package/dist/app/hosted_resident.d.ts +356 -0
  75. package/dist/app/hosted_resident.js +677 -0
  76. package/dist/app/restart.js +11 -2
  77. package/dist/app/session_manager.d.ts +5 -0
  78. package/dist/app/session_manager.js +21 -6
  79. package/dist/app/session_messages.js +6 -6
  80. package/dist/app/workspace_layout_controller.js +7 -0
  81. package/dist/batch/worktree.d.ts +10 -0
  82. package/dist/batch/worktree.js +15 -0
  83. package/dist/bench/registry.js +4 -2
  84. package/dist/cli_args.js +1 -1
  85. package/dist/cli_main.js +80 -10
  86. package/dist/cli_ratatui.d.ts +75 -0
  87. package/dist/cli_ratatui.js +485 -84
  88. package/dist/components/InputArea.js +4 -4
  89. package/dist/config/execution.d.ts +10 -0
  90. package/dist/config/execution.js +10 -0
  91. package/dist/config/hosted_runtime.d.ts +4 -1
  92. package/dist/config/hosted_runtime.js +4 -1
  93. package/dist/config/permission_pin.d.ts +34 -2
  94. package/dist/config/permission_pin.js +52 -2
  95. package/dist/config/person_command_policy.d.ts +38 -0
  96. package/dist/config/person_command_policy.js +11 -0
  97. package/dist/config/profiles.d.ts +21 -0
  98. package/dist/config/profiles.js +56 -2
  99. package/dist/config/types.d.ts +4 -1
  100. package/dist/config.js +34 -19
  101. package/dist/desktop/daily/codex_exec_adapter.js +7 -2
  102. package/dist/desktop/daily/desktop_wiring.d.ts +7 -1
  103. package/dist/desktop/daily/desktop_wiring.js +11 -3
  104. package/dist/desktop/daily/recipes.js +20 -4
  105. package/dist/desktop/health.d.ts +24 -0
  106. package/dist/desktop/health.js +151 -0
  107. package/dist/desktop/native_dialogs.d.ts +37 -0
  108. package/dist/desktop/native_dialogs.js +105 -0
  109. package/dist/diagnostics/session_export.d.ts +1 -0
  110. package/dist/diagnostics/session_export.js +28 -0
  111. package/dist/embedded/registry.js +4 -2
  112. package/dist/emulation/tool_adapters.js +9 -4
  113. package/dist/emulation/ztc_addendum.js +3 -0
  114. package/dist/headless.d.ts +11 -4
  115. package/dist/headless.js +99 -34
  116. package/dist/headless_approval.d.ts +6 -0
  117. package/dist/headless_cli.js +1 -1
  118. package/dist/hooks/runner.js +7 -6
  119. package/dist/library.d.ts +4 -0
  120. package/dist/library.js +3 -0
  121. package/dist/mcp/client.js +3 -3
  122. package/dist/modes/registry.js +13 -4
  123. package/dist/onboarding/setup_environment.js +13 -1
  124. package/dist/optimize/adapters/kernelbench.js +88 -10
  125. package/dist/optimize/adapters/types.d.ts +5 -0
  126. package/dist/optimize/executor.js +21 -0
  127. package/dist/panes/cli_install.d.ts +54 -0
  128. package/dist/panes/cli_install.js +157 -0
  129. package/dist/panes/model_catalog.js +3 -0
  130. package/dist/panes/new_pane_choices.d.ts +6 -2
  131. package/dist/panes/new_pane_choices.js +24 -12
  132. package/dist/panes/pane_cli_launch.d.ts +50 -0
  133. package/dist/panes/pane_cli_launch.js +124 -0
  134. package/dist/panes/pane_clis.d.ts +171 -0
  135. package/dist/panes/pane_clis.js +325 -0
  136. package/dist/panes/person_only_panes.d.ts +45 -0
  137. package/dist/panes/person_only_panes.js +117 -0
  138. package/dist/plugin/simulation_living.js +0 -2
  139. package/dist/plugin/simulation_living_engine.d.ts +1 -0
  140. package/dist/plugin/simulation_living_engine.js +1 -0
  141. package/dist/plugin/simulation_living_labels.d.ts +3 -0
  142. package/dist/plugin/simulation_living_labels.js +2 -0
  143. package/dist/router_auth.js +12 -1
  144. package/dist/session.js +26 -1
  145. package/dist/simulation/art/gemini_image.js +11 -5
  146. package/dist/simulation/domains/loader.js +25 -3
  147. package/dist/simulation/living/cold.d.ts +23 -0
  148. package/dist/simulation/living/cold.js +41 -0
  149. package/dist/simulation/living/context.d.ts +591 -1283
  150. package/dist/simulation/living/context.js +378 -244
  151. package/dist/simulation/living/contradictions.d.ts +14 -0
  152. package/dist/simulation/living/contradictions.js +282 -0
  153. package/dist/simulation/living/core/ids.d.ts +53 -0
  154. package/dist/simulation/living/core/ids.js +39 -0
  155. package/dist/simulation/living/core/kind.d.ts +20 -0
  156. package/dist/simulation/living/core/kind.js +15 -0
  157. package/dist/simulation/living/core/laws.d.ts +179 -0
  158. package/dist/simulation/living/core/laws.js +184 -0
  159. package/dist/simulation/living/core/ops.d.ts +257 -0
  160. package/dist/simulation/living/core/ops.js +34 -0
  161. package/dist/simulation/living/definer.d.ts +17 -1
  162. package/dist/simulation/living/definer.js +130 -51
  163. package/dist/simulation/living/definition.d.ts +174 -65
  164. package/dist/simulation/living/definition.js +287 -180
  165. package/dist/simulation/living/director.d.ts +80 -0
  166. package/dist/simulation/living/director.js +363 -0
  167. package/dist/simulation/living/frame.d.ts +108 -21
  168. package/dist/simulation/living/frame.js +111 -66
  169. package/dist/simulation/living/identifiers.d.ts +0 -1
  170. package/dist/simulation/living/identifiers.js +0 -3
  171. package/dist/simulation/living/index.d.ts +18 -9
  172. package/dist/simulation/living/index.js +18 -9
  173. package/dist/simulation/living/inference.d.ts +92 -50
  174. package/dist/simulation/living/inference.js +319 -175
  175. package/dist/simulation/living/knowledge.d.ts +28 -0
  176. package/dist/simulation/living/knowledge.js +73 -0
  177. package/dist/simulation/living/library.json +1177 -0
  178. package/dist/simulation/living/mechanics.d.ts +31 -34
  179. package/dist/simulation/living/mechanics.js +222 -138
  180. package/dist/simulation/living/model-input.d.ts +6 -3
  181. package/dist/simulation/living/model-input.js +18 -26
  182. package/dist/simulation/living/open-world.d.ts +74 -94
  183. package/dist/simulation/living/open-world.js +151 -30
  184. package/dist/simulation/living/phrases.d.ts +3 -0
  185. package/dist/simulation/living/phrases.js +37 -0
  186. package/dist/simulation/living/phrases.json +560 -0
  187. package/dist/simulation/living/projection.d.ts +316 -2
  188. package/dist/simulation/living/projection.js +50 -2
  189. package/dist/simulation/living/prompts/example-spec.json +11 -0
  190. package/dist/simulation/living/prompts/role-text.json +14 -0
  191. package/dist/simulation/living/prompts.d.ts +5 -0
  192. package/dist/simulation/living/prompts.js +275 -0
  193. package/dist/simulation/living/recall.d.ts +2 -2
  194. package/dist/simulation/living/reduce.d.ts +51 -14
  195. package/dist/simulation/living/reduce.js +941 -579
  196. package/dist/simulation/living/replay.d.ts +5 -4
  197. package/dist/simulation/living/replay.js +10 -9
  198. package/dist/simulation/living/runtime.d.ts +135 -25
  199. package/dist/simulation/living/runtime.js +1641 -583
  200. package/dist/simulation/living/scale.d.ts +96 -0
  201. package/dist/simulation/living/scale.js +124 -0
  202. package/dist/simulation/living/script.d.ts +5 -0
  203. package/dist/simulation/living/script.js +115 -0
  204. package/dist/simulation/living/shared-kinds.d.ts +4 -11
  205. package/dist/simulation/living/shared-kinds.js +11 -81
  206. package/dist/simulation/living/space.d.ts +14 -0
  207. package/dist/simulation/living/space.js +132 -0
  208. package/dist/simulation/living/state.d.ts +100 -0
  209. package/dist/simulation/living/state.js +393 -0
  210. package/dist/simulation/living/types.d.ts +829 -512
  211. package/dist/simulation/living/types.js +162 -187
  212. package/dist/simulation/living/world-rules.d.ts +100 -0
  213. package/dist/simulation/living/world-rules.js +267 -0
  214. package/dist/simulation/plugins/loader.js +11 -0
  215. package/dist/skills/loader.js +4 -0
  216. package/dist/tools.d.ts +1 -0
  217. package/dist/tools.js +1 -0
  218. package/dist/ui/ratatui/headless_pane_manager.d.ts +4 -1
  219. package/dist/ui/ratatui/headless_pane_manager.js +13 -9
  220. package/dist/ui/ratatui/pane_relay.js +29 -0
  221. package/dist/ui/ratatui/pane_type.d.ts +10 -0
  222. package/dist/ui/ratatui/pane_type.js +11 -0
  223. package/dist/ui/ratatui/process.d.ts +30 -0
  224. package/dist/ui/ratatui/process.js +133 -19
  225. package/dist/ui/ratatui/protocol.d.ts +124 -2
  226. package/dist/ui/ratatui/protocol.js +35 -0
  227. package/dist/ui/ratatui/relay_policy.js +3 -0
  228. package/dist/ui/ratatui/ztc_launch_trust.d.ts +2 -1
  229. package/dist/ui/ratatui/ztc_launch_trust.js +8 -1
  230. package/dist/ui/terminal_image.d.ts +12 -0
  231. package/dist/ui/terminal_image.js +21 -1
  232. package/dist/utils/codex_project_trust.d.ts +19 -0
  233. package/dist/utils/codex_project_trust.js +37 -0
  234. package/dist/utils/compaction.js +103 -20
  235. package/dist/utils/git_program_files.d.ts +19 -12
  236. package/dist/utils/git_program_files.js +411 -83
  237. package/dist/utils/host_shell.d.ts +10 -1
  238. package/dist/utils/host_shell.js +14 -1
  239. package/dist/utils/mid_turn_compaction.d.ts +2 -0
  240. package/dist/utils/mid_turn_compaction.js +2 -0
  241. package/dist/utils/models.js +6 -1
  242. package/dist/utils/sandbox.d.ts +109 -8
  243. package/dist/utils/sandbox.js +981 -187
  244. package/dist/utils/shell.d.ts +2 -0
  245. package/dist/utils/shell.js +10 -4
  246. package/dist/utils/subprocess_env.d.ts +47 -11
  247. package/dist/utils/subprocess_env.js +107 -15
  248. package/dist/utils/system_ps.d.ts +8 -0
  249. package/dist/utils/system_ps.js +39 -7
  250. package/dist/utils/unattended_compaction.d.ts +9 -0
  251. package/dist/utils/unattended_compaction.js +13 -0
  252. package/dist/utils/ztc_own_state.d.ts +8 -5
  253. package/dist/utils/ztc_own_state.js +17 -11
  254. package/dist/web/mirror_client.js +1 -0
  255. package/dist/web/mirror_stream.d.ts +50 -6
  256. package/dist/web/mirror_stream.js +160 -15
  257. package/dist/workflows/registry.js +3 -1
  258. package/dist/workspace/controller.js +12 -0
  259. package/dist/workspace_collision.d.ts +3 -0
  260. package/dist/workspace_collision.js +14 -1
  261. package/dist/workspace_session_context.js +2 -1
  262. package/dist/zlm-embed.mjs +3823 -1970
  263. package/node_modules/@zerg/model-contracts/README.md +16 -4
  264. package/node_modules/@zerg/model-contracts/index.js +6 -1
  265. package/npm-shrinkwrap.json +1 -1
  266. package/package.json +42 -24
  267. package/packages/model-contracts/README.md +16 -4
  268. package/packages/model-contracts/index.js +6 -1
@@ -1,149 +1,94 @@
1
1
  import { z } from 'zod';
2
- import { scheduleIntentSchema, changeSchema, entitySchema, kindDefinitionSchema, kindRequestSchema, propertyValueSchema } from './open-world.js';
2
+ import { idSchema, scheduleIntentSchema, changeSchema, entitySchema, kindDefinitionSchema, kindRequestSchema, propertyValueSchema } from './open-world.js';
3
+ import { calendarSchema } from './scale.js';
4
+ import { BOUNDS, foldSchema, ringSchema, sealState, tableRingSchema } from './state.js';
5
+ import { phrase } from './phrases.js';
3
6
  // A living world is one place-graph, one cast, and an ordered list of accepted events.
4
7
  // Everything the player or a character can know derives from this state and those events.
5
8
  export const LIVING_SCHEMA_VERSION = 1;
6
- // The engine version marks which reducer wrote a state. Replay is exact within one
7
- // engine version; a state from an older engine still loads and replays, but its
8
- // rebuilt state may differ.
9
- export const LIVING_ENGINE_VERSION = 54;
10
- export const BOUNDED_PERSON_RECORDS_ENGINE = 54;
9
+ export const LIVING_ENGINE_VERSION = 110;
10
+ export const MAX_CHAIN_LINKS = 4;
11
11
  export const MAX_WORKING_BELIEFS = 64;
12
12
  export const MAX_CLOSED_COMMITMENTS = 64;
13
- export const MAX_OPEN_COMMITMENTS = 128;
14
- export const STABLE_CONVERSATION_ENGINE = 52;
15
- export const FULL_SCHEDULE_INTENT_ENGINE = 52;
13
+ export const MAX_OPEN_COMMITMENTS = BOUNDS.datedPromises;
16
14
  // From this engine a world's own data may say messages take time to arrive.
17
- export const MESSAGE_TRAVEL_ENGINE = 39;
18
15
  // From this engine a pause or a new speed keeps the clock where the player could see it.
19
- export const SHOWN_CLOCK_ENGINE = 40;
20
16
  // From this engine the world keeps a chronicle of what the player did and perceived, for the ending.
21
- export const CHRONICLE_ENGINE = 40;
22
17
  // From this engine walking off sets aside a long act at once; before, its end did.
23
- export const WALK_OFF_ENGINE = 40;
24
18
  // From this engine a thing made past a trigger's threshold joins a check of its kind pending at its place.
25
- export const ONE_CHECK_ENGINE = 41;
26
19
  // From this engine a memory keeps the things its event concerned, and recall reaches it through them.
27
- export const THING_MEMORY_ENGINE = 42;
28
20
  // From this engine going away sets aside a long act under way and no one away can be spoken to.
29
- export const AWAY_APART_ENGINE = 42;
30
21
  // From this engine someone brought in mid-story is a newcomer.
31
- export const NEWCOMER_ENGINE = 42;
32
- export const SELF_HOLD_ENGINE = 42;
33
22
  // From this engine the player's sighting of someone keeps when the player found them gone from it.
34
- export const GONE_AT_ENGINE = 42;
35
23
  // From this engine the player reads of a problem what they last saw of it, and when.
36
- export const PROBLEM_VIEW_ENGINE = 42;
37
- export const REQUEST_TIME_ENGINE = 42;
38
24
  // From this engine a person counts the lines they said to someone who has not answered.
39
- export const SILENCE_ENGINE = 42;
40
25
  // From this engine no two people in the story share a name, and only the player's own act moves the player.
41
- export const IDENTITY_ENGINE = 42;
42
26
  // From this engine writing on a paper adds to its words, marked with when and by whom.
43
- export const WRITING_GROWS_ENGINE = 42;
44
27
  // From this engine a world's own happenings carry the typed results its data names, and deadlines are counted down;
45
28
  // a promise to be somewhere at a time is decided in time to get there.
46
- export const DEADLINE_ENGINE = 42;
47
- export const PROMISE_LEAD_MINUTES = 30;
48
29
  // A decision about a promise weighs like one about a serious act: no routine plan puts it aside.
49
30
  export const PROMISE_IMPORTANCE = 7;
50
- // From this engine the open problem nobody has acted on longest goes back to the Game Master every two game hours.
51
- export const STALL_ENGINE = 42;
52
- export const STALL_MINUTES = 120;
53
- // From this engine a thing's condition has named sides, such as damage or contents; a change to one keeps the rest.
54
- export const CONDITION_SIDES_ENGINE = 43;
55
- // From this engine a vote is a typed decision: each member casts their own ballot, and the count settles it.
56
- export const VOTES_ENGINE = 43;
57
- export const BALLOT_CHOICES = ['yes', 'no', 'abstain'];
58
31
  // From this engine the player is never shown as seeing, in a room they look into, someone who has left the story.
59
- export const LEFT_UNSEEN_ENGINE = 44;
60
32
  // From this engine one act adds at most this many characters to words already written, so a paper never restates itself.
61
- export const ADDED_LINE_ENGINE = 44;
62
33
  export const MAX_ADDED_LINE = 400;
63
34
  // From this engine a person knows the words of the papers they wrote, wherever the papers lie.
64
- export const AUTHORS_ENGINE = 44;
65
35
  // From this engine a thing that spreads or carries through places, such as a fire, a flood or a sound, is never held.
66
- export const UNHELD_ENGINE = 44;
67
- // From this engine coming back from rest is recorded, so people know how long they have been up.
68
- export const REST_ENGINE = 44;
69
- export const LONG_DAY_MINUTES = 16 * 60;
70
- // From this engine an injury, an illness, a custody, a detention, an authority, a debt or a vote belongs to no hand.
71
- export const BODILESS_ENGINE = 45;
72
36
  // From this engine a write gives a paper its whole new text; a replacement that drops most of the words is refused.
73
- export const WHOLE_TEXT_ENGINE = 45;
74
- // From this engine a vote opened during play gives its members a turn at once, and a room holds one open vote at a time.
75
- export const OPEN_NOW_ENGINE = 45;
76
- // From this engine only the engine writes a vote's count and result on it.
77
- export const COUNT_ONLY_ENGINE = 45;
78
37
  // From this engine a problem the player did not see begin is named by the place where they saw it.
79
- export const SEEN_WHERE_ENGINE = 45;
80
- // From this engine an ask records when its asker last reminded; two hours with no answer allow a reminder.
81
- export const REMINDER_ENGINE = 46;
82
- export const REMINDER_MINUTES = 120;
83
38
  // From this engine a thing's condition keeps whole sides; the oldest named side gives way, never a word.
84
- export const WHOLE_SIDES_ENGINE = 46;
85
- // From this engine the world keeps when the player last acted; two quiet game hours on, others see the
86
- // player's person resting, or asleep at night.
87
- export const PLAYER_REST_ENGINE = 47;
88
- export const PLAYER_QUIET_MINUTES = 120;
89
39
  // From this engine a thing keeps the order its condition sides were first set in a list a save keeps.
90
- export const SIDE_ORDER_ENGINE = 48;
91
40
  // From this engine a deadline averted because its problem was settled first is recorded as averted.
92
- export const AVERTED_ENGINE = 48;
93
41
  // From this engine a thing seen from the next room is named by its kind, such as "Fire can be seen at the quay".
94
- export const SIGHT_NAMED_ENGINE = 49;
95
42
  // From this engine people know what they could have seen: a world's own things from the start, what lies
96
43
  // in a room they come to, and the words of what they read.
97
- export const THINGS_SEEN_ENGINE = 49;
98
44
  // From this engine someone at home by day answers messages; asleep at night, they answer once back.
99
- export const AWAY_REPLY_ENGINE = 49;
100
- // From this engine a vote called in play without a closing time closes two game hours after it opens.
101
- export const VOTE_CLOSES_ENGINE = 50;
102
45
  // From this engine what lies in the open is in view to whoever stands there, and people learn it where
103
46
  // something happens with them present; only the player learns it on arrival, where the command loads.
104
- export const SEEN_AT_EVENTS_ENGINE = 50;
105
- export const VOTE_OPEN_MINUTES = 120;
106
- // Night, for going home and for sleep: from 20:00 to 05:00.
107
- export const NIGHT_FROM_HOUR = 20;
108
- export const NIGHT_UNTIL_HOUR = 5;
109
- export function isNight(clock) {
110
- const hour = Math.floor((clock % 1440) / 60);
111
- return hour >= NIGHT_FROM_HOUR || hour < NIGHT_UNTIL_HOUR;
112
- }
113
- export const DECISION_RESULTS = ['passed', 'failed', 'lapsed'];
114
- // Two lines to someone silent for ten minutes or more are enough until they answer; a new day starts over.
115
47
  export const UNANSWERED_LINES = 2;
116
- export const UNANSWERED_MINUTES = 10;
117
- export const UNANSWERED_RESET_MINUTES = 480;
48
+ export const REPEAT_ASK_EARLIER = 2;
49
+ export const REPEAT_ASK_OVERLAP = 0.8;
118
50
  // The most things whose last ruling the world keeps a note of.
119
51
  export const MAX_THING_NOTES = 120;
120
52
  export const THING_NOTE_TEXT = 300;
121
53
  export const MAX_CHRONICLE = 80;
122
54
  export const MAX_TEXT = 2000;
123
- export function clockLabel(minutes) {
124
- const day = Math.floor(minutes / 1440) + 1;
125
- const hour = Math.floor((minutes % 1440) / 60);
126
- const minute = minutes % 60;
127
- return `Day ${day}, ${String(hour).padStart(2, '0')}:${String(minute).padStart(2, '0')}`;
128
- }
129
- export const MAX_CLOCK_RATE = 1440;
55
+ export const MAX_CLOCK_RATE = 1_000_000_000;
56
+ export { clockLabel } from './scale.js';
130
57
  export const MAX_LINE = 600;
131
58
  // One spoken line or act may run to a paragraph, so the model is never stopped mid-word.
132
59
  export const MAX_SPOKEN = 1200;
133
60
  // A newcomer's role: what anyone could call them in a few words.
134
61
  export const MAX_ROLE = 48;
135
- const id = z.string().regex(/^[a-z0-9][a-z0-9-]{0,63}$/u);
62
+ const id = idSchema;
136
63
  const short = z.string().min(1).max(200);
137
64
  const line = z.string().min(1).max(MAX_LINE);
138
65
  const text = z.string().min(1).max(MAX_TEXT);
139
66
  const minutes = z.number().int().min(0).max(1_000_000_000);
140
- export const placeKindSchema = z.enum(['room', 'outdoors', 'transit', 'private']);
67
+ export const unitSchema = z.object({
68
+ id,
69
+ name: short.describe(phrase('schema.description.182')),
70
+ symbol: z.string().min(1).max(4).nullable().default(null).describe(phrase('schema.description.183')),
71
+ });
72
+ export const numberSlotSchema = z.object({
73
+ id,
74
+ unit: id.describe(phrase('schema.description.184')),
75
+ min: z.number().finite().nullable().default(null).describe(phrase('schema.description.185')),
76
+ max: z.number().finite().nullable().default(null).describe(phrase('schema.description.186')),
77
+ });
78
+ export const channelSchema = z.object({
79
+ id,
80
+ notice: z.string().min(1).max(200).describe(phrase('schema.description.187')),
81
+ reach: z.number().int().min(0).max(1_000_000).describe(phrase('schema.description.188')),
82
+ namesKind: z.boolean().optional().describe(phrase('schema.description.189')),
83
+ heard: z.boolean().optional().describe(phrase('schema.description.190')),
84
+ });
141
85
  export const placeSchema = z.object({
142
86
  id,
143
87
  name: short,
144
- kind: placeKindSchema,
145
88
  summary: text,
89
+ containerId: id.nullable().default(null),
146
90
  connections: z.array(id),
91
+ edgeCosts: z.record(id, z.number().int().min(1).max(1_000_000_000)).default({}),
147
92
  conditions: z.array(short),
148
93
  conditionAspects: z.record(id, z.object({ text: short, changedSeq: z.number().int().min(0), index: z.number().int().min(0).optional() })).default({}),
149
94
  introducedAt: z.number().int().min(0),
@@ -173,6 +118,8 @@ export const memorySchema = z.object({
173
118
  placeId: id.nullable(),
174
119
  // The things the remembered event concerned, when it named any.
175
120
  thingIds: z.array(id).optional(),
121
+ requestIds: z.array(id).optional(),
122
+ commitmentIds: z.array(id).optional(),
176
123
  evidence: z.object({ kind: z.enum(['observed', 'heard', 'told', 'inferred']), eventSeq: z.number().int().min(0), sourceId: id.nullable() }).optional(),
177
124
  });
178
125
  export const memorySummarySchema = z.object({
@@ -217,11 +164,12 @@ export const personSchema = z.object({
217
164
  roleId: id.nullable().optional(),
218
165
  summary: text,
219
166
  persona: text,
220
- character: z.object({ voice: short, values: z.array(short), redLines: z.array(short), privateConcerns: z.array(short) }).optional(),
167
+ character: z.object({ voice: short, values: z.array(short), redLines: z.array(short), privateConcerns: z.array(short),
168
+ wants: z.array(short).optional(), fears: z.array(short).optional() }).optional(),
221
169
  pronouns: pronouns.optional(),
222
170
  isPlayer: z.boolean(),
223
171
  placeId: id,
224
- money: z.number().min(-1_000_000_000).max(1_000_000_000).nullable(),
172
+ knownPlaceIds: z.array(id),
225
173
  mood: short,
226
174
  // Physical state that others can see: bleeding, soaked, unconscious. Absent means unremarkable.
227
175
  condition: short.optional(),
@@ -248,19 +196,24 @@ export const personSchema = z.object({
248
196
  // A person who has left the world for good: gone home, quit, moved away or died.
249
197
  departed: z.object({ at: minutes, reason: line }).optional(),
250
198
  // Off in the world for a while: home, asleep, out on an errand; back at their place when it ends.
251
- away: z.object({ at: minutes, until: minutes, reason: line }).optional(),
199
+ offstage: z.object({ at: minutes, until: minutes, why: line }).optional(),
252
200
  // Brought into the story mid-way, as a visitor: going home, they leave it. When they came, from engine 42.
253
201
  newcomer: z.literal(true).optional(),
254
202
  arrivedAt: minutes.optional(),
203
+ incidental: z.literal(true).optional(),
255
204
  // Lines this person said to someone who has done nothing others could see since the first of them.
256
205
  unanswered: z.record(id, z.object({ lines: z.number().int().min(1), firstAt: minutes })).optional(),
206
+ // The event at which this person's situation last changed in a typed way: something they perceived,
207
+ // something addressed to them, or a deadline of theirs. From engine 58.
208
+ situationSeq: z.number().int().min(0).optional(),
209
+ // The event at which the current plan's situation was established; carrying on keeps it. From engine 58.
210
+ planBasisSeq: z.number().int().min(0).optional(),
257
211
  });
258
212
  export const objectSchema = z.object({
259
213
  id,
260
214
  name: short,
261
215
  summary: text,
262
- placeId: id.nullable(),
263
- holderId: id.nullable(),
216
+ containerId: id.nullable(),
264
217
  ownerId: id.nullable(),
265
218
  condition: short,
266
219
  // Each named side of the condition, in the order first set; the condition line shows them all.
@@ -299,7 +252,7 @@ export const requestSchema = z.object({
299
252
  senderId: id,
300
253
  receiverId: id,
301
254
  topic: line,
302
- status: z.enum(['open', 'answered', 'refused', 'done']),
255
+ status: z.enum(['open', 'answered', 'accepted', 'refused', 'done']),
303
256
  openedSeq: z.number().int().min(1),
304
257
  // When it was made, from engine 42, so the one who asked knows how long it has waited.
305
258
  openedAt: minutes.optional(),
@@ -331,8 +284,7 @@ export const tensionSchema = z.object({
331
284
  // an arrival, a fire spreading, a storm, a delivery. An errand is a walk to tell
332
285
  // someone something, carried out without a model. A delivery is a message on its way. A finish is
333
286
  // the end of a long act, ruled when its time has passed.
334
- // A count opens or closes a vote at its written time; the engine settles it with no model.
335
- export const scheduledKindSchema = z.enum(['plan', 'reply', 'arrive', 'world', 'errand', 'deliver', 'finish', 'back', 'count']);
287
+ export const scheduledKindSchema = z.enum(['plan', 'reply', 'answer', 'arrive', 'world', 'errand', 'deliver', 'finish', 'onstage', 'react']);
336
288
  // A message on its way: who sent it, to whom, its words, whether its readers answer, and a request it opens on arrival.
337
289
  export const deliverySchema = z.object({
338
290
  fromId: id,
@@ -341,19 +293,34 @@ export const deliverySchema = z.object({
341
293
  replies: z.boolean(),
342
294
  request: z.object({ requestId: id, topic: z.string().min(1).max(MAX_LINE) }).optional(),
343
295
  });
344
- export const messageTravelSchema = z.object({ minutes: z.number().int().min(1).max(10_080), how: z.string().min(1).max(120) });
296
+ export const messageTravelSchema = z.object({
297
+ minutes: z.number().int().min(1).max(1_000_000_000).describe(phrase('schema.description.191')),
298
+ how: z.string().min(1).max(120).describe(phrase('schema.description.192')),
299
+ });
345
300
  // What a world's own happening changes when it falls due, whatever the Game Master rules, and when it
346
301
  // does not happen at all; how far it carries and in what words; whether people count down to it.
347
302
  export const beatRulesSchema = z.object({
348
- unless: z.object({ settled: id }).optional(),
303
+ unless: z.object({ settled: id.describe(phrase('schema.description.193')) }).optional().describe(phrase('schema.description.194')),
349
304
  then: z.object({
350
- facts: z.array(z.object({ aspect: id, text: line })).max(8).optional(),
351
- tension: z.object({ id, summary: line.optional(), status: z.enum(['open', 'settled']).optional() }).optional(),
352
- transfers: z.array(z.object({ fromId: id.nullable(), toId: id.nullable(), amount: z.number().positive().max(1_000_000_000) })).max(8).optional(),
353
- }).optional(),
354
- reach: z.enum(['nearby', 'everywhere']).optional(),
355
- heard: line.optional(),
356
- deadline: z.boolean().optional(),
305
+ facts: z.array(z.object({
306
+ aspect: id.describe(phrase('schema.description.195')),
307
+ text: line.describe(phrase('schema.description.196')),
308
+ })).max(8).optional().describe(phrase('schema.description.197')),
309
+ tension: z.object({
310
+ id,
311
+ summary: line.optional().describe(phrase('schema.description.198')),
312
+ status: z.enum(['open', 'settled']).optional().describe(phrase('schema.description.199')),
313
+ }).optional().describe(phrase('schema.description.200')),
314
+ shifts: z.array(z.object({
315
+ slot: id.describe(phrase('schema.description.201')),
316
+ fromId: id.nullable().describe(phrase('schema.description.202')),
317
+ toId: id.nullable().describe(phrase('schema.description.203')),
318
+ amount: z.number().positive().max(1_000_000_000).describe(phrase('schema.description.204')),
319
+ })).max(8).optional().describe(phrase('schema.description.205')),
320
+ }).optional().describe(phrase('schema.description.206')),
321
+ reach: z.enum(['nearby', 'everywhere']).optional().describe(phrase('schema.description.207')),
322
+ heard: line.optional().describe(phrase('schema.description.208')),
323
+ deadline: z.boolean().optional().describe(phrase('schema.description.209')),
357
324
  });
358
325
  export const scheduledSchema = z.object({
359
326
  id,
@@ -367,16 +334,21 @@ export const scheduledSchema = z.object({
367
334
  importance: z.number().int().min(1).max(10).default(3),
368
335
  // A world happening that comes back this many minutes after it is due, such as visitors or a shift change,
369
336
  // and the id its series keeps from one time to the next.
370
- everyMinutes: z.number().int().min(1).max(100_000).optional(),
337
+ everyMinutes: z.number().int().min(1).max(1_000_000_000).optional(),
371
338
  series: id.optional(),
339
+ chain: id.optional(),
340
+ link: z.number().int().min(0).max(64).optional(),
372
341
  // Engine 51 stores meter decoding separately from its bounded generated identity.
373
342
  prediction: z.object({ propertyId: id, index: z.number().int().min(0) }).optional(),
374
343
  replanned: z.literal(true).optional(),
344
+ // A routine activity the person took up themselves, which may carry on unchanged. From engine 58.
345
+ selfPlanned: z.literal(true).optional(),
346
+ waitingForExchange: z.literal(true).optional(),
347
+ decision: z.object({ kind: z.enum(['promise', 'ask']), id }).optional(),
375
348
  // A world's own happening, from engine 42: what it changes and how it carries.
376
349
  beat: beatRulesSchema.optional(),
377
350
  delivery: deliverySchema.optional(),
378
- // A vote that opens or is counted at this time, from engine 43.
379
- count: z.object({ entityId: id, opens: z.boolean() }).optional(),
351
+ law: z.object({ entityId: id, slotId: id }).optional(),
380
352
  // A long act's ruling, held until its time has passed: the event it will be, checked again when it
381
353
  // applies; how each person or thing it names stood when it began; and who may react to it. Engine 39
382
354
  // kept no record.
@@ -384,7 +356,7 @@ export const scheduledSchema = z.object({
384
356
  });
385
357
  // A sighting is where the player saw someone, or, when they saw them walk out, the room they walked into;
386
358
  // and, once the player found them gone from it, when that was.
387
- export const sightingSchema = z.object({ placeId: id, at: minutes, heading: z.literal(true).optional(), gone: z.literal(true).optional(), away: z.literal(true).optional(),
359
+ export const sightingSchema = z.object({ placeId: id, at: minutes, heading: z.literal(true).optional(), gone: z.literal(true).optional(), offstage: z.literal(true).optional(),
388
360
  goneAt: minutes.optional() });
389
361
  // Effects are the whole vocabulary of change. Every accepted event is a list of them.
390
362
  export const effectSchema = z.discriminatedUnion('kind', [
@@ -395,71 +367,67 @@ export const effectSchema = z.discriminatedUnion('kind', [
395
367
  z.object({ kind: z.literal('dispatch'), dispatchId: id, ...deliverySchema.shape, sourcePersonId: id.nullable().optional() }),
396
368
  z.object({ kind: z.literal('request.open'), requestId: id, senderId: id, receiverId: id, topic: line }),
397
369
  z.object({ kind: z.literal('request.remind'), requestId: id }),
398
- z.object({ kind: z.literal('request.update'), requestId: id, status: z.enum(['answered', 'refused', 'done']), answer: z.string().min(1).max(MAX_TEXT).optional() }),
370
+ z.object({ kind: z.literal('request.update'), requestId: id, status: z.enum(['answered', 'accepted', 'refused', 'done']), answer: z.string().min(1).max(MAX_TEXT).optional() }),
399
371
  z.object({ kind: z.literal('norm.violation'), normEntityId: id, actionKind: id, actorId: id }),
400
372
  z.object({ kind: z.literal('stance'), personId: id, actorId: id, status: stanceSchema.shape.status, sourceSeq: z.number().int().min(1) }),
401
- z.object({ kind: z.literal('object.update'), objectId: id, condition: short.nullable(), aspect: z.string().min(1).max(40).optional(), placeId: id.nullable(), holderId: id.nullable(), ownerId: id.nullable() }),
402
- z.object({ kind: z.literal('object.create'), objectId: id, name: short, summary: text, placeId: id.nullable(), holderId: id.nullable(), ownerId: id.nullable(), condition: short }),
373
+ z.object({ kind: z.literal('object.update'), objectId: id, condition: short.nullable(), aspect: z.string().min(1).max(40).optional(), containerId: id.nullable().optional(), ownerId: id.nullable() }),
374
+ z.object({ kind: z.literal('object.create'), objectId: id, name: short, summary: text, containerId: id.nullable(), ownerId: id.nullable(), condition: short }),
403
375
  z.object({ kind: z.literal('place.condition'), placeId: id, add: short.nullable(), remove: short.nullable(), aspect: id.optional() }),
404
376
  z.object({ kind: z.literal('place.create'), placeId: id, name: short, summary: text, connections: z.array(id).min(1) }),
377
+ z.object({ kind: z.literal('place.move'), placeId: id, toPlaceId: id }),
405
378
  z.object({ kind: z.literal('person.create'), personId: id, name: short, role: short, summary: text, persona: text, placeId: id, pronouns: pronouns.nullable().default(null),
406
379
  // What brought them and what they want now: their first aim.
407
380
  wants: line.optional() }),
408
- z.object({ kind: z.literal('money'), personId: id, delta: z.number().int().min(-1_000_000_000).max(1_000_000_000) }),
409
381
  // A world deadline has passed, with what came of it.
410
382
  z.object({ kind: z.literal('deadline.passed'), what: line, outcome: line, averted: z.literal(true).optional() }),
411
- // Money passes from a person or an account to another; null is outside the world, such as costs paid.
412
- z.object({ kind: z.literal('transfer'), fromId: id.nullable(), toId: id.nullable(), amount: z.number().positive().max(1_000_000_000) }),
383
+ z.object({ kind: z.literal('shift'), slotId: id, fromId: id.nullable(), toId: id.nullable(), amount: z.number().positive().max(1_000_000_000) }),
413
384
  z.object({ kind: z.literal('relationship'), personId: id, targetId: id, trust: z.number().int().min(-40).max(40), warmth: z.number().int().min(-40).max(40), note: z.string().max(MAX_LINE) }),
414
385
  z.object({ kind: z.literal('belief'), personId: id, subject: short, claim: line, sourcePersonId: id.nullable(),
415
386
  evidence: z.object({ kind: z.enum(['observed', 'heard', 'told', 'inferred']), eventSeq: z.number().int().min(0), sourceId: id.nullable() }).optional() }),
416
- z.object({ kind: z.literal('commitment'), commitmentId: id, personId: id, toId: id, text: line, dueInMinutes: z.number().int().min(0).max(100_000).nullable(), placeId: id.optional() }),
387
+ z.object({ kind: z.literal('commitment'), commitmentId: id, personId: id, toId: id, text: line, dueInMinutes: z.number().int().min(0).max(1_000_000_000).nullable(), placeId: id.optional() }),
417
388
  z.object({ kind: z.literal('commitment.update'), commitmentId: id, personId: id, status: z.enum(['kept', 'broken']) }),
418
389
  z.object({ kind: z.literal('goal'), personId: id, add: line.nullable(), dropGoalId: id.nullable(), doneGoalId: id.nullable().optional() }),
419
390
  z.object({ kind: z.literal('mood'), personId: id, mood: short }),
420
391
  z.object({ kind: z.literal('person.condition'), personId: id, condition: short.nullable() }),
421
392
  z.object({ kind: z.literal('hold'), personId: id, byId: id.nullable(), reason: line.nullable() }),
422
393
  z.object({ kind: z.literal('role'), personId: id, role: short, roleId: id.nullable().default(null) }),
423
- z.object({ kind: z.literal('schedule'), scheduledId: id, personId: id.nullable(), inMinutes: z.number().int().min(1).max(100_000), intent: scheduleIntentSchema, placeId: id.nullable(), targetId: id.nullable(), scheduleKind: scheduledKindSchema,
424
- importance: z.number().int().min(1).max(10).optional(), everyMinutes: z.number().int().min(1).max(100_000).optional(), series: id.optional(), beat: beatRulesSchema.optional(), replanned: z.literal(true).optional(),
425
- held: z.object({ fields: z.record(z.string(), z.unknown()), record: z.string().max(MAX_TEXT).optional(), standing: z.record(id, z.string().max(MAX_LINE)), reactorIds: z.array(id) }).optional() }),
394
+ z.object({ kind: z.literal('schedule'), scheduledId: id, personId: id.nullable(), inMinutes: z.number().int().min(0).max(1_000_000_000), intent: scheduleIntentSchema, placeId: id.nullable(), targetId: id.nullable(), scheduleKind: scheduledKindSchema,
395
+ importance: z.number().int().min(1).max(10).optional(), everyMinutes: z.number().int().min(1).max(1_000_000_000).optional(), series: id.optional(), chain: id.optional(), link: z.number().int().min(0).max(64).optional(), beat: beatRulesSchema.optional(), replanned: z.literal(true).optional(),
396
+ decision: z.object({ kind: z.enum(['promise', 'ask']), id }).optional(),
397
+ held: z.object({ fields: z.record(z.string(), z.unknown()), record: z.string().max(MAX_TEXT).optional(), standing: z.record(id, z.string().max(MAX_LINE)), reactorIds: z.array(id) }).optional(), selfPlanned: z.literal(true).optional(),
398
+ waitingForExchange: z.literal(true).optional() }),
426
399
  // A long act set aside before its end names what it was and when it began, so its actor is told.
427
400
  z.object({ kind: z.literal('unschedule'), scheduledId: id, leftOff: z.object({ intent: scheduleIntentSchema, begunAt: minutes }).optional() }),
428
- z.object({ kind: z.literal('plan'), personId: id, plan: planSchema.nullable() }),
401
+ z.object({ kind: z.literal('plan'), personId: id, plan: planSchema.nullable(), basisSeq: z.number().int().min(0).optional(), deciding: z.literal(true).optional() }),
429
402
  z.object({ kind: z.literal('fact'), add: line.nullable(), remove: line.nullable(), aspect: id.optional() }),
430
403
  z.object({ kind: z.literal('tension.create'), tensionId: id, title: short, summary: text, participantIds: z.array(id), openedBy: line.optional() }),
431
404
  z.object({ kind: z.literal('tension.update'), tensionId: id, status: z.enum(['open', 'settled']), note: text.nullable() }),
432
405
  z.object({ kind: z.literal('memory'), personId: id, text: text, importance: z.number().int().min(1).max(10), participantIds: z.array(id) }),
433
406
  z.object({ kind: z.literal('incapacitate'), personId: id, reason: line }),
434
407
  z.object({ kind: z.literal('person.leave'), personId: id, reason: line }),
435
- z.object({ kind: z.literal('person.away'), personId: id, minutes: z.number().int().min(1).max(2880), reason: line }),
436
- z.object({ kind: z.literal('person.back'), personId: id }),
408
+ z.object({ kind: z.literal('person.offstage'), personId: id, minutes: z.number().int().min(1).max(1_000_000_000), why: line }),
409
+ z.object({ kind: z.literal('person.onstage'), personId: id }),
437
410
  z.object({ kind: z.literal('conversation.end'), conversationId: id }),
438
411
  z.object({ kind: z.literal('kind.define'), definition: kindDefinitionSchema }),
439
412
  z.object({ kind: z.literal('kind.request'), request: kindRequestSchema }),
440
- z.object({ kind: z.literal('entity.create'), entityId: id, kindId: id, name: short, placeId: id.nullable().default(null),
413
+ z.object({ kind: z.literal('kind.revise'), definition: kindDefinitionSchema }),
414
+ z.object({ kind: z.literal('note'), facet: id, text: z.string().min(1).max(MAX_LINE), kindId: id.nullable().default(null) }),
415
+ z.object({ kind: z.literal('entity.create'), entityId: id, kindId: id, name: short, containerId: id.nullable().default(null),
441
416
  initialProperties: z.record(id, propertyValueSchema).optional(),
442
- // A thing that is somewhere may be made as it now is, and in the hand of someone there.
443
- condition: z.string().trim().min(1).max(200).optional(), holderId: id.optional(),
444
- // A decision's members, who alone may vote on it, and the problem its result settles.
445
- memberIds: z.array(id).min(1).max(12).optional(), settles: id.optional(),
417
+ condition: z.string().trim().min(1).max(200).optional(),
446
418
  // Who knows a world's own thing from the start, when its data says, and whether it is hidden; only
447
419
  // the opening names them.
448
420
  knownTo: z.array(id).max(64).optional(), hidden: z.literal(true).optional(),
449
- // Money that moves when the decision passes, such as an investment wired once an agreement is signed.
450
- transfers: z.array(z.object({ fromId: id.nullable(), toId: id.nullable(), amount: z.number().positive().max(1_000_000_000) })).max(4).optional() }),
451
- // A member casts their own vote on an open decision; only they may, in their own act or answer.
452
- z.object({ kind: z.literal('ballot'), entityId: id, personId: id, choice: z.enum(BALLOT_CHOICES) }),
453
- // A decision whose time is up is counted: the result follows from the ballots, not from anyone's word.
454
- z.object({ kind: z.literal('decision.close'), entityId: id, result: z.enum(DECISION_RESULTS) }),
421
+ }),
455
422
  z.object({ kind: z.literal('property.set'), entityId: id, propertyId: id, value: propertyValueSchema.nullable() }),
456
423
  // A thing that is somewhere changes hands, or is set down where it is.
457
- z.object({ kind: z.literal('entity.move'), entityId: id, holderId: id.nullable(), placeId: id.nullable() }),
424
+ z.object({ kind: z.literal('entity.move'), entityId: id, containerId: id }),
458
425
  // A thing that is somewhere is visibly changed, such as torn or burned.
459
426
  z.object({ kind: z.literal('entity.condition'), entityId: id, condition: short, aspect: z.string().min(1).max(40).optional() }),
427
+ z.object({ kind: z.literal('cell.add'), entityId: id, slotId: id, option: id, personId: id }),
460
428
  z.object({ kind: z.literal('relation.set'), entityId: id, relationId: id, targetId: id.nullable() }),
461
429
  // The server clock: whether the world runs, and how many game minutes pass each real minute.
462
- z.object({ kind: z.literal('clock'), paused: z.boolean(), rate: z.number().int().min(1).max(MAX_CLOCK_RATE) }),
430
+ z.object({ kind: z.literal('clock'), paused: z.boolean(), rate: z.number().int().min(1).max(MAX_CLOCK_RATE), hold: z.literal(true).optional() }),
463
431
  ]);
464
432
  export const eventKindSchema = z.enum([
465
433
  'opening', 'move', 'speech', 'message', 'attempt', 'world', 'reaction', 'plan', 'wait', 'arrive', 'keep-playing', 'finish',
@@ -485,6 +453,7 @@ export const eventSchema = z.object({
485
453
  placeId: id.nullable(),
486
454
  witnessIds: z.array(id),
487
455
  reach: reachSchema.default('here'),
456
+ channel: id.nullable().default(null),
488
457
  notice: text.nullable().default(null),
489
458
  nearbyIds: z.array(id).default([]),
490
459
  summary: text,
@@ -497,31 +466,52 @@ export const eventSchema = z.object({
497
466
  thingIds: z.array(id).max(8).optional(),
498
467
  narration: text.nullable(),
499
468
  outcome: z.enum(['succeeded', 'partial', 'failed', 'impossible']).nullable(),
500
- minutes: z.number().int().min(0).max(100_000),
469
+ narrationBasis: z.enum(['model', 'outcome']).optional(),
470
+ reasonShown: z.boolean().optional(),
471
+ reason: z.string().max(MAX_TEXT).optional(),
472
+ minutes: z.number().int().min(0).max(1_000_000_000),
501
473
  effects: z.array(effectSchema),
502
474
  causeSeq: z.number().int().min(0).nullable(),
503
475
  importance: z.number().int().min(1).max(10),
504
476
  suggestions: z.array(short).max(3),
477
+ lawSeeds: z.array(z.object({ entityId: id, slotId: id })).optional(),
505
478
  ending: endingSchema.optional(),
506
479
  // How many proposed changes the world could not accept and left out of this event.
507
480
  droppedEffects: z.number().int().min(1).optional(),
508
481
  // The real time, in epoch milliseconds, at which a clock or tick event happened.
509
482
  realAt: z.number().int().min(0).optional(),
510
483
  });
484
+ export function parseLivingEvent(value) {
485
+ return eventSchema.parse(value);
486
+ }
511
487
  export const stoppingPointSchema = z.object({ at: minutes, tensionId: id, title: short, summary: text });
512
488
  // Runs finished before recap cards carry only a title and text.
513
489
  export const epilogueSchema = z.object({ title: short, text: text, at: minutes }).extend(endingSchema.partial().shape);
490
+ export const chronicleEntrySchema = z.object({ seq: z.number().int().min(1), at: minutes, kind: z.string().min(1).max(40), placeId: id.nullable(),
491
+ summary: z.string().min(1).max(MAX_TEXT), outcome: z.string().max(40).nullable(), importance: z.number().int().min(1).max(10), mine: z.boolean() });
492
+ export const thingNoteSchema = z.object({ seq: z.number().int().min(1), at: minutes, text: z.string().min(1).max(THING_NOTE_TEXT) });
493
+ export const facetUseSchema = z.object({
494
+ count: z.number().int().min(1),
495
+ firstSeq: z.number().int().min(1),
496
+ lastSeq: z.number().int().min(1),
497
+ text: z.string().min(1).max(MAX_LINE),
498
+ kindId: id.nullable().default(null),
499
+ });
514
500
  export const stateSchema = z.object({
515
501
  schemaVersion: z.literal(LIVING_SCHEMA_VERSION),
516
502
  engine: z.number().int().min(1).default(1),
503
+ admissionCapsFrom: z.number().int().min(0).optional(),
517
504
  gameKind: id,
518
505
  seed: z.string().min(1).max(128),
519
506
  revision: z.number().int().min(0),
520
507
  clock: minutes,
508
+ calendar: calendarSchema,
509
+ travelSteps: z.number().int().min(1).max(1_000_000_000),
521
510
  // When the world began: the moment its opening and facts were written for. Older saves lack it.
522
511
  startClock: minutes.optional(),
523
512
  // When the player last acted, from engine 47.
524
513
  playerActedAt: minutes.optional(),
514
+ playerTurnSeq: z.number().int().min(0).optional(),
525
515
  status: z.enum(['open', 'finished']),
526
516
  playerId: id,
527
517
  places: z.record(id, placeSchema),
@@ -535,9 +525,7 @@ export const stateSchema = z.object({
535
525
  stances: z.array(stanceSchema).default([]),
536
526
  tensions: z.array(tensionSchema),
537
527
  schedule: z.array(scheduledSchema),
538
- // Threshold crossings predicted for growing values, ordered by time; kept apart so a large count
539
- // of growing things does not weigh on every change to the main schedule.
540
- meterSchedule: z.array(scheduledSchema).default([]),
528
+ predictions: ringSchema(scheduledSchema).default({ items: [], fold: { count: 0, first: null, last: null, digest: '', provenance: 'predictions' } }),
541
529
  sightings: z.record(id, sightingSchema),
542
530
  events: z.array(eventSchema),
543
531
  stoppingPoint: stoppingPointSchema.nullable(),
@@ -546,21 +534,23 @@ export const stateSchema = z.object({
546
534
  opening: z.object({ title: short, situation: text, stakes: text }),
547
535
  // The world's physics, technology and social order as authored; older saves carry none.
548
536
  setting: z.string().max(2000).default(''),
549
- currency: z.object({ symbol: z.string().min(1).max(4), name: z.string().min(1).max(40) }).nullable(),
537
+ units: z.record(id, unitSchema).default({}),
538
+ numbers: z.record(id, numberSlotSchema).default({}),
539
+ channels: z.record(id, channelSchema).default({}),
540
+ holdings: z.record(id, z.record(id, z.number().finite())).default({}),
541
+ outside: z.record(id, z.number().finite()).default({}),
550
542
  // The world's deadlines that have passed lately, and what came of each.
551
543
  passedDeadlines: z.array(z.object({ what: line, at: minutes, outcome: line, averted: z.literal(true).optional() })).max(8).optional(),
552
- // Money kept apart from anyone's purse, such as a city reserve or a company account.
553
- accounts: z.record(id, z.object({ id, name: short, holderId: id.nullable(), balance: z.number().min(-1_000_000_000).max(1_000_000_000), allowsDebt: z.boolean() })).optional(),
554
544
  suggestions: z.array(short).max(3),
545
+ suggestionsFrom: id.nullable().optional(),
555
546
  kinds: z.record(id, kindDefinitionSchema).default({}),
556
547
  kindRequests: z.array(kindRequestSchema).default([]),
557
548
  entities: z.record(id, entitySchema).default({}),
558
- entityPlaceIds: z.record(id, z.array(id)).default({}),
549
+ pins: z.record(id, z.number().int().min(0)).default({}),
550
+ touched: z.record(id, z.number().int().min(0)).default({}),
551
+ parked: foldSchema.default({ count: 0, first: null, last: null, digest: '', provenance: 'parked' }),
552
+ within: z.record(id, z.array(id)).default({}),
559
553
  globalEntityIds: z.array(id).default([]),
560
- // Decisions still open to votes, so finding them never walks every thing in the world.
561
- openDecisionIds: z.array(id).optional(),
562
- // The papers each person wrote, by their author slot, so a mind recalls them without walking every thing.
563
- authoredIds: z.record(id, z.array(id)).optional(),
564
554
  entityMoveSubjectIds: z.record(id, z.array(id)).default({}),
565
555
  // Placeless things by the people, places and things they name; those that name nothing apply everywhere.
566
556
  globalEntityRefs: z.record(id, z.record(id, z.literal(true))).default({}),
@@ -574,10 +564,14 @@ export const stateSchema = z.object({
574
564
  // How messages travel here and how many game minutes they take; null when they arrive at once.
575
565
  messageTravel: messageTravelSchema.nullable().default(null),
576
566
  // The turning points of the player's story as they saw them, bounded, oldest first.
577
- chronicle: z.array(z.object({ seq: z.number().int().min(1), at: minutes, kind: z.string().min(1).max(40), placeId: id.nullable(),
578
- summary: z.string().min(1).max(MAX_TEXT), outcome: z.string().max(40).nullable(), importance: z.number().int().min(1).max(10), mine: z.boolean() })).default([]),
567
+ chronicle: ringSchema(chronicleEntrySchema).default({ items: [], fold: { count: 0, first: null, last: null, digest: '', provenance: 'chronicle' } }),
579
568
  // What a ruling last did with each thing it named, for later rulings: the newest things only.
580
- thingNotes: z.record(id, z.object({ seq: z.number().int().min(1), at: minutes, text: z.string().min(1).max(THING_NOTE_TEXT) })).default({}),
569
+ thingNotes: tableRingSchema(thingNoteSchema).default({ items: {}, fold: { count: 0, first: null, last: null, digest: '', provenance: 'thingNotes' } }),
570
+ facetUse: tableRingSchema(facetUseSchema).default({ items: {}, fold: { count: 0, first: null, last: null, digest: '', provenance: 'facetUse' } }),
571
+ rulings: z.number().int().min(0).default(0),
572
+ notedRulings: z.number().int().min(0).default(0),
573
+ stewardAt: minutes.nullable().default(null),
574
+ folds: z.record(z.string().min(1).max(120), foldSchema).default({}),
581
575
  });
582
576
  // The ids a thing names through its id properties and relations.
583
577
  export function entityRefs(kinds, entity) {
@@ -591,44 +585,17 @@ export function entityRefs(kinds, entity) {
591
585
  refs.add(relation.targetId);
592
586
  return [...refs].sort();
593
587
  }
594
- function freezeThrough(value) {
595
- if (value === null || typeof value !== 'object' || Object.isFrozen(value))
596
- return;
597
- Object.freeze(value);
598
- for (const child of Object.values(value))
599
- freezeThrough(child);
600
- }
601
- // With automatic immutability off, the draft library walks every plain value it meets while drafts remain
602
- // open, so large indexes would cost their full size on every event. Frozen, they are skipped; the
603
- // reducer only ever changes them through drafts, which copy on write, and a loaded state starts sealed.
604
- export function sealLivingIndexes(state) {
605
- for (const person of Object.values(state.people))
606
- if (!Object.isFrozen(person.memories))
607
- Object.freeze(person.memories);
608
- for (const list of [state.meterSchedule, state.changes, state.globalEntityIds])
609
- if (!Object.isFrozen(list))
610
- Object.freeze(list);
611
- // An accepted event never changes; frozen through, the recent events cost nothing on later events.
612
- for (const event of state.events)
613
- if (!Object.isFrozen(event))
614
- freezeThrough(event);
615
- for (const table of [state.worldEntityIds, state.globalEntityRefs, state.entityPlaceIds, state.entityMoveSubjectIds]) {
616
- if (Object.isFrozen(table))
617
- continue;
618
- for (const value of Object.values(table))
619
- if (typeof value === 'object' && !Object.isFrozen(value))
620
- Object.freeze(value);
621
- Object.freeze(table);
622
- }
623
- return state;
624
- }
625
588
  export function parseLivingState(value) {
589
+ if (value !== null && typeof value === 'object' && 'engine' in value && value.engine !== LIVING_ENGINE_VERSION) {
590
+ throw new LivingWorldError('engine-retired', `This world was made by engine ${String(value.engine)}; only engine ${LIVING_ENGINE_VERSION} worlds open.`);
591
+ }
626
592
  const parsed = stateSchema.parse(value);
593
+ parsed.admissionCapsFrom ??= parsed.revision + 1;
627
594
  if (value === null || typeof value !== 'object' || !('globalEntityRefs' in value) || !('worldEntityIds' in value)) {
628
595
  parsed.globalEntityRefs = {};
629
596
  parsed.worldEntityIds = {};
630
597
  for (const entity of Object.values(parsed.entities)) {
631
- if (entity.placeId !== null)
598
+ if (entity.containerId !== null)
632
599
  continue;
633
600
  const refs = entityRefs(parsed.kinds, entity);
634
601
  if (refs.length === 0)
@@ -637,17 +604,25 @@ export function parseLivingState(value) {
637
604
  (parsed.globalEntityRefs[ref] ??= {})[entity.id] = true;
638
605
  }
639
606
  }
640
- if (value !== null && typeof value === 'object' && 'entityPlaceIds' in value
607
+ if (value !== null && typeof value === 'object' && 'within' in value
641
608
  && 'globalEntityIds' in value && 'entityMoveSubjectIds' in value)
642
- return sealLivingIndexes(parsed);
643
- parsed.entityPlaceIds = {};
609
+ return sealState(parsed);
610
+ parsed.within = {};
644
611
  parsed.globalEntityIds = [];
645
612
  parsed.entityMoveSubjectIds = {};
613
+ for (const person of Object.values(parsed.people))
614
+ (parsed.within[person.placeId] ??= []).push(person.id);
615
+ for (const place of Object.values(parsed.places))
616
+ if (place.containerId !== null)
617
+ (parsed.within[place.containerId] ??= []).push(place.id);
618
+ for (const object of Object.values(parsed.objects))
619
+ if (object.containerId !== null)
620
+ (parsed.within[object.containerId] ??= []).push(object.id);
646
621
  for (const entity of Object.values(parsed.entities)) {
647
- if (entity.placeId === null)
622
+ if (entity.containerId === null)
648
623
  parsed.globalEntityIds.push(entity.id);
649
624
  else
650
- (parsed.entityPlaceIds[entity.placeId] ??= []).push(entity.id);
625
+ (parsed.within[entity.containerId] ??= []).push(entity.id);
651
626
  const kind = parsed.kinds[entity.kindId];
652
627
  for (const mechanic of kind?.mechanics ?? []) {
653
628
  if (mechanic.kind !== 'change' || !mechanic.onEvent)
@@ -657,7 +632,7 @@ export function parseLivingState(value) {
657
632
  (parsed.entityMoveSubjectIds[subjectId] ??= []).push(entity.id);
658
633
  }
659
634
  }
660
- return sealLivingIndexes(parsed);
635
+ return sealState(parsed);
661
636
  }
662
637
  export class LivingWorldError extends Error {
663
638
  code;