@zergai/ztc 0.26.6-dev.202611240947 → 0.27.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +629 -167
- package/RUST_THIRD_PARTY_LICENSES.txt +5 -5
- package/bin/zmux-darwin-arm64 +0 -0
- package/bin/zmux-linux-x64 +0 -0
- package/bin/ztc-audio-darwin-arm64 +0 -0
- package/bin/ztc-capture-darwin-arm64 +0 -0
- package/bin/ztc-computer-darwin-arm64 +0 -0
- package/bin/ztc-llm-darwin-arm64 +0 -0
- package/bin/ztc-tts-darwin-arm64 +0 -0
- package/bin/ztc-tui-darwin-arm64 +0 -0
- package/bin/ztc-tui-linux-x64 +0 -0
- package/bin/zterm-darwin-arm64 +2 -2
- package/dist/App.js +6 -1
- package/dist/agent/agent.d.ts +21 -15
- package/dist/agent/agent.js +389 -163
- package/dist/agent/backends/codex_app_server.d.ts +7 -1
- package/dist/agent/backends/codex_app_server.js +11 -1
- package/dist/agent/backends/gemini.js +22 -8
- package/dist/agent/commands/batch.js +8 -0
- package/dist/agent/commands/config.js +10 -0
- package/dist/agent/commands/environment.js +5 -5
- package/dist/agent/commands/goal.d.ts +1 -0
- package/dist/agent/commands/goal.js +2 -1
- package/dist/agent/commands/index.js +2 -1
- package/dist/agent/commands/manifest.js +4 -0
- package/dist/agent/commands/optimize.js +5 -2
- package/dist/agent/commands/pane_cli.d.ts +29 -0
- package/dist/agent/commands/pane_cli.js +303 -0
- package/dist/agent/commands/settings.js +13 -3
- package/dist/agent/commands/shannon.js +8 -0
- package/dist/agent/commands/update.js +15 -3
- package/dist/agent/commands/zerg.js +31 -1
- package/dist/agent/commands/ztc_pane.js +3 -1
- package/dist/agent/factory.d.ts +4 -0
- package/dist/agent/factory.js +11 -1
- package/dist/agent/loop_policy.d.ts +42 -5
- package/dist/agent/loop_policy.js +206 -3
- package/dist/agent/runtime/command_jobs.d.ts +5 -0
- package/dist/agent/runtime/command_jobs.js +241 -31
- package/dist/agent/runtime/command_wait.d.ts +2 -0
- package/dist/agent/runtime/command_wait.js +1 -0
- package/dist/agent/runtime/done_report.d.ts +18 -0
- package/dist/agent/runtime/done_report.js +130 -0
- package/dist/agent/runtime/execution_context.js +4 -1
- package/dist/agent/runtime/failure_cause.d.ts +2 -0
- package/dist/agent/runtime/failure_cause.js +35 -0
- package/dist/agent/runtime/policy.d.ts +14 -2
- package/dist/agent/runtime/policy.js +104 -12
- package/dist/agent/runtime/quiet_job.d.ts +18 -0
- package/dist/agent/runtime/quiet_job.js +48 -0
- package/dist/agent/runtime/recovery.d.ts +1 -5
- package/dist/agent/runtime/recovery.js +2 -44
- package/dist/agent/runtime/tool_runtime.d.ts +1 -0
- package/dist/agent/runtime/tool_runtime.js +2 -0
- package/dist/agent/subagent.js +6 -1
- package/dist/agent/tools/deferred.js +1 -0
- package/dist/agent/tools/index.d.ts +2 -0
- package/dist/agent/tools/index.js +1 -0
- package/dist/agent/tools/outcome.d.ts +15 -0
- package/dist/agent/tools/outcome.js +107 -0
- package/dist/agent/tools/pane.d.ts +2 -1
- package/dist/agent/tools/pane.js +21 -3
- package/dist/agent/tools/registry.js +2 -0
- package/dist/agent/tools/shell.d.ts +1 -0
- package/dist/agent/tools/shell.js +128 -17
- package/dist/agent/tools/sim_domain_tools.js +4 -2
- package/dist/agent/tools/supervision.js +4 -2
- package/dist/agent/tools/types.d.ts +3 -0
- package/dist/app/command_context.js +5 -9
- package/dist/app/conversation_compaction.d.ts +4 -2
- package/dist/app/conversation_compaction.js +16 -5
- package/dist/app/headless_shell_mode.d.ts +14 -0
- package/dist/app/headless_shell_mode.js +7 -0
- package/dist/app/hosted_resident.d.ts +356 -0
- package/dist/app/hosted_resident.js +677 -0
- package/dist/app/restart.js +11 -2
- package/dist/app/session_manager.d.ts +5 -0
- package/dist/app/session_manager.js +21 -6
- package/dist/app/session_messages.js +6 -6
- package/dist/app/workspace_layout_controller.js +7 -0
- package/dist/batch/worktree.d.ts +10 -0
- package/dist/batch/worktree.js +15 -0
- package/dist/bench/registry.js +4 -2
- package/dist/cli_args.js +1 -1
- package/dist/cli_main.js +80 -10
- package/dist/cli_ratatui.d.ts +75 -0
- package/dist/cli_ratatui.js +485 -84
- package/dist/components/InputArea.js +4 -4
- package/dist/config/execution.d.ts +10 -0
- package/dist/config/execution.js +10 -0
- package/dist/config/hosted_runtime.d.ts +4 -1
- package/dist/config/hosted_runtime.js +4 -1
- package/dist/config/permission_pin.d.ts +34 -2
- package/dist/config/permission_pin.js +52 -2
- package/dist/config/person_command_policy.d.ts +38 -0
- package/dist/config/person_command_policy.js +11 -0
- package/dist/config/profiles.d.ts +21 -0
- package/dist/config/profiles.js +56 -2
- package/dist/config/types.d.ts +4 -1
- package/dist/config.js +34 -19
- package/dist/desktop/daily/codex_exec_adapter.js +7 -2
- package/dist/desktop/daily/desktop_wiring.d.ts +7 -1
- package/dist/desktop/daily/desktop_wiring.js +11 -3
- package/dist/desktop/daily/recipes.js +20 -4
- package/dist/desktop/health.d.ts +24 -0
- package/dist/desktop/health.js +151 -0
- package/dist/desktop/native_dialogs.d.ts +37 -0
- package/dist/desktop/native_dialogs.js +105 -0
- package/dist/diagnostics/session_export.d.ts +1 -0
- package/dist/diagnostics/session_export.js +28 -0
- package/dist/embedded/registry.js +4 -2
- package/dist/emulation/tool_adapters.js +9 -4
- package/dist/emulation/ztc_addendum.js +3 -0
- package/dist/headless.d.ts +11 -4
- package/dist/headless.js +99 -34
- package/dist/headless_approval.d.ts +6 -0
- package/dist/headless_cli.js +1 -1
- package/dist/hooks/runner.js +7 -6
- package/dist/library.d.ts +4 -0
- package/dist/library.js +3 -0
- package/dist/mcp/client.js +3 -3
- package/dist/modes/registry.js +13 -4
- package/dist/onboarding/setup_environment.js +13 -1
- package/dist/optimize/adapters/kernelbench.js +88 -10
- package/dist/optimize/adapters/types.d.ts +5 -0
- package/dist/optimize/executor.js +21 -0
- package/dist/panes/cli_install.d.ts +54 -0
- package/dist/panes/cli_install.js +157 -0
- package/dist/panes/model_catalog.js +3 -0
- package/dist/panes/new_pane_choices.d.ts +6 -2
- package/dist/panes/new_pane_choices.js +24 -12
- package/dist/panes/pane_cli_launch.d.ts +50 -0
- package/dist/panes/pane_cli_launch.js +124 -0
- package/dist/panes/pane_clis.d.ts +171 -0
- package/dist/panes/pane_clis.js +325 -0
- package/dist/panes/person_only_panes.d.ts +45 -0
- package/dist/panes/person_only_panes.js +117 -0
- package/dist/plugin/simulation_living.js +0 -2
- package/dist/plugin/simulation_living_engine.d.ts +1 -0
- package/dist/plugin/simulation_living_engine.js +1 -0
- package/dist/plugin/simulation_living_labels.d.ts +3 -0
- package/dist/plugin/simulation_living_labels.js +2 -0
- package/dist/router_auth.js +12 -1
- package/dist/session.js +26 -1
- package/dist/simulation/art/gemini_image.js +11 -5
- package/dist/simulation/domains/loader.js +25 -3
- package/dist/simulation/living/cold.d.ts +23 -0
- package/dist/simulation/living/cold.js +41 -0
- package/dist/simulation/living/context.d.ts +591 -1283
- package/dist/simulation/living/context.js +378 -244
- package/dist/simulation/living/contradictions.d.ts +14 -0
- package/dist/simulation/living/contradictions.js +282 -0
- package/dist/simulation/living/core/ids.d.ts +53 -0
- package/dist/simulation/living/core/ids.js +39 -0
- package/dist/simulation/living/core/kind.d.ts +20 -0
- package/dist/simulation/living/core/kind.js +15 -0
- package/dist/simulation/living/core/laws.d.ts +179 -0
- package/dist/simulation/living/core/laws.js +184 -0
- package/dist/simulation/living/core/ops.d.ts +257 -0
- package/dist/simulation/living/core/ops.js +34 -0
- package/dist/simulation/living/definer.d.ts +17 -1
- package/dist/simulation/living/definer.js +130 -51
- package/dist/simulation/living/definition.d.ts +174 -65
- package/dist/simulation/living/definition.js +287 -180
- package/dist/simulation/living/director.d.ts +80 -0
- package/dist/simulation/living/director.js +363 -0
- package/dist/simulation/living/frame.d.ts +108 -21
- package/dist/simulation/living/frame.js +111 -66
- package/dist/simulation/living/identifiers.d.ts +0 -1
- package/dist/simulation/living/identifiers.js +0 -3
- package/dist/simulation/living/index.d.ts +18 -9
- package/dist/simulation/living/index.js +18 -9
- package/dist/simulation/living/inference.d.ts +92 -50
- package/dist/simulation/living/inference.js +319 -175
- package/dist/simulation/living/knowledge.d.ts +28 -0
- package/dist/simulation/living/knowledge.js +73 -0
- package/dist/simulation/living/library.json +1177 -0
- package/dist/simulation/living/mechanics.d.ts +31 -34
- package/dist/simulation/living/mechanics.js +222 -138
- package/dist/simulation/living/model-input.d.ts +6 -3
- package/dist/simulation/living/model-input.js +18 -26
- package/dist/simulation/living/open-world.d.ts +74 -94
- package/dist/simulation/living/open-world.js +151 -30
- package/dist/simulation/living/phrases.d.ts +3 -0
- package/dist/simulation/living/phrases.js +37 -0
- package/dist/simulation/living/phrases.json +560 -0
- package/dist/simulation/living/projection.d.ts +316 -2
- package/dist/simulation/living/projection.js +50 -2
- package/dist/simulation/living/prompts/example-spec.json +11 -0
- package/dist/simulation/living/prompts/role-text.json +14 -0
- package/dist/simulation/living/prompts.d.ts +5 -0
- package/dist/simulation/living/prompts.js +275 -0
- package/dist/simulation/living/recall.d.ts +2 -2
- package/dist/simulation/living/reduce.d.ts +51 -14
- package/dist/simulation/living/reduce.js +941 -579
- package/dist/simulation/living/replay.d.ts +5 -4
- package/dist/simulation/living/replay.js +10 -9
- package/dist/simulation/living/runtime.d.ts +135 -25
- package/dist/simulation/living/runtime.js +1641 -583
- package/dist/simulation/living/scale.d.ts +96 -0
- package/dist/simulation/living/scale.js +124 -0
- package/dist/simulation/living/script.d.ts +5 -0
- package/dist/simulation/living/script.js +115 -0
- package/dist/simulation/living/shared-kinds.d.ts +4 -11
- package/dist/simulation/living/shared-kinds.js +11 -81
- package/dist/simulation/living/space.d.ts +14 -0
- package/dist/simulation/living/space.js +132 -0
- package/dist/simulation/living/state.d.ts +100 -0
- package/dist/simulation/living/state.js +393 -0
- package/dist/simulation/living/types.d.ts +829 -512
- package/dist/simulation/living/types.js +162 -187
- package/dist/simulation/living/world-rules.d.ts +100 -0
- package/dist/simulation/living/world-rules.js +267 -0
- package/dist/simulation/plugins/loader.js +11 -0
- package/dist/skills/loader.js +4 -0
- package/dist/tools.d.ts +1 -0
- package/dist/tools.js +1 -0
- package/dist/ui/ratatui/headless_pane_manager.d.ts +4 -1
- package/dist/ui/ratatui/headless_pane_manager.js +13 -9
- package/dist/ui/ratatui/pane_relay.js +29 -0
- package/dist/ui/ratatui/pane_type.d.ts +10 -0
- package/dist/ui/ratatui/pane_type.js +11 -0
- package/dist/ui/ratatui/process.d.ts +30 -0
- package/dist/ui/ratatui/process.js +133 -19
- package/dist/ui/ratatui/protocol.d.ts +124 -2
- package/dist/ui/ratatui/protocol.js +35 -0
- package/dist/ui/ratatui/relay_policy.js +3 -0
- package/dist/ui/ratatui/ztc_launch_trust.d.ts +2 -1
- package/dist/ui/ratatui/ztc_launch_trust.js +8 -1
- package/dist/ui/terminal_image.d.ts +12 -0
- package/dist/ui/terminal_image.js +21 -1
- package/dist/utils/codex_project_trust.d.ts +19 -0
- package/dist/utils/codex_project_trust.js +37 -0
- package/dist/utils/compaction.js +103 -20
- package/dist/utils/git_program_files.d.ts +19 -12
- package/dist/utils/git_program_files.js +411 -83
- package/dist/utils/host_shell.d.ts +10 -1
- package/dist/utils/host_shell.js +14 -1
- package/dist/utils/mid_turn_compaction.d.ts +2 -0
- package/dist/utils/mid_turn_compaction.js +2 -0
- package/dist/utils/models.js +6 -1
- package/dist/utils/sandbox.d.ts +109 -8
- package/dist/utils/sandbox.js +981 -187
- package/dist/utils/shell.d.ts +2 -0
- package/dist/utils/shell.js +10 -4
- package/dist/utils/subprocess_env.d.ts +47 -11
- package/dist/utils/subprocess_env.js +107 -15
- package/dist/utils/system_ps.d.ts +8 -0
- package/dist/utils/system_ps.js +39 -7
- package/dist/utils/unattended_compaction.d.ts +9 -0
- package/dist/utils/unattended_compaction.js +13 -0
- package/dist/utils/ztc_own_state.d.ts +8 -5
- package/dist/utils/ztc_own_state.js +17 -11
- package/dist/web/mirror_client.js +1 -0
- package/dist/web/mirror_stream.d.ts +50 -6
- package/dist/web/mirror_stream.js +160 -15
- package/dist/workflows/registry.js +3 -1
- package/dist/workspace/controller.js +12 -0
- package/dist/workspace_collision.d.ts +3 -0
- package/dist/workspace_collision.js +14 -1
- package/dist/workspace_session_context.js +2 -1
- package/dist/zlm-embed.mjs +3823 -1970
- package/node_modules/@zerg/model-contracts/README.md +16 -4
- package/node_modules/@zerg/model-contracts/index.js +6 -1
- package/npm-shrinkwrap.json +1 -1
- package/package.json +42 -24
- package/packages/model-contracts/README.md +16 -4
- package/packages/model-contracts/index.js +6 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type LivingInferenceCall } from './inference.js';
|
|
2
2
|
export declare const LIVING_INPUT_BUDGETS: {
|
|
3
3
|
readonly attempt: 16000;
|
|
4
4
|
readonly world: 16000;
|
|
@@ -9,17 +9,20 @@ export declare const LIVING_INPUT_BUDGETS: {
|
|
|
9
9
|
readonly 'message-reply': 16000;
|
|
10
10
|
readonly epilogue: 12000;
|
|
11
11
|
readonly define: 12000;
|
|
12
|
+
readonly revise: 32000;
|
|
13
|
+
readonly director: 16000;
|
|
12
14
|
};
|
|
13
15
|
export declare const LIVING_RESPONSE_SCHEMA_BUDGET = 96000;
|
|
14
16
|
export declare const MODEL_VIEW_NOTE = "Selected context: other people and facts remain in the world. Descriptions may be excerpts. Use only the IDs shown; omission does not mean absence.";
|
|
15
|
-
export declare
|
|
17
|
+
export declare const MODEL_EXCERPT_LIMITS: readonly [300, 120, 40, 16];
|
|
18
|
+
export declare function assertLivingModelCall(call: Pick<LivingInferenceCall, 'phase' | 'input' | 'responseSchema' | 'maxTokens'>): void;
|
|
16
19
|
type Data = Record<string, unknown>;
|
|
17
20
|
export declare function decisionInputBudget(input: Data, ordinaryBudget: number): number;
|
|
18
21
|
export declare const MODEL_PEOPLE_LIMIT = 24;
|
|
19
22
|
export declare function selectModelPeople(input: Data, close: ReadonlySet<string>): ReadonlySet<string>;
|
|
20
23
|
export declare function syncModelPeople(input: Data): void;
|
|
21
24
|
export declare function modelTextExcerpt(text: string, limit?: number): string;
|
|
22
|
-
export declare function compactModelInput(input: Data, budget: number, priority: ReadonlySet<string>, maximum?: number, things?: ReadonlySet<string
|
|
25
|
+
export declare function compactModelInput(input: Data, budget: number, priority: ReadonlySet<string>, maximum?: number, things?: ReadonlySet<string>, measure?: (value: unknown) => number): void;
|
|
23
26
|
export declare function withContextLookup(schema: Readonly<Data>, input: Readonly<Data>): Readonly<Data>;
|
|
24
27
|
export declare function contextSelectionInput(input: Readonly<Data>): Data;
|
|
25
28
|
export {};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { LivingWorldError } from './types.js';
|
|
2
|
+
import { livingAnswerTokens } from './inference.js';
|
|
2
3
|
export const LIVING_INPUT_BUDGETS = { attempt: 16_000, world: 16_000, 'speech-impact': 16_000,
|
|
3
|
-
reaction: 32_000, reply: 32_000, plan: 14_000, 'message-reply': 16_000, epilogue: 12_000, define: 12_000 };
|
|
4
|
+
reaction: 32_000, reply: 32_000, plan: 14_000, 'message-reply': 16_000, epilogue: 12_000, define: 12_000, revise: 32_000, director: 16_000 };
|
|
4
5
|
export const LIVING_RESPONSE_SCHEMA_BUDGET = 96_000;
|
|
5
6
|
export const MODEL_VIEW_NOTE = 'Selected context: other people and facts remain in the world. Descriptions may be excerpts. Use only the IDs shown; omission does not mean absence.';
|
|
7
|
+
export const MODEL_EXCERPT_LIMITS = [300, 120, 40, 16];
|
|
6
8
|
export function assertLivingModelCall(call) {
|
|
7
9
|
const size = JSON.stringify(call.input).length;
|
|
8
10
|
const budget = LIVING_INPUT_BUDGETS[call.phase];
|
|
@@ -11,6 +13,9 @@ export function assertLivingModelCall(call) {
|
|
|
11
13
|
const schemaSize = JSON.stringify(call.responseSchema).length;
|
|
12
14
|
if (schemaSize > LIVING_RESPONSE_SCHEMA_BUDGET)
|
|
13
15
|
throw new LivingWorldError('inference-invalid', `${call.phase} schema ${schemaSize} exceeds ${LIVING_RESPONSE_SCHEMA_BUDGET} characters`);
|
|
16
|
+
const needed = livingAnswerTokens(call.responseSchema);
|
|
17
|
+
if (needed > call.maxTokens)
|
|
18
|
+
throw new LivingWorldError('inference-invalid', `${call.phase} answer may need ${needed} tokens, over its ${call.maxTokens}`);
|
|
14
19
|
}
|
|
15
20
|
// These fields describe the decision being made. Background records may yield to them.
|
|
16
21
|
const decisionFields = new Set(['attempt', 'words', 'happening', 'happened', 'message', 'duePlan', 'request']);
|
|
@@ -26,7 +31,7 @@ export function decisionInputBudget(input, ordinaryBudget) {
|
|
|
26
31
|
}
|
|
27
32
|
const object = (value) => value !== null && typeof value === 'object' && !Array.isArray(value) ? value : undefined;
|
|
28
33
|
const list = (value) => Array.isArray(value) ? value : [];
|
|
29
|
-
const personPaths = [['scene', 'people'], ['world', 'people'], ['world', 'elsewhere'], ['world', '
|
|
34
|
+
const personPaths = [['scene', 'people'], ['world', 'people'], ['world', 'elsewhere'], ['world', 'offstage'], ['directory', 'people'], ['listeners'], ['elsewhere']];
|
|
30
35
|
export const MODEL_PEOPLE_LIMIT = 24;
|
|
31
36
|
function at(input, path) {
|
|
32
37
|
let value = input;
|
|
@@ -48,7 +53,7 @@ export function selectModelPeople(input, close) {
|
|
|
48
53
|
object(input.plan)?.targetId, object(input.about)?.id];
|
|
49
54
|
const priority = [...new Set([...close, ...explicit.filter((value) => typeof value === 'string')])]
|
|
50
55
|
.filter(id => candidates.has(id)).slice(0, MODEL_PEOPLE_LIMIT);
|
|
51
|
-
const selected = new Set([...priority, ...candidates.keys()].slice(0, MODEL_PEOPLE_LIMIT));
|
|
56
|
+
const selected = new Set([...new Set([...priority, ...candidates.keys()])].slice(0, MODEL_PEOPLE_LIMIT));
|
|
52
57
|
if (selected.size < candidates.size) {
|
|
53
58
|
input.view = MODEL_VIEW_NOTE;
|
|
54
59
|
for (const path of personPaths) {
|
|
@@ -58,25 +63,12 @@ export function selectModelPeople(input, close) {
|
|
|
58
63
|
}
|
|
59
64
|
if (Array.isArray(input.relationships))
|
|
60
65
|
input.relationships = input.relationships.filter(item => selected.has(String(object(item)?.id)));
|
|
61
|
-
const balances = object(input.money);
|
|
62
|
-
if (balances && Array.isArray(balances.balances))
|
|
63
|
-
balances.balances = balances.balances.filter(item => {
|
|
64
|
-
const id = String(object(item)?.id);
|
|
65
|
-
return !candidates.has(id) || selected.has(id);
|
|
66
|
-
});
|
|
67
66
|
}
|
|
68
67
|
const happened = object(input.happened);
|
|
69
68
|
if (happened && Array.isArray(happened.to)) {
|
|
70
69
|
const names = new Set([...selected].map(id => candidates.get(id).name));
|
|
71
70
|
names.add(object(input.identity)?.name);
|
|
72
|
-
|
|
73
|
-
const recipients = happened.to.filter(name => {
|
|
74
|
-
const size = JSON.stringify(name).length + 1;
|
|
75
|
-
if (!names.has(name) || size > remaining)
|
|
76
|
-
return false;
|
|
77
|
-
remaining -= size;
|
|
78
|
-
return true;
|
|
79
|
-
});
|
|
71
|
+
const recipients = happened.to.filter(name => names.has(name));
|
|
80
72
|
if (recipients.length < happened.to.length) {
|
|
81
73
|
input.view = MODEL_VIEW_NOTE;
|
|
82
74
|
happened.otherAddresseeCount = happened.to.length - recipients.length;
|
|
@@ -107,8 +99,8 @@ export function modelTextExcerpt(text, limit = 300) {
|
|
|
107
99
|
// When ordinary relevance trimming is insufficient, shorten descriptions, then shed whole optional
|
|
108
100
|
// records. IDs remain exact, and stored words stay whole. The view notice marks excerpts. The things
|
|
109
101
|
// a decision is about give way only after every other record that may.
|
|
110
|
-
export function compactModelInput(input, budget, priority, maximum = budget, things = new Set()) {
|
|
111
|
-
if (
|
|
102
|
+
export function compactModelInput(input, budget, priority, maximum = budget, things = new Set(), measure = value => JSON.stringify(value).length) {
|
|
103
|
+
if (measure(input) <= budget)
|
|
112
104
|
return;
|
|
113
105
|
input.view = MODEL_VIEW_NOTE;
|
|
114
106
|
const shorten = (value, path, limit) => {
|
|
@@ -123,9 +115,9 @@ export function compactModelInput(input, budget, priority, maximum = budget, thi
|
|
|
123
115
|
const record = object(value);
|
|
124
116
|
return record ? Object.fromEntries(Object.entries(record).map(([key, child]) => [key, shorten(child, path ? `${path}/${key}` : key, limit)])) : value;
|
|
125
117
|
};
|
|
126
|
-
Object.assign(input, shorten(input, '',
|
|
118
|
+
Object.assign(input, shorten(input, '', MODEL_EXCERPT_LIMITS[0]));
|
|
127
119
|
let shielded = things;
|
|
128
|
-
while (
|
|
120
|
+
while (measure(input) > budget) {
|
|
129
121
|
let choice;
|
|
130
122
|
const visit = (value, path) => {
|
|
131
123
|
if (isDecisionField(input, path))
|
|
@@ -138,7 +130,7 @@ export function compactModelInput(input, budget, priority, maximum = budget, thi
|
|
|
138
130
|
while (index >= 0 && kept(value[index]))
|
|
139
131
|
index -= 1;
|
|
140
132
|
if (index >= 0) {
|
|
141
|
-
const size =
|
|
133
|
+
const size = measure(value[index]);
|
|
142
134
|
if (!choice || size > choice.size)
|
|
143
135
|
choice = { array: value, index, size };
|
|
144
136
|
}
|
|
@@ -170,13 +162,13 @@ export function compactModelInput(input, budget, priority, maximum = budget, thi
|
|
|
170
162
|
choice.array.splice(choice.index, 1);
|
|
171
163
|
syncModelPeople(input);
|
|
172
164
|
}
|
|
173
|
-
if (
|
|
165
|
+
if (measure(input) > maximum && !isDecisionField(input, 'plan'))
|
|
174
166
|
delete input.plan;
|
|
175
167
|
// Kept cards can still hold escaped text at six JSON characters per unit; their words give way, never the decision.
|
|
176
|
-
for (const limit of
|
|
177
|
-
if (
|
|
168
|
+
for (const limit of MODEL_EXCERPT_LIMITS.slice(1))
|
|
169
|
+
if (measure(input) > maximum)
|
|
178
170
|
Object.assign(input, shorten(input, '', limit));
|
|
179
|
-
if (
|
|
171
|
+
if (measure(input) > maximum)
|
|
180
172
|
throw new LivingWorldError('inference-invalid', 'The selected model input exceeds its character budget');
|
|
181
173
|
}
|
|
182
174
|
// A model can ask for exact identities outside the selected view before proposing effects.
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
import { type Law } from './core/laws.js';
|
|
3
|
+
export declare const idDescription: string;
|
|
4
|
+
export declare const idSchema: z.ZodString;
|
|
2
5
|
export declare const scheduleIntentSchema: z.ZodString;
|
|
3
6
|
export declare const levelSchema: z.ZodEnum<{
|
|
4
7
|
none: "none";
|
|
@@ -6,12 +9,24 @@ export declare const levelSchema: z.ZodEnum<{
|
|
|
6
9
|
medium: "medium";
|
|
7
10
|
high: "high";
|
|
8
11
|
}>;
|
|
12
|
+
export declare const seriesEntrySchema: z.ZodObject<{
|
|
13
|
+
option: z.ZodString;
|
|
14
|
+
personId: z.ZodString;
|
|
15
|
+
at: z.ZodNumber;
|
|
16
|
+
seq: z.ZodNumber;
|
|
17
|
+
}, z.core.$strip>;
|
|
18
|
+
export type LivingSeriesEntry = z.infer<typeof seriesEntrySchema>;
|
|
9
19
|
export declare const propertyValueSchema: z.ZodUnion<readonly [z.ZodBoolean, z.ZodNumber, z.ZodEnum<{
|
|
10
20
|
none: "none";
|
|
11
21
|
low: "low";
|
|
12
22
|
medium: "medium";
|
|
13
23
|
high: "high";
|
|
14
|
-
}>, z.ZodString
|
|
24
|
+
}>, z.ZodString, z.ZodArray<z.ZodObject<{
|
|
25
|
+
option: z.ZodString;
|
|
26
|
+
personId: z.ZodString;
|
|
27
|
+
at: z.ZodNumber;
|
|
28
|
+
seq: z.ZodNumber;
|
|
29
|
+
}, z.core.$strip>>]>;
|
|
15
30
|
export declare const propertyDefinitionSchema: z.ZodObject<{
|
|
16
31
|
id: z.ZodString;
|
|
17
32
|
type: z.ZodEnum<{
|
|
@@ -21,8 +36,13 @@ export declare const propertyDefinitionSchema: z.ZodObject<{
|
|
|
21
36
|
flag: "flag";
|
|
22
37
|
level: "level";
|
|
23
38
|
time: "time";
|
|
39
|
+
series: "series";
|
|
24
40
|
}>;
|
|
41
|
+
options: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
42
|
+
perActor: z.ZodOptional<z.ZodBoolean>;
|
|
43
|
+
sealedBy: z.ZodOptional<z.ZodString>;
|
|
25
44
|
requiredOnCreate: z.ZodOptional<z.ZodBoolean>;
|
|
45
|
+
target: z.ZodOptional<z.ZodLiteral<"tension">>;
|
|
26
46
|
}, z.core.$strip>;
|
|
27
47
|
export declare const relationDefinitionSchema: z.ZodObject<{
|
|
28
48
|
id: z.ZodString;
|
|
@@ -49,40 +69,13 @@ export declare const mechanicSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
49
69
|
low: "low";
|
|
50
70
|
medium: "medium";
|
|
51
71
|
high: "high";
|
|
52
|
-
}>, z.ZodString
|
|
72
|
+
}>, z.ZodString, z.ZodArray<z.ZodObject<{
|
|
73
|
+
option: z.ZodString;
|
|
74
|
+
personId: z.ZodString;
|
|
75
|
+
at: z.ZodNumber;
|
|
76
|
+
seq: z.ZodNumber;
|
|
77
|
+
}, z.core.$strip>>]>;
|
|
53
78
|
}, z.core.$strip>>;
|
|
54
|
-
}, z.core.$strip>, z.ZodObject<{
|
|
55
|
-
kind: z.ZodLiteral<"trigger">;
|
|
56
|
-
propertyId: z.ZodString;
|
|
57
|
-
threshold: z.ZodNumber;
|
|
58
|
-
direction: z.ZodEnum<{
|
|
59
|
-
"at-least": "at-least";
|
|
60
|
-
"at-most": "at-most";
|
|
61
|
-
}>;
|
|
62
|
-
intent: z.ZodString;
|
|
63
|
-
delayMinutes: z.ZodNumber;
|
|
64
|
-
minImportance: z.ZodOptional<z.ZodNumber>;
|
|
65
|
-
}, z.core.$strip>, z.ZodObject<{
|
|
66
|
-
kind: z.ZodLiteral<"gate">;
|
|
67
|
-
propertyId: z.ZodString;
|
|
68
|
-
subjectPropertyId: z.ZodString;
|
|
69
|
-
atLeast: z.ZodOptional<z.ZodEnum<{
|
|
70
|
-
none: "none";
|
|
71
|
-
low: "low";
|
|
72
|
-
medium: "medium";
|
|
73
|
-
high: "high";
|
|
74
|
-
}>>;
|
|
75
|
-
blockedActionKinds: z.ZodArray<z.ZodString>;
|
|
76
|
-
}, z.core.$strip>, z.ZodObject<{
|
|
77
|
-
kind: z.ZodLiteral<"norm">;
|
|
78
|
-
actionKind: z.ZodString;
|
|
79
|
-
roleId: z.ZodNullable<z.ZodString>;
|
|
80
|
-
forbidden: z.ZodBoolean;
|
|
81
|
-
}, z.core.$strip>, z.ZodObject<{
|
|
82
|
-
kind: z.ZodLiteral<"authority">;
|
|
83
|
-
roleId: z.ZodString;
|
|
84
|
-
relationId: z.ZodNullable<z.ZodString>;
|
|
85
|
-
propertyId: z.ZodNullable<z.ZodString>;
|
|
86
79
|
}, z.core.$strip>], "kind">;
|
|
87
80
|
export declare const kindDefinitionSchema: z.ZodObject<{
|
|
88
81
|
id: z.ZodString;
|
|
@@ -97,8 +90,13 @@ export declare const kindDefinitionSchema: z.ZodObject<{
|
|
|
97
90
|
flag: "flag";
|
|
98
91
|
level: "level";
|
|
99
92
|
time: "time";
|
|
93
|
+
series: "series";
|
|
100
94
|
}>;
|
|
95
|
+
options: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
96
|
+
perActor: z.ZodOptional<z.ZodBoolean>;
|
|
97
|
+
sealedBy: z.ZodOptional<z.ZodString>;
|
|
101
98
|
requiredOnCreate: z.ZodOptional<z.ZodBoolean>;
|
|
99
|
+
target: z.ZodOptional<z.ZodLiteral<"tension">>;
|
|
102
100
|
}, z.core.$strip>>;
|
|
103
101
|
relations: z.ZodArray<z.ZodObject<{
|
|
104
102
|
id: z.ZodString;
|
|
@@ -125,43 +123,21 @@ export declare const kindDefinitionSchema: z.ZodObject<{
|
|
|
125
123
|
low: "low";
|
|
126
124
|
medium: "medium";
|
|
127
125
|
high: "high";
|
|
128
|
-
}>, z.ZodString
|
|
126
|
+
}>, z.ZodString, z.ZodArray<z.ZodObject<{
|
|
127
|
+
option: z.ZodString;
|
|
128
|
+
personId: z.ZodString;
|
|
129
|
+
at: z.ZodNumber;
|
|
130
|
+
seq: z.ZodNumber;
|
|
131
|
+
}, z.core.$strip>>]>;
|
|
129
132
|
}, z.core.$strip>>;
|
|
130
|
-
}, z.core.$strip>, z.ZodObject<{
|
|
131
|
-
kind: z.ZodLiteral<"trigger">;
|
|
132
|
-
propertyId: z.ZodString;
|
|
133
|
-
threshold: z.ZodNumber;
|
|
134
|
-
direction: z.ZodEnum<{
|
|
135
|
-
"at-least": "at-least";
|
|
136
|
-
"at-most": "at-most";
|
|
137
|
-
}>;
|
|
138
|
-
intent: z.ZodString;
|
|
139
|
-
delayMinutes: z.ZodNumber;
|
|
140
|
-
minImportance: z.ZodOptional<z.ZodNumber>;
|
|
141
|
-
}, z.core.$strip>, z.ZodObject<{
|
|
142
|
-
kind: z.ZodLiteral<"gate">;
|
|
143
|
-
propertyId: z.ZodString;
|
|
144
|
-
subjectPropertyId: z.ZodString;
|
|
145
|
-
atLeast: z.ZodOptional<z.ZodEnum<{
|
|
146
|
-
none: "none";
|
|
147
|
-
low: "low";
|
|
148
|
-
medium: "medium";
|
|
149
|
-
high: "high";
|
|
150
|
-
}>>;
|
|
151
|
-
blockedActionKinds: z.ZodArray<z.ZodString>;
|
|
152
|
-
}, z.core.$strip>, z.ZodObject<{
|
|
153
|
-
kind: z.ZodLiteral<"norm">;
|
|
154
|
-
actionKind: z.ZodString;
|
|
155
|
-
roleId: z.ZodNullable<z.ZodString>;
|
|
156
|
-
forbidden: z.ZodBoolean;
|
|
157
|
-
}, z.core.$strip>, z.ZodObject<{
|
|
158
|
-
kind: z.ZodLiteral<"authority">;
|
|
159
|
-
roleId: z.ZodString;
|
|
160
|
-
relationId: z.ZodNullable<z.ZodString>;
|
|
161
|
-
propertyId: z.ZodNullable<z.ZodString>;
|
|
162
133
|
}, z.core.$strip>], "kind">>;
|
|
134
|
+
laws: z.ZodOptional<z.ZodArray<z.ZodType<Law, unknown, z.core.$ZodTypeInternals<Law, unknown>>>>;
|
|
135
|
+
library: z.ZodOptional<z.ZodBoolean>;
|
|
136
|
+
neverHeld: z.ZodOptional<z.ZodBoolean>;
|
|
163
137
|
}, z.core.$strip>;
|
|
164
|
-
export type LivingKindDefinition = z.infer<typeof kindDefinitionSchema
|
|
138
|
+
export type LivingKindDefinition = z.infer<typeof kindDefinitionSchema> & {
|
|
139
|
+
legacy?: boolean;
|
|
140
|
+
};
|
|
165
141
|
export declare const kindRequestSchema: z.ZodObject<{
|
|
166
142
|
id: z.ZodString;
|
|
167
143
|
name: z.ZodString;
|
|
@@ -173,7 +149,12 @@ export declare const slotSchema: z.ZodObject<{
|
|
|
173
149
|
low: "low";
|
|
174
150
|
medium: "medium";
|
|
175
151
|
high: "high";
|
|
176
|
-
}>, z.ZodString
|
|
152
|
+
}>, z.ZodString, z.ZodArray<z.ZodObject<{
|
|
153
|
+
option: z.ZodString;
|
|
154
|
+
personId: z.ZodString;
|
|
155
|
+
at: z.ZodNumber;
|
|
156
|
+
seq: z.ZodNumber;
|
|
157
|
+
}, z.core.$strip>>]>;
|
|
177
158
|
changedSeq: z.ZodNumber;
|
|
178
159
|
previousSeq: z.ZodNullable<z.ZodNumber>;
|
|
179
160
|
knownTo: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
@@ -189,40 +170,23 @@ export declare const entitySchema: z.ZodObject<{
|
|
|
189
170
|
id: z.ZodString;
|
|
190
171
|
kindId: z.ZodString;
|
|
191
172
|
name: z.ZodString;
|
|
192
|
-
|
|
193
|
-
paperViews: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
194
|
-
name: z.ZodString;
|
|
195
|
-
words: z.ZodNullable<z.ZodString>;
|
|
196
|
-
}, z.core.$strip>>>;
|
|
197
|
-
holderId: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
173
|
+
containerId: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
198
174
|
condition: z.ZodDefault<z.ZodNullable<z.ZodString>>;
|
|
199
175
|
aspects: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
200
176
|
sideOrder: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
201
177
|
hidden: z.ZodOptional<z.ZodLiteral<true>>;
|
|
202
|
-
members: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
203
|
-
ballots: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodEnum<{
|
|
204
|
-
no: "no";
|
|
205
|
-
yes: "yes";
|
|
206
|
-
abstain: "abstain";
|
|
207
|
-
}>>>;
|
|
208
|
-
result: z.ZodOptional<z.ZodEnum<{
|
|
209
|
-
failed: "failed";
|
|
210
|
-
passed: "passed";
|
|
211
|
-
lapsed: "lapsed";
|
|
212
|
-
}>>;
|
|
213
|
-
settles: z.ZodOptional<z.ZodString>;
|
|
214
|
-
transfers: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
215
|
-
fromId: z.ZodNullable<z.ZodString>;
|
|
216
|
-
toId: z.ZodNullable<z.ZodString>;
|
|
217
|
-
amount: z.ZodNumber;
|
|
218
|
-
}, z.core.$strip>>>;
|
|
219
178
|
properties: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
220
179
|
value: z.ZodUnion<readonly [z.ZodBoolean, z.ZodNumber, z.ZodEnum<{
|
|
221
180
|
none: "none";
|
|
222
181
|
low: "low";
|
|
223
182
|
medium: "medium";
|
|
224
183
|
high: "high";
|
|
225
|
-
}>, z.ZodString
|
|
184
|
+
}>, z.ZodString, z.ZodArray<z.ZodObject<{
|
|
185
|
+
option: z.ZodString;
|
|
186
|
+
personId: z.ZodString;
|
|
187
|
+
at: z.ZodNumber;
|
|
188
|
+
seq: z.ZodNumber;
|
|
189
|
+
}, z.core.$strip>>]>;
|
|
226
190
|
changedSeq: z.ZodNumber;
|
|
227
191
|
previousSeq: z.ZodNullable<z.ZodNumber>;
|
|
228
192
|
knownTo: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
@@ -251,7 +215,23 @@ export declare const changeSchema: z.ZodObject<{
|
|
|
251
215
|
low: "low";
|
|
252
216
|
medium: "medium";
|
|
253
217
|
high: "high";
|
|
254
|
-
}>, z.ZodString
|
|
218
|
+
}>, z.ZodString, z.ZodArray<z.ZodObject<{
|
|
219
|
+
option: z.ZodString;
|
|
220
|
+
personId: z.ZodString;
|
|
221
|
+
at: z.ZodNumber;
|
|
222
|
+
seq: z.ZodNumber;
|
|
223
|
+
}, z.core.$strip>>]>>;
|
|
255
224
|
}, z.core.$strip>;
|
|
256
225
|
export type LivingChange = z.infer<typeof changeSchema>;
|
|
257
226
|
export declare function valueMatchesType(type: z.infer<typeof propertyDefinitionSchema>['type'], value: z.infer<typeof propertyValueSchema>): boolean;
|
|
227
|
+
export type LawSlots = {
|
|
228
|
+
properties: readonly {
|
|
229
|
+
id: string;
|
|
230
|
+
type: string;
|
|
231
|
+
}[];
|
|
232
|
+
relations: readonly {
|
|
233
|
+
id: string;
|
|
234
|
+
}[];
|
|
235
|
+
};
|
|
236
|
+
export declare function lawProblems(law: Law, definition: LawSlots): string[];
|
|
237
|
+
export declare function narrowsKindRevision(previous: LivingKindDefinition, next: LivingKindDefinition): boolean;
|
|
@@ -1,37 +1,41 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
|
|
2
|
+
import { lawSchema } from './core/laws.js';
|
|
3
|
+
import { phrase } from './phrases.js';
|
|
4
|
+
export const idDescription = phrase('schema.id');
|
|
5
|
+
export const idSchema = z.string().regex(/^[a-z0-9][a-z0-9-]{0,63}$/u).describe(idDescription);
|
|
6
|
+
const id = idSchema;
|
|
3
7
|
const text = z.string().min(1).max(2000);
|
|
4
8
|
export const scheduleIntentSchema = text;
|
|
5
9
|
export const levelSchema = z.enum(['none', 'low', 'medium', 'high']);
|
|
6
|
-
export const
|
|
10
|
+
export const seriesEntrySchema = z.object({
|
|
11
|
+
option: id.describe(phrase('schema.description.165')),
|
|
12
|
+
personId: id.describe(phrase('schema.description.166')),
|
|
13
|
+
at: z.number().int().min(0).describe(phrase('schema.description.167')),
|
|
14
|
+
seq: z.number().int().min(1).describe(phrase('schema.description.168')),
|
|
15
|
+
});
|
|
16
|
+
export const propertyValueSchema = z.union([z.boolean(), z.number().finite(), levelSchema, z.string().min(1).max(2000), z.array(seriesEntrySchema).max(64)]);
|
|
7
17
|
export const propertyDefinitionSchema = z.object({
|
|
8
18
|
id,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
19
|
+
type: z.enum(['flag', 'level', 'number', 'time', 'id', 'text', 'series']).describe(phrase('schema.description.169')),
|
|
20
|
+
options: z.array(id).max(16).optional().describe(phrase('schema.description.170')),
|
|
21
|
+
perActor: z.boolean().optional().describe(phrase('schema.description.171')),
|
|
22
|
+
sealedBy: id.optional().describe(phrase('schema.description.172')),
|
|
23
|
+
requiredOnCreate: z.boolean().optional().describe(phrase('schema.description.173')),
|
|
24
|
+
target: z.literal('tension').optional().describe(phrase('schema.description.174')),
|
|
12
25
|
});
|
|
13
26
|
export const relationDefinitionSchema = z.object({
|
|
14
27
|
id,
|
|
15
|
-
targetKindId: id,
|
|
28
|
+
targetKindId: id.describe(phrase('schema.description.175')),
|
|
16
29
|
});
|
|
17
30
|
const property = id.describe('Property of this kind that the rule reads or changes.');
|
|
18
31
|
const relation = id.describe('Relation of this kind that the rule follows.');
|
|
19
32
|
const subject = id.describe('Id property naming the person or thing affected.');
|
|
20
|
-
const role = id.describe('Role id.');
|
|
21
33
|
export const mechanicSchema = z.discriminatedUnion('kind', [
|
|
22
|
-
z.object({ kind: z.literal('spread'), propertyId: property, relationId: relation }),
|
|
23
|
-
z.object({ kind: z.literal('signal'), propertyId: property, relationId: relation, channel: id.describe('Sense channel, such as sight, sound, smell, or touch.') }),
|
|
24
|
-
z.object({ kind: z.literal('change'), propertyId: property, deltaPerMinute: z.number().finite().describe('Change per minute; 0 for a change on an event.'),
|
|
25
|
-
onEvent: z.object({ kind: z.literal('move'), subjectPropertyId: subject, value: propertyValueSchema.describe('Value set when the subject moves.') }).optional()
|
|
34
|
+
z.object({ kind: z.literal('spread').describe(phrase('mechanic.spread')), propertyId: property, relationId: relation }),
|
|
35
|
+
z.object({ kind: z.literal('signal').describe(phrase('mechanic.signal')), propertyId: property, relationId: relation, channel: id.describe('Sense channel, such as sight, sound, smell, or touch.') }),
|
|
36
|
+
z.object({ kind: z.literal('change').describe(phrase('mechanic.change')), propertyId: property, deltaPerMinute: z.number().finite().describe('Change per minute; 0 for a change on an event.'),
|
|
37
|
+
onEvent: z.object({ kind: z.literal('move').describe(phrase('schema.description.176')), subjectPropertyId: subject, value: propertyValueSchema.describe('Value set when the subject moves.') }).optional()
|
|
26
38
|
.describe('Set the property when the subject moves; omit for changes over time.') }),
|
|
27
|
-
z.object({ kind: z.literal('trigger'), propertyId: property, threshold: z.number().finite().describe('Value the property must cross.'),
|
|
28
|
-
direction: z.enum(['at-least', 'at-most']).describe('Whether it fires rising to or falling to the threshold.'), intent: scheduleIntentSchema.describe('What happens when it fires.'),
|
|
29
|
-
delayMinutes: z.number().int().min(1).describe('Minutes from crossing to the happening.'), minImportance: z.number().int().min(1).max(10).optional().describe('Least importance of the happening.') }),
|
|
30
|
-
z.object({ kind: z.literal('gate'), propertyId: property, subjectPropertyId: subject, atLeast: levelSchema.optional().describe('Lowest level at which the gate holds.'),
|
|
31
|
-
blockedActionKinds: z.array(id).describe('Action kinds the subject cannot take while it holds.') }),
|
|
32
|
-
z.object({ kind: z.literal('norm'), actionKind: id.describe('Action kind the norm covers.'), roleId: role.nullable().describe('Role it applies to; null for everyone.'), forbidden: z.boolean().describe('Whether the act is forbidden.') }),
|
|
33
|
-
z.object({ kind: z.literal('authority'), roleId: role.describe('Role granted the right.'), relationId: relation.nullable().describe('Relation the role may change; null when it grants a property.'),
|
|
34
|
-
propertyId: property.nullable().describe('Property the role may change; null when it grants a relation.') }),
|
|
35
39
|
]);
|
|
36
40
|
export const kindDefinitionSchema = z.object({
|
|
37
41
|
id: id.describe('Stable id of the requested reusable kind.'),
|
|
@@ -40,6 +44,9 @@ export const kindDefinitionSchema = z.object({
|
|
|
40
44
|
properties: z.array(propertyDefinitionSchema).describe('Typed flags, levels, numbers, text or entity ids. Mark essential ones requiredOnCreate.'),
|
|
41
45
|
relations: z.array(relationDefinitionSchema).describe('Directed links to kinds in scope.'),
|
|
42
46
|
mechanics: z.array(mechanicSchema).describe('Automatic state changes and constraints this kind needs; else empty.'),
|
|
47
|
+
laws: z.array(lawSchema).optional().describe(phrase('schema.description.178')),
|
|
48
|
+
library: z.boolean().optional().describe(phrase('schema.description.179')),
|
|
49
|
+
neverHeld: z.boolean().optional().describe(phrase('schema.description.180')),
|
|
43
50
|
});
|
|
44
51
|
export const kindRequestSchema = z.object({ id, name: text, meaning: text });
|
|
45
52
|
export const slotSchema = z.object({
|
|
@@ -59,11 +66,7 @@ export const entitySchema = z.object({
|
|
|
59
66
|
id,
|
|
60
67
|
kindId: id,
|
|
61
68
|
name: text,
|
|
62
|
-
|
|
63
|
-
// Last text each reader perceived survives unseen edits and erasure.
|
|
64
|
-
paperViews: z.record(id, z.object({ name: text, words: z.string().nullable() })).optional(),
|
|
65
|
-
// A thing that is somewhere can be held; it then goes wherever its holder goes.
|
|
66
|
-
holderId: id.nullable().default(null),
|
|
69
|
+
containerId: id.nullable().default(null),
|
|
67
70
|
// What anyone who sees it can tell of its state, such as torn or burned; null while unremarkable.
|
|
68
71
|
condition: z.string().min(1).max(200).nullable().default(null),
|
|
69
72
|
// Each named side of the condition, in the order first set; the condition line shows them all.
|
|
@@ -72,12 +75,6 @@ export const entitySchema = z.object({
|
|
|
72
75
|
sideOrder: z.array(z.string().min(1).max(40)).max(5).optional(),
|
|
73
76
|
// A thing the world's data hides, which no one who comes to its place sees.
|
|
74
77
|
hidden: z.literal(true).optional(),
|
|
75
|
-
// A decision's members, the vote each has cast, its result once counted, and the problem it settles.
|
|
76
|
-
members: z.array(id).optional(),
|
|
77
|
-
ballots: z.record(id, z.enum(['yes', 'no', 'abstain'])).optional(),
|
|
78
|
-
result: z.enum(['passed', 'failed', 'lapsed']).optional(),
|
|
79
|
-
settles: id.optional(),
|
|
80
|
-
transfers: z.array(z.object({ fromId: id.nullable(), toId: id.nullable(), amount: z.number().positive() })).optional(),
|
|
81
78
|
properties: z.record(id, slotSchema),
|
|
82
79
|
relations: z.record(id, relationSlotSchema),
|
|
83
80
|
introducedSeq: z.number().int().min(1),
|
|
@@ -98,5 +95,129 @@ export function valueMatchesType(type, value) {
|
|
|
98
95
|
case 'time': return typeof value === 'number' && Number.isInteger(value) && value >= 0;
|
|
99
96
|
case 'id': return typeof value === 'string' && id.safeParse(value).success;
|
|
100
97
|
case 'text': return typeof value === 'string';
|
|
98
|
+
case 'series': return Array.isArray(value) && value.every(entry => seriesEntrySchema.safeParse(entry).success);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
export function lawProblems(law, definition) {
|
|
102
|
+
const problems = [];
|
|
103
|
+
const properties = definition.properties;
|
|
104
|
+
const typeOf = (id) => properties.find(property => property.id === id)?.type;
|
|
105
|
+
const relations = new Set(definition.relations.map(relation => relation.id));
|
|
106
|
+
const slotProblem = (slot, need) => {
|
|
107
|
+
const type = typeOf(slot);
|
|
108
|
+
if (type === undefined)
|
|
109
|
+
problems.push(`law rule names unknown property ${slot}`);
|
|
110
|
+
else if (need !== undefined && type !== need)
|
|
111
|
+
problems.push(`law rule on ${slot}: it must be a ${need} property, not ${type}`);
|
|
112
|
+
};
|
|
113
|
+
const relationProblem = (relation) => { if (!relations.has(relation))
|
|
114
|
+
problems.push(`law rule names unknown relation ${relation}`); };
|
|
115
|
+
function walkTerm(term) {
|
|
116
|
+
const value = term;
|
|
117
|
+
if (value.slot !== undefined)
|
|
118
|
+
slotProblem(value.slot);
|
|
119
|
+
if (value.count !== undefined)
|
|
120
|
+
slotProblem(value.count.slot);
|
|
121
|
+
if (value.size !== undefined)
|
|
122
|
+
slotProblem(value.size.slot);
|
|
123
|
+
}
|
|
124
|
+
function walkCondition(condition) {
|
|
125
|
+
switch (condition.op) {
|
|
126
|
+
case 'on':
|
|
127
|
+
case 'present':
|
|
128
|
+
case 'holds':
|
|
129
|
+
case 'wrote':
|
|
130
|
+
case 'names':
|
|
131
|
+
slotProblem(condition.slot);
|
|
132
|
+
break;
|
|
133
|
+
case 'crossed':
|
|
134
|
+
slotProblem(condition.slot, 'number');
|
|
135
|
+
break;
|
|
136
|
+
case 'linked':
|
|
137
|
+
relationProblem(condition.relation);
|
|
138
|
+
break;
|
|
139
|
+
case 'beside':
|
|
140
|
+
walkTerm(condition.other);
|
|
141
|
+
break;
|
|
142
|
+
case 'allOf':
|
|
143
|
+
case 'anyOf':
|
|
144
|
+
condition.of.forEach(walkCondition);
|
|
145
|
+
break;
|
|
146
|
+
case 'not':
|
|
147
|
+
walkCondition(condition.of);
|
|
148
|
+
break;
|
|
149
|
+
default: break;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
const cue = law.on;
|
|
153
|
+
if (cue.changed !== undefined && typeOf(cue.changed) === undefined && !relations.has(cue.changed))
|
|
154
|
+
problems.push(`law rule names unknown property ${cue.changed}`);
|
|
155
|
+
if (cue.added !== undefined)
|
|
156
|
+
slotProblem(cue.added);
|
|
157
|
+
if (law.when !== undefined)
|
|
158
|
+
walkCondition(law.when);
|
|
159
|
+
if (law.kind === 'react')
|
|
160
|
+
for (const action of law.do) {
|
|
161
|
+
if (action.op === 'set') {
|
|
162
|
+
slotProblem(action.slot);
|
|
163
|
+
walkTerm(action.value);
|
|
164
|
+
}
|
|
165
|
+
if (action.op === 'add') {
|
|
166
|
+
slotProblem(action.slot);
|
|
167
|
+
walkTerm(action.option);
|
|
168
|
+
}
|
|
169
|
+
if (action.op === 'shift') {
|
|
170
|
+
walkTerm(action.slot);
|
|
171
|
+
walkTerm(action.from);
|
|
172
|
+
walkTerm(action.to);
|
|
173
|
+
walkTerm(action.amount);
|
|
174
|
+
}
|
|
175
|
+
if (action.op === 'link') {
|
|
176
|
+
relationProblem(action.relation);
|
|
177
|
+
walkTerm(action.target);
|
|
178
|
+
}
|
|
179
|
+
if (action.op === 'settle')
|
|
180
|
+
walkTerm(action.tension);
|
|
181
|
+
}
|
|
182
|
+
return problems;
|
|
183
|
+
}
|
|
184
|
+
export function narrowsKindRevision(previous, next) {
|
|
185
|
+
if (previous.id !== next.id)
|
|
186
|
+
return true;
|
|
187
|
+
const nextProperties = new Map();
|
|
188
|
+
for (const property of next.properties)
|
|
189
|
+
nextProperties.set(property.id, property);
|
|
190
|
+
for (const property of previous.properties) {
|
|
191
|
+
const kept = nextProperties.get(property.id);
|
|
192
|
+
if (kept === undefined)
|
|
193
|
+
return true;
|
|
194
|
+
if (kept.type !== property.type)
|
|
195
|
+
return true;
|
|
196
|
+
for (const option of property.options ?? [])
|
|
197
|
+
if (!(kept.options ?? []).includes(option))
|
|
198
|
+
return true;
|
|
199
|
+
if (property.requiredOnCreate === true && kept.requiredOnCreate !== true)
|
|
200
|
+
return true;
|
|
201
|
+
if (property.perActor === true && kept.perActor !== true)
|
|
202
|
+
return true;
|
|
203
|
+
if (property.target === 'tension' && kept.target !== 'tension')
|
|
204
|
+
return true;
|
|
205
|
+
if (property.sealedBy !== undefined && kept.sealedBy !== property.sealedBy)
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
const nextRelations = new Map(next.relations.map(relation => [relation.id, relation]));
|
|
209
|
+
for (const relation of previous.relations) {
|
|
210
|
+
const kept = nextRelations.get(relation.id);
|
|
211
|
+
if (kept === undefined || kept.targetKindId !== relation.targetKindId)
|
|
212
|
+
return true;
|
|
101
213
|
}
|
|
214
|
+
const nextMechanics = new Set(next.mechanics.map(mechanic => JSON.stringify(mechanic)));
|
|
215
|
+
for (const mechanic of previous.mechanics)
|
|
216
|
+
if (!nextMechanics.has(JSON.stringify(mechanic)))
|
|
217
|
+
return true;
|
|
218
|
+
const nextLaws = new Set((next.laws ?? []).map(law => JSON.stringify(law)));
|
|
219
|
+
for (const law of previous.laws ?? [])
|
|
220
|
+
if (!nextLaws.has(JSON.stringify(law)))
|
|
221
|
+
return true;
|
|
222
|
+
return false;
|
|
102
223
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import TABLE_JSON from './phrases.json' with { type: 'json' };
|
|
2
|
+
const TABLE = TABLE_JSON;
|
|
3
|
+
const OPEN = 123;
|
|
4
|
+
const CLOSE = 125;
|
|
5
|
+
function fill(template, id, slots) {
|
|
6
|
+
let out = '';
|
|
7
|
+
let index = 0;
|
|
8
|
+
while (index < template.length) {
|
|
9
|
+
if (template.charCodeAt(index) !== OPEN) {
|
|
10
|
+
out += template.charAt(index);
|
|
11
|
+
index += 1;
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
let name = '';
|
|
15
|
+
index += 1;
|
|
16
|
+
while (index < template.length && template.charCodeAt(index) !== CLOSE) {
|
|
17
|
+
name += template.charAt(index);
|
|
18
|
+
index += 1;
|
|
19
|
+
}
|
|
20
|
+
if (index === template.length)
|
|
21
|
+
throw new Error(`Phrase ${id} has a slot with no end`);
|
|
22
|
+
index += 1;
|
|
23
|
+
if (name.length === 0)
|
|
24
|
+
throw new Error(`Phrase ${id} has a slot with no name`);
|
|
25
|
+
const value = slots[name];
|
|
26
|
+
if (value === undefined)
|
|
27
|
+
throw new Error(`Phrase ${id} needs slot ${name}`);
|
|
28
|
+
out += String(value);
|
|
29
|
+
}
|
|
30
|
+
return out;
|
|
31
|
+
}
|
|
32
|
+
export function phrase(id, slots = {}) {
|
|
33
|
+
const template = TABLE[id];
|
|
34
|
+
if (template === undefined)
|
|
35
|
+
throw new Error(`Unknown phrase ${id}`);
|
|
36
|
+
return fill(template, id, slots);
|
|
37
|
+
}
|