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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (268) hide show
  1. package/README.md +629 -167
  2. package/RUST_THIRD_PARTY_LICENSES.txt +5 -5
  3. package/bin/zmux-darwin-arm64 +0 -0
  4. package/bin/zmux-linux-x64 +0 -0
  5. package/bin/ztc-audio-darwin-arm64 +0 -0
  6. package/bin/ztc-capture-darwin-arm64 +0 -0
  7. package/bin/ztc-computer-darwin-arm64 +0 -0
  8. package/bin/ztc-llm-darwin-arm64 +0 -0
  9. package/bin/ztc-tts-darwin-arm64 +0 -0
  10. package/bin/ztc-tui-darwin-arm64 +0 -0
  11. package/bin/ztc-tui-linux-x64 +0 -0
  12. package/bin/zterm-darwin-arm64 +2 -2
  13. package/dist/App.js +6 -1
  14. package/dist/agent/agent.d.ts +21 -15
  15. package/dist/agent/agent.js +389 -163
  16. package/dist/agent/backends/codex_app_server.d.ts +7 -1
  17. package/dist/agent/backends/codex_app_server.js +11 -1
  18. package/dist/agent/backends/gemini.js +22 -8
  19. package/dist/agent/commands/batch.js +8 -0
  20. package/dist/agent/commands/config.js +10 -0
  21. package/dist/agent/commands/environment.js +5 -5
  22. package/dist/agent/commands/goal.d.ts +1 -0
  23. package/dist/agent/commands/goal.js +2 -1
  24. package/dist/agent/commands/index.js +2 -1
  25. package/dist/agent/commands/manifest.js +4 -0
  26. package/dist/agent/commands/optimize.js +5 -2
  27. package/dist/agent/commands/pane_cli.d.ts +29 -0
  28. package/dist/agent/commands/pane_cli.js +303 -0
  29. package/dist/agent/commands/settings.js +13 -3
  30. package/dist/agent/commands/shannon.js +8 -0
  31. package/dist/agent/commands/update.js +15 -3
  32. package/dist/agent/commands/zerg.js +31 -1
  33. package/dist/agent/commands/ztc_pane.js +3 -1
  34. package/dist/agent/factory.d.ts +4 -0
  35. package/dist/agent/factory.js +11 -1
  36. package/dist/agent/loop_policy.d.ts +42 -5
  37. package/dist/agent/loop_policy.js +206 -3
  38. package/dist/agent/runtime/command_jobs.d.ts +5 -0
  39. package/dist/agent/runtime/command_jobs.js +241 -31
  40. package/dist/agent/runtime/command_wait.d.ts +2 -0
  41. package/dist/agent/runtime/command_wait.js +1 -0
  42. package/dist/agent/runtime/done_report.d.ts +18 -0
  43. package/dist/agent/runtime/done_report.js +130 -0
  44. package/dist/agent/runtime/execution_context.js +4 -1
  45. package/dist/agent/runtime/failure_cause.d.ts +2 -0
  46. package/dist/agent/runtime/failure_cause.js +35 -0
  47. package/dist/agent/runtime/policy.d.ts +14 -2
  48. package/dist/agent/runtime/policy.js +104 -12
  49. package/dist/agent/runtime/quiet_job.d.ts +18 -0
  50. package/dist/agent/runtime/quiet_job.js +48 -0
  51. package/dist/agent/runtime/recovery.d.ts +1 -5
  52. package/dist/agent/runtime/recovery.js +2 -44
  53. package/dist/agent/runtime/tool_runtime.d.ts +1 -0
  54. package/dist/agent/runtime/tool_runtime.js +2 -0
  55. package/dist/agent/subagent.js +6 -1
  56. package/dist/agent/tools/deferred.js +1 -0
  57. package/dist/agent/tools/index.d.ts +2 -0
  58. package/dist/agent/tools/index.js +1 -0
  59. package/dist/agent/tools/outcome.d.ts +15 -0
  60. package/dist/agent/tools/outcome.js +107 -0
  61. package/dist/agent/tools/pane.d.ts +2 -1
  62. package/dist/agent/tools/pane.js +21 -3
  63. package/dist/agent/tools/registry.js +2 -0
  64. package/dist/agent/tools/shell.d.ts +1 -0
  65. package/dist/agent/tools/shell.js +128 -17
  66. package/dist/agent/tools/sim_domain_tools.js +4 -2
  67. package/dist/agent/tools/supervision.js +4 -2
  68. package/dist/agent/tools/types.d.ts +3 -0
  69. package/dist/app/command_context.js +5 -9
  70. package/dist/app/conversation_compaction.d.ts +4 -2
  71. package/dist/app/conversation_compaction.js +16 -5
  72. package/dist/app/headless_shell_mode.d.ts +14 -0
  73. package/dist/app/headless_shell_mode.js +7 -0
  74. package/dist/app/hosted_resident.d.ts +356 -0
  75. package/dist/app/hosted_resident.js +677 -0
  76. package/dist/app/restart.js +11 -2
  77. package/dist/app/session_manager.d.ts +5 -0
  78. package/dist/app/session_manager.js +21 -6
  79. package/dist/app/session_messages.js +6 -6
  80. package/dist/app/workspace_layout_controller.js +7 -0
  81. package/dist/batch/worktree.d.ts +10 -0
  82. package/dist/batch/worktree.js +15 -0
  83. package/dist/bench/registry.js +4 -2
  84. package/dist/cli_args.js +1 -1
  85. package/dist/cli_main.js +80 -10
  86. package/dist/cli_ratatui.d.ts +75 -0
  87. package/dist/cli_ratatui.js +485 -84
  88. package/dist/components/InputArea.js +4 -4
  89. package/dist/config/execution.d.ts +10 -0
  90. package/dist/config/execution.js +10 -0
  91. package/dist/config/hosted_runtime.d.ts +4 -1
  92. package/dist/config/hosted_runtime.js +4 -1
  93. package/dist/config/permission_pin.d.ts +34 -2
  94. package/dist/config/permission_pin.js +52 -2
  95. package/dist/config/person_command_policy.d.ts +38 -0
  96. package/dist/config/person_command_policy.js +11 -0
  97. package/dist/config/profiles.d.ts +21 -0
  98. package/dist/config/profiles.js +56 -2
  99. package/dist/config/types.d.ts +4 -1
  100. package/dist/config.js +34 -19
  101. package/dist/desktop/daily/codex_exec_adapter.js +7 -2
  102. package/dist/desktop/daily/desktop_wiring.d.ts +7 -1
  103. package/dist/desktop/daily/desktop_wiring.js +11 -3
  104. package/dist/desktop/daily/recipes.js +20 -4
  105. package/dist/desktop/health.d.ts +24 -0
  106. package/dist/desktop/health.js +151 -0
  107. package/dist/desktop/native_dialogs.d.ts +37 -0
  108. package/dist/desktop/native_dialogs.js +105 -0
  109. package/dist/diagnostics/session_export.d.ts +1 -0
  110. package/dist/diagnostics/session_export.js +28 -0
  111. package/dist/embedded/registry.js +4 -2
  112. package/dist/emulation/tool_adapters.js +9 -4
  113. package/dist/emulation/ztc_addendum.js +3 -0
  114. package/dist/headless.d.ts +11 -4
  115. package/dist/headless.js +99 -34
  116. package/dist/headless_approval.d.ts +6 -0
  117. package/dist/headless_cli.js +1 -1
  118. package/dist/hooks/runner.js +7 -6
  119. package/dist/library.d.ts +4 -0
  120. package/dist/library.js +3 -0
  121. package/dist/mcp/client.js +3 -3
  122. package/dist/modes/registry.js +13 -4
  123. package/dist/onboarding/setup_environment.js +13 -1
  124. package/dist/optimize/adapters/kernelbench.js +88 -10
  125. package/dist/optimize/adapters/types.d.ts +5 -0
  126. package/dist/optimize/executor.js +21 -0
  127. package/dist/panes/cli_install.d.ts +54 -0
  128. package/dist/panes/cli_install.js +157 -0
  129. package/dist/panes/model_catalog.js +3 -0
  130. package/dist/panes/new_pane_choices.d.ts +6 -2
  131. package/dist/panes/new_pane_choices.js +24 -12
  132. package/dist/panes/pane_cli_launch.d.ts +50 -0
  133. package/dist/panes/pane_cli_launch.js +124 -0
  134. package/dist/panes/pane_clis.d.ts +171 -0
  135. package/dist/panes/pane_clis.js +325 -0
  136. package/dist/panes/person_only_panes.d.ts +45 -0
  137. package/dist/panes/person_only_panes.js +117 -0
  138. package/dist/plugin/simulation_living.js +0 -2
  139. package/dist/plugin/simulation_living_engine.d.ts +1 -0
  140. package/dist/plugin/simulation_living_engine.js +1 -0
  141. package/dist/plugin/simulation_living_labels.d.ts +3 -0
  142. package/dist/plugin/simulation_living_labels.js +2 -0
  143. package/dist/router_auth.js +12 -1
  144. package/dist/session.js +26 -1
  145. package/dist/simulation/art/gemini_image.js +11 -5
  146. package/dist/simulation/domains/loader.js +25 -3
  147. package/dist/simulation/living/cold.d.ts +23 -0
  148. package/dist/simulation/living/cold.js +41 -0
  149. package/dist/simulation/living/context.d.ts +591 -1283
  150. package/dist/simulation/living/context.js +378 -244
  151. package/dist/simulation/living/contradictions.d.ts +14 -0
  152. package/dist/simulation/living/contradictions.js +282 -0
  153. package/dist/simulation/living/core/ids.d.ts +53 -0
  154. package/dist/simulation/living/core/ids.js +39 -0
  155. package/dist/simulation/living/core/kind.d.ts +20 -0
  156. package/dist/simulation/living/core/kind.js +15 -0
  157. package/dist/simulation/living/core/laws.d.ts +179 -0
  158. package/dist/simulation/living/core/laws.js +184 -0
  159. package/dist/simulation/living/core/ops.d.ts +257 -0
  160. package/dist/simulation/living/core/ops.js +34 -0
  161. package/dist/simulation/living/definer.d.ts +17 -1
  162. package/dist/simulation/living/definer.js +130 -51
  163. package/dist/simulation/living/definition.d.ts +174 -65
  164. package/dist/simulation/living/definition.js +287 -180
  165. package/dist/simulation/living/director.d.ts +80 -0
  166. package/dist/simulation/living/director.js +363 -0
  167. package/dist/simulation/living/frame.d.ts +108 -21
  168. package/dist/simulation/living/frame.js +111 -66
  169. package/dist/simulation/living/identifiers.d.ts +0 -1
  170. package/dist/simulation/living/identifiers.js +0 -3
  171. package/dist/simulation/living/index.d.ts +18 -9
  172. package/dist/simulation/living/index.js +18 -9
  173. package/dist/simulation/living/inference.d.ts +92 -50
  174. package/dist/simulation/living/inference.js +319 -175
  175. package/dist/simulation/living/knowledge.d.ts +28 -0
  176. package/dist/simulation/living/knowledge.js +73 -0
  177. package/dist/simulation/living/library.json +1177 -0
  178. package/dist/simulation/living/mechanics.d.ts +31 -34
  179. package/dist/simulation/living/mechanics.js +222 -138
  180. package/dist/simulation/living/model-input.d.ts +6 -3
  181. package/dist/simulation/living/model-input.js +18 -26
  182. package/dist/simulation/living/open-world.d.ts +74 -94
  183. package/dist/simulation/living/open-world.js +151 -30
  184. package/dist/simulation/living/phrases.d.ts +3 -0
  185. package/dist/simulation/living/phrases.js +37 -0
  186. package/dist/simulation/living/phrases.json +560 -0
  187. package/dist/simulation/living/projection.d.ts +316 -2
  188. package/dist/simulation/living/projection.js +50 -2
  189. package/dist/simulation/living/prompts/example-spec.json +11 -0
  190. package/dist/simulation/living/prompts/role-text.json +14 -0
  191. package/dist/simulation/living/prompts.d.ts +5 -0
  192. package/dist/simulation/living/prompts.js +275 -0
  193. package/dist/simulation/living/recall.d.ts +2 -2
  194. package/dist/simulation/living/reduce.d.ts +51 -14
  195. package/dist/simulation/living/reduce.js +941 -579
  196. package/dist/simulation/living/replay.d.ts +5 -4
  197. package/dist/simulation/living/replay.js +10 -9
  198. package/dist/simulation/living/runtime.d.ts +135 -25
  199. package/dist/simulation/living/runtime.js +1641 -583
  200. package/dist/simulation/living/scale.d.ts +96 -0
  201. package/dist/simulation/living/scale.js +124 -0
  202. package/dist/simulation/living/script.d.ts +5 -0
  203. package/dist/simulation/living/script.js +115 -0
  204. package/dist/simulation/living/shared-kinds.d.ts +4 -11
  205. package/dist/simulation/living/shared-kinds.js +11 -81
  206. package/dist/simulation/living/space.d.ts +14 -0
  207. package/dist/simulation/living/space.js +132 -0
  208. package/dist/simulation/living/state.d.ts +100 -0
  209. package/dist/simulation/living/state.js +393 -0
  210. package/dist/simulation/living/types.d.ts +829 -512
  211. package/dist/simulation/living/types.js +162 -187
  212. package/dist/simulation/living/world-rules.d.ts +100 -0
  213. package/dist/simulation/living/world-rules.js +267 -0
  214. package/dist/simulation/plugins/loader.js +11 -0
  215. package/dist/skills/loader.js +4 -0
  216. package/dist/tools.d.ts +1 -0
  217. package/dist/tools.js +1 -0
  218. package/dist/ui/ratatui/headless_pane_manager.d.ts +4 -1
  219. package/dist/ui/ratatui/headless_pane_manager.js +13 -9
  220. package/dist/ui/ratatui/pane_relay.js +29 -0
  221. package/dist/ui/ratatui/pane_type.d.ts +10 -0
  222. package/dist/ui/ratatui/pane_type.js +11 -0
  223. package/dist/ui/ratatui/process.d.ts +30 -0
  224. package/dist/ui/ratatui/process.js +133 -19
  225. package/dist/ui/ratatui/protocol.d.ts +124 -2
  226. package/dist/ui/ratatui/protocol.js +35 -0
  227. package/dist/ui/ratatui/relay_policy.js +3 -0
  228. package/dist/ui/ratatui/ztc_launch_trust.d.ts +2 -1
  229. package/dist/ui/ratatui/ztc_launch_trust.js +8 -1
  230. package/dist/ui/terminal_image.d.ts +12 -0
  231. package/dist/ui/terminal_image.js +21 -1
  232. package/dist/utils/codex_project_trust.d.ts +19 -0
  233. package/dist/utils/codex_project_trust.js +37 -0
  234. package/dist/utils/compaction.js +103 -20
  235. package/dist/utils/git_program_files.d.ts +19 -12
  236. package/dist/utils/git_program_files.js +411 -83
  237. package/dist/utils/host_shell.d.ts +10 -1
  238. package/dist/utils/host_shell.js +14 -1
  239. package/dist/utils/mid_turn_compaction.d.ts +2 -0
  240. package/dist/utils/mid_turn_compaction.js +2 -0
  241. package/dist/utils/models.js +6 -1
  242. package/dist/utils/sandbox.d.ts +109 -8
  243. package/dist/utils/sandbox.js +981 -187
  244. package/dist/utils/shell.d.ts +2 -0
  245. package/dist/utils/shell.js +10 -4
  246. package/dist/utils/subprocess_env.d.ts +47 -11
  247. package/dist/utils/subprocess_env.js +107 -15
  248. package/dist/utils/system_ps.d.ts +8 -0
  249. package/dist/utils/system_ps.js +39 -7
  250. package/dist/utils/unattended_compaction.d.ts +9 -0
  251. package/dist/utils/unattended_compaction.js +13 -0
  252. package/dist/utils/ztc_own_state.d.ts +8 -5
  253. package/dist/utils/ztc_own_state.js +17 -11
  254. package/dist/web/mirror_client.js +1 -0
  255. package/dist/web/mirror_stream.d.ts +50 -6
  256. package/dist/web/mirror_stream.js +160 -15
  257. package/dist/workflows/registry.js +3 -1
  258. package/dist/workspace/controller.js +12 -0
  259. package/dist/workspace_collision.d.ts +3 -0
  260. package/dist/workspace_collision.js +14 -1
  261. package/dist/workspace_session_context.js +2 -1
  262. package/dist/zlm-embed.mjs +3823 -1970
  263. package/node_modules/@zerg/model-contracts/README.md +16 -4
  264. package/node_modules/@zerg/model-contracts/index.js +6 -1
  265. package/npm-shrinkwrap.json +1 -1
  266. package/package.json +42 -24
  267. package/packages/model-contracts/README.md +16 -4
  268. package/packages/model-contracts/index.js +6 -1
