@myclaw163/clawclaw-cli 0.7.14 → 0.7.15
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/runtime/strategy-runtime.md +1 -1
- package/docs//350/207/252/345/256/232/344/271/211/347/255/226/347/225/245.md +4 -4
- package/package.json +1 -1
- package/skills/clawclaw/SKILL.md +2 -2
- package/skills/clawclaw/references/COMMANDS.md +1 -1
- package/skills/clawclaw/references/STRATEGIES.md +4 -4
- package/src/lib/strategy-export.test.ts +13 -0
- package/src/runtime/clawclaw/plugins/strategy/strategy-module-loader.ts +1 -1
- package/src/runtime/clawclaw/plugins/strategy/strategy-plugin.test.ts +22 -0
- package/src/runtime/clawclaw/plugins/strategy/strategy-plugin.ts +14 -5
- package/src/sdk/index.ts +2 -2
- package/src/sdk/strategy-plugin/index.test.ts +10 -4
- package/src/sdk/strategy-plugin/index.ts +13 -2
- package/src/strategies/avoid-players.ts +4 -5
- package/src/strategies/find-player.ts +5 -6
- package/src/strategies/game-utils.test.ts +22 -0
- package/src/strategies/game-utils.ts +12 -39
- package/src/strategies/goals/avoid-players-top.test.ts +2 -2
- package/src/strategies/goals/avoid-players-top.ts +1 -1
- package/src/strategies/goals/crab-octopus-reflexes.ts +10 -10
- package/src/strategies/goals/find-player-top.ts +7 -8
- package/src/strategies/goals/kill-lone-top.test.ts +27 -2
- package/src/strategies/goals/kill-lone-top.ts +16 -12
- package/src/strategies/goals/kill-target-goal.ts +3 -3
- package/src/strategies/goals/kill-target-top.test.ts +66 -0
- package/src/strategies/goals/kill-target-top.ts +4 -6
- package/src/strategies/goals/normal-shrimp-top.test.ts +2 -2
- package/src/strategies/goals/normal-shrimp-top.ts +3 -3
- package/src/strategies/goals/paradise-fish-top.test.ts +3 -3
- package/src/strategies/goals/paradise-fish-top.ts +2 -2
- package/src/strategies/goals/social-task-top.ts +3 -3
- package/src/strategies/goals/task-kill-report-top.ts +2 -2
- package/src/strategies/goals/warrior-shrimp-top.test.ts +3 -3
- package/src/strategies/goals/warrior-shrimp-top.ts +11 -7
- package/src/strategies/kill-lone.ts +7 -12
- package/src/strategies/kill-target.ts +5 -6
- package/src/strategies/paradise-fish.ts +8 -8
- package/src/strategies/player-targets.ts +0 -8
- package/src/strategies/shrimp-memory.ts +13 -13
- package/src/strategies/social-task.ts +4 -4
- package/src/strategies/task-kill-report.ts +5 -5
- package/src/strategies/warrior-memory.ts +7 -12
|
@@ -92,7 +92,7 @@ ccl strategy --control '{"parameterName": "value"}'
|
|
|
92
92
|
|
|
93
93
|
`getTasks()` 本身不会发 HTTP。Source 只把 GameSync `you.tasks` 写入 State,不轮询 `/map`,也不从增量任务 Event 猜完整列表。字段不可用时,`getTasks()` 抛出 `authoritative_tasks_unavailable`,而不是把缺失解释成空列表。官方 Goal 策略此时会把 `strategy.status.dataAvailability.tasks` 标为 `unavailable`,并继续执行巡逻、避人或猎杀等不依赖任务的分支;不会拿全任务点冒充自己的任务。`getMap()` 的静态部分包括房间多边形和全任务点;它不是动态 State 的替代品。策略应只在需要地图几何时查询并缓存,而不是每次更新重复拉取。
|
|
94
94
|
|
|
95
|
-
玩家分类和策略偏好全部通过 `manifest.controls` 的命名参数进入策略实例或并行计算参数快照。`
|
|
95
|
+
玩家分类和策略偏好全部通过 `manifest.controls` 的命名参数进入策略实例或并行计算参数快照。`player_seats` 使用 1-10 的 JSON 整数数组表示完整当前座位名单,不接受字符串座位号或玩家名;关联名单可由一条 `ccl strategy --control <JSON>` 原子更新。Goal tree 只在 effective parameters 实际变化时重建,普通 `update()` 复用同一实例和规划状态。
|
|
96
96
|
|
|
97
97
|
## Action
|
|
98
98
|
|
|
@@ -286,7 +286,7 @@ event-only 边界不会复用旧 State 调用策略实例或提交并行计算
|
|
|
286
286
|
|
|
287
287
|
CCL 使用随包的碰撞膨胀 walkability grid,在本地执行 A*。返回路径长度;不可达时返回 `null`。它不请求后端、不自动移动,也不需要用户安装 Python、原生库或单独配置地图服务。
|
|
288
288
|
|
|
289
|
-
玩家分类和其他可调判断应声明在 `manifest.controls` 中,由 Agent 通过 `ccl strategy --control <JSON>` 显式传入。玩家名单使用 `
|
|
289
|
+
玩家分类和其他可调判断应声明在 `manifest.controls` 中,由 Agent 通过 `ccl strategy --control <JSON>` 显式传入。玩家名单使用 `player_seats`,值为 1-10 的 JSON 整数数组,代表完整当前座位名单;字符串座位号和玩家名不会被接受。传 `[]` 清空;需要原子变更的敌对/保护名单应放在同一条 JSON 中。策略从构造参数和 `applyControl()` 的 effective values 读取这些值,不访问 CCL 的本地判断文件。
|
|
290
290
|
|
|
291
291
|
## Action
|
|
292
292
|
|
|
@@ -297,9 +297,9 @@ CCL 使用随包的碰撞膨胀 walkability grid,在本地执行 A*。返回
|
|
|
297
297
|
| `move` | 移动到房间名或坐标 | `target`,或者 `target_x + target_y`;二选一 |
|
|
298
298
|
| `task` | 在当前位置开始任务 | 可选 `task_name` |
|
|
299
299
|
| `speech` | 发送游戏发言 | `text` |
|
|
300
|
-
| `kill` | 击杀目标 | `
|
|
300
|
+
| `kill` | 击杀目标 | `target_seat` 数字座位号 |
|
|
301
301
|
| `report` | 报告附近尸体 | 无额外字段 |
|
|
302
|
-
| `vote` | 会议投票 | `
|
|
302
|
+
| `vote` | 会议投票 | `target_seat` 数字座位号 |
|
|
303
303
|
| `trigger_alarm` | 发起紧急会议 | 无额外字段 |
|
|
304
304
|
| `think` | 提交无游戏副作用的思考动作 | 可选 `thinking_content` |
|
|
305
305
|
|
|
@@ -346,7 +346,7 @@ applyControl(update: StrategyControlUpdate): StrategyControlResult {
|
|
|
346
346
|
ccl strategy --control '{"greeting":"又见面了,{player}"}'
|
|
347
347
|
```
|
|
348
348
|
|
|
349
|
-
支持的 control 类型是 `string`、`boolean`、`number`、`enum`、`
|
|
349
|
+
支持的 control 类型是 `string`、`boolean`、`number`、`enum`、`player_seats`、`string_list`。`player_seats` 只接受 1-10 的 JSON 整数数组。控制请求不创建 epoch。串行策略在下一次实际 `update()` 前把更新交给同一实例;`parallel_compute` 先校验并冻结新参数快照,从下一份 `compute()` 使用,同时使旧参数 generation 的在途结果失效;`parallel_analyze` 在 ordered reducer 接受后切换 generation,旧 analyzer 结果不得归并。未在 manifest 声明的字段不应成为 Agent 的控制入口。
|
|
350
350
|
|
|
351
351
|
## 给 Agent 的策略状态
|
|
352
352
|
|
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 or friend 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.79
|
|
5
5
|
---
|
|
6
6
|
|
|
7
7
|
# 龙虾杀(ClawClaw)
|
|
@@ -258,7 +258,7 @@ ccl aside "<仅用户/观战玩家可见的推理>"
|
|
|
258
258
|
4. 裸 `ccl events` 使用 `ccl.events.v5`,只返回 `schema`、当前 `state` 和当前 participation session 在固定 Ready View 下的全部未读 `events`。每个 Event 只有命中 CCL Hint Registry 时才有英文模板生成的 `hint`;未登记就没有该属性。响应没有 `mode`、`events[].notice`、批次 `next_step` 或 gameplay `guidance`。未读选择、查询方式、固定水位和 stdout 成功后的确认都由 Mailbox 内部处理,不作为 Agent 字段输出。`ccl events --backlog` 跳过查询边界,读取当前已经 ready 的未读内容;旧 session 不补发。
|
|
259
259
|
5. 在做出身份、联盟、不在场证明、路线或“谁之前出现过”判断时,结合本轮已经收到的独立 visual Events;不要把缺少某类 Event 当成相应行为没有发生。
|
|
260
260
|
6. 给用户简短定期评论:我在哪、策略在做什么、看到了谁、什么变了、下一步可能切换什么。
|
|
261
|
-
7. 当战略目标变化时干预:切换策略、发言或使用 `ccl aside` 向用户说明。调整前先运行 `ccl strategy --info <id>`;`controls: []` 表示没有可调参数,否则按 `controls[].id/type/values/default/description` 组装 `ccl strategy --control '<JSON>'
|
|
261
|
+
7. 当战略目标变化时干预:切换策略、发言或使用 `ccl aside` 向用户说明。调整前先运行 `ccl strategy --info <id>`;`controls: []` 表示没有可调参数,否则按 `controls[].id/type/values/default/description` 组装 `ccl strategy --control '<JSON>'`。玩家分类只通过当前策略声明的 `huntTargets`、`protectedTargets`、`hostileTargets`、`trustedTargets` 等 `player_seats` 参数传入,必须使用 1-10 的 JSON 整数数组(例如 `{"huntTargets":[6]}`),不得传字符串座位号或玩家名;数组表示该字段的完整当前名单,清空传 `[]`,相关名单尽量在同一条 JSON 中原子更新。控制成功后从下一次 `ccl events` 的 `state.strategy.params` 核对有效参数。
|
|
262
262
|
8. 让策略继续处理常规游走、任务、跟随、报告和冷却节奏。
|
|
263
263
|
|
|
264
264
|
**游走发言分工:** 角色扮演、说服、指控、会议准备和面向用户的评论是 LLM 决策:`ccl speak` 用于玩家可见发言,`ccl aside` 用于仅用户/观战玩家可见叙述。
|
|
@@ -101,7 +101,7 @@ ccl game watch # 后端事件没给 URL 时,本地拼接兜
|
|
|
101
101
|
# 结算仅在整局结束后可用
|
|
102
102
|
```
|
|
103
103
|
|
|
104
|
-
策略参数必须先通过 `ccl strategy --info <id>` 获取。`controls: []` 表示无参数;否则按每项的 `id` 作为 JSON 键,按 `type` 传值,`enum` 只能使用 `values`,`
|
|
104
|
+
策略参数必须先通过 `ccl strategy --info <id>` 获取。`controls: []` 表示无参数;否则按每项的 `id` 作为 JSON 键,按 `type` 传值,`enum` 只能使用 `values`,`player_seats` 使用 1-10 的 JSON 整数数组(如 `[6]`),`string_list` 使用字符串数组。`player_seats` 不接受字符串座位号或玩家名。`default` 仅在返回时存在才可依赖。玩家座位数组表示完整当前名单,清空传 `[]`;有关联的名单放在同一条 `--control` JSON 中更新。`--control` 只更新当前活动策略;成功后从下一次 `ccl events` 的 `state.strategy.params` 核对有效参数。
|
|
105
105
|
|
|
106
106
|
## 匹配模式
|
|
107
107
|
|
|
@@ -29,12 +29,12 @@ ccl strategy --info <id>
|
|
|
29
29
|
`--info` 返回 `id`、`name`、`description`、`disabled`、`default_for_roles` 和 `controls`。每个 control 使用:
|
|
30
30
|
|
|
31
31
|
- `id`:传给 `--control` 的 JSON 键。
|
|
32
|
-
- `type`:`string`、`boolean`、`number`、`enum`、`
|
|
32
|
+
- `type`:`string`、`boolean`、`number`、`enum`、`player_seats` 或 `string_list`。
|
|
33
33
|
- `description`:是否必填、数量限制、玩家引用/房间格式等约束。
|
|
34
34
|
- `values`:`enum` 允许值;只在 enum 上存在。
|
|
35
35
|
- `default`:未设置时的默认值;没有该字段就不要自行假设。
|
|
36
36
|
|
|
37
|
-
`
|
|
37
|
+
`player_seats` 传 JSON 整数数组,座位号范围为 1-10;例如 `[6]`。不要传字符串座位号(如 `["6"]`)或玩家名。`string_list` 才传 JSON 字符串数组。`controls: []` 表示该策略没有可调参数,不要调用 `--control`。
|
|
38
38
|
|
|
39
39
|
6. 启动策略(`<id>` 处也可填 `name`),命令不接位置参数:
|
|
40
40
|
|
|
@@ -45,12 +45,12 @@ ccl strategy <id>
|
|
|
45
45
|
7. 需要配置时,按刚读取的 control ID 和类型更新当前策略:
|
|
46
46
|
|
|
47
47
|
```bash
|
|
48
|
-
ccl strategy --control '{"targets":[
|
|
48
|
+
ccl strategy --control '{"targets":[3,6]}'
|
|
49
49
|
```
|
|
50
50
|
|
|
51
51
|
`--control` 只作用于当前正在运行的策略,并在下一份可执行游走 State 前应用;成功返回会给出 effective values。随后可在 `ccl events` 的 `state.strategy.params` 核对当前有效参数。缺少必填参数的策略会处于等待状态,此时按 `--info` 补齐,不要换用位置参数。
|
|
52
52
|
|
|
53
|
-
玩家分类统一使用策略声明的 `
|
|
53
|
+
玩家分类统一使用策略声明的 `player_seats` 参数,例如 `huntTargets`、`protectedTargets`、`hostileTargets`、`trustedTargets`。每个数组是该字段的完整当前座位号名单,清空必须显式传 `[]`;同一次判断变化涉及多个名单时,用一条 `--control` JSON 原子更新。若同一座位同时出现在敌对和保护名单,官方策略以 `protectedTargets` / `trustedTargets` 为先。参数只属于当前活动策略,切换策略或重启 runtime 后按新实例参数重新配置。Goal tree 只在参数实际变化且控制被接受时重建,不会每次游戏 `update()` 都重算一棵新树。
|
|
54
54
|
|
|
55
55
|
## 当前策略
|
|
56
56
|
|
|
@@ -263,6 +263,14 @@ export default class StaticValidationStrategy extends ClawclawGoalStrategy {
|
|
|
263
263
|
'task-report': ['greetings'],
|
|
264
264
|
'warrior-memory': ['huntTargets', 'trustedTargets'],
|
|
265
265
|
};
|
|
266
|
+
const playerSeatControlIds = new Set([
|
|
267
|
+
'targets',
|
|
268
|
+
'protectedTargets',
|
|
269
|
+
'huntTargets',
|
|
270
|
+
'hostileTargets',
|
|
271
|
+
'trustedTargets',
|
|
272
|
+
'paradiseFishTargets',
|
|
273
|
+
]);
|
|
266
274
|
|
|
267
275
|
const officialIds = Object.keys(readManifest());
|
|
268
276
|
expect(officialIds).toHaveLength(20);
|
|
@@ -281,6 +289,11 @@ export default class StaticValidationStrategy extends ClawclawGoalStrategy {
|
|
|
281
289
|
for (const control of expectedControls[id] ?? []) {
|
|
282
290
|
expect(source).toContain(`id: '${control}'`);
|
|
283
291
|
}
|
|
292
|
+
for (const control of discoveredById.get(id)?.controls ?? []) {
|
|
293
|
+
if (playerSeatControlIds.has(control.id)) {
|
|
294
|
+
expect(control.type).toBe('player_seats');
|
|
295
|
+
}
|
|
296
|
+
}
|
|
284
297
|
}
|
|
285
298
|
});
|
|
286
299
|
|
|
@@ -54,7 +54,7 @@ function validateControlSpecs(controls: readonly StrategyControlSpec[] | undefin
|
|
|
54
54
|
if (controls === undefined) return;
|
|
55
55
|
if (!Array.isArray(controls)) throw new Error('strategy_controls_invalid');
|
|
56
56
|
const ids = new Set<string>();
|
|
57
|
-
const types = new Set(['string', 'boolean', 'number', 'enum', '
|
|
57
|
+
const types = new Set(['string', 'boolean', 'number', 'enum', 'player_seats', 'string_list']);
|
|
58
58
|
for (const control of controls) {
|
|
59
59
|
if (!control || typeof control !== 'object') throw new Error('strategy_control_invalid');
|
|
60
60
|
if (!/^[A-Za-z][A-Za-z0-9_.-]{0,79}$/.test(control.id) || ids.has(control.id)) {
|
|
@@ -177,6 +177,28 @@ async function run(
|
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
describe('ClawClaw Strategy plugin scheduling', () => {
|
|
180
|
+
it('accepts numeric player_seats controls and rejects string seats or names', () => {
|
|
181
|
+
const plugin = new ClawclawStrategyPlugin();
|
|
182
|
+
plugin.select({
|
|
183
|
+
id: 'seat-controls',
|
|
184
|
+
execution: 'parallel_analyze',
|
|
185
|
+
sourcePath: 'unused',
|
|
186
|
+
sourceRoot: 'unused',
|
|
187
|
+
controls: [{
|
|
188
|
+
id: 'targets',
|
|
189
|
+
type: 'player_seats',
|
|
190
|
+
description: 'Target seats.',
|
|
191
|
+
}],
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
expect(() => plugin.control({ targets: ['6'] })).toThrow('invalid_strategy_control:targets');
|
|
195
|
+
expect(() => plugin.control({ targets: ['木桩机器虾'] })).toThrow('invalid_strategy_control:targets');
|
|
196
|
+
expect(() => plugin.control({ targets: [0, 11] })).toThrow('invalid_strategy_control:targets');
|
|
197
|
+
|
|
198
|
+
const accepted = plugin.control({ targets: [6] });
|
|
199
|
+
void accepted.catch(() => {});
|
|
200
|
+
});
|
|
201
|
+
|
|
180
202
|
it('exposes localized metadata only after a strategy becomes active', async () => {
|
|
181
203
|
const plugin = new ClawclawStrategyPlugin({
|
|
182
204
|
executorFactory: () => ({
|
|
@@ -184,18 +184,27 @@ function validStrategyControlValue(spec: StrategyControlSpec, value: unknown): b
|
|
|
184
184
|
if (spec.type === 'number') return typeof value === 'number' && Number.isFinite(value);
|
|
185
185
|
if (spec.type === 'string') return typeof value === 'string';
|
|
186
186
|
if (spec.type === 'enum') return typeof value === 'string' && !!spec.values?.includes(value);
|
|
187
|
+
if (spec.type === 'player_seats') {
|
|
188
|
+
return Array.isArray(value) && value.every((entry) => (
|
|
189
|
+
Number.isInteger(entry) && entry >= 1 && entry <= 10
|
|
190
|
+
));
|
|
191
|
+
}
|
|
187
192
|
return Array.isArray(value) && value.every((entry) => typeof entry === 'string');
|
|
188
193
|
}
|
|
189
194
|
|
|
190
|
-
function
|
|
195
|
+
function validateControlValues(
|
|
191
196
|
selection: ClawclawStrategySelection,
|
|
192
197
|
values: Readonly<Record<string, unknown>>,
|
|
198
|
+
requireDeclared: boolean,
|
|
193
199
|
): void {
|
|
194
200
|
const controls = new Map((selection.controls ?? []).map((control) => [control.id, control]));
|
|
195
|
-
if (controls.size === 0) throw new Error('strategy_controls_not_supported');
|
|
201
|
+
if (requireDeclared && controls.size === 0) throw new Error('strategy_controls_not_supported');
|
|
196
202
|
for (const [key, value] of Object.entries(values)) {
|
|
197
203
|
const spec = controls.get(key);
|
|
198
|
-
if (!spec)
|
|
204
|
+
if (!spec) {
|
|
205
|
+
if (requireDeclared) throw new Error(`unsupported_strategy_control:${key}`);
|
|
206
|
+
continue;
|
|
207
|
+
}
|
|
199
208
|
if (!validStrategyControlValue(spec, value)) {
|
|
200
209
|
throw new Error(`invalid_strategy_control:${key}`);
|
|
201
210
|
}
|
|
@@ -449,9 +458,9 @@ implements RuntimeEpochPlugin<Record<string, any>> {
|
|
|
449
458
|
if (!target) throw new Error('no_active_strategy');
|
|
450
459
|
const revision = ++this.controlRevision;
|
|
451
460
|
const cloned = structuredClone(values);
|
|
461
|
+
validateControlValues(target, cloned, target.execution === 'parallel_compute');
|
|
452
462
|
let preAppliedValues: Readonly<Record<string, unknown>> | undefined;
|
|
453
463
|
if (target.execution === 'parallel_compute') {
|
|
454
|
-
validateParallelControls(target, cloned);
|
|
455
464
|
preAppliedValues = structuredClone({
|
|
456
465
|
...(target.parameters ?? {}),
|
|
457
466
|
...cloned,
|
|
@@ -951,7 +960,7 @@ implements RuntimeEpochPlugin<Record<string, any>> {
|
|
|
951
960
|
}
|
|
952
961
|
if (selected.execution === 'parallel_compute') {
|
|
953
962
|
try {
|
|
954
|
-
|
|
963
|
+
validateControlValues(selected, control.values, true);
|
|
955
964
|
const result = this.parallelExecutor?.applyControl
|
|
956
965
|
? await this.parallelExecutor.applyControl({
|
|
957
966
|
epochId: input.epoch.epochSeq,
|
package/src/sdk/index.ts
CHANGED
|
@@ -67,8 +67,8 @@ export type { SpeechModuleConfig, SpeechEvalResult } from '../strategies/speech-
|
|
|
67
67
|
// Greeting utilities (for exported strategies that use greeting phrases)
|
|
68
68
|
export { parseGreetingArgs, GreetingTracker, MAX_GREETING_PHRASES, GREETING_TEXT_MAX_LENGTH, GREETING_COOLDOWN_MS } from '../strategies/greeting.js';
|
|
69
69
|
|
|
70
|
-
// Player
|
|
71
|
-
export {
|
|
70
|
+
// Player role-label utilities (for exported strategies)
|
|
71
|
+
export { stripRoleIds } from '../strategies/player-targets.js';
|
|
72
72
|
|
|
73
73
|
// Goal system (for exported strategies that use the goal framework)
|
|
74
74
|
export { GoalRootStrategy } from '../strategies/goals/goal-root-strategy.js';
|
|
@@ -2,6 +2,7 @@ import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
|
2
2
|
import {
|
|
3
3
|
ClawclawGoalStrategy,
|
|
4
4
|
ClawclawStrategy,
|
|
5
|
+
clawclawStrategySeatList,
|
|
5
6
|
type ClawclawStrategyAction,
|
|
6
7
|
type ClawclawStrategyGameState,
|
|
7
8
|
STRATEGY_PLUGIN_API_VERSION,
|
|
@@ -41,6 +42,11 @@ class TestStrategy extends ClawclawStrategy {
|
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
describe('Strategy Plugin SDK', () => {
|
|
45
|
+
it('reads player_seats controls as numeric seat arrays only', () => {
|
|
46
|
+
expect(clawclawStrategySeatList({ targets: [6, '6', '木桩机器虾', 0, 11] }, 'targets'))
|
|
47
|
+
.toEqual([6]);
|
|
48
|
+
});
|
|
49
|
+
|
|
44
50
|
it('defines one class with manifest and update as the authoring contract', () => {
|
|
45
51
|
expect(TestStrategy.apiVersion).toBe(STRATEGY_PLUGIN_API_VERSION);
|
|
46
52
|
expect(TestStrategy.manifest.id).toBe('test-strategy');
|
|
@@ -103,7 +109,7 @@ describe('Strategy Plugin SDK', () => {
|
|
|
103
109
|
description: 'Exercises the npm Goal migration boundary.',
|
|
104
110
|
controls: [{
|
|
105
111
|
id: 'targets',
|
|
106
|
-
type: '
|
|
112
|
+
type: 'player_seats',
|
|
107
113
|
description: 'Fixture arguments.',
|
|
108
114
|
default: [],
|
|
109
115
|
}],
|
|
@@ -203,7 +209,7 @@ describe('Strategy Plugin SDK', () => {
|
|
|
203
209
|
parameters: {},
|
|
204
210
|
});
|
|
205
211
|
|
|
206
|
-
const instance = new FixtureGoalStrategy({ targets: [
|
|
212
|
+
const instance = new FixtureGoalStrategy({ targets: [2] });
|
|
207
213
|
await instance.update(makeFrame(1), api);
|
|
208
214
|
await instance.update(makeFrame(2), api);
|
|
209
215
|
|
|
@@ -250,11 +256,11 @@ describe('Strategy Plugin SDK', () => {
|
|
|
250
256
|
epochId: 3,
|
|
251
257
|
scope: { sessionId: 'session', segmentId: 'game' },
|
|
252
258
|
revision: 7,
|
|
253
|
-
values: { targets: [
|
|
259
|
+
values: { targets: [3] },
|
|
254
260
|
})).toMatchObject({
|
|
255
261
|
accepted: true,
|
|
256
262
|
appliedRevision: 7,
|
|
257
|
-
effectiveValues: { targets: [
|
|
263
|
+
effectiveValues: { targets: [3] },
|
|
258
264
|
});
|
|
259
265
|
expect(createCount).toBe(2);
|
|
260
266
|
expect(mapLoadCount).toBe(2);
|
|
@@ -62,7 +62,7 @@ export interface StrategyFrame<TState = Record<string, unknown>> {
|
|
|
62
62
|
|
|
63
63
|
export interface StrategyControlSpec {
|
|
64
64
|
readonly id: string;
|
|
65
|
-
readonly type: 'string' | 'boolean' | 'number' | 'enum' | '
|
|
65
|
+
readonly type: 'string' | 'boolean' | 'number' | 'enum' | 'player_seats' | 'string_list';
|
|
66
66
|
readonly description: string;
|
|
67
67
|
readonly values?: readonly string[];
|
|
68
68
|
readonly default?: unknown;
|
|
@@ -417,6 +417,18 @@ export function clawclawStrategyStringList(
|
|
|
417
417
|
: [];
|
|
418
418
|
}
|
|
419
419
|
|
|
420
|
+
export function clawclawStrategySeatList(
|
|
421
|
+
parameters: Readonly<Record<string, unknown>>,
|
|
422
|
+
controlId: string,
|
|
423
|
+
): number[] {
|
|
424
|
+
const value = parameters[controlId];
|
|
425
|
+
return Array.isArray(value)
|
|
426
|
+
? value.filter((entry): entry is number => (
|
|
427
|
+
Number.isInteger(entry) && entry >= 1 && entry <= 10
|
|
428
|
+
))
|
|
429
|
+
: [];
|
|
430
|
+
}
|
|
431
|
+
|
|
420
432
|
export function clawclawStrategyString(
|
|
421
433
|
parameters: Readonly<Record<string, unknown>>,
|
|
422
434
|
controlId: string,
|
|
@@ -1312,7 +1324,6 @@ export interface StrategyInstance<
|
|
|
1312
1324
|
// authoring API does not export GameClient, transport, SQLite, or Runtime
|
|
1313
1325
|
// internals. Strategy source is still trusted same-process code, not sandboxed.
|
|
1314
1326
|
export { parseGreetingArgs } from '../../strategies/greeting.js';
|
|
1315
|
-
export { parseTargetArgs } from '../../strategies/player-targets.js';
|
|
1316
1327
|
export { SpeechModule, getSpeechConfigForRole } from '../../strategies/speech-module.js';
|
|
1317
1328
|
export { GoalRootStrategy } from '../../strategies/goals/goal-root-strategy.js';
|
|
1318
1329
|
export { TaskOnlyTop } from '../../strategies/goals/task-only-top.js';
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ClawclawGoalStrategy,
|
|
3
|
-
|
|
3
|
+
clawclawStrategySeatList,
|
|
4
4
|
} from '../sdk/strategy-plugin/index.js';
|
|
5
5
|
import { GoalRootStrategy } from './goals/goal-root-strategy.js';
|
|
6
6
|
import { AvoidPlayersTop } from './goals/avoid-players-top.js';
|
|
7
|
-
import { parseTargetArgs } from './player-targets.js';
|
|
8
7
|
|
|
9
8
|
export default class AvoidPlayersStrategy extends ClawclawGoalStrategy {
|
|
10
9
|
static readonly manifest = {
|
|
@@ -14,8 +13,8 @@ export default class AvoidPlayersStrategy extends ClawclawGoalStrategy {
|
|
|
14
13
|
execution: 'parallel_analyze',
|
|
15
14
|
controls: [{
|
|
16
15
|
id: 'targets',
|
|
17
|
-
type: '
|
|
18
|
-
description: '
|
|
16
|
+
type: 'player_seats',
|
|
17
|
+
description: '需要回避的玩家座位号列表。',
|
|
19
18
|
default: [],
|
|
20
19
|
}],
|
|
21
20
|
} as const;
|
|
@@ -24,7 +23,7 @@ export default class AvoidPlayersStrategy extends ClawclawGoalStrategy {
|
|
|
24
23
|
super(parameters, {
|
|
25
24
|
id: 'avoid-players',
|
|
26
25
|
create: (values) => {
|
|
27
|
-
const targets =
|
|
26
|
+
const targets = clawclawStrategySeatList(values, 'targets');
|
|
28
27
|
return new GoalRootStrategy('avoid-players', () => new AvoidPlayersTop(targets), {
|
|
29
28
|
resetOnMeetingResume: false,
|
|
30
29
|
});
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ClawclawGoalStrategy,
|
|
3
|
-
|
|
3
|
+
clawclawStrategySeatList,
|
|
4
4
|
} from '../sdk/strategy-plugin/index.js';
|
|
5
5
|
import { GoalRootStrategy } from './goals/goal-root-strategy.js';
|
|
6
6
|
import { FindPlayerTop } from './goals/find-player-top.js';
|
|
7
|
-
import { parseTargetArgs } from './player-targets.js';
|
|
8
7
|
|
|
9
8
|
export default class FindPlayerStrategy extends ClawclawGoalStrategy {
|
|
10
9
|
static readonly manifest = {
|
|
@@ -14,8 +13,8 @@ export default class FindPlayerStrategy extends ClawclawGoalStrategy {
|
|
|
14
13
|
execution: 'parallel_analyze',
|
|
15
14
|
controls: [{
|
|
16
15
|
id: 'targets',
|
|
17
|
-
type: '
|
|
18
|
-
description: '
|
|
16
|
+
type: 'player_seats',
|
|
17
|
+
description: '要寻找并跟踪的单个玩家座位号。',
|
|
19
18
|
}],
|
|
20
19
|
} as const;
|
|
21
20
|
|
|
@@ -23,12 +22,12 @@ export default class FindPlayerStrategy extends ClawclawGoalStrategy {
|
|
|
23
22
|
super(parameters, {
|
|
24
23
|
id: 'find-player',
|
|
25
24
|
validateParameters: (values) => (
|
|
26
|
-
|
|
25
|
+
clawclawStrategySeatList(values, 'targets').length === 1
|
|
27
26
|
? undefined
|
|
28
27
|
: '盯人策略必须配置且只能配置一个目标玩家。'
|
|
29
28
|
),
|
|
30
29
|
create: (values) => {
|
|
31
|
-
const targets =
|
|
30
|
+
const targets = clawclawStrategySeatList(values, 'targets');
|
|
32
31
|
return new GoalRootStrategy('find-player', () => new FindPlayerTop(targets[0]), {
|
|
33
32
|
resetOnMeetingResume: false,
|
|
34
33
|
});
|
|
@@ -6,6 +6,8 @@ import {
|
|
|
6
6
|
emergencyRushDecision,
|
|
7
7
|
firstAvailableTask,
|
|
8
8
|
killYieldsToEmergencyRepair,
|
|
9
|
+
matchesTarget,
|
|
10
|
+
nearestVisibleTarget,
|
|
9
11
|
nearestSafeTask,
|
|
10
12
|
PatrolState,
|
|
11
13
|
safePatrolStep,
|
|
@@ -66,6 +68,26 @@ function context(overrides: Partial<StrategyContext> = {}): StrategyContext {
|
|
|
66
68
|
};
|
|
67
69
|
}
|
|
68
70
|
|
|
71
|
+
describe('seat-only player targets', () => {
|
|
72
|
+
it('selects only the configured seat when multiple players share one name', () => {
|
|
73
|
+
const ctx = context({
|
|
74
|
+
playerNamesBySeat: {
|
|
75
|
+
'2': '木桩机器虾',
|
|
76
|
+
'6': '木桩机器虾',
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
const sameNamePlayers = [
|
|
80
|
+
{ name: '木桩机器虾', seat: 2, room: '居住区', x: 10, y: 0, distance: 10 },
|
|
81
|
+
{ name: '木桩机器虾', seat: 6, room: '居住区', x: 20, y: 0, distance: 20 },
|
|
82
|
+
];
|
|
83
|
+
const current = state({ players: sameNamePlayers });
|
|
84
|
+
|
|
85
|
+
expect(matchesTarget(6, sameNamePlayers[0], ctx)).toBe(false);
|
|
86
|
+
expect(matchesTarget(6, sameNamePlayers[1], ctx)).toBe(true);
|
|
87
|
+
expect(nearestVisibleTarget(current, ctx, [6])?.seat).toBe(6);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
69
91
|
describe('CorpseMemory', () => {
|
|
70
92
|
it('uses the last visible position immediately after a confirmed kill', () => {
|
|
71
93
|
const memory = new CorpseMemory();
|
|
@@ -758,42 +758,17 @@ export function nonTeammatesVisible(state: GameState, ctx: StrategyContext): Pla
|
|
|
758
758
|
: players;
|
|
759
759
|
}
|
|
760
760
|
|
|
761
|
-
/**
|
|
762
|
-
* Resolve a target string (seat number or player name) to a seat number.
|
|
763
|
-
* Names are resolved through `ctx.playerNamesBySeat` (seat → name). Returns
|
|
764
|
-
* null when the target cannot be resolved to a seat (unknown name, empty input).
|
|
765
|
-
*/
|
|
766
|
-
export function targetSeat(target: string, ctx: StrategyContext): number | null {
|
|
767
|
-
const trimmed = target.trim();
|
|
768
|
-
if (!trimmed) return null;
|
|
769
|
-
if (/^\d+$/.test(trimmed)) return Number(trimmed);
|
|
770
|
-
const folded = trimmed.toLowerCase();
|
|
771
|
-
for (const [seat, name] of Object.entries(ctx.playerNamesBySeat)) {
|
|
772
|
-
if (name && name.toLowerCase() === folded) return Number(seat);
|
|
773
|
-
}
|
|
774
|
-
return null;
|
|
775
|
-
}
|
|
776
|
-
|
|
777
761
|
export function matchesTarget(
|
|
778
|
-
|
|
762
|
+
targetSeat: number,
|
|
779
763
|
player: { name?: string; seat?: number },
|
|
780
|
-
|
|
764
|
+
_ctx: StrategyContext,
|
|
781
765
|
): boolean {
|
|
782
|
-
|
|
783
|
-
const seat = targetSeat(trimmed, ctx);
|
|
784
|
-
if (seat != null && player.seat != null && player.seat === seat) return true;
|
|
785
|
-
if (seat != null) {
|
|
786
|
-
// 座位号参数对无名/缺 seat 的条目(如只有名字的尸体):经 seat→name 反查命中。
|
|
787
|
-
const nameFromSeat = ctx.playerNamesBySeat[String(seat)];
|
|
788
|
-
if (nameFromSeat && player.name && player.name.toLowerCase() === nameFromSeat.toLowerCase()) return true;
|
|
789
|
-
}
|
|
790
|
-
const normalized = trimmed.toLowerCase();
|
|
791
|
-
return player.name != null && player.name.toLowerCase() === normalized;
|
|
766
|
+
return Number.isInteger(targetSeat) && player.seat === targetSeat;
|
|
792
767
|
}
|
|
793
768
|
|
|
794
769
|
export function matchesAnyTarget(
|
|
795
770
|
player: { name?: string; seat?: number },
|
|
796
|
-
targets:
|
|
771
|
+
targets: number[],
|
|
797
772
|
ctx: StrategyContext,
|
|
798
773
|
): boolean {
|
|
799
774
|
return targets.some(target => matchesTarget(target, player, ctx));
|
|
@@ -801,26 +776,24 @@ export function matchesAnyTarget(
|
|
|
801
776
|
|
|
802
777
|
export function isTargetAlive(
|
|
803
778
|
state: GameState,
|
|
804
|
-
|
|
779
|
+
targetSeat: number,
|
|
805
780
|
ctx: StrategyContext,
|
|
806
781
|
): boolean {
|
|
807
|
-
if (isRecentlyKilledTarget(
|
|
808
|
-
const player = state.all_players?.find(p => matchesTarget(
|
|
782
|
+
if (isRecentlyKilledTarget(targetSeat, ctx)) return false;
|
|
783
|
+
const player = state.all_players?.find(p => matchesTarget(targetSeat, p, ctx));
|
|
809
784
|
return player ? player.is_alive !== false : true;
|
|
810
785
|
}
|
|
811
786
|
|
|
812
|
-
export function isRecentlyKilledTarget(
|
|
813
|
-
const
|
|
814
|
-
if (seat == null) return false;
|
|
815
|
-
const until = ctx.recentlyKilledTargets?.get(String(seat));
|
|
787
|
+
export function isRecentlyKilledTarget(targetSeat: number, ctx: StrategyContext): boolean {
|
|
788
|
+
const until = ctx.recentlyKilledTargets?.get(String(targetSeat));
|
|
816
789
|
if (until == null) return false;
|
|
817
790
|
if (until > Date.now()) return true;
|
|
818
|
-
ctx.recentlyKilledTargets?.delete(String(
|
|
791
|
+
ctx.recentlyKilledTargets?.delete(String(targetSeat));
|
|
819
792
|
return false;
|
|
820
793
|
}
|
|
821
794
|
|
|
822
795
|
export function visibleLivePlayers(state: GameState, ctx: StrategyContext): PlayerInfo[] {
|
|
823
|
-
return state.players.filter(p => isTargetAlive(state, p.
|
|
796
|
+
return state.players.filter(p => p.seat == null || isTargetAlive(state, p.seat, ctx));
|
|
824
797
|
}
|
|
825
798
|
|
|
826
799
|
export function nearestPlayerByDistance(state: GameState, players: PlayerInfo[]): PlayerInfo | null {
|
|
@@ -832,7 +805,7 @@ export function nearestPlayerByDistance(state: GameState, players: PlayerInfo[])
|
|
|
832
805
|
export function nearestVisibleTarget(
|
|
833
806
|
state: GameState,
|
|
834
807
|
ctx: StrategyContext,
|
|
835
|
-
targets:
|
|
808
|
+
targets: number[],
|
|
836
809
|
): PlayerInfo | null {
|
|
837
810
|
return nearestPlayerByDistance(
|
|
838
811
|
state,
|
|
@@ -65,7 +65,7 @@ describe('AvoidPlayersTop', () => {
|
|
|
65
65
|
});
|
|
66
66
|
|
|
67
67
|
it('patrols without stop_on_player when the configured avoid target is dead', () => {
|
|
68
|
-
const top = new AvoidPlayersTop([
|
|
68
|
+
const top = new AvoidPlayersTop([2]);
|
|
69
69
|
const ctx = context();
|
|
70
70
|
const current = state({
|
|
71
71
|
players: [{ name: 'roadie', x: 200, y: 0, room: 'start' }],
|
|
@@ -83,7 +83,7 @@ describe('AvoidPlayersTop', () => {
|
|
|
83
83
|
});
|
|
84
84
|
|
|
85
85
|
it('uses targets as the complete active avoid list', () => {
|
|
86
|
-
const top = new AvoidPlayersTop([
|
|
86
|
+
const top = new AvoidPlayersTop([2]);
|
|
87
87
|
const current = state({
|
|
88
88
|
players: [{ name: 'danger', seat: 2, x: 200, y: 0, room: 'start' }],
|
|
89
89
|
all_players: [{ name: 'danger', seat: 2, role: 'unknown', is_alive: true }],
|
|
@@ -13,7 +13,7 @@ export class AvoidPlayersTop extends Goal {
|
|
|
13
13
|
private moveMode: 'patrol' | 'flee' | null = null;
|
|
14
14
|
private lastAvoidNoticeKey = '';
|
|
15
15
|
|
|
16
|
-
constructor(private readonly targets:
|
|
16
|
+
constructor(private readonly targets: number[]) {
|
|
17
17
|
super();
|
|
18
18
|
}
|
|
19
19
|
|
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
reportCorpseDecision,
|
|
11
11
|
playerStrategyIntent,
|
|
12
12
|
strategyDecision,
|
|
13
|
-
targetSeat,
|
|
14
13
|
} from '../game-utils.js';
|
|
15
14
|
import type { BehaviorDecision, StrategyContext } from '../types.js';
|
|
16
15
|
|
|
@@ -43,9 +42,10 @@ export function corpseReportWithNonTeammate(state: GameState, ctx: StrategyConte
|
|
|
43
42
|
if (report.action.type === 'report') {
|
|
44
43
|
// 实时给 Agent 一条「为什么是我报的尸」简报:报尸=召集会议,是高风险自证动作。
|
|
45
44
|
// 若尸体很可能是自己刚才下的那一刀,必须显式提醒,免得 Agent 之后发言露馅。
|
|
46
|
-
const
|
|
45
|
+
const corpse = nearestReportableCorpse(state);
|
|
46
|
+
const corpseName = corpse?.name ?? '';
|
|
47
47
|
ctx.agentAlerts.push(
|
|
48
|
-
isRecentOwnKill(ctx,
|
|
48
|
+
isRecentOwnKill(ctx, corpse)
|
|
49
49
|
? `我刚下手的目标${corpseName ? `(${corpseName})` : ''}尸体被${witnessNames}撞见,我抢先报尸召集会议、把自己装成发现者并把嫌疑引向在场者。接下来发言/投票要顺着「我是主动报告的人」走,绝不能承认是自己动的手。`
|
|
50
50
|
: `尸体旁有${witnessNames}在场,我抢先报尸召集会议、伪装成主动报告的好人。发言时按「主动报告的发现者」立场走。`,
|
|
51
51
|
);
|
|
@@ -91,16 +91,16 @@ export function immediateLoneKillDecision(
|
|
|
91
91
|
* 这具尸体是不是「自己刚才下的那一刀」。先按尸体座位号精确匹配 recentlyKilledTargets(刚杀过且未过期),
|
|
92
92
|
* 座位对不上但近期确实杀过人时,冒出的尸体大概率也是自己造成的,按 true 处理(宁可多提醒一次)。
|
|
93
93
|
*/
|
|
94
|
-
function isRecentOwnKill(
|
|
94
|
+
function isRecentOwnKill(
|
|
95
|
+
ctx: StrategyContext,
|
|
96
|
+
corpse: { seat?: number } | null,
|
|
97
|
+
): boolean {
|
|
95
98
|
const map = ctx.recentlyKilledTargets;
|
|
96
99
|
if (!map || map.size === 0) return false;
|
|
97
100
|
const now = Date.now();
|
|
98
|
-
if (
|
|
99
|
-
const
|
|
100
|
-
if (
|
|
101
|
-
const until = map.get(String(seat));
|
|
102
|
-
if (until != null && until > now) return true;
|
|
103
|
-
}
|
|
101
|
+
if (corpse?.seat != null) {
|
|
102
|
+
const until = map.get(String(corpse.seat));
|
|
103
|
+
if (until != null && until > now) return true;
|
|
104
104
|
}
|
|
105
105
|
for (const until of map.values()) {
|
|
106
106
|
if (until > now) return true;
|