@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,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'
@@ -26,11 +28,13 @@ export type ClawclawRuntimeCause =
26
28
 
27
29
  export type ClawclawGameSnapshot =
28
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;
@@ -141,8 +146,11 @@ 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,
@@ -1,63 +1 @@
1
- import type { StrategyMemory, StrategyMemoryValue } from '../../sdk/strategy-memory.js';
2
- import { validateStrategyMemoryValue } from './strategy-memory.js';
3
-
4
- export interface StrategyMemoryRequest {
5
- readonly type: 'strategy_memory';
6
- readonly requestId: string;
7
- readonly memoryRequestId: number;
8
- readonly operation: 'get' | 'set' | 'delete';
9
- readonly key: string;
10
- readonly value?: StrategyMemoryValue;
11
- }
12
- export const unavailableStrategyMemory: StrategyMemory = {
13
- get: async () => { throw Error('strategy_memory_unavailable'); },
14
- set: async () => { throw Error('strategy_memory_unavailable'); },
15
- delete: async () => { throw Error('strategy_memory_unavailable'); },
16
- };
17
-
18
- /** Replies are handled outside the computation queue, so an awaited memory call cannot deadlock it. */
19
- export class StrategyMemoryRpcClient {
20
- private sequence = 0;
21
- private pending = new Map<number, { requestId: string; resolve: (value: any) => void; reject: (error: Error) => void; timer: ReturnType<typeof setTimeout> }>();
22
- constructor(private readonly send: (value: Readonly<Record<string, unknown>>) => void) {}
23
- receive(message: any): boolean {
24
- if (message?.type !== 'strategy_memory_result') return false;
25
- const pending = this.pending.get(message.memoryRequestId);
26
- if (!pending || pending.requestId !== message.requestId) return true;
27
- this.pending.delete(message.memoryRequestId); clearTimeout(pending.timer);
28
- if (message.error) pending.reject(Error(String(message.error))); else pending.resolve(message.value);
29
- return true;
30
- }
31
- bind(requestId: string, isActive: () => boolean): StrategyMemory {
32
- const call = (operation: StrategyMemoryRequest['operation'], key: string, value?: StrategyMemoryValue): Promise<any> => {
33
- if (!isActive()) return Promise.reject(Error('strategy_memory_inactive'));
34
- if (this.pending.size >= 64) return Promise.reject(Error('strategy_memory_request_limit'));
35
- if (operation === 'set') { try { validateStrategyMemoryValue(value); } catch (error) { return Promise.reject(error); } }
36
- const memoryRequestId = ++this.sequence;
37
- return new Promise((resolve, reject) => {
38
- const timer = setTimeout(() => { this.pending.delete(memoryRequestId); reject(Error('strategy_memory_timeout')); }, 5000);
39
- timer.unref?.(); this.pending.set(memoryRequestId, {requestId, resolve, reject, timer});
40
- try { this.send({type: 'strategy_memory', requestId, memoryRequestId, operation, key, ...(operation === 'set' ? {value} : {})}); }
41
- catch (error) { this.pending.delete(memoryRequestId); clearTimeout(timer); reject(error); }
42
- });
43
- };
44
- return Object.freeze({ get: <T extends StrategyMemoryValue>(key: string) => call('get', key) as Promise<T | undefined>,
45
- set: (key: string, value: StrategyMemoryValue) => call('set', key, value), delete: (key: string) => call('delete', key) });
46
- }
47
- }
48
-
49
- /** The parent supplies an already-bound capability; messages cannot choose another resource or scope. */
50
- export async function serveStrategyMemoryRequest(message: StrategyMemoryRequest, binding: StrategyMemory | (() => StrategyMemory),
51
- send: (value: Readonly<Record<string, unknown>>) => void): Promise<void> {
52
- let value: unknown, error: string | undefined;
53
- try {
54
- const memory = typeof binding === 'function' ? binding() : binding;
55
- if (!Number.isSafeInteger(message.memoryRequestId) || typeof message.key !== 'string') throw Error('strategy_memory_request_invalid');
56
- if (message.operation === 'get') value = await memory.get(message.key);
57
- else if (message.operation === 'set') await memory.set(message.key, message.value!);
58
- else if (message.operation === 'delete') await memory.delete(message.key);
59
- else throw Error('strategy_memory_request_invalid');
60
- } catch (failure) { error = failure instanceof Error ? failure.message : 'strategy_memory_failed'; }
61
- try { send({type: 'strategy_memory_result', requestId: message.requestId, memoryRequestId: message.memoryRequestId,
62
- ...(error ? {error} : {value})}); } catch { /* the requesting Worker may have stopped */ }
63
- }
1
+ export * from '@myclaw163/game-agent-runtime/memory/strategy-memory-rpc.js';
@@ -1,77 +1 @@
1
- import type { StrategyMemory, StrategyMemoryValue } from '../../sdk/strategy-memory.js';
2
-
3
- export const STRATEGY_MEMORY_MAX_BYTES = 64 * 1024;
4
- const MAX_KEYS = 256, MAX_SCOPE_BYTES = 4 * 1024 * 1024;
5
- type Scope = Readonly<{ sessionId: string; segmentId: string }>;
6
- interface Namespace { values: Map<string, { value: StrategyMemoryValue; bytes: number }>; bytes: number }
7
- interface Segment { namespaces: Map<string, Namespace>; bytes: number }
8
- const scopeKey = (scope: Scope) => JSON.stringify([scope.sessionId, scope.segmentId]);
9
-
10
- function keySize(key: string): number {
11
- if (typeof key !== 'string' || !key || Buffer.byteLength(key) > 256) throw Error('strategy_memory_key_invalid');
12
- return Buffer.byteLength(key);
13
- }
14
- export function validateStrategyMemoryValue(value: unknown): asserts value is StrategyMemoryValue {
15
- const seen = new Set<object>();
16
- const visit = (entry: unknown, depth: number): void => {
17
- if (depth > 32) throw Error('strategy_memory_value_invalid');
18
- if (entry === null || typeof entry === 'boolean' || typeof entry === 'string') return;
19
- if (typeof entry === 'number' && Number.isFinite(entry)) return;
20
- if (!entry || typeof entry !== 'object' || seen.has(entry)) throw Error('strategy_memory_value_invalid');
21
- const prototype = Object.getPrototypeOf(entry);
22
- if (!Array.isArray(entry) && prototype !== Object.prototype && prototype !== null) throw Error('strategy_memory_value_invalid');
23
- seen.add(entry);
24
- for (const descriptor of Object.values(Object.getOwnPropertyDescriptors(entry))) {
25
- if (!('value' in descriptor)) throw Error('strategy_memory_value_invalid');
26
- // Array length is a finite number and is harmless to validate as well.
27
- visit(descriptor.value, depth + 1);
28
- }
29
- if (Object.getOwnPropertySymbols(entry).length) throw Error('strategy_memory_value_invalid');
30
- seen.delete(entry);
31
- };
32
- visit(value, 0);
33
- if (Buffer.byteLength(JSON.stringify(value)) > STRATEGY_MEMORY_MAX_BYTES) throw Error('strategy_memory_limit_exceeded');
34
- }
35
-
36
- /** One explicitly assembled Owner-local store. Never persisted or shared with another account/Owner. */
37
- export class ClawclawStrategyMemory {
38
- private readonly segments = new Map<string, Segment>();
39
- open(scope: Scope): void {
40
- const key = scopeKey(scope);
41
- if (!this.segments.has(key)) this.segments.set(key, { namespaces: new Map(), bytes: 0 });
42
- }
43
- close(scope: Scope): void {
44
- const key = scopeKey(scope), segment = this.segments.get(key);
45
- if (segment) { segment.namespaces.clear(); segment.bytes = 0; this.segments.delete(key); }
46
- }
47
- bind(scope: Scope, namespace: string, isActive: () => boolean): StrategyMemory {
48
- const key = scopeKey(scope), segment = this.segments.get(key);
49
- const check = () => {
50
- if (!segment || this.segments.get(key) !== segment || !isActive()) throw Error('strategy_memory_inactive');
51
- return segment;
52
- };
53
- return Object.freeze({
54
- get: async <T extends StrategyMemoryValue>(name: string): Promise<T | undefined> => {
55
- keySize(name); const current = check();
56
- const value = current.namespaces.get(namespace)?.values.get(name)?.value;
57
- return value === undefined ? undefined : structuredClone(value) as T;
58
- },
59
- set: async (name: string, value: StrategyMemoryValue): Promise<void> => {
60
- const keyBytes = keySize(name); const current = check(); validateStrategyMemoryValue(value);
61
- const size = keyBytes + Buffer.byteLength(JSON.stringify(value));
62
- const target = current.namespaces.get(namespace) ?? { values: new Map(), bytes: 0 };
63
- const old = target.values.get(name)?.bytes ?? 0, delta = size - old;
64
- if ((!target.values.has(name) && target.values.size >= MAX_KEYS)
65
- || target.bytes + delta > STRATEGY_MEMORY_MAX_BYTES || current.bytes + delta > MAX_SCOPE_BYTES) {
66
- throw Error('strategy_memory_limit_exceeded');
67
- }
68
- target.values.set(name, { value: structuredClone(value), bytes: size });
69
- target.bytes += delta; current.bytes += delta; current.namespaces.set(namespace, target);
70
- },
71
- delete: async (name: string): Promise<void> => {
72
- keySize(name); const current = check(), target = current.namespaces.get(namespace), entry = target?.values.get(name);
73
- if (target && entry) { target.values.delete(name); target.bytes -= entry.bytes; current.bytes -= entry.bytes; }
74
- },
75
- });
76
- }
77
- }
1
+ export { StrategyMemoryStore as ClawclawStrategyMemory, STRATEGY_MEMORY_MAX_BYTES, validateStrategyMemoryValue } from '@myclaw163/game-agent-runtime/memory/strategy-memory.js';
@@ -26,11 +26,13 @@ export const CLAWCLAW_VISUAL_EVENT_TYPES = [
26
26
  ] as const;
