@myclaw163/clawclaw-cli 0.8.18 → 0.8.19

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.
@@ -207,7 +207,7 @@ CCL 必须能确定音频格式才会上传。优先使用响应 `Content-Type`
207
207
 
208
208
  `ccl load`、资源管理命令或 Owner 启动只要首次读到这些旧字段,就会把迁移结果写回原文件。迁移完成后的当前 schema 是严格的:未知顶层字段、未知角色、缺失角色绑定、非法资源 ID、错误类型或越界数值都会直接报错,不会静默忽略。经常切换不同 CCL 版本时,应先备份 `user-data/gameplay.json`;旧版本若不认识 Behavior/Trigger 当前字段,不应与新版本轮流写同一个 workspace。
209
209
 
210
- 官方、第三方和纯本地能力统一使用账号 `capabilities/<type>/` 工作区,Hub immutable 版本只保存在 revision cache。主目录中的合法本地资源都会自动上传;`drafts` 不扫描、不上传。新资源第一次发现时出现在 `capabilities.selection_required`,用 `ccl capability equip` 或 `ccl capability unequip` 保存一次装配选择;资源上传成功后,同一选择会应用到新建的 Hub Workspace Item。Behavior 仍以 manifest `id` 作为 `list`、`start`、fallback 和 Trigger 绑定的稳定身份。
210
+ 官方、第三方和纯本地能力统一使用账号 `capabilities/<type>/` 工作区,Hub immutable 版本只保存在 revision cache。主目录中的合法本地资源都会自动上传;`drafts` 不扫描、不上传。新资源第一次发现时出现在 `capabilities.selection_required`,用 `ccl capability equip` 或 `ccl capability unequip` 保存一次装配选择;资源上传成功后,同一选择会应用到新建的 Hub Workspace Item。策略、感知和人设按账号、类型分配持久操作名:第一个可用名称为原始 ID,重名时依次寻找空闲的 `_1`、`_2` 后缀。已分配名称不会因取消装配、文件缺失或版本更新而重新分配给另一项。`registry.json` 的 `runtimeId` 是操作名,`declaredId` 是原始声明;Hub 同步和上传仍使用 `hub.resourceId` 及原始文件内容。`list/info/start`、装配、冲突处理、fallback 和 Trigger 配置使用操作名。同一资源本地上传后再由 Hub 装配仍沿用原操作名;不同资源即使原始 ID 相同也能并存。辅助 Skill 本轮不纳入。
211
211
 
212
212
  分角色 `fallback_behaviors` 现在表示“角色确定后立即启动的默认 long Behavior”。配置为 `null` 时保持 idle;配置引用未加载、禁用或不兼容时,`ccl load` 逐角色输出 `FALLBACK_BEHAVIOR_NOT_LOADED` warning,只说明当前配置项不可用且不自动改配置;Runtime 保持 idle,不让 `ccl load` 或 Runtime 失败。
213
213
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myclaw163/clawclaw-cli",
3
- "version": "0.8.18",
3
+ "version": "0.8.19",
4
4
  "type": "module",
5
5
  "description": "ClawClaw social deduction game CLI",
