@myclaw163/clawclaw-cli 0.10.15 → 0.10.16

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 (50) hide show
  1. package/README.md +1 -1
  2. package/cli-runtime/runtime/clawclaw/behavior-reflex-control.js +27 -36
  3. package/cli-runtime/runtime/clawclaw/behavior-trigger.js +25 -46
  4. package/cli-runtime/runtime/clawclaw/owner.js +7 -6
  5. package/cli-runtime/runtime/clawclaw/plugins/assembly.js +8 -7
  6. package/cli-runtime/runtime/clawclaw/plugins/behavior/behavior-source.js +6 -5
  7. package/cli-runtime/runtime/clawclaw/plugins/perception/perception-module-plugin.js +5 -2
  8. package/cli-runtime/runtime/clawclaw/plugins/perception/perception-module-runner.js +2 -1
  9. package/cli-runtime/runtime/clawclaw/plugins/perception/perception-module-worker.js +7 -1
  10. package/cli-runtime/runtime/clawclaw/plugins/perception/perception-module-worker.ts +7 -1
  11. package/cli-runtime/runtime/clawclaw/plugins/trigger/trigger-module-loader.js +7 -17
  12. package/cli-runtime/runtime/clawclaw/plugins/trigger/trigger-plugin.js +3 -30
  13. package/cli-runtime/runtime/clawclaw/plugins/trigger/trigger-thread-worker.js +0 -2
  14. package/cli-runtime/runtime/clawclaw/plugins/trigger/trigger-thread-worker.ts +0 -2
  15. package/dist/strategy-worker/runtime/clawclaw/plugins/behavior/host.js +58 -1
  16. package/docs/custom-modules/README.md +1 -2
  17. package/docs/custom-modules/api-reference.md +8 -10
  18. package/docs/custom-modules/behavior.md +21 -23
  19. package/docs/custom-modules/examples/auto-escape.ts +17 -19
  20. package/docs/custom-modules/perception.md +2 -2
  21. package/docs/runtime/README.md +1 -1
  22. package/docs/runtime/behavior-runtime.md +4 -5
  23. package/docs/runtime/components-and-boundaries.md +4 -5
  24. package/docs/runtime/events-and-state.md +1 -1
  25. package/docs/runtime/owner-lifecycle-and-observability.md +2 -2
  26. package/docs/user-guide/README.md +1 -1
  27. package/docs/user-guide/api-reference.md +8 -10
  28. package/docs/user-guide/behavior.md +21 -23
  29. package/docs/user-guide/perception.md +2 -2
  30. package/package.json +1 -1
  31. package/skills/clawclaw/SKILL.md +3 -3
  32. package/skills/clawclaw/references/BEHAVIORS.md +1 -1
  33. package/skills/clawclaw-creator/SKILL.md +1 -1
  34. package/skills/clawclaw-creator/references/CUSTOM-BEHAVIOR-DEVELOPMENT.md +21 -23
  35. package/skills/clawclaw-creator/references/CUSTOM-MODULE-API.md +8 -10
  36. package/skills/clawclaw-creator/references/CUSTOM-MODULES.md +1 -2
  37. package/skills/clawclaw-creator/references/CUSTOM-PERCEPTION-DEVELOPMENT.md +2 -2
  38. package/src/runtime/clawclaw/behavior-reflex-control.ts +26 -22
  39. package/src/runtime/clawclaw/behavior-trigger.ts +20 -41
  40. package/src/runtime/clawclaw/owner.ts +7 -6
  41. package/src/runtime/clawclaw/plugins/assembly.ts +11 -8
  42. package/src/runtime/clawclaw/plugins/behavior/behavior-source.ts +7 -6
  43. package/src/runtime/clawclaw/plugins/perception/perception-module-plugin.ts +6 -2
  44. package/src/runtime/clawclaw/plugins/perception/perception-module-runner.ts +2 -1
  45. package/src/runtime/clawclaw/plugins/perception/perception-module-worker.ts +7 -1
  46. package/src/runtime/clawclaw/plugins/perception/perception-source.ts +1 -0
  47. package/src/runtime/clawclaw/plugins/trigger/trigger-module-loader.ts +8 -19
  48. package/src/runtime/clawclaw/plugins/trigger/trigger-plugin.ts +4 -37
  49. package/src/runtime/clawclaw/plugins/trigger/trigger-source.ts +0 -2
  50. package/src/runtime/clawclaw/plugins/trigger/trigger-thread-worker.ts +0 -2
package/README.md CHANGED
@@ -53,7 +53,7 @@ ccl game quit # 退出当前匹配、房间或游戏
53
53
 
54
54
  ## 自定义模块
55
55
 
56
- 策略资源默认导出 Strategy 执行类,可在同文件具名导出 Trigger。内置 Trigger 判断反射条件,感知持续观察并组织通知。 装配一个反射策略就能使用本局实时改参和开关。策略使用 ClawclawStrategy,感知使用 Perception API v3。
56
+ 策略资源默认导出 Strategy 执行类,可在同文件具名导出继承 ClawclawPerception 的 Trigger。感知插件运行该类并判断反射条件,感知持续观察并组织通知。 装配一个反射策略就能使用本局实时改参和开关。策略使用 ClawclawStrategy,感知使用 Perception API v3。
57
57
 
