@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
@@ -43,7 +43,7 @@ export function seedScope(
43
43
  export function testCatalog(): EventCatalog {
44
44
  return new EventCatalog([
45
45
  { type: 'speech', producer: 'backend_push', deliveryClass: 'monitor_and_events' },
46
- { type: 'vote', producer: 'backend_push', deliveryClass: 'events_only' },
46
+ { type: 'vote', producer: 'backend_push', deliveryClass: 'monitor_and_events', wakeAgent: false },
47
47
  { type: 'client_notice', producer: 'local_synth', deliveryClass: 'monitor_and_events' },
48
48
  ]);
49
49
  }
@@ -1,312 +1,2 @@
1
- export const DEFAULT_EVENT_CONSUMER_ID = 'local-agent';
2
-
3
- export type EventProducer = 'backend_push' | 'local_synth';
4
-
5
- export type EventDeliveryClass =
6
- | 'monitor_and_events'
7
- | 'events_only'
8
- | 'internal_only';
9
-
10
- /** Delivery metadata may be resolved before Ready; factual identity/payload never change. */
11
- export interface EventDeliveryDecision {
12
- eventId: string;
13
- deliveryClass: EventDeliveryClass;
14
- }
15
-
16
- export type MonitorDeliveryState =
17
- | 'not_applicable'
18
- | 'pending'
19
- | 'notified'
20
- | 'suppressed';
21
-
22
- export type DetailDeliveryState =
23
- | 'not_applicable'
24
- | 'pending'
25
- | 'deferred'
26
- | 'delivered';
27
-
28
- /** Stable output-adapter identifier persisted with a durable detail ACK. */
29
- export type DetailDeliveryVia = string;
30
-
31
- const DETAIL_DELIVERY_VIA_PATTERN = /^[a-z0-9][a-z0-9._-]{0,119}$/;
32
-
33
- export function validateDetailDeliveryVia(value: string): DetailDeliveryVia {
34
- if (!DETAIL_DELIVERY_VIA_PATTERN.test(value)) {
35
- throw new Error(
36
- 'Detail delivery adapter id must be 1-120 lowercase ASCII characters using a-z, 0-9, dot, underscore, or hyphen.',
37
- );
38
- }
39
- return value;
40
- }
41
-
42
- export type LeaseChannel = 'monitor' | 'details';
43
-
44
- export interface PlaySessionRecord {
45
- sessionId: string;
46
- adapterId: string;
47
- accountId: string;
48
- /** Stable remote participation identity used to reattach after owner restart. */
49
- resumeKey?: string;
50
- mode?: string;
51
- status: 'open' | 'sealed';
52
- isCurrent: boolean;
53
- openedAt: string;
54
- sealedAt?: string;
55
- }
56
-
57
- export interface EventSegmentRecord {
58
- segmentId: string;
59
- sessionId: string;
60
- sequence: number;
61
- kind: string;
62
- scopeRef?: string;
63
- status: 'open' | 'closed';
64
- isCurrent: boolean;
65
- openedAt: string;
66
- closedAt?: string;
67
- }
68
-
69
- export interface CurrentEventScope {
70
- session: PlaySessionRecord;
71
- segment: EventSegmentRecord;
72
- }
73
-
74
- export interface EventAccountScope {
75
- adapterId: string;
76
- accountId: string;
77
- }
78
-
79
- export interface EventSourceRef {
80
- /** Stable logical source. It must not change for an ordinary reconnect. */
81
- sourceId: string;
82
- /** Stable backend identity, when the protocol supplies one. */
83
- eventId?: string;
84
- /** Per-source ordering identity, scoped to the target session and segment. */
85
- sequence?: string | number;
86
- /** Physical connection identity. It is diagnostic and never defines a segment. */
87
- connectionId?: string;
88
- replayed?: boolean;
89
- /** Opaque resume token committed atomically with the event. */
90
- checkpoint?: string;
91
- }
92
-
93
- export interface PublishEventInput {
94
- /** Whether this Event may initiate Agent delivery; omitted means true. */
95
- readonly wakeAgent?: boolean;
96
- /** Runtime epoch that admitted or derived this Event. */
97
- epochSeq?: number;
98
- type: string;
99
- producer: EventProducer;
100
- /** Set by Runtime for Epoch Plugin output; absent for Source/backend input. */
101
- producerPluginId?: string;
102
- /** Stable position in that plugin's output list for this epoch. */
103
- producerOutputIndex?: number;
104
- sessionId: string;
105
- segmentId: string;
106
- payload?: Record<string, unknown>;
107
- occurredAt?: string;
108
- receivedAt?: string;
109
- eventId?: string;
110
- source: EventSourceRef;
111
- }
112
-
113
- export interface CanonicalEvent {
114
- /** Whether this Event may initiate Agent delivery; omitted means true. */
115
- readonly wakeAgent?: boolean;
116
- commitSeq: number;
117
- /** Absent only for records written before the epoch runtime migration. */
118
- epochSeq?: number;
119
- eventId: string;
120
- sessionId: string;
121
- segmentId: string;
122
- type: string;
123
- producer: EventProducer;
124
- producerPluginId?: string;
125
- producerOutputIndex?: number;
126
- deliveryClass: EventDeliveryClass;
127
- occurredAt: string;
128
- receivedAt: string;
129
- payload: Record<string, unknown>;
130
- sourceId: string;
131
- sourceEventId?: string;
132
- sourceSequence?: string;
133
- connectionId?: string;
134
- replayed: boolean;
135
- }
136
-
137
- export interface CanonicalEventDraft extends Omit<CanonicalEvent, 'commitSeq'> {}
138
-
139
- export interface EventDeliveryRecord {
140
- eventId: string;
141
- consumerId: string;
142
- monitorState: MonitorDeliveryState;
143
- /** Persisted before the Monitor sink is invoked, enabling owner recovery. */
144
- monitorAttemptCount: number;
145
- monitorLastAttemptAt?: string;
146
- monitorDeliveredAt?: string;
147
- detailState: DetailDeliveryState;
148
- detailDeliveredAt?: string;
149
- detailDeliveryVia?: DetailDeliveryVia;
150
- }
151
-
152
- export interface EventWithDelivery {
153
- event: CanonicalEvent;
154
- delivery: EventDeliveryRecord;
155
- }
156
-
157
- export interface SourceCheckpointRecord {
158
- sourceId: string;
159
- checkpoint: string;
160
- sourceSequence?: string;
161
- eventId: string;
162
- committedAt: string;
163
- }
164
-
165
- export interface CommitEventRequest {
166
- event: CanonicalEventDraft;
167
- consumerIds: string[];
168
- checkpoint?: SourceCheckpointRecord;
169
- }
170
-
171
- export interface CommitEventResult {
172
- inserted: boolean;
173
- event: CanonicalEvent;
174
- }
175
-
176
- export interface EventListFilter {
177
- sessionId: string;
178
- segmentId?: string;
179
- excludeSegmentId?: string;
180
- types?: string[];
181
- deliveryClasses?: EventDeliveryClass[];
182
- detailStates?: DetailDeliveryState[];
183
- monitorStates?: MonitorDeliveryState[];
184
- maxCommitSeq?: number;
185
- /** Excludes Events produced by epochs newer than an immutable Ready View. */
186
- maxEpochSeq?: number;
187
- order?: 'asc' | 'desc';
188
- }
189
-
190
- /** Read-only journal query. It deliberately has no consumer or delivery fields. */
191
- export interface CommittedEventListFilter {
192
- sessionId: string;
193
- segmentId?: string;
194
- types?: string[];
195
- /** Return only Events produced by this exact Runtime epoch. */
196
- epochSeq?: number;
197
- /** Return only events committed strictly after this cursor. */
198
- afterCommitSeq?: number;
199
- maxCommitSeq?: number;
200
- /** Legacy Events without an epoch remain visible; current Runtime Events are bounded. */
201
- maxEpochSeq?: number;
202
- order?: 'asc' | 'desc';
203
- /** Apply the bound in the repository, before payloads are materialized. */
204
- limit?: number;
205
- }
206
-
207
- export interface LatestEventScopeOptions {
208
- /** When supplied, select the newest matching segment in the chosen session. */
209
- segmentKinds?: string[];
210
- }
211
-
212
- export interface BacklogSummary {
213
- unreadCount: number;
214
- segmentCount: number;
215
- oldestAt?: string;
216
- newestAt?: string;
217
- available: boolean;
218
- }
219
-
220
- export interface ConsumerLease {
221
- consumerId: string;
222
- channel: LeaseChannel;
223
- ownerId: string;
224
- expiresAt: number;
225
- }
226
-
227
- export interface AcquireLeaseRequest {
228
- consumerId: string;
229
- channel: LeaseChannel;
230
- ownerId: string;
231
- ttlMs: number;
232
- nowMs?: number;
233
- }
234
-
235
- export interface DetailStateTransition {
236
- eventIds: string[];
237
- consumerId: string;
238
- from: DetailDeliveryState[];
239
- to: DetailDeliveryState;
240
- deliveredAt?: string;
241
- deliveryVia?: DetailDeliveryVia;
242
- lease?: ConsumerLease;
243
- nowMs?: number;
244
- }
245
-
246
- export interface MonitorStateTransition {
247
- eventIds: string[];
248
- consumerId: string;
249
- from: MonitorDeliveryState[];
250
- to: MonitorDeliveryState;
251
- deliveredAt?: string;
252
- lease?: ConsumerLease;
253
- nowMs?: number;
254
- }
255
-
256
- export interface MonitorDeliveryAttempt {
257
- eventId: string;
258
- consumerId: string;
259
- attemptedAt: string;
260
- lease: ConsumerLease;
261
- nowMs?: number;
262
- }
263
-
264
- export interface EventCatalogEntry {
265
- type: string;
266
- producer: EventProducer;
267
- deliveryClass: EventDeliveryClass;
268
- }
269
-
270
- export function initialDeliveryFor(
271
- event: Pick<CanonicalEvent, 'eventId' | 'deliveryClass'>,
272
- consumerId: string,
273
- channels: readonly LeaseChannel[] = ['monitor', 'details'],
274
- ): EventDeliveryRecord {
275
- let delivery: EventDeliveryRecord;
276
- switch (event.deliveryClass) {
277
- case 'monitor_and_events':
278
- delivery = {
279
- eventId: event.eventId,
280
- consumerId,
281
- monitorState: 'pending',
282
- monitorAttemptCount: 0,
283
- detailState: 'pending',
284
- };
285
- break;
286
- case 'events_only':
287
- delivery = {
288
- eventId: event.eventId,
289
- consumerId,
290
- monitorState: 'not_applicable',
291
- monitorAttemptCount: 0,
292
- detailState: 'pending',
293
- };
294
- break;
295
- case 'internal_only':
296
- delivery = {
297
- eventId: event.eventId,
298
- consumerId,
299
- monitorState: 'not_applicable',
300
- monitorAttemptCount: 0,
301
- detailState: 'not_applicable',
302
- };
303
- break;
304
- }
305
- if (!channels.includes('monitor')) delivery.monitorState = 'not_applicable';
306
- if (!channels.includes('details')) delivery.detailState = 'not_applicable';
307
- return delivery;
308
- }
309
-
310
- export function cloneRecord<T>(value: T): T {
311
- return structuredClone(value);
312
- }
1
+ // Compatibility facade; implementation lives in the game-neutral runtime package.
2
+ export * from '@myclaw163/game-agent-runtime/framework/events/types.js';
@@ -1,7 +1,3 @@
1
- /** Public, game-neutral CCL Runtime framework. */
2
- export * from './runtime.js';
3
- export * from './plugins/index.js';
4
- export * from './events/index.js';
5
- export * from './mailbox/index.js';
6
- export * from './state/index.js';
7
- export * from './capability-registry.js';
1
+ export * from '@myclaw163/game-agent-runtime/framework/index.js';
2
+ export { Runtime } from './runtime.js';
3
+ export { SqliteEventRepository } from './events/sqlite-event-repository.js';
@@ -1,17 +1,2 @@
1
- /**
2
- * Load node:sqlite without leaking Node's version-dependent ExperimentalWarning
3
- * into Agent-facing stderr. Other warnings keep their normal behavior.
4
- */
5
- export function loadNodeSqliteModule<T>(requireModule: (id: string) => unknown): T {
6
- const original = process.emitWarning;
7
- process.emitWarning = ((warning: string | Error, ...args: any[]) => {
8
- const message = warning instanceof Error ? warning.message : String(warning);
9
- if (message.includes('SQLite is an experimental feature')) return;
10
- return (original as any).call(process, warning, ...args);
11
- }) as typeof process.emitWarning;
12
- try {
13
- return requireModule('node:sqlite') as T;
14
- } finally {
15
- process.emitWarning = original;
16
- }
17
- }
1
+ // Compatibility facade; implementation lives in the game-neutral runtime package.
2
+ export * from '@myclaw163/game-agent-runtime/framework/load-node-sqlite.js';
@@ -1,83 +1,2 @@
1
- import { stableMailboxNotificationId } from './identity.js';
2
- import type { MailboxDeliveryMode, MailboxItem } from './types.js';
3
-
4
- export interface MailboxNotification<TPayload = unknown> {
5
- notificationId: string;
6
- consumerId: string;
7
- sessionId: string;
8
- segmentId: string;
9
- mode: MailboxDeliveryMode;
10
- formatterVersion: string;
11
- coalesceKey: string;
12
- itemIds: string[];
13
- eventIds: string[];
14
- firstEventCommitSeq: number;
15
- lastEventCommitSeq: number;
16
- payload: TPayload;
17
- }
18
-
19
- /**
20
- * A coalescer only shapes already-presented Mailbox payloads. It never reads
21
- * game Event types, decides when to wake an Agent, or changes delivery state.
22
- */
23
- export interface MailboxCoalescer<TItemPayload = unknown, TNotificationPayload = TItemPayload> {
24
- /** Passed to Repository.claimMailbox; the repository still enforces FIFO. */
25
- readonly maxItems: number;
26
- coalesce(items: readonly MailboxItem<TItemPayload>[]): MailboxNotification<TNotificationPayload>;
27
- }
28
-
29
- function assertOneClaimGroup<T>(items: readonly MailboxItem<T>[]): MailboxItem<T> {
30
- const first = items[0];
31
- if (!first) throw new Error('Cannot coalesce an empty Mailbox claim.');
32
-
33
- for (const item of items.slice(1)) {
34
- if (
35
- item.consumerId !== first.consumerId
36
- || item.sessionId !== first.sessionId
37
- || item.segmentId !== first.segmentId
38
- || item.mode !== first.mode
39
- || item.formatterVersion !== first.formatterVersion
40
- || item.coalesceKey !== first.coalesceKey
41
- ) {
42
- throw new Error(
43
- 'A Mailbox claim may only contain one consumer, segment, mode, formatter version, and coalesce key.',
44
- );
45
- }
46
- }
47
- return first;
48
- }
49
-
50
- export function mailboxNotification<TItemPayload, TNotificationPayload>(
51
- items: readonly MailboxItem<TItemPayload>[],
52
- payload: TNotificationPayload,
53
- ): MailboxNotification<TNotificationPayload> {
54
- const first = assertOneClaimGroup(items);
55
- const last = items[items.length - 1] ?? first;
56
- return {
57
- notificationId: stableMailboxNotificationId(items.map((item) => item.itemId)),
58
- consumerId: first.consumerId,
59
- sessionId: first.sessionId,
60
- segmentId: first.segmentId,
61
- mode: first.mode,
62
- formatterVersion: first.formatterVersion,
63
- coalesceKey: first.coalesceKey,
64
- itemIds: items.map((item) => item.itemId),
65
- eventIds: items.map((item) => item.eventId),
66
- firstEventCommitSeq: first.eventCommitSeq,
67
- lastEventCommitSeq: last.eventCommitSeq,
68
- payload,
69
- };
70
- }
71
-
72
- /** Default policy: claim and deliver exactly one durable item at a time. */
73
- export class IdentityMailboxCoalescer<TPayload = unknown>
74
- implements MailboxCoalescer<TPayload, TPayload> {
75
- readonly maxItems = 1;
76
-
77
- coalesce(items: readonly MailboxItem<TPayload>[]): MailboxNotification<TPayload> {
78
- if (items.length !== 1) {
79
- throw new Error(`IdentityMailboxCoalescer expected one item, received ${items.length}.`);
80
- }
81
- return mailboxNotification(items, items[0]!.payload);
82
- }
83
- }
1
+ // Compatibility facade; implementation lives in the game-neutral runtime package.
2
+ export * from '@myclaw163/game-agent-runtime/framework/mailbox/coalescer.js';
@@ -1,44 +1,2 @@
1
- import type { MailboxNotification } from './coalescer.js';
2
- import type { MailboxAcceptanceLevel } from './types.js';
3
-
4
- /**
5
- * Returning means this adapter completed the handoff level named by
6
- * acceptanceLevel. Implementations must not wait for the Agent's resulting
7
- * turn to finish, and stdout-like sinks must not claim Host acceptance.
8
- */
9
- export interface HostNotificationAcceptance {
10
- acceptedAt: string;
11
- receiptId?: string;
12
- /**
13
- * `sink_emitted` is the conservative default for stdout-like transports.
14
- * `host_accepted` means the Host durably acknowledged its own input queue.
15
- */
16
- acceptanceLevel?: MailboxAcceptanceLevel;
17
- }
18
-
19
- /** A Host rejected this notification with an explicit retry policy. */
20
- export class HostNotificationDeliveryError extends Error {
21
- readonly retryable: boolean;
22
- readonly code: string;
23
- readonly httpStatus?: number;
24
-
25
- constructor(options: {
26
- message: string;
27
- retryable: boolean;
28
- code: string;
29
- httpStatus?: number;
30
- }) {
31
- super(options.message);
32
- this.name = 'HostNotificationDeliveryError';
33
- this.retryable = options.retryable;
34
- this.code = options.code;
35
- this.httpStatus = options.httpStatus;
36
- }
37
- }
38
-
39
- export interface HostNotificationSink<TPayload = unknown> {
40
- deliver(
41
- notification: MailboxNotification<TPayload>,
42
- signal: AbortSignal,
43
- ): Promise<HostNotificationAcceptance>;
44
- }
1
+ // Compatibility facade; implementation lives in the game-neutral runtime package.
2
+ export * from '@myclaw163/game-agent-runtime/framework/mailbox/host-notification-sink.js';
@@ -1,38 +1,2 @@
1
- import { createHash } from 'node:crypto';
2
- import type { MailboxDeliveryMode } from './types.js';
3
-
4
- export interface StableMailboxItemIdentity {
5
- consumerId: string;
6
- sessionId: string;
7
- eventId: string;
8
- mode: MailboxDeliveryMode;
9
- }
10
-
11
- /**
12
- * Builds the durable identity of one Event delivery without including mutable
13
- * presentation or retry fields. Re-projecting the same Event is therefore an
14
- * idempotent enqueue even after a process restart or formatter upgrade.
15
- */
16
- export function stableMailboxItemId(identity: StableMailboxItemIdentity): string {
17
- const digest = createHash('sha256')
18
- .update(JSON.stringify([
19
- 'ccl.mailbox.item.v1',
20
- identity.consumerId,
21
- identity.sessionId,
22
- identity.eventId,
23
- identity.mode,
24
- ]))
25
- .digest('hex');
26
- return `mbx_${digest}`;
27
- }
28
-
29
- /** Stable for one ordered item set; reliable Hosts should also dedupe itemIds. */
30
- export function stableMailboxNotificationId(itemIds: readonly string[]): string {
31
- if (itemIds.length === 0) {
32
- throw new Error('A mailbox notification must contain at least one item.');
33
- }
34
- const digest = createHash('sha256')
35
- .update(JSON.stringify(['ccl.mailbox.notification.v1', ...itemIds]))
36
- .digest('hex');
37
- return `mbn_${digest}`;
38
- }
1
+ // Compatibility facade; implementation lives in the game-neutral runtime package.
2
+ export * from '@myclaw163/game-agent-runtime/framework/mailbox/identity.js';
@@ -1,7 +1 @@
1
- export * from './types.js';
2
- export * from './mailbox-repository.js';
3
- export * from './identity.js';
4
- export * from './notification-projector.js';
5
- export * from './coalescer.js';
6
- export * from './host-notification-sink.js';
7
- export * from './mailbox-dispatcher.js';
1
+ export * from '@myclaw163/game-agent-runtime/framework/mailbox/index.js';