6
6
  "bin": {
@@ -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.99
4
+ version: 4.8.100
5
5
  ---
6
6
 
7
7
  # 龙虾杀(ClawClaw)
@@ -14,6 +14,8 @@ version: 4.8.99
14
14
 
15
15
  ## 1. 运行方式
16
16
 
17
+ 策略、感知和人设的本地操作名可能带 `_1`、`_2` 后缀,用于区分原始 ID 相同的不同资源。执行 list/info/start、装配、冲突选择和配置时,使用 CCL 返回的完整操作名,不自行去掉后缀、不按显示名称猜测。操作名按账号保存,取消装配后不重新编号;它不改变脚本内容或 Hub 身份。策略详情的 `declared_id` 是脚本原始 ID,`working_copy_path` 是编辑入口,`resource_id` 是 Hub 身份。辅助 Skill 暂不使用这套重名处理。
18
+
17
19
  ### 1.1 默认使用 Monitor 直推 + `ccl events` 详情
18
20
 
19
21
  `ccl` 是 `clawclaw-cli` 的短别名。短同步命令(`ccl account`、`ccl load`、`ccl behavior`、`ccl trigger`、`ccl speak`、`ccl vote`、`ccl aside` 等)可按宿主执行,有对应 typed tool 时优先使用。Claude/Claude Code 的局内移动、任务、追踪、击杀、报告等持续行动统一通过 shell `ccl behavior ...`;`speak`、`vote`、`aside` 仍是三个独立直连命令,绝不包装成 Behavior。
@@ -46,12 +46,12 @@ Runtime 另外允许 `duration_ms` 或 `timeout_ms`,两者只能选一个,
46
46
 
47
47
  ### 修改已安装策略的源码
48
48
 
49
- 先用 `ccl behavior list` / `ccl behavior info <id>` 确认有效策略与来源;这些输出不提供编辑绝对路径。再用 `ccl behavior --help` 查看当前账号的 Behavior 主目录,用 `ccl capability list` 找到对应 `type=behavior`、`runtimeId` 的 registry 条目;Hub 来源还须匹配 `hub.resourceId` 与 `info.resource_id`。条目的 `relativePath` 相对于当前账号的 `capabilities/`,据此定位文件,不凭账号名、文件名或目录名猜测。
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` 查询对应 `runtimeId`、`declaredId` 和 `hub.resourceId`。不要从相同显示名称推断两项是同一资源,不要去掉后缀后再执行指令。
50
50
 
51
51
  | 账号内路径 | 用途 |
52
52
  |---|---|
53
53
  | `capabilities/behaviors/<资源目录>/xxx.ts` | Hub 策略的可编辑工作副本;准确位置以 registry 为准,fork 后目录名不一定等于当前资源 ID |
54
- | `capabilities/behaviors/xxx.ts` | 纯本地策略;已装配且同 ID 时优先于 Hub 策略 |
54
+ | `capabilities/behaviors/xxx.ts` | 本地主目录策略;与其他同原始 ID 资源通过独立操作名并存,不覆盖 Hub 条目 |
55
55
  | `hub-loadout/revisions/.../runtime/behaviors/<id>.ts` | CCL 生成的运行副本,不直接编辑 |
56
56
  | 旧 `behaviors/local/`、`local/behaviors/` 或主目录内另建的 `local/` 子目录 | 当前发现流程不扫描,不作为修改入口 |
57
57
 
@@ -6,6 +6,8 @@
6
6
 
7
7
  ## 赛前(设置)
8
8
 
9
+ 策略、感知和人设的命令参数使用 CCL 返回的本地操作名,如 `xx`、`xx_1`;不同资源同名时均可存在,名称按账号持久保存,取消装配或更新版本不重新编号。`behavior list/info` 和 `perception --list` 返回 `declared_id`、`working_copy_path`、`runtime_source_path`;`persona list` 返回操作名、原名、路径和可用的 Hub 身份。后缀不写入原脚本或 Hub。辅助 Skill 的重名规则本轮不变。
10
+
9
11
  ```bash
10
12
  ccl account register --check # 先探:本服务器是否需要邀请码 + 该用哪段固定话术;绝不建号
11
13
  ccl account register [--name <名称>] [--invite-code <邀请码>] # 邀请码是否必填由服务器决定
@@ -108,6 +108,9 @@ function sourceEntry(
108
108
  const loadable = versionCompatible && compatibilityError === undefined;
109
109
  return {
110
110
  id: source.id,
111
+ declared_id: source.declaredId ?? source.id,
112
+ working_copy_path: source.workingCopyPath ?? source.sourcePath,
113
+ runtime_source_path: source.sourcePath,
111
114
  name: source.name,
112
115
  description: source.description,
113
116
  api_version: source.apiVersion ?? null,
@@ -59,6 +59,7 @@ import {
59
59
  classifyStrategyLifecycle,
60
60
  pendingCapabilitySelections,
61
61
  registerDiscoveredCapability,
62
+ capabilityEntryForPath,
62
63
  } from '../lib/capability-workspace.js';
63
64
  import { syncCapabilitiesToCloud } from '../lib/capability-cloud-sync.js';
64
65
  import {
@@ -349,7 +350,7 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
349
350
  registerDiscoveredCapability(workspaceDir, profile, {
350
351
  type: 'behavior',
351
352
  path: workingPath,
352
- runtimeId: source.id,
353
+ runtimeId: source.declaredId ?? source.id,
353
354
  title: source.name,
354
355
  description: source.description,
355
356
  strategyLifecycle: classifyStrategyLifecycle(readFileSync(workingPath, 'utf8')),
@@ -380,9 +381,11 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
380
381
  for (const path of listCapabilityModuleCandidates(localBehaviorDir)) {
381
382
  if (localBehaviorSourcePaths.has(resolve(path))) continue;
382
383
  const diagnostic = diagnoseRejectedCapabilityModule('behavior', path);
383
- if (diagnostic.declaredId && disabledBehaviors.has(diagnostic.declaredId)) continue;
384
+ const operationName = capabilityEntryForPath(workspaceDir, profile, 'behavior', path)?.runtimeId ?? diagnostic.declaredId;
385
+ if (operationName && disabledBehaviors.has(operationName)) continue;
384
386
  expectedLocalBehaviors += 1;
385
- capabilityWarnings.push(warningFromStaticDiagnostic('behavior', 'local', diagnostic));
387
+ capabilityWarnings.push({ ...warningFromStaticDiagnostic('behavior', 'local', diagnostic),
388
+ ...(operationName ? { id: operationName } : {}) });
386
389
  }
387
390
  if (activeWorkspace) {
388
391
  const discoveredPaths = new Set(hubBehaviors.map(({ sourcePath }) => resolve(sourcePath)));
@@ -511,7 +514,7 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
511
514
  registerDiscoveredCapability(workspaceDir, profile, {
512
515
  type: 'perception',
513
516
  path: workingPath,
514
- runtimeId: source.id,
517
+ runtimeId: source.declaredId ?? source.id,
515
518
  title: source.name,
516
519
  description: source.description,
517
520
  selectedByHub: true,
@@ -544,9 +547,11 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
544
547
  for (const path of listCapabilityModuleCandidates(localPerceptionDir)) {
545
548
  if (localPerceptionSourcePaths.has(resolve(path))) continue;
546
549
  const diagnostic = diagnoseRejectedCapabilityModule('perception', path);
547
- if (diagnostic.declaredId && disabledPerceptions.has(diagnostic.declaredId)) continue;
550
+ const operationName = capabilityEntryForPath(workspaceDir, profile, 'perception', path)?.runtimeId ?? diagnostic.declaredId;
551
+ if (operationName && disabledPerceptions.has(operationName)) continue;
548
552
  expectedLocalPerceptions += 1;
549
- capabilityWarnings.push(warningFromStaticDiagnostic('perception', 'local', diagnostic));
553
+ capabilityWarnings.push({ ...warningFromStaticDiagnostic('perception', 'local', diagnostic),
554
+ ...(operationName ? { id: operationName } : {}) });
550
555
  }
551
556
  if (activeWorkspace) {
552
557
  const discoveredPaths = new Set(hubPerceptions.map(({ sourcePath }) => resolve(sourcePath)));
@@ -702,9 +707,9 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
702
707
  registerDiscoveredCapability(workspaceDir, profile, {
703
708
  type: 'persona',
704
709
  path: snapshot.persona.path,
705
- runtimeId: snapshot.persona.id ?? basename(snapshot.persona.path, extname(snapshot.persona.path)),
706
- title: snapshot.persona.id ?? basename(snapshot.persona.path, extname(snapshot.persona.path)),
707
- description: `Persona ${snapshot.persona.id ?? basename(snapshot.persona.path)}`,
710
+ runtimeId: basename(snapshot.persona.path, extname(snapshot.persona.path)),
711
+ title: basename(snapshot.persona.path, extname(snapshot.persona.path)),
712
+ description: `Persona ${basename(snapshot.persona.path)}`,
708
713
  selectedByHub: true,
709
714
  hub: {
710
715
  resourceId: hubPersonaItem.resourceId,
@@ -58,6 +58,7 @@ Perception modules:
58
58
  const workspaceDir = getWorkspaceDir();
59
59
  const profile = activeProfile(dependencies);
60
60
  ensureAccountUserDataLayout(workspaceDir, profile);
61
+ const localCapabilities = discoverLocalCapabilities(workspaceDir, profile).perceptions;
61
62
  const snapshot = filterInactiveAgentWorkspaceSnapshot(
62
63
  workspaceDir,
63
64
  profile,
@@ -67,7 +68,7 @@ Perception modules:
67
68
  ? listAgentWorkspacePerceptionSources(workspaceDir, profile, snapshot)
68
69
  : [];
69
70
  const hubIds = new Set(hub.map(({ id }) => id));
70
- const local = discoverLocalCapabilities(workspaceDir, profile).perceptions
71
+ const local = localCapabilities
71
72
  .filter(({ entry }) => !snapshot?.items.perception.some(item => item.resourceId === entry.hub?.resourceId))
72
73
  .map(({ source }) => source);
73
74
  const registered = (id: string) => Object.values(readCapabilityWorkspaceRegistry(workspaceDir, profile).entries)
@@ -105,6 +106,9 @@ Perception modules:
105
106
  const disabled = new Set(config.disabled_perception_modules);
106
107
  const installed = mergeAgentWorkspacePerceptionSources(local, hub).map((source) => ({
107
108
  id: source.id,
109
+ declared_id: source.declaredId ?? source.id,
110
+ working_copy_path: source.workingCopyPath ?? source.sourcePath,
111
+ runtime_source_path: source.sourcePath,
108
112
  name: source.name,
109
113
  description: source.description,
110
114
  source: hubIds.has(source.id) ? 'hub' : 'local',
@@ -1,4 +1,5 @@
1
1
  import { Command } from 'commander';
2
+ import { existsSync } from 'node:fs';
2
3
  import { AuthStore } from '../lib/auth.js';
3
4
  import { getWorkspaceDir } from '../lib/init-command.js';
4
5
  import {
@@ -15,7 +16,7 @@ import {
15
16
  import { loadPersonaSnapshot } from '../lib/load-context.js';
16
17
  import { discoverLocalCapabilities } from '../lib/capability-discovery.js';
17
18
  import { setCapabilitySelection } from '../lib/capability-workspace.js';
18
- import { readCapabilityWorkspaceRegistry, writeCapabilityWorkspaceRegistry } from '../lib/capability-workspace.js';
19
+ import { readCapabilityWorkspaceRegistry, writeCapabilityWorkspaceRegistry, capabilityEntryForPath, capabilityWorkspacePath } from '../lib/capability-workspace.js';
19
20
  import { selectCapability } from '../lib/capability-selection.js';
20
21
  import { HubClient } from '../lib/hub-client.js';
21
22
  import { readLocalAgentWorkspaceSnapshot } from '../lib/agent-workspace-sync.js';
@@ -42,8 +43,14 @@ export function createPersonaCommand(): Command {
42
43
  .command('list')
43
44
  .description('List local persona presets for the active account')
44
45
  .action(() => {
45
- const { directory } = context();
46
- const presets = listPersonaPresets(directory).map(({ id, name }) => ({ id, name, source: 'local' }));
46
+ const { workspaceDir, profile } = context();
47
+ discoverLocalCapabilities(workspaceDir, profile);
48
+ resolveActivePersonaFile();
49
+ const presets = Object.values(readCapabilityWorkspaceRegistry(workspaceDir, profile).entries)
50
+ .filter(entry => entry.type === 'persona' && existsSync(capabilityWorkspacePath(workspaceDir, profile, entry)))
51
+ .map(entry => ({ id: entry.runtimeId, name: entry.title, declared_id: entry.declaredId ?? entry.runtimeId,
52
+ source: entry.hub ? 'hub' : 'local', resource_id: entry.hub?.resourceId,
53
+ path: capabilityWorkspacePath(workspaceDir, profile, entry), selection: entry.selection }));
47
54
  console.log(JSON.stringify({ presets }, null, 2));
48
55
  });
49
56
 
@@ -68,11 +75,12 @@ export function createPersonaCommand(): Command {
68
75
  const { directory, workspaceDir, profile } = context();
69
76
  const created = createPersonaPreset(name, directory);
70
77
  discoverLocalCapabilities(workspaceDir, profile);
71
- await selectCapability(workspaceDir, profile, 'persona', created.id, true);
72
- writePersonaSelection(workspaceDir, profile, { source: 'local', id: created.id });
78
+ const operationName = capabilityEntryForPath(workspaceDir, profile, 'persona', created.path)!.runtimeId;
79
+ await selectCapability(workspaceDir, profile, 'persona', operationName, true);
80
+ writePersonaSelection(workspaceDir, profile, { source: 'local', id: operationName });
73
81
  console.log(JSON.stringify({
74
82
  path: created.path,
75
- preset: { id: created.id, name: created.name, source: 'local' },
83
+ preset: { id: operationName, name: created.name, source: 'local' },
76
84
  }, null, 2));
77
85
  });
78
86
 
@@ -81,17 +89,29 @@ export function createPersonaCommand(): Command {
81
89
  .description('Select an account-local Persona preset')
82
90
  .action(async (presetName: string) => {
83
91
  const { directory, workspaceDir, profile } = context();
92
+ discoverLocalCapabilities(workspaceDir, profile);
93
+ resolveActivePersonaFile();
94
+ const named = Object.values(readCapabilityWorkspaceRegistry(workspaceDir, profile).entries)
95
+ .find(entry => entry.type === 'persona' && entry.runtimeId === presetName);
96
+ if (named) {
97
+ const entry = await selectCapability(workspaceDir, profile, 'persona', named.runtimeId, true);
98
+ writePersonaSelection(workspaceDir, profile, entry.hub ? { source: 'hub' } : { source: 'local', id: entry.runtimeId });
99
+ console.log(JSON.stringify({ path: capabilityWorkspacePath(workspaceDir, profile, entry),
100
+ preset: { id: entry.runtimeId, name: entry.title, source: entry.hub ? 'hub' : 'local' } }, null, 2));
101
+ return;
102
+ }
84
103
  const found = findPersonaPreset(presetName, directory);
85
104
  if (!found) {
86
105
  const available = listPersonaPresets(directory).map(p => p.name).join(', ') || 'none';
87
106
  throw new Error(`Persona preset "${presetName}" not found. Available: ${available}`);
88
107
  }
89
108
  discoverLocalCapabilities(workspaceDir, profile);
90
- const entry = await selectCapability(workspaceDir, profile, 'persona', found.id, true);
91
- writePersonaSelection(workspaceDir, profile, entry.hub ? { source: 'hub' } : { source: 'local', id: found.id });
109
+ const operationName = capabilityEntryForPath(workspaceDir, profile, 'persona', found.path)!.runtimeId;
110
+ const entry = await selectCapability(workspaceDir, profile, 'persona', operationName, true);
111
+ writePersonaSelection(workspaceDir, profile, entry.hub ? { source: 'hub' } : { source: 'local', id: entry.runtimeId });
92
112
  console.log(JSON.stringify({
93
113
  path: found.path,
94
- preset: { id: found.id, name: found.name, source: 'local' },
114
+ preset: { id: entry.runtimeId, name: found.name, source: 'local' },
95
115
  message: `Persona "${found.name}" (local) selected for the active account.`,
96
116
  }, null, 2));
97
117
  });
@@ -1,12 +1,16 @@
1
1
  import { existsSync, realpathSync } from 'node:fs';
2
- import { join, resolve } from 'node:path';
2
+ import { join, resolve, basename } from 'node:path';
3
3
  import type { AuthProfile } from './auth.js';
4
4
  import {
5
5
  localAgentWorkspaceSnapshotRoot,
6
6
  readLocalAgentWorkspaceSnapshot,
7
7
  resolveLocalAgentWorkspacePath,
8
+ resolveLocalAgentWorkspaceWorkingCopyPath,
8
9
  type LocalAgentWorkspaceSnapshot,
9
10
  } from './agent-workspace-sync.js';
11
+ import { registerDiscoveredCapability } from './capability-workspace.js';
12
+ import { behaviorOperationName, perceptionOperationName } from './capability-operation-name.js';
13
+ import { getUserDataAccountCapabilitiesDir } from './user-data.js';
10
14
  import {
11
15
  listClawclawBehaviorSources,
12
16
  type ResolvedClawclawBehaviorSource,
@@ -84,7 +88,7 @@ export function listAgentWorkspaceBehaviorSources(
84
88
  && item.resolution !== 'local_modified'
85
89
  && item.resolution !== 'concurrent_difference'
86
90
  && item.resolution !== 'local_origin_unrecognized';
87
- return {
91
+ const managed = {
88
92
  ...source,
89
93
  ...(trusted ? { trustedSourceSha256: item.sourceFiles[0]!.sha256 } : {}),
90
94
  management: {
@@ -101,6 +105,17 @@ export function listAgentWorkspaceBehaviorSources(
101
105
  ...(item.hub ? { ownerName: item.hub.ownerName } : {}),
102
106
  },
103
107
  } satisfies ManagedClawclawBehaviorSource;
108
+ const workingCopyPath = resolveLocalAgentWorkspaceWorkingCopyPath(workspaceDir, profile, item)
109
+ ?? join(getUserDataAccountCapabilitiesDir(workspaceDir, profile), 'behaviors', item.resourceId,
110
+ item.sourceFiles[0]?.relativePath ?? basename(source.sourcePath));
111
+ const entry = registerDiscoveredCapability(workspaceDir, profile, {
112
+ type: 'behavior', path: workingCopyPath, runtimeId: source.id,
113
+ title: source.name, description: source.description, selectedByHub: true,
114
+ hub: { resourceId: item.resourceId, versionId: item.versionId,
115
+ workspaceItemId: item.workspaceItemId, publisher: item.hub?.publisher ?? 'community',
116
+ baseSha256: item.sourceFiles[0]?.sha256 },
117
+ });
118
+ return behaviorOperationName({ ...managed, workingCopyPath }, entry);
104
119
  });
105
120
  assertUniqueBehaviorIds(sources, 'hub');
106
121
  return sources;
@@ -118,12 +133,26 @@ export function listAgentWorkspacePerceptionSources(
118
133
  .map(item => resolveLocalAgentWorkspacePath(workspaceDir, profile, active, item.runtimeEntryPath!)));
119
134
  const sources = existsSync(root) ? listClawclawPerceptionSourcesInDirectory(root)
120
135
  .filter(source => selectedPaths.has(source.sourcePath)) : [];
136
+ const namedSources = sources.map(source => {
137
+ const item = active.items.perception.find(item => item.runtimeEntryPath
138
+ && resolveLocalAgentWorkspacePath(workspaceDir, profile, active, item.runtimeEntryPath) === source.sourcePath)!;
139
+ const workingCopyPath = resolveLocalAgentWorkspaceWorkingCopyPath(workspaceDir, profile, item)
140
+ ?? join(getUserDataAccountCapabilitiesDir(workspaceDir, profile), 'perceptions', item.resourceId,
141
+ item.sourceFiles[0]?.relativePath ?? basename(source.sourcePath));
142
+ const entry = registerDiscoveredCapability(workspaceDir, profile, {
143
+ type: 'perception', path: workingCopyPath, runtimeId: source.id, title: source.name,
144
+ description: source.description, selectedByHub: true,
145
+ hub: { resourceId: item.resourceId, versionId: item.versionId, workspaceItemId: item.workspaceItemId,
146
+ publisher: item.hub?.publisher ?? 'community', baseSha256: item.sourceFiles[0]?.sha256 },
147
+ });
148
+ return perceptionOperationName({ ...source, workingCopyPath }, entry);
149
+ });
121
150
  const ids = new Set<string>();
122
- for (const source of sources) {
151
+ for (const source of namedSources) {
123
152
  if (ids.has(source.id)) throw new Error(`AGENT_RESOURCE_ID_CONFLICT:perception:${source.id}`);
124
153
  ids.add(source.id);
125
154
  }
126
- return sources;
155
+ return namedSources;
127
156
  }
128
157
 
129
158
  export function mergeAgentWorkspaceBehaviorSources(
@@ -201,7 +201,7 @@ function validateUploadPayload(
201
201
  }
202
202
  if (entry.type === 'behavior') {
203
203
  const source = inspectClawclawBehaviorSource(path, dirname(path));
204
- if (!source || source.id !== entry.runtimeId) {
204
+ if (!source || source.id !== (entry.declaredId ?? entry.runtimeId)) {
205
205
  throw new Error('capability_validation_failed:behavior_invalid');
206
206
  }
207
207
  return;
@@ -210,7 +210,7 @@ function validateUploadPayload(
210
210
  const resolvedPath = realpathSync(path);
211
211
  const source = listClawclawPerceptionSourcesInDirectory(dirname(path))
212
212
  .find((candidate) => realpathSync(candidate.sourcePath) === resolvedPath);
213
- if (!source || source.id !== entry.runtimeId) {
213
+ if (!source || source.id !== (entry.declaredId ?? entry.runtimeId)) {
214
214
  throw new Error('capability_validation_failed:perception_invalid');
215
215
  }
216
216
  return;
@@ -221,7 +221,7 @@ function validateUploadPayload(
221
221
  }
222
222
  return;
223
223
  }
224
- if (readSkillName(path) !== entry.runtimeId) {
224
+ if (readSkillName(path) !== (entry.declaredId ?? entry.runtimeId)) {
225
225
  throw new Error('capability_validation_failed:skill_invalid');
226
226
  }
227
227
  }
@@ -8,6 +8,7 @@ import {
8
8
  } from './capability-workspace.js';
9
9
  import { listPersonaPresets } from './persona.js';
10
10
  import { readSkillName } from './skill-host.js';
11
+ import { behaviorOperationName, perceptionOperationName } from './capability-operation-name.js';
11
12
  import {
12
13
  ensureAccountUserDataLayout,
13
14
  getUserDataAccountBehaviorsDir,
@@ -90,5 +91,9 @@ export function discoverLocalCapabilities(
90
91
  })] : [];
91
92
  })
92
93
  : [];
93
- return { behaviors, perceptions, personas, skills };
94
+ return {
95
+ behaviors: behaviors.map(({ source, entry }) => ({ source: behaviorOperationName(source, entry), entry })),
96
+ perceptions: perceptions.map(({ source, entry }) => ({ source: perceptionOperationName(source, entry), entry })),
97
+ personas, skills,
98
+ };
94
99
  }
@@ -0,0 +1,14 @@
1
+ import type { CapabilityWorkspaceEntry } from './capability-workspace.js';
2
+ import type { ResolvedClawclawBehaviorSource } from '../runtime/clawclaw/plugins/behavior/behavior-source.js';
3
+ import type { ResolvedClawclawPerceptionSource } from '../runtime/clawclaw/plugins/perception/perception-source.js';
4
+
5
+ export function behaviorOperationName<T extends ResolvedClawclawBehaviorSource>(source: T, entry: CapabilityWorkspaceEntry): T {
6
+ return { ...source, id: entry.runtimeId, declaredId: source.declaredId ?? source.id,
7
+ workingCopyPath: source.workingCopyPath ?? source.sourcePath };
8
+ }
9
+
10
+ export function perceptionOperationName<T extends ResolvedClawclawPerceptionSource>(source: T, entry: CapabilityWorkspaceEntry): T {
11
+ return { ...source, id: entry.runtimeId, declaredId: source.declaredId ?? source.id,
12
+ workingCopyPath: source.workingCopyPath ?? source.sourcePath,
13
+ manifest: { ...source.manifest, id: entry.runtimeId } };
14
+ }
@@ -43,6 +43,8 @@ export interface CapabilityWorkspaceEntry {
43
43
  origin: 'local' | 'hub';
44
44
  relativePath: string;
45
45
  runtimeId: string;
46
+ /** Original source identity. runtimeId is the account-local operation name. */
47
+ declaredId?: string;
46
48
  title: string;
47
49
  description: string;
48
50
  selection: CapabilitySelection;
@@ -141,12 +143,23 @@ export function registerDiscoveredCapability(
141
143
  const key = existingByResource?.key ?? registryKey(input.type, relativePath);
142
144
  const now = new Date().toISOString();
143
145
  const previous = registry.entries[key];
146
+ const declaredId = input.runtimeId;
147
+ const occupied = new Set(Object.values(registry.entries)
148
+ .filter(entry => entry.type === input.type && entry.key !== key).map(entry => entry.runtimeId));
149
+ let runtimeId = previous?.runtimeId ?? declaredId;
150
+ // Keep retired/unselected entries in the registry: their operation names must
151
+ // never silently point to a different script after the next load.
152
+ for (let suffix = 1; input.type !== 'skill' && occupied.has(runtimeId); suffix++) {
153
+ const tail = `_${suffix}`;
154
+ runtimeId = `${declaredId.slice(0, 255 - tail.length)}${tail}`;
155
+ }
144
156
  const entry: CapabilityWorkspaceEntry = {
145
157
  key,
146
158
  type: input.type,
147
159
  origin: previous?.origin ?? (input.selectedByHub ? 'hub' : 'local'),
148
160
  relativePath,
149
- runtimeId: input.runtimeId,
161
+ runtimeId,
162
+ declaredId,
150
163
  title: input.title?.trim() || previous?.title || input.runtimeId,
151
164
  description: input.description?.trim() || previous?.description || `${input.type} ${input.runtimeId}`,
152
165
  selection: input.selectedByHub
@@ -16,7 +16,7 @@ import {
16
16
  type LocalAgentWorkspaceSnapshot,
17
17
  } from './agent-workspace-sync.js';
18
18
  import { filterInactiveAgentWorkspaceSnapshot } from './capability-cloud-presence.js';
19
- import { capabilityEntryForPath, readCapabilityWorkspaceRegistry, capabilityWorkspacePath } from './capability-workspace.js';
19
+ import { capabilityEntryForPath, readCapabilityWorkspaceRegistry, capabilityWorkspacePath, registerDiscoveredCapability } from './capability-workspace.js';
20
20
 
21
21
  export interface PersonaPreset {
22
22
  id: string;
@@ -136,7 +136,12 @@ function hubPersona(
136
136
  working = join(getUserDataAccountHubPersonasDir(workspaceDir, profile), item.resourceId, sourcePath);
137
137
  }
138
138
  if (working && existsSync(working)) {
139
- return { path: working, source: 'hub', resourceId: item.resourceId };
139
+ const entry = registerDiscoveredCapability(workspaceDir, profile, {
140
+ type: 'persona', path: working, runtimeId: basename(working, '.md'), selectedByHub: true,
141
+ hub: { resourceId: item.resourceId, versionId: item.versionId, workspaceItemId: item.workspaceItemId,
142
+ publisher: item.hub?.publisher ?? 'community', baseSha256: item.sourceFiles[0]?.sha256 },
143
+ });
144
+ return { path: working, source: 'hub', resourceId: item.resourceId, id: entry.runtimeId };
140
145
  }
141
146
  if (item.runtimeEntryPath) {
142
147
  const runtime = resolveLocalAgentWorkspacePath(workspaceDir, profile, snapshot!, item.runtimeEntryPath);
@@ -159,6 +164,12 @@ export function resolveActivePersonaFile(authStore = new AuthStore()): ResolvedP
159
164
  const selection = readPersonaSelection(workspaceDir, profile)
160
165
  ?? (selectedHub ? { source: 'hub' as const } : { source: 'none' as const });
161
166
  if (selection?.source === 'local') {
167
+ const selectedEntry = Object.values(readCapabilityWorkspaceRegistry(workspaceDir, profile).entries)
168
+ .find(entry => entry.type === 'persona' && entry.runtimeId === selection.id);
169
+ if (selectedEntry) {
170
+ if (selectedEntry.hub || selectedEntry.selection !== 'equipped') return selectedHub ?? { path: null, source: 'none' };
171
+ return { path: capabilityWorkspacePath(workspaceDir, profile, selectedEntry), source: 'local', id: selectedEntry.runtimeId };
172
+ }
162
173
  const preset = findPersonaPreset(selection.id, getUserDataAccountPersonasDir(workspaceDir, profile));
163
174
  const entry = preset ? capabilityEntryForPath(workspaceDir, profile, 'persona', preset.path) : undefined;
164
175
  if (entry?.hub) return selectedHub ?? { path: null, source: 'none' };
@@ -95,7 +95,7 @@ function assertSourceParity(
95
95
  manifest: Readonly<ClawclawBehaviorManifest>,
96
96
  source: ResolvedClawclawBehaviorSource,
97
97
  ): void {
98
- if (manifest.id !== source.id) throw new Error('behavior_id_source_mismatch');
98
+ if (manifest.id !== (source.declaredId ?? source.id)) throw new Error('behavior_id_source_mismatch');
99
99
  if (manifest.name !== source.name) throw new Error('behavior_name_source_mismatch');
100
100
  if (manifest.description !== source.description) {
101
101
  throw new Error('behavior_description_source_mismatch');
@@ -143,9 +143,11 @@ export function validateClawclawBehaviorModule(
143
143
  allowReservedProduces: source?.allowReservedProduces,
144
144
  });
145
145
  if (source) assertSourceParity(manifest, source);
146
+ const effectiveManifest = source && source.id !== manifest.id
147
+ ? Object.freeze({ ...manifest, id: source.id }) : manifest;
146
148
  return Object.freeze({
147
149
  BehaviorClass,
148
- manifest,
150
+ manifest: effectiveManifest,
149
151
  ...(source === undefined ? {} : { source }),
150
152
  });
151
153
  }
@@ -60,6 +60,9 @@ export interface ResolvedClawclawBehaviorSource {
60
60
  /** Optional so a statically identifiable legacy module remains reportable. */
61
61
  readonly apiVersion?: number;
62
62
  readonly id: string;
63
+ /** Host-assigned operation names never change the ID in the source file. */
64
+ readonly declaredId?: string;
65
+ readonly workingCopyPath?: string;
63
66
  readonly name: string;
64
67
  readonly description: string;
65
68
  readonly localizations?: ClawclawResourceLocalizations;
@@ -164,7 +164,7 @@ for (const spec of data.modules) {
164
164
  const manifest = (ModuleClass as any).manifest;
165
165
  if (
166
166
  manifest?.apiVersion !== PERCEPTION_PLUGIN_API_VERSION
167
- || manifest.id !== moduleId
167
+ || manifest.id !== (spec.declaredId ?? moduleId)
168
168
  || manifest.execution !== 'parallel_analysis'
169
169
  ) {
170
170
  throw new Error('perception_analysis_worker_manifest_mismatch');
@@ -14,6 +14,7 @@ import { assertPluginApiVersion } from '../plugin-api-version.js';
14
14
 
15
15
  export interface PerceptionThreadModuleSpec {
16
16
  readonly moduleId: string;
17
+ readonly declaredId?: string;
17
18
  readonly sourceUrl: string;
18
19
  readonly manifest: ResolvedClawclawPerceptionSource['manifest'];
19
20
  }
@@ -40,6 +41,7 @@ export class PerceptionModuleLoader {
40
41
  );
41
42
  return {
42
43
  moduleId: source.id,
44
+ declaredId: source.declaredId,
43
45
  sourceUrl: this.sourceUrl(source),
44
46
  manifest: structuredClone(source.manifest),
45
47
  };
@@ -67,6 +69,14 @@ export class PerceptionModuleLoader {
67
69
  PERCEPTION_PLUGIN_API_VERSION,
68
70
  ModuleClass.manifest?.apiVersion,
69
71
  );
72
+ if (ModuleClass.manifest?.id !== (source.declaredId ?? source.id)) {
73
+ throw new Error('perception_id_source_mismatch');
74
+ }
75
+ if (source.id !== ModuleClass.manifest!.id) {
76
+ const Aliased = class extends (ModuleClass as any) {};
77
+ Object.defineProperty(Aliased, 'manifest', { value: { ...ModuleClass.manifest, id: source.id } });
78
+ return Aliased as unknown as ClawclawPerceptionClass;
79
+ }
70
80
  return ModuleClass;
71
81
  });
72
82
  this.loaded.set(source.id, pending);
@@ -1423,9 +1423,16 @@ export class ClawclawPerceptionPlugin implements RuntimeEpochPlugin<Record<strin
1423
1423
  this.recordModuleTimings(operation, timings);
1424
1424
  this.flushModuleTimingWindows(diagnostic);
1425
1425
  }
1426
- return results.flatMap((result) => (
1427
- result.status === 'fulfilled' ? proposals(result.value) : []
1428
- ));
1426
+ return results.flatMap((result, index) => {
1427
+ if (result.status !== 'fulfilled') return [];
1428
+ const module = modules[index]!;
1429
+ const values = proposals(result.value);
1430
+ // Aliased copies may emit the same source-level dedupe key. Keep their
1431
+ // outputs separate without renaming any public Event type or payload.
1432
+ return module.source?.declaredId && module.source.declaredId !== module.manifest.id
1433
+ ? values.map(value => ({ ...value, dedupeKey: `ccl-alias:${JSON.stringify([module.manifest.id, value.dedupeKey])}` }))
1434
+ : values;
1435
+ });
1429
1436
  }
1430
1437
 
1431
1438
  private recordModuleTimings(
@@ -95,7 +95,7 @@ function validateClass(
95
95
  if (
96
96
  !manifest
97
97
  || manifest.apiVersion !== PERCEPTION_PLUGIN_API_VERSION
98
- || manifest.id !== spec.moduleId
98
+ || manifest.id !== (spec.declaredId ?? spec.moduleId)
99
99
  || (manifest.execution ?? 'ordered_update')
100
100
  !== (spec.manifest.execution ?? 'ordered_update')
101
101
  || JSON.stringify(manifest.produces) !== JSON.stringify(spec.manifest.produces)
@@ -33,6 +33,8 @@ export interface ResolvedClawclawPerceptionSource {
33
33
  /** Literal source declaration; retained so the loader can diagnose unsupported modules. */
34
34
  readonly apiVersion?: number;
35
35
  readonly id: string;
36
+ readonly declaredId?: string;
37
+ readonly workingCopyPath?: string;
36
38
  readonly name: string;
37
39
  readonly description: string;
38
40
  readonly manifest: ClawclawPerceptionManifest;
@@ -425,20 +427,17 @@ export function listClawclawPerceptionSourcesInDirectory(
425
427
  return [];
426
428
  }
427
429
 
428
- const sources = new Map<string, ResolvedClawclawPerceptionSource>();
430
+ const sources: ResolvedClawclawPerceptionSource[] = [];
429
431
  for (const file of files) {
430
432
  try {
431
433
  const sourcePath = realpathSync(join(root, file));
432
434
  if (!pathInside(root, sourcePath) || dirname(sourcePath) !== root) continue;
433
435
  const source = parseSource(sourcePath, root);
434
436
  if (!source) continue;
435
- // Match Strategy discovery: sorted filenames are deterministic and the
436
- // last declaration wins. Duplicate entries stay recoverable and never
437
- // make Owner terminal.
438
- sources.set(source.id, source);
437
+ sources.push(source);
439
438
  } catch {}
440
439
  }
441
- return [...sources.values()];
440
+ return sources;
442
441
  }
443
442
 
444
443
  /** Lists installed workspace perception classes by reading static manifests only. */