@myclaw163/clawclaw-cli 0.9.0 → 0.9.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 (86) hide show
  1. package/README.md +5 -3
  2. package/docs/custom-modules/README.md +19 -24
  3. package/docs/custom-modules/api-reference.md +85 -33
  4. package/docs/custom-modules/behavior.md +116 -22
  5. package/docs/custom-modules/examples/auto-escape.ts +41 -0
  6. package/docs/custom-modules/examples/first-sighting-v3.ts +29 -0
  7. package/docs/custom-modules/examples/nearby-reflex.ts +22 -0
  8. package/docs/custom-modules/perception.md +158 -276
  9. package/docs/custom-modules/trigger.md +5 -3
  10. package/docs/runtime/README.md +17 -8
  11. package/docs/runtime/agent-notifications.md +32 -15
  12. package/docs/runtime/behavior-runtime.md +36 -24
  13. package/docs/runtime/components-and-boundaries.md +56 -108
  14. package/docs/runtime/events-and-state.md +55 -3
  15. package/docs/runtime/owner-lifecycle-and-observability.md +5 -3
  16. package/docs/user-guide/README.md +6 -6
  17. package/docs/user-guide/api-reference.md +80 -30
  18. package/docs/user-guide/behavior.md +116 -22
  19. package/docs/user-guide/perception.md +157 -275
  20. package/package.json +1 -1
  21. package/scripts/check-skill-command-surface.mjs +2 -2
  22. package/skills/clawclaw/SKILL.md +9 -7
  23. package/skills/clawclaw/references/BEHAVIORS.md +19 -6
  24. package/skills/clawclaw/references/COMMANDS.md +19 -0
  25. package/skills/clawclaw/references/CUSTOM-BEHAVIOR-DEVELOPMENT.md +116 -22
  26. package/skills/clawclaw/references/CUSTOM-MODULE-API.md +82 -35
  27. package/skills/clawclaw/references/CUSTOM-MODULES.md +18 -23
  28. package/skills/clawclaw/references/CUSTOM-PERCEPTION-DEVELOPMENT.md +158 -276
  29. package/skills/clawclaw/references/STREAM.md +1 -1
  30. package/src/commands/behavior.ts +28 -99
  31. package/src/commands/load.ts +23 -29
  32. package/src/commands/module-runtime-control.ts +113 -0
  33. package/src/commands/perception.ts +20 -6
  34. package/src/commands/trigger.ts +1 -1
  35. package/src/lib/agent-workspace-sync.ts +2 -2
  36. package/src/runtime/clawclaw/behavior-read-api.ts +4 -0
  37. package/src/runtime/clawclaw/behavior-reflex-control.ts +74 -0
  38. package/src/runtime/clawclaw/owner.ts +51 -5
  39. package/src/runtime/clawclaw/perception-module-manifest.ts +36 -0
  40. package/src/runtime/clawclaw/plugins/assembly.ts +25 -23
  41. package/src/runtime/clawclaw/plugins/behavior/activation-manager.ts +16 -3
  42. package/src/runtime/clawclaw/plugins/behavior/behavior-analysis-thread-host.ts +4 -0
  43. package/src/runtime/clawclaw/plugins/behavior/behavior-catalog.ts +2 -0
  44. package/src/runtime/clawclaw/plugins/behavior/behavior-normalization.ts +3 -0
  45. package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.ts +129 -57
  46. package/src/runtime/clawclaw/plugins/behavior/behavior-runner.ts +7 -2
  47. package/src/runtime/clawclaw/plugins/behavior/thread-behavior-executor.ts +13 -1
  48. package/src/runtime/clawclaw/plugins/derived-event/derived-event-plugin.ts +21 -18
  49. package/src/runtime/clawclaw/plugins/derived-event/derived-event-rules.ts +3 -2
  50. package/src/runtime/clawclaw/plugins/derived-event/reminder-plugin.ts +2 -0
  51. package/src/runtime/clawclaw/plugins/derived-event/state-change-rules.ts +84 -0
  52. package/src/runtime/clawclaw/plugins/{source → derived-event}/task-change-tracker.ts +1 -1
  53. package/src/runtime/clawclaw/plugins/perception/perception-module-plugin.ts +314 -0
  54. package/src/runtime/clawclaw/plugins/perception/{reaction-runner.ts → perception-module-runner.ts} +26 -13
  55. package/src/runtime/clawclaw/plugins/perception/perception-module-worker.ts +39 -0
  56. package/src/runtime/clawclaw/plugins/perception/perception-plugin.ts +1 -1
  57. package/src/runtime/clawclaw/plugins/perception/perception-source.ts +30 -7
  58. package/src/runtime/clawclaw/plugins/source/source-plugin.ts +2 -103
  59. package/src/runtime/clawclaw/plugins/trigger/contracts.ts +3 -1
  60. package/src/runtime/clawclaw/plugins/trigger/trigger-module-loader.ts +5 -2
  61. package/src/runtime/clawclaw/plugins/trigger/trigger-plugin.ts +61 -10
  62. package/src/runtime/clawclaw/plugins/trigger/trigger-thread-pool.ts +13 -1
  63. package/src/runtime/clawclaw/plugins/trigger/trigger-thread-worker.ts +4 -0
  64. package/src/runtime/clawclaw/reaction-manifest.ts +18 -12
  65. package/src/runtime/clawclaw/runtime-state.ts +1 -1
  66. package/src/runtime/clawclaw/runtime.ts +3 -3
  67. package/src/runtime/clawclaw/strategy-memory-rpc.ts +63 -0
  68. package/src/runtime/clawclaw/strategy-memory.ts +77 -0
  69. package/src/runtime/clawclaw-event-catalog.ts +9 -6
  70. package/src/runtime/framework/plugins/contracts.ts +8 -0
  71. package/src/runtime/framework/plugins/runtime-plugin-scheduler.ts +17 -6
  72. package/src/runtime/owner-control.ts +5 -0
  73. package/src/sdk/behavior-plugin/index.ts +4 -1
  74. package/src/sdk/index.ts +5 -0
  75. package/src/sdk/perception-plugin/index.ts +29 -10
  76. package/src/sdk/perception-plugin/module.ts +55 -0
  77. package/src/sdk/perception-plugin/reaction.ts +2 -1
  78. package/src/sdk/perception-plugin/reminder.ts +1 -0
  79. package/src/sdk/strategy-memory.ts +12 -0
  80. package/src/sdk/trigger-plugin/index.ts +3 -2
  81. package/docs/custom-modules/examples/nearby-escape.ts +0 -56
  82. package/docs/custom-modules/examples/nearby-notice.ts +0 -36
  83. package/src/runtime/clawclaw/behavior-activation-capability.ts +0 -21
  84. package/src/runtime/clawclaw/plugins/perception/reaction-plugin.ts +0 -198
  85. package/src/runtime/clawclaw/plugins/perception/reaction-worker.ts +0 -26
  86. /package/src/runtime/clawclaw/plugins/{source → derived-event}/player-change-tracker.ts +0 -0
