@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,130 +0,0 @@
1
- // Per-reducer wrapper for r_session_close.
2
- // Success predicate: the existing session row disappears or reaches the
3
- // requested terminal lifecycle in the subscribed session table.
4
-
5
- import type { DbConnection } from "@spellkave/bindings";
6
- import type { SnapshotDb } from "../../connection";
7
- import { observeReducerAttempt } from "../../provenance";
8
- import type { DriverToken } from "../driver_control";
9
- import type { ProvenanceRingBuffer } from "../provenance_buffer";
10
- import type { TickIntervalEstimator } from "../tick_cadence";
11
- import { firstPopulatedHandle } from "./session_lookup";
12
-
13
- export type RSessionCloseFn = DbConnection["reducers"]["rSessionClose"];
14
-
15
- export interface SessionCloseSnapshot {
16
- sessionId: bigint;
17
- lifecycle: string;
18
- lastAdvancedAt: bigint;
19
- }
20
-
21
- export interface SessionCloseResult {
22
- status:
23
- | "success"
24
- | "rejected"
25
- | "unobserved_timeout"
26
- | "unobserved_no_provenance"
27
- | "unobservable";
28
- sessionId: bigint;
29
- outcome: string;
30
- session?: SessionCloseSnapshot;
31
- reason?: string;
32
- lagWarning: boolean;
33
- observedAtTick: bigint;
34
- }
35
-
36
- export async function rSessionCloseWrapper(
37
- actorId: string,
38
- sessionId: bigint,
39
- outcome: string,
40
- snapshotDb: () => SnapshotDb,
41
- rSessionClose: RSessionCloseFn,
42
- timeoutMs: number,
43
- pollMs: number,
44
- tickEstimator?: TickIntervalEstimator,
45
- provenanceBuffer?: ProvenanceRingBuffer,
46
- driverToken?: DriverToken,
47
- driverTokens?: readonly DriverToken[],
48
- ): Promise<SessionCloseResult> {
49
- // Copy the observations supplied with this decision. Never refresh them
50
- // from the live reader during dispatch or while polling the outcome.
51
- const frozenToken = driverToken ? Object.freeze({ ...driverToken }) : undefined;
52
- const frozenTokens = driverTokens?.map((token) => Object.freeze({ ...token }));
53
- const existedBeforeInvoke = findSession(snapshotDb(), sessionId) !== undefined;
54
- const result = await observeReducerAttempt<SessionCloseSnapshot | null>({
55
- db: snapshotDb,
56
- subjectId: actorId,
57
- invoke: () =>
58
- rSessionClose({
59
- sessionId,
60
- outcome,
61
- ...(frozenToken ? { driverToken: frozenToken } : {}),
62
- ...(frozenTokens ? { driverTokens: frozenTokens } : {}),
63
- }),
64
- successPredicate: (db) => {
65
- if (!existedBeforeInvoke) return false;
66
- const row = findSession(db, sessionId);
67
- // Current server behavior updates the session in place; disappearance is
68
- // reserved for a future terminal-row cleanup path.
69
- return row === undefined || row.lifecycle === outcome;
70
- },
71
- collectSnapshot: (db) => findSession(db, sessionId) ?? null,
72
- timeoutMs,
73
- pollMs,
74
- tickEstimator,
75
- provenanceBuffer,
76
- });
77
-
78
- if (result.status === "success") {
79
- return {
80
- status: "success",
81
- sessionId,
82
- outcome,
83
- session: result.snapshot ?? undefined,
84
- lagWarning: result.lagWarning,
85
- observedAtTick: result.observedAtTick,
86
- };
87
- }
88
-
89
- if (result.status === "rejected") {
90
- return {
91
- status: "rejected",
92
- sessionId,
93
- outcome,
94
- session: result.snapshot ?? undefined,
95
- reason: "r_session_close rejected by server",
96
- lagWarning: result.lagWarning,
97
- observedAtTick: result.observedAtTick,
98
- };
99
- }
100
-
101
- return {
102
- status: result.status,
103
- sessionId,
104
- outcome,
105
- session: result.snapshot ?? undefined,
106
- reason: `r_session_close for session '${sessionId}' not observed within ${timeoutMs}ms`,
107
- lagWarning: result.lagWarning,
108
- observedAtTick: result.observedAtTick,
109
- };
110
- }
111
-
112
- function findSession(db: SnapshotDb, sessionId: bigint): SessionCloseSnapshot | undefined {
113
- const handle = firstPopulatedHandle(db, "visible_session", "session");
114
- if (!handle) return undefined;
115
- for (const raw of handle.iter()) {
116
- const r = raw as unknown as { sessionId: unknown; lifecycle: string; lastAdvancedAt: unknown };
117
- if (toBigInt(r.sessionId) === sessionId) {
118
- return {
119
- sessionId,
120
- lifecycle: r.lifecycle,
121
- lastAdvancedAt: toBigInt(r.lastAdvancedAt),
122
- };
123
- }
124
- }
125
- return undefined;
126
- }
127
-
128
- function toBigInt(value: unknown): bigint {
129
- return typeof value === "bigint" ? value : BigInt(String(value ?? 0));
130
- }
@@ -1,116 +0,0 @@
1
- // Per-reducer wrapper for r_session_move.
2
- // Success predicate: the session row advances from its pre-call lifecycle clock
3
- // or transitions lifecycle, as observed in the subscribed session table.
4
-
5
- import type { DbConnection } from "@spellkave/bindings";
6
- import type { SnapshotDb } from "../../connection";
7
- import { observeReducerAttempt } from "../../provenance";
8
- import type { ProvenanceRingBuffer } from "../provenance_buffer";
9
- import type { TickIntervalEstimator } from "../tick_cadence";
10
- import { firstPopulatedHandle } from "./session_lookup";
11
-
12
- export type RSessionMoveFn = DbConnection["reducers"]["rSessionMove"];
13
-
14
- export interface SessionMoveSnapshot {
15
- sessionId: bigint;
16
- lifecycle: string;
17
- lastAdvancedAt: bigint;
18
- }
19
-
20
- export interface SessionMoveResult {
21
- status:
22
- | "success"
23
- | "rejected"
24
- | "unobserved_timeout"
25
- | "unobserved_no_provenance"
26
- | "unobservable";
27
- sessionId: bigint;
28
- moveTemplateId: string;
29
- session: SessionMoveSnapshot | null;
30
- reason?: string;
31
- lagWarning: boolean;
32
- observedAtTick: bigint;
33
- }
34
-
35
- export async function rSessionMoveWrapper(
36
- actorId: string,
37
- sessionId: bigint,
38
- moveTemplateId: string,
39
- snapshotDb: () => SnapshotDb,
40
- rSessionMove: RSessionMoveFn,
41
- timeoutMs: number,
42
- pollMs: number,
43
- tickEstimator?: TickIntervalEstimator,
44
- provenanceBuffer?: ProvenanceRingBuffer,
45
- ): Promise<SessionMoveResult> {
46
- const before = findSession(snapshotDb(), sessionId);
47
- const result = await observeReducerAttempt<SessionMoveSnapshot | null>({
48
- db: snapshotDb,
49
- subjectId: actorId,
50
- invoke: () => rSessionMove({ sessionId, moveTemplateId }),
51
- successPredicate: (db) => {
52
- if (before === undefined) return false;
53
- const row = findSession(db, sessionId);
54
- if (row === undefined) return false;
55
- return row.lastAdvancedAt !== before.lastAdvancedAt || row.lifecycle !== before.lifecycle;
56
- },
57
- collectSnapshot: (db) => findSession(db, sessionId) ?? null,
58
- timeoutMs,
59
- pollMs,
60
- tickEstimator,
61
- provenanceBuffer,
62
- });
63
-
64
- if (result.status === "success") {
65
- return {
66
- status: "success",
67
- sessionId,
68
- moveTemplateId,
69
- session: result.snapshot,
70
- lagWarning: result.lagWarning,
71
- observedAtTick: result.observedAtTick,
72
- };
73
- }
74
-
75
- if (result.status === "rejected") {
76
- return {
77
- status: "rejected",
78
- sessionId,
79
- moveTemplateId,
80
- session: result.snapshot,
81
- reason: "r_session_move rejected by server",
82
- lagWarning: result.lagWarning,
83
- observedAtTick: result.observedAtTick,
84
- };
85
- }
86
-
87
- return {
88
- status: result.status,
89
- sessionId,
90
- moveTemplateId,
91
- session: result.snapshot,
92
- reason: `r_session_move '${moveTemplateId}' for session '${sessionId}' not observed within ${timeoutMs}ms`,
93
- lagWarning: result.lagWarning,
94
- observedAtTick: result.observedAtTick,
95
- };
96
- }
97
-
98
- function findSession(db: SnapshotDb, sessionId: bigint): SessionMoveSnapshot | undefined {
99
- const handle = firstPopulatedHandle(db, "visible_session", "session");
100
- if (!handle) return undefined;
101
- for (const raw of handle.iter()) {
102
- const r = raw as unknown as { sessionId: unknown; lifecycle: string; lastAdvancedAt: unknown };
103
- if (toBigInt(r.sessionId) === sessionId) {
104
- return {
105
- sessionId,
106
- lifecycle: r.lifecycle,
107
- lastAdvancedAt: toBigInt(r.lastAdvancedAt),
108
- };
109
- }
110
- }
111
- return undefined;
112
- }
113
-
114
- function toBigInt(value: unknown): bigint {
115
- return typeof value === "bigint" ? value : BigInt(String(value ?? 0));
116
- }
@@ -1,91 +0,0 @@
1
- // Per-reducer wrapper for r_session_open (real wrapper — Phase 9 scenario A).
2
- // Success predicate: a session row with matching sessionDefId appears in the
3
- // session table cache (subscribed via READER_SCOPED_TABLES).
4
-
5
- import type { DbConnection } from "@spellkave/bindings";
6
- import type { SnapshotDb } from "../../connection";
7
- import { observeReducerAttempt } from "../../provenance";
8
- import type { ProvenanceRingBuffer } from "../provenance_buffer";
9
- import type { TickIntervalEstimator } from "../tick_cadence";
10
- import { findSessionId } from "./session_lookup";
11
- import { actorEntityId } from "./transport";
12
-
13
- type RSessionOpenFn = DbConnection["reducers"]["rSessionOpen"];
14
-
15
- export interface SessionOpenResult {
16
- status:
17
- | "success"
18
- | "rejected"
19
- | "unobserved_timeout"
20
- | "unobserved_no_provenance"
21
- | "unobservable";
22
- sessionDefId: string;
23
- /** Session id from the session table row, if observable. */
24
- sessionId?: bigint;
25
- reason?: string;
26
- lagWarning: boolean;
27
- observedAtTick: bigint;
28
- }
29
-
30
- export async function rSessionOpenWrapper(
31
- actorId: string,
32
- sessionDefId: string,
33
- participantsCsv: string,
34
- snapshotDb: () => SnapshotDb,
35
- rSessionOpen: RSessionOpenFn,
36
- timeoutMs: number,
37
- pollMs: number,
38
- tickEstimator?: TickIntervalEstimator,
39
- provenanceBuffer?: ProvenanceRingBuffer,
40
- ): Promise<SessionOpenResult> {
41
- const participants = participantIds(actorId, participantsCsv);
42
- const result = await observeReducerAttempt<bigint | null>({
43
- db: snapshotDb,
44
- subjectId: actorId,
45
- invoke: () =>
46
- rSessionOpen({ driverTokens: [], sessionDefId, participants, gridExtentJson: "" }),
47
- successPredicate: (db) => findSessionId(db, sessionDefId, participants) !== undefined,
48
- collectSnapshot: (db) => findSessionId(db, sessionDefId, participants) ?? null,
49
- timeoutMs,
50
- pollMs,
51
- tickEstimator,
52
- provenanceBuffer,
53
- });
54
-
55
- if (result.status === "success") {
56
- return {
57
- status: "success",
58
- sessionDefId,
59
- sessionId: result.snapshot ?? undefined,
60
- lagWarning: result.lagWarning,
61
- observedAtTick: result.observedAtTick,
62
- };
63
- }
64
-
65
- if (result.status === "rejected") {
66
- return {
67
- status: "rejected",
68
- sessionDefId,
69
- reason: `r_session_open rejected by server`,
70
- lagWarning: result.lagWarning,
71
- observedAtTick: result.observedAtTick,
72
- };
73
- }
74
-
75
- return {
76
- status: result.status,
77
- sessionDefId,
78
- reason: `r_session_open for '${sessionDefId}' not observed within ${timeoutMs}ms`,
79
- lagWarning: result.lagWarning,
80
- observedAtTick: result.observedAtTick,
81
- };
82
- }
83
-
84
- function participantIds(actorId: string, participantsCsv: string): bigint[] {
85
- const explicit = participantsCsv
86
- .split(",")
87
- .map((part) => part.trim())
88
- .filter((part) => part.length > 0)
89
- .map(actorEntityId);
90
- return explicit.length > 0 ? explicit : [actorEntityId(actorId)];
91
- }
@@ -1,64 +0,0 @@
1
- // Session-row lookup for r_session_open — split out to keep the wrapper
2
- // itself under the sdk_loc_ceiling (LR-102).
3
-
4
- import type { SnapshotDb } from "../../connection";
5
-
6
- const TERMINAL_SESSION_LIFECYCLES = new Set(["completed", "abandoned", "failed"]);
7
-
8
- /** First subscribed handle that already has rows, else the first existing
9
- * empty handle. Live clients only subscribe `visible_session` / `visible_session_participant`
10
- * (raw `session` is private, ADR-0057 / sk-2qt); unit fixtures may still inject
11
- * the pre-privacy names. */
12
- export function firstPopulatedHandle(db: SnapshotDb, ...accessors: string[]) {
13
- let empty: { iter(): Iterable<unknown> } | undefined;
14
- for (const name of accessors) {
15
- const handle = db[name];
16
- if (!handle) continue;
17
- const rows = Array.from(handle.iter());
18
- if (rows.length > 0) return handle;
19
- empty = handle;
20
- }
21
- return empty;
22
- }
23
-
24
- export function findSessionId(
25
- db: SnapshotDb,
26
- sessionDefId: string,
27
- participants: readonly bigint[],
28
- ): bigint | undefined {
29
- const handle = firstPopulatedHandle(db, "visible_session", "session");
30
- if (!handle) return undefined;
31
- const wanted = new Set(participants.map((participant) => String(participant)));
32
- const participantHandle = firstPopulatedHandle(
33
- db,
34
- "visible_session_participant",
35
- "session_participant",
36
- );
37
- const participantRows = participantHandle ? Array.from(participantHandle.iter()) : [];
38
- const matching: bigint[] = [];
39
- for (const raw of handle.iter()) {
40
- const r = raw as unknown as { sessionDefId: string; sessionId: unknown; lifecycle?: unknown };
41
- if (r.sessionDefId === sessionDefId && !TERMINAL_SESSION_LIFECYCLES.has(String(r.lifecycle))) {
42
- const sessionId =
43
- typeof r.sessionId === "bigint" ? r.sessionId : BigInt(String(r.sessionId ?? 0));
44
- if (participantRows.length === 0) {
45
- matching.push(sessionId);
46
- continue;
47
- }
48
- const sessionIdText = String(sessionId);
49
- const actual = new Set(
50
- participantRows
51
- .map((row) => row as unknown as { sessionId: unknown; actorId: unknown })
52
- .filter((row) => String(row.sessionId) === sessionIdText)
53
- .map((row) => String(row.actorId)),
54
- );
55
- if (
56
- actual.size === wanted.size &&
57
- [...wanted].every((participant) => actual.has(participant))
58
- ) {
59
- matching.push(sessionId);
60
- }
61
- }
62
- }
63
- return matching.sort((a, b) => (a > b ? -1 : a < b ? 1 : 0))[0];
64
- }
@@ -1,65 +0,0 @@
1
- import type { SpellkaveSession } from "../../connection";
2
-
3
- export async function pauseWorldTicks(session: SpellkaveSession): Promise<void> {
4
- await (
5
- session.conn.reducers as unknown as {
6
- pauseTick(args: Record<string, never>): Promise<void>;
7
- }
8
- ).pauseTick({});
9
- }
10
-
11
- // Advances one world clock tick at a logical scene boundary.
12
- // Wraps the `manual_tick` reducer (ManualClockAdvance event kind), requiring
13
- // the publisher credential or a directly bound body with live frontier.pace_time.
14
- // `world_tick` remains scheduler-only.
15
- // Convention (#675 CR-5): call once per logical scene boundary in walkthrough
16
- // scripts so the per-tick consequence cascade (autonomy jobs, claim TTLs,
17
- // affordance re-derivation) fires at each scene transition.
18
- export async function advanceScene(session: SpellkaveSession): Promise<void> {
19
- await (
20
- session.conn.reducers as unknown as {
21
- manualTick(args: Record<string, never>): Promise<void>;
22
- }
23
- ).manualTick({});
24
- }
25
-
26
- export async function advanceScenes(session: SpellkaveSession, ticks: number): Promise<void> {
27
- if (!Number.isInteger(ticks) || ticks < 0) {
28
- throw new Error(`advanceScenes requires a non-negative integer, got ${ticks}`);
29
- }
30
- await (
31
- session.conn.reducers as unknown as {
32
- manualTicks(args: { ticks: number }): Promise<void>;
33
- }
34
- ).manualTicks({ ticks });
35
- }
36
-
37
- export async function advanceTurns(
38
- session: SpellkaveSession,
39
- sessionId: bigint,
40
- count: number,
41
- ): Promise<void> {
42
- if (!Number.isInteger(count) || count < 0) {
43
- throw new Error(`advanceTurns requires a non-negative integer, got ${count}`);
44
- }
45
- await (
46
- session.conn.reducers as unknown as {
47
- rAdvanceTurns(args: { sessionId: bigint; count: number }): Promise<void>;
48
- }
49
- ).rAdvanceTurns({ sessionId, count });
50
- }
51
-
52
- export async function setDebugRngSeed(
53
- session: SpellkaveSession,
54
- seed: bigint | number | string | null,
55
- ): Promise<void> {
56
- const reducers = session.conn.reducers as unknown as {
57
- debugSetRngSeed?: (args: { seed?: bigint }) => Promise<void>;
58
- };
59
- if (typeof reducers.debugSetRngSeed !== "function") {
60
- throw new Error(
61
- "debugSetRngSeed reducer is unavailable; publish the module with --features test-rng-seed",
62
- );
63
- }
64
- await reducers.debugSetRngSeed({ seed: seed === null ? undefined : BigInt(seed) });
65
- }
@@ -1,29 +0,0 @@
1
- // Trace-row lookup for r_inscribe_trace — split out to keep the wrapper
2
- // itself under the sdk_loc_ceiling (LR-102).
3
-
4
- import type { SnapshotDb } from "../../connection";
5
-
6
- export function findTraceId(
7
- db: SnapshotDb,
8
- kind: string,
9
- locationRef: string,
10
- inscribedBy: string,
11
- ): bigint | undefined {
12
- // `trace` is private (ADR-0120, #915); read back through `visible_trace`. The
13
- // inscriber perceives its own fresh trace at inscription time (ADR-0040 seam A),
14
- // so the just-written row is in the inscriber's perception-bounded view.
15
- const handle = db.visible_trace;
16
- if (!handle) return undefined;
17
- for (const raw of handle.iter()) {
18
- const r = raw as unknown as {
19
- kind: string;
20
- locationRef: string;
21
- inscribedBy: string;
22
- traceId: unknown;
23
- };
24
- if (r.kind === kind && r.locationRef === locationRef && r.inscribedBy === inscribedBy) {
25
- return typeof r.traceId === "bigint" ? r.traceId : BigInt(String(r.traceId ?? 0));
26
- }
27
- }
28
- return undefined;
29
- }
@@ -1,84 +0,0 @@
1
- import type { DbConnection } from "@spellkave/bindings";
2
-
3
- export type ReducerActorId = bigint;
4
- export type RManipulateParams = Parameters<DbConnection["reducers"]["rManipulate"]>[0];
5
- export type TargetRefArg = RManipulateParams["targetRef"];
6
- export type ManipulationArgsArg = RManipulateParams["args"];
7
- export type FrameItemDestinationArg = NonNullable<ManipulationArgsArg["destination"]>;
8
- export type FrameSpatialRefArg = NonNullable<ManipulationArgsArg["buildTarget"]>;
9
-
10
- export function actorEntityId(value: string | bigint): ReducerActorId {
11
- if (typeof value === "bigint") return value;
12
- return BigInt(stripEntityPrefix(value));
13
- }
14
-
15
- export function targetRefFromString(value: string): TargetRefArg {
16
- const trimmed = value.trim();
17
- if (trimmed === "world") return { tag: "World" } as TargetRefArg;
18
- const [kind, rawId] = splitRef(trimmed, "entity");
19
- switch (kind) {
20
- case "entity":
21
- return { tag: "Entity", value: BigInt(rawId) } as TargetRefArg;
22
- case "item":
23
- return { tag: "Item", value: BigInt(rawId) } as TargetRefArg;
24
- case "place_node":
25
- return { tag: "PlaceNode", value: rawId } as TargetRefArg;
26
- case "place_node_set": {
27
- const [originPlaceNodeId, rangeRaw, ...templateParts] = rawId.split(":");
28
- if (!originPlaceNodeId || !rangeRaw || templateParts.length === 0) {
29
- throw new Error(`unsupported target ref '${value}'`);
30
- }
31
- return {
32
- tag: "PlaceNodeSet",
33
- value: {
34
- originPlaceNodeId,
35
- rangeMillimeters: Number(rangeRaw),
36
- affordanceTemplateId: templateParts.join(":"),
37
- },
38
- } as TargetRefArg;
39
- }
40
- case "place_edge":
41
- return { tag: "PlaceEdge", value: BigInt(rawId) } as TargetRefArg;
42
- case "location":
43
- return { tag: "Location", value: rawId } as TargetRefArg;
44
- default:
45
- throw new Error(`unsupported target ref '${value}'`);
46
- }
47
- }
48
-
49
- /**
50
- * Inverse of `targetRefFromString`: serialize a typed `TargetRef` (e.g. the
51
- * `affordance.target_ref` column — the source of truth for target kind,
52
- * ADR-0033 D1) into the canonical string the reducer transport accepts.
53
- * Round-trip: `targetRefFromString(targetRefToString(ref))` is identity.
54
- */
55
- export function targetRefToString(ref: TargetRefArg): string {
56
- switch (ref.tag) {
57
- case "Entity":
58
- return `entity:${ref.value}`;
59
- case "Item":
60
- return `item:${ref.value}`;
61
- case "PlaceNode":
62
- return `place_node:${ref.value}`;
63
- case "PlaceNodeSet":
64
- return `place_node_set:${ref.value.originPlaceNodeId}:${ref.value.rangeMillimeters}:${ref.value.affordanceTemplateId}`;
65
- case "PlaceEdge":
66
- return `place_edge:${ref.value}`;
67
- case "Location":
68
- return `location:${ref.value}`;
69
- case "World":
70
- return "world";
71
- default:
72
- throw new Error(`unsupported target ref tag '${(ref as { tag: string }).tag}'`);
73
- }
74
- }
75
-
76
- function stripEntityPrefix(value: string): string {
77
- return value.startsWith("entity:") ? value.slice("entity:".length) : value;
78
- }
79
-
80
- function splitRef(value: string, defaultKind: string): [string, string] {
81
- const index = value.indexOf(":");
82
- if (index < 0) return [defaultKind, value];
83
- return [value.slice(0, index), value.slice(index + 1)];
84
- }