@myclaw163/clawclaw-cli 0.9.1 → 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 (216) 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 +27 -40
  7. package/docs/custom-modules/api-reference.md +132 -273
  8. package/docs/custom-modules/behavior.md +185 -75
  9. package/docs/custom-modules/examples/auto-escape.ts +41 -0
  10. package/docs/custom-modules/examples/go-to-point.ts +11 -11
  11. package/docs/custom-modules/examples/nearby-reflex.ts +22 -0
  12. package/docs/custom-modules/examples/task-reminder.ts +4 -5
  13. package/docs/custom-modules/perception.md +46 -806
  14. package/docs/custom-modules/skill.md +1 -1
  15. package/docs/desktop-event-push.md +3 -3
  16. package/docs/runtime/README.md +18 -19
  17. package/docs/runtime/agent-notifications.md +31 -12
  18. package/docs/runtime/behavior-runtime.md +54 -48
  19. package/docs/runtime/components-and-boundaries.md +87 -137
  20. package/docs/runtime/events-and-state.md +52 -17
  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 +12 -9
  26. package/docs/user-guide/api-reference.md +132 -180
  27. package/docs/user-guide/behavior.md +175 -65
  28. package/docs/user-guide/installation.md +7 -7
  29. package/docs/user-guide/perception.md +46 -789
  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 +9 -14
  34. package/scripts/install-local-runtime.mjs +35 -0
  35. package/scripts/qa-install.mjs +105 -0
  36. package/skills/clawclaw/SKILL.md +50 -48
  37. package/skills/clawclaw/references/BEHAVIORS.md +45 -65
  38. package/skills/clawclaw/references/CHANNELS.md +2 -2
  39. package/skills/clawclaw/references/COMMANDS.md +65 -87
  40. package/skills/clawclaw/references/CUSTOM-BEHAVIOR-DEVELOPMENT.md +185 -75
  41. package/skills/clawclaw/references/CUSTOM-MODULE-API.md +145 -198
  42. package/skills/clawclaw/references/CUSTOM-MODULES.md +28 -29
  43. package/skills/clawclaw/references/CUSTOM-PERCEPTION-DEVELOPMENT.md +46 -811
  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 +49 -104
  51. package/src/commands/capability.ts +3 -3
  52. package/src/commands/load.ts +18 -25
  53. package/src/commands/module-runtime-control.ts +113 -0
  54. package/src/commands/perception.ts +23 -4
  55. package/src/commands/strategy.ts +2 -0
  56. package/src/commands/trigger.ts +1 -1
  57. package/src/lib/capability-load-diagnostics.ts +3 -3
  58. package/src/lib/perception-config.ts +18 -6
  59. package/src/lib/runtime-cadence-config.ts +16 -0
  60. package/src/lib/workspace-runtime-lock.ts +3 -46
  61. package/src/pipeline/canonical-event-presentation.ts +23 -124
  62. package/src/pipeline/event-format.ts +12 -21
  63. package/src/pipeline/event-hints.ts +6 -6
  64. package/src/pipeline/game-sync-event-normalization.ts +57 -63
  65. package/src/runtime/clawclaw/behavior-decision.ts +7 -3
  66. package/src/runtime/clawclaw/behavior-input.ts +8 -4
  67. package/src/runtime/clawclaw/behavior-observation-memory.ts +3 -2
  68. package/src/runtime/clawclaw/behavior-read-api.ts +4 -0
  69. package/src/runtime/clawclaw/behavior-reflex-control.ts +74 -0
  70. package/src/runtime/clawclaw/notification-policy.ts +42 -0
  71. package/src/runtime/clawclaw/notification-turn.ts +19 -0
  72. package/src/runtime/clawclaw/observation-frame-projector.ts +3 -3
  73. package/src/runtime/clawclaw/owner.ts +67 -8
  74. package/src/runtime/clawclaw/perception-module-manifest.ts +22 -8
  75. package/src/runtime/clawclaw/perception-strategy-names.ts +17 -0
  76. package/src/runtime/clawclaw/persistence-compatibility.ts +36 -0
  77. package/src/runtime/clawclaw/plugins/action/action-plugin.ts +3 -3
  78. package/src/runtime/clawclaw/plugins/assembly.ts +29 -41
  79. package/src/runtime/clawclaw/plugins/behavior/activation-manager.ts +1 -482
  80. package/src/runtime/clawclaw/plugins/behavior/behavior-analysis-thread-host.ts +17 -186
  81. package/src/runtime/clawclaw/plugins/behavior/behavior-catalog.ts +2 -0
  82. package/src/runtime/clawclaw/plugins/behavior/behavior-instance-snapshot.ts +1 -123
  83. package/src/runtime/clawclaw/plugins/behavior/behavior-normalization.ts +3 -0
  84. package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.ts +126 -1707
  85. package/src/runtime/clawclaw/plugins/behavior/behavior-runner.ts +13 -271
  86. package/src/runtime/clawclaw/plugins/behavior/behavior-source.ts +2 -2
  87. package/src/runtime/clawclaw/plugins/behavior/behavior-worker-bridge.ts +8 -0
  88. package/src/runtime/clawclaw/plugins/behavior/control-driver.ts +3 -180
  89. package/src/runtime/clawclaw/plugins/behavior/thread-behavior-executor.ts +13 -960
  90. package/src/runtime/clawclaw/plugins/derived-event/derived-event-plugin.ts +9 -107
  91. package/src/runtime/clawclaw/plugins/derived-event/derived-event-rules.ts +5 -4
  92. package/src/runtime/clawclaw/plugins/derived-event/reminder-plugin.ts +27 -17
  93. package/src/runtime/clawclaw/plugins/derived-event/reminder-runner.ts +1 -0
  94. package/src/runtime/clawclaw/plugins/derived-event/state-change-rules.ts +84 -0
  95. package/src/runtime/clawclaw/plugins/derived-event/task-change-tracker.ts +1 -0
  96. package/src/runtime/clawclaw/plugins/game-query/game-query-plugin.ts +4 -4
  97. package/src/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-adapter.ts +9 -97
  98. package/src/runtime/clawclaw/plugins/mailbox/adapters/claude-channel-socket.ts +8 -343
  99. package/src/runtime/clawclaw/plugins/mailbox/agent-mailbox-coordinator.ts +60 -572
  100. package/src/runtime/clawclaw/plugins/mailbox/desktop-event-socket.ts +6 -434
  101. package/src/runtime/clawclaw/plugins/mailbox/mailbox-event-batch-delivery.ts +1 -266
  102. package/src/runtime/clawclaw/plugins/mailbox/mailbox-plugin.ts +6 -161
  103. package/src/runtime/clawclaw/plugins/mailbox/mailbox-presentation.ts +4 -23
  104. package/src/runtime/clawclaw/plugins/mailbox/mailbox-service.ts +49 -752
  105. package/src/runtime/clawclaw/plugins/perception/map-concurrent.ts +1 -0
  106. package/src/runtime/clawclaw/plugins/perception/notification-content.ts +60 -0
  107. package/src/runtime/clawclaw/plugins/perception/perception-module-plugin.ts +136 -0
  108. package/src/runtime/clawclaw/plugins/perception/perception-module-runner.ts +13 -0
  109. package/src/runtime/clawclaw/plugins/perception/perception-module-worker.ts +13 -24
  110. package/src/runtime/clawclaw/plugins/perception/perception-plugin.ts +19 -8
  111. package/src/runtime/clawclaw/plugins/perception/perception-source.ts +23 -15
  112. package/src/runtime/clawclaw/plugins/perception/task-baseline.ts +29 -0
  113. package/src/runtime/clawclaw/plugins/source/source-plugin.ts +8 -103
  114. package/src/runtime/clawclaw/plugins/system-perception/rule-runner.ts +107 -0
  115. package/src/runtime/clawclaw/plugins/system-perception/system-perceptions.ts +107 -0
  116. package/src/runtime/clawclaw/plugins/trigger/contracts.ts +3 -1
  117. package/src/runtime/clawclaw/plugins/trigger/trigger-module-loader.ts +5 -2
  118. package/src/runtime/clawclaw/plugins/trigger/trigger-plugin.ts +69 -13
  119. package/src/runtime/clawclaw/plugins/trigger/trigger-thread-pool.ts +13 -1
  120. package/src/runtime/clawclaw/plugins/trigger/trigger-thread-worker.ts +4 -0
  121. package/src/runtime/clawclaw/reaction-behavior-resolution.ts +1 -23
  122. package/src/runtime/clawclaw/reaction-manifest.ts +18 -12
  123. package/src/runtime/clawclaw/reminder-manifest.ts +5 -2
  124. package/src/runtime/clawclaw/runtime-cadence.ts +24 -0
  125. package/src/runtime/clawclaw/runtime-state.ts +12 -1
  126. package/src/runtime/clawclaw/runtime.ts +11 -3
  127. package/src/runtime/clawclaw/strategy-memory-rpc.ts +1 -0
  128. package/src/runtime/clawclaw/strategy-memory.ts +1 -0
  129. package/src/runtime/clawclaw-event-catalog.ts +17 -17
  130. package/src/runtime/framework/action-diagnostics.ts +3 -83
  131. package/src/runtime/framework/capability-registry.ts +2 -395
  132. package/src/runtime/framework/contracts.ts +2 -144
  133. package/src/runtime/framework/control/control-scheduler.ts +2 -1268
  134. package/src/runtime/framework/control/domain-set.ts +2 -81
  135. package/src/runtime/framework/control/index.ts +1 -3
  136. package/src/runtime/framework/control/types.ts +2 -191
  137. package/src/runtime/framework/control-coordinator.ts +2 -11
  138. package/src/runtime/framework/events/event-catalog.ts +2 -74
  139. package/src/runtime/framework/events/event-delivery-service.ts +2 -200
  140. package/src/runtime/framework/events/event-ingress.ts +2 -99
  141. package/src/runtime/framework/events/event-repository.ts +2 -82
  142. package/src/runtime/framework/events/index.ts +2 -7
  143. package/src/runtime/framework/events/memory-event-repository.ts +2 -1100
  144. package/src/runtime/framework/events/runtime-resume.ts +2 -20
  145. package/src/runtime/framework/events/sqlite-event-repository.ts +5 -2280
  146. package/src/runtime/framework/events/test-helpers.ts +1 -1
  147. package/src/runtime/framework/events/types.ts +2 -312
  148. package/src/runtime/framework/index.ts +3 -7
  149. package/src/runtime/framework/load-node-sqlite.ts +2 -17
  150. package/src/runtime/framework/mailbox/coalescer.ts +2 -83
  151. package/src/runtime/framework/mailbox/host-notification-sink.ts +2 -44
  152. package/src/runtime/framework/mailbox/identity.ts +2 -38
  153. package/src/runtime/framework/mailbox/index.ts +1 -7
  154. package/src/runtime/framework/mailbox/mailbox-dispatcher.ts +2 -282
  155. package/src/runtime/framework/mailbox/mailbox-repository.ts +2 -44
  156. package/src/runtime/framework/mailbox/notification-projector.ts +2 -65
  157. package/src/runtime/framework/mailbox/types.ts +2 -145
  158. package/src/runtime/framework/modules/runtime-module-loader-hooks.mjs +2 -154
  159. package/src/runtime/framework/modules/runtime-module-loader.ts +7 -51
  160. package/src/runtime/framework/modules/runtime-module-output.ts +2 -24
  161. package/src/runtime/framework/modules/runtime-module-worker-bootstrap.mjs +3 -23
  162. package/src/runtime/framework/participation-manager.ts +2 -253
  163. package/src/runtime/framework/persistence/async-sqlite-persistence-worker.ts +2 -77
  164. package/src/runtime/framework/persistence/memory-first-persistence.ts +4 -489
  165. package/src/runtime/framework/plugins/contracts.ts +2 -388
  166. package/src/runtime/framework/plugins/index.ts +1 -4
  167. package/src/runtime/framework/plugins/runtime-event-identity.ts +2 -17
  168. package/src/runtime/framework/plugins/runtime-input-journal.ts +2 -866
  169. package/src/runtime/framework/plugins/runtime-plugin-scheduler.ts +2 -2060
  170. package/src/runtime/framework/runtime.ts +5 -1843
  171. package/src/runtime/framework/serial-task-queue.ts +2 -14
  172. package/src/runtime/framework/state/contracts.ts +2 -49
  173. package/src/runtime/framework/state/current-state-store.ts +2 -184
  174. package/src/runtime/framework/state/durable-agent-state-snapshot.ts +2 -209
  175. package/src/runtime/framework/state/freshness.ts +2 -72
  176. package/src/runtime/framework/state/history/contracts.ts +2 -158
  177. package/src/runtime/framework/state/history/history-writer.ts +2 -194
  178. package/src/runtime/framework/state/history/memory-state-history-repository.ts +2 -230
  179. package/src/runtime/framework/state/history/sqlite-state-history-repository.ts +2 -648
  180. package/src/runtime/framework/state/history/trajectory-projector.ts +2 -209
  181. package/src/runtime/framework/state/index.ts +1 -13
  182. package/src/runtime/framework/state/state-ingress.ts +2 -95
  183. package/src/runtime/framework/state/state-provider.ts +2 -62
  184. package/src/runtime/framework/state/types.ts +2 -155
  185. package/src/runtime/host-monitor-rate-gate.ts +1 -123
  186. package/src/runtime/mailbox-host-relay.ts +1 -326
  187. package/src/runtime/observability/detail-capture.ts +4 -108
  188. package/src/runtime/observability/process-timing.ts +2 -59
  189. package/src/runtime/observability/recorder.ts +2 -238
  190. package/src/runtime/observability/redaction.ts +2 -181
  191. package/src/runtime/observability/reporter.ts +2 -154
  192. package/src/runtime/observability/sinks.ts +2 -135
  193. package/src/runtime/observability/types.ts +2 -92
  194. package/src/runtime/owner-control.ts +45 -315
  195. package/src/runtime/parent-process-watch.ts +1 -51
  196. package/src/runtime/process-identity.ts +1 -72
  197. package/src/sdk/behavior-plugin/index.ts +13 -4
  198. package/src/sdk/index.ts +44 -3
  199. package/src/sdk/module-input/index.ts +5 -0
  200. package/src/sdk/perception-plugin/index.ts +9 -5
  201. package/src/sdk/perception-plugin/module.ts +25 -6
  202. package/src/sdk/perception-plugin/reaction.ts +1 -1
  203. package/src/sdk/perception-plugin/reminder-rules.ts +8 -42
  204. package/src/sdk/perception-plugin/reminder.ts +2 -1
  205. package/src/{runtime/clawclaw/plugins/source → sdk/perception-plugin}/task-change-tracker.ts +1 -2
  206. package/src/sdk/strategy-memory.ts +1 -0
  207. package/src/sdk/strategy-plugin/index.ts +36 -0
  208. package/src/sdk/trigger-plugin/index.ts +4 -3
  209. package/docs/custom-modules/examples/nearby-escape.ts +0 -56
  210. package/docs/custom-modules/examples/nearby-notice.ts +0 -36
  211. package/docs/custom-modules/trigger.md +0 -295
  212. package/src/runtime/clawclaw/behavior-activation-capability.ts +0 -21
  213. package/src/runtime/clawclaw/plugins/perception/reaction-plugin.ts +0 -233
  214. package/src/runtime/clawclaw/plugins/perception/reaction-runner.ts +0 -49
  215. package/src/runtime/clawclaw/plugins/perception/reaction-worker.ts +0 -26
  216. /package/src/runtime/clawclaw/plugins/{source → derived-event}/player-change-tracker.ts +0 -0
