@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,163 +0,0 @@
1
- // Per-reducer wrapper for r_manipulate.
2
- // Ported from actor_control.ts; Phase 4 lagWarning + observedAtTick threaded.
3
-
4
- import type { SnapshotDb } from "../../connection";
5
- import { observeReducerAttempt, type ReducerAttemptTelemetry } from "../../provenance";
6
- import type { RManipulateFn } from "../actor_control_source";
7
- import type { EntityRef } from "../ids";
8
- import type { ProvenanceRingBuffer } from "../provenance_buffer";
9
- import type { TickIntervalEstimator } from "../tick_cadence";
10
- import type {
11
- ActorManipulateRejected,
12
- ActorManipulateResult,
13
- ActorManipulateSuccess,
14
- ActorManipulateUnobservable,
15
- ActorManipulateUnobservedNoProvenance,
16
- ActorManipulateUnobservedTimeout,
17
- } from "../types";
18
- import { manipulationArgsFromJson } from "./manipulation_args";
19
- import { manipulationReceipt } from "./manipulation_receipt";
20
- import { actorEntityId, targetRefFromString } from "./transport";
21
-
22
- export async function rManipulateWrapper<T>(
23
- actorId: EntityRef,
24
- targetId: string,
25
- actionId: string,
26
- argsJson: string,
27
- snapshotDb: () => SnapshotDb,
28
- rManipulate: RManipulateFn,
29
- successPredicate: (db: SnapshotDb) => boolean,
30
- collectSnapshot: (db: SnapshotDb) => T | null,
31
- timeoutMs: number,
32
- pollMs: number,
33
- tickEstimator?: TickIntervalEstimator,
34
- provenanceBuffer?: ProvenanceRingBuffer,
35
- successOnProvenance = false,
36
- telemetry?: ReducerAttemptTelemetry,
37
- ): Promise<ActorManipulateResult<T>> {
38
- // Keep malformed JSON on the existing observed-rejection path. Only a
39
- // well-formed enrollment request requires protocol discovery before dispatch.
40
- let args: ReturnType<typeof manipulationArgsFromJson> | undefined;
41
- try {
42
- args = manipulationArgsFromJson(argsJson);
43
- } catch {
44
- /* invoke reports parsing failure */
45
- }
46
- if (args?.participantEntityIds !== undefined) {
47
- const db = snapshotDb();
48
- const contract = db.manipulationContract ?? db.manipulation_contract;
49
- if (
50
- ![...(contract?.iter() ?? [])].some(
51
- (row) =>
52
- row.argumentId === "participant_entity_ids" ||
53
- row.argument_id === "participant_entity_ids",
54
- )
55
- ) {
56
- throw new Error(
57
- "OpenSession: module does not support participant_entity_ids; publish the compatible module before activating session setup",
58
- );
59
- }
60
- }
61
- const receipt = manipulationReceipt(snapshotDb(), actorId, () => args);
62
- const result = await (async () => {
63
- try {
64
- return await observeReducerAttempt<T>({
65
- db: snapshotDb,
66
- subjectId: actorId,
67
- invoke: async () => {
68
- try {
69
- args ??= manipulationArgsFromJson(argsJson);
70
- await rManipulate({
71
- actorId: actorEntityId(actorId),
72
- targetRef: targetRefFromString(targetId),
73
- actionId,
74
- args,
75
- });
76
- receipt.settle();
77
- } catch (error) {
78
- receipt.fail();
79
- throw error;
80
- }
81
- },
82
- provenancePredicate: receipt.matches,
83
- settledEarly: (_db, invokeSettled) => invokeSettled && receipt.unattributable(),
84
- successPredicate: (db) =>
85
- receipt.succeeded() && (successOnProvenance || successPredicate(db)),
86
- collectSnapshot,
87
- timeoutMs,
88
- pollMs,
89
- tickEstimator,
90
- provenanceBuffer,
91
- successOnProvenance: false,
92
- telemetry,
93
- telemetryAttributes: {
94
- "spellkave.reducer": "r_manipulate",
95
- "spellkave.actor_id": actorId,
96
- "spellkave.action_id": actionId,
97
- "spellkave.target_ref": targetId,
98
- },
99
- });
100
- } finally {
101
- receipt.close();
102
- }
103
- })();
104
-
105
- if (result.status === "success") {
106
- return {
107
- status: "success",
108
- actor_id: actorId,
109
- target_id: targetId,
110
- action_id: actionId,
111
- // biome-ignore lint/style/noNonNullAssertion: pre-existing debt from #1368 biome onboarding, tracked in #1455
112
- snapshot: result.snapshot!,
113
- // #1968 B-9: was dropped here — every other ActorManipulateResult
114
- // variant already carries it (see rejected/unobserved branches below).
115
- provenance: result.provenance ?? undefined,
116
- lagWarning: result.lagWarning,
117
- observedAtTick: result.observedAtTick,
118
- } satisfies ActorManipulateSuccess<T>;
119
- }
120
-
121
- if (result.status === "rejected") {
122
- return {
123
- status: "rejected",
124
- actor_id: actorId,
125
- target_id: targetId,
126
- action_id: actionId,
127
- snapshot: result.snapshot,
128
- reason: `r_manipulate rejected by server`,
129
- provenance: result.provenance ?? undefined,
130
- lagWarning: result.lagWarning,
131
- observedAtTick: result.observedAtTick,
132
- } satisfies ActorManipulateRejected<T>;
133
- }
134
-
135
- if (result.status === "unobserved_timeout") {
136
- return {
137
- status: "unobserved_timeout",
138
- actor_id: actorId,
139
- target_id: targetId,
140
- action_id: actionId,
141
- snapshot: result.snapshot,
142
- reason: `manipulate '${actionId}' on '${targetId}' not observed within ${timeoutMs}ms`,
143
- provenance: result.provenance ?? undefined,
144
- lagWarning: result.lagWarning,
145
- observedAtTick: result.observedAtTick,
146
- } satisfies ActorManipulateUnobservedTimeout<T>;
147
- }
148
-
149
- return {
150
- status: result.status,
151
- actor_id: actorId,
152
- target_id: targetId,
153
- action_id: actionId,
154
- snapshot: result.snapshot,
155
- reason:
156
- result.status === "unobservable"
157
- ? `manipulate '${actionId}' on '${targetId}' settled without an attributable receipt`
158
- : `manipulate '${actionId}' on '${targetId}' not observed within ${timeoutMs}ms`,
159
- provenance: result.provenance ?? undefined,
160
- lagWarning: result.lagWarning,
161
- observedAtTick: result.observedAtTick,
162
- } satisfies ActorManipulateUnobservedNoProvenance<T> | ActorManipulateUnobservable<T>;
163
- }
@@ -1,155 +0,0 @@
1
- // Per-reducer wrapper for r_move.
2
- // Ported from actor_control.ts; Phase 4 lagWarning + observedAtTick threaded.
3
-
4
- import { type SnapshotDb, snapshotFromDb } from "../../connection";
5
- import { observeReducerAttempt } from "../../provenance";
6
- import type { RMoveFn } from "../actor_control_source";
7
- import type { EntityRef } from "../ids";
8
- import type { PlaceEdgeRow } from "../movement";
9
- import type { ProvenanceRingBuffer } from "../provenance_buffer";
10
- import { readActorSnapshot } from "../readers/actor_snapshot";
11
- import { travelSessionForActor } from "../readers/travel_session";
12
- import type { TickIntervalEstimator } from "../tick_cadence";
13
- import type {
14
- ActorMoveRejected,
15
- ActorMoveResult,
16
- ActorMoveSuccess,
17
- ActorMoveTravelling,
18
- ActorMoveUnobservable,
19
- ActorMoveUnobservedNoProvenance,
20
- ActorMoveUnobservedTimeout,
21
- } from "../types";
22
- import { actorEntityId } from "./transport";
23
-
24
- // snapshotFromDb normalises camelCase binding rows to snake_case PlaceEdgeRow —
25
- // keeps lookup host-neutral for both live DbConnection.db and SnapshotDb fakes.
26
- function lookupEdge(db: SnapshotDb, edgeId: string): PlaceEdgeRow | undefined {
27
- for (const e of snapshotFromDb(db).movement.edges()) {
28
- if (e.edge_id === edgeId) return e;
29
- }
30
- return undefined;
31
- }
32
-
33
- export async function rMoveWrapper(
34
- actorId: EntityRef,
35
- edgeId: string,
36
- snapshotDb: () => SnapshotDb,
37
- rMove: RMoveFn,
38
- timeoutMs: number,
39
- pollMs: number,
40
- tickEstimator?: TickIntervalEstimator,
41
- provenanceBuffer?: ProvenanceRingBuffer,
42
- ): Promise<ActorMoveResult> {
43
- const edgeLookup = lookupEdge(snapshotDb(), edgeId);
44
- const fromNode = edgeLookup?.from_node_id ?? "";
45
- const toNode = edgeLookup?.to_node_id ?? "";
46
-
47
- const result = await observeReducerAttempt({
48
- db: snapshotDb,
49
- subjectId: actorId,
50
- invoke: () => rMove({ actorId: actorEntityId(actorId), fromNode, toNode, edgeId }),
51
- successPredicate: (db) =>
52
- toNode !== "" && readActorSnapshot(db, actorId)?.current_node_id === toNode,
53
- collectSnapshot: (db) => readActorSnapshot(db, actorId),
54
- // Stop waiting the moment the world has promoted this into a walk: the
55
- // actor cannot arrive within `timeoutMs` and the server has already
56
- // priced the journey, so burning the full timeout only delays an answer
57
- // that is available now (feat/travel-eta, 2026-08-18).
58
- settledEarly: (db) => travelSessionForActor(db as never, actorId) !== null,
59
- timeoutMs,
60
- pollMs,
61
- tickEstimator,
62
- provenanceBuffer,
63
- // Both instant-move success and movement rejection are emitted with
64
- // next_provenance_id(ctx, "r_move") in layer2/r_move.rs. Promoted travel
65
- // emits a session instead (long_running_move.rs::begin_over_reach_travel).
66
- // A same-subject claim_released row is an independent clock-sweep or
67
- // explicit-release event, even if it arrives after this attempt's baseline.
68
- provenancePredicate: (row) => row.id.startsWith("r_move:"),
69
- });
70
-
71
- if (result.status === "success") {
72
- return {
73
- status: "success",
74
- actor_id: actorId,
75
- edge_id: edgeId,
76
- from_node: fromNode,
77
- to_node: toNode,
78
- // biome-ignore lint/style/noNonNullAssertion: pre-existing debt from #1368 biome onboarding, tracked in #1455
79
- actor_snapshot: result.snapshot!,
80
- provenance: result.provenance ?? undefined,
81
- lagWarning: result.lagWarning,
82
- observedAtTick: result.observedAtTick,
83
- } satisfies ActorMoveSuccess;
84
- }
85
-
86
- if (result.status === "rejected") {
87
- return {
88
- status: "rejected",
89
- actor_id: actorId,
90
- edge_id: edgeId,
91
- from_node: fromNode,
92
- to_node: toNode,
93
- actor_snapshot: result.snapshot,
94
- reason: `r_move rejected by server`,
95
- provenance: result.provenance ?? undefined,
96
- lagWarning: result.lagWarning,
97
- observedAtTick: result.observedAtTick,
98
- } satisfies ActorMoveRejected;
99
- }
100
-
101
- // The actor is not at `toNode` — but "did not arrive" and "was refused" are
102
- // not the only two answers. A move longer than the actor's reach is ADMITTED
103
- // and promoted into a session that walks them one tick at a time, and the
104
- // server priced that walk at admission. Ask before reporting a non-arrival:
105
- // otherwise every long journey is reported as a 2000ms timeout on a move
106
- // that in fact succeeded in starting (feat/travel-eta, 2026-08-18).
107
- const travel = travelSessionForActor(snapshotDb() as never, actorId);
108
- if (travel !== null) {
109
- return {
110
- status: "travelling",
111
- actor_id: actorId,
112
- edge_id: edgeId,
113
- from_node: fromNode,
114
- to_node: toNode,
115
- actor_snapshot: result.snapshot,
116
- arrives_in_ticks: Number(travel.arrivesInTicks),
117
- arrives_at_tick: Number(travel.arrivesAtTick),
118
- session_id: String(travel.sessionId),
119
- reason:
120
- `travelling to '${toNode}' — arrives in ${travel.arrivesInTicks} ` +
121
- `tick${travel.arrivesInTicks === 1n ? "" : "s"} (at tick ${travel.arrivesAtTick})`,
122
- provenance: result.provenance ?? undefined,
123
- lagWarning: result.lagWarning,
124
- observedAtTick: result.observedAtTick,
125
- } satisfies ActorMoveTravelling;
126
- }
127
-
128
- if (result.status === "unobserved_timeout") {
129
- return {
130
- status: "unobserved_timeout",
131
- actor_id: actorId,
132
- edge_id: edgeId,
133
- from_node: fromNode,
134
- to_node: toNode,
135
- actor_snapshot: result.snapshot,
136
- reason: `actor '${actorId}' did not reach '${toNode}' within ${timeoutMs}ms`,
137
- provenance: result.provenance ?? undefined,
138
- lagWarning: result.lagWarning,
139
- observedAtTick: result.observedAtTick,
140
- } satisfies ActorMoveUnobservedTimeout;
141
- }
142
-
143
- return {
144
- status: result.status,
145
- actor_id: actorId,
146
- edge_id: edgeId,
147
- from_node: fromNode,
148
- to_node: toNode,
149
- actor_snapshot: result.snapshot,
150
- reason: `actor '${actorId}' did not reach '${toNode}' within ${timeoutMs}ms`,
151
- provenance: result.provenance ?? undefined,
152
- lagWarning: result.lagWarning,
153
- observedAtTick: result.observedAtTick,
154
- } satisfies ActorMoveUnobservedNoProvenance | ActorMoveUnobservable;
155
- }
@@ -1,143 +0,0 @@
1
- // Per-reducer wrapper for r_react (#509 — react to a pending_resolution;
2
- // #2058 extended it to also cover post-roll intervention windows).
3
- //
4
- // STATE-OBSERVED, two shapes depending on what the caller's baseline snapshot
5
- // shows for this pendingId:
6
- // - Multi-actor reaction seat (the original #509 shape): the subscribed
7
- // `visible_pending_resolution_reactor` view exposes the caller's own
8
- // reaction seat row. A successful reaction either flips that seat to
9
- // `reacted=true` or removes it when the pending resolution closes.
10
- // - Post-roll intervention window (#2058): a stochastic action parks with
11
- // NO reactor-seat row at all — the eligible responder is `target_actor`
12
- // on the `visible_pending_resolution` row itself (see
13
- // `readInterventionWindowsForActor`). There, success is observed as that
14
- // SAME pending_resolution row disappearing (decline or accept both close
15
- // the window outright; there is only ever one responder).
16
- // Whichever shape the baseline snapshot shows is what this call polls for —
17
- // the two are mutually exclusive per pendingId, so there is no ambiguity.
18
- // The server emits no evaluation provenance for r_react either way, so these
19
- // subscribed views are the authoritative observable success signal.
20
-
21
- import type { DbConnection } from "@spellkave/bindings";
22
- import type { PendingResolutionRow } from "../../binding_rows";
23
- import type { SnapshotDb } from "../../connection";
24
- import { observeReducerAttempt } from "../../provenance";
25
- import type { EntityRef } from "../ids";
26
- import type { ProvenanceRingBuffer } from "../provenance_buffer";
27
- import { asString, rows } from "../readers/_helpers";
28
- import type { TickIntervalEstimator } from "../tick_cadence";
29
- import type { ActorReactResult } from "../types";
30
- import { actorEntityId } from "./transport";
31
-
32
- export type RReactFn = DbConnection["reducers"]["rReact"];
33
-
34
- export async function rReactWrapper(
35
- actorId: EntityRef,
36
- pendingId: bigint,
37
- responseIntent: string,
38
- snapshotDb: () => SnapshotDb,
39
- rReact: RReactFn,
40
- timeoutMs: number,
41
- pollMs: number,
42
- tickEstimator?: TickIntervalEstimator,
43
- provenanceBuffer?: ProvenanceRingBuffer,
44
- selectedDrawIndex?: number,
45
- ): Promise<ActorReactResult> {
46
- const reactorId = actorEntityId(actorId);
47
- const matchingSeat = (db: SnapshotDb) =>
48
- rows<Record<string, unknown>>(db, "visible_pending_resolution_reactor").find(
49
- (row) =>
50
- String(row.pendingId) === String(pendingId) &&
51
- asString(row.entityRef) === String(reactorId),
52
- );
53
- const pendingRowExists = (db: SnapshotDb) =>
54
- rows<PendingResolutionRow>(db, "visible_pending_resolution").some(
55
- (row) => String((row as unknown as { pendingId: unknown }).pendingId) === String(pendingId),
56
- );
57
-
58
- const baselineDb = snapshotDb();
59
- const baselineSeat = matchingSeat(baselineDb);
60
- // A seat row exists for the general multi-actor reaction shape; its absence
61
- // means this pendingId is (if anything) an intervention window instead —
62
- // there the pending_resolution row's own presence is the eligibility check.
63
- const seatMode = baselineSeat !== undefined;
64
- const baselineWasEligible = seatMode
65
- ? baselineSeat.reacted !== true
66
- : pendingRowExists(baselineDb);
67
-
68
- // Acting actor = reactor_id. Args pass 1:1 to the generated accessor (CLAUDE.md §1).
69
- const result = await observeReducerAttempt<null>({
70
- db: snapshotDb,
71
- subjectId: actorId,
72
- invoke: () => rReact({ reactorId, pendingId, responseIntent, selectedDrawIndex }),
73
- successPredicate: (db) => {
74
- if (!baselineWasEligible) return false;
75
- if (seatMode) {
76
- const seat = matchingSeat(db);
77
- return seat === undefined || seat.reacted === true;
78
- }
79
- return !pendingRowExists(db);
80
- },
81
- collectSnapshot: () => null,
82
- timeoutMs,
83
- pollMs,
84
- tickEstimator,
85
- provenanceBuffer,
86
- });
87
-
88
- const selectedDrawIndexField =
89
- selectedDrawIndex === undefined ? {} : { selected_draw_index: selectedDrawIndex };
90
-
91
- if (result.status === "success") {
92
- return {
93
- status: "success",
94
- actor_id: actorId,
95
- pending_id: pendingId,
96
- response_intent: responseIntent,
97
- ...selectedDrawIndexField,
98
- provenance: result.provenance ?? undefined,
99
- lagWarning: result.lagWarning,
100
- observedAtTick: result.observedAtTick,
101
- };
102
- }
103
-
104
- if (result.status === "rejected") {
105
- return {
106
- status: "rejected",
107
- actor_id: actorId,
108
- pending_id: pendingId,
109
- response_intent: responseIntent,
110
- ...selectedDrawIndexField,
111
- reason: "r_react rejected by server",
112
- provenance: result.provenance ?? undefined,
113
- lagWarning: result.lagWarning,
114
- observedAtTick: result.observedAtTick,
115
- };
116
- }
117
-
118
- if (result.status === "unobserved_timeout") {
119
- return {
120
- status: "unobserved_timeout",
121
- actor_id: actorId,
122
- pending_id: pendingId,
123
- response_intent: responseIntent,
124
- ...selectedDrawIndexField,
125
- reason: `r_react on pending ${pendingId} not observed within ${timeoutMs}ms`,
126
- provenance: result.provenance ?? undefined,
127
- lagWarning: result.lagWarning,
128
- observedAtTick: result.observedAtTick,
129
- };
130
- }
131
-
132
- return {
133
- status: result.status,
134
- actor_id: actorId,
135
- pending_id: pendingId,
136
- response_intent: responseIntent,
137
- ...selectedDrawIndexField,
138
- reason: `r_react on pending ${pendingId} not observed within ${timeoutMs}ms`,
139
- provenance: result.provenance ?? undefined,
140
- lagWarning: result.lagWarning,
141
- observedAtTick: result.observedAtTick,
142
- };
143
- }
@@ -1,81 +0,0 @@
1
- // Per-reducer wrapper for r_release_claim (multiplayer claim/lock contention).
2
- // Provenance-observed: the claim module emits evaluation_provenance, so success
3
- // is read from the server's verdict rather than a bespoke state predicate
4
- // (no client-side validation — @spellkave/sdk CLAUDE.md §1).
5
-
6
- import type { DbConnection } from "@spellkave/bindings";
7
- import type { SnapshotDb } from "../../connection";
8
- import { observeReducerAttempt } from "../../provenance";
9
- import type { EntityRef } from "../ids";
10
- import type { ProvenanceRingBuffer } from "../provenance_buffer";
11
- import type { TickIntervalEstimator } from "../tick_cadence";
12
-
13
- type RReleaseClaimFn = DbConnection["reducers"]["rReleaseClaim"];
14
-
15
- export interface ActorReleaseClaimResult {
16
- status:
17
- | "success"
18
- | "rejected"
19
- | "unobserved_timeout"
20
- | "unobserved_no_provenance"
21
- | "unobservable";
22
- actor_id: EntityRef;
23
- target_id: string;
24
- reason?: string;
25
- lagWarning: boolean;
26
- observedAtTick: bigint;
27
- }
28
-
29
- export async function rReleaseClaimWrapper(
30
- actorId: EntityRef,
31
- targetId: string,
32
- snapshotDb: () => SnapshotDb,
33
- rReleaseClaim: RReleaseClaimFn,
34
- timeoutMs: number,
35
- pollMs: number,
36
- tickEstimator?: TickIntervalEstimator,
37
- provenanceBuffer?: ProvenanceRingBuffer,
38
- ): Promise<ActorReleaseClaimResult> {
39
- const result = await observeReducerAttempt<null>({
40
- db: snapshotDb,
41
- subjectId: actorId,
42
- invoke: () => rReleaseClaim({ actorId, targetId }),
43
- successPredicate: () => false,
44
- collectSnapshot: () => null,
45
- timeoutMs,
46
- pollMs,
47
- tickEstimator,
48
- provenanceBuffer,
49
- successOnProvenance: true,
50
- });
51
-
52
- if (result.status === "success") {
53
- return {
54
- status: "success",
55
- actor_id: actorId,
56
- target_id: targetId,
57
- lagWarning: result.lagWarning,
58
- observedAtTick: result.observedAtTick,
59
- };
60
- }
61
-
62
- if (result.status === "rejected") {
63
- return {
64
- status: "rejected",
65
- actor_id: actorId,
66
- target_id: targetId,
67
- reason: "r_release_claim rejected by server",
68
- lagWarning: result.lagWarning,
69
- observedAtTick: result.observedAtTick,
70
- };
71
- }
72
-
73
- return {
74
- status: result.status,
75
- actor_id: actorId,
76
- target_id: targetId,
77
- reason: `r_release_claim on '${targetId}' not observed within ${timeoutMs}ms`,
78
- lagWarning: result.lagWarning,
79
- observedAtTick: result.observedAtTick,
80
- };
81
- }
@@ -1,84 +0,0 @@
1
- import type { DbConnection } from "@spellkave/bindings";
2
- import type { SnapshotDb } from "../../connection";
3
- import { observeReducerAttempt } from "../../provenance";
4
- import type { EntityRef } from "../ids";
5
- import type { ProvenanceRingBuffer } from "../provenance_buffer";
6
- import type { TickIntervalEstimator } from "../tick_cadence";
7
- import type { ActorSenseResult } from "../types";
8
- import { actorEntityId } from "./transport";
9
-
10
- export type RSenseFn = DbConnection["reducers"]["rSense"];
11
-
12
- export async function rSenseWrapper(
13
- actorId: EntityRef,
14
- queryKind: string,
15
- visibilityClass: string,
16
- snapshotDb: () => SnapshotDb,
17
- rSense: RSenseFn,
18
- timeoutMs: number,
19
- pollMs: number,
20
- tickEstimator?: TickIntervalEstimator,
21
- provenanceBuffer?: ProvenanceRingBuffer,
22
- ): Promise<ActorSenseResult> {
23
- const result = await observeReducerAttempt<null>({
24
- db: snapshotDb,
25
- subjectId: actorId,
26
- invoke: () => rSense({ actorId: actorEntityId(actorId), queryKind, visibilityClass }),
27
- successPredicate: () => false,
28
- collectSnapshot: () => null,
29
- timeoutMs,
30
- pollMs,
31
- tickEstimator,
32
- successOnProvenance: true,
33
- provenanceBuffer,
34
- });
35
-
36
- if (result.status === "success") {
37
- return {
38
- status: "success",
39
- actor_id: actorId,
40
- query_kind: queryKind,
41
- visibility_class: visibilityClass,
42
- provenance: result.provenance ?? undefined,
43
- lagWarning: result.lagWarning,
44
- observedAtTick: result.observedAtTick,
45
- };
46
- }
47
-
48
- if (result.status === "rejected") {
49
- return {
50
- status: "rejected",
51
- actor_id: actorId,
52
- query_kind: queryKind,
53
- visibility_class: visibilityClass,
54
- reason: "r_sense rejected by server",
55
- provenance: result.provenance ?? undefined,
56
- lagWarning: result.lagWarning,
57
- observedAtTick: result.observedAtTick,
58
- };
59
- }
60
-
61
- if (result.status === "unobserved_timeout") {
62
- return {
63
- status: "unobserved_timeout",
64
- actor_id: actorId,
65
- query_kind: queryKind,
66
- visibility_class: visibilityClass,
67
- reason: `r_sense '${queryKind}' not observed within ${timeoutMs}ms`,
68
- provenance: result.provenance ?? undefined,
69
- lagWarning: result.lagWarning,
70
- observedAtTick: result.observedAtTick,
71
- };
72
- }
73
-
74
- return {
75
- status: result.status,
76
- actor_id: actorId,
77
- query_kind: queryKind,
78
- visibility_class: visibilityClass,
79
- reason: `r_sense '${queryKind}' not observed within ${timeoutMs}ms`,
80
- provenance: result.provenance ?? undefined,
81
- lagWarning: result.lagWarning,
82
- observedAtTick: result.observedAtTick,
83
- };
84
- }