@@ -2,36 +2,78 @@
2
2
  // schemas, then validates every answer before it can touch the world.
3
3
  import { LIVING_ENGINE_VERSION, MAX_ADDED_LINE, MAX_ROLE, MAX_SPOKEN } from './types.js';
4
4
  import { neverHeld } from './shared-kinds.js';
5
- export const LIVING_INFERENCE_LIMITS = Object.freeze({
6
- attempt: { maxTokens: 1200, timeoutMs: 60_000 },
7
- world: { maxTokens: 1200, timeoutMs: 60_000 },
8
- 'speech-impact': { maxTokens: 200, timeoutMs: 20_000 },
9
- reaction: { maxTokens: 500, timeoutMs: 30_000 },
10
- reply: { maxTokens: 500, timeoutMs: 30_000 },
11
- plan: { maxTokens: 500, timeoutMs: 30_000 },
12
- 'message-reply': { maxTokens: 500, timeoutMs: 30_000 },
13
- epilogue: { maxTokens: 900, timeoutMs: 45_000 },
14
- define: { maxTokens: 700, timeoutMs: 45_000 },
15
- });
5
+ import { phrase } from './phrases.js';
6
+ export const LIVING_ANSWER_CHARS_PER_TOKEN = 2;
7
+ export const LIVING_TRUNCATED_ANSWER_CODE = 'output-truncated';
8
+ const numberChars = (schema) => {
9
+ const bounds = [schema.minimum, schema.maximum, schema.exclusiveMinimum, schema.exclusiveMaximum]
10
+ .filter((value) => typeof value === 'number');
11
+ return bounds.length === 0 ? 16 : String(Math.max(...bounds.map(Math.abs))).length + 4;
12
+ };
13
+ const schemaChars = (schema, depth) => {
14
+ if (depth > 40 || schema === null || typeof schema !== 'object')
15
+ return 0;
16
+ if (schema.const !== undefined)
17
+ return JSON.stringify(schema.const).length;
18
+ if (Array.isArray(schema.enum))
19
+ return Math.max(...schema.enum.map(value => JSON.stringify(value).length));
20
+ const alternatives = (schema.anyOf ?? schema.oneOf);
21
+ if (Array.isArray(alternatives))
22
+ return Math.max(...alternatives.map(arm => schemaChars(arm, depth + 1)));
23
+ if (schema.type === 'null')
24
+ return 4;
25
+ if (schema.type === 'boolean')
26
+ return 5;
27
+ if (schema.type === 'integer' || schema.type === 'number')
28
+ return numberChars(schema);
29
+ if (schema.type === 'string')
30
+ return typeof schema.maxLength === 'number' ? schema.maxLength + 2 : 0;
31
+ if (schema.type === 'array') {
32
+ const items = schemaChars(schema.items, depth + 1);
33
+ const max = typeof schema.maxItems === 'number' ? schema.maxItems : 0;
34
+ return max === 0 ? 2 : max * (items + 1) + 1;
35
+ }
36
+ const properties = schema.properties ?? {};
37
+ const listed = Object.keys(properties).reduce((sum, key) => sum + key.length + 4 + schemaChars(properties[key], depth + 1), 2);
38
+ const additional = schema.additionalProperties;
39
+ if (additional === undefined || additional === false)
40
+ return listed;
41
+ const max = typeof schema.maxProperties === 'number' ? schema.maxProperties : 0;
42
+ const value = additional === true ? 0 : schemaChars(additional, depth + 1);
43
+ return listed + max * (value + 65);
44
+ };
45
+ export function schemaWorstCaseChars(schema) {
46
+ return schemaChars(schema, 0);
47
+ }
48
+ export function livingAnswerTokens(schema) {
49
+ return Math.ceil(schemaWorstCaseChars(schema) / LIVING_ANSWER_CHARS_PER_TOKEN);
50
+ }
51
+ export function livingAnswerWasCutOff(completion, maxTokens) {
52
+ if (completion === undefined)
53
+ return false;
54
+ if (completion.finishReason === 'length' || completion.finishReason === 'max_tokens')
55
+ return true;
56
+ return typeof completion.completionTokens === 'number' && completion.completionTokens >= maxTokens;
57
+ }
16
58
  // JSON schemas for structured answers. They stay small so a modest model can fill
17
59
  // them, and every value they admit is re-checked against the world before commit.
18
60
  const str = (maxLength) => ({ type: 'string', minLength: 1, maxLength });
61
+ const blank = (maxLength) => ({ type: 'string', maxLength });
19
62
  const nullable = (schema) => ({ anyOf: [schema, { type: 'null' }] });
20
63
  const ids = (max) => ({ type: 'array', items: str(64), maxItems: max });
21
- export const GM_EFFECT_KINDS = ['move', 'take', 'drop', 'object.update', 'object.create', 'place.condition', 'place.create', 'person.create', 'money', 'transfer', 'relationship', 'belief', 'commitment', 'goal', 'mood', 'person.condition', 'hold', 'role', 'schedule', 'fact', 'tension.update', 'tension.create', 'incapacitate', 'message', 'entity.create', 'property.set', 'relation.set', 'request.open', 'person.leave', 'person.away', 'ballot'];
64
+ export const GM_EFFECT_KINDS = ['move', 'take', 'drop', 'object.update', 'object.create', 'place.condition', 'place.create', 'person.create', 'shift', 'relationship', 'belief', 'commitment', 'goal', 'mood', 'person.condition', 'hold', 'role', 'schedule', 'fact', 'tension.update', 'tension.create', 'incapacitate', 'message', 'entity.create', 'property.set', 'cell.add', 'relation.set', 'request.open', 'person.leave', 'person.offstage'];
22
65
  const described = (schema, description) => ({ ...schema, description });
23
66
  // What each kind of typed change means. The fields block shows it beside the kind's fields.
