@myclaw163/game-agent-runtime 0.0.0-stage → 0.1.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 (204) hide show
  1. package/README.md +67 -2
  2. package/dist/framework/action-diagnostics.d.ts +11 -0
  3. package/dist/framework/action-diagnostics.js +67 -0
  4. package/dist/framework/capability-registry.d.ts +58 -0
  5. package/dist/framework/capability-registry.js +325 -0
  6. package/dist/framework/contracts.d.ts +121 -0
  7. package/dist/framework/contracts.js +2 -0
  8. package/dist/framework/control/control-scheduler.d.ts +69 -0
  9. package/dist/framework/control/control-scheduler.js +1016 -0
  10. package/dist/framework/control/domain-set.d.ts +18 -0
  11. package/dist/framework/control/domain-set.js +70 -0
  12. package/dist/framework/control/index.d.ts +3 -0
  13. package/dist/framework/control/index.js +3 -0
  14. package/dist/framework/control/types.d.ts +142 -0
  15. package/dist/framework/control/types.js +13 -0
  16. package/dist/framework/control-coordinator.d.ts +7 -0
  17. package/dist/framework/control-coordinator.js +7 -0
  18. package/dist/framework/events/event-catalog.d.ts +23 -0
  19. package/dist/framework/events/event-catalog.js +52 -0
  20. package/dist/framework/events/event-delivery-service.d.ts +33 -0
  21. package/dist/framework/events/event-delivery-service.js +165 -0
  22. package/dist/framework/events/event-ingress.d.ts +28 -0
  23. package/dist/framework/events/event-ingress.js +76 -0
  24. package/dist/framework/events/event-repository.d.ts +38 -0
  25. package/dist/framework/events/event-repository.js +20 -0
  26. package/dist/framework/events/index.d.ts +7 -0
  27. package/dist/framework/events/index.js +7 -0
  28. package/dist/framework/events/memory-event-repository.d.ts +77 -0
  29. package/dist/framework/events/memory-event-repository.js +909 -0
  30. package/dist/framework/events/runtime-resume.d.ts +11 -0
  31. package/dist/framework/events/runtime-resume.js +7 -0
  32. package/dist/framework/events/sqlite-event-repository.d.ts +94 -0
  33. package/dist/framework/events/sqlite-event-repository.js +2044 -0
  34. package/dist/framework/events/store-compatibility.d.ts +17 -0
  35. package/dist/framework/events/store-compatibility.js +17 -0
  36. package/dist/framework/events/types.d.ts +244 -0
  37. package/dist/framework/events/types.js +39 -0
  38. package/dist/framework/index.d.ts +7 -0
  39. package/dist/framework/index.js +7 -0
  40. package/dist/framework/load-node-sqlite.d.ts +5 -0
  41. package/dist/framework/load-node-sqlite.js +19 -0
  42. package/dist/framework/mailbox/coalescer.d.ts +30 -0
  43. package/dist/framework/mailbox/coalescer.js +45 -0
  44. package/dist/framework/mailbox/host-notification-sink.d.ts +31 -0
  45. package/dist/framework/mailbox/host-notification-sink.js +13 -0
  46. package/dist/framework/mailbox/identity.d.ts +15 -0
  47. package/dist/framework/mailbox/identity.js +28 -0
  48. package/dist/framework/mailbox/index.d.ts +7 -0
  49. package/dist/framework/mailbox/index.js +7 -0
  50. package/dist/framework/mailbox/mailbox-dispatcher.d.ts +65 -0
  51. package/dist/framework/mailbox/mailbox-dispatcher.js +242 -0
  52. package/dist/framework/mailbox/mailbox-repository.d.ts +17 -0
  53. package/dist/framework/mailbox/mailbox-repository.js +9 -0
  54. package/dist/framework/mailbox/notification-projector.d.ts +25 -0
  55. package/dist/framework/mailbox/notification-projector.js +50 -0
  56. package/dist/framework/mailbox/types.d.ts +128 -0
  57. package/dist/framework/mailbox/types.js +1 -0
  58. package/dist/framework/modules/runtime-module-loader-hooks.mjs +156 -0
  59. package/dist/framework/modules/runtime-module-loader.d.ts +14 -0
  60. package/dist/framework/modules/runtime-module-loader.js +64 -0
  61. package/dist/framework/modules/runtime-module-output.d.ts +7 -0
  62. package/dist/framework/modules/runtime-module-output.js +15 -0
  63. package/dist/framework/modules/runtime-module-worker-bootstrap.mjs +23 -0
  64. package/dist/framework/participation-manager.d.ts +94 -0
  65. package/dist/framework/participation-manager.js +185 -0
  66. package/dist/framework/persistence/async-sqlite-persistence-worker.d.ts +1 -0
  67. package/dist/framework/persistence/async-sqlite-persistence-worker.js +62 -0
  68. package/dist/framework/persistence/memory-first-persistence.d.ts +36 -0
  69. package/dist/framework/persistence/memory-first-persistence.js +459 -0
  70. package/dist/framework/plugins/contracts.d.ts +345 -0
  71. package/dist/framework/plugins/contracts.js +1 -0
  72. package/dist/framework/plugins/index.d.ts +4 -0
  73. package/dist/framework/plugins/index.js +4 -0
  74. package/dist/framework/plugins/runtime-event-identity.d.ts +3 -0
  75. package/dist/framework/plugins/runtime-event-identity.js +11 -0
  76. package/dist/framework/plugins/runtime-input-journal.d.ts +85 -0
  77. package/dist/framework/plugins/runtime-input-journal.js +716 -0
  78. package/dist/framework/plugins/runtime-plugin-scheduler.d.ts +188 -0
  79. package/dist/framework/plugins/runtime-plugin-scheduler.js +1660 -0
  80. package/dist/framework/runtime.d.ts +264 -0
  81. package/dist/framework/runtime.js +1811 -0
  82. package/dist/framework/serial-task-queue.d.ts +6 -0
  83. package/dist/framework/serial-task-queue.js +12 -0
  84. package/dist/framework/state/contracts.d.ts +30 -0
  85. package/dist/framework/state/contracts.js +1 -0
  86. package/dist/framework/state/current-state-store.d.ts +17 -0
  87. package/dist/framework/state/current-state-store.js +153 -0
  88. package/dist/framework/state/durable-agent-state-snapshot.d.ts +61 -0
  89. package/dist/framework/state/durable-agent-state-snapshot.js +162 -0
  90. package/dist/framework/state/freshness.d.ts +7 -0
  91. package/dist/framework/state/freshness.js +52 -0
  92. package/dist/framework/state/history/contracts.d.ts +133 -0
  93. package/dist/framework/state/history/contracts.js +1 -0
  94. package/dist/framework/state/history/history-writer.d.ts +55 -0
  95. package/dist/framework/state/history/history-writer.js +157 -0
  96. package/dist/framework/state/history/memory-state-history-repository.d.ts +25 -0
  97. package/dist/framework/state/history/memory-state-history-repository.js +199 -0
  98. package/dist/framework/state/history/sqlite-state-history-repository.d.ts +28 -0
  99. package/dist/framework/state/history/sqlite-state-history-repository.js +565 -0
  100. package/dist/framework/state/history/trajectory-projector.d.ts +53 -0
  101. package/dist/framework/state/history/trajectory-projector.js +130 -0
  102. package/dist/framework/state/index.d.ts +12 -0
  103. package/dist/framework/state/index.js +12 -0
  104. package/dist/framework/state/state-ingress.d.ts +18 -0
  105. package/dist/framework/state/state-ingress.js +68 -0
  106. package/dist/framework/state/state-provider.d.ts +11 -0
  107. package/dist/framework/state/state-provider.js +56 -0
  108. package/dist/framework/state/types.d.ts +107 -0
  109. package/dist/framework/state/types.js +19 -0
  110. package/dist/index.d.ts +1 -0
  111. package/dist/index.js +1 -0
  112. package/dist/mailbox/adapters/claude-channel-adapter.d.ts +34 -0
  113. package/dist/mailbox/adapters/claude-channel-adapter.js +71 -0
  114. package/dist/mailbox/adapters/claude-channel-socket.d.ts +56 -0
  115. package/dist/mailbox/adapters/claude-channel-socket.js +279 -0
  116. package/dist/mailbox/adapters/desktop-event-socket.d.ts +81 -0
  117. package/dist/mailbox/adapters/desktop-event-socket.js +339 -0
  118. package/dist/mailbox/agent-mailbox-coordinator.d.ts +104 -0
  119. package/dist/mailbox/agent-mailbox-coordinator.js +412 -0
  120. package/dist/mailbox/host-monitor-rate-gate.d.ts +60 -0
  121. package/dist/mailbox/host-monitor-rate-gate.js +93 -0
  122. package/dist/mailbox/mailbox-event-batch-delivery.d.ts +73 -0
  123. package/dist/mailbox/mailbox-event-batch-delivery.js +251 -0
  124. package/dist/mailbox/mailbox-host-relay.d.ts +52 -0
  125. package/dist/mailbox/mailbox-host-relay.js +299 -0
  126. package/dist/mailbox/mailbox-plugin.d.ts +58 -0
  127. package/dist/mailbox/mailbox-plugin.js +128 -0
  128. package/dist/mailbox/mailbox-service.d.ts +128 -0
  129. package/dist/mailbox/mailbox-service.js +582 -0
  130. package/dist/memory/contracts.d.ts +12 -0
  131. package/dist/memory/contracts.js +1 -0
  132. package/dist/memory/strategy-memory-rpc.d.ts +21 -0
  133. package/dist/memory/strategy-memory-rpc.js +86 -0
  134. package/dist/memory/strategy-memory.d.ts +15 -0
  135. package/dist/memory/strategy-memory.js +95 -0
  136. package/dist/observability/detail-capture.d.ts +25 -0
  137. package/dist/observability/detail-capture.js +136 -0
  138. package/dist/observability/index.d.ts +5 -0
  139. package/dist/observability/index.js +5 -0
  140. package/dist/observability/process-timing.d.ts +14 -0
  141. package/dist/observability/process-timing.js +56 -0
  142. package/dist/observability/recorder.d.ts +56 -0
  143. package/dist/observability/recorder.js +202 -0
  144. package/dist/observability/redaction.d.ts +30 -0
  145. package/dist/observability/redaction.js +166 -0
  146. package/dist/observability/reporter.d.ts +32 -0
  147. package/dist/observability/reporter.js +140 -0
  148. package/dist/observability/sinks.d.ts +36 -0
  149. package/dist/observability/sinks.js +121 -0
  150. package/dist/observability/types.d.ts +81 -0
  151. package/dist/observability/types.js +1 -0
  152. package/dist/owner/control-channel.d.ts +42 -0
  153. package/dist/owner/control-channel.js +188 -0
  154. package/dist/owner/parent-process-watch.d.ts +15 -0
  155. package/dist/owner/parent-process-watch.js +40 -0
  156. package/dist/owner/process-identity.d.ts +10 -0
  157. package/dist/owner/process-identity.js +65 -0
  158. package/dist/owner/runtime-lock.d.ts +5 -0
  159. package/dist/owner/runtime-lock.js +47 -0
  160. package/dist/perception/binding-resolution.d.ts +9 -0
  161. package/dist/perception/binding-resolution.js +14 -0
  162. package/dist/perception/contracts.d.ts +85 -0
  163. package/dist/perception/contracts.js +1 -0
  164. package/dist/perception/map-concurrent.d.ts +2 -0
  165. package/dist/perception/map-concurrent.js +12 -0
  166. package/dist/perception/perception-host.d.ts +114 -0
  167. package/dist/perception/perception-host.js +338 -0
  168. package/dist/perception/perception-worker-host.d.ts +11 -0
  169. package/dist/perception/perception-worker-host.js +44 -0
  170. package/dist/perception/perception-worker.d.ts +21 -0
  171. package/dist/perception/perception-worker.js +77 -0
  172. package/dist/perception/strategy-names.d.ts +7 -0
  173. package/dist/perception/strategy-names.js +22 -0
  174. package/dist/sdk/perception.d.ts +5 -0
  175. package/dist/sdk/perception.js +6 -0
  176. package/dist/sdk/strategy.d.ts +6 -0
  177. package/dist/sdk/strategy.js +3 -0
  178. package/dist/strategy/activation-manager.d.ts +105 -0
  179. package/dist/strategy/activation-manager.js +367 -0
  180. package/dist/strategy/behavior-decision-history.d.ts +20 -0
  181. package/dist/strategy/behavior-decision-history.js +59 -0
  182. package/dist/strategy/behavior-instance-snapshot.d.ts +31 -0
  183. package/dist/strategy/behavior-instance-snapshot.js +145 -0
  184. package/dist/strategy/contracts.d.ts +189 -0
  185. package/dist/strategy/contracts.js +1 -0
  186. package/dist/strategy/control-driver.d.ts +25 -0
  187. package/dist/strategy/control-driver.js +131 -0
  188. package/dist/strategy/in-process-runner.d.ts +25 -0
  189. package/dist/strategy/in-process-runner.js +40 -0
  190. package/dist/strategy/strategy-host.d.ts +165 -0
  191. package/dist/strategy/strategy-host.js +1456 -0
  192. package/dist/strategy/strategy-script-runner.d.ts +81 -0
  193. package/dist/strategy/strategy-script-runner.js +235 -0
  194. package/dist/strategy/strategy-worker-host.d.ts +27 -0
  195. package/dist/strategy/strategy-worker-host.js +96 -0
  196. package/dist/strategy/thread-strategy-executor.d.ts +120 -0
  197. package/dist/strategy/thread-strategy-executor.js +778 -0
  198. package/examples/grid-game.mjs +129 -0
  199. package/examples/grid-perception-worker.mjs +6 -0
  200. package/examples/grid-perception.mjs +12 -0
  201. package/examples/grid-strategy-worker.mjs +11 -0
  202. package/examples/grid-strategy.mjs +13 -0
  203. package/examples/run-grid-game.mjs +24 -0
  204. package/package.json +53 -4