@@ -1,3 +1,4 @@
1
+ import { isNotificationTurn } from '../../notification-turn.js';
1
2
  import type {
2
3
  ClawclawTrigger,
3
4
  TriggerInput,
@@ -36,6 +37,7 @@ import { TriggerModuleLoader } from './trigger-module-loader.js';
36
37
  import type { ResolvedClawclawTriggerSource } from './trigger-source.js';
37
38
  import { assertRuntimeModuleOutputSize } from '../../../framework/modules/runtime-module-output.js';
38
39
  import { TriggerThreadPool } from './trigger-thread-pool.js';
40
+ import { ClawclawStrategyMemory } from '../../strategy-memory.js';
39
41
 
40
42
  const TRIGGER_COMPUTATION_SCHEMA = 1;
41
43
  const TRIGGER_CHECKPOINT_SCHEMA = 1;
@@ -44,6 +46,7 @@ export const DEFAULT_TRIGGER_PLUGIN_TIMEOUT_MS = 2_000;
44
46
  interface EffectiveTriggerConfig {
45
47
  readonly source: ResolvedClawclawTriggerSource;
46
48
  readonly enabled: boolean;
49
+ readonly scope?: Readonly<{ sessionId: string; segmentId: string }>;
47
50
  readonly input: Readonly<Record<string, unknown>>;
48
51
  readonly behavior: string;
49
52
  readonly behaviorInput: Readonly<Record<string, unknown>>;
@@ -78,6 +81,7 @@ interface TriggerCheckpoint {
78
81
  }
79
82
 
80
83
  export interface ClawclawTriggerPluginOptions {
84
+ readonly memory?: ClawclawStrategyMemory;
81
85
  readonly after?: readonly string[];
82
86
  readonly triggers?: readonly ClawclawTriggerRegistration[];
83
87
  readonly loader?: TriggerModuleLoader;
@@ -123,7 +127,7 @@ function normalizeRegistration(value: ClawclawTriggerRegistration): EffectiveTri
123
127
  const { source } = value;
124
128
  const manifest = source.manifest;
125
129
  if (!source || source.id !== manifest.id) throw new Error('trigger_source_identity_invalid');
126
- const input = normalizeBehaviorInput(value.input ?? {}, manifest.inputs);
130
+ const input = value.enabled ? normalizeBehaviorInput(value.input ?? {}, manifest.inputs) : Object.freeze(structuredClone(value.input ?? {}));
127
131
  const behavior = value.behavior ?? manifest.defaultBehavior;
128
132
  const behaviorInput = {
129
133
  ...structuredClone(manifest.defaultBehaviorInput),
@@ -149,6 +153,7 @@ function normalizeRegistration(value: ClawclawTriggerRegistration): EffectiveTri
149
153
  return Object.freeze({
150
154
  source,
151
155
  enabled: value.enabled,
156
+ scope: value.scope,
152
157
  input,
153
158
  behavior,
154
159
  behaviorInput: Object.freeze(behaviorInput),
@@ -201,6 +206,7 @@ function triggerInputFor(
201
206
  : semanticInput.events.filter((event) => consumes.has(event.type));
202
207
  return Object.freeze({
203
208
  frame,
209
+ ...(semanticInput.cycle ? { cycle: semanticInput.cycle } : {}),
204
210
  events: Object.freeze(events),
205
211
  input: config.input,
206
212
  });
@@ -214,7 +220,8 @@ function behaviorInputForTrigger(
214
220
  return Object.freeze({
215
221
  epochId: semanticInput.epochId,
216
222
  scope: semanticInput.scope,
217
- nowMs: frame.timeMs,
223
+ nowMs: semanticInput.nowMs,
224
+ ...(semanticInput.cycle ? { cycle: semanticInput.cycle } : {}),
218
225
  gameState: frame.gameState,
219
226
  events: triggerInput.events,
220
227
  input: triggerInput.input,
@@ -255,6 +262,7 @@ export class ClawclawTriggerPlugin implements RuntimeEpochPlugin<Record<string,
255
262
  private readonly loadFailures = new Set<string>();
256
263
  private readonly states = new Map<string, TriggerRuntimeState>();
257
264
  private readonly observationMemory = new ClawclawBehaviorObservationMemory();
265
+ private memory: ClawclawStrategyMemory;
258
266
  private readonly projector = new ObservationFrameProjector();
259
267
  private readonly threaded: boolean;
260
268
  private readonly diagnosticsEnabled: boolean;
@@ -264,6 +272,11 @@ export class ClawclawTriggerPlugin implements RuntimeEpochPlugin<Record<string,
264
272
  private pendingThreadResetReason?: TriggerResetReason;
265
273
  private driver?: BehaviorReflexActivationDriver;
266
274
  private configGeneration = 1;
275
+ private currentScope?: Readonly<{ sessionId: string; segmentId: string }>;
276
+ private isEnabled(config: EffectiveTriggerConfig): boolean {
277
+ return config.enabled && (!config.scope || config.scope.sessionId === this.currentScope?.sessionId
278
+ && config.scope.segmentId === this.currentScope?.segmentId);
279
+ }
267
280
  private started = false;
268
281
  private lastFrameSeq = 0;
269
282
  private lastVisualTick: number | null = null;
@@ -271,6 +284,7 @@ export class ClawclawTriggerPlugin implements RuntimeEpochPlugin<Record<string,
271
284
  private lifecyclePhase: string | null = null;
272
285
 
273
286
  constructor(options: ClawclawTriggerPluginOptions = {}) {
287
+ this.memory = options.memory ?? new ClawclawStrategyMemory();
274
288
  this.after = [...(options.after ?? [])];
275
289
  this.registrations = normalizeRegistrations(options.triggers ?? []);
276
290
  this.loader = options.loader ?? new TriggerModuleLoader();
@@ -279,6 +293,11 @@ export class ClawclawTriggerPlugin implements RuntimeEpochPlugin<Record<string,
279
293
  this.diagnosticsEnabled = options.diagnosticsEnabled === true;
280
294
  }
281
295
 
296
+ attachMemory(memory: ClawclawStrategyMemory): void {
297
+ if (this.started) throw Error('strategy_memory_already_started');
298
+ this.memory = memory;
299
+ }
300
+
282
301
  attachDriver(driver: BehaviorReflexActivationDriver): void {
283
302
  if (this.driver && this.driver !== driver) throw new Error('trigger_activation_driver_already_attached');
284
303
  this.driver = driver;
@@ -287,11 +306,17 @@ export class ClawclawTriggerPlugin implements RuntimeEpochPlugin<Record<string,
287
306
  /** Atomically replace effective config; newly enabled modules import on the next ordered boundary. */
288
307
  configure(triggers: readonly ClawclawTriggerRegistration[]): void {
289
308
  const next = normalizeRegistrations(triggers);
309
+ for (const [id, config] of next) {
310
+ if (config.enabled && !this.registrations.get(id)?.enabled) {
311
+ const state = this.states.get(id);
312
+ if (state) state.armed = true;
313
+ }
314
+ }
290
315
  this.configGeneration += 1;
291
316
  this.registrations = next;
292
317
  this.slots.clear();
293
318
  this.loadFailures.clear();
294
- this.states.clear();
319
+ for (const id of this.states.keys()) if (!next.has(id)) this.states.delete(id);
295
320
  this.observationMemory.clear();
296
321
  this.clearFrameBoundary();
297
322
  void this.threadPool?.stop();
@@ -305,6 +330,8 @@ export class ClawclawTriggerPlugin implements RuntimeEpochPlugin<Record<string,
305
330
  descriptors(): readonly Readonly<{
306
331
  id: string;
307
332
  enabled: boolean;
333
+ armed: boolean;
334
+ cooldownRemainingMs: number;
308
335
  behavior: string;
309
336
  reflexPriority: number;
310
337
  cooldownMs: number;
@@ -313,7 +340,9 @@ export class ClawclawTriggerPlugin implements RuntimeEpochPlugin<Record<string,
313
340
  }>[] {
314
341
  return [...this.registrations.values()].map((entry) => Object.freeze({
315
342
  id: entry.source.id,
316
- enabled: entry.enabled,
343
+ enabled: this.isEnabled(entry),
344
+ armed: this.states.get(entry.source.id)?.armed ?? true,
345
+ cooldownRemainingMs: Math.max(0, entry.cooldownMs - (Date.now() - (this.states.get(entry.source.id)?.lastAcceptedAtMs ?? 0))),
317
346
  behavior: entry.behavior,
318
347
  reflexPriority: entry.reflexPriority,
319
348
  cooldownMs: entry.cooldownMs,
@@ -327,7 +356,7 @@ export class ClawclawTriggerPlugin implements RuntimeEpochPlugin<Record<string,
327
356
  return Object.freeze({
328
357
  threaded: this.threaded,
329
358
  configured_trigger_count: this.registrations.size,
330
- enabled_trigger_count: [...this.registrations.values()].filter(({ enabled }) => enabled).length,
359
+ enabled_trigger_count: [...this.registrations.values()].filter(config => this.isEnabled(config)).length,
331
360
  active_trigger_count: this.threaded ? pool?.workerCount ?? 0 : this.slots.size,
332
361
  thread_pool_failed: this.threadPoolFailed,
333
362
  worker_pool: pool
@@ -346,6 +375,8 @@ export class ClawclawTriggerPlugin implements RuntimeEpochPlugin<Record<string,
346
375
 
347
376
  async start(context: RuntimeEpochPluginContext<Record<string, any>>): Promise<void> {
348
377
  this.started = true;
378
+ this.memory.open(context.scope);
379
+ this.currentScope = context.scope;
349
380
  if (this.threaded) await this.ensureThreadPool(context);
350
381
  else await this.ensureModules(context);
351
382
  }
@@ -373,6 +404,16 @@ export class ClawclawTriggerPlugin implements RuntimeEpochPlugin<Record<string,
373
404
  input: RuntimeEpochPluginInput<Record<string, any>>,
374
405
  context: RuntimeEpochPluginContext<Record<string, any>>,
375
406
  ): Promise<RuntimeEpochPluginResult> {
407
+ if (isNotificationTurn(input.epoch.state)) return { outcome: 'noop', reason: 'notification_only' };
408
+ this.currentScope = input.epoch.scope;
409
+ // Keep the live configure/enable entry point, but do no observation or Worker work while empty.
410
+ if (![...this.registrations.values()].some(config => this.isEnabled(config))) {
411
+ return { outcome: 'noop', reason: 'no_enabled_triggers', proposal: {
412
+ schema: TRIGGER_COMPUTATION_SCHEMA, configGeneration: this.configGeneration,
413
+ epochId: input.epoch.epochSeq, nowMs: input.frame.observedAtMs ?? input.frame.receivedAtMs,
414
+ ...(input.pendingEvents.length ? { eventCursor: input.pendingEvents.at(-1)!.commitSeq } : {}), evaluations: [],
415
+ } satisfies TriggerComputationProposal };
416
+ }
376
417
  if (this.threaded) return this.updateThreaded(input, context);
377
418
  await this.ensureModules(context);
378
419
  const generation = this.configGeneration;
@@ -382,7 +423,7 @@ export class ClawclawTriggerPlugin implements RuntimeEpochPlugin<Record<string,
382
423
  // excluded so rule evaluation has no hidden computation-plugin dependency.
383
424
  const triggerVisibleInput = {
384
425
  ...input,
385
- pendingEvents: input.pendingEvents.filter((event) => event.producer === 'backend_push'),
426
+ pendingEvents: input.pendingEvents.filter((event) => event.producer === 'backend_push' && !event.notificationOf && event.producerPluginId === undefined),
386
427
  } satisfies RuntimeEpochPluginInput<Record<string, any>>;
387
428
  const emptyInput = createBehaviorInput(triggerVisibleInput, Object.freeze({}));
388
429
  if (
@@ -451,7 +492,7 @@ export class ClawclawTriggerPlugin implements RuntimeEpochPlugin<Record<string,
451
492
  this.lifecyclePhase = lifecycle;
452
493
 
453
494
  const observationSnapshot = this.observationMemory.capture(emptyInput);
454
- const evaluators = [...this.slots.values()].sort((left, right) => (
495
+ const evaluators = [...this.slots.values()].filter(entry => this.isEnabled(entry.config)).sort((left, right) => (
455
496
  left.config.source.id.localeCompare(right.config.source.id)
456
497
  ));
457
498
  const evaluationsPending = evaluators.map(async (evaluator): Promise<ClawclawTriggerEvaluation> => {
@@ -465,7 +506,9 @@ export class ClawclawTriggerPlugin implements RuntimeEpochPlugin<Record<string,
465
506
  try {
466
507
  const value = await evaluator.module.evaluate(
467
508
  triggerInput,
468
- createBehaviorReadApi(readInput, { isActive, observationSnapshot }),
509
+ createBehaviorReadApi(readInput, { isActive, observationSnapshot,
510
+ memory: this.memory.bind(readInput.scope, this.memoryNamespace(config.source),
511
+ () => isActive() && !context.signal.aborted && this.started) }),
469
512
  );
470
513
  if (!isActive()) return { triggerId: config.source.id, outcome: 'error' };
471
514
  const match = normalizeMatch(value);
@@ -517,7 +560,7 @@ export class ClawclawTriggerPlugin implements RuntimeEpochPlugin<Record<string,
517
560
  const eventCursor = input.pendingEvents.at(-1)?.commitSeq;
518
561
  const triggerVisibleInput = {
519
562
  ...input,
520
- pendingEvents: input.pendingEvents.filter((event) => event.producer === 'backend_push'),
563
+ pendingEvents: input.pendingEvents.filter((event) => event.producer === 'backend_push' && !event.notificationOf && event.producerPluginId === undefined),
521
564
  } satisfies RuntimeEpochPluginInput<Record<string, any>>;
522
565
  const emptyInput = createBehaviorInput(triggerVisibleInput, Object.freeze({}));
523
566
  const baseProposal = (nowMs: number, evaluations: readonly ClawclawTriggerEvaluation[]) => ({
@@ -578,7 +621,7 @@ export class ClawclawTriggerPlugin implements RuntimeEpochPlugin<Record<string,
578
621
  ? 'phase_changed'
579
622
  : previousStored && !continuousFromPrevious ? 'trajectory_gap' : undefined;
580
623
  const configs = [...this.registrations.values()]
581
- .filter(({ enabled }) => enabled)
624
+ .filter(config => this.isEnabled(config))
582
625
  .sort((left, right) => left.source.id.localeCompare(right.source.id));
583
626
  const settled = await Promise.allSettled(configs.map(async (config): Promise<ClawclawTriggerEvaluation> => {
584
627
  const triggerInput = triggerInputFor(frame, emptyInput, config);
@@ -629,6 +672,7 @@ export class ClawclawTriggerPlugin implements RuntimeEpochPlugin<Record<string,
629
672
  computation: Readonly<RuntimeEpochPluginResult>,
630
673
  context: RuntimeEpochPluginContext<Record<string, any>>,
631
674
  ): Promise<RuntimeEpochPluginResult> {
675
+ if (isNotificationTurn(input.epoch.state)) return computation;
632
676
  const computed = proposal(computation.proposal);
633
677
  if (computed.configGeneration !== this.configGeneration) {
634
678
  return {
@@ -649,7 +693,7 @@ export class ClawclawTriggerPlugin implements RuntimeEpochPlugin<Record<string,
649
693
  const candidates = computed.evaluations.flatMap((evaluation) => {
650
694
  if (evaluation.outcome !== 'match' || !evaluation.match) return [];
651
695
  const config = this.registrations.get(evaluation.triggerId);
652
- if (!config?.enabled) return [];
696
+ if (!config || !this.isEnabled(config)) return [];
653
697
  const state = this.stateFor(evaluation.triggerId);
654
698
  if (config.rearm === 'after_clear' && !state.armed) return [];
655
699
  if (
@@ -746,6 +790,8 @@ export class ClawclawTriggerPlugin implements RuntimeEpochPlugin<Record<string,
746
790
  }
747
791
 
748
792
  async stop(reason: 'segment_ending' | 'shutdown'): Promise<void> {
793
+ this.started = false;
794
+ if (this.currentScope) this.memory.close(this.currentScope);
749
795
  if (this.threaded) await this.threadPool?.stop();
750
796
  else await this.resetModules(reason, undefined);
751
797
  this.started = false;
@@ -762,6 +808,10 @@ export class ClawclawTriggerPlugin implements RuntimeEpochPlugin<Record<string,
762
808
  this.loader.stop();
763
809
  }
764
810
 
811
+ private memoryNamespace(source: ResolvedClawclawTriggerSource): string {
812
+ return `trigger:${source.id}`;
813
+ }
814
+
765
815
  private async ensureThreadPool(
766
816
  context: RuntimeEpochPluginContext<Record<string, any>>,
767
817
  ): Promise<void> {
@@ -780,11 +830,17 @@ export class ClawclawTriggerPlugin implements RuntimeEpochPlugin<Record<string,
780
830
  context: RuntimeEpochPluginContext<Record<string, any>>,
781
831
  generation: number,
782
832
  ): Promise<void> {
783
- const enabled = [...this.registrations.values()].filter(({ enabled }) => enabled);
833
+ const enabled = [...this.registrations.values()].filter(config => this.isEnabled(config));
784
834
  if (enabled.length === 0) return;
785
835
  let pool: TriggerThreadPool | undefined;
786
836
  try {
787
837
  pool = new TriggerThreadPool({
838
+ memory: (evaluation, active) => {
839
+ const source = this.registrations.get(evaluation.triggerId)?.source;
840
+ if (!source) throw Error('strategy_memory_inactive');
841
+ return this.memory.bind(evaluation.readInput.scope, this.memoryNamespace(source),
842
+ () => active() && this.started && generation === this.configGeneration);
843
+ },
788
844
  modules: enabled.map(({ source }) => this.loader.threadSpec(source)),
789
845
  loader: this.loader.threadConfig(),
790
846
  diagnosticsEnabled: this.diagnosticsEnabled,
@@ -826,7 +882,7 @@ export class ClawclawTriggerPlugin implements RuntimeEpochPlugin<Record<string,
826
882
 
827
883
  private async ensureModules(context: RuntimeEpochPluginContext<Record<string, any>>): Promise<void> {
828
884
  if (!this.started) return;
829
- const enabled = [...this.registrations.values()].filter((entry) => entry.enabled);
885
+ const enabled = [...this.registrations.values()].filter(config => this.isEnabled(config));
830
886
  await Promise.all(enabled.map(async (config) => {
831
887
  const id = config.source.id;
832
888
  if (this.slots.has(id) || this.loadFailures.has(id)) return;
@@ -10,6 +10,8 @@ import type {
10
10
  RuntimeModuleThreadLoaderConfig,
11
11
  } from '../../../framework/modules/runtime-module-loader.js';
12
12
  import type { TriggerThreadModuleSpec } from './trigger-module-loader.js';
13
+ import type { StrategyMemory } from '../../../../sdk/strategy-memory.js';
14
+ import { serveStrategyMemoryRequest, unavailableStrategyMemory, type StrategyMemoryRequest } from '../../strategy-memory-rpc.js';
13
15
 
14
16
  const WORKER_BOOTSTRAP_URL = new URL(
15
17
  '../../../framework/modules/runtime-module-worker-bootstrap.mjs',
@@ -20,6 +22,7 @@ const MAX_TRIGGER_WORKERS = 10;
20
22
  const START_TIMEOUT_MS = 20_000;
21
23
 
22
24
  export interface TriggerThreadPoolOptions {
25
+ readonly memory?: (evaluation: TriggerThreadEvaluation, isActive: () => boolean) => StrategyMemory;
23
26
  readonly modules: readonly TriggerThreadModuleSpec[];
24
27
  readonly loader: RuntimeModuleThreadLoaderConfig;
25
28
  readonly maxOldGenerationSizeMb?: number;
@@ -311,11 +314,20 @@ export class TriggerThreadPool {
311
314
  this.failLane(lane, new Error('trigger_thread_protocol_invalid'));
312
315
  return;
313
316
  }
314
- const message = value as WorkerReadyMessage | WorkerResultMessage | WorkerErrorMessage;
317
+ const message = value as WorkerReadyMessage | WorkerResultMessage | WorkerErrorMessage
318
+ | (StrategyMemoryRequest & WorkerMessageBase & { readonly heapUsedBytes?: number });
315
319
  if (message.poolId !== this.poolId || message.laneId !== lane.id) {
316
320
  this.failLane(lane, new Error('trigger_thread_protocol_identity_mismatch'));
317
321
  return;
318
322
  }
323
+ if (message.type === 'strategy_memory') {
324
+ const request = lane.current;
325
+ const isActive = () => this.state === 'running' && !!request && lane.current === request
326
+ && request.requestId === message.requestId && !request.settled && !request.signal.aborted;
327
+ void serveStrategyMemoryRequest(message, () => request && this.options.memory
328
+ ? this.options.memory(request.evaluation, isActive) : unavailableStrategyMemory, reply => lane.worker?.postMessage(reply));
329
+ return;
330
+ }
319
331
  if (typeof message.heapUsedBytes === 'number' && Number.isFinite(message.heapUsedBytes)) {
320
332
  lane.heapUsedBytes = Math.max(0, message.heapUsedBytes);
321
333
  this.peakWorkerHeapUsedBytes = Math.max(
@@ -13,6 +13,7 @@ import {
13
13
  validateClawclawTriggerModule,
14
14
  type TriggerThreadModuleSpec,
15
15
  } from './trigger-module-loader.js';
16
+ import { StrategyMemoryRpcClient } from '../../strategy-memory-rpc.js';
16
17
 
17
18
  interface TriggerThreadWorkerData {
18
19
  readonly poolId: string;
@@ -72,6 +73,7 @@ function send(value: Readonly<Record<string, unknown>>): void {
72
73
  }
73
74
 
74
75
  const classes = new Map<string, ClawclawTriggerClass>();
76
+ const memoryClient = new StrategyMemoryRpcClient(send);
75
77
  const modules = new Map<string, ClawclawTrigger>();
76
78
  const observationMemories = new Map<string, ClawclawBehaviorObservationMemory>();
77
79
  try {
@@ -114,6 +116,7 @@ async function evaluate(request: TriggerEvaluateRequest): Promise<void> {
114
116
  const value = await module.evaluate(
115
117
  deepFreeze(request.input),
116
118
  createBehaviorReadApi(deepFreeze(request.readInput), {
119
+ memory: memoryClient.bind(request.requestId, () => invocationActive),
117
120
  isActive: () => invocationActive,
118
121
  observationSnapshot,
119
122
  }),
@@ -146,6 +149,7 @@ async function evaluate(request: TriggerEvaluateRequest): Promise<void> {
146
149
 
147
150
  let operationTail = Promise.resolve();
148
151
  port.on('message', (request: TriggerEvaluateRequest) => {
152
+ if (memoryClient.receive(request)) return;
149
153
  operationTail = operationTail.then(() => evaluate(request)).catch((error) => {
150
154
  send({
151
155
  type: 'error',
@@ -1,23 +1 @@
1
- import type { ReactionBehaviorBinding } from '../../sdk/perception-plugin/reaction.js';
2
-
3
- export interface ReactionBehaviorCandidate {
4
- readonly id: string;
5
- readonly declaredId?: string;
6
- readonly resourceId?: string;
7
- readonly loadable: boolean;
8
- }
9
-
10
- /** Shared by load diagnostics and the live activation path. Never selects disabled/unloaded entries. */
11
- export function resolveReactionBehavior(binding: ReactionBehaviorBinding, candidates: readonly ReactionBehaviorCandidate[]): string | undefined {
12
- const available = candidates.filter(candidate => candidate.loadable);
13
- const compare = (a: ReactionBehaviorCandidate, b: ReactionBehaviorCandidate) =>
14
- Number(b.id === binding.name) - Number(a.id === binding.name)
15
- || a.id.localeCompare(b.id, 'en', { numeric: true }) || String(a.resourceId).localeCompare(String(b.resourceId));
16
- const preferred = binding.resourceId && available.filter(candidate => candidate.resourceId === binding.resourceId).sort(compare)[0];
17
- if (preferred) return preferred.id;
18
- // Declared source identity distinguishes real duplicate aliases from an unrelated literal escape_1.
19
- const named = available.filter(candidate => candidate.id === binding.name || candidate.declaredId === binding.name
20
- || candidate.declaredId === undefined && candidate.id.startsWith(`${binding.name}_`)
21
- && /^[1-9][0-9]*$/.test(candidate.id.slice(binding.name.length + 1))).sort(compare);
22
- return named[0]?.id;
23
- }
1
+ export * from '@myclaw163/game-agent-runtime/perception/binding-resolution.js';
@@ -24,27 +24,33 @@ export function normalizeReactionManifest(value: unknown, requireCurrentVersion
24
24
  || m.config !== undefined && !record(m.config)
25
25
  || Object.keys(m).some(key => !['apiVersion', 'kind', 'id', 'name', 'description', 'localizations',
26
26
  'consumes', 'produces', 'behaviors', 'inputs', 'config'].includes(key))) throw new Error('reaction_manifest_invalid');
27
+ const behaviors = normalizePerceptionBehaviorBindings(m.behaviors);
28
+ const inputs = m.inputs ? normalizeBehaviorInputFields(m.inputs) : undefined;
29
+ const config = inputs ? normalizeBehaviorInput(m.config ?? {}, inputs) : structuredClone(m.config ?? {});
30
+ return { apiVersion: m.apiVersion, kind: 'reaction', id: m.id, description: m.description,
31
+ ...(m.name === undefined ? {} : { name: m.name }),
32
+ ...(m.localizations === undefined ? {} : { localizations: structuredClone(m.localizations) }),
33
+ consumes: [...new Set(m.consumes)], produces: [...new Set(m.produces)], behaviors,
34
+ ...(inputs ? { inputs } : {}), config };
35
+ }
36
+
37
+ export function normalizePerceptionBehaviorBindings(value: unknown): Record<string, ReactionBehaviorBinding> {
38
+ if (value !== undefined && !record(value)) throw Error("perception_behaviors_invalid");
27
39
  const behaviors: Record<string, ReactionBehaviorBinding> = {};
28
- if (Object.keys(m.behaviors ?? {}).length > 16) throw new Error('reaction_behavior_limit');
29
- for (const [key, binding] of Object.entries(m.behaviors ?? {})) {
40
+ if (Object.keys(value ?? {}).length > 16) throw new Error('reaction_behavior_limit');
41
+ for (const [key, binding] of Object.entries(value ?? {})) {
30
42
  if (!ID.test(key) || ['__proto__', 'constructor', 'prototype'].includes(key) || !record(binding)
31
43
  || typeof binding.name !== 'string' || !OPERATION.test(binding.name)
32
44
  || binding.resourceId !== undefined && (typeof binding.resourceId !== 'string' || !binding.resourceId.trim() || binding.resourceId.length > 255)
33
- || binding.layer !== undefined && !['reflex', 'short', 'long'].includes(binding.layer)
45
+ || binding.layer !== undefined && binding.layer !== 'reflex'
34
46
  || binding.input !== undefined && !record(binding.input)
35
47
  || binding.reflexPriority !== undefined && !integer(binding.reflexPriority, -1_000_000, 1_000_000)
36
48
  || binding.cooldownMs !== undefined && !integer(binding.cooldownMs, 0, 86_400_000)
37
49
  || binding.maxRuntimeMs !== undefined && !integer(binding.maxRuntimeMs, 1, 120_000)
38
- || binding.rearm !== undefined && !['after_clear', 'after_cooldown'].includes(binding.rearm)
50
+ || binding.rearm !== undefined && !['after_clear', 'after_cooldown'].includes(String(binding.rearm))
39
51
  || Object.keys(binding).some(field => !['name', 'resourceId', 'layer', 'input', 'reflexPriority',
40
52
  'cooldownMs', 'maxRuntimeMs', 'rearm'].includes(field))) throw new Error(`reaction_behavior_invalid:${key}`);
41
- behaviors[key] = structuredClone(binding);
53
+ behaviors[key] = structuredClone(binding) as unknown as ReactionBehaviorBinding;
42
54
  }
43
- const inputs = m.inputs ? normalizeBehaviorInputFields(m.inputs) : undefined;
44
- const config = inputs ? normalizeBehaviorInput(m.config ?? {}, inputs) : structuredClone(m.config ?? {});
45
- return { apiVersion: m.apiVersion, kind: 'reaction', id: m.id, description: m.description,
46
- ...(m.name === undefined ? {} : { name: m.name }),
47
- ...(m.localizations === undefined ? {} : { localizations: structuredClone(m.localizations) }),
48
- consumes: [...new Set(m.consumes)], produces: [...new Set(m.produces)], behaviors,
49
- ...(inputs ? { inputs } : {}), config };
55
+ return behaviors;
50
56
  }
@@ -1,10 +1,11 @@
1
+ import { REMOVED_PERCEPTION_INPUT_TYPES } from './perception-module-manifest.js';
1
2
  import { REMINDER_PLUGIN_API_VERSION, type ClawclawReminderManifest } from '../../sdk/perception-plugin/reminder.js';
2
3
  import { REMINDER_FACT_TYPES_BY_TOPIC, REMINDER_TOPICS } from '../../sdk/perception-plugin/reminder-rules.js';
3
4
  import { hasValidClawclawResourceLocalizations } from '../../sdk/resource-metadata.js';
4
5
  import { normalizeBehaviorInput, normalizeBehaviorInputFields } from './behavior-input-fields.js';
5
6
 
6
7
  /** Used by both static Perception discovery and the isolated runtime loader. */
7
- export function normalizeReminderManifest(value: unknown, requireCurrentVersion = true): ClawclawReminderManifest {
8
+ export function normalizeReminderManifest(value: unknown, requireCurrentVersion = true, discoverRemovedInputs = false): ClawclawReminderManifest {
8
9
  if (!value || typeof value !== 'object' || Array.isArray(value)) throw new Error('Invalid perception reminder manifest.');
9
10
  const m = value as ClawclawReminderManifest;
10
11
  if (m.kind !== 'reminder' || !Number.isInteger(m.apiVersion)
@@ -15,10 +16,12 @@ export function normalizeReminderManifest(value: unknown, requireCurrentVersion
15
16
  || !hasValidClawclawResourceLocalizations(m.localizations)
16
17
  || !REMINDER_TOPICS.includes(m.topic)
17
18
  || !Array.isArray(m.consumes) || new Set(m.consumes).size !== m.consumes.length
18
- || m.consumes.some(type => !(REMINDER_FACT_TYPES_BY_TOPIC[m.topic] as readonly string[]).includes(type))
19
+ || m.consumes.some(type => !(REMINDER_FACT_TYPES_BY_TOPIC[m.topic] as readonly string[]).includes(type)
20
+ && !(discoverRemovedInputs && REMOVED_PERCEPTION_INPUT_TYPES.has(type)))
19
21
  || (m.config !== undefined && (!m.config || typeof m.config !== 'object' || Array.isArray(m.config)))
20
22
  || Object.keys(m).some(key => !['apiVersion', 'kind', 'id', 'name', 'description', 'localizations',
21
23
  'topic', 'consumes', 'inputs', 'config'].includes(key))) throw new Error('Invalid perception reminder manifest.');
24
+ if (!discoverRemovedInputs && m.consumes.some(type => REMOVED_PERCEPTION_INPUT_TYPES.has(type))) throw new Error('perception_input_removed: use gameState or module-local taskChanges');
22
25
  const inputs = m.inputs === undefined ? undefined : normalizeBehaviorInputFields(m.inputs);
23
26
  const config = inputs ? normalizeBehaviorInput(m.config ?? {}, inputs) : structuredClone(m.config ?? {});
24
27
  return { apiVersion: m.apiVersion, kind: 'reminder', id: m.id, description: m.description,
@@ -0,0 +1,24 @@
1
+ import type { RuntimeProcessingCadence } from '../framework/runtime.js';
2
+ import { freshClawclawGameState, isClawclawRuntimeState } from './runtime-state.js';
3
+
4
+ /** A local cycle reuses an observation; it never claims a new backend snapshot. */
5
+ export function createClawclawProcessingCadence(intervalMs: number): RuntimeProcessingCadence {
6
+ return { intervalMs,
7
+ isStateUpdate: input => isClawclawRuntimeState(input.state)
8
+ && input.state.cause !== 'agent_events_query' && input.state.cause !== 'control',
9
+ createState: ({ latestInput, latestStateFrame, cycle }) => {
10
+ const latest = latestInput.state;
11
+ if (!isClawclawRuntimeState(latest)) throw new Error('CCL processing cycles require ClawClaw Runtime State.');
12
+ const previous = latestStateFrame?.state;
13
+ const game = previous && freshClawclawGameState(previous);
14
+ const canReuse = game && latestStateFrame?.connectionId === latestInput.connectionId
15
+ && latest.stage !== 'room' && latest.stage !== 'matching';
16
+ const { control: _control, ...state } = latest;
17
+ return { ...state, cause: cycle.notificationOnly ? 'control' : 'processing_cycle',
18
+ ...(cycle.notificationOnly ? { control: { type: 'perception_notifications' } } : {}),
19
+ game_snapshot: canReuse ? { status: 'cached', state: structuredClone(game),
20
+ ...(isClawclawRuntimeState(previous) && previous.game_snapshot.status === 'fresh'
21
+ ? { origin: previous.game_snapshot.origin } : {}) } : { status: 'not_updated' },
22
+ };
23
+ } };
24
+ }
@@ -1,4 +1,5 @@
1
1
  import { projectTaskChoiceGameState } from './task-choice-projection.js';
2
+ import type { RuntimeCycleInfo } from '../framework/plugins/contracts.js';
2
3
 
3
4
  export type ClawclawRuntimeStage =
4
5
  | 'matching'
@@ -17,6 +18,7 @@ export type ClawclawRuntimeCause =
17
18
  | 'matching_poll'
18
19
  | 'room_update'
19
20
  | 'game_snapshot'
21
+ | 'processing_cycle'
20
22
  | 'backend_event'
21
23
  | 'agent_events_query'
22
24
  | 'control'
@@ -25,12 +27,14 @@ export type ClawclawRuntimeCause =
25
27
  | 'ending';
26
28
 
27
29
  export type ClawclawGameSnapshot =
28
- | { status: 'fresh'; state: Record<string, any> }
30
+ | { status: 'fresh'; state: Record<string, any>; origin?: 'snapshot' | 'update' | 'resume' }
31
+ | { status: 'cached'; state: Record<string, any>; origin?: 'snapshot' | 'update' | 'resume' }
29
32
  | { status: 'not_updated' }
30
33
  | { status: 'unavailable' };
31
34
 
32
35
  export interface ClawclawRuntimeState {
33
36
  schema: 'clawclaw.runtime-state.v1';
37
+ cycle?: Readonly<RuntimeCycleInfo>;
34
38
  /** Internal monotonic token for Action-safety transitions; not Agent State. */
35
39
  action_safety_generation?: number;
36
40
  stage: ClawclawRuntimeStage;
@@ -98,3 +102,10 @@ export function freshClawclawGameState(
98
102
  ? state.game_snapshot.state
99
103
  : null;
100
104
  }
105
+
106
+ /** Available computation input; cached observations retain their real receipt time in cycle. */
107
+ export function clawclawComputationGameState(state: Record<string, any>): Record<string, any> | null {
108
+ if (!isClawclawRuntimeState(state)) return state;
109
+ return state.game_snapshot.status === 'fresh' || state.game_snapshot.status === 'cached'
110
+ ? state.game_snapshot.state : null;
111
+ }
@@ -1,3 +1,5 @@
1
+ import { actionFailureDiagnosticSeverity } from '../framework/action-diagnostics.js';
2
+ import { clawclawNotificationFollowUp } from './notification-turn.js';
1
3
  import type { AuthProfile } from '../../lib/auth.js';
2
4
  import {
3
5
  getProfileEventLedgerPath,
@@ -25,6 +27,7 @@ import {
25
27
  CLAWCLAW_ROOM_WS_SOURCE,
26
28
  } from './plugins/source/source-transports.js';
27
29
  import { projectClawclawCurrentState } from './runtime-state.js';
30
+ import { createClawclawNotificationPolicy } from './notification-policy.js';
28
31
 
29
32
  export const CLAWCLAW_ADAPTER_ID = 'clawclaw';
30
33
  export const CLAWCLAW_GAME_LIVENESS_SILENCE_MS = 35_000;
@@ -41,6 +44,8 @@ export type ClawclawRuntimeOptions = Omit<
41
44
  | 'inputJournalPath'
42
45
  | 'historyObserverFactory'
43
46
  | 'currentStateFromRuntimeState'
47
+ | 'notificationPolicy'
48
+ | 'followUpInput'
44
49
  > & {
45
50
  /** Tests and embedded hosts may replace or disable the durable current-State cache. */
46
51
  durableStateSnapshot?: AtomicJsonAgentStateSnapshotStore<Record<string, any>> | false;
@@ -48,7 +53,7 @@ export type ClawclawRuntimeOptions = Omit<
48
53
  visualEventDelivery?: ClawclawVisualEventDelivery;
49
54
  /** Visual Event types declared by the selected perception modules. */
50
55
  visualEventTypes?: readonly string[];
51
- reactionEventTypes?: readonly string[];
56
+ perceptionEventTypes?: readonly string[];
52
57
  /** Event types declared by enabled Intent and Strategy modules at startup. */
53
58
  behaviorEventTypes?: readonly string[];
54
59
  };
@@ -97,7 +102,7 @@ export function createClawclawRuntime(
97
102
  stateFreshnessPolicyResolver: configuredResolver,
98
103
  visualEventDelivery,
99
104
  visualEventTypes,
100
- reactionEventTypes,
105
+ perceptionEventTypes,
101
106
  behaviorEventTypes,
102
107
  ...runtimeOptions
103
108
  } = options;
@@ -141,12 +146,15 @@ export function createClawclawRuntime(
141
146
 
142
147
  return new Runtime<ClawclawPosition>({
143
148
  ...runtimeOptions,
149
+ actionFailureSeverity: actionFailureDiagnosticSeverity,
144
150
  adapterId: CLAWCLAW_ADAPTER_ID,
145
151
  accountId: getRuntimeAccountId(profile),
152
+ followUpInput: clawclawNotificationFollowUp,
153
+ notificationPolicy: createClawclawNotificationPolicy(runtimeOptions.runtimeEpochPlugins ?? []),
146
154
  eventCatalog: createClawclawEventCatalog({
147
155
  visualEventDelivery,
148
156
  visualEventTypes,
149
- reactionEventTypes,
157
+ perceptionEventTypes,
150
158
  behaviorEventTypes,
151
159
  }),
152
160
  // Mailbox ACK adapters own independent durable lanes. Disabled and
@@ -0,0 +1 @@
1
+ export * from '@myclaw163/game-agent-runtime/memory/strategy-memory-rpc.js';
@@ -0,0 +1 @@
1
+ export { StrategyMemoryStore as ClawclawStrategyMemory, STRATEGY_MEMORY_MAX_BYTES, validateStrategyMemoryValue } from '@myclaw163/game-agent-runtime/memory/strategy-memory.js';