@myclaw163/clawclaw-cli 0.10.8 → 0.10.9
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/README.md +6 -4
- package/docs/configuration.md +4 -7
- package/docs/custom-modules/README.md +1 -1
- package/docs/custom-modules/behavior.md +2 -2
- package/docs/custom-modules/perception.md +1 -1
- package/docs/custom-modules/skill.md +6 -5
- package/docs/runtime/README.md +1 -1
- package/docs/runtime/agent-notifications.md +1 -1
- package/docs/runtime/official-perception-modules.md +2 -2
- package/docs/user-guide/README.md +1 -1
- package/docs/user-guide/behavior.md +3 -2
- package/docs/user-guide/desktop-auth.md +1 -1
- package/docs/user-guide/installation.md +7 -6
- package/docs/user-guide/perception.md +1 -1
- package/docs/user-guide/skill.md +6 -5
- package/package.json +1 -1
- package/scripts/check-skill-command-surface.mjs +7 -2
- package/scripts/enable_ccl_permissions.cjs +4 -0
- package/skills/clawclaw/SKILL.md +23 -187
- package/skills/clawclaw/references/BEHAVIORS.md +7 -7
- package/skills/clawclaw/references/CHANNELS.md +1 -1
- package/skills/clawclaw/references/COMMANDS.md +20 -18
- package/skills/clawclaw/references/HUB.md +15 -15
- package/skills/clawclaw/references/STREAM.md +1 -1
- package/skills/clawclaw-creator/SKILL.md +27 -25
- package/skills/clawclaw-creator/references/CUSTOM-BEHAVIOR-DEVELOPMENT.md +9 -9
- package/skills/clawclaw-creator/references/CUSTOM-MODULE-API.md +5 -5
- package/skills/clawclaw-creator/references/CUSTOM-MODULES.md +14 -13
- package/skills/clawclaw-creator/references/CUSTOM-PERCEPTION-DEVELOPMENT.md +7 -7
- package/skills/clawclaw-creator/references/CUSTOM-PERSONA-DEVELOPMENT.md +6 -6
- package/skills/clawclaw-creator/references/CUSTOM-SKILL-DEVELOPMENT.md +11 -10
- package/skills/clawclaw-creator/references/SYNC-AND-REPORT.md +21 -19
- package/skills/clawclaw-start/SKILL.md +49 -0
- package/skills/clawclaw-start/references/STARTUP.md +176 -0
- package/src/cli.ts +2 -0
- package/src/commands/behavior.ts +1 -1
- package/src/commands/communication.ts +1 -1
- package/src/commands/hub.ts +2 -2
- package/src/commands/load.ts +30 -984
- package/src/commands/prepare.ts +1002 -0
- package/src/commands/skill.ts +1 -1
- package/src/lib/account-guidance.ts +5 -3
- package/src/lib/hub-errors.ts +2 -2
- package/src/lib/load-context.ts +11 -7
- package/src/lib/load-startup-context.ts +85 -0
- package/src/lib/load-startup.ts +47 -0
- package/src/lib/package-skills.ts +1 -1
- package/src/lib/skill-name-conflicts.ts +1 -1
- package/src/pipeline/event-hints.ts +2 -2
- package/src/runtime/auto-upgrade.ts +1 -1
- package/src/runtime/clawclaw/owner.ts +0 -7
- package/src/runtime/clawclaw/plugins/mailbox/adapters/game-sync-perception-report-adapter.ts +3 -3
- package/dist/strategy-worker/runtime/clawclaw/plugins/behavior/chunk-JMX6D6A3.js +0 -260
|
@@ -0,0 +1,1002 @@
|
|
|
1
|
+
import { isPackageManagedSkill } from '../lib/package-skills.js';
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import { readFileSync } from 'node:fs';
|
|
4
|
+
import { basename, extname, resolve } from 'node:path';
|
|
5
|
+
import { loadContext } from '../lib/load-context.js';
|
|
6
|
+
import { summarizeStartupBlockers } from '../lib/load-startup.js';
|
|
7
|
+
import { saveStartupContext } from '../lib/load-startup-context.js';
|
|
8
|
+
import { AuthStore } from '../lib/auth.js';
|
|
9
|
+
import { noAccountMessage } from '../lib/account-guidance.js';
|
|
10
|
+
import { runAutoUpgradeOnLoad } from '../runtime/auto-upgrade.js';
|
|
11
|
+
import {
|
|
12
|
+
CLAWCLAW_ROLE_IDS,
|
|
13
|
+
readGameplayConfig,
|
|
14
|
+
} from '../lib/gameplay-config.js';
|
|
15
|
+
import { getWorkspaceDir } from '../lib/init-command.js';
|
|
16
|
+
import {
|
|
17
|
+
ensureAccountUserDataLayout,
|
|
18
|
+
getUserDataAccountBehaviorsDir,
|
|
19
|
+
getUserDataAccountPerceptionsDir,
|
|
20
|
+
getUserDataAccountTriggersDir,
|
|
21
|
+
} from '../lib/user-data.js';
|
|
22
|
+
import {
|
|
23
|
+
behaviorSourceCompatibilityError,
|
|
24
|
+
} from '../runtime/clawclaw/plugins/behavior/behavior-source.js';
|
|
25
|
+
import { listClawclawTriggerSources } from '../runtime/clawclaw/plugins/trigger/trigger-source.js';
|
|
26
|
+
import { GameClient } from '../lib/game-client.js';
|
|
27
|
+
import {
|
|
28
|
+
GAME_STATUS_SCHEMA,
|
|
29
|
+
queryGameParticipationStatus,
|
|
30
|
+
type ParticipationStatusClient,
|
|
31
|
+
} from '../lib/participation-status.js';
|
|
32
|
+
import { BEHAVIOR_PLUGIN_API_VERSION } from '../sdk/behavior-plugin/index.js';
|
|
33
|
+
import { TRIGGER_PLUGIN_API_VERSION } from '../sdk/trigger-plugin/index.js';
|
|
34
|
+
import { PERCEPTION_PLUGIN_API_VERSION } from '../sdk/perception-plugin/index.js';
|
|
35
|
+
import { expectedPerceptionApiVersion, isSupportedPerceptionSource } from '../runtime/clawclaw/plugins/perception/perception-source.js';
|
|
36
|
+
import { resolveReactionBehavior } from '../runtime/clawclaw/reaction-behavior-resolution.js';
|
|
37
|
+
import { pluginApiVersionStatus } from '../runtime/clawclaw/plugins/plugin-api-version.js';
|
|
38
|
+
import {
|
|
39
|
+
readLocalAgentWorkspaceSnapshot,
|
|
40
|
+
resolveLocalAgentWorkspacePath,
|
|
41
|
+
resolveLocalAgentWorkspaceWorkingCopyPath,
|
|
42
|
+
resolveLocalAgentWorkspaceSnapshot,
|
|
43
|
+
syncAgentWorkspaceConfig,
|
|
44
|
+
type AgentWorkspaceSyncResult,
|
|
45
|
+
type LocalAgentWorkspaceSnapshot,
|
|
46
|
+
} from '../lib/agent-workspace-sync.js';
|
|
47
|
+
import { inspectSkillNameConflicts, syncAgentWorkspaceSkills } from '../lib/agent-workspace-skills.js';
|
|
48
|
+
import { skillConflictNames, skillNameKey } from '../lib/skill-name-conflicts.js';
|
|
49
|
+
import {
|
|
50
|
+
listAgentWorkspaceBehaviorSources,
|
|
51
|
+
listAgentWorkspacePerceptionSources,
|
|
52
|
+
mergeAgentWorkspaceBehaviorSources,
|
|
53
|
+
mergeAgentWorkspacePerceptionSources,
|
|
54
|
+
} from '../lib/agent-workspace-runtime.js';
|
|
55
|
+
import {
|
|
56
|
+
diagnoseRejectedCapabilityModule,
|
|
57
|
+
listCapabilityModuleCandidates,
|
|
58
|
+
warningFromStaticDiagnostic,
|
|
59
|
+
type CapabilityLoadWarning,
|
|
60
|
+
type ModuleCapabilityType,
|
|
61
|
+
} from '../lib/capability-load-diagnostics.js';
|
|
62
|
+
import { resolveClawclawResourceMetadata } from '../sdk/resource-metadata.js';
|
|
63
|
+
import { discoverLocalCapabilities } from '../lib/capability-discovery.js';
|
|
64
|
+
import {
|
|
65
|
+
capabilitySelectionRef,
|
|
66
|
+
capabilityWorkspacePath,
|
|
67
|
+
classifyStrategyLifecycle,
|
|
68
|
+
pendingCapabilitySelections,
|
|
69
|
+
readCapabilityWorkspaceRegistry,
|
|
70
|
+
registerDiscoveredCapability,
|
|
71
|
+
capabilityEntryForPath,
|
|
72
|
+
capabilityEntryForHubResource,
|
|
73
|
+
} from '../lib/capability-workspace.js';
|
|
74
|
+
import { syncCapabilitiesToCloud } from '../lib/capability-cloud-sync.js';
|
|
75
|
+
import {
|
|
76
|
+
refreshCapabilitiesFromCloud,
|
|
77
|
+
syncInstalledCapabilityUpdates,
|
|
78
|
+
} from '../lib/capability-cloud-refresh.js';
|
|
79
|
+
import {
|
|
80
|
+
filterInactiveAgentWorkspaceSnapshot,
|
|
81
|
+
reconcileCapabilityWorkspacePresence,
|
|
82
|
+
reconcileCapabilityLoadout,
|
|
83
|
+
type CapabilityPresenceResult,
|
|
84
|
+
} from '../lib/capability-cloud-presence.js';
|
|
85
|
+
|
|
86
|
+
const PREPARE_SCHEMA = 'ccl.prepare.v1';
|
|
87
|
+
const LOAD_DISPLAY_LOCALE = 'en-US';
|
|
88
|
+
|
|
89
|
+
export interface PrepareCommandDependencies {
|
|
90
|
+
clientFactory?: () => ParticipationStatusClient;
|
|
91
|
+
authStore?: AuthStore;
|
|
92
|
+
workspaceSync?: typeof syncAgentWorkspaceConfig;
|
|
93
|
+
skillSync?: typeof syncAgentWorkspaceSkills;
|
|
94
|
+
cloudWorkspaceUpdates?: typeof syncInstalledCapabilityUpdates;
|
|
95
|
+
cloudRefresh?: typeof refreshCapabilitiesFromCloud;
|
|
96
|
+
cloudSync?: typeof syncCapabilitiesToCloud;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
interface WorkspaceVersionUpdate {
|
|
100
|
+
type: string;
|
|
101
|
+
resource_id: string;
|
|
102
|
+
workspace_item_id: string;
|
|
103
|
+
version_id: string;
|
|
104
|
+
from_version?: string;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function inferredWorkspaceVersionUpdates(
|
|
108
|
+
current: LocalAgentWorkspaceSnapshot | undefined,
|
|
109
|
+
previous: LocalAgentWorkspaceSnapshot | undefined,
|
|
110
|
+
): WorkspaceVersionUpdate[] {
|
|
111
|
+
if (!current || !previous) return [];
|
|
112
|
+
const previousByResource = new Map(
|
|
113
|
+
Object.values(previous.items).flat().map((item) => [
|
|
114
|
+
`${item.resourceType}:${item.resourceId}`,
|
|
115
|
+
item,
|
|
116
|
+
]),
|
|
117
|
+
);
|
|
118
|
+
return Object.values(current.items).flat().flatMap((item) => {
|
|
119
|
+
const before = previousByResource.get(`${item.resourceType}:${item.resourceId}`);
|
|
120
|
+
if (
|
|
121
|
+
!before
|
|
122
|
+
|| before.versionId === item.versionId
|
|
123
|
+
|| (item.resolution !== 'hub' && item.resolution !== 'known_online_old')
|
|
124
|
+
) return [];
|
|
125
|
+
return [{
|
|
126
|
+
type: item.resourceType,
|
|
127
|
+
resource_id: item.resourceId,
|
|
128
|
+
workspace_item_id: item.workspaceItemId,
|
|
129
|
+
from_version: before.versionId,
|
|
130
|
+
version_id: item.versionId,
|
|
131
|
+
}];
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function mergeWorkspaceVersionUpdates(
|
|
136
|
+
reported: readonly WorkspaceVersionUpdate[],
|
|
137
|
+
inferred: readonly WorkspaceVersionUpdate[],
|
|
138
|
+
): WorkspaceVersionUpdate[] {
|
|
139
|
+
const merged = new Map<string, WorkspaceVersionUpdate>();
|
|
140
|
+
for (const item of inferred) merged.set(`${item.type}:${item.resource_id}`, { ...item });
|
|
141
|
+
for (const item of reported) {
|
|
142
|
+
const key = `${item.type}:${item.resource_id}`;
|
|
143
|
+
merged.set(key, { ...merged.get(key), ...item });
|
|
144
|
+
}
|
|
145
|
+
return [...merged.values()];
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function compatibilityWarning(
|
|
149
|
+
type: ModuleCapabilityType,
|
|
150
|
+
source: 'hub' | 'local',
|
|
151
|
+
value: {
|
|
152
|
+
readonly id: string;
|
|
153
|
+
readonly name: string;
|
|
154
|
+
readonly sourcePath: string;
|
|
155
|
+
readonly management?: {
|
|
156
|
+
readonly resourceId?: string;
|
|
157
|
+
readonly versionId?: string;
|
|
158
|
+
};
|
|
159
|
+
},
|
|
160
|
+
reason: string,
|
|
161
|
+
): CapabilityLoadWarning {
|
|
162
|
+
return {
|
|
163
|
+
code: 'CAPABILITY_NOT_LOADED',
|
|
164
|
+
capability_type: type,
|
|
165
|
+
source,
|
|
166
|
+
reason,
|
|
167
|
+
stage: 'static_discovery',
|
|
168
|
+
id: value.id,
|
|
169
|
+
name: value.name,
|
|
170
|
+
file: basename(value.sourcePath),
|
|
171
|
+
path: value.sourcePath,
|
|
172
|
+
...(value.management?.resourceId ? { resource_id: value.management.resourceId } : {}),
|
|
173
|
+
...(value.management?.versionId ? { version_id: value.management.versionId } : {}),
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function missingProjectionWarning(
|
|
178
|
+
type: ModuleCapabilityType,
|
|
179
|
+
item: {
|
|
180
|
+
readonly resourceId: string;
|
|
181
|
+
readonly versionId: string;
|
|
182
|
+
readonly sourceFiles: readonly Readonly<{ relativePath: string }>[];
|
|
183
|
+
},
|
|
184
|
+
): CapabilityLoadWarning {
|
|
185
|
+
return {
|
|
186
|
+
code: 'CAPABILITY_NOT_LOADED',
|
|
187
|
+
capability_type: type,
|
|
188
|
+
source: 'hub',
|
|
189
|
+
reason: 'projection_missing',
|
|
190
|
+
stage: 'projection',
|
|
191
|
+
resource_id: item.resourceId,
|
|
192
|
+
version_id: item.versionId,
|
|
193
|
+
file: item.sourceFiles[0]?.relativePath ?? item.resourceId,
|
|
194
|
+
path: null,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function compactCapabilityWarning(warning: CapabilityLoadWarning): Record<string, unknown> {
|
|
199
|
+
const keys = [
|
|
200
|
+
'code',
|
|
201
|
+
'capability_type',
|
|
202
|
+
'source',
|
|
203
|
+
'reason',
|
|
204
|
+
'stage',
|
|
205
|
+
'id',
|
|
206
|
+
'file',
|
|
207
|
+
'expected_import',
|
|
208
|
+
'received_imports',
|
|
209
|
+
] as const;
|
|
210
|
+
return Object.fromEntries(keys.flatMap((key) => (
|
|
211
|
+
warning[key] === undefined ? [] : [[key, warning[key]]]
|
|
212
|
+
)));
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function compactSkillChanges(changes: ReturnType<typeof syncAgentWorkspaceSkills>) {
|
|
216
|
+
const keys = ['added', 'updated', 'removed', 'preservedModified', 'failed', 'skipped', 'conflicts'] as const;
|
|
217
|
+
const value = Object.fromEntries(keys.flatMap((key) => (
|
|
218
|
+
!changes[key]?.length ? [] : [[key, changes[key]]]
|
|
219
|
+
)));
|
|
220
|
+
return Object.keys(value).length > 0 || changes.requiresUserConfirmation
|
|
221
|
+
? {
|
|
222
|
+
...value,
|
|
223
|
+
...(changes.requiresUserConfirmation ? { requires_user_confirmation: true } : {}),
|
|
224
|
+
}
|
|
225
|
+
: undefined;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function compactConfigurationWarnings(warnings: readonly Record<string, unknown>[]) {
|
|
229
|
+
return warnings.map((warning) => {
|
|
230
|
+
if (
|
|
231
|
+
warning.code !== 'DEFAULT_LONG_BEHAVIOR_UNAVAILABLE'
|
|
232
|
+
|| typeof warning.behavior_id !== 'string'
|
|
233
|
+
|| typeof warning.role !== 'string'
|
|
234
|
+
) {
|
|
235
|
+
return { ...warning };
|
|
236
|
+
}
|
|
237
|
+
return {
|
|
238
|
+
code: 'FALLBACK_BEHAVIOR_NOT_LOADED',
|
|
239
|
+
role: warning.role,
|
|
240
|
+
behavior_id: warning.behavior_id,
|
|
241
|
+
message: `Fallback Behavior ${warning.behavior_id} configured for role ${warning.role} is not loaded.`,
|
|
242
|
+
};
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function compactParticipation(value: object): Record<string, unknown> {
|
|
247
|
+
const { schema: _schema, ...participation } = value as Record<string, unknown>;
|
|
248
|
+
return participation;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export function createPrepareCommand(dependencies: PrepareCommandDependencies = {}): Command {
|
|
252
|
+
return new Command('prepare')
|
|
253
|
+
.description('Prepare gameplay resources, resolve startup blockers, and query participation')
|
|
254
|
+
.action(async () => {
|
|
255
|
+
runAutoUpgradeOnLoad({ notify: (message) => console.error(message) });
|
|
256
|
+
const workspaceDir = getWorkspaceDir();
|
|
257
|
+
const authStore = dependencies.authStore ?? new AuthStore();
|
|
258
|
+
const profile = authStore.getActive();
|
|
259
|
+
if (!profile) throw new Error(noAccountMessage('prepare'));
|
|
260
|
+
ensureAccountUserDataLayout(workspaceDir, profile);
|
|
261
|
+
|
|
262
|
+
let cloudWorkspaceUpdates = {
|
|
263
|
+
updated: [], failed: [], inventory: [], inventoryComplete: false,
|
|
264
|
+
} as Awaited<ReturnType<typeof syncInstalledCapabilityUpdates>>;
|
|
265
|
+
let inventoryReadFailed = false;
|
|
266
|
+
try {
|
|
267
|
+
cloudWorkspaceUpdates = await (
|
|
268
|
+
dependencies.cloudWorkspaceUpdates ?? syncInstalledCapabilityUpdates
|
|
269
|
+
)(profile);
|
|
270
|
+
} catch (error) {
|
|
271
|
+
inventoryReadFailed = true;
|
|
272
|
+
console.error(`[clawclaw-cli] Hub workspace update check unavailable: ${
|
|
273
|
+
error instanceof Error ? error.message : String(error)
|
|
274
|
+
}`);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
let workspaceResult: AgentWorkspaceSyncResult | undefined;
|
|
278
|
+
const storedWorkspace = readLocalAgentWorkspaceSnapshot(workspaceDir, profile);
|
|
279
|
+
let activeWorkspace = storedWorkspace
|
|
280
|
+
? resolveLocalAgentWorkspaceSnapshot(workspaceDir, profile, storedWorkspace)
|
|
281
|
+
: undefined;
|
|
282
|
+
let workspaceSyncStatus: 'updated' | 'unchanged' | 'local_overrides' | 'stale_fallback' | 'unavailable';
|
|
283
|
+
let workspaceSyncError: string | undefined;
|
|
284
|
+
try {
|
|
285
|
+
workspaceResult = await (dependencies.workspaceSync ?? syncAgentWorkspaceConfig)(workspaceDir, profile, {
|
|
286
|
+
workspaceInventory: cloudWorkspaceUpdates.inventoryComplete ? cloudWorkspaceUpdates.inventory : undefined,
|
|
287
|
+
});
|
|
288
|
+
activeWorkspace = workspaceResult.snapshot;
|
|
289
|
+
workspaceSyncStatus = workspaceResult.status;
|
|
290
|
+
} catch (error) {
|
|
291
|
+
workspaceSyncStatus = activeWorkspace ? 'stale_fallback' : 'unavailable';
|
|
292
|
+
workspaceSyncError = error instanceof Error ? error.message : String(error);
|
|
293
|
+
console.error(`[clawclaw-cli] Agent workspace sync unavailable: ${workspaceSyncError}`);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
let cloudPresence: CapabilityPresenceResult = cloudWorkspaceUpdates.inventoryComplete
|
|
297
|
+
? reconcileCapabilityWorkspacePresence(workspaceDir, profile, cloudWorkspaceUpdates.inventory, workspaceResult?.snapshot)
|
|
298
|
+
: workspaceResult?.snapshot
|
|
299
|
+
? reconcileCapabilityLoadout(workspaceDir, profile, workspaceResult.snapshot)
|
|
300
|
+
: { deactivated: [], restored: [], inactiveResourceIds: [] };
|
|
301
|
+
activeWorkspace = filterInactiveAgentWorkspaceSnapshot(
|
|
302
|
+
workspaceDir,
|
|
303
|
+
profile,
|
|
304
|
+
activeWorkspace,
|
|
305
|
+
cloudPresence.inactiveResourceIds,
|
|
306
|
+
);
|
|
307
|
+
|
|
308
|
+
const cloudRefreshChanges = inventoryReadFailed
|
|
309
|
+
? { downloaded: [], conflicts: [], failed: [], unchanged: [] }
|
|
310
|
+
: await (dependencies.cloudRefresh ?? refreshCapabilitiesFromCloud)(
|
|
311
|
+
workspaceDir,
|
|
312
|
+
profile,
|
|
313
|
+
activeWorkspace,
|
|
314
|
+
);
|
|
315
|
+
|
|
316
|
+
const newForkReplacements = activeWorkspace ? Object.values(activeWorkspace.items).flat().filter(item =>
|
|
317
|
+
workspaceResult?.forkReplacements?.includes(item.resourceId)) : [];
|
|
318
|
+
|
|
319
|
+
let firstSkillChanges: ReturnType<typeof syncAgentWorkspaceSkills> | undefined;
|
|
320
|
+
const renderFinalContext = async (completedSync?: Awaited<ReturnType<typeof syncCapabilitiesToCloud>>): Promise<void> => {
|
|
321
|
+
let snapshot;
|
|
322
|
+
try {
|
|
323
|
+
snapshot = loadContext(authStore, { includeContent: false });
|
|
324
|
+
} catch (error) {
|
|
325
|
+
if (error instanceof Error && error.message === 'Not logged in.') {
|
|
326
|
+
throw new Error(noAccountMessage('prepare'));
|
|
327
|
+
}
|
|
328
|
+
throw error;
|
|
329
|
+
}
|
|
330
|
+
if (
|
|
331
|
+
snapshot.persona.source === 'hub'
|
|
332
|
+
&& snapshot.persona.resource_id
|
|
333
|
+
&& cloudPresence.inactiveResourceIds.includes(snapshot.persona.resource_id)
|
|
334
|
+
) {
|
|
335
|
+
snapshot.persona = { path: null, exists: false, content: '', source: 'none' };
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
const gameplay = readGameplayConfig(workspaceDir, profile);
|
|
339
|
+
const discoveredLocal = discoverLocalCapabilities(workspaceDir, profile);
|
|
340
|
+
const capabilityWarnings: CapabilityLoadWarning[] = [];
|
|
341
|
+
const disabledBehaviors = new Set(gameplay.disabled_behaviors);
|
|
342
|
+
const hubBehaviors = activeWorkspace
|
|
343
|
+
? listAgentWorkspaceBehaviorSources(workspaceDir, profile, activeWorkspace)
|
|
344
|
+
: [];
|
|
345
|
+
if (activeWorkspace) {
|
|
346
|
+
for (const source of hubBehaviors) {
|
|
347
|
+
const item = activeWorkspace.items.strategy.find((candidate) => (
|
|
348
|
+
candidate.resourceId === source.management.resourceId
|
|
349
|
+
));
|
|
350
|
+
const workingPath = item
|
|
351
|
+
? resolveLocalAgentWorkspaceWorkingCopyPath(workspaceDir, profile, item)
|
|
352
|
+
: undefined;
|
|
353
|
+
if (!item || !workingPath) continue;
|
|
354
|
+
registerDiscoveredCapability(workspaceDir, profile, {
|
|
355
|
+
type: 'behavior',
|
|
356
|
+
path: workingPath,
|
|
357
|
+
runtimeId: source.declaredId ?? source.id,
|
|
358
|
+
title: source.name,
|
|
359
|
+
description: source.description,
|
|
360
|
+
strategyLifecycle: classifyStrategyLifecycle(readFileSync(workingPath, 'utf8')),
|
|
361
|
+
selectedByHub: true,
|
|
362
|
+
hub: {
|
|
363
|
+
resourceId: item.resourceId,
|
|
364
|
+
versionId: item.versionId,
|
|
365
|
+
workspaceItemId: item.workspaceItemId,
|
|
366
|
+
publisher: item.hub?.publisher ?? 'community',
|
|
367
|
+
baseSha256: item.sourceFiles[0]?.sha256,
|
|
368
|
+
localOriginUnrecognized: item.resolution === 'local_origin_unrecognized'
|
|
369
|
+
? true
|
|
370
|
+
: undefined,
|
|
371
|
+
},
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
const localBehaviorDir = getUserDataAccountBehaviorsDir(workspaceDir, profile);
|
|
376
|
+
const allLocalBehaviors = discoveredLocal.behaviors.map(({ source }) => source);
|
|
377
|
+
const localBehaviors = discoveredLocal.behaviors
|
|
378
|
+
.filter(({ source, entry }) => (
|
|
379
|
+
entry.selection === 'equipped' && !disabledBehaviors.has(source.id)
|
|
380
|
+
&& !activeWorkspace?.items.strategy.some(item => item.resourceId === entry.hub?.resourceId)
|
|
381
|
+
))
|
|
382
|
+
.map(({ source }) => source);
|
|
383
|
+
const localBehaviorSourcePaths = new Set(allLocalBehaviors.map(({ sourcePath }) => resolve(sourcePath)));
|
|
384
|
+
let expectedLocalBehaviors = localBehaviors.length;
|
|
385
|
+
for (const path of listCapabilityModuleCandidates(localBehaviorDir)) {
|
|
386
|
+
if (localBehaviorSourcePaths.has(resolve(path))) continue;
|
|
387
|
+
const diagnostic = diagnoseRejectedCapabilityModule('behavior', path);
|
|
388
|
+
const operationName = capabilityEntryForPath(workspaceDir, profile, 'behavior', path)?.runtimeId ?? diagnostic.declaredId;
|
|
389
|
+
if (operationName && disabledBehaviors.has(operationName)) continue;
|
|
390
|
+
expectedLocalBehaviors += 1;
|
|
391
|
+
capabilityWarnings.push({ ...warningFromStaticDiagnostic('behavior', 'local', diagnostic),
|
|
392
|
+
...(operationName ? { id: operationName } : {}) });
|
|
393
|
+
}
|
|
394
|
+
if (activeWorkspace) {
|
|
395
|
+
const discoveredPaths = new Set(hubBehaviors.map(({ sourcePath }) => resolve(sourcePath)));
|
|
396
|
+
for (const item of activeWorkspace.items.strategy) {
|
|
397
|
+
if (!item.runtimeEntryPath) {
|
|
398
|
+
capabilityWarnings.push(missingProjectionWarning('behavior', item));
|
|
399
|
+
continue;
|
|
400
|
+
}
|
|
401
|
+
const path = resolveLocalAgentWorkspacePath(
|
|
402
|
+
workspaceDir,
|
|
403
|
+
profile,
|
|
404
|
+
activeWorkspace,
|
|
405
|
+
item.runtimeEntryPath,
|
|
406
|
+
);
|
|
407
|
+
if (discoveredPaths.has(resolve(path))) continue;
|
|
408
|
+
capabilityWarnings.push(warningFromStaticDiagnostic(
|
|
409
|
+
'behavior',
|
|
410
|
+
'hub',
|
|
411
|
+
diagnoseRejectedCapabilityModule('behavior', path),
|
|
412
|
+
{ resourceId: item.resourceId, versionId: item.versionId },
|
|
413
|
+
));
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
const enabledBehaviors = mergeAgentWorkspaceBehaviorSources(
|
|
417
|
+
localBehaviors,
|
|
418
|
+
hubBehaviors,
|
|
419
|
+
disabledBehaviors,
|
|
420
|
+
);
|
|
421
|
+
const behaviorEntry = (source: typeof enabledBehaviors[number]) => {
|
|
422
|
+
const compatibilityError = behaviorSourceCompatibilityError(source);
|
|
423
|
+
const versionCompatible = source.apiVersion === BEHAVIOR_PLUGIN_API_VERSION;
|
|
424
|
+
const loadable = versionCompatible && compatibilityError === undefined;
|
|
425
|
+
return {
|
|
426
|
+
id: source.id,
|
|
427
|
+
name: source.name,
|
|
428
|
+
description: source.description,
|
|
429
|
+
api_version: source.apiVersion ?? null,
|
|
430
|
+
expected_api_version: BEHAVIOR_PLUGIN_API_VERSION,
|
|
431
|
+
loadable,
|
|
432
|
+
...(loadable ? {} : {
|
|
433
|
+
compatibility_error: versionCompatible
|
|
434
|
+
? compatibilityError
|
|
435
|
+
: `behavior_api_version_unsupported:expected=${BEHAVIOR_PLUGIN_API_VERSION}:received=${source.apiVersion ?? 'missing'}`,
|
|
436
|
+
}),
|
|
437
|
+
source: source.management.source,
|
|
438
|
+
managed_by: source.management.managedBy,
|
|
439
|
+
...(source.management.publisher ? { publisher: source.management.publisher } : {}),
|
|
440
|
+
...(source.management.resourceId ? { resource_id: source.management.resourceId } : {}),
|
|
441
|
+
...(source.management.versionId ? { version_id: source.management.versionId } : {}),
|
|
442
|
+
...(source.management.resolution ? { resolution: source.management.resolution } : {}),
|
|
443
|
+
};
|
|
444
|
+
};
|
|
445
|
+
const behaviorEntries = enabledBehaviors.map(behaviorEntry);
|
|
446
|
+
const behaviors = behaviorEntries.filter(({ loadable }) => loadable);
|
|
447
|
+
const incompatibleBehaviors = behaviorEntries.filter(({ loadable }) => !loadable);
|
|
448
|
+
for (const source of enabledBehaviors) {
|
|
449
|
+
const compatibilityError = behaviorSourceCompatibilityError(source);
|
|
450
|
+
const reason = source.apiVersion === BEHAVIOR_PLUGIN_API_VERSION
|
|
451
|
+
? compatibilityError
|
|
452
|
+
: `behavior_api_version_unsupported:expected=${BEHAVIOR_PLUGIN_API_VERSION}:received=${source.apiVersion ?? 'missing'}`;
|
|
453
|
+
if (!reason) continue;
|
|
454
|
+
capabilityWarnings.push(compatibilityWarning(
|
|
455
|
+
'behavior',
|
|
456
|
+
source.management.source,
|
|
457
|
+
source,
|
|
458
|
+
reason,
|
|
459
|
+
));
|
|
460
|
+
}
|
|
461
|
+
const selectedLocalBehaviorPaths = new Set(localBehaviors.map(({ sourcePath }) => resolve(sourcePath)));
|
|
462
|
+
for (const source of allLocalBehaviors) {
|
|
463
|
+
if (selectedLocalBehaviorPaths.has(resolve(source.sourcePath))) continue;
|
|
464
|
+
const compatibilityError = behaviorSourceCompatibilityError(source);
|
|
465
|
+
const reason = source.apiVersion === BEHAVIOR_PLUGIN_API_VERSION
|
|
466
|
+
? compatibilityError
|
|
467
|
+
: `behavior_api_version_unsupported:expected=${BEHAVIOR_PLUGIN_API_VERSION}:received=${source.apiVersion ?? 'missing'}`;
|
|
468
|
+
if (!reason) continue;
|
|
469
|
+
capabilityWarnings.push(compatibilityWarning('behavior', 'local', source, reason));
|
|
470
|
+
}
|
|
471
|
+
const configurationWarnings: Array<Record<string, unknown>> = [];
|
|
472
|
+
for (const item of Object.values(activeWorkspace?.items ?? {}).flat()) {
|
|
473
|
+
const relation = item.forkReconciliation;
|
|
474
|
+
if (relation?.status !== 'unresolved') continue;
|
|
475
|
+
configurationWarnings.push({ code: 'FORK_RECONCILIATION_SKIPPED',
|
|
476
|
+
resource_id: item.resourceId, forked_from_resource_id: relation.parentResourceId,
|
|
477
|
+
reason: relation.reason,
|
|
478
|
+
message: 'Fork relationship was not automatically merged. Original local files are preserved; review the resource relationship before synchronizing edits.',
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
if (workspaceSyncError) configurationWarnings.push({
|
|
482
|
+
code: 'WORKSPACE_SYNC_FAILED', message: workspaceSyncError,
|
|
483
|
+
using_previous_snapshot: !!activeWorkspace,
|
|
484
|
+
});
|
|
485
|
+
if (inventoryReadFailed) configurationWarnings.push({
|
|
486
|
+
code: 'WORKSPACE_INVENTORY_UNAVAILABLE',
|
|
487
|
+
message: 'Backpack could not be verified; automatic cloud writes and inactive-resource refresh were skipped.',
|
|
488
|
+
});
|
|
489
|
+
for (const role of CLAWCLAW_ROLE_IDS) {
|
|
490
|
+
const fallback = gameplay.fallback_behaviors[role];
|
|
491
|
+
if (fallback === null) continue;
|
|
492
|
+
if (!behaviors.some(({ id }) => id === fallback)) {
|
|
493
|
+
configurationWarnings.push({
|
|
494
|
+
code: 'DEFAULT_LONG_BEHAVIOR_UNAVAILABLE',
|
|
495
|
+
role,
|
|
496
|
+
behavior_id: fallback,
|
|
497
|
+
reason: disabledBehaviors.has(fallback) ? 'local_disabled_or_unselected' : 'not_loaded',
|
|
498
|
+
});
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
const disabledPerceptions = new Set(gameplay.disabled_perception_modules);
|
|
502
|
+
const hubPerceptions = activeWorkspace
|
|
503
|
+
? listAgentWorkspacePerceptionSources(workspaceDir, profile, activeWorkspace)
|
|
504
|
+
: [];
|
|
505
|
+
if (activeWorkspace) {
|
|
506
|
+
for (const source of hubPerceptions) {
|
|
507
|
+
const item = activeWorkspace.items.perception.find((candidate) => (
|
|
508
|
+
!!candidate.runtimeEntryPath
|
|
509
|
+
&& resolveLocalAgentWorkspacePath(
|
|
510
|
+
workspaceDir,
|
|
511
|
+
profile,
|
|
512
|
+
activeWorkspace!,
|
|
513
|
+
candidate.runtimeEntryPath,
|
|
514
|
+
) === source.sourcePath
|
|
515
|
+
));
|
|
516
|
+
const workingPath = item
|
|
517
|
+
? resolveLocalAgentWorkspaceWorkingCopyPath(workspaceDir, profile, item)
|
|
518
|
+
: undefined;
|
|
519
|
+
if (!item || !workingPath) continue;
|
|
520
|
+
registerDiscoveredCapability(workspaceDir, profile, {
|
|
521
|
+
type: 'perception',
|
|
522
|
+
path: workingPath,
|
|
523
|
+
runtimeId: source.declaredId ?? source.id,
|
|
524
|
+
title: source.name,
|
|
525
|
+
description: source.description,
|
|
526
|
+
selectedByHub: true,
|
|
527
|
+
hub: {
|
|
528
|
+
resourceId: item.resourceId,
|
|
529
|
+
versionId: item.versionId,
|
|
530
|
+
workspaceItemId: item.workspaceItemId,
|
|
531
|
+
publisher: item.hub?.publisher ?? 'community',
|
|
532
|
+
baseSha256: item.sourceFiles[0]?.sha256,
|
|
533
|
+
localOriginUnrecognized: item.resolution === 'local_origin_unrecognized'
|
|
534
|
+
? true
|
|
535
|
+
: undefined,
|
|
536
|
+
},
|
|
537
|
+
});
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
const hubPerceptionIds = new Set(hubPerceptions.map(({ id }) => id));
|
|
541
|
+
const localPerceptionDir = getUserDataAccountPerceptionsDir(workspaceDir, profile);
|
|
542
|
+
const allLocalPerceptions = discoveredLocal.perceptions.map(({ source }) => source);
|
|
543
|
+
const localPerceptions = discoveredLocal.perceptions
|
|
544
|
+
.filter(({ source, entry }) => (
|
|
545
|
+
entry.selection === 'equipped' && !disabledPerceptions.has(source.id)
|
|
546
|
+
&& !activeWorkspace?.items.perception.some(item => item.resourceId === entry.hub?.resourceId)
|
|
547
|
+
))
|
|
548
|
+
.map(({ source }) => source);
|
|
549
|
+
const localPerceptionSourcePaths = new Set(
|
|
550
|
+
allLocalPerceptions.map(({ sourcePath }) => resolve(sourcePath)),
|
|
551
|
+
);
|
|
552
|
+
let expectedLocalPerceptions = localPerceptions.length;
|
|
553
|
+
for (const path of listCapabilityModuleCandidates(localPerceptionDir)) {
|
|
554
|
+
if (localPerceptionSourcePaths.has(resolve(path))) continue;
|
|
555
|
+
const diagnostic = diagnoseRejectedCapabilityModule('perception', path);
|
|
556
|
+
const operationName = capabilityEntryForPath(workspaceDir, profile, 'perception', path)?.runtimeId ?? diagnostic.declaredId;
|
|
557
|
+
if (operationName && disabledPerceptions.has(operationName)) continue;
|
|
558
|
+
expectedLocalPerceptions += 1;
|
|
559
|
+
capabilityWarnings.push({ ...warningFromStaticDiagnostic('perception', 'local', diagnostic),
|
|
560
|
+
...(operationName ? { id: operationName } : {}) });
|
|
561
|
+
}
|
|
562
|
+
if (activeWorkspace) {
|
|
563
|
+
const discoveredPaths = new Set(hubPerceptions.map(({ sourcePath }) => resolve(sourcePath)));
|
|
564
|
+
for (const item of activeWorkspace.items.perception) {
|
|
565
|
+
if (!item.runtimeEntryPath) {
|
|
566
|
+
capabilityWarnings.push(missingProjectionWarning('perception', item));
|
|
567
|
+
continue;
|
|
568
|
+
}
|
|
569
|
+
const path = resolveLocalAgentWorkspacePath(
|
|
570
|
+
workspaceDir,
|
|
571
|
+
profile,
|
|
572
|
+
activeWorkspace,
|
|
573
|
+
item.runtimeEntryPath,
|
|
574
|
+
);
|
|
575
|
+
if (discoveredPaths.has(resolve(path))) continue;
|
|
576
|
+
capabilityWarnings.push(warningFromStaticDiagnostic(
|
|
577
|
+
'perception',
|
|
578
|
+
'hub',
|
|
579
|
+
diagnoseRejectedCapabilityModule('perception', path),
|
|
580
|
+
{ resourceId: item.resourceId, versionId: item.versionId },
|
|
581
|
+
));
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
const enabledPerceptions = mergeAgentWorkspacePerceptionSources(
|
|
585
|
+
localPerceptions,
|
|
586
|
+
hubPerceptions,
|
|
587
|
+
disabledPerceptions,
|
|
588
|
+
);
|
|
589
|
+
const reminderTopics = new Map<string, string[]>();
|
|
590
|
+
for (const source of enabledPerceptions) {
|
|
591
|
+
if (!source.reminder || source.apiVersion !== PERCEPTION_PLUGIN_API_VERSION) continue;
|
|
592
|
+
const ids = reminderTopics.get(source.reminder.topic) ?? [];
|
|
593
|
+
ids.push(source.id); reminderTopics.set(source.reminder.topic, ids);
|
|
594
|
+
}
|
|
595
|
+
const conflictingPerceptions = new Set([...reminderTopics.values()].filter(ids => ids.length > 1).flat());
|
|
596
|
+
for (const source of enabledPerceptions.filter(source => conflictingPerceptions.has(source.id))) {
|
|
597
|
+
capabilityWarnings.push({ code: 'CAPABILITY_NOT_LOADED', capability_type: 'perception',
|
|
598
|
+
source: hubPerceptionIds.has(source.id) ? 'hub' : 'local', stage: 'selection', id: source.id,
|
|
599
|
+
reason: `perception_topic_conflict:${source.reminder!.topic}:${reminderTopics.get(source.reminder!.topic)!.join(',')}` });
|
|
600
|
+
}
|
|
601
|
+
const reflexBindings = enabledPerceptions.filter(isSupportedPerceptionSource).flatMap(source =>
|
|
602
|
+
Object.entries(source.module?.behaviors ?? {}).map(([key,binding]) => {
|
|
603
|
+
const id = resolveReactionBehavior(binding,behaviorEntries.map(entry => ({ id: entry.id,
|
|
604
|
+
declaredId: enabledBehaviors.find(source => source.id === entry.id)?.declaredId,
|
|
605
|
+
resourceId: entry.resource_id, loadable: entry.loadable })));
|
|
606
|
+
if (!id) configurationWarnings.push({ code: 'PERCEPTION_BEHAVIOR_NOT_LOADED',
|
|
607
|
+
perception_id: source.id, binding: key, behavior_name: binding.name,
|
|
608
|
+
message: `Equip the paired strategy ${binding.name}; perception observation and notifications remain available.` });
|
|
609
|
+
return { perception_id: source.id, binding: key, behavior_id: id ?? binding.name,
|
|
610
|
+
available: !!id, default_enabled: false,
|
|
611
|
+
...(id ? {} : { reason: 'behavior_not_loaded' }) };
|
|
612
|
+
}));
|
|
613
|
+
const perceptionEntry = (source: typeof enabledPerceptions[number]) => ({
|
|
614
|
+
id: source.id,
|
|
615
|
+
name: source.name,
|
|
616
|
+
description: source.description,
|
|
617
|
+
source: hubPerceptionIds.has(source.id) ? 'hub' : 'workspace',
|
|
618
|
+
...pluginApiVersionStatus('perception', expectedPerceptionApiVersion(source), source.apiVersion),
|
|
619
|
+
...(source.compatibilityError ? { loadable: false, compatibility_error: source.compatibilityError } : {}),
|
|
620
|
+
});
|
|
621
|
+
const perceptions = enabledPerceptions
|
|
622
|
+
.filter(source => isSupportedPerceptionSource(source) && !conflictingPerceptions.has(source.id))
|
|
623
|
+
.map(perceptionEntry);
|
|
624
|
+
const incompatiblePerceptions = enabledPerceptions
|
|
625
|
+
.filter(source => !isSupportedPerceptionSource(source))
|
|
626
|
+
.map(perceptionEntry);
|
|
627
|
+
for (const source of enabledPerceptions) {
|
|
628
|
+
if (isSupportedPerceptionSource(source)) continue;
|
|
629
|
+
capabilityWarnings.push(compatibilityWarning(
|
|
630
|
+
'perception',
|
|
631
|
+
hubPerceptionIds.has(source.id) ? 'hub' : 'local',
|
|
632
|
+
source,
|
|
633
|
+
source.compatibilityError ?? `perception_api_version_unsupported:expected=${expectedPerceptionApiVersion(source)}:received=${source.apiVersion ?? 'missing'}`,
|
|
634
|
+
));
|
|
635
|
+
}
|
|
636
|
+
const selectedLocalPerceptionPaths = new Set(localPerceptions.map(({ sourcePath }) => resolve(sourcePath)));
|
|
637
|
+
for (const source of allLocalPerceptions) {
|
|
638
|
+
if (
|
|
639
|
+
selectedLocalPerceptionPaths.has(resolve(source.sourcePath))
|
|
640
|
+
|| isSupportedPerceptionSource(source)
|
|
641
|
+
) continue;
|
|
642
|
+
capabilityWarnings.push(compatibilityWarning(
|
|
643
|
+
'perception',
|
|
644
|
+
'local',
|
|
645
|
+
source,
|
|
646
|
+
source.compatibilityError ?? `perception_api_version_unsupported:expected=${expectedPerceptionApiVersion(source)}:received=${source.apiVersion ?? 'missing'}`,
|
|
647
|
+
));
|
|
648
|
+
}
|
|
649
|
+
const disabledTriggers = new Set(gameplay.disabled_triggers);
|
|
650
|
+
const localTriggerDir = getUserDataAccountTriggersDir(workspaceDir, profile);
|
|
651
|
+
const triggerSources = listClawclawTriggerSources(localTriggerDir);
|
|
652
|
+
const enabledTriggers = triggerSources.filter((source) => !disabledTriggers.has(source.id));
|
|
653
|
+
const triggerSourcePaths = new Set(triggerSources.map(({ sourcePath }) => resolve(sourcePath)));
|
|
654
|
+
let expectedLocalTriggers = enabledTriggers.length;
|
|
655
|
+
for (const path of listCapabilityModuleCandidates(localTriggerDir)) {
|
|
656
|
+
if (triggerSourcePaths.has(resolve(path))) continue;
|
|
657
|
+
const diagnostic = diagnoseRejectedCapabilityModule('trigger', path);
|
|
658
|
+
if (diagnostic.declaredId && disabledTriggers.has(diagnostic.declaredId)) continue;
|
|
659
|
+
expectedLocalTriggers += 1;
|
|
660
|
+
capabilityWarnings.push(warningFromStaticDiagnostic('trigger', 'local', diagnostic));
|
|
661
|
+
}
|
|
662
|
+
const availableBehaviorIds = new Set(behaviors.map(({ id }) => id));
|
|
663
|
+
const triggerEntry = (source: typeof enabledTriggers[number]) => {
|
|
664
|
+
const behaviorId = gameplay.triggers[source.id]?.behavior ?? source.manifest.defaultBehavior;
|
|
665
|
+
const versionCompatible = source.apiVersion === TRIGGER_PLUGIN_API_VERSION;
|
|
666
|
+
const bindingAvailable = availableBehaviorIds.has(behaviorId);
|
|
667
|
+
const loadable = versionCompatible && bindingAvailable;
|
|
668
|
+
return {
|
|
669
|
+
id: source.id,
|
|
670
|
+
name: source.name,
|
|
671
|
+
description: source.description,
|
|
672
|
+
api_version: source.apiVersion,
|
|
673
|
+
expected_api_version: TRIGGER_PLUGIN_API_VERSION,
|
|
674
|
+
loadable,
|
|
675
|
+
...(loadable ? {} : {
|
|
676
|
+
compatibility_error: versionCompatible
|
|
677
|
+
? `trigger_binding_unavailable:${behaviorId}`
|
|
678
|
+
: `trigger_api_version_unsupported:expected=${TRIGGER_PLUGIN_API_VERSION}:received=${source.apiVersion}`,
|
|
679
|
+
}),
|
|
680
|
+
behavior_id: behaviorId,
|
|
681
|
+
source: 'local',
|
|
682
|
+
};
|
|
683
|
+
};
|
|
684
|
+
const triggerEntries = enabledTriggers.map(triggerEntry);
|
|
685
|
+
const triggers = triggerEntries.filter(({ loadable }) => loadable);
|
|
686
|
+
const incompatibleTriggers = triggerEntries.filter(({ loadable }) => !loadable);
|
|
687
|
+
for (const entry of incompatibleTriggers) {
|
|
688
|
+
const source = enabledTriggers.find(({ id }) => id === entry.id)!;
|
|
689
|
+
capabilityWarnings.push(compatibilityWarning(
|
|
690
|
+
'trigger',
|
|
691
|
+
'local',
|
|
692
|
+
source,
|
|
693
|
+
String(entry.compatibility_error),
|
|
694
|
+
));
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
// Mutate Agent-facing Skill/Persona targets only after every non-Skill
|
|
698
|
+
// source has been parsed and Hub/local identity conflicts have passed.
|
|
699
|
+
const skillChanges = activeWorkspace
|
|
700
|
+
? (dependencies.skillSync ?? syncAgentWorkspaceSkills)(workspaceDir, profile, activeWorkspace)
|
|
701
|
+
: {
|
|
702
|
+
added: [], updated: [], removed: [], unchanged: [], failed: [],
|
|
703
|
+
preservedModified: [],
|
|
704
|
+
conflicts: inspectSkillNameConflicts(workspaceDir, profile),
|
|
705
|
+
requiresUserConfirmation: false,
|
|
706
|
+
};
|
|
707
|
+
const hubPersonaItem = activeWorkspace?.items.persona[0];
|
|
708
|
+
if (hubPersonaItem && snapshot.persona.source !== 'local' && (
|
|
709
|
+
snapshot.persona.source !== 'hub'
|
|
710
|
+
|| snapshot.persona.resource_id !== hubPersonaItem.resourceId
|
|
711
|
+
|| snapshot.persona.exists !== true
|
|
712
|
+
)) {
|
|
713
|
+
capabilityWarnings.push({
|
|
714
|
+
code: 'CAPABILITY_NOT_LOADED',
|
|
715
|
+
capability_type: 'persona',
|
|
716
|
+
source: 'hub',
|
|
717
|
+
reason: 'persona_file_unavailable',
|
|
718
|
+
stage: 'selection',
|
|
719
|
+
resource_id: hubPersonaItem.resourceId,
|
|
720
|
+
version_id: hubPersonaItem.versionId,
|
|
721
|
+
path: snapshot.persona.path,
|
|
722
|
+
});
|
|
723
|
+
} else if (snapshot.persona.source === 'local' && snapshot.persona.exists !== true) {
|
|
724
|
+
capabilityWarnings.push({
|
|
725
|
+
code: 'CAPABILITY_NOT_LOADED',
|
|
726
|
+
capability_type: 'persona',
|
|
727
|
+
source: 'local',
|
|
728
|
+
reason: 'persona_file_unavailable',
|
|
729
|
+
stage: 'selection',
|
|
730
|
+
...(snapshot.persona.id ? { id: snapshot.persona.id } : {}),
|
|
731
|
+
path: snapshot.persona.path,
|
|
732
|
+
});
|
|
733
|
+
}
|
|
734
|
+
if (
|
|
735
|
+
hubPersonaItem
|
|
736
|
+
&& snapshot.persona.source === 'hub'
|
|
737
|
+
&& snapshot.persona.path
|
|
738
|
+
&& snapshot.persona.exists
|
|
739
|
+
) {
|
|
740
|
+
registerDiscoveredCapability(workspaceDir, profile, {
|
|
741
|
+
type: 'persona',
|
|
742
|
+
path: snapshot.persona.path,
|
|
743
|
+
runtimeId: basename(snapshot.persona.path, extname(snapshot.persona.path)),
|
|
744
|
+
title: hubPersonaItem.title,
|
|
745
|
+
description: hubPersonaItem.description,
|
|
746
|
+
initialDescription: `Persona ${basename(snapshot.persona.path)}`,
|
|
747
|
+
selectedByHub: true,
|
|
748
|
+
hub: {
|
|
749
|
+
resourceId: hubPersonaItem.resourceId,
|
|
750
|
+
versionId: hubPersonaItem.versionId,
|
|
751
|
+
workspaceItemId: hubPersonaItem.workspaceItemId,
|
|
752
|
+
publisher: hubPersonaItem.hub?.publisher ?? 'community',
|
|
753
|
+
baseSha256: hubPersonaItem.sourceFiles[0]?.sha256,
|
|
754
|
+
localOriginUnrecognized: hubPersonaItem.resolution === 'local_origin_unrecognized'
|
|
755
|
+
? true
|
|
756
|
+
: undefined,
|
|
757
|
+
},
|
|
758
|
+
});
|
|
759
|
+
}
|
|
760
|
+
const cloudChanges = completedSync ?? (activeWorkspace && !inventoryReadFailed
|
|
761
|
+
? await (dependencies.cloudSync ?? syncCapabilitiesToCloud)(
|
|
762
|
+
workspaceDir,
|
|
763
|
+
profile,
|
|
764
|
+
activeWorkspace,
|
|
765
|
+
)
|
|
766
|
+
: undefined);
|
|
767
|
+
if (!completedSync && cloudChanges && (
|
|
768
|
+
cloudChanges.uploaded.length > 0 || cloudChanges.equipmentChanged
|
|
769
|
+
|| cloudChanges.failed.some(item => item.action === 'equipment')
|
|
770
|
+
)) {
|
|
771
|
+
firstSkillChanges = skillChanges;
|
|
772
|
+
try {
|
|
773
|
+
const updatedInventory = await (dependencies.cloudWorkspaceUpdates ?? syncInstalledCapabilityUpdates)(profile);
|
|
774
|
+
workspaceResult = await (dependencies.workspaceSync ?? syncAgentWorkspaceConfig)(workspaceDir, profile, {
|
|
775
|
+
workspaceInventory: updatedInventory.inventoryComplete ? updatedInventory.inventory : undefined,
|
|
776
|
+
});
|
|
777
|
+
activeWorkspace = workspaceResult.snapshot;
|
|
778
|
+
workspaceSyncStatus = workspaceResult.status;
|
|
779
|
+
if (updatedInventory.inventoryComplete) {
|
|
780
|
+
const presence = reconcileCapabilityWorkspacePresence(workspaceDir, profile, updatedInventory.inventory, activeWorkspace);
|
|
781
|
+
cloudPresence = {
|
|
782
|
+
deactivated: [...cloudPresence.deactivated, ...presence.deactivated],
|
|
783
|
+
restored: [...cloudPresence.restored, ...presence.restored],
|
|
784
|
+
inactiveResourceIds: presence.inactiveResourceIds,
|
|
785
|
+
};
|
|
786
|
+
}
|
|
787
|
+
activeWorkspace = filterInactiveAgentWorkspaceSnapshot(workspaceDir, profile, activeWorkspace, cloudPresence.inactiveResourceIds);
|
|
788
|
+
} catch (error) {
|
|
789
|
+
workspaceSyncStatus = 'stale_fallback';
|
|
790
|
+
workspaceSyncError = `post_upload_workspace_refresh_failed:${error instanceof Error ? error.message : String(error)}`;
|
|
791
|
+
console.error(`[clawclaw-cli] ${workspaceSyncError}`);
|
|
792
|
+
}
|
|
793
|
+
return renderFinalContext(cloudChanges);
|
|
794
|
+
}
|
|
795
|
+
let participation;
|
|
796
|
+
try {
|
|
797
|
+
const client = (dependencies.clientFactory ?? (() => GameClient.fromAuth()))();
|
|
798
|
+
participation = await queryGameParticipationStatus(client);
|
|
799
|
+
} catch (error) {
|
|
800
|
+
participation = {
|
|
801
|
+
schema: GAME_STATUS_SCHEMA,
|
|
802
|
+
status: 'unknown' as const,
|
|
803
|
+
queue_status: null,
|
|
804
|
+
};
|
|
805
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
806
|
+
console.error(`[clawclaw-cli] participation status unavailable: ${message}`);
|
|
807
|
+
}
|
|
808
|
+
const capabilitySummary = {
|
|
809
|
+
behavior: {
|
|
810
|
+
selected_hub: activeWorkspace?.items.strategy.length ?? 0,
|
|
811
|
+
eligible_local: expectedLocalBehaviors,
|
|
812
|
+
available: behaviors.length,
|
|
813
|
+
warnings: capabilityWarnings.filter(({ capability_type }) => (
|
|
814
|
+
capability_type === 'behavior'
|
|
815
|
+
)).length,
|
|
816
|
+
},
|
|
817
|
+
perception: {
|
|
818
|
+
selected_hub: activeWorkspace?.items.perception.length ?? 0,
|
|
819
|
+
eligible_local: expectedLocalPerceptions,
|
|
820
|
+
available: perceptions.length,
|
|
821
|
+
warnings: capabilityWarnings.filter(({ capability_type }) => (
|
|
822
|
+
capability_type === 'perception'
|
|
823
|
+
)).length,
|
|
824
|
+
},
|
|
825
|
+
trigger: {
|
|
826
|
+
selected_hub: 0,
|
|
827
|
+
eligible_local: expectedLocalTriggers,
|
|
828
|
+
available: triggers.length,
|
|
829
|
+
warnings: capabilityWarnings.filter(({ capability_type }) => (
|
|
830
|
+
capability_type === 'trigger'
|
|
831
|
+
)).length,
|
|
832
|
+
},
|
|
833
|
+
persona: {
|
|
834
|
+
selected_hub: activeWorkspace?.items.persona.length ?? 0,
|
|
835
|
+
selected_local: snapshot.persona.source === 'local' ? 1 : 0,
|
|
836
|
+
available: snapshot.persona.exists ? 1 : 0,
|
|
837
|
+
warnings: capabilityWarnings.filter(({ capability_type }) => (
|
|
838
|
+
capability_type === 'persona'
|
|
839
|
+
)).length,
|
|
840
|
+
},
|
|
841
|
+
};
|
|
842
|
+
const behaviorSourceById = new Map(enabledBehaviors.map((source) => [source.id, source]));
|
|
843
|
+
const perceptionSourceById = new Map(enabledPerceptions.map((source) => [source.id, source]));
|
|
844
|
+
const triggerSourceById = new Map(enabledTriggers.map((source) => [source.id, source]));
|
|
845
|
+
const skillChangeSummary = compactSkillChanges(firstSkillChanges ? {
|
|
846
|
+
...skillChanges,
|
|
847
|
+
added: [...new Set([...firstSkillChanges.added, ...skillChanges.added])],
|
|
848
|
+
updated: [...new Set([...firstSkillChanges.updated, ...skillChanges.updated])],
|
|
849
|
+
removed: [...new Set([...firstSkillChanges.removed, ...skillChanges.removed])],
|
|
850
|
+
failed: [...firstSkillChanges.failed, ...skillChanges.failed],
|
|
851
|
+
skipped: skillChanges.skipped,
|
|
852
|
+
} : skillChanges);
|
|
853
|
+
const cloudConflicts = [...cloudRefreshChanges.conflicts, ...(cloudChanges?.conflicts ?? [])]
|
|
854
|
+
.filter((value, index, values) => values.findIndex((candidate) => (
|
|
855
|
+
candidate.type === value.type
|
|
856
|
+
&& candidate.id === value.id
|
|
857
|
+
&& candidate.resource_id === value.resource_id
|
|
858
|
+
)) === index).map(value => {
|
|
859
|
+
const entry = capabilityEntryForHubResource(workspaceDir, profile, value.type, value.resource_id);
|
|
860
|
+
return { ...value, ...(entry ? { selection_ref: capabilitySelectionRef(entry),
|
|
861
|
+
working_copy_path: capabilityWorkspacePath(workspaceDir, profile, entry) } : {}) };
|
|
862
|
+
});
|
|
863
|
+
const cloudFailures = [...cloudRefreshChanges.failed, ...(cloudChanges?.failed ?? [])];
|
|
864
|
+
const forkReplacements = newForkReplacements.map(item => {
|
|
865
|
+
const type = item.resourceType === 'strategy' ? 'behavior' : item.resourceType;
|
|
866
|
+
const entry = capabilityEntryForHubResource(workspaceDir, profile, type, item.resourceId);
|
|
867
|
+
const finalItem = Object.values(activeWorkspace?.items ?? {}).flat().find(current => current.resourceId === item.resourceId);
|
|
868
|
+
return { type, id: entry?.runtimeId, resource_id: item.resourceId,
|
|
869
|
+
...(entry ? { selection_ref: capabilitySelectionRef(entry) } : {}),
|
|
870
|
+
forked_from_resource_id: item.forkReconciliation!.parentResourceId,
|
|
871
|
+
from_id: item.forkReconciliation!.parentOperationName,
|
|
872
|
+
resolution: finalItem?.resolution ?? item.resolution,
|
|
873
|
+
};
|
|
874
|
+
});
|
|
875
|
+
const workspaceVersionUpdates = mergeWorkspaceVersionUpdates(
|
|
876
|
+
cloudWorkspaceUpdates.updated,
|
|
877
|
+
inferredWorkspaceVersionUpdates(activeWorkspace, workspaceResult?.previous),
|
|
878
|
+
);
|
|
879
|
+
const cloudChangeSummary = (
|
|
880
|
+
workspaceVersionUpdates.length > 0
|
|
881
|
+
|| cloudWorkspaceUpdates.failed.length > 0
|
|
882
|
+
|| cloudRefreshChanges.downloaded.length > 0
|
|
883
|
+
|| (cloudChanges?.uploaded.length ?? 0) > 0
|
|
884
|
+
|| (cloudChanges?.skipped.length ?? 0) > 0
|
|
885
|
+
|| cloudConflicts.length > 0
|
|
886
|
+
|| cloudFailures.length > 0
|
|
887
|
+
|| cloudPresence.deactivated.length > 0
|
|
888
|
+
|| cloudPresence.restored.length > 0
|
|
889
|
+
|| forkReplacements.length > 0
|
|
890
|
+
) ? {
|
|
891
|
+
workspace_updated: workspaceVersionUpdates,
|
|
892
|
+
workspace_update_failed: cloudWorkspaceUpdates.failed,
|
|
893
|
+
downloaded: cloudRefreshChanges.downloaded,
|
|
894
|
+
uploaded: cloudChanges?.uploaded ?? [],
|
|
895
|
+
skipped: cloudChanges?.skipped ?? [],
|
|
896
|
+
conflicts: cloudConflicts,
|
|
897
|
+
failed: cloudFailures,
|
|
898
|
+
deactivated: cloudPresence.deactivated,
|
|
899
|
+
restored: cloudPresence.restored,
|
|
900
|
+
...(forkReplacements.length ? { fork_replacements: forkReplacements } : {}),
|
|
901
|
+
unchanged: cloudChanges?.unchanged ?? [],
|
|
902
|
+
} : undefined;
|
|
903
|
+
const selectionRequired = pendingCapabilitySelections(workspaceDir, profile);
|
|
904
|
+
const blockedSkillNames = skillConflictNames(skillChanges.conflicts ?? []);
|
|
905
|
+
const reservedSkillPaths = new Set(discoveredLocal.reservedSkills.map(skill => skill.path));
|
|
906
|
+
const skills = [...new Set(Object.values(readCapabilityWorkspaceRegistry(workspaceDir, profile).entries)
|
|
907
|
+
.filter((entry) => entry.type === 'skill' && entry.selection === 'equipped'
|
|
908
|
+
&& !blockedSkillNames.has(skillNameKey(entry.runtimeId))
|
|
909
|
+
&& !entry.hub?.cloudStatus && !isPackageManagedSkill(entry.runtimeId)
|
|
910
|
+
&& !reservedSkillPaths.has(capabilityWorkspacePath(workspaceDir, profile, entry)))
|
|
911
|
+
.map((entry) => entry.runtimeId).concat((skillChanges.conflicts ?? [])
|
|
912
|
+
.flatMap(item => item.active ? [item.active.id ?? item.active.name] : [])))].sort();
|
|
913
|
+
const output = {
|
|
914
|
+
startup: summarizeStartupBlockers(selectionRequired.map(entry => ({
|
|
915
|
+
type: entry.type, id: entry.runtimeId, selection_ref: capabilitySelectionRef(entry),
|
|
916
|
+
})), cloudConflicts, cloudFailures),
|
|
917
|
+
sync: {
|
|
918
|
+
status: workspaceSyncStatus,
|
|
919
|
+
revision: activeWorkspace?.revision ?? null,
|
|
920
|
+
...(workspaceSyncError ? { error: workspaceSyncError } : {}),
|
|
921
|
+
},
|
|
922
|
+
...(skillChangeSummary || cloudChangeSummary || discoveredLocal.reservedSkills.length ? {
|
|
923
|
+
changes: {
|
|
924
|
+
...(discoveredLocal.reservedSkills.length ? { skipped_local_skills: discoveredLocal.reservedSkills } : {}),
|
|
925
|
+
...(skillChangeSummary ? { skills: skillChangeSummary } : {}),
|
|
926
|
+
...(cloudChangeSummary ? { cloud_sync: cloudChangeSummary } : {}),
|
|
927
|
+
},
|
|
928
|
+
} : {}),
|
|
929
|
+
capabilities: {
|
|
930
|
+
summary: capabilitySummary,
|
|
931
|
+
skills,
|
|
932
|
+
behaviors: behaviors.map((entry) => {
|
|
933
|
+
const source = behaviorSourceById.get(entry.id)!;
|
|
934
|
+
const localized = resolveClawclawResourceMetadata(source, LOAD_DISPLAY_LOCALE);
|
|
935
|
+
return {
|
|
936
|
+
id: entry.id,
|
|
937
|
+
name: localized.name,
|
|
938
|
+
description: source.description,
|
|
939
|
+
source: entry.source,
|
|
940
|
+
strategy_type: classifyStrategyLifecycle(readFileSync(source.sourcePath, 'utf8')),
|
|
941
|
+
...(source.management.versionNumber ? { version_number: source.management.versionNumber,
|
|
942
|
+
version_description: source.management.versionDescription ?? '' } : {}),
|
|
943
|
+
};
|
|
944
|
+
}),
|
|
945
|
+
perceptions: perceptions.map((entry) => {
|
|
946
|
+
const source = perceptionSourceById.get(entry.id)!;
|
|
947
|
+
const localized = resolveClawclawResourceMetadata({ ...source.manifest, display: source.display }, LOAD_DISPLAY_LOCALE);
|
|
948
|
+
return {
|
|
949
|
+
id: entry.id,
|
|
950
|
+
name: localized.name,
|
|
951
|
+
description: source.description,
|
|
952
|
+
source: entry.source,
|
|
953
|
+
...(reflexBindings.some(binding => binding.perception_id === entry.id)
|
|
954
|
+
? { reflex_bindings: reflexBindings.filter(binding => binding.perception_id === entry.id) } : {}),
|
|
955
|
+
};
|
|
956
|
+
}),
|
|
957
|
+
triggers: triggers.map((entry) => {
|
|
958
|
+
const source = triggerSourceById.get(entry.id)!;
|
|
959
|
+
const localized = resolveClawclawResourceMetadata(source.manifest, LOAD_DISPLAY_LOCALE);
|
|
960
|
+
return {
|
|
961
|
+
id: entry.id,
|
|
962
|
+
name: localized.name,
|
|
963
|
+
description: localized.description,
|
|
964
|
+
source: entry.source,
|
|
965
|
+
behavior_id: entry.behavior_id,
|
|
966
|
+
};
|
|
967
|
+
}),
|
|
968
|
+
warnings: capabilityWarnings.map(compactCapabilityWarning),
|
|
969
|
+
selection_required: selectionRequired.map((entry) => ({
|
|
970
|
+
type: entry.type,
|
|
971
|
+
id: entry.runtimeId,
|
|
972
|
+
declared_id: entry.declaredId ?? entry.runtimeId,
|
|
973
|
+
selection_ref: capabilitySelectionRef(entry),
|
|
974
|
+
working_copy_path: capabilityWorkspacePath(workspaceDir, profile, entry),
|
|
975
|
+
title: entry.title,
|
|
976
|
+
...(entry.hub ? { resource_id: entry.hub.resourceId, publisher: entry.hub.publisher,
|
|
977
|
+
owner_id: entry.hub.ownerId, owner_name: entry.hub.ownerName } : {}),
|
|
978
|
+
strategy_type: entry.strategyLifecycle,
|
|
979
|
+
action: `Choose once with ccl capability equip ${capabilitySelectionRef(entry)} or ccl capability unequip ${capabilitySelectionRef(entry)}.`,
|
|
980
|
+
})),
|
|
981
|
+
},
|
|
982
|
+
configuration_warnings: compactConfigurationWarnings(configurationWarnings),
|
|
983
|
+
participation: compactParticipation(participation),
|
|
984
|
+
};
|
|
985
|
+
const reference = saveStartupContext(workspaceDir, profile, {
|
|
986
|
+
sync: output.sync, changes: output.changes, capabilities: output.capabilities,
|
|
987
|
+
configuration_warnings: output.configuration_warnings, persona_available: snapshot.persona.exists,
|
|
988
|
+
});
|
|
989
|
+
const equipmentConflicts = cloudFailures.filter(value => value.action === 'equipment'
|
|
990
|
+
&& 'code' in value && value.code === 'SKILL_NAME_CONFLICT');
|
|
991
|
+
console.log(JSON.stringify({
|
|
992
|
+
schema: PREPARE_SCHEMA, ...reference, startup: output.startup,
|
|
993
|
+
participation: output.participation,
|
|
994
|
+
capabilities: { skills, ...(selectionRequired.length ? { selection_required: output.capabilities.selection_required } : {}) },
|
|
995
|
+
...(cloudConflicts.length || equipmentConflicts.length ? {
|
|
996
|
+
changes: { cloud_sync: { conflicts: cloudConflicts, failed: equipmentConflicts } },
|
|
997
|
+
} : {}),
|
|
998
|
+
}, null, 2));
|
|
999
|
+
};
|
|
1000
|
+
await renderFinalContext();
|
|
1001
|
+
});
|
|
1002
|
+
}
|