58
58
  npm 包提供龙虾杀接入、公共 SDK 和官方 Agent Skill,通过 `@myclaw163/game-agent-runtime` 提供通用运行机制。官方模块、第三方模块和玩家自己的线上模块由当前账号 Hub loadout 获取,纯本地模块由玩家自行创建。实际可用内容以本次 `ccl load` 和对应的 `list` 命令为准。保存或同步源码后,下次正常启动 Runtime 时加载生效。
59
59
 
@@ -1,43 +1,27 @@
1
1
  import { normalizeBehaviorInput } from "./behavior-input-fields.js";
2
2
  const same = (a, b) => a.sessionId === b.sessionId && a.segmentId === b.segmentId;
3
3
  class BehaviorReflexControl {
4
- constructor(modules, behavior, catalog, scope, triggers) {
4
+ constructor(modules, behavior, catalog, scope, embedded = []) {
5
5
  this.modules = modules;
6
6
  this.behavior = behavior;
7
7
  this.catalog = catalog;
8
8
  this.scope = scope;
9
- this.triggers = triggers;
9
+ this.embedded = embedded;
10
10
  }
11
11
  modules;
12
12
  behavior;
13
13
  catalog;
14
14
  scope;
15
- triggers;
15
+ embedded;
16
16
  parameters = /* @__PURE__ */ new Map();
17
17
  currentScope;
18
18
  tail = Promise.resolve();
19
- embedded(id) {
20
- return (this.triggers?.descriptors() ?? []).filter((item) => item.embedded && (id === void 0 || item.behavior === id));
21
- }
22
19
  status(id) {
23
20
  this.refreshScope();
24
21
  const active = this.behavior.status().stack.reflex;
25
- const embedded = this.embedded(id).map((item) => ({
26
- source: "strategy",
27
- behavior_id: item.behavior,
28
- trigger_id: item.id,
29
- available: true,
30
- enabled: item.enabled,
31
- waiting_for_input: item.waitingForInput,
32
- armed: item.armed,
33
- cooldown_remaining_ms: item.cooldownRemainingMs,
34
- priority: item.reflexPriority,
35
- cooldown_ms: item.cooldownMs,
36
- rearm: item.rearm,
37
- max_runtime_ms: item.maxRuntimeMs
38
- }));
39
- return [...embedded, ...this.modules?.bindings(id) ?? []].map((binding) => ({
22
+ return (this.modules?.bindings(id) ?? []).map((binding) => ({
40
23
  ...binding,
24
+ ...this.embedded.some((source) => source.id === binding.perception_id) ? { source: "strategy", behavior_id: binding.id, config: this.modules?.status(binding.perception_id)[0]?.input } : {},
41
25
  active: active?.triggerId === binding.trigger_id,
42
26
  ...active?.triggerId === binding.trigger_id ? {
43
27
  activation_id: active.activationId,
@@ -63,8 +47,7 @@ class BehaviorReflexControl {
63
47
  if (!guard()) throw Error("stale_runtime_scope");
64
48
  const entry = this.catalog.list().find((entry2) => entry2.id === id);
65
49
  if (!entry) throw Error("behavior_not_found");
66
- const embedded = this.embedded(id)[0];
67
- if (operation !== "update" && !embedded) {
50
+ if (operation !== "update") {
68
51
  const bindings = this.modules?.bindings(id) ?? [];
69
52
  if (!bindings.length || operation === "enable" && !bindings.some((binding) => binding.available)) {
70
53
  throw Error("perception_binding_unavailable");
@@ -72,23 +55,31 @@ class BehaviorReflexControl {
72
55
  }
73
56
  let input = this.parameters.get(id) ?? {}, updated = 0;
74
57
  if (operation === "update" || Object.keys(patch).length) {
75
- input = normalizeBehaviorInput({ ...input, ...patch }, entry.inputs);
76
- updated = await this.behavior.configureInput(
77
- id,
78
- input,
79
- patch,
80
- guard,
81
- () => {
58
+ const source = this.embedded.find((source2) => source2.embedded?.strategyId === id);
59
+ const fields = source?.module?.inputs ?? [];
60
+ const detectorPatch = {};
61
+ const executionPatch = {};
62
+ for (const [key, value] of Object.entries(patch)) {
63
+ const observed = fields.some((field) => field.id === key);
64
+ if (observed) detectorPatch[key] = value;
65
+ if (!observed || entry.inputs.some((field) => field.id === key)) executionPatch[key] = value;
66
+ }
67
+ const configureDetector = () => {
68
+ if (source && Object.keys(detectorPatch).length) this.modules?.configure(source.id, detectorPatch, guard);
69
+ };
70
+ if (Object.keys(executionPatch).length || !Object.keys(detectorPatch).length) {
71
+ input = normalizeBehaviorInput({ ...input, ...executionPatch }, entry.inputs);
72
+ updated = await this.behavior.configureInput(id, input, executionPatch, guard, () => {
73
+ configureDetector();
82
74
  this.parameters.set(id, input);
83
- this.triggers?.configureEmbedded(id, { input });
84
75
  this.modules?.behaviorInputChanged(id);
85
- }
86
- );
76
+ });
77
+ } else {
78
+ configureDetector();
79
+ }
87
80
  }
88
81
  if (operation !== "update") {
89
- if (!guard()) throw Error("stale_runtime_scope");
90
- if (embedded) this.triggers?.configureEmbedded(id, { enabled: operation === "enable" });
91
- const triggerIds = embedded ? [embedded.id] : this.modules?.setWatch(id, operation === "enable", guard);
82
+ const triggerIds = this.modules?.setWatch(id, operation === "enable", guard);
92
83
  if (!triggerIds) throw Error("perception_binding_unavailable");
93
84
  if (operation === "disable") for (const triggerId of triggerIds) {
94
85
  updated += Number(await this.behavior.updateReflex(triggerId, void 0, guard));
@@ -1,59 +1,38 @@
1
- import {
2
- MAX_TRIGGER_RUNTIME_MS,
3
- TRIGGER_PLUGIN_API_VERSION
4
- } from "../../sdk/trigger-plugin/index.js";
5
- const fields = /* @__PURE__ */ new Set([
6
- "apiVersion",
7
- "consumes",
8
- "defaultReflexPriority",
9
- "defaultCooldownMs",
10
- "defaultRearm",
11
- "defaultMaxRuntimeMs"
12
- ]);
13
- function normalizeStrategyTriggerManifest(value) {
14
- const manifest = value;
15
- if (!manifest || typeof manifest !== "object" || Array.isArray(manifest) || manifest.apiVersion !== TRIGGER_PLUGIN_API_VERSION || Object.keys(manifest).some((key) => !fields.has(key))) {
16
- throw new Error("strategy_trigger_manifest_invalid");
1
+ import { normalizePerceptionModuleManifest } from "./perception-module-manifest.js";
2
+ function normalizeStrategyPerception(value, strategyId) {
3
+ const manifest = normalizePerceptionModuleManifest(value);
4
+ const bindings = Object.values(manifest.behaviors ?? {});
5
+ if (!bindings.length || bindings.some((binding) => binding.name !== strategyId || binding.resourceId !== void 0)) {
6
+ throw Error("strategy_perception_self_binding_required");
17
7
  }
18
- const consumes = manifest.consumes === void 0 ? [] : manifest.consumes;
19
- if (!Array.isArray(consumes) || consumes.some((type) => typeof type !== "string" || !/^(?:\\*|[a-z0-9][a-z0-9._-]*)$/.test(type)) || new Set(consumes).size !== consumes.length) {
20
- throw new Error("strategy_trigger_consumes_invalid");
21
- }
22
- const {
23
- defaultReflexPriority = 0,
24
- defaultCooldownMs = 1e3,
25
- defaultRearm = "after_clear",
26
- defaultMaxRuntimeMs = 1e4
27
- } = manifest;
28
- if (!Number.isSafeInteger(defaultReflexPriority) || !Number.isSafeInteger(defaultCooldownMs) || defaultCooldownMs < 0 || defaultRearm !== "after_clear" && defaultRearm !== "after_cooldown" || !Number.isSafeInteger(defaultMaxRuntimeMs) || defaultMaxRuntimeMs < 1 || defaultMaxRuntimeMs > MAX_TRIGGER_RUNTIME_MS) {
29
- throw new Error("strategy_trigger_defaults_invalid");
30
- }
31
- return {
32
- apiVersion: TRIGGER_PLUGIN_API_VERSION,
33
- consumes: [...consumes],
34
- defaultReflexPriority,
35
- defaultCooldownMs,
36
- defaultRearm,
37
- defaultMaxRuntimeMs
38
- };
8
+ return manifest;
39
9
  }
40
10
  function strategyTriggerSource(source) {
41
11
  if (!source.trigger) return void 0;
42
- const { name, description, sourcePath, sourceRoot, inputs } = source;
43
- const id = "behavior:" + source.id;
44
12
  const { manifest, sha256 } = source.trigger;
13
+ const id = "strategy:" + source.id;
14
+ const name = manifest.name ?? manifest.id;
15
+ const behaviors = Object.fromEntries(Object.entries(manifest.behaviors).map(([key, binding]) => [key, { ...binding, name: source.id }]));
45
16
  return {
46
- apiVersion: manifest.apiVersion,
47
17
  id,
48
18
  name,
49
- description,
50
- sourcePath,
51
- sourceRoot,
52
- embedded: { manifest, sha256 },
53
- manifest: { ...manifest, id, name, description, inputs, defaultBehavior: source.id, defaultBehaviorInput: {} }
19
+ description: manifest.description,
20
+ apiVersion: 3,
21
+ sourcePath: source.sourcePath,
22
+ sourceRoot: source.sourceRoot,
23
+ embedded: { strategyId: source.id, sha256, declaredManifest: manifest },
24
+ module: { ...manifest, behaviors },
25
+ manifest: {
26
+ apiVersion: 2,
27
+ id,
28
+ name,
29
+ description: manifest.description,
30
+ subjectScope: "self_and_others",
31
+ produces: manifest.produces ?? []
32
+ }
54
33
  };
55
34
  }
56
35
  export {
57
- normalizeStrategyTriggerManifest,
36
+ normalizeStrategyPerception,
58
37
  strategyTriggerSource
59
38
  };
@@ -485,9 +485,8 @@ async function runClawclawOwner(options) {
485
485
  reason: source2.triggerError
486
486
  });
487
487
  const trigger = strategyTriggerSource(source2);
488
- return trigger ? [{ source: trigger, enabled: true }] : [];
488
+ return trigger ? [trigger] : [];
489
489
  });
490
- const triggers = [...legacyTriggers, ...embeddedTriggers];
491
490
  const disabledPerceptions = new Set(gameplayConfig.disabled_perception_modules);
492
491
  const agentPerceptionSources = agentWorkspace ? listAgentWorkspacePerceptionSources(workspaceDir, options.profile, agentWorkspace) : [];
493
492
  const localPerceptionSources = discoveredLocalCapabilities.perceptions.filter(({ source: source2, entry }) => entry.selection === "equipped" && !disabledPerceptions.has(source2.id) && !agentWorkspace?.items.perception.some((item) => item.resourceId === entry.hub?.resourceId)).map(({ source: source2 }) => source2);
@@ -513,7 +512,8 @@ async function runClawclawOwner(options) {
513
512
  triggerDiagnosticsEnabled: fullDiagnosticsEnabled,
514
513
  fallbackBehaviors,
515
514
  behaviorEventTypes,
516
- triggers
515
+ triggers: legacyTriggers,
516
+ embeddedPerceptions: embeddedTriggers
517
517
  });
518
518
  await assembly.behavior.setIdleMs(gameplayConfig.idle_ms);
519
519
  const epochPlugins = assembly.plugins;
@@ -528,7 +528,7 @@ async function runClawclawOwner(options) {
528
528
  assembly.behavior,
529
529
  behaviorCatalog,
530
530
  () => runtime.publicScope(),
531
- assembly.trigger
531
+ embeddedTriggers
532
532
  );
533
533
  const runtimeDone = startupSpan("owner.runtime_init");
534
534
  runtime = createClawclawRuntime(options.profile, {
@@ -595,7 +595,7 @@ async function runClawclawOwner(options) {
595
595
  } : null
596
596
  },
597
597
  perception: assembly.perception.diagnosticSnapshot(),
598
- trigger: assembly.trigger.diagnosticSnapshot()
598
+ trigger: assembly.trigger?.diagnosticSnapshot()
599
599
  }, {
600
600
  component: "runtime.diagnostics",
601
601
  scope: runtime?.publicScope()
@@ -611,7 +611,7 @@ async function runClawclawOwner(options) {
611
611
  throw new Error("The configured Runtime repository does not support durable Mailbox delivery.");
612
612
  }
613
613
  const mailboxRepository = runtime.repository;
614
- const perceptionSourceById = new Map(perceptionSources.map((source2) => [source2.id, source2]));
614
+ const perceptionSourceById = new Map([...perceptionSources, ...embeddedTriggers].map((source2) => [source2.id, source2]));
615
615
  const perceptionReportAdapter = new GameSyncPerceptionReportAdapter({
616
616
  producerPluginIds: [assembly.perception.id, assembly.reminders.id, ...assembly.modules ? [assembly.modules.id] : []],
617
617
  descriptor: (id) => {
@@ -1157,6 +1157,7 @@ async function runClawclawOwner(options) {
1157
1157
  if (!currentTriggerSources.some((source2) => source2.id === request.trigger)) {
1158
1158
  return { ok: false, type: "trigger_configure", error: "trigger_source_unavailable" };
1159
1159
  }
1160
+ if (!assembly.trigger) return { ok: false, type: request.type, error: "trigger_runtime_restart_required" };
1160
1161
  assembly.trigger.configure(triggerRegistrations(
1161
1162
  currentTriggerSources,
1162
1163
  latest,
@@ -79,14 +79,15 @@ function assembleClawclawPlugins(client, options = {}) {
79
79
  if (configuredTrigger && !(configuredTrigger instanceof ClawclawTriggerPlugin)) {
80
80
  throw new Error(`Runtime Plugin ${CLAWCLAW_TRIGGER_PLUGIN_ID} is not a ClawclawTriggerPlugin.`);
81
81
  }
82
- const trigger = configuredTrigger ?? new ClawclawTriggerPlugin({
82
+ const trigger = configuredTrigger ?? (options.triggers?.length ? new ClawclawTriggerPlugin({
83
83
  after: [],
84
84
  triggers: options.triggers,
85
85
  diagnosticsEnabled: options.triggerDiagnosticsEnabled
86
- });
87
- if (!configuredTrigger) plugins.push(trigger);
88
- const modules = moduleSources.length ? new ClawclawPerceptionModulePlugin({
89
- sources: moduleSources,
86
+ }) : void 0);
87
+ if (trigger && !configuredTrigger) plugins.push(trigger);
88
+ const sources = [...moduleSources, ...options.embeddedPerceptions ?? []];
89
+ const modules = sources.length ? new ClawclawPerceptionModulePlugin({
90
+ sources,
90
91
  after: [],
91
92
  behaviors: () => options.behaviorCatalog?.list?.() ?? []
92
93
  }) : void 0;
@@ -111,11 +112,11 @@ function assembleClawclawPlugins(client, options = {}) {
111
112
  });
112
113
  if (!configuredBehavior) plugins.push(behavior);
113
114
  const strategyMemory = new ClawclawStrategyMemory();
114
- trigger.attachMemory(strategyMemory);
115
+ trigger?.attachMemory(strategyMemory);
115
116
  behavior.attachMemory(strategyMemory);
116
117
  modules?.attachMemory(strategyMemory);
117
118
  modules?.attachDriver(behavior);
118
- trigger.attachDriver(behavior);
119
+ trigger?.attachDriver(behavior);
119
120
  action.attachAgentActivity(() => {
120
121
  void behavior.noteAgentActivity().catch(() => {
121
122
  });
@@ -15,7 +15,7 @@ import {
15
15
  hasValidClawclawResourceLocalizations
16
16
  } from "../../../../sdk/behavior-plugin/index.js";
17
17
  import { parseLiteralBehaviorInputFields, parseLiteralModuleManifest } from "../behavior-input-source.js";
18
- import { normalizeStrategyTriggerManifest } from "../../behavior-trigger.js";
18
+ import { normalizeStrategyPerception } from "../../behavior-trigger.js";
19
19
  import {
20
20
  behaviorProducesDiagnostic,
21
21
  deepFreezeBehaviorValue,
@@ -26,7 +26,7 @@ const MAX_BEHAVIOR_SOURCE_BYTES = 2 * 1024 * 1024;
26
26
  const SAFE_IMPORT = /(?:\bfrom\s*|\bimport\s*)["'](?:@myclaw163\/clawclaw-cli|clawclaw-cli)\/(?:behavior|strategy)-plugin["']/;
27
27
  const DEFAULT_CLASS = /export\s+default\s+class(?:\s+[A-Za-z_$][\w$]*)?\s+extends\s+Clawclaw(?:Behavior|Strategy)(?:\s*<[\s\S]{0,4000}?>)?\s*\{/;
28
28
  const NAMED_TRIGGER = /export\s+class\s+Trigger\b/;
29
- const TRIGGER_CLASS = /^export\s+class\s+Trigger\s+extends\s+ClawclawTrigger(?:\s*<[\s\S]{0,4000}?>)?\s*\{/;
29
+ const TRIGGER_CLASS = /^export\s+class\s+Trigger\s+extends\s+ClawclawPerception(?:\s*<[\s\S]{0,4000}?>)?\s*\{/;
30
30
  const STATIC_MANIFEST = /\bstatic\s+(?:override\s+)?(?:readonly\s+)?manifest\s*=\s*\{/;
31
31
  const BEHAVIOR_ID = /^[a-z0-9][a-z0-9._-]*$/;
32
32
  const MANIFEST_FIELDS = /* @__PURE__ */ new Set([
@@ -462,10 +462,11 @@ function inspectClawclawBehaviorSource(sourcePath, sourceRoot) {
462
462
  if (namedTrigger) {
463
463
  try {
464
464
  const match = TRIGGER_CLASS.exec(masked.slice(namedTrigger.index));
465
- if (match) match.index = namedTrigger.index;
466
- const literal = match && classManifest(source, match);
465
+ if (!match) throw Error("strategy_trigger_requires_perception_v3");
466
+ match.index = namedTrigger.index;
467
+ const literal = classManifest(source, match);
467
468
  trigger = {
468
- manifest: normalizeStrategyTriggerManifest(literal && parseLiteralModuleManifest(literal)),
469
+ manifest: normalizeStrategyPerception(literal && parseLiteralModuleManifest(literal), compatible.id),
469
470
  sha256: createHash("sha256").update(source).digest("hex")
470
471
  };
471
472
  } catch (error) {
@@ -94,6 +94,8 @@ function createAdapter(options) {
94
94
  const { input, game, frame, facts, eventStates, boundary, common } = prepared.value;
95
95
  const events = facts.filter((event) => source.module.consumes?.includes(event.type));
96
96
  const comparison = comparePerceptionTasks(baseline, input, boundary);
97
+ const embedded = sourceValue(source).embedded;
98
+ const declaredTargets = embedded && bindings.availableBindings.length ? Object.values(embedded.declaredManifest.behaviors ?? {}).map((binding) => binding.name) : [];
97
99
  const moduleInput = {
98
100
  ...common,
99
101
  moduleId: source.id,
@@ -107,7 +109,7 @@ function createAdapter(options) {
107
109
  state,
108
110
  config,
109
111
  ...bindings,
110
- availableStrategies: bindings.availableBehaviors,
112
+ availableStrategies: [.../* @__PURE__ */ new Set([...bindings.availableBehaviors, ...declaredTargets])],
111
113
  taskChanges: comparison.changes,
112
114
  boundary
113
115
  };
@@ -134,7 +136,8 @@ class ClawclawPerceptionModulePlugin extends PerceptionHost {
134
136
  });
135
137
  }
136
138
  localizedModuleDescriptors(locale) {
137
- return super.localizedModuleDescriptors(locale);
139
+ const descriptors = super.localizedModuleDescriptors(locale);
140
+ return descriptors.filter((item) => !item.id.startsWith("strategy:"));
138
141
  }
139
142
  }
140
143
  export {
@@ -5,7 +5,8 @@ class PerceptionModuleRunner extends PerceptionWorker {
5
5
  constructor(source, bindMemory) {
6
6
  super({ compatibilityError: source.compatibilityError, workerData: {
7
7
  modulePath: source.sourcePath,
8
- expectedManifest: source.module,
8
+ expectedManifest: source.embedded?.declaredManifest ?? source.module,
9
+ embeddedSha256: source.embedded?.sha256,
9
10
  legacy: !!source.reaction,
10
11
  runtimeModuleBootstrap: {
11
12
  hostUrl: new URL("./perception-module-worker.ts", import.meta.url).href,
@@ -1,3 +1,5 @@
1
+ import { createHash } from "node:crypto";
2
+ import { readFileSync } from "node:fs";
1
3
  import { pathToFileURL } from "node:url";
2
4
  import { runPerceptionWorker } from "@myclaw163/game-agent-runtime/perception/perception-worker-host.js";
3
5
  import { ClawclawPerception, ClawclawReaction } from "../../../../sdk/perception-plugin/index.js";
@@ -5,7 +7,11 @@ import { normalizePerceptionModuleManifest } from "../../perception-module-manif
5
7
  import { normalizeReactionManifest } from "../../reaction-manifest.js";
6
8
  import { CLAWCLAW_PERCEPTION_SPATIAL_API } from "./spatial-facts.js";
7
9
  await runPerceptionWorker(async (data) => {
8
- const Module = (await import(pathToFileURL(data.modulePath).href)).default;
10
+ if (data.embeddedSha256 && createHash("sha256").update(readFileSync(data.modulePath)).digest("hex") !== data.embeddedSha256) {
11
+ throw Error("strategy_perception_source_changed");
12
+ }
13
+ const exports = await import(pathToFileURL(data.modulePath).href);
14
+ const Module = data.embeddedSha256 ? exports.Trigger : exports.default;
9
15
  if (!(Module?.prototype instanceof (data.legacy ? ClawclawReaction : ClawclawPerception)) || Module.prototype.evaluate === ClawclawPerception.prototype.evaluate) throw Error("PERCEPTION_MODULE_CLASS_INVALID");
10
16
  const legacy = data.legacy ? normalizeReactionManifest(Module.manifest) : void 0;
11
17
  const { kind: _kind, ...common } = legacy ?? {};
@@ -1,3 +1,5 @@
1
+ import { createHash } from 'node:crypto';
2
+ import { readFileSync } from 'node:fs';
1
3
  import { pathToFileURL } from 'node:url';
2
4
  import { runPerceptionWorker } from '@myclaw163/game-agent-runtime/perception/perception-worker-host.js';
3
5
  import { ClawclawPerception, ClawclawReaction } from '../../../../sdk/perception-plugin/index.js';
@@ -7,7 +9,11 @@ import { normalizeReactionManifest } from '../../reaction-manifest.js';
7
9
  import { CLAWCLAW_PERCEPTION_SPATIAL_API } from './spatial-facts.js';
8
10
 
9
11
  await runPerceptionWorker<PerceptionModuleInput>(async data => {
10
- const Module = (await import(pathToFileURL(data.modulePath).href)).default;
12
+ if (data.embeddedSha256 && createHash('sha256').update(readFileSync(data.modulePath)).digest('hex') !== data.embeddedSha256) {
13
+ throw Error('strategy_perception_source_changed');
14
+ }
15
+ const exports = await import(pathToFileURL(data.modulePath).href);
16
+ const Module = data.embeddedSha256 ? exports.Trigger : exports.default;
11
17
  if (!(Module?.prototype instanceof (data.legacy ? ClawclawReaction : ClawclawPerception))
12
18
  || Module.prototype.evaluate === ClawclawPerception.prototype.evaluate) throw Error('PERCEPTION_MODULE_CLASS_INVALID');
13
19
  const legacy = data.legacy ? normalizeReactionManifest(Module.manifest) : undefined;
@@ -1,5 +1,5 @@
1
- import { createHash, randomUUID } from "node:crypto";
2
- import { readFileSync, realpathSync } from "node:fs";
1
+ import { randomUUID } from "node:crypto";
2
+ import { realpathSync } from "node:fs";
3
3
  import { isDeepStrictEqual } from "node:util";
4
4
  import { pathToFileURL } from "node:url";
5
5
  import {
@@ -11,7 +11,6 @@ import {
11
11
  importRuntimeModule,
12
12
  runtimeModuleThreadLoaderConfig
13
13
  } from "../../../framework/modules/runtime-module-loader.js";
14
- import { normalizeStrategyTriggerManifest } from "../../behavior-trigger.js";
15
14
  import { assertPluginApiVersion } from "../plugin-api-version.js";
16
15
  function normalizedManifest(value) {
17
16
  if (!value || typeof value !== "object" || Array.isArray(value)) {
@@ -50,22 +49,17 @@ function normalizedManifest(value) {
50
49
  return structuredClone({ ...manifest, inputs });
51
50
  }
52
51
  function validateClawclawTriggerModule(loaded, source) {
53
- const entry = source.embedded ? "Trigger" : "default";
52
+ const entry = "default";
54
53
  if (typeof loaded[entry] !== "function") {
55
- throw new Error(`Trigger module '${source.id}' has no ${entry} class.`);
54
+ throw new Error(`Trigger module '${source.id}' has no default class.`);
56
55
  }
57
56
  const ModuleClass = loaded[entry];
58
- const manifest = source.embedded ? normalizeStrategyTriggerManifest(ModuleClass.manifest) : normalizedManifest(ModuleClass.manifest);
59
- if (!isDeepStrictEqual(manifest, source.embedded?.manifest ?? source.manifest)) {
57
+ const manifest = normalizedManifest(ModuleClass.manifest);
58
+ if (!isDeepStrictEqual(manifest, source.manifest)) {
60
59
  throw new Error(`Trigger module '${source.id}' changed after static discovery.`);
61
60
  }
62
61
  return ModuleClass;
63
62
  }
64
- function assertTriggerSourceDigest(source) {
65
- if (source.embedded && createHash("sha256").update(readFileSync(source.sourcePath)).digest("hex") !== source.embedded.sha256) {
66
- throw new Error("strategy_trigger_source_changed");
67
- }
68
- }
69
63
  class TriggerModuleLoader {
70
64
  runtimeId = randomUUID();
71
65
  loaded = /* @__PURE__ */ new Map();
@@ -92,10 +86,7 @@ class TriggerModuleLoader {
92
86
  }
93
87
  let pending = this.loaded.get(source.id);
94
88
  if (pending) return pending;
95
- pending = Promise.resolve().then(() => {
96
- assertTriggerSourceDigest(source);
97
- return importRuntimeModule(new URL(this.sourceUrl(source)));
98
- }).then((loaded) => validateClawclawTriggerModule(loaded, source));
89
+ pending = importRuntimeModule(new URL(this.sourceUrl(source))).then((loaded) => validateClawclawTriggerModule(loaded, source));
99
90
  this.loaded.set(source.id, pending);
100
91
  return pending;
101
92
  }
@@ -110,6 +101,5 @@ class TriggerModuleLoader {
110
101
  }
111
102
  export {
112
103
  TriggerModuleLoader,
113
- assertTriggerSourceDigest,
114
104
  validateClawclawTriggerModule
115
105
  };
@@ -1,4 +1,3 @@
1
- import { isDeepStrictEqual } from "node:util";
2
1
  import { isNotificationTurn } from "../../notification-turn.js";
3
2
  import {
4
3
  MAX_TRIGGER_RUNTIME_MS,
@@ -51,8 +50,7 @@ function normalizeRegistration(value) {
51
50
  const { source } = value;
52
51
  const manifest = source.manifest;
53
52
  if (!source || source.id !== manifest.id) throw new Error("trigger_source_identity_invalid");
54
- const input = source.embedded || value.enabled ? normalizeBehaviorInput(value.input ?? {}, manifest.inputs, { allowMissingRequired: !!source.embedded }) : Object.freeze(structuredClone(value.input ?? {}));
55
- const waitingForInput = !!source.embedded && manifest.inputs.some((field) => field.required && !Object.hasOwn(input, field.id));
53
+ const input = value.enabled ? normalizeBehaviorInput(value.input ?? {}, manifest.inputs) : Object.freeze(structuredClone(value.input ?? {}));
56
54
  const behavior = value.behavior ?? manifest.defaultBehavior;
57
55
  const behaviorInput = {
58
56
  ...structuredClone(manifest.defaultBehaviorInput),
@@ -74,7 +72,6 @@ function normalizeRegistration(value) {
74
72
  return Object.freeze({
75
73
  source,
76
74
  enabled: value.enabled,
77
- waitingForInput,
78
75
  scope: value.scope,
79
76
  input,
80
77
  behavior,
@@ -145,7 +142,6 @@ class ClawclawTriggerPlugin {
145
142
  timeoutMs = DEFAULT_TRIGGER_PLUGIN_TIMEOUT_MS;
146
143
  failurePolicy = "failed_completion";
147
144
  registrations;
148
- embeddedDefaults;
149
145
  pendingActivations = /* @__PURE__ */ new Map();
150
146
  invalidInputs = /* @__PURE__ */ new Map();
151
147
  loader;
@@ -165,7 +161,7 @@ class ClawclawTriggerPlugin {
165
161
  configGeneration = 1;
166
162
  currentScope;
167
163
  isEnabled(config) {
168
- return config.enabled && !config.waitingForInput && (!config.scope || config.scope.sessionId === this.currentScope?.sessionId && config.scope.segmentId === this.currentScope?.segmentId);
164
+ return config.enabled && (!config.scope || config.scope.sessionId === this.currentScope?.sessionId && config.scope.segmentId === this.currentScope?.segmentId);
169
165
  }
170
166
  started = false;
171
167
  lastFrameSeq = 0;
@@ -176,7 +172,6 @@ class ClawclawTriggerPlugin {
176
172
  this.memory = options.memory ?? new ClawclawStrategyMemory();
177
173
  this.after = [...options.after ?? []];
178
174
  this.registrations = normalizeRegistrations(options.triggers ?? []);
179
- this.embeddedDefaults = new Map([...this.registrations].filter(([, config]) => config.source.embedded));
180
175
  this.loader = options.loader ?? new TriggerModuleLoader();
181
176
  this.driver = options.driver;
182
177
  this.threaded = options.threaded ?? options.loader === void 0;
@@ -192,25 +187,6 @@ class ClawclawTriggerPlugin {
192
187
  }
193
188
  configure(triggers) {
194
189
  const next = normalizeRegistrations(triggers);
195
- for (const [id, config] of this.registrations) if (config.source.embedded) next.set(id, config);
196
- this.replaceRegistrations(next);
197
- }
198
- configureEmbedded(behaviorId, patch) {
199
- const id = "behavior:" + behaviorId;
200
- const config = this.registrations.get(id);
201
- if (!config?.source.embedded) return;
202
- const updated = normalizeRegistration({
203
- source: config.source,
204
- enabled: patch.enabled ?? config.enabled,
205
- input: patch.input ?? config.input
206
- });
207
- if (isDeepStrictEqual(config, updated)) return;
208
- const next = new Map(this.registrations);
209
- next.set(id, updated);
210
- this.replaceRegistrations(next);
211
- }
212
- /** Replace effective config and invalidate computations from the previous generation. */
213
- replaceRegistrations(next) {
214
190
  for (const [id, config] of next) {
215
191
  if (config.enabled && !this.registrations.get(id)?.enabled) {
216
192
  const state = this.states.get(id);
@@ -237,8 +213,6 @@ class ClawclawTriggerPlugin {
237
213
  return [...this.registrations.values()].map((entry) => Object.freeze({
238
214
  id: entry.source.id,
239
215
  enabled: this.isEnabled(entry),
240
- waitingForInput: entry.waitingForInput,
241
- embedded: !!entry.source.embedded,
242
216
  armed: this.states.get(entry.source.id)?.armed ?? true,
243
217
  cooldownRemainingMs: Math.max(0, entry.cooldownMs - (Date.now() - (this.states.get(entry.source.id)?.lastAcceptedAtMs ?? 0))),
244
218
  behavior: entry.behavior,
@@ -652,7 +626,6 @@ class ClawclawTriggerPlugin {
652
626
  this.states.clear();
653
627
  this.pendingActivations.clear();
654
628
  this.invalidInputs.clear();
655
- for (const [id, config] of this.embeddedDefaults) this.registrations.set(id, config);
656
629
  this.observationMemory.clear();
657
630
  this.clearFrameBoundary();
658
631
  this.threadPool = void 0;
@@ -662,7 +635,7 @@ class ClawclawTriggerPlugin {
662
635
  this.loader.stop();
663
636
  }
664
637
  memoryNamespace(source) {
665
- return source.embedded ? source.id : "trigger:" + source.id;
638
+ return "trigger:" + source.id;
666
639
  }
667
640
  async ensureThreadPool(context) {
668
641
  if (!this.started || this.threadPool || this.threadPoolFailed) return;
@@ -3,7 +3,6 @@ import { createBehaviorReadApi } from "../../behavior-read-api.js";
3
3
  import { ClawclawBehaviorObservationMemory } from "../../behavior-observation-memory.js";
4
4
  import { assertRuntimeModuleOutputSize } from "../../../framework/modules/runtime-module-output.js";
5
5
  import {
6
- assertTriggerSourceDigest,
7
6
  validateClawclawTriggerModule
8
7
  } from "./trigger-module-loader.js";
9
8
  import { StrategyMemoryRpcClient } from "../../strategy-memory-rpc.js";
@@ -38,7 +37,6 @@ const modules = /* @__PURE__ */ new Map();
38
37
  const observationMemories = /* @__PURE__ */ new Map();
39
38
  try {
40
39
  for (const spec of data.modules) {
41
- assertTriggerSourceDigest(spec.source);
42
40
  const loaded = await import(spec.sourceUrl);
43
41
  const ModuleClass = validateClawclawTriggerModule(loaded, spec.source);
44
42
  classes.set(spec.triggerId, ModuleClass);
@@ -10,7 +10,6 @@ import { createBehaviorReadApi } from '../../behavior-read-api.js';
10
10
  import { ClawclawBehaviorObservationMemory } from '../../behavior-observation-memory.js';
11
11
  import { assertRuntimeModuleOutputSize } from '../../../framework/modules/runtime-module-output.js';
12
12
  import {
13
- assertTriggerSourceDigest,
14
13
  validateClawclawTriggerModule,
15
14
  type TriggerThreadModuleSpec,
16
15
  } from './trigger-module-loader.js';
@@ -79,7 +78,6 @@ const modules = new Map<string, ClawclawTrigger>();
79
78
  const observationMemories = new Map<string, ClawclawBehaviorObservationMemory>();
80
79
  try {
81
80
  for (const spec of data.modules) {
82
- assertTriggerSourceDigest(spec.source);
83
81
  const loaded = await import(spec.sourceUrl) as Record<string, unknown>;
84
82
  const ModuleClass = validateClawclawTriggerModule(loaded, spec.source);
85
83
  classes.set(spec.triggerId, ModuleClass);