24
67
  const EFFECT_MEANINGS = {
25
68
  move: 'personId goes to the neighboring placeId.',
26
69
  take: 'personId picks up or is handed objectId here.',
27
70
  drop: 'The holder puts objectId down at placeId.',
28
- 'object.update': 'objectId\'s condition, holder targetId, place placeId or owner personId change; null keeps one.',
71
+ 'object.update': 'objectId\'s condition, holder, place or owner changes; null keeps.',
29
72
  'object.create': 'A new object exists.',
30
73
  'place.condition': 'A condition of a place changes.',
31
74
  'place.create': 'A new place placeId, with name and text, joins its connections.',
32
- 'person.create': 'A new person personId, name and role, at placeId: anyone narrated who could be spoken to; person.away if only on a call.',
33
- money: "personId's money changes by amount.",
34
- transfer: 'amount passes from personId to targetId; null is outside the world.',
75
+ 'person.create': 'A new person personId, name and role, at placeId: anyone narrated who could be spoken to; person.offstage if only on a call.',
76
+ shift: 'amount of the number slot passes from personId to targetId; null is outside.',
35
77
  relationship: "A person's trust or warmth toward another changes.",
36
78
  belief: 'A person now holds a claim as true.',
37
79
  commitment: 'A person promises something to another.',
@@ -40,19 +82,19 @@ const EFFECT_MEANINGS = {
40
82
  'person.condition': "A person's visible physical state changes.",
41
83
  hold: 'A person is kept where they are by another.',
42
84
  role: "A person's role changes.",
43
- schedule: 'A world happening, text, comes due at placeId in minutes; targetId is what it concerns.',
85
+ schedule: 'A world happening, text, comes due at placeId in minutes.',
44
86
  fact: 'A fact about the world changes.',
45
87
  'tension.update': 'A problem changes status.',
46
88
  'tension.create': 'A new problem opens.',
47
- incapacitate: 'personId can no longer act, for the reason in text; a typed condition must now stop them.',
89
+ incapacitate: 'personId can no longer act, for the reason in text; a typed condition must stop them.',
48
90
  message: 'A written message reaches another person.',
49
- 'entity.create': 'A new thing entityId of kindId, named name, at placeId or no place (an agreement, debt, right or rumor); initialProperties holds its required values.',
50
- 'property.set': 'propertyId of entityId becomes value; text replaces it whole, null erases it; a time counts minutes as clockMinutes does.',
91
+ 'entity.create': 'A new thing entityId of kindId, named name, at placeId or no place; initialProperties holds required values.',
92
+ 'property.set': 'propertyId of entityId becomes value; text replaces it whole, null erases it.',
51
93
  'relation.set': 'relationId of entityId links to targetId; null unlinks.',
94
+ 'cell.add': 'A series on a thing gains one entry.',
52
95
  'request.open': 'The actor personId asks targetId here to do text; priorId names a known request this repeats.',
53
- 'person.leave': 'personId leaves this world for good: quit, moved or died; text says why.',
54
- 'person.away': 'personId is away for minutes: home, asleep or an errand; text says where.',
55
- ballot: 'The actor\'s own vote.',
96
+ 'person.leave': 'personId leaves for good; text says why.',
97
+ 'person.offstage': 'personId is offstage for minutes: home, asleep or an errand; text says where.',
56
98
  };
57
99
  // A world begun on engines 42 to 44 adds each write to a paper as a line of its own.
58
100
  const ADDED_LINE_MEANING = 'propertyId of entityId becomes value; text adds a line, null erases it; a time counts minutes as clockMinutes does.';
@@ -63,17 +105,18 @@ const effectFields = {
63
105
  placeId: described(nullable(str(64)), 'Place where this change occurs; null when it has no place.'),
64
106
  objectId: described(nullable(str(64)), 'Existing object id; a written thing or token here counts as one.'),
65
107
  tensionId: described(nullable(str(64)), 'Existing or new problem id.'),
66
- name: described(nullable(str(120)), 'Name or stable aspect id for this change.'),
67
- text: described(nullable(str(600)), 'Current value or short description; null to clear it.'),
68
- condition: described(nullable(str(200)), 'Object condition; null when unchanged.'),
108
+ name: described(nullable(str(80)), 'Name or stable aspect id for this change.'),
109
+ text: described(nullable(str(200)), 'Current value or short description; null to clear it.'),
110
+ condition: described(nullable(str(120)), 'Object condition; null when unchanged.'),
69
111
  // A newcomer's role is offered only as long as the world accepts.
70
112
  role: described(nullable(str(MAX_ROLE)), 'Their job or role in a few words, as anyone could tell, such as "site visitor"; never how they stand.'),
71
- amount: described(nullable({ type: 'integer', minimum: -1_000_000_000, maximum: 1_000_000_000 }), 'Signed change in money.'),
113
+ amount: described(nullable({ type: 'integer', minimum: -1_000_000_000, maximum: 1_000_000_000 }), 'How much of the slot\'s unit moves.'),
114
+ slot: described(nullable(str(64)), 'Number slot the world declares, with its unit and bounds.'),
72
115
  trust: described(nullable({ type: 'integer', minimum: -40, maximum: 40 }), 'Change in trust.'),
73
116
  warmth: described(nullable({ type: 'integer', minimum: -40, maximum: 40 }), 'Change in warmth.'),
74
117
  minutes: described(nullable({ type: 'integer', minimum: 0, maximum: 100_000 }), 'Minutes until due or spent.'),
75
118
  connections: described(nullable(ids(4)), 'Place ids connected to a new place.'),
76
- participantIds: described(nullable(ids(6)), 'People involved in a problem.'),
119
+ participantIds: described(nullable(ids(4)), 'People involved in a problem.'),
77
120
  status: described(nullable({ type: 'string', enum: ['open', 'settled'] }), 'Current problem status.'),
78
121
  entityId: described(nullable(str(64)), 'Id of a typed entity.'),
79
122
  kindId: described(nullable(str(64)), 'Kind id from the local kind definitions.'),
@@ -81,9 +124,10 @@ const effectFields = {
81
124
  relationId: described(nullable(str(64)), 'Relation id defined by the entity kind.'),
82
125
  roleId: described(nullable(str(64)), 'Typed role id granted to this person; null removes an earlier role.'),
83
126
  priorId: described(nullable(str(64)), 'Known request id when repeating or rewording that request; otherwise null.'),
84
- value: described(nullable({ anyOf: [{ type: 'boolean' }, { type: 'number' }, str(2000)] }), 'Typed property value; use text for written content and null to clear it.'),
85
- choice: described(nullable({ type: 'string', enum: ['yes', 'no', 'abstain'] }), 'The vote cast.'),
86
- initialProperties: described({ type: 'object', additionalProperties: true }, 'Typed values written when the entity is created; include required values such as a document body.'),
127
+ value: described(nullable({ anyOf: [{ type: 'boolean' }, { type: 'number' }, str(300)] }), 'Typed property value; use text for written content and null to clear it.'),
128
+ slotId: described(nullable(str(64)), 'Series slot defined by the entity kind.'),
129
+ option: described(nullable(str(64)), 'One option the series admits.'),
130
+ initialProperties: described({ type: 'object', maxProperties: 4, additionalProperties: { anyOf: [{ type: 'boolean' }, { type: 'number' }, str(200)] } }, 'Typed values written when the entity is created; include required values such as a document body.'),
87
131
  };
88
132
  const fieldsByEffect = {
89
133
  move: ['personId', 'placeId'],
@@ -94,8 +138,7 @@ const fieldsByEffect = {
94
138
  'place.condition': ['placeId', 'name', 'text'],
95
139
  'place.create': ['placeId', 'name', 'text', 'connections'],
96
140
  'person.create': ['personId', 'name', 'role', 'text', 'placeId'],
97
- money: ['personId', 'amount'],
98
- transfer: ['personId', 'targetId', 'amount'],
141
+ shift: ['slot', 'personId', 'targetId', 'amount'],
99
142
  relationship: ['personId', 'targetId', 'trust', 'warmth'],
100
143
  belief: ['personId', 'name', 'text'],
101
144
  commitment: ['personId', 'targetId', 'text', 'minutes'],
@@ -113,24 +156,24 @@ const fieldsByEffect = {
113
156
  'entity.create': ['entityId', 'kindId', 'name', 'placeId', 'condition', 'personId', 'participantIds', 'initialProperties'],
114
157
  'property.set': ['entityId', 'propertyId', 'value'],
115
158
  'relation.set': ['entityId', 'relationId', 'targetId'],
159
+ 'cell.add': ['entityId', 'slotId', 'option', 'personId'],
116
160
  'request.open': ['personId', 'targetId', 'text', 'priorId'],
117
161
  'person.leave': ['personId', 'text'],
118
- 'person.away': ['personId', 'minutes', 'text'],
119
- ballot: ['entityId', 'personId', 'choice'],
162
+ 'person.offstage': ['personId', 'minutes', 'text'],
120
163
  };
121
164
  // Old events still decode through GmEffectRecord. New rulings use typed entities
122
165
  // for lasting things instead of open-ended prose records.
123
166
  const nonGmEffectKinds = new Set([
124
- 'fact', 'place.condition', 'object.create', 'money',
167
+ 'fact', 'place.condition', 'object.create',
125
168
  'belief', 'relationship', 'message', 'goal', 'mood', 'commitment', 'hold', 'person.condition',
126
169
  'tension.create', 'tension.update', 'role',
127
170
  ]);
128
171
  const requiredEffectValues = {
129
- 'place.create': ['name', 'text'], 'person.create': ['name', 'text'], money: ['amount'], transfer: ['amount'],
172
+ 'place.create': ['name', 'text'], 'person.create': ['name', 'text'], shift: ['slot', 'amount'],
130
173
  role: ['text'], schedule: ['text', 'minutes'], incapacitate: ['text'],
131
174
  'entity.create': ['entityId', 'name', 'initialProperties'], 'property.set': ['entityId', 'propertyId'],
132
- 'relation.set': ['entityId', 'relationId'], 'request.open': ['text'], 'person.leave': ['personId', 'text'],
133
- 'person.away': ['personId', 'minutes', 'text'], ballot: ['entityId', 'choice'],
175
+ 'relation.set': ['entityId', 'relationId'], 'cell.add': ['entityId', 'slotId', 'option', 'personId'], 'request.open': ['text'], 'person.leave': ['personId', 'text'],
176
+ 'person.offstage': ['personId', 'minutes', 'text'],
134
177
  };
135
178
  function effectField(kind, field) {
136
179
  const source = effectFields[field];
@@ -138,15 +181,10 @@ function effectField(kind, field) {
138
181
  return source;
139
182
  if (kind === 'schedule' && field === 'minutes')
140
183
  return described({ type: 'integer', minimum: 1, maximum: 100_000 }, source.description);
141
- if (kind === 'person.away' && field === 'minutes')
142
- return described({ type: 'integer', minimum: 15, maximum: 1440 }, source.description);
143
- if (kind === 'transfer' && field === 'amount')
184
+ if (kind === 'person.offstage' && field === 'minutes')
185
+ return described({ type: 'integer', minimum: 1, maximum: 1_000_000_000 }, source.description);
186
+ if (kind === 'shift' && field === 'amount')
144
187
  return described({ type: 'number', exclusiveMinimum: 0, maximum: 1_000_000_000 }, source.description);
145
- if (kind === 'money' && field === 'amount')
146
- return described({ anyOf: [
147
- { type: 'integer', minimum: -1_000_000_000, maximum: -1 },
148
- { type: 'integer', minimum: 1, maximum: 1_000_000_000 },
149
- ] }, source.description);
150
188
  if (!requiredEffectValues[kind]?.includes(field))
151
189
  return source;
152
190
  const variants = source.anyOf;
@@ -172,16 +210,16 @@ const FIELD_MEANINGS = {
172
210
  'place.create': { placeId: 'Id for the new place.', name: 'Name of the new place.', text: 'Short description of the new place.' },
173
211
  'person.create': { personId: 'Id for the new person.', name: 'Full name of the new person.',
174
212
  text: 'What brought them here and what they want now, in their own terms.', placeId: 'Place where the person appears.' },
175
- money: { personId: 'Person whose money changes.' },
176
- transfer: { personId: 'Who pays: a person or an account id; null when it comes from outside the world.', targetId: 'Who receives: a person or an account id; null when it leaves the world.',
177
- amount: 'How much, in the world\'s money unit; parts of a unit are allowed.' },
213
+ shift: { slot: 'The number slot the world declares.', personId: 'Who gives: a person, thing or place id; null when it comes from outside the world.',
214
+ targetId: 'Who receives: a person, thing or place id; null when it leaves the world.', amount: 'How much, in the slot\'s unit; parts of a unit are allowed.' },
178
215
  schedule: { personId: 'Always null; people choose their own plans.', minutes: 'Minutes until it happens.', text: 'What will happen.',
179
216
  placeId: 'Place where it happens.', targetId: 'Entity or person it concerns; null when none.' },
180
217
  incapacitate: { personId: 'Person who can no longer act.', text: 'Why they cannot act.' },
181
218
  'entity.create': { participantIds: 'A decision\'s voters; else null.', name: 'Name of the new thing.', placeId: 'Place where the new thing is; null when it belongs to no place, such as an agreement, a debt, a right, or a rumor.',
182
219
  condition: 'How it is now, as anyone could see; null when it belongs to no place.', personId: 'Person here whose hand the act leaves it in; null for words on a wall, a board or a thing, and for anything that lies there.' },
220
+ 'cell.add': { entityId: 'The thing at hand.', slotId: 'The series that gains an entry.', option: 'The entry to add.', personId: 'Who makes the entry.' },
183
221
  'person.leave': { personId: 'Person who leaves.', text: 'Why and how they leave.' },
184
- 'person.away': { personId: 'Person who goes away for a while.', minutes: 'Minutes until they are back.', text: 'Where they go and why.' },
222
+ 'person.offstage': { personId: 'Person who goes offstage for a while.', minutes: 'Minutes until they are back.', text: 'Where they go and why.' },
185
223
  'request.open': { personId: 'Actor who makes the request.', targetId: 'Person here who receives the request.',
186
224
  priorId: 'Known request id when repeating or rewording that request; otherwise null.', text: 'Action requested, with no answer implied.' },
187
225
  };
@@ -213,82 +251,80 @@ export function responseFieldLines(schema) {
213
251
  }
214
252
  // The provider emits object keys in sorted order. The names make that order the order of
215
253
  // reasoning: the written result comes first, then whether a kind fits, then the typed changes.
216
- // What a ruling may carry to the rooms around, each worded by the engine, so a notice never names anyone.
217
- export const SIGNAL_SENSES = ['sound', 'voices', 'shouting', 'scream', 'crash', 'bang', 'alarm', 'machinery', 'footsteps', 'music', 'loudspeaker', 'sight', 'light', 'smoke', 'burning', 'smell'];
218
- export const SIGNAL_NOTICES = {
219
- sound: 'A sound reaches', voices: 'Voices carry', shouting: 'Shouting carries', scream: 'A scream carries', crash: 'A crash carries', bang: 'A bang carries',
220
- alarm: 'An alarm sounds', machinery: 'The noise of machinery carries', footsteps: 'Running feet sound', music: 'Music carries', loudspeaker: 'A voice on a loudspeaker carries',
221
- sight: 'A sight reaches', light: 'A light shows', smoke: 'Smoke drifts', burning: 'A smell of burning drifts', smell: 'A smell reaches',
222
- };
223
254
  export const attemptResponseSchema = {
224
255
  type: 'object',
225
256
  additionalProperties: false,
226
- required: ['narration', 'record', 'observed', 'perceivedBy', 'visibleObjectIds', 'visibleTensionIds', 'outcome', 'minutes', 'importance', 'reach', 'signalChannel', 'actionKind', 'reactorIds', 'settledTensionId', 'settlement', 'newTension', 'stateKindFit', 'stateNewKind', 'stateUpdates', 'thingIds'],
257
+ required: ['narration', 'record', 'reason', 'observed', 'perceivedBy', 'visibleObjectIds', 'visibleTensionIds', 'outcome', 'minutes', 'importance', 'reach', 'signalChannel', 'actionKind', 'reactorIds', 'settledTensionId', 'settlement', 'newTension', 'stateKindFit', 'stateNewKind', 'stateNoted', 'stateUpdates', 'thingIds', 'contactIds'],
227
258
  properties: {
228
- narration: described(str(900), 'What the actor senses now, in the requested voice.'),
259
+ narration: described(str(900), 'What the actor senses now.'),
229
260
  record: described(str(300), 'Objective result, hidden facts included.'),
261
+ reason: described(blank(300), phrase('prompt.reason')),
230
262
  observed: described(str(600), 'What onlookers here see: outward behavior only.'),
231
- perceivedBy: described(ids(32), 'Present people who noticed it.'),
232
- visibleObjectIds: described(ids(48), 'Local objects whose state onlookers see.'),
233
- visibleTensionIds: described(ids(32), 'Local problems whose status onlookers see.'),
234
- outcome: described({ type: 'string', enum: ['succeeded', 'partial', 'failed', 'impossible'] }, 'What happened to the attempt.'),
235
- minutes: described({ type: 'integer', minimum: 0, maximum: 240 }, 'Game minutes it takes.'),
236
- importance: described({ type: 'integer', minimum: 1, maximum: 10 }, 'Impact, 1 routine to 10 life changing.'),
237
- reach: described({ type: 'string', enum: ['here', 'nearby', 'everywhere'] }, 'here, nearby (a shout, crash or smoke carries next door), or everywhere.'),
238
- signalChannel: described(nullable({ type: 'string', enum: [...SIGNAL_SENSES] }), 'For nearby or everywhere, what carries to the rooms around; else null.'),
263
+ perceivedBy: described(ids(6), 'Present people who noticed it.'),
264
+ visibleObjectIds: described(ids(6), 'Objects this act changed, which onlookers see.'),
265
+ visibleTensionIds: described(ids(6), 'Local changed problems onlookers see.'),
266
+ outcome: described({ type: 'string', enum: ['succeeded', 'partial', 'failed', 'impossible'] }, 'What happened.'),
267
+ minutes: described({ type: 'integer', minimum: 0, maximum: 1_000_000_000 }, 'Ticks it takes.'),
268
+ importance: described({ type: 'integer', minimum: 1, maximum: 10 }, 'Impact, 1 routine to 10 severe.'),
269
+ reach: described({ type: 'string', enum: ['here', 'nearby', 'everywhere'] }, 'here, nearby, everywhere.'),
270
+ signalChannel: described(nullable(str(64)), 'The world channel this carries on, from the channels it declares; else null.'),
239
271
  actionKind: described(nullable(str(64)), 'Act category from a local norm; null when none covers it.'),
240
- reactorIds: described(ids(2), 'Up to two present people who react now.'),
272
+ reactorIds: described(ids(2), 'Present people who react now.'),
241
273
  settledTensionId: described(nullable(str(64)), 'Problem this resolves; else null.'),
242
- settlement: described(nullable(str(600)), 'How that problem ended.'),
243
- newTension: described(nullable({ type: 'object', additionalProperties: false, required: ['title', 'summary', 'participantIds', 'visible'], properties: { title: str(120), summary: str(600), participantIds: ids(6), visible: { type: 'boolean' } } }), 'A new problem; else null.'),
244
- stateKindFit: described({ type: 'string', enum: ['not-needed', 'complete', 'missing'] }, 'complete: typed slots hold every lasting part; missing: no listed kind fits; not-needed: nothing lasting changes.'),
245
- stateNewKind: described(nullable({ type: 'object', additionalProperties: false, required: ['id', 'name', 'meaning'], properties: { id: str(64), name: str(120), meaning: str(300) } }), 'When stateKindFit is missing: id, name and general meaning of a reusable kind.'),
246
- stateUpdates: described({ type: 'array', items: gmEffectSchema, maxItems: 8 }, 'Typed changes that make the result last, each as its kind with fields in values.'),
247
- thingIds: described(ids(8), 'Things here the act handles, uses or changes.'),
274
+ settlement: described(nullable(str(200)), 'How that problem ended.'),
275
+ newTension: described(nullable({ type: 'object', additionalProperties: false, required: ['title', 'summary', 'participantIds', 'visible'], properties: { title: str(80), summary: str(200), participantIds: ids(3), visible: { type: 'boolean' } } }), 'A new problem; else null.'),
276
+ stateKindFit: described({ type: 'string', enum: ['not-needed', 'complete', 'missing', 'noted'] }, 'complete: every lasting part is in slots; missing: no kind fits; noted: a lasting part fits no slot and is noted under a facet; not-needed: nothing lasting changes.'),
277
+ stateNewKind: described(nullable({ type: 'object', additionalProperties: false, required: ['id', 'name', 'meaning'], properties: { id: str(64), name: str(60), meaning: str(80) } }), 'When missing: id, name, meaning.'),
278
+ stateNoted: described({ type: 'array', items: { type: 'object', additionalProperties: false, required: ['facet', 'text', 'kindId'], properties: { facet: str(64), text: str(200), kindId: nullable(str(64)) } }, maxItems: 3 }, phrase('prompt.stateNoted')),
279
+ stateUpdates: described({ type: 'array', items: gmEffectSchema, maxItems: 5 }, 'Typed changes that last.'),
280
+ thingIds: described(ids(4), 'Things here the act touches.'),
281
+ contactIds: described(ids(4), 'People elsewhere this act reaches; empty if none.'),
248
282
  },
249
283
  };
250
284
  export function scopedAttemptResponseSchema(input) {
251
- const kinds = input.kinds;
252
- const kindIds = [...new Set(kinds.map(kind => kind.id))].sort();
253
- const propertyIds = [...new Set(kinds.flatMap(kind => kind.properties.map(property => property.id)))].sort();
254
- const relationIds = [...new Set(kinds.flatMap(kind => kind.relations.map(relation => relation.id)))].sort();
285
+ const declaredKinds = input.kinds;
255
286
  const world = input.world;
256
287
  const scene = input.scene;
288
+ const kinds = declaredKinds.filter(kind => kind.legacy !== true || scene.entities.some(entity => entity.kindId === kind.id));
289
+ const kindIds = [...new Set(kinds.map(kind => kind.id))];
290
+ const propertyIds = [...new Set(kinds.flatMap(kind => kind.properties.map(property => property.id)))];
291
+ const relationIds = [...new Set(kinds.flatMap(kind => kind.relations.map(relation => relation.id)))];
257
292
  const actor = input.actor;
258
- // Only the actor votes in their own act, and only on a decision open to them.
259
- const voteIds = (actor?.votes ?? []).map(vote => vote.id).sort();
260
293
  const requests = input.requests ?? [];
261
294
  // The selected present IDs and cards share one response vocabulary.
262
295
  const present = input.possiblePerceiverIds ?? [];
263
296
  const localPeople = new Set([...scene.people.map(person => person.id), ...present, ...(actor ? [actor.id] : [])]);
264
297
  const people = world.people;
265
- const personIds = [...new Set([...people.map(person => person.id), ...present])].sort();
266
- const placeIds = world.places.map(place => place.id).sort();
298
+ const personIds = [...new Set([...people.map(person => person.id), ...present])];
299
+ const elsewhereIds = [...new Set([...people.filter(person => !localPeople.has(person.id)).map(person => person.id),
300
+ ...(world.elsewhere ?? []).map(person => person.id)])];
301
+ const placeIds = world.places.map(place => place.id);
267
302
  // Things at this place come from the scene; the directory adds what is nearby or held.
268
- const objects = [...scene.objects.map(object => ({ id: object.id, placeId: scene.id, holderId: null })), ...world.objects];
269
- const objectIds = [...new Set(objects.map(object => object.id))].sort();
270
- const localObjectIds = [...new Set(objects.filter(object => object.placeId === scene.id
271
- || (object.holderId !== null && localPeople.has(object.holderId))).map(object => object.id))].sort();
303
+ const objects = [...scene.objects.map(object => ({ id: object.id, containerId: scene.id })), ...world.objects];
304
+ const objectIds = [...new Set(objects.map(object => object.id))];
305
+ const localObjectIds = [...new Set(objects.filter(object => object.containerId === scene.id
306
+ || (object.containerId !== null && localPeople.has(object.containerId))).map(object => object.id))];
272
307
  // A written thing or token that is here changes hands the way an object does.
273
308
  const carriable = scene.entities.flatMap(entity => entity.holderId === undefined ? []
274
- : [{ id: entity.id, placeId: entity.holderId === null ? scene.id : null, holderId: entity.holderId }]);
309
+ : [{ id: entity.id, containerId: entity.holderId ?? scene.id }]);
275
310
  const reachable = [...objects, ...carriable];
276
- const takeIds = [...new Set([...localObjectIds, ...carriable.map(thing => thing.id)])].sort();
277
- const heldObjectIds = [...world.objects, ...carriable].filter(object => object.holderId !== null && localPeople.has(object.holderId))
278
- .map(object => object.id).sort();
279
- const tensionIds = world.tensions.map(tension => tension.id).sort();
311
+ const takeIds = [...new Set([...localObjectIds, ...carriable.map(thing => thing.id)])];
312
+ const heldObjectIds = [...world.objects, ...carriable].filter(object => object.containerId !== null && localPeople.has(object.containerId))
313
+ .map(object => object.id);
314
+ const tensionIds = world.tensions.map(tension => tension.id);
280
315
  const visibleTensionIds = world.tensions.filter(tension => tension.participants.some(person => localPeople.has(person.id)))
281
- .map(tension => tension.id).sort();
282
- const perceiverIds = input.possiblePerceiverIds.slice().sort();
283
- const reactorIds = input.presentCharacterIds.slice().sort();
284
- const knownIds = [...new Set([...personIds, ...placeIds])].sort();
316
+ .map(tension => tension.id);
317
+ const perceiverIds = input.possiblePerceiverIds.slice();
318
+ const reactorIds = input.presentCharacterIds.slice();
319
+ const channelIds = (input.channels ?? []).map(channel => channel.id);
320
+ const { signalChannel: signalChannelField } = attemptResponseSchema.properties;
321
+ const knownIds = [...new Set([...personIds, ...placeIds])];
285
322
  const typedValue = (type) => type === 'flag' ? { type: 'boolean' } : type === 'number' ? { type: 'number' }
286
323
  : type === 'time' ? { type: 'integer', minimum: 0 } : type === 'level' ? { type: 'string', enum: ['none', 'low', 'medium', 'high'] }
287
- : type === 'id' ? { type: 'string', enum: knownIds } : str(2000);
324
+ : type === 'id' ? { type: 'string', enum: knownIds } : str(300);
288
325
  const idField = (ids, field, optional = false) => described(optional ? nullable({ type: 'string', enum: ids }) : { type: 'string', enum: ids }, effectFields[field].description);
289
326
  // A ruling names the kind of act when a norm or a gate in scope speaks about that kind.
290
- const actionKinds = [...new Set(kinds.flatMap(kind => kind.mechanics.flatMap(mechanic => mechanic.kind === 'norm' && mechanic.actionKind !== undefined ? [mechanic.actionKind]
291
- : mechanic.kind === 'gate' ? (mechanic.blockedActionKinds ?? []).filter(actionKind => !ENGINE_ACTION_KINDS.has(actionKind)) : [])))].sort();
327
+ const actionKinds = input.ruleActionKinds ?? ruleActionKinds(kinds);
292
328
  const arms = flatEffectArms
293
329
  .filter(arm => (objectIds.length > 0 || carriable.length > 0 || arm.properties.kind.const !== 'object.update')
294
330
  && (takeIds.length > 0 || arm.properties.kind.const !== 'take')
@@ -296,7 +332,8 @@ export function scopedAttemptResponseSchema(input) {
296
332
  && (scene.entities.length > 0 || !['property.set', 'relation.set'].includes(arm.properties.kind.const))
297
333
  && (tensionIds.length > 0 || arm.properties.kind.const !== 'tension.update')
298
334
  && (actor !== undefined && localPeople.size > 1 || arm.properties.kind.const !== 'request.open')
299
- && (voteIds.length > 0 || arm.properties.kind.const !== 'ballot')
335
+ && (scene.entities.some(entity => (kinds.find(kind => kind.id === entity.kindId)?.properties ?? []).some(property => property.type === 'series'))
336
+ || arm.properties.kind.const !== 'cell.add')
300
337
  // A happening removes no one from the story; people leave by their own decisions.
301
338
  && (input.phase !== 'world' || arm.properties.kind.const !== 'person.leave'))
302
339
  .flatMap(arm => {
@@ -310,10 +347,10 @@ export function scopedAttemptResponseSchema(input) {
310
347
  const listed = new Set(world.people.map(person => person.id));
311
348
  const movers = [...world.people.filter(person => !person.isPlayer || person.id === actor?.id),
312
349
  ...reactorIds.filter(id => !listed.has(id)).map(id => ({ id, placeId: scene.id }))];
313
- const origins = [...new Set(movers.map(person => person.placeId))].sort();
350
+ const origins = [...new Set(movers.map(person => person.placeId))];
314
351
  return origins.flatMap(origin => {
315
- const destinations = [...new Set(world.places.find(place => place.id === origin)?.connections ?? [])].filter(id => id !== origin).sort();
316
- const walkers = movers.filter(person => person.placeId === origin).map(person => person.id).sort();
352
+ const destinations = [...new Set(world.places.find(place => place.id === origin)?.connections ?? [])].filter(id => id !== origin);
353
+ const walkers = movers.filter(person => person.placeId === origin).map(person => person.id);
317
354
  if (walkers.length === 0)
318
355
  return [];
319
356
  return destinations.length > 0 ? [{ ...arm, properties: { ...arm.properties,
@@ -322,9 +359,13 @@ export function scopedAttemptResponseSchema(input) {
322
359
  });
323
360
  }
324
361
  if (kind === 'take') {
325
- const holders = [...new Set(takeIds.map(id => reachable.find(object => object.id === id).holderId))];
362
+ const holderOf = (id) => {
363
+ const containerId = reachable.find(object => object.id === id).containerId;
364
+ return containerId !== null && localPeople.has(containerId) ? containerId : null;
365
+ };
366
+ const holders = [...new Set(takeIds.map(holderOf))];
326
367
  return holders.flatMap(holder => {
327
- const things = takeIds.filter(id => reachable.find(object => object.id === id).holderId === holder);
368
+ const things = takeIds.filter(id => holderOf(id) === holder);
328
369
  const takers = [...localPeople].filter(id => id !== holder).sort();
329
370
  return takers.length > 0 ? [{ ...arm, properties: { ...arm.properties,
330
371
  objectId: described(things.length === 1 ? { const: things[0] } : { type: 'string', enum: things }, effectFields.objectId.description),
@@ -332,71 +373,80 @@ export function scopedAttemptResponseSchema(input) {
332
373
  } }] : [];
333
374
  });
334
375
  }
376
+ if (kind === 'cell.add')
377
+ return kinds.flatMap(definition => {
378
+ const series = definition.properties.filter(property => property.type === 'series');
379
+ const entityIds = scene.entities.filter(entity => entity.kindId === definition.id).map(entity => entity.id);
380
+ if (entityIds.length === 0 || series.length === 0)
381
+ return [];
382
+ return series.flatMap(slot => [{ ...arm, properties: { ...arm.properties,
383
+ entityId: described({ type: 'string', enum: entityIds }, effectFields.entityId.description),
384
+ slotId: described({ const: slot.id }, effectFields.slotId.description),
385
+ option: described(slot.options === undefined ? { type: 'string', pattern: '^[a-z0-9][a-z0-9-]{0,63}$' } : { type: 'string', enum: [...slot.options] }, slot.options === undefined ? `${effectFields.option.description} A short lowercase token of letters, digits and hyphens.` : effectFields.option.description),
386
+ personId: described({ type: 'string', enum: [...localPeople] }, effectFields.personId.description),
387
+ } }]);
388
+ });
335
389
  const fields = {};
336
390
  if (kind === 'entity.create')
337
391
  return kinds.map(definition => ({ ...arm,
338
392
  required: arm.required,
339
393
  properties: { ...arm.properties,
340
394
  // A fire, a flood or a sound stays where it is, and an injury or a debt belongs to no hand.
341
- ...(neverHeld(LIVING_ENGINE_VERSION, definition.id, definition) ? { personId: described({ type: 'null' }, 'No one holds this kind of thing.') } : {}),
395
+ ...(neverHeld(definition) ? { personId: described({ type: 'null' }, 'No one holds this kind of thing.') } : {}),
342
396
  kindId: described({ const: definition.id }, effectFields.kindId.description),
343
397
  placeId: described({ enum: [scene.id, null] }, 'Place where the new thing is; null when it belongs to no place, such as an agreement, a debt, a right, or a rumor.'),
344
398
  initialProperties: described({ type: 'object', additionalProperties: false,
345
- required: definition.properties.filter(property => property.requiredOnCreate).map(property => property.id),
346
- properties: Object.fromEntries(definition.properties.map(property => [property.id,
399
+ required: definition.properties.filter(property => property.requiredOnCreate && property.type !== 'series' && property.perActor !== true).map(property => property.id),
400
+ properties: Object.fromEntries(definition.properties.filter(property => property.type !== 'series' && property.perActor !== true).map(property => [property.id,
347
401
  property.type === 'flag' ? { type: 'boolean' }
348
402
  : property.type === 'number' ? { type: 'number' }
349
403
  : property.type === 'time' ? { type: 'integer', minimum: 0, description: 'Minutes since Day 1, 00:00; now is clockMinutes.' }
350
404
  : property.type === 'level' ? { type: 'string', enum: ['none', 'low', 'medium', 'high'] }
351
405
  : property.type === 'id' ? { type: 'string', maxLength: 64, description: 'Id of a person, place or thing in the input.' }
352
- : str(2000)])) }, 'Values written when this entity is created. Include every required property.'), },
406
+ : str(300)])) }, 'Values written when this entity is created. Include every required property.'), },
353
407
  }));
354
408
  // One option for each kind here: its things, its properties, and values of its properties' types
355
409
  // only, with an id naming a person or a place.
356
410
  const addsLine = input.textWrites === 'add';
357
411
  if (kind === 'property.set')
358
412
  return kinds.flatMap(definition => {
359
- const entityIds = scene.entities.filter(entity => entity.kindId === definition.id).map(entity => entity.id).sort();
360
- const types = [...new Set(definition.properties.map(property => property.type))].sort();
413
+ const entityIds = scene.entities.filter(entity => entity.kindId === definition.id).map(entity => entity.id);
414
+ const writable = definition.properties.filter(property => property.type !== 'series' && property.perActor !== true);
415
+ const types = [...new Set(writable.map(property => property.type))];
361
416
  if (entityIds.length === 0 || types.length === 0)
362
417
  return [];
363
418
  return [{ ...arm, properties: { ...arm.properties,
364
419
  ...(addsLine ? { kind: { const: kind, description: ADDED_LINE_MEANING } } : {}),
365
420
  entityId: described({ type: 'string', enum: entityIds }, effectFields.entityId.description),
366
- propertyId: described({ type: 'string', enum: definition.properties.map(property => property.id).sort() }, effectFields.propertyId.description),
421
+ propertyId: described({ type: 'string', enum: writable.map(property => property.id) }, effectFields.propertyId.description),
367
422
  value: described({ anyOf: [...types.map(type => type === 'text' ? (addsLine ? described(str(MAX_ADDED_LINE), 'Only the words written now; what is written stays.')
368
- : described(str(2000), 'The whole text as it now reads, with the change.')) : typedValue(type)), { type: 'null' }] }, effectFields.value.description) } }];
423
+ : described(str(300), 'The whole text as it now reads, with the change.')) : typedValue(type)), { type: 'null' }] }, effectFields.value.description) } }];
369
424
  });
370
425
  // Likewise one link option for each kind here that has links: its things and its own relations only.
371
426
  if (kind === 'relation.set')
372
427
  return kinds.flatMap(definition => {
373
- const entityIds = scene.entities.filter(entity => entity.kindId === definition.id).map(entity => entity.id).sort();
428
+ const entityIds = scene.entities.filter(entity => entity.kindId === definition.id).map(entity => entity.id);
374
429
  if (entityIds.length === 0 || definition.relations.length === 0)
375
430
  return [];
376
431
  return [{ ...arm, properties: { ...arm.properties,
377
432
  entityId: described({ type: 'string', enum: entityIds }, effectFields.entityId.description),
378
- relationId: described({ type: 'string', enum: definition.relations.map(relation => relation.id).sort() }, effectFields.relationId.description) } }];
433
+ relationId: described({ type: 'string', enum: definition.relations.map(relation => relation.id) }, effectFields.relationId.description) } }];
379
434
  });
