@myclaw163/clawclaw-cli 0.9.2 → 0.10.2

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 (224) hide show
  1. package/QUICKSTART.md +1 -1
  2. package/QUICKSTART_OTHER.md +13 -12
  3. package/README.md +7 -8
  4. package/bin/clawclaw-channel.mjs +2 -2
  5. package/bin/clawclaw-cli.mjs +2 -2
  6. package/docs/configuration.md +27 -101
  7. package/docs/custom-modules/README.md +23 -35
  8. package/docs/custom-modules/api-reference.md +95 -273
  9. package/docs/custom-modules/behavior.md +94 -78
  10. package/docs/custom-modules/examples/auto-escape.ts +5 -5
  11. package/docs/custom-modules/examples/go-to-point.ts +11 -11
  12. package/docs/custom-modules/examples/nearby-reflex.ts +2 -2
  13. package/docs/custom-modules/examples/task-reminder.ts +4 -5
  14. package/docs/custom-modules/perception.md +42 -603
  15. package/docs/custom-modules/skill.md +12 -10
  16. package/docs/desktop-event-push.md +3 -3
  17. package/docs/runtime/README.md +16 -17
  18. package/docs/runtime/agent-notifications.md +42 -12
  19. package/docs/runtime/behavior-runtime.md +47 -46
  20. package/docs/runtime/components-and-boundaries.md +70 -28
  21. package/docs/runtime/events-and-state.md +41 -18
  22. package/docs/runtime/framework-package.md +73 -0
  23. package/docs/runtime/official-perception-modules.md +5 -5
  24. package/docs/runtime/owner-lifecycle-and-observability.md +6 -6
  25. package/docs/runtime/short-commands-and-capabilities.md +8 -9
  26. package/docs/user-guide/README.md +10 -7
  27. package/docs/user-guide/api-reference.md +81 -164
  28. package/docs/user-guide/behavior.md +84 -68
  29. package/docs/user-guide/installation.md +7 -7
  30. package/docs/user-guide/perception.md +42 -586
  31. package/docs/user-guide/skill.md +12 -10
  32. package/package.json +24 -9
  33. package/scripts/check-framework-boundaries.mjs +27 -0
  34. package/scripts/check-skill-command-surface.mjs +20 -23
  35. package/scripts/enable_ccl_permissions.cjs +4 -0
  36. package/scripts/install-local-runtime.mjs +35 -0
  37. package/scripts/postinstall.mjs +1 -1
  38. package/scripts/qa-install.mjs +105 -0
  39. package/scripts/sync-bundled-skill.mjs +35 -28
  40. package/skills/clawclaw/SKILL.md +53 -57
  41. package/skills/clawclaw/references/BEHAVIORS.md +43 -83
  42. package/skills/clawclaw/references/CHANNELS.md +2 -2
  43. package/skills/clawclaw/references/COMMANDS.md +62 -103
  44. package/skills/clawclaw/references/HUB.md +2 -2
  45. package/skills/clawclaw/references/STREAM.md +8 -8
  46. package/skills/clawclaw/references/TACTICS.md +1 -1
  47. package/skills/clawclaw-creator/SKILL.md +82 -0
  48. package/skills/{clawclaw → clawclaw-creator}/references/CUSTOM-BEHAVIOR-DEVELOPMENT.md +95 -79
  49. package/skills/{clawclaw → clawclaw-creator}/references/CUSTOM-MODULE-API.md +95 -180
  50. package/skills/{clawclaw → clawclaw-creator}/references/CUSTOM-MODULES.md +26 -24
  51. package/skills/clawclaw-creator/references/CUSTOM-PERCEPTION-DEVELOPMENT.md +126 -0
  52. package/skills/clawclaw-creator/references/CUSTOM-PERSONA-DEVELOPMENT.md +29 -0
  53. package/skills/clawclaw-creator/references/CUSTOM-SKILL-DEVELOPMENT.md +69 -0
  54. package/skills/clawclaw-creator/references/SYNC-AND-REPORT.md +36 -0
  55. package/src/channel/claude-channel-ipc-server.ts +1 -0
  56. package/src/cli.ts +4 -2
  57. package/src/commands/behavior.ts +26 -10
  58. package/src/commands/capability.ts +17 -14
  59. package/src/commands/load.ts +5 -3
  60. package/src/commands/perception.ts +5 -0
  61. package/src/commands/skill.ts +34 -29
  62. package/src/commands/strategy.ts +2 -0
  63. package/src/commands/upgrade.ts +2 -2
  64. package/src/lib/agent-workspace-skills.ts +20 -13
  65. package/src/lib/capability-cloud-sync.ts +2 -1
  66. package/src/lib/capability-discovery.ts +2 -1
  67. package/src/lib/capability-load-diagnostics.ts +3 -3
  68. package/src/lib/capability-workspace.ts +2 -1
  69. package/src/lib/game-client.ts +7 -1
  70. package/src/lib/package-skills.ts +4 -0
  71. package/src/lib/perception-config.ts +18 -6
  72. package/src/lib/runtime-cadence-config.ts +16 -0
  73. package/src/lib/skill-host.ts +1 -1
  74. package/src/lib/workspace-runtime-lock.ts +3 -46
  75. package/src/pipeline/canonical-event-presentation.ts +23 -124
  76. package/src/pipeline/event-format.ts +12 -21
  77. package/src/pipeline/event-hints.ts +6 -6
  78. package/src/pipeline/game-sync-event-normalization.ts +57 -63
  79. package/src/runtime/clawclaw/behavior-decision.ts +7 -3
  80. package/src/runtime/clawclaw/behavior-input.ts +8 -4
  81. package/src/runtime/clawclaw/behavior-observation-memory.ts +3 -2
  82. package/src/runtime/clawclaw/notification-policy.ts +42 -0
  83. package/src/runtime/clawclaw/notification-turn.ts +19 -0
  84. package/src/runtime/clawclaw/observation-frame-projector.ts +3 -3
  85. package/src/runtime/clawclaw/owner.ts +47 -9
  86. package/src/runtime/clawclaw/perception-module-manifest.ts +8 -3
  87. package/src/runtime/clawclaw/perception-strategy-names.ts +17 -0
  88. package/src/runtime/clawclaw/persistence-compatibility.ts +36 -0
  89. package/src/runtime/clawclaw/plugins/action/action-plugin.ts +3 -3
  90. package/src/runtime/clawclaw/plugins/assembly.ts +7 -9
  91. package/src/runtime/clawclaw/plugins/behavior/activation-manager.ts +1 -495
  92. package/src/runtime/clawclaw/plugins/behavior/behavior-analysis-thread-host.ts +17 -190
  93. package/src/runtime/clawclaw/plugins/behavior/behavior-instance-snapshot.ts +1 -123
  94. package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.ts +126 -1779
  95. package/src/runtime/clawclaw/plugins/behavior/behavior-runner.ts +13 -276
  96. package/src/runtime/clawclaw/plugins/behavior/behavior-source.ts +2 -2
  97. package/src/runtime/clawclaw/plugins/behavior/behavior-worker-bridge.ts +8 -0
  98. package/src/runtime/clawclaw/plugins/behavior/control-driver.ts +3 -180
  99. package/src/runtime/clawclaw/plugins/behavior/thread-behavior-executor.ts +13 -972
  100. package/src/runtime/clawclaw/plugins/derived-event/derived-event-plugin.ts +8 -109
  101. package/src/runtime/clawclaw/plugins/derived-event/derived-event-rules.ts +2 -2
  102. package/src/runtime/clawclaw/plugins/derived-event/reminder-plugin.ts +27 -17
  103. package/src/runtime/clawclaw/plugins/derived-event/reminder-runner.ts +1 -0
  104. package/src/runtime/clawclaw/plugins/derived-event/state-change-rules.ts +3 -3
  105. package/src/runtime/clawclaw/plugins/derived-event/task-change-tracker.ts +1 -259
  106. package/src/runtime/clawclaw/plugins/game-query/game-query-plugin.ts +4 -4
  107. package/src/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-adapter.ts +9 -97
  108. package/src/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-socket.ts +8 -343
  109. package/src/runtime/clawclaw/plugins/mailbox/adapters/game-sync-perception-report-adapter.ts +15 -20
  110. package/src/runtime/clawclaw/plugins/mailbox/adapters/game-sync-runtime-report-adapter.ts +59 -0
  111. package/src/runtime/clawclaw/plugins/mailbox/agent-mailbox-coordinator.ts +60 -572
  112. package/src/runtime/clawclaw/plugins/mailbox/desktop-event-socket.ts +6 -434
  113. package/src/runtime/clawclaw/plugins/mailbox/index.ts +1 -0
  114. package/src/runtime/clawclaw/plugins/mailbox/mailbox-event-batch-delivery.ts +1 -266
  115. package/src/runtime/clawclaw/plugins/mailbox/mailbox-plugin.ts +6 -161
  116. package/src/runtime/clawclaw/plugins/mailbox/mailbox-presentation.ts +4 -23
  117. package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.ts +49 -752
  118. package/src/runtime/clawclaw/plugins/perception/map-concurrent.ts +1 -0
  119. package/src/runtime/clawclaw/plugins/perception/notification-content.ts +60 -0
  120. package/src/runtime/clawclaw/plugins/perception/perception-module-plugin.ts +125 -297
  121. package/src/runtime/clawclaw/plugins/perception/perception-module-runner.ts +7 -56
  122. package/src/runtime/clawclaw/plugins/perception/perception-module-worker.ts +11 -33
  123. package/src/runtime/clawclaw/plugins/perception/perception-plugin.ts +25 -10
  124. package/src/runtime/clawclaw/plugins/perception/perception-source.ts +12 -6
  125. package/src/runtime/clawclaw/plugins/perception/report-content.ts +50 -0
  126. package/src/runtime/clawclaw/plugins/perception/task-baseline.ts +29 -0
  127. package/src/runtime/clawclaw/plugins/source/source-plugin.ts +6 -0
  128. package/src/runtime/clawclaw/plugins/system-perception/rule-runner.ts +107 -0
  129. package/src/runtime/clawclaw/plugins/system-perception/system-perceptions.ts +107 -0
  130. package/src/runtime/clawclaw/plugins/trigger/trigger-plugin.ts +8 -3
  131. package/src/runtime/clawclaw/reaction-behavior-resolution.ts +1 -23
  132. package/src/runtime/clawclaw/reminder-manifest.ts +5 -2
  133. package/src/runtime/clawclaw/runtime-cadence.ts +24 -0
  134. package/src/runtime/clawclaw/runtime-state.ts +11 -0
  135. package/src/runtime/clawclaw/runtime.ts +8 -0
  136. package/src/runtime/clawclaw/strategy-memory-rpc.ts +1 -63
  137. package/src/runtime/clawclaw/strategy-memory.ts +1 -77
  138. package/src/runtime/clawclaw-event-catalog.ts +12 -12
  139. package/src/runtime/framework/action-diagnostics.ts +3 -83
  140. package/src/runtime/framework/capability-registry.ts +2 -395
  141. package/src/runtime/framework/contracts.ts +2 -144
  142. package/src/runtime/framework/control/control-scheduler.ts +2 -1268
  143. package/src/runtime/framework/control/domain-set.ts +2 -81
  144. package/src/runtime/framework/control/index.ts +1 -3
  145. package/src/runtime/framework/control/types.ts +2 -191
  146. package/src/runtime/framework/control-coordinator.ts +2 -11
  147. package/src/runtime/framework/events/event-catalog.ts +2 -74
  148. package/src/runtime/framework/events/event-delivery-service.ts +2 -200
  149. package/src/runtime/framework/events/event-ingress.ts +2 -99
  150. package/src/runtime/framework/events/event-repository.ts +2 -82
  151. package/src/runtime/framework/events/index.ts +2 -7
  152. package/src/runtime/framework/events/memory-event-repository.ts +2 -1100
  153. package/src/runtime/framework/events/runtime-resume.ts +2 -20
  154. package/src/runtime/framework/events/sqlite-event-repository.ts +5 -2280
  155. package/src/runtime/framework/events/test-helpers.ts +1 -1
  156. package/src/runtime/framework/events/types.ts +2 -312
  157. package/src/runtime/framework/index.ts +3 -7
  158. package/src/runtime/framework/load-node-sqlite.ts +2 -17
  159. package/src/runtime/framework/mailbox/coalescer.ts +2 -83
  160. package/src/runtime/framework/mailbox/host-notification-sink.ts +2 -44
  161. package/src/runtime/framework/mailbox/identity.ts +2 -38
  162. package/src/runtime/framework/mailbox/index.ts +1 -7
  163. package/src/runtime/framework/mailbox/mailbox-dispatcher.ts +2 -282
  164. package/src/runtime/framework/mailbox/mailbox-repository.ts +2 -44
  165. package/src/runtime/framework/mailbox/notification-projector.ts +2 -65
  166. package/src/runtime/framework/mailbox/types.ts +2 -145
  167. package/src/runtime/framework/modules/runtime-module-loader-hooks.mjs +2 -154
  168. package/src/runtime/framework/modules/runtime-module-loader.ts +7 -51
  169. package/src/runtime/framework/modules/runtime-module-output.ts +2 -24
  170. package/src/runtime/framework/modules/runtime-module-worker-bootstrap.mjs +3 -23
  171. package/src/runtime/framework/participation-manager.ts +2 -253
  172. package/src/runtime/framework/persistence/async-sqlite-persistence-worker.ts +2 -77
  173. package/src/runtime/framework/persistence/memory-first-persistence.ts +4 -489
  174. package/src/runtime/framework/plugins/contracts.ts +2 -396
  175. package/src/runtime/framework/plugins/index.ts +1 -4
  176. package/src/runtime/framework/plugins/runtime-event-identity.ts +2 -17
  177. package/src/runtime/framework/plugins/runtime-input-journal.ts +2 -866
  178. package/src/runtime/framework/plugins/runtime-plugin-scheduler.ts +2 -2071
  179. package/src/runtime/framework/runtime.ts +5 -1843
  180. package/src/runtime/framework/serial-task-queue.ts +2 -14
  181. package/src/runtime/framework/state/contracts.ts +2 -49
  182. package/src/runtime/framework/state/current-state-store.ts +2 -184
  183. package/src/runtime/framework/state/durable-agent-state-snapshot.ts +2 -209
  184. package/src/runtime/framework/state/freshness.ts +2 -72
  185. package/src/runtime/framework/state/history/contracts.ts +2 -158
  186. package/src/runtime/framework/state/history/history-writer.ts +2 -194
  187. package/src/runtime/framework/state/history/memory-state-history-repository.ts +2 -230
  188. package/src/runtime/framework/state/history/sqlite-state-history-repository.ts +2 -648
  189. package/src/runtime/framework/state/history/trajectory-projector.ts +2 -209
  190. package/src/runtime/framework/state/index.ts +1 -13
  191. package/src/runtime/framework/state/state-ingress.ts +2 -95
  192. package/src/runtime/framework/state/state-provider.ts +2 -62
  193. package/src/runtime/framework/state/types.ts +2 -155
  194. package/src/runtime/game-sync-ingress-protocol.ts +3 -2
  195. package/src/runtime/game-sync-ingress-worker.ts +7 -1
  196. package/src/runtime/game-sync-protocol.ts +64 -4
  197. package/src/runtime/host-monitor-rate-gate.ts +1 -123
  198. package/src/runtime/mailbox-host-relay.ts +1 -326
  199. package/src/runtime/observability/detail-capture.ts +4 -108
  200. package/src/runtime/observability/process-timing.ts +2 -59
  201. package/src/runtime/observability/recorder.ts +2 -238
  202. package/src/runtime/observability/redaction.ts +2 -181
  203. package/src/runtime/observability/reporter.ts +2 -154
  204. package/src/runtime/observability/sinks.ts +2 -135
  205. package/src/runtime/observability/types.ts +2 -92
  206. package/src/runtime/owner-control.ts +45 -320
  207. package/src/runtime/parent-process-watch.ts +1 -51
  208. package/src/runtime/process-identity.ts +1 -72
  209. package/src/runtime/threaded-ws-client.ts +11 -2
  210. package/src/runtime/ws-client.ts +6 -0
  211. package/src/sdk/behavior-plugin/index.ts +9 -3
  212. package/src/sdk/index.ts +40 -2
  213. package/src/sdk/module-input/index.ts +5 -0
  214. package/src/sdk/perception-plugin/index.ts +3 -1
  215. package/src/sdk/perception-plugin/module.ts +12 -2
  216. package/src/sdk/perception-plugin/reminder-rules.ts +8 -42
  217. package/src/sdk/perception-plugin/reminder.ts +2 -1
  218. package/src/sdk/perception-plugin/task-change-tracker.ts +258 -0
  219. package/src/sdk/strategy-memory.ts +1 -12
  220. package/src/sdk/strategy-plugin/index.ts +36 -0
  221. package/src/sdk/trigger-plugin/index.ts +1 -0
  222. package/docs/custom-modules/trigger.md +0 -295
  223. package/skills/clawclaw/references/CUSTOM-PERCEPTION-DEVELOPMENT.md +0 -692
  224. package/skills/clawclaw/references/CUSTOM-SKILL-DEVELOPMENT.md +0 -67
@@ -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';