@spellkave/sdk 0.0.0-bootstrap → 0.0.0-stage

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 (144) hide show
  1. package/README.md +2 -155
  2. package/package.json +4 -63
  3. package/LICENSE +0 -89
  4. package/src/binding_rows.ts +0 -186
  5. package/src/connection.ts +0 -964
  6. package/src/core/actor.ts +0 -62
  7. package/src/core/actor_control.ts +0 -193
  8. package/src/core/actor_control_query_methods.ts +0 -101
  9. package/src/core/actor_control_reaction_methods.ts +0 -79
  10. package/src/core/actor_control_sense_methods.ts +0 -81
  11. package/src/core/actor_control_source.ts +0 -57
  12. package/src/core/actor_session_methods.ts +0 -226
  13. package/src/core/binding_drift.ts +0 -301
  14. package/src/core/credential.ts +0 -259
  15. package/src/core/driver_control.ts +0 -54
  16. package/src/core/effective_environment_state.ts +0 -71
  17. package/src/core/factored_manipulation_attempt.ts +0 -158
  18. package/src/core/ids.ts +0 -60
  19. package/src/core/interaction/canonical.ts +0 -15
  20. package/src/core/interaction/fingerprint.ts +0 -118
  21. package/src/core/interaction/index.ts +0 -31
  22. package/src/core/interaction/intent.ts +0 -284
  23. package/src/core/interaction/outcome.ts +0 -67
  24. package/src/core/interaction/rejection_ledger.ts +0 -108
  25. package/src/core/kernel_contract.generated.ts +0 -10
  26. package/src/core/log.ts +0 -23
  27. package/src/core/movement.ts +0 -111
  28. package/src/core/node-io.ts +0 -208
  29. package/src/core/paths.ts +0 -220
  30. package/src/core/profile.ts +0 -270
  31. package/src/core/profiles.ts +0 -9
  32. package/src/core/provenance_buffer.ts +0 -102
  33. package/src/core/readers/_helpers.ts +0 -273
  34. package/src/core/readers/action_description.ts +0 -17
  35. package/src/core/readers/action_economy_events.ts +0 -149
  36. package/src/core/readers/actor_body_swaps.ts +0 -62
  37. package/src/core/readers/actor_snapshot.ts +0 -197
  38. package/src/core/readers/actor_states.ts +0 -163
  39. package/src/core/readers/actors_and_bodies.ts +0 -179
  40. package/src/core/readers/affordance_cue.ts +0 -59
  41. package/src/core/readers/affordance_defaults.ts +0 -158
  42. package/src/core/readers/affordance_group_membership.ts +0 -67
  43. package/src/core/readers/affordance_input.ts +0 -129
  44. package/src/core/readers/affordance_reference.ts +0 -41
  45. package/src/core/readers/apply_consequences.ts +0 -54
  46. package/src/core/readers/audience_trace_presentation.ts +0 -62
  47. package/src/core/readers/bounded_collection.ts +0 -29
  48. package/src/core/readers/bundle_definitions.ts +0 -74
  49. package/src/core/readers/bundle_entities.ts +0 -62
  50. package/src/core/readers/co_location.ts +0 -71
  51. package/src/core/readers/combat_session.ts +0 -124
  52. package/src/core/readers/combat_session_active.ts +0 -44
  53. package/src/core/readers/combat_session_feedback.ts +0 -37
  54. package/src/core/readers/combat_session_grid.ts +0 -117
  55. package/src/core/readers/combat_session_roster.ts +0 -98
  56. package/src/core/readers/combat_session_types.ts +0 -51
  57. package/src/core/readers/condition_deltas.ts +0 -53
  58. package/src/core/readers/container_contents.ts +0 -92
  59. package/src/core/readers/dialogue_guide.ts +0 -99
  60. package/src/core/readers/dialogue_prompt_presentation.ts +0 -90
  61. package/src/core/readers/driver_control.ts +0 -64
  62. package/src/core/readers/entity_art.ts +0 -219
  63. package/src/core/readers/entity_containment.ts +0 -119
  64. package/src/core/readers/equipment.ts +0 -99
  65. package/src/core/readers/intervention_windows.ts +0 -136
  66. package/src/core/readers/inventory_query.ts +0 -145
  67. package/src/core/readers/item_detail.ts +0 -198
  68. package/src/core/readers/location_snapshot.ts +0 -216
  69. package/src/core/readers/manifest_apply_provenance.ts +0 -32
  70. package/src/core/readers/manifest_export.ts +0 -81
  71. package/src/core/readers/manipulation_context.ts +0 -475
  72. package/src/core/readers/map_layers.ts +0 -49
  73. package/src/core/readers/metadata_rows.ts +0 -56
  74. package/src/core/readers/object_state.ts +0 -124
  75. package/src/core/readers/observer_knowledge.ts +0 -41
  76. package/src/core/readers/observer_place_knowledge.ts +0 -37
  77. package/src/core/readers/observer_trace_knowledge.ts +0 -45
  78. package/src/core/readers/outcome_template.ts +0 -41
  79. package/src/core/readers/place_topology.ts +0 -109
  80. package/src/core/readers/reaction_options.ts +0 -156
  81. package/src/core/readers/resource_deltas.ts +0 -47
  82. package/src/core/readers/scene.ts +0 -275
  83. package/src/core/readers/seats.ts +0 -33
  84. package/src/core/readers/self.ts +0 -245
  85. package/src/core/readers/self_capabilities.ts +0 -159
  86. package/src/core/readers/self_economy.ts +0 -101
  87. package/src/core/readers/self_economy_budget.ts +0 -93
  88. package/src/core/readers/self_evaluations.ts +0 -128
  89. package/src/core/readers/self_identity.ts +0 -104
  90. package/src/core/readers/sense_context.ts +0 -112
  91. package/src/core/readers/session.ts +0 -207
  92. package/src/core/readers/session_detail.ts +0 -211
  93. package/src/core/readers/session_status.ts +0 -68
  94. package/src/core/readers/spatial_environment_state.ts +0 -74
  95. package/src/core/readers/spatial_niche_attachments.ts +0 -28
  96. package/src/core/readers/substrate_definitions.ts +0 -27
  97. package/src/core/readers/suggest_next_action.ts +0 -72
  98. package/src/core/readers/surface_membership.ts +0 -78
  99. package/src/core/readers/tag_reads.ts +0 -54
  100. package/src/core/readers/trace_query.ts +0 -120
  101. package/src/core/readers/trace_response.ts +0 -80
  102. package/src/core/readers/traces.ts +0 -124
  103. package/src/core/readers/travel_session.ts +0 -88
  104. package/src/core/readers/turn_state.ts +0 -34
  105. package/src/core/readers/world_events.ts +0 -43
  106. package/src/core/readers/world_status.ts +0 -63
  107. package/src/core/reducers/manipulation_args.ts +0 -239
  108. package/src/core/reducers/manipulation_receipt.ts +0 -66
  109. package/src/core/reducers/r_actor_wake_up.ts +0 -32
  110. package/src/core/reducers/r_inscribe_trace.ts +0 -109
  111. package/src/core/reducers/r_manipulate.ts +0 -163
  112. package/src/core/reducers/r_move.ts +0 -155
  113. package/src/core/reducers/r_react.ts +0 -143
  114. package/src/core/reducers/r_release_claim.ts +0 -81
  115. package/src/core/reducers/r_sense.ts +0 -84
  116. package/src/core/reducers/r_session_close.ts +0 -130
  117. package/src/core/reducers/r_session_move.ts +0 -116
  118. package/src/core/reducers/r_session_open.ts +0 -91
  119. package/src/core/reducers/session_lookup.ts +0 -64
  120. package/src/core/reducers/tick.ts +0 -65
  121. package/src/core/reducers/trace_lookup.ts +0 -29
  122. package/src/core/reducers/transport.ts +0 -84
  123. package/src/core/resolve.ts +0 -228
  124. package/src/core/shape_telemetry.ts +0 -146
  125. package/src/core/snapshot_rows.ts +0 -109
  126. package/src/core/tick_cadence.ts +0 -61
  127. package/src/core/types.ts +0 -501
  128. package/src/core/watch_provenance.ts +0 -113
  129. package/src/core/world-contract/classify.ts +0 -38
  130. package/src/core/world-contract/index.ts +0 -12
  131. package/src/core/world-contract/normalise.ts +0 -574
  132. package/src/core/world-contract/runtime.ts +0 -144
  133. package/src/core/world-contract/served.ts +0 -173
  134. package/src/core/world-contract/strict-reducers.ts +0 -14
  135. package/src/core/world-contract/typetext.ts +0 -94
  136. package/src/core/world_time.ts +0 -22
  137. package/src/index.ts +0 -262
  138. package/src/manifest-apply.ts +0 -497
  139. package/src/provenance.ts +0 -568
  140. package/src/reader-manifest.ts +0 -338
  141. package/src/readers.ts +0 -392
  142. package/src/replay.ts +0 -515
  143. package/src/watch-buffer.ts +0 -438
  144. package/src/world-events/builder.ts +0 -1042
