@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.
- package/README.md +629 -167
- package/RUST_THIRD_PARTY_LICENSES.txt +5 -5
- package/bin/zmux-darwin-arm64 +0 -0
- package/bin/zmux-linux-x64 +0 -0
- package/bin/ztc-audio-darwin-arm64 +0 -0
- package/bin/ztc-capture-darwin-arm64 +0 -0
- package/bin/ztc-computer-darwin-arm64 +0 -0
- package/bin/ztc-llm-darwin-arm64 +0 -0
- package/bin/ztc-tts-darwin-arm64 +0 -0
- package/bin/ztc-tui-darwin-arm64 +0 -0
- package/bin/ztc-tui-linux-x64 +0 -0
- package/bin/zterm-darwin-arm64 +2 -2
- package/dist/App.js +6 -1
- package/dist/agent/agent.d.ts +21 -15
- package/dist/agent/agent.js +389 -163
- package/dist/agent/backends/codex_app_server.d.ts +7 -1
- package/dist/agent/backends/codex_app_server.js +11 -1
- package/dist/agent/backends/gemini.js +22 -8
- package/dist/agent/commands/batch.js +8 -0
- package/dist/agent/commands/config.js +10 -0
- package/dist/agent/commands/environment.js +5 -5
- package/dist/agent/commands/goal.d.ts +1 -0
- package/dist/agent/commands/goal.js +2 -1
- package/dist/agent/commands/index.js +2 -1
- package/dist/agent/commands/manifest.js +4 -0
- package/dist/agent/commands/optimize.js +5 -2
- package/dist/agent/commands/pane_cli.d.ts +29 -0
- package/dist/agent/commands/pane_cli.js +303 -0
- package/dist/agent/commands/settings.js +13 -3
- package/dist/agent/commands/shannon.js +8 -0
- package/dist/agent/commands/update.js +15 -3
- package/dist/agent/commands/zerg.js +31 -1
- package/dist/agent/commands/ztc_pane.js +3 -1
- package/dist/agent/factory.d.ts +4 -0
- package/dist/agent/factory.js +11 -1
- package/dist/agent/loop_policy.d.ts +42 -5
- package/dist/agent/loop_policy.js +206 -3
- package/dist/agent/runtime/command_jobs.d.ts +5 -0
- package/dist/agent/runtime/command_jobs.js +241 -31
- package/dist/agent/runtime/command_wait.d.ts +2 -0
- package/dist/agent/runtime/command_wait.js +1 -0
- package/dist/agent/runtime/done_report.d.ts +18 -0
- package/dist/agent/runtime/done_report.js +130 -0
- package/dist/agent/runtime/execution_context.js +4 -1
- package/dist/agent/runtime/failure_cause.d.ts +2 -0
- package/dist/agent/runtime/failure_cause.js +35 -0
- package/dist/agent/runtime/policy.d.ts +14 -2
- package/dist/agent/runtime/policy.js +104 -12
- package/dist/agent/runtime/quiet_job.d.ts +18 -0
- package/dist/agent/runtime/quiet_job.js +48 -0
- package/dist/agent/runtime/recovery.d.ts +1 -5
- package/dist/agent/runtime/recovery.js +2 -44
- package/dist/agent/runtime/tool_runtime.d.ts +1 -0
- package/dist/agent/runtime/tool_runtime.js +2 -0
- package/dist/agent/subagent.js +6 -1
- package/dist/agent/tools/deferred.js +1 -0
- package/dist/agent/tools/index.d.ts +2 -0
- package/dist/agent/tools/index.js +1 -0
- package/dist/agent/tools/outcome.d.ts +15 -0
- package/dist/agent/tools/outcome.js +107 -0
- package/dist/agent/tools/pane.d.ts +2 -1
- package/dist/agent/tools/pane.js +21 -3
- package/dist/agent/tools/registry.js +2 -0
- package/dist/agent/tools/shell.d.ts +1 -0
- package/dist/agent/tools/shell.js +128 -17
- package/dist/agent/tools/sim_domain_tools.js +4 -2
- package/dist/agent/tools/supervision.js +4 -2
- package/dist/agent/tools/types.d.ts +3 -0
- package/dist/app/command_context.js +5 -9
- package/dist/app/conversation_compaction.d.ts +4 -2
- package/dist/app/conversation_compaction.js +16 -5
- package/dist/app/headless_shell_mode.d.ts +14 -0
- package/dist/app/headless_shell_mode.js +7 -0
- package/dist/app/hosted_resident.d.ts +356 -0
- package/dist/app/hosted_resident.js +677 -0
- package/dist/app/restart.js +11 -2
- package/dist/app/session_manager.d.ts +5 -0
- package/dist/app/session_manager.js +21 -6
- package/dist/app/session_messages.js +6 -6
- package/dist/app/workspace_layout_controller.js +7 -0
- package/dist/batch/worktree.d.ts +10 -0
- package/dist/batch/worktree.js +15 -0
- package/dist/bench/registry.js +4 -2
- package/dist/cli_args.js +1 -1
- package/dist/cli_main.js +80 -10
- package/dist/cli_ratatui.d.ts +75 -0
- package/dist/cli_ratatui.js +485 -84
- package/dist/components/InputArea.js +4 -4
- package/dist/config/execution.d.ts +10 -0
- package/dist/config/execution.js +10 -0
- package/dist/config/hosted_runtime.d.ts +4 -1
- package/dist/config/hosted_runtime.js +4 -1
- package/dist/config/permission_pin.d.ts +34 -2
- package/dist/config/permission_pin.js +52 -2
- package/dist/config/person_command_policy.d.ts +38 -0
- package/dist/config/person_command_policy.js +11 -0
- package/dist/config/profiles.d.ts +21 -0
- package/dist/config/profiles.js +56 -2
- package/dist/config/types.d.ts +4 -1
- package/dist/config.js +34 -19
- package/dist/desktop/daily/codex_exec_adapter.js +7 -2
- package/dist/desktop/daily/desktop_wiring.d.ts +7 -1
- package/dist/desktop/daily/desktop_wiring.js +11 -3
- package/dist/desktop/daily/recipes.js +20 -4
- package/dist/desktop/health.d.ts +24 -0
- package/dist/desktop/health.js +151 -0
- package/dist/desktop/native_dialogs.d.ts +37 -0
- package/dist/desktop/native_dialogs.js +105 -0
- package/dist/diagnostics/session_export.d.ts +1 -0
- package/dist/diagnostics/session_export.js +28 -0
- package/dist/embedded/registry.js +4 -2
- package/dist/emulation/tool_adapters.js +9 -4
- package/dist/emulation/ztc_addendum.js +3 -0
- package/dist/headless.d.ts +11 -4
- package/dist/headless.js +99 -34
- package/dist/headless_approval.d.ts +6 -0
- package/dist/headless_cli.js +1 -1
- package/dist/hooks/runner.js +7 -6
- package/dist/library.d.ts +4 -0
- package/dist/library.js +3 -0
- package/dist/mcp/client.js +3 -3
- package/dist/modes/registry.js +13 -4
- package/dist/onboarding/setup_environment.js +13 -1
- package/dist/optimize/adapters/kernelbench.js +88 -10
- package/dist/optimize/adapters/types.d.ts +5 -0
- package/dist/optimize/executor.js +21 -0
- package/dist/panes/cli_install.d.ts +54 -0
- package/dist/panes/cli_install.js +157 -0
- package/dist/panes/model_catalog.js +3 -0
- package/dist/panes/new_pane_choices.d.ts +6 -2
- package/dist/panes/new_pane_choices.js +24 -12
- package/dist/panes/pane_cli_launch.d.ts +50 -0
- package/dist/panes/pane_cli_launch.js +124 -0
- package/dist/panes/pane_clis.d.ts +171 -0
- package/dist/panes/pane_clis.js +325 -0
- package/dist/panes/person_only_panes.d.ts +45 -0
- package/dist/panes/person_only_panes.js +117 -0
- package/dist/plugin/simulation_living.js +0 -2
- package/dist/plugin/simulation_living_engine.d.ts +1 -0
- package/dist/plugin/simulation_living_engine.js +1 -0
- package/dist/plugin/simulation_living_labels.d.ts +3 -0
- package/dist/plugin/simulation_living_labels.js +2 -0
- package/dist/router_auth.js +12 -1
- package/dist/session.js +26 -1
- package/dist/simulation/art/gemini_image.js +11 -5
- package/dist/simulation/domains/loader.js +25 -3
- package/dist/simulation/living/cold.d.ts +23 -0
- package/dist/simulation/living/cold.js +41 -0
- package/dist/simulation/living/context.d.ts +591 -1283
- package/dist/simulation/living/context.js +378 -244
- package/dist/simulation/living/contradictions.d.ts +14 -0
- package/dist/simulation/living/contradictions.js +282 -0
- package/dist/simulation/living/core/ids.d.ts +53 -0
- package/dist/simulation/living/core/ids.js +39 -0
- package/dist/simulation/living/core/kind.d.ts +20 -0
- package/dist/simulation/living/core/kind.js +15 -0
- package/dist/simulation/living/core/laws.d.ts +179 -0
- package/dist/simulation/living/core/laws.js +184 -0
- package/dist/simulation/living/core/ops.d.ts +257 -0
- package/dist/simulation/living/core/ops.js +34 -0
- package/dist/simulation/living/definer.d.ts +17 -1
- package/dist/simulation/living/definer.js +130 -51
- package/dist/simulation/living/definition.d.ts +174 -65
- package/dist/simulation/living/definition.js +287 -180
- package/dist/simulation/living/director.d.ts +80 -0
- package/dist/simulation/living/director.js +363 -0
- package/dist/simulation/living/frame.d.ts +108 -21
- package/dist/simulation/living/frame.js +111 -66
- package/dist/simulation/living/identifiers.d.ts +0 -1
- package/dist/simulation/living/identifiers.js +0 -3
- package/dist/simulation/living/index.d.ts +18 -9
- package/dist/simulation/living/index.js +18 -9
- package/dist/simulation/living/inference.d.ts +92 -50
- package/dist/simulation/living/inference.js +319 -175
- package/dist/simulation/living/knowledge.d.ts +28 -0
- package/dist/simulation/living/knowledge.js +73 -0
- package/dist/simulation/living/library.json +1177 -0
- package/dist/simulation/living/mechanics.d.ts +31 -34
- package/dist/simulation/living/mechanics.js +222 -138
- package/dist/simulation/living/model-input.d.ts +6 -3
- package/dist/simulation/living/model-input.js +18 -26
- package/dist/simulation/living/open-world.d.ts +74 -94
- package/dist/simulation/living/open-world.js +151 -30
- package/dist/simulation/living/phrases.d.ts +3 -0
- package/dist/simulation/living/phrases.js +37 -0
- package/dist/simulation/living/phrases.json +560 -0
- package/dist/simulation/living/projection.d.ts +316 -2
- package/dist/simulation/living/projection.js +50 -2
- package/dist/simulation/living/prompts/example-spec.json +11 -0
- package/dist/simulation/living/prompts/role-text.json +14 -0
- package/dist/simulation/living/prompts.d.ts +5 -0
- package/dist/simulation/living/prompts.js +275 -0
- package/dist/simulation/living/recall.d.ts +2 -2
- package/dist/simulation/living/reduce.d.ts +51 -14
- package/dist/simulation/living/reduce.js +941 -579
- package/dist/simulation/living/replay.d.ts +5 -4
- package/dist/simulation/living/replay.js +10 -9
- package/dist/simulation/living/runtime.d.ts +135 -25
- package/dist/simulation/living/runtime.js +1641 -583
- package/dist/simulation/living/scale.d.ts +96 -0
- package/dist/simulation/living/scale.js +124 -0
- package/dist/simulation/living/script.d.ts +5 -0
- package/dist/simulation/living/script.js +115 -0
- package/dist/simulation/living/shared-kinds.d.ts +4 -11
- package/dist/simulation/living/shared-kinds.js +11 -81
- package/dist/simulation/living/space.d.ts +14 -0
- package/dist/simulation/living/space.js +132 -0
- package/dist/simulation/living/state.d.ts +100 -0
- package/dist/simulation/living/state.js +393 -0
- package/dist/simulation/living/types.d.ts +829 -512
- package/dist/simulation/living/types.js +162 -187
- package/dist/simulation/living/world-rules.d.ts +100 -0
- package/dist/simulation/living/world-rules.js +267 -0
- package/dist/simulation/plugins/loader.js +11 -0
- package/dist/skills/loader.js +4 -0
- package/dist/tools.d.ts +1 -0
- package/dist/tools.js +1 -0
- package/dist/ui/ratatui/headless_pane_manager.d.ts +4 -1
- package/dist/ui/ratatui/headless_pane_manager.js +13 -9
- package/dist/ui/ratatui/pane_relay.js +29 -0
- package/dist/ui/ratatui/pane_type.d.ts +10 -0
- package/dist/ui/ratatui/pane_type.js +11 -0
- package/dist/ui/ratatui/process.d.ts +30 -0
- package/dist/ui/ratatui/process.js +133 -19
- package/dist/ui/ratatui/protocol.d.ts +124 -2
- package/dist/ui/ratatui/protocol.js +35 -0
- package/dist/ui/ratatui/relay_policy.js +3 -0
- package/dist/ui/ratatui/ztc_launch_trust.d.ts +2 -1
- package/dist/ui/ratatui/ztc_launch_trust.js +8 -1
- package/dist/ui/terminal_image.d.ts +12 -0
- package/dist/ui/terminal_image.js +21 -1
- package/dist/utils/codex_project_trust.d.ts +19 -0
- package/dist/utils/codex_project_trust.js +37 -0
- package/dist/utils/compaction.js +103 -20
- package/dist/utils/git_program_files.d.ts +19 -12
- package/dist/utils/git_program_files.js +411 -83
- package/dist/utils/host_shell.d.ts +10 -1
- package/dist/utils/host_shell.js +14 -1
- package/dist/utils/mid_turn_compaction.d.ts +2 -0
- package/dist/utils/mid_turn_compaction.js +2 -0
- package/dist/utils/models.js +6 -1
- package/dist/utils/sandbox.d.ts +109 -8
- package/dist/utils/sandbox.js +981 -187
- package/dist/utils/shell.d.ts +2 -0
- package/dist/utils/shell.js +10 -4
- package/dist/utils/subprocess_env.d.ts +47 -11
- package/dist/utils/subprocess_env.js +107 -15
- package/dist/utils/system_ps.d.ts +8 -0
- package/dist/utils/system_ps.js +39 -7
- package/dist/utils/unattended_compaction.d.ts +9 -0
- package/dist/utils/unattended_compaction.js +13 -0
- package/dist/utils/ztc_own_state.d.ts +8 -5
- package/dist/utils/ztc_own_state.js +17 -11
- package/dist/web/mirror_client.js +1 -0
- package/dist/web/mirror_stream.d.ts +50 -6
- package/dist/web/mirror_stream.js +160 -15
- package/dist/workflows/registry.js +3 -1
- package/dist/workspace/controller.js +12 -0
- package/dist/workspace_collision.d.ts +3 -0
- package/dist/workspace_collision.js +14 -1
- package/dist/workspace_session_context.js +2 -1
- package/dist/zlm-embed.mjs +3823 -1970
- package/node_modules/@zerg/model-contracts/README.md +16 -4
- package/node_modules/@zerg/model-contracts/index.js +6 -1
- package/npm-shrinkwrap.json +1 -1
- package/package.json +42 -24
- package/packages/model-contracts/README.md +16 -4
- package/packages/model-contracts/index.js +6 -1
|
@@ -1,227 +1,319 @@
|
|
|
1
|
-
import {
|
|
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,
|
|
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 =
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
connections: z.array(id),
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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()
|
|
78
|
-
|
|
79
|
-
|
|
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),
|
|
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
|
-
|
|
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({
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
everyMinutes: z.number().int().min(1).max(
|
|
101
|
-
|
|
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
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
for (const place of definition.places) {
|
|
114
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
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
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
187
|
-
|
|
188
|
-
|
|
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
|
|
192
|
-
|
|
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
|
-
|
|
217
|
-
|
|
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
|
|
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
|
-
|
|
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(
|
|
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: (
|
|
241
|
-
id: generatedId(
|
|
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
|
-
|
|
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.
|
|
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.
|
|
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, ...(
|
|
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(
|
|
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 =
|
|
399
|
+
const typed = (Object.keys(rules).length > 0);
|
|
305
400
|
return {
|
|
306
|
-
id: generatedId(
|
|
307
|
-
intent: text, placeId, targetId:
|
|
308
|
-
...(everyMinutes === undefined ? {} : { everyMinutes, series: generatedId(
|
|
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
|
|
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
|
-
|
|
320
|
-
|
|
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(
|
|
423
|
+
kinds: sharedKindMap(),
|
|
324
424
|
kindRequests: [],
|
|
325
425
|
entities: {},
|
|
326
|
-
|
|
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:
|
|
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
|
}
|