@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
@@ -0,0 +1,275 @@
1
+ import EXAMPLE_SPEC_JSON from './prompts/example-spec.json' with { type: 'json' };
2
+ import ROLE_TEXT_JSON from './prompts/role-text.json' with { type: 'json' };
3
+ import { responseFieldLines } from './inference.js';
4
+ export const ROLE_IDS = ['game-master', 'speech-reading', 'character-reaction', 'character-plan', 'character-reply', 'director', 'definer', 'narrator', 'context-selection'];
5
+ const ROLE_TEXT = ROLE_TEXT_JSON;
6
+ const EXAMPLE_SPEC = EXAMPLE_SPEC_JSON;
7
+ export const WORLD_PRINCIPLES = ROLE_TEXT.principles;
8
+ export function roleText(id) {
9
+ const text = ROLE_TEXT.roles[id];
10
+ if (text === undefined)
11
+ throw new Error(`Unknown role ${id}`);
12
+ return text;
13
+ }
14
+ const FIELDS = {
15
+ id: 'id', name: 'name', title: 'title', world: 'world', meaning: 'meaning',
16
+ kindId: 'kindId', placeId: 'placeId', personId: 'personId', entityId: 'entityId', objectId: 'objectId', tensionId: 'tensionId',
17
+ slotId: 'slotId', option: 'option', channel: 'channel', unit: 'unit', slot: 'slot', targetId: 'targetId', toId: 'toId',
18
+ receiverId: 'receiverId', fromId: 'fromId', priorId: 'priorId', answered: 'answered', goalDone: 'goalDone',
19
+ leaveToPlaceId: 'leaveToPlaceId', propertyId: 'propertyId', relationId: 'relationId', sourcePersonId: 'sourcePersonId',
20
+ action: 'action', items: 'items', kind: 'kind', values: 'values', stateKindFit: 'stateKindFit', stateUpdates: 'stateUpdates', seenDoing: 'seenDoing',
21
+ };
22
+ const TYPES = { null: 'null', array: 'array', object: 'object', string: 'string', boolean: 'boolean', integer: 'integer', number: 'number',
23
+ complete: 'complete', wait: 'wait', attempt: 'attempt' };
24
+ const SLOT = { value: 'value', null: 'null', one: 'one', empty: 'empty' };
25
+ const KINDS = { entityCreate: 'entity.create', personCreate: 'person.create', placeCreate: 'place.create', tensionCreate: 'tension.create' };
26
+ const ROLES = { gameMaster: 'game-master' };
27
+ const NEWLINE = String.fromCharCode(10);
28
+ function isNameField(name) {
29
+ return name === FIELDS.name || name === FIELDS.title || name === FIELDS.world || name === FIELDS.meaning;
30
+ }
31
+ function isIdField(name) {
32
+ return name === FIELDS.id || name === FIELDS.kindId || name === FIELDS.placeId || name === FIELDS.personId || name === FIELDS.entityId
33
+ || name === FIELDS.objectId || name === FIELDS.tensionId || name === FIELDS.slotId || name === FIELDS.option || name === FIELDS.channel
34
+ || name === FIELDS.unit || name === FIELDS.slot || name === FIELDS.targetId || name === FIELDS.toId || name === FIELDS.receiverId
35
+ || name === FIELDS.fromId || name === FIELDS.priorId || name === FIELDS.answered || name === FIELDS.goalDone || name === FIELDS.leaveToPlaceId
36
+ || name === FIELDS.propertyId || name === FIELDS.relationId || name === FIELDS.sourcePersonId;
37
+ }
38
+ function isCreateKind(kind) {
39
+ return kind === KINDS.entityCreate || kind === KINDS.personCreate || kind === KINDS.placeCreate || kind === KINDS.tensionCreate;
40
+ }
41
+ function wordsOf(input) {
42
+ const names = [];
43
+ const ids = [];
44
+ const kinds = new Map();
45
+ const seen = new Set();
46
+ const add = (list, value) => {
47
+ if (value.length === 0 || seen.has(value))
48
+ return;
49
+ seen.add(value);
50
+ list.push(value);
51
+ };
52
+ const walk = (value, key) => {
53
+ if (typeof value === 'string') {
54
+ if (isNameField(key))
55
+ add(names, value);
56
+ else if (isIdField(key))
57
+ add(ids, value);
58
+ return;
59
+ }
60
+ if (Array.isArray(value)) {
61
+ for (const item of value)
62
+ walk(item, key);
63
+ return;
64
+ }
65
+ if (value !== null && typeof value === 'object') {
66
+ const record = value;
67
+ if (typeof record.id === 'string' && typeof record.name === 'string')
68
+ kinds.set(record.id, record.name);
69
+ for (const [name, child] of Object.entries(record))
70
+ walk(child, name);
71
+ }
72
+ };
73
+ walk(input, '');
74
+ return { names, ids, kinds };
75
+ }
76
+ function cut(text, max) {
77
+ if (max === undefined || text.length <= max)
78
+ return text;
79
+ return text.slice(0, max);
80
+ }
81
+ function textFor(field, max, words, offset, phrase) {
82
+ const source = words.names.length > 0 ? words.names : words.ids;
83
+ if (source.length === 0)
84
+ return cut(field, max);
85
+ const first = source[offset % source.length];
86
+ if (!phrase)
87
+ return cut(first, max);
88
+ const next = source[(offset + 1) % source.length];
89
+ return cut(first === next ? first : `${first} ${next}`, max);
90
+ }
91
+ function idFor(field, words, offset) {
92
+ if (words.ids.length === 0)
93
+ return field;
94
+ return words.ids[offset % words.ids.length];
95
+ }
96
+ function typeOf(node) {
97
+ return typeof node.type === 'string' ? node.type : '';
98
+ }
99
+ function alternativesOf(node) {
100
+ if (Array.isArray(node.anyOf))
101
+ return node.anyOf;
102
+ if (Array.isArray(node.oneOf))
103
+ return node.oneOf;
104
+ return undefined;
105
+ }
106
+ function isNullable(node) {
107
+ if (typeOf(node) === TYPES.null)
108
+ return true;
109
+ return alternativesOf(node)?.some(arm => typeOf(arm) === TYPES.null) ?? false;
110
+ }
111
+ function propertiesOf(node) {
112
+ return node.properties !== null && typeof node.properties === 'object' ? node.properties : {};
113
+ }
114
+ function requiredOf(node, properties) {
115
+ return Array.isArray(node.required) ? node.required : Object.keys(properties);
116
+ }
117
+ function kindIdOf(node) {
118
+ const kindId = propertiesOf(node)[FIELDS.kindId];
119
+ if (kindId === undefined)
120
+ return undefined;
121
+ if (typeof kindId.const === 'string')
122
+ return kindId.const;
123
+ if (Array.isArray(kindId.enum) && typeof kindId.enum[0] === 'string')
124
+ return kindId.enum[0];
125
+ return undefined;
126
+ }
127
+ function stringFor(name, node, input, words, ctx) {
128
+ const max = typeof node.maxLength === 'number' ? node.maxLength : undefined;
129
+ const request = input.request !== null && typeof input.request === 'object' ? input.request : undefined;
130
+ if (request !== undefined) {
131
+ if (name === FIELDS.id && typeof request.id === 'string')
132
+ return cut(request.id, max);
133
+ if (name === FIELDS.name && typeof request.name === 'string')
134
+ return cut(request.name, max);
135
+ if (name === FIELDS.meaning && typeof request.meaning === 'string')
136
+ return cut(request.meaning, max);
137
+ }
138
+ if (name === FIELDS.kindId && ctx.kindId !== undefined)
139
+ return cut(ctx.kindId, max);
140
+ if (name === FIELDS.entityId && ctx.kind === KINDS.entityCreate && ctx.kindId !== undefined)
141
+ return cut([ctx.kindId, 'new'].join('-'), max);
142
+ if (ctx.fresh === true && (name === FIELDS.personId || name === FIELDS.placeId || name === FIELDS.tensionId))
143
+ return cut(['new', idFor(name, words, ctx.offset)].join('-'), max);
144
+ if (name === FIELDS.name && ctx.kindId !== undefined) {
145
+ const kindName = words.kinds.get(ctx.kindId);
146
+ if (kindName !== undefined)
147
+ return cut(kindName, max);
148
+ }
149
+ const phrase = name === FIELDS.seenDoing || (max !== undefined && max >= 250);
150
+ if (isNameField(name))
151
+ return textFor(name, max, words, ctx.offset, phrase);
152
+ if (isIdField(name))
153
+ return cut(idFor(name, words, ctx.offset), max);
154
+ return textFor(name, max, words, ctx.offset, phrase);
155
+ }
156
+ function valueFor(name, node, input, words, ctx, fill) {
157
+ const alternatives = alternativesOf(node);
158
+ if (alternatives !== undefined) {
159
+ const nullable = alternatives.some(arm => typeOf(arm) === TYPES.null);
160
+ if (nullable && !fill)
161
+ return null;
162
+ if (name === FIELDS.items) {
163
+ const create = alternatives.find(arm => {
164
+ const kind = propertiesOf(arm).kind;
165
+ return kind !== undefined && typeof kind.const === 'string' && kind.const === KINDS.entityCreate;
166
+ });
167
+ if (create !== undefined)
168
+ return valueFor(name, create, input, words, ctx, fill);
169
+ }
170
+ const nonNull = alternatives.filter(arm => typeOf(arm) !== TYPES.null);
171
+ return valueFor(name, nonNull.length > 0 ? nonNull[0] : alternatives[0], input, words, ctx, fill);
172
+ }
173
+ if (node.const !== undefined)
174
+ return node.const;
175
+ if (Array.isArray(node.enum)) {
176
+ const values = node.enum;
177
+ if (name === FIELDS.action) {
178
+ const attempt = values.find(value => value === TYPES.attempt);
179
+ if (attempt !== undefined)
180
+ return attempt;
181
+ const other = values.find(value => value !== TYPES.wait);
182
+ if (other !== undefined)
183
+ return other;
184
+ }
185
+ return values[0];
186
+ }
187
+ const type = typeOf(node);
188
+ if (type === TYPES.null)
189
+ return null;
190
+ if (type === TYPES.boolean)
191
+ return false;
192
+ if (type === TYPES.integer || type === TYPES.number) {
193
+ const minimum = typeof node.minimum === 'number' ? node.minimum : undefined;
194
+ const maximum = typeof node.maximum === 'number' ? node.maximum : undefined;
195
+ const exclusive = typeof node.exclusiveMinimum === 'number' ? node.exclusiveMinimum : undefined;
196
+ let value = minimum ?? 0;
197
+ if (exclusive !== undefined && value <= exclusive)
198
+ value = exclusive + 1;
199
+ if (maximum !== undefined && value > maximum)
200
+ value = maximum;
201
+ return value;
202
+ }
203
+ if (type === TYPES.array) {
204
+ const items = node.items !== null && typeof node.items === 'object' ? node.items : undefined;
205
+ const min = typeof node.minItems === 'number' ? node.minItems : 0;
206
+ if (items === undefined || min === 0)
207
+ return [];
208
+ return [valueFor(FIELDS.items, items, input, words, ctx, true)];
209
+ }
210
+ if (type === TYPES.object) {
211
+ const properties = propertiesOf(node);
212
+ const kindNode = properties.kind;
213
+ const kind = kindNode !== undefined && typeof kindNode.const === 'string' ? kindNode.const : undefined;
214
+ const valuesNode = properties[FIELDS.values];
215
+ if (kind !== undefined && valuesNode !== undefined) {
216
+ return { kind, values: objectFor(valuesNode, input, words, { ...ctx, kind, kindId: kindIdOf(valuesNode), fresh: isCreateKind(kind) }) };
217
+ }
218
+ return objectFor(node, input, words, ctx);
219
+ }
220
+ if (type === TYPES.string || type.length === 0)
221
+ return stringFor(name, node, input, words, ctx);
222
+ return null;
223
+ }
224
+ function objectFor(node, input, words, ctx) {
225
+ const properties = propertiesOf(node);
226
+ const required = requiredOf(node, properties);
227
+ const out = {};
228
+ let offset = ctx.offset;
229
+ for (const name of required) {
230
+ const child = properties[name];
231
+ if (child === undefined)
232
+ continue;
233
+ out[name] = valueFor(name, child, input, words, { ...ctx, offset }, false);
234
+ offset += 1;
235
+ }
236
+ return out;
237
+ }
238
+ function exampleFor(id, schema, input) {
239
+ const spec = EXAMPLE_SPEC[id];
240
+ if (spec === undefined || Object.keys(spec).length === 0)
241
+ return null;
242
+ const words = wordsOf(input);
243
+ const out = {};
244
+ let offset = 0;
245
+ for (const [name, slot] of Object.entries(spec)) {
246
+ const node = schema.properties[name];
247
+ if (node === undefined)
248
+ continue;
249
+ if (slot === SLOT.null)
250
+ out[name] = isNullable(node) ? null : valueFor(name, node, input, words, { offset }, true);
251
+ else if (slot === SLOT.empty)
252
+ out[name] = [];
253
+ else if (slot === SLOT.one) {
254
+ const items = node.items !== null && typeof node.items === 'object' ? node.items : undefined;
255
+ out[name] = items === undefined ? [] : [valueFor(FIELDS.items, items, input, words, { offset }, true)];
256
+ }
257
+ else
258
+ out[name] = valueFor(name, node, input, words, { offset }, true);
259
+ offset += 1;
260
+ }
261
+ const updates = out[FIELDS.stateUpdates];
262
+ if (id === ROLES.gameMaster && Array.isArray(updates) && updates.length > 0) {
263
+ const fit = schema.properties[FIELDS.stateKindFit];
264
+ const values = fit !== undefined && Array.isArray(fit.enum) ? fit.enum : [];
265
+ if (values.some(value => value === TYPES.complete))
266
+ out[FIELDS.stateKindFit] = TYPES.complete;
267
+ }
268
+ return JSON.stringify(out);
269
+ }
270
+ export function systemFor(id, schema, input, fieldsSchema = schema) {
271
+ const header = roleText(id);
272
+ const fields = responseFieldLines(fieldsSchema);
273
+ const example = exampleFor(id, schema, input);
274
+ return [header, 'Fields:', fields, ...(example === null ? [] : ['Example:', example])].join(NEWLINE);
275
+ }
@@ -1,8 +1,8 @@
1
- import type { LivingPerson, LivingState } from './types.js';
1
+ import type { LivingPerson, LivingStateRaw } from './types.js';
2
2
  export type RecalledMemory = LivingPerson['memories'][number] & {
3
3
  score: number;
4
4
  };