@@ -0,0 +1,165 @@
1
+ import { StrategyMemoryStore } from '../memory/strategy-memory.js';
2
+ import type { RuntimeEpochCatchUp, RuntimeEpochPlugin, RuntimeEpochPluginContext, RuntimeEpochPluginInput, RuntimeEpochPluginResult } from '../framework/plugins/contracts.js';
3
+ import { BehaviorActivationManager, type BehaviorActivationSnapshot, type BehaviorActivationSource } from './activation-manager.js';
4
+ import type { StrategyControlDriver } from './control-driver.js';
5
+ import type { StrategyAdapter, PreparedStrategy, ReflexDriver, ReflexRequest, ReflexResult } from './contracts.js';
6
+ export declare const STRATEGY_LIFECYCLE_EVENT_TYPES: readonly ["behavior.started", "behavior.suspended", "behavior.restarted", "behavior.completed", "behavior.failed", "behavior.cancelled", "behavior.replaced"];
7
+ export interface StrategyFallbackBinding {
8
+ readonly behaviorId: string;
9
+ readonly input?: Readonly<Record<string, unknown>>;
10
+ }
11
+ export type StrategyFallbackBindings = Readonly<Record<string, Readonly<StrategyFallbackBinding> | undefined>>;
12
+ export interface StrategyHostOptions {
13
+ readonly id: string;
14
+ readonly stateTopic: string;
15
+ readonly actionCapability: string;
16
+ readonly adapter: StrategyAdapter;
17
+ readonly captureActions?: boolean;
18
+ readonly memory?: StrategyMemoryStore;
19
+ readonly catalog: {
20
+ has(id: string): boolean;
21
+ prepare(id: string, input: Readonly<Record<string, unknown>>): PreparedStrategy | Promise<PreparedStrategy>;
22
+ };
23
+ readonly fallbackBehaviors?: StrategyFallbackBindings;
24
+ readonly manager?: BehaviorActivationManager;
25
+ readonly driver?: StrategyControlDriver;
26
+ readonly after?: readonly string[];
27
+ readonly eventTypes?: readonly string[];
28
+ readonly timeoutMs?: number;
29
+ readonly decisionTimeoutMs?: number;
30
+ readonly catchUp?: RuntimeEpochCatchUp;
31
+ readonly diagnosticsEnabled?: boolean;
32
+ readonly now?: () => number;
33
+ readonly createActivationId?: () => string;
34
+ }
35
+ export interface StartBehaviorOptions {
36
+ readonly source: Extract<BehaviorActivationSource, 'agent' | 'user' | 'system'>;
37
+ readonly maxRuntimeMs?: number;
38
+ /** Revalidate scope/phase after asynchronous preparation, before changing control. */
39
+ readonly isCurrent?: () => boolean;
40
+ }
41
+ export interface StrategyHostStatus {
42
+ readonly running: boolean;
43
+ readonly current?: Readonly<BehaviorActivationSnapshot>;
44
+ readonly stack: ReturnType<BehaviorActivationManager['snapshot']>;
45
+ }
46
+ /**
47
+ * The sole long/short/reflex execution host. Activation policy is separate
48
+ * from module code; every layer runs the same ClawclawBehavior contract.
49
+ */
50
+ export declare class StrategyHost implements RuntimeEpochPlugin<Record<string, any>>, ReflexDriver {
51
+ private readonly options;
52
+ readonly kind: "epoch";
53
+ readonly id: string;
54
+ readonly version = "3";
55
+ readonly after: readonly string[];
56
+ readonly consumes: {
57
+ readonly events: readonly ["*"];
58
+ };
59
+ readonly produces: RuntimeEpochPlugin<Record<string, any>>['produces'];
60
+ readonly capabilities: {
61
+ uses: readonly string[];
62
+ provides?: readonly string[];
63
+ };
64
+ readonly catchUp: RuntimeEpochCatchUp;
65
+ readonly backlogPolicy: "finish_started";
66
+ get maxInFlight(): number;
67
+ readonly maxPendingEpochs = 10;
68
+ readonly timeoutMs: number;
69
+ readonly failurePolicy: "failed_completion";
70
+ private readonly catalog;
71
+ private readonly manager;
72
+ private readonly now;
73
+ private readonly createActivationId;
74
+ private readonly decisionTimeoutMs;
75
+ private readonly captureActions;
76
+ private readonly diagnosticsEnabled;
77
+ private readonly observationMemory;
78
+ private readonly adapter;
79
+ private memory;
80
+ private readonly runtimes;
81
+ private readonly inputDefaults;
82
+ private readonly delegatedShorts;
83
+ private readonly finishSummaries;
84
+ private readonly controls;
85
+ private readonly pendingLifecycleEvents;
86
+ private readonly decisionControllers;
87
+ private controlTail;
88
+ private driver?;
89
+ private scope?;
90
+ private diagnostic?;
91
+ private boundaryActive;
92
+ private stopped;
93
+ private lastCommittedEpochSeq;
94
+ private fallbackPrepared?;
95
+ private fallbackBaseInput?;
96
+ private fallbackPreparedUsed;
97
+ private fallbackBehaviors;
98
+ private fallbackConfigGeneration;
99
+ private appliedFallbackKey?;
100
+ private manualFallbackOverride;
101
+ private backendStrategyReportTarget?;
102
+ private backendStrategyReportAcknowledgedFingerprint?;
103
+ private backendStrategyReportInFlight?;
104
+ private backendStrategyReportTimer?;
105
+ private backendStrategyReportContext?;
106
+ private backendStrategyReportEligible;
107
+ private backendStrategyReportSelection;
108
+ private backendStrategyReportLifecycleGeneration;
109
+ constructor(options: StrategyHostOptions);
110
+ attachMemory(memory: StrategyMemoryStore): void;
111
+ attachDriver(driver: StrategyControlDriver): void;
112
+ start(context: RuntimeEpochPluginContext<Record<string, any>>): Promise<void>;
113
+ status(): StrategyHostStatus;
114
+ diagnosticSnapshot(): Readonly<Record<string, unknown>>;
115
+ setIdleMs(idleMs: number): Promise<void>;
116
+ configureFallbackBehaviors(bindings: StrategyFallbackBindings, currentRole?: string): Promise<void>;
117
+ bindFallback(behaviorId: string, input: Readonly<Record<string, unknown>>): Promise<void>;
118
+ clearFallback(): Promise<void>;
119
+ startLong(behaviorId: string, input: Readonly<Record<string, unknown>>, options: StartBehaviorOptions): Promise<Readonly<BehaviorActivationSnapshot>>;
120
+ startShort(behaviorId: string, input: Readonly<Record<string, unknown>>, options: StartBehaviorOptions): Promise<Readonly<BehaviorActivationSnapshot>>;
121
+ cancel(activationId: string, reason?: string): Promise<void>;
122
+ noteAgentActivity(): Promise<void>;
123
+ updateReflex(triggerId: string, patch: Readonly<Record<string, unknown>> | undefined, guard?: () => boolean): Promise<boolean>;
124
+ /** Update one execution in any layer; background watch configuration is a separate target. */
125
+ updateInput(activationId: string, patch: Readonly<Record<string, unknown>>, guard?: () => boolean): Promise<Readonly<BehaviorActivationSnapshot>>;
126
+ /** Owner-controlled match-local inputs. Explicit start/delegation input and dynamic Trigger targets take precedence. */
127
+ configureInput(behaviorId: string, input: Readonly<Record<string, unknown>>, patch: Readonly<Record<string, unknown>>, guard?: () => boolean, beforeApply?: () => void): Promise<number>;
128
+ private prepareInput;
129
+ private updateActivationInput;
130
+ private replacePreparedInputs;
131
+ requestReflex(request: Readonly<ReflexRequest>, guard?: Readonly<{
132
+ isCurrent(): boolean;
133
+ }>): Promise<ReflexResult>;
134
+ update(input: RuntimeEpochPluginInput<Record<string, any>>, context: RuntimeEpochPluginContext<Record<string, any>>): Promise<RuntimeEpochPluginResult>;
135
+ commit(input: RuntimeEpochPluginInput<Record<string, any>>, computation: Readonly<RuntimeEpochPluginResult>, context: RuntimeEpochPluginContext<Record<string, any>>): Promise<RuntimeEpochPluginResult>;
136
+ stop(reason: 'segment_ending' | 'shutdown'): Promise<void>;
137
+ private startLayer;
138
+ private commitOrdered;
139
+ private applyDecision;
140
+ private prepareDelegatedShort;
141
+ private startDelegatedShort;
142
+ private finishCurrent;
143
+ private failCurrent;
144
+ private applyTransitions;
145
+ private captureDelegationResults;
146
+ private ensureRuntime;
147
+ private syncRoleFallback;
148
+ /**
149
+ * The backend still calls this display-only field a Strategy. Report the
150
+ * current activation, including short/reflex overrides. The adapter may also
151
+ * expose an inactive selection for display without giving it control.
152
+ */
153
+ private backendStrategyDescriptor;
154
+ private refreshBackendStrategyReport;
155
+ private refreshBackendStrategyReportTarget;
156
+ private clearBackendStrategyReportTimer;
157
+ private scheduleBackendStrategyReport;
158
+ private startBackendStrategyReportAttempt;
159
+ private finishBackendStrategyReportAttempt;
160
+ private resetBackendStrategyReporting;
161
+ private output;
162
+ private withDecisionTimeout;
163
+ private interruptDecisions;
164
+ private enqueueControl;
165
+ }