@myclaw163/clawclaw-cli 0.10.17 → 0.10.18

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 (29) hide show
  1. package/cli-runtime/commands/behavior.js +7 -0
  2. package/cli-runtime/commands/prepare.js +12 -5
  3. package/cli-runtime/runtime/clawclaw/behavior-start-control.js +4 -2
  4. package/cli-runtime/runtime/clawclaw/behavior-trigger.js +17 -1
  5. package/cli-runtime/runtime/clawclaw/owner.js +12 -4
  6. package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-catalog.js +6 -0
  7. package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-plugin.js +49 -4
  8. package/cli-runtime/runtime/clawclaw/plugins/perception/perception-module-plugin.js +27 -2
  9. package/docs/custom-modules/README.md +1 -1
  10. package/docs/custom-modules/api-reference.md +2 -2
  11. package/docs/custom-modules/behavior.md +6 -4
  12. package/docs/user-guide/README.md +1 -1
  13. package/docs/user-guide/api-reference.md +2 -2
  14. package/docs/user-guide/behavior.md +6 -4
  15. package/package.json +1 -1
  16. package/skills/clawclaw/SKILL.md +2 -2
  17. package/skills/clawclaw/references/BEHAVIORS.md +2 -0
  18. package/skills/clawclaw-creator/SKILL.md +1 -1
  19. package/skills/clawclaw-creator/references/CUSTOM-BEHAVIOR-DEVELOPMENT.md +6 -4
  20. package/skills/clawclaw-creator/references/CUSTOM-MODULE-API.md +2 -2
  21. package/skills/clawclaw-creator/references/CUSTOM-MODULES.md +1 -1
  22. package/src/commands/behavior.ts +7 -0
  23. package/src/commands/prepare.ts +11 -4
  24. package/src/runtime/clawclaw/behavior-start-control.ts +3 -1
  25. package/src/runtime/clawclaw/behavior-trigger.ts +21 -1
  26. package/src/runtime/clawclaw/owner.ts +9 -4
  27. package/src/runtime/clawclaw/plugins/behavior/behavior-catalog.ts +8 -0
  28. package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.ts +60 -7
  29. package/src/runtime/clawclaw/plugins/perception/perception-module-plugin.ts +31 -4
@@ -33,6 +33,7 @@ import {
33
33
  classifyStrategyLifecycle,
34
34
  readCapabilityWorkspaceRegistry
35
35
  } from "../lib/capability-workspace.js";
36
+ import { strategyActivationError, strategyActivationMode } from "../runtime/clawclaw/behavior-trigger.js";
36
37
  import { readFileSync } from "node:fs";
37
38
  import { selectCapability } from "../lib/capability-selection.js";
38
39
  import { renameCapabilityOperationWhenIdle } from "../lib/capability-operation-rename.js";
