@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,227 +1,319 @@
1
- import { BOUNDED_PERSON_RECORDS_ENGINE, MAX_WORKING_BELIEFS } from './types.js';
1
+ import { MAX_WORKING_BELIEFS } from './types.js';
2
2
  import { generatedId } from './identifiers.js';
3
3
  import { z } from 'zod';
4
- import { LIVING_ENGINE_VERSION, LIVING_SCHEMA_VERSION, MAX_CLOCK_RATE, MESSAGE_TRAVEL_ENGINE, PROBLEM_VIEW_ENGINE, LivingWorldError, messageTravelSchema, parseLivingState, DEADLINE_ENGINE, beatRulesSchema, } from './types.js';
5
- import { kindDefinitionSchema, propertyValueSchema } from './open-world.js';
4
+ import { LIVING_ENGINE_VERSION, LIVING_SCHEMA_VERSION, MAX_CLOCK_RATE, LivingWorldError, channelSchema, messageTravelSchema, numberSlotSchema, parseLivingState, beatRulesSchema, unitSchema, } from './types.js';
5
+ import { idSchema, kindDefinitionSchema, narrowsKindRevision, propertyValueSchema } from './open-world.js';
6
6
  import { sharedKindMap } from './shared-kinds.js';
7
+ import { checkBeat, checkCalendar, checkDistinctIds, choiceText, definitionProblem } from './world-rules.js';
8
+ import { phrase } from './phrases.js';
9
+ import { DEFAULT_CALENDAR, MAX_BOUND, calendarSchema } from './scale.js';
7
10
  // A world definition is authored content: the place graph, the cast, the objects,
8
11
  // and the opening tension. The engine turns it into a revision-0 state.
9
- const id = z.string().regex(/^[a-z0-9][a-z0-9-]{0,63}$/u);
12
+ const id = idSchema;
10
13
  const characterSchema = z.object({
11
- voice: z.string().min(1).max(200),
12
- values: z.array(z.string().min(1).max(200)).min(1),
13
- redLines: z.array(z.string().min(1).max(200)).min(1),
14
- privateConcerns: z.array(z.string().min(1).max(200)).min(1),
14
+ voice: z.string().min(1).max(200).describe(phrase('schema.description.69')),
15
+ values: z.array(z.string().min(1).max(200)).min(1).describe(phrase('schema.description.70')),
16
+ redLines: z.array(z.string().min(1).max(200)).min(1).describe(phrase('schema.description.71')),
17
+ privateConcerns: z.array(z.string().min(1).max(200)).min(1).describe(phrase('schema.description.72')),
18
+ wants: z.array(z.string().min(1).max(200)).optional().describe(phrase('schema.description.73')),
19
+ fears: z.array(z.string().min(1).max(200)).optional().describe(phrase('schema.description.74')),
15
20
  });
