@myclaw163/clawclaw-cli 0.8.32 → 0.8.33

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myclaw163/clawclaw-cli",
3
- "version": "0.8.32",
3
+ "version": "0.8.33",
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.107
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
  跟上当前参与后,不要把玩家原话机械套进固定句式表。先分开判断三件事:玩家是在继续当前参与还是进入新的参与;目标房间的精确类型是否已经知道;执行目标是否需要退出当前参与。
@@ -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 <邀请码>] # 邀请码是否必填由服务器决定
@@ -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
+ }