@myclaw163/clawclaw-cli 0.9.2 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (197) hide show
  1. package/QUICKSTART_OTHER.md +5 -5
  2. package/README.md +7 -8
  3. package/bin/clawclaw-channel.mjs +2 -2
  4. package/bin/clawclaw-cli.mjs +2 -2
  5. package/docs/configuration.md +25 -99
  6. package/docs/custom-modules/README.md +23 -35
  7. package/docs/custom-modules/api-reference.md +95 -273
  8. package/docs/custom-modules/behavior.md +94 -78
  9. package/docs/custom-modules/examples/auto-escape.ts +5 -5
  10. package/docs/custom-modules/examples/go-to-point.ts +11 -11
  11. package/docs/custom-modules/examples/nearby-reflex.ts +2 -2
  12. package/docs/custom-modules/examples/task-reminder.ts +4 -5
  13. package/docs/custom-modules/perception.md +42 -603
  14. package/docs/custom-modules/skill.md +1 -1
  15. package/docs/desktop-event-push.md +3 -3
  16. package/docs/runtime/README.md +16 -17
  17. package/docs/runtime/agent-notifications.md +31 -12
  18. package/docs/runtime/behavior-runtime.md +47 -46
  19. package/docs/runtime/components-and-boundaries.md +70 -28
  20. package/docs/runtime/events-and-state.md +41 -18
  21. package/docs/runtime/framework-package.md +73 -0
  22. package/docs/runtime/official-perception-modules.md +5 -5
  23. package/docs/runtime/owner-lifecycle-and-observability.md +6 -6
  24. package/docs/runtime/short-commands-and-capabilities.md +8 -9
  25. package/docs/user-guide/README.md +10 -7
  26. package/docs/user-guide/api-reference.md +81 -164
  27. package/docs/user-guide/behavior.md +84 -68
  28. package/docs/user-guide/installation.md +7 -7
  29. package/docs/user-guide/perception.md +42 -586
  30. package/docs/user-guide/skill.md +1 -1
  31. package/package.json +24 -9
  32. package/scripts/check-framework-boundaries.mjs +27 -0
  33. package/scripts/check-skill-command-surface.mjs +8 -13
  34. package/scripts/install-local-runtime.mjs +35 -0
  35. package/scripts/qa-install.mjs +105 -0
  36. package/skills/clawclaw/SKILL.md +49 -49
  37. package/skills/clawclaw/references/BEHAVIORS.md +42 -73
  38. package/skills/clawclaw/references/CHANNELS.md +2 -2
  39. package/skills/clawclaw/references/COMMANDS.md +60 -101
  40. package/skills/clawclaw/references/CUSTOM-BEHAVIOR-DEVELOPMENT.md +94 -78
  41. package/skills/clawclaw/references/CUSTOM-MODULE-API.md +95 -180
  42. package/skills/clawclaw/references/CUSTOM-MODULES.md +24 -24
  43. package/skills/clawclaw/references/CUSTOM-PERCEPTION-DEVELOPMENT.md +42 -608
  44. package/skills/clawclaw/references/CUSTOM-SKILL-DEVELOPMENT.md +1 -1
  45. package/skills/clawclaw/references/HUB.md +1 -1
  46. package/skills/clawclaw/references/STREAM.md +8 -8
  47. package/skills/clawclaw/references/TACTICS.md +1 -1
  48. package/src/channel/claude-channel-ipc-server.ts +1 -0
  49. package/src/cli.ts +4 -2
  50. package/src/commands/behavior.ts +26 -10
  51. package/src/commands/capability.ts +3 -3
  52. package/src/commands/load.ts +3 -2
  53. package/src/commands/perception.ts +5 -0
  54. package/src/commands/strategy.ts +2 -0
  55. package/src/lib/capability-load-diagnostics.ts +3 -3
  56. package/src/lib/perception-config.ts +18 -6
  57. package/src/lib/runtime-cadence-config.ts +16 -0
  58. package/src/lib/workspace-runtime-lock.ts +3 -46
  59. package/src/pipeline/canonical-event-presentation.ts +23 -124
  60. package/src/pipeline/event-format.ts +12 -21
  61. package/src/pipeline/event-hints.ts +6 -6
  62. package/src/pipeline/game-sync-event-normalization.ts +57 -63
  63. package/src/runtime/clawclaw/behavior-decision.ts +7 -3
  64. package/src/runtime/clawclaw/behavior-input.ts +8 -4
  65. package/src/runtime/clawclaw/behavior-observation-memory.ts +3 -2
  66. package/src/runtime/clawclaw/notification-policy.ts +42 -0
  67. package/src/runtime/clawclaw/notification-turn.ts +19 -0
  68. package/src/runtime/clawclaw/observation-frame-projector.ts +3 -3
  69. package/src/runtime/clawclaw/owner.ts +18 -4
  70. package/src/runtime/clawclaw/perception-module-manifest.ts +8 -3
  71. package/src/runtime/clawclaw/perception-strategy-names.ts +17 -0
  72. package/src/runtime/clawclaw/persistence-compatibility.ts +36 -0
  73. package/src/runtime/clawclaw/plugins/action/action-plugin.ts +3 -3
  74. package/src/runtime/clawclaw/plugins/assembly.ts +7 -9
  75. package/src/runtime/clawclaw/plugins/behavior/activation-manager.ts +1 -495
  76. package/src/runtime/clawclaw/plugins/behavior/behavior-analysis-thread-host.ts +17 -190
  77. package/src/runtime/clawclaw/plugins/behavior/behavior-instance-snapshot.ts +1 -123
  78. package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.ts +126 -1779
  79. package/src/runtime/clawclaw/plugins/behavior/behavior-runner.ts +13 -276
  80. package/src/runtime/clawclaw/plugins/behavior/behavior-source.ts +2 -2
  81. package/src/runtime/clawclaw/plugins/behavior/behavior-worker-bridge.ts +8 -0
  82. package/src/runtime/clawclaw/plugins/behavior/control-driver.ts +3 -180
  83. package/src/runtime/clawclaw/plugins/behavior/thread-behavior-executor.ts +13 -972
  84. package/src/runtime/clawclaw/plugins/derived-event/derived-event-plugin.ts +8 -109
  85. package/src/runtime/clawclaw/plugins/derived-event/derived-event-rules.ts +2 -2
  86. package/src/runtime/clawclaw/plugins/derived-event/reminder-plugin.ts +25 -17
  87. package/src/runtime/clawclaw/plugins/derived-event/reminder-runner.ts +1 -0
  88. package/src/runtime/clawclaw/plugins/derived-event/state-change-rules.ts +3 -3
  89. package/src/runtime/clawclaw/plugins/derived-event/task-change-tracker.ts +1 -259
  90. package/src/runtime/clawclaw/plugins/game-query/game-query-plugin.ts +4 -4
  91. package/src/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-adapter.ts +9 -97
  92. package/src/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-socket.ts +8 -343
  93. package/src/runtime/clawclaw/plugins/mailbox/agent-mailbox-coordinator.ts +60 -572
  94. package/src/runtime/clawclaw/plugins/mailbox/desktop-event-socket.ts +6 -434
  95. package/src/runtime/clawclaw/plugins/mailbox/mailbox-event-batch-delivery.ts +1 -266
  96. package/src/runtime/clawclaw/plugins/mailbox/mailbox-plugin.ts +6 -161
  97. package/src/runtime/clawclaw/plugins/mailbox/mailbox-presentation.ts +4 -23
  98. package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.ts +49 -752
  99. package/src/runtime/clawclaw/plugins/perception/map-concurrent.ts +1 -0
  100. package/src/runtime/clawclaw/plugins/perception/notification-content.ts +60 -0
  101. package/src/runtime/clawclaw/plugins/perception/perception-module-plugin.ts +119 -297
  102. package/src/runtime/clawclaw/plugins/perception/perception-module-runner.ts +7 -56
  103. package/src/runtime/clawclaw/plugins/perception/perception-module-worker.ts +11 -33
  104. package/src/runtime/clawclaw/plugins/perception/perception-plugin.ts +18 -7
  105. package/src/runtime/clawclaw/plugins/perception/perception-source.ts +12 -6
  106. package/src/runtime/clawclaw/plugins/perception/task-baseline.ts +29 -0
  107. package/src/runtime/clawclaw/plugins/source/source-plugin.ts +6 -0
  108. package/src/runtime/clawclaw/plugins/system-perception/rule-runner.ts +107 -0
  109. package/src/runtime/clawclaw/plugins/system-perception/system-perceptions.ts +107 -0
  110. package/src/runtime/clawclaw/plugins/trigger/trigger-plugin.ts +8 -3
  111. package/src/runtime/clawclaw/reaction-behavior-resolution.ts +1 -23
  112. package/src/runtime/clawclaw/reminder-manifest.ts +5 -2
  113. package/src/runtime/clawclaw/runtime-cadence.ts +24 -0
  114. package/src/runtime/clawclaw/runtime-state.ts +11 -0
  115. package/src/runtime/clawclaw/runtime.ts +8 -0
  116. package/src/runtime/clawclaw/strategy-memory-rpc.ts +1 -63
  117. package/src/runtime/clawclaw/strategy-memory.ts +1 -77
  118. package/src/runtime/clawclaw-event-catalog.ts +12 -12
  119. package/src/runtime/framework/action-diagnostics.ts +3 -83
  120. package/src/runtime/framework/capability-registry.ts +2 -395
  121. package/src/runtime/framework/contracts.ts +2 -144
  122. package/src/runtime/framework/control/control-scheduler.ts +2 -1268
  123. package/src/runtime/framework/control/domain-set.ts +2 -81
  124. package/src/runtime/framework/control/index.ts +1 -3
  125. package/src/runtime/framework/control/types.ts +2 -191
  126. package/src/runtime/framework/control-coordinator.ts +2 -11
  127. package/src/runtime/framework/events/event-catalog.ts +2 -74
  128. package/src/runtime/framework/events/event-delivery-service.ts +2 -200
  129. package/src/runtime/framework/events/event-ingress.ts +2 -99
  130. package/src/runtime/framework/events/event-repository.ts +2 -82
  131. package/src/runtime/framework/events/index.ts +2 -7
  132. package/src/runtime/framework/events/memory-event-repository.ts +2 -1100
  133. package/src/runtime/framework/events/runtime-resume.ts +2 -20
  134. package/src/runtime/framework/events/sqlite-event-repository.ts +5 -2280
  135. package/src/runtime/framework/events/test-helpers.ts +1 -1
  136. package/src/runtime/framework/events/types.ts +2 -312
  137. package/src/runtime/framework/index.ts +3 -7
  138. package/src/runtime/framework/load-node-sqlite.ts +2 -17
  139. package/src/runtime/framework/mailbox/coalescer.ts +2 -83
  140. package/src/runtime/framework/mailbox/host-notification-sink.ts +2 -44
  141. package/src/runtime/framework/mailbox/identity.ts +2 -38
  142. package/src/runtime/framework/mailbox/index.ts +1 -7
  143. package/src/runtime/framework/mailbox/mailbox-dispatcher.ts +2 -282
  144. package/src/runtime/framework/mailbox/mailbox-repository.ts +2 -44
  145. package/src/runtime/framework/mailbox/notification-projector.ts +2 -65
  146. package/src/runtime/framework/mailbox/types.ts +2 -145
  147. package/src/runtime/framework/modules/runtime-module-loader-hooks.mjs +2 -154
  148. package/src/runtime/framework/modules/runtime-module-loader.ts +7 -51
  149. package/src/runtime/framework/modules/runtime-module-output.ts +2 -24
  150. package/src/runtime/framework/modules/runtime-module-worker-bootstrap.mjs +3 -23
  151. package/src/runtime/framework/participation-manager.ts +2 -253
  152. package/src/runtime/framework/persistence/async-sqlite-persistence-worker.ts +2 -77
  153. package/src/runtime/framework/persistence/memory-first-persistence.ts +4 -489
  154. package/src/runtime/framework/plugins/contracts.ts +2 -396
  155. package/src/runtime/framework/plugins/index.ts +1 -4
  156. package/src/runtime/framework/plugins/runtime-event-identity.ts +2 -17
  157. package/src/runtime/framework/plugins/runtime-input-journal.ts +2 -866
  158. package/src/runtime/framework/plugins/runtime-plugin-scheduler.ts +2 -2071
  159. package/src/runtime/framework/runtime.ts +5 -1843
  160. package/src/runtime/framework/serial-task-queue.ts +2 -14
  161. package/src/runtime/framework/state/contracts.ts +2 -49
  162. package/src/runtime/framework/state/current-state-store.ts +2 -184
  163. package/src/runtime/framework/state/durable-agent-state-snapshot.ts +2 -209
  164. package/src/runtime/framework/state/freshness.ts +2 -72
  165. package/src/runtime/framework/state/history/contracts.ts +2 -158
  166. package/src/runtime/framework/state/history/history-writer.ts +2 -194
  167. package/src/runtime/framework/state/history/memory-state-history-repository.ts +2 -230
  168. package/src/runtime/framework/state/history/sqlite-state-history-repository.ts +2 -648
  169. package/src/runtime/framework/state/history/trajectory-projector.ts +2 -209
  170. package/src/runtime/framework/state/index.ts +1 -13
  171. package/src/runtime/framework/state/state-ingress.ts +2 -95
  172. package/src/runtime/framework/state/state-provider.ts +2 -62
  173. package/src/runtime/framework/state/types.ts +2 -155
  174. package/src/runtime/host-monitor-rate-gate.ts +1 -123
  175. package/src/runtime/mailbox-host-relay.ts +1 -326
  176. package/src/runtime/observability/detail-capture.ts +4 -108
  177. package/src/runtime/observability/process-timing.ts +2 -59
  178. package/src/runtime/observability/recorder.ts +2 -238
  179. package/src/runtime/observability/redaction.ts +2 -181
  180. package/src/runtime/observability/reporter.ts +2 -154
  181. package/src/runtime/observability/sinks.ts +2 -135
  182. package/src/runtime/observability/types.ts +2 -92
  183. package/src/runtime/owner-control.ts +45 -320
  184. package/src/runtime/parent-process-watch.ts +1 -51
  185. package/src/runtime/process-identity.ts +1 -72
  186. package/src/sdk/behavior-plugin/index.ts +9 -3
  187. package/src/sdk/index.ts +40 -2
  188. package/src/sdk/module-input/index.ts +5 -0
  189. package/src/sdk/perception-plugin/index.ts +3 -1
  190. package/src/sdk/perception-plugin/module.ts +12 -2
  191. package/src/sdk/perception-plugin/reminder-rules.ts +8 -42
  192. package/src/sdk/perception-plugin/reminder.ts +2 -1
  193. package/src/sdk/perception-plugin/task-change-tracker.ts +258 -0
  194. package/src/sdk/strategy-memory.ts +1 -12
  195. package/src/sdk/strategy-plugin/index.ts +36 -0
  196. package/src/sdk/trigger-plugin/index.ts +1 -0
  197. package/docs/custom-modules/trigger.md +0 -295