21
+ const mapPointSchema = z.object({ x: z.number().finite().describe('x'), y: z.number().finite().describe('y') });
22
+ const mapPropSchema = z.object({
23
+ kind: z.string().min(1).max(40).describe('kind'),
24
+ x: z.number().finite().describe('x'), y: z.number().finite().describe('y'),
25
+ rotate: z.number().finite().optional().describe('rotate'), scale: z.number().finite().optional().describe('scale'),
26
+ });
27
+ const mapLocationSchema = z.object({
28
+ id: z.string().min(1).max(64).describe('id'), name: z.string().min(1).max(120).describe('name'),
29
+ x: z.number().finite().describe('x'), y: z.number().finite().describe('y'), w: z.number().finite().describe('w'), h: z.number().finite().describe('h'),
30
+ station: mapPointSchema.describe('station'), props: z.array(mapPropSchema).describe('props'),
31
+ });
32
+ const mapSchema = z.object({
33
+ name: z.string().min(1).max(120).describe('name'),
34
+ terrain: z.string().min(1).max(40).describe('terrain'),
35
+ palette: z.object({
36
+ ground: z.string().min(1).max(40).describe('ground'), path: z.string().min(1).max(40).describe('path'), wall: z.string().min(1).max(40).describe('wall'),
37
+ floor: z.string().min(1).max(40).describe('floor'), ink: z.string().min(1).max(40).describe('ink'), accent: z.string().min(1).max(40).describe('accent'),
38
+ }).describe('palette'),
39
+ paths: z.array(z.string().min(1).max(64)).describe('paths'),
40
+ locations: z.array(mapLocationSchema).describe('locations'),
41
+ trees: z.array(z.tuple([z.number().finite(), z.number().finite()])).describe('trees'),
42
+ });
43
+ const lookSchema = z.object({
44
+ map: mapSchema.optional().describe('map'),
45
+ art: z.string().min(1).max(64).optional().describe('art'),
46
+ icon: z.string().min(1).max(64).optional().describe('icon'),
47
+ catalog: z.object({
48
+ shortTitle: z.string().min(1).max(120).describe('shortTitle'),
49
+ eyebrow: z.string().min(1).max(120).describe('eyebrow'),
50
+ fantasy: z.string().min(1).max(400).describe('fantasy'),
51
+ primaryVerb: z.string().min(1).max(40).describe('primaryVerb'),
52
+ verbs: z.tuple([z.string().min(1).max(40), z.string().min(1).max(40), z.string().min(1).max(40)]).describe('verbs'),
53
+ palette: z.tuple([z.string().min(1).max(40), z.string().min(1).max(40), z.string().min(1).max(40)]).describe('palette'),
54
+ texture: z.string().min(1).max(64).describe('texture'),
55
+ }).optional().describe('catalog'),
56
+ }).optional().describe('look');
16
57
  export const definitionSchema = z.object({
17
58
  kind: id,
18
- title: z.string().min(1).max(120),
19
- tagline: z.string().min(1).max(240),
20
- setting: z.string().min(1).max(2000),
21
- startClock: z.number().int().min(0).max(1_000_000),
59
+ look: lookSchema,
60
+ title: z.string().min(1).max(120).describe(phrase('schema.description.75')),
61
+ tagline: z.string().min(1).max(240).describe(phrase('schema.description.76')),
62
+ setting: z.string().min(1).max(2000).describe(phrase('schema.description.77')),
63
+ startClock: z.number().int().min(0).max(MAX_BOUND).describe(phrase('schema.description.78')),
64
+ calendar: calendarSchema.default(DEFAULT_CALENDAR).describe(phrase('schema.description.79')),
65
+ travel: z.object({ steps: z.number().int().min(1).max(MAX_BOUND).describe(phrase('schema.description.80')) }).default({ steps: 1 }).describe(phrase('schema.description.81')),
22
66
  // A live world runs on the server clock at this many game minutes per real minute.
23
- clock: z.object({ rate: z.number().int().min(1).max(MAX_CLOCK_RATE) }).optional(),
67
+ clock: z.object({ rate: z.number().int().min(1).max(MAX_CLOCK_RATE).describe(phrase('schema.description.82')) }).optional().describe(phrase('schema.description.83')),
24
68
  // How private messages travel here, such as "by a runner", and the game minutes they take.
25
69
  // Left out, messages arrive at once, as by phone.
26
- messages: messageTravelSchema.optional(),
27
- currency: z.object({ symbol: z.string().min(1).max(4), name: z.string().min(1).max(40) }).nullable(),
28
- // Money kept apart from anyone's purse; one held by no one moves only by the world's own happenings.
29
- accounts: z.array(z.object({ id, name: z.string().min(1).max(200), holderId: id.nullable().default(null), balance: z.number(), allowsDebt: z.boolean().default(false) })).default([]),
70
+ messages: messageTravelSchema.optional().describe(phrase('schema.description.84')),
71
+ units: z.array(unitSchema).default([]).describe(phrase('schema.description.85')),
72
+ numbers: z.array(numberSlotSchema).default([]).describe(phrase('schema.description.86')),
73
+ channels: z.array(channelSchema).default([]).describe(phrase('schema.description.87')),
30
74
  places: z.array(z.object({
31
75
  id,
32
- name: z.string().min(1).max(120),
33
- kind: z.enum(['room', 'outdoors', 'transit', 'private']),
34
- summary: z.string().min(1).max(2000),
35
- connections: z.array(id),
36
- conditions: z.array(z.string().min(1).max(200)).default([]),
37
- })).min(2),
76
+ name: z.string().min(1).max(120).describe(phrase('schema.description.88')),
77
+ summary: z.string().min(1).max(2000).describe(phrase('schema.description.89')),
78
+ containerId: id.nullable().default(null).describe(phrase('schema.description.90')),
79
+ connections: z.array(id).describe(phrase('schema.description.91')),
80
+ edgeCosts: z.record(id, z.number().int().min(1).max(MAX_BOUND)).optional().describe(phrase('schema.description.92')),
81
+ conditions: z.array(z.string().min(1).max(200)).default([]).describe(phrase('schema.description.93')),
82
+ numbers: z.record(id, z.number().finite()).default({}).describe(phrase('schema.description.94')),
83
+ })).min(2).describe(phrase('schema.description.95')),
38
84
  player: z.object({
39
85
  id,
40
- name: z.string().min(1).max(120),
41
- role: z.string().min(1).max(120),
42
- roleId: id.nullable().default(null),
43
- summary: z.string().min(1).max(2000),
44
- pronouns: z.string().min(1).max(40).optional(),
86
+ name: z.string().min(1).max(120).describe(phrase('schema.description.96')),
87
+ role: z.string().min(1).max(120).describe(phrase('schema.description.97')),
88
+ roleId: id.nullable().default(null).describe(phrase('schema.description.98')),
89
+ summary: z.string().min(1).max(2000).describe(phrase('schema.description.99')),
90
+ pronouns: z.string().min(1).max(40).optional().describe(phrase('schema.description.100')),
45
91
  placeId: id,
46
- money: z.number().nullable(),
47
- }),
92
+ numbers: z.record(id, z.number().finite()).default({}).describe(phrase('schema.description.101')),
93
+ }).describe(phrase('schema.description.102')),
48
94
  cast: z.array(z.object({
49
95
  id,
50
- name: z.string().min(1).max(120),
51
- role: z.string().min(1).max(120),
52
- roleId: id.nullable().default(null),
53
- summary: z.string().min(1).max(2000),
54
- persona: z.string().min(1).max(2000).optional(),
55
- character: characterSchema.optional(),
56
- pronouns: z.string().min(1).max(40).optional(),
96
+ name: z.string().min(1).max(120).describe(phrase('schema.description.103')),
97
+ role: z.string().min(1).max(120).describe(phrase('schema.description.104')),
98
+ roleId: id.nullable().default(null).describe(phrase('schema.description.98')),
99
+ summary: z.string().min(1).max(2000).describe(phrase('schema.description.105')),
100
+ persona: z.string().min(1).max(2000).optional().describe(phrase('schema.description.106')),
101
+ character: characterSchema.optional().describe(phrase('schema.description.107')),
102
+ pronouns: z.string().min(1).max(40).optional().describe(phrase('schema.description.108')),
57
103
  placeId: id,
58
- money: z.number().nullable(),
59
- mood: z.string().min(1).max(120),
60
- goals: z.array(z.string().min(1).max(600)),
61
- beliefs: z.array(z.object({ subject: z.string().min(1).max(200), claim: z.string().min(1).max(600) })),
62
- relationships: z.record(id, z.object({ trust: z.number().int().min(-100).max(100), warmth: z.number().int().min(-100).max(100), note: z.string().max(600) })),
63
- plan: z.object({ intent: z.string().min(1).max(600), seen: z.string().min(1).max(200).optional(), placeId: id.nullable(), targetId: id.nullable(), inMinutes: z.number().int().min(1).max(100_000) }).nullable(),
104
+ knownPlaceIds: z.array(id).default([]).describe(phrase('schema.description.109')),
105
+ numbers: z.record(id, z.number().finite()).default({}).describe(phrase('schema.description.110')),
106
+ mood: z.string().min(1).max(120).describe(phrase('schema.description.111')),
107
+ goals: z.array(z.string().min(1).max(600)).describe(phrase('schema.description.112')),
108
+ beliefs: z.array(z.object({
109
+ subject: z.string().min(1).max(200).describe(phrase('schema.description.113')),
110
+ claim: z.string().min(1).max(600).describe(phrase('schema.description.114')),
111
+ })).describe(phrase('schema.description.115')),
112
+ relationships: z.record(id, z.object({
113
+ trust: z.number().int().min(-100).max(100).describe(phrase('schema.description.116')),
114
+ warmth: z.number().int().min(-100).max(100).describe(phrase('schema.description.117')),
115
+ note: z.string().max(600).describe(phrase('schema.description.118')),
116
+ })).describe(phrase('schema.description.119')),
117
+ plan: z.object({
118
+ intent: z.string().min(1).max(600).describe(phrase('schema.description.120')),
119
+ seen: z.string().min(1).max(200).optional().describe(phrase('schema.description.121')),
120
+ placeId: id.nullable().describe(phrase('schema.description.122')),
121
+ targetId: id.nullable().describe(phrase('schema.description.123')),
122
+ inMinutes: z.number().int().min(1).max(MAX_BOUND).describe(phrase('schema.description.124')),
123
+ }).nullable().describe(phrase('schema.description.125')),
64
124
  // The player starts knowing where this person is when the opening says so.
65
- knownAtStart: z.boolean().default(false),
66
- }).refine(person => person.persona !== undefined || person.character !== undefined, 'A character needs a profile')).min(2),
125
+ knownAtStart: z.boolean().default(false).describe(phrase('schema.description.126')),
126
+ }).refine(person => person.persona !== undefined || person.character !== undefined, 'A character needs a profile')).min(2).describe(phrase('schema.description.127')),
67
127
  objects: z.array(z.object({
68
128
  id,
69
- name: z.string().min(1).max(120),
70
- summary: z.string().min(1).max(2000),
71
- placeId: id.nullable(),
72
- holderId: id.nullable(),
73
- ownerId: id.nullable(),
74
- condition: z.string().min(1).max(200),
75
- singlePersonMovable: z.boolean().default(true),
129
+ name: z.string().min(1).max(120).describe(phrase('schema.description.128')),
130
+ summary: z.string().min(1).max(2000).describe(phrase('schema.description.129')),
131
+ containerId: id.nullable().describe(phrase('schema.description.130')),
132
+ ownerId: id.nullable().describe(phrase('schema.description.131')),
133
+ condition: z.string().min(1).max(200).describe(phrase('schema.description.132')),
134
+ singlePersonMovable: z.boolean().default(true).describe(phrase('schema.description.133')),
76
135
  // A hidden thing is seen only by those who know where it is: these people, and its holder.
77
- knownTo: z.array(id).max(64).optional(), hidden: z.boolean().optional(),
78
- })),
79
- kinds: z.array(kindDefinitionSchema).default([]),
136
+ knownTo: z.array(id).max(64).optional().describe(phrase('schema.description.134')),
137
+ hidden: z.boolean().optional().describe(phrase('schema.description.135')),
138
+ })).describe(phrase('schema.description.136')),
139
+ kinds: z.array(kindDefinitionSchema).default([]).describe(phrase('schema.description.137')),
80
140
  entities: z.array(z.object({
81
- id, kindId: id, name: z.string().min(1).max(200), placeId: id.nullable().default(null),
82
- properties: z.record(id, propertyValueSchema).default({}), relations: z.record(id, id).default({}),
83
- // A decision's voting members, and the world's problem its result settles.
84
- members: z.array(id).min(1).max(12).optional(), settles: id.optional(),
141
+ id, kindId: id, name: z.string().min(1).max(200).describe(phrase('schema.description.138')), containerId: id.nullable().default(null).describe(phrase('schema.description.139')),
142
+ properties: z.record(id, propertyValueSchema).default({}).describe(phrase('schema.description.140')), relations: z.record(id, id).default({}).describe(phrase('schema.description.141')), numbers: z.record(id, z.number().finite()).default({}).describe(phrase('schema.description.142')),
85
143
  // Who knows it from the start; left out, everyone in the world does. A hidden thing is not seen by
86
144
  // whoever comes to its place.
87
- knownTo: z.array(id).max(64).optional(), hidden: z.boolean().optional(),
88
- // Money that moves when the decision passes.
89
- transfers: z.array(z.object({ fromId: id.nullable(), toId: id.nullable(), amount: z.number().positive().max(1_000_000_000) })).max(4).optional(),
90
- })).default([]),
145
+ knownTo: z.array(id).max(64).optional().describe(phrase('schema.description.143')), hidden: z.boolean().optional().describe(phrase('schema.description.144')),
146
+ })).default([]).describe(phrase('schema.description.145')),
91
147
  // A fact may name its aspect, so a later happening can replace it, such as a deadline that has passed.
