@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,3 +1,8 @@
1
+ import { BUILTIN_PERCEPTION_NAMES } from './plugins/system-perception/system-perceptions.js';
2
+ import { BUILTIN_PERCEPTION_PREFIX } from './notification-policy.js';
3
+ import { isClawclawAgentNotification } from './notification-policy.js';
4
+ import { createClawclawProcessingCadence } from './runtime-cadence.js';
5
+ import { readRuntimeCycleIntervalMs } from '../../lib/runtime-cadence-config.js';
1
6
  import { randomUUID } from 'node:crypto';
2
7
  import { BehaviorReflexControl } from './behavior-reflex-control.js';
3
8
  import { acquireOwnerLock, type OwnerLock } from './owner-lock.js';
@@ -80,6 +85,7 @@ import {
80
85
  ClaudeChannelSocketSink,
81
86
  DesktopEventSocketSink,
82
87
  GameSyncPerceptionReportAdapter,
88
+ GameSyncRuntimeReportAdapter,
83
89
  AgentMailboxCoordinator,
84
90
  clawclawEventRequiresDetails,
85
91
  MailboxEventBatchPump,
@@ -652,6 +658,7 @@ export async function runClawclawOwner(
652
658
  const reflexControl = new BehaviorReflexControl(assembly.modules,
653
659
  assembly.behavior, behaviorCatalog, () => runtime!.publicScope());
654
660
  runtime = createClawclawRuntime(options.profile, {
661
+ processingCadence: createClawclawProcessingCadence(readRuntimeCycleIntervalMs()),
655
662
  initialSegment: runtimeStart.initialSegment,
656
663
  mode: runtimeStart.mode,
657
664
  resume: runtimeStart.resume,
@@ -729,21 +736,43 @@ export async function runClawclawOwner(
729
736
  throw new Error('The configured Runtime repository does not support durable Mailbox delivery.');
730
737
  }
731
738
  const mailboxRepository = runtime.repository;
739
+ const perceptionSourceById = new Map(perceptionSources.map(source => [source.id, source]));
732
740
  const perceptionReportAdapter = new GameSyncPerceptionReportAdapter({
733
- producerPluginId: assembly.perception.id,
734
- descriptor: (eventType) => assembly.perception.localizedModuleDescriptorForEvent(
735
- eventType,
736
- client.gameSyncLocale,
737
- ),
741
+ producerPluginIds: [assembly.perception.id, assembly.reminders.id, ...(assembly.modules ? [assembly.modules.id] : [])],
742
+ descriptor: id => {
743
+ const source = perceptionSourceById.get(id);
744
+ return source ? { ...resolveClawclawResourceMetadata({ ...source.manifest, display: source.display }, client.gameSyncLocale), perceptionId: id } : undefined;
745
+ },
738
746
  send: (reports) => client.reportGameSyncPerceptions(reports),
739
747
  diagnostic: (name, attributes) => runtime?.diagnostic(name, attributes),
740
748
  });
749
+ const runtimeReportAdapter = new GameSyncRuntimeReportAdapter({
750
+ snapshot: ready => {
751
+ const view = runtime!.readReadyView(0, 1);
752
+ if (view.epochSeq !== ready.epochSeq || view.scope.segmentId !== ready.scope.segmentId) return null;
753
+ const state = view.state.state;
754
+ const status = view.state.stateStatus;
755
+ if (!state?.game_id || status.connectionState !== 'connected' || !status.connectionId
756
+ || status.terminal || state.phase === 'game_over' || state.phase === 'settling') return null;
757
+ const locale = client.gameSyncLocale;
758
+ return { gameId: String(state.game_id), connectionId: status.connectionId, resources: {
759
+ perceivers: [...assembly.perception.localizedModuleDescriptors(locale),
760
+ ...assembly.reminders.localizedModuleDescriptors(locale),
761
+ ...(assembly.modules?.localizedModuleDescriptors(locale) ?? [])].sort((a, b) => a.id.localeCompare(b.id)),
762
+ strategies: behaviorCatalog.list().filter(entry => entry.loadable).map(entry =>
763
+ resolveClawclawResourceMetadata(behaviorSourceById.get(entry.id)!, locale)).sort((a, b) => a.id.localeCompare(b.id)),
764
+ } };
765
+ },
766
+ send: (report, gameId, connectionId) => client.reportGameSyncRuntime(report, gameId, connectionId),
767
+ diagnostic: (name, attributes) => runtime?.diagnostic(name, attributes),
768
+ });
741
769
  cclEventsMailbox = new AgentMailboxCoordinator({
742
770
  repository: mailboxRepository,
743
771
  readyView: () => runtime!.readReadyView(0, 1),
744
772
  onDelivered: (events) => perceptionReportAdapter.reportDelivered(events),
745
773
  presentEvent: ownerAgentEventPresenter('ccl_events', !!options.desktopEvents),
746
774
  compactState: compactStateForEvents,
775
+ admitEvent: isClawclawAgentNotification,
747
776
  eventFilter: clawclawEventRequiresDetails,
748
777
  delegatedMonitorConsumerId: MONITOR_MAILBOX_CONSUMER_ID,
749
778
  consumerId: CCL_EVENTS_MAILBOX_CONSUMER_ID,
@@ -755,6 +784,7 @@ export async function runClawclawOwner(
755
784
  diagnostic: (name, attributes) => runtime?.diagnostic(name, attributes),
756
785
  });
757
786
  mailboxService = new ClawclawMailboxService({
787
+ notificationOnly: true,
758
788
  repository: mailboxRepository,
759
789
  readyView: () => runtime!.readReadyView(0, 1),
760
790
  agentMailbox: cclEventsMailbox,
@@ -764,16 +794,19 @@ export async function runClawclawOwner(
764
794
  diagnostic: (name, attributes, severity) => runtime?.diagnostic(name, attributes, severity),
765
795
  });
766
796
  const mailboxDrivers: ClawclawMailboxDriver[] = [
797
+ runtimeReportAdapter,
798
+ perceptionReportAdapter,
767
799
  mailboxService,
768
800
  cclEventsMailbox,
769
801
  ];
770
802
  if (options.desktopEvents) {
771
803
  desktopMailbox = new AgentMailboxCoordinator({
804
+ admitEvent: isClawclawAgentNotification,
772
805
  repository: mailboxRepository,
773
806
  readyView: () => runtime!.readReadyView(0, 1),
774
807
  onDelivered: (events) => perceptionReportAdapter.reportDelivered(events),
775
808
  presentEvent: ownerAgentEventPresenter('desktop_ipc', true),
776
- compactState: compactStateForEvents,
809
+ compactState: () => null,
777
810
  consumerId: DESKTOP_IPC_MAILBOX_CONSUMER_ID,
778
811
  diagnostic: (name, attributes) => runtime?.diagnostic(name, attributes),
779
812
  });
@@ -816,7 +849,7 @@ export async function runClawclawOwner(
816
849
  ownerIdPrefix: 'desktop_ipc',
817
850
  }),
818
851
  renew: (deliveryToken) => desktopMailbox!.renew(deliveryToken),
819
- ack: (deliveryToken) => desktopMailbox!.ack(deliveryToken),
852
+ ack: (deliveryToken, level) => desktopMailbox!.ack(deliveryToken, level),
820
853
  release: (deliveryToken) => desktopMailbox!.release(deliveryToken),
821
854
  },
822
855
  sink: desktopSink,
@@ -828,6 +861,7 @@ export async function runClawclawOwner(
828
861
  assembly.behavior.attachDriver(createClawclawBehaviorControlDriver(runtime));
829
862
  if (channelPolicy.enabled) {
830
863
  channelAdapter = new ClaudeChannelMailboxAdapter({
864
+ notificationOnly: true,
831
865
  onDelivered: (events) => perceptionReportAdapter.reportDelivered(events),
832
866
  repository: mailboxRepository,
833
867
  readyView: () => runtime!.readReadyView(0, 1),
@@ -841,7 +875,7 @@ export async function runClawclawOwner(
841
875
  source: {
842
876
  prepare: () => channelAdapter!.prepare(),
843
877
  renew: (deliveryToken) => channelAdapter!.renew(deliveryToken),
844
- ack: (deliveryToken) => channelAdapter!.ack(deliveryToken),
878
+ ack: (deliveryToken, level) => channelAdapter!.ack(deliveryToken, level),
845
879
  release: (deliveryToken) => channelAdapter!.release(deliveryToken),
846
880
  },
847
881
  sink: channelSink,
@@ -1126,7 +1160,10 @@ export async function runClawclawOwner(
1126
1160
  return { ok: true, type: 'action', result };
1127
1161
  }
1128
1162
  if (request.type === 'perception_status') {
1129
- return { ok: true, type: request.type, status: assembly.modules?.status(request.perception) ?? [] };
1163
+ return { ok: true, type: request.type, status: [...Object.entries(BUILTIN_PERCEPTION_NAMES).map(([id, name]) => ({
1164
+ id: `${BUILTIN_PERCEPTION_PREFIX}${id}`, name, mandatory: true, configurable: false,
1165
+ outcome: runtime!.readReadyView().pluginOutcomes[`${BUILTIN_PERCEPTION_PREFIX}${id}`]?.outcome,
1166
+ })).filter(item => !request.perception || item.id === request.perception), ...(assembly.modules?.status(request.perception) ?? [])] };
1130
1167
  }
1131
1168
  if (request.type === 'perception_update') {
1132
1169
  const expected = ownerExpectedScope(request.expected_scope);
@@ -1135,6 +1172,7 @@ export async function runClawclawOwner(
1135
1172
  if (runtime!.currentSegment().kind !== 'game') return { ok: false, type: request.type, error: 'no_active_game' };
1136
1173
  if (!ownerScopeIsCurrent(runtime!,expected)) return { ok: false, type: request.type, error: 'stale_runtime_scope' };
1137
1174
  try {
1175
+ if (request.perception.startsWith(BUILTIN_PERCEPTION_PREFIX)) throw Error('builtin_perception_readonly');
1138
1176
  if (!assembly.modules) throw Error('perception_not_found');
1139
1177
  const result = assembly.modules.configure(request.perception,request.input,() => ownerScopeIsCurrent(runtime!,expected));
1140
1178
  return { ok: true, type: request.type, result };
@@ -5,32 +5,37 @@ import { normalizeBehaviorInputFields, normalizeBehaviorInput } from './behavior
5
5
  import { isClawclawFixedEventType, CLAWCLAW_GAME_STREAM_BACKEND_EVENT_TYPES,
6
6
  CLAWCLAW_BACKEND_AGENT_EVENT_TYPES, CLAWCLAW_LOCAL_AGENT_EVENT_TYPES, CLAWCLAW_VISUAL_EVENT_TYPES } from '../clawclaw-event-catalog.js';
7
7
 
8
+ export const REMOVED_PERCEPTION_INPUT_TYPES = new Set(['players_changed', 'tasks_changed', 'meeting_state', 'ability.ready',
9
+ 'ability.remaining_uses_changed', 'ability.exhausted', 'emergency_countdown_warning', 'room_ready_to_start']);
8
10
  const INPUT_TYPES = new Set<string>([...CLAWCLAW_GAME_STREAM_BACKEND_EVENT_TYPES, ...CLAWCLAW_BACKEND_AGENT_EVENT_TYPES,
9
11
  ...CLAWCLAW_LOCAL_AGENT_EVENT_TYPES.filter(type => !/^(behavior|reminder|perception)\./.test(type)),
10
12
  'tasks_changed', 'meeting_state']);
11
13
  const PERCEPTION_OWNED_TYPES = new Set<string>([...CLAWCLAW_VISUAL_EVENT_TYPES, 'reminder.task', 'reminder.speech']);
12
14
 
13
15
  const record = (value: unknown): value is Record<string, any> => !!value && typeof value === 'object' && !Array.isArray(value);
14
- export function normalizePerceptionModuleManifest(value: unknown, current = true): PerceptionModuleManifest {
16
+ export function normalizePerceptionModuleManifest(value: unknown, current = true, discoverRemovedInputs = false): PerceptionModuleManifest {
15
17
  if (!record(value) || !Number.isInteger(value.apiVersion) || current && value.apiVersion !== 3
16
18
  || Object.keys(value).some(key => !['apiVersion', 'id', 'name', 'description', 'localizations', 'consumes',
17
- 'produces', 'inputs', 'config', 'behaviors'].includes(key))
19
+ 'produces', 'inputs', 'config', 'behaviors', 'strategies'].includes(key))
18
20
  || typeof value.id !== 'string' || !/^[a-z0-9][a-z0-9._-]*$/.test(value.id)
19
21
  || typeof value.description !== 'string' || !value.description.trim()
20
22
  || value.name !== undefined && (typeof value.name !== 'string' || !value.name.trim())
21
23
  || !hasValidClawclawResourceLocalizations(value.localizations)
22
24
  || value.config !== undefined && !record(value.config)) throw new Error('perception_module_manifest_invalid');
23
25
  const consumes = value.consumes ?? [], produces = value.produces ?? [];
26
+ if (value.strategies !== undefined && value.behaviors !== undefined) throw new Error('perception_strategy_bindings_conflict');
27
+ const bindings = value.strategies ?? value.behaviors;
24
28
  if (!Array.isArray(produces) || produces.some(type => typeof type !== 'string'
25
29
  || !/^[a-z0-9][a-z0-9._-]*$/.test(type)
26
30
  || isClawclawFixedEventType(type) && !PERCEPTION_OWNED_TYPES.has(type))
27
31
  || !Array.isArray(consumes) || consumes.some(type => typeof type !== 'string' || !INPUT_TYPES.has(type)
28
32
  || /^(visual|reminder|reaction|perception|behavior|decision)\./.test(type))) throw new Error('perception_module_event_contract_invalid');
33
+ if (!discoverRemovedInputs && consumes.some(type => REMOVED_PERCEPTION_INPUT_TYPES.has(type))) throw new Error('perception_input_removed: use gameState, frame or module-local taskChanges; perceptions cannot subscribe to other perceptions');
29
34
  const inputs = value.inputs ? normalizeBehaviorInputFields(value.inputs) : undefined;
30
35
  const config = inputs ? normalizeBehaviorInput(value.config ?? {}, inputs) : structuredClone(value.config ?? {});
31
36
  return { apiVersion: value.apiVersion, id: value.id, description: value.description,
32
37
  ...(value.name === undefined ? {} : { name: value.name }),
33
38
  ...(value.localizations === undefined ? {} : { localizations: structuredClone(value.localizations) }),
34
- ...(value.behaviors === undefined ? {} : { behaviors: normalizePerceptionBehaviorBindings(value.behaviors) }),
39
+ ...(bindings === undefined ? {} : { behaviors: normalizePerceptionBehaviorBindings(bindings) }),
35
40
  consumes: [...new Set(consumes)], produces: [...new Set(produces)], ...(inputs ? { inputs } : {}), config };
36
41
  }
@@ -0,0 +1,17 @@
1
+ import type { PerceptionModuleResult } from '../../sdk/perception-plugin/module.js';
2
+ import type { ReactionActivation } from '../../sdk/perception-plugin/reaction.js';
3
+
4
+ export type NormalizedPerceptionModuleResult = Omit<PerceptionModuleResult, 'activations'> & {
5
+ readonly activations?: readonly ReactionActivation[];
6
+ };
7
+
8
+ /** Resolve public names once before the existing admission/arbitration path. */
9
+ export function normalizePerceptionStrategyNames(value: PerceptionModuleResult): NormalizedPerceptionModuleResult {
10
+ if (!value || typeof value !== 'object' || !Array.isArray(value.activations)) return value as NormalizedPerceptionModuleResult;
11
+ return { ...value, activations: value.activations.map(activation => {
12
+ if (!activation || typeof activation !== 'object' || !Object.hasOwn(activation, 'strategy')) return activation as ReactionActivation;
13
+ if (Object.hasOwn(activation, 'behavior')) throw new Error('perception_strategy_activation_conflict');
14
+ const { strategy, ...rest } = activation as Record<string, unknown>;
15
+ return { ...rest, behavior: strategy } as unknown as ReactionActivation;
16
+ }) };
17
+ }
@@ -0,0 +1,36 @@
1
+ import type { EventStoreCompatibility } from '@myclaw163/game-agent-runtime/framework/events/store-compatibility.js';
2
+ export const CLAWCLAW_STORE_COMPATIBILITY: EventStoreCompatibility = {
3
+ "legacyConsumer": "local-agent",
4
+ "monitorConsumer": "local-agent:monitor",
5
+ "detailsConsumer": "local-agent:ccl-events",
6
+ "desktopConsumer": "local-agent:desktop",
7
+ "channelConsumer": "local-agent:claude-channel",
8
+ "detailEvidence": [
9
+ "ccl_events",
10
+ "ccl_events_backlog",
11
+ "stdout_full"
12
+ ],
13
+ "desktopEvidence": [
14
+ "mailbox_full",
15
+ "desktop_ipc"
16
+ ],
17
+ "channelEvidence": [
18
+ "claude_channel"
19
+ ],
20
+ "desktopVia": "desktop_ipc",
21
+ "channelVia": "claude_channel",
22
+ "legacyDeliveryVias": [
23
+ "stdout_full",
24
+ "mailbox_full",
25
+ "desktop_ipc",
26
+ "claude_channel",
27
+ "ccl_events",
28
+ "ccl_events_backlog"
29
+ ],
30
+ "initialDeliveryVias": [
31
+ "stdout_full",
32
+ "mailbox_full",
33
+ "ccl_events",
34
+ "ccl_events_backlog"
35
+ ]
36
+ };
@@ -315,7 +315,7 @@ export class ClawclawActionPlugin implements RuntimeEpochPlugin<Record<string, a
315
315
  if (isClawclawRuntimeState(input.epoch.state)) {
316
316
  this.stage = input.epoch.state.stage;
317
317
  this.connection = input.epoch.state.connection;
318
- if (input.epoch.state.game_snapshot.status === 'fresh') {
318
+ if ((input.epoch.state.game_snapshot.status === 'fresh' || input.epoch.state.game_snapshot.status === 'cached')) {
319
319
  this.rememberTaskGameState(input.epoch.scope, input.epoch.epochSeq, input.epoch.state.game_snapshot.state);
320
320
  }
321
321
  }
@@ -355,7 +355,7 @@ export class ClawclawActionPlugin implements RuntimeEpochPlugin<Record<string, a
355
355
  const runtimeState = latest?.state;
356
356
  let game: Record<string, any> | undefined;
357
357
  if (isClawclawRuntimeState(runtimeState)) {
358
- if (runtimeState.game_snapshot.status === 'fresh') {
358
+ if ((runtimeState.game_snapshot.status === 'fresh' || runtimeState.game_snapshot.status === 'cached')) {
359
359
  game = runtimeState.game_snapshot.state;
360
360
  this.rememberTaskGameState(scope, latest!.epochSeq, game);
361
361
  } else if (runtimeState.game_snapshot.status === 'not_updated'
@@ -508,7 +508,7 @@ export class ClawclawActionPlugin implements RuntimeEpochPlugin<Record<string, a
508
508
  && state.connection === 'connected'
509
509
  && state.stage === 'game'
510
510
  && (
511
- state.game_snapshot.status !== 'fresh'
511
+ (state.game_snapshot.status !== 'fresh' && state.game_snapshot.status !== 'cached')
512
512
  || (
513
513
  state.game_snapshot.state.phase === 'wandering'
514
514
  && state.game_snapshot.state.you?.is_alive !== false
@@ -15,10 +15,8 @@ import {
15
15
  ClawclawBehaviorPlugin,
16
16
  type ClawclawRoleFallbackBehaviors,
17
17
  } from './behavior/index.js';
18
- import {
19
- CLAWCLAW_DERIVED_EVENT_PLUGIN_ID,
20
- ClawclawDerivedEventPlugin,
21
- } from './derived-event/index.js';
18
+ import { createSystemPerceptions } from './system-perception/system-perceptions.js';
19
+ import { BUILTIN_PERCEPTION_PREFIX } from '../notification-policy.js';
22
20
  import {
23
21
  CLAWCLAW_GAME_QUERY_PLUGIN_ID,
24
22
  ClawclawGameQueryPlugin,
@@ -69,6 +67,9 @@ export function assembleClawclawPlugins(
69
67
  ): ClawclawPluginAssembly {
70
68
  const plugins = [...(options.epochPlugins ?? [])];
71
69
  for (const plugin of plugins) {
70
+ if (plugin.id.startsWith(BUILTIN_PERCEPTION_PREFIX) || plugin.id === 'clawclaw.derived-event') {
71
+ throw new Error(`Builtin perceptions are mandatory and cannot be replaced: ${plugin.id}`);
72
+ }
72
73
  const failureMode = typeof plugin.failurePolicy === 'string'
73
74
  ? plugin.failurePolicy
74
75
  : plugin.failurePolicy?.mode;
@@ -87,9 +88,7 @@ export function assembleClawclawPlugins(
87
88
  ?? new ClawclawActionPlugin(client);
88
89
  if (!configuredAction) plugins.push(action);
89
90
 
90
- if (!plugins.some((plugin) => plugin.id === CLAWCLAW_DERIVED_EVENT_PLUGIN_ID)) {
91
- plugins.push(new ClawclawDerivedEventPlugin());
92
- }
91
+ plugins.push(...createSystemPerceptions(options.behaviorEventTypes));
93
92
  const configuredReminders = plugins.find(plugin => plugin.id === CLAWCLAW_REMINDER_PLUGIN_ID);
94
93
  if (configuredReminders && !(configuredReminders instanceof ClawclawReminderPlugin)) {
95
94
  throw new Error(`Runtime Plugin ${CLAWCLAW_REMINDER_PLUGIN_ID} is not a ClawclawReminderPlugin.`);
@@ -134,7 +133,7 @@ export function assembleClawclawPlugins(
134
133
  if (!configuredTrigger) plugins.push(trigger);
135
134
 
136
135
  const modules = moduleSources.length ? new ClawclawPerceptionModulePlugin({ sources: moduleSources,
137
- after: [CLAWCLAW_DERIVED_EVENT_PLUGIN_ID],
136
+ after: [],
138
137
  behaviors: () => options.behaviorCatalog?.list?.() ?? [],
139
138
  }) : undefined;
140
139
  if (modules) plugins.push(modules);
@@ -149,7 +148,6 @@ export function assembleClawclawPlugins(
149
148
  fallbackBehaviors: options.fallbackBehaviors,
150
149
  after: [
151
150
  CLAWCLAW_ACTION_PLUGIN_ID,
152
- CLAWCLAW_DERIVED_EVENT_PLUGIN_ID,
153
151
  CLAWCLAW_REMINDER_PLUGIN_ID,
154
152
  CLAWCLAW_GAME_QUERY_PLUGIN_ID,
155
153
  CLAWCLAW_PERCEPTION_PLUGIN_ID,