380
435
  if (kind === 'request.open') {
381
436
  fields.personId = described({ const: actor.id }, 'Actor who makes the request.');
382
- fields.targetId = described({ type: 'string', enum: [...localPeople].filter(id => id !== actor.id).sort() }, 'Person here who receives the request.');
437
+ fields.targetId = described({ type: 'string', enum: [...localPeople].filter(id => id !== actor.id) }, 'Person here who receives the request.');
383
438
  fields.priorId = described(requests.length > 0
384
- ? nullable({ type: 'string', enum: requests.map(request => request.id).sort() }) : { type: 'null' }, effectFields.priorId.description);
385
- }
386
- if (kind === 'ballot') {
387
- fields.personId = described({ const: actor.id }, 'The actor, who casts their own vote.');
388
- fields.entityId = described({ type: 'string', enum: voteIds }, 'Decision voted on.');
389
- fields.choice = described({ type: 'string', enum: ['yes', 'no', 'abstain'] }, effectFields.choice.description);
439
+ ? nullable({ type: 'string', enum: requests.map(request => request.id) }) : { type: 'null' }, effectFields.priorId.description);
390
440
  }
391
441
  if (kind === 'schedule')
392
442
  fields.personId = described({ type: 'null' }, effectFields.personId.description);
393
- if (fieldsByEffect[kind].includes('personId') && !['person.create', 'schedule', 'request.open', 'ballot'].includes(kind))
443
+ if (fieldsByEffect[kind].includes('personId') && !['person.create', 'schedule', 'request.open'].includes(kind))
394
444
  fields.personId = idField(personIds, 'personId', kind === 'object.update');