92
- facts: z.array(z.union([z.string().min(1).max(600), z.object({ aspect: id, text: z.string().min(1).max(600) })])),
93
- opening: z.object({ title: z.string().min(1).max(200), situation: z.string().min(1).max(2000), stakes: z.string().min(1).max(2000) }),
94
- tension: z.object({ id, title: z.string().min(1).max(200), summary: z.string().min(1).max(2000), participantIds: z.array(id) }),
95
- playerRelationships: z.record(id, z.object({ trust: z.number().int().min(-100).max(100), warmth: z.number().int().min(-100).max(100), note: z.string().max(600) })).default({}),
148
+ facts: z.array(z.union([z.string().min(1).max(600), z.object({
149
+ aspect: id.describe(phrase('schema.description.146')),
150
+ text: z.string().min(1).max(600).describe(phrase('schema.description.147')),
151
+ })])).describe(phrase('schema.description.148')),
152
+ opening: z.object({
153
+ title: z.string().min(1).max(200).describe(phrase('schema.description.149')),
154
+ situation: z.string().min(1).max(2000).describe(phrase('schema.description.150')),
155
+ stakes: z.string().min(1).max(2000).describe(phrase('schema.description.151')),
156
+ }).describe(phrase('schema.description.152')),
157
+ tension: z.object({
158
+ id,
159
+ title: z.string().min(1).max(200).describe(phrase('schema.description.153')),
160
+ summary: z.string().min(1).max(2000).describe(phrase('schema.description.154')),
161
+ participantIds: z.array(id).describe(phrase('schema.description.155')),
162
+ }).describe(phrase('schema.description.156')),
163
+ playerRelationships: z.record(id, z.object({
164
+ trust: z.number().int().min(-100).max(100).describe(phrase('schema.description.157')),
165
+ warmth: z.number().int().min(-100).max(100).describe(phrase('schema.description.158')),
166
+ note: z.string().max(600).describe(phrase('schema.description.118')),
167
+ })).default({}).describe(phrase('schema.description.159')),
96
168
  // Beats are the happenings the opening promises (the ambulances, the storm, the vote).