@@ -1,129 +0,0 @@
1
- import {
2
- type RequiredTables,
3
- registerReaderManifest,
4
- type SnapshotDb,
5
- } from "../../reader-manifest";
6
- import { asString } from "./_helpers";
7
- import { readMetadataAttachmentRows } from "./metadata_rows";
8
-
9
- export const requiredTables: RequiredTables<
10
- ["public_metadata_attachment", "visible_metadata_attachment"]
11
- > = ["public_metadata_attachment", "visible_metadata_attachment"];
12
- registerReaderManifest({ requiredTables });
13
-
14
- const PUBLIC_AUDIENCE = "public";
15
- const AFFORDANCE_TEMPLATE_TARGET_KIND = "affordance_template";
16
- const AFFORDANCE_INPUT_NAMESPACE = "ui.affordance_input";
17
-
18
- /** A world-authored field in an affordance's input form. The widget choice is
19
- * presentation only; action identity and dispatch remain authored by the
20
- * affordance/action rows. */
21
- export interface AffordanceInputField {
22
- name: string;
23
- label: string;
24
- control: "text" | "textarea" | "number";
25
- placeholder?: string;
26
- required?: boolean;
27
- min?: number;
28
- max?: number;
29
- maxLength?: number;
30
- /** Which PLAYER transport carries the value: `"utterance"` means the
31
- * world reads it from what the actor SAYS (spellkave_communicate's
32
- * utterance; a JSON object or plain text), `"args_json"` means the
33
- * structured argument blob. Absent means the author did not say;
34
- * the tool descriptions apply (sk-jay0.1.46). */
35
- channel?: "utterance" | "args_json";
36
- }
37
-
38
- /** Public, authored input schema for one affordance template. An explicit
39
- * empty `fields` array is meaningful: it says this action takes no form
40
- * input, even if its underlying consequence happens to carry dispatch text. */
41
- export interface AffordanceInputSchema {
42
- fields: readonly AffordanceInputField[];
43
- submitLabel?: string;
44
- }
45
-
46
- function optionalString(value: unknown): string | undefined {
47
- return typeof value === "string" && value.trim() !== "" ? value : undefined;
48
- }
49
-
50
- function optionalFiniteNumber(value: unknown): number | undefined {
51
- return typeof value === "number" && Number.isFinite(value) ? value : undefined;
52
- }
53
-
54
- function parseField(value: unknown): AffordanceInputField | undefined {
55
- if (value === null || typeof value !== "object" || Array.isArray(value)) return undefined;
56
- const row = value as Record<string, unknown>;
57
- const name = optionalString(row.name);
58
- const label = optionalString(row.label);
59
- const control = row.control;
60
- if (
61
- name === undefined ||
62
- label === undefined ||
63
- (control !== "text" && control !== "textarea" && control !== "number")
64
- )
65
- return undefined;
66
- const min = optionalFiniteNumber(row.min);
67
- const max = optionalFiniteNumber(row.max);
68
- const maxLength = optionalFiniteNumber(row.max_length);
69
- const channel =
70
- row.channel === "utterance" || row.channel === "args_json" ? row.channel : undefined;
71
- if (
72
- (min !== undefined && max !== undefined && min > max) ||
73
- (maxLength !== undefined && maxLength < 1)
74
- )
75
- return undefined;
76
- return {
77
- name,
78
- label,
79
- control,
80
- ...(optionalString(row.placeholder) === undefined
81
- ? {}
82
- : { placeholder: optionalString(row.placeholder) }),
83
- ...(row.required === true ? { required: true } : {}),
84
- ...(min === undefined ? {} : { min }),
85
- ...(max === undefined ? {} : { max }),
86
- ...(maxLength === undefined ? {} : { maxLength }),
87
- ...(channel === undefined ? {} : { channel }),
88
- };
89
- }
90
-
91
- /** Reader-owned validation for `ui.affordance_input`. Bad authored payloads
92
- * are omitted rather than guessed: a player client must never invent an input
93
- * shape for a world action. */
94
- function parseInputPayload(payloadJson: unknown): AffordanceInputSchema | undefined {
95
- let parsed: unknown;
96
- try {
97
- parsed = JSON.parse(asString(payloadJson));
98
- } catch {
99
- return undefined;
100
- }
101
- if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) return undefined;
102
- const row = parsed as Record<string, unknown>;
103
- if (!Array.isArray(row.fields)) return undefined;
104
- const fields = row.fields.map(parseField);
105
- if (fields.some((field) => field === undefined)) return undefined;
106
- const typedFields = fields as AffordanceInputField[];
107
- if (new Set(typedFields.map((field) => field.name)).size !== typedFields.length) return undefined;
108
- return {
109
- fields: typedFields,
110
- ...(optionalString(row.submit_label) === undefined
111
- ? {}
112
- : { submitLabel: optionalString(row.submit_label) }),
113
- };
114
- }
115
-
116
- /** Reads public, template-keyed form schemas. There is deliberately no action
117
- * vocabulary in this reader: a template's manifest attachment is the sole
118
- * authority for which fields its offered action presents. */
119
- export function readAffordanceInputSchemas(db: SnapshotDb): Map<string, AffordanceInputSchema> {
120
- const out = new Map<string, AffordanceInputSchema>();
121
- for (const row of readMetadataAttachmentRows(db)) {
122
- if (asString(row.namespace) !== AFFORDANCE_INPUT_NAMESPACE) continue;
123
- if (asString(row.targetKind) !== AFFORDANCE_TEMPLATE_TARGET_KIND) continue;
124
- if (asString(row.audience) !== PUBLIC_AUDIENCE) continue;
125
- const schema = parseInputPayload(row.payloadJson);
126
- if (schema !== undefined) out.set(asString(row.targetRef), schema);
127
- }
128
- return out;
129
- }
@@ -1,41 +0,0 @@
1
- import {
2
- type RequiredTables,
3
- registerReaderManifest,
4
- type SnapshotDb,
5
- } from "../../reader-manifest";
6
- import { asString } from "./_helpers";
7
- import { readMetadataAttachmentRows } from "./metadata_rows";
8
-
9
- export const requiredTables: RequiredTables<
10
- ["public_metadata_attachment", "visible_metadata_attachment"]
11
- > = ["public_metadata_attachment", "visible_metadata_attachment"];
12
- registerReaderManifest({ requiredTables });
13
-
14
- const PUBLIC_AUDIENCE = "public";
15
- const AFFORDANCE_TEMPLATE_TARGET_KIND = "affordance_template";
16
- const AFFORDANCE_REFERENCE_NAMESPACE = "ui.affordance_reference";
17
-
18
- /**
19
- * Reads exact, world-authored definition references for affordance templates.
20
- * The attachment is deliberately optional: actions remain usable when a world
21
- * has no reference card, while consumers never infer one from display prose.
22
- */
23
- export function readAffordanceDefinitionRefs(db: SnapshotDb): Map<string, string> {
24
- const out = new Map<string, string>();
25
- for (const row of readMetadataAttachmentRows(db)) {
26
- if (asString(row.namespace) !== AFFORDANCE_REFERENCE_NAMESPACE) continue;
27
- if (asString(row.targetKind) !== AFFORDANCE_TEMPLATE_TARGET_KIND) continue;
28
- if (asString(row.audience) !== PUBLIC_AUDIENCE) continue;
29
- let payload: unknown;
30
- try {
31
- payload = JSON.parse(asString(row.payloadJson));
32
- } catch {
33
- continue;
34
- }
35
- if (typeof payload !== "object" || payload === null) continue;
36
- const reference = (payload as Record<string, unknown>).definition_ref;
37
- if (typeof reference !== "string" || reference.trim().length === 0) continue;
38
- out.set(asString(row.targetRef), reference);
39
- }
40
- return out;
41
- }
@@ -1,54 +0,0 @@
1
- import type { EventApplyConsequenceRow as DbEventApplyConsequenceRow } from "../../binding_rows";
2
- import {
3
- type RequiredTables,
4
- registerReaderManifest,
5
- type SnapshotDb,
6
- } from "../../reader-manifest";
7
- import { asNumber, asString, optString, rows } from "./_helpers";
8
-
9
- // `event_apply_consequence` is private (ADR-0120, #915) — subscribe + read
10
- // the per-caller `visible_event_apply_consequence` view instead
11
- // (owner/DM-extent-bounded on target/source body).
12
- export const requiredTables: RequiredTables<["visible_event_apply_consequence"]> = [
13
- "visible_event_apply_consequence",
14
- ];
15
- registerReaderManifest({ requiredTables });
16
-
17
- export interface EventApplyConsequenceEntry {
18
- event_id: string;
19
- template_id: string;
20
- target_entity_id?: string;
21
- /** ADR-0093 B2: the acting/source entity, denormalised onto the row at emit
22
- * time (`EventApplyConsequence.source_entity_ref`). `undefined` for an
23
- * ambient/ownerless consequence — the server carries this as an empty
24
- * string (`String`, not `Option<u64>`), so an empty value maps to
25
- * `undefined` here, never `""`. Was previously dropped by this reader even
26
- * though the server has always carried it. */
27
- source_entity_ref?: string;
28
- frame_writes_count: number;
29
- traces_inscribed_count: number;
30
- }
31
-
32
- export function readEventApplyConsequences(db: SnapshotDb): EventApplyConsequenceEntry[] {
33
- return rows<DbEventApplyConsequenceRow>(db, "visible_event_apply_consequence").map((row) => ({
34
- event_id: asString(row.eventId),
35
- template_id: row.templateId,
36
- target_entity_id: optionString(row.targetEntityId),
37
- source_entity_ref: optString(row.sourceEntityRef),
38
- frame_writes_count: asNumber(row.frameWritesCount),
39
- traces_inscribed_count: asNumber(row.tracesInscribedCount),
40
- }));
41
- }
42
-
43
- function optionString(value: unknown): string | undefined {
44
- if (value === undefined || value === null) return undefined;
45
- if (typeof value === "bigint" || typeof value === "number" || typeof value === "string")
46
- return String(value);
47
- if (typeof value === "object") {
48
- const record = value as { tag?: unknown; value?: unknown; some?: unknown };
49
- if (record.tag === "some" || record.tag === "Some")
50
- return optionString(record.value ?? record.some);
51
- if ("some" in record) return optionString(record.some);
52
- }
53
- return undefined;
54
- }
@@ -1,62 +0,0 @@
1
- /** ADR-0155 D-6: prompt labels bind to the occurrence's captured speech trace. */
2
- import type { TraceRow } from "../../binding_rows";
3
- import {
4
- type RequiredTables,
5
- registerReaderManifest,
6
- type SnapshotDb,
7
- } from "../../reader-manifest";
8
- import { rows } from "./_helpers";
9
- import { parseDialogueGuide } from "./dialogue_guide";
10
- import type { DialoguePromptPresentation } from "./dialogue_prompt_presentation";
11
- export const requiredTables: RequiredTables<["visible_trace"]> = ["visible_trace"];
12
- registerReaderManifest({ requiredTables });
13
-
14
- export function readAudienceTracePresentation(
15
- db: SnapshotDb,
16
- traceId: string,
17
- responseIds: readonly string[],
18
- authored: DialoguePromptPresentation | undefined,
19
- ): DialoguePromptPresentation | undefined {
20
- if (authored?.presentation !== "audience_trace") return authored;
21
- const fallback = Object.fromEntries(responseIds.map((id, index) => [id, String(index + 1)]));
22
- const trace = rows<TraceRow>(db, "visible_trace").find((row) => String(row.traceId) === traceId);
23
- let payload: unknown;
24
- try {
25
- payload = JSON.parse(trace?.payloadJson ?? "null");
26
- } catch {
27
- payload = undefined;
28
- }
29
- if (typeof payload !== "object" || payload === null || Array.isArray(payload))
30
- return { labels: fallback };
31
- const { text, options, option_definition_refs, context } = payload as Record<string, unknown>;
32
- // The speaker's machine side rides the same captured trace, so it is bound
33
- // to this occurrence like the labels are.
34
- const guide = parseDialogueGuide(context);
35
- const valid =
36
- Array.isArray(options) &&
37
- options.length === responseIds.length &&
38
- options.every((label) => typeof label === "string");
39
- const refs =
40
- valid &&
41
- Array.isArray(option_definition_refs) &&
42
- option_definition_refs.length === responseIds.length &&
43
- option_definition_refs.every(
44
- (ref) => ref === null || (typeof ref === "string" && ref.length > 0),
45
- )
46
- ? Object.fromEntries(
47
- responseIds.flatMap((id, index) =>
48
- typeof option_definition_refs[index] === "string"
49
- ? [[id, option_definition_refs[index]]]
50
- : [],
51
- ),
52
- )
53
- : undefined;
54
- return {
55
- ...(typeof text === "string" ? { question: text } : {}),
56
- ...(refs === undefined || Object.keys(refs).length === 0 ? {} : { response_refs: refs }),
57
- ...(guide === undefined ? {} : { guide }),
58
- labels: valid
59
- ? Object.fromEntries(responseIds.map((id, i) => [id, (options as string[])[i] as string]))
60
- : fallback,
61
- };
62
- }
@@ -1,29 +0,0 @@
1
- const EXAMPLE_BOUND = 4;
2
-
3
- /**
4
- * Self-describing bounded collection: `listing` tells a caller whether
5
- * `items` is the entire authorized collection ("complete") or a bounded
6
- * example slice ("examples") that needs a follow-up `continuation` call to
7
- * see the rest. Never silent-truncate a collection without saying so.
8
- */
9
- export interface BoundedCollection<T> {
10
- count: number;
11
- listing: "complete" | "examples";
12
- items: T[];
13
- continuation?: { tool: string; args: Record<string, unknown> };
14
- }
15
-
16
- /** Build a `BoundedCollection` from a full authorized row set. */
17
- export function boundedCollection<T>(
18
- all: readonly T[],
19
- continuation: { tool: string; args: Record<string, unknown> },
20
- limit = EXAMPLE_BOUND,
21
- ): BoundedCollection<T> {
22
- const complete = all.length <= limit;
23
- return {
24
- count: all.length,
25
- listing: complete ? "complete" : "examples",
26
- items: all.slice(0, limit),
27
- ...(complete ? {} : { continuation }),
28
- };
29
- }
@@ -1,74 +0,0 @@
1
- import type { CapabilityDefinitionRow, ResourceDefinitionRow } from "../../binding_rows";
2
- import {
3
- type RequiredTables,
4
- registerReaderManifest,
5
- type SnapshotDb,
6
- } from "../../reader-manifest";
7
- import { asNumber, asString, optNumber, rows } from "./_helpers";
8
-
9
- export const capabilityRequiredTables: RequiredTables<["capability_definition"]> = [
10
- "capability_definition",
11
- ];
12
- registerReaderManifest({ requiredTables: capabilityRequiredTables });
13
-
14
- export const resourceRequiredTables: RequiredTables<["resource_definition"]> = [
15
- "resource_definition",
16
- ];
17
- registerReaderManifest({ requiredTables: resourceRequiredTables });
18
-
19
- export interface BundleCapabilityDefinitionRow {
20
- capability_id: string;
21
- bundle_id: string;
22
- actor_kind: string;
23
- display_name: string;
24
- description: string;
25
- }
26
-
27
- export interface BundleResourceDefinitionRow {
28
- resource_definition_id: string;
29
- bundle_id: string;
30
- display_name: string;
31
- value_kind: string;
32
- min_value: number;
33
- max_value: number;
34
- recovery_rule: string;
35
- initial_value: number | null;
36
- }
37
-
38
- export function readCapabilityDefinition(
39
- db: SnapshotDb,
40
- capabilityId: string,
41
- ): BundleCapabilityDefinitionRow | null {
42
- const row = rows<CapabilityDefinitionRow>(db, "capability_definition").find(
43
- (r) => r.capabilityId === capabilityId,
44
- );
45
- if (!row) return null;
46
- return {
47
- capability_id: asString(row.capabilityId),
48
- bundle_id: asString(row.bundleId),
49
- actor_kind: asString(row.actorKind),
50
- display_name: asString(row.displayName),
51
- description: asString(row.description),
52
- };
53
- }
54
-
55
- export function readResourceDefinition(
56
- db: SnapshotDb,
57
- resourceDefinitionId: string,
58
- ): BundleResourceDefinitionRow | null {
59
- const row = rows<ResourceDefinitionRow>(db, "resource_definition").find(
60
- (r) => r.resourceDefinitionId === resourceDefinitionId,
61
- );
62
- if (!row) return null;
63
- const initial = optNumber(row.initialValue);
64
- return {
65
- resource_definition_id: asString(row.resourceDefinitionId),
66
- bundle_id: asString(row.bundleId),
67
- display_name: asString(row.displayName),
68
- value_kind: asString(row.valueKind),
69
- min_value: asNumber(row.minValue),
70
- max_value: asNumber(row.maxValue),
71
- recovery_rule: asString(row.recoveryRule),
72
- initial_value: initial === undefined || !Number.isFinite(initial) ? null : initial,
73
- };
74
- }
@@ -1,62 +0,0 @@
1
- import type { EntityRow } from "../../binding_rows";
2
- import {
3
- type RequiredTables,
4
- registerReaderManifest,
5
- type SnapshotDb,
6
- } from "../../reader-manifest";
7
- import type { EntityRef } from "../ids";
8
- import { asNumber, asString, resolveEntityId, rows } from "./_helpers";
9
-
10
- export const requiredTables: RequiredTables<
11
- ["entity", "visible_manifest_authored_entity", "visible_manifest_authored_entity_coverage"]
12
- > = ["entity", "visible_manifest_authored_entity", "visible_manifest_authored_entity_coverage"];
13
- registerReaderManifest({ requiredTables });
14
-
15
- export interface BundleEntityRow {
16
- entity_id: string;
17
- entity_key: string | null;
18
- entity_def_id: string;
19
- name: string;
20
- kind: string;
21
- created_at_tick: number;
22
- quantity: number;
23
- owned_by_entity_id: string;
24
- }
25
-
26
- export type BundleItemRow = BundleEntityRow & { kind: "item" };
27
-
28
- export function readEntity(db: SnapshotDb, entityKey: EntityRef): BundleEntityRow | null {
29
- const entityId = resolveEntityId(db, entityKey);
30
- const entityRows = rows<EntityRow>(db, "entity");
31
- if (entityId === undefined) return null;
32
- const entity = entityRows.find((r) => r.entityId === entityId);
33
- return entity ? toEntityRow(db, entity, entityKey) : null;
34
- }
35
-
36
- export function readItem(db: SnapshotDb, itemKey: EntityRef): BundleItemRow | null {
37
- const entity = readEntity(db, itemKey);
38
- return entity?.kind === "item" ? (entity as BundleItemRow) : null;
39
- }
40
-
41
- function toEntityRow(db: SnapshotDb, row: EntityRow, lookupKey: string): BundleEntityRow {
42
- return {
43
- entity_id: String(row.entityId),
44
- entity_key: entityKeyFor(db, row.entityId, lookupKey),
45
- entity_def_id: asString(row.entityDefId),
46
- name: asString(row.name),
47
- kind: asString(row.kind),
48
- created_at_tick: asNumber(row.createdAtTick),
49
- quantity: asNumber(row.quantity),
50
- owned_by_entity_id: String(row.ownedByEntityId),
51
- };
52
- }
53
-
54
- function entityKeyFor(db: SnapshotDb, entityId: bigint, lookupKey: string): string | null {
55
- const authored = rows<{ manifestKey: string; entityId: bigint }>(
56
- db,
57
- "visible_manifest_authored_entity",
58
- ).find((r) => r.entityId === entityId);
59
- if (!authored) return null;
60
- const idx = authored.manifestKey.indexOf(":");
61
- return idx >= 0 ? authored.manifestKey.slice(idx + 1) : lookupKey;
62
- }
@@ -1,71 +0,0 @@
1
- // Reader: actor co-location snapshot — the two place-node values a perceiver
2
- // occupies in the spatial vs. the entity track. The co-evolution Verifier
3
- // (packages/world-explorer) compares these BEFORE trusting any affordance/
4
- // perception query, because the round-13 #655 false-negative slipped in when
5
- // the perceiver's `actor_spatial_location` (market_lane) diverged from its
6
- // `entity_location`. This reader only READS both rows; it does NOT judge — the
7
- // divergence verdict is the Verifier's pure `assertCoLocation` (SDK CLAUDE.md §1:
8
- // no runtime state-dependent decision in the SDK).
9
-
10
- import type { ActorSpatialLocationRow, EntityLocationRow } from "../../binding_rows";
11
- import {
12
- type RequiredTables,
13
- registerReaderManifest,
14
- type SnapshotDb,
15
- } from "../../reader-manifest";
16
- import type { EntityRef } from "../ids";
17
- import { resolveEntityId, rows } from "./_helpers";
18
-
19
- export const requiredTables: RequiredTables<
20
- [
21
- "visible_actor_spatial_location",
22
- "visible_entity_location",
23
- "visible_manifest_authored_entity",
24
- "visible_manifest_authored_entity_coverage",
25
- ]
26
- > = [
27
- "visible_actor_spatial_location",
28
- "visible_entity_location",
29
- "visible_manifest_authored_entity",
30
- "visible_manifest_authored_entity_coverage",
31
- ];
32
- registerReaderManifest({ requiredTables });
33
-
34
- /**
35
- * The two place-node ids a perceiver is recorded at. `null` for either track
36
- * means no row exists there for the entity (which `assertCoLocation` treats as
37
- * a divergence, never as a silent match).
38
- */
39
- export interface ActorCoLocation {
40
- /** The entity id this snapshot is for (resolved from the ref). */
41
- entity_id: string;
42
- /** `actor_spatial_location.placeNodeId`, or `null` if no row. */
43
- actor_spatial_location: string | null;
44
- /** `entity_location.placeNodeId`, or `null` if no row. */
45
- entity_location: string | null;
46
- }
47
-
48
- /**
49
- * Read the perceiver's co-location across both tracks. Returns `null` only when
50
- * the ref does not resolve to an entity id at all; an existing entity with no
51
- * row in one track yields that track as `null` (a divergence the Verifier
52
- * withholds on). Accepts the same ref forms as the other perceive readers
53
- * (numeric, `entity:N`, or a manifest authored-entity key).
54
- */
55
- export function readActorCoLocation(db: SnapshotDb, entityRef: EntityRef): ActorCoLocation | null {
56
- const entityId = resolveEntityId(db, entityRef);
57
- if (entityId === undefined) return null;
58
-
59
- const spatial = rows<ActorSpatialLocationRow>(db, "visible_actor_spatial_location").find(
60
- (r) => String(r.entityId) === String(entityId),
61
- );
62
- const entity = rows<EntityLocationRow>(db, "visible_entity_location").find(
63
- (r) => String(r.entityId) === String(entityId),
64
- );
65
-
66
- return {
67
- entity_id: String(entityId),
68
- actor_spatial_location: spatial ? String(spatial.placeNodeId) : null,
69
- entity_location: entity ? String(entity.placeNodeId) : null,
70
- };
71
- }
@@ -1,124 +0,0 @@
1
- import type {
2
- ActorSpatialLocationRow,
3
- EntityRow,
4
- EvaluationProvenanceRow,
5
- ObjectStateRow,
6
- PlaceEdgeAffordanceRow,
7
- PlaceEdgeRow,
8
- PlaceGraphDefinitionRow,
9
- PlaceNodeRow,
10
- WorldEventRow,
11
- } from "../../binding_rows";
12
- import {
13
- type RequiredTables,
14
- registerReaderManifest,
15
- type SnapshotDb,
16
- } from "../../reader-manifest";
17
- import { asString, resolveEntityId, rows } from "./_helpers";
18
- import { activeSessionForParticipant } from "./combat_session_active";
19
- import { latestFeedback } from "./combat_session_feedback";
20
- import { gridForSession } from "./combat_session_grid";
21
- import { buildRoster, nextRosterEntry } from "./combat_session_roster";
22
-
23
- export type {
24
- CombatFeedback,
25
- CombatGridCell,
26
- CombatMove,
27
- CombatRosterEntry,
28
- CombatSessionView,
29
- } from "./combat_session_types";
30
-
31
- import type { EntityRef } from "../ids";
32
- import type { CombatSessionView } from "./combat_session_types";
33
-
34
- export const requiredTables: RequiredTables<
35
- [
36
- "visible_session",
37
- "visible_session_participant",
38
- "visible_actor_spatial_location",
39
- "entity",
40
- "visible_object_state",
41
- "visible_manifest_authored_entity",
42
- "visible_manifest_authored_entity_coverage",
43
- "visible_place_graph_definition",
44
- "visible_place_node",
45
- "visible_place_edge",
46
- "place_edge_affordance",
47
- "visible_evaluation_provenance",
48
- "visible_world_event",
49
- ]
50
- > = [
51
- "visible_session",
52
- "visible_session_participant",
53
- "visible_actor_spatial_location",
54
- "entity",
55
- "visible_object_state",
56
- "visible_manifest_authored_entity",
57
- "visible_manifest_authored_entity_coverage",
58
- "visible_place_graph_definition",
59
- "visible_place_node",
60
- "visible_place_edge",
61
- "place_edge_affordance",
62
- "visible_evaluation_provenance",
63
- // `world_event` is private (#915 PR-8); read the per-caller dispatch view.
64
- "visible_world_event",
65
- ];
66
- registerReaderManifest({ requiredTables });
67
-
68
- export function readCombatSessionView(
69
- db: SnapshotDb,
70
- actorRef: EntityRef,
71
- ): CombatSessionView | null {
72
- const heroEntity = resolveEntityId(db, actorRef);
73
- const graphs = rows<PlaceGraphDefinitionRow>(db, "visible_place_graph_definition");
74
- const nodes = rows<PlaceNodeRow>(db, "visible_place_node");
75
- const edges = rows<PlaceEdgeRow>(db, "visible_place_edge");
76
- const edgeAffordances = rows<PlaceEdgeAffordanceRow>(db, "place_edge_affordance");
77
- const spatialRows = rows<ActorSpatialLocationRow>(db, "visible_actor_spatial_location");
78
- const entityRows = rows<EntityRow>(db, "entity");
79
- const stateRows = rows<ObjectStateRow>(db, "visible_object_state");
80
- const provenanceRows = rows<EvaluationProvenanceRow>(db, "visible_evaluation_provenance");
81
- const eventRows = rows<WorldEventRow>(db, "visible_world_event");
82
- const heroId = heroEntity === undefined ? undefined : String(heroEntity);
83
- if (heroId === undefined) return null;
84
-
85
- const active = activeSessionForParticipant(db, heroId);
86
- if (active === null) return null;
87
-
88
- const positions = new Map(
89
- spatialRows.map((row) => [String(row.entityId), asString(row.placeNodeId)]),
90
- );
91
- const roster = buildRoster(
92
- active.participants,
93
- active.session.currentActor,
94
- heroId,
95
- entityRows,
96
- stateRows,
97
- positions,
98
- nodes,
99
- );
100
- const currentActorName =
101
- roster.find((entry) => entry.isCurrent)?.name ?? `entity:${active.session.currentActor}`;
102
- const nextActorName = nextRosterEntry(roster, active.session.currentActor)?.name ?? null;
103
- const isHeroTurn = active.session.currentActor === heroId;
104
-
105
- return {
106
- session: active.session,
107
- roster,
108
- currentActorName,
109
- nextActorName,
110
- isHeroTurn,
111
- waitingReason: isHeroTurn ? null : `Waiting for ${currentActorName}. It is not your turn.`,
112
- grid: gridForSession(
113
- active.session.sessionId,
114
- heroId,
115
- graphs,
116
- nodes,
117
- edges,
118
- edgeAffordances,
119
- roster,
120
- positions,
121
- ),
122
- feedback: latestFeedback(heroId, provenanceRows, eventRows),
123
- };
124
- }