395
445
  // A happening sends away only someone it brings in, heard on a call; the rest leave by their own decisions.
396
- if (kind === 'person.away' && input.phase === 'world')
446
+ if (kind === 'person.offstage' && input.phase === 'world')
397
447
  fields.personId = described(str(64), 'Someone this ruling brings in who is only on a call.');
398
448
  if (['take', 'drop', 'object.update'].includes(kind))
399
- fields.objectId = idField(kind === 'object.update' ? [...new Set([...objectIds, ...carriable.map(thing => thing.id)])].sort() : kind === 'drop' ? heldObjectIds : takeIds, 'objectId');
449
+ fields.objectId = idField(kind === 'object.update' ? [...new Set([...objectIds, ...carriable.map(thing => thing.id)])] : kind === 'drop' ? heldObjectIds : takeIds, 'objectId');
400
450
  if (fieldsByEffect[kind].includes('placeId') && kind !== 'place.create')
401
451
  fields.placeId = idField(placeIds, 'placeId', !['move', 'drop', 'person.create'].includes(kind));
402
452
  if (kind === 'tension.update')
@@ -408,36 +458,55 @@ export function scopedAttemptResponseSchema(input) {
408
458
  if (kind === 'message')
409
459
  fields.sourcePersonId = idField(personIds, 'sourcePersonId', true);
410
460
  if (kind === 'tension.create')
411
- fields.participantIds = described({ type: 'array', items: { type: 'string', enum: personIds }, maxItems: 6 }, effectFields.participantIds.description);
461
+ fields.participantIds = described({ type: 'array', items: { type: 'string', enum: personIds }, maxItems: 4 }, effectFields.participantIds.description);
412
462
  return [{ ...arm, properties: { ...arm.properties, ...fields } }];
413
463
  });
