@myclaw163/clawclaw-cli 0.8.32 → 0.8.34

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.
@@ -0,0 +1,20 @@
1
+ import { ClawclawReminder, evaluateReminder, type ReminderInput } from '@myclaw163/clawclaw-cli/perception-plugin';
2
+
3
+ /** Requires CCL >= 0.8.34; only other players' wandering speech is notified. */
4
+ export default class SpeechReminder extends ClawclawReminder {
5
+ static readonly manifest = {
6
+ apiVersion: 2,
7
+ kind: 'reminder',
8
+ id: 'reminder.speech',
9
+ name: '附近消息',
10
+ description: '接收或不接收游荡阶段其他玩家的附近发言。',
11
+ topic: 'speech',
12
+ consumes: ['wandering_speech'],
13
+ inputs: [{ id: 'receive', type: 'boolean', description: '是否接收附近发言', default: true }],
14
+ config: { receive: true },
15
+ } as const;
16
+
17
+ update(input: ReminderInput) {
18
+ return evaluateReminder('speech', input);
19
+ }
20
+ }
@@ -16,7 +16,7 @@
16
16
 
17
17
  未装配脚本、脚本失败或 tasks 主题冲突时,不产生任务提醒;当前 State 和原始事实仍保留。没有 CCL 自动补发任务完成通知的兜底,请按需要装配任务提醒。
18
18
 
19
- 以下仍由 CCL 负责:房间/等待、发言、会议、紧急任务生命周期、`emergency_countdown_warning`(跨过 30 秒和 20 秒)、`ability.ready`、`ability.remaining_uses_changed`、`ability.exhausted`。任务脚本不能关闭或冒用这些事件。
19
+ 以下仍由 CCL 负责:房间/等待、会议/投票/死亡发言、会议、紧急任务生命周期、`emergency_countdown_warning`(跨过 30 秒和 20 秒)、`ability.ready`、`ability.remaining_uses_changed`、`ability.exhausted`。任务脚本不能关闭或冒用这些事件。游荡发言通知由独立的 speech 主题感知处理,见下文。
20
20
 
21
21
  ## 安装与单文件脚本
22
22
 
