@myclaw163/clawclaw-cli 0.8.5 → 0.8.7

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 (119) hide show
  1. package/README.md +1 -1
  2. package/docs/configuration.md +2 -1
  3. package/docs/custom-modules/behavior.md +7 -18
  4. package/docs/custom-modules/trigger.md +3 -4
  5. package/docs/runtime/short-commands-and-capabilities.md +1 -1
  6. package/package.json +9 -3
  7. package/scripts/find-hide-spots.py +2 -2
  8. package/skills/clawclaw/SKILL.md +17 -13
  9. package/skills/clawclaw/references/BEHAVIORS.md +13 -9
  10. package/skills/clawclaw/references/COMMANDS.md +17 -29
  11. package/skills/clawclaw/references/TACTICS.md +1 -1
  12. package/src/commands/load.ts +245 -14
  13. package/src/commands/trigger.ts +22 -13
  14. package/src/lib/capability-load-diagnostics.ts +182 -0
  15. package/src/lib/gameplay-config.ts +10 -0
  16. package/src/lib/hub-reminder.ts +3 -5
  17. package/src/lib/trigger-config.ts +2 -10
  18. package/src/runtime/clawclaw/behavior-read-api.ts +1 -1
  19. package/src/{strategies/pathfind → runtime/clawclaw/navigation}/astar-path.ts +1 -1
  20. package/src/{strategies/pathfind → runtime/clawclaw/navigation}/escape-planner.ts +1 -1
  21. package/src/{strategies → runtime/clawclaw/navigation}/hide-spots.ts +2 -2
  22. package/src/{strategies → runtime/clawclaw/navigation}/off-route-points.ts +6 -3
  23. package/src/{strategies/pathfind → runtime/clawclaw/navigation}/walkable-grid.ts +1 -1
  24. package/src/runtime/clawclaw/owner.ts +4 -6
  25. package/src/runtime/clawclaw/plugins/game-query/game-query-plugin.ts +1 -1
  26. package/src/runtime/framework/modules/runtime-module-loader.ts +0 -54
  27. package/src/sdk/behavior-toolkit/escape.ts +2 -2
  28. package/scripts/build-official-hub-behaviors.mjs +0 -136
  29. package/scripts/build-official-hub-behaviors.test.mjs +0 -178
  30. package/scripts/compare-perception-replays.test.ts +0 -188
  31. package/scripts/enable_ccl_permissions.test.mjs +0 -167
  32. package/scripts/enable_monitor.test.mjs +0 -201
  33. package/scripts/sync-bundled-skill.test.mjs +0 -87
  34. package/scripts/watch-perception-events.test.ts +0 -43
  35. package/src/behaviors/official-finite/do-task.ts +0 -211
  36. package/src/behaviors/official-finite/evade.ts +0 -78
  37. package/src/behaviors/official-finite/find-player.ts +0 -50
  38. package/src/behaviors/official-finite/follow-player.ts +0 -70
  39. package/src/behaviors/official-finite/go-to.ts +0 -69
  40. package/src/behaviors/official-finite/hide-temporarily.ts +0 -77
  41. package/src/behaviors/official-finite/hold-position.ts +0 -48
  42. package/src/behaviors/official-finite/hunt-player.ts +0 -47
  43. package/src/behaviors/official-finite/index.ts +0 -44
  44. package/src/behaviors/official-finite/inspect-corpse.ts +0 -64
  45. package/src/behaviors/official-finite/patrol-area.ts +0 -80
  46. package/src/behaviors/official-finite/report-corpse.ts +0 -73
  47. package/src/behaviors/official-finite/seek-kill-opportunity.ts +0 -152
  48. package/src/behaviors/official-finite/shared.ts +0 -27
  49. package/src/hub-official-behaviors/kill-lone.ts +0 -138
  50. package/src/hub-official-behaviors/patrol.ts +0 -30
  51. package/src/hub-official-behaviors/shared.ts +0 -125
  52. package/src/hub-official-behaviors/task-only.ts +0 -158
  53. package/src/runtime/clawclaw/plugins/behavior/official-goal-behavior.ts +0 -757
  54. package/src/strategies/avoid-lone.ts +0 -32
  55. package/src/strategies/avoid-players.ts +0 -43
  56. package/src/strategies/corpse-patrol.ts +0 -50
  57. package/src/strategies/crab-sabotage.ts +0 -48
  58. package/src/strategies/find-player.ts +0 -49
  59. package/src/strategies/game-utils.ts +0 -927
  60. package/src/strategies/goals/anchor-linger.ts +0 -77
  61. package/src/strategies/goals/avoid-lone-top.ts +0 -189
  62. package/src/strategies/goals/avoid-players-top.ts +0 -122
  63. package/src/strategies/goals/conversation-goal.ts +0 -51
  64. package/src/strategies/goals/corpse-patrol-top.ts +0 -120
  65. package/src/strategies/goals/crab-octopus-reflexes.ts +0 -109
  66. package/src/strategies/goals/crab-sabotage-top.ts +0 -139
  67. package/src/strategies/goals/emergency-hunt-goal.ts +0 -40
  68. package/src/strategies/goals/find-player-top.ts +0 -136
  69. package/src/strategies/goals/flee-players-goal.ts +0 -55
  70. package/src/strategies/goals/follow-companion-goal.ts +0 -130
  71. package/src/strategies/goals/goal-manager.ts +0 -41
  72. package/src/strategies/goals/goal-root-strategy.ts +0 -49
  73. package/src/strategies/goals/goal.ts +0 -28
  74. package/src/strategies/goals/hide-top.ts +0 -240
  75. package/src/strategies/goals/keep-away-goal.ts +0 -243
  76. package/src/strategies/goals/kill-frenzy-top.ts +0 -90
  77. package/src/strategies/goals/kill-lone-top.ts +0 -166
  78. package/src/strategies/goals/kill-target-goal.ts +0 -69
  79. package/src/strategies/goals/kill-target-top.ts +0 -121
  80. package/src/strategies/goals/leaf-goal.ts +0 -27
  81. package/src/strategies/goals/linger-corpse-goal.ts +0 -43
  82. package/src/strategies/goals/lone-kill-core.ts +0 -86
  83. package/src/strategies/goals/lone-kill-goal.ts +0 -24
  84. package/src/strategies/goals/lone-kill-task-top.ts +0 -133
  85. package/src/strategies/goals/move-room-goal.ts +0 -102
  86. package/src/strategies/goals/normal-shrimp-top.ts +0 -248
  87. package/src/strategies/goals/paradise-fish-top.ts +0 -234
  88. package/src/strategies/goals/patrol-top.ts +0 -68
  89. package/src/strategies/goals/report-patrol-top.ts +0 -97
  90. package/src/strategies/goals/safe-task-goal.ts +0 -130
  91. package/src/strategies/goals/social-task-top.ts +0 -192
  92. package/src/strategies/goals/task-kill-report-top.ts +0 -187
  93. package/src/strategies/goals/task-only-top.ts +0 -64
  94. package/src/strategies/goals/task-or-patrol-goal.ts +0 -59
  95. package/src/strategies/goals/task-report-top.ts +0 -57
  96. package/src/strategies/goals/wander-task-goal.ts +0 -33
  97. package/src/strategies/goals/warrior-shrimp-top.ts +0 -293
  98. package/src/strategies/greeting.ts +0 -60
  99. package/src/strategies/hide.ts +0 -51
  100. package/src/strategies/kill-frenzy.ts +0 -32
  101. package/src/strategies/kill-lone.ts +0 -52
  102. package/src/strategies/kill-target.ts +0 -48
  103. package/src/strategies/lone-kill-task.ts +0 -48
  104. package/src/strategies/meeting-gate.ts +0 -28
  105. package/src/strategies/move-room.ts +0 -46
  106. package/src/strategies/paradise-fish.ts +0 -70
  107. package/src/strategies/patrol.ts +0 -32
  108. package/src/strategies/player-targets.ts +0 -18
  109. package/src/strategies/report-patrol.ts +0 -32
  110. package/src/strategies/shrimp-memory.ts +0 -87
  111. package/src/strategies/social-task.ts +0 -67
  112. package/src/strategies/speech-module.ts +0 -123
  113. package/src/strategies/task-kill-report.ts +0 -49
  114. package/src/strategies/task-only.ts +0 -34
  115. package/src/strategies/task-report.ts +0 -50
  116. package/src/strategies/types.ts +0 -116
  117. package/src/strategies/warrior-memory.ts +0 -54
  118. /package/src/{strategies/pathfind → runtime/clawclaw/navigation}/clawclaw-walkable.bin +0 -0
  119. /package/src/{strategies/pathfind → runtime/clawclaw/navigation}/distance-field.ts +0 -0