414
- return { ...attemptResponseSchema, properties: { ...attemptResponseSchema.properties,
464
+ const responseFields = attemptResponseSchema.properties;
465
+ const stateNotedField = responseFields.stateNoted;
466
+ return { ...attemptResponseSchema, ...(input.phase === 'world' && input.chain !== undefined ? { required: [...attemptResponseSchema.required, 'chainContinues'] } : {}), properties: { ...responseFields,
415
467
  actionKind: described(actionKinds.length > 0 ? nullable({ type: 'string', enum: actionKinds }) : { type: 'null' }, attemptResponseSchema.properties.actionKind.description),
416
- stateUpdates: described({ type: 'array', items: { anyOf: arms.map(kindFirst('values')) }, maxItems: 8 }, attemptResponseSchema.properties.stateUpdates.description),
417
- perceivedBy: described({ type: 'array', items: perceiverIds.length > 0 ? { type: 'string', enum: perceiverIds } : str(64), maxItems: Math.min(32, perceiverIds.length) }, attemptResponseSchema.properties.perceivedBy.description),
468
+ stateUpdates: described({ type: 'array', items: { anyOf: arms.map(kindFirst('values')) }, maxItems: 5 }, attemptResponseSchema.properties.stateUpdates.description),
469
+ perceivedBy: described({ type: 'array', items: perceiverIds.length > 0 ? { type: 'string', enum: perceiverIds } : str(64), maxItems: Math.min(6, perceiverIds.length) }, attemptResponseSchema.properties.perceivedBy.description),
418
470
  reactorIds: described({ type: 'array', items: reactorIds.length > 0 ? { type: 'string', enum: reactorIds } : str(64), maxItems: Math.min(2, reactorIds.length) }, attemptResponseSchema.properties.reactorIds.description),
419
- visibleObjectIds: described({ type: 'array', items: localObjectIds.length > 0 ? { type: 'string', enum: localObjectIds } : str(64), maxItems: Math.min(48, localObjectIds.length) }, attemptResponseSchema.properties.visibleObjectIds.description),
420
- visibleTensionIds: described({ type: 'array', items: visibleTensionIds.length > 0 ? { type: 'string', enum: visibleTensionIds } : str(64), maxItems: Math.min(32, visibleTensionIds.length) }, attemptResponseSchema.properties.visibleTensionIds.description),
471
+ visibleObjectIds: described({ type: 'array', items: localObjectIds.length > 0 ? { type: 'string', enum: localObjectIds } : str(64), maxItems: Math.min(6, localObjectIds.length) }, attemptResponseSchema.properties.visibleObjectIds.description),
472
+ visibleTensionIds: described({ type: 'array', items: visibleTensionIds.length > 0 ? { type: 'string', enum: visibleTensionIds } : str(64), maxItems: Math.min(6, visibleTensionIds.length) }, attemptResponseSchema.properties.visibleTensionIds.description),
421
473
  settledTensionId: described(tensionIds.length > 0 ? nullable({ type: 'string', enum: tensionIds }) : { type: 'null' }, attemptResponseSchema.properties.settledTensionId.description),
422
- } };
474
+ contactIds: described(elsewhereIds.length > 0 ? { type: 'array', items: { type: 'string', enum: elsewhereIds }, maxItems: Math.min(4, elsewhereIds.length) } : { type: 'array', maxItems: 0 }, attemptResponseSchema.properties.contactIds.description),
475
+ signalChannel: described(channelIds.length > 0 ? nullable({ type: 'string', enum: channelIds }) : { type: 'null' }, signalChannelField.description),
476
+ stateNoted: described({ type: 'array', items: { type: 'object', additionalProperties: false, required: ['facet', 'text', 'kindId'], properties: {
477
+ facet: described(str(64), phrase('prompt.facetReuse')),
478
+ text: str(200),
479
+ kindId: described(kindIds.length > 0 ? nullable({ type: 'string', enum: kindIds }) : { type: 'null' }, phrase('prompt.facetKind')),
480
+ } }, maxItems: 3 }, stateNotedField.description),
481
+ ...(input.phase === 'world' && input.chain !== undefined ? { chainContinues: described({ type: 'boolean' }, 'Whether this happening\'s chain goes on: true to let what follows continue it, false to end it here.') } : {}), } };
482
+ }
483
+ export function ruleActionKinds(kinds) {
484
+ return [...new Set(kinds.flatMap(kind => (kind.laws ?? []).flatMap(law => {
485
+ const attemptedValue = law.on.attempted;
486
+ const attempted = attemptedValue === undefined ? [] : typeof attemptedValue === 'string' ? [attemptedValue] : [...attemptedValue];
487
+ return attempted.filter(actionKind => law.kind === 'react' && (law.do ?? []).some(action => action.op === 'violation')
488
+ || law.kind === 'forbid' && !ENGINE_ACTION_KINDS.has(actionKind));
489
+ })))];
423
490
  }
424
491
  // An activity: its private purpose, what anyone watching sees, where and with whom, and how long it lasts.
425
492
  // Round 9: named "doing", the outward view drew the person's aim in 9 of 60 answers; "seenDoing" drew none.
426
493
  const ACTIVITY = { type: 'object', additionalProperties: false, required: ['intent', 'seenDoing', 'placeId', 'targetId', 'inMinutes'], properties: {
427
- intent: described(str(300), 'Your private purpose.'), seenDoing: described({ ...str(200), minLength: 3 }, 'What anyone watching sees you doing.'),
494
+ intent: described(str(200), 'Your private purpose.'), seenDoing: described({ ...str(120), minLength: 3 }, 'What anyone watching sees you doing.'),
428
495
  placeId: nullable(str(64)), targetId: nullable(str(64)), inMinutes: described({ type: 'integer', minimum: 1, maximum: 100_000 }, 'Minutes it really takes, often 30 to 120. Replies and anything you notice reach you during it.')
429
496
  } };
430
497
  export const reactionResponseSchema = {
431
498
  type: 'object',
432
499
  additionalProperties: false,
433
- required: ['say', 'act', 'toIds', 'mood', 'weight', 'leaveToPlaceId', 'trust', 'warmth', 'relationshipNote', 'belief', 'commitment', 'newGoal', 'goalDone', 'plan', 'tell', 'suggestedReplies', 'endConversation', 'request', 'requestDecision', 'answered', 'stance'],
500
+ required: ['say', 'act', 'toIds', 'mood', 'weight', 'leaveToPlaceId', 'trust', 'warmth', 'relationshipNote', 'belief', 'commitment', 'newGoal', 'goalDone', 'plan', 'tell', 'suggestedReplies', 'endConversation', 'request', 'requestDecision', 'commitmentDecision', 'answered', 'stance'],
434
501
  properties: {
435
502
  say: described(nullable(str(MAX_SPOKEN)), 'Your words to people here; null for silence.'),
436
503
  request: described(nullable({ type: 'object', additionalProperties: false,
437
504
  required: ['topic', 'receiverId', 'priorId'],
438
- properties: { topic: str(600), receiverId: str(64), priorId: nullable(str(64)) } }), 'A concrete ask of someone in this line, with priorId when it repeats a known request; else null.'),
505
+ properties: { topic: str(300), receiverId: str(64), priorId: nullable(str(64)) } }), 'A concrete ask of someone in this line, with priorId when it repeats a known request; else null.'),
439
506
  requestDecision: described(nullable({ type: 'object', additionalProperties: false, required: ['id', 'status'],
440
- properties: { id: str(64), status: { type: 'string', enum: ['answered', 'refused', 'done'] } } }), 'Your answer to an open request to you; else null.'),
507
+ properties: { id: str(64), status: { type: 'string', enum: ['accepted', 'refused', 'done'] } } }), 'Your answer to an open request; else null.'),
508
+ commitmentDecision: described(nullable({ type: 'object', additionalProperties: false, required: ['id', 'status'],
509
+ properties: { id: str(64), status: { type: 'string', enum: ['kept', 'broken'] } } }), 'Your decision on a due promise; else null.'),
441
510
  answered: described(nullable(str(64)), 'Id of your own open request these words answer; else null.'),
442
511
  act: described(nullable(str(200)), 'One physical act you try now; null if you only speak.'),
443
512
  toIds: described(ids(4), 'People here you address.'),
