@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,124 +0,0 @@
1
- import type { ObjectStateRow } from "../../binding_rows";
2
- import {
3
- type RequiredTables,
4
- registerReaderManifest,
5
- type SnapshotDb,
6
- } from "../../reader-manifest";
7
- import { rows, tagString } from "./_helpers";
8
-
9
- export const requiredTables: RequiredTables<["visible_object_state"]> = ["visible_object_state"];
10
- registerReaderManifest({ requiredTables });
11
-
12
- export interface ObjectStateRef {
13
- targetKind: string;
14
- targetId: string | number | bigint;
15
- stateId: string;
16
- }
17
-
18
- export interface AwaitObjectStateAppliedOpts extends ObjectStateRef {
19
- previousValue?: number | bigint;
20
- expectedValue?: number | bigint;
21
- delta?: number | bigint;
22
- timeoutMs?: number;
23
- pollMs?: number;
24
- }
25
-
26
- const DEFAULT_TIMEOUT_MS = 2_000;
27
- const DEFAULT_POLL_MS = 40;
28
-
29
- export function readObjectStateInt(db: SnapshotDb, ref: ObjectStateRef): bigint | null {
30
- const row = rows<ObjectStateRow>(db, "visible_object_state").find(
31
- (candidate) =>
32
- targetKindMatches(candidate.targetKind, ref.targetKind) &&
33
- String(candidate.targetId) === String(ref.targetId) &&
34
- candidate.stateId === ref.stateId,
35
- );
36
- if (!row) return null;
37
- return dslIntValue(row.value);
38
- }
39
-
40
- export interface EntityIntState {
41
- stateId: string;
42
- value: bigint;
43
- }
44
-
45
- /**
46
- * All integer `object_state` pools for one entity, sorted by `stateId`.
47
- *
48
- * Generic over state vocabulary — the panel layer renders whatever pools an
49
- * entity carries (`srd/hp`, `srd/ac`, a modder's `myworld/stamina`) without the
50
- * kernel's content-neutrality (ADR-0021) leaking an SRD assumption into the SDK.
51
- * Non-int values (bool/text/outcome) are skipped: `dslIntValue` returns null and
52
- * they fall out of the list.
53
- */
54
- export function readEntityIntStates(
55
- db: SnapshotDb,
56
- targetId: string | number | bigint,
57
- ): EntityIntState[] {
58
- const wanted = String(targetId);
59
- return rows<ObjectStateRow>(db, "visible_object_state")
60
- .filter((row) => targetKindMatches(row.targetKind, "entity") && String(row.targetId) === wanted)
61
- .map((row) => ({ stateId: String(row.stateId), value: dslIntValue(row.value) }))
62
- .filter((state): state is EntityIntState => state.value !== null)
63
- .sort((a, b) => (a.stateId < b.stateId ? -1 : a.stateId > b.stateId ? 1 : 0));
64
- }
65
-
66
- export async function awaitObjectStateApplied(
67
- db: () => SnapshotDb,
68
- opts: AwaitObjectStateAppliedOpts,
69
- ): Promise<bigint | null> {
70
- const timeoutMs = Math.max(1, opts.timeoutMs ?? DEFAULT_TIMEOUT_MS);
71
- const pollMs = Math.max(1, opts.pollMs ?? DEFAULT_POLL_MS);
72
- const expected = expectedIntValue(opts);
73
- const previous = opts.previousValue === undefined ? undefined : BigInt(opts.previousValue);
74
- const deadline = Date.now() + timeoutMs;
75
-
76
- let latest = readObjectStateInt(db(), opts);
77
- while (Date.now() <= deadline) {
78
- if (matches(latest, expected, previous)) return latest;
79
- // Yield to the JS SDK's event loop so pending websocket updates can refresh the cache.
80
- await new Promise((resolve) => setTimeout(resolve, pollMs));
81
- latest = readObjectStateInt(db(), opts);
82
- }
83
-
84
- return matches(latest, expected, previous) ? latest : null;
85
- }
86
-
87
- function expectedIntValue(opts: AwaitObjectStateAppliedOpts): bigint | undefined {
88
- if (opts.expectedValue !== undefined) return BigInt(opts.expectedValue);
89
- if (opts.previousValue !== undefined && opts.delta !== undefined) {
90
- return BigInt(opts.previousValue) + BigInt(opts.delta);
91
- }
92
- return undefined;
93
- }
94
-
95
- function matches(
96
- value: bigint | null,
97
- expected: bigint | undefined,
98
- previous: bigint | undefined,
99
- ): boolean {
100
- if (value === null) return false;
101
- if (expected !== undefined) return value === expected;
102
- if (previous !== undefined) return value !== previous;
103
- return true;
104
- }
105
-
106
- function targetKindMatches(actual: unknown, expected: string): boolean {
107
- return normalizeTargetKind(String(actual)) === normalizeTargetKind(expected);
108
- }
109
-
110
- function normalizeTargetKind(kind: string): string {
111
- return kind.replace(/_/g, "").toLowerCase();
112
- }
113
-
114
- function dslIntValue(value: unknown): bigint | null {
115
- if (typeof value === "bigint") return value;
116
- if (typeof value === "number") return BigInt(value);
117
- if (typeof value === "string" && /^-?\d+$/.test(value)) return BigInt(value);
118
- if (!value || typeof value !== "object") return null;
119
-
120
- const record = value as Record<string, unknown>;
121
- if (tagString(record.tag) === "Int") return dslIntValue(record.value);
122
- if ("Int" in record) return dslIntValue(record.Int);
123
- return null;
124
- }
@@ -1,41 +0,0 @@
1
- import type { ObserverKnowledgeRow } from "../../binding_rows";
2
- import {
3
- type RequiredTables,
4
- registerReaderManifest,
5
- type SnapshotDb,
6
- } from "../../reader-manifest";
7
- import { asNumber, asString, rows } from "./_helpers";
8
-
9
- // `observer_knowledge` is private (ADR-0120, #915 sweep PR-2); subscribe +
10
- // read the per-caller `visible_observer_knowledge` view — a body sees only
11
- // its own perception rows (own bodies + ADR-0007 D-4 extent grants). Raw
12
- // god-view → operator `just sql`.
13
- export const requiredTables: RequiredTables<["visible_observer_knowledge"]> = [
14
- "visible_observer_knowledge",
15
- ];
16
- registerReaderManifest({ requiredTables });
17
-
18
- export interface ObserverKnowledgeEntry {
19
- // Post Phase 6 (Item 16 — 16-observer-knowledge-projection.md):
20
- // observer_knowledge is entity-keyed; the field is now `observer_entity_id`.
21
- observer_entity_id: string;
22
- known_entity_id: string;
23
- learned_at_tick: number;
24
- }
25
-
26
- /**
27
- * Returns all knowledge entries for the given observer entity id.
28
- * Empty array if the entity has no rows yet (learn hook not fired, or no anchored entities).
29
- */
30
- export function readObserverKnowledge(
31
- db: SnapshotDb,
32
- observerEntityId: string,
33
- ): ObserverKnowledgeEntry[] {
34
- return rows<ObserverKnowledgeRow>(db, "visible_observer_knowledge")
35
- .filter((r) => asString(r.observerEntityId) === observerEntityId)
36
- .map((r) => ({
37
- observer_entity_id: asString(r.observerEntityId),
38
- known_entity_id: asString(r.knownEntityId),
39
- learned_at_tick: asNumber(r.learnedAtTick),
40
- }));
41
- }
@@ -1,37 +0,0 @@
1
- import type { ObserverPlaceKnowledgeRow } from "../../binding_rows";
2
- import {
3
- type RequiredTables,
4
- registerReaderManifest,
5
- type SnapshotDb,
6
- } from "../../reader-manifest";
7
- import { asNumber, asString, rows } from "./_helpers";
8
-
9
- // `observer_place_knowledge` is private (ADR-0120, #915 sweep PR-2);
10
- // subscribe + read the per-caller `visible_observer_place_knowledge` view.
11
- export const requiredTables: RequiredTables<["visible_observer_place_knowledge"]> = [
12
- "visible_observer_place_knowledge",
13
- ];
14
- registerReaderManifest({ requiredTables });
15
-
16
- export interface ObserverPlaceKnowledgeEntry {
17
- observer_entity_id: string;
18
- known_node_id: string;
19
- learned_at_tick: number;
20
- }
21
-
22
- /**
23
- * Returns all place-knowledge entries for the given observer entity id.
24
- * Empty array if the entity has not perceived any place nodes yet.
25
- */
26
- export function readObserverPlaceKnowledge(
27
- db: SnapshotDb,
28
- observerEntityId: string,
29
- ): ObserverPlaceKnowledgeEntry[] {
30
- return rows<ObserverPlaceKnowledgeRow>(db, "visible_observer_place_knowledge")
31
- .filter((r) => asString(r.observerEntityId) === observerEntityId)
32
- .map((r) => ({
33
- observer_entity_id: asString(r.observerEntityId),
34
- known_node_id: asString(r.knownNodeId),
35
- learned_at_tick: asNumber(r.learnedAtTick),
36
- }));
37
- }
@@ -1,45 +0,0 @@
1
- import type { ObserverTraceKnowledgeRow } from "../../binding_rows";
2
- import {
3
- type RequiredTables,
4
- registerReaderManifest,
5
- type SnapshotDb,
6
- } from "../../reader-manifest";
7
- import { asNumber, asString, rows } from "./_helpers";
8
-
9
- // `observer_trace_knowledge` is private (ADR-0120, #915 sweep PR-2);
10
- // subscribe + read the per-caller `visible_observer_trace_knowledge` view.
11
- // NOT to be confused with `visible_trace` (traces.ts), which reads this
12
- // table server-internally to gate delivery of the (also private) `trace`
13
- // row itself.
14
- export const requiredTables: RequiredTables<["visible_observer_trace_knowledge"]> = [
15
- "visible_observer_trace_knowledge",
16
- ];
17
- registerReaderManifest({ requiredTables });
18
-
19
- export interface ObserverTraceKnowledgeEntry {
20
- observer_entity_id: string;
21
- known_trace_id: string;
22
- content: string;
23
- learned_at_tick: number;
24
- }
25
-
26
- /**
27
- * Returns all trace-knowledge entries for the given observer entity id.
28
- * Empty array if the entity has not perceived any inscribed traces yet.
29
- * A dangling known_trace_id (trace decayed) is intentional — caller should
30
- * cross-reference with the live trace table if freshness is needed. The
31
- * content field is the perceived trace payload captured at first perception.
32
- */
33
- export function readObserverTraceKnowledge(
34
- db: SnapshotDb,
35
- observerEntityId: string,
36
- ): ObserverTraceKnowledgeEntry[] {
37
- return rows<ObserverTraceKnowledgeRow>(db, "visible_observer_trace_knowledge")
38
- .filter((r) => asString(r.observerEntityId) === observerEntityId)
39
- .map((r) => ({
40
- observer_entity_id: asString(r.observerEntityId),
41
- known_trace_id: asString(r.knownTraceId),
42
- content: asString(r.content),
43
- learned_at_tick: asNumber(r.learnedAtTick),
44
- }));
45
- }
@@ -1,41 +0,0 @@
1
- // Reader: outcome_template description (#1968 B-9).
2
- // Mechanical, single-field reader: no new functionality beyond exposing the
3
- // authored `outcome_template.description` column, mirroring
4
- // `readLocationSnapshot`'s `node_description`/`graph_description` pattern —
5
- // `outcome_template` is public/definition-shaped (like `niche_definition`,
6
- // `action_definition`), not a hidden-state or per-caller-gated table, so no
7
- // view/visibility split is needed here.
8
-
9
- import type { OutcomeTemplateRow } from "../../binding_rows";
10
- import {
11
- type RequiredTables,
12
- registerReaderManifest,
13
- type SnapshotDb,
14
- } from "../../reader-manifest";
15
- import { rows } from "./_helpers";
16
-
17
- export const requiredTables: RequiredTables<["outcome_template"]> = ["outcome_template"];
18
- registerReaderManifest({ requiredTables });
19
-
20
- /**
21
- * Read the RAW authored `outcome_template.description` for one
22
- * `outcomeTemplateId` — uninterpolated, placeholder tokens (`{target_name}`
23
- * etc.) left verbatim. Returns `null` when the row does not exist or its
24
- * description is unauthored (empty string), so callers fall back to their
25
- * own honest gap rather than treating "" as a valid observation.
26
- *
27
- * Interpolation and epistemic composition (which data resolves each
28
- * placeholder) is a shared tool runtime concern
29
- * (`packages/spellkave-tool-player/src/observation.ts`), not this reader
30
- * — SDK readers stay pure reads, no business logic.
31
- */
32
- export function readOutcomeTemplateDescription(
33
- db: SnapshotDb,
34
- outcomeTemplateId: string,
35
- ): string | null {
36
- const row = rows<OutcomeTemplateRow>(db, "outcome_template").find(
37
- (r) => r.outcomeTemplateId === outcomeTemplateId,
38
- );
39
- const description = row?.description ?? "";
40
- return description !== "" ? description : null;
41
- }
@@ -1,109 +0,0 @@
1
-
2
- import type { PlaceEdgeRow, PlaceGraphDefinitionRow, PlaceNodeRow } from "../../binding_rows";
3
- import {
4
- type RequiredTables,
5
- registerReaderManifest,
6
- type SnapshotDb,
7
- } from "../../reader-manifest";
8
- import { asString, rows } from "./_helpers";
9
-
10
- export const requiredTables: RequiredTables<
11
- ["visible_place_node", "visible_place_edge", "visible_place_graph_definition"]
12
- > = ["visible_place_node", "visible_place_edge", "visible_place_graph_definition"];
13
- registerReaderManifest({ requiredTables });
14
-
15
- export interface PlaceTopology {
16
- place_graphs: Record<string, unknown>[];
17
- place_nodes: Record<string, unknown>[];
18
- place_edges: Record<string, unknown>[];
19
- }
20
-
21
- /**
22
- * Read the caller's admitted place-graph topology: every visible
23
- * place_graph/place_node/place_edge row, in the manifest's own snake_case
24
- * row shape. Filtering is module-side — see the header note.
25
- */
26
- export function readPlaceTopology(db: SnapshotDb): PlaceTopology {
27
- return projectPlaceTopology(
28
- db,
29
- "visible_place_graph_definition",
30
- "visible_place_node",
31
- "visible_place_edge",
32
- );
33
- }
34
-
35
- /**
36
- * Shared projection over named accessors — kept so fixtures and internal
37
- * callers can point at explicit table names while producing the same row shape.
38
- */
39
- export function projectPlaceTopology(
40
- db: SnapshotDb,
41
- graphTable: string,
42
- nodeTable: string,
43
- edgeTable: string,
44
- ): PlaceTopology {
45
- const place_graphs = rows<PlaceGraphDefinitionRow>(db, graphTable).map((g) => ({
46
- place_graph_id: asString(g.placeGraphId),
47
- bundle_id: asString(g.bundleId),
48
- substrate_id: asString(g.substrateId),
49
- display_name: asString(g.displayName),
50
- description: asString(g.description),
51
- origin_cell_res10: g.originCellRes10,
52
- bearing: g.bearing,
53
- metres_per_unit: g.metresPerUnit,
54
- blueprint_id: asString(g.blueprintId),
55
- parent_graph_id: asString(g.parentGraphId),
56
- anchor_node_id: asString(g.anchorNodeId),
57
- // Runtime-minted instance (session tactical grid) vs authored graph.
58
- // `parent_graph_id` alone does NOT discriminate the two — authored
59
- // graphs nest as well (elven-mini's tomb/inn under hamlet/region) —
60
- // so a consumer that must treat ephemeral instances differently needs
61
- // this column, not the parent link. Projected for the companion's
62
- // map composition gate (bead sk-pej D-2), which otherwise has to
63
- // sniff the server's `session_grid_<id>` string shape.
64
- is_ephemeral_instance: g.isEphemeralInstance,
65
- }));
66
- const place_nodes = rows<PlaceNodeRow>(db, nodeTable).map((n) => ({
67
- node_id: asString(n.nodeId),
68
- bundle_id: asString(n.bundleId),
69
- place_graph_id: asString(n.placeGraphId),
70
- local_id: asString(n.localId),
71
- substrate_id: asString(n.substrateId),
72
- display_name: asString(n.displayName),
73
- description: asString(n.description),
74
- cell_res10: n.cellRes10,
75
- cell_res7: n.cellRes7,
76
- cell_res4: n.cellRes4,
77
- pose_elevation: n.poseElevation,
78
- pose_elevation_present: n.poseElevationPresent,
79
- pos_x: n.posX,
80
- pos_y: n.posY,
81
- pos_present: n.posPresent,
82
- extent_shape_id: asString(n.extentShapeId),
83
- extent_params_json: asString(n.extentParamsJson),
84
- is_ephemeral: Boolean(n.isEphemeral),
85
- }));
86
- const place_edges = rows<PlaceEdgeRow>(db, edgeTable).map((e) => ({
87
- // u64 on the wire — keep decimal string so world-map never loses bits.
88
- edge_id: asString(e.edgeId),
89
- edge_key: asString(e.edgeKey),
90
- bundle_id: asString(e.bundleId),
91
- place_graph_id: asString(e.placeGraphId),
92
- from_node_id: asString(e.fromNodeId),
93
- to_node_id: asString(e.toNodeId),
94
- pose_dt_elevation: e.poseDtElevation,
95
- pose_dt_elevation_present: Boolean(e.poseDtElevationPresent),
96
- substrate_crossing: Boolean(e.substrateCrossing),
97
- cell_anchor: e.cellAnchor,
98
- cell_anchor_u: e.cellAnchorU,
99
- cell_anchor_v: e.cellAnchorV,
100
- cell_anchor_present: Boolean(e.cellAnchorPresent),
101
- from_anchor_side: asString(e.fromAnchorSide),
102
- from_anchor_offset: e.fromAnchorOffset,
103
- to_anchor_side: asString(e.toAnchorSide),
104
- to_anchor_offset: e.toAnchorOffset,
105
- description: asString(e.description),
106
- inherit_movement_default: Boolean(e.inheritMovementDefault),
107
- }));
108
- return { place_graphs, place_nodes, place_edges };
109
- }
@@ -1,156 +0,0 @@
1
- import type {
2
- ManipulationObservedTargetRow as DbManipulationObservedTargetRow,
3
- PendingResolutionReactorRow,
4
- PendingResolutionRow,
5
- } from "../../binding_rows";
6
- import {
7
- type RequiredTables,
8
- registerReaderManifest,
9
- type SnapshotDb,
10
- } from "../../reader-manifest";
11
- import type { EntityRef } from "../ids";
12
- import { targetRefToString } from "../reducers/transport";
13
- import { asNumber, asString, buildEntityFactionMap, resolveEntityId, rows } from "./_helpers";
14
-
15
- export const requiredTables: RequiredTables<
16
- [
17
- "visible_pending_resolution",
18
- "visible_pending_resolution_reactor",
19
- "visible_manifest_authored_entity",
20
- "visible_manifest_authored_entity_coverage",
21
- "visible_manipulation_observed_target",
22
- "visible_entity_tag",
23
- "visible_entity_tag_coverage",
24
- ]
25
- > = [
26
- "visible_pending_resolution",
27
- "visible_pending_resolution_reactor",
28
- "visible_manifest_authored_entity",
29
- "visible_manifest_authored_entity_coverage",
30
- "visible_manipulation_observed_target",
31
- "visible_entity_tag",
32
- "visible_entity_tag_coverage",
33
- ];
34
- registerReaderManifest({ requiredTables });
35
-
36
- /** Participant-visible reaction seat joined to its still-open parent window. */
37
- export interface ReactionOptionProjection {
38
- /** Internal typed reducer argument. Presentation layers must hide this id. */
39
- pending_id: bigint;
40
- reactor_id: string;
41
- originating_action_id: string;
42
- originating_actor: string;
43
- target_actor: string;
44
- /**
45
- * Faction suffix already disclosed on this perceiver's factored target
46
- * context for `target_actor`. Null when that actor is not a disclosed target
47
- * (runtime tags use admitted visible_entity_tag with coverage).
48
- */
49
- target_entity_faction: string | null;
50
- computed_outcome_template: string;
51
- session_id: bigint;
52
- window_opens_at_micros: number;
53
- window_closes_at_micros: number;
54
- depth: number;
55
- bundle_id: string;
56
- }
57
-
58
- function bigint(value: unknown): bigint {
59
- return typeof value === "bigint" ? value : BigInt(String(value ?? 0));
60
- }
61
-
62
- /**
63
- * Return only unreacted seats belonging to `actorEntityId`. Rows without a
64
- * visible parent are skipped fail-closed. Sorting is deadline then pending id.
65
- */
66
- export function readReactionOptionsForActor(
67
- db: SnapshotDb,
68
- actorEntityRef: EntityRef,
69
- ): ReactionOptionProjection[] {
70
- const actorEntityId = resolveEntityId(db, actorEntityRef);
71
- if (actorEntityId === undefined) return [];
72
- const actorEntityIdText = String(actorEntityId);
73
- const perceivedTargets = perceivedManipulationTargetIds(db, actorEntityId);
74
- const factions = buildEntityFactionMap(db);
75
- const parents = new Map<string, PendingResolutionRow>();
76
- for (const row of rows<PendingResolutionRow>(db, "visible_pending_resolution")) {
77
- const raw = row as unknown as { pendingId: unknown };
78
- parents.set(String(raw.pendingId), row);
79
- }
80
-
81
- const options: ReactionOptionProjection[] = [];
82
- for (const seat of rows<PendingResolutionReactorRow>(db, "visible_pending_resolution_reactor")) {
83
- const reactor = seat as unknown as {
84
- pendingId: unknown;
85
- entityRef: unknown;
86
- reacted: boolean;
87
- };
88
- if (reactor.reacted || asString(reactor.entityRef) !== actorEntityIdText) continue;
89
- const parent = parents.get(String(reactor.pendingId));
90
- if (parent === undefined) continue;
91
- const pending = parent as unknown as {
92
- pendingId: unknown;
93
- originatingActionId: unknown;
94
- originatingActor: unknown;
95
- targetActor: unknown;
96
- computedOutcomeTemplate: unknown;
97
- sessionId: unknown;
98
- windowOpensAtMicros: unknown;
99
- windowClosesAtMicros: unknown;
100
- depth: unknown;
101
- bundleId: unknown;
102
- };
103
- options.push({
104
- pending_id: bigint(pending.pendingId),
105
- reactor_id: asString(reactor.entityRef),
106
- originating_action_id: asString(pending.originatingActionId),
107
- originating_actor: asString(pending.originatingActor),
108
- target_actor: asString(pending.targetActor),
109
- target_entity_faction: disclosedTargetFaction(
110
- asString(pending.targetActor),
111
- perceivedTargets,
112
- factions,
113
- ),
114
- computed_outcome_template: asString(pending.computedOutcomeTemplate),
115
- session_id: bigint(pending.sessionId),
116
- window_opens_at_micros: asNumber(pending.windowOpensAtMicros),
117
- window_closes_at_micros: asNumber(pending.windowClosesAtMicros),
118
- depth: asNumber(pending.depth),
119
- bundle_id: asString(pending.bundleId),
120
- });
121
- }
122
- return options.sort((a, b) =>
123
- a.window_closes_at_micros !== b.window_closes_at_micros
124
- ? a.window_closes_at_micros - b.window_closes_at_micros
125
- : a.pending_id < b.pending_id
126
- ? -1
127
- : a.pending_id > b.pending_id
128
- ? 1
129
- : 0,
130
- );
131
- }
132
-
133
- /** Factored target facts replace the eager action × target listing for this
134
- * reaction-side classification. A reaction remains its own bounded surface;
135
- * this only avoids rebuilding ordinary offers to learn target visibility. */
136
- function perceivedManipulationTargetIds(db: SnapshotDb, perceiverId: bigint): Set<string> {
137
- const out = new Set<string>();
138
- for (const row of rows<DbManipulationObservedTargetRow>(
139
- db,
140
- "visible_manipulation_observed_target",
141
- )) {
142
- if (row.perceiverEntityId !== perceiverId) continue;
143
- const targetRef = targetRefToString(row.targetRef);
144
- if (targetRef.startsWith("entity:")) out.add(targetRef.slice("entity:".length));
145
- }
146
- return out;
147
- }
148
-
149
- function disclosedTargetFaction(
150
- targetActor: string,
151
- perceivedTargets: Set<string>,
152
- factions: Map<string, string>,
153
- ): string | null {
154
- if (targetActor.length === 0 || !perceivedTargets.has(targetActor)) return null;
155
- return factions.get(targetActor) ?? null;
156
- }
@@ -1,47 +0,0 @@
1
- import type { EventResourceDeltaRow as DbEventResourceDeltaRow } from "../../binding_rows";
2
- import {
3
- type RequiredTables,
4
- registerReaderManifest,
5
- type SnapshotDb,
6
- } from "../../reader-manifest";
7
- import { asNumber, asString, optionNumber, optString, rows } from "./_helpers";
8
-
9
- // `event_resource_delta` is private (ADR-0120, #915) — the single
10
- // highest-sensitivity table in the sweep. Subscribe + read the per-caller
11
- // `visible_event_resource_delta` view instead (owner/DM-extent-bounded).
12
- export const requiredTables: RequiredTables<["visible_event_resource_delta"]> = [
13
- "visible_event_resource_delta",
14
- ];
15
- registerReaderManifest({ requiredTables });
16
-
17
- export interface ResourceDeltaEventRow {
18
- event_id: string;
19
- entity_id: string;
20
- resource_id: string;
21
- delta: number;
22
- /** Remaining resource after the delta. `undefined` when the view redacted
23
- * it (caller admitted only as source — ADR-0120 / T29 / #2215). */
24
- new_value?: number;
25
- template_id: string;
26
- /** ADR-0093 B2: the attacker/actor entity that caused this delta, denormalised
27
- * onto the row at emit time (mirrors `event_apply_consequence`'s
28
- * `source_entity_ref`). `undefined` for an ambient/ownerless delta — the
29
- * server carries this as an empty string (`String`, not `Option<u64>`), so an
30
- * empty value maps to `undefined` here, never `""`. */
31
- source_entity_ref?: string;
32
- }
33
-
34
- export function readRecentResourceDeltas(db: SnapshotDb, n: number): ResourceDeltaEventRow[] {
35
- if (n <= 0) return [];
36
- const all = rows<DbEventResourceDeltaRow>(db, "visible_event_resource_delta").map((row) => ({
37
- event_id: asString(row.eventId),
38
- entity_id: asString(row.entityId),
39
- resource_id: row.resourceId,
40
- delta: asNumber(row.delta),
41
- new_value: optionNumber(row.newValue),
42
- template_id: row.templateId,
43
- source_entity_ref: optString(row.sourceEntityRef),
44
- }));
45
- all.sort((a, b) => b.event_id.localeCompare(a.event_id, undefined, { numeric: true }));
46
- return all.slice(0, n);
47
- }