@myclaw163/clawclaw-cli 0.8.6 → 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.
- package/docs/configuration.md +2 -1
- package/docs/custom-modules/trigger.md +3 -4
- package/docs/runtime/short-commands-and-capabilities.md +1 -1
- package/package.json +1 -1
- package/skills/clawclaw/SKILL.md +4 -2
- package/skills/clawclaw/references/BEHAVIORS.md +1 -1
- package/skills/clawclaw/references/COMMANDS.md +2 -2
- package/src/commands/load.ts +245 -14
- package/src/commands/trigger.ts +22 -13
- package/src/lib/capability-load-diagnostics.ts +182 -0
- package/src/lib/gameplay-config.ts +10 -0
- package/src/lib/trigger-config.ts +2 -10
- package/src/runtime/clawclaw/owner.ts +4 -6
package/docs/configuration.md
CHANGED
|
@@ -183,6 +183,7 @@ CCL 必须能确定音频格式才会上传。优先使用响应 `Content-Type`
|
|
|
183
183
|
"neutral_octopus": "kill-lone"
|
|
184
184
|
},
|
|
185
185
|
"disabled_behaviors": [],
|
|
186
|
+
"disabled_triggers": [],
|
|
186
187
|
"idle_ms": 500,
|
|
187
188
|
"triggers": {}
|
|
188
189
|
}
|
|
@@ -229,7 +230,7 @@ ccl trigger disable <id>
|
|
|
229
230
|
ccl trigger configure <id> [options]
|
|
230
231
|
```
|
|
231
232
|
|
|
232
|
-
Behavior/Perception enable 变化从下一次 Runtime 生效。
|
|
233
|
+
Behavior/Perception enable 变化从下一次 Runtime 生效。Trigger 与它们一致:默认可用,`ccl trigger disable/enable` 增删顶层 `disabled_triggers`。`triggers[id]` 只保存规则 `input`、固定 `behavior`、`behavior_input`、`reflex_priority`、`cooldown_ms`、`rearm` 和 `max_runtime_ms`;遗留的 `enabled` 字段读取时忽略。fallback、idle 与 Trigger 配置在持久化后会尝试同步到已附着的 Owner;没有 Owner 时在下一次启动生效。
|
|
233
234
|
|
|
234
235
|
这些 list/info/load 命令在判断资源 `loadable` 时只读取源码文本中的静态 Manifest,不 import 或执行源码,也不从 CLI 包同步官方副本。详情见[自定义模块开发](./custom-modules/README.md)。
|
|
235
236
|
|
|
@@ -217,7 +217,6 @@ Trigger 的 Manifest 会被静态扫描器从源码字面量中读取。不要
|
|
|
217
217
|
|
|
218
218
|
| 配置 | 含义 |
|
|
219
219
|
|---|---|
|
|
220
|
-
| `enabled` | 是否评估规则;新社区 Trigger 默认为 `false` |
|
|
221
220
|
| `input` | Trigger 规则参数 |
|
|
222
221
|
| `behavior` | 已审核的固定 Behavior 绑定 |
|
|
223
222
|
| `behavior_input` | 传给该 Behavior 的配置输入 |
|
|
@@ -228,7 +227,7 @@ Trigger 的 Manifest 会被静态扫描器从源码字面量中读取。不要
|
|
|
228
227
|
|
|
229
228
|
`behavior` 是“每个 Trigger 的有效配置固定一个”,不是“永远不可修改”。用户或 Agent 可以通过受控管理入口改变绑定;一次 `evaluate()` 不能越过管理面临时选择另一个 Behavior。
|
|
230
229
|
|
|
231
|
-
上表是 `user-data/gameplay.json`
|
|
230
|
+
上表是 `user-data/gameplay.json` 的 `triggers[id]` 持久化字段,因此使用 snake_case;对应 CLI 选项使用 `--behavior-input`、`--reflex-priority`、`--cooldown-ms` 和 `--max-runtime-ms`。Trigger 默认可用,禁用状态统一保存在顶层 `disabled_triggers`,不放进 Trigger 参数对象。
|
|
232
231
|
|
|
233
232
|
## 安装、配置和观察
|
|
234
233
|
|
|
@@ -238,7 +237,7 @@ Trigger 的 Manifest 会被静态扫描器从源码字面量中读取。不要
|
|
|
238
237
|
<workspace>/user-data/accounts/<account-hash>/triggers/local/
|
|
239
238
|
```
|
|
240
239
|
|
|
241
|
-
先静态查看 Manifest
|
|
240
|
+
先静态查看 Manifest,再按需配置;模块默认可用,也可以显式禁用或恢复:
|
|
242
241
|
|
|
243
242
|
```powershell
|
|
244
243
|
ccl trigger list
|
|
@@ -255,7 +254,7 @@ ccl trigger enable community.untrusted-follower
|
|
|
255
254
|
ccl trigger disable community.untrusted-follower
|
|
256
255
|
```
|
|
257
256
|
|
|
258
|
-
管理命令把配置写入 `user-data/gameplay.json`;存在已附着 Runtime 时会把这份持久配置同步应用,否则在下一次 Runtime 启动时生效。当前没有独立于持久配置的临时 Runtime override。`configure --reset`
|
|
257
|
+
管理命令把配置写入 `user-data/gameplay.json`;存在已附着 Runtime 时会把这份持久配置同步应用,否则在下一次 Runtime 启动时生效。当前没有独立于持久配置的临时 Runtime override。`configure --reset` 清除参数覆盖值但不修改 `disabled_triggers`。
|
|
259
258
|
|
|
260
259
|
启用后用 `ccl behavior status` 观察当前 reflex Activation,并结合它启动的 Behavior lifecycle Event 和诊断判断结果。新增或修改 Trigger 源码、Manifest 后需要重启 Runtime。
|
|
261
260
|
|
|
@@ -48,6 +48,6 @@ CLI
|
|
|
48
48
|
- `ccl behavior status` 返回当前 `reflex > short > long` 栈;`ccl behavior cancel [activation-id]` 取消当前或指定 Activation。
|
|
49
49
|
- `ccl behavior idle <milliseconds>` 持久保存共享 `idle_ms` 并尽量热更新当前 Owner;默认是 500ms。它同时用于 short 结束后交还 long、边界解除后恢复 long,以及 Agent 无新动作时启动角色 fallback。
|
|
50
50
|
- `ccl behavior fallback set|clear` 配置按角色选择的 idle long Behavior。
|
|
51
|
-
- `ccl trigger list|info|enable|disable|configure` 管理只读 Trigger 规则、固定 reflex Behavior 绑定、优先级、冷却、rearm
|
|
51
|
+
- `ccl trigger list|info|enable|disable|configure` 管理只读 Trigger 规则、固定 reflex Behavior 绑定、优先级、冷却、rearm 和最大运行时间。本地 Trigger 默认可用,`disabled_triggers` 统一控制禁用;静态发现不会执行模块源码。
|
|
52
52
|
|
|
53
53
|
Trigger 只根据共享观察帧和后端 Event 请求 reflex,不读取任何计算插件输出;Behavior 才通过 Action capability 执行角色动作。Behavior Action 获得的是本地接纳结果,不等待 HTTP settlement;Behavior 必须从后续权威 State/Event 判断目标是否真正完成。Runtime capability 仍在 Owner 内执行,并经过参数校验、scope 校验、权限检查、超时和取消;模块不能自行访问未声明的外部服务。
|
package/package.json
CHANGED
package/skills/clawclaw/SKILL.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: clawclaw
|
|
3
3
|
description: 默认官方 ClawClaw/龙虾杀 gameplay skill,通过 clawclaw-cli/ccl/myclaw 开始或继续普通匹配、创建或加入好友房,以及进入模拟训练或木桩训练。Use when the user asks to play/start/join/continue a ClawClaw match, friend room, or training room, including “玩一局”“开一局”“再来一局”“玩龙虾杀”“玩 ClawClaw”“玩 myclaw”“创建房间”“加入房间”“好友房”“房间码”“训练一下”“模拟训练”“木桩测试”. If another Hub/local/custom ClawClaw gameplay skill is available, prefer that skill and do not load this official fallback.
|
|
4
|
-
version: 4.8.
|
|
4
|
+
version: 4.8.88
|
|
5
5
|
---
|
|
6
6
|
|
|
7
7
|
# 龙虾杀(ClawClaw)
|
|
@@ -244,6 +244,8 @@ Runtime 使用固定优先级 `reflex > short > long`。服务端角色确定后
|
|
|
244
244
|
|
|
245
245
|
**Behavior 可用性只有一个权威来源:当前账号实时执行的 `ccl behavior list`。** 用户问“有哪些策略/Behavior 可切换”、Agent 要推荐或启动 Behavior、修改 fallback、配置 Trigger 绑定时,都必须先执行该命令;只使用返回中 `loadable: true` 且未禁用的条目。Skill/reference 中的能力说明、命令占位符、旧对局记忆、npm 包文件、源码目录、Runtime loader、Hub 搜索结果和模型知识都不是已安装清单。命令失败时明确说无法确定;成功返回空列表时明确说当前没有可用 Behavior,角色不能执行 Behavior 驱动的移动、任务、等待、跟随或战斗,会 idle/站着不动,但发言、投票和旁白等独立直连命令仍可使用。绝不补出固定/历史列表。`ccl load`、Hub loadout 或本地文件变化后重新查询。
|
|
246
246
|
|
|
247
|
+
`ccl load` 的 `capability_warnings[]` 表示本地应该进入 CCL、且未被相应 `disabled_*` 禁用,但最终未能装载的 Behavior、Perception、Trigger 或 Persona。必须向用户说明具体资源、文件和 `reason`,不能只复述可用列表或把它说成正常未选择;后端没有下发进账号 snapshot 的资源不在 CCL 可诊断范围内。
|
|
248
|
+
|
|
247
249
|
对列表中的候选运行 `ccl behavior info <id>` 查看完整静态 manifest、输入、runtime 和 `fallback_for_roles`。`list/info` 不执行源码,也不从 CLI 包物化官方资源;`loadable` 不等于已经运行。本地 blacklist 只影响纯本地资源,Hub 资源是否启用由 Hub loadout 决定。输入只按 manifest 组装,不猜字段:
|
|
248
250
|
|
|
249
251
|
```bash
|
|
@@ -290,7 +292,7 @@ Behavior manifest 中类型为 `player_seat` 或 `player_seats` 的输入只接
|
|
|
290
292
|
6. `ccl behavior start` 输出只确认 `accepted`。等待 `behavior.completed`、`behavior.failed`、`behavior.cancelled` 或 `behavior.replaced` 再判断终态;中途确需进度时运行 `ccl behavior status`,不要把 status 忙轮询成新的主循环。`behavior.suspended` / `behavior.restarted` 表示高层抢占及新实例恢复,不是完成。
|
|
291
293
|
7. 新事实改变目标时直接启动新的同层 Behavior(旧 Activation 会收到 `behavior.replaced`),或按 activation id 运行 `ccl behavior cancel <activation-id>`。取消只停止后续规划并释放本地控制权;已经交给 Action 模块的请求不能靠取消撤回,后端已接受的移动可能继续到目标。需要接管移动时启动新的移动类 Behavior,并以命令输出和随后权威 State/Event 确认结果。
|
|
292
294
|
8. 给用户简短定期评论:我在哪、当前 Behavior 在做什么、看到了谁、什么变了、下一步准备做什么。需要改变空闲 fallback 时先用 `ccl behavior info <id>` 检查输入;当前 fallback 命令绑定空输入,因此有未满足必填输入的 Behavior 不适合作 fallback。用 `ccl behavior fallback set <id> --role <role>` 持久设置,用 `clear --role <role>` 清除。需要带动态输入持续运行时,直接重新 `start ... --layer long --input ...`,不要寻找已删除的热控制命令。
|
|
293
|
-
9. Trigger 与 Perception 独立读取同一观察帧,只根据该帧和后端推送的 Event 请求固定 Reflex Behavior
|
|
295
|
+
9. Trigger 与 Perception 独立读取同一观察帧,只根据该帧和后端推送的 Event 请求固定 Reflex Behavior,不读取任何计算插件输出。本地 Trigger 与 Behavior/Perception 一样默认可用,只有列入 `disabled_triggers` 才禁用;威胁仍由 Agent 决策。可用 `ccl trigger info/configure/enable/disable` 调整绑定、规则输入、Reflex 优先级、冷却和重装条件,绑定 ID 也必须来自当前 `ccl behavior list`。跨层顺序始终是 `reflex > short > long`;Reflex 优先级只在多个 Reflex 之间比较,只有严格更高的新 Reflex 才会替换正在执行的 Reflex。
|
|
294
296
|
|
|
295
297
|
**游走发言分工:** 角色扮演、说服、指控、会议准备和面向用户的评论是 LLM 决策:`ccl speak` 用于玩家可见发言,`ccl aside` 用于仅用户/观战玩家可见叙述。
|
|
296
298
|
|
|
@@ -117,7 +117,7 @@ ccl trigger disable <id>
|
|
|
117
117
|
ccl trigger configure <id> --reset
|
|
118
118
|
```
|
|
119
119
|
|
|
120
|
-
|
|
120
|
+
本地 Trigger 默认可用,只有列入 `disabled_triggers` 才禁用;参数配置和启停会持久化,并在存在当前 Runtime 时尝试热应用。Trigger 与 Perception 独立读取同一观察帧,只基于该帧和后端推送的 Event 判断规则,不读取任何计算插件输出;命中后只能请求有效配置中固定绑定的 Behavior 和 Reflex 输入。
|
|
121
121
|
|
|
122
122
|
`reflex_priority` 只比较 Reflex,不改变 `reflex > short > long`:
|
|
123
123
|
|
|
@@ -38,7 +38,7 @@ ccl trigger enable <id> # 启用并尝试热应用到当前
|
|
|
38
38
|
ccl trigger disable <id> # 禁用并尝试热应用到当前 Runtime
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
-
`ccl load` 返回账号上下文、`workspace_config`、实际加载资源、`configuration_warnings` 和 `participation
|
|
41
|
+
`ccl load` 返回账号上下文、`workspace_config`、`capability_summary`、实际加载资源、`capability_warnings`、`configuration_warnings` 和 `participation`。`capability_warnings` 必须逐项说明本地应装载但失败的 Behavior、Perception、Trigger 或 Persona 及原因;后端未放进账号 snapshot 的资源不在其中。Hub 来源的本地修改优先使用且不自动上传;同步回 Hub 的入口尚未定义。这些命令只静态读取 Manifest,绝不 import 或执行源码,也不再从 CLI 包物化官方资源。`loadable: true` 不代表模块已经运行。
|
|
42
42
|
|
|
43
43
|
### 注册流程详情
|
|
44
44
|
|
|
@@ -165,7 +165,7 @@ ccl trigger disable <id>
|
|
|
165
165
|
ccl trigger configure <id> --reset
|
|
166
166
|
```
|
|
167
167
|
|
|
168
|
-
|
|
168
|
+
本地 Trigger 默认可用,`ccl trigger disable/enable` 通过 `disabled_triggers` 黑名单持久禁用或恢复;list/info 只静态读取 manifest,不执行源码。参数配置和启停都会在存在当前 Runtime 时尝试热应用。`--behavior` 是该 Trigger 命中后唯一固定请求的 Reflex Behavior;Trigger 不能在每次命中时任意选择模块。Reflex 优先级只比较 Reflex:已有 Reflex 时,只有另一个 Trigger 请求的严格更高优先级 Reflex 才会替换它;相同 Trigger 重复命中或等/低优先级请求都不换。跨层顺序 `reflex > short > long` 不可配置。`after_clear` 要求规则先返回不命中再重新武装;`after_cooldown` 允许持续命中在冷却后再次申请。
|
|
169
169
|
|
|
170
170
|
### 独立沟通与游戏命令
|
|
171
171
|
|
package/src/commands/load.ts
CHANGED
|
@@ -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
|
|
95
|
-
|
|
96
|
-
|
|
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
|
|
147
|
-
|
|
148
|
-
|
|
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
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
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
|
|
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:
|
|
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,
|
package/src/commands/trigger.ts
CHANGED
|
@@ -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:
|
|
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
|
-
|
|
201
|
+
const nextDisabled = new Set(before.disabled_triggers);
|
|
202
|
+
update(nextConfig, nextDisabled);
|
|
201
203
|
const effectiveBehavior = nextConfig.behavior ?? source.manifest.defaultBehavior;
|
|
202
|
-
if (
|
|
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
|
|
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(
|
|
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(
|
|
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, (
|
|
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, (
|
|
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
|
|
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
|
+
}
|
|
@@ -41,6 +41,7 @@ const GAMEPLAY_CONFIG_FIELDS = new Set([
|
|
|
41
41
|
'disabled_perception_modules',
|
|
42
42
|
'fallback_behaviors',
|
|
43
43
|
'disabled_behaviors',
|
|
44
|
+
'disabled_triggers',
|
|
44
45
|
'idle_ms',
|
|
45
46
|
'triggers',
|
|
46
47
|
]);
|
|
@@ -62,6 +63,7 @@ export interface GameplayConfig {
|
|
|
62
63
|
disabled_perception_modules: string[];
|
|
63
64
|
fallback_behaviors: GameplayFallbackBehaviors;
|
|
64
65
|
disabled_behaviors: string[];
|
|
66
|
+
disabled_triggers: string[];
|
|
65
67
|
idle_ms: number;
|
|
66
68
|
triggers: GameplayTriggerConfigs;
|
|
67
69
|
}
|
|
@@ -73,6 +75,7 @@ export function defaultGameplayConfig(): GameplayConfig {
|
|
|
73
75
|
disabled_perception_modules: [],
|
|
74
76
|
fallback_behaviors: { ...NPM_ROLE_FALLBACK_BEHAVIORS },
|
|
75
77
|
disabled_behaviors: [],
|
|
78
|
+
disabled_triggers: [],
|
|
76
79
|
idle_ms: DEFAULT_BEHAVIOR_IDLE_MS,
|
|
77
80
|
triggers: {},
|
|
78
81
|
};
|
|
@@ -165,6 +168,12 @@ export function parseGameplayConfig(value: unknown): GameplayConfig {
|
|
|
165
168
|
root.disabled_behaviors,
|
|
166
169
|
'user-data/gameplay.json disabled_behaviors',
|
|
167
170
|
),
|
|
171
|
+
disabled_triggers: hasOwn(root, 'disabled_triggers')
|
|
172
|
+
? resourceIds(
|
|
173
|
+
root.disabled_triggers,
|
|
174
|
+
'user-data/gameplay.json disabled_triggers',
|
|
175
|
+
)
|
|
176
|
+
: [],
|
|
168
177
|
idle_ms: behaviorIdleMs(root.idle_ms),
|
|
169
178
|
triggers: parseGameplayTriggerConfigs(root.triggers),
|
|
170
179
|
};
|
|
@@ -231,6 +240,7 @@ function migrateLegacyGameplayConfig(root: Record<string, unknown>): GameplayCon
|
|
|
231
240
|
...legacyDisabledStrategies,
|
|
232
241
|
...legacyDisabledIntents,
|
|
233
242
|
],
|
|
243
|
+
disabled_triggers: hasOwn(root, 'disabled_triggers') ? root.disabled_triggers : [],
|
|
234
244
|
idle_ms: migratedIdleMs(root),
|
|
235
245
|
triggers: hasOwn(root, 'triggers') ? root.triggers : {},
|
|
236
246
|
});
|
|
@@ -2,11 +2,7 @@ import { MAX_TRIGGER_RUNTIME_MS } from '../sdk/trigger-plugin/index.js';
|
|
|
2
2
|
|
|
3
3
|
export type GameplayTriggerRearm = 'after_clear' | 'after_cooldown';
|
|
4
4
|
|
|
5
|
-
/** New community Trigger modules are inert until explicitly enabled. */
|
|
6
|
-
export const DEFAULT_GAMEPLAY_TRIGGER_ENABLED = false;
|
|
7
|
-
|
|
8
5
|
export interface GameplayTriggerConfig {
|
|
9
|
-
enabled?: boolean;
|
|
10
6
|
input?: Record<string, unknown>;
|
|
11
7
|
behavior?: string;
|
|
12
8
|
behavior_input?: Record<string, unknown>;
|
|
@@ -25,7 +21,6 @@ export type GameplayTriggerConfigs = Record<string, GameplayTriggerConfig>;
|
|
|
25
21
|
*/
|
|
26
22
|
export interface TriggerRegistrationOverride {
|
|
27
23
|
readonly id: string;
|
|
28
|
-
readonly enabled?: boolean;
|
|
29
24
|
readonly input?: Readonly<Record<string, unknown>>;
|
|
30
25
|
readonly behavior?: string;
|
|
31
26
|
readonly behaviorInput?: Readonly<Record<string, unknown>>;
|
|
@@ -37,6 +32,8 @@ export interface TriggerRegistrationOverride {
|
|
|
37
32
|
|
|
38
33
|
const RESOURCE_ID = /^[a-z0-9][a-z0-9._-]*$/;
|
|
39
34
|
const TRIGGER_FIELDS = new Set([
|
|
35
|
+
// Legacy persisted field: accepted but deliberately ignored. Enablement is
|
|
36
|
+
// controlled only by gameplay.disabled_triggers.
|
|
40
37
|
'enabled',
|
|
41
38
|
'input',
|
|
42
39
|
'behavior',
|
|
@@ -139,9 +136,6 @@ function parseTriggerConfig(value: unknown, field: string): GameplayTriggerConfi
|
|
|
139
136
|
if (unknown.length > 0) {
|
|
140
137
|
throw new Error(`${field} contains unknown fields: ${unknown.sort().join(', ')}.`);
|
|
141
138
|
}
|
|
142
|
-
if (source.enabled !== undefined && typeof source.enabled !== 'boolean') {
|
|
143
|
-
throw new Error(`${field}.enabled must be a boolean.`);
|
|
144
|
-
}
|
|
145
139
|
if (
|
|
146
140
|
source.behavior !== undefined
|
|
147
141
|
&& (typeof source.behavior !== 'string' || !RESOURCE_ID.test(source.behavior))
|
|
@@ -164,7 +158,6 @@ function parseTriggerConfig(value: unknown, field: string): GameplayTriggerConfi
|
|
|
164
158
|
}
|
|
165
159
|
|
|
166
160
|
return {
|
|
167
|
-
...(source.enabled === undefined ? {} : { enabled: source.enabled }),
|
|
168
161
|
...(source.input === undefined ? {} : { input: jsonObject(source.input, `${field}.input`) }),
|
|
169
162
|
...(source.behavior === undefined ? {} : { behavior: source.behavior }),
|
|
170
163
|
...(source.behavior_input === undefined ? {} : {
|
|
@@ -201,7 +194,6 @@ export function toTriggerRegistrationOverrides(
|
|
|
201
194
|
const normalized = parseGameplayTriggerConfigs(configs);
|
|
202
195
|
return Object.entries(normalized).map(([id, config]) => Object.freeze({
|
|
203
196
|
id,
|
|
204
|
-
...(config.enabled === undefined ? {} : { enabled: config.enabled }),
|
|
205
197
|
...(config.input === undefined ? {} : { input: Object.freeze(config.input) }),
|
|
206
198
|
...(config.behavior === undefined ? {} : { behavior: config.behavior }),
|
|
207
199
|
...(config.behavior_input === undefined ? {} : {
|
|
@@ -19,10 +19,7 @@ import {
|
|
|
19
19
|
readGameplayConfig,
|
|
20
20
|
type GameplayConfig,
|
|
21
21
|
} from '../../lib/gameplay-config.js';
|
|
22
|
-
import {
|
|
23
|
-
DEFAULT_GAMEPLAY_TRIGGER_ENABLED,
|
|
24
|
-
toTriggerRegistrationOverrides,
|
|
25
|
-
} from '../../lib/trigger-config.js';
|
|
22
|
+
import { toTriggerRegistrationOverrides } from '../../lib/trigger-config.js';
|
|
26
23
|
import {
|
|
27
24
|
isRoomMode,
|
|
28
25
|
isTrainingRoomMode,
|
|
@@ -292,7 +289,7 @@ export function roleFallbackBehaviors(
|
|
|
292
289
|
|
|
293
290
|
export function triggerRegistrations(
|
|
294
291
|
sources: readonly ResolvedClawclawTriggerSource[],
|
|
295
|
-
config: Pick<GameplayConfig, 'triggers'>,
|
|
292
|
+
config: Pick<GameplayConfig, 'triggers' | 'disabled_triggers'>,
|
|
296
293
|
catalog: Pick<ClawclawBehaviorCatalog, 'list'>,
|
|
297
294
|
warning: ConfigurationWarning = () => {},
|
|
298
295
|
): readonly ClawclawTriggerRegistration[] {
|
|
@@ -302,6 +299,7 @@ export function triggerRegistrations(
|
|
|
302
299
|
const overrides = new Map(
|
|
303
300
|
toTriggerRegistrationOverrides(config.triggers).map((override) => [override.id, override]),
|
|
304
301
|
);
|
|
302
|
+
const disabledTriggers = new Set(config.disabled_triggers);
|
|
305
303
|
const sourceIds = new Set(sources.map((source) => source.id));
|
|
306
304
|
for (const id of overrides.keys()) {
|
|
307
305
|
if (!sourceIds.has(id)) warning('trigger_source_unavailable', { trigger_id: id });
|
|
@@ -309,7 +307,7 @@ export function triggerRegistrations(
|
|
|
309
307
|
return Object.freeze(sources.map((source): ClawclawTriggerRegistration => {
|
|
310
308
|
const override = overrides.get(source.id);
|
|
311
309
|
const behavior = override?.behavior ?? source.manifest.defaultBehavior;
|
|
312
|
-
const requestedEnabled =
|
|
310
|
+
const requestedEnabled = !disabledTriggers.has(source.id);
|
|
313
311
|
const enabled = requestedEnabled
|
|
314
312
|
&& source.apiVersion === TRIGGER_PLUGIN_API_VERSION
|
|
315
313
|
&& loadableBehaviors.has(behavior);
|