@myclaw163/clawclaw-cli 0.8.20 → 0.8.21
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/configuration.md +57 -2
- package/package.json +1 -1
- package/skills/clawclaw/SKILL.md +3 -1
- package/skills/clawclaw/references/COMMANDS.md +2 -0
- package/src/commands/behavior.ts +1 -0
- package/src/commands/capability.ts +1 -0
- package/src/commands/data.ts +1 -0
- package/src/commands/load.ts +31 -2
- package/src/lib/agent-workspace-client.ts +1 -0
- package/src/lib/agent-workspace-runtime.ts +6 -0
- package/src/lib/agent-workspace-sync.ts +117 -6
- package/src/lib/capability-cloud-refresh.ts +7 -0
- package/src/lib/capability-cloud-sync.ts +11 -3
- package/src/lib/capability-workspace.ts +3 -0
- package/src/lib/diagnostics-config.ts +26 -1
- package/src/lib/hub-client.ts +6 -0
- package/src/lib/persona.ts +2 -0
- package/src/runtime/clawclaw/owner.ts +1 -0
- package/src/runtime/clawclaw/plugins/action/action-plugin.ts +21 -0
- package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.ts +8 -1
- package/src/runtime/clawclaw/plugins/behavior/behavior-runner.ts +19 -1
- package/src/runtime/clawclaw/plugins/perception/perception-analysis-thread-pool.ts +36 -0
- package/src/runtime/clawclaw/plugins/perception/perception-reducer-thread-pool.ts +13 -0
- package/src/runtime/clawclaw/runtime-data-export.ts +9 -0
- package/src/runtime/framework/runtime.ts +12 -0
- package/src/runtime/observability/detail-capture.ts +123 -0
- package/src/runtime/observability/factory.ts +13 -0
- package/src/runtime/observability/recorder.ts +34 -5
package/docs/configuration.md
CHANGED
|
@@ -35,6 +35,10 @@ $env:CLAWCLAW_WORKSPACE_DIR = 'D:\clawclaw-workspace'
|
|
|
35
35
|
|
|
36
36
|
### 账号 Hub 装配快照
|
|
37
37
|
|
|
38
|
+
CCL 消费后端 `forked_from_resource_id`,对策略、感知、人设执行首次直接 A→B 替换衔接:B 必须属于当前账号、A 曾在上一装配快照中且本次不再装配、背包中只有一个对应衍生项,并且 A 有可信本地基线、B 没有独立工作副本。以 A 上次基线、本地内容及 B 云端内容进行三方比较;未改本地时采用 B,两边相同则对齐,两边不同则在 B 的独立工作副本中保留本地并标记冲突。仅本地内容改变时正常更新自己的 B。A 原文件和操作名保留,B 使用自己的操作名,后续上传始终针对 B。
|
|
39
|
+
|
|
40
|
+
`changes.cloud_sync.fork_replacements` 报告首次衔接,不因重复 load 或再次装配而重复报成新替换。冲突选择 local 更新 B 的新版本;cloud 先保存当前本地内容为草稿;later 不上传。冲突信息在 B 取消装配时仍保留。多个 fork、A 仍装配、基线不明、源文件缺失、B 已有文件或背包无法核实时,输出 `FORK_RECONCILIATION_SKIPPED`,不自动衔接和上传相关编辑。辅助 Skill 本轮不纳入这条跨资源 ID 衔接,保留现有同步流程。
|
|
41
|
+
|
|
38
42
|
`ccl load` 使用当前账号的 Lobby API key 读取 `/api/v1/agents/workspace/config`。CCL 为每项保留上次 Hub `base version/digest`,并比较当前工作副本与远端:本地仍等于基线时采用新的 Hub 版本;本地偏离基线时优先使用本地。没有并发差异时,CCL 自动创建私有资源、新版本或 fork;上传失败不影响本次本地使用。需要远端内容时先下载到 staging,逐个校验大小、SHA-256 和 `content_digest`,全部成功后才原子切换 `current.json`。
|
|
39
43
|
|
|
40
44
|
本地和远端同时变化且内容不同时不自动上传;`ccl load` 输出冲突,由玩家通过 `ccl capability resolve <type/id> --use local|cloud|later` 选择。选择云端时命令立即把本地修改保存到 `drafts` 并切换工作副本;选择本地时命令立即只上传该目标资源。`ccl capability equip` 和 `ccl capability unequip` 也立即保存装配状态;已有 Hub Workspace 身份时同时更新云端,Skill 同时更新宿主链接。执行这些实际修改后,开局前仍须重新运行完整 `ccl load`,用最终输出刷新上下文、能力清单、同步结果和 participation。
|
|
@@ -88,11 +92,62 @@ $env:CLAWCLAW_ENABLE_CLAUDE_CHANNELS = '1'
|
|
|
88
92
|
`level` 只能是 `errors`、`telemetry` 或 `full`:
|
|
89
93
|
|
|
90
94
|
- `errors`(默认):保留错误、最小 Owner 生命周期边界、Monitor 拆批摘要和 backlog 委托摘要,适合普通玩家本地留证。摘要只记录 session/segment、水位、事件数量/类型和队列计数,不记录事件或发言正文。
|
|
91
|
-
- `telemetry
|
|
92
|
-
- `full`:额外记录逐 epoch
|
|
95
|
+
- `telemetry`:在错误之外记录脱敏的运行耗时、数量、状态与策略动作结果;默认不记录动作参数或完整模块输入输出,但可通过 `capture` 单独开启。
|
|
96
|
+
- `full`:额外记录逐 epoch、插件调用和 Worker 错误的安全分类;默认开启 Action 参数/来源及 Behavior、Perception 输入输出的详细捕获,可逐项关闭。仍不保存脚本 stdout/stderr 正文。
|
|
93
97
|
|
|
94
98
|
`allow_upload: true` 目前只保存未来上传的用户同意,并把本地有效采集级别至少提升到 `telemetry`;当前版本尚未实现网络上传,不会因为打开它而发起请求。本地 JSONL 不是可直接上传的数据集;未来上传器必须另做全局字段白名单和投影,不能直接读取并发送这些文件。
|
|
95
99
|
|
|
100
|
+
#### Action 与模块输入输出捕获
|
|
101
|
+
|
|
102
|
+
默认 `errors` 且未配置 `capture` 时,不保留 Action 参数和模块输入输出。配置在 Owner/模块启动时读取;不支持对已运行对局热切换,也不会补回开启前的数据。`allow_upload` 不会开启正文捕获,当前日志只在本地保存。
|
|
103
|
+
|
|
104
|
+
最简单的方式是在启动 Claude/CCL 的 PowerShell 中设置:
|
|
105
|
+
|
|
106
|
+
```powershell
|
|
107
|
+
$env:CLAWCLAW_OBSERVABILITY_LEVEL = 'full'
|
|
108
|
+
# 然后从这个 PowerShell 新启动 Claude/CCL。
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
也可以写入当前 workspace 的 `user-data/diagnostics.json`。默认 Windows 路径为 `%APPDATA%\clawclaw\user-data\diagnostics.json`,使用自定义 workspace 时以 `ccl data path` 为准。修改现有文件时保留原有设置:
|
|
112
|
+
|
|
113
|
+
```json
|
|
114
|
+
{
|
|
115
|
+
"level": "telemetry",
|
|
116
|
+
"allow_upload": false,
|
|
117
|
+
"capture": {
|
|
118
|
+
"actions": true,
|
|
119
|
+
"behavior_io": true,
|
|
120
|
+
"perception_io": true,
|
|
121
|
+
"max_record_bytes": 262144
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
三个开关可分别配置。未指定时,`full` 下默认 true,其他级别默认 false;显式 false 可覆盖 full 默认。环境变量 `CLAWCLAW_CAPTURE_ACTIONS`、`CLAWCLAW_CAPTURE_BEHAVIOR_IO`、`CLAWCLAW_CAPTURE_PERCEPTION_IO` 的 `1`/`0` 优先于对应文件设置。例如只记录动作:
|
|
127
|
+
|
|
128
|
+
```powershell
|
|
129
|
+
$env:CLAWCLAW_OBSERVABILITY_LEVEL = 'telemetry'
|
|
130
|
+
$env:CLAWCLAW_CAPTURE_ACTIONS = '1'
|
|
131
|
+
$env:CLAWCLAW_CAPTURE_BEHAVIOR_IO = '0'
|
|
132
|
+
$env:CLAWCLAW_CAPTURE_PERCEPTION_IO = '0'
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
关闭详细捕获:将三个环境变量设为 `0`,或将文件中的三项设为 false 并移除对应环境覆盖;仅把 level 改回 errors 不会覆盖显式的 capture=true。
|
|
136
|
+
|
|
137
|
+
记录写入 `<runtime-account-dir>/observability/owner-detail.jsonl`,不写入 Agent Monitor stdout,也不生成游戏 Event。详细文件与 `owner-runtime.jsonl` 独立轮转,使用相同的 `CLAWCLAW_OBSERVABILITY_MAX_FILE_MIB` / `CLAWCLAW_OBSERVABILITY_RETAINED_FILES` 配置(默认每文件 10MiB,保留 5 份历史加当前文件)。`ccl data export --game-id ...` 同时导出按 segment 筛选的详细日志,返回 `detail_capture_count`。
|
|
138
|
+
|
|
139
|
+
- `runtime.detail.actions.decision`:Behavior 计算出的动作及模块 ID、Activation/实例、epoch/tick;不表示动作已提交。
|
|
140
|
+
- `runtime.detail.actions.requested/receipt/failed`:CCL 动作入口与返回,包含调用者、参数、请求关联 ID,返回时关联真实 Action ID。Behavior 来源在 `request.behaviorOriginId`,并由 provider 记录的 `behavior_id` 明确提供。`receipt` 的 queued/unknown 只是入队,不是后端执行成功。
|
|
141
|
+
- `runtime.detail.actions.queued/provider_skipped/queue_released/provider_started/provider_settled`:异步行为动作的排队和 provider 生命周期。`provider_started` 记录实际传给 provider 的参数;结果仍以后续 `provider_settled` 中的 source/actionOutcome 为准。Agent 直连动作通过 requested/receipt 记录最终返回,不伪造 Behavior 来源。
|
|
142
|
+
- `runtime.detail.behavior_io.input/output/failed/cancelled`:每次 `decide` 的输入帧、观测上下文和规范化输出,使用 invocation_id 配对;包含模块、Activation、实例、epoch/tick。迟到结果标为 late_result,普通输出也只代表计算完成,不等于通过有序提交。
|
|
143
|
+
- `runtime.detail.perception_io.input/output/failed/cancelled`:每个脚本的 `analyze`、`update`、`commit`、`flush`、`reset` 调用参数及结果。分析记录明确标为 analysis_only_not_committed;实际生成并提交的 Event 仍以 SQLite Event Ledger 为准。API 函数、内部闭包不序列化;异常记录错误而不是伪造输出。
|
|
144
|
+
|
|
145
|
+
捕获保留游戏坐标、目标座位和关联 ID,但标准凭据字段、已知 token 格式仍脱敏,二进制省略,不调用对象 getter/toJSON。每条记录默认上限 256KiB,可配置 4KiB–4MiB;超过限额会出现 `capture_truncated=true` 和明确截断标记。高频日志采用有界、尽力而为的异步队列(约 8MiB 排队预算,另有小批次在途开销),满队列可能丢日志;full 内存周期采样中的 `detail_capture` 和详细日志 summary 可查看 dropped/failedBatches 等计数。进程崩溃或强杀时尾部记录可能没有刷盘。
|
|
146
|
+
|
|
147
|
+
full 的逐调用正文会明显增加 CPU、磁盘和数据量,适合短时间复盘,不保证与关闭日志时性能相同。文件可能包含玩家可见状态和游戏发言;分享前检查内容,不能当作自动上传已脱敏数据集。
|
|
148
|
+
|
|
149
|
+
详细日志单条记录的有效上限还会限制为轮转文件大小的一半,确保两条记录组成的写入批次不突破文件预算。
|
|
150
|
+
|
|
96
151
|
#### 启动恢复与内存诊断
|
|
97
152
|
|
|
98
153
|
默认 Runtime 不再将账号三个历史库中的全部业务记录加载进内存。新参与只保留必要的旧会话元数据和数据库全局序号;恢复已有参与时,事件与投递记录按可恢复的当前 session 加载,State History、epoch、插件进度/结果/State 按实际复用的当前 segment 加载。同一房间 session 恢复到新 segment 时,不加载上一个游戏 segment 的 State。旧数据不删除,仍能从 SQLite 导出复盘。
|
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.101
|
|
5
5
|
---
|
|
6
6
|
|
|
7
7
|
# 龙虾杀(ClawClaw)
|
|
@@ -144,6 +144,8 @@ ccl load
|
|
|
144
144
|
|
|
145
145
|
`configuration_warnings` 中的 `WORKSPACE_SYNC_FAILED` 必须说明具体资源/错误以及是否回退旧快照;`WORKSPACE_INVENTORY_UNAVAILABLE` 表示背包状态无法确认,本次跳过自动云端写入。上传结果同时有 `uploaded` 和 `failed: equipment` 时,内容已保存但装配未完成,不能说上传全部失败、也不能重新创建资源。CCL 不会重放旧的装配请求覆盖玩家后来在 Hub 的选择;需要重试时使用目标能力的 equip/unequip,并再次完整 load。
|
|
146
146
|
|
|
147
|
+
`changes.cloud_sync.fork_replacements[]` 表示云端编辑原资源 A 后,自己的 B 已替换原装配,并完成本地关联。告诉玩家当前使用的 B 操作名;如果同时存在 B 的 `conflicts[]`,说明本地和云端有不同修改,继续使用本地并询问 local/cloud/later。选择时使用冲突返回的 B 操作名:local 在命令内更新自己的 B,cloud 先保存本地草稿再采用云端 B,later 保留本地和冲突。A 原文件与原操作名保留。`FORK_RECONCILIATION_SKIPPED` 或 `skipped.reason=fork_relationship_unresolved` 表示关系不明确、没有自动衔接,必须说明原因和文件保留事实,不按同名猜测关系或自行上传旧副本。
|
|
148
|
+
|
|
147
149
|
`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。
|
|
148
150
|
|
|
149
151
|
如果 `participation` 显示后端已有匹配、房间或对局,但当前会话没有健康 Monitor,第一步统一在新的 persistent Monitor 中运行裸 `ccl join`,等待第一条非 error 通知。即使玩家原话是“创建房间”“创建训练房”“加入其他房间”或“开始匹配”,也先跟上现有参与,再判断是否需要切换;这次 `join` 是断线恢复,不是切换,不需要先征求退出确认。
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
|
|
7
7
|
## 赛前(设置)
|
|
8
8
|
|
|
9
|
+
云端编辑第三方 A 得到自己的 B 时,`load` 可返回 `changes.cloud_sync.fork_replacements`(含 A/B 资源 ID、操作名和内容决议)。B 若有冲突,使用 B 的完整操作名执行 `ccl capability resolve <type/id> --use local|cloud|later`;local 更新 B 的新版本,cloud 先存本地草稿,later 继续本地且不上传。取消再重新装配不能清掉未解决冲突。`FORK_RECONCILIATION_SKIPPED` 明确说明无法自动衔接的原因;A/B 文件均保留,不把来源不明的副本自动上传。
|
|
10
|
+
|
|
9
11
|
策略、感知和人设的命令参数使用 CCL 返回的本地操作名,如 `xx`、`xx_1`;不同资源同名时均可存在,名称按账号持久保存,取消装配或更新版本不重新编号。`behavior list/info` 和 `perception --list` 返回 `declared_id`、`working_copy_path`、`runtime_source_path`;`persona list` 返回操作名、原名、路径和可用的 Hub 身份。后缀不写入原脚本或 Hub。辅助 Skill 的重名规则本轮不变。
|
|
10
12
|
|
|
11
13
|
```bash
|
package/src/commands/behavior.ts
CHANGED
|
@@ -131,6 +131,7 @@ function sourceEntry(
|
|
|
131
131
|
managed_by: source.management.managedBy,
|
|
132
132
|
...(source.management.publisher ? { publisher: source.management.publisher } : {}),
|
|
133
133
|
...(source.management.resourceId ? { resource_id: source.management.resourceId } : {}),
|
|
134
|
+
...(source.management.forkedFromResourceId ? { forked_from_resource_id: source.management.forkedFromResourceId } : {}),
|
|
134
135
|
...(source.management.versionId ? { version_id: source.management.versionId } : {}),
|
|
135
136
|
...(source.management.versionNumber ? { version_number: source.management.versionNumber,
|
|
136
137
|
version_description: source.management.versionDescription ?? '' } : {}),
|
|
@@ -343,6 +343,7 @@ export function createCapabilityCommand(dependencies: CapabilityCommandDependenc
|
|
|
343
343
|
lastUploadedSha256: digest,
|
|
344
344
|
observedCloudVersionId: undefined,
|
|
345
345
|
localOriginUnrecognized: undefined,
|
|
346
|
+
pendingForkConflict: undefined,
|
|
346
347
|
});
|
|
347
348
|
setCapabilityConflictChoice(workspaceDir, profile, entry.key, undefined);
|
|
348
349
|
console.log(JSON.stringify({
|
package/src/commands/data.ts
CHANGED
|
@@ -89,6 +89,7 @@ export function createDataCommand(dependencies: DataCommandDependencies = {}): C
|
|
|
89
89
|
segment_ids: result.segmentIds,
|
|
90
90
|
row_counts: result.rowCounts,
|
|
91
91
|
diagnostic_count: result.diagnosticCount,
|
|
92
|
+
detail_capture_count: result.detailCaptureCount ?? 0,
|
|
92
93
|
raw_ws_frame_count: result.rawWsFrameCount,
|
|
93
94
|
}, null, 2));
|
|
94
95
|
});
|
package/src/commands/load.ts
CHANGED
|
@@ -60,6 +60,7 @@ import {
|
|
|
60
60
|
pendingCapabilitySelections,
|
|
61
61
|
registerDiscoveredCapability,
|
|
62
62
|
capabilityEntryForPath,
|
|
63
|
+
capabilityEntryForHubResource,
|
|
63
64
|
} from '../lib/capability-workspace.js';
|
|
64
65
|
import { syncCapabilitiesToCloud } from '../lib/capability-cloud-sync.js';
|
|
65
66
|
import {
|
|
@@ -283,7 +284,9 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
|
|
|
283
284
|
let workspaceSyncStatus: 'updated' | 'unchanged' | 'local_overrides' | 'stale_fallback' | 'unavailable';
|
|
284
285
|
let workspaceSyncError: string | undefined;
|
|
285
286
|
try {
|
|
286
|
-
workspaceResult = await (dependencies.workspaceSync ?? syncAgentWorkspaceConfig)(workspaceDir, profile
|
|
287
|
+
workspaceResult = await (dependencies.workspaceSync ?? syncAgentWorkspaceConfig)(workspaceDir, profile, {
|
|
288
|
+
workspaceInventory: cloudWorkspaceUpdates.inventoryComplete ? cloudWorkspaceUpdates.inventory : undefined,
|
|
289
|
+
});
|
|
287
290
|
activeWorkspace = workspaceResult.snapshot;
|
|
288
291
|
workspaceSyncStatus = workspaceResult.status;
|
|
289
292
|
} catch (error) {
|
|
@@ -312,6 +315,9 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
|
|
|
312
315
|
activeWorkspace,
|
|
313
316
|
);
|
|
314
317
|
|
|
318
|
+
const newForkReplacements = activeWorkspace ? Object.values(activeWorkspace.items).flat().filter(item =>
|
|
319
|
+
workspaceResult?.forkReplacements?.includes(item.resourceId)) : [];
|
|
320
|
+
|
|
315
321
|
let firstSkillChanges: ReturnType<typeof syncAgentWorkspaceSkills> | undefined;
|
|
316
322
|
const renderFinalContext = async (completedSync?: Awaited<ReturnType<typeof syncCapabilitiesToCloud>>): Promise<void> => {
|
|
317
323
|
let snapshot;
|
|
@@ -464,6 +470,15 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
|
|
|
464
470
|
capabilityWarnings.push(compatibilityWarning('behavior', 'local', source, reason));
|
|
465
471
|
}
|
|
466
472
|
const configurationWarnings: Array<Record<string, unknown>> = [];
|
|
473
|
+
for (const item of Object.values(activeWorkspace?.items ?? {}).flat()) {
|
|
474
|
+
const relation = item.forkReconciliation;
|
|
475
|
+
if (relation?.status !== 'unresolved') continue;
|
|
476
|
+
configurationWarnings.push({ code: 'FORK_RECONCILIATION_SKIPPED',
|
|
477
|
+
resource_id: item.resourceId, forked_from_resource_id: relation.parentResourceId,
|
|
478
|
+
reason: relation.reason,
|
|
479
|
+
message: 'Fork relationship was not automatically merged. Original local files are preserved; review the resource relationship before synchronizing edits.',
|
|
480
|
+
});
|
|
481
|
+
}
|
|
467
482
|
if (workspaceSyncError) configurationWarnings.push({
|
|
468
483
|
code: 'WORKSPACE_SYNC_FAILED', message: workspaceSyncError,
|
|
469
484
|
using_previous_snapshot: !!activeWorkspace,
|
|
@@ -737,7 +752,9 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
|
|
|
737
752
|
firstSkillChanges = skillChanges;
|
|
738
753
|
try {
|
|
739
754
|
const updatedInventory = await (dependencies.cloudWorkspaceUpdates ?? syncInstalledCapabilityUpdates)(profile);
|
|
740
|
-
workspaceResult = await (dependencies.workspaceSync ?? syncAgentWorkspaceConfig)(workspaceDir, profile
|
|
755
|
+
workspaceResult = await (dependencies.workspaceSync ?? syncAgentWorkspaceConfig)(workspaceDir, profile, {
|
|
756
|
+
workspaceInventory: updatedInventory.inventoryComplete ? updatedInventory.inventory : undefined,
|
|
757
|
+
});
|
|
741
758
|
activeWorkspace = workspaceResult.snapshot;
|
|
742
759
|
workspaceSyncStatus = workspaceResult.status;
|
|
743
760
|
if (updatedInventory.inventoryComplete) {
|
|
@@ -820,6 +837,16 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
|
|
|
820
837
|
&& candidate.resource_id === value.resource_id
|
|
821
838
|
)) === index);
|
|
822
839
|
const cloudFailures = [...cloudRefreshChanges.failed, ...(cloudChanges?.failed ?? [])];
|
|
840
|
+
const forkReplacements = newForkReplacements.map(item => {
|
|
841
|
+
const type = item.resourceType === 'strategy' ? 'behavior' : item.resourceType;
|
|
842
|
+
const entry = capabilityEntryForHubResource(workspaceDir, profile, type, item.resourceId);
|
|
843
|
+
const finalItem = Object.values(activeWorkspace?.items ?? {}).flat().find(current => current.resourceId === item.resourceId);
|
|
844
|
+
return { type, id: entry?.runtimeId, resource_id: item.resourceId,
|
|
845
|
+
forked_from_resource_id: item.forkReconciliation!.parentResourceId,
|
|
846
|
+
from_id: item.forkReconciliation!.parentOperationName,
|
|
847
|
+
resolution: finalItem?.resolution ?? item.resolution,
|
|
848
|
+
};
|
|
849
|
+
});
|
|
823
850
|
const workspaceVersionUpdates = mergeWorkspaceVersionUpdates(
|
|
824
851
|
cloudWorkspaceUpdates.updated,
|
|
825
852
|
inferredWorkspaceVersionUpdates(activeWorkspace, workspaceResult?.previous),
|
|
@@ -834,6 +861,7 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
|
|
|
834
861
|
|| cloudFailures.length > 0
|
|
835
862
|
|| cloudPresence.deactivated.length > 0
|
|
836
863
|
|| cloudPresence.restored.length > 0
|
|
864
|
+
|| forkReplacements.length > 0
|
|
837
865
|
) ? {
|
|
838
866
|
workspace_updated: workspaceVersionUpdates,
|
|
839
867
|
workspace_update_failed: cloudWorkspaceUpdates.failed,
|
|
@@ -844,6 +872,7 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
|
|
|
844
872
|
failed: cloudFailures,
|
|
845
873
|
deactivated: cloudPresence.deactivated,
|
|
846
874
|
restored: cloudPresence.restored,
|
|
875
|
+
...(forkReplacements.length ? { fork_replacements: forkReplacements } : {}),
|
|
847
876
|
unchanged: cloudChanges?.unchanged ?? [],
|
|
848
877
|
} : undefined;
|
|
849
878
|
const selectionRequired = pendingCapabilitySelections(workspaceDir, profile);
|
|
@@ -16,6 +16,7 @@ export interface AgentWorkspaceRemoteFile {
|
|
|
16
16
|
export interface AgentWorkspaceRemoteItem {
|
|
17
17
|
workspace_item_id: string;
|
|
18
18
|
resource_id: string;
|
|
19
|
+
forked_from_resource_id?: string | null;
|
|
19
20
|
version_id: string;
|
|
20
21
|
version_number?: string;
|
|
21
22
|
version_description?: string;
|
|
@@ -47,6 +47,7 @@ export interface AgentWorkspaceBehaviorManagement {
|
|
|
47
47
|
publisher?: 'official' | 'self' | 'community';
|
|
48
48
|
workspaceItemId?: string;
|
|
49
49
|
resourceId?: string;
|
|
50
|
+
forkedFromResourceId?: string;
|
|
50
51
|
versionId?: string;
|
|
51
52
|
versionNumber?: string;
|
|
52
53
|
versionDescription?: string;
|
|
@@ -97,6 +98,7 @@ export function listAgentWorkspaceBehaviorSources(
|
|
|
97
98
|
...(item.hub?.publisher ? { publisher: item.hub.publisher } : {}),
|
|
98
99
|
workspaceItemId: item.workspaceItemId,
|
|
99
100
|
resourceId: item.resourceId,
|
|
101
|
+
forkedFromResourceId: item.forkedFromResourceId,
|
|
100
102
|
versionId: item.versionId,
|
|
101
103
|
versionNumber: item.versionNumber,
|
|
102
104
|
versionDescription: item.versionDescription,
|
|
@@ -113,6 +115,8 @@ export function listAgentWorkspaceBehaviorSources(
|
|
|
113
115
|
title: source.name, description: source.description, selectedByHub: true,
|
|
114
116
|
hub: { resourceId: item.resourceId, versionId: item.versionId,
|
|
115
117
|
workspaceItemId: item.workspaceItemId, publisher: item.hub?.publisher ?? 'community',
|
|
118
|
+
pendingForkConflict: item.forkReconciliation?.status === 'linked' && item.resolution === 'concurrent_difference' || undefined,
|
|
119
|
+
...(item.forkReconciliation?.status === 'unresolved' ? { forkRelationshipUnresolved: true } : {}),
|
|
116
120
|
baseSha256: item.sourceFiles[0]?.sha256 },
|
|
117
121
|
});
|
|
118
122
|
return behaviorOperationName({ ...managed, workingCopyPath }, entry);
|
|
@@ -143,6 +147,8 @@ export function listAgentWorkspacePerceptionSources(
|
|
|
143
147
|
type: 'perception', path: workingCopyPath, runtimeId: source.id, title: source.name,
|
|
144
148
|
description: source.description, selectedByHub: true,
|
|
145
149
|
hub: { resourceId: item.resourceId, versionId: item.versionId, workspaceItemId: item.workspaceItemId,
|
|
150
|
+
pendingForkConflict: item.forkReconciliation?.status === 'linked' && item.resolution === 'concurrent_difference' || undefined,
|
|
151
|
+
...(item.forkReconciliation?.status === 'unresolved' ? { forkRelationshipUnresolved: true } : {}),
|
|
146
152
|
publisher: item.hub?.publisher ?? 'community', baseSha256: item.sourceFiles[0]?.sha256 },
|
|
147
153
|
});
|
|
148
154
|
return perceptionOperationName({ ...source, workingCopyPath }, entry);
|
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
type AgentWorkspaceRemoteFile,
|
|
20
20
|
type AgentWorkspaceRemoteItem,
|
|
21
21
|
} from './agent-workspace-client.js';
|
|
22
|
-
import type { ResourceType } from './hub-client.js';
|
|
22
|
+
import type { ResourceType, WorkspaceResourceSummary } from './hub-client.js';
|
|
23
23
|
import { unzip } from './hub-unzip.js';
|
|
24
24
|
import {
|
|
25
25
|
getUserDataAgentWorkspaceCurrentFile,
|
|
@@ -33,6 +33,8 @@ import {
|
|
|
33
33
|
import {
|
|
34
34
|
capabilityEntryForHubResource,
|
|
35
35
|
capabilityWorkspacePath,
|
|
36
|
+
registerDiscoveredCapability,
|
|
37
|
+
updateCapabilityHubIdentity,
|
|
36
38
|
} from './capability-workspace.js';
|
|
37
39
|
import { inspectClawclawBehaviorSource, behaviorSourceCompatibilityError } from '../runtime/clawclaw/plugins/behavior/behavior-source.js';
|
|
38
40
|
import { listClawclawPerceptionSourcesInDirectory } from '../runtime/clawclaw/plugins/perception/perception-source.js';
|
|
@@ -54,6 +56,15 @@ export interface LocalAgentWorkspaceFile {
|
|
|
54
56
|
|
|
55
57
|
export interface LocalAgentWorkspaceItem {
|
|
56
58
|
workspaceItemId: string;
|
|
59
|
+
forkedFromResourceId?: string;
|
|
60
|
+
forkReconciliation?: {
|
|
61
|
+
parentResourceId: string;
|
|
62
|
+
parentVersionId?: string;
|
|
63
|
+
parentOperationName?: string;
|
|
64
|
+
status: 'linked' | 'unresolved';
|
|
65
|
+
reason?: 'multiple_forks' | 'parent_still_equipped' | 'baseline_unrecognized'
|
|
66
|
+
| 'parent_working_copy_missing' | 'target_working_copy_exists' | 'not_owned' | 'inventory_unavailable';
|
|
67
|
+
};
|
|
57
68
|
resourceId: string;
|
|
58
69
|
versionId: string;
|
|
59
70
|
versionNumber?: string;
|
|
@@ -108,12 +119,14 @@ export interface AgentWorkspaceSyncResult {
|
|
|
108
119
|
status: AgentWorkspaceSyncStatus;
|
|
109
120
|
snapshot: LocalAgentWorkspaceSnapshot;
|
|
110
121
|
previous?: LocalAgentWorkspaceSnapshot;
|
|
122
|
+
forkReplacements?: readonly string[];
|
|
111
123
|
}
|
|
112
124
|
|
|
113
125
|
export interface AgentWorkspaceSyncDependencies {
|
|
114
126
|
client?: AgentWorkspaceConfigReader;
|
|
115
127
|
download?: (url: string) => Promise<Buffer>;
|
|
116
128
|
now?: () => Date;
|
|
129
|
+
workspaceInventory?: readonly WorkspaceResourceSummary[];
|
|
117
130
|
}
|
|
118
131
|
|
|
119
132
|
function record(value: unknown): Record<string, unknown> | null {
|
|
@@ -170,6 +183,7 @@ function validateRemoteItem(item: AgentWorkspaceRemoteItem, expectedType: Resour
|
|
|
170
183
|
if (item.resource_type !== expectedType) throw new Error('agent_workspace_resource_type_mismatch');
|
|
171
184
|
safeSegment(item.workspace_item_id, 'workspace_item_id');
|
|
172
185
|
safeSegment(item.resource_id, 'resource_id');
|
|
186
|
+
if (item.forked_from_resource_id != null) safeSegment(item.forked_from_resource_id, 'forked_from_resource_id');
|
|
173
187
|
safeSegment(item.version_id, 'version_id');
|
|
174
188
|
if (
|
|
175
189
|
!['owned', 'installed'].includes(item.workspace_kind)
|
|
@@ -359,6 +373,7 @@ async function materializeItem(
|
|
|
359
373
|
return {
|
|
360
374
|
workspaceItemId: item.workspace_item_id,
|
|
361
375
|
resourceId: item.resource_id,
|
|
376
|
+
forkedFromResourceId: item.forked_from_resource_id ?? undefined,
|
|
362
377
|
versionId: item.version_id,
|
|
363
378
|
versionNumber: item.version_number,
|
|
364
379
|
versionDescription: item.version_description,
|
|
@@ -420,6 +435,7 @@ interface WorkingCopyMetadata {
|
|
|
420
435
|
resourceId: string;
|
|
421
436
|
relativePath: string;
|
|
422
437
|
knownVersions: NonNullable<LocalAgentWorkspaceItem['knownVersions']>;
|
|
438
|
+
forkReconciliation?: LocalAgentWorkspaceItem['forkReconciliation'];
|
|
423
439
|
}
|
|
424
440
|
|
|
425
441
|
function singleFileContentDigest(relativePath: string, bytes: Buffer): string {
|
|
@@ -691,7 +707,8 @@ export async function syncAgentWorkspaceConfig(
|
|
|
691
707
|
const items = previous.items[type];
|
|
692
708
|
return items.length === remote.items[type].length && remote.items[type].every(item =>
|
|
693
709
|
items.some(old => old.resourceId === item.resource_id && old.versionId === item.version_id
|
|
694
|
-
&& old.workspaceItemId === item.workspace_item_id && old.contentDigest === item.content_digest
|
|
710
|
+
&& old.workspaceItemId === item.workspace_item_id && old.contentDigest === item.content_digest
|
|
711
|
+
&& old.forkedFromResourceId === (item.forked_from_resource_id ?? undefined)));
|
|
695
712
|
});
|
|
696
713
|
if (
|
|
697
714
|
previous?.revision === remote.revision
|
|
@@ -716,12 +733,25 @@ export async function syncAgentWorkspaceConfig(
|
|
|
716
733
|
const items = emptyItems();
|
|
717
734
|
const workingUpdates: Array<{ path: string; bytes: Buffer }> = [];
|
|
718
735
|
const workingMetadataUpdates: Array<{ path: string; value: WorkingCopyMetadata }> = [];
|
|
736
|
+
const forkReplacements: string[] = [];
|
|
737
|
+
const forkRegistrations: Array<Parameters<typeof registerDiscoveredCapability>[2]> = [];
|
|
738
|
+
const unresolvedParentKeys = new Set<string>();
|
|
719
739
|
const previousByKey = new Map<ResourceType, Map<string, LocalAgentWorkspaceItem>>(
|
|
720
740
|
RESOURCE_TYPES.map((type) => [
|
|
721
741
|
type,
|
|
722
742
|
new Map((previous?.items[type] ?? []).map((item) => [item.resourceId, item])),
|
|
723
743
|
]),
|
|
724
744
|
);
|
|
745
|
+
const selectedResourceIds = new Set(Object.values(remote.items).flat().map(item => item.resource_id));
|
|
746
|
+
const forkChildren = new Map<string, Set<string>>();
|
|
747
|
+
const addChild = (parent: string | null | undefined, child: string): void => {
|
|
748
|
+
if (!parent) return;
|
|
749
|
+
const children = forkChildren.get(parent) ?? new Set<string>();
|
|
750
|
+
children.add(child);
|
|
751
|
+
forkChildren.set(parent, children);
|
|
752
|
+
};
|
|
753
|
+
for (const item of Object.values(remote.items).flat()) addChild(item.forked_from_resource_id, item.resource_id);
|
|
754
|
+
for (const item of dependencies.workspaceInventory ?? []) addChild(item.forkedFromResourceId, item.resourceId);
|
|
725
755
|
for (const type of RESOURCE_TYPES) {
|
|
726
756
|
for (const item of remote.items[type]) {
|
|
727
757
|
let materialized: LocalAgentWorkspaceItem;
|
|
@@ -733,6 +763,8 @@ export async function syncAgentWorkspaceConfig(
|
|
|
733
763
|
const prior = previousByKey.get(type)?.get(materialized.resourceId);
|
|
734
764
|
let workingPath: string | undefined;
|
|
735
765
|
let persistedWorkingMetadata: WorkingCopyMetadata | undefined;
|
|
766
|
+
let targetAlreadyRegistered = false;
|
|
767
|
+
let pendingForkConflict = false;
|
|
736
768
|
if (type !== 'skill' && materialized.sourceFiles[0]) {
|
|
737
769
|
const workspaceType = type === 'strategy' ? 'behavior' : type;
|
|
738
770
|
const registered = capabilityEntryForHubResource(
|
|
@@ -741,6 +773,8 @@ export async function syncAgentWorkspaceConfig(
|
|
|
741
773
|
workspaceType,
|
|
742
774
|
materialized.resourceId,
|
|
743
775
|
);
|
|
776
|
+
targetAlreadyRegistered = registered !== undefined;
|
|
777
|
+
pendingForkConflict = registered?.hub?.pendingForkConflict === true;
|
|
744
778
|
workingPath = registered
|
|
745
779
|
? capabilityWorkspacePath(workspaceDir, profile, registered)
|
|
746
780
|
: hubWorkingCopyPath(
|
|
@@ -765,7 +799,51 @@ export async function syncAgentWorkspaceConfig(
|
|
|
765
799
|
...(persistedWorkingMetadata?.knownVersions ?? []),
|
|
766
800
|
...knownVersions(materialized),
|
|
767
801
|
].map((entry) => [entry.versionId, entry])).values()];
|
|
802
|
+
materialized.forkReconciliation = prior?.forkReconciliation ?? persistedWorkingMetadata?.forkReconciliation;
|
|
768
803
|
let override = inspected?.overrides.get(`${type}:${materialized.resourceId}`);
|
|
804
|
+
let forkCloudChanged: boolean | undefined;
|
|
805
|
+
// Only bridge a newly received, owned, direct replacement. Keep A's
|
|
806
|
+
// file and operation name intact; B gets a separate working copy/name.
|
|
807
|
+
const parentId = materialized.forkedFromResourceId;
|
|
808
|
+
const parent = parentId ? previousByKey.get(type)?.get(parentId) : undefined;
|
|
809
|
+
if (type !== 'skill' && parent && !prior && !targetAlreadyRegistered && !materialized.forkReconciliation) {
|
|
810
|
+
if (!dependencies.workspaceInventory) {
|
|
811
|
+
throw new Error(`agent_workspace_resource_failed:${type}:${item.resource_id}:fork_inventory_unavailable`);
|
|
812
|
+
}
|
|
813
|
+
const workspaceType = type === 'strategy' ? 'behavior' : type;
|
|
814
|
+
const parentEntry = capabilityEntryForHubResource(workspaceDir, profile, workspaceType, parent.resourceId);
|
|
815
|
+
const relation: NonNullable<LocalAgentWorkspaceItem['forkReconciliation']> = {
|
|
816
|
+
parentResourceId: parent.resourceId, parentVersionId: parent.versionId,
|
|
817
|
+
parentOperationName: parentEntry?.runtimeId, status: 'unresolved',
|
|
818
|
+
};
|
|
819
|
+
const parentPath = resolveLocalAgentWorkspaceWorkingCopyPath(workspaceDir, profile, parent);
|
|
820
|
+
const baseline = parent.sourceFiles[0]?.sha256;
|
|
821
|
+
if (!item.is_created_by_me || item.workspace_kind !== 'owned') relation.reason = 'not_owned';
|
|
822
|
+
else if (selectedResourceIds.has(parent.resourceId)) relation.reason = 'parent_still_equipped';
|
|
823
|
+
else if (forkChildren.get(parent.resourceId)?.size !== 1) relation.reason = 'multiple_forks';
|
|
824
|
+
else if (!baseline || parent.resolution === 'local_origin_unrecognized' || parentEntry?.hub?.localOriginUnrecognized) {
|
|
825
|
+
relation.reason = 'baseline_unrecognized';
|
|
826
|
+
} else if (!parentPath || !existsSync(parentPath)) relation.reason = 'parent_working_copy_missing';
|
|
827
|
+
else if (workingPath && existsSync(workingPath)) relation.reason = 'target_working_copy_exists';
|
|
828
|
+
else {
|
|
829
|
+
const bytes = readFileSync(parentPath);
|
|
830
|
+
const digest = sha256(bytes);
|
|
831
|
+
relation.status = 'linked';
|
|
832
|
+
forkReplacements.push(item.resource_id);
|
|
833
|
+
const localChanged = digest !== baseline && !knownVersions(parent).some(version => version.sourceSha256 === digest);
|
|
834
|
+
if (localChanged && digest !== materialized.sourceFiles[0]?.sha256) {
|
|
835
|
+
override = {
|
|
836
|
+
bytes, sha256: digest,
|
|
837
|
+
contentDigest: singleFileContentDigest(materialized.sourceFiles[0]!.relativePath, bytes),
|
|
838
|
+
modifiedAtMs: statSync(parentPath).mtimeMs, originRecognized: true,
|
|
839
|
+
};
|
|
840
|
+
forkCloudChanged = baseline !== materialized.sourceFiles[0]?.sha256
|
|
841
|
+
|| parent.resolution === 'concurrent_difference' || parentEntry?.hub?.pendingForkConflict === true;
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
materialized.forkReconciliation = relation;
|
|
845
|
+
if (relation.status === 'unresolved' && parentEntry) unresolvedParentKeys.add(parentEntry.key);
|
|
846
|
+
}
|
|
769
847
|
if (!override && !prior && workingPath && existsSync(workingPath)) {
|
|
770
848
|
const bytes = readFileSync(workingPath);
|
|
771
849
|
const localSha = sha256(bytes);
|
|
@@ -794,15 +872,15 @@ export async function syncAgentWorkspaceConfig(
|
|
|
794
872
|
);
|
|
795
873
|
writeFileSync(runtimePath, override.bytes);
|
|
796
874
|
effectiveBytes = override.bytes;
|
|
797
|
-
const remoteAdvancedFromLocalBaseline = prior
|
|
875
|
+
const remoteAdvancedFromLocalBaseline = forkCloudChanged ?? (prior
|
|
798
876
|
? prior.versionId !== materialized.versionId
|
|
799
877
|
: persistedWorkingMetadata !== undefined
|
|
800
878
|
&& !persistedWorkingMetadata.knownVersions.some(
|
|
801
879
|
(entry) => entry.versionId === materialized.versionId,
|
|
802
|
-
);
|
|
880
|
+
));
|
|
803
881
|
materialized.resolution = !override.originRecognized
|
|
804
882
|
? 'local_origin_unrecognized'
|
|
805
|
-
: remoteAdvancedFromLocalBaseline || prior?.resolution === 'concurrent_difference'
|
|
883
|
+
: remoteAdvancedFromLocalBaseline || prior?.resolution === 'concurrent_difference' || pendingForkConflict
|
|
806
884
|
? 'concurrent_difference'
|
|
807
885
|
: 'local_modified';
|
|
808
886
|
materialized.localContentDigest = override.contentDigest;
|
|
@@ -854,8 +932,29 @@ export async function syncAgentWorkspaceConfig(
|
|
|
854
932
|
resourceId: materialized.resourceId,
|
|
855
933
|
relativePath: materialized.sourceFiles[0]!.relativePath,
|
|
856
934
|
knownVersions: materialized.knownVersions,
|
|
935
|
+
forkReconciliation: materialized.forkReconciliation,
|
|
857
936
|
},
|
|
858
937
|
});
|
|
938
|
+
if (materialized.forkReconciliation?.status === 'linked' && forkReplacements.includes(item.resource_id)) {
|
|
939
|
+
const workspaceType = type === 'strategy' ? 'behavior' : type as 'persona' | 'perception';
|
|
940
|
+
const stagedPath = join(temporary, materialized.runtimeEntryPath!);
|
|
941
|
+
const source = type === 'strategy' ? inspectClawclawBehaviorSource(stagedPath, dirname(stagedPath))
|
|
942
|
+
: type === 'perception' ? listClawclawPerceptionSourcesInDirectory(dirname(stagedPath))
|
|
943
|
+
.find(source => source.sourcePath === stagedPath) : undefined;
|
|
944
|
+
const parentEntry = capabilityEntryForHubResource(workspaceDir, profile, workspaceType,
|
|
945
|
+
materialized.forkReconciliation.parentResourceId);
|
|
946
|
+
const runtimeId = source?.id ?? (type === 'persona'
|
|
947
|
+
? materialized.sourceFiles[0]!.relativePath.replace(/\.md$/i, '')
|
|
948
|
+
: parentEntry?.declaredId ?? parentEntry?.runtimeId);
|
|
949
|
+
if (runtimeId) forkRegistrations.push({
|
|
950
|
+
type: workspaceType, path: workingPath!, runtimeId,
|
|
951
|
+
title: source?.name ?? parentEntry?.title, description: source?.description ?? parentEntry?.description,
|
|
952
|
+
selectedByHub: true,
|
|
953
|
+
hub: { resourceId: item.resource_id, versionId: item.version_id, workspaceItemId: item.workspace_item_id,
|
|
954
|
+
publisher: 'self', baseSha256: materialized.sourceFiles[0]!.sha256,
|
|
955
|
+
pendingForkConflict: materialized.resolution === 'concurrent_difference' || undefined },
|
|
956
|
+
});
|
|
957
|
+
}
|
|
859
958
|
}
|
|
860
959
|
items[type].push(materialized);
|
|
861
960
|
}
|
|
@@ -877,7 +976,19 @@ export async function syncAgentWorkspaceConfig(
|
|
|
877
976
|
const target = join(revisionsDir, relativeDir);
|
|
878
977
|
renameSync(temporary, target);
|
|
879
978
|
writeCurrentPointer(workspaceDir, profile, { revision: remote.revision, relative_dir: relativeDir });
|
|
880
|
-
|
|
979
|
+
for (const registration of forkRegistrations) registerDiscoveredCapability(workspaceDir, profile, registration);
|
|
980
|
+
for (const key of unresolvedParentKeys) {
|
|
981
|
+
const parent = Object.values(previous?.items ?? {}).flat().find(item => {
|
|
982
|
+
const type = item.resourceType === 'strategy' ? 'behavior' : item.resourceType;
|
|
983
|
+
return capabilityEntryForHubResource(workspaceDir, profile, type, item.resourceId)?.key === key;
|
|
984
|
+
});
|
|
985
|
+
if (!parent) continue;
|
|
986
|
+
const type = parent.resourceType === 'strategy' ? 'behavior' : parent.resourceType;
|
|
987
|
+
const entry = capabilityEntryForHubResource(workspaceDir, profile, type, parent.resourceId)!;
|
|
988
|
+
updateCapabilityHubIdentity(workspaceDir, profile, key, { ...entry.hub!, forkRelationshipUnresolved: true });
|
|
989
|
+
}
|
|
990
|
+
return { status: 'updated', snapshot, ...(previous ? { previous } : {}),
|
|
991
|
+
...(forkReplacements.length ? { forkReplacements } : {}) };
|
|
881
992
|
} catch (error) {
|
|
882
993
|
rmSync(temporary, { recursive: true, force: true });
|
|
883
994
|
throw error;
|
|
@@ -233,12 +233,16 @@ export async function refreshCapabilitiesFromCloud(
|
|
|
233
233
|
const client = dependencies.client ?? HubClient.fromProfile(profile);
|
|
234
234
|
const result: CapabilityCloudRefreshResult = { downloaded: [], conflicts: [], failed: [], unchanged: [] };
|
|
235
235
|
const active = activeResourceIds(activeWorkspace);
|
|
236
|
+
const unresolvedParents = new Set(Object.values(activeWorkspace?.items ?? {}).flat().flatMap(item =>
|
|
237
|
+
item.forkReconciliation?.status === 'unresolved' ? [item.forkReconciliation.parentResourceId] : []));
|
|
236
238
|
const entries = Object.values(readCapabilityWorkspaceRegistry(workspaceDir, profile).entries)
|
|
237
239
|
.filter((entry) => (
|
|
238
240
|
entry.runtimeId !== 'clawclaw'
|
|
239
241
|
&& entry.hub
|
|
240
242
|
&& !entry.hub.cloudStatus
|
|
243
|
+
&& !entry.hub.forkRelationshipUnresolved
|
|
241
244
|
&& !active.has(entry.hub.resourceId)
|
|
245
|
+
&& !unresolvedParents.has(entry.hub.resourceId)
|
|
242
246
|
));
|
|
243
247
|
for (const entry of entries) {
|
|
244
248
|
const hub = entry.hub!;
|
|
@@ -257,12 +261,14 @@ export async function refreshCapabilitiesFromCloud(
|
|
|
257
261
|
if (detail.versionId === hub.versionId) {
|
|
258
262
|
if (
|
|
259
263
|
hub.observedCloudVersionId
|
|
264
|
+
|| (hub.pendingForkConflict && before === hub.baseSha256)
|
|
260
265
|
|| (hub.localOriginUnrecognized && (
|
|
261
266
|
before === hub.baseSha256 || before === hub.lastUploadedSha256
|
|
262
267
|
))
|
|
263
268
|
) updateCapabilityHubIdentity(workspaceDir, profile, entry.key, {
|
|
264
269
|
...hub,
|
|
265
270
|
observedCloudVersionId: undefined,
|
|
271
|
+
pendingForkConflict: before === hub.baseSha256 ? undefined : hub.pendingForkConflict,
|
|
266
272
|
localOriginUnrecognized: before === hub.baseSha256 || before === hub.lastUploadedSha256
|
|
267
273
|
? undefined
|
|
268
274
|
: hub.localOriginUnrecognized,
|
|
@@ -311,6 +317,7 @@ export async function refreshCapabilitiesFromCloud(
|
|
|
311
317
|
lastUploadedSha256: artifact.digest,
|
|
312
318
|
observedCloudVersionId: undefined,
|
|
313
319
|
localOriginUnrecognized: undefined,
|
|
320
|
+
pendingForkConflict: undefined,
|
|
314
321
|
});
|
|
315
322
|
result.downloaded.push({
|
|
316
323
|
type: entry.type,
|
|
@@ -60,7 +60,7 @@ export interface CapabilityCloudSyncFailure {
|
|
|
60
60
|
export interface CapabilityCloudSyncSkip {
|
|
61
61
|
type: CapabilityWorkspaceType;
|
|
62
62
|
id: string;
|
|
63
|
-
reason: 'local_origin_unrecognized';
|
|
63
|
+
reason: 'local_origin_unrecognized' | 'fork_relationship_unresolved';
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
export interface CapabilityCloudSyncResult {
|
|
@@ -241,6 +241,9 @@ export async function syncCapabilitiesToCloud(
|
|
|
241
241
|
unchanged: [],
|
|
242
242
|
};
|
|
243
243
|
const selectedKeys = dependencies.entryKeys ? new Set(dependencies.entryKeys) : undefined;
|
|
244
|
+
const unresolvedForks = new Set(Object.values(snapshot.items).flat().flatMap(item =>
|
|
245
|
+
item.forkReconciliation?.status === 'unresolved'
|
|
246
|
+
? [item.resourceId, item.forkReconciliation.parentResourceId] : []));
|
|
244
247
|
const entries = Object.values(readCapabilityWorkspaceRegistry(workspaceDir, profile).entries)
|
|
245
248
|
.filter((entry) => (
|
|
246
249
|
entry.runtimeId !== 'clawclaw'
|
|
@@ -248,6 +251,10 @@ export async function syncCapabilitiesToCloud(
|
|
|
248
251
|
&& (!selectedKeys || selectedKeys.has(entry.key))
|
|
249
252
|
));
|
|
250
253
|
for (const entry of entries) {
|
|
254
|
+
if (entry.hub && (entry.hub.forkRelationshipUnresolved || unresolvedForks.has(entry.hub.resourceId))) {
|
|
255
|
+
result.skipped.push({ type: entry.type, id: entry.runtimeId, reason: 'fork_relationship_unresolved' });
|
|
256
|
+
continue;
|
|
257
|
+
}
|
|
251
258
|
if (entry.hub?.pendingEquipment !== undefined) {
|
|
252
259
|
// An old request must never replay over a newer Hub selection. The player
|
|
253
260
|
// can retry equip explicitly; load always consumes the latest cloud state.
|
|
@@ -305,8 +312,8 @@ export async function syncCapabilitiesToCloud(
|
|
|
305
312
|
continue;
|
|
306
313
|
}
|
|
307
314
|
if (
|
|
308
|
-
entry.hub?.observedCloudVersionId
|
|
309
|
-
&& entry.hub.observedCloudVersionId !== entry.hub.versionId
|
|
315
|
+
(entry.hub?.pendingForkConflict || (entry.hub?.observedCloudVersionId
|
|
316
|
+
&& entry.hub.observedCloudVersionId !== entry.hub.versionId))
|
|
310
317
|
&& entry.conflictChoice !== 'local'
|
|
311
318
|
) {
|
|
312
319
|
result.conflicts.push({
|
|
@@ -396,6 +403,7 @@ export async function syncCapabilitiesToCloud(
|
|
|
396
403
|
baseSha256: payload.digest,
|
|
397
404
|
lastUploadedSha256: payload.digest,
|
|
398
405
|
observedCloudVersionId: undefined,
|
|
406
|
+
pendingForkConflict: undefined,
|
|
399
407
|
...(action === 'fork' && entry.hub ? {
|
|
400
408
|
pendingBackpackRestoreResourceId: entry.hub.resourceId,
|
|
401
409
|
} : {}),
|
|
@@ -31,6 +31,9 @@ export interface CapabilityHubIdentity {
|
|
|
31
31
|
/** Retry a local equipment choice after the cloud resource itself was created successfully. */
|
|
32
32
|
pendingEquipment?: boolean;
|
|
33
33
|
observedCloudVersionId?: string;
|
|
34
|
+
/** Retain a bridged A→B conflict even while B is unequipped. */
|
|
35
|
+
pendingForkConflict?: boolean;
|
|
36
|
+
forkRelationshipUnresolved?: boolean;
|
|
34
37
|
/** The working copy existed before CCL had a trustworthy Hub baseline. */
|
|
35
38
|
localOriginUnrecognized?: boolean;
|
|
36
39
|
/** Cloud association is retained locally but automatic cloud I/O is suspended. */
|