27
27
 
28
28
  export type ClawclawVisualEventType = typeof CLAWCLAW_VISUAL_EVENT_TYPES[number];
29
+ export type ClawclawEventDelivery = EventDeliveryClass
30
+ | Readonly<Pick<EventCatalogEntry, 'deliveryClass' | 'wakeAgent'>>;
29
31
  export type ClawclawVisualEventDelivery = EventDeliveryClass
30
- | Readonly<Partial<Record<string, EventDeliveryClass>>>;
32
+ | Readonly<Partial<Record<string, ClawclawEventDelivery>>>;
31
33
 
32
34
  export interface ClawclawEventCatalogOptions {
33
- /** Defaults to monitor_and_events so visual facts wake the default Agent surface. */
35
+ /** Defaults to visible notifications while preserving the producer's wakeAgent choice. */
34
36
  visualEventDelivery?: ClawclawVisualEventDelivery;
35
37
  /** Additional visual Event types declared by selected user perception modules. */
36
38
  visualEventTypes?: readonly string[];
@@ -241,21 +243,19 @@ export const CLAWCLAW_MONITOR_AND_EVENTS_EVENT_TYPES = new Set<string>([
241
243
  ...CLAWCLAW_LOCAL_AGENT_EVENT_TYPES,
242
244
  ]);
243
245
 
244
- /** Intentionally empty for the current ClawClaw Agent contract. */
245
- export const CLAWCLAW_EVENTS_ONLY_EVENT_TYPES = new Set<string>();
246
-
247
246
  function visualDelivery(
248
247
  config: ClawclawVisualEventDelivery | undefined,
249
248
  type: string,
250
- ): EventDeliveryClass {
251
- if (typeof config === 'string') return config;
252
- return config?.[type] ?? 'monitor_and_events';
249
+ ): Pick<EventCatalogEntry, 'deliveryClass' | 'wakeAgent'> {
250
+ const configured = typeof config === 'string' ? config : config?.[type];
251
+ return typeof configured === 'object' ? { ...configured }
252
+ : { deliveryClass: configured ?? 'monitor_and_events' };
253
253
  }
254
254
 
255
255
  function entries(options: ClawclawEventCatalogOptions = {}): EventCatalogEntry[] {
256
256
  const perceptionOutputTypes = new Set(options.perceptionEventTypes ?? []);
257
257
  const ownOutputDelivery = (type: string) => perceptionOutputTypes.has(type)
258
- ? visualDelivery(options.visualEventDelivery, type) : 'monitor_and_events' as const;
258
+ ? visualDelivery(options.visualEventDelivery, type) : { deliveryClass: 'monitor_and_events' as const };
259
259
  const visualEventTypes = [...new Set([
260
260
  ...CLAWCLAW_VISUAL_EVENT_TYPES,
261
261
  ...(options.visualEventTypes ?? []),
@@ -276,7 +276,7 @@ function entries(options: ClawclawEventCatalogOptions = {}): EventCatalogEntry[]
276
276
  ...CLAWCLAW_LOCAL_AGENT_EVENT_TYPES.map((type) => ({
277
277
  type,
278
278
  producer: 'local_synth' as const,
279
- deliveryClass: ownOutputDelivery(type),
279
+ ...ownOutputDelivery(type),
280
280
  })),
281
281
  ...CLAWCLAW_INTERNAL_BACKEND_EVENT_TYPES.map((type) => ({
282
282
  type,
@@ -291,12 +291,12 @@ function entries(options: ClawclawEventCatalogOptions = {}): EventCatalogEntry[]
291
291
  ...visualEventTypes.map((type) => ({
292
292
  type,
293
293
  producer: 'local_synth' as const,
294
- deliveryClass: visualDelivery(options.visualEventDelivery, type),
294
+ ...visualDelivery(options.visualEventDelivery, type),
295
295
  })),
296
296
  ...behaviorEventTypes.map((type) => ({
297
297
  type,
298
298
  producer: 'local_synth' as const,
299
- deliveryClass: ownOutputDelivery(type),
299
+ ...ownOutputDelivery(type),
300
300
  })),
301
301
  ];
302
302
  }
@@ -1,12 +1,6 @@
1
+ import { actionFailureDiagnosticSeverity as classify } from '@myclaw163/game-agent-runtime/framework/action-diagnostics.js';
1
2
  import type { ActionResult } from './contracts.js';
2
-
3
- export interface ActionErrorDiagnosticSummary {
4
- readonly code?: string;
5
- readonly httpStatus?: number;
6
- readonly messagePresent: boolean;
7
- readonly messageLength?: number;
8
- }
9
-
3
+ export { summarizeActionError, type ActionErrorDiagnosticSummary } from '@myclaw163/game-agent-runtime/framework/action-diagnostics.js';
10
4
  const EXPLICIT_GAMEPLAY_REJECTIONS = new Set([
11
5
  'action_failed',
12
6
  'already_spoke',
@@ -70,78 +64,4 @@ const EXPLICIT_GAMEPLAY_REJECTIONS = new Set([
70
64
  'you_are_dead',
71
65
  ]);
72
66
 
73
- const CLIENT_REJECTION_HTTP_STATUSES = new Set([400, 409, 422]);
74
-
75
- function record(value: unknown): Record<string, unknown> | null {
76
- return value && typeof value === 'object' && !Array.isArray(value)
77
- ? value as Record<string, unknown>
78
- : null;
79
- }
80
-
81
- function machineCode(value: unknown): string | undefined {
82
- if (typeof value !== 'string') return undefined;
83
- const code = value.trim();
84
- return /^[A-Za-z][A-Za-z0-9_.-]{0,119}$/.test(code) ? code : undefined;
85
- }
86
-
87
- function machineErrorCode(value: unknown): string | undefined {
88
- const exact = machineCode(value);
89
- if (exact) return exact;
90
- if (typeof value !== 'string') return undefined;
91
- return /^([A-Za-z][A-Za-z0-9_.-]{0,119})(?=\s*[:,])/.exec(value.trim())?.[1];
92
- }
93
-
94
- function httpStatus(value: unknown): number | undefined {
95
- const status = Number(value);
96
- return Number.isInteger(status) && status >= 100 && status <= 599 ? status : undefined;
97
- }
98
-
99
- /** Extract only machine-readable Action failure metadata; never copy the response body. */
100
- export function summarizeActionError(error: unknown): ActionErrorDiagnosticSummary {
101
- const root = record(error);
102
- const nested = record(root?.error);
103
- const message = error instanceof Error
104
- ? error.message
105
- : typeof root?.message === 'string'
106
- ? root.message
107
- : typeof nested?.message === 'string'
108
- ? nested.message
109
- : typeof root?.error === 'string'
110
- ? root.error
111
- : typeof error === 'string' ? error : undefined;
112
- const code = machineCode(root?.code)
113
- ?? machineCode(nested?.code)
114
- ?? machineErrorCode(root?.error);
115
- const status = httpStatus(root?.http_status) ?? httpStatus(nested?.http_status);
116
- return {
117
- ...(code ? { code } : {}),
118
- ...(status ? { httpStatus: status } : {}),
119
- messagePresent: !!message,
120
- ...(message ? { messageLength: message.length } : {}),
121
- };
122
- }
123
-
124
- function explicitGameplayRejection(summary: ActionErrorDiagnosticSummary): boolean {
125
- const code = summary.code?.toLowerCase();
126
- const statusFromCode = code && /^http_(\d{3})$/.exec(code)?.[1];
127
- const status = summary.httpStatus ?? (statusFromCode ? Number(statusFromCode) : undefined);
128
- if (status !== undefined && status >= 500) return false;
129
- if (code && EXPLICIT_GAMEPLAY_REJECTIONS.has(code)) return true;
130
- return status !== undefined && CLIENT_REJECTION_HTTP_STATUSES.has(status);
131
- }
132
-
133
- /** Unknown, transport, protocol, auth and server failures stay error-level. */
134
- export function actionFailureDiagnosticSeverity(
135
- result: Pick<ActionResult, 'source' | 'actionOutcome' | 'error'>,
136
- ): 'warn' | 'error' {
137
- const knownBoundary = (
138
- result.source === 'backend'
139
- && (result.actionOutcome === 'confirmed' || result.actionOutcome === 'not_submitted')
140
- ) || (
141
- result.source === 'local'
142
- && result.actionOutcome === 'not_submitted'
143
- );
144
- return knownBoundary && explicitGameplayRejection(summarizeActionError(result.error))
145
- ? 'warn'
146
- : 'error';
147
- }
67
+ export const actionFailureDiagnosticSeverity = (result: Pick<ActionResult, 'source' | 'actionOutcome' | 'error'>) => classify(result, EXPLICIT_GAMEPLAY_REJECTIONS);