@@ -106,6 +107,8 @@ function sourceEntry(source, disabled) {
106
107
  inputs: source.inputs,
107
108
  produces: source.produces ?? [],
108
109
  ...source.runtime === void 0 ? {} : { runtime: source.runtime },
110
+ activation_mode: strategyActivationMode(source),
111
+ ...source.triggerError ? { reflex: { available: false, reason: source.triggerError } } : {},
109
112
  strategy_type: classifyStrategyLifecycle(readFileSync(source.sourcePath, "utf8")),
110
113
  source: source.management.source,
111
114
  managed_by: source.management.managedBy,
@@ -305,6 +308,8 @@ ${commandName === "strategy" ? "Strategy" : "Behavior"} modules:
305
308
  if (!hub && gameplay.disabled_behaviors.includes(id)) {
306
309
  throw new Error(`Behavior '${id}' is disabled in user-data/gameplay.json.`);
307
310
  }
311
+ const error = strategyActivationError(source);
312
+ if (error) throw new Error(`${id}: ${error}. \u8BE5\u7B56\u7565\u4EC5\u81EA\u52A8\u89E6\u53D1\uFF0C\u7531\u540C\u6587\u4EF6\u7684\u611F\u77E5\u8BF7\u6C42\u542F\u52A8\u3002`);
308
313
  await runOwnerCommand(`ccl ${commandName} start`, "behavior_start", {
309
314
  behavior: id,
310
315
  layer: opts.layer,
@@ -346,6 +351,8 @@ ${commandName === "strategy" ? "Strategy" : "Behavior"} modules:
346
351
  if (entry.loadable !== true || !hub && gameplay.disabled_behaviors.includes(id)) {
347
352
  throw new Error(`Behavior '${id}' is not enabled and loadable.`);
348
353
  }
354
+ const error = strategyActivationError(source);
355
+ if (error) throw new Error(`${id}: ${error}. \u8BE5\u7B56\u7565\u4EC5\u81EA\u52A8\u89E6\u53D1\uFF0C\u8BF7\u9009\u62E9\u666E\u901A\u7B56\u7565\u4F5C\u4E3A\u89D2\u8272\u9ED8\u8BA4\u7B56\u7565\u3002`);
349
356
  const updated = updateGameplayConfig((current) => {
350
357
  current.fallback_behaviors[role] = id;
351
358
  }, workspaceDir, profile);
@@ -33,6 +33,7 @@ import { BEHAVIOR_PLUGIN_API_VERSION } from "../sdk/behavior-plugin/index.js";
33
33
  import { TRIGGER_PLUGIN_API_VERSION } from "../sdk/trigger-plugin/index.js";
34
34
  import { PERCEPTION_PLUGIN_API_VERSION } from "../sdk/perception-plugin/index.js";
35
35
  import { expectedPerceptionApiVersion, isSupportedPerceptionSource } from "../runtime/clawclaw/plugins/perception/perception-source.js";
36
+ import { strategyActivationMode } from "../runtime/clawclaw/behavior-trigger.js";
36
37
  import { resolveReactionBehavior } from "../runtime/clawclaw/reaction-behavior-resolution.js";
37
38
  import { pluginApiVersionStatus } from "../runtime/clawclaw/plugins/plugin-api-version.js";
38
39
  import {
@@ -333,6 +334,7 @@ function createPrepareCommand(dependencies = {}) {
333
334
  api_version: source.apiVersion ?? null,
334
335
  expected_api_version: BEHAVIOR_PLUGIN_API_VERSION,
335
336
  loadable,
337
+ activation_mode: strategyActivationMode(source),
336
338
  ...loadable ? {} : {
337
339
  compatibility_error: versionCompatible ? compatibilityError : `behavior_api_version_unsupported:expected=${BEHAVIOR_PLUGIN_API_VERSION}:received=${source.apiVersion ?? "missing"}`
338
340
  },
@@ -390,12 +392,14 @@ function createPrepareCommand(dependencies = {}) {
390
392
  for (const role of CLAWCLAW_ROLE_IDS) {
391
393
  const fallback = gameplay.fallback_behaviors[role];
392
394
  if (fallback === null) continue;
393
- if (!behaviors.some(({ id }) => id === fallback)) {
395
+ const entry = behaviors.find(({ id }) => id === fallback);
396
+ if (!entry || entry.activation_mode === "automatic_only") {
397
+ const unavailableReason = disabledBehaviors.has(fallback) ? "local_disabled_or_unselected" : "not_loaded";
394
398
  configurationWarnings.push({
395
399
  code: "DEFAULT_LONG_BEHAVIOR_UNAVAILABLE",
396
400
  role,
397
401
  behavior_id: fallback,
398
- reason: disabledBehaviors.has(fallback) ? "local_disabled_or_unselected" : "not_loaded"
402
+ reason: entry ? "strategy_automatic_only" : unavailableReason
399
403
  });
400
404
  }
401
405
  }
@@ -507,13 +511,15 @@ function createPrepareCommand(dependencies = {}) {
507
511
  behavior_name: binding.name,
508
512
  message: `Equip the paired strategy ${binding.name}; perception observation and notifications remain available.`
509
513
  });
514
+ const target = behaviors.find((entry) => entry.id === id);
515
+ const available = !!target && target.activation_mode !== "automatic_only";
510
516
  return {
511
517
  perception_id: source.id,
512
518
  binding: key,
513
519
  behavior_id: id ?? binding.name,
514
- available: !!id,
515
- default_enabled: false,
516
- ...id ? {} : { reason: "behavior_not_loaded" }
520
+ available,
521
+ default_enabled: available,
522
+ ...available ? {} : { reason: target ? "strategy_automatic_only" : "behavior_not_loaded" }
517
523
  };
518
524
  }));
519
525
  const perceptionEntry = (source) => ({
@@ -798,6 +804,7 @@ function createPrepareCommand(dependencies = {}) {
798
804
  name: localized.name,
799
805
  description: source.description,
800
806
  source: entry.source,
807
+ activation_mode: entry.activation_mode,
801
808
  strategy_type: strategyLifecycle(source.sourcePath),
802
809
  ...source.trigger ? { reflex: { available: true } } : source.triggerError ? { reflex: { available: false, reason: source.triggerError } } : {},
803
810
  ...source.management.versionNumber ? {
@@ -69,6 +69,8 @@ class DeferredMeetingShortStrategy {
69
69
  async start(request) {
70
70
  const rejection = startRejection(this.runtime, request);
71
71
  if (rejection) return rejection;
72
+ const error = this.behavior.startError(request.behavior);
73
+ if (error) return { ok: false, type: "behavior_start", error };
72
74
  if (request.layer !== "short") return startOwnerBehavior(this.runtime, this.behavior, request);
73
75
  const version = ++this.requestVersion;
74
76
  const inMeeting = () => this.runtime.readState().state?.phase === "meeting";
@@ -89,8 +91,8 @@ class DeferredMeetingShortStrategy {
89
91
  if (!display) return { ok: false, type: "behavior_start", error: "behavior_not_found" };
90
92
  this.pending = { request: structuredClone(request), requestId: randomUUID(), display, starting: false };
91
93
  return { ok: true, type: "behavior_start", status: "queued", pending: this.status() };
92
- } catch (error) {
93
- return { ok: false, type: "behavior_start", error: error instanceof Error ? error.message : String(error) };
94
+ } catch (error2) {
95
+ return { ok: false, type: "behavior_start", error: error2 instanceof Error ? error2.message : String(error2) };
94
96
  }
95
97
  }
96
98
  status(behaviorId) {
@@ -1,4 +1,18 @@
1
1
  import { normalizePerceptionModuleManifest } from "./perception-module-manifest.js";
2
+ function strategyActivationMode(source) {
3
+ return source.trigger || source.triggerError ? "automatic_only" : "standard";
4
+ }
5
+ function strategyActivationError(source, request) {
6
+ if (source.triggerError) return source.triggerError;
7
+ if (!source.trigger) return void 0;
8
+ if (request?.source === "perception" && Object.keys(source.trigger.manifest.behaviors ?? {}).some(
9
+ (key) => request.triggerId === `perception:${strategyPerceptionId(source.id)}:${key}`
10
+ )) return void 0;
11
+ return "strategy_automatic_only";
12
+ }
13
+ function strategyPerceptionId(strategyId) {
14
+ return "strategy:" + strategyId;
15
+ }
2
16
  function normalizeStrategyPerception(value, strategyId) {
3
17
  const manifest = normalizePerceptionModuleManifest(value);
4
18
  const bindings = Object.values(manifest.behaviors ?? {});
@@ -10,7 +24,7 @@ function normalizeStrategyPerception(value, strategyId) {
10
24
  function strategyTriggerSource(source) {
11
25
  if (!source.trigger) return void 0;
12
26
  const { manifest, sha256 } = source.trigger;
13
- const id = "strategy:" + source.id;
27
+ const id = strategyPerceptionId(source.id);
14
28
  const name = manifest.name ?? manifest.id;
15
29
  const behaviors = Object.fromEntries(Object.entries(manifest.behaviors).map(([key, binding]) => [key, { ...binding, name: source.id }]));
16
30
  return {
@@ -34,5 +48,7 @@ function strategyTriggerSource(source) {
34
48
  }
35
49
  export {
36
50
  normalizeStrategyPerception,
51
+ strategyActivationError,
52
+ strategyActivationMode,
37
53
  strategyTriggerSource
38
54
  };
@@ -177,13 +177,18 @@ const EVENTS_QUERY_BARRIER_TIMEOUT_MS = 1e4;
177
177
  const LOCAL_STOP_FORCE_EXIT_MS = 1e4;
178
178
  function roleFallbackBehaviors(config, catalog, warning = () => {
179
179
  }) {
180
- const loadable = new Set(catalog.list().filter((entry) => entry.loadable).map((entry) => entry.id));
180
+ const entries = new Map(catalog.list().map((entry) => [entry.id, entry]));
181
181
  const result = {};
182
182
  for (const role of CLAWCLAW_ROLE_IDS) {
183
183
  const behaviorId = config.fallback_behaviors[role];
184
184
  if (behaviorId === null) continue;
185
- if (!loadable.has(behaviorId)) {
186
- warning("behavior_fallback_unavailable", { role, behavior_id: behaviorId });
185
+ const entry = entries.get(behaviorId);
186
+ if (!entry?.loadable || entry.activationMode === "automatic_only") {
187
+ warning("behavior_fallback_unavailable", {
188
+ role,
189
+ behavior_id: behaviorId,
190
+ ...entry?.activationMode === "automatic_only" ? { reason: "strategy_automatic_only" } : {}
191
+ });
187
192
  continue;
188
193
  }
189
194
  result[role] = { behaviorId, input: {} };
@@ -1116,6 +1121,9 @@ async function runClawclawOwner(options) {
1116
1121
  return { ok: false, type: "behavior_fallback", error: "stale_runtime_scope" };
1117
1122
  }
1118
1123
  const latest = readGameplayConfig(workspaceDir, options.profile);
1124
+ const selected = latest.fallback_behaviors[role];
1125
+ const error = request.action === "set" && selected && behaviorCatalog.activationError(selected);
1126
+ if (error) return { ok: false, type: "behavior_fallback", error };
1119
1127
  const currentRole = readyRoleForScope(runtime, expected);
1120
1128
  if (currentRole === role) {
1121
1129
  await assembly.behavior.noteAgentActivity();
@@ -1129,7 +1137,7 @@ async function runClawclawOwner(options) {
1129
1137
  ok: true,
1130
1138
  type: "behavior_fallback",
1131
1139
  role,
1132
- fallback: latest.fallback_behaviors[role]
1140
+ fallback: selected
1133
1141
  };
1134
1142
  }
1135
1143
  if (request.type === "behavior_idle") {
@@ -8,6 +8,7 @@ import {
8
8
  } from "./behavior-source.js";
9
9
  import { prepareBehaviorInWorker } from "./thread-behavior-executor.js";
10
10
  import { deepFreezeBehaviorValue } from "./behavior-manifest.js";
11
+ import { strategyActivationError, strategyActivationMode } from "../../behavior-trigger.js";
11
12
  import { normalizeBehaviorInput } from "../../behavior-input-fields.js";
12
13
  function catalogEntry(source) {
13
14
  const apiError = source.apiVersion === BEHAVIOR_PLUGIN_API_VERSION ? void 0 : pluginApiVersionDiagnostic(
@@ -32,6 +33,7 @@ function catalogEntry(source) {
32
33
  ...source.produces === void 0 ? {} : { produces: source.produces },
33
34
  ...source.runtime === void 0 ? {} : { runtime: source.runtime },
34
35
  ...source.provenance === void 0 ? {} : { provenance: source.provenance },
36
+ activationMode: strategyActivationMode(source),
35
37
  loadable: compatibilityError === void 0,
36
38
  ...compatibilityError === void 0 ? {} : { compatibilityError }
37
39
  });
@@ -53,6 +55,10 @@ class ClawclawBehaviorCatalog {
53
55
  has(id) {
54
56
  return this.sources.has(id);
55
57
  }
58
+ activationError(id, request) {
59
+ const source = this.sources.get(id);
60
+ return source && strategyActivationError(source, request);
61
+ }
56
62
  load(id) {
57
63
  const source = this.sources.get(id);
58
64
  if (!source) return Promise.reject(new Error(`Unknown behavior module '${id}'.`));
@@ -42,7 +42,14 @@ function sdkFrame(frame) {
42
42
  function preparedValue(prepared) {
43
43
  return { ...prepared.value, ...prepared.module ? { module: prepared.module } : {} };
44
44
  }
45
- function createAdapter(deferredDisplay, useAdaptiveWorkers) {
45
+ function createAdapter(deferredDisplay, useAdaptiveWorkers, assertStartAllowed) {
46
+ const checkDelegation = (decision) => {
47
+ if (decision.delegate) {
48
+ const target = decision.delegate;
49
+ assertStartAllowed("strategy" in target ? target.strategy : target.behavior);
50
+ }
51
+ return decision;
52
+ };
46
53
  const observations = new ClawclawBehaviorObservationMemory();
47
54
  return {
48
55
  input: (input, parameters, continuation, history) => {
@@ -104,8 +111,8 @@ function createAdapter(deferredDisplay, useAdaptiveWorkers) {
104
111
  prepare: () => runner.prepare(),
105
112
  stop: (reason) => runner.stop(reason),
106
113
  diagnosticSnapshot: () => runner.diagnosticSnapshot(),
107
- decideSerial: (frame, signal, observation) => runner.decideSerial(sdkFrame(frame), signal, observation),
108
- decideParallel: (frame, signal, observation) => runner.decideParallel(sdkFrame(frame), signal, observation)
114
+ decideSerial: (frame, signal, observation) => runner.decideSerial(sdkFrame(frame), signal, observation).then(checkDelegation),
115
+ decideParallel: (frame, signal, observation) => runner.decideParallel(sdkFrame(frame), signal, observation).then(checkDelegation)
109
116
  };
110
117
  },
111
118
  action: (action, epoch, safety, generation, tick) => ({ ...normalizeClawclawBehaviorAction(action, epoch, safety, generation, tick) }),
@@ -127,14 +134,23 @@ function createAdapter(deferredDisplay, useAdaptiveWorkers) {
127
134
  }
128
135
  class ClawclawBehaviorPlugin extends StrategyHost {
129
136
  deferredShort;
137
+ catalogAccess;
138
+ assertStartAllowed;
130
139
  constructor(options) {
140
+ const assertStartAllowed = (id) => {
141
+ const error = options.catalog.activationError?.(id);
142
+ if (error) throw new Error(error);
143
+ };
144
+ for (const binding of Object.values(options.fallbackBehaviors ?? {})) {
145
+ if (binding) assertStartAllowed(binding.behaviorId);
146
+ }
131
147
  const deferredShort = {};
132
148
  super({
133
149
  ...options,
134
150
  id: CLAWCLAW_BEHAVIOR_PLUGIN_ID,
135
151
  stateTopic: CLAWCLAW_BEHAVIOR_STATE_TOPIC,
136
152
  actionCapability: CLAWCLAW_ACTION_CAPABILITY,
137
- adapter: createAdapter(() => deferredShort.control?.display(), !!options.catalog.prepareForActivation),
153
+ adapter: createAdapter(() => deferredShort.control?.display(), !!options.catalog.prepareForActivation, assertStartAllowed),
138
154
  captureActions: resolveDetailCapture().actions,
139
155
  catalog: { has: (id) => options.catalog.has(id), prepare: async (id, input) => {
140
156
  const prepared = await options.catalog.prepare(id, input);
@@ -146,6 +162,35 @@ class ClawclawBehaviorPlugin extends StrategyHost {
146
162
  after: options.after ?? [CLAWCLAW_ACTION_PLUGIN_ID, CLAWCLAW_GAME_QUERY_PLUGIN_ID, CLAWCLAW_PERCEPTION_PLUGIN_ID, CLAWCLAW_TRIGGER_PLUGIN_ID]
147
163
  });
148
164
  this.deferredShort = deferredShort;
165
+ this.catalogAccess = options.catalog;
166
+ this.assertStartAllowed = assertStartAllowed;
167
+ }
168
+ startError(id) {
169
+ return this.catalogAccess.activationError?.(id);
170
+ }
171
+ async startLong(id, input, options) {
172
+ this.assertStartAllowed(id);
173
+ return super.startLong(id, input, options);
174
+ }
175
+ async startShort(id, input, options) {
176
+ this.assertStartAllowed(id);
177
+ return super.startShort(id, input, options);
178
+ }
179
+ async bindFallback(id, input) {
180
+ this.assertStartAllowed(id);
181
+ return super.bindFallback(id, input);
182
+ }
183
+ async configureFallbackBehaviors(bindings, currentRole) {
184
+ for (const binding of Object.values(bindings)) {
185
+ if (binding) this.assertStartAllowed(binding.behaviorId);
186
+ }
187
+ return super.configureFallbackBehaviors(bindings, currentRole);
188
+ }
189
+ async requestReflex(request, guard) {
190
+ if (this.catalogAccess.activationError?.(request.behavior, request)) {
191
+ return { accepted: false, reason: "activation_ineligible" };
192
+ }
193
+ return super.requestReflex(request, guard);
149
194
  }
150
195
  attachDeferredShortControl(control) {
151
196
  this.deferredShort.control = control;
@@ -3,6 +3,7 @@ import { prepareNotificationContent, notificationStateAt } from "./notification-
3
3
  import { preparePerceptionNotification } from "./report-content.js";
4
4
  import { isNotificationTurn } from "../../notification-turn.js";
5
5
  import { normalizeBehaviorInput } from "../../behavior-input-fields.js";
6
+ import { resolveReactionBehavior } from "../../reaction-behavior-resolution.js";
6
7
  import { clawclawComputationGameState, isClawclawRuntimeState } from "../../runtime-state.js";
7
8
  import { projectTaskChoiceEventPayload } from "../../task-choice-projection.js";
8
9
  import { PerceptionModuleRunner } from "./perception-module-runner.js";
@@ -15,7 +16,7 @@ import { REACTION_HOST_EVENT_TYPES } from "@myclaw163/game-agent-runtime/percept
15
16
  function sourceValue(source) {
16
17
  return source.value;
17
18
  }
18
- function createAdapter(options) {
19
+ function createAdapter(options, blockedBindings) {
19
20
  function prepare(input, previous, context) {
20
21
  const checkpoint = structuredClone(previous ?? { modules: {} });
21
22
  const oldBoundary = checkpoint.gameId ? {
@@ -94,6 +95,14 @@ function createAdapter(options) {
94
95
  const { input, game, frame, facts, eventStates, boundary, common } = prepared.value;
95
96
  const events = facts.filter((event) => source.module.consumes?.includes(event.type));
96
97
  const comparison = comparePerceptionTasks(baseline, input, boundary);
98
+ const blocked = blockedBindings.get(source.id);
99
+ if (blocked) {
100
+ bindings = {
101
+ ...bindings,
102
+ availableBindings: bindings.availableBindings.filter((key) => !blocked.has(key)),
103
+ enabledBindings: bindings.enabledBindings.filter((key) => !blocked.has(key))
104
+ };
105
+ }
97
106
  const embedded = sourceValue(source).embedded;
98
107
  const declaredTargets = embedded && bindings.availableBindings.length ? Object.values(embedded.declaredManifest.behaviors ?? {}).map((binding) => binding.name) : [];
99
108
  const moduleInput = {
@@ -126,14 +135,30 @@ function createAdapter(options) {
126
135
  };
127
136
  }
128
137
  class ClawclawPerceptionModulePlugin extends PerceptionHost {
138
+ blockedBindings;
129
139
  constructor(options) {
140
+ const blockedBindings = /* @__PURE__ */ new Map();
141
+ const candidates = options.behaviors?.() ?? [];
142
+ const automatic = new Set(candidates.filter((entry) => entry.activationMode === "automatic_only").map((entry) => entry.id));
143
+ for (const source of options.sources) {
144
+ if (source.embedded) continue;
145
+ const blocked = Object.entries(source.module?.behaviors ?? {}).filter(([, binding]) => {
146
+ const id = resolveReactionBehavior(binding, candidates);
147
+ return id !== void 0 && automatic.has(id);
148
+ }).map(([key]) => key);
149
+ if (blocked.length) blockedBindings.set(source.id, new Set(blocked));
150
+ }
130
151
  super({
131
152
  id: CLAWCLAW_PERCEPTION_MODULE_PLUGIN_ID,
132
153
  after: options.after,
133
154
  behaviors: options.behaviors,
134
- adapter: createAdapter(options),
155
+ adapter: createAdapter(options, blockedBindings),
135
156
  sources: options.sources.filter((source) => source.module).map((source) => ({ id: source.id, name: source.name, module: source.module, value: source }))
136
157
  });
158
+ this.blockedBindings = blockedBindings;
159
+ }
160
+ bindings(id) {
161
+ return super.bindings(id).map((binding) => this.blockedBindings.get(binding.perception_id)?.has(binding.binding) ? { ...binding, enabled: false, available: false, reason: "strategy_automatic_only" } : binding);
137
162
  }
138
163
  localizedModuleDescriptors(locale) {
139
164
  const descriptors = super.localizedModuleDescriptors(locale);
@@ -75,7 +75,7 @@ flowchart LR
75
75
  | `short` | 暂时完成一件有限工作 |
76
76
  | `reflex` | 策略内置 Trigger 条件命中后请求优先执行即时反应 |
77
77
 
78
- 三层都使用 `ClawclawStrategy`,优先级为 `reflex > short > long`。手动启动支持 long/short,反射由策略内置 Trigger 请求,默认策略 fallback 是空栈时使用哪个 long 的配置。具体启动、暂停恢复与会议边界见[策略教程](./behavior.md#长期短期和反射)。
78
+ 三层都使用 `ClawclawStrategy`,优先级为 `reflex > short > long`。普通策略可以手动启动为 long/short。带具名 `Trigger` 的策略仅由同文件的感知自动触发。角色默认策略从普通策略中选择。具体启动、暂停恢复与会议边界见[策略教程](./behavior.md#长期短期和反射)。
79
79
 
80
80
  ## 一个模块文件由什么组成
81
81
 
@@ -406,7 +406,7 @@ interface StrategyDelegation {
406
406
  }
407
407
  ```
408
408
 
409
- 只有当前 long Activation 可以使用 `delegate` 启动一个 short。Runtime 会先通过 Strategy Catalog 校验目标与输入,再改变控制栈。`delegate` 不能与 `actions` 或 `finish` 同时返回;short/reflex 使用会让当前 Activation failed。委派 short 的终态通过 long 恢复后的 `continuation.delegatedBehavior` 一次性返回。
409
+ 当前 long Activation 可以用 `delegate` 将普通策略启动为 short。Runtime 会先通过 Strategy Catalog 校验目标与输入,再改变控制栈。`delegate` 不能与 `actions` 或 `finish` 同时返回;short/reflex 使用会让当前 Activation failed。委派 short 的终态通过 long 恢复后的 `continuation.delegatedBehavior` 一次性返回。
410
410
 
411
411
  #### `StrategyFinish`
412
412
 
@@ -494,7 +494,7 @@ interface StrategyNormalizationApi {
494
494
 
495
495
  ## 策略内置触发感知
496
496
 
497
- CCL 0.10.16 起,策略文件可以具名导出继承 `ClawclawPerception` 的 `Trigger`。使用 `@myclaw163/clawclaw-cli/perception-plugin` 的感知 API v3。`Trigger.manifest` 和普通感知一样声明 `id`、`description`,在 `strategies` 里给本文件默认策略的声明 ID 配置固定绑定。绑定可以指定 `reflexPriority`、`cooldownMs`、`rearm` 和 `maxRuntimeMs`。
497
+ 策略文件具名导出继承 `ClawclawPerception` 的 `Trigger` 后,只有这份感知可以请求启动本策略。使用 `@myclaw163/clawclaw-cli/perception-plugin` 的感知 API v3。`Trigger.manifest` 和普通感知一样声明 `id`、`description`,在 `strategies` 里给本文件默认策略的声明 ID 配置固定绑定。绑定可以指定 `reflexPriority`、`cooldownMs`、`rearm` 和 `maxRuntimeMs`。
498
498
 
499
499
  `evaluate(input, api)` 接收 `PerceptionModuleInput`,通过 `input.frame`、`input.events`、`input.config` 和 `input.state` 读取观察、事实、配置和上次返回的私有状态。返回 `PerceptionModuleResult`,可含 `state`、`events` 和 `activations`。例如 `{ activations: [{ strategy: 'escape', input: { x: 2708, y: 2320 }, reason: 'player_nearby' }] }` 使用清单里的 `escape` 绑定,激活参数覆盖策略默认值。
500
500
 
@@ -11,7 +11,7 @@
11
11
 
12
12
  ## 长期、短期和反射
13
13
 
14
- 所有策略都继承 `ClawclawStrategy`。下面三种是一次策略运行所处的层,不是三种模块基类;同一份代码可以按适用场景运行在不同层。
14
+ 所有策略都继承 `ClawclawStrategy`。每次启动时,CCL 会为策略分配一个运行层。
15
15
 
16
16
  | 运行方式 | 代码值 | 用途 | 启动入口 |
17
17
  |---|---|---|---|
@@ -21,7 +21,9 @@
21
21
 
22
22
  控制优先级固定为 **反射 > 短期 > 长期**。例如:长期做任务 → 短期报尸,暂停做任务 → 反射撤离,暂停报尸 → 撤离结束后恢复仍有效的报尸 → 报尸结束后再恢复长期任务。
23
23
 
24
- 手动命令 `ccl strategy start --layer` 只接受 long 和 short。反射由策略内置 Trigger 请求并由 Strategy 插件仲裁,见下文。
24
+ 普通策略可以用 `ccl strategy start` 启动为 long 或 short。**同一文件具名导出 `Trigger` 的策略仅自动触发**。例如,撤离策略只会在同文件的感知发现玩家靠近并请求撤离后,参与 reflex 层的优先级仲裁。CCL 从文件导出识别规则,作者无需添加配置项。
25
+
26
+ `ccl strategy list` 和 `info` 用 `activation_mode: automatic_only` 标识这类策略。手动启动(包括会议期间排队)、其他策略的 `delegate` 和角色默认策略都只能选普通策略。
25
27
 
26
28
  `long` 不要求永不结束,`short` 和 `reflex` 也不会自动知道业务目标何时完成。模块应在确认目标完成或失败后返回 `finish`;运行时限用于防止有限任务长期占用控制权。
27
29
 
@@ -101,7 +103,7 @@ export default class GoToPoint extends ClawclawStrategy<GoToPointInput> {
101
103
 
102
104
  ## 单文件反射与局中控制
103
105
 
104
- 运行对局的 CCL 需要 0.10.16 或更新版本,桌面端以实际使用的 CCL 版本为准。一个策略文件同时导出执行类和触发感知。默认导出的 `ClawclawStrategy` 在取得控制权后执行 `decide()`。具名导出的 `Trigger extends ClawclawPerception` 使用感知 API v3,在 `evaluate()` 中通过 `activations` 请求已声明的同文件策略绑定。示例在玩家进入指定范围时前往撤离点。
106
+ 一个策略文件同时导出执行类和触发感知。默认导出的 `ClawclawStrategy` 在取得控制权后执行 `decide()`。具名导出的 `Trigger extends ClawclawPerception` 使用感知 API v3,在 `evaluate()` 中通过 `activations` 请求已声明的同文件策略绑定。示例在玩家进入指定范围时前往撤离点。
105
107
 
106
108
  ```ts
107
109
  import {
@@ -181,7 +183,7 @@ ccl strategy unwatch community.auto-escape
181
183
 
182
184
  装配一个策略文件后,触发感知随对局运行,默认允许自动激活。`unwatch` 禁止自动激活并取消该绑定正在执行的反射,感知继续观察和保存状态。`watch` 恢复自动激活。
183
185
 
184
- `strategy update` 按两个类各自声明的字段更新感知配置或策略输入。策略输入影响本策略当前执行及后续启动默认值。动态命中参数和显式启动参数覆盖本局默认值。只改一次执行时加 `--activation` 并指定 Activation ID。改参保留 Activation ID 和原截止时间,增加实例代际。暂停实例继续暂停。设置在换局或 Owner 退出时清空。
186
+ `strategy update` 按两个类各自声明的字段更新感知配置或策略输入。策略输入影响本策略当前执行及后续启动默认值。触发感知可以在命中时传入本次反射的目标,覆盖对应的本局默认值。只改一次执行时加 `--activation` 并指定 Activation ID。改参保留 Activation ID 和原截止时间,增加实例代际。暂停实例继续暂停。设置在换局或 Owner 退出时清空。
185
187
 
186
188
  跨激活去重使用 `api.memory`。例如 Trigger 查 `handled:<尸体ID>`,追尸策略实际接手现场后再写。单次执行进度可以用实例字段。
187
189
 
@@ -35,7 +35,7 @@ CCL 内置玩家、任务、能力、紧急任务、房间与流程、会议、
35
35
  | 短期策略 | `--layer short` | 前往指定地点、完成一次追踪或处理当前任务 |
36
36
  | 反射策略 | 策略内置 Trigger 请求 | 条件命中后优先撤离或处理即时情况 |
37
37
 
38
- 三种方式都使用 `ClawclawStrategy`,优先级是 `reflex > short > long`。手动启动只接受 long/short;反射由策略内置 Trigger 请求。启用表示模块可供使用,启动才表示开始执行。
38
+ 三种方式都使用 `ClawclawStrategy`,优先级是 `reflex > short > long`。普通策略可以手动启动为 long/short。带具名 `Trigger` 的策略仅由同文件的感知自动触发。启用表示模块可供使用,启动才表示开始执行。
39
39
 
40
40
  ## 开发前须知
41
41
 
@@ -365,7 +365,7 @@ interface StrategyDelegation {
365
365
  }
366
366
  ```
367
367
 
368
- 只有当前 long Activation 可以使用 `delegate` 启动一个 short。Runtime 会先通过策略 Catalog 校验目标与输入,再改变控制栈。`delegate` 不能与 `actions` 或 `finish` 同时返回;short 使用会让当前 Activation failed。委派 short 的终态通过 long 恢复后的 `continuation.delegatedBehavior` 一次性返回。
368
+ 当前 long Activation 可以用 `delegate` 将普通策略启动为 short。Runtime 会先通过策略 Catalog 校验目标与输入,再改变控制栈。`delegate` 不能与 `actions` 或 `finish` 同时返回;short 使用会让当前 Activation failed。委派 short 的终态通过 long 恢复后的 `continuation.delegatedBehavior` 一次性返回。
369
369
 
370
370
  #### `StrategyFinish`
371
371
 
@@ -646,7 +646,7 @@ import type {
646
646
 
647
647
  ## 策略内置触发感知
648
648
 
649
- CCL 0.10.16 起,策略文件可以具名导出继承 `ClawclawPerception` 的 `Trigger`。使用 `@myclaw163/clawclaw-cli/perception-plugin` 的感知 API v3。`Trigger.manifest` 和普通感知一样声明 `id`、`description`,在 `strategies` 里给本文件默认策略的声明 ID 配置固定绑定。绑定可以指定 `reflexPriority`、`cooldownMs`、`rearm` 和 `maxRuntimeMs`。
649
+ 策略文件具名导出继承 `ClawclawPerception` 的 `Trigger` 后,只有这份感知可以请求启动本策略。使用 `@myclaw163/clawclaw-cli/perception-plugin` 的感知 API v3。`Trigger.manifest` 和普通感知一样声明 `id`、`description`,在 `strategies` 里给本文件默认策略的声明 ID 配置固定绑定。绑定可以指定 `reflexPriority`、`cooldownMs`、`rearm` 和 `maxRuntimeMs`。
650
650
 
651
651
  `evaluate(input, api)` 接收 `PerceptionModuleInput`,通过 `input.frame`、`input.events`、`input.config` 和 `input.state` 读取观察、事实、配置和上次返回的私有状态。返回 `PerceptionModuleResult`,可含 `state`、`events` 和 `activations`。例如 `{ activations: [{ strategy: 'escape', input: { x: 2708, y: 2320 }, reason: 'player_nearby' }] }` 使用清单里的 `escape` 绑定,激活参数覆盖策略默认值。
652
652
 
@@ -11,7 +11,7 @@
11
11
 
12
12
  ## 长期、短期和反射
13
13
 
14
- 所有策略都继承 `ClawclawStrategy`。下面三种是一次策略运行所处的层,不是三种模块基类;同一份代码可以按适用场景运行在不同层。
14
+ 所有策略都继承 `ClawclawStrategy`。每次启动时,CCL 会为策略分配一个运行层。
15
15
 
16
16
  | 运行方式 | 代码值 | 用途 | 启动入口 |
17
17
  |---|---|---|---|
@@ -21,7 +21,9 @@
21
21
 
22
22
  控制优先级固定为 **反射 > 短期 > 长期**。例如:长期做任务 → 短期报尸,暂停做任务 → 反射撤离,暂停报尸 → 撤离结束后恢复仍有效的报尸 → 报尸结束后再恢复长期任务。
23
23
 
24
- 手动命令 `ccl strategy start --layer` 只接受 long 和 short。反射由策略内置 Trigger 请求并由 Strategy 插件仲裁,见下文。
24
+ 普通策略可以用 `ccl strategy start` 启动为 long 或 short。**同一文件具名导出 `Trigger` 的策略仅自动触发**。例如,撤离策略只会在同文件的感知发现玩家靠近并请求撤离后,参与 reflex 层的优先级仲裁。CCL 从文件导出识别规则,作者无需添加配置项。
25
+
26
+ `ccl strategy list` 和 `info` 用 `activation_mode: automatic_only` 标识这类策略。手动启动(包括会议期间排队)、其他策略的 `delegate` 和角色默认策略都只能选普通策略。
25
27
 
26
28
  `long` 不要求永不结束,`short` 和 `reflex` 也不会自动知道业务目标何时完成。模块应在确认目标完成或失败后返回 `finish`;运行时限用于防止有限任务长期占用控制权。
27
29
 
@@ -101,7 +103,7 @@ export default class GoToPoint extends ClawclawStrategy<GoToPointInput> {
101
103
 
102
104
  ## 单文件反射与局中控制
103
105
 
104
- 运行对局的 CCL 需要 0.10.16 或更新版本,桌面端以实际使用的 CCL 版本为准。一个策略文件同时导出执行类和触发感知。默认导出的 `ClawclawStrategy` 在取得控制权后执行 `decide()`。具名导出的 `Trigger extends ClawclawPerception` 使用感知 API v3,在 `evaluate()` 中通过 `activations` 请求已声明的同文件策略绑定。示例在玩家进入指定范围时前往撤离点。
106
+ 一个策略文件同时导出执行类和触发感知。默认导出的 `ClawclawStrategy` 在取得控制权后执行 `decide()`。具名导出的 `Trigger extends ClawclawPerception` 使用感知 API v3,在 `evaluate()` 中通过 `activations` 请求已声明的同文件策略绑定。示例在玩家进入指定范围时前往撤离点。
105
107
 
106
108
  ```ts
107
109
  import {
@@ -181,7 +183,7 @@ ccl strategy unwatch community.auto-escape
181
183
 
182
184
  装配一个策略文件后,触发感知随对局运行,默认允许自动激活。`unwatch` 禁止自动激活并取消该绑定正在执行的反射,感知继续观察和保存状态。`watch` 恢复自动激活。
183
185
 
184
- `strategy update` 按两个类各自声明的字段更新感知配置或策略输入。策略输入影响本策略当前执行及后续启动默认值。动态命中参数和显式启动参数覆盖本局默认值。只改一次执行时加 `--activation` 并指定 Activation ID。改参保留 Activation ID 和原截止时间,增加实例代际。暂停实例继续暂停。设置在换局或 Owner 退出时清空。
186
+ `strategy update` 按两个类各自声明的字段更新感知配置或策略输入。策略输入影响本策略当前执行及后续启动默认值。触发感知可以在命中时传入本次反射的目标,覆盖对应的本局默认值。只改一次执行时加 `--activation` 并指定 Activation ID。改参保留 Activation ID 和原截止时间,增加实例代际。暂停实例继续暂停。设置在换局或 Owner 退出时清空。
185
187
 
186
188
  跨激活去重使用 `api.memory`。例如 Trigger 查 `handled:<尸体ID>`,追尸策略实际接手现场后再写。单次执行进度可以用实例字段。
187
189
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myclaw163/clawclaw-cli",
3
- "version": "0.10.17",
3
+ "version": "0.10.18",
4
4
  "type": "module",
5
5
  "description": "ClawClaw social deduction game CLI",
6
6
  "bin": {
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  name: clawclaw
3
3
  description: ClawClaw/龙虾杀的完整玩法 Skill,仅在游戏事件流接通后读取。开局或恢复连接之前不要读取本 Skill,此阶段只读取 clawclaw-start。start/join 成功接流后立即调用本 Skill,不必等待匹配完成或身份分配。用于处理实时游戏事件、角色行动、策略、会议发言与投票、结算和复盘。资源创作使用 clawclaw-creator。
4
- version: 4.8.134
4
+ version: 4.8.135
5
5
  ---
6
6
 
7
7
  # 龙虾杀完整玩法(接流后调用)
@@ -155,7 +155,7 @@ ccl strategy idle 500
155
155
  ccl aside "<仅用户/观战玩家可见的推理>"
156
156
  ```
157
157
 
158
- 用户要求检查或管理 Strategy 时,先用 `ccl strategy list` 取得当前目录,再对返回的纯本地条目使用 `info/disable/enable`;Hub enablement 由 Hub loadout 管理。list/info 只做静态 manifest 检查,绝不 import 或执行第三方源码。启用变更和源码/manifest 修改从下一次 Runtime 起生效。运行当前 Owner 已加载的模块使用 `ccl strategy start <id> --layer short|long --input '<JSON object>'`。同层一次只有一个 Activation:新 short 替换旧 short,新 long 替换旧 long;`accepted` 不等于完成。
158
+ 用户要求检查或管理 Strategy 时,先用 `ccl strategy list` 取得当前目录,再对返回的纯本地条目使用 `info/disable/enable`;Hub enablement 由 Hub loadout 管理。list/info 只做静态 manifest 检查,绝不 import 或执行第三方源码。启用变更和源码/manifest 修改从下一次 Runtime 起生效。`list/info` 中 `activation_mode: automatic_only` 表示仅由同文件的感知自动触发。这类策略用 `watch/unwatch` 开关自动反射,用 `update` 调参。手动启动普通策略使用 `ccl strategy start <id> --layer short|long --input '<JSON object>'`。同层一次只有一个 Activation:新 short 替换旧 short,新 long 替换旧 long;`accepted` 不等于完成。
159
159
 
160
160
  ### 3.5 游走阶段
161
161
 
@@ -62,6 +62,8 @@ ccl strategy info <behavior-id-from-list>
62
62
  ccl strategy start <behavior-id-from-list> --layer short --input '<JSON object from info.inputs>'
63
63
  ```
64
64
 
65
+ 请先查看 `ccl strategy info <id>` 的 `activation_mode`。`automatic_only` 仅允许同文件的感知触发,手动启动、委派和角色默认策略都应选择 `standard`。
66
+
65
67
  会议中手动启动短策略时,`status: queued` 表示已选中并等待游荡。CCL 上报选中的策略名和描述,回到游荡才实际启动并计算运行时限。用 `ccl strategy status` 查看 `pending_short`,用 `ccl strategy cancel <request_id>` 取消。同一局的后续短策略请求替换待执行项。
66
68
 
67
69
  启动输出的 `accepted` 只表示 Owner 接受请求,不表示行动成功。一个 short 运行时:
@@ -22,7 +22,7 @@ metadata:
22
22
  | 教 Agent 分析、组织发言或执行一套流程 | Skill | [游戏 Skill](references/CUSTOM-SKILL-DEVELOPMENT.md) |
23
23
  | 玩家声音、性格和表达风格 | 人设 | [人设 Markdown](references/CUSTOM-PERSONA-DEVELOPMENT.md) |
24
24
 
25
- 精确字段与签名查 [API 参考](references/CUSTOM-MODULE-API.md),不要一次加载所有教程。自动反射在同一个策略文件中添加继承 ClawclawPerception 的具名 Trigger,安装并启用一个 Strategy 资源。只需要修改当前局参数时,按现有模块的 manifest 使用 `ccl strategy update` / `ccl perception update`,不用新建源码。
25
+ 精确字段与签名查 [API 参考](references/CUSTOM-MODULE-API.md),不要一次加载所有教程。自动反射在同一个策略文件中添加继承 ClawclawPerception 的具名 Trigger,装配这一个 Strategy 资源后,只能由该感知请求启动策略。只需要修改当前局参数时,按现有模块的 manifest 使用 `ccl strategy update` / `ccl perception update`,不用新建源码。
26
26
 
27
27
  ## 2. 同步编辑基线,定位当前账号和原文件
28
28
 
@@ -11,7 +11,7 @@
11
11
 
12
12
  ## 长期、短期和反射
13
13
 
14
- 所有策略都继承 `ClawclawStrategy`。下面三种是一次策略运行所处的层,不是三种模块基类;同一份代码可以按适用场景运行在不同层。
14
+ 所有策略都继承 `ClawclawStrategy`。每次启动时,CCL 会为策略分配一个运行层。
15
15
 
16
16
  | 运行方式 | 代码值 | 用途 | 启动入口 |
17
17
  |---|---|---|---|
@@ -21,7 +21,9 @@
21
21
 
22
22
  控制优先级固定为 **反射 > 短期 > 长期**。例如:长期做任务 → 短期报尸,暂停做任务 → 反射撤离,暂停报尸 → 撤离结束后恢复仍有效的报尸 → 报尸结束后再恢复长期任务。
23
23
 
24
- 手动命令 `ccl strategy start --layer` 只接受 long 和 short。反射由策略内置 Trigger 请求并由 Strategy 插件仲裁,见下文。
24
+ 普通策略可以用 `ccl strategy start` 启动为 long 或 short。**同一文件具名导出 `Trigger` 的策略仅自动触发**。例如,撤离策略只会在同文件的感知发现玩家靠近并请求撤离后,参与 reflex 层的优先级仲裁。CCL 从文件导出识别规则,作者无需添加配置项。
25
+
26
+ `ccl strategy list` 和 `info` 用 `activation_mode: automatic_only` 标识这类策略。手动启动(包括会议期间排队)、其他策略的 `delegate` 和角色默认策略都只能选普通策略。
25
27
 
26
28
  `long` 不要求永不结束,`short` 和 `reflex` 也不会自动知道业务目标何时完成。模块应在确认目标完成或失败后返回 `finish`;运行时限用于防止有限任务长期占用控制权。
27
29
 
@@ -101,7 +103,7 @@ export default class GoToPoint extends ClawclawStrategy<GoToPointInput> {
101
103
 
102
104
  ## 单文件反射与局中控制
103
105
 
104
- 运行对局的 CCL 需要 0.10.16 或更新版本,桌面端以实际使用的 CCL 版本为准。一个策略文件同时导出执行类和触发感知。默认导出的 `ClawclawStrategy` 在取得控制权后执行 `decide()`。具名导出的 `Trigger extends ClawclawPerception` 使用感知 API v3,在 `evaluate()` 中通过 `activations` 请求已声明的同文件策略绑定。示例在玩家进入指定范围时前往撤离点。
106
+ 一个策略文件同时导出执行类和触发感知。默认导出的 `ClawclawStrategy` 在取得控制权后执行 `decide()`。具名导出的 `Trigger extends ClawclawPerception` 使用感知 API v3,在 `evaluate()` 中通过 `activations` 请求已声明的同文件策略绑定。示例在玩家进入指定范围时前往撤离点。
105
107
 
106
108
  ```ts
107
109
  import {
@@ -181,7 +183,7 @@ ccl strategy unwatch community.auto-escape
181
183
 
182
184
  装配一个策略文件后,触发感知随对局运行,默认允许自动激活。`unwatch` 禁止自动激活并取消该绑定正在执行的反射,感知继续观察和保存状态。`watch` 恢复自动激活。
183
185
 
184
- `strategy update` 按两个类各自声明的字段更新感知配置或策略输入。策略输入影响本策略当前执行及后续启动默认值。动态命中参数和显式启动参数覆盖本局默认值。只改一次执行时加 `--activation` 并指定 Activation ID。改参保留 Activation ID 和原截止时间,增加实例代际。暂停实例继续暂停。设置在换局或 Owner 退出时清空。
186
+ `strategy update` 按两个类各自声明的字段更新感知配置或策略输入。策略输入影响本策略当前执行及后续启动默认值。触发感知可以在命中时传入本次反射的目标,覆盖对应的本局默认值。只改一次执行时加 `--activation` 并指定 Activation ID。改参保留 Activation ID 和原截止时间,增加实例代际。暂停实例继续暂停。设置在换局或 Owner 退出时清空。
185
187
 
186
188
  跨激活去重使用 `api.memory`。例如 Trigger 查 `handled:<尸体ID>`,追尸策略实际接手现场后再写。单次执行进度可以用实例字段。
187
189
 
@@ -404,7 +404,7 @@ interface StrategyDelegation {
404
404
  }
405
405
  ```
406
406
 
407
- 只有当前 long Activation 可以使用 `delegate` 启动一个 short。Runtime 会先通过 Strategy Catalog 校验目标与输入,再改变控制栈。`delegate` 不能与 `actions` 或 `finish` 同时返回;short 使用会让当前 Activation failed。委派 short 的终态通过 long 恢复后的 `continuation.delegatedBehavior` 一次性返回。
407
+ 当前 long Activation 可以用 `delegate` 将普通策略启动为 short。Runtime 会先通过 Strategy Catalog 校验目标与输入,再改变控制栈。`delegate` 不能与 `actions` 或 `finish` 同时返回;short 使用会让当前 Activation failed。委派 short 的终态通过 long 恢复后的 `continuation.delegatedBehavior` 一次性返回。
408
408
 
409
409
  #### `StrategyFinish`
410
410
 
@@ -685,7 +685,7 @@ import type {
685
685
 
686
686
  ## 策略内置触发感知
687
687
 
688
- CCL 0.10.16 起,策略文件可以具名导出继承 `ClawclawPerception` 的 `Trigger`。使用 `@myclaw163/clawclaw-cli/perception-plugin` 的感知 API v3。`Trigger.manifest` 和普通感知一样声明 `id`、`description`,在 `strategies` 里给本文件默认策略的声明 ID 配置固定绑定。绑定可以指定 `reflexPriority`、`cooldownMs`、`rearm` 和 `maxRuntimeMs`。
688
+ 策略文件具名导出继承 `ClawclawPerception` 的 `Trigger` 后,只有这份感知可以请求启动本策略。使用 `@myclaw163/clawclaw-cli/perception-plugin` 的感知 API v3。`Trigger.manifest` 和普通感知一样声明 `id`、`description`,在 `strategies` 里给本文件默认策略的声明 ID 配置固定绑定。绑定可以指定 `reflexPriority`、`cooldownMs`、`rearm` 和 `maxRuntimeMs`。
689
689
 
690
690
  `evaluate(input, api)` 接收 `PerceptionModuleInput`,通过 `input.frame`、`input.events`、`input.config` 和 `input.state` 读取观察、事实、配置和上次返回的私有状态。返回 `PerceptionModuleResult`,可含 `state`、`events` 和 `activations`。例如 `{ activations: [{ strategy: 'escape', input: { x: 2708, y: 2320 }, reason: 'player_nearby' }] }` 使用清单里的 `escape` 绑定,激活参数覆盖策略默认值。
691
691
 
@@ -75,7 +75,7 @@ flowchart LR
75
75
  | `short` | 暂时完成一件有限工作 |
76
76
  | `reflex` | 策略内置 Trigger 条件命中后请求优先执行即时反应 |
77
77
 
78
- 三层都使用 `ClawclawStrategy`,优先级为 `reflex > short > long`。手动启动支持 long/short,反射由策略内置 Trigger 请求,默认策略 fallback 是空栈时使用哪个 long 的配置。具体启动、暂停恢复与会议边界见[策略教程](./CUSTOM-BEHAVIOR-DEVELOPMENT.md#长期短期和反射)。
78
+ 三层都使用 `ClawclawStrategy`,优先级为 `reflex > short > long`。普通策略可以手动启动为 long/short。带具名 `Trigger` 的策略仅由同文件的感知自动触发。角色默认策略从普通策略中选择。具体启动、暂停恢复与会议边界见[策略教程](./CUSTOM-BEHAVIOR-DEVELOPMENT.md#长期短期和反射)。
79
79
 
80
80
  ## 一个模块文件由什么组成
81
81
 
@@ -42,6 +42,7 @@ import {
42
42
  classifyStrategyLifecycle,
43
43
  readCapabilityWorkspaceRegistry,
44
44
  } from '../lib/capability-workspace.js';
45
+ import { strategyActivationError, strategyActivationMode } from '../runtime/clawclaw/behavior-trigger.js';
45
46
  import { readFileSync } from 'node:fs';
46
47
  import { selectCapability } from '../lib/capability-selection.js';
47
48
  import { renameCapabilityOperationWhenIdle } from '../lib/capability-operation-rename.js';
@@ -130,6 +131,8 @@ function sourceEntry(
130
131
  inputs: source.inputs,
131
132
  produces: source.produces ?? [],
132
133
  ...(source.runtime === undefined ? {} : { runtime: source.runtime }),
134
+ activation_mode: strategyActivationMode(source),
135
+ ...(source.triggerError ? { reflex: { available: false, reason: source.triggerError } } : {}),
133
136
  strategy_type: classifyStrategyLifecycle(readFileSync(source.sourcePath, 'utf8')),
134
137
  source: source.management.source,
135
138
  managed_by: source.management.managedBy,
@@ -386,6 +389,8 @@ function createStrategyControlCommand(commandName: 'behavior' | 'strategy', depe
386
389
  if (!hub && gameplay.disabled_behaviors.includes(id)) {
387
390
  throw new Error(`Behavior '${id}' is disabled in user-data/gameplay.json.`);
388
391
  }
392
+ const error = strategyActivationError(source);
393
+ if (error) throw new Error(`${id}: ${error}. 该策略仅自动触发,由同文件的感知请求启动。`);
389
394
  await runOwnerCommand(`ccl ${commandName} start`, 'behavior_start', {
390
395
  behavior: id,
391
396
  layer: opts.layer,
@@ -448,6 +453,8 @@ function createStrategyControlCommand(commandName: 'behavior' | 'strategy', depe
448
453
  if (entry.loadable !== true || (!hub && gameplay.disabled_behaviors.includes(id))) {
449
454
  throw new Error(`Behavior '${id}' is not enabled and loadable.`);
450
455
  }
456
+ const error = strategyActivationError(source);
457
+ if (error) throw new Error(`${id}: ${error}. 该策略仅自动触发,请选择普通策略作为角色默认策略。`);
451
458
  const updated = updateGameplayConfig((current) => {
452
459
  current.fallback_behaviors[role] = id;
453
460
  }, workspaceDir, profile);
@@ -34,6 +34,7 @@ import { BEHAVIOR_PLUGIN_API_VERSION } from '../sdk/behavior-plugin/index.js';
34
34
  import { TRIGGER_PLUGIN_API_VERSION } from '../sdk/trigger-plugin/index.js';
35
35
  import { PERCEPTION_PLUGIN_API_VERSION } from '../sdk/perception-plugin/index.js';
36
36
  import { expectedPerceptionApiVersion, isSupportedPerceptionSource } from '../runtime/clawclaw/plugins/perception/perception-source.js';
37
+ import { strategyActivationMode } from '../runtime/clawclaw/behavior-trigger.js';
37
38
  import { resolveReactionBehavior } from '../runtime/clawclaw/reaction-behavior-resolution.js';
38
39
  import { pluginApiVersionStatus } from '../runtime/clawclaw/plugins/plugin-api-version.js';
39
40
  import {
@@ -442,6 +443,7 @@ export function createPrepareCommand(dependencies: PrepareCommandDependencies =
442
443
  api_version: source.apiVersion ?? null,
443
444
  expected_api_version: BEHAVIOR_PLUGIN_API_VERSION,
444
445
  loadable,
446
+ activation_mode: strategyActivationMode(source),
445
447
  ...(loadable ? {} : {
446
448
  compatibility_error: versionCompatible
447
449
  ? compatibilityError
@@ -502,12 +504,14 @@ export function createPrepareCommand(dependencies: PrepareCommandDependencies =
502
504
  for (const role of CLAWCLAW_ROLE_IDS) {
503
505
  const fallback = gameplay.fallback_behaviors[role];
504
506
  if (fallback === null) continue;
505
- if (!behaviors.some(({ id }) => id === fallback)) {
507
+ const entry = behaviors.find(({ id }) => id === fallback);
508
+ if (!entry || entry.activation_mode === 'automatic_only') {
509
+ const unavailableReason = disabledBehaviors.has(fallback) ? 'local_disabled_or_unselected' : 'not_loaded';
506
510
  configurationWarnings.push({
507
511
  code: 'DEFAULT_LONG_BEHAVIOR_UNAVAILABLE',
508
512
  role,
509
513
  behavior_id: fallback,
510
- reason: disabledBehaviors.has(fallback) ? 'local_disabled_or_unselected' : 'not_loaded',
514
+ reason: entry ? 'strategy_automatic_only' : unavailableReason,
511
515
  });
512
516
  }
513
517
  }
@@ -619,9 +623,11 @@ export function createPrepareCommand(dependencies: PrepareCommandDependencies =
619
623
  if (!id) configurationWarnings.push({ code: 'PERCEPTION_BEHAVIOR_NOT_LOADED',
620
624
  perception_id: source.id, binding: key, behavior_name: binding.name,
621
625
  message: `Equip the paired strategy ${binding.name}; perception observation and notifications remain available.` });
626
+ const target = behaviors.find(entry => entry.id === id);
627
+ const available = !!target && target.activation_mode !== 'automatic_only';
622
628
  return { perception_id: source.id, binding: key, behavior_id: id ?? binding.name,
623
- available: !!id, default_enabled: false,
624
- ...(id ? {} : { reason: 'behavior_not_loaded' }) };
629
+ available, default_enabled: available,
630
+ ...(available ? {} : { reason: target ? 'strategy_automatic_only' : 'behavior_not_loaded' }) };
625
631
  }));
626
632
  const perceptionEntry = (source: typeof enabledPerceptions[number]) => ({
627
633
  id: source.id,
@@ -954,6 +960,7 @@ export function createPrepareCommand(dependencies: PrepareCommandDependencies =
954
960
  name: localized.name,
955
961
  description: source.description,
956
962
  source: entry.source,
963
+ activation_mode: entry.activation_mode,
957
964
  strategy_type: strategyLifecycle(source.sourcePath),
958
965
  ...(source.trigger ? { reflex: { available: true } }
959
966
  : source.triggerError ? { reflex: { available: false, reason: source.triggerError } } : {}),
@@ -99,13 +99,15 @@ export class DeferredMeetingShortStrategy {
99
99
 
100
100
  constructor(
101
101
  private readonly runtime: DeferredStartRuntime,
102
- private readonly behavior: BehaviorStarter & Pick<ClawclawBehaviorPlugin, 'cancel'>,
102
+ private readonly behavior: BehaviorStarter & Pick<ClawclawBehaviorPlugin, 'cancel' | 'startError'>,
103
103
  private readonly resolveDisplay: (request: BehaviorStartRequest) => ClawclawResolvedResourceMetadata | undefined,
104
104
  ) {}
105
105
 
106
106
  async start(request: BehaviorStartRequest): Promise<OwnerControlResponse> {
107
107
  const rejection = startRejection(this.runtime, request);
108
108
  if (rejection) return rejection;
109
+ const error = this.behavior.startError(request.behavior);
110
+ if (error) return { ok: false, type: 'behavior_start', error };
109
111
  if (request.layer !== 'short') return startOwnerBehavior(this.runtime, this.behavior, request);
110
112
  const version = ++this.requestVersion;
111
113
  const inMeeting = () => this.runtime.readState().state?.phase === 'meeting';
@@ -2,6 +2,26 @@ import { normalizePerceptionModuleManifest } from './perception-module-manifest.
2
2
  import type { ResolvedClawclawBehaviorSource } from './plugins/behavior/behavior-source.js';
3
3
  import type { ResolvedClawclawPerceptionSource } from './plugins/perception/perception-source.js';
4
4
 
5
+ type TriggerDeclaration = Pick<ResolvedClawclawBehaviorSource, 'trigger' | 'triggerError'>;
6
+
7
+ export function strategyActivationMode(source: TriggerDeclaration) {
8
+ return source.trigger || source.triggerError ? 'automatic_only' : 'standard';
9
+ }
10
+
11
+ export function strategyActivationError(source: ResolvedClawclawBehaviorSource,
12
+ request?: Readonly<{ source: string; triggerId: string }>): string | undefined {
13
+ if (source.triggerError) return source.triggerError;
14
+ if (!source.trigger) return undefined;
15
+ if (request?.source === 'perception' && Object.keys(source.trigger.manifest.behaviors ?? {}).some(
16
+ key => request.triggerId === `perception:${strategyPerceptionId(source.id)}:${key}`,
17
+ )) return undefined;
18
+ return 'strategy_automatic_only';
19
+ }
20
+
21
+ function strategyPerceptionId(strategyId: string): string {
22
+ return 'strategy:' + strategyId;
23
+ }
24
+
5
25
  export function normalizeStrategyPerception(value: unknown, strategyId: string) {
6
26
  const manifest = normalizePerceptionModuleManifest(value);
7
27
  const bindings = Object.values(manifest.behaviors ?? {});
@@ -15,7 +35,7 @@ export function normalizeStrategyPerception(value: unknown, strategyId: string)
15
35
  export function strategyTriggerSource(source: ResolvedClawclawBehaviorSource): ResolvedClawclawPerceptionSource | undefined {
16
36
  if (!source.trigger) return undefined;
17
37
  const { manifest, sha256 } = source.trigger;
18
- const id = 'strategy:' + source.id;
38
+ const id = strategyPerceptionId(source.id);
19
39
  const name = manifest.name ?? manifest.id;
20
40
  const behaviors = Object.fromEntries(Object.entries(manifest.behaviors!).map(([key, binding]) =>
21
41
  [key, { ...binding, name: source.id }]));
@@ -280,13 +280,15 @@ export function roleFallbackBehaviors(
280
280
  catalog: Pick<ClawclawBehaviorCatalog, 'list'>,
281
281
  warning: ConfigurationWarning = () => {},
282
282
  ): ClawclawRoleFallbackBehaviors {
283
- const loadable = new Set(catalog.list().filter((entry) => entry.loadable).map((entry) => entry.id));
283
+ const entries = new Map(catalog.list().map(entry => [entry.id, entry]));
284
284
  const result: Record<string, { behaviorId: string; input: Record<string, never> } | undefined> = {};
285
285
  for (const role of CLAWCLAW_ROLE_IDS) {
286
286
  const behaviorId = config.fallback_behaviors[role];
287
287
  if (behaviorId === null) continue;
288
- if (!loadable.has(behaviorId)) {
289
- warning('behavior_fallback_unavailable', { role, behavior_id: behaviorId });
288
+ const entry = entries.get(behaviorId);
289
+ if (!entry?.loadable || entry.activationMode === 'automatic_only') {
290
+ warning('behavior_fallback_unavailable', { role, behavior_id: behaviorId,
291
+ ...(entry?.activationMode === 'automatic_only' ? { reason: 'strategy_automatic_only' } : {}) });
290
292
  continue;
291
293
  }
292
294
  result[role] = { behaviorId, input: {} };
@@ -1312,6 +1314,9 @@ export async function runClawclawOwner(
1312
1314
  return { ok: false, type: 'behavior_fallback', error: 'stale_runtime_scope' };
1313
1315
  }
1314
1316
  const latest = readGameplayConfig(workspaceDir, options.profile);
1317
+ const selected = latest.fallback_behaviors[role as keyof typeof latest.fallback_behaviors];
1318
+ const error = request.action === 'set' && selected && behaviorCatalog.activationError(selected);
1319
+ if (error) return { ok: false, type: 'behavior_fallback', error };
1315
1320
  const currentRole = readyRoleForScope(runtime!, expected);
1316
1321
  if (currentRole === role) {
1317
1322
  await assembly.behavior.noteAgentActivity();
@@ -1325,7 +1330,7 @@ export async function runClawclawOwner(
1325
1330
  ok: true,
1326
1331
  type: 'behavior_fallback',
1327
1332
  role,
1328
- fallback: latest.fallback_behaviors[role as keyof typeof latest.fallback_behaviors],
1333
+ fallback: selected,
1329
1334
  };
1330
1335
  }
1331
1336
  if (request.type === 'behavior_idle') {
@@ -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 { strategyActivationError, strategyActivationMode } from '../../behavior-trigger.js';
16
17
  import { normalizeBehaviorInput } from '../../behavior-input-fields.js';
17
18
 
18
19
  export interface ClawclawBehaviorCatalogEntry {
@@ -31,6 +32,7 @@ export interface ClawclawBehaviorCatalogEntry {
31
32
  readonly produces?: readonly string[];
32
33
  readonly runtime?: ResolvedClawclawBehaviorSource['runtime'];
33
34
  readonly provenance?: ResolvedClawclawBehaviorSource['provenance'];
35
+ readonly activationMode?: ReturnType<typeof strategyActivationMode>;
34
36
  readonly loadable: boolean;
35
37
  readonly compatibilityError?: string;
36
38
  }
@@ -60,6 +62,7 @@ function catalogEntry(source: ResolvedClawclawBehaviorSource): ClawclawBehaviorC
60
62
  ...(source.produces === undefined ? {} : { produces: source.produces }),
61
63
  ...(source.runtime === undefined ? {} : { runtime: source.runtime }),
62
64
  ...(source.provenance === undefined ? {} : { provenance: source.provenance }),
65
+ activationMode: strategyActivationMode(source),
63
66
  loadable: compatibilityError === undefined,
64
67
  ...(compatibilityError === undefined ? {} : { compatibilityError }),
65
68
  });
@@ -87,6 +90,11 @@ export class ClawclawBehaviorCatalog {
87
90
  return this.sources.has(id);
88
91
  }
89
92
 
93
+ activationError(id: string, request?: Readonly<{ source: string; triggerId: string }>): string | undefined {
94
+ const source = this.sources.get(id);
95
+ return source && strategyActivationError(source, request);
96
+ }
97
+
90
98
  load(id: string): Promise<LoadedClawclawBehaviorModule> {
91
99
  const source = this.sources.get(id);
92
100
  if (!source) return Promise.reject(new Error(`Unknown behavior module '${id}'.`));
@@ -1,7 +1,7 @@
1
1
  import { isNotificationTurn } from '../../notification-turn.js';
2
2
  import { ClawclawStrategyMemory } from '../../strategy-memory.js';
3
3
  import { resolveDetailCapture } from '../../../observability/detail-capture.js';
4
- import type { BehaviorContinuation, BehaviorInput, ClawclawResolvedResourceMetadata, GameAction } from '../../../../sdk/behavior-plugin/index.js';
4
+ import type { BehaviorContinuation, BehaviorDecision, BehaviorInput, ClawclawResolvedResourceMetadata, GameAction } from '../../../../sdk/behavior-plugin/index.js';
5
5
  import { resolveClawclawResourceMetadata } from '../../../../sdk/behavior-plugin/index.js';
6
6
  import type { RuntimeEpochCatchUp } from '../../../framework/plugins/contracts.js';
7
7
  import { createBehaviorInput } from '../../behavior-input.js';
@@ -18,7 +18,7 @@ import type { PreparedClawclawBehavior } from './behavior-normalization.js';
18
18
  import { ClawclawBehaviorRunner } from './behavior-runner.js';
19
19
  import type { ClawclawBehaviorControlDriver } from './control-driver.js';
20
20
  import { StrategyHost } from '@myclaw163/game-agent-runtime/strategy/strategy-host.js';
21
- import type { PreparedStrategy, StrategyAdapter, StrategyFrame } from '@myclaw163/game-agent-runtime/strategy/contracts.js';
21
+ import type { PreparedStrategy, ReflexRequest, ReflexResult, StrategyAdapter, StrategyFrame } from '@myclaw163/game-agent-runtime/strategy/contracts.js';
22
22
  import type { BehaviorDecisionFrame } from '../../../../sdk/module-input/index.js';
23
23
  import type { ClawclawBehaviorObservationSnapshot } from '../../behavior-observation-memory.js';
24
24
  export const CLAWCLAW_BEHAVIOR_PLUGIN_ID = 'clawclaw.behavior';
@@ -59,7 +59,7 @@ function isSuccessfulBackendStrategyReport(value: unknown): boolean {
59
59
  }
60
60
  export interface ClawclawBehaviorPluginOptions {
61
61
  readonly memory?: ClawclawStrategyMemory;
62
- readonly catalog: Pick<ClawclawBehaviorCatalog, 'has' | 'prepare'> & Partial<Pick<ClawclawBehaviorCatalog, 'prepareForActivation'>>;
62
+ readonly catalog: Pick<ClawclawBehaviorCatalog, 'has' | 'prepare'> & Partial<Pick<ClawclawBehaviorCatalog, 'prepareForActivation' | 'activationError'>>;
63
63
  readonly fallbackBehaviors?: ClawclawRoleFallbackBehaviors;
64
64
  readonly manager?: BehaviorActivationManager;
65
65
  readonly driver?: ClawclawBehaviorControlDriver;
@@ -87,7 +87,16 @@ function sdkFrame(frame: StrategyFrame): Readonly<BehaviorInput> { return frame.
87
87
  function preparedValue(prepared: PreparedStrategy): PreparedClawclawBehavior {
88
88
  return { ...(prepared.value as PreparedClawclawBehavior), ...(prepared.module ? { module: prepared.module as PreparedClawclawBehavior['module'] } : {}) };
89
89
  }
90
- function createAdapter(deferredDisplay: () => ClawclawResolvedResourceMetadata | undefined, useAdaptiveWorkers: boolean): StrategyAdapter {
90
+ function createAdapter(deferredDisplay: () => ClawclawResolvedResourceMetadata | undefined, useAdaptiveWorkers: boolean,
91
+ assertStartAllowed: (id: string) => void): StrategyAdapter {
92
+ // The CCL adapter receives normalized decisions from both execution modes.
93
+ const checkDelegation = (decision: BehaviorDecision) => {
94
+ if (decision.delegate) {
95
+ const target = decision.delegate;
96
+ assertStartAllowed('strategy' in target ? target.strategy : target.behavior);
97
+ }
98
+ return decision;
99
+ };
91
100
  const observations = new ClawclawBehaviorObservationMemory();
92
101
  return {
93
102
  input: (input, parameters, continuation, history) => {
@@ -121,8 +130,8 @@ function createAdapter(deferredDisplay: () => ClawclawResolvedResourceMetadata |
121
130
  nowMs: input.nowMs, tick: Number(input.gameState.tick ?? input.epochId), cycle: input.cycle, events: input.events }, active)) });
122
131
  return { execution: runner.execution, everyTicks: runner.everyTicks, prepare: () => runner.prepare(),
123
132
  stop: reason => runner.stop(reason), diagnosticSnapshot: () => runner.diagnosticSnapshot(),
124
- decideSerial: (frame, signal, observation) => runner.decideSerial(sdkFrame(frame), signal, observation as ClawclawBehaviorObservationSnapshot),
125
- decideParallel: (frame, signal, observation) => runner.decideParallel(sdkFrame(frame), signal, observation as ClawclawBehaviorObservationSnapshot) };
133
+ decideSerial: (frame, signal, observation) => runner.decideSerial(sdkFrame(frame), signal, observation as ClawclawBehaviorObservationSnapshot).then(checkDelegation),
134
+ decideParallel: (frame, signal, observation) => runner.decideParallel(sdkFrame(frame), signal, observation as ClawclawBehaviorObservationSnapshot).then(checkDelegation) };
126
135
  },
127
136
  action: (action, epoch, safety, generation, tick) => ({ ...normalizeClawclawBehaviorAction(action as GameAction, epoch, safety, generation, tick) }),
128
137
  display: prepared => deferredDisplay() ?? (prepared
@@ -156,11 +165,20 @@ interface DeferredShortControl {
156
165
 
157
166
  export class ClawclawBehaviorPlugin extends StrategyHost {
158
167
  private readonly deferredShort: { control?: DeferredShortControl };
168
+ private readonly catalogAccess: ClawclawBehaviorPluginOptions['catalog'];
169
+ private readonly assertStartAllowed: (id: string) => void;
159
170
 
160
171
  constructor(options: ClawclawBehaviorPluginOptions) {
172
+ const assertStartAllowed = (id: string) => {
173
+ const error = options.catalog.activationError?.(id);
174
+ if (error) throw new Error(error);
175
+ };
176
+ for (const binding of Object.values(options.fallbackBehaviors ?? {})) {
177
+ if (binding) assertStartAllowed(binding.behaviorId);
178
+ }
161
179
  const deferredShort: { control?: DeferredShortControl } = {};
162
180
  super({ ...options, id: CLAWCLAW_BEHAVIOR_PLUGIN_ID, stateTopic: CLAWCLAW_BEHAVIOR_STATE_TOPIC,
163
- actionCapability: CLAWCLAW_ACTION_CAPABILITY, adapter: createAdapter(() => deferredShort.control?.display(), !!options.catalog.prepareForActivation), captureActions: resolveDetailCapture().actions,
181
+ actionCapability: CLAWCLAW_ACTION_CAPABILITY, adapter: createAdapter(() => deferredShort.control?.display(), !!options.catalog.prepareForActivation, assertStartAllowed), captureActions: resolveDetailCapture().actions,
164
182
  catalog: { has: id => options.catalog.has(id), prepare: async (id, input) => {
165
183
  const prepared = await options.catalog.prepare(id, input);
166
184
  return { ...prepared, value: prepared };
@@ -169,6 +187,41 @@ export class ClawclawBehaviorPlugin extends StrategyHost {
169
187
  return { ...prepared, value: prepared, discardWorker: () => prepared.worker?.dispose() };
170
188
  } } : {}) }, after: options.after ?? [CLAWCLAW_ACTION_PLUGIN_ID, CLAWCLAW_GAME_QUERY_PLUGIN_ID, CLAWCLAW_PERCEPTION_PLUGIN_ID, CLAWCLAW_TRIGGER_PLUGIN_ID] });
171
189
  this.deferredShort = deferredShort;
190
+ this.catalogAccess = options.catalog;
191
+ this.assertStartAllowed = assertStartAllowed;
192
+ }
193
+
194
+ startError(id: string): string | undefined {
195
+ return this.catalogAccess.activationError?.(id);
196
+ }
197
+
198
+ override async startLong(id: string, input: Readonly<Record<string, unknown>>, options: StartBehaviorOptions) {
199
+ this.assertStartAllowed(id);
200
+ return super.startLong(id, input, options);
201
+ }
202
+
203
+ override async startShort(id: string, input: Readonly<Record<string, unknown>>, options: StartBehaviorOptions) {
204
+ this.assertStartAllowed(id);
205
+ return super.startShort(id, input, options);
206
+ }
207
+
208
+ override async bindFallback(id: string, input: Readonly<Record<string, unknown>>) {
209
+ this.assertStartAllowed(id);
210
+ return super.bindFallback(id, input);
211
+ }
212
+
213
+ override async configureFallbackBehaviors(bindings: ClawclawRoleFallbackBehaviors, currentRole?: string) {
214
+ for (const binding of Object.values(bindings)) {
215
+ if (binding) this.assertStartAllowed(binding.behaviorId);
216
+ }
217
+ return super.configureFallbackBehaviors(bindings, currentRole);
218
+ }
219
+
220
+ override async requestReflex(request: Readonly<ReflexRequest>, guard?: Readonly<{ isCurrent(): boolean }>): Promise<ReflexResult> {
221
+ if (this.catalogAccess.activationError?.(request.behavior, request)) {
222
+ return { accepted: false, reason: 'activation_ineligible' };
223
+ }
224
+ return super.requestReflex(request, guard);
172
225
  }
173
226
 
174
227
  attachDeferredShortControl(control: DeferredShortControl): void {
@@ -4,7 +4,7 @@ import { preparePerceptionNotification } from './report-content.js';
4
4
  import { isNotificationTurn } from '../../notification-turn.js';
5
5
  import type { RuntimeEpochPluginInput, RuntimeEpochPluginContext } from '../../../framework/plugins/index.js';
6
6
  import { normalizeBehaviorInput } from '../../behavior-input-fields.js';
7
- import { type ReactionBehaviorCandidate } from '../../reaction-behavior-resolution.js';
7
+ import { resolveReactionBehavior, type ReactionBehaviorCandidate } from '../../reaction-behavior-resolution.js';
8
8
  import { clawclawComputationGameState, isClawclawRuntimeState } from '../../runtime-state.js';
9
9
  import { projectTaskChoiceEventPayload } from '../../task-choice-projection.js';
10
10
  import type { ResolvedClawclawPerceptionSource } from './perception-source.js';
@@ -22,7 +22,7 @@ export interface PerceptionModulePluginOptions {
22
22
  /** Unified execution, including verified v2 Reaction consumers, at the source/system observation boundary. */
23
23
  sources: readonly ResolvedClawclawPerceptionSource[];
24
24
  after: readonly string[];
25
- behaviors?: () => readonly ReactionBehaviorCandidate[];
25
+ behaviors?: () => readonly (ReactionBehaviorCandidate & { readonly activationMode?: 'standard' | 'automatic_only' })[];
26
26
  runnerFactory?: (source: ResolvedClawclawPerceptionSource) => Pick<PerceptionModuleRunner, 'start' | 'evaluate' | 'stop'>;
27
27
  }
28
28
  interface GameCheckpoint {
@@ -41,7 +41,7 @@ interface GameCheckpoint {
41
41
  }>;
42
42
  }
43
43
  function sourceValue(source: PerceptionSource): ResolvedClawclawPerceptionSource { return source.value as ResolvedClawclawPerceptionSource; }
44
- function createAdapter(options: PerceptionModulePluginOptions): PerceptionAdapter {
44
+ function createAdapter(options: PerceptionModulePluginOptions, blockedBindings: ReadonlyMap<string, ReadonlySet<string>>): PerceptionAdapter {
45
45
  function prepare(input: RuntimeEpochPluginInput<Record<string, any>>, previous: unknown, context?: RuntimeEpochPluginContext<Record<string, any>>) {
46
46
  const checkpoint = structuredClone(previous ?? { modules: {} }) as GameCheckpoint;
47
47
  // The shipped host checkpoint already has this baseline under flat names.
@@ -103,6 +103,11 @@ function createAdapter(options: PerceptionModulePluginOptions): PerceptionAdapte
103
103
  const { input, game, frame, facts, eventStates, boundary, common } = prepared.value as Prepared;
104
104
  const events = facts.filter(event => source.module.consumes?.includes(event.type));
105
105
  const comparison = comparePerceptionTasks(baseline as PerceptionTaskBaseline | undefined, input, boundary);
106
+ const blocked = blockedBindings.get(source.id);
107
+ if (blocked) {
108
+ bindings = { ...bindings, availableBindings: bindings.availableBindings.filter(key => !blocked.has(key)),
109
+ enabledBindings: bindings.enabledBindings.filter(key => !blocked.has(key)) };
110
+ }
106
111
  const embedded = sourceValue(source).embedded;
107
112
  const declaredTargets = embedded && bindings.availableBindings.length
108
113
  ? Object.values(embedded.declaredManifest.behaviors ?? {}).map(binding => binding.name) : [];
@@ -123,10 +128,32 @@ function createAdapter(options: PerceptionModulePluginOptions): PerceptionAdapte
123
128
  };
124
129
  }
125
130
  export class ClawclawPerceptionModulePlugin extends PerceptionHost {
131
+ private readonly blockedBindings: ReadonlyMap<string, ReadonlySet<string>>;
132
+
126
133
  constructor(options: PerceptionModulePluginOptions) {
127
- super({ id: CLAWCLAW_PERCEPTION_MODULE_PLUGIN_ID, after: options.after, behaviors: options.behaviors, adapter: createAdapter(options),
134
+ // The Owner pins this catalog for the session. Keep external observers and
135
+ // their memory bindings alive even when only the embedded perception may start the strategy.
136
+ const blockedBindings = new Map<string, Set<string>>();
137
+ const candidates = options.behaviors?.() ?? [];
138
+ const automatic = new Set(candidates.filter(entry => entry.activationMode === 'automatic_only').map(entry => entry.id));
139
+ for (const source of options.sources) {
140
+ if (source.embedded) continue;
141
+ const blocked = Object.entries(source.module?.behaviors ?? {}).filter(([, binding]) => {
142
+ const id = resolveReactionBehavior(binding, candidates);
143
+ return id !== undefined && automatic.has(id);
144
+ }).map(([key]) => key);
145
+ if (blocked.length) blockedBindings.set(source.id, new Set(blocked));
146
+ }
147
+ super({ id: CLAWCLAW_PERCEPTION_MODULE_PLUGIN_ID, after: options.after, behaviors: options.behaviors, adapter: createAdapter(options, blockedBindings),
128
148
  sources: options.sources.filter(source => source.module).map(source => ({ id: source.id, name: source.name, module: source.module!, value: source })) });
149
+ this.blockedBindings = blockedBindings;
129
150
  }
151
+
152
+ override bindings(id?: string) {
153
+ return super.bindings(id).map(binding => this.blockedBindings.get(binding.perception_id)?.has(binding.binding)
154
+ ? { ...binding, enabled: false, available: false, reason: 'strategy_automatic_only' } : binding);
155
+ }
156
+
130
157
  override localizedModuleDescriptors(locale: string): ClawclawResolvedResourceMetadata[] {
131
158
  const descriptors = super.localizedModuleDescriptors(locale) as ClawclawResolvedResourceMetadata[];
132
159
  return descriptors.filter(item => !item.id.startsWith('strategy:'));