@@ -447,37 +516,44 @@ export const reactionResponseSchema = {
447
516
  leaveToPlaceId: described(nullable(str(64)), 'Exit you take now; else null.'),
448
517
  trust: described({ type: 'integer', minimum: -20, maximum: 20 }, 'Change in your trust of the actor.'),
449
518
  warmth: described({ type: 'integer', minimum: -20, maximum: 20 }, 'Change in your warmth toward the actor.'),
450
- relationshipNote: described(nullable(str(200)), 'Why your feelings changed; else null.'),
451
- belief: described(nullable({ type: 'object', additionalProperties: false, required: ['subject', 'claim'], properties: { subject: str(120), claim: str(300) } }), 'A conclusion you now hold; else null.'),
452
- commitment: described(nullable({ type: 'object', additionalProperties: false, required: ['toId', 'text', 'dueInMinutes', 'placeId'], properties: { toId: str(64), text: str(300), dueInMinutes: nullable({ type: 'integer', minimum: 0, maximum: 100_000 }),
519
+ relationshipNote: described(nullable(str(120)), 'Why your feelings changed; else null.'),
520
+ belief: described(nullable({ type: 'object', additionalProperties: false, required: ['subject', 'claim'], properties: { subject: str(80), claim: str(200) } }), 'A conclusion you now hold; else null.'),
521
+ commitment: described(nullable({ type: 'object', additionalProperties: false, required: ['toId', 'text', 'dueInMinutes', 'placeId'], properties: { toId: str(64), text: str(200), dueInMinutes: nullable({ type: 'integer', minimum: 0, maximum: 100_000 }),
453
522
  placeId: described(nullable(str(64)), 'Where you promised to be, when you promised to be somewhere; else null.') } }), 'A promise you make; else null.'),
454
- newGoal: described(nullable(str(300)), 'A new aim; else null.'),
455
- goalDone: described(nullable(str(300)), 'Id of your goal now resolved; else null.'),
523
+ newGoal: described(nullable(str(200)), 'A new aim; else null.'),
524
+ goalDone: described(nullable(str(200)), 'Id of your goal now resolved; else null.'),
456
525
  plan: described(nullable(ACTIVITY), 'A new activity you switch to now; null to carry on.'),
457
- tell: described(nullable({ type: 'object', additionalProperties: false, required: ['targetId', 'text'], properties: { targetId: str(64), text: str(300) } }), 'Someone to inform and what to tell them; else null.'),
526
+ tell: described(nullable({ type: 'object', additionalProperties: false, required: ['targetId', 'text'], properties: { targetId: str(64), text: str(200) } }), 'Someone to inform and what to tell them; else null.'),
458
527
  suggestedReplies: described({ type: 'array', items: str(120), maxItems: 3 }, 'Lines the player might say next, in the player\'s voice.'),
459
528
  endConversation: described({ type: 'boolean' }, 'Whether you end this exchange.'),
460
529
  },
461
530
  };
462
531
  // The engine's own action kinds, which gates block outside any ruling.
463
532
  export const ENGINE_ACTION_KINDS = new Set(['move', 'speak', 'message', 'act', 'incapacitate']);
464
- export function scopedReactionResponseSchema(input) {
533
+ export function scopedReactionResponseSchema(input, engine = LIVING_ENGINE_VERSION) {
465
534
  const identity = input.identity;
466
535
  const blocked = new Set(identity.blocked ?? []);
467
536
  const requests = input.requests;
468
- const openIds = requests.filter(request => request.toId === identity.id && request.status === 'open').map(request => request.id).sort();
537
+ const openIds = requests.filter(request => request.toId === identity.id && request.status === 'open').map(request => request.id);
538
+ const commitments = input.commitments ?? [];
539
+ const commitmentIds = commitments.map(commitment => commitment.id);
540
+ const decisionStatuses = (['accepted', 'refused', 'done']);
469
541
  // Only the person spoken to can answer what this person asked them.
470
542
  const speakerId = input.happened?.byId ?? null;
471
543
  const askedIds = requests.filter(request => request.fromId === identity.id && request.toId === speakerId && request.status === 'open')
472
- .map(request => request.id).sort();
473
- const goalIds = [...new Set((input.goals ?? []).map(goal => goal.id))].sort();
544
+ .map(request => request.id);
545
+ const goalIds = [...new Set((input.goals ?? []).map(goal => goal.id))];
474
546
  // People here may be addressed, except someone who has left this person's last lines unanswered.
475
547
  const addressable = directoryPeople(input).filter(person => person.here === true && person.id !== identity.id && person.noAnswerSince === undefined)
476
- .map(person => person.id).sort();
477
- return withBallot({ ...reactionResponseSchema, properties: { ...reactionResponseSchema.properties,
548
+ .map(person => person.id);
549
+ return withChoice({ ...reactionResponseSchema, properties: { ...reactionResponseSchema.properties,
550
+ waitingOnIds: described(ids(4), phrase('schema.description.waitingOnIds')),
478
551
  requestDecision: described(openIds.length > 0 ? nullable({ type: 'object', additionalProperties: false,
479
552
  required: ['id', 'status'], properties: { id: { type: 'string', enum: openIds },
480
- status: { type: 'string', enum: ['answered', 'refused', 'done'] } } }) : { type: 'null' }, reactionResponseSchema.properties.requestDecision.description),
553
+ status: { type: 'string', enum: decisionStatuses } } }) : { type: 'null' }, reactionResponseSchema.properties.requestDecision.description),
554
+ commitmentDecision: described(commitmentIds.length > 0 ? nullable({ type: 'object', additionalProperties: false,
555
+ required: ['id', 'status'], properties: { id: { type: 'string', enum: commitmentIds },
556
+ status: { type: 'string', enum: ['kept', 'broken'] } } }) : { type: 'null' }, reactionResponseSchema.properties.commitmentDecision.description),
481
557
  answered: described(askedIds.length > 0 ? nullable({ type: 'string', enum: askedIds }) : { type: 'null' }, reactionResponseSchema.properties.answered.description),
482
558
  goalDone: described(goalIds.length > 0 ? nullable({ type: 'string', enum: goalIds }) : { type: 'null' }, reactionResponseSchema.properties.goalDone.description),
483
559
  toIds: described(addressable.length > 0 ? { type: 'array', items: { type: 'string', enum: addressable }, maxItems: Math.min(4, addressable.length) } : { type: 'array', maxItems: 0 }, reactionResponseSchema.properties.toIds.description),
@@ -486,29 +562,49 @@ export function scopedReactionResponseSchema(input) {
486
562
  ...(blocked.has('act') ? { act: described({ type: 'null' }, reactionResponseSchema.properties.act.description) } : {}),
487
563
  } }, input);
488
564
  }
489
- // Someone with a vote open to them may cast it in this answer; anyone else is offered no ballot at all.
490
- // On their own turn to vote they must cast it; abstaining is a choice.
491
- function withBallot(schema, input, turn = false) {
492
- const voteIds = (input.votes ?? []).map(vote => vote.id).sort();
493
- if (voteIds.length === 0)
565
+ function withChoice(schema, input, turn = false) {
566
+ const choices = input.choices ?? [];
567
+ if (choices.length === 0)
494
568
  return schema;
495
- const cast = { type: 'object', additionalProperties: false, required: ['decisionId', 'choice'], properties: {
496
- decisionId: { type: 'string', enum: voteIds }, choice: { type: 'string', enum: ['yes', 'no', 'abstain'] }
569
+ const choose = { type: 'object', additionalProperties: false, required: ['entityId', 'slotId', 'option'], properties: {
570
+ entityId: { type: 'string', enum: choices.map(choice => choice.id) },
571
+ slotId: { type: 'string', enum: [...new Set(choices.map(choice => choice.slotId))] },
572
+ option: { type: 'string', enum: [...new Set(choices.flatMap(choice => choice.options))] }
497
573
  } };
498
- return { ...schema, required: [...schema.required, 'ballot'], properties: { ...schema.properties,
499
- ballot: turn ? described(cast, 'Your own vote on the open decision, cast now.') : described(nullable(cast), 'Your own vote on an open decision, cast now; else null.') } };
574
+ return { ...schema, required: [...schema.required, 'choose'], properties: { ...schema.properties,
575
+ choose: turn ? described(choose, 'Your own choice, made now.') : described(nullable(choose), 'Your own choice, made now; else null.') } };
500
576
  }
501
- const PLAN_ACTION_GATES = { go: 'move', 'go-home': 'move', speak: 'speak', message: 'message', attempt: 'act' };
577
+ const PLAN_ACTION_GATES = { go: 'move', speak: 'speak', message: 'message', attempt: 'act' };
502
578
  const directoryPeople = (input) => (input.directory?.people ?? []);
503
- export function scopedPlanResponseSchema(input) {
579
+ export function scopedPlanResponseSchema(input, engine = LIVING_ENGINE_VERSION, restAction = null) {
504
580
  const identity = input.identity;
505
581
  const blocked = new Set(identity.blocked ?? []);
506
- const actions = PLAN_ACTIONS.filter(action => !blocked.has(PLAN_ACTION_GATES[action] ?? ''));
582
+ const actions = [...PLAN_ACTIONS.filter(action => action !== 'wait'), ...(restAction === null ? [] : [restAction]), 'wait']
583
+ .filter(action => !blocked.has(PLAN_ACTION_GATES[action] ?? (action === restAction ? 'move' : '')));
507
584
  // Anyone known may be sought out, except someone who has left this person's last lines unanswered.
508
- const targets = directoryPeople(input).filter(person => person.id !== identity.id && person.noAnswerSince === undefined).map(person => person.id).sort();
509
- return withBallot({ ...planResponseSchema, properties: { ...planResponseSchema.properties,
585
+ const targets = directoryPeople(input).filter(person => person.id !== identity.id && person.noAnswerSince === undefined).map(person => person.id);
586
+ const requests = input.requests ?? [];
587
+ const openIds = requests.filter(request => request.toId === identity.id && request.status === 'open').map(request => request.id);
588
+ const commitments = input.commitments ?? [];
589
+ const commitmentIds = commitments.map(commitment => commitment.id);
590
+ const decision = input.decision;
591
+ const decisionStatuses = (['accepted', 'refused', 'done']);
592
+ const schema = withChoice({ ...planResponseSchema, properties: { ...planResponseSchema.properties,
510
593
  action: described({ type: 'string', enum: actions }, planResponseSchema.properties.action.description),
511
- targetId: described(targets.length > 0 ? nullable({ type: 'string', enum: targets }) : { type: 'null' }, planResponseSchema.properties.targetId.description) } }, input, true);
594
+ targetId: described(targets.length > 0 ? nullable({ type: 'string', enum: targets }) : { type: 'null' }, planResponseSchema.properties.targetId.description),
595
+ requestDecision: described(openIds.length > 0 ? nullable({ type: 'object', additionalProperties: false,
596
+ required: ['id', 'status'], properties: { id: { type: 'string', enum: openIds }, status: { type: 'string', enum: decisionStatuses } } }) : { type: 'null' }, planResponseSchema.properties.requestDecision.description),
597
+ commitmentDecision: described(commitmentIds.length > 0 ? nullable({ type: 'object', additionalProperties: false,
598
+ required: ['id', 'status'], properties: { id: { type: 'string', enum: commitmentIds }, status: { type: 'string', enum: ['kept', 'broken'] } } }) : { type: 'null' }, planResponseSchema.properties.commitmentDecision.description) } }, input, true);
599
+ if (decision?.kind === 'ask')
600
+ return { ...schema, required: [...schema.required, 'requestDecision'],
601
+ properties: { ...schema.properties, requestDecision: described({ type: 'object', additionalProperties: false,
602
+ required: ['id', 'status'], properties: { id: { type: 'string', enum: [decision.id] }, status: { type: 'string', enum: decisionStatuses } } }, planResponseSchema.properties.requestDecision.description) } };
603
+ if (decision?.kind === 'promise')
604
+ return { ...schema, required: [...schema.required, 'commitmentDecision'],
605
+ properties: { ...schema.properties, commitmentDecision: described({ type: 'object', additionalProperties: false,
606
+ required: ['id', 'status'], properties: { id: { type: 'string', enum: [decision.id] }, status: { type: 'string', enum: ['kept', 'broken'] } } }, planResponseSchema.properties.commitmentDecision.description) } };
607
+ return schema;
512
608
  }
513
609
  export const speechImpactResponseSchema = {
514
610
  type: 'object',
@@ -522,28 +618,44 @@ export const speechImpactResponseSchema = {
522
618
  dueInMinutes: described(nullable({ type: 'integer', minimum: 0, maximum: 100_000 }), 'When a promise falls due, in minutes from now; else null.')
523
619
  } }), 'What the line presses on listeners; else null.'),
524
620
  loud: described({ type: 'boolean' }, 'True only if shouted, loud enough to carry next door.'),
525
- addressedIds: described({ type: 'array', items: str(64), maxItems: 4 }, 'People these words are for; empty for the room.'),
621
+ addressedIds: described({ type: 'array', items: str(64), maxItems: 4 }, 'People spoken to; empty for the room.'),
622
+ mentionedIds: described({ type: 'array', items: str(64), maxItems: 4 }, 'People talked about.'),
526
623
  aboutIds: described({ type: 'array', items: str(64), maxItems: 4 }, 'Things here the words are about.'),
624
+ act: described(nullable({ type: 'object', additionalProperties: false, required: ['kind', 'entityId', 'targetId'], properties: {
625
+ kind: { type: 'string', enum: ['sign', 'initial', 'witness', 'approve', 'seal', 'hand'] },
626
+ entityId: str(64),
627
+ targetId: nullable(str(64))
628
+ } }), 'The speaker\'s own act.'),
527
629
  },
528
630
  };
529
631
  // A line may be for someone present or someone known elsewhere.
530
632
  export function scopedSpeechImpactResponseSchema(presentIds, thingIds = []) {
531
633
  return { ...speechImpactResponseSchema, properties: { ...speechImpactResponseSchema.properties,
532
- addressedIds: described({ type: 'array', items: presentIds.length > 0 ? { type: 'string', enum: [...presentIds].sort() } : str(64), maxItems: Math.min(4, presentIds.length) }, speechImpactResponseSchema.properties.addressedIds.description),
533
- aboutIds: described({ type: 'array', items: thingIds.length > 0 ? { type: 'string', enum: [...thingIds].sort() } : str(64), maxItems: Math.min(4, thingIds.length) }, speechImpactResponseSchema.properties.aboutIds.description) } };
634
+ addressedIds: described({ type: 'array', items: presentIds.length > 0 ? { type: 'string', enum: [...presentIds] } : str(64), maxItems: Math.min(4, presentIds.length) }, speechImpactResponseSchema.properties.addressedIds.description),
635
+ mentionedIds: described({ type: 'array', items: presentIds.length > 0 ? { type: 'string', enum: [...presentIds] } : str(64), maxItems: Math.min(4, presentIds.length) }, speechImpactResponseSchema.properties.mentionedIds.description),
636
+ aboutIds: described({ type: 'array', items: thingIds.length > 0 ? { type: 'string', enum: [...thingIds] } : str(64), maxItems: Math.min(4, thingIds.length) }, speechImpactResponseSchema.properties.aboutIds.description),
637
+ act: described(nullable({ type: 'object', additionalProperties: false, required: ['kind', 'entityId', 'targetId'], properties: {
638
+ kind: { type: 'string', enum: ['sign', 'initial', 'witness', 'approve', 'seal', 'hand'] },
639
+ entityId: thingIds.length > 0 ? { type: 'string', enum: [...thingIds] } : str(64),
640
+ targetId: presentIds.length > 0 ? nullable({ type: 'string', enum: [...presentIds] }) : nullable(str(64))
641
+ } }), speechImpactResponseSchema.properties.act.description) } };
534
642
  }
535
- const PLAN_ACTIONS = ['go', 'speak', 'message', 'attempt', 'go-home', 'wait'];
643
+ const PLAN_ACTIONS = ['go', 'speak', 'message', 'attempt', 'wait'];
536
644
  export const planResponseSchema = {
537
645
  type: 'object',
538
646
  additionalProperties: false,
539
- required: ['action', 'placeId', 'targetId', 'text', 'mood', 'nextPlan', 'request', 'stance'],
647
+ required: ['action', 'placeId', 'targetId', 'text', 'mood', 'nextPlan', 'request', 'requestDecision', 'commitmentDecision', 'stance'],
540
648
  properties: {
541
- action: described({ type: 'string', enum: [...PLAN_ACTIONS] }, 'One act now; go-home: away until nextPlan ends.'),
649
+ action: described({ type: 'string', enum: [...PLAN_ACTIONS] }, 'One act now; the world\'s rest action takes you offstage until nextPlan ends.'),
542
650
  placeId: described(nullable(str(64)), 'Destination for go; else null.'),
543
651
  targetId: described(nullable(str(64)), 'Person for speak or message; else null.'),
544
652
  text: described(nullable(str(MAX_SPOKEN)), 'Words to say or act to try; else null.'),
545
653
  request: described(nullable({ type: 'object', additionalProperties: false, required: ['topic', 'priorId'],
546
- properties: { topic: str(600), priorId: nullable(str(64)) } }), 'When your words ask someone to act: its topic, with priorId for a known request.'),
654
+ properties: { topic: str(300), priorId: nullable(str(64)) } }), 'When your words ask someone to act: its topic, with priorId for a known request.'),
655
+ requestDecision: described(nullable({ type: 'object', additionalProperties: false, required: ['id', 'status'],
656
+ properties: { id: str(64), status: { type: 'string', enum: ['accepted', 'refused', 'done'] } } }), 'Your answer to an open request to you; else null.'),
657
+ commitmentDecision: described(nullable({ type: 'object', additionalProperties: false, required: ['id', 'status'],
658
+ properties: { id: str(64), status: { type: 'string', enum: ['kept', 'broken'] } } }), 'Your decision on a promise of yours that has fallen due; else null.'),
547
659
  mood: described(str(40), 'Your feeling now in a few words.'),
548
660
  nextPlan: described(ACTIVITY, 'What you do next, until it ends.'),
549
661
  stance: described(nullable({ type: 'string', enum: ['undecided', 'cooperate', 'refuse', 'report', 'avoid', 'confront'] }), 'Where you now stand toward someone after their serious act; else null.'),
@@ -552,16 +664,33 @@ export const planResponseSchema = {
552
664
  export const messageReplyResponseSchema = {
553
665
  type: 'object',
554
666
  additionalProperties: false,
555
- required: ['reply', 'mood', 'trust', 'warmth', 'belief', 'plan'],
667
+ required: ['reply', 'mood', 'trust', 'warmth', 'belief', 'plan', 'requestDecision'],
556
668
  properties: {
557
669
  reply: described(nullable(str(MAX_SPOKEN)), 'Your reply; null for silence.'),
558
670
  mood: described(str(40), 'Your feeling now in a few words.'),
559
671
  trust: described({ type: 'integer', minimum: -20, maximum: 20 }, 'Change in trust of the sender.'),
560
672
  warmth: described({ type: 'integer', minimum: -20, maximum: 20 }, 'Change in warmth toward the sender.'),
561
- belief: described(nullable({ type: 'object', additionalProperties: false, required: ['subject', 'claim'], properties: { subject: str(120), claim: str(300) } }), 'A conclusion you now hold; else null.'),
673
+ belief: described(nullable({ type: 'object', additionalProperties: false, required: ['subject', 'claim'], properties: { subject: str(80), claim: str(200) } }), 'A conclusion you now hold; else null.'),
562
674
  plan: described(nullable(ACTIVITY), 'A new activity you switch to; null to carry on.'),
675
+ requestDecision: described(nullable({ type: 'object', additionalProperties: false, required: ['id', 'status'],
676
+ properties: { id: str(64), status: { type: 'string', enum: ['accepted', 'refused', 'done'] } } }), 'Your answer to an open request to you; else null.'),
563
677
  },
564
678
  };
679
+ export function scopedMessageReplyResponseSchema(input, engine = LIVING_ENGINE_VERSION) {
680
+ const identity = input.identity;
681
+ const requests = input.requests ?? [];
682
+ const openIds = requests.filter(request => request.toId === identity.id && request.status === 'open').map(request => request.id);
683
+ const decision = input.decision;
684
+ const decisionStatuses = (['accepted', 'refused', 'done']);
685
+ const schema = { ...messageReplyResponseSchema, properties: { ...messageReplyResponseSchema.properties,
686
+ requestDecision: described(openIds.length > 0 ? nullable({ type: 'object', additionalProperties: false,
687
+ required: ['id', 'status'], properties: { id: { type: 'string', enum: openIds }, status: { type: 'string', enum: decisionStatuses } } }) : { type: 'null' }, messageReplyResponseSchema.properties.requestDecision.description) } };
688
+ if (decision?.kind !== 'ask')
689
+ return schema;
690
+ return { ...schema, required: [...schema.required, 'requestDecision'],
691
+ properties: { ...schema.properties, requestDecision: described({ type: 'object', additionalProperties: false,
692
+ required: ['id', 'status'], properties: { id: { type: 'string', enum: [decision.id] }, status: { type: 'string', enum: decisionStatuses } } }, messageReplyResponseSchema.properties.requestDecision.description) } };
693
+ }
565
694
  export const epilogueResponseSchema = {
566
695
  type: 'object',
567
696
  additionalProperties: false,
@@ -569,8 +698,23 @@ export const epilogueResponseSchema = {
569
698
  properties: {
570
699
  title: described(str(120), 'Short title for the ending.'),
571
700
  verdict: described(str(300), 'One sentence on the outcome.'),
572
- highlights: described({ type: 'array', minItems: 1, maxItems: 5, items: str(240) }, 'Recorded major events in order.'),
573
- cast: described({ type: 'array', maxItems: 4, items: { type: 'object', additionalProperties: false, required: ['name', 'line'], properties: { name: str(120), line: str(200) } } }, 'Where up to four recorded people ended up.'),
701
+ highlights: described({ type: 'array', minItems: 1, maxItems: 4, items: str(200) }, 'Recorded major events in order.'),
702
+ cast: described({ type: 'array', maxItems: 3, items: { type: 'object', additionalProperties: false, required: ['name', 'line'], properties: { name: str(80), line: str(160) } } }, 'Where up to three recorded people ended up.'),
574
703
  closing: described(str(200), 'One final line grounded in the recorded outcome.'),
575
704
  },
576
705
  };
706
+ const DEFINER_CALL = { maxTokens: 700, timeoutMs: 45_000 };
707
+ export const LIVING_INFERENCE_LIMITS = Object.freeze({
708
+ attempt: { maxTokens: 1200, timeoutMs: 90_000 },
709
+ world: { maxTokens: 1200, timeoutMs: 90_000 },
710
+ 'speech-impact': { maxTokens: 200, timeoutMs: 20_000 },
711
+ reaction: { maxTokens: 500, timeoutMs: 45_000 },
712
+ reply: { maxTokens: 500, timeoutMs: 45_000 },
713
+ plan: { maxTokens: 500, timeoutMs: 30_000 },
714
+ 'message-reply': { maxTokens: 500, timeoutMs: 30_000 },
715
+ epilogue: { maxTokens: 900, timeoutMs: 45_000 },
716
+ define: DEFINER_CALL,
717
+ revise: DEFINER_CALL,
718
+ director: { maxTokens: 700, timeoutMs: 45_000 },
719
+ });
720
+ export const LIVING_ANSWER_BUDGET_MS = Math.min(LIVING_INFERENCE_LIMITS.reply.timeoutMs, LIVING_INFERENCE_LIMITS['message-reply'].timeoutMs);