@@ -1,4 +1,5 @@
1
1
  import { Command } from 'commander';
2
+ import { basename, resolve } from 'node:path';
2
3
  import { loadContext } from '../lib/load-context.js';
3
4
  import { AuthStore } from '../lib/auth.js';
4
5
  import { noAccountMessage } from '../lib/account-guidance.js';
@@ -29,6 +30,7 @@ import { PERCEPTION_PLUGIN_API_VERSION } from '../sdk/perception-plugin/index.js
29
30
  import { pluginApiVersionStatus } from '../runtime/clawclaw/plugins/plugin-api-version.js';
30
31
  import {
31
32
  readLocalAgentWorkspaceSnapshot,
33
+ resolveLocalAgentWorkspacePath,
32
34
  resolveLocalAgentWorkspaceSnapshot,
33
35
  syncAgentWorkspaceConfig,
34
36
  type AgentWorkspaceSyncResult,
@@ -40,6 +42,13 @@ import {
40
42
  mergeAgentWorkspaceBehaviorSources,
41
43
  mergeAgentWorkspacePerceptionSources,
42
44
  } from '../lib/agent-workspace-runtime.js';
45
+ import {
46
+ diagnoseRejectedCapabilityModule,
47
+ listCapabilityModuleCandidates,
48
+ warningFromStaticDiagnostic,
49
+ type CapabilityLoadWarning,
50
+ type ModuleCapabilityType,
51
+ } from '../lib/capability-load-diagnostics.js';
43
52
 
44
53
  export interface LoadCommandDependencies {
45
54
  clientFactory?: () => ParticipationStatusClient;
@@ -48,6 +57,56 @@ export interface LoadCommandDependencies {
48
57
  skillSync?: typeof syncAgentWorkspaceSkills;
49
58
  }
50
59
 
60
+ function compatibilityWarning(
61
+ type: ModuleCapabilityType,
62
+ source: 'hub' | 'local',
63
+ value: {
64
+ readonly id: string;
65
+ readonly name: string;
66
+ readonly sourcePath: string;
67
+ readonly management?: {
68
+ readonly resourceId?: string;
69
+ readonly versionId?: string;
70
+ };
71
+ },
72
+ reason: string,
73
+ ): CapabilityLoadWarning {
74
+ return {
75
+ code: 'CAPABILITY_NOT_LOADED',
76
+ capability_type: type,
77
+ source,
78
+ reason,
79
+ stage: 'static_discovery',
80
+ id: value.id,
81
+ name: value.name,
82
+ file: basename(value.sourcePath),
83
+ path: value.sourcePath,
84
+ ...(value.management?.resourceId ? { resource_id: value.management.resourceId } : {}),
85
+ ...(value.management?.versionId ? { version_id: value.management.versionId } : {}),
86
+ };
87
+ }
88
+
89
+ function missingProjectionWarning(
90
+ type: ModuleCapabilityType,
91
+ item: {
92
+ readonly resourceId: string;
93
+ readonly versionId: string;
94
+ readonly sourceFiles: readonly Readonly<{ relativePath: string }>[];
95
+ },
96
+ ): CapabilityLoadWarning {
97
+ return {
98
+ code: 'CAPABILITY_NOT_LOADED',
99
+ capability_type: type,
100
+ source: 'hub',
101
+ reason: 'projection_missing',
102
+ stage: 'projection',
103
+ resource_id: item.resourceId,
104
+ version_id: item.versionId,
105
+ file: item.sourceFiles[0]?.relativePath ?? item.resourceId,
106
+ path: null,
107
+ };
108
+ }
109
+
51
110
  export function createLoadCommand(dependencies: LoadCommandDependencies = {}): Command {
52
111
  return new Command('load')
53
112
  .description('Read active account context, configured gameplay resources, and backend participation')
@@ -87,13 +146,45 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
87
146
  }
88
147
 
89
148
  const gameplay = readGameplayConfig(workspaceDir, profile);
149
+ const capabilityWarnings: CapabilityLoadWarning[] = [];
90
150
  const disabledBehaviors = new Set(gameplay.disabled_behaviors);
91
151
  const hubBehaviors = activeWorkspace
92
152
  ? listAgentWorkspaceBehaviorSources(workspaceDir, profile, activeWorkspace)
93
153
  : [];
94
- const localBehaviors = listClawclawBehaviorSources(
95
- getUserDataAccountBehaviorsDir(workspaceDir, profile),
96
- ).filter(({ id }) => !disabledBehaviors.has(id));
154
+ const localBehaviorDir = getUserDataAccountBehaviorsDir(workspaceDir, profile);
155
+ const allLocalBehaviors = listClawclawBehaviorSources(localBehaviorDir);
156
+ const localBehaviors = allLocalBehaviors.filter(({ id }) => !disabledBehaviors.has(id));
157
+ const localBehaviorSourcePaths = new Set(allLocalBehaviors.map(({ sourcePath }) => resolve(sourcePath)));
158
+ let expectedLocalBehaviors = localBehaviors.length;
159
+ for (const path of listCapabilityModuleCandidates(localBehaviorDir)) {
160
+ if (localBehaviorSourcePaths.has(resolve(path))) continue;
161
+ const diagnostic = diagnoseRejectedCapabilityModule('behavior', path);
162
+ if (diagnostic.declaredId && disabledBehaviors.has(diagnostic.declaredId)) continue;
163
+ expectedLocalBehaviors += 1;
164
+ capabilityWarnings.push(warningFromStaticDiagnostic('behavior', 'local', diagnostic));
165
+ }
166
+ if (activeWorkspace) {
167
+ const discoveredPaths = new Set(hubBehaviors.map(({ sourcePath }) => resolve(sourcePath)));
168
+ for (const item of activeWorkspace.items.strategy) {
169
+ if (!item.runtimeEntryPath) {
170
+ capabilityWarnings.push(missingProjectionWarning('behavior', item));
171
+ continue;
172
+ }
173
+ const path = resolveLocalAgentWorkspacePath(
174
+ workspaceDir,
175
+ profile,
176
+ activeWorkspace,
177
+ item.runtimeEntryPath,
178
+ );
179
+ if (discoveredPaths.has(resolve(path))) continue;
180
+ capabilityWarnings.push(warningFromStaticDiagnostic(
181
+ 'behavior',
182
+ 'hub',
183
+ diagnoseRejectedCapabilityModule('behavior', path),
184
+ { resourceId: item.resourceId, versionId: item.versionId },
185
+ ));
186
+ }
187
+ }
97
188
  const enabledBehaviors = mergeAgentWorkspaceBehaviorSources(
98
189
  localBehaviors,
99
190
  hubBehaviors,
@@ -125,6 +216,19 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
125
216
  const behaviorEntries = enabledBehaviors.map(behaviorEntry);
126
217
  const behaviors = behaviorEntries.filter(({ loadable }) => loadable);
127
218
  const incompatibleBehaviors = behaviorEntries.filter(({ loadable }) => !loadable);
219
+ for (const source of enabledBehaviors) {
220
+ const compatibilityError = behaviorSourceCompatibilityError(source);
221
+ const reason = source.apiVersion === BEHAVIOR_PLUGIN_API_VERSION
222
+ ? compatibilityError
223
+ : `behavior_api_version_unsupported:expected=${BEHAVIOR_PLUGIN_API_VERSION}:received=${source.apiVersion ?? 'missing'}`;
224
+ if (!reason) continue;
225
+ capabilityWarnings.push(compatibilityWarning(
226
+ 'behavior',
227
+ source.management.source,
228
+ source,
229
+ reason,
230
+ ));
231
+ }
128
232
  const configurationWarnings: Array<Record<string, unknown>> = [];
129
233
  for (const role of CLAWCLAW_ROLE_IDS) {
130
234
  const fallback = gameplay.fallback_behaviors[role];
@@ -143,9 +247,42 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
143
247
  ? listAgentWorkspacePerceptionSources(workspaceDir, profile, activeWorkspace)
144
248
  : [];
145
249
  const hubPerceptionIds = new Set(hubPerceptions.map(({ id }) => id));
146
- const localPerceptions = listClawclawPerceptionSourcesInDirectory(
147
- getUserDataAccountPerceptionsDir(workspaceDir, profile),
148
- ).filter(({ id }) => !disabledPerceptions.has(id));
250
+ const localPerceptionDir = getUserDataAccountPerceptionsDir(workspaceDir, profile);
251
+ const allLocalPerceptions = listClawclawPerceptionSourcesInDirectory(localPerceptionDir);
252
+ const localPerceptions = allLocalPerceptions.filter(({ id }) => !disabledPerceptions.has(id));
253
+ const localPerceptionSourcePaths = new Set(
254
+ allLocalPerceptions.map(({ sourcePath }) => resolve(sourcePath)),
255
+ );
256
+ let expectedLocalPerceptions = localPerceptions.length;
257
+ for (const path of listCapabilityModuleCandidates(localPerceptionDir)) {
258
+ if (localPerceptionSourcePaths.has(resolve(path))) continue;
259
+ const diagnostic = diagnoseRejectedCapabilityModule('perception', path);
260
+ if (diagnostic.declaredId && disabledPerceptions.has(diagnostic.declaredId)) continue;
261
+ expectedLocalPerceptions += 1;
262
+ capabilityWarnings.push(warningFromStaticDiagnostic('perception', 'local', diagnostic));
263
+ }
264
+ if (activeWorkspace) {
265
+ const discoveredPaths = new Set(hubPerceptions.map(({ sourcePath }) => resolve(sourcePath)));
266
+ for (const item of activeWorkspace.items.perception) {
267
+ if (!item.runtimeEntryPath) {
268
+ capabilityWarnings.push(missingProjectionWarning('perception', item));
269
+ continue;
270
+ }
271
+ const path = resolveLocalAgentWorkspacePath(
272
+ workspaceDir,
273
+ profile,
274
+ activeWorkspace,
275
+ item.runtimeEntryPath,
276
+ );
277
+ if (discoveredPaths.has(resolve(path))) continue;
278
+ capabilityWarnings.push(warningFromStaticDiagnostic(
279
+ 'perception',
280
+ 'hub',
281
+ diagnoseRejectedCapabilityModule('perception', path),
282
+ { resourceId: item.resourceId, versionId: item.versionId },
283
+ ));
284
+ }
285
+ }
149
286
  const enabledPerceptions = mergeAgentWorkspacePerceptionSources(
150
287
  localPerceptions,
151
288
  hubPerceptions,
@@ -163,14 +300,34 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
163
300
  const incompatiblePerceptions = enabledPerceptions
164
301
  .filter(({ apiVersion }) => apiVersion !== PERCEPTION_PLUGIN_API_VERSION)
165
302
  .map(perceptionEntry);
166
- const triggerSources = listClawclawTriggerSources(
167
- getUserDataAccountTriggersDir(workspaceDir, profile),
168
- );
169
- const enabledTriggers = triggerSources.filter((source) => (
170
- gameplay.triggers[source.id]?.enabled === true
171
- ));
303
+ for (const source of enabledPerceptions) {
304
+ if (source.apiVersion === PERCEPTION_PLUGIN_API_VERSION) continue;
305
+ capabilityWarnings.push(compatibilityWarning(
306
+ 'perception',
307
+ hubPerceptionIds.has(source.id) ? 'hub' : 'local',
308
+ source,
309
+ `perception_api_version_unsupported:expected=${PERCEPTION_PLUGIN_API_VERSION}:received=${source.apiVersion ?? 'missing'}`,
310
+ ));
311
+ }
312
+ const disabledTriggers = new Set(gameplay.disabled_triggers);
313
+ const localTriggerDir = getUserDataAccountTriggersDir(workspaceDir, profile);
314
+ const triggerSources = listClawclawTriggerSources(localTriggerDir);
315
+ const enabledTriggers = triggerSources.filter((source) => !disabledTriggers.has(source.id));
316
+ const triggerSourcePaths = new Set(triggerSources.map(({ sourcePath }) => resolve(sourcePath)));
317
+ let expectedLocalTriggers = enabledTriggers.length;
318
+ for (const path of listCapabilityModuleCandidates(localTriggerDir)) {
319
+ if (triggerSourcePaths.has(resolve(path))) continue;
320
+ const diagnostic = diagnoseRejectedCapabilityModule('trigger', path);
321
+ if (diagnostic.declaredId && disabledTriggers.has(diagnostic.declaredId)) continue;
322
+ expectedLocalTriggers += 1;
323
+ capabilityWarnings.push(warningFromStaticDiagnostic('trigger', 'local', diagnostic));
324
+ }
325
+ const availableBehaviorIds = new Set(behaviors.map(({ id }) => id));
172
326
  const triggerEntry = (source: typeof enabledTriggers[number]) => {
173
- const loadable = source.apiVersion === TRIGGER_PLUGIN_API_VERSION;
327
+ const behaviorId = gameplay.triggers[source.id]?.behavior ?? source.manifest.defaultBehavior;
328
+ const versionCompatible = source.apiVersion === TRIGGER_PLUGIN_API_VERSION;
329
+ const bindingAvailable = availableBehaviorIds.has(behaviorId);
330
+ const loadable = versionCompatible && bindingAvailable;
174
331
  return {
175
332
  id: source.id,
176
333
  name: source.name,
@@ -179,14 +336,26 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
179
336
  expected_api_version: TRIGGER_PLUGIN_API_VERSION,
180
337
  loadable,
181
338
  ...(loadable ? {} : {
182
- compatibility_error: `trigger_api_version_unsupported:expected=${TRIGGER_PLUGIN_API_VERSION}:received=${source.apiVersion}`,
339
+ compatibility_error: versionCompatible
340
+ ? `trigger_binding_unavailable:${behaviorId}`
341
+ : `trigger_api_version_unsupported:expected=${TRIGGER_PLUGIN_API_VERSION}:received=${source.apiVersion}`,
183
342
  }),
343
+ behavior_id: behaviorId,
184
344
  source: 'local',
185
345
  };
186
346
  };
187
347
  const triggerEntries = enabledTriggers.map(triggerEntry);
188
348
  const triggers = triggerEntries.filter(({ loadable }) => loadable);
189
349
  const incompatibleTriggers = triggerEntries.filter(({ loadable }) => !loadable);
350
+ for (const entry of incompatibleTriggers) {
351
+ const source = enabledTriggers.find(({ id }) => id === entry.id)!;
352
+ capabilityWarnings.push(compatibilityWarning(
353
+ 'trigger',
354
+ 'local',
355
+ source,
356
+ String(entry.compatibility_error),
357
+ ));
358
+ }
190
359
 
191
360
  // Mutate Agent-facing Skill/Persona targets only after every non-Skill
192
361
  // source has been parsed and Hub/local identity conflicts have passed.
@@ -197,6 +366,33 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
197
366
  preservedModified: [],
198
367
  requiresUserConfirmation: false,
199
368
  };
369
+ const hubPersonaItem = activeWorkspace?.items.persona[0];
370
+ if (hubPersonaItem && (
371
+ snapshot.persona.source !== 'hub'
372
+ || snapshot.persona.resource_id !== hubPersonaItem.resourceId
373
+ || snapshot.persona.exists !== true
374
+ )) {
375
+ capabilityWarnings.push({
376
+ code: 'CAPABILITY_NOT_LOADED',
377
+ capability_type: 'persona',
378
+ source: 'hub',
379
+ reason: 'persona_file_unavailable',
380
+ stage: 'selection',
381
+ resource_id: hubPersonaItem.resourceId,
382
+ version_id: hubPersonaItem.versionId,
383
+ path: snapshot.persona.path,
384
+ });
385
+ } else if (snapshot.persona.source === 'local' && snapshot.persona.exists !== true) {
386
+ capabilityWarnings.push({
387
+ code: 'CAPABILITY_NOT_LOADED',
388
+ capability_type: 'persona',
389
+ source: 'local',
390
+ reason: 'persona_file_unavailable',
391
+ stage: 'selection',
392
+ ...(snapshot.persona.id ? { id: snapshot.persona.id } : {}),
393
+ path: snapshot.persona.path,
394
+ });
395
+ }
200
396
  let participation;
201
397
  try {
202
398
  const client = (dependencies.clientFactory ?? (() => GameClient.fromAuth()))();
@@ -243,6 +439,41 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
243
439
  },
244
440
  requires_user_confirmation: skillChanges.requiresUserConfirmation,
245
441
  },
442
+ capability_summary: {
443
+ behavior: {
444
+ selected_hub: activeWorkspace?.items.strategy.length ?? 0,
445
+ eligible_local: expectedLocalBehaviors,
446
+ available: behaviors.length,
447
+ warnings: capabilityWarnings.filter(({ capability_type }) => (
448
+ capability_type === 'behavior'
449
+ )).length,
450
+ },
451
+ perception: {
452
+ selected_hub: activeWorkspace?.items.perception.length ?? 0,
453
+ eligible_local: expectedLocalPerceptions,
454
+ available: perceptions.length,
455
+ warnings: capabilityWarnings.filter(({ capability_type }) => (
456
+ capability_type === 'perception'
457
+ )).length,
458
+ },
459
+ trigger: {
460
+ selected_hub: 0,
461
+ eligible_local: expectedLocalTriggers,
462
+ available: triggers.length,
463
+ warnings: capabilityWarnings.filter(({ capability_type }) => (
464
+ capability_type === 'trigger'
465
+ )).length,
466
+ },
467
+ persona: {
468
+ selected_hub: activeWorkspace?.items.persona.length ?? 0,
469
+ selected_local: snapshot.persona.source === 'local' ? 1 : 0,
470
+ available: snapshot.persona.exists ? 1 : 0,
471
+ warnings: capabilityWarnings.filter(({ capability_type }) => (
472
+ capability_type === 'persona'
473
+ )).length,
474
+ },
475
+ },
476
+ capability_warnings: capabilityWarnings,
246
477
  behaviors,
247
478
  incompatible_behaviors: incompatibleBehaviors,
248
479
  perceptions,
@@ -83,6 +83,7 @@ function persistedOverride(id: string, config: GameplayTriggerConfig | undefined
83
83
  function triggerEntry(
84
84
  source: ReturnType<typeof triggerSources>[number],
85
85
  config: GameplayTriggerConfig | undefined,
86
+ disabled = false,
86
87
  ): Record<string, unknown> {
87
88
  const override = persistedOverride(source.id, config);
88
89
  const versionCompatible = source.apiVersion === TRIGGER_PLUGIN_API_VERSION;
@@ -113,7 +114,7 @@ function triggerEntry(
113
114
  },
114
115
  configured: config ?? {},
115
116
  effective: {
116
- enabled: override?.enabled ?? false,
117
+ enabled: !disabled,
117
118
  input,
118
119
  behavior: override?.behavior ?? source.manifest.defaultBehavior,
119
120
  behavior_input: behaviorInput,
@@ -188,7 +189,7 @@ async function tryApplyRuntimeConfig(
188
189
 
189
190
  async function updateTrigger(
190
191
  id: string,
191
- update: (config: GameplayTriggerConfig) => void,
192
+ update: (config: GameplayTriggerConfig, disabled: Set<string>) => void,
192
193
  dependencies: TriggerCommandDependencies,
193
194
  ): Promise<void> {
194
195
  const workspaceDir = getWorkspaceDir();
@@ -197,18 +198,20 @@ async function updateTrigger(
197
198
  if (!source) throw new Error(`Unknown or ambiguous trigger module '${id}'.`);
198
199
  const before = readGameplayConfig(workspaceDir, profile);
199
200
  const nextConfig = { ...(before.triggers[id] ?? {}) };
200
- update(nextConfig);
201
+ const nextDisabled = new Set(before.disabled_triggers);
202
+ update(nextConfig, nextDisabled);
201
203
  const effectiveBehavior = nextConfig.behavior ?? source.manifest.defaultBehavior;
202
- if (nextConfig.enabled === true) assertBehaviorBinding(effectiveBehavior, workspaceDir, profile);
204
+ if (!nextDisabled.has(id)) assertBehaviorBinding(effectiveBehavior, workspaceDir, profile);
203
205
  const updated = updateGameplayConfig((gameplay) => {
204
206
  gameplay.triggers[id] = nextConfig;
207
+ gameplay.disabled_triggers = [...nextDisabled].sort();
205
208
  }, workspaceDir, profile);
206
209
  const config = updated.triggers[id]!;
207
210
  const runtime = await tryApplyRuntimeConfig(id, config, dependencies);
208
211
  console.log(JSON.stringify({
209
212
  trigger: id,
210
213
  config,
211
- effective: triggerEntry(source, config).effective,
214
+ effective: triggerEntry(source, config, updated.disabled_triggers.includes(id)).effective,
212
215
  config_file: getUserDataAccountGameplayConfigFile(workspaceDir, profile),
213
216
  runtime,
214
217
  }, null, 2));
@@ -224,7 +227,7 @@ export function createTriggerCommand(dependencies: TriggerCommandDependencies =
224
227
  const directory = profile
225
228
  ? getUserDataAccountTriggersDir(workspaceDir, profile)
226
229
  : '<active-account>/triggers/local';
227
- return `\nTrigger modules:\n Place .ts or .js files in ${directory}\n Community Triggers are disabled by default and discovery never executes module code.\n`;
230
+ return `\nTrigger modules:\n Place .ts or .js files in ${directory}\n Local Triggers are available by default unless listed in disabled_triggers; discovery never executes module code.\n`;
228
231
  });
229
232
 
230
233
  trigger.addCommand(new Command('list')
@@ -235,7 +238,11 @@ export function createTriggerCommand(dependencies: TriggerCommandDependencies =
235
238
  const gameplay = readGameplayConfig(workspaceDir, profile);
236
239
  const sources = triggerSources(workspaceDir, profile);
237
240
  console.log(JSON.stringify({
238
- triggers: sources.map((source) => triggerEntry(source, gameplay.triggers[source.id])),
241
+ triggers: sources.map((source) => triggerEntry(
242
+ source,
243
+ gameplay.triggers[source.id],
244
+ gameplay.disabled_triggers.includes(source.id),
245
+ )),
239
246
  ignored_config_ids: Object.keys(gameplay.triggers)
240
247
  .filter((id) => !sources.some((source) => source.id === id)),
241
248
  }, null, 2));
@@ -251,7 +258,11 @@ export function createTriggerCommand(dependencies: TriggerCommandDependencies =
251
258
  const gameplay = readGameplayConfig(workspaceDir, profile);
252
259
  const source = triggerSources(workspaceDir, profile).find((candidate) => candidate.id === id);
253
260
  if (!source) throw new Error(`Unknown or ambiguous trigger module '${id}'.`);
254
- console.log(JSON.stringify(triggerEntry(source, gameplay.triggers[id]), null, 2));
261
+ console.log(JSON.stringify(triggerEntry(
262
+ source,
263
+ gameplay.triggers[id],
264
+ gameplay.disabled_triggers.includes(id),
265
+ ), null, 2));
255
266
  }));
256
267
 
257
268
  trigger.addCommand(new Command('enable')
@@ -269,7 +280,7 @@ export function createTriggerCommand(dependencies: TriggerCommandDependencies =
269
280
  workspaceDir,
270
281
  profile,
271
282
  );
272
- await updateTrigger(id, (config) => { config.enabled = true; }, dependencies);
283
+ await updateTrigger(id, (_config, disabled) => { disabled.delete(id); }, dependencies);
273
284
  }));
274
285
 
275
286
  trigger.addCommand(new Command('disable')
@@ -277,7 +288,7 @@ export function createTriggerCommand(dependencies: TriggerCommandDependencies =
277
288
  .argument('<id>', 'Trigger id')
278
289
  .allowExcessArguments(false)
279
290
  .action(async (id: string) => {
280
- await updateTrigger(id, (config) => { config.enabled = false; }, dependencies);
291
+ await updateTrigger(id, (_config, disabled) => { disabled.add(id); }, dependencies);
281
292
  }));
282
293
 
283
294
  trigger.addCommand(new Command('configure')
@@ -296,7 +307,7 @@ export function createTriggerCommand(dependencies: TriggerCommandDependencies =
296
307
  .option('--max-runtime-ms <milliseconds>', 'Maximum Reflex runtime', (value) => (
297
308
  parseSafeInteger(value, 'max-runtime-ms', 1, MAX_TRIGGER_RUNTIME_MS)
298
309
  ))
299
- .option('--reset', 'Clear all overrides except the enabled state')
310
+ .option('--reset', 'Clear all Trigger overrides without changing disabled_triggers')
300
311
  .allowExcessArguments(false)
301
312
  .action(async (id: string, opts: {
302
313
  input?: Record<string, unknown>;
@@ -327,12 +338,10 @@ export function createTriggerCommand(dependencies: TriggerCommandDependencies =
327
338
  assertBehaviorBinding(opts.behavior, getWorkspaceDir(), activeProfile(dependencies));
328
339
  }
329
340
  await updateTrigger(id, (config) => {
330
- const enabled = config.enabled;
331
341
  if (opts.reset) {
332
342
  for (const key of Object.keys(config) as (keyof GameplayTriggerConfig)[]) {
333
343
  delete config[key];
334
344
  }
335
- if (enabled !== undefined) config.enabled = enabled;
336
345
  return;
337
346
  }
338
347
  if (opts.input !== undefined) config.input = opts.input;
@@ -0,0 +1,182 @@
1
+ import {
2
+ existsSync,
3
+ readFileSync,
4
+ readdirSync,
5
+ realpathSync,
6
+ statSync,
7
+ } from 'node:fs';
8
+ import {
9
+ basename,
10
+ dirname,
11
+ isAbsolute,
12
+ join,
13
+ relative,
14
+ } from 'node:path';
15
+
16
+ export type ModuleCapabilityType = 'behavior' | 'perception' | 'trigger';
17
+ export type CapabilitySource = 'hub' | 'local';
18
+
19
+ export type StaticModuleFailureReason =
20
+ | 'projection_missing'
21
+ | 'file_unreadable'
22
+ | 'source_too_large'
23
+ | 'public_sdk_import_required'
24
+ | 'default_export_missing'
25
+ | 'manifest_missing'
26
+ | 'static_manifest_invalid';
27
+
28
+ export interface StaticModuleDiagnostic {
29
+ readonly reason: StaticModuleFailureReason;
30
+ readonly path: string;
31
+ readonly file: string;
32
+ readonly declaredId?: string;
33
+ readonly declaredName?: string;
34
+ readonly expectedImport?: string;
35
+ readonly receivedImports?: readonly string[];
36
+ }
37
+
38
+ export interface CapabilityLoadWarning {
39
+ readonly code: 'CAPABILITY_NOT_LOADED';
40
+ readonly capability_type: 'behavior' | 'perception' | 'trigger' | 'persona';
41
+ readonly source: CapabilitySource;
42
+ readonly reason: string;
43
+ readonly stage: 'projection' | 'static_discovery' | 'selection';
44
+ readonly resource_id?: string;
45
+ readonly version_id?: string;
46
+ readonly id?: string;
47
+ readonly name?: string;
48
+ readonly file?: string;
49
+ readonly path?: string | null;
50
+ readonly expected_import?: string;
51
+ readonly received_imports?: readonly string[];
52
+ }
53
+
54
+ const MAX_SOURCE_BYTES = 2 * 1024 * 1024;
55
+ const MAX_MODULE_FILES = 512;
56
+ const IMPORT_SPECIFIER = /(?:\bfrom\s*|\bimport\s*)["']([^"']+)["']/g;
57
+ const DECLARED_ID = /\bid\s*:\s*["']([^"']+)["']/;
58
+ const DECLARED_NAME = /\bname\s*:\s*["']([^"']+)["']/;
59
+
60
+ const MODULE_CONTRACTS: Record<ModuleCapabilityType, {
61
+ readonly expectedImport: string;
62
+ readonly safeImport: RegExp;
63
+ readonly defaultClass: RegExp;
64
+ readonly manifest: RegExp;
65
+ }> = {
66
+ behavior: {
67
+ expectedImport: '@myclaw163/clawclaw-cli/behavior-plugin',
68
+ safeImport: /(?:@myclaw163\/clawclaw-cli|clawclaw-cli)\/behavior-plugin/,
69
+ defaultClass: /export\s+default\s+class(?:\s+[A-Za-z_$][\w$]*)?\s+extends\s+ClawclawBehavior/,
70
+ manifest: /\bstatic\s+(?:override\s+)?(?:readonly\s+)?manifest\s*=\s*\{/,
71
+ },
72
+ perception: {
73
+ expectedImport: '@myclaw163/clawclaw-cli/perception-plugin',
74
+ safeImport: /(?:@myclaw163\/clawclaw-cli|clawclaw-cli)\/perception-plugin/,
75
+ defaultClass: /export\s+default\s+class(?:\s+[A-Za-z_$][\w$]*)?\s+extends\s+(?:ClawclawPerception|ClawclawParallelPerception)/,
76
+ manifest: /\bstatic\s+(?:readonly\s+)?manifest\s*=\s*\{/,
77
+ },
78
+ trigger: {
79
+ expectedImport: '@myclaw163/clawclaw-cli/trigger-plugin',
80
+ safeImport: /(?:@myclaw163\/clawclaw-cli|clawclaw-cli)\/trigger-plugin|[./]trigger-plugin(?:\.[cm]?[jt]s)?["']/,
81
+ defaultClass: /export\s+default\s+class(?:\s+[A-Za-z_$][\w$]*)?\s+extends\s+ClawclawTrigger/,
82
+ manifest: /\bstatic\s+(?:override\s+)?(?:readonly\s+)?manifest\s*=\s*\{/,
83
+ },
84
+ };
85
+
86
+ function pathInside(root: string, candidate: string): boolean {
87
+ const child = relative(root, candidate);
88
+ return child === '' || (!child.startsWith('..') && !isAbsolute(child));
89
+ }
90
+
91
+ export function listCapabilityModuleCandidates(directory: string): readonly string[] {
92
+ if (!existsSync(directory)) return [];
93
+ try {
94
+ const root = realpathSync(directory);
95
+ return readdirSync(root)
96
+ .filter((file) => (
97
+ !file.startsWith('_')
98
+ && !file.endsWith('.d.ts')
99
+ && !file.endsWith('.test.ts')
100
+ && /\.(?:ts|js)$/.test(file)
101
+ ))
102
+ .sort()
103
+ .slice(0, MAX_MODULE_FILES)
104
+ .flatMap((file) => {
105
+ try {
106
+ const path = realpathSync(join(root, file));
107
+ return pathInside(root, path) && dirname(path) === root ? [path] : [];
108
+ } catch {
109
+ return [];
110
+ }
111
+ });
112
+ } catch {
113
+ return [];
114
+ }
115
+ }
116
+
117
+ export function diagnoseRejectedCapabilityModule(
118
+ type: ModuleCapabilityType,
119
+ path: string,
120
+ ): StaticModuleDiagnostic {
121
+ const contract = MODULE_CONTRACTS[type];
122
+ if (!existsSync(path)) {
123
+ return { reason: 'projection_missing', path, file: basename(path) };
124
+ }
125
+ let source: string;
126
+ try {
127
+ if (!statSync(path).isFile()) throw new Error('not_file');
128
+ source = readFileSync(path, 'utf8');
129
+ } catch {
130
+ return { reason: 'file_unreadable', path, file: basename(path) };
131
+ }
132
+ const declaredId = DECLARED_ID.exec(source)?.[1];
133
+ const declaredName = DECLARED_NAME.exec(source)?.[1];
134
+ const common = {
135
+ path,
136
+ file: basename(path),
137
+ ...(declaredId ? { declaredId } : {}),
138
+ ...(declaredName ? { declaredName } : {}),
139
+ };
140
+ if (Buffer.byteLength(source, 'utf8') > MAX_SOURCE_BYTES) {
141
+ return { ...common, reason: 'source_too_large' };
142
+ }
143
+ if (!contract.safeImport.test(source)) {
144
+ const receivedImports = [...source.matchAll(IMPORT_SPECIFIER)].map((match) => match[1]!);
145
+ return {
146
+ ...common,
147
+ reason: 'public_sdk_import_required',
148
+ expectedImport: contract.expectedImport,
149
+ ...(receivedImports.length === 0 ? {} : { receivedImports }),
150
+ };
151
+ }
152
+ if (!contract.defaultClass.test(source)) {
153
+ return { ...common, reason: 'default_export_missing' };
154
+ }
155
+ if (!contract.manifest.test(source)) {
156
+ return { ...common, reason: 'manifest_missing' };
157
+ }
158
+ return { ...common, reason: 'static_manifest_invalid' };
159
+ }
160
+
161
+ export function warningFromStaticDiagnostic(
162
+ type: ModuleCapabilityType,
163
+ source: CapabilitySource,
164
+ diagnostic: StaticModuleDiagnostic,
165
+ metadata: { readonly resourceId?: string; readonly versionId?: string } = {},
166
+ ): CapabilityLoadWarning {
167
+ return {
168
+ code: 'CAPABILITY_NOT_LOADED',
169
+ capability_type: type,
170
+ source,
171
+ reason: diagnostic.reason,
172
+ stage: diagnostic.reason === 'projection_missing' ? 'projection' : 'static_discovery',
173
+ ...(metadata.resourceId ? { resource_id: metadata.resourceId } : {}),
174
+ ...(metadata.versionId ? { version_id: metadata.versionId } : {}),
175
+ ...(diagnostic.declaredId ? { id: diagnostic.declaredId } : {}),
176
+ ...(diagnostic.declaredName ? { name: diagnostic.declaredName } : {}),
177
+ file: diagnostic.file,
178
+ path: diagnostic.path,
179
+ ...(diagnostic.expectedImport ? { expected_import: diagnostic.expectedImport } : {}),
180
+ ...(diagnostic.receivedImports ? { received_imports: diagnostic.receivedImports } : {}),
181
+ };
182
+ }