@myclaw163/clawclaw-cli 0.8.16 → 0.8.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/configuration.md +7 -3
- package/docs/runtime/owner-lifecycle-and-observability.md +25 -0
- package/package.json +1 -1
- package/skills/clawclaw/SKILL.md +22 -3
- package/skills/clawclaw/references/COMMANDS.md +8 -4
- package/src/commands/account.ts +9 -1
- package/src/commands/behavior.ts +17 -17
- package/src/commands/capability.ts +33 -25
- package/src/commands/load.ts +145 -8
- package/src/commands/perception.ts +17 -16
- package/src/commands/persona.ts +24 -6
- package/src/lib/agent-workspace-client.ts +2 -0
- package/src/lib/agent-workspace-runtime.ts +10 -2
- package/src/lib/agent-workspace-skills.ts +7 -1
- package/src/lib/agent-workspace-sync.ts +39 -7
- package/src/lib/capability-cloud-presence.ts +179 -0
- package/src/lib/capability-cloud-refresh.ts +33 -20
- package/src/lib/capability-cloud-sync.ts +94 -7
- package/src/lib/capability-selection.ts +62 -0
- package/src/lib/capability-workspace.ts +4 -0
- package/src/lib/game-client.ts +40 -10
- package/src/lib/http-transport.ts +2 -2
- package/src/lib/hub-client.ts +75 -0
- package/src/lib/persona.ts +14 -1
- package/src/pipeline/event-hints.ts +1 -1
- package/src/runtime/clawclaw/owner.ts +32 -20
- package/src/runtime/clawclaw/plugins/action/action-plugin.ts +33 -6
- package/src/runtime/clawclaw/plugins/behavior/behavior-plugin.ts +8 -0
- package/src/runtime/clawclaw/plugins/source/source-plugin.ts +25 -0
- package/src/runtime/framework/capability-registry.ts +31 -1
- package/src/runtime/framework/plugins/contracts.ts +2 -0
- package/src/runtime/framework/plugins/runtime-plugin-scheduler.ts +14 -4
- package/src/runtime/framework/runtime.ts +5 -0
- package/src/runtime/game-sync-ingress-protocol.ts +34 -0
- package/src/runtime/game-sync-ingress-worker.ts +153 -0
- package/src/runtime/observability/factory.ts +2 -1
- package/src/runtime/observability/process-timing.ts +59 -0
- package/src/runtime/threaded-ws-client.ts +196 -0
- package/src/runtime/ws-client.ts +48 -1
package/src/commands/load.ts
CHANGED
|
@@ -37,6 +37,7 @@ import {
|
|
|
37
37
|
resolveLocalAgentWorkspaceSnapshot,
|
|
38
38
|
syncAgentWorkspaceConfig,
|
|
39
39
|
type AgentWorkspaceSyncResult,
|
|
40
|
+
type LocalAgentWorkspaceSnapshot,
|
|
40
41
|
} from '../lib/agent-workspace-sync.js';
|
|
41
42
|
import { syncAgentWorkspaceSkills } from '../lib/agent-workspace-skills.js';
|
|
42
43
|
import {
|
|
@@ -64,6 +65,12 @@ import {
|
|
|
64
65
|
refreshCapabilitiesFromCloud,
|
|
65
66
|
syncInstalledCapabilityUpdates,
|
|
66
67
|
} from '../lib/capability-cloud-refresh.js';
|
|
68
|
+
import {
|
|
69
|
+
filterInactiveAgentWorkspaceSnapshot,
|
|
70
|
+
reconcileCapabilityWorkspacePresence,
|
|
71
|
+
reconcileCapabilityLoadout,
|
|
72
|
+
type CapabilityPresenceResult,
|
|
73
|
+
} from '../lib/capability-cloud-presence.js';
|
|
67
74
|
|
|
68
75
|
const LOAD_SCHEMA = 'ccl.load.v2';
|
|
69
76
|
const LOAD_DISPLAY_LOCALE = 'en-US';
|
|
@@ -78,6 +85,55 @@ export interface LoadCommandDependencies {
|
|
|
78
85
|
cloudSync?: typeof syncCapabilitiesToCloud;
|
|
79
86
|
}
|
|
80
87
|
|
|
88
|
+
interface WorkspaceVersionUpdate {
|
|
89
|
+
type: string;
|
|
90
|
+
resource_id: string;
|
|
91
|
+
workspace_item_id: string;
|
|
92
|
+
version_id: string;
|
|
93
|
+
from_version?: string;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function inferredWorkspaceVersionUpdates(
|
|
97
|
+
current: LocalAgentWorkspaceSnapshot | undefined,
|
|
98
|
+
previous: LocalAgentWorkspaceSnapshot | undefined,
|
|
99
|
+
): WorkspaceVersionUpdate[] {
|
|
100
|
+
if (!current || !previous) return [];
|
|
101
|
+
const previousByResource = new Map(
|
|
102
|
+
Object.values(previous.items).flat().map((item) => [
|
|
103
|
+
`${item.resourceType}:${item.resourceId}`,
|
|
104
|
+
item,
|
|
105
|
+
]),
|
|
106
|
+
);
|
|
107
|
+
return Object.values(current.items).flat().flatMap((item) => {
|
|
108
|
+
const before = previousByResource.get(`${item.resourceType}:${item.resourceId}`);
|
|
109
|
+
if (
|
|
110
|
+
!before
|
|
111
|
+
|| before.versionId === item.versionId
|
|
112
|
+
|| (item.resolution !== 'hub' && item.resolution !== 'known_online_old')
|
|
113
|
+
) return [];
|
|
114
|
+
return [{
|
|
115
|
+
type: item.resourceType,
|
|
116
|
+
resource_id: item.resourceId,
|
|
117
|
+
workspace_item_id: item.workspaceItemId,
|
|
118
|
+
from_version: before.versionId,
|
|
119
|
+
version_id: item.versionId,
|
|
120
|
+
}];
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function mergeWorkspaceVersionUpdates(
|
|
125
|
+
reported: readonly WorkspaceVersionUpdate[],
|
|
126
|
+
inferred: readonly WorkspaceVersionUpdate[],
|
|
127
|
+
): WorkspaceVersionUpdate[] {
|
|
128
|
+
const merged = new Map<string, WorkspaceVersionUpdate>();
|
|
129
|
+
for (const item of inferred) merged.set(`${item.type}:${item.resource_id}`, { ...item });
|
|
130
|
+
for (const item of reported) {
|
|
131
|
+
const key = `${item.type}:${item.resource_id}`;
|
|
132
|
+
merged.set(key, { ...merged.get(key), ...item });
|
|
133
|
+
}
|
|
134
|
+
return [...merged.values()];
|
|
135
|
+
}
|
|
136
|
+
|
|
81
137
|
function compatibilityWarning(
|
|
82
138
|
type: ModuleCapabilityType,
|
|
83
139
|
source: 'hub' | 'local',
|
|
@@ -203,12 +259,16 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
|
|
|
203
259
|
if (!profile) throw new Error(noAccountMessage('load'));
|
|
204
260
|
ensureAccountUserDataLayout(workspaceDir, profile);
|
|
205
261
|
|
|
206
|
-
let cloudWorkspaceUpdates = {
|
|
262
|
+
let cloudWorkspaceUpdates = {
|
|
263
|
+
updated: [], failed: [], inventory: [], inventoryComplete: false,
|
|
264
|
+
} as Awaited<ReturnType<typeof syncInstalledCapabilityUpdates>>;
|
|
265
|
+
let inventoryReadFailed = false;
|
|
207
266
|
try {
|
|
208
267
|
cloudWorkspaceUpdates = await (
|
|
209
268
|
dependencies.cloudWorkspaceUpdates ?? syncInstalledCapabilityUpdates
|
|
210
269
|
)(profile);
|
|
211
270
|
} catch (error) {
|
|
271
|
+
inventoryReadFailed = true;
|
|
212
272
|
console.error(`[clawclaw-cli] Hub workspace update check unavailable: ${
|
|
213
273
|
error instanceof Error ? error.message : String(error)
|
|
214
274
|
}`);
|
|
@@ -231,12 +291,28 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
|
|
|
231
291
|
console.error(`[clawclaw-cli] Agent workspace sync unavailable: ${workspaceSyncError}`);
|
|
232
292
|
}
|
|
233
293
|
|
|
234
|
-
|
|
294
|
+
let cloudPresence: CapabilityPresenceResult = cloudWorkspaceUpdates.inventoryComplete
|
|
295
|
+
? reconcileCapabilityWorkspacePresence(workspaceDir, profile, cloudWorkspaceUpdates.inventory, workspaceResult?.snapshot)
|
|
296
|
+
: workspaceResult?.snapshot
|
|
297
|
+
? reconcileCapabilityLoadout(workspaceDir, profile, workspaceResult.snapshot)
|
|
298
|
+
: { deactivated: [], restored: [], inactiveResourceIds: [] };
|
|
299
|
+
activeWorkspace = filterInactiveAgentWorkspaceSnapshot(
|
|
300
|
+
workspaceDir,
|
|
301
|
+
profile,
|
|
302
|
+
activeWorkspace,
|
|
303
|
+
cloudPresence.inactiveResourceIds,
|
|
304
|
+
);
|
|
305
|
+
|
|
306
|
+
const cloudRefreshChanges = inventoryReadFailed
|
|
307
|
+
? { downloaded: [], conflicts: [], failed: [], unchanged: [] }
|
|
308
|
+
: await (dependencies.cloudRefresh ?? refreshCapabilitiesFromCloud)(
|
|
235
309
|
workspaceDir,
|
|
236
310
|
profile,
|
|
237
311
|
activeWorkspace,
|
|
238
312
|
);
|
|
239
313
|
|
|
314
|
+
let firstSkillChanges: ReturnType<typeof syncAgentWorkspaceSkills> | undefined;
|
|
315
|
+
const renderFinalContext = async (completedSync?: Awaited<ReturnType<typeof syncCapabilitiesToCloud>>): Promise<void> => {
|
|
240
316
|
let snapshot;
|
|
241
317
|
try {
|
|
242
318
|
snapshot = loadContext(authStore);
|
|
@@ -246,6 +322,13 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
|
|
|
246
322
|
}
|
|
247
323
|
throw error;
|
|
248
324
|
}
|
|
325
|
+
if (
|
|
326
|
+
snapshot.persona.source === 'hub'
|
|
327
|
+
&& snapshot.persona.resource_id
|
|
328
|
+
&& cloudPresence.inactiveResourceIds.includes(snapshot.persona.resource_id)
|
|
329
|
+
) {
|
|
330
|
+
snapshot.persona = { path: null, exists: false, content: '', source: 'none' };
|
|
331
|
+
}
|
|
249
332
|
|
|
250
333
|
const gameplay = readGameplayConfig(workspaceDir, profile);
|
|
251
334
|
const discoveredLocal = discoverLocalCapabilities(workspaceDir, profile);
|
|
@@ -289,6 +372,7 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
|
|
|
289
372
|
const localBehaviors = discoveredLocal.behaviors
|
|
290
373
|
.filter(({ source, entry }) => (
|
|
291
374
|
entry.selection === 'equipped' && !disabledBehaviors.has(source.id)
|
|
375
|
+
&& !activeWorkspace?.items.strategy.some(item => item.resourceId === entry.hub?.resourceId)
|
|
292
376
|
))
|
|
293
377
|
.map(({ source }) => source);
|
|
294
378
|
const localBehaviorSourcePaths = new Set(allLocalBehaviors.map(({ sourcePath }) => resolve(sourcePath)));
|
|
@@ -377,6 +461,14 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
|
|
|
377
461
|
capabilityWarnings.push(compatibilityWarning('behavior', 'local', source, reason));
|
|
378
462
|
}
|
|
379
463
|
const configurationWarnings: Array<Record<string, unknown>> = [];
|
|
464
|
+
if (workspaceSyncError) configurationWarnings.push({
|
|
465
|
+
code: 'WORKSPACE_SYNC_FAILED', message: workspaceSyncError,
|
|
466
|
+
using_previous_snapshot: !!activeWorkspace,
|
|
467
|
+
});
|
|
468
|
+
if (inventoryReadFailed) configurationWarnings.push({
|
|
469
|
+
code: 'WORKSPACE_INVENTORY_UNAVAILABLE',
|
|
470
|
+
message: 'Backpack could not be verified; automatic cloud writes and inactive-resource refresh were skipped.',
|
|
471
|
+
});
|
|
380
472
|
if (snapshot.memory.truncated) {
|
|
381
473
|
configurationWarnings.push({
|
|
382
474
|
code: 'MEMORY_LENGTH_EXCEEDED',
|
|
@@ -408,7 +500,7 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
|
|
|
408
500
|
&& resolveLocalAgentWorkspacePath(
|
|
409
501
|
workspaceDir,
|
|
410
502
|
profile,
|
|
411
|
-
activeWorkspace
|
|
503
|
+
activeWorkspace!,
|
|
412
504
|
candidate.runtimeEntryPath,
|
|
413
505
|
) === source.sourcePath
|
|
414
506
|
));
|
|
@@ -442,6 +534,7 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
|
|
|
442
534
|
const localPerceptions = discoveredLocal.perceptions
|
|
443
535
|
.filter(({ source, entry }) => (
|
|
444
536
|
entry.selection === 'equipped' && !disabledPerceptions.has(source.id)
|
|
537
|
+
&& !activeWorkspace?.items.perception.some(item => item.resourceId === entry.hub?.resourceId)
|
|
445
538
|
))
|
|
446
539
|
.map(({ source }) => source);
|
|
447
540
|
const localPerceptionSourcePaths = new Set(
|
|
@@ -625,13 +718,39 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
|
|
|
625
718
|
},
|
|
626
719
|
});
|
|
627
720
|
}
|
|
628
|
-
const cloudChanges = activeWorkspace
|
|
721
|
+
const cloudChanges = completedSync ?? (activeWorkspace && !inventoryReadFailed
|
|
629
722
|
? await (dependencies.cloudSync ?? syncCapabilitiesToCloud)(
|
|
630
723
|
workspaceDir,
|
|
631
724
|
profile,
|
|
632
725
|
activeWorkspace,
|
|
633
726
|
)
|
|
634
|
-
: undefined;
|
|
727
|
+
: undefined);
|
|
728
|
+
if (!completedSync && cloudChanges && (
|
|
729
|
+
cloudChanges.uploaded.length > 0 || cloudChanges.equipmentChanged
|
|
730
|
+
|| cloudChanges.failed.some(item => item.action === 'equipment')
|
|
731
|
+
)) {
|
|
732
|
+
firstSkillChanges = skillChanges;
|
|
733
|
+
try {
|
|
734
|
+
const updatedInventory = await (dependencies.cloudWorkspaceUpdates ?? syncInstalledCapabilityUpdates)(profile);
|
|
735
|
+
workspaceResult = await (dependencies.workspaceSync ?? syncAgentWorkspaceConfig)(workspaceDir, profile);
|
|
736
|
+
activeWorkspace = workspaceResult.snapshot;
|
|
737
|
+
workspaceSyncStatus = workspaceResult.status;
|
|
738
|
+
if (updatedInventory.inventoryComplete) {
|
|
739
|
+
const presence = reconcileCapabilityWorkspacePresence(workspaceDir, profile, updatedInventory.inventory, activeWorkspace);
|
|
740
|
+
cloudPresence = {
|
|
741
|
+
deactivated: [...cloudPresence.deactivated, ...presence.deactivated],
|
|
742
|
+
restored: [...cloudPresence.restored, ...presence.restored],
|
|
743
|
+
inactiveResourceIds: presence.inactiveResourceIds,
|
|
744
|
+
};
|
|
745
|
+
}
|
|
746
|
+
activeWorkspace = filterInactiveAgentWorkspaceSnapshot(workspaceDir, profile, activeWorkspace, cloudPresence.inactiveResourceIds);
|
|
747
|
+
} catch (error) {
|
|
748
|
+
workspaceSyncStatus = 'stale_fallback';
|
|
749
|
+
workspaceSyncError = `post_upload_workspace_refresh_failed:${error instanceof Error ? error.message : String(error)}`;
|
|
750
|
+
console.error(`[clawclaw-cli] ${workspaceSyncError}`);
|
|
751
|
+
}
|
|
752
|
+
return renderFinalContext(cloudChanges);
|
|
753
|
+
}
|
|
635
754
|
let participation;
|
|
636
755
|
try {
|
|
637
756
|
const client = (dependencies.clientFactory ?? (() => GameClient.fromAuth()))();
|
|
@@ -682,7 +801,13 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
|
|
|
682
801
|
const behaviorSourceById = new Map(enabledBehaviors.map((source) => [source.id, source]));
|
|
683
802
|
const perceptionSourceById = new Map(enabledPerceptions.map((source) => [source.id, source]));
|
|
684
803
|
const triggerSourceById = new Map(enabledTriggers.map((source) => [source.id, source]));
|
|
685
|
-
const skillChangeSummary = compactSkillChanges(
|
|
804
|
+
const skillChangeSummary = compactSkillChanges(firstSkillChanges ? {
|
|
805
|
+
...skillChanges,
|
|
806
|
+
added: [...new Set([...firstSkillChanges.added, ...skillChanges.added])],
|
|
807
|
+
updated: [...new Set([...firstSkillChanges.updated, ...skillChanges.updated])],
|
|
808
|
+
removed: [...new Set([...firstSkillChanges.removed, ...skillChanges.removed])],
|
|
809
|
+
failed: [...firstSkillChanges.failed, ...skillChanges.failed],
|
|
810
|
+
} : skillChanges);
|
|
686
811
|
const cloudConflicts = [...cloudRefreshChanges.conflicts, ...(cloudChanges?.conflicts ?? [])]
|
|
687
812
|
.filter((value, index, values) => values.findIndex((candidate) => (
|
|
688
813
|
candidate.type === value.type
|
|
@@ -690,22 +815,30 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
|
|
|
690
815
|
&& candidate.resource_id === value.resource_id
|
|
691
816
|
)) === index);
|
|
692
817
|
const cloudFailures = [...cloudRefreshChanges.failed, ...(cloudChanges?.failed ?? [])];
|
|
818
|
+
const workspaceVersionUpdates = mergeWorkspaceVersionUpdates(
|
|
819
|
+
cloudWorkspaceUpdates.updated,
|
|
820
|
+
inferredWorkspaceVersionUpdates(activeWorkspace, workspaceResult?.previous),
|
|
821
|
+
);
|
|
693
822
|
const cloudChangeSummary = (
|
|
694
|
-
|
|
823
|
+
workspaceVersionUpdates.length > 0
|
|
695
824
|
|| cloudWorkspaceUpdates.failed.length > 0
|
|
696
825
|
|| cloudRefreshChanges.downloaded.length > 0
|
|
697
826
|
|| (cloudChanges?.uploaded.length ?? 0) > 0
|
|
698
827
|
|| (cloudChanges?.skipped.length ?? 0) > 0
|
|
699
828
|
|| cloudConflicts.length > 0
|
|
700
829
|
|| cloudFailures.length > 0
|
|
830
|
+
|| cloudPresence.deactivated.length > 0
|
|
831
|
+
|| cloudPresence.restored.length > 0
|
|
701
832
|
) ? {
|
|
702
|
-
workspace_updated:
|
|
833
|
+
workspace_updated: workspaceVersionUpdates,
|
|
703
834
|
workspace_update_failed: cloudWorkspaceUpdates.failed,
|
|
704
835
|
downloaded: cloudRefreshChanges.downloaded,
|
|
705
836
|
uploaded: cloudChanges?.uploaded ?? [],
|
|
706
837
|
skipped: cloudChanges?.skipped ?? [],
|
|
707
838
|
conflicts: cloudConflicts,
|
|
708
839
|
failed: cloudFailures,
|
|
840
|
+
deactivated: cloudPresence.deactivated,
|
|
841
|
+
restored: cloudPresence.restored,
|
|
709
842
|
unchanged: cloudChanges?.unchanged ?? [],
|
|
710
843
|
} : undefined;
|
|
711
844
|
const selectionRequired = pendingCapabilitySelections(workspaceDir, profile);
|
|
@@ -737,6 +870,8 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
|
|
|
737
870
|
description: localized.description,
|
|
738
871
|
source: entry.source,
|
|
739
872
|
strategy_type: classifyStrategyLifecycle(readFileSync(source.sourcePath, 'utf8')),
|
|
873
|
+
...(source.management.versionNumber ? { version_number: source.management.versionNumber,
|
|
874
|
+
version_description: source.management.versionDescription ?? '' } : {}),
|
|
740
875
|
};
|
|
741
876
|
}),
|
|
742
877
|
perceptions: perceptions.map((entry) => {
|
|
@@ -771,5 +906,7 @@ export function createLoadCommand(dependencies: LoadCommandDependencies = {}): C
|
|
|
771
906
|
configuration_warnings: compactConfigurationWarnings(configurationWarnings),
|
|
772
907
|
participation: compactParticipation(participation),
|
|
773
908
|
}, null, 2));
|
|
909
|
+
};
|
|
910
|
+
await renderFinalContext();
|
|
774
911
|
});
|
|
775
912
|
}
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
getUserDataAccountPerceptionsDir,
|
|
12
12
|
} from '../lib/user-data.js';
|
|
13
13
|
import { readLocalAgentWorkspaceSnapshot } from '../lib/agent-workspace-sync.js';
|
|
14
|
+
import { filterInactiveAgentWorkspaceSnapshot } from '../lib/capability-cloud-presence.js';
|
|
14
15
|
import {
|
|
15
16
|
listAgentWorkspacePerceptionSources,
|
|
16
17
|
mergeAgentWorkspacePerceptionSources,
|
|
@@ -18,7 +19,8 @@ import {
|
|
|
18
19
|
import { PERCEPTION_PLUGIN_API_VERSION } from '../sdk/perception-plugin/index.js';
|
|
19
20
|
import { pluginApiVersionStatus } from '../runtime/clawclaw/plugins/plugin-api-version.js';
|
|
20
21
|
import { discoverLocalCapabilities } from '../lib/capability-discovery.js';
|
|
21
|
-
import { capabilityEntryForPath,
|
|
22
|
+
import { capabilityEntryForPath, readCapabilityWorkspaceRegistry } from '../lib/capability-workspace.js';
|
|
23
|
+
import { selectCapability } from '../lib/capability-selection.js';
|
|
22
24
|
|
|
23
25
|
export interface PerceptionCommandDependencies {
|
|
24
26
|
activeProfile?: () => AuthProfile | null;
|
|
@@ -56,23 +58,25 @@ Perception modules:
|
|
|
56
58
|
const workspaceDir = getWorkspaceDir();
|
|
57
59
|
const profile = activeProfile(dependencies);
|
|
58
60
|
ensureAccountUserDataLayout(workspaceDir, profile);
|
|
59
|
-
const snapshot =
|
|
61
|
+
const snapshot = filterInactiveAgentWorkspaceSnapshot(
|
|
62
|
+
workspaceDir,
|
|
63
|
+
profile,
|
|
64
|
+
readLocalAgentWorkspaceSnapshot(workspaceDir, profile),
|
|
65
|
+
);
|
|
60
66
|
const hub = snapshot
|
|
61
67
|
? listAgentWorkspacePerceptionSources(workspaceDir, profile, snapshot)
|
|
62
68
|
: [];
|
|
63
69
|
const hubIds = new Set(hub.map(({ id }) => id));
|
|
64
70
|
const local = discoverLocalCapabilities(workspaceDir, profile).perceptions
|
|
71
|
+
.filter(({ entry }) => !snapshot?.items.perception.some(item => item.resourceId === entry.hub?.resourceId))
|
|
65
72
|
.map(({ source }) => source);
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}
|
|
73
|
+
const registered = (id: string) => Object.values(readCapabilityWorkspaceRegistry(workspaceDir, profile).entries)
|
|
74
|
+
.some(entry => entry.type === 'perception' && entry.runtimeId === id);
|
|
69
75
|
if (opts.disable) {
|
|
70
76
|
const source = local.find(({ id }) => id === opts.disable);
|
|
71
|
-
if (!source) throw new Error(`Unknown local Perception '${opts.disable}'.`);
|
|
72
|
-
|
|
73
|
-
const updated =
|
|
74
|
-
current.disabled_perception_modules.push(opts.disable!);
|
|
75
|
-
}, workspaceDir, profile);
|
|
77
|
+
if (!source && !hubIds.has(opts.disable) && !registered(opts.disable)) throw new Error(`Unknown local Perception '${opts.disable}'.`);
|
|
78
|
+
await selectCapability(workspaceDir, profile, 'perception', opts.disable, false);
|
|
79
|
+
const updated = readGameplayConfig(workspaceDir, profile);
|
|
76
80
|
console.log(JSON.stringify({
|
|
77
81
|
perception_module: opts.disable,
|
|
78
82
|
disabled: true,
|
|
@@ -84,12 +88,9 @@ Perception modules:
|
|
|
84
88
|
}
|
|
85
89
|
if (opts.enable) {
|
|
86
90
|
const source = local.find(({ id }) => id === opts.enable);
|
|
87
|
-
if (!source) throw new Error(`Unknown local Perception '${opts.enable}'.`);
|
|
88
|
-
|
|
89
|
-
const updated =
|
|
90
|
-
current.disabled_perception_modules = current.disabled_perception_modules
|
|
91
|
-
.filter((id) => id !== opts.enable);
|
|
92
|
-
}, workspaceDir, profile);
|
|
91
|
+
if (!source && !hubIds.has(opts.enable) && !registered(opts.enable)) throw new Error(`Unknown local Perception '${opts.enable}'.`);
|
|
92
|
+
await selectCapability(workspaceDir, profile, 'perception', opts.enable, true);
|
|
93
|
+
const updated = readGameplayConfig(workspaceDir, profile);
|
|
93
94
|
console.log(JSON.stringify({
|
|
94
95
|
perception_module: opts.enable,
|
|
95
96
|
disabled: false,
|
package/src/commands/persona.ts
CHANGED
|
@@ -15,6 +15,10 @@ import {
|
|
|
15
15
|
import { loadPersonaSnapshot } from '../lib/load-context.js';
|
|
16
16
|
import { discoverLocalCapabilities } from '../lib/capability-discovery.js';
|
|
17
17
|
import { setCapabilitySelection } from '../lib/capability-workspace.js';
|
|
18
|
+
import { readCapabilityWorkspaceRegistry, writeCapabilityWorkspaceRegistry } from '../lib/capability-workspace.js';
|
|
19
|
+
import { selectCapability } from '../lib/capability-selection.js';
|
|
20
|
+
import { HubClient } from '../lib/hub-client.js';
|
|
21
|
+
import { readLocalAgentWorkspaceSnapshot } from '../lib/agent-workspace-sync.js';
|
|
18
22
|
|
|
19
23
|
function context() {
|
|
20
24
|
const profile = new AuthStore().getActive();
|
|
@@ -60,11 +64,11 @@ export function createPersonaCommand(): Command {
|
|
|
60
64
|
persona
|
|
61
65
|
.command('create <name>')
|
|
62
66
|
.description('Create and select an empty account-local Persona preset')
|
|
63
|
-
.action((name: string) => {
|
|
67
|
+
.action(async (name: string) => {
|
|
64
68
|
const { directory, workspaceDir, profile } = context();
|
|
65
69
|
const created = createPersonaPreset(name, directory);
|
|
66
70
|
discoverLocalCapabilities(workspaceDir, profile);
|
|
67
|
-
|
|
71
|
+
await selectCapability(workspaceDir, profile, 'persona', created.id, true);
|
|
68
72
|
writePersonaSelection(workspaceDir, profile, { source: 'local', id: created.id });
|
|
69
73
|
console.log(JSON.stringify({
|
|
70
74
|
path: created.path,
|
|
@@ -75,16 +79,16 @@ export function createPersonaCommand(): Command {
|
|
|
75
79
|
persona
|
|
76
80
|
.command('use <preset>')
|
|
77
81
|
.description('Select an account-local Persona preset')
|
|
78
|
-
.action((presetName: string) => {
|
|
82
|
+
.action(async (presetName: string) => {
|
|
79
83
|
const { directory, workspaceDir, profile } = context();
|
|
80
84
|
const found = findPersonaPreset(presetName, directory);
|
|
81
85
|
if (!found) {
|
|
82
86
|
const available = listPersonaPresets(directory).map(p => p.name).join(', ') || 'none';
|
|
83
87
|
throw new Error(`Persona preset "${presetName}" not found. Available: ${available}`);
|
|
84
88
|
}
|
|
85
|
-
writePersonaSelection(workspaceDir, profile, { source: 'local', id: found.id });
|
|
86
89
|
discoverLocalCapabilities(workspaceDir, profile);
|
|
87
|
-
|
|
90
|
+
const entry = await selectCapability(workspaceDir, profile, 'persona', found.id, true);
|
|
91
|
+
writePersonaSelection(workspaceDir, profile, entry.hub ? { source: 'hub' } : { source: 'local', id: found.id });
|
|
88
92
|
console.log(JSON.stringify({
|
|
89
93
|
path: found.path,
|
|
90
94
|
preset: { id: found.id, name: found.name, source: 'local' },
|
|
@@ -97,6 +101,11 @@ export function createPersonaCommand(): Command {
|
|
|
97
101
|
.description('Use the Persona selected by the active account Hub loadout')
|
|
98
102
|
.action(() => {
|
|
99
103
|
const { workspaceDir, profile } = context();
|
|
104
|
+
const registry = readCapabilityWorkspaceRegistry(workspaceDir, profile);
|
|
105
|
+
for (const entry of Object.values(registry.entries)) {
|
|
106
|
+
if (entry.type === 'persona' && !entry.hub && entry.selection === 'equipped') entry.selection = 'unequipped';
|
|
107
|
+
}
|
|
108
|
+
writeCapabilityWorkspaceRegistry(workspaceDir, profile, registry);
|
|
100
109
|
writePersonaSelection(workspaceDir, profile, { source: 'hub' });
|
|
101
110
|
console.log(JSON.stringify(resolveActivePersonaFile(), null, 2));
|
|
102
111
|
});
|
|
@@ -104,8 +113,17 @@ export function createPersonaCommand(): Command {
|
|
|
104
113
|
persona
|
|
105
114
|
.command('clear')
|
|
106
115
|
.description('Use no Persona for the active account')
|
|
107
|
-
.action(() => {
|
|
116
|
+
.action(async () => {
|
|
108
117
|
const { workspaceDir, profile } = context();
|
|
118
|
+
const registry = readCapabilityWorkspaceRegistry(workspaceDir, profile);
|
|
119
|
+
if (Object.values(registry.entries).some(entry => entry.type === 'persona' && entry.hub)
|
|
120
|
+
|| readLocalAgentWorkspaceSnapshot(workspaceDir, profile)?.items.persona.length) {
|
|
121
|
+
await HubClient.fromProfile(profile).updateWorkspaceLoadout({ personaItemIds: [] });
|
|
122
|
+
}
|
|
123
|
+
for (const entry of Object.values(registry.entries)) {
|
|
124
|
+
if (entry.type === 'persona') entry.selection = 'unequipped';
|
|
125
|
+
}
|
|
126
|
+
writeCapabilityWorkspaceRegistry(workspaceDir, profile, registry);
|
|
109
127
|
writePersonaSelection(workspaceDir, profile, { source: 'none' });
|
|
110
128
|
console.log(JSON.stringify({ path: null, source: 'none' }, null, 2));
|
|
111
129
|
});
|
|
@@ -17,6 +17,8 @@ export interface AgentWorkspaceRemoteItem {
|
|
|
17
17
|
workspace_item_id: string;
|
|
18
18
|
resource_id: string;
|
|
19
19
|
version_id: string;
|
|
20
|
+
version_number?: string;
|
|
21
|
+
version_description?: string;
|
|
20
22
|
resource_type: ResourceType;
|
|
21
23
|
workspace_kind: 'owned' | 'installed';
|
|
22
24
|
is_created_by_me: boolean;
|
|
@@ -44,6 +44,8 @@ export interface AgentWorkspaceBehaviorManagement {
|
|
|
44
44
|
workspaceItemId?: string;
|
|
45
45
|
resourceId?: string;
|
|
46
46
|
versionId?: string;
|
|
47
|
+
versionNumber?: string;
|
|
48
|
+
versionDescription?: string;
|
|
47
49
|
resolution?: LocalAgentWorkspaceSnapshot['items']['strategy'][number]['resolution'];
|
|
48
50
|
ownerId?: string;
|
|
49
51
|
ownerName?: string | null;
|
|
@@ -74,7 +76,8 @@ export function listAgentWorkspaceBehaviorSources(
|
|
|
74
76
|
: []
|
|
75
77
|
)),
|
|
76
78
|
);
|
|
77
|
-
const sources = listClawclawBehaviorSources(root)
|
|
79
|
+
const sources = listClawclawBehaviorSources(root)
|
|
80
|
+
.filter(source => itemByPath.has(realpathSync(source.sourcePath))).map((source) => {
|
|
78
81
|
const item = itemByPath.get(realpathSync(source.sourcePath));
|
|
79
82
|
if (!item) throw new Error(`agent_workspace_behavior_metadata_missing:${source.id}`);
|
|
80
83
|
const trusted = item.sourceFiles[0]
|
|
@@ -91,6 +94,8 @@ export function listAgentWorkspaceBehaviorSources(
|
|
|
91
94
|
workspaceItemId: item.workspaceItemId,
|
|
92
95
|
resourceId: item.resourceId,
|
|
93
96
|
versionId: item.versionId,
|
|
97
|
+
versionNumber: item.versionNumber,
|
|
98
|
+
versionDescription: item.versionDescription,
|
|
94
99
|
resolution: item.resolution,
|
|
95
100
|
...(item.hub?.ownerId ? { ownerId: item.hub.ownerId } : {}),
|
|
96
101
|
...(item.hub ? { ownerName: item.hub.ownerName } : {}),
|
|
@@ -109,7 +114,10 @@ export function listAgentWorkspacePerceptionSources(
|
|
|
109
114
|
const active = currentSnapshot(workspaceDir, profile, snapshot);
|
|
110
115
|
if (!active || active.items.perception.length === 0) return [];
|
|
111
116
|
const root = join(localAgentWorkspaceSnapshotRoot(workspaceDir, profile, active), 'runtime', 'perceptions');
|
|
112
|
-
const
|
|
117
|
+
const selectedPaths = new Set(active.items.perception.filter(item => item.runtimeEntryPath)
|
|
118
|
+
.map(item => resolveLocalAgentWorkspacePath(workspaceDir, profile, active, item.runtimeEntryPath!)));
|
|
119
|
+
const sources = existsSync(root) ? listClawclawPerceptionSourcesInDirectory(root)
|
|
120
|
+
.filter(source => selectedPaths.has(source.sourcePath)) : [];
|
|
113
121
|
const ids = new Set<string>();
|
|
114
122
|
for (const source of sources) {
|
|
115
123
|
if (ids.has(source.id)) throw new Error(`AGENT_RESOURCE_ID_CONFLICT:perception:${source.id}`);
|
|
@@ -152,11 +152,15 @@ function unique(values: Array<string | undefined>): string[] {
|
|
|
152
152
|
function accountManagedSkillSources(
|
|
153
153
|
workspaceDir: string,
|
|
154
154
|
profile: Pick<AuthProfile, 'apiKey'>,
|
|
155
|
+
includeInactive = false,
|
|
155
156
|
): Map<string, string> {
|
|
156
157
|
const skillsRoot = getUserDataAccountSkillsDir(workspaceDir, profile);
|
|
157
158
|
const sources = new Map<string, string>();
|
|
158
159
|
for (const [name] of Object.entries(readManifest(workspaceDir, profile).entries)) {
|
|
159
160
|
if (name === 'clawclaw') continue;
|
|
161
|
+
const entry = Object.values(readCapabilityWorkspaceRegistry(workspaceDir, profile).entries)
|
|
162
|
+
.find(entry => entry.type === 'skill' && entry.runtimeId === name);
|
|
163
|
+
if (!includeInactive && entry && (entry.selection !== 'equipped' || entry.hub?.cloudStatus)) continue;
|
|
160
164
|
sources.set(name, join(skillsRoot, name));
|
|
161
165
|
}
|
|
162
166
|
for (const entry of Object.values(readCapabilityWorkspaceRegistry(workspaceDir, profile).entries)) {
|
|
@@ -186,7 +190,7 @@ export function switchActiveAccountSkillLinks(
|
|
|
186
190
|
const linkTarget = dependencies.linkTarget ?? linkAgentSkillTarget;
|
|
187
191
|
const unlinkTarget = dependencies.unlinkTarget ?? unlinkAgentSkillTarget;
|
|
188
192
|
const previous = previousProfile
|
|
189
|
-
? accountManagedSkillSources(workspaceDir, previousProfile)
|
|
193
|
+
? accountManagedSkillSources(workspaceDir, previousProfile, true)
|
|
190
194
|
: new Map<string, string>();
|
|
191
195
|
const next = accountManagedSkillSources(workspaceDir, nextProfile);
|
|
192
196
|
|
|
@@ -298,6 +302,7 @@ export function syncAgentWorkspaceSkills(
|
|
|
298
302
|
}
|
|
299
303
|
const path = capabilityWorkspacePath(workspaceDir, profile, entry);
|
|
300
304
|
if (desired.has(entry.runtimeId)) {
|
|
305
|
+
if (entry.hub?.resourceId === desired.get(entry.runtimeId)?.resourceId) continue;
|
|
301
306
|
failed.push({ name: entry.runtimeId, action: 'add', error: 'local and Hub Skill names conflict' });
|
|
302
307
|
continue;
|
|
303
308
|
}
|
|
@@ -473,6 +478,7 @@ export function syncAgentWorkspaceSkills(
|
|
|
473
478
|
}
|
|
474
479
|
}
|
|
475
480
|
if (!failedRemoval) removed.push(name);
|
|
481
|
+
else next.entries[name] = current.entries[name]!;
|
|
476
482
|
}
|
|
477
483
|
|
|
478
484
|
writeManifest(workspaceDir, profile, next);
|
|
@@ -34,6 +34,10 @@ import {
|
|
|
34
34
|
capabilityEntryForHubResource,
|
|
35
35
|
capabilityWorkspacePath,
|
|
36
36
|
} from './capability-workspace.js';
|
|
37
|
+
import { inspectClawclawBehaviorSource, behaviorSourceCompatibilityError } from '../runtime/clawclaw/plugins/behavior/behavior-source.js';
|
|
38
|
+
import { listClawclawPerceptionSourcesInDirectory } from '../runtime/clawclaw/plugins/perception/perception-source.js';
|
|
39
|
+
import { BEHAVIOR_PLUGIN_API_VERSION } from '../sdk/behavior-plugin/index.js';
|
|
40
|
+
import { PERCEPTION_PLUGIN_API_VERSION } from '../sdk/perception-plugin/index.js';
|
|
37
41
|
|
|
38
42
|
const RESOURCE_TYPES: readonly ResourceType[] = ['skill', 'strategy', 'persona', 'perception'];
|
|
39
43
|
const SHA256 = /^[0-9a-f]{64}$/;
|
|
@@ -52,6 +56,8 @@ export interface LocalAgentWorkspaceItem {
|
|
|
52
56
|
workspaceItemId: string;
|
|
53
57
|
resourceId: string;
|
|
54
58
|
versionId: string;
|
|
59
|
+
versionNumber?: string;
|
|
60
|
+
versionDescription?: string;
|
|
55
61
|
resourceType: ResourceType;
|
|
56
62
|
hub?: {
|
|
57
63
|
workspaceKind: 'owned' | 'installed';
|
|
@@ -354,6 +360,8 @@ async function materializeItem(
|
|
|
354
360
|
workspaceItemId: item.workspace_item_id,
|
|
355
361
|
resourceId: item.resource_id,
|
|
356
362
|
versionId: item.version_id,
|
|
363
|
+
versionNumber: item.version_number,
|
|
364
|
+
versionDescription: item.version_description,
|
|
357
365
|
resourceType: item.resource_type,
|
|
358
366
|
hub: {
|
|
359
367
|
workspaceKind: item.workspace_kind,
|
|
@@ -608,7 +616,7 @@ function inspectLocalSnapshot(
|
|
|
608
616
|
const modifiedAtMs = statSync(workingPath).mtimeMs;
|
|
609
617
|
item.resolution = item.resolution === 'local_origin_unrecognized'
|
|
610
618
|
? 'local_origin_unrecognized'
|
|
611
|
-
: 'local_modified';
|
|
619
|
+
: item.resolution === 'concurrent_difference' ? 'concurrent_difference' : 'local_modified';
|
|
612
620
|
item.localContentDigest = localDigest;
|
|
613
621
|
item.localModifiedAtMs = modifiedAtMs;
|
|
614
622
|
if (projectionSha !== localSha) projectionOutdated = true;
|
|
@@ -679,8 +687,15 @@ export async function syncAgentWorkspaceConfig(
|
|
|
679
687
|
const client = dependencies.client ?? new AgentWorkspaceClient(profile);
|
|
680
688
|
const remote = await client.getConfig();
|
|
681
689
|
validateRemoteConfig(remote);
|
|
690
|
+
const contentUnchanged = previous && RESOURCE_TYPES.every(type => {
|
|
691
|
+
const items = previous.items[type];
|
|
692
|
+
return items.length === remote.items[type].length && remote.items[type].every(item =>
|
|
693
|
+
items.some(old => old.resourceId === item.resource_id && old.versionId === item.version_id
|
|
694
|
+
&& old.workspaceItemId === item.workspace_item_id && old.contentDigest === item.content_digest));
|
|
695
|
+
});
|
|
682
696
|
if (
|
|
683
697
|
previous?.revision === remote.revision
|
|
698
|
+
&& contentUnchanged
|
|
684
699
|
&& previous.metadataVersion === 1
|
|
685
700
|
&& previous.layoutVersion === 3
|
|
686
701
|
&& inspected?.projectionOutdated !== true
|
|
@@ -709,11 +724,12 @@ export async function syncAgentWorkspaceConfig(
|
|
|
709
724
|
);
|
|
710
725
|
for (const type of RESOURCE_TYPES) {
|
|
711
726
|
for (const item of remote.items[type]) {
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
item,
|
|
715
|
-
|
|
716
|
-
|
|
727
|
+
let materialized: LocalAgentWorkspaceItem;
|
|
728
|
+
try {
|
|
729
|
+
materialized = await materializeItem(temporary, item, dependencies.download ?? downloadAgentWorkspaceFile);
|
|
730
|
+
} catch (error) {
|
|
731
|
+
throw new Error(`agent_workspace_resource_failed:${type}:${item.resource_id}:${item.source_files.map(file => file.relative_path).join(',')}:${error instanceof Error ? error.message : String(error)}`);
|
|
732
|
+
}
|
|
717
733
|
const prior = previousByKey.get(type)?.get(materialized.resourceId);
|
|
718
734
|
let workingPath: string | undefined;
|
|
719
735
|
let persistedWorkingMetadata: WorkingCopyMetadata | undefined;
|
|
@@ -786,7 +802,7 @@ export async function syncAgentWorkspaceConfig(
|
|
|
786
802
|
);
|
|
787
803
|
materialized.resolution = !override.originRecognized
|
|
788
804
|
? 'local_origin_unrecognized'
|
|
789
|
-
: remoteAdvancedFromLocalBaseline
|
|
805
|
+
: remoteAdvancedFromLocalBaseline || prior?.resolution === 'concurrent_difference'
|
|
790
806
|
? 'concurrent_difference'
|
|
791
807
|
: 'local_modified';
|
|
792
808
|
materialized.localContentDigest = override.contentDigest;
|
|
@@ -800,6 +816,22 @@ export async function syncAgentWorkspaceConfig(
|
|
|
800
816
|
));
|
|
801
817
|
}
|
|
802
818
|
}
|
|
819
|
+
// Reject an invalid cloud replacement before touching the working copy
|
|
820
|
+
// or pointer. Invalid local edits remain visible to load diagnostics.
|
|
821
|
+
if (prior && materialized.resolution === 'hub' && materialized.runtimeEntryPath) {
|
|
822
|
+
const path = join(temporary, materialized.runtimeEntryPath);
|
|
823
|
+
if (type === 'strategy') {
|
|
824
|
+
const source = inspectClawclawBehaviorSource(path, dirname(path));
|
|
825
|
+
if (!source || source.apiVersion !== BEHAVIOR_PLUGIN_API_VERSION || behaviorSourceCompatibilityError(source)) {
|
|
826
|
+
throw new Error(`agent_workspace_resource_failed:strategy:${item.resource_id}:cloud_module_invalid`);
|
|
827
|
+
}
|
|
828
|
+
} else if (type === 'perception') {
|
|
829
|
+
const source = listClawclawPerceptionSourcesInDirectory(dirname(path)).find(source => source.sourcePath === path);
|
|
830
|
+
if (!source || source.apiVersion !== PERCEPTION_PLUGIN_API_VERSION) {
|
|
831
|
+
throw new Error(`agent_workspace_resource_failed:perception:${item.resource_id}:cloud_module_invalid`);
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
}
|
|
803
835
|
if (materialized.workingCopyPath && effectiveBytes) {
|
|
804
836
|
const accountRoot = getUserDataAccountDir(workspaceDir, profile);
|
|
805
837
|
workingUpdates.push({
|