@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
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { applyLivingEvent } from './reduce.js';
|
|
2
|
+
export type ProseContradiction = {
|
|
3
|
+
entityId: string;
|
|
4
|
+
entityName: string;
|
|
5
|
+
propertyId: string;
|
|
6
|
+
label: string;
|
|
7
|
+
saysTrue: boolean;
|
|
8
|
+
actual: boolean;
|
|
9
|
+
};
|
|
10
|
+
type State = Parameters<typeof applyLivingEvent>[0];
|
|
11
|
+
export declare function wordsOf(text: string): string[];
|
|
12
|
+
export declare function unknownNames(state: Parameters<typeof applyLivingEvent>[0], personId: string, text: string): string[];
|
|
13
|
+
export declare function proseContradictions(state: State, texts: readonly (string | null | undefined)[]): ProseContradiction[];
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { phrase } from './phrases.js';
|
|
2
|
+
import { personKnowledgeSources } from './knowledge.js';
|
|
3
|
+
import { entitiesHere, objectsHere } from './space.js';
|
|
4
|
+
const ARTICLES = wordsOf(phrase('contradiction.articles'));
|
|
5
|
+
const PRONOUNS = wordsOf(phrase('contradiction.pronouns'));
|
|
6
|
+
const LINKING = wordsOf(phrase('contradiction.linking'));
|
|
7
|
+
const FILLERS = wordsOf(phrase('contradiction.fillers'));
|
|
8
|
+
const NEGATIONS = wordsOf(phrase('contradiction.negations'));
|
|
9
|
+
const NEGATION_MORE = wordsOf(phrase('contradiction.negationMore'));
|
|
10
|
+
const NEGATIVE_WORDS = wordsOf(phrase('contradiction.negativeWords'));
|
|
11
|
+
const NEGATIVE_PREFIX = phrase('contradiction.negativePrefix');
|
|
12
|
+
function wordChar(code, dash = false) {
|
|
13
|
+
return (code >= 97 && code <= 122) || (code >= 48 && code <= 57) || code === 39 || dash;
|
|
14
|
+
}
|
|
15
|
+
export function wordsOf(text) {
|
|
16
|
+
const out = [];
|
|
17
|
+
let word = '';
|
|
18
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
19
|
+
const code = text.charCodeAt(index);
|
|
20
|
+
const lower = code >= 65 && code <= 90 ? code + 32 : code;
|
|
21
|
+
if (wordChar(lower))
|
|
22
|
+
word += String.fromCharCode(lower);
|
|
23
|
+
else if (word.length !== 0) {
|
|
24
|
+
out.push(word);
|
|
25
|
+
word = '';
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (word.length !== 0)
|
|
29
|
+
out.push(word);
|
|
30
|
+
return out;
|
|
31
|
+
}
|
|
32
|
+
function sentencesOf(text) {
|
|
33
|
+
const out = [];
|
|
34
|
+
let words = [];
|
|
35
|
+
let word = '';
|
|
36
|
+
let quote = 0;
|
|
37
|
+
let previous = 0;
|
|
38
|
+
const flushWord = () => { if (word.length !== 0) {
|
|
39
|
+
words.push(word);
|
|
40
|
+
word = '';
|
|
41
|
+
} };
|
|
42
|
+
const flushSentence = () => { flushWord(); if (words.length > 0)
|
|
43
|
+
out.push(words); words = []; };
|
|
44
|
+
for (let index = 0; index < text.length; index += 1) {
|
|
45
|
+
const code = text.charCodeAt(index);
|
|
46
|
+
const lower = code >= 65 && code <= 90 ? code + 32 : code;
|
|
47
|
+
if (quote !== 0) {
|
|
48
|
+
if (code === quote)
|
|
49
|
+
quote = 0;
|
|
50
|
+
previous = code;
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const opening = code === 34 ? 34 : code === 8220 ? 8221 : code === 8216 ? 8217 : code === 39 && !wordChar(previous) && previous !== 39 ? 39 : 0;
|
|
54
|
+
if (opening !== 0) {
|
|
55
|
+
quote = opening;
|
|
56
|
+
flushWord();
|
|
57
|
+
previous = code;
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (wordChar(lower))
|
|
61
|
+
word += String.fromCharCode(lower);
|
|
62
|
+
else {
|
|
63
|
+
flushWord();
|
|
64
|
+
if (code === 46 || code === 33 || code === 63 || code === 59 || code === 10)
|
|
65
|
+
flushSentence();
|
|
66
|
+
}
|
|
67
|
+
previous = code;
|
|
68
|
+
}
|
|
69
|
+
flushSentence();
|
|
70
|
+
return out;
|
|
71
|
+
}
|
|
72
|
+
function isIn(word, list) {
|
|
73
|
+
for (const item of list)
|
|
74
|
+
if (word === item)
|
|
75
|
+
return true;
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
function matchesAt(tokens, words, at) {
|
|
79
|
+
if (words.length === 0 || at + words.length > tokens.length)
|
|
80
|
+
return false;
|
|
81
|
+
for (let index = 0; index < words.length; index += 1)
|
|
82
|
+
if (tokens[at + index] !== words[index])
|
|
83
|
+
return false;
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
function containsWords(tokens, words) {
|
|
87
|
+
for (let at = 0; at + words.length <= tokens.length; at += 1)
|
|
88
|
+
if (matchesAt(tokens, words, at))
|
|
89
|
+
return true;
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
export function unknownNames(state, personId, text) {
|
|
93
|
+
const person = state.people[personId];
|
|
94
|
+
if (person === undefined)
|
|
95
|
+
return [];
|
|
96
|
+
const knownPeople = new Set([personId, ...personKnowledgeSources(state, person).keys()]);
|
|
97
|
+
const knownPlaces = new Set([person.placeId, ...(state.places[person.placeId]?.connections ?? []), ...(person.knownPlaceIds ?? [])]);
|
|
98
|
+
for (const memory of person.memories)
|
|
99
|
+
if (memory.placeId !== null)
|
|
100
|
+
knownPlaces.add(memory.placeId);
|
|
101
|
+
const knownObjects = new Set();
|
|
102
|
+
for (const id of objectsHere(state, person.placeId)) {
|
|
103
|
+
const object = state.objects[id];
|
|
104
|
+
if (!object.hidden || object.containerId === personId || object.custodyKnownTo.includes(personId))
|
|
105
|
+
knownObjects.add(id);
|
|
106
|
+
}
|
|
107
|
+
for (const object of Object.values(state.objects)) {
|
|
108
|
+
if (object.ownerId === personId || object.custodyKnownTo.includes(personId))
|
|
109
|
+
knownObjects.add(object.id);
|
|
110
|
+
}
|
|
111
|
+
const knownEntities = new Set();
|
|
112
|
+
for (const id of entitiesHere(state, person.placeId)) {
|
|
113
|
+
const entity = state.entities[id];
|
|
114
|
+
if (!entity.hidden || entity.knownTo.includes(personId))
|
|
115
|
+
knownEntities.add(id);
|
|
116
|
+
}
|
|
117
|
+
for (const entity of Object.values(state.entities)) {
|
|
118
|
+
if (entity.knownTo.includes(personId))
|
|
119
|
+
knownEntities.add(entity.id);
|
|
120
|
+
}
|
|
121
|
+
const words = wordsOf(text);
|
|
122
|
+
const hidden = [];
|
|
123
|
+
for (const other of Object.values(state.people)) {
|
|
124
|
+
if (knownPeople.has(other.id))
|
|
125
|
+
continue;
|
|
126
|
+
if (containsWords(words, wordsOf(other.name)))
|
|
127
|
+
hidden.push(other.name);
|
|
128
|
+
}
|
|
129
|
+
for (const object of Object.values(state.objects)) {
|
|
130
|
+
if (knownObjects.has(object.id))
|
|
131
|
+
continue;
|
|
132
|
+
if (containsWords(words, wordsOf(object.name)))
|
|
133
|
+
hidden.push(object.name);
|
|
134
|
+
}
|
|
135
|
+
for (const entity of Object.values(state.entities)) {
|
|
136
|
+
if (knownEntities.has(entity.id))
|
|
137
|
+
continue;
|
|
138
|
+
if (containsWords(words, wordsOf(entity.name)))
|
|
139
|
+
hidden.push(entity.name);
|
|
140
|
+
}
|
|
141
|
+
for (const place of Object.values(state.places)) {
|
|
142
|
+
if (knownPlaces.has(place.id))
|
|
143
|
+
continue;
|
|
144
|
+
if (containsWords(words, wordsOf(place.name)))
|
|
145
|
+
hidden.push(place.name);
|
|
146
|
+
}
|
|
147
|
+
return hidden;
|
|
148
|
+
}
|
|
149
|
+
function negativeClaim(tokens, words) {
|
|
150
|
+
for (let index = 0; index < tokens.length; index += 1) {
|
|
151
|
+
const token = tokens[index];
|
|
152
|
+
let next = -1;
|
|
153
|
+
if (isIn(token, NEGATIONS) || isIn(token, NEGATIVE_WORDS))
|
|
154
|
+
next = index + 1;
|
|
155
|
+
else if (words.length === 1 && token.length > NEGATIVE_PREFIX.length) {
|
|
156
|
+
let prefix = true;
|
|
157
|
+
for (let offset = 0; offset < NEGATIVE_PREFIX.length; offset += 1)
|
|
158
|
+
if (token.charCodeAt(offset) !== NEGATIVE_PREFIX.charCodeAt(offset)) {
|
|
159
|
+
prefix = false;
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
if (prefix && sameText(token.slice(NEGATIVE_PREFIX.length), words[0]))
|
|
163
|
+
return true;
|
|
164
|
+
}
|
|
165
|
+
if (next === -1)
|
|
166
|
+
continue;
|
|
167
|
+
while (next < tokens.length && isIn(tokens[next], NEGATION_MORE))
|
|
168
|
+
next += 1;
|
|
169
|
+
if (matchesAt(tokens, words, next))
|
|
170
|
+
return true;
|
|
171
|
+
}
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
function sameText(left, right) {
|
|
175
|
+
if (left.length !== right.length)
|
|
176
|
+
return false;
|
|
177
|
+
for (let index = 0; index < left.length; index += 1)
|
|
178
|
+
if (left.charCodeAt(index) !== right.charCodeAt(index))
|
|
179
|
+
return false;
|
|
180
|
+
return true;
|
|
181
|
+
}
|
|
182
|
+
function sameWords(left, right) {
|
|
183
|
+
if (left.length !== right.length)
|
|
184
|
+
return false;
|
|
185
|
+
for (let index = 0; index < left.length; index += 1)
|
|
186
|
+
if (left[index] !== right[index])
|
|
187
|
+
return false;
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
190
|
+
function cellsOf(state) {
|
|
191
|
+
const out = [];
|
|
192
|
+
for (const entity of Object.values(state.entities)) {
|
|
193
|
+
const kind = state.kinds[entity.kindId];
|
|
194
|
+
if (kind === undefined)
|
|
195
|
+
continue;
|
|
196
|
+
const words = wordsOf(entity.name);
|
|
197
|
+
if (words.length === 0)
|
|
198
|
+
continue;
|
|
199
|
+
const cells = [];
|
|
200
|
+
const flags = [];
|
|
201
|
+
for (const property of kind.properties) {
|
|
202
|
+
if (property.type !== 'flag')
|
|
203
|
+
continue;
|
|
204
|
+
const slot = entity.properties[property.id];
|
|
205
|
+
const labelWords = wordsOf(property.id);
|
|
206
|
+
flags.push(labelWords);
|
|
207
|
+
cells.push({ propertyId: property.id, label: property.id, words: labelWords, truth: slot !== undefined && slot.value === true });
|
|
208
|
+
}
|
|
209
|
+
for (const property of kind.properties) {
|
|
210
|
+
if (property.type !== 'series' || property.options === undefined)
|
|
211
|
+
continue;
|
|
212
|
+
const slot = entity.properties[property.id];
|
|
213
|
+
const entries = slot !== undefined && Array.isArray(slot.value) ? slot.value : [];
|
|
214
|
+
for (const option of property.options) {
|
|
215
|
+
const labelWords = wordsOf(option);
|
|
216
|
+
let flagged = false;
|
|
217
|
+
for (const flag of flags)
|
|
218
|
+
if (sameWords(flag, labelWords)) {
|
|
219
|
+
flagged = true;
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
if (flagged)
|
|
223
|
+
continue;
|
|
224
|
+
let truth = false;
|
|
225
|
+
for (const entry of entries)
|
|
226
|
+
if (entry.option === option) {
|
|
227
|
+
truth = true;
|
|
228
|
+
break;
|
|
229
|
+
}
|
|
230
|
+
cells.push({ propertyId: property.id, label: option, words: labelWords, truth });
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
out.push({ id: entity.id, name: entity.name, words, cells });
|
|
234
|
+
}
|
|
235
|
+
return out;
|
|
236
|
+
}
|
|
237
|
+
function subjectOf(sentence, carried, entities) {
|
|
238
|
+
if (sentence.length === 0)
|
|
239
|
+
return undefined;
|
|
240
|
+
if (isIn(sentence[0], PRONOUNS))
|
|
241
|
+
return carried;
|
|
242
|
+
const start = isIn(sentence[0], ARTICLES) ? 1 : 0;
|
|
243
|
+
let found;
|
|
244
|
+
let longest = 0;
|
|
245
|
+
for (const entity of entities) {
|
|
246
|
+
if (entity.words.length <= longest)
|
|
247
|
+
continue;
|
|
248
|
+
if (!matchesAt(sentence, entity.words, start))
|
|
249
|
+
continue;
|
|
250
|
+
let next = start + entity.words.length;
|
|
251
|
+
while (next < sentence.length && isIn(sentence[next], FILLERS))
|
|
252
|
+
next += 1;
|
|
253
|
+
if (next < sentence.length && isIn(sentence[next], LINKING)) {
|
|
254
|
+
found = entity;
|
|
255
|
+
longest = entity.words.length;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return found;
|
|
259
|
+
}
|
|
260
|
+
export function proseContradictions(state, texts) {
|
|
261
|
+
const found = [];
|
|
262
|
+
const entities = cellsOf(state);
|
|
263
|
+
for (const text of texts) {
|
|
264
|
+
if (typeof text !== 'string' || text.length === 0)
|
|
265
|
+
continue;
|
|
266
|
+
let subject;
|
|
267
|
+
for (const sentence of sentencesOf(text)) {
|
|
268
|
+
const named = subjectOf(sentence, subject, entities);
|
|
269
|
+
if (named !== undefined)
|
|
270
|
+
subject = named;
|
|
271
|
+
if (named === undefined)
|
|
272
|
+
continue;
|
|
273
|
+
for (const cell of named.cells) {
|
|
274
|
+
const said = negativeClaim(sentence, cell.words) ? false : containsWords(sentence, cell.words) ? true : null;
|
|
275
|
+
if (said === null || said === cell.truth)
|
|
276
|
+
continue;
|
|
277
|
+
found.push({ entityId: named.id, entityName: named.name, propertyId: cell.propertyId, label: cell.label, saysTrue: said, actual: cell.truth });
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return found;
|
|
282
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
declare const space: unique symbol;
|
|
2
|
+
declare const measure: unique symbol;
|
|
3
|
+
export type Handle<Space extends string> = {
|
|
4
|
+
readonly [space]: Space;
|
|
5
|
+
};
|
|
6
|
+
export type KindId = Handle<'kind'>;
|
|
7
|
+
export type SlotId = Handle<'slot'>;
|
|
8
|
+
export type PropertyId = Handle<'property'>;
|
|
9
|
+
export type RelationId = Handle<'relation'>;
|
|
10
|
+
export type FacetId = Handle<'facet'>;
|
|
11
|
+
export type ChannelId = Handle<'channel'>;
|
|
12
|
+
export type UnitId = Handle<'unit'>;
|
|
13
|
+
export type OptionId = Handle<'option'>;
|
|
14
|
+
export type EntityId = Handle<'entity'>;
|
|
15
|
+
export type PersonId = Handle<'person'>;
|
|
16
|
+
export type PlaceId = Handle<'place'>;
|
|
17
|
+
export type LawId = Handle<'law'>;
|
|
18
|
+
declare const tableKey: unique symbol;
|
|
19
|
+
export type Table<K, V> = {
|
|
20
|
+
readonly [key: string]: V;
|
|
21
|
+
} & {
|
|
22
|
+
readonly [tableKey]?: K;
|
|
23
|
+
};
|
|
24
|
+
export type CellTable<K, V> = {
|
|
25
|
+
get(key: K): V | undefined;
|
|
26
|
+
has(key: K): boolean;
|
|
27
|
+
entries(): [K, V][];
|
|
28
|
+
};
|
|
29
|
+
export type Prose = {
|
|
30
|
+
readonly [space]: 'prose';
|
|
31
|
+
};
|
|
32
|
+
export type Seq = {
|
|
33
|
+
readonly [measure]: 'seq';
|
|
34
|
+
};
|
|
35
|
+
export type Tick = {
|
|
36
|
+
readonly [measure]: 'tick';
|
|
37
|
+
};
|
|
38
|
+
export type Minutes = {
|
|
39
|
+
readonly [measure]: 'minutes';
|
|
40
|
+
};
|
|
41
|
+
export declare function handle<Space extends string>(raw: string): Handle<Space>;
|
|
42
|
+
export declare function prose(raw: string): Prose;
|
|
43
|
+
export declare function seq(value: number): Seq;
|
|
44
|
+
export declare function tick(value: number): Tick;
|
|
45
|
+
export declare function minutes(value: number): Minutes;
|
|
46
|
+
export declare function spell(word: Handle<string> | Prose): string;
|
|
47
|
+
export declare function count(value: Seq | Tick | Minutes): number;
|
|
48
|
+
export declare function addMinutes(left: Minutes, right: Minutes): Minutes;
|
|
49
|
+
export declare function subtractMinutes(left: Minutes, right: Minutes): Minutes;
|
|
50
|
+
export declare function compareMinutes(left: Minutes, right: Minutes): number;
|
|
51
|
+
export declare function chars(text: Prose): number;
|
|
52
|
+
export declare function excerpt(text: Prose, maxChars: number): Prose;
|
|
53
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export function handle(raw) {
|
|
2
|
+
return raw;
|
|
3
|
+
}
|
|
4
|
+
export function prose(raw) {
|
|
5
|
+
return raw;
|
|
6
|
+
}
|
|
7
|
+
export function seq(value) {
|
|
8
|
+
return value;
|
|
9
|
+
}
|
|
10
|
+
export function tick(value) {
|
|
11
|
+
return value;
|
|
12
|
+
}
|
|
13
|
+
export function minutes(value) {
|
|
14
|
+
return value;
|
|
15
|
+
}
|
|
16
|
+
export function spell(word) {
|
|
17
|
+
return word;
|
|
18
|
+
}
|
|
19
|
+
export function count(value) {
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
22
|
+
export function addMinutes(left, right) {
|
|
23
|
+
return minutes(count(left) + count(right));
|
|
24
|
+
}
|
|
25
|
+
export function subtractMinutes(left, right) {
|
|
26
|
+
return minutes(count(left) - count(right));
|
|
27
|
+
}
|
|
28
|
+
export function compareMinutes(left, right) {
|
|
29
|
+
return count(left) - count(right);
|
|
30
|
+
}
|
|
31
|
+
export function chars(text) {
|
|
32
|
+
return text.length;
|
|
33
|
+
}
|
|
34
|
+
export function excerpt(text, maxChars) {
|
|
35
|
+
const raw = text;
|
|
36
|
+
if (raw.length <= maxChars)
|
|
37
|
+
return text;
|
|
38
|
+
return prose(`${raw.slice(0, Math.max(0, maxChars - 1))}…`);
|
|
39
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { KindId, OptionId, Prose, SlotId } from './ids.js';
|
|
2
|
+
export type SlotType = 'flag' | 'level' | 'number' | 'time' | 'id' | 'text' | 'series';
|
|
3
|
+
export type SlotDef = {
|
|
4
|
+
id: SlotId;
|
|
5
|
+
type: SlotType;
|
|
6
|
+
options?: readonly OptionId[];
|
|
7
|
+
perActor?: boolean;
|
|
8
|
+
sealedBy?: SlotId;
|
|
9
|
+
requiredOnCreate?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export type KindDef = {
|
|
12
|
+
id: KindId;
|
|
13
|
+
name: Prose;
|
|
14
|
+
slots: readonly SlotDef[];
|
|
15
|
+
};
|
|
16
|
+
export declare function slotOf(kind: KindDef, id: SlotId): SlotDef | undefined;
|
|
17
|
+
export declare function writable(slot: SlotDef): boolean;
|
|
18
|
+
export declare function seriesSlots(kind: KindDef): readonly SlotDef[];
|
|
19
|
+
export declare function writerSlot(kind: KindDef): SlotDef | undefined;
|
|
20
|
+
export declare function optionAllowed(slot: SlotDef, option: OptionId): boolean;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export function slotOf(kind, id) {
|
|
2
|
+
return kind.slots.find(slot => slot.id === id);
|
|
3
|
+
}
|
|
4
|
+
export function writable(slot) {
|
|
5
|
+
return slot.type !== 'series' && slot.perActor !== true;
|
|
6
|
+
}
|
|
7
|
+
export function seriesSlots(kind) {
|
|
8
|
+
return kind.slots.filter(slot => slot.type === 'series');
|
|
9
|
+
}
|
|
10
|
+
export function writerSlot(kind) {
|
|
11
|
+
return kind.slots.find(slot => slot.perActor === true);
|
|
12
|
+
}
|
|
13
|
+
export function optionAllowed(slot, option) {
|
|
14
|
+
return slot.options === undefined || slot.options.some(candidate => candidate === option);
|
|
15
|
+
}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export type Subject = 'self' | 'actor' | 'target';
|
|
3
|
+
export type Term = {
|
|
4
|
+
value: boolean | number | string | null;
|
|
5
|
+
} | {
|
|
6
|
+
slot: string;
|
|
7
|
+
of?: Subject;
|
|
8
|
+
} | {
|
|
9
|
+
count: {
|
|
10
|
+
slot: string;
|
|
11
|
+
equals?: string;
|
|
12
|
+
of?: Subject;
|
|
13
|
+
};
|
|
14
|
+
} | {
|
|
15
|
+
size: {
|
|
16
|
+
slot: string;
|
|
17
|
+
of?: Subject;
|
|
18
|
+
};
|
|
19
|
+
} | {
|
|
20
|
+
actor: true;
|
|
21
|
+
} | {
|
|
22
|
+
now: true;
|
|
23
|
+
};
|
|
24
|
+
export type Condition = {
|
|
25
|
+
op: 'eq' | 'ne' | 'gte' | 'lte' | 'gt' | 'lt';
|
|
26
|
+
left: Term;
|
|
27
|
+
right: Term;
|
|
28
|
+
} | {
|
|
29
|
+
op: 'holds';
|
|
30
|
+
subject: Subject;
|
|
31
|
+
slot: string;
|
|
32
|
+
value: Term;
|
|
33
|
+
} | {
|
|
34
|
+
op: 'present';
|
|
35
|
+
subject: Subject;
|
|
36
|
+
slot: string;
|
|
37
|
+
} | {
|
|
38
|
+
op: 'on';
|
|
39
|
+
subject: Subject;
|
|
40
|
+
slot: string;
|
|
41
|
+
} | {
|
|
42
|
+
op: 'wrote';
|
|
43
|
+
subject: Subject;
|
|
44
|
+
slot: string;
|
|
45
|
+
person: Subject;
|
|
46
|
+
} | {
|
|
47
|
+
op: 'names';
|
|
48
|
+
subject: Subject;
|
|
49
|
+
slot: string;
|
|
50
|
+
target: Subject;
|
|
51
|
+
} | {
|
|
52
|
+
op: 'linked';
|
|
53
|
+
subject: Subject;
|
|
54
|
+
relation: string;
|
|
55
|
+
target: Subject;
|
|
56
|
+
} | {
|
|
57
|
+
op: 'crossed';
|
|
58
|
+
slot: string;
|
|
59
|
+
threshold: number;
|
|
60
|
+
direction: 'at-least' | 'at-most';
|
|
61
|
+
of?: Subject;
|
|
62
|
+
} | {
|
|
63
|
+
op: 'role';
|
|
64
|
+
subject: Subject;
|
|
65
|
+
is: string;
|
|
66
|
+
} | {
|
|
67
|
+
op: 'beside';
|
|
68
|
+
subject: Subject;
|
|
69
|
+
other: Term;
|
|
70
|
+
} | {
|
|
71
|
+
op: 'actor';
|
|
72
|
+
} | {
|
|
73
|
+
op: 'allOf';
|
|
74
|
+
of: readonly Condition[];
|
|
75
|
+
} | {
|
|
76
|
+
op: 'anyOf';
|
|
77
|
+
of: readonly Condition[];
|
|
78
|
+
} | {
|
|
79
|
+
op: 'not';
|
|
80
|
+
of: Condition;
|
|
81
|
+
};
|
|
82
|
+
export type Cue = {
|
|
83
|
+
changed: string;
|
|
84
|
+
} | {
|
|
85
|
+
added: string;
|
|
86
|
+
} | {
|
|
87
|
+
created: true;
|
|
88
|
+
} | {
|
|
89
|
+
every: number;
|
|
90
|
+
} | {
|
|
91
|
+
attempted: string | readonly string[];
|
|
92
|
+
};
|
|
93
|
+
export type Action = {
|
|
94
|
+
op: 'set';
|
|
95
|
+
slot: string;
|
|
96
|
+
value: Term;
|
|
97
|
+
} | {
|
|
98
|
+
op: 'add';
|
|
99
|
+
slot: string;
|
|
100
|
+
option: Term;
|
|
101
|
+
person?: Subject;
|
|
102
|
+
} | {
|
|
103
|
+
op: 'shift';
|
|
104
|
+
slot: Term;
|
|
105
|
+
from: Term;
|
|
106
|
+
to: Term;
|
|
107
|
+
amount: Term;
|
|
108
|
+
} | {
|
|
109
|
+
op: 'link';
|
|
110
|
+
relation: string;
|
|
111
|
+
target: Term;
|
|
112
|
+
} | {
|
|
113
|
+
op: 'settle';
|
|
114
|
+
tension: Term;
|
|
115
|
+
} | {
|
|
116
|
+
op: 'happen';
|
|
117
|
+
intent: string;
|
|
118
|
+
delayMinutes: number;
|
|
119
|
+
minImportance?: number;
|
|
120
|
+
} | {
|
|
121
|
+
op: 'violation';
|
|
122
|
+
};
|
|
123
|
+
export type Law = {
|
|
124
|
+
kind: 'react';
|
|
125
|
+
on: Cue;
|
|
126
|
+
when?: Condition;
|
|
127
|
+
do: readonly Action[];
|
|
128
|
+
} | {
|
|
129
|
+
kind: 'forbid';
|
|
130
|
+
on: Cue;
|
|
131
|
+
when?: Condition;
|
|
132
|
+
then: string;
|
|
133
|
+
};
|
|
134
|
+
export declare const lawSchema: z.ZodType<Law>;
|
|
135
|
+
export type SeriesEntry = {
|
|
136
|
+
option: string;
|
|
137
|
+
personId: string;
|
|
138
|
+
at: number;
|
|
139
|
+
seq: number;
|
|
140
|
+
};
|
|
141
|
+
export type LawState = {
|
|
142
|
+
entities: Record<string, {
|
|
143
|
+
kindId: string;
|
|
144
|
+
properties: Record<string, {
|
|
145
|
+
value: unknown;
|
|
146
|
+
} | undefined>;
|
|
147
|
+
relations: Record<string, {
|
|
148
|
+
targetId: string;
|
|
149
|
+
} | undefined>;
|
|
150
|
+
}>;
|
|
151
|
+
kinds: Record<string, {
|
|
152
|
+
properties: readonly {
|
|
153
|
+
id: string;
|
|
154
|
+
type: string;
|
|
155
|
+
}[];
|
|
156
|
+
laws?: readonly Law[];
|
|
157
|
+
}>;
|
|
158
|
+
people: Record<string, {
|
|
159
|
+
placeId: string;
|
|
160
|
+
roleId?: string | null;
|
|
161
|
+
away?: unknown;
|
|
162
|
+
departed?: unknown;
|
|
163
|
+
}>;
|
|
164
|
+
};
|
|
165
|
+
export type LawEnv = {
|
|
166
|
+
self: string;
|
|
167
|
+
actor: string | null;
|
|
168
|
+
target: string | null;
|
|
169
|
+
value: unknown;
|
|
170
|
+
previous?: unknown;
|
|
171
|
+
at: number;
|
|
172
|
+
};
|
|
173
|
+
export declare function subjectId(env: LawEnv, of: Subject): string | null;
|
|
174
|
+
export declare function readSlot(state: LawState, env: LawEnv, slot: string, of: Subject): unknown;
|
|
175
|
+
export declare function evaluateTerm(state: LawState, env: LawEnv, term: Term): unknown;
|
|
176
|
+
export declare function evaluateCondition(state: LawState, env: LawEnv, condition: Condition): boolean;
|
|
177
|
+
export declare function cueMatches(cue: Cue, slot: string): boolean;
|
|
178
|
+
export declare function lawCueSlot(cue: Cue): string | null;
|
|
179
|
+
export declare function attemptedKinds(cue: Cue): string[];
|