@@ -1,4 +1,5 @@
1
1
  import { randomUUID } from 'node:crypto';
2
+ import { BehaviorReflexControl } from './behavior-reflex-control.js';
2
3
  import { acquireOwnerLock, type OwnerLock } from './owner-lock.js';
3
4
  import { createStartingOwnerControl } from './starting-owner-control.js';
4
5
  export { acquireOwnerLock, type OwnerLock, type OwnerLockOperations } from './owner-lock.js';
@@ -585,7 +586,7 @@ export async function runClawclawOwner(
585
586
  agentBehaviorSources,
586
587
  disabledBehaviors,
587
588
  );
588
- const behaviorSourceById = new Map(behaviorSources.map((source) => [source.id, source]));
589
+ const behaviorSourceById = new Map(behaviorSources.map(source => [source.id,source]));
589
590
  const behaviorCatalog = new ClawclawBehaviorCatalog(behaviorSources);
590
591
  const behaviorEventTypes = [...new Set(
591
592
  behaviorCatalog.list()
@@ -600,12 +601,13 @@ export async function runClawclawOwner(
600
601
  const triggerSources = listClawclawTriggerSources(
601
602
  getUserDataAccountTriggersDir(workspaceDir, options.profile),
602
603
  );
603
- const triggers = triggerRegistrations(
604
+ const legacyTriggers = triggerRegistrations(
604
605
  triggerSources,
605
606
  gameplayConfig,
606
607
  behaviorCatalog,
607
608
  configurationWarning,
608
609
  );
610
+ const triggers = legacyTriggers;
609
611
  const disabledPerceptions = new Set(gameplayConfig.disabled_perception_modules);
610
612
  const agentPerceptionSources = agentWorkspace
611
613
  ? listAgentWorkspacePerceptionSources(workspaceDir, options.profile, agentWorkspace)
@@ -647,6 +649,8 @@ export async function runClawclawOwner(
647
649
  await client.getQueueStatus('clawclaw'),
648
650
  options.intent,
649
651
  );
652
+ const reflexControl = new BehaviorReflexControl(assembly.modules,
653
+ assembly.behavior, behaviorCatalog, () => runtime!.publicScope());
650
654
  runtime = createClawclawRuntime(options.profile, {
651
655
  initialSegment: runtimeStart.initialSegment,
652
656
  mode: runtimeStart.mode,
@@ -657,7 +661,7 @@ export async function runClawclawOwner(
657
661
  visualEventDelivery: perceptionConfig.events.delivery,
658
662
  visualEventTypes: assembly.perception.produces.events,
659
663
  behaviorEventTypes: assembly.behavior.produces?.events ?? [],
660
- reactionEventTypes: assembly.reactions?.produces.events,
664
+ perceptionEventTypes: assembly.modules?.produces.events,
661
665
  });
662
666
  if (fullDiagnosticsEnabled) {
663
667
  processTimingSampler = new RuntimeProcessTimingSampler();
@@ -787,7 +791,7 @@ export async function runClawclawOwner(
787
791
  })(),
788
792
  perceptions: [...assembly.perception.localizedModuleDescriptors(DESKTOP_RESOURCE_LOCALE),
789
793
  ...assembly.reminders.localizedModuleDescriptors(DESKTOP_RESOURCE_LOCALE),
790
- ...(assembly.reactions?.localizedModuleDescriptors(DESKTOP_RESOURCE_LOCALE) ?? [])],
794
+ ...(assembly.modules?.localizedModuleDescriptors(DESKTOP_RESOURCE_LOCALE) ?? [])],
791
795
  }),
792
796
  eventDescriptors: () => assembly.perception
793
797
  .localizedEventDescriptors(DESKTOP_RESOURCE_LOCALE)
@@ -1121,6 +1125,48 @@ export async function runClawclawOwner(
1121
1125
  );
1122
1126
  return { ok: true, type: 'action', result };
1123
1127
  }
1128
+ if (request.type === 'perception_status') {
1129
+ return { ok: true, type: request.type, status: assembly.modules?.status(request.perception) ?? [] };
1130
+ }
1131
+ if (request.type === 'perception_update') {
1132
+ const expected = ownerExpectedScope(request.expected_scope);
1133
+ if (!expected || !request.input || typeof request.input !== 'object' || Array.isArray(request.input)
1134
+ || typeof request.perception !== 'string') return { ok: false, type: request.type, error: 'invalid_perception_control_request' };
1135
+ if (runtime!.currentSegment().kind !== 'game') return { ok: false, type: request.type, error: 'no_active_game' };
1136
+ if (!ownerScopeIsCurrent(runtime!,expected)) return { ok: false, type: request.type, error: 'stale_runtime_scope' };
1137
+ try {
1138
+ if (!assembly.modules) throw Error('perception_not_found');
1139
+ const result = assembly.modules.configure(request.perception,request.input,() => ownerScopeIsCurrent(runtime!,expected));
1140
+ return { ok: true, type: request.type, result };
1141
+ } catch (error) { return { ok: false, type: request.type, error: error instanceof Error ? error.message : 'perception_control_failed' }; }
1142
+ }
1143
+ if (request.type === 'behavior_watch' || request.type === 'behavior_unwatch' || request.type === 'behavior_update') {
1144
+ if (runtime!.currentSegment().kind !== 'game') {
1145
+ return { ok: false, type: request.type, error: 'no_active_game' };
1146
+ }
1147
+ const expected = ownerExpectedScope(request.expected_scope);
1148
+ const behavior = typeof request.behavior === 'string' ? request.behavior.trim() : '';
1149
+ const activationId = typeof request.activation_id === 'string' ? request.activation_id.trim() : '';
1150
+ const patch = request.type === 'behavior_unwatch' ? {} : request.input;
1151
+ if (!expected || !patch || typeof patch !== 'object' || Array.isArray(patch)
1152
+ || (request.type === 'behavior_update' ? (Boolean(behavior) === Boolean(activationId)) : (!behavior || !!activationId))) {
1153
+ return { ok: false, type: request.type, error: 'invalid_behavior_control_request' };
1154
+ }
1155
+ if (!ownerScopeIsCurrent(runtime!, expected)) return { ok: false, type: request.type, error: 'stale_runtime_scope' };
1156
+ try {
1157
+ if (activationId) {
1158
+ const activation = await assembly.behavior.updateInput(activationId, patch,
1159
+ () => ownerScopeIsCurrent(runtime!, expected));
1160
+ return { ok: true, type: request.type, updated: true, activation };
1161
+ }
1162
+ const operation = request.type === 'behavior_watch' ? 'enable'
1163
+ : request.type === 'behavior_unwatch' ? 'disable' : 'update';
1164
+ const result = await reflexControl.apply(operation, behavior, patch, expected);
1165
+ return { ok: true, type: request.type, result };
1166
+ } catch (error) {
1167
+ return { ok: false, type: request.type, error: error instanceof Error ? error.message : 'behavior_control_failed' };
1168
+ }
1169
+ }
1124
1170
  if (request.type === 'behavior_start') {
1125
1171
  const expected = ownerExpectedScope(request.expected_scope);
1126
1172
  const behavior = typeof request.behavior === 'string' ? request.behavior.trim() : '';
@@ -1163,7 +1209,7 @@ export async function runClawclawOwner(
1163
1209
  }
1164
1210
  }
1165
1211
  if (request.type === 'behavior_status') {
1166
- return { ok: true, type: 'behavior_status', status: assembly.behavior.status() };
1212
+ return { ok: true, type: 'behavior_status', status: reflexControl.view(typeof request.behavior === 'string' ? request.behavior : undefined) };
1167
1213
  }
1168
1214
  if (request.type === 'behavior_cancel') {
1169
1215
  const expected = ownerExpectedScope(request.expected_scope);
@@ -0,0 +1,36 @@
1
+ import { normalizePerceptionBehaviorBindings } from './reaction-manifest.js';
2
+ import type { PerceptionModuleManifest } from '../../sdk/perception-plugin/module.js';
3
+ import { hasValidClawclawResourceLocalizations } from '../../sdk/resource-metadata.js';
4
+ import { normalizeBehaviorInputFields, normalizeBehaviorInput } from './behavior-input-fields.js';
5
+ import { isClawclawFixedEventType, CLAWCLAW_GAME_STREAM_BACKEND_EVENT_TYPES,
6
+ CLAWCLAW_BACKEND_AGENT_EVENT_TYPES, CLAWCLAW_LOCAL_AGENT_EVENT_TYPES, CLAWCLAW_VISUAL_EVENT_TYPES } from '../clawclaw-event-catalog.js';
7
+
8
+ const INPUT_TYPES = new Set<string>([...CLAWCLAW_GAME_STREAM_BACKEND_EVENT_TYPES, ...CLAWCLAW_BACKEND_AGENT_EVENT_TYPES,
9
+ ...CLAWCLAW_LOCAL_AGENT_EVENT_TYPES.filter(type => !/^(behavior|reminder|perception)\./.test(type)),
10
+ 'tasks_changed', 'meeting_state']);
11
+ const PERCEPTION_OWNED_TYPES = new Set<string>([...CLAWCLAW_VISUAL_EVENT_TYPES, 'reminder.task', 'reminder.speech']);
12
+
13
+ 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 {
15
+ if (!record(value) || !Number.isInteger(value.apiVersion) || current && value.apiVersion !== 3
16
+ || Object.keys(value).some(key => !['apiVersion', 'id', 'name', 'description', 'localizations', 'consumes',
17
+ 'produces', 'inputs', 'config', 'behaviors'].includes(key))
18
+ || typeof value.id !== 'string' || !/^[a-z0-9][a-z0-9._-]*$/.test(value.id)
19
+ || typeof value.description !== 'string' || !value.description.trim()
20
+ || value.name !== undefined && (typeof value.name !== 'string' || !value.name.trim())
21
+ || !hasValidClawclawResourceLocalizations(value.localizations)
22
+ || value.config !== undefined && !record(value.config)) throw new Error('perception_module_manifest_invalid');
23
+ const consumes = value.consumes ?? [], produces = value.produces ?? [];
24
+ if (!Array.isArray(produces) || produces.some(type => typeof type !== 'string'
25
+ || !/^[a-z0-9][a-z0-9._-]*$/.test(type)
26
+ || isClawclawFixedEventType(type) && !PERCEPTION_OWNED_TYPES.has(type))
27
+ || !Array.isArray(consumes) || consumes.some(type => typeof type !== 'string' || !INPUT_TYPES.has(type)
28
+ || /^(visual|reminder|reaction|perception|behavior|decision)\./.test(type))) throw new Error('perception_module_event_contract_invalid');
29
+ const inputs = value.inputs ? normalizeBehaviorInputFields(value.inputs) : undefined;
30
+ const config = inputs ? normalizeBehaviorInput(value.config ?? {}, inputs) : structuredClone(value.config ?? {});
31
+ return { apiVersion: value.apiVersion, id: value.id, description: value.description,
32
+ ...(value.name === undefined ? {} : { name: value.name }),
33
+ ...(value.localizations === undefined ? {} : { localizations: structuredClone(value.localizations) }),
34
+ ...(value.behaviors === undefined ? {} : { behaviors: normalizePerceptionBehaviorBindings(value.behaviors) }),
35
+ consumes: [...new Set(consumes)], produces: [...new Set(produces)], ...(inputs ? { inputs } : {}), config };
36
+ }
@@ -1,8 +1,9 @@
1
1
  import type { GameClient } from '../../../lib/game-client.js';
2
+ import { ClawclawStrategyMemory } from '../strategy-memory.js';
2
3
  import { ClawclawReminderPlugin, CLAWCLAW_REMINDER_PLUGIN_ID } from './derived-event/reminder-plugin.js';
3
- import { listClawclawPerceptionSources } from './perception/perception-source.js';
4
+ import { listClawclawPerceptionSources, isSupportedPerceptionSource } from './perception/perception-source.js';
4
5
  import { DEFAULT_PERCEPTION_MODULES } from './perception/official-module-ids.js';
5
- import { ClawclawReactionPlugin, CLAWCLAW_REACTION_PLUGIN_ID } from './perception/reaction-plugin.js';
6
+ import { ClawclawPerceptionModulePlugin, CLAWCLAW_PERCEPTION_MODULE_PLUGIN_ID } from './perception/perception-module-plugin.js';
6
7
  import type { RuntimeEpochPlugin } from '../../framework/plugins/index.js';
7
8
  import {
8
9
  CLAWCLAW_ACTION_PLUGIN_ID,
@@ -50,7 +51,7 @@ export interface ClawclawPluginAssemblyOptions {
50
51
  }
51
52
 
52
53
  export interface ClawclawPluginAssembly {
53
- reactions?: ClawclawReactionPlugin;
54
+ modules?: ClawclawPerceptionModulePlugin;
54
55
  plugins: RuntimeEpochPlugin<Record<string, any>, Record<string, unknown>>[];
55
56
  action: ClawclawActionPlugin;
56
57
  gameQuery: ClawclawGameQueryPlugin;
@@ -94,13 +95,15 @@ export function assembleClawclawPlugins(
94
95
  throw new Error(`Runtime Plugin ${CLAWCLAW_REMINDER_PLUGIN_ID} is not a ClawclawReminderPlugin.`);
95
96
  }
96
97
  const selected = new Set(options.perception?.modules ?? DEFAULT_PERCEPTION_MODULES);
97
- const reactionSources = (options.perception?.moduleSources ?? listClawclawPerceptionSources(options.perception?.workspaceDir))
98
- .filter(source => source.reaction && source.apiVersion === 2 && selected.has(source.id));
98
+ const availableSources = options.perception?.moduleSources ?? listClawclawPerceptionSources(options.perception?.workspaceDir);
99
+ const explicitlyRequired = (id: string) => plugins.some(plugin => plugin.after?.includes(id));
100
+ const moduleSources = availableSources
101
+ .filter(source => source.module && isSupportedPerceptionSource(source) && selected.has(source.id));
102
+ const reminderSources = availableSources.filter(source => source.reminder && selected.has(source.id));
99
103
  const reminders = configuredReminders as ClawclawReminderPlugin | undefined ?? new ClawclawReminderPlugin({
100
- sources: (options.perception?.moduleSources ?? listClawclawPerceptionSources(options.perception?.workspaceDir))
101
- .filter(source => source.reminder && selected.has(source.id)),
104
+ sources: reminderSources,
102
105
  });
103
- if (!configuredReminders) plugins.push(reminders);
106
+ if (!configuredReminders && (reminderSources.length > 0 || explicitlyRequired(reminders.id))) plugins.push(reminders);
104
107
 
105
108
  const configuredGameQuery = plugins.find((plugin) => plugin.id === CLAWCLAW_GAME_QUERY_PLUGIN_ID);
106
109
  if (configuredGameQuery && !(configuredGameQuery instanceof ClawclawGameQueryPlugin)) {
@@ -115,8 +118,8 @@ export function assembleClawclawPlugins(
115
118
  throw new Error(`Runtime Plugin ${CLAWCLAW_PERCEPTION_PLUGIN_ID} is not a ClawclawPerceptionPlugin.`);
116
119
  }
117
120
  const perception = configuredPerception as ClawclawPerceptionPlugin | undefined
118
- ?? new ClawclawPerceptionPlugin(options.perception);
119
- if (!configuredPerception) plugins.push(perception);
121
+ ?? new ClawclawPerceptionPlugin({ ...options.perception, moduleSources: availableSources });
122
+ if (!configuredPerception && (perception.produces.events.length > 0 || explicitlyRequired(perception.id))) plugins.push(perception);
120
123
 
121
124
  const configuredTrigger = plugins.find((plugin) => plugin.id === CLAWCLAW_TRIGGER_PLUGIN_ID);
122
125
  if (configuredTrigger && !(configuredTrigger instanceof ClawclawTriggerPlugin)) {
@@ -125,21 +128,16 @@ export function assembleClawclawPlugins(
125
128
  const trigger = configuredTrigger as ClawclawTriggerPlugin | undefined
126
129
  ?? new ClawclawTriggerPlugin({
127
130
  after: [],
128
- // A migrated, selected perception replaces the same declared legacy Trigger.
129
- // Its old file/config can remain for rollback without evaluating the rule twice.
130
- triggers: options.triggers?.map(entry => reactionSources.some(source =>
131
- (source.declaredId ?? source.id) === entry.source.id) ? { ...entry, enabled: false } : entry),
131
+ triggers: options.triggers,
132
132
  diagnosticsEnabled: options.triggerDiagnosticsEnabled,
133
133
  });
134
134
  if (!configuredTrigger) plugins.push(trigger);
135
135
 
136
- const reactions = reactionSources.length ? new ClawclawReactionPlugin({
137
- sources: reactionSources,
138
- after: [CLAWCLAW_DERIVED_EVENT_PLUGIN_ID, CLAWCLAW_REMINDER_PLUGIN_ID,
139
- CLAWCLAW_GAME_QUERY_PLUGIN_ID, CLAWCLAW_PERCEPTION_PLUGIN_ID, CLAWCLAW_TRIGGER_PLUGIN_ID],
136
+ const modules = moduleSources.length ? new ClawclawPerceptionModulePlugin({ sources: moduleSources,
137
+ after: [CLAWCLAW_DERIVED_EVENT_PLUGIN_ID],
140
138
  behaviors: () => options.behaviorCatalog?.list?.() ?? [],
141
139
  }) : undefined;
142
- if (reactions) plugins.push(reactions);
140
+ if (modules) plugins.push(modules);
143
141
 
144
142
  const configuredBehavior = plugins.find((plugin) => plugin.id === CLAWCLAW_BEHAVIOR_PLUGIN_ID);
145
143
  if (configuredBehavior && !(configuredBehavior instanceof ClawclawBehaviorPlugin)) {
@@ -147,7 +145,6 @@ export function assembleClawclawPlugins(
147
145
  }
148
146
  const behavior = configuredBehavior as ClawclawBehaviorPlugin | undefined
149
147
  ?? new ClawclawBehaviorPlugin({
150
- perceptionActivations: !!reactions,
151
148
  catalog: options.behaviorCatalog ?? new ClawclawBehaviorCatalog([]),
152
149
  fallbackBehaviors: options.fallbackBehaviors,
153
150
  after: [
@@ -157,13 +154,18 @@ export function assembleClawclawPlugins(
157
154
  CLAWCLAW_GAME_QUERY_PLUGIN_ID,
158
155
  CLAWCLAW_PERCEPTION_PLUGIN_ID,
159
156
  CLAWCLAW_TRIGGER_PLUGIN_ID,
160
- ...(reactions ? [CLAWCLAW_REACTION_PLUGIN_ID] : []),
161
- ],
157
+ ...(modules ? [CLAWCLAW_PERCEPTION_MODULE_PLUGIN_ID] : []),
158
+ ].filter(id => plugins.some(plugin => plugin.id === id)),
162
159
  eventTypes: options.behaviorEventTypes,
163
160
  diagnosticsEnabled: options.behaviorDiagnosticsEnabled,
164
161
  });
165
162
  if (!configuredBehavior) plugins.push(behavior);
166
163
 
164
+ const strategyMemory = new ClawclawStrategyMemory();
165
+ trigger.attachMemory(strategyMemory);
166
+ behavior.attachMemory(strategyMemory);
167
+ modules?.attachMemory(strategyMemory);
168
+ modules?.attachDriver(behavior);
167
169
  trigger.attachDriver(behavior);
168
170
  // Direct Agent/user commands remain ActionPlugin calls this round. Preserve
169
171
  // their original activity timing: mark activity at Action admission, before
@@ -184,5 +186,5 @@ export function assembleClawclawPlugins(
184
186
  ?? new ClawclawMailboxPlugin({ after: eventProducers });
185
187
  if (!configuredMailbox) plugins.push(mailbox);
186
188
 
187
- return { plugins, action, gameQuery, perception, reminders, trigger, behavior, mailbox, reactions };
189
+ return { plugins, action, gameQuery, perception, reminders, trigger, behavior, mailbox, modules };
188
190
  }
@@ -1,6 +1,6 @@
1
1
  import type { BehaviorActivationLayer } from '../../../../sdk/behavior-plugin/index.js';
2
2
 
3
- export type BehaviorActivationSource = 'user' | 'agent' | 'idle' | 'trigger' | 'behavior' | 'system' | 'perception';
3
+ export type BehaviorActivationSource = 'user' | 'agent' | 'idle' | 'trigger' | 'perception' | 'behavior' | 'system';
4
4
  export type BehaviorActivationState = 'running' | 'suspended';
5
5
 
6
6
  export interface BehaviorActivationSpec {
@@ -266,11 +266,11 @@ export class BehaviorActivationManager {
266
266
  requestReflex(
267
267
  spec: Omit<BehaviorActivationSpec, 'layer' | 'source'> & {
268
268
  readonly layer?: 'reflex';
269
- readonly source?: 'trigger';
269
+ readonly source?: 'trigger' | 'perception';
270
270
  },
271
271
  now: number,
272
272
  ): readonly BehaviorActivationTransition[] {
273
- const candidate = this.activation({ ...spec, layer: 'reflex', source: 'trigger' }, now);
273
+ const candidate = this.activation({ ...spec, layer: 'reflex', source: spec.source ?? 'trigger' }, now);
274
274
  const active = this.reflex;
275
275
  if (active) {
276
276
  const sameTrigger = active.spec.triggerId === candidate.spec.triggerId;
@@ -365,6 +365,19 @@ export class BehaviorActivationManager {
365
365
  );
366
366
  }
367
367
 
368
+ /** New immutable input, same activation and deadline; old decision generations expire. */
369
+ updateInput(activationId: string, input: Readonly<Record<string, unknown>>, now: number): readonly BehaviorActivationTransition[] {
370
+ const active = [this.long, this.short, this.reflex].find(entry => entry?.spec.activationId === activationId);
371
+ if (!active) throw new Error('behavior_activation_not_found');
372
+ active.spec = { ...active.spec, input: cloneInput(input) };
373
+ active.instanceGeneration += 1;
374
+ return [this.transition(active, active.state === 'running' ? 'restarted' : 'suspended', now, 'behavior_input_updated')];
375
+ }
376
+
377
+ updateFallbackInput(behaviorId: string, input: Readonly<Record<string, unknown>>): void {
378
+ if (this.fallback?.behaviorId === behaviorId) this.fallback = { behaviorId, input: cloneInput(input) };
379
+ }
380
+
368
381
  snapshot(): Readonly<{
369
382
  long?: BehaviorActivationSnapshot;
370
383
  short?: BehaviorActivationSnapshot;
@@ -16,6 +16,7 @@ import type { ResolvedClawclawBehaviorSource } from './behavior-source.js';
16
16
  import type { ClawclawBehaviorObservationSnapshot } from '../../behavior-observation-memory.js';
17
17
  import { assertRuntimeModuleOutputSize } from '../../../framework/modules/runtime-module-output.js';
18
18
  import { captureBehaviorInstance, restoreBehaviorInstance, type BehaviorInstanceSnapshot } from './behavior-instance-snapshot.js';
19
+ import { StrategyMemoryRpcClient } from '../../strategy-memory-rpc.js';
19
20
 
20
21
  interface BehaviorThreadWorkerData {
21
22
  readonly poolId: string;
@@ -77,6 +78,7 @@ function diagnosticMemory(): Readonly<Record<string, number>> {
77
78
  : {};
78
79
  }
79
80
 
81
+ const memoryClient = new StrategyMemoryRpcClient(send);
80
82
  let loaded: ReturnType<typeof validateClawclawBehaviorModule>;
81
83
  let execution: ResolvedClawclawBehaviorSource['execution'];
82
84
  let preparation: ReturnType<typeof prepareClawclawBehavior> | undefined;
@@ -143,6 +145,7 @@ async function run(request: BehaviorThreadRunRequest | BehaviorThreadStopRequest
143
145
  restoreBehaviorInstance(instance, request.instanceSnapshot);
144
146
  }
145
147
  const api = createBehaviorReadApi(input, {
148
+ memory: memoryClient.bind(request.requestId, () => invocationActive),
146
149
  onQuery: () => { queryCount += 1; },
147
150
  isActive: () => invocationActive,
148
151
  ...(request.observationSnapshot === undefined
@@ -169,6 +172,7 @@ async function run(request: BehaviorThreadRunRequest | BehaviorThreadStopRequest
169
172
 
170
173
  let operationTail = Promise.resolve();
171
174
  port.on('message', (request: BehaviorThreadRunRequest | BehaviorThreadStopRequest) => {
175
+ if (memoryClient.receive(request)) return;
172
176
  operationTail = operationTail.then(() => run(request)).catch((error) => {
173
177
  send({
174
178
  type: 'error',
@@ -13,6 +13,7 @@ import {
13
13
  } from './behavior-source.js';
14
14
  import { prepareBehaviorInWorker } from './thread-behavior-executor.js';
15
15
  import { deepFreezeBehaviorValue } from './behavior-manifest.js';
16
+ import { normalizeBehaviorInput } from '../../behavior-input-fields.js';
16
17
 
17
18
  export interface ClawclawBehaviorCatalogEntry {
18
19
  readonly apiVersion: number | null;
@@ -107,6 +108,7 @@ export class ClawclawBehaviorCatalog {
107
108
  return Object.freeze({
108
109
  manifest: deepFreezeBehaviorValue(structuredClone(prepared.manifest)),
109
110
  input: deepFreezeBehaviorValue(structuredClone(prepared.input)),
111
+ rawInput: deepFreezeBehaviorValue(normalizeBehaviorInput(input, source.inputs, { allowedKeys: ['timeout_ms', 'duration_ms'] })),
110
112
  source: prepared.source,
111
113
  display: source.display,
112
114
  ...(prepared.timing === undefined ? {} : { timing: prepared.timing }),
@@ -20,6 +20,8 @@ export interface PreparedClawclawBehavior {
20
20
  readonly createModule?: () => ClawclawBehavior;
21
21
  readonly manifest: Readonly<ClawclawBehaviorManifest>;
22
22
  readonly input: Readonly<Record<string, unknown>>;
23
+ /** Schema input before optional author normalization; used when applying later parameter patches. */
24
+ readonly rawInput?: Readonly<Record<string, unknown>>;
23
25
  /** Static source identity required only by isolated parallel execution. */
24
26
  readonly source?: ResolvedClawclawBehaviorSource;
25
27
  /** Present only when the request/module materialized a finite budget. */
@@ -151,6 +153,7 @@ export function prepareClawclawBehavior(
151
153
  const timing = materializedTiming(raw, normalized, api);
152
154
  return Object.freeze({
153
155
  module,
156
+ rawInput: immutableRecord(declared),
154
157
  createModule: () => new BehaviorClass(),
155
158
  manifest,
156
159
  input: normalized,