@@ -1,396 +1,2 @@
1
- import type { CanonicalEvent, EventProducer } from '../events/types.js';
2
- import type { StateFrameHistoryReader, StoredStateFrame } from '../state/history/contracts.js';
3
- import type { RuntimeConnectionState, RuntimeScope } from '../state/types.js';
4
- import type {
5
- ActionCaller,
6
- ActionResult,
7
- ObservationProvider,
8
- ObservationResult,
9
- } from '../contracts.js';
10
- import type { RegisteredActionService } from '../capability-registry.js';
11
- import type { StateProviderResult } from '../state/types.js';
12
-
13
- export type RuntimeInputCompleteness = 'complete' | 'best_effort';
14
- export type RuntimeInputCoalescing = 'allowed' | 'forbidden';
15
- /**
16
- * `strict_ordered` never discards an accepted epoch: computation may overlap,
17
- * but Runtime grants the effect boundary in epoch order. `every_epoch`
18
- * processes each epoch only while it remains inside the bounded catch-up
19
- * window; `latest_only` may supersede it as soon as a newer ready epoch exists.
20
- * A `coalescing: forbidden` input overrides the coalescing policies, and a
21
- * commit that has already started is never interrupted.
22
- */
23
- export type RuntimeEpochCatchUp = 'strict_ordered' | 'every_epoch' | 'latest_only';
24
- export type RuntimePluginFailureMode = 'failed_completion' | 'retry' | 'pause' | 'terminate';
25
- export type RuntimePluginKind = 'source' | 'epoch';
26
- export type RuntimeEpochFlushReason =
27
- | 'segment_ending'
28
- | 'shutdown';
29
-
30
- export interface RuntimeSourceEvent<T = Record<string, unknown>> {
31
- readonly type: string;
32
- readonly producer?: EventProducer;
33
- readonly payload: T;
34
- readonly sourceEventId?: string;
35
- readonly sourceSeq?: number | string;
36
- readonly observedAt?: string;
37
- readonly receivedAt?: string;
38
- readonly replayed?: boolean;
39
- readonly checkpoint?: string;
40
- }
41
-
42
- /** One Source submission creates exactly one Runtime epoch. */
43
- export interface RuntimeInputBatch<
44
- TState = Record<string, unknown>,
45
- TEvent = Record<string, unknown>,
46
- > {
47
- readonly scope: RuntimeScope;
48
- readonly sourceId: string;
49
- readonly connectionId: string;
50
- /** Stable physical-message identity within source and scope. */
51
- readonly sourceKey: string;
52
- readonly sourceSeq?: number | string;
53
- readonly domainTick?: number | string;
54
- readonly state: TState;
55
- /** Always present, including when the Source observed no Event. */
56
- readonly events: readonly RuntimeSourceEvent<TEvent>[];
57
- readonly eventWatermark?: number | string;
58
- readonly completeness: RuntimeInputCompleteness;
59
- /** A forbidden epoch must be processed by every loaded Epoch Plugin. */
60
- readonly coalescing?: RuntimeInputCoalescing;
61
- readonly observedAt?: string;
62
- readonly receivedAt: string;
63
- }
64
-
65
- export interface RuntimePluginIdentity<K extends RuntimePluginKind = RuntimePluginKind> {
66
- readonly kind: K;
67
- readonly id: string;
68
- readonly version: string;
69
- }
70
-
71
- export interface RuntimePluginCapabilityDeclaration {
72
- /** Capability names registered by this plugin while its scope is active. */
73
- readonly provides?: readonly string[];
74
- /** Capability names this plugin may invoke while processing an epoch. */
75
- readonly uses?: readonly string[];
76
- }
77
-
78
- export interface RuntimePluginFailurePolicy {
79
- readonly mode: RuntimePluginFailureMode;
80
- /** Total invocation attempts, including the first call. Only used by retry. */
81
- readonly maxAttempts?: number;
82
- }
83
-
84
- /**
85
- * Scope-bound capability surface exposed to an Epoch Plugin. Runtime performs
86
- * declaration checks and routing; capability providers own all game behavior.
87
- */
88
- export interface RuntimePluginCapabilityAccess {
89
- provideObservation<Q, R>(provider: ObservationProvider<Q, R>): () => void;
90
- provideAction<A, R>(service: RegisteredActionService<A, R>): () => void;
91
- queryObservation<Q, R>(capability: string, request: Q): Promise<ObservationResult<R>>;
92
- performAction<A, R>(
93
- capability: string,
94
- action: A,
95
- caller?: ActionCaller,
96
- ): Promise<ActionResult<R>>;
97
- }
98
-
99
- /** The persisted scheduling unit created from exactly one InputBatch. */
100
- export interface RuntimeEpoch<
101
- TState = Record<string, unknown>,
102
- TEvent = Record<string, unknown>,
103
- > extends RuntimeInputBatch<TState, TEvent> {
104
- readonly epochSeq: number;
105
- }
106
-
107
- export interface RuntimeInputAcceptance<TState = Record<string, unknown>, TEvent = Record<string, unknown>> {
108
- readonly inserted: boolean;
109
- readonly epoch: RuntimeEpoch<TState, TEvent>;
110
- }
111
-
112
- export interface RuntimeStateProposal<T = unknown> {
113
- readonly topic: string;
114
- readonly value: T;
115
- }
116
-
117
- export interface RuntimeEventProposal {
118
- /** Whether this Event may initiate Agent delivery; omitted means true. */
119
- readonly wakeAgent?: boolean;
120
- readonly type: string;
121
- /** Stable key for retrying this output at the same epoch and output position.
122
- * Cross-epoch repetition is controlled by the producer's rule state, not this key.
123
- */
124
- readonly dedupeKey: string;
125
- /** Identity namespace only; epoch and output position remain part of the ID. */
126
- readonly dedupeScope?: 'segment' | 'session';
127
- readonly payload: Record<string, unknown>;
128
- readonly occurredAt?: string;
129
- }
130
-
131
- export type RuntimeEpochPluginOutcome = 'processed' | 'noop' | 'failed' | 'coalesced';
132
- export type RuntimeDiagnosticSeverity = 'debug' | 'info' | 'warn' | 'error';
133
-
134
- export interface RuntimeEpochPluginResult {
135
- readonly eventDeliveries?: readonly import('../events/types.js').EventDeliveryDecision[];
136
- readonly outcome: 'processed' | 'noop';
137
- readonly reason?: string;
138
- /**
139
- * Opaque, cloneable computation output consumed by this plugin's ordered
140
- * commit hook. Runtime never publishes a proposal directly.
141
- */
142
- readonly proposal?: unknown;
143
- readonly states?: readonly RuntimeStateProposal[];
144
- readonly events?: readonly RuntimeEventProposal[];
145
- /** Durable plugin-owned continuation state for this scope. */
146
- readonly checkpoint?: unknown;
147
- /** Omit to leave this plugin's independent Event cursor unchanged. */
148
- readonly consumeEventsThroughCommitSeq?: number;
149
- }
150
-
151
- export interface RuntimeEpochPluginContext<TState = Record<string, unknown>> {
152
- readonly scope: Readonly<RuntimeScope>;
153
- readonly stateHistory: StateFrameHistoryReader<TState>;
154
- /** Declared Source facts in an accepted epoch, restricted to this scope and invocation boundary.
155
- * Used to rebuild state rules with the same facts as live processing; never returns plugin outputs.
156
- */
157
- readonly sourceEventsAt?: (epochSeq: number) => readonly RuntimeSourceEvent[];
158
- /** Current logical segment without exposing Runtime internals. */
159
- readonly currentSegment: () => {
160
- readonly kind: string;
161
- readonly identity?: string;
162
- };
163
- /** Last durable checkpoint committed by this plugin in the active scope. */
164
- readonly checkpoint: () => unknown;
165
- /** Durable completion, Event cursor and checkpoint for this plugin/scope. */
166
- readonly progress: () => Readonly<RuntimeEpochPluginProgress>;
167
- readonly capabilities: RuntimePluginCapabilityAccess;
168
- /** Plugin-owned diagnostics. They never become game Events. */
169
- readonly diagnostic: (
170
- name: string,
171
- attributes?: Readonly<Record<string, unknown>>,
172
- severity?: RuntimeDiagnosticSeverity,
173
- ) => void;
174
- readonly signal: AbortSignal;
175
- }
176
-
177
- export interface RuntimeEpochPluginInput<
178
- TState = Record<string, unknown>,
179
- TEvent = Record<string, unknown>,
180
- > {
181
- readonly epoch: Readonly<RuntimeEpoch<TState, TEvent>>;
182
- readonly frame: Readonly<StoredStateFrame<TState>>;
183
- /** Game-facing State associated with this exact Runtime epoch. */
184
- readonly currentState: Readonly<StateProviderResult<Record<string, any> | null>>;
185
- readonly previousState: Readonly<TState> | null;
186
- /** Canonical Events committed from this InputBatch and upstream plugins. */
187
- readonly epochEvents: readonly CanonicalEvent[];
188
- /** Subscribed Events after this plugin's cursor, bounded by this epoch's watermark. */
189
- readonly pendingEvents: readonly CanonicalEvent[];
190
- /** Same-epoch State proposals produced by completed upstream plugins. */
191
- readonly upstreamStates: Readonly<Record<string, unknown>>;
192
- }
193
-
194
- export interface RuntimeEpochPlugin<TState = Record<string, unknown>, TEvent = Record<string, unknown>>
195
- extends RuntimePluginIdentity<'epoch'> {
196
- /** Only these existing Event types may have their pre-Ready delivery metadata resolved. */
197
- readonly controlsEventDelivery?: readonly string[];
198
- readonly consumes?: {
199
- readonly states?: readonly string[];
200
- readonly events?: readonly string[];
201
- };
202
- readonly produces?: {
203
- readonly states?: readonly string[];
204
- readonly events?: readonly string[];
205
- };
206
- readonly after?: readonly string[];
207
- readonly capabilities?: RuntimePluginCapabilityDeclaration;
208
- readonly catchUp?: RuntimeEpochCatchUp;
209
- /** Preserve started computations under ordinary overload, then catch up to the latest boundary. */
210
- readonly backlogPolicy?: 'finish_started';
211
- /**
212
- * Maximum overlapping update calls, from 1 through 10. Defaults to 1.
213
- * Values above 1 are an explicit promise that update is re-entrant and
214
- * performs no side effects; Runtime buffers its cloneable results and
215
- * commits them in epoch order. With `strict_ordered`, reaching the bounded
216
- * in-flight capacity delays newer computation instead of discarding work.
217
- */
218
- readonly maxInFlight?: number;
219
- /** Maximum retained epochs for non-strict catch-up before oldest work is coalesced. */
220
- readonly maxPendingEpochs?: number;
221
- readonly failurePolicy?: RuntimePluginFailureMode | RuntimePluginFailurePolicy;
222
- /** Per-call deadline; Runtime still owns cancellation and stale-output rejection. */
223
- readonly timeoutMs?: number;
224
- /** Optional longer deadline for rebuilding plugin state when a scope is activated. */
225
- readonly recoveryTimeoutMs?: number;
226
- start?(context: RuntimeEpochPluginContext<TState>): void | Promise<void>;
227
- recover?(context: RuntimeEpochPluginContext<TState>): void | Promise<void>;
228
- update(
229
- input: RuntimeEpochPluginInput<TState, TEvent>,
230
- context: RuntimeEpochPluginContext<TState>,
231
- ): RuntimeEpochPluginResult | Promise<RuntimeEpochPluginResult>;
232
- /**
233
- * Optional ordered reducer/effect boundary. When present, update returns
234
- * only outcome/reason/proposal and commit returns the final State/Event/
235
- * checkpoint output. Exactly one commit call per plugin runs at a time, and
236
- * once it starts Runtime lets that atomic effect boundary finish.
237
- */
238
- commit?(
239
- input: RuntimeEpochPluginInput<TState, TEvent>,
240
- computation: Readonly<RuntimeEpochPluginResult>,
241
- context: RuntimeEpochPluginContext<TState>,
242
- ): RuntimeEpochPluginResult | Promise<RuntimeEpochPluginResult>;
243
- flush?(
244
- reason: RuntimeEpochFlushReason,
245
- context: RuntimeEpochPluginContext<TState>,
246
- ): void | Promise<void>;
247
- stop?(
248
- reason: 'segment_ending' | 'shutdown',
249
- context: RuntimeEpochPluginContext<TState>,
250
- ): void | Promise<void>;
251
- }
252
-
253
- export interface RuntimeInputSink<TState = Record<string, unknown>, TEvent = Record<string, unknown>> {
254
- acceptInputBatch(batch: RuntimeInputBatch<TState, TEvent>): Promise<RuntimeInputAcceptance<TState, TEvent>>;
255
- }
256
-
257
- export interface RuntimeSourceSegment {
258
- readonly scope: RuntimeScope;
259
- readonly kind: string;
260
- readonly identity?: string;
261
- }
262
-
263
- /**
264
- * The game-neutral Runtime surface available to Source Plugins. A Source may
265
- * own any transport, but it cannot reach Runtime repositories or schedulers.
266
- */
267
- export interface RuntimeSourceContext<
268
- TState = Record<string, unknown>,
269
- TEvent = Record<string, unknown>,
270
- > extends RuntimeInputSink<TState, TEvent> {
271
- currentSegment(): RuntimeSourceSegment;
272
- /** A Source-confirmed terminal scope revokes Actions without stopping queries or event delivery. */
273
- closeActionScope(scope: RuntimeScope, reason: string): void;
274
- activateSegment(kind: string, identity?: string): Promise<RuntimeScope>;
275
- adoptResumeKey(resumeKey: string): RuntimeScope;
276
- updateMode(mode: string): RuntimeScope;
277
- bindConnection(sourceId: string, connectionId: string, atMs?: number): RuntimeScope;
278
- rebindConnectionScope(sourceId: string, connectionId: string, atMs?: number): RuntimeScope;
279
- connectionScope(sourceId: string, connectionId: string): RuntimeScope | null;
280
- isActiveConnection(sourceId: string, connectionId: string): boolean;
281
- connectionChanged(
282
- sourceId: string,
283
- connectionId: string,
284
- state: RuntimeConnectionState,
285
- atMs?: number,
286
- ): void;
287
- connectionLiveness(sourceId: string, connectionId: string, atMs?: number): boolean;
288
- /** Source-owned transport/protocol diagnostics. These never enter the game Event ledger. */
289
- diagnostic(
290
- name: string,
291
- attributes?: Readonly<Record<string, unknown>>,
292
- severity?: 'debug' | 'info' | 'warn' | 'error',
293
- ): void;
294
- }
295
-
296
- export interface RuntimeSourceStopHandle {
297
- /** Stop external intake. The captured Source context may submit a final InputBatch before resolving. */
298
- stop(reason: 'shutdown'): Promise<void> | void;
299
- }
300
-
301
- export interface RuntimeSourcePlugin<TState = Record<string, unknown>, TEvent = Record<string, unknown>>
302
- extends RuntimePluginIdentity<'source'> {
303
- start(
304
- context: RuntimeSourceContext<TState, TEvent>,
305
- ): RuntimeSourceStopHandle | Promise<RuntimeSourceStopHandle>;
306
- }
307
-
308
- /** The complete game-neutral plugin surface understood by Runtime. */
309
- export type RuntimePlugin<
310
- TState = Record<string, unknown>,
311
- TEvent = Record<string, unknown>,
312
- > = RuntimeSourcePlugin<TState, TEvent> | RuntimeEpochPlugin<TState, TEvent>;
313
-
314
- export interface RuntimeSourcePluginDescriptor extends RuntimePluginIdentity<'source'> {}
315
-
316
- export interface RuntimeEpochPluginDescriptor extends RuntimePluginIdentity<'epoch'> {
317
- readonly after: readonly string[];
318
- readonly catchUp: RuntimeEpochCatchUp;
319
- readonly maxInFlight: number;
320
- readonly maxPendingEpochs: number;
321
- readonly consumes: Readonly<NonNullable<RuntimeEpochPlugin['consumes']>>;
322
- readonly produces: Readonly<NonNullable<RuntimeEpochPlugin['produces']>>;
323
- readonly capabilities: Readonly<RuntimePluginCapabilityDeclaration>;
324
- readonly failurePolicy: Readonly<RuntimePluginFailurePolicy>;
325
- readonly timeoutMs?: number;
326
- readonly recoveryTimeoutMs?: number;
327
- }
328
-
329
- export type RuntimePluginDescriptor = RuntimeSourcePluginDescriptor | RuntimeEpochPluginDescriptor;
330
-
331
- export interface RuntimeEpochPluginProgress {
332
- readonly pluginId: string;
333
- readonly completedThroughEpochSeq: number;
334
- readonly eventCursor: number;
335
- readonly checkpoint?: unknown;
336
- readonly updatedAt: string;
337
- }
338
-
339
- export interface RuntimeEpochPluginRecord {
340
- readonly epochSeq: number;
341
- readonly pluginId: string;
342
- readonly invocationId: string;
343
- readonly outcome: RuntimeEpochPluginOutcome;
344
- readonly reason?: string;
345
- readonly durationMs: number;
346
- readonly stateCount: number;
347
- readonly eventCount: number;
348
- readonly eventCursorBefore: number;
349
- readonly eventCursorAfter: number;
350
- readonly recordedAt: string;
351
- }
352
-
353
- export interface RuntimeEpochStateRecord {
354
- readonly epochSeq: number;
355
- readonly pluginId: string;
356
- readonly topic: string;
357
- readonly value: unknown;
358
- }
359
-
360
- export interface RuntimeInputJournal<TState = Record<string, unknown>, TEvent = Record<string, unknown>> {
361
- accept(batch: RuntimeInputBatch<TState, TEvent>): RuntimeInputAcceptance<TState, TEvent>;
362
- epoch(epochSeq: number): RuntimeEpoch<TState, TEvent> | null;
363
- list(scope: RuntimeScope, afterEpochSeq?: number, limit?: number): RuntimeEpoch<TState, TEvent>[];
364
- listOpen(scope: RuntimeScope, afterEpochSeq?: number, limit?: number): RuntimeEpoch<TState, TEvent>[];
365
- inputEventsCommitted(epochSeq: number): boolean;
366
- markInputEventsCommitted(epochSeq: number, eventWatermark: number, committedAt?: string): void;
367
- eventWatermarkThrough(scope: RuntimeScope, epochSeq: number): number;
368
- markEventWatermark(epochSeq: number, eventWatermark: number): void;
369
- markClosed(epochSeq: number, closedAt?: string, durationMs?: number): void;
370
- close?(): void | Promise<void>;
371
- }
372
-
373
- /** Durable outcomes, derived State and independent Event cursors for plugins. */
374
- export interface RuntimePluginStore {
375
- recordPlugin(record: RuntimeEpochPluginRecord): void;
376
- pluginRecords(epochSeq: number): RuntimeEpochPluginRecord[];
377
- pluginProgress(pluginId: string, scope: RuntimeScope): RuntimeEpochPluginProgress;
378
- savePluginProgress(progress: RuntimeEpochPluginProgress, scope: RuntimeScope): void;
379
- saveStates(records: readonly RuntimeEpochStateRecord[]): void;
380
- states(epochSeq: number): RuntimeEpochStateRecord[];
381
- close?(): void | Promise<void>;
382
- }
383
-
384
- /** One physical database may implement both logical persistence contracts. */
385
- export interface RuntimePersistenceStore<TState = Record<string, unknown>, TEvent = Record<string, unknown>>
386
- extends RuntimeInputJournal<TState, TEvent>, RuntimePluginStore {}
387
-
388
- export interface RuntimeEpochExecutionResult {
389
- readonly epochSeq: number;
390
- /** Wall-clock time from scheduler enqueue until every plugin completion is durable. */
391
- readonly durationMs: number;
392
- readonly outcomes: readonly RuntimeEpochPluginRecord[];
393
- readonly stateCount: number;
394
- readonly eventCount: number;
395
- readonly eventWatermark: number;
396
- }
1
+ // Compatibility facade; implementation lives in the game-neutral runtime package.
2
+ export * from '@myclaw163/game-agent-runtime/framework/plugins/contracts.js';
@@ -1,4 +1 @@
1
- export * from './contracts.js';
2
- export * from './runtime-plugin-scheduler.js';
3
- export * from './runtime-input-journal.js';
4
- export * from './runtime-event-identity.js';
1
+ export * from '@myclaw163/game-agent-runtime/framework/plugins/index.js';
@@ -1,17 +1,2 @@
1
- import type { RuntimeEpoch, RuntimeSourceEvent } from './contracts.js';
2
-
3
- /** Stable canonical Event identity for one Event inside a Source InputBatch. */
4
- export function runtimeSourceEventId(
5
- epoch: Pick<RuntimeEpoch, 'sourceId' | 'sourceKey' | 'scope'>,
6
- event: Pick<RuntimeSourceEvent, 'sourceEventId'>,
7
- eventIndex: number,
8
- ): string {
9
- return JSON.stringify([
10
- 'runtime-source',
11
- epoch.sourceId,
12
- epoch.scope.sessionId,
13
- epoch.scope.segmentId,
14
- event.sourceEventId ?? epoch.sourceKey,
15
- event.sourceEventId ? null : eventIndex,
16
- ]);
17
- }
1
+ // Compatibility facade; implementation lives in the game-neutral runtime package.
2
+ export * from '@myclaw163/game-agent-runtime/framework/plugins/runtime-event-identity.js';