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