5
- export declare function recallMemories(state: LivingState, person: LivingPerson, focusIds: readonly string[], limit: number, exclude?: ReadonlySet<string>, ranked?: boolean): RecalledMemory[];
5
+ export declare function recallMemories(state: LivingStateRaw, person: LivingPerson, focusIds: readonly string[], limit: number, exclude?: ReadonlySet<string>, ranked?: boolean): RecalledMemory[];
6
6
  export declare function recallBeliefs(person: LivingPerson, cues: readonly string[], limit: number): {
7
7
  score: number;
8
8
  id: string;
@@ -1,15 +1,52 @@
1
- import { type LivingEvent, type LivingState } from './types.js';
2
- export declare function peopleAt(state: LivingState, placeId: string): string[];
3
- export declare function witnessesFor(state: LivingState, event: Pick<LivingEvent, 'placeId' | 'actorId'>): string[];
4
- export declare function nearbyFor(state: LivingState, event: Pick<LivingEvent, 'placeId' | 'reach' | 'effects'>): string[];
5
- export declare function arrivalFor(state: LivingState, event: Pick<LivingEvent, 'placeId' | 'effects'>, personId: string): string | null;
6
- export declare function applyLivingEvent(previous: LivingState, input: LivingEvent): LivingState;
7
- export declare function foldLivingEvents(initial: LivingState, events: readonly LivingEvent[]): LivingState;
8
- export declare function countResult(decision: LivingState['entities'][string]): 'passed' | 'failed' | 'lapsed';
9
- export declare function votingShut(state: LivingState, decision: LivingState['entities'][string], at: number): string | null;
10
- export declare function countNote(decision: LivingState['entities'][string]): string;
11
- export declare function unansweredSince(state: LivingState, speakerId: string, listenerId: string): number | null;
1
+ import { type LivingKindDefinition } from './open-world.js';
2
+ import { type LivingEvent, type LivingStateRaw } from './types.js';
3
+ import type { ColdStore } from './cold.js';
4
+ export declare function peopleAt(state: LivingStateRaw, placeId: string): string[];
5
+ export declare function witnessesFor(state: LivingStateRaw, event: Pick<LivingEvent, 'placeId' | 'actorId'>): string[];
6
+ export declare function nearbyFor(state: LivingStateRaw, event: Pick<LivingEvent, 'placeId' | 'reach' | 'effects'> & {
7
+ channel?: string | null;
8
+ }): string[];
9
+ export declare function arrivalFor(state: LivingStateRaw, event: Pick<LivingEvent, 'placeId' | 'effects'>, personId: string): string | null;
10
+ export declare function applyLivingEvent(previous: LivingStateRaw, input: LivingEvent, cold?: ColdStore): LivingStateRaw;
11
+ export declare function foldLivingEvents(initial: LivingStateRaw, events: readonly LivingEvent[], cold?: ColdStore): LivingStateRaw;
12
+ export declare function isDecisionKind(kind: LivingKindDefinition | undefined): boolean;
13
+ export declare function isChoiceTurn(state: {
14
+ entities: Record<string, {
15
+ kindId: string;
16
+ }>;
17
+ kinds: Record<string, LivingKindDefinition | undefined>;
18
+ }, item: {
19
+ kind: string;
20
+ targetId: string | null;
21
+ }): boolean;
22
+ export declare function answeredLine(state: Parameters<typeof applyLivingEvent>[0], personId: string, causeSeq: number): boolean;
23
+ export type AnsweredAgain = {
24
+ repeats: number;
25
+ sameAskRepeats: number;
26
+ answers: number;
27
+ firstAt: number;
28
+ answeredAt: number;
29
+ answeredSeq: number;
30
+ };
31
+ export declare function answeredAgain(state: LivingStateRaw, personId: string): AnsweredAgain | null;
32
+ export type SaidAgain = {
33
+ count: number;
34
+ since: number;
35
+ toIds: string[];
36
+ };
37
+ export declare function saidAgain(state: Parameters<typeof answeredAgain>[0], personId: string, beforeSeq?: number): SaidAgain | null;
38
+ export declare function liveExchange(state: LivingStateRaw, personId: string): {
39
+ conversationId: string;
40
+ lastLineAt: number;
41
+ lastLineSeq: number;
42
+ lastLineText: string;
43
+ awaitingAnswer: boolean;
44
+ } | null;
45
+ export declare function reactPass(state: LivingStateRaw, event: LivingEvent, seeds: readonly {
46
+ entityId: string;
47
+ slotId: string;
48
+ }[], depth: number): void;
49
+ export declare function unansweredSince(state: LivingStateRaw, speakerId: string, listenerId: string): number | null;
12
50
  export declare function livingClockLead(rate: number): number;
13
- export declare function clockTargetAt(state: Pick<LivingState, 'clock' | 'clockRate' | 'paused' | 'clockAnchor'>, realMs: number): number;
14
- export declare const TRAVEL_MINUTES_PER_HOP = 3;
15
- export declare function travelPath(state: LivingState, from: string, to: string): string[] | null;
51
+ export declare function clockTargetAt(state: Pick<LivingStateRaw, 'clock' | 'clockRate' | 'paused' | 'clockAnchor'>, realMs: number): number;
52
+ export declare function travelPath(state: LivingStateRaw, from: string, to: string): string[] | null;