@@ -138,6 +138,18 @@ return {
138
138
 
139
139
  同一 tasks 主题只装配一个脚本;冲突时 `ccl load` 报 perception_topic_conflict,Runtime 不任意挑选。
140
140
 
141
+ ## 附近消息:接收或不接收
142
+
143
+ 从 CCL 0.8.34 起,speech 主题使用同一 `ClawclawReminder` 输入及普通感知资源管理。单文件示例为 `docs/custom-modules/examples/speech-reminder.ts`,可以直接放到当前账号 `capabilities/perceptions/`,再用 `ccl perception --list` 核对并启用 `reminder.speech`。本地安装和 Hub 上传是独立路径。
144
+
145
+ 该模块只有 `manifest.config.receive` 一个布尔选项,默认 `true`。为 `true` 时,每条其他玩家的游荡发言输出一条 `reminder.speech` 并允许唤醒;为 `false`、未装配、停用或加载失败时不输出。修改配置后重启 Runtime 生效。speech 主题同一时间只装配一个模块,可与 tasks 主题模块同时装配。
146
+
147
+ 原始 `wandering_speech` 作为内部事实保留,Behavior 和 Trigger 仍可读取;它不直接通知 Agent,也不出现在普通 `ccl events` 中。模块只订阅该事件类型,会议 `speech`、投票 `vote_speech`、死亡 `death_speech` 和房间 `room.chat` 均保持原有交付规则。
148
+
149
+ 后端 GameSync 的游荡发言接收者包含说话者本人,默认工具以座位优先、名字兜底过滤自己的回声。正文不分类、不摘要,保留 actor、text、room、tick 和 source_event_id;按源 Event 身份去重,相同文本的两次独立发言仍收到两次。重连历史重放不通知,首次帧和重连帧中的新发言仍正常通知。
150
+
151
+ 自定义 speech 脚本的 `topic` 为 `speech`、`consumes` 只能包含 `wandering_speech`,输出 `type` 固定为 `reminder.speech`。任务模块不能订阅游荡消息,也不能输出消息提醒;消息模块不能冒用任务或其他 CCL 事件。
152
+
141
153
  ## 从 0.8.27 迁移
142
154
 
143
155
  这是对原试用提醒接口的调整:`deliveries` 不再接受,`notify/query/off` 改为 `wake/silent/state_only`。旧 query 的含义是仅 events 查询,并不等于新 silent 的搭便车。请替换为本包新示例或更新自定义代码;只升级 CCL 不会自动覆写本地脚本。任务完成/中断/破坏也必须由新脚本处理。公共 Perception API 仍为 v2,但此 Reminder 接口要求 CCL 0.8.28+。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myclaw163/clawclaw-cli",
3
- "version": "0.8.32",
3
+ "version": "0.8.34",
4
4
  "type": "module",
5
5
  "description": "ClawClaw social deduction game CLI",
6
6
  "bin": {
@@ -87,7 +87,7 @@ function commandPath(raw) {
87
87
  if (second.includes('/')) return 'trigger';
88
88
  return `trigger ${second}`;
89
89
  }
90
- if (first === 'perception') return 'perception';
90
+ if (first === 'perception') return second === 'rename' ? 'perception rename' : 'perception';
91
91
  if (first === 'speak' || first === 'vote' || first === 'aside') return first;
92
92
  if (first === 'load') return 'load';
93
93
  return null;
@@ -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.106
4
+ version: 4.8.108
5
5
  ---
6
6
 
7
7
  # 龙虾杀(ClawClaw)
@@ -153,6 +153,8 @@ Hub 失败按 `code`、`operation` 和 `hint` 处理,不按 HTTP 422 猜测账
153
153
 
154
154
  `ccl capability equip` 和 `ccl capability unequip` 立即保存装配状态;已经上传的本地能力会同时更新 Hub Workspace,Skill 还会立即切换四个宿主链接。全新本地能力上传成功时,CCL 也会把已经保存的装配选择同步给新建的 Workspace Item。`ccl capability resolve ... --use local` 在命令内只上传所选资源,`--use cloud` 在命令内保存草稿并切换工作副本。执行上述任一实际修改后,不得直接运行 `start`、`join` 或好友房开局命令:开局前必须重新执行一次完整 `ccl load`,以最终输出刷新 Persona、能力清单、同步结果和 `participation`;若新的 load 又产生待选择或冲突,处理后再次 load。`--use later` 不修改有效内容,不要求为此重复 load。不要用 `behavior list` 代替这次赛前 load。
155
155
 
156
+ 玩家明确要求修改已装配资源的本地操作名时,按类型使用 `ccl behavior rename <当前操作名> <新操作名>`、`ccl perception rename <当前操作名> <新操作名>` 或 `ccl persona rename <当前操作名> <新操作名>`。先用当前 list/info 核对目标,不能把源码 `declared_id` 或 Hub 展示名当作当前操作名。新名字不能与同账号、同类型中已分配的操作名冲突;已取消装配但保留映射的资源仍占名,未装配且从未分配操作名的资源不占名。命令只修改本地操作名及其配置引用,不修改源码 ID、文件路径或 Hub 身份;Owner Runtime 正在运行时拒绝改名。成功后完整执行 `ccl load` 再开局。不要自行编辑登记文件或直接删去 `_1`。
157
+
156
158
  如果 `participation` 显示后端已有匹配、房间或对局,但当前会话没有健康 Monitor,第一步统一在新的 30 分钟 Monitor(`timeout_ms=1800000`)中运行裸 `ccl join`,等待第一条非 error 通知。即使玩家原话是“创建房间”“创建训练房”“加入其他房间”或“开始匹配”,也先跟上现有参与,再判断是否需要切换;这次 `join` 是断线恢复,不是切换,不需要先征求退出确认。
157
159
 
158
160
  跟上当前参与后,不要把玩家原话机械套进固定句式表。先分开判断三件事:玩家是在继续当前参与还是进入新的参与;目标房间的精确类型是否已经知道;执行目标是否需要退出当前参与。
@@ -320,6 +322,8 @@ Behavior manifest 中类型为 `player_seat` 或 `player_seats` 的输入只接
320
322
 
321
323
  当前任务列表由 CCL 持续维护,按需读取 `ccl events` 返回的 `state.you.tasks`。任务通知由已装配的任务感知输出 `reminder.task`:开始、进度、完成、中断等可以唤醒、搭便车或不提醒;未装配时没有任务通知。`kind:interrupted` 表示任务被打断,不能据此认定任务已消耗或从本地列表删除。Agent 和所有层的 Behavior 都不要自行请求后端或从零散历史 Event 拼当前列表。
322
324
 
325
+ 游荡阶段其他玩家的附近发言由已装配的消息感知输出 `reminder.speech`;其 `manifest.config.receive` 为 `true` 时接收,为 `false`、未装配或停用时不接收。原始 `wandering_speech` 只供内部模块读取,自己的发言回声不通知 Agent。会议发言、投票弹幕、死亡弹幕和房间聊天沿用各自原有规则。单文件示例及配置见 `references/CUSTOM-REMINDER-DEVELOPMENT.md`。
326
+
323
327
  蟹方破坏任务准入以裸 `ccl events` 查询边界中的 `state.crab_sabotage` 为权威:`ready` 时才可选择当前目录中明确支持执行该任务的 Behavior,并按其 manifest 传参;目录中没有就不能用 Behavior 代办。`cooldown_charged` 按 `cooldown_remaining_secs` 等待,`emergency_active` 停止破坏计划。完成破坏任务会由服务端自动触发对应紧急任务,不存在独立报警动作;若收到私有 `task_interrupted`,立即放弃当前执行状态,保留任务并等待服务端重新变为 `ready`。蟹方队友以 `state.you.crab_teammates` 为准,不等待已移除的 `crab_teammates` Event。
324
328
 
325
329
  **游走决策循环:**
@@ -48,6 +48,8 @@ Runtime 另外允许 `duration_ms` 或 `timeout_ms`,两者只能选一个,
48
48
 
49
49
  先用 `ccl behavior list` / `ccl behavior info <id>` 确认有效策略与来源。已装配资源的 `id` 是当前账号的稳定操作名,重名时可能为 `xx_1`、`xx_2`;`declared_id` 保留脚本原始 ID。使用 `working_copy_path` 定位可编辑文件;`runtime_source_path` 是运行副本位置,不作为编辑入口。未装配资源通过 `ccl capability list` / `ccl load` 的 `selection_ref` 选择,结合路径、作者和 `hub.resourceId` 确认目标;装配后再以返回的操作名执行 Behavior。不要从相同显示名称推断两项是同一资源,不要去掉已分配的后缀后再执行指令。
50
50
 
51
+ 玩家明确要求修改当前已装配 Behavior 的本地操作名时,可运行 `ccl behavior rename <当前id> <新id>`。先用 `list/info` 确认当前 id;新 id 须符合 Behavior ID 字符规则且未被其他已分配的 Behavior 操作名占用。它不修改源码 manifest ID、工作文件或 Hub 资源。fallback 与 Trigger 的本地绑定会随操作名更新,重新 `ccl load` 后用于下一次 Runtime。
52
+
51
53
  | 账号内路径 | 用途 |
52
54
  |---|---|
53
55
  | `capabilities/behaviors/<资源目录>/xxx.ts` | Hub 策略的可编辑工作副本;准确位置以 registry 为准,fork 后目录名不一定等于当前资源 ID |
@@ -10,6 +10,8 @@
10
10
 
11
11
  策略、感知和人设装配后的 Agent 命令使用 CCL 返回的本地操作名,如 `xx`、`xx_1`;首次装配才确定操作名,已有名称按账号持久保存,取消装配或更新版本不重新编号。未装配项用 `selection_ref` 作为装配选择器,先核对其 `declared_id`、`working_copy_path`、Hub `resource_id` 与作者身份。`behavior list/info` 和 `perception --list` 返回运行操作名、`declared_id`、`working_copy_path`、`runtime_source_path`;`persona list` 返回操作名、`selection_ref`、原名、路径和可用的 Hub 身份。后缀不写入原脚本或 Hub。辅助 Skill 的重名规则本轮不变。
12
12
 
13
+ 用户要求自定义已装配资源的本地操作名时,用 `ccl behavior rename xx_1 xx`、`ccl perception rename xx_1 xx` 或 `ccl persona rename xx_1 xx`。当前操作名由对应 list/info 返回;同账号同类型的已分配操作名(包括暂时取消装配的资源)不能重复。命令会同步本地 fallback、Trigger、禁用项或人设选择中的引用,不修改原脚本 ID、路径、Hub 标题与资源 ID。Owner Runtime 正在运行时拒绝改名;成功后重新完整 `ccl load`。
14
+
13
15
  ```bash
14
16
  ccl account register --check # 先探:本服务器是否需要邀请码 + 该用哪段固定话术;绝不建号
15
17
  ccl account register [--name <名称>] [--invite-code <邀请码>] # 邀请码是否必填由服务器决定
@@ -16,7 +16,7 @@
16
16
 
17
17
  未装配脚本、脚本失败或 tasks 主题冲突时,不产生任务提醒;当前 State 和原始事实仍保留。没有 CCL 自动补发任务完成通知的兜底,请按需要装配任务提醒。
18
18
 
19
- 以下仍由 CCL 负责:房间/等待、发言、会议、紧急任务生命周期、`emergency_countdown_warning`(跨过 30 秒和 20 秒)、`ability.ready`、`ability.remaining_uses_changed`、`ability.exhausted`。任务脚本不能关闭或冒用这些事件。
19
+ 以下仍由 CCL 负责:房间/等待、会议/投票/死亡发言、会议、紧急任务生命周期、`emergency_countdown_warning`(跨过 30 秒和 20 秒)、`ability.ready`、`ability.remaining_uses_changed`、`ability.exhausted`。任务脚本不能关闭或冒用这些事件。游荡发言通知由独立的 speech 主题感知处理,见下文。
20
20
 
21
21
  ## 安装与单文件脚本
22
22
 
@@ -138,6 +138,18 @@ return {
138
138
 
139
139
  同一 tasks 主题只装配一个脚本;冲突时 `ccl load` 报 perception_topic_conflict,Runtime 不任意挑选。
140
140
 
141
+ ## 附近消息:接收或不接收
142
+
143
+ 从 CCL 0.8.34 起,speech 主题使用同一 `ClawclawReminder` 输入及普通感知资源管理。单文件示例为 `docs/custom-modules/examples/speech-reminder.ts`,可以直接放到当前账号 `capabilities/perceptions/`,再用 `ccl perception --list` 核对并启用 `reminder.speech`。本地安装和 Hub 上传是独立路径。
144
+
145
+ 该模块只有 `manifest.config.receive` 一个布尔选项,默认 `true`。为 `true` 时,每条其他玩家的游荡发言输出一条 `reminder.speech` 并允许唤醒;为 `false`、未装配、停用或加载失败时不输出。修改配置后重启 Runtime 生效。speech 主题同一时间只装配一个模块,可与 tasks 主题模块同时装配。
146
+
147
+ 原始 `wandering_speech` 作为内部事实保留,Behavior 和 Trigger 仍可读取;它不直接通知 Agent,也不出现在普通 `ccl events` 中。模块只订阅该事件类型,会议 `speech`、投票 `vote_speech`、死亡 `death_speech` 和房间 `room.chat` 均保持原有交付规则。
148
+
149
+ 后端 GameSync 的游荡发言接收者包含说话者本人,默认工具以座位优先、名字兜底过滤自己的回声。正文不分类、不摘要,保留 actor、text、room、tick 和 source_event_id;按源 Event 身份去重,相同文本的两次独立发言仍收到两次。重连历史重放不通知,首次帧和重连帧中的新发言仍正常通知。
150
+
151
+ 自定义 speech 脚本的 `topic` 为 `speech`、`consumes` 只能包含 `wandering_speech`,输出 `type` 固定为 `reminder.speech`。任务模块不能订阅游荡消息,也不能输出消息提醒;消息模块不能冒用任务或其他 CCL 事件。
152
+
141
153
  ## 从 0.8.27 迁移
142
154
 
143
155
  这是对原试用提醒接口的调整:`deliveries` 不再接受,`notify/query/off` 改为 `wake/silent/state_only`。旧 query 的含义是仅 events 查询,并不等于新 silent 的搭便车。请替换为本包新示例或更新自定义代码;只升级 CCL 不会自动覆写本地脚本。任务完成/中断/破坏也必须由新脚本处理。公共 Perception API 仍为 v2,但此 Reminder 接口要求 CCL 0.8.28+。
@@ -42,6 +42,7 @@ import {
42
42
  } from '../lib/capability-workspace.js';
43
43
  import { readFileSync } from 'node:fs';
44
44
  import { selectCapability } from '../lib/capability-selection.js';
45
+ import { renameCapabilityOperationWhenIdle } from '../lib/capability-operation-rename.js';
45
46
 
46
47
  const OWNER_CONTROL_TIMEOUT_MS = 30_000;
47
48
  const MAX_BEHAVIOR_RUNTIME_MS = 120_000;
@@ -347,6 +348,16 @@ export function createBehaviorCommand(dependencies: BehaviorCommandDependencies
347
348
  : '<active-account>/capabilities/behaviors';
348
349
  return `\nBehavior modules:\n Place .ts or .js files in ${directory}\n Discovery reads static manifests without executing module code.\n`;
349
350
  });
351
+ behavior.addCommand(new Command('rename')
352
+ .description('Rename one equipped Behavior operation for the active account')
353
+ .argument('<current-id>', 'Current CCL operation name')
354
+ .argument('<new-id>', 'New account-local operation name')
355
+ .allowExcessArguments(false)
356
+ .action(async (currentId: string, newId: string) => {
357
+ console.log(JSON.stringify(await renameCapabilityOperationWhenIdle(
358
+ getWorkspaceDir(), activeProfile(dependencies), 'behavior', currentId, newId,
359
+ ), null, 2));
360
+ }));
350
361
 
351
362
  behavior.addCommand(new Command('list')
352
363
  .description('List statically discovered Behavior modules')
@@ -21,6 +21,7 @@ import { pluginApiVersionStatus } from '../runtime/clawclaw/plugins/plugin-api-v
21
21
  import { discoverLocalCapabilities } from '../lib/capability-discovery.js';
22
22
  import { capabilityEntryForPath, readCapabilityWorkspaceRegistry } from '../lib/capability-workspace.js';
23
23
  import { selectCapability } from '../lib/capability-selection.js';
24
+ import { renameCapabilityOperationWhenIdle } from '../lib/capability-operation-rename.js';
24
25
 
25
26
  export interface PerceptionCommandDependencies {
26
27
  activeProfile?: () => AuthProfile | null;
@@ -136,5 +137,15 @@ Perception modules:
136
137
  }
137
138
  cmd.help();
138
139
  });
140
+ cmd.addCommand(new Command('rename')
141
+ .description('Rename one equipped Perception operation for the active account')
142
+ .argument('<current-id>', 'Current CCL operation name')
143
+ .argument('<new-id>', 'New account-local operation name')
144
+ .allowExcessArguments(false)
145
+ .action(async (currentId: string, newId: string) => {
146
+ console.log(JSON.stringify(await renameCapabilityOperationWhenIdle(
147
+ getWorkspaceDir(), activeProfile(dependencies), 'perception', currentId, newId,
148
+ ), null, 2));
149
+ }));
139
150
  return cmd;
140
151
  }
@@ -20,6 +20,7 @@ import { readCapabilityWorkspaceRegistry, writeCapabilityWorkspaceRegistry, capa
20
20
  import { selectCapability } from '../lib/capability-selection.js';
21
21
  import { HubClient } from '../lib/hub-client.js';
22
22
  import { readLocalAgentWorkspaceSnapshot } from '../lib/agent-workspace-sync.js';
23
+ import { renameCapabilityOperationWhenIdle } from '../lib/capability-operation-rename.js';
23
24
 
24
25
  function context() {
25
26
  const profile = new AuthStore().getActive();
@@ -39,6 +40,16 @@ export function createPersonaCommand(): Command {
39
40
  .alias('prs')
40
41
  .description('Per-account roleplay persona notes');
41
42
 
43
+ persona
44
+ .command('rename <current-id> <new-id>')
45
+ .description('Rename one equipped Persona operation for the active account')
46
+ .action(async (currentId: string, newId: string) => {
47
+ const { workspaceDir, profile } = context();
48
+ console.log(JSON.stringify(await renameCapabilityOperationWhenIdle(
49
+ workspaceDir, profile, 'persona', currentId, newId,
50
+ ), null, 2));
51
+ });
52
+
42
53
  persona
43
54
  .command('list')
44
55
  .description('List local persona presets for the active account')
@@ -0,0 +1,136 @@
1
+ import { rmSync } from 'node:fs';
2
+ import type { AuthProfile } from './auth.js';
3
+ import {
4
+ capabilityWorkspacePath,
5
+ readCapabilityWorkspaceRegistry,
6
+ writeCapabilityWorkspaceRegistry,
7
+ type CapabilityWorkspaceType,
8
+ } from './capability-workspace.js';
9
+ import { readGameplayConfig, writeGameplayConfig } from './gameplay-config.js';
10
+ import { readPersonaSelection, writePersonaSelection } from './persona.js';
11
+ import { getUserDataAccountPersonaSelectionFile, getUserDataAccountTriggersDir } from './user-data.js';
12
+ import { listClawclawTriggerSources } from '../runtime/clawclaw/plugins/trigger/trigger-source.js';
13
+ import { sendProfileOwnerControlRequest } from '../runtime/owner-control.js';
14
+
15
+ export type RenameableCapabilityType = Exclude<CapabilityWorkspaceType, 'skill'>;
16
+
17
+ const MODULE_OPERATION_NAME = /^[A-Za-z0-9][A-Za-z0-9._-]{0,255}$/;
18
+
19
+ function validName(type: RenameableCapabilityType, name: string): boolean {
20
+ if (type !== 'persona') return MODULE_OPERATION_NAME.test(name);
21
+ return !!name.trim() && name === name.trim() && name.length <= 255
22
+ && !/[\\/\u0000-\u001f]/u.test(name) && name !== '.' && name !== '..';
23
+ }
24
+
25
+ export async function renameCapabilityOperationWhenIdle(
26
+ workspaceDir: string,
27
+ profile: AuthProfile,
28
+ type: RenameableCapabilityType,
29
+ currentName: string,
30
+ newName: string,
31
+ ownerRequest: typeof sendProfileOwnerControlRequest = sendProfileOwnerControlRequest,
32
+ ) {
33
+ let owner;
34
+ try {
35
+ owner = await ownerRequest(profile, 'behavior_status', {}, 750);
36
+ } catch (error) {
37
+ const code = (error as NodeJS.ErrnoException).code;
38
+ if (code !== 'ENOENT' && code !== 'ECONNREFUSED') {
39
+ throw new Error('capability_operation_name_runtime_check_failed', { cause: error });
40
+ }
41
+ owner = null;
42
+ }
43
+ if (owner) throw new Error('capability_operation_name_runtime_active');
44
+ return renameCapabilityOperation(workspaceDir, profile, type, currentName, newName);
45
+ }
46
+
47
+ export function renameCapabilityOperation(
48
+ workspaceDir: string,
49
+ profile: Pick<AuthProfile, 'apiKey'>,
50
+ type: RenameableCapabilityType,
51
+ currentName: string,
52
+ newName: string,
53
+ ) {
54
+ if (!validName(type, newName)) {
55
+ throw new Error(`capability_operation_name_invalid:${type}:${newName}`);
56
+ }
57
+ const registry = readCapabilityWorkspaceRegistry(workspaceDir, profile);
58
+ const matches = Object.values(registry.entries).filter(entry => (
59
+ entry.type === type && entry.runtimeId === currentName
60
+ && entry.selection === 'equipped' && !entry.hub?.cloudStatus
61
+ && entry.operationNameAssigned !== false
62
+ ));
63
+ if (matches.length !== 1) {
64
+ throw new Error(`capability_operation_name_target_${matches.length ? 'ambiguous' : 'not_equipped'}:${type}:${currentName}`);
65
+ }
66
+ const entry = matches[0]!;
67
+ const path = capabilityWorkspacePath(workspaceDir, profile, entry);
68
+ const identity = { resource_id: entry.hub?.resourceId, declared_id: entry.declaredId ?? currentName,
69
+ working_copy_path: path };
70
+ if (newName === currentName) {
71
+ return { type, old_id: currentName, id: newName, changed: false,
72
+ scope: 'account_operation_name', effective: 'next_runtime',
73
+ ...identity, reload_required_before_game: false };
74
+ }
75
+ if (Object.values(registry.entries).some(other => (
76
+ other.key !== entry.key && other.type === type && other.runtimeId === newName
77
+ && other.operationNameAssigned !== false
78
+ ))) {
79
+ throw new Error(`capability_operation_name_conflict:${type}:${newName}`);
80
+ }
81
+
82
+ const beforeRegistry = structuredClone(registry);
83
+ const beforeGameplay = type === 'persona' ? undefined : readGameplayConfig(workspaceDir, profile);
84
+ const nextGameplay = beforeGameplay ? structuredClone(beforeGameplay) : undefined;
85
+ if (nextGameplay && type === 'behavior') {
86
+ for (const role of Object.keys(nextGameplay.fallback_behaviors) as Array<keyof typeof nextGameplay.fallback_behaviors>) {
87
+ if (nextGameplay.fallback_behaviors[role] === currentName) {
88
+ nextGameplay.fallback_behaviors[role] = newName;
89
+ }
90
+ }
91
+ nextGameplay.disabled_behaviors = [...new Set(nextGameplay.disabled_behaviors.map(id =>
92
+ id === currentName ? newName : id))];
93
+ for (const trigger of Object.values(nextGameplay.triggers)) {
94
+ if (trigger.behavior === currentName) trigger.behavior = newName;
95
+ }
96
+ for (const trigger of listClawclawTriggerSources(getUserDataAccountTriggersDir(workspaceDir, profile))) {
97
+ if (trigger.manifest.defaultBehavior === currentName
98
+ && nextGameplay.triggers[trigger.id]?.behavior === undefined) {
99
+ nextGameplay.triggers[trigger.id] = { ...nextGameplay.triggers[trigger.id], behavior: newName };
100
+ }
101
+ }
102
+ } else if (nextGameplay) {
103
+ nextGameplay.disabled_perception_modules = [...new Set(nextGameplay.disabled_perception_modules.map(id =>
104
+ id === currentName ? newName : id))];
105
+ }
106
+ const beforePersona = type === 'persona' ? readPersonaSelection(workspaceDir, profile) : undefined;
107
+ const nextPersona = beforePersona?.source === 'local' && beforePersona.id === currentName
108
+ ? { source: 'local' as const, id: newName } : undefined;
109
+
110
+ entry.runtimeId = newName;
111
+ entry.updatedAt = new Date().toISOString();
112
+ try {
113
+ writeCapabilityWorkspaceRegistry(workspaceDir, profile, registry);
114
+ if (nextGameplay && JSON.stringify(nextGameplay) !== JSON.stringify(beforeGameplay)) {
115
+ writeGameplayConfig(nextGameplay, workspaceDir, profile);
116
+ }
117
+ if (nextPersona) writePersonaSelection(workspaceDir, profile, nextPersona);
118
+ } catch (error) {
119
+ // Registry and command bindings must never intentionally disagree after a
120
+ // failed rename. Restore every touched local source of operation names.
121
+ try {
122
+ writeCapabilityWorkspaceRegistry(workspaceDir, profile, beforeRegistry);
123
+ if (beforeGameplay) writeGameplayConfig(beforeGameplay, workspaceDir, profile);
124
+ if (type === 'persona') {
125
+ if (beforePersona) writePersonaSelection(workspaceDir, profile, beforePersona);
126
+ else rmSync(getUserDataAccountPersonaSelectionFile(workspaceDir, profile), { force: true });
127
+ }
128
+ } catch (rollbackError) {
129
+ throw new Error(`capability_operation_name_rollback_failed:${String(rollbackError)}`, { cause: error });
130
+ }
131
+ throw error;
132
+ }
133
+ return { type, old_id: currentName, id: newName, changed: true,
134
+ scope: 'account_operation_name', effective: 'next_runtime',
135
+ ...identity, reload_required_before_game: true };
136
+ }
@@ -418,6 +418,11 @@ function shortBody(event: Record<string, any>, ctx: EventFormatContext): string
418
418
  }
419
419
  case 'reminder.task':
420
420
  return firstString(event, ['text'], '任务提醒。');
421
+ case 'reminder.speech': {
422
+ const actor = event.actor && typeof event.actor === 'object' ? event.actor : {};
423
+ const speaker = playerLabel(actor.name ?? event.actor_name, actor.seat ?? event.actor_seat, ctx);
424
+ return `${speaker}在${firstString(event, ['room'])}说:${truncate(event.text, maxTextLength)}`;
425
+ }
421
426
  case 'tasks_changed':
422
427
  return `任务列表已更新(${firstString(event, ['reason'])})。`;
423
428
  case 'players_changed':
@@ -5,7 +5,7 @@ import type { ResolvedClawclawPerceptionSource } from '../perception/perception-
5
5
  import { freshClawclawGameState } from '../../runtime-state.js';
6
6
  import { createCanonicalGameState } from '../../behavior-input.js';
7
7
  import { ObservationFrameProjector } from '../../observation-frame-projector.js';
8
- import { REMINDER_EVENT_TYPES, REMINDER_FACT_TYPES, REMINDER_TOPICS } from './reminder-rules.js';
8
+ import { REMINDER_EVENT_TYPES, REMINDER_EVENT_TYPE_BY_TOPIC, REMINDER_FACT_TYPES, REMINDER_TOPICS } from './reminder-rules.js';
9
9
  import { ReminderRunner } from './reminder-runner.js';
10
10
  import { resolveClawclawResourceMetadata } from '../../../../sdk/resource-metadata.js';
11
11
 
@@ -58,7 +58,8 @@ export class ClawclawReminderPlugin implements RuntimeEpochPlugin<Record<string,
58
58
  if (checkpoint?.states) this.checkpoint = structuredClone({
59
59
  gameId: checkpoint.gameId, previousTick: checkpoint.previousTick,
60
60
  previousConnectionId: checkpoint.previousConnectionId,
61
- states: checkpoint.states.tasks ? { tasks: checkpoint.states.tasks } : {},
61
+ states: Object.fromEntries(REMINDER_TOPICS.filter(topic => checkpoint.states[topic])
62
+ .map(topic => [topic, checkpoint.states[topic]])),
62
63
  });
63
64
  }
64
65
  async stop(): Promise<void> { await Promise.all([...this.runners.values()].map(r => r.stop())); this.runners.clear(); }
@@ -104,8 +105,9 @@ export class ClawclawReminderPlugin implements RuntimeEpochPlugin<Record<string,
104
105
  const previous = next.states[topic];
105
106
  const moduleInput: ReminderInput = {
106
107
  scope: input.epoch.scope, frame, gameState: game, taskChanges, boundary,
107
- facts: facts.map(e => ({ eventId: e.eventId, epochId: e.epochSeq, type: e.type,
108
- occurredAt: e.occurredAt, producer: e.producer, payload: e.payload })),
108
+ facts: facts.filter(e => topic !== 'speech' || !e.replayed)
109
+ .map(e => ({ eventId: e.eventId, epochId: e.epochSeq, type: e.type,
110
+ occurredAt: e.occurredAt, producer: e.producer, replayed: e.replayed, payload: e.payload })),
109
111
  config: selected.reminder!.config ?? {}, state: previous?.provider === selected.id ? previous.value : undefined,
110
112
  nowMs: input.frame.observedAtMs ?? input.frame.receivedAtMs,
111
113
  };
@@ -118,19 +120,20 @@ export class ClawclawReminderPlugin implements RuntimeEpochPlugin<Record<string,
118
120
  const accepted: RuntimeEventProposal[] = [];
119
121
  const keys = new Set<string>();
120
122
  for (const event of result.events ?? []) {
121
- if (!event || event.type !== 'reminder.task' || typeof event.key !== 'string'
123
+ if (!event || event.type !== REMINDER_EVENT_TYPE_BY_TOPIC[topic] || typeof event.key !== 'string'
122
124
  || !event.key.trim() || event.key.length > 512 || keys.has(event.key)
123
125
  || typeof event.wakeAgent !== 'boolean' || !event.payload || Array.isArray(event.payload)
124
126
  || typeof event.payload.text !== 'string' || !event.payload.text.trim()) {
125
- throw new Error('Invalid task reminder event.');
127
+ throw new Error(`Invalid ${topic} reminder event.`);
126
128
  }
127
129
  keys.add(event.key);
128
130
  accepted.push({ type: event.type, dedupeKey: JSON.stringify([selected.id, event.key]),
129
131
  dedupeScope: 'segment', wakeAgent: event.wakeAgent, payload: { ...event.payload },
130
132
  occurredAt: new Date(moduleInput.nowMs).toISOString() });
131
133
  }
132
- // Recovery/initial snapshots establish private state, never replay notices.
133
- if (!boundary && game) events.push(...accepted);
134
+ // Task snapshots establish baselines. Fresh speech remains an occurrence
135
+ // even in the first/reconnected frame; replayed speech is excluded from input.
136
+ if (game && (topic === 'speech' || !boundary)) events.push(...accepted);
134
137
  next.states[topic] = { provider: selected.id, value: structuredClone(result.state) };
135
138
  } catch (error) { this.markFailed(topic, context, error); }
136
139
  }
@@ -1,5 +1,5 @@
1
1
  import { REMINDER_PLUGIN_API_VERSION, type ClawclawReminderManifest } from '../../sdk/perception-plugin/reminder.js';
2
- import { REMINDER_FACT_TYPES } from '../../sdk/perception-plugin/reminder-rules.js';
2
+ import { REMINDER_FACT_TYPES_BY_TOPIC, REMINDER_TOPICS } from '../../sdk/perception-plugin/reminder-rules.js';
3
3
  import { hasValidClawclawResourceLocalizations } from '../../sdk/resource-metadata.js';
4
4
  import { normalizeBehaviorInput, normalizeBehaviorInputFields } from './behavior-input-fields.js';
5
5
 
@@ -13,9 +13,9 @@ export function normalizeReminderManifest(value: unknown, requireCurrentVersion
13
13
  || typeof m.description !== 'string' || !m.description.trim()
14
14
  || (m.name !== undefined && (typeof m.name !== 'string' || !m.name.trim()))
15
15
  || !hasValidClawclawResourceLocalizations(m.localizations)
16
- || m.topic !== 'tasks'
16
+ || !REMINDER_TOPICS.includes(m.topic)
17
17
  || !Array.isArray(m.consumes) || new Set(m.consumes).size !== m.consumes.length
18
- || m.consumes.some(type => !(REMINDER_FACT_TYPES as readonly string[]).includes(type))
18
+ || m.consumes.some(type => !(REMINDER_FACT_TYPES_BY_TOPIC[m.topic] as readonly string[]).includes(type))
19
19
  || (m.config !== undefined && (!m.config || typeof m.config !== 'object' || Array.isArray(m.config)))
20
20
  || Object.keys(m).some(key => !['apiVersion', 'kind', 'id', 'name', 'description', 'localizations',
21
21
  'topic', 'consumes', 'inputs', 'config'].includes(key))) throw new Error('Invalid perception reminder manifest.');
@@ -110,7 +110,6 @@ export const CLAWCLAW_BACKEND_AGENT_EVENT_TYPES = [
110
110
  'no_exile',
111
111
  'vote_speech_phase_ended',
112
112
  'death_speech',
113
- 'wandering_speech',
114
113
  'meeting_briefing',
115
114
  'speech',
116
115
  'speech_skipped',
@@ -181,6 +180,7 @@ export const CLAWCLAW_LOCAL_AGENT_EVENT_TYPES = [
181
180
  'behavior.replaced',
182
181
  'players_changed',
183
182
  'reminder.task',
183
+ 'reminder.speech',
184
184
  'emergency_countdown_warning',
185
185
  'ability.ready',
186
186
  'ability.remaining_uses_changed',
@@ -189,6 +189,7 @@ export const CLAWCLAW_LOCAL_AGENT_EVENT_TYPES = [
189
189
 
190
190
  /** Durable inputs used by projectors, but never sent directly to the Agent. */
191
191
  export const CLAWCLAW_INTERNAL_BACKEND_EVENT_TYPES = [
192
+ 'wandering_speech',
192
193
  'task_completed',
193
194
  'task_interrupted',
194
195
  'task_sabotaged',
@@ -1,12 +1,18 @@
1
1
  import type { ReminderInput, ReminderMode, ReminderResult, ReminderTopic, ReminderFact, ReminderTaskChange, ReminderEvent } from './reminder.js';
2
2
 
3
- export const REMINDER_FACT_TYPES = [
3
+ export const TASK_REMINDER_FACT_TYPES = [
4
4
  'ability.ready', 'ability.remaining_uses_changed', 'ability.exhausted', 'tasks_changed',
5
5
  'task_started', 'task_progress', 'task_assigned', 'task_completed', 'task_interrupted', 'task_sabotaged',
6
6
  'role_assigned', 'emergency_started', 'emergency_resolved', 'emergency_interrupted', 'meeting_briefing',
7
7
  ] as const;
8
- export const REMINDER_EVENT_TYPES = ['reminder.task'] as const;
9
- export const REMINDER_TOPICS: readonly ReminderTopic[] = ['tasks'];
8
+ export const REMINDER_FACT_TYPES_BY_TOPIC = {
9
+ tasks: TASK_REMINDER_FACT_TYPES,
10
+ speech: ['wandering_speech'],
11
+ } as const;
12
+ export const REMINDER_EVENT_TYPE_BY_TOPIC = { tasks: 'reminder.task', speech: 'reminder.speech' } as const;
13
+ export const REMINDER_FACT_TYPES = [...TASK_REMINDER_FACT_TYPES, 'wandering_speech'] as const;
14
+ export const REMINDER_EVENT_TYPES = ['reminder.task', 'reminder.speech'] as const;
15
+ export const REMINDER_TOPICS: readonly ReminderTopic[] = ['tasks', 'speech'];
10
16
  export function isReminderMode(value: unknown): value is ReminderMode {
11
17
  return value === 'wake' || value === 'silent' || value === 'state_only';
12
18
  }
@@ -61,8 +67,31 @@ function explained(fact: ReminderFact, change: ReminderTaskChange, input: Remind
61
67
  }
62
68
  return false;
63
69
  }
64
- /** Optional task policy: classify individual changes, never re-deliver the whole raw fact. */
70
+ /** Nearby speech is a backend fact; only its Agent notification is optional. */
71
+ export function speechReminder(input: ReminderInput): ReminderResult {
72
+ if (Object.keys(input.config).some(key => key !== 'receive')
73
+ || (input.config.receive !== undefined && typeof input.config.receive !== 'boolean')) {
74
+ throw new Error('Speech reminder config must contain only a boolean receive.');
75
+ }
76
+ if (input.config.receive === false) return { events: [] };
77
+ const self = input.gameState?.you?.player;
78
+ return { events: input.facts.flatMap(fact => {
79
+ if (fact.type !== 'wandering_speech' || fact.replayed) return [];
80
+ const actor = record(fact.payload.actor);
81
+ const seat = actor.seat ?? fact.payload.actor_seat;
82
+ const name = actor.name ?? fact.payload.actor_name;
83
+ // GameSync includes the speaker among the frozen nearby recipients.
84
+ const own = seat !== undefined && self?.seat !== undefined ? seat === self.seat
85
+ : typeof name === 'string' && self?.name !== undefined && name === self.name;
86
+ if (own || typeof fact.payload.text !== 'string' || !fact.payload.text.trim()) return [];
87
+ return [{ type: 'reminder.speech' as const, key: `fact:${fact.eventId}`, wakeAgent: true,
88
+ payload: { ...fact.payload, text: fact.payload.text, source_event_id: fact.eventId } }];
89
+ }) };
90
+ }
91
+
92
+ /** Optional reminder policy; raw facts always remain available to computation plugins. */
65
93
  export function defaultReminder(topic: ReminderTopic, input: ReminderInput): ReminderResult {
94
+ if (topic === 'speech') return speechReminder(input);
66
95
  const config = validateDefaultConfig(topic, input.config);
67
96
  const events: ReminderEvent[] = [];
68
97
  if (input.boundary) return { events };
@@ -3,9 +3,12 @@ import type { BehaviorInputFieldSpec } from '../behavior-plugin/index.js';
3
3
 
4
4
  /** Reminder classes use the same public Perception API version and resource lifecycle. */
5
5
  export const REMINDER_PLUGIN_API_VERSION = 2 as const;
6
- export type ReminderTopic = 'tasks';
6
+ export type ReminderTopic = 'tasks' | 'speech';
7
7
  export type ReminderMode = 'wake' | 'silent' | 'state_only';
8
- export interface ReminderFact extends GameEvent { readonly producer: 'backend_push' | 'local_synth' }
8
+ export interface ReminderFact extends GameEvent {
9
+ readonly producer: 'backend_push' | 'local_synth';
10
+ readonly replayed?: boolean;
11
+ }
9
12
  /** Structural task changes, not Agent notifications or inferred completion facts. */
10
13
  export interface ReminderTaskChange {
11
14
  readonly key: string;
@@ -37,7 +40,7 @@ export interface ReminderResult {
37
40
  readonly events?: readonly ReminderEvent[];
38
41
  }
39
42
  export interface ReminderEvent {
40
- readonly type: 'reminder.task';
43
+ readonly type: 'reminder.task' | 'reminder.speech';
41
44
  /** Stable per occurrence, retained across retry/recovery. */
42
45
  readonly key: string;
43
46
  readonly wakeAgent: boolean;