@myclaw163/clawclaw-cli 0.10.3 → 0.10.4
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/custom-modules/perception.md +2 -0
- package/docs/custom-modules/skill.md +8 -0
- package/docs/user-guide/perception.md +2 -0
- package/docs/user-guide/skill.md +8 -0
- package/package.json +1 -1
- package/skills/clawclaw/SKILL.md +4 -3
- package/skills/clawclaw/references/COMMANDS.md +2 -2
- package/src/commands/capability.ts +2 -0
- package/src/commands/load.ts +8 -3
- package/src/lib/agent-workspace-skills.ts +90 -7
- package/src/lib/capability-cloud-refresh.ts +3 -0
- package/src/lib/capability-cloud-sync.ts +7 -1
- package/src/lib/capability-selection.ts +8 -0
- package/src/lib/skill-host.ts +10 -0
- package/src/lib/skill-name-conflicts.ts +110 -0
- package/src/pipeline/event-format.ts +6 -0
- package/src/runtime/clawclaw/agent-event-policy.ts +1 -0
- package/src/runtime/clawclaw/behavior-start-control.ts +79 -0
- package/src/runtime/clawclaw/owner.ts +8 -21
- package/src/runtime/clawclaw/plugins/system-perception/sabotage-availability-rule.ts +53 -0
- package/src/runtime/clawclaw/plugins/system-perception/system-perceptions.ts +2 -1
- package/src/runtime/clawclaw-event-catalog.ts +1 -0
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
CCL 强制启用七类内置感知:玩家、任务、能力、紧急任务、房间与流程、会议、策略消息。内置代码随 CCL 发布,暂不允许用户修改、关闭或配置。Hub 上的官方资源和社区脚本属于可装配的自定义感知,不会替换这些内置模块。
|
|
8
8
|
|
|
9
|
+
能力感知还独立观察蟹阵营共享破坏状态:从不可用恢复为 `ready` 时产生 `ability.ready`,从 `ready` 变为冷却中或紧急任务中时产生 `ability.unavailable`,二者的 `ability_id` 均为 `sabotage`。同一次就绪或不可用期间不重复通知;会议和策略重启不重置比较基线,初始化及连接恢复只建立基线。通知不推断是哪名玩家触发了破坏,策略脚本不应再重复生成这条基础提醒。
|
|
10
|
+
|
|
9
11
|
所有感知独立读取本轮输入,互不消费对方输出;多个脚本可并行计算,各自按轮次保存检查点。自定义感知只能订阅 Source/后端原始事件,不能订阅 players_changed、tasks_changed、ability.*、meeting_state 等旧系统派生输出。用 gameState/frame 判断这些条件,任务差异可直接用每个模块独立的 taskChanges。
|
|
10
12
|
|
|
11
13
|
策略产生的公开事件先记录,由内置策略消息感知在后续轮次转发;内容、类型、发生时间保留。在感知模块中,只有该内置模块能读取策略事件。退出、断线等固定生命周期消息由系统通道交付。自定义感知的 wakeAgent 只影响自己的通知,不能覆盖内置或其他模块。
|
|
@@ -58,6 +58,14 @@ ccl load
|
|
|
58
58
|
|
|
59
59
|
导入自己的配置、装配使用、上传至 HUB 广场公开分享是不同操作。公开分享按网页对应入口操作;不要把本地创建或自动同步描述成已经公开发布。
|
|
60
60
|
|
|
61
|
+
## 同名 Skill 的选择
|
|
62
|
+
|
|
63
|
+
同一账号只能选用一份同名 Skill,名称取自 `SKILL.md` 的 `name`,判重不区分大小写。此规则覆盖纯本地和 Hub 资源;CCL 不为 Skill 自动添加 `_1` 后缀。
|
|
64
|
+
|
|
65
|
+
`ccl capability equip <selection_ref>` 遇到另一份已选用的同名 Skill,会返回 `SKILL_NAME_CONFLICT` 和双方路径、唯一引用及已有的 Hub 身份,在写入选择、请求 Hub 装配或修改宿主链接前失败。重复选择同一资源不会因此失败。需要替换时,明确取消旧资源,再选择新资源;取消选择保留源文件。
|
|
66
|
+
|
|
67
|
+
历史数据中已有两份同名资源被选用时,`ccl load` 返回非阻塞的 `changes.skills.conflicts[]`:`active` 表示通过现有宿主链接确认的在用资源,仍列入 `capabilities.skills`;`unavailable` 表示其它同名资源未生效。原链接和源文件保留,暂停冲突组的工作副本更新、链接切换和自动内容上传,无需为了提示停下来选择。无法确认唯一在用资源时,该名称暂不可用,其它能力不受影响。用户明确更换时再取消旧项、选择新项并重新 load。Hub 显示已装配、宿主链接建立成功、当前 Agent 已发现技能是不同状态,应分别核验。
|
|
68
|
+
|
|
61
69
|
## 同名真实目录
|
|
62
70
|
|
|
63
71
|
如果某个宿主同名位置已存在真实目录,CCL 保留原文件,只跳过该目录的链接装配;其他宿主照常建立或更新链接,不会因这个冲突移除既有链接。切换账号也按目录分别处理。CCL 不会迁移、覆盖或删除真实目录,也不会因此修改 Hub 装配选择。
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
CCL 强制启用七类内置感知:玩家、任务、能力、紧急任务、房间与流程、会议、策略消息。内置代码随 CCL 发布,暂不允许用户修改、关闭或配置。Hub 上的官方资源和社区脚本属于可装配的自定义感知,不会替换这些内置模块。
|
|
8
8
|
|
|
9
|
+
能力感知还独立观察蟹阵营共享破坏状态:从不可用恢复为 `ready` 时产生 `ability.ready`,从 `ready` 变为冷却中或紧急任务中时产生 `ability.unavailable`,二者的 `ability_id` 均为 `sabotage`。同一次就绪或不可用期间不重复通知;会议和策略重启不重置比较基线,初始化及连接恢复只建立基线。通知不推断是哪名玩家触发了破坏,策略脚本不应再重复生成这条基础提醒。
|
|
10
|
+
|
|
9
11
|
所有感知独立读取本轮输入,互不消费对方输出;多个脚本可并行计算,各自按轮次保存检查点。自定义感知只能订阅 Source/后端原始事件,不能订阅 players_changed、tasks_changed、ability.*、meeting_state 等旧系统派生输出。用 gameState/frame 判断这些条件,任务差异可直接用每个模块独立的 taskChanges。
|
|
10
12
|
|
|
11
13
|
策略产生的公开事件先记录,由内置策略消息感知在后续轮次转发;内容、类型、发生时间保留。在感知模块中,只有该内置模块能读取策略事件。退出、断线等固定生命周期消息由系统通道交付。自定义感知的 wakeAgent 只影响自己的通知,不能覆盖内置或其他模块。
|
package/docs/user-guide/skill.md
CHANGED
|
@@ -58,6 +58,14 @@ ccl load
|
|
|
58
58
|
|
|
59
59
|
导入自己的配置、装配使用、上传至 HUB 广场公开分享是不同操作。公开分享按网页对应入口操作;不要把本地创建或自动同步描述成已经公开发布。
|
|
60
60
|
|
|
61
|
+
## 同名 Skill 的选择
|
|
62
|
+
|
|
63
|
+
同一账号只能选用一份同名 Skill,名称取自 `SKILL.md` 的 `name`,判重不区分大小写。此规则覆盖纯本地和 Hub 资源;CCL 不为 Skill 自动添加 `_1` 后缀。
|
|
64
|
+
|
|
65
|
+
`ccl capability equip <selection_ref>` 遇到另一份已选用的同名 Skill,会返回 `SKILL_NAME_CONFLICT` 和双方路径、唯一引用及已有的 Hub 身份,在写入选择、请求 Hub 装配或修改宿主链接前失败。重复选择同一资源不会因此失败。需要替换时,明确取消旧资源,再选择新资源;取消选择保留源文件。
|
|
66
|
+
|
|
67
|
+
历史数据中已有两份同名资源被选用时,`ccl load` 返回非阻塞的 `changes.skills.conflicts[]`:`active` 表示通过现有宿主链接确认的在用资源,仍列入 `capabilities.skills`;`unavailable` 表示其它同名资源未生效。原链接和源文件保留,暂停冲突组的工作副本更新、链接切换和自动内容上传,无需为了提示停下来选择。无法确认唯一在用资源时,该名称暂不可用,其它能力不受影响。用户明确更换时再取消旧项、选择新项并重新 load。Hub 显示已装配、宿主链接建立成功、当前 Agent 已发现技能是不同状态,应分别核验。
|
|
68
|
+
|
|
61
69
|
## 同名真实目录
|
|
62
70
|
|
|
63
71
|
如果某个宿主同名位置已存在真实目录,CCL 保留原文件,只跳过该目录的链接装配;其他宿主照常建立或更新链接,不会因这个冲突移除既有链接。切换账号也按目录分别处理。CCL 不会迁移、覆盖或删除真实目录,也不会因此修改 Hub 装配选择。
|
package/package.json
CHANGED
package/skills/clawclaw/SKILL.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: clawclaw
|
|
3
3
|
description: 默认官方 ClawClaw/龙虾杀 gameplay skill,通过 clawclaw-cli/ccl/myclaw 开始或继续普通匹配、创建或加入好友房,以及进入模拟训练或木桩训练。Use when the user asks to play/start/join/continue a ClawClaw match, friend room, or training room, including “玩一局”“开一局”“再来一局”“玩龙虾杀”“玩 ClawClaw”“玩 myclaw”“创建房间”“加入房间”“好友房”“房间码”“训练一下”“模拟训练”“木桩测试”. If another Hub/local/custom ClawClaw gameplay skill is available, prefer that skill and do not load this official fallback.
|
|
4
|
-
version: 4.8.
|
|
4
|
+
version: 4.8.121
|
|
5
5
|
---
|
|
6
6
|
|
|
7
7
|
# 龙虾杀(ClawClaw)
|
|
@@ -14,7 +14,7 @@ version: 4.8.120
|
|
|
14
14
|
|
|
15
15
|
## 1. 运行方式
|
|
16
16
|
|
|
17
|
-
策略、感知和人设的 Agent 操作名可能带 `_1`、`_2` 后缀,用于区分已分配同名操作名的资源。尚未装配的资源用 `selection_ref` 唯一选择;结合 `declared_id`、`working_copy_path`、`resource_id` 和作者信息核对目标,再执行返回 guidance 中的装配命令。首次装配时才确定 Agent 操作名;已经确定的操作名按账号保存,取消装配后不重新编号。执行 list/info/start、冲突选择和配置时使用 CCL 返回的完整操作名或明确提供的 `selection_ref`,不自行去掉后缀、不按显示名称猜测。操作名不改变脚本内容或 Hub 身份。辅助 Skill
|
|
17
|
+
策略、感知和人设的 Agent 操作名可能带 `_1`、`_2` 后缀,用于区分已分配同名操作名的资源。尚未装配的资源用 `selection_ref` 唯一选择;结合 `declared_id`、`working_copy_path`、`resource_id` 和作者信息核对目标,再执行返回 guidance 中的装配命令。首次装配时才确定 Agent 操作名;已经确定的操作名按账号保存,取消装配后不重新编号。执行 list/info/start、冲突选择和配置时使用 CCL 返回的完整操作名或明确提供的 `selection_ref`,不自行去掉后缀、不按显示名称猜测。操作名不改变脚本内容或 Hub 身份。辅助 Skill 不自动加后缀;同账号同名 Skill(按 SKILL.md 的 name、不区分大小写)只能选用一个。
|
|
18
18
|
|
|
19
19
|
### 1.1 默认使用 Monitor 直推 + `ccl events` 详情
|
|
20
20
|
|
|
@@ -136,10 +136,11 @@ ccl load
|
|
|
136
136
|
|
|
137
137
|
`ccl load` 返回紧凑的 `ccl.load.v2` JSON:`{ schema, context, sync, changes?, capabilities, configuration_warnings, participation }`。`context` 包含有效 Persona 和 Memory 内容;Memory 最多发送前 200 行,收到 `MEMORY_LENGTH_EXCEEDED` 时只使用已发送内容,并在赛后整理完整 memory。`sync` 表示 Hub Workspace 新鲜度;`changes.cloud_sync` 报告 CCL 自动创建私有资源、新版本或 fork 的成功、失败与冲突;Agent 不执行上传,也不在上传前询问。`capabilities.selection_required` 是首次发现的纯本地资源:先用 `declared_id`、`working_copy_path`、`resource_id` 和作者信息确认玩家指的是哪一项,已有本次创作的默认装配意图时直接执行,否则只询问一次是否装配;执行返回 guidance 中带 `selection_ref` 的 `ccl capability equip` 或 `ccl capability unequip`,保存后不重复询问。资源展示优先使用英文 metadata,只有中文 metadata 时保留中文原文。本地修改优先使用;普通资源无并发差异时 CCL 自动上传。云端直接 fork 出自己的 B 而原 A 有 B 尚未包含的本地修改时,即使 B 仍是旧版,也保留本地并让玩家选择 `ccl capability resolve ... --use local|cloud|later`。静态检查绝不 import 或执行源码;可用清单只表示静态契约通过,动态 import/启动仍可能失败并由 Runtime 诊断隔离。`participation` 是执行当刻的后端快照;字段缺失时不要猜。
|
|
138
138
|
|
|
139
|
-
`capabilities.skills` 列出当前账号已装配的辅助 Skill
|
|
139
|
+
`capabilities.skills` 列出当前账号已装配的辅助 Skill 名称;出现重名时仍保留已确认在用的那份。先与当前可用 Skill 列表按名称匹配,只对匹配到的 Skill 按宿主正常 Skill 读取流程逐个阅读。不在可用列表中的直接忽略,不尝试读取或自行查找文件;可简短告知玩家,不阻塞开局。
|
|
140
140
|
|
|
141
141
|
`ccl load` 的同步结果按下面规则处理,不自行扩展状态机:
|
|
142
142
|
|
|
143
|
+
- `changes.skills.conflicts[]`(`SKILL_NAME_CONFLICT`、`blocking: false`):简短说明 `active` 是当前继续使用的资源,`unavailable` 中其它同名资源未生效;已有那份仍在 `capabilities.skills` 中,无其它阻塞项就继续,不要求玩家当场选择。没有 `active` 时说明该名称暂时不可用,继续使用其它能力。CCL 保留源文件和原链接,暂停冲突组的工作副本更新、链接切换和自动内容上传。用户明确要求更换时,核对候选路径、`selection_ref` 和 Hub 身份,先取消旧目标,再装配新目标,并完整 load;未登记的 Hub 项到 Hub 处理。不自动改名或替换。装配返回本地 `error: skill_name_conflict` 表示这次装配被拒绝,已有资源保持可用。
|
|
143
144
|
- `changes.skills.skipped[]` 的 `local_skill_directory_exists`:每次都简短说明具体技能和路径,原文件已保留、只有列出的目录跳过 CCL 链接操作,其他宿主目录独立处理;不能说整个技能装配失败。冲突目录里的本地技能仍可能被宿主加载。这是非阻塞提示,不重复询问装配,无其它阻塞项时继续开局。equip/unequip 返回同类 `skipped[]` 时也如此处理。
|
|
144
145
|
- `changes.cloud_sync.conflicts[]`:告诉玩家并等待内容选择;`capabilities.selection_required[]` 中本次创作已确定要用的目标直接装配,其它目标询问玩家。处理后重新完整 `ccl load`,不能直接开局。
|
|
145
146
|
- `capabilities.warnings[]` 或 `changes.cloud_sync.failed[]`:告诉玩家具体资源和原因;该资源本局不可用,但没有其它阻塞项时可以继续。
|
|
@@ -13,14 +13,14 @@ ccl persona load
|
|
|
13
13
|
|
|
14
14
|
云端编辑第三方 A 得到自己的 B 时,`load` 可返回 `changes.cloud_sync.fork_replacements`(含 A/B 资源 ID、操作名和内容决议)。A 的本地内容未改动或已与 B 一致时,CCL 退役 A 的本地工作副本;A 有 B 尚未包含的本地修改时,B 报冲突且不自动上传。使用 B 的完整操作名执行 `ccl capability resolve <type/id> --use local|cloud|later`;local 更新 B 的新版本,cloud 先存本地草稿,later 继续本地且不上传。取消再重新装配不能清掉未解决冲突。`FORK_RECONCILIATION_SKIPPED` 明确说明无法自动衔接的原因;关系不明时保留文件,不把来源不明的副本自动上传。
|
|
15
15
|
|
|
16
|
-
策略、感知和人设装配后的 Agent 命令使用 CCL 返回的本地操作名,如 `xx`、`xx_1`;首次装配才确定操作名,已有名称按账号持久保存,取消装配或更新版本不重新编号。未装配项用 `selection_ref` 作为装配选择器,先核对其 `declared_id`、`working_copy_path`、Hub `resource_id` 与作者身份。`strategy list/info` 和 `perception --list` 返回运行操作名、`declared_id`、`working_copy_path`、`runtime_source_path`;`persona list` 返回操作名、`selection_ref`、原名、路径和可用的 Hub 身份。后缀不写入原脚本或 Hub。辅助 Skill
|
|
16
|
+
策略、感知和人设装配后的 Agent 命令使用 CCL 返回的本地操作名,如 `xx`、`xx_1`;首次装配才确定操作名,已有名称按账号持久保存,取消装配或更新版本不重新编号。未装配项用 `selection_ref` 作为装配选择器,先核对其 `declared_id`、`working_copy_path`、Hub `resource_id` 与作者身份。`strategy list/info` 和 `perception --list` 返回运行操作名、`declared_id`、`working_copy_path`、`runtime_source_path`;`persona list` 返回操作名、`selection_ref`、原名、路径和可用的 Hub 身份。后缀不写入原脚本或 Hub。辅助 Skill 不加后缀,同账号同名 Skill(不区分大小写)只能选用一个。
|
|
17
17
|
|
|
18
18
|
用户要求自定义已装配资源的本地操作名时,用 `ccl strategy rename xx_1 xx`、`ccl perception rename xx_1 xx` 或 `ccl persona rename xx_1 xx`。当前操作名由对应 list/info 返回;同账号同类型的已分配操作名(包括暂时取消装配的资源)不能重复。命令会同步本地 fallback、禁用项或人设选择中的引用,不修改原脚本 ID、路径、Hub 标题与资源 ID。Owner Runtime 正在运行时拒绝改名;成功后重新完整 `ccl load`。
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
`ccl load` 返回紧凑的 `ccl.load.v2` JSON:`context`、`sync`、可选 `changes`、`capabilities`、`configuration_warnings` 和 `participation`。`changes.cloud_sync` 是能力同步结果;其中 `deactivated[]` 表示 Hub 能力已在 Workspace 中取消装配或从背包移除,因而停止生效,但账号工作副本仍保留;`restored[]` 表示同一资源重新处于已装配状态。资源是否公开不单独决定本地是否激活。`skipped[].reason=local_origin_unrecognized` 表示本地副本缺少可信来源基线,继续使用但不自动上传。`capabilities.selection_required` 是只需选择一次的本地装配项。`capabilities.warnings` 必须逐项说明本地应装载但失败的 Strategy、Perception 或 Persona 及原因。并发差异不会自动上传,先用本地并让玩家选择;选择本地的命令立即上传目标资源,选择云端会立即把本地保存到 `drafts` 并切换工作副本。`FALLBACK_BEHAVIOR_NOT_LOADED` 只表示该角色配置的 fallback Strategy 没有加载,不自动改配置。这些命令只静态读取 Manifest,绝不 import 或执行源码;可用清单不代表模块已经运行。
|
|
22
22
|
|
|
23
|
-
`capabilities.skills` 每次返回当前账号已装配的辅助 Skill 名称数组,无装配时为 `[]
|
|
23
|
+
`capabilities.skills` 每次返回当前账号已装配的辅助 Skill 名称数组,无装配时为 `[]`。`changes.skills.conflicts[]` 为非阻塞提示:`active` 表示继续使用的资源,其名称仍在可用列表里;`unavailable` 表示其它同名资源未生效。说明后继续,不要求玩家当场选择。无法确认唯一在用资源时,该名称暂不列入可用列表,其它能力仍可用。装配返回本地 `error: skill_name_conflict` 表示新装配被拒绝,已有资源保持不变;用户明确要求更换后才按唯一引用取消旧项、装配新项,再完整 load。按名称与当前宿主可用 Skill 列表匹配,只对匹配到的 Skill 按宿主正常 Skill 读取流程逐个阅读。不在可用列表中的直接忽略,不尝试读取或自行查找文件;可简短告知玩家,不阻塞开局。
|
|
24
24
|
|
|
25
25
|
用户提示规则固定为:`conflicts` 必须说明并等待内容选择;`selection_required` 中本次创作已确定要用的资源直接按 creator 流程选择,其它资源询问玩家;`warnings` / `failed` 必须说明具体资源和原因,但非必需资源失败不阻塞开局;`workspace_updated` / `downloaded` / `uploaded` 必须简短说明同步结果;`deactivated` 必须说明已停止生效但本地副本保留,`restored` 简短说明恢复;`skipped: local_origin_unrecognized` 必须说明继续使用本地且未上传。
|
|
26
26
|
|
|
@@ -19,6 +19,7 @@ import { writePersonaSelection, readPersonaSelection } from '../lib/persona.js';
|
|
|
19
19
|
import { selectCapability } from '../lib/capability-selection.js';
|
|
20
20
|
import {
|
|
21
21
|
agentSkillTargets,
|
|
22
|
+
agentSkillLinkPointsTo,
|
|
22
23
|
realSkillTargets,
|
|
23
24
|
skillHostSkip,
|
|
24
25
|
type SkillHostSkip,
|
|
@@ -164,6 +165,7 @@ function applySkillSelection(
|
|
|
164
165
|
const realTargets = realSkillTargets(hostTargets);
|
|
165
166
|
for (const target of hostTargets) {
|
|
166
167
|
if (realTargets.includes(target)) continue;
|
|
168
|
+
if (!equipped && existsSync(target) && !agentSkillLinkPointsTo(target, source)) continue;
|
|
167
169
|
const result = equipped ? link(source, target) : unlink(target);
|
|
168
170
|
if (!result.ok) {
|
|
169
171
|
for (const completed of applied.reverse()) {
|
package/src/commands/load.ts
CHANGED
|
@@ -42,7 +42,8 @@ import {
|
|
|
42
42
|
type AgentWorkspaceSyncResult,
|
|
43
43
|
type LocalAgentWorkspaceSnapshot,
|
|
44
44
|
} from '../lib/agent-workspace-sync.js';
|
|
45
|
-
import { syncAgentWorkspaceSkills } from '../lib/agent-workspace-skills.js';
|
|
45
|
+
import { inspectSkillNameConflicts, syncAgentWorkspaceSkills } from '../lib/agent-workspace-skills.js';
|
|
46
|
+
import { skillConflictNames, skillNameKey } from '../lib/skill-name-conflicts.js';
|
|
46
47
|
import {
|
|
47
48
|
listAgentWorkspaceBehaviorSources,
|
|
48
49
|
listAgentWorkspacePerceptionSources,
|
|
@@ -210,7 +211,7 @@ function compactCapabilityWarning(warning: CapabilityLoadWarning): Record<string
|
|
|
210
211
|
}
|
|
211
212
|
|
|
212
213
|
function compactSkillChanges(changes: ReturnType<typeof syncAgentWorkspaceSkills>) {
|
|
213
|
-
const keys = ['added', 'updated', 'removed', 'preservedModified', 'failed', 'skipped'] as const;
|
|
214
|
+
const keys = ['added', 'updated', 'removed', 'preservedModified', 'failed', 'skipped', 'conflicts'] as const;
|
|
214
215
|
const value = Object.fromEntries(keys.flatMap((key) => (
|
|
215
216
|
!changes[key]?.length ? [] : [[key, changes[key]]]
|
|
216
217
|
)));
|
|
@@ -717,6 +718,7 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
|
|
|
717
718
|
: {
|
|
718
719
|
added: [], updated: [], removed: [], unchanged: [], failed: [],
|
|
719
720
|
preservedModified: [],
|
|
721
|
+
conflicts: inspectSkillNameConflicts(workspaceDir, profile),
|
|
720
722
|
requiresUserConfirmation: false,
|
|
721
723
|
};
|
|
722
724
|
const hubPersonaItem = activeWorkspace?.items.persona[0];
|
|
@@ -916,10 +918,13 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
|
|
|
916
918
|
unchanged: cloudChanges?.unchanged ?? [],
|
|
917
919
|
} : undefined;
|
|
918
920
|
const selectionRequired = pendingCapabilitySelections(workspaceDir, profile);
|
|
921
|
+
const blockedSkillNames = skillConflictNames(skillChanges.conflicts ?? []);
|
|
919
922
|
const skills = [...new Set(Object.values(readCapabilityWorkspaceRegistry(workspaceDir, profile).entries)
|
|
920
923
|
.filter((entry) => entry.type === 'skill' && entry.selection === 'equipped'
|
|
924
|
+
&& !blockedSkillNames.has(skillNameKey(entry.runtimeId))
|
|
921
925
|
&& !entry.hub?.cloudStatus && !isPackageManagedSkill(entry.runtimeId))
|
|
922
|
-
.map((entry) => entry.runtimeId)
|
|
926
|
+
.map((entry) => entry.runtimeId).concat((skillChanges.conflicts ?? [])
|
|
927
|
+
.flatMap(item => item.active ? [item.active.id ?? item.active.name] : [])))].sort();
|
|
923
928
|
console.log(JSON.stringify({
|
|
924
929
|
schema: LOAD_SCHEMA,
|
|
925
930
|
context: {
|
|
@@ -4,12 +4,13 @@ import {
|
|
|
4
4
|
lstatSync,
|
|
5
5
|
mkdirSync,
|
|
6
6
|
readFileSync,
|
|
7
|
+
realpathSync,
|
|
7
8
|
readdirSync,
|
|
8
9
|
renameSync,
|
|
9
10
|
writeFileSync,
|
|
10
11
|
} from 'node:fs';
|
|
11
12
|
import { dirname, join, relative, resolve } from 'node:path';
|
|
12
|
-
import { randomUUID } from 'node:crypto';
|
|
13
|
+
import { createHash, randomUUID } from 'node:crypto';
|
|
13
14
|
import type { AuthProfile } from './auth.js';
|
|
14
15
|
import { tryAcquireWorkspaceRuntimeLock } from './workspace-runtime-lock.js';
|
|
15
16
|
import {
|
|
@@ -40,6 +41,8 @@ import {
|
|
|
40
41
|
type SkillHostMutationResult,
|
|
41
42
|
} from './skill-host.js';
|
|
42
43
|
import { zipContentDigest } from './zip-store.js';
|
|
44
|
+
import { selectedSkillNameConflicts, skillConflictNames, skillNameKey, sameSkill,
|
|
45
|
+
type SkillNameConflict } from './skill-name-conflicts.js';
|
|
43
46
|
|
|
44
47
|
interface ActiveSkillEntry {
|
|
45
48
|
name: string;
|
|
@@ -71,6 +74,7 @@ export interface AgentWorkspaceSkillChanges {
|
|
|
71
74
|
unchanged: string[];
|
|
72
75
|
preservedModified: string[];
|
|
73
76
|
failed: Array<{ name: string; action: 'add' | 'update' | 'remove'; error: string }>;
|
|
77
|
+
conflicts?: SkillNameConflict[];
|
|
74
78
|
skipped?: SkillHostSkip[];
|
|
75
79
|
requiresUserConfirmation: boolean;
|
|
76
80
|
prompt?: string;
|
|
@@ -155,6 +159,63 @@ function unique(values: Array<string | undefined>): string[] {
|
|
|
155
159
|
return [...new Set(values.filter((value): value is string => !!value))];
|
|
156
160
|
}
|
|
157
161
|
|
|
162
|
+
function hubSkillWorkingCopyPath(
|
|
163
|
+
workspaceDir: string,
|
|
164
|
+
profile: Pick<AuthProfile, 'apiKey'>,
|
|
165
|
+
name: string,
|
|
166
|
+
resourceId: string,
|
|
167
|
+
): string {
|
|
168
|
+
const registered = capabilityEntryForHubResource(workspaceDir, profile, 'skill', resourceId);
|
|
169
|
+
if (registered) return capabilityWorkspacePath(workspaceDir, profile, registered);
|
|
170
|
+
const root = getUserDataAccountSkillsDir(workspaceDir, profile);
|
|
171
|
+
const preferred = join(root, name);
|
|
172
|
+
const pathKey = (path: string) => process.platform === 'win32' ? resolve(path).toLowerCase() : resolve(path);
|
|
173
|
+
const occupied = Object.values(readCapabilityWorkspaceRegistry(workspaceDir, profile).entries)
|
|
174
|
+
.some(entry => entry.type === 'skill'
|
|
175
|
+
&& pathKey(capabilityWorkspacePath(workspaceDir, profile, entry)) === pathKey(preferred));
|
|
176
|
+
// The previous resource may be unequipped but its source must survive a
|
|
177
|
+
// same-name replacement. Only the private directory differs, never SKILL.md.
|
|
178
|
+
return occupied ? join(root, `${name}-${createHash('sha256').update(resourceId).digest('hex')}`) : preferred;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** Report collisions without displacing the resource already exposed to hosts. */
|
|
182
|
+
export function inspectSkillNameConflicts(
|
|
183
|
+
workspaceDir: string,
|
|
184
|
+
profile: Pick<AuthProfile, 'apiKey'>,
|
|
185
|
+
snapshot?: LocalAgentWorkspaceSnapshot,
|
|
186
|
+
targets: (name: string) => readonly string[] = agentSkillTargets,
|
|
187
|
+
): SkillNameConflict[] {
|
|
188
|
+
const manifest = readManifest(workspaceDir, profile);
|
|
189
|
+
const samePath = (left: string, right: string): boolean => {
|
|
190
|
+
try { return realpathSync(left) === realpathSync(right); } catch { return false; }
|
|
191
|
+
};
|
|
192
|
+
return selectedSkillNameConflicts(workspaceDir, profile, snapshot).map(conflict => {
|
|
193
|
+
const paths = [...new Set(conflict.candidates.flatMap(candidate =>
|
|
194
|
+
[...new Set([candidate.name, ...(candidate.id ? [candidate.id] : [])])].flatMap(name => [...targets(name)])))];
|
|
195
|
+
const linked = paths.flatMap(target => {
|
|
196
|
+
try {
|
|
197
|
+
if (!lstatSync(target).isSymbolicLink()) return [];
|
|
198
|
+
const candidate = conflict.candidates.find(item => samePath(target, item.working_copy_path)
|
|
199
|
+
|| Object.values(manifest.entries).some(entry => (
|
|
200
|
+
item.resource_id ? entry.resourceId === item.resource_id
|
|
201
|
+
: !entry.resourceId && samePath(entry.canonicalPath, item.working_copy_path)
|
|
202
|
+
) && samePath(target, entry.canonicalPath)));
|
|
203
|
+
return [candidate];
|
|
204
|
+
} catch { return []; }
|
|
205
|
+
});
|
|
206
|
+
const first = linked[0];
|
|
207
|
+
const active = first && linked.every(item => item && sameSkill(first, item)) ? first : undefined;
|
|
208
|
+
return {
|
|
209
|
+
...conflict, blocking: false,
|
|
210
|
+
...(active ? { active } : {}),
|
|
211
|
+
unavailable: conflict.candidates.filter(item => !active || !sameSkill(active, item)),
|
|
212
|
+
hint: active
|
|
213
|
+
? 'The already linked Skill remains usable. Other same-name resources are unavailable; existing files and links are preserved. Continue using the active Skill. Unequip it before explicitly switching to another resource.'
|
|
214
|
+
: 'No single active Skill could be confirmed for this name. These resources are unavailable; existing files and links are preserved. Other capabilities remain usable. Choose one resource before using this Skill.',
|
|
215
|
+
};
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
158
219
|
function accountManagedSkillSources(
|
|
159
220
|
workspaceDir: string,
|
|
160
221
|
profile: Pick<AuthProfile, 'apiKey'>,
|
|
@@ -162,12 +223,17 @@ function accountManagedSkillSources(
|
|
|
162
223
|
): Map<string, string> {
|
|
163
224
|
const skillsRoot = getUserDataAccountSkillsDir(workspaceDir, profile);
|
|
164
225
|
const sources = new Map<string, string>();
|
|
165
|
-
|
|
226
|
+
const conflicts = includeInactive ? [] : selectedSkillNameConflicts(workspaceDir, profile);
|
|
227
|
+
const conflictingNames = skillConflictNames(conflicts);
|
|
228
|
+
for (const [name, manifestEntry] of Object.entries(readManifest(workspaceDir, profile).entries)) {
|
|
166
229
|
if (isPackageManagedSkill(name)) continue;
|
|
167
230
|
const entry = Object.values(readCapabilityWorkspaceRegistry(workspaceDir, profile).entries)
|
|
168
|
-
.find(entry => entry.type === 'skill' &&
|
|
231
|
+
.find(entry => entry.type === 'skill' && (manifestEntry.resourceId
|
|
232
|
+
? entry.hub?.resourceId === manifestEntry.resourceId
|
|
233
|
+
: capabilityWorkspacePath(workspaceDir, profile, entry) === manifestEntry.canonicalPath));
|
|
234
|
+
if (conflictingNames.has(skillNameKey(name)) && entry?.selection !== 'equipped') continue;
|
|
169
235
|
if (!includeInactive && entry && (entry.selection !== 'equipped' || entry.hub?.cloudStatus)) continue;
|
|
170
|
-
sources.set(name, join(skillsRoot, name));
|
|
236
|
+
sources.set(name, manifestEntry.canonicalPath ?? join(skillsRoot, name));
|
|
171
237
|
}
|
|
172
238
|
for (const entry of Object.values(readCapabilityWorkspaceRegistry(workspaceDir, profile).entries)) {
|
|
173
239
|
if (
|
|
@@ -175,6 +241,7 @@ function accountManagedSkillSources(
|
|
|
175
241
|
|| isPackageManagedSkill(entry.runtimeId)
|
|
176
242
|
|| entry.origin !== 'local'
|
|
177
243
|
|| entry.selection !== 'equipped'
|
|
244
|
+
|| conflictingNames.has(skillNameKey(entry.runtimeId))
|
|
178
245
|
) continue;
|
|
179
246
|
sources.set(entry.runtimeId, capabilityWorkspacePath(workspaceDir, profile, entry));
|
|
180
247
|
}
|
|
@@ -256,6 +323,8 @@ export function syncAgentWorkspaceSkills(
|
|
|
256
323
|
const next: ActiveSkillManifest = { format: 2, entries: {} };
|
|
257
324
|
const failed: AgentWorkspaceSkillChanges['failed'] = [];
|
|
258
325
|
const skipped: SkillHostSkip[] = [];
|
|
326
|
+
const conflicts = inspectSkillNameConflicts(workspaceDir, profile, snapshot, dependencies.targets);
|
|
327
|
+
const blockedNames = skillConflictNames(conflicts);
|
|
259
328
|
const hashDirectory = dependencies.hashDirectory ?? hashAgentSkillDirectory;
|
|
260
329
|
const overwriteTarget = dependencies.overwriteTarget ?? overwriteAgentSkillTarget;
|
|
261
330
|
const linkTarget = dependencies.linkTarget ?? linkAgentSkillTarget;
|
|
@@ -280,6 +349,7 @@ export function syncAgentWorkspaceSkills(
|
|
|
280
349
|
if (!item.skillRootPath) continue;
|
|
281
350
|
const path = resolveLocalAgentWorkspacePath(workspaceDir, profile, snapshot, item.skillRootPath);
|
|
282
351
|
const name = readSkillName(path);
|
|
352
|
+
if (name && blockedNames.has(skillNameKey(name))) continue;
|
|
283
353
|
if (!name || !/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/.test(name) || isPackageManagedSkill(name)) {
|
|
284
354
|
failed.push({
|
|
285
355
|
name: name ?? item.resourceId,
|
|
@@ -308,6 +378,11 @@ export function syncAgentWorkspaceSkills(
|
|
|
308
378
|
|
|
309
379
|
for (const entry of Object.values(readCapabilityWorkspaceRegistry(workspaceDir, profile).entries)) {
|
|
310
380
|
if (entry.type !== 'skill' || entry.origin !== 'local' || entry.selection !== 'equipped') continue;
|
|
381
|
+
if (entry.hub?.cloudStatus) continue;
|
|
382
|
+
if (entry.hub && !snapshot.items.skill.some(item => item.resourceId === entry.hub!.resourceId)) continue;
|
|
383
|
+
const path = capabilityWorkspacePath(workspaceDir, profile, entry);
|
|
384
|
+
const name = readSkillName(path) ?? entry.runtimeId;
|
|
385
|
+
if (blockedNames.has(skillNameKey(name))) continue;
|
|
311
386
|
if (isPackageManagedSkill(entry.runtimeId)) {
|
|
312
387
|
failed.push({
|
|
313
388
|
name: entry.runtimeId,
|
|
@@ -316,9 +391,8 @@ export function syncAgentWorkspaceSkills(
|
|
|
316
391
|
});
|
|
317
392
|
continue;
|
|
318
393
|
}
|
|
319
|
-
const path = capabilityWorkspacePath(workspaceDir, profile, entry);
|
|
320
394
|
if (desired.has(entry.runtimeId)) {
|
|
321
|
-
if (entry.hub?.resourceId === desired.get(entry.runtimeId)?.resourceId) continue;
|
|
395
|
+
if (entry.hub?.resourceId && entry.hub.resourceId === desired.get(entry.runtimeId)?.resourceId) continue;
|
|
322
396
|
failed.push({ name: entry.runtimeId, action: 'add', error: 'local and Hub Skill names conflict' });
|
|
323
397
|
continue;
|
|
324
398
|
}
|
|
@@ -332,7 +406,10 @@ export function syncAgentWorkspaceSkills(
|
|
|
332
406
|
const preservedModified: string[] = [];
|
|
333
407
|
|
|
334
408
|
for (const [name, item] of desired) {
|
|
335
|
-
|
|
409
|
+
// A local Skill already has its own working copy. Do not manufacture a
|
|
410
|
+
// second name-based copy/registry entry when the folder name differs.
|
|
411
|
+
const canonical = item.kind === 'local' ? item.sourcePath
|
|
412
|
+
: hubSkillWorkingCopyPath(workspaceDir, profile, name, item.resourceId!);
|
|
336
413
|
const previous = current.entries[name];
|
|
337
414
|
const sourceDigest = hashDirectory(item.sourcePath);
|
|
338
415
|
const sourceCloudDigest = item.remoteCloudDigest ?? cloudDigest(item.sourcePath);
|
|
@@ -489,6 +566,10 @@ export function syncAgentWorkspaceSkills(
|
|
|
489
566
|
}
|
|
490
567
|
|
|
491
568
|
for (const [name] of Object.entries(current.entries)) {
|
|
569
|
+
if (blockedNames.has(skillNameKey(name))) {
|
|
570
|
+
next.entries[name] = current.entries[name]!;
|
|
571
|
+
continue;
|
|
572
|
+
}
|
|
492
573
|
if (isPackageManagedSkill(name) || desired.has(name)) continue;
|
|
493
574
|
let failedRemoval = false;
|
|
494
575
|
const realTargets = realSkillTargets(targets(name));
|
|
@@ -509,6 +590,7 @@ export function syncAgentWorkspaceSkills(
|
|
|
509
590
|
// Keep reporting host-owned paths even in that case, without reopening selection.
|
|
510
591
|
for (const entry of Object.values(readCapabilityWorkspaceRegistry(workspaceDir, profile).entries)) {
|
|
511
592
|
if (entry.type !== 'skill' || isPackageManagedSkill(entry.runtimeId)
|
|
593
|
+
|| blockedNames.has(skillNameKey(entry.runtimeId))
|
|
512
594
|
|| desired.has(entry.runtimeId) || current.entries[entry.runtimeId]) continue;
|
|
513
595
|
const realTargets = realSkillTargets(targets(entry.runtimeId));
|
|
514
596
|
if (realTargets.length) skipped.push(skillHostSkip(entry.runtimeId, realTargets));
|
|
@@ -521,6 +603,7 @@ export function syncAgentWorkspaceSkills(
|
|
|
521
603
|
unchanged,
|
|
522
604
|
preservedModified,
|
|
523
605
|
failed,
|
|
606
|
+
...(conflicts.length ? { conflicts } : {}),
|
|
524
607
|
skipped,
|
|
525
608
|
requiresUserConfirmation: false,
|
|
526
609
|
};
|
|
@@ -26,6 +26,7 @@ import { HubClient, type ResourceType } from './hub-client.js';
|
|
|
26
26
|
import { findSkillRoot, overwriteAgentSkillTarget } from './skill-host.js';
|
|
27
27
|
import { unzip } from './hub-unzip.js';
|
|
28
28
|
import { zipContentDigest } from './zip-store.js';
|
|
29
|
+
import { selectedSkillNameConflicts, skillNameCandidate, skillNameKey } from './skill-name-conflicts.js';
|
|
29
30
|
|
|
30
31
|
export interface CapabilityCloudDownload {
|
|
31
32
|
type: CapabilityWorkspaceType;
|
|
@@ -234,6 +235,7 @@ export async function refreshCapabilitiesFromCloud(
|
|
|
234
235
|
const client = dependencies.client ?? HubClient.fromProfile(profile);
|
|
235
236
|
const result: CapabilityCloudRefreshResult = { downloaded: [], conflicts: [], failed: [], unchanged: [] };
|
|
236
237
|
const active = activeResourceIds(activeWorkspace);
|
|
238
|
+
const blockedSkillNames = new Set(selectedSkillNameConflicts(workspaceDir, profile, activeWorkspace).map(item => item.name));
|
|
237
239
|
const unresolvedParents = new Set(Object.values(activeWorkspace?.items ?? {}).flat().flatMap(item =>
|
|
238
240
|
item.forkReconciliation?.status === 'unresolved' ? [item.forkReconciliation.parentResourceId] : []));
|
|
239
241
|
const entries = Object.values(readCapabilityWorkspaceRegistry(workspaceDir, profile).entries)
|
|
@@ -246,6 +248,7 @@ export async function refreshCapabilitiesFromCloud(
|
|
|
246
248
|
&& !unresolvedParents.has(entry.hub.resourceId)
|
|
247
249
|
));
|
|
248
250
|
for (const entry of entries) {
|
|
251
|
+
if (entry.type === 'skill' && blockedSkillNames.has(skillNameKey(skillNameCandidate(workspaceDir, profile, entry).name))) continue;
|
|
249
252
|
const hub = entry.hub!;
|
|
250
253
|
const type = resourceType(entry.type);
|
|
251
254
|
const path = capabilityWorkspacePath(workspaceDir, profile, entry);
|
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
} from './hub-client.js';
|
|
29
29
|
import type { LocalAgentWorkspaceSnapshot } from './agent-workspace-sync.js';
|
|
30
30
|
import { readSkillName } from './skill-host.js';
|
|
31
|
+
import { selectedSkillNameConflicts, skillNameCandidate, skillNameKey } from './skill-name-conflicts.js';
|
|
31
32
|
import { createStoredZip, zipContentDigest, type ZipStoreEntry } from './zip-store.js';
|
|
32
33
|
import {
|
|
33
34
|
inspectClawclawBehaviorSource,
|
|
@@ -63,7 +64,7 @@ export interface CapabilityCloudSyncFailure extends Partial<HubErrorFields> {
|
|
|
63
64
|
export interface CapabilityCloudSyncSkip {
|
|
64
65
|
type: CapabilityWorkspaceType;
|
|
65
66
|
id: string;
|
|
66
|
-
reason: 'local_origin_unrecognized' | 'fork_relationship_unresolved';
|
|
67
|
+
reason: 'local_origin_unrecognized' | 'fork_relationship_unresolved' | 'skill_name_conflict';
|
|
67
68
|
}
|
|
68
69
|
|
|
69
70
|
export interface CapabilityCloudSyncResult {
|
|
@@ -244,6 +245,7 @@ export async function syncCapabilitiesToCloud(
|
|
|
244
245
|
unchanged: [],
|
|
245
246
|
};
|
|
246
247
|
const selectedKeys = dependencies.entryKeys ? new Set(dependencies.entryKeys) : undefined;
|
|
248
|
+
const blockedSkillNames = new Set(selectedSkillNameConflicts(workspaceDir, profile, snapshot).map(item => item.name));
|
|
247
249
|
const unresolvedForks = new Set(Object.values(snapshot.items).flat().flatMap(item =>
|
|
248
250
|
item.forkReconciliation?.status === 'unresolved'
|
|
249
251
|
? [item.resourceId, item.forkReconciliation.parentResourceId] : []));
|
|
@@ -254,6 +256,10 @@ export async function syncCapabilitiesToCloud(
|
|
|
254
256
|
&& (!selectedKeys || selectedKeys.has(entry.key))
|
|
255
257
|
));
|
|
256
258
|
for (const entry of entries) {
|
|
259
|
+
if (entry.type === 'skill' && blockedSkillNames.has(skillNameKey(skillNameCandidate(workspaceDir, profile, entry).name))) {
|
|
260
|
+
result.skipped.push({ type: entry.type, id: entry.runtimeId, reason: 'skill_name_conflict' });
|
|
261
|
+
continue;
|
|
262
|
+
}
|
|
257
263
|
if (entry.hub && (entry.hub.forkRelationshipUnresolved || unresolvedForks.has(entry.hub.resourceId))) {
|
|
258
264
|
result.skipped.push({ type: entry.type, id: entry.runtimeId, reason: 'fork_relationship_unresolved' });
|
|
259
265
|
continue;
|
|
@@ -4,6 +4,7 @@ import { assignCapabilityOperationName, capabilitySelectionRef,
|
|
|
4
4
|
readCapabilityWorkspaceRegistry, writeCapabilityWorkspaceRegistry,
|
|
5
5
|
type CapabilityWorkspaceType } from './capability-workspace.js';
|
|
6
6
|
import { updateGameplayConfig } from './gameplay-config.js';
|
|
7
|
+
import { skillNameCandidate, skillNameConflicts, throwSkillNameConflict } from './skill-name-conflicts.js';
|
|
7
8
|
|
|
8
9
|
export type EquipmentClient = Pick<HubClient,
|
|
9
10
|
'updateWorkspaceEquipment' | 'updateWorkspaceLoadout' | 'findWorkspaceItem'>;
|
|
@@ -25,6 +26,13 @@ export async function selectCapability(
|
|
|
25
26
|
));
|
|
26
27
|
if (matches.length !== 1) throw new Error(`capability_selection_${matches.length ? 'ambiguous' : 'not_found'}:${type}:${id}`);
|
|
27
28
|
const entry = matches[0]!;
|
|
29
|
+
if (type === 'skill' && equipped) {
|
|
30
|
+
const candidates = Object.values(registry.entries).filter(other => other.type === 'skill'
|
|
31
|
+
&& (other.key === entry.key || (other.selection === 'equipped' && !other.hub?.cloudStatus)));
|
|
32
|
+
const conflict = skillNameConflicts(candidates.map(other => skillNameCandidate(workspaceDir, profile, other)))
|
|
33
|
+
.find(item => item.candidates.some(candidate => candidate.selection_ref === capabilitySelectionRef(entry)));
|
|
34
|
+
if (conflict) throwSkillNameConflict(conflict);
|
|
35
|
+
}
|
|
28
36
|
if (entry.hub) {
|
|
29
37
|
const client = providedClient ?? HubClient.fromProfile(profile);
|
|
30
38
|
if (entry.hub.cloudStatus) throw new Error(`capability_workspace_removed:${type}/${id}`);
|
package/src/lib/skill-host.ts
CHANGED
|
@@ -218,6 +218,16 @@ export function unlinkAgentSkillTarget(targetPath: string): SkillHostMutationRes
|
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
220
|
|
|
221
|
+
/** An unequip must not remove another resource's link at the same Skill name. */
|
|
222
|
+
export function agentSkillLinkPointsTo(targetPath: string, sourcePath: string): boolean {
|
|
223
|
+
try {
|
|
224
|
+
return lstatSync(targetPath).isSymbolicLink()
|
|
225
|
+
&& realpathSync(targetPath) === realpathSync(sourcePath);
|
|
226
|
+
} catch {
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
221
231
|
export function unregisterAgentSkill(name: string): SkillHostMutationResult {
|
|
222
232
|
return runSkillsCli(['remove', name, '-g', '-y']);
|
|
223
233
|
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { resolve } from 'node:path';
|
|
2
|
+
import type { AuthProfile } from './auth.js';
|
|
3
|
+
import {
|
|
4
|
+
resolveLocalAgentWorkspacePath,
|
|
5
|
+
type LocalAgentWorkspaceSnapshot,
|
|
6
|
+
} from './agent-workspace-sync.js';
|
|
7
|
+
import {
|
|
8
|
+
capabilitySelectionRef,
|
|
9
|
+
capabilityWorkspacePath,
|
|
10
|
+
readCapabilityWorkspaceRegistry,
|
|
11
|
+
type CapabilityWorkspaceEntry,
|
|
12
|
+
} from './capability-workspace.js';
|
|
13
|
+
import { CommandOutputError } from './command-error.js';
|
|
14
|
+
import { readSkillName } from './skill-host.js';
|
|
15
|
+
|
|
16
|
+
export interface SkillNameCandidate {
|
|
17
|
+
name: string;
|
|
18
|
+
id?: string;
|
|
19
|
+
working_copy_path: string;
|
|
20
|
+
selection_ref?: string;
|
|
21
|
+
resource_id?: string;
|
|
22
|
+
workspace_item_id?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface SkillNameConflict {
|
|
26
|
+
code: 'SKILL_NAME_CONFLICT';
|
|
27
|
+
name: string;
|
|
28
|
+
blocking: boolean;
|
|
29
|
+
candidates: SkillNameCandidate[];
|
|
30
|
+
active?: SkillNameCandidate;
|
|
31
|
+
unavailable?: SkillNameCandidate[];
|
|
32
|
+
hint: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const skillNameKey = (name: string): string => name.toLowerCase();
|
|
36
|
+
|
|
37
|
+
export function skillNameCandidate(
|
|
38
|
+
workspaceDir: string,
|
|
39
|
+
profile: Pick<AuthProfile, 'apiKey'>,
|
|
40
|
+
entry: CapabilityWorkspaceEntry,
|
|
41
|
+
): SkillNameCandidate {
|
|
42
|
+
const path = capabilityWorkspacePath(workspaceDir, profile, entry);
|
|
43
|
+
return {
|
|
44
|
+
name: readSkillName(path) ?? entry.runtimeId,
|
|
45
|
+
id: entry.runtimeId,
|
|
46
|
+
working_copy_path: path,
|
|
47
|
+
selection_ref: capabilitySelectionRef(entry),
|
|
48
|
+
...(entry.hub ? { resource_id: entry.hub.resourceId, workspace_item_id: entry.hub.workspaceItemId } : {}),
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function sameSkill(left: SkillNameCandidate, right: SkillNameCandidate): boolean {
|
|
53
|
+
// Missing Hub IDs are not an identity. Two local resources must remain distinct.
|
|
54
|
+
if (left.resource_id || right.resource_id) {
|
|
55
|
+
return !!left.resource_id && left.resource_id === right.resource_id;
|
|
56
|
+
}
|
|
57
|
+
return resolve(left.working_copy_path) === resolve(right.working_copy_path);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function skillNameConflicts(candidates: readonly SkillNameCandidate[]): SkillNameConflict[] {
|
|
61
|
+
const groups = new Map<string, SkillNameCandidate[]>();
|
|
62
|
+
for (const candidate of candidates) {
|
|
63
|
+
const name = skillNameKey(candidate.name);
|
|
64
|
+
const group = groups.get(name) ?? [];
|
|
65
|
+
const previous = group.findIndex(other => sameSkill(other, candidate));
|
|
66
|
+
if (previous < 0) group.push(candidate);
|
|
67
|
+
else if (candidate.selection_ref) group[previous] = candidate;
|
|
68
|
+
groups.set(name, group);
|
|
69
|
+
}
|
|
70
|
+
return [...groups].filter(([, group]) => group.length > 1).map(([name, group]) => ({
|
|
71
|
+
code: 'SKILL_NAME_CONFLICT', name, blocking: true, candidates: group,
|
|
72
|
+
hint: 'Only one Skill with this name may be equipped. Choose which resource to keep and unequip the others using their selection_ref (or in Hub), then run ccl load. No Skill is renamed or replaced automatically.',
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Also freeze old host names if someone edited SKILL.md before the next load. */
|
|
77
|
+
export function skillConflictNames(conflicts: readonly SkillNameConflict[]): Set<string> {
|
|
78
|
+
return new Set(conflicts.flatMap(conflict => [conflict.name,
|
|
79
|
+
...conflict.candidates.flatMap(candidate => [candidate.name, ...(candidate.id ? [candidate.id] : [])]),
|
|
80
|
+
]).map(skillNameKey));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** A supplied Hub snapshot is authoritative; local-only choices remain independent. */
|
|
84
|
+
export function selectedSkillNameConflicts(
|
|
85
|
+
workspaceDir: string,
|
|
86
|
+
profile: Pick<AuthProfile, 'apiKey'>,
|
|
87
|
+
snapshot?: LocalAgentWorkspaceSnapshot,
|
|
88
|
+
): SkillNameConflict[] {
|
|
89
|
+
const candidates: SkillNameCandidate[] = [];
|
|
90
|
+
const selectedIds = new Set(snapshot?.items.skill.map(item => item.resourceId));
|
|
91
|
+
for (const item of snapshot?.items.skill ?? []) {
|
|
92
|
+
if (!item.skillRootPath) continue;
|
|
93
|
+
const path = resolveLocalAgentWorkspacePath(workspaceDir, profile, snapshot!, item.skillRootPath);
|
|
94
|
+
const name = readSkillName(path);
|
|
95
|
+
if (name) candidates.push({ name, working_copy_path: path,
|
|
96
|
+
resource_id: item.resourceId, workspace_item_id: item.workspaceItemId });
|
|
97
|
+
}
|
|
98
|
+
for (const entry of Object.values(readCapabilityWorkspaceRegistry(workspaceDir, profile).entries)) {
|
|
99
|
+
if (entry.type !== 'skill' || entry.selection !== 'equipped' || entry.hub?.cloudStatus) continue;
|
|
100
|
+
if (snapshot && entry.hub && !selectedIds.has(entry.hub.resourceId)) continue;
|
|
101
|
+
candidates.push(skillNameCandidate(workspaceDir, profile, entry));
|
|
102
|
+
}
|
|
103
|
+
return skillNameConflicts(candidates);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function throwSkillNameConflict(conflict: SkillNameConflict): never {
|
|
107
|
+
throw new CommandOutputError(`SKILL_NAME_CONFLICT:${conflict.name}`, {
|
|
108
|
+
error: 'skill_name_conflict', ...conflict, retryable: false,
|
|
109
|
+
});
|
|
110
|
+
}
|
|
@@ -469,7 +469,13 @@ function shortBody(event: Record<string, any>, ctx: EventFormatContext): string
|
|
|
469
469
|
case 'emergency_interrupted':
|
|
470
470
|
return `你在处理${firstString(event, ['task_name'])}时死亡,紧急任务仍未解除。`;
|
|
471
471
|
case 'ability.ready':
|
|
472
|
+
if (event.ability_id === 'sabotage') return `蟹阵营共享破坏能力已恢复就绪。${event.phase === 'meeting' ? '当前会议中,结束后可执行。' : ''}`;
|
|
472
473
|
return `能力“${firstString(event, ['ability_name', 'ability_id'])}”现在可以使用。`;
|
|
474
|
+
case 'ability.unavailable':
|
|
475
|
+
if (event.ability_id === 'sabotage') return event.status === 'emergency_active'
|
|
476
|
+
? '蟹阵营共享破坏能力暂不可用:紧急任务正在进行。'
|
|
477
|
+
: `蟹阵营共享破坏能力进入冷却${typeof event.cooldown_remaining_secs === 'number' ? `,剩余${event.cooldown_remaining_secs}秒` : ''}。`;
|
|
478
|
+
return `能力“${firstString(event, ['ability_name', 'ability_id'])}”暂不可用。`;
|
|
473
479
|
case 'ability.remaining_uses_changed':
|
|
474
480
|
return `能力“${firstString(event, ['ability_name', 'ability_id'])}”剩余${text(event.remaining_uses, '?')}次。`;
|
|
475
481
|
case 'ability.exhausted':
|
|
@@ -10,6 +10,7 @@ export const CLAWCLAW_MONITOR_EVENT_PRIORITY: Readonly<Record<string, number>> =
|
|
|
10
10
|
task_interrupted: 95,
|
|
11
11
|
emergency_countdown_warning: 95,
|
|
12
12
|
'ability.ready': 80,
|
|
13
|
+
'ability.unavailable': 80,
|
|
13
14
|
'ability.remaining_uses_changed': 80,
|
|
14
15
|
'ability.exhausted': 90,
|
|
15
16
|
'behavior.completed': 90,
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { Runtime } from '../framework/runtime.js';
|
|
2
|
+
import type { OwnerControlResponse } from '../owner-control.js';
|
|
3
|
+
import type { ClawclawBehaviorPlugin } from './plugins/behavior/behavior-plugin.js';
|
|
4
|
+
|
|
5
|
+
type StartRuntime = Pick<Runtime, 'publicScope' | 'currentSegment' | 'readState'>;
|
|
6
|
+
type BehaviorStarter = Pick<ClawclawBehaviorPlugin, 'startLong' | 'startShort'>;
|
|
7
|
+
|
|
8
|
+
interface BehaviorStartRequest {
|
|
9
|
+
expectedScope: Readonly<{ sessionId: string; segmentId: string }>;
|
|
10
|
+
behavior: string;
|
|
11
|
+
layer: 'long' | 'short';
|
|
12
|
+
input: Readonly<Record<string, unknown>>;
|
|
13
|
+
maxRuntimeMs?: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function startRejection(runtime: StartRuntime, request: BehaviorStartRequest): OwnerControlResponse | undefined {
|
|
17
|
+
const actual = runtime.publicScope();
|
|
18
|
+
const expected = request.expectedScope;
|
|
19
|
+
if (actual.sessionId !== expected.sessionId || actual.segmentId !== expected.segmentId) {
|
|
20
|
+
return { ok: false, type: 'behavior_start', error: 'stale_runtime_scope' };
|
|
21
|
+
}
|
|
22
|
+
if (runtime.currentSegment().kind !== 'game') {
|
|
23
|
+
return { ok: false, type: 'behavior_start', error: 'no_active_game' };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Admission reads accepted Source state, not the potentially older Ready view.
|
|
27
|
+
const { state, stateStatus } = runtime.readState();
|
|
28
|
+
const scope = stateStatus.scope;
|
|
29
|
+
const inScope = scope?.sessionId === expected.sessionId && scope.segmentId === expected.segmentId;
|
|
30
|
+
let code: string;
|
|
31
|
+
let message: string;
|
|
32
|
+
if (inScope && (state?.phase === 'game_over' || state?.phase === 'settling')) {
|
|
33
|
+
code = 'GAME_ENDED';
|
|
34
|
+
message = `The game has ended. Strategy '${request.behavior}' was not started.`;
|
|
35
|
+
} else if (inScope && state?.you?.is_alive === false) {
|
|
36
|
+
code = 'PLAYER_DEAD';
|
|
37
|
+
message = `The player is dead. Strategy '${request.behavior}' was not started.`;
|
|
38
|
+
} else if (!inScope || stateStatus.status !== 'fresh' || state?.you?.is_alive !== true) {
|
|
39
|
+
code = 'GAME_STATE_UNAVAILABLE';
|
|
40
|
+
message = `Current player state is unavailable. Strategy '${request.behavior}' was not started.`;
|
|
41
|
+
} else {
|
|
42
|
+
// A living player's strategy may still wait for a meeting or another layer.
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
return { ok: false, type: 'behavior_start', error: code, code, message };
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Game-specific admission for explicit strategy starts; GAR owns activation mechanics. */
|
|
49
|
+
export async function startOwnerBehavior(
|
|
50
|
+
runtime: StartRuntime,
|
|
51
|
+
behavior: BehaviorStarter,
|
|
52
|
+
request: BehaviorStartRequest,
|
|
53
|
+
): Promise<OwnerControlResponse> {
|
|
54
|
+
let rejection: OwnerControlResponse | undefined;
|
|
55
|
+
const isCurrent = (): boolean => {
|
|
56
|
+
rejection = startRejection(runtime, request);
|
|
57
|
+
return rejection === undefined;
|
|
58
|
+
};
|
|
59
|
+
if (!isCurrent()) return rejection!;
|
|
60
|
+
try {
|
|
61
|
+
const options = {
|
|
62
|
+
source: 'agent' as const,
|
|
63
|
+
// The existing GAR guard runs in its control queue after async preparation,
|
|
64
|
+
// before an activation is created or an existing strategy is replaced.
|
|
65
|
+
isCurrent,
|
|
66
|
+
...(request.maxRuntimeMs === undefined ? {} : { maxRuntimeMs: request.maxRuntimeMs }),
|
|
67
|
+
};
|
|
68
|
+
const activation = request.layer === 'long'
|
|
69
|
+
? await behavior.startLong(request.behavior, request.input, options)
|
|
70
|
+
: await behavior.startShort(request.behavior, request.input, options);
|
|
71
|
+
return { ok: true, type: 'behavior_start', status: 'accepted', activation };
|
|
72
|
+
} catch (error) {
|
|
73
|
+
return rejection ?? {
|
|
74
|
+
ok: false,
|
|
75
|
+
type: 'behavior_start',
|
|
76
|
+
error: error instanceof Error ? error.message : String(error),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -5,6 +5,7 @@ import { createClawclawProcessingCadence } from './runtime-cadence.js';
|
|
|
5
5
|
import { readRuntimeCycleIntervalMs } from '../../lib/runtime-cadence-config.js';
|
|
6
6
|
import { randomUUID } from 'node:crypto';
|
|
7
7
|
import { BehaviorReflexControl } from './behavior-reflex-control.js';
|
|
8
|
+
import { startOwnerBehavior } from './behavior-start-control.js';
|
|
8
9
|
import { acquireOwnerLock, type OwnerLock } from './owner-lock.js';
|
|
9
10
|
import { createStartingOwnerControl } from './starting-owner-control.js';
|
|
10
11
|
export { acquireOwnerLock, type OwnerLock, type OwnerLockOperations } from './owner-lock.js';
|
|
@@ -1224,27 +1225,13 @@ export async function runClawclawOwner(
|
|
|
1224
1225
|
|| maxRuntimeMs > 120_000
|
|
1225
1226
|
))
|
|
1226
1227
|
) return { ok: false, type: 'behavior_start', error: 'invalid_behavior_start_request' };
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
...(maxRuntimeMs === undefined ? {} : { maxRuntimeMs }),
|
|
1235
|
-
})
|
|
1236
|
-
: await assembly.behavior.startShort(behavior, behaviorInput, {
|
|
1237
|
-
source: 'agent',
|
|
1238
|
-
...(maxRuntimeMs === undefined ? {} : { maxRuntimeMs }),
|
|
1239
|
-
});
|
|
1240
|
-
return { ok: true, type: 'behavior_start', status: 'accepted', activation };
|
|
1241
|
-
} catch (error) {
|
|
1242
|
-
return {
|
|
1243
|
-
ok: false,
|
|
1244
|
-
type: 'behavior_start',
|
|
1245
|
-
error: error instanceof Error ? error.message : String(error),
|
|
1246
|
-
};
|
|
1247
|
-
}
|
|
1228
|
+
return startOwnerBehavior(runtime!, assembly.behavior, {
|
|
1229
|
+
expectedScope: expected,
|
|
1230
|
+
behavior,
|
|
1231
|
+
layer,
|
|
1232
|
+
input: behaviorInput,
|
|
1233
|
+
...(maxRuntimeMs === undefined ? {} : { maxRuntimeMs }),
|
|
1234
|
+
});
|
|
1248
1235
|
}
|
|
1249
1236
|
if (request.type === 'behavior_status') {
|
|
1250
1237
|
return { ok: true, type: 'behavior_status', status: reflexControl.view(typeof request.behavior === 'string' ? request.behavior : undefined) };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { RuntimeEventProposal } from '../../../framework/plugins/index.js';
|
|
2
|
+
import type { StoredStateFrame } from '../../../framework/state/index.js';
|
|
3
|
+
import type { ClawclawDerivedEventRule } from '../derived-event/derived-event-rules.js';
|
|
4
|
+
import { isClawclawRuntimeState } from '../../runtime-state.js';
|
|
5
|
+
|
|
6
|
+
type SabotageStatus = 'ready' | 'cooldown_charged' | 'emergency_active';
|
|
7
|
+
|
|
8
|
+
/** Shared sabotage availability belongs to the game, not to a strategy instance. */
|
|
9
|
+
export class SabotageAvailabilityRule implements ClawclawDerivedEventRule {
|
|
10
|
+
readonly id = 'sabotage-availability';
|
|
11
|
+
readonly eventTypes = ['ability.ready', 'ability.unavailable'] as const;
|
|
12
|
+
private boundary?: string;
|
|
13
|
+
private status?: SabotageStatus;
|
|
14
|
+
|
|
15
|
+
reset(): void { this.boundary = undefined; this.status = undefined; }
|
|
16
|
+
|
|
17
|
+
inspect(frame: StoredStateFrame<Record<string, any>>): RuntimeEventProposal[] {
|
|
18
|
+
const runtime = frame.state;
|
|
19
|
+
if (isClawclawRuntimeState(runtime) && runtime.connection !== 'connected') {
|
|
20
|
+
this.reset();
|
|
21
|
+
return [];
|
|
22
|
+
}
|
|
23
|
+
const game = isClawclawRuntimeState(runtime)
|
|
24
|
+
? runtime.game_snapshot.status === 'fresh' || runtime.game_snapshot.status === 'cached'
|
|
25
|
+
? runtime.game_snapshot.state : undefined
|
|
26
|
+
: runtime;
|
|
27
|
+
if (!game) return [];
|
|
28
|
+
const boundary = JSON.stringify([frame.scope.sessionId, frame.scope.segmentId, frame.connectionId, game.game_id]);
|
|
29
|
+
if (this.boundary !== boundary) { this.boundary = boundary; this.status = undefined; }
|
|
30
|
+
const current = game.crab_sabotage?.status;
|
|
31
|
+
if (current !== 'ready' && current !== 'cooldown_charged' && current !== 'emergency_active') return [];
|
|
32
|
+
const previous = this.status;
|
|
33
|
+
this.status = current;
|
|
34
|
+
if (previous === undefined || (previous === 'ready') === (current === 'ready')) return [];
|
|
35
|
+
if (game.you?.is_alive !== true || game.phase === 'game_over') return [];
|
|
36
|
+
if (game.you?.faction !== 'crab' && game.you?.role !== 'crab_generic') return [];
|
|
37
|
+
const remaining = game.crab_sabotage.cooldown_remaining_secs;
|
|
38
|
+
return [{
|
|
39
|
+
type: current === 'ready' ? 'ability.ready' : 'ability.unavailable',
|
|
40
|
+
dedupeKey: `sabotage-availability:${frame.epochSeq ?? frame.frameSeq}:${current}`,
|
|
41
|
+
dedupeScope: 'segment',
|
|
42
|
+
occurredAt: new Date(frame.observedAtMs ?? frame.receivedAtMs).toISOString(),
|
|
43
|
+
payload: {
|
|
44
|
+
ability_id: 'sabotage', ability_name: '破坏', shared: true,
|
|
45
|
+
previous_status: previous, status: current,
|
|
46
|
+
...(typeof game.tick === 'number' ? { tick: game.tick } : {}),
|
|
47
|
+
...(typeof game.phase === 'string' ? { phase: game.phase } : {}),
|
|
48
|
+
...(current === 'cooldown_charged' && typeof remaining === 'number' && Number.isFinite(remaining)
|
|
49
|
+
? { cooldown_remaining_secs: Math.max(0, remaining) } : {}),
|
|
50
|
+
},
|
|
51
|
+
}];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -10,6 +10,7 @@ import { defaultReminder, TASK_LIFECYCLE_FACT_TYPES } from '../../../../sdk/perc
|
|
|
10
10
|
import { clawclawComputationGameState } from '../../runtime-state.js';
|
|
11
11
|
import { createCanonicalGameState } from '../../behavior-input.js';
|
|
12
12
|
import { projectTaskChoiceEventPayload } from '../../task-choice-projection.js';
|
|
13
|
+
import { SabotageAvailabilityRule } from './sabotage-availability-rule.js';
|
|
13
14
|
|
|
14
15
|
export const BUILTIN_PERCEPTION_NAMES = {
|
|
15
16
|
players: '玩家变化', tasks: '任务提醒', abilities: '能力变化', emergency: '紧急任务',
|
|
@@ -98,7 +99,7 @@ export function createSystemPerceptions(behaviorEventTypes: readonly string[] =
|
|
|
98
99
|
return [
|
|
99
100
|
new SystemPerceptionPlugin('players', groups.players, [new PlayerChangesDerivedEventRule()]),
|
|
100
101
|
new SystemPerceptionPlugin('tasks', groups.tasks),
|
|
101
|
-
new SystemPerceptionPlugin('abilities', groups.abilities, [new AbilityStateDerivedEventRule()]),
|
|
102
|
+
new SystemPerceptionPlugin('abilities', groups.abilities, [new AbilityStateDerivedEventRule(), new SabotageAvailabilityRule()]),
|
|
102
103
|
new SystemPerceptionPlugin('emergency', groups.emergency, [new EmergencyCountdownDerivedEventRule()]),
|
|
103
104
|
new SystemPerceptionPlugin('flow', groups.flow, [new RoomReadyDerivedEventRule()]),
|
|
104
105
|
new SystemPerceptionPlugin('meeting', groups.meeting),
|