97
169
  // The world carries them out when they fall due, whatever the player does.
98
170
  // A beat with everyMinutes comes back after each time it happens: visitors, deliveries, shift changes.
99
- beats: z.array(z.object({ id, inMinutes: z.number().int().min(1).max(100_000), placeId: id, text: z.string().min(1).max(600),
100
- everyMinutes: z.number().int().min(1).max(100_000).optional(),
101
- // What it concerns, and the typed results the world's data gives it (see docs/world-data.md).
102
- concerns: id.optional(), ...beatRulesSchema.shape })).default([]),
171
+ beats: z.array(z.object({ id, inMinutes: z.number().int().min(1).max(MAX_BOUND).describe(phrase('schema.description.160')), placeId: id, text: z.string().min(1).max(600).describe(phrase('schema.description.161')),
172
+ everyMinutes: z.number().int().min(1).max(MAX_BOUND).optional().describe(phrase('schema.description.162')),
173
+ concerns: id.optional().describe(phrase('schema.description.163')), ...beatRulesSchema.shape })).default([]).describe(phrase('schema.description.164')),
103
174
  });
175
+ export function definitionJsonSchema() {
176
+ return z.toJSONSchema(definitionSchema, { io: 'input' });
177
+ }
104
178
  export function parseLivingWorldDefinition(value) {
105
179
  const parsed = definitionSchema.safeParse(value);
106
180
  if (!parsed.success)
107
181
  throw new LivingWorldError('definition-invalid', parsed.error.message);
108
182
  const definition = parsed.data;
109
183
  const placeIds = new Set(definition.places.map(place => place.id));
110
- const peopleIds = new Set([definition.player.id, ...definition.cast.map(person => person.id)]);
111
- if (peopleIds.size !== definition.cast.length + 1)
112
- throw new LivingWorldError('definition-invalid', 'Every person needs a distinct id');
113
- for (const place of definition.places) {
114
- for (const connection of place.connections) {
184
+ const people = [definition.player, ...definition.cast];
185
+ const peopleIds = new Set(people.map(person => person.id));
186
+ checkDistinctIds(people.map((person, index) => ({ id: person.id, path: index === 0 ? 'player.id' : `cast[${index - 1}].id` })), 'person', 'player,cast');
187
+ for (const [index, place] of definition.places.entries()) {
188
+ const at = `places[${index}]`;
189
+ for (const [connectionIndex, connection] of place.connections.entries()) {
115
190
  if (!placeIds.has(connection))
116
- throw new LivingWorldError('definition-invalid', `Place ${place.id} connects to unknown place ${connection}`);
191
+ definitionProblem(`${at}.connections[${connectionIndex}]`, connection, phrase('definition.notPlace'), choiceText(phrase('definition.label.places'), placeIds, 'places', `${at}.connections[${connectionIndex}]`));
117
192
  if (connection === place.id)
118
- throw new LivingWorldError('definition-invalid', `Place ${place.id} connects to itself`);
193
+ definitionProblem(`${at}.connections[${connectionIndex}]`, connection, phrase('definition.selfPlace'), choiceText(phrase('definition.label.places'), [...placeIds].filter(id => id !== place.id), 'places', `${at}.connections[${connectionIndex}]`));
194
+ }
195
+ for (const [connection, cost] of Object.entries(place.edgeCosts ?? {})) {
196
+ if (!place.connections.includes(connection))
197
+ definitionProblem(`${at}.edgeCosts.${connection}`, connection, phrase('definition.notConnection'), choiceText(phrase('definition.label.connections'), place.connections, `${at}.connections`, `${at}.edgeCosts.${connection}`));
198
+ if (cost < 1)
199
+ definitionProblem(`${at}.edgeCosts.${connection}`, cost, phrase('definition.edgeCost'), phrase('definition.edgeCostValid'));
119
200
  }
201
+ if (place.containerId !== null && !placeIds.has(place.containerId))
202
+ definitionProblem(`${at}.containerId`, place.containerId, phrase('definition.notPlace'), choiceText(phrase('definition.label.places'), placeIds, 'places', `${at}.containerId`));
120
203
  }
121
- for (const person of [definition.player, ...definition.cast]) {
204
+ checkDistinctIds(definition.channels.map((channel, index) => ({ id: channel.id, path: `channels[${index}].id` })), 'channel', 'channels');
205
+ checkCalendar(definition.calendar);
206
+ for (const [index, person] of people.entries()) {
207
+ const at = index === 0 ? 'player' : `cast[${index - 1}]`;
122
208
  if (!placeIds.has(person.placeId))
123
- throw new LivingWorldError('definition-invalid', `${person.id} starts in unknown place ${person.placeId}`);
209
+ definitionProblem(`${at}.placeId`, person.placeId, phrase('definition.notPlace'), choiceText(phrase('definition.label.places'), placeIds, 'places', `${at}.placeId`));
124
210
  }
125
- for (const person of definition.cast) {
211
+ for (const [index, person] of definition.cast.entries()) {
212
+ const at = `cast[${index}]`;
213
+ for (const [knownIndex, knownPlaceId] of person.knownPlaceIds.entries()) {
214
+ if (!placeIds.has(knownPlaceId))
215
+ definitionProblem(`${at}.knownPlaceIds[${knownIndex}]`, knownPlaceId, phrase('definition.notPlace'), choiceText(phrase('definition.label.places'), placeIds, 'places', `${at}.knownPlaceIds[${knownIndex}]`));
216
+ }
126
217
  for (const target of Object.keys(person.relationships)) {
127
218
  if (!peopleIds.has(target))
128
- throw new LivingWorldError('definition-invalid', `${person.id} relates to unknown person ${target}`);
219
+ definitionProblem(`${at}.relationships.${target}`, target, phrase('definition.notPerson'), choiceText(phrase('definition.label.people'), peopleIds, 'player,cast', `${at}.relationships.${target}`));
129
220
  }
130
221
  if (person.plan?.placeId && !placeIds.has(person.plan.placeId))
131
- throw new LivingWorldError('definition-invalid', `${person.id} plans to reach unknown place ${person.plan.placeId}`);
222
+ definitionProblem(`${at}.plan.placeId`, person.plan.placeId, phrase('definition.notPlace'), choiceText(phrase('definition.label.places'), placeIds, 'places', `${at}.plan.placeId`));
132
223
  }
133
224
  for (const target of Object.keys(definition.playerRelationships)) {
134
225
  if (!peopleIds.has(target))
135
- throw new LivingWorldError('definition-invalid', `Player relates to unknown person ${target}`);
226
+ definitionProblem(`playerRelationships.${target}`, target, phrase('definition.notPerson'), choiceText(phrase('definition.label.people'), peopleIds, 'player,cast', `playerRelationships.${target}`));
136
227
  }
137
- for (const object of definition.objects) {
138
- if (object.placeId !== null && !placeIds.has(object.placeId))
139
- throw new LivingWorldError('definition-invalid', `${object.id} sits in unknown place ${object.placeId}`);
140
- if (object.holderId !== null && !peopleIds.has(object.holderId))
141
- throw new LivingWorldError('definition-invalid', `${object.id} is held by unknown person ${object.holderId}`);
228
+ for (const [index, object] of definition.objects.entries()) {
229
+ const at = `objects[${index}]`;
230
+ if (object.containerId !== null && !placeIds.has(object.containerId) && !peopleIds.has(object.containerId)) {
231
+ definitionProblem(`${at}.containerId`, object.containerId, phrase('definition.notContainer'), choiceText(phrase('definition.label.containers'), [...placeIds, ...peopleIds], 'places,player,cast', `${at}.containerId`));
232
+ }
142
233
  if (object.ownerId !== null && !peopleIds.has(object.ownerId))
143
- throw new LivingWorldError('definition-invalid', `${object.id} is owned by unknown person ${object.ownerId}`);
144
- if ((object.placeId === null) === (object.holderId === null))
145
- throw new LivingWorldError('definition-invalid', `${object.id} needs exactly one of a place or a holder`);
234
+ definitionProblem(`${at}.ownerId`, object.ownerId, phrase('definition.notPerson'), choiceText(phrase('definition.label.people'), peopleIds, 'player,cast', `${at}.ownerId`));
146
235
  }
147
- for (const participant of definition.tension.participantIds) {
236
+ for (const [index, participant] of definition.tension.participantIds.entries()) {
148
237
  if (!peopleIds.has(participant))
149
- throw new LivingWorldError('definition-invalid', `Tension names unknown person ${participant}`);
238
+ definitionProblem(`tension.participantIds[${index}]`, participant, phrase('definition.notPerson'), choiceText(phrase('definition.label.people'), peopleIds, 'player,cast', `tension.participantIds[${index}]`));
239
+ }
240
+ const unitIds = new Set(definition.units.map(unit => unit.id));
241
+ checkDistinctIds(definition.units.map((unit, index) => ({ id: unit.id, path: `units[${index}].id` })), 'unit', 'units');
242
+ const numberIds = new Set(definition.numbers.map(number => number.id));
243
+ checkDistinctIds(definition.numbers.map((number, index) => ({ id: number.id, path: `numbers[${index}].id` })), 'number', 'numbers');
244
+ for (const [index, number] of definition.numbers.entries()) {
245
+ if (!unitIds.has(number.unit))
246
+ definitionProblem(`numbers[${index}].unit`, number.unit, phrase('definition.notUnit'), choiceText(phrase('definition.label.units'), unitIds, 'units', `numbers[${index}].unit`));
247
+ if (number.min !== null && number.max !== null && number.min > number.max)
248
+ definitionProblem(`numbers[${index}].min`, number.min, phrase('definition.minAboveMax'), phrase('definition.maxValid', { max: number.max }));
150
249
  }
151
- const accountIds = new Set(definition.accounts.map(account => account.id));
152
- if (accountIds.size !== definition.accounts.length)
153
- throw new LivingWorldError('definition-invalid', 'Every account needs a distinct id');
154
- for (const account of definition.accounts) {
155
- if (peopleIds.has(account.id))
156
- throw new LivingWorldError('definition-invalid', `Account ${account.id} has the id of a person`);
157
- if (account.holderId !== null && !peopleIds.has(account.holderId))
158
- throw new LivingWorldError('definition-invalid', `Account ${account.id} is held by unknown person ${account.holderId}`);
250
+ const holderEntries = [
251
+ ...people.map((person, index) => ({ holder: person, path: index === 0 ? 'player' : `cast[${index - 1}]` })),
252
+ ...definition.places.map((place, index) => ({ holder: place, path: `places[${index}]` })),
253
+ ...definition.entities.map((entity, index) => ({ holder: entity, path: `entities[${index}]` })),
254
+ ];
255
+ checkDistinctIds(holderEntries.map(entry => ({ id: entry.holder.id, path: `${entry.path}.id` })), 'holder', 'player,cast,places,entities');
256
+ for (const entry of holderEntries) {
257
+ for (const [slotId, amount] of Object.entries(entry.holder.numbers)) {
258
+ const number = definition.numbers.find(candidate => candidate.id === slotId);
259
+ if (number === undefined)
260
+ definitionProblem(`${entry.path}.numbers.${slotId}`, slotId, phrase('definition.notNumber'), choiceText(phrase('definition.label.numberSlots'), numberIds, 'numbers', `${entry.path}.numbers.${slotId}`));
261
+ if (number.min !== null && amount < number.min)
262
+ definitionProblem(`${entry.path}.numbers.${slotId}`, amount, phrase('definition.belowMin'), phrase('definition.atLeast', { min: number.min }));
263
+ if (number.max !== null && amount > number.max)
264
+ definitionProblem(`${entry.path}.numbers.${slotId}`, amount, phrase('definition.aboveMax'), phrase('definition.atMost', { max: number.max }));
265
+ }
159
266
  }
160
- // A vote names who may cast it and the problem it settles, and only a decision is voted on.
161
- for (const entity of definition.entities) {
162
- if ((entity.members !== undefined || entity.settles !== undefined || entity.transfers !== undefined) && entity.kindId !== 'decision' || entity.kindId === 'decision' && entity.members === undefined)
163
- throw new LivingWorldError('definition-invalid', `${entity.id}: a decision, and only a decision, names its members`);
164
- for (const member of entity.members ?? [])
165
- if (!peopleIds.has(member))
166
- throw new LivingWorldError('definition-invalid', `${entity.id} names unknown member ${member}`);
167
- for (const knower of entity.knownTo ?? [])
267
+ const holders = holderEntries.map(entry => entry.holder);
268
+ const kindIds = new Set([...Object.keys(sharedKindMap()), ...definition.kinds.map(kind => kind.id)]);
269
+ for (const [index, entity] of definition.entities.entries()) {
270
+ const at = `entities[${index}]`;
271
+ if (!kindIds.has(entity.kindId))
272
+ definitionProblem(`${at}.kindId`, entity.kindId, phrase('definition.notKind'), choiceText(phrase('definition.label.kinds'), kindIds, 'kinds', `${at}.kindId`));
273
+ if (entity.containerId !== null && !placeIds.has(entity.containerId) && !peopleIds.has(entity.containerId)) {
274
+ definitionProblem(`${at}.containerId`, entity.containerId, phrase('definition.notContainer'), choiceText(phrase('definition.label.containers'), [...placeIds, ...peopleIds], 'places,player,cast', `${at}.containerId`));
275
+ }
276
+ for (const [knownIndex, knower] of (entity.knownTo ?? []).entries()) {
168
277
  if (!peopleIds.has(knower))
169
- throw new LivingWorldError('definition-invalid', `${entity.id} is known to unknown person ${knower}`);
170
- if (entity.settles !== undefined && entity.settles !== definition.tension.id)
171
- throw new LivingWorldError('definition-invalid', `${entity.id} settles unknown problem ${entity.settles}`);
172
- for (const end of (entity.transfers ?? []).flatMap(transfer => [transfer.fromId, transfer.toId])) {
173
- const person = [definition.player, ...definition.cast].find(candidate => candidate.id === end);
174
- if (end !== null && !accountIds.has(end) && person?.money === undefined)
175
- throw new LivingWorldError('definition-invalid', `${entity.id} moves money through unknown person or account ${end}`);
176
- if (person?.money === null)
177
- throw new LivingWorldError('definition-invalid', `${entity.id} moves money through ${person.name}, who keeps no money in this world`);
278
+ definitionProblem(`${at}.knownTo[${knownIndex}]`, knower, phrase('definition.notPerson'), choiceText(phrase('definition.label.people'), peopleIds, 'player,cast', `${at}.knownTo[${knownIndex}]`));
178
279
  }
179
280
  }
180
- for (const object of definition.objects) {
181
- for (const knower of object.knownTo ?? [])
281
+ for (const [index, object] of definition.objects.entries()) {
282
+ for (const [knownIndex, knower] of (object.knownTo ?? []).entries()) {
182
283
  if (!peopleIds.has(knower))
183
- throw new LivingWorldError('definition-invalid', `${object.id} is known to unknown person ${knower}`);
284
+ definitionProblem(`objects[${index}].knownTo[${knownIndex}]`, knower, phrase('definition.notPerson'), choiceText(phrase('definition.label.people'), peopleIds, 'player,cast', `objects[${index}].knownTo[${knownIndex}]`));
285
+ }
184
286
  }
185
287
  const aspects = definition.facts.flatMap(fact => typeof fact === 'string' ? [] : [fact.aspect]);
186
- const repeated = aspects.filter((aspect, index) => aspects.indexOf(aspect) !== index);
187
- if (repeated.length > 0)
188
- throw new LivingWorldError('definition-invalid', `Every fact aspect is named once; ${repeated.join(', ')} is repeated`);
288
+ const seenAspects = new Map();
289
+ for (const [index, fact] of definition.facts.entries()) {
290
+ if (typeof fact === 'string')
291
+ continue;
292
+ const first = seenAspects.get(fact.aspect);
293
+ if (first !== undefined)
294
+ definitionProblem(`facts[${index}].aspect`, fact.aspect, phrase('definition.repeatsFact', { first }), choiceText(phrase('definition.label.aspects'), aspects, 'facts', `facts[${index}].aspect`));
295
+ seenAspects.set(fact.aspect, index);
296
+ }
189
297
  // A beat's typed results name only what the world has, or they would change nothing when it falls due.
190
298
  const thingIds = new Set([...definition.objects.map(object => object.id), ...definition.entities.map(entity => entity.id)]);
191
- const people = [definition.player, ...definition.cast];
192
- for (const beat of definition.beats) {
193
- const refuse = (message) => new LivingWorldError('definition-invalid', `Beat ${beat.id} ${message}`);
194
- if (!placeIds.has(beat.placeId))
195
- throw refuse(`happens in unknown place ${beat.placeId}`);
196
- if (beat.concerns !== undefined && !thingIds.has(beat.concerns) && !peopleIds.has(beat.concerns) && !placeIds.has(beat.concerns) && beat.concerns !== definition.tension.id) {
197
- throw refuse(`concerns ${beat.concerns}, which is no thing, person, place or problem of this world`);
198
- }
199
- if (beat.unless !== undefined && beat.unless.settled !== definition.tension.id)
200
- throw refuse(`waits on unknown problem ${beat.unless.settled}`);
201
- if (beat.then?.tension !== undefined && beat.then.tension.id !== definition.tension.id)
202
- throw refuse(`changes unknown problem ${beat.then.tension.id}`);
203
- for (const fact of beat.then?.facts ?? [])
204
- if (!aspects.includes(fact.aspect))
205
- throw refuse(`changes fact aspect ${fact.aspect}, which no fact of this world has`);
206
- for (const end of (beat.then?.transfers ?? []).flatMap(transfer => [transfer.fromId, transfer.toId])) {
207
- if (end === null || accountIds.has(end))
208
- continue;
209
- const person = people.find(candidate => candidate.id === end);
210
- if (person === undefined)
211
- throw refuse(`moves money through unknown person or account ${end}`);
212
- if (person.money === null)
213
- throw refuse(`moves money through ${person.name}, who keeps no money in this world`);
214
- }
299
+ for (const [index, beat] of definition.beats.entries()) {
300
+ checkBeat(beat, `beats[${index}]`, { aspects, placeIds, thingIds, peopleIds, tensionId: definition.tension.id, numberIds, holders });
215
301
  }
216
- if (new Set(definition.beats.map(beat => beat.id)).size !== definition.beats.length)
217
- throw new LivingWorldError('definition-invalid', 'Every beat needs a distinct id');
218
- const objectIds = new Set(definition.objects.map(object => object.id));
219
- if (objectIds.size !== definition.objects.length)
220
- throw new LivingWorldError('definition-invalid', 'Every object needs a distinct id');
302
+ checkDistinctIds(definition.beats.map((beat, index) => ({ id: beat.id, path: `beats[${index}].id` })), 'beat', 'beats');
303
+ checkDistinctIds(definition.objects.map((object, index) => ({ id: object.id, path: `objects[${index}].id` })), 'object', 'objects');
221
304
  return definition;
222
305
  }
306
+ export function parseKindRevision(previous, proposed) {
307
+ const parsed = kindDefinitionSchema.safeParse(proposed);
308
+ if (!parsed.success)
309
+ throw new LivingWorldError('definition-invalid', parsed.error.message);
310
+ if (narrowsKindRevision(previous, parsed.data))
311
+ throw new LivingWorldError('narrows-revision', `Kind ${previous.id} revision narrows it; a revision may only add slots, options, mechanics and laws`);
312
+ return parsed.data;
313
+ }
223
314
  // Revision 0 holds only authored facts. The opening event is the first accepted event.
224
- export function createLivingState(definition, seed, engine = LIVING_ENGINE_VERSION) {
315
+ export function createLivingState(definition, seed) {
316
+ const calendar = definition.calendar ?? DEFAULT_CALENDAR;
225
317
  const person = (input) => ({
226
318
  id: input.id,
227
319
  name: input.name,
@@ -233,12 +325,12 @@ export function createLivingState(definition, seed, engine = LIVING_ENGINE_VERSI
233
325
  ...(input.pronouns ? { pronouns: input.pronouns } : {}),
234
326
  isPlayer: false,
235
327
  placeId: input.placeId,
236
- money: input.money,
328
+ knownPlaceIds: [...new Set([...(input.knownPlaceIds ?? []), ...(input.plan?.placeId ? [input.plan.placeId] : [])])],
237
329
  mood: input.mood,
238
- goals: input.goals.map((text, index) => ({ id: generatedId(engine, 'goal', [input.id, index + 1], `${input.id}-goal-${index + 1}`), text, status: 'active' })),
330
+ goals: input.goals.map((text, index) => ({ id: generatedId(LIVING_ENGINE_VERSION, 'goal', [input.id, index + 1], `${input.id}-goal-${index + 1}`), text, status: 'active' })),
239
331
  relationships: { ...input.relationships },
240
- beliefs: (engine >= BOUNDED_PERSON_RECORDS_ENGINE ? input.beliefs.slice(-MAX_WORKING_BELIEFS) : input.beliefs).map((belief, index) => ({
241
- id: generatedId(engine, 'belief', [input.id, index + 1], `${input.id}-belief-${index + 1}`), subject: belief.subject, claim: belief.claim,
332
+ beliefs: ((input.beliefs.slice(-MAX_WORKING_BELIEFS))).map((belief, index) => ({
333
+ id: generatedId(LIVING_ENGINE_VERSION, 'belief', [input.id, index + 1], `${input.id}-belief-${index + 1}`), subject: belief.subject, claim: belief.claim,
242
334
  source: { kind: 'initial', personId: null, eventSeq: 0 }, at: definition.startClock,
243
335
  })),
244
336
  memories: [],
@@ -257,7 +349,7 @@ export function createLivingState(definition, seed, engine = LIVING_ENGINE_VERSI
257
349
  ...(definition.player.pronouns ? { pronouns: definition.player.pronouns } : {}),
258
350
  isPlayer: true,
259
351
  placeId: definition.player.placeId,
260
- money: definition.player.money,
352
+ knownPlaceIds: [],
261
353
  mood: 'Present',
262
354
  goals: [],
263
355
  relationships: Object.fromEntries(definition.cast.map(other => [other.id, definition.playerRelationships[other.id] ?? { trust: 0, warmth: 0, note: '' }])),
@@ -269,21 +361,24 @@ export function createLivingState(definition, seed, engine = LIVING_ENGINE_VERSI
269
361
  };
270
362
  const state = {
271
363
  schemaVersion: LIVING_SCHEMA_VERSION,
272
- engine,
364
+ engine: LIVING_ENGINE_VERSION,
365
+ admissionCapsFrom: 1,
273
366
  gameKind: definition.kind,
274
367
  seed,
275
368
  revision: 0,
276
369
  clock: definition.startClock,
277
370
  startClock: definition.startClock,
371
+ calendar: { ...calendar, ...(calendar.rest === null ? {} : { rest: { ...calendar.rest } }) },
372
+ travelSteps: definition.travel?.steps ?? 1,
278
373
  status: 'open',
279
374
  playerId: player.id,
280
- places: Object.fromEntries(definition.places.map(place => [place.id, { ...place, conditions: [...place.conditions], conditionAspects: {}, connections: [...place.connections], introducedAt: 0 }])),
375
+ places: Object.fromEntries(definition.places.map(place => [place.id, { ...place, containerId: place.containerId ?? null, conditions: [...place.conditions], conditionAspects: {}, connections: [...place.connections], edgeCosts: { ...(place.edgeCosts ?? {}) }, introducedAt: 0 }])),
281
376
  people: Object.fromEntries([player, ...definition.cast.map(person)].map(entry => [entry.id, entry])),
282
377
  objects: Object.fromEntries(definition.objects.map(({ knownTo, hidden, ...object }) => [object.id, {
283
- ...object, introducedAt: 0, ...(hidden ? { hidden: true } : {}),
284
- custodyKnownTo: [...new Set([...(object.holderId && definition.cast.some(person => person.id === object.holderId
378
+ ...object, containerId: object.containerId ?? null, introducedAt: 0, ...(hidden ? { hidden: true } : {}),
379
+ custodyKnownTo: [...new Set([...(object.containerId && definition.cast.some(person => person.id === object.containerId
285
380
  && (person.knownAtStart || person.placeId === definition.player.placeId)) ? [definition.player.id] : []), ...(knownTo ?? [])])],
286
- conditionKnownTo: object.placeId === definition.player.placeId || object.holderId === definition.player.id
381
+ conditionKnownTo: object.containerId === definition.player.placeId || object.containerId === definition.player.id
287
382
  ? [definition.player.id] : [],
288
383
  }])),
289
384
  facts: definition.facts.map(fact => typeof fact === 'string' ? fact : fact.text),
@@ -293,49 +388,61 @@ export function createLivingState(definition, seed, engine = LIVING_ENGINE_VERSI
293
388
  requests: [],
294
389
  stances: [],
295
390
  tensions: [{ ...definition.tension, participantIds: [...definition.tension.participantIds], status: 'open', resolution: null, changedAt: definition.startClock,
296
- playerView: { title: definition.tension.title, summary: definition.tension.summary, status: 'open', resolution: null, ...(engine >= PROBLEM_VIEW_ENGINE ? { since: definition.startClock } : {}) } }],
391
+ playerView: { title: definition.tension.title, summary: definition.tension.summary, status: 'open', resolution: null, ...(({ since: definition.startClock })) } }],
297
392
  schedule: [
298
393
  ...definition.cast.flatMap(member => member.plan ? [{
299
- id: generatedId(engine, 'opening-plan', [member.id], `${member.id}-opening-plan`, true), at: definition.startClock + member.plan.inMinutes, personId: member.id, kind: 'plan',
394
+ id: generatedId(LIVING_ENGINE_VERSION, 'opening-plan', [member.id], `${member.id}-opening-plan`, true), at: definition.startClock + member.plan.inMinutes, personId: member.id, kind: 'plan',
300
395
  intent: member.plan.intent, placeId: member.plan.placeId, targetId: member.plan.targetId, sourceSeq: 0, importance: 3,
301
396
  }] : []),
302
397
  ...definition.beats.map(beat => {
303
398
  const { id: beatId, inMinutes, placeId, text, everyMinutes, concerns, ...rules } = beat;
304
- const typed = engine >= DEADLINE_ENGINE && Object.keys(rules).length > 0;
399
+ const typed = (Object.keys(rules).length > 0);
305
400
  return {
306
- id: generatedId(engine, 'beat', [beatId]), at: definition.startClock + inMinutes, personId: null, kind: 'world',
307
- intent: text, placeId, targetId: engine >= DEADLINE_ENGINE ? concerns ?? null : null, sourceSeq: 0, importance: 5,
308
- ...(everyMinutes === undefined ? {} : { everyMinutes, series: generatedId(engine, 'beat', [beatId]) }),
401
+ id: generatedId(LIVING_ENGINE_VERSION, 'beat', [beatId]), at: definition.startClock + inMinutes, personId: null, kind: 'world',
402
+ intent: text, placeId, targetId: (concerns ?? null), sourceSeq: 0, importance: 5,
403
+ ...(everyMinutes === undefined ? {} : { everyMinutes, series: generatedId(LIVING_ENGINE_VERSION, 'beat', [beatId]) }),
309
404
  ...(typed ? { beat: { ...rules, ...(rules.deadline === undefined && rules.then !== undefined ? { deadline: true } : {}) } } : {}),
310
405
  };
311
406
  }),
312
- ].sort((a, b) => a.at - b.at || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0)),
407
+ ].sort((a, b) => a.at - b.at),
408
+ predictions: { items: [], fold: { count: 0, first: null, last: null, digest: '', provenance: 'predictions' } },
313
409
  sightings: Object.fromEntries(definition.cast.filter(member => member.knownAtStart || member.placeId === definition.player.placeId).map(member => [member.id, { placeId: member.placeId, at: definition.startClock }])),
314
410
  events: [],
315
411
  stoppingPoint: null,
316
412
  forcedEnding: null,
317
413
  epilogue: null,
318
414
  opening: { ...definition.opening },
319
- currency: definition.currency ? { ...definition.currency } : null,
320
- ...(definition.accounts.length === 0 ? {} : { accounts: Object.fromEntries(definition.accounts.map(account => [account.id, { ...account }])) }),
415
+ units: Object.fromEntries((definition.units ?? []).map(unit => [unit.id, { ...unit }])),
416
+ numbers: Object.fromEntries((definition.numbers ?? []).map(number => [number.id, { ...number }])),
417
+ channels: Object.fromEntries((definition.channels ?? []).map(channel => [channel.id, { ...channel }])),
418
+ holdings: Object.fromEntries([definition.player, ...definition.cast, ...definition.places, ...definition.entities]
419
+ .filter(holder => Object.keys(holder.numbers ?? {}).length > 0).map(holder => [holder.id, { ...holder.numbers }])),
420
+ outside: Object.fromEntries((definition.units ?? []).map(unit => [unit.id, 0])),
321
421
  setting: definition.setting,
322
422
  suggestions: [],
323
- kinds: sharedKindMap(engine),
423
+ kinds: sharedKindMap(),
324
424
  kindRequests: [],
325
425
  entities: {},
326
- entityPlaceIds: {},
426
+ pins: {},
427
+ touched: {},
428
+ parked: { count: 0, first: null, last: null, digest: '', provenance: 'parked' },
429
+ within: {},
327
430
  globalEntityIds: [],
328
431
  entityMoveSubjectIds: {},
329
432
  globalEntityRefs: {},
330
433
  worldEntityIds: {},
331
- meterSchedule: [],
332
434
  changes: [],
333
435
  clockRate: null,
334
436
  paused: false,
335
437
  clockAnchor: null,
336
- messageTravel: engine >= MESSAGE_TRAVEL_ENGINE && definition.messages ? { ...definition.messages } : null,
337
- chronicle: [],
338
- thingNotes: {},
438
+ messageTravel: (definition.messages) ? { ...definition.messages } : null,
439
+ chronicle: { items: [], fold: { count: 0, first: null, last: null, digest: '', provenance: 'chronicle' } },
440
+ thingNotes: { items: {}, fold: { count: 0, first: null, last: null, digest: '', provenance: 'thingNotes' } },
441
+ facetUse: { items: {}, fold: { count: 0, first: null, last: null, digest: '', provenance: 'facetUse' } },
442
+ rulings: 0,
443
+ notedRulings: 0,
444
+ stewardAt: null,
445
+ folds: {},
339
446
  };
340
447
  return parseLivingState(state);
341
448
  }