@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,16 +1,40 @@
|
|
|
1
1
|
import { compactModelInput, decisionInputBudget, MODEL_VIEW_NOTE, selectModelPeople, syncModelPeople } from './model-input.js';
|
|
2
2
|
import { recallBeliefs, recallMemories } from './recall.js';
|
|
3
|
-
import {
|
|
3
|
+
import { ruleActionKinds } from './inference.js';
|
|
4
4
|
import { blockedActionKinds, currentValue, placelessNear } from './mechanics.js';
|
|
5
|
-
import { peopleAt, unansweredSince
|
|
5
|
+
import { answeredAgain, isChoiceTurn, isDecisionKind, peopleAt, unansweredSince } from './reduce.js';
|
|
6
6
|
import { knowsCustody, observedSummary, visibleTo, witnessed } from './projection.js';
|
|
7
|
-
import { SHARED_KINDS,
|
|
8
|
-
import {
|
|
7
|
+
import { SHARED_KINDS, staysInPlace } from './shared-kinds.js';
|
|
8
|
+
import { entitiesHere, heldBy, objectsHere, siteOf } from './space.js';
|
|
9
|
+
import { MAX_CHAIN_LINKS, clockLabel } from './types.js';
|
|
10
|
+
import { pace, restingAt } from './scale.js';
|
|
11
|
+
import { phrase } from './phrases.js';
|
|
12
|
+
import { cueMatches, evaluateCondition } from './core/laws.js';
|
|
13
|
+
import { personKnowledgeSources } from './knowledge.js';
|
|
14
|
+
function seriesEntries(state, entity) {
|
|
15
|
+
const properties = state.kinds[entity.kindId]?.properties ?? [];
|
|
16
|
+
return properties.flatMap(property => property.type !== 'series' ? []
|
|
17
|
+
: (Array.isArray(entity.properties[property.id]?.value) ? entity.properties[property.id].value : [])
|
|
18
|
+
.map(entry => ({ slot: property.id, option: entry.option, personId: entry.personId, at: entry.at })));
|
|
19
|
+
}
|
|
20
|
+
function sealedHere(state, entity, propertyId) {
|
|
21
|
+
const properties = state.kinds[entity.kindId]?.properties ?? [];
|
|
22
|
+
const slot = properties.find(property => property.id === propertyId);
|
|
23
|
+
return slot?.sealedBy !== undefined && entity.properties[slot.sealedBy]?.value === true;
|
|
24
|
+
}
|
|
25
|
+
function writerId(state, entity) {
|
|
26
|
+
const properties = state.kinds[entity.kindId]?.properties ?? [];
|
|
27
|
+
const slot = properties.find(property => property.perActor === true);
|
|
28
|
+
return slot === undefined ? null : String(entity.properties[slot.id]?.value ?? '');
|
|
29
|
+
}
|
|
30
|
+
function sealedText(state, entity) {
|
|
31
|
+
const properties = state.kinds[entity.kindId]?.properties ?? [];
|
|
32
|
+
return properties.some(property => property.type === 'text' && sealedHere(state, entity, property.id));
|
|
33
|
+
}
|
|
9
34
|
// Context builders turn state into what one participant can know right now.
|
|
10
35
|
// The Game Master sees the world. A character sees their own mind and their scene.
|
|
11
36
|
// A serious thing stays pressing for this long: people do not go back to routine
|
|
12
37
|
// business within minutes of violence, fire, theft or a collapse.
|
|
13
|
-
export const PRESSING_MINUTES = 240;
|
|
14
38
|
export const PRESSING_IMPORTANCE = 6;
|
|
15
39
|
// Memories this grave stay in a person's mind for good, the gravest few of them.
|
|
16
40
|
const LANDMARK_IMPORTANCE = 8;
|
|
@@ -38,66 +62,75 @@ function personCard(state, id) {
|
|
|
38
62
|
// What anyone present can see the person doing; their purpose stays private. Someone whose next activity
|
|
39
63
|
// is somewhere else is seen getting ready to leave, not doing what they mean to do there.
|
|
40
64
|
const plan = person.plan;
|
|
41
|
-
const elsewhere =
|
|
65
|
+
const elsewhere = (plan?.placeId !== undefined) && plan.placeId !== null && plan.placeId !== person.placeId;
|
|
66
|
+
// Getting ready to leave is only what anyone sees just before the walk, never the hours before it.
|
|
67
|
+
const departing = elsewhere && ((plan.dueAt - state.clock <= pace(state.calendar, 'departureReady')));
|
|
42
68
|
// The player's person, two quiet game hours after the player last acted, is seen resting, or asleep at
|
|
43
69
|
// night; never while a long act of theirs is under way.
|
|
44
|
-
const resting =
|
|
70
|
+
const resting = (person.isPlayer) && state.clock - (state.playerActedAt ?? state.startClock ?? 0) >= pace(state.calendar, 'playerQuiet')
|
|
45
71
|
&& !state.schedule.some(item => item.kind === 'finish' && item.targetId === person.id)
|
|
46
|
-
?
|
|
72
|
+
? restingAt(state.calendar, state.clock) ? phrase('person.asleep') : phrase('person.resting') : null;
|
|
47
73
|
return { id, name: person.name, role: person.role, pronouns: person.pronouns ?? 'they/them', summary: person.summary,
|
|
48
|
-
...(person.arrivedAt === undefined ? {} : { arrived: clockLabel(person.arrivedAt) }),
|
|
49
|
-
mood: null, condition: person.condition ?? null, doing: person.incapacitated ? null : resting ?? (
|
|
50
|
-
held: null, incapacitated: person.incapacitated };
|
|
74
|
+
...(person.arrivedAt === undefined ? {} : { arrived: clockLabel(state.calendar, person.arrivedAt) }),
|
|
75
|
+
mood: null, condition: person.condition ?? null, doing: person.incapacitated ? null : resting ?? (departing ? phrase('person.departing') : plan?.seen ?? null),
|
|
76
|
+
held: null, incapacitated: person.incapacitated, numbers: heldNumbers(state, id) };
|
|
51
77
|
}
|
|
52
78
|
export function describeScene(state, placeId, viewerId, kept = new Set()) {
|
|
53
79
|
const place = state.places[placeId];
|
|
54
80
|
const people = peopleAt(state, placeId).filter(id => id !== viewerId).map((id) => {
|
|
55
|
-
const holding = [...Object.values(state.objects).filter(object => object.
|
|
81
|
+
const holding = [...Object.values(state.objects).filter(object => object.containerId === id
|
|
56
82
|
&& (viewerId === null || knowsCustody(state, object, viewerId))).map(object => object.name),
|
|
57
|
-
...(state
|
|
83
|
+
...heldBy(state, id).filter(entityId => state.entities[entityId] !== undefined
|
|
58
84
|
&& (viewerId === null || state.entities[entityId].knownTo.includes(viewerId))).map(entityId => state.entities[entityId].name)];
|
|
59
85
|
return { ...personCard(state, id), holding };
|
|
60
86
|
});
|
|
61
87
|
// A thing the world hides is seen only by those who know where it is.
|
|
62
|
-
const objects =
|
|
63
|
-
&& (!object.hidden || viewerId === null || object.
|
|
64
|
-
id: object.id, name: object.name, summary: viewerId !== null && object.
|
|
65
|
-
condition: viewerId !== null && object.
|
|
88
|
+
const objects = objectsHere(state, placeId).map(id => state.objects[id]).filter(object => object.containerId === placeId
|
|
89
|
+
&& (!object.hidden || viewerId === null || object.containerId === viewerId || object.custodyKnownTo.includes(viewerId))).map(object => ({
|
|
90
|
+
id: object.id, name: object.name, summary: viewerId !== null && object.containerId !== viewerId && !object.conditionKnownTo.includes(viewerId) ? phrase('object.unexamined') : object.summary,
|
|
91
|
+
condition: viewerId !== null && object.containerId !== viewerId && !object.conditionKnownTo.includes(viewerId) ? 'unexamined' : object.condition,
|
|
66
92
|
singlePersonMovable: object.singlePersonMovable,
|
|
67
93
|
ownerName: viewerId !== null && object.ownerId !== viewerId ? null : object.ownerId ? personLabel(state, object.ownerId) : null,
|
|
68
|
-
...(viewerId === null && state.thingNotes[object.id] ? { refereeOnly: note(state.thingNotes[object.id]) } : {}),
|
|
94
|
+
...(viewerId === null && state.thingNotes.items[object.id] ? { refereeOnly: note(state, state.thingNotes.items[object.id]) } : {}),
|
|
69
95
|
}));
|
|
70
|
-
const near = new Set([placeId, ...peopleAt(state, placeId), ...(state
|
|
71
|
-
...
|
|
96
|
+
const near = new Set([placeId, ...peopleAt(state, placeId), ...entitiesHere(state, placeId).slice(-SCENE_SLICE),
|
|
97
|
+
...objectsHere(state, placeId), ...(viewerId === null ? [] : [viewerId])]);
|
|
72
98
|
// A scene lists the newest things at the place; the input budget trims further.
|
|
73
|
-
const here = state
|
|
99
|
+
const here = entitiesHere(state, placeId);
|
|
74
100
|
// What someone holds or just dealt with is listed however many newer things lie about.
|
|
75
101
|
const newest = [...here.filter(id => kept.has(id) && !here.slice(-SCENE_SLICE).includes(id)), ...here.slice(-SCENE_SLICE)];
|
|
76
102
|
// From engine 50 what lies in the open where the viewer stands is in view, and how it plainly is.
|
|
77
|
-
const standsHere = viewerId !== null && state.
|
|
78
|
-
&& state.people[viewerId]?.
|
|
79
|
-
const inView = (entity) => standsHere && entity.
|
|
103
|
+
const standsHere = (viewerId !== null) && state.people[viewerId]?.placeId === placeId
|
|
104
|
+
&& state.people[viewerId]?.offstage === undefined;
|
|
105
|
+
const inView = (entity) => standsHere && entity.containerId === placeId && !entity.hidden;
|
|
80
106
|
const entities = [...placelessNear(state, near, MIND_SLICE), ...newest].map(id => state.entities[id])
|
|
81
|
-
.filter(entity => (viewerId === null || entity.knownTo.includes(viewerId) || inView(entity)) && !(entity.
|
|
82
|
-
.
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
.
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
107
|
+
.filter(entity => (viewerId === null || entity.knownTo.includes(viewerId) || inView(entity)) && !(entity.containerId !== null && state.people[entity.containerId] !== undefined
|
|
108
|
+
&& (state.people[entity.containerId].departed !== undefined || state.people[entity.containerId].offstage !== undefined)))
|
|
109
|
+
.map(entity => {
|
|
110
|
+
const properties = state.kinds[entity.kindId]?.properties ?? [];
|
|
111
|
+
return {
|
|
112
|
+
id: entity.id, kindId: entity.kindId, kindName: state.kinds[entity.kindId].name, name: entity.name,
|
|
113
|
+
// A thing that is here can be picked up; who holds it is plain to see.
|
|
114
|
+
...(entity.containerId === placeId || (entity.containerId !== null && state.people[entity.containerId]?.placeId === placeId)
|
|
115
|
+
? { holderId: state.people[entity.containerId ?? ''] === undefined ? null : entity.containerId,
|
|
116
|
+
...(state.people[entity.containerId ?? ''] === undefined ? {} : { holder: personLabel(state, entity.containerId) }),
|
|
117
|
+
...(entity.condition ? { condition: entity.condition } : {}) } : {}),
|
|
118
|
+
...(seriesEntries(state, entity).length ? { marks: seriesEntries(state, entity).map(entry => ({ kind: entry.option, by: personLabel(state, entry.personId), at: clockLabel(state.calendar, entry.at) })) } : {}),
|
|
119
|
+
// A sealed paper's words stay hidden from everyone in the world until it is opened.
|
|
120
|
+
properties: Object.fromEntries(Object.entries(entity.properties)
|
|
121
|
+
.filter(([key, slot]) => viewerId === null || (slot.knownTo.includes(viewerId) || inView(entity) && properties.find(property => property.id === key)?.type !== 'text')
|
|
122
|
+
&& !(sealedHere(state, entity, key) && properties.find(property => property.id === key)?.type === 'text'))
|
|
123
|
+
.map(([key]) => [key, currentValue(state, entity, key, state.clock)])),
|
|
124
|
+
relations: Object.fromEntries(Object.entries(entity.relations)
|
|
125
|
+
.filter(([, slot]) => viewerId === null || slot.knownTo.includes(viewerId))
|
|
126
|
+
.map(([key, slot]) => [key, slot.targetId])),
|
|
127
|
+
...(Object.keys(state.holdings?.[entity.id] ?? {}).length === 0 ? {} : { numbers: heldNumbers(state, entity.id) }),
|
|
128
|
+
// Only the Game Master reads what the last ruling did with it.
|
|
129
|
+
...(viewerId === null && state.thingNotes.items[entity.id] ? { refereeOnly: note(state, state.thingNotes.items[entity.id]) } : {}),
|
|
130
|
+
};
|
|
131
|
+
});
|
|
99
132
|
const exits = place.connections.map(id => ({ id, name: state.places[id]?.name ?? id }));
|
|
100
|
-
return { id: place.id, name: place.name,
|
|
133
|
+
return { id: place.id, name: place.name, summary: place.summary, conditions: [...place.conditions], people, objects, entities, exits };
|
|
101
134
|
}
|
|
102
135
|
function recentSeqsAt(state, placeId, limit) {
|
|
103
136
|
return new Set(state.events.filter(event => event.placeId === placeId).slice(-limit).map(event => event.seq));
|
|
@@ -106,7 +139,7 @@ export function recentEventsAt(state, placeId, limit, viewerId, exceptSeq = null
|
|
|
106
139
|
return state.events
|
|
107
140
|
.filter(event => event.placeId === placeId && event.seq !== exceptSeq && (viewerId === null || witnessed(event, viewerId)))
|
|
108
141
|
.slice(-limit)
|
|
109
|
-
.map(event => ({ at: clockLabel(event.at), summary: viewerId === null ? event.summary : observedSummary(event, viewerId) }));
|
|
142
|
+
.map(event => ({ at: clockLabel(state.calendar, event.at), summary: viewerId === null ? event.summary : observedSummary(event, viewerId) }));
|
|
110
143
|
}
|
|
111
144
|
// The serious things that happened lately anywhere, so the world stays consistent
|
|
112
145
|
// about them (security already called, a fire still burning, someone hurt).
|
|
@@ -115,7 +148,7 @@ export function recentImportant(state, limit, shownHere = new Set()) {
|
|
|
115
148
|
return state.events
|
|
116
149
|
.filter(event => event.importance >= PRESSING_IMPORTANCE && (event.kind === 'attempt' || event.kind === 'world') && !shownHere.has(event.seq))
|
|
117
150
|
.slice(-limit)
|
|
118
|
-
.map(event => ({ at: clockLabel(event.at), place: placeLabel(state, event.placeId), summary: event.summary, witnesses: event.witnessIds.map(id => personLabel(state, id)) }));
|
|
151
|
+
.map(event => ({ at: clockLabel(state.calendar, event.at), place: placeLabel(state, event.placeId), summary: event.summary, witnesses: event.witnessIds.map(id => personLabel(state, id)) }));
|
|
119
152
|
}
|
|
120
153
|
export function openConversationAt(state, placeId, participantId) {
|
|
121
154
|
return state.conversations.find(conversation => conversation.endedAt === null && conversation.placeId === placeId && conversation.participantIds.includes(participantId)) ?? null;
|
|
@@ -150,40 +183,44 @@ function heardLines(state, placeId, participantId, limit) {
|
|
|
150
183
|
function lineCard(state, line) {
|
|
151
184
|
return { speaker: personLabel(state, line.speakerId), speakerId: line.speakerId, to: line.toIds.map(id => personLabel(state, id)), text: line.text };
|
|
152
185
|
}
|
|
186
|
+
function repeatAsk(state, person) {
|
|
187
|
+
const record = answeredAgain(state, person.id);
|
|
188
|
+
return record === null ? {} : { askedAgain: { repeats: record.repeats, since: clockLabel(state.calendar, record.firstAt), answered: clockLabel(state.calendar, record.answeredAt) } };
|
|
189
|
+
}
|
|
153
190
|
export function conversationLines(state, placeId, participantId, limit) {
|
|
154
191
|
return heardLines(state, placeId, participantId, limit).map(line => lineCard(state, line));
|
|
155
192
|
}
|
|
156
|
-
function note(entry) {
|
|
157
|
-
return { when: clockLabel(entry.at), what: entry.text };
|
|
193
|
+
function note(state, entry) {
|
|
194
|
+
return { when: clockLabel(state.calendar, entry.at), what: entry.text };
|
|
158
195
|
}
|
|
159
196
|
export function worldDirectory(state, placeId) {
|
|
160
197
|
const localPlaces = new Set([placeId, ...state.places[placeId].connections]);
|
|
161
|
-
const localPeople = new Set(Object.values(state.people).filter(person => localPlaces.has(person.placeId) && person.
|
|
162
|
-
const
|
|
198
|
+
const localPeople = new Set(Object.values(state.people).filter(person => localPlaces.has(person.placeId) && person.offstage === undefined && person.departed === undefined).map(person => person.id));
|
|
199
|
+
const offstage = Object.values(state.people).filter(person => localPlaces.has(person.placeId) && person.offstage !== undefined);
|
|
163
200
|
return {
|
|
164
|
-
places: Object.values(state.places).filter(place => localPlaces.has(place.id)).map(place => ({ id: place.id, name: place.name,
|
|
165
|
-
people: Object.values(state.people).filter(person => localPeople.has(person.id)).map(person => ({ id: person.id, name: person.name, role: person.role, pronouns: person.pronouns ?? 'they/them', placeId: person.placeId, isPlayer: person.isPlayer, incapacitated: person.incapacitated })),
|
|
201
|
+
places: Object.values(state.places).filter(place => localPlaces.has(place.id)).map(place => ({ id: place.id, name: place.name, connections: place.connections, conditions: [...place.conditions] })),
|
|
202
|
+
people: Object.values(state.people).filter(person => localPeople.has(person.id)).map(person => ({ id: person.id, name: person.name, role: person.role, pronouns: person.pronouns ?? 'they/them', placeId: person.placeId, isPlayer: person.isPlayer, incapacitated: person.incapacitated, numbers: heldNumbers(state, person.id) })),
|
|
166
203
|
// People from nearby who are off for a while, and where.
|
|
167
|
-
...(
|
|
204
|
+
...(offstage.length === 0 ? {} : { offstage: offstage.map(person => ({ id: person.id, name: person.name, where: person.offstage.why })) }),
|
|
168
205
|
// Everyone else in the story, by name, so no one is brought in a second time.
|
|
169
206
|
elsewhere: Object.values(state.people).filter(person => !localPlaces.has(person.placeId) && person.departed === undefined).map(person => ({ id: person.id, name: person.name })),
|
|
170
207
|
// Things at this place are already in the scene; the directory lists the rest nearby and what people hold.
|
|
171
|
-
objects: Object.values(state.objects).filter(object => (object.
|
|
172
|
-
.map(object => ({ id: object.id, name: object.name,
|
|
208
|
+
objects: Object.values(state.objects).filter(object => (object.containerId !== null && object.containerId !== placeId && localPlaces.has(object.containerId)) || (object.containerId !== null && localPeople.has(object.containerId)))
|
|
209
|
+
.map(object => ({ id: object.id, name: object.name, containerId: object.containerId, ownerId: object.ownerId, condition: object.condition, singlePersonMovable: object.singlePersonMovable })),
|
|
173
210
|
tensions: state.tensions.filter(tension => tension.status === 'open' && tension.participantIds.some(id => localPeople.has(id)))
|
|
174
211
|
.slice(-MIND_SLICE).map(tension => ({ id: tension.id, title: tension.title, summary: tension.summary, ...(tension.openedBy === undefined ? {} : { openedBy: tension.openedBy }),
|
|
175
212
|
participants: tension.participantIds.map(id => ({ id, name: personLabel(state, id) })) })),
|
|
176
213
|
facts: state.facts.slice(-8),
|
|
177
|
-
...(state.startClock === undefined ? {} : { factsAsOf: clockLabel(state.startClock) }),
|
|
214
|
+
...(state.startClock === undefined ? {} : { factsAsOf: clockLabel(state.calendar, state.startClock) }),
|
|
178
215
|
};
|
|
179
216
|
}
|
|
180
217
|
// A world begun on engines 42 to 44 adds each write to a paper as a line of its own, so its referee is told so.
|
|
181
218
|
function writeRule(state) {
|
|
182
|
-
return
|
|
219
|
+
return ({});
|
|
183
220
|
}
|
|
184
221
|
function kindsInScope(state, placeId) {
|
|
185
222
|
const nearby = new Set([placeId, ...state.places[placeId].connections]);
|
|
186
|
-
const ids = new Set(SHARED_KINDS.map(kind => kind.id));
|
|
223
|
+
const ids = new Set(SHARED_KINDS.filter(kind => kind.library !== true).map(kind => kind.id));
|
|
187
224
|
const near = new Set([...nearby, ...Object.values(state.people).filter(person => nearby.has(person.placeId)).map(person => person.id)]);
|
|
188
225
|
// Kinds of things here carry their rules; the rest are named and described, which is all a new thing needs.
|
|
189
226
|
const inView = new Set();
|
|
@@ -192,7 +229,7 @@ function kindsInScope(state, placeId) {
|
|
|
192
229
|
inView.add(state.entities[entityId].kindId);
|
|
193
230
|
}
|
|
194
231
|
for (const nearbyPlaceId of nearby)
|
|
195
|
-
for (const entityId of (state
|
|
232
|
+
for (const entityId of entitiesHere(state, nearbyPlaceId).slice(-SCENE_SLICE)) {
|
|
196
233
|
ids.add(state.entities[entityId].kindId);
|
|
197
234
|
if (nearbyPlaceId === placeId)
|
|
198
235
|
inView.add(state.entities[entityId].kindId);
|
|
@@ -205,7 +242,16 @@ function kindsInScope(state, placeId) {
|
|
|
205
242
|
}
|
|
206
243
|
}
|
|
207
244
|
return [...ids].sort().map(id => state.kinds[id]).filter((kind) => kind !== undefined)
|
|
208
|
-
.map(kind =>
|
|
245
|
+
.map(kind => {
|
|
246
|
+
const { laws: _laws, ...rest } = kind;
|
|
247
|
+
return (inView.has(kind.id)) ? rest : { ...rest, mechanics: [], ...(staysInPlace(kind) ? { neverHeld: true } : {}) };
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
function notedFacets(state) {
|
|
251
|
+
return Object.entries(state.facetUse.items)
|
|
252
|
+
.sort(([, left], [, right]) => right.count - left.count || right.lastSeq - left.lastSeq)
|
|
253
|
+
.slice(0, MIND_SLICE)
|
|
254
|
+
.map(([facet, use]) => ({ facet, count: use.count, kindId: use.kindId, kind: use.kindId === null ? null : state.kinds[use.kindId]?.name ?? null }));
|
|
209
255
|
}
|
|
210
256
|
// The Game Master adjudicates against the whole world, so it sees the directory.
|
|
211
257
|
export function gameMasterAttemptInput(state, actorId, attempt, previousErrors = [], _fitted = true, finishing, focusIds = []) {
|
|
@@ -213,28 +259,30 @@ export function gameMasterAttemptInput(state, actorId, attempt, previousErrors =
|
|
|
213
259
|
const close = inTalkWith(state, actor, focusIds);
|
|
214
260
|
const keeps = actorKeeps(state, actor.id, close);
|
|
215
261
|
const scene = describeScene(state, actor.placeId, null, keeps);
|
|
216
|
-
|
|
262
|
+
const noted = notedFacets(state);
|
|
263
|
+
const built = {
|
|
217
264
|
phase: 'attempt',
|
|
218
|
-
clock: clockLabel(state.clock),
|
|
265
|
+
clock: clockLabel(state.calendar, state.clock),
|
|
219
266
|
// The present as the count a time is written in: minutes since Day 1, 00:00.
|
|
220
267
|
clockMinutes: state.clock,
|
|
221
268
|
// The opening was written for the moment the world began; the clock shows how long ago that was.
|
|
222
|
-
setting: { world: state.setting, opening: { ...state.opening, ...(state.startClock === undefined ? {} : { asOf: clockLabel(state.startClock) }) }, ...messageTravel(state) },
|
|
223
|
-
actor: { id: actor.id, name: actor.name, role: actor.role, pronouns: actor.pronouns ?? 'they/them', isPlayer: actor.isPlayer,
|
|
224
|
-
...(state
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
narrationVoice: actor.isPlayer ? 'second person ("you"), present tense' : `third person by name (${actor.name}), present tense`,
|
|
269
|
+
setting: { world: state.setting, opening: { ...state.opening, ...(state.startClock === undefined ? {} : { asOf: clockLabel(state.calendar, state.startClock) }) }, ...messageTravel(state) },
|
|
270
|
+
actor: { id: actor.id, name: actor.name, role: actor.role, pronouns: actor.pronouns ?? 'they/them', isPlayer: actor.isPlayer, mood: actor.mood, incapacitated: actor.incapacitated, holding: [...Object.values(state.objects).filter(object => object.containerId === actor.id).map(object => ({ id: object.id, name: object.name, condition: object.condition })),
|
|
271
|
+
...heldBy(state, actor.id).filter(id => state.entities[id] !== undefined).map(id => ({ id, name: state.entities[id].name }))],
|
|
272
|
+
...(actor.isPlayer ? {} : openChoices(state, actor.id)) },
|
|
273
|
+
narrationVoice: actor.isPlayer ? phrase('role.you') : phrase('role.third', { name: actor.name }),
|
|
228
274
|
attempt,
|
|
229
275
|
// What the actor said here lately, word for word, for an act that writes or repeats it.
|
|
230
276
|
actorSaid: state.conversations.filter(conversation => conversation.placeId === actor.placeId).flatMap(conversation => conversation.lines)
|
|
231
|
-
.filter(line => line.speakerId === actor.id).sort((left, right) => left.seq - right.seq).slice(-3).map(line => ({ at: clockLabel(line.at), text: line.text })),
|
|
277
|
+
.filter(line => line.speakerId === actor.id).sort((left, right) => left.seq - right.seq).slice(-3).map(line => ({ at: clockLabel(state.calendar, line.at), text: line.text })),
|
|
232
278
|
...(finishing ? { finishing: { note: FINISHING_NOTE, ...finishing } } : {}),
|
|
233
279
|
scene,
|
|
234
|
-
...moneyAt(state, actor.placeId, actor.id),
|
|
235
280
|
...deadlinesNow(state, true),
|
|
236
281
|
...promisesAt(state, actor.placeId),
|
|
237
282
|
kinds: kindsInScope(state, actor.placeId),
|
|
283
|
+
...(noted.length === 0 ? {} : { noted }),
|
|
284
|
+
channels: Object.values(state.channels).map(channel => ({ ...channel })),
|
|
285
|
+
ruleActionKinds: ruleActionKinds(Object.values(state.kinds)),
|
|
238
286
|
...writeRule(state),
|
|
239
287
|
requests: relevantRequests(state.requests.filter(request => request.senderId === actor.id
|
|
240
288
|
&& request.knownTo.includes(actor.id) && scene.people.some(person => person.id === request.receiverId)))
|
|
@@ -247,48 +295,42 @@ export function gameMasterAttemptInput(state, actorId, attempt, previousErrors =
|
|
|
247
295
|
possiblePerceiverIds: scene.people.map(person => person.id),
|
|
248
296
|
presentCharacterIds: scene.people.filter(person => !state.people[person.id].isPlayer && !person.incapacitated).map(person => person.id),
|
|
249
297
|
...(previousErrors.length === 0 ? {} : { previousErrors: [...previousErrors] }),
|
|
250
|
-
}
|
|
298
|
+
};
|
|
299
|
+
return fitInput(built, REFEREE_INPUT_BUDGET, refereeTrim(state, keeps, close), close, keeps, nameMeasure(state));
|
|
251
300
|
}
|
|
252
301
|
// The open promises of the people where a ruling happens, so what they do keeps or breaks them knowingly.
|
|
253
302
|
function promisesAt(state, placeId) {
|
|
254
303
|
const here = new Set(peopleAt(state, placeId));
|
|
255
304
|
const promises = Object.values(state.people).flatMap(person => person.commitments.filter(commitment => commitment.status === 'open'
|
|
256
305
|
&& (here.has(person.id) || here.has(commitment.toId))).map(commitment => ({ by: person.name, to: personLabel(state, commitment.toId), text: commitment.text,
|
|
257
|
-
...(commitment.dueAt === null ? {} : { due: clockLabel(commitment.dueAt) }) }))).slice(-MIND_SLICE);
|
|
306
|
+
...(commitment.dueAt === null ? {} : { due: clockLabel(state.calendar, commitment.dueAt) }) }))).slice(-MIND_SLICE);
|
|
258
307
|
return promises.length === 0 ? {} : { promises };
|
|
259
308
|
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
function moneyAt(state, placeId, actorId) {
|
|
263
|
-
if (state.currency === null)
|
|
264
|
-
return {};
|
|
265
|
-
const purses = Object.values(state.people).filter(person => person.money !== null && person.departed === undefined
|
|
266
|
-
&& (person.id === actorId || person.placeId === placeId && person.away === undefined)).map(person => ({ id: person.id, name: person.name, balance: person.money }));
|
|
267
|
-
const accounts = Object.values(state.accounts ?? {}).map(account => ({ id: account.id, name: account.name, balance: account.balance,
|
|
268
|
-
movedBy: account.holderId === null ? 'the world\'s own rules' : personLabel(state, account.holderId) }));
|
|
269
|
-
return purses.length + accounts.length === 0 ? {} : { money: { unit: state.currency.name, balances: [...purses, ...accounts] } };
|
|
309
|
+
export function heldNumbers(state, holderId) {
|
|
310
|
+
return Object.entries(state.holdings?.[holderId] ?? {}).map(([slot, amount]) => ({ slot, unit: state.units?.[state.numbers?.[slot]?.unit ?? '']?.name ?? state.numbers?.[slot]?.unit ?? slot, amount }));
|
|
270
311
|
}
|
|
271
312
|
// The things an actor holds, those their last act concerned, and the newest things in the hands of the
|
|
272
313
|
// people they deal with here stay in a ruling's view longest, so it can read and hand on what is in play.
|
|
273
314
|
function actorKeeps(state, actorId, close) {
|
|
274
315
|
const last = [...state.events].reverse().find(event => event.actorId === actorId && event.thingIds !== undefined);
|
|
275
|
-
const dealing = (state
|
|
276
|
-
const
|
|
277
|
-
return
|
|
316
|
+
const dealing = entitiesHere(state, state.people[actorId].placeId).filter(id => {
|
|
317
|
+
const containerId = state.entities[id].containerId;
|
|
318
|
+
return containerId !== null && containerId !== actorId && close.has(containerId);
|
|
278
319
|
}).slice(-MIND_SLICE);
|
|
279
|
-
return new Set([...Object.values(state.entities).filter(entity => entity.
|
|
320
|
+
return new Set([...Object.values(state.entities).filter(entity => entity.containerId === actorId).map(entity => entity.id), ...(last?.thingIds ?? []), ...dealing]);
|
|
280
321
|
}
|
|
281
322
|
// A due happening is carried out as its world wrote it, and one that comes back is new each time.
|
|
282
|
-
const HAPPENING_NOTE = '
|
|
283
|
-
const RECURRING_NOTE = '
|
|
323
|
+
const HAPPENING_NOTE = phrase('happening.note');
|
|
324
|
+
const RECURRING_NOTE = phrase('happening.recurring');
|
|
325
|
+
const CHAIN_NOTE = phrase('happening.chain');
|
|
284
326
|
// A later look at a serious act's consequences restates the act; it must not rule the act again.
|
|
285
|
-
const AFTERMATH_NOTE = '
|
|
327
|
+
const AFTERMATH_NOTE = phrase('happening.aftermath');
|
|
286
328
|
// A problem nobody has acted on for a while goes on by itself.
|
|
287
|
-
const STALL_NOTE = '
|
|
288
|
-
const FINISHING_NOTE = '
|
|
329
|
+
const STALL_NOTE = phrase('happening.stall');
|
|
330
|
+
const FINISHING_NOTE = phrase('happening.finishing');
|
|
289
331
|
// In a world where messages take time, everyone knows how they go and how long they take.
|
|
290
332
|
function messageTravel(state) {
|
|
291
|
-
return state.messageTravel ? { messages:
|
|
333
|
+
return state.messageTravel ? { messages: phrase('message.travel', { how: state.messageTravel.how, minutes: state.messageTravel.minutes }) } : {};
|
|
292
334
|
}
|
|
293
335
|
// What a happening concerns, by id, name and kind.
|
|
294
336
|
function concerned(state, id) {
|
|
@@ -303,7 +345,7 @@ function concerned(state, id) {
|
|
|
303
345
|
return { id, name: state.places[id].name, kind: 'Place' };
|
|
304
346
|
const tension = state.tensions.find(candidate => candidate.id === id);
|
|
305
347
|
// A problem says since when it has stood as it is.
|
|
306
|
-
return tension ? { id, name: tension.title, kind: 'Problem', since: clockLabel(tension.changedAt) } : undefined;
|
|
348
|
+
return tension ? { id, name: tension.title, kind: 'Problem', since: clockLabel(state.calendar, tension.changedAt) } : undefined;
|
|
307
349
|
}
|
|
308
350
|
// A happening that comes back remembers its last few times, so each one can be new.
|
|
309
351
|
export function earlierTimes(state, sourceSeq) {
|
|
@@ -312,37 +354,52 @@ export function earlierTimes(state, sourceSeq) {
|
|
|
312
354
|
const before = state.events.find(event => event.seq === seq);
|
|
313
355
|
if (!before || before.kind !== 'world')
|
|
314
356
|
break;
|
|
315
|
-
earlier.push({ at: clockLabel(before.at), what: before.observed ?? before.summary });
|
|
357
|
+
earlier.push({ at: clockLabel(state.calendar, before.at), what: before.observed ?? before.summary });
|
|
316
358
|
seq = before.causeSeq ?? 0;
|
|
317
359
|
}
|
|
318
360
|
return earlier;
|
|
319
361
|
}
|
|
362
|
+
function chainHistory(state, sourceSeq) {
|
|
363
|
+
const earlier = [];
|
|
364
|
+
for (let seq = sourceSeq; seq > 0 && earlier.length < MAX_CHAIN_LINKS;) {
|
|
365
|
+
const before = state.events.find(event => event.seq === seq);
|
|
366
|
+
if (!before || before.kind !== 'world')
|
|
367
|
+
break;
|
|
368
|
+
earlier.push({ at: clockLabel(state.calendar, before.at), what: before.observed ?? before.summary });
|
|
369
|
+
seq = before.causeSeq ?? 0;
|
|
370
|
+
}
|
|
371
|
+
return earlier.reverse();
|
|
372
|
+
}
|
|
320
373
|
// A world happening that fell due: an arrival, a spreading fire, a storm, a delivery.
|
|
321
374
|
export function gameMasterWorldInput(state, happening, previousErrors = [], _fitted = true, focusIds = []) {
|
|
322
375
|
const scene = describeScene(state, happening.placeId, null);
|
|
323
376
|
const cause = state.events.find(event => event.seq === happening.sourceSeq);
|
|
324
377
|
const about = happening.targetId ? concerned(state, happening.targetId) : undefined;
|
|
325
378
|
const earlier = happening.everyMinutes === undefined ? [] : earlierTimes(state, happening.sourceSeq);
|
|
326
|
-
|
|
379
|
+
const noted = notedFacets(state);
|
|
380
|
+
const built = {
|
|
327
381
|
phase: 'world',
|
|
328
|
-
clock: clockLabel(state.clock),
|
|
382
|
+
clock: clockLabel(state.calendar, state.clock),
|
|
329
383
|
clockMinutes: state.clock,
|
|
330
384
|
// The opening was written for the moment the world began; the clock shows how long ago that was.
|
|
331
|
-
setting: { world: state.setting, opening: { ...state.opening, ...(state.startClock === undefined ? {} : { asOf: clockLabel(state.startClock) }) }, ...messageTravel(state) },
|
|
385
|
+
setting: { world: state.setting, opening: { ...state.opening, ...(state.startClock === undefined ? {} : { asOf: clockLabel(state.calendar, state.startClock) }) }, ...messageTravel(state) },
|
|
332
386
|
happening: happening.intent,
|
|
333
387
|
// What the world's own data says this happening has made true; the narration agrees with it.
|
|
334
388
|
...(happening.alreadyTrue && happening.alreadyTrue.length > 0 ? { nowTrue: [...happening.alreadyTrue] } : {}),
|
|
335
|
-
happeningNote: happening.id?.startsWith('aftermath-') ? AFTERMATH_NOTE : happening.id?.startsWith('stall-check') ? STALL_NOTE
|
|
389
|
+
happeningNote: happening.id?.startsWith('aftermath-') ? AFTERMATH_NOTE : happening.id?.startsWith('stall-check') ? STALL_NOTE
|
|
390
|
+
: happening.everyMinutes === undefined ? `${HAPPENING_NOTE}${happening.chain === undefined ? '' : ` ${CHAIN_NOTE}`}` : `${HAPPENING_NOTE} ${RECURRING_NOTE}${happening.chain === undefined ? '' : ` ${CHAIN_NOTE}`}`,
|
|
336
391
|
// What a happening concerns, such as the fire a danger check is about or the expiry a deadline made.
|
|
337
392
|
...(about === undefined ? {} : { about }),
|
|
338
393
|
...(happening.everyMinutes === undefined ? {} : { recurring: { everyMinutes: happening.everyMinutes, earlier } }),
|
|
339
|
-
|
|
340
|
-
|
|
394
|
+
...(happening.chain === undefined ? {} : { chain: { id: happening.chain.id, link: happening.chain.link, limit: MAX_CHAIN_LINKS, earlier: chainHistory(state, happening.sourceSeq) } }),
|
|
395
|
+
cause: cause ? { at: clockLabel(state.calendar, cause.at), summary: cause.summary } : null,
|
|
396
|
+
narrationVoice: phrase('role.thirdNoYou'),
|
|
341
397
|
scene,
|
|
342
|
-
...moneyAt(state, happening.placeId, null),
|
|
343
398
|
...deadlinesNow(state, true),
|
|
344
399
|
...promisesAt(state, happening.placeId),
|
|
345
400
|
kinds: kindsInScope(state, happening.placeId),
|
|
401
|
+
...(noted.length === 0 ? {} : { noted }),
|
|
402
|
+
channels: Object.values(state.channels).map(channel => ({ ...channel })),
|
|
346
403
|
...writeRule(state),
|
|
347
404
|
// The cause is its own field, so it is left out of the recent events here.
|
|
348
405
|
recentHere: recentEventsAt(state, happening.placeId, 8, null, happening.sourceSeq),
|
|
@@ -351,15 +408,17 @@ export function gameMasterWorldInput(state, happening, previousErrors = [], _fit
|
|
|
351
408
|
possiblePerceiverIds: scene.people.map(person => person.id),
|
|
352
409
|
presentCharacterIds: scene.people.filter(person => !state.people[person.id].isPlayer && !person.incapacitated).map(person => person.id),
|
|
353
410
|
...(previousErrors.length === 0 ? {} : { previousErrors: [...previousErrors] }),
|
|
354
|
-
}
|
|
411
|
+
};
|
|
412
|
+
const close = new Set([...focusIds, ...(happening.targetId ? [happening.targetId] : [])]);
|
|
413
|
+
return fitInput(built, REFEREE_INPUT_BUDGET, refereeTrim(state, close, close), close, close, nameMeasure(state));
|
|
355
414
|
}
|
|
356
415
|
// What weighs on a person right now: the serious things they saw, noticed or were told lately.
|
|
357
416
|
export function pressingMatters(state, person, limit) {
|
|
358
417
|
return pressingOf(state, person, limit)
|
|
359
|
-
.map(memory => ({ when: clockLabel(memory.at), minutesAgo: Math.max(0, state.clock - memory.at), text: memory.text }));
|
|
418
|
+
.map(memory => ({ when: clockLabel(state.calendar, memory.at), minutesAgo: Math.max(0, state.clock - memory.at), text: memory.text }));
|
|
360
419
|
}
|
|
361
|
-
function
|
|
362
|
-
|
|
420
|
+
function unresolvedConditionSeqs(state) {
|
|
421
|
+
return new Set(state.events.filter(event => event.effects.some(effect => {
|
|
363
422
|
if (effect.kind === 'place.condition')
|
|
364
423
|
return effect.add !== null && effect.aspect !== undefined
|
|
365
424
|
&& state.places[effect.placeId]?.conditionAspects[effect.aspect]?.changedSeq === event.seq;
|
|
@@ -367,14 +426,14 @@ function pressingOf(state, person, limit) {
|
|
|
367
426
|
return effect.condition !== null && state.people[effect.personId]?.conditionChangedSeq === event.seq;
|
|
368
427
|
return false;
|
|
369
428
|
})).map(event => event.seq));
|
|
370
|
-
|
|
429
|
+
}
|
|
430
|
+
export function memoryIsPressing(state, person) {
|
|
431
|
+
const unresolved = unresolvedConditionSeqs(state);
|
|
432
|
+
return memory => memory.importance >= PRESSING_IMPORTANCE && (memory.at >= state.clock - pace(state.calendar, 'pressing') || unresolved.has(memory.eventSeq));
|
|
371
433
|
}
|
|
372
434
|
// The latest pressing memories by time, whatever order a load brought them in.
|
|
373
|
-
function
|
|
374
|
-
return person.memories
|
|
375
|
-
.filter(memory => memory.importance >= PRESSING_IMPORTANCE && (memory.at >= state.clock - PRESSING_MINUTES || unresolved.has(memory.eventSeq)))
|
|
376
|
-
.sort((left, right) => left.at - right.at)
|
|
377
|
-
.slice(-limit);
|
|
435
|
+
function pressingOf(state, person, limit) {
|
|
436
|
+
return person.memories.filter(memoryIsPressing(state, person)).sort((left, right) => left.at - right.at).slice(-limit);
|
|
378
437
|
}
|
|
379
438
|
export function myMovements(state, person, limit) {
|
|
380
439
|
const moves = state.events
|
|
@@ -382,14 +441,13 @@ export function myMovements(state, person, limit) {
|
|
|
382
441
|
.slice(-limit)
|
|
383
442
|
.map((event) => {
|
|
384
443
|
const move = event.effects.find(effect => effect.kind === 'move' && effect.personId === person.id);
|
|
385
|
-
return `${clockLabel(event.at)}: went to ${move.kind === 'move' ? placeLabel(state, move.placeId) : ''}`;
|
|
444
|
+
return `${clockLabel(state.calendar, event.at)}: went to ${move.kind === 'move' ? placeLabel(state, move.placeId) : ''}`;
|
|
386
445
|
});
|
|
387
|
-
return [...moves, `${clockLabel(state.clock)}: now in ${placeLabel(state, person.placeId)}`];
|
|
446
|
+
return [...moves, `${clockLabel(state.calendar, state.clock)}: now in ${placeLabel(state, person.placeId)}`];
|
|
388
447
|
}
|
|
389
448
|
// A text field keeps its newest items until its size budget is spent, so its size stays flat as a
|
|
390
449
|
// world ages and its lines grow longer. Items arrive oldest first; the newest one always fits.
|
|
391
450
|
const FIELD_BUDGET = { conversation: 2400, myRecentLines: 1800, memories: 2400, recentlySeen: 1000, pressing: 1200, summaries: 1200 };
|
|
392
|
-
// A summary card keeps its opening, most weighty lines within this many characters, so one always fits.
|
|
393
451
|
const SUMMARY_CARD_TEXT = 1000;
|
|
394
452
|
// Fields that tell the same kind of thing share one size, so a person with more pressing news or
|
|
395
453
|
// more heard talk recalls fewer older things instead of getting a longer input as the world ages.
|
|
@@ -399,11 +457,11 @@ const OWN_LINES_ROOM = 600;
|
|
|
399
457
|
// The newest items that fit. The first field of a group keeps at least one item; later fields
|
|
400
458
|
// get only the room the group has left.
|
|
401
459
|
// The first items that fit, in order.
|
|
402
|
-
function firstWithinBudget(items, budget) {
|
|
460
|
+
function firstWithinBudget(items, budget, measure) {
|
|
403
461
|
const kept = [];
|
|
404
462
|
let used = 0;
|
|
405
463
|
for (const item of items) {
|
|
406
|
-
const size =
|
|
464
|
+
const size = measure(item);
|
|
407
465
|
if (used + size > budget)
|
|
408
466
|
break;
|
|
409
467
|
kept.push(item);
|
|
@@ -411,11 +469,11 @@ function firstWithinBudget(items, budget) {
|
|
|
411
469
|
}
|
|
412
470
|
return kept;
|
|
413
471
|
}
|
|
414
|
-
function withinBudget(items, budget, keepOne = true) {
|
|
472
|
+
function withinBudget(items, budget, measure, keepOne = true) {
|
|
415
473
|
const kept = [];
|
|
416
474
|
let used = 0;
|
|
417
475
|
for (const item of [...items].reverse()) {
|
|
418
|
-
const size =
|
|
476
|
+
const size = measure(item);
|
|
419
477
|
if ((kept.length > 0 || !keepOne) && used + size > budget)
|
|
420
478
|
break;
|
|
421
479
|
kept.unshift(item);
|
|
@@ -427,14 +485,14 @@ function withinBudget(items, budget, keepOne = true) {
|
|
|
427
485
|
// input runs over, the least needed lists give up items in turn, tier by tier, until it fits.
|
|
428
486
|
const CHARACTER_INPUT_BUDGET = 10_000;
|
|
429
487
|
const REFEREE_INPUT_BUDGET = 12_000;
|
|
430
|
-
function fitInput(input, budget, tiers, close = new Set(), things = new Set()) {
|
|
488
|
+
function fitInput(input, budget, tiers, close = new Set(), things = new Set(), measure = value => JSON.stringify(value).length) {
|
|
431
489
|
// Leave room for the bounded lookup result on a follow-up transmission.
|
|
432
490
|
const maximum = decisionInputBudget(input, budget) - 512;
|
|
433
491
|
budget -= 512;
|
|
434
492
|
const fitted = structuredClone(input);
|
|
435
493
|
const priority = selectModelPeople(fitted, close);
|
|
436
494
|
syncModelPeople(fitted);
|
|
437
|
-
let size =
|
|
495
|
+
let size = measure(fitted);
|
|
438
496
|
if (size <= budget)
|
|
439
497
|
return fitted;
|
|
440
498
|
const listAt = (path) => {
|
|
@@ -471,12 +529,12 @@ function fitInput(input, budget, tiers, close = new Set(), things = new Set()) {
|
|
|
471
529
|
list.splice(index, 1);
|
|
472
530
|
fitted.view = MODEL_VIEW_NOTE;
|
|
473
531
|
syncModelPeople(fitted);
|
|
474
|
-
size =
|
|
532
|
+
size = measure(fitted);
|
|
475
533
|
removed = true;
|
|
476
534
|
}
|
|
477
535
|
}
|
|
478
536
|
}
|
|
479
|
-
compactModelInput(fitted, budget, priority, maximum, things);
|
|
537
|
+
compactModelInput(fitted, budget, priority, maximum, things, measure);
|
|
480
538
|
syncModelPeople(fitted);
|
|
481
539
|
return fitted;
|
|
482
540
|
}
|
|
@@ -494,7 +552,7 @@ function stalestThing(state, kept = new Set()) {
|
|
|
494
552
|
let chosenKey = [Infinity, Infinity];
|
|
495
553
|
items.forEach((item, index) => {
|
|
496
554
|
const id = item.id;
|
|
497
|
-
const key = [kept.has(id) ? 2 : state.entities[id]?.
|
|
555
|
+
const key = [kept.has(id) ? 2 : state.entities[id]?.containerId === null ? 1 : 0, lastChanged(id)];
|
|
498
556
|
if (key[0] < chosenKey[0] || (key[0] === chosenKey[0] && key[1] < chosenKey[1])) {
|
|
499
557
|
chosen = index;
|
|
500
558
|
chosenKey = key;
|
|
@@ -531,7 +589,8 @@ function dealtWith(state, person) {
|
|
|
531
589
|
// to in the last lines of their talk here, their plan's person and those they have an open ask with.
|
|
532
590
|
const TALK_LINES_IN_VIEW = 6;
|
|
533
591
|
function inTalkWith(state, person, focusIds) {
|
|
534
|
-
return new Set([...focusIds.filter((id) => typeof id === 'string'), person.id,
|
|
592
|
+
return new Set([...focusIds.filter((id) => typeof id === 'string'), person.id,
|
|
593
|
+
...(knownPeople(state, person).has(state.playerId) ? [state.playerId] : []), ...(person.plan?.targetId ? [person.plan.targetId] : []),
|
|
535
594
|
...state.conversations.filter(conversation => conversation.placeId === person.placeId && conversation.endedAt === null && conversation.participantIds.includes(person.id))
|
|
536
595
|
.flatMap(conversation => conversation.lines.slice(-TALK_LINES_IN_VIEW).flatMap(line => [line.speakerId, ...line.toIds])),
|
|
537
596
|
...state.requests.filter(request => request.status === 'open' && (request.senderId === person.id || request.receiverId === person.id)).flatMap(request => [request.senderId, request.receiverId])]);
|
|
@@ -560,7 +619,7 @@ export function speechSetting(state) {
|
|
|
560
619
|
}
|
|
561
620
|
export function fitSpeechInput(state, input, close, held) {
|
|
562
621
|
return fitInput(input, SPEECH_INPUT_BUDGET, [[{ path: ['elsewhere'], drop: 'last' }],
|
|
563
|
-
[{ path: ['things'], drop: stalestThing(state, held), keep: 4 }, { path: ['listeners'], drop: leastInvolved(close), keep: SCENE_PEOPLE_KEPT }]], close);
|
|
622
|
+
[{ path: ['things'], drop: stalestThing(state, held), keep: 4 }, { path: ['listeners'], drop: leastInvolved(close), keep: SCENE_PEOPLE_KEPT }]], close, new Set(), nameMeasure(state));
|
|
564
623
|
}
|
|
565
624
|
function characterTrim(state, kept = new Set(), close = new Set()) {
|
|
566
625
|
return [
|
|
@@ -579,20 +638,79 @@ function refereeTrim(state, kept = new Set(), close = new Set()) {
|
|
|
579
638
|
[{ path: ['world', 'facts'], drop: 'first' }, { path: ['world', 'objects'], drop: 'first' }],
|
|
580
639
|
// A ruling names anyone present who notices from the ids it is given; the crowd's details give way.
|
|
581
640
|
[{ path: ['scene', 'people'], drop: leastInvolved(close), keep: SCENE_PEOPLE_KEPT }, { path: ['world', 'people'], drop: leastInvolved(close), keep: SCENE_PEOPLE_KEPT },
|
|
582
|
-
{ path: ['money', 'balances'], drop: leastInvolved(close, id => state.people[id] !== undefined), keep: SCENE_PEOPLE_KEPT },
|
|
583
641
|
{ path: ['scene', 'entities'], drop: stalestThing(state, kept), keep: 2 }, { path: ['recentHere'], drop: 'first', keep: 2 }, { path: ['world', 'tensions'], drop: 'first', keep: 1 }],
|
|
584
642
|
[{ path: ['requests'], drop: settledAskFirst, keep: 2 }, { path: ['scene', 'objects'], drop: 'first', keep: 2 }, { path: ['world', 'elsewhere'], drop: 'first' }, { path: ['promises'], drop: 'first', keep: 2 }],
|
|
585
643
|
// The record of what really happened goes last, and its newest three stay.
|
|
586
644
|
[{ path: ['recentSerious'], drop: 'first', keep: 3 }],
|
|
587
645
|
];
|
|
588
646
|
}
|
|
589
|
-
function spent(items) {
|
|
590
|
-
return items.reduce((total, item) => total +
|
|
647
|
+
function spent(items, measure) {
|
|
648
|
+
return items.reduce((total, item) => total + measure(item), 0);
|
|
649
|
+
}
|
|
650
|
+
export function memoryBoundToOpenBusiness(state, person) {
|
|
651
|
+
const openRequestIds = new Set(state.requests.filter(request => request.status === 'open'
|
|
652
|
+
&& (request.senderId === person.id || request.receiverId === person.id)).map(request => request.id));
|
|
653
|
+
const openCommitmentIds = new Set(person.commitments.filter(commitment => commitment.status === 'open').map(commitment => commitment.id));
|
|
654
|
+
const counterparts = new Set();
|
|
655
|
+
for (const request of state.requests) {
|
|
656
|
+
if (request.status !== 'open' || (request.senderId !== person.id && request.receiverId !== person.id))
|
|
657
|
+
continue;
|
|
658
|
+
counterparts.add(request.senderId === person.id ? request.receiverId : request.senderId);
|
|
659
|
+
}
|
|
660
|
+
for (const commitment of person.commitments)
|
|
661
|
+
if (commitment.status === 'open')
|
|
662
|
+
counterparts.add(commitment.toId);
|
|
663
|
+
for (const other of Object.values(state.people)) {
|
|
664
|
+
for (const commitment of other.commitments)
|
|
665
|
+
if (commitment.status === 'open' && commitment.toId === person.id)
|
|
666
|
+
counterparts.add(other.id);
|
|
667
|
+
}
|
|
668
|
+
return memory => (memory.requestIds ?? []).some(id => openRequestIds.has(id))
|
|
669
|
+
|| (memory.commitmentIds ?? []).some(id => openCommitmentIds.has(id))
|
|
670
|
+
|| memory.participantIds.some(id => counterparts.has(id));
|
|
671
|
+
}
|
|
672
|
+
function nameMeasure(state) {
|
|
673
|
+
const names = new Set();
|
|
674
|
+
for (const other of Object.values(state.people))
|
|
675
|
+
names.add(other.name);
|
|
676
|
+
for (const place of Object.values(state.places))
|
|
677
|
+
names.add(place.name);
|
|
678
|
+
for (const entity of Object.values(state.entities))
|
|
679
|
+
names.add(entity.name);
|
|
680
|
+
for (const object of Object.values(state.objects))
|
|
681
|
+
names.add(object.name);
|
|
682
|
+
const shared = new Set(SHARED_KINDS.map(kind => kind.id));
|
|
683
|
+
for (const kind of Object.values(state.kinds)) {
|
|
684
|
+
if (kind.library === true || shared.has(kind.id))
|
|
685
|
+
continue;
|
|
686
|
+
names.add(kind.id);
|
|
687
|
+
names.add(kind.name);
|
|
688
|
+
for (const property of kind.properties)
|
|
689
|
+
names.add(property.id);
|
|
690
|
+
for (const relation of kind.relations)
|
|
691
|
+
names.add(relation.id);
|
|
692
|
+
}
|
|
693
|
+
for (const tension of state.tensions) {
|
|
694
|
+
names.add(tension.id);
|
|
695
|
+
names.add(tension.title);
|
|
696
|
+
}
|
|
697
|
+
names.add(state.opening.title);
|
|
698
|
+
for (const id of [...Object.keys(state.people), ...Object.keys(state.places), ...Object.keys(state.entities), ...Object.keys(state.objects),
|
|
699
|
+
...Object.keys(state.numbers ?? {}), ...Object.keys(state.units ?? {}), ...Object.keys(state.factAspects ?? {})])
|
|
700
|
+
names.add(id);
|
|
701
|
+
const ordered = [...names].filter(name => name.length > 0).sort((left, right) => right.length - left.length);
|
|
702
|
+
return (value) => {
|
|
703
|
+
let json = JSON.stringify(value);
|
|
704
|
+
for (const name of ordered)
|
|
705
|
+
json = json.replaceAll(name, 'x'.repeat(8));
|
|
706
|
+
return json.length;
|
|
707
|
+
};
|
|
591
708
|
}
|
|
592
709
|
// Each memory, line and plan appears once: pressing memories first, then the latest others, then
|
|
593
710
|
// recalled older ones; the conversation, then the person's own lines elsewhere.
|
|
594
711
|
export function characterMind(state, person, focusIds, shownElsewhere = {}) {
|
|
595
712
|
const scene = describeScene(state, person.placeId, person.id);
|
|
713
|
+
const measure = nameMeasure(state);
|
|
596
714
|
const relationships = Object.entries(person.relationships)
|
|
597
715
|
.filter(([id]) => state.people[id] && (scene.people.some(other => other.id === id) || person.memories.some(memory => memory.participantIds.includes(id))))
|
|
598
716
|
// Why their feelings last changed, so a confession or a betrayal is not forgotten.
|
|
@@ -602,43 +720,50 @@ export function characterMind(state, person, focusIds, shownElsewhere = {}) {
|
|
|
602
720
|
const triggerLine = trigger === undefined ? undefined
|
|
603
721
|
: [...heard].reverse().find(line => line.speakerId === trigger.speakerId && line.text === trigger.text);
|
|
604
722
|
// The conversation leaves room in the talk budget for at least the person's latest line elsewhere.
|
|
605
|
-
const conversation = withinBudget(heard.filter(line => line !== triggerLine).map(line => lineCard(state, line)), Math.min(FIELD_BUDGET.conversation, TALK_BUDGET - OWN_LINES_ROOM));
|
|
723
|
+
const conversation = withinBudget(heard.filter(line => line !== triggerLine).map(line => lineCard(state, line)), Math.min(FIELD_BUDGET.conversation, TALK_BUDGET - OWN_LINES_ROOM), measure);
|
|
606
724
|
const heardSeqs = new Set(heard.map(line => line.seq));
|
|
607
725
|
// A line already in the conversation, or the one being answered, is not listed again as news.
|
|
608
726
|
const inTalk = new Set([...heard.slice(-conversation.length - (triggerLine ? 1 : 0)).map(line => line.seq), ...(triggerLine ? [triggerLine.seq] : [])]);
|
|
609
|
-
const
|
|
727
|
+
const newest = person.memories.filter(memory => !inTalk.has(memory.eventSeq)).sort((left, right) => left.at - right.at).slice(-6);
|
|
728
|
+
const newestIds = new Set(newest.map(memory => memory.id));
|
|
729
|
+
const boundToOpenBusiness = memoryBoundToOpenBusiness(state, person);
|
|
730
|
+
const bound = person.memories.filter(memory => !newestIds.has(memory.id) && boundToOpenBusiness(memory));
|
|
731
|
+
const boundIds = new Set(bound.map(memory => memory.id));
|
|
732
|
+
const pressing = [...bound, ...pressingOf(state, person, 6).filter(memory => !boundIds.has(memory.id))].filter(memory => !inTalk.has(memory.eventSeq));
|
|
610
733
|
const pressingIds = new Set(pressing.map(memory => memory.id));
|
|
611
734
|
const latest = person.memories.filter(memory => !pressingIds.has(memory.id) && !inTalk.has(memory.eventSeq)).sort((left, right) => left.at - right.at).slice(-6);
|
|
612
735
|
const shownIds = new Set([...pressingIds, ...latest.map(memory => memory.id)]);
|
|
613
736
|
// History fills in order of urgency: pressing news, the last things seen, long-term summaries,
|
|
614
737
|
// then recalled older memories in whatever room is left.
|
|
615
|
-
const pressingCards =
|
|
738
|
+
const pressingCards = firstWithinBudget([...bound.map(memory => ({ id: memory.id, when: clockLabel(state.calendar, memory.at), minutesAgo: Math.max(0, state.clock - memory.at), text: memory.text })),
|
|
739
|
+
...pressing.filter(memory => !boundIds.has(memory.id)).sort((left, right) => right.at - left.at)
|
|
740
|
+
.map(memory => ({ id: memory.id, when: clockLabel(state.calendar, memory.at), minutesAgo: Math.max(0, state.clock - memory.at), text: memory.text }))], FIELD_BUDGET.pressing, measure);
|
|
616
741
|
// The last things this person saw or was told, whatever the cues: nobody forgets the last hour.
|
|
617
|
-
const recentCards = withinBudget(latest.map(memory => ({ id: memory.id, when: clockLabel(memory.at), text: memory.text, evidence: memory.evidence?.kind ?? 'legacy' })), Math.min(FIELD_BUDGET.recentlySeen, HISTORY_BUDGET - spent(pressingCards)));
|
|
742
|
+
const recentCards = withinBudget(latest.map(memory => ({ id: memory.id, when: clockLabel(state.calendar, memory.at), text: memory.text, evidence: memory.evidence?.kind ?? 'legacy' })), Math.min(FIELD_BUDGET.recentlySeen, HISTORY_BUDGET - spent(pressingCards, measure)), measure);
|
|
618
743
|
// Summaries come best first, so the budget keeps them from the front.
|
|
619
744
|
const summaryCards = withinBudget((person.summaries ?? []).filter(summary => summary.personId === person.id)
|
|
620
745
|
.map(summary => ({ summary, relevance: summary.participantIds.some(id => focusIds.includes(id))
|
|
621
746
|
|| summary.placeIds.some(id => focusIds.includes(id)) ? 1 : 0 }))
|
|
622
747
|
.sort((left, right) => right.relevance - left.relevance || right.summary.importance - left.summary.importance
|
|
623
748
|
|| right.summary.at - left.summary.at).slice(0, 3)
|
|
624
|
-
.map(({ summary }) => ({ id: summary.id, when: clockLabel(summary.at), text: summary.text.slice(0, SUMMARY_CARD_TEXT),
|
|
625
|
-
importance: summary.importance })).reverse(), Math.min(FIELD_BUDGET.summaries, HISTORY_BUDGET - spent(pressingCards) - spent(recentCards)), false).reverse();
|
|
749
|
+
.map(({ summary }) => ({ id: summary.id, when: clockLabel(state.calendar, summary.at), text: summary.text.slice(0, SUMMARY_CARD_TEXT),
|
|
750
|
+
importance: summary.importance })).reverse(), Math.min(FIELD_BUDGET.summaries, HISTORY_BUDGET - spent(pressingCards, measure) - spent(recentCards, measure)), measure, false).reverse();
|
|
626
751
|
// Recall reaches past the talk under way to older things.
|
|
627
752
|
const talkMemoryIds = person.memories.filter(memory => heardSeqs.has(memory.eventSeq)).map(memory => memory.id);
|
|
628
753
|
// Recalled memories come best first; a cut takes the least bound to the moment, never the oldest first.
|
|
629
|
-
const memoryCards = firstWithinBudget(recallMemories(state, person, focusIds, 8, new Set([...shownIds, ...talkMemoryIds]), true).map(memory => ({ id: memory.id, when: clockLabel(memory.at), text: memory.text, importance: memory.importance,
|
|
630
|
-
evidence: memory.evidence?.kind ?? 'legacy' })), Math.min(FIELD_BUDGET.memories, HISTORY_BUDGET - spent(pressingCards) - spent(recentCards) - spent(summaryCards)));
|
|
754
|
+
const memoryCards = firstWithinBudget(recallMemories(state, person, focusIds, 8, new Set([...shownIds, ...talkMemoryIds]), true).map(memory => ({ id: memory.id, when: clockLabel(state.calendar, memory.at), text: memory.text, importance: memory.importance,
|
|
755
|
+
evidence: memory.evidence?.kind ?? 'legacy' })), Math.min(FIELD_BUDGET.memories, HISTORY_BUDGET - spent(pressingCards, measure) - spent(recentCards, measure) - spent(summaryCards, measure)), measure);
|
|
631
756
|
// The gravest things this person ever lived through stay with them, however long ago.
|
|
632
757
|
const listed = new Set([...shownIds, ...memoryCards.map(card => card.id)]);
|
|
633
758
|
const landmarkCards = person.memories.filter(memory => memory.importance >= LANDMARK_IMPORTANCE && !listed.has(memory.id))
|
|
634
759
|
.sort((left, right) => right.importance - left.importance || right.at - left.at).slice(0, LANDMARKS).sort((left, right) => left.at - right.at)
|
|
635
|
-
.map(memory => ({ id: memory.id, when: clockLabel(memory.at), text: memory.text, importance: memory.importance, evidence: memory.evidence?.kind ?? 'legacy' }));
|
|
760
|
+
.map(memory => ({ id: memory.id, when: clockLabel(state.calendar, memory.at), text: memory.text, importance: memory.importance, evidence: memory.evidence?.kind ?? 'legacy' }));
|
|
636
761
|
return {
|
|
637
762
|
setting: state.setting,
|
|
638
763
|
...messageTravel(state),
|
|
639
764
|
identity: { id: person.id, name: person.name, role: person.role, pronouns: person.pronouns ?? 'they/them',
|
|
640
765
|
character: person.character ?? { voice: person.persona, values: [], redLines: [], privateConcerns: [] },
|
|
641
|
-
mood: person.mood, condition: person.condition ?? null, held: person.held ? person.held.reason : null,
|
|
766
|
+
mood: person.mood, condition: person.condition ?? null, held: person.held ? person.held.reason : null,
|
|
642
767
|
blocked: blockedActionKinds(state, person.id) },
|
|
643
768
|
goals: person.goals.filter(goal => goal.status === 'active').slice(-MIND_SLICE).map(goal => ({ id: goal.id, text: goal.text })),
|
|
644
769
|
relationships,
|
|
@@ -651,17 +776,17 @@ export function characterMind(state, person, focusIds, shownElsewhere = {}) {
|
|
|
651
776
|
myMovements: myMovements(state, person, 6),
|
|
652
777
|
// What they took up before their present activity and when, so hours of the same waiting are
|
|
653
778
|
// plain to them; the present one is the plan above.
|
|
654
|
-
myEarlierActivities: (person.planHistory ?? []).slice(0, person.plan ? -1 : undefined).map(item => ({ since: clockLabel(item.at), what: item.intent })),
|
|
655
|
-
beliefs: recallBeliefs(person, focusIds, 6).map(belief => ({ id: belief.id, subject: belief.subject, claim: belief.claim, source: belief.source.kind === 'told' ?
|
|
779
|
+
myEarlierActivities: (person.planHistory ?? []).slice(0, person.plan ? -1 : undefined).map(item => ({ since: clockLabel(state.calendar, item.at), what: item.intent })),
|
|
780
|
+
beliefs: recallBeliefs(person, focusIds, 6).map(belief => ({ id: belief.id, subject: belief.subject, claim: belief.claim, source: belief.source.kind === 'told' ? phrase('belief.toldBy', { person: personLabel(state, belief.source.personId ?? '') }) : belief.source.kind })),
|
|
656
781
|
// What others have promised this person and not yet kept: what they are owed.
|
|
657
782
|
promisedToMe: Object.values(state.people).flatMap(other => other.id === person.id ? [] : other.commitments
|
|
658
783
|
.filter(commitment => commitment.toId === person.id && commitment.status === 'open' && (commitment.knownTo?.includes(person.id) ?? true))
|
|
659
784
|
.map(commitment => ({ other, commitment })))
|
|
660
785
|
.sort((left, right) => left.commitment.madeAt - right.commitment.madeAt).slice(-MIND_SLICE)
|
|
661
|
-
.map(({ other, commitment }) => ({ id: commitment.id, by: other.name, text: commitment.text, due: commitment.dueAt === null ? null : clockLabel(commitment.dueAt) })),
|
|
786
|
+
.map(({ other, commitment }) => ({ id: commitment.id, by: other.name, text: commitment.text, due: commitment.dueAt === null ? null : clockLabel(state.calendar, commitment.dueAt) })),
|
|
662
787
|
commitments: person.commitments.filter(commitment => commitment.status === 'open')
|
|
663
788
|
.sort((left, right) => (left.dueAt ?? Infinity) - (right.dueAt ?? Infinity) || left.madeAt - right.madeAt).slice(0, MIND_SLICE)
|
|
664
|
-
.map(commitment => ({ id: commitment.id, to: personLabel(state, commitment.toId), text: commitment.text, due: commitment.dueAt === null ? null : clockLabel(commitment.dueAt),
|
|
789
|
+
.map(commitment => ({ id: commitment.id, to: personLabel(state, commitment.toId), text: commitment.text, due: commitment.dueAt === null ? null : clockLabel(state.calendar, commitment.dueAt),
|
|
665
790
|
...(commitment.dueAt === null ? {} : commitment.dueAt >= state.clock ? { minutesLeft: commitment.dueAt - state.clock } : { minutesPast: state.clock - commitment.dueAt }) })),
|
|
666
791
|
...deadlinesNow(state),
|
|
667
792
|
...ownPapers(state, person.id),
|
|
@@ -676,37 +801,16 @@ export function characterMind(state, person, focusIds, shownElsewhere = {}) {
|
|
|
676
801
|
.sort((left, right) => Number(scene.people.some(other => other.id === right.actorId)) - Number(scene.people.some(other => other.id === left.actorId))
|
|
677
802
|
|| right.changedSeq - left.changedSeq).slice(0, MIND_SLICE)
|
|
678
803
|
.map(stance => ({ actorId: stance.actorId, status: stance.status, sourceSeq: stance.sourceSeq })),
|
|
679
|
-
plan: person.plan ? { intent: person.plan.intent, due: clockLabel(person.plan.dueAt), placeId: person.plan.placeId, targetId: person.plan.targetId } : null,
|
|
804
|
+
plan: person.plan ? { intent: person.plan.intent, due: clockLabel(state.calendar, person.plan.dueAt), placeId: person.plan.placeId, targetId: person.plan.targetId } : null,
|
|
680
805
|
scene,
|
|
681
806
|
conversation,
|
|
682
|
-
|
|
683
|
-
|
|
807
|
+
...repeatAsk(state, person),
|
|
808
|
+
myRecentLines: withinBudget(recentLinesBy(state, person.id, 12).filter(line => !heardSeqs.has(line.seq)).map(line => line.text), Math.min(FIELD_BUDGET.myRecentLines, TALK_BUDGET - spent(conversation, measure)), measure),
|
|
809
|
+
clock: clockLabel(state.calendar, state.clock),
|
|
684
810
|
};
|
|
685
811
|
}
|
|
686
812
|
function knownPeople(state, person) {
|
|
687
|
-
|
|
688
|
-
// Only those really here are known by being here: not someone away, nor someone who left the story.
|
|
689
|
-
for (const other of Object.values(state.people))
|
|
690
|
-
if (other.placeId === person.placeId && other.away === undefined && other.departed === undefined)
|
|
691
|
-
ids.add(other.id);
|
|
692
|
-
for (const memory of person.memories)
|
|
693
|
-
for (const id of memory.participantIds)
|
|
694
|
-
ids.add(id);
|
|
695
|
-
for (const belief of person.beliefs)
|
|
696
|
-
if (belief.source.personId !== null)
|
|
697
|
-
ids.add(belief.source.personId);
|
|
698
|
-
for (const commitment of person.commitments)
|
|
699
|
-
ids.add(commitment.toId);
|
|
700
|
-
if (person.plan?.targetId)
|
|
701
|
-
ids.add(person.plan.targetId);
|
|
702
|
-
for (const conversation of state.conversations) {
|
|
703
|
-
if (!conversation.participantIds.includes(person.id))
|
|
704
|
-
continue;
|
|
705
|
-
for (const id of conversation.participantIds)
|
|
706
|
-
ids.add(id);
|
|
707
|
-
}
|
|
708
|
-
ids.delete(person.id);
|
|
709
|
-
return ids;
|
|
813
|
+
return new Set(personKnowledgeSources(state, person).keys());
|
|
710
814
|
}
|
|
711
815
|
// Resolve model-supplied references, never words in an action. Unknown and ambiguous names
|
|
712
816
|
// have the same result, so asking cannot expose an identity outside this role's knowledge.
|
|
@@ -728,15 +832,27 @@ export function modelContextPeople(state, actorId, phase, input, requested) {
|
|
|
728
832
|
}
|
|
729
833
|
return { focusIds: [...new Set(focusIds)], unavailable };
|
|
730
834
|
}
|
|
731
|
-
function
|
|
732
|
-
|
|
835
|
+
export function perceivedPlaces(state, person) {
|
|
836
|
+
return new Set([person.placeId, ...state.places[person.placeId].connections, ...(person.knownPlaceIds ?? [])]);
|
|
837
|
+
}
|
|
838
|
+
export function reachFor(state, fromPlaceId, person) {
|
|
839
|
+
if (person.departed !== undefined)
|
|
840
|
+
return [];
|
|
841
|
+
const here = person.placeId === fromPlaceId && person.offstage === undefined;
|
|
842
|
+
const reach = here ? ['voice'] : [];
|
|
843
|
+
reach.push('message');
|
|
844
|
+
return reach;
|
|
845
|
+
}
|
|
846
|
+
export function knownPlaces(state, person) {
|
|
847
|
+
const ids = perceivedPlaces(state, person);
|
|
733
848
|
for (const memory of person.memories)
|
|
734
849
|
if (memory.placeId !== null)
|
|
735
850
|
ids.add(memory.placeId);
|
|
736
|
-
if (person.plan?.placeId)
|
|
737
|
-
ids.add(person.plan.placeId);
|
|
738
851
|
return ids;
|
|
739
852
|
}
|
|
853
|
+
export function knowsPlace(state, person, placeId) {
|
|
854
|
+
return knownPlaces(state, person).has(placeId);
|
|
855
|
+
}
|
|
740
856
|
function spokenTo(state, trigger) {
|
|
741
857
|
for (const event of [...state.events].reverse()) {
|
|
742
858
|
const said = event.effects.find(effect => effect.kind === 'say' && effect.personId === trigger.actorId && effect.text === trigger.text);
|
|
@@ -746,11 +862,11 @@ function spokenTo(state, trigger) {
|
|
|
746
862
|
return [];
|
|
747
863
|
}
|
|
748
864
|
export function characterReactionInput(state, person, trigger, _fitted = true, previousErrors = [], focusIds = []) {
|
|
749
|
-
const actorName = trigger.actorId ? personLabel(state, trigger.actorId) : '
|
|
865
|
+
const actorName = trigger.actorId ? personLabel(state, trigger.actorId) : phrase('world.name');
|
|
750
866
|
const noticed = trigger.kind === 'nearby';
|
|
751
867
|
const peopleInScope = knownPeople(state, person);
|
|
752
868
|
// Someone away for a while is not here, wherever they left from.
|
|
753
|
-
const present = (other) => other.placeId === person.placeId && other.
|
|
869
|
+
const present = (other) => other.placeId === person.placeId && other.offstage === undefined && other.departed === undefined;
|
|
754
870
|
return fitInput({
|
|
755
871
|
phase: 'reaction',
|
|
756
872
|
...(previousErrors.length === 0 ? {} : { previousErrors: [...previousErrors] }),
|
|
@@ -760,16 +876,19 @@ export function characterReactionInput(state, person, trigger, _fitted = true, p
|
|
|
760
876
|
: { kind: trigger.kind, by: actorName, byId: trigger.actorId, text: trigger.text, narration: trigger.narration, pressure: trigger.pressure ?? null,
|
|
761
877
|
// Whom the line was said to, since the line itself is not repeated in the conversation.
|
|
762
878
|
...(trigger.kind === 'speech' ? { to: spokenTo(state, trigger) } : {}) },
|
|
763
|
-
|
|
764
|
-
...
|
|
765
|
-
playerId: state.playerId,
|
|
879
|
+
...openChoices(state, person.id, new Set(trigger.thingIds ?? [])),
|
|
880
|
+
...(peopleInScope.has(state.playerId) ? { playerId: state.playerId } : {}),
|
|
766
881
|
playerName: peopleInScope.has(state.playerId) ? personLabel(state, state.playerId) : null,
|
|
767
882
|
playerPronouns: peopleInScope.has(state.playerId) ? state.people[state.playerId]?.pronouns ?? 'they/them' : null,
|
|
768
883
|
playerHere: state.people[state.playerId]?.placeId === person.placeId,
|
|
769
884
|
exits: state.places[person.placeId].connections.map(id => ({ id, name: state.places[id]?.name ?? id })),
|
|
770
885
|
directory: { people: Object.values(state.people).filter(other => peopleInScope.has(other.id)).map(other => ({ id: other.id, name: other.name,
|
|
771
|
-
pronouns: other.pronouns ?? 'they/them', role: present(other) ? other.role : null, here: present(other),
|
|
772
|
-
|
|
886
|
+
pronouns: other.pronouns ?? 'they/them', role: present(other) ? other.role : null, here: present(other), reach: reachFor(state, person.placeId, other),
|
|
887
|
+
...silentSince(state, person.id, other.id) })) },
|
|
888
|
+
}, CHARACTER_INPUT_BUDGET, characterTrim(state, dealtWith(state, person), inTalkWith(state, person, [...focusIds, trigger.actorId])), inTalkWith(state, person, [...focusIds, trigger.actorId]), new Set(), nameMeasure(state));
|
|
889
|
+
}
|
|
890
|
+
export function replyPressureMatches(shown, reading) {
|
|
891
|
+
return shown === null || shown === reading;
|
|
773
892
|
}
|
|
774
893
|
// A deadline whose problem is already settled will not happen; it is no longer counted down to.
|
|
775
894
|
export function avertedAhead(state, item) {
|
|
@@ -780,24 +899,24 @@ export function avertedAhead(state, item) {
|
|
|
780
899
|
// those that went by in the last day, so no one speaks of a passed deadline as still to come.
|
|
781
900
|
function deadlinesNow(state, withOutcome = false) {
|
|
782
901
|
const ahead = state.schedule.filter(item => item.kind === 'world' && item.beat?.deadline && !avertedAhead(state, item)).sort((left, right) => left.at - right.at).slice(0, 4)
|
|
783
|
-
.map(item => ({ what: item.intent, due: clockLabel(item.at), minutesLeft: Math.max(0, item.at - state.clock) }));
|
|
784
|
-
const past = (state.passedDeadlines ?? []).filter(entry => state.clock - entry.at <=
|
|
785
|
-
.map(entry => ({ what: entry.what, due: clockLabel(entry.at), minutesPast: state.clock - entry.at, ...(entry.averted ? { averted: true } : {}),
|
|
902
|
+
.map(item => ({ what: item.intent, due: clockLabel(state.calendar, item.at), minutesLeft: Math.max(0, item.at - state.clock) }));
|
|
903
|
+
const past = (state.passedDeadlines ?? []).filter(entry => state.clock - entry.at <= state.calendar.day).slice(-3)
|
|
904
|
+
.map(entry => ({ what: entry.what, due: clockLabel(state.calendar, entry.at), minutesPast: state.clock - entry.at, ...(entry.averted ? { averted: true } : {}),
|
|
786
905
|
...(withOutcome ? { outcome: entry.outcome } : {}) }));
|
|
787
906
|
return ahead.length + past.length === 0 ? {} : { deadlines: [...past, ...ahead] };
|
|
788
907
|
}
|
|
789
908
|
// Since when someone up a long day has been awake: since they last came back from rest, or since the story began.
|
|
790
909
|
export function awakeSince(state, person) {
|
|
791
910
|
const since = person.restedAt ?? state.startClock ?? 0;
|
|
792
|
-
return state.clock - since >=
|
|
911
|
+
return state.clock - since >= pace(state.calendar, 'longDay') ? { awakeSince: clockLabel(state.calendar, since) } : {};
|
|
793
912
|
}
|
|
794
913
|
// The words of the papers this person wrote, the newest two, wherever the papers now lie.
|
|
795
914
|
export function ownPapers(state, personId) {
|
|
796
|
-
const papers = (state.
|
|
797
|
-
const slot = entity?.properties.
|
|
798
|
-
const
|
|
799
|
-
return
|
|
800
|
-
|
|
915
|
+
const papers = Object.values(state.entities).filter(entity => writerId(state, entity) === personId).slice(-2).flatMap(entity => {
|
|
916
|
+
const slot = (state.kinds[entity.kindId]?.properties ?? []).find(property => property.type === 'text');
|
|
917
|
+
const words = slot === undefined ? undefined : entity.properties[slot.id];
|
|
918
|
+
return words === undefined || typeof words.value !== 'string' || !words.knownTo.includes(personId) ? []
|
|
919
|
+
: [{ id: entity.id, name: entity.name, words: words.value.slice(0, OWN_PAPER_WORDS) }];
|
|
801
920
|
});
|
|
802
921
|
return papers.length === 0 ? {} : { myPapers: papers };
|
|
803
922
|
}
|
|
@@ -805,35 +924,62 @@ const OWN_PAPER_WORDS = 800;
|
|
|
805
924
|
// The words of the papers a moment concerns that this person knows, wherever they lie, so no one makes
|
|
806
925
|
// up what a paper they know says. Those here are in the scene, and those they wrote are their own.
|
|
807
926
|
export function papersInMind(state, person, focusIds) {
|
|
808
|
-
const own = new Set(state.
|
|
927
|
+
const own = new Set(Object.values(state.entities).filter(entity => writerId(state, entity) === person.id).map(entity => entity.id));
|
|
809
928
|
const papers = [...new Set(focusIds)].flatMap(id => {
|
|
810
929
|
const entity = state.entities[id];
|
|
811
|
-
const
|
|
812
|
-
|
|
813
|
-
|
|
930
|
+
const slot = entity === undefined ? undefined : (state.kinds[entity.kindId]?.properties ?? []).find(property => property.type === 'text');
|
|
931
|
+
const words = slot === undefined ? undefined : entity.properties[slot.id];
|
|
932
|
+
return entity !== undefined && typeof words?.value === 'string' && words.knownTo.includes(person.id)
|
|
933
|
+
&& siteOf(state, entity.containerId) !== person.placeId && !own.has(id) && entity.knownTo.includes(person.id)
|
|
934
|
+
&& !sealedText(state, entity) ? [{ id, name: entity.name, words: words.value.slice(0, OWN_PAPER_WORDS) }] : [];
|
|
814
935
|
}).slice(0, 2);
|
|
815
936
|
return papers.length === 0 ? {} : { papersInMind: papers };
|
|
816
937
|
}
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
.map(entity =>
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
938
|
+
export function openChoices(state, personId, concerned, cap = 3) {
|
|
939
|
+
const person = state.people[personId];
|
|
940
|
+
if (person === undefined)
|
|
941
|
+
return {};
|
|
942
|
+
const candidates = concerned === undefined || concerned.size === 0
|
|
943
|
+
? entitiesHere(state, person.placeId).map(id => state.entities[id]).filter(entity => entity !== undefined)
|
|
944
|
+
: [...concerned].map(id => state.entities[id]).filter(entity => entity !== undefined);
|
|
945
|
+
const choices = candidates
|
|
946
|
+
.filter(entity => entity.knownTo.includes(personId))
|
|
947
|
+
.flatMap(entity => (state.kinds[entity.kindId]?.properties ?? [])
|
|
948
|
+
.filter(property => property.type === 'series' && property.options !== undefined)
|
|
949
|
+
.flatMap(property => {
|
|
950
|
+
const options = property.options.filter(option => {
|
|
951
|
+
if (!entity.knownTo.includes(personId))
|
|
952
|
+
return false;
|
|
953
|
+
if (person.departed !== undefined || person.offstage !== undefined || (person.placeId !== entity.containerId && entity.containerId !== personId))
|
|
954
|
+
return false;
|
|
955
|
+
const entries = Array.isArray(entity.properties[property.id]?.value) ? entity.properties[property.id].value : [];
|
|
956
|
+
if (entries.some(entry => entry.personId === personId))
|
|
957
|
+
return false;
|
|
958
|
+
const env = { self: entity.id, actor: personId, target: personId, value: option, at: state.clock };
|
|
959
|
+
return !(state.kinds[entity.kindId]?.laws ?? []).some(law => law.kind === 'forbid' && cueMatches(law.on, property.id)
|
|
960
|
+
&& (law.when === undefined || evaluateCondition(state, env, law.when)));
|
|
961
|
+
});
|
|
962
|
+
if (options.length === 0)
|
|
963
|
+
return [];
|
|
964
|
+
const until = isDecisionKind(state.kinds[entity.kindId])
|
|
965
|
+
? (state.kinds[entity.kindId]?.properties ?? []).filter(slot => slot.type === 'time')
|
|
966
|
+
.map(slot => entity.properties[slot.id]?.value).filter((value) => typeof value === 'number' && value > state.clock)
|
|
967
|
+
.sort((left, right) => left - right)[0] ?? null
|
|
968
|
+
: null;
|
|
969
|
+
const called = state.schedule.some(item => isChoiceTurn(state, item) && item.targetId === entity.id);
|
|
970
|
+
const due = !called ? null : until === null ? phrase('choice.dueNow', { name: entity.name })
|
|
971
|
+
: phrase('choice.due', { name: entity.name, until: clockLabel(state.calendar, until) });
|
|
972
|
+
return [{ id: entity.id, name: entity.name, slotId: property.id, options, due, until: until === null ? null : clockLabel(state.calendar, until) }];
|
|
973
|
+
})).slice(0, cap);
|
|
974
|
+
return choices.length === 0 ? {} : { choices };
|
|
829
975
|
}
|
|
830
976
|
// Someone who has left this person's last lines unanswered, since the first of them.
|
|
831
977
|
function silentSince(state, personId, otherId) {
|
|
832
978
|
const since = unansweredSince(state, personId, otherId);
|
|
833
|
-
return since === null ? {} : { noAnswerSince: clockLabel(since) };
|
|
979
|
+
return since === null ? {} : { noAnswerSince: clockLabel(state.calendar, since) };
|
|
834
980
|
}
|
|
835
981
|
// The due plan is data: what the person meant to do, and how late it now is.
|
|
836
|
-
export function characterPlanInput(state, person, plan, voteTurn = false, focusIds = []) {
|
|
982
|
+
export function characterPlanInput(state, person, plan, voteTurn = false, focusIds = [], decision) {
|
|
837
983
|
const duePlan = typeof plan === 'string' ? { intent: plan } : plan;
|
|
838
984
|
// A decision is cued by where the person is, whom they are with, and whom their plan is about.
|
|
839
985
|
const mind = characterMind(state, person, [person.placeId, ...peopleAt(state, person.placeId).filter(id => id !== person.id),
|
|
@@ -844,32 +990,34 @@ export function characterPlanInput(state, person, plan, voteTurn = false, focusI
|
|
|
844
990
|
if (due !== duePlan)
|
|
845
991
|
mind.plan = null;
|
|
846
992
|
const peopleInScope = knownPeople(state, person);
|
|
847
|
-
const here = (other) => other.placeId === person.placeId && other.
|
|
993
|
+
const here = (other) => other.placeId === person.placeId && other.offstage === undefined;
|
|
848
994
|
const placesInScope = knownPlaces(state, person);
|
|
849
995
|
return fitInput({
|
|
850
996
|
phase: 'plan',
|
|
851
997
|
...mind,
|
|
852
998
|
duePlan: due,
|
|
999
|
+
...(decision === undefined ? {} : { decision }),
|
|
853
1000
|
// A member's turn to vote, when voting opens, is the decision in which they cast it.
|
|
854
|
-
...(voteTurn ?
|
|
1001
|
+
...(voteTurn ? openChoices(state, person.id) : {}),
|
|
855
1002
|
directory: {
|
|
856
1003
|
places: Object.values(state.places).filter(place => placesInScope.has(place.id)).map(place => ({ id: place.id, name: place.name })),
|
|
857
1004
|
people: Object.values(state.people).filter(other => peopleInScope.has(other.id)).map(other => ({ id: other.id, name: other.name,
|
|
858
1005
|
pronouns: other.pronouns ?? 'they/them', role: here(other) ? other.role : null, lastKnownPlaceId: here(other) ? other.placeId : null, ...silentSince(state, person.id, other.id) })),
|
|
859
1006
|
},
|
|
860
|
-
playerId: state.playerId,
|
|
861
|
-
}, CHARACTER_INPUT_BUDGET, characterTrim(state, dealtWith(state, person), inTalkWith(state, person, [...focusIds, due?.targetId])), inTalkWith(state, person, [...focusIds, due?.targetId]));
|
|
1007
|
+
...(peopleInScope.has(state.playerId) ? { playerId: state.playerId } : {}),
|
|
1008
|
+
}, CHARACTER_INPUT_BUDGET, characterTrim(state, dealtWith(state, person), inTalkWith(state, person, [...focusIds, due?.targetId])), inTalkWith(state, person, [...focusIds, due?.targetId]), new Set(), nameMeasure(state));
|
|
862
1009
|
}
|
|
863
|
-
export function characterMessageReplyInput(state, person, message, focusIds = []) {
|
|
1010
|
+
export function characterMessageReplyInput(state, person, message, focusIds = [], decision) {
|
|
864
1011
|
const mind = characterMind(state, person, [message.fromId, person.placeId]);
|
|
865
1012
|
const placesInScope = knownPlaces(state, person);
|
|
866
1013
|
return fitInput({
|
|
867
1014
|
phase: 'message-reply',
|
|
868
1015
|
...mind,
|
|
869
1016
|
message: { fromId: message.fromId, from: personLabel(state, message.fromId), text: message.text },
|
|
1017
|
+
...(decision === undefined ? {} : { decision }),
|
|
870
1018
|
directory: { places: Object.values(state.places).filter(place => placesInScope.has(place.id)).map(place => ({ id: place.id, name: place.name })),
|
|
871
1019
|
...(focusIds.length === 0 ? {} : { people: focusIds.filter(id => knownPeople(state, person).has(id)).map(id => ({ id, name: state.people[id].name })) }) },
|
|
872
|
-
}, CHARACTER_INPUT_BUDGET, characterTrim(state, dealtWith(state, person), inTalkWith(state, person, [...focusIds, message.fromId])), inTalkWith(state, person, [...focusIds, message.fromId]));
|
|
1020
|
+
}, CHARACTER_INPUT_BUDGET, characterTrim(state, dealtWith(state, person), inTalkWith(state, person, [...focusIds, message.fromId])), inTalkWith(state, person, [...focusIds, message.fromId]), new Set(), nameMeasure(state));
|
|
873
1021
|
}
|
|
874
1022
|
export function epilogueInput(state) {
|
|
875
1023
|
const player = state.people[state.playerId];
|
|
@@ -879,13 +1027,11 @@ export function epilogueInput(state) {
|
|
|
879
1027
|
&& (event.importance >= 6 || event.kind === 'attempt' || event.kind === 'world')).slice(-(40 - playerChoices.length));
|
|
880
1028
|
const keyEvents = [...playerChoices, ...otherEvents].sort((left, right) => left.seq - right.seq);
|
|
881
1029
|
// From engine 40 the ending reads the chronicle of the whole story; the weightiest fifty, in order.
|
|
882
|
-
const chronicled = state.
|
|
883
|
-
|
|
884
|
-
.map(entry => ({ kind: entry.kind, at: clockLabel(entry.at), place: placeLabel(state, entry.placeId), summary: entry.summary, outcome: entry.outcome, witnesses: [] }))
|
|
885
|
-
: null;
|
|
1030
|
+
const chronicled = ([...state.chronicle.items].sort((left, right) => right.importance - left.importance || right.seq - left.seq).slice(0, 50).sort((left, right) => left.seq - right.seq)
|
|
1031
|
+
.map(entry => ({ kind: entry.kind, at: clockLabel(state.calendar, entry.at), place: placeLabel(state, entry.placeId), summary: entry.summary, outcome: entry.outcome, witnesses: [] })));
|
|
886
1032
|
return fitInput({
|
|
887
1033
|
phase: 'epilogue',
|
|
888
|
-
player: { name: player.name, role: player.role, pronouns: player.pronouns ?? 'they/them', place: placeLabel(state, player.placeId),
|
|
1034
|
+
player: { name: player.name, role: player.role, pronouns: player.pronouns ?? 'they/them', place: placeLabel(state, player.placeId), numbers: heldNumbers(state, player.id), incapacitated: player.incapacitated, forcedEnding: state.forcedEnding },
|
|
889
1035
|
opening: state.opening,
|
|
890
1036
|
tensions: state.tensions.flatMap(tension => {
|
|
891
1037
|
if (!tension.playerView)
|
|
@@ -893,7 +1039,7 @@ export function epilogueInput(state) {
|
|
|
893
1039
|
const { since: _since, latestAt: _latestAt, ...view } = tension.playerView;
|
|
894
1040
|
return [view];
|
|
895
1041
|
}),
|
|
896
|
-
...
|
|
1042
|
+
...knownChoices(state, player.id),
|
|
897
1043
|
relationships: [],
|
|
898
1044
|
whereabouts: Object.values(state.people).filter(person => person.id === player.id || person.placeId === player.placeId || state.sightings[person.id]).map(person => ({ name: person.name,
|
|
899
1045
|
place: person.id === player.id || person.placeId === player.placeId ? placeLabel(state, person.placeId) : placeLabel(state, state.sightings[person.id].placeId),
|
|
@@ -901,44 +1047,32 @@ export function epilogueInput(state) {
|
|
|
901
1047
|
condition: person.id === player.id || person.placeId === player.placeId ? person.condition ?? null : null,
|
|
902
1048
|
incapacitated: person.id === player.id || person.placeId === player.placeId ? person.incapacitated : null })),
|
|
903
1049
|
places: [{ name: state.places[player.placeId].name, conditions: [...state.places[player.placeId].conditions] }],
|
|
904
|
-
objects: Object.values(state.objects).filter(object => object.
|
|
905
|
-
|| (object.
|
|
906
|
-
condition: object.
|
|
907
|
-
where: object.
|
|
1050
|
+
objects: Object.values(state.objects).filter(object => object.containerId === player.id || object.containerId === player.placeId
|
|
1051
|
+
|| (object.containerId !== null && knowsCustody(state, object, player.id))).map(object => ({ name: object.name,
|
|
1052
|
+
condition: object.containerId === player.id || object.conditionKnownTo.includes(player.id) ? object.condition : 'unexamined',
|
|
1053
|
+
where: object.containerId !== null && state.people[object.containerId] !== undefined ? phrase('object.with', { person: personLabel(state, object.containerId) }) : placeLabel(state, object.containerId) })),
|
|
908
1054
|
commitments: Object.values(state.people).flatMap(person => person.commitments
|
|
909
1055
|
.filter(commitment => person.id === player.id || commitment.toId === player.id).map(commitment => ({ person, commitment })))
|
|
910
1056
|
.sort((left, right) => left.commitment.madeAt - right.commitment.madeAt).slice(-12)
|
|
911
1057
|
.map(({ person, commitment }) => ({ by: person.name, to: personLabel(state, commitment.toId), text: commitment.text, status: commitment.status })),
|
|
912
1058
|
keyEvents: chronicled ?? keyEvents.flatMap(event => {
|
|
913
1059
|
const summary = observedSummary(event, player.id);
|
|
914
|
-
return summary === null ? [] : [{ kind: event.kind, at: clockLabel(event.at), place: event.nearbyIds.includes(player.id) && !witnessed(event, player.id) ? null : placeLabel(state, event.placeId),
|
|
1060
|
+
return summary === null ? [] : [{ kind: event.kind, at: clockLabel(state.calendar, event.at), place: event.nearbyIds.includes(player.id) && !witnessed(event, player.id) ? null : placeLabel(state, event.placeId),
|
|
915
1061
|
summary, outcome: event.observed === undefined ? event.outcome : null, witnesses: [] }];
|
|
916
1062
|
}),
|
|
917
|
-
clock: clockLabel(state.clock),
|
|
918
|
-
}, REFEREE_INPUT_BUDGET, [[{ path: ['whereabouts'], drop: 'last', keep: 1 }, { path: ['objects'], drop: 'first' }, { path: ['keyEvents'], drop: 'first', keep: 8 }, { path: ['tensions'], drop: openFirst, keep: 1 }]]);
|
|
1063
|
+
clock: clockLabel(state.calendar, state.clock),
|
|
1064
|
+
}, REFEREE_INPUT_BUDGET, [[{ path: ['whereabouts'], drop: 'last', keep: 1 }, { path: ['objects'], drop: 'first' }, { path: ['keyEvents'], drop: 'first', keep: 8 }, { path: ['tensions'], drop: openFirst, keep: 1 }]], new Set(), new Set(), nameMeasure(state));
|
|
919
1065
|
}
|
|
920
1066
|
// Problems still open give way before settled ones, whose ends the ending tells; the oldest first within each.
|
|
921
1067
|
function openFirst(items) {
|
|
922
1068
|
const open = items.findIndex(item => item.status === 'open');
|
|
923
1069
|
return open >= 0 ? open : 0;
|
|
924
1070
|
}
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
}
|
|
934
|
-
export const WORLD_PRINCIPLES = `People know only what they perceive, read or are told. They have their own aims, duties, feelings, and judgment. The setting decides what is physically and socially possible. An act can fail yet still cause a real result. A lasting result needs a typed change in state. Speech is a statement until evidence supports its claim. Describe only what a person in the scene can sense. Keep private thoughts and unseen causes in the objective record. Use ids for known people, things, places, kinds, problems. Let serious events affect later choices.`;
|
|
935
|
-
function systemPrompt(role, schema, example) {
|
|
936
|
-
return `Role:\n${role}\nPrinciples:\n${WORLD_PRINCIPLES}\nFields:\n${responseFieldLines(schema)}\nExample:\n${example}`;
|
|
937
|
-
}
|
|
938
|
-
// One Game Master rules on both an actor's attempt and a happening that fell due; the input says which.
|
|
939
|
-
export const GAME_MASTER_SYSTEM = systemPrompt('You are the Game Master of a living world. Rule on an actor\'s attempt, which reaches only who and what is here, or a due happening. Tell the actor what they perceive, including what they read or hear, word for word, and add no act, word or feeling they did not state. Represent each lasting result with the fitting kind and typed slots; request a kind when none fits.', attemptResponseSchema, '{"outcome":"partial","stateKindFit":"complete","stateUpdates":[{"kind":"entity.create","values":{"condition":"cracked","entityId":"lamp-id","initialProperties":{},"kindId":"item","name":"Oil lamp","personId":"actor-id","placeId":"place-id"}}]}');
|
|
940
|
-
export const SPEECH_IMPACT_SYSTEM = systemPrompt('Assess one spoken line: its impact, the pressure it puts on listeners, and whether it carries. Never decide anyone\'s response.', speechImpactResponseSchema, '{"importance":3,"pressure":null,"loud":false}');
|
|
941
|
-
export const CHARACTER_REACTION_SYSTEM = systemPrompt('You are the named character. Respond to happened.pressure when it exists, then choose what you say or do now. Say nothing you already said.', reactionResponseSchema, '{"say":"I need time to think.","act":null,"request":null,"endConversation":false,"plan":{"intent":"Check the figures alone","seenDoing":"reading at the window","placeId":null,"targetId":null,"inMinutes":40}}');
|
|
942
|
-
export const CHARACTER_PLAN_SYSTEM = systemPrompt('You are the named character. What you were doing has ended, or something needs your decision. Live a whole day: eat, rest, go home when your day ends, and stop waiting when it brings nothing.', planResponseSchema, '{"action":"wait","placeId":null,"targetId":null,"text":null,"request":null,"nextPlan":{"intent":"Finish the report","seenDoing":"typing at the desk","placeId":null,"targetId":null,"inMinutes":45}}');
|
|
943
|
-
export const CHARACTER_MESSAGE_SYSTEM = systemPrompt('You are the named character answering a private message. Treat its claims as claims, then decide whether to reply and what you believe.', messageReplyResponseSchema, '{"reply":null,"belief":null,"plan":{"intent":"Find the sender","seenDoing":"heading for the stairs","placeId":null,"targetId":null,"inMinutes":10}}');
|
|
944
|
-
export const NARRATOR_EPILOGUE_SYSTEM = systemPrompt('Write an ending card from recorded outcomes. Use dry, kind humor and keep unresolved matters unresolved.', epilogueResponseSchema, '{"title":"The Long Afternoon","verdict":"The day ended.","highlights":["They went home."],"cast":[],"closing":"Tomorrow remained."}');
|
|
1071
|
+
function knownChoices(state, playerId) {
|
|
1072
|
+
const choices = Object.values(state.entities).filter(entity => entity.knownTo.includes(playerId)).slice(-MIND_SLICE)
|
|
1073
|
+
.flatMap(entity => (state.kinds[entity.kindId]?.properties ?? []).filter(property => property.type === 'series' && property.options !== undefined)
|
|
1074
|
+
.map(property => ({ name: entity.name, options: [...property.options],
|
|
1075
|
+
chosen: (Array.isArray(entity.properties[property.id]?.value) ? entity.properties[property.id].value : [])
|
|
1076
|
+
.map(entry => ({ name: personLabel(state, entry.personId), choice: entry.option })) })));
|
|
1077
|
+
return choices.length === 0 ? {} : { choices };
|
|
1078
|
+
}
|